3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
15 * This file contains the low-level support and setup for the
16 * PowerPC-64 platform, including trap and interrupt dispatch.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
24 #include <linux/config.h>
25 #include <linux/threads.h>
29 #include <asm/ppc_asm.h>
30 #include <asm/asm-offsets.h>
32 #include <asm/cputable.h>
33 #include <asm/setup.h>
34 #include <asm/hvcall.h>
35 #include <asm/iseries/lpar_map.h>
36 #include <asm/thread_info.h>
38 #ifdef CONFIG_PPC_ISERIES
39 #define DO_SOFT_DISABLE
43 * We layout physical memory as follows:
44 * 0x0000 - 0x00ff : Secondary processor spin code
45 * 0x0100 - 0x2fff : pSeries Interrupt prologs
46 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
47 * 0x6000 - 0x6fff : Initial (CPU0) segment table
48 * 0x7000 - 0x7fff : FWNMI data area
49 * 0x8000 - : Early init and support code
57 * SPRG0 reserved for hypervisor
58 * SPRG1 temp - used to save gpr
59 * SPRG2 temp - used to save gpr
60 * SPRG3 virt addr of paca
64 * Entering into this code we make the following assumptions:
66 * 1. The MMU is off & open firmware is running in real mode.
67 * 2. The kernel is entered at __start
70 * 1. The MMU is on (as it always is for iSeries)
71 * 2. The kernel is entered at system_reset_iSeries
77 #ifdef CONFIG_PPC_MULTIPLATFORM
79 /* NOP this out unconditionally */
81 b .__start_initialization_multiplatform
83 #endif /* CONFIG_PPC_MULTIPLATFORM */
85 /* Catch branch to 0 in real mode */
88 #ifdef CONFIG_PPC_ISERIES
90 * At offset 0x20, there is a pointer to iSeries LPAR data.
91 * This is required by the hypervisor
94 .llong hvReleaseData-KERNELBASE
97 * At offset 0x28 and 0x30 are offsets to the mschunks_map
98 * array (used by the iSeries LPAR debugger to do translation
99 * between physical addresses and absolute addresses) and
100 * to the pidhash table (also used by the debugger)
102 .llong mschunks_map-KERNELBASE
103 .llong 0 /* pidhash-KERNELBASE SFRXXX */
105 /* Offset 0x38 - Pointer to start of embedded System.map */
106 .globl embedded_sysmap_start
107 embedded_sysmap_start:
109 /* Offset 0x40 - Pointer to end of embedded System.map */
110 .globl embedded_sysmap_end
114 #endif /* CONFIG_PPC_ISERIES */
116 /* Secondary processors spin on this value until it goes to 1. */
117 .globl __secondary_hold_spinloop
118 __secondary_hold_spinloop:
121 /* Secondary processors write this value with their cpu # */
122 /* after they enter the spin loop immediately below. */
123 .globl __secondary_hold_acknowledge
124 __secondary_hold_acknowledge:
129 * The following code is used on pSeries to hold secondary processors
130 * in a spin loop after they have been freed from OpenFirmware, but
131 * before the bulk of the kernel has been relocated. This code
132 * is relocated to physical address 0x60 before prom_init is run.
133 * All of it must fit below the first exception vector at 0x100.
135 _GLOBAL(__secondary_hold)
138 mtmsrd r24 /* RI on */
140 /* Grab our physical cpu number */
143 /* Tell the master cpu we're here */
144 /* Relocation is off & we are located at an address less */
145 /* than 0x100, so only need to grab low order offset. */
146 std r24,__secondary_hold_acknowledge@l(0)
149 /* All secondary cpus wait here until told to start. */
150 100: ld r4,__secondary_hold_spinloop@l(0)
154 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
155 LOAD_REG_IMMEDIATE(r4, .pSeries_secondary_smp_init)
163 /* This value is used to mark exception frames on the stack. */
166 .tc ID_72656773_68657265[TC],0x7265677368657265
170 * The following macros define the code that appears as
171 * the prologue to each of the exception handlers. They
172 * are split into two parts to allow a single kernel binary
173 * to be used for pSeries and iSeries.
174 * LOL. One day... - paulus
178 * We make as much of the exception code common between native
179 * exception handlers (including pSeries LPAR) and iSeries LPAR
180 * implementations as possible.
184 * This is the start of the interrupt handlers for pSeries
185 * This code runs with relocation off.
200 * We're short on space and time in the exception prolog, so we can't
201 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
202 * low halfword of the address, but for Kdump we need the whole low
205 #ifdef CONFIG_CRASH_DUMP
206 #define LOAD_HANDLER(reg, label) \
207 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
208 ori reg,reg,(label)@l; /* .. and the rest */
210 #define LOAD_HANDLER(reg, label) \
211 ori reg,reg,(label)@l; /* virt addr of handler ... */
214 #define EXCEPTION_PROLOG_PSERIES(area, label) \
215 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
216 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
217 std r10,area+EX_R10(r13); \
218 std r11,area+EX_R11(r13); \
219 std r12,area+EX_R12(r13); \
220 mfspr r9,SPRN_SPRG1; \
221 std r9,area+EX_R13(r13); \
223 clrrdi r12,r13,32; /* get high part of &label */ \
225 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
226 LOAD_HANDLER(r12,label) \
227 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
228 mtspr SPRN_SRR0,r12; \
229 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
230 mtspr SPRN_SRR1,r10; \
232 b . /* prevent speculative execution */
235 * This is the start of the interrupt handlers for iSeries
236 * This code runs with relocation on.
238 #define EXCEPTION_PROLOG_ISERIES_1(area) \
239 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
240 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
241 std r10,area+EX_R10(r13); \
242 std r11,area+EX_R11(r13); \
243 std r12,area+EX_R12(r13); \
244 mfspr r9,SPRN_SPRG1; \
245 std r9,area+EX_R13(r13); \
248 #define EXCEPTION_PROLOG_ISERIES_2 \
250 ld r12,PACALPPACAPTR(r13); \
251 ld r11,LPPACASRR0(r12); \
252 ld r12,LPPACASRR1(r12); \
253 ori r10,r10,MSR_RI; \
257 * The common exception prolog is used for all except a few exceptions
258 * such as a segment miss on a kernel address. We have to be prepared
259 * to take another exception from the point where we first touch the
260 * kernel stack onwards.
262 * On entry r13 points to the paca, r9-r13 are saved in the paca,
263 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
264 * SRR1, and relocation is on.
266 #define EXCEPTION_PROLOG_COMMON(n, area) \
267 andi. r10,r12,MSR_PR; /* See if coming from user */ \
268 mr r10,r1; /* Save r1 */ \
269 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
271 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
272 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
273 bge- cr1,bad_stack; /* abort if it is */ \
274 std r9,_CCR(r1); /* save CR in stackframe */ \
275 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
276 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
277 std r10,0(r1); /* make stack chain pointer */ \
278 std r0,GPR0(r1); /* save r0 in stackframe */ \
279 std r10,GPR1(r1); /* save r1 in stackframe */ \
280 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
281 std r2,GPR2(r1); /* save r2 in stackframe */ \
282 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
283 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
284 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
285 ld r10,area+EX_R10(r13); \
288 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
289 ld r10,area+EX_R12(r13); \
290 ld r11,area+EX_R13(r13); \
294 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
295 mflr r9; /* save LR in stackframe */ \
297 mfctr r10; /* save CTR in stackframe */ \
299 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
302 std r9,_TRAP(r1); /* set trap number */ \
304 ld r11,exception_marker@toc(r2); \
305 std r10,RESULT(r1); /* clear regs->result */ \
306 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
311 #define STD_EXCEPTION_PSERIES(n, label) \
313 .globl label##_pSeries; \
316 mtspr SPRN_SPRG1,r13; /* save r13 */ \
317 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
319 #define STD_EXCEPTION_ISERIES(n, label, area) \
320 .globl label##_iSeries; \
323 mtspr SPRN_SPRG1,r13; /* save r13 */ \
324 EXCEPTION_PROLOG_ISERIES_1(area); \
325 EXCEPTION_PROLOG_ISERIES_2; \
328 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
329 .globl label##_iSeries; \
332 mtspr SPRN_SPRG1,r13; /* save r13 */ \
333 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
334 lbz r10,PACAPROCENABLED(r13); \
336 beq- label##_iSeries_masked; \
337 EXCEPTION_PROLOG_ISERIES_2; \
340 #ifdef DO_SOFT_DISABLE
341 #define DISABLE_INTS \
342 lbz r10,PACAPROCENABLED(r13); \
346 stb r11,PACAPROCENABLED(r13); \
347 ori r10,r10,MSR_EE; \
350 #define ENABLE_INTS \
351 lbz r10,PACAPROCENABLED(r13); \
354 ori r11,r11,MSR_EE; \
357 #else /* hard enable/disable interrupts */
360 #define ENABLE_INTS \
363 rlwimi r11,r12,0,MSR_EE; \
368 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
370 .globl label##_common; \
372 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
375 addi r3,r1,STACK_FRAME_OVERHEAD; \
380 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
381 * in the idle task and therefore need the special idle handling.
383 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
385 .globl label##_common; \
387 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
391 addi r3,r1,STACK_FRAME_OVERHEAD; \
395 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
397 .globl label##_common; \
399 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
402 bl .ppc64_runlatch_on; \
403 addi r3,r1,STACK_FRAME_OVERHEAD; \
405 b .ret_from_except_lite
408 * When the idle code in power4_idle puts the CPU into NAP mode,
409 * it has to do so in a loop, and relies on the external interrupt
410 * and decrementer interrupt entry code to get it out of the loop.
411 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
412 * to signal that it is in the loop and needs help to get out.
414 #ifdef CONFIG_PPC_970_NAP
417 clrrdi r11,r1,THREAD_SHIFT; \
418 ld r9,TI_LOCAL_FLAGS(r11); \
419 andi. r10,r9,_TLF_NAPPING; \
420 bnel power4_fixup_nap; \
421 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
427 * Start of pSeries system interrupt routines
430 .globl __start_interrupts
433 STD_EXCEPTION_PSERIES(0x100, system_reset)
436 _machine_check_pSeries:
438 mtspr SPRN_SPRG1,r13 /* save r13 */
439 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
442 .globl data_access_pSeries
451 rlwimi r13,r12,16,0x20
454 beq .do_stab_bolted_pSeries
457 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
458 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
461 .globl data_access_slb_pSeries
462 data_access_slb_pSeries:
465 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
466 std r3,PACA_EXSLB+EX_R3(r13)
468 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
471 /* Keep that around for when we re-implement dynamic VSIDs */
473 bge slb_miss_user_pseries
474 #endif /* __DISABLED__ */
475 std r10,PACA_EXSLB+EX_R10(r13)
476 std r11,PACA_EXSLB+EX_R11(r13)
477 std r12,PACA_EXSLB+EX_R12(r13)
479 std r10,PACA_EXSLB+EX_R13(r13)
480 mfspr r12,SPRN_SRR1 /* and SRR1 */
481 b .slb_miss_realmode /* Rel. branch works in real mode */
483 STD_EXCEPTION_PSERIES(0x400, instruction_access)
486 .globl instruction_access_slb_pSeries
487 instruction_access_slb_pSeries:
490 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
491 std r3,PACA_EXSLB+EX_R3(r13)
492 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
493 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
496 /* Keep that around for when we re-implement dynamic VSIDs */
498 bge slb_miss_user_pseries
499 #endif /* __DISABLED__ */
500 std r10,PACA_EXSLB+EX_R10(r13)
501 std r11,PACA_EXSLB+EX_R11(r13)
502 std r12,PACA_EXSLB+EX_R12(r13)
504 std r10,PACA_EXSLB+EX_R13(r13)
505 mfspr r12,SPRN_SRR1 /* and SRR1 */
506 b .slb_miss_realmode /* Rel. branch works in real mode */
508 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
509 STD_EXCEPTION_PSERIES(0x600, alignment)
510 STD_EXCEPTION_PSERIES(0x700, program_check)
511 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
512 STD_EXCEPTION_PSERIES(0x900, decrementer)
513 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
514 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
517 .globl system_call_pSeries
525 oris r12,r12,system_call_common@h
526 ori r12,r12,system_call_common@l
528 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
532 b . /* prevent speculative execution */
534 STD_EXCEPTION_PSERIES(0xd00, single_step)
535 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
537 /* We need to deal with the Altivec unavailable exception
538 * here which is at 0xf20, thus in the middle of the
539 * prolog code of the PerformanceMonitor one. A little
540 * trickery is thus necessary
543 b performance_monitor_pSeries
545 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
547 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
548 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
552 /*** pSeries interrupt support ***/
554 /* moved from 0xf00 */
555 STD_EXCEPTION_PSERIES(., performance_monitor)
558 _GLOBAL(do_stab_bolted_pSeries)
561 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
564 * We have some room here we use that to put
565 * the peries slb miss user trampoline code so it's reasonably
566 * away from slb_miss_user_common to avoid problems with rfid
568 * This is used for when the SLB miss handler has to go virtual,
569 * which doesn't happen for now anymore but will once we re-implement
570 * dynamic VSIDs for shared page tables
573 slb_miss_user_pseries:
574 std r10,PACA_EXGEN+EX_R10(r13)
575 std r11,PACA_EXGEN+EX_R11(r13)
576 std r12,PACA_EXGEN+EX_R12(r13)
578 ld r11,PACA_EXSLB+EX_R9(r13)
579 ld r12,PACA_EXSLB+EX_R3(r13)
580 std r10,PACA_EXGEN+EX_R13(r13)
581 std r11,PACA_EXGEN+EX_R9(r13)
582 std r12,PACA_EXGEN+EX_R3(r13)
585 mfspr r11,SRR0 /* save SRR0 */
586 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
587 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
589 mfspr r12,SRR1 /* and SRR1 */
592 b . /* prevent spec. execution */
593 #endif /* __DISABLED__ */
596 * Vectors for the FWNMI option. Share common code.
598 .globl system_reset_fwnmi
602 mtspr SPRN_SPRG1,r13 /* save r13 */
603 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
605 .globl machine_check_fwnmi
609 mtspr SPRN_SPRG1,r13 /* save r13 */
610 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
612 #ifdef CONFIG_PPC_ISERIES
613 /*** ISeries-LPAR interrupt handlers ***/
615 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
617 .globl data_access_iSeries
625 rlwimi r13,r12,16,0x20
628 beq .do_stab_bolted_iSeries
631 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
632 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
633 EXCEPTION_PROLOG_ISERIES_2
636 .do_stab_bolted_iSeries:
639 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
640 EXCEPTION_PROLOG_ISERIES_2
643 .globl data_access_slb_iSeries
644 data_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)
649 std r9,PACA_EXSLB+EX_R9(r13)
653 bge slb_miss_user_iseries
655 std r10,PACA_EXSLB+EX_R10(r13)
656 std r11,PACA_EXSLB+EX_R11(r13)
657 std r12,PACA_EXSLB+EX_R12(r13)
659 std r10,PACA_EXSLB+EX_R13(r13)
660 ld r12,PACALPPACAPTR(r13)
661 ld r12,LPPACASRR1(r12)
664 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
666 .globl instruction_access_slb_iSeries
667 instruction_access_slb_iSeries:
668 mtspr SPRN_SPRG1,r13 /* save r13 */
669 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
670 std r3,PACA_EXSLB+EX_R3(r13)
671 ld r3,PACALPPACAPTR(r13)
672 ld r3,LPPACASRR0(r3) /* get SRR0 value */
673 std r9,PACA_EXSLB+EX_R9(r13)
677 bge .slb_miss_user_iseries
679 std r10,PACA_EXSLB+EX_R10(r13)
680 std r11,PACA_EXSLB+EX_R11(r13)
681 std r12,PACA_EXSLB+EX_R12(r13)
683 std r10,PACA_EXSLB+EX_R13(r13)
684 ld r12,PACALPPACAPTR(r13)
685 ld r12,LPPACASRR1(r12)
689 slb_miss_user_iseries:
690 std r10,PACA_EXGEN+EX_R10(r13)
691 std r11,PACA_EXGEN+EX_R11(r13)
692 std r12,PACA_EXGEN+EX_R12(r13)
694 ld r11,PACA_EXSLB+EX_R9(r13)
695 ld r12,PACA_EXSLB+EX_R3(r13)
696 std r10,PACA_EXGEN+EX_R13(r13)
697 std r11,PACA_EXGEN+EX_R9(r13)
698 std r12,PACA_EXGEN+EX_R3(r13)
699 EXCEPTION_PROLOG_ISERIES_2
700 b slb_miss_user_common
703 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
704 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
705 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
706 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
707 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
708 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
709 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
711 .globl system_call_iSeries
715 EXCEPTION_PROLOG_ISERIES_2
718 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
719 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
720 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
722 .globl system_reset_iSeries
723 system_reset_iSeries:
724 mfspr r13,SPRN_SPRG3 /* Get paca address */
727 mtmsrd r24 /* RI on */
728 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
729 cmpwi 0,r24,0 /* Are we processor 0? */
730 beq .__start_initialization_iSeries /* Start up the first processor */
732 li r5,CTRL_RUNLATCH /* Turn off the run light */
739 lbz r23,PACAPROCSTART(r13) /* Test if this processor
742 LOAD_REG_IMMEDIATE(r3,current_set)
743 sldi r28,r24,3 /* get current_set[cpu#] */
745 addi r1,r3,THREAD_SIZE
746 subi r1,r1,STACK_FRAME_OVERHEAD
749 beq iSeries_secondary_smp_loop /* Loop until told to go */
750 bne .__secondary_start /* Loop until told to go */
751 iSeries_secondary_smp_loop:
752 /* Let the Hypervisor know we are alive */
753 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
755 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
756 #else /* CONFIG_SMP */
757 /* Yield the processor. This is required for non-SMP kernels
758 which are running on multi-threaded machines. */
760 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
761 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
762 li r4,0 /* "yield timed" */
763 li r5,-1 /* "yield forever" */
764 #endif /* CONFIG_SMP */
765 li r0,-1 /* r0=-1 indicates a Hypervisor call */
766 sc /* Invoke the hypervisor via a system call */
767 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
768 b 1b /* If SMP not configured, secondaries
771 .globl decrementer_iSeries_masked
772 decrementer_iSeries_masked:
773 /* We may not have a valid TOC pointer in here. */
775 ld r12,PACALPPACAPTR(r13)
776 stb r11,LPPACADECRINT(r12)
777 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
782 .globl hardware_interrupt_iSeries_masked
783 hardware_interrupt_iSeries_masked:
784 mtcrf 0x80,r9 /* Restore regs */
785 ld r12,PACALPPACAPTR(r13)
786 ld r11,LPPACASRR0(r12)
787 ld r12,LPPACASRR1(r12)
790 ld r9,PACA_EXGEN+EX_R9(r13)
791 ld r10,PACA_EXGEN+EX_R10(r13)
792 ld r11,PACA_EXGEN+EX_R11(r13)
793 ld r12,PACA_EXGEN+EX_R12(r13)
794 ld r13,PACA_EXGEN+EX_R13(r13)
796 b . /* prevent speculative execution */
797 #endif /* CONFIG_PPC_ISERIES */
799 /*** Common interrupt handlers ***/
801 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
804 * Machine check is different because we use a different
805 * save area: PACA_EXMC instead of PACA_EXGEN.
808 .globl machine_check_common
809 machine_check_common:
810 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
814 addi r3,r1,STACK_FRAME_OVERHEAD
815 bl .machine_check_exception
818 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
819 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
820 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
821 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
822 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
823 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
824 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
825 #ifdef CONFIG_ALTIVEC
826 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
828 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
832 * Here we have detected that the kernel stack pointer is bad.
833 * R9 contains the saved CR, r13 points to the paca,
834 * r10 contains the (bad) kernel stack pointer,
835 * r11 and r12 contain the saved SRR0 and SRR1.
836 * We switch to using an emergency stack, save the registers there,
837 * and call kernel_bad_stack(), which panics.
840 ld r1,PACAEMERGSP(r13)
841 subi r1,r1,64+INT_FRAME_SIZE
862 addi r11,r1,INT_FRAME_SIZE
867 1: addi r3,r1,STACK_FRAME_OVERHEAD
872 * Return from an exception with minimal checks.
873 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
874 * If interrupts have been enabled, or anything has been
875 * done that might have changed the scheduling status of
876 * any task or sent any task a signal, you should use
877 * ret_from_except or ret_from_except_lite instead of this.
879 .globl fast_exception_return
880 fast_exception_return:
883 andi. r3,r12,MSR_RI /* check if RI is set */
886 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
889 ACCOUNT_CPU_USER_EXIT(r3, r4)
905 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
913 b . /* prevent speculative execution */
917 1: addi r3,r1,STACK_FRAME_OVERHEAD
918 bl .unrecoverable_exception
922 * Here r13 points to the paca, r9 contains the saved CR,
923 * SRR0 and SRR1 are saved in r11 and r12,
924 * r9 - r13 are saved in paca->exgen.
927 .globl data_access_common
930 std r10,PACA_EXGEN+EX_DAR(r13)
932 stw r10,PACA_EXGEN+EX_DSISR(r13)
933 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
934 ld r3,PACA_EXGEN+EX_DAR(r13)
935 lwz r4,PACA_EXGEN+EX_DSISR(r13)
937 b .do_hash_page /* Try to handle as hpte fault */
940 .globl instruction_access_common
941 instruction_access_common:
942 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
946 b .do_hash_page /* Try to handle as hpte fault */
949 * Here is the common SLB miss user that is used when going to virtual
950 * mode for SLB misses, that is currently not used
954 .globl slb_miss_user_common
955 slb_miss_user_common:
957 std r3,PACA_EXGEN+EX_DAR(r13)
958 stw r9,PACA_EXGEN+EX_CCR(r13)
959 std r10,PACA_EXGEN+EX_LR(r13)
960 std r11,PACA_EXGEN+EX_SRR0(r13)
961 bl .slb_allocate_user
963 ld r10,PACA_EXGEN+EX_LR(r13)
964 ld r3,PACA_EXGEN+EX_R3(r13)
965 lwz r9,PACA_EXGEN+EX_CCR(r13)
966 ld r11,PACA_EXGEN+EX_SRR0(r13)
970 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
971 beq- unrecov_user_slb
979 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
985 ld r9,PACA_EXGEN+EX_R9(r13)
986 ld r10,PACA_EXGEN+EX_R10(r13)
987 ld r11,PACA_EXGEN+EX_R11(r13)
988 ld r12,PACA_EXGEN+EX_R12(r13)
989 ld r13,PACA_EXGEN+EX_R13(r13)
994 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
995 ld r4,PACA_EXGEN+EX_DAR(r13)
1002 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1005 1: addi r3,r1,STACK_FRAME_OVERHEAD
1006 bl .unrecoverable_exception
1009 #endif /* __DISABLED__ */
1013 * r13 points to the PACA, r9 contains the saved CR,
1014 * r12 contain the saved SRR1, SRR0 is still ready for return
1015 * r3 has the faulting address
1016 * r9 - r13 are saved in paca->exslb.
1017 * r3 is saved in paca->slb_r3
1018 * We assume we aren't going to take any exceptions during this procedure.
1020 _GLOBAL(slb_miss_realmode)
1023 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1024 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1026 bl .slb_allocate_realmode
1028 /* All done -- return from exception. */
1030 ld r10,PACA_EXSLB+EX_LR(r13)
1031 ld r3,PACA_EXSLB+EX_R3(r13)
1032 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1033 #ifdef CONFIG_PPC_ISERIES
1034 ld r11,PACALPPACAPTR(r13)
1035 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1036 #endif /* CONFIG_PPC_ISERIES */
1040 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1046 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1049 #ifdef CONFIG_PPC_ISERIES
1052 #endif /* CONFIG_PPC_ISERIES */
1053 ld r9,PACA_EXSLB+EX_R9(r13)
1054 ld r10,PACA_EXSLB+EX_R10(r13)
1055 ld r11,PACA_EXSLB+EX_R11(r13)
1056 ld r12,PACA_EXSLB+EX_R12(r13)
1057 ld r13,PACA_EXSLB+EX_R13(r13)
1059 b . /* prevent speculative execution */
1062 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1065 1: addi r3,r1,STACK_FRAME_OVERHEAD
1066 bl .unrecoverable_exception
1070 .globl hardware_interrupt_common
1071 .globl hardware_interrupt_entry
1072 hardware_interrupt_common:
1073 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1075 hardware_interrupt_entry:
1077 bl .ppc64_runlatch_on
1078 addi r3,r1,STACK_FRAME_OVERHEAD
1080 b .ret_from_except_lite
1082 #ifdef CONFIG_PPC_970_NAP
1085 std r9,TI_LOCAL_FLAGS(r11)
1086 ld r10,_LINK(r1) /* make idle task do the */
1087 std r10,_NIP(r1) /* equivalent of a blr */
1092 .globl alignment_common
1095 std r10,PACA_EXGEN+EX_DAR(r13)
1096 mfspr r10,SPRN_DSISR
1097 stw r10,PACA_EXGEN+EX_DSISR(r13)
1098 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1099 ld r3,PACA_EXGEN+EX_DAR(r13)
1100 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1104 addi r3,r1,STACK_FRAME_OVERHEAD
1106 bl .alignment_exception
1110 .globl program_check_common
1111 program_check_common:
1112 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1114 addi r3,r1,STACK_FRAME_OVERHEAD
1116 bl .program_check_exception
1120 .globl fp_unavailable_common
1121 fp_unavailable_common:
1122 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1123 bne .load_up_fpu /* if from user, just load it up */
1125 addi r3,r1,STACK_FRAME_OVERHEAD
1127 bl .kernel_fp_unavailable_exception
1131 .globl altivec_unavailable_common
1132 altivec_unavailable_common:
1133 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1134 #ifdef CONFIG_ALTIVEC
1136 bne .load_up_altivec /* if from user, just load it up */
1137 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1140 addi r3,r1,STACK_FRAME_OVERHEAD
1142 bl .altivec_unavailable_exception
1145 #ifdef CONFIG_ALTIVEC
1147 * load_up_altivec(unused, unused, tsk)
1148 * Disable VMX for the task which had it previously,
1149 * and save its vector registers in its thread_struct.
1150 * Enables the VMX for use in the kernel on return.
1151 * On SMP we know the VMX is free, since we give it up every
1152 * switch (ie, no lazy save of the vector registers).
1153 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1155 _STATIC(load_up_altivec)
1156 mfmsr r5 /* grab the current MSR */
1157 oris r5,r5,MSR_VEC@h
1158 mtmsrd r5 /* enable use of VMX now */
1162 * For SMP, we don't do lazy VMX switching because it just gets too
1163 * horrendously complex, especially when a task switches from one CPU
1164 * to another. Instead we call giveup_altvec in switch_to.
1165 * VRSAVE isn't dealt with here, that is done in the normal context
1166 * switch code. Note that we could rely on vrsave value to eventually
1167 * avoid saving all of the VREGs here...
1170 ld r3,last_task_used_altivec@got(r2)
1174 /* Save VMX state to last_task_used_altivec's THREAD struct */
1180 /* Disable VMX for last_task_used_altivec */
1182 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1185 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1187 #endif /* CONFIG_SMP */
1188 /* Hack: if we get an altivec unavailable trap with VRSAVE
1189 * set to all zeros, we assume this is a broken application
1190 * that fails to set it properly, and thus we switch it to
1193 mfspr r4,SPRN_VRSAVE
1197 mtspr SPRN_VRSAVE,r4
1199 /* enable use of VMX after return */
1200 ld r4,PACACURRENT(r13)
1201 addi r5,r4,THREAD /* Get THREAD */
1202 oris r12,r12,MSR_VEC@h
1206 stw r4,THREAD_USED_VR(r5)
1211 /* Update last_task_used_math to 'current' */
1212 subi r4,r5,THREAD /* Back to 'current' */
1214 #endif /* CONFIG_SMP */
1215 /* restore registers and return */
1216 b fast_exception_return
1217 #endif /* CONFIG_ALTIVEC */
1223 _GLOBAL(do_hash_page)
1227 andis. r0,r4,0xa450 /* weird error? */
1228 bne- .handle_page_fault /* if not, try to insert a HPTE */
1230 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1231 bne- .do_ste_alloc /* If so handle it */
1232 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1235 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1236 * accessing a userspace segment (even from the kernel). We assume
1237 * kernel addresses always have the high bit set.
1239 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1240 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1241 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1242 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1243 ori r4,r4,1 /* add _PAGE_PRESENT */
1244 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1247 * On iSeries, we soft-disable interrupts here, then
1248 * hard-enable interrupts so that the hash_page code can spin on
1249 * the hash_table_lock without problems on a shared processor.
1254 * r3 contains the faulting address
1255 * r4 contains the required access permissions
1256 * r5 contains the trap number
1258 * at return r3 = 0 for success
1260 bl .hash_page /* build HPTE if possible */
1261 cmpdi r3,0 /* see if hash_page succeeded */
1263 #ifdef DO_SOFT_DISABLE
1265 * If we had interrupts soft-enabled at the point where the
1266 * DSI/ISI occurred, and an interrupt came in during hash_page,
1268 * We jump to ret_from_except_lite rather than fast_exception_return
1269 * because ret_from_except_lite will check for and handle pending
1270 * interrupts if necessary.
1272 beq .ret_from_except_lite
1273 /* For a hash failure, we don't bother re-enabling interrupts */
1277 * hash_page couldn't handle it, set soft interrupt enable back
1278 * to what it was before the trap. Note that .local_irq_restore
1279 * handles any interrupts pending at this point.
1282 bl .local_irq_restore
1285 beq fast_exception_return /* Return from exception on success */
1286 ble- 12f /* Failure return from hash_page */
1291 /* Here we have a page fault that hash_page can't handle. */
1292 _GLOBAL(handle_page_fault)
1296 addi r3,r1,STACK_FRAME_OVERHEAD
1299 beq+ .ret_from_except_lite
1302 addi r3,r1,STACK_FRAME_OVERHEAD
1307 /* We have a page fault that hash_page could handle but HV refused
1311 addi r3,r1,STACK_FRAME_OVERHEAD
1316 /* here we have a segment miss */
1317 _GLOBAL(do_ste_alloc)
1318 bl .ste_allocate /* try to insert stab entry */
1320 beq+ fast_exception_return
1321 b .handle_page_fault
1324 * r13 points to the PACA, r9 contains the saved CR,
1325 * r11 and r12 contain the saved SRR0 and SRR1.
1326 * r9 - r13 are saved in paca->exslb.
1327 * We assume we aren't going to take any exceptions during this procedure.
1328 * We assume (DAR >> 60) == 0xc.
1331 _GLOBAL(do_stab_bolted)
1332 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1333 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1335 /* Hash to the primary group */
1336 ld r10,PACASTABVIRT(r13)
1339 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1341 /* Calculate VSID */
1342 /* This is a kernel address, so protovsid = ESID */
1343 ASM_VSID_SCRAMBLE(r11, r9)
1344 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1346 /* Search the primary group for a free entry */
1347 1: ld r11,0(r10) /* Test valid bit of the current ste */
1354 /* Stick for only searching the primary group for now. */
1355 /* At least for now, we use a very simple random castout scheme */
1356 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1358 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1361 /* r10 currently points to an ste one past the group of interest */
1362 /* make it point to the randomly selected entry */
1364 or r10,r10,r11 /* r10 is the entry to invalidate */
1366 isync /* mark the entry invalid */
1368 rldicl r11,r11,56,1 /* clear the valid bit */
1373 clrrdi r11,r11,28 /* Get the esid part of the ste */
1376 2: std r9,8(r10) /* Store the vsid part of the ste */
1379 mfspr r11,SPRN_DAR /* Get the new esid */
1380 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1381 ori r11,r11,0x90 /* Turn on valid and kp */
1382 std r11,0(r10) /* Put new entry back into the stab */
1386 /* All done -- return from exception. */
1387 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1388 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1390 andi. r10,r12,MSR_RI
1393 mtcrf 0x80,r9 /* restore CR */
1401 ld r9,PACA_EXSLB+EX_R9(r13)
1402 ld r10,PACA_EXSLB+EX_R10(r13)
1403 ld r11,PACA_EXSLB+EX_R11(r13)
1404 ld r12,PACA_EXSLB+EX_R12(r13)
1405 ld r13,PACA_EXSLB+EX_R13(r13)
1407 b . /* prevent speculative execution */
1410 * Space for CPU0's segment table.
1412 * On iSeries, the hypervisor must fill in at least one entry before
1413 * we get control (with relocate on). The address is give to the hv
1414 * as a page number (see xLparMap in lpardata.c), so this must be at a
1415 * fixed address (the linker can't compute (u64)&initial_stab >>
1418 . = STAB0_OFFSET /* 0x6000 */
1424 * Data area reserved for FWNMI option.
1425 * This address (0x7000) is fixed by the RPA.
1428 .globl fwnmi_data_area
1431 /* iSeries does not use the FWNMI stuff, so it is safe to put
1432 * this here, even if we later allow kernels that will boot on
1433 * both pSeries and iSeries */
1434 #ifdef CONFIG_PPC_ISERIES
1436 #include "lparmap.s"
1438 * This ".text" is here for old compilers that generate a trailing
1439 * .note section when compiling .c files to .s
1442 #endif /* CONFIG_PPC_ISERIES */
1447 * On pSeries, secondary processors spin in the following code.
1448 * At entry, r3 = this processor's number (physical cpu id)
1450 _GLOBAL(pSeries_secondary_smp_init)
1453 /* turn on 64-bit mode */
1457 /* Copy some CPU settings from CPU 0 */
1458 bl .__restore_cpu_setup
1460 /* Set up a paca value for this processor. Since we have the
1461 * physical cpu id in r24, we need to search the pacas to find
1462 * which logical id maps to our physical one.
1464 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1465 li r5,0 /* logical cpu id */
1466 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1467 cmpw r6,r24 /* Compare to our id */
1469 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1474 mr r3,r24 /* not found, copy phys to r3 */
1475 b .kexec_wait /* next kernel might do better */
1477 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1478 /* From now on, r24 is expected to be logical cpuid */
1481 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1485 /* Create a temp kernel stack for use before relocation is on. */
1486 ld r1,PACAEMERGSP(r13)
1487 subi r1,r1,STACK_FRAME_OVERHEAD
1491 bne .__secondary_start
1493 b 3b /* Loop until told to go */
1495 #ifdef CONFIG_PPC_ISERIES
1496 _STATIC(__start_initialization_iSeries)
1497 /* Clear out the BSS */
1498 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1499 LOAD_REG_IMMEDIATE(r8,__bss_start)
1500 sub r11,r11,r8 /* bss size */
1501 addi r11,r11,7 /* round up to an even double word */
1502 rldicl. r11,r11,61,3 /* shift right by 3 */
1506 mtctr r11 /* zero this many doublewords */
1510 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1511 addi r1,r1,THREAD_SIZE
1513 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1515 LOAD_REG_IMMEDIATE(r3,cpu_specs)
1516 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1520 LOAD_REG_IMMEDIATE(r2,__toc_start)
1524 bl .iSeries_early_setup
1527 /* relocation is on at this point */
1529 b .start_here_common
1530 #endif /* CONFIG_PPC_ISERIES */
1532 #ifdef CONFIG_PPC_MULTIPLATFORM
1536 andi. r0,r3,MSR_IR|MSR_DR
1543 b . /* prevent speculative execution */
1547 * Here is our main kernel entry point. We support currently 2 kind of entries
1548 * depending on the value of r5.
1550 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1553 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1554 * DT block, r4 is a physical pointer to the kernel itself
1557 _GLOBAL(__start_initialization_multiplatform)
1558 #ifdef CONFIG_PPC_MULTIPLATFORM
1560 * Are we booted from a PROM Of-type client-interface ?
1563 bne .__boot_from_prom /* yes -> prom */
1566 /* Save parameters */
1570 /* Make sure we are running in 64 bits mode */
1573 /* Setup some critical 970 SPRs before switching MMU off */
1574 bl .__970_cpu_preinit
1579 /* Switch off MMU if not already */
1580 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1583 b .__after_prom_start
1585 #ifdef CONFIG_PPC_MULTIPLATFORM
1586 _STATIC(__boot_from_prom)
1587 /* Save parameters */
1595 * Align the stack to 16-byte boundary
1596 * Depending on the size and layout of the ELF sections in the initial
1597 * boot binary, the stack pointer will be unalignet on PowerMac
1601 /* Make sure we are running in 64 bits mode */
1604 /* put a relocation offset into r3 */
1607 LOAD_REG_IMMEDIATE(r2,__toc_start)
1611 /* Relocate the TOC from a virt addr to a real addr */
1614 /* Restore parameters */
1621 /* Do all of the interaction with OF client interface */
1623 /* We never return */
1628 * At this point, r3 contains the physical address we are running at,
1629 * returned by prom_init()
1631 _STATIC(__after_prom_start)
1634 * We need to run with __start at physical address PHYSICAL_START.
1635 * This will leave some code in the first 256B of
1636 * real memory, which are reserved for software use.
1637 * The remainder of the first page is loaded with the fixed
1638 * interrupt vectors. The next two pages are filled with
1639 * unknown exception placeholders.
1641 * Note: This process overwrites the OF exception vectors.
1642 * r26 == relocation offset
1647 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1649 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1651 // XXX FIXME: Use phys returned by OF (r30)
1652 add r4,r27,r26 /* source addr */
1653 /* current address of _start */
1654 /* i.e. where we are running */
1655 /* the source addr */
1657 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1660 li r6,0x100 /* Start offset, the first 0x100 */
1661 /* bytes were copied earlier. */
1663 bl .copy_and_flush /* copy the first n bytes */
1664 /* this includes the code being */
1665 /* executed here. */
1667 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1668 mtctr r0 /* that we just made/relocated */
1671 4: LOAD_REG_IMMEDIATE(r5,klimit)
1673 ld r5,0(r5) /* get the value of klimit */
1675 bl .copy_and_flush /* copy the rest */
1676 b .start_here_multiplatform
1678 #endif /* CONFIG_PPC_MULTIPLATFORM */
1681 * Copy routine used to copy the kernel to start at physical address 0
1682 * and flush and invalidate the caches as needed.
1683 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1684 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1686 * Note: this routine *only* clobbers r0, r6 and lr
1688 _GLOBAL(copy_and_flush)
1691 4: li r0,16 /* Use the least common */
1692 /* denominator cache line */
1693 /* size. This results in */
1694 /* extra cache line flushes */
1695 /* but operation is correct. */
1696 /* Can't get cache line size */
1697 /* from NACA as it is being */
1700 mtctr r0 /* put # words/line in ctr */
1701 3: addi r6,r6,8 /* copy a cache line */
1705 dcbst r6,r3 /* write it to memory */
1707 icbi r6,r3 /* flush the icache line */
1719 #ifdef CONFIG_PPC_PMAC
1721 * On PowerMac, secondary processors starts from the reset vector, which
1722 * is temporarily turned into a call to one of the functions below.
1727 .globl __secondary_start_pmac_0
1728 __secondary_start_pmac_0:
1729 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1739 _GLOBAL(pmac_secondary_start)
1740 /* turn on 64-bit mode */
1744 /* Copy some CPU settings from CPU 0 */
1745 bl .__restore_cpu_setup
1747 /* pSeries do that early though I don't think we really need it */
1750 mtmsrd r3 /* RI on */
1752 /* Set up a paca value for this processor. */
1753 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1754 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1755 add r13,r13,r4 /* for this processor. */
1756 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1758 /* Create a temp kernel stack for use before relocation is on. */
1759 ld r1,PACAEMERGSP(r13)
1760 subi r1,r1,STACK_FRAME_OVERHEAD
1762 b .__secondary_start
1764 #endif /* CONFIG_PPC_PMAC */
1767 * This function is called after the master CPU has released the
1768 * secondary processors. The execution environment is relocation off.
1769 * The paca for this processor has the following fields initialized at
1771 * 1. Processor number
1772 * 2. Segment table pointer (virtual address)
1773 * On entry the following are set:
1774 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1775 * r24 = cpu# (in Linux terms)
1776 * r13 = paca virtual address
1777 * SPRG3 = paca virtual address
1779 _GLOBAL(__secondary_start)
1780 /* Set thread priority to MEDIUM */
1786 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1787 bl .early_setup_secondary
1789 /* Initialize the kernel stack. Just a repeat for iSeries. */
1790 LOAD_REG_ADDR(r3, current_set)
1791 sldi r28,r24,3 /* get current_set[cpu#] */
1793 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1794 std r1,PACAKSAVE(r13)
1796 /* Clear backchain so we get nice backtraces */
1800 /* enable MMU and jump to start_secondary */
1801 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1802 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1803 #ifdef DO_SOFT_DISABLE
1809 b . /* prevent speculative execution */
1812 * Running with relocation on at this point. All we want to do is
1813 * zero the stack back-chain pointer before going into C code.
1815 _GLOBAL(start_secondary_prolog)
1817 std r3,0(r1) /* Zero the stack frame pointer */
1823 * This subroutine clobbers r11 and r12
1825 _GLOBAL(enable_64b_mode)
1826 mfmsr r11 /* grab the current MSR */
1828 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1831 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1837 #ifdef CONFIG_PPC_MULTIPLATFORM
1839 * This is where the main kernel code starts.
1841 _STATIC(start_here_multiplatform)
1842 /* get a new offset, now that the kernel has moved. */
1846 /* Clear out the BSS. It may have been done in prom_init,
1847 * already but that's irrelevant since prom_init will soon
1848 * be detached from the kernel completely. Besides, we need
1849 * to clear it now for kexec-style entry.
1851 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1852 LOAD_REG_IMMEDIATE(r8,__bss_start)
1853 sub r11,r11,r8 /* bss size */
1854 addi r11,r11,7 /* round up to an even double word */
1855 rldicl. r11,r11,61,3 /* shift right by 3 */
1859 mtctr r11 /* zero this many doublewords */
1866 mtmsrd r6 /* RI on */
1868 /* The following gets the stack and TOC set up with the regs */
1869 /* pointing to the real addr of the kernel stack. This is */
1870 /* all done to support the C function call below which sets */
1871 /* up the htab. This is done because we have relocated the */
1872 /* kernel but are still running in real mode. */
1874 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1877 /* set up a stack pointer (physical address) */
1878 addi r1,r3,THREAD_SIZE
1880 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1882 /* set up the TOC (physical address) */
1883 LOAD_REG_IMMEDIATE(r2,__toc_start)
1888 LOAD_REG_IMMEDIATE(r3, cpu_specs)
1890 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1895 /* Save some low level config HIDs of CPU0 to be copied to
1896 * other CPUs later on, or used for suspend/resume
1898 bl .__save_cpu_setup
1901 /* Do very early kernel initializations, including initial hash table,
1902 * stab and slb setup before we turn on relocation. */
1904 /* Restore parameters passed from prom_init/kexec */
1908 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1909 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1913 b . /* prevent speculative execution */
1914 #endif /* CONFIG_PPC_MULTIPLATFORM */
1916 /* This is where all platforms converge execution */
1917 _STATIC(start_here_common)
1918 /* relocation is on at this point */
1920 /* The following code sets up the SP and TOC now that we are */
1921 /* running with translation enabled. */
1923 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1925 /* set up the stack */
1926 addi r1,r3,THREAD_SIZE
1928 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1930 /* Apply the CPUs-specific fixups (nop out sections not relevant
1934 bl .do_cpu_ftr_fixups
1936 LOAD_REG_IMMEDIATE(r26, boot_cpuid)
1939 LOAD_REG_IMMEDIATE(r24, paca) /* Get base vaddr of paca array */
1940 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1941 add r13,r13,r24 /* for this processor. */
1942 mtspr SPRN_SPRG3,r13
1944 /* ptr to current */
1945 LOAD_REG_IMMEDIATE(r4, init_task)
1946 std r4,PACACURRENT(r13)
1950 std r1,PACAKSAVE(r13)
1954 /* Load up the kernel context */
1956 #ifdef DO_SOFT_DISABLE
1958 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1960 ori r5,r5,MSR_EE /* Hard Enabled */
1969 /* Put the paca pointer into r13 and SPRG3 */
1970 _GLOBAL(setup_boot_paca)
1971 LOAD_REG_IMMEDIATE(r3, boot_cpuid)
1973 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1974 mulli r3,r3,PACA_SIZE /* Calculate vaddr of right paca */
1975 add r13,r3,r4 /* for this processor. */
1976 mtspr SPRN_SPRG3,r13
1981 * We put a few things here that have to be page-aligned.
1982 * This stuff goes at the beginning of the bss, which is page-aligned.
1988 .globl empty_zero_page
1992 .globl swapper_pg_dir
1997 * This space gets a copy of optional info passed to us by the bootstrap
1998 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2002 .space COMMAND_LINE_SIZE