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>
21 #include <asm/feature-fixups.h>
25 * There are a few constraints to be concerned with.
26 * - Real mode exceptions code/data must be located at their physical location.
27 * - Virtual mode exceptions must be mapped at their 0xc000... location.
28 * - Fixed location code must not call directly beyond the __end_interrupts
29 * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
31 * - LOAD_HANDLER targets must be within first 64K of physical 0 /
33 * - Conditional branch targets must be within +/-32K of caller.
35 * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
36 * therefore don't have to run in physically located code or rfid to
37 * virtual mode kernel code. However on relocatable kernels they do have
38 * to branch to KERNELBASE offset because the rest of the kernel (outside
39 * the exception vectors) may be located elsewhere.
41 * Virtual exceptions correspond with physical, except their entry points
42 * are offset by 0xc000000000000000 and also tend to get an added 0x4000
43 * offset applied. Virtual exceptions are enabled with the Alternate
44 * Interrupt Location (AIL) bit set in the LPCR. However this does not
45 * guarantee they will be delivered virtually. Some conditions (see the ISA)
46 * cause exceptions to be delivered in real mode.
48 * It's impossible to receive interrupts below 0x300 via AIL.
50 * KVM: None of the virtual exceptions are from the guest. Anything that
51 * escalated to HV=1 from HV=0 is delivered via real mode handlers.
54 * We layout physical memory as follows:
55 * 0x0000 - 0x00ff : Secondary processor spin code
56 * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
57 * 0x1900 - 0x3fff : Real mode trampolines
58 * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
59 * 0x5900 - 0x6fff : Relon mode trampolines
60 * 0x7000 - 0x7fff : FWNMI data area
61 * 0x8000 - .... : Common interrupt handlers, remaining early
62 * setup code, rest of kernel.
64 * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
65 * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
68 OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
69 OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000)
70 OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900)
71 OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
73 #ifdef CONFIG_PPC_POWERNV
74 .globl start_real_trampolines
75 .globl end_real_trampolines
76 .globl start_virt_trampolines
77 .globl end_virt_trampolines
80 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
82 * Data area reserved for FWNMI option.
83 * This address (0x7000) is fixed by the RPA.
84 * pseries and powernv need to keep the whole page from
85 * 0x7000 to 0x8000 free for use by the firmware
87 ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
88 OPEN_TEXT_SECTION(0x8000)
90 OPEN_TEXT_SECTION(0x7000)
93 USE_FIXED_SECTION(real_vectors)
96 * This is the start of the interrupt handlers for pSeries
97 * This code runs with relocation off.
98 * Code from here to __end_interrupts gets copied down to real
99 * address 0x100 when we are running a relocatable kernel.
100 * Therefore any relative branches in this section must only
101 * branch to labels in this section.
103 .globl __start_interrupts
106 /* No virt vectors corresponding with 0x0..0x100 */
107 EXC_VIRT_NONE(0x4000, 0x100)
110 #ifdef CONFIG_PPC_P7_NAP
112 * If running native on arch 2.06 or later, check if we are waking up
113 * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
114 * bits 46:47. A non-0 value indicates that we are coming from a power
115 * saving state. The idle wakeup handler initially runs in real mode,
116 * but we branch to the 0xc000... address so we can turn on relocation
119 #define IDLETEST(n) \
120 BEGIN_FTR_SECTION ; \
121 mfspr r10,SPRN_SRR1 ; \
122 rlwinm. r10,r10,47-31,30,31 ; \
125 mfspr r3,SPRN_SRR1 ; \
126 bltlr cr1 ; /* no state loss, return to idle caller */ \
127 BRANCH_TO_C000(r10, system_reset_idle_common) ; \
130 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
132 #define IDLETEST NOTEST
135 EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
138 * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
139 * being used, so a nested NMI exception would corrupt it.
141 EXCEPTION_PROLOG_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
144 EXC_REAL_END(system_reset, 0x100, 0x100)
145 EXC_VIRT_NONE(0x4100, 0x100)
146 TRAMP_KVM(PACA_EXNMI, 0x100)
148 #ifdef CONFIG_PPC_P7_NAP
149 EXC_COMMON_BEGIN(system_reset_idle_common)
151 * This must be a direct branch (without linker branch stub) because
152 * we can not use TOC at this point as r2 may not be restored yet.
154 b idle_return_gpr_loss
158 * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does
159 * the right thing. We do not want to reconcile because that goes
160 * through irq tracing which we don't want in NMI.
162 * Save PACAIRQHAPPENED because some code will do a hard disable
163 * (e.g., xmon). So we want to restore this back to where it was
164 * when we return. DAR is unused in the stack, so save it there.
166 #define ADD_RECONCILE_NMI \
167 li r10,IRQS_ALL_DISABLED; \
168 stb r10,PACAIRQSOFTMASK(r13); \
169 lbz r10,PACAIRQHAPPENED(r13); \
172 EXC_COMMON_BEGIN(system_reset_common)
174 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
175 * to recover, but nested NMI will notice in_nmi and not recover
176 * because of the use of the NMI stack. in_nmi reentrancy is tested in
177 * system_reset_exception.
179 lhz r10,PACA_IN_NMI(r13)
181 sth r10,PACA_IN_NMI(r13)
186 ld r1,PACA_NMI_EMERG_SP(r13)
187 subi r1,r1,INT_FRAME_SIZE
188 EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
189 system_reset, system_reset_exception,
190 ADD_NVGPRS;ADD_RECONCILE_NMI)
192 /* This (and MCE) can be simplified with mtmsrd L=1 */
193 /* Clear MSR_RI before setting SRR0 and SRR1. */
200 * MSR_RI is clear, now we can decrement paca->in_nmi.
202 lhz r10,PACA_IN_NMI(r13)
204 sth r10,PACA_IN_NMI(r13)
207 * Restore soft mask settings.
210 stb r10,PACAIRQHAPPENED(r13)
212 stb r10,PACAIRQSOFTMASK(r13)
215 * Keep below code in synch with MACHINE_CHECK_HANDLER_WINDUP.
216 * Should share common bits...
219 /* Move original SRR0 and SRR1 into the respective regs */
237 /* restore original r1. */
239 RFI_TO_USER_OR_KERNEL
241 #ifdef CONFIG_PPC_PSERIES
243 * Vectors for the FWNMI option. Share common code.
245 TRAMP_REAL_BEGIN(system_reset_fwnmi)
246 SET_SCRATCH0(r13) /* save r13 */
247 /* See comment at system_reset exception */
248 EXCEPTION_PROLOG_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
250 #endif /* CONFIG_PPC_PSERIES */
253 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
254 /* This is moved out of line as it can be patched by FW, but
255 * some code path might still want to branch into the original
258 SET_SCRATCH0(r13) /* save r13 */
259 EXCEPTION_PROLOG_0(PACA_EXMC)
261 b machine_check_common_early
263 b machine_check_pSeries_0
264 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
265 EXC_REAL_END(machine_check, 0x200, 0x100)
266 EXC_VIRT_NONE(0x4200, 0x100)
267 TRAMP_REAL_BEGIN(machine_check_common_early)
268 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
273 * Original R9 to R13 is saved on PACA_EXMC
275 * Switch to mc_emergency stack and handle re-entrancy (we limit
276 * the nested MCE upto level 4 to avoid stack overflow).
277 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
279 * We use paca->in_mce to check whether this is the first entry or
280 * nested machine check. We increment paca->in_mce to track nested
283 * If this is the first entry then set stack pointer to
284 * paca->mc_emergency_sp, otherwise r1 is already pointing to
285 * stack frame on mc_emergency stack.
287 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
288 * checkstop if we get another machine check exception before we do
289 * rfid with MSR_ME=1.
291 * This interrupt can wake directly from idle. If that is the case,
292 * the machine check is handled then the idle wakeup code is called
295 mr r11,r1 /* Save r1 */
296 lhz r10,PACA_IN_MCE(r13)
297 cmpwi r10,0 /* Are we in nested machine check */
298 bne 0f /* Yes, we are. */
299 /* First machine check entry */
300 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
301 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
302 addi r10,r10,1 /* increment paca->in_mce */
303 sth r10,PACA_IN_MCE(r13)
304 /* Limit nested MCE to level 4 to avoid stack overflow */
305 cmpwi r10,MAX_MCE_DEPTH
306 bgt 2f /* Check if we hit limit of 4 */
307 std r11,GPR1(r1) /* Save r1 on the stack. */
308 std r11,0(r1) /* make stack chain pointer */
309 mfspr r11,SPRN_SRR0 /* Save SRR0 */
311 mfspr r11,SPRN_SRR1 /* Save SRR1 */
313 mfspr r11,SPRN_DAR /* Save DAR */
315 mfspr r11,SPRN_DSISR /* Save DSISR */
317 std r9,_CCR(r1) /* Save CR in stackframe */
318 /* We don't touch AMR here, we never go to virtual mode */
319 /* Save r9 through r13 from EXMC save area to stack frame. */
320 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
321 mfmsr r11 /* get MSR value */
323 ori r11,r11,MSR_ME /* turn on ME bit */
324 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
325 ori r11,r11,MSR_RI /* turn on RI bit */
326 LOAD_HANDLER(r12, machine_check_handle_early)
327 1: mtspr SPRN_SRR0,r12
330 b . /* prevent speculative execution */
332 /* Stack overflow. Stay on emergency stack and panic.
333 * Keep the ME bit off while panic-ing, so that if we hit
334 * another machine check we checkstop.
336 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
338 LOAD_HANDLER(r12, unrecover_mce)
340 andc r11,r11,r10 /* Turn off MSR_ME */
342 b . /* prevent speculative execution */
344 TRAMP_REAL_BEGIN(machine_check_pSeries)
345 .globl machine_check_fwnmi
347 SET_SCRATCH0(r13) /* save r13 */
348 EXCEPTION_PROLOG_0(PACA_EXMC)
350 b machine_check_common_early
351 END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
352 machine_check_pSeries_0:
353 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
355 * MSR_RI is not enabled, because PACA_EXMC is being used, so a
356 * nested machine check corrupts it. machine_check_common enables
359 EXCEPTION_PROLOG_2_NORI(machine_check_common, EXC_STD)
361 TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
363 EXC_COMMON_BEGIN(machine_check_common)
365 * Machine check is different because we use a different
366 * save area: PACA_EXMC instead of PACA_EXGEN.
369 std r10,PACA_EXMC+EX_DAR(r13)
371 stw r10,PACA_EXMC+EX_DSISR(r13)
372 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
374 RECONCILE_IRQ_STATE(r10, r11)
375 ld r3,PACA_EXMC+EX_DAR(r13)
376 lwz r4,PACA_EXMC+EX_DSISR(r13)
377 /* Enable MSR_RI when finished with PACA_EXMC */
383 addi r3,r1,STACK_FRAME_OVERHEAD
384 bl machine_check_exception
387 #define MACHINE_CHECK_HANDLER_WINDUP \
388 /* Clear MSR_RI before setting SRR0 and SRR1. */\
390 mfmsr r9; /* get MSR value */ \
392 mtmsrd r9,1; /* Clear MSR_RI */ \
393 /* Move original SRR0 and SRR1 into the respective regs */ \
395 mtspr SPRN_SRR1,r9; \
397 mtspr SPRN_SRR0,r3; \
409 /* Decrement paca->in_mce. */ \
410 lhz r12,PACA_IN_MCE(r13); \
412 sth r12,PACA_IN_MCE(r13); \
414 REST_2GPRS(12, r1); \
415 /* restore original r1. */ \
418 #ifdef CONFIG_PPC_P7_NAP
420 * This is an idle wakeup. Low level machine check has already been
421 * done. Queue the event then call the idle code to do the wake up.
423 EXC_COMMON_BEGIN(machine_check_idle_common)
424 bl machine_check_queue_event
427 * We have not used any non-volatile GPRs here, and as a rule
428 * most exception code including machine check does not.
429 * Therefore PACA_NAPSTATELOST does not need to be set. Idle
430 * wakeup will restore volatile registers.
432 * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
434 * Then decrement MCE nesting after finishing with the stack.
439 lhz r11,PACA_IN_MCE(r13)
441 sth r11,PACA_IN_MCE(r13)
444 rlwinm r10,r3,47-31,30,31
446 bltlr cr1 /* no state loss, return to idle caller */
447 b idle_return_gpr_loss
450 * Handle machine check early in real mode. We come here with
451 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
453 EXC_COMMON_BEGIN(machine_check_handle_early)
454 std r0,GPR0(r1) /* Save r0 */
455 EXCEPTION_PROLOG_COMMON_3(0x200)
457 addi r3,r1,STACK_FRAME_OVERHEAD
458 bl machine_check_early
459 std r3,RESULT(r1) /* Save result */
463 END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
465 #ifdef CONFIG_PPC_P7_NAP
467 * Check if thread was in power saving mode. We come here when any
468 * of the following is true:
469 * a. thread wasn't in power saving mode
470 * b. thread was in power saving mode with no state loss,
471 * supervisor state loss or hypervisor state loss.
473 * Go back to nap/sleep/winkle mode again if (b) is true.
476 rlwinm. r11,r12,47-31,30,31
477 bne machine_check_idle_common
478 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
482 * Check if we are coming from hypervisor userspace. If yes then we
483 * continue in host kernel in V mode to deliver the MC event.
485 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
487 4: andi. r11,r12,MSR_PR /* See if coming from user. */
488 bne 9f /* continue in V mode if we are. */
491 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
494 * We are coming from kernel context. Check if we are coming from
495 * guest. if yes, then we can continue. We will fall through
496 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
498 lbz r11,HSTATE_IN_GUEST(r13)
499 cmpwi r11,0 /* Check if coming from guest */
500 bne 9f /* continue if we are. */
501 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
504 * At this point we are not sure about what context we come from.
505 * Queue up the MCE event and return from the interrupt.
506 * But before that, check if this is an un-recoverable exception.
507 * If yes, then stay on emergency stack and panic.
511 1: mfspr r11,SPRN_SRR0
512 LOAD_HANDLER(r10,unrecover_mce)
516 * We are going down. But there are chances that we might get hit by
517 * another MCE during panic path and we may run into unstable state
518 * with no way out. Hence, turn ME bit off while going down, so that
519 * when another MCE is hit during panic path, system will checkstop
520 * and hypervisor will get restarted cleanly by SP.
523 andc r10,r10,r3 /* Turn off MSR_ME */
529 * Check if we have successfully handled/recovered from error, if not
530 * then stay on emergency stack and panic.
532 ld r3,RESULT(r1) /* Load result */
533 cmpdi r3,0 /* see if we handled MCE successfully */
535 beq 1b /* if !handled then panic */
538 * Return from MC interrupt.
539 * Queue up the MCE event so that we can log it later, while
540 * returning from kernel or opal call.
542 bl machine_check_queue_event
543 MACHINE_CHECK_HANDLER_WINDUP
544 RFI_TO_USER_OR_KERNEL
547 * pSeries: Return from MC interrupt. Before that stay on emergency
548 * stack and call machine_check_exception to log the MCE event.
550 LOAD_HANDLER(r10,mce_return)
556 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
558 /* Deliver the machine check to host kernel in V mode. */
559 MACHINE_CHECK_HANDLER_WINDUP
560 SET_SCRATCH0(r13) /* save r13 */
561 EXCEPTION_PROLOG_0(PACA_EXMC)
562 b machine_check_pSeries_0
564 EXC_COMMON_BEGIN(unrecover_mce)
565 /* Invoke machine_check_exception to print MCE event and panic. */
566 addi r3,r1,STACK_FRAME_OVERHEAD
567 bl machine_check_exception
569 * We will not reach here. Even if we did, there is no way out. Call
570 * unrecoverable_exception and die.
572 1: addi r3,r1,STACK_FRAME_OVERHEAD
573 bl unrecoverable_exception
576 EXC_COMMON_BEGIN(mce_return)
577 /* Invoke machine_check_exception to print MCE event and return. */
578 addi r3,r1,STACK_FRAME_OVERHEAD
579 bl machine_check_exception
580 MACHINE_CHECK_HANDLER_WINDUP
584 EXC_REAL_BEGIN(data_access, 0x300, 0x80)
585 SET_SCRATCH0(r13) /* save r13 */
586 EXCEPTION_PROLOG_0(PACA_EXGEN)
587 b tramp_real_data_access
588 EXC_REAL_END(data_access, 0x300, 0x80)
590 TRAMP_REAL_BEGIN(tramp_real_data_access)
591 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, 0x300)
593 * DAR/DSISR must be read before setting MSR[RI], because
594 * a d-side MCE will clobber those registers so is not
595 * recoverable if they are live.
599 std r10,PACA_EXGEN+EX_DAR(r13)
600 stw r11,PACA_EXGEN+EX_DSISR(r13)
601 EXCEPTION_PROLOG_2(data_access_common, EXC_STD)
603 EXC_VIRT_BEGIN(data_access, 0x4300, 0x80)
604 SET_SCRATCH0(r13) /* save r13 */
605 EXCEPTION_PROLOG_0(PACA_EXGEN)
606 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x300)
609 std r10,PACA_EXGEN+EX_DAR(r13)
610 stw r11,PACA_EXGEN+EX_DSISR(r13)
611 EXCEPTION_PROLOG_2_RELON(data_access_common, EXC_STD)
612 EXC_VIRT_END(data_access, 0x4300, 0x80)
614 TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
616 EXC_COMMON_BEGIN(data_access_common)
618 * Here r13 points to the paca, r9 contains the saved CR,
619 * SRR0 and SRR1 are saved in r11 and r12,
620 * r9 - r13 are saved in paca->exgen.
621 * EX_DAR and EX_DSISR have saved DAR/DSISR
623 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
624 RECONCILE_IRQ_STATE(r10, r11)
626 ld r3,PACA_EXGEN+EX_DAR(r13)
627 lwz r4,PACA_EXGEN+EX_DSISR(r13)
631 BEGIN_MMU_FTR_SECTION
632 b do_hash_page /* Try to handle as hpte fault */
635 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
638 EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
639 SET_SCRATCH0(r13) /* save r13 */
640 EXCEPTION_PROLOG_0(PACA_EXSLB)
641 b tramp_real_data_access_slb
642 EXC_REAL_END(data_access_slb, 0x380, 0x80)
644 TRAMP_REAL_BEGIN(tramp_real_data_access_slb)
645 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
647 std r10,PACA_EXSLB+EX_DAR(r13)
648 EXCEPTION_PROLOG_2(data_access_slb_common, EXC_STD)
650 EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
651 SET_SCRATCH0(r13) /* save r13 */
652 EXCEPTION_PROLOG_0(PACA_EXSLB)
653 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
655 std r10,PACA_EXSLB+EX_DAR(r13)
656 EXCEPTION_PROLOG_2_RELON(data_access_slb_common, EXC_STD)
657 EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
659 TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
661 EXC_COMMON_BEGIN(data_access_slb_common)
662 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
663 ld r4,PACA_EXSLB+EX_DAR(r13)
665 addi r3,r1,STACK_FRAME_OVERHEAD
666 BEGIN_MMU_FTR_SECTION
667 /* HPT case, do SLB fault */
671 b fast_exception_return
674 /* Radix case, access is outside page table range */
676 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
679 RECONCILE_IRQ_STATE(r10, r11)
682 addi r3,r1,STACK_FRAME_OVERHEAD
687 EXC_REAL(instruction_access, 0x400, 0x80)
688 EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
689 TRAMP_KVM(PACA_EXGEN, 0x400)
691 EXC_COMMON_BEGIN(instruction_access_common)
692 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
693 RECONCILE_IRQ_STATE(r10, r11)
696 andis. r4,r12,DSISR_SRR1_MATCH_64S@h
700 BEGIN_MMU_FTR_SECTION
701 b do_hash_page /* Try to handle as hpte fault */
704 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
707 EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
708 EXCEPTION_PROLOG(PACA_EXSLB, instruction_access_slb_common, EXC_STD, KVMTEST_PR, 0x480);
709 EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
711 EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
712 EXCEPTION_RELON_PROLOG(PACA_EXSLB, instruction_access_slb_common, EXC_STD, NOTEST, 0x480);
713 EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
715 TRAMP_KVM(PACA_EXSLB, 0x480)
717 EXC_COMMON_BEGIN(instruction_access_slb_common)
718 EXCEPTION_PROLOG_COMMON(0x480, PACA_EXSLB)
720 addi r3,r1,STACK_FRAME_OVERHEAD
721 BEGIN_MMU_FTR_SECTION
722 /* HPT case, do SLB fault */
726 b fast_exception_return
729 /* Radix case, access is outside page table range */
731 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
734 RECONCILE_IRQ_STATE(r10, r11)
737 addi r3,r1,STACK_FRAME_OVERHEAD
742 EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
743 .globl hardware_interrupt_hv;
744 hardware_interrupt_hv:
746 MASKABLE_EXCEPTION_HV(0x500, hardware_interrupt_common, IRQS_DISABLED)
748 MASKABLE_EXCEPTION(0x500, hardware_interrupt_common, IRQS_DISABLED)
749 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
750 EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
752 EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
753 .globl hardware_interrupt_relon_hv;
754 hardware_interrupt_relon_hv:
756 MASKABLE_RELON_EXCEPTION_HV(0x500, hardware_interrupt_common,
759 __MASKABLE_RELON_EXCEPTION(0x500, hardware_interrupt_common,
760 EXC_STD, SOFTEN_TEST_PR, IRQS_DISABLED)
761 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
762 EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
764 TRAMP_KVM(PACA_EXGEN, 0x500)
765 TRAMP_KVM_HV(PACA_EXGEN, 0x500)
766 EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
769 EXC_REAL_BEGIN(alignment, 0x600, 0x100)
770 SET_SCRATCH0(r13) /* save r13 */
771 EXCEPTION_PROLOG_0(PACA_EXGEN)
772 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, 0x600)
775 std r10,PACA_EXGEN+EX_DAR(r13)
776 stw r11,PACA_EXGEN+EX_DSISR(r13)
777 EXCEPTION_PROLOG_2(alignment_common, EXC_STD)
778 EXC_REAL_END(alignment, 0x600, 0x100)
780 EXC_VIRT_BEGIN(alignment, 0x4600, 0x100)
781 SET_SCRATCH0(r13) /* save r13 */
782 EXCEPTION_PROLOG_0(PACA_EXGEN)
783 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x600)
786 std r10,PACA_EXGEN+EX_DAR(r13)
787 stw r11,PACA_EXGEN+EX_DSISR(r13)
788 EXCEPTION_PROLOG_2_RELON(alignment_common, EXC_STD)
789 EXC_VIRT_END(alignment, 0x4600, 0x100)
791 TRAMP_KVM(PACA_EXGEN, 0x600)
792 EXC_COMMON_BEGIN(alignment_common)
793 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
794 ld r3,PACA_EXGEN+EX_DAR(r13)
795 lwz r4,PACA_EXGEN+EX_DSISR(r13)
799 RECONCILE_IRQ_STATE(r10, r11)
800 addi r3,r1,STACK_FRAME_OVERHEAD
801 bl alignment_exception
805 EXC_REAL(program_check, 0x700, 0x100)
806 EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
807 TRAMP_KVM(PACA_EXGEN, 0x700)
808 EXC_COMMON_BEGIN(program_check_common)
810 * It's possible to receive a TM Bad Thing type program check with
811 * userspace register values (in particular r1), but with SRR1 reporting
812 * that we came from the kernel. Normally that would confuse the bad
813 * stack logic, and we would report a bad kernel stack pointer. Instead
814 * we switch to the emergency stack if we're taking a TM Bad Thing from
817 li r10,MSR_PR /* Build a mask of MSR_PR .. */
818 oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */
819 and r10,r10,r12 /* Mask SRR1 with that. */
820 srdi r10,r10,8 /* Shift it so we can compare */
821 cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */
822 bne 1f /* If != go to normal path. */
824 /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
825 andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */
826 /* 3 in EXCEPTION_PROLOG_COMMON */
827 mr r10,r1 /* Save r1 */
828 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
829 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
830 b 3f /* Jump into the macro !! */
831 1: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
833 RECONCILE_IRQ_STATE(r10, r11)
834 addi r3,r1,STACK_FRAME_OVERHEAD
835 bl program_check_exception
839 EXC_REAL(fp_unavailable, 0x800, 0x100)
840 EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
841 TRAMP_KVM(PACA_EXGEN, 0x800)
842 EXC_COMMON_BEGIN(fp_unavailable_common)
843 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
844 bne 1f /* if from user, just load it up */
846 RECONCILE_IRQ_STATE(r10, r11)
847 addi r3,r1,STACK_FRAME_OVERHEAD
848 bl kernel_fp_unavailable_exception
851 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
853 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
854 * transaction), go do TM stuff
856 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
858 END_FTR_SECTION_IFSET(CPU_FTR_TM)
861 b fast_exception_return
862 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
863 2: /* User process was in a transaction */
865 RECONCILE_IRQ_STATE(r10, r11)
866 addi r3,r1,STACK_FRAME_OVERHEAD
872 EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
873 EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
874 TRAMP_KVM(PACA_EXGEN, 0x900)
875 EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
878 EXC_REAL_HV(hdecrementer, 0x980, 0x80)
879 EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
880 TRAMP_KVM_HV(PACA_EXGEN, 0x980)
881 EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
884 EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED)
885 EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED)
886 TRAMP_KVM(PACA_EXGEN, 0xa00)
887 #ifdef CONFIG_PPC_DOORBELL
888 EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
890 EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
894 EXC_REAL(trap_0b, 0xb00, 0x100)
895 EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
896 TRAMP_KVM(PACA_EXGEN, 0xb00)
897 EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
900 * system call / hypercall (0xc00, 0x4c00)
902 * The system call exception is invoked with "sc 0" and does not alter HV bit.
903 * There is support for kernel code to invoke system calls but there are no
906 * The hypercall is invoked with "sc 1" and sets HV=1.
908 * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
909 * 0x4c00 virtual mode.
913 * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
915 * For hypercalls, the register convention is as follows:
918 * r3 volatile parameter and return value for status
919 * r4-r10 volatile input and output value
920 * r11 volatile hypercall number and output value
921 * r12 volatile input and output value
922 * r13-r31 nonvolatile
926 * CR0-1 CR5-7 volatile
928 * Other registers nonvolatile
930 * The intersection of volatile registers that don't contain possible
931 * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
932 * without saving, though xer is not a good idea to use, as hardware may
933 * interpret some bits so it may be costly to change them.
935 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
937 * There is a little bit of juggling to get syscall and hcall
938 * working well. Save r13 in ctr to avoid using SPRG scratch
941 * Userspace syscalls have already saved the PPR, hcalls must save
942 * it before setting HMT_MEDIUM.
944 #define SYSCALL_KVMTEST \
947 std r10,PACA_EXGEN+EX_R10(r13); \
948 INTERRUPT_TO_KERNEL; \
949 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
954 #define SYSCALL_KVMTEST \
961 #define LOAD_SYSCALL_HANDLER(reg) \
962 __LOAD_HANDLER(reg, system_call_common)
965 * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
968 #define SYSCALL_REAL \
969 mfspr r11,SPRN_SRR0 ; \
970 mfspr r12,SPRN_SRR1 ; \
971 LOAD_SYSCALL_HANDLER(r10) ; \
972 mtspr SPRN_SRR0,r10 ; \
973 ld r10,PACAKMSR(r13) ; \
974 mtspr SPRN_SRR1,r10 ; \
976 b . ; /* prevent speculative execution */
978 #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
979 #define SYSCALL_FASTENDIAN_TEST \
983 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
985 #define SYSCALL_FASTENDIAN \
986 /* Fast LE/BE switch system call */ \
987 1: mfspr r12,SPRN_SRR1 ; \
988 xori r12,r12,MSR_LE ; \
989 mtspr SPRN_SRR1,r12 ; \
991 RFI_TO_USER ; /* return to userspace */ \
992 b . ; /* prevent speculative execution */
994 #define SYSCALL_FASTENDIAN_TEST
995 #define SYSCALL_FASTENDIAN
996 #endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
998 #if defined(CONFIG_RELOCATABLE)
1000 * We can't branch directly so we do it via the CTR which
1001 * is volatile across system calls.
1003 #define SYSCALL_VIRT \
1004 LOAD_SYSCALL_HANDLER(r10) ; \
1006 mfspr r11,SPRN_SRR0 ; \
1007 mfspr r12,SPRN_SRR1 ; \
1012 /* We can branch directly */
1013 #define SYSCALL_VIRT \
1014 mfspr r11,SPRN_SRR0 ; \
1015 mfspr r12,SPRN_SRR1 ; \
1017 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
1018 b system_call_common ;
1021 EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
1022 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
1023 SYSCALL_FASTENDIAN_TEST
1026 EXC_REAL_END(system_call, 0xc00, 0x100)
1028 EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
1029 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
1030 SYSCALL_FASTENDIAN_TEST
1033 EXC_VIRT_END(system_call, 0x4c00, 0x100)
1035 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1037 * This is a hcall, so register convention is as above, with these
1041 * orig r10 saved in PACA
1043 TRAMP_KVM_BEGIN(do_kvm_0xc00)
1045 * Save the PPR (on systems that support it) before changing to
1046 * HMT_MEDIUM. That allows the KVM code to save that value into the
1047 * guest state (it is the guest's PPR value).
1049 OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
1051 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
1054 std r9,PACA_EXGEN+EX_R9(r13)
1056 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
1060 EXC_REAL(single_step, 0xd00, 0x100)
1061 EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
1062 TRAMP_KVM(PACA_EXGEN, 0xd00)
1063 EXC_COMMON(single_step_common, 0xd00, single_step_exception)
1065 EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
1066 EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
1067 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
1068 EXC_COMMON_BEGIN(h_data_storage_common)
1070 std r10,PACA_EXGEN+EX_DAR(r13)
1071 mfspr r10,SPRN_HDSISR
1072 stw r10,PACA_EXGEN+EX_DSISR(r13)
1073 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1075 RECONCILE_IRQ_STATE(r10, r11)
1076 addi r3,r1,STACK_FRAME_OVERHEAD
1077 BEGIN_MMU_FTR_SECTION
1078 ld r4,PACA_EXGEN+EX_DAR(r13)
1079 lwz r5,PACA_EXGEN+EX_DSISR(r13)
1084 MMU_FTR_SECTION_ELSE
1085 bl unknown_exception
1086 ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX)
1090 EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
1091 EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
1092 TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
1093 EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
1096 EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
1097 EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
1098 TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
1099 EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
1103 * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1104 * first, and then eventaully from there to the trampoline to get into virtual
1107 __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
1108 __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
1109 EXC_VIRT_NONE(0x4e60, 0x20)
1110 TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1111 TRAMP_REAL_BEGIN(hmi_exception_early)
1112 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
1113 mr r10,r1 /* Save r1 */
1114 ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
1115 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1116 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
1117 mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
1118 EXCEPTION_PROLOG_COMMON_1()
1119 /* We don't touch AMR here, we never go to virtual mode */
1120 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1121 EXCEPTION_PROLOG_COMMON_3(0xe60)
1122 addi r3,r1,STACK_FRAME_OVERHEAD
1123 BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI */
1126 /* Windup the stack. */
1127 /* Move original HSRR0 and HSRR1 into the respective regs */
1147 HRFI_TO_USER_OR_KERNEL
1154 * Go to virtual mode and pull the HMI event information from
1157 .globl hmi_exception_after_realmode
1158 hmi_exception_after_realmode:
1160 EXCEPTION_PROLOG_0(PACA_EXGEN)
1161 b tramp_real_hmi_exception
1163 EXC_COMMON_BEGIN(hmi_exception_common)
1164 EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
1165 ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
1167 EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED)
1168 EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED)
1169 TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1170 #ifdef CONFIG_PPC_DOORBELL
1171 EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1173 EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1177 EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED)
1178 EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED)
1179 TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1180 EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1183 EXC_REAL_NONE(0xec0, 0x20)
1184 EXC_VIRT_NONE(0x4ec0, 0x20)
1185 EXC_REAL_NONE(0xee0, 0x20)
1186 EXC_VIRT_NONE(0x4ee0, 0x20)
1189 EXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED)
1190 EXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED)
1191 TRAMP_KVM(PACA_EXGEN, 0xf00)
1192 EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1195 EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
1196 EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
1197 TRAMP_KVM(PACA_EXGEN, 0xf20)
1198 EXC_COMMON_BEGIN(altivec_unavailable_common)
1199 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1200 #ifdef CONFIG_ALTIVEC
1203 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1204 BEGIN_FTR_SECTION_NESTED(69)
1205 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1206 * transaction), go do TM stuff
1208 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1210 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1213 b fast_exception_return
1214 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1215 2: /* User process was in a transaction */
1217 RECONCILE_IRQ_STATE(r10, r11)
1218 addi r3,r1,STACK_FRAME_OVERHEAD
1219 bl altivec_unavailable_tm
1223 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1226 RECONCILE_IRQ_STATE(r10, r11)
1227 addi r3,r1,STACK_FRAME_OVERHEAD
1228 bl altivec_unavailable_exception
1232 EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
1233 EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
1234 TRAMP_KVM(PACA_EXGEN, 0xf40)
1235 EXC_COMMON_BEGIN(vsx_unavailable_common)
1236 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1240 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1241 BEGIN_FTR_SECTION_NESTED(69)
1242 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1243 * transaction), go do TM stuff
1245 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1247 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1250 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1251 2: /* User process was in a transaction */
1253 RECONCILE_IRQ_STATE(r10, r11)
1254 addi r3,r1,STACK_FRAME_OVERHEAD
1255 bl vsx_unavailable_tm
1259 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1262 RECONCILE_IRQ_STATE(r10, r11)
1263 addi r3,r1,STACK_FRAME_OVERHEAD
1264 bl vsx_unavailable_exception
1268 EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
1269 EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
1270 TRAMP_KVM(PACA_EXGEN, 0xf60)
1271 EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1274 EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
1275 EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
1276 TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1277 EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1280 EXC_REAL_NONE(0xfa0, 0x20)
1281 EXC_VIRT_NONE(0x4fa0, 0x20)
1282 EXC_REAL_NONE(0xfc0, 0x20)
1283 EXC_VIRT_NONE(0x4fc0, 0x20)
1284 EXC_REAL_NONE(0xfe0, 0x20)
1285 EXC_VIRT_NONE(0x4fe0, 0x20)
1287 EXC_REAL_NONE(0x1000, 0x100)
1288 EXC_VIRT_NONE(0x5000, 0x100)
1289 EXC_REAL_NONE(0x1100, 0x100)
1290 EXC_VIRT_NONE(0x5100, 0x100)
1292 #ifdef CONFIG_CBE_RAS
1293 EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
1294 EXC_VIRT_NONE(0x5200, 0x100)
1295 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
1296 EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
1297 #else /* CONFIG_CBE_RAS */
1298 EXC_REAL_NONE(0x1200, 0x100)
1299 EXC_VIRT_NONE(0x5200, 0x100)
1303 EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
1304 EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
1305 TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
1306 EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1308 EXC_REAL_NONE(0x1400, 0x100)
1309 EXC_VIRT_NONE(0x5400, 0x100)
1311 EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
1312 mtspr SPRN_SPRG_HSCRATCH0,r13
1313 EXCEPTION_PROLOG_0(PACA_EXGEN)
1314 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
1316 #ifdef CONFIG_PPC_DENORMALISATION
1317 mfspr r10,SPRN_HSRR1
1318 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
1323 EXCEPTION_PROLOG_2(denorm_common, EXC_HV)
1324 EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
1326 #ifdef CONFIG_PPC_DENORMALISATION
1327 EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
1328 b exc_real_0x1500_denorm_exception_hv
1329 EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
1331 EXC_VIRT_NONE(0x5500, 0x100)
1334 TRAMP_KVM_HV(PACA_EXGEN, 0x1500)
1336 #ifdef CONFIG_PPC_DENORMALISATION
1337 TRAMP_REAL_BEGIN(denorm_assist)
1340 * To denormalise we need to move a copy of the register to itself.
1341 * For POWER6 do that here for all FP regs.
1344 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1345 xori r10,r10,(MSR_FE0|MSR_FE1)
1349 #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
1350 #define FMR4(n) FMR2(n) ; FMR2(n+2)
1351 #define FMR8(n) FMR4(n) ; FMR4(n+4)
1352 #define FMR16(n) FMR8(n) ; FMR8(n+8)
1353 #define FMR32(n) FMR16(n) ; FMR16(n+16)
1358 * To denormalise we need to move a copy of the register to itself.
1359 * For POWER7 do that here for the first 32 VSX registers only.
1362 oris r10,r10,MSR_VSX@h
1366 #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
1367 #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
1368 #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
1369 #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
1370 #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
1373 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
1377 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1379 * To denormalise we need to move a copy of the register to itself.
1380 * For POWER8 we need to do that for all 64 VSX registers
1384 mfspr r11,SPRN_HSRR0
1386 mtspr SPRN_HSRR0,r11
1388 ld r9,PACA_EXGEN+EX_R9(r13)
1389 RESTORE_PPR_PACA(PACA_EXGEN, r10)
1391 ld r10,PACA_EXGEN+EX_CFAR(r13)
1393 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1394 ld r10,PACA_EXGEN+EX_R10(r13)
1395 ld r11,PACA_EXGEN+EX_R11(r13)
1396 ld r12,PACA_EXGEN+EX_R12(r13)
1397 ld r13,PACA_EXGEN+EX_R13(r13)
1402 EXC_COMMON(denorm_common, 0x1500, unknown_exception)
1405 #ifdef CONFIG_CBE_RAS
1406 EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
1407 EXC_VIRT_NONE(0x5600, 0x100)
1408 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
1409 EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
1410 #else /* CONFIG_CBE_RAS */
1411 EXC_REAL_NONE(0x1600, 0x100)
1412 EXC_VIRT_NONE(0x5600, 0x100)
1416 EXC_REAL(altivec_assist, 0x1700, 0x100)
1417 EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
1418 TRAMP_KVM(PACA_EXGEN, 0x1700)
1419 #ifdef CONFIG_ALTIVEC
1420 EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
1422 EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
1426 #ifdef CONFIG_CBE_RAS
1427 EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
1428 EXC_VIRT_NONE(0x5800, 0x100)
1429 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
1430 EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
1431 #else /* CONFIG_CBE_RAS */
1432 EXC_REAL_NONE(0x1800, 0x100)
1433 EXC_VIRT_NONE(0x5800, 0x100)
1436 #ifdef CONFIG_PPC_WATCHDOG
1438 #define MASKED_DEC_HANDLER_LABEL 3f
1440 #define MASKED_DEC_HANDLER(_H) \
1442 std r12,PACA_EXGEN+EX_R12(r13); \
1443 GET_SCRATCH0(r10); \
1444 std r10,PACA_EXGEN+EX_R13(r13); \
1445 EXCEPTION_PROLOG_2(soft_nmi_common, _H)
1448 * Branch to soft_nmi_interrupt using the emergency stack. The emergency
1449 * stack is one that is usable by maskable interrupts so long as MSR_EE
1450 * remains off. It is used for recovery when something has corrupted the
1451 * normal kernel stack, for example. The "soft NMI" must not use the process
1452 * stack because we want irq disabled sections to avoid touching the stack
1453 * at all (other than PMU interrupts), so use the emergency stack for this,
1454 * and run it entirely with interrupts hard disabled.
1456 EXC_COMMON_BEGIN(soft_nmi_common)
1458 ld r1,PACAEMERGSP(r13)
1459 subi r1,r1,INT_FRAME_SIZE
1460 EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
1461 system_reset, soft_nmi_interrupt,
1462 ADD_NVGPRS;ADD_RECONCILE)
1465 #else /* CONFIG_PPC_WATCHDOG */
1466 #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
1467 #define MASKED_DEC_HANDLER(_H)
1468 #endif /* CONFIG_PPC_WATCHDOG */
1471 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
1472 * - If it was a decrementer interrupt, we bump the dec to max and and return.
1473 * - If it was a doorbell we return immediately since doorbells are edge
1474 * triggered and won't automatically refire.
1475 * - If it was a HMI we return immediately since we handled it in realmode
1476 * and it won't refire.
1477 * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
1478 * This is called with r10 containing the value to OR to the paca field.
1480 #define MASKED_INTERRUPT(_H) \
1481 masked_##_H##interrupt: \
1482 std r11,PACA_EXGEN+EX_R11(r13); \
1483 lbz r11,PACAIRQHAPPENED(r13); \
1485 stb r11,PACAIRQHAPPENED(r13); \
1486 cmpwi r10,PACA_IRQ_DEC; \
1489 ori r10,r10,0xffff; \
1490 mtspr SPRN_DEC,r10; \
1491 b MASKED_DEC_HANDLER_LABEL; \
1492 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK; \
1494 mfspr r10,SPRN_##_H##SRR1; \
1495 xori r10,r10,MSR_EE; /* clear MSR_EE */ \
1496 mtspr SPRN_##_H##SRR1,r10; \
1497 ori r11,r11,PACA_IRQ_HARD_DIS; \
1498 stb r11,PACAIRQHAPPENED(r13); \
1501 std r1,PACAR1(r13); \
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(stf_barrier_fallback)
1511 std r9,PACA_EXRFI+EX_R9(r13)
1512 std r10,PACA_EXRFI+EX_R10(r13)
1514 ld r9,PACA_EXRFI+EX_R9(r13)
1515 ld r10,PACA_EXRFI+EX_R10(r13)
1523 TRAMP_REAL_BEGIN(rfi_flush_fallback)
1526 std r1,PACA_EXRFI+EX_R12(r13)
1527 ld r1,PACAKSAVE(r13)
1528 std r9,PACA_EXRFI+EX_R9(r13)
1529 std r10,PACA_EXRFI+EX_R10(r13)
1530 std r11,PACA_EXRFI+EX_R11(r13)
1532 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
1533 ld r11,PACA_L1D_FLUSH_SIZE(r13)
1534 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
1536 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1538 /* order ld/st prior to dcbt stop all streams with flushing */
1542 * The load adresses are at staggered offsets within cachelines,
1543 * which suits some pipelines better (on others it should not
1547 ld r11,(0x80 + 8)*0(r10)
1548 ld r11,(0x80 + 8)*1(r10)
1549 ld r11,(0x80 + 8)*2(r10)
1550 ld r11,(0x80 + 8)*3(r10)
1551 ld r11,(0x80 + 8)*4(r10)
1552 ld r11,(0x80 + 8)*5(r10)
1553 ld r11,(0x80 + 8)*6(r10)
1554 ld r11,(0x80 + 8)*7(r10)
1559 ld r9,PACA_EXRFI+EX_R9(r13)
1560 ld r10,PACA_EXRFI+EX_R10(r13)
1561 ld r11,PACA_EXRFI+EX_R11(r13)
1562 ld r1,PACA_EXRFI+EX_R12(r13)
1566 TRAMP_REAL_BEGIN(hrfi_flush_fallback)
1569 std r1,PACA_EXRFI+EX_R12(r13)
1570 ld r1,PACAKSAVE(r13)
1571 std r9,PACA_EXRFI+EX_R9(r13)
1572 std r10,PACA_EXRFI+EX_R10(r13)
1573 std r11,PACA_EXRFI+EX_R11(r13)
1575 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
1576 ld r11,PACA_L1D_FLUSH_SIZE(r13)
1577 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
1579 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1581 /* order ld/st prior to dcbt stop all streams with flushing */
1585 * The load adresses are at staggered offsets within cachelines,
1586 * which suits some pipelines better (on others it should not
1590 ld r11,(0x80 + 8)*0(r10)
1591 ld r11,(0x80 + 8)*1(r10)
1592 ld r11,(0x80 + 8)*2(r10)
1593 ld r11,(0x80 + 8)*3(r10)
1594 ld r11,(0x80 + 8)*4(r10)
1595 ld r11,(0x80 + 8)*5(r10)
1596 ld r11,(0x80 + 8)*6(r10)
1597 ld r11,(0x80 + 8)*7(r10)
1602 ld r9,PACA_EXRFI+EX_R9(r13)
1603 ld r10,PACA_EXRFI+EX_R10(r13)
1604 ld r11,PACA_EXRFI+EX_R11(r13)
1605 ld r1,PACA_EXRFI+EX_R12(r13)
1610 * Real mode exceptions actually use this too, but alternate
1611 * instruction code patches (which end up in the common .text area)
1612 * cannot reach these if they are put there.
1614 USE_FIXED_SECTION(virt_trampolines)
1618 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1619 TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
1621 * Here all GPRs are unchanged from when the interrupt happened
1622 * except for r13, which is saved in SPRG_SCRATCH0.
1624 mfspr r13, SPRN_SRR0
1626 mtspr SPRN_SRR0, r13
1631 TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
1633 * Here all GPRs are unchanged from when the interrupt happened
1634 * except for r13, which is saved in SPRG_SCRATCH0.
1636 mfspr r13, SPRN_HSRR0
1638 mtspr SPRN_HSRR0, r13
1645 * Ensure that any handlers that get invoked from the exception prologs
1646 * above are below the first 64KB (0x10000) of the kernel image because
1647 * the prologs assemble the addresses of these handlers using the
1648 * LOAD_HANDLER macro, which uses an ori instruction.
1651 /*** Common interrupt handlers ***/
1655 * Relocation-on interrupts: A subset of the interrupts can be delivered
1656 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
1657 * it. Addresses are the same as the original interrupt addresses, but
1658 * offset by 0xc000000000004000.
1659 * It's impossible to receive interrupts below 0x300 via this mechanism.
1660 * KVM: None of these traps are from the guest ; anything that escalated
1661 * to HV=1 from HV=0 is delivered via real mode handlers.
1665 * This uses the standard macro, since the original 0x300 vector
1666 * only has extra guff for STAB-based processors -- which never
1670 EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
1671 b __ppc64_runlatch_on
1673 USE_FIXED_SECTION(virt_trampolines)
1675 * The __end_interrupts marker must be past the out-of-line (OOL)
1676 * handlers, so that they are copied to real address 0x100 when running
1677 * a relocatable kernel. This ensures they can be reached from the short
1678 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
1679 * directly, without using LOAD_HANDLER().
1682 .globl __end_interrupts
1684 DEFINE_FIXED_SYMBOL(__end_interrupts)
1686 #ifdef CONFIG_PPC_970_NAP
1687 EXC_COMMON_BEGIN(power4_fixup_nap)
1689 std r9,TI_LOCAL_FLAGS(r11)
1690 ld r10,_LINK(r1) /* make idle task do the */
1691 std r10,_NIP(r1) /* equivalent of a blr */
1695 CLOSE_FIXED_SECTION(real_vectors);
1696 CLOSE_FIXED_SECTION(real_trampolines);
1697 CLOSE_FIXED_SECTION(virt_vectors);
1698 CLOSE_FIXED_SECTION(virt_trampolines);
1705 .balign IFETCH_ALIGN_BYTES
1707 #ifdef CONFIG_PPC_BOOK3S_64
1708 lis r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h
1709 ori r0,r0,DSISR_BAD_FAULT_64S@l
1710 and. r0,r4,r0 /* weird error? */
1711 bne- handle_page_fault /* if not, try to insert a HPTE */
1712 ld r11, PACA_THREAD_INFO(r13)
1713 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1714 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1715 bne 77f /* then don't call hash_page now */
1718 * r3 contains the faulting address
1720 * r5 contains the trap number
1723 * at return r3 = 0 for success, 1 for page fault, negative for error
1727 bl __hash_page /* build HPTE if possible */
1728 cmpdi r3,0 /* see if __hash_page succeeded */
1731 beq fast_exc_return_irq /* Return from exception on success */
1736 /* Reload DSISR into r4 for the DABR check below */
1738 #endif /* CONFIG_PPC_BOOK3S_64 */
1740 /* Here we have a page fault that hash_page can't handle. */
1742 11: andis. r0,r4,DSISR_DABRMATCH@h
1743 bne- handle_dabr_fault
1746 addi r3,r1,STACK_FRAME_OVERHEAD
1749 beq+ ret_from_except_lite
1752 addi r3,r1,STACK_FRAME_OVERHEAD
1757 /* We have a data breakpoint exception - handle it */
1762 addi r3,r1,STACK_FRAME_OVERHEAD
1765 * do_break() may have changed the NV GPRS while handling a breakpoint.
1766 * If so, we need to restore them with their updated values. Don't use
1767 * ret_from_except_lite here.
1772 #ifdef CONFIG_PPC_BOOK3S_64
1773 /* We have a page fault that hash_page could handle but HV refused
1778 addi r3,r1,STACK_FRAME_OVERHEAD
1785 * We come here as a result of a DSI at a point where we don't want
1786 * to call hash_page, such as when we are accessing memory (possibly
1787 * user memory) inside a PMU interrupt that occurred while interrupts
1788 * were soft-disabled. We want to invoke the exception handler for
1789 * the access, or panic if there isn't a handler.
1793 addi r3,r1,STACK_FRAME_OVERHEAD
1799 * Here we have detected that the kernel stack pointer is bad.
1800 * R9 contains the saved CR, r13 points to the paca,
1801 * r10 contains the (bad) kernel stack pointer,
1802 * r11 and r12 contain the saved SRR0 and SRR1.
1803 * We switch to using an emergency stack, save the registers there,
1804 * and call kernel_bad_stack(), which panics.
1807 ld r1,PACAEMERGSP(r13)
1808 subi r1,r1,64+INT_FRAME_SIZE
1814 mfspr r12,SPRN_DSISR
1840 std r10,ORIG_GPR3(r1)
1841 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1844 lhz r12,PACA_TRAP_SAVE(r13)
1846 addi r11,r1,INT_FRAME_SIZE
1851 ld r11,exception_marker@toc(r2)
1853 std r11,STACK_FRAME_OVERHEAD-16(r1)
1854 1: addi r3,r1,STACK_FRAME_OVERHEAD
1857 _ASM_NOKPROBE_SYMBOL(bad_stack);
1860 * When doorbell is triggered from system reset wakeup, the message is
1861 * not cleared, so it would fire again when EE is enabled.
1863 * When coming from local_irq_enable, there may be the same problem if
1864 * we were hard disabled.
1866 * Execute msgclr to clear pending exceptions before handling it.
1868 h_doorbell_common_msgclr:
1869 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1873 doorbell_super_common_msgclr:
1874 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1876 b doorbell_super_common
1879 * Called from arch_local_irq_enable when an interrupt needs
1880 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
1881 * which kind of interrupt. MSR:EE is already off. We generate a
1882 * stackframe like if a real interrupt had happened.
1884 * Note: While MSR:EE is off, we need to make sure that _MSR
1885 * in the generated frame has EE set to 1 or the exception
1886 * handler will not properly re-enable them.
1888 * Note that we don't specify LR as the NIP (return address) for
1889 * the interrupt because that would unbalance the return branch
1892 _GLOBAL(__replay_interrupt)
1893 /* We are going to jump to the exception common code which
1894 * will retrieve various register values from the PACA which
1895 * we don't give a damn about, so we don't bother storing them.
1898 LOAD_REG_ADDR(r11, replay_interrupt_return)
1902 beq decrementer_common
1905 beq h_virt_irq_common
1907 beq hardware_interrupt_common
1908 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
1910 beq performance_monitor_common
1913 beq h_doorbell_common_msgclr
1915 beq hmi_exception_common
1918 beq doorbell_super_common_msgclr
1919 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1920 replay_interrupt_return:
1923 _ASM_NOKPROBE_SYMBOL(__replay_interrupt)