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. We only handle no state loss and
106 * supervisor state loss. We do -not- handle hypervisor
107 * state loss at this time.
110 rlwinm. r13,r13,47-31,30,31
116 lbz r0,PACA_THREAD_IDLE_STATE(r13)
117 cmpwi cr2,r0,PNV_THREAD_NAP
118 bgt cr2,8f /* Either sleep or Winkle */
120 /* Waking up from nap should not cause hypervisor state loss */
123 /* Waking up from nap */
124 li r0,PNV_THREAD_RUNNING
125 stb r0,PACA_THREAD_IDLE_STATE(r13) /* Clear thread state */
127 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
128 li r0,KVM_HWTHREAD_IN_KERNEL
129 stb r0,HSTATE_HWTHREAD_STATE(r13)
130 /* Order setting hwthread_state vs. testing hwthread_req */
132 lbz r0,HSTATE_HWTHREAD_REQ(r13)
139 /* Return SRR1 from power7_nap() */
142 b power7_wakeup_noloss
143 2: b power7_wakeup_loss
145 /* Fast Sleep wakeup on PowerNV */
147 b power7_wakeup_tb_loss
150 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
151 #endif /* CONFIG_PPC_P7_NAP */
152 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
156 machine_check_pSeries_1:
157 /* This is moved out of line as it can be patched by FW, but
158 * some code path might still want to branch into the original
161 HMT_MEDIUM_PPR_DISCARD
162 SET_SCRATCH0(r13) /* save r13 */
163 #ifdef CONFIG_PPC_P7_NAP
165 /* Running native on arch 2.06 or later, check if we are
166 * waking up from nap. We only handle no state loss and
167 * supervisor state loss. We do -not- handle hypervisor
168 * state loss at this time.
171 rlwinm. r13,r13,47-31,30,31
172 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
176 rlwinm. r13,r13,47-31,30,31
177 /* waking up from powersave (nap) state */
179 /* Total loss of HV state is fatal. let's just stay stuck here */
180 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
183 OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
184 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
185 #endif /* CONFIG_PPC_P7_NAP */
186 EXCEPTION_PROLOG_0(PACA_EXMC)
188 b machine_check_pSeries_early
190 b machine_check_pSeries_0
191 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
194 .globl data_access_pSeries
196 HMT_MEDIUM_PPR_DISCARD
198 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
202 .globl data_access_slb_pSeries
203 data_access_slb_pSeries:
204 HMT_MEDIUM_PPR_DISCARD
206 EXCEPTION_PROLOG_0(PACA_EXSLB)
207 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
208 std r3,PACA_EXSLB+EX_R3(r13)
211 /* Keep that around for when we re-implement dynamic VSIDs */
213 bge slb_miss_user_pseries
214 #endif /* __DISABLED__ */
216 #ifndef CONFIG_RELOCATABLE
220 * We can't just use a direct branch to slb_miss_realmode
221 * because the distance from here to there depends on where
222 * the kernel ends up being put.
225 ld r10,PACAKBASE(r13)
226 LOAD_HANDLER(r10, slb_miss_realmode)
231 STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
234 .globl instruction_access_slb_pSeries
235 instruction_access_slb_pSeries:
236 HMT_MEDIUM_PPR_DISCARD
238 EXCEPTION_PROLOG_0(PACA_EXSLB)
239 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
240 std r3,PACA_EXSLB+EX_R3(r13)
241 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
243 /* Keep that around for when we re-implement dynamic VSIDs */
245 bge slb_miss_user_pseries
246 #endif /* __DISABLED__ */
248 #ifndef CONFIG_RELOCATABLE
252 ld r10,PACAKBASE(r13)
253 LOAD_HANDLER(r10, slb_miss_realmode)
258 /* We open code these as we can't have a ". = x" (even with
259 * x = "." within a feature section
262 .globl hardware_interrupt_pSeries;
263 .globl hardware_interrupt_hv;
264 hardware_interrupt_pSeries:
265 hardware_interrupt_hv:
266 HMT_MEDIUM_PPR_DISCARD
268 _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
269 EXC_HV, SOFTEN_TEST_HV)
270 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
272 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
273 EXC_STD, SOFTEN_TEST_HV_201)
274 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
275 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
277 STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
278 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
280 STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
281 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
283 STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
284 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
287 .globl decrementer_pSeries
289 _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
291 STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
293 MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
294 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
296 STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
297 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
300 .globl system_call_pSeries
303 * If CONFIG_KVM_BOOK3S_64_HANDLER is set, save the PPR (on systems
304 * that support it) before changing to HMT_MEDIUM. That allows the KVM
305 * code to save that value into the guest state (it is the guest's PPR
306 * value). Otherwise just change to HMT_MEDIUM as userspace has
307 * already saved the PPR.
309 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
312 std r9,PACA_EXGEN+EX_R9(r13)
313 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR);
315 std r10,PACA_EXGEN+EX_R10(r13)
316 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r9, CPU_FTR_HAS_PPR);
324 SYSCALL_PSERIES_2_RFID
326 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
328 STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
329 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
331 /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
332 * out of line to handle them
335 hv_data_storage_trampoline:
337 EXCEPTION_PROLOG_0(PACA_EXGEN)
341 hv_instr_storage_trampoline:
343 EXCEPTION_PROLOG_0(PACA_EXGEN)
347 emulation_assist_trampoline:
349 EXCEPTION_PROLOG_0(PACA_EXGEN)
350 b emulation_assist_hv
353 hv_exception_trampoline:
355 EXCEPTION_PROLOG_0(PACA_EXGEN)
356 b hmi_exception_early
359 hv_doorbell_trampoline:
361 EXCEPTION_PROLOG_0(PACA_EXGEN)
364 /* We need to deal with the Altivec unavailable exception
365 * here which is at 0xf20, thus in the middle of the
366 * prolog code of the PerformanceMonitor one. A little
367 * trickery is thus necessary
370 performance_monitor_pseries_trampoline:
372 EXCEPTION_PROLOG_0(PACA_EXGEN)
373 b performance_monitor_pSeries
376 altivec_unavailable_pseries_trampoline:
378 EXCEPTION_PROLOG_0(PACA_EXGEN)
379 b altivec_unavailable_pSeries
382 vsx_unavailable_pseries_trampoline:
384 EXCEPTION_PROLOG_0(PACA_EXGEN)
385 b vsx_unavailable_pSeries
388 facility_unavailable_trampoline:
390 EXCEPTION_PROLOG_0(PACA_EXGEN)
391 b facility_unavailable_pSeries
394 hv_facility_unavailable_trampoline:
396 EXCEPTION_PROLOG_0(PACA_EXGEN)
397 b facility_unavailable_hv
399 #ifdef CONFIG_CBE_RAS
400 STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
401 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
402 #endif /* CONFIG_CBE_RAS */
404 STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
405 KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
408 .global denorm_exception_hv
410 HMT_MEDIUM_PPR_DISCARD
411 mtspr SPRN_SPRG_HSCRATCH0,r13
412 EXCEPTION_PROLOG_0(PACA_EXGEN)
413 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
415 #ifdef CONFIG_PPC_DENORMALISATION
417 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
418 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
419 addi r11,r11,-4 /* HSRR0 is next instruction */
424 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
425 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
427 #ifdef CONFIG_CBE_RAS
428 STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
429 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
430 #endif /* CONFIG_CBE_RAS */
432 STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
433 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
435 #ifdef CONFIG_CBE_RAS
436 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
437 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
440 #endif /* CONFIG_CBE_RAS */
443 /*** Out of line interrupts support ***/
446 /* moved from 0x200 */
447 machine_check_pSeries_early:
449 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
454 * Original R9 to R13 is saved on PACA_EXMC
456 * Switch to mc_emergency stack and handle re-entrancy (we limit
457 * the nested MCE upto level 4 to avoid stack overflow).
458 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
460 * We use paca->in_mce to check whether this is the first entry or
461 * nested machine check. We increment paca->in_mce to track nested
464 * If this is the first entry then set stack pointer to
465 * paca->mc_emergency_sp, otherwise r1 is already pointing to
466 * stack frame on mc_emergency stack.
468 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
469 * checkstop if we get another machine check exception before we do
470 * rfid with MSR_ME=1.
472 mr r11,r1 /* Save r1 */
473 lhz r10,PACA_IN_MCE(r13)
474 cmpwi r10,0 /* Are we in nested machine check */
475 bne 0f /* Yes, we are. */
476 /* First machine check entry */
477 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
478 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
479 addi r10,r10,1 /* increment paca->in_mce */
480 sth r10,PACA_IN_MCE(r13)
481 /* Limit nested MCE to level 4 to avoid stack overflow */
483 bgt 2f /* Check if we hit limit of 4 */
484 std r11,GPR1(r1) /* Save r1 on the stack. */
485 std r11,0(r1) /* make stack chain pointer */
486 mfspr r11,SPRN_SRR0 /* Save SRR0 */
488 mfspr r11,SPRN_SRR1 /* Save SRR1 */
490 mfspr r11,SPRN_DAR /* Save DAR */
492 mfspr r11,SPRN_DSISR /* Save DSISR */
494 std r9,_CCR(r1) /* Save CR in stackframe */
495 /* Save r9 through r13 from EXMC save area to stack frame. */
496 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
497 mfmsr r11 /* get MSR value */
498 ori r11,r11,MSR_ME /* turn on ME bit */
499 ori r11,r11,MSR_RI /* turn on RI bit */
500 ld r12,PACAKBASE(r13) /* get high part of &label */
501 LOAD_HANDLER(r12, machine_check_handle_early)
502 1: mtspr SPRN_SRR0,r12
505 b . /* prevent speculative execution */
507 /* Stack overflow. Stay on emergency stack and panic.
508 * Keep the ME bit off while panic-ing, so that if we hit
509 * another machine check we checkstop.
511 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
513 ld r12,PACAKBASE(r13)
514 LOAD_HANDLER(r12, unrecover_mce)
516 andc r11,r11,r10 /* Turn off MSR_ME */
518 b . /* prevent speculative execution */
519 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
521 machine_check_pSeries:
522 .globl machine_check_fwnmi
524 HMT_MEDIUM_PPR_DISCARD
525 SET_SCRATCH0(r13) /* save r13 */
526 EXCEPTION_PROLOG_0(PACA_EXMC)
527 machine_check_pSeries_0:
528 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
529 EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
530 KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
531 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
532 KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
533 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
534 KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
535 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
536 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
538 #ifdef CONFIG_PPC_DENORMALISATION
542 * To denormalise we need to move a copy of the register to itself.
543 * For POWER6 do that here for all FP regs.
546 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
547 xori r10,r10,(MSR_FE0|MSR_FE1)
551 #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
552 #define FMR4(n) FMR2(n) ; FMR2(n+2)
553 #define FMR8(n) FMR4(n) ; FMR4(n+4)
554 #define FMR16(n) FMR8(n) ; FMR8(n+8)
555 #define FMR32(n) FMR16(n) ; FMR16(n+16)
560 * To denormalise we need to move a copy of the register to itself.
561 * For POWER7 do that here for the first 32 VSX registers only.
564 oris r10,r10,MSR_VSX@h
568 #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
569 #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
570 #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
571 #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
572 #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
575 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
579 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
581 * To denormalise we need to move a copy of the register to itself.
582 * For POWER8 we need to do that for all 64 VSX registers
588 ld r9,PACA_EXGEN+EX_R9(r13)
589 RESTORE_PPR_PACA(PACA_EXGEN, r10)
591 ld r10,PACA_EXGEN+EX_CFAR(r13)
593 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
594 ld r10,PACA_EXGEN+EX_R10(r13)
595 ld r11,PACA_EXGEN+EX_R11(r13)
596 ld r12,PACA_EXGEN+EX_R12(r13)
597 ld r13,PACA_EXGEN+EX_R13(r13)
603 /* moved from 0xe00 */
604 STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
605 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
606 STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
607 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
608 STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
609 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
610 MASKABLE_EXCEPTION_HV_OOL(0xe62, hmi_exception)
611 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
613 MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
614 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
616 /* moved from 0xf00 */
617 STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
618 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
619 STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
620 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
621 STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
622 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
623 STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
624 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf60)
625 STD_EXCEPTION_HV_OOL(0xf82, facility_unavailable)
626 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xf82)
629 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
630 * - If it was a decrementer interrupt, we bump the dec to max and and return.
631 * - If it was a doorbell we return immediately since doorbells are edge
632 * triggered and won't automatically refire.
633 * - If it was a HMI we return immediately since we handled it in realmode
634 * and it won't refire.
635 * - else we hard disable and return.
636 * This is called with r10 containing the value to OR to the paca field.
638 #define MASKED_INTERRUPT(_H) \
639 masked_##_H##interrupt: \
640 std r11,PACA_EXGEN+EX_R11(r13); \
641 lbz r11,PACAIRQHAPPENED(r13); \
643 stb r11,PACAIRQHAPPENED(r13); \
644 cmpwi r10,PACA_IRQ_DEC; \
647 ori r10,r10,0xffff; \
648 mtspr SPRN_DEC,r10; \
650 1: cmpwi r10,PACA_IRQ_DBELL; \
652 cmpwi r10,PACA_IRQ_HMI; \
654 mfspr r10,SPRN_##_H##SRR1; \
655 rldicl r10,r10,48,1; /* clear MSR_EE */ \
657 mtspr SPRN_##_H##SRR1,r10; \
659 ld r9,PACA_EXGEN+EX_R9(r13); \
660 ld r10,PACA_EXGEN+EX_R10(r13); \
661 ld r11,PACA_EXGEN+EX_R11(r13); \
670 * Called from arch_local_irq_enable when an interrupt needs
671 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
672 * which kind of interrupt. MSR:EE is already off. We generate a
673 * stackframe like if a real interrupt had happened.
675 * Note: While MSR:EE is off, we need to make sure that _MSR
676 * in the generated frame has EE set to 1 or the exception
677 * handler will not properly re-enable them.
679 _GLOBAL(__replay_interrupt)
680 /* We are going to jump to the exception common code which
681 * will retrieve various register values from the PACA which
682 * we don't give a damn about, so we don't bother storing them.
689 beq decrementer_common
691 beq hardware_interrupt_common
694 beq h_doorbell_common
697 beq doorbell_super_common
698 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
701 #ifdef CONFIG_PPC_PSERIES
703 * Vectors for the FWNMI option. Share common code.
705 .globl system_reset_fwnmi
708 HMT_MEDIUM_PPR_DISCARD
709 SET_SCRATCH0(r13) /* save r13 */
710 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
713 #endif /* CONFIG_PPC_PSERIES */
717 * This is used for when the SLB miss handler has to go virtual,
718 * which doesn't happen for now anymore but will once we re-implement
719 * dynamic VSIDs for shared page tables
721 slb_miss_user_pseries:
722 std r10,PACA_EXGEN+EX_R10(r13)
723 std r11,PACA_EXGEN+EX_R11(r13)
724 std r12,PACA_EXGEN+EX_R12(r13)
726 ld r11,PACA_EXSLB+EX_R9(r13)
727 ld r12,PACA_EXSLB+EX_R3(r13)
728 std r10,PACA_EXGEN+EX_R13(r13)
729 std r11,PACA_EXGEN+EX_R9(r13)
730 std r12,PACA_EXGEN+EX_R3(r13)
733 mfspr r11,SRR0 /* save SRR0 */
734 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
735 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
737 mfspr r12,SRR1 /* and SRR1 */
740 b . /* prevent spec. execution */
741 #endif /* __DISABLED__ */
743 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
744 kvmppc_skip_interrupt:
746 * Here all GPRs are unchanged from when the interrupt happened
747 * except for r13, which is saved in SPRG_SCRATCH0.
756 kvmppc_skip_Hinterrupt:
758 * Here all GPRs are unchanged from when the interrupt happened
759 * except for r13, which is saved in SPRG_SCRATCH0.
761 mfspr r13, SPRN_HSRR0
763 mtspr SPRN_HSRR0, r13
770 * Code from here down to __end_handlers is invoked from the
771 * exception prologs above. Because the prologs assemble the
772 * addresses of these handlers using the LOAD_HANDLER macro,
773 * which uses an ori instruction, these handlers must be in
774 * the first 64k of the kernel image.
777 /*** Common interrupt handlers ***/
779 STD_EXCEPTION_COMMON(0x100, system_reset, system_reset_exception)
781 STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
782 STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, timer_interrupt)
783 STD_EXCEPTION_COMMON(0x980, hdecrementer, hdec_interrupt)
784 #ifdef CONFIG_PPC_DOORBELL
785 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, doorbell_exception)
787 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, unknown_exception)
789 STD_EXCEPTION_COMMON(0xb00, trap_0b, unknown_exception)
790 STD_EXCEPTION_COMMON(0xd00, single_step, single_step_exception)
791 STD_EXCEPTION_COMMON(0xe00, trap_0e, unknown_exception)
792 STD_EXCEPTION_COMMON(0xe40, emulation_assist, emulation_assist_interrupt)
793 STD_EXCEPTION_COMMON_ASYNC(0xe60, hmi_exception, handle_hmi_exception)
794 #ifdef CONFIG_PPC_DOORBELL
795 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, doorbell_exception)
797 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, unknown_exception)
799 STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, performance_monitor_exception)
800 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, instruction_breakpoint_exception)
801 STD_EXCEPTION_COMMON(0x1502, denorm, unknown_exception)
802 #ifdef CONFIG_ALTIVEC
803 STD_EXCEPTION_COMMON(0x1700, altivec_assist, altivec_assist_exception)
805 STD_EXCEPTION_COMMON(0x1700, altivec_assist, unknown_exception)
807 #ifdef CONFIG_CBE_RAS
808 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, cbe_system_error_exception)
809 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, cbe_maintenance_exception)
810 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, cbe_thermal_exception)
811 #endif /* CONFIG_CBE_RAS */
814 * Relocation-on interrupts: A subset of the interrupts can be delivered
815 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
816 * it. Addresses are the same as the original interrupt addresses, but
817 * offset by 0xc000000000004000.
818 * It's impossible to receive interrupts below 0x300 via this mechanism.
819 * KVM: None of these traps are from the guest ; anything that escalated
820 * to HV=1 from HV=0 is delivered via real mode handlers.
824 * This uses the standard macro, since the original 0x300 vector
825 * only has extra guff for STAB-based processors -- which never
828 STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
830 .globl data_access_slb_relon_pSeries
831 data_access_slb_relon_pSeries:
833 EXCEPTION_PROLOG_0(PACA_EXSLB)
834 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
835 std r3,PACA_EXSLB+EX_R3(r13)
838 #ifndef CONFIG_RELOCATABLE
842 * We can't just use a direct branch to slb_miss_realmode
843 * because the distance from here to there depends on where
844 * the kernel ends up being put.
847 ld r10,PACAKBASE(r13)
848 LOAD_HANDLER(r10, slb_miss_realmode)
853 STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
855 .globl instruction_access_slb_relon_pSeries
856 instruction_access_slb_relon_pSeries:
858 EXCEPTION_PROLOG_0(PACA_EXSLB)
859 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
860 std r3,PACA_EXSLB+EX_R3(r13)
861 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
863 #ifndef CONFIG_RELOCATABLE
867 ld r10,PACAKBASE(r13)
868 LOAD_HANDLER(r10, slb_miss_realmode)
874 .globl hardware_interrupt_relon_pSeries;
875 .globl hardware_interrupt_relon_hv;
876 hardware_interrupt_relon_pSeries:
877 hardware_interrupt_relon_hv:
879 _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
881 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
882 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
883 STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
884 STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
885 STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
886 MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
887 STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
888 MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
889 STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
892 .globl system_call_relon_pSeries
893 system_call_relon_pSeries:
896 SYSCALL_PSERIES_2_DIRECT
899 STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
902 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
905 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
908 emulation_assist_relon_trampoline:
910 EXCEPTION_PROLOG_0(PACA_EXGEN)
911 b emulation_assist_relon_hv
914 b . /* Can't happen, see v2.07 Book III-S section 6.5 */
917 h_doorbell_relon_trampoline:
919 EXCEPTION_PROLOG_0(PACA_EXGEN)
920 b h_doorbell_relon_hv
923 performance_monitor_relon_pseries_trampoline:
925 EXCEPTION_PROLOG_0(PACA_EXGEN)
926 b performance_monitor_relon_pSeries
929 altivec_unavailable_relon_pseries_trampoline:
931 EXCEPTION_PROLOG_0(PACA_EXGEN)
932 b altivec_unavailable_relon_pSeries
935 vsx_unavailable_relon_pseries_trampoline:
937 EXCEPTION_PROLOG_0(PACA_EXGEN)
938 b vsx_unavailable_relon_pSeries
941 facility_unavailable_relon_trampoline:
943 EXCEPTION_PROLOG_0(PACA_EXGEN)
944 b facility_unavailable_relon_pSeries
947 hv_facility_unavailable_relon_trampoline:
949 EXCEPTION_PROLOG_0(PACA_EXGEN)
950 b hv_facility_unavailable_relon_hv
952 STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
953 #ifdef CONFIG_PPC_DENORMALISATION
955 b denorm_exception_hv
957 STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
959 /* Other future vectors */
961 .globl __end_interrupts
965 system_call_entry_direct:
966 #if defined(CONFIG_RELOCATABLE)
967 /* The first level prologue may have used LR to get here, saving
968 * orig in r10. To save hacking/ifdeffing common code, restore here.
975 ppc64_runlatch_on_trampoline:
976 b __ppc64_runlatch_on
979 * Here r13 points to the paca, r9 contains the saved CR,
980 * SRR0 and SRR1 are saved in r11 and r12,
981 * r9 - r13 are saved in paca->exgen.
984 .globl data_access_common
987 std r10,PACA_EXGEN+EX_DAR(r13)
989 stw r10,PACA_EXGEN+EX_DSISR(r13)
990 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
991 RECONCILE_IRQ_STATE(r10, r11)
993 ld r3,PACA_EXGEN+EX_DAR(r13)
994 lwz r4,PACA_EXGEN+EX_DSISR(r13)
996 b do_hash_page /* Try to handle as hpte fault */
999 .globl h_data_storage_common
1000 h_data_storage_common:
1002 std r10,PACA_EXGEN+EX_DAR(r13)
1003 mfspr r10,SPRN_HDSISR
1004 stw r10,PACA_EXGEN+EX_DSISR(r13)
1005 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1007 RECONCILE_IRQ_STATE(r10, r11)
1008 addi r3,r1,STACK_FRAME_OVERHEAD
1009 bl unknown_exception
1013 .globl instruction_access_common
1014 instruction_access_common:
1015 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
1016 RECONCILE_IRQ_STATE(r10, r11)
1019 andis. r4,r12,0x5820
1021 b do_hash_page /* Try to handle as hpte fault */
1023 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
1026 * Here is the common SLB miss user that is used when going to virtual
1027 * mode for SLB misses, that is currently not used
1031 .globl slb_miss_user_common
1032 slb_miss_user_common:
1034 std r3,PACA_EXGEN+EX_DAR(r13)
1035 stw r9,PACA_EXGEN+EX_CCR(r13)
1036 std r10,PACA_EXGEN+EX_LR(r13)
1037 std r11,PACA_EXGEN+EX_SRR0(r13)
1038 bl slb_allocate_user
1040 ld r10,PACA_EXGEN+EX_LR(r13)
1041 ld r3,PACA_EXGEN+EX_R3(r13)
1042 lwz r9,PACA_EXGEN+EX_CCR(r13)
1043 ld r11,PACA_EXGEN+EX_SRR0(r13)
1047 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1048 beq- unrecov_user_slb
1056 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
1062 ld r9,PACA_EXGEN+EX_R9(r13)
1063 ld r10,PACA_EXGEN+EX_R10(r13)
1064 ld r11,PACA_EXGEN+EX_R11(r13)
1065 ld r12,PACA_EXGEN+EX_R12(r13)
1066 ld r13,PACA_EXGEN+EX_R13(r13)
1071 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1072 ld r4,PACA_EXGEN+EX_DAR(r13)
1079 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1080 RECONCILE_IRQ_STATE(r10, r11)
1082 1: addi r3,r1,STACK_FRAME_OVERHEAD
1083 bl unrecoverable_exception
1086 #endif /* __DISABLED__ */
1090 * Machine check is different because we use a different
1091 * save area: PACA_EXMC instead of PACA_EXGEN.
1094 .globl machine_check_common
1095 machine_check_common:
1098 std r10,PACA_EXGEN+EX_DAR(r13)
1099 mfspr r10,SPRN_DSISR
1100 stw r10,PACA_EXGEN+EX_DSISR(r13)
1101 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
1103 RECONCILE_IRQ_STATE(r10, r11)
1104 ld r3,PACA_EXGEN+EX_DAR(r13)
1105 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1109 addi r3,r1,STACK_FRAME_OVERHEAD
1110 bl machine_check_exception
1114 .globl alignment_common
1117 std r10,PACA_EXGEN+EX_DAR(r13)
1118 mfspr r10,SPRN_DSISR
1119 stw r10,PACA_EXGEN+EX_DSISR(r13)
1120 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1121 ld r3,PACA_EXGEN+EX_DAR(r13)
1122 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1126 RECONCILE_IRQ_STATE(r10, r11)
1127 addi r3,r1,STACK_FRAME_OVERHEAD
1128 bl alignment_exception
1132 .globl program_check_common
1133 program_check_common:
1134 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1136 RECONCILE_IRQ_STATE(r10, r11)
1137 addi r3,r1,STACK_FRAME_OVERHEAD
1138 bl program_check_exception
1142 .globl fp_unavailable_common
1143 fp_unavailable_common:
1144 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1145 bne 1f /* if from user, just load it up */
1147 RECONCILE_IRQ_STATE(r10, r11)
1148 addi r3,r1,STACK_FRAME_OVERHEAD
1149 bl kernel_fp_unavailable_exception
1152 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1154 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1155 * transaction), go do TM stuff
1157 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1159 END_FTR_SECTION_IFSET(CPU_FTR_TM)
1162 b fast_exception_return
1163 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1164 2: /* User process was in a transaction */
1166 RECONCILE_IRQ_STATE(r10, r11)
1167 addi r3,r1,STACK_FRAME_OVERHEAD
1168 bl fp_unavailable_tm
1172 .globl altivec_unavailable_common
1173 altivec_unavailable_common:
1174 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1175 #ifdef CONFIG_ALTIVEC
1178 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1179 BEGIN_FTR_SECTION_NESTED(69)
1180 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1181 * transaction), go do TM stuff
1183 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1185 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1188 b fast_exception_return
1189 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1190 2: /* User process was in a transaction */
1192 RECONCILE_IRQ_STATE(r10, r11)
1193 addi r3,r1,STACK_FRAME_OVERHEAD
1194 bl altivec_unavailable_tm
1198 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1201 RECONCILE_IRQ_STATE(r10, r11)
1202 addi r3,r1,STACK_FRAME_OVERHEAD
1203 bl altivec_unavailable_exception
1207 .globl vsx_unavailable_common
1208 vsx_unavailable_common:
1209 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1213 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1214 BEGIN_FTR_SECTION_NESTED(69)
1215 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1216 * transaction), go do TM stuff
1218 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1220 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1223 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1224 2: /* User process was in a transaction */
1226 RECONCILE_IRQ_STATE(r10, r11)
1227 addi r3,r1,STACK_FRAME_OVERHEAD
1228 bl vsx_unavailable_tm
1232 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1235 RECONCILE_IRQ_STATE(r10, r11)
1236 addi r3,r1,STACK_FRAME_OVERHEAD
1237 bl vsx_unavailable_exception
1240 STD_EXCEPTION_COMMON(0xf60, facility_unavailable, facility_unavailable_exception)
1241 STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, facility_unavailable_exception)
1244 .globl __end_handlers
1247 /* Equivalents to the above handlers for relocation-on interrupt vectors */
1248 STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
1249 MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
1251 STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
1252 STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
1253 STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
1254 STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
1255 STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
1257 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
1259 * Data area reserved for FWNMI option.
1260 * This address (0x7000) is fixed by the RPA.
1263 .globl fwnmi_data_area
1266 /* pseries and powernv need to keep the whole page from
1267 * 0x7000 to 0x8000 free for use by the firmware
1270 #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
1272 .globl hmi_exception_early
1273 hmi_exception_early:
1274 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0xe60)
1275 mr r10,r1 /* Save r1 */
1276 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
1277 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1278 std r9,_CCR(r1) /* save CR in stackframe */
1279 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
1280 std r11,_NIP(r1) /* save HSRR0 in stackframe */
1281 mfspr r12,SPRN_HSRR1 /* Save SRR1 */
1282 std r12,_MSR(r1) /* save SRR1 in stackframe */
1283 std r10,0(r1) /* make stack chain pointer */
1284 std r0,GPR0(r1) /* save r0 in stackframe */
1285 std r10,GPR1(r1) /* save r1 in stackframe */
1286 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1287 EXCEPTION_PROLOG_COMMON_3(0xe60)
1288 addi r3,r1,STACK_FRAME_OVERHEAD
1289 bl hmi_exception_realmode
1290 /* Windup the stack. */
1291 /* Move original HSRR0 and HSRR1 into the respective regs */
1309 /* restore original r1. */
1313 * Go to virtual mode and pull the HMI event information from
1316 .globl hmi_exception_after_realmode
1317 hmi_exception_after_realmode:
1319 EXCEPTION_PROLOG_0(PACA_EXGEN)
1323 #define MACHINE_CHECK_HANDLER_WINDUP \
1324 /* Clear MSR_RI before setting SRR0 and SRR1. */\
1326 mfmsr r9; /* get MSR value */ \
1328 mtmsrd r9,1; /* Clear MSR_RI */ \
1329 /* Move original SRR0 and SRR1 into the respective regs */ \
1331 mtspr SPRN_SRR1,r9; \
1333 mtspr SPRN_SRR0,r3; \
1341 REST_8GPRS(2, r1); \
1345 /* Decrement paca->in_mce. */ \
1346 lhz r12,PACA_IN_MCE(r13); \
1348 sth r12,PACA_IN_MCE(r13); \
1350 REST_2GPRS(12, r1); \
1351 /* restore original r1. */ \
1355 * Handle machine check early in real mode. We come here with
1356 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
1359 .globl machine_check_handle_early
1360 machine_check_handle_early:
1361 std r0,GPR0(r1) /* Save r0 */
1362 EXCEPTION_PROLOG_COMMON_3(0x200)
1364 addi r3,r1,STACK_FRAME_OVERHEAD
1365 bl machine_check_early
1366 std r3,RESULT(r1) /* Save result */
1368 #ifdef CONFIG_PPC_P7_NAP
1370 * Check if thread was in power saving mode. We come here when any
1371 * of the following is true:
1372 * a. thread wasn't in power saving mode
1373 * b. thread was in power saving mode with no state loss or
1374 * supervisor state loss
1376 * Go back to nap again if (b) is true.
1378 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
1379 beq 4f /* No, it wasn;t */
1380 /* Thread was in power saving mode. Go back to nap again. */
1383 /* Supervisor state loss */
1385 stb r0,PACA_NAPSTATELOST(r13)
1386 3: bl machine_check_queue_event
1387 MACHINE_CHECK_HANDLER_WINDUP
1390 li r3,PNV_THREAD_NAP
1391 b power7_enter_nap_mode
1395 * Check if we are coming from hypervisor userspace. If yes then we
1396 * continue in host kernel in V mode to deliver the MC event.
1398 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
1400 andi. r11,r12,MSR_PR /* See if coming from user. */
1401 bne 9f /* continue in V mode if we are. */
1404 #ifdef CONFIG_KVM_BOOK3S_64_HV
1406 * We are coming from kernel context. Check if we are coming from
1407 * guest. if yes, then we can continue. We will fall through
1408 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
1410 lbz r11,HSTATE_IN_GUEST(r13)
1411 cmpwi r11,0 /* Check if coming from guest */
1412 bne 9f /* continue if we are. */
1415 * At this point we are not sure about what context we come from.
1416 * Queue up the MCE event and return from the interrupt.
1417 * But before that, check if this is an un-recoverable exception.
1418 * If yes, then stay on emergency stack and panic.
1420 andi. r11,r12,MSR_RI
1422 1: mfspr r11,SPRN_SRR0
1423 ld r10,PACAKBASE(r13)
1424 LOAD_HANDLER(r10,unrecover_mce)
1426 ld r10,PACAKMSR(r13)
1428 * We are going down. But there are chances that we might get hit by
1429 * another MCE during panic path and we may run into unstable state
1430 * with no way out. Hence, turn ME bit off while going down, so that
1431 * when another MCE is hit during panic path, system will checkstop
1432 * and hypervisor will get restarted cleanly by SP.
1435 andc r10,r10,r3 /* Turn off MSR_ME */
1441 * Check if we have successfully handled/recovered from error, if not
1442 * then stay on emergency stack and panic.
1444 ld r3,RESULT(r1) /* Load result */
1445 cmpdi r3,0 /* see if we handled MCE successfully */
1447 beq 1b /* if !handled then panic */
1449 * Return from MC interrupt.
1450 * Queue up the MCE event so that we can log it later, while
1451 * returning from kernel or opal call.
1453 bl machine_check_queue_event
1454 MACHINE_CHECK_HANDLER_WINDUP
1457 /* Deliver the machine check to host kernel in V mode. */
1458 MACHINE_CHECK_HANDLER_WINDUP
1459 b machine_check_pSeries
1462 /* Invoke machine_check_exception to print MCE event and panic. */
1463 addi r3,r1,STACK_FRAME_OVERHEAD
1464 bl machine_check_exception
1466 * We will not reach here. Even if we did, there is no way out. Call
1467 * unrecoverable_exception and die.
1469 1: addi r3,r1,STACK_FRAME_OVERHEAD
1470 bl unrecoverable_exception
1473 * r13 points to the PACA, r9 contains the saved CR,
1474 * r12 contain the saved SRR1, SRR0 is still ready for return
1475 * r3 has the faulting address
1476 * r9 - r13 are saved in paca->exslb.
1477 * r3 is saved in paca->slb_r3
1478 * We assume we aren't going to take any exceptions during this procedure.
1482 #ifdef CONFIG_RELOCATABLE
1486 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1487 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1489 bl slb_allocate_realmode
1491 /* All done -- return from exception. */
1493 ld r10,PACA_EXSLB+EX_LR(r13)
1494 ld r3,PACA_EXSLB+EX_R3(r13)
1495 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1499 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1505 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1508 RESTORE_PPR_PACA(PACA_EXSLB, r9)
1509 ld r9,PACA_EXSLB+EX_R9(r13)
1510 ld r10,PACA_EXSLB+EX_R10(r13)
1511 ld r11,PACA_EXSLB+EX_R11(r13)
1512 ld r12,PACA_EXSLB+EX_R12(r13)
1513 ld r13,PACA_EXSLB+EX_R13(r13)
1515 b . /* prevent speculative execution */
1517 2: mfspr r11,SPRN_SRR0
1518 ld r10,PACAKBASE(r13)
1519 LOAD_HANDLER(r10,unrecov_slb)
1521 ld r10,PACAKMSR(r13)
1527 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1528 RECONCILE_IRQ_STATE(r10, r11)
1530 1: addi r3,r1,STACK_FRAME_OVERHEAD
1531 bl unrecoverable_exception
1535 #ifdef CONFIG_PPC_970_NAP
1538 std r9,TI_LOCAL_FLAGS(r11)
1539 ld r10,_LINK(r1) /* make idle task do the */
1540 std r10,_NIP(r1) /* equivalent of a blr */
1552 andis. r0,r4,0xa410 /* weird error? */
1553 bne- handle_page_fault /* if not, try to insert a HPTE */
1554 andis. r0,r4,DSISR_DABRMATCH@h
1555 bne- handle_dabr_fault
1556 CURRENT_THREAD_INFO(r11, r1)
1557 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1558 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1559 bne 77f /* then don't call hash_page now */
1561 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1562 * accessing a userspace segment (even from the kernel). We assume
1563 * kernel addresses always have the high bit set.
1565 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1566 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1567 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1568 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1569 ori r4,r4,1 /* add _PAGE_PRESENT */
1570 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1573 * r3 contains the faulting address
1574 * r4 contains the required access permissions
1575 * r5 contains the trap number
1578 * at return r3 = 0 for success, 1 for page fault, negative for error
1581 bl hash_page /* build HPTE if possible */
1582 cmpdi r3,0 /* see if hash_page succeeded */
1585 beq fast_exc_return_irq /* Return from exception on success */
1590 /* Here we have a page fault that hash_page can't handle. */
1594 addi r3,r1,STACK_FRAME_OVERHEAD
1600 addi r3,r1,STACK_FRAME_OVERHEAD
1605 /* We have a data breakpoint exception - handle it */
1610 addi r3,r1,STACK_FRAME_OVERHEAD
1612 12: b ret_from_except_lite
1615 /* We have a page fault that hash_page could handle but HV refused
1620 addi r3,r1,STACK_FRAME_OVERHEAD
1626 * We come here as a result of a DSI at a point where we don't want
1627 * to call hash_page, such as when we are accessing memory (possibly
1628 * user memory) inside a PMU interrupt that occurred while interrupts
1629 * were soft-disabled. We want to invoke the exception handler for
1630 * the access, or panic if there isn't a handler.
1634 addi r3,r1,STACK_FRAME_OVERHEAD
1640 * Here we have detected that the kernel stack pointer is bad.
1641 * R9 contains the saved CR, r13 points to the paca,
1642 * r10 contains the (bad) kernel stack pointer,
1643 * r11 and r12 contain the saved SRR0 and SRR1.
1644 * We switch to using an emergency stack, save the registers there,
1645 * and call kernel_bad_stack(), which panics.
1648 ld r1,PACAEMERGSP(r13)
1649 subi r1,r1,64+INT_FRAME_SIZE
1655 mfspr r12,SPRN_DSISR
1681 std r10,ORIG_GPR3(r1)
1682 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1685 lhz r12,PACA_TRAP_SAVE(r13)
1687 addi r11,r1,INT_FRAME_SIZE
1692 ld r11,exception_marker@toc(r2)
1694 std r11,STACK_FRAME_OVERHEAD-16(r1)
1695 1: addi r3,r1,STACK_FRAME_OVERHEAD