1 /* SPDX-License-Identifier: GPL-2.0 */
3 * This file contains the 64-bit "server" PowerPC variant
4 * of the low level exception handling including exception
5 * vectors, exception return, part of the slb and stab
6 * handling and other fixed offset specific things.
8 * This file is meant to be #included from head_64.S due to
9 * position dependent assembly.
11 * Most of this originates from head_64.S and thus has the same
16 #include <asm/hw_irq.h>
17 #include <asm/exception-64s.h>
18 #include <asm/ptrace.h>
19 #include <asm/cpuidle.h>
20 #include <asm/head-64.h>
23 * There are a few constraints to be concerned with.
24 * - Real mode exceptions code/data must be located at their physical location.
25 * - Virtual mode exceptions must be mapped at their 0xc000... location.
26 * - Fixed location code must not call directly beyond the __end_interrupts
27 * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
29 * - LOAD_HANDLER targets must be within first 64K of physical 0 /
31 * - Conditional branch targets must be within +/-32K of caller.
33 * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
34 * therefore don't have to run in physically located code or rfid to
35 * virtual mode kernel code. However on relocatable kernels they do have
36 * to branch to KERNELBASE offset because the rest of the kernel (outside
37 * the exception vectors) may be located elsewhere.
39 * Virtual exceptions correspond with physical, except their entry points
40 * are offset by 0xc000000000000000 and also tend to get an added 0x4000
41 * offset applied. Virtual exceptions are enabled with the Alternate
42 * Interrupt Location (AIL) bit set in the LPCR. However this does not
43 * guarantee they will be delivered virtually. Some conditions (see the ISA)
44 * cause exceptions to be delivered in real mode.
46 * It's impossible to receive interrupts below 0x300 via AIL.
48 * KVM: None of the virtual exceptions are from the guest. Anything that
49 * escalated to HV=1 from HV=0 is delivered via real mode handlers.
52 * We layout physical memory as follows:
53 * 0x0000 - 0x00ff : Secondary processor spin code
54 * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
55 * 0x1900 - 0x3fff : Real mode trampolines
56 * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
57 * 0x5900 - 0x6fff : Relon mode trampolines
58 * 0x7000 - 0x7fff : FWNMI data area
59 * 0x8000 - .... : Common interrupt handlers, remaining early
60 * setup code, rest of kernel.
62 * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
63 * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
66 OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
67 OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000)
68 OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900)
69 OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
70 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
72 * Data area reserved for FWNMI option.
73 * This address (0x7000) is fixed by the RPA.
74 * pseries and powernv need to keep the whole page from
75 * 0x7000 to 0x8000 free for use by the firmware
77 ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
78 OPEN_TEXT_SECTION(0x8000)
80 OPEN_TEXT_SECTION(0x7000)
83 USE_FIXED_SECTION(real_vectors)
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.
93 .globl __start_interrupts
96 /* No virt vectors corresponding with 0x0..0x100 */
97 EXC_VIRT_NONE(0x4000, 0x100)
100 #ifdef CONFIG_PPC_P7_NAP
102 * If running native on arch 2.06 or later, check if we are waking up
103 * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
104 * bits 46:47. A non-0 value indicates that we are coming from a power
105 * saving state. The idle wakeup handler initially runs in real mode,
106 * but we branch to the 0xc000... address so we can turn on relocation
109 #define IDLETEST(n) \
110 BEGIN_FTR_SECTION ; \
111 mfspr r10,SPRN_SRR1 ; \
112 rlwinm. r10,r10,47-31,30,31 ; \
115 BRANCH_TO_C000(r10, system_reset_idle_common) ; \
118 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
120 #define IDLETEST NOTEST
123 EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
126 * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
127 * being used, so a nested NMI exception would corrupt it.
129 EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
132 EXC_REAL_END(system_reset, 0x100, 0x100)
133 EXC_VIRT_NONE(0x4100, 0x100)
134 TRAMP_KVM(PACA_EXNMI, 0x100)
136 #ifdef CONFIG_PPC_P7_NAP
137 EXC_COMMON_BEGIN(system_reset_idle_common)
139 b pnv_powersave_wakeup
143 * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does
144 * the right thing. We do not want to reconcile because that goes
145 * through irq tracing which we don't want in NMI.
147 * Save PACAIRQHAPPENED because some code will do a hard disable
148 * (e.g., xmon). So we want to restore this back to where it was
149 * when we return. DAR is unused in the stack, so save it there.
151 #define ADD_RECONCILE_NMI \
152 li r10,IRQS_ALL_DISABLED; \
153 stb r10,PACAIRQSOFTMASK(r13); \
154 lbz r10,PACAIRQHAPPENED(r13); \
157 EXC_COMMON_BEGIN(system_reset_common)
159 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
160 * to recover, but nested NMI will notice in_nmi and not recover
161 * because of the use of the NMI stack. in_nmi reentrancy is tested in
162 * system_reset_exception.
164 lhz r10,PACA_IN_NMI(r13)
166 sth r10,PACA_IN_NMI(r13)
171 ld r1,PACA_NMI_EMERG_SP(r13)
172 subi r1,r1,INT_FRAME_SIZE
173 EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
174 system_reset, system_reset_exception,
175 ADD_NVGPRS;ADD_RECONCILE_NMI)
177 /* This (and MCE) can be simplified with mtmsrd L=1 */
178 /* Clear MSR_RI before setting SRR0 and SRR1. */
185 * MSR_RI is clear, now we can decrement paca->in_nmi.
187 lhz r10,PACA_IN_NMI(r13)
189 sth r10,PACA_IN_NMI(r13)
192 * Restore soft mask settings.
195 stb r10,PACAIRQHAPPENED(r13)
197 stb r10,PACAIRQSOFTMASK(r13)
200 * Keep below code in synch with MACHINE_CHECK_HANDLER_WINDUP.
201 * Should share common bits...
204 /* Move original SRR0 and SRR1 into the respective regs */
222 /* restore original r1. */
224 RFI_TO_USER_OR_KERNEL
226 #ifdef CONFIG_PPC_PSERIES
228 * Vectors for the FWNMI option. Share common code.
230 TRAMP_REAL_BEGIN(system_reset_fwnmi)
231 SET_SCRATCH0(r13) /* save r13 */
232 /* See comment at system_reset exception */
233 EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common,
234 EXC_STD, NOTEST, 0x100)
235 #endif /* CONFIG_PPC_PSERIES */
238 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
239 /* This is moved out of line as it can be patched by FW, but
240 * some code path might still want to branch into the original
243 SET_SCRATCH0(r13) /* save r13 */
244 EXCEPTION_PROLOG_0(PACA_EXMC)
246 b machine_check_powernv_early
248 b machine_check_pSeries_0
249 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
250 EXC_REAL_END(machine_check, 0x200, 0x100)
251 EXC_VIRT_NONE(0x4200, 0x100)
252 TRAMP_REAL_BEGIN(machine_check_powernv_early)
254 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
259 * Original R9 to R13 is saved on PACA_EXMC
261 * Switch to mc_emergency stack and handle re-entrancy (we limit
262 * the nested MCE upto level 4 to avoid stack overflow).
263 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
265 * We use paca->in_mce to check whether this is the first entry or
266 * nested machine check. We increment paca->in_mce to track nested
269 * If this is the first entry then set stack pointer to
270 * paca->mc_emergency_sp, otherwise r1 is already pointing to
271 * stack frame on mc_emergency stack.
273 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
274 * checkstop if we get another machine check exception before we do
275 * rfid with MSR_ME=1.
277 * This interrupt can wake directly from idle. If that is the case,
278 * the machine check is handled then the idle wakeup code is called
279 * to restore state. In that case, the POWER9 DD1 idle PACA workaround
280 * is not applied in the early machine check code, which will cause
283 mr r11,r1 /* Save r1 */
284 lhz r10,PACA_IN_MCE(r13)
285 cmpwi r10,0 /* Are we in nested machine check */
286 bne 0f /* Yes, we are. */
287 /* First machine check entry */
288 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
289 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
290 addi r10,r10,1 /* increment paca->in_mce */
291 sth r10,PACA_IN_MCE(r13)
292 /* Limit nested MCE to level 4 to avoid stack overflow */
293 cmpwi r10,MAX_MCE_DEPTH
294 bgt 2f /* Check if we hit limit of 4 */
295 std r11,GPR1(r1) /* Save r1 on the stack. */
296 std r11,0(r1) /* make stack chain pointer */
297 mfspr r11,SPRN_SRR0 /* Save SRR0 */
299 mfspr r11,SPRN_SRR1 /* Save SRR1 */
301 mfspr r11,SPRN_DAR /* Save DAR */
303 mfspr r11,SPRN_DSISR /* Save DSISR */
305 std r9,_CCR(r1) /* Save CR in stackframe */
306 /* Save r9 through r13 from EXMC save area to stack frame. */
307 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
308 mfmsr r11 /* get MSR value */
309 ori r11,r11,MSR_ME /* turn on ME bit */
310 ori r11,r11,MSR_RI /* turn on RI bit */
311 LOAD_HANDLER(r12, machine_check_handle_early)
312 1: mtspr SPRN_SRR0,r12
315 b . /* prevent speculative execution */
317 /* Stack overflow. Stay on emergency stack and panic.
318 * Keep the ME bit off while panic-ing, so that if we hit
319 * another machine check we checkstop.
321 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
323 LOAD_HANDLER(r12, unrecover_mce)
325 andc r11,r11,r10 /* Turn off MSR_ME */
327 b . /* prevent speculative execution */
328 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
330 TRAMP_REAL_BEGIN(machine_check_pSeries)
331 .globl machine_check_fwnmi
333 SET_SCRATCH0(r13) /* save r13 */
334 EXCEPTION_PROLOG_0(PACA_EXMC)
335 machine_check_pSeries_0:
336 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
338 * MSR_RI is not enabled, because PACA_EXMC is being used, so a
339 * nested machine check corrupts it. machine_check_common enables
342 EXCEPTION_PROLOG_PSERIES_1_NORI(machine_check_common, EXC_STD)
344 TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
346 EXC_COMMON_BEGIN(machine_check_common)
348 * Machine check is different because we use a different
349 * save area: PACA_EXMC instead of PACA_EXGEN.
352 std r10,PACA_EXMC+EX_DAR(r13)
354 stw r10,PACA_EXMC+EX_DSISR(r13)
355 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
357 RECONCILE_IRQ_STATE(r10, r11)
358 ld r3,PACA_EXMC+EX_DAR(r13)
359 lwz r4,PACA_EXMC+EX_DSISR(r13)
360 /* Enable MSR_RI when finished with PACA_EXMC */
366 addi r3,r1,STACK_FRAME_OVERHEAD
367 bl machine_check_exception
370 #define MACHINE_CHECK_HANDLER_WINDUP \
371 /* Clear MSR_RI before setting SRR0 and SRR1. */\
373 mfmsr r9; /* get MSR value */ \
375 mtmsrd r9,1; /* Clear MSR_RI */ \
376 /* Move original SRR0 and SRR1 into the respective regs */ \
378 mtspr SPRN_SRR1,r9; \
380 mtspr SPRN_SRR0,r3; \
392 /* Decrement paca->in_mce. */ \
393 lhz r12,PACA_IN_MCE(r13); \
395 sth r12,PACA_IN_MCE(r13); \
397 REST_2GPRS(12, r1); \
398 /* restore original r1. */ \
401 #ifdef CONFIG_PPC_P7_NAP
403 * This is an idle wakeup. Low level machine check has already been
404 * done. Queue the event then call the idle code to do the wake up.
406 EXC_COMMON_BEGIN(machine_check_idle_common)
407 bl machine_check_queue_event
410 * We have not used any non-volatile GPRs here, and as a rule
411 * most exception code including machine check does not.
412 * Therefore PACA_NAPSTATELOST does not need to be set. Idle
413 * wakeup will restore volatile registers.
415 * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
417 * Then decrement MCE nesting after finishing with the stack.
421 lhz r11,PACA_IN_MCE(r13)
423 sth r11,PACA_IN_MCE(r13)
425 /* Turn off the RI bit because SRR1 is used by idle wakeup code. */
426 /* Recoverability could be improved by reducing the use of SRR1. */
430 b pnv_powersave_wakeup_mce
433 * Handle machine check early in real mode. We come here with
434 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
436 EXC_COMMON_BEGIN(machine_check_handle_early)
437 std r0,GPR0(r1) /* Save r0 */
438 EXCEPTION_PROLOG_COMMON_3(0x200)
440 addi r3,r1,STACK_FRAME_OVERHEAD
441 bl machine_check_early
442 std r3,RESULT(r1) /* Save result */
445 #ifdef CONFIG_PPC_P7_NAP
447 * Check if thread was in power saving mode. We come here when any
448 * of the following is true:
449 * a. thread wasn't in power saving mode
450 * b. thread was in power saving mode with no state loss,
451 * supervisor state loss or hypervisor state loss.
453 * Go back to nap/sleep/winkle mode again if (b) is true.
456 rlwinm. r11,r12,47-31,30,31
457 bne machine_check_idle_common
458 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
462 * Check if we are coming from hypervisor userspace. If yes then we
463 * continue in host kernel in V mode to deliver the MC event.
465 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
467 andi. r11,r12,MSR_PR /* See if coming from user. */
468 bne 9f /* continue in V mode if we are. */
471 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
473 * We are coming from kernel context. Check if we are coming from
474 * guest. if yes, then we can continue. We will fall through
475 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
477 lbz r11,HSTATE_IN_GUEST(r13)
478 cmpwi r11,0 /* Check if coming from guest */
479 bne 9f /* continue if we are. */
482 * At this point we are not sure about what context we come from.
483 * Queue up the MCE event and return from the interrupt.
484 * But before that, check if this is an un-recoverable exception.
485 * If yes, then stay on emergency stack and panic.
489 1: mfspr r11,SPRN_SRR0
490 LOAD_HANDLER(r10,unrecover_mce)
494 * We are going down. But there are chances that we might get hit by
495 * another MCE during panic path and we may run into unstable state
496 * with no way out. Hence, turn ME bit off while going down, so that
497 * when another MCE is hit during panic path, system will checkstop
498 * and hypervisor will get restarted cleanly by SP.
501 andc r10,r10,r3 /* Turn off MSR_ME */
507 * Check if we have successfully handled/recovered from error, if not
508 * then stay on emergency stack and panic.
510 ld r3,RESULT(r1) /* Load result */
511 cmpdi r3,0 /* see if we handled MCE successfully */
513 beq 1b /* if !handled then panic */
515 * Return from MC interrupt.
516 * Queue up the MCE event so that we can log it later, while
517 * returning from kernel or opal call.
519 bl machine_check_queue_event
520 MACHINE_CHECK_HANDLER_WINDUP
521 RFI_TO_USER_OR_KERNEL
523 /* Deliver the machine check to host kernel in V mode. */
524 MACHINE_CHECK_HANDLER_WINDUP
525 b machine_check_pSeries
527 EXC_COMMON_BEGIN(unrecover_mce)
528 /* Invoke machine_check_exception to print MCE event and panic. */
529 addi r3,r1,STACK_FRAME_OVERHEAD
530 bl machine_check_exception
532 * We will not reach here. Even if we did, there is no way out. Call
533 * unrecoverable_exception and die.
535 1: addi r3,r1,STACK_FRAME_OVERHEAD
536 bl unrecoverable_exception
540 EXC_REAL(data_access, 0x300, 0x80)
541 EXC_VIRT(data_access, 0x4300, 0x80, 0x300)
542 TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
544 EXC_COMMON_BEGIN(data_access_common)
546 * Here r13 points to the paca, r9 contains the saved CR,
547 * SRR0 and SRR1 are saved in r11 and r12,
548 * r9 - r13 are saved in paca->exgen.
551 std r10,PACA_EXGEN+EX_DAR(r13)
553 stw r10,PACA_EXGEN+EX_DSISR(r13)
554 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
555 RECONCILE_IRQ_STATE(r10, r11)
557 ld r3,PACA_EXGEN+EX_DAR(r13)
558 lwz r4,PACA_EXGEN+EX_DSISR(r13)
562 BEGIN_MMU_FTR_SECTION
563 b do_hash_page /* Try to handle as hpte fault */
566 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
569 EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
571 EXCEPTION_PROLOG_0(PACA_EXSLB)
572 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
573 mr r12,r3 /* save r3 */
577 BRANCH_TO_COMMON(r10, slb_miss_common)
578 EXC_REAL_END(data_access_slb, 0x380, 0x80)
580 EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
582 EXCEPTION_PROLOG_0(PACA_EXSLB)
583 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
584 mr r12,r3 /* save r3 */
588 BRANCH_TO_COMMON(r10, slb_miss_common)
589 EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
590 TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
593 EXC_REAL(instruction_access, 0x400, 0x80)
594 EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
595 TRAMP_KVM(PACA_EXGEN, 0x400)
597 EXC_COMMON_BEGIN(instruction_access_common)
598 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
599 RECONCILE_IRQ_STATE(r10, r11)
602 andis. r4,r12,DSISR_SRR1_MATCH_64S@h
606 BEGIN_MMU_FTR_SECTION
607 b do_hash_page /* Try to handle as hpte fault */
610 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
613 EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
615 EXCEPTION_PROLOG_0(PACA_EXSLB)
616 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
617 mr r12,r3 /* save r3 */
618 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
621 BRANCH_TO_COMMON(r10, slb_miss_common)
622 EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
624 EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
626 EXCEPTION_PROLOG_0(PACA_EXSLB)
627 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
628 mr r12,r3 /* save r3 */
629 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
632 BRANCH_TO_COMMON(r10, slb_miss_common)
633 EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
634 TRAMP_KVM(PACA_EXSLB, 0x480)
638 * This handler is used by the 0x380 and 0x480 SLB miss interrupts, as well as
639 * the virtual mode 0x4380 and 0x4480 interrupts if AIL is enabled.
641 EXC_COMMON_BEGIN(slb_miss_common)
643 * r13 points to the PACA, r9 contains the saved CR,
644 * r12 contains the saved r3,
645 * r11 contain the saved SRR1, SRR0 is still ready for return
646 * r3 has the faulting address
647 * r9 - r13 are saved in paca->exslb.
648 * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss
649 * We assume we aren't going to take any exceptions during this
653 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
654 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
656 andi. r9,r11,MSR_PR // Check for exception from userspace
657 cmpdi cr4,r9,MSR_PR // And save the result in CR4 for later
660 * Test MSR_RI before calling slb_allocate_realmode, because the
661 * MSR in r11 gets clobbered. However we still want to allocate
662 * SLB in case MSR_RI=0, to minimise the risk of getting stuck in
663 * recursive SLB faults. So use cr5 for this, which is preserved.
665 andi. r11,r11,MSR_RI /* check for unrecoverable exception */
669 #ifdef CONFIG_PPC_BOOK3S_64
670 BEGIN_MMU_FTR_SECTION
672 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
675 ld r10,PACA_EXSLB+EX_LR(r13)
676 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
680 * Large address, check whether we have to allocate new contexts.
684 bne- cr5,2f /* if unrecoverable exception, oops */
686 /* All done -- return from exception. */
688 bne cr4,1f /* returning to kernel */
691 mtcrf 0x08,r9 /* MSR[PR] indication is in cr4 */
692 mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */
693 mtcrf 0x02,r9 /* I/D indication is in cr6 */
694 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
696 RESTORE_CTR(r9, PACA_EXSLB)
697 RESTORE_PPR_PACA(PACA_EXSLB, r9)
699 ld r9,PACA_EXSLB+EX_R9(r13)
700 ld r10,PACA_EXSLB+EX_R10(r13)
701 ld r11,PACA_EXSLB+EX_R11(r13)
702 ld r12,PACA_EXSLB+EX_R12(r13)
703 ld r13,PACA_EXSLB+EX_R13(r13)
705 b . /* prevent speculative execution */
708 mtcrf 0x08,r9 /* MSR[PR] indication is in cr4 */
709 mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */
710 mtcrf 0x02,r9 /* I/D indication is in cr6 */
711 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
713 RESTORE_CTR(r9, PACA_EXSLB)
714 RESTORE_PPR_PACA(PACA_EXSLB, r9)
716 ld r9,PACA_EXSLB+EX_R9(r13)
717 ld r10,PACA_EXSLB+EX_R10(r13)
718 ld r11,PACA_EXSLB+EX_R11(r13)
719 ld r12,PACA_EXSLB+EX_R12(r13)
720 ld r13,PACA_EXSLB+EX_R13(r13)
722 b . /* prevent speculative execution */
725 2: std r3,PACA_EXSLB+EX_DAR(r13)
729 LOAD_HANDLER(r10,unrecov_slb)
736 8: std r3,PACA_EXSLB+EX_DAR(r13)
740 LOAD_HANDLER(r10, large_addr_slb)
747 EXC_COMMON_BEGIN(unrecov_slb)
748 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
749 RECONCILE_IRQ_STATE(r10, r11)
751 1: addi r3,r1,STACK_FRAME_OVERHEAD
752 bl unrecoverable_exception
755 EXC_COMMON_BEGIN(large_addr_slb)
756 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
757 RECONCILE_IRQ_STATE(r10, r11)
758 ld r3, PACA_EXSLB+EX_DAR(r13)
761 li r10, 0x481 /* fix trap number for I-SLB miss */
764 addi r3, r1, STACK_FRAME_OVERHEAD
765 bl slb_miss_large_addr
768 EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
769 .globl hardware_interrupt_hv;
770 hardware_interrupt_hv:
772 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
773 EXC_HV, SOFTEN_TEST_HV,
776 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
777 EXC_STD, SOFTEN_TEST_PR,
779 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
780 EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
782 EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
783 .globl hardware_interrupt_relon_hv;
784 hardware_interrupt_relon_hv:
786 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
787 EXC_HV, SOFTEN_TEST_HV,
790 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
791 EXC_STD, SOFTEN_TEST_PR,
793 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
794 EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
796 TRAMP_KVM(PACA_EXGEN, 0x500)
797 TRAMP_KVM_HV(PACA_EXGEN, 0x500)
798 EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
801 EXC_REAL(alignment, 0x600, 0x100)
802 EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
803 TRAMP_KVM(PACA_EXGEN, 0x600)
804 EXC_COMMON_BEGIN(alignment_common)
806 std r10,PACA_EXGEN+EX_DAR(r13)
808 stw r10,PACA_EXGEN+EX_DSISR(r13)
809 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
810 ld r3,PACA_EXGEN+EX_DAR(r13)
811 lwz r4,PACA_EXGEN+EX_DSISR(r13)
815 RECONCILE_IRQ_STATE(r10, r11)
816 addi r3,r1,STACK_FRAME_OVERHEAD
817 bl alignment_exception
821 EXC_REAL(program_check, 0x700, 0x100)
822 EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
823 TRAMP_KVM(PACA_EXGEN, 0x700)
824 EXC_COMMON_BEGIN(program_check_common)
826 * It's possible to receive a TM Bad Thing type program check with
827 * userspace register values (in particular r1), but with SRR1 reporting
828 * that we came from the kernel. Normally that would confuse the bad
829 * stack logic, and we would report a bad kernel stack pointer. Instead
830 * we switch to the emergency stack if we're taking a TM Bad Thing from
833 li r10,MSR_PR /* Build a mask of MSR_PR .. */
834 oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */
835 and r10,r10,r12 /* Mask SRR1 with that. */
836 srdi r10,r10,8 /* Shift it so we can compare */
837 cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */
838 bne 1f /* If != go to normal path. */
840 /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
841 andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */
842 /* 3 in EXCEPTION_PROLOG_COMMON */
843 mr r10,r1 /* Save r1 */
844 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
845 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
846 b 3f /* Jump into the macro !! */
847 1: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
849 RECONCILE_IRQ_STATE(r10, r11)
850 addi r3,r1,STACK_FRAME_OVERHEAD
851 bl program_check_exception
855 EXC_REAL(fp_unavailable, 0x800, 0x100)
856 EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
857 TRAMP_KVM(PACA_EXGEN, 0x800)
858 EXC_COMMON_BEGIN(fp_unavailable_common)
859 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
860 bne 1f /* if from user, just load it up */
862 RECONCILE_IRQ_STATE(r10, r11)
863 addi r3,r1,STACK_FRAME_OVERHEAD
864 bl kernel_fp_unavailable_exception
867 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
869 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
870 * transaction), go do TM stuff
872 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
874 END_FTR_SECTION_IFSET(CPU_FTR_TM)
877 b fast_exception_return
878 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
879 2: /* User process was in a transaction */
881 RECONCILE_IRQ_STATE(r10, r11)
882 addi r3,r1,STACK_FRAME_OVERHEAD
888 EXC_REAL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
889 EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
890 TRAMP_KVM(PACA_EXGEN, 0x900)
891 EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
894 EXC_REAL_HV(hdecrementer, 0x980, 0x80)
895 EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
896 TRAMP_KVM_HV(PACA_EXGEN, 0x980)
897 EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
900 EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED)
901 EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED)
902 TRAMP_KVM(PACA_EXGEN, 0xa00)
903 #ifdef CONFIG_PPC_DOORBELL
904 EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
906 EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
910 EXC_REAL(trap_0b, 0xb00, 0x100)
911 EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
912 TRAMP_KVM(PACA_EXGEN, 0xb00)
913 EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
916 * system call / hypercall (0xc00, 0x4c00)
918 * The system call exception is invoked with "sc 0" and does not alter HV bit.
919 * There is support for kernel code to invoke system calls but there are no
922 * The hypercall is invoked with "sc 1" and sets HV=1.
924 * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
925 * 0x4c00 virtual mode.
929 * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
931 * For hypercalls, the register convention is as follows:
934 * r3 volatile parameter and return value for status
935 * r4-r10 volatile input and output value
936 * r11 volatile hypercall number and output value
937 * r12 volatile input and output value
938 * r13-r31 nonvolatile
942 * CR0-1 CR5-7 volatile
944 * Other registers nonvolatile
946 * The intersection of volatile registers that don't contain possible
947 * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
948 * without saving, though xer is not a good idea to use, as hardware may
949 * interpret some bits so it may be costly to change them.
951 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
953 * There is a little bit of juggling to get syscall and hcall
954 * working well. Save r13 in ctr to avoid using SPRG scratch
957 * Userspace syscalls have already saved the PPR, hcalls must save
958 * it before setting HMT_MEDIUM.
960 #define SYSCALL_KVMTEST \
963 std r10,PACA_EXGEN+EX_R10(r13); \
964 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
969 #define SYSCALL_KVMTEST \
975 #define LOAD_SYSCALL_HANDLER(reg) \
976 __LOAD_HANDLER(reg, system_call_common)
979 * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
982 #define SYSCALL_REAL \
983 mfspr r11,SPRN_SRR0 ; \
984 mfspr r12,SPRN_SRR1 ; \
985 LOAD_SYSCALL_HANDLER(r10) ; \
986 mtspr SPRN_SRR0,r10 ; \
987 ld r10,PACAKMSR(r13) ; \
988 mtspr SPRN_SRR1,r10 ; \
990 b . ; /* prevent speculative execution */
992 #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
993 #define SYSCALL_FASTENDIAN_TEST \
997 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
999 #define SYSCALL_FASTENDIAN \
1000 /* Fast LE/BE switch system call */ \
1001 1: mfspr r12,SPRN_SRR1 ; \
1002 xori r12,r12,MSR_LE ; \
1003 mtspr SPRN_SRR1,r12 ; \
1005 RFI_TO_USER ; /* return to userspace */ \
1006 b . ; /* prevent speculative execution */
1008 #define SYSCALL_FASTENDIAN_TEST
1009 #define SYSCALL_FASTENDIAN
1010 #endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
1012 #if defined(CONFIG_RELOCATABLE)
1014 * We can't branch directly so we do it via the CTR which
1015 * is volatile across system calls.
1017 #define SYSCALL_VIRT \
1018 LOAD_SYSCALL_HANDLER(r10) ; \
1020 mfspr r11,SPRN_SRR0 ; \
1021 mfspr r12,SPRN_SRR1 ; \
1026 /* We can branch directly */
1027 #define SYSCALL_VIRT \
1028 mfspr r11,SPRN_SRR0 ; \
1029 mfspr r12,SPRN_SRR1 ; \
1031 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
1032 b system_call_common ;
1035 EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
1036 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
1037 SYSCALL_FASTENDIAN_TEST
1040 EXC_REAL_END(system_call, 0xc00, 0x100)
1042 EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
1043 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
1044 SYSCALL_FASTENDIAN_TEST
1047 EXC_VIRT_END(system_call, 0x4c00, 0x100)
1049 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1051 * This is a hcall, so register convention is as above, with these
1055 * orig r10 saved in PACA
1057 TRAMP_KVM_BEGIN(do_kvm_0xc00)
1059 * Save the PPR (on systems that support it) before changing to
1060 * HMT_MEDIUM. That allows the KVM code to save that value into the
1061 * guest state (it is the guest's PPR value).
1063 OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
1065 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
1068 std r9,PACA_EXGEN+EX_R9(r13)
1070 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
1074 EXC_REAL(single_step, 0xd00, 0x100)
1075 EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
1076 TRAMP_KVM(PACA_EXGEN, 0xd00)
1077 EXC_COMMON(single_step_common, 0xd00, single_step_exception)
1079 EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
1080 EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
1081 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
1082 EXC_COMMON_BEGIN(h_data_storage_common)
1084 std r10,PACA_EXGEN+EX_DAR(r13)
1085 mfspr r10,SPRN_HDSISR
1086 stw r10,PACA_EXGEN+EX_DSISR(r13)
1087 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1089 RECONCILE_IRQ_STATE(r10, r11)
1090 addi r3,r1,STACK_FRAME_OVERHEAD
1091 bl unknown_exception
1095 EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
1096 EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
1097 TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
1098 EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
1101 EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
1102 EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
1103 TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
1104 EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
1108 * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1109 * first, and then eventaully from there to the trampoline to get into virtual
1112 __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
1113 __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
1114 EXC_VIRT_NONE(0x4e60, 0x20)
1115 TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1116 TRAMP_REAL_BEGIN(hmi_exception_early)
1117 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
1118 mr r10,r1 /* Save r1 */
1119 ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
1120 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1121 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
1122 mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
1123 EXCEPTION_PROLOG_COMMON_1()
1124 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1125 EXCEPTION_PROLOG_COMMON_3(0xe60)
1126 addi r3,r1,STACK_FRAME_OVERHEAD
1127 BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */
1130 /* Windup the stack. */
1131 /* Move original HSRR0 and HSRR1 into the respective regs */
1151 HRFI_TO_USER_OR_KERNEL
1158 * Go to virtual mode and pull the HMI event information from
1161 .globl hmi_exception_after_realmode
1162 hmi_exception_after_realmode:
1164 EXCEPTION_PROLOG_0(PACA_EXGEN)
1165 b tramp_real_hmi_exception
1167 EXC_COMMON_BEGIN(hmi_exception_common)
1168 EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
1169 ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
1171 EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED)
1172 EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED)
1173 TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1174 #ifdef CONFIG_PPC_DOORBELL
1175 EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1177 EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1181 EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED)
1182 EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED)
1183 TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1184 EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1187 EXC_REAL_NONE(0xec0, 0x20)
1188 EXC_VIRT_NONE(0x4ec0, 0x20)
1189 EXC_REAL_NONE(0xee0, 0x20)
1190 EXC_VIRT_NONE(0x4ee0, 0x20)
1193 EXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED)
1194 EXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED)
1195 TRAMP_KVM(PACA_EXGEN, 0xf00)
1196 EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1199 EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
1200 EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
1201 TRAMP_KVM(PACA_EXGEN, 0xf20)
1202 EXC_COMMON_BEGIN(altivec_unavailable_common)
1203 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1204 #ifdef CONFIG_ALTIVEC
1207 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1208 BEGIN_FTR_SECTION_NESTED(69)
1209 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1210 * transaction), go do TM stuff
1212 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1214 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1217 b fast_exception_return
1218 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1219 2: /* User process was in a transaction */
1221 RECONCILE_IRQ_STATE(r10, r11)
1222 addi r3,r1,STACK_FRAME_OVERHEAD
1223 bl altivec_unavailable_tm
1227 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1230 RECONCILE_IRQ_STATE(r10, r11)
1231 addi r3,r1,STACK_FRAME_OVERHEAD
1232 bl altivec_unavailable_exception
1236 EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
1237 EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
1238 TRAMP_KVM(PACA_EXGEN, 0xf40)
1239 EXC_COMMON_BEGIN(vsx_unavailable_common)
1240 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1244 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1245 BEGIN_FTR_SECTION_NESTED(69)
1246 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1247 * transaction), go do TM stuff
1249 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1251 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1254 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1255 2: /* User process was in a transaction */
1257 RECONCILE_IRQ_STATE(r10, r11)
1258 addi r3,r1,STACK_FRAME_OVERHEAD
1259 bl vsx_unavailable_tm
1263 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1266 RECONCILE_IRQ_STATE(r10, r11)
1267 addi r3,r1,STACK_FRAME_OVERHEAD
1268 bl vsx_unavailable_exception
1272 EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
1273 EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
1274 TRAMP_KVM(PACA_EXGEN, 0xf60)
1275 EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1278 EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
1279 EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
1280 TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1281 EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1284 EXC_REAL_NONE(0xfa0, 0x20)
1285 EXC_VIRT_NONE(0x4fa0, 0x20)
1286 EXC_REAL_NONE(0xfc0, 0x20)
1287 EXC_VIRT_NONE(0x4fc0, 0x20)
1288 EXC_REAL_NONE(0xfe0, 0x20)
1289 EXC_VIRT_NONE(0x4fe0, 0x20)
1291 EXC_REAL_NONE(0x1000, 0x100)
1292 EXC_VIRT_NONE(0x5000, 0x100)
1293 EXC_REAL_NONE(0x1100, 0x100)
1294 EXC_VIRT_NONE(0x5100, 0x100)
1296 #ifdef CONFIG_CBE_RAS
1297 EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
1298 EXC_VIRT_NONE(0x5200, 0x100)
1299 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
1300 EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
1301 #else /* CONFIG_CBE_RAS */
1302 EXC_REAL_NONE(0x1200, 0x100)
1303 EXC_VIRT_NONE(0x5200, 0x100)
1307 EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
1308 EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
1309 TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
1310 EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1312 EXC_REAL_NONE(0x1400, 0x100)
1313 EXC_VIRT_NONE(0x5400, 0x100)
1315 EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
1316 mtspr SPRN_SPRG_HSCRATCH0,r13
1317 EXCEPTION_PROLOG_0(PACA_EXGEN)
1318 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
1320 #ifdef CONFIG_PPC_DENORMALISATION
1321 mfspr r10,SPRN_HSRR1
1322 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
1323 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
1324 addi r11,r11,-4 /* HSRR0 is next instruction */
1329 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
1330 EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
1332 #ifdef CONFIG_PPC_DENORMALISATION
1333 EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
1334 b exc_real_0x1500_denorm_exception_hv
1335 EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
1337 EXC_VIRT_NONE(0x5500, 0x100)
1340 TRAMP_KVM_HV(PACA_EXGEN, 0x1500)
1342 #ifdef CONFIG_PPC_DENORMALISATION
1343 TRAMP_REAL_BEGIN(denorm_assist)
1346 * To denormalise we need to move a copy of the register to itself.
1347 * For POWER6 do that here for all FP regs.
1350 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1351 xori r10,r10,(MSR_FE0|MSR_FE1)
1355 #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
1356 #define FMR4(n) FMR2(n) ; FMR2(n+2)
1357 #define FMR8(n) FMR4(n) ; FMR4(n+4)
1358 #define FMR16(n) FMR8(n) ; FMR8(n+8)
1359 #define FMR32(n) FMR16(n) ; FMR16(n+16)
1364 * To denormalise we need to move a copy of the register to itself.
1365 * For POWER7 do that here for the first 32 VSX registers only.
1368 oris r10,r10,MSR_VSX@h
1372 #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
1373 #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
1374 #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
1375 #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
1376 #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
1379 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
1383 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1385 * To denormalise we need to move a copy of the register to itself.
1386 * For POWER8 we need to do that for all 64 VSX registers
1390 mtspr SPRN_HSRR0,r11
1392 ld r9,PACA_EXGEN+EX_R9(r13)
1393 RESTORE_PPR_PACA(PACA_EXGEN, r10)
1395 ld r10,PACA_EXGEN+EX_CFAR(r13)
1397 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1398 ld r10,PACA_EXGEN+EX_R10(r13)
1399 ld r11,PACA_EXGEN+EX_R11(r13)
1400 ld r12,PACA_EXGEN+EX_R12(r13)
1401 ld r13,PACA_EXGEN+EX_R13(r13)
1406 EXC_COMMON(denorm_common, 0x1500, unknown_exception)
1409 #ifdef CONFIG_CBE_RAS
1410 EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
1411 EXC_VIRT_NONE(0x5600, 0x100)
1412 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
1413 EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
1414 #else /* CONFIG_CBE_RAS */
1415 EXC_REAL_NONE(0x1600, 0x100)
1416 EXC_VIRT_NONE(0x5600, 0x100)
1420 EXC_REAL(altivec_assist, 0x1700, 0x100)
1421 EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
1422 TRAMP_KVM(PACA_EXGEN, 0x1700)
1423 #ifdef CONFIG_ALTIVEC
1424 EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
1426 EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
1430 #ifdef CONFIG_CBE_RAS
1431 EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
1432 EXC_VIRT_NONE(0x5800, 0x100)
1433 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
1434 EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
1435 #else /* CONFIG_CBE_RAS */
1436 EXC_REAL_NONE(0x1800, 0x100)
1437 EXC_VIRT_NONE(0x5800, 0x100)
1440 #ifdef CONFIG_PPC_WATCHDOG
1442 #define MASKED_DEC_HANDLER_LABEL 3f
1444 #define MASKED_DEC_HANDLER(_H) \
1446 std r12,PACA_EXGEN+EX_R12(r13); \
1447 GET_SCRATCH0(r10); \
1448 std r10,PACA_EXGEN+EX_R13(r13); \
1449 EXCEPTION_PROLOG_PSERIES_1(soft_nmi_common, _H)
1452 * Branch to soft_nmi_interrupt using the emergency stack. The emergency
1453 * stack is one that is usable by maskable interrupts so long as MSR_EE
1454 * remains off. It is used for recovery when something has corrupted the
1455 * normal kernel stack, for example. The "soft NMI" must not use the process
1456 * stack because we want irq disabled sections to avoid touching the stack
1457 * at all (other than PMU interrupts), so use the emergency stack for this,
1458 * and run it entirely with interrupts hard disabled.
1460 EXC_COMMON_BEGIN(soft_nmi_common)
1462 ld r1,PACAEMERGSP(r13)
1463 subi r1,r1,INT_FRAME_SIZE
1464 EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
1465 system_reset, soft_nmi_interrupt,
1466 ADD_NVGPRS;ADD_RECONCILE)
1469 #else /* CONFIG_PPC_WATCHDOG */
1470 #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
1471 #define MASKED_DEC_HANDLER(_H)
1472 #endif /* CONFIG_PPC_WATCHDOG */
1475 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
1476 * - If it was a decrementer interrupt, we bump the dec to max and and return.
1477 * - If it was a doorbell we return immediately since doorbells are edge
1478 * triggered and won't automatically refire.
1479 * - If it was a HMI we return immediately since we handled it in realmode
1480 * and it won't refire.
1481 * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
1482 * This is called with r10 containing the value to OR to the paca field.
1484 #define MASKED_INTERRUPT(_H) \
1485 masked_##_H##interrupt: \
1486 std r11,PACA_EXGEN+EX_R11(r13); \
1487 lbz r11,PACAIRQHAPPENED(r13); \
1489 stb r11,PACAIRQHAPPENED(r13); \
1490 cmpwi r10,PACA_IRQ_DEC; \
1493 ori r10,r10,0xffff; \
1494 mtspr SPRN_DEC,r10; \
1495 b MASKED_DEC_HANDLER_LABEL; \
1496 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK; \
1498 mfspr r10,SPRN_##_H##SRR1; \
1499 xori r10,r10,MSR_EE; /* clear MSR_EE */ \
1500 mtspr SPRN_##_H##SRR1,r10; \
1502 ld r9,PACA_EXGEN+EX_R9(r13); \
1503 ld r10,PACA_EXGEN+EX_R10(r13); \
1504 ld r11,PACA_EXGEN+EX_R11(r13); \
1505 /* returns to kernel where r13 must be set up, so don't restore it */ \
1506 ##_H##RFI_TO_KERNEL; \
1508 MASKED_DEC_HANDLER(_H)
1510 TRAMP_REAL_BEGIN(rfi_flush_fallback)
1513 std r9,PACA_EXRFI+EX_R9(r13)
1514 std r10,PACA_EXRFI+EX_R10(r13)
1515 std r11,PACA_EXRFI+EX_R11(r13)
1517 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
1518 ld r11,PACA_L1D_FLUSH_SIZE(r13)
1519 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
1521 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1523 /* order ld/st prior to dcbt stop all streams with flushing */
1527 * The load adresses are at staggered offsets within cachelines,
1528 * which suits some pipelines better (on others it should not
1532 ld r11,(0x80 + 8)*0(r10)
1533 ld r11,(0x80 + 8)*1(r10)
1534 ld r11,(0x80 + 8)*2(r10)
1535 ld r11,(0x80 + 8)*3(r10)
1536 ld r11,(0x80 + 8)*4(r10)
1537 ld r11,(0x80 + 8)*5(r10)
1538 ld r11,(0x80 + 8)*6(r10)
1539 ld r11,(0x80 + 8)*7(r10)
1544 ld r9,PACA_EXRFI+EX_R9(r13)
1545 ld r10,PACA_EXRFI+EX_R10(r13)
1546 ld r11,PACA_EXRFI+EX_R11(r13)
1550 TRAMP_REAL_BEGIN(hrfi_flush_fallback)
1553 std r9,PACA_EXRFI+EX_R9(r13)
1554 std r10,PACA_EXRFI+EX_R10(r13)
1555 std r11,PACA_EXRFI+EX_R11(r13)
1557 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
1558 ld r11,PACA_L1D_FLUSH_SIZE(r13)
1559 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
1561 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1563 /* order ld/st prior to dcbt stop all streams with flushing */
1567 * The load adresses are at staggered offsets within cachelines,
1568 * which suits some pipelines better (on others it should not
1572 ld r11,(0x80 + 8)*0(r10)
1573 ld r11,(0x80 + 8)*1(r10)
1574 ld r11,(0x80 + 8)*2(r10)
1575 ld r11,(0x80 + 8)*3(r10)
1576 ld r11,(0x80 + 8)*4(r10)
1577 ld r11,(0x80 + 8)*5(r10)
1578 ld r11,(0x80 + 8)*6(r10)
1579 ld r11,(0x80 + 8)*7(r10)
1584 ld r9,PACA_EXRFI+EX_R9(r13)
1585 ld r10,PACA_EXRFI+EX_R10(r13)
1586 ld r11,PACA_EXRFI+EX_R11(r13)
1591 * Real mode exceptions actually use this too, but alternate
1592 * instruction code patches (which end up in the common .text area)
1593 * cannot reach these if they are put there.
1595 USE_FIXED_SECTION(virt_trampolines)
1599 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1600 TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
1602 * Here all GPRs are unchanged from when the interrupt happened
1603 * except for r13, which is saved in SPRG_SCRATCH0.
1605 mfspr r13, SPRN_SRR0
1607 mtspr SPRN_SRR0, r13
1612 TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
1614 * Here all GPRs are unchanged from when the interrupt happened
1615 * except for r13, which is saved in SPRG_SCRATCH0.
1617 mfspr r13, SPRN_HSRR0
1619 mtspr SPRN_HSRR0, r13
1626 * Ensure that any handlers that get invoked from the exception prologs
1627 * above are below the first 64KB (0x10000) of the kernel image because
1628 * the prologs assemble the addresses of these handlers using the
1629 * LOAD_HANDLER macro, which uses an ori instruction.
1632 /*** Common interrupt handlers ***/
1636 * Relocation-on interrupts: A subset of the interrupts can be delivered
1637 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
1638 * it. Addresses are the same as the original interrupt addresses, but
1639 * offset by 0xc000000000004000.
1640 * It's impossible to receive interrupts below 0x300 via this mechanism.
1641 * KVM: None of these traps are from the guest ; anything that escalated
1642 * to HV=1 from HV=0 is delivered via real mode handlers.
1646 * This uses the standard macro, since the original 0x300 vector
1647 * only has extra guff for STAB-based processors -- which never
1651 EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
1652 b __ppc64_runlatch_on
1654 USE_FIXED_SECTION(virt_trampolines)
1656 * The __end_interrupts marker must be past the out-of-line (OOL)
1657 * handlers, so that they are copied to real address 0x100 when running
1658 * a relocatable kernel. This ensures they can be reached from the short
1659 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
1660 * directly, without using LOAD_HANDLER().
1663 .globl __end_interrupts
1665 DEFINE_FIXED_SYMBOL(__end_interrupts)
1667 #ifdef CONFIG_PPC_970_NAP
1668 EXC_COMMON_BEGIN(power4_fixup_nap)
1670 std r9,TI_LOCAL_FLAGS(r11)
1671 ld r10,_LINK(r1) /* make idle task do the */
1672 std r10,_NIP(r1) /* equivalent of a blr */
1676 CLOSE_FIXED_SECTION(real_vectors);
1677 CLOSE_FIXED_SECTION(real_trampolines);
1678 CLOSE_FIXED_SECTION(virt_vectors);
1679 CLOSE_FIXED_SECTION(virt_trampolines);
1686 .balign IFETCH_ALIGN_BYTES
1688 #ifdef CONFIG_PPC_BOOK3S_64
1689 lis r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h
1690 ori r0,r0,DSISR_BAD_FAULT_64S@l
1691 and. r0,r4,r0 /* weird error? */
1692 bne- handle_page_fault /* if not, try to insert a HPTE */
1693 CURRENT_THREAD_INFO(r11, r1)
1694 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1695 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1696 bne 77f /* then don't call hash_page now */
1699 * r3 contains the faulting address
1701 * r5 contains the trap number
1704 * at return r3 = 0 for success, 1 for page fault, negative for error
1708 bl __hash_page /* build HPTE if possible */
1709 cmpdi r3,0 /* see if __hash_page succeeded */
1712 beq fast_exc_return_irq /* Return from exception on success */
1717 /* Reload DSISR into r4 for the DABR check below */
1719 #endif /* CONFIG_PPC_BOOK3S_64 */
1721 /* Here we have a page fault that hash_page can't handle. */
1723 11: andis. r0,r4,DSISR_DABRMATCH@h
1724 bne- handle_dabr_fault
1727 addi r3,r1,STACK_FRAME_OVERHEAD
1733 addi r3,r1,STACK_FRAME_OVERHEAD
1738 /* We have a data breakpoint exception - handle it */
1743 addi r3,r1,STACK_FRAME_OVERHEAD
1745 12: b ret_from_except_lite
1748 #ifdef CONFIG_PPC_BOOK3S_64
1749 /* We have a page fault that hash_page could handle but HV refused
1754 addi r3,r1,STACK_FRAME_OVERHEAD
1761 * We come here as a result of a DSI at a point where we don't want
1762 * to call hash_page, such as when we are accessing memory (possibly
1763 * user memory) inside a PMU interrupt that occurred while interrupts
1764 * were soft-disabled. We want to invoke the exception handler for
1765 * the access, or panic if there isn't a handler.
1769 addi r3,r1,STACK_FRAME_OVERHEAD
1775 * Here we have detected that the kernel stack pointer is bad.
1776 * R9 contains the saved CR, r13 points to the paca,
1777 * r10 contains the (bad) kernel stack pointer,
1778 * r11 and r12 contain the saved SRR0 and SRR1.
1779 * We switch to using an emergency stack, save the registers there,
1780 * and call kernel_bad_stack(), which panics.
1783 ld r1,PACAEMERGSP(r13)
1784 subi r1,r1,64+INT_FRAME_SIZE
1790 mfspr r12,SPRN_DSISR
1816 std r10,ORIG_GPR3(r1)
1817 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1820 lhz r12,PACA_TRAP_SAVE(r13)
1822 addi r11,r1,INT_FRAME_SIZE
1827 ld r11,exception_marker@toc(r2)
1829 std r11,STACK_FRAME_OVERHEAD-16(r1)
1830 1: addi r3,r1,STACK_FRAME_OVERHEAD
1833 _ASM_NOKPROBE_SYMBOL(bad_stack);
1836 * When doorbell is triggered from system reset wakeup, the message is
1837 * not cleared, so it would fire again when EE is enabled.
1839 * When coming from local_irq_enable, there may be the same problem if
1840 * we were hard disabled.
1842 * Execute msgclr to clear pending exceptions before handling it.
1844 h_doorbell_common_msgclr:
1845 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1849 doorbell_super_common_msgclr:
1850 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1852 b doorbell_super_common
1855 * Called from arch_local_irq_enable when an interrupt needs
1856 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
1857 * which kind of interrupt. MSR:EE is already off. We generate a
1858 * stackframe like if a real interrupt had happened.
1860 * Note: While MSR:EE is off, we need to make sure that _MSR
1861 * in the generated frame has EE set to 1 or the exception
1862 * handler will not properly re-enable them.
1864 * Note that we don't specify LR as the NIP (return address) for
1865 * the interrupt because that would unbalance the return branch
1868 _GLOBAL(__replay_interrupt)
1869 /* We are going to jump to the exception common code which
1870 * will retrieve various register values from the PACA which
1871 * we don't give a damn about, so we don't bother storing them.
1874 LOAD_REG_ADDR(r11, replay_interrupt_return)
1878 beq decrementer_common
1881 beq h_virt_irq_common
1883 beq hardware_interrupt_common
1884 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
1886 beq performance_monitor_common
1889 beq h_doorbell_common_msgclr
1891 beq hmi_exception_common
1894 beq doorbell_super_common_msgclr
1895 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1896 replay_interrupt_return:
1899 _ASM_NOKPROBE_SYMBOL(__replay_interrupt)