]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/powerpc/kernel/head.S
powerpc: Merge lmb.c and make MM initialization use it.
[mirror_ubuntu-artful-kernel.git] / arch / powerpc / kernel / head.S
CommitLineData
14cf11af
PM
1/*
2 * PowerPC version
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 *
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
11 * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
12 * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
13 *
14 * This file contains the low-level support and setup for the
15 * PowerPC platform, including trap and interrupt dispatch.
16 * (The PPC 8xx embedded CPUs use head_8xx.S instead.)
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 *
23 */
24
25#include <linux/config.h>
26#include <asm/processor.h>
27#include <asm/page.h>
28#include <asm/mmu.h>
29#include <asm/pgtable.h>
30#include <asm/cputable.h>
31#include <asm/cache.h>
32#include <asm/thread_info.h>
33#include <asm/ppc_asm.h>
34#include <asm/asm-offsets.h>
35
36#ifdef CONFIG_APUS
37#include <asm/amigappc.h>
38#endif
39
40#ifdef CONFIG_PPC64BRIDGE
41#define LOAD_BAT(n, reg, RA, RB) \
42 ld RA,(n*32)+0(reg); \
43 ld RB,(n*32)+8(reg); \
44 mtspr SPRN_IBAT##n##U,RA; \
45 mtspr SPRN_IBAT##n##L,RB; \
46 ld RA,(n*32)+16(reg); \
47 ld RB,(n*32)+24(reg); \
48 mtspr SPRN_DBAT##n##U,RA; \
49 mtspr SPRN_DBAT##n##L,RB; \
50
51#else /* CONFIG_PPC64BRIDGE */
52
53/* 601 only have IBAT; cr0.eq is set on 601 when using this macro */
54#define LOAD_BAT(n, reg, RA, RB) \
55 /* see the comment for clear_bats() -- Cort */ \
56 li RA,0; \
57 mtspr SPRN_IBAT##n##U,RA; \
58 mtspr SPRN_DBAT##n##U,RA; \
59 lwz RA,(n*16)+0(reg); \
60 lwz RB,(n*16)+4(reg); \
61 mtspr SPRN_IBAT##n##U,RA; \
62 mtspr SPRN_IBAT##n##L,RB; \
63 beq 1f; \
64 lwz RA,(n*16)+8(reg); \
65 lwz RB,(n*16)+12(reg); \
66 mtspr SPRN_DBAT##n##U,RA; \
67 mtspr SPRN_DBAT##n##L,RB; \
681:
69#endif /* CONFIG_PPC64BRIDGE */
70
71 .text
72 .stabs "arch/ppc/kernel/",N_SO,0,0,0f
73 .stabs "head.S",N_SO,0,0,0f
740:
75 .globl _stext
76_stext:
77
78/*
79 * _start is defined this way because the XCOFF loader in the OpenFirmware
80 * on the powermac expects the entry point to be a procedure descriptor.
81 */
82 .text
83 .globl _start
84_start:
85 /*
86 * These are here for legacy reasons, the kernel used to
87 * need to look like a coff function entry for the pmac
88 * but we're always started by some kind of bootloader now.
89 * -- Cort
90 */
91 nop /* used by __secondary_hold on prep (mtx) and chrp smp */
92 nop /* used by __secondary_hold on prep (mtx) and chrp smp */
93 nop
94
95/* PMAC
96 * Enter here with the kernel text, data and bss loaded starting at
97 * 0, running with virtual == physical mapping.
98 * r5 points to the prom entry point (the client interface handler
99 * address). Address translation is turned on, with the prom
100 * managing the hash table. Interrupts are disabled. The stack
101 * pointer (r1) points to just below the end of the half-meg region
102 * from 0x380000 - 0x400000, which is mapped in already.
103 *
104 * If we are booted from MacOS via BootX, we enter with the kernel
105 * image loaded somewhere, and the following values in registers:
106 * r3: 'BooX' (0x426f6f58)
107 * r4: virtual address of boot_infos_t
108 * r5: 0
109 *
110 * APUS
111 * r3: 'APUS'
112 * r4: physical address of memory base
113 * Linux/m68k style BootInfo structure at &_end.
114 *
115 * PREP
116 * This is jumped to on prep systems right after the kernel is relocated
117 * to its proper place in memory by the boot loader. The expected layout
118 * of the regs is:
119 * r3: ptr to residual data
120 * r4: initrd_start or if no initrd then 0
121 * r5: initrd_end - unused if r4 is 0
122 * r6: Start of command line string
123 * r7: End of command line string
124 *
125 * This just gets a minimal mmu environment setup so we can call
126 * start_here() to do the real work.
127 * -- Cort
128 */
129
130 .globl __start
131__start:
132/*
133 * We have to do any OF calls before we map ourselves to KERNELBASE,
134 * because OF may have I/O devices mapped into that area
135 * (particularly on CHRP).
136 */
9b6b563c
PM
137 cmpwi 0,r5,0
138 beq 1f
139 bl prom_init
140 trap
141
1421: mr r31,r3 /* save parameters */
14cf11af 143 mr r30,r4
14cf11af
PM
144 li r24,0 /* cpu # */
145
146/*
147 * early_init() does the early machine identification and does
148 * the necessary low-level setup and clears the BSS
149 * -- Cort <cort@fsmlabs.com>
150 */
151 bl early_init
152
153/*
154 * On POWER4, we first need to tweak some CPU configuration registers
155 * like real mode cache inhibit or exception base
156 */
157#ifdef CONFIG_POWER4
158 bl __970_cpu_preinit
159#endif /* CONFIG_POWER4 */
160
161#ifdef CONFIG_APUS
162/* On APUS the __va/__pa constants need to be set to the correct
163 * values before continuing.
164 */
165 mr r4,r30
166 bl fix_mem_constants
167#endif /* CONFIG_APUS */
168
169/* Switch MMU off, clear BATs and flush TLB. At this point, r3 contains
170 * the physical address we are running at, returned by early_init()
171 */
172 bl mmu_off
173__after_mmu_off:
174#ifndef CONFIG_POWER4
175 bl clear_bats
176 bl flush_tlbs
177
178 bl initial_bats
179#if !defined(CONFIG_APUS) && defined(CONFIG_BOOTX_TEXT)
180 bl setup_disp_bat
181#endif
182#else /* CONFIG_POWER4 */
183 bl reloc_offset
184 bl initial_mm_power4
185#endif /* CONFIG_POWER4 */
186
187/*
188 * Call setup_cpu for CPU 0 and initialize 6xx Idle
189 */
190 bl reloc_offset
191 li r24,0 /* cpu# */
192 bl call_setup_cpu /* Call setup_cpu for this CPU */
193#ifdef CONFIG_6xx
194 bl reloc_offset
195 bl init_idle_6xx
196#endif /* CONFIG_6xx */
197#ifdef CONFIG_POWER4
198 bl reloc_offset
199 bl init_idle_power4
200#endif /* CONFIG_POWER4 */
201
202
203#ifndef CONFIG_APUS
204/*
205 * We need to run with _start at physical address 0.
206 * On CHRP, we are loaded at 0x10000 since OF on CHRP uses
207 * the exception vectors at 0 (and therefore this copy
208 * overwrites OF's exception vectors with our own).
9b6b563c 209 * The MMU is off at this point.
14cf11af
PM
210 */
211 bl reloc_offset
212 mr r26,r3
213 addis r4,r3,KERNELBASE@h /* current address of _start */
214 cmpwi 0,r4,0 /* are we already running at 0? */
215 bne relocate_kernel
216#endif /* CONFIG_APUS */
217/*
218 * we now have the 1st 16M of ram mapped with the bats.
219 * prep needs the mmu to be turned on here, but pmac already has it on.
220 * this shouldn't bother the pmac since it just gets turned on again
221 * as we jump to our code at KERNELBASE. -- Cort
222 * Actually no, pmac doesn't have it on any more. BootX enters with MMU
223 * off, and in other cases, we now turn it off before changing BATs above.
224 */
225turn_on_mmu:
226 mfmsr r0
227 ori r0,r0,MSR_DR|MSR_IR
228 mtspr SPRN_SRR1,r0
229 lis r0,start_here@h
230 ori r0,r0,start_here@l
231 mtspr SPRN_SRR0,r0
232 SYNC
233 RFI /* enables MMU */
234
235/*
236 * We need __secondary_hold as a place to hold the other cpus on
237 * an SMP machine, even when we are running a UP kernel.
238 */
239 . = 0xc0 /* for prep bootloader */
240 li r3,1 /* MTX only has 1 cpu */
241 .globl __secondary_hold
242__secondary_hold:
243 /* tell the master we're here */
244 stw r3,4(0)
245#ifdef CONFIG_SMP
246100: lwz r4,0(0)
247 /* wait until we're told to start */
248 cmpw 0,r4,r3
249 bne 100b
250 /* our cpu # was at addr 0 - go */
251 mr r24,r3 /* cpu # */
252 b __secondary_start
253#else
254 b .
255#endif /* CONFIG_SMP */
256
257/*
258 * Exception entry code. This code runs with address translation
259 * turned off, i.e. using physical addresses.
260 * We assume sprg3 has the physical address of the current
261 * task's thread_struct.
262 */
263#define EXCEPTION_PROLOG \
264 mtspr SPRN_SPRG0,r10; \
265 mtspr SPRN_SPRG1,r11; \
266 mfcr r10; \
267 EXCEPTION_PROLOG_1; \
268 EXCEPTION_PROLOG_2
269
270#define EXCEPTION_PROLOG_1 \
271 mfspr r11,SPRN_SRR1; /* check whether user or kernel */ \
272 andi. r11,r11,MSR_PR; \
273 tophys(r11,r1); /* use tophys(r1) if kernel */ \
274 beq 1f; \
275 mfspr r11,SPRN_SPRG3; \
276 lwz r11,THREAD_INFO-THREAD(r11); \
277 addi r11,r11,THREAD_SIZE; \
278 tophys(r11,r11); \
2791: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
280
281
282#define EXCEPTION_PROLOG_2 \
283 CLR_TOP32(r11); \
284 stw r10,_CCR(r11); /* save registers */ \
285 stw r12,GPR12(r11); \
286 stw r9,GPR9(r11); \
287 mfspr r10,SPRN_SPRG0; \
288 stw r10,GPR10(r11); \
289 mfspr r12,SPRN_SPRG1; \
290 stw r12,GPR11(r11); \
291 mflr r10; \
292 stw r10,_LINK(r11); \
293 mfspr r12,SPRN_SRR0; \
294 mfspr r9,SPRN_SRR1; \
295 stw r1,GPR1(r11); \
296 stw r1,0(r11); \
297 tovirt(r1,r11); /* set new kernel sp */ \
298 li r10,MSR_KERNEL & ~(MSR_IR|MSR_DR); /* can take exceptions */ \
299 MTMSRD(r10); /* (except for mach check in rtas) */ \
300 stw r0,GPR0(r11); \
301 SAVE_4GPRS(3, r11); \
302 SAVE_2GPRS(7, r11)
303
304/*
305 * Note: code which follows this uses cr0.eq (set if from kernel),
306 * r11, r12 (SRR0), and r9 (SRR1).
307 *
308 * Note2: once we have set r1 we are in a position to take exceptions
309 * again, and we could thus set MSR:RI at that point.
310 */
311
312/*
313 * Exception vectors.
314 */
315#define EXCEPTION(n, label, hdlr, xfer) \
316 . = n; \
317label: \
318 EXCEPTION_PROLOG; \
319 addi r3,r1,STACK_FRAME_OVERHEAD; \
320 xfer(n, hdlr)
321
322#define EXC_XFER_TEMPLATE(n, hdlr, trap, copyee, tfer, ret) \
323 li r10,trap; \
324 stw r10,TRAP(r11); \
325 li r10,MSR_KERNEL; \
326 copyee(r10, r9); \
327 bl tfer; \
328i##n: \
329 .long hdlr; \
330 .long ret
331
332#define COPY_EE(d, s) rlwimi d,s,0,16,16
333#define NOCOPY(d, s)
334
335#define EXC_XFER_STD(n, hdlr) \
336 EXC_XFER_TEMPLATE(n, hdlr, n, NOCOPY, transfer_to_handler_full, \
337 ret_from_except_full)
338
339#define EXC_XFER_LITE(n, hdlr) \
340 EXC_XFER_TEMPLATE(n, hdlr, n+1, NOCOPY, transfer_to_handler, \
341 ret_from_except)
342
343#define EXC_XFER_EE(n, hdlr) \
344 EXC_XFER_TEMPLATE(n, hdlr, n, COPY_EE, transfer_to_handler_full, \
345 ret_from_except_full)
346
347#define EXC_XFER_EE_LITE(n, hdlr) \
348 EXC_XFER_TEMPLATE(n, hdlr, n+1, COPY_EE, transfer_to_handler, \
349 ret_from_except)
350
351/* System reset */
352/* core99 pmac starts the seconary here by changing the vector, and
dc1c1ca3 353 putting it back to what it was (unknown_exception) when done. */
14cf11af
PM
354#if defined(CONFIG_GEMINI) && defined(CONFIG_SMP)
355 . = 0x100
356 b __secondary_start_gemini
357#else
dc1c1ca3 358 EXCEPTION(0x100, Reset, unknown_exception, EXC_XFER_STD)
14cf11af
PM
359#endif
360
361/* Machine check */
362/*
363 * On CHRP, this is complicated by the fact that we could get a
364 * machine check inside RTAS, and we have no guarantee that certain
365 * critical registers will have the values we expect. The set of
366 * registers that might have bad values includes all the GPRs
367 * and all the BATs. We indicate that we are in RTAS by putting
368 * a non-zero value, the address of the exception frame to use,
369 * in SPRG2. The machine check handler checks SPRG2 and uses its
370 * value if it is non-zero. If we ever needed to free up SPRG2,
371 * we could use a field in the thread_info or thread_struct instead.
372 * (Other exception handlers assume that r1 is a valid kernel stack
373 * pointer when we take an exception from supervisor mode.)
374 * -- paulus.
375 */
376 . = 0x200
377 mtspr SPRN_SPRG0,r10
378 mtspr SPRN_SPRG1,r11
379 mfcr r10
380#ifdef CONFIG_PPC_CHRP
381 mfspr r11,SPRN_SPRG2
382 cmpwi 0,r11,0
383 bne 7f
384#endif /* CONFIG_PPC_CHRP */
385 EXCEPTION_PROLOG_1
3867: EXCEPTION_PROLOG_2
387 addi r3,r1,STACK_FRAME_OVERHEAD
388#ifdef CONFIG_PPC_CHRP
389 mfspr r4,SPRN_SPRG2
390 cmpwi cr1,r4,0
391 bne cr1,1f
392#endif
dc1c1ca3 393 EXC_XFER_STD(0x200, machine_check_exception)
14cf11af
PM
394#ifdef CONFIG_PPC_CHRP
3951: b machine_check_in_rtas
396#endif
397
398/* Data access exception. */
399 . = 0x300
400#ifdef CONFIG_PPC64BRIDGE
401 b DataAccess
402DataAccessCont:
403#else
404DataAccess:
405 EXCEPTION_PROLOG
406#endif /* CONFIG_PPC64BRIDGE */
407 mfspr r10,SPRN_DSISR
408 andis. r0,r10,0xa470 /* weird error? */
409 bne 1f /* if not, try to put a PTE */
410 mfspr r4,SPRN_DAR /* into the hash table */
411 rlwinm r3,r10,32-15,21,21 /* DSISR_STORE -> _PAGE_RW */
412 bl hash_page
4131: stw r10,_DSISR(r11)
414 mr r5,r10
415 mfspr r4,SPRN_DAR
416 EXC_XFER_EE_LITE(0x300, handle_page_fault)
417
418#ifdef CONFIG_PPC64BRIDGE
419/* SLB fault on data access. */
420 . = 0x380
421 b DataSegment
422#endif /* CONFIG_PPC64BRIDGE */
423
424/* Instruction access exception. */
425 . = 0x400
426#ifdef CONFIG_PPC64BRIDGE
427 b InstructionAccess
428InstructionAccessCont:
429#else
430InstructionAccess:
431 EXCEPTION_PROLOG
432#endif /* CONFIG_PPC64BRIDGE */
433 andis. r0,r9,0x4000 /* no pte found? */
434 beq 1f /* if so, try to put a PTE */
435 li r3,0 /* into the hash table */
436 mr r4,r12 /* SRR0 is fault address */
437 bl hash_page
4381: mr r4,r12
439 mr r5,r9
440 EXC_XFER_EE_LITE(0x400, handle_page_fault)
441
442#ifdef CONFIG_PPC64BRIDGE
443/* SLB fault on instruction access. */
444 . = 0x480
445 b InstructionSegment
446#endif /* CONFIG_PPC64BRIDGE */
447
448/* External interrupt */
449 EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
450
451/* Alignment exception */
452 . = 0x600
453Alignment:
454 EXCEPTION_PROLOG
455 mfspr r4,SPRN_DAR
456 stw r4,_DAR(r11)
457 mfspr r5,SPRN_DSISR
458 stw r5,_DSISR(r11)
459 addi r3,r1,STACK_FRAME_OVERHEAD
dc1c1ca3 460 EXC_XFER_EE(0x600, alignment_exception)
14cf11af
PM
461
462/* Program check exception */
dc1c1ca3 463 EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
14cf11af
PM
464
465/* Floating-point unavailable */
466 . = 0x800
467FPUnavailable:
468 EXCEPTION_PROLOG
469 bne load_up_fpu /* if from user, just load it up */
470 addi r3,r1,STACK_FRAME_OVERHEAD
471 EXC_XFER_EE_LITE(0x800, KernelFP)
472
473/* Decrementer */
474 EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
475
dc1c1ca3
SR
476 EXCEPTION(0xa00, Trap_0a, unknown_exception, EXC_XFER_EE)
477 EXCEPTION(0xb00, Trap_0b, unknown_exception, EXC_XFER_EE)
14cf11af
PM
478
479/* System call */
480 . = 0xc00
481SystemCall:
482 EXCEPTION_PROLOG
483 EXC_XFER_EE_LITE(0xc00, DoSyscall)
484
485/* Single step - not used on 601 */
dc1c1ca3
SR
486 EXCEPTION(0xd00, SingleStep, single_step_exception, EXC_XFER_STD)
487 EXCEPTION(0xe00, Trap_0e, unknown_exception, EXC_XFER_EE)
14cf11af
PM
488
489/*
490 * The Altivec unavailable trap is at 0x0f20. Foo.
491 * We effectively remap it to 0x3000.
492 * We include an altivec unavailable exception vector even if
493 * not configured for Altivec, so that you can't panic a
494 * non-altivec kernel running on a machine with altivec just
495 * by executing an altivec instruction.
496 */
497 . = 0xf00
498 b Trap_0f
499
500 . = 0xf20
501 b AltiVecUnavailable
502
503Trap_0f:
504 EXCEPTION_PROLOG
505 addi r3,r1,STACK_FRAME_OVERHEAD
dc1c1ca3 506 EXC_XFER_EE(0xf00, unknown_exception)
14cf11af
PM
507
508/*
509 * Handle TLB miss for instruction on 603/603e.
510 * Note: we get an alternate set of r0 - r3 to use automatically.
511 */
512 . = 0x1000
513InstructionTLBMiss:
514/*
515 * r0: stored ctr
516 * r1: linux style pte ( later becomes ppc hardware pte )
517 * r2: ptr to linux-style pte
518 * r3: scratch
519 */
520 mfctr r0
521 /* Get PTE (linux-style) and check access */
522 mfspr r3,SPRN_IMISS
523 lis r1,KERNELBASE@h /* check if kernel address */
524 cmplw 0,r3,r1
525 mfspr r2,SPRN_SPRG3
526 li r1,_PAGE_USER|_PAGE_PRESENT /* low addresses tested as user */
527 lwz r2,PGDIR(r2)
528 blt+ 112f
529 lis r2,swapper_pg_dir@ha /* if kernel address, use */
530 addi r2,r2,swapper_pg_dir@l /* kernel page table */
531 mfspr r1,SPRN_SRR1 /* and MSR_PR bit from SRR1 */
532 rlwinm r1,r1,32-12,29,29 /* shift MSR_PR to _PAGE_USER posn */
533112: tophys(r2,r2)
534 rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */
535 lwz r2,0(r2) /* get pmd entry */
536 rlwinm. r2,r2,0,0,19 /* extract address of pte page */
537 beq- InstructionAddressInvalid /* return if no mapping */
538 rlwimi r2,r3,22,20,29 /* insert next 10 bits of address */
539 lwz r3,0(r2) /* get linux-style pte */
540 andc. r1,r1,r3 /* check access & ~permission */
541 bne- InstructionAddressInvalid /* return if access not permitted */
542 ori r3,r3,_PAGE_ACCESSED /* set _PAGE_ACCESSED in pte */
543 /*
544 * NOTE! We are assuming this is not an SMP system, otherwise
545 * we would need to update the pte atomically with lwarx/stwcx.
546 */
547 stw r3,0(r2) /* update PTE (accessed bit) */
548 /* Convert linux-style PTE to low word of PPC-style PTE */
549 rlwinm r1,r3,32-10,31,31 /* _PAGE_RW -> PP lsb */
550 rlwinm r2,r3,32-7,31,31 /* _PAGE_DIRTY -> PP lsb */
551 and r1,r1,r2 /* writable if _RW and _DIRTY */
552 rlwimi r3,r3,32-1,30,30 /* _PAGE_USER -> PP msb */
553 rlwimi r3,r3,32-1,31,31 /* _PAGE_USER -> PP lsb */
554 ori r1,r1,0xe14 /* clear out reserved bits and M */
555 andc r1,r3,r1 /* PP = user? (rw&dirty? 2: 3): 0 */
556 mtspr SPRN_RPA,r1
557 mfspr r3,SPRN_IMISS
558 tlbli r3
559 mfspr r3,SPRN_SRR1 /* Need to restore CR0 */
560 mtcrf 0x80,r3
561 rfi
562InstructionAddressInvalid:
563 mfspr r3,SPRN_SRR1
564 rlwinm r1,r3,9,6,6 /* Get load/store bit */
565
566 addis r1,r1,0x2000
567 mtspr SPRN_DSISR,r1 /* (shouldn't be needed) */
568 mtctr r0 /* Restore CTR */
569 andi. r2,r3,0xFFFF /* Clear upper bits of SRR1 */
570 or r2,r2,r1
571 mtspr SPRN_SRR1,r2
572 mfspr r1,SPRN_IMISS /* Get failing address */
573 rlwinm. r2,r2,0,31,31 /* Check for little endian access */
574 rlwimi r2,r2,1,30,30 /* change 1 -> 3 */
575 xor r1,r1,r2
576 mtspr SPRN_DAR,r1 /* Set fault address */
577 mfmsr r0 /* Restore "normal" registers */
578 xoris r0,r0,MSR_TGPR>>16
579 mtcrf 0x80,r3 /* Restore CR0 */
580 mtmsr r0
581 b InstructionAccess
582
583/*
584 * Handle TLB miss for DATA Load operation on 603/603e
585 */
586 . = 0x1100
587DataLoadTLBMiss:
588/*
589 * r0: stored ctr
590 * r1: linux style pte ( later becomes ppc hardware pte )
591 * r2: ptr to linux-style pte
592 * r3: scratch
593 */
594 mfctr r0
595 /* Get PTE (linux-style) and check access */
596 mfspr r3,SPRN_DMISS
597 lis r1,KERNELBASE@h /* check if kernel address */
598 cmplw 0,r3,r1
599 mfspr r2,SPRN_SPRG3
600 li r1,_PAGE_USER|_PAGE_PRESENT /* low addresses tested as user */
601 lwz r2,PGDIR(r2)
602 blt+ 112f
603 lis r2,swapper_pg_dir@ha /* if kernel address, use */
604 addi r2,r2,swapper_pg_dir@l /* kernel page table */
605 mfspr r1,SPRN_SRR1 /* and MSR_PR bit from SRR1 */
606 rlwinm r1,r1,32-12,29,29 /* shift MSR_PR to _PAGE_USER posn */
607112: tophys(r2,r2)
608 rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */
609 lwz r2,0(r2) /* get pmd entry */
610 rlwinm. r2,r2,0,0,19 /* extract address of pte page */
611 beq- DataAddressInvalid /* return if no mapping */
612 rlwimi r2,r3,22,20,29 /* insert next 10 bits of address */
613 lwz r3,0(r2) /* get linux-style pte */
614 andc. r1,r1,r3 /* check access & ~permission */
615 bne- DataAddressInvalid /* return if access not permitted */
616 ori r3,r3,_PAGE_ACCESSED /* set _PAGE_ACCESSED in pte */
617 /*
618 * NOTE! We are assuming this is not an SMP system, otherwise
619 * we would need to update the pte atomically with lwarx/stwcx.
620 */
621 stw r3,0(r2) /* update PTE (accessed bit) */
622 /* Convert linux-style PTE to low word of PPC-style PTE */
623 rlwinm r1,r3,32-10,31,31 /* _PAGE_RW -> PP lsb */
624 rlwinm r2,r3,32-7,31,31 /* _PAGE_DIRTY -> PP lsb */
625 and r1,r1,r2 /* writable if _RW and _DIRTY */
626 rlwimi r3,r3,32-1,30,30 /* _PAGE_USER -> PP msb */
627 rlwimi r3,r3,32-1,31,31 /* _PAGE_USER -> PP lsb */
628 ori r1,r1,0xe14 /* clear out reserved bits and M */
629 andc r1,r3,r1 /* PP = user? (rw&dirty? 2: 3): 0 */
630 mtspr SPRN_RPA,r1
631 mfspr r3,SPRN_DMISS
632 tlbld r3
633 mfspr r3,SPRN_SRR1 /* Need to restore CR0 */
634 mtcrf 0x80,r3
635 rfi
636DataAddressInvalid:
637 mfspr r3,SPRN_SRR1
638 rlwinm r1,r3,9,6,6 /* Get load/store bit */
639 addis r1,r1,0x2000
640 mtspr SPRN_DSISR,r1
641 mtctr r0 /* Restore CTR */
642 andi. r2,r3,0xFFFF /* Clear upper bits of SRR1 */
643 mtspr SPRN_SRR1,r2
644 mfspr r1,SPRN_DMISS /* Get failing address */
645 rlwinm. r2,r2,0,31,31 /* Check for little endian access */
646 beq 20f /* Jump if big endian */
647 xori r1,r1,3
64820: mtspr SPRN_DAR,r1 /* Set fault address */
649 mfmsr r0 /* Restore "normal" registers */
650 xoris r0,r0,MSR_TGPR>>16
651 mtcrf 0x80,r3 /* Restore CR0 */
652 mtmsr r0
653 b DataAccess
654
655/*
656 * Handle TLB miss for DATA Store on 603/603e
657 */
658 . = 0x1200
659DataStoreTLBMiss:
660/*
661 * r0: stored ctr
662 * r1: linux style pte ( later becomes ppc hardware pte )
663 * r2: ptr to linux-style pte
664 * r3: scratch
665 */
666 mfctr r0
667 /* Get PTE (linux-style) and check access */
668 mfspr r3,SPRN_DMISS
669 lis r1,KERNELBASE@h /* check if kernel address */
670 cmplw 0,r3,r1
671 mfspr r2,SPRN_SPRG3
672 li r1,_PAGE_RW|_PAGE_USER|_PAGE_PRESENT /* access flags */
673 lwz r2,PGDIR(r2)
674 blt+ 112f
675 lis r2,swapper_pg_dir@ha /* if kernel address, use */
676 addi r2,r2,swapper_pg_dir@l /* kernel page table */
677 mfspr r1,SPRN_SRR1 /* and MSR_PR bit from SRR1 */
678 rlwinm r1,r1,32-12,29,29 /* shift MSR_PR to _PAGE_USER posn */
679112: tophys(r2,r2)
680 rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */
681 lwz r2,0(r2) /* get pmd entry */
682 rlwinm. r2,r2,0,0,19 /* extract address of pte page */
683 beq- DataAddressInvalid /* return if no mapping */
684 rlwimi r2,r3,22,20,29 /* insert next 10 bits of address */
685 lwz r3,0(r2) /* get linux-style pte */
686 andc. r1,r1,r3 /* check access & ~permission */
687 bne- DataAddressInvalid /* return if access not permitted */
688 ori r3,r3,_PAGE_ACCESSED|_PAGE_DIRTY
689 /*
690 * NOTE! We are assuming this is not an SMP system, otherwise
691 * we would need to update the pte atomically with lwarx/stwcx.
692 */
693 stw r3,0(r2) /* update PTE (accessed/dirty bits) */
694 /* Convert linux-style PTE to low word of PPC-style PTE */
695 rlwimi r3,r3,32-1,30,30 /* _PAGE_USER -> PP msb */
696 li r1,0xe15 /* clear out reserved bits and M */
697 andc r1,r3,r1 /* PP = user? 2: 0 */
698 mtspr SPRN_RPA,r1
699 mfspr r3,SPRN_DMISS
700 tlbld r3
701 mfspr r3,SPRN_SRR1 /* Need to restore CR0 */
702 mtcrf 0x80,r3
703 rfi
704
705#ifndef CONFIG_ALTIVEC
dc1c1ca3 706#define altivec_assist_exception unknown_exception
14cf11af
PM
707#endif
708
dc1c1ca3 709 EXCEPTION(0x1300, Trap_13, instruction_breakpoint_exception, EXC_XFER_EE)
14cf11af 710 EXCEPTION(0x1400, SMI, SMIException, EXC_XFER_EE)
dc1c1ca3 711 EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_EE)
14cf11af 712#ifdef CONFIG_POWER4
dc1c1ca3
SR
713 EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_EE)
714 EXCEPTION(0x1700, Trap_17, altivec_assist_exception, EXC_XFER_EE)
14cf11af
PM
715 EXCEPTION(0x1800, Trap_18, TAUException, EXC_XFER_STD)
716#else /* !CONFIG_POWER4 */
dc1c1ca3 717 EXCEPTION(0x1600, Trap_16, altivec_assist_exception, EXC_XFER_EE)
14cf11af 718 EXCEPTION(0x1700, Trap_17, TAUException, EXC_XFER_STD)
dc1c1ca3 719 EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_EE)
14cf11af 720#endif /* CONFIG_POWER4 */
dc1c1ca3
SR
721 EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_EE)
722 EXCEPTION(0x1a00, Trap_1a, unknown_exception, EXC_XFER_EE)
723 EXCEPTION(0x1b00, Trap_1b, unknown_exception, EXC_XFER_EE)
724 EXCEPTION(0x1c00, Trap_1c, unknown_exception, EXC_XFER_EE)
725 EXCEPTION(0x1d00, Trap_1d, unknown_exception, EXC_XFER_EE)
726 EXCEPTION(0x1e00, Trap_1e, unknown_exception, EXC_XFER_EE)
727 EXCEPTION(0x1f00, Trap_1f, unknown_exception, EXC_XFER_EE)
14cf11af 728 EXCEPTION(0x2000, RunMode, RunModeException, EXC_XFER_EE)
dc1c1ca3
SR
729 EXCEPTION(0x2100, Trap_21, unknown_exception, EXC_XFER_EE)
730 EXCEPTION(0x2200, Trap_22, unknown_exception, EXC_XFER_EE)
731 EXCEPTION(0x2300, Trap_23, unknown_exception, EXC_XFER_EE)
732 EXCEPTION(0x2400, Trap_24, unknown_exception, EXC_XFER_EE)
733 EXCEPTION(0x2500, Trap_25, unknown_exception, EXC_XFER_EE)
734 EXCEPTION(0x2600, Trap_26, unknown_exception, EXC_XFER_EE)
735 EXCEPTION(0x2700, Trap_27, unknown_exception, EXC_XFER_EE)
736 EXCEPTION(0x2800, Trap_28, unknown_exception, EXC_XFER_EE)
737 EXCEPTION(0x2900, Trap_29, unknown_exception, EXC_XFER_EE)
738 EXCEPTION(0x2a00, Trap_2a, unknown_exception, EXC_XFER_EE)
739 EXCEPTION(0x2b00, Trap_2b, unknown_exception, EXC_XFER_EE)
740 EXCEPTION(0x2c00, Trap_2c, unknown_exception, EXC_XFER_EE)
741 EXCEPTION(0x2d00, Trap_2d, unknown_exception, EXC_XFER_EE)
742 EXCEPTION(0x2e00, Trap_2e, unknown_exception, EXC_XFER_EE)
743 EXCEPTION(0x2f00, MOLTrampoline, unknown_exception, EXC_XFER_EE_LITE)
14cf11af
PM
744
745 .globl mol_trampoline
746 .set mol_trampoline, i0x2f00
747
748 . = 0x3000
749
750AltiVecUnavailable:
751 EXCEPTION_PROLOG
752#ifdef CONFIG_ALTIVEC
753 bne load_up_altivec /* if from user, just load it up */
754#endif /* CONFIG_ALTIVEC */
dc1c1ca3 755 EXC_XFER_EE_LITE(0xf20, altivec_unavailable_exception)
14cf11af
PM
756
757#ifdef CONFIG_PPC64BRIDGE
758DataAccess:
759 EXCEPTION_PROLOG
760 b DataAccessCont
761
762InstructionAccess:
763 EXCEPTION_PROLOG
764 b InstructionAccessCont
765
766DataSegment:
767 EXCEPTION_PROLOG
768 addi r3,r1,STACK_FRAME_OVERHEAD
769 mfspr r4,SPRN_DAR
770 stw r4,_DAR(r11)
dc1c1ca3 771 EXC_XFER_STD(0x380, unknown_exception)
14cf11af
PM
772
773InstructionSegment:
774 EXCEPTION_PROLOG
775 addi r3,r1,STACK_FRAME_OVERHEAD
dc1c1ca3 776 EXC_XFER_STD(0x480, unknown_exception)
14cf11af
PM
777#endif /* CONFIG_PPC64BRIDGE */
778
779#ifdef CONFIG_ALTIVEC
780/* Note that the AltiVec support is closely modeled after the FP
781 * support. Changes to one are likely to be applicable to the
782 * other! */
783load_up_altivec:
784/*
785 * Disable AltiVec for the task which had AltiVec previously,
786 * and save its AltiVec registers in its thread_struct.
787 * Enables AltiVec for use in the kernel on return.
788 * On SMP we know the AltiVec units are free, since we give it up every
789 * switch. -- Kumar
790 */
791 mfmsr r5
792 oris r5,r5,MSR_VEC@h
793 MTMSRD(r5) /* enable use of AltiVec now */
794 isync
795/*
796 * For SMP, we don't do lazy AltiVec switching because it just gets too
797 * horrendously complex, especially when a task switches from one CPU
798 * to another. Instead we call giveup_altivec in switch_to.
799 */
800#ifndef CONFIG_SMP
801 tophys(r6,0)
802 addis r3,r6,last_task_used_altivec@ha
803 lwz r4,last_task_used_altivec@l(r3)
804 cmpwi 0,r4,0
805 beq 1f
806 add r4,r4,r6
807 addi r4,r4,THREAD /* want THREAD of last_task_used_altivec */
808 SAVE_32VRS(0,r10,r4)
809 mfvscr vr0
810 li r10,THREAD_VSCR
811 stvx vr0,r10,r4
812 lwz r5,PT_REGS(r4)
813 add r5,r5,r6
814 lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
815 lis r10,MSR_VEC@h
816 andc r4,r4,r10 /* disable altivec for previous task */
817 stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
8181:
819#endif /* CONFIG_SMP */
820 /* enable use of AltiVec after return */
821 oris r9,r9,MSR_VEC@h
822 mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
823 li r4,1
824 li r10,THREAD_VSCR
825 stw r4,THREAD_USED_VR(r5)
826 lvx vr0,r10,r5
827 mtvscr vr0
828 REST_32VRS(0,r10,r5)
829#ifndef CONFIG_SMP
830 subi r4,r5,THREAD
831 sub r4,r4,r6
832 stw r4,last_task_used_altivec@l(r3)
833#endif /* CONFIG_SMP */
834 /* restore registers and return */
835 /* we haven't used ctr or xer or lr */
836 b fast_exception_return
837
838/*
839 * AltiVec unavailable trap from kernel - print a message, but let
840 * the task use AltiVec in the kernel until it returns to user mode.
841 */
842KernelAltiVec:
843 lwz r3,_MSR(r1)
844 oris r3,r3,MSR_VEC@h
845 stw r3,_MSR(r1) /* enable use of AltiVec after return */
846 lis r3,87f@h
847 ori r3,r3,87f@l
848 mr r4,r2 /* current */
849 lwz r5,_NIP(r1)
850 bl printk
851 b ret_from_except
85287: .string "AltiVec used in kernel (task=%p, pc=%x) \n"
853 .align 4,0
854
855/*
856 * giveup_altivec(tsk)
857 * Disable AltiVec for the task given as the argument,
858 * and save the AltiVec registers in its thread_struct.
859 * Enables AltiVec for use in the kernel on return.
860 */
861
862 .globl giveup_altivec
863giveup_altivec:
864 mfmsr r5
865 oris r5,r5,MSR_VEC@h
866 SYNC
867 MTMSRD(r5) /* enable use of AltiVec now */
868 isync
869 cmpwi 0,r3,0
870 beqlr- /* if no previous owner, done */
871 addi r3,r3,THREAD /* want THREAD of task */
872 lwz r5,PT_REGS(r3)
873 cmpwi 0,r5,0
874 SAVE_32VRS(0, r4, r3)
875 mfvscr vr0
876 li r4,THREAD_VSCR
877 stvx vr0,r4,r3
878 beq 1f
879 lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
880 lis r3,MSR_VEC@h
881 andc r4,r4,r3 /* disable AltiVec for previous task */
882 stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
8831:
884#ifndef CONFIG_SMP
885 li r5,0
886 lis r4,last_task_used_altivec@ha
887 stw r5,last_task_used_altivec@l(r4)
888#endif /* CONFIG_SMP */
889 blr
890#endif /* CONFIG_ALTIVEC */
891
892/*
893 * This code is jumped to from the startup code to copy
894 * the kernel image to physical address 0.
895 */
896relocate_kernel:
897 addis r9,r26,klimit@ha /* fetch klimit */
898 lwz r25,klimit@l(r9)
899 addis r25,r25,-KERNELBASE@h
900 li r3,0 /* Destination base address */
901 li r6,0 /* Destination offset */
902 li r5,0x4000 /* # bytes of memory to copy */
903 bl copy_and_flush /* copy the first 0x4000 bytes */
904 addi r0,r3,4f@l /* jump to the address of 4f */
905 mtctr r0 /* in copy and do the rest. */
906 bctr /* jump to the copy */
9074: mr r5,r25
908 bl copy_and_flush /* copy the rest */
909 b turn_on_mmu
910
911/*
912 * Copy routine used to copy the kernel to start at physical address 0
913 * and flush and invalidate the caches as needed.
914 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
915 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
916 */
917copy_and_flush:
918 addi r5,r5,-4
919 addi r6,r6,-4
9204: li r0,L1_CACHE_LINE_SIZE/4
921 mtctr r0
9223: addi r6,r6,4 /* copy a cache line */
923 lwzx r0,r6,r4
924 stwx r0,r6,r3
925 bdnz 3b
926 dcbst r6,r3 /* write it to memory */
927 sync
928 icbi r6,r3 /* flush the icache line */
929 cmplw 0,r6,r5
930 blt 4b
931 sync /* additional sync needed on g4 */
932 isync
933 addi r5,r5,4
934 addi r6,r6,4
935 blr
936
937#ifdef CONFIG_APUS
938/*
939 * On APUS the physical base address of the kernel is not known at compile
940 * time, which means the __pa/__va constants used are incorrect. In the
941 * __init section is recorded the virtual addresses of instructions using
942 * these constants, so all that has to be done is fix these before
943 * continuing the kernel boot.
944 *
945 * r4 = The physical address of the kernel base.
946 */
947fix_mem_constants:
948 mr r10,r4
949 addis r10,r10,-KERNELBASE@h /* virt_to_phys constant */
950 neg r11,r10 /* phys_to_virt constant */
951
952 lis r12,__vtop_table_begin@h
953 ori r12,r12,__vtop_table_begin@l
954 add r12,r12,r10 /* table begin phys address */
955 lis r13,__vtop_table_end@h
956 ori r13,r13,__vtop_table_end@l
957 add r13,r13,r10 /* table end phys address */
958 subi r12,r12,4
959 subi r13,r13,4
9601: lwzu r14,4(r12) /* virt address of instruction */
961 add r14,r14,r10 /* phys address of instruction */
962 lwz r15,0(r14) /* instruction, now insert top */
963 rlwimi r15,r10,16,16,31 /* half of vp const in low half */
964 stw r15,0(r14) /* of instruction and restore. */
965 dcbst r0,r14 /* write it to memory */
966 sync
967 icbi r0,r14 /* flush the icache line */
968 cmpw r12,r13
969 bne 1b
970 sync /* additional sync needed on g4 */
971 isync
972
973/*
974 * Map the memory where the exception handlers will
975 * be copied to when hash constants have been patched.
976 */
977#ifdef CONFIG_APUS_FAST_EXCEPT
978 lis r8,0xfff0
979#else
980 lis r8,0
981#endif
982 ori r8,r8,0x2 /* 128KB, supervisor */
983 mtspr SPRN_DBAT3U,r8
984 mtspr SPRN_DBAT3L,r8
985
986 lis r12,__ptov_table_begin@h
987 ori r12,r12,__ptov_table_begin@l
988 add r12,r12,r10 /* table begin phys address */
989 lis r13,__ptov_table_end@h
990 ori r13,r13,__ptov_table_end@l
991 add r13,r13,r10 /* table end phys address */
992 subi r12,r12,4
993 subi r13,r13,4
9941: lwzu r14,4(r12) /* virt address of instruction */
995 add r14,r14,r10 /* phys address of instruction */
996 lwz r15,0(r14) /* instruction, now insert top */
997 rlwimi r15,r11,16,16,31 /* half of pv const in low half*/
998 stw r15,0(r14) /* of instruction and restore. */
999 dcbst r0,r14 /* write it to memory */
1000 sync
1001 icbi r0,r14 /* flush the icache line */
1002 cmpw r12,r13
1003 bne 1b
1004
1005 sync /* additional sync needed on g4 */
1006 isync /* No speculative loading until now */
1007 blr
1008
1009/***********************************************************************
1010 * Please note that on APUS the exception handlers are located at the
1011 * physical address 0xfff0000. For this reason, the exception handlers
1012 * cannot use relative branches to access the code below.
1013 ***********************************************************************/
1014#endif /* CONFIG_APUS */
1015
1016#ifdef CONFIG_SMP
1017#ifdef CONFIG_GEMINI
1018 .globl __secondary_start_gemini
1019__secondary_start_gemini:
1020 mfspr r4,SPRN_HID0
1021 ori r4,r4,HID0_ICFI
1022 li r3,0
1023 ori r3,r3,HID0_ICE
1024 andc r4,r4,r3
1025 mtspr SPRN_HID0,r4
1026 sync
1027 b __secondary_start
1028#endif /* CONFIG_GEMINI */
1029
1030 .globl __secondary_start_pmac_0
1031__secondary_start_pmac_0:
1032 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1033 li r24,0
1034 b 1f
1035 li r24,1
1036 b 1f
1037 li r24,2
1038 b 1f
1039 li r24,3
10401:
1041 /* on powersurge, we come in here with IR=0 and DR=1, and DBAT 0
1042 set to map the 0xf0000000 - 0xffffffff region */
1043 mfmsr r0
1044 rlwinm r0,r0,0,28,26 /* clear DR (0x10) */
1045 SYNC
1046 mtmsr r0
1047 isync
1048
1049 .globl __secondary_start
1050__secondary_start:
1051#ifdef CONFIG_PPC64BRIDGE
1052 mfmsr r0
1053 clrldi r0,r0,1 /* make sure it's in 32-bit mode */
1054 SYNC
1055 MTMSRD(r0)
1056 isync
1057#endif
1058 /* Copy some CPU settings from CPU 0 */
1059 bl __restore_cpu_setup
1060
1061 lis r3,-KERNELBASE@h
1062 mr r4,r24
14cf11af
PM
1063 bl call_setup_cpu /* Call setup_cpu for this CPU */
1064#ifdef CONFIG_6xx
1065 lis r3,-KERNELBASE@h
1066 bl init_idle_6xx
1067#endif /* CONFIG_6xx */
1068#ifdef CONFIG_POWER4
1069 lis r3,-KERNELBASE@h
1070 bl init_idle_power4
1071#endif /* CONFIG_POWER4 */
1072
1073 /* get current_thread_info and current */
1074 lis r1,secondary_ti@ha
1075 tophys(r1,r1)
1076 lwz r1,secondary_ti@l(r1)
1077 tophys(r2,r1)
1078 lwz r2,TI_TASK(r2)
1079
1080 /* stack */
1081 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1082 li r0,0
1083 tophys(r3,r1)
1084 stw r0,0(r3)
1085
1086 /* load up the MMU */
1087 bl load_up_mmu
1088
1089 /* ptr to phys current thread */
1090 tophys(r4,r2)
1091 addi r4,r4,THREAD /* phys address of our thread_struct */
1092 CLR_TOP32(r4)
1093 mtspr SPRN_SPRG3,r4
1094 li r3,0
1095 mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
1096
1097 /* enable MMU and jump to start_secondary */
1098 li r4,MSR_KERNEL
1099 FIX_SRR1(r4,r5)
1100 lis r3,start_secondary@h
1101 ori r3,r3,start_secondary@l
1102 mtspr SPRN_SRR0,r3
1103 mtspr SPRN_SRR1,r4
1104 SYNC
1105 RFI
1106#endif /* CONFIG_SMP */
1107
1108/*
1109 * Those generic dummy functions are kept for CPUs not
1110 * included in CONFIG_6xx
1111 */
14cf11af
PM
1112#if !defined(CONFIG_6xx) && !defined(CONFIG_POWER4)
1113_GLOBAL(__save_cpu_setup)
1114 blr
1115_GLOBAL(__restore_cpu_setup)
1116 blr
1117#endif /* !defined(CONFIG_6xx) && !defined(CONFIG_POWER4) */
1118
1119
1120/*
1121 * Load stuff into the MMU. Intended to be called with
1122 * IR=0 and DR=0.
1123 */
1124load_up_mmu:
1125 sync /* Force all PTE updates to finish */
1126 isync
1127 tlbia /* Clear all TLB entries */
1128 sync /* wait for tlbia/tlbie to finish */
1129 TLBSYNC /* ... on all CPUs */
1130 /* Load the SDR1 register (hash table base & size) */
1131 lis r6,_SDR1@ha
1132 tophys(r6,r6)
1133 lwz r6,_SDR1@l(r6)
1134 mtspr SPRN_SDR1,r6
1135#ifdef CONFIG_PPC64BRIDGE
1136 /* clear the ASR so we only use the pseudo-segment registers. */
1137 li r6,0
1138 mtasr r6
1139#endif /* CONFIG_PPC64BRIDGE */
1140 li r0,16 /* load up segment register values */
1141 mtctr r0 /* for context 0 */
1142 lis r3,0x2000 /* Ku = 1, VSID = 0 */
1143 li r4,0
11443: mtsrin r3,r4
1145 addi r3,r3,0x111 /* increment VSID */
1146 addis r4,r4,0x1000 /* address of next segment */
1147 bdnz 3b
1148#ifndef CONFIG_POWER4
1149/* Load the BAT registers with the values set up by MMU_init.
1150 MMU_init takes care of whether we're on a 601 or not. */
1151 mfpvr r3
1152 srwi r3,r3,16
1153 cmpwi r3,1
1154 lis r3,BATS@ha
1155 addi r3,r3,BATS@l
1156 tophys(r3,r3)
1157 LOAD_BAT(0,r3,r4,r5)
1158 LOAD_BAT(1,r3,r4,r5)
1159 LOAD_BAT(2,r3,r4,r5)
1160 LOAD_BAT(3,r3,r4,r5)
1161#endif /* CONFIG_POWER4 */
1162 blr
1163
1164/*
1165 * This is where the main kernel code starts.
1166 */
1167start_here:
1168 /* ptr to current */
1169 lis r2,init_task@h
1170 ori r2,r2,init_task@l
1171 /* Set up for using our exception vectors */
1172 /* ptr to phys current thread */
1173 tophys(r4,r2)
1174 addi r4,r4,THREAD /* init task's THREAD */
1175 CLR_TOP32(r4)
1176 mtspr SPRN_SPRG3,r4
1177 li r3,0
1178 mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
1179
1180 /* stack */
1181 lis r1,init_thread_union@ha
1182 addi r1,r1,init_thread_union@l
1183 li r0,0
1184 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
1185/*
1186 * Do early bootinfo parsing, platform-specific initialization,
1187 * and set up the MMU.
1188 */
1189 mr r3,r31
1190 mr r4,r30
14cf11af
PM
1191 bl machine_init
1192 bl MMU_init
1193
1194#ifdef CONFIG_APUS
1195 /* Copy exception code to exception vector base on APUS. */
1196 lis r4,KERNELBASE@h
1197#ifdef CONFIG_APUS_FAST_EXCEPT
1198 lis r3,0xfff0 /* Copy to 0xfff00000 */
1199#else
1200 lis r3,0 /* Copy to 0x00000000 */
1201#endif
1202 li r5,0x4000 /* # bytes of memory to copy */
1203 li r6,0
1204 bl copy_and_flush /* copy the first 0x4000 bytes */
1205#endif /* CONFIG_APUS */
1206
1207/*
1208 * Go back to running unmapped so we can load up new values
1209 * for SDR1 (hash table pointer) and the segment registers
1210 * and change to using our exception vectors.
1211 */
1212 lis r4,2f@h
1213 ori r4,r4,2f@l
1214 tophys(r4,r4)
1215 li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
1216 FIX_SRR1(r3,r5)
1217 mtspr SPRN_SRR0,r4
1218 mtspr SPRN_SRR1,r3
1219 SYNC
1220 RFI
1221/* Load up the kernel context */
12222: bl load_up_mmu
1223
1224#ifdef CONFIG_BDI_SWITCH
1225 /* Add helper information for the Abatron bdiGDB debugger.
1226 * We do this here because we know the mmu is disabled, and
1227 * will be enabled for real in just a few instructions.
1228 */
1229 lis r5, abatron_pteptrs@h
1230 ori r5, r5, abatron_pteptrs@l
1231 stw r5, 0xf0(r0) /* This much match your Abatron config */
1232 lis r6, swapper_pg_dir@h
1233 ori r6, r6, swapper_pg_dir@l
1234 tophys(r5, r5)
1235 stw r6, 0(r5)
1236#endif /* CONFIG_BDI_SWITCH */
1237
1238/* Now turn on the MMU for real! */
1239 li r4,MSR_KERNEL
1240 FIX_SRR1(r4,r5)
1241 lis r3,start_kernel@h
1242 ori r3,r3,start_kernel@l
1243 mtspr SPRN_SRR0,r3
1244 mtspr SPRN_SRR1,r4
1245 SYNC
1246 RFI
1247
1248/*
1249 * Set up the segment registers for a new context.
1250 */
1251_GLOBAL(set_context)
1252 mulli r3,r3,897 /* multiply context by skew factor */
1253 rlwinm r3,r3,4,8,27 /* VSID = (context & 0xfffff) << 4 */
1254 addis r3,r3,0x6000 /* Set Ks, Ku bits */
1255 li r0,NUM_USER_SEGMENTS
1256 mtctr r0
1257
1258#ifdef CONFIG_BDI_SWITCH
1259 /* Context switch the PTE pointer for the Abatron BDI2000.
1260 * The PGDIR is passed as second argument.
1261 */
1262 lis r5, KERNELBASE@h
1263 lwz r5, 0xf0(r5)
1264 stw r4, 0x4(r5)
1265#endif
1266 li r4,0
1267 isync
12683:
1269#ifdef CONFIG_PPC64BRIDGE
1270 slbie r4
1271#endif /* CONFIG_PPC64BRIDGE */
1272 mtsrin r3,r4
1273 addi r3,r3,0x111 /* next VSID */
1274 rlwinm r3,r3,0,8,3 /* clear out any overflow from VSID field */
1275 addis r4,r4,0x1000 /* address of next segment */
1276 bdnz 3b
1277 sync
1278 isync
1279 blr
1280
1281/*
1282 * An undocumented "feature" of 604e requires that the v bit
1283 * be cleared before changing BAT values.
1284 *
1285 * Also, newer IBM firmware does not clear bat3 and 4 so
1286 * this makes sure it's done.
1287 * -- Cort
1288 */
1289clear_bats:
1290 li r10,0
1291 mfspr r9,SPRN_PVR
1292 rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
1293 cmpwi r9, 1
1294 beq 1f
1295
1296 mtspr SPRN_DBAT0U,r10
1297 mtspr SPRN_DBAT0L,r10
1298 mtspr SPRN_DBAT1U,r10
1299 mtspr SPRN_DBAT1L,r10
1300 mtspr SPRN_DBAT2U,r10
1301 mtspr SPRN_DBAT2L,r10
1302 mtspr SPRN_DBAT3U,r10
1303 mtspr SPRN_DBAT3L,r10
13041:
1305 mtspr SPRN_IBAT0U,r10
1306 mtspr SPRN_IBAT0L,r10
1307 mtspr SPRN_IBAT1U,r10
1308 mtspr SPRN_IBAT1L,r10
1309 mtspr SPRN_IBAT2U,r10
1310 mtspr SPRN_IBAT2L,r10
1311 mtspr SPRN_IBAT3U,r10
1312 mtspr SPRN_IBAT3L,r10
1313BEGIN_FTR_SECTION
1314 /* Here's a tweak: at this point, CPU setup have
1315 * not been called yet, so HIGH_BAT_EN may not be
1316 * set in HID0 for the 745x processors. However, it
1317 * seems that doesn't affect our ability to actually
1318 * write to these SPRs.
1319 */
1320 mtspr SPRN_DBAT4U,r10
1321 mtspr SPRN_DBAT4L,r10
1322 mtspr SPRN_DBAT5U,r10
1323 mtspr SPRN_DBAT5L,r10
1324 mtspr SPRN_DBAT6U,r10
1325 mtspr SPRN_DBAT6L,r10
1326 mtspr SPRN_DBAT7U,r10
1327 mtspr SPRN_DBAT7L,r10
1328 mtspr SPRN_IBAT4U,r10
1329 mtspr SPRN_IBAT4L,r10
1330 mtspr SPRN_IBAT5U,r10
1331 mtspr SPRN_IBAT5L,r10
1332 mtspr SPRN_IBAT6U,r10
1333 mtspr SPRN_IBAT6L,r10
1334 mtspr SPRN_IBAT7U,r10
1335 mtspr SPRN_IBAT7L,r10
1336END_FTR_SECTION_IFSET(CPU_FTR_HAS_HIGH_BATS)
1337 blr
1338
1339flush_tlbs:
1340 lis r10, 0x40
13411: addic. r10, r10, -0x1000
1342 tlbie r10
1343 blt 1b
1344 sync
1345 blr
1346
1347mmu_off:
1348 addi r4, r3, __after_mmu_off - _start
1349 mfmsr r3
1350 andi. r0,r3,MSR_DR|MSR_IR /* MMU enabled? */
1351 beqlr
1352 andc r3,r3,r0
1353 mtspr SPRN_SRR0,r4
1354 mtspr SPRN_SRR1,r3
1355 sync
1356 RFI
1357
1358#ifndef CONFIG_POWER4
1359/*
1360 * Use the first pair of BAT registers to map the 1st 16MB
1361 * of RAM to KERNELBASE. From this point on we can't safely
1362 * call OF any more.
1363 */
1364initial_bats:
1365 lis r11,KERNELBASE@h
1366#ifndef CONFIG_PPC64BRIDGE
1367 mfspr r9,SPRN_PVR
1368 rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
1369 cmpwi 0,r9,1
1370 bne 4f
1371 ori r11,r11,4 /* set up BAT registers for 601 */
1372 li r8,0x7f /* valid, block length = 8MB */
1373 oris r9,r11,0x800000@h /* set up BAT reg for 2nd 8M */
1374 oris r10,r8,0x800000@h /* set up BAT reg for 2nd 8M */
1375 mtspr SPRN_IBAT0U,r11 /* N.B. 601 has valid bit in */
1376 mtspr SPRN_IBAT0L,r8 /* lower BAT register */
1377 mtspr SPRN_IBAT1U,r9
1378 mtspr SPRN_IBAT1L,r10
1379 isync
1380 blr
1381#endif /* CONFIG_PPC64BRIDGE */
1382
13834: tophys(r8,r11)
1384#ifdef CONFIG_SMP
1385 ori r8,r8,0x12 /* R/W access, M=1 */
1386#else
1387 ori r8,r8,2 /* R/W access */
1388#endif /* CONFIG_SMP */
1389#ifdef CONFIG_APUS
1390 ori r11,r11,BL_8M<<2|0x2 /* set up 8MB BAT registers for 604 */
1391#else
1392 ori r11,r11,BL_256M<<2|0x2 /* set up BAT registers for 604 */
1393#endif /* CONFIG_APUS */
1394
1395#ifdef CONFIG_PPC64BRIDGE
1396 /* clear out the high 32 bits in the BAT */
1397 clrldi r11,r11,32
1398 clrldi r8,r8,32
1399#endif /* CONFIG_PPC64BRIDGE */
1400 mtspr SPRN_DBAT0L,r8 /* N.B. 6xx (not 601) have valid */
1401 mtspr SPRN_DBAT0U,r11 /* bit in upper BAT register */
1402 mtspr SPRN_IBAT0L,r8
1403 mtspr SPRN_IBAT0U,r11
1404 isync
1405 blr
1406
1407#if !defined(CONFIG_APUS) && defined(CONFIG_BOOTX_TEXT)
1408setup_disp_bat:
1409 /*
1410 * setup the display bat prepared for us in prom.c
1411 */
1412 mflr r8
1413 bl reloc_offset
1414 mtlr r8
1415 addis r8,r3,disp_BAT@ha
1416 addi r8,r8,disp_BAT@l
1417 lwz r11,0(r8)
1418 lwz r8,4(r8)
1419 mfspr r9,SPRN_PVR
1420 rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
1421 cmpwi 0,r9,1
1422 beq 1f
1423 mtspr SPRN_DBAT3L,r8
1424 mtspr SPRN_DBAT3U,r11
1425 blr
14261: mtspr SPRN_IBAT3L,r8
1427 mtspr SPRN_IBAT3U,r11
1428 blr
1429
1430#endif /* !defined(CONFIG_APUS) && defined(CONFIG_BOOTX_TEXT) */
1431
1432#else /* CONFIG_POWER4 */
1433/*
1434 * Load up the SDR1 and segment register values now
1435 * since we don't have the BATs.
1436 * Also make sure we are running in 32-bit mode.
1437 */
1438
1439initial_mm_power4:
1440 addis r14,r3,_SDR1@ha /* get the value from _SDR1 */
1441 lwz r14,_SDR1@l(r14) /* assume hash table below 4GB */
1442 mtspr SPRN_SDR1,r14
1443 slbia
1444 lis r4,0x2000 /* set pseudo-segment reg 12 */
1445 ori r5,r4,0x0ccc
1446 mtsr 12,r5
1447#if 0
1448 ori r5,r4,0x0888 /* set pseudo-segment reg 8 */
1449 mtsr 8,r5 /* (for access to serial port) */
1450#endif
1451#ifdef CONFIG_BOOTX_TEXT
1452 ori r5,r4,0x0999 /* set pseudo-segment reg 9 */
1453 mtsr 9,r5 /* (for access to screen) */
1454#endif
1455 mfmsr r0
1456 clrldi r0,r0,1
1457 sync
1458 mtmsr r0
1459 isync
1460 blr
1461
1462#endif /* CONFIG_POWER4 */
1463
1464#ifdef CONFIG_8260
1465/* Jump into the system reset for the rom.
1466 * We first disable the MMU, and then jump to the ROM reset address.
1467 *
1468 * r3 is the board info structure, r4 is the location for starting.
1469 * I use this for building a small kernel that can load other kernels,
1470 * rather than trying to write or rely on a rom monitor that can tftp load.
1471 */
1472 .globl m8260_gorom
1473m8260_gorom:
1474 mfmsr r0
1475 rlwinm r0,r0,0,17,15 /* clear MSR_EE in r0 */
1476 sync
1477 mtmsr r0
1478 sync
1479 mfspr r11, SPRN_HID0
1480 lis r10, 0
1481 ori r10,r10,HID0_ICE|HID0_DCE
1482 andc r11, r11, r10
1483 mtspr SPRN_HID0, r11
1484 isync
1485 li r5, MSR_ME|MSR_RI
1486 lis r6,2f@h
1487 addis r6,r6,-KERNELBASE@h
1488 ori r6,r6,2f@l
1489 mtspr SPRN_SRR0,r6
1490 mtspr SPRN_SRR1,r5
1491 isync
1492 sync
1493 rfi
14942:
1495 mtlr r4
1496 blr
1497#endif
1498
1499
1500/*
1501 * We put a few things here that have to be page-aligned.
1502 * This stuff goes at the beginning of the data segment,
1503 * which is page-aligned.
1504 */
1505 .data
1506 .globl sdata
1507sdata:
1508 .globl empty_zero_page
1509empty_zero_page:
1510 .space 4096
1511
1512 .globl swapper_pg_dir
1513swapper_pg_dir:
1514 .space 4096
1515
1516/*
1517 * This space gets a copy of optional info passed to us by the bootstrap
1518 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
1519 */
1520 .globl cmd_line
1521cmd_line:
1522 .space 512
1523
1524 .globl intercept_table
1525intercept_table:
1526 .long 0, 0, i0x200, i0x300, i0x400, 0, i0x600, i0x700
1527 .long i0x800, 0, 0, 0, 0, i0xd00, 0, 0
1528 .long 0, 0, 0, i0x1300, 0, 0, 0, 0
1529 .long 0, 0, 0, 0, 0, 0, 0, 0
1530 .long 0, 0, 0, 0, 0, 0, 0, 0
1531 .long 0, 0, 0, 0, 0, 0, 0, 0
1532
1533/* Room for two PTE pointers, usually the kernel and current user pointers
1534 * to their respective root page table.
1535 */
1536abatron_pteptrs:
1537 .space 8