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