]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/powerpc/kernel/exceptions-64s.S
Merge branch 'topic/livepatch' into next
[mirror_ubuntu-zesty-kernel.git] / arch / powerpc / kernel / exceptions-64s.S
1 /*
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 dependent assembly.
9 *
10 * Most of this originates from head_64.S and thus has the same
11 * copyright history.
12 *
13 */
14
15 #include <asm/hw_irq.h>
16 #include <asm/exception-64s.h>
17 #include <asm/ptrace.h>
18 #include <asm/cpuidle.h>
19
20 /*
21 * We layout physical memory as follows:
22 * 0x0000 - 0x00ff : Secondary processor spin code
23 * 0x0100 - 0x17ff : pSeries Interrupt prologs
24 * 0x1800 - 0x4000 : interrupt support common interrupt prologs
25 * 0x4000 - 0x5fff : pSeries interrupts with IR=1,DR=1
26 * 0x6000 - 0x6fff : more interrupt support including for IR=1,DR=1
27 * 0x7000 - 0x7fff : FWNMI data area
28 * 0x8000 - 0x8fff : Initial (CPU0) segment table
29 * 0x9000 - : Early init and support code
30 */
31 /* Syscall routine is used twice, in reloc-off and reloc-on paths */
32 #define SYSCALL_PSERIES_1 \
33 BEGIN_FTR_SECTION \
34 cmpdi r0,0x1ebe ; \
35 beq- 1f ; \
36 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
37 mr r9,r13 ; \
38 GET_PACA(r13) ; \
39 mfspr r11,SPRN_SRR0 ; \
40 0:
41
42 #define SYSCALL_PSERIES_2_RFID \
43 mfspr r12,SPRN_SRR1 ; \
44 ld r10,PACAKBASE(r13) ; \
45 LOAD_HANDLER(r10, system_call_entry) ; \
46 mtspr SPRN_SRR0,r10 ; \
47 ld r10,PACAKMSR(r13) ; \
48 mtspr SPRN_SRR1,r10 ; \
49 rfid ; \
50 b . ; /* prevent speculative execution */
51
52 #define SYSCALL_PSERIES_3 \
53 /* Fast LE/BE switch system call */ \
54 1: mfspr r12,SPRN_SRR1 ; \
55 xori r12,r12,MSR_LE ; \
56 mtspr SPRN_SRR1,r12 ; \
57 rfid ; /* return to userspace */ \
58 b . ; /* prevent speculative execution */
59
60 #if defined(CONFIG_RELOCATABLE)
61 /*
62 * We can't branch directly so we do it via the CTR which
63 * is volatile across system calls.
64 */
65 #define SYSCALL_PSERIES_2_DIRECT \
66 mflr r10 ; \
67 ld r12,PACAKBASE(r13) ; \
68 LOAD_HANDLER(r12, system_call_entry) ; \
69 mtctr r12 ; \
70 mfspr r12,SPRN_SRR1 ; \
71 /* Re-use of r13... No spare regs to do this */ \
72 li r13,MSR_RI ; \
73 mtmsrd r13,1 ; \
74 GET_PACA(r13) ; /* get r13 back */ \
75 bctr ;
76 #else
77 /* We can branch directly */
78 #define SYSCALL_PSERIES_2_DIRECT \
79 mfspr r12,SPRN_SRR1 ; \
80 li r10,MSR_RI ; \
81 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
82 b system_call_common ;
83 #endif
84
85 /*
86 * This is the start of the interrupt handlers for pSeries
87 * This code runs with relocation off.
88 * Code from here to __end_interrupts gets copied down to real
89 * address 0x100 when we are running a relocatable kernel.
90 * Therefore any relative branches in this section must only
91 * branch to labels in this section.
92 */
93 . = 0x100
94 .globl __start_interrupts
95 __start_interrupts:
96
97 .globl system_reset_pSeries;
98 system_reset_pSeries:
99 SET_SCRATCH0(r13)
100 #ifdef CONFIG_PPC_P7_NAP
101 BEGIN_FTR_SECTION
102 /* Running native on arch 2.06 or later, check if we are
103 * waking up from nap/sleep/winkle.
104 */
105 mfspr r13,SPRN_SRR1
106 rlwinm. r13,r13,47-31,30,31
107 beq 9f
108
109 cmpwi cr3,r13,2
110
111 /*
112 * Check if last bit of HSPGR0 is set. This indicates whether we are
113 * waking up from winkle.
114 */
115 GET_PACA(r13)
116 clrldi r5,r13,63
117 clrrdi r13,r13,1
118 cmpwi cr4,r5,1
119 mtspr SPRN_HSPRG0,r13
120
121 lbz r0,PACA_THREAD_IDLE_STATE(r13)
122 cmpwi cr2,r0,PNV_THREAD_NAP
123 bgt cr2,8f /* Either sleep or Winkle */
124
125 /* Waking up from nap should not cause hypervisor state loss */
126 bgt cr3,.
127
128 /* Waking up from nap */
129 li r0,PNV_THREAD_RUNNING
130 stb r0,PACA_THREAD_IDLE_STATE(r13) /* Clear thread state */
131
132 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
133 li r0,KVM_HWTHREAD_IN_KERNEL
134 stb r0,HSTATE_HWTHREAD_STATE(r13)
135 /* Order setting hwthread_state vs. testing hwthread_req */
136 sync
137 lbz r0,HSTATE_HWTHREAD_REQ(r13)
138 cmpwi r0,0
139 beq 1f
140 b kvm_start_guest
141 1:
142 #endif
143
144 /* Return SRR1 from power7_nap() */
145 mfspr r3,SPRN_SRR1
146 beq cr3,2f
147 b power7_wakeup_noloss
148 2: b power7_wakeup_loss
149
150 /* Fast Sleep wakeup on PowerNV */
151 8: GET_PACA(r13)
152 b power7_wakeup_tb_loss
153
154 9:
155 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
156 #endif /* CONFIG_PPC_P7_NAP */
157 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
158 NOTEST, 0x100)
159
160 . = 0x200
161 machine_check_pSeries_1:
162 /* This is moved out of line as it can be patched by FW, but
163 * some code path might still want to branch into the original
164 * vector
165 */
166 SET_SCRATCH0(r13) /* save r13 */
167 #ifdef CONFIG_PPC_P7_NAP
168 BEGIN_FTR_SECTION
169 /* Running native on arch 2.06 or later, check if we are
170 * waking up from nap. We only handle no state loss and
171 * supervisor state loss. We do -not- handle hypervisor
172 * state loss at this time.
173 */
174 mfspr r13,SPRN_SRR1
175 rlwinm. r13,r13,47-31,30,31
176 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
177 beq 9f
178
179 mfspr r13,SPRN_SRR1
180 rlwinm. r13,r13,47-31,30,31
181 /* waking up from powersave (nap) state */
182 cmpwi cr1,r13,2
183 /* Total loss of HV state is fatal. let's just stay stuck here */
184 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
185 bgt cr1,.
186 9:
187 OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
188 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
189 #endif /* CONFIG_PPC_P7_NAP */
190 EXCEPTION_PROLOG_0(PACA_EXMC)
191 BEGIN_FTR_SECTION
192 b machine_check_pSeries_early
193 FTR_SECTION_ELSE
194 b machine_check_pSeries_0
195 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
196
197 . = 0x300
198 .globl data_access_pSeries
199 data_access_pSeries:
200 SET_SCRATCH0(r13)
201 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
202 KVMTEST, 0x300)
203
204 . = 0x380
205 .globl data_access_slb_pSeries
206 data_access_slb_pSeries:
207 SET_SCRATCH0(r13)
208 EXCEPTION_PROLOG_0(PACA_EXSLB)
209 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
210 std r3,PACA_EXSLB+EX_R3(r13)
211 mfspr r3,SPRN_DAR
212 mfspr r12,SPRN_SRR1
213 #ifndef CONFIG_RELOCATABLE
214 b slb_miss_realmode
215 #else
216 /*
217 * We can't just use a direct branch to slb_miss_realmode
218 * because the distance from here to there depends on where
219 * the kernel ends up being put.
220 */
221 mfctr r11
222 ld r10,PACAKBASE(r13)
223 LOAD_HANDLER(r10, slb_miss_realmode)
224 mtctr r10
225 bctr
226 #endif
227
228 STD_EXCEPTION_PSERIES(0x400, instruction_access)
229
230 . = 0x480
231 .globl instruction_access_slb_pSeries
232 instruction_access_slb_pSeries:
233 SET_SCRATCH0(r13)
234 EXCEPTION_PROLOG_0(PACA_EXSLB)
235 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x480)
236 std r3,PACA_EXSLB+EX_R3(r13)
237 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
238 mfspr r12,SPRN_SRR1
239 #ifndef CONFIG_RELOCATABLE
240 b slb_miss_realmode
241 #else
242 mfctr r11
243 ld r10,PACAKBASE(r13)
244 LOAD_HANDLER(r10, slb_miss_realmode)
245 mtctr r10
246 bctr
247 #endif
248
249 /* We open code these as we can't have a ". = x" (even with
250 * x = "." within a feature section
251 */
252 . = 0x500;
253 .globl hardware_interrupt_pSeries;
254 .globl hardware_interrupt_hv;
255 hardware_interrupt_pSeries:
256 hardware_interrupt_hv:
257 BEGIN_FTR_SECTION
258 _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
259 EXC_HV, SOFTEN_TEST_HV)
260 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
261 FTR_SECTION_ELSE
262 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
263 EXC_STD, SOFTEN_TEST_PR)
264 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
265 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
266
267 STD_EXCEPTION_PSERIES(0x600, alignment)
268 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x600)
269
270 STD_EXCEPTION_PSERIES(0x700, program_check)
271 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x700)
272
273 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
274 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x800)
275
276 . = 0x900
277 .globl decrementer_pSeries
278 decrementer_pSeries:
279 _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
280
281 STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
282
283 MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
284 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xa00)
285
286 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
287 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xb00)
288
289 . = 0xc00
290 .globl system_call_pSeries
291 system_call_pSeries:
292 /*
293 * If CONFIG_KVM_BOOK3S_64_HANDLER is set, save the PPR (on systems
294 * that support it) before changing to HMT_MEDIUM. That allows the KVM
295 * code to save that value into the guest state (it is the guest's PPR
296 * value). Otherwise just change to HMT_MEDIUM as userspace has
297 * already saved the PPR.
298 */
299 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
300 SET_SCRATCH0(r13)
301 GET_PACA(r13)
302 std r9,PACA_EXGEN+EX_R9(r13)
303 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR);
304 HMT_MEDIUM;
305 std r10,PACA_EXGEN+EX_R10(r13)
306 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r9, CPU_FTR_HAS_PPR);
307 mfcr r9
308 KVMTEST(0xc00)
309 GET_SCRATCH0(r13)
310 #else
311 HMT_MEDIUM;
312 #endif
313 SYSCALL_PSERIES_1
314 SYSCALL_PSERIES_2_RFID
315 SYSCALL_PSERIES_3
316 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
317
318 STD_EXCEPTION_PSERIES(0xd00, single_step)
319 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xd00)
320
321 /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
322 * out of line to handle them
323 */
324 . = 0xe00
325 hv_data_storage_trampoline:
326 SET_SCRATCH0(r13)
327 EXCEPTION_PROLOG_0(PACA_EXGEN)
328 b h_data_storage_hv
329
330 . = 0xe20
331 hv_instr_storage_trampoline:
332 SET_SCRATCH0(r13)
333 EXCEPTION_PROLOG_0(PACA_EXGEN)
334 b h_instr_storage_hv
335
336 . = 0xe40
337 emulation_assist_trampoline:
338 SET_SCRATCH0(r13)
339 EXCEPTION_PROLOG_0(PACA_EXGEN)
340 b emulation_assist_hv
341
342 . = 0xe60
343 hv_exception_trampoline:
344 SET_SCRATCH0(r13)
345 EXCEPTION_PROLOG_0(PACA_EXGEN)
346 b hmi_exception_early
347
348 . = 0xe80
349 hv_doorbell_trampoline:
350 SET_SCRATCH0(r13)
351 EXCEPTION_PROLOG_0(PACA_EXGEN)
352 b h_doorbell_hv
353
354 /* We need to deal with the Altivec unavailable exception
355 * here which is at 0xf20, thus in the middle of the
356 * prolog code of the PerformanceMonitor one. A little
357 * trickery is thus necessary
358 */
359 . = 0xf00
360 performance_monitor_pseries_trampoline:
361 SET_SCRATCH0(r13)
362 EXCEPTION_PROLOG_0(PACA_EXGEN)
363 b performance_monitor_pSeries
364
365 . = 0xf20
366 altivec_unavailable_pseries_trampoline:
367 SET_SCRATCH0(r13)
368 EXCEPTION_PROLOG_0(PACA_EXGEN)
369 b altivec_unavailable_pSeries
370
371 . = 0xf40
372 vsx_unavailable_pseries_trampoline:
373 SET_SCRATCH0(r13)
374 EXCEPTION_PROLOG_0(PACA_EXGEN)
375 b vsx_unavailable_pSeries
376
377 . = 0xf60
378 facility_unavailable_trampoline:
379 SET_SCRATCH0(r13)
380 EXCEPTION_PROLOG_0(PACA_EXGEN)
381 b facility_unavailable_pSeries
382
383 . = 0xf80
384 hv_facility_unavailable_trampoline:
385 SET_SCRATCH0(r13)
386 EXCEPTION_PROLOG_0(PACA_EXGEN)
387 b facility_unavailable_hv
388
389 #ifdef CONFIG_CBE_RAS
390 STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
391 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
392 #endif /* CONFIG_CBE_RAS */
393
394 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
395 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
396
397 . = 0x1500
398 .global denorm_exception_hv
399 denorm_exception_hv:
400 mtspr SPRN_SPRG_HSCRATCH0,r13
401 EXCEPTION_PROLOG_0(PACA_EXGEN)
402 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
403
404 #ifdef CONFIG_PPC_DENORMALISATION
405 mfspr r10,SPRN_HSRR1
406 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
407 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
408 addi r11,r11,-4 /* HSRR0 is next instruction */
409 bne+ denorm_assist
410 #endif
411
412 KVMTEST(0x1500)
413 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
414 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
415
416 #ifdef CONFIG_CBE_RAS
417 STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
418 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
419 #endif /* CONFIG_CBE_RAS */
420
421 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
422 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x1700)
423
424 #ifdef CONFIG_CBE_RAS
425 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
426 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
427 #else
428 . = 0x1800
429 #endif /* CONFIG_CBE_RAS */
430
431
432 /*** Out of line interrupts support ***/
433
434 .align 7
435 /* moved from 0x200 */
436 machine_check_pSeries_early:
437 BEGIN_FTR_SECTION
438 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
439 /*
440 * Register contents:
441 * R13 = PACA
442 * R9 = CR
443 * Original R9 to R13 is saved on PACA_EXMC
444 *
445 * Switch to mc_emergency stack and handle re-entrancy (we limit
446 * the nested MCE upto level 4 to avoid stack overflow).
447 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
448 *
449 * We use paca->in_mce to check whether this is the first entry or
450 * nested machine check. We increment paca->in_mce to track nested
451 * machine checks.
452 *
453 * If this is the first entry then set stack pointer to
454 * paca->mc_emergency_sp, otherwise r1 is already pointing to
455 * stack frame on mc_emergency stack.
456 *
457 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
458 * checkstop if we get another machine check exception before we do
459 * rfid with MSR_ME=1.
460 */
461 mr r11,r1 /* Save r1 */
462 lhz r10,PACA_IN_MCE(r13)
463 cmpwi r10,0 /* Are we in nested machine check */
464 bne 0f /* Yes, we are. */
465 /* First machine check entry */
466 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
467 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
468 addi r10,r10,1 /* increment paca->in_mce */
469 sth r10,PACA_IN_MCE(r13)
470 /* Limit nested MCE to level 4 to avoid stack overflow */
471 cmpwi r10,4
472 bgt 2f /* Check if we hit limit of 4 */
473 std r11,GPR1(r1) /* Save r1 on the stack. */
474 std r11,0(r1) /* make stack chain pointer */
475 mfspr r11,SPRN_SRR0 /* Save SRR0 */
476 std r11,_NIP(r1)
477 mfspr r11,SPRN_SRR1 /* Save SRR1 */
478 std r11,_MSR(r1)
479 mfspr r11,SPRN_DAR /* Save DAR */
480 std r11,_DAR(r1)
481 mfspr r11,SPRN_DSISR /* Save DSISR */
482 std r11,_DSISR(r1)
483 std r9,_CCR(r1) /* Save CR in stackframe */
484 /* Save r9 through r13 from EXMC save area to stack frame. */
485 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
486 mfmsr r11 /* get MSR value */
487 ori r11,r11,MSR_ME /* turn on ME bit */
488 ori r11,r11,MSR_RI /* turn on RI bit */
489 ld r12,PACAKBASE(r13) /* get high part of &label */
490 LOAD_HANDLER(r12, machine_check_handle_early)
491 1: mtspr SPRN_SRR0,r12
492 mtspr SPRN_SRR1,r11
493 rfid
494 b . /* prevent speculative execution */
495 2:
496 /* Stack overflow. Stay on emergency stack and panic.
497 * Keep the ME bit off while panic-ing, so that if we hit
498 * another machine check we checkstop.
499 */
500 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
501 ld r11,PACAKMSR(r13)
502 ld r12,PACAKBASE(r13)
503 LOAD_HANDLER(r12, unrecover_mce)
504 li r10,MSR_ME
505 andc r11,r11,r10 /* Turn off MSR_ME */
506 b 1b
507 b . /* prevent speculative execution */
508 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
509
510 machine_check_pSeries:
511 .globl machine_check_fwnmi
512 machine_check_fwnmi:
513 SET_SCRATCH0(r13) /* save r13 */
514 EXCEPTION_PROLOG_0(PACA_EXMC)
515 machine_check_pSeries_0:
516 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
517 EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
518 KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
519 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
520 KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
521 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x400)
522 KVM_HANDLER(PACA_EXSLB, EXC_STD, 0x480)
523 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x900)
524 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
525
526 #ifdef CONFIG_PPC_DENORMALISATION
527 denorm_assist:
528 BEGIN_FTR_SECTION
529 /*
530 * To denormalise we need to move a copy of the register to itself.
531 * For POWER6 do that here for all FP regs.
532 */
533 mfmsr r10
534 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
535 xori r10,r10,(MSR_FE0|MSR_FE1)
536 mtmsrd r10
537 sync
538
539 #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
540 #define FMR4(n) FMR2(n) ; FMR2(n+2)
541 #define FMR8(n) FMR4(n) ; FMR4(n+4)
542 #define FMR16(n) FMR8(n) ; FMR8(n+8)
543 #define FMR32(n) FMR16(n) ; FMR16(n+16)
544 FMR32(0)
545
546 FTR_SECTION_ELSE
547 /*
548 * To denormalise we need to move a copy of the register to itself.
549 * For POWER7 do that here for the first 32 VSX registers only.
550 */
551 mfmsr r10
552 oris r10,r10,MSR_VSX@h
553 mtmsrd r10
554 sync
555
556 #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
557 #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
558 #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
559 #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
560 #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
561 XVCPSGNDP32(0)
562
563 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
564
565 BEGIN_FTR_SECTION
566 b denorm_done
567 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
568 /*
569 * To denormalise we need to move a copy of the register to itself.
570 * For POWER8 we need to do that for all 64 VSX registers
571 */
572 XVCPSGNDP32(32)
573 denorm_done:
574 mtspr SPRN_HSRR0,r11
575 mtcrf 0x80,r9
576 ld r9,PACA_EXGEN+EX_R9(r13)
577 RESTORE_PPR_PACA(PACA_EXGEN, r10)
578 BEGIN_FTR_SECTION
579 ld r10,PACA_EXGEN+EX_CFAR(r13)
580 mtspr SPRN_CFAR,r10
581 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
582 ld r10,PACA_EXGEN+EX_R10(r13)
583 ld r11,PACA_EXGEN+EX_R11(r13)
584 ld r12,PACA_EXGEN+EX_R12(r13)
585 ld r13,PACA_EXGEN+EX_R13(r13)
586 HRFID
587 b .
588 #endif
589
590 .align 7
591 /* moved from 0xe00 */
592 STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
593 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
594 STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
595 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
596 STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
597 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
598 MASKABLE_EXCEPTION_HV_OOL(0xe62, hmi_exception)
599 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
600
601 MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
602 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
603
604 /* moved from 0xf00 */
605 STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
606 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xf00)
607 STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
608 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xf20)
609 STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
610 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xf40)
611 STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
612 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xf60)
613 STD_EXCEPTION_HV_OOL(0xf82, facility_unavailable)
614 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xf82)
615
616 /*
617 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
618 * - If it was a decrementer interrupt, we bump the dec to max and and return.
619 * - If it was a doorbell we return immediately since doorbells are edge
620 * triggered and won't automatically refire.
621 * - If it was a HMI we return immediately since we handled it in realmode
622 * and it won't refire.
623 * - else we hard disable and return.
624 * This is called with r10 containing the value to OR to the paca field.
625 */
626 #define MASKED_INTERRUPT(_H) \
627 masked_##_H##interrupt: \
628 std r11,PACA_EXGEN+EX_R11(r13); \
629 lbz r11,PACAIRQHAPPENED(r13); \
630 or r11,r11,r10; \
631 stb r11,PACAIRQHAPPENED(r13); \
632 cmpwi r10,PACA_IRQ_DEC; \
633 bne 1f; \
634 lis r10,0x7fff; \
635 ori r10,r10,0xffff; \
636 mtspr SPRN_DEC,r10; \
637 b 2f; \
638 1: cmpwi r10,PACA_IRQ_DBELL; \
639 beq 2f; \
640 cmpwi r10,PACA_IRQ_HMI; \
641 beq 2f; \
642 mfspr r10,SPRN_##_H##SRR1; \
643 rldicl r10,r10,48,1; /* clear MSR_EE */ \
644 rotldi r10,r10,16; \
645 mtspr SPRN_##_H##SRR1,r10; \
646 2: mtcrf 0x80,r9; \
647 ld r9,PACA_EXGEN+EX_R9(r13); \
648 ld r10,PACA_EXGEN+EX_R10(r13); \
649 ld r11,PACA_EXGEN+EX_R11(r13); \
650 GET_SCRATCH0(r13); \
651 ##_H##rfid; \
652 b .
653
654 MASKED_INTERRUPT()
655 MASKED_INTERRUPT(H)
656
657 /*
658 * Called from arch_local_irq_enable when an interrupt needs
659 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
660 * which kind of interrupt. MSR:EE is already off. We generate a
661 * stackframe like if a real interrupt had happened.
662 *
663 * Note: While MSR:EE is off, we need to make sure that _MSR
664 * in the generated frame has EE set to 1 or the exception
665 * handler will not properly re-enable them.
666 */
667 _GLOBAL(__replay_interrupt)
668 /* We are going to jump to the exception common code which
669 * will retrieve various register values from the PACA which
670 * we don't give a damn about, so we don't bother storing them.
671 */
672 mfmsr r12
673 mflr r11
674 mfcr r9
675 ori r12,r12,MSR_EE
676 cmpwi r3,0x900
677 beq decrementer_common
678 cmpwi r3,0x500
679 beq hardware_interrupt_common
680 BEGIN_FTR_SECTION
681 cmpwi r3,0xe80
682 beq h_doorbell_common
683 FTR_SECTION_ELSE
684 cmpwi r3,0xa00
685 beq doorbell_super_common
686 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
687 blr
688
689 #ifdef CONFIG_PPC_PSERIES
690 /*
691 * Vectors for the FWNMI option. Share common code.
692 */
693 .globl system_reset_fwnmi
694 .align 7
695 system_reset_fwnmi:
696 SET_SCRATCH0(r13) /* save r13 */
697 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
698 NOTEST, 0x100)
699
700 #endif /* CONFIG_PPC_PSERIES */
701
702 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
703 kvmppc_skip_interrupt:
704 /*
705 * Here all GPRs are unchanged from when the interrupt happened
706 * except for r13, which is saved in SPRG_SCRATCH0.
707 */
708 mfspr r13, SPRN_SRR0
709 addi r13, r13, 4
710 mtspr SPRN_SRR0, r13
711 GET_SCRATCH0(r13)
712 rfid
713 b .
714
715 kvmppc_skip_Hinterrupt:
716 /*
717 * Here all GPRs are unchanged from when the interrupt happened
718 * except for r13, which is saved in SPRG_SCRATCH0.
719 */
720 mfspr r13, SPRN_HSRR0
721 addi r13, r13, 4
722 mtspr SPRN_HSRR0, r13
723 GET_SCRATCH0(r13)
724 hrfid
725 b .
726 #endif
727
728 /*
729 * Code from here down to __end_handlers is invoked from the
730 * exception prologs above. Because the prologs assemble the
731 * addresses of these handlers using the LOAD_HANDLER macro,
732 * which uses an ori instruction, these handlers must be in
733 * the first 64k of the kernel image.
734 */
735
736 /*** Common interrupt handlers ***/
737
738 STD_EXCEPTION_COMMON(0x100, system_reset, system_reset_exception)
739
740 STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
741 STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, timer_interrupt)
742 STD_EXCEPTION_COMMON(0x980, hdecrementer, hdec_interrupt)
743 #ifdef CONFIG_PPC_DOORBELL
744 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, doorbell_exception)
745 #else
746 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, unknown_exception)
747 #endif
748 STD_EXCEPTION_COMMON(0xb00, trap_0b, unknown_exception)
749 STD_EXCEPTION_COMMON(0xd00, single_step, single_step_exception)
750 STD_EXCEPTION_COMMON(0xe00, trap_0e, unknown_exception)
751 STD_EXCEPTION_COMMON(0xe40, emulation_assist, emulation_assist_interrupt)
752 STD_EXCEPTION_COMMON_ASYNC(0xe60, hmi_exception, handle_hmi_exception)
753 #ifdef CONFIG_PPC_DOORBELL
754 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, doorbell_exception)
755 #else
756 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, unknown_exception)
757 #endif
758 STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, performance_monitor_exception)
759 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, instruction_breakpoint_exception)
760 STD_EXCEPTION_COMMON(0x1502, denorm, unknown_exception)
761 #ifdef CONFIG_ALTIVEC
762 STD_EXCEPTION_COMMON(0x1700, altivec_assist, altivec_assist_exception)
763 #else
764 STD_EXCEPTION_COMMON(0x1700, altivec_assist, unknown_exception)
765 #endif
766 #ifdef CONFIG_CBE_RAS
767 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, cbe_system_error_exception)
768 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, cbe_maintenance_exception)
769 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, cbe_thermal_exception)
770 #endif /* CONFIG_CBE_RAS */
771
772 /*
773 * Relocation-on interrupts: A subset of the interrupts can be delivered
774 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
775 * it. Addresses are the same as the original interrupt addresses, but
776 * offset by 0xc000000000004000.
777 * It's impossible to receive interrupts below 0x300 via this mechanism.
778 * KVM: None of these traps are from the guest ; anything that escalated
779 * to HV=1 from HV=0 is delivered via real mode handlers.
780 */
781
782 /*
783 * This uses the standard macro, since the original 0x300 vector
784 * only has extra guff for STAB-based processors -- which never
785 * come here.
786 */
787 STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
788 . = 0x4380
789 .globl data_access_slb_relon_pSeries
790 data_access_slb_relon_pSeries:
791 SET_SCRATCH0(r13)
792 EXCEPTION_PROLOG_0(PACA_EXSLB)
793 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
794 std r3,PACA_EXSLB+EX_R3(r13)
795 mfspr r3,SPRN_DAR
796 mfspr r12,SPRN_SRR1
797 #ifndef CONFIG_RELOCATABLE
798 b slb_miss_realmode
799 #else
800 /*
801 * We can't just use a direct branch to slb_miss_realmode
802 * because the distance from here to there depends on where
803 * the kernel ends up being put.
804 */
805 mfctr r11
806 ld r10,PACAKBASE(r13)
807 LOAD_HANDLER(r10, slb_miss_realmode)
808 mtctr r10
809 bctr
810 #endif
811
812 STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
813 . = 0x4480
814 .globl instruction_access_slb_relon_pSeries
815 instruction_access_slb_relon_pSeries:
816 SET_SCRATCH0(r13)
817 EXCEPTION_PROLOG_0(PACA_EXSLB)
818 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
819 std r3,PACA_EXSLB+EX_R3(r13)
820 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
821 mfspr r12,SPRN_SRR1
822 #ifndef CONFIG_RELOCATABLE
823 b slb_miss_realmode
824 #else
825 mfctr r11
826 ld r10,PACAKBASE(r13)
827 LOAD_HANDLER(r10, slb_miss_realmode)
828 mtctr r10
829 bctr
830 #endif
831
832 . = 0x4500
833 .globl hardware_interrupt_relon_pSeries;
834 .globl hardware_interrupt_relon_hv;
835 hardware_interrupt_relon_pSeries:
836 hardware_interrupt_relon_hv:
837 BEGIN_FTR_SECTION
838 _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
839 FTR_SECTION_ELSE
840 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
841 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
842 STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
843 STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
844 STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
845 MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
846 STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
847 MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
848 STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
849
850 . = 0x4c00
851 .globl system_call_relon_pSeries
852 system_call_relon_pSeries:
853 HMT_MEDIUM
854 SYSCALL_PSERIES_1
855 SYSCALL_PSERIES_2_DIRECT
856 SYSCALL_PSERIES_3
857
858 STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
859
860 . = 0x4e00
861 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
862
863 . = 0x4e20
864 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
865
866 . = 0x4e40
867 emulation_assist_relon_trampoline:
868 SET_SCRATCH0(r13)
869 EXCEPTION_PROLOG_0(PACA_EXGEN)
870 b emulation_assist_relon_hv
871
872 . = 0x4e60
873 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
874
875 . = 0x4e80
876 h_doorbell_relon_trampoline:
877 SET_SCRATCH0(r13)
878 EXCEPTION_PROLOG_0(PACA_EXGEN)
879 b h_doorbell_relon_hv
880
881 . = 0x4f00
882 performance_monitor_relon_pseries_trampoline:
883 SET_SCRATCH0(r13)
884 EXCEPTION_PROLOG_0(PACA_EXGEN)
885 b performance_monitor_relon_pSeries
886
887 . = 0x4f20
888 altivec_unavailable_relon_pseries_trampoline:
889 SET_SCRATCH0(r13)
890 EXCEPTION_PROLOG_0(PACA_EXGEN)
891 b altivec_unavailable_relon_pSeries
892
893 . = 0x4f40
894 vsx_unavailable_relon_pseries_trampoline:
895 SET_SCRATCH0(r13)
896 EXCEPTION_PROLOG_0(PACA_EXGEN)
897 b vsx_unavailable_relon_pSeries
898
899 . = 0x4f60
900 facility_unavailable_relon_trampoline:
901 SET_SCRATCH0(r13)
902 EXCEPTION_PROLOG_0(PACA_EXGEN)
903 b facility_unavailable_relon_pSeries
904
905 . = 0x4f80
906 hv_facility_unavailable_relon_trampoline:
907 SET_SCRATCH0(r13)
908 EXCEPTION_PROLOG_0(PACA_EXGEN)
909 b hv_facility_unavailable_relon_hv
910
911 STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
912 #ifdef CONFIG_PPC_DENORMALISATION
913 . = 0x5500
914 b denorm_exception_hv
915 #endif
916 STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
917
918 /* Other future vectors */
919 .align 7
920 .globl __end_interrupts
921 __end_interrupts:
922
923 .align 7
924 system_call_entry:
925 b system_call_common
926
927 ppc64_runlatch_on_trampoline:
928 b __ppc64_runlatch_on
929
930 /*
931 * Here r13 points to the paca, r9 contains the saved CR,
932 * SRR0 and SRR1 are saved in r11 and r12,
933 * r9 - r13 are saved in paca->exgen.
934 */
935 .align 7
936 .globl data_access_common
937 data_access_common:
938 mfspr r10,SPRN_DAR
939 std r10,PACA_EXGEN+EX_DAR(r13)
940 mfspr r10,SPRN_DSISR
941 stw r10,PACA_EXGEN+EX_DSISR(r13)
942 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
943 RECONCILE_IRQ_STATE(r10, r11)
944 ld r12,_MSR(r1)
945 ld r3,PACA_EXGEN+EX_DAR(r13)
946 lwz r4,PACA_EXGEN+EX_DSISR(r13)
947 li r5,0x300
948 b do_hash_page /* Try to handle as hpte fault */
949
950 .align 7
951 .globl h_data_storage_common
952 h_data_storage_common:
953 mfspr r10,SPRN_HDAR
954 std r10,PACA_EXGEN+EX_DAR(r13)
955 mfspr r10,SPRN_HDSISR
956 stw r10,PACA_EXGEN+EX_DSISR(r13)
957 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
958 bl save_nvgprs
959 RECONCILE_IRQ_STATE(r10, r11)
960 addi r3,r1,STACK_FRAME_OVERHEAD
961 bl unknown_exception
962 b ret_from_except
963
964 .align 7
965 .globl instruction_access_common
966 instruction_access_common:
967 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
968 RECONCILE_IRQ_STATE(r10, r11)
969 ld r12,_MSR(r1)
970 ld r3,_NIP(r1)
971 andis. r4,r12,0x5820
972 li r5,0x400
973 b do_hash_page /* Try to handle as hpte fault */
974
975 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
976
977 /*
978 * Machine check is different because we use a different
979 * save area: PACA_EXMC instead of PACA_EXGEN.
980 */
981 .align 7
982 .globl machine_check_common
983 machine_check_common:
984
985 mfspr r10,SPRN_DAR
986 std r10,PACA_EXGEN+EX_DAR(r13)
987 mfspr r10,SPRN_DSISR
988 stw r10,PACA_EXGEN+EX_DSISR(r13)
989 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
990 FINISH_NAP
991 RECONCILE_IRQ_STATE(r10, r11)
992 ld r3,PACA_EXGEN+EX_DAR(r13)
993 lwz r4,PACA_EXGEN+EX_DSISR(r13)
994 std r3,_DAR(r1)
995 std r4,_DSISR(r1)
996 bl save_nvgprs
997 addi r3,r1,STACK_FRAME_OVERHEAD
998 bl machine_check_exception
999 b ret_from_except
1000
1001 .align 7
1002 .globl alignment_common
1003 alignment_common:
1004 mfspr r10,SPRN_DAR
1005 std r10,PACA_EXGEN+EX_DAR(r13)
1006 mfspr r10,SPRN_DSISR
1007 stw r10,PACA_EXGEN+EX_DSISR(r13)
1008 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1009 ld r3,PACA_EXGEN+EX_DAR(r13)
1010 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1011 std r3,_DAR(r1)
1012 std r4,_DSISR(r1)
1013 bl save_nvgprs
1014 RECONCILE_IRQ_STATE(r10, r11)
1015 addi r3,r1,STACK_FRAME_OVERHEAD
1016 bl alignment_exception
1017 b ret_from_except
1018
1019 .align 7
1020 .globl program_check_common
1021 program_check_common:
1022 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1023 bl save_nvgprs
1024 RECONCILE_IRQ_STATE(r10, r11)
1025 addi r3,r1,STACK_FRAME_OVERHEAD
1026 bl program_check_exception
1027 b ret_from_except
1028
1029 .align 7
1030 .globl fp_unavailable_common
1031 fp_unavailable_common:
1032 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1033 bne 1f /* if from user, just load it up */
1034 bl save_nvgprs
1035 RECONCILE_IRQ_STATE(r10, r11)
1036 addi r3,r1,STACK_FRAME_OVERHEAD
1037 bl kernel_fp_unavailable_exception
1038 BUG_OPCODE
1039 1:
1040 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1041 BEGIN_FTR_SECTION
1042 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1043 * transaction), go do TM stuff
1044 */
1045 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1046 bne- 2f
1047 END_FTR_SECTION_IFSET(CPU_FTR_TM)
1048 #endif
1049 bl load_up_fpu
1050 b fast_exception_return
1051 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1052 2: /* User process was in a transaction */
1053 bl save_nvgprs
1054 RECONCILE_IRQ_STATE(r10, r11)
1055 addi r3,r1,STACK_FRAME_OVERHEAD
1056 bl fp_unavailable_tm
1057 b ret_from_except
1058 #endif
1059 .align 7
1060 .globl altivec_unavailable_common
1061 altivec_unavailable_common:
1062 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1063 #ifdef CONFIG_ALTIVEC
1064 BEGIN_FTR_SECTION
1065 beq 1f
1066 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1067 BEGIN_FTR_SECTION_NESTED(69)
1068 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1069 * transaction), go do TM stuff
1070 */
1071 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1072 bne- 2f
1073 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1074 #endif
1075 bl load_up_altivec
1076 b fast_exception_return
1077 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1078 2: /* User process was in a transaction */
1079 bl save_nvgprs
1080 RECONCILE_IRQ_STATE(r10, r11)
1081 addi r3,r1,STACK_FRAME_OVERHEAD
1082 bl altivec_unavailable_tm
1083 b ret_from_except
1084 #endif
1085 1:
1086 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1087 #endif
1088 bl save_nvgprs
1089 RECONCILE_IRQ_STATE(r10, r11)
1090 addi r3,r1,STACK_FRAME_OVERHEAD
1091 bl altivec_unavailable_exception
1092 b ret_from_except
1093
1094 .align 7
1095 .globl vsx_unavailable_common
1096 vsx_unavailable_common:
1097 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1098 #ifdef CONFIG_VSX
1099 BEGIN_FTR_SECTION
1100 beq 1f
1101 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1102 BEGIN_FTR_SECTION_NESTED(69)
1103 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1104 * transaction), go do TM stuff
1105 */
1106 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1107 bne- 2f
1108 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1109 #endif
1110 b load_up_vsx
1111 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1112 2: /* User process was in a transaction */
1113 bl save_nvgprs
1114 RECONCILE_IRQ_STATE(r10, r11)
1115 addi r3,r1,STACK_FRAME_OVERHEAD
1116 bl vsx_unavailable_tm
1117 b ret_from_except
1118 #endif
1119 1:
1120 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1121 #endif
1122 bl save_nvgprs
1123 RECONCILE_IRQ_STATE(r10, r11)
1124 addi r3,r1,STACK_FRAME_OVERHEAD
1125 bl vsx_unavailable_exception
1126 b ret_from_except
1127
1128 STD_EXCEPTION_COMMON(0xf60, facility_unavailable, facility_unavailable_exception)
1129 STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, facility_unavailable_exception)
1130
1131 .align 7
1132 .globl __end_handlers
1133 __end_handlers:
1134
1135 /* Equivalents to the above handlers for relocation-on interrupt vectors */
1136 STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
1137 MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
1138
1139 STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
1140 STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
1141 STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
1142 STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
1143 STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
1144
1145 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
1146 /*
1147 * Data area reserved for FWNMI option.
1148 * This address (0x7000) is fixed by the RPA.
1149 */
1150 .= 0x7000
1151 .globl fwnmi_data_area
1152 fwnmi_data_area:
1153
1154 /* pseries and powernv need to keep the whole page from
1155 * 0x7000 to 0x8000 free for use by the firmware
1156 */
1157 . = 0x8000
1158 #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
1159
1160 .globl hmi_exception_early
1161 hmi_exception_early:
1162 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0xe60)
1163 mr r10,r1 /* Save r1 */
1164 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
1165 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1166 std r9,_CCR(r1) /* save CR in stackframe */
1167 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
1168 std r11,_NIP(r1) /* save HSRR0 in stackframe */
1169 mfspr r12,SPRN_HSRR1 /* Save SRR1 */
1170 std r12,_MSR(r1) /* save SRR1 in stackframe */
1171 std r10,0(r1) /* make stack chain pointer */
1172 std r0,GPR0(r1) /* save r0 in stackframe */
1173 std r10,GPR1(r1) /* save r1 in stackframe */
1174 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1175 EXCEPTION_PROLOG_COMMON_3(0xe60)
1176 addi r3,r1,STACK_FRAME_OVERHEAD
1177 bl hmi_exception_realmode
1178 /* Windup the stack. */
1179 /* Move original HSRR0 and HSRR1 into the respective regs */
1180 ld r9,_MSR(r1)
1181 mtspr SPRN_HSRR1,r9
1182 ld r3,_NIP(r1)
1183 mtspr SPRN_HSRR0,r3
1184 ld r9,_CTR(r1)
1185 mtctr r9
1186 ld r9,_XER(r1)
1187 mtxer r9
1188 ld r9,_LINK(r1)
1189 mtlr r9
1190 REST_GPR(0, r1)
1191 REST_8GPRS(2, r1)
1192 REST_GPR(10, r1)
1193 ld r11,_CCR(r1)
1194 mtcr r11
1195 REST_GPR(11, r1)
1196 REST_2GPRS(12, r1)
1197 /* restore original r1. */
1198 ld r1,GPR1(r1)
1199
1200 /*
1201 * Go to virtual mode and pull the HMI event information from
1202 * firmware.
1203 */
1204 .globl hmi_exception_after_realmode
1205 hmi_exception_after_realmode:
1206 SET_SCRATCH0(r13)
1207 EXCEPTION_PROLOG_0(PACA_EXGEN)
1208 b hmi_exception_hv
1209
1210
1211 #define MACHINE_CHECK_HANDLER_WINDUP \
1212 /* Clear MSR_RI before setting SRR0 and SRR1. */\
1213 li r0,MSR_RI; \
1214 mfmsr r9; /* get MSR value */ \
1215 andc r9,r9,r0; \
1216 mtmsrd r9,1; /* Clear MSR_RI */ \
1217 /* Move original SRR0 and SRR1 into the respective regs */ \
1218 ld r9,_MSR(r1); \
1219 mtspr SPRN_SRR1,r9; \
1220 ld r3,_NIP(r1); \
1221 mtspr SPRN_SRR0,r3; \
1222 ld r9,_CTR(r1); \
1223 mtctr r9; \
1224 ld r9,_XER(r1); \
1225 mtxer r9; \
1226 ld r9,_LINK(r1); \
1227 mtlr r9; \
1228 REST_GPR(0, r1); \
1229 REST_8GPRS(2, r1); \
1230 REST_GPR(10, r1); \
1231 ld r11,_CCR(r1); \
1232 mtcr r11; \
1233 /* Decrement paca->in_mce. */ \
1234 lhz r12,PACA_IN_MCE(r13); \
1235 subi r12,r12,1; \
1236 sth r12,PACA_IN_MCE(r13); \
1237 REST_GPR(11, r1); \
1238 REST_2GPRS(12, r1); \
1239 /* restore original r1. */ \
1240 ld r1,GPR1(r1)
1241
1242 /*
1243 * Handle machine check early in real mode. We come here with
1244 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
1245 */
1246 .align 7
1247 .globl machine_check_handle_early
1248 machine_check_handle_early:
1249 std r0,GPR0(r1) /* Save r0 */
1250 EXCEPTION_PROLOG_COMMON_3(0x200)
1251 bl save_nvgprs
1252 addi r3,r1,STACK_FRAME_OVERHEAD
1253 bl machine_check_early
1254 std r3,RESULT(r1) /* Save result */
1255 ld r12,_MSR(r1)
1256 #ifdef CONFIG_PPC_P7_NAP
1257 /*
1258 * Check if thread was in power saving mode. We come here when any
1259 * of the following is true:
1260 * a. thread wasn't in power saving mode
1261 * b. thread was in power saving mode with no state loss or
1262 * supervisor state loss
1263 *
1264 * Go back to nap again if (b) is true.
1265 */
1266 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
1267 beq 4f /* No, it wasn;t */
1268 /* Thread was in power saving mode. Go back to nap again. */
1269 cmpwi r11,2
1270 bne 3f
1271 /* Supervisor state loss */
1272 li r0,1
1273 stb r0,PACA_NAPSTATELOST(r13)
1274 3: bl machine_check_queue_event
1275 MACHINE_CHECK_HANDLER_WINDUP
1276 GET_PACA(r13)
1277 ld r1,PACAR1(r13)
1278 li r3,PNV_THREAD_NAP
1279 b power7_enter_nap_mode
1280 4:
1281 #endif
1282 /*
1283 * Check if we are coming from hypervisor userspace. If yes then we
1284 * continue in host kernel in V mode to deliver the MC event.
1285 */
1286 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
1287 beq 5f
1288 andi. r11,r12,MSR_PR /* See if coming from user. */
1289 bne 9f /* continue in V mode if we are. */
1290
1291 5:
1292 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1293 /*
1294 * We are coming from kernel context. Check if we are coming from
1295 * guest. if yes, then we can continue. We will fall through
1296 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
1297 */
1298 lbz r11,HSTATE_IN_GUEST(r13)
1299 cmpwi r11,0 /* Check if coming from guest */
1300 bne 9f /* continue if we are. */
1301 #endif
1302 /*
1303 * At this point we are not sure about what context we come from.
1304 * Queue up the MCE event and return from the interrupt.
1305 * But before that, check if this is an un-recoverable exception.
1306 * If yes, then stay on emergency stack and panic.
1307 */
1308 andi. r11,r12,MSR_RI
1309 bne 2f
1310 1: mfspr r11,SPRN_SRR0
1311 ld r10,PACAKBASE(r13)
1312 LOAD_HANDLER(r10,unrecover_mce)
1313 mtspr SPRN_SRR0,r10
1314 ld r10,PACAKMSR(r13)
1315 /*
1316 * We are going down. But there are chances that we might get hit by
1317 * another MCE during panic path and we may run into unstable state
1318 * with no way out. Hence, turn ME bit off while going down, so that
1319 * when another MCE is hit during panic path, system will checkstop
1320 * and hypervisor will get restarted cleanly by SP.
1321 */
1322 li r3,MSR_ME
1323 andc r10,r10,r3 /* Turn off MSR_ME */
1324 mtspr SPRN_SRR1,r10
1325 rfid
1326 b .
1327 2:
1328 /*
1329 * Check if we have successfully handled/recovered from error, if not
1330 * then stay on emergency stack and panic.
1331 */
1332 ld r3,RESULT(r1) /* Load result */
1333 cmpdi r3,0 /* see if we handled MCE successfully */
1334
1335 beq 1b /* if !handled then panic */
1336 /*
1337 * Return from MC interrupt.
1338 * Queue up the MCE event so that we can log it later, while
1339 * returning from kernel or opal call.
1340 */
1341 bl machine_check_queue_event
1342 MACHINE_CHECK_HANDLER_WINDUP
1343 rfid
1344 9:
1345 /* Deliver the machine check to host kernel in V mode. */
1346 MACHINE_CHECK_HANDLER_WINDUP
1347 b machine_check_pSeries
1348
1349 unrecover_mce:
1350 /* Invoke machine_check_exception to print MCE event and panic. */
1351 addi r3,r1,STACK_FRAME_OVERHEAD
1352 bl machine_check_exception
1353 /*
1354 * We will not reach here. Even if we did, there is no way out. Call
1355 * unrecoverable_exception and die.
1356 */
1357 1: addi r3,r1,STACK_FRAME_OVERHEAD
1358 bl unrecoverable_exception
1359 b 1b
1360 /*
1361 * r13 points to the PACA, r9 contains the saved CR,
1362 * r12 contain the saved SRR1, SRR0 is still ready for return
1363 * r3 has the faulting address
1364 * r9 - r13 are saved in paca->exslb.
1365 * r3 is saved in paca->slb_r3
1366 * We assume we aren't going to take any exceptions during this procedure.
1367 */
1368 slb_miss_realmode:
1369 mflr r10
1370 #ifdef CONFIG_RELOCATABLE
1371 mtctr r11
1372 #endif
1373
1374 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1375 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1376
1377 bl slb_allocate_realmode
1378
1379 /* All done -- return from exception. */
1380
1381 ld r10,PACA_EXSLB+EX_LR(r13)
1382 ld r3,PACA_EXSLB+EX_R3(r13)
1383 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1384
1385 mtlr r10
1386
1387 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1388 beq- 2f
1389
1390 .machine push
1391 .machine "power4"
1392 mtcrf 0x80,r9
1393 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1394 .machine pop
1395
1396 RESTORE_PPR_PACA(PACA_EXSLB, r9)
1397 ld r9,PACA_EXSLB+EX_R9(r13)
1398 ld r10,PACA_EXSLB+EX_R10(r13)
1399 ld r11,PACA_EXSLB+EX_R11(r13)
1400 ld r12,PACA_EXSLB+EX_R12(r13)
1401 ld r13,PACA_EXSLB+EX_R13(r13)
1402 rfid
1403 b . /* prevent speculative execution */
1404
1405 2: mfspr r11,SPRN_SRR0
1406 ld r10,PACAKBASE(r13)
1407 LOAD_HANDLER(r10,unrecov_slb)
1408 mtspr SPRN_SRR0,r10
1409 ld r10,PACAKMSR(r13)
1410 mtspr SPRN_SRR1,r10
1411 rfid
1412 b .
1413
1414 unrecov_slb:
1415 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1416 RECONCILE_IRQ_STATE(r10, r11)
1417 bl save_nvgprs
1418 1: addi r3,r1,STACK_FRAME_OVERHEAD
1419 bl unrecoverable_exception
1420 b 1b
1421
1422
1423 #ifdef CONFIG_PPC_970_NAP
1424 power4_fixup_nap:
1425 andc r9,r9,r10
1426 std r9,TI_LOCAL_FLAGS(r11)
1427 ld r10,_LINK(r1) /* make idle task do the */
1428 std r10,_NIP(r1) /* equivalent of a blr */
1429 blr
1430 #endif
1431
1432 /*
1433 * Hash table stuff
1434 */
1435 .align 7
1436 do_hash_page:
1437 std r3,_DAR(r1)
1438 std r4,_DSISR(r1)
1439
1440 andis. r0,r4,0xa410 /* weird error? */
1441 bne- handle_page_fault /* if not, try to insert a HPTE */
1442 andis. r0,r4,DSISR_DABRMATCH@h
1443 bne- handle_dabr_fault
1444 CURRENT_THREAD_INFO(r11, r1)
1445 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1446 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1447 bne 77f /* then don't call hash_page now */
1448
1449 /*
1450 * r3 contains the faulting address
1451 * r4 msr
1452 * r5 contains the trap number
1453 * r6 contains dsisr
1454 *
1455 * at return r3 = 0 for success, 1 for page fault, negative for error
1456 */
1457 mr r4,r12
1458 ld r6,_DSISR(r1)
1459 bl __hash_page /* build HPTE if possible */
1460 cmpdi r3,0 /* see if __hash_page succeeded */
1461
1462 /* Success */
1463 beq fast_exc_return_irq /* Return from exception on success */
1464
1465 /* Error */
1466 blt- 13f
1467
1468 /* Here we have a page fault that hash_page can't handle. */
1469 handle_page_fault:
1470 11: ld r4,_DAR(r1)
1471 ld r5,_DSISR(r1)
1472 addi r3,r1,STACK_FRAME_OVERHEAD
1473 bl do_page_fault
1474 cmpdi r3,0
1475 beq+ 12f
1476 bl save_nvgprs
1477 mr r5,r3
1478 addi r3,r1,STACK_FRAME_OVERHEAD
1479 lwz r4,_DAR(r1)
1480 bl bad_page_fault
1481 b ret_from_except
1482
1483 /* We have a data breakpoint exception - handle it */
1484 handle_dabr_fault:
1485 bl save_nvgprs
1486 ld r4,_DAR(r1)
1487 ld r5,_DSISR(r1)
1488 addi r3,r1,STACK_FRAME_OVERHEAD
1489 bl do_break
1490 12: b ret_from_except_lite
1491
1492
1493 /* We have a page fault that hash_page could handle but HV refused
1494 * the PTE insertion
1495 */
1496 13: bl save_nvgprs
1497 mr r5,r3
1498 addi r3,r1,STACK_FRAME_OVERHEAD
1499 ld r4,_DAR(r1)
1500 bl low_hash_fault
1501 b ret_from_except
1502
1503 /*
1504 * We come here as a result of a DSI at a point where we don't want
1505 * to call hash_page, such as when we are accessing memory (possibly
1506 * user memory) inside a PMU interrupt that occurred while interrupts
1507 * were soft-disabled. We want to invoke the exception handler for
1508 * the access, or panic if there isn't a handler.
1509 */
1510 77: bl save_nvgprs
1511 mr r4,r3
1512 addi r3,r1,STACK_FRAME_OVERHEAD
1513 li r5,SIGSEGV
1514 bl bad_page_fault
1515 b ret_from_except
1516
1517 /*
1518 * Here we have detected that the kernel stack pointer is bad.
1519 * R9 contains the saved CR, r13 points to the paca,
1520 * r10 contains the (bad) kernel stack pointer,
1521 * r11 and r12 contain the saved SRR0 and SRR1.
1522 * We switch to using an emergency stack, save the registers there,
1523 * and call kernel_bad_stack(), which panics.
1524 */
1525 bad_stack:
1526 ld r1,PACAEMERGSP(r13)
1527 subi r1,r1,64+INT_FRAME_SIZE
1528 std r9,_CCR(r1)
1529 std r10,GPR1(r1)
1530 std r11,_NIP(r1)
1531 std r12,_MSR(r1)
1532 mfspr r11,SPRN_DAR
1533 mfspr r12,SPRN_DSISR
1534 std r11,_DAR(r1)
1535 std r12,_DSISR(r1)
1536 mflr r10
1537 mfctr r11
1538 mfxer r12
1539 std r10,_LINK(r1)
1540 std r11,_CTR(r1)
1541 std r12,_XER(r1)
1542 SAVE_GPR(0,r1)
1543 SAVE_GPR(2,r1)
1544 ld r10,EX_R3(r3)
1545 std r10,GPR3(r1)
1546 SAVE_GPR(4,r1)
1547 SAVE_4GPRS(5,r1)
1548 ld r9,EX_R9(r3)
1549 ld r10,EX_R10(r3)
1550 SAVE_2GPRS(9,r1)
1551 ld r9,EX_R11(r3)
1552 ld r10,EX_R12(r3)
1553 ld r11,EX_R13(r3)
1554 std r9,GPR11(r1)
1555 std r10,GPR12(r1)
1556 std r11,GPR13(r1)
1557 BEGIN_FTR_SECTION
1558 ld r10,EX_CFAR(r3)
1559 std r10,ORIG_GPR3(r1)
1560 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1561 SAVE_8GPRS(14,r1)
1562 SAVE_10GPRS(22,r1)
1563 lhz r12,PACA_TRAP_SAVE(r13)
1564 std r12,_TRAP(r1)
1565 addi r11,r1,INT_FRAME_SIZE
1566 std r11,0(r1)
1567 li r12,0
1568 std r12,0(r11)
1569 ld r2,PACATOC(r13)
1570 ld r11,exception_marker@toc(r2)
1571 std r12,RESULT(r1)
1572 std r11,STACK_FRAME_OVERHEAD-16(r1)
1573 1: addi r3,r1,STACK_FRAME_OVERHEAD
1574 bl kernel_bad_stack
1575 b 1b