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 <asm/asm-compat.h>
9 #include <asm/processor.h>
12 #error __FILE__ should only be used in assembler files
15 #define SZL (BITS_PER_LONG/8)
18 * Stuff for accurate CPU time accounting.
19 * These macros handle transitions between user and system state
20 * in exception entry and exit and accumulate time to the
21 * user_time and system_time fields in the paca.
24 #ifndef CONFIG_VIRT_CPU_ACCOUNTING
25 #define ACCOUNT_CPU_USER_ENTRY(ra, rb)
26 #define ACCOUNT_CPU_USER_EXIT(ra, rb)
28 #define ACCOUNT_CPU_USER_ENTRY(ra, rb) \
29 beq 2f; /* if from kernel mode */ \
31 mfspr ra,SPRN_PURR; /* get processor util. reg */ \
32 END_FTR_SECTION_IFSET(CPU_FTR_PURR); \
34 MFTB(ra); /* or get TB if no PURR */ \
35 END_FTR_SECTION_IFCLR(CPU_FTR_PURR); \
36 ld rb,PACA_STARTPURR(r13); \
37 std ra,PACA_STARTPURR(r13); \
38 subf rb,rb,ra; /* subtract start value */ \
39 ld ra,PACA_USER_TIME(r13); \
40 add ra,ra,rb; /* add on to user time */ \
41 std ra,PACA_USER_TIME(r13); \
44 #define ACCOUNT_CPU_USER_EXIT(ra, rb) \
46 mfspr ra,SPRN_PURR; /* get processor util. reg */ \
47 END_FTR_SECTION_IFSET(CPU_FTR_PURR); \
49 MFTB(ra); /* or get TB if no PURR */ \
50 END_FTR_SECTION_IFCLR(CPU_FTR_PURR); \
51 ld rb,PACA_STARTPURR(r13); \
52 std ra,PACA_STARTPURR(r13); \
53 subf rb,rb,ra; /* subtract start value */ \
54 ld ra,PACA_SYSTEM_TIME(r13); \
55 add ra,ra,rb; /* add on to user time */ \
56 std ra,PACA_SYSTEM_TIME(r13);
60 * Macros for storing registers into and loading registers from
64 #define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
65 #define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
66 #define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
67 #define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
69 #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
70 #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
71 #define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
73 #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
78 * Define what the VSX XX1 form instructions will look like, then add
79 * the 128 bit load store instructions based on that.
81 #define VSX_XX1(xs, ra, rb) (((xs) & 0x1f) << 21 | ((ra) << 16) | \
82 ((rb) << 11) | (((xs) >> 5)))
84 #define STXVD2X(xs, ra, rb) .long (0x7c000798 | VSX_XX1((xs), (ra), (rb)))
85 #define LXVD2X(xs, ra, rb) .long (0x7c000698 | VSX_XX1((xs), (ra), (rb)))
87 #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
88 #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
89 #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
90 #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
91 #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
92 #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
93 #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
94 #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
96 #define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*TS_FPRWIDTH*(n)(base)
97 #define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
98 #define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
99 #define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
100 #define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
101 #define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
102 #define REST_FPR(n, base) lfd n,THREAD_FPR0+8*TS_FPRWIDTH*(n)(base)
103 #define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
104 #define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
105 #define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
106 #define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
107 #define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
109 #define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,b,base
110 #define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
111 #define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
112 #define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
113 #define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
114 #define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
115 #define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,b,base
116 #define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
117 #define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
118 #define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
119 #define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
120 #define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
122 /* Save the lower 32 VSRs in the thread VSR region */
123 #define SAVE_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); STXVD2X(n,b,base)
124 #define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
125 #define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
126 #define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
127 #define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
128 #define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
129 #define REST_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); LXVD2X(n,b,base)
130 #define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
131 #define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
132 #define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
133 #define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
134 #define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
135 /* Save the upper 32 VSRs (32-63) in the thread VSX region (0-31) */
136 #define SAVE_VSRU(n,b,base) li b,THREAD_VR0+(16*(n)); STXVD2X(n+32,b,base)
137 #define SAVE_2VSRSU(n,b,base) SAVE_VSRU(n,b,base); SAVE_VSRU(n+1,b,base)
138 #define SAVE_4VSRSU(n,b,base) SAVE_2VSRSU(n,b,base); SAVE_2VSRSU(n+2,b,base)
139 #define SAVE_8VSRSU(n,b,base) SAVE_4VSRSU(n,b,base); SAVE_4VSRSU(n+4,b,base)
140 #define SAVE_16VSRSU(n,b,base) SAVE_8VSRSU(n,b,base); SAVE_8VSRSU(n+8,b,base)
141 #define SAVE_32VSRSU(n,b,base) SAVE_16VSRSU(n,b,base); SAVE_16VSRSU(n+16,b,base)
142 #define REST_VSRU(n,b,base) li b,THREAD_VR0+(16*(n)); LXVD2X(n+32,b,base)
143 #define REST_2VSRSU(n,b,base) REST_VSRU(n,b,base); REST_VSRU(n+1,b,base)
144 #define REST_4VSRSU(n,b,base) REST_2VSRSU(n,b,base); REST_2VSRSU(n+2,b,base)
145 #define REST_8VSRSU(n,b,base) REST_4VSRSU(n,b,base); REST_4VSRSU(n+4,b,base)
146 #define REST_16VSRSU(n,b,base) REST_8VSRSU(n,b,base); REST_8VSRSU(n+8,b,base)
147 #define REST_32VSRSU(n,b,base) REST_16VSRSU(n,b,base); REST_16VSRSU(n+16,b,base)
149 #define SAVE_EVR(n,s,base) evmergehi s,s,n; stw s,THREAD_EVR0+4*(n)(base)
150 #define SAVE_2EVRS(n,s,base) SAVE_EVR(n,s,base); SAVE_EVR(n+1,s,base)
151 #define SAVE_4EVRS(n,s,base) SAVE_2EVRS(n,s,base); SAVE_2EVRS(n+2,s,base)
152 #define SAVE_8EVRS(n,s,base) SAVE_4EVRS(n,s,base); SAVE_4EVRS(n+4,s,base)
153 #define SAVE_16EVRS(n,s,base) SAVE_8EVRS(n,s,base); SAVE_8EVRS(n+8,s,base)
154 #define SAVE_32EVRS(n,s,base) SAVE_16EVRS(n,s,base); SAVE_16EVRS(n+16,s,base)
155 #define REST_EVR(n,s,base) lwz s,THREAD_EVR0+4*(n)(base); evmergelo n,s,n
156 #define REST_2EVRS(n,s,base) REST_EVR(n,s,base); REST_EVR(n+1,s,base)
157 #define REST_4EVRS(n,s,base) REST_2EVRS(n,s,base); REST_2EVRS(n+2,s,base)
158 #define REST_8EVRS(n,s,base) REST_4EVRS(n,s,base); REST_4EVRS(n+4,s,base)
159 #define REST_16EVRS(n,s,base) REST_8EVRS(n,s,base); REST_8EVRS(n+8,s,base)
160 #define REST_32EVRS(n,s,base) REST_16EVRS(n,s,base); REST_16EVRS(n+16,s,base)
162 /* Macros to adjust thread priority for hardware multithreading */
163 #define HMT_VERY_LOW or 31,31,31 # very low priority
164 #define HMT_LOW or 1,1,1
165 #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
166 #define HMT_MEDIUM or 2,2,2
167 #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
168 #define HMT_HIGH or 3,3,3
170 /* handle instructions that older assemblers may not know */
171 #define RFCI .long 0x4c000066 /* rfci instruction */
172 #define RFDI .long 0x4c00004e /* rfdi instruction */
173 #define RFMCI .long 0x4c00004c /* rfmci instruction */
178 #define XGLUE(a,b) a##b
179 #define GLUE(a,b) XGLUE(a,b)
181 #define _GLOBAL(name) \
185 .globl GLUE(.,name); \
186 .section ".opd","aw"; \
188 .quad GLUE(.,name); \
189 .quad .TOC.@tocbase; \
192 .type GLUE(.,name),@function; \
195 #define _INIT_GLOBAL(name) \
196 .section ".text.init.refok"; \
199 .globl GLUE(.,name); \
200 .section ".opd","aw"; \
202 .quad GLUE(.,name); \
203 .quad .TOC.@tocbase; \
206 .type GLUE(.,name),@function; \
209 #define _KPROBE(name) \
210 .section ".kprobes.text","a"; \
213 .globl GLUE(.,name); \
214 .section ".opd","aw"; \
216 .quad GLUE(.,name); \
217 .quad .TOC.@tocbase; \
220 .type GLUE(.,name),@function; \
223 #define _STATIC(name) \
226 .section ".opd","aw"; \
228 .quad GLUE(.,name); \
229 .quad .TOC.@tocbase; \
232 .type GLUE(.,name),@function; \
235 #define _INIT_STATIC(name) \
236 .section ".text.init.refok"; \
238 .section ".opd","aw"; \
240 .quad GLUE(.,name); \
241 .quad .TOC.@tocbase; \
244 .type GLUE(.,name),@function; \
255 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
260 .section ".kprobes.text","a"; \
267 * LOAD_REG_IMMEDIATE(rn, expr)
268 * Loads the value of the constant expression 'expr' into register 'rn'
269 * using immediate instructions only. Use this when it's important not
270 * to reference other data (i.e. on ppc64 when the TOC pointer is not
273 * LOAD_REG_ADDR(rn, name)
274 * Loads the address of label 'name' into register 'rn'. Use this when
275 * you don't particularly need immediate instructions only, but you need
276 * the whole address in one register (e.g. it's a structure address and
277 * you want to access various offsets within it). On ppc32 this is
278 * identical to LOAD_REG_IMMEDIATE.
280 * LOAD_REG_ADDRBASE(rn, name)
282 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
283 * register 'rn'. ADDROFF(name) returns the remainder of the address as
284 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
285 * in size, so is suitable for use directly as an offset in load and store
286 * instructions. Use this when loading/storing a single word or less as:
287 * LOAD_REG_ADDRBASE(rX, name)
288 * ld rY,ADDROFF(name)(rX)
291 #define LOAD_REG_IMMEDIATE(reg,expr) \
292 lis (reg),(expr)@highest; \
293 ori (reg),(reg),(expr)@higher; \
294 rldicr (reg),(reg),32,31; \
295 oris (reg),(reg),(expr)@h; \
296 ori (reg),(reg),(expr)@l;
298 #define LOAD_REG_ADDR(reg,name) \
299 ld (reg),name@got(r2)
301 #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
302 #define ADDROFF(name) 0
304 /* offsets for stack frame layout */
309 #define LOAD_REG_IMMEDIATE(reg,expr) \
310 lis (reg),(expr)@ha; \
311 addi (reg),(reg),(expr)@l;
313 #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
315 #define LOAD_REG_ADDRBASE(reg, name) lis (reg),name@ha
316 #define ADDROFF(name) name@l
318 /* offsets for stack frame layout */
323 /* various errata or part fixups */
324 #ifdef CONFIG_PPC601_SYNC_FIX
329 END_FTR_SECTION_IFSET(CPU_FTR_601)
333 END_FTR_SECTION_IFSET(CPU_FTR_601)
337 END_FTR_SECTION_IFSET(CPU_FTR_601)
344 #ifdef CONFIG_PPC_CELL
347 BEGIN_FTR_SECTION_NESTED(96); \
350 END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
352 #define MFTB(dest) mftb dest
357 #else /* CONFIG_SMP */
358 /* tlbsync is not implemented on 601 */
363 END_FTR_SECTION_IFCLR(CPU_FTR_601)
368 * This instruction is not implemented on the PPC 603 or 601; however, on
369 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
370 * All of these instructions exist in the 8xx, they have magical powers,
371 * and they must be used.
374 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
378 lis r4,KERNELBASE@h; \
385 #ifdef CONFIG_IBM440EP_ERR42
386 #define PPC440EP_ERR42 isync
388 #define PPC440EP_ERR42
392 #if defined(CONFIG_BOOKE)
397 * We use addis to ensure compatibility with the "classic" ppc versions of
398 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
399 * converting the address in r0, and so this version has to do that too
400 * (i.e. set register rd to 0 when rs == 0).
402 #define tophys(rd,rs) \
405 #define tovirt(rd,rs) \
408 #elif defined(CONFIG_PPC64)
409 #define toreal(rd) /* we can access c000... in real mode */
412 #define tophys(rd,rs) \
415 #define tovirt(rd,rs) \
417 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
421 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
422 * physical base address of RAM at compile time.
424 #define toreal(rd) tophys(rd,rd)
425 #define fromreal(rd) tovirt(rd,rd)
427 #define tophys(rd,rs) \
428 0: addis rd,rs,-KERNELBASE@h; \
429 .section ".vtop_fixup","aw"; \
434 #define tovirt(rd,rs) \
435 0: addis rd,rs,KERNELBASE@h; \
436 .section ".ptov_fixup","aw"; \
444 #define MTMSRD(r) mtmsrd r
447 #define FIX_SRR1(ra, rb)
451 #define RFI rfi; b . /* Prevent prefetch past rfi */
453 #define MTMSRD(r) mtmsr r
457 #endif /* __KERNEL__ */
459 /* The boring bits... */
461 /* Condition Register Bit Fields */
473 /* General Purpose Registers (GPRs) */
509 /* Floating Point Registers (FPRs) */
544 /* AltiVec Registers (VPRs) */
579 /* VSX Registers (VSRs) */
646 /* SPE Registers (EVPRs) */
681 /* some stab codes */
687 #endif /* __ASSEMBLY__ */
689 #endif /* _ASM_POWERPC_PPC_ASM_H */