2 * arch/ppc64/kernel/head.S
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
8 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
9 * Adapted for Power Macintosh by Paul Mackerras.
10 * Low-level exception handlers and MMU support
11 * rewritten by Paul Mackerras.
12 * Copyright (C) 1996 Paul Mackerras.
14 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
15 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
17 * This file contains the low-level support and setup for the
18 * PowerPC-64 platform, including trap and interrupt dispatch.
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version
23 * 2 of the License, or (at your option) any later version.
26 #define SECONDARY_PROCESSORS
28 #include <linux/config.h>
29 #include <linux/threads.h>
30 #include <asm/processor.h>
34 #include <asm/systemcfg.h>
35 #include <asm/ppc_asm.h>
36 #include <asm/offsets.h>
38 #include <asm/cputable.h>
39 #include <asm/setup.h>
40 #include <asm/hvcall.h>
42 #ifdef CONFIG_PPC_ISERIES
43 #define DO_SOFT_DISABLE
47 * hcall interface to pSeries LPAR
49 #define H_SET_ASR 0x30
52 * We layout physical memory as follows:
53 * 0x0000 - 0x00ff : Secondary processor spin code
54 * 0x0100 - 0x2fff : pSeries Interrupt prologs
55 * 0x3000 - 0x3fff : Interrupt support
56 * 0x4000 - 0x4fff : NACA
57 * 0x6000 : iSeries and common interrupt prologs
58 * 0x9000 - 0x9fff : Initial segment table
66 * SPRG0 reserved for hypervisor
67 * SPRG1 temp - used to save gpr
68 * SPRG2 temp - used to save gpr
69 * SPRG3 virt addr of paca
73 * Entering into this code we make the following assumptions:
75 * 1. The MMU is off & open firmware is running in real mode.
76 * 2. The kernel is entered at __start
79 * 1. The MMU is on (as it always is for iSeries)
80 * 2. The kernel is entered at system_reset_iSeries
86 #ifdef CONFIG_PPC_MULTIPLATFORM
88 /* NOP this out unconditionally */
90 b .__start_initialization_multiplatform
92 #endif /* CONFIG_PPC_MULTIPLATFORM */
94 /* Catch branch to 0 in real mode */
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
105 * At offset 0x28 and 0x30 are offsets to the msChunks
106 * array (used by the iSeries LPAR debugger to do translation
107 * between physical addresses and absolute addresses) and
108 * to the pidhash table (also used by the debugger)
110 .llong msChunks-KERNELBASE
111 .llong 0 /* pidhash-KERNELBASE SFRXXX */
113 /* Offset 0x38 - Pointer to start of embedded System.map */
114 .globl embedded_sysmap_start
115 embedded_sysmap_start:
117 /* Offset 0x40 - Pointer to end of embedded System.map */
118 .globl embedded_sysmap_end
122 #else /* CONFIG_PPC_ISERIES */
124 /* Secondary processors spin on this value until it goes to 1. */
125 .globl __secondary_hold_spinloop
126 __secondary_hold_spinloop:
129 /* Secondary processors write this value with their cpu # */
130 /* after they enter the spin loop immediately below. */
131 .globl __secondary_hold_acknowledge
132 __secondary_hold_acknowledge:
137 * The following code is used on pSeries to hold secondary processors
138 * in a spin loop after they have been freed from OpenFirmware, but
139 * before the bulk of the kernel has been relocated. This code
140 * is relocated to physical address 0x60 before prom_init is run.
141 * All of it must fit below the first exception vector at 0x100.
143 _GLOBAL(__secondary_hold)
146 mtmsrd r24 /* RI on */
148 /* Grab our linux cpu number */
151 /* Tell the master cpu we're here */
152 /* Relocation is off & we are located at an address less */
153 /* than 0x100, so only need to grab low order offset. */
154 std r24,__secondary_hold_acknowledge@l(0)
157 /* All secondary cpu's wait here until told to start. */
158 100: ld r4,__secondary_hold_spinloop@l(0)
167 b .pSeries_secondary_smp_init
174 /* This value is used to mark exception frames on the stack. */
177 .tc ID_72656773_68657265[TC],0x7265677368657265
181 * The following macros define the code that appears as
182 * the prologue to each of the exception handlers. They
183 * are split into two parts to allow a single kernel binary
184 * to be used for pSeries and iSeries.
185 * LOL. One day... - paulus
189 * We make as much of the exception code common between native
190 * exception handlers (including pSeries LPAR) and iSeries LPAR
191 * implementations as possible.
195 * This is the start of the interrupt handlers for pSeries
196 * This code runs with relocation off.
204 #define EX_R3 40 /* SLB miss saves R3, but not SRR0 */
206 #define EX_LR 48 /* SLB miss saves LR, but not DAR */
210 #define EXCEPTION_PROLOG_PSERIES(area, label) \
211 mfspr r13,SPRG3; /* get paca address into r13 */ \
212 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
213 std r10,area+EX_R10(r13); \
214 std r11,area+EX_R11(r13); \
215 std r12,area+EX_R12(r13); \
217 std r9,area+EX_R13(r13); \
219 clrrdi r12,r13,32; /* get high part of &label */ \
221 mfspr r11,SRR0; /* save SRR0 */ \
222 ori r12,r12,(label)@l; /* virt addr of handler */ \
223 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
225 mfspr r12,SRR1; /* and SRR1 */ \
228 b . /* prevent speculative execution */
231 * This is the start of the interrupt handlers for iSeries
232 * This code runs with relocation on.
234 #define EXCEPTION_PROLOG_ISERIES_1(area) \
235 mfspr r13,SPRG3; /* get paca address into r13 */ \
236 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
237 std r10,area+EX_R10(r13); \
238 std r11,area+EX_R11(r13); \
239 std r12,area+EX_R12(r13); \
241 std r9,area+EX_R13(r13); \
244 #define EXCEPTION_PROLOG_ISERIES_2 \
246 ld r11,PACALPPACA+LPPACASRR0(r13); \
247 ld r12,PACALPPACA+LPPACASRR1(r13); \
248 ori r10,r10,MSR_RI; \
252 * The common exception prolog is used for all except a few exceptions
253 * such as a segment miss on a kernel address. We have to be prepared
254 * to take another exception from the point where we first touch the
255 * kernel stack onwards.
257 * On entry r13 points to the paca, r9-r13 are saved in the paca,
258 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
259 * SRR1, and relocation is on.
261 #define EXCEPTION_PROLOG_COMMON(n, area) \
262 andi. r10,r12,MSR_PR; /* See if coming from user */ \
263 mr r10,r1; /* Save r1 */ \
264 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
266 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
267 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
268 bge- cr1,bad_stack; /* abort if it is */ \
269 std r9,_CCR(r1); /* save CR in stackframe */ \
270 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
271 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
272 std r10,0(r1); /* make stack chain pointer */ \
273 std r0,GPR0(r1); /* save r0 in stackframe */ \
274 std r10,GPR1(r1); /* save r1 in stackframe */ \
275 std r2,GPR2(r1); /* save r2 in stackframe */ \
276 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
277 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
278 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
279 ld r10,area+EX_R10(r13); \
282 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
283 ld r10,area+EX_R12(r13); \
284 ld r11,area+EX_R13(r13); \
288 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
289 mflr r9; /* save LR in stackframe */ \
291 mfctr r10; /* save CTR in stackframe */ \
293 mfspr r11,XER; /* save XER in stackframe */ \
296 std r9,_TRAP(r1); /* set trap number */ \
298 ld r11,exception_marker@toc(r2); \
299 std r10,RESULT(r1); /* clear regs->result */ \
300 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
305 #define STD_EXCEPTION_PSERIES(n, label) \
307 .globl label##_pSeries; \
310 mtspr SPRG1,r13; /* save r13 */ \
312 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
314 #define STD_EXCEPTION_ISERIES(n, label, area) \
315 .globl label##_iSeries; \
318 mtspr SPRG1,r13; /* save r13 */ \
320 EXCEPTION_PROLOG_ISERIES_1(area); \
321 EXCEPTION_PROLOG_ISERIES_2; \
324 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
325 .globl label##_iSeries; \
328 mtspr SPRG1,r13; /* save r13 */ \
330 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
331 lbz r10,PACAPROCENABLED(r13); \
333 beq- label##_iSeries_masked; \
334 EXCEPTION_PROLOG_ISERIES_2; \
337 #ifdef DO_SOFT_DISABLE
338 #define DISABLE_INTS \
339 lbz r10,PACAPROCENABLED(r13); \
343 stb r11,PACAPROCENABLED(r13); \
344 ori r10,r10,MSR_EE; \
347 #define ENABLE_INTS \
348 lbz r10,PACAPROCENABLED(r13); \
351 ori r11,r11,MSR_EE; \
354 #else /* hard enable/disable interrupts */
357 #define ENABLE_INTS \
360 rlwimi r11,r12,0,MSR_EE; \
365 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
367 .globl label##_common; \
369 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
372 addi r3,r1,STACK_FRAME_OVERHEAD; \
376 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
378 .globl label##_common; \
380 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
382 addi r3,r1,STACK_FRAME_OVERHEAD; \
384 b .ret_from_except_lite
387 * Start of pSeries system interrupt routines
390 .globl __start_interrupts
393 STD_EXCEPTION_PSERIES(0x100, system_reset)
396 _machine_check_pSeries:
398 mtspr SPRG1,r13 /* save r13 */
400 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
403 .globl data_access_pSeries
412 rlwimi r13,r12,16,0x20
415 beq .do_stab_bolted_pSeries
418 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
419 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
422 .globl data_access_slb_pSeries
423 data_access_slb_pSeries:
427 mfspr r13,SPRG3 /* get paca address into r13 */
428 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
429 std r10,PACA_EXSLB+EX_R10(r13)
430 std r11,PACA_EXSLB+EX_R11(r13)
431 std r12,PACA_EXSLB+EX_R12(r13)
432 std r3,PACA_EXSLB+EX_R3(r13)
434 std r9,PACA_EXSLB+EX_R13(r13)
436 mfspr r12,SRR1 /* and SRR1 */
438 b .do_slb_miss /* Rel. branch works in real mode */
440 STD_EXCEPTION_PSERIES(0x400, instruction_access)
443 .globl instruction_access_slb_pSeries
444 instruction_access_slb_pSeries:
448 mfspr r13,SPRG3 /* get paca address into r13 */
449 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
450 std r10,PACA_EXSLB+EX_R10(r13)
451 std r11,PACA_EXSLB+EX_R11(r13)
452 std r12,PACA_EXSLB+EX_R12(r13)
453 std r3,PACA_EXSLB+EX_R3(r13)
455 std r9,PACA_EXSLB+EX_R13(r13)
457 mfspr r12,SRR1 /* and SRR1 */
458 mfspr r3,SRR0 /* SRR0 is faulting address */
459 b .do_slb_miss /* Rel. branch works in real mode */
461 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
462 STD_EXCEPTION_PSERIES(0x600, alignment)
463 STD_EXCEPTION_PSERIES(0x700, program_check)
464 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
465 STD_EXCEPTION_PSERIES(0x900, decrementer)
466 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
467 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
470 .globl system_call_pSeries
479 oris r12,r12,system_call_common@h
480 ori r12,r12,system_call_common@l
482 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
486 b . /* prevent speculative execution */
488 STD_EXCEPTION_PSERIES(0xd00, single_step)
489 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
491 /* We need to deal with the Altivec unavailable exception
492 * here which is at 0xf20, thus in the middle of the
493 * prolog code of the PerformanceMonitor one. A little
494 * trickery is thus necessary
497 b performance_monitor_pSeries
499 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
501 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
502 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
504 /* moved from 0xf00 */
505 STD_EXCEPTION_PSERIES(0x3000, performance_monitor)
508 _GLOBAL(do_stab_bolted_pSeries)
511 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
514 /* Space for the naca. Architected to be located at real address
515 * NACA_PHYS_ADDR. Various tools rely on this location being fixed.
516 * The first dword of the naca is required by iSeries LPAR to
517 * point to itVpdAreas. On pSeries native, this value is not used.
520 .globl __end_interrupts
522 #ifdef CONFIG_PPC_ISERIES
526 .llong 0 /* xRamDisk */
527 .llong 0 /* xRamDiskSize */
531 /*** ISeries-LPAR interrupt handlers ***/
533 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
535 .globl data_access_iSeries
543 rlwimi r13,r12,16,0x20
546 beq .do_stab_bolted_iSeries
549 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
550 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
551 EXCEPTION_PROLOG_ISERIES_2
554 .do_stab_bolted_iSeries:
557 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
558 EXCEPTION_PROLOG_ISERIES_2
561 .globl data_access_slb_iSeries
562 data_access_slb_iSeries:
563 mtspr SPRG1,r13 /* save r13 */
564 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
565 std r3,PACA_EXSLB+EX_R3(r13)
566 ld r12,PACALPPACA+LPPACASRR1(r13)
570 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
572 .globl instruction_access_slb_iSeries
573 instruction_access_slb_iSeries:
574 mtspr SPRG1,r13 /* save r13 */
575 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
576 std r3,PACA_EXSLB+EX_R3(r13)
577 ld r12,PACALPPACA+LPPACASRR1(r13)
578 ld r3,PACALPPACA+LPPACASRR0(r13)
581 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
582 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
583 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
584 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
585 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
586 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
587 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
589 .globl system_call_iSeries
593 EXCEPTION_PROLOG_ISERIES_2
596 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
597 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
598 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
600 .globl system_reset_iSeries
601 system_reset_iSeries:
602 mfspr r13,SPRG3 /* Get paca address */
605 mtmsrd r24 /* RI on */
606 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
607 cmpwi 0,r24,0 /* Are we processor 0? */
608 beq .__start_initialization_iSeries /* Start up the first processor */
610 li r5,CTRL_RUNLATCH /* Turn off the run light */
617 lbz r23,PACAPROCSTART(r13) /* Test if this processor
620 LOADADDR(r3,current_set)
621 sldi r28,r24,3 /* get current_set[cpu#] */
623 addi r1,r3,THREAD_SIZE
624 subi r1,r1,STACK_FRAME_OVERHEAD
627 beq iSeries_secondary_smp_loop /* Loop until told to go */
628 #ifdef SECONDARY_PROCESSORS
629 bne .__secondary_start /* Loop until told to go */
631 iSeries_secondary_smp_loop:
632 /* Let the Hypervisor know we are alive */
633 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
635 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
636 #else /* CONFIG_SMP */
637 /* Yield the processor. This is required for non-SMP kernels
638 which are running on multi-threaded machines. */
640 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
641 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
642 li r4,0 /* "yield timed" */
643 li r5,-1 /* "yield forever" */
644 #endif /* CONFIG_SMP */
645 li r0,-1 /* r0=-1 indicates a Hypervisor call */
646 sc /* Invoke the hypervisor via a system call */
647 mfspr r13,SPRG3 /* Put r13 back ???? */
648 b 1b /* If SMP not configured, secondaries
651 .globl decrementer_iSeries_masked
652 decrementer_iSeries_masked:
654 stb r11,PACALPPACA+LPPACADECRINT(r13)
655 lwz r12,PACADEFAULTDECR(r13)
659 .globl hardware_interrupt_iSeries_masked
660 hardware_interrupt_iSeries_masked:
661 mtcrf 0x80,r9 /* Restore regs */
662 ld r11,PACALPPACA+LPPACASRR0(r13)
663 ld r12,PACALPPACA+LPPACASRR1(r13)
666 ld r9,PACA_EXGEN+EX_R9(r13)
667 ld r10,PACA_EXGEN+EX_R10(r13)
668 ld r11,PACA_EXGEN+EX_R11(r13)
669 ld r12,PACA_EXGEN+EX_R12(r13)
670 ld r13,PACA_EXGEN+EX_R13(r13)
672 b . /* prevent speculative execution */
676 * Data area reserved for FWNMI option.
679 .globl fwnmi_data_area
683 * Vectors for the FWNMI option. Share common code.
686 .globl system_reset_fwnmi
689 mtspr SPRG1,r13 /* save r13 */
691 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
692 .globl machine_check_fwnmi
695 mtspr SPRG1,r13 /* save r13 */
697 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
700 * Space for the initial segment table
701 * For LPAR, the hypervisor must fill in at least one entry
702 * before we get control (with relocate on)
708 . = (STAB0_PHYS_ADDR + PAGE_SIZE)
713 /*** Common interrupt handlers ***/
715 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
718 * Machine check is different because we use a different
719 * save area: PACA_EXMC instead of PACA_EXGEN.
722 .globl machine_check_common
723 machine_check_common:
724 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
727 addi r3,r1,STACK_FRAME_OVERHEAD
728 bl .machine_check_exception
731 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
732 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
733 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
734 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
735 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
736 STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
737 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
738 #ifdef CONFIG_ALTIVEC
739 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
741 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
745 * Here we have detected that the kernel stack pointer is bad.
746 * R9 contains the saved CR, r13 points to the paca,
747 * r10 contains the (bad) kernel stack pointer,
748 * r11 and r12 contain the saved SRR0 and SRR1.
749 * We switch to using the paca guard page as an emergency stack,
750 * save the registers there, and call kernel_bad_stack(), which panics.
753 ld r1,PACAEMERGSP(r13)
754 subi r1,r1,64+INT_FRAME_SIZE
775 addi r11,r1,INT_FRAME_SIZE
780 1: addi r3,r1,STACK_FRAME_OVERHEAD
785 * Return from an exception with minimal checks.
786 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
787 * If interrupts have been enabled, or anything has been
788 * done that might have changed the scheduling status of
789 * any task or sent any task a signal, you should use
790 * ret_from_except or ret_from_except_lite instead of this.
792 fast_exception_return:
795 andi. r3,r12,MSR_RI /* check if RI is set */
809 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
817 b . /* prevent speculative execution */
821 1: addi r3,r1,STACK_FRAME_OVERHEAD
822 bl .unrecoverable_exception
826 * Here r13 points to the paca, r9 contains the saved CR,
827 * SRR0 and SRR1 are saved in r11 and r12,
828 * r9 - r13 are saved in paca->exgen.
831 .globl data_access_common
833 RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
835 std r10,PACA_EXGEN+EX_DAR(r13)
837 stw r10,PACA_EXGEN+EX_DSISR(r13)
838 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
839 ld r3,PACA_EXGEN+EX_DAR(r13)
840 lwz r4,PACA_EXGEN+EX_DSISR(r13)
842 b .do_hash_page /* Try to handle as hpte fault */
845 .globl instruction_access_common
846 instruction_access_common:
847 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
851 b .do_hash_page /* Try to handle as hpte fault */
854 .globl hardware_interrupt_common
855 .globl hardware_interrupt_entry
856 hardware_interrupt_common:
857 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
858 hardware_interrupt_entry:
860 addi r3,r1,STACK_FRAME_OVERHEAD
862 b .ret_from_except_lite
865 .globl alignment_common
868 std r10,PACA_EXGEN+EX_DAR(r13)
870 stw r10,PACA_EXGEN+EX_DSISR(r13)
871 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
872 ld r3,PACA_EXGEN+EX_DAR(r13)
873 lwz r4,PACA_EXGEN+EX_DSISR(r13)
877 addi r3,r1,STACK_FRAME_OVERHEAD
879 bl .alignment_exception
883 .globl program_check_common
884 program_check_common:
885 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
887 addi r3,r1,STACK_FRAME_OVERHEAD
889 bl .program_check_exception
893 .globl fp_unavailable_common
894 fp_unavailable_common:
895 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
896 bne .load_up_fpu /* if from user, just load it up */
898 addi r3,r1,STACK_FRAME_OVERHEAD
900 bl .kernel_fp_unavailable_exception
904 .globl altivec_unavailable_common
905 altivec_unavailable_common:
906 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
907 #ifdef CONFIG_ALTIVEC
909 bne .load_up_altivec /* if from user, just load it up */
910 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
913 addi r3,r1,STACK_FRAME_OVERHEAD
915 bl .altivec_unavailable_exception
922 _GLOBAL(do_hash_page)
926 andis. r0,r4,0xa450 /* weird error? */
927 bne- .handle_page_fault /* if not, try to insert a HPTE */
929 andis. r0,r4,0x0020 /* Is it a segment table fault? */
930 bne- .do_ste_alloc /* If so handle it */
931 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
934 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
935 * accessing a userspace segment (even from the kernel). We assume
936 * kernel addresses always have the high bit set.
938 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
939 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
940 orc r0,r12,r0 /* MSR_PR | ~high_bit */
941 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
942 ori r4,r4,1 /* add _PAGE_PRESENT */
943 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
946 * On iSeries, we soft-disable interrupts here, then
947 * hard-enable interrupts so that the hash_page code can spin on
948 * the hash_table_lock without problems on a shared processor.
953 * r3 contains the faulting address
954 * r4 contains the required access permissions
955 * r5 contains the trap number
957 * at return r3 = 0 for success
959 bl .hash_page /* build HPTE if possible */
960 cmpdi r3,0 /* see if hash_page succeeded */
962 #ifdef DO_SOFT_DISABLE
964 * If we had interrupts soft-enabled at the point where the
965 * DSI/ISI occurred, and an interrupt came in during hash_page,
967 * We jump to ret_from_except_lite rather than fast_exception_return
968 * because ret_from_except_lite will check for and handle pending
969 * interrupts if necessary.
971 beq .ret_from_except_lite
972 /* For a hash failure, we don't bother re-enabling interrupts */
976 * hash_page couldn't handle it, set soft interrupt enable back
977 * to what it was before the trap. Note that .local_irq_restore
978 * handles any interrupts pending at this point.
981 bl .local_irq_restore
984 beq fast_exception_return /* Return from exception on success */
985 ble- 12f /* Failure return from hash_page */
990 /* Here we have a page fault that hash_page can't handle. */
991 _GLOBAL(handle_page_fault)
995 addi r3,r1,STACK_FRAME_OVERHEAD
998 beq+ .ret_from_except_lite
1001 addi r3,r1,STACK_FRAME_OVERHEAD
1006 /* We have a page fault that hash_page could handle but HV refused
1010 addi r3,r1,STACK_FRAME_OVERHEAD
1015 /* here we have a segment miss */
1016 _GLOBAL(do_ste_alloc)
1017 bl .ste_allocate /* try to insert stab entry */
1019 beq+ fast_exception_return
1020 b .handle_page_fault
1023 * r13 points to the PACA, r9 contains the saved CR,
1024 * r11 and r12 contain the saved SRR0 and SRR1.
1025 * r9 - r13 are saved in paca->exslb.
1026 * We assume we aren't going to take any exceptions during this procedure.
1027 * We assume (DAR >> 60) == 0xc.
1030 _GLOBAL(do_stab_bolted)
1031 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1032 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1034 /* Hash to the primary group */
1035 ld r10,PACASTABVIRT(r13)
1038 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1040 /* Calculate VSID */
1041 /* This is a kernel address, so protovsid = ESID */
1042 ASM_VSID_SCRAMBLE(r11, r9)
1043 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1045 /* Search the primary group for a free entry */
1046 1: ld r11,0(r10) /* Test valid bit of the current ste */
1053 /* Stick for only searching the primary group for now. */
1054 /* At least for now, we use a very simple random castout scheme */
1055 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1057 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1060 /* r10 currently points to an ste one past the group of interest */
1061 /* make it point to the randomly selected entry */
1063 or r10,r10,r11 /* r10 is the entry to invalidate */
1065 isync /* mark the entry invalid */
1067 rldicl r11,r11,56,1 /* clear the valid bit */
1072 clrrdi r11,r11,28 /* Get the esid part of the ste */
1075 2: std r9,8(r10) /* Store the vsid part of the ste */
1078 mfspr r11,DAR /* Get the new esid */
1079 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1080 ori r11,r11,0x90 /* Turn on valid and kp */
1081 std r11,0(r10) /* Put new entry back into the stab */
1085 /* All done -- return from exception. */
1086 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1087 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1089 andi. r10,r12,MSR_RI
1092 mtcrf 0x80,r9 /* restore CR */
1100 ld r9,PACA_EXSLB+EX_R9(r13)
1101 ld r10,PACA_EXSLB+EX_R10(r13)
1102 ld r11,PACA_EXSLB+EX_R11(r13)
1103 ld r12,PACA_EXSLB+EX_R12(r13)
1104 ld r13,PACA_EXSLB+EX_R13(r13)
1106 b . /* prevent speculative execution */
1109 * r13 points to the PACA, r9 contains the saved CR,
1110 * r11 and r12 contain the saved SRR0 and SRR1.
1111 * r3 has the faulting address
1112 * r9 - r13 are saved in paca->exslb.
1113 * r3 is saved in paca->slb_r3
1114 * We assume we aren't going to take any exceptions during this procedure.
1116 _GLOBAL(do_slb_miss)
1119 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1120 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1122 bl .slb_allocate /* handle it */
1124 /* All done -- return from exception. */
1126 ld r10,PACA_EXSLB+EX_LR(r13)
1127 ld r3,PACA_EXSLB+EX_R3(r13)
1128 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1129 #ifdef CONFIG_PPC_ISERIES
1130 ld r11,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
1131 #endif /* CONFIG_PPC_ISERIES */
1135 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1141 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1144 #ifdef CONFIG_PPC_ISERIES
1147 #endif /* CONFIG_PPC_ISERIES */
1148 ld r9,PACA_EXSLB+EX_R9(r13)
1149 ld r10,PACA_EXSLB+EX_R10(r13)
1150 ld r11,PACA_EXSLB+EX_R11(r13)
1151 ld r12,PACA_EXSLB+EX_R12(r13)
1152 ld r13,PACA_EXSLB+EX_R13(r13)
1154 b . /* prevent speculative execution */
1157 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1160 1: addi r3,r1,STACK_FRAME_OVERHEAD
1161 bl .unrecoverable_exception
1166 * On pSeries, secondary processors spin in the following code.
1167 * At entry, r3 = this processor's number (physical cpu id)
1169 _GLOBAL(pSeries_secondary_smp_init)
1172 /* turn on 64-bit mode */
1176 /* Copy some CPU settings from CPU 0 */
1177 bl .__restore_cpu_setup
1179 /* Set up a paca value for this processor. Since we have the
1180 * physical cpu id in r24, we need to search the pacas to find
1181 * which logical id maps to our physical one.
1183 LOADADDR(r13, paca) /* Get base vaddr of paca array */
1184 li r5,0 /* logical cpu id */
1185 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1186 cmpw r6,r24 /* Compare to our id */
1188 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1193 mr r3,r24 /* not found, copy phys to r3 */
1194 b .kexec_wait /* next kernel might do better */
1196 2: mtspr SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1197 /* From now on, r24 is expected to be logica cpuid */
1200 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1204 /* Create a temp kernel stack for use before relocation is on. */
1205 ld r1,PACAEMERGSP(r13)
1206 subi r1,r1,STACK_FRAME_OVERHEAD
1210 #ifdef SECONDARY_PROCESSORS
1211 bne .__secondary_start
1214 b 3b /* Loop until told to go */
1216 #ifdef CONFIG_PPC_ISERIES
1217 _STATIC(__start_initialization_iSeries)
1218 /* Clear out the BSS */
1219 LOADADDR(r11,__bss_stop)
1220 LOADADDR(r8,__bss_start)
1221 sub r11,r11,r8 /* bss size */
1222 addi r11,r11,7 /* round up to an even double word */
1223 rldicl. r11,r11,61,3 /* shift right by 3 */
1227 mtctr r11 /* zero this many doublewords */
1231 LOADADDR(r1,init_thread_union)
1232 addi r1,r1,THREAD_SIZE
1234 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1236 LOADADDR(r3,cpu_specs)
1237 LOADADDR(r4,cur_cpu_spec)
1241 LOADADDR(r2,__toc_start)
1245 bl .iSeries_early_setup
1247 /* relocation is on at this point */
1249 b .start_here_common
1250 #endif /* CONFIG_PPC_ISERIES */
1252 #ifdef CONFIG_PPC_MULTIPLATFORM
1256 andi. r0,r3,MSR_IR|MSR_DR
1263 b . /* prevent speculative execution */
1267 * Here is our main kernel entry point. We support currently 2 kind of entries
1268 * depending on the value of r5.
1270 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1273 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1274 * DT block, r4 is a physical pointer to the kernel itself
1277 _GLOBAL(__start_initialization_multiplatform)
1279 * Are we booted from a PROM Of-type client-interface ?
1282 bne .__boot_from_prom /* yes -> prom */
1284 /* Save parameters */
1288 /* Make sure we are running in 64 bits mode */
1291 /* Setup some critical 970 SPRs before switching MMU off */
1292 bl .__970_cpu_preinit
1297 /* Switch off MMU if not already */
1298 LOADADDR(r4, .__after_prom_start - KERNELBASE)
1301 b .__after_prom_start
1303 _STATIC(__boot_from_prom)
1304 /* Save parameters */
1311 /* Make sure we are running in 64 bits mode */
1314 /* put a relocation offset into r3 */
1317 LOADADDR(r2,__toc_start)
1321 /* Relocate the TOC from a virt addr to a real addr */
1324 /* Restore parameters */
1331 /* Do all of the interaction with OF client interface */
1333 /* We never return */
1337 * At this point, r3 contains the physical address we are running at,
1338 * returned by prom_init()
1340 _STATIC(__after_prom_start)
1343 * We need to run with __start at physical address 0.
1344 * This will leave some code in the first 256B of
1345 * real memory, which are reserved for software use.
1346 * The remainder of the first page is loaded with the fixed
1347 * interrupt vectors. The next two pages are filled with
1348 * unknown exception placeholders.
1350 * Note: This process overwrites the OF exception vectors.
1351 * r26 == relocation offset
1356 SET_REG_TO_CONST(r27,KERNELBASE)
1358 li r3,0 /* target addr */
1360 // XXX FIXME: Use phys returned by OF (r30)
1361 sub r4,r27,r26 /* source addr */
1362 /* current address of _start */
1363 /* i.e. where we are running */
1364 /* the source addr */
1366 LOADADDR(r5,copy_to_here) /* # bytes of memory to copy */
1369 li r6,0x100 /* Start offset, the first 0x100 */
1370 /* bytes were copied earlier. */
1372 bl .copy_and_flush /* copy the first n bytes */
1373 /* this includes the code being */
1374 /* executed here. */
1376 LOADADDR(r0, 4f) /* Jump to the copy of this code */
1377 mtctr r0 /* that we just made/relocated */
1380 4: LOADADDR(r5,klimit)
1382 ld r5,0(r5) /* get the value of klimit */
1384 bl .copy_and_flush /* copy the rest */
1385 b .start_here_multiplatform
1387 #endif /* CONFIG_PPC_MULTIPLATFORM */
1390 * Copy routine used to copy the kernel to start at physical address 0
1391 * and flush and invalidate the caches as needed.
1392 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1393 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1395 * Note: this routine *only* clobbers r0, r6 and lr
1397 _GLOBAL(copy_and_flush)
1400 4: li r0,16 /* Use the least common */
1401 /* denominator cache line */
1402 /* size. This results in */
1403 /* extra cache line flushes */
1404 /* but operation is correct. */
1405 /* Can't get cache line size */
1406 /* from NACA as it is being */
1409 mtctr r0 /* put # words/line in ctr */
1410 3: addi r6,r6,8 /* copy a cache line */
1414 dcbst r6,r3 /* write it to memory */
1416 icbi r6,r3 /* flush the icache line */
1428 * load_up_fpu(unused, unused, tsk)
1429 * Disable FP for the task which had the FPU previously,
1430 * and save its floating-point registers in its thread_struct.
1431 * Enables the FPU for use in the kernel on return.
1432 * On SMP we know the fpu is free, since we give it up every
1433 * switch (ie, no lazy save of the FP registers).
1434 * On entry: r13 == 'current' && last_task_used_math != 'current'
1436 _STATIC(load_up_fpu)
1437 mfmsr r5 /* grab the current MSR */
1439 mtmsrd r5 /* enable use of fpu now */
1442 * For SMP, we don't do lazy FPU switching because it just gets too
1443 * horrendously complex, especially when a task switches from one CPU
1444 * to another. Instead we call giveup_fpu in switch_to.
1448 ld r3,last_task_used_math@got(r2)
1452 /* Save FP state to last_task_used_math's THREAD struct */
1456 stfd fr0,THREAD_FPSCR(r4)
1457 /* Disable FP for last_task_used_math */
1459 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1460 li r6,MSR_FP|MSR_FE0|MSR_FE1
1462 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1464 #endif /* CONFIG_SMP */
1465 /* enable use of FP after return */
1466 ld r4,PACACURRENT(r13)
1467 addi r5,r4,THREAD /* Get THREAD */
1468 ld r4,THREAD_FPEXC_MODE(r5)
1472 lfd fr0,THREAD_FPSCR(r5)
1476 /* Update last_task_used_math to 'current' */
1477 subi r4,r5,THREAD /* Back to 'current' */
1479 #endif /* CONFIG_SMP */
1480 /* restore registers and return */
1481 b fast_exception_return
1484 * disable_kernel_fp()
1487 _GLOBAL(disable_kernel_fp)
1489 rldicl r0,r3,(63-MSR_FP_LG),1
1490 rldicl r3,r0,(MSR_FP_LG+1),0
1491 mtmsrd r3 /* disable use of fpu now */
1497 * Disable FP for the task given as the argument,
1498 * and save the floating-point registers in its thread_struct.
1499 * Enables the FPU for use in the kernel on return.
1504 mtmsrd r5 /* enable use of fpu now */
1507 beqlr- /* if no previous owner, done */
1508 addi r3,r3,THREAD /* want THREAD of task */
1513 stfd fr0,THREAD_FPSCR(r3)
1515 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1516 li r3,MSR_FP|MSR_FE0|MSR_FE1
1517 andc r4,r4,r3 /* disable FP for previous task */
1518 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1522 ld r4,last_task_used_math@got(r2)
1524 #endif /* CONFIG_SMP */
1528 #ifdef CONFIG_ALTIVEC
1531 * load_up_altivec(unused, unused, tsk)
1532 * Disable VMX for the task which had it previously,
1533 * and save its vector registers in its thread_struct.
1534 * Enables the VMX for use in the kernel on return.
1535 * On SMP we know the VMX is free, since we give it up every
1536 * switch (ie, no lazy save of the vector registers).
1537 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1539 _STATIC(load_up_altivec)
1540 mfmsr r5 /* grab the current MSR */
1541 oris r5,r5,MSR_VEC@h
1542 mtmsrd r5 /* enable use of VMX now */
1546 * For SMP, we don't do lazy VMX switching because it just gets too
1547 * horrendously complex, especially when a task switches from one CPU
1548 * to another. Instead we call giveup_altvec in switch_to.
1549 * VRSAVE isn't dealt with here, that is done in the normal context
1550 * switch code. Note that we could rely on vrsave value to eventually
1551 * avoid saving all of the VREGs here...
1554 ld r3,last_task_used_altivec@got(r2)
1558 /* Save VMX state to last_task_used_altivec's THREAD struct */
1564 /* Disable VMX for last_task_used_altivec */
1566 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1569 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1571 #endif /* CONFIG_SMP */
1572 /* Hack: if we get an altivec unavailable trap with VRSAVE
1573 * set to all zeros, we assume this is a broken application
1574 * that fails to set it properly, and thus we switch it to
1577 mfspr r4,SPRN_VRSAVE
1581 mtspr SPRN_VRSAVE,r4
1583 /* enable use of VMX after return */
1584 ld r4,PACACURRENT(r13)
1585 addi r5,r4,THREAD /* Get THREAD */
1586 oris r12,r12,MSR_VEC@h
1590 stw r4,THREAD_USED_VR(r5)
1595 /* Update last_task_used_math to 'current' */
1596 subi r4,r5,THREAD /* Back to 'current' */
1598 #endif /* CONFIG_SMP */
1599 /* restore registers and return */
1600 b fast_exception_return
1603 * disable_kernel_altivec()
1606 _GLOBAL(disable_kernel_altivec)
1608 rldicl r0,r3,(63-MSR_VEC_LG),1
1609 rldicl r3,r0,(MSR_VEC_LG+1),0
1610 mtmsrd r3 /* disable use of VMX now */
1615 * giveup_altivec(tsk)
1616 * Disable VMX for the task given as the argument,
1617 * and save the vector registers in its thread_struct.
1618 * Enables the VMX for use in the kernel on return.
1620 _GLOBAL(giveup_altivec)
1622 oris r5,r5,MSR_VEC@h
1623 mtmsrd r5 /* enable use of VMX now */
1626 beqlr- /* if no previous owner, done */
1627 addi r3,r3,THREAD /* want THREAD of task */
1635 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1637 andc r4,r4,r3 /* disable FP for previous task */
1638 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1642 ld r4,last_task_used_altivec@got(r2)
1644 #endif /* CONFIG_SMP */
1647 #endif /* CONFIG_ALTIVEC */
1650 #ifdef CONFIG_PPC_PMAC
1652 * On PowerMac, secondary processors starts from the reset vector, which
1653 * is temporarily turned into a call to one of the functions below.
1658 .globl pmac_secondary_start_1
1659 pmac_secondary_start_1:
1661 b .pmac_secondary_start
1663 .globl pmac_secondary_start_2
1664 pmac_secondary_start_2:
1666 b .pmac_secondary_start
1668 .globl pmac_secondary_start_3
1669 pmac_secondary_start_3:
1671 b .pmac_secondary_start
1673 _GLOBAL(pmac_secondary_start)
1674 /* turn on 64-bit mode */
1678 /* Copy some CPU settings from CPU 0 */
1679 bl .__restore_cpu_setup
1681 /* pSeries do that early though I don't think we really need it */
1684 mtmsrd r3 /* RI on */
1686 /* Set up a paca value for this processor. */
1687 LOADADDR(r4, paca) /* Get base vaddr of paca array */
1688 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1689 add r13,r13,r4 /* for this processor. */
1690 mtspr SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1692 /* Create a temp kernel stack for use before relocation is on. */
1693 ld r1,PACAEMERGSP(r13)
1694 subi r1,r1,STACK_FRAME_OVERHEAD
1696 b .__secondary_start
1698 #endif /* CONFIG_PPC_PMAC */
1701 * This function is called after the master CPU has released the
1702 * secondary processors. The execution environment is relocation off.
1703 * The paca for this processor has the following fields initialized at
1705 * 1. Processor number
1706 * 2. Segment table pointer (virtual address)
1707 * On entry the following are set:
1708 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1709 * r24 = cpu# (in Linux terms)
1710 * r13 = paca virtual address
1711 * SPRG3 = paca virtual address
1713 _GLOBAL(__secondary_start)
1715 HMT_MEDIUM /* Set thread priority to MEDIUM */
1719 stb r6,PACAPROCENABLED(r13)
1721 #ifndef CONFIG_PPC_ISERIES
1722 /* Initialize the page table pointer register. */
1724 ld r6,0(r6) /* get the value of _SDR1 */
1725 mtspr SDR1,r6 /* set the htab location */
1727 /* Initialize the first segment table (or SLB) entry */
1728 ld r3,PACASTABVIRT(r13) /* get addr of segment table */
1731 /* Initialize the kernel stack. Just a repeat for iSeries. */
1732 LOADADDR(r3,current_set)
1733 sldi r28,r24,3 /* get current_set[cpu#] */
1735 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1736 std r1,PACAKSAVE(r13)
1738 ld r3,PACASTABREAL(r13) /* get raddr of segment table */
1739 ori r4,r3,1 /* turn on valid bit */
1741 #ifdef CONFIG_PPC_ISERIES
1742 li r0,-1 /* hypervisor call */
1744 sldi r3,r3,63 /* 0x8000000000000000 */
1745 ori r3,r3,4 /* 0x8000000000000004 */
1746 sc /* HvCall_setASR */
1749 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1750 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1751 cmpldi r3,PLATFORM_PSERIES_LPAR
1755 cmpwi r3,0x37 /* SStar */
1757 cmpwi r3,0x36 /* IStar */
1759 cmpwi r3,0x34 /* Pulsar */
1761 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
1762 HVSC /* Invoking hcall */
1764 98: /* !(rpa hypervisor) || !(star) */
1765 mtasr r4 /* set the stab location */
1771 /* enable MMU and jump to start_secondary */
1772 LOADADDR(r3,.start_secondary_prolog)
1773 SET_REG_TO_CONST(r4, MSR_KERNEL)
1774 #ifdef DO_SOFT_DISABLE
1780 b . /* prevent speculative execution */
1783 * Running with relocation on at this point. All we want to do is
1784 * zero the stack back-chain pointer before going into C code.
1786 _GLOBAL(start_secondary_prolog)
1788 std r3,0(r1) /* Zero the stack frame pointer */
1793 * This subroutine clobbers r11 and r12
1795 _GLOBAL(enable_64b_mode)
1796 mfmsr r11 /* grab the current MSR */
1798 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1801 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1807 #ifdef CONFIG_PPC_MULTIPLATFORM
1809 * This is where the main kernel code starts.
1811 _STATIC(start_here_multiplatform)
1812 /* get a new offset, now that the kernel has moved. */
1816 /* Clear out the BSS. It may have been done in prom_init,
1817 * already but that's irrelevant since prom_init will soon
1818 * be detached from the kernel completely. Besides, we need
1819 * to clear it now for kexec-style entry.
1821 LOADADDR(r11,__bss_stop)
1822 LOADADDR(r8,__bss_start)
1823 sub r11,r11,r8 /* bss size */
1824 addi r11,r11,7 /* round up to an even double word */
1825 rldicl. r11,r11,61,3 /* shift right by 3 */
1829 mtctr r11 /* zero this many doublewords */
1836 mtmsrd r6 /* RI on */
1839 /* Start up the second thread on cpu 0 */
1842 cmpwi r3,0x34 /* Pulsar */
1844 cmpwi r3,0x36 /* Icestar */
1846 cmpwi r3,0x37 /* SStar */
1848 b 91f /* HMT not supported */
1850 bl .hmt_start_secondary
1854 /* The following gets the stack and TOC set up with the regs */
1855 /* pointing to the real addr of the kernel stack. This is */
1856 /* all done to support the C function call below which sets */
1857 /* up the htab. This is done because we have relocated the */
1858 /* kernel but are still running in real mode. */
1860 LOADADDR(r3,init_thread_union)
1863 /* set up a stack pointer (physical address) */
1864 addi r1,r3,THREAD_SIZE
1866 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1868 /* set up the TOC (physical address) */
1869 LOADADDR(r2,__toc_start)
1874 LOADADDR(r3,cpu_specs)
1876 LOADADDR(r4,cur_cpu_spec)
1881 /* Save some low level config HIDs of CPU0 to be copied to
1882 * other CPUs later on, or used for suspend/resume
1884 bl .__save_cpu_setup
1887 /* Setup a valid physical PACA pointer in SPRG3 for early_setup
1888 * note that boot_cpuid can always be 0 nowadays since there is
1889 * nowhere it can be initialized differently before we reach this
1892 LOADADDR(r27, boot_cpuid)
1896 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1897 mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
1898 add r13,r13,r24 /* for this processor. */
1899 sub r13,r13,r26 /* convert to physical addr */
1900 mtspr SPRG3,r13 /* PPPBBB: Temp... -Peter */
1902 /* Do very early kernel initializations, including initial hash table,
1903 * stab and slb setup before we turn on relocation. */
1905 /* Restore parameters passed from prom_init/kexec */
1910 ld r3,PACASTABREAL(r13)
1911 ori r4,r3,1 /* turn on valid bit */
1912 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1913 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1914 cmpldi r3,PLATFORM_PSERIES_LPAR
1918 cmpwi r3,0x37 /* SStar */
1920 cmpwi r3,0x36 /* IStar */
1922 cmpwi r3,0x34 /* Pulsar */
1924 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
1925 HVSC /* Invoking hcall */
1927 98: /* !(rpa hypervisor) || !(star) */
1928 mtasr r4 /* set the stab location */
1930 /* Set SDR1 (hash table pointer) */
1931 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1932 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1933 /* Test if bit 0 is set (LPAR bit) */
1936 LOADADDR(r6,_SDR1) /* Only if NOT LPAR */
1938 ld r6,0(r6) /* get the value of _SDR1 */
1939 mtspr SDR1,r6 /* set the htab location */
1941 LOADADDR(r3,.start_here_common)
1942 SET_REG_TO_CONST(r4, MSR_KERNEL)
1946 b . /* prevent speculative execution */
1947 #endif /* CONFIG_PPC_MULTIPLATFORM */
1949 /* This is where all platforms converge execution */
1950 _STATIC(start_here_common)
1951 /* relocation is on at this point */
1953 /* The following code sets up the SP and TOC now that we are */
1954 /* running with translation enabled. */
1956 LOADADDR(r3,init_thread_union)
1958 /* set up the stack */
1959 addi r1,r3,THREAD_SIZE
1961 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1963 /* Apply the CPUs-specific fixups (nop out sections not relevant
1967 bl .do_cpu_ftr_fixups
1969 LOADADDR(r26, boot_cpuid)
1972 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1973 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1974 add r13,r13,r24 /* for this processor. */
1977 /* ptr to current */
1978 LOADADDR(r4,init_task)
1979 std r4,PACACURRENT(r13)
1983 std r1,PACAKSAVE(r13)
1987 /* Load up the kernel context */
1989 #ifdef DO_SOFT_DISABLE
1991 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1993 ori r5,r5,MSR_EE /* Hard Enabled */
1999 _GLOBAL(__setup_cpu_power3)
2004 LOADADDR(r5, hmt_thread_data)
2007 cmpwi r7,0x34 /* Pulsar */
2009 cmpwi r7,0x36 /* Icestar */
2011 cmpwi r7,0x37 /* SStar */
2021 bl .hmt_start_secondary
2024 __hmt_secondary_hold:
2025 LOADADDR(r5, hmt_thread_data)
2035 93: andi. r6,r6,0x3f
2049 b .pSeries_secondary_smp_init
2052 _GLOBAL(hmt_start_secondary)
2053 LOADADDR(r4,__hmt_secondary_hold)
2068 mfspr r4, SPRN_CTRLF
2070 mtspr SPRN_CTRLT, r4
2074 #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES)
2075 _GLOBAL(smp_release_cpus)
2076 /* All secondary cpus are spinning on a common
2077 * spinloop, release them all now so they can start
2078 * to spin on their individual paca spinloops.
2079 * For non SMP kernels, the secondary cpus never
2080 * get out of the common spinloop.
2083 LOADADDR(r5,__secondary_hold_spinloop)
2087 #endif /* CONFIG_SMP && !CONFIG_PPC_ISERIES */
2091 * We put a few things here that have to be page-aligned.
2092 * This stuff goes at the beginning of the data segment,
2093 * which is page-aligned.
2099 .globl empty_zero_page
2103 .globl swapper_pg_dir
2108 * This space gets a copy of optional info passed to us by the bootstrap
2109 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2113 .space COMMAND_LINE_SIZE