xref: /openbmc/linux/arch/powerpc/include/asm/ppc_asm.h (revision f23699c9)
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  * Macros for storing registers into and loading registers from
20b8b572e1SStephen Rothwell  * exception frames.
21b8b572e1SStephen Rothwell  */
22b8b572e1SStephen Rothwell #ifdef __powerpc64__
23b8b572e1SStephen Rothwell #define SAVE_GPR(n, base)	std	n,GPR0+8*(n)(base)
24b8b572e1SStephen Rothwell #define REST_GPR(n, base)	ld	n,GPR0+8*(n)(base)
25b8b572e1SStephen Rothwell #define SAVE_NVGPRS(base)	SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
26b8b572e1SStephen Rothwell #define REST_NVGPRS(base)	REST_8GPRS(14, base); REST_10GPRS(22, base)
27b8b572e1SStephen Rothwell #else
28b8b572e1SStephen Rothwell #define SAVE_GPR(n, base)	stw	n,GPR0+4*(n)(base)
29b8b572e1SStephen Rothwell #define REST_GPR(n, base)	lwz	n,GPR0+4*(n)(base)
30a1f3ae3fSChristophe Leroy #define SAVE_NVGPRS(base)	stmw	13, GPR0+4*13(base)
31a1f3ae3fSChristophe Leroy #define REST_NVGPRS(base)	lmw	13, GPR0+4*13(base)
32b8b572e1SStephen Rothwell #endif
33b8b572e1SStephen Rothwell 
34b8b572e1SStephen Rothwell #define SAVE_2GPRS(n, base)	SAVE_GPR(n, base); SAVE_GPR(n+1, base)
35b8b572e1SStephen Rothwell #define SAVE_4GPRS(n, base)	SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
36b8b572e1SStephen Rothwell #define SAVE_8GPRS(n, base)	SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
37b8b572e1SStephen Rothwell #define SAVE_10GPRS(n, base)	SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
38b8b572e1SStephen Rothwell #define REST_2GPRS(n, base)	REST_GPR(n, base); REST_GPR(n+1, base)
39b8b572e1SStephen Rothwell #define REST_4GPRS(n, base)	REST_2GPRS(n, base); REST_2GPRS(n+2, base)
40b8b572e1SStephen Rothwell #define REST_8GPRS(n, base)	REST_4GPRS(n, base); REST_4GPRS(n+4, base)
41b8b572e1SStephen Rothwell #define REST_10GPRS(n, base)	REST_8GPRS(n, base); REST_2GPRS(n+8, base)
42b8b572e1SStephen Rothwell 
43de79f7b9SPaul Mackerras #define SAVE_FPR(n, base)	stfd	n,8*TS_FPRWIDTH*(n)(base)
44b8b572e1SStephen Rothwell #define SAVE_2FPRS(n, base)	SAVE_FPR(n, base); SAVE_FPR(n+1, base)
45b8b572e1SStephen Rothwell #define SAVE_4FPRS(n, base)	SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
46b8b572e1SStephen Rothwell #define SAVE_8FPRS(n, base)	SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
47b8b572e1SStephen Rothwell #define SAVE_16FPRS(n, base)	SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
48b8b572e1SStephen Rothwell #define SAVE_32FPRS(n, base)	SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
49de79f7b9SPaul Mackerras #define REST_FPR(n, base)	lfd	n,8*TS_FPRWIDTH*(n)(base)
50b8b572e1SStephen Rothwell #define REST_2FPRS(n, base)	REST_FPR(n, base); REST_FPR(n+1, base)
51b8b572e1SStephen Rothwell #define REST_4FPRS(n, base)	REST_2FPRS(n, base); REST_2FPRS(n+2, base)
52b8b572e1SStephen Rothwell #define REST_8FPRS(n, base)	REST_4FPRS(n, base); REST_4FPRS(n+4, base)
53b8b572e1SStephen Rothwell #define REST_16FPRS(n, base)	REST_8FPRS(n, base); REST_8FPRS(n+8, base)
54b8b572e1SStephen Rothwell #define REST_32FPRS(n, base)	REST_16FPRS(n, base); REST_16FPRS(n+16, base)
55b8b572e1SStephen Rothwell 
56de79f7b9SPaul Mackerras #define SAVE_VR(n,b,base)	li b,16*(n);  stvx n,base,b
57b8b572e1SStephen Rothwell #define SAVE_2VRS(n,b,base)	SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
58b8b572e1SStephen Rothwell #define SAVE_4VRS(n,b,base)	SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
59b8b572e1SStephen Rothwell #define SAVE_8VRS(n,b,base)	SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
60b8b572e1SStephen Rothwell #define SAVE_16VRS(n,b,base)	SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
61b8b572e1SStephen Rothwell #define SAVE_32VRS(n,b,base)	SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
62de79f7b9SPaul Mackerras #define REST_VR(n,b,base)	li b,16*(n); lvx n,base,b
63b8b572e1SStephen Rothwell #define REST_2VRS(n,b,base)	REST_VR(n,b,base); REST_VR(n+1,b,base)
64b8b572e1SStephen Rothwell #define REST_4VRS(n,b,base)	REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
65b8b572e1SStephen Rothwell #define REST_8VRS(n,b,base)	REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
66b8b572e1SStephen Rothwell #define REST_16VRS(n,b,base)	REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
67b8b572e1SStephen Rothwell #define REST_32VRS(n,b,base)	REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
68b8b572e1SStephen Rothwell 
69926f160fSAnton Blanchard #ifdef __BIG_ENDIAN__
70926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base)		STXVD2X(n,b,base)
71926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base)
72926f160fSAnton Blanchard #else
73926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base)		XXSWAPD(n,n);		\
74926f160fSAnton Blanchard 					STXVD2X(n,b,base);	\
75926f160fSAnton Blanchard 					XXSWAPD(n,n)
76926f160fSAnton Blanchard 
77926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base);	\
78926f160fSAnton Blanchard 					XXSWAPD(n,n)
79926f160fSAnton Blanchard #endif
80b8b572e1SStephen Rothwell /* Save the lower 32 VSRs in the thread VSR region */
813ad26e5cSBenjamin Herrenschmidt #define SAVE_VSR(n,b,base)	li b,16*(n);  STXVD2X_ROT(n,R##base,R##b)
82b8b572e1SStephen Rothwell #define SAVE_2VSRS(n,b,base)	SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
83b8b572e1SStephen Rothwell #define SAVE_4VSRS(n,b,base)	SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
84b8b572e1SStephen Rothwell #define SAVE_8VSRS(n,b,base)	SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
85b8b572e1SStephen Rothwell #define SAVE_16VSRS(n,b,base)	SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
86b8b572e1SStephen Rothwell #define SAVE_32VSRS(n,b,base)	SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
873ad26e5cSBenjamin Herrenschmidt #define REST_VSR(n,b,base)	li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
88b8b572e1SStephen Rothwell #define REST_2VSRS(n,b,base)	REST_VSR(n,b,base); REST_VSR(n+1,b,base)
89b8b572e1SStephen Rothwell #define REST_4VSRS(n,b,base)	REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
90b8b572e1SStephen Rothwell #define REST_8VSRS(n,b,base)	REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
91b8b572e1SStephen Rothwell #define REST_16VSRS(n,b,base)	REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
92b8b572e1SStephen Rothwell #define REST_32VSRS(n,b,base)	REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
93b8b572e1SStephen Rothwell 
94c51584d5SScott Wood /*
95c51584d5SScott Wood  * b = base register for addressing, o = base offset from register of 1st EVR
96c51584d5SScott Wood  * n = first EVR, s = scratch
97c51584d5SScott Wood  */
98c51584d5SScott Wood #define SAVE_EVR(n,s,b,o)	evmergehi s,s,n; stw s,o+4*(n)(b)
99c51584d5SScott Wood #define SAVE_2EVRS(n,s,b,o)	SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
100c51584d5SScott Wood #define SAVE_4EVRS(n,s,b,o)	SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
101c51584d5SScott Wood #define SAVE_8EVRS(n,s,b,o)	SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
102c51584d5SScott Wood #define SAVE_16EVRS(n,s,b,o)	SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
103c51584d5SScott Wood #define SAVE_32EVRS(n,s,b,o)	SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
104c51584d5SScott Wood #define REST_EVR(n,s,b,o)	lwz s,o+4*(n)(b); evmergelo n,s,n
105c51584d5SScott Wood #define REST_2EVRS(n,s,b,o)	REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
106c51584d5SScott Wood #define REST_4EVRS(n,s,b,o)	REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
107c51584d5SScott Wood #define REST_8EVRS(n,s,b,o)	REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
108c51584d5SScott Wood #define REST_16EVRS(n,s,b,o)	REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
109c51584d5SScott Wood #define REST_32EVRS(n,s,b,o)	REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
110b8b572e1SStephen Rothwell 
111b8b572e1SStephen Rothwell /* Macros to adjust thread priority for hardware multithreading */
112b8b572e1SStephen Rothwell #define HMT_VERY_LOW	or	31,31,31	# very low priority
113b8b572e1SStephen Rothwell #define HMT_LOW		or	1,1,1
114b8b572e1SStephen Rothwell #define HMT_MEDIUM_LOW  or	6,6,6		# medium low priority
115b8b572e1SStephen Rothwell #define HMT_MEDIUM	or	2,2,2
116b8b572e1SStephen Rothwell #define HMT_MEDIUM_HIGH or	5,5,5		# medium high priority
117b8b572e1SStephen Rothwell #define HMT_HIGH	or	3,3,3
11850fb8ebeSBenjamin Herrenschmidt #define HMT_EXTRA_HIGH	or	7,7,7		# power7 only
119b8b572e1SStephen Rothwell 
120d72be892SMichael Neuling #ifdef CONFIG_PPC64
121d72be892SMichael Neuling #define ULONG_SIZE 	8
122d72be892SMichael Neuling #else
123d72be892SMichael Neuling #define ULONG_SIZE	4
124d72be892SMichael Neuling #endif
1250b7673c3SMichael Neuling #define __VCPU_GPR(n)	(VCPU_GPRS + (n * ULONG_SIZE))
1260b7673c3SMichael Neuling #define VCPU_GPR(n)	__VCPU_GPR(__REG_##n)
127d72be892SMichael Neuling 
128b8b572e1SStephen Rothwell #ifdef __KERNEL__
1292eda7f11SMichael Ellerman 
1302eda7f11SMichael Ellerman /*
1312eda7f11SMichael Ellerman  * We use __powerpc64__ here because we want the compat VDSO to use the 32-bit
1322eda7f11SMichael Ellerman  * version below in the else case of the ifdef.
1332eda7f11SMichael Ellerman  */
1342eda7f11SMichael Ellerman #ifdef __powerpc64__
135b8b572e1SStephen Rothwell 
13644ce6a5eSMichael Neuling #define STACKFRAMESIZE 256
1370b7673c3SMichael Neuling #define __STK_REG(i)   (112 + ((i)-14)*8)
1380b7673c3SMichael Neuling #define STK_REG(i)     __STK_REG(__REG_##i)
13944ce6a5eSMichael Neuling 
140f55d9665SMichael Ellerman #ifdef PPC64_ELF_ABI_v2
1416403105bSAnton Blanchard #define STK_GOT		24
142b37c10d1SAnton Blanchard #define __STK_PARAM(i)	(32 + ((i)-3)*8)
143b37c10d1SAnton Blanchard #else
1446403105bSAnton Blanchard #define STK_GOT		40
1450b7673c3SMichael Neuling #define __STK_PARAM(i)	(48 + ((i)-3)*8)
146b37c10d1SAnton Blanchard #endif
1470b7673c3SMichael Neuling #define STK_PARAM(i)	__STK_PARAM(__REG_##i)
14844ce6a5eSMichael Neuling 
149f55d9665SMichael Ellerman #ifdef PPC64_ELF_ABI_v2
1507167af7cSAnton Blanchard 
1517167af7cSAnton Blanchard #define _GLOBAL(name) \
1527167af7cSAnton Blanchard 	.align 2 ; \
1537167af7cSAnton Blanchard 	.type name,@function; \
1547167af7cSAnton Blanchard 	.globl name; \
1557167af7cSAnton Blanchard name:
1567167af7cSAnton Blanchard 
157169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) \
158169c7ceeSAnton Blanchard 	.align 2 ; \
159169c7ceeSAnton Blanchard 	.type name,@function; \
160169c7ceeSAnton Blanchard 	.globl name; \
161169c7ceeSAnton Blanchard name: \
162169c7ceeSAnton Blanchard 0:	addis r2,r12,(.TOC.-0b)@ha; \
163169c7ceeSAnton Blanchard 	addi r2,r2,(.TOC.-0b)@l; \
164169c7ceeSAnton Blanchard 	.localentry name,.-name
165169c7ceeSAnton Blanchard 
1667167af7cSAnton Blanchard #define DOTSYM(a)	a
1677167af7cSAnton Blanchard 
1687167af7cSAnton Blanchard #else
1697167af7cSAnton Blanchard 
170b8b572e1SStephen Rothwell #define XGLUE(a,b) a##b
171b8b572e1SStephen Rothwell #define GLUE(a,b) XGLUE(a,b)
172b8b572e1SStephen Rothwell 
173b8b572e1SStephen Rothwell #define _GLOBAL(name) \
174b8b572e1SStephen Rothwell 	.align 2 ; \
175b8b572e1SStephen Rothwell 	.globl name; \
176b8b572e1SStephen Rothwell 	.globl GLUE(.,name); \
177bea2dcccSMichael Ellerman 	.pushsection ".opd","aw"; \
178b8b572e1SStephen Rothwell name: \
179b8b572e1SStephen Rothwell 	.quad GLUE(.,name); \
180b8b572e1SStephen Rothwell 	.quad .TOC.@tocbase; \
181b8b572e1SStephen Rothwell 	.quad 0; \
182bea2dcccSMichael Ellerman 	.popsection; \
183b8b572e1SStephen Rothwell 	.type GLUE(.,name),@function; \
184b8b572e1SStephen Rothwell GLUE(.,name):
185b8b572e1SStephen Rothwell 
186169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) _GLOBAL(name)
187169c7ceeSAnton Blanchard 
188c1fb0194SAnton Blanchard #define DOTSYM(a)	GLUE(.,a)
189c1fb0194SAnton Blanchard 
1907167af7cSAnton Blanchard #endif
1917167af7cSAnton Blanchard 
192b8b572e1SStephen Rothwell #else /* 32-bit */
193b8b572e1SStephen Rothwell 
194b8b572e1SStephen Rothwell #define _ENTRY(n)	\
195b8b572e1SStephen Rothwell 	.globl n;	\
196b8b572e1SStephen Rothwell n:
197b8b572e1SStephen Rothwell 
198b8b572e1SStephen Rothwell #define _GLOBAL(n)	\
199b8b572e1SStephen Rothwell 	.stabs __stringify(n:F-1),N_FUN,0,0,n;\
200b8b572e1SStephen Rothwell 	.globl n;	\
201b8b572e1SStephen Rothwell n:
202b8b572e1SStephen Rothwell 
2039715a2e8SAlexander Graf #define _GLOBAL_TOC(name) _GLOBAL(name)
2049715a2e8SAlexander Graf 
205ce7d8056SChristophe Leroy #define DOTSYM(a)	a
206ce7d8056SChristophe Leroy 
207b8b572e1SStephen Rothwell #endif
208b8b572e1SStephen Rothwell 
2096f698df1SNicholas Piggin /*
2106f698df1SNicholas Piggin  * __kprobes (the C annotation) puts the symbol into the .kprobes.text
2116f698df1SNicholas Piggin  * section, which gets emitted at the end of regular text.
2126f698df1SNicholas Piggin  *
2136f698df1SNicholas Piggin  * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
2146f698df1SNicholas Piggin  * a blacklist. The former is for core kprobe functions/data, the
2156f698df1SNicholas Piggin  * latter is for those that incdentially must be excluded from probing
2166f698df1SNicholas Piggin  * and allows them to be linked at more optimal location within text.
2176f698df1SNicholas Piggin  */
218c0a51491SNicholas Piggin #ifdef CONFIG_KPROBES
2196f698df1SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry)			\
2206f698df1SNicholas Piggin 	.pushsection "_kprobe_blacklist","aw";		\
2216f698df1SNicholas Piggin 	PPC_LONG (entry) ;				\
2226f698df1SNicholas Piggin 	.popsection
223c0a51491SNicholas Piggin #else
224c0a51491SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry)
225c0a51491SNicholas Piggin #endif
2266f698df1SNicholas Piggin 
227151f2511SAnton Blanchard #define FUNC_START(name)	_GLOBAL(name)
228151f2511SAnton Blanchard #define FUNC_END(name)
229151f2511SAnton Blanchard 
230b8b572e1SStephen Rothwell /*
231b8b572e1SStephen Rothwell  * LOAD_REG_IMMEDIATE(rn, expr)
232b8b572e1SStephen Rothwell  *   Loads the value of the constant expression 'expr' into register 'rn'
233b8b572e1SStephen Rothwell  *   using immediate instructions only.  Use this when it's important not
234b8b572e1SStephen Rothwell  *   to reference other data (i.e. on ppc64 when the TOC pointer is not
235e31aa453SPaul Mackerras  *   valid) and when 'expr' is a constant or absolute address.
236b8b572e1SStephen Rothwell  *
237b8b572e1SStephen Rothwell  * LOAD_REG_ADDR(rn, name)
238b8b572e1SStephen Rothwell  *   Loads the address of label 'name' into register 'rn'.  Use this when
239b8b572e1SStephen Rothwell  *   you don't particularly need immediate instructions only, but you need
240b8b572e1SStephen Rothwell  *   the whole address in one register (e.g. it's a structure address and
241b8b572e1SStephen Rothwell  *   you want to access various offsets within it).  On ppc32 this is
242b8b572e1SStephen Rothwell  *   identical to LOAD_REG_IMMEDIATE.
243b8b572e1SStephen Rothwell  *
2441c49abecSKevin Hao  * LOAD_REG_ADDR_PIC(rn, name)
2451c49abecSKevin Hao  *   Loads the address of label 'name' into register 'run'. Use this when
2461c49abecSKevin Hao  *   the kernel doesn't run at the linked or relocated address. Please
2471c49abecSKevin Hao  *   note that this macro will clobber the lr register.
2481c49abecSKevin Hao  *
249b8b572e1SStephen Rothwell  * LOAD_REG_ADDRBASE(rn, name)
250b8b572e1SStephen Rothwell  * ADDROFF(name)
251b8b572e1SStephen Rothwell  *   LOAD_REG_ADDRBASE loads part of the address of label 'name' into
252b8b572e1SStephen Rothwell  *   register 'rn'.  ADDROFF(name) returns the remainder of the address as
253b8b572e1SStephen Rothwell  *   a constant expression.  ADDROFF(name) is a signed expression < 16 bits
254b8b572e1SStephen Rothwell  *   in size, so is suitable for use directly as an offset in load and store
255b8b572e1SStephen Rothwell  *   instructions.  Use this when loading/storing a single word or less as:
256b8b572e1SStephen Rothwell  *      LOAD_REG_ADDRBASE(rX, name)
257b8b572e1SStephen Rothwell  *      ld	rY,ADDROFF(name)(rX)
258b8b572e1SStephen Rothwell  */
2591c49abecSKevin Hao 
2601c49abecSKevin Hao /* Be careful, this will clobber the lr register. */
2611c49abecSKevin Hao #define LOAD_REG_ADDR_PIC(reg, name)		\
2621c49abecSKevin Hao 	bl	0f;				\
2631c49abecSKevin Hao 0:	mflr	reg;				\
2641c49abecSKevin Hao 	addis	reg,reg,(name - 0b)@ha;		\
2651c49abecSKevin Hao 	addi	reg,reg,(name - 0b)@l;
2661c49abecSKevin Hao 
267c691b4b8SChristophe Leroy #if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH)
2687998eb3dSGuenter Roeck #define __AS_ATHIGH high
2697998eb3dSGuenter Roeck #else
2707998eb3dSGuenter Roeck #define __AS_ATHIGH h
2717998eb3dSGuenter Roeck #endif
272c691b4b8SChristophe Leroy 
273c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE_32 r, x
274c691b4b8SChristophe Leroy 	.if (\x) >= 0x8000 || (\x) < -0x8000
275c691b4b8SChristophe Leroy 		lis \r, (\x)@__AS_ATHIGH
276c691b4b8SChristophe Leroy 		.if (\x) & 0xffff != 0
277c691b4b8SChristophe Leroy 			ori \r, \r, (\x)@l
278c691b4b8SChristophe Leroy 		.endif
279c691b4b8SChristophe Leroy 	.else
280c691b4b8SChristophe Leroy 		li \r, (\x)@l
281c691b4b8SChristophe Leroy 	.endif
282c691b4b8SChristophe Leroy .endm
283c691b4b8SChristophe Leroy 
284c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE r, x
285c691b4b8SChristophe Leroy 	.if (\x) >= 0x80000000 || (\x) < -0x80000000
286c691b4b8SChristophe Leroy 		__LOAD_REG_IMMEDIATE_32 \r, (\x) >> 32
287c691b4b8SChristophe Leroy 		sldi	\r, \r, 32
288c691b4b8SChristophe Leroy 		.if (\x) & 0xffff0000 != 0
289c691b4b8SChristophe Leroy 			oris \r, \r, (\x)@__AS_ATHIGH
290c691b4b8SChristophe Leroy 		.endif
291c691b4b8SChristophe Leroy 		.if (\x) & 0xffff != 0
292c691b4b8SChristophe Leroy 			ori \r, \r, (\x)@l
293c691b4b8SChristophe Leroy 		.endif
294c691b4b8SChristophe Leroy 	.else
295c691b4b8SChristophe Leroy 		__LOAD_REG_IMMEDIATE_32 \r, \x
296c691b4b8SChristophe Leroy 	.endif
297c691b4b8SChristophe Leroy .endm
298c691b4b8SChristophe Leroy 
299c691b4b8SChristophe Leroy #ifdef __powerpc64__
300c691b4b8SChristophe Leroy 
301c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE reg, expr
302c691b4b8SChristophe Leroy 
303d7fb5b18SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg, tmp, expr)	\
304d7fb5b18SChristophe Leroy 	lis	tmp, (expr)@highest;		\
305d7fb5b18SChristophe Leroy 	lis	reg, (expr)@__AS_ATHIGH;	\
306d7fb5b18SChristophe Leroy 	ori	tmp, tmp, (expr)@higher;	\
307d7fb5b18SChristophe Leroy 	ori	reg, reg, (expr)@l;		\
308d7fb5b18SChristophe Leroy 	rldimi	reg, tmp, 32, 0
309b8b572e1SStephen Rothwell 
310b8b572e1SStephen Rothwell #define LOAD_REG_ADDR(reg,name)			\
311564aa5cfSMichael Neuling 	ld	reg,name@got(r2)
312b8b572e1SStephen Rothwell 
313b8b572e1SStephen Rothwell #define LOAD_REG_ADDRBASE(reg,name)	LOAD_REG_ADDR(reg,name)
314b8b572e1SStephen Rothwell #define ADDROFF(name)			0
315b8b572e1SStephen Rothwell 
316b8b572e1SStephen Rothwell /* offsets for stack frame layout */
317b8b572e1SStephen Rothwell #define LRSAVE	16
318b8b572e1SStephen Rothwell 
319b8b572e1SStephen Rothwell #else /* 32-bit */
320b8b572e1SStephen Rothwell 
321c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr
322c691b4b8SChristophe Leroy 
323c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg,expr)		\
324564aa5cfSMichael Neuling 	lis	reg,(expr)@ha;		\
325564aa5cfSMichael Neuling 	addi	reg,reg,(expr)@l;
326b8b572e1SStephen Rothwell 
327c691b4b8SChristophe Leroy #define LOAD_REG_ADDR(reg,name)		LOAD_REG_IMMEDIATE_SYM(reg, name)
328b8b572e1SStephen Rothwell 
329564aa5cfSMichael Neuling #define LOAD_REG_ADDRBASE(reg, name)	lis	reg,name@ha
330b8b572e1SStephen Rothwell #define ADDROFF(name)			name@l
331b8b572e1SStephen Rothwell 
332b8b572e1SStephen Rothwell /* offsets for stack frame layout */
333b8b572e1SStephen Rothwell #define LRSAVE	4
334b8b572e1SStephen Rothwell 
335b8b572e1SStephen Rothwell #endif
336b8b572e1SStephen Rothwell 
337b8b572e1SStephen Rothwell /* various errata or part fixups */
338d52459caSScott Wood #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
339b8b572e1SStephen Rothwell #define MFTB(dest)			\
340beb2dc0aSScott Wood 90:	mfspr dest, SPRN_TBRL;		\
341b8b572e1SStephen Rothwell BEGIN_FTR_SECTION_NESTED(96);		\
342b8b572e1SStephen Rothwell 	cmpwi dest,0;			\
343b8b572e1SStephen Rothwell 	beq-  90b;			\
344b8b572e1SStephen Rothwell END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
345b8b572e1SStephen Rothwell #else
34672e4b2cdSChristophe Leroy #define MFTB(dest)			MFTBL(dest)
34772e4b2cdSChristophe Leroy #endif
34872e4b2cdSChristophe Leroy 
34972e4b2cdSChristophe Leroy #ifdef CONFIG_PPC_8xx
35072e4b2cdSChristophe Leroy #define MFTBL(dest)			mftb dest
35172e4b2cdSChristophe Leroy #define MFTBU(dest)			mftbu dest
35272e4b2cdSChristophe Leroy #else
35372e4b2cdSChristophe Leroy #define MFTBL(dest)			mfspr dest, SPRN_TBRL
35472e4b2cdSChristophe Leroy #define MFTBU(dest)			mfspr dest, SPRN_TBRU
355b8b572e1SStephen Rothwell #endif
356b8b572e1SStephen Rothwell 
3578b14e1dfSChristophe Leroy #ifndef CONFIG_SMP
35812c3f1fdSChristophe Leroy #define TLBSYNC
35912c3f1fdSChristophe Leroy #else
36012c3f1fdSChristophe Leroy #define TLBSYNC		tlbsync; sync
361b8b572e1SStephen Rothwell #endif
362b8b572e1SStephen Rothwell 
363694caf02SAnton Blanchard #ifdef CONFIG_PPC64
364694caf02SAnton Blanchard #define MTOCRF(FXM, RS)			\
365694caf02SAnton Blanchard 	BEGIN_FTR_SECTION_NESTED(848);	\
36686e32fdcSMichael Neuling 	mtcrf	(FXM), RS;		\
367694caf02SAnton Blanchard 	FTR_SECTION_ELSE_NESTED(848);	\
36886e32fdcSMichael Neuling 	mtocrf (FXM), RS;		\
369694caf02SAnton Blanchard 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
370694caf02SAnton Blanchard #endif
371b8b572e1SStephen Rothwell 
372b8b572e1SStephen Rothwell /*
373b8b572e1SStephen Rothwell  * This instruction is not implemented on the PPC 603 or 601; however, on
374b8b572e1SStephen Rothwell  * the 403GCX and 405GP tlbia IS defined and tlbie is not.
375b8b572e1SStephen Rothwell  * All of these instructions exist in the 8xx, they have magical powers,
376b8b572e1SStephen Rothwell  * and they must be used.
377b8b572e1SStephen Rothwell  */
378b8b572e1SStephen Rothwell 
379968159c0SChristophe Leroy #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx)
380b8b572e1SStephen Rothwell #define tlbia					\
381b8b572e1SStephen Rothwell 	li	r4,1024;			\
382b8b572e1SStephen Rothwell 	mtctr	r4;				\
383b8b572e1SStephen Rothwell 	lis	r4,KERNELBASE@h;		\
384e3824e42SRussell Currey 	.machine push;				\
385e3824e42SRussell Currey 	.machine "power4";			\
386b8b572e1SStephen Rothwell 0:	tlbie	r4;				\
387e3824e42SRussell Currey 	.machine pop;				\
388b8b572e1SStephen Rothwell 	addi	r4,r4,0x1000;			\
389b8b572e1SStephen Rothwell 	bdnz	0b
390b8b572e1SStephen Rothwell #endif
391b8b572e1SStephen Rothwell 
392b8b572e1SStephen Rothwell 
393b8b572e1SStephen Rothwell #ifdef CONFIG_IBM440EP_ERR42
394b8b572e1SStephen Rothwell #define PPC440EP_ERR42 isync
395b8b572e1SStephen Rothwell #else
396b8b572e1SStephen Rothwell #define PPC440EP_ERR42
397b8b572e1SStephen Rothwell #endif
398b8b572e1SStephen Rothwell 
399a515348fSMichael Neuling /* The following stops all load and store data streams associated with stream
400a515348fSMichael Neuling  * ID (ie. streams created explicitly).  The embedded and server mnemonics for
40115a3204dSNicholas Piggin  * dcbt are different so this must only be used for server.
402a515348fSMichael Neuling  */
40315a3204dSNicholas Piggin #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch)	\
404a515348fSMichael Neuling        lis     scratch,0x60000000@h;			\
40515a3204dSNicholas Piggin        dcbt    0,scratch,0b01010
406a515348fSMichael Neuling 
40744c58cccSBenjamin Herrenschmidt /*
40844c58cccSBenjamin Herrenschmidt  * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
40944c58cccSBenjamin Herrenschmidt  * keep the address intact to be compatible with code shared with
41044c58cccSBenjamin Herrenschmidt  * 32-bit classic.
41144c58cccSBenjamin Herrenschmidt  *
41244c58cccSBenjamin Herrenschmidt  * On the other hand, I find it useful to have them behave as expected
41344c58cccSBenjamin Herrenschmidt  * by their name (ie always do the addition) on 64-bit BookE
41444c58cccSBenjamin Herrenschmidt  */
41544c58cccSBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
416b8b572e1SStephen Rothwell #define toreal(rd)
417b8b572e1SStephen Rothwell #define fromreal(rd)
418b8b572e1SStephen Rothwell 
419b8b572e1SStephen Rothwell /*
420b8b572e1SStephen Rothwell  * We use addis to ensure compatibility with the "classic" ppc versions of
421b8b572e1SStephen Rothwell  * these macros, which use rs = 0 to get the tophys offset in rd, rather than
422b8b572e1SStephen Rothwell  * converting the address in r0, and so this version has to do that too
423b8b572e1SStephen Rothwell  * (i.e. set register rd to 0 when rs == 0).
424b8b572e1SStephen Rothwell  */
425b8b572e1SStephen Rothwell #define tophys(rd,rs)				\
426b8b572e1SStephen Rothwell 	addis	rd,rs,0
427b8b572e1SStephen Rothwell 
428b8b572e1SStephen Rothwell #define tovirt(rd,rs)				\
429b8b572e1SStephen Rothwell 	addis	rd,rs,0
430b8b572e1SStephen Rothwell 
431b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC64)
432b8b572e1SStephen Rothwell #define toreal(rd)		/* we can access c000... in real mode */
433b8b572e1SStephen Rothwell #define fromreal(rd)
434b8b572e1SStephen Rothwell 
435b8b572e1SStephen Rothwell #define tophys(rd,rs)                           \
436b8b572e1SStephen Rothwell 	clrldi	rd,rs,2
437b8b572e1SStephen Rothwell 
438b8b572e1SStephen Rothwell #define tovirt(rd,rs)                           \
439b8b572e1SStephen Rothwell 	rotldi	rd,rs,16;			\
440b8b572e1SStephen Rothwell 	ori	rd,rd,((KERNELBASE>>48)&0xFFFF);\
441b8b572e1SStephen Rothwell 	rotldi	rd,rd,48
442b8b572e1SStephen Rothwell #else
443b8b572e1SStephen Rothwell #define toreal(rd)	tophys(rd,rd)
444b8b572e1SStephen Rothwell #define fromreal(rd)	tovirt(rd,rd)
445b8b572e1SStephen Rothwell 
446c62ce9efSChristophe Leroy #define tophys(rd, rs)	addis	rd, rs, -PAGE_OFFSET@h
447c62ce9efSChristophe Leroy #define tovirt(rd, rs)	addis	rd, rs, PAGE_OFFSET@h
448b8b572e1SStephen Rothwell #endif
449b8b572e1SStephen Rothwell 
45044c58cccSBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S_64
451b8b572e1SStephen Rothwell #define MTMSRD(r)	mtmsrd	r
452b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg)	mtmsrd	reg,1
453b8b572e1SStephen Rothwell #else
454b8b572e1SStephen Rothwell #define MTMSRD(r)	mtmsr	r
455b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg)	mtmsr	reg
456b8b572e1SStephen Rothwell #endif
457b8b572e1SStephen Rothwell 
458b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
459b8b572e1SStephen Rothwell 
460b8b572e1SStephen Rothwell /* The boring bits... */
461b8b572e1SStephen Rothwell 
462b8b572e1SStephen Rothwell /* Condition Register Bit Fields */
463b8b572e1SStephen Rothwell 
464b8b572e1SStephen Rothwell #define	cr0	0
465b8b572e1SStephen Rothwell #define	cr1	1
466b8b572e1SStephen Rothwell #define	cr2	2
467b8b572e1SStephen Rothwell #define	cr3	3
468b8b572e1SStephen Rothwell #define	cr4	4
469b8b572e1SStephen Rothwell #define	cr5	5
470b8b572e1SStephen Rothwell #define	cr6	6
471b8b572e1SStephen Rothwell #define	cr7	7
472b8b572e1SStephen Rothwell 
473b8b572e1SStephen Rothwell 
4749a13a524SMichael Neuling /*
4759a13a524SMichael Neuling  * General Purpose Registers (GPRs)
4769a13a524SMichael Neuling  *
4779a13a524SMichael Neuling  * The lower case r0-r31 should be used in preference to the upper
4789a13a524SMichael Neuling  * case R0-R31 as they provide more error checking in the assembler.
4799a13a524SMichael Neuling  * Use R0-31 only when really nessesary.
4809a13a524SMichael Neuling  */
481b8b572e1SStephen Rothwell 
4829a13a524SMichael Neuling #define	r0	%r0
4839a13a524SMichael Neuling #define	r1	%r1
4849a13a524SMichael Neuling #define	r2	%r2
4859a13a524SMichael Neuling #define	r3	%r3
4869a13a524SMichael Neuling #define	r4	%r4
4879a13a524SMichael Neuling #define	r5	%r5
4889a13a524SMichael Neuling #define	r6	%r6
4899a13a524SMichael Neuling #define	r7	%r7
4909a13a524SMichael Neuling #define	r8	%r8
4919a13a524SMichael Neuling #define	r9	%r9
4929a13a524SMichael Neuling #define	r10	%r10
4939a13a524SMichael Neuling #define	r11	%r11
4949a13a524SMichael Neuling #define	r12	%r12
4959a13a524SMichael Neuling #define	r13	%r13
4969a13a524SMichael Neuling #define	r14	%r14
4979a13a524SMichael Neuling #define	r15	%r15
4989a13a524SMichael Neuling #define	r16	%r16
4999a13a524SMichael Neuling #define	r17	%r17
5009a13a524SMichael Neuling #define	r18	%r18
5019a13a524SMichael Neuling #define	r19	%r19
5029a13a524SMichael Neuling #define	r20	%r20
5039a13a524SMichael Neuling #define	r21	%r21
5049a13a524SMichael Neuling #define	r22	%r22
5059a13a524SMichael Neuling #define	r23	%r23
5069a13a524SMichael Neuling #define	r24	%r24
5079a13a524SMichael Neuling #define	r25	%r25
5089a13a524SMichael Neuling #define	r26	%r26
5099a13a524SMichael Neuling #define	r27	%r27
5109a13a524SMichael Neuling #define	r28	%r28
5119a13a524SMichael Neuling #define	r29	%r29
5129a13a524SMichael Neuling #define	r30	%r30
5139a13a524SMichael Neuling #define	r31	%r31
514b8b572e1SStephen Rothwell 
515b8b572e1SStephen Rothwell 
516b8b572e1SStephen Rothwell /* Floating Point Registers (FPRs) */
517b8b572e1SStephen Rothwell 
518b8b572e1SStephen Rothwell #define	fr0	0
519b8b572e1SStephen Rothwell #define	fr1	1
520b8b572e1SStephen Rothwell #define	fr2	2
521b8b572e1SStephen Rothwell #define	fr3	3
522b8b572e1SStephen Rothwell #define	fr4	4
523b8b572e1SStephen Rothwell #define	fr5	5
524b8b572e1SStephen Rothwell #define	fr6	6
525b8b572e1SStephen Rothwell #define	fr7	7
526b8b572e1SStephen Rothwell #define	fr8	8
527b8b572e1SStephen Rothwell #define	fr9	9
528b8b572e1SStephen Rothwell #define	fr10	10
529b8b572e1SStephen Rothwell #define	fr11	11
530b8b572e1SStephen Rothwell #define	fr12	12
531b8b572e1SStephen Rothwell #define	fr13	13
532b8b572e1SStephen Rothwell #define	fr14	14
533b8b572e1SStephen Rothwell #define	fr15	15
534b8b572e1SStephen Rothwell #define	fr16	16
535b8b572e1SStephen Rothwell #define	fr17	17
536b8b572e1SStephen Rothwell #define	fr18	18
537b8b572e1SStephen Rothwell #define	fr19	19
538b8b572e1SStephen Rothwell #define	fr20	20
539b8b572e1SStephen Rothwell #define	fr21	21
540b8b572e1SStephen Rothwell #define	fr22	22
541b8b572e1SStephen Rothwell #define	fr23	23
542b8b572e1SStephen Rothwell #define	fr24	24
543b8b572e1SStephen Rothwell #define	fr25	25
544b8b572e1SStephen Rothwell #define	fr26	26
545b8b572e1SStephen Rothwell #define	fr27	27
546b8b572e1SStephen Rothwell #define	fr28	28
547b8b572e1SStephen Rothwell #define	fr29	29
548b8b572e1SStephen Rothwell #define	fr30	30
549b8b572e1SStephen Rothwell #define	fr31	31
550b8b572e1SStephen Rothwell 
551b8b572e1SStephen Rothwell /* AltiVec Registers (VPRs) */
552b8b572e1SStephen Rothwell 
553c2ce6f9fSAnton Blanchard #define	v0	0
554c2ce6f9fSAnton Blanchard #define	v1	1
555c2ce6f9fSAnton Blanchard #define	v2	2
556c2ce6f9fSAnton Blanchard #define	v3	3
557c2ce6f9fSAnton Blanchard #define	v4	4
558c2ce6f9fSAnton Blanchard #define	v5	5
559c2ce6f9fSAnton Blanchard #define	v6	6
560c2ce6f9fSAnton Blanchard #define	v7	7
561c2ce6f9fSAnton Blanchard #define	v8	8
562c2ce6f9fSAnton Blanchard #define	v9	9
563c2ce6f9fSAnton Blanchard #define	v10	10
564c2ce6f9fSAnton Blanchard #define	v11	11
565c2ce6f9fSAnton Blanchard #define	v12	12
566c2ce6f9fSAnton Blanchard #define	v13	13
567c2ce6f9fSAnton Blanchard #define	v14	14
568c2ce6f9fSAnton Blanchard #define	v15	15
569c2ce6f9fSAnton Blanchard #define	v16	16
570c2ce6f9fSAnton Blanchard #define	v17	17
571c2ce6f9fSAnton Blanchard #define	v18	18
572c2ce6f9fSAnton Blanchard #define	v19	19
573c2ce6f9fSAnton Blanchard #define	v20	20
574c2ce6f9fSAnton Blanchard #define	v21	21
575c2ce6f9fSAnton Blanchard #define	v22	22
576c2ce6f9fSAnton Blanchard #define	v23	23
577c2ce6f9fSAnton Blanchard #define	v24	24
578c2ce6f9fSAnton Blanchard #define	v25	25
579c2ce6f9fSAnton Blanchard #define	v26	26
580c2ce6f9fSAnton Blanchard #define	v27	27
581c2ce6f9fSAnton Blanchard #define	v28	28
582c2ce6f9fSAnton Blanchard #define	v29	29
583c2ce6f9fSAnton Blanchard #define	v30	30
584c2ce6f9fSAnton Blanchard #define	v31	31
585b8b572e1SStephen Rothwell 
586b8b572e1SStephen Rothwell /* VSX Registers (VSRs) */
587b8b572e1SStephen Rothwell 
588df99e6ebSAnton Blanchard #define	vs0	0
589df99e6ebSAnton Blanchard #define	vs1	1
590df99e6ebSAnton Blanchard #define	vs2	2
591df99e6ebSAnton Blanchard #define	vs3	3
592df99e6ebSAnton Blanchard #define	vs4	4
593df99e6ebSAnton Blanchard #define	vs5	5
594df99e6ebSAnton Blanchard #define	vs6	6
595df99e6ebSAnton Blanchard #define	vs7	7
596df99e6ebSAnton Blanchard #define	vs8	8
597df99e6ebSAnton Blanchard #define	vs9	9
598df99e6ebSAnton Blanchard #define	vs10	10
599df99e6ebSAnton Blanchard #define	vs11	11
600df99e6ebSAnton Blanchard #define	vs12	12
601df99e6ebSAnton Blanchard #define	vs13	13
602df99e6ebSAnton Blanchard #define	vs14	14
603df99e6ebSAnton Blanchard #define	vs15	15
604df99e6ebSAnton Blanchard #define	vs16	16
605df99e6ebSAnton Blanchard #define	vs17	17
606df99e6ebSAnton Blanchard #define	vs18	18
607df99e6ebSAnton Blanchard #define	vs19	19
608df99e6ebSAnton Blanchard #define	vs20	20
609df99e6ebSAnton Blanchard #define	vs21	21
610df99e6ebSAnton Blanchard #define	vs22	22
611df99e6ebSAnton Blanchard #define	vs23	23
612df99e6ebSAnton Blanchard #define	vs24	24
613df99e6ebSAnton Blanchard #define	vs25	25
614df99e6ebSAnton Blanchard #define	vs26	26
615df99e6ebSAnton Blanchard #define	vs27	27
616df99e6ebSAnton Blanchard #define	vs28	28
617df99e6ebSAnton Blanchard #define	vs29	29
618df99e6ebSAnton Blanchard #define	vs30	30
619df99e6ebSAnton Blanchard #define	vs31	31
620df99e6ebSAnton Blanchard #define	vs32	32
621df99e6ebSAnton Blanchard #define	vs33	33
622df99e6ebSAnton Blanchard #define	vs34	34
623df99e6ebSAnton Blanchard #define	vs35	35
624df99e6ebSAnton Blanchard #define	vs36	36
625df99e6ebSAnton Blanchard #define	vs37	37
626df99e6ebSAnton Blanchard #define	vs38	38
627df99e6ebSAnton Blanchard #define	vs39	39
628df99e6ebSAnton Blanchard #define	vs40	40
629df99e6ebSAnton Blanchard #define	vs41	41
630df99e6ebSAnton Blanchard #define	vs42	42
631df99e6ebSAnton Blanchard #define	vs43	43
632df99e6ebSAnton Blanchard #define	vs44	44
633df99e6ebSAnton Blanchard #define	vs45	45
634df99e6ebSAnton Blanchard #define	vs46	46
635df99e6ebSAnton Blanchard #define	vs47	47
636df99e6ebSAnton Blanchard #define	vs48	48
637df99e6ebSAnton Blanchard #define	vs49	49
638df99e6ebSAnton Blanchard #define	vs50	50
639df99e6ebSAnton Blanchard #define	vs51	51
640df99e6ebSAnton Blanchard #define	vs52	52
641df99e6ebSAnton Blanchard #define	vs53	53
642df99e6ebSAnton Blanchard #define	vs54	54
643df99e6ebSAnton Blanchard #define	vs55	55
644df99e6ebSAnton Blanchard #define	vs56	56
645df99e6ebSAnton Blanchard #define	vs57	57
646df99e6ebSAnton Blanchard #define	vs58	58
647df99e6ebSAnton Blanchard #define	vs59	59
648df99e6ebSAnton Blanchard #define	vs60	60
649df99e6ebSAnton Blanchard #define	vs61	61
650df99e6ebSAnton Blanchard #define	vs62	62
651df99e6ebSAnton Blanchard #define	vs63	63
652b8b572e1SStephen Rothwell 
653b8b572e1SStephen Rothwell /* SPE Registers (EVPRs) */
654b8b572e1SStephen Rothwell 
655b8b572e1SStephen Rothwell #define	evr0	0
656b8b572e1SStephen Rothwell #define	evr1	1
657b8b572e1SStephen Rothwell #define	evr2	2
658b8b572e1SStephen Rothwell #define	evr3	3
659b8b572e1SStephen Rothwell #define	evr4	4
660b8b572e1SStephen Rothwell #define	evr5	5
661b8b572e1SStephen Rothwell #define	evr6	6
662b8b572e1SStephen Rothwell #define	evr7	7
663b8b572e1SStephen Rothwell #define	evr8	8
664b8b572e1SStephen Rothwell #define	evr9	9
665b8b572e1SStephen Rothwell #define	evr10	10
666b8b572e1SStephen Rothwell #define	evr11	11
667b8b572e1SStephen Rothwell #define	evr12	12
668b8b572e1SStephen Rothwell #define	evr13	13
669b8b572e1SStephen Rothwell #define	evr14	14
670b8b572e1SStephen Rothwell #define	evr15	15
671b8b572e1SStephen Rothwell #define	evr16	16
672b8b572e1SStephen Rothwell #define	evr17	17
673b8b572e1SStephen Rothwell #define	evr18	18
674b8b572e1SStephen Rothwell #define	evr19	19
675b8b572e1SStephen Rothwell #define	evr20	20
676b8b572e1SStephen Rothwell #define	evr21	21
677b8b572e1SStephen Rothwell #define	evr22	22
678b8b572e1SStephen Rothwell #define	evr23	23
679b8b572e1SStephen Rothwell #define	evr24	24
680b8b572e1SStephen Rothwell #define	evr25	25
681b8b572e1SStephen Rothwell #define	evr26	26
682b8b572e1SStephen Rothwell #define	evr27	27
683b8b572e1SStephen Rothwell #define	evr28	28
684b8b572e1SStephen Rothwell #define	evr29	29
685b8b572e1SStephen Rothwell #define	evr30	30
686b8b572e1SStephen Rothwell #define	evr31	31
687b8b572e1SStephen Rothwell 
688b8b572e1SStephen Rothwell /* some stab codes */
689b8b572e1SStephen Rothwell #define N_FUN	36
690b8b572e1SStephen Rothwell #define N_RSYM	64
691b8b572e1SStephen Rothwell #define N_SLINE	68
692b8b572e1SStephen Rothwell #define N_SO	100
693b8b572e1SStephen Rothwell 
6947fa95f9aSNicholas Piggin #define RFSCV	.long 0x4c0000a4
6957fa95f9aSNicholas Piggin 
6965c0484e2SBenjamin Herrenschmidt /*
6975c0484e2SBenjamin Herrenschmidt  * Create an endian fixup trampoline
6985c0484e2SBenjamin Herrenschmidt  *
6995c0484e2SBenjamin Herrenschmidt  * This starts with a "tdi 0,0,0x48" instruction which is
7005c0484e2SBenjamin Herrenschmidt  * essentially a "trap never", and thus akin to a nop.
7015c0484e2SBenjamin Herrenschmidt  *
7025c0484e2SBenjamin Herrenschmidt  * The opcode for this instruction read with the wrong endian
7035c0484e2SBenjamin Herrenschmidt  * however results in a b . + 8
7045c0484e2SBenjamin Herrenschmidt  *
7055c0484e2SBenjamin Herrenschmidt  * So essentially we use that trick to execute the following
7065c0484e2SBenjamin Herrenschmidt  * trampoline in "reverse endian" if we are running with the
7075c0484e2SBenjamin Herrenschmidt  * MSR_LE bit set the "wrong" way for whatever endianness the
7085c0484e2SBenjamin Herrenschmidt  * kernel is built for.
7095c0484e2SBenjamin Herrenschmidt  */
710b8b572e1SStephen Rothwell 
7115c0484e2SBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3E
7125c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN
7135c0484e2SBenjamin Herrenschmidt #else
7148ca9c08dSNicholas Piggin /*
715db10f550SRandy Dunlap  * This version may be used in HV or non-HV context.
7168ca9c08dSNicholas Piggin  * MSR[EE] must be disabled.
7178ca9c08dSNicholas Piggin  */
7185c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN						   \
7195c0484e2SBenjamin Herrenschmidt 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
720f848ea7fSNicholas Piggin 	b     191f;	  /* Skip trampoline if endian is good	*/ \
7215c0484e2SBenjamin Herrenschmidt 	.long 0xa600607d; /* mfmsr r11				*/ \
7225c0484e2SBenjamin Herrenschmidt 	.long 0x01006b69; /* xori r11,r11,1			*/ \
723f1fe5252SNicholas Piggin 	.long 0x00004039; /* li r10,0				*/ \
724f1fe5252SNicholas Piggin 	.long 0x6401417d; /* mtmsrd r10,1			*/ \
725f1fe5252SNicholas Piggin 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
726f1fe5252SNicholas Piggin 	.long 0xa602487d; /* mflr r10				*/ \
727f1fe5252SNicholas Piggin 	.long 0x14004a39; /* addi r10,r10,20			*/ \
7285c0484e2SBenjamin Herrenschmidt 	.long 0xa6035a7d; /* mtsrr0 r10				*/ \
7295c0484e2SBenjamin Herrenschmidt 	.long 0xa6037b7d; /* mtsrr1 r11				*/ \
730f848ea7fSNicholas Piggin 	.long 0x2400004c; /* rfid				*/ \
731f848ea7fSNicholas Piggin 191:
732f1fe5252SNicholas Piggin 
7338ca9c08dSNicholas Piggin /*
7348ca9c08dSNicholas Piggin  * This version that may only be used with MSR[HV]=1
7358ca9c08dSNicholas Piggin  * - Does not clear MSR[RI], so more robust.
7368ca9c08dSNicholas Piggin  * - Slightly smaller and faster.
7378ca9c08dSNicholas Piggin  */
7388ca9c08dSNicholas Piggin #define FIXUP_ENDIAN_HV						   \
7398ca9c08dSNicholas Piggin 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
7408ca9c08dSNicholas Piggin 	b     191f;	  /* Skip trampoline if endian is good	*/ \
7418ca9c08dSNicholas Piggin 	.long 0xa600607d; /* mfmsr r11				*/ \
7428ca9c08dSNicholas Piggin 	.long 0x01006b69; /* xori r11,r11,1			*/ \
7438ca9c08dSNicholas Piggin 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
7448ca9c08dSNicholas Piggin 	.long 0xa602487d; /* mflr r10				*/ \
7458ca9c08dSNicholas Piggin 	.long 0x14004a39; /* addi r10,r10,20			*/ \
7468ca9c08dSNicholas Piggin 	.long 0xa64b5a7d; /* mthsrr0 r10			*/ \
7478ca9c08dSNicholas Piggin 	.long 0xa64b7b7d; /* mthsrr1 r11			*/ \
7488ca9c08dSNicholas Piggin 	.long 0x2402004c; /* hrfid				*/ \
7498ca9c08dSNicholas Piggin 191:
7508ca9c08dSNicholas Piggin 
7515c0484e2SBenjamin Herrenschmidt #endif /* !CONFIG_PPC_BOOK3E */
752e3f2c6c3SMichael Ellerman 
7535c0484e2SBenjamin Herrenschmidt #endif /*  __ASSEMBLY__ */
754e3f2c6c3SMichael Ellerman 
75524bfa6a9SNicholas Piggin /*
75624bfa6a9SNicholas Piggin  * Helper macro for exception table entries
75724bfa6a9SNicholas Piggin  */
75824bfa6a9SNicholas Piggin #define EX_TABLE(_fault, _target)		\
75924bfa6a9SNicholas Piggin 	stringify_in_c(.section __ex_table,"a";)\
76061a92f70SNicholas Piggin 	stringify_in_c(.balign 4;)		\
76161a92f70SNicholas Piggin 	stringify_in_c(.long (_fault) - . ;)	\
76261a92f70SNicholas Piggin 	stringify_in_c(.long (_target) - . ;)	\
76324bfa6a9SNicholas Piggin 	stringify_in_c(.previous)
76424bfa6a9SNicholas Piggin 
765*f23699c9SNicholas Piggin #define RESTART_TABLE(_start, _end, _target)	\
766*f23699c9SNicholas Piggin 	stringify_in_c(.section __restart_table,"a";)\
767*f23699c9SNicholas Piggin 	stringify_in_c(.balign 8;)		\
768*f23699c9SNicholas Piggin 	stringify_in_c(.llong (_start);)	\
769*f23699c9SNicholas Piggin 	stringify_in_c(.llong (_end);)		\
770*f23699c9SNicholas Piggin 	stringify_in_c(.llong (_target);)	\
771*f23699c9SNicholas Piggin 	stringify_in_c(.previous)
772*f23699c9SNicholas Piggin 
7731cbf8990SDiana Craciun #ifdef CONFIG_PPC_FSL_BOOK3E
7741cbf8990SDiana Craciun #define BTB_FLUSH(reg)			\
7751cbf8990SDiana Craciun 	lis reg,BUCSR_INIT@h;		\
7761cbf8990SDiana Craciun 	ori reg,reg,BUCSR_INIT@l;	\
7771cbf8990SDiana Craciun 	mtspr SPRN_BUCSR,reg;		\
7781cbf8990SDiana Craciun 	isync;
7791cbf8990SDiana Craciun #else
7801cbf8990SDiana Craciun #define BTB_FLUSH(reg)
7811cbf8990SDiana Craciun #endif /* CONFIG_PPC_FSL_BOOK3E */
7821cbf8990SDiana Craciun 
783b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PPC_ASM_H */
784