blob: 3185d11b6691d247e5e66d2f53865f803d505061 [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
Paul Mackerras40ef8cb2005-10-10 22:50:37 +10007#include <linux/stringify.h>
David Gibson3ddfbcf2005-11-10 12:56:55 +11008#include <asm/asm-compat.h>
Michael Neuling9c75a312008-06-26 17:07:48 +10009#include <asm/processor.h>
Kumar Gala16c57b32009-02-10 20:10:44 +000010#include <asm/ppc-opcode.h>
Paul Mackerrascf9efce2010-08-26 19:56:43 +000011#include <asm/firmware.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100012
David Gibson3ddfbcf2005-11-10 12:56:55 +110013#ifndef __ASSEMBLY__
14#error __FILE__ should only be used in assembler files
15#else
16
17#define SZL (BITS_PER_LONG/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*
Paul Mackerrasc6622f62006-02-24 10:06:59 +110020 * Stuff for accurate CPU time accounting.
21 * These macros handle transitions between user and system state
22 * in exception entry and exit and accumulate time to the
23 * user_time and system_time fields in the paca.
24 */
25
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020026#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
Paul Mackerrasc6622f62006-02-24 10:06:59 +110027#define ACCOUNT_CPU_USER_ENTRY(ra, rb)
28#define ACCOUNT_CPU_USER_EXIT(ra, rb)
Paul Mackerrascf9efce2010-08-26 19:56:43 +000029#define ACCOUNT_STOLEN_TIME
Paul Mackerrasc6622f62006-02-24 10:06:59 +110030#else
31#define ACCOUNT_CPU_USER_ENTRY(ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000032 MFTB(ra); /* get timebase */ \
33 ld rb,PACA_STARTTIME_USER(r13); \
34 std ra,PACA_STARTTIME(r13); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110035 subf rb,rb,ra; /* subtract start value */ \
36 ld ra,PACA_USER_TIME(r13); \
37 add ra,ra,rb; /* add on to user time */ \
38 std ra,PACA_USER_TIME(r13); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110039
40#define ACCOUNT_CPU_USER_EXIT(ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000041 MFTB(ra); /* get timebase */ \
42 ld rb,PACA_STARTTIME(r13); \
43 std ra,PACA_STARTTIME_USER(r13); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110044 subf rb,rb,ra; /* subtract start value */ \
45 ld ra,PACA_SYSTEM_TIME(r13); \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000046 add ra,ra,rb; /* add on to system time */ \
47 std ra,PACA_SYSTEM_TIME(r13)
48
49#ifdef CONFIG_PPC_SPLPAR
50#define ACCOUNT_STOLEN_TIME \
51BEGIN_FW_FTR_SECTION; \
52 beq 33f; \
53 /* from user - see if there are any DTL entries to process */ \
54 ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \
55 ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \
Anton Blanchard7ffcf8e2013-08-07 02:01:46 +100056 addi r10,r10,LPPACA_DTLIDX; \
57 LDX_BE r10,0,r10; /* get log write index */ \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000058 cmpd cr1,r11,r10; \
59 beq+ cr1,33f; \
Anton Blanchardb1576fe2014-02-04 16:04:35 +110060 bl accumulate_stolen_time; \
Benjamin Herrenschmidt990118c2012-03-02 11:01:31 +110061 ld r12,_MSR(r1); \
62 andi. r10,r12,MSR_PR; /* Restore cr0 (coming from user) */ \
Paul Mackerrascf9efce2010-08-26 19:56:43 +00006333: \
64END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
65
66#else /* CONFIG_PPC_SPLPAR */
67#define ACCOUNT_STOLEN_TIME
68
69#endif /* CONFIG_PPC_SPLPAR */
70
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020071#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
Paul Mackerrasc6622f62006-02-24 10:06:59 +110072
73/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * Macros for storing registers into and loading registers from
75 * exception frames.
76 */
Kumar Gala5f7c6902005-09-09 15:02:25 -050077#ifdef __powerpc64__
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)
82#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
86 SAVE_10GPRS(22, base)
87#define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
88 REST_10GPRS(22, base)
Kumar Gala5f7c6902005-09-09 15:02:25 -050089#endif
90
Kumar Gala5f7c6902005-09-09 15:02:25 -050091#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000100#define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#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)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000106#define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#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)
112
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000113#define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -0500114#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)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000119#define REST_VR(n,b,base) li b,16*(n); lvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -0500120#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Anton Blanchard926f1602013-09-23 12:04:39 +1000126#ifdef __BIG_ENDIAN__
127#define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base)
128#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base)
129#else
130#define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \
131 STXVD2X(n,b,base); \
132 XXSWAPD(n,n)
133
134#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \
135 XXSWAPD(n,n)
136#endif
Michael Neuling72ffff52008-06-25 14:07:18 +1000137/* Save the lower 32 VSRs in the thread VSR region */
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100138#define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +1000139#define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
140#define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
141#define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
142#define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
143#define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100144#define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +1000145#define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
146#define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
147#define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
148#define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
149#define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
Michael Neuling72ffff52008-06-25 14:07:18 +1000150
Scott Woodc51584d2011-06-14 18:34:27 -0500151/*
152 * b = base register for addressing, o = base offset from register of 1st EVR
153 * n = first EVR, s = scratch
154 */
155#define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b)
156#define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
157#define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
158#define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
159#define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
160#define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
161#define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n
162#define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
163#define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
164#define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
165#define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
166#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 -0700167
Michael Ellerman8c716322005-10-24 15:07:27 +1000168/* Macros to adjust thread priority for hardware multithreading */
169#define HMT_VERY_LOW or 31,31,31 # very low priority
170#define HMT_LOW or 1,1,1
171#define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
172#define HMT_MEDIUM or 2,2,2
173#define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
174#define HMT_HIGH or 3,3,3
Benjamin Herrenschmidt50fb8eb2011-01-12 17:41:28 +1100175#define HMT_EXTRA_HIGH or 7,7,7 # power7 only
Kumar Gala5f7c6902005-09-09 15:02:25 -0500176
Michael Neulingd72be892012-06-25 13:33:15 +0000177#ifdef CONFIG_PPC64
178#define ULONG_SIZE 8
179#else
180#define ULONG_SIZE 4
181#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000182#define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
183#define VCPU_GPR(n) __VCPU_GPR(__REG_##n)
Michael Neulingd72be892012-06-25 13:33:15 +0000184
Arnd Bergmann88ced032005-12-16 22:43:46 +0100185#ifdef __KERNEL__
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000186#ifdef CONFIG_PPC64
187
Michael Neuling44ce6a52012-06-25 13:33:14 +0000188#define STACKFRAMESIZE 256
Michael Neuling0b7673c2012-06-25 13:33:23 +0000189#define __STK_REG(i) (112 + ((i)-14)*8)
190#define STK_REG(i) __STK_REG(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000191
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100192#if defined(_CALL_ELF) && _CALL_ELF == 2
193#define __STK_PARAM(i) (32 + ((i)-3)*8)
194#else
Michael Neuling0b7673c2012-06-25 13:33:23 +0000195#define __STK_PARAM(i) (48 + ((i)-3)*8)
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100196#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000197#define STK_PARAM(i) __STK_PARAM(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000198
Anton Blanchard7167af72014-02-04 16:07:20 +1100199#if defined(_CALL_ELF) && _CALL_ELF == 2
200
201#define _GLOBAL(name) \
202 .section ".text"; \
203 .align 2 ; \
204 .type name,@function; \
205 .globl name; \
206name:
207
208#define _KPROBE(name) \
209 .section ".kprobes.text","a"; \
210 .align 2 ; \
211 .type name,@function; \
212 .globl name; \
213name:
214
215#define DOTSYM(a) a
216
217#else
218
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000219#define XGLUE(a,b) a##b
220#define GLUE(a,b) XGLUE(a,b)
221
222#define _GLOBAL(name) \
223 .section ".text"; \
224 .align 2 ; \
225 .globl name; \
226 .globl GLUE(.,name); \
227 .section ".opd","aw"; \
228name: \
229 .quad GLUE(.,name); \
230 .quad .TOC.@tocbase; \
231 .quad 0; \
232 .previous; \
233 .type GLUE(.,name),@function; \
234GLUE(.,name):
235
236#define _KPROBE(name) \
237 .section ".kprobes.text","a"; \
238 .align 2 ; \
239 .globl name; \
240 .globl GLUE(.,name); \
241 .section ".opd","aw"; \
242name: \
243 .quad GLUE(.,name); \
244 .quad .TOC.@tocbase; \
245 .quad 0; \
246 .previous; \
247 .type GLUE(.,name),@function; \
248GLUE(.,name):
249
Anton Blanchardc1fb0192014-02-04 16:07:01 +1100250#define DOTSYM(a) GLUE(.,a)
251
Anton Blanchard7167af72014-02-04 16:07:20 +1100252#endif
253
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000254#else /* 32-bit */
255
Kumar Gala748a7682007-09-13 15:42:35 -0500256#define _ENTRY(n) \
257 .globl n; \
258n:
259
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000260#define _GLOBAL(n) \
261 .text; \
262 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
263 .globl n; \
264n:
265
266#define _KPROBE(n) \
267 .section ".kprobes.text","a"; \
268 .globl n; \
269n:
270
271#endif
272
Kumar Gala5f7c6902005-09-09 15:02:25 -0500273/*
David Gibsone58c3492006-01-13 14:56:25 +1100274 * LOAD_REG_IMMEDIATE(rn, expr)
275 * Loads the value of the constant expression 'expr' into register 'rn'
276 * using immediate instructions only. Use this when it's important not
277 * to reference other data (i.e. on ppc64 when the TOC pointer is not
Paul Mackerrase31aa452008-08-30 11:41:12 +1000278 * valid) and when 'expr' is a constant or absolute address.
Kumar Gala5f7c6902005-09-09 15:02:25 -0500279 *
David Gibsone58c3492006-01-13 14:56:25 +1100280 * LOAD_REG_ADDR(rn, name)
281 * Loads the address of label 'name' into register 'rn'. Use this when
282 * you don't particularly need immediate instructions only, but you need
283 * the whole address in one register (e.g. it's a structure address and
284 * you want to access various offsets within it). On ppc32 this is
285 * identical to LOAD_REG_IMMEDIATE.
286 *
Kevin Hao1c49abe2013-12-24 15:12:05 +0800287 * LOAD_REG_ADDR_PIC(rn, name)
288 * Loads the address of label 'name' into register 'run'. Use this when
289 * the kernel doesn't run at the linked or relocated address. Please
290 * note that this macro will clobber the lr register.
291 *
David Gibsone58c3492006-01-13 14:56:25 +1100292 * LOAD_REG_ADDRBASE(rn, name)
293 * ADDROFF(name)
294 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
295 * register 'rn'. ADDROFF(name) returns the remainder of the address as
296 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
297 * in size, so is suitable for use directly as an offset in load and store
298 * instructions. Use this when loading/storing a single word or less as:
299 * LOAD_REG_ADDRBASE(rX, name)
300 * ld rY,ADDROFF(name)(rX)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500301 */
Kevin Hao1c49abe2013-12-24 15:12:05 +0800302
303/* Be careful, this will clobber the lr register. */
304#define LOAD_REG_ADDR_PIC(reg, name) \
305 bl 0f; \
3060: mflr reg; \
307 addis reg,reg,(name - 0b)@ha; \
308 addi reg,reg,(name - 0b)@l;
309
Kumar Gala5f7c6902005-09-09 15:02:25 -0500310#ifdef __powerpc64__
David Gibsone58c3492006-01-13 14:56:25 +1100311#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000312 lis reg,(expr)@highest; \
313 ori reg,reg,(expr)@higher; \
314 rldicr reg,reg,32,31; \
315 oris reg,reg,(expr)@h; \
316 ori reg,reg,(expr)@l;
Kumar Gala5f7c6902005-09-09 15:02:25 -0500317
David Gibsone58c3492006-01-13 14:56:25 +1100318#define LOAD_REG_ADDR(reg,name) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000319 ld reg,name@got(r2)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500320
David Gibsone58c3492006-01-13 14:56:25 +1100321#define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
322#define ADDROFF(name) 0
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000323
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000324/* offsets for stack frame layout */
325#define LRSAVE 16
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000326
327#else /* 32-bit */
Stephen Rothwell70620182005-10-12 17:44:55 +1000328
David Gibsone58c3492006-01-13 14:56:25 +1100329#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000330 lis reg,(expr)@ha; \
331 addi reg,reg,(expr)@l;
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000332
David Gibsone58c3492006-01-13 14:56:25 +1100333#define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
334
Michael Neuling564aa5c2012-06-25 13:33:09 +0000335#define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha
David Gibsone58c3492006-01-13 14:56:25 +1100336#define ADDROFF(name) name@l
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000337
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000338/* offsets for stack frame layout */
339#define LRSAVE 4
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000340
Kumar Gala5f7c6902005-09-09 15:02:25 -0500341#endif
342
343/* various errata or part fixups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#ifdef CONFIG_PPC601_SYNC_FIX
345#define SYNC \
346BEGIN_FTR_SECTION \
347 sync; \
348 isync; \
349END_FTR_SECTION_IFSET(CPU_FTR_601)
350#define SYNC_601 \
351BEGIN_FTR_SECTION \
352 sync; \
353END_FTR_SECTION_IFSET(CPU_FTR_601)
354#define ISYNC_601 \
355BEGIN_FTR_SECTION \
356 isync; \
357END_FTR_SECTION_IFSET(CPU_FTR_601)
358#else
359#define SYNC
360#define SYNC_601
361#define ISYNC_601
362#endif
363
Scott Woodd52459c2013-07-23 20:21:11 -0500364#if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000365#define MFTB(dest) \
Scott Woodbeb2dc02013-08-20 19:33:12 -050036690: mfspr dest, SPRN_TBRL; \
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000367BEGIN_FTR_SECTION_NESTED(96); \
368 cmpwi dest,0; \
369 beq- 90b; \
370END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
LEROY Christopheae2163b2013-11-22 17:57:31 +0100371#elif defined(CONFIG_8xx)
372#define MFTB(dest) mftb dest
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000373#else
Scott Woodbeb2dc02013-08-20 19:33:12 -0500374#define MFTB(dest) mfspr dest, SPRN_TBRL
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000375#endif
Kumar Gala5f7c6902005-09-09 15:02:25 -0500376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#ifndef CONFIG_SMP
378#define TLBSYNC
379#else /* CONFIG_SMP */
380/* tlbsync is not implemented on 601 */
381#define TLBSYNC \
382BEGIN_FTR_SECTION \
383 tlbsync; \
384 sync; \
385END_FTR_SECTION_IFCLR(CPU_FTR_601)
386#endif
387
Anton Blanchard694caf02012-04-18 02:21:52 +0000388#ifdef CONFIG_PPC64
389#define MTOCRF(FXM, RS) \
390 BEGIN_FTR_SECTION_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000391 mtcrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000392 FTR_SECTION_ELSE_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000393 mtocrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000394 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000395
396/*
397 * PPR restore macros used in entry_64.S
398 * Used for P7 or later processors
399 */
400#define HMT_MEDIUM_LOW_HAS_PPR \
401BEGIN_FTR_SECTION_NESTED(944) \
402 HMT_MEDIUM_LOW; \
403END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,944)
404
405#define SET_DEFAULT_THREAD_PPR(ra, rb) \
406BEGIN_FTR_SECTION_NESTED(945) \
407 lis ra,INIT_PPR@highest; /* default ppr=3 */ \
408 ld rb,PACACURRENT(r13); \
409 sldi ra,ra,32; /* 11- 13 bits are used for ppr */ \
410 std ra,TASKTHREADPPR(rb); \
411END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,945)
412
Anton Blanchard694caf02012-04-18 02:21:52 +0000413#endif
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415/*
416 * This instruction is not implemented on the PPC 603 or 601; however, on
417 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
418 * All of these instructions exist in the 8xx, they have magical powers,
419 * and they must be used.
420 */
421
422#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
423#define tlbia \
424 li r4,1024; \
425 mtctr r4; \
426 lis r4,KERNELBASE@h; \
4270: tlbie r4; \
428 addi r4,r4,0x1000; \
429 bdnz 0b
430#endif
431
Kumar Gala5f7c6902005-09-09 15:02:25 -0500432
Kumar Gala5f7c6902005-09-09 15:02:25 -0500433#ifdef CONFIG_IBM440EP_ERR42
434#define PPC440EP_ERR42 isync
435#else
436#define PPC440EP_ERR42
437#endif
438
Michael Neulinga5153482013-05-29 19:34:27 +0000439/* The following stops all load and store data streams associated with stream
440 * ID (ie. streams created explicitly). The embedded and server mnemonics for
441 * dcbt are different so we use machine "power4" here explicitly.
442 */
443#define DCBT_STOP_ALL_STREAM_IDS(scratch) \
444.machine push ; \
445.machine "power4" ; \
446 lis scratch,0x60000000@h; \
447 dcbt r0,scratch,0b01010; \
448.machine pop
449
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000450/*
451 * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
452 * keep the address intact to be compatible with code shared with
453 * 32-bit classic.
454 *
455 * On the other hand, I find it useful to have them behave as expected
456 * by their name (ie always do the addition) on 64-bit BookE
457 */
458#if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000459#define toreal(rd)
460#define fromreal(rd)
461
Roland McGrath2ca76332008-05-11 10:40:47 +1000462/*
463 * We use addis to ensure compatibility with the "classic" ppc versions of
464 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
465 * converting the address in r0, and so this version has to do that too
466 * (i.e. set register rd to 0 when rs == 0).
467 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define tophys(rd,rs) \
469 addis rd,rs,0
470
471#define tovirt(rd,rs) \
472 addis rd,rs,0
473
Kumar Gala5f7c6902005-09-09 15:02:25 -0500474#elif defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000475#define toreal(rd) /* we can access c000... in real mode */
476#define fromreal(rd)
477
Kumar Gala5f7c6902005-09-09 15:02:25 -0500478#define tophys(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000479 clrldi rd,rs,2
Kumar Gala5f7c6902005-09-09 15:02:25 -0500480
481#define tovirt(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000482 rotldi rd,rs,16; \
483 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
484 rotldi rd,rd,48
Kumar Gala5f7c6902005-09-09 15:02:25 -0500485#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486/*
487 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
488 * physical base address of RAM at compile time.
489 */
Paul Mackerras63162222005-10-27 22:44:39 +1000490#define toreal(rd) tophys(rd,rd)
491#define fromreal(rd) tovirt(rd,rd)
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define tophys(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00004940: addis rd,rs,-PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .section ".vtop_fixup","aw"; \
496 .align 1; \
497 .long 0b; \
498 .previous
499
500#define tovirt(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00005010: addis rd,rs,PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .section ".ptov_fixup","aw"; \
503 .align 1; \
504 .long 0b; \
505 .previous
Kumar Gala5f7c6902005-09-09 15:02:25 -0500506#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000508#ifdef CONFIG_PPC_BOOK3S_64
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000509#define RFI rfid
510#define MTMSRD(r) mtmsrd r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000511#define MTMSR_EERI(reg) mtmsrd reg,1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#else
513#define FIX_SRR1(ra, rb)
514#ifndef CONFIG_40x
515#define RFI rfi
516#else
517#define RFI rfi; b . /* Prevent prefetch past rfi */
518#endif
519#define MTMSRD(r) mtmsr r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000520#define MTMSR_EERI(reg) mtmsr reg
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#define CLR_TOP32(r)
Matt Porterc9cf73a2005-07-31 22:34:52 -0700522#endif
523
Arnd Bergmann88ced032005-12-16 22:43:46 +0100524#endif /* __KERNEL__ */
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526/* The boring bits... */
527
528/* Condition Register Bit Fields */
529
530#define cr0 0
531#define cr1 1
532#define cr2 2
533#define cr3 3
534#define cr4 4
535#define cr5 5
536#define cr6 6
537#define cr7 7
538
539
Michael Neuling9a13a522012-06-25 13:33:12 +0000540/*
541 * General Purpose Registers (GPRs)
542 *
543 * The lower case r0-r31 should be used in preference to the upper
544 * case R0-R31 as they provide more error checking in the assembler.
545 * Use R0-31 only when really nessesary.
546 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Michael Neuling9a13a522012-06-25 13:33:12 +0000548#define r0 %r0
549#define r1 %r1
550#define r2 %r2
551#define r3 %r3
552#define r4 %r4
553#define r5 %r5
554#define r6 %r6
555#define r7 %r7
556#define r8 %r8
557#define r9 %r9
558#define r10 %r10
559#define r11 %r11
560#define r12 %r12
561#define r13 %r13
562#define r14 %r14
563#define r15 %r15
564#define r16 %r16
565#define r17 %r17
566#define r18 %r18
567#define r19 %r19
568#define r20 %r20
569#define r21 %r21
570#define r22 %r22
571#define r23 %r23
572#define r24 %r24
573#define r25 %r25
574#define r26 %r26
575#define r27 %r27
576#define r28 %r28
577#define r29 %r29
578#define r30 %r30
579#define r31 %r31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581
582/* Floating Point Registers (FPRs) */
583
584#define fr0 0
585#define fr1 1
586#define fr2 2
587#define fr3 3
588#define fr4 4
589#define fr5 5
590#define fr6 6
591#define fr7 7
592#define fr8 8
593#define fr9 9
594#define fr10 10
595#define fr11 11
596#define fr12 12
597#define fr13 13
598#define fr14 14
599#define fr15 15
600#define fr16 16
601#define fr17 17
602#define fr18 18
603#define fr19 19
604#define fr20 20
605#define fr21 21
606#define fr22 22
607#define fr23 23
608#define fr24 24
609#define fr25 25
610#define fr26 26
611#define fr27 27
612#define fr28 28
613#define fr29 29
614#define fr30 30
615#define fr31 31
616
Kumar Gala5f7c6902005-09-09 15:02:25 -0500617/* AltiVec Registers (VPRs) */
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define vr0 0
620#define vr1 1
621#define vr2 2
622#define vr3 3
623#define vr4 4
624#define vr5 5
625#define vr6 6
626#define vr7 7
627#define vr8 8
628#define vr9 9
629#define vr10 10
630#define vr11 11
631#define vr12 12
632#define vr13 13
633#define vr14 14
634#define vr15 15
635#define vr16 16
636#define vr17 17
637#define vr18 18
638#define vr19 19
639#define vr20 20
640#define vr21 21
641#define vr22 22
642#define vr23 23
643#define vr24 24
644#define vr25 25
645#define vr26 26
646#define vr27 27
647#define vr28 28
648#define vr29 29
649#define vr30 30
650#define vr31 31
651
Michael Neuling72ffff52008-06-25 14:07:18 +1000652/* VSX Registers (VSRs) */
653
654#define vsr0 0
655#define vsr1 1
656#define vsr2 2
657#define vsr3 3
658#define vsr4 4
659#define vsr5 5
660#define vsr6 6
661#define vsr7 7
662#define vsr8 8
663#define vsr9 9
664#define vsr10 10
665#define vsr11 11
666#define vsr12 12
667#define vsr13 13
668#define vsr14 14
669#define vsr15 15
670#define vsr16 16
671#define vsr17 17
672#define vsr18 18
673#define vsr19 19
674#define vsr20 20
675#define vsr21 21
676#define vsr22 22
677#define vsr23 23
678#define vsr24 24
679#define vsr25 25
680#define vsr26 26
681#define vsr27 27
682#define vsr28 28
683#define vsr29 29
684#define vsr30 30
685#define vsr31 31
686#define vsr32 32
687#define vsr33 33
688#define vsr34 34
689#define vsr35 35
690#define vsr36 36
691#define vsr37 37
692#define vsr38 38
693#define vsr39 39
694#define vsr40 40
695#define vsr41 41
696#define vsr42 42
697#define vsr43 43
698#define vsr44 44
699#define vsr45 45
700#define vsr46 46
701#define vsr47 47
702#define vsr48 48
703#define vsr49 49
704#define vsr50 50
705#define vsr51 51
706#define vsr52 52
707#define vsr53 53
708#define vsr54 54
709#define vsr55 55
710#define vsr56 56
711#define vsr57 57
712#define vsr58 58
713#define vsr59 59
714#define vsr60 60
715#define vsr61 61
716#define vsr62 62
717#define vsr63 63
718
Kumar Gala5f7c6902005-09-09 15:02:25 -0500719/* SPE Registers (EVPRs) */
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#define evr0 0
722#define evr1 1
723#define evr2 2
724#define evr3 3
725#define evr4 4
726#define evr5 5
727#define evr6 6
728#define evr7 7
729#define evr8 8
730#define evr9 9
731#define evr10 10
732#define evr11 11
733#define evr12 12
734#define evr13 13
735#define evr14 14
736#define evr15 15
737#define evr16 16
738#define evr17 17
739#define evr18 18
740#define evr19 19
741#define evr20 20
742#define evr21 21
743#define evr22 22
744#define evr23 23
745#define evr24 24
746#define evr25 25
747#define evr26 26
748#define evr27 27
749#define evr28 28
750#define evr29 29
751#define evr30 30
752#define evr31 31
753
754/* some stab codes */
755#define N_FUN 36
756#define N_RSYM 64
757#define N_SLINE 68
758#define N_SO 100
Kumar Gala5f7c6902005-09-09 15:02:25 -0500759
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000760/*
761 * Create an endian fixup trampoline
762 *
763 * This starts with a "tdi 0,0,0x48" instruction which is
764 * essentially a "trap never", and thus akin to a nop.
765 *
766 * The opcode for this instruction read with the wrong endian
767 * however results in a b . + 8
768 *
769 * So essentially we use that trick to execute the following
770 * trampoline in "reverse endian" if we are running with the
771 * MSR_LE bit set the "wrong" way for whatever endianness the
772 * kernel is built for.
773 */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500774
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000775#ifdef CONFIG_PPC_BOOK3E
776#define FIXUP_ENDIAN
777#else
778#define FIXUP_ENDIAN \
779 tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
780 b $+36; /* Skip trampoline if endian is good */ \
781 .long 0x05009f42; /* bcl 20,31,$+4 */ \
782 .long 0xa602487d; /* mflr r10 */ \
783 .long 0x1c004a39; /* addi r10,r10,28 */ \
784 .long 0xa600607d; /* mfmsr r11 */ \
785 .long 0x01006b69; /* xori r11,r11,1 */ \
786 .long 0xa6035a7d; /* mtsrr0 r10 */ \
787 .long 0xa6037b7d; /* mtsrr1 r11 */ \
788 .long 0x2400004c /* rfid */
789#endif /* !CONFIG_PPC_BOOK3E */
790#endif /* __ASSEMBLY__ */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500791#endif /* _ASM_POWERPC_PPC_ASM_H */