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/init.h>
8 #include <linux/stringify.h>
9 #include <asm/asm-compat.h>
10 #include <asm/processor.h>
11 #include <asm/ppc-opcode.h>
12 #include <asm/firmware.h>
15 #error __FILE__ should only be used in assembler files
18 #define SZL (BITS_PER_LONG/8)
21 * Stuff for accurate CPU time accounting.
22 * These macros handle transitions between user and system state
23 * in exception entry and exit and accumulate time to the
24 * user_time and system_time fields in the paca.
27 #ifndef CONFIG_VIRT_CPU_ACCOUNTING
28 #define ACCOUNT_CPU_USER_ENTRY(ra, rb)
29 #define ACCOUNT_CPU_USER_EXIT(ra, rb)
30 #define ACCOUNT_STOLEN_TIME
32 #define ACCOUNT_CPU_USER_ENTRY(ra, rb) \
33 beq 2f; /* if from kernel mode */ \
34 MFTB(ra); /* get timebase */ \
35 ld rb,PACA_STARTTIME_USER(r13); \
36 std ra,PACA_STARTTIME(r13); \
37 subf rb,rb,ra; /* subtract start value */ \
38 ld ra,PACA_USER_TIME(r13); \
39 add ra,ra,rb; /* add on to user time */ \
40 std ra,PACA_USER_TIME(r13); \
43 #define ACCOUNT_CPU_USER_EXIT(ra, rb) \
44 MFTB(ra); /* get timebase */ \
45 ld rb,PACA_STARTTIME(r13); \
46 std ra,PACA_STARTTIME_USER(r13); \
47 subf rb,rb,ra; /* subtract start value */ \
48 ld ra,PACA_SYSTEM_TIME(r13); \
49 add ra,ra,rb; /* add on to system time */ \
50 std ra,PACA_SYSTEM_TIME(r13)
52 #ifdef CONFIG_PPC_SPLPAR
53 #define ACCOUNT_STOLEN_TIME \
54 BEGIN_FW_FTR_SECTION; \
56 /* from user - see if there are any DTL entries to process */ \
57 ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \
58 ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \
59 ld r10,LPPACA_DTLIDX(r10); /* get log write index */ \
62 bl .accumulate_stolen_time; \
64 END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
66 #else /* CONFIG_PPC_SPLPAR */
67 #define ACCOUNT_STOLEN_TIME
69 #endif /* CONFIG_PPC_SPLPAR */
71 #endif /* CONFIG_VIRT_CPU_ACCOUNTING */
74 * Macros for storing registers into and loading registers from
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)
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); \
87 #define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
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)
100 #define SAVE_FPR(n, base) stfd n,THREAD_FPR0+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,THREAD_FPR0+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)
113 #define SAVE_VR(n,b,base) li b,THREAD_VR0+(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,THREAD_VR0+(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)
126 /* Save the lower 32 VSRs in the thread VSR region */
127 #define SAVE_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); STXVD2X(n,base,b)
128 #define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
129 #define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
130 #define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
131 #define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
132 #define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
133 #define REST_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); LXVD2X(n,base,b)
134 #define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
135 #define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
136 #define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
137 #define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
138 #define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
139 /* Save the upper 32 VSRs (32-63) in the thread VSX region (0-31) */
140 #define SAVE_VSRU(n,b,base) li b,THREAD_VR0+(16*(n)); STXVD2X(n+32,base,b)
141 #define SAVE_2VSRSU(n,b,base) SAVE_VSRU(n,b,base); SAVE_VSRU(n+1,b,base)
142 #define SAVE_4VSRSU(n,b,base) SAVE_2VSRSU(n,b,base); SAVE_2VSRSU(n+2,b,base)
143 #define SAVE_8VSRSU(n,b,base) SAVE_4VSRSU(n,b,base); SAVE_4VSRSU(n+4,b,base)
144 #define SAVE_16VSRSU(n,b,base) SAVE_8VSRSU(n,b,base); SAVE_8VSRSU(n+8,b,base)
145 #define SAVE_32VSRSU(n,b,base) SAVE_16VSRSU(n,b,base); SAVE_16VSRSU(n+16,b,base)
146 #define REST_VSRU(n,b,base) li b,THREAD_VR0+(16*(n)); LXVD2X(n+32,base,b)
147 #define REST_2VSRSU(n,b,base) REST_VSRU(n,b,base); REST_VSRU(n+1,b,base)
148 #define REST_4VSRSU(n,b,base) REST_2VSRSU(n,b,base); REST_2VSRSU(n+2,b,base)
149 #define REST_8VSRSU(n,b,base) REST_4VSRSU(n,b,base); REST_4VSRSU(n+4,b,base)
150 #define REST_16VSRSU(n,b,base) REST_8VSRSU(n,b,base); REST_8VSRSU(n+8,b,base)
151 #define REST_32VSRSU(n,b,base) REST_16VSRSU(n,b,base); REST_16VSRSU(n+16,b,base)
154 * b = base register for addressing, o = base offset from register of 1st EVR
155 * n = first EVR, s = scratch
157 #define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b)
158 #define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
159 #define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
160 #define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
161 #define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
162 #define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
163 #define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n
164 #define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
165 #define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
166 #define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
167 #define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
168 #define REST_32EVRS(n,s,b,o) REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
170 /* Macros to adjust thread priority for hardware multithreading */
171 #define HMT_VERY_LOW or 31,31,31 # very low priority
172 #define HMT_LOW or 1,1,1
173 #define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
174 #define HMT_MEDIUM or 2,2,2
175 #define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
176 #define HMT_HIGH or 3,3,3
177 #define HMT_EXTRA_HIGH or 7,7,7 # power7 only
182 #define XGLUE(a,b) a##b
183 #define GLUE(a,b) XGLUE(a,b)
185 #define _GLOBAL(name) \
189 .globl GLUE(.,name); \
190 .section ".opd","aw"; \
192 .quad GLUE(.,name); \
193 .quad .TOC.@tocbase; \
196 .type GLUE(.,name),@function; \
199 #define _INIT_GLOBAL(name) \
203 .globl GLUE(.,name); \
204 .section ".opd","aw"; \
206 .quad GLUE(.,name); \
207 .quad .TOC.@tocbase; \
210 .type GLUE(.,name),@function; \
213 #define _KPROBE(name) \
214 .section ".kprobes.text","a"; \
217 .globl GLUE(.,name); \
218 .section ".opd","aw"; \
220 .quad GLUE(.,name); \
221 .quad .TOC.@tocbase; \
224 .type GLUE(.,name),@function; \
227 #define _STATIC(name) \
230 .section ".opd","aw"; \
232 .quad GLUE(.,name); \
233 .quad .TOC.@tocbase; \
236 .type GLUE(.,name),@function; \
239 #define _INIT_STATIC(name) \
242 .section ".opd","aw"; \
244 .quad GLUE(.,name); \
245 .quad .TOC.@tocbase; \
248 .type GLUE(.,name),@function; \
259 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
264 .section ".kprobes.text","a"; \
271 * LOAD_REG_IMMEDIATE(rn, expr)
272 * Loads the value of the constant expression 'expr' into register 'rn'
273 * using immediate instructions only. Use this when it's important not
274 * to reference other data (i.e. on ppc64 when the TOC pointer is not
275 * valid) and when 'expr' is a constant or absolute address.
277 * LOAD_REG_ADDR(rn, name)
278 * Loads the address of label 'name' into register 'rn'. Use this when
279 * you don't particularly need immediate instructions only, but you need
280 * the whole address in one register (e.g. it's a structure address and
281 * you want to access various offsets within it). On ppc32 this is
282 * identical to LOAD_REG_IMMEDIATE.
284 * LOAD_REG_ADDRBASE(rn, name)
286 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
287 * register 'rn'. ADDROFF(name) returns the remainder of the address as
288 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
289 * in size, so is suitable for use directly as an offset in load and store
290 * instructions. Use this when loading/storing a single word or less as:
291 * LOAD_REG_ADDRBASE(rX, name)
292 * ld rY,ADDROFF(name)(rX)
295 #define LOAD_REG_IMMEDIATE(reg,expr) \
296 lis (reg),(expr)@highest; \
297 ori (reg),(reg),(expr)@higher; \
298 rldicr (reg),(reg),32,31; \
299 oris (reg),(reg),(expr)@h; \
300 ori (reg),(reg),(expr)@l;
302 #define LOAD_REG_ADDR(reg,name) \
303 ld (reg),name@got(r2)
305 #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
306 #define ADDROFF(name) 0
308 /* offsets for stack frame layout */
313 #define LOAD_REG_IMMEDIATE(reg,expr) \
314 lis (reg),(expr)@ha; \
315 addi (reg),(reg),(expr)@l;
317 #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
319 #define LOAD_REG_ADDRBASE(reg, name) lis (reg),name@ha
320 #define ADDROFF(name) name@l
322 /* offsets for stack frame layout */
327 /* various errata or part fixups */
328 #ifdef CONFIG_PPC601_SYNC_FIX
333 END_FTR_SECTION_IFSET(CPU_FTR_601)
337 END_FTR_SECTION_IFSET(CPU_FTR_601)
341 END_FTR_SECTION_IFSET(CPU_FTR_601)
348 #ifdef CONFIG_PPC_CELL
351 BEGIN_FTR_SECTION_NESTED(96); \
354 END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
356 #define MFTB(dest) mftb dest
361 #else /* CONFIG_SMP */
362 /* tlbsync is not implemented on 601 */
367 END_FTR_SECTION_IFCLR(CPU_FTR_601)
372 * This instruction is not implemented on the PPC 603 or 601; however, on
373 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
374 * All of these instructions exist in the 8xx, they have magical powers,
375 * and they must be used.
378 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
382 lis r4,KERNELBASE@h; \
389 #ifdef CONFIG_IBM440EP_ERR42
390 #define PPC440EP_ERR42 isync
392 #define PPC440EP_ERR42
396 * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
397 * keep the address intact to be compatible with code shared with
400 * On the other hand, I find it useful to have them behave as expected
401 * by their name (ie always do the addition) on 64-bit BookE
403 #if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
408 * We use addis to ensure compatibility with the "classic" ppc versions of
409 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
410 * converting the address in r0, and so this version has to do that too
411 * (i.e. set register rd to 0 when rs == 0).
413 #define tophys(rd,rs) \
416 #define tovirt(rd,rs) \
419 #elif defined(CONFIG_PPC64)
420 #define toreal(rd) /* we can access c000... in real mode */
423 #define tophys(rd,rs) \
426 #define tovirt(rd,rs) \
428 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
432 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
433 * physical base address of RAM at compile time.
435 #define toreal(rd) tophys(rd,rd)
436 #define fromreal(rd) tovirt(rd,rd)
438 #define tophys(rd,rs) \
439 0: addis rd,rs,-PAGE_OFFSET@h; \
440 .section ".vtop_fixup","aw"; \
445 #define tovirt(rd,rs) \
446 0: addis rd,rs,PAGE_OFFSET@h; \
447 .section ".ptov_fixup","aw"; \
453 #ifdef CONFIG_PPC_BOOK3S_64
455 #define MTMSRD(r) mtmsrd r
457 #define FIX_SRR1(ra, rb)
461 #define RFI rfi; b . /* Prevent prefetch past rfi */
463 #define MTMSRD(r) mtmsr r
467 #endif /* __KERNEL__ */
469 /* The boring bits... */
471 /* Condition Register Bit Fields */
483 /* General Purpose Registers (GPRs) */
519 /* Floating Point Registers (FPRs) */
554 /* AltiVec Registers (VPRs) */
589 /* VSX Registers (VSRs) */
656 /* SPE Registers (EVPRs) */
691 /* some stab codes */
697 #endif /* __ASSEMBLY__ */
699 #endif /* _ASM_POWERPC_PPC_ASM_H */