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>
37 #ifdef CONFIG_PPC_ISERIES
38 #define DO_SOFT_DISABLE
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
76 #ifdef CONFIG_PPC_MULTIPLATFORM
78 /* NOP this out unconditionally */
80 b .__start_initialization_multiplatform
82 #endif /* CONFIG_PPC_MULTIPLATFORM */
84 /* Catch branch to 0 in real mode */
87 /* Secondary processors spin on this value until it goes to 1. */
88 .globl __secondary_hold_spinloop
89 __secondary_hold_spinloop:
92 /* Secondary processors write this value with their cpu # */
93 /* after they enter the spin loop immediately below. */
94 .globl __secondary_hold_acknowledge
95 __secondary_hold_acknowledge:
98 #ifdef CONFIG_PPC_ISERIES
100 * At offset 0x20, there is a pointer to iSeries LPAR data.
101 * This is required by the hypervisor
104 .llong hvReleaseData-KERNELBASE
105 #endif /* CONFIG_PPC_ISERIES */
109 * The following code is used on pSeries to hold secondary processors
110 * in a spin loop after they have been freed from OpenFirmware, but
111 * before the bulk of the kernel has been relocated. This code
112 * is relocated to physical address 0x60 before prom_init is run.
113 * All of it must fit below the first exception vector at 0x100.
115 _GLOBAL(__secondary_hold)
118 mtmsrd r24 /* RI on */
120 /* Grab our physical cpu number */
123 /* Tell the master cpu we're here */
124 /* Relocation is off & we are located at an address less */
125 /* than 0x100, so only need to grab low order offset. */
126 std r24,__secondary_hold_acknowledge@l(0)
129 /* All secondary cpus wait here until told to start. */
130 100: ld r4,__secondary_hold_spinloop@l(0)
134 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
135 LOAD_REG_IMMEDIATE(r4, .pSeries_secondary_smp_init)
143 /* This value is used to mark exception frames on the stack. */
146 .tc ID_72656773_68657265[TC],0x7265677368657265
150 * The following macros define the code that appears as
151 * the prologue to each of the exception handlers. They
152 * are split into two parts to allow a single kernel binary
153 * to be used for pSeries and iSeries.
154 * LOL. One day... - paulus
158 * We make as much of the exception code common between native
159 * exception handlers (including pSeries LPAR) and iSeries LPAR
160 * implementations as possible.
164 * This is the start of the interrupt handlers for pSeries
165 * This code runs with relocation off.
180 * We're short on space and time in the exception prolog, so we can't
181 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
182 * low halfword of the address, but for Kdump we need the whole low
185 #ifdef CONFIG_CRASH_DUMP
186 #define LOAD_HANDLER(reg, label) \
187 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
188 ori reg,reg,(label)@l; /* .. and the rest */
190 #define LOAD_HANDLER(reg, label) \
191 ori reg,reg,(label)@l; /* virt addr of handler ... */
194 #define EXCEPTION_PROLOG_PSERIES(area, label) \
195 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
196 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
197 std r10,area+EX_R10(r13); \
198 std r11,area+EX_R11(r13); \
199 std r12,area+EX_R12(r13); \
200 mfspr r9,SPRN_SPRG1; \
201 std r9,area+EX_R13(r13); \
203 clrrdi r12,r13,32; /* get high part of &label */ \
205 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
206 LOAD_HANDLER(r12,label) \
207 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
208 mtspr SPRN_SRR0,r12; \
209 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
210 mtspr SPRN_SRR1,r10; \
212 b . /* prevent speculative execution */
215 * This is the start of the interrupt handlers for iSeries
216 * This code runs with relocation on.
218 #define EXCEPTION_PROLOG_ISERIES_1(area) \
219 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
220 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
221 std r10,area+EX_R10(r13); \
222 std r11,area+EX_R11(r13); \
223 std r12,area+EX_R12(r13); \
224 mfspr r9,SPRN_SPRG1; \
225 std r9,area+EX_R13(r13); \
228 #define EXCEPTION_PROLOG_ISERIES_2 \
230 ld r12,PACALPPACAPTR(r13); \
231 ld r11,LPPACASRR0(r12); \
232 ld r12,LPPACASRR1(r12); \
233 ori r10,r10,MSR_RI; \
237 * The common exception prolog is used for all except a few exceptions
238 * such as a segment miss on a kernel address. We have to be prepared
239 * to take another exception from the point where we first touch the
240 * kernel stack onwards.
242 * On entry r13 points to the paca, r9-r13 are saved in the paca,
243 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
244 * SRR1, and relocation is on.
246 #define EXCEPTION_PROLOG_COMMON(n, area) \
247 andi. r10,r12,MSR_PR; /* See if coming from user */ \
248 mr r10,r1; /* Save r1 */ \
249 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
251 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
252 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
253 bge- cr1,bad_stack; /* abort if it is */ \
254 std r9,_CCR(r1); /* save CR in stackframe */ \
255 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
256 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
257 std r10,0(r1); /* make stack chain pointer */ \
258 std r0,GPR0(r1); /* save r0 in stackframe */ \
259 std r10,GPR1(r1); /* save r1 in stackframe */ \
260 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
261 std r2,GPR2(r1); /* save r2 in stackframe */ \
262 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
263 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
264 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
265 ld r10,area+EX_R10(r13); \
268 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
269 ld r10,area+EX_R12(r13); \
270 ld r11,area+EX_R13(r13); \
274 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
275 mflr r9; /* save LR in stackframe */ \
277 mfctr r10; /* save CTR in stackframe */ \
279 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
282 std r9,_TRAP(r1); /* set trap number */ \
284 ld r11,exception_marker@toc(r2); \
285 std r10,RESULT(r1); /* clear regs->result */ \
286 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
291 #define STD_EXCEPTION_PSERIES(n, label) \
293 .globl label##_pSeries; \
296 mtspr SPRN_SPRG1,r13; /* save r13 */ \
297 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
299 #define HSTD_EXCEPTION_PSERIES(n, label) \
301 .globl label##_pSeries; \
304 mtspr SPRN_SPRG1,r20; /* save r20 */ \
305 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
306 mtspr SPRN_SRR0,r20; \
307 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
308 mtspr SPRN_SRR1,r20; \
309 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
310 mtspr SPRN_SPRG1,r13; /* save r13 */ \
311 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
314 #define STD_EXCEPTION_ISERIES(n, label, area) \
315 .globl label##_iSeries; \
318 mtspr SPRN_SPRG1,r13; /* save r13 */ \
319 EXCEPTION_PROLOG_ISERIES_1(area); \
320 EXCEPTION_PROLOG_ISERIES_2; \
323 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
324 .globl label##_iSeries; \
327 mtspr SPRN_SPRG1,r13; /* save r13 */ \
328 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
329 lbz r10,PACAPROCENABLED(r13); \
331 beq- label##_iSeries_masked; \
332 EXCEPTION_PROLOG_ISERIES_2; \
335 #ifdef DO_SOFT_DISABLE
336 #define DISABLE_INTS \
337 lbz r10,PACAPROCENABLED(r13); \
341 stb r11,PACAPROCENABLED(r13); \
342 ori r10,r10,MSR_EE; \
345 #define ENABLE_INTS \
346 lbz r10,PACAPROCENABLED(r13); \
349 ori r11,r11,MSR_EE; \
352 #else /* hard enable/disable interrupts */
355 #define ENABLE_INTS \
358 rlwimi r11,r12,0,MSR_EE; \
363 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
365 .globl label##_common; \
367 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
370 addi r3,r1,STACK_FRAME_OVERHEAD; \
375 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
376 * in the idle task and therefore need the special idle handling.
378 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
380 .globl label##_common; \
382 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
386 addi r3,r1,STACK_FRAME_OVERHEAD; \
390 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
392 .globl label##_common; \
394 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
397 bl .ppc64_runlatch_on; \
398 addi r3,r1,STACK_FRAME_OVERHEAD; \
400 b .ret_from_except_lite
403 * When the idle code in power4_idle puts the CPU into NAP mode,
404 * it has to do so in a loop, and relies on the external interrupt
405 * and decrementer interrupt entry code to get it out of the loop.
406 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
407 * to signal that it is in the loop and needs help to get out.
409 #ifdef CONFIG_PPC_970_NAP
412 clrrdi r11,r1,THREAD_SHIFT; \
413 ld r9,TI_LOCAL_FLAGS(r11); \
414 andi. r10,r9,_TLF_NAPPING; \
415 bnel power4_fixup_nap; \
416 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
422 * Start of pSeries system interrupt routines
425 .globl __start_interrupts
428 STD_EXCEPTION_PSERIES(0x100, system_reset)
431 _machine_check_pSeries:
433 mtspr SPRN_SPRG1,r13 /* save r13 */
434 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
437 .globl data_access_pSeries
446 rlwimi r13,r12,16,0x20
449 beq .do_stab_bolted_pSeries
452 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
453 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
456 .globl data_access_slb_pSeries
457 data_access_slb_pSeries:
460 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
461 std r3,PACA_EXSLB+EX_R3(r13)
463 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
466 /* Keep that around for when we re-implement dynamic VSIDs */
468 bge slb_miss_user_pseries
469 #endif /* __DISABLED__ */
470 std r10,PACA_EXSLB+EX_R10(r13)
471 std r11,PACA_EXSLB+EX_R11(r13)
472 std r12,PACA_EXSLB+EX_R12(r13)
474 std r10,PACA_EXSLB+EX_R13(r13)
475 mfspr r12,SPRN_SRR1 /* and SRR1 */
476 b .slb_miss_realmode /* Rel. branch works in real mode */
478 STD_EXCEPTION_PSERIES(0x400, instruction_access)
481 .globl instruction_access_slb_pSeries
482 instruction_access_slb_pSeries:
485 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
486 std r3,PACA_EXSLB+EX_R3(r13)
487 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
488 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
491 /* Keep that around for when we re-implement dynamic VSIDs */
493 bge slb_miss_user_pseries
494 #endif /* __DISABLED__ */
495 std r10,PACA_EXSLB+EX_R10(r13)
496 std r11,PACA_EXSLB+EX_R11(r13)
497 std r12,PACA_EXSLB+EX_R12(r13)
499 std r10,PACA_EXSLB+EX_R13(r13)
500 mfspr r12,SPRN_SRR1 /* and SRR1 */
501 b .slb_miss_realmode /* Rel. branch works in real mode */
503 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
504 STD_EXCEPTION_PSERIES(0x600, alignment)
505 STD_EXCEPTION_PSERIES(0x700, program_check)
506 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
507 STD_EXCEPTION_PSERIES(0x900, decrementer)
508 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
509 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
512 .globl system_call_pSeries
520 oris r12,r12,system_call_common@h
521 ori r12,r12,system_call_common@l
523 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
527 b . /* prevent speculative execution */
529 STD_EXCEPTION_PSERIES(0xd00, single_step)
530 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
532 /* We need to deal with the Altivec unavailable exception
533 * here which is at 0xf20, thus in the middle of the
534 * prolog code of the PerformanceMonitor one. A little
535 * trickery is thus necessary
538 b performance_monitor_pSeries
540 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
542 #ifdef CONFIG_CBE_RAS
543 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
544 #endif /* CONFIG_CBE_RAS */
545 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
546 #ifdef CONFIG_CBE_RAS
547 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
548 #endif /* CONFIG_CBE_RAS */
549 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
550 #ifdef CONFIG_CBE_RAS
551 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
552 #endif /* CONFIG_CBE_RAS */
556 /*** pSeries interrupt support ***/
558 /* moved from 0xf00 */
559 STD_EXCEPTION_PSERIES(., performance_monitor)
562 _GLOBAL(do_stab_bolted_pSeries)
565 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
568 * We have some room here we use that to put
569 * the peries slb miss user trampoline code so it's reasonably
570 * away from slb_miss_user_common to avoid problems with rfid
572 * This is used for when the SLB miss handler has to go virtual,
573 * which doesn't happen for now anymore but will once we re-implement
574 * dynamic VSIDs for shared page tables
577 slb_miss_user_pseries:
578 std r10,PACA_EXGEN+EX_R10(r13)
579 std r11,PACA_EXGEN+EX_R11(r13)
580 std r12,PACA_EXGEN+EX_R12(r13)
582 ld r11,PACA_EXSLB+EX_R9(r13)
583 ld r12,PACA_EXSLB+EX_R3(r13)
584 std r10,PACA_EXGEN+EX_R13(r13)
585 std r11,PACA_EXGEN+EX_R9(r13)
586 std r12,PACA_EXGEN+EX_R3(r13)
589 mfspr r11,SRR0 /* save SRR0 */
590 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
591 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
593 mfspr r12,SRR1 /* and SRR1 */
596 b . /* prevent spec. execution */
597 #endif /* __DISABLED__ */
600 * Vectors for the FWNMI option. Share common code.
602 .globl system_reset_fwnmi
606 mtspr SPRN_SPRG1,r13 /* save r13 */
607 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
609 .globl machine_check_fwnmi
613 mtspr SPRN_SPRG1,r13 /* save r13 */
614 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
616 #ifdef CONFIG_PPC_ISERIES
617 /*** ISeries-LPAR interrupt handlers ***/
619 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
621 .globl data_access_iSeries
629 rlwimi r13,r12,16,0x20
632 beq .do_stab_bolted_iSeries
635 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
636 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
637 EXCEPTION_PROLOG_ISERIES_2
640 .do_stab_bolted_iSeries:
643 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
644 EXCEPTION_PROLOG_ISERIES_2
647 .globl data_access_slb_iSeries
648 data_access_slb_iSeries:
649 mtspr SPRN_SPRG1,r13 /* save r13 */
650 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
651 std r3,PACA_EXSLB+EX_R3(r13)
653 std r9,PACA_EXSLB+EX_R9(r13)
657 bge slb_miss_user_iseries
659 std r10,PACA_EXSLB+EX_R10(r13)
660 std r11,PACA_EXSLB+EX_R11(r13)
661 std r12,PACA_EXSLB+EX_R12(r13)
663 std r10,PACA_EXSLB+EX_R13(r13)
664 ld r12,PACALPPACAPTR(r13)
665 ld r12,LPPACASRR1(r12)
668 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
670 .globl instruction_access_slb_iSeries
671 instruction_access_slb_iSeries:
672 mtspr SPRN_SPRG1,r13 /* save r13 */
673 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
674 std r3,PACA_EXSLB+EX_R3(r13)
675 ld r3,PACALPPACAPTR(r13)
676 ld r3,LPPACASRR0(r3) /* get SRR0 value */
677 std r9,PACA_EXSLB+EX_R9(r13)
681 bge .slb_miss_user_iseries
683 std r10,PACA_EXSLB+EX_R10(r13)
684 std r11,PACA_EXSLB+EX_R11(r13)
685 std r12,PACA_EXSLB+EX_R12(r13)
687 std r10,PACA_EXSLB+EX_R13(r13)
688 ld r12,PACALPPACAPTR(r13)
689 ld r12,LPPACASRR1(r12)
693 slb_miss_user_iseries:
694 std r10,PACA_EXGEN+EX_R10(r13)
695 std r11,PACA_EXGEN+EX_R11(r13)
696 std r12,PACA_EXGEN+EX_R12(r13)
698 ld r11,PACA_EXSLB+EX_R9(r13)
699 ld r12,PACA_EXSLB+EX_R3(r13)
700 std r10,PACA_EXGEN+EX_R13(r13)
701 std r11,PACA_EXGEN+EX_R9(r13)
702 std r12,PACA_EXGEN+EX_R3(r13)
703 EXCEPTION_PROLOG_ISERIES_2
704 b slb_miss_user_common
707 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
708 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
709 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
710 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
711 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
712 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
713 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
715 .globl system_call_iSeries
719 EXCEPTION_PROLOG_ISERIES_2
722 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
723 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
724 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
726 .globl system_reset_iSeries
727 system_reset_iSeries:
728 mfspr r13,SPRN_SPRG3 /* Get paca address */
731 mtmsrd r24 /* RI on */
732 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
733 cmpwi 0,r24,0 /* Are we processor 0? */
734 beq .__start_initialization_iSeries /* Start up the first processor */
736 li r5,CTRL_RUNLATCH /* Turn off the run light */
743 lbz r23,PACAPROCSTART(r13) /* Test if this processor
746 LOAD_REG_IMMEDIATE(r3,current_set)
747 sldi r28,r24,3 /* get current_set[cpu#] */
749 addi r1,r3,THREAD_SIZE
750 subi r1,r1,STACK_FRAME_OVERHEAD
753 beq iSeries_secondary_smp_loop /* Loop until told to go */
754 bne .__secondary_start /* Loop until told to go */
755 iSeries_secondary_smp_loop:
756 /* Let the Hypervisor know we are alive */
757 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
759 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
760 #else /* CONFIG_SMP */
761 /* Yield the processor. This is required for non-SMP kernels
762 which are running on multi-threaded machines. */
764 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
765 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
766 li r4,0 /* "yield timed" */
767 li r5,-1 /* "yield forever" */
768 #endif /* CONFIG_SMP */
769 li r0,-1 /* r0=-1 indicates a Hypervisor call */
770 sc /* Invoke the hypervisor via a system call */
771 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
772 b 1b /* If SMP not configured, secondaries
775 .globl decrementer_iSeries_masked
776 decrementer_iSeries_masked:
777 /* We may not have a valid TOC pointer in here. */
779 ld r12,PACALPPACAPTR(r13)
780 stb r11,LPPACADECRINT(r12)
781 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
786 .globl hardware_interrupt_iSeries_masked
787 hardware_interrupt_iSeries_masked:
788 mtcrf 0x80,r9 /* Restore regs */
789 ld r12,PACALPPACAPTR(r13)
790 ld r11,LPPACASRR0(r12)
791 ld r12,LPPACASRR1(r12)
794 ld r9,PACA_EXGEN+EX_R9(r13)
795 ld r10,PACA_EXGEN+EX_R10(r13)
796 ld r11,PACA_EXGEN+EX_R11(r13)
797 ld r12,PACA_EXGEN+EX_R12(r13)
798 ld r13,PACA_EXGEN+EX_R13(r13)
800 b . /* prevent speculative execution */
801 #endif /* CONFIG_PPC_ISERIES */
803 /*** Common interrupt handlers ***/
805 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
808 * Machine check is different because we use a different
809 * save area: PACA_EXMC instead of PACA_EXGEN.
812 .globl machine_check_common
813 machine_check_common:
814 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
818 addi r3,r1,STACK_FRAME_OVERHEAD
819 bl .machine_check_exception
822 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
823 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
824 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
825 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
826 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
827 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
828 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
829 #ifdef CONFIG_ALTIVEC
830 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
832 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
834 #ifdef CONFIG_CBE_RAS
835 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
836 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
837 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
838 #endif /* CONFIG_CBE_RAS */
841 * Here we have detected that the kernel stack pointer is bad.
842 * R9 contains the saved CR, r13 points to the paca,
843 * r10 contains the (bad) kernel stack pointer,
844 * r11 and r12 contain the saved SRR0 and SRR1.
845 * We switch to using an emergency stack, save the registers there,
846 * and call kernel_bad_stack(), which panics.
849 ld r1,PACAEMERGSP(r13)
850 subi r1,r1,64+INT_FRAME_SIZE
871 addi r11,r1,INT_FRAME_SIZE
876 1: addi r3,r1,STACK_FRAME_OVERHEAD
881 * Return from an exception with minimal checks.
882 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
883 * If interrupts have been enabled, or anything has been
884 * done that might have changed the scheduling status of
885 * any task or sent any task a signal, you should use
886 * ret_from_except or ret_from_except_lite instead of this.
888 .globl fast_exception_return
889 fast_exception_return:
892 andi. r3,r12,MSR_RI /* check if RI is set */
895 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
898 ACCOUNT_CPU_USER_EXIT(r3, r4)
914 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
922 b . /* prevent speculative execution */
926 1: addi r3,r1,STACK_FRAME_OVERHEAD
927 bl .unrecoverable_exception
931 * Here r13 points to the paca, r9 contains the saved CR,
932 * SRR0 and SRR1 are saved in r11 and r12,
933 * r9 - r13 are saved in paca->exgen.
936 .globl data_access_common
939 std r10,PACA_EXGEN+EX_DAR(r13)
941 stw r10,PACA_EXGEN+EX_DSISR(r13)
942 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
943 ld r3,PACA_EXGEN+EX_DAR(r13)
944 lwz r4,PACA_EXGEN+EX_DSISR(r13)
946 b .do_hash_page /* Try to handle as hpte fault */
949 .globl instruction_access_common
950 instruction_access_common:
951 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
955 b .do_hash_page /* Try to handle as hpte fault */
958 * Here is the common SLB miss user that is used when going to virtual
959 * mode for SLB misses, that is currently not used
963 .globl slb_miss_user_common
964 slb_miss_user_common:
966 std r3,PACA_EXGEN+EX_DAR(r13)
967 stw r9,PACA_EXGEN+EX_CCR(r13)
968 std r10,PACA_EXGEN+EX_LR(r13)
969 std r11,PACA_EXGEN+EX_SRR0(r13)
970 bl .slb_allocate_user
972 ld r10,PACA_EXGEN+EX_LR(r13)
973 ld r3,PACA_EXGEN+EX_R3(r13)
974 lwz r9,PACA_EXGEN+EX_CCR(r13)
975 ld r11,PACA_EXGEN+EX_SRR0(r13)
979 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
980 beq- unrecov_user_slb
988 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
994 ld r9,PACA_EXGEN+EX_R9(r13)
995 ld r10,PACA_EXGEN+EX_R10(r13)
996 ld r11,PACA_EXGEN+EX_R11(r13)
997 ld r12,PACA_EXGEN+EX_R12(r13)
998 ld r13,PACA_EXGEN+EX_R13(r13)
1003 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1004 ld r4,PACA_EXGEN+EX_DAR(r13)
1008 b .handle_page_fault
1011 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1014 1: addi r3,r1,STACK_FRAME_OVERHEAD
1015 bl .unrecoverable_exception
1018 #endif /* __DISABLED__ */
1022 * r13 points to the PACA, r9 contains the saved CR,
1023 * r12 contain the saved SRR1, SRR0 is still ready for return
1024 * r3 has the faulting address
1025 * r9 - r13 are saved in paca->exslb.
1026 * r3 is saved in paca->slb_r3
1027 * We assume we aren't going to take any exceptions during this procedure.
1029 _GLOBAL(slb_miss_realmode)
1032 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1033 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1035 bl .slb_allocate_realmode
1037 /* All done -- return from exception. */
1039 ld r10,PACA_EXSLB+EX_LR(r13)
1040 ld r3,PACA_EXSLB+EX_R3(r13)
1041 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1042 #ifdef CONFIG_PPC_ISERIES
1043 ld r11,PACALPPACAPTR(r13)
1044 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1045 #endif /* CONFIG_PPC_ISERIES */
1049 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1055 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1058 #ifdef CONFIG_PPC_ISERIES
1061 #endif /* CONFIG_PPC_ISERIES */
1062 ld r9,PACA_EXSLB+EX_R9(r13)
1063 ld r10,PACA_EXSLB+EX_R10(r13)
1064 ld r11,PACA_EXSLB+EX_R11(r13)
1065 ld r12,PACA_EXSLB+EX_R12(r13)
1066 ld r13,PACA_EXSLB+EX_R13(r13)
1068 b . /* prevent speculative execution */
1071 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1074 1: addi r3,r1,STACK_FRAME_OVERHEAD
1075 bl .unrecoverable_exception
1079 .globl hardware_interrupt_common
1080 .globl hardware_interrupt_entry
1081 hardware_interrupt_common:
1082 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1084 hardware_interrupt_entry:
1086 bl .ppc64_runlatch_on
1087 addi r3,r1,STACK_FRAME_OVERHEAD
1089 b .ret_from_except_lite
1091 #ifdef CONFIG_PPC_970_NAP
1094 std r9,TI_LOCAL_FLAGS(r11)
1095 ld r10,_LINK(r1) /* make idle task do the */
1096 std r10,_NIP(r1) /* equivalent of a blr */
1101 .globl alignment_common
1104 std r10,PACA_EXGEN+EX_DAR(r13)
1105 mfspr r10,SPRN_DSISR
1106 stw r10,PACA_EXGEN+EX_DSISR(r13)
1107 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1108 ld r3,PACA_EXGEN+EX_DAR(r13)
1109 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1113 addi r3,r1,STACK_FRAME_OVERHEAD
1115 bl .alignment_exception
1119 .globl program_check_common
1120 program_check_common:
1121 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1123 addi r3,r1,STACK_FRAME_OVERHEAD
1125 bl .program_check_exception
1129 .globl fp_unavailable_common
1130 fp_unavailable_common:
1131 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1132 bne .load_up_fpu /* if from user, just load it up */
1134 addi r3,r1,STACK_FRAME_OVERHEAD
1136 bl .kernel_fp_unavailable_exception
1140 .globl altivec_unavailable_common
1141 altivec_unavailable_common:
1142 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1143 #ifdef CONFIG_ALTIVEC
1145 bne .load_up_altivec /* if from user, just load it up */
1146 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1149 addi r3,r1,STACK_FRAME_OVERHEAD
1151 bl .altivec_unavailable_exception
1154 #ifdef CONFIG_ALTIVEC
1156 * load_up_altivec(unused, unused, tsk)
1157 * Disable VMX for the task which had it previously,
1158 * and save its vector registers in its thread_struct.
1159 * Enables the VMX for use in the kernel on return.
1160 * On SMP we know the VMX is free, since we give it up every
1161 * switch (ie, no lazy save of the vector registers).
1162 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1164 _STATIC(load_up_altivec)
1165 mfmsr r5 /* grab the current MSR */
1166 oris r5,r5,MSR_VEC@h
1167 mtmsrd r5 /* enable use of VMX now */
1171 * For SMP, we don't do lazy VMX switching because it just gets too
1172 * horrendously complex, especially when a task switches from one CPU
1173 * to another. Instead we call giveup_altvec in switch_to.
1174 * VRSAVE isn't dealt with here, that is done in the normal context
1175 * switch code. Note that we could rely on vrsave value to eventually
1176 * avoid saving all of the VREGs here...
1179 ld r3,last_task_used_altivec@got(r2)
1183 /* Save VMX state to last_task_used_altivec's THREAD struct */
1189 /* Disable VMX for last_task_used_altivec */
1191 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1194 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1196 #endif /* CONFIG_SMP */
1197 /* Hack: if we get an altivec unavailable trap with VRSAVE
1198 * set to all zeros, we assume this is a broken application
1199 * that fails to set it properly, and thus we switch it to
1202 mfspr r4,SPRN_VRSAVE
1206 mtspr SPRN_VRSAVE,r4
1208 /* enable use of VMX after return */
1209 ld r4,PACACURRENT(r13)
1210 addi r5,r4,THREAD /* Get THREAD */
1211 oris r12,r12,MSR_VEC@h
1215 stw r4,THREAD_USED_VR(r5)
1220 /* Update last_task_used_math to 'current' */
1221 subi r4,r5,THREAD /* Back to 'current' */
1223 #endif /* CONFIG_SMP */
1224 /* restore registers and return */
1225 b fast_exception_return
1226 #endif /* CONFIG_ALTIVEC */
1232 _GLOBAL(do_hash_page)
1236 andis. r0,r4,0xa450 /* weird error? */
1237 bne- .handle_page_fault /* if not, try to insert a HPTE */
1239 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1240 bne- .do_ste_alloc /* If so handle it */
1241 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1244 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1245 * accessing a userspace segment (even from the kernel). We assume
1246 * kernel addresses always have the high bit set.
1248 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1249 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1250 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1251 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1252 ori r4,r4,1 /* add _PAGE_PRESENT */
1253 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1256 * On iSeries, we soft-disable interrupts here, then
1257 * hard-enable interrupts so that the hash_page code can spin on
1258 * the hash_table_lock without problems on a shared processor.
1263 * r3 contains the faulting address
1264 * r4 contains the required access permissions
1265 * r5 contains the trap number
1267 * at return r3 = 0 for success
1269 bl .hash_page /* build HPTE if possible */
1270 cmpdi r3,0 /* see if hash_page succeeded */
1272 #ifdef DO_SOFT_DISABLE
1274 * If we had interrupts soft-enabled at the point where the
1275 * DSI/ISI occurred, and an interrupt came in during hash_page,
1277 * We jump to ret_from_except_lite rather than fast_exception_return
1278 * because ret_from_except_lite will check for and handle pending
1279 * interrupts if necessary.
1281 beq .ret_from_except_lite
1282 /* For a hash failure, we don't bother re-enabling interrupts */
1286 * hash_page couldn't handle it, set soft interrupt enable back
1287 * to what it was before the trap. Note that .local_irq_restore
1288 * handles any interrupts pending at this point.
1291 bl .local_irq_restore
1294 beq fast_exception_return /* Return from exception on success */
1295 ble- 12f /* Failure return from hash_page */
1300 /* Here we have a page fault that hash_page can't handle. */
1301 _GLOBAL(handle_page_fault)
1305 addi r3,r1,STACK_FRAME_OVERHEAD
1308 beq+ .ret_from_except_lite
1311 addi r3,r1,STACK_FRAME_OVERHEAD
1316 /* We have a page fault that hash_page could handle but HV refused
1320 addi r3,r1,STACK_FRAME_OVERHEAD
1325 /* here we have a segment miss */
1326 _GLOBAL(do_ste_alloc)
1327 bl .ste_allocate /* try to insert stab entry */
1329 beq+ fast_exception_return
1330 b .handle_page_fault
1333 * r13 points to the PACA, r9 contains the saved CR,
1334 * r11 and r12 contain the saved SRR0 and SRR1.
1335 * r9 - r13 are saved in paca->exslb.
1336 * We assume we aren't going to take any exceptions during this procedure.
1337 * We assume (DAR >> 60) == 0xc.
1340 _GLOBAL(do_stab_bolted)
1341 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1342 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1344 /* Hash to the primary group */
1345 ld r10,PACASTABVIRT(r13)
1348 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1350 /* Calculate VSID */
1351 /* This is a kernel address, so protovsid = ESID */
1352 ASM_VSID_SCRAMBLE(r11, r9)
1353 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1355 /* Search the primary group for a free entry */
1356 1: ld r11,0(r10) /* Test valid bit of the current ste */
1363 /* Stick for only searching the primary group for now. */
1364 /* At least for now, we use a very simple random castout scheme */
1365 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1367 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1370 /* r10 currently points to an ste one past the group of interest */
1371 /* make it point to the randomly selected entry */
1373 or r10,r10,r11 /* r10 is the entry to invalidate */
1375 isync /* mark the entry invalid */
1377 rldicl r11,r11,56,1 /* clear the valid bit */
1382 clrrdi r11,r11,28 /* Get the esid part of the ste */
1385 2: std r9,8(r10) /* Store the vsid part of the ste */
1388 mfspr r11,SPRN_DAR /* Get the new esid */
1389 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1390 ori r11,r11,0x90 /* Turn on valid and kp */
1391 std r11,0(r10) /* Put new entry back into the stab */
1395 /* All done -- return from exception. */
1396 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1397 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1399 andi. r10,r12,MSR_RI
1402 mtcrf 0x80,r9 /* restore CR */
1410 ld r9,PACA_EXSLB+EX_R9(r13)
1411 ld r10,PACA_EXSLB+EX_R10(r13)
1412 ld r11,PACA_EXSLB+EX_R11(r13)
1413 ld r12,PACA_EXSLB+EX_R12(r13)
1414 ld r13,PACA_EXSLB+EX_R13(r13)
1416 b . /* prevent speculative execution */
1419 * Space for CPU0's segment table.
1421 * On iSeries, the hypervisor must fill in at least one entry before
1422 * we get control (with relocate on). The address is give to the hv
1423 * as a page number (see xLparMap in lpardata.c), so this must be at a
1424 * fixed address (the linker can't compute (u64)&initial_stab >>
1427 . = STAB0_OFFSET /* 0x6000 */
1433 * Data area reserved for FWNMI option.
1434 * This address (0x7000) is fixed by the RPA.
1437 .globl fwnmi_data_area
1440 /* iSeries does not use the FWNMI stuff, so it is safe to put
1441 * this here, even if we later allow kernels that will boot on
1442 * both pSeries and iSeries */
1443 #ifdef CONFIG_PPC_ISERIES
1445 #include "lparmap.s"
1447 * This ".text" is here for old compilers that generate a trailing
1448 * .note section when compiling .c files to .s
1451 #endif /* CONFIG_PPC_ISERIES */
1456 * On pSeries, secondary processors spin in the following code.
1457 * At entry, r3 = this processor's number (physical cpu id)
1459 _GLOBAL(pSeries_secondary_smp_init)
1462 /* turn on 64-bit mode */
1466 /* Copy some CPU settings from CPU 0 */
1467 bl .__restore_cpu_setup
1469 /* Set up a paca value for this processor. Since we have the
1470 * physical cpu id in r24, we need to search the pacas to find
1471 * which logical id maps to our physical one.
1473 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1474 li r5,0 /* logical cpu id */
1475 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1476 cmpw r6,r24 /* Compare to our id */
1478 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1483 mr r3,r24 /* not found, copy phys to r3 */
1484 b .kexec_wait /* next kernel might do better */
1486 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1487 /* From now on, r24 is expected to be logical cpuid */
1490 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1494 /* Create a temp kernel stack for use before relocation is on. */
1495 ld r1,PACAEMERGSP(r13)
1496 subi r1,r1,STACK_FRAME_OVERHEAD
1500 bne .__secondary_start
1502 b 3b /* Loop until told to go */
1504 #ifdef CONFIG_PPC_ISERIES
1505 _STATIC(__start_initialization_iSeries)
1506 /* Clear out the BSS */
1507 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1508 LOAD_REG_IMMEDIATE(r8,__bss_start)
1509 sub r11,r11,r8 /* bss size */
1510 addi r11,r11,7 /* round up to an even double word */
1511 rldicl. r11,r11,61,3 /* shift right by 3 */
1515 mtctr r11 /* zero this many doublewords */
1519 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1520 addi r1,r1,THREAD_SIZE
1522 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1524 LOAD_REG_IMMEDIATE(r3,cpu_specs)
1525 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1529 LOAD_REG_IMMEDIATE(r2,__toc_start)
1533 bl .iSeries_early_setup
1536 /* relocation is on at this point */
1538 b .start_here_common
1539 #endif /* CONFIG_PPC_ISERIES */
1541 #ifdef CONFIG_PPC_MULTIPLATFORM
1545 andi. r0,r3,MSR_IR|MSR_DR
1552 b . /* prevent speculative execution */
1556 * Here is our main kernel entry point. We support currently 2 kind of entries
1557 * depending on the value of r5.
1559 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1562 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1563 * DT block, r4 is a physical pointer to the kernel itself
1566 _GLOBAL(__start_initialization_multiplatform)
1567 #ifdef CONFIG_PPC_MULTIPLATFORM
1569 * Are we booted from a PROM Of-type client-interface ?
1572 bne .__boot_from_prom /* yes -> prom */
1575 /* Save parameters */
1579 /* Make sure we are running in 64 bits mode */
1582 /* Setup some critical 970 SPRs before switching MMU off */
1583 bl .__970_cpu_preinit
1585 /* Switch off MMU if not already */
1586 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1589 b .__after_prom_start
1591 #ifdef CONFIG_PPC_MULTIPLATFORM
1592 _STATIC(__boot_from_prom)
1593 /* Save parameters */
1601 * Align the stack to 16-byte boundary
1602 * Depending on the size and layout of the ELF sections in the initial
1603 * boot binary, the stack pointer will be unalignet on PowerMac
1607 /* Make sure we are running in 64 bits mode */
1610 /* put a relocation offset into r3 */
1613 LOAD_REG_IMMEDIATE(r2,__toc_start)
1617 /* Relocate the TOC from a virt addr to a real addr */
1620 /* Restore parameters */
1627 /* Do all of the interaction with OF client interface */
1629 /* We never return */
1634 * At this point, r3 contains the physical address we are running at,
1635 * returned by prom_init()
1637 _STATIC(__after_prom_start)
1640 * We need to run with __start at physical address PHYSICAL_START.
1641 * This will leave some code in the first 256B of
1642 * real memory, which are reserved for software use.
1643 * The remainder of the first page is loaded with the fixed
1644 * interrupt vectors. The next two pages are filled with
1645 * unknown exception placeholders.
1647 * Note: This process overwrites the OF exception vectors.
1648 * r26 == relocation offset
1653 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1655 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1657 // XXX FIXME: Use phys returned by OF (r30)
1658 add r4,r27,r26 /* source addr */
1659 /* current address of _start */
1660 /* i.e. where we are running */
1661 /* the source addr */
1663 cmpdi r4,0 /* In some cases the loader may */
1664 beq .start_here_multiplatform /* have already put us at zero */
1665 /* so we can skip the copy. */
1666 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1669 li r6,0x100 /* Start offset, the first 0x100 */
1670 /* bytes were copied earlier. */
1672 bl .copy_and_flush /* copy the first n bytes */
1673 /* this includes the code being */
1674 /* executed here. */
1676 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1677 mtctr r0 /* that we just made/relocated */
1680 4: LOAD_REG_IMMEDIATE(r5,klimit)
1682 ld r5,0(r5) /* get the value of klimit */
1684 bl .copy_and_flush /* copy the rest */
1685 b .start_here_multiplatform
1687 #endif /* CONFIG_PPC_MULTIPLATFORM */
1690 * Copy routine used to copy the kernel to start at physical address 0
1691 * and flush and invalidate the caches as needed.
1692 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1693 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1695 * Note: this routine *only* clobbers r0, r6 and lr
1697 _GLOBAL(copy_and_flush)
1700 4: li r0,16 /* Use the least common */
1701 /* denominator cache line */
1702 /* size. This results in */
1703 /* extra cache line flushes */
1704 /* but operation is correct. */
1705 /* Can't get cache line size */
1706 /* from NACA as it is being */
1709 mtctr r0 /* put # words/line in ctr */
1710 3: addi r6,r6,8 /* copy a cache line */
1714 dcbst r6,r3 /* write it to memory */
1716 icbi r6,r3 /* flush the icache line */
1728 #ifdef CONFIG_PPC_PMAC
1730 * On PowerMac, secondary processors starts from the reset vector, which
1731 * is temporarily turned into a call to one of the functions below.
1736 .globl __secondary_start_pmac_0
1737 __secondary_start_pmac_0:
1738 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1748 _GLOBAL(pmac_secondary_start)
1749 /* turn on 64-bit mode */
1753 /* Copy some CPU settings from CPU 0 */
1754 bl .__restore_cpu_setup
1756 /* pSeries do that early though I don't think we really need it */
1759 mtmsrd r3 /* RI on */
1761 /* Set up a paca value for this processor. */
1762 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1763 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1764 add r13,r13,r4 /* for this processor. */
1765 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1767 /* Create a temp kernel stack for use before relocation is on. */
1768 ld r1,PACAEMERGSP(r13)
1769 subi r1,r1,STACK_FRAME_OVERHEAD
1771 b .__secondary_start
1773 #endif /* CONFIG_PPC_PMAC */
1776 * This function is called after the master CPU has released the
1777 * secondary processors. The execution environment is relocation off.
1778 * The paca for this processor has the following fields initialized at
1780 * 1. Processor number
1781 * 2. Segment table pointer (virtual address)
1782 * On entry the following are set:
1783 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1784 * r24 = cpu# (in Linux terms)
1785 * r13 = paca virtual address
1786 * SPRG3 = paca virtual address
1788 _GLOBAL(__secondary_start)
1789 /* Set thread priority to MEDIUM */
1795 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1796 bl .early_setup_secondary
1798 /* Initialize the kernel stack. Just a repeat for iSeries. */
1799 LOAD_REG_ADDR(r3, current_set)
1800 sldi r28,r24,3 /* get current_set[cpu#] */
1802 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1803 std r1,PACAKSAVE(r13)
1805 /* Clear backchain so we get nice backtraces */
1809 /* enable MMU and jump to start_secondary */
1810 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1811 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1812 #ifdef DO_SOFT_DISABLE
1818 b . /* prevent speculative execution */
1821 * Running with relocation on at this point. All we want to do is
1822 * zero the stack back-chain pointer before going into C code.
1824 _GLOBAL(start_secondary_prolog)
1826 std r3,0(r1) /* Zero the stack frame pointer */
1832 * This subroutine clobbers r11 and r12
1834 _GLOBAL(enable_64b_mode)
1835 mfmsr r11 /* grab the current MSR */
1837 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1840 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1846 #ifdef CONFIG_PPC_MULTIPLATFORM
1848 * This is where the main kernel code starts.
1850 _STATIC(start_here_multiplatform)
1851 /* get a new offset, now that the kernel has moved. */
1855 /* Clear out the BSS. It may have been done in prom_init,
1856 * already but that's irrelevant since prom_init will soon
1857 * be detached from the kernel completely. Besides, we need
1858 * to clear it now for kexec-style entry.
1860 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1861 LOAD_REG_IMMEDIATE(r8,__bss_start)
1862 sub r11,r11,r8 /* bss size */
1863 addi r11,r11,7 /* round up to an even double word */
1864 rldicl. r11,r11,61,3 /* shift right by 3 */
1868 mtctr r11 /* zero this many doublewords */
1875 mtmsrd r6 /* RI on */
1877 /* The following gets the stack and TOC set up with the regs */
1878 /* pointing to the real addr of the kernel stack. This is */
1879 /* all done to support the C function call below which sets */
1880 /* up the htab. This is done because we have relocated the */
1881 /* kernel but are still running in real mode. */
1883 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1886 /* set up a stack pointer (physical address) */
1887 addi r1,r3,THREAD_SIZE
1889 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1891 /* set up the TOC (physical address) */
1892 LOAD_REG_IMMEDIATE(r2,__toc_start)
1897 LOAD_REG_IMMEDIATE(r3, cpu_specs)
1899 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1904 /* Save some low level config HIDs of CPU0 to be copied to
1905 * other CPUs later on, or used for suspend/resume
1907 bl .__save_cpu_setup
1910 /* Do very early kernel initializations, including initial hash table,
1911 * stab and slb setup before we turn on relocation. */
1913 /* Restore parameters passed from prom_init/kexec */
1917 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1918 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1922 b . /* prevent speculative execution */
1923 #endif /* CONFIG_PPC_MULTIPLATFORM */
1925 /* This is where all platforms converge execution */
1926 _STATIC(start_here_common)
1927 /* relocation is on at this point */
1929 /* The following code sets up the SP and TOC now that we are */
1930 /* running with translation enabled. */
1932 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1934 /* set up the stack */
1935 addi r1,r3,THREAD_SIZE
1937 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1939 /* Apply the CPUs-specific fixups (nop out sections not relevant
1943 bl .do_cpu_ftr_fixups
1945 /* ptr to current */
1946 LOAD_REG_IMMEDIATE(r4, init_task)
1947 std r4,PACACURRENT(r13)
1951 std r1,PACAKSAVE(r13)
1955 /* Load up the kernel context */
1957 #ifdef DO_SOFT_DISABLE
1959 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1961 ori r5,r5,MSR_EE /* Hard Enabled */
1971 * We put a few things here that have to be page-aligned.
1972 * This stuff goes at the beginning of the bss, which is page-aligned.
1978 .globl empty_zero_page
1982 .globl swapper_pg_dir
1987 * This space gets a copy of optional info passed to us by the bootstrap
1988 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
1992 .space COMMAND_LINE_SIZE