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/config.h>
25 #include <linux/threads.h>
29 #include <asm/ppc_asm.h>
30 #include <asm/asm-offsets.h>
32 #include <asm/cputable.h>
33 #include <asm/setup.h>
34 #include <asm/hvcall.h>
35 #include <asm/iseries/lpar_map.h>
36 #include <asm/thread_info.h>
38 #ifdef CONFIG_PPC_ISERIES
39 #define DO_SOFT_DISABLE
43 * We layout physical memory as follows:
44 * 0x0000 - 0x00ff : Secondary processor spin code
45 * 0x0100 - 0x2fff : pSeries Interrupt prologs
46 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
47 * 0x6000 - 0x6fff : Initial (CPU0) segment table
48 * 0x7000 - 0x7fff : FWNMI data area
49 * 0x8000 - : Early init and support code
57 * SPRG0 reserved for hypervisor
58 * SPRG1 temp - used to save gpr
59 * SPRG2 temp - used to save gpr
60 * SPRG3 virt addr of paca
64 * Entering into this code we make the following assumptions:
66 * 1. The MMU is off & open firmware is running in real mode.
67 * 2. The kernel is entered at __start
70 * 1. The MMU is on (as it always is for iSeries)
71 * 2. The kernel is entered at system_reset_iSeries
77 #ifdef CONFIG_PPC_MULTIPLATFORM
79 /* NOP this out unconditionally */
81 b .__start_initialization_multiplatform
83 #endif /* CONFIG_PPC_MULTIPLATFORM */
85 /* Catch branch to 0 in real mode */
88 /* Secondary processors spin on this value until it goes to 1. */
89 .globl __secondary_hold_spinloop
90 __secondary_hold_spinloop:
93 /* Secondary processors write this value with their cpu # */
94 /* after they enter the spin loop immediately below. */
95 .globl __secondary_hold_acknowledge
96 __secondary_hold_acknowledge:
99 #ifdef CONFIG_PPC_ISERIES
101 * At offset 0x20, there is a pointer to iSeries LPAR data.
102 * This is required by the hypervisor
105 .llong hvReleaseData-KERNELBASE
106 #endif /* CONFIG_PPC_ISERIES */
110 * The following code is used on pSeries to hold secondary processors
111 * in a spin loop after they have been freed from OpenFirmware, but
112 * before the bulk of the kernel has been relocated. This code
113 * is relocated to physical address 0x60 before prom_init is run.
114 * All of it must fit below the first exception vector at 0x100.
116 _GLOBAL(__secondary_hold)
119 mtmsrd r24 /* RI on */
121 /* Grab our physical cpu number */
124 /* Tell the master cpu we're here */
125 /* Relocation is off & we are located at an address less */
126 /* than 0x100, so only need to grab low order offset. */
127 std r24,__secondary_hold_acknowledge@l(0)
130 /* All secondary cpus wait here until told to start. */
131 100: ld r4,__secondary_hold_spinloop@l(0)
135 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
136 LOAD_REG_IMMEDIATE(r4, .pSeries_secondary_smp_init)
144 /* This value is used to mark exception frames on the stack. */
147 .tc ID_72656773_68657265[TC],0x7265677368657265
151 * The following macros define the code that appears as
152 * the prologue to each of the exception handlers. They
153 * are split into two parts to allow a single kernel binary
154 * to be used for pSeries and iSeries.
155 * LOL. One day... - paulus
159 * We make as much of the exception code common between native
160 * exception handlers (including pSeries LPAR) and iSeries LPAR
161 * implementations as possible.
165 * This is the start of the interrupt handlers for pSeries
166 * This code runs with relocation off.
181 * We're short on space and time in the exception prolog, so we can't
182 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
183 * low halfword of the address, but for Kdump we need the whole low
186 #ifdef CONFIG_CRASH_DUMP
187 #define LOAD_HANDLER(reg, label) \
188 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
189 ori reg,reg,(label)@l; /* .. and the rest */
191 #define LOAD_HANDLER(reg, label) \
192 ori reg,reg,(label)@l; /* virt addr of handler ... */
195 #define EXCEPTION_PROLOG_PSERIES(area, label) \
196 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
197 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
198 std r10,area+EX_R10(r13); \
199 std r11,area+EX_R11(r13); \
200 std r12,area+EX_R12(r13); \
201 mfspr r9,SPRN_SPRG1; \
202 std r9,area+EX_R13(r13); \
204 clrrdi r12,r13,32; /* get high part of &label */ \
206 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
207 LOAD_HANDLER(r12,label) \
208 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
209 mtspr SPRN_SRR0,r12; \
210 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
211 mtspr SPRN_SRR1,r10; \
213 b . /* prevent speculative execution */
216 * This is the start of the interrupt handlers for iSeries
217 * This code runs with relocation on.
219 #define EXCEPTION_PROLOG_ISERIES_1(area) \
220 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
221 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
222 std r10,area+EX_R10(r13); \
223 std r11,area+EX_R11(r13); \
224 std r12,area+EX_R12(r13); \
225 mfspr r9,SPRN_SPRG1; \
226 std r9,area+EX_R13(r13); \
229 #define EXCEPTION_PROLOG_ISERIES_2 \
231 ld r12,PACALPPACAPTR(r13); \
232 ld r11,LPPACASRR0(r12); \
233 ld r12,LPPACASRR1(r12); \
234 ori r10,r10,MSR_RI; \
238 * The common exception prolog is used for all except a few exceptions
239 * such as a segment miss on a kernel address. We have to be prepared
240 * to take another exception from the point where we first touch the
241 * kernel stack onwards.
243 * On entry r13 points to the paca, r9-r13 are saved in the paca,
244 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
245 * SRR1, and relocation is on.
247 #define EXCEPTION_PROLOG_COMMON(n, area) \
248 andi. r10,r12,MSR_PR; /* See if coming from user */ \
249 mr r10,r1; /* Save r1 */ \
250 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
252 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
253 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
254 bge- cr1,bad_stack; /* abort if it is */ \
255 std r9,_CCR(r1); /* save CR in stackframe */ \
256 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
257 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
258 std r10,0(r1); /* make stack chain pointer */ \
259 std r0,GPR0(r1); /* save r0 in stackframe */ \
260 std r10,GPR1(r1); /* save r1 in stackframe */ \
261 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
262 std r2,GPR2(r1); /* save r2 in stackframe */ \
263 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
264 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
265 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
266 ld r10,area+EX_R10(r13); \
269 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
270 ld r10,area+EX_R12(r13); \
271 ld r11,area+EX_R13(r13); \
275 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
276 mflr r9; /* save LR in stackframe */ \
278 mfctr r10; /* save CTR in stackframe */ \
280 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
283 std r9,_TRAP(r1); /* set trap number */ \
285 ld r11,exception_marker@toc(r2); \
286 std r10,RESULT(r1); /* clear regs->result */ \
287 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
292 #define STD_EXCEPTION_PSERIES(n, label) \
294 .globl label##_pSeries; \
297 mtspr SPRN_SPRG1,r13; /* save r13 */ \
298 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
300 #define HSTD_EXCEPTION_PSERIES(n, label) \
302 .globl label##_pSeries; \
305 mtspr SPRN_SPRG1,r20; /* save r20 */ \
306 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
307 mtspr SPRN_SRR0,r20; \
308 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
309 mtspr SPRN_SRR1,r20; \
310 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
311 mtspr SPRN_SPRG1,r13; /* save r13 */ \
312 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
315 #define STD_EXCEPTION_ISERIES(n, label, area) \
316 .globl label##_iSeries; \
319 mtspr SPRN_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 SPRN_SPRG1,r13; /* save r13 */ \
329 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
330 lbz r10,PACAPROCENABLED(r13); \
332 beq- label##_iSeries_masked; \
333 EXCEPTION_PROLOG_ISERIES_2; \
336 #ifdef DO_SOFT_DISABLE
337 #define DISABLE_INTS \
338 lbz r10,PACAPROCENABLED(r13); \
342 stb r11,PACAPROCENABLED(r13); \
343 ori r10,r10,MSR_EE; \
346 #define ENABLE_INTS \
347 lbz r10,PACAPROCENABLED(r13); \
350 ori r11,r11,MSR_EE; \
353 #else /* hard enable/disable interrupts */
356 #define ENABLE_INTS \
359 rlwimi r11,r12,0,MSR_EE; \
364 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
366 .globl label##_common; \
368 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
371 addi r3,r1,STACK_FRAME_OVERHEAD; \
376 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
377 * in the idle task and therefore need the special idle handling.
379 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
381 .globl label##_common; \
383 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
387 addi r3,r1,STACK_FRAME_OVERHEAD; \
391 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
393 .globl label##_common; \
395 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
398 bl .ppc64_runlatch_on; \
399 addi r3,r1,STACK_FRAME_OVERHEAD; \
401 b .ret_from_except_lite
404 * When the idle code in power4_idle puts the CPU into NAP mode,
405 * it has to do so in a loop, and relies on the external interrupt
406 * and decrementer interrupt entry code to get it out of the loop.
407 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
408 * to signal that it is in the loop and needs help to get out.
410 #ifdef CONFIG_PPC_970_NAP
413 clrrdi r11,r1,THREAD_SHIFT; \
414 ld r9,TI_LOCAL_FLAGS(r11); \
415 andi. r10,r9,_TLF_NAPPING; \
416 bnel power4_fixup_nap; \
417 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
423 * Start of pSeries system interrupt routines
426 .globl __start_interrupts
429 STD_EXCEPTION_PSERIES(0x100, system_reset)
432 _machine_check_pSeries:
434 mtspr SPRN_SPRG1,r13 /* save r13 */
435 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
438 .globl data_access_pSeries
447 rlwimi r13,r12,16,0x20
450 beq .do_stab_bolted_pSeries
453 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
454 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
457 .globl data_access_slb_pSeries
458 data_access_slb_pSeries:
461 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
462 std r3,PACA_EXSLB+EX_R3(r13)
464 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
467 /* Keep that around for when we re-implement dynamic VSIDs */
469 bge slb_miss_user_pseries
470 #endif /* __DISABLED__ */
471 std r10,PACA_EXSLB+EX_R10(r13)
472 std r11,PACA_EXSLB+EX_R11(r13)
473 std r12,PACA_EXSLB+EX_R12(r13)
475 std r10,PACA_EXSLB+EX_R13(r13)
476 mfspr r12,SPRN_SRR1 /* and SRR1 */
477 b .slb_miss_realmode /* Rel. branch works in real mode */
479 STD_EXCEPTION_PSERIES(0x400, instruction_access)
482 .globl instruction_access_slb_pSeries
483 instruction_access_slb_pSeries:
486 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
487 std r3,PACA_EXSLB+EX_R3(r13)
488 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
489 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
492 /* Keep that around for when we re-implement dynamic VSIDs */
494 bge slb_miss_user_pseries
495 #endif /* __DISABLED__ */
496 std r10,PACA_EXSLB+EX_R10(r13)
497 std r11,PACA_EXSLB+EX_R11(r13)
498 std r12,PACA_EXSLB+EX_R12(r13)
500 std r10,PACA_EXSLB+EX_R13(r13)
501 mfspr r12,SPRN_SRR1 /* and SRR1 */
502 b .slb_miss_realmode /* Rel. branch works in real mode */
504 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
505 STD_EXCEPTION_PSERIES(0x600, alignment)
506 STD_EXCEPTION_PSERIES(0x700, program_check)
507 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
508 STD_EXCEPTION_PSERIES(0x900, decrementer)
509 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
510 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
513 .globl system_call_pSeries
521 oris r12,r12,system_call_common@h
522 ori r12,r12,system_call_common@l
524 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
528 b . /* prevent speculative execution */
530 STD_EXCEPTION_PSERIES(0xd00, single_step)
531 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
533 /* We need to deal with the Altivec unavailable exception
534 * here which is at 0xf20, thus in the middle of the
535 * prolog code of the PerformanceMonitor one. A little
536 * trickery is thus necessary
539 b performance_monitor_pSeries
541 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
543 #ifdef CONFIG_CBE_RAS
544 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
545 #endif /* CONFIG_CBE_RAS */
546 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
547 #ifdef CONFIG_CBE_RAS
548 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
549 #endif /* CONFIG_CBE_RAS */
550 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
551 #ifdef CONFIG_CBE_RAS
552 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
553 #endif /* CONFIG_CBE_RAS */
557 /*** pSeries interrupt support ***/
559 /* moved from 0xf00 */
560 STD_EXCEPTION_PSERIES(., performance_monitor)
563 _GLOBAL(do_stab_bolted_pSeries)
566 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
569 * We have some room here we use that to put
570 * the peries slb miss user trampoline code so it's reasonably
571 * away from slb_miss_user_common to avoid problems with rfid
573 * This is used for when the SLB miss handler has to go virtual,
574 * which doesn't happen for now anymore but will once we re-implement
575 * dynamic VSIDs for shared page tables
578 slb_miss_user_pseries:
579 std r10,PACA_EXGEN+EX_R10(r13)
580 std r11,PACA_EXGEN+EX_R11(r13)
581 std r12,PACA_EXGEN+EX_R12(r13)
583 ld r11,PACA_EXSLB+EX_R9(r13)
584 ld r12,PACA_EXSLB+EX_R3(r13)
585 std r10,PACA_EXGEN+EX_R13(r13)
586 std r11,PACA_EXGEN+EX_R9(r13)
587 std r12,PACA_EXGEN+EX_R3(r13)
590 mfspr r11,SRR0 /* save SRR0 */
591 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
592 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
594 mfspr r12,SRR1 /* and SRR1 */
597 b . /* prevent spec. execution */
598 #endif /* __DISABLED__ */
601 * Vectors for the FWNMI option. Share common code.
603 .globl system_reset_fwnmi
607 mtspr SPRN_SPRG1,r13 /* save r13 */
608 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
610 .globl machine_check_fwnmi
614 mtspr SPRN_SPRG1,r13 /* save r13 */
615 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
617 #ifdef CONFIG_PPC_ISERIES
618 /*** ISeries-LPAR interrupt handlers ***/
620 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
622 .globl data_access_iSeries
630 rlwimi r13,r12,16,0x20
633 beq .do_stab_bolted_iSeries
636 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
637 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
638 EXCEPTION_PROLOG_ISERIES_2
641 .do_stab_bolted_iSeries:
644 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
645 EXCEPTION_PROLOG_ISERIES_2
648 .globl data_access_slb_iSeries
649 data_access_slb_iSeries:
650 mtspr SPRN_SPRG1,r13 /* save r13 */
651 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
652 std r3,PACA_EXSLB+EX_R3(r13)
654 std r9,PACA_EXSLB+EX_R9(r13)
658 bge slb_miss_user_iseries
660 std r10,PACA_EXSLB+EX_R10(r13)
661 std r11,PACA_EXSLB+EX_R11(r13)
662 std r12,PACA_EXSLB+EX_R12(r13)
664 std r10,PACA_EXSLB+EX_R13(r13)
665 ld r12,PACALPPACAPTR(r13)
666 ld r12,LPPACASRR1(r12)
669 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
671 .globl instruction_access_slb_iSeries
672 instruction_access_slb_iSeries:
673 mtspr SPRN_SPRG1,r13 /* save r13 */
674 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
675 std r3,PACA_EXSLB+EX_R3(r13)
676 ld r3,PACALPPACAPTR(r13)
677 ld r3,LPPACASRR0(r3) /* get SRR0 value */
678 std r9,PACA_EXSLB+EX_R9(r13)
682 bge .slb_miss_user_iseries
684 std r10,PACA_EXSLB+EX_R10(r13)
685 std r11,PACA_EXSLB+EX_R11(r13)
686 std r12,PACA_EXSLB+EX_R12(r13)
688 std r10,PACA_EXSLB+EX_R13(r13)
689 ld r12,PACALPPACAPTR(r13)
690 ld r12,LPPACASRR1(r12)
694 slb_miss_user_iseries:
695 std r10,PACA_EXGEN+EX_R10(r13)
696 std r11,PACA_EXGEN+EX_R11(r13)
697 std r12,PACA_EXGEN+EX_R12(r13)
699 ld r11,PACA_EXSLB+EX_R9(r13)
700 ld r12,PACA_EXSLB+EX_R3(r13)
701 std r10,PACA_EXGEN+EX_R13(r13)
702 std r11,PACA_EXGEN+EX_R9(r13)
703 std r12,PACA_EXGEN+EX_R3(r13)
704 EXCEPTION_PROLOG_ISERIES_2
705 b slb_miss_user_common
708 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
709 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
710 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
711 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
712 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
713 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
714 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
716 .globl system_call_iSeries
720 EXCEPTION_PROLOG_ISERIES_2
723 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
724 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
725 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
727 .globl system_reset_iSeries
728 system_reset_iSeries:
729 mfspr r13,SPRN_SPRG3 /* Get paca address */
732 mtmsrd r24 /* RI on */
733 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
734 cmpwi 0,r24,0 /* Are we processor 0? */
735 beq .__start_initialization_iSeries /* Start up the first processor */
737 li r5,CTRL_RUNLATCH /* Turn off the run light */
744 lbz r23,PACAPROCSTART(r13) /* Test if this processor
747 LOAD_REG_IMMEDIATE(r3,current_set)
748 sldi r28,r24,3 /* get current_set[cpu#] */
750 addi r1,r3,THREAD_SIZE
751 subi r1,r1,STACK_FRAME_OVERHEAD
754 beq iSeries_secondary_smp_loop /* Loop until told to go */
755 bne .__secondary_start /* Loop until told to go */
756 iSeries_secondary_smp_loop:
757 /* Let the Hypervisor know we are alive */
758 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
760 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
761 #else /* CONFIG_SMP */
762 /* Yield the processor. This is required for non-SMP kernels
763 which are running on multi-threaded machines. */
765 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
766 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
767 li r4,0 /* "yield timed" */
768 li r5,-1 /* "yield forever" */
769 #endif /* CONFIG_SMP */
770 li r0,-1 /* r0=-1 indicates a Hypervisor call */
771 sc /* Invoke the hypervisor via a system call */
772 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
773 b 1b /* If SMP not configured, secondaries
776 .globl decrementer_iSeries_masked
777 decrementer_iSeries_masked:
778 /* We may not have a valid TOC pointer in here. */
780 ld r12,PACALPPACAPTR(r13)
781 stb r11,LPPACADECRINT(r12)
782 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
787 .globl hardware_interrupt_iSeries_masked
788 hardware_interrupt_iSeries_masked:
789 mtcrf 0x80,r9 /* Restore regs */
790 ld r12,PACALPPACAPTR(r13)
791 ld r11,LPPACASRR0(r12)
792 ld r12,LPPACASRR1(r12)
795 ld r9,PACA_EXGEN+EX_R9(r13)
796 ld r10,PACA_EXGEN+EX_R10(r13)
797 ld r11,PACA_EXGEN+EX_R11(r13)
798 ld r12,PACA_EXGEN+EX_R12(r13)
799 ld r13,PACA_EXGEN+EX_R13(r13)
801 b . /* prevent speculative execution */
802 #endif /* CONFIG_PPC_ISERIES */
804 /*** Common interrupt handlers ***/
806 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
809 * Machine check is different because we use a different
810 * save area: PACA_EXMC instead of PACA_EXGEN.
813 .globl machine_check_common
814 machine_check_common:
815 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
819 addi r3,r1,STACK_FRAME_OVERHEAD
820 bl .machine_check_exception
823 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
824 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
825 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
826 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
827 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
828 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
829 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
830 #ifdef CONFIG_ALTIVEC
831 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
833 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
835 #ifdef CONFIG_CBE_RAS
836 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
837 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
838 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
839 #endif /* CONFIG_CBE_RAS */
842 * Here we have detected that the kernel stack pointer is bad.
843 * R9 contains the saved CR, r13 points to the paca,
844 * r10 contains the (bad) kernel stack pointer,
845 * r11 and r12 contain the saved SRR0 and SRR1.
846 * We switch to using an emergency stack, save the registers there,
847 * and call kernel_bad_stack(), which panics.
850 ld r1,PACAEMERGSP(r13)
851 subi r1,r1,64+INT_FRAME_SIZE
872 addi r11,r1,INT_FRAME_SIZE
877 1: addi r3,r1,STACK_FRAME_OVERHEAD
882 * Return from an exception with minimal checks.
883 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
884 * If interrupts have been enabled, or anything has been
885 * done that might have changed the scheduling status of
886 * any task or sent any task a signal, you should use
887 * ret_from_except or ret_from_except_lite instead of this.
889 .globl fast_exception_return
890 fast_exception_return:
893 andi. r3,r12,MSR_RI /* check if RI is set */
896 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
899 ACCOUNT_CPU_USER_EXIT(r3, r4)
915 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
923 b . /* prevent speculative execution */
927 1: addi r3,r1,STACK_FRAME_OVERHEAD
928 bl .unrecoverable_exception
932 * Here r13 points to the paca, r9 contains the saved CR,
933 * SRR0 and SRR1 are saved in r11 and r12,
934 * r9 - r13 are saved in paca->exgen.
937 .globl data_access_common
940 std r10,PACA_EXGEN+EX_DAR(r13)
942 stw r10,PACA_EXGEN+EX_DSISR(r13)
943 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
944 ld r3,PACA_EXGEN+EX_DAR(r13)
945 lwz r4,PACA_EXGEN+EX_DSISR(r13)
947 b .do_hash_page /* Try to handle as hpte fault */
950 .globl instruction_access_common
951 instruction_access_common:
952 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
956 b .do_hash_page /* Try to handle as hpte fault */
959 * Here is the common SLB miss user that is used when going to virtual
960 * mode for SLB misses, that is currently not used
964 .globl slb_miss_user_common
965 slb_miss_user_common:
967 std r3,PACA_EXGEN+EX_DAR(r13)
968 stw r9,PACA_EXGEN+EX_CCR(r13)
969 std r10,PACA_EXGEN+EX_LR(r13)
970 std r11,PACA_EXGEN+EX_SRR0(r13)
971 bl .slb_allocate_user
973 ld r10,PACA_EXGEN+EX_LR(r13)
974 ld r3,PACA_EXGEN+EX_R3(r13)
975 lwz r9,PACA_EXGEN+EX_CCR(r13)
976 ld r11,PACA_EXGEN+EX_SRR0(r13)
980 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
981 beq- unrecov_user_slb
989 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
995 ld r9,PACA_EXGEN+EX_R9(r13)
996 ld r10,PACA_EXGEN+EX_R10(r13)
997 ld r11,PACA_EXGEN+EX_R11(r13)
998 ld r12,PACA_EXGEN+EX_R12(r13)
999 ld r13,PACA_EXGEN+EX_R13(r13)
1004 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1005 ld r4,PACA_EXGEN+EX_DAR(r13)
1009 b .handle_page_fault
1012 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1015 1: addi r3,r1,STACK_FRAME_OVERHEAD
1016 bl .unrecoverable_exception
1019 #endif /* __DISABLED__ */
1023 * r13 points to the PACA, r9 contains the saved CR,
1024 * r12 contain the saved SRR1, SRR0 is still ready for return
1025 * r3 has the faulting address
1026 * r9 - r13 are saved in paca->exslb.
1027 * r3 is saved in paca->slb_r3
1028 * We assume we aren't going to take any exceptions during this procedure.
1030 _GLOBAL(slb_miss_realmode)
1033 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1034 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1036 bl .slb_allocate_realmode
1038 /* All done -- return from exception. */
1040 ld r10,PACA_EXSLB+EX_LR(r13)
1041 ld r3,PACA_EXSLB+EX_R3(r13)
1042 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1043 #ifdef CONFIG_PPC_ISERIES
1044 ld r11,PACALPPACAPTR(r13)
1045 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1046 #endif /* CONFIG_PPC_ISERIES */
1050 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1056 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1059 #ifdef CONFIG_PPC_ISERIES
1062 #endif /* CONFIG_PPC_ISERIES */
1063 ld r9,PACA_EXSLB+EX_R9(r13)
1064 ld r10,PACA_EXSLB+EX_R10(r13)
1065 ld r11,PACA_EXSLB+EX_R11(r13)
1066 ld r12,PACA_EXSLB+EX_R12(r13)
1067 ld r13,PACA_EXSLB+EX_R13(r13)
1069 b . /* prevent speculative execution */
1072 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1075 1: addi r3,r1,STACK_FRAME_OVERHEAD
1076 bl .unrecoverable_exception
1080 .globl hardware_interrupt_common
1081 .globl hardware_interrupt_entry
1082 hardware_interrupt_common:
1083 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1085 hardware_interrupt_entry:
1087 bl .ppc64_runlatch_on
1088 addi r3,r1,STACK_FRAME_OVERHEAD
1090 b .ret_from_except_lite
1092 #ifdef CONFIG_PPC_970_NAP
1095 std r9,TI_LOCAL_FLAGS(r11)
1096 ld r10,_LINK(r1) /* make idle task do the */
1097 std r10,_NIP(r1) /* equivalent of a blr */
1102 .globl alignment_common
1105 std r10,PACA_EXGEN+EX_DAR(r13)
1106 mfspr r10,SPRN_DSISR
1107 stw r10,PACA_EXGEN+EX_DSISR(r13)
1108 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1109 ld r3,PACA_EXGEN+EX_DAR(r13)
1110 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1114 addi r3,r1,STACK_FRAME_OVERHEAD
1116 bl .alignment_exception
1120 .globl program_check_common
1121 program_check_common:
1122 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1124 addi r3,r1,STACK_FRAME_OVERHEAD
1126 bl .program_check_exception
1130 .globl fp_unavailable_common
1131 fp_unavailable_common:
1132 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1133 bne .load_up_fpu /* if from user, just load it up */
1135 addi r3,r1,STACK_FRAME_OVERHEAD
1137 bl .kernel_fp_unavailable_exception
1141 .globl altivec_unavailable_common
1142 altivec_unavailable_common:
1143 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1144 #ifdef CONFIG_ALTIVEC
1146 bne .load_up_altivec /* if from user, just load it up */
1147 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1150 addi r3,r1,STACK_FRAME_OVERHEAD
1152 bl .altivec_unavailable_exception
1155 #ifdef CONFIG_ALTIVEC
1157 * load_up_altivec(unused, unused, tsk)
1158 * Disable VMX for the task which had it previously,
1159 * and save its vector registers in its thread_struct.
1160 * Enables the VMX for use in the kernel on return.
1161 * On SMP we know the VMX is free, since we give it up every
1162 * switch (ie, no lazy save of the vector registers).
1163 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1165 _STATIC(load_up_altivec)
1166 mfmsr r5 /* grab the current MSR */
1167 oris r5,r5,MSR_VEC@h
1168 mtmsrd r5 /* enable use of VMX now */
1172 * For SMP, we don't do lazy VMX switching because it just gets too
1173 * horrendously complex, especially when a task switches from one CPU
1174 * to another. Instead we call giveup_altvec in switch_to.
1175 * VRSAVE isn't dealt with here, that is done in the normal context
1176 * switch code. Note that we could rely on vrsave value to eventually
1177 * avoid saving all of the VREGs here...
1180 ld r3,last_task_used_altivec@got(r2)
1184 /* Save VMX state to last_task_used_altivec's THREAD struct */
1190 /* Disable VMX for last_task_used_altivec */
1192 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1195 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1197 #endif /* CONFIG_SMP */
1198 /* Hack: if we get an altivec unavailable trap with VRSAVE
1199 * set to all zeros, we assume this is a broken application
1200 * that fails to set it properly, and thus we switch it to
1203 mfspr r4,SPRN_VRSAVE
1207 mtspr SPRN_VRSAVE,r4
1209 /* enable use of VMX after return */
1210 ld r4,PACACURRENT(r13)
1211 addi r5,r4,THREAD /* Get THREAD */
1212 oris r12,r12,MSR_VEC@h
1216 stw r4,THREAD_USED_VR(r5)
1221 /* Update last_task_used_math to 'current' */
1222 subi r4,r5,THREAD /* Back to 'current' */
1224 #endif /* CONFIG_SMP */
1225 /* restore registers and return */
1226 b fast_exception_return
1227 #endif /* CONFIG_ALTIVEC */
1233 _GLOBAL(do_hash_page)
1237 andis. r0,r4,0xa450 /* weird error? */
1238 bne- .handle_page_fault /* if not, try to insert a HPTE */
1240 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1241 bne- .do_ste_alloc /* If so handle it */
1242 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1245 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1246 * accessing a userspace segment (even from the kernel). We assume
1247 * kernel addresses always have the high bit set.
1249 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1250 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1251 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1252 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1253 ori r4,r4,1 /* add _PAGE_PRESENT */
1254 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1257 * On iSeries, we soft-disable interrupts here, then
1258 * hard-enable interrupts so that the hash_page code can spin on
1259 * the hash_table_lock without problems on a shared processor.
1264 * r3 contains the faulting address
1265 * r4 contains the required access permissions
1266 * r5 contains the trap number
1268 * at return r3 = 0 for success
1270 bl .hash_page /* build HPTE if possible */
1271 cmpdi r3,0 /* see if hash_page succeeded */
1273 #ifdef DO_SOFT_DISABLE
1275 * If we had interrupts soft-enabled at the point where the
1276 * DSI/ISI occurred, and an interrupt came in during hash_page,
1278 * We jump to ret_from_except_lite rather than fast_exception_return
1279 * because ret_from_except_lite will check for and handle pending
1280 * interrupts if necessary.
1282 beq .ret_from_except_lite
1283 /* For a hash failure, we don't bother re-enabling interrupts */
1287 * hash_page couldn't handle it, set soft interrupt enable back
1288 * to what it was before the trap. Note that .local_irq_restore
1289 * handles any interrupts pending at this point.
1292 bl .local_irq_restore
1295 beq fast_exception_return /* Return from exception on success */
1296 ble- 12f /* Failure return from hash_page */
1301 /* Here we have a page fault that hash_page can't handle. */
1302 _GLOBAL(handle_page_fault)
1306 addi r3,r1,STACK_FRAME_OVERHEAD
1309 beq+ .ret_from_except_lite
1312 addi r3,r1,STACK_FRAME_OVERHEAD
1317 /* We have a page fault that hash_page could handle but HV refused
1321 addi r3,r1,STACK_FRAME_OVERHEAD
1326 /* here we have a segment miss */
1327 _GLOBAL(do_ste_alloc)
1328 bl .ste_allocate /* try to insert stab entry */
1330 beq+ fast_exception_return
1331 b .handle_page_fault
1334 * r13 points to the PACA, r9 contains the saved CR,
1335 * r11 and r12 contain the saved SRR0 and SRR1.
1336 * r9 - r13 are saved in paca->exslb.
1337 * We assume we aren't going to take any exceptions during this procedure.
1338 * We assume (DAR >> 60) == 0xc.
1341 _GLOBAL(do_stab_bolted)
1342 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1343 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1345 /* Hash to the primary group */
1346 ld r10,PACASTABVIRT(r13)
1349 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1351 /* Calculate VSID */
1352 /* This is a kernel address, so protovsid = ESID */
1353 ASM_VSID_SCRAMBLE(r11, r9)
1354 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1356 /* Search the primary group for a free entry */
1357 1: ld r11,0(r10) /* Test valid bit of the current ste */
1364 /* Stick for only searching the primary group for now. */
1365 /* At least for now, we use a very simple random castout scheme */
1366 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1368 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1371 /* r10 currently points to an ste one past the group of interest */
1372 /* make it point to the randomly selected entry */
1374 or r10,r10,r11 /* r10 is the entry to invalidate */
1376 isync /* mark the entry invalid */
1378 rldicl r11,r11,56,1 /* clear the valid bit */
1383 clrrdi r11,r11,28 /* Get the esid part of the ste */
1386 2: std r9,8(r10) /* Store the vsid part of the ste */
1389 mfspr r11,SPRN_DAR /* Get the new esid */
1390 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1391 ori r11,r11,0x90 /* Turn on valid and kp */
1392 std r11,0(r10) /* Put new entry back into the stab */
1396 /* All done -- return from exception. */
1397 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1398 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1400 andi. r10,r12,MSR_RI
1403 mtcrf 0x80,r9 /* restore CR */
1411 ld r9,PACA_EXSLB+EX_R9(r13)
1412 ld r10,PACA_EXSLB+EX_R10(r13)
1413 ld r11,PACA_EXSLB+EX_R11(r13)
1414 ld r12,PACA_EXSLB+EX_R12(r13)
1415 ld r13,PACA_EXSLB+EX_R13(r13)
1417 b . /* prevent speculative execution */
1420 * Space for CPU0's segment table.
1422 * On iSeries, the hypervisor must fill in at least one entry before
1423 * we get control (with relocate on). The address is give to the hv
1424 * as a page number (see xLparMap in lpardata.c), so this must be at a
1425 * fixed address (the linker can't compute (u64)&initial_stab >>
1428 . = STAB0_OFFSET /* 0x6000 */
1434 * Data area reserved for FWNMI option.
1435 * This address (0x7000) is fixed by the RPA.
1438 .globl fwnmi_data_area
1441 /* iSeries does not use the FWNMI stuff, so it is safe to put
1442 * this here, even if we later allow kernels that will boot on
1443 * both pSeries and iSeries */
1444 #ifdef CONFIG_PPC_ISERIES
1446 #include "lparmap.s"
1448 * This ".text" is here for old compilers that generate a trailing
1449 * .note section when compiling .c files to .s
1452 #endif /* CONFIG_PPC_ISERIES */
1457 * On pSeries, secondary processors spin in the following code.
1458 * At entry, r3 = this processor's number (physical cpu id)
1460 _GLOBAL(pSeries_secondary_smp_init)
1463 /* turn on 64-bit mode */
1467 /* Copy some CPU settings from CPU 0 */
1468 bl .__restore_cpu_setup
1470 /* Set up a paca value for this processor. Since we have the
1471 * physical cpu id in r24, we need to search the pacas to find
1472 * which logical id maps to our physical one.
1474 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1475 li r5,0 /* logical cpu id */
1476 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1477 cmpw r6,r24 /* Compare to our id */
1479 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1484 mr r3,r24 /* not found, copy phys to r3 */
1485 b .kexec_wait /* next kernel might do better */
1487 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1488 /* From now on, r24 is expected to be logical cpuid */
1491 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1495 /* Create a temp kernel stack for use before relocation is on. */
1496 ld r1,PACAEMERGSP(r13)
1497 subi r1,r1,STACK_FRAME_OVERHEAD
1501 bne .__secondary_start
1503 b 3b /* Loop until told to go */
1505 #ifdef CONFIG_PPC_ISERIES
1506 _STATIC(__start_initialization_iSeries)
1507 /* Clear out the BSS */
1508 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1509 LOAD_REG_IMMEDIATE(r8,__bss_start)
1510 sub r11,r11,r8 /* bss size */
1511 addi r11,r11,7 /* round up to an even double word */
1512 rldicl. r11,r11,61,3 /* shift right by 3 */
1516 mtctr r11 /* zero this many doublewords */
1520 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1521 addi r1,r1,THREAD_SIZE
1523 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1525 LOAD_REG_IMMEDIATE(r3,cpu_specs)
1526 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1530 LOAD_REG_IMMEDIATE(r2,__toc_start)
1534 bl .iSeries_early_setup
1537 /* relocation is on at this point */
1539 b .start_here_common
1540 #endif /* CONFIG_PPC_ISERIES */
1542 #ifdef CONFIG_PPC_MULTIPLATFORM
1546 andi. r0,r3,MSR_IR|MSR_DR
1553 b . /* prevent speculative execution */
1557 * Here is our main kernel entry point. We support currently 2 kind of entries
1558 * depending on the value of r5.
1560 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1563 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1564 * DT block, r4 is a physical pointer to the kernel itself
1567 _GLOBAL(__start_initialization_multiplatform)
1568 #ifdef CONFIG_PPC_MULTIPLATFORM
1570 * Are we booted from a PROM Of-type client-interface ?
1573 bne .__boot_from_prom /* yes -> prom */
1576 /* Save parameters */
1580 /* Make sure we are running in 64 bits mode */
1583 /* Setup some critical 970 SPRs before switching MMU off */
1584 bl .__970_cpu_preinit
1586 /* Switch off MMU if not already */
1587 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1590 b .__after_prom_start
1592 #ifdef CONFIG_PPC_MULTIPLATFORM
1593 _STATIC(__boot_from_prom)
1594 /* Save parameters */
1602 * Align the stack to 16-byte boundary
1603 * Depending on the size and layout of the ELF sections in the initial
1604 * boot binary, the stack pointer will be unalignet on PowerMac
1608 /* Make sure we are running in 64 bits mode */
1611 /* put a relocation offset into r3 */
1614 LOAD_REG_IMMEDIATE(r2,__toc_start)
1618 /* Relocate the TOC from a virt addr to a real addr */
1621 /* Restore parameters */
1628 /* Do all of the interaction with OF client interface */
1630 /* We never return */
1635 * At this point, r3 contains the physical address we are running at,
1636 * returned by prom_init()
1638 _STATIC(__after_prom_start)
1641 * We need to run with __start at physical address PHYSICAL_START.
1642 * This will leave some code in the first 256B of
1643 * real memory, which are reserved for software use.
1644 * The remainder of the first page is loaded with the fixed
1645 * interrupt vectors. The next two pages are filled with
1646 * unknown exception placeholders.
1648 * Note: This process overwrites the OF exception vectors.
1649 * r26 == relocation offset
1654 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1656 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1658 // XXX FIXME: Use phys returned by OF (r30)
1659 add r4,r27,r26 /* source addr */
1660 /* current address of _start */
1661 /* i.e. where we are running */
1662 /* the source addr */
1664 cmpdi r4,0 /* In some cases the loader may */
1665 beq .start_here_multiplatform /* have already put us at zero */
1666 /* so we can skip the copy. */
1667 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1670 li r6,0x100 /* Start offset, the first 0x100 */
1671 /* bytes were copied earlier. */
1673 bl .copy_and_flush /* copy the first n bytes */
1674 /* this includes the code being */
1675 /* executed here. */
1677 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1678 mtctr r0 /* that we just made/relocated */
1681 4: LOAD_REG_IMMEDIATE(r5,klimit)
1683 ld r5,0(r5) /* get the value of klimit */
1685 bl .copy_and_flush /* copy the rest */
1686 b .start_here_multiplatform
1688 #endif /* CONFIG_PPC_MULTIPLATFORM */
1691 * Copy routine used to copy the kernel to start at physical address 0
1692 * and flush and invalidate the caches as needed.
1693 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1694 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1696 * Note: this routine *only* clobbers r0, r6 and lr
1698 _GLOBAL(copy_and_flush)
1701 4: li r0,16 /* Use the least common */
1702 /* denominator cache line */
1703 /* size. This results in */
1704 /* extra cache line flushes */
1705 /* but operation is correct. */
1706 /* Can't get cache line size */
1707 /* from NACA as it is being */
1710 mtctr r0 /* put # words/line in ctr */
1711 3: addi r6,r6,8 /* copy a cache line */
1715 dcbst r6,r3 /* write it to memory */
1717 icbi r6,r3 /* flush the icache line */
1729 #ifdef CONFIG_PPC_PMAC
1731 * On PowerMac, secondary processors starts from the reset vector, which
1732 * is temporarily turned into a call to one of the functions below.
1737 .globl __secondary_start_pmac_0
1738 __secondary_start_pmac_0:
1739 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1749 _GLOBAL(pmac_secondary_start)
1750 /* turn on 64-bit mode */
1754 /* Copy some CPU settings from CPU 0 */
1755 bl .__restore_cpu_setup
1757 /* pSeries do that early though I don't think we really need it */
1760 mtmsrd r3 /* RI on */
1762 /* Set up a paca value for this processor. */
1763 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1764 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1765 add r13,r13,r4 /* for this processor. */
1766 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1768 /* Create a temp kernel stack for use before relocation is on. */
1769 ld r1,PACAEMERGSP(r13)
1770 subi r1,r1,STACK_FRAME_OVERHEAD
1772 b .__secondary_start
1774 #endif /* CONFIG_PPC_PMAC */
1777 * This function is called after the master CPU has released the
1778 * secondary processors. The execution environment is relocation off.
1779 * The paca for this processor has the following fields initialized at
1781 * 1. Processor number
1782 * 2. Segment table pointer (virtual address)
1783 * On entry the following are set:
1784 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1785 * r24 = cpu# (in Linux terms)
1786 * r13 = paca virtual address
1787 * SPRG3 = paca virtual address
1789 _GLOBAL(__secondary_start)
1790 /* Set thread priority to MEDIUM */
1796 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1797 bl .early_setup_secondary
1799 /* Initialize the kernel stack. Just a repeat for iSeries. */
1800 LOAD_REG_ADDR(r3, current_set)
1801 sldi r28,r24,3 /* get current_set[cpu#] */
1803 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1804 std r1,PACAKSAVE(r13)
1806 /* Clear backchain so we get nice backtraces */
1810 /* enable MMU and jump to start_secondary */
1811 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1812 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1813 #ifdef DO_SOFT_DISABLE
1819 b . /* prevent speculative execution */
1822 * Running with relocation on at this point. All we want to do is
1823 * zero the stack back-chain pointer before going into C code.
1825 _GLOBAL(start_secondary_prolog)
1827 std r3,0(r1) /* Zero the stack frame pointer */
1833 * This subroutine clobbers r11 and r12
1835 _GLOBAL(enable_64b_mode)
1836 mfmsr r11 /* grab the current MSR */
1838 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1841 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1847 #ifdef CONFIG_PPC_MULTIPLATFORM
1849 * This is where the main kernel code starts.
1851 _STATIC(start_here_multiplatform)
1852 /* get a new offset, now that the kernel has moved. */
1856 /* Clear out the BSS. It may have been done in prom_init,
1857 * already but that's irrelevant since prom_init will soon
1858 * be detached from the kernel completely. Besides, we need
1859 * to clear it now for kexec-style entry.
1861 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1862 LOAD_REG_IMMEDIATE(r8,__bss_start)
1863 sub r11,r11,r8 /* bss size */
1864 addi r11,r11,7 /* round up to an even double word */
1865 rldicl. r11,r11,61,3 /* shift right by 3 */
1869 mtctr r11 /* zero this many doublewords */
1876 mtmsrd r6 /* RI on */
1878 /* The following gets the stack and TOC set up with the regs */
1879 /* pointing to the real addr of the kernel stack. This is */
1880 /* all done to support the C function call below which sets */
1881 /* up the htab. This is done because we have relocated the */
1882 /* kernel but are still running in real mode. */
1884 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1887 /* set up a stack pointer (physical address) */
1888 addi r1,r3,THREAD_SIZE
1890 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1892 /* set up the TOC (physical address) */
1893 LOAD_REG_IMMEDIATE(r2,__toc_start)
1898 LOAD_REG_IMMEDIATE(r3, cpu_specs)
1900 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1905 /* Save some low level config HIDs of CPU0 to be copied to
1906 * other CPUs later on, or used for suspend/resume
1908 bl .__save_cpu_setup
1911 /* Do very early kernel initializations, including initial hash table,
1912 * stab and slb setup before we turn on relocation. */
1914 /* Restore parameters passed from prom_init/kexec */
1918 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1919 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1923 b . /* prevent speculative execution */
1924 #endif /* CONFIG_PPC_MULTIPLATFORM */
1926 /* This is where all platforms converge execution */
1927 _STATIC(start_here_common)
1928 /* relocation is on at this point */
1930 /* The following code sets up the SP and TOC now that we are */
1931 /* running with translation enabled. */
1933 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1935 /* set up the stack */
1936 addi r1,r3,THREAD_SIZE
1938 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1940 /* Apply the CPUs-specific fixups (nop out sections not relevant
1944 bl .do_cpu_ftr_fixups
1946 /* ptr to current */
1947 LOAD_REG_IMMEDIATE(r4, init_task)
1948 std r4,PACACURRENT(r13)
1952 std r1,PACAKSAVE(r13)
1956 /* Load up the kernel context */
1958 #ifdef DO_SOFT_DISABLE
1960 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1962 ori r5,r5,MSR_EE /* Hard Enabled */
1972 * We put a few things here that have to be page-aligned.
1973 * This stuff goes at the beginning of the bss, which is page-aligned.
1979 .globl empty_zero_page
1983 .globl swapper_pg_dir
1988 * This space gets a copy of optional info passed to us by the bootstrap
1989 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
1993 .space COMMAND_LINE_SIZE