blob: f4194f5fd2e5d5fa3376b6f0f5000a4f9ca7661d [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
2 * arch/ppc64/kernel/head.S
3 *
4 * PowerPC version
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
7 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
8 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
9 * Adapted for Power Macintosh by Paul Mackerras.
10 * Low-level exception handlers and MMU support
11 * rewritten by Paul Mackerras.
12 * Copyright (C) 1996 Paul Mackerras.
13 *
14 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
15 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
16 *
17 * This file contains the low-level support and setup for the
18 * PowerPC-64 platform, including trap and interrupt dispatch.
19 *
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version
23 * 2 of the License, or (at your option) any later version.
24 */
25
26#include <linux/config.h>
27#include <linux/threads.h>
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100028#include <asm/reg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100029#include <asm/page.h>
30#include <asm/mmu.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100031#include <asm/ppc_asm.h>
32#include <asm/asm-offsets.h>
33#include <asm/bug.h>
34#include <asm/cputable.h>
35#include <asm/setup.h>
36#include <asm/hvcall.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110037#include <asm/iseries/lpar_map.h>
David Gibson6cb7bfe2005-10-21 15:45:50 +100038#include <asm/thread_info.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100039
40#ifdef CONFIG_PPC_ISERIES
41#define DO_SOFT_DISABLE
42#endif
43
44/*
45 * We layout physical memory as follows:
46 * 0x0000 - 0x00ff : Secondary processor spin code
47 * 0x0100 - 0x2fff : pSeries Interrupt prologs
48 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
49 * 0x6000 - 0x6fff : Initial (CPU0) segment table
50 * 0x7000 - 0x7fff : FWNMI data area
51 * 0x8000 - : Early init and support code
52 */
53
54/*
55 * SPRG Usage
56 *
57 * Register Definition
58 *
59 * SPRG0 reserved for hypervisor
60 * SPRG1 temp - used to save gpr
61 * SPRG2 temp - used to save gpr
62 * SPRG3 virt addr of paca
63 */
64
65/*
66 * Entering into this code we make the following assumptions:
67 * For pSeries:
68 * 1. The MMU is off & open firmware is running in real mode.
69 * 2. The kernel is entered at __start
70 *
71 * For iSeries:
72 * 1. The MMU is on (as it always is for iSeries)
73 * 2. The kernel is entered at system_reset_iSeries
74 */
75
76 .text
77 .globl _stext
78_stext:
79#ifdef CONFIG_PPC_MULTIPLATFORM
80_GLOBAL(__start)
81 /* NOP this out unconditionally */
82BEGIN_FTR_SECTION
Paul Mackerrasb85a0462005-10-06 10:59:19 +100083 b .__start_initialization_multiplatform
Paul Mackerras14cf11a2005-09-26 16:04:21 +100084END_FTR_SECTION(0, 1)
85#endif /* CONFIG_PPC_MULTIPLATFORM */
86
87 /* Catch branch to 0 in real mode */
88 trap
89
90#ifdef CONFIG_PPC_ISERIES
91 /*
92 * At offset 0x20, there is a pointer to iSeries LPAR data.
93 * This is required by the hypervisor
94 */
95 . = 0x20
96 .llong hvReleaseData-KERNELBASE
97
98 /*
99 * At offset 0x28 and 0x30 are offsets to the mschunks_map
100 * array (used by the iSeries LPAR debugger to do translation
101 * between physical addresses and absolute addresses) and
102 * to the pidhash table (also used by the debugger)
103 */
104 .llong mschunks_map-KERNELBASE
105 .llong 0 /* pidhash-KERNELBASE SFRXXX */
106
107 /* Offset 0x38 - Pointer to start of embedded System.map */
108 .globl embedded_sysmap_start
109embedded_sysmap_start:
110 .llong 0
111 /* Offset 0x40 - Pointer to end of embedded System.map */
112 .globl embedded_sysmap_end
113embedded_sysmap_end:
114 .llong 0
115
116#endif /* CONFIG_PPC_ISERIES */
117
118 /* Secondary processors spin on this value until it goes to 1. */
119 .globl __secondary_hold_spinloop
120__secondary_hold_spinloop:
121 .llong 0x0
122
123 /* Secondary processors write this value with their cpu # */
124 /* after they enter the spin loop immediately below. */
125 .globl __secondary_hold_acknowledge
126__secondary_hold_acknowledge:
127 .llong 0x0
128
129 . = 0x60
130/*
131 * The following code is used on pSeries to hold secondary processors
132 * in a spin loop after they have been freed from OpenFirmware, but
133 * before the bulk of the kernel has been relocated. This code
134 * is relocated to physical address 0x60 before prom_init is run.
135 * All of it must fit below the first exception vector at 0x100.
136 */
137_GLOBAL(__secondary_hold)
138 mfmsr r24
139 ori r24,r24,MSR_RI
140 mtmsrd r24 /* RI on */
141
142 /* Grab our linux cpu number */
143 mr r24,r3
144
145 /* Tell the master cpu we're here */
146 /* Relocation is off & we are located at an address less */
147 /* than 0x100, so only need to grab low order offset. */
148 std r24,__secondary_hold_acknowledge@l(0)
149 sync
150
151 /* All secondary cpus wait here until told to start. */
152100: ld r4,__secondary_hold_spinloop@l(0)
153 cmpdi 0,r4,1
154 bne 100b
155
156#ifdef CONFIG_HMT
157 b .hmt_init
158#else
159#ifdef CONFIG_SMP
160 mr r3,r24
161 b .pSeries_secondary_smp_init
162#else
163 BUG_OPCODE
164#endif
165#endif
166
167/* This value is used to mark exception frames on the stack. */
168 .section ".toc","aw"
169exception_marker:
170 .tc ID_72656773_68657265[TC],0x7265677368657265
171 .text
172
173/*
174 * The following macros define the code that appears as
175 * the prologue to each of the exception handlers. They
176 * are split into two parts to allow a single kernel binary
177 * to be used for pSeries and iSeries.
178 * LOL. One day... - paulus
179 */
180
181/*
182 * We make as much of the exception code common between native
183 * exception handlers (including pSeries LPAR) and iSeries LPAR
184 * implementations as possible.
185 */
186
187/*
188 * This is the start of the interrupt handlers for pSeries
189 * This code runs with relocation off.
190 */
191#define EX_R9 0
192#define EX_R10 8
193#define EX_R11 16
194#define EX_R12 24
195#define EX_R13 32
196#define EX_SRR0 40
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000197#define EX_DAR 48
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000198#define EX_DSISR 56
199#define EX_CCR 60
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100200#define EX_R3 64
201#define EX_LR 72
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000202
203#define EXCEPTION_PROLOG_PSERIES(area, label) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000204 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000205 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
206 std r10,area+EX_R10(r13); \
207 std r11,area+EX_R11(r13); \
208 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000209 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000210 std r9,area+EX_R13(r13); \
211 mfcr r9; \
212 clrrdi r12,r13,32; /* get high part of &label */ \
213 mfmsr r10; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000214 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000215 ori r12,r12,(label)@l; /* virt addr of handler */ \
216 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000217 mtspr SPRN_SRR0,r12; \
218 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
219 mtspr SPRN_SRR1,r10; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000220 rfid; \
221 b . /* prevent speculative execution */
222
223/*
224 * This is the start of the interrupt handlers for iSeries
225 * This code runs with relocation on.
226 */
227#define EXCEPTION_PROLOG_ISERIES_1(area) \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000228 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000229 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
230 std r10,area+EX_R10(r13); \
231 std r11,area+EX_R11(r13); \
232 std r12,area+EX_R12(r13); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000233 mfspr r9,SPRN_SPRG1; \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000234 std r9,area+EX_R13(r13); \
235 mfcr r9
236
237#define EXCEPTION_PROLOG_ISERIES_2 \
238 mfmsr r10; \
239 ld r11,PACALPPACA+LPPACASRR0(r13); \
240 ld r12,PACALPPACA+LPPACASRR1(r13); \
241 ori r10,r10,MSR_RI; \
242 mtmsrd r10,1
243
244/*
245 * The common exception prolog is used for all except a few exceptions
246 * such as a segment miss on a kernel address. We have to be prepared
247 * to take another exception from the point where we first touch the
248 * kernel stack onwards.
249 *
250 * On entry r13 points to the paca, r9-r13 are saved in the paca,
251 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
252 * SRR1, and relocation is on.
253 */
254#define EXCEPTION_PROLOG_COMMON(n, area) \
255 andi. r10,r12,MSR_PR; /* See if coming from user */ \
256 mr r10,r1; /* Save r1 */ \
257 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
258 beq- 1f; \
259 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
2601: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
261 bge- cr1,bad_stack; /* abort if it is */ \
262 std r9,_CCR(r1); /* save CR in stackframe */ \
263 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
264 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
265 std r10,0(r1); /* make stack chain pointer */ \
266 std r0,GPR0(r1); /* save r0 in stackframe */ \
267 std r10,GPR1(r1); /* save r1 in stackframe */ \
268 std r2,GPR2(r1); /* save r2 in stackframe */ \
269 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
270 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
271 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
272 ld r10,area+EX_R10(r13); \
273 std r9,GPR9(r1); \
274 std r10,GPR10(r1); \
275 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
276 ld r10,area+EX_R12(r13); \
277 ld r11,area+EX_R13(r13); \
278 std r9,GPR11(r1); \
279 std r10,GPR12(r1); \
280 std r11,GPR13(r1); \
281 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
282 mflr r9; /* save LR in stackframe */ \
283 std r9,_LINK(r1); \
284 mfctr r10; /* save CTR in stackframe */ \
285 std r10,_CTR(r1); \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000286 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000287 std r11,_XER(r1); \
288 li r9,(n)+1; \
289 std r9,_TRAP(r1); /* set trap number */ \
290 li r10,0; \
291 ld r11,exception_marker@toc(r2); \
292 std r10,RESULT(r1); /* clear regs->result */ \
293 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
294
295/*
296 * Exception vectors.
297 */
298#define STD_EXCEPTION_PSERIES(n, label) \
299 . = n; \
300 .globl label##_pSeries; \
301label##_pSeries: \
302 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000303 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000304 RUNLATCH_ON(r13); \
305 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
306
307#define STD_EXCEPTION_ISERIES(n, label, area) \
308 .globl label##_iSeries; \
309label##_iSeries: \
310 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000311 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000312 RUNLATCH_ON(r13); \
313 EXCEPTION_PROLOG_ISERIES_1(area); \
314 EXCEPTION_PROLOG_ISERIES_2; \
315 b label##_common
316
317#define MASKABLE_EXCEPTION_ISERIES(n, label) \
318 .globl label##_iSeries; \
319label##_iSeries: \
320 HMT_MEDIUM; \
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000321 mtspr SPRN_SPRG1,r13; /* save r13 */ \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000322 RUNLATCH_ON(r13); \
323 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
324 lbz r10,PACAPROCENABLED(r13); \
325 cmpwi 0,r10,0; \
326 beq- label##_iSeries_masked; \
327 EXCEPTION_PROLOG_ISERIES_2; \
328 b label##_common; \
329
330#ifdef DO_SOFT_DISABLE
331#define DISABLE_INTS \
332 lbz r10,PACAPROCENABLED(r13); \
333 li r11,0; \
334 std r10,SOFTE(r1); \
335 mfmsr r10; \
336 stb r11,PACAPROCENABLED(r13); \
337 ori r10,r10,MSR_EE; \
338 mtmsrd r10,1
339
340#define ENABLE_INTS \
341 lbz r10,PACAPROCENABLED(r13); \
342 mfmsr r11; \
343 std r10,SOFTE(r1); \
344 ori r11,r11,MSR_EE; \
345 mtmsrd r11,1
346
347#else /* hard enable/disable interrupts */
348#define DISABLE_INTS
349
350#define ENABLE_INTS \
351 ld r12,_MSR(r1); \
352 mfmsr r11; \
353 rlwimi r11,r12,0,MSR_EE; \
354 mtmsrd r11,1
355
356#endif
357
358#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
359 .align 7; \
360 .globl label##_common; \
361label##_common: \
362 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
363 DISABLE_INTS; \
364 bl .save_nvgprs; \
365 addi r3,r1,STACK_FRAME_OVERHEAD; \
366 bl hdlr; \
367 b .ret_from_except
368
369#define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
370 .align 7; \
371 .globl label##_common; \
372label##_common: \
373 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
374 DISABLE_INTS; \
375 addi r3,r1,STACK_FRAME_OVERHEAD; \
376 bl hdlr; \
377 b .ret_from_except_lite
378
379/*
380 * Start of pSeries system interrupt routines
381 */
382 . = 0x100
383 .globl __start_interrupts
384__start_interrupts:
385
386 STD_EXCEPTION_PSERIES(0x100, system_reset)
387
388 . = 0x200
389_machine_check_pSeries:
390 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000391 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000392 RUNLATCH_ON(r13)
393 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
394
395 . = 0x300
396 .globl data_access_pSeries
397data_access_pSeries:
398 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000399 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000400BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000401 mtspr SPRN_SPRG2,r12
402 mfspr r13,SPRN_DAR
403 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000404 srdi r13,r13,60
405 rlwimi r13,r12,16,0x20
406 mfcr r12
407 cmpwi r13,0x2c
408 beq .do_stab_bolted_pSeries
409 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000410 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000411END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
412 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
413
414 . = 0x380
415 .globl data_access_slb_pSeries
416data_access_slb_pSeries:
417 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000418 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000419 RUNLATCH_ON(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000420 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100421 std r3,PACA_EXSLB+EX_R3(r13)
422 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000423 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100424 mfcr r9
425#ifdef __DISABLED__
426 /* Keep that around for when we re-implement dynamic VSIDs */
427 cmpdi r3,0
428 bge slb_miss_user_pseries
429#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000430 std r10,PACA_EXSLB+EX_R10(r13)
431 std r11,PACA_EXSLB+EX_R11(r13)
432 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100433 mfspr r10,SPRN_SPRG1
434 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000435 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100436 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000437
438 STD_EXCEPTION_PSERIES(0x400, instruction_access)
439
440 . = 0x480
441 .globl instruction_access_slb_pSeries
442instruction_access_slb_pSeries:
443 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000444 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000445 RUNLATCH_ON(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000446 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100447 std r3,PACA_EXSLB+EX_R3(r13)
448 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000449 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100450 mfcr r9
451#ifdef __DISABLED__
452 /* Keep that around for when we re-implement dynamic VSIDs */
453 cmpdi r3,0
454 bge slb_miss_user_pseries
455#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000456 std r10,PACA_EXSLB+EX_R10(r13)
457 std r11,PACA_EXSLB+EX_R11(r13)
458 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100459 mfspr r10,SPRN_SPRG1
460 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000461 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100462 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000463
464 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
465 STD_EXCEPTION_PSERIES(0x600, alignment)
466 STD_EXCEPTION_PSERIES(0x700, program_check)
467 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
468 STD_EXCEPTION_PSERIES(0x900, decrementer)
469 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
470 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
471
472 . = 0xc00
473 .globl system_call_pSeries
474system_call_pSeries:
475 HMT_MEDIUM
476 RUNLATCH_ON(r9)
477 mr r9,r13
478 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000479 mfspr r13,SPRN_SPRG3
480 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000481 clrrdi r12,r13,32
482 oris r12,r12,system_call_common@h
483 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000484 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000485 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000486 mfspr r12,SPRN_SRR1
487 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000488 rfid
489 b . /* prevent speculative execution */
490
491 STD_EXCEPTION_PSERIES(0xd00, single_step)
492 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
493
494 /* We need to deal with the Altivec unavailable exception
495 * here which is at 0xf20, thus in the middle of the
496 * prolog code of the PerformanceMonitor one. A little
497 * trickery is thus necessary
498 */
499 . = 0xf00
500 b performance_monitor_pSeries
501
502 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
503
504 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
505 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
506
507 . = 0x3000
508
509/*** pSeries interrupt support ***/
510
511 /* moved from 0xf00 */
512 STD_EXCEPTION_PSERIES(., performance_monitor)
513
514 .align 7
515_GLOBAL(do_stab_bolted_pSeries)
516 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000517 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000518 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
519
520/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100521 * We have some room here we use that to put
522 * the peries slb miss user trampoline code so it's reasonably
523 * away from slb_miss_user_common to avoid problems with rfid
524 *
525 * This is used for when the SLB miss handler has to go virtual,
526 * which doesn't happen for now anymore but will once we re-implement
527 * dynamic VSIDs for shared page tables
528 */
529#ifdef __DISABLED__
530slb_miss_user_pseries:
531 std r10,PACA_EXGEN+EX_R10(r13)
532 std r11,PACA_EXGEN+EX_R11(r13)
533 std r12,PACA_EXGEN+EX_R12(r13)
534 mfspr r10,SPRG1
535 ld r11,PACA_EXSLB+EX_R9(r13)
536 ld r12,PACA_EXSLB+EX_R3(r13)
537 std r10,PACA_EXGEN+EX_R13(r13)
538 std r11,PACA_EXGEN+EX_R9(r13)
539 std r12,PACA_EXGEN+EX_R3(r13)
540 clrrdi r12,r13,32
541 mfmsr r10
542 mfspr r11,SRR0 /* save SRR0 */
543 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
544 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
545 mtspr SRR0,r12
546 mfspr r12,SRR1 /* and SRR1 */
547 mtspr SRR1,r10
548 rfid
549 b . /* prevent spec. execution */
550#endif /* __DISABLED__ */
551
552/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000553 * Vectors for the FWNMI option. Share common code.
554 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000555 .globl system_reset_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100556 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000557system_reset_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000558 HMT_MEDIUM
559 mtspr SPRN_SPRG1,r13 /* save r13 */
560 RUNLATCH_ON(r13)
561 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000562
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000563 .globl machine_check_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100564 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000565machine_check_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000566 HMT_MEDIUM
567 mtspr SPRN_SPRG1,r13 /* save r13 */
568 RUNLATCH_ON(r13)
569 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000570
571#ifdef CONFIG_PPC_ISERIES
572/*** ISeries-LPAR interrupt handlers ***/
573
574 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
575
576 .globl data_access_iSeries
577data_access_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000578 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000579BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000580 mtspr SPRN_SPRG2,r12
581 mfspr r13,SPRN_DAR
582 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000583 srdi r13,r13,60
584 rlwimi r13,r12,16,0x20
585 mfcr r12
586 cmpwi r13,0x2c
587 beq .do_stab_bolted_iSeries
588 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000589 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000590END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
591 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
592 EXCEPTION_PROLOG_ISERIES_2
593 b data_access_common
594
595.do_stab_bolted_iSeries:
596 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000597 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000598 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
599 EXCEPTION_PROLOG_ISERIES_2
600 b .do_stab_bolted
601
602 .globl data_access_slb_iSeries
603data_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000604 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100605 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000606 std r3,PACA_EXSLB+EX_R3(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000607 mfspr r3,SPRN_DAR
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100608 std r9,PACA_EXSLB+EX_R9(r13)
609 mfcr r9
610#ifdef __DISABLED__
611 cmpdi r3,0
612 bge slb_miss_user_iseries
613#endif
614 std r10,PACA_EXSLB+EX_R10(r13)
615 std r11,PACA_EXSLB+EX_R11(r13)
616 std r12,PACA_EXSLB+EX_R12(r13)
617 mfspr r10,SPRN_SPRG1
618 std r10,PACA_EXSLB+EX_R13(r13)
619 ld r12,PACALPPACA+LPPACASRR1(r13);
620 b .slb_miss_realmode
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000621
622 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
623
624 .globl instruction_access_slb_iSeries
625instruction_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000626 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100627 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000628 std r3,PACA_EXSLB+EX_R3(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100629 ld r3,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
630 std r9,PACA_EXSLB+EX_R9(r13)
631 mfcr r9
632#ifdef __DISABLED__
633 cmpdi r3,0
634 bge .slb_miss_user_iseries
635#endif
636 std r10,PACA_EXSLB+EX_R10(r13)
637 std r11,PACA_EXSLB+EX_R11(r13)
638 std r12,PACA_EXSLB+EX_R12(r13)
639 mfspr r10,SPRN_SPRG1
640 std r10,PACA_EXSLB+EX_R13(r13)
641 ld r12,PACALPPACA+LPPACASRR1(r13);
642 b .slb_miss_realmode
643
644#ifdef __DISABLED__
645slb_miss_user_iseries:
646 std r10,PACA_EXGEN+EX_R10(r13)
647 std r11,PACA_EXGEN+EX_R11(r13)
648 std r12,PACA_EXGEN+EX_R12(r13)
649 mfspr r10,SPRG1
650 ld r11,PACA_EXSLB+EX_R9(r13)
651 ld r12,PACA_EXSLB+EX_R3(r13)
652 std r10,PACA_EXGEN+EX_R13(r13)
653 std r11,PACA_EXGEN+EX_R9(r13)
654 std r12,PACA_EXGEN+EX_R3(r13)
655 EXCEPTION_PROLOG_ISERIES_2
656 b slb_miss_user_common
657#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000658
659 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
660 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
661 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
662 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
663 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
664 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
665 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
666
667 .globl system_call_iSeries
668system_call_iSeries:
669 mr r9,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000670 mfspr r13,SPRN_SPRG3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000671 EXCEPTION_PROLOG_ISERIES_2
672 b system_call_common
673
674 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
675 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
676 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
677
678 .globl system_reset_iSeries
679system_reset_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000680 mfspr r13,SPRN_SPRG3 /* Get paca address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000681 mfmsr r24
682 ori r24,r24,MSR_RI
683 mtmsrd r24 /* RI on */
684 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
685 cmpwi 0,r24,0 /* Are we processor 0? */
686 beq .__start_initialization_iSeries /* Start up the first processor */
687 mfspr r4,SPRN_CTRLF
688 li r5,CTRL_RUNLATCH /* Turn off the run light */
689 andc r4,r4,r5
690 mtspr SPRN_CTRLT,r4
691
6921:
693 HMT_LOW
694#ifdef CONFIG_SMP
695 lbz r23,PACAPROCSTART(r13) /* Test if this processor
696 * should start */
697 sync
698 LOADADDR(r3,current_set)
699 sldi r28,r24,3 /* get current_set[cpu#] */
700 ldx r3,r3,r28
701 addi r1,r3,THREAD_SIZE
702 subi r1,r1,STACK_FRAME_OVERHEAD
703
704 cmpwi 0,r23,0
705 beq iSeries_secondary_smp_loop /* Loop until told to go */
706 bne .__secondary_start /* Loop until told to go */
707iSeries_secondary_smp_loop:
708 /* Let the Hypervisor know we are alive */
709 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
710 lis r3,0x8002
711 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
712#else /* CONFIG_SMP */
713 /* Yield the processor. This is required for non-SMP kernels
714 which are running on multi-threaded machines. */
715 lis r3,0x8000
716 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
717 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
718 li r4,0 /* "yield timed" */
719 li r5,-1 /* "yield forever" */
720#endif /* CONFIG_SMP */
721 li r0,-1 /* r0=-1 indicates a Hypervisor call */
722 sc /* Invoke the hypervisor via a system call */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000723 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000724 b 1b /* If SMP not configured, secondaries
725 * loop forever */
726
727 .globl decrementer_iSeries_masked
728decrementer_iSeries_masked:
729 li r11,1
730 stb r11,PACALPPACA+LPPACADECRINT(r13)
David Gibson404849b2005-11-24 16:51:31 +1100731 LOADBASE(r12,tb_ticks_per_jiffy)
Paul Mackerras4693c092005-12-07 14:52:16 +1100732 lwz r12,OFF(tb_ticks_per_jiffy)(r12)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000733 mtspr SPRN_DEC,r12
734 /* fall through */
735
736 .globl hardware_interrupt_iSeries_masked
737hardware_interrupt_iSeries_masked:
738 mtcrf 0x80,r9 /* Restore regs */
739 ld r11,PACALPPACA+LPPACASRR0(r13)
740 ld r12,PACALPPACA+LPPACASRR1(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000741 mtspr SPRN_SRR0,r11
742 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000743 ld r9,PACA_EXGEN+EX_R9(r13)
744 ld r10,PACA_EXGEN+EX_R10(r13)
745 ld r11,PACA_EXGEN+EX_R11(r13)
746 ld r12,PACA_EXGEN+EX_R12(r13)
747 ld r13,PACA_EXGEN+EX_R13(r13)
748 rfid
749 b . /* prevent speculative execution */
750#endif /* CONFIG_PPC_ISERIES */
751
752/*** Common interrupt handlers ***/
753
754 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
755
756 /*
757 * Machine check is different because we use a different
758 * save area: PACA_EXMC instead of PACA_EXGEN.
759 */
760 .align 7
761 .globl machine_check_common
762machine_check_common:
763 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
764 DISABLE_INTS
765 bl .save_nvgprs
766 addi r3,r1,STACK_FRAME_OVERHEAD
767 bl .machine_check_exception
768 b .ret_from_except
769
770 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
771 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
772 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
773 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
774 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
775 STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
776 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
777#ifdef CONFIG_ALTIVEC
778 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
779#else
780 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
781#endif
782
783/*
784 * Here we have detected that the kernel stack pointer is bad.
785 * R9 contains the saved CR, r13 points to the paca,
786 * r10 contains the (bad) kernel stack pointer,
787 * r11 and r12 contain the saved SRR0 and SRR1.
788 * We switch to using an emergency stack, save the registers there,
789 * and call kernel_bad_stack(), which panics.
790 */
791bad_stack:
792 ld r1,PACAEMERGSP(r13)
793 subi r1,r1,64+INT_FRAME_SIZE
794 std r9,_CCR(r1)
795 std r10,GPR1(r1)
796 std r11,_NIP(r1)
797 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000798 mfspr r11,SPRN_DAR
799 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000800 std r11,_DAR(r1)
801 std r12,_DSISR(r1)
802 mflr r10
803 mfctr r11
804 mfxer r12
805 std r10,_LINK(r1)
806 std r11,_CTR(r1)
807 std r12,_XER(r1)
808 SAVE_GPR(0,r1)
809 SAVE_GPR(2,r1)
810 SAVE_4GPRS(3,r1)
811 SAVE_2GPRS(7,r1)
812 SAVE_10GPRS(12,r1)
813 SAVE_10GPRS(22,r1)
814 addi r11,r1,INT_FRAME_SIZE
815 std r11,0(r1)
816 li r12,0
817 std r12,0(r11)
818 ld r2,PACATOC(r13)
8191: addi r3,r1,STACK_FRAME_OVERHEAD
820 bl .kernel_bad_stack
821 b 1b
822
823/*
824 * Return from an exception with minimal checks.
825 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
826 * If interrupts have been enabled, or anything has been
827 * done that might have changed the scheduling status of
828 * any task or sent any task a signal, you should use
829 * ret_from_except or ret_from_except_lite instead of this.
830 */
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000831 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000832fast_exception_return:
833 ld r12,_MSR(r1)
834 ld r11,_NIP(r1)
835 andi. r3,r12,MSR_RI /* check if RI is set */
836 beq- unrecov_fer
837 ld r3,_CCR(r1)
838 ld r4,_LINK(r1)
839 ld r5,_CTR(r1)
840 ld r6,_XER(r1)
841 mtcr r3
842 mtlr r4
843 mtctr r5
844 mtxer r6
845 REST_GPR(0, r1)
846 REST_8GPRS(2, r1)
847
848 mfmsr r10
849 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
850 mtmsrd r10,1
851
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000852 mtspr SPRN_SRR1,r12
853 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000854 REST_4GPRS(10, r1)
855 ld r1,GPR1(r1)
856 rfid
857 b . /* prevent speculative execution */
858
859unrecov_fer:
860 bl .save_nvgprs
8611: addi r3,r1,STACK_FRAME_OVERHEAD
862 bl .unrecoverable_exception
863 b 1b
864
865/*
866 * Here r13 points to the paca, r9 contains the saved CR,
867 * SRR0 and SRR1 are saved in r11 and r12,
868 * r9 - r13 are saved in paca->exgen.
869 */
870 .align 7
871 .globl data_access_common
872data_access_common:
873 RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000874 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000875 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000876 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000877 stw r10,PACA_EXGEN+EX_DSISR(r13)
878 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
879 ld r3,PACA_EXGEN+EX_DAR(r13)
880 lwz r4,PACA_EXGEN+EX_DSISR(r13)
881 li r5,0x300
882 b .do_hash_page /* Try to handle as hpte fault */
883
884 .align 7
885 .globl instruction_access_common
886instruction_access_common:
887 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
888 ld r3,_NIP(r1)
889 andis. r4,r12,0x5820
890 li r5,0x400
891 b .do_hash_page /* Try to handle as hpte fault */
892
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100893/*
894 * Here is the common SLB miss user that is used when going to virtual
895 * mode for SLB misses, that is currently not used
896 */
897#ifdef __DISABLED__
898 .align 7
899 .globl slb_miss_user_common
900slb_miss_user_common:
901 mflr r10
902 std r3,PACA_EXGEN+EX_DAR(r13)
903 stw r9,PACA_EXGEN+EX_CCR(r13)
904 std r10,PACA_EXGEN+EX_LR(r13)
905 std r11,PACA_EXGEN+EX_SRR0(r13)
906 bl .slb_allocate_user
907
908 ld r10,PACA_EXGEN+EX_LR(r13)
909 ld r3,PACA_EXGEN+EX_R3(r13)
910 lwz r9,PACA_EXGEN+EX_CCR(r13)
911 ld r11,PACA_EXGEN+EX_SRR0(r13)
912 mtlr r10
913 beq- slb_miss_fault
914
915 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
916 beq- unrecov_user_slb
917 mfmsr r10
918
919.machine push
920.machine "power4"
921 mtcrf 0x80,r9
922.machine pop
923
924 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
925 mtmsrd r10,1
926
927 mtspr SRR0,r11
928 mtspr SRR1,r12
929
930 ld r9,PACA_EXGEN+EX_R9(r13)
931 ld r10,PACA_EXGEN+EX_R10(r13)
932 ld r11,PACA_EXGEN+EX_R11(r13)
933 ld r12,PACA_EXGEN+EX_R12(r13)
934 ld r13,PACA_EXGEN+EX_R13(r13)
935 rfid
936 b .
937
938slb_miss_fault:
939 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
940 ld r4,PACA_EXGEN+EX_DAR(r13)
941 li r5,0
942 std r4,_DAR(r1)
943 std r5,_DSISR(r1)
944 b .handle_page_fault
945
946unrecov_user_slb:
947 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
948 DISABLE_INTS
949 bl .save_nvgprs
9501: addi r3,r1,STACK_FRAME_OVERHEAD
951 bl .unrecoverable_exception
952 b 1b
953
954#endif /* __DISABLED__ */
955
956
957/*
958 * r13 points to the PACA, r9 contains the saved CR,
959 * r12 contain the saved SRR1, SRR0 is still ready for return
960 * r3 has the faulting address
961 * r9 - r13 are saved in paca->exslb.
962 * r3 is saved in paca->slb_r3
963 * We assume we aren't going to take any exceptions during this procedure.
964 */
965_GLOBAL(slb_miss_realmode)
966 mflr r10
967
968 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
969 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
970
971 bl .slb_allocate_realmode
972
973 /* All done -- return from exception. */
974
975 ld r10,PACA_EXSLB+EX_LR(r13)
976 ld r3,PACA_EXSLB+EX_R3(r13)
977 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
978#ifdef CONFIG_PPC_ISERIES
979 ld r11,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
980#endif /* CONFIG_PPC_ISERIES */
981
982 mtlr r10
983
984 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
985 beq- unrecov_slb
986
987.machine push
988.machine "power4"
989 mtcrf 0x80,r9
990 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
991.machine pop
992
993#ifdef CONFIG_PPC_ISERIES
994 mtspr SPRN_SRR0,r11
995 mtspr SPRN_SRR1,r12
996#endif /* CONFIG_PPC_ISERIES */
997 ld r9,PACA_EXSLB+EX_R9(r13)
998 ld r10,PACA_EXSLB+EX_R10(r13)
999 ld r11,PACA_EXSLB+EX_R11(r13)
1000 ld r12,PACA_EXSLB+EX_R12(r13)
1001 ld r13,PACA_EXSLB+EX_R13(r13)
1002 rfid
1003 b . /* prevent speculative execution */
1004
1005unrecov_slb:
1006 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1007 DISABLE_INTS
1008 bl .save_nvgprs
10091: addi r3,r1,STACK_FRAME_OVERHEAD
1010 bl .unrecoverable_exception
1011 b 1b
1012
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001013 .align 7
1014 .globl hardware_interrupt_common
1015 .globl hardware_interrupt_entry
1016hardware_interrupt_common:
1017 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1018hardware_interrupt_entry:
1019 DISABLE_INTS
1020 addi r3,r1,STACK_FRAME_OVERHEAD
1021 bl .do_IRQ
1022 b .ret_from_except_lite
1023
1024 .align 7
1025 .globl alignment_common
1026alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001027 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001028 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001029 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001030 stw r10,PACA_EXGEN+EX_DSISR(r13)
1031 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1032 ld r3,PACA_EXGEN+EX_DAR(r13)
1033 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1034 std r3,_DAR(r1)
1035 std r4,_DSISR(r1)
1036 bl .save_nvgprs
1037 addi r3,r1,STACK_FRAME_OVERHEAD
1038 ENABLE_INTS
1039 bl .alignment_exception
1040 b .ret_from_except
1041
1042 .align 7
1043 .globl program_check_common
1044program_check_common:
1045 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1046 bl .save_nvgprs
1047 addi r3,r1,STACK_FRAME_OVERHEAD
1048 ENABLE_INTS
1049 bl .program_check_exception
1050 b .ret_from_except
1051
1052 .align 7
1053 .globl fp_unavailable_common
1054fp_unavailable_common:
1055 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1056 bne .load_up_fpu /* if from user, just load it up */
1057 bl .save_nvgprs
1058 addi r3,r1,STACK_FRAME_OVERHEAD
1059 ENABLE_INTS
1060 bl .kernel_fp_unavailable_exception
1061 BUG_OPCODE
1062
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001063 .align 7
1064 .globl altivec_unavailable_common
1065altivec_unavailable_common:
1066 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1067#ifdef CONFIG_ALTIVEC
1068BEGIN_FTR_SECTION
1069 bne .load_up_altivec /* if from user, just load it up */
1070END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1071#endif
1072 bl .save_nvgprs
1073 addi r3,r1,STACK_FRAME_OVERHEAD
1074 ENABLE_INTS
1075 bl .altivec_unavailable_exception
1076 b .ret_from_except
1077
1078#ifdef CONFIG_ALTIVEC
1079/*
1080 * load_up_altivec(unused, unused, tsk)
1081 * Disable VMX for the task which had it previously,
1082 * and save its vector registers in its thread_struct.
1083 * Enables the VMX for use in the kernel on return.
1084 * On SMP we know the VMX is free, since we give it up every
1085 * switch (ie, no lazy save of the vector registers).
1086 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1087 */
1088_STATIC(load_up_altivec)
1089 mfmsr r5 /* grab the current MSR */
1090 oris r5,r5,MSR_VEC@h
1091 mtmsrd r5 /* enable use of VMX now */
1092 isync
1093
1094/*
1095 * For SMP, we don't do lazy VMX switching because it just gets too
1096 * horrendously complex, especially when a task switches from one CPU
1097 * to another. Instead we call giveup_altvec in switch_to.
1098 * VRSAVE isn't dealt with here, that is done in the normal context
1099 * switch code. Note that we could rely on vrsave value to eventually
1100 * avoid saving all of the VREGs here...
1101 */
1102#ifndef CONFIG_SMP
1103 ld r3,last_task_used_altivec@got(r2)
1104 ld r4,0(r3)
1105 cmpdi 0,r4,0
1106 beq 1f
1107 /* Save VMX state to last_task_used_altivec's THREAD struct */
1108 addi r4,r4,THREAD
1109 SAVE_32VRS(0,r5,r4)
1110 mfvscr vr0
1111 li r10,THREAD_VSCR
1112 stvx vr0,r10,r4
1113 /* Disable VMX for last_task_used_altivec */
1114 ld r5,PT_REGS(r4)
1115 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1116 lis r6,MSR_VEC@h
1117 andc r4,r4,r6
1118 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
11191:
1120#endif /* CONFIG_SMP */
1121 /* Hack: if we get an altivec unavailable trap with VRSAVE
1122 * set to all zeros, we assume this is a broken application
1123 * that fails to set it properly, and thus we switch it to
1124 * all 1's
1125 */
1126 mfspr r4,SPRN_VRSAVE
1127 cmpdi 0,r4,0
1128 bne+ 1f
1129 li r4,-1
1130 mtspr SPRN_VRSAVE,r4
11311:
1132 /* enable use of VMX after return */
1133 ld r4,PACACURRENT(r13)
1134 addi r5,r4,THREAD /* Get THREAD */
1135 oris r12,r12,MSR_VEC@h
1136 std r12,_MSR(r1)
1137 li r4,1
1138 li r10,THREAD_VSCR
1139 stw r4,THREAD_USED_VR(r5)
1140 lvx vr0,r10,r5
1141 mtvscr vr0
1142 REST_32VRS(0,r4,r5)
1143#ifndef CONFIG_SMP
1144 /* Update last_task_used_math to 'current' */
1145 subi r4,r5,THREAD /* Back to 'current' */
1146 std r4,0(r3)
1147#endif /* CONFIG_SMP */
1148 /* restore registers and return */
1149 b fast_exception_return
1150#endif /* CONFIG_ALTIVEC */
1151
1152/*
1153 * Hash table stuff
1154 */
1155 .align 7
1156_GLOBAL(do_hash_page)
1157 std r3,_DAR(r1)
1158 std r4,_DSISR(r1)
1159
1160 andis. r0,r4,0xa450 /* weird error? */
1161 bne- .handle_page_fault /* if not, try to insert a HPTE */
1162BEGIN_FTR_SECTION
1163 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1164 bne- .do_ste_alloc /* If so handle it */
1165END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1166
1167 /*
1168 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1169 * accessing a userspace segment (even from the kernel). We assume
1170 * kernel addresses always have the high bit set.
1171 */
1172 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1173 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1174 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1175 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1176 ori r4,r4,1 /* add _PAGE_PRESENT */
1177 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1178
1179 /*
1180 * On iSeries, we soft-disable interrupts here, then
1181 * hard-enable interrupts so that the hash_page code can spin on
1182 * the hash_table_lock without problems on a shared processor.
1183 */
1184 DISABLE_INTS
1185
1186 /*
1187 * r3 contains the faulting address
1188 * r4 contains the required access permissions
1189 * r5 contains the trap number
1190 *
1191 * at return r3 = 0 for success
1192 */
1193 bl .hash_page /* build HPTE if possible */
1194 cmpdi r3,0 /* see if hash_page succeeded */
1195
1196#ifdef DO_SOFT_DISABLE
1197 /*
1198 * If we had interrupts soft-enabled at the point where the
1199 * DSI/ISI occurred, and an interrupt came in during hash_page,
1200 * handle it now.
1201 * We jump to ret_from_except_lite rather than fast_exception_return
1202 * because ret_from_except_lite will check for and handle pending
1203 * interrupts if necessary.
1204 */
1205 beq .ret_from_except_lite
1206 /* For a hash failure, we don't bother re-enabling interrupts */
1207 ble- 12f
1208
1209 /*
1210 * hash_page couldn't handle it, set soft interrupt enable back
1211 * to what it was before the trap. Note that .local_irq_restore
1212 * handles any interrupts pending at this point.
1213 */
1214 ld r3,SOFTE(r1)
1215 bl .local_irq_restore
1216 b 11f
1217#else
1218 beq fast_exception_return /* Return from exception on success */
1219 ble- 12f /* Failure return from hash_page */
1220
1221 /* fall through */
1222#endif
1223
1224/* Here we have a page fault that hash_page can't handle. */
1225_GLOBAL(handle_page_fault)
1226 ENABLE_INTS
122711: ld r4,_DAR(r1)
1228 ld r5,_DSISR(r1)
1229 addi r3,r1,STACK_FRAME_OVERHEAD
1230 bl .do_page_fault
1231 cmpdi r3,0
1232 beq+ .ret_from_except_lite
1233 bl .save_nvgprs
1234 mr r5,r3
1235 addi r3,r1,STACK_FRAME_OVERHEAD
1236 lwz r4,_DAR(r1)
1237 bl .bad_page_fault
1238 b .ret_from_except
1239
1240/* We have a page fault that hash_page could handle but HV refused
1241 * the PTE insertion
1242 */
124312: bl .save_nvgprs
1244 addi r3,r1,STACK_FRAME_OVERHEAD
1245 lwz r4,_DAR(r1)
1246 bl .low_hash_fault
1247 b .ret_from_except
1248
1249 /* here we have a segment miss */
1250_GLOBAL(do_ste_alloc)
1251 bl .ste_allocate /* try to insert stab entry */
1252 cmpdi r3,0
1253 beq+ fast_exception_return
1254 b .handle_page_fault
1255
1256/*
1257 * r13 points to the PACA, r9 contains the saved CR,
1258 * r11 and r12 contain the saved SRR0 and SRR1.
1259 * r9 - r13 are saved in paca->exslb.
1260 * We assume we aren't going to take any exceptions during this procedure.
1261 * We assume (DAR >> 60) == 0xc.
1262 */
1263 .align 7
1264_GLOBAL(do_stab_bolted)
1265 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1266 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1267
1268 /* Hash to the primary group */
1269 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001270 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001271 srdi r11,r11,28
1272 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1273
1274 /* Calculate VSID */
1275 /* This is a kernel address, so protovsid = ESID */
1276 ASM_VSID_SCRAMBLE(r11, r9)
1277 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1278
1279 /* Search the primary group for a free entry */
12801: ld r11,0(r10) /* Test valid bit of the current ste */
1281 andi. r11,r11,0x80
1282 beq 2f
1283 addi r10,r10,16
1284 andi. r11,r10,0x70
1285 bne 1b
1286
1287 /* Stick for only searching the primary group for now. */
1288 /* At least for now, we use a very simple random castout scheme */
1289 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1290 mftb r11
1291 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1292 ori r11,r11,0x10
1293
1294 /* r10 currently points to an ste one past the group of interest */
1295 /* make it point to the randomly selected entry */
1296 subi r10,r10,128
1297 or r10,r10,r11 /* r10 is the entry to invalidate */
1298
1299 isync /* mark the entry invalid */
1300 ld r11,0(r10)
1301 rldicl r11,r11,56,1 /* clear the valid bit */
1302 rotldi r11,r11,8
1303 std r11,0(r10)
1304 sync
1305
1306 clrrdi r11,r11,28 /* Get the esid part of the ste */
1307 slbie r11
1308
13092: std r9,8(r10) /* Store the vsid part of the ste */
1310 eieio
1311
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001312 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001313 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1314 ori r11,r11,0x90 /* Turn on valid and kp */
1315 std r11,0(r10) /* Put new entry back into the stab */
1316
1317 sync
1318
1319 /* All done -- return from exception. */
1320 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1321 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1322
1323 andi. r10,r12,MSR_RI
1324 beq- unrecov_slb
1325
1326 mtcrf 0x80,r9 /* restore CR */
1327
1328 mfmsr r10
1329 clrrdi r10,r10,2
1330 mtmsrd r10,1
1331
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001332 mtspr SPRN_SRR0,r11
1333 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001334 ld r9,PACA_EXSLB+EX_R9(r13)
1335 ld r10,PACA_EXSLB+EX_R10(r13)
1336 ld r11,PACA_EXSLB+EX_R11(r13)
1337 ld r12,PACA_EXSLB+EX_R12(r13)
1338 ld r13,PACA_EXSLB+EX_R13(r13)
1339 rfid
1340 b . /* prevent speculative execution */
1341
1342/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001343 * Space for CPU0's segment table.
1344 *
1345 * On iSeries, the hypervisor must fill in at least one entry before
1346 * we get control (with relocate on). The address is give to the hv
Stephen Rothwellee400b62005-09-29 11:50:22 +10001347 * as a page number (see xLparMap in lpardata.c), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001348 * fixed address (the linker can't compute (u64)&initial_stab >>
1349 * PAGE_SHIFT).
1350 */
1351 . = STAB0_PHYS_ADDR /* 0x6000 */
1352 .globl initial_stab
1353initial_stab:
1354 .space 4096
1355
1356/*
1357 * Data area reserved for FWNMI option.
1358 * This address (0x7000) is fixed by the RPA.
1359 */
1360 .= 0x7000
1361 .globl fwnmi_data_area
1362fwnmi_data_area:
1363
1364 /* iSeries does not use the FWNMI stuff, so it is safe to put
1365 * this here, even if we later allow kernels that will boot on
1366 * both pSeries and iSeries */
1367#ifdef CONFIG_PPC_ISERIES
1368 . = LPARMAP_PHYS
1369#include "lparmap.s"
1370/*
1371 * This ".text" is here for old compilers that generate a trailing
1372 * .note section when compiling .c files to .s
1373 */
1374 .text
1375#endif /* CONFIG_PPC_ISERIES */
1376
1377 . = 0x8000
1378
1379/*
1380 * On pSeries, secondary processors spin in the following code.
1381 * At entry, r3 = this processor's number (physical cpu id)
1382 */
1383_GLOBAL(pSeries_secondary_smp_init)
1384 mr r24,r3
1385
1386 /* turn on 64-bit mode */
1387 bl .enable_64b_mode
1388 isync
1389
1390 /* Copy some CPU settings from CPU 0 */
1391 bl .__restore_cpu_setup
1392
1393 /* Set up a paca value for this processor. Since we have the
1394 * physical cpu id in r24, we need to search the pacas to find
1395 * which logical id maps to our physical one.
1396 */
1397 LOADADDR(r13, paca) /* Get base vaddr of paca array */
1398 li r5,0 /* logical cpu id */
13991: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1400 cmpw r6,r24 /* Compare to our id */
1401 beq 2f
1402 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1403 addi r5,r5,1
1404 cmpwi r5,NR_CPUS
1405 blt 1b
1406
1407 mr r3,r24 /* not found, copy phys to r3 */
1408 b .kexec_wait /* next kernel might do better */
1409
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100014102: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001411 /* From now on, r24 is expected to be logical cpuid */
1412 mr r24,r5
14133: HMT_LOW
1414 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1415 /* start. */
1416 sync
1417
1418 /* Create a temp kernel stack for use before relocation is on. */
1419 ld r1,PACAEMERGSP(r13)
1420 subi r1,r1,STACK_FRAME_OVERHEAD
1421
1422 cmpwi 0,r23,0
1423#ifdef CONFIG_SMP
1424 bne .__secondary_start
1425#endif
1426 b 3b /* Loop until told to go */
1427
1428#ifdef CONFIG_PPC_ISERIES
1429_STATIC(__start_initialization_iSeries)
1430 /* Clear out the BSS */
1431 LOADADDR(r11,__bss_stop)
1432 LOADADDR(r8,__bss_start)
1433 sub r11,r11,r8 /* bss size */
1434 addi r11,r11,7 /* round up to an even double word */
1435 rldicl. r11,r11,61,3 /* shift right by 3 */
1436 beq 4f
1437 addi r8,r8,-8
1438 li r0,0
1439 mtctr r11 /* zero this many doublewords */
14403: stdu r0,8(r8)
1441 bdnz 3b
14424:
1443 LOADADDR(r1,init_thread_union)
1444 addi r1,r1,THREAD_SIZE
1445 li r0,0
1446 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1447
1448 LOADADDR(r3,cpu_specs)
1449 LOADADDR(r4,cur_cpu_spec)
1450 li r5,0
1451 bl .identify_cpu
1452
1453 LOADADDR(r2,__toc_start)
1454 addi r2,r2,0x4000
1455 addi r2,r2,0x4000
1456
1457 bl .iSeries_early_setup
Stephen Rothwellee400b62005-09-29 11:50:22 +10001458 bl .early_setup
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001459
1460 /* relocation is on at this point */
1461
1462 b .start_here_common
1463#endif /* CONFIG_PPC_ISERIES */
1464
1465#ifdef CONFIG_PPC_MULTIPLATFORM
1466
1467_STATIC(__mmu_off)
1468 mfmsr r3
1469 andi. r0,r3,MSR_IR|MSR_DR
1470 beqlr
1471 andc r3,r3,r0
1472 mtspr SPRN_SRR0,r4
1473 mtspr SPRN_SRR1,r3
1474 sync
1475 rfid
1476 b . /* prevent speculative execution */
1477
1478
1479/*
1480 * Here is our main kernel entry point. We support currently 2 kind of entries
1481 * depending on the value of r5.
1482 *
1483 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1484 * in r3...r7
1485 *
1486 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1487 * DT block, r4 is a physical pointer to the kernel itself
1488 *
1489 */
1490_GLOBAL(__start_initialization_multiplatform)
1491 /*
1492 * Are we booted from a PROM Of-type client-interface ?
1493 */
1494 cmpldi cr0,r5,0
1495 bne .__boot_from_prom /* yes -> prom */
1496
1497 /* Save parameters */
1498 mr r31,r3
1499 mr r30,r4
1500
1501 /* Make sure we are running in 64 bits mode */
1502 bl .enable_64b_mode
1503
1504 /* Setup some critical 970 SPRs before switching MMU off */
1505 bl .__970_cpu_preinit
1506
1507 /* cpu # */
1508 li r24,0
1509
1510 /* Switch off MMU if not already */
1511 LOADADDR(r4, .__after_prom_start - KERNELBASE)
1512 add r4,r4,r30
1513 bl .__mmu_off
1514 b .__after_prom_start
1515
1516_STATIC(__boot_from_prom)
1517 /* Save parameters */
1518 mr r31,r3
1519 mr r30,r4
1520 mr r29,r5
1521 mr r28,r6
1522 mr r27,r7
1523
1524 /* Make sure we are running in 64 bits mode */
1525 bl .enable_64b_mode
1526
1527 /* put a relocation offset into r3 */
1528 bl .reloc_offset
1529
1530 LOADADDR(r2,__toc_start)
1531 addi r2,r2,0x4000
1532 addi r2,r2,0x4000
1533
1534 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001535 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001536
1537 /* Restore parameters */
1538 mr r3,r31
1539 mr r4,r30
1540 mr r5,r29
1541 mr r6,r28
1542 mr r7,r27
1543
1544 /* Do all of the interaction with OF client interface */
1545 bl .prom_init
1546 /* We never return */
1547 trap
1548
1549/*
1550 * At this point, r3 contains the physical address we are running at,
1551 * returned by prom_init()
1552 */
1553_STATIC(__after_prom_start)
1554
1555/*
1556 * We need to run with __start at physical address 0.
1557 * This will leave some code in the first 256B of
1558 * real memory, which are reserved for software use.
1559 * The remainder of the first page is loaded with the fixed
1560 * interrupt vectors. The next two pages are filled with
1561 * unknown exception placeholders.
1562 *
1563 * Note: This process overwrites the OF exception vectors.
1564 * r26 == relocation offset
1565 * r27 == KERNELBASE
1566 */
1567 bl .reloc_offset
1568 mr r26,r3
1569 SET_REG_TO_CONST(r27,KERNELBASE)
1570
1571 li r3,0 /* target addr */
1572
1573 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001574 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001575 /* current address of _start */
1576 /* i.e. where we are running */
1577 /* the source addr */
1578
1579 LOADADDR(r5,copy_to_here) /* # bytes of memory to copy */
1580 sub r5,r5,r27
1581
1582 li r6,0x100 /* Start offset, the first 0x100 */
1583 /* bytes were copied earlier. */
1584
1585 bl .copy_and_flush /* copy the first n bytes */
1586 /* this includes the code being */
1587 /* executed here. */
1588
1589 LOADADDR(r0, 4f) /* Jump to the copy of this code */
1590 mtctr r0 /* that we just made/relocated */
1591 bctr
1592
15934: LOADADDR(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001594 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001595 ld r5,0(r5) /* get the value of klimit */
1596 sub r5,r5,r27
1597 bl .copy_and_flush /* copy the rest */
1598 b .start_here_multiplatform
1599
1600#endif /* CONFIG_PPC_MULTIPLATFORM */
1601
1602/*
1603 * Copy routine used to copy the kernel to start at physical address 0
1604 * and flush and invalidate the caches as needed.
1605 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1606 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1607 *
1608 * Note: this routine *only* clobbers r0, r6 and lr
1609 */
1610_GLOBAL(copy_and_flush)
1611 addi r5,r5,-8
1612 addi r6,r6,-8
16134: li r0,16 /* Use the least common */
1614 /* denominator cache line */
1615 /* size. This results in */
1616 /* extra cache line flushes */
1617 /* but operation is correct. */
1618 /* Can't get cache line size */
1619 /* from NACA as it is being */
1620 /* moved too. */
1621
1622 mtctr r0 /* put # words/line in ctr */
16233: addi r6,r6,8 /* copy a cache line */
1624 ldx r0,r6,r4
1625 stdx r0,r6,r3
1626 bdnz 3b
1627 dcbst r6,r3 /* write it to memory */
1628 sync
1629 icbi r6,r3 /* flush the icache line */
1630 cmpld 0,r6,r5
1631 blt 4b
1632 sync
1633 addi r5,r5,8
1634 addi r6,r6,8
1635 blr
1636
1637.align 8
1638copy_to_here:
1639
1640#ifdef CONFIG_SMP
1641#ifdef CONFIG_PPC_PMAC
1642/*
1643 * On PowerMac, secondary processors starts from the reset vector, which
1644 * is temporarily turned into a call to one of the functions below.
1645 */
1646 .section ".text";
1647 .align 2 ;
1648
Paul Mackerras35499c02005-10-22 16:02:39 +10001649 .globl __secondary_start_pmac_0
1650__secondary_start_pmac_0:
1651 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1652 li r24,0
1653 b 1f
1654 li r24,1
1655 b 1f
1656 li r24,2
1657 b 1f
1658 li r24,3
16591:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001660
1661_GLOBAL(pmac_secondary_start)
1662 /* turn on 64-bit mode */
1663 bl .enable_64b_mode
1664 isync
1665
1666 /* Copy some CPU settings from CPU 0 */
1667 bl .__restore_cpu_setup
1668
1669 /* pSeries do that early though I don't think we really need it */
1670 mfmsr r3
1671 ori r3,r3,MSR_RI
1672 mtmsrd r3 /* RI on */
1673
1674 /* Set up a paca value for this processor. */
1675 LOADADDR(r4, paca) /* Get base vaddr of paca array */
1676 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1677 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001678 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001679
1680 /* Create a temp kernel stack for use before relocation is on. */
1681 ld r1,PACAEMERGSP(r13)
1682 subi r1,r1,STACK_FRAME_OVERHEAD
1683
1684 b .__secondary_start
1685
1686#endif /* CONFIG_PPC_PMAC */
1687
1688/*
1689 * This function is called after the master CPU has released the
1690 * secondary processors. The execution environment is relocation off.
1691 * The paca for this processor has the following fields initialized at
1692 * this point:
1693 * 1. Processor number
1694 * 2. Segment table pointer (virtual address)
1695 * On entry the following are set:
1696 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1697 * r24 = cpu# (in Linux terms)
1698 * r13 = paca virtual address
1699 * SPRG3 = paca virtual address
1700 */
1701_GLOBAL(__secondary_start)
Paul Mackerras799d6042005-11-10 13:37:51 +11001702 /* Set thread priority to MEDIUM */
1703 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001704
Paul Mackerras799d6042005-11-10 13:37:51 +11001705 /* Load TOC */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001706 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001707
Paul Mackerras799d6042005-11-10 13:37:51 +11001708 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1709 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001710
1711 /* Initialize the kernel stack. Just a repeat for iSeries. */
1712 LOADADDR(r3,current_set)
1713 sldi r28,r24,3 /* get current_set[cpu#] */
1714 ldx r1,r3,r28
1715 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1716 std r1,PACAKSAVE(r13)
1717
Paul Mackerras799d6042005-11-10 13:37:51 +11001718 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001719 li r7,0
1720 mtlr r7
1721
1722 /* enable MMU and jump to start_secondary */
1723 LOADADDR(r3,.start_secondary_prolog)
1724 SET_REG_TO_CONST(r4, MSR_KERNEL)
1725#ifdef DO_SOFT_DISABLE
1726 ori r4,r4,MSR_EE
1727#endif
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001728 mtspr SPRN_SRR0,r3
1729 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001730 rfid
1731 b . /* prevent speculative execution */
1732
1733/*
1734 * Running with relocation on at this point. All we want to do is
1735 * zero the stack back-chain pointer before going into C code.
1736 */
1737_GLOBAL(start_secondary_prolog)
1738 li r3,0
1739 std r3,0(r1) /* Zero the stack frame pointer */
1740 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001741 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001742#endif
1743
1744/*
1745 * This subroutine clobbers r11 and r12
1746 */
1747_GLOBAL(enable_64b_mode)
1748 mfmsr r11 /* grab the current MSR */
1749 li r12,1
1750 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1751 or r11,r11,r12
1752 li r12,1
1753 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1754 or r11,r11,r12
1755 mtmsrd r11
1756 isync
1757 blr
1758
1759#ifdef CONFIG_PPC_MULTIPLATFORM
1760/*
1761 * This is where the main kernel code starts.
1762 */
1763_STATIC(start_here_multiplatform)
1764 /* get a new offset, now that the kernel has moved. */
1765 bl .reloc_offset
1766 mr r26,r3
1767
1768 /* Clear out the BSS. It may have been done in prom_init,
1769 * already but that's irrelevant since prom_init will soon
1770 * be detached from the kernel completely. Besides, we need
1771 * to clear it now for kexec-style entry.
1772 */
1773 LOADADDR(r11,__bss_stop)
1774 LOADADDR(r8,__bss_start)
1775 sub r11,r11,r8 /* bss size */
1776 addi r11,r11,7 /* round up to an even double word */
1777 rldicl. r11,r11,61,3 /* shift right by 3 */
1778 beq 4f
1779 addi r8,r8,-8
1780 li r0,0
1781 mtctr r11 /* zero this many doublewords */
17823: stdu r0,8(r8)
1783 bdnz 3b
17844:
1785
1786 mfmsr r6
1787 ori r6,r6,MSR_RI
1788 mtmsrd r6 /* RI on */
1789
1790#ifdef CONFIG_HMT
1791 /* Start up the second thread on cpu 0 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001792 mfspr r3,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001793 srwi r3,r3,16
1794 cmpwi r3,0x34 /* Pulsar */
1795 beq 90f
1796 cmpwi r3,0x36 /* Icestar */
1797 beq 90f
1798 cmpwi r3,0x37 /* SStar */
1799 beq 90f
1800 b 91f /* HMT not supported */
180190: li r3,0
1802 bl .hmt_start_secondary
180391:
1804#endif
1805
1806 /* The following gets the stack and TOC set up with the regs */
1807 /* pointing to the real addr of the kernel stack. This is */
1808 /* all done to support the C function call below which sets */
1809 /* up the htab. This is done because we have relocated the */
1810 /* kernel but are still running in real mode. */
1811
1812 LOADADDR(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001813 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001814
1815 /* set up a stack pointer (physical address) */
1816 addi r1,r3,THREAD_SIZE
1817 li r0,0
1818 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1819
1820 /* set up the TOC (physical address) */
1821 LOADADDR(r2,__toc_start)
1822 addi r2,r2,0x4000
1823 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001824 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001825
1826 LOADADDR(r3,cpu_specs)
Paul Mackerras5a408322005-10-10 22:41:25 +10001827 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001828 LOADADDR(r4,cur_cpu_spec)
Paul Mackerras5a408322005-10-10 22:41:25 +10001829 add r4,r4,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001830 mr r5,r26
1831 bl .identify_cpu
1832
1833 /* Save some low level config HIDs of CPU0 to be copied to
1834 * other CPUs later on, or used for suspend/resume
1835 */
1836 bl .__save_cpu_setup
1837 sync
1838
1839 /* Setup a valid physical PACA pointer in SPRG3 for early_setup
1840 * note that boot_cpuid can always be 0 nowadays since there is
1841 * nowhere it can be initialized differently before we reach this
1842 * code
1843 */
1844 LOADADDR(r27, boot_cpuid)
Paul Mackerras5a408322005-10-10 22:41:25 +10001845 add r27,r27,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001846 lwz r27,0(r27)
1847
1848 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1849 mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
1850 add r13,r13,r24 /* for this processor. */
Paul Mackerras5a408322005-10-10 22:41:25 +10001851 add r13,r13,r26 /* convert to physical addr */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001852 mtspr SPRN_SPRG3,r13 /* PPPBBB: Temp... -Peter */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001853
1854 /* Do very early kernel initializations, including initial hash table,
1855 * stab and slb setup before we turn on relocation. */
1856
1857 /* Restore parameters passed from prom_init/kexec */
1858 mr r3,r31
1859 bl .early_setup
1860
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001861 LOADADDR(r3,.start_here_common)
1862 SET_REG_TO_CONST(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001863 mtspr SPRN_SRR0,r3
1864 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001865 rfid
1866 b . /* prevent speculative execution */
1867#endif /* CONFIG_PPC_MULTIPLATFORM */
1868
1869 /* This is where all platforms converge execution */
1870_STATIC(start_here_common)
1871 /* relocation is on at this point */
1872
1873 /* The following code sets up the SP and TOC now that we are */
1874 /* running with translation enabled. */
1875
1876 LOADADDR(r3,init_thread_union)
1877
1878 /* set up the stack */
1879 addi r1,r3,THREAD_SIZE
1880 li r0,0
1881 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1882
1883 /* Apply the CPUs-specific fixups (nop out sections not relevant
1884 * to this CPU
1885 */
1886 li r3,0
1887 bl .do_cpu_ftr_fixups
1888
1889 LOADADDR(r26, boot_cpuid)
1890 lwz r26,0(r26)
1891
1892 LOADADDR(r24, paca) /* Get base vaddr of paca array */
1893 mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
1894 add r13,r13,r24 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001895 mtspr SPRN_SPRG3,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001896
1897 /* ptr to current */
1898 LOADADDR(r4,init_task)
1899 std r4,PACACURRENT(r13)
1900
1901 /* Load the TOC */
1902 ld r2,PACATOC(r13)
1903 std r1,PACAKSAVE(r13)
1904
1905 bl .setup_system
1906
1907 /* Load up the kernel context */
19085:
1909#ifdef DO_SOFT_DISABLE
1910 li r5,0
1911 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
1912 mfmsr r5
1913 ori r5,r5,MSR_EE /* Hard Enabled */
1914 mtmsrd r5
1915#endif
1916
1917 bl .start_kernel
1918
1919_GLOBAL(hmt_init)
1920#ifdef CONFIG_HMT
1921 LOADADDR(r5, hmt_thread_data)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001922 mfspr r7,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001923 srwi r7,r7,16
1924 cmpwi r7,0x34 /* Pulsar */
1925 beq 90f
1926 cmpwi r7,0x36 /* Icestar */
1927 beq 91f
1928 cmpwi r7,0x37 /* SStar */
1929 beq 91f
1930 b 101f
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000193190: mfspr r6,SPRN_PIR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001932 andi. r6,r6,0x1f
1933 b 92f
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000193491: mfspr r6,SPRN_PIR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001935 andi. r6,r6,0x3ff
193692: sldi r4,r24,3
1937 stwx r6,r5,r4
1938 bl .hmt_start_secondary
1939 b 101f
1940
1941__hmt_secondary_hold:
1942 LOADADDR(r5, hmt_thread_data)
1943 clrldi r5,r5,4
1944 li r7,0
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001945 mfspr r6,SPRN_PIR
1946 mfspr r8,SPRN_PVR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001947 srwi r8,r8,16
1948 cmpwi r8,0x34
1949 bne 93f
1950 andi. r6,r6,0x1f
1951 b 103f
195293: andi. r6,r6,0x3f
1953
1954103: lwzx r8,r5,r7
1955 cmpw r8,r6
1956 beq 104f
1957 addi r7,r7,8
1958 b 103b
1959
1960104: addi r7,r7,4
1961 lwzx r9,r5,r7
1962 mr r24,r9
1963101:
1964#endif
1965 mr r3,r24
1966 b .pSeries_secondary_smp_init
1967
1968#ifdef CONFIG_HMT
1969_GLOBAL(hmt_start_secondary)
1970 LOADADDR(r4,__hmt_secondary_hold)
1971 clrldi r4,r4,4
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001972 mtspr SPRN_NIADORM, r4
1973 mfspr r4, SPRN_MSRDORM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001974 li r5, -65
1975 and r4, r4, r5
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001976 mtspr SPRN_MSRDORM, r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001977 lis r4,0xffef
1978 ori r4,r4,0x7403
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001979 mtspr SPRN_TSC, r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001980 li r4,0x1f4
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001981 mtspr SPRN_TST, r4
1982 mfspr r4, SPRN_HID0
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001983 ori r4, r4, 0x1
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001984 mtspr SPRN_HID0, r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001985 mfspr r4, SPRN_CTRLF
1986 oris r4, r4, 0x40
1987 mtspr SPRN_CTRLT, r4
1988 blr
1989#endif
1990
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001991/*
1992 * We put a few things here that have to be page-aligned.
1993 * This stuff goes at the beginning of the bss, which is page-aligned.
1994 */
1995 .section ".bss"
1996
1997 .align PAGE_SHIFT
1998
1999 .globl empty_zero_page
2000empty_zero_page:
2001 .space PAGE_SIZE
2002
2003 .globl swapper_pg_dir
2004swapper_pg_dir:
2005 .space PAGE_SIZE
2006
2007/*
2008 * This space gets a copy of optional info passed to us by the bootstrap
2009 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2010 */
2011 .globl cmd_line
2012cmd_line:
2013 .space COMMAND_LINE_SIZE