xref: /openbmc/linux/arch/powerpc/include/asm/ppc_asm.h (revision 7fa95f9a)
1b8b572e1SStephen Rothwell /*
2b8b572e1SStephen Rothwell  * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
3b8b572e1SStephen Rothwell  */
4b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PPC_ASM_H
5b8b572e1SStephen Rothwell #define _ASM_POWERPC_PPC_ASM_H
6b8b572e1SStephen Rothwell 
7b8b572e1SStephen Rothwell #include <linux/stringify.h>
8b8b572e1SStephen Rothwell #include <asm/asm-compat.h>
9b8b572e1SStephen Rothwell #include <asm/processor.h>
1016c57b36SKumar Gala #include <asm/ppc-opcode.h>
11cf9efce0SPaul Mackerras #include <asm/firmware.h>
122c86cd18SChristophe Leroy #include <asm/feature-fixups.h>
13b8b572e1SStephen Rothwell 
14e3f2c6c3SMichael Ellerman #ifdef __ASSEMBLY__
15b8b572e1SStephen Rothwell 
16b8b572e1SStephen Rothwell #define SZL			(BITS_PER_LONG/8)
17b8b572e1SStephen Rothwell 
18b8b572e1SStephen Rothwell /*
19b8b572e1SStephen Rothwell  * Stuff for accurate CPU time accounting.
20b8b572e1SStephen Rothwell  * These macros handle transitions between user and system state
21b8b572e1SStephen Rothwell  * in exception entry and exit and accumulate time to the
22b8b572e1SStephen Rothwell  * user_time and system_time fields in the paca.
23b8b572e1SStephen Rothwell  */
24b8b572e1SStephen Rothwell 
25abf917cdSFrederic Weisbecker #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
26c223c903SChristophe Leroy #define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb)
27c223c903SChristophe Leroy #define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb)
28cf9efce0SPaul Mackerras #define ACCOUNT_STOLEN_TIME
29b8b572e1SStephen Rothwell #else
30c223c903SChristophe Leroy #define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb)				\
31cf9efce0SPaul Mackerras 	MFTB(ra);			/* get timebase */		\
32c223c903SChristophe Leroy 	PPC_LL	rb, ACCOUNT_STARTTIME_USER(ptr);			\
33c223c903SChristophe Leroy 	PPC_STL	ra, ACCOUNT_STARTTIME(ptr);				\
34b8b572e1SStephen Rothwell 	subf	rb,rb,ra;		/* subtract start value */	\
35c223c903SChristophe Leroy 	PPC_LL	ra, ACCOUNT_USER_TIME(ptr);				\
36b8b572e1SStephen Rothwell 	add	ra,ra,rb;		/* add on to user time */	\
37c223c903SChristophe Leroy 	PPC_STL	ra, ACCOUNT_USER_TIME(ptr);				\
38b8b572e1SStephen Rothwell 
39c223c903SChristophe Leroy #define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb)				\
40cf9efce0SPaul Mackerras 	MFTB(ra);			/* get timebase */		\
41c223c903SChristophe Leroy 	PPC_LL	rb, ACCOUNT_STARTTIME(ptr);				\
42c223c903SChristophe Leroy 	PPC_STL	ra, ACCOUNT_STARTTIME_USER(ptr);			\
43b8b572e1SStephen Rothwell 	subf	rb,rb,ra;		/* subtract start value */	\
44c223c903SChristophe Leroy 	PPC_LL	ra, ACCOUNT_SYSTEM_TIME(ptr);				\
45cf9efce0SPaul Mackerras 	add	ra,ra,rb;		/* add on to system time */	\
46c223c903SChristophe Leroy 	PPC_STL	ra, ACCOUNT_SYSTEM_TIME(ptr)
47cf9efce0SPaul Mackerras 
48cf9efce0SPaul Mackerras #ifdef CONFIG_PPC_SPLPAR
49cf9efce0SPaul Mackerras #define ACCOUNT_STOLEN_TIME						\
50cf9efce0SPaul Mackerras BEGIN_FW_FTR_SECTION;							\
51cf9efce0SPaul Mackerras 	beq	33f;							\
52cf9efce0SPaul Mackerras 	/* from user - see if there are any DTL entries to process */	\
53cf9efce0SPaul Mackerras 	ld	r10,PACALPPACAPTR(r13);	/* get ptr to VPA */		\
54cf9efce0SPaul Mackerras 	ld	r11,PACA_DTL_RIDX(r13);	/* get log read index */	\
557ffcf8ecSAnton Blanchard 	addi	r10,r10,LPPACA_DTLIDX;					\
567ffcf8ecSAnton Blanchard 	LDX_BE	r10,0,r10;		/* get log write index */	\
57cf9efce0SPaul Mackerras 	cmpd	cr1,r11,r10;						\
58cf9efce0SPaul Mackerras 	beq+	cr1,33f;						\
59b1576fecSAnton Blanchard 	bl	accumulate_stolen_time;				\
60990118c8SBenjamin Herrenschmidt 	ld	r12,_MSR(r1);						\
61990118c8SBenjamin Herrenschmidt 	andi.	r10,r12,MSR_PR;		/* Restore cr0 (coming from user) */ \
62cf9efce0SPaul Mackerras 33:									\
63cf9efce0SPaul Mackerras END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
64cf9efce0SPaul Mackerras 
65cf9efce0SPaul Mackerras #else  /* CONFIG_PPC_SPLPAR */
66cf9efce0SPaul Mackerras #define ACCOUNT_STOLEN_TIME
67cf9efce0SPaul Mackerras 
68cf9efce0SPaul Mackerras #endif /* CONFIG_PPC_SPLPAR */
69cf9efce0SPaul Mackerras 
70abf917cdSFrederic Weisbecker #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
71b8b572e1SStephen Rothwell 
72b8b572e1SStephen Rothwell /*
73b8b572e1SStephen Rothwell  * Macros for storing registers into and loading registers from
74b8b572e1SStephen Rothwell  * exception frames.
75b8b572e1SStephen Rothwell  */
76b8b572e1SStephen Rothwell #ifdef __powerpc64__
77b8b572e1SStephen Rothwell #define SAVE_GPR(n, base)	std	n,GPR0+8*(n)(base)
78b8b572e1SStephen Rothwell #define REST_GPR(n, base)	ld	n,GPR0+8*(n)(base)
79b8b572e1SStephen Rothwell #define SAVE_NVGPRS(base)	SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
80b8b572e1SStephen Rothwell #define REST_NVGPRS(base)	REST_8GPRS(14, base); REST_10GPRS(22, base)
81b8b572e1SStephen Rothwell #else
82b8b572e1SStephen Rothwell #define SAVE_GPR(n, base)	stw	n,GPR0+4*(n)(base)
83b8b572e1SStephen Rothwell #define REST_GPR(n, base)	lwz	n,GPR0+4*(n)(base)
84a1f3ae3fSChristophe Leroy #define SAVE_NVGPRS(base)	stmw	13, GPR0+4*13(base)
85a1f3ae3fSChristophe Leroy #define REST_NVGPRS(base)	lmw	13, GPR0+4*13(base)
86b8b572e1SStephen Rothwell #endif
87b8b572e1SStephen Rothwell 
88b8b572e1SStephen Rothwell #define SAVE_2GPRS(n, base)	SAVE_GPR(n, base); SAVE_GPR(n+1, base)
89b8b572e1SStephen Rothwell #define SAVE_4GPRS(n, base)	SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
90b8b572e1SStephen Rothwell #define SAVE_8GPRS(n, base)	SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
91b8b572e1SStephen Rothwell #define SAVE_10GPRS(n, base)	SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
92b8b572e1SStephen Rothwell #define REST_2GPRS(n, base)	REST_GPR(n, base); REST_GPR(n+1, base)
93b8b572e1SStephen Rothwell #define REST_4GPRS(n, base)	REST_2GPRS(n, base); REST_2GPRS(n+2, base)
94b8b572e1SStephen Rothwell #define REST_8GPRS(n, base)	REST_4GPRS(n, base); REST_4GPRS(n+4, base)
95b8b572e1SStephen Rothwell #define REST_10GPRS(n, base)	REST_8GPRS(n, base); REST_2GPRS(n+8, base)
96b8b572e1SStephen Rothwell 
97de79f7b9SPaul Mackerras #define SAVE_FPR(n, base)	stfd	n,8*TS_FPRWIDTH*(n)(base)
98b8b572e1SStephen Rothwell #define SAVE_2FPRS(n, base)	SAVE_FPR(n, base); SAVE_FPR(n+1, base)
99b8b572e1SStephen Rothwell #define SAVE_4FPRS(n, base)	SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
100b8b572e1SStephen Rothwell #define SAVE_8FPRS(n, base)	SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
101b8b572e1SStephen Rothwell #define SAVE_16FPRS(n, base)	SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
102b8b572e1SStephen Rothwell #define SAVE_32FPRS(n, base)	SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
103de79f7b9SPaul Mackerras #define REST_FPR(n, base)	lfd	n,8*TS_FPRWIDTH*(n)(base)
104b8b572e1SStephen Rothwell #define REST_2FPRS(n, base)	REST_FPR(n, base); REST_FPR(n+1, base)
105b8b572e1SStephen Rothwell #define REST_4FPRS(n, base)	REST_2FPRS(n, base); REST_2FPRS(n+2, base)
106b8b572e1SStephen Rothwell #define REST_8FPRS(n, base)	REST_4FPRS(n, base); REST_4FPRS(n+4, base)
107b8b572e1SStephen Rothwell #define REST_16FPRS(n, base)	REST_8FPRS(n, base); REST_8FPRS(n+8, base)
108b8b572e1SStephen Rothwell #define REST_32FPRS(n, base)	REST_16FPRS(n, base); REST_16FPRS(n+16, base)
109b8b572e1SStephen Rothwell 
110de79f7b9SPaul Mackerras #define SAVE_VR(n,b,base)	li b,16*(n);  stvx n,base,b
111b8b572e1SStephen Rothwell #define SAVE_2VRS(n,b,base)	SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
112b8b572e1SStephen Rothwell #define SAVE_4VRS(n,b,base)	SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
113b8b572e1SStephen Rothwell #define SAVE_8VRS(n,b,base)	SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
114b8b572e1SStephen Rothwell #define SAVE_16VRS(n,b,base)	SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
115b8b572e1SStephen Rothwell #define SAVE_32VRS(n,b,base)	SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
116de79f7b9SPaul Mackerras #define REST_VR(n,b,base)	li b,16*(n); lvx n,base,b
117b8b572e1SStephen Rothwell #define REST_2VRS(n,b,base)	REST_VR(n,b,base); REST_VR(n+1,b,base)
118b8b572e1SStephen Rothwell #define REST_4VRS(n,b,base)	REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
119b8b572e1SStephen Rothwell #define REST_8VRS(n,b,base)	REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
120b8b572e1SStephen Rothwell #define REST_16VRS(n,b,base)	REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
121b8b572e1SStephen Rothwell #define REST_32VRS(n,b,base)	REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
122b8b572e1SStephen Rothwell 
123926f160fSAnton Blanchard #ifdef __BIG_ENDIAN__
124926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base)		STXVD2X(n,b,base)
125926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base)
126926f160fSAnton Blanchard #else
127926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base)		XXSWAPD(n,n);		\
128926f160fSAnton Blanchard 					STXVD2X(n,b,base);	\
129926f160fSAnton Blanchard 					XXSWAPD(n,n)
130926f160fSAnton Blanchard 
131926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base);	\
132926f160fSAnton Blanchard 					XXSWAPD(n,n)
133926f160fSAnton Blanchard #endif
134b8b572e1SStephen Rothwell /* Save the lower 32 VSRs in the thread VSR region */
1353ad26e5cSBenjamin Herrenschmidt #define SAVE_VSR(n,b,base)	li b,16*(n);  STXVD2X_ROT(n,R##base,R##b)
136b8b572e1SStephen Rothwell #define SAVE_2VSRS(n,b,base)	SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
137b8b572e1SStephen Rothwell #define SAVE_4VSRS(n,b,base)	SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
138b8b572e1SStephen Rothwell #define SAVE_8VSRS(n,b,base)	SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
139b8b572e1SStephen Rothwell #define SAVE_16VSRS(n,b,base)	SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
140b8b572e1SStephen Rothwell #define SAVE_32VSRS(n,b,base)	SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
1413ad26e5cSBenjamin Herrenschmidt #define REST_VSR(n,b,base)	li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
142b8b572e1SStephen Rothwell #define REST_2VSRS(n,b,base)	REST_VSR(n,b,base); REST_VSR(n+1,b,base)
143b8b572e1SStephen Rothwell #define REST_4VSRS(n,b,base)	REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
144b8b572e1SStephen Rothwell #define REST_8VSRS(n,b,base)	REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
145b8b572e1SStephen Rothwell #define REST_16VSRS(n,b,base)	REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
146b8b572e1SStephen Rothwell #define REST_32VSRS(n,b,base)	REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
147b8b572e1SStephen Rothwell 
148c51584d5SScott Wood /*
149c51584d5SScott Wood  * b = base register for addressing, o = base offset from register of 1st EVR
150c51584d5SScott Wood  * n = first EVR, s = scratch
151c51584d5SScott Wood  */
152c51584d5SScott Wood #define SAVE_EVR(n,s,b,o)	evmergehi s,s,n; stw s,o+4*(n)(b)
153c51584d5SScott Wood #define SAVE_2EVRS(n,s,b,o)	SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
154c51584d5SScott Wood #define SAVE_4EVRS(n,s,b,o)	SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
155c51584d5SScott Wood #define SAVE_8EVRS(n,s,b,o)	SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
156c51584d5SScott Wood #define SAVE_16EVRS(n,s,b,o)	SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
157c51584d5SScott Wood #define SAVE_32EVRS(n,s,b,o)	SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
158c51584d5SScott Wood #define REST_EVR(n,s,b,o)	lwz s,o+4*(n)(b); evmergelo n,s,n
159c51584d5SScott Wood #define REST_2EVRS(n,s,b,o)	REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
160c51584d5SScott Wood #define REST_4EVRS(n,s,b,o)	REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
161c51584d5SScott Wood #define REST_8EVRS(n,s,b,o)	REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
162c51584d5SScott Wood #define REST_16EVRS(n,s,b,o)	REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
163c51584d5SScott Wood #define REST_32EVRS(n,s,b,o)	REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
164b8b572e1SStephen Rothwell 
165b8b572e1SStephen Rothwell /* Macros to adjust thread priority for hardware multithreading */
166b8b572e1SStephen Rothwell #define HMT_VERY_LOW	or	31,31,31	# very low priority
167b8b572e1SStephen Rothwell #define HMT_LOW		or	1,1,1
168b8b572e1SStephen Rothwell #define HMT_MEDIUM_LOW  or	6,6,6		# medium low priority
169b8b572e1SStephen Rothwell #define HMT_MEDIUM	or	2,2,2
170b8b572e1SStephen Rothwell #define HMT_MEDIUM_HIGH or	5,5,5		# medium high priority
171b8b572e1SStephen Rothwell #define HMT_HIGH	or	3,3,3
17250fb8ebeSBenjamin Herrenschmidt #define HMT_EXTRA_HIGH	or	7,7,7		# power7 only
173b8b572e1SStephen Rothwell 
174d72be892SMichael Neuling #ifdef CONFIG_PPC64
175d72be892SMichael Neuling #define ULONG_SIZE 	8
176d72be892SMichael Neuling #else
177d72be892SMichael Neuling #define ULONG_SIZE	4
178d72be892SMichael Neuling #endif
1790b7673c3SMichael Neuling #define __VCPU_GPR(n)	(VCPU_GPRS + (n * ULONG_SIZE))
1800b7673c3SMichael Neuling #define VCPU_GPR(n)	__VCPU_GPR(__REG_##n)
181d72be892SMichael Neuling 
182b8b572e1SStephen Rothwell #ifdef __KERNEL__
183b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
184b8b572e1SStephen Rothwell 
18544ce6a5eSMichael Neuling #define STACKFRAMESIZE 256
1860b7673c3SMichael Neuling #define __STK_REG(i)   (112 + ((i)-14)*8)
1870b7673c3SMichael Neuling #define STK_REG(i)     __STK_REG(__REG_##i)
18844ce6a5eSMichael Neuling 
189f55d9665SMichael Ellerman #ifdef PPC64_ELF_ABI_v2
1906403105bSAnton Blanchard #define STK_GOT		24
191b37c10d1SAnton Blanchard #define __STK_PARAM(i)	(32 + ((i)-3)*8)
192b37c10d1SAnton Blanchard #else
1936403105bSAnton Blanchard #define STK_GOT		40
1940b7673c3SMichael Neuling #define __STK_PARAM(i)	(48 + ((i)-3)*8)
195b37c10d1SAnton Blanchard #endif
1960b7673c3SMichael Neuling #define STK_PARAM(i)	__STK_PARAM(__REG_##i)
19744ce6a5eSMichael Neuling 
198f55d9665SMichael Ellerman #ifdef PPC64_ELF_ABI_v2
1997167af7cSAnton Blanchard 
2007167af7cSAnton Blanchard #define _GLOBAL(name) \
2017167af7cSAnton Blanchard 	.align 2 ; \
2027167af7cSAnton Blanchard 	.type name,@function; \
2037167af7cSAnton Blanchard 	.globl name; \
2047167af7cSAnton Blanchard name:
2057167af7cSAnton Blanchard 
206169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) \
207169c7ceeSAnton Blanchard 	.align 2 ; \
208169c7ceeSAnton Blanchard 	.type name,@function; \
209169c7ceeSAnton Blanchard 	.globl name; \
210169c7ceeSAnton Blanchard name: \
211169c7ceeSAnton Blanchard 0:	addis r2,r12,(.TOC.-0b)@ha; \
212169c7ceeSAnton Blanchard 	addi r2,r2,(.TOC.-0b)@l; \
213169c7ceeSAnton Blanchard 	.localentry name,.-name
214169c7ceeSAnton Blanchard 
2157167af7cSAnton Blanchard #define DOTSYM(a)	a
2167167af7cSAnton Blanchard 
2177167af7cSAnton Blanchard #else
2187167af7cSAnton Blanchard 
219b8b572e1SStephen Rothwell #define XGLUE(a,b) a##b
220b8b572e1SStephen Rothwell #define GLUE(a,b) XGLUE(a,b)
221b8b572e1SStephen Rothwell 
222b8b572e1SStephen Rothwell #define _GLOBAL(name) \
223b8b572e1SStephen Rothwell 	.align 2 ; \
224b8b572e1SStephen Rothwell 	.globl name; \
225b8b572e1SStephen Rothwell 	.globl GLUE(.,name); \
226bea2dcccSMichael Ellerman 	.pushsection ".opd","aw"; \
227b8b572e1SStephen Rothwell name: \
228b8b572e1SStephen Rothwell 	.quad GLUE(.,name); \
229b8b572e1SStephen Rothwell 	.quad .TOC.@tocbase; \
230b8b572e1SStephen Rothwell 	.quad 0; \
231bea2dcccSMichael Ellerman 	.popsection; \
232b8b572e1SStephen Rothwell 	.type GLUE(.,name),@function; \
233b8b572e1SStephen Rothwell GLUE(.,name):
234b8b572e1SStephen Rothwell 
235169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) _GLOBAL(name)
236169c7ceeSAnton Blanchard 
237c1fb0194SAnton Blanchard #define DOTSYM(a)	GLUE(.,a)
238c1fb0194SAnton Blanchard 
2397167af7cSAnton Blanchard #endif
2407167af7cSAnton Blanchard 
241b8b572e1SStephen Rothwell #else /* 32-bit */
242b8b572e1SStephen Rothwell 
243b8b572e1SStephen Rothwell #define _ENTRY(n)	\
244b8b572e1SStephen Rothwell 	.globl n;	\
245b8b572e1SStephen Rothwell n:
246b8b572e1SStephen Rothwell 
247b8b572e1SStephen Rothwell #define _GLOBAL(n)	\
248b8b572e1SStephen Rothwell 	.stabs __stringify(n:F-1),N_FUN,0,0,n;\
249b8b572e1SStephen Rothwell 	.globl n;	\
250b8b572e1SStephen Rothwell n:
251b8b572e1SStephen Rothwell 
2529715a2e8SAlexander Graf #define _GLOBAL_TOC(name) _GLOBAL(name)
2539715a2e8SAlexander Graf 
254b8b572e1SStephen Rothwell #endif
255b8b572e1SStephen Rothwell 
2566f698df1SNicholas Piggin /*
2576f698df1SNicholas Piggin  * __kprobes (the C annotation) puts the symbol into the .kprobes.text
2586f698df1SNicholas Piggin  * section, which gets emitted at the end of regular text.
2596f698df1SNicholas Piggin  *
2606f698df1SNicholas Piggin  * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
2616f698df1SNicholas Piggin  * a blacklist. The former is for core kprobe functions/data, the
2626f698df1SNicholas Piggin  * latter is for those that incdentially must be excluded from probing
2636f698df1SNicholas Piggin  * and allows them to be linked at more optimal location within text.
2646f698df1SNicholas Piggin  */
265c0a51491SNicholas Piggin #ifdef CONFIG_KPROBES
2666f698df1SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry)			\
2676f698df1SNicholas Piggin 	.pushsection "_kprobe_blacklist","aw";		\
2686f698df1SNicholas Piggin 	PPC_LONG (entry) ;				\
2696f698df1SNicholas Piggin 	.popsection
270c0a51491SNicholas Piggin #else
271c0a51491SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry)
272c0a51491SNicholas Piggin #endif
2736f698df1SNicholas Piggin 
274151f2511SAnton Blanchard #define FUNC_START(name)	_GLOBAL(name)
275151f2511SAnton Blanchard #define FUNC_END(name)
276151f2511SAnton Blanchard 
277b8b572e1SStephen Rothwell /*
278b8b572e1SStephen Rothwell  * LOAD_REG_IMMEDIATE(rn, expr)
279b8b572e1SStephen Rothwell  *   Loads the value of the constant expression 'expr' into register 'rn'
280b8b572e1SStephen Rothwell  *   using immediate instructions only.  Use this when it's important not
281b8b572e1SStephen Rothwell  *   to reference other data (i.e. on ppc64 when the TOC pointer is not
282e31aa453SPaul Mackerras  *   valid) and when 'expr' is a constant or absolute address.
283b8b572e1SStephen Rothwell  *
284b8b572e1SStephen Rothwell  * LOAD_REG_ADDR(rn, name)
285b8b572e1SStephen Rothwell  *   Loads the address of label 'name' into register 'rn'.  Use this when
286b8b572e1SStephen Rothwell  *   you don't particularly need immediate instructions only, but you need
287b8b572e1SStephen Rothwell  *   the whole address in one register (e.g. it's a structure address and
288b8b572e1SStephen Rothwell  *   you want to access various offsets within it).  On ppc32 this is
289b8b572e1SStephen Rothwell  *   identical to LOAD_REG_IMMEDIATE.
290b8b572e1SStephen Rothwell  *
2911c49abecSKevin Hao  * LOAD_REG_ADDR_PIC(rn, name)
2921c49abecSKevin Hao  *   Loads the address of label 'name' into register 'run'. Use this when
2931c49abecSKevin Hao  *   the kernel doesn't run at the linked or relocated address. Please
2941c49abecSKevin Hao  *   note that this macro will clobber the lr register.
2951c49abecSKevin Hao  *
296b8b572e1SStephen Rothwell  * LOAD_REG_ADDRBASE(rn, name)
297b8b572e1SStephen Rothwell  * ADDROFF(name)
298b8b572e1SStephen Rothwell  *   LOAD_REG_ADDRBASE loads part of the address of label 'name' into
299b8b572e1SStephen Rothwell  *   register 'rn'.  ADDROFF(name) returns the remainder of the address as
300b8b572e1SStephen Rothwell  *   a constant expression.  ADDROFF(name) is a signed expression < 16 bits
301b8b572e1SStephen Rothwell  *   in size, so is suitable for use directly as an offset in load and store
302b8b572e1SStephen Rothwell  *   instructions.  Use this when loading/storing a single word or less as:
303b8b572e1SStephen Rothwell  *      LOAD_REG_ADDRBASE(rX, name)
304b8b572e1SStephen Rothwell  *      ld	rY,ADDROFF(name)(rX)
305b8b572e1SStephen Rothwell  */
3061c49abecSKevin Hao 
3071c49abecSKevin Hao /* Be careful, this will clobber the lr register. */
3081c49abecSKevin Hao #define LOAD_REG_ADDR_PIC(reg, name)		\
3091c49abecSKevin Hao 	bl	0f;				\
3101c49abecSKevin Hao 0:	mflr	reg;				\
3111c49abecSKevin Hao 	addis	reg,reg,(name - 0b)@ha;		\
3121c49abecSKevin Hao 	addi	reg,reg,(name - 0b)@l;
3131c49abecSKevin Hao 
314c691b4b8SChristophe Leroy #if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH)
3157998eb3dSGuenter Roeck #define __AS_ATHIGH high
3167998eb3dSGuenter Roeck #else
3177998eb3dSGuenter Roeck #define __AS_ATHIGH h
3187998eb3dSGuenter Roeck #endif
319c691b4b8SChristophe Leroy 
320c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE_32 r, x
321c691b4b8SChristophe Leroy 	.if (\x) >= 0x8000 || (\x) < -0x8000
322c691b4b8SChristophe Leroy 		lis \r, (\x)@__AS_ATHIGH
323c691b4b8SChristophe Leroy 		.if (\x) & 0xffff != 0
324c691b4b8SChristophe Leroy 			ori \r, \r, (\x)@l
325c691b4b8SChristophe Leroy 		.endif
326c691b4b8SChristophe Leroy 	.else
327c691b4b8SChristophe Leroy 		li \r, (\x)@l
328c691b4b8SChristophe Leroy 	.endif
329c691b4b8SChristophe Leroy .endm
330c691b4b8SChristophe Leroy 
331c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE r, x
332c691b4b8SChristophe Leroy 	.if (\x) >= 0x80000000 || (\x) < -0x80000000
333c691b4b8SChristophe Leroy 		__LOAD_REG_IMMEDIATE_32 \r, (\x) >> 32
334c691b4b8SChristophe Leroy 		sldi	\r, \r, 32
335c691b4b8SChristophe Leroy 		.if (\x) & 0xffff0000 != 0
336c691b4b8SChristophe Leroy 			oris \r, \r, (\x)@__AS_ATHIGH
337c691b4b8SChristophe Leroy 		.endif
338c691b4b8SChristophe Leroy 		.if (\x) & 0xffff != 0
339c691b4b8SChristophe Leroy 			ori \r, \r, (\x)@l
340c691b4b8SChristophe Leroy 		.endif
341c691b4b8SChristophe Leroy 	.else
342c691b4b8SChristophe Leroy 		__LOAD_REG_IMMEDIATE_32 \r, \x
343c691b4b8SChristophe Leroy 	.endif
344c691b4b8SChristophe Leroy .endm
345c691b4b8SChristophe Leroy 
346c691b4b8SChristophe Leroy #ifdef __powerpc64__
347c691b4b8SChristophe Leroy 
348c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE reg, expr
349c691b4b8SChristophe Leroy 
350d7fb5b18SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg, tmp, expr)	\
351d7fb5b18SChristophe Leroy 	lis	tmp, (expr)@highest;		\
352d7fb5b18SChristophe Leroy 	lis	reg, (expr)@__AS_ATHIGH;	\
353d7fb5b18SChristophe Leroy 	ori	tmp, tmp, (expr)@higher;	\
354d7fb5b18SChristophe Leroy 	ori	reg, reg, (expr)@l;		\
355d7fb5b18SChristophe Leroy 	rldimi	reg, tmp, 32, 0
356b8b572e1SStephen Rothwell 
357b8b572e1SStephen Rothwell #define LOAD_REG_ADDR(reg,name)			\
358564aa5cfSMichael Neuling 	ld	reg,name@got(r2)
359b8b572e1SStephen Rothwell 
360b8b572e1SStephen Rothwell #define LOAD_REG_ADDRBASE(reg,name)	LOAD_REG_ADDR(reg,name)
361b8b572e1SStephen Rothwell #define ADDROFF(name)			0
362b8b572e1SStephen Rothwell 
363b8b572e1SStephen Rothwell /* offsets for stack frame layout */
364b8b572e1SStephen Rothwell #define LRSAVE	16
365b8b572e1SStephen Rothwell 
366b8b572e1SStephen Rothwell #else /* 32-bit */
367b8b572e1SStephen Rothwell 
368c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr
369c691b4b8SChristophe Leroy 
370c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg,expr)		\
371564aa5cfSMichael Neuling 	lis	reg,(expr)@ha;		\
372564aa5cfSMichael Neuling 	addi	reg,reg,(expr)@l;
373b8b572e1SStephen Rothwell 
374c691b4b8SChristophe Leroy #define LOAD_REG_ADDR(reg,name)		LOAD_REG_IMMEDIATE_SYM(reg, name)
375b8b572e1SStephen Rothwell 
376564aa5cfSMichael Neuling #define LOAD_REG_ADDRBASE(reg, name)	lis	reg,name@ha
377b8b572e1SStephen Rothwell #define ADDROFF(name)			name@l
378b8b572e1SStephen Rothwell 
379b8b572e1SStephen Rothwell /* offsets for stack frame layout */
380b8b572e1SStephen Rothwell #define LRSAVE	4
381b8b572e1SStephen Rothwell 
382b8b572e1SStephen Rothwell #endif
383b8b572e1SStephen Rothwell 
384b8b572e1SStephen Rothwell /* various errata or part fixups */
385b8b572e1SStephen Rothwell #ifdef CONFIG_PPC601_SYNC_FIX
38612c3f1fdSChristophe Leroy #define SYNC		sync; isync
38712c3f1fdSChristophe Leroy #define SYNC_601	sync
38812c3f1fdSChristophe Leroy #define ISYNC_601	isync
389b8b572e1SStephen Rothwell #else
390b8b572e1SStephen Rothwell #define	SYNC
391b8b572e1SStephen Rothwell #define SYNC_601
392b8b572e1SStephen Rothwell #define ISYNC_601
393b8b572e1SStephen Rothwell #endif
394b8b572e1SStephen Rothwell 
395d52459caSScott Wood #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
396b8b572e1SStephen Rothwell #define MFTB(dest)			\
397beb2dc0aSScott Wood 90:	mfspr dest, SPRN_TBRL;		\
398b8b572e1SStephen Rothwell BEGIN_FTR_SECTION_NESTED(96);		\
399b8b572e1SStephen Rothwell 	cmpwi dest,0;			\
400b8b572e1SStephen Rothwell 	beq-  90b;			\
401b8b572e1SStephen Rothwell END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
402b8b572e1SStephen Rothwell #else
40372e4b2cdSChristophe Leroy #define MFTB(dest)			MFTBL(dest)
40472e4b2cdSChristophe Leroy #endif
40572e4b2cdSChristophe Leroy 
40672e4b2cdSChristophe Leroy #ifdef CONFIG_PPC_8xx
40772e4b2cdSChristophe Leroy #define MFTBL(dest)			mftb dest
40872e4b2cdSChristophe Leroy #define MFTBU(dest)			mftbu dest
40972e4b2cdSChristophe Leroy #else
41072e4b2cdSChristophe Leroy #define MFTBL(dest)			mfspr dest, SPRN_TBRL
41172e4b2cdSChristophe Leroy #define MFTBU(dest)			mfspr dest, SPRN_TBRU
412b8b572e1SStephen Rothwell #endif
413b8b572e1SStephen Rothwell 
414b8b572e1SStephen Rothwell /* tlbsync is not implemented on 601 */
41512c3f1fdSChristophe Leroy #if !defined(CONFIG_SMP) || defined(CONFIG_PPC_BOOK3S_601)
41612c3f1fdSChristophe Leroy #define TLBSYNC
41712c3f1fdSChristophe Leroy #else
41812c3f1fdSChristophe Leroy #define TLBSYNC		tlbsync; sync
419b8b572e1SStephen Rothwell #endif
420b8b572e1SStephen Rothwell 
421694caf02SAnton Blanchard #ifdef CONFIG_PPC64
422694caf02SAnton Blanchard #define MTOCRF(FXM, RS)			\
423694caf02SAnton Blanchard 	BEGIN_FTR_SECTION_NESTED(848);	\
42486e32fdcSMichael Neuling 	mtcrf	(FXM), RS;		\
425694caf02SAnton Blanchard 	FTR_SECTION_ELSE_NESTED(848);	\
42686e32fdcSMichael Neuling 	mtocrf (FXM), RS;		\
427694caf02SAnton Blanchard 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
428694caf02SAnton Blanchard #endif
429b8b572e1SStephen Rothwell 
430b8b572e1SStephen Rothwell /*
431b8b572e1SStephen Rothwell  * This instruction is not implemented on the PPC 603 or 601; however, on
432b8b572e1SStephen Rothwell  * the 403GCX and 405GP tlbia IS defined and tlbie is not.
433b8b572e1SStephen Rothwell  * All of these instructions exist in the 8xx, they have magical powers,
434b8b572e1SStephen Rothwell  * and they must be used.
435b8b572e1SStephen Rothwell  */
436b8b572e1SStephen Rothwell 
437968159c0SChristophe Leroy #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx)
438b8b572e1SStephen Rothwell #define tlbia					\
439b8b572e1SStephen Rothwell 	li	r4,1024;			\
440b8b572e1SStephen Rothwell 	mtctr	r4;				\
441b8b572e1SStephen Rothwell 	lis	r4,KERNELBASE@h;		\
442e3824e42SRussell Currey 	.machine push;				\
443e3824e42SRussell Currey 	.machine "power4";			\
444b8b572e1SStephen Rothwell 0:	tlbie	r4;				\
445e3824e42SRussell Currey 	.machine pop;				\
446b8b572e1SStephen Rothwell 	addi	r4,r4,0x1000;			\
447b8b572e1SStephen Rothwell 	bdnz	0b
448b8b572e1SStephen Rothwell #endif
449b8b572e1SStephen Rothwell 
450b8b572e1SStephen Rothwell 
451b8b572e1SStephen Rothwell #ifdef CONFIG_IBM440EP_ERR42
452b8b572e1SStephen Rothwell #define PPC440EP_ERR42 isync
453b8b572e1SStephen Rothwell #else
454b8b572e1SStephen Rothwell #define PPC440EP_ERR42
455b8b572e1SStephen Rothwell #endif
456b8b572e1SStephen Rothwell 
457a515348fSMichael Neuling /* The following stops all load and store data streams associated with stream
458a515348fSMichael Neuling  * ID (ie. streams created explicitly).  The embedded and server mnemonics for
45915a3204dSNicholas Piggin  * dcbt are different so this must only be used for server.
460a515348fSMichael Neuling  */
46115a3204dSNicholas Piggin #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch)	\
462a515348fSMichael Neuling        lis     scratch,0x60000000@h;			\
46315a3204dSNicholas Piggin        dcbt    0,scratch,0b01010
464a515348fSMichael Neuling 
46544c58cccSBenjamin Herrenschmidt /*
46644c58cccSBenjamin Herrenschmidt  * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
46744c58cccSBenjamin Herrenschmidt  * keep the address intact to be compatible with code shared with
46844c58cccSBenjamin Herrenschmidt  * 32-bit classic.
46944c58cccSBenjamin Herrenschmidt  *
47044c58cccSBenjamin Herrenschmidt  * On the other hand, I find it useful to have them behave as expected
47144c58cccSBenjamin Herrenschmidt  * by their name (ie always do the addition) on 64-bit BookE
47244c58cccSBenjamin Herrenschmidt  */
47344c58cccSBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
474b8b572e1SStephen Rothwell #define toreal(rd)
475b8b572e1SStephen Rothwell #define fromreal(rd)
476b8b572e1SStephen Rothwell 
477b8b572e1SStephen Rothwell /*
478b8b572e1SStephen Rothwell  * We use addis to ensure compatibility with the "classic" ppc versions of
479b8b572e1SStephen Rothwell  * these macros, which use rs = 0 to get the tophys offset in rd, rather than
480b8b572e1SStephen Rothwell  * converting the address in r0, and so this version has to do that too
481b8b572e1SStephen Rothwell  * (i.e. set register rd to 0 when rs == 0).
482b8b572e1SStephen Rothwell  */
483b8b572e1SStephen Rothwell #define tophys(rd,rs)				\
484b8b572e1SStephen Rothwell 	addis	rd,rs,0
485b8b572e1SStephen Rothwell 
486b8b572e1SStephen Rothwell #define tovirt(rd,rs)				\
487b8b572e1SStephen Rothwell 	addis	rd,rs,0
488b8b572e1SStephen Rothwell 
489b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC64)
490b8b572e1SStephen Rothwell #define toreal(rd)		/* we can access c000... in real mode */
491b8b572e1SStephen Rothwell #define fromreal(rd)
492b8b572e1SStephen Rothwell 
493b8b572e1SStephen Rothwell #define tophys(rd,rs)                           \
494b8b572e1SStephen Rothwell 	clrldi	rd,rs,2
495b8b572e1SStephen Rothwell 
496b8b572e1SStephen Rothwell #define tovirt(rd,rs)                           \
497b8b572e1SStephen Rothwell 	rotldi	rd,rs,16;			\
498b8b572e1SStephen Rothwell 	ori	rd,rd,((KERNELBASE>>48)&0xFFFF);\
499b8b572e1SStephen Rothwell 	rotldi	rd,rd,48
500b8b572e1SStephen Rothwell #else
501b8b572e1SStephen Rothwell #define toreal(rd)	tophys(rd,rd)
502b8b572e1SStephen Rothwell #define fromreal(rd)	tovirt(rd,rd)
503b8b572e1SStephen Rothwell 
504c62ce9efSChristophe Leroy #define tophys(rd, rs)	addis	rd, rs, -PAGE_OFFSET@h
505c62ce9efSChristophe Leroy #define tovirt(rd, rs)	addis	rd, rs, PAGE_OFFSET@h
506b8b572e1SStephen Rothwell #endif
507b8b572e1SStephen Rothwell 
50844c58cccSBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S_64
509b8b572e1SStephen Rothwell #define RFI		rfid
510b8b572e1SStephen Rothwell #define MTMSRD(r)	mtmsrd	r
511b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg)	mtmsrd	reg,1
512b8b572e1SStephen Rothwell #else
513b8b572e1SStephen Rothwell #ifndef CONFIG_40x
514b8b572e1SStephen Rothwell #define	RFI		rfi
515b8b572e1SStephen Rothwell #else
516b8b572e1SStephen Rothwell #define RFI		rfi; b .	/* Prevent prefetch past rfi */
517b8b572e1SStephen Rothwell #endif
518b8b572e1SStephen Rothwell #define MTMSRD(r)	mtmsr	r
519b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg)	mtmsr	reg
520b8b572e1SStephen Rothwell #endif
521b8b572e1SStephen Rothwell 
522b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
523b8b572e1SStephen Rothwell 
524b8b572e1SStephen Rothwell /* The boring bits... */
525b8b572e1SStephen Rothwell 
526b8b572e1SStephen Rothwell /* Condition Register Bit Fields */
527b8b572e1SStephen Rothwell 
528b8b572e1SStephen Rothwell #define	cr0	0
529b8b572e1SStephen Rothwell #define	cr1	1
530b8b572e1SStephen Rothwell #define	cr2	2
531b8b572e1SStephen Rothwell #define	cr3	3
532b8b572e1SStephen Rothwell #define	cr4	4
533b8b572e1SStephen Rothwell #define	cr5	5
534b8b572e1SStephen Rothwell #define	cr6	6
535b8b572e1SStephen Rothwell #define	cr7	7
536b8b572e1SStephen Rothwell 
537b8b572e1SStephen Rothwell 
5389a13a524SMichael Neuling /*
5399a13a524SMichael Neuling  * General Purpose Registers (GPRs)
5409a13a524SMichael Neuling  *
5419a13a524SMichael Neuling  * The lower case r0-r31 should be used in preference to the upper
5429a13a524SMichael Neuling  * case R0-R31 as they provide more error checking in the assembler.
5439a13a524SMichael Neuling  * Use R0-31 only when really nessesary.
5449a13a524SMichael Neuling  */
545b8b572e1SStephen Rothwell 
5469a13a524SMichael Neuling #define	r0	%r0
5479a13a524SMichael Neuling #define	r1	%r1
5489a13a524SMichael Neuling #define	r2	%r2
5499a13a524SMichael Neuling #define	r3	%r3
5509a13a524SMichael Neuling #define	r4	%r4
5519a13a524SMichael Neuling #define	r5	%r5
5529a13a524SMichael Neuling #define	r6	%r6
5539a13a524SMichael Neuling #define	r7	%r7
5549a13a524SMichael Neuling #define	r8	%r8
5559a13a524SMichael Neuling #define	r9	%r9
5569a13a524SMichael Neuling #define	r10	%r10
5579a13a524SMichael Neuling #define	r11	%r11
5589a13a524SMichael Neuling #define	r12	%r12
5599a13a524SMichael Neuling #define	r13	%r13
5609a13a524SMichael Neuling #define	r14	%r14
5619a13a524SMichael Neuling #define	r15	%r15
5629a13a524SMichael Neuling #define	r16	%r16
5639a13a524SMichael Neuling #define	r17	%r17
5649a13a524SMichael Neuling #define	r18	%r18
5659a13a524SMichael Neuling #define	r19	%r19
5669a13a524SMichael Neuling #define	r20	%r20
5679a13a524SMichael Neuling #define	r21	%r21
5689a13a524SMichael Neuling #define	r22	%r22
5699a13a524SMichael Neuling #define	r23	%r23
5709a13a524SMichael Neuling #define	r24	%r24
5719a13a524SMichael Neuling #define	r25	%r25
5729a13a524SMichael Neuling #define	r26	%r26
5739a13a524SMichael Neuling #define	r27	%r27
5749a13a524SMichael Neuling #define	r28	%r28
5759a13a524SMichael Neuling #define	r29	%r29
5769a13a524SMichael Neuling #define	r30	%r30
5779a13a524SMichael Neuling #define	r31	%r31
578b8b572e1SStephen Rothwell 
579b8b572e1SStephen Rothwell 
580b8b572e1SStephen Rothwell /* Floating Point Registers (FPRs) */
581b8b572e1SStephen Rothwell 
582b8b572e1SStephen Rothwell #define	fr0	0
583b8b572e1SStephen Rothwell #define	fr1	1
584b8b572e1SStephen Rothwell #define	fr2	2
585b8b572e1SStephen Rothwell #define	fr3	3
586b8b572e1SStephen Rothwell #define	fr4	4
587b8b572e1SStephen Rothwell #define	fr5	5
588b8b572e1SStephen Rothwell #define	fr6	6
589b8b572e1SStephen Rothwell #define	fr7	7
590b8b572e1SStephen Rothwell #define	fr8	8
591b8b572e1SStephen Rothwell #define	fr9	9
592b8b572e1SStephen Rothwell #define	fr10	10
593b8b572e1SStephen Rothwell #define	fr11	11
594b8b572e1SStephen Rothwell #define	fr12	12
595b8b572e1SStephen Rothwell #define	fr13	13
596b8b572e1SStephen Rothwell #define	fr14	14
597b8b572e1SStephen Rothwell #define	fr15	15
598b8b572e1SStephen Rothwell #define	fr16	16
599b8b572e1SStephen Rothwell #define	fr17	17
600b8b572e1SStephen Rothwell #define	fr18	18
601b8b572e1SStephen Rothwell #define	fr19	19
602b8b572e1SStephen Rothwell #define	fr20	20
603b8b572e1SStephen Rothwell #define	fr21	21
604b8b572e1SStephen Rothwell #define	fr22	22
605b8b572e1SStephen Rothwell #define	fr23	23
606b8b572e1SStephen Rothwell #define	fr24	24
607b8b572e1SStephen Rothwell #define	fr25	25
608b8b572e1SStephen Rothwell #define	fr26	26
609b8b572e1SStephen Rothwell #define	fr27	27
610b8b572e1SStephen Rothwell #define	fr28	28
611b8b572e1SStephen Rothwell #define	fr29	29
612b8b572e1SStephen Rothwell #define	fr30	30
613b8b572e1SStephen Rothwell #define	fr31	31
614b8b572e1SStephen Rothwell 
615b8b572e1SStephen Rothwell /* AltiVec Registers (VPRs) */
616b8b572e1SStephen Rothwell 
617c2ce6f9fSAnton Blanchard #define	v0	0
618c2ce6f9fSAnton Blanchard #define	v1	1
619c2ce6f9fSAnton Blanchard #define	v2	2
620c2ce6f9fSAnton Blanchard #define	v3	3
621c2ce6f9fSAnton Blanchard #define	v4	4
622c2ce6f9fSAnton Blanchard #define	v5	5
623c2ce6f9fSAnton Blanchard #define	v6	6
624c2ce6f9fSAnton Blanchard #define	v7	7
625c2ce6f9fSAnton Blanchard #define	v8	8
626c2ce6f9fSAnton Blanchard #define	v9	9
627c2ce6f9fSAnton Blanchard #define	v10	10
628c2ce6f9fSAnton Blanchard #define	v11	11
629c2ce6f9fSAnton Blanchard #define	v12	12
630c2ce6f9fSAnton Blanchard #define	v13	13
631c2ce6f9fSAnton Blanchard #define	v14	14
632c2ce6f9fSAnton Blanchard #define	v15	15
633c2ce6f9fSAnton Blanchard #define	v16	16
634c2ce6f9fSAnton Blanchard #define	v17	17
635c2ce6f9fSAnton Blanchard #define	v18	18
636c2ce6f9fSAnton Blanchard #define	v19	19
637c2ce6f9fSAnton Blanchard #define	v20	20
638c2ce6f9fSAnton Blanchard #define	v21	21
639c2ce6f9fSAnton Blanchard #define	v22	22
640c2ce6f9fSAnton Blanchard #define	v23	23
641c2ce6f9fSAnton Blanchard #define	v24	24
642c2ce6f9fSAnton Blanchard #define	v25	25
643c2ce6f9fSAnton Blanchard #define	v26	26
644c2ce6f9fSAnton Blanchard #define	v27	27
645c2ce6f9fSAnton Blanchard #define	v28	28
646c2ce6f9fSAnton Blanchard #define	v29	29
647c2ce6f9fSAnton Blanchard #define	v30	30
648c2ce6f9fSAnton Blanchard #define	v31	31
649b8b572e1SStephen Rothwell 
650b8b572e1SStephen Rothwell /* VSX Registers (VSRs) */
651b8b572e1SStephen Rothwell 
652df99e6ebSAnton Blanchard #define	vs0	0
653df99e6ebSAnton Blanchard #define	vs1	1
654df99e6ebSAnton Blanchard #define	vs2	2
655df99e6ebSAnton Blanchard #define	vs3	3
656df99e6ebSAnton Blanchard #define	vs4	4
657df99e6ebSAnton Blanchard #define	vs5	5
658df99e6ebSAnton Blanchard #define	vs6	6
659df99e6ebSAnton Blanchard #define	vs7	7
660df99e6ebSAnton Blanchard #define	vs8	8
661df99e6ebSAnton Blanchard #define	vs9	9
662df99e6ebSAnton Blanchard #define	vs10	10
663df99e6ebSAnton Blanchard #define	vs11	11
664df99e6ebSAnton Blanchard #define	vs12	12
665df99e6ebSAnton Blanchard #define	vs13	13
666df99e6ebSAnton Blanchard #define	vs14	14
667df99e6ebSAnton Blanchard #define	vs15	15
668df99e6ebSAnton Blanchard #define	vs16	16
669df99e6ebSAnton Blanchard #define	vs17	17
670df99e6ebSAnton Blanchard #define	vs18	18
671df99e6ebSAnton Blanchard #define	vs19	19
672df99e6ebSAnton Blanchard #define	vs20	20
673df99e6ebSAnton Blanchard #define	vs21	21
674df99e6ebSAnton Blanchard #define	vs22	22
675df99e6ebSAnton Blanchard #define	vs23	23
676df99e6ebSAnton Blanchard #define	vs24	24
677df99e6ebSAnton Blanchard #define	vs25	25
678df99e6ebSAnton Blanchard #define	vs26	26
679df99e6ebSAnton Blanchard #define	vs27	27
680df99e6ebSAnton Blanchard #define	vs28	28
681df99e6ebSAnton Blanchard #define	vs29	29
682df99e6ebSAnton Blanchard #define	vs30	30
683df99e6ebSAnton Blanchard #define	vs31	31
684df99e6ebSAnton Blanchard #define	vs32	32
685df99e6ebSAnton Blanchard #define	vs33	33
686df99e6ebSAnton Blanchard #define	vs34	34
687df99e6ebSAnton Blanchard #define	vs35	35
688df99e6ebSAnton Blanchard #define	vs36	36
689df99e6ebSAnton Blanchard #define	vs37	37
690df99e6ebSAnton Blanchard #define	vs38	38
691df99e6ebSAnton Blanchard #define	vs39	39
692df99e6ebSAnton Blanchard #define	vs40	40
693df99e6ebSAnton Blanchard #define	vs41	41
694df99e6ebSAnton Blanchard #define	vs42	42
695df99e6ebSAnton Blanchard #define	vs43	43
696df99e6ebSAnton Blanchard #define	vs44	44
697df99e6ebSAnton Blanchard #define	vs45	45
698df99e6ebSAnton Blanchard #define	vs46	46
699df99e6ebSAnton Blanchard #define	vs47	47
700df99e6ebSAnton Blanchard #define	vs48	48
701df99e6ebSAnton Blanchard #define	vs49	49
702df99e6ebSAnton Blanchard #define	vs50	50
703df99e6ebSAnton Blanchard #define	vs51	51
704df99e6ebSAnton Blanchard #define	vs52	52
705df99e6ebSAnton Blanchard #define	vs53	53
706df99e6ebSAnton Blanchard #define	vs54	54
707df99e6ebSAnton Blanchard #define	vs55	55
708df99e6ebSAnton Blanchard #define	vs56	56
709df99e6ebSAnton Blanchard #define	vs57	57
710df99e6ebSAnton Blanchard #define	vs58	58
711df99e6ebSAnton Blanchard #define	vs59	59
712df99e6ebSAnton Blanchard #define	vs60	60
713df99e6ebSAnton Blanchard #define	vs61	61
714df99e6ebSAnton Blanchard #define	vs62	62
715df99e6ebSAnton Blanchard #define	vs63	63
716b8b572e1SStephen Rothwell 
717b8b572e1SStephen Rothwell /* SPE Registers (EVPRs) */
718b8b572e1SStephen Rothwell 
719b8b572e1SStephen Rothwell #define	evr0	0
720b8b572e1SStephen Rothwell #define	evr1	1
721b8b572e1SStephen Rothwell #define	evr2	2
722b8b572e1SStephen Rothwell #define	evr3	3
723b8b572e1SStephen Rothwell #define	evr4	4
724b8b572e1SStephen Rothwell #define	evr5	5
725b8b572e1SStephen Rothwell #define	evr6	6
726b8b572e1SStephen Rothwell #define	evr7	7
727b8b572e1SStephen Rothwell #define	evr8	8
728b8b572e1SStephen Rothwell #define	evr9	9
729b8b572e1SStephen Rothwell #define	evr10	10
730b8b572e1SStephen Rothwell #define	evr11	11
731b8b572e1SStephen Rothwell #define	evr12	12
732b8b572e1SStephen Rothwell #define	evr13	13
733b8b572e1SStephen Rothwell #define	evr14	14
734b8b572e1SStephen Rothwell #define	evr15	15
735b8b572e1SStephen Rothwell #define	evr16	16
736b8b572e1SStephen Rothwell #define	evr17	17
737b8b572e1SStephen Rothwell #define	evr18	18
738b8b572e1SStephen Rothwell #define	evr19	19
739b8b572e1SStephen Rothwell #define	evr20	20
740b8b572e1SStephen Rothwell #define	evr21	21
741b8b572e1SStephen Rothwell #define	evr22	22
742b8b572e1SStephen Rothwell #define	evr23	23
743b8b572e1SStephen Rothwell #define	evr24	24
744b8b572e1SStephen Rothwell #define	evr25	25
745b8b572e1SStephen Rothwell #define	evr26	26
746b8b572e1SStephen Rothwell #define	evr27	27
747b8b572e1SStephen Rothwell #define	evr28	28
748b8b572e1SStephen Rothwell #define	evr29	29
749b8b572e1SStephen Rothwell #define	evr30	30
750b8b572e1SStephen Rothwell #define	evr31	31
751b8b572e1SStephen Rothwell 
752b8b572e1SStephen Rothwell /* some stab codes */
753b8b572e1SStephen Rothwell #define N_FUN	36
754b8b572e1SStephen Rothwell #define N_RSYM	64
755b8b572e1SStephen Rothwell #define N_SLINE	68
756b8b572e1SStephen Rothwell #define N_SO	100
757b8b572e1SStephen Rothwell 
7587fa95f9aSNicholas Piggin #define RFSCV	.long 0x4c0000a4
7597fa95f9aSNicholas Piggin 
7605c0484e2SBenjamin Herrenschmidt /*
7615c0484e2SBenjamin Herrenschmidt  * Create an endian fixup trampoline
7625c0484e2SBenjamin Herrenschmidt  *
7635c0484e2SBenjamin Herrenschmidt  * This starts with a "tdi 0,0,0x48" instruction which is
7645c0484e2SBenjamin Herrenschmidt  * essentially a "trap never", and thus akin to a nop.
7655c0484e2SBenjamin Herrenschmidt  *
7665c0484e2SBenjamin Herrenschmidt  * The opcode for this instruction read with the wrong endian
7675c0484e2SBenjamin Herrenschmidt  * however results in a b . + 8
7685c0484e2SBenjamin Herrenschmidt  *
7695c0484e2SBenjamin Herrenschmidt  * So essentially we use that trick to execute the following
7705c0484e2SBenjamin Herrenschmidt  * trampoline in "reverse endian" if we are running with the
7715c0484e2SBenjamin Herrenschmidt  * MSR_LE bit set the "wrong" way for whatever endianness the
7725c0484e2SBenjamin Herrenschmidt  * kernel is built for.
7735c0484e2SBenjamin Herrenschmidt  */
774b8b572e1SStephen Rothwell 
7755c0484e2SBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3E
7765c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN
7775c0484e2SBenjamin Herrenschmidt #else
7788ca9c08dSNicholas Piggin /*
7798ca9c08dSNicholas Piggin  * This version may be used in in HV or non-HV context.
7808ca9c08dSNicholas Piggin  * MSR[EE] must be disabled.
7818ca9c08dSNicholas Piggin  */
7825c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN						   \
7835c0484e2SBenjamin Herrenschmidt 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
784f848ea7fSNicholas Piggin 	b     191f;	  /* Skip trampoline if endian is good	*/ \
7855c0484e2SBenjamin Herrenschmidt 	.long 0xa600607d; /* mfmsr r11				*/ \
7865c0484e2SBenjamin Herrenschmidt 	.long 0x01006b69; /* xori r11,r11,1			*/ \
787f1fe5252SNicholas Piggin 	.long 0x00004039; /* li r10,0				*/ \
788f1fe5252SNicholas Piggin 	.long 0x6401417d; /* mtmsrd r10,1			*/ \
789f1fe5252SNicholas Piggin 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
790f1fe5252SNicholas Piggin 	.long 0xa602487d; /* mflr r10				*/ \
791f1fe5252SNicholas Piggin 	.long 0x14004a39; /* addi r10,r10,20			*/ \
7925c0484e2SBenjamin Herrenschmidt 	.long 0xa6035a7d; /* mtsrr0 r10				*/ \
7935c0484e2SBenjamin Herrenschmidt 	.long 0xa6037b7d; /* mtsrr1 r11				*/ \
794f848ea7fSNicholas Piggin 	.long 0x2400004c; /* rfid				*/ \
795f848ea7fSNicholas Piggin 191:
796f1fe5252SNicholas Piggin 
7978ca9c08dSNicholas Piggin /*
7988ca9c08dSNicholas Piggin  * This version that may only be used with MSR[HV]=1
7998ca9c08dSNicholas Piggin  * - Does not clear MSR[RI], so more robust.
8008ca9c08dSNicholas Piggin  * - Slightly smaller and faster.
8018ca9c08dSNicholas Piggin  */
8028ca9c08dSNicholas Piggin #define FIXUP_ENDIAN_HV						   \
8038ca9c08dSNicholas Piggin 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
8048ca9c08dSNicholas Piggin 	b     191f;	  /* Skip trampoline if endian is good	*/ \
8058ca9c08dSNicholas Piggin 	.long 0xa600607d; /* mfmsr r11				*/ \
8068ca9c08dSNicholas Piggin 	.long 0x01006b69; /* xori r11,r11,1			*/ \
8078ca9c08dSNicholas Piggin 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
8088ca9c08dSNicholas Piggin 	.long 0xa602487d; /* mflr r10				*/ \
8098ca9c08dSNicholas Piggin 	.long 0x14004a39; /* addi r10,r10,20			*/ \
8108ca9c08dSNicholas Piggin 	.long 0xa64b5a7d; /* mthsrr0 r10			*/ \
8118ca9c08dSNicholas Piggin 	.long 0xa64b7b7d; /* mthsrr1 r11			*/ \
8128ca9c08dSNicholas Piggin 	.long 0x2402004c; /* hrfid				*/ \
8138ca9c08dSNicholas Piggin 191:
8148ca9c08dSNicholas Piggin 
8155c0484e2SBenjamin Herrenschmidt #endif /* !CONFIG_PPC_BOOK3E */
816e3f2c6c3SMichael Ellerman 
8175c0484e2SBenjamin Herrenschmidt #endif /*  __ASSEMBLY__ */
818e3f2c6c3SMichael Ellerman 
81924bfa6a9SNicholas Piggin /*
82024bfa6a9SNicholas Piggin  * Helper macro for exception table entries
82124bfa6a9SNicholas Piggin  */
82224bfa6a9SNicholas Piggin #define EX_TABLE(_fault, _target)		\
82324bfa6a9SNicholas Piggin 	stringify_in_c(.section __ex_table,"a";)\
82461a92f70SNicholas Piggin 	stringify_in_c(.balign 4;)		\
82561a92f70SNicholas Piggin 	stringify_in_c(.long (_fault) - . ;)	\
82661a92f70SNicholas Piggin 	stringify_in_c(.long (_target) - . ;)	\
82724bfa6a9SNicholas Piggin 	stringify_in_c(.previous)
82824bfa6a9SNicholas Piggin 
8291cbf8990SDiana Craciun #ifdef CONFIG_PPC_FSL_BOOK3E
8301cbf8990SDiana Craciun #define BTB_FLUSH(reg)			\
8311cbf8990SDiana Craciun 	lis reg,BUCSR_INIT@h;		\
8321cbf8990SDiana Craciun 	ori reg,reg,BUCSR_INIT@l;	\
8331cbf8990SDiana Craciun 	mtspr SPRN_BUCSR,reg;		\
8341cbf8990SDiana Craciun 	isync;
8351cbf8990SDiana Craciun #else
8361cbf8990SDiana Craciun #define BTB_FLUSH(reg)
8371cbf8990SDiana Craciun #endif /* CONFIG_PPC_FSL_BOOK3E */
8381cbf8990SDiana Craciun 
839b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PPC_ASM_H */
840