blob: f595b98079ee1ec75064640001998a407524ad59 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
Kumar Gala5f7c6902005-09-09 15:02:25 -05004#ifndef _ASM_POWERPC_PPC_ASM_H
5#define _ASM_POWERPC_PPC_ASM_H
6
Tim Abbott9203fc92009-04-27 14:02:24 -04007#include <linux/init.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +10008#include <linux/stringify.h>
David Gibson3ddfbcf2005-11-10 12:56:55 +11009#include <asm/asm-compat.h>
Michael Neuling9c75a312008-06-26 17:07:48 +100010#include <asm/processor.h>
Kumar Gala16c57b32009-02-10 20:10:44 +000011#include <asm/ppc-opcode.h>
Paul Mackerrascf9efce2010-08-26 19:56:43 +000012#include <asm/firmware.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100013
David Gibson3ddfbcf2005-11-10 12:56:55 +110014#ifndef __ASSEMBLY__
15#error __FILE__ should only be used in assembler files
16#else
17
18#define SZL (BITS_PER_LONG/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20/*
Paul Mackerrasc6622f62006-02-24 10:06:59 +110021 * 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.
25 */
26
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020027#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
Paul Mackerrasc6622f62006-02-24 10:06:59 +110028#define ACCOUNT_CPU_USER_ENTRY(ra, rb)
29#define ACCOUNT_CPU_USER_EXIT(ra, rb)
Paul Mackerrascf9efce2010-08-26 19:56:43 +000030#define ACCOUNT_STOLEN_TIME
Paul Mackerrasc6622f62006-02-24 10:06:59 +110031#else
32#define ACCOUNT_CPU_USER_ENTRY(ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000033 MFTB(ra); /* get timebase */ \
34 ld rb,PACA_STARTTIME_USER(r13); \
35 std ra,PACA_STARTTIME(r13); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110036 subf rb,rb,ra; /* subtract start value */ \
37 ld ra,PACA_USER_TIME(r13); \
38 add ra,ra,rb; /* add on to user time */ \
39 std ra,PACA_USER_TIME(r13); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110040
41#define ACCOUNT_CPU_USER_EXIT(ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000042 MFTB(ra); /* get timebase */ \
43 ld rb,PACA_STARTTIME(r13); \
44 std ra,PACA_STARTTIME_USER(r13); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110045 subf rb,rb,ra; /* subtract start value */ \
46 ld ra,PACA_SYSTEM_TIME(r13); \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000047 add ra,ra,rb; /* add on to system time */ \
48 std ra,PACA_SYSTEM_TIME(r13)
49
50#ifdef CONFIG_PPC_SPLPAR
51#define ACCOUNT_STOLEN_TIME \
52BEGIN_FW_FTR_SECTION; \
53 beq 33f; \
54 /* from user - see if there are any DTL entries to process */ \
55 ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \
56 ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \
Anton Blanchard7ffcf8e2013-08-07 02:01:46 +100057 addi r10,r10,LPPACA_DTLIDX; \
58 LDX_BE r10,0,r10; /* get log write index */ \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000059 cmpd cr1,r11,r10; \
60 beq+ cr1,33f; \
61 bl .accumulate_stolen_time; \
Benjamin Herrenschmidt990118c2012-03-02 11:01:31 +110062 ld r12,_MSR(r1); \
63 andi. r10,r12,MSR_PR; /* Restore cr0 (coming from user) */ \
Paul Mackerrascf9efce2010-08-26 19:56:43 +00006433: \
65END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
66
67#else /* CONFIG_PPC_SPLPAR */
68#define ACCOUNT_STOLEN_TIME
69
70#endif /* CONFIG_PPC_SPLPAR */
71
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020072#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
Paul Mackerrasc6622f62006-02-24 10:06:59 +110073
74/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 * Macros for storing registers into and loading registers from
76 * exception frames.
77 */
Kumar Gala5f7c6902005-09-09 15:02:25 -050078#ifdef __powerpc64__
79#define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
80#define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
81#define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
82#define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
83#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
87 SAVE_10GPRS(22, base)
88#define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
89 REST_10GPRS(22, base)
Kumar Gala5f7c6902005-09-09 15:02:25 -050090#endif
91
Kumar Gala5f7c6902005-09-09 15:02:25 -050092#define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
93#define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
94#define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
95#define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
96#define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
97#define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
98#define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
99#define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000101#define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
103#define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
104#define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
105#define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
106#define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000107#define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
109#define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
110#define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
111#define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
112#define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
113
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000114#define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -0500115#define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
116#define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
117#define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
118#define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
119#define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000120#define REST_VR(n,b,base) li b,16*(n); lvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -0500121#define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
122#define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
123#define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
124#define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
125#define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Anton Blanchard926f1602013-09-23 12:04:39 +1000127#ifdef __BIG_ENDIAN__
128#define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base)
129#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base)
130#else
131#define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \
132 STXVD2X(n,b,base); \
133 XXSWAPD(n,n)
134
135#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \
136 XXSWAPD(n,n)
137#endif
Michael Neuling72ffff52008-06-25 14:07:18 +1000138/* Save the lower 32 VSRs in the thread VSR region */
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100139#define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +1000140#define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
141#define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
142#define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
143#define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
144#define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100145#define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +1000146#define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
147#define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
148#define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
149#define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
150#define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
Michael Neuling72ffff52008-06-25 14:07:18 +1000151
Scott Woodc51584d2011-06-14 18:34:27 -0500152/*
153 * b = base register for addressing, o = base offset from register of 1st EVR
154 * n = first EVR, s = scratch
155 */
156#define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b)
157#define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
158#define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
159#define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
160#define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
161#define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
162#define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n
163#define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
164#define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
165#define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
166#define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
167#define REST_32EVRS(n,s,b,o) REST_16EVRS(n,s,b,o); REST_16EVRS(n+16,s,b,o)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Michael Ellerman8c716322005-10-24 15:07:27 +1000169/* Macros to adjust thread priority for hardware multithreading */
170#define HMT_VERY_LOW or 31,31,31 # very low priority
171#define HMT_LOW or 1,1,1
172#define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
173#define HMT_MEDIUM or 2,2,2
174#define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
175#define HMT_HIGH or 3,3,3
Benjamin Herrenschmidt50fb8eb2011-01-12 17:41:28 +1100176#define HMT_EXTRA_HIGH or 7,7,7 # power7 only
Kumar Gala5f7c6902005-09-09 15:02:25 -0500177
Michael Neulingd72be892012-06-25 13:33:15 +0000178#ifdef CONFIG_PPC64
179#define ULONG_SIZE 8
180#else
181#define ULONG_SIZE 4
182#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000183#define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
184#define VCPU_GPR(n) __VCPU_GPR(__REG_##n)
Michael Neulingd72be892012-06-25 13:33:15 +0000185
Arnd Bergmann88ced032005-12-16 22:43:46 +0100186#ifdef __KERNEL__
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000187#ifdef CONFIG_PPC64
188
Michael Neuling44ce6a52012-06-25 13:33:14 +0000189#define STACKFRAMESIZE 256
Michael Neuling0b7673c2012-06-25 13:33:23 +0000190#define __STK_REG(i) (112 + ((i)-14)*8)
191#define STK_REG(i) __STK_REG(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000192
Michael Neuling0b7673c2012-06-25 13:33:23 +0000193#define __STK_PARAM(i) (48 + ((i)-3)*8)
194#define STK_PARAM(i) __STK_PARAM(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000195
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000196#define XGLUE(a,b) a##b
197#define GLUE(a,b) XGLUE(a,b)
198
199#define _GLOBAL(name) \
200 .section ".text"; \
201 .align 2 ; \
202 .globl name; \
203 .globl GLUE(.,name); \
204 .section ".opd","aw"; \
205name: \
206 .quad GLUE(.,name); \
207 .quad .TOC.@tocbase; \
208 .quad 0; \
209 .previous; \
210 .type GLUE(.,name),@function; \
211GLUE(.,name):
212
Stephen Rothwellfc68e862007-08-22 13:44:58 +1000213#define _INIT_GLOBAL(name) \
Tim Abbott9203fc92009-04-27 14:02:24 -0400214 __REF; \
Stephen Rothwellfc68e862007-08-22 13:44:58 +1000215 .align 2 ; \
216 .globl name; \
217 .globl GLUE(.,name); \
218 .section ".opd","aw"; \
219name: \
220 .quad GLUE(.,name); \
221 .quad .TOC.@tocbase; \
222 .quad 0; \
223 .previous; \
224 .type GLUE(.,name),@function; \
225GLUE(.,name):
226
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000227#define _KPROBE(name) \
228 .section ".kprobes.text","a"; \
229 .align 2 ; \
230 .globl name; \
231 .globl GLUE(.,name); \
232 .section ".opd","aw"; \
233name: \
234 .quad GLUE(.,name); \
235 .quad .TOC.@tocbase; \
236 .quad 0; \
237 .previous; \
238 .type GLUE(.,name),@function; \
239GLUE(.,name):
240
241#define _STATIC(name) \
242 .section ".text"; \
243 .align 2 ; \
244 .section ".opd","aw"; \
245name: \
246 .quad GLUE(.,name); \
247 .quad .TOC.@tocbase; \
248 .quad 0; \
249 .previous; \
250 .type GLUE(.,name),@function; \
251GLUE(.,name):
252
Stephen Rothwellc40b91b2007-07-25 09:27:35 +1000253#define _INIT_STATIC(name) \
Tim Abbott9203fc92009-04-27 14:02:24 -0400254 __REF; \
Stephen Rothwellc40b91b2007-07-25 09:27:35 +1000255 .align 2 ; \
256 .section ".opd","aw"; \
257name: \
258 .quad GLUE(.,name); \
259 .quad .TOC.@tocbase; \
260 .quad 0; \
261 .previous; \
262 .type GLUE(.,name),@function; \
263GLUE(.,name):
264
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000265#else /* 32-bit */
266
Kumar Gala748a7682007-09-13 15:42:35 -0500267#define _ENTRY(n) \
268 .globl n; \
269n:
270
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000271#define _GLOBAL(n) \
272 .text; \
273 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
274 .globl n; \
275n:
276
277#define _KPROBE(n) \
278 .section ".kprobes.text","a"; \
279 .globl n; \
280n:
281
282#endif
283
Kumar Gala5f7c6902005-09-09 15:02:25 -0500284/*
David Gibsone58c3492006-01-13 14:56:25 +1100285 * LOAD_REG_IMMEDIATE(rn, expr)
286 * Loads the value of the constant expression 'expr' into register 'rn'
287 * using immediate instructions only. Use this when it's important not
288 * to reference other data (i.e. on ppc64 when the TOC pointer is not
Paul Mackerrase31aa452008-08-30 11:41:12 +1000289 * valid) and when 'expr' is a constant or absolute address.
Kumar Gala5f7c6902005-09-09 15:02:25 -0500290 *
David Gibsone58c3492006-01-13 14:56:25 +1100291 * LOAD_REG_ADDR(rn, name)
292 * Loads the address of label 'name' into register 'rn'. Use this when
293 * you don't particularly need immediate instructions only, but you need
294 * the whole address in one register (e.g. it's a structure address and
295 * you want to access various offsets within it). On ppc32 this is
296 * identical to LOAD_REG_IMMEDIATE.
297 *
298 * LOAD_REG_ADDRBASE(rn, name)
299 * ADDROFF(name)
300 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
301 * register 'rn'. ADDROFF(name) returns the remainder of the address as
302 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
303 * in size, so is suitable for use directly as an offset in load and store
304 * instructions. Use this when loading/storing a single word or less as:
305 * LOAD_REG_ADDRBASE(rX, name)
306 * ld rY,ADDROFF(name)(rX)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500307 */
308#ifdef __powerpc64__
David Gibsone58c3492006-01-13 14:56:25 +1100309#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000310 lis reg,(expr)@highest; \
311 ori reg,reg,(expr)@higher; \
312 rldicr reg,reg,32,31; \
313 oris reg,reg,(expr)@h; \
314 ori reg,reg,(expr)@l;
Kumar Gala5f7c6902005-09-09 15:02:25 -0500315
David Gibsone58c3492006-01-13 14:56:25 +1100316#define LOAD_REG_ADDR(reg,name) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000317 ld reg,name@got(r2)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500318
David Gibsone58c3492006-01-13 14:56:25 +1100319#define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
320#define ADDROFF(name) 0
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000321
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000322/* offsets for stack frame layout */
323#define LRSAVE 16
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000324
325#else /* 32-bit */
Stephen Rothwell70620182005-10-12 17:44:55 +1000326
David Gibsone58c3492006-01-13 14:56:25 +1100327#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000328 lis reg,(expr)@ha; \
329 addi reg,reg,(expr)@l;
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000330
David Gibsone58c3492006-01-13 14:56:25 +1100331#define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
332
Michael Neuling564aa5c2012-06-25 13:33:09 +0000333#define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha
David Gibsone58c3492006-01-13 14:56:25 +1100334#define ADDROFF(name) name@l
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000335
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000336/* offsets for stack frame layout */
337#define LRSAVE 4
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000338
Kumar Gala5f7c6902005-09-09 15:02:25 -0500339#endif
340
341/* various errata or part fixups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#ifdef CONFIG_PPC601_SYNC_FIX
343#define SYNC \
344BEGIN_FTR_SECTION \
345 sync; \
346 isync; \
347END_FTR_SECTION_IFSET(CPU_FTR_601)
348#define SYNC_601 \
349BEGIN_FTR_SECTION \
350 sync; \
351END_FTR_SECTION_IFSET(CPU_FTR_601)
352#define ISYNC_601 \
353BEGIN_FTR_SECTION \
354 isync; \
355END_FTR_SECTION_IFSET(CPU_FTR_601)
356#else
357#define SYNC
358#define SYNC_601
359#define ISYNC_601
360#endif
361
Scott Woodd52459c2013-07-23 20:21:11 -0500362#if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000363#define MFTB(dest) \
Scott Woodbeb2dc02013-08-20 19:33:12 -050036490: mfspr dest, SPRN_TBRL; \
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000365BEGIN_FTR_SECTION_NESTED(96); \
366 cmpwi dest,0; \
367 beq- 90b; \
368END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
LEROY Christopheae2163b2013-11-22 17:57:31 +0100369#elif defined(CONFIG_8xx)
370#define MFTB(dest) mftb dest
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000371#else
Scott Woodbeb2dc02013-08-20 19:33:12 -0500372#define MFTB(dest) mfspr dest, SPRN_TBRL
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000373#endif
Kumar Gala5f7c6902005-09-09 15:02:25 -0500374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#ifndef CONFIG_SMP
376#define TLBSYNC
377#else /* CONFIG_SMP */
378/* tlbsync is not implemented on 601 */
379#define TLBSYNC \
380BEGIN_FTR_SECTION \
381 tlbsync; \
382 sync; \
383END_FTR_SECTION_IFCLR(CPU_FTR_601)
384#endif
385
Anton Blanchard694caf02012-04-18 02:21:52 +0000386#ifdef CONFIG_PPC64
387#define MTOCRF(FXM, RS) \
388 BEGIN_FTR_SECTION_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000389 mtcrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000390 FTR_SECTION_ELSE_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000391 mtocrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000392 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000393
394/*
395 * PPR restore macros used in entry_64.S
396 * Used for P7 or later processors
397 */
398#define HMT_MEDIUM_LOW_HAS_PPR \
399BEGIN_FTR_SECTION_NESTED(944) \
400 HMT_MEDIUM_LOW; \
401END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,944)
402
403#define SET_DEFAULT_THREAD_PPR(ra, rb) \
404BEGIN_FTR_SECTION_NESTED(945) \
405 lis ra,INIT_PPR@highest; /* default ppr=3 */ \
406 ld rb,PACACURRENT(r13); \
407 sldi ra,ra,32; /* 11- 13 bits are used for ppr */ \
408 std ra,TASKTHREADPPR(rb); \
409END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,945)
410
Anton Blanchard694caf02012-04-18 02:21:52 +0000411#endif
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413/*
414 * This instruction is not implemented on the PPC 603 or 601; however, on
415 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
416 * All of these instructions exist in the 8xx, they have magical powers,
417 * and they must be used.
418 */
419
420#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
421#define tlbia \
422 li r4,1024; \
423 mtctr r4; \
424 lis r4,KERNELBASE@h; \
4250: tlbie r4; \
426 addi r4,r4,0x1000; \
427 bdnz 0b
428#endif
429
Kumar Gala5f7c6902005-09-09 15:02:25 -0500430
Kumar Gala5f7c6902005-09-09 15:02:25 -0500431#ifdef CONFIG_IBM440EP_ERR42
432#define PPC440EP_ERR42 isync
433#else
434#define PPC440EP_ERR42
435#endif
436
Michael Neulinga5153482013-05-29 19:34:27 +0000437/* The following stops all load and store data streams associated with stream
438 * ID (ie. streams created explicitly). The embedded and server mnemonics for
439 * dcbt are different so we use machine "power4" here explicitly.
440 */
441#define DCBT_STOP_ALL_STREAM_IDS(scratch) \
442.machine push ; \
443.machine "power4" ; \
444 lis scratch,0x60000000@h; \
445 dcbt r0,scratch,0b01010; \
446.machine pop
447
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000448/*
449 * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
450 * keep the address intact to be compatible with code shared with
451 * 32-bit classic.
452 *
453 * On the other hand, I find it useful to have them behave as expected
454 * by their name (ie always do the addition) on 64-bit BookE
455 */
456#if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000457#define toreal(rd)
458#define fromreal(rd)
459
Roland McGrath2ca76332008-05-11 10:40:47 +1000460/*
461 * We use addis to ensure compatibility with the "classic" ppc versions of
462 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
463 * converting the address in r0, and so this version has to do that too
464 * (i.e. set register rd to 0 when rs == 0).
465 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define tophys(rd,rs) \
467 addis rd,rs,0
468
469#define tovirt(rd,rs) \
470 addis rd,rs,0
471
Kumar Gala5f7c6902005-09-09 15:02:25 -0500472#elif defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000473#define toreal(rd) /* we can access c000... in real mode */
474#define fromreal(rd)
475
Kumar Gala5f7c6902005-09-09 15:02:25 -0500476#define tophys(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000477 clrldi rd,rs,2
Kumar Gala5f7c6902005-09-09 15:02:25 -0500478
479#define tovirt(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000480 rotldi rd,rs,16; \
481 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
482 rotldi rd,rd,48
Kumar Gala5f7c6902005-09-09 15:02:25 -0500483#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484/*
485 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
486 * physical base address of RAM at compile time.
487 */
Paul Mackerras63162222005-10-27 22:44:39 +1000488#define toreal(rd) tophys(rd,rd)
489#define fromreal(rd) tovirt(rd,rd)
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define tophys(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00004920: addis rd,rs,-PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .section ".vtop_fixup","aw"; \
494 .align 1; \
495 .long 0b; \
496 .previous
497
498#define tovirt(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00004990: addis rd,rs,PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .section ".ptov_fixup","aw"; \
501 .align 1; \
502 .long 0b; \
503 .previous
Kumar Gala5f7c6902005-09-09 15:02:25 -0500504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000506#ifdef CONFIG_PPC_BOOK3S_64
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000507#define RFI rfid
508#define MTMSRD(r) mtmsrd r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000509#define MTMSR_EERI(reg) mtmsrd reg,1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#else
511#define FIX_SRR1(ra, rb)
512#ifndef CONFIG_40x
513#define RFI rfi
514#else
515#define RFI rfi; b . /* Prevent prefetch past rfi */
516#endif
517#define MTMSRD(r) mtmsr r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000518#define MTMSR_EERI(reg) mtmsr reg
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#define CLR_TOP32(r)
Matt Porterc9cf73a2005-07-31 22:34:52 -0700520#endif
521
Arnd Bergmann88ced032005-12-16 22:43:46 +0100522#endif /* __KERNEL__ */
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524/* The boring bits... */
525
526/* Condition Register Bit Fields */
527
528#define cr0 0
529#define cr1 1
530#define cr2 2
531#define cr3 3
532#define cr4 4
533#define cr5 5
534#define cr6 6
535#define cr7 7
536
537
Michael Neuling9a13a522012-06-25 13:33:12 +0000538/*
539 * General Purpose Registers (GPRs)
540 *
541 * The lower case r0-r31 should be used in preference to the upper
542 * case R0-R31 as they provide more error checking in the assembler.
543 * Use R0-31 only when really nessesary.
544 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Michael Neuling9a13a522012-06-25 13:33:12 +0000546#define r0 %r0
547#define r1 %r1
548#define r2 %r2
549#define r3 %r3
550#define r4 %r4
551#define r5 %r5
552#define r6 %r6
553#define r7 %r7
554#define r8 %r8
555#define r9 %r9
556#define r10 %r10
557#define r11 %r11
558#define r12 %r12
559#define r13 %r13
560#define r14 %r14
561#define r15 %r15
562#define r16 %r16
563#define r17 %r17
564#define r18 %r18
565#define r19 %r19
566#define r20 %r20
567#define r21 %r21
568#define r22 %r22
569#define r23 %r23
570#define r24 %r24
571#define r25 %r25
572#define r26 %r26
573#define r27 %r27
574#define r28 %r28
575#define r29 %r29
576#define r30 %r30
577#define r31 %r31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579
580/* Floating Point Registers (FPRs) */
581
582#define fr0 0
583#define fr1 1
584#define fr2 2
585#define fr3 3
586#define fr4 4
587#define fr5 5
588#define fr6 6
589#define fr7 7
590#define fr8 8
591#define fr9 9
592#define fr10 10
593#define fr11 11
594#define fr12 12
595#define fr13 13
596#define fr14 14
597#define fr15 15
598#define fr16 16
599#define fr17 17
600#define fr18 18
601#define fr19 19
602#define fr20 20
603#define fr21 21
604#define fr22 22
605#define fr23 23
606#define fr24 24
607#define fr25 25
608#define fr26 26
609#define fr27 27
610#define fr28 28
611#define fr29 29
612#define fr30 30
613#define fr31 31
614
Kumar Gala5f7c6902005-09-09 15:02:25 -0500615/* AltiVec Registers (VPRs) */
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define vr0 0
618#define vr1 1
619#define vr2 2
620#define vr3 3
621#define vr4 4
622#define vr5 5
623#define vr6 6
624#define vr7 7
625#define vr8 8
626#define vr9 9
627#define vr10 10
628#define vr11 11
629#define vr12 12
630#define vr13 13
631#define vr14 14
632#define vr15 15
633#define vr16 16
634#define vr17 17
635#define vr18 18
636#define vr19 19
637#define vr20 20
638#define vr21 21
639#define vr22 22
640#define vr23 23
641#define vr24 24
642#define vr25 25
643#define vr26 26
644#define vr27 27
645#define vr28 28
646#define vr29 29
647#define vr30 30
648#define vr31 31
649
Michael Neuling72ffff52008-06-25 14:07:18 +1000650/* VSX Registers (VSRs) */
651
652#define vsr0 0
653#define vsr1 1
654#define vsr2 2
655#define vsr3 3
656#define vsr4 4
657#define vsr5 5
658#define vsr6 6
659#define vsr7 7
660#define vsr8 8
661#define vsr9 9
662#define vsr10 10
663#define vsr11 11
664#define vsr12 12
665#define vsr13 13
666#define vsr14 14
667#define vsr15 15
668#define vsr16 16
669#define vsr17 17
670#define vsr18 18
671#define vsr19 19
672#define vsr20 20
673#define vsr21 21
674#define vsr22 22
675#define vsr23 23
676#define vsr24 24
677#define vsr25 25
678#define vsr26 26
679#define vsr27 27
680#define vsr28 28
681#define vsr29 29
682#define vsr30 30
683#define vsr31 31
684#define vsr32 32
685#define vsr33 33
686#define vsr34 34
687#define vsr35 35
688#define vsr36 36
689#define vsr37 37
690#define vsr38 38
691#define vsr39 39
692#define vsr40 40
693#define vsr41 41
694#define vsr42 42
695#define vsr43 43
696#define vsr44 44
697#define vsr45 45
698#define vsr46 46
699#define vsr47 47
700#define vsr48 48
701#define vsr49 49
702#define vsr50 50
703#define vsr51 51
704#define vsr52 52
705#define vsr53 53
706#define vsr54 54
707#define vsr55 55
708#define vsr56 56
709#define vsr57 57
710#define vsr58 58
711#define vsr59 59
712#define vsr60 60
713#define vsr61 61
714#define vsr62 62
715#define vsr63 63
716
Kumar Gala5f7c6902005-09-09 15:02:25 -0500717/* SPE Registers (EVPRs) */
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#define evr0 0
720#define evr1 1
721#define evr2 2
722#define evr3 3
723#define evr4 4
724#define evr5 5
725#define evr6 6
726#define evr7 7
727#define evr8 8
728#define evr9 9
729#define evr10 10
730#define evr11 11
731#define evr12 12
732#define evr13 13
733#define evr14 14
734#define evr15 15
735#define evr16 16
736#define evr17 17
737#define evr18 18
738#define evr19 19
739#define evr20 20
740#define evr21 21
741#define evr22 22
742#define evr23 23
743#define evr24 24
744#define evr25 25
745#define evr26 26
746#define evr27 27
747#define evr28 28
748#define evr29 29
749#define evr30 30
750#define evr31 31
751
752/* some stab codes */
753#define N_FUN 36
754#define N_RSYM 64
755#define N_SLINE 68
756#define N_SO 100
Kumar Gala5f7c6902005-09-09 15:02:25 -0500757
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000758/*
759 * Create an endian fixup trampoline
760 *
761 * This starts with a "tdi 0,0,0x48" instruction which is
762 * essentially a "trap never", and thus akin to a nop.
763 *
764 * The opcode for this instruction read with the wrong endian
765 * however results in a b . + 8
766 *
767 * So essentially we use that trick to execute the following
768 * trampoline in "reverse endian" if we are running with the
769 * MSR_LE bit set the "wrong" way for whatever endianness the
770 * kernel is built for.
771 */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500772
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000773#ifdef CONFIG_PPC_BOOK3E
774#define FIXUP_ENDIAN
775#else
776#define FIXUP_ENDIAN \
777 tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
778 b $+36; /* Skip trampoline if endian is good */ \
779 .long 0x05009f42; /* bcl 20,31,$+4 */ \
780 .long 0xa602487d; /* mflr r10 */ \
781 .long 0x1c004a39; /* addi r10,r10,28 */ \
782 .long 0xa600607d; /* mfmsr r11 */ \
783 .long 0x01006b69; /* xori r11,r11,1 */ \
784 .long 0xa6035a7d; /* mtsrr0 r10 */ \
785 .long 0xa6037b7d; /* mtsrr1 r11 */ \
786 .long 0x2400004c /* rfid */
787#endif /* !CONFIG_PPC_BOOK3E */
788#endif /* __ASSEMBLY__ */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500789#endif /* _ASM_POWERPC_PPC_ASM_H */