3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
15 * This file contains the low-level support and setup for the
16 * PowerPC-64 platform, including trap and interrupt dispatch.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
24 #include <linux/threads.h>
28 #include <asm/ppc_asm.h>
29 #include <asm/asm-offsets.h>
31 #include <asm/cputable.h>
32 #include <asm/setup.h>
33 #include <asm/hvcall.h>
34 #include <asm/iseries/lpar_map.h>
35 #include <asm/thread_info.h>
37 #ifdef CONFIG_PPC_ISERIES
38 #define DO_SOFT_DISABLE
42 * We layout physical memory as follows:
43 * 0x0000 - 0x00ff : Secondary processor spin code
44 * 0x0100 - 0x2fff : pSeries Interrupt prologs
45 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
46 * 0x6000 - 0x6fff : Initial (CPU0) segment table
47 * 0x7000 - 0x7fff : FWNMI data area
48 * 0x8000 - : Early init and support code
56 * SPRG0 reserved for hypervisor
57 * SPRG1 temp - used to save gpr
58 * SPRG2 temp - used to save gpr
59 * SPRG3 virt addr of paca
63 * Entering into this code we make the following assumptions:
65 * 1. The MMU is off & open firmware is running in real mode.
66 * 2. The kernel is entered at __start
69 * 1. The MMU is on (as it always is for iSeries)
70 * 2. The kernel is entered at system_reset_iSeries
76 #ifdef CONFIG_PPC_MULTIPLATFORM
78 /* NOP this out unconditionally */
80 b .__start_initialization_multiplatform
82 #endif /* CONFIG_PPC_MULTIPLATFORM */
84 /* Catch branch to 0 in real mode */
87 /* Secondary processors spin on this value until it goes to 1. */
88 .globl __secondary_hold_spinloop
89 __secondary_hold_spinloop:
92 /* Secondary processors write this value with their cpu # */
93 /* after they enter the spin loop immediately below. */
94 .globl __secondary_hold_acknowledge
95 __secondary_hold_acknowledge:
98 #ifdef CONFIG_PPC_ISERIES
100 * At offset 0x20, there is a pointer to iSeries LPAR data.
101 * This is required by the hypervisor
104 .llong hvReleaseData-KERNELBASE
105 #endif /* CONFIG_PPC_ISERIES */
109 * The following code is used on pSeries to hold secondary processors
110 * in a spin loop after they have been freed from OpenFirmware, but
111 * before the bulk of the kernel has been relocated. This code
112 * is relocated to physical address 0x60 before prom_init is run.
113 * All of it must fit below the first exception vector at 0x100.
115 _GLOBAL(__secondary_hold)
118 mtmsrd r24 /* RI on */
120 /* Grab our physical cpu number */
123 /* Tell the master cpu we're here */
124 /* Relocation is off & we are located at an address less */
125 /* than 0x100, so only need to grab low order offset. */
126 std r24,__secondary_hold_acknowledge@l(0)
129 /* All secondary cpus wait here until told to start. */
130 100: ld r4,__secondary_hold_spinloop@l(0)
134 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
135 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
143 /* This value is used to mark exception frames on the stack. */
146 .tc ID_72656773_68657265[TC],0x7265677368657265
150 * The following macros define the code that appears as
151 * the prologue to each of the exception handlers. They
152 * are split into two parts to allow a single kernel binary
153 * to be used for pSeries and iSeries.
154 * LOL. One day... - paulus
158 * We make as much of the exception code common between native
159 * exception handlers (including pSeries LPAR) and iSeries LPAR
160 * implementations as possible.
164 * This is the start of the interrupt handlers for pSeries
165 * This code runs with relocation off.
180 * We're short on space and time in the exception prolog, so we can't
181 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
182 * low halfword of the address, but for Kdump we need the whole low
185 #ifdef CONFIG_CRASH_DUMP
186 #define LOAD_HANDLER(reg, label) \
187 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
188 ori reg,reg,(label)@l; /* .. and the rest */
190 #define LOAD_HANDLER(reg, label) \
191 ori reg,reg,(label)@l; /* virt addr of handler ... */
195 * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode.
196 * The firmware calls the registered system_reset_fwnmi and
197 * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run
198 * a 32bit application at the time of the event.
199 * This firmware bug is present on POWER4 and JS20.
201 #define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \
202 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
203 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
204 std r10,area+EX_R10(r13); \
205 std r11,area+EX_R11(r13); \
206 std r12,area+EX_R12(r13); \
207 mfspr r9,SPRN_SPRG1; \
208 std r9,area+EX_R13(r13); \
210 clrrdi r12,r13,32; /* get high part of &label */ \
212 /* force 64bit mode */ \
213 li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \
214 rldimi r10,r11,61,0; /* insert into top 3 bits */ \
215 /* done 64bit mode */ \
216 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
217 LOAD_HANDLER(r12,label) \
218 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
219 mtspr SPRN_SRR0,r12; \
220 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
221 mtspr SPRN_SRR1,r10; \
223 b . /* prevent speculative execution */
225 #define EXCEPTION_PROLOG_PSERIES(area, label) \
226 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
227 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
228 std r10,area+EX_R10(r13); \
229 std r11,area+EX_R11(r13); \
230 std r12,area+EX_R12(r13); \
231 mfspr r9,SPRN_SPRG1; \
232 std r9,area+EX_R13(r13); \
234 clrrdi r12,r13,32; /* get high part of &label */ \
236 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
237 LOAD_HANDLER(r12,label) \
238 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
239 mtspr SPRN_SRR0,r12; \
240 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
241 mtspr SPRN_SRR1,r10; \
243 b . /* prevent speculative execution */
246 * This is the start of the interrupt handlers for iSeries
247 * This code runs with relocation on.
249 #define EXCEPTION_PROLOG_ISERIES_1(area) \
250 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
251 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
252 std r10,area+EX_R10(r13); \
253 std r11,area+EX_R11(r13); \
254 std r12,area+EX_R12(r13); \
255 mfspr r9,SPRN_SPRG1; \
256 std r9,area+EX_R13(r13); \
259 #define EXCEPTION_PROLOG_ISERIES_2 \
261 ld r12,PACALPPACAPTR(r13); \
262 ld r11,LPPACASRR0(r12); \
263 ld r12,LPPACASRR1(r12); \
264 ori r10,r10,MSR_RI; \
268 * The common exception prolog is used for all except a few exceptions
269 * such as a segment miss on a kernel address. We have to be prepared
270 * to take another exception from the point where we first touch the
271 * kernel stack onwards.
273 * On entry r13 points to the paca, r9-r13 are saved in the paca,
274 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
275 * SRR1, and relocation is on.
277 #define EXCEPTION_PROLOG_COMMON(n, area) \
278 andi. r10,r12,MSR_PR; /* See if coming from user */ \
279 mr r10,r1; /* Save r1 */ \
280 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
282 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
283 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
284 bge- cr1,bad_stack; /* abort if it is */ \
285 std r9,_CCR(r1); /* save CR in stackframe */ \
286 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
287 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
288 std r10,0(r1); /* make stack chain pointer */ \
289 std r0,GPR0(r1); /* save r0 in stackframe */ \
290 std r10,GPR1(r1); /* save r1 in stackframe */ \
291 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
292 std r2,GPR2(r1); /* save r2 in stackframe */ \
293 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
294 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
295 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
296 ld r10,area+EX_R10(r13); \
299 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
300 ld r10,area+EX_R12(r13); \
301 ld r11,area+EX_R13(r13); \
305 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
306 mflr r9; /* save LR in stackframe */ \
308 mfctr r10; /* save CTR in stackframe */ \
310 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
313 std r9,_TRAP(r1); /* set trap number */ \
315 ld r11,exception_marker@toc(r2); \
316 std r10,RESULT(r1); /* clear regs->result */ \
317 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
322 #define STD_EXCEPTION_PSERIES(n, label) \
324 .globl label##_pSeries; \
327 mtspr SPRN_SPRG1,r13; /* save r13 */ \
328 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
330 #define HSTD_EXCEPTION_PSERIES(n, label) \
332 .globl label##_pSeries; \
335 mtspr SPRN_SPRG1,r20; /* save r20 */ \
336 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
337 mtspr SPRN_SRR0,r20; \
338 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
339 mtspr SPRN_SRR1,r20; \
340 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
341 mtspr SPRN_SPRG1,r13; /* save r13 */ \
342 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
345 #define STD_EXCEPTION_ISERIES(n, label, area) \
346 .globl label##_iSeries; \
349 mtspr SPRN_SPRG1,r13; /* save r13 */ \
350 EXCEPTION_PROLOG_ISERIES_1(area); \
351 EXCEPTION_PROLOG_ISERIES_2; \
354 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
355 .globl label##_iSeries; \
358 mtspr SPRN_SPRG1,r13; /* save r13 */ \
359 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
360 lbz r10,PACAPROCENABLED(r13); \
362 beq- label##_iSeries_masked; \
363 EXCEPTION_PROLOG_ISERIES_2; \
366 #ifdef DO_SOFT_DISABLE
367 #define DISABLE_INTS \
368 lbz r10,PACAPROCENABLED(r13); \
372 stb r11,PACAPROCENABLED(r13); \
373 ori r10,r10,MSR_EE; \
376 #define ENABLE_INTS \
377 lbz r10,PACAPROCENABLED(r13); \
380 ori r11,r11,MSR_EE; \
383 #else /* hard enable/disable interrupts */
386 #define ENABLE_INTS \
389 rlwimi r11,r12,0,MSR_EE; \
394 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
396 .globl label##_common; \
398 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
401 addi r3,r1,STACK_FRAME_OVERHEAD; \
406 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
407 * in the idle task and therefore need the special idle handling.
409 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
411 .globl label##_common; \
413 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
417 addi r3,r1,STACK_FRAME_OVERHEAD; \
421 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
423 .globl label##_common; \
425 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
428 bl .ppc64_runlatch_on; \
429 addi r3,r1,STACK_FRAME_OVERHEAD; \
431 b .ret_from_except_lite
434 * When the idle code in power4_idle puts the CPU into NAP mode,
435 * it has to do so in a loop, and relies on the external interrupt
436 * and decrementer interrupt entry code to get it out of the loop.
437 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
438 * to signal that it is in the loop and needs help to get out.
440 #ifdef CONFIG_PPC_970_NAP
443 clrrdi r11,r1,THREAD_SHIFT; \
444 ld r9,TI_LOCAL_FLAGS(r11); \
445 andi. r10,r9,_TLF_NAPPING; \
446 bnel power4_fixup_nap; \
447 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
453 * Start of pSeries system interrupt routines
456 .globl __start_interrupts
459 STD_EXCEPTION_PSERIES(0x100, system_reset)
462 _machine_check_pSeries:
464 mtspr SPRN_SPRG1,r13 /* save r13 */
465 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
468 .globl data_access_pSeries
477 rlwimi r13,r12,16,0x20
480 beq .do_stab_bolted_pSeries
483 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
484 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
487 .globl data_access_slb_pSeries
488 data_access_slb_pSeries:
491 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
492 std r3,PACA_EXSLB+EX_R3(r13)
494 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
497 /* Keep that around for when we re-implement dynamic VSIDs */
499 bge slb_miss_user_pseries
500 #endif /* __DISABLED__ */
501 std r10,PACA_EXSLB+EX_R10(r13)
502 std r11,PACA_EXSLB+EX_R11(r13)
503 std r12,PACA_EXSLB+EX_R12(r13)
505 std r10,PACA_EXSLB+EX_R13(r13)
506 mfspr r12,SPRN_SRR1 /* and SRR1 */
507 b .slb_miss_realmode /* Rel. branch works in real mode */
509 STD_EXCEPTION_PSERIES(0x400, instruction_access)
512 .globl instruction_access_slb_pSeries
513 instruction_access_slb_pSeries:
516 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
517 std r3,PACA_EXSLB+EX_R3(r13)
518 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
519 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
522 /* Keep that around for when we re-implement dynamic VSIDs */
524 bge slb_miss_user_pseries
525 #endif /* __DISABLED__ */
526 std r10,PACA_EXSLB+EX_R10(r13)
527 std r11,PACA_EXSLB+EX_R11(r13)
528 std r12,PACA_EXSLB+EX_R12(r13)
530 std r10,PACA_EXSLB+EX_R13(r13)
531 mfspr r12,SPRN_SRR1 /* and SRR1 */
532 b .slb_miss_realmode /* Rel. branch works in real mode */
534 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
535 STD_EXCEPTION_PSERIES(0x600, alignment)
536 STD_EXCEPTION_PSERIES(0x700, program_check)
537 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
538 STD_EXCEPTION_PSERIES(0x900, decrementer)
539 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
540 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
543 .globl system_call_pSeries
551 oris r12,r12,system_call_common@h
552 ori r12,r12,system_call_common@l
554 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
558 b . /* prevent speculative execution */
560 STD_EXCEPTION_PSERIES(0xd00, single_step)
561 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
563 /* We need to deal with the Altivec unavailable exception
564 * here which is at 0xf20, thus in the middle of the
565 * prolog code of the PerformanceMonitor one. A little
566 * trickery is thus necessary
569 b performance_monitor_pSeries
571 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
573 #ifdef CONFIG_CBE_RAS
574 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
575 #endif /* CONFIG_CBE_RAS */
576 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
577 #ifdef CONFIG_CBE_RAS
578 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
579 #endif /* CONFIG_CBE_RAS */
580 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
581 #ifdef CONFIG_CBE_RAS
582 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
583 #endif /* CONFIG_CBE_RAS */
587 /*** pSeries interrupt support ***/
589 /* moved from 0xf00 */
590 STD_EXCEPTION_PSERIES(., performance_monitor)
593 _GLOBAL(do_stab_bolted_pSeries)
596 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
599 * We have some room here we use that to put
600 * the peries slb miss user trampoline code so it's reasonably
601 * away from slb_miss_user_common to avoid problems with rfid
603 * This is used for when the SLB miss handler has to go virtual,
604 * which doesn't happen for now anymore but will once we re-implement
605 * dynamic VSIDs for shared page tables
608 slb_miss_user_pseries:
609 std r10,PACA_EXGEN+EX_R10(r13)
610 std r11,PACA_EXGEN+EX_R11(r13)
611 std r12,PACA_EXGEN+EX_R12(r13)
613 ld r11,PACA_EXSLB+EX_R9(r13)
614 ld r12,PACA_EXSLB+EX_R3(r13)
615 std r10,PACA_EXGEN+EX_R13(r13)
616 std r11,PACA_EXGEN+EX_R9(r13)
617 std r12,PACA_EXGEN+EX_R3(r13)
620 mfspr r11,SRR0 /* save SRR0 */
621 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
622 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
624 mfspr r12,SRR1 /* and SRR1 */
627 b . /* prevent spec. execution */
628 #endif /* __DISABLED__ */
631 * Vectors for the FWNMI option. Share common code.
633 .globl system_reset_fwnmi
637 mtspr SPRN_SPRG1,r13 /* save r13 */
638 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
640 .globl machine_check_fwnmi
644 mtspr SPRN_SPRG1,r13 /* save r13 */
645 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
647 #ifdef CONFIG_PPC_ISERIES
648 /*** ISeries-LPAR interrupt handlers ***/
650 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
652 .globl data_access_iSeries
660 rlwimi r13,r12,16,0x20
663 beq .do_stab_bolted_iSeries
666 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
667 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
668 EXCEPTION_PROLOG_ISERIES_2
671 .do_stab_bolted_iSeries:
674 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
675 EXCEPTION_PROLOG_ISERIES_2
678 .globl data_access_slb_iSeries
679 data_access_slb_iSeries:
680 mtspr SPRN_SPRG1,r13 /* save r13 */
681 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
682 std r3,PACA_EXSLB+EX_R3(r13)
684 std r9,PACA_EXSLB+EX_R9(r13)
688 bge slb_miss_user_iseries
690 std r10,PACA_EXSLB+EX_R10(r13)
691 std r11,PACA_EXSLB+EX_R11(r13)
692 std r12,PACA_EXSLB+EX_R12(r13)
694 std r10,PACA_EXSLB+EX_R13(r13)
695 ld r12,PACALPPACAPTR(r13)
696 ld r12,LPPACASRR1(r12)
699 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
701 .globl instruction_access_slb_iSeries
702 instruction_access_slb_iSeries:
703 mtspr SPRN_SPRG1,r13 /* save r13 */
704 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
705 std r3,PACA_EXSLB+EX_R3(r13)
706 ld r3,PACALPPACAPTR(r13)
707 ld r3,LPPACASRR0(r3) /* get SRR0 value */
708 std r9,PACA_EXSLB+EX_R9(r13)
712 bge .slb_miss_user_iseries
714 std r10,PACA_EXSLB+EX_R10(r13)
715 std r11,PACA_EXSLB+EX_R11(r13)
716 std r12,PACA_EXSLB+EX_R12(r13)
718 std r10,PACA_EXSLB+EX_R13(r13)
719 ld r12,PACALPPACAPTR(r13)
720 ld r12,LPPACASRR1(r12)
724 slb_miss_user_iseries:
725 std r10,PACA_EXGEN+EX_R10(r13)
726 std r11,PACA_EXGEN+EX_R11(r13)
727 std r12,PACA_EXGEN+EX_R12(r13)
729 ld r11,PACA_EXSLB+EX_R9(r13)
730 ld r12,PACA_EXSLB+EX_R3(r13)
731 std r10,PACA_EXGEN+EX_R13(r13)
732 std r11,PACA_EXGEN+EX_R9(r13)
733 std r12,PACA_EXGEN+EX_R3(r13)
734 EXCEPTION_PROLOG_ISERIES_2
735 b slb_miss_user_common
738 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
739 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
740 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
741 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
742 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
743 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
744 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
746 .globl system_call_iSeries
750 EXCEPTION_PROLOG_ISERIES_2
753 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
754 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
755 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
757 .globl system_reset_iSeries
758 system_reset_iSeries:
759 mfspr r13,SPRN_SPRG3 /* Get paca address */
762 mtmsrd r24 /* RI on */
763 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
764 cmpwi 0,r24,0 /* Are we processor 0? */
765 beq .__start_initialization_iSeries /* Start up the first processor */
767 li r5,CTRL_RUNLATCH /* Turn off the run light */
774 lbz r23,PACAPROCSTART(r13) /* Test if this processor
777 LOAD_REG_IMMEDIATE(r3,current_set)
778 sldi r28,r24,3 /* get current_set[cpu#] */
780 addi r1,r3,THREAD_SIZE
781 subi r1,r1,STACK_FRAME_OVERHEAD
784 beq iSeries_secondary_smp_loop /* Loop until told to go */
785 bne .__secondary_start /* Loop until told to go */
786 iSeries_secondary_smp_loop:
787 /* Let the Hypervisor know we are alive */
788 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
790 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
791 #else /* CONFIG_SMP */
792 /* Yield the processor. This is required for non-SMP kernels
793 which are running on multi-threaded machines. */
795 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
796 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
797 li r4,0 /* "yield timed" */
798 li r5,-1 /* "yield forever" */
799 #endif /* CONFIG_SMP */
800 li r0,-1 /* r0=-1 indicates a Hypervisor call */
801 sc /* Invoke the hypervisor via a system call */
802 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
803 b 1b /* If SMP not configured, secondaries
806 .globl decrementer_iSeries_masked
807 decrementer_iSeries_masked:
808 /* We may not have a valid TOC pointer in here. */
810 ld r12,PACALPPACAPTR(r13)
811 stb r11,LPPACADECRINT(r12)
812 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
817 .globl hardware_interrupt_iSeries_masked
818 hardware_interrupt_iSeries_masked:
819 mtcrf 0x80,r9 /* Restore regs */
820 ld r12,PACALPPACAPTR(r13)
821 ld r11,LPPACASRR0(r12)
822 ld r12,LPPACASRR1(r12)
825 ld r9,PACA_EXGEN+EX_R9(r13)
826 ld r10,PACA_EXGEN+EX_R10(r13)
827 ld r11,PACA_EXGEN+EX_R11(r13)
828 ld r12,PACA_EXGEN+EX_R12(r13)
829 ld r13,PACA_EXGEN+EX_R13(r13)
831 b . /* prevent speculative execution */
832 #endif /* CONFIG_PPC_ISERIES */
834 /*** Common interrupt handlers ***/
836 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
839 * Machine check is different because we use a different
840 * save area: PACA_EXMC instead of PACA_EXGEN.
843 .globl machine_check_common
844 machine_check_common:
845 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
849 addi r3,r1,STACK_FRAME_OVERHEAD
850 bl .machine_check_exception
853 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
854 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
855 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
856 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
857 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
858 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
859 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
860 #ifdef CONFIG_ALTIVEC
861 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
863 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
865 #ifdef CONFIG_CBE_RAS
866 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
867 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
868 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
869 #endif /* CONFIG_CBE_RAS */
872 * Here we have detected that the kernel stack pointer is bad.
873 * R9 contains the saved CR, r13 points to the paca,
874 * r10 contains the (bad) kernel stack pointer,
875 * r11 and r12 contain the saved SRR0 and SRR1.
876 * We switch to using an emergency stack, save the registers there,
877 * and call kernel_bad_stack(), which panics.
880 ld r1,PACAEMERGSP(r13)
881 subi r1,r1,64+INT_FRAME_SIZE
902 addi r11,r1,INT_FRAME_SIZE
907 1: addi r3,r1,STACK_FRAME_OVERHEAD
912 * Return from an exception with minimal checks.
913 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
914 * If interrupts have been enabled, or anything has been
915 * done that might have changed the scheduling status of
916 * any task or sent any task a signal, you should use
917 * ret_from_except or ret_from_except_lite instead of this.
919 .globl fast_exception_return
920 fast_exception_return:
923 andi. r3,r12,MSR_RI /* check if RI is set */
926 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
929 ACCOUNT_CPU_USER_EXIT(r3, r4)
945 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
953 b . /* prevent speculative execution */
957 1: addi r3,r1,STACK_FRAME_OVERHEAD
958 bl .unrecoverable_exception
962 * Here r13 points to the paca, r9 contains the saved CR,
963 * SRR0 and SRR1 are saved in r11 and r12,
964 * r9 - r13 are saved in paca->exgen.
967 .globl data_access_common
970 std r10,PACA_EXGEN+EX_DAR(r13)
972 stw r10,PACA_EXGEN+EX_DSISR(r13)
973 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
974 ld r3,PACA_EXGEN+EX_DAR(r13)
975 lwz r4,PACA_EXGEN+EX_DSISR(r13)
977 b .do_hash_page /* Try to handle as hpte fault */
980 .globl instruction_access_common
981 instruction_access_common:
982 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
986 b .do_hash_page /* Try to handle as hpte fault */
989 * Here is the common SLB miss user that is used when going to virtual
990 * mode for SLB misses, that is currently not used
994 .globl slb_miss_user_common
995 slb_miss_user_common:
997 std r3,PACA_EXGEN+EX_DAR(r13)
998 stw r9,PACA_EXGEN+EX_CCR(r13)
999 std r10,PACA_EXGEN+EX_LR(r13)
1000 std r11,PACA_EXGEN+EX_SRR0(r13)
1001 bl .slb_allocate_user
1003 ld r10,PACA_EXGEN+EX_LR(r13)
1004 ld r3,PACA_EXGEN+EX_R3(r13)
1005 lwz r9,PACA_EXGEN+EX_CCR(r13)
1006 ld r11,PACA_EXGEN+EX_SRR0(r13)
1010 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1011 beq- unrecov_user_slb
1019 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1025 ld r9,PACA_EXGEN+EX_R9(r13)
1026 ld r10,PACA_EXGEN+EX_R10(r13)
1027 ld r11,PACA_EXGEN+EX_R11(r13)
1028 ld r12,PACA_EXGEN+EX_R12(r13)
1029 ld r13,PACA_EXGEN+EX_R13(r13)
1034 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1035 ld r4,PACA_EXGEN+EX_DAR(r13)
1039 b .handle_page_fault
1042 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1045 1: addi r3,r1,STACK_FRAME_OVERHEAD
1046 bl .unrecoverable_exception
1049 #endif /* __DISABLED__ */
1053 * r13 points to the PACA, r9 contains the saved CR,
1054 * r12 contain the saved SRR1, SRR0 is still ready for return
1055 * r3 has the faulting address
1056 * r9 - r13 are saved in paca->exslb.
1057 * r3 is saved in paca->slb_r3
1058 * We assume we aren't going to take any exceptions during this procedure.
1060 _GLOBAL(slb_miss_realmode)
1063 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1064 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1066 bl .slb_allocate_realmode
1068 /* All done -- return from exception. */
1070 ld r10,PACA_EXSLB+EX_LR(r13)
1071 ld r3,PACA_EXSLB+EX_R3(r13)
1072 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1073 #ifdef CONFIG_PPC_ISERIES
1074 ld r11,PACALPPACAPTR(r13)
1075 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1076 #endif /* CONFIG_PPC_ISERIES */
1080 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1086 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1089 #ifdef CONFIG_PPC_ISERIES
1092 #endif /* CONFIG_PPC_ISERIES */
1093 ld r9,PACA_EXSLB+EX_R9(r13)
1094 ld r10,PACA_EXSLB+EX_R10(r13)
1095 ld r11,PACA_EXSLB+EX_R11(r13)
1096 ld r12,PACA_EXSLB+EX_R12(r13)
1097 ld r13,PACA_EXSLB+EX_R13(r13)
1099 b . /* prevent speculative execution */
1102 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1105 1: addi r3,r1,STACK_FRAME_OVERHEAD
1106 bl .unrecoverable_exception
1110 .globl hardware_interrupt_common
1111 .globl hardware_interrupt_entry
1112 hardware_interrupt_common:
1113 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1115 hardware_interrupt_entry:
1117 bl .ppc64_runlatch_on
1118 addi r3,r1,STACK_FRAME_OVERHEAD
1120 b .ret_from_except_lite
1122 #ifdef CONFIG_PPC_970_NAP
1125 std r9,TI_LOCAL_FLAGS(r11)
1126 ld r10,_LINK(r1) /* make idle task do the */
1127 std r10,_NIP(r1) /* equivalent of a blr */
1132 .globl alignment_common
1135 std r10,PACA_EXGEN+EX_DAR(r13)
1136 mfspr r10,SPRN_DSISR
1137 stw r10,PACA_EXGEN+EX_DSISR(r13)
1138 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1139 ld r3,PACA_EXGEN+EX_DAR(r13)
1140 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1144 addi r3,r1,STACK_FRAME_OVERHEAD
1146 bl .alignment_exception
1150 .globl program_check_common
1151 program_check_common:
1152 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1154 addi r3,r1,STACK_FRAME_OVERHEAD
1156 bl .program_check_exception
1160 .globl fp_unavailable_common
1161 fp_unavailable_common:
1162 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1163 bne .load_up_fpu /* if from user, just load it up */
1165 addi r3,r1,STACK_FRAME_OVERHEAD
1167 bl .kernel_fp_unavailable_exception
1171 .globl altivec_unavailable_common
1172 altivec_unavailable_common:
1173 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1174 #ifdef CONFIG_ALTIVEC
1176 bne .load_up_altivec /* if from user, just load it up */
1177 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1180 addi r3,r1,STACK_FRAME_OVERHEAD
1182 bl .altivec_unavailable_exception
1185 #ifdef CONFIG_ALTIVEC
1187 * load_up_altivec(unused, unused, tsk)
1188 * Disable VMX for the task which had it previously,
1189 * and save its vector registers in its thread_struct.
1190 * Enables the VMX for use in the kernel on return.
1191 * On SMP we know the VMX is free, since we give it up every
1192 * switch (ie, no lazy save of the vector registers).
1193 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1195 _STATIC(load_up_altivec)
1196 mfmsr r5 /* grab the current MSR */
1197 oris r5,r5,MSR_VEC@h
1198 mtmsrd r5 /* enable use of VMX now */
1202 * For SMP, we don't do lazy VMX switching because it just gets too
1203 * horrendously complex, especially when a task switches from one CPU
1204 * to another. Instead we call giveup_altvec in switch_to.
1205 * VRSAVE isn't dealt with here, that is done in the normal context
1206 * switch code. Note that we could rely on vrsave value to eventually
1207 * avoid saving all of the VREGs here...
1210 ld r3,last_task_used_altivec@got(r2)
1214 /* Save VMX state to last_task_used_altivec's THREAD struct */
1220 /* Disable VMX for last_task_used_altivec */
1222 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1225 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1227 #endif /* CONFIG_SMP */
1228 /* Hack: if we get an altivec unavailable trap with VRSAVE
1229 * set to all zeros, we assume this is a broken application
1230 * that fails to set it properly, and thus we switch it to
1233 mfspr r4,SPRN_VRSAVE
1237 mtspr SPRN_VRSAVE,r4
1239 /* enable use of VMX after return */
1240 ld r4,PACACURRENT(r13)
1241 addi r5,r4,THREAD /* Get THREAD */
1242 oris r12,r12,MSR_VEC@h
1246 stw r4,THREAD_USED_VR(r5)
1251 /* Update last_task_used_math to 'current' */
1252 subi r4,r5,THREAD /* Back to 'current' */
1254 #endif /* CONFIG_SMP */
1255 /* restore registers and return */
1256 b fast_exception_return
1257 #endif /* CONFIG_ALTIVEC */
1263 _GLOBAL(do_hash_page)
1267 andis. r0,r4,0xa450 /* weird error? */
1268 bne- .handle_page_fault /* if not, try to insert a HPTE */
1270 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1271 bne- .do_ste_alloc /* If so handle it */
1272 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1275 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1276 * accessing a userspace segment (even from the kernel). We assume
1277 * kernel addresses always have the high bit set.
1279 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1280 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1281 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1282 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1283 ori r4,r4,1 /* add _PAGE_PRESENT */
1284 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1287 * On iSeries, we soft-disable interrupts here, then
1288 * hard-enable interrupts so that the hash_page code can spin on
1289 * the hash_table_lock without problems on a shared processor.
1294 * r3 contains the faulting address
1295 * r4 contains the required access permissions
1296 * r5 contains the trap number
1298 * at return r3 = 0 for success
1300 bl .hash_page /* build HPTE if possible */
1301 cmpdi r3,0 /* see if hash_page succeeded */
1303 #ifdef DO_SOFT_DISABLE
1305 * If we had interrupts soft-enabled at the point where the
1306 * DSI/ISI occurred, and an interrupt came in during hash_page,
1308 * We jump to ret_from_except_lite rather than fast_exception_return
1309 * because ret_from_except_lite will check for and handle pending
1310 * interrupts if necessary.
1312 beq .ret_from_except_lite
1313 /* For a hash failure, we don't bother re-enabling interrupts */
1317 * hash_page couldn't handle it, set soft interrupt enable back
1318 * to what it was before the trap. Note that .local_irq_restore
1319 * handles any interrupts pending at this point.
1322 bl .local_irq_restore
1325 beq fast_exception_return /* Return from exception on success */
1326 ble- 12f /* Failure return from hash_page */
1331 /* Here we have a page fault that hash_page can't handle. */
1332 _GLOBAL(handle_page_fault)
1336 addi r3,r1,STACK_FRAME_OVERHEAD
1339 beq+ .ret_from_except_lite
1342 addi r3,r1,STACK_FRAME_OVERHEAD
1347 /* We have a page fault that hash_page could handle but HV refused
1351 addi r3,r1,STACK_FRAME_OVERHEAD
1356 /* here we have a segment miss */
1357 _GLOBAL(do_ste_alloc)
1358 bl .ste_allocate /* try to insert stab entry */
1360 beq+ fast_exception_return
1361 b .handle_page_fault
1364 * r13 points to the PACA, r9 contains the saved CR,
1365 * r11 and r12 contain the saved SRR0 and SRR1.
1366 * r9 - r13 are saved in paca->exslb.
1367 * We assume we aren't going to take any exceptions during this procedure.
1368 * We assume (DAR >> 60) == 0xc.
1371 _GLOBAL(do_stab_bolted)
1372 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1373 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1375 /* Hash to the primary group */
1376 ld r10,PACASTABVIRT(r13)
1379 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1381 /* Calculate VSID */
1382 /* This is a kernel address, so protovsid = ESID */
1383 ASM_VSID_SCRAMBLE(r11, r9)
1384 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1386 /* Search the primary group for a free entry */
1387 1: ld r11,0(r10) /* Test valid bit of the current ste */
1394 /* Stick for only searching the primary group for now. */
1395 /* At least for now, we use a very simple random castout scheme */
1396 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1398 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1401 /* r10 currently points to an ste one past the group of interest */
1402 /* make it point to the randomly selected entry */
1404 or r10,r10,r11 /* r10 is the entry to invalidate */
1406 isync /* mark the entry invalid */
1408 rldicl r11,r11,56,1 /* clear the valid bit */
1413 clrrdi r11,r11,28 /* Get the esid part of the ste */
1416 2: std r9,8(r10) /* Store the vsid part of the ste */
1419 mfspr r11,SPRN_DAR /* Get the new esid */
1420 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1421 ori r11,r11,0x90 /* Turn on valid and kp */
1422 std r11,0(r10) /* Put new entry back into the stab */
1426 /* All done -- return from exception. */
1427 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1428 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1430 andi. r10,r12,MSR_RI
1433 mtcrf 0x80,r9 /* restore CR */
1441 ld r9,PACA_EXSLB+EX_R9(r13)
1442 ld r10,PACA_EXSLB+EX_R10(r13)
1443 ld r11,PACA_EXSLB+EX_R11(r13)
1444 ld r12,PACA_EXSLB+EX_R12(r13)
1445 ld r13,PACA_EXSLB+EX_R13(r13)
1447 b . /* prevent speculative execution */
1450 * Space for CPU0's segment table.
1452 * On iSeries, the hypervisor must fill in at least one entry before
1453 * we get control (with relocate on). The address is give to the hv
1454 * as a page number (see xLparMap in lpardata.c), so this must be at a
1455 * fixed address (the linker can't compute (u64)&initial_stab >>
1458 . = STAB0_OFFSET /* 0x6000 */
1464 * Data area reserved for FWNMI option.
1465 * This address (0x7000) is fixed by the RPA.
1468 .globl fwnmi_data_area
1471 /* iSeries does not use the FWNMI stuff, so it is safe to put
1472 * this here, even if we later allow kernels that will boot on
1473 * both pSeries and iSeries */
1474 #ifdef CONFIG_PPC_ISERIES
1476 #include "lparmap.s"
1478 * This ".text" is here for old compilers that generate a trailing
1479 * .note section when compiling .c files to .s
1482 #endif /* CONFIG_PPC_ISERIES */
1487 * On pSeries and most other platforms, secondary processors spin
1488 * in the following code.
1489 * At entry, r3 = this processor's number (physical cpu id)
1491 _GLOBAL(generic_secondary_smp_init)
1494 /* turn on 64-bit mode */
1498 /* Set up a paca value for this processor. Since we have the
1499 * physical cpu id in r24, we need to search the pacas to find
1500 * which logical id maps to our physical one.
1502 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1503 li r5,0 /* logical cpu id */
1504 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1505 cmpw r6,r24 /* Compare to our id */
1507 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1512 mr r3,r24 /* not found, copy phys to r3 */
1513 b .kexec_wait /* next kernel might do better */
1515 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1516 /* From now on, r24 is expected to be logical cpuid */
1519 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1524 b 3b /* Never go on non-SMP */
1527 beq 3b /* Loop until told to go */
1529 /* See if we need to call a cpu state restore handler */
1530 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1532 ld r23,CPU_SPEC_RESTORE(r23)
1539 4: /* Create a temp kernel stack for use before relocation is on. */
1540 ld r1,PACAEMERGSP(r13)
1541 subi r1,r1,STACK_FRAME_OVERHEAD
1543 b .__secondary_start
1546 #ifdef CONFIG_PPC_ISERIES
1547 _STATIC(__start_initialization_iSeries)
1548 /* Clear out the BSS */
1549 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1550 LOAD_REG_IMMEDIATE(r8,__bss_start)
1551 sub r11,r11,r8 /* bss size */
1552 addi r11,r11,7 /* round up to an even double word */
1553 rldicl. r11,r11,61,3 /* shift right by 3 */
1557 mtctr r11 /* zero this many doublewords */
1561 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1562 addi r1,r1,THREAD_SIZE
1564 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1566 LOAD_REG_IMMEDIATE(r3,cpu_specs)
1567 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1571 LOAD_REG_IMMEDIATE(r2,__toc_start)
1575 bl .iSeries_early_setup
1578 /* relocation is on at this point */
1580 b .start_here_common
1581 #endif /* CONFIG_PPC_ISERIES */
1583 #ifdef CONFIG_PPC_MULTIPLATFORM
1587 andi. r0,r3,MSR_IR|MSR_DR
1594 b . /* prevent speculative execution */
1598 * Here is our main kernel entry point. We support currently 2 kind of entries
1599 * depending on the value of r5.
1601 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1604 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1605 * DT block, r4 is a physical pointer to the kernel itself
1608 _GLOBAL(__start_initialization_multiplatform)
1609 #ifdef CONFIG_PPC_MULTIPLATFORM
1611 * Are we booted from a PROM Of-type client-interface ?
1614 bne .__boot_from_prom /* yes -> prom */
1617 /* Save parameters */
1621 /* Make sure we are running in 64 bits mode */
1624 /* Setup some critical 970 SPRs before switching MMU off */
1627 cmpwi r0,0x39 /* 970 */
1629 cmpwi r0,0x3c /* 970FX */
1631 cmpwi r0,0x44 /* 970MP */
1633 1: bl .__cpu_preinit_ppc970
1636 /* Switch off MMU if not already */
1637 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1640 b .__after_prom_start
1642 #ifdef CONFIG_PPC_MULTIPLATFORM
1643 _STATIC(__boot_from_prom)
1644 /* Save parameters */
1652 * Align the stack to 16-byte boundary
1653 * Depending on the size and layout of the ELF sections in the initial
1654 * boot binary, the stack pointer will be unalignet on PowerMac
1658 /* Make sure we are running in 64 bits mode */
1661 /* put a relocation offset into r3 */
1664 LOAD_REG_IMMEDIATE(r2,__toc_start)
1668 /* Relocate the TOC from a virt addr to a real addr */
1671 /* Restore parameters */
1678 /* Do all of the interaction with OF client interface */
1680 /* We never return */
1685 * At this point, r3 contains the physical address we are running at,
1686 * returned by prom_init()
1688 _STATIC(__after_prom_start)
1691 * We need to run with __start at physical address PHYSICAL_START.
1692 * This will leave some code in the first 256B of
1693 * real memory, which are reserved for software use.
1694 * The remainder of the first page is loaded with the fixed
1695 * interrupt vectors. The next two pages are filled with
1696 * unknown exception placeholders.
1698 * Note: This process overwrites the OF exception vectors.
1699 * r26 == relocation offset
1704 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1706 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1708 // XXX FIXME: Use phys returned by OF (r30)
1709 add r4,r27,r26 /* source addr */
1710 /* current address of _start */
1711 /* i.e. where we are running */
1712 /* the source addr */
1714 cmpdi r4,0 /* In some cases the loader may */
1715 beq .start_here_multiplatform /* have already put us at zero */
1716 /* so we can skip the copy. */
1717 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1720 li r6,0x100 /* Start offset, the first 0x100 */
1721 /* bytes were copied earlier. */
1723 bl .copy_and_flush /* copy the first n bytes */
1724 /* this includes the code being */
1725 /* executed here. */
1727 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1728 mtctr r0 /* that we just made/relocated */
1731 4: LOAD_REG_IMMEDIATE(r5,klimit)
1733 ld r5,0(r5) /* get the value of klimit */
1735 bl .copy_and_flush /* copy the rest */
1736 b .start_here_multiplatform
1738 #endif /* CONFIG_PPC_MULTIPLATFORM */
1741 * Copy routine used to copy the kernel to start at physical address 0
1742 * and flush and invalidate the caches as needed.
1743 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1744 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1746 * Note: this routine *only* clobbers r0, r6 and lr
1748 _GLOBAL(copy_and_flush)
1751 4: li r0,8 /* Use the smallest common */
1752 /* denominator cache line */
1753 /* size. This results in */
1754 /* extra cache line flushes */
1755 /* but operation is correct. */
1756 /* Can't get cache line size */
1757 /* from NACA as it is being */
1760 mtctr r0 /* put # words/line in ctr */
1761 3: addi r6,r6,8 /* copy a cache line */
1765 dcbst r6,r3 /* write it to memory */
1767 icbi r6,r3 /* flush the icache line */
1779 #ifdef CONFIG_PPC_PMAC
1781 * On PowerMac, secondary processors starts from the reset vector, which
1782 * is temporarily turned into a call to one of the functions below.
1787 .globl __secondary_start_pmac_0
1788 __secondary_start_pmac_0:
1789 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1799 _GLOBAL(pmac_secondary_start)
1800 /* turn on 64-bit mode */
1804 /* Copy some CPU settings from CPU 0 */
1805 bl .__restore_cpu_ppc970
1807 /* pSeries do that early though I don't think we really need it */
1810 mtmsrd r3 /* RI on */
1812 /* Set up a paca value for this processor. */
1813 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1814 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1815 add r13,r13,r4 /* for this processor. */
1816 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1818 /* Create a temp kernel stack for use before relocation is on. */
1819 ld r1,PACAEMERGSP(r13)
1820 subi r1,r1,STACK_FRAME_OVERHEAD
1822 b .__secondary_start
1824 #endif /* CONFIG_PPC_PMAC */
1827 * This function is called after the master CPU has released the
1828 * secondary processors. The execution environment is relocation off.
1829 * The paca for this processor has the following fields initialized at
1831 * 1. Processor number
1832 * 2. Segment table pointer (virtual address)
1833 * On entry the following are set:
1834 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1835 * r24 = cpu# (in Linux terms)
1836 * r13 = paca virtual address
1837 * SPRG3 = paca virtual address
1839 _GLOBAL(__secondary_start)
1840 /* Set thread priority to MEDIUM */
1846 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1847 bl .early_setup_secondary
1849 /* Initialize the kernel stack. Just a repeat for iSeries. */
1850 LOAD_REG_ADDR(r3, current_set)
1851 sldi r28,r24,3 /* get current_set[cpu#] */
1853 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1854 std r1,PACAKSAVE(r13)
1856 /* Clear backchain so we get nice backtraces */
1860 /* enable MMU and jump to start_secondary */
1861 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1862 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1863 #ifdef DO_SOFT_DISABLE
1869 b . /* prevent speculative execution */
1872 * Running with relocation on at this point. All we want to do is
1873 * zero the stack back-chain pointer before going into C code.
1875 _GLOBAL(start_secondary_prolog)
1877 std r3,0(r1) /* Zero the stack frame pointer */
1883 * This subroutine clobbers r11 and r12
1885 _GLOBAL(enable_64b_mode)
1886 mfmsr r11 /* grab the current MSR */
1888 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1891 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1897 #ifdef CONFIG_PPC_MULTIPLATFORM
1899 * This is where the main kernel code starts.
1901 _STATIC(start_here_multiplatform)
1902 /* get a new offset, now that the kernel has moved. */
1906 /* Clear out the BSS. It may have been done in prom_init,
1907 * already but that's irrelevant since prom_init will soon
1908 * be detached from the kernel completely. Besides, we need
1909 * to clear it now for kexec-style entry.
1911 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1912 LOAD_REG_IMMEDIATE(r8,__bss_start)
1913 sub r11,r11,r8 /* bss size */
1914 addi r11,r11,7 /* round up to an even double word */
1915 rldicl. r11,r11,61,3 /* shift right by 3 */
1919 mtctr r11 /* zero this many doublewords */
1926 mtmsrd r6 /* RI on */
1928 /* The following gets the stack and TOC set up with the regs */
1929 /* pointing to the real addr of the kernel stack. This is */
1930 /* all done to support the C function call below which sets */
1931 /* up the htab. This is done because we have relocated the */
1932 /* kernel but are still running in real mode. */
1934 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1937 /* set up a stack pointer (physical address) */
1938 addi r1,r3,THREAD_SIZE
1940 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1942 /* set up the TOC (physical address) */
1943 LOAD_REG_IMMEDIATE(r2,__toc_start)
1948 LOAD_REG_IMMEDIATE(r3, cpu_specs)
1950 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1955 /* Do very early kernel initializations, including initial hash table,
1956 * stab and slb setup before we turn on relocation. */
1958 /* Restore parameters passed from prom_init/kexec */
1962 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1963 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1967 b . /* prevent speculative execution */
1968 #endif /* CONFIG_PPC_MULTIPLATFORM */
1970 /* This is where all platforms converge execution */
1971 _STATIC(start_here_common)
1972 /* relocation is on at this point */
1974 /* The following code sets up the SP and TOC now that we are */
1975 /* running with translation enabled. */
1977 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1979 /* set up the stack */
1980 addi r1,r3,THREAD_SIZE
1982 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1984 /* Apply the CPUs-specific fixups (nop out sections not relevant
1988 bl .do_cpu_ftr_fixups
1990 /* ptr to current */
1991 LOAD_REG_IMMEDIATE(r4, init_task)
1992 std r4,PACACURRENT(r13)
1996 std r1,PACAKSAVE(r13)
2000 /* Load up the kernel context */
2002 #ifdef DO_SOFT_DISABLE
2004 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
2006 ori r5,r5,MSR_EE /* Hard Enabled */
2016 * We put a few things here that have to be page-aligned.
2017 * This stuff goes at the beginning of the bss, which is page-aligned.
2023 .globl empty_zero_page
2027 .globl swapper_pg_dir
2032 * This space gets a copy of optional info passed to us by the bootstrap
2033 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2037 .space COMMAND_LINE_SIZE