[POWERPC] Consolidate feature fixup code
[deliverable/linux.git] / arch / powerpc / kernel / head_64.S
1 /*
2 * 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/threads.h>
25 #include <asm/reg.h>
26 #include <asm/page.h>
27 #include <asm/mmu.h>
28 #include <asm/ppc_asm.h>
29 #include <asm/asm-offsets.h>
30 #include <asm/bug.h>
31 #include <asm/cputable.h>
32 #include <asm/setup.h>
33 #include <asm/hvcall.h>
34 #include <asm/iseries/lpar_map.h>
35 #include <asm/thread_info.h>
36 #include <asm/firmware.h>
37
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 */
80 BEGIN_FTR_SECTION
81 b .__start_initialization_multiplatform
82 END_FTR_SECTION(0, 1)
83 #endif /* CONFIG_PPC_MULTIPLATFORM */
84
85 /* Catch branch to 0 in real mode */
86 trap
87
88 /* 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
99 #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
108 . = 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
121 /* Grab our physical cpu number */
122 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. */
131 100: ld r4,__secondary_hold_spinloop@l(0)
132 cmpdi 0,r4,1
133 bne 100b
134
135 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
136 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
137 mtctr r4
138 mr r3,r24
139 bctr
140 #else
141 BUG_OPCODE
142 #endif
143
144 /* This value is used to mark exception frames on the stack. */
145 .section ".toc","aw"
146 exception_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
174 #define EX_DAR 48
175 #define EX_DSISR 56
176 #define EX_CCR 60
177 #define EX_R3 64
178 #define EX_LR 72
179
180 /*
181 * 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.
185 */
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
195 /*
196 * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode.
197 * The firmware calls the registered system_reset_fwnmi and
198 * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run
199 * a 32bit application at the time of the event.
200 * This firmware bug is present on POWER4 and JS20.
201 */
202 #define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \
203 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
204 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
205 std r10,area+EX_R10(r13); \
206 std r11,area+EX_R11(r13); \
207 std r12,area+EX_R12(r13); \
208 mfspr r9,SPRN_SPRG1; \
209 std r9,area+EX_R13(r13); \
210 mfcr r9; \
211 clrrdi r12,r13,32; /* get high part of &label */ \
212 mfmsr r10; \
213 /* force 64bit mode */ \
214 li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \
215 rldimi r10,r11,61,0; /* insert into top 3 bits */ \
216 /* done 64bit mode */ \
217 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
218 LOAD_HANDLER(r12,label) \
219 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
220 mtspr SPRN_SRR0,r12; \
221 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
222 mtspr SPRN_SRR1,r10; \
223 rfid; \
224 b . /* prevent speculative execution */
225
226 #define EXCEPTION_PROLOG_PSERIES(area, label) \
227 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
228 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
229 std r10,area+EX_R10(r13); \
230 std r11,area+EX_R11(r13); \
231 std r12,area+EX_R12(r13); \
232 mfspr r9,SPRN_SPRG1; \
233 std r9,area+EX_R13(r13); \
234 mfcr r9; \
235 clrrdi r12,r13,32; /* get high part of &label */ \
236 mfmsr r10; \
237 mfspr r11,SPRN_SRR0; /* save SRR0 */ \
238 LOAD_HANDLER(r12,label) \
239 ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
240 mtspr SPRN_SRR0,r12; \
241 mfspr r12,SPRN_SRR1; /* and SRR1 */ \
242 mtspr SPRN_SRR1,r10; \
243 rfid; \
244 b . /* prevent speculative execution */
245
246 /*
247 * This is the start of the interrupt handlers for iSeries
248 * This code runs with relocation on.
249 */
250 #define EXCEPTION_PROLOG_ISERIES_1(area) \
251 mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
252 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
253 std r10,area+EX_R10(r13); \
254 std r11,area+EX_R11(r13); \
255 std r12,area+EX_R12(r13); \
256 mfspr r9,SPRN_SPRG1; \
257 std r9,area+EX_R13(r13); \
258 mfcr r9
259
260 #define EXCEPTION_PROLOG_ISERIES_2 \
261 mfmsr r10; \
262 ld r12,PACALPPACAPTR(r13); \
263 ld r11,LPPACASRR0(r12); \
264 ld r12,LPPACASRR1(r12); \
265 ori r10,r10,MSR_RI; \
266 mtmsrd r10,1
267
268 /*
269 * The common exception prolog is used for all except a few exceptions
270 * such as a segment miss on a kernel address. We have to be prepared
271 * to take another exception from the point where we first touch the
272 * kernel stack onwards.
273 *
274 * On entry r13 points to the paca, r9-r13 are saved in the paca,
275 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
276 * SRR1, and relocation is on.
277 */
278 #define EXCEPTION_PROLOG_COMMON(n, area) \
279 andi. r10,r12,MSR_PR; /* See if coming from user */ \
280 mr r10,r1; /* Save r1 */ \
281 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
282 beq- 1f; \
283 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
284 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
285 bge- cr1,bad_stack; /* abort if it is */ \
286 std r9,_CCR(r1); /* save CR in stackframe */ \
287 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
288 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
289 std r10,0(r1); /* make stack chain pointer */ \
290 std r0,GPR0(r1); /* save r0 in stackframe */ \
291 std r10,GPR1(r1); /* save r1 in stackframe */ \
292 ACCOUNT_CPU_USER_ENTRY(r9, r10); \
293 std r2,GPR2(r1); /* save r2 in stackframe */ \
294 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
295 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
296 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
297 ld r10,area+EX_R10(r13); \
298 std r9,GPR9(r1); \
299 std r10,GPR10(r1); \
300 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
301 ld r10,area+EX_R12(r13); \
302 ld r11,area+EX_R13(r13); \
303 std r9,GPR11(r1); \
304 std r10,GPR12(r1); \
305 std r11,GPR13(r1); \
306 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
307 mflr r9; /* save LR in stackframe */ \
308 std r9,_LINK(r1); \
309 mfctr r10; /* save CTR in stackframe */ \
310 std r10,_CTR(r1); \
311 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
312 std r11,_XER(r1); \
313 li r9,(n)+1; \
314 std r9,_TRAP(r1); /* set trap number */ \
315 li r10,0; \
316 ld r11,exception_marker@toc(r2); \
317 std r10,RESULT(r1); /* clear regs->result */ \
318 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
319
320 /*
321 * Exception vectors.
322 */
323 #define STD_EXCEPTION_PSERIES(n, label) \
324 . = n; \
325 .globl label##_pSeries; \
326 label##_pSeries: \
327 HMT_MEDIUM; \
328 mtspr SPRN_SPRG1,r13; /* save r13 */ \
329 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
330
331 #define HSTD_EXCEPTION_PSERIES(n, label) \
332 . = n; \
333 .globl label##_pSeries; \
334 label##_pSeries: \
335 HMT_MEDIUM; \
336 mtspr SPRN_SPRG1,r20; /* save r20 */ \
337 mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
338 mtspr SPRN_SRR0,r20; \
339 mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
340 mtspr SPRN_SRR1,r20; \
341 mfspr r20,SPRN_SPRG1; /* restore r20 */ \
342 mtspr SPRN_SPRG1,r13; /* save r13 */ \
343 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
344
345
346 #define STD_EXCEPTION_ISERIES(n, label, area) \
347 .globl label##_iSeries; \
348 label##_iSeries: \
349 HMT_MEDIUM; \
350 mtspr SPRN_SPRG1,r13; /* save r13 */ \
351 EXCEPTION_PROLOG_ISERIES_1(area); \
352 EXCEPTION_PROLOG_ISERIES_2; \
353 b label##_common
354
355 #define MASKABLE_EXCEPTION_ISERIES(n, label) \
356 .globl label##_iSeries; \
357 label##_iSeries: \
358 HMT_MEDIUM; \
359 mtspr SPRN_SPRG1,r13; /* save r13 */ \
360 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
361 lbz r10,PACAPROCENABLED(r13); \
362 cmpwi 0,r10,0; \
363 beq- label##_iSeries_masked; \
364 EXCEPTION_PROLOG_ISERIES_2; \
365 b label##_common; \
366
367 #ifdef DO_SOFT_DISABLE
368 #define DISABLE_INTS \
369 BEGIN_FW_FTR_SECTION; \
370 lbz r10,PACAPROCENABLED(r13); \
371 li r11,0; \
372 std r10,SOFTE(r1); \
373 mfmsr r10; \
374 stb r11,PACAPROCENABLED(r13); \
375 ori r10,r10,MSR_EE; \
376 mtmsrd r10,1; \
377 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
378
379 #define ENABLE_INTS \
380 BEGIN_FW_FTR_SECTION; \
381 lbz r10,PACAPROCENABLED(r13); \
382 mfmsr r11; \
383 std r10,SOFTE(r1); \
384 ori r11,r11,MSR_EE; \
385 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES); \
386 BEGIN_FW_FTR_SECTION; \
387 ld r12,_MSR(r1); \
388 mfmsr r11; \
389 rlwimi r11,r12,0,MSR_EE; \
390 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES); \
391 mtmsrd r11,1
392
393 #else /* hard enable/disable interrupts */
394 #define DISABLE_INTS
395
396 #define ENABLE_INTS \
397 ld r12,_MSR(r1); \
398 mfmsr r11; \
399 rlwimi r11,r12,0,MSR_EE; \
400 mtmsrd r11,1
401
402 #endif
403
404 #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
405 .align 7; \
406 .globl label##_common; \
407 label##_common: \
408 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
409 DISABLE_INTS; \
410 bl .save_nvgprs; \
411 addi r3,r1,STACK_FRAME_OVERHEAD; \
412 bl hdlr; \
413 b .ret_from_except
414
415 /*
416 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
417 * in the idle task and therefore need the special idle handling.
418 */
419 #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
420 .align 7; \
421 .globl label##_common; \
422 label##_common: \
423 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
424 FINISH_NAP; \
425 DISABLE_INTS; \
426 bl .save_nvgprs; \
427 addi r3,r1,STACK_FRAME_OVERHEAD; \
428 bl hdlr; \
429 b .ret_from_except
430
431 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
432 .align 7; \
433 .globl label##_common; \
434 label##_common: \
435 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
436 FINISH_NAP; \
437 DISABLE_INTS; \
438 bl .ppc64_runlatch_on; \
439 addi r3,r1,STACK_FRAME_OVERHEAD; \
440 bl hdlr; \
441 b .ret_from_except_lite
442
443 /*
444 * When the idle code in power4_idle puts the CPU into NAP mode,
445 * it has to do so in a loop, and relies on the external interrupt
446 * and decrementer interrupt entry code to get it out of the loop.
447 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
448 * to signal that it is in the loop and needs help to get out.
449 */
450 #ifdef CONFIG_PPC_970_NAP
451 #define FINISH_NAP \
452 BEGIN_FTR_SECTION \
453 clrrdi r11,r1,THREAD_SHIFT; \
454 ld r9,TI_LOCAL_FLAGS(r11); \
455 andi. r10,r9,_TLF_NAPPING; \
456 bnel power4_fixup_nap; \
457 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
458 #else
459 #define FINISH_NAP
460 #endif
461
462 /*
463 * Start of pSeries system interrupt routines
464 */
465 . = 0x100
466 .globl __start_interrupts
467 __start_interrupts:
468
469 STD_EXCEPTION_PSERIES(0x100, system_reset)
470
471 . = 0x200
472 _machine_check_pSeries:
473 HMT_MEDIUM
474 mtspr SPRN_SPRG1,r13 /* save r13 */
475 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
476
477 . = 0x300
478 .globl data_access_pSeries
479 data_access_pSeries:
480 HMT_MEDIUM
481 mtspr SPRN_SPRG1,r13
482 BEGIN_FTR_SECTION
483 mtspr SPRN_SPRG2,r12
484 mfspr r13,SPRN_DAR
485 mfspr r12,SPRN_DSISR
486 srdi r13,r13,60
487 rlwimi r13,r12,16,0x20
488 mfcr r12
489 cmpwi r13,0x2c
490 beq .do_stab_bolted_pSeries
491 mtcrf 0x80,r12
492 mfspr r12,SPRN_SPRG2
493 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
494 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
495
496 . = 0x380
497 .globl data_access_slb_pSeries
498 data_access_slb_pSeries:
499 HMT_MEDIUM
500 mtspr SPRN_SPRG1,r13
501 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
502 std r3,PACA_EXSLB+EX_R3(r13)
503 mfspr r3,SPRN_DAR
504 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
505 mfcr r9
506 #ifdef __DISABLED__
507 /* Keep that around for when we re-implement dynamic VSIDs */
508 cmpdi r3,0
509 bge slb_miss_user_pseries
510 #endif /* __DISABLED__ */
511 std r10,PACA_EXSLB+EX_R10(r13)
512 std r11,PACA_EXSLB+EX_R11(r13)
513 std r12,PACA_EXSLB+EX_R12(r13)
514 mfspr r10,SPRN_SPRG1
515 std r10,PACA_EXSLB+EX_R13(r13)
516 mfspr r12,SPRN_SRR1 /* and SRR1 */
517 b .slb_miss_realmode /* Rel. branch works in real mode */
518
519 STD_EXCEPTION_PSERIES(0x400, instruction_access)
520
521 . = 0x480
522 .globl instruction_access_slb_pSeries
523 instruction_access_slb_pSeries:
524 HMT_MEDIUM
525 mtspr SPRN_SPRG1,r13
526 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
527 std r3,PACA_EXSLB+EX_R3(r13)
528 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
529 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
530 mfcr r9
531 #ifdef __DISABLED__
532 /* Keep that around for when we re-implement dynamic VSIDs */
533 cmpdi r3,0
534 bge slb_miss_user_pseries
535 #endif /* __DISABLED__ */
536 std r10,PACA_EXSLB+EX_R10(r13)
537 std r11,PACA_EXSLB+EX_R11(r13)
538 std r12,PACA_EXSLB+EX_R12(r13)
539 mfspr r10,SPRN_SPRG1
540 std r10,PACA_EXSLB+EX_R13(r13)
541 mfspr r12,SPRN_SRR1 /* and SRR1 */
542 b .slb_miss_realmode /* Rel. branch works in real mode */
543
544 STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
545 STD_EXCEPTION_PSERIES(0x600, alignment)
546 STD_EXCEPTION_PSERIES(0x700, program_check)
547 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
548 STD_EXCEPTION_PSERIES(0x900, decrementer)
549 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
550 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
551
552 . = 0xc00
553 .globl system_call_pSeries
554 system_call_pSeries:
555 HMT_MEDIUM
556 mr r9,r13
557 mfmsr r10
558 mfspr r13,SPRN_SPRG3
559 mfspr r11,SPRN_SRR0
560 clrrdi r12,r13,32
561 oris r12,r12,system_call_common@h
562 ori r12,r12,system_call_common@l
563 mtspr SPRN_SRR0,r12
564 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
565 mfspr r12,SPRN_SRR1
566 mtspr SPRN_SRR1,r10
567 rfid
568 b . /* prevent speculative execution */
569
570 STD_EXCEPTION_PSERIES(0xd00, single_step)
571 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
572
573 /* We need to deal with the Altivec unavailable exception
574 * here which is at 0xf20, thus in the middle of the
575 * prolog code of the PerformanceMonitor one. A little
576 * trickery is thus necessary
577 */
578 . = 0xf00
579 b performance_monitor_pSeries
580
581 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
582
583 #ifdef CONFIG_CBE_RAS
584 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
585 #endif /* CONFIG_CBE_RAS */
586 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
587 #ifdef CONFIG_CBE_RAS
588 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
589 #endif /* CONFIG_CBE_RAS */
590 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
591 #ifdef CONFIG_CBE_RAS
592 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
593 #endif /* CONFIG_CBE_RAS */
594
595 . = 0x3000
596
597 /*** pSeries interrupt support ***/
598
599 /* moved from 0xf00 */
600 STD_EXCEPTION_PSERIES(., performance_monitor)
601
602 .align 7
603 _GLOBAL(do_stab_bolted_pSeries)
604 mtcrf 0x80,r12
605 mfspr r12,SPRN_SPRG2
606 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
607
608 /*
609 * We have some room here we use that to put
610 * the peries slb miss user trampoline code so it's reasonably
611 * away from slb_miss_user_common to avoid problems with rfid
612 *
613 * This is used for when the SLB miss handler has to go virtual,
614 * which doesn't happen for now anymore but will once we re-implement
615 * dynamic VSIDs for shared page tables
616 */
617 #ifdef __DISABLED__
618 slb_miss_user_pseries:
619 std r10,PACA_EXGEN+EX_R10(r13)
620 std r11,PACA_EXGEN+EX_R11(r13)
621 std r12,PACA_EXGEN+EX_R12(r13)
622 mfspr r10,SPRG1
623 ld r11,PACA_EXSLB+EX_R9(r13)
624 ld r12,PACA_EXSLB+EX_R3(r13)
625 std r10,PACA_EXGEN+EX_R13(r13)
626 std r11,PACA_EXGEN+EX_R9(r13)
627 std r12,PACA_EXGEN+EX_R3(r13)
628 clrrdi r12,r13,32
629 mfmsr r10
630 mfspr r11,SRR0 /* save SRR0 */
631 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
632 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
633 mtspr SRR0,r12
634 mfspr r12,SRR1 /* and SRR1 */
635 mtspr SRR1,r10
636 rfid
637 b . /* prevent spec. execution */
638 #endif /* __DISABLED__ */
639
640 /*
641 * Vectors for the FWNMI option. Share common code.
642 */
643 .globl system_reset_fwnmi
644 .align 7
645 system_reset_fwnmi:
646 HMT_MEDIUM
647 mtspr SPRN_SPRG1,r13 /* save r13 */
648 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
649
650 .globl machine_check_fwnmi
651 .align 7
652 machine_check_fwnmi:
653 HMT_MEDIUM
654 mtspr SPRN_SPRG1,r13 /* save r13 */
655 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
656
657 #ifdef CONFIG_PPC_ISERIES
658 /*** ISeries-LPAR interrupt handlers ***/
659
660 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
661
662 .globl data_access_iSeries
663 data_access_iSeries:
664 mtspr SPRN_SPRG1,r13
665 BEGIN_FTR_SECTION
666 mtspr SPRN_SPRG2,r12
667 mfspr r13,SPRN_DAR
668 mfspr r12,SPRN_DSISR
669 srdi r13,r13,60
670 rlwimi r13,r12,16,0x20
671 mfcr r12
672 cmpwi r13,0x2c
673 beq .do_stab_bolted_iSeries
674 mtcrf 0x80,r12
675 mfspr r12,SPRN_SPRG2
676 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
677 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
678 EXCEPTION_PROLOG_ISERIES_2
679 b data_access_common
680
681 .do_stab_bolted_iSeries:
682 mtcrf 0x80,r12
683 mfspr r12,SPRN_SPRG2
684 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
685 EXCEPTION_PROLOG_ISERIES_2
686 b .do_stab_bolted
687
688 .globl data_access_slb_iSeries
689 data_access_slb_iSeries:
690 mtspr SPRN_SPRG1,r13 /* save r13 */
691 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
692 std r3,PACA_EXSLB+EX_R3(r13)
693 mfspr r3,SPRN_DAR
694 std r9,PACA_EXSLB+EX_R9(r13)
695 mfcr r9
696 #ifdef __DISABLED__
697 cmpdi r3,0
698 bge slb_miss_user_iseries
699 #endif
700 std r10,PACA_EXSLB+EX_R10(r13)
701 std r11,PACA_EXSLB+EX_R11(r13)
702 std r12,PACA_EXSLB+EX_R12(r13)
703 mfspr r10,SPRN_SPRG1
704 std r10,PACA_EXSLB+EX_R13(r13)
705 ld r12,PACALPPACAPTR(r13)
706 ld r12,LPPACASRR1(r12)
707 b .slb_miss_realmode
708
709 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
710
711 .globl instruction_access_slb_iSeries
712 instruction_access_slb_iSeries:
713 mtspr SPRN_SPRG1,r13 /* save r13 */
714 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
715 std r3,PACA_EXSLB+EX_R3(r13)
716 ld r3,PACALPPACAPTR(r13)
717 ld r3,LPPACASRR0(r3) /* get SRR0 value */
718 std r9,PACA_EXSLB+EX_R9(r13)
719 mfcr r9
720 #ifdef __DISABLED__
721 cmpdi r3,0
722 bge .slb_miss_user_iseries
723 #endif
724 std r10,PACA_EXSLB+EX_R10(r13)
725 std r11,PACA_EXSLB+EX_R11(r13)
726 std r12,PACA_EXSLB+EX_R12(r13)
727 mfspr r10,SPRN_SPRG1
728 std r10,PACA_EXSLB+EX_R13(r13)
729 ld r12,PACALPPACAPTR(r13)
730 ld r12,LPPACASRR1(r12)
731 b .slb_miss_realmode
732
733 #ifdef __DISABLED__
734 slb_miss_user_iseries:
735 std r10,PACA_EXGEN+EX_R10(r13)
736 std r11,PACA_EXGEN+EX_R11(r13)
737 std r12,PACA_EXGEN+EX_R12(r13)
738 mfspr r10,SPRG1
739 ld r11,PACA_EXSLB+EX_R9(r13)
740 ld r12,PACA_EXSLB+EX_R3(r13)
741 std r10,PACA_EXGEN+EX_R13(r13)
742 std r11,PACA_EXGEN+EX_R9(r13)
743 std r12,PACA_EXGEN+EX_R3(r13)
744 EXCEPTION_PROLOG_ISERIES_2
745 b slb_miss_user_common
746 #endif
747
748 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
749 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
750 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
751 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
752 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
753 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
754 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
755
756 .globl system_call_iSeries
757 system_call_iSeries:
758 mr r9,r13
759 mfspr r13,SPRN_SPRG3
760 EXCEPTION_PROLOG_ISERIES_2
761 b system_call_common
762
763 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
764 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
765 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
766
767 .globl system_reset_iSeries
768 system_reset_iSeries:
769 mfspr r13,SPRN_SPRG3 /* Get paca address */
770 mfmsr r24
771 ori r24,r24,MSR_RI
772 mtmsrd r24 /* RI on */
773 lhz r24,PACAPACAINDEX(r13) /* Get processor # */
774 cmpwi 0,r24,0 /* Are we processor 0? */
775 beq .__start_initialization_iSeries /* Start up the first processor */
776 mfspr r4,SPRN_CTRLF
777 li r5,CTRL_RUNLATCH /* Turn off the run light */
778 andc r4,r4,r5
779 mtspr SPRN_CTRLT,r4
780
781 1:
782 HMT_LOW
783 #ifdef CONFIG_SMP
784 lbz r23,PACAPROCSTART(r13) /* Test if this processor
785 * should start */
786 sync
787 LOAD_REG_IMMEDIATE(r3,current_set)
788 sldi r28,r24,3 /* get current_set[cpu#] */
789 ldx r3,r3,r28
790 addi r1,r3,THREAD_SIZE
791 subi r1,r1,STACK_FRAME_OVERHEAD
792
793 cmpwi 0,r23,0
794 beq iSeries_secondary_smp_loop /* Loop until told to go */
795 bne .__secondary_start /* Loop until told to go */
796 iSeries_secondary_smp_loop:
797 /* Let the Hypervisor know we are alive */
798 /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
799 lis r3,0x8002
800 rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
801 #else /* CONFIG_SMP */
802 /* Yield the processor. This is required for non-SMP kernels
803 which are running on multi-threaded machines. */
804 lis r3,0x8000
805 rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
806 addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
807 li r4,0 /* "yield timed" */
808 li r5,-1 /* "yield forever" */
809 #endif /* CONFIG_SMP */
810 li r0,-1 /* r0=-1 indicates a Hypervisor call */
811 sc /* Invoke the hypervisor via a system call */
812 mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
813 b 1b /* If SMP not configured, secondaries
814 * loop forever */
815
816 .globl decrementer_iSeries_masked
817 decrementer_iSeries_masked:
818 /* We may not have a valid TOC pointer in here. */
819 li r11,1
820 ld r12,PACALPPACAPTR(r13)
821 stb r11,LPPACADECRINT(r12)
822 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
823 lwz r12,0(r12)
824 mtspr SPRN_DEC,r12
825 /* fall through */
826
827 .globl hardware_interrupt_iSeries_masked
828 hardware_interrupt_iSeries_masked:
829 mtcrf 0x80,r9 /* Restore regs */
830 ld r12,PACALPPACAPTR(r13)
831 ld r11,LPPACASRR0(r12)
832 ld r12,LPPACASRR1(r12)
833 mtspr SPRN_SRR0,r11
834 mtspr SPRN_SRR1,r12
835 ld r9,PACA_EXGEN+EX_R9(r13)
836 ld r10,PACA_EXGEN+EX_R10(r13)
837 ld r11,PACA_EXGEN+EX_R11(r13)
838 ld r12,PACA_EXGEN+EX_R12(r13)
839 ld r13,PACA_EXGEN+EX_R13(r13)
840 rfid
841 b . /* prevent speculative execution */
842 #endif /* CONFIG_PPC_ISERIES */
843
844 /*** Common interrupt handlers ***/
845
846 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
847
848 /*
849 * Machine check is different because we use a different
850 * save area: PACA_EXMC instead of PACA_EXGEN.
851 */
852 .align 7
853 .globl machine_check_common
854 machine_check_common:
855 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
856 FINISH_NAP
857 DISABLE_INTS
858 bl .save_nvgprs
859 addi r3,r1,STACK_FRAME_OVERHEAD
860 bl .machine_check_exception
861 b .ret_from_except
862
863 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
864 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
865 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
866 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
867 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
868 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
869 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
870 #ifdef CONFIG_ALTIVEC
871 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
872 #else
873 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
874 #endif
875 #ifdef CONFIG_CBE_RAS
876 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
877 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
878 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
879 #endif /* CONFIG_CBE_RAS */
880
881 /*
882 * Here we have detected that the kernel stack pointer is bad.
883 * R9 contains the saved CR, r13 points to the paca,
884 * r10 contains the (bad) kernel stack pointer,
885 * r11 and r12 contain the saved SRR0 and SRR1.
886 * We switch to using an emergency stack, save the registers there,
887 * and call kernel_bad_stack(), which panics.
888 */
889 bad_stack:
890 ld r1,PACAEMERGSP(r13)
891 subi r1,r1,64+INT_FRAME_SIZE
892 std r9,_CCR(r1)
893 std r10,GPR1(r1)
894 std r11,_NIP(r1)
895 std r12,_MSR(r1)
896 mfspr r11,SPRN_DAR
897 mfspr r12,SPRN_DSISR
898 std r11,_DAR(r1)
899 std r12,_DSISR(r1)
900 mflr r10
901 mfctr r11
902 mfxer r12
903 std r10,_LINK(r1)
904 std r11,_CTR(r1)
905 std r12,_XER(r1)
906 SAVE_GPR(0,r1)
907 SAVE_GPR(2,r1)
908 SAVE_4GPRS(3,r1)
909 SAVE_2GPRS(7,r1)
910 SAVE_10GPRS(12,r1)
911 SAVE_10GPRS(22,r1)
912 addi r11,r1,INT_FRAME_SIZE
913 std r11,0(r1)
914 li r12,0
915 std r12,0(r11)
916 ld r2,PACATOC(r13)
917 1: addi r3,r1,STACK_FRAME_OVERHEAD
918 bl .kernel_bad_stack
919 b 1b
920
921 /*
922 * Return from an exception with minimal checks.
923 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
924 * If interrupts have been enabled, or anything has been
925 * done that might have changed the scheduling status of
926 * any task or sent any task a signal, you should use
927 * ret_from_except or ret_from_except_lite instead of this.
928 */
929 .globl fast_exception_return
930 fast_exception_return:
931 ld r12,_MSR(r1)
932 ld r11,_NIP(r1)
933 andi. r3,r12,MSR_RI /* check if RI is set */
934 beq- unrecov_fer
935
936 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
937 andi. r3,r12,MSR_PR
938 beq 2f
939 ACCOUNT_CPU_USER_EXIT(r3, r4)
940 2:
941 #endif
942
943 ld r3,_CCR(r1)
944 ld r4,_LINK(r1)
945 ld r5,_CTR(r1)
946 ld r6,_XER(r1)
947 mtcr r3
948 mtlr r4
949 mtctr r5
950 mtxer r6
951 REST_GPR(0, r1)
952 REST_8GPRS(2, r1)
953
954 mfmsr r10
955 clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
956 mtmsrd r10,1
957
958 mtspr SPRN_SRR1,r12
959 mtspr SPRN_SRR0,r11
960 REST_4GPRS(10, r1)
961 ld r1,GPR1(r1)
962 rfid
963 b . /* prevent speculative execution */
964
965 unrecov_fer:
966 bl .save_nvgprs
967 1: addi r3,r1,STACK_FRAME_OVERHEAD
968 bl .unrecoverable_exception
969 b 1b
970
971 /*
972 * Here r13 points to the paca, r9 contains the saved CR,
973 * SRR0 and SRR1 are saved in r11 and r12,
974 * r9 - r13 are saved in paca->exgen.
975 */
976 .align 7
977 .globl data_access_common
978 data_access_common:
979 mfspr r10,SPRN_DAR
980 std r10,PACA_EXGEN+EX_DAR(r13)
981 mfspr r10,SPRN_DSISR
982 stw r10,PACA_EXGEN+EX_DSISR(r13)
983 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
984 ld r3,PACA_EXGEN+EX_DAR(r13)
985 lwz r4,PACA_EXGEN+EX_DSISR(r13)
986 li r5,0x300
987 b .do_hash_page /* Try to handle as hpte fault */
988
989 .align 7
990 .globl instruction_access_common
991 instruction_access_common:
992 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
993 ld r3,_NIP(r1)
994 andis. r4,r12,0x5820
995 li r5,0x400
996 b .do_hash_page /* Try to handle as hpte fault */
997
998 /*
999 * Here is the common SLB miss user that is used when going to virtual
1000 * mode for SLB misses, that is currently not used
1001 */
1002 #ifdef __DISABLED__
1003 .align 7
1004 .globl slb_miss_user_common
1005 slb_miss_user_common:
1006 mflr r10
1007 std r3,PACA_EXGEN+EX_DAR(r13)
1008 stw r9,PACA_EXGEN+EX_CCR(r13)
1009 std r10,PACA_EXGEN+EX_LR(r13)
1010 std r11,PACA_EXGEN+EX_SRR0(r13)
1011 bl .slb_allocate_user
1012
1013 ld r10,PACA_EXGEN+EX_LR(r13)
1014 ld r3,PACA_EXGEN+EX_R3(r13)
1015 lwz r9,PACA_EXGEN+EX_CCR(r13)
1016 ld r11,PACA_EXGEN+EX_SRR0(r13)
1017 mtlr r10
1018 beq- slb_miss_fault
1019
1020 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1021 beq- unrecov_user_slb
1022 mfmsr r10
1023
1024 .machine push
1025 .machine "power4"
1026 mtcrf 0x80,r9
1027 .machine pop
1028
1029 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1030 mtmsrd r10,1
1031
1032 mtspr SRR0,r11
1033 mtspr SRR1,r12
1034
1035 ld r9,PACA_EXGEN+EX_R9(r13)
1036 ld r10,PACA_EXGEN+EX_R10(r13)
1037 ld r11,PACA_EXGEN+EX_R11(r13)
1038 ld r12,PACA_EXGEN+EX_R12(r13)
1039 ld r13,PACA_EXGEN+EX_R13(r13)
1040 rfid
1041 b .
1042
1043 slb_miss_fault:
1044 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1045 ld r4,PACA_EXGEN+EX_DAR(r13)
1046 li r5,0
1047 std r4,_DAR(r1)
1048 std r5,_DSISR(r1)
1049 b .handle_page_fault
1050
1051 unrecov_user_slb:
1052 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1053 DISABLE_INTS
1054 bl .save_nvgprs
1055 1: addi r3,r1,STACK_FRAME_OVERHEAD
1056 bl .unrecoverable_exception
1057 b 1b
1058
1059 #endif /* __DISABLED__ */
1060
1061
1062 /*
1063 * r13 points to the PACA, r9 contains the saved CR,
1064 * r12 contain the saved SRR1, SRR0 is still ready for return
1065 * r3 has the faulting address
1066 * r9 - r13 are saved in paca->exslb.
1067 * r3 is saved in paca->slb_r3
1068 * We assume we aren't going to take any exceptions during this procedure.
1069 */
1070 _GLOBAL(slb_miss_realmode)
1071 mflr r10
1072
1073 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1074 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1075
1076 bl .slb_allocate_realmode
1077
1078 /* All done -- return from exception. */
1079
1080 ld r10,PACA_EXSLB+EX_LR(r13)
1081 ld r3,PACA_EXSLB+EX_R3(r13)
1082 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1083 #ifdef CONFIG_PPC_ISERIES
1084 BEGIN_FW_FTR_SECTION
1085 ld r11,PACALPPACAPTR(r13)
1086 ld r11,LPPACASRR0(r11) /* get SRR0 value */
1087 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1088 #endif /* CONFIG_PPC_ISERIES */
1089
1090 mtlr r10
1091
1092 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1093 beq- unrecov_slb
1094
1095 .machine push
1096 .machine "power4"
1097 mtcrf 0x80,r9
1098 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1099 .machine pop
1100
1101 #ifdef CONFIG_PPC_ISERIES
1102 BEGIN_FW_FTR_SECTION
1103 mtspr SPRN_SRR0,r11
1104 mtspr SPRN_SRR1,r12
1105 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1106 #endif /* CONFIG_PPC_ISERIES */
1107 ld r9,PACA_EXSLB+EX_R9(r13)
1108 ld r10,PACA_EXSLB+EX_R10(r13)
1109 ld r11,PACA_EXSLB+EX_R11(r13)
1110 ld r12,PACA_EXSLB+EX_R12(r13)
1111 ld r13,PACA_EXSLB+EX_R13(r13)
1112 rfid
1113 b . /* prevent speculative execution */
1114
1115 unrecov_slb:
1116 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1117 DISABLE_INTS
1118 bl .save_nvgprs
1119 1: addi r3,r1,STACK_FRAME_OVERHEAD
1120 bl .unrecoverable_exception
1121 b 1b
1122
1123 .align 7
1124 .globl hardware_interrupt_common
1125 .globl hardware_interrupt_entry
1126 hardware_interrupt_common:
1127 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1128 FINISH_NAP
1129 hardware_interrupt_entry:
1130 DISABLE_INTS
1131 bl .ppc64_runlatch_on
1132 addi r3,r1,STACK_FRAME_OVERHEAD
1133 bl .do_IRQ
1134 b .ret_from_except_lite
1135
1136 #ifdef CONFIG_PPC_970_NAP
1137 power4_fixup_nap:
1138 andc r9,r9,r10
1139 std r9,TI_LOCAL_FLAGS(r11)
1140 ld r10,_LINK(r1) /* make idle task do the */
1141 std r10,_NIP(r1) /* equivalent of a blr */
1142 blr
1143 #endif
1144
1145 .align 7
1146 .globl alignment_common
1147 alignment_common:
1148 mfspr r10,SPRN_DAR
1149 std r10,PACA_EXGEN+EX_DAR(r13)
1150 mfspr r10,SPRN_DSISR
1151 stw r10,PACA_EXGEN+EX_DSISR(r13)
1152 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1153 ld r3,PACA_EXGEN+EX_DAR(r13)
1154 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1155 std r3,_DAR(r1)
1156 std r4,_DSISR(r1)
1157 bl .save_nvgprs
1158 addi r3,r1,STACK_FRAME_OVERHEAD
1159 ENABLE_INTS
1160 bl .alignment_exception
1161 b .ret_from_except
1162
1163 .align 7
1164 .globl program_check_common
1165 program_check_common:
1166 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1167 bl .save_nvgprs
1168 addi r3,r1,STACK_FRAME_OVERHEAD
1169 ENABLE_INTS
1170 bl .program_check_exception
1171 b .ret_from_except
1172
1173 .align 7
1174 .globl fp_unavailable_common
1175 fp_unavailable_common:
1176 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1177 bne .load_up_fpu /* if from user, just load it up */
1178 bl .save_nvgprs
1179 addi r3,r1,STACK_FRAME_OVERHEAD
1180 ENABLE_INTS
1181 bl .kernel_fp_unavailable_exception
1182 BUG_OPCODE
1183
1184 .align 7
1185 .globl altivec_unavailable_common
1186 altivec_unavailable_common:
1187 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1188 #ifdef CONFIG_ALTIVEC
1189 BEGIN_FTR_SECTION
1190 bne .load_up_altivec /* if from user, just load it up */
1191 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1192 #endif
1193 bl .save_nvgprs
1194 addi r3,r1,STACK_FRAME_OVERHEAD
1195 ENABLE_INTS
1196 bl .altivec_unavailable_exception
1197 b .ret_from_except
1198
1199 #ifdef CONFIG_ALTIVEC
1200 /*
1201 * load_up_altivec(unused, unused, tsk)
1202 * Disable VMX for the task which had it previously,
1203 * and save its vector registers in its thread_struct.
1204 * Enables the VMX for use in the kernel on return.
1205 * On SMP we know the VMX is free, since we give it up every
1206 * switch (ie, no lazy save of the vector registers).
1207 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1208 */
1209 _STATIC(load_up_altivec)
1210 mfmsr r5 /* grab the current MSR */
1211 oris r5,r5,MSR_VEC@h
1212 mtmsrd r5 /* enable use of VMX now */
1213 isync
1214
1215 /*
1216 * For SMP, we don't do lazy VMX switching because it just gets too
1217 * horrendously complex, especially when a task switches from one CPU
1218 * to another. Instead we call giveup_altvec in switch_to.
1219 * VRSAVE isn't dealt with here, that is done in the normal context
1220 * switch code. Note that we could rely on vrsave value to eventually
1221 * avoid saving all of the VREGs here...
1222 */
1223 #ifndef CONFIG_SMP
1224 ld r3,last_task_used_altivec@got(r2)
1225 ld r4,0(r3)
1226 cmpdi 0,r4,0
1227 beq 1f
1228 /* Save VMX state to last_task_used_altivec's THREAD struct */
1229 addi r4,r4,THREAD
1230 SAVE_32VRS(0,r5,r4)
1231 mfvscr vr0
1232 li r10,THREAD_VSCR
1233 stvx vr0,r10,r4
1234 /* Disable VMX for last_task_used_altivec */
1235 ld r5,PT_REGS(r4)
1236 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1237 lis r6,MSR_VEC@h
1238 andc r4,r4,r6
1239 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1240 1:
1241 #endif /* CONFIG_SMP */
1242 /* Hack: if we get an altivec unavailable trap with VRSAVE
1243 * set to all zeros, we assume this is a broken application
1244 * that fails to set it properly, and thus we switch it to
1245 * all 1's
1246 */
1247 mfspr r4,SPRN_VRSAVE
1248 cmpdi 0,r4,0
1249 bne+ 1f
1250 li r4,-1
1251 mtspr SPRN_VRSAVE,r4
1252 1:
1253 /* enable use of VMX after return */
1254 ld r4,PACACURRENT(r13)
1255 addi r5,r4,THREAD /* Get THREAD */
1256 oris r12,r12,MSR_VEC@h
1257 std r12,_MSR(r1)
1258 li r4,1
1259 li r10,THREAD_VSCR
1260 stw r4,THREAD_USED_VR(r5)
1261 lvx vr0,r10,r5
1262 mtvscr vr0
1263 REST_32VRS(0,r4,r5)
1264 #ifndef CONFIG_SMP
1265 /* Update last_task_used_math to 'current' */
1266 subi r4,r5,THREAD /* Back to 'current' */
1267 std r4,0(r3)
1268 #endif /* CONFIG_SMP */
1269 /* restore registers and return */
1270 b fast_exception_return
1271 #endif /* CONFIG_ALTIVEC */
1272
1273 /*
1274 * Hash table stuff
1275 */
1276 .align 7
1277 _GLOBAL(do_hash_page)
1278 std r3,_DAR(r1)
1279 std r4,_DSISR(r1)
1280
1281 andis. r0,r4,0xa450 /* weird error? */
1282 bne- .handle_page_fault /* if not, try to insert a HPTE */
1283 BEGIN_FTR_SECTION
1284 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1285 bne- .do_ste_alloc /* If so handle it */
1286 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1287
1288 /*
1289 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1290 * accessing a userspace segment (even from the kernel). We assume
1291 * kernel addresses always have the high bit set.
1292 */
1293 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1294 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1295 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1296 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1297 ori r4,r4,1 /* add _PAGE_PRESENT */
1298 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1299
1300 /*
1301 * On iSeries, we soft-disable interrupts here, then
1302 * hard-enable interrupts so that the hash_page code can spin on
1303 * the hash_table_lock without problems on a shared processor.
1304 */
1305 DISABLE_INTS
1306
1307 /*
1308 * r3 contains the faulting address
1309 * r4 contains the required access permissions
1310 * r5 contains the trap number
1311 *
1312 * at return r3 = 0 for success
1313 */
1314 bl .hash_page /* build HPTE if possible */
1315 cmpdi r3,0 /* see if hash_page succeeded */
1316
1317 #ifdef DO_SOFT_DISABLE
1318 BEGIN_FW_FTR_SECTION
1319 /*
1320 * If we had interrupts soft-enabled at the point where the
1321 * DSI/ISI occurred, and an interrupt came in during hash_page,
1322 * handle it now.
1323 * We jump to ret_from_except_lite rather than fast_exception_return
1324 * because ret_from_except_lite will check for and handle pending
1325 * interrupts if necessary.
1326 */
1327 beq .ret_from_except_lite
1328 /* For a hash failure, we don't bother re-enabling interrupts */
1329 ble- 12f
1330
1331 /*
1332 * hash_page couldn't handle it, set soft interrupt enable back
1333 * to what it was before the trap. Note that .local_irq_restore
1334 * handles any interrupts pending at this point.
1335 */
1336 ld r3,SOFTE(r1)
1337 bl .local_irq_restore
1338 b 11f
1339 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1340 #endif
1341 BEGIN_FW_FTR_SECTION
1342 beq fast_exception_return /* Return from exception on success */
1343 ble- 12f /* Failure return from hash_page */
1344
1345 /* fall through */
1346 END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1347
1348 /* Here we have a page fault that hash_page can't handle. */
1349 _GLOBAL(handle_page_fault)
1350 ENABLE_INTS
1351 11: ld r4,_DAR(r1)
1352 ld r5,_DSISR(r1)
1353 addi r3,r1,STACK_FRAME_OVERHEAD
1354 bl .do_page_fault
1355 cmpdi r3,0
1356 beq+ .ret_from_except_lite
1357 bl .save_nvgprs
1358 mr r5,r3
1359 addi r3,r1,STACK_FRAME_OVERHEAD
1360 lwz r4,_DAR(r1)
1361 bl .bad_page_fault
1362 b .ret_from_except
1363
1364 /* We have a page fault that hash_page could handle but HV refused
1365 * the PTE insertion
1366 */
1367 12: bl .save_nvgprs
1368 addi r3,r1,STACK_FRAME_OVERHEAD
1369 lwz r4,_DAR(r1)
1370 bl .low_hash_fault
1371 b .ret_from_except
1372
1373 /* here we have a segment miss */
1374 _GLOBAL(do_ste_alloc)
1375 bl .ste_allocate /* try to insert stab entry */
1376 cmpdi r3,0
1377 beq+ fast_exception_return
1378 b .handle_page_fault
1379
1380 /*
1381 * r13 points to the PACA, r9 contains the saved CR,
1382 * r11 and r12 contain the saved SRR0 and SRR1.
1383 * r9 - r13 are saved in paca->exslb.
1384 * We assume we aren't going to take any exceptions during this procedure.
1385 * We assume (DAR >> 60) == 0xc.
1386 */
1387 .align 7
1388 _GLOBAL(do_stab_bolted)
1389 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1390 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1391
1392 /* Hash to the primary group */
1393 ld r10,PACASTABVIRT(r13)
1394 mfspr r11,SPRN_DAR
1395 srdi r11,r11,28
1396 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1397
1398 /* Calculate VSID */
1399 /* This is a kernel address, so protovsid = ESID */
1400 ASM_VSID_SCRAMBLE(r11, r9)
1401 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1402
1403 /* Search the primary group for a free entry */
1404 1: ld r11,0(r10) /* Test valid bit of the current ste */
1405 andi. r11,r11,0x80
1406 beq 2f
1407 addi r10,r10,16
1408 andi. r11,r10,0x70
1409 bne 1b
1410
1411 /* Stick for only searching the primary group for now. */
1412 /* At least for now, we use a very simple random castout scheme */
1413 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1414 mftb r11
1415 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1416 ori r11,r11,0x10
1417
1418 /* r10 currently points to an ste one past the group of interest */
1419 /* make it point to the randomly selected entry */
1420 subi r10,r10,128
1421 or r10,r10,r11 /* r10 is the entry to invalidate */
1422
1423 isync /* mark the entry invalid */
1424 ld r11,0(r10)
1425 rldicl r11,r11,56,1 /* clear the valid bit */
1426 rotldi r11,r11,8
1427 std r11,0(r10)
1428 sync
1429
1430 clrrdi r11,r11,28 /* Get the esid part of the ste */
1431 slbie r11
1432
1433 2: std r9,8(r10) /* Store the vsid part of the ste */
1434 eieio
1435
1436 mfspr r11,SPRN_DAR /* Get the new esid */
1437 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1438 ori r11,r11,0x90 /* Turn on valid and kp */
1439 std r11,0(r10) /* Put new entry back into the stab */
1440
1441 sync
1442
1443 /* All done -- return from exception. */
1444 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1445 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1446
1447 andi. r10,r12,MSR_RI
1448 beq- unrecov_slb
1449
1450 mtcrf 0x80,r9 /* restore CR */
1451
1452 mfmsr r10
1453 clrrdi r10,r10,2
1454 mtmsrd r10,1
1455
1456 mtspr SPRN_SRR0,r11
1457 mtspr SPRN_SRR1,r12
1458 ld r9,PACA_EXSLB+EX_R9(r13)
1459 ld r10,PACA_EXSLB+EX_R10(r13)
1460 ld r11,PACA_EXSLB+EX_R11(r13)
1461 ld r12,PACA_EXSLB+EX_R12(r13)
1462 ld r13,PACA_EXSLB+EX_R13(r13)
1463 rfid
1464 b . /* prevent speculative execution */
1465
1466 /*
1467 * Space for CPU0's segment table.
1468 *
1469 * On iSeries, the hypervisor must fill in at least one entry before
1470 * we get control (with relocate on). The address is give to the hv
1471 * as a page number (see xLparMap in lpardata.c), so this must be at a
1472 * fixed address (the linker can't compute (u64)&initial_stab >>
1473 * PAGE_SHIFT).
1474 */
1475 . = STAB0_OFFSET /* 0x6000 */
1476 .globl initial_stab
1477 initial_stab:
1478 .space 4096
1479
1480 /*
1481 * Data area reserved for FWNMI option.
1482 * This address (0x7000) is fixed by the RPA.
1483 */
1484 .= 0x7000
1485 .globl fwnmi_data_area
1486 fwnmi_data_area:
1487
1488 /* iSeries does not use the FWNMI stuff, so it is safe to put
1489 * this here, even if we later allow kernels that will boot on
1490 * both pSeries and iSeries */
1491 #ifdef CONFIG_PPC_ISERIES
1492 . = LPARMAP_PHYS
1493 #include "lparmap.s"
1494 /*
1495 * This ".text" is here for old compilers that generate a trailing
1496 * .note section when compiling .c files to .s
1497 */
1498 .text
1499 #endif /* CONFIG_PPC_ISERIES */
1500
1501 . = 0x8000
1502
1503 /*
1504 * On pSeries and most other platforms, secondary processors spin
1505 * in the following code.
1506 * At entry, r3 = this processor's number (physical cpu id)
1507 */
1508 _GLOBAL(generic_secondary_smp_init)
1509 mr r24,r3
1510
1511 /* turn on 64-bit mode */
1512 bl .enable_64b_mode
1513 isync
1514
1515 /* Set up a paca value for this processor. Since we have the
1516 * physical cpu id in r24, we need to search the pacas to find
1517 * which logical id maps to our physical one.
1518 */
1519 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
1520 li r5,0 /* logical cpu id */
1521 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1522 cmpw r6,r24 /* Compare to our id */
1523 beq 2f
1524 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1525 addi r5,r5,1
1526 cmpwi r5,NR_CPUS
1527 blt 1b
1528
1529 mr r3,r24 /* not found, copy phys to r3 */
1530 b .kexec_wait /* next kernel might do better */
1531
1532 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1533 /* From now on, r24 is expected to be logical cpuid */
1534 mr r24,r5
1535 3: HMT_LOW
1536 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1537 /* start. */
1538 sync
1539
1540 #ifndef CONFIG_SMP
1541 b 3b /* Never go on non-SMP */
1542 #else
1543 cmpwi 0,r23,0
1544 beq 3b /* Loop until told to go */
1545
1546 /* See if we need to call a cpu state restore handler */
1547 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1548 ld r23,0(r23)
1549 ld r23,CPU_SPEC_RESTORE(r23)
1550 cmpdi 0,r23,0
1551 beq 4f
1552 ld r23,0(r23)
1553 mtctr r23
1554 bctrl
1555
1556 4: /* Create a temp kernel stack for use before relocation is on. */
1557 ld r1,PACAEMERGSP(r13)
1558 subi r1,r1,STACK_FRAME_OVERHEAD
1559
1560 b .__secondary_start
1561 #endif
1562
1563 #ifdef CONFIG_PPC_ISERIES
1564 _STATIC(__start_initialization_iSeries)
1565 /* Clear out the BSS */
1566 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1567 LOAD_REG_IMMEDIATE(r8,__bss_start)
1568 sub r11,r11,r8 /* bss size */
1569 addi r11,r11,7 /* round up to an even double word */
1570 rldicl. r11,r11,61,3 /* shift right by 3 */
1571 beq 4f
1572 addi r8,r8,-8
1573 li r0,0
1574 mtctr r11 /* zero this many doublewords */
1575 3: stdu r0,8(r8)
1576 bdnz 3b
1577 4:
1578 LOAD_REG_IMMEDIATE(r1,init_thread_union)
1579 addi r1,r1,THREAD_SIZE
1580 li r0,0
1581 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1582
1583 LOAD_REG_IMMEDIATE(r2,__toc_start)
1584 addi r2,r2,0x4000
1585 addi r2,r2,0x4000
1586
1587 bl .iSeries_early_setup
1588 bl .early_setup
1589
1590 /* relocation is on at this point */
1591
1592 b .start_here_common
1593 #endif /* CONFIG_PPC_ISERIES */
1594
1595 #ifdef CONFIG_PPC_MULTIPLATFORM
1596
1597 _STATIC(__mmu_off)
1598 mfmsr r3
1599 andi. r0,r3,MSR_IR|MSR_DR
1600 beqlr
1601 andc r3,r3,r0
1602 mtspr SPRN_SRR0,r4
1603 mtspr SPRN_SRR1,r3
1604 sync
1605 rfid
1606 b . /* prevent speculative execution */
1607
1608
1609 /*
1610 * Here is our main kernel entry point. We support currently 2 kind of entries
1611 * depending on the value of r5.
1612 *
1613 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1614 * in r3...r7
1615 *
1616 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1617 * DT block, r4 is a physical pointer to the kernel itself
1618 *
1619 */
1620 _GLOBAL(__start_initialization_multiplatform)
1621 #ifdef CONFIG_PPC_MULTIPLATFORM
1622 /*
1623 * Are we booted from a PROM Of-type client-interface ?
1624 */
1625 cmpldi cr0,r5,0
1626 bne .__boot_from_prom /* yes -> prom */
1627 #endif
1628
1629 /* Save parameters */
1630 mr r31,r3
1631 mr r30,r4
1632
1633 /* Make sure we are running in 64 bits mode */
1634 bl .enable_64b_mode
1635
1636 /* Setup some critical 970 SPRs before switching MMU off */
1637 mfspr r0,SPRN_PVR
1638 srwi r0,r0,16
1639 cmpwi r0,0x39 /* 970 */
1640 beq 1f
1641 cmpwi r0,0x3c /* 970FX */
1642 beq 1f
1643 cmpwi r0,0x44 /* 970MP */
1644 bne 2f
1645 1: bl .__cpu_preinit_ppc970
1646 2:
1647
1648 /* Switch off MMU if not already */
1649 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1650 add r4,r4,r30
1651 bl .__mmu_off
1652 b .__after_prom_start
1653
1654 #ifdef CONFIG_PPC_MULTIPLATFORM
1655 _STATIC(__boot_from_prom)
1656 /* Save parameters */
1657 mr r31,r3
1658 mr r30,r4
1659 mr r29,r5
1660 mr r28,r6
1661 mr r27,r7
1662
1663 /*
1664 * Align the stack to 16-byte boundary
1665 * Depending on the size and layout of the ELF sections in the initial
1666 * boot binary, the stack pointer will be unalignet on PowerMac
1667 */
1668 rldicr r1,r1,0,59
1669
1670 /* Make sure we are running in 64 bits mode */
1671 bl .enable_64b_mode
1672
1673 /* put a relocation offset into r3 */
1674 bl .reloc_offset
1675
1676 LOAD_REG_IMMEDIATE(r2,__toc_start)
1677 addi r2,r2,0x4000
1678 addi r2,r2,0x4000
1679
1680 /* Relocate the TOC from a virt addr to a real addr */
1681 add r2,r2,r3
1682
1683 /* Restore parameters */
1684 mr r3,r31
1685 mr r4,r30
1686 mr r5,r29
1687 mr r6,r28
1688 mr r7,r27
1689
1690 /* Do all of the interaction with OF client interface */
1691 bl .prom_init
1692 /* We never return */
1693 trap
1694 #endif
1695
1696 /*
1697 * At this point, r3 contains the physical address we are running at,
1698 * returned by prom_init()
1699 */
1700 _STATIC(__after_prom_start)
1701
1702 /*
1703 * We need to run with __start at physical address PHYSICAL_START.
1704 * This will leave some code in the first 256B of
1705 * real memory, which are reserved for software use.
1706 * The remainder of the first page is loaded with the fixed
1707 * interrupt vectors. The next two pages are filled with
1708 * unknown exception placeholders.
1709 *
1710 * Note: This process overwrites the OF exception vectors.
1711 * r26 == relocation offset
1712 * r27 == KERNELBASE
1713 */
1714 bl .reloc_offset
1715 mr r26,r3
1716 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1717
1718 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
1719
1720 // XXX FIXME: Use phys returned by OF (r30)
1721 add r4,r27,r26 /* source addr */
1722 /* current address of _start */
1723 /* i.e. where we are running */
1724 /* the source addr */
1725
1726 cmpdi r4,0 /* In some cases the loader may */
1727 beq .start_here_multiplatform /* have already put us at zero */
1728 /* so we can skip the copy. */
1729 LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1730 sub r5,r5,r27
1731
1732 li r6,0x100 /* Start offset, the first 0x100 */
1733 /* bytes were copied earlier. */
1734
1735 bl .copy_and_flush /* copy the first n bytes */
1736 /* this includes the code being */
1737 /* executed here. */
1738
1739 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
1740 mtctr r0 /* that we just made/relocated */
1741 bctr
1742
1743 4: LOAD_REG_IMMEDIATE(r5,klimit)
1744 add r5,r5,r26
1745 ld r5,0(r5) /* get the value of klimit */
1746 sub r5,r5,r27
1747 bl .copy_and_flush /* copy the rest */
1748 b .start_here_multiplatform
1749
1750 #endif /* CONFIG_PPC_MULTIPLATFORM */
1751
1752 /*
1753 * Copy routine used to copy the kernel to start at physical address 0
1754 * and flush and invalidate the caches as needed.
1755 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1756 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1757 *
1758 * Note: this routine *only* clobbers r0, r6 and lr
1759 */
1760 _GLOBAL(copy_and_flush)
1761 addi r5,r5,-8
1762 addi r6,r6,-8
1763 4: li r0,8 /* Use the smallest common */
1764 /* denominator cache line */
1765 /* size. This results in */
1766 /* extra cache line flushes */
1767 /* but operation is correct. */
1768 /* Can't get cache line size */
1769 /* from NACA as it is being */
1770 /* moved too. */
1771
1772 mtctr r0 /* put # words/line in ctr */
1773 3: addi r6,r6,8 /* copy a cache line */
1774 ldx r0,r6,r4
1775 stdx r0,r6,r3
1776 bdnz 3b
1777 dcbst r6,r3 /* write it to memory */
1778 sync
1779 icbi r6,r3 /* flush the icache line */
1780 cmpld 0,r6,r5
1781 blt 4b
1782 sync
1783 addi r5,r5,8
1784 addi r6,r6,8
1785 blr
1786
1787 .align 8
1788 copy_to_here:
1789
1790 #ifdef CONFIG_SMP
1791 #ifdef CONFIG_PPC_PMAC
1792 /*
1793 * On PowerMac, secondary processors starts from the reset vector, which
1794 * is temporarily turned into a call to one of the functions below.
1795 */
1796 .section ".text";
1797 .align 2 ;
1798
1799 .globl __secondary_start_pmac_0
1800 __secondary_start_pmac_0:
1801 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1802 li r24,0
1803 b 1f
1804 li r24,1
1805 b 1f
1806 li r24,2
1807 b 1f
1808 li r24,3
1809 1:
1810
1811 _GLOBAL(pmac_secondary_start)
1812 /* turn on 64-bit mode */
1813 bl .enable_64b_mode
1814 isync
1815
1816 /* Copy some CPU settings from CPU 0 */
1817 bl .__restore_cpu_ppc970
1818
1819 /* pSeries do that early though I don't think we really need it */
1820 mfmsr r3
1821 ori r3,r3,MSR_RI
1822 mtmsrd r3 /* RI on */
1823
1824 /* Set up a paca value for this processor. */
1825 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
1826 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1827 add r13,r13,r4 /* for this processor. */
1828 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
1829
1830 /* Create a temp kernel stack for use before relocation is on. */
1831 ld r1,PACAEMERGSP(r13)
1832 subi r1,r1,STACK_FRAME_OVERHEAD
1833
1834 b .__secondary_start
1835
1836 #endif /* CONFIG_PPC_PMAC */
1837
1838 /*
1839 * This function is called after the master CPU has released the
1840 * secondary processors. The execution environment is relocation off.
1841 * The paca for this processor has the following fields initialized at
1842 * this point:
1843 * 1. Processor number
1844 * 2. Segment table pointer (virtual address)
1845 * On entry the following are set:
1846 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1847 * r24 = cpu# (in Linux terms)
1848 * r13 = paca virtual address
1849 * SPRG3 = paca virtual address
1850 */
1851 _GLOBAL(__secondary_start)
1852 /* Set thread priority to MEDIUM */
1853 HMT_MEDIUM
1854
1855 /* Load TOC */
1856 ld r2,PACATOC(r13)
1857
1858 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1859 bl .early_setup_secondary
1860
1861 /* Initialize the kernel stack. Just a repeat for iSeries. */
1862 LOAD_REG_ADDR(r3, current_set)
1863 sldi r28,r24,3 /* get current_set[cpu#] */
1864 ldx r1,r3,r28
1865 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1866 std r1,PACAKSAVE(r13)
1867
1868 /* Clear backchain so we get nice backtraces */
1869 li r7,0
1870 mtlr r7
1871
1872 /* enable MMU and jump to start_secondary */
1873 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1874 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1875 #ifdef DO_SOFT_DISABLE
1876 BEGIN_FW_FTR_SECTION
1877 ori r4,r4,MSR_EE
1878 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
1879 #endif
1880 mtspr SPRN_SRR0,r3
1881 mtspr SPRN_SRR1,r4
1882 rfid
1883 b . /* prevent speculative execution */
1884
1885 /*
1886 * Running with relocation on at this point. All we want to do is
1887 * zero the stack back-chain pointer before going into C code.
1888 */
1889 _GLOBAL(start_secondary_prolog)
1890 li r3,0
1891 std r3,0(r1) /* Zero the stack frame pointer */
1892 bl .start_secondary
1893 b .
1894 #endif
1895
1896 /*
1897 * This subroutine clobbers r11 and r12
1898 */
1899 _GLOBAL(enable_64b_mode)
1900 mfmsr r11 /* grab the current MSR */
1901 li r12,1
1902 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1903 or r11,r11,r12
1904 li r12,1
1905 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1906 or r11,r11,r12
1907 mtmsrd r11
1908 isync
1909 blr
1910
1911 #ifdef CONFIG_PPC_MULTIPLATFORM
1912 /*
1913 * This is where the main kernel code starts.
1914 */
1915 _STATIC(start_here_multiplatform)
1916 /* get a new offset, now that the kernel has moved. */
1917 bl .reloc_offset
1918 mr r26,r3
1919
1920 /* Clear out the BSS. It may have been done in prom_init,
1921 * already but that's irrelevant since prom_init will soon
1922 * be detached from the kernel completely. Besides, we need
1923 * to clear it now for kexec-style entry.
1924 */
1925 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1926 LOAD_REG_IMMEDIATE(r8,__bss_start)
1927 sub r11,r11,r8 /* bss size */
1928 addi r11,r11,7 /* round up to an even double word */
1929 rldicl. r11,r11,61,3 /* shift right by 3 */
1930 beq 4f
1931 addi r8,r8,-8
1932 li r0,0
1933 mtctr r11 /* zero this many doublewords */
1934 3: stdu r0,8(r8)
1935 bdnz 3b
1936 4:
1937
1938 mfmsr r6
1939 ori r6,r6,MSR_RI
1940 mtmsrd r6 /* RI on */
1941
1942 /* The following gets the stack and TOC set up with the regs */
1943 /* pointing to the real addr of the kernel stack. This is */
1944 /* all done to support the C function call below which sets */
1945 /* up the htab. This is done because we have relocated the */
1946 /* kernel but are still running in real mode. */
1947
1948 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1949 add r3,r3,r26
1950
1951 /* set up a stack pointer (physical address) */
1952 addi r1,r3,THREAD_SIZE
1953 li r0,0
1954 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1955
1956 /* set up the TOC (physical address) */
1957 LOAD_REG_IMMEDIATE(r2,__toc_start)
1958 addi r2,r2,0x4000
1959 addi r2,r2,0x4000
1960 add r2,r2,r26
1961
1962 /* Do very early kernel initializations, including initial hash table,
1963 * stab and slb setup before we turn on relocation. */
1964
1965 /* Restore parameters passed from prom_init/kexec */
1966 mr r3,r31
1967 bl .early_setup
1968
1969 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1970 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1971 mtspr SPRN_SRR0,r3
1972 mtspr SPRN_SRR1,r4
1973 rfid
1974 b . /* prevent speculative execution */
1975 #endif /* CONFIG_PPC_MULTIPLATFORM */
1976
1977 /* This is where all platforms converge execution */
1978 _STATIC(start_here_common)
1979 /* relocation is on at this point */
1980
1981 /* The following code sets up the SP and TOC now that we are */
1982 /* running with translation enabled. */
1983
1984 LOAD_REG_IMMEDIATE(r3,init_thread_union)
1985
1986 /* set up the stack */
1987 addi r1,r3,THREAD_SIZE
1988 li r0,0
1989 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1990
1991 /* ptr to current */
1992 LOAD_REG_IMMEDIATE(r4, init_task)
1993 std r4,PACACURRENT(r13)
1994
1995 /* Load the TOC */
1996 ld r2,PACATOC(r13)
1997 std r1,PACAKSAVE(r13)
1998
1999 bl .setup_system
2000
2001 /* Load up the kernel context */
2002 5:
2003 #ifdef DO_SOFT_DISABLE
2004 BEGIN_FW_FTR_SECTION
2005 li r5,0
2006 stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
2007 mfmsr r5
2008 ori r5,r5,MSR_EE /* Hard Enabled */
2009 mtmsrd r5
2010 END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
2011 #endif
2012
2013 bl .start_kernel
2014
2015 /* Not reached */
2016 BUG_OPCODE
2017
2018 /*
2019 * We put a few things here that have to be page-aligned.
2020 * This stuff goes at the beginning of the bss, which is page-aligned.
2021 */
2022 .section ".bss"
2023
2024 .align PAGE_SHIFT
2025
2026 .globl empty_zero_page
2027 empty_zero_page:
2028 .space PAGE_SIZE
2029
2030 .globl swapper_pg_dir
2031 swapper_pg_dir:
2032 .space PAGE_SIZE
2033
2034 /*
2035 * This space gets a copy of optional info passed to us by the bootstrap
2036 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2037 */
2038 .globl cmd_line
2039 cmd_line:
2040 .space COMMAND_LINE_SIZE
This page took 0.071532 seconds and 6 git commands to generate.