18aa34ab8SBenjamin Herrenschmidt #ifndef _ASM_POWERPC_EXCEPTION_H
28aa34ab8SBenjamin Herrenschmidt #define _ASM_POWERPC_EXCEPTION_H
38aa34ab8SBenjamin Herrenschmidt /*
48aa34ab8SBenjamin Herrenschmidt  * Extracted from head_64.S
58aa34ab8SBenjamin Herrenschmidt  *
68aa34ab8SBenjamin Herrenschmidt  *  PowerPC version
78aa34ab8SBenjamin Herrenschmidt  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
88aa34ab8SBenjamin Herrenschmidt  *
98aa34ab8SBenjamin Herrenschmidt  *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
108aa34ab8SBenjamin Herrenschmidt  *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
118aa34ab8SBenjamin Herrenschmidt  *  Adapted for Power Macintosh by Paul Mackerras.
128aa34ab8SBenjamin Herrenschmidt  *  Low-level exception handlers and MMU support
138aa34ab8SBenjamin Herrenschmidt  *  rewritten by Paul Mackerras.
148aa34ab8SBenjamin Herrenschmidt  *    Copyright (C) 1996 Paul Mackerras.
158aa34ab8SBenjamin Herrenschmidt  *
168aa34ab8SBenjamin Herrenschmidt  *  Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
178aa34ab8SBenjamin Herrenschmidt  *    Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
188aa34ab8SBenjamin Herrenschmidt  *
198aa34ab8SBenjamin Herrenschmidt  *  This file contains the low-level support and setup for the
208aa34ab8SBenjamin Herrenschmidt  *  PowerPC-64 platform, including trap and interrupt dispatch.
218aa34ab8SBenjamin Herrenschmidt  *
228aa34ab8SBenjamin Herrenschmidt  *  This program is free software; you can redistribute it and/or
238aa34ab8SBenjamin Herrenschmidt  *  modify it under the terms of the GNU General Public License
248aa34ab8SBenjamin Herrenschmidt  *  as published by the Free Software Foundation; either version
258aa34ab8SBenjamin Herrenschmidt  *  2 of the License, or (at your option) any later version.
268aa34ab8SBenjamin Herrenschmidt  */
278aa34ab8SBenjamin Herrenschmidt /*
288aa34ab8SBenjamin Herrenschmidt  * The following macros define the code that appears as
298aa34ab8SBenjamin Herrenschmidt  * the prologue to each of the exception handlers.  They
308aa34ab8SBenjamin Herrenschmidt  * are split into two parts to allow a single kernel binary
318aa34ab8SBenjamin Herrenschmidt  * to be used for pSeries and iSeries.
328aa34ab8SBenjamin Herrenschmidt  *
338aa34ab8SBenjamin Herrenschmidt  * We make as much of the exception code common between native
348aa34ab8SBenjamin Herrenschmidt  * exception handlers (including pSeries LPAR) and iSeries LPAR
358aa34ab8SBenjamin Herrenschmidt  * implementations as possible.
368aa34ab8SBenjamin Herrenschmidt  */
378aa34ab8SBenjamin Herrenschmidt 
388aa34ab8SBenjamin Herrenschmidt #define EX_R9		0
398aa34ab8SBenjamin Herrenschmidt #define EX_R10		8
408aa34ab8SBenjamin Herrenschmidt #define EX_R11		16
418aa34ab8SBenjamin Herrenschmidt #define EX_R12		24
428aa34ab8SBenjamin Herrenschmidt #define EX_R13		32
438aa34ab8SBenjamin Herrenschmidt #define EX_SRR0		40
448aa34ab8SBenjamin Herrenschmidt #define EX_DAR		48
458aa34ab8SBenjamin Herrenschmidt #define EX_DSISR	56
468aa34ab8SBenjamin Herrenschmidt #define EX_CCR		60
478aa34ab8SBenjamin Herrenschmidt #define EX_R3		64
488aa34ab8SBenjamin Herrenschmidt #define EX_LR		72
4948404f2eSPaul Mackerras #define EX_CFAR		80
508aa34ab8SBenjamin Herrenschmidt 
518aa34ab8SBenjamin Herrenschmidt /*
528aa34ab8SBenjamin Herrenschmidt  * We're short on space and time in the exception prolog, so we can't
538aa34ab8SBenjamin Herrenschmidt  * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
548aa34ab8SBenjamin Herrenschmidt  * low halfword of the address, but for Kdump we need the whole low
558aa34ab8SBenjamin Herrenschmidt  * word.
568aa34ab8SBenjamin Herrenschmidt  */
578aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label)					\
5861e2390eSMichael Neuling 	/* Handlers must be within 64K of kbase, which must be 64k aligned */ \
5961e2390eSMichael Neuling 	ori	reg,reg,(label)-_stext;	/* virt addr of handler ... */
608aa34ab8SBenjamin Herrenschmidt 
61a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */
62a5d4f3adSBenjamin Herrenschmidt #define EXC_HV	H
63a5d4f3adSBenjamin Herrenschmidt #define EXC_STD
64a5d4f3adSBenjamin Herrenschmidt 
65b01c8b54SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec)				\
662dd60d79SBenjamin Herrenschmidt 	GET_PACA(r13);							\
678aa34ab8SBenjamin Herrenschmidt 	std	r9,area+EX_R9(r13);	/* save r9 - r12 */		\
688aa34ab8SBenjamin Herrenschmidt 	std	r10,area+EX_R10(r13);					\
6948404f2eSPaul Mackerras 	BEGIN_FTR_SECTION_NESTED(66);					\
7048404f2eSPaul Mackerras 	mfspr	r10,SPRN_CFAR;						\
7148404f2eSPaul Mackerras 	std	r10,area+EX_CFAR(r13);					\
7248404f2eSPaul Mackerras 	END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);		\
73b01c8b54SPaul Mackerras 	mfcr	r9;							\
74b01c8b54SPaul Mackerras 	extra(vec);							\
75b01c8b54SPaul Mackerras 	std	r11,area+EX_R11(r13);					\
76b01c8b54SPaul Mackerras 	std	r12,area+EX_R12(r13);					\
77b01c8b54SPaul Mackerras 	GET_SCRATCH0(r10);						\
78b01c8b54SPaul Mackerras 	std	r10,area+EX_R13(r13)
79b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec)				\
80b01c8b54SPaul Mackerras 	__EXCEPTION_PROLOG_1(area, extra, vec)
818aa34ab8SBenjamin Herrenschmidt 
82a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h)				\
838aa34ab8SBenjamin Herrenschmidt 	ld	r12,PACAKBASE(r13);	/* get high part of &label */	\
848aa34ab8SBenjamin Herrenschmidt 	ld	r10,PACAKMSR(r13);	/* get MSR value for kernel */	\
85a5d4f3adSBenjamin Herrenschmidt 	mfspr	r11,SPRN_##h##SRR0;	/* save SRR0 */			\
868aa34ab8SBenjamin Herrenschmidt 	LOAD_HANDLER(r12,label)						\
87a5d4f3adSBenjamin Herrenschmidt 	mtspr	SPRN_##h##SRR0,r12;					\
88a5d4f3adSBenjamin Herrenschmidt 	mfspr	r12,SPRN_##h##SRR1;	/* and SRR1 */			\
89a5d4f3adSBenjamin Herrenschmidt 	mtspr	SPRN_##h##SRR1,r10;					\
90a5d4f3adSBenjamin Herrenschmidt 	h##rfid;							\
918aa34ab8SBenjamin Herrenschmidt 	b	.	/* prevent speculative execution */
92a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h)				\
93a5d4f3adSBenjamin Herrenschmidt 	__EXCEPTION_PROLOG_PSERIES_1(label, h)
948aa34ab8SBenjamin Herrenschmidt 
95b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec)		\
96b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_1(area, extra, vec);				\
97a5d4f3adSBenjamin Herrenschmidt 	EXCEPTION_PROLOG_PSERIES_1(label, h);
98c5a8c0c9SBenjamin Herrenschmidt 
99b01c8b54SPaul Mackerras #define __KVMTEST(n)							\
1003c42bf8aSPaul Mackerras 	lbz	r10,HSTATE_IN_GUEST(r13);			\
101b01c8b54SPaul Mackerras 	cmpwi	r10,0;							\
102b01c8b54SPaul Mackerras 	bne	do_kvm_##n
103b01c8b54SPaul Mackerras 
104b01c8b54SPaul Mackerras #define __KVM_HANDLER(area, h, n)					\
105b01c8b54SPaul Mackerras do_kvm_##n:								\
106b01c8b54SPaul Mackerras 	ld	r10,area+EX_R10(r13);					\
1073c42bf8aSPaul Mackerras 	stw	r9,HSTATE_SCRATCH1(r13);			\
108b01c8b54SPaul Mackerras 	ld	r9,area+EX_R9(r13);					\
1093c42bf8aSPaul Mackerras 	std	r12,HSTATE_SCRATCH0(r13);			\
110b01c8b54SPaul Mackerras 	li	r12,n;							\
111b01c8b54SPaul Mackerras 	b	kvmppc_interrupt
112b01c8b54SPaul Mackerras 
113b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n)					\
114b01c8b54SPaul Mackerras do_kvm_##n:								\
115b01c8b54SPaul Mackerras 	cmpwi	r10,KVM_GUEST_MODE_SKIP;				\
116b01c8b54SPaul Mackerras 	ld	r10,area+EX_R10(r13);					\
117b01c8b54SPaul Mackerras 	beq	89f;							\
1183c42bf8aSPaul Mackerras 	stw	r9,HSTATE_SCRATCH1(r13);			\
119b01c8b54SPaul Mackerras 	ld	r9,area+EX_R9(r13);					\
1203c42bf8aSPaul Mackerras 	std	r12,HSTATE_SCRATCH0(r13);			\
121b01c8b54SPaul Mackerras 	li	r12,n;							\
122b01c8b54SPaul Mackerras 	b	kvmppc_interrupt;					\
123b01c8b54SPaul Mackerras 89:	mtocrf	0x80,r9;						\
124b01c8b54SPaul Mackerras 	ld	r9,area+EX_R9(r13);					\
125b01c8b54SPaul Mackerras 	b	kvmppc_skip_##h##interrupt
126b01c8b54SPaul Mackerras 
127b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
128b01c8b54SPaul Mackerras #define KVMTEST(n)			__KVMTEST(n)
129b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n)		__KVM_HANDLER(area, h, n)
130b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n)	__KVM_HANDLER_SKIP(area, h, n)
131b01c8b54SPaul Mackerras 
132b01c8b54SPaul Mackerras #else
133b01c8b54SPaul Mackerras #define KVMTEST(n)
134b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n)
135b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n)
136b01c8b54SPaul Mackerras #endif
137b01c8b54SPaul Mackerras 
138de56a948SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_PR
139de56a948SPaul Mackerras #define KVMTEST_PR(n)			__KVMTEST(n)
140de56a948SPaul Mackerras #define KVM_HANDLER_PR(area, h, n)	__KVM_HANDLER(area, h, n)
141de56a948SPaul Mackerras #define KVM_HANDLER_PR_SKIP(area, h, n)	__KVM_HANDLER_SKIP(area, h, n)
142de56a948SPaul Mackerras 
143de56a948SPaul Mackerras #else
144de56a948SPaul Mackerras #define KVMTEST_PR(n)
145de56a948SPaul Mackerras #define KVM_HANDLER_PR(area, h, n)
146de56a948SPaul Mackerras #define KVM_HANDLER_PR_SKIP(area, h, n)
147de56a948SPaul Mackerras #endif
148de56a948SPaul Mackerras 
149b01c8b54SPaul Mackerras #define NOTEST(n)
150b01c8b54SPaul Mackerras 
1518aa34ab8SBenjamin Herrenschmidt /*
1528aa34ab8SBenjamin Herrenschmidt  * The common exception prolog is used for all except a few exceptions
1538aa34ab8SBenjamin Herrenschmidt  * such as a segment miss on a kernel address.  We have to be prepared
1548aa34ab8SBenjamin Herrenschmidt  * to take another exception from the point where we first touch the
1558aa34ab8SBenjamin Herrenschmidt  * kernel stack onwards.
1568aa34ab8SBenjamin Herrenschmidt  *
1578aa34ab8SBenjamin Herrenschmidt  * On entry r13 points to the paca, r9-r13 are saved in the paca,
1588aa34ab8SBenjamin Herrenschmidt  * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
1598aa34ab8SBenjamin Herrenschmidt  * SRR1, and relocation is on.
1608aa34ab8SBenjamin Herrenschmidt  */
1618aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area)				   \
1628aa34ab8SBenjamin Herrenschmidt 	andi.	r10,r12,MSR_PR;		/* See if coming from user	*/ \
1638aa34ab8SBenjamin Herrenschmidt 	mr	r10,r1;			/* Save r1			*/ \
1648aa34ab8SBenjamin Herrenschmidt 	subi	r1,r1,INT_FRAME_SIZE;	/* alloc frame on kernel stack	*/ \
1658aa34ab8SBenjamin Herrenschmidt 	beq-	1f;							   \
1668aa34ab8SBenjamin Herrenschmidt 	ld	r1,PACAKSAVE(r13);	/* kernel stack to use		*/ \
1678aa34ab8SBenjamin Herrenschmidt 1:	cmpdi	cr1,r1,0;		/* check if r1 is in userspace	*/ \
1681977b502SPaul Mackerras 	blt+	cr1,3f;			/* abort if it is		*/ \
1691977b502SPaul Mackerras 	li	r1,(n);			/* will be reloaded later	*/ \
1708aa34ab8SBenjamin Herrenschmidt 	sth	r1,PACA_TRAP_SAVE(r13);					   \
1711977b502SPaul Mackerras 	std	r3,area+EX_R3(r13);					   \
1721977b502SPaul Mackerras 	addi	r3,r13,area;		/* r3 -> where regs are saved*/	   \
1738aa34ab8SBenjamin Herrenschmidt 	b	bad_stack;						   \
1748aa34ab8SBenjamin Herrenschmidt 3:	std	r9,_CCR(r1);		/* save CR in stackframe	*/ \
1758aa34ab8SBenjamin Herrenschmidt 	std	r11,_NIP(r1);		/* save SRR0 in stackframe	*/ \
1768aa34ab8SBenjamin Herrenschmidt 	std	r12,_MSR(r1);		/* save SRR1 in stackframe	*/ \
1778aa34ab8SBenjamin Herrenschmidt 	std	r10,0(r1);		/* make stack chain pointer	*/ \
1788aa34ab8SBenjamin Herrenschmidt 	std	r0,GPR0(r1);		/* save r0 in stackframe	*/ \
1798aa34ab8SBenjamin Herrenschmidt 	std	r10,GPR1(r1);		/* save r1 in stackframe	*/ \
1808aa34ab8SBenjamin Herrenschmidt 	ACCOUNT_CPU_USER_ENTRY(r9, r10);				   \
1818aa34ab8SBenjamin Herrenschmidt 	std	r2,GPR2(r1);		/* save r2 in stackframe	*/ \
1828aa34ab8SBenjamin Herrenschmidt 	SAVE_4GPRS(3, r1);		/* save r3 - r6 in stackframe	*/ \
1838aa34ab8SBenjamin Herrenschmidt 	SAVE_2GPRS(7, r1);		/* save r7, r8 in stackframe	*/ \
1848aa34ab8SBenjamin Herrenschmidt 	ld	r9,area+EX_R9(r13);	/* move r9, r10 to stackframe	*/ \
1858aa34ab8SBenjamin Herrenschmidt 	ld	r10,area+EX_R10(r13);					   \
1868aa34ab8SBenjamin Herrenschmidt 	std	r9,GPR9(r1);						   \
1878aa34ab8SBenjamin Herrenschmidt 	std	r10,GPR10(r1);						   \
1888aa34ab8SBenjamin Herrenschmidt 	ld	r9,area+EX_R11(r13);	/* move r11 - r13 to stackframe	*/ \
1898aa34ab8SBenjamin Herrenschmidt 	ld	r10,area+EX_R12(r13);					   \
1908aa34ab8SBenjamin Herrenschmidt 	ld	r11,area+EX_R13(r13);					   \
1918aa34ab8SBenjamin Herrenschmidt 	std	r9,GPR11(r1);						   \
1928aa34ab8SBenjamin Herrenschmidt 	std	r10,GPR12(r1);						   \
1938aa34ab8SBenjamin Herrenschmidt 	std	r11,GPR13(r1);						   \
19448404f2eSPaul Mackerras 	BEGIN_FTR_SECTION_NESTED(66);					   \
19548404f2eSPaul Mackerras 	ld	r10,area+EX_CFAR(r13);					   \
19648404f2eSPaul Mackerras 	std	r10,ORIG_GPR3(r1);					   \
19748404f2eSPaul Mackerras 	END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);		   \
1988aa34ab8SBenjamin Herrenschmidt 	ld	r2,PACATOC(r13);	/* get kernel TOC into r2	*/ \
1998aa34ab8SBenjamin Herrenschmidt 	mflr	r9;			/* save LR in stackframe	*/ \
2008aa34ab8SBenjamin Herrenschmidt 	std	r9,_LINK(r1);						   \
2018aa34ab8SBenjamin Herrenschmidt 	mfctr	r10;			/* save CTR in stackframe	*/ \
2028aa34ab8SBenjamin Herrenschmidt 	std	r10,_CTR(r1);						   \
2038aa34ab8SBenjamin Herrenschmidt 	lbz	r10,PACASOFTIRQEN(r13);				   \
2048aa34ab8SBenjamin Herrenschmidt 	mfspr	r11,SPRN_XER;		/* save XER in stackframe	*/ \
2058aa34ab8SBenjamin Herrenschmidt 	std	r10,SOFTE(r1);						   \
2068aa34ab8SBenjamin Herrenschmidt 	std	r11,_XER(r1);						   \
2078aa34ab8SBenjamin Herrenschmidt 	li	r9,(n)+1;						   \
2088aa34ab8SBenjamin Herrenschmidt 	std	r9,_TRAP(r1);		/* set trap number		*/ \
2098aa34ab8SBenjamin Herrenschmidt 	li	r10,0;							   \
2108aa34ab8SBenjamin Herrenschmidt 	ld	r11,exception_marker@toc(r2);				   \
2118aa34ab8SBenjamin Herrenschmidt 	std	r10,RESULT(r1);		/* clear regs->result		*/ \
212cf9efce0SPaul Mackerras 	std	r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame	*/ \
213cf9efce0SPaul Mackerras 	ACCOUNT_STOLEN_TIME
2148aa34ab8SBenjamin Herrenschmidt 
2158aa34ab8SBenjamin Herrenschmidt /*
2168aa34ab8SBenjamin Herrenschmidt  * Exception vectors.
2178aa34ab8SBenjamin Herrenschmidt  */
218b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_PSERIES(loc, vec, label)		\
219b3e6b5dfSBenjamin Herrenschmidt 	. = loc;					\
2208aa34ab8SBenjamin Herrenschmidt 	.globl label##_pSeries;				\
2218aa34ab8SBenjamin Herrenschmidt label##_pSeries:					\
2228aa34ab8SBenjamin Herrenschmidt 	HMT_MEDIUM;					\
223673b189aSPaul Mackerras 	SET_SCRATCH0(r13);		/* save r13 */		\
224b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common,	\
225de56a948SPaul Mackerras 				 EXC_STD, KVMTEST_PR, vec)
2268aa34ab8SBenjamin Herrenschmidt 
227b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label)		\
228b3e6b5dfSBenjamin Herrenschmidt 	. = loc;					\
229b3e6b5dfSBenjamin Herrenschmidt 	.globl label##_hv;				\
230b3e6b5dfSBenjamin Herrenschmidt label##_hv:						\
2318aa34ab8SBenjamin Herrenschmidt 	HMT_MEDIUM;					\
232673b189aSPaul Mackerras 	SET_SCRATCH0(r13);	/* save r13 */			\
233b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common,	\
234b01c8b54SPaul Mackerras 				 EXC_HV, KVMTEST, vec)
2358aa34ab8SBenjamin Herrenschmidt 
2367230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */
2377230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500	PACA_IRQ_EE
2387230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x502	PACA_IRQ_EE
2397230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900	PACA_IRQ_DEC
2407230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x982	PACA_IRQ_DEC
2417230c564SBenjamin Herrenschmidt 
2427230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec)						\
2438aa34ab8SBenjamin Herrenschmidt 	lbz	r10,PACASOFTIRQEN(r13);					\
2448aa34ab8SBenjamin Herrenschmidt 	cmpwi	r10,0;							\
2457230c564SBenjamin Herrenschmidt 	li	r10,SOFTEN_VALUE_##vec;					\
246b01c8b54SPaul Mackerras 	beq	masked_##h##interrupt
2477230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec)	__SOFTEN_TEST(h, vec)
248b01c8b54SPaul Mackerras 
249de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec)						\
250de56a948SPaul Mackerras 	KVMTEST_PR(vec);						\
2517230c564SBenjamin Herrenschmidt 	_SOFTEN_TEST(EXC_STD, vec)
252b01c8b54SPaul Mackerras 
253b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec)						\
254b01c8b54SPaul Mackerras 	KVMTEST(vec);							\
2557230c564SBenjamin Herrenschmidt 	_SOFTEN_TEST(EXC_HV, vec)
256b01c8b54SPaul Mackerras 
2579e368f29SPaul Mackerras #define SOFTEN_TEST_HV_201(vec)						\
2589e368f29SPaul Mackerras 	KVMTEST(vec);							\
2597230c564SBenjamin Herrenschmidt 	_SOFTEN_TEST(EXC_STD, vec)
2609e368f29SPaul Mackerras 
261b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)		\
262b01c8b54SPaul Mackerras 	HMT_MEDIUM;							\
263b01c8b54SPaul Mackerras 	SET_SCRATCH0(r13);    /* save r13 */				\
264b01c8b54SPaul Mackerras 	__EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec);		\
265b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES_1(label##_common, h);
266b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)		\
267b01c8b54SPaul Mackerras 	__MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)
268b3e6b5dfSBenjamin Herrenschmidt 
269b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label)			\
270b3e6b5dfSBenjamin Herrenschmidt 	. = loc;							\
271b3e6b5dfSBenjamin Herrenschmidt 	.globl label##_pSeries;						\
272b3e6b5dfSBenjamin Herrenschmidt label##_pSeries:							\
273b01c8b54SPaul Mackerras 	_MASKABLE_EXCEPTION_PSERIES(vec, label,				\
274de56a948SPaul Mackerras 				    EXC_STD, SOFTEN_TEST_PR)
275b3e6b5dfSBenjamin Herrenschmidt 
276b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label)				\
277b3e6b5dfSBenjamin Herrenschmidt 	. = loc;							\
278b3e6b5dfSBenjamin Herrenschmidt 	.globl label##_hv;						\
279b3e6b5dfSBenjamin Herrenschmidt label##_hv:								\
280b01c8b54SPaul Mackerras 	_MASKABLE_EXCEPTION_PSERIES(vec, label,				\
281b01c8b54SPaul Mackerras 				    EXC_HV, SOFTEN_TEST_HV)
2828aa34ab8SBenjamin Herrenschmidt 
2831b701179SBenjamin Herrenschmidt /*
2841b701179SBenjamin Herrenschmidt  * Our exception common code can be passed various "additions"
2851b701179SBenjamin Herrenschmidt  * to specify the behaviour of interrupts, whether to kick the
2861b701179SBenjamin Herrenschmidt  * runlatch, etc...
2871b701179SBenjamin Herrenschmidt  */
2881b701179SBenjamin Herrenschmidt 
2891b701179SBenjamin Herrenschmidt /* Exception addition: Hard disable interrupts */
2907230c564SBenjamin Herrenschmidt #define DISABLE_INTS	SOFT_DISABLE_INTS(r10,r11)
2918aa34ab8SBenjamin Herrenschmidt 
292fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS				\
293fe1952fcSBenjamin Herrenschmidt 	bl	.save_nvgprs
294fe1952fcSBenjamin Herrenschmidt 
295fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON				\
296fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION				\
2979778b696SStuart Yoder 	CURRENT_THREAD_INFO(r3, r1);		\
298fe1952fcSBenjamin Herrenschmidt 	ld	r4,TI_LOCAL_FLAGS(r3);		\
299fe1952fcSBenjamin Herrenschmidt 	andi.	r0,r4,_TLF_RUNLATCH;		\
300fe1952fcSBenjamin Herrenschmidt 	beql	ppc64_runlatch_on_trampoline;	\
301fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
302fe1952fcSBenjamin Herrenschmidt 
303fe1952fcSBenjamin Herrenschmidt #define EXCEPTION_COMMON(trap, label, hdlr, ret, additions)	\
3048aa34ab8SBenjamin Herrenschmidt 	.align	7;						\
3058aa34ab8SBenjamin Herrenschmidt 	.globl label##_common;					\
3068aa34ab8SBenjamin Herrenschmidt label##_common:							\
3078aa34ab8SBenjamin Herrenschmidt 	EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN);		\
308fe1952fcSBenjamin Herrenschmidt 	additions;						\
3098aa34ab8SBenjamin Herrenschmidt 	addi	r3,r1,STACK_FRAME_OVERHEAD;			\
3108aa34ab8SBenjamin Herrenschmidt 	bl	hdlr;						\
311fe1952fcSBenjamin Herrenschmidt 	b	ret
312fe1952fcSBenjamin Herrenschmidt 
313fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr)			\
314fe1952fcSBenjamin Herrenschmidt 	EXCEPTION_COMMON(trap, label, hdlr, ret_from_except,	\
315fe1952fcSBenjamin Herrenschmidt 			 ADD_NVGPRS;DISABLE_INTS)
3168aa34ab8SBenjamin Herrenschmidt 
3178aa34ab8SBenjamin Herrenschmidt /*
3188aa34ab8SBenjamin Herrenschmidt  * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
3197450f6f0SBenjamin Herrenschmidt  * in the idle task and therefore need the special idle handling
3207450f6f0SBenjamin Herrenschmidt  * (finish nap and runlatch)
3218aa34ab8SBenjamin Herrenschmidt  */
3227450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr)		  \
323fe1952fcSBenjamin Herrenschmidt 	EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \
324fe1952fcSBenjamin Herrenschmidt 			 FINISH_NAP;RUNLATCH_ON;DISABLE_INTS)
3258aa34ab8SBenjamin Herrenschmidt 
3268aa34ab8SBenjamin Herrenschmidt /*
3278aa34ab8SBenjamin Herrenschmidt  * When the idle code in power4_idle puts the CPU into NAP mode,
3288aa34ab8SBenjamin Herrenschmidt  * it has to do so in a loop, and relies on the external interrupt
3298aa34ab8SBenjamin Herrenschmidt  * and decrementer interrupt entry code to get it out of the loop.
3308aa34ab8SBenjamin Herrenschmidt  * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
3318aa34ab8SBenjamin Herrenschmidt  * to signal that it is in the loop and needs help to get out.
3328aa34ab8SBenjamin Herrenschmidt  */
3338aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP
3348aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP				\
3358aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION				\
3369778b696SStuart Yoder 	CURRENT_THREAD_INFO(r11, r1);		\
3378aa34ab8SBenjamin Herrenschmidt 	ld	r9,TI_LOCAL_FLAGS(r11);		\
3388aa34ab8SBenjamin Herrenschmidt 	andi.	r10,r9,_TLF_NAPPING;		\
3398aa34ab8SBenjamin Herrenschmidt 	bnel	power4_fixup_nap;		\
3408aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
3418aa34ab8SBenjamin Herrenschmidt #else
3428aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP
3438aa34ab8SBenjamin Herrenschmidt #endif
3448aa34ab8SBenjamin Herrenschmidt 
3458aa34ab8SBenjamin Herrenschmidt #endif	/* _ASM_POWERPC_EXCEPTION_H */
346