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 #define DO_SOFT_DISABLE
41 * We layout physical memory as follows:
42 * 0x0000 - 0x00ff : Secondary processor spin code
43 * 0x0100 - 0x2fff : pSeries Interrupt prologs
44 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
45 * 0x6000 - 0x6fff : Initial (CPU0) segment table
46 * 0x7000 - 0x7fff : FWNMI data area
47 * 0x8000 - : Early init and support code
55 * SPRG0 reserved for hypervisor
56 * SPRG1 temp - used to save gpr
57 * SPRG2 temp - used to save gpr
58 * SPRG3 virt addr of paca
62 * Entering into this code we make the following assumptions:
64 * 1. The MMU is off & open firmware is running in real mode.
65 * 2. The kernel is entered at __start
68 * 1. The MMU is on (as it always is for iSeries)
69 * 2. The kernel is entered at system_reset_iSeries
76 /* NOP this out unconditionally */
78 b .__start_initialization_multiplatform
81 /* Catch branch to 0 in real mode */
84 /* Secondary processors spin on this value until it goes to 1. */
85 .globl __secondary_hold_spinloop
86 __secondary_hold_spinloop:
89 /* Secondary processors write this value with their cpu # */
90 /* after they enter the spin loop immediately below. */
91 .globl __secondary_hold_acknowledge
92 __secondary_hold_acknowledge:
95 #ifdef CONFIG_PPC_ISERIES
97 * At offset 0x20, there is a pointer to iSeries LPAR data.
98 * This is required by the hypervisor
101 .llong hvReleaseData-KERNELBASE
102 #endif /* CONFIG_PPC_ISERIES */
106 * The following code is used to hold secondary processors
107 * in a spin loop after they have entered the kernel, but
108 * before the bulk of the kernel has been relocated. This code
109 * is relocated to physical address 0x60 before prom_init is run.
110 * All of it must fit below the first exception vector at 0x100.
112 _GLOBAL(__secondary_hold)
115 mtmsrd r24 /* RI on */
117 /* Grab our physical cpu number */
120 /* Tell the master cpu we're here */
121 /* Relocation is off & we are located at an address less */
122 /* than 0x100, so only need to grab low order offset. */
123 std r24,__secondary_hold_acknowledge@l(0)
126 /* All secondary cpus wait here until told to start. */
127 100: ld r4,__secondary_hold_spinloop@l(0)
131 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
132 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
140 /* This value is used to mark exception frames on the stack. */
143 .tc ID_72656773_68657265[TC],0x7265677368657265
147 * The following macros define the code that appears as
148 * the prologue to each of the exception handlers. They
149 * are split into two parts to allow a single kernel binary
150 * to be used for pSeries and iSeries.
151 * LOL. One day... - paulus
155 * We make as much of the exception code common between native
156 * exception handlers (including pSeries LPAR) and iSeries LPAR
157 * implementations as possible.
161 * This is the start of the interrupt handlers for pSeries
162 * This code runs with relocation off.
177 * We're short on space and time in the exception prolog, so we can't
178 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
179 * low halfword of the address, but for Kdump we need the whole low
182 #ifdef CONFIG_CRASH_DUMP
183 #define LOAD_HANDLER(reg, label) \
184 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
185 ori reg,reg,(label)@l; /* .. and the rest */
187 #define LOAD_HANDLER(reg, label) \
188 ori reg,reg,(label)@l; /* virt addr of handler ... */
192 * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode.
193 * The firmware calls the registered system_reset_fwnmi and
194 * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run
195 * a 32bit application at the time of the event.
196 * This firmware bug is present on POWER4 and JS20.
198 #define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \
199 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
200 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
201 std r10,area+EX_R10(r13); \
202 std r11,area+EX_R11(r13); \
203 std r12,area+EX_R12(r13); \
204 mfspr r9,SPRN_SPRG1; \
205 std r9,area+EX_R13(r13); \
207 clrrdi r12,r13,32; /* get high part of &label */ \
209 /* force 64bit mode */ \
210 li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \
211 rldimi r10,r11,61,0; /* insert into top 3 bits */ \
212 /* done 64bit mode */ \
213 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
214 LOAD_HANDLER(r12,label) \
215 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
216 mtspr SPRN_SRR0,r12; \
217 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
218 mtspr SPRN_SRR1,r10; \
220 b . /* prevent speculative execution */
222 #define EXCEPTION_PROLOG_PSERIES(area, label) \
223 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
224 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
225 std r10,area+EX_R10(r13); \
226 std r11,area+EX_R11(r13); \
227 std r12,area+EX_R12(r13); \
228 mfspr r9,SPRN_SPRG1; \
229 std r9,area+EX_R13(r13); \
231 clrrdi r12,r13,32; /* get high part of &label */ \
233 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
234 LOAD_HANDLER(r12,label) \
235 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
236 mtspr SPRN_SRR0,r12; \
237 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
238 mtspr SPRN_SRR1,r10; \
240 b . /* prevent speculative execution */
243 * This is the start of the interrupt handlers for iSeries
244 * This code runs with relocation on.
246 #define EXCEPTION_PROLOG_ISERIES_1(area) \
247 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
248 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
249 std r10,area+EX_R10(r13); \
250 std r11,area+EX_R11(r13); \
251 std r12,area+EX_R12(r13); \
252 mfspr r9,SPRN_SPRG1; \
253 std r9,area+EX_R13(r13); \
256 #define EXCEPTION_PROLOG_ISERIES_2 \
258 ld r12,PACALPPACAPTR(r13); \
259 ld r11,LPPACASRR0(r12); \
260 ld r12,LPPACASRR1(r12); \
261 ori r10,r10,MSR_RI; \
265 * The common exception prolog is used for all except a few exceptions
266 * such as a segment miss on a kernel address. We have to be prepared
267 * to take another exception from the point where we first touch the
268 * kernel stack onwards.
270 * On entry r13 points to the paca, r9-r13 are saved in the paca,
271 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
272 * SRR1, and relocation is on.
274 #define EXCEPTION_PROLOG_COMMON(n, area) \
275 andi. r10,r12,MSR_PR; /* See if coming from user */ \
276 mr r10,r1; /* Save r1 */ \
277 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
279 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
280 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
281 bge- cr1,2f; /* abort if it is */ \
283 2: li r1,(n); /* will be reloaded later */ \
284 sth r1,PACA_TRAP_SAVE(r13); \
286 3: 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 lbz r10,PACASOFTIRQEN(r13); \
312 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
316 std r9,_TRAP(r1); /* set trap number */ \
318 ld r11,exception_marker@toc(r2); \
319 std r10,RESULT(r1); /* clear regs->result */ \
320 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
325 #define STD_EXCEPTION_PSERIES(n, label) \
327 .globl label##_pSeries; \
330 mtspr SPRN_SPRG1,r13; /* save r13 */ \
331 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
333 #define HSTD_EXCEPTION_PSERIES(n, label) \
335 .globl label##_pSeries; \
338 mtspr SPRN_SPRG1,r20; /* save r20 */ \
339 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
340 mtspr SPRN_SRR0,r20; \
341 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
342 mtspr SPRN_SRR1,r20; \
343 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
344 mtspr SPRN_SPRG1,r13; /* save r13 */ \
345 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
348 #define MASKABLE_EXCEPTION_PSERIES(n, label) \
350 .globl label##_pSeries; \
353 mtspr SPRN_SPRG1,r13; /* save r13 */ \
354 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
355 std r9,PACA_EXGEN+EX_R9(r13); /* save r9, r10 */ \
356 std r10,PACA_EXGEN+EX_R10(r13); \
357 lbz r10,PACASOFTIRQEN(r13); \
360 beq masked_interrupt; \
361 mfspr r10,SPRN_SPRG1; \
362 std r10,PACA_EXGEN+EX_R13(r13); \
363 std r11,PACA_EXGEN+EX_R11(r13); \
364 std r12,PACA_EXGEN+EX_R12(r13); \
365 clrrdi r12,r13,32; /* get high part of &label */ \
367 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
368 LOAD_HANDLER(r12,label##_common) \
369 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
370 mtspr SPRN_SRR0,r12; \
371 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
372 mtspr SPRN_SRR1,r10; \
374 b . /* prevent speculative execution */
376 #define STD_EXCEPTION_ISERIES(n, label, area) \
377 .globl label##_iSeries; \
380 mtspr SPRN_SPRG1,r13; /* save r13 */ \
381 EXCEPTION_PROLOG_ISERIES_1(area); \
382 EXCEPTION_PROLOG_ISERIES_2; \
385 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
386 .globl label##_iSeries; \
389 mtspr SPRN_SPRG1,r13; /* save r13 */ \
390 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
391 lbz r10,PACASOFTIRQEN(r13); \
393 beq- label##_iSeries_masked; \
394 EXCEPTION_PROLOG_ISERIES_2; \
397 #ifdef CONFIG_PPC_ISERIES
398 #define DISABLE_INTS \
400 stb r11,PACASOFTIRQEN(r13); \
401 BEGIN_FW_FTR_SECTION; \
402 stb r11,PACAHARDIRQEN(r13); \
403 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES); \
404 BEGIN_FW_FTR_SECTION; \
406 ori r10,r10,MSR_EE; \
408 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
411 #define DISABLE_INTS \
413 stb r11,PACASOFTIRQEN(r13); \
414 stb r11,PACAHARDIRQEN(r13)
416 #endif /* CONFIG_PPC_ISERIES */
418 #define ENABLE_INTS \
421 rlwimi r11,r12,0,MSR_EE; \
424 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
426 .globl label##_common; \
428 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
431 addi r3,r1,STACK_FRAME_OVERHEAD; \
436 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
437 * in the idle task and therefore need the special idle handling.
439 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
441 .globl label##_common; \
443 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
447 addi r3,r1,STACK_FRAME_OVERHEAD; \
451 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
453 .globl label##_common; \
455 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
458 bl .ppc64_runlatch_on; \
459 addi r3,r1,STACK_FRAME_OVERHEAD; \
461 b .ret_from_except_lite
464 * When the idle code in power4_idle puts the CPU into NAP mode,
465 * it has to do so in a loop, and relies on the external interrupt
466 * and decrementer interrupt entry code to get it out of the loop.
467 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
468 * to signal that it is in the loop and needs help to get out.
470 #ifdef CONFIG_PPC_970_NAP
473 clrrdi r11,r1,THREAD_SHIFT; \
474 ld r9,TI_LOCAL_FLAGS(r11); \
475 andi. r10,r9,_TLF_NAPPING; \
476 bnel power4_fixup_nap; \
477 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
483 * Start of pSeries system interrupt routines
486 .globl __start_interrupts
489 STD_EXCEPTION_PSERIES(0x100, system_reset)
492 _machine_check_pSeries:
494 mtspr SPRN_SPRG1,r13 /* save r13 */
495 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
498 .globl data_access_pSeries
507 rlwimi r13,r12,16,0x20
510 beq do_stab_bolted_pSeries
513 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
514 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
517 .globl data_access_slb_pSeries
518 data_access_slb_pSeries:
521 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
522 std r3,PACA_EXSLB+EX_R3(r13)
524 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
527 /* Keep that around for when we re-implement dynamic VSIDs */
529 bge slb_miss_user_pseries
530 #endif /* __DISABLED__ */
531 std r10,PACA_EXSLB+EX_R10(r13)
532 std r11,PACA_EXSLB+EX_R11(r13)
533 std r12,PACA_EXSLB+EX_R12(r13)
535 std r10,PACA_EXSLB+EX_R13(r13)
536 mfspr r12,SPRN_SRR1 /* and SRR1 */
537 b .slb_miss_realmode /* Rel. branch works in real mode */
539 STD_EXCEPTION_PSERIES(0x400, instruction_access)
542 .globl instruction_access_slb_pSeries
543 instruction_access_slb_pSeries:
546 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
547 std r3,PACA_EXSLB+EX_R3(r13)
548 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
549 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
552 /* Keep that around for when we re-implement dynamic VSIDs */
554 bge slb_miss_user_pseries
555 #endif /* __DISABLED__ */
556 std r10,PACA_EXSLB+EX_R10(r13)
557 std r11,PACA_EXSLB+EX_R11(r13)
558 std r12,PACA_EXSLB+EX_R12(r13)
560 std r10,PACA_EXSLB+EX_R13(r13)
561 mfspr r12,SPRN_SRR1 /* and SRR1 */
562 b .slb_miss_realmode /* Rel. branch works in real mode */
564 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
565 STD_EXCEPTION_PSERIES(0x600, alignment)
566 STD_EXCEPTION_PSERIES(0x700, program_check)
567 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
568 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
569 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
570 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
573 .globl system_call_pSeries
581 oris r12,r12,system_call_common@h
582 ori r12,r12,system_call_common@l
584 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
588 b . /* prevent speculative execution */
590 STD_EXCEPTION_PSERIES(0xd00, single_step)
591 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
593 /* We need to deal with the Altivec unavailable exception
594 * here which is at 0xf20, thus in the middle of the
595 * prolog code of the PerformanceMonitor one. A little
596 * trickery is thus necessary
599 b performance_monitor_pSeries
601 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
603 #ifdef CONFIG_CBE_RAS
604 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
605 #endif /* CONFIG_CBE_RAS */
606 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
607 #ifdef CONFIG_CBE_RAS
608 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
609 #endif /* CONFIG_CBE_RAS */
610 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
611 #ifdef CONFIG_CBE_RAS
612 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
613 #endif /* CONFIG_CBE_RAS */
617 /*** pSeries interrupt support ***/
619 /* moved from 0xf00 */
620 STD_EXCEPTION_PSERIES(., performance_monitor)
623 * An interrupt came in while soft-disabled; clear EE in SRR1,
624 * clear paca->hard_enabled and return.
627 stb r10,PACAHARDIRQEN(r13)
629 ld r9,PACA_EXGEN+EX_R9(r13)
631 rldicl r10,r10,48,1 /* clear MSR_EE */
634 ld r10,PACA_EXGEN+EX_R10(r13)
640 do_stab_bolted_pSeries:
643 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
646 * We have some room here we use that to put
647 * the peries slb miss user trampoline code so it's reasonably
648 * away from slb_miss_user_common to avoid problems with rfid
650 * This is used for when the SLB miss handler has to go virtual,
651 * which doesn't happen for now anymore but will once we re-implement
652 * dynamic VSIDs for shared page tables
655 slb_miss_user_pseries:
656 std r10,PACA_EXGEN+EX_R10(r13)
657 std r11,PACA_EXGEN+EX_R11(r13)
658 std r12,PACA_EXGEN+EX_R12(r13)
660 ld r11,PACA_EXSLB+EX_R9(r13)
661 ld r12,PACA_EXSLB+EX_R3(r13)
662 std r10,PACA_EXGEN+EX_R13(r13)
663 std r11,PACA_EXGEN+EX_R9(r13)
664 std r12,PACA_EXGEN+EX_R3(r13)
667 mfspr r11,SRR0 /* save SRR0 */
668 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
669 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
671 mfspr r12,SRR1 /* and SRR1 */
674 b . /* prevent spec. execution */
675 #endif /* __DISABLED__ */
678 * Vectors for the FWNMI option. Share common code.
680 .globl system_reset_fwnmi
684 mtspr SPRN_SPRG1,r13 /* save r13 */
685 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
687 .globl machine_check_fwnmi
691 mtspr SPRN_SPRG1,r13 /* save r13 */
692 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
694 #ifdef CONFIG_PPC_ISERIES
695 /*** ISeries-LPAR interrupt handlers ***/
697 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
699 .globl data_access_iSeries
707 rlwimi r13,r12,16,0x20
710 beq .do_stab_bolted_iSeries
713 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
714 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
715 EXCEPTION_PROLOG_ISERIES_2
718 .do_stab_bolted_iSeries:
721 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
722 EXCEPTION_PROLOG_ISERIES_2
725 .globl data_access_slb_iSeries
726 data_access_slb_iSeries:
727 mtspr SPRN_SPRG1,r13 /* save r13 */
728 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
729 std r3,PACA_EXSLB+EX_R3(r13)
731 std r9,PACA_EXSLB+EX_R9(r13)
735 bge slb_miss_user_iseries
737 std r10,PACA_EXSLB+EX_R10(r13)
738 std r11,PACA_EXSLB+EX_R11(r13)
739 std r12,PACA_EXSLB+EX_R12(r13)
741 std r10,PACA_EXSLB+EX_R13(r13)
742 ld r12,PACALPPACAPTR(r13)
743 ld r12,LPPACASRR1(r12)
746 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
748 .globl instruction_access_slb_iSeries
749 instruction_access_slb_iSeries:
750 mtspr SPRN_SPRG1,r13 /* save r13 */
751 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
752 std r3,PACA_EXSLB+EX_R3(r13)
753 ld r3,PACALPPACAPTR(r13)
754 ld r3,LPPACASRR0(r3) /* get SRR0 value */
755 std r9,PACA_EXSLB+EX_R9(r13)
759 bge .slb_miss_user_iseries
761 std r10,PACA_EXSLB+EX_R10(r13)
762 std r11,PACA_EXSLB+EX_R11(r13)
763 std r12,PACA_EXSLB+EX_R12(r13)
765 std r10,PACA_EXSLB+EX_R13(r13)
766 ld r12,PACALPPACAPTR(r13)
767 ld r12,LPPACASRR1(r12)
771 slb_miss_user_iseries:
772 std r10,PACA_EXGEN+EX_R10(r13)
773 std r11,PACA_EXGEN+EX_R11(r13)
774 std r12,PACA_EXGEN+EX_R12(r13)
776 ld r11,PACA_EXSLB+EX_R9(r13)
777 ld r12,PACA_EXSLB+EX_R3(r13)
778 std r10,PACA_EXGEN+EX_R13(r13)
779 std r11,PACA_EXGEN+EX_R9(r13)
780 std r12,PACA_EXGEN+EX_R3(r13)
781 EXCEPTION_PROLOG_ISERIES_2
782 b slb_miss_user_common
785 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
786 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
787 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
788 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
789 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
790 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
791 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
793 .globl system_call_iSeries
797 EXCEPTION_PROLOG_ISERIES_2
800 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
801 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
802 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
804 .globl system_reset_iSeries
805 system_reset_iSeries:
806 mfspr r13,SPRN_SPRG3 /* Get paca address */
809 mtmsrd r24 /* RI on */
810 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
811 cmpwi 0,r24,0 /* Are we processor 0? */
813 b .__start_initialization_iSeries /* Start up the first processor */
814 1: mfspr r4,SPRN_CTRLF
815 li r5,CTRL_RUNLATCH /* Turn off the run light */
822 lbz r23,PACAPROCSTART(r13) /* Test if this processor
825 LOAD_REG_IMMEDIATE(r3,current_set)
826 sldi r28,r24,3 /* get current_set[cpu#] */
828 addi r1,r3,THREAD_SIZE
829 subi r1,r1,STACK_FRAME_OVERHEAD
832 beq iSeries_secondary_smp_loop /* Loop until told to go */
833 bne __secondary_start /* Loop until told to go */
834 iSeries_secondary_smp_loop:
835 /* Let the Hypervisor know we are alive */
836 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
838 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
839 #else /* CONFIG_SMP */
840 /* Yield the processor. This is required for non-SMP kernels
841 which are running on multi-threaded machines. */
843 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
844 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
845 li r4,0 /* "yield timed" */
846 li r5,-1 /* "yield forever" */
847 #endif /* CONFIG_SMP */
848 li r0,-1 /* r0=-1 indicates a Hypervisor call */
849 sc /* Invoke the hypervisor via a system call */
850 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
851 b 1b /* If SMP not configured, secondaries
854 decrementer_iSeries_masked:
855 /* We may not have a valid TOC pointer in here. */
857 ld r12,PACALPPACAPTR(r13)
858 stb r11,LPPACADECRINT(r12)
859 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
864 hardware_interrupt_iSeries_masked:
865 mtcrf 0x80,r9 /* Restore regs */
866 ld r12,PACALPPACAPTR(r13)
867 ld r11,LPPACASRR0(r12)
868 ld r12,LPPACASRR1(r12)
871 ld r9,PACA_EXGEN+EX_R9(r13)
872 ld r10,PACA_EXGEN+EX_R10(r13)
873 ld r11,PACA_EXGEN+EX_R11(r13)
874 ld r12,PACA_EXGEN+EX_R12(r13)
875 ld r13,PACA_EXGEN+EX_R13(r13)
877 b . /* prevent speculative execution */
878 #endif /* CONFIG_PPC_ISERIES */
880 /*** Common interrupt handlers ***/
882 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
885 * Machine check is different because we use a different
886 * save area: PACA_EXMC instead of PACA_EXGEN.
889 .globl machine_check_common
890 machine_check_common:
891 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
895 addi r3,r1,STACK_FRAME_OVERHEAD
896 bl .machine_check_exception
899 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
900 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
901 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
902 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
903 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
904 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
905 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
906 #ifdef CONFIG_ALTIVEC
907 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
909 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
911 #ifdef CONFIG_CBE_RAS
912 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
913 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
914 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
915 #endif /* CONFIG_CBE_RAS */
918 * Here we have detected that the kernel stack pointer is bad.
919 * R9 contains the saved CR, r13 points to the paca,
920 * r10 contains the (bad) kernel stack pointer,
921 * r11 and r12 contain the saved SRR0 and SRR1.
922 * We switch to using an emergency stack, save the registers there,
923 * and call kernel_bad_stack(), which panics.
926 ld r1,PACAEMERGSP(r13)
927 subi r1,r1,64+INT_FRAME_SIZE
948 lhz r12,PACA_TRAP_SAVE(r13)
950 addi r11,r1,INT_FRAME_SIZE
955 1: addi r3,r1,STACK_FRAME_OVERHEAD
960 * Return from an exception with minimal checks.
961 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
962 * If interrupts have been enabled, or anything has been
963 * done that might have changed the scheduling status of
964 * any task or sent any task a signal, you should use
965 * ret_from_except or ret_from_except_lite instead of this.
967 fast_exc_return_irq: /* restores irq state too */
970 stb r3,PACASOFTIRQEN(r13) /* restore paca->soft_enabled */
971 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
972 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
975 .globl fast_exception_return
976 fast_exception_return:
979 andi. r3,r12,MSR_RI /* check if RI is set */
982 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
985 ACCOUNT_CPU_USER_EXIT(r3, r4)
1001 rldicl r10,r10,48,1 /* clear EE */
1002 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
1010 b . /* prevent speculative execution */
1014 1: addi r3,r1,STACK_FRAME_OVERHEAD
1015 bl .unrecoverable_exception
1019 * Here r13 points to the paca, r9 contains the saved CR,
1020 * SRR0 and SRR1 are saved in r11 and r12,
1021 * r9 - r13 are saved in paca->exgen.
1024 .globl data_access_common
1027 std r10,PACA_EXGEN+EX_DAR(r13)
1028 mfspr r10,SPRN_DSISR
1029 stw r10,PACA_EXGEN+EX_DSISR(r13)
1030 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
1031 ld r3,PACA_EXGEN+EX_DAR(r13)
1032 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1034 b .do_hash_page /* Try to handle as hpte fault */
1037 .globl instruction_access_common
1038 instruction_access_common:
1039 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
1041 andis. r4,r12,0x5820
1043 b .do_hash_page /* Try to handle as hpte fault */
1046 * Here is the common SLB miss user that is used when going to virtual
1047 * mode for SLB misses, that is currently not used
1051 .globl slb_miss_user_common
1052 slb_miss_user_common:
1054 std r3,PACA_EXGEN+EX_DAR(r13)
1055 stw r9,PACA_EXGEN+EX_CCR(r13)
1056 std r10,PACA_EXGEN+EX_LR(r13)
1057 std r11,PACA_EXGEN+EX_SRR0(r13)
1058 bl .slb_allocate_user
1060 ld r10,PACA_EXGEN+EX_LR(r13)
1061 ld r3,PACA_EXGEN+EX_R3(r13)
1062 lwz r9,PACA_EXGEN+EX_CCR(r13)
1063 ld r11,PACA_EXGEN+EX_SRR0(r13)
1067 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1068 beq- unrecov_user_slb
1076 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1082 ld r9,PACA_EXGEN+EX_R9(r13)
1083 ld r10,PACA_EXGEN+EX_R10(r13)
1084 ld r11,PACA_EXGEN+EX_R11(r13)
1085 ld r12,PACA_EXGEN+EX_R12(r13)
1086 ld r13,PACA_EXGEN+EX_R13(r13)
1091 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1092 ld r4,PACA_EXGEN+EX_DAR(r13)
1099 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1102 1: addi r3,r1,STACK_FRAME_OVERHEAD
1103 bl .unrecoverable_exception
1106 #endif /* __DISABLED__ */
1110 * r13 points to the PACA, r9 contains the saved CR,
1111 * r12 contain the saved SRR1, SRR0 is still ready for return
1112 * r3 has the faulting address
1113 * r9 - r13 are saved in paca->exslb.
1114 * r3 is saved in paca->slb_r3
1115 * We assume we aren't going to take any exceptions during this procedure.
1117 _GLOBAL(slb_miss_realmode)
1120 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1121 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1123 bl .slb_allocate_realmode
1125 /* All done -- return from exception. */
1127 ld r10,PACA_EXSLB+EX_LR(r13)
1128 ld r3,PACA_EXSLB+EX_R3(r13)
1129 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1130 #ifdef CONFIG_PPC_ISERIES
1131 BEGIN_FW_FTR_SECTION
1132 ld r11,PACALPPACAPTR(r13)
1133 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1134 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1135 #endif /* CONFIG_PPC_ISERIES */
1139 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1145 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1148 #ifdef CONFIG_PPC_ISERIES
1149 BEGIN_FW_FTR_SECTION
1152 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1153 #endif /* CONFIG_PPC_ISERIES */
1154 ld r9,PACA_EXSLB+EX_R9(r13)
1155 ld r10,PACA_EXSLB+EX_R10(r13)
1156 ld r11,PACA_EXSLB+EX_R11(r13)
1157 ld r12,PACA_EXSLB+EX_R12(r13)
1158 ld r13,PACA_EXSLB+EX_R13(r13)
1160 b . /* prevent speculative execution */
1163 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1166 1: addi r3,r1,STACK_FRAME_OVERHEAD
1167 bl .unrecoverable_exception
1171 .globl hardware_interrupt_common
1172 .globl hardware_interrupt_entry
1173 hardware_interrupt_common:
1174 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1176 hardware_interrupt_entry:
1178 bl .ppc64_runlatch_on
1179 addi r3,r1,STACK_FRAME_OVERHEAD
1181 b .ret_from_except_lite
1183 #ifdef CONFIG_PPC_970_NAP
1186 std r9,TI_LOCAL_FLAGS(r11)
1187 ld r10,_LINK(r1) /* make idle task do the */
1188 std r10,_NIP(r1) /* equivalent of a blr */
1193 .globl alignment_common
1196 std r10,PACA_EXGEN+EX_DAR(r13)
1197 mfspr r10,SPRN_DSISR
1198 stw r10,PACA_EXGEN+EX_DSISR(r13)
1199 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1200 ld r3,PACA_EXGEN+EX_DAR(r13)
1201 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1205 addi r3,r1,STACK_FRAME_OVERHEAD
1207 bl .alignment_exception
1211 .globl program_check_common
1212 program_check_common:
1213 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1215 addi r3,r1,STACK_FRAME_OVERHEAD
1217 bl .program_check_exception
1221 .globl fp_unavailable_common
1222 fp_unavailable_common:
1223 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1224 bne 1f /* if from user, just load it up */
1226 addi r3,r1,STACK_FRAME_OVERHEAD
1228 bl .kernel_fp_unavailable_exception
1233 .globl altivec_unavailable_common
1234 altivec_unavailable_common:
1235 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1236 #ifdef CONFIG_ALTIVEC
1238 bne .load_up_altivec /* if from user, just load it up */
1239 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1242 addi r3,r1,STACK_FRAME_OVERHEAD
1244 bl .altivec_unavailable_exception
1247 #ifdef CONFIG_ALTIVEC
1249 * load_up_altivec(unused, unused, tsk)
1250 * Disable VMX for the task which had it previously,
1251 * and save its vector registers in its thread_struct.
1252 * Enables the VMX for use in the kernel on return.
1253 * On SMP we know the VMX is free, since we give it up every
1254 * switch (ie, no lazy save of the vector registers).
1255 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1257 _STATIC(load_up_altivec)
1258 mfmsr r5 /* grab the current MSR */
1259 oris r5,r5,MSR_VEC@h
1260 mtmsrd r5 /* enable use of VMX now */
1264 * For SMP, we don't do lazy VMX switching because it just gets too
1265 * horrendously complex, especially when a task switches from one CPU
1266 * to another. Instead we call giveup_altvec in switch_to.
1267 * VRSAVE isn't dealt with here, that is done in the normal context
1268 * switch code. Note that we could rely on vrsave value to eventually
1269 * avoid saving all of the VREGs here...
1272 ld r3,last_task_used_altivec@got(r2)
1276 /* Save VMX state to last_task_used_altivec's THREAD struct */
1282 /* Disable VMX for last_task_used_altivec */
1284 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1287 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1289 #endif /* CONFIG_SMP */
1290 /* Hack: if we get an altivec unavailable trap with VRSAVE
1291 * set to all zeros, we assume this is a broken application
1292 * that fails to set it properly, and thus we switch it to
1295 mfspr r4,SPRN_VRSAVE
1299 mtspr SPRN_VRSAVE,r4
1301 /* enable use of VMX after return */
1302 ld r4,PACACURRENT(r13)
1303 addi r5,r4,THREAD /* Get THREAD */
1304 oris r12,r12,MSR_VEC@h
1308 stw r4,THREAD_USED_VR(r5)
1313 /* Update last_task_used_math to 'current' */
1314 subi r4,r5,THREAD /* Back to 'current' */
1316 #endif /* CONFIG_SMP */
1317 /* restore registers and return */
1318 b fast_exception_return
1319 #endif /* CONFIG_ALTIVEC */
1325 _GLOBAL(do_hash_page)
1329 andis. r0,r4,0xa450 /* weird error? */
1330 bne- handle_page_fault /* if not, try to insert a HPTE */
1332 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1333 bne- do_ste_alloc /* If so handle it */
1334 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1337 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1338 * accessing a userspace segment (even from the kernel). We assume
1339 * kernel addresses always have the high bit set.
1341 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1342 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1343 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1344 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1345 ori r4,r4,1 /* add _PAGE_PRESENT */
1346 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1349 * On iSeries, we soft-disable interrupts here, then
1350 * hard-enable interrupts so that the hash_page code can spin on
1351 * the hash_table_lock without problems on a shared processor.
1356 * r3 contains the faulting address
1357 * r4 contains the required access permissions
1358 * r5 contains the trap number
1360 * at return r3 = 0 for success
1362 bl .hash_page /* build HPTE if possible */
1363 cmpdi r3,0 /* see if hash_page succeeded */
1365 #ifdef DO_SOFT_DISABLE
1366 BEGIN_FW_FTR_SECTION
1368 * If we had interrupts soft-enabled at the point where the
1369 * DSI/ISI occurred, and an interrupt came in during hash_page,
1371 * We jump to ret_from_except_lite rather than fast_exception_return
1372 * because ret_from_except_lite will check for and handle pending
1373 * interrupts if necessary.
1376 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1378 BEGIN_FW_FTR_SECTION
1380 * Here we have interrupts hard-disabled, so it is sufficient
1381 * to restore paca->{soft,hard}_enable and get out.
1383 beq fast_exc_return_irq /* Return from exception on success */
1384 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1386 /* For a hash failure, we don't bother re-enabling interrupts */
1390 * hash_page couldn't handle it, set soft interrupt enable back
1391 * to what it was before the trap. Note that .local_irq_restore
1392 * handles any interrupts pending at this point.
1395 bl .local_irq_restore
1398 /* Here we have a page fault that hash_page can't handle. */
1403 addi r3,r1,STACK_FRAME_OVERHEAD
1409 addi r3,r1,STACK_FRAME_OVERHEAD
1414 13: b .ret_from_except_lite
1416 /* We have a page fault that hash_page could handle but HV refused
1420 addi r3,r1,STACK_FRAME_OVERHEAD
1425 /* here we have a segment miss */
1427 bl .ste_allocate /* try to insert stab entry */
1429 bne- handle_page_fault
1430 b fast_exception_return
1433 * r13 points to the PACA, r9 contains the saved CR,
1434 * r11 and r12 contain the saved SRR0 and SRR1.
1435 * r9 - r13 are saved in paca->exslb.
1436 * We assume we aren't going to take any exceptions during this procedure.
1437 * We assume (DAR >> 60) == 0xc.
1440 _GLOBAL(do_stab_bolted)
1441 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1442 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1444 /* Hash to the primary group */
1445 ld r10,PACASTABVIRT(r13)
1448 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1450 /* Calculate VSID */
1451 /* This is a kernel address, so protovsid = ESID */
1452 ASM_VSID_SCRAMBLE(r11, r9)
1453 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1455 /* Search the primary group for a free entry */
1456 1: ld r11,0(r10) /* Test valid bit of the current ste */
1463 /* Stick for only searching the primary group for now. */
1464 /* At least for now, we use a very simple random castout scheme */
1465 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1467 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1470 /* r10 currently points to an ste one past the group of interest */
1471 /* make it point to the randomly selected entry */
1473 or r10,r10,r11 /* r10 is the entry to invalidate */
1475 isync /* mark the entry invalid */
1477 rldicl r11,r11,56,1 /* clear the valid bit */
1482 clrrdi r11,r11,28 /* Get the esid part of the ste */
1485 2: std r9,8(r10) /* Store the vsid part of the ste */
1488 mfspr r11,SPRN_DAR /* Get the new esid */
1489 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1490 ori r11,r11,0x90 /* Turn on valid and kp */
1491 std r11,0(r10) /* Put new entry back into the stab */
1495 /* All done -- return from exception. */
1496 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1497 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1499 andi. r10,r12,MSR_RI
1502 mtcrf 0x80,r9 /* restore CR */
1510 ld r9,PACA_EXSLB+EX_R9(r13)
1511 ld r10,PACA_EXSLB+EX_R10(r13)
1512 ld r11,PACA_EXSLB+EX_R11(r13)
1513 ld r12,PACA_EXSLB+EX_R12(r13)
1514 ld r13,PACA_EXSLB+EX_R13(r13)
1516 b . /* prevent speculative execution */
1519 * Space for CPU0's segment table.
1521 * On iSeries, the hypervisor must fill in at least one entry before
1522 * we get control (with relocate on). The address is give to the hv
1523 * as a page number (see xLparMap in lpardata.c), so this must be at a
1524 * fixed address (the linker can't compute (u64)&initial_stab >>
1527 . = STAB0_OFFSET /* 0x6000 */
1533 * Data area reserved for FWNMI option.
1534 * This address (0x7000) is fixed by the RPA.
1537 .globl fwnmi_data_area
1540 /* iSeries does not use the FWNMI stuff, so it is safe to put
1541 * this here, even if we later allow kernels that will boot on
1542 * both pSeries and iSeries */
1543 #ifdef CONFIG_PPC_ISERIES
1545 #include "lparmap.s"
1547 * This ".text" is here for old compilers that generate a trailing
1548 * .note section when compiling .c files to .s
1551 #endif /* CONFIG_PPC_ISERIES */
1556 * On pSeries and most other platforms, secondary processors spin
1557 * in the following code.
1558 * At entry, r3 = this processor's number (physical cpu id)
1560 _GLOBAL(generic_secondary_smp_init)
1563 /* turn on 64-bit mode */
1566 /* Set up a paca value for this processor. Since we have the
1567 * physical cpu id in r24, we need to search the pacas to find
1568 * which logical id maps to our physical one.
1570 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1571 li r5,0 /* logical cpu id */
1572 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1573 cmpw r6,r24 /* Compare to our id */
1575 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1580 mr r3,r24 /* not found, copy phys to r3 */
1581 b .kexec_wait /* next kernel might do better */
1583 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1584 /* From now on, r24 is expected to be logical cpuid */
1587 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1592 b 3b /* Never go on non-SMP */
1595 beq 3b /* Loop until told to go */
1597 /* See if we need to call a cpu state restore handler */
1598 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1600 ld r23,CPU_SPEC_RESTORE(r23)
1607 4: /* Create a temp kernel stack for use before relocation is on. */
1608 ld r1,PACAEMERGSP(r13)
1609 subi r1,r1,STACK_FRAME_OVERHEAD
1614 #ifdef CONFIG_PPC_ISERIES
1615 _INIT_STATIC(__start_initialization_iSeries)
1616 /* Clear out the BSS */
1617 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1618 LOAD_REG_IMMEDIATE(r8,__bss_start)
1619 sub r11,r11,r8 /* bss size */
1620 addi r11,r11,7 /* round up to an even double word */
1621 rldicl. r11,r11,61,3 /* shift right by 3 */
1625 mtctr r11 /* zero this many doublewords */
1629 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1630 addi r1,r1,THREAD_SIZE
1632 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1634 LOAD_REG_IMMEDIATE(r2,__toc_start)
1638 bl .iSeries_early_setup
1641 /* relocation is on at this point */
1643 b .start_here_common
1644 #endif /* CONFIG_PPC_ISERIES */
1649 andi. r0,r3,MSR_IR|MSR_DR
1656 b . /* prevent speculative execution */
1660 * Here is our main kernel entry point. We support currently 2 kind of entries
1661 * depending on the value of r5.
1663 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1666 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1667 * DT block, r4 is a physical pointer to the kernel itself
1670 _GLOBAL(__start_initialization_multiplatform)
1672 * Are we booted from a PROM Of-type client-interface ?
1676 b .__boot_from_prom /* yes -> prom */
1678 /* Save parameters */
1682 /* Make sure we are running in 64 bits mode */
1685 /* Setup some critical 970 SPRs before switching MMU off */
1688 cmpwi r0,0x39 /* 970 */
1690 cmpwi r0,0x3c /* 970FX */
1692 cmpwi r0,0x44 /* 970MP */
1694 cmpwi r0,0x45 /* 970GX */
1696 1: bl .__cpu_preinit_ppc970
1699 /* Switch off MMU if not already */
1700 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1703 b .__after_prom_start
1705 _INIT_STATIC(__boot_from_prom)
1706 /* Save parameters */
1714 * Align the stack to 16-byte boundary
1715 * Depending on the size and layout of the ELF sections in the initial
1716 * boot binary, the stack pointer will be unalignet on PowerMac
1720 /* Make sure we are running in 64 bits mode */
1723 /* put a relocation offset into r3 */
1726 LOAD_REG_IMMEDIATE(r2,__toc_start)
1730 /* Relocate the TOC from a virt addr to a real addr */
1733 /* Restore parameters */
1740 /* Do all of the interaction with OF client interface */
1742 /* We never return */
1745 _STATIC(__after_prom_start)
1748 * We need to run with __start at physical address PHYSICAL_START.
1749 * This will leave some code in the first 256B of
1750 * real memory, which are reserved for software use.
1751 * The remainder of the first page is loaded with the fixed
1752 * interrupt vectors. The next two pages are filled with
1753 * unknown exception placeholders.
1755 * Note: This process overwrites the OF exception vectors.
1756 * r26 == relocation offset
1761 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1763 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1765 // XXX FIXME: Use phys returned by OF (r30)
1766 add r4,r27,r26 /* source addr */
1767 /* current address of _start */
1768 /* i.e. where we are running */
1769 /* the source addr */
1771 cmpdi r4,0 /* In some cases the loader may */
1773 b .start_here_multiplatform /* have already put us at zero */
1774 /* so we can skip the copy. */
1775 1: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1778 li r6,0x100 /* Start offset, the first 0x100 */
1779 /* bytes were copied earlier. */
1781 bl .copy_and_flush /* copy the first n bytes */
1782 /* this includes the code being */
1783 /* executed here. */
1785 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1786 mtctr r0 /* that we just made/relocated */
1789 4: LOAD_REG_IMMEDIATE(r5,klimit)
1791 ld r5,0(r5) /* get the value of klimit */
1793 bl .copy_and_flush /* copy the rest */
1794 b .start_here_multiplatform
1797 * Copy routine used to copy the kernel to start at physical address 0
1798 * and flush and invalidate the caches as needed.
1799 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1800 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1802 * Note: this routine *only* clobbers r0, r6 and lr
1804 _GLOBAL(copy_and_flush)
1807 4: li r0,8 /* Use the smallest common */
1808 /* denominator cache line */
1809 /* size. This results in */
1810 /* extra cache line flushes */
1811 /* but operation is correct. */
1812 /* Can't get cache line size */
1813 /* from NACA as it is being */
1816 mtctr r0 /* put # words/line in ctr */
1817 3: addi r6,r6,8 /* copy a cache line */
1821 dcbst r6,r3 /* write it to memory */
1823 icbi r6,r3 /* flush the icache line */
1835 #ifdef CONFIG_PPC_PMAC
1837 * On PowerMac, secondary processors starts from the reset vector, which
1838 * is temporarily turned into a call to one of the functions below.
1843 .globl __secondary_start_pmac_0
1844 __secondary_start_pmac_0:
1845 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1855 _GLOBAL(pmac_secondary_start)
1856 /* turn on 64-bit mode */
1859 /* Copy some CPU settings from CPU 0 */
1860 bl .__restore_cpu_ppc970
1862 /* pSeries do that early though I don't think we really need it */
1865 mtmsrd r3 /* RI on */
1867 /* Set up a paca value for this processor. */
1868 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1869 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1870 add r13,r13,r4 /* for this processor. */
1871 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1873 /* Create a temp kernel stack for use before relocation is on. */
1874 ld r1,PACAEMERGSP(r13)
1875 subi r1,r1,STACK_FRAME_OVERHEAD
1879 #endif /* CONFIG_PPC_PMAC */
1882 * This function is called after the master CPU has released the
1883 * secondary processors. The execution environment is relocation off.
1884 * The paca for this processor has the following fields initialized at
1886 * 1. Processor number
1887 * 2. Segment table pointer (virtual address)
1888 * On entry the following are set:
1889 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1890 * r24 = cpu# (in Linux terms)
1891 * r13 = paca virtual address
1892 * SPRG3 = paca virtual address
1895 /* Set thread priority to MEDIUM */
1901 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1902 bl .early_setup_secondary
1904 /* Initialize the kernel stack. Just a repeat for iSeries. */
1905 LOAD_REG_ADDR(r3, current_set)
1906 sldi r28,r24,3 /* get current_set[cpu#] */
1908 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1909 std r1,PACAKSAVE(r13)
1911 /* Clear backchain so we get nice backtraces */
1915 /* enable MMU and jump to start_secondary */
1916 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1917 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1918 #ifdef CONFIG_PPC_ISERIES
1919 BEGIN_FW_FTR_SECTION
1921 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1923 BEGIN_FW_FTR_SECTION
1924 stb r7,PACASOFTIRQEN(r13)
1925 stb r7,PACAHARDIRQEN(r13)
1926 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1931 b . /* prevent speculative execution */
1934 * Running with relocation on at this point. All we want to do is
1935 * zero the stack back-chain pointer before going into C code.
1937 _GLOBAL(start_secondary_prolog)
1939 std r3,0(r1) /* Zero the stack frame pointer */
1945 * This subroutine clobbers r11 and r12
1947 _GLOBAL(enable_64b_mode)
1948 mfmsr r11 /* grab the current MSR */
1950 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1953 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1960 * This is where the main kernel code starts.
1962 _INIT_STATIC(start_here_multiplatform)
1963 /* get a new offset, now that the kernel has moved. */
1967 /* Clear out the BSS. It may have been done in prom_init,
1968 * already but that's irrelevant since prom_init will soon
1969 * be detached from the kernel completely. Besides, we need
1970 * to clear it now for kexec-style entry.
1972 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1973 LOAD_REG_IMMEDIATE(r8,__bss_start)
1974 sub r11,r11,r8 /* bss size */
1975 addi r11,r11,7 /* round up to an even double word */
1976 rldicl. r11,r11,61,3 /* shift right by 3 */
1980 mtctr r11 /* zero this many doublewords */
1987 mtmsrd r6 /* RI on */
1989 /* The following gets the stack and TOC set up with the regs */
1990 /* pointing to the real addr of the kernel stack. This is */
1991 /* all done to support the C function call below which sets */
1992 /* up the htab. This is done because we have relocated the */
1993 /* kernel but are still running in real mode. */
1995 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1998 /* set up a stack pointer (physical address) */
1999 addi r1,r3,THREAD_SIZE
2001 stdu r0,-STACK_FRAME_OVERHEAD(r1)
2003 /* set up the TOC (physical address) */
2004 LOAD_REG_IMMEDIATE(r2,__toc_start)
2009 /* Do very early kernel initializations, including initial hash table,
2010 * stab and slb setup before we turn on relocation. */
2012 /* Restore parameters passed from prom_init/kexec */
2016 LOAD_REG_IMMEDIATE(r3, .start_here_common)
2017 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
2021 b . /* prevent speculative execution */
2023 /* This is where all platforms converge execution */
2024 _INIT_STATIC(start_here_common)
2025 /* relocation is on at this point */
2027 /* The following code sets up the SP and TOC now that we are */
2028 /* running with translation enabled. */
2030 LOAD_REG_IMMEDIATE(r3,init_thread_union)
2032 /* set up the stack */
2033 addi r1,r3,THREAD_SIZE
2035 stdu r0,-STACK_FRAME_OVERHEAD(r1)
2037 /* ptr to current */
2038 LOAD_REG_IMMEDIATE(r4, init_task)
2039 std r4,PACACURRENT(r13)
2043 std r1,PACAKSAVE(r13)
2047 /* Load up the kernel context */
2050 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
2051 #ifdef CONFIG_PPC_ISERIES
2052 BEGIN_FW_FTR_SECTION
2054 ori r5,r5,MSR_EE /* Hard Enabled */
2056 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
2058 BEGIN_FW_FTR_SECTION
2059 stb r5,PACAHARDIRQEN(r13)
2060 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
2068 * We put a few things here that have to be page-aligned.
2069 * This stuff goes at the beginning of the bss, which is page-aligned.
2075 .globl empty_zero_page
2079 .globl swapper_pg_dir
2084 * This space gets a copy of optional info passed to us by the bootstrap
2085 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2089 .space COMMAND_LINE_SIZE