3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
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.
12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
15 * This file contains the low-level support and setup for the
16 * PowerPC-64 platform, including trap and interrupt dispatch.
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.
24 #include <linux/threads.h>
28 #include <asm/ppc_asm.h>
29 #include <asm/asm-offsets.h>
31 #include <asm/cputable.h>
32 #include <asm/setup.h>
33 #include <asm/hvcall.h>
34 #include <asm/iseries/lpar_map.h>
35 #include <asm/thread_info.h>
36 #include <asm/firmware.h>
37 #include <asm/page_64.h>
38 #include <asm/exception.h>
39 #include <asm/irqflags.h>
42 * We layout physical memory as follows:
43 * 0x0000 - 0x00ff : Secondary processor spin code
44 * 0x0100 - 0x2fff : pSeries Interrupt prologs
45 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
46 * 0x6000 - 0x6fff : Initial (CPU0) segment table
47 * 0x7000 - 0x7fff : FWNMI data area
48 * 0x8000 - : Early init and support code
56 * SPRG0 reserved for hypervisor
57 * SPRG1 temp - used to save gpr
58 * SPRG2 temp - used to save gpr
59 * SPRG3 virt addr of paca
63 * Entering into this code we make the following assumptions:
65 * 1. The MMU is off & open firmware is running in real mode.
66 * 2. The kernel is entered at __start
69 * 1. The MMU is on (as it always is for iSeries)
70 * 2. The kernel is entered at system_reset_iSeries
77 /* NOP this out unconditionally */
79 b .__start_initialization_multiplatform
82 /* Catch branch to 0 in real mode */
85 /* Secondary processors spin on this value until it goes to 1. */
86 .globl __secondary_hold_spinloop
87 __secondary_hold_spinloop:
90 /* Secondary processors write this value with their cpu # */
91 /* after they enter the spin loop immediately below. */
92 .globl __secondary_hold_acknowledge
93 __secondary_hold_acknowledge:
96 #ifdef CONFIG_PPC_ISERIES
98 * At offset 0x20, there is a pointer to iSeries LPAR data.
99 * This is required by the hypervisor
102 .llong hvReleaseData-KERNELBASE
103 #endif /* CONFIG_PPC_ISERIES */
107 * The following code is used to hold secondary processors
108 * in a spin loop after they have entered the kernel, but
109 * before the bulk of the kernel has been relocated. This code
110 * is relocated to physical address 0x60 before prom_init is run.
111 * All of it must fit below the first exception vector at 0x100.
113 _GLOBAL(__secondary_hold)
116 mtmsrd r24 /* RI on */
118 /* Grab our physical cpu number */
121 /* Tell the master cpu we're here */
122 /* Relocation is off & we are located at an address less */
123 /* than 0x100, so only need to grab low order offset. */
124 std r24,__secondary_hold_acknowledge@l(0)
127 /* All secondary cpus wait here until told to start. */
128 100: ld r4,__secondary_hold_spinloop@l(0)
132 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
133 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
141 /* This value is used to mark exception frames on the stack. */
144 .tc ID_72656773_68657265[TC],0x7265677368657265
148 * This is the start of the interrupt handlers for pSeries
149 * This code runs with relocation off.
152 .globl __start_interrupts
155 STD_EXCEPTION_PSERIES(0x100, system_reset)
158 _machine_check_pSeries:
160 mtspr SPRN_SPRG1,r13 /* save r13 */
161 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
164 .globl data_access_pSeries
173 rlwimi r13,r12,16,0x20
176 beq do_stab_bolted_pSeries
179 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
180 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
183 .globl data_access_slb_pSeries
184 data_access_slb_pSeries:
187 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
188 std r3,PACA_EXSLB+EX_R3(r13)
190 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
193 /* Keep that around for when we re-implement dynamic VSIDs */
195 bge slb_miss_user_pseries
196 #endif /* __DISABLED__ */
197 std r10,PACA_EXSLB+EX_R10(r13)
198 std r11,PACA_EXSLB+EX_R11(r13)
199 std r12,PACA_EXSLB+EX_R12(r13)
201 std r10,PACA_EXSLB+EX_R13(r13)
202 mfspr r12,SPRN_SRR1 /* and SRR1 */
203 b .slb_miss_realmode /* Rel. branch works in real mode */
205 STD_EXCEPTION_PSERIES(0x400, instruction_access)
208 .globl instruction_access_slb_pSeries
209 instruction_access_slb_pSeries:
212 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
213 std r3,PACA_EXSLB+EX_R3(r13)
214 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
215 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
218 /* Keep that around for when we re-implement dynamic VSIDs */
220 bge slb_miss_user_pseries
221 #endif /* __DISABLED__ */
222 std r10,PACA_EXSLB+EX_R10(r13)
223 std r11,PACA_EXSLB+EX_R11(r13)
224 std r12,PACA_EXSLB+EX_R12(r13)
226 std r10,PACA_EXSLB+EX_R13(r13)
227 mfspr r12,SPRN_SRR1 /* and SRR1 */
228 b .slb_miss_realmode /* Rel. branch works in real mode */
230 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
231 STD_EXCEPTION_PSERIES(0x600, alignment)
232 STD_EXCEPTION_PSERIES(0x700, program_check)
233 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
234 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
235 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
236 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
239 .globl system_call_pSeries
247 oris r12,r12,system_call_common@h
248 ori r12,r12,system_call_common@l
250 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
254 b . /* prevent speculative execution */
256 STD_EXCEPTION_PSERIES(0xd00, single_step)
257 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
259 /* We need to deal with the Altivec unavailable exception
260 * here which is at 0xf20, thus in the middle of the
261 * prolog code of the PerformanceMonitor one. A little
262 * trickery is thus necessary
265 b performance_monitor_pSeries
267 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
269 #ifdef CONFIG_CBE_RAS
270 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
271 #endif /* CONFIG_CBE_RAS */
272 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
273 #ifdef CONFIG_CBE_RAS
274 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
275 #endif /* CONFIG_CBE_RAS */
276 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
277 #ifdef CONFIG_CBE_RAS
278 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
279 #endif /* CONFIG_CBE_RAS */
283 /*** pSeries interrupt support ***/
285 /* moved from 0xf00 */
286 STD_EXCEPTION_PSERIES(., performance_monitor)
289 * An interrupt came in while soft-disabled; clear EE in SRR1,
290 * clear paca->hard_enabled and return.
293 stb r10,PACAHARDIRQEN(r13)
295 ld r9,PACA_EXGEN+EX_R9(r13)
297 rldicl r10,r10,48,1 /* clear MSR_EE */
300 ld r10,PACA_EXGEN+EX_R10(r13)
306 do_stab_bolted_pSeries:
309 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
312 * We have some room here we use that to put
313 * the peries slb miss user trampoline code so it's reasonably
314 * away from slb_miss_user_common to avoid problems with rfid
316 * This is used for when the SLB miss handler has to go virtual,
317 * which doesn't happen for now anymore but will once we re-implement
318 * dynamic VSIDs for shared page tables
321 slb_miss_user_pseries:
322 std r10,PACA_EXGEN+EX_R10(r13)
323 std r11,PACA_EXGEN+EX_R11(r13)
324 std r12,PACA_EXGEN+EX_R12(r13)
326 ld r11,PACA_EXSLB+EX_R9(r13)
327 ld r12,PACA_EXSLB+EX_R3(r13)
328 std r10,PACA_EXGEN+EX_R13(r13)
329 std r11,PACA_EXGEN+EX_R9(r13)
330 std r12,PACA_EXGEN+EX_R3(r13)
333 mfspr r11,SRR0 /* save SRR0 */
334 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
335 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
337 mfspr r12,SRR1 /* and SRR1 */
340 b . /* prevent spec. execution */
341 #endif /* __DISABLED__ */
343 #ifdef CONFIG_PPC_PSERIES
345 * Vectors for the FWNMI option. Share common code.
347 .globl system_reset_fwnmi
351 mtspr SPRN_SPRG1,r13 /* save r13 */
352 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
354 .globl machine_check_fwnmi
358 mtspr SPRN_SPRG1,r13 /* save r13 */
359 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
361 #endif /* CONFIG_PPC_PSERIES */
363 /*** Common interrupt handlers ***/
365 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
368 * Machine check is different because we use a different
369 * save area: PACA_EXMC instead of PACA_EXGEN.
372 .globl machine_check_common
373 machine_check_common:
374 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
378 addi r3,r1,STACK_FRAME_OVERHEAD
379 bl .machine_check_exception
382 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
383 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
384 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
385 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
386 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
387 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
388 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
389 #ifdef CONFIG_ALTIVEC
390 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
392 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
394 #ifdef CONFIG_CBE_RAS
395 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
396 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
397 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
398 #endif /* CONFIG_CBE_RAS */
401 * Here we have detected that the kernel stack pointer is bad.
402 * R9 contains the saved CR, r13 points to the paca,
403 * r10 contains the (bad) kernel stack pointer,
404 * r11 and r12 contain the saved SRR0 and SRR1.
405 * We switch to using an emergency stack, save the registers there,
406 * and call kernel_bad_stack(), which panics.
409 ld r1,PACAEMERGSP(r13)
410 subi r1,r1,64+INT_FRAME_SIZE
431 lhz r12,PACA_TRAP_SAVE(r13)
433 addi r11,r1,INT_FRAME_SIZE
438 1: addi r3,r1,STACK_FRAME_OVERHEAD
443 * Return from an exception with minimal checks.
444 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
445 * If interrupts have been enabled, or anything has been
446 * done that might have changed the scheduling status of
447 * any task or sent any task a signal, you should use
448 * ret_from_except or ret_from_except_lite instead of this.
450 fast_exc_return_irq: /* restores irq state too */
452 TRACE_AND_RESTORE_IRQ(r3);
454 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
455 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
458 .globl fast_exception_return
459 fast_exception_return:
462 andi. r3,r12,MSR_RI /* check if RI is set */
465 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
468 ACCOUNT_CPU_USER_EXIT(r3, r4)
484 rldicl r10,r10,48,1 /* clear EE */
485 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
493 b . /* prevent speculative execution */
497 1: addi r3,r1,STACK_FRAME_OVERHEAD
498 bl .unrecoverable_exception
502 * Here r13 points to the paca, r9 contains the saved CR,
503 * SRR0 and SRR1 are saved in r11 and r12,
504 * r9 - r13 are saved in paca->exgen.
507 .globl data_access_common
510 std r10,PACA_EXGEN+EX_DAR(r13)
512 stw r10,PACA_EXGEN+EX_DSISR(r13)
513 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
514 ld r3,PACA_EXGEN+EX_DAR(r13)
515 lwz r4,PACA_EXGEN+EX_DSISR(r13)
517 b .do_hash_page /* Try to handle as hpte fault */
520 .globl instruction_access_common
521 instruction_access_common:
522 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
526 b .do_hash_page /* Try to handle as hpte fault */
529 * Here is the common SLB miss user that is used when going to virtual
530 * mode for SLB misses, that is currently not used
534 .globl slb_miss_user_common
535 slb_miss_user_common:
537 std r3,PACA_EXGEN+EX_DAR(r13)
538 stw r9,PACA_EXGEN+EX_CCR(r13)
539 std r10,PACA_EXGEN+EX_LR(r13)
540 std r11,PACA_EXGEN+EX_SRR0(r13)
541 bl .slb_allocate_user
543 ld r10,PACA_EXGEN+EX_LR(r13)
544 ld r3,PACA_EXGEN+EX_R3(r13)
545 lwz r9,PACA_EXGEN+EX_CCR(r13)
546 ld r11,PACA_EXGEN+EX_SRR0(r13)
550 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
551 beq- unrecov_user_slb
559 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
565 ld r9,PACA_EXGEN+EX_R9(r13)
566 ld r10,PACA_EXGEN+EX_R10(r13)
567 ld r11,PACA_EXGEN+EX_R11(r13)
568 ld r12,PACA_EXGEN+EX_R12(r13)
569 ld r13,PACA_EXGEN+EX_R13(r13)
574 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
575 ld r4,PACA_EXGEN+EX_DAR(r13)
582 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
585 1: addi r3,r1,STACK_FRAME_OVERHEAD
586 bl .unrecoverable_exception
589 #endif /* __DISABLED__ */
593 * r13 points to the PACA, r9 contains the saved CR,
594 * r12 contain the saved SRR1, SRR0 is still ready for return
595 * r3 has the faulting address
596 * r9 - r13 are saved in paca->exslb.
597 * r3 is saved in paca->slb_r3
598 * We assume we aren't going to take any exceptions during this procedure.
600 _GLOBAL(slb_miss_realmode)
603 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
604 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
606 bl .slb_allocate_realmode
608 /* All done -- return from exception. */
610 ld r10,PACA_EXSLB+EX_LR(r13)
611 ld r3,PACA_EXSLB+EX_R3(r13)
612 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
613 #ifdef CONFIG_PPC_ISERIES
615 ld r11,PACALPPACAPTR(r13)
616 ld r11,LPPACASRR0(r11) /* get SRR0 value */
617 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
618 #endif /* CONFIG_PPC_ISERIES */
622 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
628 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
631 #ifdef CONFIG_PPC_ISERIES
635 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
636 #endif /* CONFIG_PPC_ISERIES */
637 ld r9,PACA_EXSLB+EX_R9(r13)
638 ld r10,PACA_EXSLB+EX_R10(r13)
639 ld r11,PACA_EXSLB+EX_R11(r13)
640 ld r12,PACA_EXSLB+EX_R12(r13)
641 ld r13,PACA_EXSLB+EX_R13(r13)
643 b . /* prevent speculative execution */
646 #ifdef CONFIG_PPC_ISERIES
649 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
650 #endif /* CONFIG_PPC_ISERIES */
653 LOAD_HANDLER(r10,unrecov_slb)
656 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
662 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
665 1: addi r3,r1,STACK_FRAME_OVERHEAD
666 bl .unrecoverable_exception
670 .globl hardware_interrupt_common
671 .globl hardware_interrupt_entry
672 hardware_interrupt_common:
673 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
675 hardware_interrupt_entry:
678 bl .ppc64_runlatch_on
679 END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
680 addi r3,r1,STACK_FRAME_OVERHEAD
682 b .ret_from_except_lite
684 #ifdef CONFIG_PPC_970_NAP
687 std r9,TI_LOCAL_FLAGS(r11)
688 ld r10,_LINK(r1) /* make idle task do the */
689 std r10,_NIP(r1) /* equivalent of a blr */
694 .globl alignment_common
697 std r10,PACA_EXGEN+EX_DAR(r13)
699 stw r10,PACA_EXGEN+EX_DSISR(r13)
700 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
701 ld r3,PACA_EXGEN+EX_DAR(r13)
702 lwz r4,PACA_EXGEN+EX_DSISR(r13)
706 addi r3,r1,STACK_FRAME_OVERHEAD
708 bl .alignment_exception
712 .globl program_check_common
713 program_check_common:
714 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
716 addi r3,r1,STACK_FRAME_OVERHEAD
718 bl .program_check_exception
722 .globl fp_unavailable_common
723 fp_unavailable_common:
724 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
725 bne 1f /* if from user, just load it up */
727 addi r3,r1,STACK_FRAME_OVERHEAD
729 bl .kernel_fp_unavailable_exception
734 .globl altivec_unavailable_common
735 altivec_unavailable_common:
736 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
737 #ifdef CONFIG_ALTIVEC
739 bne .load_up_altivec /* if from user, just load it up */
740 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
743 addi r3,r1,STACK_FRAME_OVERHEAD
745 bl .altivec_unavailable_exception
748 #ifdef CONFIG_ALTIVEC
750 * load_up_altivec(unused, unused, tsk)
751 * Disable VMX for the task which had it previously,
752 * and save its vector registers in its thread_struct.
753 * Enables the VMX for use in the kernel on return.
754 * On SMP we know the VMX is free, since we give it up every
755 * switch (ie, no lazy save of the vector registers).
756 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
758 _STATIC(load_up_altivec)
759 mfmsr r5 /* grab the current MSR */
761 mtmsrd r5 /* enable use of VMX now */
765 * For SMP, we don't do lazy VMX switching because it just gets too
766 * horrendously complex, especially when a task switches from one CPU
767 * to another. Instead we call giveup_altvec in switch_to.
768 * VRSAVE isn't dealt with here, that is done in the normal context
769 * switch code. Note that we could rely on vrsave value to eventually
770 * avoid saving all of the VREGs here...
773 ld r3,last_task_used_altivec@got(r2)
777 /* Save VMX state to last_task_used_altivec's THREAD struct */
783 /* Disable VMX for last_task_used_altivec */
785 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
788 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
790 #endif /* CONFIG_SMP */
791 /* Hack: if we get an altivec unavailable trap with VRSAVE
792 * set to all zeros, we assume this is a broken application
793 * that fails to set it properly, and thus we switch it to
802 /* enable use of VMX after return */
803 ld r4,PACACURRENT(r13)
804 addi r5,r4,THREAD /* Get THREAD */
805 oris r12,r12,MSR_VEC@h
809 stw r4,THREAD_USED_VR(r5)
814 /* Update last_task_used_math to 'current' */
815 subi r4,r5,THREAD /* Back to 'current' */
817 #endif /* CONFIG_SMP */
818 /* restore registers and return */
819 b fast_exception_return
820 #endif /* CONFIG_ALTIVEC */
826 _STATIC(do_hash_page)
830 andis. r0,r4,0xa450 /* weird error? */
831 bne- handle_page_fault /* if not, try to insert a HPTE */
833 andis. r0,r4,0x0020 /* Is it a segment table fault? */
834 bne- do_ste_alloc /* If so handle it */
835 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
838 * On iSeries, we soft-disable interrupts here, then
839 * hard-enable interrupts so that the hash_page code can spin on
840 * the hash_table_lock without problems on a shared processor.
845 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
846 * and will clobber volatile registers when irq tracing is enabled
847 * so we need to reload them. It may be possible to be smarter here
848 * and move the irq tracing elsewhere but let's keep it simple for
851 #ifdef CONFIG_TRACE_IRQFLAGS
857 #endif /* CONFIG_TRACE_IRQFLAGS */
859 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
860 * accessing a userspace segment (even from the kernel). We assume
861 * kernel addresses always have the high bit set.
863 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
864 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
865 orc r0,r12,r0 /* MSR_PR | ~high_bit */
866 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
867 ori r4,r4,1 /* add _PAGE_PRESENT */
868 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
871 * r3 contains the faulting address
872 * r4 contains the required access permissions
873 * r5 contains the trap number
875 * at return r3 = 0 for success
877 bl .hash_page /* build HPTE if possible */
878 cmpdi r3,0 /* see if hash_page succeeded */
882 * If we had interrupts soft-enabled at the point where the
883 * DSI/ISI occurred, and an interrupt came in during hash_page,
885 * We jump to ret_from_except_lite rather than fast_exception_return
886 * because ret_from_except_lite will check for and handle pending
887 * interrupts if necessary.
890 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
894 * Here we have interrupts hard-disabled, so it is sufficient
895 * to restore paca->{soft,hard}_enable and get out.
897 beq fast_exc_return_irq /* Return from exception on success */
898 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
900 /* For a hash failure, we don't bother re-enabling interrupts */
904 * hash_page couldn't handle it, set soft interrupt enable back
905 * to what it was before the trap. Note that .raw_local_irq_restore
906 * handles any interrupts pending at this point.
909 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
910 bl .raw_local_irq_restore
913 /* Here we have a page fault that hash_page can't handle. */
918 addi r3,r1,STACK_FRAME_OVERHEAD
924 addi r3,r1,STACK_FRAME_OVERHEAD
929 13: b .ret_from_except_lite
931 /* We have a page fault that hash_page could handle but HV refused
936 addi r3,r1,STACK_FRAME_OVERHEAD
941 /* here we have a segment miss */
943 bl .ste_allocate /* try to insert stab entry */
945 bne- handle_page_fault
946 b fast_exception_return
949 * r13 points to the PACA, r9 contains the saved CR,
950 * r11 and r12 contain the saved SRR0 and SRR1.
951 * r9 - r13 are saved in paca->exslb.
952 * We assume we aren't going to take any exceptions during this procedure.
953 * We assume (DAR >> 60) == 0xc.
956 _GLOBAL(do_stab_bolted)
957 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
958 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
960 /* Hash to the primary group */
961 ld r10,PACASTABVIRT(r13)
964 rldimi r10,r11,7,52 /* r10 = first ste of the group */
967 /* This is a kernel address, so protovsid = ESID */
968 ASM_VSID_SCRAMBLE(r11, r9, 256M)
969 rldic r9,r11,12,16 /* r9 = vsid << 12 */
971 /* Search the primary group for a free entry */
972 1: ld r11,0(r10) /* Test valid bit of the current ste */
979 /* Stick for only searching the primary group for now. */
980 /* At least for now, we use a very simple random castout scheme */
981 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
983 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
986 /* r10 currently points to an ste one past the group of interest */
987 /* make it point to the randomly selected entry */
989 or r10,r10,r11 /* r10 is the entry to invalidate */
991 isync /* mark the entry invalid */
993 rldicl r11,r11,56,1 /* clear the valid bit */
998 clrrdi r11,r11,28 /* Get the esid part of the ste */
1001 2: std r9,8(r10) /* Store the vsid part of the ste */
1004 mfspr r11,SPRN_DAR /* Get the new esid */
1005 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1006 ori r11,r11,0x90 /* Turn on valid and kp */
1007 std r11,0(r10) /* Put new entry back into the stab */
1011 /* All done -- return from exception. */
1012 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1013 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1015 andi. r10,r12,MSR_RI
1018 mtcrf 0x80,r9 /* restore CR */
1026 ld r9,PACA_EXSLB+EX_R9(r13)
1027 ld r10,PACA_EXSLB+EX_R10(r13)
1028 ld r11,PACA_EXSLB+EX_R11(r13)
1029 ld r12,PACA_EXSLB+EX_R12(r13)
1030 ld r13,PACA_EXSLB+EX_R13(r13)
1032 b . /* prevent speculative execution */
1035 * Space for CPU0's segment table.
1037 * On iSeries, the hypervisor must fill in at least one entry before
1038 * we get control (with relocate on). The address is given to the hv
1039 * as a page number (see xLparMap below), so this must be at a
1040 * fixed address (the linker can't compute (u64)&initial_stab >>
1043 . = STAB0_OFFSET /* 0x6000 */
1048 #ifdef CONFIG_PPC_PSERIES
1050 * Data area reserved for FWNMI option.
1051 * This address (0x7000) is fixed by the RPA.
1054 .globl fwnmi_data_area
1056 #endif /* CONFIG_PPC_PSERIES */
1058 /* iSeries does not use the FWNMI stuff, so it is safe to put
1059 * this here, even if we later allow kernels that will boot on
1060 * both pSeries and iSeries */
1061 #ifdef CONFIG_PPC_ISERIES
1065 .quad HvEsidsToMap /* xNumberEsids */
1066 .quad HvRangesToMap /* xNumberRanges */
1067 .quad STAB0_PAGE /* xSegmentTableOffs */
1068 .zero 40 /* xRsvd */
1069 /* xEsids (HvEsidsToMap entries of 2 quads) */
1070 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1071 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1072 .quad VMALLOC_START_ESID /* xKernelEsid */
1073 .quad VMALLOC_START_VSID /* xKernelVsid */
1074 /* xRanges (HvRangesToMap entries of 3 quads) */
1075 .quad HvPagesToMap /* xPages */
1076 .quad 0 /* xOffset */
1077 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1079 #endif /* CONFIG_PPC_ISERIES */
1081 #ifdef CONFIG_PPC_PSERIES
1083 #endif /* CONFIG_PPC_PSERIES */
1086 * On pSeries and most other platforms, secondary processors spin
1087 * in the following code.
1088 * At entry, r3 = this processor's number (physical cpu id)
1090 _GLOBAL(generic_secondary_smp_init)
1093 /* turn on 64-bit mode */
1096 /* Set up a paca value for this processor. Since we have the
1097 * physical cpu id in r24, we need to search the pacas to find
1098 * which logical id maps to our physical one.
1100 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1101 li r5,0 /* logical cpu id */
1102 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1103 cmpw r6,r24 /* Compare to our id */
1105 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1110 mr r3,r24 /* not found, copy phys to r3 */
1111 b .kexec_wait /* next kernel might do better */
1113 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1114 /* From now on, r24 is expected to be logical cpuid */
1117 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1122 b 3b /* Never go on non-SMP */
1125 beq 3b /* Loop until told to go */
1127 /* See if we need to call a cpu state restore handler */
1128 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1130 ld r23,CPU_SPEC_RESTORE(r23)
1137 4: /* Create a temp kernel stack for use before relocation is on. */
1138 ld r1,PACAEMERGSP(r13)
1139 subi r1,r1,STACK_FRAME_OVERHEAD
1146 andi. r0,r3,MSR_IR|MSR_DR
1153 b . /* prevent speculative execution */
1157 * Here is our main kernel entry point. We support currently 2 kind of entries
1158 * depending on the value of r5.
1160 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1163 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1164 * DT block, r4 is a physical pointer to the kernel itself
1167 _GLOBAL(__start_initialization_multiplatform)
1169 * Are we booted from a PROM Of-type client-interface ?
1173 b .__boot_from_prom /* yes -> prom */
1175 /* Save parameters */
1179 /* Make sure we are running in 64 bits mode */
1182 /* Setup some critical 970 SPRs before switching MMU off */
1185 cmpwi r0,0x39 /* 970 */
1187 cmpwi r0,0x3c /* 970FX */
1189 cmpwi r0,0x44 /* 970MP */
1191 cmpwi r0,0x45 /* 970GX */
1193 1: bl .__cpu_preinit_ppc970
1196 /* Switch off MMU if not already */
1197 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1200 b .__after_prom_start
1202 _INIT_STATIC(__boot_from_prom)
1203 /* Save parameters */
1211 * Align the stack to 16-byte boundary
1212 * Depending on the size and layout of the ELF sections in the initial
1213 * boot binary, the stack pointer will be unalignet on PowerMac
1217 /* Make sure we are running in 64 bits mode */
1220 /* put a relocation offset into r3 */
1223 LOAD_REG_IMMEDIATE(r2,__toc_start)
1227 /* Relocate the TOC from a virt addr to a real addr */
1230 /* Restore parameters */
1237 /* Do all of the interaction with OF client interface */
1239 /* We never return */
1242 _STATIC(__after_prom_start)
1245 * We need to run with __start at physical address PHYSICAL_START.
1246 * This will leave some code in the first 256B of
1247 * real memory, which are reserved for software use.
1248 * The remainder of the first page is loaded with the fixed
1249 * interrupt vectors. The next two pages are filled with
1250 * unknown exception placeholders.
1252 * Note: This process overwrites the OF exception vectors.
1253 * r26 == relocation offset
1258 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1260 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1262 // XXX FIXME: Use phys returned by OF (r30)
1263 add r4,r27,r26 /* source addr */
1264 /* current address of _start */
1265 /* i.e. where we are running */
1266 /* the source addr */
1268 cmpdi r4,0 /* In some cases the loader may */
1270 b .start_here_multiplatform /* have already put us at zero */
1271 /* so we can skip the copy. */
1272 1: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1275 li r6,0x100 /* Start offset, the first 0x100 */
1276 /* bytes were copied earlier. */
1278 bl .copy_and_flush /* copy the first n bytes */
1279 /* this includes the code being */
1280 /* executed here. */
1282 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1283 mtctr r0 /* that we just made/relocated */
1286 4: LOAD_REG_IMMEDIATE(r5,klimit)
1288 ld r5,0(r5) /* get the value of klimit */
1290 bl .copy_and_flush /* copy the rest */
1291 b .start_here_multiplatform
1294 * Copy routine used to copy the kernel to start at physical address 0
1295 * and flush and invalidate the caches as needed.
1296 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1297 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1299 * Note: this routine *only* clobbers r0, r6 and lr
1301 _GLOBAL(copy_and_flush)
1304 4: li r0,8 /* Use the smallest common */
1305 /* denominator cache line */
1306 /* size. This results in */
1307 /* extra cache line flushes */
1308 /* but operation is correct. */
1309 /* Can't get cache line size */
1310 /* from NACA as it is being */
1313 mtctr r0 /* put # words/line in ctr */
1314 3: addi r6,r6,8 /* copy a cache line */
1318 dcbst r6,r3 /* write it to memory */
1320 icbi r6,r3 /* flush the icache line */
1332 #ifdef CONFIG_PPC_PMAC
1334 * On PowerMac, secondary processors starts from the reset vector, which
1335 * is temporarily turned into a call to one of the functions below.
1340 .globl __secondary_start_pmac_0
1341 __secondary_start_pmac_0:
1342 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1352 _GLOBAL(pmac_secondary_start)
1353 /* turn on 64-bit mode */
1356 /* Copy some CPU settings from CPU 0 */
1357 bl .__restore_cpu_ppc970
1359 /* pSeries do that early though I don't think we really need it */
1362 mtmsrd r3 /* RI on */
1364 /* Set up a paca value for this processor. */
1365 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1366 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1367 add r13,r13,r4 /* for this processor. */
1368 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1370 /* Create a temp kernel stack for use before relocation is on. */
1371 ld r1,PACAEMERGSP(r13)
1372 subi r1,r1,STACK_FRAME_OVERHEAD
1376 #endif /* CONFIG_PPC_PMAC */
1379 * This function is called after the master CPU has released the
1380 * secondary processors. The execution environment is relocation off.
1381 * The paca for this processor has the following fields initialized at
1383 * 1. Processor number
1384 * 2. Segment table pointer (virtual address)
1385 * On entry the following are set:
1386 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1387 * r24 = cpu# (in Linux terms)
1388 * r13 = paca virtual address
1389 * SPRG3 = paca virtual address
1391 .globl __secondary_start
1393 /* Set thread priority to MEDIUM */
1399 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1400 bl .early_setup_secondary
1402 /* Initialize the kernel stack. Just a repeat for iSeries. */
1403 LOAD_REG_ADDR(r3, current_set)
1404 sldi r28,r24,3 /* get current_set[cpu#] */
1406 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1407 std r1,PACAKSAVE(r13)
1409 /* Clear backchain so we get nice backtraces */
1413 /* enable MMU and jump to start_secondary */
1414 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1415 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1416 #ifdef CONFIG_PPC_ISERIES
1417 BEGIN_FW_FTR_SECTION
1420 stb r8,PACAHARDIRQEN(r13)
1421 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1423 BEGIN_FW_FTR_SECTION
1424 stb r7,PACAHARDIRQEN(r13)
1425 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1426 stb r7,PACASOFTIRQEN(r13)
1431 b . /* prevent speculative execution */
1434 * Running with relocation on at this point. All we want to do is
1435 * zero the stack back-chain pointer before going into C code.
1437 _GLOBAL(start_secondary_prolog)
1439 std r3,0(r1) /* Zero the stack frame pointer */
1445 * This subroutine clobbers r11 and r12
1447 _GLOBAL(enable_64b_mode)
1448 mfmsr r11 /* grab the current MSR */
1450 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1453 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1460 * This is where the main kernel code starts.
1462 _INIT_STATIC(start_here_multiplatform)
1463 /* get a new offset, now that the kernel has moved. */
1467 /* Clear out the BSS. It may have been done in prom_init,
1468 * already but that's irrelevant since prom_init will soon
1469 * be detached from the kernel completely. Besides, we need
1470 * to clear it now for kexec-style entry.
1472 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1473 LOAD_REG_IMMEDIATE(r8,__bss_start)
1474 sub r11,r11,r8 /* bss size */
1475 addi r11,r11,7 /* round up to an even double word */
1476 rldicl. r11,r11,61,3 /* shift right by 3 */
1480 mtctr r11 /* zero this many doublewords */
1487 mtmsrd r6 /* RI on */
1489 /* The following gets the stack and TOC set up with the regs */
1490 /* pointing to the real addr of the kernel stack. This is */
1491 /* all done to support the C function call below which sets */
1492 /* up the htab. This is done because we have relocated the */
1493 /* kernel but are still running in real mode. */
1495 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1498 /* set up a stack pointer (physical address) */
1499 addi r1,r3,THREAD_SIZE
1501 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1503 /* set up the TOC (physical address) */
1504 LOAD_REG_IMMEDIATE(r2,__toc_start)
1509 /* Set initial ptr to current */
1510 LOAD_REG_IMMEDIATE(r4, init_task)
1511 std r4,PACACURRENT(r13)
1513 /* Do very early kernel initializations, including initial hash table,
1514 * stab and slb setup before we turn on relocation. */
1516 /* Restore parameters passed from prom_init/kexec */
1520 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1521 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1525 b . /* prevent speculative execution */
1527 /* This is where all platforms converge execution */
1528 _INIT_GLOBAL(start_here_common)
1529 /* relocation is on at this point */
1531 /* The following code sets up the SP and TOC now that we are */
1532 /* running with translation enabled. */
1534 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1536 /* set up the stack */
1537 addi r1,r3,THREAD_SIZE
1539 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1543 std r1,PACAKSAVE(r13)
1547 /* Load up the kernel context */
1550 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1551 #ifdef CONFIG_PPC_ISERIES
1552 BEGIN_FW_FTR_SECTION
1554 ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
1557 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1559 stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
1567 * We put a few things here that have to be page-aligned.
1568 * This stuff goes at the beginning of the bss, which is page-aligned.
1574 .globl empty_zero_page
1578 .globl swapper_pg_dir
1580 .space PGD_TABLE_SIZE