3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
15 * This file contains the low-level support and setup for the
16 * PowerPC-64 platform, including trap and interrupt dispatch.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
24 #include <linux/threads.h>
28 #include <asm/ppc_asm.h>
29 #include <asm/asm-offsets.h>
31 #include <asm/cputable.h>
32 #include <asm/setup.h>
33 #include <asm/hvcall.h>
34 #include <asm/iseries/lpar_map.h>
35 #include <asm/thread_info.h>
36 #include <asm/firmware.h>
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, .generic_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 ... */
196 * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode.
197 * The firmware calls the registered system_reset_fwnmi and
198 * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run
199 * a 32bit application at the time of the event.
200 * This firmware bug is present on POWER4 and JS20.
202 #define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \
203 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
204 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
205 std r10,area+EX_R10(r13); \
206 std r11,area+EX_R11(r13); \
207 std r12,area+EX_R12(r13); \
208 mfspr r9,SPRN_SPRG1; \
209 std r9,area+EX_R13(r13); \
211 clrrdi r12,r13,32; /* get high part of &label */ \
213 /* force 64bit mode */ \
214 li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \
215 rldimi r10,r11,61,0; /* insert into top 3 bits */ \
216 /* done 64bit mode */ \
217 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
218 LOAD_HANDLER(r12,label) \
219 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
220 mtspr SPRN_SRR0,r12; \
221 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
222 mtspr SPRN_SRR1,r10; \
224 b . /* prevent speculative execution */
226 #define EXCEPTION_PROLOG_PSERIES(area, label) \
227 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
228 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
229 std r10,area+EX_R10(r13); \
230 std r11,area+EX_R11(r13); \
231 std r12,area+EX_R12(r13); \
232 mfspr r9,SPRN_SPRG1; \
233 std r9,area+EX_R13(r13); \
235 clrrdi r12,r13,32; /* get high part of &label */ \
237 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
238 LOAD_HANDLER(r12,label) \
239 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
240 mtspr SPRN_SRR0,r12; \
241 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
242 mtspr SPRN_SRR1,r10; \
244 b . /* prevent speculative execution */
247 * This is the start of the interrupt handlers for iSeries
248 * This code runs with relocation on.
250 #define EXCEPTION_PROLOG_ISERIES_1(area) \
251 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
252 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
253 std r10,area+EX_R10(r13); \
254 std r11,area+EX_R11(r13); \
255 std r12,area+EX_R12(r13); \
256 mfspr r9,SPRN_SPRG1; \
257 std r9,area+EX_R13(r13); \
260 #define EXCEPTION_PROLOG_ISERIES_2 \
262 ld r12,PACALPPACAPTR(r13); \
263 ld r11,LPPACASRR0(r12); \
264 ld r12,LPPACASRR1(r12); \
265 ori r10,r10,MSR_RI; \
269 * The common exception prolog is used for all except a few exceptions
270 * such as a segment miss on a kernel address. We have to be prepared
271 * to take another exception from the point where we first touch the
272 * kernel stack onwards.
274 * On entry r13 points to the paca, r9-r13 are saved in the paca,
275 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
276 * SRR1, and relocation is on.
278 #define EXCEPTION_PROLOG_COMMON(n, area) \
279 andi. r10,r12,MSR_PR; /* See if coming from user */ \
280 mr r10,r1; /* Save r1 */ \
281 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
283 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
284 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
285 bge- cr1,bad_stack; /* abort if it is */ \
286 std r9,_CCR(r1); /* save CR in stackframe */ \
287 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
288 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
289 std r10,0(r1); /* make stack chain pointer */ \
290 std r0,GPR0(r1); /* save r0 in stackframe */ \
291 std r10,GPR1(r1); /* save r1 in stackframe */ \
292 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
293 std r2,GPR2(r1); /* save r2 in stackframe */ \
294 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
295 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
296 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
297 ld r10,area+EX_R10(r13); \
300 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
301 ld r10,area+EX_R12(r13); \
302 ld r11,area+EX_R13(r13); \
306 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
307 mflr r9; /* save LR in stackframe */ \
309 mfctr r10; /* save CTR in stackframe */ \
311 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
314 std r9,_TRAP(r1); /* set trap number */ \
316 ld r11,exception_marker@toc(r2); \
317 std r10,RESULT(r1); /* clear regs->result */ \
318 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
323 #define STD_EXCEPTION_PSERIES(n, label) \
325 .globl label##_pSeries; \
328 mtspr SPRN_SPRG1,r13; /* save r13 */ \
329 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
331 #define HSTD_EXCEPTION_PSERIES(n, label) \
333 .globl label##_pSeries; \
336 mtspr SPRN_SPRG1,r20; /* save r20 */ \
337 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
338 mtspr SPRN_SRR0,r20; \
339 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
340 mtspr SPRN_SRR1,r20; \
341 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
342 mtspr SPRN_SPRG1,r13; /* save r13 */ \
343 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
346 #define STD_EXCEPTION_ISERIES(n, label, area) \
347 .globl label##_iSeries; \
350 mtspr SPRN_SPRG1,r13; /* save r13 */ \
351 EXCEPTION_PROLOG_ISERIES_1(area); \
352 EXCEPTION_PROLOG_ISERIES_2; \
355 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
356 .globl label##_iSeries; \
359 mtspr SPRN_SPRG1,r13; /* save r13 */ \
360 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
361 lbz r10,PACAPROCENABLED(r13); \
363 beq- label##_iSeries_masked; \
364 EXCEPTION_PROLOG_ISERIES_2; \
367 #ifdef DO_SOFT_DISABLE
368 #define DISABLE_INTS \
369 BEGIN_FW_FTR_SECTION; \
370 lbz r10,PACAPROCENABLED(r13); \
374 stb r11,PACAPROCENABLED(r13); \
375 ori r10,r10,MSR_EE; \
377 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
379 #define ENABLE_INTS \
380 BEGIN_FW_FTR_SECTION; \
381 lbz r10,PACAPROCENABLED(r13); \
384 ori r11,r11,MSR_EE; \
385 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES); \
386 BEGIN_FW_FTR_SECTION; \
389 rlwimi r11,r12,0,MSR_EE; \
390 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES); \
393 #else /* hard enable/disable interrupts */
396 #define ENABLE_INTS \
399 rlwimi r11,r12,0,MSR_EE; \
404 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
406 .globl label##_common; \
408 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
411 addi r3,r1,STACK_FRAME_OVERHEAD; \
416 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
417 * in the idle task and therefore need the special idle handling.
419 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
421 .globl label##_common; \
423 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
427 addi r3,r1,STACK_FRAME_OVERHEAD; \
431 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
433 .globl label##_common; \
435 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
438 bl .ppc64_runlatch_on; \
439 addi r3,r1,STACK_FRAME_OVERHEAD; \
441 b .ret_from_except_lite
444 * When the idle code in power4_idle puts the CPU into NAP mode,
445 * it has to do so in a loop, and relies on the external interrupt
446 * and decrementer interrupt entry code to get it out of the loop.
447 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
448 * to signal that it is in the loop and needs help to get out.
450 #ifdef CONFIG_PPC_970_NAP
453 clrrdi r11,r1,THREAD_SHIFT; \
454 ld r9,TI_LOCAL_FLAGS(r11); \
455 andi. r10,r9,_TLF_NAPPING; \
456 bnel power4_fixup_nap; \
457 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
463 * Start of pSeries system interrupt routines
466 .globl __start_interrupts
469 STD_EXCEPTION_PSERIES(0x100, system_reset)
472 _machine_check_pSeries:
474 mtspr SPRN_SPRG1,r13 /* save r13 */
475 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
478 .globl data_access_pSeries
487 rlwimi r13,r12,16,0x20
490 beq .do_stab_bolted_pSeries
493 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
494 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
497 .globl data_access_slb_pSeries
498 data_access_slb_pSeries:
501 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
502 std r3,PACA_EXSLB+EX_R3(r13)
504 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
507 /* Keep that around for when we re-implement dynamic VSIDs */
509 bge slb_miss_user_pseries
510 #endif /* __DISABLED__ */
511 std r10,PACA_EXSLB+EX_R10(r13)
512 std r11,PACA_EXSLB+EX_R11(r13)
513 std r12,PACA_EXSLB+EX_R12(r13)
515 std r10,PACA_EXSLB+EX_R13(r13)
516 mfspr r12,SPRN_SRR1 /* and SRR1 */
517 b .slb_miss_realmode /* Rel. branch works in real mode */
519 STD_EXCEPTION_PSERIES(0x400, instruction_access)
522 .globl instruction_access_slb_pSeries
523 instruction_access_slb_pSeries:
526 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
527 std r3,PACA_EXSLB+EX_R3(r13)
528 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
529 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
532 /* Keep that around for when we re-implement dynamic VSIDs */
534 bge slb_miss_user_pseries
535 #endif /* __DISABLED__ */
536 std r10,PACA_EXSLB+EX_R10(r13)
537 std r11,PACA_EXSLB+EX_R11(r13)
538 std r12,PACA_EXSLB+EX_R12(r13)
540 std r10,PACA_EXSLB+EX_R13(r13)
541 mfspr r12,SPRN_SRR1 /* and SRR1 */
542 b .slb_miss_realmode /* Rel. branch works in real mode */
544 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
545 STD_EXCEPTION_PSERIES(0x600, alignment)
546 STD_EXCEPTION_PSERIES(0x700, program_check)
547 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
548 STD_EXCEPTION_PSERIES(0x900, decrementer)
549 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
550 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
553 .globl system_call_pSeries
561 oris r12,r12,system_call_common@h
562 ori r12,r12,system_call_common@l
564 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
568 b . /* prevent speculative execution */
570 STD_EXCEPTION_PSERIES(0xd00, single_step)
571 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
573 /* We need to deal with the Altivec unavailable exception
574 * here which is at 0xf20, thus in the middle of the
575 * prolog code of the PerformanceMonitor one. A little
576 * trickery is thus necessary
579 b performance_monitor_pSeries
581 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
583 #ifdef CONFIG_CBE_RAS
584 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
585 #endif /* CONFIG_CBE_RAS */
586 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
587 #ifdef CONFIG_CBE_RAS
588 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
589 #endif /* CONFIG_CBE_RAS */
590 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
591 #ifdef CONFIG_CBE_RAS
592 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
593 #endif /* CONFIG_CBE_RAS */
597 /*** pSeries interrupt support ***/
599 /* moved from 0xf00 */
600 STD_EXCEPTION_PSERIES(., performance_monitor)
603 _GLOBAL(do_stab_bolted_pSeries)
606 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
609 * We have some room here we use that to put
610 * the peries slb miss user trampoline code so it's reasonably
611 * away from slb_miss_user_common to avoid problems with rfid
613 * This is used for when the SLB miss handler has to go virtual,
614 * which doesn't happen for now anymore but will once we re-implement
615 * dynamic VSIDs for shared page tables
618 slb_miss_user_pseries:
619 std r10,PACA_EXGEN+EX_R10(r13)
620 std r11,PACA_EXGEN+EX_R11(r13)
621 std r12,PACA_EXGEN+EX_R12(r13)
623 ld r11,PACA_EXSLB+EX_R9(r13)
624 ld r12,PACA_EXSLB+EX_R3(r13)
625 std r10,PACA_EXGEN+EX_R13(r13)
626 std r11,PACA_EXGEN+EX_R9(r13)
627 std r12,PACA_EXGEN+EX_R3(r13)
630 mfspr r11,SRR0 /* save SRR0 */
631 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
632 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
634 mfspr r12,SRR1 /* and SRR1 */
637 b . /* prevent spec. execution */
638 #endif /* __DISABLED__ */
641 * Vectors for the FWNMI option. Share common code.
643 .globl system_reset_fwnmi
647 mtspr SPRN_SPRG1,r13 /* save r13 */
648 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
650 .globl machine_check_fwnmi
654 mtspr SPRN_SPRG1,r13 /* save r13 */
655 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
657 #ifdef CONFIG_PPC_ISERIES
658 /*** ISeries-LPAR interrupt handlers ***/
660 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
662 .globl data_access_iSeries
670 rlwimi r13,r12,16,0x20
673 beq .do_stab_bolted_iSeries
676 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
677 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
678 EXCEPTION_PROLOG_ISERIES_2
681 .do_stab_bolted_iSeries:
684 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
685 EXCEPTION_PROLOG_ISERIES_2
688 .globl data_access_slb_iSeries
689 data_access_slb_iSeries:
690 mtspr SPRN_SPRG1,r13 /* save r13 */
691 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
692 std r3,PACA_EXSLB+EX_R3(r13)
694 std r9,PACA_EXSLB+EX_R9(r13)
698 bge slb_miss_user_iseries
700 std r10,PACA_EXSLB+EX_R10(r13)
701 std r11,PACA_EXSLB+EX_R11(r13)
702 std r12,PACA_EXSLB+EX_R12(r13)
704 std r10,PACA_EXSLB+EX_R13(r13)
705 ld r12,PACALPPACAPTR(r13)
706 ld r12,LPPACASRR1(r12)
709 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
711 .globl instruction_access_slb_iSeries
712 instruction_access_slb_iSeries:
713 mtspr SPRN_SPRG1,r13 /* save r13 */
714 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
715 std r3,PACA_EXSLB+EX_R3(r13)
716 ld r3,PACALPPACAPTR(r13)
717 ld r3,LPPACASRR0(r3) /* get SRR0 value */
718 std r9,PACA_EXSLB+EX_R9(r13)
722 bge .slb_miss_user_iseries
724 std r10,PACA_EXSLB+EX_R10(r13)
725 std r11,PACA_EXSLB+EX_R11(r13)
726 std r12,PACA_EXSLB+EX_R12(r13)
728 std r10,PACA_EXSLB+EX_R13(r13)
729 ld r12,PACALPPACAPTR(r13)
730 ld r12,LPPACASRR1(r12)
734 slb_miss_user_iseries:
735 std r10,PACA_EXGEN+EX_R10(r13)
736 std r11,PACA_EXGEN+EX_R11(r13)
737 std r12,PACA_EXGEN+EX_R12(r13)
739 ld r11,PACA_EXSLB+EX_R9(r13)
740 ld r12,PACA_EXSLB+EX_R3(r13)
741 std r10,PACA_EXGEN+EX_R13(r13)
742 std r11,PACA_EXGEN+EX_R9(r13)
743 std r12,PACA_EXGEN+EX_R3(r13)
744 EXCEPTION_PROLOG_ISERIES_2
745 b slb_miss_user_common
748 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
749 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
750 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
751 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
752 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
753 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
754 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
756 .globl system_call_iSeries
760 EXCEPTION_PROLOG_ISERIES_2
763 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
764 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
765 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
767 .globl system_reset_iSeries
768 system_reset_iSeries:
769 mfspr r13,SPRN_SPRG3 /* Get paca address */
772 mtmsrd r24 /* RI on */
773 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
774 cmpwi 0,r24,0 /* Are we processor 0? */
775 beq .__start_initialization_iSeries /* Start up the first processor */
777 li r5,CTRL_RUNLATCH /* Turn off the run light */
784 lbz r23,PACAPROCSTART(r13) /* Test if this processor
787 LOAD_REG_IMMEDIATE(r3,current_set)
788 sldi r28,r24,3 /* get current_set[cpu#] */
790 addi r1,r3,THREAD_SIZE
791 subi r1,r1,STACK_FRAME_OVERHEAD
794 beq iSeries_secondary_smp_loop /* Loop until told to go */
795 bne .__secondary_start /* Loop until told to go */
796 iSeries_secondary_smp_loop:
797 /* Let the Hypervisor know we are alive */
798 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
800 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
801 #else /* CONFIG_SMP */
802 /* Yield the processor. This is required for non-SMP kernels
803 which are running on multi-threaded machines. */
805 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
806 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
807 li r4,0 /* "yield timed" */
808 li r5,-1 /* "yield forever" */
809 #endif /* CONFIG_SMP */
810 li r0,-1 /* r0=-1 indicates a Hypervisor call */
811 sc /* Invoke the hypervisor via a system call */
812 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
813 b 1b /* If SMP not configured, secondaries
816 .globl decrementer_iSeries_masked
817 decrementer_iSeries_masked:
818 /* We may not have a valid TOC pointer in here. */
820 ld r12,PACALPPACAPTR(r13)
821 stb r11,LPPACADECRINT(r12)
822 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
827 .globl hardware_interrupt_iSeries_masked
828 hardware_interrupt_iSeries_masked:
829 mtcrf 0x80,r9 /* Restore regs */
830 ld r12,PACALPPACAPTR(r13)
831 ld r11,LPPACASRR0(r12)
832 ld r12,LPPACASRR1(r12)
835 ld r9,PACA_EXGEN+EX_R9(r13)
836 ld r10,PACA_EXGEN+EX_R10(r13)
837 ld r11,PACA_EXGEN+EX_R11(r13)
838 ld r12,PACA_EXGEN+EX_R12(r13)
839 ld r13,PACA_EXGEN+EX_R13(r13)
841 b . /* prevent speculative execution */
842 #endif /* CONFIG_PPC_ISERIES */
844 /*** Common interrupt handlers ***/
846 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
849 * Machine check is different because we use a different
850 * save area: PACA_EXMC instead of PACA_EXGEN.
853 .globl machine_check_common
854 machine_check_common:
855 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
859 addi r3,r1,STACK_FRAME_OVERHEAD
860 bl .machine_check_exception
863 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
864 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
865 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
866 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
867 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
868 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
869 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
870 #ifdef CONFIG_ALTIVEC
871 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
873 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
875 #ifdef CONFIG_CBE_RAS
876 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
877 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
878 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
879 #endif /* CONFIG_CBE_RAS */
882 * Here we have detected that the kernel stack pointer is bad.
883 * R9 contains the saved CR, r13 points to the paca,
884 * r10 contains the (bad) kernel stack pointer,
885 * r11 and r12 contain the saved SRR0 and SRR1.
886 * We switch to using an emergency stack, save the registers there,
887 * and call kernel_bad_stack(), which panics.
890 ld r1,PACAEMERGSP(r13)
891 subi r1,r1,64+INT_FRAME_SIZE
912 addi r11,r1,INT_FRAME_SIZE
917 1: addi r3,r1,STACK_FRAME_OVERHEAD
922 * Return from an exception with minimal checks.
923 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
924 * If interrupts have been enabled, or anything has been
925 * done that might have changed the scheduling status of
926 * any task or sent any task a signal, you should use
927 * ret_from_except or ret_from_except_lite instead of this.
929 .globl fast_exception_return
930 fast_exception_return:
933 andi. r3,r12,MSR_RI /* check if RI is set */
936 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
939 ACCOUNT_CPU_USER_EXIT(r3, r4)
955 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
963 b . /* prevent speculative execution */
967 1: addi r3,r1,STACK_FRAME_OVERHEAD
968 bl .unrecoverable_exception
972 * Here r13 points to the paca, r9 contains the saved CR,
973 * SRR0 and SRR1 are saved in r11 and r12,
974 * r9 - r13 are saved in paca->exgen.
977 .globl data_access_common
980 std r10,PACA_EXGEN+EX_DAR(r13)
982 stw r10,PACA_EXGEN+EX_DSISR(r13)
983 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
984 ld r3,PACA_EXGEN+EX_DAR(r13)
985 lwz r4,PACA_EXGEN+EX_DSISR(r13)
987 b .do_hash_page /* Try to handle as hpte fault */
990 .globl instruction_access_common
991 instruction_access_common:
992 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
996 b .do_hash_page /* Try to handle as hpte fault */
999 * Here is the common SLB miss user that is used when going to virtual
1000 * mode for SLB misses, that is currently not used
1004 .globl slb_miss_user_common
1005 slb_miss_user_common:
1007 std r3,PACA_EXGEN+EX_DAR(r13)
1008 stw r9,PACA_EXGEN+EX_CCR(r13)
1009 std r10,PACA_EXGEN+EX_LR(r13)
1010 std r11,PACA_EXGEN+EX_SRR0(r13)
1011 bl .slb_allocate_user
1013 ld r10,PACA_EXGEN+EX_LR(r13)
1014 ld r3,PACA_EXGEN+EX_R3(r13)
1015 lwz r9,PACA_EXGEN+EX_CCR(r13)
1016 ld r11,PACA_EXGEN+EX_SRR0(r13)
1020 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1021 beq- unrecov_user_slb
1029 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1035 ld r9,PACA_EXGEN+EX_R9(r13)
1036 ld r10,PACA_EXGEN+EX_R10(r13)
1037 ld r11,PACA_EXGEN+EX_R11(r13)
1038 ld r12,PACA_EXGEN+EX_R12(r13)
1039 ld r13,PACA_EXGEN+EX_R13(r13)
1044 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1045 ld r4,PACA_EXGEN+EX_DAR(r13)
1049 b .handle_page_fault
1052 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1055 1: addi r3,r1,STACK_FRAME_OVERHEAD
1056 bl .unrecoverable_exception
1059 #endif /* __DISABLED__ */
1063 * r13 points to the PACA, r9 contains the saved CR,
1064 * r12 contain the saved SRR1, SRR0 is still ready for return
1065 * r3 has the faulting address
1066 * r9 - r13 are saved in paca->exslb.
1067 * r3 is saved in paca->slb_r3
1068 * We assume we aren't going to take any exceptions during this procedure.
1070 _GLOBAL(slb_miss_realmode)
1073 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1074 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1076 bl .slb_allocate_realmode
1078 /* All done -- return from exception. */
1080 ld r10,PACA_EXSLB+EX_LR(r13)
1081 ld r3,PACA_EXSLB+EX_R3(r13)
1082 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1083 #ifdef CONFIG_PPC_ISERIES
1084 BEGIN_FW_FTR_SECTION
1085 ld r11,PACALPPACAPTR(r13)
1086 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1087 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1088 #endif /* CONFIG_PPC_ISERIES */
1092 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1098 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1101 #ifdef CONFIG_PPC_ISERIES
1102 BEGIN_FW_FTR_SECTION
1105 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1106 #endif /* CONFIG_PPC_ISERIES */
1107 ld r9,PACA_EXSLB+EX_R9(r13)
1108 ld r10,PACA_EXSLB+EX_R10(r13)
1109 ld r11,PACA_EXSLB+EX_R11(r13)
1110 ld r12,PACA_EXSLB+EX_R12(r13)
1111 ld r13,PACA_EXSLB+EX_R13(r13)
1113 b . /* prevent speculative execution */
1116 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1119 1: addi r3,r1,STACK_FRAME_OVERHEAD
1120 bl .unrecoverable_exception
1124 .globl hardware_interrupt_common
1125 .globl hardware_interrupt_entry
1126 hardware_interrupt_common:
1127 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1129 hardware_interrupt_entry:
1131 bl .ppc64_runlatch_on
1132 addi r3,r1,STACK_FRAME_OVERHEAD
1134 b .ret_from_except_lite
1136 #ifdef CONFIG_PPC_970_NAP
1139 std r9,TI_LOCAL_FLAGS(r11)
1140 ld r10,_LINK(r1) /* make idle task do the */
1141 std r10,_NIP(r1) /* equivalent of a blr */
1146 .globl alignment_common
1149 std r10,PACA_EXGEN+EX_DAR(r13)
1150 mfspr r10,SPRN_DSISR
1151 stw r10,PACA_EXGEN+EX_DSISR(r13)
1152 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1153 ld r3,PACA_EXGEN+EX_DAR(r13)
1154 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1158 addi r3,r1,STACK_FRAME_OVERHEAD
1160 bl .alignment_exception
1164 .globl program_check_common
1165 program_check_common:
1166 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1168 addi r3,r1,STACK_FRAME_OVERHEAD
1170 bl .program_check_exception
1174 .globl fp_unavailable_common
1175 fp_unavailable_common:
1176 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1177 bne .load_up_fpu /* if from user, just load it up */
1179 addi r3,r1,STACK_FRAME_OVERHEAD
1181 bl .kernel_fp_unavailable_exception
1185 .globl altivec_unavailable_common
1186 altivec_unavailable_common:
1187 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1188 #ifdef CONFIG_ALTIVEC
1190 bne .load_up_altivec /* if from user, just load it up */
1191 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1194 addi r3,r1,STACK_FRAME_OVERHEAD
1196 bl .altivec_unavailable_exception
1199 #ifdef CONFIG_ALTIVEC
1201 * load_up_altivec(unused, unused, tsk)
1202 * Disable VMX for the task which had it previously,
1203 * and save its vector registers in its thread_struct.
1204 * Enables the VMX for use in the kernel on return.
1205 * On SMP we know the VMX is free, since we give it up every
1206 * switch (ie, no lazy save of the vector registers).
1207 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1209 _STATIC(load_up_altivec)
1210 mfmsr r5 /* grab the current MSR */
1211 oris r5,r5,MSR_VEC@h
1212 mtmsrd r5 /* enable use of VMX now */
1216 * For SMP, we don't do lazy VMX switching because it just gets too
1217 * horrendously complex, especially when a task switches from one CPU
1218 * to another. Instead we call giveup_altvec in switch_to.
1219 * VRSAVE isn't dealt with here, that is done in the normal context
1220 * switch code. Note that we could rely on vrsave value to eventually
1221 * avoid saving all of the VREGs here...
1224 ld r3,last_task_used_altivec@got(r2)
1228 /* Save VMX state to last_task_used_altivec's THREAD struct */
1234 /* Disable VMX for last_task_used_altivec */
1236 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1239 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1241 #endif /* CONFIG_SMP */
1242 /* Hack: if we get an altivec unavailable trap with VRSAVE
1243 * set to all zeros, we assume this is a broken application
1244 * that fails to set it properly, and thus we switch it to
1247 mfspr r4,SPRN_VRSAVE
1251 mtspr SPRN_VRSAVE,r4
1253 /* enable use of VMX after return */
1254 ld r4,PACACURRENT(r13)
1255 addi r5,r4,THREAD /* Get THREAD */
1256 oris r12,r12,MSR_VEC@h
1260 stw r4,THREAD_USED_VR(r5)
1265 /* Update last_task_used_math to 'current' */
1266 subi r4,r5,THREAD /* Back to 'current' */
1268 #endif /* CONFIG_SMP */
1269 /* restore registers and return */
1270 b fast_exception_return
1271 #endif /* CONFIG_ALTIVEC */
1277 _GLOBAL(do_hash_page)
1281 andis. r0,r4,0xa450 /* weird error? */
1282 bne- .handle_page_fault /* if not, try to insert a HPTE */
1284 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1285 bne- .do_ste_alloc /* If so handle it */
1286 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1289 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1290 * accessing a userspace segment (even from the kernel). We assume
1291 * kernel addresses always have the high bit set.
1293 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1294 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1295 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1296 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1297 ori r4,r4,1 /* add _PAGE_PRESENT */
1298 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1301 * On iSeries, we soft-disable interrupts here, then
1302 * hard-enable interrupts so that the hash_page code can spin on
1303 * the hash_table_lock without problems on a shared processor.
1308 * r3 contains the faulting address
1309 * r4 contains the required access permissions
1310 * r5 contains the trap number
1312 * at return r3 = 0 for success
1314 bl .hash_page /* build HPTE if possible */
1315 cmpdi r3,0 /* see if hash_page succeeded */
1317 #ifdef DO_SOFT_DISABLE
1318 BEGIN_FW_FTR_SECTION
1320 * If we had interrupts soft-enabled at the point where the
1321 * DSI/ISI occurred, and an interrupt came in during hash_page,
1323 * We jump to ret_from_except_lite rather than fast_exception_return
1324 * because ret_from_except_lite will check for and handle pending
1325 * interrupts if necessary.
1327 beq .ret_from_except_lite
1328 /* For a hash failure, we don't bother re-enabling interrupts */
1332 * hash_page couldn't handle it, set soft interrupt enable back
1333 * to what it was before the trap. Note that .local_irq_restore
1334 * handles any interrupts pending at this point.
1337 bl .local_irq_restore
1339 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1341 BEGIN_FW_FTR_SECTION
1342 beq fast_exception_return /* Return from exception on success */
1343 ble- 12f /* Failure return from hash_page */
1346 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1348 /* Here we have a page fault that hash_page can't handle. */
1349 _GLOBAL(handle_page_fault)
1353 addi r3,r1,STACK_FRAME_OVERHEAD
1356 beq+ .ret_from_except_lite
1359 addi r3,r1,STACK_FRAME_OVERHEAD
1364 /* We have a page fault that hash_page could handle but HV refused
1368 addi r3,r1,STACK_FRAME_OVERHEAD
1373 /* here we have a segment miss */
1374 _GLOBAL(do_ste_alloc)
1375 bl .ste_allocate /* try to insert stab entry */
1377 beq+ fast_exception_return
1378 b .handle_page_fault
1381 * r13 points to the PACA, r9 contains the saved CR,
1382 * r11 and r12 contain the saved SRR0 and SRR1.
1383 * r9 - r13 are saved in paca->exslb.
1384 * We assume we aren't going to take any exceptions during this procedure.
1385 * We assume (DAR >> 60) == 0xc.
1388 _GLOBAL(do_stab_bolted)
1389 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1390 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1392 /* Hash to the primary group */
1393 ld r10,PACASTABVIRT(r13)
1396 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1398 /* Calculate VSID */
1399 /* This is a kernel address, so protovsid = ESID */
1400 ASM_VSID_SCRAMBLE(r11, r9)
1401 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1403 /* Search the primary group for a free entry */
1404 1: ld r11,0(r10) /* Test valid bit of the current ste */
1411 /* Stick for only searching the primary group for now. */
1412 /* At least for now, we use a very simple random castout scheme */
1413 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1415 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1418 /* r10 currently points to an ste one past the group of interest */
1419 /* make it point to the randomly selected entry */
1421 or r10,r10,r11 /* r10 is the entry to invalidate */
1423 isync /* mark the entry invalid */
1425 rldicl r11,r11,56,1 /* clear the valid bit */
1430 clrrdi r11,r11,28 /* Get the esid part of the ste */
1433 2: std r9,8(r10) /* Store the vsid part of the ste */
1436 mfspr r11,SPRN_DAR /* Get the new esid */
1437 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1438 ori r11,r11,0x90 /* Turn on valid and kp */
1439 std r11,0(r10) /* Put new entry back into the stab */
1443 /* All done -- return from exception. */
1444 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1445 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1447 andi. r10,r12,MSR_RI
1450 mtcrf 0x80,r9 /* restore CR */
1458 ld r9,PACA_EXSLB+EX_R9(r13)
1459 ld r10,PACA_EXSLB+EX_R10(r13)
1460 ld r11,PACA_EXSLB+EX_R11(r13)
1461 ld r12,PACA_EXSLB+EX_R12(r13)
1462 ld r13,PACA_EXSLB+EX_R13(r13)
1464 b . /* prevent speculative execution */
1467 * Space for CPU0's segment table.
1469 * On iSeries, the hypervisor must fill in at least one entry before
1470 * we get control (with relocate on). The address is give to the hv
1471 * as a page number (see xLparMap in lpardata.c), so this must be at a
1472 * fixed address (the linker can't compute (u64)&initial_stab >>
1475 . = STAB0_OFFSET /* 0x6000 */
1481 * Data area reserved for FWNMI option.
1482 * This address (0x7000) is fixed by the RPA.
1485 .globl fwnmi_data_area
1488 /* iSeries does not use the FWNMI stuff, so it is safe to put
1489 * this here, even if we later allow kernels that will boot on
1490 * both pSeries and iSeries */
1491 #ifdef CONFIG_PPC_ISERIES
1493 #include "lparmap.s"
1495 * This ".text" is here for old compilers that generate a trailing
1496 * .note section when compiling .c files to .s
1499 #endif /* CONFIG_PPC_ISERIES */
1504 * On pSeries and most other platforms, secondary processors spin
1505 * in the following code.
1506 * At entry, r3 = this processor's number (physical cpu id)
1508 _GLOBAL(generic_secondary_smp_init)
1511 /* turn on 64-bit mode */
1515 /* Set up a paca value for this processor. Since we have the
1516 * physical cpu id in r24, we need to search the pacas to find
1517 * which logical id maps to our physical one.
1519 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1520 li r5,0 /* logical cpu id */
1521 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1522 cmpw r6,r24 /* Compare to our id */
1524 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1529 mr r3,r24 /* not found, copy phys to r3 */
1530 b .kexec_wait /* next kernel might do better */
1532 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1533 /* From now on, r24 is expected to be logical cpuid */
1536 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1541 b 3b /* Never go on non-SMP */
1544 beq 3b /* Loop until told to go */
1546 /* See if we need to call a cpu state restore handler */
1547 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1549 ld r23,CPU_SPEC_RESTORE(r23)
1556 4: /* Create a temp kernel stack for use before relocation is on. */
1557 ld r1,PACAEMERGSP(r13)
1558 subi r1,r1,STACK_FRAME_OVERHEAD
1560 b .__secondary_start
1563 #ifdef CONFIG_PPC_ISERIES
1564 _STATIC(__start_initialization_iSeries)
1565 /* Clear out the BSS */
1566 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1567 LOAD_REG_IMMEDIATE(r8,__bss_start)
1568 sub r11,r11,r8 /* bss size */
1569 addi r11,r11,7 /* round up to an even double word */
1570 rldicl. r11,r11,61,3 /* shift right by 3 */
1574 mtctr r11 /* zero this many doublewords */
1578 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1579 addi r1,r1,THREAD_SIZE
1581 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1583 LOAD_REG_IMMEDIATE(r2,__toc_start)
1587 bl .iSeries_early_setup
1590 /* relocation is on at this point */
1592 b .start_here_common
1593 #endif /* CONFIG_PPC_ISERIES */
1595 #ifdef CONFIG_PPC_MULTIPLATFORM
1599 andi. r0,r3,MSR_IR|MSR_DR
1606 b . /* prevent speculative execution */
1610 * Here is our main kernel entry point. We support currently 2 kind of entries
1611 * depending on the value of r5.
1613 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1616 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1617 * DT block, r4 is a physical pointer to the kernel itself
1620 _GLOBAL(__start_initialization_multiplatform)
1621 #ifdef CONFIG_PPC_MULTIPLATFORM
1623 * Are we booted from a PROM Of-type client-interface ?
1626 bne .__boot_from_prom /* yes -> prom */
1629 /* Save parameters */
1633 /* Make sure we are running in 64 bits mode */
1636 /* Setup some critical 970 SPRs before switching MMU off */
1639 cmpwi r0,0x39 /* 970 */
1641 cmpwi r0,0x3c /* 970FX */
1643 cmpwi r0,0x44 /* 970MP */
1645 cmpwi r0,0x45 /* 970GX */
1647 1: bl .__cpu_preinit_ppc970
1650 /* Switch off MMU if not already */
1651 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1654 b .__after_prom_start
1656 #ifdef CONFIG_PPC_MULTIPLATFORM
1657 _STATIC(__boot_from_prom)
1658 /* Save parameters */
1666 * Align the stack to 16-byte boundary
1667 * Depending on the size and layout of the ELF sections in the initial
1668 * boot binary, the stack pointer will be unalignet on PowerMac
1672 /* Make sure we are running in 64 bits mode */
1675 /* put a relocation offset into r3 */
1678 LOAD_REG_IMMEDIATE(r2,__toc_start)
1682 /* Relocate the TOC from a virt addr to a real addr */
1685 /* Restore parameters */
1692 /* Do all of the interaction with OF client interface */
1694 /* We never return */
1699 * At this point, r3 contains the physical address we are running at,
1700 * returned by prom_init()
1702 _STATIC(__after_prom_start)
1705 * We need to run with __start at physical address PHYSICAL_START.
1706 * This will leave some code in the first 256B of
1707 * real memory, which are reserved for software use.
1708 * The remainder of the first page is loaded with the fixed
1709 * interrupt vectors. The next two pages are filled with
1710 * unknown exception placeholders.
1712 * Note: This process overwrites the OF exception vectors.
1713 * r26 == relocation offset
1718 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1720 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1722 // XXX FIXME: Use phys returned by OF (r30)
1723 add r4,r27,r26 /* source addr */
1724 /* current address of _start */
1725 /* i.e. where we are running */
1726 /* the source addr */
1728 cmpdi r4,0 /* In some cases the loader may */
1729 beq .start_here_multiplatform /* have already put us at zero */
1730 /* so we can skip the copy. */
1731 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1734 li r6,0x100 /* Start offset, the first 0x100 */
1735 /* bytes were copied earlier. */
1737 bl .copy_and_flush /* copy the first n bytes */
1738 /* this includes the code being */
1739 /* executed here. */
1741 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1742 mtctr r0 /* that we just made/relocated */
1745 4: LOAD_REG_IMMEDIATE(r5,klimit)
1747 ld r5,0(r5) /* get the value of klimit */
1749 bl .copy_and_flush /* copy the rest */
1750 b .start_here_multiplatform
1752 #endif /* CONFIG_PPC_MULTIPLATFORM */
1755 * Copy routine used to copy the kernel to start at physical address 0
1756 * and flush and invalidate the caches as needed.
1757 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1758 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1760 * Note: this routine *only* clobbers r0, r6 and lr
1762 _GLOBAL(copy_and_flush)
1765 4: li r0,8 /* Use the smallest common */
1766 /* denominator cache line */
1767 /* size. This results in */
1768 /* extra cache line flushes */
1769 /* but operation is correct. */
1770 /* Can't get cache line size */
1771 /* from NACA as it is being */
1774 mtctr r0 /* put # words/line in ctr */
1775 3: addi r6,r6,8 /* copy a cache line */
1779 dcbst r6,r3 /* write it to memory */
1781 icbi r6,r3 /* flush the icache line */
1793 #ifdef CONFIG_PPC_PMAC
1795 * On PowerMac, secondary processors starts from the reset vector, which
1796 * is temporarily turned into a call to one of the functions below.
1801 .globl __secondary_start_pmac_0
1802 __secondary_start_pmac_0:
1803 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1813 _GLOBAL(pmac_secondary_start)
1814 /* turn on 64-bit mode */
1818 /* Copy some CPU settings from CPU 0 */
1819 bl .__restore_cpu_ppc970
1821 /* pSeries do that early though I don't think we really need it */
1824 mtmsrd r3 /* RI on */
1826 /* Set up a paca value for this processor. */
1827 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1828 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1829 add r13,r13,r4 /* for this processor. */
1830 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1832 /* Create a temp kernel stack for use before relocation is on. */
1833 ld r1,PACAEMERGSP(r13)
1834 subi r1,r1,STACK_FRAME_OVERHEAD
1836 b .__secondary_start
1838 #endif /* CONFIG_PPC_PMAC */
1841 * This function is called after the master CPU has released the
1842 * secondary processors. The execution environment is relocation off.
1843 * The paca for this processor has the following fields initialized at
1845 * 1. Processor number
1846 * 2. Segment table pointer (virtual address)
1847 * On entry the following are set:
1848 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1849 * r24 = cpu# (in Linux terms)
1850 * r13 = paca virtual address
1851 * SPRG3 = paca virtual address
1853 _GLOBAL(__secondary_start)
1854 /* Set thread priority to MEDIUM */
1860 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1861 bl .early_setup_secondary
1863 /* Initialize the kernel stack. Just a repeat for iSeries. */
1864 LOAD_REG_ADDR(r3, current_set)
1865 sldi r28,r24,3 /* get current_set[cpu#] */
1867 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1868 std r1,PACAKSAVE(r13)
1870 /* Clear backchain so we get nice backtraces */
1874 /* enable MMU and jump to start_secondary */
1875 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1876 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1877 #ifdef DO_SOFT_DISABLE
1878 BEGIN_FW_FTR_SECTION
1880 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1885 b . /* prevent speculative execution */
1888 * Running with relocation on at this point. All we want to do is
1889 * zero the stack back-chain pointer before going into C code.
1891 _GLOBAL(start_secondary_prolog)
1893 std r3,0(r1) /* Zero the stack frame pointer */
1899 * This subroutine clobbers r11 and r12
1901 _GLOBAL(enable_64b_mode)
1902 mfmsr r11 /* grab the current MSR */
1904 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1907 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1913 #ifdef CONFIG_PPC_MULTIPLATFORM
1915 * This is where the main kernel code starts.
1917 _STATIC(start_here_multiplatform)
1918 /* get a new offset, now that the kernel has moved. */
1922 /* Clear out the BSS. It may have been done in prom_init,
1923 * already but that's irrelevant since prom_init will soon
1924 * be detached from the kernel completely. Besides, we need
1925 * to clear it now for kexec-style entry.
1927 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1928 LOAD_REG_IMMEDIATE(r8,__bss_start)
1929 sub r11,r11,r8 /* bss size */
1930 addi r11,r11,7 /* round up to an even double word */
1931 rldicl. r11,r11,61,3 /* shift right by 3 */
1935 mtctr r11 /* zero this many doublewords */
1942 mtmsrd r6 /* RI on */
1944 /* The following gets the stack and TOC set up with the regs */
1945 /* pointing to the real addr of the kernel stack. This is */
1946 /* all done to support the C function call below which sets */
1947 /* up the htab. This is done because we have relocated the */
1948 /* kernel but are still running in real mode. */
1950 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1953 /* set up a stack pointer (physical address) */
1954 addi r1,r3,THREAD_SIZE
1956 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1958 /* set up the TOC (physical address) */
1959 LOAD_REG_IMMEDIATE(r2,__toc_start)
1964 /* Do very early kernel initializations, including initial hash table,
1965 * stab and slb setup before we turn on relocation. */
1967 /* Restore parameters passed from prom_init/kexec */
1971 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1972 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1976 b . /* prevent speculative execution */
1977 #endif /* CONFIG_PPC_MULTIPLATFORM */
1979 /* This is where all platforms converge execution */
1980 _STATIC(start_here_common)
1981 /* relocation is on at this point */
1983 /* The following code sets up the SP and TOC now that we are */
1984 /* running with translation enabled. */
1986 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1988 /* set up the stack */
1989 addi r1,r3,THREAD_SIZE
1991 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1993 /* ptr to current */
1994 LOAD_REG_IMMEDIATE(r4, init_task)
1995 std r4,PACACURRENT(r13)
1999 std r1,PACAKSAVE(r13)
2003 /* Load up the kernel context */
2005 #ifdef DO_SOFT_DISABLE
2006 BEGIN_FW_FTR_SECTION
2008 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
2010 ori r5,r5,MSR_EE /* Hard Enabled */
2012 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
2021 * We put a few things here that have to be page-aligned.
2022 * This stuff goes at the beginning of the bss, which is page-aligned.
2028 .globl empty_zero_page
2032 .globl swapper_pg_dir
2037 * This space gets a copy of optional info passed to us by the bootstrap
2038 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2042 .space COMMAND_LINE_SIZE