blob: 291e3629b5046e67caea8b9dbbbbbb70ca1eca15 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002 * PowerPC version
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 *
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
11 *
12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
14 *
15 * This file contains the low-level support and setup for the
16 * PowerPC-64 platform, including trap and interrupt dispatch.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 */
23
Paul Mackerras14cf11a2005-09-26 16:04:21 +100024#include <linux/threads.h>
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100025#include <asm/reg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100026#include <asm/page.h>
27#include <asm/mmu.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100028#include <asm/ppc_asm.h>
29#include <asm/asm-offsets.h>
30#include <asm/bug.h>
31#include <asm/cputable.h>
32#include <asm/setup.h>
33#include <asm/hvcall.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110034#include <asm/iseries/lpar_map.h>
David Gibson6cb7bfe2005-10-21 15:45:50 +100035#include <asm/thread_info.h>
Stephen Rothwell3f639ee2006-09-25 18:19:00 +100036#include <asm/firmware.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100037
38#ifdef CONFIG_PPC_ISERIES
39#define DO_SOFT_DISABLE
40#endif
41
42/*
43 * We layout physical memory as follows:
44 * 0x0000 - 0x00ff : Secondary processor spin code
45 * 0x0100 - 0x2fff : pSeries Interrupt prologs
46 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
47 * 0x6000 - 0x6fff : Initial (CPU0) segment table
48 * 0x7000 - 0x7fff : FWNMI data area
49 * 0x8000 - : Early init and support code
50 */
51
52/*
53 * SPRG Usage
54 *
55 * Register Definition
56 *
57 * SPRG0 reserved for hypervisor
58 * SPRG1 temp - used to save gpr
59 * SPRG2 temp - used to save gpr
60 * SPRG3 virt addr of paca
61 */
62
63/*
64 * Entering into this code we make the following assumptions:
65 * For pSeries:
66 * 1. The MMU is off & open firmware is running in real mode.
67 * 2. The kernel is entered at __start
68 *
69 * For iSeries:
70 * 1. The MMU is on (as it always is for iSeries)
71 * 2. The kernel is entered at system_reset_iSeries
72 */
73
74 .text
75 .globl _stext
76_stext:
77#ifdef CONFIG_PPC_MULTIPLATFORM
78_GLOBAL(__start)
79 /* NOP this out unconditionally */
80BEGIN_FTR_SECTION
Paul Mackerrasb85a0462005-10-06 10:59:19 +100081 b .__start_initialization_multiplatform
Paul Mackerras14cf11a2005-09-26 16:04:21 +100082END_FTR_SECTION(0, 1)
83#endif /* CONFIG_PPC_MULTIPLATFORM */
84
85 /* Catch branch to 0 in real mode */
86 trap
87
Paul Mackerras14cf11a2005-09-26 16:04:21 +100088 /* Secondary processors spin on this value until it goes to 1. */
89 .globl __secondary_hold_spinloop
90__secondary_hold_spinloop:
91 .llong 0x0
92
93 /* Secondary processors write this value with their cpu # */
94 /* after they enter the spin loop immediately below. */
95 .globl __secondary_hold_acknowledge
96__secondary_hold_acknowledge:
97 .llong 0x0
98
Michael Ellerman1dce0e32006-06-23 18:15:37 +100099#ifdef CONFIG_PPC_ISERIES
100 /*
101 * At offset 0x20, there is a pointer to iSeries LPAR data.
102 * This is required by the hypervisor
103 */
104 . = 0x20
105 .llong hvReleaseData-KERNELBASE
106#endif /* CONFIG_PPC_ISERIES */
107
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000108 . = 0x60
109/*
110 * The following code is used on pSeries to hold secondary processors
111 * in a spin loop after they have been freed from OpenFirmware, but
112 * before the bulk of the kernel has been relocated. This code
113 * is relocated to physical address 0x60 before prom_init is run.
114 * All of it must fit below the first exception vector at 0x100.
115 */
116_GLOBAL(__secondary_hold)
117 mfmsr r24
118 ori r24,r24,MSR_RI
119 mtmsrd r24 /* RI on */
120
Anton Blanchardf1870f72006-02-13 18:11:13 +1100121 /* Grab our physical cpu number */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000122 mr r24,r3
123
124 /* Tell the master cpu we're here */
125 /* Relocation is off & we are located at an address less */
126 /* than 0x100, so only need to grab low order offset. */
127 std r24,__secondary_hold_acknowledge@l(0)
128 sync
129
130 /* All secondary cpus wait here until told to start. */
131100: ld r4,__secondary_hold_spinloop@l(0)
132 cmpdi 0,r4,1
133 bne 100b
134
Anton Blanchardf1870f72006-02-13 18:11:13 +1100135#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
Olof Johanssonf39b7a52006-08-11 00:07:08 -0500136 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
Michael Ellerman758438a2005-12-05 15:49:00 -0600137 mtctr r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000138 mr r3,r24
Michael Ellerman758438a2005-12-05 15:49:00 -0600139 bctr
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000140#else
141 BUG_OPCODE
142#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000143
144/* This value is used to mark exception frames on the stack. */
145 .section ".toc","aw"
146exception_marker:
147 .tc ID_72656773_68657265[TC],0x7265677368657265
148 .text
149
150/*
151 * The following macros define the code that appears as
152 * the prologue to each of the exception handlers. They
153 * are split into two parts to allow a single kernel binary
154 * to be used for pSeries and iSeries.
155 * LOL. One day... - paulus
156 */
157
158/*
159 * We make as much of the exception code common between native
160 * exception handlers (including pSeries LPAR) and iSeries LPAR
161 * implementations as possible.
162 */
163
164/*
165 * This is the start of the interrupt handlers for pSeries
166 * This code runs with relocation off.
167 */
168#define EX_R9 0
169#define EX_R10 8
170#define EX_R11 16
171#define EX_R12 24
172#define EX_R13 32
173#define EX_SRR0 40
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000174#define EX_DAR 48
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000175#define EX_DSISR 56
176#define EX_CCR 60
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100177#define EX_R3 64
178#define EX_LR 72
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000179
Michael Ellerman758438a2005-12-05 15:49:00 -0600180/*
David Gibsone58c3492006-01-13 14:56:25 +1100181 * We're short on space and time in the exception prolog, so we can't
182 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
183 * low halfword of the address, but for Kdump we need the whole low
184 * word.
Michael Ellerman758438a2005-12-05 15:49:00 -0600185 */
186#ifdef CONFIG_CRASH_DUMP
187#define LOAD_HANDLER(reg, label) \
188 oris reg,reg,(label)@h; /* virt addr of handler ... */ \
189 ori reg,reg,(label)@l; /* .. and the rest */
190#else
191#define LOAD_HANDLER(reg, label) \
192 ori reg,reg,(label)@l; /* virt addr of handler ... */
193#endif
194
Olaf Hering9fc0a922006-07-19 10:34:05 +0200195/*
196 * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode.
197 * The firmware calls the registered system_reset_fwnmi and
198 * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run
199 * a 32bit application at the time of the event.
200 * This firmware bug is present on POWER4 and JS20.
201 */
202#define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \
203 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
204 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
205 std r10,area+EX_R10(r13); \
206 std r11,area+EX_R11(r13); \
207 std r12,area+EX_R12(r13); \
208 mfspr r9,SPRN_SPRG1; \
209 std r9,area+EX_R13(r13); \
210 mfcr r9; \
211 clrrdi r12,r13,32; /* get high part of &label */ \
212 mfmsr r10; \
213 /* force 64bit mode */ \
214 li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \
215 rldimi r10,r11,61,0; /* insert into top 3 bits */ \
216 /* done 64bit mode */ \
217 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
218 LOAD_HANDLER(r12,label) \
219 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
220 mtspr SPRN_SRR0,r12; \
221 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
222 mtspr SPRN_SRR1,r10; \
223 rfid; \
224 b . /* prevent speculative execution */
225
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000226#define EXCEPTION_PROLOG_PSERIES(area, label) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000227 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000228 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
229 std r10,area+EX_R10(r13); \
230 std r11,area+EX_R11(r13); \
231 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000232 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000233 std r9,area+EX_R13(r13); \
234 mfcr r9; \
235 clrrdi r12,r13,32; /* get high part of &label */ \
236 mfmsr r10; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000237 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
Michael Ellerman758438a2005-12-05 15:49:00 -0600238 LOAD_HANDLER(r12,label) \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000239 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000240 mtspr SPRN_SRR0,r12; \
241 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
242 mtspr SPRN_SRR1,r10; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000243 rfid; \
244 b . /* prevent speculative execution */
245
246/*
247 * This is the start of the interrupt handlers for iSeries
248 * This code runs with relocation on.
249 */
250#define EXCEPTION_PROLOG_ISERIES_1(area) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000251 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000252 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
253 std r10,area+EX_R10(r13); \
254 std r11,area+EX_R11(r13); \
255 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000256 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000257 std r9,area+EX_R13(r13); \
258 mfcr r9
259
260#define EXCEPTION_PROLOG_ISERIES_2 \
261 mfmsr r10; \
David Gibson3356bb92006-01-13 10:26:42 +1100262 ld r12,PACALPPACAPTR(r13); \
263 ld r11,LPPACASRR0(r12); \
264 ld r12,LPPACASRR1(r12); \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000265 ori r10,r10,MSR_RI; \
266 mtmsrd r10,1
267
268/*
269 * The common exception prolog is used for all except a few exceptions
270 * such as a segment miss on a kernel address. We have to be prepared
271 * to take another exception from the point where we first touch the
272 * kernel stack onwards.
273 *
274 * On entry r13 points to the paca, r9-r13 are saved in the paca,
275 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
276 * SRR1, and relocation is on.
277 */
278#define EXCEPTION_PROLOG_COMMON(n, area) \
279 andi. r10,r12,MSR_PR; /* See if coming from user */ \
280 mr r10,r1; /* Save r1 */ \
281 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
282 beq- 1f; \
283 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
2841: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
285 bge- cr1,bad_stack; /* abort if it is */ \
286 std r9,_CCR(r1); /* save CR in stackframe */ \
287 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
288 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
289 std r10,0(r1); /* make stack chain pointer */ \
290 std r0,GPR0(r1); /* save r0 in stackframe */ \
291 std r10,GPR1(r1); /* save r1 in stackframe */ \
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100292 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000293 std r2,GPR2(r1); /* save r2 in stackframe */ \
294 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
295 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
296 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
297 ld r10,area+EX_R10(r13); \
298 std r9,GPR9(r1); \
299 std r10,GPR10(r1); \
300 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
301 ld r10,area+EX_R12(r13); \
302 ld r11,area+EX_R13(r13); \
303 std r9,GPR11(r1); \
304 std r10,GPR12(r1); \
305 std r11,GPR13(r1); \
306 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
307 mflr r9; /* save LR in stackframe */ \
308 std r9,_LINK(r1); \
309 mfctr r10; /* save CTR in stackframe */ \
310 std r10,_CTR(r1); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000311 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000312 std r11,_XER(r1); \
313 li r9,(n)+1; \
314 std r9,_TRAP(r1); /* set trap number */ \
315 li r10,0; \
316 ld r11,exception_marker@toc(r2); \
317 std r10,RESULT(r1); /* clear regs->result */ \
318 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
319
320/*
321 * Exception vectors.
322 */
323#define STD_EXCEPTION_PSERIES(n, label) \
324 . = n; \
325 .globl label##_pSeries; \
326label##_pSeries: \
327 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000328 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000329 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
330
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200331#define HSTD_EXCEPTION_PSERIES(n, label) \
332 . = n; \
333 .globl label##_pSeries; \
334label##_pSeries: \
335 HMT_MEDIUM; \
336 mtspr SPRN_SPRG1,r20; /* save r20 */ \
337 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
338 mtspr SPRN_SRR0,r20; \
339 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
340 mtspr SPRN_SRR1,r20; \
341 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
342 mtspr SPRN_SPRG1,r13; /* save r13 */ \
343 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
344
345
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000346#define STD_EXCEPTION_ISERIES(n, label, area) \
347 .globl label##_iSeries; \
348label##_iSeries: \
349 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000350 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000351 EXCEPTION_PROLOG_ISERIES_1(area); \
352 EXCEPTION_PROLOG_ISERIES_2; \
353 b label##_common
354
355#define MASKABLE_EXCEPTION_ISERIES(n, label) \
356 .globl label##_iSeries; \
357label##_iSeries: \
358 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000359 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000360 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
361 lbz r10,PACAPROCENABLED(r13); \
362 cmpwi 0,r10,0; \
363 beq- label##_iSeries_masked; \
364 EXCEPTION_PROLOG_ISERIES_2; \
365 b label##_common; \
366
367#ifdef DO_SOFT_DISABLE
368#define DISABLE_INTS \
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000369BEGIN_FW_FTR_SECTION; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000370 lbz r10,PACAPROCENABLED(r13); \
371 li r11,0; \
372 std r10,SOFTE(r1); \
373 mfmsr r10; \
374 stb r11,PACAPROCENABLED(r13); \
375 ori r10,r10,MSR_EE; \
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000376 mtmsrd r10,1; \
377END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000378
379#define ENABLE_INTS \
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000380BEGIN_FW_FTR_SECTION; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000381 lbz r10,PACAPROCENABLED(r13); \
382 mfmsr r11; \
383 std r10,SOFTE(r1); \
384 ori r11,r11,MSR_EE; \
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000385END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES); \
386BEGIN_FW_FTR_SECTION; \
387 ld r12,_MSR(r1); \
388 mfmsr r11; \
389 rlwimi r11,r12,0,MSR_EE; \
390END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES); \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000391 mtmsrd r11,1
392
393#else /* hard enable/disable interrupts */
394#define DISABLE_INTS
395
396#define ENABLE_INTS \
397 ld r12,_MSR(r1); \
398 mfmsr r11; \
399 rlwimi r11,r12,0,MSR_EE; \
400 mtmsrd r11,1
401
402#endif
403
404#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
405 .align 7; \
406 .globl label##_common; \
407label##_common: \
408 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
409 DISABLE_INTS; \
410 bl .save_nvgprs; \
411 addi r3,r1,STACK_FRAME_OVERHEAD; \
412 bl hdlr; \
413 b .ret_from_except
414
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000415/*
416 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
417 * in the idle task and therefore need the special idle handling.
418 */
419#define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
420 .align 7; \
421 .globl label##_common; \
422label##_common: \
423 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
424 FINISH_NAP; \
425 DISABLE_INTS; \
426 bl .save_nvgprs; \
427 addi r3,r1,STACK_FRAME_OVERHEAD; \
428 bl hdlr; \
429 b .ret_from_except
430
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000431#define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
432 .align 7; \
433 .globl label##_common; \
434label##_common: \
435 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000436 FINISH_NAP; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000437 DISABLE_INTS; \
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100438 bl .ppc64_runlatch_on; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000439 addi r3,r1,STACK_FRAME_OVERHEAD; \
440 bl hdlr; \
441 b .ret_from_except_lite
442
443/*
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000444 * When the idle code in power4_idle puts the CPU into NAP mode,
445 * it has to do so in a loop, and relies on the external interrupt
446 * and decrementer interrupt entry code to get it out of the loop.
447 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
448 * to signal that it is in the loop and needs help to get out.
449 */
450#ifdef CONFIG_PPC_970_NAP
451#define FINISH_NAP \
452BEGIN_FTR_SECTION \
453 clrrdi r11,r1,THREAD_SHIFT; \
454 ld r9,TI_LOCAL_FLAGS(r11); \
455 andi. r10,r9,_TLF_NAPPING; \
456 bnel power4_fixup_nap; \
457END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
458#else
459#define FINISH_NAP
460#endif
461
462/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000463 * Start of pSeries system interrupt routines
464 */
465 . = 0x100
466 .globl __start_interrupts
467__start_interrupts:
468
469 STD_EXCEPTION_PSERIES(0x100, system_reset)
470
471 . = 0x200
472_machine_check_pSeries:
473 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000474 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000475 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
476
477 . = 0x300
478 .globl data_access_pSeries
479data_access_pSeries:
480 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000481 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000482BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000483 mtspr SPRN_SPRG2,r12
484 mfspr r13,SPRN_DAR
485 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000486 srdi r13,r13,60
487 rlwimi r13,r12,16,0x20
488 mfcr r12
489 cmpwi r13,0x2c
490 beq .do_stab_bolted_pSeries
491 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000492 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000493END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
494 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
495
496 . = 0x380
497 .globl data_access_slb_pSeries
498data_access_slb_pSeries:
499 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000500 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000501 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100502 std r3,PACA_EXSLB+EX_R3(r13)
503 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000504 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100505 mfcr r9
506#ifdef __DISABLED__
507 /* Keep that around for when we re-implement dynamic VSIDs */
508 cmpdi r3,0
509 bge slb_miss_user_pseries
510#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000511 std r10,PACA_EXSLB+EX_R10(r13)
512 std r11,PACA_EXSLB+EX_R11(r13)
513 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100514 mfspr r10,SPRN_SPRG1
515 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000516 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100517 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000518
519 STD_EXCEPTION_PSERIES(0x400, instruction_access)
520
521 . = 0x480
522 .globl instruction_access_slb_pSeries
523instruction_access_slb_pSeries:
524 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000525 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000526 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100527 std r3,PACA_EXSLB+EX_R3(r13)
528 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000529 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100530 mfcr r9
531#ifdef __DISABLED__
532 /* Keep that around for when we re-implement dynamic VSIDs */
533 cmpdi r3,0
534 bge slb_miss_user_pseries
535#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000536 std r10,PACA_EXSLB+EX_R10(r13)
537 std r11,PACA_EXSLB+EX_R11(r13)
538 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100539 mfspr r10,SPRN_SPRG1
540 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000541 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100542 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000543
544 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
545 STD_EXCEPTION_PSERIES(0x600, alignment)
546 STD_EXCEPTION_PSERIES(0x700, program_check)
547 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
548 STD_EXCEPTION_PSERIES(0x900, decrementer)
549 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
550 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
551
552 . = 0xc00
553 .globl system_call_pSeries
554system_call_pSeries:
555 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000556 mr r9,r13
557 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000558 mfspr r13,SPRN_SPRG3
559 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000560 clrrdi r12,r13,32
561 oris r12,r12,system_call_common@h
562 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000563 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000564 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000565 mfspr r12,SPRN_SRR1
566 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000567 rfid
568 b . /* prevent speculative execution */
569
570 STD_EXCEPTION_PSERIES(0xd00, single_step)
571 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
572
573 /* We need to deal with the Altivec unavailable exception
574 * here which is at 0xf20, thus in the middle of the
575 * prolog code of the PerformanceMonitor one. A little
576 * trickery is thus necessary
577 */
578 . = 0xf00
579 b performance_monitor_pSeries
580
581 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
582
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200583#ifdef CONFIG_CBE_RAS
584 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
585#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000586 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200587#ifdef CONFIG_CBE_RAS
588 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
589#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000590 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200591#ifdef CONFIG_CBE_RAS
592 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
593#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000594
595 . = 0x3000
596
597/*** pSeries interrupt support ***/
598
599 /* moved from 0xf00 */
600 STD_EXCEPTION_PSERIES(., performance_monitor)
601
602 .align 7
603_GLOBAL(do_stab_bolted_pSeries)
604 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000605 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000606 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
607
608/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100609 * We have some room here we use that to put
610 * the peries slb miss user trampoline code so it's reasonably
611 * away from slb_miss_user_common to avoid problems with rfid
612 *
613 * This is used for when the SLB miss handler has to go virtual,
614 * which doesn't happen for now anymore but will once we re-implement
615 * dynamic VSIDs for shared page tables
616 */
617#ifdef __DISABLED__
618slb_miss_user_pseries:
619 std r10,PACA_EXGEN+EX_R10(r13)
620 std r11,PACA_EXGEN+EX_R11(r13)
621 std r12,PACA_EXGEN+EX_R12(r13)
622 mfspr r10,SPRG1
623 ld r11,PACA_EXSLB+EX_R9(r13)
624 ld r12,PACA_EXSLB+EX_R3(r13)
625 std r10,PACA_EXGEN+EX_R13(r13)
626 std r11,PACA_EXGEN+EX_R9(r13)
627 std r12,PACA_EXGEN+EX_R3(r13)
628 clrrdi r12,r13,32
629 mfmsr r10
630 mfspr r11,SRR0 /* save SRR0 */
631 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
632 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
633 mtspr SRR0,r12
634 mfspr r12,SRR1 /* and SRR1 */
635 mtspr SRR1,r10
636 rfid
637 b . /* prevent spec. execution */
638#endif /* __DISABLED__ */
639
640/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000641 * Vectors for the FWNMI option. Share common code.
642 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000643 .globl system_reset_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100644 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000645system_reset_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000646 HMT_MEDIUM
647 mtspr SPRN_SPRG1,r13 /* save r13 */
Olaf Hering9fc0a922006-07-19 10:34:05 +0200648 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000649
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000650 .globl machine_check_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100651 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000652machine_check_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000653 HMT_MEDIUM
654 mtspr SPRN_SPRG1,r13 /* save r13 */
Olaf Hering9fc0a922006-07-19 10:34:05 +0200655 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000656
657#ifdef CONFIG_PPC_ISERIES
658/*** ISeries-LPAR interrupt handlers ***/
659
660 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
661
662 .globl data_access_iSeries
663data_access_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000664 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000665BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000666 mtspr SPRN_SPRG2,r12
667 mfspr r13,SPRN_DAR
668 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000669 srdi r13,r13,60
670 rlwimi r13,r12,16,0x20
671 mfcr r12
672 cmpwi r13,0x2c
673 beq .do_stab_bolted_iSeries
674 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000675 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000676END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
677 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
678 EXCEPTION_PROLOG_ISERIES_2
679 b data_access_common
680
681.do_stab_bolted_iSeries:
682 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000683 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000684 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
685 EXCEPTION_PROLOG_ISERIES_2
686 b .do_stab_bolted
687
688 .globl data_access_slb_iSeries
689data_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000690 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100691 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000692 std r3,PACA_EXSLB+EX_R3(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000693 mfspr r3,SPRN_DAR
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100694 std r9,PACA_EXSLB+EX_R9(r13)
695 mfcr r9
696#ifdef __DISABLED__
697 cmpdi r3,0
698 bge slb_miss_user_iseries
699#endif
700 std r10,PACA_EXSLB+EX_R10(r13)
701 std r11,PACA_EXSLB+EX_R11(r13)
702 std r12,PACA_EXSLB+EX_R12(r13)
703 mfspr r10,SPRN_SPRG1
704 std r10,PACA_EXSLB+EX_R13(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100705 ld r12,PACALPPACAPTR(r13)
706 ld r12,LPPACASRR1(r12)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100707 b .slb_miss_realmode
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000708
709 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
710
711 .globl instruction_access_slb_iSeries
712instruction_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000713 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100714 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000715 std r3,PACA_EXSLB+EX_R3(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100716 ld r3,PACALPPACAPTR(r13)
717 ld r3,LPPACASRR0(r3) /* get SRR0 value */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100718 std r9,PACA_EXSLB+EX_R9(r13)
719 mfcr r9
720#ifdef __DISABLED__
721 cmpdi r3,0
722 bge .slb_miss_user_iseries
723#endif
724 std r10,PACA_EXSLB+EX_R10(r13)
725 std r11,PACA_EXSLB+EX_R11(r13)
726 std r12,PACA_EXSLB+EX_R12(r13)
727 mfspr r10,SPRN_SPRG1
728 std r10,PACA_EXSLB+EX_R13(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100729 ld r12,PACALPPACAPTR(r13)
730 ld r12,LPPACASRR1(r12)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100731 b .slb_miss_realmode
732
733#ifdef __DISABLED__
734slb_miss_user_iseries:
735 std r10,PACA_EXGEN+EX_R10(r13)
736 std r11,PACA_EXGEN+EX_R11(r13)
737 std r12,PACA_EXGEN+EX_R12(r13)
738 mfspr r10,SPRG1
739 ld r11,PACA_EXSLB+EX_R9(r13)
740 ld r12,PACA_EXSLB+EX_R3(r13)
741 std r10,PACA_EXGEN+EX_R13(r13)
742 std r11,PACA_EXGEN+EX_R9(r13)
743 std r12,PACA_EXGEN+EX_R3(r13)
744 EXCEPTION_PROLOG_ISERIES_2
745 b slb_miss_user_common
746#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000747
748 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
749 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
750 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
751 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
752 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
753 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
754 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
755
756 .globl system_call_iSeries
757system_call_iSeries:
758 mr r9,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000759 mfspr r13,SPRN_SPRG3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000760 EXCEPTION_PROLOG_ISERIES_2
761 b system_call_common
762
763 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
764 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
765 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
766
767 .globl system_reset_iSeries
768system_reset_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000769 mfspr r13,SPRN_SPRG3 /* Get paca address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000770 mfmsr r24
771 ori r24,r24,MSR_RI
772 mtmsrd r24 /* RI on */
773 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
774 cmpwi 0,r24,0 /* Are we processor 0? */
775 beq .__start_initialization_iSeries /* Start up the first processor */
776 mfspr r4,SPRN_CTRLF
777 li r5,CTRL_RUNLATCH /* Turn off the run light */
778 andc r4,r4,r5
779 mtspr SPRN_CTRLT,r4
780
7811:
782 HMT_LOW
783#ifdef CONFIG_SMP
784 lbz r23,PACAPROCSTART(r13) /* Test if this processor
785 * should start */
786 sync
David Gibsone58c3492006-01-13 14:56:25 +1100787 LOAD_REG_IMMEDIATE(r3,current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000788 sldi r28,r24,3 /* get current_set[cpu#] */
789 ldx r3,r3,r28
790 addi r1,r3,THREAD_SIZE
791 subi r1,r1,STACK_FRAME_OVERHEAD
792
793 cmpwi 0,r23,0
794 beq iSeries_secondary_smp_loop /* Loop until told to go */
795 bne .__secondary_start /* Loop until told to go */
796iSeries_secondary_smp_loop:
797 /* Let the Hypervisor know we are alive */
798 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
799 lis r3,0x8002
800 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
801#else /* CONFIG_SMP */
802 /* Yield the processor. This is required for non-SMP kernels
803 which are running on multi-threaded machines. */
804 lis r3,0x8000
805 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
806 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
807 li r4,0 /* "yield timed" */
808 li r5,-1 /* "yield forever" */
809#endif /* CONFIG_SMP */
810 li r0,-1 /* r0=-1 indicates a Hypervisor call */
811 sc /* Invoke the hypervisor via a system call */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000812 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000813 b 1b /* If SMP not configured, secondaries
814 * loop forever */
815
816 .globl decrementer_iSeries_masked
817decrementer_iSeries_masked:
Michael Ellermanf9b40452006-02-07 13:26:14 +1100818 /* We may not have a valid TOC pointer in here. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000819 li r11,1
David Gibson3356bb92006-01-13 10:26:42 +1100820 ld r12,PACALPPACAPTR(r13)
821 stb r11,LPPACADECRINT(r12)
Michael Ellermanf9b40452006-02-07 13:26:14 +1100822 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
823 lwz r12,0(r12)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000824 mtspr SPRN_DEC,r12
825 /* fall through */
826
827 .globl hardware_interrupt_iSeries_masked
828hardware_interrupt_iSeries_masked:
829 mtcrf 0x80,r9 /* Restore regs */
David Gibson3356bb92006-01-13 10:26:42 +1100830 ld r12,PACALPPACAPTR(r13)
831 ld r11,LPPACASRR0(r12)
832 ld r12,LPPACASRR1(r12)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000833 mtspr SPRN_SRR0,r11
834 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000835 ld r9,PACA_EXGEN+EX_R9(r13)
836 ld r10,PACA_EXGEN+EX_R10(r13)
837 ld r11,PACA_EXGEN+EX_R11(r13)
838 ld r12,PACA_EXGEN+EX_R12(r13)
839 ld r13,PACA_EXGEN+EX_R13(r13)
840 rfid
841 b . /* prevent speculative execution */
842#endif /* CONFIG_PPC_ISERIES */
843
844/*** Common interrupt handlers ***/
845
846 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
847
848 /*
849 * Machine check is different because we use a different
850 * save area: PACA_EXMC instead of PACA_EXGEN.
851 */
852 .align 7
853 .globl machine_check_common
854machine_check_common:
855 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000856 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000857 DISABLE_INTS
858 bl .save_nvgprs
859 addi r3,r1,STACK_FRAME_OVERHEAD
860 bl .machine_check_exception
861 b .ret_from_except
862
863 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
864 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
865 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
866 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
867 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000868 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000869 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
870#ifdef CONFIG_ALTIVEC
871 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
872#else
873 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
874#endif
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200875#ifdef CONFIG_CBE_RAS
876 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
877 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
878 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
879#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000880
881/*
882 * Here we have detected that the kernel stack pointer is bad.
883 * R9 contains the saved CR, r13 points to the paca,
884 * r10 contains the (bad) kernel stack pointer,
885 * r11 and r12 contain the saved SRR0 and SRR1.
886 * We switch to using an emergency stack, save the registers there,
887 * and call kernel_bad_stack(), which panics.
888 */
889bad_stack:
890 ld r1,PACAEMERGSP(r13)
891 subi r1,r1,64+INT_FRAME_SIZE
892 std r9,_CCR(r1)
893 std r10,GPR1(r1)
894 std r11,_NIP(r1)
895 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000896 mfspr r11,SPRN_DAR
897 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000898 std r11,_DAR(r1)
899 std r12,_DSISR(r1)
900 mflr r10
901 mfctr r11
902 mfxer r12
903 std r10,_LINK(r1)
904 std r11,_CTR(r1)
905 std r12,_XER(r1)
906 SAVE_GPR(0,r1)
907 SAVE_GPR(2,r1)
908 SAVE_4GPRS(3,r1)
909 SAVE_2GPRS(7,r1)
910 SAVE_10GPRS(12,r1)
911 SAVE_10GPRS(22,r1)
912 addi r11,r1,INT_FRAME_SIZE
913 std r11,0(r1)
914 li r12,0
915 std r12,0(r11)
916 ld r2,PACATOC(r13)
9171: addi r3,r1,STACK_FRAME_OVERHEAD
918 bl .kernel_bad_stack
919 b 1b
920
921/*
922 * Return from an exception with minimal checks.
923 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
924 * If interrupts have been enabled, or anything has been
925 * done that might have changed the scheduling status of
926 * any task or sent any task a signal, you should use
927 * ret_from_except or ret_from_except_lite instead of this.
928 */
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000929 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000930fast_exception_return:
931 ld r12,_MSR(r1)
932 ld r11,_NIP(r1)
933 andi. r3,r12,MSR_RI /* check if RI is set */
934 beq- unrecov_fer
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100935
936#ifdef CONFIG_VIRT_CPU_ACCOUNTING
937 andi. r3,r12,MSR_PR
938 beq 2f
939 ACCOUNT_CPU_USER_EXIT(r3, r4)
9402:
941#endif
942
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000943 ld r3,_CCR(r1)
944 ld r4,_LINK(r1)
945 ld r5,_CTR(r1)
946 ld r6,_XER(r1)
947 mtcr r3
948 mtlr r4
949 mtctr r5
950 mtxer r6
951 REST_GPR(0, r1)
952 REST_8GPRS(2, r1)
953
954 mfmsr r10
955 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
956 mtmsrd r10,1
957
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000958 mtspr SPRN_SRR1,r12
959 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000960 REST_4GPRS(10, r1)
961 ld r1,GPR1(r1)
962 rfid
963 b . /* prevent speculative execution */
964
965unrecov_fer:
966 bl .save_nvgprs
9671: addi r3,r1,STACK_FRAME_OVERHEAD
968 bl .unrecoverable_exception
969 b 1b
970
971/*
972 * Here r13 points to the paca, r9 contains the saved CR,
973 * SRR0 and SRR1 are saved in r11 and r12,
974 * r9 - r13 are saved in paca->exgen.
975 */
976 .align 7
977 .globl data_access_common
978data_access_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000979 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000980 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000981 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000982 stw r10,PACA_EXGEN+EX_DSISR(r13)
983 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
984 ld r3,PACA_EXGEN+EX_DAR(r13)
985 lwz r4,PACA_EXGEN+EX_DSISR(r13)
986 li r5,0x300
987 b .do_hash_page /* Try to handle as hpte fault */
988
989 .align 7
990 .globl instruction_access_common
991instruction_access_common:
992 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
993 ld r3,_NIP(r1)
994 andis. r4,r12,0x5820
995 li r5,0x400
996 b .do_hash_page /* Try to handle as hpte fault */
997
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100998/*
999 * Here is the common SLB miss user that is used when going to virtual
1000 * mode for SLB misses, that is currently not used
1001 */
1002#ifdef __DISABLED__
1003 .align 7
1004 .globl slb_miss_user_common
1005slb_miss_user_common:
1006 mflr r10
1007 std r3,PACA_EXGEN+EX_DAR(r13)
1008 stw r9,PACA_EXGEN+EX_CCR(r13)
1009 std r10,PACA_EXGEN+EX_LR(r13)
1010 std r11,PACA_EXGEN+EX_SRR0(r13)
1011 bl .slb_allocate_user
1012
1013 ld r10,PACA_EXGEN+EX_LR(r13)
1014 ld r3,PACA_EXGEN+EX_R3(r13)
1015 lwz r9,PACA_EXGEN+EX_CCR(r13)
1016 ld r11,PACA_EXGEN+EX_SRR0(r13)
1017 mtlr r10
1018 beq- slb_miss_fault
1019
1020 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1021 beq- unrecov_user_slb
1022 mfmsr r10
1023
1024.machine push
1025.machine "power4"
1026 mtcrf 0x80,r9
1027.machine pop
1028
1029 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1030 mtmsrd r10,1
1031
1032 mtspr SRR0,r11
1033 mtspr SRR1,r12
1034
1035 ld r9,PACA_EXGEN+EX_R9(r13)
1036 ld r10,PACA_EXGEN+EX_R10(r13)
1037 ld r11,PACA_EXGEN+EX_R11(r13)
1038 ld r12,PACA_EXGEN+EX_R12(r13)
1039 ld r13,PACA_EXGEN+EX_R13(r13)
1040 rfid
1041 b .
1042
1043slb_miss_fault:
1044 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1045 ld r4,PACA_EXGEN+EX_DAR(r13)
1046 li r5,0
1047 std r4,_DAR(r1)
1048 std r5,_DSISR(r1)
1049 b .handle_page_fault
1050
1051unrecov_user_slb:
1052 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1053 DISABLE_INTS
1054 bl .save_nvgprs
10551: addi r3,r1,STACK_FRAME_OVERHEAD
1056 bl .unrecoverable_exception
1057 b 1b
1058
1059#endif /* __DISABLED__ */
1060
1061
1062/*
1063 * r13 points to the PACA, r9 contains the saved CR,
1064 * r12 contain the saved SRR1, SRR0 is still ready for return
1065 * r3 has the faulting address
1066 * r9 - r13 are saved in paca->exslb.
1067 * r3 is saved in paca->slb_r3
1068 * We assume we aren't going to take any exceptions during this procedure.
1069 */
1070_GLOBAL(slb_miss_realmode)
1071 mflr r10
1072
1073 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1074 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1075
1076 bl .slb_allocate_realmode
1077
1078 /* All done -- return from exception. */
1079
1080 ld r10,PACA_EXSLB+EX_LR(r13)
1081 ld r3,PACA_EXSLB+EX_R3(r13)
1082 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1083#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001084BEGIN_FW_FTR_SECTION
David Gibson3356bb92006-01-13 10:26:42 +11001085 ld r11,PACALPPACAPTR(r13)
1086 ld r11,LPPACASRR0(r11) /* get SRR0 value */
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001087END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +11001088#endif /* CONFIG_PPC_ISERIES */
1089
1090 mtlr r10
1091
1092 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1093 beq- unrecov_slb
1094
1095.machine push
1096.machine "power4"
1097 mtcrf 0x80,r9
1098 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1099.machine pop
1100
1101#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001102BEGIN_FW_FTR_SECTION
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +11001103 mtspr SPRN_SRR0,r11
1104 mtspr SPRN_SRR1,r12
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001105END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +11001106#endif /* CONFIG_PPC_ISERIES */
1107 ld r9,PACA_EXSLB+EX_R9(r13)
1108 ld r10,PACA_EXSLB+EX_R10(r13)
1109 ld r11,PACA_EXSLB+EX_R11(r13)
1110 ld r12,PACA_EXSLB+EX_R12(r13)
1111 ld r13,PACA_EXSLB+EX_R13(r13)
1112 rfid
1113 b . /* prevent speculative execution */
1114
1115unrecov_slb:
1116 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1117 DISABLE_INTS
1118 bl .save_nvgprs
11191: addi r3,r1,STACK_FRAME_OVERHEAD
1120 bl .unrecoverable_exception
1121 b 1b
1122
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001123 .align 7
1124 .globl hardware_interrupt_common
1125 .globl hardware_interrupt_entry
1126hardware_interrupt_common:
1127 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
Paul Mackerrasf39224a2006-04-18 21:49:11 +10001128 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001129hardware_interrupt_entry:
1130 DISABLE_INTS
Anton Blanchardcb2c9b22006-02-13 14:48:35 +11001131 bl .ppc64_runlatch_on
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001132 addi r3,r1,STACK_FRAME_OVERHEAD
1133 bl .do_IRQ
1134 b .ret_from_except_lite
1135
Paul Mackerrasf39224a2006-04-18 21:49:11 +10001136#ifdef CONFIG_PPC_970_NAP
1137power4_fixup_nap:
1138 andc r9,r9,r10
1139 std r9,TI_LOCAL_FLAGS(r11)
1140 ld r10,_LINK(r1) /* make idle task do the */
1141 std r10,_NIP(r1) /* equivalent of a blr */
1142 blr
1143#endif
1144
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001145 .align 7
1146 .globl alignment_common
1147alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001148 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001149 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001150 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001151 stw r10,PACA_EXGEN+EX_DSISR(r13)
1152 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1153 ld r3,PACA_EXGEN+EX_DAR(r13)
1154 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1155 std r3,_DAR(r1)
1156 std r4,_DSISR(r1)
1157 bl .save_nvgprs
1158 addi r3,r1,STACK_FRAME_OVERHEAD
1159 ENABLE_INTS
1160 bl .alignment_exception
1161 b .ret_from_except
1162
1163 .align 7
1164 .globl program_check_common
1165program_check_common:
1166 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1167 bl .save_nvgprs
1168 addi r3,r1,STACK_FRAME_OVERHEAD
1169 ENABLE_INTS
1170 bl .program_check_exception
1171 b .ret_from_except
1172
1173 .align 7
1174 .globl fp_unavailable_common
1175fp_unavailable_common:
1176 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1177 bne .load_up_fpu /* if from user, just load it up */
1178 bl .save_nvgprs
1179 addi r3,r1,STACK_FRAME_OVERHEAD
1180 ENABLE_INTS
1181 bl .kernel_fp_unavailable_exception
1182 BUG_OPCODE
1183
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001184 .align 7
1185 .globl altivec_unavailable_common
1186altivec_unavailable_common:
1187 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1188#ifdef CONFIG_ALTIVEC
1189BEGIN_FTR_SECTION
1190 bne .load_up_altivec /* if from user, just load it up */
1191END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1192#endif
1193 bl .save_nvgprs
1194 addi r3,r1,STACK_FRAME_OVERHEAD
1195 ENABLE_INTS
1196 bl .altivec_unavailable_exception
1197 b .ret_from_except
1198
1199#ifdef CONFIG_ALTIVEC
1200/*
1201 * load_up_altivec(unused, unused, tsk)
1202 * Disable VMX for the task which had it previously,
1203 * and save its vector registers in its thread_struct.
1204 * Enables the VMX for use in the kernel on return.
1205 * On SMP we know the VMX is free, since we give it up every
1206 * switch (ie, no lazy save of the vector registers).
1207 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1208 */
1209_STATIC(load_up_altivec)
1210 mfmsr r5 /* grab the current MSR */
1211 oris r5,r5,MSR_VEC@h
1212 mtmsrd r5 /* enable use of VMX now */
1213 isync
1214
1215/*
1216 * For SMP, we don't do lazy VMX switching because it just gets too
1217 * horrendously complex, especially when a task switches from one CPU
1218 * to another. Instead we call giveup_altvec in switch_to.
1219 * VRSAVE isn't dealt with here, that is done in the normal context
1220 * switch code. Note that we could rely on vrsave value to eventually
1221 * avoid saving all of the VREGs here...
1222 */
1223#ifndef CONFIG_SMP
1224 ld r3,last_task_used_altivec@got(r2)
1225 ld r4,0(r3)
1226 cmpdi 0,r4,0
1227 beq 1f
1228 /* Save VMX state to last_task_used_altivec's THREAD struct */
1229 addi r4,r4,THREAD
1230 SAVE_32VRS(0,r5,r4)
1231 mfvscr vr0
1232 li r10,THREAD_VSCR
1233 stvx vr0,r10,r4
1234 /* Disable VMX for last_task_used_altivec */
1235 ld r5,PT_REGS(r4)
1236 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1237 lis r6,MSR_VEC@h
1238 andc r4,r4,r6
1239 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
12401:
1241#endif /* CONFIG_SMP */
1242 /* Hack: if we get an altivec unavailable trap with VRSAVE
1243 * set to all zeros, we assume this is a broken application
1244 * that fails to set it properly, and thus we switch it to
1245 * all 1's
1246 */
1247 mfspr r4,SPRN_VRSAVE
1248 cmpdi 0,r4,0
1249 bne+ 1f
1250 li r4,-1
1251 mtspr SPRN_VRSAVE,r4
12521:
1253 /* enable use of VMX after return */
1254 ld r4,PACACURRENT(r13)
1255 addi r5,r4,THREAD /* Get THREAD */
1256 oris r12,r12,MSR_VEC@h
1257 std r12,_MSR(r1)
1258 li r4,1
1259 li r10,THREAD_VSCR
1260 stw r4,THREAD_USED_VR(r5)
1261 lvx vr0,r10,r5
1262 mtvscr vr0
1263 REST_32VRS(0,r4,r5)
1264#ifndef CONFIG_SMP
1265 /* Update last_task_used_math to 'current' */
1266 subi r4,r5,THREAD /* Back to 'current' */
1267 std r4,0(r3)
1268#endif /* CONFIG_SMP */
1269 /* restore registers and return */
1270 b fast_exception_return
1271#endif /* CONFIG_ALTIVEC */
1272
1273/*
1274 * Hash table stuff
1275 */
1276 .align 7
1277_GLOBAL(do_hash_page)
1278 std r3,_DAR(r1)
1279 std r4,_DSISR(r1)
1280
1281 andis. r0,r4,0xa450 /* weird error? */
1282 bne- .handle_page_fault /* if not, try to insert a HPTE */
1283BEGIN_FTR_SECTION
1284 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1285 bne- .do_ste_alloc /* If so handle it */
1286END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1287
1288 /*
1289 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1290 * accessing a userspace segment (even from the kernel). We assume
1291 * kernel addresses always have the high bit set.
1292 */
1293 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1294 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1295 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1296 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1297 ori r4,r4,1 /* add _PAGE_PRESENT */
1298 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1299
1300 /*
1301 * On iSeries, we soft-disable interrupts here, then
1302 * hard-enable interrupts so that the hash_page code can spin on
1303 * the hash_table_lock without problems on a shared processor.
1304 */
1305 DISABLE_INTS
1306
1307 /*
1308 * r3 contains the faulting address
1309 * r4 contains the required access permissions
1310 * r5 contains the trap number
1311 *
1312 * at return r3 = 0 for success
1313 */
1314 bl .hash_page /* build HPTE if possible */
1315 cmpdi r3,0 /* see if hash_page succeeded */
1316
1317#ifdef DO_SOFT_DISABLE
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001318BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001319 /*
1320 * If we had interrupts soft-enabled at the point where the
1321 * DSI/ISI occurred, and an interrupt came in during hash_page,
1322 * handle it now.
1323 * We jump to ret_from_except_lite rather than fast_exception_return
1324 * because ret_from_except_lite will check for and handle pending
1325 * interrupts if necessary.
1326 */
1327 beq .ret_from_except_lite
1328 /* For a hash failure, we don't bother re-enabling interrupts */
1329 ble- 12f
1330
1331 /*
1332 * hash_page couldn't handle it, set soft interrupt enable back
1333 * to what it was before the trap. Note that .local_irq_restore
1334 * handles any interrupts pending at this point.
1335 */
1336 ld r3,SOFTE(r1)
1337 bl .local_irq_restore
1338 b 11f
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001339END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1340#endif
1341BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001342 beq fast_exception_return /* Return from exception on success */
1343 ble- 12f /* Failure return from hash_page */
1344
1345 /* fall through */
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001346END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001347
1348/* Here we have a page fault that hash_page can't handle. */
1349_GLOBAL(handle_page_fault)
1350 ENABLE_INTS
135111: ld r4,_DAR(r1)
1352 ld r5,_DSISR(r1)
1353 addi r3,r1,STACK_FRAME_OVERHEAD
1354 bl .do_page_fault
1355 cmpdi r3,0
1356 beq+ .ret_from_except_lite
1357 bl .save_nvgprs
1358 mr r5,r3
1359 addi r3,r1,STACK_FRAME_OVERHEAD
1360 lwz r4,_DAR(r1)
1361 bl .bad_page_fault
1362 b .ret_from_except
1363
1364/* We have a page fault that hash_page could handle but HV refused
1365 * the PTE insertion
1366 */
136712: bl .save_nvgprs
1368 addi r3,r1,STACK_FRAME_OVERHEAD
1369 lwz r4,_DAR(r1)
1370 bl .low_hash_fault
1371 b .ret_from_except
1372
1373 /* here we have a segment miss */
1374_GLOBAL(do_ste_alloc)
1375 bl .ste_allocate /* try to insert stab entry */
1376 cmpdi r3,0
1377 beq+ fast_exception_return
1378 b .handle_page_fault
1379
1380/*
1381 * r13 points to the PACA, r9 contains the saved CR,
1382 * r11 and r12 contain the saved SRR0 and SRR1.
1383 * r9 - r13 are saved in paca->exslb.
1384 * We assume we aren't going to take any exceptions during this procedure.
1385 * We assume (DAR >> 60) == 0xc.
1386 */
1387 .align 7
1388_GLOBAL(do_stab_bolted)
1389 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1390 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1391
1392 /* Hash to the primary group */
1393 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001394 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001395 srdi r11,r11,28
1396 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1397
1398 /* Calculate VSID */
1399 /* This is a kernel address, so protovsid = ESID */
1400 ASM_VSID_SCRAMBLE(r11, r9)
1401 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1402
1403 /* Search the primary group for a free entry */
14041: ld r11,0(r10) /* Test valid bit of the current ste */
1405 andi. r11,r11,0x80
1406 beq 2f
1407 addi r10,r10,16
1408 andi. r11,r10,0x70
1409 bne 1b
1410
1411 /* Stick for only searching the primary group for now. */
1412 /* At least for now, we use a very simple random castout scheme */
1413 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1414 mftb r11
1415 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1416 ori r11,r11,0x10
1417
1418 /* r10 currently points to an ste one past the group of interest */
1419 /* make it point to the randomly selected entry */
1420 subi r10,r10,128
1421 or r10,r10,r11 /* r10 is the entry to invalidate */
1422
1423 isync /* mark the entry invalid */
1424 ld r11,0(r10)
1425 rldicl r11,r11,56,1 /* clear the valid bit */
1426 rotldi r11,r11,8
1427 std r11,0(r10)
1428 sync
1429
1430 clrrdi r11,r11,28 /* Get the esid part of the ste */
1431 slbie r11
1432
14332: std r9,8(r10) /* Store the vsid part of the ste */
1434 eieio
1435
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001436 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001437 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1438 ori r11,r11,0x90 /* Turn on valid and kp */
1439 std r11,0(r10) /* Put new entry back into the stab */
1440
1441 sync
1442
1443 /* All done -- return from exception. */
1444 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1445 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1446
1447 andi. r10,r12,MSR_RI
1448 beq- unrecov_slb
1449
1450 mtcrf 0x80,r9 /* restore CR */
1451
1452 mfmsr r10
1453 clrrdi r10,r10,2
1454 mtmsrd r10,1
1455
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001456 mtspr SPRN_SRR0,r11
1457 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001458 ld r9,PACA_EXSLB+EX_R9(r13)
1459 ld r10,PACA_EXSLB+EX_R10(r13)
1460 ld r11,PACA_EXSLB+EX_R11(r13)
1461 ld r12,PACA_EXSLB+EX_R12(r13)
1462 ld r13,PACA_EXSLB+EX_R13(r13)
1463 rfid
1464 b . /* prevent speculative execution */
1465
1466/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001467 * Space for CPU0's segment table.
1468 *
1469 * On iSeries, the hypervisor must fill in at least one entry before
1470 * we get control (with relocate on). The address is give to the hv
Stephen Rothwellee400b62005-09-29 11:50:22 +10001471 * as a page number (see xLparMap in lpardata.c), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001472 * fixed address (the linker can't compute (u64)&initial_stab >>
1473 * PAGE_SHIFT).
1474 */
Michael Ellerman758438a2005-12-05 15:49:00 -06001475 . = STAB0_OFFSET /* 0x6000 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001476 .globl initial_stab
1477initial_stab:
1478 .space 4096
1479
1480/*
1481 * Data area reserved for FWNMI option.
1482 * This address (0x7000) is fixed by the RPA.
1483 */
1484 .= 0x7000
1485 .globl fwnmi_data_area
1486fwnmi_data_area:
1487
1488 /* iSeries does not use the FWNMI stuff, so it is safe to put
1489 * this here, even if we later allow kernels that will boot on
1490 * both pSeries and iSeries */
1491#ifdef CONFIG_PPC_ISERIES
1492 . = LPARMAP_PHYS
1493#include "lparmap.s"
1494/*
1495 * This ".text" is here for old compilers that generate a trailing
1496 * .note section when compiling .c files to .s
1497 */
1498 .text
1499#endif /* CONFIG_PPC_ISERIES */
1500
1501 . = 0x8000
1502
1503/*
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001504 * On pSeries and most other platforms, secondary processors spin
1505 * in the following code.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001506 * At entry, r3 = this processor's number (physical cpu id)
1507 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001508_GLOBAL(generic_secondary_smp_init)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001509 mr r24,r3
1510
1511 /* turn on 64-bit mode */
1512 bl .enable_64b_mode
1513 isync
1514
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001515 /* Set up a paca value for this processor. Since we have the
1516 * physical cpu id in r24, we need to search the pacas to find
1517 * which logical id maps to our physical one.
1518 */
David Gibsone58c3492006-01-13 14:56:25 +11001519 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001520 li r5,0 /* logical cpu id */
15211: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1522 cmpw r6,r24 /* Compare to our id */
1523 beq 2f
1524 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1525 addi r5,r5,1
1526 cmpwi r5,NR_CPUS
1527 blt 1b
1528
1529 mr r3,r24 /* not found, copy phys to r3 */
1530 b .kexec_wait /* next kernel might do better */
1531
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100015322: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001533 /* From now on, r24 is expected to be logical cpuid */
1534 mr r24,r5
15353: HMT_LOW
1536 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1537 /* start. */
1538 sync
1539
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001540#ifndef CONFIG_SMP
1541 b 3b /* Never go on non-SMP */
1542#else
1543 cmpwi 0,r23,0
1544 beq 3b /* Loop until told to go */
1545
1546 /* See if we need to call a cpu state restore handler */
1547 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1548 ld r23,0(r23)
1549 ld r23,CPU_SPEC_RESTORE(r23)
1550 cmpdi 0,r23,0
1551 beq 4f
1552 ld r23,0(r23)
1553 mtctr r23
1554 bctrl
1555
15564: /* Create a temp kernel stack for use before relocation is on. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001557 ld r1,PACAEMERGSP(r13)
1558 subi r1,r1,STACK_FRAME_OVERHEAD
1559
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001560 b .__secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001561#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001562
1563#ifdef CONFIG_PPC_ISERIES
1564_STATIC(__start_initialization_iSeries)
1565 /* Clear out the BSS */
David Gibsone58c3492006-01-13 14:56:25 +11001566 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1567 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001568 sub r11,r11,r8 /* bss size */
1569 addi r11,r11,7 /* round up to an even double word */
1570 rldicl. r11,r11,61,3 /* shift right by 3 */
1571 beq 4f
1572 addi r8,r8,-8
1573 li r0,0
1574 mtctr r11 /* zero this many doublewords */
15753: stdu r0,8(r8)
1576 bdnz 3b
15774:
David Gibsone58c3492006-01-13 14:56:25 +11001578 LOAD_REG_IMMEDIATE(r1,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001579 addi r1,r1,THREAD_SIZE
1580 li r0,0
1581 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1582
David Gibsone58c3492006-01-13 14:56:25 +11001583 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001584 addi r2,r2,0x4000
1585 addi r2,r2,0x4000
1586
1587 bl .iSeries_early_setup
Stephen Rothwellee400b62005-09-29 11:50:22 +10001588 bl .early_setup
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001589
1590 /* relocation is on at this point */
1591
1592 b .start_here_common
1593#endif /* CONFIG_PPC_ISERIES */
1594
1595#ifdef CONFIG_PPC_MULTIPLATFORM
1596
1597_STATIC(__mmu_off)
1598 mfmsr r3
1599 andi. r0,r3,MSR_IR|MSR_DR
1600 beqlr
1601 andc r3,r3,r0
1602 mtspr SPRN_SRR0,r4
1603 mtspr SPRN_SRR1,r3
1604 sync
1605 rfid
1606 b . /* prevent speculative execution */
1607
1608
1609/*
1610 * Here is our main kernel entry point. We support currently 2 kind of entries
1611 * depending on the value of r5.
1612 *
1613 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1614 * in r3...r7
1615 *
1616 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1617 * DT block, r4 is a physical pointer to the kernel itself
1618 *
1619 */
1620_GLOBAL(__start_initialization_multiplatform)
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001621#ifdef CONFIG_PPC_MULTIPLATFORM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001622 /*
1623 * Are we booted from a PROM Of-type client-interface ?
1624 */
1625 cmpldi cr0,r5,0
1626 bne .__boot_from_prom /* yes -> prom */
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001627#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001628
1629 /* Save parameters */
1630 mr r31,r3
1631 mr r30,r4
1632
1633 /* Make sure we are running in 64 bits mode */
1634 bl .enable_64b_mode
1635
1636 /* Setup some critical 970 SPRs before switching MMU off */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001637 mfspr r0,SPRN_PVR
1638 srwi r0,r0,16
1639 cmpwi r0,0x39 /* 970 */
1640 beq 1f
1641 cmpwi r0,0x3c /* 970FX */
1642 beq 1f
1643 cmpwi r0,0x44 /* 970MP */
Olof Johansson190a24f2006-10-25 17:32:40 -05001644 beq 1f
1645 cmpwi r0,0x45 /* 970GX */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001646 bne 2f
16471: bl .__cpu_preinit_ppc970
16482:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001649
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001650 /* Switch off MMU if not already */
David Gibsone58c3492006-01-13 14:56:25 +11001651 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001652 add r4,r4,r30
1653 bl .__mmu_off
1654 b .__after_prom_start
1655
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001656#ifdef CONFIG_PPC_MULTIPLATFORM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001657_STATIC(__boot_from_prom)
1658 /* Save parameters */
1659 mr r31,r3
1660 mr r30,r4
1661 mr r29,r5
1662 mr r28,r6
1663 mr r27,r7
1664
Olaf Hering60888572006-03-23 21:50:59 +01001665 /*
1666 * Align the stack to 16-byte boundary
1667 * Depending on the size and layout of the ELF sections in the initial
1668 * boot binary, the stack pointer will be unalignet on PowerMac
1669 */
Linus Torvaldsc05b4772006-03-04 15:00:45 -08001670 rldicr r1,r1,0,59
1671
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001672 /* Make sure we are running in 64 bits mode */
1673 bl .enable_64b_mode
1674
1675 /* put a relocation offset into r3 */
1676 bl .reloc_offset
1677
David Gibsone58c3492006-01-13 14:56:25 +11001678 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001679 addi r2,r2,0x4000
1680 addi r2,r2,0x4000
1681
1682 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001683 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001684
1685 /* Restore parameters */
1686 mr r3,r31
1687 mr r4,r30
1688 mr r5,r29
1689 mr r6,r28
1690 mr r7,r27
1691
1692 /* Do all of the interaction with OF client interface */
1693 bl .prom_init
1694 /* We never return */
1695 trap
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001696#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001697
1698/*
1699 * At this point, r3 contains the physical address we are running at,
1700 * returned by prom_init()
1701 */
1702_STATIC(__after_prom_start)
1703
1704/*
Michael Ellerman758438a2005-12-05 15:49:00 -06001705 * We need to run with __start at physical address PHYSICAL_START.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001706 * This will leave some code in the first 256B of
1707 * real memory, which are reserved for software use.
1708 * The remainder of the first page is loaded with the fixed
1709 * interrupt vectors. The next two pages are filled with
1710 * unknown exception placeholders.
1711 *
1712 * Note: This process overwrites the OF exception vectors.
1713 * r26 == relocation offset
1714 * r27 == KERNELBASE
1715 */
1716 bl .reloc_offset
1717 mr r26,r3
David Gibsone58c3492006-01-13 14:56:25 +11001718 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001719
David Gibsone58c3492006-01-13 14:56:25 +11001720 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001721
1722 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001723 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001724 /* current address of _start */
1725 /* i.e. where we are running */
1726 /* the source addr */
1727
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001728 cmpdi r4,0 /* In some cases the loader may */
1729 beq .start_here_multiplatform /* have already put us at zero */
1730 /* so we can skip the copy. */
David Gibsone58c3492006-01-13 14:56:25 +11001731 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001732 sub r5,r5,r27
1733
1734 li r6,0x100 /* Start offset, the first 0x100 */
1735 /* bytes were copied earlier. */
1736
1737 bl .copy_and_flush /* copy the first n bytes */
1738 /* this includes the code being */
1739 /* executed here. */
1740
David Gibsone58c3492006-01-13 14:56:25 +11001741 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001742 mtctr r0 /* that we just made/relocated */
1743 bctr
1744
David Gibsone58c3492006-01-13 14:56:25 +110017454: LOAD_REG_IMMEDIATE(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001746 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001747 ld r5,0(r5) /* get the value of klimit */
1748 sub r5,r5,r27
1749 bl .copy_and_flush /* copy the rest */
1750 b .start_here_multiplatform
1751
1752#endif /* CONFIG_PPC_MULTIPLATFORM */
1753
1754/*
1755 * Copy routine used to copy the kernel to start at physical address 0
1756 * and flush and invalidate the caches as needed.
1757 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1758 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1759 *
1760 * Note: this routine *only* clobbers r0, r6 and lr
1761 */
1762_GLOBAL(copy_and_flush)
1763 addi r5,r5,-8
1764 addi r6,r6,-8
Olof Johansson5a2fe382006-09-06 14:34:41 -050017654: li r0,8 /* Use the smallest common */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001766 /* denominator cache line */
1767 /* size. This results in */
1768 /* extra cache line flushes */
1769 /* but operation is correct. */
1770 /* Can't get cache line size */
1771 /* from NACA as it is being */
1772 /* moved too. */
1773
1774 mtctr r0 /* put # words/line in ctr */
17753: addi r6,r6,8 /* copy a cache line */
1776 ldx r0,r6,r4
1777 stdx r0,r6,r3
1778 bdnz 3b
1779 dcbst r6,r3 /* write it to memory */
1780 sync
1781 icbi r6,r3 /* flush the icache line */
1782 cmpld 0,r6,r5
1783 blt 4b
1784 sync
1785 addi r5,r5,8
1786 addi r6,r6,8
1787 blr
1788
1789.align 8
1790copy_to_here:
1791
1792#ifdef CONFIG_SMP
1793#ifdef CONFIG_PPC_PMAC
1794/*
1795 * On PowerMac, secondary processors starts from the reset vector, which
1796 * is temporarily turned into a call to one of the functions below.
1797 */
1798 .section ".text";
1799 .align 2 ;
1800
Paul Mackerras35499c02005-10-22 16:02:39 +10001801 .globl __secondary_start_pmac_0
1802__secondary_start_pmac_0:
1803 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1804 li r24,0
1805 b 1f
1806 li r24,1
1807 b 1f
1808 li r24,2
1809 b 1f
1810 li r24,3
18111:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001812
1813_GLOBAL(pmac_secondary_start)
1814 /* turn on 64-bit mode */
1815 bl .enable_64b_mode
1816 isync
1817
1818 /* Copy some CPU settings from CPU 0 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001819 bl .__restore_cpu_ppc970
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001820
1821 /* pSeries do that early though I don't think we really need it */
1822 mfmsr r3
1823 ori r3,r3,MSR_RI
1824 mtmsrd r3 /* RI on */
1825
1826 /* Set up a paca value for this processor. */
David Gibsone58c3492006-01-13 14:56:25 +11001827 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001828 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1829 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001830 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001831
1832 /* Create a temp kernel stack for use before relocation is on. */
1833 ld r1,PACAEMERGSP(r13)
1834 subi r1,r1,STACK_FRAME_OVERHEAD
1835
1836 b .__secondary_start
1837
1838#endif /* CONFIG_PPC_PMAC */
1839
1840/*
1841 * This function is called after the master CPU has released the
1842 * secondary processors. The execution environment is relocation off.
1843 * The paca for this processor has the following fields initialized at
1844 * this point:
1845 * 1. Processor number
1846 * 2. Segment table pointer (virtual address)
1847 * On entry the following are set:
1848 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1849 * r24 = cpu# (in Linux terms)
1850 * r13 = paca virtual address
1851 * SPRG3 = paca virtual address
1852 */
1853_GLOBAL(__secondary_start)
Paul Mackerras799d6042005-11-10 13:37:51 +11001854 /* Set thread priority to MEDIUM */
1855 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001856
Paul Mackerras799d6042005-11-10 13:37:51 +11001857 /* Load TOC */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001858 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001859
Paul Mackerras799d6042005-11-10 13:37:51 +11001860 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1861 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001862
1863 /* Initialize the kernel stack. Just a repeat for iSeries. */
David Gibsone58c3492006-01-13 14:56:25 +11001864 LOAD_REG_ADDR(r3, current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001865 sldi r28,r24,3 /* get current_set[cpu#] */
1866 ldx r1,r3,r28
1867 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1868 std r1,PACAKSAVE(r13)
1869
Paul Mackerras799d6042005-11-10 13:37:51 +11001870 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001871 li r7,0
1872 mtlr r7
1873
1874 /* enable MMU and jump to start_secondary */
David Gibsone58c3492006-01-13 14:56:25 +11001875 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1876 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001877#ifdef DO_SOFT_DISABLE
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001878BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001879 ori r4,r4,MSR_EE
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001880END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001881#endif
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001882 mtspr SPRN_SRR0,r3
1883 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001884 rfid
1885 b . /* prevent speculative execution */
1886
1887/*
1888 * Running with relocation on at this point. All we want to do is
1889 * zero the stack back-chain pointer before going into C code.
1890 */
1891_GLOBAL(start_secondary_prolog)
1892 li r3,0
1893 std r3,0(r1) /* Zero the stack frame pointer */
1894 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001895 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001896#endif
1897
1898/*
1899 * This subroutine clobbers r11 and r12
1900 */
1901_GLOBAL(enable_64b_mode)
1902 mfmsr r11 /* grab the current MSR */
1903 li r12,1
1904 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1905 or r11,r11,r12
1906 li r12,1
1907 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1908 or r11,r11,r12
1909 mtmsrd r11
1910 isync
1911 blr
1912
1913#ifdef CONFIG_PPC_MULTIPLATFORM
1914/*
1915 * This is where the main kernel code starts.
1916 */
1917_STATIC(start_here_multiplatform)
1918 /* get a new offset, now that the kernel has moved. */
1919 bl .reloc_offset
1920 mr r26,r3
1921
1922 /* Clear out the BSS. It may have been done in prom_init,
1923 * already but that's irrelevant since prom_init will soon
1924 * be detached from the kernel completely. Besides, we need
1925 * to clear it now for kexec-style entry.
1926 */
David Gibsone58c3492006-01-13 14:56:25 +11001927 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1928 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001929 sub r11,r11,r8 /* bss size */
1930 addi r11,r11,7 /* round up to an even double word */
1931 rldicl. r11,r11,61,3 /* shift right by 3 */
1932 beq 4f
1933 addi r8,r8,-8
1934 li r0,0
1935 mtctr r11 /* zero this many doublewords */
19363: stdu r0,8(r8)
1937 bdnz 3b
19384:
1939
1940 mfmsr r6
1941 ori r6,r6,MSR_RI
1942 mtmsrd r6 /* RI on */
1943
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001944 /* The following gets the stack and TOC set up with the regs */
1945 /* pointing to the real addr of the kernel stack. This is */
1946 /* all done to support the C function call below which sets */
1947 /* up the htab. This is done because we have relocated the */
1948 /* kernel but are still running in real mode. */
1949
David Gibsone58c3492006-01-13 14:56:25 +11001950 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001951 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001952
1953 /* set up a stack pointer (physical address) */
1954 addi r1,r3,THREAD_SIZE
1955 li r0,0
1956 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1957
1958 /* set up the TOC (physical address) */
David Gibsone58c3492006-01-13 14:56:25 +11001959 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001960 addi r2,r2,0x4000
1961 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001962 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001963
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001964 /* Do very early kernel initializations, including initial hash table,
1965 * stab and slb setup before we turn on relocation. */
1966
1967 /* Restore parameters passed from prom_init/kexec */
1968 mr r3,r31
1969 bl .early_setup
1970
David Gibsone58c3492006-01-13 14:56:25 +11001971 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1972 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001973 mtspr SPRN_SRR0,r3
1974 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001975 rfid
1976 b . /* prevent speculative execution */
1977#endif /* CONFIG_PPC_MULTIPLATFORM */
1978
1979 /* This is where all platforms converge execution */
1980_STATIC(start_here_common)
1981 /* relocation is on at this point */
1982
1983 /* The following code sets up the SP and TOC now that we are */
1984 /* running with translation enabled. */
1985
David Gibsone58c3492006-01-13 14:56:25 +11001986 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001987
1988 /* set up the stack */
1989 addi r1,r3,THREAD_SIZE
1990 li r0,0
1991 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1992
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001993 /* ptr to current */
David Gibsone58c3492006-01-13 14:56:25 +11001994 LOAD_REG_IMMEDIATE(r4, init_task)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001995 std r4,PACACURRENT(r13)
1996
1997 /* Load the TOC */
1998 ld r2,PACATOC(r13)
1999 std r1,PACAKSAVE(r13)
2000
2001 bl .setup_system
2002
2003 /* Load up the kernel context */
20045:
2005#ifdef DO_SOFT_DISABLE
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10002006BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002007 li r5,0
2008 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
2009 mfmsr r5
2010 ori r5,r5,MSR_EE /* Hard Enabled */
2011 mtmsrd r5
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10002012END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002013#endif
2014
2015 bl .start_kernel
2016
Anton Blanchardf1870f72006-02-13 18:11:13 +11002017 /* Not reached */
2018 BUG_OPCODE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002019
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002020/*
2021 * We put a few things here that have to be page-aligned.
2022 * This stuff goes at the beginning of the bss, which is page-aligned.
2023 */
2024 .section ".bss"
2025
2026 .align PAGE_SHIFT
2027
2028 .globl empty_zero_page
2029empty_zero_page:
2030 .space PAGE_SIZE
2031
2032 .globl swapper_pg_dir
2033swapper_pg_dir:
2034 .space PAGE_SIZE
2035
2036/*
2037 * This space gets a copy of optional info passed to us by the bootstrap
2038 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2039 */
2040 .globl cmd_line
2041cmd_line:
2042 .space COMMAND_LINE_SIZE