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