blob: d5d5b5e348f22c68dc4d88d3b9fcb0eb6e987229 [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
Christophe Leroyc223c902016-05-17 08:33:46 +020027#define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb)
28#define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb)
Paul Mackerrascf9efce2010-08-26 19:56:43 +000029#define ACCOUNT_STOLEN_TIME
Paul Mackerrasc6622f62006-02-24 10:06:59 +110030#else
Christophe Leroyc223c902016-05-17 08:33:46 +020031#define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000032 MFTB(ra); /* get timebase */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020033 PPC_LL rb, ACCOUNT_STARTTIME_USER(ptr); \
34 PPC_STL ra, ACCOUNT_STARTTIME(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110035 subf rb,rb,ra; /* subtract start value */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020036 PPC_LL ra, ACCOUNT_USER_TIME(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110037 add ra,ra,rb; /* add on to user time */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020038 PPC_STL ra, ACCOUNT_USER_TIME(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110039
Christophe Leroyc223c902016-05-17 08:33:46 +020040#define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000041 MFTB(ra); /* get timebase */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020042 PPC_LL rb, ACCOUNT_STARTTIME(ptr); \
43 PPC_STL ra, ACCOUNT_STARTTIME_USER(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110044 subf rb,rb,ra; /* subtract start value */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020045 PPC_LL ra, ACCOUNT_SYSTEM_TIME(ptr); \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000046 add ra,ra,rb; /* add on to system time */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020047 PPC_STL ra, ACCOUNT_SYSTEM_TIME(ptr)
Paul Mackerrascf9efce2010-08-26 19:56:43 +000048
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
Michael Ellermanf55d9662016-06-06 22:26:10 +0530192#ifdef PPC64_ELF_ABI_v2
Anton Blanchard64031052014-03-10 10:52:17 +1100193#define STK_GOT 24
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100194#define __STK_PARAM(i) (32 + ((i)-3)*8)
195#else
Anton Blanchard64031052014-03-10 10:52:17 +1100196#define STK_GOT 40
Michael Neuling0b7673c2012-06-25 13:33:23 +0000197#define __STK_PARAM(i) (48 + ((i)-3)*8)
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100198#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000199#define STK_PARAM(i) __STK_PARAM(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000200
Michael Ellermanf55d9662016-06-06 22:26:10 +0530201#ifdef PPC64_ELF_ABI_v2
Anton Blanchard7167af72014-02-04 16:07:20 +1100202
203#define _GLOBAL(name) \
204 .section ".text"; \
205 .align 2 ; \
206 .type name,@function; \
207 .globl name; \
208name:
209
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100210#define _GLOBAL_TOC(name) \
211 .section ".text"; \
212 .align 2 ; \
213 .type name,@function; \
214 .globl name; \
215name: \
2160: addis r2,r12,(.TOC.-0b)@ha; \
217 addi r2,r2,(.TOC.-0b)@l; \
218 .localentry name,.-name
219
Anton Blanchard7167af72014-02-04 16:07:20 +1100220#define _KPROBE(name) \
221 .section ".kprobes.text","a"; \
222 .align 2 ; \
223 .type name,@function; \
224 .globl name; \
225name:
226
227#define DOTSYM(a) a
228
229#else
230
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000231#define XGLUE(a,b) a##b
232#define GLUE(a,b) XGLUE(a,b)
233
234#define _GLOBAL(name) \
235 .section ".text"; \
236 .align 2 ; \
237 .globl name; \
238 .globl GLUE(.,name); \
239 .section ".opd","aw"; \
240name: \
241 .quad GLUE(.,name); \
242 .quad .TOC.@tocbase; \
243 .quad 0; \
244 .previous; \
245 .type GLUE(.,name),@function; \
246GLUE(.,name):
247
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100248#define _GLOBAL_TOC(name) _GLOBAL(name)
249
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000250#define _KPROBE(name) \
251 .section ".kprobes.text","a"; \
252 .align 2 ; \
253 .globl name; \
254 .globl GLUE(.,name); \
255 .section ".opd","aw"; \
256name: \
257 .quad GLUE(.,name); \
258 .quad .TOC.@tocbase; \
259 .quad 0; \
260 .previous; \
261 .type GLUE(.,name),@function; \
262GLUE(.,name):
263
Anton Blanchardc1fb0192014-02-04 16:07:01 +1100264#define DOTSYM(a) GLUE(.,a)
265
Anton Blanchard7167af72014-02-04 16:07:20 +1100266#endif
267
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000268#else /* 32-bit */
269
Kumar Gala748a7682007-09-13 15:42:35 -0500270#define _ENTRY(n) \
271 .globl n; \
272n:
273
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000274#define _GLOBAL(n) \
275 .text; \
276 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
277 .globl n; \
278n:
279
Alexander Graf9715a2e2014-06-26 13:19:40 +0200280#define _GLOBAL_TOC(name) _GLOBAL(name)
281
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000282#define _KPROBE(n) \
283 .section ".kprobes.text","a"; \
284 .globl n; \
285n:
286
287#endif
288
Anton Blanchard151f2512016-07-01 08:19:44 +1000289#define FUNC_START(name) _GLOBAL(name)
290#define FUNC_END(name)
291
Kumar Gala5f7c6902005-09-09 15:02:25 -0500292/*
David Gibsone58c3492006-01-13 14:56:25 +1100293 * LOAD_REG_IMMEDIATE(rn, expr)
294 * Loads the value of the constant expression 'expr' into register 'rn'
295 * using immediate instructions only. Use this when it's important not
296 * to reference other data (i.e. on ppc64 when the TOC pointer is not
Paul Mackerrase31aa452008-08-30 11:41:12 +1000297 * valid) and when 'expr' is a constant or absolute address.
Kumar Gala5f7c6902005-09-09 15:02:25 -0500298 *
David Gibsone58c3492006-01-13 14:56:25 +1100299 * LOAD_REG_ADDR(rn, name)
300 * Loads the address of label 'name' into register 'rn'. Use this when
301 * you don't particularly need immediate instructions only, but you need
302 * the whole address in one register (e.g. it's a structure address and
303 * you want to access various offsets within it). On ppc32 this is
304 * identical to LOAD_REG_IMMEDIATE.
305 *
Kevin Hao1c49abe2013-12-24 15:12:05 +0800306 * LOAD_REG_ADDR_PIC(rn, name)
307 * Loads the address of label 'name' into register 'run'. Use this when
308 * the kernel doesn't run at the linked or relocated address. Please
309 * note that this macro will clobber the lr register.
310 *
David Gibsone58c3492006-01-13 14:56:25 +1100311 * LOAD_REG_ADDRBASE(rn, name)
312 * ADDROFF(name)
313 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
314 * register 'rn'. ADDROFF(name) returns the remainder of the address as
315 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
316 * in size, so is suitable for use directly as an offset in load and store
317 * instructions. Use this when loading/storing a single word or less as:
318 * LOAD_REG_ADDRBASE(rX, name)
319 * ld rY,ADDROFF(name)(rX)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500320 */
Kevin Hao1c49abe2013-12-24 15:12:05 +0800321
322/* Be careful, this will clobber the lr register. */
323#define LOAD_REG_ADDR_PIC(reg, name) \
324 bl 0f; \
3250: mflr reg; \
326 addis reg,reg,(name - 0b)@ha; \
327 addi reg,reg,(name - 0b)@l;
328
Kumar Gala5f7c6902005-09-09 15:02:25 -0500329#ifdef __powerpc64__
Guenter Roeck7998eb32014-05-15 09:33:42 -0700330#ifdef HAVE_AS_ATHIGH
331#define __AS_ATHIGH high
332#else
333#define __AS_ATHIGH h
334#endif
David Gibsone58c3492006-01-13 14:56:25 +1100335#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000336 lis reg,(expr)@highest; \
337 ori reg,reg,(expr)@higher; \
338 rldicr reg,reg,32,31; \
Guenter Roeck7998eb32014-05-15 09:33:42 -0700339 oris reg,reg,(expr)@__AS_ATHIGH; \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000340 ori reg,reg,(expr)@l;
Kumar Gala5f7c6902005-09-09 15:02:25 -0500341
David Gibsone58c3492006-01-13 14:56:25 +1100342#define LOAD_REG_ADDR(reg,name) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000343 ld reg,name@got(r2)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500344
David Gibsone58c3492006-01-13 14:56:25 +1100345#define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
346#define ADDROFF(name) 0
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000347
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000348/* offsets for stack frame layout */
349#define LRSAVE 16
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000350
351#else /* 32-bit */
Stephen Rothwell70620182005-10-12 17:44:55 +1000352
David Gibsone58c3492006-01-13 14:56:25 +1100353#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000354 lis reg,(expr)@ha; \
355 addi reg,reg,(expr)@l;
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000356
David Gibsone58c3492006-01-13 14:56:25 +1100357#define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
358
Michael Neuling564aa5c2012-06-25 13:33:09 +0000359#define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha
David Gibsone58c3492006-01-13 14:56:25 +1100360#define ADDROFF(name) name@l
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000361
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000362/* offsets for stack frame layout */
363#define LRSAVE 4
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000364
Kumar Gala5f7c6902005-09-09 15:02:25 -0500365#endif
366
367/* various errata or part fixups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#ifdef CONFIG_PPC601_SYNC_FIX
369#define SYNC \
370BEGIN_FTR_SECTION \
371 sync; \
372 isync; \
373END_FTR_SECTION_IFSET(CPU_FTR_601)
374#define SYNC_601 \
375BEGIN_FTR_SECTION \
376 sync; \
377END_FTR_SECTION_IFSET(CPU_FTR_601)
378#define ISYNC_601 \
379BEGIN_FTR_SECTION \
380 isync; \
381END_FTR_SECTION_IFSET(CPU_FTR_601)
382#else
383#define SYNC
384#define SYNC_601
385#define ISYNC_601
386#endif
387
Scott Woodd52459c2013-07-23 20:21:11 -0500388#if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000389#define MFTB(dest) \
Scott Woodbeb2dc02013-08-20 19:33:12 -050039090: mfspr dest, SPRN_TBRL; \
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000391BEGIN_FTR_SECTION_NESTED(96); \
392 cmpwi dest,0; \
393 beq- 90b; \
394END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
LEROY Christopheae2163b2013-11-22 17:57:31 +0100395#elif defined(CONFIG_8xx)
396#define MFTB(dest) mftb dest
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000397#else
Scott Woodbeb2dc02013-08-20 19:33:12 -0500398#define MFTB(dest) mfspr dest, SPRN_TBRL
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000399#endif
Kumar Gala5f7c6902005-09-09 15:02:25 -0500400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#ifndef CONFIG_SMP
402#define TLBSYNC
403#else /* CONFIG_SMP */
404/* tlbsync is not implemented on 601 */
405#define TLBSYNC \
406BEGIN_FTR_SECTION \
407 tlbsync; \
408 sync; \
409END_FTR_SECTION_IFCLR(CPU_FTR_601)
410#endif
411
Anton Blanchard694caf02012-04-18 02:21:52 +0000412#ifdef CONFIG_PPC64
413#define MTOCRF(FXM, RS) \
414 BEGIN_FTR_SECTION_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000415 mtcrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000416 FTR_SECTION_ELSE_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000417 mtocrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000418 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
419#endif
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421/*
422 * This instruction is not implemented on the PPC 603 or 601; however, on
423 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
424 * All of these instructions exist in the 8xx, they have magical powers,
425 * and they must be used.
426 */
427
428#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
429#define tlbia \
430 li r4,1024; \
431 mtctr r4; \
432 lis r4,KERNELBASE@h; \
Russell Curreye3824e42016-03-02 17:12:45 +1100433 .machine push; \
434 .machine "power4"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350: tlbie r4; \
Russell Curreye3824e42016-03-02 17:12:45 +1100436 .machine pop; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 addi r4,r4,0x1000; \
438 bdnz 0b
439#endif
440
Kumar Gala5f7c6902005-09-09 15:02:25 -0500441
Kumar Gala5f7c6902005-09-09 15:02:25 -0500442#ifdef CONFIG_IBM440EP_ERR42
443#define PPC440EP_ERR42 isync
444#else
445#define PPC440EP_ERR42
446#endif
447
Michael Neulinga5153482013-05-29 19:34:27 +0000448/* The following stops all load and store data streams associated with stream
449 * ID (ie. streams created explicitly). The embedded and server mnemonics for
450 * dcbt are different so we use machine "power4" here explicitly.
451 */
452#define DCBT_STOP_ALL_STREAM_IDS(scratch) \
453.machine push ; \
454.machine "power4" ; \
455 lis scratch,0x60000000@h; \
456 dcbt r0,scratch,0b01010; \
457.machine pop
458
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000459/*
460 * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
461 * keep the address intact to be compatible with code shared with
462 * 32-bit classic.
463 *
464 * On the other hand, I find it useful to have them behave as expected
465 * by their name (ie always do the addition) on 64-bit BookE
466 */
467#if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000468#define toreal(rd)
469#define fromreal(rd)
470
Roland McGrath2ca76332008-05-11 10:40:47 +1000471/*
472 * We use addis to ensure compatibility with the "classic" ppc versions of
473 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
474 * converting the address in r0, and so this version has to do that too
475 * (i.e. set register rd to 0 when rs == 0).
476 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define tophys(rd,rs) \
478 addis rd,rs,0
479
480#define tovirt(rd,rs) \
481 addis rd,rs,0
482
Kumar Gala5f7c6902005-09-09 15:02:25 -0500483#elif defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000484#define toreal(rd) /* we can access c000... in real mode */
485#define fromreal(rd)
486
Kumar Gala5f7c6902005-09-09 15:02:25 -0500487#define tophys(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000488 clrldi rd,rs,2
Kumar Gala5f7c6902005-09-09 15:02:25 -0500489
490#define tovirt(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000491 rotldi rd,rs,16; \
492 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
493 rotldi rd,rd,48
Kumar Gala5f7c6902005-09-09 15:02:25 -0500494#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495/*
496 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
497 * physical base address of RAM at compile time.
498 */
Paul Mackerras63162222005-10-27 22:44:39 +1000499#define toreal(rd) tophys(rd,rd)
500#define fromreal(rd) tovirt(rd,rd)
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#define tophys(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00005030: addis rd,rs,-PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .section ".vtop_fixup","aw"; \
505 .align 1; \
506 .long 0b; \
507 .previous
508
509#define tovirt(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00005100: addis rd,rs,PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .section ".ptov_fixup","aw"; \
512 .align 1; \
513 .long 0b; \
514 .previous
Kumar Gala5f7c6902005-09-09 15:02:25 -0500515#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000517#ifdef CONFIG_PPC_BOOK3S_64
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000518#define RFI rfid
519#define MTMSRD(r) mtmsrd r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000520#define MTMSR_EERI(reg) mtmsrd reg,1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#else
522#define FIX_SRR1(ra, rb)
523#ifndef CONFIG_40x
524#define RFI rfi
525#else
526#define RFI rfi; b . /* Prevent prefetch past rfi */
527#endif
528#define MTMSRD(r) mtmsr r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000529#define MTMSR_EERI(reg) mtmsr reg
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#define CLR_TOP32(r)
Matt Porterc9cf73a2005-07-31 22:34:52 -0700531#endif
532
Arnd Bergmann88ced032005-12-16 22:43:46 +0100533#endif /* __KERNEL__ */
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535/* The boring bits... */
536
537/* Condition Register Bit Fields */
538
539#define cr0 0
540#define cr1 1
541#define cr2 2
542#define cr3 3
543#define cr4 4
544#define cr5 5
545#define cr6 6
546#define cr7 7
547
548
Michael Neuling9a13a522012-06-25 13:33:12 +0000549/*
550 * General Purpose Registers (GPRs)
551 *
552 * The lower case r0-r31 should be used in preference to the upper
553 * case R0-R31 as they provide more error checking in the assembler.
554 * Use R0-31 only when really nessesary.
555 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Michael Neuling9a13a522012-06-25 13:33:12 +0000557#define r0 %r0
558#define r1 %r1
559#define r2 %r2
560#define r3 %r3
561#define r4 %r4
562#define r5 %r5
563#define r6 %r6
564#define r7 %r7
565#define r8 %r8
566#define r9 %r9
567#define r10 %r10
568#define r11 %r11
569#define r12 %r12
570#define r13 %r13
571#define r14 %r14
572#define r15 %r15
573#define r16 %r16
574#define r17 %r17
575#define r18 %r18
576#define r19 %r19
577#define r20 %r20
578#define r21 %r21
579#define r22 %r22
580#define r23 %r23
581#define r24 %r24
582#define r25 %r25
583#define r26 %r26
584#define r27 %r27
585#define r28 %r28
586#define r29 %r29
587#define r30 %r30
588#define r31 %r31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590
591/* Floating Point Registers (FPRs) */
592
593#define fr0 0
594#define fr1 1
595#define fr2 2
596#define fr3 3
597#define fr4 4
598#define fr5 5
599#define fr6 6
600#define fr7 7
601#define fr8 8
602#define fr9 9
603#define fr10 10
604#define fr11 11
605#define fr12 12
606#define fr13 13
607#define fr14 14
608#define fr15 15
609#define fr16 16
610#define fr17 17
611#define fr18 18
612#define fr19 19
613#define fr20 20
614#define fr21 21
615#define fr22 22
616#define fr23 23
617#define fr24 24
618#define fr25 25
619#define fr26 26
620#define fr27 27
621#define fr28 28
622#define fr29 29
623#define fr30 30
624#define fr31 31
625
Kumar Gala5f7c6902005-09-09 15:02:25 -0500626/* AltiVec Registers (VPRs) */
627
Anton Blanchardc2ce6f92015-02-10 09:51:22 +1100628#define v0 0
629#define v1 1
630#define v2 2
631#define v3 3
632#define v4 4
633#define v5 5
634#define v6 6
635#define v7 7
636#define v8 8
637#define v9 9
638#define v10 10
639#define v11 11
640#define v12 12
641#define v13 13
642#define v14 14
643#define v15 15
644#define v16 16
645#define v17 17
646#define v18 18
647#define v19 19
648#define v20 20
649#define v21 21
650#define v22 22
651#define v23 23
652#define v24 24
653#define v25 25
654#define v26 26
655#define v27 27
656#define v28 28
657#define v29 29
658#define v30 30
659#define v31 31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Michael Neuling72ffff52008-06-25 14:07:18 +1000661/* VSX Registers (VSRs) */
662
Anton Blancharddf99e6e2015-02-10 09:51:23 +1100663#define vs0 0
664#define vs1 1
665#define vs2 2
666#define vs3 3
667#define vs4 4
668#define vs5 5
669#define vs6 6
670#define vs7 7
671#define vs8 8
672#define vs9 9
673#define vs10 10
674#define vs11 11
675#define vs12 12
676#define vs13 13
677#define vs14 14
678#define vs15 15
679#define vs16 16
680#define vs17 17
681#define vs18 18
682#define vs19 19
683#define vs20 20
684#define vs21 21
685#define vs22 22
686#define vs23 23
687#define vs24 24
688#define vs25 25
689#define vs26 26
690#define vs27 27
691#define vs28 28
692#define vs29 29
693#define vs30 30
694#define vs31 31
695#define vs32 32
696#define vs33 33
697#define vs34 34
698#define vs35 35
699#define vs36 36
700#define vs37 37
701#define vs38 38
702#define vs39 39
703#define vs40 40
704#define vs41 41
705#define vs42 42
706#define vs43 43
707#define vs44 44
708#define vs45 45
709#define vs46 46
710#define vs47 47
711#define vs48 48
712#define vs49 49
713#define vs50 50
714#define vs51 51
715#define vs52 52
716#define vs53 53
717#define vs54 54
718#define vs55 55
719#define vs56 56
720#define vs57 57
721#define vs58 58
722#define vs59 59
723#define vs60 60
724#define vs61 61
725#define vs62 62
726#define vs63 63
Michael Neuling72ffff52008-06-25 14:07:18 +1000727
Kumar Gala5f7c6902005-09-09 15:02:25 -0500728/* SPE Registers (EVPRs) */
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#define evr0 0
731#define evr1 1
732#define evr2 2
733#define evr3 3
734#define evr4 4
735#define evr5 5
736#define evr6 6
737#define evr7 7
738#define evr8 8
739#define evr9 9
740#define evr10 10
741#define evr11 11
742#define evr12 12
743#define evr13 13
744#define evr14 14
745#define evr15 15
746#define evr16 16
747#define evr17 17
748#define evr18 18
749#define evr19 19
750#define evr20 20
751#define evr21 21
752#define evr22 22
753#define evr23 23
754#define evr24 24
755#define evr25 25
756#define evr26 26
757#define evr27 27
758#define evr28 28
759#define evr29 29
760#define evr30 30
761#define evr31 31
762
763/* some stab codes */
764#define N_FUN 36
765#define N_RSYM 64
766#define N_SLINE 68
767#define N_SO 100
Kumar Gala5f7c6902005-09-09 15:02:25 -0500768
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000769/*
770 * Create an endian fixup trampoline
771 *
772 * This starts with a "tdi 0,0,0x48" instruction which is
773 * essentially a "trap never", and thus akin to a nop.
774 *
775 * The opcode for this instruction read with the wrong endian
776 * however results in a b . + 8
777 *
778 * So essentially we use that trick to execute the following
779 * trampoline in "reverse endian" if we are running with the
780 * MSR_LE bit set the "wrong" way for whatever endianness the
781 * kernel is built for.
782 */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500783
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000784#ifdef CONFIG_PPC_BOOK3E
785#define FIXUP_ENDIAN
786#else
787#define FIXUP_ENDIAN \
788 tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
789 b $+36; /* Skip trampoline if endian is good */ \
790 .long 0x05009f42; /* bcl 20,31,$+4 */ \
791 .long 0xa602487d; /* mflr r10 */ \
792 .long 0x1c004a39; /* addi r10,r10,28 */ \
793 .long 0xa600607d; /* mfmsr r11 */ \
794 .long 0x01006b69; /* xori r11,r11,1 */ \
795 .long 0xa6035a7d; /* mtsrr0 r10 */ \
796 .long 0xa6037b7d; /* mtsrr1 r11 */ \
797 .long 0x2400004c /* rfid */
798#endif /* !CONFIG_PPC_BOOK3E */
799#endif /* __ASSEMBLY__ */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500800#endif /* _ASM_POWERPC_PPC_ASM_H */