xref: /openbmc/linux/arch/powerpc/include/asm/ppc_asm.h (revision 4e991e3c)
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>
131e688dd2SChristophe 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 /*
20aebd1fb4SNicholas Piggin  * This expands to a sequence of operations with reg incrementing from
21aebd1fb4SNicholas Piggin  * start to end inclusive, of this form:
22aebd1fb4SNicholas Piggin  *
23aebd1fb4SNicholas Piggin  *   op  reg, (offset + (width * reg))(base)
24aebd1fb4SNicholas Piggin  *
25aebd1fb4SNicholas Piggin  * Note that offset is not the offset of the first operation unless start
26aebd1fb4SNicholas Piggin  * is zero (or width is zero).
27aebd1fb4SNicholas Piggin  */
28aebd1fb4SNicholas Piggin .macro OP_REGS op, width, start, end, base, offset
29aebd1fb4SNicholas Piggin 	.Lreg=\start
30aebd1fb4SNicholas Piggin 	.rept (\end - \start + 1)
31aebd1fb4SNicholas Piggin 	\op	.Lreg, \offset + \width * .Lreg(\base)
32aebd1fb4SNicholas Piggin 	.Lreg=.Lreg+1
33aebd1fb4SNicholas Piggin 	.endr
34aebd1fb4SNicholas Piggin .endm
35aebd1fb4SNicholas Piggin 
36aebd1fb4SNicholas Piggin /*
379d54a5ceSRohan McLure  * This expands to a sequence of register clears for regs start to end
389d54a5ceSRohan McLure  * inclusive, of the form:
399d54a5ceSRohan McLure  *
409d54a5ceSRohan McLure  *   li rN, 0
419d54a5ceSRohan McLure  */
429d54a5ceSRohan McLure .macro ZEROIZE_REGS start, end
439d54a5ceSRohan McLure 	.Lreg=\start
449d54a5ceSRohan McLure 	.rept (\end - \start + 1)
459d54a5ceSRohan McLure 	li	.Lreg, 0
469d54a5ceSRohan McLure 	.Lreg=.Lreg+1
479d54a5ceSRohan McLure 	.endr
489d54a5ceSRohan McLure .endm
499d54a5ceSRohan McLure 
509d54a5ceSRohan McLure /*
51b8b572e1SStephen Rothwell  * Macros for storing registers into and loading registers from
52b8b572e1SStephen Rothwell  * exception frames.
53b8b572e1SStephen Rothwell  */
54b8b572e1SStephen Rothwell #ifdef __powerpc64__
55aebd1fb4SNicholas Piggin #define SAVE_GPRS(start, end, base)	OP_REGS std, 8, start, end, base, GPR0
56aebd1fb4SNicholas Piggin #define REST_GPRS(start, end, base)	OP_REGS ld, 8, start, end, base, GPR0
57aebd1fb4SNicholas Piggin #define SAVE_NVGPRS(base)		SAVE_GPRS(14, 31, base)
58aebd1fb4SNicholas Piggin #define REST_NVGPRS(base)		REST_GPRS(14, 31, base)
59b8b572e1SStephen Rothwell #else
60aebd1fb4SNicholas Piggin #define SAVE_GPRS(start, end, base)	OP_REGS stw, 4, start, end, base, GPR0
61aebd1fb4SNicholas Piggin #define REST_GPRS(start, end, base)	OP_REGS lwz, 4, start, end, base, GPR0
62aebd1fb4SNicholas Piggin #define SAVE_NVGPRS(base)		SAVE_GPRS(13, 31, base)
63aebd1fb4SNicholas Piggin #define REST_NVGPRS(base)		REST_GPRS(13, 31, base)
64b8b572e1SStephen Rothwell #endif
65b8b572e1SStephen Rothwell 
669d54a5ceSRohan McLure #define	ZEROIZE_GPRS(start, end)	ZEROIZE_REGS start, end
679d54a5ceSRohan McLure #ifdef __powerpc64__
689d54a5ceSRohan McLure #define	ZEROIZE_NVGPRS()		ZEROIZE_GPRS(14, 31)
699d54a5ceSRohan McLure #else
709d54a5ceSRohan McLure #define	ZEROIZE_NVGPRS()		ZEROIZE_GPRS(13, 31)
719d54a5ceSRohan McLure #endif
729d54a5ceSRohan McLure #define	ZEROIZE_GPR(n)			ZEROIZE_GPRS(n, n)
739d54a5ceSRohan McLure 
74aebd1fb4SNicholas Piggin #define SAVE_GPR(n, base)		SAVE_GPRS(n, n, base)
75aebd1fb4SNicholas Piggin #define REST_GPR(n, base)		REST_GPRS(n, n, base)
76b8b572e1SStephen Rothwell 
77cbf892baSRohan McLure /* macros for handling user register sanitisation */
78cbf892baSRohan McLure #ifdef CONFIG_INTERRUPT_SANITIZE_REGISTERS
79cbf892baSRohan McLure #define SANITIZE_SYSCALL_GPRS()			ZEROIZE_GPR(0);		\
80cbf892baSRohan McLure 						ZEROIZE_GPRS(5, 12);	\
81cbf892baSRohan McLure 						ZEROIZE_NVGPRS()
82cbf892baSRohan McLure #define SANITIZE_GPR(n)				ZEROIZE_GPR(n)
83cbf892baSRohan McLure #define SANITIZE_GPRS(start, end)		ZEROIZE_GPRS(start, end)
84cbf892baSRohan McLure #define SANITIZE_NVGPRS()			ZEROIZE_NVGPRS()
85cbf892baSRohan McLure #define SANITIZE_RESTORE_NVGPRS()		REST_NVGPRS(r1)
86cbf892baSRohan McLure #define HANDLER_RESTORE_NVGPRS()
87cbf892baSRohan McLure #else
88cbf892baSRohan McLure #define SANITIZE_SYSCALL_GPRS()
89cbf892baSRohan McLure #define SANITIZE_GPR(n)
90cbf892baSRohan McLure #define SANITIZE_GPRS(start, end)
91cbf892baSRohan McLure #define SANITIZE_NVGPRS()
92cbf892baSRohan McLure #define SANITIZE_RESTORE_NVGPRS()
93cbf892baSRohan McLure #define HANDLER_RESTORE_NVGPRS()		REST_NVGPRS(r1)
94cbf892baSRohan McLure #endif /* CONFIG_INTERRUPT_SANITIZE_REGISTERS */
95cbf892baSRohan McLure 
96de79f7b9SPaul Mackerras #define SAVE_FPR(n, base)	stfd	n,8*TS_FPRWIDTH*(n)(base)
97b8b572e1SStephen Rothwell #define SAVE_2FPRS(n, base)	SAVE_FPR(n, base); SAVE_FPR(n+1, base)
98b8b572e1SStephen Rothwell #define SAVE_4FPRS(n, base)	SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
99b8b572e1SStephen Rothwell #define SAVE_8FPRS(n, base)	SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
100b8b572e1SStephen Rothwell #define SAVE_16FPRS(n, base)	SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
101b8b572e1SStephen Rothwell #define SAVE_32FPRS(n, base)	SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
102de79f7b9SPaul Mackerras #define REST_FPR(n, base)	lfd	n,8*TS_FPRWIDTH*(n)(base)
103b8b572e1SStephen Rothwell #define REST_2FPRS(n, base)	REST_FPR(n, base); REST_FPR(n+1, base)
104b8b572e1SStephen Rothwell #define REST_4FPRS(n, base)	REST_2FPRS(n, base); REST_2FPRS(n+2, base)
105b8b572e1SStephen Rothwell #define REST_8FPRS(n, base)	REST_4FPRS(n, base); REST_4FPRS(n+4, base)
106b8b572e1SStephen Rothwell #define REST_16FPRS(n, base)	REST_8FPRS(n, base); REST_8FPRS(n+8, base)
107b8b572e1SStephen Rothwell #define REST_32FPRS(n, base)	REST_16FPRS(n, base); REST_16FPRS(n+16, base)
108b8b572e1SStephen Rothwell 
109de79f7b9SPaul Mackerras #define SAVE_VR(n,b,base)	li b,16*(n);  stvx n,base,b
110b8b572e1SStephen Rothwell #define SAVE_2VRS(n,b,base)	SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
111b8b572e1SStephen Rothwell #define SAVE_4VRS(n,b,base)	SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
112b8b572e1SStephen Rothwell #define SAVE_8VRS(n,b,base)	SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
113b8b572e1SStephen Rothwell #define SAVE_16VRS(n,b,base)	SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
114b8b572e1SStephen Rothwell #define SAVE_32VRS(n,b,base)	SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
115de79f7b9SPaul Mackerras #define REST_VR(n,b,base)	li b,16*(n); lvx n,base,b
116b8b572e1SStephen Rothwell #define REST_2VRS(n,b,base)	REST_VR(n,b,base); REST_VR(n+1,b,base)
117b8b572e1SStephen Rothwell #define REST_4VRS(n,b,base)	REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
118b8b572e1SStephen Rothwell #define REST_8VRS(n,b,base)	REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
119b8b572e1SStephen Rothwell #define REST_16VRS(n,b,base)	REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
120b8b572e1SStephen Rothwell #define REST_32VRS(n,b,base)	REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
121b8b572e1SStephen Rothwell 
122926f160fSAnton Blanchard #ifdef __BIG_ENDIAN__
123926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base)		STXVD2X(n,b,base)
124926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base)
125926f160fSAnton Blanchard #else
126926f160fSAnton Blanchard #define STXVD2X_ROT(n,b,base)		XXSWAPD(n,n);		\
127926f160fSAnton Blanchard 					STXVD2X(n,b,base);	\
128926f160fSAnton Blanchard 					XXSWAPD(n,n)
129926f160fSAnton Blanchard 
130926f160fSAnton Blanchard #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base);	\
131926f160fSAnton Blanchard 					XXSWAPD(n,n)
132926f160fSAnton Blanchard #endif
133b8b572e1SStephen Rothwell /* Save the lower 32 VSRs in the thread VSR region */
1343ad26e5cSBenjamin Herrenschmidt #define SAVE_VSR(n,b,base)	li b,16*(n);  STXVD2X_ROT(n,R##base,R##b)
135b8b572e1SStephen Rothwell #define SAVE_2VSRS(n,b,base)	SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
136b8b572e1SStephen Rothwell #define SAVE_4VSRS(n,b,base)	SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
137b8b572e1SStephen Rothwell #define SAVE_8VSRS(n,b,base)	SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
138b8b572e1SStephen Rothwell #define SAVE_16VSRS(n,b,base)	SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
139b8b572e1SStephen Rothwell #define SAVE_32VSRS(n,b,base)	SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
1403ad26e5cSBenjamin Herrenschmidt #define REST_VSR(n,b,base)	li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
141b8b572e1SStephen Rothwell #define REST_2VSRS(n,b,base)	REST_VSR(n,b,base); REST_VSR(n+1,b,base)
142b8b572e1SStephen Rothwell #define REST_4VSRS(n,b,base)	REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
143b8b572e1SStephen Rothwell #define REST_8VSRS(n,b,base)	REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
144b8b572e1SStephen Rothwell #define REST_16VSRS(n,b,base)	REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
145b8b572e1SStephen Rothwell #define REST_32VSRS(n,b,base)	REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
146b8b572e1SStephen Rothwell 
147c51584d5SScott Wood /*
148c51584d5SScott Wood  * b = base register for addressing, o = base offset from register of 1st EVR
149c51584d5SScott Wood  * n = first EVR, s = scratch
150c51584d5SScott Wood  */
151c51584d5SScott Wood #define SAVE_EVR(n,s,b,o)	evmergehi s,s,n; stw s,o+4*(n)(b)
152c51584d5SScott Wood #define SAVE_2EVRS(n,s,b,o)	SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
153c51584d5SScott Wood #define SAVE_4EVRS(n,s,b,o)	SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
154c51584d5SScott Wood #define SAVE_8EVRS(n,s,b,o)	SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
155c51584d5SScott Wood #define SAVE_16EVRS(n,s,b,o)	SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
156c51584d5SScott Wood #define SAVE_32EVRS(n,s,b,o)	SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
157c51584d5SScott Wood #define REST_EVR(n,s,b,o)	lwz s,o+4*(n)(b); evmergelo n,s,n
158c51584d5SScott Wood #define REST_2EVRS(n,s,b,o)	REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
159c51584d5SScott Wood #define REST_4EVRS(n,s,b,o)	REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
160c51584d5SScott Wood #define REST_8EVRS(n,s,b,o)	REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
161c51584d5SScott Wood #define REST_16EVRS(n,s,b,o)	REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
162c51584d5SScott Wood #define REST_32EVRS(n,s,b,o)	REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
163b8b572e1SStephen Rothwell 
164b8b572e1SStephen Rothwell /* Macros to adjust thread priority for hardware multithreading */
165b8b572e1SStephen Rothwell #define HMT_VERY_LOW	or	31,31,31	# very low priority
166b8b572e1SStephen Rothwell #define HMT_LOW		or	1,1,1
167b8b572e1SStephen Rothwell #define HMT_MEDIUM_LOW  or	6,6,6		# medium low priority
168b8b572e1SStephen Rothwell #define HMT_MEDIUM	or	2,2,2
169b8b572e1SStephen Rothwell #define HMT_MEDIUM_HIGH or	5,5,5		# medium high priority
170b8b572e1SStephen Rothwell #define HMT_HIGH	or	3,3,3
17150fb8ebeSBenjamin Herrenschmidt #define HMT_EXTRA_HIGH	or	7,7,7		# power7 only
172b8b572e1SStephen Rothwell 
173d72be892SMichael Neuling #ifdef CONFIG_PPC64
174d72be892SMichael Neuling #define ULONG_SIZE 	8
175d72be892SMichael Neuling #else
176d72be892SMichael Neuling #define ULONG_SIZE	4
177d72be892SMichael Neuling #endif
1780b7673c3SMichael Neuling #define __VCPU_GPR(n)	(VCPU_GPRS + (n * ULONG_SIZE))
1790b7673c3SMichael Neuling #define VCPU_GPR(n)	__VCPU_GPR(__REG_##n)
180d72be892SMichael Neuling 
181b8b572e1SStephen Rothwell #ifdef __KERNEL__
1822eda7f11SMichael Ellerman 
1832eda7f11SMichael Ellerman /*
184*4e991e3cSNicholas Piggin  * Used to name C functions called from asm
185*4e991e3cSNicholas Piggin  */
186*4e991e3cSNicholas Piggin #define CFUNC(name) name
187*4e991e3cSNicholas Piggin 
188*4e991e3cSNicholas Piggin /*
1892eda7f11SMichael Ellerman  * We use __powerpc64__ here because we want the compat VDSO to use the 32-bit
1902eda7f11SMichael Ellerman  * version below in the else case of the ifdef.
1912eda7f11SMichael Ellerman  */
1922eda7f11SMichael Ellerman #ifdef __powerpc64__
193b8b572e1SStephen Rothwell 
19444ce6a5eSMichael Neuling #define STACKFRAMESIZE 256
1950b7673c3SMichael Neuling #define __STK_REG(i)   (112 + ((i)-14)*8)
1960b7673c3SMichael Neuling #define STK_REG(i)     __STK_REG(__REG_##i)
19744ce6a5eSMichael Neuling 
1987d40aff8SChristophe Leroy #ifdef CONFIG_PPC64_ELF_ABI_V2
1996403105bSAnton Blanchard #define STK_GOT		24
200b37c10d1SAnton Blanchard #define __STK_PARAM(i)	(32 + ((i)-3)*8)
201b37c10d1SAnton Blanchard #else
2026403105bSAnton Blanchard #define STK_GOT		40
2030b7673c3SMichael Neuling #define __STK_PARAM(i)	(48 + ((i)-3)*8)
204b37c10d1SAnton Blanchard #endif
2050b7673c3SMichael Neuling #define STK_PARAM(i)	__STK_PARAM(__REG_##i)
20644ce6a5eSMichael Neuling 
2077d40aff8SChristophe Leroy #ifdef CONFIG_PPC64_ELF_ABI_V2
2087167af7cSAnton Blanchard 
2097167af7cSAnton Blanchard #define _GLOBAL(name) \
2107167af7cSAnton Blanchard 	.align 2 ; \
2117167af7cSAnton Blanchard 	.type name,@function; \
2127167af7cSAnton Blanchard 	.globl name; \
2137167af7cSAnton Blanchard name:
2147167af7cSAnton Blanchard 
215169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) \
216169c7ceeSAnton Blanchard 	.align 2 ; \
217169c7ceeSAnton Blanchard 	.type name,@function; \
218169c7ceeSAnton Blanchard 	.globl name; \
219169c7ceeSAnton Blanchard name: \
220169c7ceeSAnton Blanchard 0:	addis r2,r12,(.TOC.-0b)@ha; \
221169c7ceeSAnton Blanchard 	addi r2,r2,(.TOC.-0b)@l; \
222169c7ceeSAnton Blanchard 	.localentry name,.-name
223169c7ceeSAnton Blanchard 
2247167af7cSAnton Blanchard #define DOTSYM(a)	a
2257167af7cSAnton Blanchard 
2267167af7cSAnton Blanchard #else
2277167af7cSAnton Blanchard 
228b8b572e1SStephen Rothwell #define XGLUE(a,b) a##b
229b8b572e1SStephen Rothwell #define GLUE(a,b) XGLUE(a,b)
230b8b572e1SStephen Rothwell 
231b8b572e1SStephen Rothwell #define _GLOBAL(name) \
232b8b572e1SStephen Rothwell 	.align 2 ; \
233b8b572e1SStephen Rothwell 	.globl name; \
234b8b572e1SStephen Rothwell 	.globl GLUE(.,name); \
235bea2dcccSMichael Ellerman 	.pushsection ".opd","aw"; \
236b8b572e1SStephen Rothwell name: \
237b8b572e1SStephen Rothwell 	.quad GLUE(.,name); \
238b8b572e1SStephen Rothwell 	.quad .TOC.@tocbase; \
239b8b572e1SStephen Rothwell 	.quad 0; \
240bea2dcccSMichael Ellerman 	.popsection; \
241b8b572e1SStephen Rothwell 	.type GLUE(.,name),@function; \
242b8b572e1SStephen Rothwell GLUE(.,name):
243b8b572e1SStephen Rothwell 
244169c7ceeSAnton Blanchard #define _GLOBAL_TOC(name) _GLOBAL(name)
245169c7ceeSAnton Blanchard 
246c1fb0194SAnton Blanchard #define DOTSYM(a)	GLUE(.,a)
247c1fb0194SAnton Blanchard 
2487167af7cSAnton Blanchard #endif
2497167af7cSAnton Blanchard 
250b8b572e1SStephen Rothwell #else /* 32-bit */
251b8b572e1SStephen Rothwell 
252b8b572e1SStephen Rothwell #define _GLOBAL(n)	\
253b8b572e1SStephen Rothwell 	.globl n;	\
254b8b572e1SStephen Rothwell n:
255b8b572e1SStephen Rothwell 
2569715a2e8SAlexander Graf #define _GLOBAL_TOC(name) _GLOBAL(name)
2579715a2e8SAlexander Graf 
258ce7d8056SChristophe Leroy #define DOTSYM(a)	a
259ce7d8056SChristophe Leroy 
260b8b572e1SStephen Rothwell #endif
261b8b572e1SStephen Rothwell 
2626f698df1SNicholas Piggin /*
2636f698df1SNicholas Piggin  * __kprobes (the C annotation) puts the symbol into the .kprobes.text
2646f698df1SNicholas Piggin  * section, which gets emitted at the end of regular text.
2656f698df1SNicholas Piggin  *
2666f698df1SNicholas Piggin  * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
2676f698df1SNicholas Piggin  * a blacklist. The former is for core kprobe functions/data, the
2686f698df1SNicholas Piggin  * latter is for those that incdentially must be excluded from probing
2696f698df1SNicholas Piggin  * and allows them to be linked at more optimal location within text.
2706f698df1SNicholas Piggin  */
271c0a51491SNicholas Piggin #ifdef CONFIG_KPROBES
2726f698df1SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry)			\
2736f698df1SNicholas Piggin 	.pushsection "_kprobe_blacklist","aw";		\
2746f698df1SNicholas Piggin 	PPC_LONG (entry) ;				\
2756f698df1SNicholas Piggin 	.popsection
276c0a51491SNicholas Piggin #else
277c0a51491SNicholas Piggin #define _ASM_NOKPROBE_SYMBOL(entry)
278c0a51491SNicholas Piggin #endif
2796f698df1SNicholas Piggin 
280151f2511SAnton Blanchard #define FUNC_START(name)	_GLOBAL(name)
281151f2511SAnton Blanchard #define FUNC_END(name)
282151f2511SAnton Blanchard 
283b8b572e1SStephen Rothwell /*
284b8b572e1SStephen Rothwell  * LOAD_REG_IMMEDIATE(rn, expr)
285b8b572e1SStephen Rothwell  *   Loads the value of the constant expression 'expr' into register 'rn'
286b8b572e1SStephen Rothwell  *   using immediate instructions only.  Use this when it's important not
287b8b572e1SStephen Rothwell  *   to reference other data (i.e. on ppc64 when the TOC pointer is not
288e31aa453SPaul Mackerras  *   valid) and when 'expr' is a constant or absolute address.
289b8b572e1SStephen Rothwell  *
290b8b572e1SStephen Rothwell  * LOAD_REG_ADDR(rn, name)
291b8b572e1SStephen Rothwell  *   Loads the address of label 'name' into register 'rn'.  Use this when
292b8b572e1SStephen Rothwell  *   you don't particularly need immediate instructions only, but you need
293b8b572e1SStephen Rothwell  *   the whole address in one register (e.g. it's a structure address and
294b8b572e1SStephen Rothwell  *   you want to access various offsets within it).  On ppc32 this is
295b8b572e1SStephen Rothwell  *   identical to LOAD_REG_IMMEDIATE.
296b8b572e1SStephen Rothwell  *
2971c49abecSKevin Hao  * LOAD_REG_ADDR_PIC(rn, name)
2981c49abecSKevin Hao  *   Loads the address of label 'name' into register 'run'. Use this when
2991c49abecSKevin Hao  *   the kernel doesn't run at the linked or relocated address. Please
3001c49abecSKevin Hao  *   note that this macro will clobber the lr register.
3011c49abecSKevin Hao  *
302b8b572e1SStephen Rothwell  * LOAD_REG_ADDRBASE(rn, name)
303b8b572e1SStephen Rothwell  * ADDROFF(name)
304b8b572e1SStephen Rothwell  *   LOAD_REG_ADDRBASE loads part of the address of label 'name' into
305b8b572e1SStephen Rothwell  *   register 'rn'.  ADDROFF(name) returns the remainder of the address as
306b8b572e1SStephen Rothwell  *   a constant expression.  ADDROFF(name) is a signed expression < 16 bits
307b8b572e1SStephen Rothwell  *   in size, so is suitable for use directly as an offset in load and store
308b8b572e1SStephen Rothwell  *   instructions.  Use this when loading/storing a single word or less as:
309b8b572e1SStephen Rothwell  *      LOAD_REG_ADDRBASE(rX, name)
310b8b572e1SStephen Rothwell  *      ld	rY,ADDROFF(name)(rX)
311b8b572e1SStephen Rothwell  */
3121c49abecSKevin Hao 
3131c49abecSKevin Hao /* Be careful, this will clobber the lr register. */
3141c49abecSKevin Hao #define LOAD_REG_ADDR_PIC(reg, name)		\
315f5007dbfSChristophe Leroy 	bcl	20,31,$+4;			\
3161c49abecSKevin Hao 0:	mflr	reg;				\
3171c49abecSKevin Hao 	addis	reg,reg,(name - 0b)@ha;		\
3181c49abecSKevin Hao 	addi	reg,reg,(name - 0b)@l;
3191c49abecSKevin Hao 
320c691b4b8SChristophe Leroy #if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH)
3217998eb3dSGuenter Roeck #define __AS_ATHIGH high
3227998eb3dSGuenter Roeck #else
3237998eb3dSGuenter Roeck #define __AS_ATHIGH h
3247998eb3dSGuenter Roeck #endif
325c691b4b8SChristophe Leroy 
326c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE_32 r, x
327c691b4b8SChristophe Leroy 	.if (\x) >= 0x8000 || (\x) < -0x8000
328c691b4b8SChristophe Leroy 		lis \r, (\x)@__AS_ATHIGH
329c691b4b8SChristophe Leroy 		.if (\x) & 0xffff != 0
330c691b4b8SChristophe Leroy 			ori \r, \r, (\x)@l
331c691b4b8SChristophe Leroy 		.endif
332c691b4b8SChristophe Leroy 	.else
333c691b4b8SChristophe Leroy 		li \r, (\x)@l
334c691b4b8SChristophe Leroy 	.endif
335c691b4b8SChristophe Leroy .endm
336c691b4b8SChristophe Leroy 
337c691b4b8SChristophe Leroy .macro __LOAD_REG_IMMEDIATE r, x
338c691b4b8SChristophe Leroy 	.if (\x) >= 0x80000000 || (\x) < -0x80000000
339c691b4b8SChristophe Leroy 		__LOAD_REG_IMMEDIATE_32 \r, (\x) >> 32
340c691b4b8SChristophe Leroy 		sldi	\r, \r, 32
341c691b4b8SChristophe Leroy 		.if (\x) & 0xffff0000 != 0
342c691b4b8SChristophe Leroy 			oris \r, \r, (\x)@__AS_ATHIGH
343c691b4b8SChristophe Leroy 		.endif
344c691b4b8SChristophe Leroy 		.if (\x) & 0xffff != 0
345c691b4b8SChristophe Leroy 			ori \r, \r, (\x)@l
346c691b4b8SChristophe Leroy 		.endif
347c691b4b8SChristophe Leroy 	.else
348c691b4b8SChristophe Leroy 		__LOAD_REG_IMMEDIATE_32 \r, \x
349c691b4b8SChristophe Leroy 	.endif
350c691b4b8SChristophe Leroy .endm
351c691b4b8SChristophe Leroy 
352c691b4b8SChristophe Leroy #ifdef __powerpc64__
353c691b4b8SChristophe Leroy 
3548e93fb33SNicholas Piggin #define __LOAD_PACA_TOC(reg)			\
3558e93fb33SNicholas Piggin 	ld	reg,PACATOC(r13)
3568e93fb33SNicholas Piggin 
3578e93fb33SNicholas Piggin #define LOAD_PACA_TOC()				\
3588e93fb33SNicholas Piggin 	__LOAD_PACA_TOC(r2)
3598e93fb33SNicholas Piggin 
360c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE reg, expr
361c691b4b8SChristophe Leroy 
362d7fb5b18SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg, tmp, expr)	\
363d7fb5b18SChristophe Leroy 	lis	tmp, (expr)@highest;		\
364d7fb5b18SChristophe Leroy 	lis	reg, (expr)@__AS_ATHIGH;	\
365d7fb5b18SChristophe Leroy 	ori	tmp, tmp, (expr)@higher;	\
366d7fb5b18SChristophe Leroy 	ori	reg, reg, (expr)@l;		\
367d7fb5b18SChristophe Leroy 	rldimi	reg, tmp, 32, 0
368b8b572e1SStephen Rothwell 
369b8b572e1SStephen Rothwell #define LOAD_REG_ADDR(reg,name)			\
370754f6117SNicholas Piggin 	addis	reg,r2,name@toc@ha;		\
371754f6117SNicholas Piggin 	addi	reg,reg,name@toc@l
372b8b572e1SStephen Rothwell 
3733569d84bSNicholas Piggin #ifdef CONFIG_PPC_BOOK3E_64
3743569d84bSNicholas Piggin /*
3753569d84bSNicholas Piggin  * This is used in register-constrained interrupt handlers. Not to be used
3763569d84bSNicholas Piggin  * by BOOK3S. ld complains with "got/toc optimization is not supported" if r2
3773569d84bSNicholas Piggin  * is not used for the TOC offset, so use @got(tocreg). If the interrupt
3783569d84bSNicholas Piggin  * handlers saved r2 instead, LOAD_REG_ADDR could be used.
3793569d84bSNicholas Piggin  */
3803569d84bSNicholas Piggin #define LOAD_REG_ADDR_ALTTOC(reg,tocreg,name)	\
3813569d84bSNicholas Piggin 	ld	reg,name@got(tocreg)
3823569d84bSNicholas Piggin #endif
3833569d84bSNicholas Piggin 
384b8b572e1SStephen Rothwell #define LOAD_REG_ADDRBASE(reg,name)	LOAD_REG_ADDR(reg,name)
385b8b572e1SStephen Rothwell #define ADDROFF(name)			0
386b8b572e1SStephen Rothwell 
387b8b572e1SStephen Rothwell /* offsets for stack frame layout */
388b8b572e1SStephen Rothwell #define LRSAVE	16
389b8b572e1SStephen Rothwell 
390b8b572e1SStephen Rothwell #else /* 32-bit */
391b8b572e1SStephen Rothwell 
392c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr
393c691b4b8SChristophe Leroy 
394c691b4b8SChristophe Leroy #define LOAD_REG_IMMEDIATE_SYM(reg,expr)		\
395564aa5cfSMichael Neuling 	lis	reg,(expr)@ha;		\
396564aa5cfSMichael Neuling 	addi	reg,reg,(expr)@l;
397b8b572e1SStephen Rothwell 
398c691b4b8SChristophe Leroy #define LOAD_REG_ADDR(reg,name)		LOAD_REG_IMMEDIATE_SYM(reg, name)
399b8b572e1SStephen Rothwell 
400564aa5cfSMichael Neuling #define LOAD_REG_ADDRBASE(reg, name)	lis	reg,name@ha
401b8b572e1SStephen Rothwell #define ADDROFF(name)			name@l
402b8b572e1SStephen Rothwell 
403b8b572e1SStephen Rothwell /* offsets for stack frame layout */
404b8b572e1SStephen Rothwell #define LRSAVE	4
405b8b572e1SStephen Rothwell 
406b8b572e1SStephen Rothwell #endif
407b8b572e1SStephen Rothwell 
408b8b572e1SStephen Rothwell /* various errata or part fixups */
4093e731858SChristophe Leroy #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_E500)
410b8b572e1SStephen Rothwell #define MFTB(dest)			\
411beb2dc0aSScott Wood 90:	mfspr dest, SPRN_TBRL;		\
412b8b572e1SStephen Rothwell BEGIN_FTR_SECTION_NESTED(96);		\
413b8b572e1SStephen Rothwell 	cmpwi dest,0;			\
414b8b572e1SStephen Rothwell 	beq-  90b;			\
415b8b572e1SStephen Rothwell END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
416b8b572e1SStephen Rothwell #else
41772e4b2cdSChristophe Leroy #define MFTB(dest)			MFTBL(dest)
41872e4b2cdSChristophe Leroy #endif
41972e4b2cdSChristophe Leroy 
42072e4b2cdSChristophe Leroy #ifdef CONFIG_PPC_8xx
42172e4b2cdSChristophe Leroy #define MFTBL(dest)			mftb dest
42272e4b2cdSChristophe Leroy #define MFTBU(dest)			mftbu dest
42372e4b2cdSChristophe Leroy #else
42472e4b2cdSChristophe Leroy #define MFTBL(dest)			mfspr dest, SPRN_TBRL
42572e4b2cdSChristophe Leroy #define MFTBU(dest)			mfspr dest, SPRN_TBRU
426b8b572e1SStephen Rothwell #endif
427b8b572e1SStephen Rothwell 
4288b14e1dfSChristophe Leroy #ifndef CONFIG_SMP
42912c3f1fdSChristophe Leroy #define TLBSYNC
43012c3f1fdSChristophe Leroy #else
43112c3f1fdSChristophe Leroy #define TLBSYNC		tlbsync; sync
432b8b572e1SStephen Rothwell #endif
433b8b572e1SStephen Rothwell 
434694caf02SAnton Blanchard #ifdef CONFIG_PPC64
435694caf02SAnton Blanchard #define MTOCRF(FXM, RS)			\
436694caf02SAnton Blanchard 	BEGIN_FTR_SECTION_NESTED(848);	\
43786e32fdcSMichael Neuling 	mtcrf	(FXM), RS;		\
438694caf02SAnton Blanchard 	FTR_SECTION_ELSE_NESTED(848);	\
43986e32fdcSMichael Neuling 	mtocrf (FXM), RS;		\
440694caf02SAnton Blanchard 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
441694caf02SAnton Blanchard #endif
442b8b572e1SStephen Rothwell 
443b8b572e1SStephen Rothwell /*
444b8b572e1SStephen Rothwell  * This instruction is not implemented on the PPC 603 or 601; however, on
445b8b572e1SStephen Rothwell  * the 403GCX and 405GP tlbia IS defined and tlbie is not.
446b8b572e1SStephen Rothwell  * All of these instructions exist in the 8xx, they have magical powers,
447b8b572e1SStephen Rothwell  * and they must be used.
448b8b572e1SStephen Rothwell  */
449b8b572e1SStephen Rothwell 
450968159c0SChristophe Leroy #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx)
451b8b572e1SStephen Rothwell #define tlbia					\
452b8b572e1SStephen Rothwell 	li	r4,1024;			\
453b8b572e1SStephen Rothwell 	mtctr	r4;				\
454b8b572e1SStephen Rothwell 	lis	r4,KERNELBASE@h;		\
455e3824e42SRussell Currey 	.machine push;				\
456e3824e42SRussell Currey 	.machine "power4";			\
457b8b572e1SStephen Rothwell 0:	tlbie	r4;				\
458e3824e42SRussell Currey 	.machine pop;				\
459b8b572e1SStephen Rothwell 	addi	r4,r4,0x1000;			\
460b8b572e1SStephen Rothwell 	bdnz	0b
461b8b572e1SStephen Rothwell #endif
462b8b572e1SStephen Rothwell 
463b8b572e1SStephen Rothwell 
464b8b572e1SStephen Rothwell #ifdef CONFIG_IBM440EP_ERR42
465b8b572e1SStephen Rothwell #define PPC440EP_ERR42 isync
466b8b572e1SStephen Rothwell #else
467b8b572e1SStephen Rothwell #define PPC440EP_ERR42
468b8b572e1SStephen Rothwell #endif
469b8b572e1SStephen Rothwell 
470a515348fSMichael Neuling /* The following stops all load and store data streams associated with stream
471a515348fSMichael Neuling  * ID (ie. streams created explicitly).  The embedded and server mnemonics for
47215a3204dSNicholas Piggin  * dcbt are different so this must only be used for server.
473a515348fSMichael Neuling  */
47415a3204dSNicholas Piggin #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch)	\
475a515348fSMichael Neuling        lis     scratch,0x60000000@h;			\
47615a3204dSNicholas Piggin        dcbt    0,scratch,0b01010
477a515348fSMichael Neuling 
47844c58cccSBenjamin Herrenschmidt /*
47944c58cccSBenjamin Herrenschmidt  * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
48044c58cccSBenjamin Herrenschmidt  * keep the address intact to be compatible with code shared with
48144c58cccSBenjamin Herrenschmidt  * 32-bit classic.
48244c58cccSBenjamin Herrenschmidt  *
48344c58cccSBenjamin Herrenschmidt  * On the other hand, I find it useful to have them behave as expected
48444c58cccSBenjamin Herrenschmidt  * by their name (ie always do the addition) on 64-bit BookE
48544c58cccSBenjamin Herrenschmidt  */
48644c58cccSBenjamin Herrenschmidt #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
487b8b572e1SStephen Rothwell #define toreal(rd)
488b8b572e1SStephen Rothwell #define fromreal(rd)
489b8b572e1SStephen Rothwell 
490b8b572e1SStephen Rothwell /*
491b8b572e1SStephen Rothwell  * We use addis to ensure compatibility with the "classic" ppc versions of
492b8b572e1SStephen Rothwell  * these macros, which use rs = 0 to get the tophys offset in rd, rather than
493b8b572e1SStephen Rothwell  * converting the address in r0, and so this version has to do that too
494b8b572e1SStephen Rothwell  * (i.e. set register rd to 0 when rs == 0).
495b8b572e1SStephen Rothwell  */
496b8b572e1SStephen Rothwell #define tophys(rd,rs)				\
497b8b572e1SStephen Rothwell 	addis	rd,rs,0
498b8b572e1SStephen Rothwell 
499b8b572e1SStephen Rothwell #define tovirt(rd,rs)				\
500b8b572e1SStephen Rothwell 	addis	rd,rs,0
501b8b572e1SStephen Rothwell 
502b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC64)
503b8b572e1SStephen Rothwell #define toreal(rd)		/* we can access c000... in real mode */
504b8b572e1SStephen Rothwell #define fromreal(rd)
505b8b572e1SStephen Rothwell 
506b8b572e1SStephen Rothwell #define tophys(rd,rs)                           \
507b8b572e1SStephen Rothwell 	clrldi	rd,rs,2
508b8b572e1SStephen Rothwell 
509b8b572e1SStephen Rothwell #define tovirt(rd,rs)                           \
510b8b572e1SStephen Rothwell 	rotldi	rd,rs,16;			\
511b8b572e1SStephen Rothwell 	ori	rd,rd,((KERNELBASE>>48)&0xFFFF);\
512b8b572e1SStephen Rothwell 	rotldi	rd,rd,48
513b8b572e1SStephen Rothwell #else
514b8b572e1SStephen Rothwell #define toreal(rd)	tophys(rd,rd)
515b8b572e1SStephen Rothwell #define fromreal(rd)	tovirt(rd,rd)
516b8b572e1SStephen Rothwell 
517c62ce9efSChristophe Leroy #define tophys(rd, rs)	addis	rd, rs, -PAGE_OFFSET@h
518c62ce9efSChristophe Leroy #define tovirt(rd, rs)	addis	rd, rs, PAGE_OFFSET@h
519b8b572e1SStephen Rothwell #endif
520b8b572e1SStephen Rothwell 
52144c58cccSBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S_64
522b8b572e1SStephen Rothwell #define MTMSRD(r)	mtmsrd	r
523b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg)	mtmsrd	reg,1
524b8b572e1SStephen Rothwell #else
525b8b572e1SStephen Rothwell #define MTMSRD(r)	mtmsr	r
526b38c77d8SBenjamin Herrenschmidt #define MTMSR_EERI(reg)	mtmsr	reg
527b8b572e1SStephen Rothwell #endif
528b8b572e1SStephen Rothwell 
529b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
530b8b572e1SStephen Rothwell 
531b8b572e1SStephen Rothwell /* The boring bits... */
532b8b572e1SStephen Rothwell 
533b8b572e1SStephen Rothwell /* Condition Register Bit Fields */
534b8b572e1SStephen Rothwell 
535b8b572e1SStephen Rothwell #define	cr0	0
536b8b572e1SStephen Rothwell #define	cr1	1
537b8b572e1SStephen Rothwell #define	cr2	2
538b8b572e1SStephen Rothwell #define	cr3	3
539b8b572e1SStephen Rothwell #define	cr4	4
540b8b572e1SStephen Rothwell #define	cr5	5
541b8b572e1SStephen Rothwell #define	cr6	6
542b8b572e1SStephen Rothwell #define	cr7	7
543b8b572e1SStephen Rothwell 
544b8b572e1SStephen Rothwell 
5459a13a524SMichael Neuling /*
5469a13a524SMichael Neuling  * General Purpose Registers (GPRs)
5479a13a524SMichael Neuling  *
5489a13a524SMichael Neuling  * The lower case r0-r31 should be used in preference to the upper
5499a13a524SMichael Neuling  * case R0-R31 as they provide more error checking in the assembler.
5509a13a524SMichael Neuling  * Use R0-31 only when really nessesary.
5519a13a524SMichael Neuling  */
552b8b572e1SStephen Rothwell 
5539a13a524SMichael Neuling #define	r0	%r0
5549a13a524SMichael Neuling #define	r1	%r1
5559a13a524SMichael Neuling #define	r2	%r2
5569a13a524SMichael Neuling #define	r3	%r3
5579a13a524SMichael Neuling #define	r4	%r4
5589a13a524SMichael Neuling #define	r5	%r5
5599a13a524SMichael Neuling #define	r6	%r6
5609a13a524SMichael Neuling #define	r7	%r7
5619a13a524SMichael Neuling #define	r8	%r8
5629a13a524SMichael Neuling #define	r9	%r9
5639a13a524SMichael Neuling #define	r10	%r10
5649a13a524SMichael Neuling #define	r11	%r11
5659a13a524SMichael Neuling #define	r12	%r12
5669a13a524SMichael Neuling #define	r13	%r13
5679a13a524SMichael Neuling #define	r14	%r14
5689a13a524SMichael Neuling #define	r15	%r15
5699a13a524SMichael Neuling #define	r16	%r16
5709a13a524SMichael Neuling #define	r17	%r17
5719a13a524SMichael Neuling #define	r18	%r18
5729a13a524SMichael Neuling #define	r19	%r19
5739a13a524SMichael Neuling #define	r20	%r20
5749a13a524SMichael Neuling #define	r21	%r21
5759a13a524SMichael Neuling #define	r22	%r22
5769a13a524SMichael Neuling #define	r23	%r23
5779a13a524SMichael Neuling #define	r24	%r24
5789a13a524SMichael Neuling #define	r25	%r25
5799a13a524SMichael Neuling #define	r26	%r26
5809a13a524SMichael Neuling #define	r27	%r27
5819a13a524SMichael Neuling #define	r28	%r28
5829a13a524SMichael Neuling #define	r29	%r29
5839a13a524SMichael Neuling #define	r30	%r30
5849a13a524SMichael Neuling #define	r31	%r31
585b8b572e1SStephen Rothwell 
586b8b572e1SStephen Rothwell 
587b8b572e1SStephen Rothwell /* Floating Point Registers (FPRs) */
588b8b572e1SStephen Rothwell 
589b8b572e1SStephen Rothwell #define	fr0	0
590b8b572e1SStephen Rothwell #define	fr1	1
591b8b572e1SStephen Rothwell #define	fr2	2
592b8b572e1SStephen Rothwell #define	fr3	3
593b8b572e1SStephen Rothwell #define	fr4	4
594b8b572e1SStephen Rothwell #define	fr5	5
595b8b572e1SStephen Rothwell #define	fr6	6
596b8b572e1SStephen Rothwell #define	fr7	7
597b8b572e1SStephen Rothwell #define	fr8	8
598b8b572e1SStephen Rothwell #define	fr9	9
599b8b572e1SStephen Rothwell #define	fr10	10
600b8b572e1SStephen Rothwell #define	fr11	11
601b8b572e1SStephen Rothwell #define	fr12	12
602b8b572e1SStephen Rothwell #define	fr13	13
603b8b572e1SStephen Rothwell #define	fr14	14
604b8b572e1SStephen Rothwell #define	fr15	15
605b8b572e1SStephen Rothwell #define	fr16	16
606b8b572e1SStephen Rothwell #define	fr17	17
607b8b572e1SStephen Rothwell #define	fr18	18
608b8b572e1SStephen Rothwell #define	fr19	19
609b8b572e1SStephen Rothwell #define	fr20	20
610b8b572e1SStephen Rothwell #define	fr21	21
611b8b572e1SStephen Rothwell #define	fr22	22
612b8b572e1SStephen Rothwell #define	fr23	23
613b8b572e1SStephen Rothwell #define	fr24	24
614b8b572e1SStephen Rothwell #define	fr25	25
615b8b572e1SStephen Rothwell #define	fr26	26
616b8b572e1SStephen Rothwell #define	fr27	27
617b8b572e1SStephen Rothwell #define	fr28	28
618b8b572e1SStephen Rothwell #define	fr29	29
619b8b572e1SStephen Rothwell #define	fr30	30
620b8b572e1SStephen Rothwell #define	fr31	31
621b8b572e1SStephen Rothwell 
622b8b572e1SStephen Rothwell /* AltiVec Registers (VPRs) */
623b8b572e1SStephen Rothwell 
624c2ce6f9fSAnton Blanchard #define	v0	0
625c2ce6f9fSAnton Blanchard #define	v1	1
626c2ce6f9fSAnton Blanchard #define	v2	2
627c2ce6f9fSAnton Blanchard #define	v3	3
628c2ce6f9fSAnton Blanchard #define	v4	4
629c2ce6f9fSAnton Blanchard #define	v5	5
630c2ce6f9fSAnton Blanchard #define	v6	6
631c2ce6f9fSAnton Blanchard #define	v7	7
632c2ce6f9fSAnton Blanchard #define	v8	8
633c2ce6f9fSAnton Blanchard #define	v9	9
634c2ce6f9fSAnton Blanchard #define	v10	10
635c2ce6f9fSAnton Blanchard #define	v11	11
636c2ce6f9fSAnton Blanchard #define	v12	12
637c2ce6f9fSAnton Blanchard #define	v13	13
638c2ce6f9fSAnton Blanchard #define	v14	14
639c2ce6f9fSAnton Blanchard #define	v15	15
640c2ce6f9fSAnton Blanchard #define	v16	16
641c2ce6f9fSAnton Blanchard #define	v17	17
642c2ce6f9fSAnton Blanchard #define	v18	18
643c2ce6f9fSAnton Blanchard #define	v19	19
644c2ce6f9fSAnton Blanchard #define	v20	20
645c2ce6f9fSAnton Blanchard #define	v21	21
646c2ce6f9fSAnton Blanchard #define	v22	22
647c2ce6f9fSAnton Blanchard #define	v23	23
648c2ce6f9fSAnton Blanchard #define	v24	24
649c2ce6f9fSAnton Blanchard #define	v25	25
650c2ce6f9fSAnton Blanchard #define	v26	26
651c2ce6f9fSAnton Blanchard #define	v27	27
652c2ce6f9fSAnton Blanchard #define	v28	28
653c2ce6f9fSAnton Blanchard #define	v29	29
654c2ce6f9fSAnton Blanchard #define	v30	30
655c2ce6f9fSAnton Blanchard #define	v31	31
656b8b572e1SStephen Rothwell 
657b8b572e1SStephen Rothwell /* VSX Registers (VSRs) */
658b8b572e1SStephen Rothwell 
659df99e6ebSAnton Blanchard #define	vs0	0
660df99e6ebSAnton Blanchard #define	vs1	1
661df99e6ebSAnton Blanchard #define	vs2	2
662df99e6ebSAnton Blanchard #define	vs3	3
663df99e6ebSAnton Blanchard #define	vs4	4
664df99e6ebSAnton Blanchard #define	vs5	5
665df99e6ebSAnton Blanchard #define	vs6	6
666df99e6ebSAnton Blanchard #define	vs7	7
667df99e6ebSAnton Blanchard #define	vs8	8
668df99e6ebSAnton Blanchard #define	vs9	9
669df99e6ebSAnton Blanchard #define	vs10	10
670df99e6ebSAnton Blanchard #define	vs11	11
671df99e6ebSAnton Blanchard #define	vs12	12
672df99e6ebSAnton Blanchard #define	vs13	13
673df99e6ebSAnton Blanchard #define	vs14	14
674df99e6ebSAnton Blanchard #define	vs15	15
675df99e6ebSAnton Blanchard #define	vs16	16
676df99e6ebSAnton Blanchard #define	vs17	17
677df99e6ebSAnton Blanchard #define	vs18	18
678df99e6ebSAnton Blanchard #define	vs19	19
679df99e6ebSAnton Blanchard #define	vs20	20
680df99e6ebSAnton Blanchard #define	vs21	21
681df99e6ebSAnton Blanchard #define	vs22	22
682df99e6ebSAnton Blanchard #define	vs23	23
683df99e6ebSAnton Blanchard #define	vs24	24
684df99e6ebSAnton Blanchard #define	vs25	25
685df99e6ebSAnton Blanchard #define	vs26	26
686df99e6ebSAnton Blanchard #define	vs27	27
687df99e6ebSAnton Blanchard #define	vs28	28
688df99e6ebSAnton Blanchard #define	vs29	29
689df99e6ebSAnton Blanchard #define	vs30	30
690df99e6ebSAnton Blanchard #define	vs31	31
691df99e6ebSAnton Blanchard #define	vs32	32
692df99e6ebSAnton Blanchard #define	vs33	33
693df99e6ebSAnton Blanchard #define	vs34	34
694df99e6ebSAnton Blanchard #define	vs35	35
695df99e6ebSAnton Blanchard #define	vs36	36
696df99e6ebSAnton Blanchard #define	vs37	37
697df99e6ebSAnton Blanchard #define	vs38	38
698df99e6ebSAnton Blanchard #define	vs39	39
699df99e6ebSAnton Blanchard #define	vs40	40
700df99e6ebSAnton Blanchard #define	vs41	41
701df99e6ebSAnton Blanchard #define	vs42	42
702df99e6ebSAnton Blanchard #define	vs43	43
703df99e6ebSAnton Blanchard #define	vs44	44
704df99e6ebSAnton Blanchard #define	vs45	45
705df99e6ebSAnton Blanchard #define	vs46	46
706df99e6ebSAnton Blanchard #define	vs47	47
707df99e6ebSAnton Blanchard #define	vs48	48
708df99e6ebSAnton Blanchard #define	vs49	49
709df99e6ebSAnton Blanchard #define	vs50	50
710df99e6ebSAnton Blanchard #define	vs51	51
711df99e6ebSAnton Blanchard #define	vs52	52
712df99e6ebSAnton Blanchard #define	vs53	53
713df99e6ebSAnton Blanchard #define	vs54	54
714df99e6ebSAnton Blanchard #define	vs55	55
715df99e6ebSAnton Blanchard #define	vs56	56
716df99e6ebSAnton Blanchard #define	vs57	57
717df99e6ebSAnton Blanchard #define	vs58	58
718df99e6ebSAnton Blanchard #define	vs59	59
719df99e6ebSAnton Blanchard #define	vs60	60
720df99e6ebSAnton Blanchard #define	vs61	61
721df99e6ebSAnton Blanchard #define	vs62	62
722df99e6ebSAnton Blanchard #define	vs63	63
723b8b572e1SStephen Rothwell 
724b8b572e1SStephen Rothwell /* SPE Registers (EVPRs) */
725b8b572e1SStephen Rothwell 
726b8b572e1SStephen Rothwell #define	evr0	0
727b8b572e1SStephen Rothwell #define	evr1	1
728b8b572e1SStephen Rothwell #define	evr2	2
729b8b572e1SStephen Rothwell #define	evr3	3
730b8b572e1SStephen Rothwell #define	evr4	4
731b8b572e1SStephen Rothwell #define	evr5	5
732b8b572e1SStephen Rothwell #define	evr6	6
733b8b572e1SStephen Rothwell #define	evr7	7
734b8b572e1SStephen Rothwell #define	evr8	8
735b8b572e1SStephen Rothwell #define	evr9	9
736b8b572e1SStephen Rothwell #define	evr10	10
737b8b572e1SStephen Rothwell #define	evr11	11
738b8b572e1SStephen Rothwell #define	evr12	12
739b8b572e1SStephen Rothwell #define	evr13	13
740b8b572e1SStephen Rothwell #define	evr14	14
741b8b572e1SStephen Rothwell #define	evr15	15
742b8b572e1SStephen Rothwell #define	evr16	16
743b8b572e1SStephen Rothwell #define	evr17	17
744b8b572e1SStephen Rothwell #define	evr18	18
745b8b572e1SStephen Rothwell #define	evr19	19
746b8b572e1SStephen Rothwell #define	evr20	20
747b8b572e1SStephen Rothwell #define	evr21	21
748b8b572e1SStephen Rothwell #define	evr22	22
749b8b572e1SStephen Rothwell #define	evr23	23
750b8b572e1SStephen Rothwell #define	evr24	24
751b8b572e1SStephen Rothwell #define	evr25	25
752b8b572e1SStephen Rothwell #define	evr26	26
753b8b572e1SStephen Rothwell #define	evr27	27
754b8b572e1SStephen Rothwell #define	evr28	28
755b8b572e1SStephen Rothwell #define	evr29	29
756b8b572e1SStephen Rothwell #define	evr30	30
757b8b572e1SStephen Rothwell #define	evr31	31
758b8b572e1SStephen Rothwell 
7597fa95f9aSNicholas Piggin #define RFSCV	.long 0x4c0000a4
7607fa95f9aSNicholas Piggin 
7615c0484e2SBenjamin Herrenschmidt /*
7625c0484e2SBenjamin Herrenschmidt  * Create an endian fixup trampoline
7635c0484e2SBenjamin Herrenschmidt  *
7645c0484e2SBenjamin Herrenschmidt  * This starts with a "tdi 0,0,0x48" instruction which is
7655c0484e2SBenjamin Herrenschmidt  * essentially a "trap never", and thus akin to a nop.
7665c0484e2SBenjamin Herrenschmidt  *
7675c0484e2SBenjamin Herrenschmidt  * The opcode for this instruction read with the wrong endian
7685c0484e2SBenjamin Herrenschmidt  * however results in a b . + 8
7695c0484e2SBenjamin Herrenschmidt  *
7705c0484e2SBenjamin Herrenschmidt  * So essentially we use that trick to execute the following
7715c0484e2SBenjamin Herrenschmidt  * trampoline in "reverse endian" if we are running with the
7725c0484e2SBenjamin Herrenschmidt  * MSR_LE bit set the "wrong" way for whatever endianness the
7735c0484e2SBenjamin Herrenschmidt  * kernel is built for.
7745c0484e2SBenjamin Herrenschmidt  */
775b8b572e1SStephen Rothwell 
776e0d68273SChristophe Leroy #ifdef CONFIG_PPC_BOOK3E_64
7775c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN
7785c0484e2SBenjamin Herrenschmidt #else
7798ca9c08dSNicholas Piggin /*
780db10f550SRandy Dunlap  * This version may be used in HV or non-HV context.
7818ca9c08dSNicholas Piggin  * MSR[EE] must be disabled.
7828ca9c08dSNicholas Piggin  */
7835c0484e2SBenjamin Herrenschmidt #define FIXUP_ENDIAN						   \
7845c0484e2SBenjamin Herrenschmidt 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
785f848ea7fSNicholas Piggin 	b     191f;	  /* Skip trampoline if endian is good	*/ \
7865c0484e2SBenjamin Herrenschmidt 	.long 0xa600607d; /* mfmsr r11				*/ \
7875c0484e2SBenjamin Herrenschmidt 	.long 0x01006b69; /* xori r11,r11,1			*/ \
788f1fe5252SNicholas Piggin 	.long 0x00004039; /* li r10,0				*/ \
789f1fe5252SNicholas Piggin 	.long 0x6401417d; /* mtmsrd r10,1			*/ \
790f1fe5252SNicholas Piggin 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
791f1fe5252SNicholas Piggin 	.long 0xa602487d; /* mflr r10				*/ \
792f1fe5252SNicholas Piggin 	.long 0x14004a39; /* addi r10,r10,20			*/ \
7935c0484e2SBenjamin Herrenschmidt 	.long 0xa6035a7d; /* mtsrr0 r10				*/ \
7945c0484e2SBenjamin Herrenschmidt 	.long 0xa6037b7d; /* mtsrr1 r11				*/ \
795f848ea7fSNicholas Piggin 	.long 0x2400004c; /* rfid				*/ \
796f848ea7fSNicholas Piggin 191:
797f1fe5252SNicholas Piggin 
7988ca9c08dSNicholas Piggin /*
7998ca9c08dSNicholas Piggin  * This version that may only be used with MSR[HV]=1
8008ca9c08dSNicholas Piggin  * - Does not clear MSR[RI], so more robust.
8018ca9c08dSNicholas Piggin  * - Slightly smaller and faster.
8028ca9c08dSNicholas Piggin  */
8038ca9c08dSNicholas Piggin #define FIXUP_ENDIAN_HV						   \
8048ca9c08dSNicholas Piggin 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
8058ca9c08dSNicholas Piggin 	b     191f;	  /* Skip trampoline if endian is good	*/ \
8068ca9c08dSNicholas Piggin 	.long 0xa600607d; /* mfmsr r11				*/ \
8078ca9c08dSNicholas Piggin 	.long 0x01006b69; /* xori r11,r11,1			*/ \
8088ca9c08dSNicholas Piggin 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
8098ca9c08dSNicholas Piggin 	.long 0xa602487d; /* mflr r10				*/ \
8108ca9c08dSNicholas Piggin 	.long 0x14004a39; /* addi r10,r10,20			*/ \
8118ca9c08dSNicholas Piggin 	.long 0xa64b5a7d; /* mthsrr0 r10			*/ \
8128ca9c08dSNicholas Piggin 	.long 0xa64b7b7d; /* mthsrr1 r11			*/ \
8138ca9c08dSNicholas Piggin 	.long 0x2402004c; /* hrfid				*/ \
8148ca9c08dSNicholas Piggin 191:
8158ca9c08dSNicholas Piggin 
816e0d68273SChristophe Leroy #endif /* !CONFIG_PPC_BOOK3E_64 */
817e3f2c6c3SMichael Ellerman 
8185c0484e2SBenjamin Herrenschmidt #endif /*  __ASSEMBLY__ */
819e3f2c6c3SMichael Ellerman 
820325678fdSNicholas Piggin #define SOFT_MASK_TABLE(_start, _end)		\
821325678fdSNicholas Piggin 	stringify_in_c(.section __soft_mask_table,"a";)\
822325678fdSNicholas Piggin 	stringify_in_c(.balign 8;)		\
823325678fdSNicholas Piggin 	stringify_in_c(.llong (_start);)	\
824325678fdSNicholas Piggin 	stringify_in_c(.llong (_end);)		\
825325678fdSNicholas Piggin 	stringify_in_c(.previous)
826325678fdSNicholas Piggin 
827f23699c9SNicholas Piggin #define RESTART_TABLE(_start, _end, _target)	\
828f23699c9SNicholas Piggin 	stringify_in_c(.section __restart_table,"a";)\
829f23699c9SNicholas Piggin 	stringify_in_c(.balign 8;)		\
830f23699c9SNicholas Piggin 	stringify_in_c(.llong (_start);)	\
831f23699c9SNicholas Piggin 	stringify_in_c(.llong (_end);)		\
832f23699c9SNicholas Piggin 	stringify_in_c(.llong (_target);)	\
833f23699c9SNicholas Piggin 	stringify_in_c(.previous)
834f23699c9SNicholas Piggin 
8353e731858SChristophe Leroy #ifdef CONFIG_PPC_E500
8361cbf8990SDiana Craciun #define BTB_FLUSH(reg)			\
8371cbf8990SDiana Craciun 	lis reg,BUCSR_INIT@h;		\
8381cbf8990SDiana Craciun 	ori reg,reg,BUCSR_INIT@l;	\
8391cbf8990SDiana Craciun 	mtspr SPRN_BUCSR,reg;		\
8401cbf8990SDiana Craciun 	isync;
8411cbf8990SDiana Craciun #else
8421cbf8990SDiana Craciun #define BTB_FLUSH(reg)
8433e731858SChristophe Leroy #endif /* CONFIG_PPC_E500 */
8441cbf8990SDiana Craciun 
845ac9c8901SNicholas Miehlbradt #if defined(CONFIG_PPC64_ELF_ABI_V1)
846ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 48
847ac9c8901SNicholas Miehlbradt #elif defined(CONFIG_PPC64_ELF_ABI_V2)
848ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 32
849ac9c8901SNicholas Miehlbradt #elif defined(CONFIG_PPC32)
850ac9c8901SNicholas Miehlbradt #define STACK_FRAME_PARAMS 8
851ac9c8901SNicholas Miehlbradt #endif
852ac9c8901SNicholas Miehlbradt 
853b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PPC_ASM_H */
854