xref: /openbmc/linux/arch/powerpc/include/asm/ppc_asm.h (revision fadbafc1)
1 /*
2  * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
3  */
4 #ifndef _ASM_POWERPC_PPC_ASM_H
5 #define _ASM_POWERPC_PPC_ASM_H
6 
7 #include <linux/stringify.h>
8 #include <asm/asm-compat.h>
9 #include <asm/processor.h>
10 #include <asm/ppc-opcode.h>
11 #include <asm/firmware.h>
12 #include <asm/feature-fixups.h>
13 #include <asm/extable.h>
14 
15 #ifdef __ASSEMBLY__
16 
17 #define SZL			(BITS_PER_LONG/8)
18 
19 /*
20  * This expands to a sequence of operations with reg incrementing from
21  * start to end inclusive, of this form:
22  *
23  *   op  reg, (offset + (width * reg))(base)
24  *
25  * Note that offset is not the offset of the first operation unless start
26  * is zero (or width is zero).
27  */
28 .macro OP_REGS op, width, start, end, base, offset
29 	.Lreg=\start
30 	.rept (\end - \start + 1)
31 	\op	.Lreg, \offset + \width * .Lreg(\base)
32 	.Lreg=.Lreg+1
33 	.endr
34 .endm
35 
36 /*
37  * This expands to a sequence of register clears for regs start to end
38  * inclusive, of the form:
39  *
40  *   li rN, 0
41  */
42 .macro ZEROIZE_REGS start, end
43 	.Lreg=\start
44 	.rept (\end - \start + 1)
45 	li	.Lreg, 0
46 	.Lreg=.Lreg+1
47 	.endr
48 .endm
49 
50 /*
51  * Macros for storing registers into and loading registers from
52  * exception frames.
53  */
54 #ifdef __powerpc64__
55 #define SAVE_GPRS(start, end, base)	OP_REGS std, 8, start, end, base, GPR0
56 #define REST_GPRS(start, end, base)	OP_REGS ld, 8, start, end, base, GPR0
57 #define SAVE_NVGPRS(base)		SAVE_GPRS(14, 31, base)
58 #define REST_NVGPRS(base)		REST_GPRS(14, 31, base)
59 #else
60 #define SAVE_GPRS(start, end, base)	OP_REGS stw, 4, start, end, base, GPR0
61 #define REST_GPRS(start, end, base)	OP_REGS lwz, 4, start, end, base, GPR0
62 #define SAVE_NVGPRS(base)		SAVE_GPRS(13, 31, base)
63 #define REST_NVGPRS(base)		REST_GPRS(13, 31, base)
64 #endif
65 
66 #define	ZEROIZE_GPRS(start, end)	ZEROIZE_REGS start, end
67 #ifdef __powerpc64__
68 #define	ZEROIZE_NVGPRS()		ZEROIZE_GPRS(14, 31)
69 #else
70 #define	ZEROIZE_NVGPRS()		ZEROIZE_GPRS(13, 31)
71 #endif
72 #define	ZEROIZE_GPR(n)			ZEROIZE_GPRS(n, n)
73 
74 #define SAVE_GPR(n, base)		SAVE_GPRS(n, n, base)
75 #define REST_GPR(n, base)		REST_GPRS(n, n, base)
76 
77 #define SAVE_FPR(n, base)	stfd	n,8*TS_FPRWIDTH*(n)(base)
78 #define SAVE_2FPRS(n, base)	SAVE_FPR(n, base); SAVE_FPR(n+1, base)
79 #define SAVE_4FPRS(n, base)	SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
80 #define SAVE_8FPRS(n, base)	SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
81 #define SAVE_16FPRS(n, base)	SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
82 #define SAVE_32FPRS(n, base)	SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
83 #define REST_FPR(n, base)	lfd	n,8*TS_FPRWIDTH*(n)(base)
84 #define REST_2FPRS(n, base)	REST_FPR(n, base); REST_FPR(n+1, base)
85 #define REST_4FPRS(n, base)	REST_2FPRS(n, base); REST_2FPRS(n+2, base)
86 #define REST_8FPRS(n, base)	REST_4FPRS(n, base); REST_4FPRS(n+4, base)
87 #define REST_16FPRS(n, base)	REST_8FPRS(n, base); REST_8FPRS(n+8, base)
88 #define REST_32FPRS(n, base)	REST_16FPRS(n, base); REST_16FPRS(n+16, base)
89 
90 #define SAVE_VR(n,b,base)	li b,16*(n);  stvx n,base,b
91 #define SAVE_2VRS(n,b,base)	SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
92 #define SAVE_4VRS(n,b,base)	SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
93 #define SAVE_8VRS(n,b,base)	SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
94 #define SAVE_16VRS(n,b,base)	SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
95 #define SAVE_32VRS(n,b,base)	SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
96 #define REST_VR(n,b,base)	li b,16*(n); lvx n,base,b
97 #define REST_2VRS(n,b,base)	REST_VR(n,b,base); REST_VR(n+1,b,base)
98 #define REST_4VRS(n,b,base)	REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
99 #define REST_8VRS(n,b,base)	REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
100 #define REST_16VRS(n,b,base)	REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
101 #define REST_32VRS(n,b,base)	REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
102 
103 #ifdef __BIG_ENDIAN__
104 #define STXVD2X_ROT(n,b,base)		STXVD2X(n,b,base)
105 #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base)
106 #else
107 #define STXVD2X_ROT(n,b,base)		XXSWAPD(n,n);		\
108 					STXVD2X(n,b,base);	\
109 					XXSWAPD(n,n)
110 
111 #define LXVD2X_ROT(n,b,base)		LXVD2X(n,b,base);	\
112 					XXSWAPD(n,n)
113 #endif
114 /* Save the lower 32 VSRs in the thread VSR region */
115 #define SAVE_VSR(n,b,base)	li b,16*(n);  STXVD2X_ROT(n,R##base,R##b)
116 #define SAVE_2VSRS(n,b,base)	SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
117 #define SAVE_4VSRS(n,b,base)	SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
118 #define SAVE_8VSRS(n,b,base)	SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
119 #define SAVE_16VSRS(n,b,base)	SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
120 #define SAVE_32VSRS(n,b,base)	SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
121 #define REST_VSR(n,b,base)	li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
122 #define REST_2VSRS(n,b,base)	REST_VSR(n,b,base); REST_VSR(n+1,b,base)
123 #define REST_4VSRS(n,b,base)	REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
124 #define REST_8VSRS(n,b,base)	REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
125 #define REST_16VSRS(n,b,base)	REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
126 #define REST_32VSRS(n,b,base)	REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
127 
128 /*
129  * b = base register for addressing, o = base offset from register of 1st EVR
130  * n = first EVR, s = scratch
131  */
132 #define SAVE_EVR(n,s,b,o)	evmergehi s,s,n; stw s,o+4*(n)(b)
133 #define SAVE_2EVRS(n,s,b,o)	SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
134 #define SAVE_4EVRS(n,s,b,o)	SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
135 #define SAVE_8EVRS(n,s,b,o)	SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
136 #define SAVE_16EVRS(n,s,b,o)	SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
137 #define SAVE_32EVRS(n,s,b,o)	SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
138 #define REST_EVR(n,s,b,o)	lwz s,o+4*(n)(b); evmergelo n,s,n
139 #define REST_2EVRS(n,s,b,o)	REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
140 #define REST_4EVRS(n,s,b,o)	REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
141 #define REST_8EVRS(n,s,b,o)	REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
142 #define REST_16EVRS(n,s,b,o)	REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
143 #define REST_32EVRS(n,s,b,o)	REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
144 
145 /* Macros to adjust thread priority for hardware multithreading */
146 #define HMT_VERY_LOW	or	31,31,31	# very low priority
147 #define HMT_LOW		or	1,1,1
148 #define HMT_MEDIUM_LOW  or	6,6,6		# medium low priority
149 #define HMT_MEDIUM	or	2,2,2
150 #define HMT_MEDIUM_HIGH or	5,5,5		# medium high priority
151 #define HMT_HIGH	or	3,3,3
152 #define HMT_EXTRA_HIGH	or	7,7,7		# power7 only
153 
154 #ifdef CONFIG_PPC64
155 #define ULONG_SIZE 	8
156 #else
157 #define ULONG_SIZE	4
158 #endif
159 #define __VCPU_GPR(n)	(VCPU_GPRS + (n * ULONG_SIZE))
160 #define VCPU_GPR(n)	__VCPU_GPR(__REG_##n)
161 
162 #ifdef __KERNEL__
163 
164 /*
165  * We use __powerpc64__ here because we want the compat VDSO to use the 32-bit
166  * version below in the else case of the ifdef.
167  */
168 #ifdef __powerpc64__
169 
170 #define STACKFRAMESIZE 256
171 #define __STK_REG(i)   (112 + ((i)-14)*8)
172 #define STK_REG(i)     __STK_REG(__REG_##i)
173 
174 #ifdef CONFIG_PPC64_ELF_ABI_V2
175 #define STK_GOT		24
176 #define __STK_PARAM(i)	(32 + ((i)-3)*8)
177 #else
178 #define STK_GOT		40
179 #define __STK_PARAM(i)	(48 + ((i)-3)*8)
180 #endif
181 #define STK_PARAM(i)	__STK_PARAM(__REG_##i)
182 
183 #ifdef CONFIG_PPC64_ELF_ABI_V2
184 
185 #define _GLOBAL(name) \
186 	.align 2 ; \
187 	.type name,@function; \
188 	.globl name; \
189 name:
190 
191 #define _GLOBAL_TOC(name) \
192 	.align 2 ; \
193 	.type name,@function; \
194 	.globl name; \
195 name: \
196 0:	addis r2,r12,(.TOC.-0b)@ha; \
197 	addi r2,r2,(.TOC.-0b)@l; \
198 	.localentry name,.-name
199 
200 #define DOTSYM(a)	a
201 
202 #else
203 
204 #define XGLUE(a,b) a##b
205 #define GLUE(a,b) XGLUE(a,b)
206 
207 #define _GLOBAL(name) \
208 	.align 2 ; \
209 	.globl name; \
210 	.globl GLUE(.,name); \
211 	.pushsection ".opd","aw"; \
212 name: \
213 	.quad GLUE(.,name); \
214 	.quad .TOC.@tocbase; \
215 	.quad 0; \
216 	.popsection; \
217 	.type GLUE(.,name),@function; \
218 GLUE(.,name):
219 
220 #define _GLOBAL_TOC(name) _GLOBAL(name)
221 
222 #define DOTSYM(a)	GLUE(.,a)
223 
224 #endif
225 
226 #else /* 32-bit */
227 
228 #define _GLOBAL(n)	\
229 	.globl n;	\
230 n:
231 
232 #define _GLOBAL_TOC(name) _GLOBAL(name)
233 
234 #define DOTSYM(a)	a
235 
236 #endif
237 
238 /*
239  * __kprobes (the C annotation) puts the symbol into the .kprobes.text
240  * section, which gets emitted at the end of regular text.
241  *
242  * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
243  * a blacklist. The former is for core kprobe functions/data, the
244  * latter is for those that incdentially must be excluded from probing
245  * and allows them to be linked at more optimal location within text.
246  */
247 #ifdef CONFIG_KPROBES
248 #define _ASM_NOKPROBE_SYMBOL(entry)			\
249 	.pushsection "_kprobe_blacklist","aw";		\
250 	PPC_LONG (entry) ;				\
251 	.popsection
252 #else
253 #define _ASM_NOKPROBE_SYMBOL(entry)
254 #endif
255 
256 #define FUNC_START(name)	_GLOBAL(name)
257 #define FUNC_END(name)
258 
259 /*
260  * LOAD_REG_IMMEDIATE(rn, expr)
261  *   Loads the value of the constant expression 'expr' into register 'rn'
262  *   using immediate instructions only.  Use this when it's important not
263  *   to reference other data (i.e. on ppc64 when the TOC pointer is not
264  *   valid) and when 'expr' is a constant or absolute address.
265  *
266  * LOAD_REG_ADDR(rn, name)
267  *   Loads the address of label 'name' into register 'rn'.  Use this when
268  *   you don't particularly need immediate instructions only, but you need
269  *   the whole address in one register (e.g. it's a structure address and
270  *   you want to access various offsets within it).  On ppc32 this is
271  *   identical to LOAD_REG_IMMEDIATE.
272  *
273  * LOAD_REG_ADDR_PIC(rn, name)
274  *   Loads the address of label 'name' into register 'run'. Use this when
275  *   the kernel doesn't run at the linked or relocated address. Please
276  *   note that this macro will clobber the lr register.
277  *
278  * LOAD_REG_ADDRBASE(rn, name)
279  * ADDROFF(name)
280  *   LOAD_REG_ADDRBASE loads part of the address of label 'name' into
281  *   register 'rn'.  ADDROFF(name) returns the remainder of the address as
282  *   a constant expression.  ADDROFF(name) is a signed expression < 16 bits
283  *   in size, so is suitable for use directly as an offset in load and store
284  *   instructions.  Use this when loading/storing a single word or less as:
285  *      LOAD_REG_ADDRBASE(rX, name)
286  *      ld	rY,ADDROFF(name)(rX)
287  */
288 
289 /* Be careful, this will clobber the lr register. */
290 #define LOAD_REG_ADDR_PIC(reg, name)		\
291 	bcl	20,31,$+4;			\
292 0:	mflr	reg;				\
293 	addis	reg,reg,(name - 0b)@ha;		\
294 	addi	reg,reg,(name - 0b)@l;
295 
296 #if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH)
297 #define __AS_ATHIGH high
298 #else
299 #define __AS_ATHIGH h
300 #endif
301 
302 .macro __LOAD_REG_IMMEDIATE_32 r, x
303 	.if (\x) >= 0x8000 || (\x) < -0x8000
304 		lis \r, (\x)@__AS_ATHIGH
305 		.if (\x) & 0xffff != 0
306 			ori \r, \r, (\x)@l
307 		.endif
308 	.else
309 		li \r, (\x)@l
310 	.endif
311 .endm
312 
313 .macro __LOAD_REG_IMMEDIATE r, x
314 	.if (\x) >= 0x80000000 || (\x) < -0x80000000
315 		__LOAD_REG_IMMEDIATE_32 \r, (\x) >> 32
316 		sldi	\r, \r, 32
317 		.if (\x) & 0xffff0000 != 0
318 			oris \r, \r, (\x)@__AS_ATHIGH
319 		.endif
320 		.if (\x) & 0xffff != 0
321 			ori \r, \r, (\x)@l
322 		.endif
323 	.else
324 		__LOAD_REG_IMMEDIATE_32 \r, \x
325 	.endif
326 .endm
327 
328 #ifdef __powerpc64__
329 
330 #define __LOAD_PACA_TOC(reg)			\
331 	ld	reg,PACATOC(r13)
332 
333 #define LOAD_PACA_TOC()				\
334 	__LOAD_PACA_TOC(r2)
335 
336 #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE reg, expr
337 
338 #define LOAD_REG_IMMEDIATE_SYM(reg, tmp, expr)	\
339 	lis	tmp, (expr)@highest;		\
340 	lis	reg, (expr)@__AS_ATHIGH;	\
341 	ori	tmp, tmp, (expr)@higher;	\
342 	ori	reg, reg, (expr)@l;		\
343 	rldimi	reg, tmp, 32, 0
344 
345 #define LOAD_REG_ADDR(reg,name)			\
346 	addis	reg,r2,name@toc@ha;		\
347 	addi	reg,reg,name@toc@l
348 
349 #ifdef CONFIG_PPC_BOOK3E_64
350 /*
351  * This is used in register-constrained interrupt handlers. Not to be used
352  * by BOOK3S. ld complains with "got/toc optimization is not supported" if r2
353  * is not used for the TOC offset, so use @got(tocreg). If the interrupt
354  * handlers saved r2 instead, LOAD_REG_ADDR could be used.
355  */
356 #define LOAD_REG_ADDR_ALTTOC(reg,tocreg,name)	\
357 	ld	reg,name@got(tocreg)
358 #endif
359 
360 #define LOAD_REG_ADDRBASE(reg,name)	LOAD_REG_ADDR(reg,name)
361 #define ADDROFF(name)			0
362 
363 /* offsets for stack frame layout */
364 #define LRSAVE	16
365 
366 #else /* 32-bit */
367 
368 #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr
369 
370 #define LOAD_REG_IMMEDIATE_SYM(reg,expr)		\
371 	lis	reg,(expr)@ha;		\
372 	addi	reg,reg,(expr)@l;
373 
374 #define LOAD_REG_ADDR(reg,name)		LOAD_REG_IMMEDIATE_SYM(reg, name)
375 
376 #define LOAD_REG_ADDRBASE(reg, name)	lis	reg,name@ha
377 #define ADDROFF(name)			name@l
378 
379 /* offsets for stack frame layout */
380 #define LRSAVE	4
381 
382 #endif
383 
384 /* various errata or part fixups */
385 #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_E500)
386 #define MFTB(dest)			\
387 90:	mfspr dest, SPRN_TBRL;		\
388 BEGIN_FTR_SECTION_NESTED(96);		\
389 	cmpwi dest,0;			\
390 	beq-  90b;			\
391 END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
392 #else
393 #define MFTB(dest)			MFTBL(dest)
394 #endif
395 
396 #ifdef CONFIG_PPC_8xx
397 #define MFTBL(dest)			mftb dest
398 #define MFTBU(dest)			mftbu dest
399 #else
400 #define MFTBL(dest)			mfspr dest, SPRN_TBRL
401 #define MFTBU(dest)			mfspr dest, SPRN_TBRU
402 #endif
403 
404 #ifndef CONFIG_SMP
405 #define TLBSYNC
406 #else
407 #define TLBSYNC		tlbsync; sync
408 #endif
409 
410 #ifdef CONFIG_PPC64
411 #define MTOCRF(FXM, RS)			\
412 	BEGIN_FTR_SECTION_NESTED(848);	\
413 	mtcrf	(FXM), RS;		\
414 	FTR_SECTION_ELSE_NESTED(848);	\
415 	mtocrf (FXM), RS;		\
416 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
417 #endif
418 
419 /*
420  * This instruction is not implemented on the PPC 603 or 601; however, on
421  * the 403GCX and 405GP tlbia IS defined and tlbie is not.
422  * All of these instructions exist in the 8xx, they have magical powers,
423  * and they must be used.
424  */
425 
426 #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx)
427 #define tlbia					\
428 	li	r4,1024;			\
429 	mtctr	r4;				\
430 	lis	r4,KERNELBASE@h;		\
431 	.machine push;				\
432 	.machine "power4";			\
433 0:	tlbie	r4;				\
434 	.machine pop;				\
435 	addi	r4,r4,0x1000;			\
436 	bdnz	0b
437 #endif
438 
439 
440 #ifdef CONFIG_IBM440EP_ERR42
441 #define PPC440EP_ERR42 isync
442 #else
443 #define PPC440EP_ERR42
444 #endif
445 
446 /* The following stops all load and store data streams associated with stream
447  * ID (ie. streams created explicitly).  The embedded and server mnemonics for
448  * dcbt are different so this must only be used for server.
449  */
450 #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch)	\
451        lis     scratch,0x60000000@h;			\
452        dcbt    0,scratch,0b01010
453 
454 /*
455  * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
456  * keep the address intact to be compatible with code shared with
457  * 32-bit classic.
458  *
459  * On the other hand, I find it useful to have them behave as expected
460  * by their name (ie always do the addition) on 64-bit BookE
461  */
462 #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
463 #define toreal(rd)
464 #define fromreal(rd)
465 
466 /*
467  * We use addis to ensure compatibility with the "classic" ppc versions of
468  * these macros, which use rs = 0 to get the tophys offset in rd, rather than
469  * converting the address in r0, and so this version has to do that too
470  * (i.e. set register rd to 0 when rs == 0).
471  */
472 #define tophys(rd,rs)				\
473 	addis	rd,rs,0
474 
475 #define tovirt(rd,rs)				\
476 	addis	rd,rs,0
477 
478 #elif defined(CONFIG_PPC64)
479 #define toreal(rd)		/* we can access c000... in real mode */
480 #define fromreal(rd)
481 
482 #define tophys(rd,rs)                           \
483 	clrldi	rd,rs,2
484 
485 #define tovirt(rd,rs)                           \
486 	rotldi	rd,rs,16;			\
487 	ori	rd,rd,((KERNELBASE>>48)&0xFFFF);\
488 	rotldi	rd,rd,48
489 #else
490 #define toreal(rd)	tophys(rd,rd)
491 #define fromreal(rd)	tovirt(rd,rd)
492 
493 #define tophys(rd, rs)	addis	rd, rs, -PAGE_OFFSET@h
494 #define tovirt(rd, rs)	addis	rd, rs, PAGE_OFFSET@h
495 #endif
496 
497 #ifdef CONFIG_PPC_BOOK3S_64
498 #define MTMSRD(r)	mtmsrd	r
499 #define MTMSR_EERI(reg)	mtmsrd	reg,1
500 #else
501 #define MTMSRD(r)	mtmsr	r
502 #define MTMSR_EERI(reg)	mtmsr	reg
503 #endif
504 
505 #endif /* __KERNEL__ */
506 
507 /* The boring bits... */
508 
509 /* Condition Register Bit Fields */
510 
511 #define	cr0	0
512 #define	cr1	1
513 #define	cr2	2
514 #define	cr3	3
515 #define	cr4	4
516 #define	cr5	5
517 #define	cr6	6
518 #define	cr7	7
519 
520 
521 /*
522  * General Purpose Registers (GPRs)
523  *
524  * The lower case r0-r31 should be used in preference to the upper
525  * case R0-R31 as they provide more error checking in the assembler.
526  * Use R0-31 only when really nessesary.
527  */
528 
529 #define	r0	%r0
530 #define	r1	%r1
531 #define	r2	%r2
532 #define	r3	%r3
533 #define	r4	%r4
534 #define	r5	%r5
535 #define	r6	%r6
536 #define	r7	%r7
537 #define	r8	%r8
538 #define	r9	%r9
539 #define	r10	%r10
540 #define	r11	%r11
541 #define	r12	%r12
542 #define	r13	%r13
543 #define	r14	%r14
544 #define	r15	%r15
545 #define	r16	%r16
546 #define	r17	%r17
547 #define	r18	%r18
548 #define	r19	%r19
549 #define	r20	%r20
550 #define	r21	%r21
551 #define	r22	%r22
552 #define	r23	%r23
553 #define	r24	%r24
554 #define	r25	%r25
555 #define	r26	%r26
556 #define	r27	%r27
557 #define	r28	%r28
558 #define	r29	%r29
559 #define	r30	%r30
560 #define	r31	%r31
561 
562 
563 /* Floating Point Registers (FPRs) */
564 
565 #define	fr0	0
566 #define	fr1	1
567 #define	fr2	2
568 #define	fr3	3
569 #define	fr4	4
570 #define	fr5	5
571 #define	fr6	6
572 #define	fr7	7
573 #define	fr8	8
574 #define	fr9	9
575 #define	fr10	10
576 #define	fr11	11
577 #define	fr12	12
578 #define	fr13	13
579 #define	fr14	14
580 #define	fr15	15
581 #define	fr16	16
582 #define	fr17	17
583 #define	fr18	18
584 #define	fr19	19
585 #define	fr20	20
586 #define	fr21	21
587 #define	fr22	22
588 #define	fr23	23
589 #define	fr24	24
590 #define	fr25	25
591 #define	fr26	26
592 #define	fr27	27
593 #define	fr28	28
594 #define	fr29	29
595 #define	fr30	30
596 #define	fr31	31
597 
598 /* AltiVec Registers (VPRs) */
599 
600 #define	v0	0
601 #define	v1	1
602 #define	v2	2
603 #define	v3	3
604 #define	v4	4
605 #define	v5	5
606 #define	v6	6
607 #define	v7	7
608 #define	v8	8
609 #define	v9	9
610 #define	v10	10
611 #define	v11	11
612 #define	v12	12
613 #define	v13	13
614 #define	v14	14
615 #define	v15	15
616 #define	v16	16
617 #define	v17	17
618 #define	v18	18
619 #define	v19	19
620 #define	v20	20
621 #define	v21	21
622 #define	v22	22
623 #define	v23	23
624 #define	v24	24
625 #define	v25	25
626 #define	v26	26
627 #define	v27	27
628 #define	v28	28
629 #define	v29	29
630 #define	v30	30
631 #define	v31	31
632 
633 /* VSX Registers (VSRs) */
634 
635 #define	vs0	0
636 #define	vs1	1
637 #define	vs2	2
638 #define	vs3	3
639 #define	vs4	4
640 #define	vs5	5
641 #define	vs6	6
642 #define	vs7	7
643 #define	vs8	8
644 #define	vs9	9
645 #define	vs10	10
646 #define	vs11	11
647 #define	vs12	12
648 #define	vs13	13
649 #define	vs14	14
650 #define	vs15	15
651 #define	vs16	16
652 #define	vs17	17
653 #define	vs18	18
654 #define	vs19	19
655 #define	vs20	20
656 #define	vs21	21
657 #define	vs22	22
658 #define	vs23	23
659 #define	vs24	24
660 #define	vs25	25
661 #define	vs26	26
662 #define	vs27	27
663 #define	vs28	28
664 #define	vs29	29
665 #define	vs30	30
666 #define	vs31	31
667 #define	vs32	32
668 #define	vs33	33
669 #define	vs34	34
670 #define	vs35	35
671 #define	vs36	36
672 #define	vs37	37
673 #define	vs38	38
674 #define	vs39	39
675 #define	vs40	40
676 #define	vs41	41
677 #define	vs42	42
678 #define	vs43	43
679 #define	vs44	44
680 #define	vs45	45
681 #define	vs46	46
682 #define	vs47	47
683 #define	vs48	48
684 #define	vs49	49
685 #define	vs50	50
686 #define	vs51	51
687 #define	vs52	52
688 #define	vs53	53
689 #define	vs54	54
690 #define	vs55	55
691 #define	vs56	56
692 #define	vs57	57
693 #define	vs58	58
694 #define	vs59	59
695 #define	vs60	60
696 #define	vs61	61
697 #define	vs62	62
698 #define	vs63	63
699 
700 /* SPE Registers (EVPRs) */
701 
702 #define	evr0	0
703 #define	evr1	1
704 #define	evr2	2
705 #define	evr3	3
706 #define	evr4	4
707 #define	evr5	5
708 #define	evr6	6
709 #define	evr7	7
710 #define	evr8	8
711 #define	evr9	9
712 #define	evr10	10
713 #define	evr11	11
714 #define	evr12	12
715 #define	evr13	13
716 #define	evr14	14
717 #define	evr15	15
718 #define	evr16	16
719 #define	evr17	17
720 #define	evr18	18
721 #define	evr19	19
722 #define	evr20	20
723 #define	evr21	21
724 #define	evr22	22
725 #define	evr23	23
726 #define	evr24	24
727 #define	evr25	25
728 #define	evr26	26
729 #define	evr27	27
730 #define	evr28	28
731 #define	evr29	29
732 #define	evr30	30
733 #define	evr31	31
734 
735 #define RFSCV	.long 0x4c0000a4
736 
737 /*
738  * Create an endian fixup trampoline
739  *
740  * This starts with a "tdi 0,0,0x48" instruction which is
741  * essentially a "trap never", and thus akin to a nop.
742  *
743  * The opcode for this instruction read with the wrong endian
744  * however results in a b . + 8
745  *
746  * So essentially we use that trick to execute the following
747  * trampoline in "reverse endian" if we are running with the
748  * MSR_LE bit set the "wrong" way for whatever endianness the
749  * kernel is built for.
750  */
751 
752 #ifdef CONFIG_PPC_BOOK3E_64
753 #define FIXUP_ENDIAN
754 #else
755 /*
756  * This version may be used in HV or non-HV context.
757  * MSR[EE] must be disabled.
758  */
759 #define FIXUP_ENDIAN						   \
760 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
761 	b     191f;	  /* Skip trampoline if endian is good	*/ \
762 	.long 0xa600607d; /* mfmsr r11				*/ \
763 	.long 0x01006b69; /* xori r11,r11,1			*/ \
764 	.long 0x00004039; /* li r10,0				*/ \
765 	.long 0x6401417d; /* mtmsrd r10,1			*/ \
766 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
767 	.long 0xa602487d; /* mflr r10				*/ \
768 	.long 0x14004a39; /* addi r10,r10,20			*/ \
769 	.long 0xa6035a7d; /* mtsrr0 r10				*/ \
770 	.long 0xa6037b7d; /* mtsrr1 r11				*/ \
771 	.long 0x2400004c; /* rfid				*/ \
772 191:
773 
774 /*
775  * This version that may only be used with MSR[HV]=1
776  * - Does not clear MSR[RI], so more robust.
777  * - Slightly smaller and faster.
778  */
779 #define FIXUP_ENDIAN_HV						   \
780 	tdi   0,0,0x48;	  /* Reverse endian of b . + 8		*/ \
781 	b     191f;	  /* Skip trampoline if endian is good	*/ \
782 	.long 0xa600607d; /* mfmsr r11				*/ \
783 	.long 0x01006b69; /* xori r11,r11,1			*/ \
784 	.long 0x05009f42; /* bcl 20,31,$+4			*/ \
785 	.long 0xa602487d; /* mflr r10				*/ \
786 	.long 0x14004a39; /* addi r10,r10,20			*/ \
787 	.long 0xa64b5a7d; /* mthsrr0 r10			*/ \
788 	.long 0xa64b7b7d; /* mthsrr1 r11			*/ \
789 	.long 0x2402004c; /* hrfid				*/ \
790 191:
791 
792 #endif /* !CONFIG_PPC_BOOK3E_64 */
793 
794 #endif /*  __ASSEMBLY__ */
795 
796 #define SOFT_MASK_TABLE(_start, _end)		\
797 	stringify_in_c(.section __soft_mask_table,"a";)\
798 	stringify_in_c(.balign 8;)		\
799 	stringify_in_c(.llong (_start);)	\
800 	stringify_in_c(.llong (_end);)		\
801 	stringify_in_c(.previous)
802 
803 #define RESTART_TABLE(_start, _end, _target)	\
804 	stringify_in_c(.section __restart_table,"a";)\
805 	stringify_in_c(.balign 8;)		\
806 	stringify_in_c(.llong (_start);)	\
807 	stringify_in_c(.llong (_end);)		\
808 	stringify_in_c(.llong (_target);)	\
809 	stringify_in_c(.previous)
810 
811 #ifdef CONFIG_PPC_E500
812 #define BTB_FLUSH(reg)			\
813 	lis reg,BUCSR_INIT@h;		\
814 	ori reg,reg,BUCSR_INIT@l;	\
815 	mtspr SPRN_BUCSR,reg;		\
816 	isync;
817 #else
818 #define BTB_FLUSH(reg)
819 #endif /* CONFIG_PPC_E500 */
820 
821 #endif /* _ASM_POWERPC_PPC_ASM_H */
822