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 becomes nonzero.
86 * When it does it contains the real address of the descriptor
87 * of the function that the cpu should jump to to continue
90 .globl __secondary_hold_spinloop
91 __secondary_hold_spinloop:
94 /* Secondary processors write this value with their cpu # */
95 /* after they enter the spin loop immediately below. */
96 .globl __secondary_hold_acknowledge
97 __secondary_hold_acknowledge:
100 #ifdef CONFIG_PPC_ISERIES
102 * At offset 0x20, there is a pointer to iSeries LPAR data.
103 * This is required by the hypervisor
106 .llong hvReleaseData-KERNELBASE
107 #endif /* CONFIG_PPC_ISERIES */
111 * The following code is used to hold secondary processors
112 * in a spin loop after they have entered the kernel, but
113 * before the bulk of the kernel has been relocated. This code
114 * is relocated to physical address 0x60 before prom_init is run.
115 * All of it must fit below the first exception vector at 0x100.
116 * Use .globl here not _GLOBAL because we want __secondary_hold
117 * to be the actual text address, not a descriptor.
119 .globl __secondary_hold
123 mtmsrd r24 /* RI on */
125 /* Grab our physical cpu number */
128 /* Tell the master cpu we're here */
129 /* Relocation is off & we are located at an address less */
130 /* than 0x100, so only need to grab low order offset. */
131 std r24,__secondary_hold_acknowledge-_stext(0)
134 /* All secondary cpus wait here until told to start. */
135 100: ld r4,__secondary_hold_spinloop-_stext(0)
139 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
140 ld r4,0(r4) /* deref function descriptor */
148 /* This value is used to mark exception frames on the stack. */
151 .tc ID_72656773_68657265[TC],0x7265677368657265
155 * This is the start of the interrupt handlers for pSeries
156 * This code runs with relocation off.
157 * Code from here to __end_interrupts gets copied down to real
158 * address 0x100 when we are running a relocatable kernel.
159 * Therefore any relative branches in this section must only
160 * branch to labels in this section.
163 .globl __start_interrupts
166 STD_EXCEPTION_PSERIES(0x100, system_reset)
169 _machine_check_pSeries:
171 mtspr SPRN_SPRG1,r13 /* save r13 */
172 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
175 .globl data_access_pSeries
184 rlwimi r13,r12,16,0x20
187 beq do_stab_bolted_pSeries
190 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
191 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
194 .globl data_access_slb_pSeries
195 data_access_slb_pSeries:
198 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
199 std r3,PACA_EXSLB+EX_R3(r13)
201 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
204 /* Keep that around for when we re-implement dynamic VSIDs */
206 bge slb_miss_user_pseries
207 #endif /* __DISABLED__ */
208 std r10,PACA_EXSLB+EX_R10(r13)
209 std r11,PACA_EXSLB+EX_R11(r13)
210 std r12,PACA_EXSLB+EX_R12(r13)
212 std r10,PACA_EXSLB+EX_R13(r13)
213 mfspr r12,SPRN_SRR1 /* and SRR1 */
214 #ifndef CONFIG_RELOCATABLE
218 * We can't just use a direct branch to .slb_miss_realmode
219 * because the distance from here to there depends on where
220 * the kernel ends up being put.
223 ld r10,PACAKBASE(r13)
224 LOAD_HANDLER(r10, .slb_miss_realmode)
229 STD_EXCEPTION_PSERIES(0x400, instruction_access)
232 .globl instruction_access_slb_pSeries
233 instruction_access_slb_pSeries:
236 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
237 std r3,PACA_EXSLB+EX_R3(r13)
238 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
239 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
242 /* Keep that around for when we re-implement dynamic VSIDs */
244 bge slb_miss_user_pseries
245 #endif /* __DISABLED__ */
246 std r10,PACA_EXSLB+EX_R10(r13)
247 std r11,PACA_EXSLB+EX_R11(r13)
248 std r12,PACA_EXSLB+EX_R12(r13)
250 std r10,PACA_EXSLB+EX_R13(r13)
251 mfspr r12,SPRN_SRR1 /* and SRR1 */
252 #ifndef CONFIG_RELOCATABLE
256 ld r10,PACAKBASE(r13)
257 LOAD_HANDLER(r10, .slb_miss_realmode)
262 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
263 STD_EXCEPTION_PSERIES(0x600, alignment)
264 STD_EXCEPTION_PSERIES(0x700, program_check)
265 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
266 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
267 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
268 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
271 .globl system_call_pSeries
277 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
281 ld r12,PACAKBASE(r13)
283 LOAD_HANDLER(r12, system_call_entry)
288 b . /* prevent speculative execution */
290 /* Fast LE/BE switch system call */
291 1: mfspr r12,SPRN_SRR1
294 rfid /* return to userspace */
297 STD_EXCEPTION_PSERIES(0xd00, single_step)
298 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
300 /* We need to deal with the Altivec unavailable exception
301 * here which is at 0xf20, thus in the middle of the
302 * prolog code of the PerformanceMonitor one. A little
303 * trickery is thus necessary
306 b performance_monitor_pSeries
309 b altivec_unavailable_pSeries
312 b vsx_unavailable_pSeries
314 #ifdef CONFIG_CBE_RAS
315 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
316 #endif /* CONFIG_CBE_RAS */
317 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
318 #ifdef CONFIG_CBE_RAS
319 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
320 #endif /* CONFIG_CBE_RAS */
321 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
322 #ifdef CONFIG_CBE_RAS
323 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
324 #endif /* CONFIG_CBE_RAS */
328 /*** pSeries interrupt support ***/
330 /* moved from 0xf00 */
331 STD_EXCEPTION_PSERIES(., performance_monitor)
332 STD_EXCEPTION_PSERIES(., altivec_unavailable)
333 STD_EXCEPTION_PSERIES(., vsx_unavailable)
336 * An interrupt came in while soft-disabled; clear EE in SRR1,
337 * clear paca->hard_enabled and return.
340 stb r10,PACAHARDIRQEN(r13)
342 ld r9,PACA_EXGEN+EX_R9(r13)
344 rldicl r10,r10,48,1 /* clear MSR_EE */
347 ld r10,PACA_EXGEN+EX_R10(r13)
353 do_stab_bolted_pSeries:
356 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
358 #ifdef CONFIG_PPC_PSERIES
360 * Vectors for the FWNMI option. Share common code.
362 .globl system_reset_fwnmi
366 mtspr SPRN_SPRG1,r13 /* save r13 */
367 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
369 .globl machine_check_fwnmi
373 mtspr SPRN_SPRG1,r13 /* save r13 */
374 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
376 #endif /* CONFIG_PPC_PSERIES */
380 * This is used for when the SLB miss handler has to go virtual,
381 * which doesn't happen for now anymore but will once we re-implement
382 * dynamic VSIDs for shared page tables
384 slb_miss_user_pseries:
385 std r10,PACA_EXGEN+EX_R10(r13)
386 std r11,PACA_EXGEN+EX_R11(r13)
387 std r12,PACA_EXGEN+EX_R12(r13)
389 ld r11,PACA_EXSLB+EX_R9(r13)
390 ld r12,PACA_EXSLB+EX_R3(r13)
391 std r10,PACA_EXGEN+EX_R13(r13)
392 std r11,PACA_EXGEN+EX_R9(r13)
393 std r12,PACA_EXGEN+EX_R3(r13)
396 mfspr r11,SRR0 /* save SRR0 */
397 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
398 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
400 mfspr r12,SRR1 /* and SRR1 */
403 b . /* prevent spec. execution */
404 #endif /* __DISABLED__ */
407 .globl __end_interrupts
411 * Code from here down to __end_handlers is invoked from the
412 * exception prologs above. Because the prologs assemble the
413 * addresses of these handlers using the LOAD_HANDLER macro,
414 * which uses an addi instruction, these handlers must be in
415 * the first 32k of the kernel image.
418 /*** Common interrupt handlers ***/
420 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
423 * Machine check is different because we use a different
424 * save area: PACA_EXMC instead of PACA_EXGEN.
427 .globl machine_check_common
428 machine_check_common:
429 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
433 addi r3,r1,STACK_FRAME_OVERHEAD
434 bl .machine_check_exception
437 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
438 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
439 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
440 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
441 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
442 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
443 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
444 #ifdef CONFIG_ALTIVEC
445 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
447 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
449 #ifdef CONFIG_CBE_RAS
450 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
451 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
452 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
453 #endif /* CONFIG_CBE_RAS */
460 * Here we have detected that the kernel stack pointer is bad.
461 * R9 contains the saved CR, r13 points to the paca,
462 * r10 contains the (bad) kernel stack pointer,
463 * r11 and r12 contain the saved SRR0 and SRR1.
464 * We switch to using an emergency stack, save the registers there,
465 * and call kernel_bad_stack(), which panics.
468 ld r1,PACAEMERGSP(r13)
469 subi r1,r1,64+INT_FRAME_SIZE
490 lhz r12,PACA_TRAP_SAVE(r13)
492 addi r11,r1,INT_FRAME_SIZE
497 1: addi r3,r1,STACK_FRAME_OVERHEAD
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)
602 #ifdef CONFIG_RELOCATABLE
606 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
607 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
609 bl .slb_allocate_realmode
611 /* All done -- return from exception. */
613 ld r10,PACA_EXSLB+EX_LR(r13)
614 ld r3,PACA_EXSLB+EX_R3(r13)
615 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
616 #ifdef CONFIG_PPC_ISERIES
618 ld r11,PACALPPACAPTR(r13)
619 ld r11,LPPACASRR0(r11) /* get SRR0 value */
620 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
621 #endif /* CONFIG_PPC_ISERIES */
625 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
631 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
634 #ifdef CONFIG_PPC_ISERIES
638 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
639 #endif /* CONFIG_PPC_ISERIES */
640 ld r9,PACA_EXSLB+EX_R9(r13)
641 ld r10,PACA_EXSLB+EX_R10(r13)
642 ld r11,PACA_EXSLB+EX_R11(r13)
643 ld r12,PACA_EXSLB+EX_R12(r13)
644 ld r13,PACA_EXSLB+EX_R13(r13)
646 b . /* prevent speculative execution */
649 #ifdef CONFIG_PPC_ISERIES
652 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
653 #endif /* CONFIG_PPC_ISERIES */
655 ld r10,PACAKBASE(r13)
656 LOAD_HANDLER(r10,unrecov_slb)
664 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
667 1: addi r3,r1,STACK_FRAME_OVERHEAD
668 bl .unrecoverable_exception
672 .globl hardware_interrupt_common
673 .globl hardware_interrupt_entry
674 hardware_interrupt_common:
675 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
677 hardware_interrupt_entry:
680 bl .ppc64_runlatch_on
681 END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
682 addi r3,r1,STACK_FRAME_OVERHEAD
684 b .ret_from_except_lite
686 #ifdef CONFIG_PPC_970_NAP
689 std r9,TI_LOCAL_FLAGS(r11)
690 ld r10,_LINK(r1) /* make idle task do the */
691 std r10,_NIP(r1) /* equivalent of a blr */
696 .globl alignment_common
699 std r10,PACA_EXGEN+EX_DAR(r13)
701 stw r10,PACA_EXGEN+EX_DSISR(r13)
702 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
703 ld r3,PACA_EXGEN+EX_DAR(r13)
704 lwz r4,PACA_EXGEN+EX_DSISR(r13)
708 addi r3,r1,STACK_FRAME_OVERHEAD
710 bl .alignment_exception
714 .globl program_check_common
715 program_check_common:
716 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
718 addi r3,r1,STACK_FRAME_OVERHEAD
720 bl .program_check_exception
724 .globl fp_unavailable_common
725 fp_unavailable_common:
726 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
727 bne 1f /* if from user, just load it up */
729 addi r3,r1,STACK_FRAME_OVERHEAD
731 bl .kernel_fp_unavailable_exception
734 b fast_exception_return
737 .globl altivec_unavailable_common
738 altivec_unavailable_common:
739 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
740 #ifdef CONFIG_ALTIVEC
744 b fast_exception_return
746 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
749 addi r3,r1,STACK_FRAME_OVERHEAD
751 bl .altivec_unavailable_exception
755 .globl vsx_unavailable_common
756 vsx_unavailable_common:
757 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
762 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
765 addi r3,r1,STACK_FRAME_OVERHEAD
767 bl .vsx_unavailable_exception
771 .globl __end_handlers
775 * Return from an exception with minimal checks.
776 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
777 * If interrupts have been enabled, or anything has been
778 * done that might have changed the scheduling status of
779 * any task or sent any task a signal, you should use
780 * ret_from_except or ret_from_except_lite instead of this.
782 fast_exc_return_irq: /* restores irq state too */
784 TRACE_AND_RESTORE_IRQ(r3);
786 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
787 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
790 .globl fast_exception_return
791 fast_exception_return:
794 andi. r3,r12,MSR_RI /* check if RI is set */
797 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
800 ACCOUNT_CPU_USER_EXIT(r3, r4)
816 rldicl r10,r10,48,1 /* clear EE */
817 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
825 b . /* prevent speculative execution */
829 1: addi r3,r1,STACK_FRAME_OVERHEAD
830 bl .unrecoverable_exception
833 #ifdef CONFIG_ALTIVEC
835 * load_up_altivec(unused, unused, tsk)
836 * Disable VMX for the task which had it previously,
837 * and save its vector registers in its thread_struct.
838 * Enables the VMX for use in the kernel on return.
839 * On SMP we know the VMX is free, since we give it up every
840 * switch (ie, no lazy save of the vector registers).
841 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
843 _STATIC(load_up_altivec)
844 mfmsr r5 /* grab the current MSR */
846 mtmsrd r5 /* enable use of VMX now */
850 * For SMP, we don't do lazy VMX switching because it just gets too
851 * horrendously complex, especially when a task switches from one CPU
852 * to another. Instead we call giveup_altvec in switch_to.
853 * VRSAVE isn't dealt with here, that is done in the normal context
854 * switch code. Note that we could rely on vrsave value to eventually
855 * avoid saving all of the VREGs here...
858 ld r3,last_task_used_altivec@got(r2)
862 /* Save VMX state to last_task_used_altivec's THREAD struct */
868 /* Disable VMX for last_task_used_altivec */
870 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
873 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
875 #endif /* CONFIG_SMP */
876 /* Hack: if we get an altivec unavailable trap with VRSAVE
877 * set to all zeros, we assume this is a broken application
878 * that fails to set it properly, and thus we switch it to
887 /* enable use of VMX after return */
888 ld r4,PACACURRENT(r13)
889 addi r5,r4,THREAD /* Get THREAD */
890 oris r12,r12,MSR_VEC@h
894 stw r4,THREAD_USED_VR(r5)
899 /* Update last_task_used_math to 'current' */
900 subi r4,r5,THREAD /* Back to 'current' */
902 #endif /* CONFIG_SMP */
903 /* restore registers and return */
905 #endif /* CONFIG_ALTIVEC */
909 * load_up_vsx(unused, unused, tsk)
910 * Disable VSX for the task which had it previously,
911 * and save its vector registers in its thread_struct.
912 * Reuse the fp and vsx saves, but first check to see if they have
913 * been saved already.
914 * On entry: r13 == 'current' && last_task_used_vsx != 'current'
917 /* Load FP and VSX registers if they haven't been done yet */
919 beql+ load_up_fpu /* skip if already loaded */
920 andis. r5,r12,MSR_VEC@h
921 beql+ load_up_altivec /* skip if already loaded */
924 ld r3,last_task_used_vsx@got(r2)
928 /* Disable VSX for last_task_used_vsx */
931 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
934 std r6,_MSR-STACK_FRAME_OVERHEAD(r5)
936 #endif /* CONFIG_SMP */
937 ld r4,PACACURRENT(r13)
938 addi r4,r4,THREAD /* Get THREAD */
940 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
941 /* enable use of VSX after return */
942 oris r12,r12,MSR_VSX@h
945 /* Update last_task_used_math to 'current' */
946 ld r4,PACACURRENT(r13)
948 #endif /* CONFIG_SMP */
949 b fast_exception_return
950 #endif /* CONFIG_VSX */
956 _STATIC(do_hash_page)
960 andis. r0,r4,0xa450 /* weird error? */
961 bne- handle_page_fault /* if not, try to insert a HPTE */
963 andis. r0,r4,0x0020 /* Is it a segment table fault? */
964 bne- do_ste_alloc /* If so handle it */
965 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
968 * On iSeries, we soft-disable interrupts here, then
969 * hard-enable interrupts so that the hash_page code can spin on
970 * the hash_table_lock without problems on a shared processor.
975 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
976 * and will clobber volatile registers when irq tracing is enabled
977 * so we need to reload them. It may be possible to be smarter here
978 * and move the irq tracing elsewhere but let's keep it simple for
981 #ifdef CONFIG_TRACE_IRQFLAGS
987 #endif /* CONFIG_TRACE_IRQFLAGS */
989 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
990 * accessing a userspace segment (even from the kernel). We assume
991 * kernel addresses always have the high bit set.
993 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
994 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
995 orc r0,r12,r0 /* MSR_PR | ~high_bit */
996 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
997 ori r4,r4,1 /* add _PAGE_PRESENT */
998 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1001 * r3 contains the faulting address
1002 * r4 contains the required access permissions
1003 * r5 contains the trap number
1005 * at return r3 = 0 for success
1007 bl .hash_page /* build HPTE if possible */
1008 cmpdi r3,0 /* see if hash_page succeeded */
1010 BEGIN_FW_FTR_SECTION
1012 * If we had interrupts soft-enabled at the point where the
1013 * DSI/ISI occurred, and an interrupt came in during hash_page,
1015 * We jump to ret_from_except_lite rather than fast_exception_return
1016 * because ret_from_except_lite will check for and handle pending
1017 * interrupts if necessary.
1020 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1022 BEGIN_FW_FTR_SECTION
1024 * Here we have interrupts hard-disabled, so it is sufficient
1025 * to restore paca->{soft,hard}_enable and get out.
1027 beq fast_exc_return_irq /* Return from exception on success */
1028 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1030 /* For a hash failure, we don't bother re-enabling interrupts */
1034 * hash_page couldn't handle it, set soft interrupt enable back
1035 * to what it was before the trap. Note that .raw_local_irq_restore
1036 * handles any interrupts pending at this point.
1039 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
1040 bl .raw_local_irq_restore
1043 /* Here we have a page fault that hash_page can't handle. */
1048 addi r3,r1,STACK_FRAME_OVERHEAD
1054 addi r3,r1,STACK_FRAME_OVERHEAD
1059 13: b .ret_from_except_lite
1061 /* We have a page fault that hash_page could handle but HV refused
1066 addi r3,r1,STACK_FRAME_OVERHEAD
1071 /* here we have a segment miss */
1073 bl .ste_allocate /* try to insert stab entry */
1075 bne- handle_page_fault
1076 b fast_exception_return
1079 * r13 points to the PACA, r9 contains the saved CR,
1080 * r11 and r12 contain the saved SRR0 and SRR1.
1081 * r9 - r13 are saved in paca->exslb.
1082 * We assume we aren't going to take any exceptions during this procedure.
1083 * We assume (DAR >> 60) == 0xc.
1086 _GLOBAL(do_stab_bolted)
1087 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1088 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1090 /* Hash to the primary group */
1091 ld r10,PACASTABVIRT(r13)
1094 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1096 /* Calculate VSID */
1097 /* This is a kernel address, so protovsid = ESID */
1098 ASM_VSID_SCRAMBLE(r11, r9, 256M)
1099 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1101 /* Search the primary group for a free entry */
1102 1: ld r11,0(r10) /* Test valid bit of the current ste */
1109 /* Stick for only searching the primary group for now. */
1110 /* At least for now, we use a very simple random castout scheme */
1111 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1113 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1116 /* r10 currently points to an ste one past the group of interest */
1117 /* make it point to the randomly selected entry */
1119 or r10,r10,r11 /* r10 is the entry to invalidate */
1121 isync /* mark the entry invalid */
1123 rldicl r11,r11,56,1 /* clear the valid bit */
1128 clrrdi r11,r11,28 /* Get the esid part of the ste */
1131 2: std r9,8(r10) /* Store the vsid part of the ste */
1134 mfspr r11,SPRN_DAR /* Get the new esid */
1135 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1136 ori r11,r11,0x90 /* Turn on valid and kp */
1137 std r11,0(r10) /* Put new entry back into the stab */
1141 /* All done -- return from exception. */
1142 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1143 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1145 andi. r10,r12,MSR_RI
1148 mtcrf 0x80,r9 /* restore CR */
1156 ld r9,PACA_EXSLB+EX_R9(r13)
1157 ld r10,PACA_EXSLB+EX_R10(r13)
1158 ld r11,PACA_EXSLB+EX_R11(r13)
1159 ld r12,PACA_EXSLB+EX_R12(r13)
1160 ld r13,PACA_EXSLB+EX_R13(r13)
1162 b . /* prevent speculative execution */
1165 * Space for CPU0's segment table.
1167 * On iSeries, the hypervisor must fill in at least one entry before
1168 * we get control (with relocate on). The address is given to the hv
1169 * as a page number (see xLparMap below), so this must be at a
1170 * fixed address (the linker can't compute (u64)&initial_stab >>
1173 . = STAB0_OFFSET /* 0x6000 */
1178 #ifdef CONFIG_PPC_PSERIES
1180 * Data area reserved for FWNMI option.
1181 * This address (0x7000) is fixed by the RPA.
1184 .globl fwnmi_data_area
1186 #endif /* CONFIG_PPC_PSERIES */
1188 /* iSeries does not use the FWNMI stuff, so it is safe to put
1189 * this here, even if we later allow kernels that will boot on
1190 * both pSeries and iSeries */
1191 #ifdef CONFIG_PPC_ISERIES
1195 .quad HvEsidsToMap /* xNumberEsids */
1196 .quad HvRangesToMap /* xNumberRanges */
1197 .quad STAB0_PAGE /* xSegmentTableOffs */
1198 .zero 40 /* xRsvd */
1199 /* xEsids (HvEsidsToMap entries of 2 quads) */
1200 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1201 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1202 .quad VMALLOC_START_ESID /* xKernelEsid */
1203 .quad VMALLOC_START_VSID /* xKernelVsid */
1204 /* xRanges (HvRangesToMap entries of 3 quads) */
1205 .quad HvPagesToMap /* xPages */
1206 .quad 0 /* xOffset */
1207 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1209 #endif /* CONFIG_PPC_ISERIES */
1211 #ifdef CONFIG_PPC_PSERIES
1213 #endif /* CONFIG_PPC_PSERIES */
1216 * On pSeries and most other platforms, secondary processors spin
1217 * in the following code.
1218 * At entry, r3 = this processor's number (physical cpu id)
1220 _GLOBAL(generic_secondary_smp_init)
1223 /* turn on 64-bit mode */
1226 /* get the TOC pointer (real address) */
1229 /* Set up a paca value for this processor. Since we have the
1230 * physical cpu id in r24, we need to search the pacas to find
1231 * which logical id maps to our physical one.
1233 LOAD_REG_ADDR(r13, paca) /* Get base vaddr of paca array */
1234 li r5,0 /* logical cpu id */
1235 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1236 cmpw r6,r24 /* Compare to our id */
1238 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1243 mr r3,r24 /* not found, copy phys to r3 */
1244 b .kexec_wait /* next kernel might do better */
1246 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1247 /* From now on, r24 is expected to be logical cpuid */
1250 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1254 b 3b /* Never go on non-SMP */
1257 beq 3b /* Loop until told to go */
1259 sync /* order paca.run and cur_cpu_spec */
1261 /* See if we need to call a cpu state restore handler */
1262 LOAD_REG_ADDR(r23, cur_cpu_spec)
1264 ld r23,CPU_SPEC_RESTORE(r23)
1271 4: /* Create a temp kernel stack for use before relocation is on. */
1272 ld r1,PACAEMERGSP(r13)
1273 subi r1,r1,STACK_FRAME_OVERHEAD
1280 * Assumes we're mapped EA == RA if the MMU is on.
1284 andi. r0,r3,MSR_IR|MSR_DR
1292 b . /* prevent speculative execution */
1296 * Here is our main kernel entry point. We support currently 2 kind of entries
1297 * depending on the value of r5.
1299 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1302 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1303 * DT block, r4 is a physical pointer to the kernel itself
1306 _GLOBAL(__start_initialization_multiplatform)
1307 /* Make sure we are running in 64 bits mode */
1310 /* Get TOC pointer (current runtime address) */
1313 /* find out where we are now */
1315 0: mflr r26 /* r26 = runtime addr here */
1316 addis r26,r26,(_stext - 0b)@ha
1317 addi r26,r26,(_stext - 0b)@l /* current runtime base addr */
1320 * Are we booted from a PROM Of-type client-interface ?
1324 b .__boot_from_prom /* yes -> prom */
1326 /* Save parameters */
1330 /* Setup some critical 970 SPRs before switching MMU off */
1333 cmpwi r0,0x39 /* 970 */
1335 cmpwi r0,0x3c /* 970FX */
1337 cmpwi r0,0x44 /* 970MP */
1339 cmpwi r0,0x45 /* 970GX */
1341 1: bl .__cpu_preinit_ppc970
1344 /* Switch off MMU if not already off */
1346 b .__after_prom_start
1348 _INIT_STATIC(__boot_from_prom)
1349 /* Save parameters */
1357 * Align the stack to 16-byte boundary
1358 * Depending on the size and layout of the ELF sections in the initial
1359 * boot binary, the stack pointer may be unaligned on PowerMac
1363 #ifdef CONFIG_RELOCATABLE
1364 /* Relocate code for where we are now */
1369 /* Restore parameters */
1376 /* Do all of the interaction with OF client interface */
1379 /* We never return */
1382 _STATIC(__after_prom_start)
1383 #ifdef CONFIG_RELOCATABLE
1384 /* process relocations for the final address of the kernel */
1385 lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */
1392 * We need to run with _stext at physical address PHYSICAL_START.
1393 * This will leave some code in the first 256B of
1394 * real memory, which are reserved for software use.
1396 * Note: This process overwrites the OF exception vectors.
1398 li r3,0 /* target addr */
1399 mr. r4,r26 /* In some cases the loader may */
1400 beq 9f /* have already put us at zero */
1401 lis r5,(copy_to_here - _stext)@ha
1402 addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */
1403 li r6,0x100 /* Start offset, the first 0x100 */
1404 /* bytes were copied earlier. */
1406 bl .copy_and_flush /* copy the first n bytes */
1407 /* this includes the code being */
1408 /* executed here. */
1409 addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */
1410 addi r8,r8,(4f - _stext)@l /* that we just made */
1414 4: /* Now copy the rest of the kernel up to _end */
1415 addis r5,r26,(p_end - _stext)@ha
1416 ld r5,(p_end - _stext)@l(r5) /* get _end */
1417 bl .copy_and_flush /* copy the rest */
1419 9: b .start_here_multiplatform
1421 p_end: .llong _end - _stext
1424 * Copy routine used to copy the kernel to start at physical address 0
1425 * and flush and invalidate the caches as needed.
1426 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1427 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1429 * Note: this routine *only* clobbers r0, r6 and lr
1431 _GLOBAL(copy_and_flush)
1434 4: li r0,8 /* Use the smallest common */
1435 /* denominator cache line */
1436 /* size. This results in */
1437 /* extra cache line flushes */
1438 /* but operation is correct. */
1439 /* Can't get cache line size */
1440 /* from NACA as it is being */
1443 mtctr r0 /* put # words/line in ctr */
1444 3: addi r6,r6,8 /* copy a cache line */
1448 dcbst r6,r3 /* write it to memory */
1450 icbi r6,r3 /* flush the icache line */
1462 #ifdef CONFIG_PPC_PMAC
1464 * On PowerMac, secondary processors starts from the reset vector, which
1465 * is temporarily turned into a call to one of the functions below.
1470 .globl __secondary_start_pmac_0
1471 __secondary_start_pmac_0:
1472 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1482 _GLOBAL(pmac_secondary_start)
1483 /* turn on 64-bit mode */
1486 /* get TOC pointer (real address) */
1489 /* Copy some CPU settings from CPU 0 */
1490 bl .__restore_cpu_ppc970
1492 /* pSeries do that early though I don't think we really need it */
1495 mtmsrd r3 /* RI on */
1497 /* Set up a paca value for this processor. */
1498 LOAD_REG_ADDR(r4,paca) /* Get base vaddr of paca array */
1499 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1500 add r13,r13,r4 /* for this processor. */
1501 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1503 /* Create a temp kernel stack for use before relocation is on. */
1504 ld r1,PACAEMERGSP(r13)
1505 subi r1,r1,STACK_FRAME_OVERHEAD
1509 #endif /* CONFIG_PPC_PMAC */
1512 * This function is called after the master CPU has released the
1513 * secondary processors. The execution environment is relocation off.
1514 * The paca for this processor has the following fields initialized at
1516 * 1. Processor number
1517 * 2. Segment table pointer (virtual address)
1518 * On entry the following are set:
1519 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1520 * r24 = cpu# (in Linux terms)
1521 * r13 = paca virtual address
1522 * SPRG3 = paca virtual address
1524 .globl __secondary_start
1526 /* Set thread priority to MEDIUM */
1529 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1530 bl .early_setup_secondary
1532 /* Initialize the kernel stack. Just a repeat for iSeries. */
1533 LOAD_REG_ADDR(r3, current_set)
1534 sldi r28,r24,3 /* get current_set[cpu#] */
1536 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1537 std r1,PACAKSAVE(r13)
1539 /* Clear backchain so we get nice backtraces */
1543 /* enable MMU and jump to start_secondary */
1544 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1545 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1546 #ifdef CONFIG_PPC_ISERIES
1547 BEGIN_FW_FTR_SECTION
1550 stb r8,PACAHARDIRQEN(r13)
1551 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1553 BEGIN_FW_FTR_SECTION
1554 stb r7,PACAHARDIRQEN(r13)
1555 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1556 stb r7,PACASOFTIRQEN(r13)
1561 b . /* prevent speculative execution */
1564 * Running with relocation on at this point. All we want to do is
1565 * zero the stack back-chain pointer and get the TOC virtual address
1566 * before going into C code.
1568 _GLOBAL(start_secondary_prolog)
1571 std r3,0(r1) /* Zero the stack frame pointer */
1577 * This subroutine clobbers r11 and r12
1579 _GLOBAL(enable_64b_mode)
1580 mfmsr r11 /* grab the current MSR */
1581 li r12,(MSR_SF | MSR_ISF)@highest
1589 * This puts the TOC pointer into r2, offset by 0x8000 (as expected
1590 * by the toolchain). It computes the correct value for wherever we
1591 * are running at the moment, using position-independent code.
1593 _GLOBAL(relative_toc)
1597 ld r2,(p_toc - 0b)(r9)
1602 p_toc: .llong __toc_start + 0x8000 - 0b
1605 * This is where the main kernel code starts.
1607 _INIT_STATIC(start_here_multiplatform)
1608 /* set up the TOC (real address) */
1611 /* Clear out the BSS. It may have been done in prom_init,
1612 * already but that's irrelevant since prom_init will soon
1613 * be detached from the kernel completely. Besides, we need
1614 * to clear it now for kexec-style entry.
1616 LOAD_REG_ADDR(r11,__bss_stop)
1617 LOAD_REG_ADDR(r8,__bss_start)
1618 sub r11,r11,r8 /* bss size */
1619 addi r11,r11,7 /* round up to an even double word */
1620 srdi. r11,r11,3 /* shift right by 3 */
1624 mtctr r11 /* zero this many doublewords */
1631 mtmsrd r6 /* RI on */
1633 #ifdef CONFIG_RELOCATABLE
1634 /* Save the physical address we're running at in kernstart_addr */
1635 LOAD_REG_ADDR(r4, kernstart_addr)
1640 /* The following gets the stack set up with the regs */
1641 /* pointing to the real addr of the kernel stack. This is */
1642 /* all done to support the C function call below which sets */
1643 /* up the htab. This is done because we have relocated the */
1644 /* kernel but are still running in real mode. */
1646 LOAD_REG_ADDR(r3,init_thread_union)
1648 /* set up a stack pointer */
1649 addi r1,r3,THREAD_SIZE
1651 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1653 /* Do very early kernel initializations, including initial hash table,
1654 * stab and slb setup before we turn on relocation. */
1656 /* Restore parameters passed from prom_init/kexec */
1658 bl .early_setup /* also sets r13 and SPRG3 */
1660 LOAD_REG_ADDR(r3, .start_here_common)
1665 b . /* prevent speculative execution */
1667 /* This is where all platforms converge execution */
1668 _INIT_GLOBAL(start_here_common)
1669 /* relocation is on at this point */
1670 std r1,PACAKSAVE(r13)
1672 /* Load the TOC (virtual address) */
1677 /* Load up the kernel context */
1680 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1681 #ifdef CONFIG_PPC_ISERIES
1682 BEGIN_FW_FTR_SECTION
1684 ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
1687 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1689 stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
1697 * We put a few things here that have to be page-aligned.
1698 * This stuff goes at the beginning of the bss, which is page-aligned.
1704 .globl empty_zero_page
1708 .globl swapper_pg_dir
1710 .space PGD_TABLE_SIZE