2 * Kernel execution entry point code.
4 * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
5 * Initial PowerPC version.
6 * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
8 * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
9 * Low-level exception handers, MMU support, and rewrite.
10 * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
11 * PowerPC 8xx modifications.
12 * Copyright (c) 1998-1999 TiVo, Inc.
13 * PowerPC 403GCX modifications.
14 * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
15 * PowerPC 403GCX/405GP modifications.
16 * Copyright 2000 MontaVista Software Inc.
17 * PPC405 modifications
18 * PowerPC 403GCX/405GP modifications.
19 * Author: MontaVista Software, Inc.
20 * frank_rowand@mvista.com or source@mvista.com
21 * debbie_chu@mvista.com
22 * Copyright 2002-2005 MontaVista Software, Inc.
23 * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
25 * This program is free software; you can redistribute it and/or modify it
26 * under the terms of the GNU General Public License as published by the
27 * Free Software Foundation; either version 2 of the License, or (at your
28 * option) any later version.
31 #include <linux/init.h>
32 #include <asm/processor.h>
35 #include <asm/pgtable.h>
36 #include <asm/cputable.h>
37 #include <asm/thread_info.h>
38 #include <asm/ppc_asm.h>
39 #include <asm/asm-offsets.h>
40 #include <asm/synch.h>
41 #include "head_booke.h"
44 /* As with the other PowerPC ports, it is expected that when code
45 * execution begins here, the following registers contain valid, yet
46 * optional, information:
48 * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
49 * r4 - Starting address of the init RAM disk
50 * r5 - Ending address of the init RAM disk
51 * r6 - Start of kernel command line string (e.g. "mem=128")
52 * r7 - End of kernel command line string
59 * Reserve a word at a fixed location to store the address
64 * Save parameters we are passed
71 li r24,0 /* CPU number */
76 * This is where the main kernel code starts.
83 /* ptr to current thread */
84 addi r4,r2,THREAD /* init task's THREAD */
85 mtspr SPRN_SPRG_THREAD,r4
88 lis r1,init_thread_union@h
89 ori r1,r1,init_thread_union@l
91 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
96 * Decide what sort of machine this is and initialize the MMU.
106 /* Setup PTE pointers for the Abatron bdiGDB */
107 lis r6, swapper_pg_dir@h
108 ori r6, r6, swapper_pg_dir@l
109 lis r5, abatron_pteptrs@h
110 ori r5, r5, abatron_pteptrs@l
112 ori r4, r4, KERNELBASE@l
113 stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
116 /* Clear the Machine Check Syndrome Register */
121 lis r4,start_kernel@h
122 ori r4,r4,start_kernel@l
124 ori r3,r3,MSR_KERNEL@l
127 rfi /* change context and jump to start_kernel */
130 * Interrupt vector entry code
132 * The Book E MMUs are always on so we don't need to handle
133 * interrupts in real mode as with previous PPC processors. In
134 * this case we handle interrupts in the kernel virtual address
137 * Interrupt vectors are dynamically placed relative to the
138 * interrupt prefix as determined by the address of interrupt_base.
139 * The interrupt vectors offsets are programmed using the labels
140 * for each interrupt vector entry.
142 * Interrupt vectors must be aligned on a 16 byte boundary.
143 * We align on a 32 byte cache line boundary for good measure.
147 /* Critical Input Interrupt */
148 CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception)
150 /* Machine Check Interrupt */
151 CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
152 MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
154 /* Data Storage Interrupt */
155 DATA_STORAGE_EXCEPTION
157 /* Instruction Storage Interrupt */
158 INSTRUCTION_STORAGE_EXCEPTION
160 /* External Input Interrupt */
161 EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
163 /* Alignment Interrupt */
166 /* Program Interrupt */
169 /* Floating Point Unavailable Interrupt */
170 #ifdef CONFIG_PPC_FPU
171 FP_UNAVAILABLE_EXCEPTION
173 EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
175 /* System Call Interrupt */
176 START_EXCEPTION(SystemCall)
177 NORMAL_EXCEPTION_PROLOG
178 EXC_XFER_EE_LITE(0x0c00, DoSyscall)
180 /* Auxillary Processor Unavailable Interrupt */
181 EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
183 /* Decrementer Interrupt */
184 DECREMENTER_EXCEPTION
186 /* Fixed Internal Timer Interrupt */
187 /* TODO: Add FIT support */
188 EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE)
190 /* Watchdog Timer Interrupt */
191 /* TODO: Add watchdog support */
192 #ifdef CONFIG_BOOKE_WDT
193 CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException)
195 CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception)
198 /* Data TLB Error Interrupt */
199 START_EXCEPTION(DataTLBError44x)
200 mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
201 mtspr SPRN_SPRG_WSCRATCH1, r11
202 mtspr SPRN_SPRG_WSCRATCH2, r12
203 mtspr SPRN_SPRG_WSCRATCH3, r13
205 mtspr SPRN_SPRG_WSCRATCH4, r11
206 mfspr r10, SPRN_DEAR /* Get faulting address */
208 /* If we are faulting a kernel address, we have to use the
209 * kernel page tables.
211 lis r11, PAGE_OFFSET@h
214 lis r11, swapper_pg_dir@h
215 ori r11, r11, swapper_pg_dir@l
218 rlwinm r12,r12,0,0,23 /* Clear TID */
222 /* Get the PGD for the current thread */
224 mfspr r11,SPRN_SPRG_THREAD
227 /* Load PID into MMUCR TID */
229 mfspr r13,SPRN_PID /* Get PID */
230 rlwimi r12,r13,0,24,31 /* Set TID */
235 /* Mask of required permission bits. Note that while we
236 * do copy ESR:ST to _PAGE_RW position as trying to write
237 * to an RO page is pretty common, we don't do it with
238 * _PAGE_DIRTY. We could do it, but it's a fairly rare
239 * event so I'd rather take the overhead when it happens
240 * rather than adding an instruction here. We should measure
241 * whether the whole thing is worth it in the first place
242 * as we could avoid loading SPRN_ESR completely in the first
245 * TODO: Is it worth doing that mfspr & rlwimi in the first
246 * place or can we save a couple of instructions here ?
249 li r13,_PAGE_PRESENT|_PAGE_ACCESSED
250 rlwimi r13,r12,10,30,30
253 /* Compute pgdir/pmd offset */
254 rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
255 lwzx r11, r12, r11 /* Get pgd/pmd entry */
256 rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
257 beq 2f /* Bail if no table */
259 /* Compute pte address */
260 rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
261 lwz r11, 0(r12) /* Get high word of pte entry */
262 lwz r12, 4(r12) /* Get low word of pte entry */
264 lis r10,tlb_44x_index@ha
266 andc. r13,r13,r12 /* Check permission */
268 /* Load the next available TLB index */
269 lwz r13,tlb_44x_index@l(r10)
271 bne 2f /* Bail if permission mismach */
273 /* Increment, rollover, and store TLB index */
276 /* Compare with watermark (instruction gets patched) */
277 .globl tlb_44x_patch_hwater_D
278 tlb_44x_patch_hwater_D:
279 cmpwi 0,r13,1 /* reserve entries */
283 /* Store the next available TLB index */
284 stw r13,tlb_44x_index@l(r10)
286 /* Re-load the faulting address */
289 /* Jump to common tlb load */
290 b finish_tlb_load_44x
293 /* The bailout. Restore registers to pre-exception conditions
294 * and call the heavyweights to help us out.
296 mfspr r11, SPRN_SPRG_RSCRATCH4
298 mfspr r13, SPRN_SPRG_RSCRATCH3
299 mfspr r12, SPRN_SPRG_RSCRATCH2
300 mfspr r11, SPRN_SPRG_RSCRATCH1
301 mfspr r10, SPRN_SPRG_RSCRATCH0
304 /* Instruction TLB Error Interrupt */
306 * Nearly the same as above, except we get our
307 * information from different registers and bailout
308 * to a different point.
310 START_EXCEPTION(InstructionTLBError44x)
311 mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
312 mtspr SPRN_SPRG_WSCRATCH1, r11
313 mtspr SPRN_SPRG_WSCRATCH2, r12
314 mtspr SPRN_SPRG_WSCRATCH3, r13
316 mtspr SPRN_SPRG_WSCRATCH4, r11
317 mfspr r10, SPRN_SRR0 /* Get faulting address */
319 /* If we are faulting a kernel address, we have to use the
320 * kernel page tables.
322 lis r11, PAGE_OFFSET@h
325 lis r11, swapper_pg_dir@h
326 ori r11, r11, swapper_pg_dir@l
329 rlwinm r12,r12,0,0,23 /* Clear TID */
333 /* Get the PGD for the current thread */
335 mfspr r11,SPRN_SPRG_THREAD
338 /* Load PID into MMUCR TID */
340 mfspr r13,SPRN_PID /* Get PID */
341 rlwimi r12,r13,0,24,31 /* Set TID */
346 /* Make up the required permissions */
347 li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
349 /* Compute pgdir/pmd offset */
350 rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
351 lwzx r11, r12, r11 /* Get pgd/pmd entry */
352 rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
353 beq 2f /* Bail if no table */
355 /* Compute pte address */
356 rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
357 lwz r11, 0(r12) /* Get high word of pte entry */
358 lwz r12, 4(r12) /* Get low word of pte entry */
360 lis r10,tlb_44x_index@ha
362 andc. r13,r13,r12 /* Check permission */
364 /* Load the next available TLB index */
365 lwz r13,tlb_44x_index@l(r10)
367 bne 2f /* Bail if permission mismach */
369 /* Increment, rollover, and store TLB index */
372 /* Compare with watermark (instruction gets patched) */
373 .globl tlb_44x_patch_hwater_I
374 tlb_44x_patch_hwater_I:
375 cmpwi 0,r13,1 /* reserve entries */
379 /* Store the next available TLB index */
380 stw r13,tlb_44x_index@l(r10)
382 /* Re-load the faulting address */
385 /* Jump to common TLB load point */
386 b finish_tlb_load_44x
389 /* The bailout. Restore registers to pre-exception conditions
390 * and call the heavyweights to help us out.
392 mfspr r11, SPRN_SPRG_RSCRATCH4
394 mfspr r13, SPRN_SPRG_RSCRATCH3
395 mfspr r12, SPRN_SPRG_RSCRATCH2
396 mfspr r11, SPRN_SPRG_RSCRATCH1
397 mfspr r10, SPRN_SPRG_RSCRATCH0
401 * Both the instruction and data TLB miss get to this
402 * point to load the TLB.
404 * r11 - PTE high word value
405 * r12 - PTE low word value
407 * MMUCR - loaded with proper value when we get here
408 * Upon exit, we reload everything and RFI.
411 /* Combine RPN & ERPN an write WS 0 */
412 rlwimi r11,r12,0,0,31-PAGE_SHIFT
413 tlbwe r11,r13,PPC44x_TLB_XLAT
416 * Create WS1. This is the faulting address (EPN),
417 * page size, and valid flag.
419 li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE
420 /* Insert valid and page size */
421 rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31
422 tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */
425 li r10,0xf85 /* Mask to apply from PTE */
426 rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
427 and r11,r12,r10 /* Mask PTE bits to keep */
428 andi. r10,r12,_PAGE_USER /* User page ? */
429 beq 1f /* nope, leave U bits empty */
430 rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
431 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */
433 /* Done...restore registers and get out of here.
435 mfspr r11, SPRN_SPRG_RSCRATCH4
437 mfspr r13, SPRN_SPRG_RSCRATCH3
438 mfspr r12, SPRN_SPRG_RSCRATCH2
439 mfspr r11, SPRN_SPRG_RSCRATCH1
440 mfspr r10, SPRN_SPRG_RSCRATCH0
441 rfi /* Force context change */
443 /* TLB error interrupts for 476
445 #ifdef CONFIG_PPC_47x
446 START_EXCEPTION(DataTLBError47x)
447 mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
448 mtspr SPRN_SPRG_WSCRATCH1,r11
449 mtspr SPRN_SPRG_WSCRATCH2,r12
450 mtspr SPRN_SPRG_WSCRATCH3,r13
452 mtspr SPRN_SPRG_WSCRATCH4,r11
453 mfspr r10,SPRN_DEAR /* Get faulting address */
455 /* If we are faulting a kernel address, we have to use the
456 * kernel page tables.
458 lis r11,PAGE_OFFSET@h
461 lis r11,swapper_pg_dir@h
462 ori r11,r11, swapper_pg_dir@l
463 li r12,0 /* MMUCR = 0 */
466 /* Get the PGD for the current thread and setup MMUCR */
467 3: mfspr r11,SPRN_SPRG3
469 mfspr r12,SPRN_PID /* Get PID */
470 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
472 /* Mask of required permission bits. Note that while we
473 * do copy ESR:ST to _PAGE_RW position as trying to write
474 * to an RO page is pretty common, we don't do it with
475 * _PAGE_DIRTY. We could do it, but it's a fairly rare
476 * event so I'd rather take the overhead when it happens
477 * rather than adding an instruction here. We should measure
478 * whether the whole thing is worth it in the first place
479 * as we could avoid loading SPRN_ESR completely in the first
482 * TODO: Is it worth doing that mfspr & rlwimi in the first
483 * place or can we save a couple of instructions here ?
486 li r13,_PAGE_PRESENT|_PAGE_ACCESSED
487 rlwimi r13,r12,10,30,30
490 /* Compute pgdir/pmd offset */
491 rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
492 lwzx r11,r12,r11 /* Get pgd/pmd entry */
494 /* Word 0 is EPN,V,TS,DSIZ */
495 li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
496 rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
500 /* XXX can we do better ? Need to make sure tlbwe has established
501 * latch V bit in MMUCR0 before the PTE is loaded further down */
506 rlwinm. r12,r11,0,0,20 /* Extract pt base address */
507 /* Compute pte address */
508 rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
509 beq 2f /* Bail if no table */
510 lwz r11,0(r12) /* Get high word of pte entry */
512 /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
513 * bottom of r12 to create a data dependency... We can also use r10
514 * as destination nowadays
519 lwz r12,4(r12) /* Get low word of pte entry */
521 andc. r13,r13,r12 /* Check permission */
523 /* Jump to common tlb load */
524 beq finish_tlb_load_47x
526 2: /* The bailout. Restore registers to pre-exception conditions
527 * and call the heavyweights to help us out.
529 mfspr r11,SPRN_SPRG_RSCRATCH4
531 mfspr r13,SPRN_SPRG_RSCRATCH3
532 mfspr r12,SPRN_SPRG_RSCRATCH2
533 mfspr r11,SPRN_SPRG_RSCRATCH1
534 mfspr r10,SPRN_SPRG_RSCRATCH0
537 /* Instruction TLB Error Interrupt */
539 * Nearly the same as above, except we get our
540 * information from different registers and bailout
541 * to a different point.
543 START_EXCEPTION(InstructionTLBError47x)
544 mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
545 mtspr SPRN_SPRG_WSCRATCH1,r11
546 mtspr SPRN_SPRG_WSCRATCH2,r12
547 mtspr SPRN_SPRG_WSCRATCH3,r13
549 mtspr SPRN_SPRG_WSCRATCH4,r11
550 mfspr r10,SPRN_SRR0 /* Get faulting address */
552 /* If we are faulting a kernel address, we have to use the
553 * kernel page tables.
555 lis r11,PAGE_OFFSET@h
558 lis r11,swapper_pg_dir@h
559 ori r11,r11, swapper_pg_dir@l
560 li r12,0 /* MMUCR = 0 */
563 /* Get the PGD for the current thread and setup MMUCR */
564 3: mfspr r11,SPRN_SPRG_THREAD
566 mfspr r12,SPRN_PID /* Get PID */
567 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
569 /* Make up the required permissions */
570 li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
573 /* Compute pgdir/pmd offset */
574 rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
575 lwzx r11,r12,r11 /* Get pgd/pmd entry */
577 /* Word 0 is EPN,V,TS,DSIZ */
578 li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
579 rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
583 /* XXX can we do better ? Need to make sure tlbwe has established
584 * latch V bit in MMUCR0 before the PTE is loaded further down */
589 rlwinm. r12,r11,0,0,20 /* Extract pt base address */
590 /* Compute pte address */
591 rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
592 beq 2f /* Bail if no table */
594 lwz r11,0(r12) /* Get high word of pte entry */
595 /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
596 * bottom of r12 to create a data dependency... We can also use r10
597 * as destination nowadays
602 lwz r12,4(r12) /* Get low word of pte entry */
604 andc. r13,r13,r12 /* Check permission */
606 /* Jump to common TLB load point */
607 beq finish_tlb_load_47x
609 2: /* The bailout. Restore registers to pre-exception conditions
610 * and call the heavyweights to help us out.
612 mfspr r11, SPRN_SPRG_RSCRATCH4
614 mfspr r13, SPRN_SPRG_RSCRATCH3
615 mfspr r12, SPRN_SPRG_RSCRATCH2
616 mfspr r11, SPRN_SPRG_RSCRATCH1
617 mfspr r10, SPRN_SPRG_RSCRATCH0
621 * Both the instruction and data TLB miss get to this
622 * point to load the TLB.
624 * r11 - PTE high word value
625 * r12 - PTE low word value
627 * MMUCR - loaded with proper value when we get here
628 * Upon exit, we reload everything and RFI.
631 /* Combine RPN & ERPN an write WS 1 */
632 rlwimi r11,r12,0,0,31-PAGE_SHIFT
635 /* And make up word 2 */
636 li r10,0xf85 /* Mask to apply from PTE */
637 rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
638 and r11,r12,r10 /* Mask PTE bits to keep */
639 andi. r10,r12,_PAGE_USER /* User page ? */
640 beq 1f /* nope, leave U bits empty */
641 rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
644 /* Done...restore registers and get out of here.
646 mfspr r11, SPRN_SPRG_RSCRATCH4
648 mfspr r13, SPRN_SPRG_RSCRATCH3
649 mfspr r12, SPRN_SPRG_RSCRATCH2
650 mfspr r11, SPRN_SPRG_RSCRATCH1
651 mfspr r10, SPRN_SPRG_RSCRATCH0
654 #endif /* CONFIG_PPC_47x */
656 /* Debug Interrupt */
658 * This statement needs to exist at the end of the IVPR
659 * definition just in case you end up taking a debug
660 * exception within another exception.
669 * Adjust the machine check IVOR on 440A cores
671 _GLOBAL(__fixup_440A_mcheck)
672 li r3,MachineCheckA@l
678 * extern void giveup_altivec(struct task_struct *prev)
680 * The 44x core does not have an AltiVec unit.
682 _GLOBAL(giveup_altivec)
686 * extern void giveup_fpu(struct task_struct *prev)
688 * The 44x core does not have an FPU.
690 #ifndef CONFIG_PPC_FPU
697 #ifdef CONFIG_BDI_SWITCH
698 /* Context switch the PTE pointer for the Abatron BDI2000.
699 * The PGDIR is the second parameter.
701 lis r5, abatron_pteptrs@h
702 ori r5, r5, abatron_pteptrs@l
706 isync /* Force context change */
710 * Init CPU state. This is called at boot time or for secondary CPUs
711 * to setup initial TLB entries, setup IVORs, etc...
714 _GLOBAL(init_cpu_state)
716 #ifdef CONFIG_PPC_47x
717 /* We use the PVR to differenciate 44x cores from 476 */
720 cmplwi cr0,r3,PVR_476@h
722 cmplwi cr0,r3,PVR_476_ISS@h
724 #endif /* CONFIG_PPC_47x */
727 * In case the firmware didn't do it, we apply some workarounds
728 * that are good for all 440 core variants here
731 rlwinm r3,r3,0,0,27 /* disable icache prefetch */
738 * Set up the initial MMU state for 44x
740 * We are still executing code at the virtual address
741 * mappings set by the firmware for the base of RAM.
743 * We first invalidate all TLB entries but the one
744 * we are running from. We then load the KERNELBASE
745 * mappings so we can begin to use kernel addresses
746 * natively and so the interrupt vector locations are
747 * permanently pinned (necessary since Book E
748 * implementations always have translation enabled).
750 * TODO: Use the known TLB entry we are running from to
751 * determine which physical region we are located
752 * in. This can be used to determine where in RAM
753 * (on a shared CPU system) or PCI memory space
754 * (on a DRAMless system) we are located.
755 * For now, we assume a perfect world which means
756 * we are located at the base of DRAM (physical 0).
760 * Search TLB for entry that we are currently using.
761 * Invalidate all entries but the one we are using.
763 /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
764 mfspr r3,SPRN_PID /* Get PID */
765 mfmsr r4 /* Get MSR */
766 andi. r4,r4,MSR_IS@l /* TS=1? */
767 beq wmmucr /* If not, leave STS=0 */
768 oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */
769 wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
772 bl invstr /* Find our address */
773 invstr: mflr r5 /* Make it accessible */
774 tlbsx r23,0,r5 /* Find entry we are in */
775 li r4,0 /* Start at TLB entry 0 */
776 li r3,0 /* Set PAGEID inval value */
777 1: cmpw r23,r4 /* Is this our entry? */
778 beq skpinv /* If so, skip the inval */
779 tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
780 skpinv: addi r4,r4,1 /* Increment */
781 cmpwi r4,64 /* Are we done? */
782 bne 1b /* If not, repeat */
783 isync /* If so, context change */
786 * Configure and load pinned entry into TLB slot 63.
790 ori r3,r3,PAGE_OFFSET@l
792 /* Kernel is at the base of RAM */
793 li r4, 0 /* Load the kernel physical address */
795 /* Load the kernel PID = 0 */
800 /* Initialize MMUCR */
806 clrrwi r3,r3,10 /* Mask off the effective page number */
807 ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
810 clrrwi r4,r4,10 /* Mask off the real page number */
811 /* ERPN is 0 for first 4GB page */
814 /* Added guarded bit to protect against speculative loads/stores */
816 ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
818 li r0,63 /* TLB slot 63 */
820 tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
821 tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */
822 tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
824 /* Force context change */
833 /* If necessary, invalidate original entry we used */
837 tlbwe r6,r23,PPC44x_TLB_PAGEID
841 #ifdef CONFIG_PPC_EARLY_DEBUG_44x
842 /* Add UART mapping for early debug. */
845 lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
846 ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K
849 lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
850 ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
853 li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G)
854 li r0,62 /* TLB slot 0 */
856 tlbwe r3,r0,PPC44x_TLB_PAGEID
857 tlbwe r4,r0,PPC44x_TLB_XLAT
858 tlbwe r5,r0,PPC44x_TLB_ATTRIB
860 /* Force context change */
862 #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
864 /* Establish the interrupt vector offsets */
865 SET_IVOR(0, CriticalInput);
866 SET_IVOR(1, MachineCheck);
867 SET_IVOR(2, DataStorage);
868 SET_IVOR(3, InstructionStorage);
869 SET_IVOR(4, ExternalInput);
870 SET_IVOR(5, Alignment);
871 SET_IVOR(6, Program);
872 SET_IVOR(7, FloatingPointUnavailable);
873 SET_IVOR(8, SystemCall);
874 SET_IVOR(9, AuxillaryProcessorUnavailable);
875 SET_IVOR(10, Decrementer);
876 SET_IVOR(11, FixedIntervalTimer);
877 SET_IVOR(12, WatchdogTimer);
878 SET_IVOR(13, DataTLBError44x);
879 SET_IVOR(14, InstructionTLBError44x);
880 SET_IVOR(15, DebugCrit);
885 #ifdef CONFIG_PPC_47x
889 /* Entry point for secondary 47x processors */
890 _GLOBAL(start_secondary_47x)
891 mr r24,r3 /* CPU number */
895 /* Now we need to bolt the rest of kernel memory which
896 * is done in C code. We must be careful because our task
897 * struct or our stack can (and will probably) be out
898 * of reach of the initial 256M TLB entry, so we use a
899 * small temporary stack in .bss for that. This works
900 * because only one CPU at a time can be in this code
902 lis r1,temp_boot_stack@h
903 ori r1,r1,temp_boot_stack@l
904 addi r1,r1,1024-STACK_FRAME_OVERHEAD
907 bl mmu_init_secondary
909 /* Now we can get our task struct and real stack pointer */
911 /* Get current_thread_info and current */
912 lis r1,secondary_ti@ha
913 lwz r1,secondary_ti@l(r1)
916 /* Current stack pointer */
917 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
921 /* Kernel stack for exception entry in SPRG3 */
922 addi r4,r2,THREAD /* init task's THREAD */
927 #endif /* CONFIG_SMP */
930 * Set up the initial MMU state for 44x
932 * We are still executing code at the virtual address
933 * mappings set by the firmware for the base of RAM.
937 /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
938 mfspr r3,SPRN_PID /* Get PID */
939 mfmsr r4 /* Get MSR */
940 andi. r4,r4,MSR_IS@l /* TS=1? */
941 beq 1f /* If not, leave STS=0 */
942 oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */
943 1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
946 /* Find the entry we are running from */
958 /* Initialize MMUCR */
963 clear_all_utlb_entries:
965 #; Set initial values.
972 #; Align the loop to speed things up.
989 #; Restore original entry.
991 oris r23,r23,0x8000 /* specify the way */
997 * Configure and load pinned entry into TLB for the kernel core
1000 lis r3,PAGE_OFFSET@h
1001 ori r3,r3,PAGE_OFFSET@l
1003 /* Kernel is at the base of RAM */
1004 li r4, 0 /* Load the kernel physical address */
1006 /* Load the kernel PID = 0 */
1012 clrrwi r3,r3,12 /* Mask off the effective page number */
1013 ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M
1016 clrrwi r4,r4,12 /* Mask off the real page number */
1017 /* ERPN is 0 for first 4GB page */
1020 ori r5,r5,PPC47x_TLB2_S_RWX
1022 ori r5,r5,PPC47x_TLB2_M
1025 /* We write to way 0 and bolted 0 */
1032 * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix
1035 LOAD_REG_IMMEDIATE(r3, 0x9abcdef0)
1038 LOAD_REG_IMMEDIATE(r3, 0x12345670)
1041 /* Force context change */
1050 /* Invalidate original entry we used */
1052 rlwinm r24,r24,0,21,19 /* clear the "valid" bit */
1057 isync /* Clear out the shadow TLB entries */
1059 #ifdef CONFIG_PPC_EARLY_DEBUG_44x
1060 /* Add UART mapping for early debug. */
1063 lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
1064 ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M
1067 lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
1068 ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
1071 li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG)
1073 /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same
1074 * congruence class as the kernel, we need to make sure of it at
1082 /* Force context change */
1084 #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
1086 /* Establish the interrupt vector offsets */
1087 SET_IVOR(0, CriticalInput);
1088 SET_IVOR(1, MachineCheckA);
1089 SET_IVOR(2, DataStorage);
1090 SET_IVOR(3, InstructionStorage);
1091 SET_IVOR(4, ExternalInput);
1092 SET_IVOR(5, Alignment);
1093 SET_IVOR(6, Program);
1094 SET_IVOR(7, FloatingPointUnavailable);
1095 SET_IVOR(8, SystemCall);
1096 SET_IVOR(9, AuxillaryProcessorUnavailable);
1097 SET_IVOR(10, Decrementer);
1098 SET_IVOR(11, FixedIntervalTimer);
1099 SET_IVOR(12, WatchdogTimer);
1100 SET_IVOR(13, DataTLBError47x);
1101 SET_IVOR(14, InstructionTLBError47x);
1102 SET_IVOR(15, DebugCrit);
1104 /* We configure icbi to invalidate 128 bytes at a time since the
1105 * current 32-bit kernel code isn't too happy with icache != dcache
1113 #endif /* CONFIG_PPC_47x */
1116 * Here we are back to code that is common between 44x and 47x
1118 * We proceed to further kernel initialization and return to the
1122 /* Establish the interrupt vector base */
1123 lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
1126 addis r22,r22,KERNELBASE@h
1132 * We put a few things here that have to be page-aligned. This stuff
1133 * goes at the beginning of the data segment, which is page-aligned.
1139 .globl empty_zero_page
1144 * To support >32-bit physical addresses, we use an 8KB pgdir.
1146 .globl swapper_pg_dir
1148 .space PGD_TABLE_SIZE
1151 * Room for two PTE pointers, usually the kernel and current user pointers
1152 * to their respective root page table.
1161 #endif /* CONFIG_SMP */