2 * arch/ppc64/kernel/head.S
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
8 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
9 * Adapted for Power Macintosh by Paul Mackerras.
10 * Low-level exception handlers and MMU support
11 * rewritten by Paul Mackerras.
12 * Copyright (C) 1996 Paul Mackerras.
14 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
15 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
17 * This file contains the low-level support and setup for the
18 * PowerPC-64 platform, including trap and interrupt dispatch.
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version
23 * 2 of the License, or (at your option) any later version.
26 #include <linux/config.h>
27 #include <linux/threads.h>
31 #include <asm/ppc_asm.h>
32 #include <asm/asm-offsets.h>
34 #include <asm/cputable.h>
35 #include <asm/setup.h>
36 #include <asm/hvcall.h>
37 #include <asm/iseries/lpar_map.h>
38 #include <asm/thread_info.h>
40 #ifdef CONFIG_PPC_ISERIES
41 #define DO_SOFT_DISABLE
45 * We layout physical memory as follows:
46 * 0x0000 - 0x00ff : Secondary processor spin code
47 * 0x0100 - 0x2fff : pSeries Interrupt prologs
48 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
49 * 0x6000 - 0x6fff : Initial (CPU0) segment table
50 * 0x7000 - 0x7fff : FWNMI data area
51 * 0x8000 - : Early init and support code
59 * SPRG0 reserved for hypervisor
60 * SPRG1 temp - used to save gpr
61 * SPRG2 temp - used to save gpr
62 * SPRG3 virt addr of paca
66 * Entering into this code we make the following assumptions:
68 * 1. The MMU is off & open firmware is running in real mode.
69 * 2. The kernel is entered at __start
72 * 1. The MMU is on (as it always is for iSeries)
73 * 2. The kernel is entered at system_reset_iSeries
79 #ifdef CONFIG_PPC_MULTIPLATFORM
81 /* NOP this out unconditionally */
83 b .__start_initialization_multiplatform
85 #endif /* CONFIG_PPC_MULTIPLATFORM */
87 /* Catch branch to 0 in real mode */
90 #ifdef CONFIG_PPC_ISERIES
92 * At offset 0x20, there is a pointer to iSeries LPAR data.
93 * This is required by the hypervisor
96 .llong hvReleaseData-KERNELBASE
99 * At offset 0x28 and 0x30 are offsets to the mschunks_map
100 * array (used by the iSeries LPAR debugger to do translation
101 * between physical addresses and absolute addresses) and
102 * to the pidhash table (also used by the debugger)
104 .llong mschunks_map-KERNELBASE
105 .llong 0 /* pidhash-KERNELBASE SFRXXX */
107 /* Offset 0x38 - Pointer to start of embedded System.map */
108 .globl embedded_sysmap_start
109 embedded_sysmap_start:
111 /* Offset 0x40 - Pointer to end of embedded System.map */
112 .globl embedded_sysmap_end
116 #endif /* CONFIG_PPC_ISERIES */
118 /* Secondary processors spin on this value until it goes to 1. */
119 .globl __secondary_hold_spinloop
120 __secondary_hold_spinloop:
123 /* Secondary processors write this value with their cpu # */
124 /* after they enter the spin loop immediately below. */
125 .globl __secondary_hold_acknowledge
126 __secondary_hold_acknowledge:
131 * The following code is used on pSeries to hold secondary processors
132 * in a spin loop after they have been freed from OpenFirmware, but
133 * before the bulk of the kernel has been relocated. This code
134 * is relocated to physical address 0x60 before prom_init is run.
135 * All of it must fit below the first exception vector at 0x100.
137 _GLOBAL(__secondary_hold)
140 mtmsrd r24 /* RI on */
142 /* Grab our linux cpu number */
145 /* Tell the master cpu we're here */
146 /* Relocation is off & we are located at an address less */
147 /* than 0x100, so only need to grab low order offset. */
148 std r24,__secondary_hold_acknowledge@l(0)
151 /* All secondary cpus wait here until told to start. */
152 100: ld r4,__secondary_hold_spinloop@l(0)
157 SET_REG_IMMEDIATE(r4, .hmt_init)
160 #elif defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
161 LOAD_REG_IMMEDIATE(r4, .pSeries_secondary_smp_init)
169 /* This value is used to mark exception frames on the stack. */
172 .tc ID_72656773_68657265[TC],0x7265677368657265
176 * The following macros define the code that appears as
177 * the prologue to each of the exception handlers. They
178 * are split into two parts to allow a single kernel binary
179 * to be used for pSeries and iSeries.
180 * LOL. One day... - paulus
184 * We make as much of the exception code common between native
185 * exception handlers (including pSeries LPAR) and iSeries LPAR
186 * implementations as possible.
190 * This is the start of the interrupt handlers for pSeries
191 * This code runs with relocation off.
206 * We're short on space and time in the exception prolog, so we can't
207 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
208 * low halfword of the address, but for Kdump we need the whole low
211 #ifdef CONFIG_CRASH_DUMP
212 #define LOAD_HANDLER(reg, label) \
213 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
214 ori reg,reg,(label)@l; /* .. and the rest */
216 #define LOAD_HANDLER(reg, label) \
217 ori reg,reg,(label)@l; /* virt addr of handler ... */
220 #define EXCEPTION_PROLOG_PSERIES(area, label) \
221 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
222 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
223 std r10,area+EX_R10(r13); \
224 std r11,area+EX_R11(r13); \
225 std r12,area+EX_R12(r13); \
226 mfspr r9,SPRN_SPRG1; \
227 std r9,area+EX_R13(r13); \
229 clrrdi r12,r13,32; /* get high part of &label */ \
231 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
232 LOAD_HANDLER(r12,label) \
233 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
234 mtspr SPRN_SRR0,r12; \
235 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
236 mtspr SPRN_SRR1,r10; \
238 b . /* prevent speculative execution */
241 * This is the start of the interrupt handlers for iSeries
242 * This code runs with relocation on.
244 #define EXCEPTION_PROLOG_ISERIES_1(area) \
245 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
246 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
247 std r10,area+EX_R10(r13); \
248 std r11,area+EX_R11(r13); \
249 std r12,area+EX_R12(r13); \
250 mfspr r9,SPRN_SPRG1; \
251 std r9,area+EX_R13(r13); \
254 #define EXCEPTION_PROLOG_ISERIES_2 \
256 ld r12,PACALPPACAPTR(r13); \
257 ld r11,LPPACASRR0(r12); \
258 ld r12,LPPACASRR1(r12); \
259 ori r10,r10,MSR_RI; \
263 * The common exception prolog is used for all except a few exceptions
264 * such as a segment miss on a kernel address. We have to be prepared
265 * to take another exception from the point where we first touch the
266 * kernel stack onwards.
268 * On entry r13 points to the paca, r9-r13 are saved in the paca,
269 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
270 * SRR1, and relocation is on.
272 #define EXCEPTION_PROLOG_COMMON(n, area) \
273 andi. r10,r12,MSR_PR; /* See if coming from user */ \
274 mr r10,r1; /* Save r1 */ \
275 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
277 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
278 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
279 bge- cr1,bad_stack; /* abort if it is */ \
280 std r9,_CCR(r1); /* save CR in stackframe */ \
281 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
282 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
283 std r10,0(r1); /* make stack chain pointer */ \
284 std r0,GPR0(r1); /* save r0 in stackframe */ \
285 std r10,GPR1(r1); /* save r1 in stackframe */ \
286 std r2,GPR2(r1); /* save r2 in stackframe */ \
287 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
288 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
289 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
290 ld r10,area+EX_R10(r13); \
293 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
294 ld r10,area+EX_R12(r13); \
295 ld r11,area+EX_R13(r13); \
299 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
300 mflr r9; /* save LR in stackframe */ \
302 mfctr r10; /* save CTR in stackframe */ \
304 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
307 std r9,_TRAP(r1); /* set trap number */ \
309 ld r11,exception_marker@toc(r2); \
310 std r10,RESULT(r1); /* clear regs->result */ \
311 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
316 #define STD_EXCEPTION_PSERIES(n, label) \
318 .globl label##_pSeries; \
321 mtspr SPRN_SPRG1,r13; /* save r13 */ \
323 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
325 #define STD_EXCEPTION_ISERIES(n, label, area) \
326 .globl label##_iSeries; \
329 mtspr SPRN_SPRG1,r13; /* save r13 */ \
331 EXCEPTION_PROLOG_ISERIES_1(area); \
332 EXCEPTION_PROLOG_ISERIES_2; \
335 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
336 .globl label##_iSeries; \
339 mtspr SPRN_SPRG1,r13; /* save r13 */ \
341 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
342 lbz r10,PACAPROCENABLED(r13); \
344 beq- label##_iSeries_masked; \
345 EXCEPTION_PROLOG_ISERIES_2; \
348 #ifdef DO_SOFT_DISABLE
349 #define DISABLE_INTS \
350 lbz r10,PACAPROCENABLED(r13); \
354 stb r11,PACAPROCENABLED(r13); \
355 ori r10,r10,MSR_EE; \
358 #define ENABLE_INTS \
359 lbz r10,PACAPROCENABLED(r13); \
362 ori r11,r11,MSR_EE; \
365 #else /* hard enable/disable interrupts */
368 #define ENABLE_INTS \
371 rlwimi r11,r12,0,MSR_EE; \
376 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
378 .globl label##_common; \
380 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
383 addi r3,r1,STACK_FRAME_OVERHEAD; \
387 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
389 .globl label##_common; \
391 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
393 addi r3,r1,STACK_FRAME_OVERHEAD; \
395 b .ret_from_except_lite
398 * Start of pSeries system interrupt routines
401 .globl __start_interrupts
404 STD_EXCEPTION_PSERIES(0x100, system_reset)
407 _machine_check_pSeries:
409 mtspr SPRN_SPRG1,r13 /* save r13 */
411 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
414 .globl data_access_pSeries
423 rlwimi r13,r12,16,0x20
426 beq .do_stab_bolted_pSeries
429 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
430 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
433 .globl data_access_slb_pSeries
434 data_access_slb_pSeries:
438 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
439 std r3,PACA_EXSLB+EX_R3(r13)
441 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
444 /* Keep that around for when we re-implement dynamic VSIDs */
446 bge slb_miss_user_pseries
447 #endif /* __DISABLED__ */
448 std r10,PACA_EXSLB+EX_R10(r13)
449 std r11,PACA_EXSLB+EX_R11(r13)
450 std r12,PACA_EXSLB+EX_R12(r13)
452 std r10,PACA_EXSLB+EX_R13(r13)
453 mfspr r12,SPRN_SRR1 /* and SRR1 */
454 b .slb_miss_realmode /* Rel. branch works in real mode */
456 STD_EXCEPTION_PSERIES(0x400, instruction_access)
459 .globl instruction_access_slb_pSeries
460 instruction_access_slb_pSeries:
464 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
465 std r3,PACA_EXSLB+EX_R3(r13)
466 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
467 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
470 /* Keep that around for when we re-implement dynamic VSIDs */
472 bge slb_miss_user_pseries
473 #endif /* __DISABLED__ */
474 std r10,PACA_EXSLB+EX_R10(r13)
475 std r11,PACA_EXSLB+EX_R11(r13)
476 std r12,PACA_EXSLB+EX_R12(r13)
478 std r10,PACA_EXSLB+EX_R13(r13)
479 mfspr r12,SPRN_SRR1 /* and SRR1 */
480 b .slb_miss_realmode /* Rel. branch works in real mode */
482 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
483 STD_EXCEPTION_PSERIES(0x600, alignment)
484 STD_EXCEPTION_PSERIES(0x700, program_check)
485 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
486 STD_EXCEPTION_PSERIES(0x900, decrementer)
487 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
488 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
491 .globl system_call_pSeries
500 oris r12,r12,system_call_common@h
501 ori r12,r12,system_call_common@l
503 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
507 b . /* prevent speculative execution */
509 STD_EXCEPTION_PSERIES(0xd00, single_step)
510 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
512 /* We need to deal with the Altivec unavailable exception
513 * here which is at 0xf20, thus in the middle of the
514 * prolog code of the PerformanceMonitor one. A little
515 * trickery is thus necessary
518 b performance_monitor_pSeries
520 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
522 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
523 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
527 /*** pSeries interrupt support ***/
529 /* moved from 0xf00 */
530 STD_EXCEPTION_PSERIES(., performance_monitor)
533 _GLOBAL(do_stab_bolted_pSeries)
536 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
539 * We have some room here we use that to put
540 * the peries slb miss user trampoline code so it's reasonably
541 * away from slb_miss_user_common to avoid problems with rfid
543 * This is used for when the SLB miss handler has to go virtual,
544 * which doesn't happen for now anymore but will once we re-implement
545 * dynamic VSIDs for shared page tables
548 slb_miss_user_pseries:
549 std r10,PACA_EXGEN+EX_R10(r13)
550 std r11,PACA_EXGEN+EX_R11(r13)
551 std r12,PACA_EXGEN+EX_R12(r13)
553 ld r11,PACA_EXSLB+EX_R9(r13)
554 ld r12,PACA_EXSLB+EX_R3(r13)
555 std r10,PACA_EXGEN+EX_R13(r13)
556 std r11,PACA_EXGEN+EX_R9(r13)
557 std r12,PACA_EXGEN+EX_R3(r13)
560 mfspr r11,SRR0 /* save SRR0 */
561 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
562 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
564 mfspr r12,SRR1 /* and SRR1 */
567 b . /* prevent spec. execution */
568 #endif /* __DISABLED__ */
571 * Vectors for the FWNMI option. Share common code.
573 .globl system_reset_fwnmi
577 mtspr SPRN_SPRG1,r13 /* save r13 */
579 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
581 .globl machine_check_fwnmi
585 mtspr SPRN_SPRG1,r13 /* save r13 */
587 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
589 #ifdef CONFIG_PPC_ISERIES
590 /*** ISeries-LPAR interrupt handlers ***/
592 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
594 .globl data_access_iSeries
602 rlwimi r13,r12,16,0x20
605 beq .do_stab_bolted_iSeries
608 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
609 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
610 EXCEPTION_PROLOG_ISERIES_2
613 .do_stab_bolted_iSeries:
616 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
617 EXCEPTION_PROLOG_ISERIES_2
620 .globl data_access_slb_iSeries
621 data_access_slb_iSeries:
622 mtspr SPRN_SPRG1,r13 /* save r13 */
623 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
624 std r3,PACA_EXSLB+EX_R3(r13)
626 std r9,PACA_EXSLB+EX_R9(r13)
630 bge slb_miss_user_iseries
632 std r10,PACA_EXSLB+EX_R10(r13)
633 std r11,PACA_EXSLB+EX_R11(r13)
634 std r12,PACA_EXSLB+EX_R12(r13)
636 std r10,PACA_EXSLB+EX_R13(r13)
637 ld r12,PACALPPACAPTR(r13)
638 ld r12,LPPACASRR1(r12)
641 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
643 .globl instruction_access_slb_iSeries
644 instruction_access_slb_iSeries:
645 mtspr SPRN_SPRG1,r13 /* save r13 */
646 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
647 std r3,PACA_EXSLB+EX_R3(r13)
648 ld r3,PACALPPACAPTR(r13)
649 ld r3,LPPACASRR0(r3) /* get SRR0 value */
650 std r9,PACA_EXSLB+EX_R9(r13)
654 bge .slb_miss_user_iseries
656 std r10,PACA_EXSLB+EX_R10(r13)
657 std r11,PACA_EXSLB+EX_R11(r13)
658 std r12,PACA_EXSLB+EX_R12(r13)
660 std r10,PACA_EXSLB+EX_R13(r13)
661 ld r12,PACALPPACAPTR(r13)
662 ld r12,LPPACASRR1(r12)
666 slb_miss_user_iseries:
667 std r10,PACA_EXGEN+EX_R10(r13)
668 std r11,PACA_EXGEN+EX_R11(r13)
669 std r12,PACA_EXGEN+EX_R12(r13)
671 ld r11,PACA_EXSLB+EX_R9(r13)
672 ld r12,PACA_EXSLB+EX_R3(r13)
673 std r10,PACA_EXGEN+EX_R13(r13)
674 std r11,PACA_EXGEN+EX_R9(r13)
675 std r12,PACA_EXGEN+EX_R3(r13)
676 EXCEPTION_PROLOG_ISERIES_2
677 b slb_miss_user_common
680 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
681 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
682 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
683 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
684 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
685 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
686 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
688 .globl system_call_iSeries
692 EXCEPTION_PROLOG_ISERIES_2
695 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
696 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
697 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
699 .globl system_reset_iSeries
700 system_reset_iSeries:
701 mfspr r13,SPRN_SPRG3 /* Get paca address */
704 mtmsrd r24 /* RI on */
705 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
706 cmpwi 0,r24,0 /* Are we processor 0? */
707 beq .__start_initialization_iSeries /* Start up the first processor */
709 li r5,CTRL_RUNLATCH /* Turn off the run light */
716 lbz r23,PACAPROCSTART(r13) /* Test if this processor
719 LOAD_REG_IMMEDIATE(r3,current_set)
720 sldi r28,r24,3 /* get current_set[cpu#] */
722 addi r1,r3,THREAD_SIZE
723 subi r1,r1,STACK_FRAME_OVERHEAD
726 beq iSeries_secondary_smp_loop /* Loop until told to go */
727 bne .__secondary_start /* Loop until told to go */
728 iSeries_secondary_smp_loop:
729 /* Let the Hypervisor know we are alive */
730 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
732 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
733 #else /* CONFIG_SMP */
734 /* Yield the processor. This is required for non-SMP kernels
735 which are running on multi-threaded machines. */
737 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
738 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
739 li r4,0 /* "yield timed" */
740 li r5,-1 /* "yield forever" */
741 #endif /* CONFIG_SMP */
742 li r0,-1 /* r0=-1 indicates a Hypervisor call */
743 sc /* Invoke the hypervisor via a system call */
744 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
745 b 1b /* If SMP not configured, secondaries
748 .globl decrementer_iSeries_masked
749 decrementer_iSeries_masked:
750 /* We may not have a valid TOC pointer in here. */
752 ld r12,PACALPPACAPTR(r13)
753 stb r11,LPPACADECRINT(r12)
754 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
759 .globl hardware_interrupt_iSeries_masked
760 hardware_interrupt_iSeries_masked:
761 mtcrf 0x80,r9 /* Restore regs */
762 ld r12,PACALPPACAPTR(r13)
763 ld r11,LPPACASRR0(r12)
764 ld r12,LPPACASRR1(r12)
767 ld r9,PACA_EXGEN+EX_R9(r13)
768 ld r10,PACA_EXGEN+EX_R10(r13)
769 ld r11,PACA_EXGEN+EX_R11(r13)
770 ld r12,PACA_EXGEN+EX_R12(r13)
771 ld r13,PACA_EXGEN+EX_R13(r13)
773 b . /* prevent speculative execution */
774 #endif /* CONFIG_PPC_ISERIES */
776 /*** Common interrupt handlers ***/
778 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
781 * Machine check is different because we use a different
782 * save area: PACA_EXMC instead of PACA_EXGEN.
785 .globl machine_check_common
786 machine_check_common:
787 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
790 addi r3,r1,STACK_FRAME_OVERHEAD
791 bl .machine_check_exception
794 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
795 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
796 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
797 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
798 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
799 STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
800 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
801 #ifdef CONFIG_ALTIVEC
802 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
804 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
808 * Here we have detected that the kernel stack pointer is bad.
809 * R9 contains the saved CR, r13 points to the paca,
810 * r10 contains the (bad) kernel stack pointer,
811 * r11 and r12 contain the saved SRR0 and SRR1.
812 * We switch to using an emergency stack, save the registers there,
813 * and call kernel_bad_stack(), which panics.
816 ld r1,PACAEMERGSP(r13)
817 subi r1,r1,64+INT_FRAME_SIZE
838 addi r11,r1,INT_FRAME_SIZE
843 1: addi r3,r1,STACK_FRAME_OVERHEAD
848 * Return from an exception with minimal checks.
849 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
850 * If interrupts have been enabled, or anything has been
851 * done that might have changed the scheduling status of
852 * any task or sent any task a signal, you should use
853 * ret_from_except or ret_from_except_lite instead of this.
855 .globl fast_exception_return
856 fast_exception_return:
859 andi. r3,r12,MSR_RI /* check if RI is set */
873 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
881 b . /* prevent speculative execution */
885 1: addi r3,r1,STACK_FRAME_OVERHEAD
886 bl .unrecoverable_exception
890 * Here r13 points to the paca, r9 contains the saved CR,
891 * SRR0 and SRR1 are saved in r11 and r12,
892 * r9 - r13 are saved in paca->exgen.
895 .globl data_access_common
897 RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
899 std r10,PACA_EXGEN+EX_DAR(r13)
901 stw r10,PACA_EXGEN+EX_DSISR(r13)
902 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
903 ld r3,PACA_EXGEN+EX_DAR(r13)
904 lwz r4,PACA_EXGEN+EX_DSISR(r13)
906 b .do_hash_page /* Try to handle as hpte fault */
909 .globl instruction_access_common
910 instruction_access_common:
911 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
915 b .do_hash_page /* Try to handle as hpte fault */
918 * Here is the common SLB miss user that is used when going to virtual
919 * mode for SLB misses, that is currently not used
923 .globl slb_miss_user_common
924 slb_miss_user_common:
926 std r3,PACA_EXGEN+EX_DAR(r13)
927 stw r9,PACA_EXGEN+EX_CCR(r13)
928 std r10,PACA_EXGEN+EX_LR(r13)
929 std r11,PACA_EXGEN+EX_SRR0(r13)
930 bl .slb_allocate_user
932 ld r10,PACA_EXGEN+EX_LR(r13)
933 ld r3,PACA_EXGEN+EX_R3(r13)
934 lwz r9,PACA_EXGEN+EX_CCR(r13)
935 ld r11,PACA_EXGEN+EX_SRR0(r13)
939 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
940 beq- unrecov_user_slb
948 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
954 ld r9,PACA_EXGEN+EX_R9(r13)
955 ld r10,PACA_EXGEN+EX_R10(r13)
956 ld r11,PACA_EXGEN+EX_R11(r13)
957 ld r12,PACA_EXGEN+EX_R12(r13)
958 ld r13,PACA_EXGEN+EX_R13(r13)
963 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
964 ld r4,PACA_EXGEN+EX_DAR(r13)
971 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
974 1: addi r3,r1,STACK_FRAME_OVERHEAD
975 bl .unrecoverable_exception
978 #endif /* __DISABLED__ */
982 * r13 points to the PACA, r9 contains the saved CR,
983 * r12 contain the saved SRR1, SRR0 is still ready for return
984 * r3 has the faulting address
985 * r9 - r13 are saved in paca->exslb.
986 * r3 is saved in paca->slb_r3
987 * We assume we aren't going to take any exceptions during this procedure.
989 _GLOBAL(slb_miss_realmode)
992 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
993 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
995 bl .slb_allocate_realmode
997 /* All done -- return from exception. */
999 ld r10,PACA_EXSLB+EX_LR(r13)
1000 ld r3,PACA_EXSLB+EX_R3(r13)
1001 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1002 #ifdef CONFIG_PPC_ISERIES
1003 ld r11,PACALPPACAPTR(r13)
1004 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1005 #endif /* CONFIG_PPC_ISERIES */
1009 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1015 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1018 #ifdef CONFIG_PPC_ISERIES
1021 #endif /* CONFIG_PPC_ISERIES */
1022 ld r9,PACA_EXSLB+EX_R9(r13)
1023 ld r10,PACA_EXSLB+EX_R10(r13)
1024 ld r11,PACA_EXSLB+EX_R11(r13)
1025 ld r12,PACA_EXSLB+EX_R12(r13)
1026 ld r13,PACA_EXSLB+EX_R13(r13)
1028 b . /* prevent speculative execution */
1031 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1034 1: addi r3,r1,STACK_FRAME_OVERHEAD
1035 bl .unrecoverable_exception
1039 .globl hardware_interrupt_common
1040 .globl hardware_interrupt_entry
1041 hardware_interrupt_common:
1042 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1043 hardware_interrupt_entry:
1045 addi r3,r1,STACK_FRAME_OVERHEAD
1047 b .ret_from_except_lite
1050 .globl alignment_common
1053 std r10,PACA_EXGEN+EX_DAR(r13)
1054 mfspr r10,SPRN_DSISR
1055 stw r10,PACA_EXGEN+EX_DSISR(r13)
1056 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1057 ld r3,PACA_EXGEN+EX_DAR(r13)
1058 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1062 addi r3,r1,STACK_FRAME_OVERHEAD
1064 bl .alignment_exception
1068 .globl program_check_common
1069 program_check_common:
1070 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1072 addi r3,r1,STACK_FRAME_OVERHEAD
1074 bl .program_check_exception
1078 .globl fp_unavailable_common
1079 fp_unavailable_common:
1080 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1081 bne .load_up_fpu /* if from user, just load it up */
1083 addi r3,r1,STACK_FRAME_OVERHEAD
1085 bl .kernel_fp_unavailable_exception
1089 .globl altivec_unavailable_common
1090 altivec_unavailable_common:
1091 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1092 #ifdef CONFIG_ALTIVEC
1094 bne .load_up_altivec /* if from user, just load it up */
1095 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1098 addi r3,r1,STACK_FRAME_OVERHEAD
1100 bl .altivec_unavailable_exception
1103 #ifdef CONFIG_ALTIVEC
1105 * load_up_altivec(unused, unused, tsk)
1106 * Disable VMX for the task which had it previously,
1107 * and save its vector registers in its thread_struct.
1108 * Enables the VMX for use in the kernel on return.
1109 * On SMP we know the VMX is free, since we give it up every
1110 * switch (ie, no lazy save of the vector registers).
1111 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1113 _STATIC(load_up_altivec)
1114 mfmsr r5 /* grab the current MSR */
1115 oris r5,r5,MSR_VEC@h
1116 mtmsrd r5 /* enable use of VMX now */
1120 * For SMP, we don't do lazy VMX switching because it just gets too
1121 * horrendously complex, especially when a task switches from one CPU
1122 * to another. Instead we call giveup_altvec in switch_to.
1123 * VRSAVE isn't dealt with here, that is done in the normal context
1124 * switch code. Note that we could rely on vrsave value to eventually
1125 * avoid saving all of the VREGs here...
1128 ld r3,last_task_used_altivec@got(r2)
1132 /* Save VMX state to last_task_used_altivec's THREAD struct */
1138 /* Disable VMX for last_task_used_altivec */
1140 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1143 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1145 #endif /* CONFIG_SMP */
1146 /* Hack: if we get an altivec unavailable trap with VRSAVE
1147 * set to all zeros, we assume this is a broken application
1148 * that fails to set it properly, and thus we switch it to
1151 mfspr r4,SPRN_VRSAVE
1155 mtspr SPRN_VRSAVE,r4
1157 /* enable use of VMX after return */
1158 ld r4,PACACURRENT(r13)
1159 addi r5,r4,THREAD /* Get THREAD */
1160 oris r12,r12,MSR_VEC@h
1164 stw r4,THREAD_USED_VR(r5)
1169 /* Update last_task_used_math to 'current' */
1170 subi r4,r5,THREAD /* Back to 'current' */
1172 #endif /* CONFIG_SMP */
1173 /* restore registers and return */
1174 b fast_exception_return
1175 #endif /* CONFIG_ALTIVEC */
1181 _GLOBAL(do_hash_page)
1185 andis. r0,r4,0xa450 /* weird error? */
1186 bne- .handle_page_fault /* if not, try to insert a HPTE */
1188 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1189 bne- .do_ste_alloc /* If so handle it */
1190 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1193 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1194 * accessing a userspace segment (even from the kernel). We assume
1195 * kernel addresses always have the high bit set.
1197 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1198 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1199 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1200 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1201 ori r4,r4,1 /* add _PAGE_PRESENT */
1202 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1205 * On iSeries, we soft-disable interrupts here, then
1206 * hard-enable interrupts so that the hash_page code can spin on
1207 * the hash_table_lock without problems on a shared processor.
1212 * r3 contains the faulting address
1213 * r4 contains the required access permissions
1214 * r5 contains the trap number
1216 * at return r3 = 0 for success
1218 bl .hash_page /* build HPTE if possible */
1219 cmpdi r3,0 /* see if hash_page succeeded */
1221 #ifdef DO_SOFT_DISABLE
1223 * If we had interrupts soft-enabled at the point where the
1224 * DSI/ISI occurred, and an interrupt came in during hash_page,
1226 * We jump to ret_from_except_lite rather than fast_exception_return
1227 * because ret_from_except_lite will check for and handle pending
1228 * interrupts if necessary.
1230 beq .ret_from_except_lite
1231 /* For a hash failure, we don't bother re-enabling interrupts */
1235 * hash_page couldn't handle it, set soft interrupt enable back
1236 * to what it was before the trap. Note that .local_irq_restore
1237 * handles any interrupts pending at this point.
1240 bl .local_irq_restore
1243 beq fast_exception_return /* Return from exception on success */
1244 ble- 12f /* Failure return from hash_page */
1249 /* Here we have a page fault that hash_page can't handle. */
1250 _GLOBAL(handle_page_fault)
1254 addi r3,r1,STACK_FRAME_OVERHEAD
1257 beq+ .ret_from_except_lite
1260 addi r3,r1,STACK_FRAME_OVERHEAD
1265 /* We have a page fault that hash_page could handle but HV refused
1269 addi r3,r1,STACK_FRAME_OVERHEAD
1274 /* here we have a segment miss */
1275 _GLOBAL(do_ste_alloc)
1276 bl .ste_allocate /* try to insert stab entry */
1278 beq+ fast_exception_return
1279 b .handle_page_fault
1282 * r13 points to the PACA, r9 contains the saved CR,
1283 * r11 and r12 contain the saved SRR0 and SRR1.
1284 * r9 - r13 are saved in paca->exslb.
1285 * We assume we aren't going to take any exceptions during this procedure.
1286 * We assume (DAR >> 60) == 0xc.
1289 _GLOBAL(do_stab_bolted)
1290 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1291 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1293 /* Hash to the primary group */
1294 ld r10,PACASTABVIRT(r13)
1297 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1299 /* Calculate VSID */
1300 /* This is a kernel address, so protovsid = ESID */
1301 ASM_VSID_SCRAMBLE(r11, r9)
1302 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1304 /* Search the primary group for a free entry */
1305 1: ld r11,0(r10) /* Test valid bit of the current ste */
1312 /* Stick for only searching the primary group for now. */
1313 /* At least for now, we use a very simple random castout scheme */
1314 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1316 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1319 /* r10 currently points to an ste one past the group of interest */
1320 /* make it point to the randomly selected entry */
1322 or r10,r10,r11 /* r10 is the entry to invalidate */
1324 isync /* mark the entry invalid */
1326 rldicl r11,r11,56,1 /* clear the valid bit */
1331 clrrdi r11,r11,28 /* Get the esid part of the ste */
1334 2: std r9,8(r10) /* Store the vsid part of the ste */
1337 mfspr r11,SPRN_DAR /* Get the new esid */
1338 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1339 ori r11,r11,0x90 /* Turn on valid and kp */
1340 std r11,0(r10) /* Put new entry back into the stab */
1344 /* All done -- return from exception. */
1345 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1346 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1348 andi. r10,r12,MSR_RI
1351 mtcrf 0x80,r9 /* restore CR */
1359 ld r9,PACA_EXSLB+EX_R9(r13)
1360 ld r10,PACA_EXSLB+EX_R10(r13)
1361 ld r11,PACA_EXSLB+EX_R11(r13)
1362 ld r12,PACA_EXSLB+EX_R12(r13)
1363 ld r13,PACA_EXSLB+EX_R13(r13)
1365 b . /* prevent speculative execution */
1368 * Space for CPU0's segment table.
1370 * On iSeries, the hypervisor must fill in at least one entry before
1371 * we get control (with relocate on). The address is give to the hv
1372 * as a page number (see xLparMap in lpardata.c), so this must be at a
1373 * fixed address (the linker can't compute (u64)&initial_stab >>
1376 . = STAB0_OFFSET /* 0x6000 */
1382 * Data area reserved for FWNMI option.
1383 * This address (0x7000) is fixed by the RPA.
1386 .globl fwnmi_data_area
1389 /* iSeries does not use the FWNMI stuff, so it is safe to put
1390 * this here, even if we later allow kernels that will boot on
1391 * both pSeries and iSeries */
1392 #ifdef CONFIG_PPC_ISERIES
1394 #include "lparmap.s"
1396 * This ".text" is here for old compilers that generate a trailing
1397 * .note section when compiling .c files to .s
1400 #endif /* CONFIG_PPC_ISERIES */
1405 * On pSeries, secondary processors spin in the following code.
1406 * At entry, r3 = this processor's number (physical cpu id)
1408 _GLOBAL(pSeries_secondary_smp_init)
1411 /* turn on 64-bit mode */
1415 /* Copy some CPU settings from CPU 0 */
1416 bl .__restore_cpu_setup
1418 /* Set up a paca value for this processor. Since we have the
1419 * physical cpu id in r24, we need to search the pacas to find
1420 * which logical id maps to our physical one.
1422 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1423 li r5,0 /* logical cpu id */
1424 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1425 cmpw r6,r24 /* Compare to our id */
1427 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1432 mr r3,r24 /* not found, copy phys to r3 */
1433 b .kexec_wait /* next kernel might do better */
1435 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1436 /* From now on, r24 is expected to be logical cpuid */
1439 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1443 /* Create a temp kernel stack for use before relocation is on. */
1444 ld r1,PACAEMERGSP(r13)
1445 subi r1,r1,STACK_FRAME_OVERHEAD
1449 bne .__secondary_start
1451 b 3b /* Loop until told to go */
1453 #ifdef CONFIG_PPC_ISERIES
1454 _STATIC(__start_initialization_iSeries)
1455 /* Clear out the BSS */
1456 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1457 LOAD_REG_IMMEDIATE(r8,__bss_start)
1458 sub r11,r11,r8 /* bss size */
1459 addi r11,r11,7 /* round up to an even double word */
1460 rldicl. r11,r11,61,3 /* shift right by 3 */
1464 mtctr r11 /* zero this many doublewords */
1468 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1469 addi r1,r1,THREAD_SIZE
1471 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1473 LOAD_REG_IMMEDIATE(r3,cpu_specs)
1474 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1478 LOAD_REG_IMMEDIATE(r2,__toc_start)
1482 bl .iSeries_early_setup
1485 /* relocation is on at this point */
1487 b .start_here_common
1488 #endif /* CONFIG_PPC_ISERIES */
1490 #ifdef CONFIG_PPC_MULTIPLATFORM
1494 andi. r0,r3,MSR_IR|MSR_DR
1501 b . /* prevent speculative execution */
1505 * Here is our main kernel entry point. We support currently 2 kind of entries
1506 * depending on the value of r5.
1508 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1511 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1512 * DT block, r4 is a physical pointer to the kernel itself
1515 _GLOBAL(__start_initialization_multiplatform)
1516 #ifdef CONFIG_PPC_MULTIPLATFORM
1518 * Are we booted from a PROM Of-type client-interface ?
1521 bne .__boot_from_prom /* yes -> prom */
1524 /* Save parameters */
1528 /* Make sure we are running in 64 bits mode */
1531 /* Setup some critical 970 SPRs before switching MMU off */
1532 bl .__970_cpu_preinit
1537 /* Switch off MMU if not already */
1538 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1541 b .__after_prom_start
1543 #ifdef CONFIG_PPC_MULTIPLATFORM
1544 _STATIC(__boot_from_prom)
1545 /* Save parameters */
1552 /* Make sure we are running in 64 bits mode */
1555 /* put a relocation offset into r3 */
1558 LOAD_REG_IMMEDIATE(r2,__toc_start)
1562 /* Relocate the TOC from a virt addr to a real addr */
1565 /* Restore parameters */
1572 /* Do all of the interaction with OF client interface */
1574 /* We never return */
1579 * At this point, r3 contains the physical address we are running at,
1580 * returned by prom_init()
1582 _STATIC(__after_prom_start)
1585 * We need to run with __start at physical address PHYSICAL_START.
1586 * This will leave some code in the first 256B of
1587 * real memory, which are reserved for software use.
1588 * The remainder of the first page is loaded with the fixed
1589 * interrupt vectors. The next two pages are filled with
1590 * unknown exception placeholders.
1592 * Note: This process overwrites the OF exception vectors.
1593 * r26 == relocation offset
1598 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1600 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1602 // XXX FIXME: Use phys returned by OF (r30)
1603 add r4,r27,r26 /* source addr */
1604 /* current address of _start */
1605 /* i.e. where we are running */
1606 /* the source addr */
1608 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1611 li r6,0x100 /* Start offset, the first 0x100 */
1612 /* bytes were copied earlier. */
1614 bl .copy_and_flush /* copy the first n bytes */
1615 /* this includes the code being */
1616 /* executed here. */
1618 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1619 mtctr r0 /* that we just made/relocated */
1622 4: LOAD_REG_IMMEDIATE(r5,klimit)
1624 ld r5,0(r5) /* get the value of klimit */
1626 bl .copy_and_flush /* copy the rest */
1627 b .start_here_multiplatform
1629 #endif /* CONFIG_PPC_MULTIPLATFORM */
1632 * Copy routine used to copy the kernel to start at physical address 0
1633 * and flush and invalidate the caches as needed.
1634 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1635 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1637 * Note: this routine *only* clobbers r0, r6 and lr
1639 _GLOBAL(copy_and_flush)
1642 4: li r0,16 /* Use the least common */
1643 /* denominator cache line */
1644 /* size. This results in */
1645 /* extra cache line flushes */
1646 /* but operation is correct. */
1647 /* Can't get cache line size */
1648 /* from NACA as it is being */
1651 mtctr r0 /* put # words/line in ctr */
1652 3: addi r6,r6,8 /* copy a cache line */
1656 dcbst r6,r3 /* write it to memory */
1658 icbi r6,r3 /* flush the icache line */
1670 #ifdef CONFIG_PPC_PMAC
1672 * On PowerMac, secondary processors starts from the reset vector, which
1673 * is temporarily turned into a call to one of the functions below.
1678 .globl __secondary_start_pmac_0
1679 __secondary_start_pmac_0:
1680 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1690 _GLOBAL(pmac_secondary_start)
1691 /* turn on 64-bit mode */
1695 /* Copy some CPU settings from CPU 0 */
1696 bl .__restore_cpu_setup
1698 /* pSeries do that early though I don't think we really need it */
1701 mtmsrd r3 /* RI on */
1703 /* Set up a paca value for this processor. */
1704 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1705 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1706 add r13,r13,r4 /* for this processor. */
1707 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1709 /* Create a temp kernel stack for use before relocation is on. */
1710 ld r1,PACAEMERGSP(r13)
1711 subi r1,r1,STACK_FRAME_OVERHEAD
1713 b .__secondary_start
1715 #endif /* CONFIG_PPC_PMAC */
1718 * This function is called after the master CPU has released the
1719 * secondary processors. The execution environment is relocation off.
1720 * The paca for this processor has the following fields initialized at
1722 * 1. Processor number
1723 * 2. Segment table pointer (virtual address)
1724 * On entry the following are set:
1725 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1726 * r24 = cpu# (in Linux terms)
1727 * r13 = paca virtual address
1728 * SPRG3 = paca virtual address
1730 _GLOBAL(__secondary_start)
1731 /* Set thread priority to MEDIUM */
1737 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1738 bl .early_setup_secondary
1740 /* Initialize the kernel stack. Just a repeat for iSeries. */
1741 LOAD_REG_ADDR(r3, current_set)
1742 sldi r28,r24,3 /* get current_set[cpu#] */
1744 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1745 std r1,PACAKSAVE(r13)
1747 /* Clear backchain so we get nice backtraces */
1751 /* enable MMU and jump to start_secondary */
1752 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1753 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1754 #ifdef DO_SOFT_DISABLE
1760 b . /* prevent speculative execution */
1763 * Running with relocation on at this point. All we want to do is
1764 * zero the stack back-chain pointer before going into C code.
1766 _GLOBAL(start_secondary_prolog)
1768 std r3,0(r1) /* Zero the stack frame pointer */
1774 * This subroutine clobbers r11 and r12
1776 _GLOBAL(enable_64b_mode)
1777 mfmsr r11 /* grab the current MSR */
1779 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1782 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1788 #ifdef CONFIG_PPC_MULTIPLATFORM
1790 * This is where the main kernel code starts.
1792 _STATIC(start_here_multiplatform)
1793 /* get a new offset, now that the kernel has moved. */
1797 /* Clear out the BSS. It may have been done in prom_init,
1798 * already but that's irrelevant since prom_init will soon
1799 * be detached from the kernel completely. Besides, we need
1800 * to clear it now for kexec-style entry.
1802 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1803 LOAD_REG_IMMEDIATE(r8,__bss_start)
1804 sub r11,r11,r8 /* bss size */
1805 addi r11,r11,7 /* round up to an even double word */
1806 rldicl. r11,r11,61,3 /* shift right by 3 */
1810 mtctr r11 /* zero this many doublewords */
1817 mtmsrd r6 /* RI on */
1820 /* Start up the second thread on cpu 0 */
1823 cmpwi r3,0x34 /* Pulsar */
1825 cmpwi r3,0x36 /* Icestar */
1827 cmpwi r3,0x37 /* SStar */
1829 b 91f /* HMT not supported */
1831 bl .hmt_start_secondary
1835 /* The following gets the stack and TOC set up with the regs */
1836 /* pointing to the real addr of the kernel stack. This is */
1837 /* all done to support the C function call below which sets */
1838 /* up the htab. This is done because we have relocated the */
1839 /* kernel but are still running in real mode. */
1841 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1844 /* set up a stack pointer (physical address) */
1845 addi r1,r3,THREAD_SIZE
1847 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1849 /* set up the TOC (physical address) */
1850 LOAD_REG_IMMEDIATE(r2,__toc_start)
1855 LOAD_REG_IMMEDIATE(r3, cpu_specs)
1857 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1862 /* Save some low level config HIDs of CPU0 to be copied to
1863 * other CPUs later on, or used for suspend/resume
1865 bl .__save_cpu_setup
1868 /* Setup a valid physical PACA pointer in SPRG3 for early_setup
1869 * note that boot_cpuid can always be 0 nowadays since there is
1870 * nowhere it can be initialized differently before we reach this
1873 LOAD_REG_IMMEDIATE(r27, boot_cpuid)
1877 LOAD_REG_IMMEDIATE(r24, paca) /* Get base vaddr of paca array */
1878 mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
1879 add r13,r13,r24 /* for this processor. */
1880 add r13,r13,r26 /* convert to physical addr */
1881 mtspr SPRN_SPRG3,r13
1883 /* Do very early kernel initializations, including initial hash table,
1884 * stab and slb setup before we turn on relocation. */
1886 /* Restore parameters passed from prom_init/kexec */
1890 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1891 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1895 b . /* prevent speculative execution */
1896 #endif /* CONFIG_PPC_MULTIPLATFORM */
1898 /* This is where all platforms converge execution */
1899 _STATIC(start_here_common)
1900 /* relocation is on at this point */
1902 /* The following code sets up the SP and TOC now that we are */
1903 /* running with translation enabled. */
1905 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1907 /* set up the stack */
1908 addi r1,r3,THREAD_SIZE
1910 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1912 /* Apply the CPUs-specific fixups (nop out sections not relevant
1916 bl .do_cpu_ftr_fixups
1918 LOAD_REG_IMMEDIATE(r26, boot_cpuid)
1921 LOAD_REG_IMMEDIATE(r24, paca) /* Get base vaddr of paca array */
1922 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1923 add r13,r13,r24 /* for this processor. */
1924 mtspr SPRN_SPRG3,r13
1926 /* ptr to current */
1927 LOAD_REG_IMMEDIATE(r4, init_task)
1928 std r4,PACACURRENT(r13)
1932 std r1,PACAKSAVE(r13)
1936 /* Load up the kernel context */
1938 #ifdef DO_SOFT_DISABLE
1940 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1942 ori r5,r5,MSR_EE /* Hard Enabled */
1950 LOAD_REG_IMMEDIATE(r5, hmt_thread_data)
1953 cmpwi r7,0x34 /* Pulsar */
1955 cmpwi r7,0x36 /* Icestar */
1957 cmpwi r7,0x37 /* SStar */
1960 90: mfspr r6,SPRN_PIR
1963 91: mfspr r6,SPRN_PIR
1967 bl .hmt_start_secondary
1970 __hmt_secondary_hold:
1971 LOAD_REG_IMMEDIATE(r5, hmt_thread_data)
1981 93: andi. r6,r6,0x3f
1995 b .pSeries_secondary_smp_init
1998 _GLOBAL(hmt_start_secondary)
1999 LOAD_REG_IMMEDIATE(r4,__hmt_secondary_hold)
2001 mtspr SPRN_NIADORM, r4
2002 mfspr r4, SPRN_MSRDORM
2005 mtspr SPRN_MSRDORM, r4
2014 mfspr r4, SPRN_CTRLF
2016 mtspr SPRN_CTRLT, r4
2021 * We put a few things here that have to be page-aligned.
2022 * This stuff goes at the beginning of the bss, which is page-aligned.
2028 .globl empty_zero_page
2032 .globl swapper_pg_dir
2037 * This space gets a copy of optional info passed to us by the bootstrap
2038 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2042 .space COMMAND_LINE_SIZE