blob: 4e9640cc0563c0f410ffbee098590a24a57a371b [file] [log] [blame]
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001/*
2 * This file contains the 64-bit "server" PowerPC variant
3 * of the low level exception handling including exception
4 * vectors, exception return, part of the slb and stab
5 * handling and other fixed offset specific things.
6 *
7 * This file is meant to be #included from head_64.S due to
8 * position dependant assembly.
9 *
10 * Most of this originates from head_64.S and thus has the same
11 * copyright history.
12 *
13 */
14
Benjamin Herrenschmidt8aa34ab2009-07-14 20:52:52 +000015#include <asm/exception-64s.h>
16
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000017/*
18 * We layout physical memory as follows:
19 * 0x0000 - 0x00ff : Secondary processor spin code
20 * 0x0100 - 0x2fff : pSeries Interrupt prologs
21 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
22 * 0x6000 - 0x6fff : Initial (CPU0) segment table
23 * 0x7000 - 0x7fff : FWNMI data area
24 * 0x8000 - : Early init and support code
25 */
26
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000027/*
28 * This is the start of the interrupt handlers for pSeries
29 * This code runs with relocation off.
30 * Code from here to __end_interrupts gets copied down to real
31 * address 0x100 when we are running a relocatable kernel.
32 * Therefore any relative branches in this section must only
33 * branch to labels in this section.
34 */
35 . = 0x100
36 .globl __start_interrupts
37__start_interrupts:
38
39 STD_EXCEPTION_PSERIES(0x100, system_reset)
40
41 . = 0x200
42_machine_check_pSeries:
43 HMT_MEDIUM
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000044 mtspr SPRN_SPRG_SCRATCH0,r13 /* save r13 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000045 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
46
47 . = 0x300
48 .globl data_access_pSeries
49data_access_pSeries:
50 HMT_MEDIUM
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000051 mtspr SPRN_SPRG_SCRATCH0,r13
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000052BEGIN_FTR_SECTION
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000053 mtspr SPRN_SPRG_SCRATCH1,r12
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000054 mfspr r13,SPRN_DAR
55 mfspr r12,SPRN_DSISR
56 srdi r13,r13,60
57 rlwimi r13,r12,16,0x20
58 mfcr r12
59 cmpwi r13,0x2c
60 beq do_stab_bolted_pSeries
61 mtcrf 0x80,r12
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000062 mfspr r12,SPRN_SPRG_SCRATCH1
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000063END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
64 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
65
66 . = 0x380
67 .globl data_access_slb_pSeries
68data_access_slb_pSeries:
69 HMT_MEDIUM
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000070 mtspr SPRN_SPRG_SCRATCH0,r13
71 mfspr r13,SPRN_SPRG_PACA /* get paca address into r13 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000072 std r3,PACA_EXSLB+EX_R3(r13)
73 mfspr r3,SPRN_DAR
74 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
75 mfcr r9
76#ifdef __DISABLED__
77 /* Keep that around for when we re-implement dynamic VSIDs */
78 cmpdi r3,0
79 bge slb_miss_user_pseries
80#endif /* __DISABLED__ */
81 std r10,PACA_EXSLB+EX_R10(r13)
82 std r11,PACA_EXSLB+EX_R11(r13)
83 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000084 mfspr r10,SPRN_SPRG_SCRATCH0
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000085 std r10,PACA_EXSLB+EX_R13(r13)
86 mfspr r12,SPRN_SRR1 /* and SRR1 */
87#ifndef CONFIG_RELOCATABLE
88 b .slb_miss_realmode
89#else
90 /*
91 * We can't just use a direct branch to .slb_miss_realmode
92 * because the distance from here to there depends on where
93 * the kernel ends up being put.
94 */
95 mfctr r11
96 ld r10,PACAKBASE(r13)
97 LOAD_HANDLER(r10, .slb_miss_realmode)
98 mtctr r10
99 bctr
100#endif
101
102 STD_EXCEPTION_PSERIES(0x400, instruction_access)
103
104 . = 0x480
105 .globl instruction_access_slb_pSeries
106instruction_access_slb_pSeries:
107 HMT_MEDIUM
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000108 mtspr SPRN_SPRG_SCRATCH0,r13
109 mfspr r13,SPRN_SPRG_PACA /* get paca address into r13 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000110 std r3,PACA_EXSLB+EX_R3(r13)
111 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
112 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
113 mfcr r9
114#ifdef __DISABLED__
115 /* Keep that around for when we re-implement dynamic VSIDs */
116 cmpdi r3,0
117 bge slb_miss_user_pseries
118#endif /* __DISABLED__ */
119 std r10,PACA_EXSLB+EX_R10(r13)
120 std r11,PACA_EXSLB+EX_R11(r13)
121 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000122 mfspr r10,SPRN_SPRG_SCRATCH0
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000123 std r10,PACA_EXSLB+EX_R13(r13)
124 mfspr r12,SPRN_SRR1 /* and SRR1 */
125#ifndef CONFIG_RELOCATABLE
126 b .slb_miss_realmode
127#else
128 mfctr r11
129 ld r10,PACAKBASE(r13)
130 LOAD_HANDLER(r10, .slb_miss_realmode)
131 mtctr r10
132 bctr
133#endif
134
135 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
136 STD_EXCEPTION_PSERIES(0x600, alignment)
137 STD_EXCEPTION_PSERIES(0x700, program_check)
138 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
139 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
140 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
141 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
142
143 . = 0xc00
144 .globl system_call_pSeries
145system_call_pSeries:
146 HMT_MEDIUM
147BEGIN_FTR_SECTION
148 cmpdi r0,0x1ebe
149 beq- 1f
150END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
151 mr r9,r13
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000152 mfspr r13,SPRN_SPRG_PACA
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000153 mfspr r11,SPRN_SRR0
154 ld r12,PACAKBASE(r13)
155 ld r10,PACAKMSR(r13)
156 LOAD_HANDLER(r12, system_call_entry)
157 mtspr SPRN_SRR0,r12
158 mfspr r12,SPRN_SRR1
159 mtspr SPRN_SRR1,r10
160 rfid
161 b . /* prevent speculative execution */
162
163/* Fast LE/BE switch system call */
1641: mfspr r12,SPRN_SRR1
165 xori r12,r12,MSR_LE
166 mtspr SPRN_SRR1,r12
167 rfid /* return to userspace */
168 b .
169
170 STD_EXCEPTION_PSERIES(0xd00, single_step)
171 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
172
173 /* We need to deal with the Altivec unavailable exception
174 * here which is at 0xf20, thus in the middle of the
175 * prolog code of the PerformanceMonitor one. A little
176 * trickery is thus necessary
177 */
178 . = 0xf00
179 b performance_monitor_pSeries
180
181 . = 0xf20
182 b altivec_unavailable_pSeries
183
184 . = 0xf40
185 b vsx_unavailable_pSeries
186
187#ifdef CONFIG_CBE_RAS
188 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
189#endif /* CONFIG_CBE_RAS */
190 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
191#ifdef CONFIG_CBE_RAS
192 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
193#endif /* CONFIG_CBE_RAS */
194 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
195#ifdef CONFIG_CBE_RAS
196 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
197#endif /* CONFIG_CBE_RAS */
198
199 . = 0x3000
200
201/*** pSeries interrupt support ***/
202
203 /* moved from 0xf00 */
204 STD_EXCEPTION_PSERIES(., performance_monitor)
205 STD_EXCEPTION_PSERIES(., altivec_unavailable)
206 STD_EXCEPTION_PSERIES(., vsx_unavailable)
207
208/*
209 * An interrupt came in while soft-disabled; clear EE in SRR1,
210 * clear paca->hard_enabled and return.
211 */
212masked_interrupt:
213 stb r10,PACAHARDIRQEN(r13)
214 mtcrf 0x80,r9
215 ld r9,PACA_EXGEN+EX_R9(r13)
216 mfspr r10,SPRN_SRR1
217 rldicl r10,r10,48,1 /* clear MSR_EE */
218 rotldi r10,r10,16
219 mtspr SPRN_SRR1,r10
220 ld r10,PACA_EXGEN+EX_R10(r13)
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000221 mfspr r13,SPRN_SPRG_SCRATCH0
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000222 rfid
223 b .
224
225 .align 7
226do_stab_bolted_pSeries:
227 mtcrf 0x80,r12
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000228 mfspr r12,SPRN_SPRG_SCRATCH1
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000229 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
230
231#ifdef CONFIG_PPC_PSERIES
232/*
233 * Vectors for the FWNMI option. Share common code.
234 */
235 .globl system_reset_fwnmi
236 .align 7
237system_reset_fwnmi:
238 HMT_MEDIUM
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000239 mtspr SPRN_SPRG_SCRATCH0,r13 /* save r13 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000240 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
241
242 .globl machine_check_fwnmi
243 .align 7
244machine_check_fwnmi:
245 HMT_MEDIUM
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000246 mtspr SPRN_SPRG_SCRATCH0,r13 /* save r13 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000247 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
248
249#endif /* CONFIG_PPC_PSERIES */
250
251#ifdef __DISABLED__
252/*
253 * This is used for when the SLB miss handler has to go virtual,
254 * which doesn't happen for now anymore but will once we re-implement
255 * dynamic VSIDs for shared page tables
256 */
257slb_miss_user_pseries:
258 std r10,PACA_EXGEN+EX_R10(r13)
259 std r11,PACA_EXGEN+EX_R11(r13)
260 std r12,PACA_EXGEN+EX_R12(r13)
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000261 mfspr r10,SPRG_SCRATCH0
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000262 ld r11,PACA_EXSLB+EX_R9(r13)
263 ld r12,PACA_EXSLB+EX_R3(r13)
264 std r10,PACA_EXGEN+EX_R13(r13)
265 std r11,PACA_EXGEN+EX_R9(r13)
266 std r12,PACA_EXGEN+EX_R3(r13)
267 clrrdi r12,r13,32
268 mfmsr r10
269 mfspr r11,SRR0 /* save SRR0 */
270 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
271 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
272 mtspr SRR0,r12
273 mfspr r12,SRR1 /* and SRR1 */
274 mtspr SRR1,r10
275 rfid
276 b . /* prevent spec. execution */
277#endif /* __DISABLED__ */
278
279 .align 7
280 .globl __end_interrupts
281__end_interrupts:
282
283/*
284 * Code from here down to __end_handlers is invoked from the
285 * exception prologs above. Because the prologs assemble the
286 * addresses of these handlers using the LOAD_HANDLER macro,
287 * which uses an addi instruction, these handlers must be in
288 * the first 32k of the kernel image.
289 */
290
291/*** Common interrupt handlers ***/
292
293 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
294
295 /*
296 * Machine check is different because we use a different
297 * save area: PACA_EXMC instead of PACA_EXGEN.
298 */
299 .align 7
300 .globl machine_check_common
301machine_check_common:
302 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
303 FINISH_NAP
304 DISABLE_INTS
305 bl .save_nvgprs
306 addi r3,r1,STACK_FRAME_OVERHEAD
307 bl .machine_check_exception
308 b .ret_from_except
309
310 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
311 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
312 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
313 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
314 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
315 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
316 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
317#ifdef CONFIG_ALTIVEC
318 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
319#else
320 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
321#endif
322#ifdef CONFIG_CBE_RAS
323 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
324 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
325 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
326#endif /* CONFIG_CBE_RAS */
327
328 .align 7
329system_call_entry:
330 b system_call_common
331
332/*
333 * Here we have detected that the kernel stack pointer is bad.
334 * R9 contains the saved CR, r13 points to the paca,
335 * r10 contains the (bad) kernel stack pointer,
336 * r11 and r12 contain the saved SRR0 and SRR1.
337 * We switch to using an emergency stack, save the registers there,
338 * and call kernel_bad_stack(), which panics.
339 */
340bad_stack:
341 ld r1,PACAEMERGSP(r13)
342 subi r1,r1,64+INT_FRAME_SIZE
343 std r9,_CCR(r1)
344 std r10,GPR1(r1)
345 std r11,_NIP(r1)
346 std r12,_MSR(r1)
347 mfspr r11,SPRN_DAR
348 mfspr r12,SPRN_DSISR
349 std r11,_DAR(r1)
350 std r12,_DSISR(r1)
351 mflr r10
352 mfctr r11
353 mfxer r12
354 std r10,_LINK(r1)
355 std r11,_CTR(r1)
356 std r12,_XER(r1)
357 SAVE_GPR(0,r1)
358 SAVE_GPR(2,r1)
359 SAVE_4GPRS(3,r1)
360 SAVE_2GPRS(7,r1)
361 SAVE_10GPRS(12,r1)
362 SAVE_10GPRS(22,r1)
363 lhz r12,PACA_TRAP_SAVE(r13)
364 std r12,_TRAP(r1)
365 addi r11,r1,INT_FRAME_SIZE
366 std r11,0(r1)
367 li r12,0
368 std r12,0(r11)
369 ld r2,PACATOC(r13)
3701: addi r3,r1,STACK_FRAME_OVERHEAD
371 bl .kernel_bad_stack
372 b 1b
373
374/*
375 * Here r13 points to the paca, r9 contains the saved CR,
376 * SRR0 and SRR1 are saved in r11 and r12,
377 * r9 - r13 are saved in paca->exgen.
378 */
379 .align 7
380 .globl data_access_common
381data_access_common:
382 mfspr r10,SPRN_DAR
383 std r10,PACA_EXGEN+EX_DAR(r13)
384 mfspr r10,SPRN_DSISR
385 stw r10,PACA_EXGEN+EX_DSISR(r13)
386 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
387 ld r3,PACA_EXGEN+EX_DAR(r13)
388 lwz r4,PACA_EXGEN+EX_DSISR(r13)
389 li r5,0x300
390 b .do_hash_page /* Try to handle as hpte fault */
391
392 .align 7
393 .globl instruction_access_common
394instruction_access_common:
395 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
396 ld r3,_NIP(r1)
397 andis. r4,r12,0x5820
398 li r5,0x400
399 b .do_hash_page /* Try to handle as hpte fault */
400
401/*
402 * Here is the common SLB miss user that is used when going to virtual
403 * mode for SLB misses, that is currently not used
404 */
405#ifdef __DISABLED__
406 .align 7
407 .globl slb_miss_user_common
408slb_miss_user_common:
409 mflr r10
410 std r3,PACA_EXGEN+EX_DAR(r13)
411 stw r9,PACA_EXGEN+EX_CCR(r13)
412 std r10,PACA_EXGEN+EX_LR(r13)
413 std r11,PACA_EXGEN+EX_SRR0(r13)
414 bl .slb_allocate_user
415
416 ld r10,PACA_EXGEN+EX_LR(r13)
417 ld r3,PACA_EXGEN+EX_R3(r13)
418 lwz r9,PACA_EXGEN+EX_CCR(r13)
419 ld r11,PACA_EXGEN+EX_SRR0(r13)
420 mtlr r10
421 beq- slb_miss_fault
422
423 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
424 beq- unrecov_user_slb
425 mfmsr r10
426
427.machine push
428.machine "power4"
429 mtcrf 0x80,r9
430.machine pop
431
432 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
433 mtmsrd r10,1
434
435 mtspr SRR0,r11
436 mtspr SRR1,r12
437
438 ld r9,PACA_EXGEN+EX_R9(r13)
439 ld r10,PACA_EXGEN+EX_R10(r13)
440 ld r11,PACA_EXGEN+EX_R11(r13)
441 ld r12,PACA_EXGEN+EX_R12(r13)
442 ld r13,PACA_EXGEN+EX_R13(r13)
443 rfid
444 b .
445
446slb_miss_fault:
447 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
448 ld r4,PACA_EXGEN+EX_DAR(r13)
449 li r5,0
450 std r4,_DAR(r1)
451 std r5,_DSISR(r1)
452 b handle_page_fault
453
454unrecov_user_slb:
455 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
456 DISABLE_INTS
457 bl .save_nvgprs
4581: addi r3,r1,STACK_FRAME_OVERHEAD
459 bl .unrecoverable_exception
460 b 1b
461
462#endif /* __DISABLED__ */
463
464
465/*
466 * r13 points to the PACA, r9 contains the saved CR,
467 * r12 contain the saved SRR1, SRR0 is still ready for return
468 * r3 has the faulting address
469 * r9 - r13 are saved in paca->exslb.
470 * r3 is saved in paca->slb_r3
471 * We assume we aren't going to take any exceptions during this procedure.
472 */
473_GLOBAL(slb_miss_realmode)
474 mflr r10
475#ifdef CONFIG_RELOCATABLE
476 mtctr r11
477#endif
478
479 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
480 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
481
482 bl .slb_allocate_realmode
483
484 /* All done -- return from exception. */
485
486 ld r10,PACA_EXSLB+EX_LR(r13)
487 ld r3,PACA_EXSLB+EX_R3(r13)
488 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
489#ifdef CONFIG_PPC_ISERIES
490BEGIN_FW_FTR_SECTION
491 ld r11,PACALPPACAPTR(r13)
492 ld r11,LPPACASRR0(r11) /* get SRR0 value */
493END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
494#endif /* CONFIG_PPC_ISERIES */
495
496 mtlr r10
497
498 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
499 beq- 2f
500
501.machine push
502.machine "power4"
503 mtcrf 0x80,r9
504 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
505.machine pop
506
507#ifdef CONFIG_PPC_ISERIES
508BEGIN_FW_FTR_SECTION
509 mtspr SPRN_SRR0,r11
510 mtspr SPRN_SRR1,r12
511END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
512#endif /* CONFIG_PPC_ISERIES */
513 ld r9,PACA_EXSLB+EX_R9(r13)
514 ld r10,PACA_EXSLB+EX_R10(r13)
515 ld r11,PACA_EXSLB+EX_R11(r13)
516 ld r12,PACA_EXSLB+EX_R12(r13)
517 ld r13,PACA_EXSLB+EX_R13(r13)
518 rfid
519 b . /* prevent speculative execution */
520
5212:
522#ifdef CONFIG_PPC_ISERIES
523BEGIN_FW_FTR_SECTION
524 b unrecov_slb
525END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
526#endif /* CONFIG_PPC_ISERIES */
527 mfspr r11,SPRN_SRR0
528 ld r10,PACAKBASE(r13)
529 LOAD_HANDLER(r10,unrecov_slb)
530 mtspr SPRN_SRR0,r10
531 ld r10,PACAKMSR(r13)
532 mtspr SPRN_SRR1,r10
533 rfid
534 b .
535
536unrecov_slb:
537 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
538 DISABLE_INTS
539 bl .save_nvgprs
5401: addi r3,r1,STACK_FRAME_OVERHEAD
541 bl .unrecoverable_exception
542 b 1b
543
544 .align 7
545 .globl hardware_interrupt_common
546 .globl hardware_interrupt_entry
547hardware_interrupt_common:
548 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
549 FINISH_NAP
550hardware_interrupt_entry:
551 DISABLE_INTS
552BEGIN_FTR_SECTION
553 bl .ppc64_runlatch_on
554END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
555 addi r3,r1,STACK_FRAME_OVERHEAD
556 bl .do_IRQ
557 b .ret_from_except_lite
558
559#ifdef CONFIG_PPC_970_NAP
560power4_fixup_nap:
561 andc r9,r9,r10
562 std r9,TI_LOCAL_FLAGS(r11)
563 ld r10,_LINK(r1) /* make idle task do the */
564 std r10,_NIP(r1) /* equivalent of a blr */
565 blr
566#endif
567
568 .align 7
569 .globl alignment_common
570alignment_common:
571 mfspr r10,SPRN_DAR
572 std r10,PACA_EXGEN+EX_DAR(r13)
573 mfspr r10,SPRN_DSISR
574 stw r10,PACA_EXGEN+EX_DSISR(r13)
575 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
576 ld r3,PACA_EXGEN+EX_DAR(r13)
577 lwz r4,PACA_EXGEN+EX_DSISR(r13)
578 std r3,_DAR(r1)
579 std r4,_DSISR(r1)
580 bl .save_nvgprs
581 addi r3,r1,STACK_FRAME_OVERHEAD
582 ENABLE_INTS
583 bl .alignment_exception
584 b .ret_from_except
585
586 .align 7
587 .globl program_check_common
588program_check_common:
589 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
590 bl .save_nvgprs
591 addi r3,r1,STACK_FRAME_OVERHEAD
592 ENABLE_INTS
593 bl .program_check_exception
594 b .ret_from_except
595
596 .align 7
597 .globl fp_unavailable_common
598fp_unavailable_common:
599 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
600 bne 1f /* if from user, just load it up */
601 bl .save_nvgprs
602 addi r3,r1,STACK_FRAME_OVERHEAD
603 ENABLE_INTS
604 bl .kernel_fp_unavailable_exception
605 BUG_OPCODE
6061: bl .load_up_fpu
607 b fast_exception_return
608
609 .align 7
610 .globl altivec_unavailable_common
611altivec_unavailable_common:
612 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
613#ifdef CONFIG_ALTIVEC
614BEGIN_FTR_SECTION
615 beq 1f
616 bl .load_up_altivec
617 b fast_exception_return
6181:
619END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
620#endif
621 bl .save_nvgprs
622 addi r3,r1,STACK_FRAME_OVERHEAD
623 ENABLE_INTS
624 bl .altivec_unavailable_exception
625 b .ret_from_except
626
627 .align 7
628 .globl vsx_unavailable_common
629vsx_unavailable_common:
630 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
631#ifdef CONFIG_VSX
632BEGIN_FTR_SECTION
633 bne .load_up_vsx
6341:
635END_FTR_SECTION_IFSET(CPU_FTR_VSX)
636#endif
637 bl .save_nvgprs
638 addi r3,r1,STACK_FRAME_OVERHEAD
639 ENABLE_INTS
640 bl .vsx_unavailable_exception
641 b .ret_from_except
642
643 .align 7
644 .globl __end_handlers
645__end_handlers:
646
647/*
648 * Return from an exception with minimal checks.
649 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
650 * If interrupts have been enabled, or anything has been
651 * done that might have changed the scheduling status of
652 * any task or sent any task a signal, you should use
653 * ret_from_except or ret_from_except_lite instead of this.
654 */
655fast_exc_return_irq: /* restores irq state too */
656 ld r3,SOFTE(r1)
657 TRACE_AND_RESTORE_IRQ(r3);
658 ld r12,_MSR(r1)
659 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
660 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
661 b 1f
662
663 .globl fast_exception_return
664fast_exception_return:
665 ld r12,_MSR(r1)
6661: ld r11,_NIP(r1)
667 andi. r3,r12,MSR_RI /* check if RI is set */
668 beq- unrecov_fer
669
670#ifdef CONFIG_VIRT_CPU_ACCOUNTING
671 andi. r3,r12,MSR_PR
672 beq 2f
673 ACCOUNT_CPU_USER_EXIT(r3, r4)
6742:
675#endif
676
677 ld r3,_CCR(r1)
678 ld r4,_LINK(r1)
679 ld r5,_CTR(r1)
680 ld r6,_XER(r1)
681 mtcr r3
682 mtlr r4
683 mtctr r5
684 mtxer r6
685 REST_GPR(0, r1)
686 REST_8GPRS(2, r1)
687
688 mfmsr r10
689 rldicl r10,r10,48,1 /* clear EE */
690 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
691 mtmsrd r10,1
692
693 mtspr SPRN_SRR1,r12
694 mtspr SPRN_SRR0,r11
695 REST_4GPRS(10, r1)
696 ld r1,GPR1(r1)
697 rfid
698 b . /* prevent speculative execution */
699
700unrecov_fer:
701 bl .save_nvgprs
7021: addi r3,r1,STACK_FRAME_OVERHEAD
703 bl .unrecoverable_exception
704 b 1b
705
706
707/*
708 * Hash table stuff
709 */
710 .align 7
711_STATIC(do_hash_page)
712 std r3,_DAR(r1)
713 std r4,_DSISR(r1)
714
715 andis. r0,r4,0xa450 /* weird error? */
716 bne- handle_page_fault /* if not, try to insert a HPTE */
717BEGIN_FTR_SECTION
718 andis. r0,r4,0x0020 /* Is it a segment table fault? */
719 bne- do_ste_alloc /* If so handle it */
720END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
721
722 /*
723 * On iSeries, we soft-disable interrupts here, then
724 * hard-enable interrupts so that the hash_page code can spin on
725 * the hash_table_lock without problems on a shared processor.
726 */
727 DISABLE_INTS
728
729 /*
730 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
731 * and will clobber volatile registers when irq tracing is enabled
732 * so we need to reload them. It may be possible to be smarter here
733 * and move the irq tracing elsewhere but let's keep it simple for
734 * now
735 */
736#ifdef CONFIG_TRACE_IRQFLAGS
737 ld r3,_DAR(r1)
738 ld r4,_DSISR(r1)
739 ld r5,_TRAP(r1)
740 ld r12,_MSR(r1)
741 clrrdi r5,r5,4
742#endif /* CONFIG_TRACE_IRQFLAGS */
743 /*
744 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
745 * accessing a userspace segment (even from the kernel). We assume
746 * kernel addresses always have the high bit set.
747 */
748 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
749 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
750 orc r0,r12,r0 /* MSR_PR | ~high_bit */
751 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
752 ori r4,r4,1 /* add _PAGE_PRESENT */
753 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
754
755 /*
756 * r3 contains the faulting address
757 * r4 contains the required access permissions
758 * r5 contains the trap number
759 *
760 * at return r3 = 0 for success
761 */
762 bl .hash_page /* build HPTE if possible */
763 cmpdi r3,0 /* see if hash_page succeeded */
764
765BEGIN_FW_FTR_SECTION
766 /*
767 * If we had interrupts soft-enabled at the point where the
768 * DSI/ISI occurred, and an interrupt came in during hash_page,
769 * handle it now.
770 * We jump to ret_from_except_lite rather than fast_exception_return
771 * because ret_from_except_lite will check for and handle pending
772 * interrupts if necessary.
773 */
774 beq 13f
775END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
776
777BEGIN_FW_FTR_SECTION
778 /*
779 * Here we have interrupts hard-disabled, so it is sufficient
780 * to restore paca->{soft,hard}_enable and get out.
781 */
782 beq fast_exc_return_irq /* Return from exception on success */
783END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
784
785 /* For a hash failure, we don't bother re-enabling interrupts */
786 ble- 12f
787
788 /*
789 * hash_page couldn't handle it, set soft interrupt enable back
790 * to what it was before the trap. Note that .raw_local_irq_restore
791 * handles any interrupts pending at this point.
792 */
793 ld r3,SOFTE(r1)
794 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
795 bl .raw_local_irq_restore
796 b 11f
797
798/* Here we have a page fault that hash_page can't handle. */
799handle_page_fault:
800 ENABLE_INTS
80111: ld r4,_DAR(r1)
802 ld r5,_DSISR(r1)
803 addi r3,r1,STACK_FRAME_OVERHEAD
804 bl .do_page_fault
805 cmpdi r3,0
806 beq+ 13f
807 bl .save_nvgprs
808 mr r5,r3
809 addi r3,r1,STACK_FRAME_OVERHEAD
810 lwz r4,_DAR(r1)
811 bl .bad_page_fault
812 b .ret_from_except
813
81413: b .ret_from_except_lite
815
816/* We have a page fault that hash_page could handle but HV refused
817 * the PTE insertion
818 */
81912: bl .save_nvgprs
820 mr r5,r3
821 addi r3,r1,STACK_FRAME_OVERHEAD
822 ld r4,_DAR(r1)
823 bl .low_hash_fault
824 b .ret_from_except
825
826 /* here we have a segment miss */
827do_ste_alloc:
828 bl .ste_allocate /* try to insert stab entry */
829 cmpdi r3,0
830 bne- handle_page_fault
831 b fast_exception_return
832
833/*
834 * r13 points to the PACA, r9 contains the saved CR,
835 * r11 and r12 contain the saved SRR0 and SRR1.
836 * r9 - r13 are saved in paca->exslb.
837 * We assume we aren't going to take any exceptions during this procedure.
838 * We assume (DAR >> 60) == 0xc.
839 */
840 .align 7
841_GLOBAL(do_stab_bolted)
842 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
843 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
844
845 /* Hash to the primary group */
846 ld r10,PACASTABVIRT(r13)
847 mfspr r11,SPRN_DAR
848 srdi r11,r11,28
849 rldimi r10,r11,7,52 /* r10 = first ste of the group */
850
851 /* Calculate VSID */
852 /* This is a kernel address, so protovsid = ESID */
853 ASM_VSID_SCRAMBLE(r11, r9, 256M)
854 rldic r9,r11,12,16 /* r9 = vsid << 12 */
855
856 /* Search the primary group for a free entry */
8571: ld r11,0(r10) /* Test valid bit of the current ste */
858 andi. r11,r11,0x80
859 beq 2f
860 addi r10,r10,16
861 andi. r11,r10,0x70
862 bne 1b
863
864 /* Stick for only searching the primary group for now. */
865 /* At least for now, we use a very simple random castout scheme */
866 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
867 mftb r11
868 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
869 ori r11,r11,0x10
870
871 /* r10 currently points to an ste one past the group of interest */
872 /* make it point to the randomly selected entry */
873 subi r10,r10,128
874 or r10,r10,r11 /* r10 is the entry to invalidate */
875
876 isync /* mark the entry invalid */
877 ld r11,0(r10)
878 rldicl r11,r11,56,1 /* clear the valid bit */
879 rotldi r11,r11,8
880 std r11,0(r10)
881 sync
882
883 clrrdi r11,r11,28 /* Get the esid part of the ste */
884 slbie r11
885
8862: std r9,8(r10) /* Store the vsid part of the ste */
887 eieio
888
889 mfspr r11,SPRN_DAR /* Get the new esid */
890 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
891 ori r11,r11,0x90 /* Turn on valid and kp */
892 std r11,0(r10) /* Put new entry back into the stab */
893
894 sync
895
896 /* All done -- return from exception. */
897 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
898 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
899
900 andi. r10,r12,MSR_RI
901 beq- unrecov_slb
902
903 mtcrf 0x80,r9 /* restore CR */
904
905 mfmsr r10
906 clrrdi r10,r10,2
907 mtmsrd r10,1
908
909 mtspr SPRN_SRR0,r11
910 mtspr SPRN_SRR1,r12
911 ld r9,PACA_EXSLB+EX_R9(r13)
912 ld r10,PACA_EXSLB+EX_R10(r13)
913 ld r11,PACA_EXSLB+EX_R11(r13)
914 ld r12,PACA_EXSLB+EX_R12(r13)
915 ld r13,PACA_EXSLB+EX_R13(r13)
916 rfid
917 b . /* prevent speculative execution */
918
919/*
920 * Space for CPU0's segment table.
921 *
922 * On iSeries, the hypervisor must fill in at least one entry before
923 * we get control (with relocate on). The address is given to the hv
924 * as a page number (see xLparMap below), so this must be at a
925 * fixed address (the linker can't compute (u64)&initial_stab >>
926 * PAGE_SHIFT).
927 */
928 . = STAB0_OFFSET /* 0x6000 */
929 .globl initial_stab
930initial_stab:
931 .space 4096
932
933#ifdef CONFIG_PPC_PSERIES
934/*
935 * Data area reserved for FWNMI option.
936 * This address (0x7000) is fixed by the RPA.
937 */
938 .= 0x7000
939 .globl fwnmi_data_area
940fwnmi_data_area:
941#endif /* CONFIG_PPC_PSERIES */
942
943 /* iSeries does not use the FWNMI stuff, so it is safe to put
944 * this here, even if we later allow kernels that will boot on
945 * both pSeries and iSeries */
946#ifdef CONFIG_PPC_ISERIES
947 . = LPARMAP_PHYS
948 .globl xLparMap
949xLparMap:
950 .quad HvEsidsToMap /* xNumberEsids */
951 .quad HvRangesToMap /* xNumberRanges */
952 .quad STAB0_PAGE /* xSegmentTableOffs */
953 .zero 40 /* xRsvd */
954 /* xEsids (HvEsidsToMap entries of 2 quads) */
955 .quad PAGE_OFFSET_ESID /* xKernelEsid */
956 .quad PAGE_OFFSET_VSID /* xKernelVsid */
957 .quad VMALLOC_START_ESID /* xKernelEsid */
958 .quad VMALLOC_START_VSID /* xKernelVsid */
959 /* xRanges (HvRangesToMap entries of 3 quads) */
960 .quad HvPagesToMap /* xPages */
961 .quad 0 /* xOffset */
962 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
963
964#endif /* CONFIG_PPC_ISERIES */
965
966#ifdef CONFIG_PPC_PSERIES
967 . = 0x8000
968#endif /* CONFIG_PPC_PSERIES */