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 #define SECONDARY_PROCESSORS
28 #include <linux/config.h>
29 #include <linux/threads.h>
30 #include <asm/processor.h>
34 #include <asm/systemcfg.h>
35 #include <asm/ppc_asm.h>
36 #include <asm/offsets.h>
38 #include <asm/cputable.h>
39 #include <asm/setup.h>
40 #include <asm/hvcall.h>
41 #include <asm/iSeries/LparMap.h>
43 #ifdef CONFIG_PPC_ISERIES
44 #define DO_SOFT_DISABLE
48 * hcall interface to pSeries LPAR
50 #define H_SET_ASR 0x30
53 * We layout physical memory as follows:
54 * 0x0000 - 0x00ff : Secondary processor spin code
55 * 0x0100 - 0x2fff : pSeries Interrupt prologs
56 * 0x3000 - 0x3fff : Interrupt support
57 * 0x4000 - 0x4fff : NACA
58 * 0x6000 : iSeries and common interrupt prologs
59 * 0x9000 - 0x9fff : Initial segment table
67 * SPRG0 reserved for hypervisor
68 * SPRG1 temp - used to save gpr
69 * SPRG2 temp - used to save gpr
70 * SPRG3 virt addr of paca
74 * Entering into this code we make the following assumptions:
76 * 1. The MMU is off & open firmware is running in real mode.
77 * 2. The kernel is entered at __start
80 * 1. The MMU is on (as it always is for iSeries)
81 * 2. The kernel is entered at system_reset_iSeries
87 #ifdef CONFIG_PPC_MULTIPLATFORM
89 /* NOP this out unconditionally */
91 b .__start_initialization_multiplatform
93 #endif /* CONFIG_PPC_MULTIPLATFORM */
95 /* Catch branch to 0 in real mode */
97 #ifdef CONFIG_PPC_ISERIES
99 * At offset 0x20, there is a pointer to iSeries LPAR data.
100 * This is required by the hypervisor
103 .llong hvReleaseData-KERNELBASE
106 * At offset 0x28 and 0x30 are offsets to the msChunks
107 * array (used by the iSeries LPAR debugger to do translation
108 * between physical addresses and absolute addresses) and
109 * to the pidhash table (also used by the debugger)
111 .llong msChunks-KERNELBASE
112 .llong 0 /* pidhash-KERNELBASE SFRXXX */
114 /* Offset 0x38 - Pointer to start of embedded System.map */
115 .globl embedded_sysmap_start
116 embedded_sysmap_start:
118 /* Offset 0x40 - Pointer to end of embedded System.map */
119 .globl embedded_sysmap_end
123 #else /* CONFIG_PPC_ISERIES */
125 /* Secondary processors spin on this value until it goes to 1. */
126 .globl __secondary_hold_spinloop
127 __secondary_hold_spinloop:
130 /* Secondary processors write this value with their cpu # */
131 /* after they enter the spin loop immediately below. */
132 .globl __secondary_hold_acknowledge
133 __secondary_hold_acknowledge:
138 * The following code is used on pSeries to hold secondary processors
139 * in a spin loop after they have been freed from OpenFirmware, but
140 * before the bulk of the kernel has been relocated. This code
141 * is relocated to physical address 0x60 before prom_init is run.
142 * All of it must fit below the first exception vector at 0x100.
144 _GLOBAL(__secondary_hold)
147 mtmsrd r24 /* RI on */
149 /* Grab our linux cpu number */
152 /* Tell the master cpu we're here */
153 /* Relocation is off & we are located at an address less */
154 /* than 0x100, so only need to grab low order offset. */
155 std r24,__secondary_hold_acknowledge@l(0)
158 /* All secondary cpu's wait here until told to start. */
159 100: ld r4,__secondary_hold_spinloop@l(0)
168 b .pSeries_secondary_smp_init
175 /* This value is used to mark exception frames on the stack. */
178 .tc ID_72656773_68657265[TC],0x7265677368657265
182 * The following macros define the code that appears as
183 * the prologue to each of the exception handlers. They
184 * are split into two parts to allow a single kernel binary
185 * to be used for pSeries and iSeries.
186 * LOL. One day... - paulus
190 * We make as much of the exception code common between native
191 * exception handlers (including pSeries LPAR) and iSeries LPAR
192 * implementations as possible.
196 * This is the start of the interrupt handlers for pSeries
197 * This code runs with relocation off.
205 #define EX_R3 40 /* SLB miss saves R3, but not SRR0 */
207 #define EX_LR 48 /* SLB miss saves LR, but not DAR */
211 #define EXCEPTION_PROLOG_PSERIES(area, label) \
212 mfspr r13,SPRG3; /* get paca address into r13 */ \
213 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
214 std r10,area+EX_R10(r13); \
215 std r11,area+EX_R11(r13); \
216 std r12,area+EX_R12(r13); \
218 std r9,area+EX_R13(r13); \
220 clrrdi r12,r13,32; /* get high part of &label */ \
222 mfspr r11,SRR0; /* save SRR0 */ \
223 ori r12,r12,(label)@l; /* virt addr of handler */ \
224 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
226 mfspr r12,SRR1; /* and SRR1 */ \
229 b . /* prevent speculative execution */
232 * This is the start of the interrupt handlers for iSeries
233 * This code runs with relocation on.
235 #define EXCEPTION_PROLOG_ISERIES_1(area) \
236 mfspr r13,SPRG3; /* get paca address into r13 */ \
237 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
238 std r10,area+EX_R10(r13); \
239 std r11,area+EX_R11(r13); \
240 std r12,area+EX_R12(r13); \
242 std r9,area+EX_R13(r13); \
245 #define EXCEPTION_PROLOG_ISERIES_2 \
247 ld r11,PACALPPACA+LPPACASRR0(r13); \
248 ld r12,PACALPPACA+LPPACASRR1(r13); \
249 ori r10,r10,MSR_RI; \
253 * The common exception prolog is used for all except a few exceptions
254 * such as a segment miss on a kernel address. We have to be prepared
255 * to take another exception from the point where we first touch the
256 * kernel stack onwards.
258 * On entry r13 points to the paca, r9-r13 are saved in the paca,
259 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
260 * SRR1, and relocation is on.
262 #define EXCEPTION_PROLOG_COMMON(n, area) \
263 andi. r10,r12,MSR_PR; /* See if coming from user */ \
264 mr r10,r1; /* Save r1 */ \
265 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
267 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
268 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
269 bge- cr1,bad_stack; /* abort if it is */ \
270 std r9,_CCR(r1); /* save CR in stackframe */ \
271 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
272 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
273 std r10,0(r1); /* make stack chain pointer */ \
274 std r0,GPR0(r1); /* save r0 in stackframe */ \
275 std r10,GPR1(r1); /* save r1 in stackframe */ \
276 std r2,GPR2(r1); /* save r2 in stackframe */ \
277 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
278 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
279 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
280 ld r10,area+EX_R10(r13); \
283 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
284 ld r10,area+EX_R12(r13); \
285 ld r11,area+EX_R13(r13); \
289 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
290 mflr r9; /* save LR in stackframe */ \
292 mfctr r10; /* save CTR in stackframe */ \
294 mfspr r11,XER; /* save XER in stackframe */ \
297 std r9,_TRAP(r1); /* set trap number */ \
299 ld r11,exception_marker@toc(r2); \
300 std r10,RESULT(r1); /* clear regs->result */ \
301 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
306 #define STD_EXCEPTION_PSERIES(n, label) \
308 .globl label##_pSeries; \
311 mtspr SPRG1,r13; /* save r13 */ \
313 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
315 #define STD_EXCEPTION_ISERIES(n, label, area) \
316 .globl label##_iSeries; \
319 mtspr SPRG1,r13; /* save r13 */ \
321 EXCEPTION_PROLOG_ISERIES_1(area); \
322 EXCEPTION_PROLOG_ISERIES_2; \
325 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
326 .globl label##_iSeries; \
329 mtspr SPRG1,r13; /* save r13 */ \
331 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
332 lbz r10,PACAPROCENABLED(r13); \
334 beq- label##_iSeries_masked; \
335 EXCEPTION_PROLOG_ISERIES_2; \
338 #ifdef DO_SOFT_DISABLE
339 #define DISABLE_INTS \
340 lbz r10,PACAPROCENABLED(r13); \
344 stb r11,PACAPROCENABLED(r13); \
345 ori r10,r10,MSR_EE; \
348 #define ENABLE_INTS \
349 lbz r10,PACAPROCENABLED(r13); \
352 ori r11,r11,MSR_EE; \
355 #else /* hard enable/disable interrupts */
358 #define ENABLE_INTS \
361 rlwimi r11,r12,0,MSR_EE; \
366 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
368 .globl label##_common; \
370 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
373 addi r3,r1,STACK_FRAME_OVERHEAD; \
377 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
379 .globl label##_common; \
381 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
383 addi r3,r1,STACK_FRAME_OVERHEAD; \
385 b .ret_from_except_lite
388 * Start of pSeries system interrupt routines
391 .globl __start_interrupts
394 STD_EXCEPTION_PSERIES(0x100, system_reset)
397 _machine_check_pSeries:
399 mtspr SPRG1,r13 /* save r13 */
401 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
404 .globl data_access_pSeries
413 rlwimi r13,r12,16,0x20
416 beq .do_stab_bolted_pSeries
419 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
420 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
423 .globl data_access_slb_pSeries
424 data_access_slb_pSeries:
428 mfspr r13,SPRG3 /* get paca address into r13 */
429 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
430 std r10,PACA_EXSLB+EX_R10(r13)
431 std r11,PACA_EXSLB+EX_R11(r13)
432 std r12,PACA_EXSLB+EX_R12(r13)
433 std r3,PACA_EXSLB+EX_R3(r13)
435 std r9,PACA_EXSLB+EX_R13(r13)
437 mfspr r12,SRR1 /* and SRR1 */
439 b .do_slb_miss /* Rel. branch works in real mode */
441 STD_EXCEPTION_PSERIES(0x400, instruction_access)
444 .globl instruction_access_slb_pSeries
445 instruction_access_slb_pSeries:
449 mfspr r13,SPRG3 /* get paca address into r13 */
450 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
451 std r10,PACA_EXSLB+EX_R10(r13)
452 std r11,PACA_EXSLB+EX_R11(r13)
453 std r12,PACA_EXSLB+EX_R12(r13)
454 std r3,PACA_EXSLB+EX_R3(r13)
456 std r9,PACA_EXSLB+EX_R13(r13)
458 mfspr r12,SRR1 /* and SRR1 */
459 mfspr r3,SRR0 /* SRR0 is faulting address */
460 b .do_slb_miss /* Rel. branch works in real mode */
462 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
463 STD_EXCEPTION_PSERIES(0x600, alignment)
464 STD_EXCEPTION_PSERIES(0x700, program_check)
465 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
466 STD_EXCEPTION_PSERIES(0x900, decrementer)
467 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
468 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
471 .globl system_call_pSeries
480 oris r12,r12,system_call_common@h
481 ori r12,r12,system_call_common@l
483 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
487 b . /* prevent speculative execution */
489 STD_EXCEPTION_PSERIES(0xd00, single_step)
490 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
492 /* We need to deal with the Altivec unavailable exception
493 * here which is at 0xf20, thus in the middle of the
494 * prolog code of the PerformanceMonitor one. A little
495 * trickery is thus necessary
498 b performance_monitor_pSeries
500 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
502 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
503 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
505 /* moved from 0xf00 */
506 STD_EXCEPTION_PSERIES(0x3000, performance_monitor)
509 _GLOBAL(do_stab_bolted_pSeries)
512 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
515 /* Space for the naca. Architected to be located at real address
516 * NACA_PHYS_ADDR. Various tools rely on this location being fixed.
517 * The first dword of the naca is required by iSeries LPAR to
518 * point to itVpdAreas. On pSeries native, this value is not used.
521 .globl __end_interrupts
523 #ifdef CONFIG_PPC_ISERIES
527 .llong 0 /* xRamDisk */
528 .llong 0 /* xRamDiskSize */
532 /*** ISeries-LPAR interrupt handlers ***/
534 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
536 .globl data_access_iSeries
544 rlwimi r13,r12,16,0x20
547 beq .do_stab_bolted_iSeries
550 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
551 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
552 EXCEPTION_PROLOG_ISERIES_2
555 .do_stab_bolted_iSeries:
558 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
559 EXCEPTION_PROLOG_ISERIES_2
562 .globl data_access_slb_iSeries
563 data_access_slb_iSeries:
564 mtspr SPRG1,r13 /* save r13 */
565 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
566 std r3,PACA_EXSLB+EX_R3(r13)
567 ld r12,PACALPPACA+LPPACASRR1(r13)
571 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
573 .globl instruction_access_slb_iSeries
574 instruction_access_slb_iSeries:
575 mtspr SPRG1,r13 /* save r13 */
576 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
577 std r3,PACA_EXSLB+EX_R3(r13)
578 ld r12,PACALPPACA+LPPACASRR1(r13)
579 ld r3,PACALPPACA+LPPACASRR0(r13)
582 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
583 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
584 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
585 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
586 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
587 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
588 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
590 .globl system_call_iSeries
594 EXCEPTION_PROLOG_ISERIES_2
597 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
598 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
599 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
601 .globl system_reset_iSeries
602 system_reset_iSeries:
603 mfspr r13,SPRG3 /* Get paca address */
606 mtmsrd r24 /* RI on */
607 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
608 cmpwi 0,r24,0 /* Are we processor 0? */
609 beq .__start_initialization_iSeries /* Start up the first processor */
611 li r5,CTRL_RUNLATCH /* Turn off the run light */
618 lbz r23,PACAPROCSTART(r13) /* Test if this processor
621 LOADADDR(r3,current_set)
622 sldi r28,r24,3 /* get current_set[cpu#] */
624 addi r1,r3,THREAD_SIZE
625 subi r1,r1,STACK_FRAME_OVERHEAD
628 beq iSeries_secondary_smp_loop /* Loop until told to go */
629 #ifdef SECONDARY_PROCESSORS
630 bne .__secondary_start /* Loop until told to go */
632 iSeries_secondary_smp_loop:
633 /* Let the Hypervisor know we are alive */
634 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
636 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
637 #else /* CONFIG_SMP */
638 /* Yield the processor. This is required for non-SMP kernels
639 which are running on multi-threaded machines. */
641 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
642 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
643 li r4,0 /* "yield timed" */
644 li r5,-1 /* "yield forever" */
645 #endif /* CONFIG_SMP */
646 li r0,-1 /* r0=-1 indicates a Hypervisor call */
647 sc /* Invoke the hypervisor via a system call */
648 mfspr r13,SPRG3 /* Put r13 back ???? */
649 b 1b /* If SMP not configured, secondaries
652 .globl decrementer_iSeries_masked
653 decrementer_iSeries_masked:
655 stb r11,PACALPPACA+LPPACADECRINT(r13)
656 lwz r12,PACADEFAULTDECR(r13)
660 .globl hardware_interrupt_iSeries_masked
661 hardware_interrupt_iSeries_masked:
662 mtcrf 0x80,r9 /* Restore regs */
663 ld r11,PACALPPACA+LPPACASRR0(r13)
664 ld r12,PACALPPACA+LPPACASRR1(r13)
667 ld r9,PACA_EXGEN+EX_R9(r13)
668 ld r10,PACA_EXGEN+EX_R10(r13)
669 ld r11,PACA_EXGEN+EX_R11(r13)
670 ld r12,PACA_EXGEN+EX_R12(r13)
671 ld r13,PACA_EXGEN+EX_R13(r13)
673 b . /* prevent speculative execution */
677 * Data area reserved for FWNMI option.
680 .globl fwnmi_data_area
683 #ifdef CONFIG_PPC_ISERIES
686 #endif /* CONFIG_PPC_ISERIES */
689 * Vectors for the FWNMI option. Share common code.
692 .globl system_reset_fwnmi
695 mtspr SPRG1,r13 /* save r13 */
697 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
698 .globl machine_check_fwnmi
701 mtspr SPRG1,r13 /* save r13 */
703 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
706 * Space for the initial segment table
707 * For LPAR, the hypervisor must fill in at least one entry
708 * before we get control (with relocate on)
714 . = (STAB0_PHYS_ADDR + PAGE_SIZE)
719 /*** Common interrupt handlers ***/
721 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
724 * Machine check is different because we use a different
725 * save area: PACA_EXMC instead of PACA_EXGEN.
728 .globl machine_check_common
729 machine_check_common:
730 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
733 addi r3,r1,STACK_FRAME_OVERHEAD
734 bl .machine_check_exception
737 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
738 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
739 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
740 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
741 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
742 STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
743 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
744 #ifdef CONFIG_ALTIVEC
745 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
747 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
751 * Here we have detected that the kernel stack pointer is bad.
752 * R9 contains the saved CR, r13 points to the paca,
753 * r10 contains the (bad) kernel stack pointer,
754 * r11 and r12 contain the saved SRR0 and SRR1.
755 * We switch to using the paca guard page as an emergency stack,
756 * save the registers there, and call kernel_bad_stack(), which panics.
759 ld r1,PACAEMERGSP(r13)
760 subi r1,r1,64+INT_FRAME_SIZE
781 addi r11,r1,INT_FRAME_SIZE
786 1: addi r3,r1,STACK_FRAME_OVERHEAD
791 * Return from an exception with minimal checks.
792 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
793 * If interrupts have been enabled, or anything has been
794 * done that might have changed the scheduling status of
795 * any task or sent any task a signal, you should use
796 * ret_from_except or ret_from_except_lite instead of this.
798 fast_exception_return:
801 andi. r3,r12,MSR_RI /* check if RI is set */
815 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
823 b . /* prevent speculative execution */
827 1: addi r3,r1,STACK_FRAME_OVERHEAD
828 bl .unrecoverable_exception
832 * Here r13 points to the paca, r9 contains the saved CR,
833 * SRR0 and SRR1 are saved in r11 and r12,
834 * r9 - r13 are saved in paca->exgen.
837 .globl data_access_common
839 RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
841 std r10,PACA_EXGEN+EX_DAR(r13)
843 stw r10,PACA_EXGEN+EX_DSISR(r13)
844 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
845 ld r3,PACA_EXGEN+EX_DAR(r13)
846 lwz r4,PACA_EXGEN+EX_DSISR(r13)
848 b .do_hash_page /* Try to handle as hpte fault */
851 .globl instruction_access_common
852 instruction_access_common:
853 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
857 b .do_hash_page /* Try to handle as hpte fault */
860 .globl hardware_interrupt_common
861 .globl hardware_interrupt_entry
862 hardware_interrupt_common:
863 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
864 hardware_interrupt_entry:
866 addi r3,r1,STACK_FRAME_OVERHEAD
868 b .ret_from_except_lite
871 .globl alignment_common
874 std r10,PACA_EXGEN+EX_DAR(r13)
876 stw r10,PACA_EXGEN+EX_DSISR(r13)
877 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
878 ld r3,PACA_EXGEN+EX_DAR(r13)
879 lwz r4,PACA_EXGEN+EX_DSISR(r13)
883 addi r3,r1,STACK_FRAME_OVERHEAD
885 bl .alignment_exception
889 .globl program_check_common
890 program_check_common:
891 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
893 addi r3,r1,STACK_FRAME_OVERHEAD
895 bl .program_check_exception
899 .globl fp_unavailable_common
900 fp_unavailable_common:
901 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
902 bne .load_up_fpu /* if from user, just load it up */
904 addi r3,r1,STACK_FRAME_OVERHEAD
906 bl .kernel_fp_unavailable_exception
910 .globl altivec_unavailable_common
911 altivec_unavailable_common:
912 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
913 #ifdef CONFIG_ALTIVEC
915 bne .load_up_altivec /* if from user, just load it up */
916 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
919 addi r3,r1,STACK_FRAME_OVERHEAD
921 bl .altivec_unavailable_exception
928 _GLOBAL(do_hash_page)
932 andis. r0,r4,0xa450 /* weird error? */
933 bne- .handle_page_fault /* if not, try to insert a HPTE */
935 andis. r0,r4,0x0020 /* Is it a segment table fault? */
936 bne- .do_ste_alloc /* If so handle it */
937 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
940 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
941 * accessing a userspace segment (even from the kernel). We assume
942 * kernel addresses always have the high bit set.
944 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
945 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
946 orc r0,r12,r0 /* MSR_PR | ~high_bit */
947 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
948 ori r4,r4,1 /* add _PAGE_PRESENT */
949 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
952 * On iSeries, we soft-disable interrupts here, then
953 * hard-enable interrupts so that the hash_page code can spin on
954 * the hash_table_lock without problems on a shared processor.
959 * r3 contains the faulting address
960 * r4 contains the required access permissions
961 * r5 contains the trap number
963 * at return r3 = 0 for success
965 bl .hash_page /* build HPTE if possible */
966 cmpdi r3,0 /* see if hash_page succeeded */
968 #ifdef DO_SOFT_DISABLE
970 * If we had interrupts soft-enabled at the point where the
971 * DSI/ISI occurred, and an interrupt came in during hash_page,
973 * We jump to ret_from_except_lite rather than fast_exception_return
974 * because ret_from_except_lite will check for and handle pending
975 * interrupts if necessary.
977 beq .ret_from_except_lite
978 /* For a hash failure, we don't bother re-enabling interrupts */
982 * hash_page couldn't handle it, set soft interrupt enable back
983 * to what it was before the trap. Note that .local_irq_restore
984 * handles any interrupts pending at this point.
987 bl .local_irq_restore
990 beq fast_exception_return /* Return from exception on success */
991 ble- 12f /* Failure return from hash_page */
996 /* Here we have a page fault that hash_page can't handle. */
997 _GLOBAL(handle_page_fault)
1001 addi r3,r1,STACK_FRAME_OVERHEAD
1004 beq+ .ret_from_except_lite
1007 addi r3,r1,STACK_FRAME_OVERHEAD
1012 /* We have a page fault that hash_page could handle but HV refused
1016 addi r3,r1,STACK_FRAME_OVERHEAD
1021 /* here we have a segment miss */
1022 _GLOBAL(do_ste_alloc)
1023 bl .ste_allocate /* try to insert stab entry */
1025 beq+ fast_exception_return
1026 b .handle_page_fault
1029 * r13 points to the PACA, r9 contains the saved CR,
1030 * r11 and r12 contain the saved SRR0 and SRR1.
1031 * r9 - r13 are saved in paca->exslb.
1032 * We assume we aren't going to take any exceptions during this procedure.
1033 * We assume (DAR >> 60) == 0xc.
1036 _GLOBAL(do_stab_bolted)
1037 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1038 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1040 /* Hash to the primary group */
1041 ld r10,PACASTABVIRT(r13)
1044 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1046 /* Calculate VSID */
1047 /* This is a kernel address, so protovsid = ESID */
1048 ASM_VSID_SCRAMBLE(r11, r9)
1049 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1051 /* Search the primary group for a free entry */
1052 1: ld r11,0(r10) /* Test valid bit of the current ste */
1059 /* Stick for only searching the primary group for now. */
1060 /* At least for now, we use a very simple random castout scheme */
1061 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1063 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1066 /* r10 currently points to an ste one past the group of interest */
1067 /* make it point to the randomly selected entry */
1069 or r10,r10,r11 /* r10 is the entry to invalidate */
1071 isync /* mark the entry invalid */
1073 rldicl r11,r11,56,1 /* clear the valid bit */
1078 clrrdi r11,r11,28 /* Get the esid part of the ste */
1081 2: std r9,8(r10) /* Store the vsid part of the ste */
1084 mfspr r11,DAR /* Get the new esid */
1085 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1086 ori r11,r11,0x90 /* Turn on valid and kp */
1087 std r11,0(r10) /* Put new entry back into the stab */
1091 /* All done -- return from exception. */
1092 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1093 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1095 andi. r10,r12,MSR_RI
1098 mtcrf 0x80,r9 /* restore CR */
1106 ld r9,PACA_EXSLB+EX_R9(r13)
1107 ld r10,PACA_EXSLB+EX_R10(r13)
1108 ld r11,PACA_EXSLB+EX_R11(r13)
1109 ld r12,PACA_EXSLB+EX_R12(r13)
1110 ld r13,PACA_EXSLB+EX_R13(r13)
1112 b . /* prevent speculative execution */
1115 * r13 points to the PACA, r9 contains the saved CR,
1116 * r11 and r12 contain the saved SRR0 and SRR1.
1117 * r3 has the faulting address
1118 * r9 - r13 are saved in paca->exslb.
1119 * r3 is saved in paca->slb_r3
1120 * We assume we aren't going to take any exceptions during this procedure.
1122 _GLOBAL(do_slb_miss)
1125 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1126 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1128 bl .slb_allocate /* handle it */
1130 /* All done -- return from exception. */
1132 ld r10,PACA_EXSLB+EX_LR(r13)
1133 ld r3,PACA_EXSLB+EX_R3(r13)
1134 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1135 #ifdef CONFIG_PPC_ISERIES
1136 ld r11,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
1137 #endif /* CONFIG_PPC_ISERIES */
1141 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1147 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1150 #ifdef CONFIG_PPC_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
1172 * On pSeries, secondary processors spin in the following code.
1173 * At entry, r3 = this processor's number (physical cpu id)
1175 _GLOBAL(pSeries_secondary_smp_init)
1178 /* turn on 64-bit mode */
1182 /* Copy some CPU settings from CPU 0 */
1183 bl .__restore_cpu_setup
1185 /* Set up a paca value for this processor. Since we have the
1186 * physical cpu id in r24, we need to search the pacas to find
1187 * which logical id maps to our physical one.
1189 LOADADDR(r13, paca) /* Get base vaddr of paca array */
1190 li r5,0 /* logical cpu id */
1191 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1192 cmpw r6,r24 /* Compare to our id */
1194 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1199 mr r3,r24 /* not found, copy phys to r3 */
1200 b .kexec_wait /* next kernel might do better */
1202 2: mtspr SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1203 /* From now on, r24 is expected to be logica cpuid */
1206 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1210 /* Create a temp kernel stack for use before relocation is on. */
1211 ld r1,PACAEMERGSP(r13)
1212 subi r1,r1,STACK_FRAME_OVERHEAD
1216 #ifdef SECONDARY_PROCESSORS
1217 bne .__secondary_start
1220 b 3b /* Loop until told to go */
1222 #ifdef CONFIG_PPC_ISERIES
1223 _STATIC(__start_initialization_iSeries)
1224 /* Clear out the BSS */
1225 LOADADDR(r11,__bss_stop)
1226 LOADADDR(r8,__bss_start)
1227 sub r11,r11,r8 /* bss size */
1228 addi r11,r11,7 /* round up to an even double word */
1229 rldicl. r11,r11,61,3 /* shift right by 3 */
1233 mtctr r11 /* zero this many doublewords */
1237 LOADADDR(r1,init_thread_union)
1238 addi r1,r1,THREAD_SIZE
1240 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1242 LOADADDR(r3,cpu_specs)
1243 LOADADDR(r4,cur_cpu_spec)
1247 LOADADDR(r2,__toc_start)
1251 bl .iSeries_early_setup
1253 /* relocation is on at this point */
1255 b .start_here_common
1256 #endif /* CONFIG_PPC_ISERIES */
1258 #ifdef CONFIG_PPC_MULTIPLATFORM
1262 andi. r0,r3,MSR_IR|MSR_DR
1269 b . /* prevent speculative execution */
1273 * Here is our main kernel entry point. We support currently 2 kind of entries
1274 * depending on the value of r5.
1276 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1279 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1280 * DT block, r4 is a physical pointer to the kernel itself
1283 _GLOBAL(__start_initialization_multiplatform)
1285 * Are we booted from a PROM Of-type client-interface ?
1288 bne .__boot_from_prom /* yes -> prom */
1290 /* Save parameters */
1294 /* Make sure we are running in 64 bits mode */
1297 /* Setup some critical 970 SPRs before switching MMU off */
1298 bl .__970_cpu_preinit
1303 /* Switch off MMU if not already */
1304 LOADADDR(r4, .__after_prom_start - KERNELBASE)
1307 b .__after_prom_start
1309 _STATIC(__boot_from_prom)
1310 /* Save parameters */
1317 /* Make sure we are running in 64 bits mode */
1320 /* put a relocation offset into r3 */
1323 LOADADDR(r2,__toc_start)
1327 /* Relocate the TOC from a virt addr to a real addr */
1330 /* Restore parameters */
1337 /* Do all of the interaction with OF client interface */
1339 /* We never return */
1343 * At this point, r3 contains the physical address we are running at,
1344 * returned by prom_init()
1346 _STATIC(__after_prom_start)
1349 * We need to run with __start at physical address 0.
1350 * This will leave some code in the first 256B of
1351 * real memory, which are reserved for software use.
1352 * The remainder of the first page is loaded with the fixed
1353 * interrupt vectors. The next two pages are filled with
1354 * unknown exception placeholders.
1356 * Note: This process overwrites the OF exception vectors.
1357 * r26 == relocation offset
1362 SET_REG_TO_CONST(r27,KERNELBASE)
1364 li r3,0 /* target addr */
1366 // XXX FIXME: Use phys returned by OF (r30)
1367 sub r4,r27,r26 /* source addr */
1368 /* current address of _start */
1369 /* i.e. where we are running */
1370 /* the source addr */
1372 LOADADDR(r5,copy_to_here) /* # bytes of memory to copy */
1375 li r6,0x100 /* Start offset, the first 0x100 */
1376 /* bytes were copied earlier. */
1378 bl .copy_and_flush /* copy the first n bytes */
1379 /* this includes the code being */
1380 /* executed here. */
1382 LOADADDR(r0, 4f) /* Jump to the copy of this code */
1383 mtctr r0 /* that we just made/relocated */
1386 4: LOADADDR(r5,klimit)
1388 ld r5,0(r5) /* get the value of klimit */
1390 bl .copy_and_flush /* copy the rest */
1391 b .start_here_multiplatform
1393 #endif /* CONFIG_PPC_MULTIPLATFORM */
1396 * Copy routine used to copy the kernel to start at physical address 0
1397 * and flush and invalidate the caches as needed.
1398 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1399 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1401 * Note: this routine *only* clobbers r0, r6 and lr
1403 _GLOBAL(copy_and_flush)
1406 4: li r0,16 /* Use the least common */
1407 /* denominator cache line */
1408 /* size. This results in */
1409 /* extra cache line flushes */
1410 /* but operation is correct. */
1411 /* Can't get cache line size */
1412 /* from NACA as it is being */
1415 mtctr r0 /* put # words/line in ctr */
1416 3: addi r6,r6,8 /* copy a cache line */
1420 dcbst r6,r3 /* write it to memory */
1422 icbi r6,r3 /* flush the icache line */
1434 * load_up_fpu(unused, unused, tsk)
1435 * Disable FP for the task which had the FPU previously,
1436 * and save its floating-point registers in its thread_struct.
1437 * Enables the FPU for use in the kernel on return.
1438 * On SMP we know the fpu is free, since we give it up every
1439 * switch (ie, no lazy save of the FP registers).
1440 * On entry: r13 == 'current' && last_task_used_math != 'current'
1442 _STATIC(load_up_fpu)
1443 mfmsr r5 /* grab the current MSR */
1445 mtmsrd r5 /* enable use of fpu now */
1448 * For SMP, we don't do lazy FPU switching because it just gets too
1449 * horrendously complex, especially when a task switches from one CPU
1450 * to another. Instead we call giveup_fpu in switch_to.
1454 ld r3,last_task_used_math@got(r2)
1458 /* Save FP state to last_task_used_math's THREAD struct */
1462 stfd fr0,THREAD_FPSCR(r4)
1463 /* Disable FP for last_task_used_math */
1465 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1466 li r6,MSR_FP|MSR_FE0|MSR_FE1
1468 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1470 #endif /* CONFIG_SMP */
1471 /* enable use of FP after return */
1472 ld r4,PACACURRENT(r13)
1473 addi r5,r4,THREAD /* Get THREAD */
1474 ld r4,THREAD_FPEXC_MODE(r5)
1478 lfd fr0,THREAD_FPSCR(r5)
1482 /* Update last_task_used_math to 'current' */
1483 subi r4,r5,THREAD /* Back to 'current' */
1485 #endif /* CONFIG_SMP */
1486 /* restore registers and return */
1487 b fast_exception_return
1490 * disable_kernel_fp()
1493 _GLOBAL(disable_kernel_fp)
1495 rldicl r0,r3,(63-MSR_FP_LG),1
1496 rldicl r3,r0,(MSR_FP_LG+1),0
1497 mtmsrd r3 /* disable use of fpu now */
1503 * Disable FP for the task given as the argument,
1504 * and save the floating-point registers in its thread_struct.
1505 * Enables the FPU for use in the kernel on return.
1510 mtmsrd r5 /* enable use of fpu now */
1513 beqlr- /* if no previous owner, done */
1514 addi r3,r3,THREAD /* want THREAD of task */
1519 stfd fr0,THREAD_FPSCR(r3)
1521 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1522 li r3,MSR_FP|MSR_FE0|MSR_FE1
1523 andc r4,r4,r3 /* disable FP for previous task */
1524 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1528 ld r4,last_task_used_math@got(r2)
1530 #endif /* CONFIG_SMP */
1534 #ifdef CONFIG_ALTIVEC
1537 * load_up_altivec(unused, unused, tsk)
1538 * Disable VMX for the task which had it previously,
1539 * and save its vector registers in its thread_struct.
1540 * Enables the VMX for use in the kernel on return.
1541 * On SMP we know the VMX is free, since we give it up every
1542 * switch (ie, no lazy save of the vector registers).
1543 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1545 _STATIC(load_up_altivec)
1546 mfmsr r5 /* grab the current MSR */
1547 oris r5,r5,MSR_VEC@h
1548 mtmsrd r5 /* enable use of VMX now */
1552 * For SMP, we don't do lazy VMX switching because it just gets too
1553 * horrendously complex, especially when a task switches from one CPU
1554 * to another. Instead we call giveup_altvec in switch_to.
1555 * VRSAVE isn't dealt with here, that is done in the normal context
1556 * switch code. Note that we could rely on vrsave value to eventually
1557 * avoid saving all of the VREGs here...
1560 ld r3,last_task_used_altivec@got(r2)
1564 /* Save VMX state to last_task_used_altivec's THREAD struct */
1570 /* Disable VMX for last_task_used_altivec */
1572 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1575 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1577 #endif /* CONFIG_SMP */
1578 /* Hack: if we get an altivec unavailable trap with VRSAVE
1579 * set to all zeros, we assume this is a broken application
1580 * that fails to set it properly, and thus we switch it to
1583 mfspr r4,SPRN_VRSAVE
1587 mtspr SPRN_VRSAVE,r4
1589 /* enable use of VMX after return */
1590 ld r4,PACACURRENT(r13)
1591 addi r5,r4,THREAD /* Get THREAD */
1592 oris r12,r12,MSR_VEC@h
1596 stw r4,THREAD_USED_VR(r5)
1601 /* Update last_task_used_math to 'current' */
1602 subi r4,r5,THREAD /* Back to 'current' */
1604 #endif /* CONFIG_SMP */
1605 /* restore registers and return */
1606 b fast_exception_return
1609 * disable_kernel_altivec()
1612 _GLOBAL(disable_kernel_altivec)
1614 rldicl r0,r3,(63-MSR_VEC_LG),1
1615 rldicl r3,r0,(MSR_VEC_LG+1),0
1616 mtmsrd r3 /* disable use of VMX now */
1621 * giveup_altivec(tsk)
1622 * Disable VMX for the task given as the argument,
1623 * and save the vector registers in its thread_struct.
1624 * Enables the VMX for use in the kernel on return.
1626 _GLOBAL(giveup_altivec)
1628 oris r5,r5,MSR_VEC@h
1629 mtmsrd r5 /* enable use of VMX now */
1632 beqlr- /* if no previous owner, done */
1633 addi r3,r3,THREAD /* want THREAD of task */
1641 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1643 andc r4,r4,r3 /* disable FP for previous task */
1644 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1648 ld r4,last_task_used_altivec@got(r2)
1650 #endif /* CONFIG_SMP */
1653 #endif /* CONFIG_ALTIVEC */
1656 #ifdef CONFIG_PPC_PMAC
1658 * On PowerMac, secondary processors starts from the reset vector, which
1659 * is temporarily turned into a call to one of the functions below.
1664 .globl pmac_secondary_start_1
1665 pmac_secondary_start_1:
1667 b .pmac_secondary_start
1669 .globl pmac_secondary_start_2
1670 pmac_secondary_start_2:
1672 b .pmac_secondary_start
1674 .globl pmac_secondary_start_3
1675 pmac_secondary_start_3:
1677 b .pmac_secondary_start
1679 _GLOBAL(pmac_secondary_start)
1680 /* turn on 64-bit mode */
1684 /* Copy some CPU settings from CPU 0 */
1685 bl .__restore_cpu_setup
1687 /* pSeries do that early though I don't think we really need it */
1690 mtmsrd r3 /* RI on */
1692 /* Set up a paca value for this processor. */
1693 LOADADDR(r4, paca) /* Get base vaddr of paca array */
1694 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1695 add r13,r13,r4 /* for this processor. */
1696 mtspr SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1698 /* Create a temp kernel stack for use before relocation is on. */
1699 ld r1,PACAEMERGSP(r13)
1700 subi r1,r1,STACK_FRAME_OVERHEAD
1702 b .__secondary_start
1704 #endif /* CONFIG_PPC_PMAC */
1707 * This function is called after the master CPU has released the
1708 * secondary processors. The execution environment is relocation off.
1709 * The paca for this processor has the following fields initialized at
1711 * 1. Processor number
1712 * 2. Segment table pointer (virtual address)
1713 * On entry the following are set:
1714 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1715 * r24 = cpu# (in Linux terms)
1716 * r13 = paca virtual address
1717 * SPRG3 = paca virtual address
1719 _GLOBAL(__secondary_start)
1721 HMT_MEDIUM /* Set thread priority to MEDIUM */
1725 stb r6,PACAPROCENABLED(r13)
1727 #ifndef CONFIG_PPC_ISERIES
1728 /* Initialize the page table pointer register. */
1730 ld r6,0(r6) /* get the value of _SDR1 */
1731 mtspr SDR1,r6 /* set the htab location */
1733 /* Initialize the first segment table (or SLB) entry */
1734 ld r3,PACASTABVIRT(r13) /* get addr of segment table */
1737 /* Initialize the kernel stack. Just a repeat for iSeries. */
1738 LOADADDR(r3,current_set)
1739 sldi r28,r24,3 /* get current_set[cpu#] */
1741 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1742 std r1,PACAKSAVE(r13)
1744 ld r3,PACASTABREAL(r13) /* get raddr of segment table */
1745 ori r4,r3,1 /* turn on valid bit */
1747 #ifdef CONFIG_PPC_ISERIES
1748 li r0,-1 /* hypervisor call */
1750 sldi r3,r3,63 /* 0x8000000000000000 */
1751 ori r3,r3,4 /* 0x8000000000000004 */
1752 sc /* HvCall_setASR */
1755 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1756 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1757 cmpldi r3,PLATFORM_PSERIES_LPAR
1761 cmpwi r3,0x37 /* SStar */
1763 cmpwi r3,0x36 /* IStar */
1765 cmpwi r3,0x34 /* Pulsar */
1767 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
1768 HVSC /* Invoking hcall */
1770 98: /* !(rpa hypervisor) || !(star) */
1771 mtasr r4 /* set the stab location */
1777 /* enable MMU and jump to start_secondary */
1778 LOADADDR(r3,.start_secondary_prolog)
1779 SET_REG_TO_CONST(r4, MSR_KERNEL)
1780 #ifdef DO_SOFT_DISABLE
1786 b . /* prevent speculative execution */
1789 * Running with relocation on at this point. All we want to do is
1790 * zero the stack back-chain pointer before going into C code.
1792 _GLOBAL(start_secondary_prolog)
1794 std r3,0(r1) /* Zero the stack frame pointer */
1799 * This subroutine clobbers r11 and r12
1801 _GLOBAL(enable_64b_mode)
1802 mfmsr r11 /* grab the current MSR */
1804 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1807 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1813 #ifdef CONFIG_PPC_MULTIPLATFORM
1815 * This is where the main kernel code starts.
1817 _STATIC(start_here_multiplatform)
1818 /* get a new offset, now that the kernel has moved. */
1822 /* Clear out the BSS. It may have been done in prom_init,
1823 * already but that's irrelevant since prom_init will soon
1824 * be detached from the kernel completely. Besides, we need
1825 * to clear it now for kexec-style entry.
1827 LOADADDR(r11,__bss_stop)
1828 LOADADDR(r8,__bss_start)
1829 sub r11,r11,r8 /* bss size */
1830 addi r11,r11,7 /* round up to an even double word */
1831 rldicl. r11,r11,61,3 /* shift right by 3 */
1835 mtctr r11 /* zero this many doublewords */
1842 mtmsrd r6 /* RI on */
1845 /* Start up the second thread on cpu 0 */
1848 cmpwi r3,0x34 /* Pulsar */
1850 cmpwi r3,0x36 /* Icestar */
1852 cmpwi r3,0x37 /* SStar */
1854 b 91f /* HMT not supported */
1856 bl .hmt_start_secondary
1860 /* The following gets the stack and TOC set up with the regs */
1861 /* pointing to the real addr of the kernel stack. This is */
1862 /* all done to support the C function call below which sets */
1863 /* up the htab. This is done because we have relocated the */
1864 /* kernel but are still running in real mode. */
1866 LOADADDR(r3,init_thread_union)
1869 /* set up a stack pointer (physical address) */
1870 addi r1,r3,THREAD_SIZE
1872 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1874 /* set up the TOC (physical address) */
1875 LOADADDR(r2,__toc_start)
1880 LOADADDR(r3,cpu_specs)
1882 LOADADDR(r4,cur_cpu_spec)
1887 /* Save some low level config HIDs of CPU0 to be copied to
1888 * other CPUs later on, or used for suspend/resume
1890 bl .__save_cpu_setup
1893 /* Setup a valid physical PACA pointer in SPRG3 for early_setup
1894 * note that boot_cpuid can always be 0 nowadays since there is
1895 * nowhere it can be initialized differently before we reach this
1898 LOADADDR(r27, boot_cpuid)
1902 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1903 mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
1904 add r13,r13,r24 /* for this processor. */
1905 sub r13,r13,r26 /* convert to physical addr */
1906 mtspr SPRG3,r13 /* PPPBBB: Temp... -Peter */
1908 /* Do very early kernel initializations, including initial hash table,
1909 * stab and slb setup before we turn on relocation. */
1911 /* Restore parameters passed from prom_init/kexec */
1916 ld r3,PACASTABREAL(r13)
1917 ori r4,r3,1 /* turn on valid bit */
1918 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1919 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1920 cmpldi r3,PLATFORM_PSERIES_LPAR
1924 cmpwi r3,0x37 /* SStar */
1926 cmpwi r3,0x36 /* IStar */
1928 cmpwi r3,0x34 /* Pulsar */
1930 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
1931 HVSC /* Invoking hcall */
1933 98: /* !(rpa hypervisor) || !(star) */
1934 mtasr r4 /* set the stab location */
1936 /* Set SDR1 (hash table pointer) */
1937 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1938 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1939 /* Test if bit 0 is set (LPAR bit) */
1942 LOADADDR(r6,_SDR1) /* Only if NOT LPAR */
1944 ld r6,0(r6) /* get the value of _SDR1 */
1945 mtspr SDR1,r6 /* set the htab location */
1947 LOADADDR(r3,.start_here_common)
1948 SET_REG_TO_CONST(r4, MSR_KERNEL)
1952 b . /* prevent speculative execution */
1953 #endif /* CONFIG_PPC_MULTIPLATFORM */
1955 /* This is where all platforms converge execution */
1956 _STATIC(start_here_common)
1957 /* relocation is on at this point */
1959 /* The following code sets up the SP and TOC now that we are */
1960 /* running with translation enabled. */
1962 LOADADDR(r3,init_thread_union)
1964 /* set up the stack */
1965 addi r1,r3,THREAD_SIZE
1967 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1969 /* Apply the CPUs-specific fixups (nop out sections not relevant
1973 bl .do_cpu_ftr_fixups
1975 LOADADDR(r26, boot_cpuid)
1978 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1979 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1980 add r13,r13,r24 /* for this processor. */
1983 /* ptr to current */
1984 LOADADDR(r4,init_task)
1985 std r4,PACACURRENT(r13)
1989 std r1,PACAKSAVE(r13)
1993 /* Load up the kernel context */
1995 #ifdef DO_SOFT_DISABLE
1997 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1999 ori r5,r5,MSR_EE /* Hard Enabled */
2005 _GLOBAL(__setup_cpu_power3)
2010 LOADADDR(r5, hmt_thread_data)
2013 cmpwi r7,0x34 /* Pulsar */
2015 cmpwi r7,0x36 /* Icestar */
2017 cmpwi r7,0x37 /* SStar */
2027 bl .hmt_start_secondary
2030 __hmt_secondary_hold:
2031 LOADADDR(r5, hmt_thread_data)
2041 93: andi. r6,r6,0x3f
2055 b .pSeries_secondary_smp_init
2058 _GLOBAL(hmt_start_secondary)
2059 LOADADDR(r4,__hmt_secondary_hold)
2074 mfspr r4, SPRN_CTRLF
2076 mtspr SPRN_CTRLT, r4
2080 #if defined(CONFIG_KEXEC) || (defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES))
2081 _GLOBAL(smp_release_cpus)
2082 /* All secondary cpus are spinning on a common
2083 * spinloop, release them all now so they can start
2084 * to spin on their individual paca spinloops.
2085 * For non SMP kernels, the secondary cpus never
2086 * get out of the common spinloop.
2089 LOADADDR(r5,__secondary_hold_spinloop)
2093 #endif /* CONFIG_SMP && !CONFIG_PPC_ISERIES */
2097 * We put a few things here that have to be page-aligned.
2098 * This stuff goes at the beginning of the data segment,
2099 * which is page-aligned.
2105 .globl empty_zero_page
2109 .globl swapper_pg_dir
2114 * This space gets a copy of optional info passed to us by the bootstrap
2115 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2119 .space COMMAND_LINE_SIZE