blob: a4ceb9ae20fc01bfd67bcc0790cf695b6b92f090 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
2 * arch/ppc64/kernel/head.S
3 *
4 * PowerPC version
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
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.
13 *
14 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
15 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
16 *
17 * This file contains the low-level support and setup for the
18 * PowerPC-64 platform, including trap and interrupt dispatch.
19 *
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.
24 */
25
26#include <linux/config.h>
27#include <linux/threads.h>
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100028#include <asm/reg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100029#include <asm/page.h>
30#include <asm/mmu.h>
31#include <asm/systemcfg.h>
32#include <asm/ppc_asm.h>
33#include <asm/asm-offsets.h>
34#include <asm/bug.h>
35#include <asm/cputable.h>
36#include <asm/setup.h>
37#include <asm/hvcall.h>
38#include <asm/iSeries/LparMap.h>
39
40#ifdef CONFIG_PPC_ISERIES
41#define DO_SOFT_DISABLE
42#endif
43
44/*
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
52 */
53
54/*
55 * SPRG Usage
56 *
57 * Register Definition
58 *
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
63 */
64
65/*
66 * Entering into this code we make the following assumptions:
67 * For pSeries:
68 * 1. The MMU is off & open firmware is running in real mode.
69 * 2. The kernel is entered at __start
70 *
71 * For iSeries:
72 * 1. The MMU is on (as it always is for iSeries)
73 * 2. The kernel is entered at system_reset_iSeries
74 */
75
76 .text
77 .globl _stext
78_stext:
79#ifdef CONFIG_PPC_MULTIPLATFORM
80_GLOBAL(__start)
81 /* NOP this out unconditionally */
82BEGIN_FTR_SECTION
Paul Mackerrasb85a0462005-10-06 10:59:19 +100083 b .__start_initialization_multiplatform
Paul Mackerras14cf11a2005-09-26 16:04:21 +100084END_FTR_SECTION(0, 1)
85#endif /* CONFIG_PPC_MULTIPLATFORM */
86
87 /* Catch branch to 0 in real mode */
88 trap
89
90#ifdef CONFIG_PPC_ISERIES
91 /*
92 * At offset 0x20, there is a pointer to iSeries LPAR data.
93 * This is required by the hypervisor
94 */
95 . = 0x20
96 .llong hvReleaseData-KERNELBASE
97
98 /*
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)
103 */
104 .llong mschunks_map-KERNELBASE
105 .llong 0 /* pidhash-KERNELBASE SFRXXX */
106
107 /* Offset 0x38 - Pointer to start of embedded System.map */
108 .globl embedded_sysmap_start
109embedded_sysmap_start:
110 .llong 0
111 /* Offset 0x40 - Pointer to end of embedded System.map */
112 .globl embedded_sysmap_end
113embedded_sysmap_end:
114 .llong 0
115
116#endif /* CONFIG_PPC_ISERIES */
117
118 /* Secondary processors spin on this value until it goes to 1. */
119 .globl __secondary_hold_spinloop
120__secondary_hold_spinloop:
121 .llong 0x0
122
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:
127 .llong 0x0
128
129 . = 0x60
130/*
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.
136 */
137_GLOBAL(__secondary_hold)
138 mfmsr r24
139 ori r24,r24,MSR_RI
140 mtmsrd r24 /* RI on */
141
142 /* Grab our linux cpu number */
143 mr r24,r3
144
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)
149 sync
150
151 /* All secondary cpus wait here until told to start. */
152100: ld r4,__secondary_hold_spinloop@l(0)
153 cmpdi 0,r4,1
154 bne 100b
155
156#ifdef CONFIG_HMT
157 b .hmt_init
158#else
159#ifdef CONFIG_SMP
160 mr r3,r24
161 b .pSeries_secondary_smp_init
162#else
163 BUG_OPCODE
164#endif
165#endif
166
167/* This value is used to mark exception frames on the stack. */
168 .section ".toc","aw"
169exception_marker:
170 .tc ID_72656773_68657265[TC],0x7265677368657265
171 .text
172
173/*
174 * The following macros define the code that appears as
175 * the prologue to each of the exception handlers. They
176 * are split into two parts to allow a single kernel binary
177 * to be used for pSeries and iSeries.
178 * LOL. One day... - paulus
179 */
180
181/*
182 * We make as much of the exception code common between native
183 * exception handlers (including pSeries LPAR) and iSeries LPAR
184 * implementations as possible.
185 */
186
187/*
188 * This is the start of the interrupt handlers for pSeries
189 * This code runs with relocation off.
190 */
191#define EX_R9 0
192#define EX_R10 8
193#define EX_R11 16
194#define EX_R12 24
195#define EX_R13 32
196#define EX_SRR0 40
197#define EX_R3 40 /* SLB miss saves R3, but not SRR0 */
198#define EX_DAR 48
199#define EX_LR 48 /* SLB miss saves LR, but not DAR */
200#define EX_DSISR 56
201#define EX_CCR 60
202
203#define EXCEPTION_PROLOG_PSERIES(area, label) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000204 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000205 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
206 std r10,area+EX_R10(r13); \
207 std r11,area+EX_R11(r13); \
208 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000209 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000210 std r9,area+EX_R13(r13); \
211 mfcr r9; \
212 clrrdi r12,r13,32; /* get high part of &label */ \
213 mfmsr r10; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000214 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000215 ori r12,r12,(label)@l; /* virt addr of handler */ \
216 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000217 mtspr SPRN_SRR0,r12; \
218 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
219 mtspr SPRN_SRR1,r10; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000220 rfid; \
221 b . /* prevent speculative execution */
222
223/*
224 * This is the start of the interrupt handlers for iSeries
225 * This code runs with relocation on.
226 */
227#define EXCEPTION_PROLOG_ISERIES_1(area) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000228 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000229 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
230 std r10,area+EX_R10(r13); \
231 std r11,area+EX_R11(r13); \
232 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000233 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000234 std r9,area+EX_R13(r13); \
235 mfcr r9
236
237#define EXCEPTION_PROLOG_ISERIES_2 \
238 mfmsr r10; \
239 ld r11,PACALPPACA+LPPACASRR0(r13); \
240 ld r12,PACALPPACA+LPPACASRR1(r13); \
241 ori r10,r10,MSR_RI; \
242 mtmsrd r10,1
243
244/*
245 * The common exception prolog is used for all except a few exceptions
246 * such as a segment miss on a kernel address. We have to be prepared
247 * to take another exception from the point where we first touch the
248 * kernel stack onwards.
249 *
250 * On entry r13 points to the paca, r9-r13 are saved in the paca,
251 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
252 * SRR1, and relocation is on.
253 */
254#define EXCEPTION_PROLOG_COMMON(n, area) \
255 andi. r10,r12,MSR_PR; /* See if coming from user */ \
256 mr r10,r1; /* Save r1 */ \
257 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
258 beq- 1f; \
259 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
2601: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
261 bge- cr1,bad_stack; /* abort if it is */ \
262 std r9,_CCR(r1); /* save CR in stackframe */ \
263 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
264 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
265 std r10,0(r1); /* make stack chain pointer */ \
266 std r0,GPR0(r1); /* save r0 in stackframe */ \
267 std r10,GPR1(r1); /* save r1 in stackframe */ \
268 std r2,GPR2(r1); /* save r2 in stackframe */ \
269 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
270 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
271 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
272 ld r10,area+EX_R10(r13); \
273 std r9,GPR9(r1); \
274 std r10,GPR10(r1); \
275 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
276 ld r10,area+EX_R12(r13); \
277 ld r11,area+EX_R13(r13); \
278 std r9,GPR11(r1); \
279 std r10,GPR12(r1); \
280 std r11,GPR13(r1); \
281 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
282 mflr r9; /* save LR in stackframe */ \
283 std r9,_LINK(r1); \
284 mfctr r10; /* save CTR in stackframe */ \
285 std r10,_CTR(r1); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000286 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000287 std r11,_XER(r1); \
288 li r9,(n)+1; \
289 std r9,_TRAP(r1); /* set trap number */ \
290 li r10,0; \
291 ld r11,exception_marker@toc(r2); \
292 std r10,RESULT(r1); /* clear regs->result */ \
293 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
294
295/*
296 * Exception vectors.
297 */
298#define STD_EXCEPTION_PSERIES(n, label) \
299 . = n; \
300 .globl label##_pSeries; \
301label##_pSeries: \
302 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000303 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000304 RUNLATCH_ON(r13); \
305 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
306
307#define STD_EXCEPTION_ISERIES(n, label, area) \
308 .globl label##_iSeries; \
309label##_iSeries: \
310 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000311 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000312 RUNLATCH_ON(r13); \
313 EXCEPTION_PROLOG_ISERIES_1(area); \
314 EXCEPTION_PROLOG_ISERIES_2; \
315 b label##_common
316
317#define MASKABLE_EXCEPTION_ISERIES(n, label) \
318 .globl label##_iSeries; \
319label##_iSeries: \
320 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000321 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000322 RUNLATCH_ON(r13); \
323 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
324 lbz r10,PACAPROCENABLED(r13); \
325 cmpwi 0,r10,0; \
326 beq- label##_iSeries_masked; \
327 EXCEPTION_PROLOG_ISERIES_2; \
328 b label##_common; \
329
330#ifdef DO_SOFT_DISABLE
331#define DISABLE_INTS \
332 lbz r10,PACAPROCENABLED(r13); \
333 li r11,0; \
334 std r10,SOFTE(r1); \
335 mfmsr r10; \
336 stb r11,PACAPROCENABLED(r13); \
337 ori r10,r10,MSR_EE; \
338 mtmsrd r10,1
339
340#define ENABLE_INTS \
341 lbz r10,PACAPROCENABLED(r13); \
342 mfmsr r11; \
343 std r10,SOFTE(r1); \
344 ori r11,r11,MSR_EE; \
345 mtmsrd r11,1
346
347#else /* hard enable/disable interrupts */
348#define DISABLE_INTS
349
350#define ENABLE_INTS \
351 ld r12,_MSR(r1); \
352 mfmsr r11; \
353 rlwimi r11,r12,0,MSR_EE; \
354 mtmsrd r11,1
355
356#endif
357
358#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
359 .align 7; \
360 .globl label##_common; \
361label##_common: \
362 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
363 DISABLE_INTS; \
364 bl .save_nvgprs; \
365 addi r3,r1,STACK_FRAME_OVERHEAD; \
366 bl hdlr; \
367 b .ret_from_except
368
369#define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
370 .align 7; \
371 .globl label##_common; \
372label##_common: \
373 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
374 DISABLE_INTS; \
375 addi r3,r1,STACK_FRAME_OVERHEAD; \
376 bl hdlr; \
377 b .ret_from_except_lite
378
379/*
380 * Start of pSeries system interrupt routines
381 */
382 . = 0x100
383 .globl __start_interrupts
384__start_interrupts:
385
386 STD_EXCEPTION_PSERIES(0x100, system_reset)
387
388 . = 0x200
389_machine_check_pSeries:
390 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000391 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000392 RUNLATCH_ON(r13)
393 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
394
395 . = 0x300
396 .globl data_access_pSeries
397data_access_pSeries:
398 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000399 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000400BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000401 mtspr SPRN_SPRG2,r12
402 mfspr r13,SPRN_DAR
403 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000404 srdi r13,r13,60
405 rlwimi r13,r12,16,0x20
406 mfcr r12
407 cmpwi r13,0x2c
408 beq .do_stab_bolted_pSeries
409 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000410 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000411END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
412 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
413
414 . = 0x380
415 .globl data_access_slb_pSeries
416data_access_slb_pSeries:
417 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000418 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000419 RUNLATCH_ON(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000420 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000421 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
422 std r10,PACA_EXSLB+EX_R10(r13)
423 std r11,PACA_EXSLB+EX_R11(r13)
424 std r12,PACA_EXSLB+EX_R12(r13)
425 std r3,PACA_EXSLB+EX_R3(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000426 mfspr r9,SPRN_SPRG1
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000427 std r9,PACA_EXSLB+EX_R13(r13)
428 mfcr r9
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000429 mfspr r12,SPRN_SRR1 /* and SRR1 */
430 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000431 b .do_slb_miss /* Rel. branch works in real mode */
432
433 STD_EXCEPTION_PSERIES(0x400, instruction_access)
434
435 . = 0x480
436 .globl instruction_access_slb_pSeries
437instruction_access_slb_pSeries:
438 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000439 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000440 RUNLATCH_ON(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000441 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000442 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
443 std r10,PACA_EXSLB+EX_R10(r13)
444 std r11,PACA_EXSLB+EX_R11(r13)
445 std r12,PACA_EXSLB+EX_R12(r13)
446 std r3,PACA_EXSLB+EX_R3(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000447 mfspr r9,SPRN_SPRG1
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000448 std r9,PACA_EXSLB+EX_R13(r13)
449 mfcr r9
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000450 mfspr r12,SPRN_SRR1 /* and SRR1 */
451 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000452 b .do_slb_miss /* Rel. branch works in real mode */
453
454 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
455 STD_EXCEPTION_PSERIES(0x600, alignment)
456 STD_EXCEPTION_PSERIES(0x700, program_check)
457 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
458 STD_EXCEPTION_PSERIES(0x900, decrementer)
459 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
460 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
461
462 . = 0xc00
463 .globl system_call_pSeries
464system_call_pSeries:
465 HMT_MEDIUM
466 RUNLATCH_ON(r9)
467 mr r9,r13
468 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000469 mfspr r13,SPRN_SPRG3
470 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000471 clrrdi r12,r13,32
472 oris r12,r12,system_call_common@h
473 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000474 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000475 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000476 mfspr r12,SPRN_SRR1
477 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000478 rfid
479 b . /* prevent speculative execution */
480
481 STD_EXCEPTION_PSERIES(0xd00, single_step)
482 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
483
484 /* We need to deal with the Altivec unavailable exception
485 * here which is at 0xf20, thus in the middle of the
486 * prolog code of the PerformanceMonitor one. A little
487 * trickery is thus necessary
488 */
489 . = 0xf00
490 b performance_monitor_pSeries
491
492 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
493
494 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
495 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
496
497 . = 0x3000
498
499/*** pSeries interrupt support ***/
500
501 /* moved from 0xf00 */
502 STD_EXCEPTION_PSERIES(., performance_monitor)
503
504 .align 7
505_GLOBAL(do_stab_bolted_pSeries)
506 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000507 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000508 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
509
510/*
511 * Vectors for the FWNMI option. Share common code.
512 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000513 .globl system_reset_fwnmi
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000514system_reset_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000515 HMT_MEDIUM
516 mtspr SPRN_SPRG1,r13 /* save r13 */
517 RUNLATCH_ON(r13)
518 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000519
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000520 .globl machine_check_fwnmi
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000521machine_check_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000522 HMT_MEDIUM
523 mtspr SPRN_SPRG1,r13 /* save r13 */
524 RUNLATCH_ON(r13)
525 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000526
527#ifdef CONFIG_PPC_ISERIES
528/*** ISeries-LPAR interrupt handlers ***/
529
530 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
531
532 .globl data_access_iSeries
533data_access_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000534 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000535BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000536 mtspr SPRN_SPRG2,r12
537 mfspr r13,SPRN_DAR
538 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000539 srdi r13,r13,60
540 rlwimi r13,r12,16,0x20
541 mfcr r12
542 cmpwi r13,0x2c
543 beq .do_stab_bolted_iSeries
544 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000545 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000546END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
547 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
548 EXCEPTION_PROLOG_ISERIES_2
549 b data_access_common
550
551.do_stab_bolted_iSeries:
552 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000553 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000554 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
555 EXCEPTION_PROLOG_ISERIES_2
556 b .do_stab_bolted
557
558 .globl data_access_slb_iSeries
559data_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000560 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000561 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
562 std r3,PACA_EXSLB+EX_R3(r13)
563 ld r12,PACALPPACA+LPPACASRR1(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000564 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000565 b .do_slb_miss
566
567 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
568
569 .globl instruction_access_slb_iSeries
570instruction_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000571 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000572 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
573 std r3,PACA_EXSLB+EX_R3(r13)
574 ld r12,PACALPPACA+LPPACASRR1(r13)
575 ld r3,PACALPPACA+LPPACASRR0(r13)
576 b .do_slb_miss
577
578 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
579 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
580 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
581 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
582 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
583 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
584 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
585
586 .globl system_call_iSeries
587system_call_iSeries:
588 mr r9,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000589 mfspr r13,SPRN_SPRG3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000590 EXCEPTION_PROLOG_ISERIES_2
591 b system_call_common
592
593 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
594 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
595 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
596
597 .globl system_reset_iSeries
598system_reset_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000599 mfspr r13,SPRN_SPRG3 /* Get paca address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000600 mfmsr r24
601 ori r24,r24,MSR_RI
602 mtmsrd r24 /* RI on */
603 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
604 cmpwi 0,r24,0 /* Are we processor 0? */
605 beq .__start_initialization_iSeries /* Start up the first processor */
606 mfspr r4,SPRN_CTRLF
607 li r5,CTRL_RUNLATCH /* Turn off the run light */
608 andc r4,r4,r5
609 mtspr SPRN_CTRLT,r4
610
6111:
612 HMT_LOW
613#ifdef CONFIG_SMP
614 lbz r23,PACAPROCSTART(r13) /* Test if this processor
615 * should start */
616 sync
617 LOADADDR(r3,current_set)
618 sldi r28,r24,3 /* get current_set[cpu#] */
619 ldx r3,r3,r28
620 addi r1,r3,THREAD_SIZE
621 subi r1,r1,STACK_FRAME_OVERHEAD
622
623 cmpwi 0,r23,0
624 beq iSeries_secondary_smp_loop /* Loop until told to go */
625 bne .__secondary_start /* Loop until told to go */
626iSeries_secondary_smp_loop:
627 /* Let the Hypervisor know we are alive */
628 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
629 lis r3,0x8002
630 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
631#else /* CONFIG_SMP */
632 /* Yield the processor. This is required for non-SMP kernels
633 which are running on multi-threaded machines. */
634 lis r3,0x8000
635 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
636 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
637 li r4,0 /* "yield timed" */
638 li r5,-1 /* "yield forever" */
639#endif /* CONFIG_SMP */
640 li r0,-1 /* r0=-1 indicates a Hypervisor call */
641 sc /* Invoke the hypervisor via a system call */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000642 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000643 b 1b /* If SMP not configured, secondaries
644 * loop forever */
645
646 .globl decrementer_iSeries_masked
647decrementer_iSeries_masked:
648 li r11,1
649 stb r11,PACALPPACA+LPPACADECRINT(r13)
650 lwz r12,PACADEFAULTDECR(r13)
651 mtspr SPRN_DEC,r12
652 /* fall through */
653
654 .globl hardware_interrupt_iSeries_masked
655hardware_interrupt_iSeries_masked:
656 mtcrf 0x80,r9 /* Restore regs */
657 ld r11,PACALPPACA+LPPACASRR0(r13)
658 ld r12,PACALPPACA+LPPACASRR1(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000659 mtspr SPRN_SRR0,r11
660 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000661 ld r9,PACA_EXGEN+EX_R9(r13)
662 ld r10,PACA_EXGEN+EX_R10(r13)
663 ld r11,PACA_EXGEN+EX_R11(r13)
664 ld r12,PACA_EXGEN+EX_R12(r13)
665 ld r13,PACA_EXGEN+EX_R13(r13)
666 rfid
667 b . /* prevent speculative execution */
668#endif /* CONFIG_PPC_ISERIES */
669
670/*** Common interrupt handlers ***/
671
672 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
673
674 /*
675 * Machine check is different because we use a different
676 * save area: PACA_EXMC instead of PACA_EXGEN.
677 */
678 .align 7
679 .globl machine_check_common
680machine_check_common:
681 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
682 DISABLE_INTS
683 bl .save_nvgprs
684 addi r3,r1,STACK_FRAME_OVERHEAD
685 bl .machine_check_exception
686 b .ret_from_except
687
688 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
689 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
690 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
691 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
692 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
693 STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
694 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
695#ifdef CONFIG_ALTIVEC
696 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
697#else
698 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
699#endif
700
701/*
702 * Here we have detected that the kernel stack pointer is bad.
703 * R9 contains the saved CR, r13 points to the paca,
704 * r10 contains the (bad) kernel stack pointer,
705 * r11 and r12 contain the saved SRR0 and SRR1.
706 * We switch to using an emergency stack, save the registers there,
707 * and call kernel_bad_stack(), which panics.
708 */
709bad_stack:
710 ld r1,PACAEMERGSP(r13)
711 subi r1,r1,64+INT_FRAME_SIZE
712 std r9,_CCR(r1)
713 std r10,GPR1(r1)
714 std r11,_NIP(r1)
715 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000716 mfspr r11,SPRN_DAR
717 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000718 std r11,_DAR(r1)
719 std r12,_DSISR(r1)
720 mflr r10
721 mfctr r11
722 mfxer r12
723 std r10,_LINK(r1)
724 std r11,_CTR(r1)
725 std r12,_XER(r1)
726 SAVE_GPR(0,r1)
727 SAVE_GPR(2,r1)
728 SAVE_4GPRS(3,r1)
729 SAVE_2GPRS(7,r1)
730 SAVE_10GPRS(12,r1)
731 SAVE_10GPRS(22,r1)
732 addi r11,r1,INT_FRAME_SIZE
733 std r11,0(r1)
734 li r12,0
735 std r12,0(r11)
736 ld r2,PACATOC(r13)
7371: addi r3,r1,STACK_FRAME_OVERHEAD
738 bl .kernel_bad_stack
739 b 1b
740
741/*
742 * Return from an exception with minimal checks.
743 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
744 * If interrupts have been enabled, or anything has been
745 * done that might have changed the scheduling status of
746 * any task or sent any task a signal, you should use
747 * ret_from_except or ret_from_except_lite instead of this.
748 */
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000749 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000750fast_exception_return:
751 ld r12,_MSR(r1)
752 ld r11,_NIP(r1)
753 andi. r3,r12,MSR_RI /* check if RI is set */
754 beq- unrecov_fer
755 ld r3,_CCR(r1)
756 ld r4,_LINK(r1)
757 ld r5,_CTR(r1)
758 ld r6,_XER(r1)
759 mtcr r3
760 mtlr r4
761 mtctr r5
762 mtxer r6
763 REST_GPR(0, r1)
764 REST_8GPRS(2, r1)
765
766 mfmsr r10
767 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
768 mtmsrd r10,1
769
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000770 mtspr SPRN_SRR1,r12
771 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000772 REST_4GPRS(10, r1)
773 ld r1,GPR1(r1)
774 rfid
775 b . /* prevent speculative execution */
776
777unrecov_fer:
778 bl .save_nvgprs
7791: addi r3,r1,STACK_FRAME_OVERHEAD
780 bl .unrecoverable_exception
781 b 1b
782
783/*
784 * Here r13 points to the paca, r9 contains the saved CR,
785 * SRR0 and SRR1 are saved in r11 and r12,
786 * r9 - r13 are saved in paca->exgen.
787 */
788 .align 7
789 .globl data_access_common
790data_access_common:
791 RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000792 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000793 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000794 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000795 stw r10,PACA_EXGEN+EX_DSISR(r13)
796 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
797 ld r3,PACA_EXGEN+EX_DAR(r13)
798 lwz r4,PACA_EXGEN+EX_DSISR(r13)
799 li r5,0x300
800 b .do_hash_page /* Try to handle as hpte fault */
801
802 .align 7
803 .globl instruction_access_common
804instruction_access_common:
805 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
806 ld r3,_NIP(r1)
807 andis. r4,r12,0x5820
808 li r5,0x400
809 b .do_hash_page /* Try to handle as hpte fault */
810
811 .align 7
812 .globl hardware_interrupt_common
813 .globl hardware_interrupt_entry
814hardware_interrupt_common:
815 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
816hardware_interrupt_entry:
817 DISABLE_INTS
818 addi r3,r1,STACK_FRAME_OVERHEAD
819 bl .do_IRQ
820 b .ret_from_except_lite
821
822 .align 7
823 .globl alignment_common
824alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000825 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000826 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000827 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000828 stw r10,PACA_EXGEN+EX_DSISR(r13)
829 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
830 ld r3,PACA_EXGEN+EX_DAR(r13)
831 lwz r4,PACA_EXGEN+EX_DSISR(r13)
832 std r3,_DAR(r1)
833 std r4,_DSISR(r1)
834 bl .save_nvgprs
835 addi r3,r1,STACK_FRAME_OVERHEAD
836 ENABLE_INTS
837 bl .alignment_exception
838 b .ret_from_except
839
840 .align 7
841 .globl program_check_common
842program_check_common:
843 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
844 bl .save_nvgprs
845 addi r3,r1,STACK_FRAME_OVERHEAD
846 ENABLE_INTS
847 bl .program_check_exception
848 b .ret_from_except
849
850 .align 7
851 .globl fp_unavailable_common
852fp_unavailable_common:
853 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
854 bne .load_up_fpu /* if from user, just load it up */
855 bl .save_nvgprs
856 addi r3,r1,STACK_FRAME_OVERHEAD
857 ENABLE_INTS
858 bl .kernel_fp_unavailable_exception
859 BUG_OPCODE
860
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000861 .align 7
862 .globl altivec_unavailable_common
863altivec_unavailable_common:
864 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
865#ifdef CONFIG_ALTIVEC
866BEGIN_FTR_SECTION
867 bne .load_up_altivec /* if from user, just load it up */
868END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
869#endif
870 bl .save_nvgprs
871 addi r3,r1,STACK_FRAME_OVERHEAD
872 ENABLE_INTS
873 bl .altivec_unavailable_exception
874 b .ret_from_except
875
876#ifdef CONFIG_ALTIVEC
877/*
878 * load_up_altivec(unused, unused, tsk)
879 * Disable VMX for the task which had it previously,
880 * and save its vector registers in its thread_struct.
881 * Enables the VMX for use in the kernel on return.
882 * On SMP we know the VMX is free, since we give it up every
883 * switch (ie, no lazy save of the vector registers).
884 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
885 */
886_STATIC(load_up_altivec)
887 mfmsr r5 /* grab the current MSR */
888 oris r5,r5,MSR_VEC@h
889 mtmsrd r5 /* enable use of VMX now */
890 isync
891
892/*
893 * For SMP, we don't do lazy VMX switching because it just gets too
894 * horrendously complex, especially when a task switches from one CPU
895 * to another. Instead we call giveup_altvec in switch_to.
896 * VRSAVE isn't dealt with here, that is done in the normal context
897 * switch code. Note that we could rely on vrsave value to eventually
898 * avoid saving all of the VREGs here...
899 */
900#ifndef CONFIG_SMP
901 ld r3,last_task_used_altivec@got(r2)
902 ld r4,0(r3)
903 cmpdi 0,r4,0
904 beq 1f
905 /* Save VMX state to last_task_used_altivec's THREAD struct */
906 addi r4,r4,THREAD
907 SAVE_32VRS(0,r5,r4)
908 mfvscr vr0
909 li r10,THREAD_VSCR
910 stvx vr0,r10,r4
911 /* Disable VMX for last_task_used_altivec */
912 ld r5,PT_REGS(r4)
913 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
914 lis r6,MSR_VEC@h
915 andc r4,r4,r6
916 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
9171:
918#endif /* CONFIG_SMP */
919 /* Hack: if we get an altivec unavailable trap with VRSAVE
920 * set to all zeros, we assume this is a broken application
921 * that fails to set it properly, and thus we switch it to
922 * all 1's
923 */
924 mfspr r4,SPRN_VRSAVE
925 cmpdi 0,r4,0
926 bne+ 1f
927 li r4,-1
928 mtspr SPRN_VRSAVE,r4
9291:
930 /* enable use of VMX after return */
931 ld r4,PACACURRENT(r13)
932 addi r5,r4,THREAD /* Get THREAD */
933 oris r12,r12,MSR_VEC@h
934 std r12,_MSR(r1)
935 li r4,1
936 li r10,THREAD_VSCR
937 stw r4,THREAD_USED_VR(r5)
938 lvx vr0,r10,r5
939 mtvscr vr0
940 REST_32VRS(0,r4,r5)
941#ifndef CONFIG_SMP
942 /* Update last_task_used_math to 'current' */
943 subi r4,r5,THREAD /* Back to 'current' */
944 std r4,0(r3)
945#endif /* CONFIG_SMP */
946 /* restore registers and return */
947 b fast_exception_return
948#endif /* CONFIG_ALTIVEC */
949
950/*
951 * Hash table stuff
952 */
953 .align 7
954_GLOBAL(do_hash_page)
955 std r3,_DAR(r1)
956 std r4,_DSISR(r1)
957
958 andis. r0,r4,0xa450 /* weird error? */
959 bne- .handle_page_fault /* if not, try to insert a HPTE */
960BEGIN_FTR_SECTION
961 andis. r0,r4,0x0020 /* Is it a segment table fault? */
962 bne- .do_ste_alloc /* If so handle it */
963END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
964
965 /*
966 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
967 * accessing a userspace segment (even from the kernel). We assume
968 * kernel addresses always have the high bit set.
969 */
970 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
971 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
972 orc r0,r12,r0 /* MSR_PR | ~high_bit */
973 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
974 ori r4,r4,1 /* add _PAGE_PRESENT */
975 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
976
977 /*
978 * On iSeries, we soft-disable interrupts here, then
979 * hard-enable interrupts so that the hash_page code can spin on
980 * the hash_table_lock without problems on a shared processor.
981 */
982 DISABLE_INTS
983
984 /*
985 * r3 contains the faulting address
986 * r4 contains the required access permissions
987 * r5 contains the trap number
988 *
989 * at return r3 = 0 for success
990 */
991 bl .hash_page /* build HPTE if possible */
992 cmpdi r3,0 /* see if hash_page succeeded */
993
994#ifdef DO_SOFT_DISABLE
995 /*
996 * If we had interrupts soft-enabled at the point where the
997 * DSI/ISI occurred, and an interrupt came in during hash_page,
998 * handle it now.
999 * We jump to ret_from_except_lite rather than fast_exception_return
1000 * because ret_from_except_lite will check for and handle pending
1001 * interrupts if necessary.
1002 */
1003 beq .ret_from_except_lite
1004 /* For a hash failure, we don't bother re-enabling interrupts */
1005 ble- 12f
1006
1007 /*
1008 * hash_page couldn't handle it, set soft interrupt enable back
1009 * to what it was before the trap. Note that .local_irq_restore
1010 * handles any interrupts pending at this point.
1011 */
1012 ld r3,SOFTE(r1)
1013 bl .local_irq_restore
1014 b 11f
1015#else
1016 beq fast_exception_return /* Return from exception on success */
1017 ble- 12f /* Failure return from hash_page */
1018
1019 /* fall through */
1020#endif
1021
1022/* Here we have a page fault that hash_page can't handle. */
1023_GLOBAL(handle_page_fault)
1024 ENABLE_INTS
102511: ld r4,_DAR(r1)
1026 ld r5,_DSISR(r1)
1027 addi r3,r1,STACK_FRAME_OVERHEAD
1028 bl .do_page_fault
1029 cmpdi r3,0
1030 beq+ .ret_from_except_lite
1031 bl .save_nvgprs
1032 mr r5,r3
1033 addi r3,r1,STACK_FRAME_OVERHEAD
1034 lwz r4,_DAR(r1)
1035 bl .bad_page_fault
1036 b .ret_from_except
1037
1038/* We have a page fault that hash_page could handle but HV refused
1039 * the PTE insertion
1040 */
104112: bl .save_nvgprs
1042 addi r3,r1,STACK_FRAME_OVERHEAD
1043 lwz r4,_DAR(r1)
1044 bl .low_hash_fault
1045 b .ret_from_except
1046
1047 /* here we have a segment miss */
1048_GLOBAL(do_ste_alloc)
1049 bl .ste_allocate /* try to insert stab entry */
1050 cmpdi r3,0
1051 beq+ fast_exception_return
1052 b .handle_page_fault
1053
1054/*
1055 * r13 points to the PACA, r9 contains the saved CR,
1056 * r11 and r12 contain the saved SRR0 and SRR1.
1057 * r9 - r13 are saved in paca->exslb.
1058 * We assume we aren't going to take any exceptions during this procedure.
1059 * We assume (DAR >> 60) == 0xc.
1060 */
1061 .align 7
1062_GLOBAL(do_stab_bolted)
1063 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1064 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1065
1066 /* Hash to the primary group */
1067 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001068 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001069 srdi r11,r11,28
1070 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1071
1072 /* Calculate VSID */
1073 /* This is a kernel address, so protovsid = ESID */
1074 ASM_VSID_SCRAMBLE(r11, r9)
1075 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1076
1077 /* Search the primary group for a free entry */
10781: ld r11,0(r10) /* Test valid bit of the current ste */
1079 andi. r11,r11,0x80
1080 beq 2f
1081 addi r10,r10,16
1082 andi. r11,r10,0x70
1083 bne 1b
1084
1085 /* Stick for only searching the primary group for now. */
1086 /* At least for now, we use a very simple random castout scheme */
1087 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1088 mftb r11
1089 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1090 ori r11,r11,0x10
1091
1092 /* r10 currently points to an ste one past the group of interest */
1093 /* make it point to the randomly selected entry */
1094 subi r10,r10,128
1095 or r10,r10,r11 /* r10 is the entry to invalidate */
1096
1097 isync /* mark the entry invalid */
1098 ld r11,0(r10)
1099 rldicl r11,r11,56,1 /* clear the valid bit */
1100 rotldi r11,r11,8
1101 std r11,0(r10)
1102 sync
1103
1104 clrrdi r11,r11,28 /* Get the esid part of the ste */
1105 slbie r11
1106
11072: std r9,8(r10) /* Store the vsid part of the ste */
1108 eieio
1109
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001110 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001111 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1112 ori r11,r11,0x90 /* Turn on valid and kp */
1113 std r11,0(r10) /* Put new entry back into the stab */
1114
1115 sync
1116
1117 /* All done -- return from exception. */
1118 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1119 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1120
1121 andi. r10,r12,MSR_RI
1122 beq- unrecov_slb
1123
1124 mtcrf 0x80,r9 /* restore CR */
1125
1126 mfmsr r10
1127 clrrdi r10,r10,2
1128 mtmsrd r10,1
1129
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001130 mtspr SPRN_SRR0,r11
1131 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001132 ld r9,PACA_EXSLB+EX_R9(r13)
1133 ld r10,PACA_EXSLB+EX_R10(r13)
1134 ld r11,PACA_EXSLB+EX_R11(r13)
1135 ld r12,PACA_EXSLB+EX_R12(r13)
1136 ld r13,PACA_EXSLB+EX_R13(r13)
1137 rfid
1138 b . /* prevent speculative execution */
1139
1140/*
1141 * r13 points to the PACA, r9 contains the saved CR,
1142 * r11 and r12 contain the saved SRR0 and SRR1.
1143 * r3 has the faulting address
1144 * r9 - r13 are saved in paca->exslb.
1145 * r3 is saved in paca->slb_r3
1146 * We assume we aren't going to take any exceptions during this procedure.
1147 */
1148_GLOBAL(do_slb_miss)
1149 mflr r10
1150
1151 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1152 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1153
1154 bl .slb_allocate /* handle it */
1155
1156 /* All done -- return from exception. */
1157
1158 ld r10,PACA_EXSLB+EX_LR(r13)
1159 ld r3,PACA_EXSLB+EX_R3(r13)
1160 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1161#ifdef CONFIG_PPC_ISERIES
1162 ld r11,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
1163#endif /* CONFIG_PPC_ISERIES */
1164
1165 mtlr r10
1166
1167 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1168 beq- unrecov_slb
1169
1170.machine push
1171.machine "power4"
1172 mtcrf 0x80,r9
1173 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1174.machine pop
1175
1176#ifdef CONFIG_PPC_ISERIES
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001177 mtspr SPRN_SRR0,r11
1178 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001179#endif /* CONFIG_PPC_ISERIES */
1180 ld r9,PACA_EXSLB+EX_R9(r13)
1181 ld r10,PACA_EXSLB+EX_R10(r13)
1182 ld r11,PACA_EXSLB+EX_R11(r13)
1183 ld r12,PACA_EXSLB+EX_R12(r13)
1184 ld r13,PACA_EXSLB+EX_R13(r13)
1185 rfid
1186 b . /* prevent speculative execution */
1187
1188unrecov_slb:
1189 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1190 DISABLE_INTS
1191 bl .save_nvgprs
11921: addi r3,r1,STACK_FRAME_OVERHEAD
1193 bl .unrecoverable_exception
1194 b 1b
1195
1196/*
1197 * Space for CPU0's segment table.
1198 *
1199 * On iSeries, the hypervisor must fill in at least one entry before
1200 * we get control (with relocate on). The address is give to the hv
Stephen Rothwellee400b62005-09-29 11:50:22 +10001201 * as a page number (see xLparMap in lpardata.c), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001202 * fixed address (the linker can't compute (u64)&initial_stab >>
1203 * PAGE_SHIFT).
1204 */
1205 . = STAB0_PHYS_ADDR /* 0x6000 */
1206 .globl initial_stab
1207initial_stab:
1208 .space 4096
1209
1210/*
1211 * Data area reserved for FWNMI option.
1212 * This address (0x7000) is fixed by the RPA.
1213 */
1214 .= 0x7000
1215 .globl fwnmi_data_area
1216fwnmi_data_area:
1217
1218 /* iSeries does not use the FWNMI stuff, so it is safe to put
1219 * this here, even if we later allow kernels that will boot on
1220 * both pSeries and iSeries */
1221#ifdef CONFIG_PPC_ISERIES
1222 . = LPARMAP_PHYS
1223#include "lparmap.s"
1224/*
1225 * This ".text" is here for old compilers that generate a trailing
1226 * .note section when compiling .c files to .s
1227 */
1228 .text
1229#endif /* CONFIG_PPC_ISERIES */
1230
1231 . = 0x8000
1232
1233/*
1234 * On pSeries, secondary processors spin in the following code.
1235 * At entry, r3 = this processor's number (physical cpu id)
1236 */
1237_GLOBAL(pSeries_secondary_smp_init)
1238 mr r24,r3
1239
1240 /* turn on 64-bit mode */
1241 bl .enable_64b_mode
1242 isync
1243
1244 /* Copy some CPU settings from CPU 0 */
1245 bl .__restore_cpu_setup
1246
1247 /* Set up a paca value for this processor. Since we have the
1248 * physical cpu id in r24, we need to search the pacas to find
1249 * which logical id maps to our physical one.
1250 */
1251 LOADADDR(r13, paca) /* Get base vaddr of paca array */
1252 li r5,0 /* logical cpu id */
12531: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1254 cmpw r6,r24 /* Compare to our id */
1255 beq 2f
1256 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1257 addi r5,r5,1
1258 cmpwi r5,NR_CPUS
1259 blt 1b
1260
1261 mr r3,r24 /* not found, copy phys to r3 */
1262 b .kexec_wait /* next kernel might do better */
1263
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100012642: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001265 /* From now on, r24 is expected to be logical cpuid */
1266 mr r24,r5
12673: HMT_LOW
1268 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1269 /* start. */
1270 sync
1271
1272 /* Create a temp kernel stack for use before relocation is on. */
1273 ld r1,PACAEMERGSP(r13)
1274 subi r1,r1,STACK_FRAME_OVERHEAD
1275
1276 cmpwi 0,r23,0
1277#ifdef CONFIG_SMP
1278 bne .__secondary_start
1279#endif
1280 b 3b /* Loop until told to go */
1281
1282#ifdef CONFIG_PPC_ISERIES
1283_STATIC(__start_initialization_iSeries)
1284 /* Clear out the BSS */
1285 LOADADDR(r11,__bss_stop)
1286 LOADADDR(r8,__bss_start)
1287 sub r11,r11,r8 /* bss size */
1288 addi r11,r11,7 /* round up to an even double word */
1289 rldicl. r11,r11,61,3 /* shift right by 3 */
1290 beq 4f
1291 addi r8,r8,-8
1292 li r0,0
1293 mtctr r11 /* zero this many doublewords */
12943: stdu r0,8(r8)
1295 bdnz 3b
12964:
1297 LOADADDR(r1,init_thread_union)
1298 addi r1,r1,THREAD_SIZE
1299 li r0,0
1300 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1301
1302 LOADADDR(r3,cpu_specs)
1303 LOADADDR(r4,cur_cpu_spec)
1304 li r5,0
1305 bl .identify_cpu
1306
1307 LOADADDR(r2,__toc_start)
1308 addi r2,r2,0x4000
1309 addi r2,r2,0x4000
1310
1311 bl .iSeries_early_setup
Stephen Rothwellee400b62005-09-29 11:50:22 +10001312 bl .early_setup
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001313
1314 /* relocation is on at this point */
1315
1316 b .start_here_common
1317#endif /* CONFIG_PPC_ISERIES */
1318
1319#ifdef CONFIG_PPC_MULTIPLATFORM
1320
1321_STATIC(__mmu_off)
1322 mfmsr r3
1323 andi. r0,r3,MSR_IR|MSR_DR
1324 beqlr
1325 andc r3,r3,r0
1326 mtspr SPRN_SRR0,r4
1327 mtspr SPRN_SRR1,r3
1328 sync
1329 rfid
1330 b . /* prevent speculative execution */
1331
1332
1333/*
1334 * Here is our main kernel entry point. We support currently 2 kind of entries
1335 * depending on the value of r5.
1336 *
1337 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1338 * in r3...r7
1339 *
1340 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1341 * DT block, r4 is a physical pointer to the kernel itself
1342 *
1343 */
1344_GLOBAL(__start_initialization_multiplatform)
1345 /*
1346 * Are we booted from a PROM Of-type client-interface ?
1347 */
1348 cmpldi cr0,r5,0
1349 bne .__boot_from_prom /* yes -> prom */
1350
1351 /* Save parameters */
1352 mr r31,r3
1353 mr r30,r4
1354
1355 /* Make sure we are running in 64 bits mode */
1356 bl .enable_64b_mode
1357
1358 /* Setup some critical 970 SPRs before switching MMU off */
1359 bl .__970_cpu_preinit
1360
1361 /* cpu # */
1362 li r24,0
1363
1364 /* Switch off MMU if not already */
1365 LOADADDR(r4, .__after_prom_start - KERNELBASE)
1366 add r4,r4,r30
1367 bl .__mmu_off
1368 b .__after_prom_start
1369
1370_STATIC(__boot_from_prom)
1371 /* Save parameters */
1372 mr r31,r3
1373 mr r30,r4
1374 mr r29,r5
1375 mr r28,r6
1376 mr r27,r7
1377
1378 /* Make sure we are running in 64 bits mode */
1379 bl .enable_64b_mode
1380
1381 /* put a relocation offset into r3 */
1382 bl .reloc_offset
1383
1384 LOADADDR(r2,__toc_start)
1385 addi r2,r2,0x4000
1386 addi r2,r2,0x4000
1387
1388 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001389 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001390
1391 /* Restore parameters */
1392 mr r3,r31
1393 mr r4,r30
1394 mr r5,r29
1395 mr r6,r28
1396 mr r7,r27
1397
1398 /* Do all of the interaction with OF client interface */
1399 bl .prom_init
1400 /* We never return */
1401 trap
1402
1403/*
1404 * At this point, r3 contains the physical address we are running at,
1405 * returned by prom_init()
1406 */
1407_STATIC(__after_prom_start)
1408
1409/*
1410 * We need to run with __start at physical address 0.
1411 * This will leave some code in the first 256B of
1412 * real memory, which are reserved for software use.
1413 * The remainder of the first page is loaded with the fixed
1414 * interrupt vectors. The next two pages are filled with
1415 * unknown exception placeholders.
1416 *
1417 * Note: This process overwrites the OF exception vectors.
1418 * r26 == relocation offset
1419 * r27 == KERNELBASE
1420 */
1421 bl .reloc_offset
1422 mr r26,r3
1423 SET_REG_TO_CONST(r27,KERNELBASE)
1424
1425 li r3,0 /* target addr */
1426
1427 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001428 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001429 /* current address of _start */
1430 /* i.e. where we are running */
1431 /* the source addr */
1432
1433 LOADADDR(r5,copy_to_here) /* # bytes of memory to copy */
1434 sub r5,r5,r27
1435
1436 li r6,0x100 /* Start offset, the first 0x100 */
1437 /* bytes were copied earlier. */
1438
1439 bl .copy_and_flush /* copy the first n bytes */
1440 /* this includes the code being */
1441 /* executed here. */
1442
1443 LOADADDR(r0, 4f) /* Jump to the copy of this code */
1444 mtctr r0 /* that we just made/relocated */
1445 bctr
1446
14474: LOADADDR(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001448 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001449 ld r5,0(r5) /* get the value of klimit */
1450 sub r5,r5,r27
1451 bl .copy_and_flush /* copy the rest */
1452 b .start_here_multiplatform
1453
1454#endif /* CONFIG_PPC_MULTIPLATFORM */
1455
1456/*
1457 * Copy routine used to copy the kernel to start at physical address 0
1458 * and flush and invalidate the caches as needed.
1459 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1460 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1461 *
1462 * Note: this routine *only* clobbers r0, r6 and lr
1463 */
1464_GLOBAL(copy_and_flush)
1465 addi r5,r5,-8
1466 addi r6,r6,-8
14674: li r0,16 /* Use the least common */
1468 /* denominator cache line */
1469 /* size. This results in */
1470 /* extra cache line flushes */
1471 /* but operation is correct. */
1472 /* Can't get cache line size */
1473 /* from NACA as it is being */
1474 /* moved too. */
1475
1476 mtctr r0 /* put # words/line in ctr */
14773: addi r6,r6,8 /* copy a cache line */
1478 ldx r0,r6,r4
1479 stdx r0,r6,r3
1480 bdnz 3b
1481 dcbst r6,r3 /* write it to memory */
1482 sync
1483 icbi r6,r3 /* flush the icache line */
1484 cmpld 0,r6,r5
1485 blt 4b
1486 sync
1487 addi r5,r5,8
1488 addi r6,r6,8
1489 blr
1490
1491.align 8
1492copy_to_here:
1493
1494#ifdef CONFIG_SMP
1495#ifdef CONFIG_PPC_PMAC
1496/*
1497 * On PowerMac, secondary processors starts from the reset vector, which
1498 * is temporarily turned into a call to one of the functions below.
1499 */
1500 .section ".text";
1501 .align 2 ;
1502
1503 .globl pmac_secondary_start_1
1504pmac_secondary_start_1:
1505 li r24, 1
1506 b .pmac_secondary_start
1507
1508 .globl pmac_secondary_start_2
1509pmac_secondary_start_2:
1510 li r24, 2
1511 b .pmac_secondary_start
1512
1513 .globl pmac_secondary_start_3
1514pmac_secondary_start_3:
1515 li r24, 3
1516 b .pmac_secondary_start
1517
1518_GLOBAL(pmac_secondary_start)
1519 /* turn on 64-bit mode */
1520 bl .enable_64b_mode
1521 isync
1522
1523 /* Copy some CPU settings from CPU 0 */
1524 bl .__restore_cpu_setup
1525
1526 /* pSeries do that early though I don't think we really need it */
1527 mfmsr r3
1528 ori r3,r3,MSR_RI
1529 mtmsrd r3 /* RI on */
1530
1531 /* Set up a paca value for this processor. */
1532 LOADADDR(r4, paca) /* Get base vaddr of paca array */
1533 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1534 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001535 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001536
1537 /* Create a temp kernel stack for use before relocation is on. */
1538 ld r1,PACAEMERGSP(r13)
1539 subi r1,r1,STACK_FRAME_OVERHEAD
1540
1541 b .__secondary_start
1542
1543#endif /* CONFIG_PPC_PMAC */
1544
1545/*
1546 * This function is called after the master CPU has released the
1547 * secondary processors. The execution environment is relocation off.
1548 * The paca for this processor has the following fields initialized at
1549 * this point:
1550 * 1. Processor number
1551 * 2. Segment table pointer (virtual address)
1552 * On entry the following are set:
1553 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1554 * r24 = cpu# (in Linux terms)
1555 * r13 = paca virtual address
1556 * SPRG3 = paca virtual address
1557 */
1558_GLOBAL(__secondary_start)
1559
1560 HMT_MEDIUM /* Set thread priority to MEDIUM */
1561
1562 ld r2,PACATOC(r13)
1563 li r6,0
1564 stb r6,PACAPROCENABLED(r13)
1565
1566#ifndef CONFIG_PPC_ISERIES
1567 /* Initialize the page table pointer register. */
1568 LOADADDR(r6,_SDR1)
1569 ld r6,0(r6) /* get the value of _SDR1 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001570 mtspr SPRN_SDR1,r6 /* set the htab location */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001571#endif
1572 /* Initialize the first segment table (or SLB) entry */
1573 ld r3,PACASTABVIRT(r13) /* get addr of segment table */
1574 bl .stab_initialize
1575
1576 /* Initialize the kernel stack. Just a repeat for iSeries. */
1577 LOADADDR(r3,current_set)
1578 sldi r28,r24,3 /* get current_set[cpu#] */
1579 ldx r1,r3,r28
1580 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1581 std r1,PACAKSAVE(r13)
1582
1583 ld r3,PACASTABREAL(r13) /* get raddr of segment table */
1584 ori r4,r3,1 /* turn on valid bit */
1585
1586#ifdef CONFIG_PPC_ISERIES
1587 li r0,-1 /* hypervisor call */
1588 li r3,1
1589 sldi r3,r3,63 /* 0x8000000000000000 */
1590 ori r3,r3,4 /* 0x8000000000000004 */
1591 sc /* HvCall_setASR */
1592#else
1593 /* set the ASR */
1594 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1595 ld r3,0(r3)
1596 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1597 andi. r3,r3,PLATFORM_LPAR /* Test if bit 0 is set (LPAR bit) */
1598 beq 98f /* branch if result is 0 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001599 mfspr r3,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001600 srwi r3,r3,16
1601 cmpwi r3,0x37 /* SStar */
1602 beq 97f
1603 cmpwi r3,0x36 /* IStar */
1604 beq 97f
1605 cmpwi r3,0x34 /* Pulsar */
1606 bne 98f
160797: li r3,H_SET_ASR /* hcall = H_SET_ASR */
1608 HVSC /* Invoking hcall */
1609 b 99f
161098: /* !(rpa hypervisor) || !(star) */
1611 mtasr r4 /* set the stab location */
161299:
1613#endif
1614 li r7,0
1615 mtlr r7
1616
1617 /* enable MMU and jump to start_secondary */
1618 LOADADDR(r3,.start_secondary_prolog)
1619 SET_REG_TO_CONST(r4, MSR_KERNEL)
1620#ifdef DO_SOFT_DISABLE
1621 ori r4,r4,MSR_EE
1622#endif
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001623 mtspr SPRN_SRR0,r3
1624 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001625 rfid
1626 b . /* prevent speculative execution */
1627
1628/*
1629 * Running with relocation on at this point. All we want to do is
1630 * zero the stack back-chain pointer before going into C code.
1631 */
1632_GLOBAL(start_secondary_prolog)
1633 li r3,0
1634 std r3,0(r1) /* Zero the stack frame pointer */
1635 bl .start_secondary
1636#endif
1637
1638/*
1639 * This subroutine clobbers r11 and r12
1640 */
1641_GLOBAL(enable_64b_mode)
1642 mfmsr r11 /* grab the current MSR */
1643 li r12,1
1644 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1645 or r11,r11,r12
1646 li r12,1
1647 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1648 or r11,r11,r12
1649 mtmsrd r11
1650 isync
1651 blr
1652
1653#ifdef CONFIG_PPC_MULTIPLATFORM
1654/*
1655 * This is where the main kernel code starts.
1656 */
1657_STATIC(start_here_multiplatform)
1658 /* get a new offset, now that the kernel has moved. */
1659 bl .reloc_offset
1660 mr r26,r3
1661
1662 /* Clear out the BSS. It may have been done in prom_init,
1663 * already but that's irrelevant since prom_init will soon
1664 * be detached from the kernel completely. Besides, we need
1665 * to clear it now for kexec-style entry.
1666 */
1667 LOADADDR(r11,__bss_stop)
1668 LOADADDR(r8,__bss_start)
1669 sub r11,r11,r8 /* bss size */
1670 addi r11,r11,7 /* round up to an even double word */
1671 rldicl. r11,r11,61,3 /* shift right by 3 */
1672 beq 4f
1673 addi r8,r8,-8
1674 li r0,0
1675 mtctr r11 /* zero this many doublewords */
16763: stdu r0,8(r8)
1677 bdnz 3b
16784:
1679
1680 mfmsr r6
1681 ori r6,r6,MSR_RI
1682 mtmsrd r6 /* RI on */
1683
1684#ifdef CONFIG_HMT
1685 /* Start up the second thread on cpu 0 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001686 mfspr r3,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001687 srwi r3,r3,16
1688 cmpwi r3,0x34 /* Pulsar */
1689 beq 90f
1690 cmpwi r3,0x36 /* Icestar */
1691 beq 90f
1692 cmpwi r3,0x37 /* SStar */
1693 beq 90f
1694 b 91f /* HMT not supported */
169590: li r3,0
1696 bl .hmt_start_secondary
169791:
1698#endif
1699
1700 /* The following gets the stack and TOC set up with the regs */
1701 /* pointing to the real addr of the kernel stack. This is */
1702 /* all done to support the C function call below which sets */
1703 /* up the htab. This is done because we have relocated the */
1704 /* kernel but are still running in real mode. */
1705
1706 LOADADDR(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001707 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001708
1709 /* set up a stack pointer (physical address) */
1710 addi r1,r3,THREAD_SIZE
1711 li r0,0
1712 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1713
1714 /* set up the TOC (physical address) */
1715 LOADADDR(r2,__toc_start)
1716 addi r2,r2,0x4000
1717 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001718 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001719
1720 LOADADDR(r3,cpu_specs)
Paul Mackerras5a408322005-10-10 22:41:25 +10001721 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001722 LOADADDR(r4,cur_cpu_spec)
Paul Mackerras5a408322005-10-10 22:41:25 +10001723 add r4,r4,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001724 mr r5,r26
1725 bl .identify_cpu
1726
1727 /* Save some low level config HIDs of CPU0 to be copied to
1728 * other CPUs later on, or used for suspend/resume
1729 */
1730 bl .__save_cpu_setup
1731 sync
1732
1733 /* Setup a valid physical PACA pointer in SPRG3 for early_setup
1734 * note that boot_cpuid can always be 0 nowadays since there is
1735 * nowhere it can be initialized differently before we reach this
1736 * code
1737 */
1738 LOADADDR(r27, boot_cpuid)
Paul Mackerras5a408322005-10-10 22:41:25 +10001739 add r27,r27,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001740 lwz r27,0(r27)
1741
1742 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1743 mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
1744 add r13,r13,r24 /* for this processor. */
Paul Mackerras5a408322005-10-10 22:41:25 +10001745 add r13,r13,r26 /* convert to physical addr */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001746 mtspr SPRN_SPRG3,r13 /* PPPBBB: Temp... -Peter */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001747
1748 /* Do very early kernel initializations, including initial hash table,
1749 * stab and slb setup before we turn on relocation. */
1750
1751 /* Restore parameters passed from prom_init/kexec */
1752 mr r3,r31
1753 bl .early_setup
1754
1755 /* set the ASR */
1756 ld r3,PACASTABREAL(r13)
1757 ori r4,r3,1 /* turn on valid bit */
1758 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1759 ld r3,0(r3)
1760 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1761 andi. r3,r3,PLATFORM_LPAR /* Test if bit 0 is set (LPAR bit) */
1762 beq 98f /* branch if result is 0 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001763 mfspr r3,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001764 srwi r3,r3,16
1765 cmpwi r3,0x37 /* SStar */
1766 beq 97f
1767 cmpwi r3,0x36 /* IStar */
1768 beq 97f
1769 cmpwi r3,0x34 /* Pulsar */
1770 bne 98f
177197: li r3,H_SET_ASR /* hcall = H_SET_ASR */
1772 HVSC /* Invoking hcall */
1773 b 99f
177498: /* !(rpa hypervisor) || !(star) */
1775 mtasr r4 /* set the stab location */
177699:
1777 /* Set SDR1 (hash table pointer) */
1778 ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
1779 ld r3,0(r3)
1780 lwz r3,PLATFORM(r3) /* r3 = platform flags */
1781 /* Test if bit 0 is set (LPAR bit) */
1782 andi. r3,r3,PLATFORM_LPAR
1783 bne 98f /* branch if result is !0 */
1784 LOADADDR(r6,_SDR1) /* Only if NOT LPAR */
Paul Mackerras5a408322005-10-10 22:41:25 +10001785 add r6,r6,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001786 ld r6,0(r6) /* get the value of _SDR1 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001787 mtspr SPRN_SDR1,r6 /* set the htab location */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000178898:
1789 LOADADDR(r3,.start_here_common)
1790 SET_REG_TO_CONST(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001791 mtspr SPRN_SRR0,r3
1792 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001793 rfid
1794 b . /* prevent speculative execution */
1795#endif /* CONFIG_PPC_MULTIPLATFORM */
1796
1797 /* This is where all platforms converge execution */
1798_STATIC(start_here_common)
1799 /* relocation is on at this point */
1800
1801 /* The following code sets up the SP and TOC now that we are */
1802 /* running with translation enabled. */
1803
1804 LOADADDR(r3,init_thread_union)
1805
1806 /* set up the stack */
1807 addi r1,r3,THREAD_SIZE
1808 li r0,0
1809 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1810
1811 /* Apply the CPUs-specific fixups (nop out sections not relevant
1812 * to this CPU
1813 */
1814 li r3,0
1815 bl .do_cpu_ftr_fixups
1816
1817 LOADADDR(r26, boot_cpuid)
1818 lwz r26,0(r26)
1819
1820 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1821 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1822 add r13,r13,r24 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001823 mtspr SPRN_SPRG3,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001824
1825 /* ptr to current */
1826 LOADADDR(r4,init_task)
1827 std r4,PACACURRENT(r13)
1828
1829 /* Load the TOC */
1830 ld r2,PACATOC(r13)
1831 std r1,PACAKSAVE(r13)
1832
1833 bl .setup_system
1834
1835 /* Load up the kernel context */
18365:
1837#ifdef DO_SOFT_DISABLE
1838 li r5,0
1839 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1840 mfmsr r5
1841 ori r5,r5,MSR_EE /* Hard Enabled */
1842 mtmsrd r5
1843#endif
1844
1845 bl .start_kernel
1846
1847_GLOBAL(hmt_init)
1848#ifdef CONFIG_HMT
1849 LOADADDR(r5, hmt_thread_data)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001850 mfspr r7,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001851 srwi r7,r7,16
1852 cmpwi r7,0x34 /* Pulsar */
1853 beq 90f
1854 cmpwi r7,0x36 /* Icestar */
1855 beq 91f
1856 cmpwi r7,0x37 /* SStar */
1857 beq 91f
1858 b 101f
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000185990: mfspr r6,SPRN_PIR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001860 andi. r6,r6,0x1f
1861 b 92f
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000186291: mfspr r6,SPRN_PIR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001863 andi. r6,r6,0x3ff
186492: sldi r4,r24,3
1865 stwx r6,r5,r4
1866 bl .hmt_start_secondary
1867 b 101f
1868
1869__hmt_secondary_hold:
1870 LOADADDR(r5, hmt_thread_data)
1871 clrldi r5,r5,4
1872 li r7,0
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001873 mfspr r6,SPRN_PIR
1874 mfspr r8,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001875 srwi r8,r8,16
1876 cmpwi r8,0x34
1877 bne 93f
1878 andi. r6,r6,0x1f
1879 b 103f
188093: andi. r6,r6,0x3f
1881
1882103: lwzx r8,r5,r7
1883 cmpw r8,r6
1884 beq 104f
1885 addi r7,r7,8
1886 b 103b
1887
1888104: addi r7,r7,4
1889 lwzx r9,r5,r7
1890 mr r24,r9
1891101:
1892#endif
1893 mr r3,r24
1894 b .pSeries_secondary_smp_init
1895
1896#ifdef CONFIG_HMT
1897_GLOBAL(hmt_start_secondary)
1898 LOADADDR(r4,__hmt_secondary_hold)
1899 clrldi r4,r4,4
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001900 mtspr SPRN_NIADORM, r4
1901 mfspr r4, SPRN_MSRDORM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001902 li r5, -65
1903 and r4, r4, r5
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001904 mtspr SPRN_MSRDORM, r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001905 lis r4,0xffef
1906 ori r4,r4,0x7403
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001907 mtspr SPRN_TSC, r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001908 li r4,0x1f4
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001909 mtspr SPRN_TST, r4
1910 mfspr r4, SPRN_HID0
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001911 ori r4, r4, 0x1
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001912 mtspr SPRN_HID0, r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001913 mfspr r4, SPRN_CTRLF
1914 oris r4, r4, 0x40
1915 mtspr SPRN_CTRLT, r4
1916 blr
1917#endif
1918
Stephen Rothwellee400b62005-09-29 11:50:22 +10001919#if defined(CONFIG_KEXEC) || defined(CONFIG_SMP)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001920_GLOBAL(smp_release_cpus)
1921 /* All secondary cpus are spinning on a common
1922 * spinloop, release them all now so they can start
1923 * to spin on their individual paca spinloops.
1924 * For non SMP kernels, the secondary cpus never
1925 * get out of the common spinloop.
Stephen Rothwellee400b62005-09-29 11:50:22 +10001926 * XXX This does nothing useful on iSeries, secondaries are
1927 * already waiting on their paca.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001928 */
1929 li r3,1
1930 LOADADDR(r5,__secondary_hold_spinloop)
1931 std r3,0(r5)
1932 sync
1933 blr
Stephen Rothwellee400b62005-09-29 11:50:22 +10001934#endif /* CONFIG_SMP */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001935
1936
1937/*
1938 * We put a few things here that have to be page-aligned.
1939 * This stuff goes at the beginning of the bss, which is page-aligned.
1940 */
1941 .section ".bss"
1942
1943 .align PAGE_SHIFT
1944
1945 .globl empty_zero_page
1946empty_zero_page:
1947 .space PAGE_SIZE
1948
1949 .globl swapper_pg_dir
1950swapper_pg_dir:
1951 .space PAGE_SIZE
1952
1953/*
1954 * This space gets a copy of optional info passed to us by the bootstrap
1955 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
1956 */
1957 .globl cmd_line
1958cmd_line:
1959 .space COMMAND_LINE_SIZE