blob: f2fab687a01c52b7014d6a951032b24733ef7527 [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
24#include <linux/config.h>
25#include <linux/threads.h>
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100026#include <asm/reg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100027#include <asm/page.h>
28#include <asm/mmu.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100029#include <asm/ppc_asm.h>
30#include <asm/asm-offsets.h>
31#include <asm/bug.h>
32#include <asm/cputable.h>
33#include <asm/setup.h>
34#include <asm/hvcall.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110035#include <asm/iseries/lpar_map.h>
David Gibson6cb7bfe2005-10-21 15:45:50 +100036#include <asm/thread_info.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)
David Gibsone58c3492006-01-13 14:56:25 +1100136 LOAD_REG_IMMEDIATE(r4, .pSeries_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
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000195#define EXCEPTION_PROLOG_PSERIES(area, label) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000196 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000197 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
198 std r10,area+EX_R10(r13); \
199 std r11,area+EX_R11(r13); \
200 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000201 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000202 std r9,area+EX_R13(r13); \
203 mfcr r9; \
204 clrrdi r12,r13,32; /* get high part of &label */ \
205 mfmsr r10; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000206 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
Michael Ellerman758438a2005-12-05 15:49:00 -0600207 LOAD_HANDLER(r12,label) \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000208 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000209 mtspr SPRN_SRR0,r12; \
210 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
211 mtspr SPRN_SRR1,r10; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000212 rfid; \
213 b . /* prevent speculative execution */
214
215/*
216 * This is the start of the interrupt handlers for iSeries
217 * This code runs with relocation on.
218 */
219#define EXCEPTION_PROLOG_ISERIES_1(area) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000220 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000221 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
222 std r10,area+EX_R10(r13); \
223 std r11,area+EX_R11(r13); \
224 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000225 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000226 std r9,area+EX_R13(r13); \
227 mfcr r9
228
229#define EXCEPTION_PROLOG_ISERIES_2 \
230 mfmsr r10; \
David Gibson3356bb92006-01-13 10:26:42 +1100231 ld r12,PACALPPACAPTR(r13); \
232 ld r11,LPPACASRR0(r12); \
233 ld r12,LPPACASRR1(r12); \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000234 ori r10,r10,MSR_RI; \
235 mtmsrd r10,1
236
237/*
238 * The common exception prolog is used for all except a few exceptions
239 * such as a segment miss on a kernel address. We have to be prepared
240 * to take another exception from the point where we first touch the
241 * kernel stack onwards.
242 *
243 * On entry r13 points to the paca, r9-r13 are saved in the paca,
244 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
245 * SRR1, and relocation is on.
246 */
247#define EXCEPTION_PROLOG_COMMON(n, area) \
248 andi. r10,r12,MSR_PR; /* See if coming from user */ \
249 mr r10,r1; /* Save r1 */ \
250 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
251 beq- 1f; \
252 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
2531: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
254 bge- cr1,bad_stack; /* abort if it is */ \
255 std r9,_CCR(r1); /* save CR in stackframe */ \
256 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
257 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
258 std r10,0(r1); /* make stack chain pointer */ \
259 std r0,GPR0(r1); /* save r0 in stackframe */ \
260 std r10,GPR1(r1); /* save r1 in stackframe */ \
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100261 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000262 std r2,GPR2(r1); /* save r2 in stackframe */ \
263 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
264 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
265 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
266 ld r10,area+EX_R10(r13); \
267 std r9,GPR9(r1); \
268 std r10,GPR10(r1); \
269 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
270 ld r10,area+EX_R12(r13); \
271 ld r11,area+EX_R13(r13); \
272 std r9,GPR11(r1); \
273 std r10,GPR12(r1); \
274 std r11,GPR13(r1); \
275 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
276 mflr r9; /* save LR in stackframe */ \
277 std r9,_LINK(r1); \
278 mfctr r10; /* save CTR in stackframe */ \
279 std r10,_CTR(r1); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000280 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000281 std r11,_XER(r1); \
282 li r9,(n)+1; \
283 std r9,_TRAP(r1); /* set trap number */ \
284 li r10,0; \
285 ld r11,exception_marker@toc(r2); \
286 std r10,RESULT(r1); /* clear regs->result */ \
287 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
288
289/*
290 * Exception vectors.
291 */
292#define STD_EXCEPTION_PSERIES(n, label) \
293 . = n; \
294 .globl label##_pSeries; \
295label##_pSeries: \
296 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000297 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000298 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
299
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200300#define HSTD_EXCEPTION_PSERIES(n, label) \
301 . = n; \
302 .globl label##_pSeries; \
303label##_pSeries: \
304 HMT_MEDIUM; \
305 mtspr SPRN_SPRG1,r20; /* save r20 */ \
306 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
307 mtspr SPRN_SRR0,r20; \
308 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
309 mtspr SPRN_SRR1,r20; \
310 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
311 mtspr SPRN_SPRG1,r13; /* save r13 */ \
312 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
313
314
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000315#define STD_EXCEPTION_ISERIES(n, label, area) \
316 .globl label##_iSeries; \
317label##_iSeries: \
318 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000319 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000320 EXCEPTION_PROLOG_ISERIES_1(area); \
321 EXCEPTION_PROLOG_ISERIES_2; \
322 b label##_common
323
324#define MASKABLE_EXCEPTION_ISERIES(n, label) \
325 .globl label##_iSeries; \
326label##_iSeries: \
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_ISERIES_1(PACA_EXGEN); \
330 lbz r10,PACAPROCENABLED(r13); \
331 cmpwi 0,r10,0; \
332 beq- label##_iSeries_masked; \
333 EXCEPTION_PROLOG_ISERIES_2; \
334 b label##_common; \
335
336#ifdef DO_SOFT_DISABLE
337#define DISABLE_INTS \
338 lbz r10,PACAPROCENABLED(r13); \
339 li r11,0; \
340 std r10,SOFTE(r1); \
341 mfmsr r10; \
342 stb r11,PACAPROCENABLED(r13); \
343 ori r10,r10,MSR_EE; \
344 mtmsrd r10,1
345
346#define ENABLE_INTS \
347 lbz r10,PACAPROCENABLED(r13); \
348 mfmsr r11; \
349 std r10,SOFTE(r1); \
350 ori r11,r11,MSR_EE; \
351 mtmsrd r11,1
352
353#else /* hard enable/disable interrupts */
354#define DISABLE_INTS
355
356#define ENABLE_INTS \
357 ld r12,_MSR(r1); \
358 mfmsr r11; \
359 rlwimi r11,r12,0,MSR_EE; \
360 mtmsrd r11,1
361
362#endif
363
364#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
365 .align 7; \
366 .globl label##_common; \
367label##_common: \
368 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
369 DISABLE_INTS; \
370 bl .save_nvgprs; \
371 addi r3,r1,STACK_FRAME_OVERHEAD; \
372 bl hdlr; \
373 b .ret_from_except
374
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000375/*
376 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
377 * in the idle task and therefore need the special idle handling.
378 */
379#define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
380 .align 7; \
381 .globl label##_common; \
382label##_common: \
383 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
384 FINISH_NAP; \
385 DISABLE_INTS; \
386 bl .save_nvgprs; \
387 addi r3,r1,STACK_FRAME_OVERHEAD; \
388 bl hdlr; \
389 b .ret_from_except
390
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000391#define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
392 .align 7; \
393 .globl label##_common; \
394label##_common: \
395 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000396 FINISH_NAP; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000397 DISABLE_INTS; \
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100398 bl .ppc64_runlatch_on; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000399 addi r3,r1,STACK_FRAME_OVERHEAD; \
400 bl hdlr; \
401 b .ret_from_except_lite
402
403/*
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000404 * When the idle code in power4_idle puts the CPU into NAP mode,
405 * it has to do so in a loop, and relies on the external interrupt
406 * and decrementer interrupt entry code to get it out of the loop.
407 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
408 * to signal that it is in the loop and needs help to get out.
409 */
410#ifdef CONFIG_PPC_970_NAP
411#define FINISH_NAP \
412BEGIN_FTR_SECTION \
413 clrrdi r11,r1,THREAD_SHIFT; \
414 ld r9,TI_LOCAL_FLAGS(r11); \
415 andi. r10,r9,_TLF_NAPPING; \
416 bnel power4_fixup_nap; \
417END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
418#else
419#define FINISH_NAP
420#endif
421
422/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000423 * Start of pSeries system interrupt routines
424 */
425 . = 0x100
426 .globl __start_interrupts
427__start_interrupts:
428
429 STD_EXCEPTION_PSERIES(0x100, system_reset)
430
431 . = 0x200
432_machine_check_pSeries:
433 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000434 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000435 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
436
437 . = 0x300
438 .globl data_access_pSeries
439data_access_pSeries:
440 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000441 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000442BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000443 mtspr SPRN_SPRG2,r12
444 mfspr r13,SPRN_DAR
445 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000446 srdi r13,r13,60
447 rlwimi r13,r12,16,0x20
448 mfcr r12
449 cmpwi r13,0x2c
450 beq .do_stab_bolted_pSeries
451 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000452 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000453END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
454 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
455
456 . = 0x380
457 .globl data_access_slb_pSeries
458data_access_slb_pSeries:
459 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000460 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000461 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100462 std r3,PACA_EXSLB+EX_R3(r13)
463 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000464 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100465 mfcr r9
466#ifdef __DISABLED__
467 /* Keep that around for when we re-implement dynamic VSIDs */
468 cmpdi r3,0
469 bge slb_miss_user_pseries
470#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000471 std r10,PACA_EXSLB+EX_R10(r13)
472 std r11,PACA_EXSLB+EX_R11(r13)
473 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100474 mfspr r10,SPRN_SPRG1
475 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000476 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100477 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000478
479 STD_EXCEPTION_PSERIES(0x400, instruction_access)
480
481 . = 0x480
482 .globl instruction_access_slb_pSeries
483instruction_access_slb_pSeries:
484 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000485 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000486 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100487 std r3,PACA_EXSLB+EX_R3(r13)
488 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000489 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100490 mfcr r9
491#ifdef __DISABLED__
492 /* Keep that around for when we re-implement dynamic VSIDs */
493 cmpdi r3,0
494 bge slb_miss_user_pseries
495#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000496 std r10,PACA_EXSLB+EX_R10(r13)
497 std r11,PACA_EXSLB+EX_R11(r13)
498 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100499 mfspr r10,SPRN_SPRG1
500 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000501 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100502 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000503
504 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
505 STD_EXCEPTION_PSERIES(0x600, alignment)
506 STD_EXCEPTION_PSERIES(0x700, program_check)
507 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
508 STD_EXCEPTION_PSERIES(0x900, decrementer)
509 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
510 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
511
512 . = 0xc00
513 .globl system_call_pSeries
514system_call_pSeries:
515 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000516 mr r9,r13
517 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000518 mfspr r13,SPRN_SPRG3
519 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000520 clrrdi r12,r13,32
521 oris r12,r12,system_call_common@h
522 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000523 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000524 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000525 mfspr r12,SPRN_SRR1
526 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000527 rfid
528 b . /* prevent speculative execution */
529
530 STD_EXCEPTION_PSERIES(0xd00, single_step)
531 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
532
533 /* We need to deal with the Altivec unavailable exception
534 * here which is at 0xf20, thus in the middle of the
535 * prolog code of the PerformanceMonitor one. A little
536 * trickery is thus necessary
537 */
538 . = 0xf00
539 b performance_monitor_pSeries
540
541 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
542
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200543#ifdef CONFIG_CBE_RAS
544 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
545#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000546 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200547#ifdef CONFIG_CBE_RAS
548 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
549#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000550 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200551#ifdef CONFIG_CBE_RAS
552 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
553#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000554
555 . = 0x3000
556
557/*** pSeries interrupt support ***/
558
559 /* moved from 0xf00 */
560 STD_EXCEPTION_PSERIES(., performance_monitor)
561
562 .align 7
563_GLOBAL(do_stab_bolted_pSeries)
564 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000565 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000566 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
567
568/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100569 * We have some room here we use that to put
570 * the peries slb miss user trampoline code so it's reasonably
571 * away from slb_miss_user_common to avoid problems with rfid
572 *
573 * This is used for when the SLB miss handler has to go virtual,
574 * which doesn't happen for now anymore but will once we re-implement
575 * dynamic VSIDs for shared page tables
576 */
577#ifdef __DISABLED__
578slb_miss_user_pseries:
579 std r10,PACA_EXGEN+EX_R10(r13)
580 std r11,PACA_EXGEN+EX_R11(r13)
581 std r12,PACA_EXGEN+EX_R12(r13)
582 mfspr r10,SPRG1
583 ld r11,PACA_EXSLB+EX_R9(r13)
584 ld r12,PACA_EXSLB+EX_R3(r13)
585 std r10,PACA_EXGEN+EX_R13(r13)
586 std r11,PACA_EXGEN+EX_R9(r13)
587 std r12,PACA_EXGEN+EX_R3(r13)
588 clrrdi r12,r13,32
589 mfmsr r10
590 mfspr r11,SRR0 /* save SRR0 */
591 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
592 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
593 mtspr SRR0,r12
594 mfspr r12,SRR1 /* and SRR1 */
595 mtspr SRR1,r10
596 rfid
597 b . /* prevent spec. execution */
598#endif /* __DISABLED__ */
599
600/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000601 * Vectors for the FWNMI option. Share common code.
602 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000603 .globl system_reset_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100604 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000605system_reset_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000606 HMT_MEDIUM
607 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000608 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000609
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000610 .globl machine_check_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100611 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000612machine_check_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000613 HMT_MEDIUM
614 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000615 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000616
617#ifdef CONFIG_PPC_ISERIES
618/*** ISeries-LPAR interrupt handlers ***/
619
620 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
621
622 .globl data_access_iSeries
623data_access_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000624 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000625BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000626 mtspr SPRN_SPRG2,r12
627 mfspr r13,SPRN_DAR
628 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000629 srdi r13,r13,60
630 rlwimi r13,r12,16,0x20
631 mfcr r12
632 cmpwi r13,0x2c
633 beq .do_stab_bolted_iSeries
634 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000635 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000636END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
637 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
638 EXCEPTION_PROLOG_ISERIES_2
639 b data_access_common
640
641.do_stab_bolted_iSeries:
642 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000643 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000644 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
645 EXCEPTION_PROLOG_ISERIES_2
646 b .do_stab_bolted
647
648 .globl data_access_slb_iSeries
649data_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000650 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100651 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000652 std r3,PACA_EXSLB+EX_R3(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000653 mfspr r3,SPRN_DAR
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100654 std r9,PACA_EXSLB+EX_R9(r13)
655 mfcr r9
656#ifdef __DISABLED__
657 cmpdi r3,0
658 bge slb_miss_user_iseries
659#endif
660 std r10,PACA_EXSLB+EX_R10(r13)
661 std r11,PACA_EXSLB+EX_R11(r13)
662 std r12,PACA_EXSLB+EX_R12(r13)
663 mfspr r10,SPRN_SPRG1
664 std r10,PACA_EXSLB+EX_R13(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100665 ld r12,PACALPPACAPTR(r13)
666 ld r12,LPPACASRR1(r12)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100667 b .slb_miss_realmode
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000668
669 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
670
671 .globl instruction_access_slb_iSeries
672instruction_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000673 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100674 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000675 std r3,PACA_EXSLB+EX_R3(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100676 ld r3,PACALPPACAPTR(r13)
677 ld r3,LPPACASRR0(r3) /* get SRR0 value */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100678 std r9,PACA_EXSLB+EX_R9(r13)
679 mfcr r9
680#ifdef __DISABLED__
681 cmpdi r3,0
682 bge .slb_miss_user_iseries
683#endif
684 std r10,PACA_EXSLB+EX_R10(r13)
685 std r11,PACA_EXSLB+EX_R11(r13)
686 std r12,PACA_EXSLB+EX_R12(r13)
687 mfspr r10,SPRN_SPRG1
688 std r10,PACA_EXSLB+EX_R13(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100689 ld r12,PACALPPACAPTR(r13)
690 ld r12,LPPACASRR1(r12)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100691 b .slb_miss_realmode
692
693#ifdef __DISABLED__
694slb_miss_user_iseries:
695 std r10,PACA_EXGEN+EX_R10(r13)
696 std r11,PACA_EXGEN+EX_R11(r13)
697 std r12,PACA_EXGEN+EX_R12(r13)
698 mfspr r10,SPRG1
699 ld r11,PACA_EXSLB+EX_R9(r13)
700 ld r12,PACA_EXSLB+EX_R3(r13)
701 std r10,PACA_EXGEN+EX_R13(r13)
702 std r11,PACA_EXGEN+EX_R9(r13)
703 std r12,PACA_EXGEN+EX_R3(r13)
704 EXCEPTION_PROLOG_ISERIES_2
705 b slb_miss_user_common
706#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000707
708 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
709 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
710 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
711 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
712 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
713 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
714 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
715
716 .globl system_call_iSeries
717system_call_iSeries:
718 mr r9,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000719 mfspr r13,SPRN_SPRG3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000720 EXCEPTION_PROLOG_ISERIES_2
721 b system_call_common
722
723 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
724 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
725 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
726
727 .globl system_reset_iSeries
728system_reset_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000729 mfspr r13,SPRN_SPRG3 /* Get paca address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000730 mfmsr r24
731 ori r24,r24,MSR_RI
732 mtmsrd r24 /* RI on */
733 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
734 cmpwi 0,r24,0 /* Are we processor 0? */
735 beq .__start_initialization_iSeries /* Start up the first processor */
736 mfspr r4,SPRN_CTRLF
737 li r5,CTRL_RUNLATCH /* Turn off the run light */
738 andc r4,r4,r5
739 mtspr SPRN_CTRLT,r4
740
7411:
742 HMT_LOW
743#ifdef CONFIG_SMP
744 lbz r23,PACAPROCSTART(r13) /* Test if this processor
745 * should start */
746 sync
David Gibsone58c3492006-01-13 14:56:25 +1100747 LOAD_REG_IMMEDIATE(r3,current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000748 sldi r28,r24,3 /* get current_set[cpu#] */
749 ldx r3,r3,r28
750 addi r1,r3,THREAD_SIZE
751 subi r1,r1,STACK_FRAME_OVERHEAD
752
753 cmpwi 0,r23,0
754 beq iSeries_secondary_smp_loop /* Loop until told to go */
755 bne .__secondary_start /* Loop until told to go */
756iSeries_secondary_smp_loop:
757 /* Let the Hypervisor know we are alive */
758 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
759 lis r3,0x8002
760 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
761#else /* CONFIG_SMP */
762 /* Yield the processor. This is required for non-SMP kernels
763 which are running on multi-threaded machines. */
764 lis r3,0x8000
765 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
766 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
767 li r4,0 /* "yield timed" */
768 li r5,-1 /* "yield forever" */
769#endif /* CONFIG_SMP */
770 li r0,-1 /* r0=-1 indicates a Hypervisor call */
771 sc /* Invoke the hypervisor via a system call */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000772 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000773 b 1b /* If SMP not configured, secondaries
774 * loop forever */
775
776 .globl decrementer_iSeries_masked
777decrementer_iSeries_masked:
Michael Ellermanf9b40452006-02-07 13:26:14 +1100778 /* We may not have a valid TOC pointer in here. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000779 li r11,1
David Gibson3356bb92006-01-13 10:26:42 +1100780 ld r12,PACALPPACAPTR(r13)
781 stb r11,LPPACADECRINT(r12)
Michael Ellermanf9b40452006-02-07 13:26:14 +1100782 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
783 lwz r12,0(r12)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000784 mtspr SPRN_DEC,r12
785 /* fall through */
786
787 .globl hardware_interrupt_iSeries_masked
788hardware_interrupt_iSeries_masked:
789 mtcrf 0x80,r9 /* Restore regs */
David Gibson3356bb92006-01-13 10:26:42 +1100790 ld r12,PACALPPACAPTR(r13)
791 ld r11,LPPACASRR0(r12)
792 ld r12,LPPACASRR1(r12)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000793 mtspr SPRN_SRR0,r11
794 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000795 ld r9,PACA_EXGEN+EX_R9(r13)
796 ld r10,PACA_EXGEN+EX_R10(r13)
797 ld r11,PACA_EXGEN+EX_R11(r13)
798 ld r12,PACA_EXGEN+EX_R12(r13)
799 ld r13,PACA_EXGEN+EX_R13(r13)
800 rfid
801 b . /* prevent speculative execution */
802#endif /* CONFIG_PPC_ISERIES */
803
804/*** Common interrupt handlers ***/
805
806 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
807
808 /*
809 * Machine check is different because we use a different
810 * save area: PACA_EXMC instead of PACA_EXGEN.
811 */
812 .align 7
813 .globl machine_check_common
814machine_check_common:
815 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000816 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000817 DISABLE_INTS
818 bl .save_nvgprs
819 addi r3,r1,STACK_FRAME_OVERHEAD
820 bl .machine_check_exception
821 b .ret_from_except
822
823 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
824 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
825 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
826 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
827 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000828 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000829 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
830#ifdef CONFIG_ALTIVEC
831 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
832#else
833 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
834#endif
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200835#ifdef CONFIG_CBE_RAS
836 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
837 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
838 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
839#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000840
841/*
842 * Here we have detected that the kernel stack pointer is bad.
843 * R9 contains the saved CR, r13 points to the paca,
844 * r10 contains the (bad) kernel stack pointer,
845 * r11 and r12 contain the saved SRR0 and SRR1.
846 * We switch to using an emergency stack, save the registers there,
847 * and call kernel_bad_stack(), which panics.
848 */
849bad_stack:
850 ld r1,PACAEMERGSP(r13)
851 subi r1,r1,64+INT_FRAME_SIZE
852 std r9,_CCR(r1)
853 std r10,GPR1(r1)
854 std r11,_NIP(r1)
855 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000856 mfspr r11,SPRN_DAR
857 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000858 std r11,_DAR(r1)
859 std r12,_DSISR(r1)
860 mflr r10
861 mfctr r11
862 mfxer r12
863 std r10,_LINK(r1)
864 std r11,_CTR(r1)
865 std r12,_XER(r1)
866 SAVE_GPR(0,r1)
867 SAVE_GPR(2,r1)
868 SAVE_4GPRS(3,r1)
869 SAVE_2GPRS(7,r1)
870 SAVE_10GPRS(12,r1)
871 SAVE_10GPRS(22,r1)
872 addi r11,r1,INT_FRAME_SIZE
873 std r11,0(r1)
874 li r12,0
875 std r12,0(r11)
876 ld r2,PACATOC(r13)
8771: addi r3,r1,STACK_FRAME_OVERHEAD
878 bl .kernel_bad_stack
879 b 1b
880
881/*
882 * Return from an exception with minimal checks.
883 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
884 * If interrupts have been enabled, or anything has been
885 * done that might have changed the scheduling status of
886 * any task or sent any task a signal, you should use
887 * ret_from_except or ret_from_except_lite instead of this.
888 */
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000889 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000890fast_exception_return:
891 ld r12,_MSR(r1)
892 ld r11,_NIP(r1)
893 andi. r3,r12,MSR_RI /* check if RI is set */
894 beq- unrecov_fer
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100895
896#ifdef CONFIG_VIRT_CPU_ACCOUNTING
897 andi. r3,r12,MSR_PR
898 beq 2f
899 ACCOUNT_CPU_USER_EXIT(r3, r4)
9002:
901#endif
902
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000903 ld r3,_CCR(r1)
904 ld r4,_LINK(r1)
905 ld r5,_CTR(r1)
906 ld r6,_XER(r1)
907 mtcr r3
908 mtlr r4
909 mtctr r5
910 mtxer r6
911 REST_GPR(0, r1)
912 REST_8GPRS(2, r1)
913
914 mfmsr r10
915 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
916 mtmsrd r10,1
917
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000918 mtspr SPRN_SRR1,r12
919 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000920 REST_4GPRS(10, r1)
921 ld r1,GPR1(r1)
922 rfid
923 b . /* prevent speculative execution */
924
925unrecov_fer:
926 bl .save_nvgprs
9271: addi r3,r1,STACK_FRAME_OVERHEAD
928 bl .unrecoverable_exception
929 b 1b
930
931/*
932 * Here r13 points to the paca, r9 contains the saved CR,
933 * SRR0 and SRR1 are saved in r11 and r12,
934 * r9 - r13 are saved in paca->exgen.
935 */
936 .align 7
937 .globl data_access_common
938data_access_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000939 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000940 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000941 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000942 stw r10,PACA_EXGEN+EX_DSISR(r13)
943 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
944 ld r3,PACA_EXGEN+EX_DAR(r13)
945 lwz r4,PACA_EXGEN+EX_DSISR(r13)
946 li r5,0x300
947 b .do_hash_page /* Try to handle as hpte fault */
948
949 .align 7
950 .globl instruction_access_common
951instruction_access_common:
952 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
953 ld r3,_NIP(r1)
954 andis. r4,r12,0x5820
955 li r5,0x400
956 b .do_hash_page /* Try to handle as hpte fault */
957
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100958/*
959 * Here is the common SLB miss user that is used when going to virtual
960 * mode for SLB misses, that is currently not used
961 */
962#ifdef __DISABLED__
963 .align 7
964 .globl slb_miss_user_common
965slb_miss_user_common:
966 mflr r10
967 std r3,PACA_EXGEN+EX_DAR(r13)
968 stw r9,PACA_EXGEN+EX_CCR(r13)
969 std r10,PACA_EXGEN+EX_LR(r13)
970 std r11,PACA_EXGEN+EX_SRR0(r13)
971 bl .slb_allocate_user
972
973 ld r10,PACA_EXGEN+EX_LR(r13)
974 ld r3,PACA_EXGEN+EX_R3(r13)
975 lwz r9,PACA_EXGEN+EX_CCR(r13)
976 ld r11,PACA_EXGEN+EX_SRR0(r13)
977 mtlr r10
978 beq- slb_miss_fault
979
980 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
981 beq- unrecov_user_slb
982 mfmsr r10
983
984.machine push
985.machine "power4"
986 mtcrf 0x80,r9
987.machine pop
988
989 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
990 mtmsrd r10,1
991
992 mtspr SRR0,r11
993 mtspr SRR1,r12
994
995 ld r9,PACA_EXGEN+EX_R9(r13)
996 ld r10,PACA_EXGEN+EX_R10(r13)
997 ld r11,PACA_EXGEN+EX_R11(r13)
998 ld r12,PACA_EXGEN+EX_R12(r13)
999 ld r13,PACA_EXGEN+EX_R13(r13)
1000 rfid
1001 b .
1002
1003slb_miss_fault:
1004 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1005 ld r4,PACA_EXGEN+EX_DAR(r13)
1006 li r5,0
1007 std r4,_DAR(r1)
1008 std r5,_DSISR(r1)
1009 b .handle_page_fault
1010
1011unrecov_user_slb:
1012 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1013 DISABLE_INTS
1014 bl .save_nvgprs
10151: addi r3,r1,STACK_FRAME_OVERHEAD
1016 bl .unrecoverable_exception
1017 b 1b
1018
1019#endif /* __DISABLED__ */
1020
1021
1022/*
1023 * r13 points to the PACA, r9 contains the saved CR,
1024 * r12 contain the saved SRR1, SRR0 is still ready for return
1025 * r3 has the faulting address
1026 * r9 - r13 are saved in paca->exslb.
1027 * r3 is saved in paca->slb_r3
1028 * We assume we aren't going to take any exceptions during this procedure.
1029 */
1030_GLOBAL(slb_miss_realmode)
1031 mflr r10
1032
1033 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1034 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1035
1036 bl .slb_allocate_realmode
1037
1038 /* All done -- return from exception. */
1039
1040 ld r10,PACA_EXSLB+EX_LR(r13)
1041 ld r3,PACA_EXSLB+EX_R3(r13)
1042 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1043#ifdef CONFIG_PPC_ISERIES
David Gibson3356bb92006-01-13 10:26:42 +11001044 ld r11,PACALPPACAPTR(r13)
1045 ld r11,LPPACASRR0(r11) /* get SRR0 value */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +11001046#endif /* CONFIG_PPC_ISERIES */
1047
1048 mtlr r10
1049
1050 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1051 beq- unrecov_slb
1052
1053.machine push
1054.machine "power4"
1055 mtcrf 0x80,r9
1056 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1057.machine pop
1058
1059#ifdef CONFIG_PPC_ISERIES
1060 mtspr SPRN_SRR0,r11
1061 mtspr SPRN_SRR1,r12
1062#endif /* CONFIG_PPC_ISERIES */
1063 ld r9,PACA_EXSLB+EX_R9(r13)
1064 ld r10,PACA_EXSLB+EX_R10(r13)
1065 ld r11,PACA_EXSLB+EX_R11(r13)
1066 ld r12,PACA_EXSLB+EX_R12(r13)
1067 ld r13,PACA_EXSLB+EX_R13(r13)
1068 rfid
1069 b . /* prevent speculative execution */
1070
1071unrecov_slb:
1072 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1073 DISABLE_INTS
1074 bl .save_nvgprs
10751: addi r3,r1,STACK_FRAME_OVERHEAD
1076 bl .unrecoverable_exception
1077 b 1b
1078
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001079 .align 7
1080 .globl hardware_interrupt_common
1081 .globl hardware_interrupt_entry
1082hardware_interrupt_common:
1083 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
Paul Mackerrasf39224a2006-04-18 21:49:11 +10001084 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001085hardware_interrupt_entry:
1086 DISABLE_INTS
Anton Blanchardcb2c9b22006-02-13 14:48:35 +11001087 bl .ppc64_runlatch_on
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001088 addi r3,r1,STACK_FRAME_OVERHEAD
1089 bl .do_IRQ
1090 b .ret_from_except_lite
1091
Paul Mackerrasf39224a2006-04-18 21:49:11 +10001092#ifdef CONFIG_PPC_970_NAP
1093power4_fixup_nap:
1094 andc r9,r9,r10
1095 std r9,TI_LOCAL_FLAGS(r11)
1096 ld r10,_LINK(r1) /* make idle task do the */
1097 std r10,_NIP(r1) /* equivalent of a blr */
1098 blr
1099#endif
1100
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001101 .align 7
1102 .globl alignment_common
1103alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001104 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001105 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001106 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001107 stw r10,PACA_EXGEN+EX_DSISR(r13)
1108 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1109 ld r3,PACA_EXGEN+EX_DAR(r13)
1110 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1111 std r3,_DAR(r1)
1112 std r4,_DSISR(r1)
1113 bl .save_nvgprs
1114 addi r3,r1,STACK_FRAME_OVERHEAD
1115 ENABLE_INTS
1116 bl .alignment_exception
1117 b .ret_from_except
1118
1119 .align 7
1120 .globl program_check_common
1121program_check_common:
1122 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1123 bl .save_nvgprs
1124 addi r3,r1,STACK_FRAME_OVERHEAD
1125 ENABLE_INTS
1126 bl .program_check_exception
1127 b .ret_from_except
1128
1129 .align 7
1130 .globl fp_unavailable_common
1131fp_unavailable_common:
1132 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1133 bne .load_up_fpu /* if from user, just load it up */
1134 bl .save_nvgprs
1135 addi r3,r1,STACK_FRAME_OVERHEAD
1136 ENABLE_INTS
1137 bl .kernel_fp_unavailable_exception
1138 BUG_OPCODE
1139
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001140 .align 7
1141 .globl altivec_unavailable_common
1142altivec_unavailable_common:
1143 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1144#ifdef CONFIG_ALTIVEC
1145BEGIN_FTR_SECTION
1146 bne .load_up_altivec /* if from user, just load it up */
1147END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1148#endif
1149 bl .save_nvgprs
1150 addi r3,r1,STACK_FRAME_OVERHEAD
1151 ENABLE_INTS
1152 bl .altivec_unavailable_exception
1153 b .ret_from_except
1154
1155#ifdef CONFIG_ALTIVEC
1156/*
1157 * load_up_altivec(unused, unused, tsk)
1158 * Disable VMX for the task which had it previously,
1159 * and save its vector registers in its thread_struct.
1160 * Enables the VMX for use in the kernel on return.
1161 * On SMP we know the VMX is free, since we give it up every
1162 * switch (ie, no lazy save of the vector registers).
1163 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1164 */
1165_STATIC(load_up_altivec)
1166 mfmsr r5 /* grab the current MSR */
1167 oris r5,r5,MSR_VEC@h
1168 mtmsrd r5 /* enable use of VMX now */
1169 isync
1170
1171/*
1172 * For SMP, we don't do lazy VMX switching because it just gets too
1173 * horrendously complex, especially when a task switches from one CPU
1174 * to another. Instead we call giveup_altvec in switch_to.
1175 * VRSAVE isn't dealt with here, that is done in the normal context
1176 * switch code. Note that we could rely on vrsave value to eventually
1177 * avoid saving all of the VREGs here...
1178 */
1179#ifndef CONFIG_SMP
1180 ld r3,last_task_used_altivec@got(r2)
1181 ld r4,0(r3)
1182 cmpdi 0,r4,0
1183 beq 1f
1184 /* Save VMX state to last_task_used_altivec's THREAD struct */
1185 addi r4,r4,THREAD
1186 SAVE_32VRS(0,r5,r4)
1187 mfvscr vr0
1188 li r10,THREAD_VSCR
1189 stvx vr0,r10,r4
1190 /* Disable VMX for last_task_used_altivec */
1191 ld r5,PT_REGS(r4)
1192 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1193 lis r6,MSR_VEC@h
1194 andc r4,r4,r6
1195 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
11961:
1197#endif /* CONFIG_SMP */
1198 /* Hack: if we get an altivec unavailable trap with VRSAVE
1199 * set to all zeros, we assume this is a broken application
1200 * that fails to set it properly, and thus we switch it to
1201 * all 1's
1202 */
1203 mfspr r4,SPRN_VRSAVE
1204 cmpdi 0,r4,0
1205 bne+ 1f
1206 li r4,-1
1207 mtspr SPRN_VRSAVE,r4
12081:
1209 /* enable use of VMX after return */
1210 ld r4,PACACURRENT(r13)
1211 addi r5,r4,THREAD /* Get THREAD */
1212 oris r12,r12,MSR_VEC@h
1213 std r12,_MSR(r1)
1214 li r4,1
1215 li r10,THREAD_VSCR
1216 stw r4,THREAD_USED_VR(r5)
1217 lvx vr0,r10,r5
1218 mtvscr vr0
1219 REST_32VRS(0,r4,r5)
1220#ifndef CONFIG_SMP
1221 /* Update last_task_used_math to 'current' */
1222 subi r4,r5,THREAD /* Back to 'current' */
1223 std r4,0(r3)
1224#endif /* CONFIG_SMP */
1225 /* restore registers and return */
1226 b fast_exception_return
1227#endif /* CONFIG_ALTIVEC */
1228
1229/*
1230 * Hash table stuff
1231 */
1232 .align 7
1233_GLOBAL(do_hash_page)
1234 std r3,_DAR(r1)
1235 std r4,_DSISR(r1)
1236
1237 andis. r0,r4,0xa450 /* weird error? */
1238 bne- .handle_page_fault /* if not, try to insert a HPTE */
1239BEGIN_FTR_SECTION
1240 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1241 bne- .do_ste_alloc /* If so handle it */
1242END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1243
1244 /*
1245 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1246 * accessing a userspace segment (even from the kernel). We assume
1247 * kernel addresses always have the high bit set.
1248 */
1249 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1250 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1251 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1252 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1253 ori r4,r4,1 /* add _PAGE_PRESENT */
1254 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1255
1256 /*
1257 * On iSeries, we soft-disable interrupts here, then
1258 * hard-enable interrupts so that the hash_page code can spin on
1259 * the hash_table_lock without problems on a shared processor.
1260 */
1261 DISABLE_INTS
1262
1263 /*
1264 * r3 contains the faulting address
1265 * r4 contains the required access permissions
1266 * r5 contains the trap number
1267 *
1268 * at return r3 = 0 for success
1269 */
1270 bl .hash_page /* build HPTE if possible */
1271 cmpdi r3,0 /* see if hash_page succeeded */
1272
1273#ifdef DO_SOFT_DISABLE
1274 /*
1275 * If we had interrupts soft-enabled at the point where the
1276 * DSI/ISI occurred, and an interrupt came in during hash_page,
1277 * handle it now.
1278 * We jump to ret_from_except_lite rather than fast_exception_return
1279 * because ret_from_except_lite will check for and handle pending
1280 * interrupts if necessary.
1281 */
1282 beq .ret_from_except_lite
1283 /* For a hash failure, we don't bother re-enabling interrupts */
1284 ble- 12f
1285
1286 /*
1287 * hash_page couldn't handle it, set soft interrupt enable back
1288 * to what it was before the trap. Note that .local_irq_restore
1289 * handles any interrupts pending at this point.
1290 */
1291 ld r3,SOFTE(r1)
1292 bl .local_irq_restore
1293 b 11f
1294#else
1295 beq fast_exception_return /* Return from exception on success */
1296 ble- 12f /* Failure return from hash_page */
1297
1298 /* fall through */
1299#endif
1300
1301/* Here we have a page fault that hash_page can't handle. */
1302_GLOBAL(handle_page_fault)
1303 ENABLE_INTS
130411: ld r4,_DAR(r1)
1305 ld r5,_DSISR(r1)
1306 addi r3,r1,STACK_FRAME_OVERHEAD
1307 bl .do_page_fault
1308 cmpdi r3,0
1309 beq+ .ret_from_except_lite
1310 bl .save_nvgprs
1311 mr r5,r3
1312 addi r3,r1,STACK_FRAME_OVERHEAD
1313 lwz r4,_DAR(r1)
1314 bl .bad_page_fault
1315 b .ret_from_except
1316
1317/* We have a page fault that hash_page could handle but HV refused
1318 * the PTE insertion
1319 */
132012: bl .save_nvgprs
1321 addi r3,r1,STACK_FRAME_OVERHEAD
1322 lwz r4,_DAR(r1)
1323 bl .low_hash_fault
1324 b .ret_from_except
1325
1326 /* here we have a segment miss */
1327_GLOBAL(do_ste_alloc)
1328 bl .ste_allocate /* try to insert stab entry */
1329 cmpdi r3,0
1330 beq+ fast_exception_return
1331 b .handle_page_fault
1332
1333/*
1334 * r13 points to the PACA, r9 contains the saved CR,
1335 * r11 and r12 contain the saved SRR0 and SRR1.
1336 * r9 - r13 are saved in paca->exslb.
1337 * We assume we aren't going to take any exceptions during this procedure.
1338 * We assume (DAR >> 60) == 0xc.
1339 */
1340 .align 7
1341_GLOBAL(do_stab_bolted)
1342 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1343 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1344
1345 /* Hash to the primary group */
1346 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001347 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001348 srdi r11,r11,28
1349 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1350
1351 /* Calculate VSID */
1352 /* This is a kernel address, so protovsid = ESID */
1353 ASM_VSID_SCRAMBLE(r11, r9)
1354 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1355
1356 /* Search the primary group for a free entry */
13571: ld r11,0(r10) /* Test valid bit of the current ste */
1358 andi. r11,r11,0x80
1359 beq 2f
1360 addi r10,r10,16
1361 andi. r11,r10,0x70
1362 bne 1b
1363
1364 /* Stick for only searching the primary group for now. */
1365 /* At least for now, we use a very simple random castout scheme */
1366 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1367 mftb r11
1368 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1369 ori r11,r11,0x10
1370
1371 /* r10 currently points to an ste one past the group of interest */
1372 /* make it point to the randomly selected entry */
1373 subi r10,r10,128
1374 or r10,r10,r11 /* r10 is the entry to invalidate */
1375
1376 isync /* mark the entry invalid */
1377 ld r11,0(r10)
1378 rldicl r11,r11,56,1 /* clear the valid bit */
1379 rotldi r11,r11,8
1380 std r11,0(r10)
1381 sync
1382
1383 clrrdi r11,r11,28 /* Get the esid part of the ste */
1384 slbie r11
1385
13862: std r9,8(r10) /* Store the vsid part of the ste */
1387 eieio
1388
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001389 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001390 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1391 ori r11,r11,0x90 /* Turn on valid and kp */
1392 std r11,0(r10) /* Put new entry back into the stab */
1393
1394 sync
1395
1396 /* All done -- return from exception. */
1397 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1398 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1399
1400 andi. r10,r12,MSR_RI
1401 beq- unrecov_slb
1402
1403 mtcrf 0x80,r9 /* restore CR */
1404
1405 mfmsr r10
1406 clrrdi r10,r10,2
1407 mtmsrd r10,1
1408
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001409 mtspr SPRN_SRR0,r11
1410 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001411 ld r9,PACA_EXSLB+EX_R9(r13)
1412 ld r10,PACA_EXSLB+EX_R10(r13)
1413 ld r11,PACA_EXSLB+EX_R11(r13)
1414 ld r12,PACA_EXSLB+EX_R12(r13)
1415 ld r13,PACA_EXSLB+EX_R13(r13)
1416 rfid
1417 b . /* prevent speculative execution */
1418
1419/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001420 * Space for CPU0's segment table.
1421 *
1422 * On iSeries, the hypervisor must fill in at least one entry before
1423 * we get control (with relocate on). The address is give to the hv
Stephen Rothwellee400b62005-09-29 11:50:22 +10001424 * as a page number (see xLparMap in lpardata.c), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001425 * fixed address (the linker can't compute (u64)&initial_stab >>
1426 * PAGE_SHIFT).
1427 */
Michael Ellerman758438a2005-12-05 15:49:00 -06001428 . = STAB0_OFFSET /* 0x6000 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001429 .globl initial_stab
1430initial_stab:
1431 .space 4096
1432
1433/*
1434 * Data area reserved for FWNMI option.
1435 * This address (0x7000) is fixed by the RPA.
1436 */
1437 .= 0x7000
1438 .globl fwnmi_data_area
1439fwnmi_data_area:
1440
1441 /* iSeries does not use the FWNMI stuff, so it is safe to put
1442 * this here, even if we later allow kernels that will boot on
1443 * both pSeries and iSeries */
1444#ifdef CONFIG_PPC_ISERIES
1445 . = LPARMAP_PHYS
1446#include "lparmap.s"
1447/*
1448 * This ".text" is here for old compilers that generate a trailing
1449 * .note section when compiling .c files to .s
1450 */
1451 .text
1452#endif /* CONFIG_PPC_ISERIES */
1453
1454 . = 0x8000
1455
1456/*
1457 * On pSeries, secondary processors spin in the following code.
1458 * At entry, r3 = this processor's number (physical cpu id)
1459 */
1460_GLOBAL(pSeries_secondary_smp_init)
1461 mr r24,r3
1462
1463 /* turn on 64-bit mode */
1464 bl .enable_64b_mode
1465 isync
1466
1467 /* Copy some CPU settings from CPU 0 */
1468 bl .__restore_cpu_setup
1469
1470 /* Set up a paca value for this processor. Since we have the
1471 * physical cpu id in r24, we need to search the pacas to find
1472 * which logical id maps to our physical one.
1473 */
David Gibsone58c3492006-01-13 14:56:25 +11001474 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001475 li r5,0 /* logical cpu id */
14761: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1477 cmpw r6,r24 /* Compare to our id */
1478 beq 2f
1479 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1480 addi r5,r5,1
1481 cmpwi r5,NR_CPUS
1482 blt 1b
1483
1484 mr r3,r24 /* not found, copy phys to r3 */
1485 b .kexec_wait /* next kernel might do better */
1486
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100014872: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001488 /* From now on, r24 is expected to be logical cpuid */
1489 mr r24,r5
14903: HMT_LOW
1491 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1492 /* start. */
1493 sync
1494
1495 /* Create a temp kernel stack for use before relocation is on. */
1496 ld r1,PACAEMERGSP(r13)
1497 subi r1,r1,STACK_FRAME_OVERHEAD
1498
1499 cmpwi 0,r23,0
1500#ifdef CONFIG_SMP
1501 bne .__secondary_start
1502#endif
1503 b 3b /* Loop until told to go */
1504
1505#ifdef CONFIG_PPC_ISERIES
1506_STATIC(__start_initialization_iSeries)
1507 /* Clear out the BSS */
David Gibsone58c3492006-01-13 14:56:25 +11001508 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1509 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001510 sub r11,r11,r8 /* bss size */
1511 addi r11,r11,7 /* round up to an even double word */
1512 rldicl. r11,r11,61,3 /* shift right by 3 */
1513 beq 4f
1514 addi r8,r8,-8
1515 li r0,0
1516 mtctr r11 /* zero this many doublewords */
15173: stdu r0,8(r8)
1518 bdnz 3b
15194:
David Gibsone58c3492006-01-13 14:56:25 +11001520 LOAD_REG_IMMEDIATE(r1,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001521 addi r1,r1,THREAD_SIZE
1522 li r0,0
1523 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1524
David Gibsone58c3492006-01-13 14:56:25 +11001525 LOAD_REG_IMMEDIATE(r3,cpu_specs)
1526 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001527 li r5,0
1528 bl .identify_cpu
1529
David Gibsone58c3492006-01-13 14:56:25 +11001530 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001531 addi r2,r2,0x4000
1532 addi r2,r2,0x4000
1533
1534 bl .iSeries_early_setup
Stephen Rothwellee400b62005-09-29 11:50:22 +10001535 bl .early_setup
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001536
1537 /* relocation is on at this point */
1538
1539 b .start_here_common
1540#endif /* CONFIG_PPC_ISERIES */
1541
1542#ifdef CONFIG_PPC_MULTIPLATFORM
1543
1544_STATIC(__mmu_off)
1545 mfmsr r3
1546 andi. r0,r3,MSR_IR|MSR_DR
1547 beqlr
1548 andc r3,r3,r0
1549 mtspr SPRN_SRR0,r4
1550 mtspr SPRN_SRR1,r3
1551 sync
1552 rfid
1553 b . /* prevent speculative execution */
1554
1555
1556/*
1557 * Here is our main kernel entry point. We support currently 2 kind of entries
1558 * depending on the value of r5.
1559 *
1560 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1561 * in r3...r7
1562 *
1563 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1564 * DT block, r4 is a physical pointer to the kernel itself
1565 *
1566 */
1567_GLOBAL(__start_initialization_multiplatform)
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001568#ifdef CONFIG_PPC_MULTIPLATFORM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001569 /*
1570 * Are we booted from a PROM Of-type client-interface ?
1571 */
1572 cmpldi cr0,r5,0
1573 bne .__boot_from_prom /* yes -> prom */
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001574#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001575
1576 /* Save parameters */
1577 mr r31,r3
1578 mr r30,r4
1579
1580 /* Make sure we are running in 64 bits mode */
1581 bl .enable_64b_mode
1582
1583 /* Setup some critical 970 SPRs before switching MMU off */
1584 bl .__970_cpu_preinit
1585
1586 /* cpu # */
1587 li r24,0
1588
1589 /* Switch off MMU if not already */
David Gibsone58c3492006-01-13 14:56:25 +11001590 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001591 add r4,r4,r30
1592 bl .__mmu_off
1593 b .__after_prom_start
1594
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001595#ifdef CONFIG_PPC_MULTIPLATFORM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001596_STATIC(__boot_from_prom)
1597 /* Save parameters */
1598 mr r31,r3
1599 mr r30,r4
1600 mr r29,r5
1601 mr r28,r6
1602 mr r27,r7
1603
Olaf Hering60888572006-03-23 21:50:59 +01001604 /*
1605 * Align the stack to 16-byte boundary
1606 * Depending on the size and layout of the ELF sections in the initial
1607 * boot binary, the stack pointer will be unalignet on PowerMac
1608 */
Linus Torvaldsc05b4772006-03-04 15:00:45 -08001609 rldicr r1,r1,0,59
1610
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001611 /* Make sure we are running in 64 bits mode */
1612 bl .enable_64b_mode
1613
1614 /* put a relocation offset into r3 */
1615 bl .reloc_offset
1616
David Gibsone58c3492006-01-13 14:56:25 +11001617 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001618 addi r2,r2,0x4000
1619 addi r2,r2,0x4000
1620
1621 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001622 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001623
1624 /* Restore parameters */
1625 mr r3,r31
1626 mr r4,r30
1627 mr r5,r29
1628 mr r6,r28
1629 mr r7,r27
1630
1631 /* Do all of the interaction with OF client interface */
1632 bl .prom_init
1633 /* We never return */
1634 trap
Paul Mackerrasbe42d5f2006-01-09 21:32:42 +11001635#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001636
1637/*
1638 * At this point, r3 contains the physical address we are running at,
1639 * returned by prom_init()
1640 */
1641_STATIC(__after_prom_start)
1642
1643/*
Michael Ellerman758438a2005-12-05 15:49:00 -06001644 * We need to run with __start at physical address PHYSICAL_START.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001645 * This will leave some code in the first 256B of
1646 * real memory, which are reserved for software use.
1647 * The remainder of the first page is loaded with the fixed
1648 * interrupt vectors. The next two pages are filled with
1649 * unknown exception placeholders.
1650 *
1651 * Note: This process overwrites the OF exception vectors.
1652 * r26 == relocation offset
1653 * r27 == KERNELBASE
1654 */
1655 bl .reloc_offset
1656 mr r26,r3
David Gibsone58c3492006-01-13 14:56:25 +11001657 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001658
David Gibsone58c3492006-01-13 14:56:25 +11001659 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001660
1661 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001662 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001663 /* current address of _start */
1664 /* i.e. where we are running */
1665 /* the source addr */
1666
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001667 cmpdi r4,0 /* In some cases the loader may */
1668 beq .start_here_multiplatform /* have already put us at zero */
1669 /* so we can skip the copy. */
David Gibsone58c3492006-01-13 14:56:25 +11001670 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001671 sub r5,r5,r27
1672
1673 li r6,0x100 /* Start offset, the first 0x100 */
1674 /* bytes were copied earlier. */
1675
1676 bl .copy_and_flush /* copy the first n bytes */
1677 /* this includes the code being */
1678 /* executed here. */
1679
David Gibsone58c3492006-01-13 14:56:25 +11001680 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001681 mtctr r0 /* that we just made/relocated */
1682 bctr
1683
David Gibsone58c3492006-01-13 14:56:25 +110016844: LOAD_REG_IMMEDIATE(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001685 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001686 ld r5,0(r5) /* get the value of klimit */
1687 sub r5,r5,r27
1688 bl .copy_and_flush /* copy the rest */
1689 b .start_here_multiplatform
1690
1691#endif /* CONFIG_PPC_MULTIPLATFORM */
1692
1693/*
1694 * Copy routine used to copy the kernel to start at physical address 0
1695 * and flush and invalidate the caches as needed.
1696 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1697 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1698 *
1699 * Note: this routine *only* clobbers r0, r6 and lr
1700 */
1701_GLOBAL(copy_and_flush)
1702 addi r5,r5,-8
1703 addi r6,r6,-8
17044: li r0,16 /* Use the least common */
1705 /* denominator cache line */
1706 /* size. This results in */
1707 /* extra cache line flushes */
1708 /* but operation is correct. */
1709 /* Can't get cache line size */
1710 /* from NACA as it is being */
1711 /* moved too. */
1712
1713 mtctr r0 /* put # words/line in ctr */
17143: addi r6,r6,8 /* copy a cache line */
1715 ldx r0,r6,r4
1716 stdx r0,r6,r3
1717 bdnz 3b
1718 dcbst r6,r3 /* write it to memory */
1719 sync
1720 icbi r6,r3 /* flush the icache line */
1721 cmpld 0,r6,r5
1722 blt 4b
1723 sync
1724 addi r5,r5,8
1725 addi r6,r6,8
1726 blr
1727
1728.align 8
1729copy_to_here:
1730
1731#ifdef CONFIG_SMP
1732#ifdef CONFIG_PPC_PMAC
1733/*
1734 * On PowerMac, secondary processors starts from the reset vector, which
1735 * is temporarily turned into a call to one of the functions below.
1736 */
1737 .section ".text";
1738 .align 2 ;
1739
Paul Mackerras35499c02005-10-22 16:02:39 +10001740 .globl __secondary_start_pmac_0
1741__secondary_start_pmac_0:
1742 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1743 li r24,0
1744 b 1f
1745 li r24,1
1746 b 1f
1747 li r24,2
1748 b 1f
1749 li r24,3
17501:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001751
1752_GLOBAL(pmac_secondary_start)
1753 /* turn on 64-bit mode */
1754 bl .enable_64b_mode
1755 isync
1756
1757 /* Copy some CPU settings from CPU 0 */
1758 bl .__restore_cpu_setup
1759
1760 /* pSeries do that early though I don't think we really need it */
1761 mfmsr r3
1762 ori r3,r3,MSR_RI
1763 mtmsrd r3 /* RI on */
1764
1765 /* Set up a paca value for this processor. */
David Gibsone58c3492006-01-13 14:56:25 +11001766 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001767 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1768 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001769 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001770
1771 /* Create a temp kernel stack for use before relocation is on. */
1772 ld r1,PACAEMERGSP(r13)
1773 subi r1,r1,STACK_FRAME_OVERHEAD
1774
1775 b .__secondary_start
1776
1777#endif /* CONFIG_PPC_PMAC */
1778
1779/*
1780 * This function is called after the master CPU has released the
1781 * secondary processors. The execution environment is relocation off.
1782 * The paca for this processor has the following fields initialized at
1783 * this point:
1784 * 1. Processor number
1785 * 2. Segment table pointer (virtual address)
1786 * On entry the following are set:
1787 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1788 * r24 = cpu# (in Linux terms)
1789 * r13 = paca virtual address
1790 * SPRG3 = paca virtual address
1791 */
1792_GLOBAL(__secondary_start)
Paul Mackerras799d6042005-11-10 13:37:51 +11001793 /* Set thread priority to MEDIUM */
1794 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001795
Paul Mackerras799d6042005-11-10 13:37:51 +11001796 /* Load TOC */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001797 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001798
Paul Mackerras799d6042005-11-10 13:37:51 +11001799 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1800 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001801
1802 /* Initialize the kernel stack. Just a repeat for iSeries. */
David Gibsone58c3492006-01-13 14:56:25 +11001803 LOAD_REG_ADDR(r3, current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001804 sldi r28,r24,3 /* get current_set[cpu#] */
1805 ldx r1,r3,r28
1806 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1807 std r1,PACAKSAVE(r13)
1808
Paul Mackerras799d6042005-11-10 13:37:51 +11001809 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001810 li r7,0
1811 mtlr r7
1812
1813 /* enable MMU and jump to start_secondary */
David Gibsone58c3492006-01-13 14:56:25 +11001814 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1815 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001816#ifdef DO_SOFT_DISABLE
1817 ori r4,r4,MSR_EE
1818#endif
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001819 mtspr SPRN_SRR0,r3
1820 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001821 rfid
1822 b . /* prevent speculative execution */
1823
1824/*
1825 * Running with relocation on at this point. All we want to do is
1826 * zero the stack back-chain pointer before going into C code.
1827 */
1828_GLOBAL(start_secondary_prolog)
1829 li r3,0
1830 std r3,0(r1) /* Zero the stack frame pointer */
1831 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001832 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001833#endif
1834
1835/*
1836 * This subroutine clobbers r11 and r12
1837 */
1838_GLOBAL(enable_64b_mode)
1839 mfmsr r11 /* grab the current MSR */
1840 li r12,1
1841 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1842 or r11,r11,r12
1843 li r12,1
1844 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1845 or r11,r11,r12
1846 mtmsrd r11
1847 isync
1848 blr
1849
1850#ifdef CONFIG_PPC_MULTIPLATFORM
1851/*
1852 * This is where the main kernel code starts.
1853 */
1854_STATIC(start_here_multiplatform)
1855 /* get a new offset, now that the kernel has moved. */
1856 bl .reloc_offset
1857 mr r26,r3
1858
1859 /* Clear out the BSS. It may have been done in prom_init,
1860 * already but that's irrelevant since prom_init will soon
1861 * be detached from the kernel completely. Besides, we need
1862 * to clear it now for kexec-style entry.
1863 */
David Gibsone58c3492006-01-13 14:56:25 +11001864 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1865 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001866 sub r11,r11,r8 /* bss size */
1867 addi r11,r11,7 /* round up to an even double word */
1868 rldicl. r11,r11,61,3 /* shift right by 3 */
1869 beq 4f
1870 addi r8,r8,-8
1871 li r0,0
1872 mtctr r11 /* zero this many doublewords */
18733: stdu r0,8(r8)
1874 bdnz 3b
18754:
1876
1877 mfmsr r6
1878 ori r6,r6,MSR_RI
1879 mtmsrd r6 /* RI on */
1880
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001881 /* The following gets the stack and TOC set up with the regs */
1882 /* pointing to the real addr of the kernel stack. This is */
1883 /* all done to support the C function call below which sets */
1884 /* up the htab. This is done because we have relocated the */
1885 /* kernel but are still running in real mode. */
1886
David Gibsone58c3492006-01-13 14:56:25 +11001887 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001888 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001889
1890 /* set up a stack pointer (physical address) */
1891 addi r1,r3,THREAD_SIZE
1892 li r0,0
1893 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1894
1895 /* set up the TOC (physical address) */
David Gibsone58c3492006-01-13 14:56:25 +11001896 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001897 addi r2,r2,0x4000
1898 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001899 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001900
David Gibsone58c3492006-01-13 14:56:25 +11001901 LOAD_REG_IMMEDIATE(r3, cpu_specs)
Paul Mackerras5a408322005-10-10 22:41:25 +10001902 add r3,r3,r26
David Gibsone58c3492006-01-13 14:56:25 +11001903 LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
Paul Mackerras5a408322005-10-10 22:41:25 +10001904 add r4,r4,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001905 mr r5,r26
1906 bl .identify_cpu
1907
1908 /* Save some low level config HIDs of CPU0 to be copied to
1909 * other CPUs later on, or used for suspend/resume
1910 */
1911 bl .__save_cpu_setup
1912 sync
1913
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001914 /* Do very early kernel initializations, including initial hash table,
1915 * stab and slb setup before we turn on relocation. */
1916
1917 /* Restore parameters passed from prom_init/kexec */
1918 mr r3,r31
1919 bl .early_setup
1920
David Gibsone58c3492006-01-13 14:56:25 +11001921 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1922 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001923 mtspr SPRN_SRR0,r3
1924 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001925 rfid
1926 b . /* prevent speculative execution */
1927#endif /* CONFIG_PPC_MULTIPLATFORM */
1928
1929 /* This is where all platforms converge execution */
1930_STATIC(start_here_common)
1931 /* relocation is on at this point */
1932
1933 /* The following code sets up the SP and TOC now that we are */
1934 /* running with translation enabled. */
1935
David Gibsone58c3492006-01-13 14:56:25 +11001936 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001937
1938 /* set up the stack */
1939 addi r1,r3,THREAD_SIZE
1940 li r0,0
1941 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1942
1943 /* Apply the CPUs-specific fixups (nop out sections not relevant
1944 * to this CPU
1945 */
1946 li r3,0
1947 bl .do_cpu_ftr_fixups
1948
David Gibsone58c3492006-01-13 14:56:25 +11001949 LOAD_REG_IMMEDIATE(r26, boot_cpuid)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001950 lwz r26,0(r26)
1951
David Gibsone58c3492006-01-13 14:56:25 +11001952 LOAD_REG_IMMEDIATE(r24, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001953 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1954 add r13,r13,r24 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001955 mtspr SPRN_SPRG3,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001956
1957 /* ptr to current */
David Gibsone58c3492006-01-13 14:56:25 +11001958 LOAD_REG_IMMEDIATE(r4, init_task)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001959 std r4,PACACURRENT(r13)
1960
1961 /* Load the TOC */
1962 ld r2,PACATOC(r13)
1963 std r1,PACAKSAVE(r13)
1964
1965 bl .setup_system
1966
1967 /* Load up the kernel context */
19685:
1969#ifdef DO_SOFT_DISABLE
1970 li r5,0
1971 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1972 mfmsr r5
1973 ori r5,r5,MSR_EE /* Hard Enabled */
1974 mtmsrd r5
1975#endif
1976
1977 bl .start_kernel
1978
Anton Blanchardf1870f72006-02-13 18:11:13 +11001979 /* Not reached */
1980 BUG_OPCODE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001981
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001982/*
1983 * We put a few things here that have to be page-aligned.
1984 * This stuff goes at the beginning of the bss, which is page-aligned.
1985 */
1986 .section ".bss"
1987
1988 .align PAGE_SHIFT
1989
1990 .globl empty_zero_page
1991empty_zero_page:
1992 .space PAGE_SIZE
1993
1994 .globl swapper_pg_dir
1995swapper_pg_dir:
1996 .space PAGE_SIZE
1997
1998/*
1999 * This space gets a copy of optional info passed to us by the bootstrap
2000 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2001 */
2002 .globl cmd_line
2003cmd_line:
2004 .space COMMAND_LINE_SIZE