2 * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
4 #ifndef _ASM_POWERPC_PPC_ASM_H
5 #define _ASM_POWERPC_PPC_ASM_H
7 #include <linux/stringify.h>
8 #include <linux/config.h>
13 * Macros for storing registers into and loading registers from
17 #define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
18 #define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
19 #define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
20 #define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
22 #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
23 #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
24 #define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
26 #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
31 #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
32 #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
33 #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
34 #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
35 #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
36 #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
37 #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
38 #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
40 #define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*(n)(base)
41 #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
42 #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
43 #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
44 #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
45 #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
46 #define REST_FPR(n, base) lfd n,THREAD_FPR0+8*(n)(base)
47 #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
48 #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
49 #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
50 #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
51 #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
53 #define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,b,base
54 #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
55 #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
56 #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
57 #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
58 #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
59 #define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,b,base
60 #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
61 #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
62 #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
63 #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
64 #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
66 #define SAVE_EVR(n,s,base) evmergehi s,s,n; stw s,THREAD_EVR0+4*(n)(base)
67 #define SAVE_2EVRS(n,s,base) SAVE_EVR(n,s,base); SAVE_EVR(n+1,s,base)
68 #define SAVE_4EVRS(n,s,base) SAVE_2EVRS(n,s,base); SAVE_2EVRS(n+2,s,base)
69 #define SAVE_8EVRS(n,s,base) SAVE_4EVRS(n,s,base); SAVE_4EVRS(n+4,s,base)
70 #define SAVE_16EVRS(n,s,base) SAVE_8EVRS(n,s,base); SAVE_8EVRS(n+8,s,base)
71 #define SAVE_32EVRS(n,s,base) SAVE_16EVRS(n,s,base); SAVE_16EVRS(n+16,s,base)
72 #define REST_EVR(n,s,base) lwz s,THREAD_EVR0+4*(n)(base); evmergelo n,s,n
73 #define REST_2EVRS(n,s,base) REST_EVR(n,s,base); REST_EVR(n+1,s,base)
74 #define REST_4EVRS(n,s,base) REST_2EVRS(n,s,base); REST_2EVRS(n+2,s,base)
75 #define REST_8EVRS(n,s,base) REST_4EVRS(n,s,base); REST_4EVRS(n+4,s,base)
76 #define REST_16EVRS(n,s,base) REST_8EVRS(n,s,base); REST_8EVRS(n+8,s,base)
77 #define REST_32EVRS(n,s,base) REST_16EVRS(n,s,base); REST_16EVRS(n+16,s,base)
79 /* Macros to adjust thread priority for Iseries hardware multithreading */
80 #define HMT_VERY_LOW or 31,31,31 # very low priority\n"
81 #define HMT_LOW or 1,1,1
82 #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority\n"
83 #define HMT_MEDIUM or 2,2,2
84 #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority\n"
85 #define HMT_HIGH or 3,3,3
87 /* handle instructions that older assemblers may not know */
88 #define RFCI .long 0x4c000066 /* rfci instruction */
89 #define RFDI .long 0x4c00004e /* rfdi instruction */
90 #define RFMCI .long 0x4c00004c /* rfmci instruction */
94 #define XGLUE(a,b) a##b
95 #define GLUE(a,b) XGLUE(a,b)
97 #define _GLOBAL(name) \
101 .globl GLUE(.,name); \
102 .section ".opd","aw"; \
104 .quad GLUE(.,name); \
105 .quad .TOC.@tocbase; \
108 .type GLUE(.,name),@function; \
111 #define _KPROBE(name) \
112 .section ".kprobes.text","a"; \
115 .globl GLUE(.,name); \
116 .section ".opd","aw"; \
118 .quad GLUE(.,name); \
119 .quad .TOC.@tocbase; \
122 .type GLUE(.,name),@function; \
125 #define _STATIC(name) \
128 .section ".opd","aw"; \
130 .quad GLUE(.,name); \
131 .quad .TOC.@tocbase; \
134 .type GLUE(.,name),@function; \
141 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
146 .section ".kprobes.text","a"; \
153 * LOADADDR( rn, name )
154 * loads the address of 'name' into 'rn'
156 * LOADBASE( rn, name )
157 * loads the address (less the low 16 bits) of 'name' into 'rn'
158 * suitable for base+disp addressing
161 #define LOADADDR(rn,name) \
162 lis rn,name##@highest; \
163 ori rn,rn,name##@higher; \
164 rldicr rn,rn,32,31; \
165 oris rn,rn,name##@h; \
168 #define LOADBASE(rn,name) \
169 .section .toc,"aw"; \
170 1: .tc name[TC],name; \
176 #define SET_REG_TO_CONST(reg, value) \
177 lis reg,(((value)>>48)&0xFFFF); \
178 ori reg,reg,(((value)>>32)&0xFFFF); \
179 rldicr reg,reg,32,31; \
180 oris reg,reg,(((value)>>16)&0xFFFF); \
181 ori reg,reg,((value)&0xFFFF);
183 #define SET_REG_TO_LABEL(reg, label) \
184 lis reg,(label)@highest; \
185 ori reg,reg,(label)@higher; \
186 rldicr reg,reg,32,31; \
187 oris reg,reg,(label)@h; \
188 ori reg,reg,(label)@l;
190 /* operations for longs and pointers */
196 #define LOADBASE(rn,name) \
199 #define OFF(name) name@l
201 /* operations for longs and pointers */
208 /* various errata or part fixups */
209 #ifdef CONFIG_PPC601_SYNC_FIX
214 END_FTR_SECTION_IFSET(CPU_FTR_601)
218 END_FTR_SECTION_IFSET(CPU_FTR_601)
222 END_FTR_SECTION_IFSET(CPU_FTR_601)
232 #else /* CONFIG_SMP */
233 /* tlbsync is not implemented on 601 */
238 END_FTR_SECTION_IFCLR(CPU_FTR_601)
243 * This instruction is not implemented on the PPC 603 or 601; however, on
244 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
245 * All of these instructions exist in the 8xx, they have magical powers,
246 * and they must be used.
249 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
253 lis r4,KERNELBASE@h; \
260 #ifdef CONFIG_IBM405_ERR77
261 #define PPC405_ERR77(ra,rb) dcbt ra, rb;
262 #define PPC405_ERR77_SYNC sync;
264 #define PPC405_ERR77(ra,rb)
265 #define PPC405_ERR77_SYNC
269 #ifdef CONFIG_IBM440EP_ERR42
270 #define PPC440EP_ERR42 isync
272 #define PPC440EP_ERR42
276 #if defined(CONFIG_BOOKE)
277 #define tophys(rd,rs) \
280 #define tovirt(rd,rs) \
283 #elif defined(CONFIG_PPC64)
284 /* PPPBBB - DRENG If KERNELBASE is always 0xC0...,
285 * Then we can easily do this with one asm insn. -Peter
287 #define tophys(rd,rs) \
288 lis rd,((KERNELBASE>>48)&0xFFFF); \
289 rldicr rd,rd,32,31; \
292 #define tovirt(rd,rs) \
293 lis rd,((KERNELBASE>>48)&0xFFFF); \
294 rldicr rd,rd,32,31; \
298 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
299 * physical base address of RAM at compile time.
301 #define tophys(rd,rs) \
302 0: addis rd,rs,-KERNELBASE@h; \
303 .section ".vtop_fixup","aw"; \
308 #define tovirt(rd,rs) \
309 0: addis rd,rs,KERNELBASE@h; \
310 .section ".ptov_fixup","aw"; \
318 #define MTMSRD(r) mtmsrd r
321 #define FIX_SRR1(ra, rb)
325 #define RFI rfi; b . /* Prevent prefetch past rfi */
327 #define MTMSRD(r) mtmsr r
331 /* The boring bits... */
333 /* Condition Register Bit Fields */
345 /* General Purpose Registers (GPRs) */
381 /* Floating Point Registers (FPRs) */
416 /* AltiVec Registers (VPRs) */
451 /* SPE Registers (EVPRs) */
486 /* some stab codes */
492 #define ASM_CONST(x) x
494 #define __ASM_CONST(x) x##UL
495 #define ASM_CONST(x) __ASM_CONST(x)
496 #endif /* __ASSEMBLY__ */
498 #endif /* _ASM_POWERPC_PPC_ASM_H */