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>
9 #include <asm/asm-compat.h>
12 #error __FILE__ should only be used in assembler files
15 #define SZL (BITS_PER_LONG/8)
18 * Macros for storing registers into and loading registers from
22 #define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
23 #define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
24 #define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
25 #define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
27 #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
28 #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
29 #define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
31 #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
36 #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
37 #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
38 #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
39 #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
40 #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
41 #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
42 #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
43 #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
45 #define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*(n)(base)
46 #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
47 #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
48 #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
49 #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
50 #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
51 #define REST_FPR(n, base) lfd n,THREAD_FPR0+8*(n)(base)
52 #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
53 #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
54 #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
55 #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
56 #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
58 #define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,b,base
59 #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
60 #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
61 #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
62 #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
63 #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
64 #define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,b,base
65 #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
66 #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
67 #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
68 #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
69 #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
71 #define SAVE_EVR(n,s,base) evmergehi s,s,n; stw s,THREAD_EVR0+4*(n)(base)
72 #define SAVE_2EVRS(n,s,base) SAVE_EVR(n,s,base); SAVE_EVR(n+1,s,base)
73 #define SAVE_4EVRS(n,s,base) SAVE_2EVRS(n,s,base); SAVE_2EVRS(n+2,s,base)
74 #define SAVE_8EVRS(n,s,base) SAVE_4EVRS(n,s,base); SAVE_4EVRS(n+4,s,base)
75 #define SAVE_16EVRS(n,s,base) SAVE_8EVRS(n,s,base); SAVE_8EVRS(n+8,s,base)
76 #define SAVE_32EVRS(n,s,base) SAVE_16EVRS(n,s,base); SAVE_16EVRS(n+16,s,base)
77 #define REST_EVR(n,s,base) lwz s,THREAD_EVR0+4*(n)(base); evmergelo n,s,n
78 #define REST_2EVRS(n,s,base) REST_EVR(n,s,base); REST_EVR(n+1,s,base)
79 #define REST_4EVRS(n,s,base) REST_2EVRS(n,s,base); REST_2EVRS(n+2,s,base)
80 #define REST_8EVRS(n,s,base) REST_4EVRS(n,s,base); REST_4EVRS(n+4,s,base)
81 #define REST_16EVRS(n,s,base) REST_8EVRS(n,s,base); REST_8EVRS(n+8,s,base)
82 #define REST_32EVRS(n,s,base) REST_16EVRS(n,s,base); REST_16EVRS(n+16,s,base)
84 /* Macros to adjust thread priority for hardware multithreading */
85 #define HMT_VERY_LOW or 31,31,31 # very low priority
86 #define HMT_LOW or 1,1,1
87 #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
88 #define HMT_MEDIUM or 2,2,2
89 #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
90 #define HMT_HIGH or 3,3,3
92 /* handle instructions that older assemblers may not know */
93 #define RFCI .long 0x4c000066 /* rfci instruction */
94 #define RFDI .long 0x4c00004e /* rfdi instruction */
95 #define RFMCI .long 0x4c00004c /* rfmci instruction */
100 #define XGLUE(a,b) a##b
101 #define GLUE(a,b) XGLUE(a,b)
103 #define _GLOBAL(name) \
107 .globl GLUE(.,name); \
108 .section ".opd","aw"; \
110 .quad GLUE(.,name); \
111 .quad .TOC.@tocbase; \
114 .type GLUE(.,name),@function; \
117 #define _KPROBE(name) \
118 .section ".kprobes.text","a"; \
121 .globl GLUE(.,name); \
122 .section ".opd","aw"; \
124 .quad GLUE(.,name); \
125 .quad .TOC.@tocbase; \
128 .type GLUE(.,name),@function; \
131 #define _STATIC(name) \
134 .section ".opd","aw"; \
136 .quad GLUE(.,name); \
137 .quad .TOC.@tocbase; \
140 .type GLUE(.,name),@function; \
147 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
152 .section ".kprobes.text","a"; \
159 * LOAD_REG_IMMEDIATE(rn, expr)
160 * Loads the value of the constant expression 'expr' into register 'rn'
161 * using immediate instructions only. Use this when it's important not
162 * to reference other data (i.e. on ppc64 when the TOC pointer is not
165 * LOAD_REG_ADDR(rn, name)
166 * Loads the address of label 'name' into register 'rn'. Use this when
167 * you don't particularly need immediate instructions only, but you need
168 * the whole address in one register (e.g. it's a structure address and
169 * you want to access various offsets within it). On ppc32 this is
170 * identical to LOAD_REG_IMMEDIATE.
172 * LOAD_REG_ADDRBASE(rn, name)
174 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
175 * register 'rn'. ADDROFF(name) returns the remainder of the address as
176 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
177 * in size, so is suitable for use directly as an offset in load and store
178 * instructions. Use this when loading/storing a single word or less as:
179 * LOAD_REG_ADDRBASE(rX, name)
180 * ld rY,ADDROFF(name)(rX)
183 #define LOAD_REG_IMMEDIATE(reg,expr) \
184 lis (reg),(expr)@highest; \
185 ori (reg),(reg),(expr)@higher; \
186 rldicr (reg),(reg),32,31; \
187 oris (reg),(reg),(expr)@h; \
188 ori (reg),(reg),(expr)@l;
190 #define LOAD_REG_ADDR(reg,name) \
191 ld (reg),name@got(r2)
193 #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
194 #define ADDROFF(name) 0
196 /* offsets for stack frame layout */
201 #define LOAD_REG_IMMEDIATE(reg,expr) \
202 lis (reg),(expr)@ha; \
203 addi (reg),(reg),(expr)@l;
205 #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
207 #define LOAD_REG_ADDRBASE(reg, name) lis (reg),name@ha
208 #define ADDROFF(name) name@l
210 /* offsets for stack frame layout */
215 /* various errata or part fixups */
216 #ifdef CONFIG_PPC601_SYNC_FIX
221 END_FTR_SECTION_IFSET(CPU_FTR_601)
225 END_FTR_SECTION_IFSET(CPU_FTR_601)
229 END_FTR_SECTION_IFSET(CPU_FTR_601)
239 #else /* CONFIG_SMP */
240 /* tlbsync is not implemented on 601 */
245 END_FTR_SECTION_IFCLR(CPU_FTR_601)
250 * This instruction is not implemented on the PPC 603 or 601; however, on
251 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
252 * All of these instructions exist in the 8xx, they have magical powers,
253 * and they must be used.
256 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
260 lis r4,KERNELBASE@h; \
267 #ifdef CONFIG_IBM440EP_ERR42
268 #define PPC440EP_ERR42 isync
270 #define PPC440EP_ERR42
274 #if defined(CONFIG_BOOKE)
278 #define tophys(rd,rs) \
281 #define tovirt(rd,rs) \
284 #elif defined(CONFIG_PPC64)
285 #define toreal(rd) /* we can access c000... in real mode */
288 #define tophys(rd,rs) \
291 #define tovirt(rd,rs) \
293 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
297 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
298 * physical base address of RAM at compile time.
300 #define toreal(rd) tophys(rd,rd)
301 #define fromreal(rd) tovirt(rd,rd)
303 #define tophys(rd,rs) \
304 0: addis rd,rs,-KERNELBASE@h; \
305 .section ".vtop_fixup","aw"; \
310 #define tovirt(rd,rs) \
311 0: addis rd,rs,KERNELBASE@h; \
312 .section ".ptov_fixup","aw"; \
320 #define MTMSRD(r) mtmsrd r
323 #define FIX_SRR1(ra, rb)
327 #define RFI rfi; b . /* Prevent prefetch past rfi */
329 #define MTMSRD(r) mtmsr r
333 #endif /* __KERNEL__ */
335 /* The boring bits... */
337 /* Condition Register Bit Fields */
349 /* General Purpose Registers (GPRs) */
385 /* Floating Point Registers (FPRs) */
420 /* AltiVec Registers (VPRs) */
455 /* SPE Registers (EVPRs) */
490 /* some stab codes */
496 #endif /* __ASSEMBLY__ */
498 #endif /* _ASM_POWERPC_PPC_ASM_H */