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>
40 #define DO_SOFT_DISABLE
43 * We layout physical memory as follows:
44 * 0x0000 - 0x00ff : Secondary processor spin code
45 * 0x0100 - 0x2fff : pSeries Interrupt prologs
46 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
47 * 0x6000 - 0x6fff : Initial (CPU0) segment table
48 * 0x7000 - 0x7fff : FWNMI data area
49 * 0x8000 - : Early init and support code
57 * SPRG0 reserved for hypervisor
58 * SPRG1 temp - used to save gpr
59 * SPRG2 temp - used to save gpr
60 * SPRG3 virt addr of paca
64 * Entering into this code we make the following assumptions:
66 * 1. The MMU is off & open firmware is running in real mode.
67 * 2. The kernel is entered at __start
70 * 1. The MMU is on (as it always is for iSeries)
71 * 2. The kernel is entered at system_reset_iSeries
78 /* NOP this out unconditionally */
80 b .__start_initialization_multiplatform
83 /* Catch branch to 0 in real mode */
86 /* Secondary processors spin on this value until it goes to 1. */
87 .globl __secondary_hold_spinloop
88 __secondary_hold_spinloop:
91 /* Secondary processors write this value with their cpu # */
92 /* after they enter the spin loop immediately below. */
93 .globl __secondary_hold_acknowledge
94 __secondary_hold_acknowledge:
97 #ifdef CONFIG_PPC_ISERIES
99 * At offset 0x20, there is a pointer to iSeries LPAR data.
100 * This is required by the hypervisor
103 .llong hvReleaseData-KERNELBASE
104 #endif /* CONFIG_PPC_ISERIES */
108 * The following code is used to hold secondary processors
109 * in a spin loop after they have entered the kernel, but
110 * before the bulk of the kernel has been relocated. This code
111 * is relocated to physical address 0x60 before prom_init is run.
112 * All of it must fit below the first exception vector at 0x100.
114 _GLOBAL(__secondary_hold)
117 mtmsrd r24 /* RI on */
119 /* Grab our physical cpu number */
122 /* Tell the master cpu we're here */
123 /* Relocation is off & we are located at an address less */
124 /* than 0x100, so only need to grab low order offset. */
125 std r24,__secondary_hold_acknowledge@l(0)
128 /* All secondary cpus wait here until told to start. */
129 100: ld r4,__secondary_hold_spinloop@l(0)
133 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
134 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
142 /* This value is used to mark exception frames on the stack. */
145 .tc ID_72656773_68657265[TC],0x7265677368657265
149 * This is the start of the interrupt handlers for pSeries
150 * This code runs with relocation off.
153 .globl __start_interrupts
156 STD_EXCEPTION_PSERIES(0x100, system_reset)
159 _machine_check_pSeries:
161 mtspr SPRN_SPRG1,r13 /* save r13 */
162 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
165 .globl data_access_pSeries
174 rlwimi r13,r12,16,0x20
177 beq do_stab_bolted_pSeries
180 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
181 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
184 .globl data_access_slb_pSeries
185 data_access_slb_pSeries:
188 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
189 std r3,PACA_EXSLB+EX_R3(r13)
191 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
194 /* Keep that around for when we re-implement dynamic VSIDs */
196 bge slb_miss_user_pseries
197 #endif /* __DISABLED__ */
198 std r10,PACA_EXSLB+EX_R10(r13)
199 std r11,PACA_EXSLB+EX_R11(r13)
200 std r12,PACA_EXSLB+EX_R12(r13)
202 std r10,PACA_EXSLB+EX_R13(r13)
203 mfspr r12,SPRN_SRR1 /* and SRR1 */
204 b .slb_miss_realmode /* Rel. branch works in real mode */
206 STD_EXCEPTION_PSERIES(0x400, instruction_access)
209 .globl instruction_access_slb_pSeries
210 instruction_access_slb_pSeries:
213 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
214 std r3,PACA_EXSLB+EX_R3(r13)
215 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
216 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
219 /* Keep that around for when we re-implement dynamic VSIDs */
221 bge slb_miss_user_pseries
222 #endif /* __DISABLED__ */
223 std r10,PACA_EXSLB+EX_R10(r13)
224 std r11,PACA_EXSLB+EX_R11(r13)
225 std r12,PACA_EXSLB+EX_R12(r13)
227 std r10,PACA_EXSLB+EX_R13(r13)
228 mfspr r12,SPRN_SRR1 /* and SRR1 */
229 b .slb_miss_realmode /* Rel. branch works in real mode */
231 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
232 STD_EXCEPTION_PSERIES(0x600, alignment)
233 STD_EXCEPTION_PSERIES(0x700, program_check)
234 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
235 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
236 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
237 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
240 .globl system_call_pSeries
248 oris r12,r12,system_call_common@h
249 ori r12,r12,system_call_common@l
251 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
255 b . /* prevent speculative execution */
257 STD_EXCEPTION_PSERIES(0xd00, single_step)
258 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
260 /* We need to deal with the Altivec unavailable exception
261 * here which is at 0xf20, thus in the middle of the
262 * prolog code of the PerformanceMonitor one. A little
263 * trickery is thus necessary
266 b performance_monitor_pSeries
268 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
270 #ifdef CONFIG_CBE_RAS
271 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
272 #endif /* CONFIG_CBE_RAS */
273 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
274 #ifdef CONFIG_CBE_RAS
275 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
276 #endif /* CONFIG_CBE_RAS */
277 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
278 #ifdef CONFIG_CBE_RAS
279 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
280 #endif /* CONFIG_CBE_RAS */
284 /*** pSeries interrupt support ***/
286 /* moved from 0xf00 */
287 STD_EXCEPTION_PSERIES(., performance_monitor)
290 * An interrupt came in while soft-disabled; clear EE in SRR1,
291 * clear paca->hard_enabled and return.
294 stb r10,PACAHARDIRQEN(r13)
296 ld r9,PACA_EXGEN+EX_R9(r13)
298 rldicl r10,r10,48,1 /* clear MSR_EE */
301 ld r10,PACA_EXGEN+EX_R10(r13)
307 do_stab_bolted_pSeries:
310 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
313 * We have some room here we use that to put
314 * the peries slb miss user trampoline code so it's reasonably
315 * away from slb_miss_user_common to avoid problems with rfid
317 * This is used for when the SLB miss handler has to go virtual,
318 * which doesn't happen for now anymore but will once we re-implement
319 * dynamic VSIDs for shared page tables
322 slb_miss_user_pseries:
323 std r10,PACA_EXGEN+EX_R10(r13)
324 std r11,PACA_EXGEN+EX_R11(r13)
325 std r12,PACA_EXGEN+EX_R12(r13)
327 ld r11,PACA_EXSLB+EX_R9(r13)
328 ld r12,PACA_EXSLB+EX_R3(r13)
329 std r10,PACA_EXGEN+EX_R13(r13)
330 std r11,PACA_EXGEN+EX_R9(r13)
331 std r12,PACA_EXGEN+EX_R3(r13)
334 mfspr r11,SRR0 /* save SRR0 */
335 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
336 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
338 mfspr r12,SRR1 /* and SRR1 */
341 b . /* prevent spec. execution */
342 #endif /* __DISABLED__ */
344 #ifdef CONFIG_PPC_PSERIES
346 * Vectors for the FWNMI option. Share common code.
348 .globl system_reset_fwnmi
352 mtspr SPRN_SPRG1,r13 /* save r13 */
353 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
355 .globl machine_check_fwnmi
359 mtspr SPRN_SPRG1,r13 /* save r13 */
360 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
362 #endif /* CONFIG_PPC_PSERIES */
364 /*** Common interrupt handlers ***/
366 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
369 * Machine check is different because we use a different
370 * save area: PACA_EXMC instead of PACA_EXGEN.
373 .globl machine_check_common
374 machine_check_common:
375 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
379 addi r3,r1,STACK_FRAME_OVERHEAD
380 bl .machine_check_exception
383 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
384 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
385 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
386 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
387 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
388 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
389 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
390 #ifdef CONFIG_ALTIVEC
391 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
393 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
395 #ifdef CONFIG_CBE_RAS
396 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
397 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
398 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
399 #endif /* CONFIG_CBE_RAS */
402 * Here we have detected that the kernel stack pointer is bad.
403 * R9 contains the saved CR, r13 points to the paca,
404 * r10 contains the (bad) kernel stack pointer,
405 * r11 and r12 contain the saved SRR0 and SRR1.
406 * We switch to using an emergency stack, save the registers there,
407 * and call kernel_bad_stack(), which panics.
410 ld r1,PACAEMERGSP(r13)
411 subi r1,r1,64+INT_FRAME_SIZE
432 lhz r12,PACA_TRAP_SAVE(r13)
434 addi r11,r1,INT_FRAME_SIZE
439 1: addi r3,r1,STACK_FRAME_OVERHEAD
444 * Return from an exception with minimal checks.
445 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
446 * If interrupts have been enabled, or anything has been
447 * done that might have changed the scheduling status of
448 * any task or sent any task a signal, you should use
449 * ret_from_except or ret_from_except_lite instead of this.
451 fast_exc_return_irq: /* restores irq state too */
454 stb r3,PACASOFTIRQEN(r13) /* restore paca->soft_enabled */
455 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
456 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
459 .globl fast_exception_return
460 fast_exception_return:
463 andi. r3,r12,MSR_RI /* check if RI is set */
466 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
469 ACCOUNT_CPU_USER_EXIT(r3, r4)
485 rldicl r10,r10,48,1 /* clear EE */
486 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
494 b . /* prevent speculative execution */
498 1: addi r3,r1,STACK_FRAME_OVERHEAD
499 bl .unrecoverable_exception
503 * Here r13 points to the paca, r9 contains the saved CR,
504 * SRR0 and SRR1 are saved in r11 and r12,
505 * r9 - r13 are saved in paca->exgen.
508 .globl data_access_common
511 std r10,PACA_EXGEN+EX_DAR(r13)
513 stw r10,PACA_EXGEN+EX_DSISR(r13)
514 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
515 ld r3,PACA_EXGEN+EX_DAR(r13)
516 lwz r4,PACA_EXGEN+EX_DSISR(r13)
518 b .do_hash_page /* Try to handle as hpte fault */
521 .globl instruction_access_common
522 instruction_access_common:
523 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
527 b .do_hash_page /* Try to handle as hpte fault */
530 * Here is the common SLB miss user that is used when going to virtual
531 * mode for SLB misses, that is currently not used
535 .globl slb_miss_user_common
536 slb_miss_user_common:
538 std r3,PACA_EXGEN+EX_DAR(r13)
539 stw r9,PACA_EXGEN+EX_CCR(r13)
540 std r10,PACA_EXGEN+EX_LR(r13)
541 std r11,PACA_EXGEN+EX_SRR0(r13)
542 bl .slb_allocate_user
544 ld r10,PACA_EXGEN+EX_LR(r13)
545 ld r3,PACA_EXGEN+EX_R3(r13)
546 lwz r9,PACA_EXGEN+EX_CCR(r13)
547 ld r11,PACA_EXGEN+EX_SRR0(r13)
551 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
552 beq- unrecov_user_slb
560 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
566 ld r9,PACA_EXGEN+EX_R9(r13)
567 ld r10,PACA_EXGEN+EX_R10(r13)
568 ld r11,PACA_EXGEN+EX_R11(r13)
569 ld r12,PACA_EXGEN+EX_R12(r13)
570 ld r13,PACA_EXGEN+EX_R13(r13)
575 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
576 ld r4,PACA_EXGEN+EX_DAR(r13)
583 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
586 1: addi r3,r1,STACK_FRAME_OVERHEAD
587 bl .unrecoverable_exception
590 #endif /* __DISABLED__ */
594 * r13 points to the PACA, r9 contains the saved CR,
595 * r12 contain the saved SRR1, SRR0 is still ready for return
596 * r3 has the faulting address
597 * r9 - r13 are saved in paca->exslb.
598 * r3 is saved in paca->slb_r3
599 * We assume we aren't going to take any exceptions during this procedure.
601 _GLOBAL(slb_miss_realmode)
604 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
605 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
607 bl .slb_allocate_realmode
609 /* All done -- return from exception. */
611 ld r10,PACA_EXSLB+EX_LR(r13)
612 ld r3,PACA_EXSLB+EX_R3(r13)
613 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
614 #ifdef CONFIG_PPC_ISERIES
616 ld r11,PACALPPACAPTR(r13)
617 ld r11,LPPACASRR0(r11) /* get SRR0 value */
618 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
619 #endif /* CONFIG_PPC_ISERIES */
623 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
629 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
632 #ifdef CONFIG_PPC_ISERIES
636 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
637 #endif /* CONFIG_PPC_ISERIES */
638 ld r9,PACA_EXSLB+EX_R9(r13)
639 ld r10,PACA_EXSLB+EX_R10(r13)
640 ld r11,PACA_EXSLB+EX_R11(r13)
641 ld r12,PACA_EXSLB+EX_R12(r13)
642 ld r13,PACA_EXSLB+EX_R13(r13)
644 b . /* prevent speculative execution */
647 #ifdef CONFIG_PPC_ISERIES
650 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
651 #endif /* CONFIG_PPC_ISERIES */
654 LOAD_HANDLER(r10,unrecov_slb)
657 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
663 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
666 1: addi r3,r1,STACK_FRAME_OVERHEAD
667 bl .unrecoverable_exception
671 .globl hardware_interrupt_common
672 .globl hardware_interrupt_entry
673 hardware_interrupt_common:
674 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
676 hardware_interrupt_entry:
679 bl .ppc64_runlatch_on
680 END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
681 addi r3,r1,STACK_FRAME_OVERHEAD
683 b .ret_from_except_lite
685 #ifdef CONFIG_PPC_970_NAP
688 std r9,TI_LOCAL_FLAGS(r11)
689 ld r10,_LINK(r1) /* make idle task do the */
690 std r10,_NIP(r1) /* equivalent of a blr */
695 .globl alignment_common
698 std r10,PACA_EXGEN+EX_DAR(r13)
700 stw r10,PACA_EXGEN+EX_DSISR(r13)
701 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
702 ld r3,PACA_EXGEN+EX_DAR(r13)
703 lwz r4,PACA_EXGEN+EX_DSISR(r13)
707 addi r3,r1,STACK_FRAME_OVERHEAD
709 bl .alignment_exception
713 .globl program_check_common
714 program_check_common:
715 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
717 addi r3,r1,STACK_FRAME_OVERHEAD
719 bl .program_check_exception
723 .globl fp_unavailable_common
724 fp_unavailable_common:
725 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
726 bne 1f /* if from user, just load it up */
728 addi r3,r1,STACK_FRAME_OVERHEAD
730 bl .kernel_fp_unavailable_exception
735 .globl altivec_unavailable_common
736 altivec_unavailable_common:
737 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
738 #ifdef CONFIG_ALTIVEC
740 bne .load_up_altivec /* if from user, just load it up */
741 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
744 addi r3,r1,STACK_FRAME_OVERHEAD
746 bl .altivec_unavailable_exception
749 #ifdef CONFIG_ALTIVEC
751 * load_up_altivec(unused, unused, tsk)
752 * Disable VMX for the task which had it previously,
753 * and save its vector registers in its thread_struct.
754 * Enables the VMX for use in the kernel on return.
755 * On SMP we know the VMX is free, since we give it up every
756 * switch (ie, no lazy save of the vector registers).
757 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
759 _STATIC(load_up_altivec)
760 mfmsr r5 /* grab the current MSR */
762 mtmsrd r5 /* enable use of VMX now */
766 * For SMP, we don't do lazy VMX switching because it just gets too
767 * horrendously complex, especially when a task switches from one CPU
768 * to another. Instead we call giveup_altvec in switch_to.
769 * VRSAVE isn't dealt with here, that is done in the normal context
770 * switch code. Note that we could rely on vrsave value to eventually
771 * avoid saving all of the VREGs here...
774 ld r3,last_task_used_altivec@got(r2)
778 /* Save VMX state to last_task_used_altivec's THREAD struct */
784 /* Disable VMX for last_task_used_altivec */
786 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
789 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
791 #endif /* CONFIG_SMP */
792 /* Hack: if we get an altivec unavailable trap with VRSAVE
793 * set to all zeros, we assume this is a broken application
794 * that fails to set it properly, and thus we switch it to
803 /* enable use of VMX after return */
804 ld r4,PACACURRENT(r13)
805 addi r5,r4,THREAD /* Get THREAD */
806 oris r12,r12,MSR_VEC@h
810 stw r4,THREAD_USED_VR(r5)
815 /* Update last_task_used_math to 'current' */
816 subi r4,r5,THREAD /* Back to 'current' */
818 #endif /* CONFIG_SMP */
819 /* restore registers and return */
820 b fast_exception_return
821 #endif /* CONFIG_ALTIVEC */
827 _GLOBAL(do_hash_page)
831 andis. r0,r4,0xa450 /* weird error? */
832 bne- handle_page_fault /* if not, try to insert a HPTE */
834 andis. r0,r4,0x0020 /* Is it a segment table fault? */
835 bne- do_ste_alloc /* If so handle it */
836 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
839 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
840 * accessing a userspace segment (even from the kernel). We assume
841 * kernel addresses always have the high bit set.
843 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
844 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
845 orc r0,r12,r0 /* MSR_PR | ~high_bit */
846 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
847 ori r4,r4,1 /* add _PAGE_PRESENT */
848 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
851 * On iSeries, we soft-disable interrupts here, then
852 * hard-enable interrupts so that the hash_page code can spin on
853 * the hash_table_lock without problems on a shared processor.
858 * r3 contains the faulting address
859 * r4 contains the required access permissions
860 * r5 contains the trap number
862 * at return r3 = 0 for success
864 bl .hash_page /* build HPTE if possible */
865 cmpdi r3,0 /* see if hash_page succeeded */
867 #ifdef DO_SOFT_DISABLE
870 * If we had interrupts soft-enabled at the point where the
871 * DSI/ISI occurred, and an interrupt came in during hash_page,
873 * We jump to ret_from_except_lite rather than fast_exception_return
874 * because ret_from_except_lite will check for and handle pending
875 * interrupts if necessary.
878 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
882 * Here we have interrupts hard-disabled, so it is sufficient
883 * to restore paca->{soft,hard}_enable and get out.
885 beq fast_exc_return_irq /* Return from exception on success */
886 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
888 /* For a hash failure, we don't bother re-enabling interrupts */
892 * hash_page couldn't handle it, set soft interrupt enable back
893 * to what it was before the trap. Note that .local_irq_restore
894 * handles any interrupts pending at this point.
897 bl .local_irq_restore
900 /* Here we have a page fault that hash_page can't handle. */
905 addi r3,r1,STACK_FRAME_OVERHEAD
911 addi r3,r1,STACK_FRAME_OVERHEAD
916 13: b .ret_from_except_lite
918 /* We have a page fault that hash_page could handle but HV refused
923 addi r3,r1,STACK_FRAME_OVERHEAD
928 /* here we have a segment miss */
930 bl .ste_allocate /* try to insert stab entry */
932 bne- handle_page_fault
933 b fast_exception_return
936 * r13 points to the PACA, r9 contains the saved CR,
937 * r11 and r12 contain the saved SRR0 and SRR1.
938 * r9 - r13 are saved in paca->exslb.
939 * We assume we aren't going to take any exceptions during this procedure.
940 * We assume (DAR >> 60) == 0xc.
943 _GLOBAL(do_stab_bolted)
944 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
945 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
947 /* Hash to the primary group */
948 ld r10,PACASTABVIRT(r13)
951 rldimi r10,r11,7,52 /* r10 = first ste of the group */
954 /* This is a kernel address, so protovsid = ESID */
955 ASM_VSID_SCRAMBLE(r11, r9, 256M)
956 rldic r9,r11,12,16 /* r9 = vsid << 12 */
958 /* Search the primary group for a free entry */
959 1: ld r11,0(r10) /* Test valid bit of the current ste */
966 /* Stick for only searching the primary group for now. */
967 /* At least for now, we use a very simple random castout scheme */
968 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
970 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
973 /* r10 currently points to an ste one past the group of interest */
974 /* make it point to the randomly selected entry */
976 or r10,r10,r11 /* r10 is the entry to invalidate */
978 isync /* mark the entry invalid */
980 rldicl r11,r11,56,1 /* clear the valid bit */
985 clrrdi r11,r11,28 /* Get the esid part of the ste */
988 2: std r9,8(r10) /* Store the vsid part of the ste */
991 mfspr r11,SPRN_DAR /* Get the new esid */
992 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
993 ori r11,r11,0x90 /* Turn on valid and kp */
994 std r11,0(r10) /* Put new entry back into the stab */
998 /* All done -- return from exception. */
999 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1000 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1002 andi. r10,r12,MSR_RI
1005 mtcrf 0x80,r9 /* restore CR */
1013 ld r9,PACA_EXSLB+EX_R9(r13)
1014 ld r10,PACA_EXSLB+EX_R10(r13)
1015 ld r11,PACA_EXSLB+EX_R11(r13)
1016 ld r12,PACA_EXSLB+EX_R12(r13)
1017 ld r13,PACA_EXSLB+EX_R13(r13)
1019 b . /* prevent speculative execution */
1022 * Space for CPU0's segment table.
1024 * On iSeries, the hypervisor must fill in at least one entry before
1025 * we get control (with relocate on). The address is given to the hv
1026 * as a page number (see xLparMap below), so this must be at a
1027 * fixed address (the linker can't compute (u64)&initial_stab >>
1030 . = STAB0_OFFSET /* 0x6000 */
1035 #ifdef CONFIG_PPC_PSERIES
1037 * Data area reserved for FWNMI option.
1038 * This address (0x7000) is fixed by the RPA.
1041 .globl fwnmi_data_area
1043 #endif /* CONFIG_PPC_PSERIES */
1045 /* iSeries does not use the FWNMI stuff, so it is safe to put
1046 * this here, even if we later allow kernels that will boot on
1047 * both pSeries and iSeries */
1048 #ifdef CONFIG_PPC_ISERIES
1052 .quad HvEsidsToMap /* xNumberEsids */
1053 .quad HvRangesToMap /* xNumberRanges */
1054 .quad STAB0_PAGE /* xSegmentTableOffs */
1055 .zero 40 /* xRsvd */
1056 /* xEsids (HvEsidsToMap entries of 2 quads) */
1057 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1058 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1059 .quad VMALLOC_START_ESID /* xKernelEsid */
1060 .quad VMALLOC_START_VSID /* xKernelVsid */
1061 /* xRanges (HvRangesToMap entries of 3 quads) */
1062 .quad HvPagesToMap /* xPages */
1063 .quad 0 /* xOffset */
1064 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1066 #endif /* CONFIG_PPC_ISERIES */
1068 #ifdef CONFIG_PPC_PSERIES
1070 #endif /* CONFIG_PPC_PSERIES */
1073 * On pSeries and most other platforms, secondary processors spin
1074 * in the following code.
1075 * At entry, r3 = this processor's number (physical cpu id)
1077 _GLOBAL(generic_secondary_smp_init)
1080 /* turn on 64-bit mode */
1083 /* Set up a paca value for this processor. Since we have the
1084 * physical cpu id in r24, we need to search the pacas to find
1085 * which logical id maps to our physical one.
1087 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1088 li r5,0 /* logical cpu id */
1089 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1090 cmpw r6,r24 /* Compare to our id */
1092 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1097 mr r3,r24 /* not found, copy phys to r3 */
1098 b .kexec_wait /* next kernel might do better */
1100 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1101 /* From now on, r24 is expected to be logical cpuid */
1104 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1109 b 3b /* Never go on non-SMP */
1112 beq 3b /* Loop until told to go */
1114 /* See if we need to call a cpu state restore handler */
1115 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1117 ld r23,CPU_SPEC_RESTORE(r23)
1124 4: /* Create a temp kernel stack for use before relocation is on. */
1125 ld r1,PACAEMERGSP(r13)
1126 subi r1,r1,STACK_FRAME_OVERHEAD
1133 andi. r0,r3,MSR_IR|MSR_DR
1140 b . /* prevent speculative execution */
1144 * Here is our main kernel entry point. We support currently 2 kind of entries
1145 * depending on the value of r5.
1147 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1150 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1151 * DT block, r4 is a physical pointer to the kernel itself
1154 _GLOBAL(__start_initialization_multiplatform)
1156 * Are we booted from a PROM Of-type client-interface ?
1160 b .__boot_from_prom /* yes -> prom */
1162 /* Save parameters */
1166 /* Make sure we are running in 64 bits mode */
1169 /* Setup some critical 970 SPRs before switching MMU off */
1172 cmpwi r0,0x39 /* 970 */
1174 cmpwi r0,0x3c /* 970FX */
1176 cmpwi r0,0x44 /* 970MP */
1178 cmpwi r0,0x45 /* 970GX */
1180 1: bl .__cpu_preinit_ppc970
1183 /* Switch off MMU if not already */
1184 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1187 b .__after_prom_start
1189 _INIT_STATIC(__boot_from_prom)
1190 /* Save parameters */
1198 * Align the stack to 16-byte boundary
1199 * Depending on the size and layout of the ELF sections in the initial
1200 * boot binary, the stack pointer will be unalignet on PowerMac
1204 /* Make sure we are running in 64 bits mode */
1207 /* put a relocation offset into r3 */
1210 LOAD_REG_IMMEDIATE(r2,__toc_start)
1214 /* Relocate the TOC from a virt addr to a real addr */
1217 /* Restore parameters */
1224 /* Do all of the interaction with OF client interface */
1226 /* We never return */
1229 _STATIC(__after_prom_start)
1232 * We need to run with __start at physical address PHYSICAL_START.
1233 * This will leave some code in the first 256B of
1234 * real memory, which are reserved for software use.
1235 * The remainder of the first page is loaded with the fixed
1236 * interrupt vectors. The next two pages are filled with
1237 * unknown exception placeholders.
1239 * Note: This process overwrites the OF exception vectors.
1240 * r26 == relocation offset
1245 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1247 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1249 // XXX FIXME: Use phys returned by OF (r30)
1250 add r4,r27,r26 /* source addr */
1251 /* current address of _start */
1252 /* i.e. where we are running */
1253 /* the source addr */
1255 cmpdi r4,0 /* In some cases the loader may */
1257 b .start_here_multiplatform /* have already put us at zero */
1258 /* so we can skip the copy. */
1259 1: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1262 li r6,0x100 /* Start offset, the first 0x100 */
1263 /* bytes were copied earlier. */
1265 bl .copy_and_flush /* copy the first n bytes */
1266 /* this includes the code being */
1267 /* executed here. */
1269 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1270 mtctr r0 /* that we just made/relocated */
1273 4: LOAD_REG_IMMEDIATE(r5,klimit)
1275 ld r5,0(r5) /* get the value of klimit */
1277 bl .copy_and_flush /* copy the rest */
1278 b .start_here_multiplatform
1281 * Copy routine used to copy the kernel to start at physical address 0
1282 * and flush and invalidate the caches as needed.
1283 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1284 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1286 * Note: this routine *only* clobbers r0, r6 and lr
1288 _GLOBAL(copy_and_flush)
1291 4: li r0,8 /* Use the smallest common */
1292 /* denominator cache line */
1293 /* size. This results in */
1294 /* extra cache line flushes */
1295 /* but operation is correct. */
1296 /* Can't get cache line size */
1297 /* from NACA as it is being */
1300 mtctr r0 /* put # words/line in ctr */
1301 3: addi r6,r6,8 /* copy a cache line */
1305 dcbst r6,r3 /* write it to memory */
1307 icbi r6,r3 /* flush the icache line */
1319 #ifdef CONFIG_PPC_PMAC
1321 * On PowerMac, secondary processors starts from the reset vector, which
1322 * is temporarily turned into a call to one of the functions below.
1327 .globl __secondary_start_pmac_0
1328 __secondary_start_pmac_0:
1329 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1339 _GLOBAL(pmac_secondary_start)
1340 /* turn on 64-bit mode */
1343 /* Copy some CPU settings from CPU 0 */
1344 bl .__restore_cpu_ppc970
1346 /* pSeries do that early though I don't think we really need it */
1349 mtmsrd r3 /* RI on */
1351 /* Set up a paca value for this processor. */
1352 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1353 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1354 add r13,r13,r4 /* for this processor. */
1355 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1357 /* Create a temp kernel stack for use before relocation is on. */
1358 ld r1,PACAEMERGSP(r13)
1359 subi r1,r1,STACK_FRAME_OVERHEAD
1363 #endif /* CONFIG_PPC_PMAC */
1366 * This function is called after the master CPU has released the
1367 * secondary processors. The execution environment is relocation off.
1368 * The paca for this processor has the following fields initialized at
1370 * 1. Processor number
1371 * 2. Segment table pointer (virtual address)
1372 * On entry the following are set:
1373 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1374 * r24 = cpu# (in Linux terms)
1375 * r13 = paca virtual address
1376 * SPRG3 = paca virtual address
1378 .globl __secondary_start
1380 /* Set thread priority to MEDIUM */
1386 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1387 bl .early_setup_secondary
1389 /* Initialize the kernel stack. Just a repeat for iSeries. */
1390 LOAD_REG_ADDR(r3, current_set)
1391 sldi r28,r24,3 /* get current_set[cpu#] */
1393 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1394 std r1,PACAKSAVE(r13)
1396 /* Clear backchain so we get nice backtraces */
1400 /* enable MMU and jump to start_secondary */
1401 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1402 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1403 #ifdef CONFIG_PPC_ISERIES
1404 BEGIN_FW_FTR_SECTION
1407 stb r8,PACAHARDIRQEN(r13)
1408 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1410 BEGIN_FW_FTR_SECTION
1411 stb r7,PACAHARDIRQEN(r13)
1412 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1413 stb r7,PACASOFTIRQEN(r13)
1418 b . /* prevent speculative execution */
1421 * Running with relocation on at this point. All we want to do is
1422 * zero the stack back-chain pointer before going into C code.
1424 _GLOBAL(start_secondary_prolog)
1426 std r3,0(r1) /* Zero the stack frame pointer */
1432 * This subroutine clobbers r11 and r12
1434 _GLOBAL(enable_64b_mode)
1435 mfmsr r11 /* grab the current MSR */
1437 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1440 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1447 * This is where the main kernel code starts.
1449 _INIT_STATIC(start_here_multiplatform)
1450 /* get a new offset, now that the kernel has moved. */
1454 /* Clear out the BSS. It may have been done in prom_init,
1455 * already but that's irrelevant since prom_init will soon
1456 * be detached from the kernel completely. Besides, we need
1457 * to clear it now for kexec-style entry.
1459 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1460 LOAD_REG_IMMEDIATE(r8,__bss_start)
1461 sub r11,r11,r8 /* bss size */
1462 addi r11,r11,7 /* round up to an even double word */
1463 rldicl. r11,r11,61,3 /* shift right by 3 */
1467 mtctr r11 /* zero this many doublewords */
1474 mtmsrd r6 /* RI on */
1476 /* The following gets the stack and TOC set up with the regs */
1477 /* pointing to the real addr of the kernel stack. This is */
1478 /* all done to support the C function call below which sets */
1479 /* up the htab. This is done because we have relocated the */
1480 /* kernel but are still running in real mode. */
1482 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1485 /* set up a stack pointer (physical address) */
1486 addi r1,r3,THREAD_SIZE
1488 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1490 /* set up the TOC (physical address) */
1491 LOAD_REG_IMMEDIATE(r2,__toc_start)
1496 /* Do very early kernel initializations, including initial hash table,
1497 * stab and slb setup before we turn on relocation. */
1499 /* Restore parameters passed from prom_init/kexec */
1503 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1504 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1508 b . /* prevent speculative execution */
1510 /* This is where all platforms converge execution */
1511 _INIT_GLOBAL(start_here_common)
1512 /* relocation is on at this point */
1514 /* The following code sets up the SP and TOC now that we are */
1515 /* running with translation enabled. */
1517 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1519 /* set up the stack */
1520 addi r1,r3,THREAD_SIZE
1522 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1526 std r1,PACAKSAVE(r13)
1530 /* Load up the kernel context */
1533 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1534 #ifdef CONFIG_PPC_ISERIES
1535 BEGIN_FW_FTR_SECTION
1537 ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
1540 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1542 stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
1550 * We put a few things here that have to be page-aligned.
1551 * This stuff goes at the beginning of the bss, which is page-aligned.
1557 .globl empty_zero_page
1561 .globl swapper_pg_dir
1563 .space PGD_TABLE_SIZE