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
50a09688cdSHaren Myneni #define EX_PPR		88	/* SMT thread status register (priority) */
51bc2e6c6aSMichael Neuling #define EX_CTR		96
528aa34ab8SBenjamin Herrenschmidt 
534700dfafSMichael Neuling #ifdef CONFIG_RELOCATABLE
541707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)			\
554700dfafSMichael Neuling 	ld	r12,PACAKBASE(r13);	/* get high part of &label */	\
564700dfafSMichael Neuling 	mfspr	r11,SPRN_##h##SRR0;	/* save SRR0 */			\
574700dfafSMichael Neuling 	LOAD_HANDLER(r12,label);					\
58bc2e6c6aSMichael Neuling 	mtctr	r12;							\
594700dfafSMichael Neuling 	mfspr	r12,SPRN_##h##SRR1;	/* and SRR1 */			\
604700dfafSMichael Neuling 	li	r10,MSR_RI;						\
614700dfafSMichael Neuling 	mtmsrd 	r10,1;			/* Set RI (EE=0) */		\
62bc2e6c6aSMichael Neuling 	bctr;
634700dfafSMichael Neuling #else
644700dfafSMichael Neuling /* If not relocatable, we can jump directly -- and save messing with LR */
651707dd16SPaul Mackerras #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)			\
664700dfafSMichael Neuling 	mfspr	r11,SPRN_##h##SRR0;	/* save SRR0 */			\
674700dfafSMichael Neuling 	mfspr	r12,SPRN_##h##SRR1;	/* and SRR1 */			\
684700dfafSMichael Neuling 	li	r10,MSR_RI;						\
694700dfafSMichael Neuling 	mtmsrd 	r10,1;			/* Set RI (EE=0) */		\
704700dfafSMichael Neuling 	b	label;
714700dfafSMichael Neuling #endif
721707dd16SPaul Mackerras #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)			\
731707dd16SPaul Mackerras 	__EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)			\
744700dfafSMichael Neuling 
754700dfafSMichael Neuling /*
764700dfafSMichael Neuling  * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on
774700dfafSMichael Neuling  * so no need to rfid.  Save lr in case we're CONFIG_RELOCATABLE, in which
784700dfafSMichael Neuling  * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr.
794700dfafSMichael Neuling  */
804700dfafSMichael Neuling #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec)	\
811707dd16SPaul Mackerras 	EXCEPTION_PROLOG_0(area);					\
824700dfafSMichael Neuling 	EXCEPTION_PROLOG_1(area, extra, vec);				\
834700dfafSMichael Neuling 	EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
844700dfafSMichael Neuling 
858aa34ab8SBenjamin Herrenschmidt /*
868aa34ab8SBenjamin Herrenschmidt  * We're short on space and time in the exception prolog, so we can't
878aa34ab8SBenjamin Herrenschmidt  * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
888aa34ab8SBenjamin Herrenschmidt  * low halfword of the address, but for Kdump we need the whole low
898aa34ab8SBenjamin Herrenschmidt  * word.
908aa34ab8SBenjamin Herrenschmidt  */
918aa34ab8SBenjamin Herrenschmidt #define LOAD_HANDLER(reg, label)					\
9261e2390eSMichael Neuling 	/* Handlers must be within 64K of kbase, which must be 64k aligned */ \
9361e2390eSMichael Neuling 	ori	reg,reg,(label)-_stext;	/* virt addr of handler ... */
948aa34ab8SBenjamin Herrenschmidt 
95a5d4f3adSBenjamin Herrenschmidt /* Exception register prefixes */
96a5d4f3adSBenjamin Herrenschmidt #define EXC_HV	H
97a5d4f3adSBenjamin Herrenschmidt #define EXC_STD
98a5d4f3adSBenjamin Herrenschmidt 
994700dfafSMichael Neuling #if defined(CONFIG_RELOCATABLE)
1004700dfafSMichael Neuling /*
101bc2e6c6aSMichael Neuling  * If we support interrupts with relocation on AND we're a relocatable kernel,
102bc2e6c6aSMichael Neuling  * we need to use CTR to get to the 2nd level handler.  So, save/restore it
103bc2e6c6aSMichael Neuling  * when required.
1044700dfafSMichael Neuling  */
105bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area)	mfctr	reg ; 	std	reg,area+EX_CTR(r13)
106bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) 			ld	reg,area+EX_CTR(r13)
107bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area)	ld	reg,area+EX_CTR(r13) ; mtctr reg
1084700dfafSMichael Neuling #else
109bc2e6c6aSMichael Neuling /* ...else CTR is unused and in register. */
110bc2e6c6aSMichael Neuling #define SAVE_CTR(reg, area)
111bc2e6c6aSMichael Neuling #define GET_CTR(reg, area) 	mfctr	reg
112bc2e6c6aSMichael Neuling #define RESTORE_CTR(reg, area)
1134700dfafSMichael Neuling #endif
1144700dfafSMichael Neuling 
11513e7a8e8SHaren Myneni /*
11613e7a8e8SHaren Myneni  * PPR save/restore macros used in exceptions_64s.S
11713e7a8e8SHaren Myneni  * Used for P7 or later processors
11813e7a8e8SHaren Myneni  */
11913e7a8e8SHaren Myneni #define SAVE_PPR(area, ra, rb)						\
12013e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(940)						\
12113e7a8e8SHaren Myneni 	ld	ra,PACACURRENT(r13);					\
12213e7a8e8SHaren Myneni 	ld	rb,area+EX_PPR(r13);	/* Read PPR from paca */	\
12313e7a8e8SHaren Myneni 	std	rb,TASKTHREADPPR(ra);					\
12413e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
12513e7a8e8SHaren Myneni 
12613e7a8e8SHaren Myneni #define RESTORE_PPR_PACA(area, ra)					\
12713e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(941)						\
12813e7a8e8SHaren Myneni 	ld	ra,area+EX_PPR(r13);					\
12913e7a8e8SHaren Myneni 	mtspr	SPRN_PPR,ra;						\
13013e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
13113e7a8e8SHaren Myneni 
13213e7a8e8SHaren Myneni /*
13313e7a8e8SHaren Myneni  * Increase the priority on systems where PPR save/restore is not
13413e7a8e8SHaren Myneni  * implemented/ supported.
13513e7a8e8SHaren Myneni  */
13613e7a8e8SHaren Myneni #define HMT_MEDIUM_PPR_DISCARD						\
13713e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(942)						\
13813e7a8e8SHaren Myneni 	HMT_MEDIUM;							\
13913e7a8e8SHaren Myneni END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,0,942)  /*non P7*/
14013e7a8e8SHaren Myneni 
14113e7a8e8SHaren Myneni /*
1421707dd16SPaul Mackerras  * Get an SPR into a register if the CPU has the given feature
14313e7a8e8SHaren Myneni  */
1441707dd16SPaul Mackerras #define OPT_GET_SPR(ra, spr, ftr)					\
14513e7a8e8SHaren Myneni BEGIN_FTR_SECTION_NESTED(943)						\
1461707dd16SPaul Mackerras 	mfspr	ra,spr;							\
1471707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943)
14813e7a8e8SHaren Myneni 
1491707dd16SPaul Mackerras /*
150d410ae21SMahesh Salgaonkar  * Set an SPR from a register if the CPU has the given feature
151d410ae21SMahesh Salgaonkar  */
152d410ae21SMahesh Salgaonkar #define OPT_SET_SPR(ra, spr, ftr)					\
153d410ae21SMahesh Salgaonkar BEGIN_FTR_SECTION_NESTED(943)						\
154d410ae21SMahesh Salgaonkar 	mtspr	spr,ra;							\
155d410ae21SMahesh Salgaonkar END_FTR_SECTION_NESTED(ftr,ftr,943)
156d410ae21SMahesh Salgaonkar 
157d410ae21SMahesh Salgaonkar /*
1581707dd16SPaul Mackerras  * Save a register to the PACA if the CPU has the given feature
1591707dd16SPaul Mackerras  */
1601707dd16SPaul Mackerras #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr)				\
1611707dd16SPaul Mackerras BEGIN_FTR_SECTION_NESTED(943)						\
1621707dd16SPaul Mackerras 	std	ra,offset(r13);						\
1631707dd16SPaul Mackerras END_FTR_SECTION_NESTED(ftr,ftr,943)
1641707dd16SPaul Mackerras 
1651707dd16SPaul Mackerras #define EXCEPTION_PROLOG_0(area)					\
1662dd60d79SBenjamin Herrenschmidt 	GET_PACA(r13);							\
16744e9309fSHaren Myneni 	std	r9,area+EX_R9(r13);	/* save r9 */			\
1681707dd16SPaul Mackerras 	OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR);			\
1691707dd16SPaul Mackerras 	HMT_MEDIUM;							\
17044e9309fSHaren Myneni 	std	r10,area+EX_R10(r13);	/* save r10 - r12 */		\
1711707dd16SPaul Mackerras 	OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
1721707dd16SPaul Mackerras 
1731707dd16SPaul Mackerras #define __EXCEPTION_PROLOG_1(area, extra, vec)				\
1741707dd16SPaul Mackerras 	OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR);		\
1751707dd16SPaul Mackerras 	OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR);		\
176bc2e6c6aSMichael Neuling 	SAVE_CTR(r10, area);						\
177b01c8b54SPaul Mackerras 	mfcr	r9;							\
178b01c8b54SPaul Mackerras 	extra(vec);							\
179b01c8b54SPaul Mackerras 	std	r11,area+EX_R11(r13);					\
180b01c8b54SPaul Mackerras 	std	r12,area+EX_R12(r13);					\
181b01c8b54SPaul Mackerras 	GET_SCRATCH0(r10);						\
182b01c8b54SPaul Mackerras 	std	r10,area+EX_R13(r13)
183b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_1(area, extra, vec)				\
184b01c8b54SPaul Mackerras 	__EXCEPTION_PROLOG_1(area, extra, vec)
1858aa34ab8SBenjamin Herrenschmidt 
186a5d4f3adSBenjamin Herrenschmidt #define __EXCEPTION_PROLOG_PSERIES_1(label, h)				\
1878aa34ab8SBenjamin Herrenschmidt 	ld	r12,PACAKBASE(r13);	/* get high part of &label */	\
1888aa34ab8SBenjamin Herrenschmidt 	ld	r10,PACAKMSR(r13);	/* get MSR value for kernel */	\
189a5d4f3adSBenjamin Herrenschmidt 	mfspr	r11,SPRN_##h##SRR0;	/* save SRR0 */			\
1908aa34ab8SBenjamin Herrenschmidt 	LOAD_HANDLER(r12,label)						\
191a5d4f3adSBenjamin Herrenschmidt 	mtspr	SPRN_##h##SRR0,r12;					\
192a5d4f3adSBenjamin Herrenschmidt 	mfspr	r12,SPRN_##h##SRR1;	/* and SRR1 */			\
193a5d4f3adSBenjamin Herrenschmidt 	mtspr	SPRN_##h##SRR1,r10;					\
194a5d4f3adSBenjamin Herrenschmidt 	h##rfid;							\
1958aa34ab8SBenjamin Herrenschmidt 	b	.	/* prevent speculative execution */
196a5d4f3adSBenjamin Herrenschmidt #define EXCEPTION_PROLOG_PSERIES_1(label, h)				\
197a5d4f3adSBenjamin Herrenschmidt 	__EXCEPTION_PROLOG_PSERIES_1(label, h)
1988aa34ab8SBenjamin Herrenschmidt 
199b01c8b54SPaul Mackerras #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec)		\
2001707dd16SPaul Mackerras 	EXCEPTION_PROLOG_0(area);					\
201b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_1(area, extra, vec);				\
202a5d4f3adSBenjamin Herrenschmidt 	EXCEPTION_PROLOG_PSERIES_1(label, h);
203c5a8c0c9SBenjamin Herrenschmidt 
204b01c8b54SPaul Mackerras #define __KVMTEST(n)							\
2053c42bf8aSPaul Mackerras 	lbz	r10,HSTATE_IN_GUEST(r13);			\
206b01c8b54SPaul Mackerras 	cmpwi	r10,0;							\
207b01c8b54SPaul Mackerras 	bne	do_kvm_##n
208b01c8b54SPaul Mackerras 
209dd96b2c2SAneesh Kumar K.V #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
210dd96b2c2SAneesh Kumar K.V /*
211dd96b2c2SAneesh Kumar K.V  * If hv is possible, interrupts come into to the hv version
212dd96b2c2SAneesh Kumar K.V  * of the kvmppc_interrupt code, which then jumps to the PR handler,
213dd96b2c2SAneesh Kumar K.V  * kvmppc_interrupt_pr, if the guest is a PR guest.
214dd96b2c2SAneesh Kumar K.V  */
215dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_hv
216dd96b2c2SAneesh Kumar K.V #else
217dd96b2c2SAneesh Kumar K.V #define kvmppc_interrupt kvmppc_interrupt_pr
218dd96b2c2SAneesh Kumar K.V #endif
219dd96b2c2SAneesh Kumar K.V 
220b01c8b54SPaul Mackerras #define __KVM_HANDLER(area, h, n)					\
221b01c8b54SPaul Mackerras do_kvm_##n:								\
2220acb9111SPaul Mackerras 	BEGIN_FTR_SECTION_NESTED(947)					\
2230acb9111SPaul Mackerras 	ld	r10,area+EX_CFAR(r13);					\
2240acb9111SPaul Mackerras 	std	r10,HSTATE_CFAR(r13);					\
2250acb9111SPaul Mackerras 	END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947);		\
2264b8473c9SPaul Mackerras 	BEGIN_FTR_SECTION_NESTED(948)					\
2274b8473c9SPaul Mackerras 	ld	r10,area+EX_PPR(r13);					\
2284b8473c9SPaul Mackerras 	std	r10,HSTATE_PPR(r13);					\
2294b8473c9SPaul Mackerras 	END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948);	\
230b01c8b54SPaul Mackerras 	ld	r10,area+EX_R10(r13);					\
2313c42bf8aSPaul Mackerras 	stw	r9,HSTATE_SCRATCH1(r13);				\
232b01c8b54SPaul Mackerras 	ld	r9,area+EX_R9(r13);					\
2333c42bf8aSPaul Mackerras 	std	r12,HSTATE_SCRATCH0(r13);				\
234b01c8b54SPaul Mackerras 	li	r12,n;							\
235b01c8b54SPaul Mackerras 	b	kvmppc_interrupt
236b01c8b54SPaul Mackerras 
237b01c8b54SPaul Mackerras #define __KVM_HANDLER_SKIP(area, h, n)					\
238b01c8b54SPaul Mackerras do_kvm_##n:								\
239b01c8b54SPaul Mackerras 	cmpwi	r10,KVM_GUEST_MODE_SKIP;				\
240b01c8b54SPaul Mackerras 	ld	r10,area+EX_R10(r13);					\
241b01c8b54SPaul Mackerras 	beq	89f;							\
2423c42bf8aSPaul Mackerras 	stw	r9,HSTATE_SCRATCH1(r13);			\
2434b8473c9SPaul Mackerras 	BEGIN_FTR_SECTION_NESTED(948)					\
2444b8473c9SPaul Mackerras 	ld	r9,area+EX_PPR(r13);					\
2454b8473c9SPaul Mackerras 	std	r9,HSTATE_PPR(r13);					\
2464b8473c9SPaul Mackerras 	END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948);	\
247b01c8b54SPaul Mackerras 	ld	r9,area+EX_R9(r13);					\
2483c42bf8aSPaul Mackerras 	std	r12,HSTATE_SCRATCH0(r13);			\
249b01c8b54SPaul Mackerras 	li	r12,n;							\
250b01c8b54SPaul Mackerras 	b	kvmppc_interrupt;					\
251b01c8b54SPaul Mackerras 89:	mtocrf	0x80,r9;						\
252b01c8b54SPaul Mackerras 	ld	r9,area+EX_R9(r13);					\
253b01c8b54SPaul Mackerras 	b	kvmppc_skip_##h##interrupt
254b01c8b54SPaul Mackerras 
255b01c8b54SPaul Mackerras #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
256b01c8b54SPaul Mackerras #define KVMTEST(n)			__KVMTEST(n)
257b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n)		__KVM_HANDLER(area, h, n)
258b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n)	__KVM_HANDLER_SKIP(area, h, n)
259b01c8b54SPaul Mackerras 
260b01c8b54SPaul Mackerras #else
261b01c8b54SPaul Mackerras #define KVMTEST(n)
262b01c8b54SPaul Mackerras #define KVM_HANDLER(area, h, n)
263b01c8b54SPaul Mackerras #define KVM_HANDLER_SKIP(area, h, n)
264b01c8b54SPaul Mackerras #endif
265b01c8b54SPaul Mackerras 
266b01c8b54SPaul Mackerras #define NOTEST(n)
267b01c8b54SPaul Mackerras 
2688aa34ab8SBenjamin Herrenschmidt /*
2698aa34ab8SBenjamin Herrenschmidt  * The common exception prolog is used for all except a few exceptions
2708aa34ab8SBenjamin Herrenschmidt  * such as a segment miss on a kernel address.  We have to be prepared
2718aa34ab8SBenjamin Herrenschmidt  * to take another exception from the point where we first touch the
2728aa34ab8SBenjamin Herrenschmidt  * kernel stack onwards.
2738aa34ab8SBenjamin Herrenschmidt  *
2748aa34ab8SBenjamin Herrenschmidt  * On entry r13 points to the paca, r9-r13 are saved in the paca,
2758aa34ab8SBenjamin Herrenschmidt  * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
2768aa34ab8SBenjamin Herrenschmidt  * SRR1, and relocation is on.
2778aa34ab8SBenjamin Herrenschmidt  */
2788aa34ab8SBenjamin Herrenschmidt #define EXCEPTION_PROLOG_COMMON(n, area)				   \
2798aa34ab8SBenjamin Herrenschmidt 	andi.	r10,r12,MSR_PR;		/* See if coming from user	*/ \
2808aa34ab8SBenjamin Herrenschmidt 	mr	r10,r1;			/* Save r1			*/ \
2818aa34ab8SBenjamin Herrenschmidt 	subi	r1,r1,INT_FRAME_SIZE;	/* alloc frame on kernel stack	*/ \
2828aa34ab8SBenjamin Herrenschmidt 	beq-	1f;							   \
2838aa34ab8SBenjamin Herrenschmidt 	ld	r1,PACAKSAVE(r13);	/* kernel stack to use		*/ \
28490ff5d68SMichael Neuling 1:	cmpdi	cr1,r1,-INT_FRAME_SIZE;	/* check if r1 is in userspace	*/ \
2851977b502SPaul Mackerras 	blt+	cr1,3f;			/* abort if it is		*/ \
2861977b502SPaul Mackerras 	li	r1,(n);			/* will be reloaded later	*/ \
2878aa34ab8SBenjamin Herrenschmidt 	sth	r1,PACA_TRAP_SAVE(r13);					   \
2881977b502SPaul Mackerras 	std	r3,area+EX_R3(r13);					   \
2891977b502SPaul Mackerras 	addi	r3,r13,area;		/* r3 -> where regs are saved*/	   \
290bc2e6c6aSMichael Neuling 	RESTORE_CTR(r1, area);						   \
2918aa34ab8SBenjamin Herrenschmidt 	b	bad_stack;						   \
2928aa34ab8SBenjamin Herrenschmidt 3:	std	r9,_CCR(r1);		/* save CR in stackframe	*/ \
2938aa34ab8SBenjamin Herrenschmidt 	std	r11,_NIP(r1);		/* save SRR0 in stackframe	*/ \
2948aa34ab8SBenjamin Herrenschmidt 	std	r12,_MSR(r1);		/* save SRR1 in stackframe	*/ \
2958aa34ab8SBenjamin Herrenschmidt 	std	r10,0(r1);		/* make stack chain pointer	*/ \
2968aa34ab8SBenjamin Herrenschmidt 	std	r0,GPR0(r1);		/* save r0 in stackframe	*/ \
2978aa34ab8SBenjamin Herrenschmidt 	std	r10,GPR1(r1);		/* save r1 in stackframe	*/ \
2985d75b264SHaren Myneni 	beq	4f;			/* if from kernel mode		*/ \
2998aa34ab8SBenjamin Herrenschmidt 	ACCOUNT_CPU_USER_ENTRY(r9, r10);				   \
30044e9309fSHaren Myneni 	SAVE_PPR(area, r9, r10);					   \
301b14a7253SMahesh Salgaonkar 4:	EXCEPTION_PROLOG_COMMON_2(area)					   \
302b14a7253SMahesh Salgaonkar 	EXCEPTION_PROLOG_COMMON_3(n)					   \
303b14a7253SMahesh Salgaonkar 	ACCOUNT_STOLEN_TIME
304b14a7253SMahesh Salgaonkar 
305b14a7253SMahesh Salgaonkar /* Save original regs values from save area to stack frame. */
306b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_2(area)					   \
3078aa34ab8SBenjamin Herrenschmidt 	ld	r9,area+EX_R9(r13);	/* move r9, r10 to stackframe	*/ \
3088aa34ab8SBenjamin Herrenschmidt 	ld	r10,area+EX_R10(r13);					   \
3098aa34ab8SBenjamin Herrenschmidt 	std	r9,GPR9(r1);						   \
3108aa34ab8SBenjamin Herrenschmidt 	std	r10,GPR10(r1);						   \
3118aa34ab8SBenjamin Herrenschmidt 	ld	r9,area+EX_R11(r13);	/* move r11 - r13 to stackframe	*/ \
3128aa34ab8SBenjamin Herrenschmidt 	ld	r10,area+EX_R12(r13);					   \
3138aa34ab8SBenjamin Herrenschmidt 	ld	r11,area+EX_R13(r13);					   \
3148aa34ab8SBenjamin Herrenschmidt 	std	r9,GPR11(r1);						   \
3158aa34ab8SBenjamin Herrenschmidt 	std	r10,GPR12(r1);						   \
3168aa34ab8SBenjamin Herrenschmidt 	std	r11,GPR13(r1);						   \
31748404f2eSPaul Mackerras 	BEGIN_FTR_SECTION_NESTED(66);					   \
31848404f2eSPaul Mackerras 	ld	r10,area+EX_CFAR(r13);					   \
31948404f2eSPaul Mackerras 	std	r10,ORIG_GPR3(r1);					   \
32048404f2eSPaul Mackerras 	END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);		   \
321b14a7253SMahesh Salgaonkar 	GET_CTR(r10, area);						   \
322b14a7253SMahesh Salgaonkar 	std	r10,_CTR(r1);
323b14a7253SMahesh Salgaonkar 
324b14a7253SMahesh Salgaonkar #define EXCEPTION_PROLOG_COMMON_3(n)					   \
325b14a7253SMahesh Salgaonkar 	std	r2,GPR2(r1);		/* save r2 in stackframe	*/ \
326b14a7253SMahesh Salgaonkar 	SAVE_4GPRS(3, r1);		/* save r3 - r6 in stackframe   */ \
327b14a7253SMahesh Salgaonkar 	SAVE_2GPRS(7, r1);		/* save r7, r8 in stackframe	*/ \
328bc2e6c6aSMichael Neuling 	mflr	r9;			/* Get LR, later save to stack	*/ \
3298aa34ab8SBenjamin Herrenschmidt 	ld	r2,PACATOC(r13);	/* get kernel TOC into r2	*/ \
3308aa34ab8SBenjamin Herrenschmidt 	std	r9,_LINK(r1);						   \
3318aa34ab8SBenjamin Herrenschmidt 	lbz	r10,PACASOFTIRQEN(r13);				   \
3328aa34ab8SBenjamin Herrenschmidt 	mfspr	r11,SPRN_XER;		/* save XER in stackframe	*/ \
3338aa34ab8SBenjamin Herrenschmidt 	std	r10,SOFTE(r1);						   \
3348aa34ab8SBenjamin Herrenschmidt 	std	r11,_XER(r1);						   \
3358aa34ab8SBenjamin Herrenschmidt 	li	r9,(n)+1;						   \
3368aa34ab8SBenjamin Herrenschmidt 	std	r9,_TRAP(r1);		/* set trap number		*/ \
3378aa34ab8SBenjamin Herrenschmidt 	li	r10,0;							   \
3388aa34ab8SBenjamin Herrenschmidt 	ld	r11,exception_marker@toc(r2);				   \
3398aa34ab8SBenjamin Herrenschmidt 	std	r10,RESULT(r1);		/* clear regs->result		*/ \
340b14a7253SMahesh Salgaonkar 	std	r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame	*/
3418aa34ab8SBenjamin Herrenschmidt 
3428aa34ab8SBenjamin Herrenschmidt /*
3438aa34ab8SBenjamin Herrenschmidt  * Exception vectors.
3448aa34ab8SBenjamin Herrenschmidt  */
345b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_PSERIES(loc, vec, label)		\
346b3e6b5dfSBenjamin Herrenschmidt 	. = loc;					\
3478aa34ab8SBenjamin Herrenschmidt 	.globl label##_pSeries;				\
3488aa34ab8SBenjamin Herrenschmidt label##_pSeries:					\
34944e9309fSHaren Myneni 	HMT_MEDIUM_PPR_DISCARD;				\
350673b189aSPaul Mackerras 	SET_SCRATCH0(r13);		/* save r13 */		\
351b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common,	\
35231a40e2bSPaul Mackerras 				 EXC_STD, KVMTEST, vec)
3538aa34ab8SBenjamin Herrenschmidt 
3541707dd16SPaul Mackerras /* Version of above for when we have to branch out-of-line */
3551707dd16SPaul Mackerras #define STD_EXCEPTION_PSERIES_OOL(vec, label)			\
3561707dd16SPaul Mackerras 	.globl label##_pSeries;					\
3571707dd16SPaul Mackerras label##_pSeries:						\
35831a40e2bSPaul Mackerras 	EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST, vec);	\
3591707dd16SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES_1(label##_common, EXC_STD)
3601707dd16SPaul Mackerras 
361b3e6b5dfSBenjamin Herrenschmidt #define STD_EXCEPTION_HV(loc, vec, label)		\
362b3e6b5dfSBenjamin Herrenschmidt 	. = loc;					\
363b3e6b5dfSBenjamin Herrenschmidt 	.globl label##_hv;				\
364b3e6b5dfSBenjamin Herrenschmidt label##_hv:						\
36544e9309fSHaren Myneni 	HMT_MEDIUM_PPR_DISCARD;				\
366673b189aSPaul Mackerras 	SET_SCRATCH0(r13);	/* save r13 */			\
367b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common,	\
368b01c8b54SPaul Mackerras 				 EXC_HV, KVMTEST, vec)
3698aa34ab8SBenjamin Herrenschmidt 
3701707dd16SPaul Mackerras /* Version of above for when we have to branch out-of-line */
3711707dd16SPaul Mackerras #define STD_EXCEPTION_HV_OOL(vec, label)		\
3721707dd16SPaul Mackerras 	.globl label##_hv;				\
3731707dd16SPaul Mackerras label##_hv:						\
3741707dd16SPaul Mackerras 	EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST, vec);	\
3751707dd16SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES_1(label##_common, EXC_HV)
3761707dd16SPaul Mackerras 
3774700dfafSMichael Neuling #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label)	\
3784700dfafSMichael Neuling 	. = loc;					\
3794700dfafSMichael Neuling 	.globl label##_relon_pSeries;			\
3804700dfafSMichael Neuling label##_relon_pSeries:					\
38144e9309fSHaren Myneni 	HMT_MEDIUM_PPR_DISCARD;				\
3824700dfafSMichael Neuling 	/* No guest interrupts come through here */	\
3834700dfafSMichael Neuling 	SET_SCRATCH0(r13);		/* save r13 */	\
3844700dfafSMichael Neuling 	EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
385c9f69518SMichael Ellerman 				       EXC_STD, NOTEST, vec)
3864700dfafSMichael Neuling 
3871707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label)		\
3881707dd16SPaul Mackerras 	.globl label##_relon_pSeries;				\
3891707dd16SPaul Mackerras label##_relon_pSeries:						\
390c9f69518SMichael Ellerman 	EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec);		\
3911707dd16SPaul Mackerras 	EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, EXC_STD)
3921707dd16SPaul Mackerras 
3934700dfafSMichael Neuling #define STD_RELON_EXCEPTION_HV(loc, vec, label)		\
3944700dfafSMichael Neuling 	. = loc;					\
3954700dfafSMichael Neuling 	.globl label##_relon_hv;			\
3964700dfafSMichael Neuling label##_relon_hv:					\
39744e9309fSHaren Myneni 	HMT_MEDIUM_PPR_DISCARD;				\
3984700dfafSMichael Neuling 	/* No guest interrupts come through here */	\
3994700dfafSMichael Neuling 	SET_SCRATCH0(r13);	/* save r13 */		\
4004700dfafSMichael Neuling 	EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
401c9f69518SMichael Ellerman 				       EXC_HV, NOTEST, vec)
4024700dfafSMichael Neuling 
4031707dd16SPaul Mackerras #define STD_RELON_EXCEPTION_HV_OOL(vec, label)			\
4041707dd16SPaul Mackerras 	.globl label##_relon_hv;				\
4051707dd16SPaul Mackerras label##_relon_hv:						\
406c9f69518SMichael Ellerman 	EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec);		\
4071707dd16SPaul Mackerras 	EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, EXC_HV)
4081707dd16SPaul Mackerras 
4097230c564SBenjamin Herrenschmidt /* This associate vector numbers with bits in paca->irq_happened */
4107230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x500	PACA_IRQ_EE
4117230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x502	PACA_IRQ_EE
4127230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x900	PACA_IRQ_DEC
4137230c564SBenjamin Herrenschmidt #define SOFTEN_VALUE_0x982	PACA_IRQ_DEC
4141dbdafecSIan Munsie #define SOFTEN_VALUE_0xa00	PACA_IRQ_DBELL
415655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe80	PACA_IRQ_DBELL
416655bb3f4SIan Munsie #define SOFTEN_VALUE_0xe82	PACA_IRQ_DBELL
4170869b6fdSMahesh Salgaonkar #define SOFTEN_VALUE_0xe60	PACA_IRQ_HMI
4180869b6fdSMahesh Salgaonkar #define SOFTEN_VALUE_0xe62	PACA_IRQ_HMI
4197230c564SBenjamin Herrenschmidt 
4207230c564SBenjamin Herrenschmidt #define __SOFTEN_TEST(h, vec)						\
4218aa34ab8SBenjamin Herrenschmidt 	lbz	r10,PACASOFTIRQEN(r13);					\
4228aa34ab8SBenjamin Herrenschmidt 	cmpwi	r10,0;							\
4237230c564SBenjamin Herrenschmidt 	li	r10,SOFTEN_VALUE_##vec;					\
424b01c8b54SPaul Mackerras 	beq	masked_##h##interrupt
4257230c564SBenjamin Herrenschmidt #define _SOFTEN_TEST(h, vec)	__SOFTEN_TEST(h, vec)
426b01c8b54SPaul Mackerras 
427de56a948SPaul Mackerras #define SOFTEN_TEST_PR(vec)						\
42831a40e2bSPaul Mackerras 	KVMTEST(vec);							\
4297230c564SBenjamin Herrenschmidt 	_SOFTEN_TEST(EXC_STD, vec)
430b01c8b54SPaul Mackerras 
431b01c8b54SPaul Mackerras #define SOFTEN_TEST_HV(vec)						\
432b01c8b54SPaul Mackerras 	KVMTEST(vec);							\
4337230c564SBenjamin Herrenschmidt 	_SOFTEN_TEST(EXC_HV, vec)
434b01c8b54SPaul Mackerras 
4354700dfafSMichael Neuling #define SOFTEN_NOTEST_PR(vec)		_SOFTEN_TEST(EXC_STD, vec)
4364700dfafSMichael Neuling #define SOFTEN_NOTEST_HV(vec)		_SOFTEN_TEST(EXC_HV, vec)
4374700dfafSMichael Neuling 
438b01c8b54SPaul Mackerras #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)		\
439b01c8b54SPaul Mackerras 	SET_SCRATCH0(r13);    /* save r13 */				\
4401707dd16SPaul Mackerras 	EXCEPTION_PROLOG_0(PACA_EXGEN);					\
441b01c8b54SPaul Mackerras 	__EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec);			\
442b01c8b54SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES_1(label##_common, h);
4431707dd16SPaul Mackerras 
444b01c8b54SPaul Mackerras #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)		\
445b01c8b54SPaul Mackerras 	__MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)
446b3e6b5dfSBenjamin Herrenschmidt 
447b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label)			\
448b3e6b5dfSBenjamin Herrenschmidt 	. = loc;							\
449b3e6b5dfSBenjamin Herrenschmidt 	.globl label##_pSeries;						\
450b3e6b5dfSBenjamin Herrenschmidt label##_pSeries:							\
451a485c709SPaul Mackerras 	HMT_MEDIUM_PPR_DISCARD;						\
452b01c8b54SPaul Mackerras 	_MASKABLE_EXCEPTION_PSERIES(vec, label,				\
453de56a948SPaul Mackerras 				    EXC_STD, SOFTEN_TEST_PR)
454b3e6b5dfSBenjamin Herrenschmidt 
455b3e6b5dfSBenjamin Herrenschmidt #define MASKABLE_EXCEPTION_HV(loc, vec, label)				\
456b3e6b5dfSBenjamin Herrenschmidt 	. = loc;							\
457b3e6b5dfSBenjamin Herrenschmidt 	.globl label##_hv;						\
458b3e6b5dfSBenjamin Herrenschmidt label##_hv:								\
459b01c8b54SPaul Mackerras 	_MASKABLE_EXCEPTION_PSERIES(vec, label,				\
460b01c8b54SPaul Mackerras 				    EXC_HV, SOFTEN_TEST_HV)
4618aa34ab8SBenjamin Herrenschmidt 
4621707dd16SPaul Mackerras #define MASKABLE_EXCEPTION_HV_OOL(vec, label)				\
4631707dd16SPaul Mackerras 	.globl label##_hv;						\
4641707dd16SPaul Mackerras label##_hv:								\
4651707dd16SPaul Mackerras 	EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec);		\
4661707dd16SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES_1(label##_common, EXC_HV);
4671707dd16SPaul Mackerras 
4684700dfafSMichael Neuling #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)	\
46944e9309fSHaren Myneni 	HMT_MEDIUM_PPR_DISCARD;						\
4704700dfafSMichael Neuling 	SET_SCRATCH0(r13);    /* save r13 */				\
4711707dd16SPaul Mackerras 	EXCEPTION_PROLOG_0(PACA_EXGEN);					\
4724700dfafSMichael Neuling 	__EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec);		\
4734700dfafSMichael Neuling 	EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, h);
4744700dfafSMichael Neuling #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)	\
4754700dfafSMichael Neuling 	__MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
4764700dfafSMichael Neuling 
4774700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label)		\
4784700dfafSMichael Neuling 	. = loc;							\
4794700dfafSMichael Neuling 	.globl label##_relon_pSeries;					\
4804700dfafSMichael Neuling label##_relon_pSeries:							\
4814700dfafSMichael Neuling 	_MASKABLE_RELON_EXCEPTION_PSERIES(vec, label,			\
4824700dfafSMichael Neuling 					  EXC_STD, SOFTEN_NOTEST_PR)
4834700dfafSMichael Neuling 
4844700dfafSMichael Neuling #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label)			\
4854700dfafSMichael Neuling 	. = loc;							\
4864700dfafSMichael Neuling 	.globl label##_relon_hv;					\
4874700dfafSMichael Neuling label##_relon_hv:							\
4884700dfafSMichael Neuling 	_MASKABLE_RELON_EXCEPTION_PSERIES(vec, label,			\
4894700dfafSMichael Neuling 					  EXC_HV, SOFTEN_NOTEST_HV)
4904700dfafSMichael Neuling 
4911707dd16SPaul Mackerras #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label)			\
4921707dd16SPaul Mackerras 	.globl label##_relon_hv;					\
4931707dd16SPaul Mackerras label##_relon_hv:							\
4941707dd16SPaul Mackerras 	EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_HV, vec);		\
4951707dd16SPaul Mackerras 	EXCEPTION_PROLOG_PSERIES_1(label##_common, EXC_HV);
4961707dd16SPaul Mackerras 
4971b701179SBenjamin Herrenschmidt /*
4981b701179SBenjamin Herrenschmidt  * Our exception common code can be passed various "additions"
4991b701179SBenjamin Herrenschmidt  * to specify the behaviour of interrupts, whether to kick the
5001b701179SBenjamin Herrenschmidt  * runlatch, etc...
5011b701179SBenjamin Herrenschmidt  */
5021b701179SBenjamin Herrenschmidt 
5039daf112bSMichael Ellerman /*
5049daf112bSMichael Ellerman  * This addition reconciles our actual IRQ state with the various software
5059daf112bSMichael Ellerman  * flags that track it. This may call C code.
5069daf112bSMichael Ellerman  */
5079daf112bSMichael Ellerman #define ADD_RECONCILE	RECONCILE_IRQ_STATE(r10,r11)
5088aa34ab8SBenjamin Herrenschmidt 
509fe1952fcSBenjamin Herrenschmidt #define ADD_NVGPRS				\
510b1576fecSAnton Blanchard 	bl	save_nvgprs
511fe1952fcSBenjamin Herrenschmidt 
512fe1952fcSBenjamin Herrenschmidt #define RUNLATCH_ON				\
513fe1952fcSBenjamin Herrenschmidt BEGIN_FTR_SECTION				\
5149778b696SStuart Yoder 	CURRENT_THREAD_INFO(r3, r1);		\
515fe1952fcSBenjamin Herrenschmidt 	ld	r4,TI_LOCAL_FLAGS(r3);		\
516fe1952fcSBenjamin Herrenschmidt 	andi.	r0,r4,_TLF_RUNLATCH;		\
517fe1952fcSBenjamin Herrenschmidt 	beql	ppc64_runlatch_on_trampoline;	\
518fe1952fcSBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
519fe1952fcSBenjamin Herrenschmidt 
520fe1952fcSBenjamin Herrenschmidt #define EXCEPTION_COMMON(trap, label, hdlr, ret, additions)	\
5218aa34ab8SBenjamin Herrenschmidt 	.align	7;						\
5228aa34ab8SBenjamin Herrenschmidt 	.globl label##_common;					\
5238aa34ab8SBenjamin Herrenschmidt label##_common:							\
5248aa34ab8SBenjamin Herrenschmidt 	EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN);		\
525a1d711c5SMichael Ellerman 	/* Volatile regs are potentially clobbered here */	\
526fe1952fcSBenjamin Herrenschmidt 	additions;						\
5278aa34ab8SBenjamin Herrenschmidt 	addi	r3,r1,STACK_FRAME_OVERHEAD;			\
5288aa34ab8SBenjamin Herrenschmidt 	bl	hdlr;						\
529fe1952fcSBenjamin Herrenschmidt 	b	ret
530fe1952fcSBenjamin Herrenschmidt 
531fe1952fcSBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON(trap, label, hdlr)			\
532fe1952fcSBenjamin Herrenschmidt 	EXCEPTION_COMMON(trap, label, hdlr, ret_from_except,	\
5339daf112bSMichael Ellerman 			 ADD_NVGPRS;ADD_RECONCILE)
5348aa34ab8SBenjamin Herrenschmidt 
5358aa34ab8SBenjamin Herrenschmidt /*
5368aa34ab8SBenjamin Herrenschmidt  * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
5377450f6f0SBenjamin Herrenschmidt  * in the idle task and therefore need the special idle handling
5387450f6f0SBenjamin Herrenschmidt  * (finish nap and runlatch)
5398aa34ab8SBenjamin Herrenschmidt  */
5407450f6f0SBenjamin Herrenschmidt #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr)		  \
541fe1952fcSBenjamin Herrenschmidt 	EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \
5429daf112bSMichael Ellerman 			 FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON)
5438aa34ab8SBenjamin Herrenschmidt 
5448aa34ab8SBenjamin Herrenschmidt /*
5458aa34ab8SBenjamin Herrenschmidt  * When the idle code in power4_idle puts the CPU into NAP mode,
5468aa34ab8SBenjamin Herrenschmidt  * it has to do so in a loop, and relies on the external interrupt
5478aa34ab8SBenjamin Herrenschmidt  * and decrementer interrupt entry code to get it out of the loop.
5488aa34ab8SBenjamin Herrenschmidt  * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
5498aa34ab8SBenjamin Herrenschmidt  * to signal that it is in the loop and needs help to get out.
5508aa34ab8SBenjamin Herrenschmidt  */
5518aa34ab8SBenjamin Herrenschmidt #ifdef CONFIG_PPC_970_NAP
5528aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP				\
5538aa34ab8SBenjamin Herrenschmidt BEGIN_FTR_SECTION				\
5549778b696SStuart Yoder 	CURRENT_THREAD_INFO(r11, r1);		\
5558aa34ab8SBenjamin Herrenschmidt 	ld	r9,TI_LOCAL_FLAGS(r11);		\
5568aa34ab8SBenjamin Herrenschmidt 	andi.	r10,r9,_TLF_NAPPING;		\
5578aa34ab8SBenjamin Herrenschmidt 	bnel	power4_fixup_nap;		\
5588aa34ab8SBenjamin Herrenschmidt END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
5598aa34ab8SBenjamin Herrenschmidt #else
5608aa34ab8SBenjamin Herrenschmidt #define FINISH_NAP
5618aa34ab8SBenjamin Herrenschmidt #endif
5628aa34ab8SBenjamin Herrenschmidt 
5638aa34ab8SBenjamin Herrenschmidt #endif	/* _ASM_POWERPC_EXCEPTION_H */
564