xref: /linux/arch/powerpc/kernel/exceptions-64s.S (revision e779fc93643c1181b0164745a537986a525850ca)
1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
20ebc4cdaSBenjamin Herrenschmidt/*
30ebc4cdaSBenjamin Herrenschmidt * This file contains the 64-bit "server" PowerPC variant
40ebc4cdaSBenjamin Herrenschmidt * of the low level exception handling including exception
50ebc4cdaSBenjamin Herrenschmidt * vectors, exception return, part of the slb and stab
60ebc4cdaSBenjamin Herrenschmidt * handling and other fixed offset specific things.
70ebc4cdaSBenjamin Herrenschmidt *
80ebc4cdaSBenjamin Herrenschmidt * This file is meant to be #included from head_64.S due to
925985edcSLucas De Marchi * position dependent assembly.
100ebc4cdaSBenjamin Herrenschmidt *
110ebc4cdaSBenjamin Herrenschmidt * Most of this originates from head_64.S and thus has the same
120ebc4cdaSBenjamin Herrenschmidt * copyright history.
130ebc4cdaSBenjamin Herrenschmidt *
140ebc4cdaSBenjamin Herrenschmidt */
150ebc4cdaSBenjamin Herrenschmidt
167230c564SBenjamin Herrenschmidt#include <asm/hw_irq.h>
178aa34ab8SBenjamin Herrenschmidt#include <asm/exception-64s.h>
1846f52210SStephen Rothwell#include <asm/ptrace.h>
197cba160aSShreyas B. Prabhu#include <asm/cpuidle.h>
20da2bc464SMichael Ellerman#include <asm/head-64.h>
212c86cd18SChristophe Leroy#include <asm/feature-fixups.h>
228aa34ab8SBenjamin Herrenschmidt
230ebc4cdaSBenjamin Herrenschmidt/*
2457f26649SNicholas Piggin * There are a few constraints to be concerned with.
2557f26649SNicholas Piggin * - Real mode exceptions code/data must be located at their physical location.
2657f26649SNicholas Piggin * - Virtual mode exceptions must be mapped at their 0xc000... location.
2757f26649SNicholas Piggin * - Fixed location code must not call directly beyond the __end_interrupts
2857f26649SNicholas Piggin *   area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
2957f26649SNicholas Piggin *   must be used.
3057f26649SNicholas Piggin * - LOAD_HANDLER targets must be within first 64K of physical 0 /
3157f26649SNicholas Piggin *   virtual 0xc00...
3257f26649SNicholas Piggin * - Conditional branch targets must be within +/-32K of caller.
3357f26649SNicholas Piggin *
3457f26649SNicholas Piggin * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
3557f26649SNicholas Piggin * therefore don't have to run in physically located code or rfid to
3657f26649SNicholas Piggin * virtual mode kernel code. However on relocatable kernels they do have
3757f26649SNicholas Piggin * to branch to KERNELBASE offset because the rest of the kernel (outside
3857f26649SNicholas Piggin * the exception vectors) may be located elsewhere.
3957f26649SNicholas Piggin *
4057f26649SNicholas Piggin * Virtual exceptions correspond with physical, except their entry points
4157f26649SNicholas Piggin * are offset by 0xc000000000000000 and also tend to get an added 0x4000
4257f26649SNicholas Piggin * offset applied. Virtual exceptions are enabled with the Alternate
4357f26649SNicholas Piggin * Interrupt Location (AIL) bit set in the LPCR. However this does not
4457f26649SNicholas Piggin * guarantee they will be delivered virtually. Some conditions (see the ISA)
4557f26649SNicholas Piggin * cause exceptions to be delivered in real mode.
4657f26649SNicholas Piggin *
4757f26649SNicholas Piggin * It's impossible to receive interrupts below 0x300 via AIL.
4857f26649SNicholas Piggin *
4957f26649SNicholas Piggin * KVM: None of the virtual exceptions are from the guest. Anything that
5057f26649SNicholas Piggin * escalated to HV=1 from HV=0 is delivered via real mode handlers.
5157f26649SNicholas Piggin *
5257f26649SNicholas Piggin *
530ebc4cdaSBenjamin Herrenschmidt * We layout physical memory as follows:
540ebc4cdaSBenjamin Herrenschmidt * 0x0000 - 0x00ff : Secondary processor spin code
5557f26649SNicholas Piggin * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
5657f26649SNicholas Piggin * 0x1900 - 0x3fff : Real mode trampolines
5757f26649SNicholas Piggin * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
5857f26649SNicholas Piggin * 0x5900 - 0x6fff : Relon mode trampolines
590ebc4cdaSBenjamin Herrenschmidt * 0x7000 - 0x7fff : FWNMI data area
6057f26649SNicholas Piggin * 0x8000 -   .... : Common interrupt handlers, remaining early
6157f26649SNicholas Piggin *                   setup code, rest of kernel.
62e0319829SNicholas Piggin *
63e0319829SNicholas Piggin * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
64e0319829SNicholas Piggin * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
65e0319829SNicholas Piggin * vectors there.
660ebc4cdaSBenjamin Herrenschmidt */
6757f26649SNicholas PigginOPEN_FIXED_SECTION(real_vectors,        0x0100, 0x1900)
6857f26649SNicholas PigginOPEN_FIXED_SECTION(real_trampolines,    0x1900, 0x4000)
6957f26649SNicholas PigginOPEN_FIXED_SECTION(virt_vectors,        0x4000, 0x5900)
7057f26649SNicholas PigginOPEN_FIXED_SECTION(virt_trampolines,    0x5900, 0x7000)
71ccd47702SNicholas Piggin
72ccd47702SNicholas Piggin#ifdef CONFIG_PPC_POWERNV
73ccd47702SNicholas Piggin	.globl real_trampolines_start
74ccd47702SNicholas Piggin	.globl real_trampolines_end
75ccd47702SNicholas Piggin	.globl virt_trampolines_start
76ccd47702SNicholas Piggin	.globl virt_trampolines_end
77ccd47702SNicholas Piggin#endif
78ccd47702SNicholas Piggin
7957f26649SNicholas Piggin#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
8057f26649SNicholas Piggin/*
8157f26649SNicholas Piggin * Data area reserved for FWNMI option.
8257f26649SNicholas Piggin * This address (0x7000) is fixed by the RPA.
8357f26649SNicholas Piggin * pseries and powernv need to keep the whole page from
8457f26649SNicholas Piggin * 0x7000 to 0x8000 free for use by the firmware
8557f26649SNicholas Piggin */
8657f26649SNicholas PigginZERO_FIXED_SECTION(fwnmi_page,          0x7000, 0x8000)
8757f26649SNicholas PigginOPEN_TEXT_SECTION(0x8000)
8857f26649SNicholas Piggin#else
8957f26649SNicholas PigginOPEN_TEXT_SECTION(0x7000)
9057f26649SNicholas Piggin#endif
9157f26649SNicholas Piggin
9257f26649SNicholas PigginUSE_FIXED_SECTION(real_vectors)
9357f26649SNicholas Piggin
940ebc4cdaSBenjamin Herrenschmidt/*
950ebc4cdaSBenjamin Herrenschmidt * This is the start of the interrupt handlers for pSeries
960ebc4cdaSBenjamin Herrenschmidt * This code runs with relocation off.
970ebc4cdaSBenjamin Herrenschmidt * Code from here to __end_interrupts gets copied down to real
980ebc4cdaSBenjamin Herrenschmidt * address 0x100 when we are running a relocatable kernel.
990ebc4cdaSBenjamin Herrenschmidt * Therefore any relative branches in this section must only
1000ebc4cdaSBenjamin Herrenschmidt * branch to labels in this section.
1010ebc4cdaSBenjamin Herrenschmidt */
1020ebc4cdaSBenjamin Herrenschmidt	.globl __start_interrupts
1030ebc4cdaSBenjamin Herrenschmidt__start_interrupts:
1040ebc4cdaSBenjamin Herrenschmidt
105e0319829SNicholas Piggin/* No virt vectors corresponding with 0x0..0x100 */
1061a6822d1SNicholas PigginEXC_VIRT_NONE(0x4000, 0x100)
107e0319829SNicholas Piggin
108fb479e44SNicholas Piggin
109fb479e44SNicholas Piggin#ifdef CONFIG_PPC_P7_NAP
110fb479e44SNicholas Piggin	/*
111fb479e44SNicholas Piggin	 * If running native on arch 2.06 or later, check if we are waking up
112ba6d334aSBenjamin Herrenschmidt	 * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
113ba6d334aSBenjamin Herrenschmidt	 * bits 46:47. A non-0 value indicates that we are coming from a power
114ba6d334aSBenjamin Herrenschmidt	 * saving state. The idle wakeup handler initially runs in real mode,
115ba6d334aSBenjamin Herrenschmidt	 * but we branch to the 0xc000... address so we can turn on relocation
116ba6d334aSBenjamin Herrenschmidt	 * with mtmsr.
117fb479e44SNicholas Piggin	 */
118fb479e44SNicholas Piggin#define IDLETEST(n)							\
119fb479e44SNicholas Piggin	BEGIN_FTR_SECTION ;						\
120fb479e44SNicholas Piggin	mfspr	r10,SPRN_SRR1 ;						\
121fb479e44SNicholas Piggin	rlwinm.	r10,r10,47-31,30,31 ;					\
122fb479e44SNicholas Piggin	beq-	1f ;							\
123fb479e44SNicholas Piggin	cmpwi	cr3,r10,2 ;						\
124b51351e2SNicholas Piggin	BRANCH_TO_C000(r10, system_reset_idle_common) ;			\
125fb479e44SNicholas Piggin1:									\
1266de6638bSNicholas Piggin	KVMTEST_PR(n) ;							\
127fb479e44SNicholas Piggin	END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
128fb479e44SNicholas Piggin#else
129fb479e44SNicholas Piggin#define IDLETEST NOTEST
130fb479e44SNicholas Piggin#endif
131fb479e44SNicholas Piggin
1321a6822d1SNicholas PigginEXC_REAL_BEGIN(system_reset, 0x100, 0x100)
133948cf67cSBenjamin Herrenschmidt	SET_SCRATCH0(r13)
134c4f3b52cSNicholas Piggin	/*
135c4f3b52cSNicholas Piggin	 * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
136c4f3b52cSNicholas Piggin	 * being used, so a nested NMI exception would corrupt it.
137c4f3b52cSNicholas Piggin	 */
13894f3cc8eSMichael Ellerman	EXCEPTION_PROLOG_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
139fb479e44SNicholas Piggin			      IDLETEST, 0x100)
140371fefd6SPaul Mackerras
1411a6822d1SNicholas PigginEXC_REAL_END(system_reset, 0x100, 0x100)
1421a6822d1SNicholas PigginEXC_VIRT_NONE(0x4100, 0x100)
1436de6638bSNicholas PigginTRAMP_KVM(PACA_EXNMI, 0x100)
144fb479e44SNicholas Piggin
145fb479e44SNicholas Piggin#ifdef CONFIG_PPC_P7_NAP
146fb479e44SNicholas PigginEXC_COMMON_BEGIN(system_reset_idle_common)
1479d292501SNicholas Piggin	mfspr	r12,SPRN_SRR1
148bf0153c1SNicholas Piggin	b	pnv_powersave_wakeup
149371fefd6SPaul Mackerras#endif
150371fefd6SPaul Mackerras
15115b4dd79SNicholas Piggin/*
15215b4dd79SNicholas Piggin * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does
15315b4dd79SNicholas Piggin * the right thing. We do not want to reconcile because that goes
15415b4dd79SNicholas Piggin * through irq tracing which we don't want in NMI.
15515b4dd79SNicholas Piggin *
15615b4dd79SNicholas Piggin * Save PACAIRQHAPPENED because some code will do a hard disable
15715b4dd79SNicholas Piggin * (e.g., xmon). So we want to restore this back to where it was
15815b4dd79SNicholas Piggin * when we return. DAR is unused in the stack, so save it there.
15915b4dd79SNicholas Piggin */
16015b4dd79SNicholas Piggin#define ADD_RECONCILE_NMI						\
16115b4dd79SNicholas Piggin	li	r10,IRQS_ALL_DISABLED;					\
16215b4dd79SNicholas Piggin	stb	r10,PACAIRQSOFTMASK(r13);				\
16315b4dd79SNicholas Piggin	lbz	r10,PACAIRQHAPPENED(r13);				\
16415b4dd79SNicholas Piggin	std	r10,_DAR(r1)
16515b4dd79SNicholas Piggin
166a3d96f70SNicholas PigginEXC_COMMON_BEGIN(system_reset_common)
167c4f3b52cSNicholas Piggin	/*
168c4f3b52cSNicholas Piggin	 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
169c4f3b52cSNicholas Piggin	 * to recover, but nested NMI will notice in_nmi and not recover
170c4f3b52cSNicholas Piggin	 * because of the use of the NMI stack. in_nmi reentrancy is tested in
171c4f3b52cSNicholas Piggin	 * system_reset_exception.
172c4f3b52cSNicholas Piggin	 */
173c4f3b52cSNicholas Piggin	lhz	r10,PACA_IN_NMI(r13)
174c4f3b52cSNicholas Piggin	addi	r10,r10,1
175c4f3b52cSNicholas Piggin	sth	r10,PACA_IN_NMI(r13)
176c4f3b52cSNicholas Piggin	li	r10,MSR_RI
177c4f3b52cSNicholas Piggin	mtmsrd 	r10,1
178aca79d2bSVaidyanathan Srinivasan
179b1ee8a3dSNicholas Piggin	mr	r10,r1
180b1ee8a3dSNicholas Piggin	ld	r1,PACA_NMI_EMERG_SP(r13)
181b1ee8a3dSNicholas Piggin	subi	r1,r1,INT_FRAME_SIZE
182b1ee8a3dSNicholas Piggin	EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
183b1ee8a3dSNicholas Piggin			system_reset, system_reset_exception,
18415b4dd79SNicholas Piggin			ADD_NVGPRS;ADD_RECONCILE_NMI)
18515b4dd79SNicholas Piggin
18615b4dd79SNicholas Piggin	/* This (and MCE) can be simplified with mtmsrd L=1 */
18715b4dd79SNicholas Piggin	/* Clear MSR_RI before setting SRR0 and SRR1. */
18815b4dd79SNicholas Piggin	li	r0,MSR_RI
18915b4dd79SNicholas Piggin	mfmsr	r9
19015b4dd79SNicholas Piggin	andc	r9,r9,r0
19115b4dd79SNicholas Piggin	mtmsrd	r9,1
192c4f3b52cSNicholas Piggin
193c4f3b52cSNicholas Piggin	/*
19415b4dd79SNicholas Piggin	 * MSR_RI is clear, now we can decrement paca->in_nmi.
195c4f3b52cSNicholas Piggin	 */
196c4f3b52cSNicholas Piggin	lhz	r10,PACA_IN_NMI(r13)
197c4f3b52cSNicholas Piggin	subi	r10,r10,1
198c4f3b52cSNicholas Piggin	sth	r10,PACA_IN_NMI(r13)
199c4f3b52cSNicholas Piggin
20015b4dd79SNicholas Piggin	/*
20115b4dd79SNicholas Piggin	 * Restore soft mask settings.
20215b4dd79SNicholas Piggin	 */
20315b4dd79SNicholas Piggin	ld	r10,_DAR(r1)
20415b4dd79SNicholas Piggin	stb	r10,PACAIRQHAPPENED(r13)
20515b4dd79SNicholas Piggin	ld	r10,SOFTE(r1)
20615b4dd79SNicholas Piggin	stb	r10,PACAIRQSOFTMASK(r13)
20715b4dd79SNicholas Piggin
20815b4dd79SNicholas Piggin	/*
20915b4dd79SNicholas Piggin	 * Keep below code in synch with MACHINE_CHECK_HANDLER_WINDUP.
21015b4dd79SNicholas Piggin	 * Should share common bits...
21115b4dd79SNicholas Piggin	 */
21215b4dd79SNicholas Piggin
21315b4dd79SNicholas Piggin	/* Move original SRR0 and SRR1 into the respective regs */
21415b4dd79SNicholas Piggin	ld	r9,_MSR(r1)
21515b4dd79SNicholas Piggin	mtspr	SPRN_SRR1,r9
21615b4dd79SNicholas Piggin	ld	r3,_NIP(r1)
21715b4dd79SNicholas Piggin	mtspr	SPRN_SRR0,r3
21815b4dd79SNicholas Piggin	ld	r9,_CTR(r1)
21915b4dd79SNicholas Piggin	mtctr	r9
22015b4dd79SNicholas Piggin	ld	r9,_XER(r1)
22115b4dd79SNicholas Piggin	mtxer	r9
22215b4dd79SNicholas Piggin	ld	r9,_LINK(r1)
22315b4dd79SNicholas Piggin	mtlr	r9
22415b4dd79SNicholas Piggin	REST_GPR(0, r1)
22515b4dd79SNicholas Piggin	REST_8GPRS(2, r1)
22615b4dd79SNicholas Piggin	REST_GPR(10, r1)
22715b4dd79SNicholas Piggin	ld	r11,_CCR(r1)
22815b4dd79SNicholas Piggin	mtcr	r11
22915b4dd79SNicholas Piggin	REST_GPR(11, r1)
23015b4dd79SNicholas Piggin	REST_2GPRS(12, r1)
23115b4dd79SNicholas Piggin	/* restore original r1. */
23215b4dd79SNicholas Piggin	ld	r1,GPR1(r1)
23315b4dd79SNicholas Piggin	RFI_TO_USER_OR_KERNEL
234582baf44SNicholas Piggin
235582baf44SNicholas Piggin#ifdef CONFIG_PPC_PSERIES
236582baf44SNicholas Piggin/*
237582baf44SNicholas Piggin * Vectors for the FWNMI option.  Share common code.
238582baf44SNicholas Piggin */
239582baf44SNicholas PigginTRAMP_REAL_BEGIN(system_reset_fwnmi)
240582baf44SNicholas Piggin	SET_SCRATCH0(r13)		/* save r13 */
241c4f3b52cSNicholas Piggin	/* See comment at system_reset exception */
24294f3cc8eSMichael Ellerman	EXCEPTION_PROLOG_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
24394f3cc8eSMichael Ellerman			      NOTEST, 0x100)
244582baf44SNicholas Piggin#endif /* CONFIG_PPC_PSERIES */
245582baf44SNicholas Piggin
2460ebc4cdaSBenjamin Herrenschmidt
2471a6822d1SNicholas PigginEXC_REAL_BEGIN(machine_check, 0x200, 0x100)
248b01c8b54SPaul Mackerras	/* This is moved out of line as it can be patched by FW, but
249b01c8b54SPaul Mackerras	 * some code path might still want to branch into the original
250b01c8b54SPaul Mackerras	 * vector
251b01c8b54SPaul Mackerras	 */
2521707dd16SPaul Mackerras	SET_SCRATCH0(r13)		/* save r13 */
2531707dd16SPaul Mackerras	EXCEPTION_PROLOG_0(PACA_EXMC)
2541e9b4507SMahesh SalgaonkarBEGIN_FTR_SECTION
255db7d31acSMahesh Salgaonkar	b	machine_check_common_early
2561e9b4507SMahesh SalgaonkarFTR_SECTION_ELSE
2571707dd16SPaul Mackerras	b	machine_check_pSeries_0
2581e9b4507SMahesh SalgaonkarALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
2591a6822d1SNicholas PigginEXC_REAL_END(machine_check, 0x200, 0x100)
2601a6822d1SNicholas PigginEXC_VIRT_NONE(0x4200, 0x100)
261db7d31acSMahesh SalgaonkarTRAMP_REAL_BEGIN(machine_check_common_early)
262afcf0095SNicholas Piggin	EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
263afcf0095SNicholas Piggin	/*
264afcf0095SNicholas Piggin	 * Register contents:
265afcf0095SNicholas Piggin	 * R13		= PACA
266afcf0095SNicholas Piggin	 * R9		= CR
267afcf0095SNicholas Piggin	 * Original R9 to R13 is saved on PACA_EXMC
268afcf0095SNicholas Piggin	 *
269afcf0095SNicholas Piggin	 * Switch to mc_emergency stack and handle re-entrancy (we limit
270afcf0095SNicholas Piggin	 * the nested MCE upto level 4 to avoid stack overflow).
271afcf0095SNicholas Piggin	 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
272afcf0095SNicholas Piggin	 *
273afcf0095SNicholas Piggin	 * We use paca->in_mce to check whether this is the first entry or
274afcf0095SNicholas Piggin	 * nested machine check. We increment paca->in_mce to track nested
275afcf0095SNicholas Piggin	 * machine checks.
276afcf0095SNicholas Piggin	 *
277afcf0095SNicholas Piggin	 * If this is the first entry then set stack pointer to
278afcf0095SNicholas Piggin	 * paca->mc_emergency_sp, otherwise r1 is already pointing to
279afcf0095SNicholas Piggin	 * stack frame on mc_emergency stack.
280afcf0095SNicholas Piggin	 *
281afcf0095SNicholas Piggin	 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
282afcf0095SNicholas Piggin	 * checkstop if we get another machine check exception before we do
283afcf0095SNicholas Piggin	 * rfid with MSR_ME=1.
2841945bc45SNicholas Piggin	 *
2851945bc45SNicholas Piggin	 * This interrupt can wake directly from idle. If that is the case,
2861945bc45SNicholas Piggin	 * the machine check is handled then the idle wakeup code is called
2872bf1071aSNicholas Piggin	 * to restore state.
288afcf0095SNicholas Piggin	 */
289afcf0095SNicholas Piggin	mr	r11,r1			/* Save r1 */
290afcf0095SNicholas Piggin	lhz	r10,PACA_IN_MCE(r13)
291afcf0095SNicholas Piggin	cmpwi	r10,0			/* Are we in nested machine check */
292afcf0095SNicholas Piggin	bne	0f			/* Yes, we are. */
293afcf0095SNicholas Piggin	/* First machine check entry */
294afcf0095SNicholas Piggin	ld	r1,PACAMCEMERGSP(r13)	/* Use MC emergency stack */
295afcf0095SNicholas Piggin0:	subi	r1,r1,INT_FRAME_SIZE	/* alloc stack frame */
296afcf0095SNicholas Piggin	addi	r10,r10,1		/* increment paca->in_mce */
297afcf0095SNicholas Piggin	sth	r10,PACA_IN_MCE(r13)
298afcf0095SNicholas Piggin	/* Limit nested MCE to level 4 to avoid stack overflow */
299ba41e1e1SBalbir Singh	cmpwi	r10,MAX_MCE_DEPTH
300afcf0095SNicholas Piggin	bgt	2f			/* Check if we hit limit of 4 */
301afcf0095SNicholas Piggin	std	r11,GPR1(r1)		/* Save r1 on the stack. */
302afcf0095SNicholas Piggin	std	r11,0(r1)		/* make stack chain pointer */
303afcf0095SNicholas Piggin	mfspr	r11,SPRN_SRR0		/* Save SRR0 */
304afcf0095SNicholas Piggin	std	r11,_NIP(r1)
305afcf0095SNicholas Piggin	mfspr	r11,SPRN_SRR1		/* Save SRR1 */
306afcf0095SNicholas Piggin	std	r11,_MSR(r1)
307afcf0095SNicholas Piggin	mfspr	r11,SPRN_DAR		/* Save DAR */
308afcf0095SNicholas Piggin	std	r11,_DAR(r1)
309afcf0095SNicholas Piggin	mfspr	r11,SPRN_DSISR		/* Save DSISR */
310afcf0095SNicholas Piggin	std	r11,_DSISR(r1)
311afcf0095SNicholas Piggin	std	r9,_CCR(r1)		/* Save CR in stackframe */
312afcf0095SNicholas Piggin	/* Save r9 through r13 from EXMC save area to stack frame. */
313afcf0095SNicholas Piggin	EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
314afcf0095SNicholas Piggin	mfmsr	r11			/* get MSR value */
315db7d31acSMahesh SalgaonkarBEGIN_FTR_SECTION
316afcf0095SNicholas Piggin	ori	r11,r11,MSR_ME		/* turn on ME bit */
317db7d31acSMahesh SalgaonkarEND_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
318afcf0095SNicholas Piggin	ori	r11,r11,MSR_RI		/* turn on RI bit */
319afcf0095SNicholas Piggin	LOAD_HANDLER(r12, machine_check_handle_early)
320afcf0095SNicholas Piggin1:	mtspr	SPRN_SRR0,r12
321afcf0095SNicholas Piggin	mtspr	SPRN_SRR1,r11
322222f20f1SNicholas Piggin	RFI_TO_KERNEL
323afcf0095SNicholas Piggin	b	.	/* prevent speculative execution */
324afcf0095SNicholas Piggin2:
325afcf0095SNicholas Piggin	/* Stack overflow. Stay on emergency stack and panic.
326afcf0095SNicholas Piggin	 * Keep the ME bit off while panic-ing, so that if we hit
327afcf0095SNicholas Piggin	 * another machine check we checkstop.
328afcf0095SNicholas Piggin	 */
329afcf0095SNicholas Piggin	addi	r1,r1,INT_FRAME_SIZE	/* go back to previous stack frame */
330afcf0095SNicholas Piggin	ld	r11,PACAKMSR(r13)
331afcf0095SNicholas Piggin	LOAD_HANDLER(r12, unrecover_mce)
332afcf0095SNicholas Piggin	li	r10,MSR_ME
333afcf0095SNicholas Piggin	andc	r11,r11,r10		/* Turn off MSR_ME */
334afcf0095SNicholas Piggin	b	1b
335afcf0095SNicholas Piggin	b	.	/* prevent speculative execution */
336afcf0095SNicholas Piggin
337afcf0095SNicholas PigginTRAMP_REAL_BEGIN(machine_check_pSeries)
338afcf0095SNicholas Piggin	.globl machine_check_fwnmi
339afcf0095SNicholas Pigginmachine_check_fwnmi:
340afcf0095SNicholas Piggin	SET_SCRATCH0(r13)		/* save r13 */
341afcf0095SNicholas Piggin	EXCEPTION_PROLOG_0(PACA_EXMC)
342a43c1590SMahesh SalgaonkarBEGIN_FTR_SECTION
343db7d31acSMahesh Salgaonkar	b	machine_check_common_early
344a43c1590SMahesh SalgaonkarEND_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
345afcf0095SNicholas Pigginmachine_check_pSeries_0:
346afcf0095SNicholas Piggin	EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
347afcf0095SNicholas Piggin	/*
34883a980f7SNicholas Piggin	 * MSR_RI is not enabled, because PACA_EXMC is being used, so a
34983a980f7SNicholas Piggin	 * nested machine check corrupts it. machine_check_common enables
35083a980f7SNicholas Piggin	 * MSR_RI.
351afcf0095SNicholas Piggin	 */
35294f3cc8eSMichael Ellerman	EXCEPTION_PROLOG_2_NORI(machine_check_common, EXC_STD)
353afcf0095SNicholas Piggin
354afcf0095SNicholas PigginTRAMP_KVM_SKIP(PACA_EXMC, 0x200)
355afcf0095SNicholas Piggin
356afcf0095SNicholas PigginEXC_COMMON_BEGIN(machine_check_common)
357afcf0095SNicholas Piggin	/*
358afcf0095SNicholas Piggin	 * Machine check is different because we use a different
359afcf0095SNicholas Piggin	 * save area: PACA_EXMC instead of PACA_EXGEN.
360afcf0095SNicholas Piggin	 */
361afcf0095SNicholas Piggin	mfspr	r10,SPRN_DAR
362afcf0095SNicholas Piggin	std	r10,PACA_EXMC+EX_DAR(r13)
363afcf0095SNicholas Piggin	mfspr	r10,SPRN_DSISR
364afcf0095SNicholas Piggin	stw	r10,PACA_EXMC+EX_DSISR(r13)
365afcf0095SNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
366afcf0095SNicholas Piggin	FINISH_NAP
367afcf0095SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
368afcf0095SNicholas Piggin	ld	r3,PACA_EXMC+EX_DAR(r13)
369afcf0095SNicholas Piggin	lwz	r4,PACA_EXMC+EX_DSISR(r13)
370afcf0095SNicholas Piggin	/* Enable MSR_RI when finished with PACA_EXMC */
371afcf0095SNicholas Piggin	li	r10,MSR_RI
372afcf0095SNicholas Piggin	mtmsrd 	r10,1
373afcf0095SNicholas Piggin	std	r3,_DAR(r1)
374afcf0095SNicholas Piggin	std	r4,_DSISR(r1)
375afcf0095SNicholas Piggin	bl	save_nvgprs
376afcf0095SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
377afcf0095SNicholas Piggin	bl	machine_check_exception
378afcf0095SNicholas Piggin	b	ret_from_except
379afcf0095SNicholas Piggin
380afcf0095SNicholas Piggin#define MACHINE_CHECK_HANDLER_WINDUP			\
381afcf0095SNicholas Piggin	/* Clear MSR_RI before setting SRR0 and SRR1. */\
382afcf0095SNicholas Piggin	li	r0,MSR_RI;				\
383afcf0095SNicholas Piggin	mfmsr	r9;		/* get MSR value */	\
384afcf0095SNicholas Piggin	andc	r9,r9,r0;				\
385afcf0095SNicholas Piggin	mtmsrd	r9,1;		/* Clear MSR_RI */	\
386afcf0095SNicholas Piggin	/* Move original SRR0 and SRR1 into the respective regs */	\
387afcf0095SNicholas Piggin	ld	r9,_MSR(r1);				\
388afcf0095SNicholas Piggin	mtspr	SPRN_SRR1,r9;				\
389afcf0095SNicholas Piggin	ld	r3,_NIP(r1);				\
390afcf0095SNicholas Piggin	mtspr	SPRN_SRR0,r3;				\
391afcf0095SNicholas Piggin	ld	r9,_CTR(r1);				\
392afcf0095SNicholas Piggin	mtctr	r9;					\
393afcf0095SNicholas Piggin	ld	r9,_XER(r1);				\
394afcf0095SNicholas Piggin	mtxer	r9;					\
395afcf0095SNicholas Piggin	ld	r9,_LINK(r1);				\
396afcf0095SNicholas Piggin	mtlr	r9;					\
397afcf0095SNicholas Piggin	REST_GPR(0, r1);				\
398afcf0095SNicholas Piggin	REST_8GPRS(2, r1);				\
399afcf0095SNicholas Piggin	REST_GPR(10, r1);				\
400afcf0095SNicholas Piggin	ld	r11,_CCR(r1);				\
401afcf0095SNicholas Piggin	mtcr	r11;					\
402afcf0095SNicholas Piggin	/* Decrement paca->in_mce. */			\
403afcf0095SNicholas Piggin	lhz	r12,PACA_IN_MCE(r13);			\
404afcf0095SNicholas Piggin	subi	r12,r12,1;				\
405afcf0095SNicholas Piggin	sth	r12,PACA_IN_MCE(r13);			\
406afcf0095SNicholas Piggin	REST_GPR(11, r1);				\
407afcf0095SNicholas Piggin	REST_2GPRS(12, r1);				\
408afcf0095SNicholas Piggin	/* restore original r1. */			\
409afcf0095SNicholas Piggin	ld	r1,GPR1(r1)
410afcf0095SNicholas Piggin
4111945bc45SNicholas Piggin#ifdef CONFIG_PPC_P7_NAP
4121945bc45SNicholas Piggin/*
4131945bc45SNicholas Piggin * This is an idle wakeup. Low level machine check has already been
4141945bc45SNicholas Piggin * done. Queue the event then call the idle code to do the wake up.
4151945bc45SNicholas Piggin */
4161945bc45SNicholas PigginEXC_COMMON_BEGIN(machine_check_idle_common)
4171945bc45SNicholas Piggin	bl	machine_check_queue_event
4181945bc45SNicholas Piggin
4191945bc45SNicholas Piggin	/*
4201945bc45SNicholas Piggin	 * We have not used any non-volatile GPRs here, and as a rule
4211945bc45SNicholas Piggin	 * most exception code including machine check does not.
4221945bc45SNicholas Piggin	 * Therefore PACA_NAPSTATELOST does not need to be set. Idle
4231945bc45SNicholas Piggin	 * wakeup will restore volatile registers.
4241945bc45SNicholas Piggin	 *
4251945bc45SNicholas Piggin	 * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
4261945bc45SNicholas Piggin	 *
4271945bc45SNicholas Piggin	 * Then decrement MCE nesting after finishing with the stack.
4281945bc45SNicholas Piggin	 */
4291945bc45SNicholas Piggin	ld	r3,_MSR(r1)
4301945bc45SNicholas Piggin
4311945bc45SNicholas Piggin	lhz	r11,PACA_IN_MCE(r13)
4321945bc45SNicholas Piggin	subi	r11,r11,1
4331945bc45SNicholas Piggin	sth	r11,PACA_IN_MCE(r13)
4341945bc45SNicholas Piggin
4351945bc45SNicholas Piggin	/* Turn off the RI bit because SRR1 is used by idle wakeup code. */
4361945bc45SNicholas Piggin	/* Recoverability could be improved by reducing the use of SRR1. */
4371945bc45SNicholas Piggin	li	r11,0
4381945bc45SNicholas Piggin	mtmsrd	r11,1
4391945bc45SNicholas Piggin
4401945bc45SNicholas Piggin	b	pnv_powersave_wakeup_mce
4411945bc45SNicholas Piggin#endif
442afcf0095SNicholas Piggin	/*
443afcf0095SNicholas Piggin	 * Handle machine check early in real mode. We come here with
444afcf0095SNicholas Piggin	 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
445afcf0095SNicholas Piggin	 */
446afcf0095SNicholas PigginEXC_COMMON_BEGIN(machine_check_handle_early)
447afcf0095SNicholas Piggin	std	r0,GPR0(r1)	/* Save r0 */
448afcf0095SNicholas Piggin	EXCEPTION_PROLOG_COMMON_3(0x200)
449afcf0095SNicholas Piggin	bl	save_nvgprs
450afcf0095SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
451afcf0095SNicholas Piggin	bl	machine_check_early
452afcf0095SNicholas Piggin	std	r3,RESULT(r1)	/* Save result */
453afcf0095SNicholas Piggin	ld	r12,_MSR(r1)
454db7d31acSMahesh SalgaonkarBEGIN_FTR_SECTION
455db7d31acSMahesh Salgaonkar	b	4f
456db7d31acSMahesh SalgaonkarEND_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
4571945bc45SNicholas Piggin
458afcf0095SNicholas Piggin#ifdef	CONFIG_PPC_P7_NAP
459afcf0095SNicholas Piggin	/*
460afcf0095SNicholas Piggin	 * Check if thread was in power saving mode. We come here when any
461afcf0095SNicholas Piggin	 * of the following is true:
462afcf0095SNicholas Piggin	 * a. thread wasn't in power saving mode
463afcf0095SNicholas Piggin	 * b. thread was in power saving mode with no state loss,
464afcf0095SNicholas Piggin	 *    supervisor state loss or hypervisor state loss.
465afcf0095SNicholas Piggin	 *
466afcf0095SNicholas Piggin	 * Go back to nap/sleep/winkle mode again if (b) is true.
467afcf0095SNicholas Piggin	 */
4681945bc45SNicholas Piggin	BEGIN_FTR_SECTION
4691945bc45SNicholas Piggin	rlwinm.	r11,r12,47-31,30,31
4706102c005SNicholas Piggin	bne	machine_check_idle_common
4711945bc45SNicholas Piggin	END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
472afcf0095SNicholas Piggin#endif
4731945bc45SNicholas Piggin
474afcf0095SNicholas Piggin	/*
475afcf0095SNicholas Piggin	 * Check if we are coming from hypervisor userspace. If yes then we
476afcf0095SNicholas Piggin	 * continue in host kernel in V mode to deliver the MC event.
477afcf0095SNicholas Piggin	 */
478afcf0095SNicholas Piggin	rldicl.	r11,r12,4,63		/* See if MC hit while in HV mode. */
479afcf0095SNicholas Piggin	beq	5f
480db7d31acSMahesh Salgaonkar4:	andi.	r11,r12,MSR_PR		/* See if coming from user. */
481afcf0095SNicholas Piggin	bne	9f			/* continue in V mode if we are. */
482afcf0095SNicholas Piggin
483afcf0095SNicholas Piggin5:
484afcf0095SNicholas Piggin#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
485db7d31acSMahesh SalgaonkarBEGIN_FTR_SECTION
486afcf0095SNicholas Piggin	/*
487afcf0095SNicholas Piggin	 * We are coming from kernel context. Check if we are coming from
488afcf0095SNicholas Piggin	 * guest. if yes, then we can continue. We will fall through
489afcf0095SNicholas Piggin	 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
490afcf0095SNicholas Piggin	 */
491afcf0095SNicholas Piggin	lbz	r11,HSTATE_IN_GUEST(r13)
492afcf0095SNicholas Piggin	cmpwi	r11,0			/* Check if coming from guest */
493afcf0095SNicholas Piggin	bne	9f			/* continue if we are. */
494db7d31acSMahesh SalgaonkarEND_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
495afcf0095SNicholas Piggin#endif
496afcf0095SNicholas Piggin	/*
497afcf0095SNicholas Piggin	 * At this point we are not sure about what context we come from.
498afcf0095SNicholas Piggin	 * Queue up the MCE event and return from the interrupt.
499afcf0095SNicholas Piggin	 * But before that, check if this is an un-recoverable exception.
500afcf0095SNicholas Piggin	 * If yes, then stay on emergency stack and panic.
501afcf0095SNicholas Piggin	 */
502afcf0095SNicholas Piggin	andi.	r11,r12,MSR_RI
503afcf0095SNicholas Piggin	bne	2f
504afcf0095SNicholas Piggin1:	mfspr	r11,SPRN_SRR0
505afcf0095SNicholas Piggin	LOAD_HANDLER(r10,unrecover_mce)
506afcf0095SNicholas Piggin	mtspr	SPRN_SRR0,r10
507afcf0095SNicholas Piggin	ld	r10,PACAKMSR(r13)
508afcf0095SNicholas Piggin	/*
509afcf0095SNicholas Piggin	 * We are going down. But there are chances that we might get hit by
510afcf0095SNicholas Piggin	 * another MCE during panic path and we may run into unstable state
511afcf0095SNicholas Piggin	 * with no way out. Hence, turn ME bit off while going down, so that
512afcf0095SNicholas Piggin	 * when another MCE is hit during panic path, system will checkstop
513afcf0095SNicholas Piggin	 * and hypervisor will get restarted cleanly by SP.
514afcf0095SNicholas Piggin	 */
515afcf0095SNicholas Piggin	li	r3,MSR_ME
516afcf0095SNicholas Piggin	andc	r10,r10,r3		/* Turn off MSR_ME */
517afcf0095SNicholas Piggin	mtspr	SPRN_SRR1,r10
518222f20f1SNicholas Piggin	RFI_TO_KERNEL
519afcf0095SNicholas Piggin	b	.
520afcf0095SNicholas Piggin2:
521afcf0095SNicholas Piggin	/*
522afcf0095SNicholas Piggin	 * Check if we have successfully handled/recovered from error, if not
523afcf0095SNicholas Piggin	 * then stay on emergency stack and panic.
524afcf0095SNicholas Piggin	 */
525afcf0095SNicholas Piggin	ld	r3,RESULT(r1)	/* Load result */
526afcf0095SNicholas Piggin	cmpdi	r3,0		/* see if we handled MCE successfully */
527afcf0095SNicholas Piggin
528afcf0095SNicholas Piggin	beq	1b		/* if !handled then panic */
529db7d31acSMahesh SalgaonkarBEGIN_FTR_SECTION
530afcf0095SNicholas Piggin	/*
531afcf0095SNicholas Piggin	 * Return from MC interrupt.
532afcf0095SNicholas Piggin	 * Queue up the MCE event so that we can log it later, while
533afcf0095SNicholas Piggin	 * returning from kernel or opal call.
534afcf0095SNicholas Piggin	 */
535afcf0095SNicholas Piggin	bl	machine_check_queue_event
536afcf0095SNicholas Piggin	MACHINE_CHECK_HANDLER_WINDUP
537222f20f1SNicholas Piggin	RFI_TO_USER_OR_KERNEL
538db7d31acSMahesh SalgaonkarFTR_SECTION_ELSE
539db7d31acSMahesh Salgaonkar	/*
540db7d31acSMahesh Salgaonkar	 * pSeries: Return from MC interrupt. Before that stay on emergency
541db7d31acSMahesh Salgaonkar	 * stack and call machine_check_exception to log the MCE event.
542db7d31acSMahesh Salgaonkar	 */
543db7d31acSMahesh Salgaonkar	LOAD_HANDLER(r10,mce_return)
544db7d31acSMahesh Salgaonkar	mtspr	SPRN_SRR0,r10
545db7d31acSMahesh Salgaonkar	ld	r10,PACAKMSR(r13)
546db7d31acSMahesh Salgaonkar	mtspr	SPRN_SRR1,r10
547db7d31acSMahesh Salgaonkar	RFI_TO_KERNEL
548db7d31acSMahesh Salgaonkar	b	.
549db7d31acSMahesh SalgaonkarALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
550afcf0095SNicholas Piggin9:
551afcf0095SNicholas Piggin	/* Deliver the machine check to host kernel in V mode. */
552afcf0095SNicholas Piggin	MACHINE_CHECK_HANDLER_WINDUP
553db7d31acSMahesh Salgaonkar	SET_SCRATCH0(r13)		/* save r13 */
554db7d31acSMahesh Salgaonkar	EXCEPTION_PROLOG_0(PACA_EXMC)
555db7d31acSMahesh Salgaonkar	b	machine_check_pSeries_0
556afcf0095SNicholas Piggin
557afcf0095SNicholas PigginEXC_COMMON_BEGIN(unrecover_mce)
558afcf0095SNicholas Piggin	/* Invoke machine_check_exception to print MCE event and panic. */
559afcf0095SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
560afcf0095SNicholas Piggin	bl	machine_check_exception
561afcf0095SNicholas Piggin	/*
562afcf0095SNicholas Piggin	 * We will not reach here. Even if we did, there is no way out. Call
563afcf0095SNicholas Piggin	 * unrecoverable_exception and die.
564afcf0095SNicholas Piggin	 */
565afcf0095SNicholas Piggin1:	addi	r3,r1,STACK_FRAME_OVERHEAD
566afcf0095SNicholas Piggin	bl	unrecoverable_exception
567afcf0095SNicholas Piggin	b	1b
568afcf0095SNicholas Piggin
569a43c1590SMahesh SalgaonkarEXC_COMMON_BEGIN(mce_return)
570a43c1590SMahesh Salgaonkar	/* Invoke machine_check_exception to print MCE event and return. */
571a43c1590SMahesh Salgaonkar	addi	r3,r1,STACK_FRAME_OVERHEAD
572a43c1590SMahesh Salgaonkar	bl	machine_check_exception
573db7d31acSMahesh Salgaonkar	MACHINE_CHECK_HANDLER_WINDUP
574a43c1590SMahesh Salgaonkar	RFI_TO_KERNEL
575a43c1590SMahesh Salgaonkar	b	.
5760ebc4cdaSBenjamin Herrenschmidt
577*e779fc93SNicholas PigginEXC_REAL_BEGIN(data_access, 0x300, 0x80)
578*e779fc93SNicholas PigginSET_SCRATCH0(r13)		/* save r13 */
579*e779fc93SNicholas PigginEXCEPTION_PROLOG_0(PACA_EXGEN)
580*e779fc93SNicholas Piggin	b	tramp_real_data_access
581*e779fc93SNicholas PigginEXC_REAL_END(data_access, 0x300, 0x80)
582*e779fc93SNicholas Piggin
583*e779fc93SNicholas PigginTRAMP_REAL_BEGIN(tramp_real_data_access)
584*e779fc93SNicholas PigginEXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, 0x300)
585*e779fc93SNicholas PigginEXCEPTION_PROLOG_2(data_access_common, EXC_STD)
586*e779fc93SNicholas Piggin
587*e779fc93SNicholas PigginEXC_VIRT_BEGIN(data_access, 0x4300, 0x80)
588*e779fc93SNicholas PigginSET_SCRATCH0(r13)		/* save r13 */
589*e779fc93SNicholas PigginEXCEPTION_PROLOG_0(PACA_EXGEN)
590*e779fc93SNicholas PigginEXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x300)
591*e779fc93SNicholas PigginEXCEPTION_PROLOG_2_RELON(data_access_common, EXC_STD)
592*e779fc93SNicholas PigginEXC_VIRT_END(data_access, 0x4300, 0x80)
593*e779fc93SNicholas Piggin
59480795e6cSNicholas PigginTRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
59580795e6cSNicholas Piggin
59680795e6cSNicholas PigginEXC_COMMON_BEGIN(data_access_common)
59780795e6cSNicholas Piggin	/*
59880795e6cSNicholas Piggin	 * Here r13 points to the paca, r9 contains the saved CR,
59980795e6cSNicholas Piggin	 * SRR0 and SRR1 are saved in r11 and r12,
60080795e6cSNicholas Piggin	 * r9 - r13 are saved in paca->exgen.
60180795e6cSNicholas Piggin	 */
60280795e6cSNicholas Piggin	mfspr	r10,SPRN_DAR
60380795e6cSNicholas Piggin	std	r10,PACA_EXGEN+EX_DAR(r13)
60480795e6cSNicholas Piggin	mfspr	r10,SPRN_DSISR
60580795e6cSNicholas Piggin	stw	r10,PACA_EXGEN+EX_DSISR(r13)
60680795e6cSNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
60780795e6cSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
60880795e6cSNicholas Piggin	ld	r12,_MSR(r1)
60980795e6cSNicholas Piggin	ld	r3,PACA_EXGEN+EX_DAR(r13)
61080795e6cSNicholas Piggin	lwz	r4,PACA_EXGEN+EX_DSISR(r13)
61180795e6cSNicholas Piggin	li	r5,0x300
61280795e6cSNicholas Piggin	std	r3,_DAR(r1)
61380795e6cSNicholas Piggin	std	r4,_DSISR(r1)
61480795e6cSNicholas PigginBEGIN_MMU_FTR_SECTION
61580795e6cSNicholas Piggin	b	do_hash_page		/* Try to handle as hpte fault */
61680795e6cSNicholas PigginMMU_FTR_SECTION_ELSE
61780795e6cSNicholas Piggin	b	handle_page_fault
61880795e6cSNicholas PigginALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
61980795e6cSNicholas Piggin
6200ebc4cdaSBenjamin Herrenschmidt
6211a6822d1SNicholas PigginEXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
622*e779fc93SNicholas PigginSET_SCRATCH0(r13)		/* save r13 */
623*e779fc93SNicholas PigginEXCEPTION_PROLOG_0(PACA_EXSLB)
624*e779fc93SNicholas Piggin	b	tramp_real_data_access_slb
6251a6822d1SNicholas PigginEXC_REAL_END(data_access_slb, 0x380, 0x80)
6260ebc4cdaSBenjamin Herrenschmidt
627*e779fc93SNicholas PigginTRAMP_REAL_BEGIN(tramp_real_data_access_slb)
628*e779fc93SNicholas PigginEXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
629*e779fc93SNicholas PigginEXCEPTION_PROLOG_2(data_access_slb_common, EXC_STD)
630*e779fc93SNicholas Piggin
6311a6822d1SNicholas PigginEXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
632*e779fc93SNicholas PigginSET_SCRATCH0(r13)		/* save r13 */
633*e779fc93SNicholas PigginEXCEPTION_PROLOG_0(PACA_EXSLB)
634*e779fc93SNicholas PigginEXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
635*e779fc93SNicholas PigginEXCEPTION_PROLOG_2_RELON(data_access_slb_common, EXC_STD)
6361a6822d1SNicholas PigginEXC_VIRT_END(data_access_slb, 0x4380, 0x80)
63748e7b769SNicholas Piggin
6382b9af6e4SNicholas PigginTRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
6392b9af6e4SNicholas Piggin
64048e7b769SNicholas PigginEXC_COMMON_BEGIN(data_access_slb_common)
64148e7b769SNicholas Piggin	mfspr	r10,SPRN_DAR
64248e7b769SNicholas Piggin	std	r10,PACA_EXSLB+EX_DAR(r13)
64348e7b769SNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
64448e7b769SNicholas Piggin	ld	r4,PACA_EXSLB+EX_DAR(r13)
64548e7b769SNicholas Piggin	std	r4,_DAR(r1)
64648e7b769SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
64748e7b769SNicholas Piggin	bl	do_slb_fault
64848e7b769SNicholas Piggin	cmpdi	r3,0
64948e7b769SNicholas Piggin	bne-	1f
65048e7b769SNicholas Piggin	b	fast_exception_return
65148e7b769SNicholas Piggin1:	/* Error case */
65248e7b769SNicholas Piggin	std	r3,RESULT(r1)
65348e7b769SNicholas Piggin	bl	save_nvgprs
65448e7b769SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
65548e7b769SNicholas Piggin	ld	r4,_DAR(r1)
65648e7b769SNicholas Piggin	ld	r5,RESULT(r1)
65748e7b769SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
65848e7b769SNicholas Piggin	bl	do_bad_slb_fault
65948e7b769SNicholas Piggin	b	ret_from_except
66048e7b769SNicholas Piggin
6612b9af6e4SNicholas Piggin
6621a6822d1SNicholas PigginEXC_REAL(instruction_access, 0x400, 0x80)
6631a6822d1SNicholas PigginEXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
66427ce77dfSNicholas PigginTRAMP_KVM(PACA_EXGEN, 0x400)
66527ce77dfSNicholas Piggin
66627ce77dfSNicholas PigginEXC_COMMON_BEGIN(instruction_access_common)
66727ce77dfSNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
66827ce77dfSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
66927ce77dfSNicholas Piggin	ld	r12,_MSR(r1)
67027ce77dfSNicholas Piggin	ld	r3,_NIP(r1)
671475b581fSMichael Ellerman	andis.	r4,r12,DSISR_SRR1_MATCH_64S@h
67227ce77dfSNicholas Piggin	li	r5,0x400
67327ce77dfSNicholas Piggin	std	r3,_DAR(r1)
67427ce77dfSNicholas Piggin	std	r4,_DSISR(r1)
67527ce77dfSNicholas PigginBEGIN_MMU_FTR_SECTION
67627ce77dfSNicholas Piggin	b	do_hash_page		/* Try to handle as hpte fault */
67727ce77dfSNicholas PigginMMU_FTR_SECTION_ELSE
67827ce77dfSNicholas Piggin	b	handle_page_fault
67927ce77dfSNicholas PigginALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
68027ce77dfSNicholas Piggin
6810ebc4cdaSBenjamin Herrenschmidt
6821a6822d1SNicholas PigginEXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
68348e7b769SNicholas PigginEXCEPTION_PROLOG(PACA_EXSLB, instruction_access_slb_common, EXC_STD, KVMTEST_PR, 0x480);
6841a6822d1SNicholas PigginEXC_REAL_END(instruction_access_slb, 0x480, 0x80)
6850ebc4cdaSBenjamin Herrenschmidt
6861a6822d1SNicholas PigginEXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
68748e7b769SNicholas PigginEXCEPTION_RELON_PROLOG(PACA_EXSLB, instruction_access_slb_common, EXC_STD, NOTEST, 0x480);
6881a6822d1SNicholas PigginEXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
68948e7b769SNicholas Piggin
6908d04631aSNicholas PigginTRAMP_KVM(PACA_EXSLB, 0x480)
6918d04631aSNicholas Piggin
69248e7b769SNicholas PigginEXC_COMMON_BEGIN(instruction_access_slb_common)
69348e7b769SNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x480, PACA_EXSLB)
69448e7b769SNicholas Piggin	ld	r4,_NIP(r1)
69554be0b9cSMichael Ellerman	addi	r3,r1,STACK_FRAME_OVERHEAD
69648e7b769SNicholas Piggin	bl	do_slb_fault
69748e7b769SNicholas Piggin	cmpdi	r3,0
69848e7b769SNicholas Piggin	bne-	1f
69948e7b769SNicholas Piggin	b	fast_exception_return
70048e7b769SNicholas Piggin1:	/* Error case */
70148e7b769SNicholas Piggin	std	r3,RESULT(r1)
70248e7b769SNicholas Piggin	bl	save_nvgprs
70348e7b769SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
70448e7b769SNicholas Piggin	ld	r4,_NIP(r1)
70548e7b769SNicholas Piggin	ld	r5,RESULT(r1)
70648e7b769SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
70748e7b769SNicholas Piggin	bl	do_bad_slb_fault
70854be0b9cSMichael Ellerman	b	ret_from_except
7095e46e29eSNicholas Piggin
71048e7b769SNicholas Piggin
7111a6822d1SNicholas PigginEXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
712b3e6b5dfSBenjamin Herrenschmidt	.globl hardware_interrupt_hv;
713b3e6b5dfSBenjamin Herrenschmidthardware_interrupt_hv:
714a5d4f3adSBenjamin Herrenschmidt	BEGIN_FTR_SECTION
7150b924de4SMichael Ellerman		MASKABLE_EXCEPTION_HV(0x500, hardware_interrupt_common, IRQS_DISABLED)
716de56a948SPaul Mackerras	FTR_SECTION_ELSE
7170b924de4SMichael Ellerman		MASKABLE_EXCEPTION(0x500, hardware_interrupt_common, IRQS_DISABLED)
718969391c5SPaul Mackerras	ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
7191a6822d1SNicholas PigginEXC_REAL_END(hardware_interrupt, 0x500, 0x100)
720a5d4f3adSBenjamin Herrenschmidt
7211a6822d1SNicholas PigginEXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
722c138e588SNicholas Piggin	.globl hardware_interrupt_relon_hv;
723c138e588SNicholas Pigginhardware_interrupt_relon_hv:
724c138e588SNicholas Piggin	BEGIN_FTR_SECTION
7250b924de4SMichael Ellerman		MASKABLE_RELON_EXCEPTION_HV(0x500, hardware_interrupt_common,
726f14e953bSMadhavan Srinivasan					    IRQS_DISABLED)
727c138e588SNicholas Piggin	FTR_SECTION_ELSE
7280a55c241SMichael Ellerman		__MASKABLE_RELON_EXCEPTION(0x500, hardware_interrupt_common,
7290b924de4SMichael Ellerman					   EXC_STD, SOFTEN_TEST_PR, IRQS_DISABLED)
730c138e588SNicholas Piggin	ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
7311a6822d1SNicholas PigginEXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
732c138e588SNicholas Piggin
7337ede5317SNicholas PigginTRAMP_KVM(PACA_EXGEN, 0x500)
7347ede5317SNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0x500)
735c138e588SNicholas PigginEXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
736c138e588SNicholas Piggin
737c138e588SNicholas Piggin
738*e779fc93SNicholas PigginEXC_REAL_BEGIN(alignment, 0x600, 0x100)
739*e779fc93SNicholas PigginSET_SCRATCH0(r13)		/* save r13 */
740*e779fc93SNicholas PigginEXCEPTION_PROLOG_0(PACA_EXGEN)
741*e779fc93SNicholas PigginEXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, 0x600)
742*e779fc93SNicholas PigginEXCEPTION_PROLOG_2(alignment_common, EXC_STD)
743*e779fc93SNicholas PigginEXC_REAL_END(alignment, 0x600, 0x100)
744*e779fc93SNicholas Piggin
745*e779fc93SNicholas PigginEXC_VIRT_BEGIN(alignment, 0x4600, 0x100)
746*e779fc93SNicholas PigginSET_SCRATCH0(r13)		/* save r13 */
747*e779fc93SNicholas PigginEXCEPTION_PROLOG_0(PACA_EXGEN)
748*e779fc93SNicholas PigginEXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x600)
749*e779fc93SNicholas PigginEXCEPTION_PROLOG_2_RELON(alignment_common, EXC_STD)
750*e779fc93SNicholas PigginEXC_VIRT_END(alignment, 0x4600, 0x100)
751*e779fc93SNicholas Piggin
752da2bc464SMichael EllermanTRAMP_KVM(PACA_EXGEN, 0x600)
753f9aa6714SNicholas PigginEXC_COMMON_BEGIN(alignment_common)
754f9aa6714SNicholas Piggin	mfspr	r10,SPRN_DAR
755f9aa6714SNicholas Piggin	std	r10,PACA_EXGEN+EX_DAR(r13)
756f9aa6714SNicholas Piggin	mfspr	r10,SPRN_DSISR
757f9aa6714SNicholas Piggin	stw	r10,PACA_EXGEN+EX_DSISR(r13)
758f9aa6714SNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
759f9aa6714SNicholas Piggin	ld	r3,PACA_EXGEN+EX_DAR(r13)
760f9aa6714SNicholas Piggin	lwz	r4,PACA_EXGEN+EX_DSISR(r13)
761f9aa6714SNicholas Piggin	std	r3,_DAR(r1)
762f9aa6714SNicholas Piggin	std	r4,_DSISR(r1)
763f9aa6714SNicholas Piggin	bl	save_nvgprs
764f9aa6714SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
765f9aa6714SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
766f9aa6714SNicholas Piggin	bl	alignment_exception
767f9aa6714SNicholas Piggin	b	ret_from_except
768f9aa6714SNicholas Piggin
769b01c8b54SPaul Mackerras
7701a6822d1SNicholas PigginEXC_REAL(program_check, 0x700, 0x100)
7711a6822d1SNicholas PigginEXC_VIRT(program_check, 0x4700, 0x100, 0x700)
772da2bc464SMichael EllermanTRAMP_KVM(PACA_EXGEN, 0x700)
77311e87346SNicholas PigginEXC_COMMON_BEGIN(program_check_common)
774265e60a1SCyril Bur	/*
775265e60a1SCyril Bur	 * It's possible to receive a TM Bad Thing type program check with
776265e60a1SCyril Bur	 * userspace register values (in particular r1), but with SRR1 reporting
777265e60a1SCyril Bur	 * that we came from the kernel. Normally that would confuse the bad
778265e60a1SCyril Bur	 * stack logic, and we would report a bad kernel stack pointer. Instead
779265e60a1SCyril Bur	 * we switch to the emergency stack if we're taking a TM Bad Thing from
780265e60a1SCyril Bur	 * the kernel.
781265e60a1SCyril Bur	 */
782265e60a1SCyril Bur	li	r10,MSR_PR		/* Build a mask of MSR_PR ..	*/
783265e60a1SCyril Bur	oris	r10,r10,0x200000@h	/* .. and SRR1_PROGTM		*/
784265e60a1SCyril Bur	and	r10,r10,r12		/* Mask SRR1 with that.		*/
785265e60a1SCyril Bur	srdi	r10,r10,8		/* Shift it so we can compare	*/
786265e60a1SCyril Bur	cmpldi	r10,(0x200000 >> 8)	/* .. with an immediate.	*/
787265e60a1SCyril Bur	bne 1f				/* If != go to normal path.	*/
788265e60a1SCyril Bur
789265e60a1SCyril Bur	/* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack	*/
790265e60a1SCyril Bur	andi.	r10,r12,MSR_PR;		/* Set CR0 correctly for label	*/
791265e60a1SCyril Bur					/* 3 in EXCEPTION_PROLOG_COMMON	*/
792265e60a1SCyril Bur	mr	r10,r1			/* Save r1			*/
793265e60a1SCyril Bur	ld	r1,PACAEMERGSP(r13)	/* Use emergency stack		*/
794265e60a1SCyril Bur	subi	r1,r1,INT_FRAME_SIZE	/* alloc stack frame		*/
795265e60a1SCyril Bur	b 3f				/* Jump into the macro !!	*/
796265e60a1SCyril Bur1:	EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
79711e87346SNicholas Piggin	bl	save_nvgprs
79811e87346SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
79911e87346SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
80011e87346SNicholas Piggin	bl	program_check_exception
80111e87346SNicholas Piggin	b	ret_from_except
80211e87346SNicholas Piggin
803a485c709SPaul Mackerras
8041a6822d1SNicholas PigginEXC_REAL(fp_unavailable, 0x800, 0x100)
8051a6822d1SNicholas PigginEXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
806da2bc464SMichael EllermanTRAMP_KVM(PACA_EXGEN, 0x800)
807c78d9b97SNicholas PigginEXC_COMMON_BEGIN(fp_unavailable_common)
808c78d9b97SNicholas Piggin	EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
809c78d9b97SNicholas Piggin	bne	1f			/* if from user, just load it up */
810c78d9b97SNicholas Piggin	bl	save_nvgprs
811c78d9b97SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
812c78d9b97SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
813c78d9b97SNicholas Piggin	bl	kernel_fp_unavailable_exception
814c78d9b97SNicholas Piggin	BUG_OPCODE
815c78d9b97SNicholas Piggin1:
816c78d9b97SNicholas Piggin#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
817c78d9b97SNicholas PigginBEGIN_FTR_SECTION
818c78d9b97SNicholas Piggin	/* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
819c78d9b97SNicholas Piggin	 * transaction), go do TM stuff
820c78d9b97SNicholas Piggin	 */
821c78d9b97SNicholas Piggin	rldicl.	r0, r12, (64-MSR_TS_LG), (64-2)
822c78d9b97SNicholas Piggin	bne-	2f
823c78d9b97SNicholas PigginEND_FTR_SECTION_IFSET(CPU_FTR_TM)
824c78d9b97SNicholas Piggin#endif
825c78d9b97SNicholas Piggin	bl	load_up_fpu
826c78d9b97SNicholas Piggin	b	fast_exception_return
827c78d9b97SNicholas Piggin#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
828c78d9b97SNicholas Piggin2:	/* User process was in a transaction */
829c78d9b97SNicholas Piggin	bl	save_nvgprs
830c78d9b97SNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
831c78d9b97SNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
832c78d9b97SNicholas Piggin	bl	fp_unavailable_tm
833c78d9b97SNicholas Piggin	b	ret_from_except
834c78d9b97SNicholas Piggin#endif
835c78d9b97SNicholas Piggin
836b01c8b54SPaul Mackerras
837a048a07dSNicholas PigginEXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
838f14e953bSMadhavan SrinivasanEXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
83939c0da57SNicholas PigginTRAMP_KVM(PACA_EXGEN, 0x900)
84039c0da57SNicholas PigginEXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
84139c0da57SNicholas Piggin
8420ebc4cdaSBenjamin Herrenschmidt
8431a6822d1SNicholas PigginEXC_REAL_HV(hdecrementer, 0x980, 0x80)
8441a6822d1SNicholas PigginEXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
845facc6d74SNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0x980)
846facc6d74SNicholas PigginEXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
847facc6d74SNicholas Piggin
848da2bc464SMichael Ellerman
849f14e953bSMadhavan SrinivasanEXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED)
850f14e953bSMadhavan SrinivasanEXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED)
851da2bc464SMichael EllermanTRAMP_KVM(PACA_EXGEN, 0xa00)
852ca243163SNicholas Piggin#ifdef CONFIG_PPC_DOORBELL
853ca243163SNicholas PigginEXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
854ca243163SNicholas Piggin#else
855ca243163SNicholas PigginEXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
856ca243163SNicholas Piggin#endif
857ca243163SNicholas Piggin
858da2bc464SMichael Ellerman
8591a6822d1SNicholas PigginEXC_REAL(trap_0b, 0xb00, 0x100)
8601a6822d1SNicholas PigginEXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
861da2bc464SMichael EllermanTRAMP_KVM(PACA_EXGEN, 0xb00)
862341215dcSNicholas PigginEXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
863341215dcSNicholas Piggin
864acd7d8ceSNicholas Piggin/*
865acd7d8ceSNicholas Piggin * system call / hypercall (0xc00, 0x4c00)
866acd7d8ceSNicholas Piggin *
867acd7d8ceSNicholas Piggin * The system call exception is invoked with "sc 0" and does not alter HV bit.
868acd7d8ceSNicholas Piggin * There is support for kernel code to invoke system calls but there are no
869acd7d8ceSNicholas Piggin * in-tree users.
870acd7d8ceSNicholas Piggin *
871acd7d8ceSNicholas Piggin * The hypercall is invoked with "sc 1" and sets HV=1.
872acd7d8ceSNicholas Piggin *
873acd7d8ceSNicholas Piggin * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
874acd7d8ceSNicholas Piggin * 0x4c00 virtual mode.
875acd7d8ceSNicholas Piggin *
876acd7d8ceSNicholas Piggin * Call convention:
877acd7d8ceSNicholas Piggin *
878acd7d8ceSNicholas Piggin * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
879acd7d8ceSNicholas Piggin *
880acd7d8ceSNicholas Piggin * For hypercalls, the register convention is as follows:
881acd7d8ceSNicholas Piggin * r0 volatile
882acd7d8ceSNicholas Piggin * r1-2 nonvolatile
883acd7d8ceSNicholas Piggin * r3 volatile parameter and return value for status
884acd7d8ceSNicholas Piggin * r4-r10 volatile input and output value
885acd7d8ceSNicholas Piggin * r11 volatile hypercall number and output value
88676fc0cfcSNicholas Piggin * r12 volatile input and output value
887acd7d8ceSNicholas Piggin * r13-r31 nonvolatile
888acd7d8ceSNicholas Piggin * LR nonvolatile
889acd7d8ceSNicholas Piggin * CTR volatile
890acd7d8ceSNicholas Piggin * XER volatile
891acd7d8ceSNicholas Piggin * CR0-1 CR5-7 volatile
892acd7d8ceSNicholas Piggin * CR2-4 nonvolatile
893acd7d8ceSNicholas Piggin * Other registers nonvolatile
894acd7d8ceSNicholas Piggin *
895acd7d8ceSNicholas Piggin * The intersection of volatile registers that don't contain possible
89676fc0cfcSNicholas Piggin * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
89776fc0cfcSNicholas Piggin * without saving, though xer is not a good idea to use, as hardware may
89876fc0cfcSNicholas Piggin * interpret some bits so it may be costly to change them.
899acd7d8ceSNicholas Piggin */
900bc355125SPaul Mackerras#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
901bc355125SPaul Mackerras	/*
902acd7d8ceSNicholas Piggin	 * There is a little bit of juggling to get syscall and hcall
90376fc0cfcSNicholas Piggin	 * working well. Save r13 in ctr to avoid using SPRG scratch
90476fc0cfcSNicholas Piggin	 * register.
905acd7d8ceSNicholas Piggin	 *
906acd7d8ceSNicholas Piggin	 * Userspace syscalls have already saved the PPR, hcalls must save
907acd7d8ceSNicholas Piggin	 * it before setting HMT_MEDIUM.
908bc355125SPaul Mackerras	 */
909bc355125SPaul Mackerras#define SYSCALL_KVMTEST							\
91076fc0cfcSNicholas Piggin	mtctr	r13;							\
911bc355125SPaul Mackerras	GET_PACA(r13);							\
91276fc0cfcSNicholas Piggin	std	r10,PACA_EXGEN+EX_R10(r13);				\
913a048a07dSNicholas Piggin	INTERRUPT_TO_KERNEL;						\
914acd7d8ceSNicholas Piggin	KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
915bc355125SPaul Mackerras	HMT_MEDIUM;							\
91676fc0cfcSNicholas Piggin	mfctr	r9;
917bc355125SPaul Mackerras
918bc355125SPaul Mackerras#else
919bc355125SPaul Mackerras#define SYSCALL_KVMTEST							\
920acd7d8ceSNicholas Piggin	HMT_MEDIUM;							\
921acd7d8ceSNicholas Piggin	mr	r9,r13;							\
922a048a07dSNicholas Piggin	GET_PACA(r13);							\
923a048a07dSNicholas Piggin	INTERRUPT_TO_KERNEL;
924bc355125SPaul Mackerras#endif
925bc355125SPaul Mackerras
926d807ad37SNicholas Piggin#define LOAD_SYSCALL_HANDLER(reg)					\
927fb479e44SNicholas Piggin	__LOAD_HANDLER(reg, system_call_common)
928d807ad37SNicholas Piggin
929acd7d8ceSNicholas Piggin/*
930acd7d8ceSNicholas Piggin * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
931acd7d8ceSNicholas Piggin * and HMT_MEDIUM.
932acd7d8ceSNicholas Piggin */
933acd7d8ceSNicholas Piggin#define SYSCALL_REAL	 					\
934acd7d8ceSNicholas Piggin	mfspr	r11,SPRN_SRR0 ;					\
935d807ad37SNicholas Piggin	mfspr	r12,SPRN_SRR1 ;					\
936d807ad37SNicholas Piggin	LOAD_SYSCALL_HANDLER(r10) ; 				\
937d807ad37SNicholas Piggin	mtspr	SPRN_SRR0,r10 ; 				\
938d807ad37SNicholas Piggin	ld	r10,PACAKMSR(r13) ;				\
939d807ad37SNicholas Piggin	mtspr	SPRN_SRR1,r10 ; 				\
940222f20f1SNicholas Piggin	RFI_TO_KERNEL ;						\
941d807ad37SNicholas Piggin	b	. ;	/* prevent speculative execution */
942d807ad37SNicholas Piggin
943727f1361SMichael Ellerman#ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
9445c2511bfSMichael Ellerman#define SYSCALL_FASTENDIAN_TEST					\
9455c2511bfSMichael EllermanBEGIN_FTR_SECTION						\
9465c2511bfSMichael Ellerman	cmpdi	r0,0x1ebe ; 					\
9475c2511bfSMichael Ellerman	beq-	1f ;						\
9485c2511bfSMichael EllermanEND_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)				\
9495c2511bfSMichael Ellerman
950acd7d8ceSNicholas Piggin#define SYSCALL_FASTENDIAN					\
951d807ad37SNicholas Piggin	/* Fast LE/BE switch system call */			\
952d807ad37SNicholas Piggin1:	mfspr	r12,SPRN_SRR1 ;					\
953d807ad37SNicholas Piggin	xori	r12,r12,MSR_LE ;				\
954d807ad37SNicholas Piggin	mtspr	SPRN_SRR1,r12 ;					\
955acd7d8ceSNicholas Piggin	mr	r13,r9 ;					\
956222f20f1SNicholas Piggin	RFI_TO_USER ;	/* return to userspace */		\
957d807ad37SNicholas Piggin	b	. ;	/* prevent speculative execution */
958727f1361SMichael Ellerman#else
959727f1361SMichael Ellerman#define SYSCALL_FASTENDIAN_TEST
960727f1361SMichael Ellerman#define SYSCALL_FASTENDIAN
961727f1361SMichael Ellerman#endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
962d807ad37SNicholas Piggin
963d807ad37SNicholas Piggin#if defined(CONFIG_RELOCATABLE)
964d807ad37SNicholas Piggin	/*
965d807ad37SNicholas Piggin	 * We can't branch directly so we do it via the CTR which
966d807ad37SNicholas Piggin	 * is volatile across system calls.
967d807ad37SNicholas Piggin	 */
968acd7d8ceSNicholas Piggin#define SYSCALL_VIRT						\
969acd7d8ceSNicholas Piggin	LOAD_SYSCALL_HANDLER(r10) ;				\
970acd7d8ceSNicholas Piggin	mtctr	r10 ;						\
971acd7d8ceSNicholas Piggin	mfspr	r11,SPRN_SRR0 ;					\
972d807ad37SNicholas Piggin	mfspr	r12,SPRN_SRR1 ;					\
973d807ad37SNicholas Piggin	li	r10,MSR_RI ;					\
974d807ad37SNicholas Piggin	mtmsrd 	r10,1 ;						\
975d807ad37SNicholas Piggin	bctr ;
976d807ad37SNicholas Piggin#else
977d807ad37SNicholas Piggin	/* We can branch directly */
978acd7d8ceSNicholas Piggin#define SYSCALL_VIRT						\
979acd7d8ceSNicholas Piggin	mfspr	r11,SPRN_SRR0 ;					\
980d807ad37SNicholas Piggin	mfspr	r12,SPRN_SRR1 ;					\
981d807ad37SNicholas Piggin	li	r10,MSR_RI ;					\
982d807ad37SNicholas Piggin	mtmsrd 	r10,1 ;			/* Set RI (EE=0) */	\
983d807ad37SNicholas Piggin	b	system_call_common ;
984d807ad37SNicholas Piggin#endif
985d807ad37SNicholas Piggin
9861a6822d1SNicholas PigginEXC_REAL_BEGIN(system_call, 0xc00, 0x100)
987acd7d8ceSNicholas Piggin	SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
988acd7d8ceSNicholas Piggin	SYSCALL_FASTENDIAN_TEST
989acd7d8ceSNicholas Piggin	SYSCALL_REAL
990acd7d8ceSNicholas Piggin	SYSCALL_FASTENDIAN
9911a6822d1SNicholas PigginEXC_REAL_END(system_call, 0xc00, 0x100)
992b01c8b54SPaul Mackerras
9931a6822d1SNicholas PigginEXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
994acd7d8ceSNicholas Piggin	SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
995acd7d8ceSNicholas Piggin	SYSCALL_FASTENDIAN_TEST
996acd7d8ceSNicholas Piggin	SYSCALL_VIRT
997acd7d8ceSNicholas Piggin	SYSCALL_FASTENDIAN
9981a6822d1SNicholas PigginEXC_VIRT_END(system_call, 0x4c00, 0x100)
999d807ad37SNicholas Piggin
1000acd7d8ceSNicholas Piggin#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1001acd7d8ceSNicholas Piggin	/*
1002acd7d8ceSNicholas Piggin	 * This is a hcall, so register convention is as above, with these
1003acd7d8ceSNicholas Piggin	 * differences:
1004acd7d8ceSNicholas Piggin	 * r13 = PACA
100576fc0cfcSNicholas Piggin	 * ctr = orig r13
100676fc0cfcSNicholas Piggin	 * orig r10 saved in PACA
1007acd7d8ceSNicholas Piggin	 */
1008acd7d8ceSNicholas PigginTRAMP_KVM_BEGIN(do_kvm_0xc00)
1009acd7d8ceSNicholas Piggin	 /*
1010acd7d8ceSNicholas Piggin	  * Save the PPR (on systems that support it) before changing to
1011acd7d8ceSNicholas Piggin	  * HMT_MEDIUM. That allows the KVM code to save that value into the
1012acd7d8ceSNicholas Piggin	  * guest state (it is the guest's PPR value).
1013acd7d8ceSNicholas Piggin	  */
101476fc0cfcSNicholas Piggin	OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
1015acd7d8ceSNicholas Piggin	HMT_MEDIUM
101676fc0cfcSNicholas Piggin	OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
1017acd7d8ceSNicholas Piggin	mfctr	r10
101876fc0cfcSNicholas Piggin	SET_SCRATCH0(r10)
1019acd7d8ceSNicholas Piggin	std	r9,PACA_EXGEN+EX_R9(r13)
1020acd7d8ceSNicholas Piggin	mfcr	r9
1021acd7d8ceSNicholas Piggin	KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
1022acd7d8ceSNicholas Piggin#endif
1023da2bc464SMichael Ellerman
1024d807ad37SNicholas Piggin
10251a6822d1SNicholas PigginEXC_REAL(single_step, 0xd00, 0x100)
10261a6822d1SNicholas PigginEXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
1027da2bc464SMichael EllermanTRAMP_KVM(PACA_EXGEN, 0xd00)
1028bc6675c6SNicholas PigginEXC_COMMON(single_step_common, 0xd00, single_step_exception)
1029da2bc464SMichael Ellerman
10301a6822d1SNicholas PigginEXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
1031da0e7e62SMichael EllermanEXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
1032f5c32c1dSNicholas PigginTRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
1033f5c32c1dSNicholas PigginEXC_COMMON_BEGIN(h_data_storage_common)
1034f5c32c1dSNicholas Piggin	mfspr   r10,SPRN_HDAR
1035f5c32c1dSNicholas Piggin	std     r10,PACA_EXGEN+EX_DAR(r13)
1036f5c32c1dSNicholas Piggin	mfspr   r10,SPRN_HDSISR
1037f5c32c1dSNicholas Piggin	stw     r10,PACA_EXGEN+EX_DSISR(r13)
1038f5c32c1dSNicholas Piggin	EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1039f5c32c1dSNicholas Piggin	bl      save_nvgprs
1040f5c32c1dSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
1041f5c32c1dSNicholas Piggin	addi    r3,r1,STACK_FRAME_OVERHEAD
1042d7b45615SSuraj Jitindar SinghBEGIN_MMU_FTR_SECTION
1043d7b45615SSuraj Jitindar Singh	ld	r4,PACA_EXGEN+EX_DAR(r13)
1044d7b45615SSuraj Jitindar Singh	lwz	r5,PACA_EXGEN+EX_DSISR(r13)
1045d7b45615SSuraj Jitindar Singh	std	r4,_DAR(r1)
1046d7b45615SSuraj Jitindar Singh	std	r5,_DSISR(r1)
1047d7b45615SSuraj Jitindar Singh	li	r5,SIGSEGV
1048d7b45615SSuraj Jitindar Singh	bl      bad_page_fault
1049d7b45615SSuraj Jitindar SinghMMU_FTR_SECTION_ELSE
1050f5c32c1dSNicholas Piggin	bl      unknown_exception
1051d7b45615SSuraj Jitindar SinghALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX)
1052f5c32c1dSNicholas Piggin	b       ret_from_except
1053f5c32c1dSNicholas Piggin
10541707dd16SPaul Mackerras
10551a6822d1SNicholas PigginEXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
1056da0e7e62SMichael EllermanEXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
105782517cabSNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0xe20)
105882517cabSNicholas PigginEXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
105982517cabSNicholas Piggin
10601707dd16SPaul Mackerras
10611a6822d1SNicholas PigginEXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
10621a6822d1SNicholas PigginEXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
1063031b4026SNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0xe40)
1064031b4026SNicholas PigginEXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
1065031b4026SNicholas Piggin
10661707dd16SPaul Mackerras
1067e0319829SNicholas Piggin/*
1068e0319829SNicholas Piggin * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1069e0319829SNicholas Piggin * first, and then eventaully from there to the trampoline to get into virtual
1070e0319829SNicholas Piggin * mode.
1071e0319829SNicholas Piggin */
10721a6822d1SNicholas Piggin__EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
1073f14e953bSMadhavan Srinivasan__TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
10741a6822d1SNicholas PigginEXC_VIRT_NONE(0x4e60, 0x20)
107562f9b03bSNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0xe60)
107662f9b03bSNicholas PigginTRAMP_REAL_BEGIN(hmi_exception_early)
107762f9b03bSNicholas Piggin	EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
107862f9b03bSNicholas Piggin	mr	r10,r1			/* Save r1 */
1079a4087a4dSNicholas Piggin	ld	r1,PACAEMERGSP(r13)	/* Use emergency stack for realmode */
108062f9b03bSNicholas Piggin	subi	r1,r1,INT_FRAME_SIZE	/* alloc stack frame		*/
108162f9b03bSNicholas Piggin	mfspr	r11,SPRN_HSRR0		/* Save HSRR0 */
1082a4087a4dSNicholas Piggin	mfspr	r12,SPRN_HSRR1		/* Save HSRR1 */
1083a4087a4dSNicholas Piggin	EXCEPTION_PROLOG_COMMON_1()
108462f9b03bSNicholas Piggin	EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
108562f9b03bSNicholas Piggin	EXCEPTION_PROLOG_COMMON_3(0xe60)
108662f9b03bSNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
1087505a314fSBenjamin Herrenschmidt	BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI */
10885080332cSMichael Neuling	cmpdi	cr0,r3,0
10895080332cSMichael Neuling
109062f9b03bSNicholas Piggin	/* Windup the stack. */
109162f9b03bSNicholas Piggin	/* Move original HSRR0 and HSRR1 into the respective regs */
109262f9b03bSNicholas Piggin	ld	r9,_MSR(r1)
109362f9b03bSNicholas Piggin	mtspr	SPRN_HSRR1,r9
109462f9b03bSNicholas Piggin	ld	r3,_NIP(r1)
109562f9b03bSNicholas Piggin	mtspr	SPRN_HSRR0,r3
109662f9b03bSNicholas Piggin	ld	r9,_CTR(r1)
109762f9b03bSNicholas Piggin	mtctr	r9
109862f9b03bSNicholas Piggin	ld	r9,_XER(r1)
109962f9b03bSNicholas Piggin	mtxer	r9
110062f9b03bSNicholas Piggin	ld	r9,_LINK(r1)
110162f9b03bSNicholas Piggin	mtlr	r9
110262f9b03bSNicholas Piggin	REST_GPR(0, r1)
110362f9b03bSNicholas Piggin	REST_8GPRS(2, r1)
110462f9b03bSNicholas Piggin	REST_GPR(10, r1)
110562f9b03bSNicholas Piggin	ld	r11,_CCR(r1)
11065080332cSMichael Neuling	REST_2GPRS(12, r1)
11075080332cSMichael Neuling	bne	1f
110862f9b03bSNicholas Piggin	mtcr	r11
110962f9b03bSNicholas Piggin	REST_GPR(11, r1)
11105080332cSMichael Neuling	ld	r1,GPR1(r1)
1111222f20f1SNicholas Piggin	HRFI_TO_USER_OR_KERNEL
11125080332cSMichael Neuling
11135080332cSMichael Neuling1:	mtcr	r11
11145080332cSMichael Neuling	REST_GPR(11, r1)
111562f9b03bSNicholas Piggin	ld	r1,GPR1(r1)
111662f9b03bSNicholas Piggin
111762f9b03bSNicholas Piggin	/*
111862f9b03bSNicholas Piggin	 * Go to virtual mode and pull the HMI event information from
111962f9b03bSNicholas Piggin	 * firmware.
112062f9b03bSNicholas Piggin	 */
112162f9b03bSNicholas Piggin	.globl hmi_exception_after_realmode
112262f9b03bSNicholas Pigginhmi_exception_after_realmode:
112362f9b03bSNicholas Piggin	SET_SCRATCH0(r13)
112462f9b03bSNicholas Piggin	EXCEPTION_PROLOG_0(PACA_EXGEN)
112562f9b03bSNicholas Piggin	b	tramp_real_hmi_exception
112662f9b03bSNicholas Piggin
11275080332cSMichael NeulingEXC_COMMON_BEGIN(hmi_exception_common)
11285080332cSMichael NeulingEXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
11295080332cSMichael Neuling        ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
11301707dd16SPaul Mackerras
1131f14e953bSMadhavan SrinivasanEXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED)
1132f14e953bSMadhavan SrinivasanEXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED)
11339bcb81bfSNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0xe80)
11349bcb81bfSNicholas Piggin#ifdef CONFIG_PPC_DOORBELL
11359bcb81bfSNicholas PigginEXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
11369bcb81bfSNicholas Piggin#else
11379bcb81bfSNicholas PigginEXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
11389bcb81bfSNicholas Piggin#endif
11399bcb81bfSNicholas Piggin
11400ebc4cdaSBenjamin Herrenschmidt
1141f14e953bSMadhavan SrinivasanEXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED)
1142f14e953bSMadhavan SrinivasanEXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED)
114374408776SNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0xea0)
114474408776SNicholas PigginEXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
114574408776SNicholas Piggin
11469baaef0aSBenjamin Herrenschmidt
11471a6822d1SNicholas PigginEXC_REAL_NONE(0xec0, 0x20)
11481a6822d1SNicholas PigginEXC_VIRT_NONE(0x4ec0, 0x20)
11491a6822d1SNicholas PigginEXC_REAL_NONE(0xee0, 0x20)
11501a6822d1SNicholas PigginEXC_VIRT_NONE(0x4ee0, 0x20)
1151bda7fea2SNicholas Piggin
11520ebc4cdaSBenjamin Herrenschmidt
1153f442d004SMadhavan SrinivasanEXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED)
1154f442d004SMadhavan SrinivasanEXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED)
1155b1c7f150SNicholas PigginTRAMP_KVM(PACA_EXGEN, 0xf00)
1156b1c7f150SNicholas PigginEXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1157b1c7f150SNicholas Piggin
11580ebc4cdaSBenjamin Herrenschmidt
11591a6822d1SNicholas PigginEXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
11601a6822d1SNicholas PigginEXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
1161d1a0ca9cSNicholas PigginTRAMP_KVM(PACA_EXGEN, 0xf20)
1162d1a0ca9cSNicholas PigginEXC_COMMON_BEGIN(altivec_unavailable_common)
1163d1a0ca9cSNicholas Piggin	EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1164d1a0ca9cSNicholas Piggin#ifdef CONFIG_ALTIVEC
1165d1a0ca9cSNicholas PigginBEGIN_FTR_SECTION
1166d1a0ca9cSNicholas Piggin	beq	1f
1167d1a0ca9cSNicholas Piggin#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1168d1a0ca9cSNicholas Piggin  BEGIN_FTR_SECTION_NESTED(69)
1169d1a0ca9cSNicholas Piggin	/* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1170d1a0ca9cSNicholas Piggin	 * transaction), go do TM stuff
1171d1a0ca9cSNicholas Piggin	 */
1172d1a0ca9cSNicholas Piggin	rldicl.	r0, r12, (64-MSR_TS_LG), (64-2)
1173d1a0ca9cSNicholas Piggin	bne-	2f
1174d1a0ca9cSNicholas Piggin  END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1175d1a0ca9cSNicholas Piggin#endif
1176d1a0ca9cSNicholas Piggin	bl	load_up_altivec
1177d1a0ca9cSNicholas Piggin	b	fast_exception_return
1178d1a0ca9cSNicholas Piggin#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1179d1a0ca9cSNicholas Piggin2:	/* User process was in a transaction */
1180d1a0ca9cSNicholas Piggin	bl	save_nvgprs
1181d1a0ca9cSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
1182d1a0ca9cSNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
1183d1a0ca9cSNicholas Piggin	bl	altivec_unavailable_tm
1184d1a0ca9cSNicholas Piggin	b	ret_from_except
1185d1a0ca9cSNicholas Piggin#endif
1186d1a0ca9cSNicholas Piggin1:
1187d1a0ca9cSNicholas PigginEND_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1188d1a0ca9cSNicholas Piggin#endif
1189d1a0ca9cSNicholas Piggin	bl	save_nvgprs
1190d1a0ca9cSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
1191d1a0ca9cSNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
1192d1a0ca9cSNicholas Piggin	bl	altivec_unavailable_exception
1193d1a0ca9cSNicholas Piggin	b	ret_from_except
1194d1a0ca9cSNicholas Piggin
11950ebc4cdaSBenjamin Herrenschmidt
11961a6822d1SNicholas PigginEXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
11971a6822d1SNicholas PigginEXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
1198792cbdddSNicholas PigginTRAMP_KVM(PACA_EXGEN, 0xf40)
1199792cbdddSNicholas PigginEXC_COMMON_BEGIN(vsx_unavailable_common)
1200792cbdddSNicholas Piggin	EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1201792cbdddSNicholas Piggin#ifdef CONFIG_VSX
1202792cbdddSNicholas PigginBEGIN_FTR_SECTION
1203792cbdddSNicholas Piggin	beq	1f
1204792cbdddSNicholas Piggin#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1205792cbdddSNicholas Piggin  BEGIN_FTR_SECTION_NESTED(69)
1206792cbdddSNicholas Piggin	/* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1207792cbdddSNicholas Piggin	 * transaction), go do TM stuff
1208792cbdddSNicholas Piggin	 */
1209792cbdddSNicholas Piggin	rldicl.	r0, r12, (64-MSR_TS_LG), (64-2)
1210792cbdddSNicholas Piggin	bne-	2f
1211792cbdddSNicholas Piggin  END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1212792cbdddSNicholas Piggin#endif
1213792cbdddSNicholas Piggin	b	load_up_vsx
1214792cbdddSNicholas Piggin#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1215792cbdddSNicholas Piggin2:	/* User process was in a transaction */
1216792cbdddSNicholas Piggin	bl	save_nvgprs
1217792cbdddSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
1218792cbdddSNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
1219792cbdddSNicholas Piggin	bl	vsx_unavailable_tm
1220792cbdddSNicholas Piggin	b	ret_from_except
1221792cbdddSNicholas Piggin#endif
1222792cbdddSNicholas Piggin1:
1223792cbdddSNicholas PigginEND_FTR_SECTION_IFSET(CPU_FTR_VSX)
1224792cbdddSNicholas Piggin#endif
1225792cbdddSNicholas Piggin	bl	save_nvgprs
1226792cbdddSNicholas Piggin	RECONCILE_IRQ_STATE(r10, r11)
1227792cbdddSNicholas Piggin	addi	r3,r1,STACK_FRAME_OVERHEAD
1228792cbdddSNicholas Piggin	bl	vsx_unavailable_exception
1229792cbdddSNicholas Piggin	b	ret_from_except
1230792cbdddSNicholas Piggin
1231d0c0c9a1SMichael Neuling
12321a6822d1SNicholas PigginEXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
12331a6822d1SNicholas PigginEXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
12341134713cSNicholas PigginTRAMP_KVM(PACA_EXGEN, 0xf60)
12351134713cSNicholas PigginEXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
12361134713cSNicholas Piggin
1237da2bc464SMichael Ellerman
12381a6822d1SNicholas PigginEXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
12391a6822d1SNicholas PigginEXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
124014b0072cSNicholas PigginTRAMP_KVM_HV(PACA_EXGEN, 0xf80)
124114b0072cSNicholas PigginEXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
124214b0072cSNicholas Piggin
1243da2bc464SMichael Ellerman
12441a6822d1SNicholas PigginEXC_REAL_NONE(0xfa0, 0x20)
12451a6822d1SNicholas PigginEXC_VIRT_NONE(0x4fa0, 0x20)
12461a6822d1SNicholas PigginEXC_REAL_NONE(0xfc0, 0x20)
12471a6822d1SNicholas PigginEXC_VIRT_NONE(0x4fc0, 0x20)
12481a6822d1SNicholas PigginEXC_REAL_NONE(0xfe0, 0x20)
12491a6822d1SNicholas PigginEXC_VIRT_NONE(0x4fe0, 0x20)
12501a6822d1SNicholas Piggin
12511a6822d1SNicholas PigginEXC_REAL_NONE(0x1000, 0x100)
12521a6822d1SNicholas PigginEXC_VIRT_NONE(0x5000, 0x100)
12531a6822d1SNicholas PigginEXC_REAL_NONE(0x1100, 0x100)
12541a6822d1SNicholas PigginEXC_VIRT_NONE(0x5100, 0x100)
1255da2bc464SMichael Ellerman
12560ebc4cdaSBenjamin Herrenschmidt#ifdef CONFIG_CBE_RAS
12571a6822d1SNicholas PigginEXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
12581a6822d1SNicholas PigginEXC_VIRT_NONE(0x5200, 0x100)
1259da2bc464SMichael EllermanTRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
1260ff1b3206SNicholas PigginEXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
1261da2bc464SMichael Ellerman#else /* CONFIG_CBE_RAS */
12621a6822d1SNicholas PigginEXC_REAL_NONE(0x1200, 0x100)
12631a6822d1SNicholas PigginEXC_VIRT_NONE(0x5200, 0x100)
1264da2bc464SMichael Ellerman#endif
1265da2bc464SMichael Ellerman
1266ff1b3206SNicholas Piggin
12671a6822d1SNicholas PigginEXC_REAL(instruction_breakpoint, 0x1300, 0x100)
12681a6822d1SNicholas PigginEXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
1269da2bc464SMichael EllermanTRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
12704e96dbbfSNicholas PigginEXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
12714e96dbbfSNicholas Piggin
12721a6822d1SNicholas PigginEXC_REAL_NONE(0x1400, 0x100)
12731a6822d1SNicholas PigginEXC_VIRT_NONE(0x5400, 0x100)
1274da2bc464SMichael Ellerman
12751a6822d1SNicholas PigginEXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
1276b92a66a6SMichael Neuling	mtspr	SPRN_SPRG_HSCRATCH0,r13
12771707dd16SPaul Mackerras	EXCEPTION_PROLOG_0(PACA_EXGEN)
1278630573c1SPaul Mackerras	EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
1279b92a66a6SMichael Neuling
1280b92a66a6SMichael Neuling#ifdef CONFIG_PPC_DENORMALISATION
1281b92a66a6SMichael Neuling	mfspr	r10,SPRN_HSRR1
1282b92a66a6SMichael Neuling	andis.	r10,r10,(HSRR1_DENORM)@h /* denorm? */
1283b92a66a6SMichael Neuling	bne+	denorm_assist
1284b92a66a6SMichael Neuling#endif
1285b92a66a6SMichael Neuling
12864bb3c7a0SPaul Mackerras	KVMTEST_HV(0x1500)
1287cb58a4a4SMichael Ellerman	EXCEPTION_PROLOG_2(denorm_common, EXC_HV)
12881a6822d1SNicholas PigginEXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
1289da2bc464SMichael Ellerman
1290d7e89849SNicholas Piggin#ifdef CONFIG_PPC_DENORMALISATION
12911a6822d1SNicholas PigginEXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
1292d7e89849SNicholas Piggin	b	exc_real_0x1500_denorm_exception_hv
12931a6822d1SNicholas PigginEXC_VIRT_END(denorm_exception, 0x5500, 0x100)
1294d7e89849SNicholas Piggin#else
12951a6822d1SNicholas PigginEXC_VIRT_NONE(0x5500, 0x100)
1296d7e89849SNicholas Piggin#endif
1297d7e89849SNicholas Piggin
12984bb3c7a0SPaul MackerrasTRAMP_KVM_HV(PACA_EXGEN, 0x1500)
1299b92a66a6SMichael Neuling
1300b92a66a6SMichael Neuling#ifdef CONFIG_PPC_DENORMALISATION
1301da2bc464SMichael EllermanTRAMP_REAL_BEGIN(denorm_assist)
1302b92a66a6SMichael NeulingBEGIN_FTR_SECTION
1303b92a66a6SMichael Neuling/*
1304b92a66a6SMichael Neuling * To denormalise we need to move a copy of the register to itself.
1305b92a66a6SMichael Neuling * For POWER6 do that here for all FP regs.
1306b92a66a6SMichael Neuling */
1307b92a66a6SMichael Neuling	mfmsr	r10
1308b92a66a6SMichael Neuling	ori	r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1309b92a66a6SMichael Neuling	xori	r10,r10,(MSR_FE0|MSR_FE1)
1310b92a66a6SMichael Neuling	mtmsrd	r10
1311b92a66a6SMichael Neuling	sync
1312d7c67fb1SMichael Neuling
1313d7c67fb1SMichael Neuling#define FMR2(n)  fmr (n), (n) ; fmr n+1, n+1
1314d7c67fb1SMichael Neuling#define FMR4(n)  FMR2(n) ; FMR2(n+2)
1315d7c67fb1SMichael Neuling#define FMR8(n)  FMR4(n) ; FMR4(n+4)
1316d7c67fb1SMichael Neuling#define FMR16(n) FMR8(n) ; FMR8(n+8)
1317d7c67fb1SMichael Neuling#define FMR32(n) FMR16(n) ; FMR16(n+16)
1318d7c67fb1SMichael Neuling	FMR32(0)
1319d7c67fb1SMichael Neuling
1320b92a66a6SMichael NeulingFTR_SECTION_ELSE
1321b92a66a6SMichael Neuling/*
1322b92a66a6SMichael Neuling * To denormalise we need to move a copy of the register to itself.
1323b92a66a6SMichael Neuling * For POWER7 do that here for the first 32 VSX registers only.
1324b92a66a6SMichael Neuling */
1325b92a66a6SMichael Neuling	mfmsr	r10
1326b92a66a6SMichael Neuling	oris	r10,r10,MSR_VSX@h
1327b92a66a6SMichael Neuling	mtmsrd	r10
1328b92a66a6SMichael Neuling	sync
1329d7c67fb1SMichael Neuling
1330d7c67fb1SMichael Neuling#define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
1331d7c67fb1SMichael Neuling#define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
1332d7c67fb1SMichael Neuling#define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
1333d7c67fb1SMichael Neuling#define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
1334d7c67fb1SMichael Neuling#define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
1335d7c67fb1SMichael Neuling	XVCPSGNDP32(0)
1336d7c67fb1SMichael Neuling
1337b92a66a6SMichael NeulingALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
1338fb0fce3eSMichael Neuling
1339fb0fce3eSMichael NeulingBEGIN_FTR_SECTION
1340fb0fce3eSMichael Neuling	b	denorm_done
1341fb0fce3eSMichael NeulingEND_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1342fb0fce3eSMichael Neuling/*
1343fb0fce3eSMichael Neuling * To denormalise we need to move a copy of the register to itself.
1344fb0fce3eSMichael Neuling * For POWER8 we need to do that for all 64 VSX registers
1345fb0fce3eSMichael Neuling */
1346fb0fce3eSMichael Neuling	XVCPSGNDP32(32)
1347fb0fce3eSMichael Neulingdenorm_done:
1348f14040bcSMichael Neuling	mfspr	r11,SPRN_HSRR0
1349f14040bcSMichael Neuling	subi	r11,r11,4
1350b92a66a6SMichael Neuling	mtspr	SPRN_HSRR0,r11
1351b92a66a6SMichael Neuling	mtcrf	0x80,r9
1352b92a66a6SMichael Neuling	ld	r9,PACA_EXGEN+EX_R9(r13)
135344e9309fSHaren Myneni	RESTORE_PPR_PACA(PACA_EXGEN, r10)
1354630573c1SPaul MackerrasBEGIN_FTR_SECTION
1355630573c1SPaul Mackerras	ld	r10,PACA_EXGEN+EX_CFAR(r13)
1356630573c1SPaul Mackerras	mtspr	SPRN_CFAR,r10
1357630573c1SPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1358b92a66a6SMichael Neuling	ld	r10,PACA_EXGEN+EX_R10(r13)
1359b92a66a6SMichael Neuling	ld	r11,PACA_EXGEN+EX_R11(r13)
1360b92a66a6SMichael Neuling	ld	r12,PACA_EXGEN+EX_R12(r13)
1361b92a66a6SMichael Neuling	ld	r13,PACA_EXGEN+EX_R13(r13)
1362222f20f1SNicholas Piggin	HRFI_TO_UNKNOWN
1363b92a66a6SMichael Neuling	b	.
1364b92a66a6SMichael Neuling#endif
1365b92a66a6SMichael Neuling
1366872e2ae4SBenjamin HerrenschmidtEXC_COMMON(denorm_common, 0x1500, unknown_exception)
1367d7e89849SNicholas Piggin
1368d7e89849SNicholas Piggin
1369d7e89849SNicholas Piggin#ifdef CONFIG_CBE_RAS
13701a6822d1SNicholas PigginEXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
13711a6822d1SNicholas PigginEXC_VIRT_NONE(0x5600, 0x100)
1372d7e89849SNicholas PigginTRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
137369a79344SNicholas PigginEXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
1374d7e89849SNicholas Piggin#else /* CONFIG_CBE_RAS */
13751a6822d1SNicholas PigginEXC_REAL_NONE(0x1600, 0x100)
13761a6822d1SNicholas PigginEXC_VIRT_NONE(0x5600, 0x100)
1377d7e89849SNicholas Piggin#endif
1378d7e89849SNicholas Piggin
137969a79344SNicholas Piggin
13801a6822d1SNicholas PigginEXC_REAL(altivec_assist, 0x1700, 0x100)
13811a6822d1SNicholas PigginEXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
1382d7e89849SNicholas PigginTRAMP_KVM(PACA_EXGEN, 0x1700)
1383b51c079eSNicholas Piggin#ifdef CONFIG_ALTIVEC
1384b51c079eSNicholas PigginEXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
1385b51c079eSNicholas Piggin#else
1386b51c079eSNicholas PigginEXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
1387b51c079eSNicholas Piggin#endif
1388b51c079eSNicholas Piggin
1389d7e89849SNicholas Piggin
1390d7e89849SNicholas Piggin#ifdef CONFIG_CBE_RAS
13911a6822d1SNicholas PigginEXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
13921a6822d1SNicholas PigginEXC_VIRT_NONE(0x5800, 0x100)
1393d7e89849SNicholas PigginTRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
13943965f8abSNicholas PigginEXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
1395d7e89849SNicholas Piggin#else /* CONFIG_CBE_RAS */
13961a6822d1SNicholas PigginEXC_REAL_NONE(0x1800, 0x100)
13971a6822d1SNicholas PigginEXC_VIRT_NONE(0x5800, 0x100)
1398d7e89849SNicholas Piggin#endif
1399d7e89849SNicholas Piggin
140075eb767eSNicholas Piggin#ifdef CONFIG_PPC_WATCHDOG
14012104180aSNicholas Piggin
14022104180aSNicholas Piggin#define MASKED_DEC_HANDLER_LABEL 3f
14032104180aSNicholas Piggin
14042104180aSNicholas Piggin#define MASKED_DEC_HANDLER(_H)				\
14052104180aSNicholas Piggin3: /* soft-nmi */					\
14062104180aSNicholas Piggin	std	r12,PACA_EXGEN+EX_R12(r13);		\
14072104180aSNicholas Piggin	GET_SCRATCH0(r10);				\
14082104180aSNicholas Piggin	std	r10,PACA_EXGEN+EX_R13(r13);		\
1409cb58a4a4SMichael Ellerman	EXCEPTION_PROLOG_2(soft_nmi_common, _H)
14102104180aSNicholas Piggin
1411cc491f1dSNicholas Piggin/*
1412cc491f1dSNicholas Piggin * Branch to soft_nmi_interrupt using the emergency stack. The emergency
1413cc491f1dSNicholas Piggin * stack is one that is usable by maskable interrupts so long as MSR_EE
1414cc491f1dSNicholas Piggin * remains off. It is used for recovery when something has corrupted the
1415cc491f1dSNicholas Piggin * normal kernel stack, for example. The "soft NMI" must not use the process
1416cc491f1dSNicholas Piggin * stack because we want irq disabled sections to avoid touching the stack
1417cc491f1dSNicholas Piggin * at all (other than PMU interrupts), so use the emergency stack for this,
1418cc491f1dSNicholas Piggin * and run it entirely with interrupts hard disabled.
1419cc491f1dSNicholas Piggin */
14202104180aSNicholas PigginEXC_COMMON_BEGIN(soft_nmi_common)
14212104180aSNicholas Piggin	mr	r10,r1
14222104180aSNicholas Piggin	ld	r1,PACAEMERGSP(r13)
14232104180aSNicholas Piggin	subi	r1,r1,INT_FRAME_SIZE
14242104180aSNicholas Piggin	EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
14252104180aSNicholas Piggin			system_reset, soft_nmi_interrupt,
14262104180aSNicholas Piggin			ADD_NVGPRS;ADD_RECONCILE)
14272104180aSNicholas Piggin	b	ret_from_except
14282104180aSNicholas Piggin
142975eb767eSNicholas Piggin#else /* CONFIG_PPC_WATCHDOG */
14302104180aSNicholas Piggin#define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
14312104180aSNicholas Piggin#define MASKED_DEC_HANDLER(_H)
143275eb767eSNicholas Piggin#endif /* CONFIG_PPC_WATCHDOG */
1433d7e89849SNicholas Piggin
14340ebc4cdaSBenjamin Herrenschmidt/*
1435fe9e1d54SIan Munsie * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
1436fe9e1d54SIan Munsie * - If it was a decrementer interrupt, we bump the dec to max and and return.
1437fe9e1d54SIan Munsie * - If it was a doorbell we return immediately since doorbells are edge
1438fe9e1d54SIan Munsie *   triggered and won't automatically refire.
14390869b6fdSMahesh Salgaonkar * - If it was a HMI we return immediately since we handled it in realmode
14400869b6fdSMahesh Salgaonkar *   and it won't refire.
14416cc3f91bSNicholas Piggin * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
1442fe9e1d54SIan Munsie * This is called with r10 containing the value to OR to the paca field.
14430ebc4cdaSBenjamin Herrenschmidt */
14447230c564SBenjamin Herrenschmidt#define MASKED_INTERRUPT(_H)				\
14457230c564SBenjamin Herrenschmidtmasked_##_H##interrupt:					\
14467230c564SBenjamin Herrenschmidt	std	r11,PACA_EXGEN+EX_R11(r13);		\
14477230c564SBenjamin Herrenschmidt	lbz	r11,PACAIRQHAPPENED(r13);		\
14487230c564SBenjamin Herrenschmidt	or	r11,r11,r10;				\
14497230c564SBenjamin Herrenschmidt	stb	r11,PACAIRQHAPPENED(r13);		\
1450fe9e1d54SIan Munsie	cmpwi	r10,PACA_IRQ_DEC;			\
1451fe9e1d54SIan Munsie	bne	1f;					\
14527230c564SBenjamin Herrenschmidt	lis	r10,0x7fff;				\
14537230c564SBenjamin Herrenschmidt	ori	r10,r10,0xffff;				\
14547230c564SBenjamin Herrenschmidt	mtspr	SPRN_DEC,r10;				\
14552104180aSNicholas Piggin	b	MASKED_DEC_HANDLER_LABEL;		\
14566cc3f91bSNicholas Piggin1:	andi.	r10,r10,PACA_IRQ_MUST_HARD_MASK;	\
14576cc3f91bSNicholas Piggin	beq	2f;					\
1458fe9e1d54SIan Munsie	mfspr	r10,SPRN_##_H##SRR1;			\
14596e9a2f6eSNicholas Piggin	xori	r10,r10,MSR_EE; /* clear MSR_EE */	\
14607230c564SBenjamin Herrenschmidt	mtspr	SPRN_##_H##SRR1,r10;			\
14619b81c021SNicholas Piggin	ori	r11,r11,PACA_IRQ_HARD_DIS;		\
14629b81c021SNicholas Piggin	stb	r11,PACAIRQHAPPENED(r13);		\
14639b81c021SNicholas Piggin2:	/* done */					\
14649b81c021SNicholas Piggin	mtcrf	0x80,r9;				\
14657b08729cSMichael Ellerman	std	r1,PACAR1(r13);				\
14667230c564SBenjamin Herrenschmidt	ld	r9,PACA_EXGEN+EX_R9(r13);		\
14677230c564SBenjamin Herrenschmidt	ld	r10,PACA_EXGEN+EX_R10(r13);		\
14687230c564SBenjamin Herrenschmidt	ld	r11,PACA_EXGEN+EX_R11(r13);		\
1469c05f0be8SNicholas Piggin	/* returns to kernel where r13 must be set up, so don't restore it */ \
1470222f20f1SNicholas Piggin	##_H##RFI_TO_KERNEL;				\
14712104180aSNicholas Piggin	b	.;					\
14722104180aSNicholas Piggin	MASKED_DEC_HANDLER(_H)
14730ebc4cdaSBenjamin Herrenschmidt
1474a048a07dSNicholas PigginTRAMP_REAL_BEGIN(stf_barrier_fallback)
1475a048a07dSNicholas Piggin	std	r9,PACA_EXRFI+EX_R9(r13)
1476a048a07dSNicholas Piggin	std	r10,PACA_EXRFI+EX_R10(r13)
1477a048a07dSNicholas Piggin	sync
1478a048a07dSNicholas Piggin	ld	r9,PACA_EXRFI+EX_R9(r13)
1479a048a07dSNicholas Piggin	ld	r10,PACA_EXRFI+EX_R10(r13)
1480a048a07dSNicholas Piggin	ori	31,31,0
1481a048a07dSNicholas Piggin	.rept 14
1482a048a07dSNicholas Piggin	b	1f
1483a048a07dSNicholas Piggin1:
1484a048a07dSNicholas Piggin	.endr
1485a048a07dSNicholas Piggin	blr
1486a048a07dSNicholas Piggin
1487aa8a5e00SMichael EllermanTRAMP_REAL_BEGIN(rfi_flush_fallback)
1488aa8a5e00SMichael Ellerman	SET_SCRATCH0(r13);
1489aa8a5e00SMichael Ellerman	GET_PACA(r13);
149078ee9946SMichael Ellerman	std	r1,PACA_EXRFI+EX_R12(r13)
149178ee9946SMichael Ellerman	ld	r1,PACAKSAVE(r13)
1492aa8a5e00SMichael Ellerman	std	r9,PACA_EXRFI+EX_R9(r13)
1493aa8a5e00SMichael Ellerman	std	r10,PACA_EXRFI+EX_R10(r13)
1494aa8a5e00SMichael Ellerman	std	r11,PACA_EXRFI+EX_R11(r13)
1495aa8a5e00SMichael Ellerman	mfctr	r9
1496aa8a5e00SMichael Ellerman	ld	r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
1497bdcb1aefSNicholas Piggin	ld	r11,PACA_L1D_FLUSH_SIZE(r13)
1498bdcb1aefSNicholas Piggin	srdi	r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
1499aa8a5e00SMichael Ellerman	mtctr	r11
150015a3204dSNicholas Piggin	DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1501aa8a5e00SMichael Ellerman
1502aa8a5e00SMichael Ellerman	/* order ld/st prior to dcbt stop all streams with flushing */
1503aa8a5e00SMichael Ellerman	sync
1504bdcb1aefSNicholas Piggin
1505bdcb1aefSNicholas Piggin	/*
1506bdcb1aefSNicholas Piggin	 * The load adresses are at staggered offsets within cachelines,
1507bdcb1aefSNicholas Piggin	 * which suits some pipelines better (on others it should not
1508bdcb1aefSNicholas Piggin	 * hurt).
1509bdcb1aefSNicholas Piggin	 */
1510bdcb1aefSNicholas Piggin1:
1511bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*0(r10)
1512bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*1(r10)
1513bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*2(r10)
1514bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*3(r10)
1515bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*4(r10)
1516bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*5(r10)
1517bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*6(r10)
1518bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*7(r10)
1519bdcb1aefSNicholas Piggin	addi	r10,r10,0x80*8
1520aa8a5e00SMichael Ellerman	bdnz	1b
1521aa8a5e00SMichael Ellerman
1522aa8a5e00SMichael Ellerman	mtctr	r9
1523aa8a5e00SMichael Ellerman	ld	r9,PACA_EXRFI+EX_R9(r13)
1524aa8a5e00SMichael Ellerman	ld	r10,PACA_EXRFI+EX_R10(r13)
1525aa8a5e00SMichael Ellerman	ld	r11,PACA_EXRFI+EX_R11(r13)
152678ee9946SMichael Ellerman	ld	r1,PACA_EXRFI+EX_R12(r13)
1527aa8a5e00SMichael Ellerman	GET_SCRATCH0(r13);
1528aa8a5e00SMichael Ellerman	rfid
1529aa8a5e00SMichael Ellerman
1530aa8a5e00SMichael EllermanTRAMP_REAL_BEGIN(hrfi_flush_fallback)
1531aa8a5e00SMichael Ellerman	SET_SCRATCH0(r13);
1532aa8a5e00SMichael Ellerman	GET_PACA(r13);
153378ee9946SMichael Ellerman	std	r1,PACA_EXRFI+EX_R12(r13)
153478ee9946SMichael Ellerman	ld	r1,PACAKSAVE(r13)
1535aa8a5e00SMichael Ellerman	std	r9,PACA_EXRFI+EX_R9(r13)
1536aa8a5e00SMichael Ellerman	std	r10,PACA_EXRFI+EX_R10(r13)
1537aa8a5e00SMichael Ellerman	std	r11,PACA_EXRFI+EX_R11(r13)
1538aa8a5e00SMichael Ellerman	mfctr	r9
1539aa8a5e00SMichael Ellerman	ld	r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
1540bdcb1aefSNicholas Piggin	ld	r11,PACA_L1D_FLUSH_SIZE(r13)
1541bdcb1aefSNicholas Piggin	srdi	r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
1542aa8a5e00SMichael Ellerman	mtctr	r11
154315a3204dSNicholas Piggin	DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1544aa8a5e00SMichael Ellerman
1545aa8a5e00SMichael Ellerman	/* order ld/st prior to dcbt stop all streams with flushing */
1546aa8a5e00SMichael Ellerman	sync
1547bdcb1aefSNicholas Piggin
1548bdcb1aefSNicholas Piggin	/*
1549bdcb1aefSNicholas Piggin	 * The load adresses are at staggered offsets within cachelines,
1550bdcb1aefSNicholas Piggin	 * which suits some pipelines better (on others it should not
1551bdcb1aefSNicholas Piggin	 * hurt).
1552bdcb1aefSNicholas Piggin	 */
1553bdcb1aefSNicholas Piggin1:
1554bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*0(r10)
1555bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*1(r10)
1556bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*2(r10)
1557bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*3(r10)
1558bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*4(r10)
1559bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*5(r10)
1560bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*6(r10)
1561bdcb1aefSNicholas Piggin	ld	r11,(0x80 + 8)*7(r10)
1562bdcb1aefSNicholas Piggin	addi	r10,r10,0x80*8
1563aa8a5e00SMichael Ellerman	bdnz	1b
1564aa8a5e00SMichael Ellerman
1565aa8a5e00SMichael Ellerman	mtctr	r9
1566aa8a5e00SMichael Ellerman	ld	r9,PACA_EXRFI+EX_R9(r13)
1567aa8a5e00SMichael Ellerman	ld	r10,PACA_EXRFI+EX_R10(r13)
1568aa8a5e00SMichael Ellerman	ld	r11,PACA_EXRFI+EX_R11(r13)
156978ee9946SMichael Ellerman	ld	r1,PACA_EXRFI+EX_R12(r13)
1570aa8a5e00SMichael Ellerman	GET_SCRATCH0(r13);
1571aa8a5e00SMichael Ellerman	hrfid
1572aa8a5e00SMichael Ellerman
157357f26649SNicholas Piggin/*
157457f26649SNicholas Piggin * Real mode exceptions actually use this too, but alternate
157557f26649SNicholas Piggin * instruction code patches (which end up in the common .text area)
157657f26649SNicholas Piggin * cannot reach these if they are put there.
157757f26649SNicholas Piggin */
157857f26649SNicholas PigginUSE_FIXED_SECTION(virt_trampolines)
15797230c564SBenjamin Herrenschmidt	MASKED_INTERRUPT()
15807230c564SBenjamin Herrenschmidt	MASKED_INTERRUPT(H)
15817230c564SBenjamin Herrenschmidt
15824f6c11dbSPaul Mackerras#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1583da2bc464SMichael EllermanTRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
15844f6c11dbSPaul Mackerras	/*
15854f6c11dbSPaul Mackerras	 * Here all GPRs are unchanged from when the interrupt happened
15864f6c11dbSPaul Mackerras	 * except for r13, which is saved in SPRG_SCRATCH0.
15874f6c11dbSPaul Mackerras	 */
15884f6c11dbSPaul Mackerras	mfspr	r13, SPRN_SRR0
15894f6c11dbSPaul Mackerras	addi	r13, r13, 4
15904f6c11dbSPaul Mackerras	mtspr	SPRN_SRR0, r13
15914f6c11dbSPaul Mackerras	GET_SCRATCH0(r13)
1592222f20f1SNicholas Piggin	RFI_TO_KERNEL
15934f6c11dbSPaul Mackerras	b	.
15944f6c11dbSPaul Mackerras
1595da2bc464SMichael EllermanTRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
15964f6c11dbSPaul Mackerras	/*
15974f6c11dbSPaul Mackerras	 * Here all GPRs are unchanged from when the interrupt happened
15984f6c11dbSPaul Mackerras	 * except for r13, which is saved in SPRG_SCRATCH0.
15994f6c11dbSPaul Mackerras	 */
16004f6c11dbSPaul Mackerras	mfspr	r13, SPRN_HSRR0
16014f6c11dbSPaul Mackerras	addi	r13, r13, 4
16024f6c11dbSPaul Mackerras	mtspr	SPRN_HSRR0, r13
16034f6c11dbSPaul Mackerras	GET_SCRATCH0(r13)
1604222f20f1SNicholas Piggin	HRFI_TO_KERNEL
16054f6c11dbSPaul Mackerras	b	.
16064f6c11dbSPaul Mackerras#endif
16074f6c11dbSPaul Mackerras
16080ebc4cdaSBenjamin Herrenschmidt/*
1609057b6d7eSHari Bathini * Ensure that any handlers that get invoked from the exception prologs
1610057b6d7eSHari Bathini * above are below the first 64KB (0x10000) of the kernel image because
1611057b6d7eSHari Bathini * the prologs assemble the addresses of these handlers using the
1612057b6d7eSHari Bathini * LOAD_HANDLER macro, which uses an ori instruction.
16130ebc4cdaSBenjamin Herrenschmidt */
16140ebc4cdaSBenjamin Herrenschmidt
16150ebc4cdaSBenjamin Herrenschmidt/*** Common interrupt handlers ***/
16160ebc4cdaSBenjamin Herrenschmidt
16170ebc4cdaSBenjamin Herrenschmidt
1618c1fb6816SMichael Neuling	/*
1619c1fb6816SMichael Neuling	 * Relocation-on interrupts: A subset of the interrupts can be delivered
1620c1fb6816SMichael Neuling	 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
1621c1fb6816SMichael Neuling	 * it.  Addresses are the same as the original interrupt addresses, but
1622c1fb6816SMichael Neuling	 * offset by 0xc000000000004000.
1623c1fb6816SMichael Neuling	 * It's impossible to receive interrupts below 0x300 via this mechanism.
1624c1fb6816SMichael Neuling	 * KVM: None of these traps are from the guest ; anything that escalated
1625c1fb6816SMichael Neuling	 * to HV=1 from HV=0 is delivered via real mode handlers.
1626c1fb6816SMichael Neuling	 */
1627c1fb6816SMichael Neuling
1628c1fb6816SMichael Neuling	/*
1629c1fb6816SMichael Neuling	 * This uses the standard macro, since the original 0x300 vector
1630c1fb6816SMichael Neuling	 * only has extra guff for STAB-based processors -- which never
1631c1fb6816SMichael Neuling	 * come here.
1632c1fb6816SMichael Neuling	 */
1633da2bc464SMichael Ellerman
163457f26649SNicholas PigginEXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
1635b1576fecSAnton Blanchard	b	__ppc64_runlatch_on
1636fe1952fcSBenjamin Herrenschmidt
163757f26649SNicholas PigginUSE_FIXED_SECTION(virt_trampolines)
16388ed8ab40SHari Bathini	/*
16398ed8ab40SHari Bathini	 * The __end_interrupts marker must be past the out-of-line (OOL)
16408ed8ab40SHari Bathini	 * handlers, so that they are copied to real address 0x100 when running
16418ed8ab40SHari Bathini	 * a relocatable kernel. This ensures they can be reached from the short
16428ed8ab40SHari Bathini	 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
16438ed8ab40SHari Bathini	 * directly, without using LOAD_HANDLER().
16448ed8ab40SHari Bathini	 */
16458ed8ab40SHari Bathini	.align	7
16468ed8ab40SHari Bathini	.globl	__end_interrupts
16478ed8ab40SHari Bathini__end_interrupts:
164857f26649SNicholas PigginDEFINE_FIXED_SYMBOL(__end_interrupts)
164961383407SBenjamin Herrenschmidt
1650087aa036SChen Gang#ifdef CONFIG_PPC_970_NAP
16517c8cb4b5SNicholas PigginEXC_COMMON_BEGIN(power4_fixup_nap)
1652087aa036SChen Gang	andc	r9,r9,r10
1653087aa036SChen Gang	std	r9,TI_LOCAL_FLAGS(r11)
1654087aa036SChen Gang	ld	r10,_LINK(r1)		/* make idle task do the */
1655087aa036SChen Gang	std	r10,_NIP(r1)		/* equivalent of a blr */
1656087aa036SChen Gang	blr
1657087aa036SChen Gang#endif
1658087aa036SChen Gang
165957f26649SNicholas PigginCLOSE_FIXED_SECTION(real_vectors);
166057f26649SNicholas PigginCLOSE_FIXED_SECTION(real_trampolines);
166157f26649SNicholas PigginCLOSE_FIXED_SECTION(virt_vectors);
166257f26649SNicholas PigginCLOSE_FIXED_SECTION(virt_trampolines);
166357f26649SNicholas Piggin
166457f26649SNicholas PigginUSE_TEXT_SECTION()
166557f26649SNicholas Piggin
1666087aa036SChen Gang/*
16670ebc4cdaSBenjamin Herrenschmidt * Hash table stuff
16680ebc4cdaSBenjamin Herrenschmidt */
1669f4329f2eSNicholas Piggin	.balign	IFETCH_ALIGN_BYTES
16706a3bab90SAnton Blancharddo_hash_page:
16714e003747SMichael Ellerman#ifdef CONFIG_PPC_BOOK3S_64
1672e6c2a479SRam Pai	lis	r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h
1673398a719dSBenjamin Herrenschmidt	ori	r0,r0,DSISR_BAD_FAULT_64S@l
1674398a719dSBenjamin Herrenschmidt	and.	r0,r4,r0		/* weird error? */
16750ebc4cdaSBenjamin Herrenschmidt	bne-	handle_page_fault	/* if not, try to insert a HPTE */
1676c911d2e1SChristophe Leroy	ld	r11, PACA_THREAD_INFO(r13)
16779c1e1052SPaul Mackerras	lwz	r0,TI_PREEMPT(r11)	/* If we're in an "NMI" */
16789c1e1052SPaul Mackerras	andis.	r0,r0,NMI_MASK@h	/* (i.e. an irq when soft-disabled) */
16799c1e1052SPaul Mackerras	bne	77f			/* then don't call hash_page now */
16800ebc4cdaSBenjamin Herrenschmidt
16810ebc4cdaSBenjamin Herrenschmidt	/*
16820ebc4cdaSBenjamin Herrenschmidt	 * r3 contains the faulting address
1683106713a1SAneesh Kumar K.V	 * r4 msr
16840ebc4cdaSBenjamin Herrenschmidt	 * r5 contains the trap number
1685aefa5688SAneesh Kumar K.V	 * r6 contains dsisr
16860ebc4cdaSBenjamin Herrenschmidt	 *
16877230c564SBenjamin Herrenschmidt	 * at return r3 = 0 for success, 1 for page fault, negative for error
16880ebc4cdaSBenjamin Herrenschmidt	 */
1689106713a1SAneesh Kumar K.V        mr 	r4,r12
1690aefa5688SAneesh Kumar K.V	ld      r6,_DSISR(r1)
1691106713a1SAneesh Kumar K.V	bl	__hash_page		/* build HPTE if possible */
1692106713a1SAneesh Kumar K.V        cmpdi	r3,0			/* see if __hash_page succeeded */
16930ebc4cdaSBenjamin Herrenschmidt
16947230c564SBenjamin Herrenschmidt	/* Success */
16950ebc4cdaSBenjamin Herrenschmidt	beq	fast_exc_return_irq	/* Return from exception on success */
16960ebc4cdaSBenjamin Herrenschmidt
16977230c564SBenjamin Herrenschmidt	/* Error */
16987230c564SBenjamin Herrenschmidt	blt-	13f
1699d89ba535SNaveen N. Rao
1700d89ba535SNaveen N. Rao	/* Reload DSISR into r4 for the DABR check below */
1701d89ba535SNaveen N. Rao	ld      r4,_DSISR(r1)
17024e003747SMichael Ellerman#endif /* CONFIG_PPC_BOOK3S_64 */
17030ebc4cdaSBenjamin Herrenschmidt
1704a546498fSBenjamin Herrenschmidt/* Here we have a page fault that hash_page can't handle. */
1705a546498fSBenjamin Herrenschmidthandle_page_fault:
1706d89ba535SNaveen N. Rao11:	andis.  r0,r4,DSISR_DABRMATCH@h
1707d89ba535SNaveen N. Rao	bne-    handle_dabr_fault
1708d89ba535SNaveen N. Rao	ld	r4,_DAR(r1)
1709a546498fSBenjamin Herrenschmidt	ld	r5,_DSISR(r1)
1710a546498fSBenjamin Herrenschmidt	addi	r3,r1,STACK_FRAME_OVERHEAD
1711b1576fecSAnton Blanchard	bl	do_page_fault
1712a546498fSBenjamin Herrenschmidt	cmpdi	r3,0
1713a546498fSBenjamin Herrenschmidt	beq+	12f
1714b1576fecSAnton Blanchard	bl	save_nvgprs
1715a546498fSBenjamin Herrenschmidt	mr	r5,r3
1716a546498fSBenjamin Herrenschmidt	addi	r3,r1,STACK_FRAME_OVERHEAD
1717a546498fSBenjamin Herrenschmidt	lwz	r4,_DAR(r1)
1718b1576fecSAnton Blanchard	bl	bad_page_fault
1719b1576fecSAnton Blanchard	b	ret_from_except
17200ebc4cdaSBenjamin Herrenschmidt
17219c7cc234SK.Prasad/* We have a data breakpoint exception - handle it */
17229c7cc234SK.Prasadhandle_dabr_fault:
1723b1576fecSAnton Blanchard	bl	save_nvgprs
17249c7cc234SK.Prasad	ld      r4,_DAR(r1)
17259c7cc234SK.Prasad	ld      r5,_DSISR(r1)
17269c7cc234SK.Prasad	addi    r3,r1,STACK_FRAME_OVERHEAD
1727b1576fecSAnton Blanchard	bl      do_break
1728b1576fecSAnton Blanchard12:	b       ret_from_except_lite
17299c7cc234SK.Prasad
17300ebc4cdaSBenjamin Herrenschmidt
17314e003747SMichael Ellerman#ifdef CONFIG_PPC_BOOK3S_64
17320ebc4cdaSBenjamin Herrenschmidt/* We have a page fault that hash_page could handle but HV refused
17330ebc4cdaSBenjamin Herrenschmidt * the PTE insertion
17340ebc4cdaSBenjamin Herrenschmidt */
1735b1576fecSAnton Blanchard13:	bl	save_nvgprs
17360ebc4cdaSBenjamin Herrenschmidt	mr	r5,r3
17370ebc4cdaSBenjamin Herrenschmidt	addi	r3,r1,STACK_FRAME_OVERHEAD
17380ebc4cdaSBenjamin Herrenschmidt	ld	r4,_DAR(r1)
1739b1576fecSAnton Blanchard	bl	low_hash_fault
1740b1576fecSAnton Blanchard	b	ret_from_except
1741caca285eSAneesh Kumar K.V#endif
17420ebc4cdaSBenjamin Herrenschmidt
17439c1e1052SPaul Mackerras/*
17449c1e1052SPaul Mackerras * We come here as a result of a DSI at a point where we don't want
17459c1e1052SPaul Mackerras * to call hash_page, such as when we are accessing memory (possibly
17469c1e1052SPaul Mackerras * user memory) inside a PMU interrupt that occurred while interrupts
17479c1e1052SPaul Mackerras * were soft-disabled.  We want to invoke the exception handler for
17489c1e1052SPaul Mackerras * the access, or panic if there isn't a handler.
17499c1e1052SPaul Mackerras */
1750b1576fecSAnton Blanchard77:	bl	save_nvgprs
17519c1e1052SPaul Mackerras	mr	r4,r3
17529c1e1052SPaul Mackerras	addi	r3,r1,STACK_FRAME_OVERHEAD
17539c1e1052SPaul Mackerras	li	r5,SIGSEGV
1754b1576fecSAnton Blanchard	bl	bad_page_fault
1755b1576fecSAnton Blanchard	b	ret_from_except
17564e2bf01bSMichael Ellerman
17574e2bf01bSMichael Ellerman/*
17584e2bf01bSMichael Ellerman * Here we have detected that the kernel stack pointer is bad.
17594e2bf01bSMichael Ellerman * R9 contains the saved CR, r13 points to the paca,
17604e2bf01bSMichael Ellerman * r10 contains the (bad) kernel stack pointer,
17614e2bf01bSMichael Ellerman * r11 and r12 contain the saved SRR0 and SRR1.
17624e2bf01bSMichael Ellerman * We switch to using an emergency stack, save the registers there,
17634e2bf01bSMichael Ellerman * and call kernel_bad_stack(), which panics.
17644e2bf01bSMichael Ellerman */
17654e2bf01bSMichael Ellermanbad_stack:
17664e2bf01bSMichael Ellerman	ld	r1,PACAEMERGSP(r13)
17674e2bf01bSMichael Ellerman	subi	r1,r1,64+INT_FRAME_SIZE
17684e2bf01bSMichael Ellerman	std	r9,_CCR(r1)
17694e2bf01bSMichael Ellerman	std	r10,GPR1(r1)
17704e2bf01bSMichael Ellerman	std	r11,_NIP(r1)
17714e2bf01bSMichael Ellerman	std	r12,_MSR(r1)
17724e2bf01bSMichael Ellerman	mfspr	r11,SPRN_DAR
17734e2bf01bSMichael Ellerman	mfspr	r12,SPRN_DSISR
17744e2bf01bSMichael Ellerman	std	r11,_DAR(r1)
17754e2bf01bSMichael Ellerman	std	r12,_DSISR(r1)
17764e2bf01bSMichael Ellerman	mflr	r10
17774e2bf01bSMichael Ellerman	mfctr	r11
17784e2bf01bSMichael Ellerman	mfxer	r12
17794e2bf01bSMichael Ellerman	std	r10,_LINK(r1)
17804e2bf01bSMichael Ellerman	std	r11,_CTR(r1)
17814e2bf01bSMichael Ellerman	std	r12,_XER(r1)
17824e2bf01bSMichael Ellerman	SAVE_GPR(0,r1)
17834e2bf01bSMichael Ellerman	SAVE_GPR(2,r1)
17844e2bf01bSMichael Ellerman	ld	r10,EX_R3(r3)
17854e2bf01bSMichael Ellerman	std	r10,GPR3(r1)
17864e2bf01bSMichael Ellerman	SAVE_GPR(4,r1)
17874e2bf01bSMichael Ellerman	SAVE_4GPRS(5,r1)
17884e2bf01bSMichael Ellerman	ld	r9,EX_R9(r3)
17894e2bf01bSMichael Ellerman	ld	r10,EX_R10(r3)
17904e2bf01bSMichael Ellerman	SAVE_2GPRS(9,r1)
17914e2bf01bSMichael Ellerman	ld	r9,EX_R11(r3)
17924e2bf01bSMichael Ellerman	ld	r10,EX_R12(r3)
17934e2bf01bSMichael Ellerman	ld	r11,EX_R13(r3)
17944e2bf01bSMichael Ellerman	std	r9,GPR11(r1)
17954e2bf01bSMichael Ellerman	std	r10,GPR12(r1)
17964e2bf01bSMichael Ellerman	std	r11,GPR13(r1)
17974e2bf01bSMichael EllermanBEGIN_FTR_SECTION
17984e2bf01bSMichael Ellerman	ld	r10,EX_CFAR(r3)
17994e2bf01bSMichael Ellerman	std	r10,ORIG_GPR3(r1)
18004e2bf01bSMichael EllermanEND_FTR_SECTION_IFSET(CPU_FTR_CFAR)
18014e2bf01bSMichael Ellerman	SAVE_8GPRS(14,r1)
18024e2bf01bSMichael Ellerman	SAVE_10GPRS(22,r1)
18034e2bf01bSMichael Ellerman	lhz	r12,PACA_TRAP_SAVE(r13)
18044e2bf01bSMichael Ellerman	std	r12,_TRAP(r1)
18054e2bf01bSMichael Ellerman	addi	r11,r1,INT_FRAME_SIZE
18064e2bf01bSMichael Ellerman	std	r11,0(r1)
18074e2bf01bSMichael Ellerman	li	r12,0
18084e2bf01bSMichael Ellerman	std	r12,0(r11)
18094e2bf01bSMichael Ellerman	ld	r2,PACATOC(r13)
18104e2bf01bSMichael Ellerman	ld	r11,exception_marker@toc(r2)
18114e2bf01bSMichael Ellerman	std	r12,RESULT(r1)
18124e2bf01bSMichael Ellerman	std	r11,STACK_FRAME_OVERHEAD-16(r1)
18134e2bf01bSMichael Ellerman1:	addi	r3,r1,STACK_FRAME_OVERHEAD
18144e2bf01bSMichael Ellerman	bl	kernel_bad_stack
18154e2bf01bSMichael Ellerman	b	1b
181615770a13SNaveen N. Rao_ASM_NOKPROBE_SYMBOL(bad_stack);
18170f0c6ca1SNicholas Piggin
18180f0c6ca1SNicholas Piggin/*
1819a9af97aaSNicholas Piggin * When doorbell is triggered from system reset wakeup, the message is
1820a9af97aaSNicholas Piggin * not cleared, so it would fire again when EE is enabled.
1821a9af97aaSNicholas Piggin *
1822a9af97aaSNicholas Piggin * When coming from local_irq_enable, there may be the same problem if
1823a9af97aaSNicholas Piggin * we were hard disabled.
1824a9af97aaSNicholas Piggin *
1825a9af97aaSNicholas Piggin * Execute msgclr to clear pending exceptions before handling it.
1826a9af97aaSNicholas Piggin */
1827a9af97aaSNicholas Pigginh_doorbell_common_msgclr:
1828a9af97aaSNicholas Piggin	LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1829a9af97aaSNicholas Piggin	PPC_MSGCLR(3)
1830a9af97aaSNicholas Piggin	b 	h_doorbell_common
1831a9af97aaSNicholas Piggin
1832a9af97aaSNicholas Piggindoorbell_super_common_msgclr:
1833a9af97aaSNicholas Piggin	LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1834a9af97aaSNicholas Piggin	PPC_MSGCLRP(3)
1835a9af97aaSNicholas Piggin	b 	doorbell_super_common
1836a9af97aaSNicholas Piggin
1837a9af97aaSNicholas Piggin/*
18380f0c6ca1SNicholas Piggin * Called from arch_local_irq_enable when an interrupt needs
18390f0c6ca1SNicholas Piggin * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
18400f0c6ca1SNicholas Piggin * which kind of interrupt. MSR:EE is already off. We generate a
18410f0c6ca1SNicholas Piggin * stackframe like if a real interrupt had happened.
18420f0c6ca1SNicholas Piggin *
18430f0c6ca1SNicholas Piggin * Note: While MSR:EE is off, we need to make sure that _MSR
18440f0c6ca1SNicholas Piggin * in the generated frame has EE set to 1 or the exception
18450f0c6ca1SNicholas Piggin * handler will not properly re-enable them.
1846b48bbb82SNicholas Piggin *
1847b48bbb82SNicholas Piggin * Note that we don't specify LR as the NIP (return address) for
1848b48bbb82SNicholas Piggin * the interrupt because that would unbalance the return branch
1849b48bbb82SNicholas Piggin * predictor.
18500f0c6ca1SNicholas Piggin */
18510f0c6ca1SNicholas Piggin_GLOBAL(__replay_interrupt)
18520f0c6ca1SNicholas Piggin	/* We are going to jump to the exception common code which
18530f0c6ca1SNicholas Piggin	 * will retrieve various register values from the PACA which
18540f0c6ca1SNicholas Piggin	 * we don't give a damn about, so we don't bother storing them.
18550f0c6ca1SNicholas Piggin	 */
18560f0c6ca1SNicholas Piggin	mfmsr	r12
18573e23a12bSMichael Ellerman	LOAD_REG_ADDR(r11, replay_interrupt_return)
18580f0c6ca1SNicholas Piggin	mfcr	r9
18590f0c6ca1SNicholas Piggin	ori	r12,r12,MSR_EE
18600f0c6ca1SNicholas Piggin	cmpwi	r3,0x900
18610f0c6ca1SNicholas Piggin	beq	decrementer_common
18620f0c6ca1SNicholas Piggin	cmpwi	r3,0x500
1863e6c1203dSNicholas PigginBEGIN_FTR_SECTION
1864e6c1203dSNicholas Piggin	beq	h_virt_irq_common
1865e6c1203dSNicholas PigginFTR_SECTION_ELSE
18660f0c6ca1SNicholas Piggin	beq	hardware_interrupt_common
1867e6c1203dSNicholas PigginALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
1868f442d004SMadhavan Srinivasan	cmpwi	r3,0xf00
1869f442d004SMadhavan Srinivasan	beq	performance_monitor_common
18700f0c6ca1SNicholas PigginBEGIN_FTR_SECTION
1871d6f73fc6SNicholas Piggin	cmpwi	r3,0xa00
1872a9af97aaSNicholas Piggin	beq	h_doorbell_common_msgclr
18730f0c6ca1SNicholas Piggin	cmpwi	r3,0xe60
18740f0c6ca1SNicholas Piggin	beq	hmi_exception_common
18750f0c6ca1SNicholas PigginFTR_SECTION_ELSE
18760f0c6ca1SNicholas Piggin	cmpwi	r3,0xa00
1877a9af97aaSNicholas Piggin	beq	doorbell_super_common_msgclr
18780f0c6ca1SNicholas PigginALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
18793e23a12bSMichael Ellermanreplay_interrupt_return:
18800f0c6ca1SNicholas Piggin	blr
1881b48bbb82SNicholas Piggin
188215770a13SNaveen N. Rao_ASM_NOKPROBE_SYMBOL(__replay_interrupt)
1883