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.
7 * This file is meant to be #included from head_64.S due to
8 * position dependent assembly.
10 * Most of this originates from head_64.S and thus has the same
15 #include <asm/hw_irq.h>
16 #include <asm/exception-64s.h>
17 #include <asm/ptrace.h>
18 #include <asm/cpuidle.h>
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
31 /* Syscall routine is used twice, in reloc-off and reloc-on paths */
32 #define SYSCALL_PSERIES_1 \
36 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
39 mfspr r11,SPRN_SRR0 ; \
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 ; \
50 b . ; /* prevent speculative execution */
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 */
60 #if defined(CONFIG_RELOCATABLE)
62 * We can't branch directly; in the direct case we use LR
63 * and system_call_entry restores LR. (We thus need to move
64 * LR to r10 in the RFID case too.)
66 #define SYSCALL_PSERIES_2_DIRECT \
68 ld r12,PACAKBASE(r13) ; \
69 LOAD_HANDLER(r12, system_call_entry_direct) ; \
71 mfspr r12,SPRN_SRR1 ; \
72 /* Re-use of r13... No spare regs to do this */ \
75 GET_PACA(r13) ; /* get r13 back */ \
78 /* We can branch directly */
79 #define SYSCALL_PSERIES_2_DIRECT \
80 mfspr r12,SPRN_SRR1 ; \
82 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
83 b system_call_entry_direct ;
87 * This is the start of the interrupt handlers for pSeries
88 * This code runs with relocation off.
89 * Code from here to __end_interrupts gets copied down to real
90 * address 0x100 when we are running a relocatable kernel.
91 * Therefore any relative branches in this section must only
92 * branch to labels in this section.
95 .globl __start_interrupts
98 .globl system_reset_pSeries;
100 HMT_MEDIUM_PPR_DISCARD
102 #ifdef CONFIG_PPC_P7_NAP
104 /* Running native on arch 2.06 or later, check if we are
105 * waking up from nap/sleep/winkle.
108 rlwinm. r13,r13,47-31,30,31
114 * Check if last bit of HSPGR0 is set. This indicates whether we are
115 * waking up from winkle.
121 mtspr SPRN_HSPRG0,r13
123 lbz r0,PACA_THREAD_IDLE_STATE(r13)
124 cmpwi cr2,r0,PNV_THREAD_NAP
125 bgt cr2,8f /* Either sleep or Winkle */
127 /* Waking up from nap should not cause hypervisor state loss */
130 /* Waking up from nap */
131 li r0,PNV_THREAD_RUNNING
132 stb r0,PACA_THREAD_IDLE_STATE(r13) /* Clear thread state */
134 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
135 li r0,KVM_HWTHREAD_IN_KERNEL
136 stb r0,HSTATE_HWTHREAD_STATE(r13)
137 /* Order setting hwthread_state vs. testing hwthread_req */
139 lbz r0,HSTATE_HWTHREAD_REQ(r13)
146 /* Return SRR1 from power7_nap() */
149 b power7_wakeup_noloss
150 2: b power7_wakeup_loss
152 /* Fast Sleep wakeup on PowerNV */
154 b power7_wakeup_tb_loss
157 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
158 #endif /* CONFIG_PPC_P7_NAP */
159 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
163 machine_check_pSeries_1:
164 /* This is moved out of line as it can be patched by FW, but
165 * some code path might still want to branch into the original
168 HMT_MEDIUM_PPR_DISCARD
169 SET_SCRATCH0(r13) /* save r13 */
170 #ifdef CONFIG_PPC_P7_NAP
172 /* Running native on arch 2.06 or later, check if we are
173 * waking up from nap. We only handle no state loss and
174 * supervisor state loss. We do -not- handle hypervisor
175 * state loss at this time.
178 rlwinm. r13,r13,47-31,30,31
179 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
183 rlwinm. r13,r13,47-31,30,31
184 /* waking up from powersave (nap) state */
186 /* Total loss of HV state is fatal. let's just stay stuck here */
187 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
190 OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
191 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
192 #endif /* CONFIG_PPC_P7_NAP */
193 EXCEPTION_PROLOG_0(PACA_EXMC)
195 b machine_check_pSeries_early
197 b machine_check_pSeries_0
198 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
201 .globl data_access_pSeries
203 HMT_MEDIUM_PPR_DISCARD
205 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
209 .globl data_access_slb_pSeries
210 data_access_slb_pSeries:
211 HMT_MEDIUM_PPR_DISCARD
213 EXCEPTION_PROLOG_0(PACA_EXSLB)
214 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
215 std r3,PACA_EXSLB+EX_R3(r13)
218 /* Keep that around for when we re-implement dynamic VSIDs */
220 bge slb_miss_user_pseries
221 #endif /* __DISABLED__ */
223 #ifndef CONFIG_RELOCATABLE
227 * We can't just use a direct branch to slb_miss_realmode
228 * because the distance from here to there depends on where
229 * the kernel ends up being put.
232 ld r10,PACAKBASE(r13)
233 LOAD_HANDLER(r10, slb_miss_realmode)
238 STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
241 .globl instruction_access_slb_pSeries
242 instruction_access_slb_pSeries:
243 HMT_MEDIUM_PPR_DISCARD
245 EXCEPTION_PROLOG_0(PACA_EXSLB)
246 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
247 std r3,PACA_EXSLB+EX_R3(r13)
248 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
250 /* Keep that around for when we re-implement dynamic VSIDs */
252 bge slb_miss_user_pseries
253 #endif /* __DISABLED__ */
255 #ifndef CONFIG_RELOCATABLE
259 ld r10,PACAKBASE(r13)
260 LOAD_HANDLER(r10, slb_miss_realmode)
265 /* We open code these as we can't have a ". = x" (even with
266 * x = "." within a feature section
269 .globl hardware_interrupt_pSeries;
270 .globl hardware_interrupt_hv;
271 hardware_interrupt_pSeries:
272 hardware_interrupt_hv:
273 HMT_MEDIUM_PPR_DISCARD
275 _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
276 EXC_HV, SOFTEN_TEST_HV)
277 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
279 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
280 EXC_STD, SOFTEN_TEST_HV_201)
281 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
282 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
284 STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
285 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
287 STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
288 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
290 STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
291 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
294 .globl decrementer_pSeries
296 _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
298 STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
300 MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
301 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
303 STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
304 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
307 .globl system_call_pSeries
310 * If CONFIG_KVM_BOOK3S_64_HANDLER is set, save the PPR (on systems
311 * that support it) before changing to HMT_MEDIUM. That allows the KVM
312 * code to save that value into the guest state (it is the guest's PPR
313 * value). Otherwise just change to HMT_MEDIUM as userspace has
314 * already saved the PPR.
316 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
319 std r9,PACA_EXGEN+EX_R9(r13)
320 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR);
322 std r10,PACA_EXGEN+EX_R10(r13)
323 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r9, CPU_FTR_HAS_PPR);
331 SYSCALL_PSERIES_2_RFID
333 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
335 STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
336 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
338 /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
339 * out of line to handle them
342 hv_data_storage_trampoline:
344 EXCEPTION_PROLOG_0(PACA_EXGEN)
348 hv_instr_storage_trampoline:
350 EXCEPTION_PROLOG_0(PACA_EXGEN)
354 emulation_assist_trampoline:
356 EXCEPTION_PROLOG_0(PACA_EXGEN)
357 b emulation_assist_hv
360 hv_exception_trampoline:
362 EXCEPTION_PROLOG_0(PACA_EXGEN)
363 b hmi_exception_early
366 hv_doorbell_trampoline:
368 EXCEPTION_PROLOG_0(PACA_EXGEN)
371 /* We need to deal with the Altivec unavailable exception
372 * here which is at 0xf20, thus in the middle of the
373 * prolog code of the PerformanceMonitor one. A little
374 * trickery is thus necessary
377 performance_monitor_pseries_trampoline:
379 EXCEPTION_PROLOG_0(PACA_EXGEN)
380 b performance_monitor_pSeries
383 altivec_unavailable_pseries_trampoline:
385 EXCEPTION_PROLOG_0(PACA_EXGEN)
386 b altivec_unavailable_pSeries
389 vsx_unavailable_pseries_trampoline:
391 EXCEPTION_PROLOG_0(PACA_EXGEN)
392 b vsx_unavailable_pSeries
395 facility_unavailable_trampoline:
397 EXCEPTION_PROLOG_0(PACA_EXGEN)
398 b facility_unavailable_pSeries
401 hv_facility_unavailable_trampoline:
403 EXCEPTION_PROLOG_0(PACA_EXGEN)
404 b facility_unavailable_hv
406 #ifdef CONFIG_CBE_RAS
407 STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
408 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
409 #endif /* CONFIG_CBE_RAS */
411 STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
412 KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
415 .global denorm_exception_hv
417 HMT_MEDIUM_PPR_DISCARD
418 mtspr SPRN_SPRG_HSCRATCH0,r13
419 EXCEPTION_PROLOG_0(PACA_EXGEN)
420 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
422 #ifdef CONFIG_PPC_DENORMALISATION
424 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
425 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
426 addi r11,r11,-4 /* HSRR0 is next instruction */
431 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
432 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
434 #ifdef CONFIG_CBE_RAS
435 STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
436 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
437 #endif /* CONFIG_CBE_RAS */
439 STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
440 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
442 #ifdef CONFIG_CBE_RAS
443 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
444 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
447 #endif /* CONFIG_CBE_RAS */
450 /*** Out of line interrupts support ***/
453 /* moved from 0x200 */
454 machine_check_pSeries_early:
456 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
461 * Original R9 to R13 is saved on PACA_EXMC
463 * Switch to mc_emergency stack and handle re-entrancy (we limit
464 * the nested MCE upto level 4 to avoid stack overflow).
465 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
467 * We use paca->in_mce to check whether this is the first entry or
468 * nested machine check. We increment paca->in_mce to track nested
471 * If this is the first entry then set stack pointer to
472 * paca->mc_emergency_sp, otherwise r1 is already pointing to
473 * stack frame on mc_emergency stack.
475 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
476 * checkstop if we get another machine check exception before we do
477 * rfid with MSR_ME=1.
479 mr r11,r1 /* Save r1 */
480 lhz r10,PACA_IN_MCE(r13)
481 cmpwi r10,0 /* Are we in nested machine check */
482 bne 0f /* Yes, we are. */
483 /* First machine check entry */
484 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
485 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
486 addi r10,r10,1 /* increment paca->in_mce */
487 sth r10,PACA_IN_MCE(r13)
488 /* Limit nested MCE to level 4 to avoid stack overflow */
490 bgt 2f /* Check if we hit limit of 4 */
491 std r11,GPR1(r1) /* Save r1 on the stack. */
492 std r11,0(r1) /* make stack chain pointer */
493 mfspr r11,SPRN_SRR0 /* Save SRR0 */
495 mfspr r11,SPRN_SRR1 /* Save SRR1 */
497 mfspr r11,SPRN_DAR /* Save DAR */
499 mfspr r11,SPRN_DSISR /* Save DSISR */
501 std r9,_CCR(r1) /* Save CR in stackframe */
502 /* Save r9 through r13 from EXMC save area to stack frame. */
503 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
504 mfmsr r11 /* get MSR value */
505 ori r11,r11,MSR_ME /* turn on ME bit */
506 ori r11,r11,MSR_RI /* turn on RI bit */
507 ld r12,PACAKBASE(r13) /* get high part of &label */
508 LOAD_HANDLER(r12, machine_check_handle_early)
509 1: mtspr SPRN_SRR0,r12
512 b . /* prevent speculative execution */
514 /* Stack overflow. Stay on emergency stack and panic.
515 * Keep the ME bit off while panic-ing, so that if we hit
516 * another machine check we checkstop.
518 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
520 ld r12,PACAKBASE(r13)
521 LOAD_HANDLER(r12, unrecover_mce)
523 andc r11,r11,r10 /* Turn off MSR_ME */
525 b . /* prevent speculative execution */
526 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
528 machine_check_pSeries:
529 .globl machine_check_fwnmi
531 HMT_MEDIUM_PPR_DISCARD
532 SET_SCRATCH0(r13) /* save r13 */
533 EXCEPTION_PROLOG_0(PACA_EXMC)
534 machine_check_pSeries_0:
535 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
536 EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
537 KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
538 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
539 KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
540 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
541 KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
542 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
543 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
545 #ifdef CONFIG_PPC_DENORMALISATION
549 * To denormalise we need to move a copy of the register to itself.
550 * For POWER6 do that here for all FP regs.
553 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
554 xori r10,r10,(MSR_FE0|MSR_FE1)
558 #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
559 #define FMR4(n) FMR2(n) ; FMR2(n+2)
560 #define FMR8(n) FMR4(n) ; FMR4(n+4)
561 #define FMR16(n) FMR8(n) ; FMR8(n+8)
562 #define FMR32(n) FMR16(n) ; FMR16(n+16)
567 * To denormalise we need to move a copy of the register to itself.
568 * For POWER7 do that here for the first 32 VSX registers only.
571 oris r10,r10,MSR_VSX@h
575 #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
576 #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
577 #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
578 #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
579 #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
582 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
586 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
588 * To denormalise we need to move a copy of the register to itself.
589 * For POWER8 we need to do that for all 64 VSX registers
595 ld r9,PACA_EXGEN+EX_R9(r13)
596 RESTORE_PPR_PACA(PACA_EXGEN, r10)
598 ld r10,PACA_EXGEN+EX_CFAR(r13)
600 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
601 ld r10,PACA_EXGEN+EX_R10(r13)
602 ld r11,PACA_EXGEN+EX_R11(r13)
603 ld r12,PACA_EXGEN+EX_R12(r13)
604 ld r13,PACA_EXGEN+EX_R13(r13)
610 /* moved from 0xe00 */
611 STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
612 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
613 STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
614 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
615 STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
616 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
617 MASKABLE_EXCEPTION_HV_OOL(0xe62, hmi_exception)
618 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
620 MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
621 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
623 /* moved from 0xf00 */
624 STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
625 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
626 STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
627 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
628 STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
629 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
630 STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
631 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf60)
632 STD_EXCEPTION_HV_OOL(0xf82, facility_unavailable)
633 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xf82)
636 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
637 * - If it was a decrementer interrupt, we bump the dec to max and and return.
638 * - If it was a doorbell we return immediately since doorbells are edge
639 * triggered and won't automatically refire.
640 * - If it was a HMI we return immediately since we handled it in realmode
641 * and it won't refire.
642 * - else we hard disable and return.
643 * This is called with r10 containing the value to OR to the paca field.
645 #define MASKED_INTERRUPT(_H) \
646 masked_##_H##interrupt: \
647 std r11,PACA_EXGEN+EX_R11(r13); \
648 lbz r11,PACAIRQHAPPENED(r13); \
650 stb r11,PACAIRQHAPPENED(r13); \
651 cmpwi r10,PACA_IRQ_DEC; \
654 ori r10,r10,0xffff; \
655 mtspr SPRN_DEC,r10; \
657 1: cmpwi r10,PACA_IRQ_DBELL; \
659 cmpwi r10,PACA_IRQ_HMI; \
661 mfspr r10,SPRN_##_H##SRR1; \
662 rldicl r10,r10,48,1; /* clear MSR_EE */ \
664 mtspr SPRN_##_H##SRR1,r10; \
666 ld r9,PACA_EXGEN+EX_R9(r13); \
667 ld r10,PACA_EXGEN+EX_R10(r13); \
668 ld r11,PACA_EXGEN+EX_R11(r13); \
677 * Called from arch_local_irq_enable when an interrupt needs
678 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
679 * which kind of interrupt. MSR:EE is already off. We generate a
680 * stackframe like if a real interrupt had happened.
682 * Note: While MSR:EE is off, we need to make sure that _MSR
683 * in the generated frame has EE set to 1 or the exception
684 * handler will not properly re-enable them.
686 _GLOBAL(__replay_interrupt)
687 /* We are going to jump to the exception common code which
688 * will retrieve various register values from the PACA which
689 * we don't give a damn about, so we don't bother storing them.
696 beq decrementer_common
698 beq hardware_interrupt_common
701 beq h_doorbell_common
704 beq doorbell_super_common
705 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
708 #ifdef CONFIG_PPC_PSERIES
710 * Vectors for the FWNMI option. Share common code.
712 .globl system_reset_fwnmi
715 HMT_MEDIUM_PPR_DISCARD
716 SET_SCRATCH0(r13) /* save r13 */
717 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
720 #endif /* CONFIG_PPC_PSERIES */
724 * This is used for when the SLB miss handler has to go virtual,
725 * which doesn't happen for now anymore but will once we re-implement
726 * dynamic VSIDs for shared page tables
728 slb_miss_user_pseries:
729 std r10,PACA_EXGEN+EX_R10(r13)
730 std r11,PACA_EXGEN+EX_R11(r13)
731 std r12,PACA_EXGEN+EX_R12(r13)
733 ld r11,PACA_EXSLB+EX_R9(r13)
734 ld r12,PACA_EXSLB+EX_R3(r13)
735 std r10,PACA_EXGEN+EX_R13(r13)
736 std r11,PACA_EXGEN+EX_R9(r13)
737 std r12,PACA_EXGEN+EX_R3(r13)
740 mfspr r11,SRR0 /* save SRR0 */
741 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
742 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
744 mfspr r12,SRR1 /* and SRR1 */
747 b . /* prevent spec. execution */
748 #endif /* __DISABLED__ */
750 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
751 kvmppc_skip_interrupt:
753 * Here all GPRs are unchanged from when the interrupt happened
754 * except for r13, which is saved in SPRG_SCRATCH0.
763 kvmppc_skip_Hinterrupt:
765 * Here all GPRs are unchanged from when the interrupt happened
766 * except for r13, which is saved in SPRG_SCRATCH0.
768 mfspr r13, SPRN_HSRR0
770 mtspr SPRN_HSRR0, r13
777 * Code from here down to __end_handlers is invoked from the
778 * exception prologs above. Because the prologs assemble the
779 * addresses of these handlers using the LOAD_HANDLER macro,
780 * which uses an ori instruction, these handlers must be in
781 * the first 64k of the kernel image.
784 /*** Common interrupt handlers ***/
786 STD_EXCEPTION_COMMON(0x100, system_reset, system_reset_exception)
788 STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
789 STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, timer_interrupt)
790 STD_EXCEPTION_COMMON(0x980, hdecrementer, hdec_interrupt)
791 #ifdef CONFIG_PPC_DOORBELL
792 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, doorbell_exception)
794 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, unknown_exception)
796 STD_EXCEPTION_COMMON(0xb00, trap_0b, unknown_exception)
797 STD_EXCEPTION_COMMON(0xd00, single_step, single_step_exception)
798 STD_EXCEPTION_COMMON(0xe00, trap_0e, unknown_exception)
799 STD_EXCEPTION_COMMON(0xe40, emulation_assist, emulation_assist_interrupt)
800 STD_EXCEPTION_COMMON_ASYNC(0xe60, hmi_exception, handle_hmi_exception)
801 #ifdef CONFIG_PPC_DOORBELL
802 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, doorbell_exception)
804 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, unknown_exception)
806 STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, performance_monitor_exception)
807 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, instruction_breakpoint_exception)
808 STD_EXCEPTION_COMMON(0x1502, denorm, unknown_exception)
809 #ifdef CONFIG_ALTIVEC
810 STD_EXCEPTION_COMMON(0x1700, altivec_assist, altivec_assist_exception)
812 STD_EXCEPTION_COMMON(0x1700, altivec_assist, unknown_exception)
814 #ifdef CONFIG_CBE_RAS
815 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, cbe_system_error_exception)
816 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, cbe_maintenance_exception)
817 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, cbe_thermal_exception)
818 #endif /* CONFIG_CBE_RAS */
821 * Relocation-on interrupts: A subset of the interrupts can be delivered
822 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
823 * it. Addresses are the same as the original interrupt addresses, but
824 * offset by 0xc000000000004000.
825 * It's impossible to receive interrupts below 0x300 via this mechanism.
826 * KVM: None of these traps are from the guest ; anything that escalated
827 * to HV=1 from HV=0 is delivered via real mode handlers.
831 * This uses the standard macro, since the original 0x300 vector
832 * only has extra guff for STAB-based processors -- which never
835 STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
837 .globl data_access_slb_relon_pSeries
838 data_access_slb_relon_pSeries:
840 EXCEPTION_PROLOG_0(PACA_EXSLB)
841 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
842 std r3,PACA_EXSLB+EX_R3(r13)
845 #ifndef CONFIG_RELOCATABLE
849 * We can't just use a direct branch to slb_miss_realmode
850 * because the distance from here to there depends on where
851 * the kernel ends up being put.
854 ld r10,PACAKBASE(r13)
855 LOAD_HANDLER(r10, slb_miss_realmode)
860 STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
862 .globl instruction_access_slb_relon_pSeries
863 instruction_access_slb_relon_pSeries:
865 EXCEPTION_PROLOG_0(PACA_EXSLB)
866 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
867 std r3,PACA_EXSLB+EX_R3(r13)
868 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
870 #ifndef CONFIG_RELOCATABLE
874 ld r10,PACAKBASE(r13)
875 LOAD_HANDLER(r10, slb_miss_realmode)
881 .globl hardware_interrupt_relon_pSeries;
882 .globl hardware_interrupt_relon_hv;
883 hardware_interrupt_relon_pSeries:
884 hardware_interrupt_relon_hv:
886 _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
888 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
889 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
890 STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
891 STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
892 STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
893 MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
894 STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
895 MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
896 STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
899 .globl system_call_relon_pSeries
900 system_call_relon_pSeries:
903 SYSCALL_PSERIES_2_DIRECT
906 STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
909 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
912 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
915 emulation_assist_relon_trampoline:
917 EXCEPTION_PROLOG_0(PACA_EXGEN)
918 b emulation_assist_relon_hv
921 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
924 h_doorbell_relon_trampoline:
926 EXCEPTION_PROLOG_0(PACA_EXGEN)
927 b h_doorbell_relon_hv
930 performance_monitor_relon_pseries_trampoline:
932 EXCEPTION_PROLOG_0(PACA_EXGEN)
933 b performance_monitor_relon_pSeries
936 altivec_unavailable_relon_pseries_trampoline:
938 EXCEPTION_PROLOG_0(PACA_EXGEN)
939 b altivec_unavailable_relon_pSeries
942 vsx_unavailable_relon_pseries_trampoline:
944 EXCEPTION_PROLOG_0(PACA_EXGEN)
945 b vsx_unavailable_relon_pSeries
948 facility_unavailable_relon_trampoline:
950 EXCEPTION_PROLOG_0(PACA_EXGEN)
951 b facility_unavailable_relon_pSeries
954 hv_facility_unavailable_relon_trampoline:
956 EXCEPTION_PROLOG_0(PACA_EXGEN)
957 b hv_facility_unavailable_relon_hv
959 STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
960 #ifdef CONFIG_PPC_DENORMALISATION
962 b denorm_exception_hv
964 STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
967 system_call_entry_direct:
968 #if defined(CONFIG_RELOCATABLE)
969 /* The first level prologue may have used LR to get here, saving
970 * orig in r10. To save hacking/ifdeffing common code, restore here.
977 ppc64_runlatch_on_trampoline:
978 b __ppc64_runlatch_on
981 * Here r13 points to the paca, r9 contains the saved CR,
982 * SRR0 and SRR1 are saved in r11 and r12,
983 * r9 - r13 are saved in paca->exgen.
986 .globl data_access_common
989 std r10,PACA_EXGEN+EX_DAR(r13)
991 stw r10,PACA_EXGEN+EX_DSISR(r13)
992 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
993 RECONCILE_IRQ_STATE(r10, r11)
995 ld r3,PACA_EXGEN+EX_DAR(r13)
996 lwz r4,PACA_EXGEN+EX_DSISR(r13)
998 b do_hash_page /* Try to handle as hpte fault */
1001 .globl h_data_storage_common
1002 h_data_storage_common:
1004 std r10,PACA_EXGEN+EX_DAR(r13)
1005 mfspr r10,SPRN_HDSISR
1006 stw r10,PACA_EXGEN+EX_DSISR(r13)
1007 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1009 RECONCILE_IRQ_STATE(r10, r11)
1010 addi r3,r1,STACK_FRAME_OVERHEAD
1011 bl unknown_exception
1015 .globl instruction_access_common
1016 instruction_access_common:
1017 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
1018 RECONCILE_IRQ_STATE(r10, r11)
1021 andis. r4,r12,0x5820
1023 b do_hash_page /* Try to handle as hpte fault */
1025 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
1028 * Here is the common SLB miss user that is used when going to virtual
1029 * mode for SLB misses, that is currently not used
1033 .globl slb_miss_user_common
1034 slb_miss_user_common:
1036 std r3,PACA_EXGEN+EX_DAR(r13)
1037 stw r9,PACA_EXGEN+EX_CCR(r13)
1038 std r10,PACA_EXGEN+EX_LR(r13)
1039 std r11,PACA_EXGEN+EX_SRR0(r13)
1040 bl slb_allocate_user
1042 ld r10,PACA_EXGEN+EX_LR(r13)
1043 ld r3,PACA_EXGEN+EX_R3(r13)
1044 lwz r9,PACA_EXGEN+EX_CCR(r13)
1045 ld r11,PACA_EXGEN+EX_SRR0(r13)
1049 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1050 beq- unrecov_user_slb
1058 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1064 ld r9,PACA_EXGEN+EX_R9(r13)
1065 ld r10,PACA_EXGEN+EX_R10(r13)
1066 ld r11,PACA_EXGEN+EX_R11(r13)
1067 ld r12,PACA_EXGEN+EX_R12(r13)
1068 ld r13,PACA_EXGEN+EX_R13(r13)
1073 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1074 ld r4,PACA_EXGEN+EX_DAR(r13)
1081 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1082 RECONCILE_IRQ_STATE(r10, r11)
1084 1: addi r3,r1,STACK_FRAME_OVERHEAD
1085 bl unrecoverable_exception
1088 #endif /* __DISABLED__ */
1092 * Machine check is different because we use a different
1093 * save area: PACA_EXMC instead of PACA_EXGEN.
1096 .globl machine_check_common
1097 machine_check_common:
1100 std r10,PACA_EXGEN+EX_DAR(r13)
1101 mfspr r10,SPRN_DSISR
1102 stw r10,PACA_EXGEN+EX_DSISR(r13)
1103 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
1105 RECONCILE_IRQ_STATE(r10, r11)
1106 ld r3,PACA_EXGEN+EX_DAR(r13)
1107 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1111 addi r3,r1,STACK_FRAME_OVERHEAD
1112 bl machine_check_exception
1116 .globl alignment_common
1119 std r10,PACA_EXGEN+EX_DAR(r13)
1120 mfspr r10,SPRN_DSISR
1121 stw r10,PACA_EXGEN+EX_DSISR(r13)
1122 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1123 ld r3,PACA_EXGEN+EX_DAR(r13)
1124 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1128 RECONCILE_IRQ_STATE(r10, r11)
1129 addi r3,r1,STACK_FRAME_OVERHEAD
1130 bl alignment_exception
1134 .globl program_check_common
1135 program_check_common:
1136 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1138 RECONCILE_IRQ_STATE(r10, r11)
1139 addi r3,r1,STACK_FRAME_OVERHEAD
1140 bl program_check_exception
1144 .globl fp_unavailable_common
1145 fp_unavailable_common:
1146 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1147 bne 1f /* if from user, just load it up */
1149 RECONCILE_IRQ_STATE(r10, r11)
1150 addi r3,r1,STACK_FRAME_OVERHEAD
1151 bl kernel_fp_unavailable_exception
1154 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1156 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1157 * transaction), go do TM stuff
1159 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1161 END_FTR_SECTION_IFSET(CPU_FTR_TM)
1164 b fast_exception_return
1165 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1166 2: /* User process was in a transaction */
1168 RECONCILE_IRQ_STATE(r10, r11)
1169 addi r3,r1,STACK_FRAME_OVERHEAD
1170 bl fp_unavailable_tm
1174 .globl altivec_unavailable_common
1175 altivec_unavailable_common:
1176 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1177 #ifdef CONFIG_ALTIVEC
1180 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1181 BEGIN_FTR_SECTION_NESTED(69)
1182 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1183 * transaction), go do TM stuff
1185 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1187 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1190 b fast_exception_return
1191 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1192 2: /* User process was in a transaction */
1194 RECONCILE_IRQ_STATE(r10, r11)
1195 addi r3,r1,STACK_FRAME_OVERHEAD
1196 bl altivec_unavailable_tm
1200 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1203 RECONCILE_IRQ_STATE(r10, r11)
1204 addi r3,r1,STACK_FRAME_OVERHEAD
1205 bl altivec_unavailable_exception
1209 .globl vsx_unavailable_common
1210 vsx_unavailable_common:
1211 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1215 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1216 BEGIN_FTR_SECTION_NESTED(69)
1217 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1218 * transaction), go do TM stuff
1220 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1222 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1225 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1226 2: /* User process was in a transaction */
1228 RECONCILE_IRQ_STATE(r10, r11)
1229 addi r3,r1,STACK_FRAME_OVERHEAD
1230 bl vsx_unavailable_tm
1234 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1237 RECONCILE_IRQ_STATE(r10, r11)
1238 addi r3,r1,STACK_FRAME_OVERHEAD
1239 bl vsx_unavailable_exception
1242 STD_EXCEPTION_COMMON(0xf60, facility_unavailable, facility_unavailable_exception)
1243 STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, facility_unavailable_exception)
1246 .globl __end_handlers
1249 /* Equivalents to the above handlers for relocation-on interrupt vectors */
1250 STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
1251 MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
1253 STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
1254 STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
1255 STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
1256 STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
1257 STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
1260 * The __end_interrupts marker must be past the out-of-line (OOL)
1261 * handlers, so that they are copied to real address 0x100 when running
1262 * a relocatable kernel. This ensures they can be reached from the short
1263 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
1264 * directly, without using LOAD_HANDLER().
1267 .globl __end_interrupts
1270 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
1272 * Data area reserved for FWNMI option.
1273 * This address (0x7000) is fixed by the RPA.
1276 .globl fwnmi_data_area
1279 /* pseries and powernv need to keep the whole page from
1280 * 0x7000 to 0x8000 free for use by the firmware
1283 #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
1285 .globl hmi_exception_early
1286 hmi_exception_early:
1287 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0xe60)
1288 mr r10,r1 /* Save r1 */
1289 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
1290 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1291 std r9,_CCR(r1) /* save CR in stackframe */
1292 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
1293 std r11,_NIP(r1) /* save HSRR0 in stackframe */
1294 mfspr r12,SPRN_HSRR1 /* Save SRR1 */
1295 std r12,_MSR(r1) /* save SRR1 in stackframe */
1296 std r10,0(r1) /* make stack chain pointer */
1297 std r0,GPR0(r1) /* save r0 in stackframe */
1298 std r10,GPR1(r1) /* save r1 in stackframe */
1299 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1300 EXCEPTION_PROLOG_COMMON_3(0xe60)
1301 addi r3,r1,STACK_FRAME_OVERHEAD
1302 bl hmi_exception_realmode
1303 /* Windup the stack. */
1304 /* Move original HSRR0 and HSRR1 into the respective regs */
1322 /* restore original r1. */
1326 * Go to virtual mode and pull the HMI event information from
1329 .globl hmi_exception_after_realmode
1330 hmi_exception_after_realmode:
1332 EXCEPTION_PROLOG_0(PACA_EXGEN)
1336 #define MACHINE_CHECK_HANDLER_WINDUP \
1337 /* Clear MSR_RI before setting SRR0 and SRR1. */\
1339 mfmsr r9; /* get MSR value */ \
1341 mtmsrd r9,1; /* Clear MSR_RI */ \
1342 /* Move original SRR0 and SRR1 into the respective regs */ \
1344 mtspr SPRN_SRR1,r9; \
1346 mtspr SPRN_SRR0,r3; \
1354 REST_8GPRS(2, r1); \
1358 /* Decrement paca->in_mce. */ \
1359 lhz r12,PACA_IN_MCE(r13); \
1361 sth r12,PACA_IN_MCE(r13); \
1363 REST_2GPRS(12, r1); \
1364 /* restore original r1. */ \
1368 * Handle machine check early in real mode. We come here with
1369 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
1372 .globl machine_check_handle_early
1373 machine_check_handle_early:
1374 std r0,GPR0(r1) /* Save r0 */
1375 EXCEPTION_PROLOG_COMMON_3(0x200)
1377 addi r3,r1,STACK_FRAME_OVERHEAD
1378 bl machine_check_early
1379 std r3,RESULT(r1) /* Save result */
1381 #ifdef CONFIG_PPC_P7_NAP
1383 * Check if thread was in power saving mode. We come here when any
1384 * of the following is true:
1385 * a. thread wasn't in power saving mode
1386 * b. thread was in power saving mode with no state loss or
1387 * supervisor state loss
1389 * Go back to nap again if (b) is true.
1391 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
1392 beq 4f /* No, it wasn;t */
1393 /* Thread was in power saving mode. Go back to nap again. */
1396 /* Supervisor state loss */
1398 stb r0,PACA_NAPSTATELOST(r13)
1399 3: bl machine_check_queue_event
1400 MACHINE_CHECK_HANDLER_WINDUP
1403 li r3,PNV_THREAD_NAP
1404 b power7_enter_nap_mode
1408 * Check if we are coming from hypervisor userspace. If yes then we
1409 * continue in host kernel in V mode to deliver the MC event.
1411 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
1413 andi. r11,r12,MSR_PR /* See if coming from user. */
1414 bne 9f /* continue in V mode if we are. */
1417 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1419 * We are coming from kernel context. Check if we are coming from
1420 * guest. if yes, then we can continue. We will fall through
1421 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
1423 lbz r11,HSTATE_IN_GUEST(r13)
1424 cmpwi r11,0 /* Check if coming from guest */
1425 bne 9f /* continue if we are. */
1428 * At this point we are not sure about what context we come from.
1429 * Queue up the MCE event and return from the interrupt.
1430 * But before that, check if this is an un-recoverable exception.
1431 * If yes, then stay on emergency stack and panic.
1433 andi. r11,r12,MSR_RI
1435 1: mfspr r11,SPRN_SRR0
1436 ld r10,PACAKBASE(r13)
1437 LOAD_HANDLER(r10,unrecover_mce)
1439 ld r10,PACAKMSR(r13)
1441 * We are going down. But there are chances that we might get hit by
1442 * another MCE during panic path and we may run into unstable state
1443 * with no way out. Hence, turn ME bit off while going down, so that
1444 * when another MCE is hit during panic path, system will checkstop
1445 * and hypervisor will get restarted cleanly by SP.
1448 andc r10,r10,r3 /* Turn off MSR_ME */
1454 * Check if we have successfully handled/recovered from error, if not
1455 * then stay on emergency stack and panic.
1457 ld r3,RESULT(r1) /* Load result */
1458 cmpdi r3,0 /* see if we handled MCE successfully */
1460 beq 1b /* if !handled then panic */
1462 * Return from MC interrupt.
1463 * Queue up the MCE event so that we can log it later, while
1464 * returning from kernel or opal call.
1466 bl machine_check_queue_event
1467 MACHINE_CHECK_HANDLER_WINDUP
1470 /* Deliver the machine check to host kernel in V mode. */
1471 MACHINE_CHECK_HANDLER_WINDUP
1472 b machine_check_pSeries
1475 /* Invoke machine_check_exception to print MCE event and panic. */
1476 addi r3,r1,STACK_FRAME_OVERHEAD
1477 bl machine_check_exception
1479 * We will not reach here. Even if we did, there is no way out. Call
1480 * unrecoverable_exception and die.
1482 1: addi r3,r1,STACK_FRAME_OVERHEAD
1483 bl unrecoverable_exception
1486 * r13 points to the PACA, r9 contains the saved CR,
1487 * r12 contain the saved SRR1, SRR0 is still ready for return
1488 * r3 has the faulting address
1489 * r9 - r13 are saved in paca->exslb.
1490 * r3 is saved in paca->slb_r3
1491 * We assume we aren't going to take any exceptions during this procedure.
1495 #ifdef CONFIG_RELOCATABLE
1499 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1500 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1502 bl slb_allocate_realmode
1504 /* All done -- return from exception. */
1506 ld r10,PACA_EXSLB+EX_LR(r13)
1507 ld r3,PACA_EXSLB+EX_R3(r13)
1508 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1512 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1518 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1521 RESTORE_PPR_PACA(PACA_EXSLB, r9)
1522 ld r9,PACA_EXSLB+EX_R9(r13)
1523 ld r10,PACA_EXSLB+EX_R10(r13)
1524 ld r11,PACA_EXSLB+EX_R11(r13)
1525 ld r12,PACA_EXSLB+EX_R12(r13)
1526 ld r13,PACA_EXSLB+EX_R13(r13)
1528 b . /* prevent speculative execution */
1530 2: mfspr r11,SPRN_SRR0
1531 ld r10,PACAKBASE(r13)
1532 LOAD_HANDLER(r10,unrecov_slb)
1534 ld r10,PACAKMSR(r13)
1540 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1541 RECONCILE_IRQ_STATE(r10, r11)
1543 1: addi r3,r1,STACK_FRAME_OVERHEAD
1544 bl unrecoverable_exception
1548 #ifdef CONFIG_PPC_970_NAP
1551 std r9,TI_LOCAL_FLAGS(r11)
1552 ld r10,_LINK(r1) /* make idle task do the */
1553 std r10,_NIP(r1) /* equivalent of a blr */
1565 andis. r0,r4,0xa410 /* weird error? */
1566 bne- handle_page_fault /* if not, try to insert a HPTE */
1567 andis. r0,r4,DSISR_DABRMATCH@h
1568 bne- handle_dabr_fault
1569 CURRENT_THREAD_INFO(r11, r1)
1570 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1571 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1572 bne 77f /* then don't call hash_page now */
1574 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1575 * accessing a userspace segment (even from the kernel). We assume
1576 * kernel addresses always have the high bit set.
1578 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1579 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1580 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1581 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1582 ori r4,r4,1 /* add _PAGE_PRESENT */
1583 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1586 * r3 contains the faulting address
1587 * r4 contains the required access permissions
1588 * r5 contains the trap number
1591 * at return r3 = 0 for success, 1 for page fault, negative for error
1594 bl hash_page /* build HPTE if possible */
1595 cmpdi r3,0 /* see if hash_page succeeded */
1598 beq fast_exc_return_irq /* Return from exception on success */
1603 /* Here we have a page fault that hash_page can't handle. */
1607 addi r3,r1,STACK_FRAME_OVERHEAD
1613 addi r3,r1,STACK_FRAME_OVERHEAD
1618 /* We have a data breakpoint exception - handle it */
1623 addi r3,r1,STACK_FRAME_OVERHEAD
1625 12: b ret_from_except_lite
1628 /* We have a page fault that hash_page could handle but HV refused
1633 addi r3,r1,STACK_FRAME_OVERHEAD
1639 * We come here as a result of a DSI at a point where we don't want
1640 * to call hash_page, such as when we are accessing memory (possibly
1641 * user memory) inside a PMU interrupt that occurred while interrupts
1642 * were soft-disabled. We want to invoke the exception handler for
1643 * the access, or panic if there isn't a handler.
1647 addi r3,r1,STACK_FRAME_OVERHEAD
1653 * Here we have detected that the kernel stack pointer is bad.
1654 * R9 contains the saved CR, r13 points to the paca,
1655 * r10 contains the (bad) kernel stack pointer,
1656 * r11 and r12 contain the saved SRR0 and SRR1.
1657 * We switch to using an emergency stack, save the registers there,
1658 * and call kernel_bad_stack(), which panics.
1661 ld r1,PACAEMERGSP(r13)
1662 subi r1,r1,64+INT_FRAME_SIZE
1668 mfspr r12,SPRN_DSISR
1694 std r10,ORIG_GPR3(r1)
1695 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1698 lhz r12,PACA_TRAP_SAVE(r13)
1700 addi r11,r1,INT_FRAME_SIZE
1705 ld r11,exception_marker@toc(r2)
1707 std r11,STACK_FRAME_OVERHEAD-16(r1)
1708 1: addi r3,r1,STACK_FRAME_OVERHEAD