blob: 1c538a9a11e09327a174b13ae5dffb3fdd0c1fc1 [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>
Christophe Leroy2c86cd12018-07-05 16:25:01 +000012#include <asm/feature-fixups.h>
Christophe Leroy1e688dd22021-04-13 16:38:10 +000013#include <asm/extable.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100014
Michael Ellermane3f2c6c2016-10-14 15:58:28 +110015#ifdef __ASSEMBLY__
David Gibson3ddfbcf2005-11-10 12:56:55 +110016
17#define SZL (BITS_PER_LONG/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*
20 * Macros for storing registers into and loading registers from
21 * exception frames.
22 */
Kumar Gala5f7c6902005-09-09 15:02:25 -050023#ifdef __powerpc64__
24#define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
25#define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
26#define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
27#define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
28#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
Christophe Leroya1f3ae32018-04-17 19:08:18 +020031#define SAVE_NVGPRS(base) stmw 13, GPR0+4*13(base)
32#define REST_NVGPRS(base) lmw 13, GPR0+4*13(base)
Kumar Gala5f7c6902005-09-09 15:02:25 -050033#endif
34
Kumar Gala5f7c6902005-09-09 15:02:25 -050035#define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
36#define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
37#define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
38#define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
39#define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
40#define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
41#define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
42#define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Paul Mackerrasde79f7b2013-09-10 20:20:42 +100044#define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
46#define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
47#define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
48#define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
49#define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +100050#define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
52#define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
53#define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
54#define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
55#define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
56
Paul Mackerrasde79f7b2013-09-10 20:20:42 +100057#define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -050058#define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
59#define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
60#define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
61#define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
62#define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +100063#define REST_VR(n,b,base) li b,16*(n); lvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -050064#define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
65#define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
66#define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
67#define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
68#define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Anton Blanchard926f1602013-09-23 12:04:39 +100070#ifdef __BIG_ENDIAN__
71#define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base)
72#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base)
73#else
74#define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \
75 STXVD2X(n,b,base); \
76 XXSWAPD(n,n)
77
78#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \
79 XXSWAPD(n,n)
80#endif
Michael Neuling72ffff52008-06-25 14:07:18 +100081/* Save the lower 32 VSRs in the thread VSR region */
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +110082#define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +100083#define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
84#define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
85#define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
86#define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
87#define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +110088#define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +100089#define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
90#define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
91#define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
92#define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
93#define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
Michael Neuling72ffff52008-06-25 14:07:18 +100094
Scott Woodc51584d2011-06-14 18:34:27 -050095/*
96 * b = base register for addressing, o = base offset from register of 1st EVR
97 * n = first EVR, s = scratch
98 */
99#define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b)
100#define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
101#define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
102#define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
103#define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
104#define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
105#define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n
106#define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
107#define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
108#define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
109#define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
110#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 -0700111
Michael Ellerman8c716322005-10-24 15:07:27 +1000112/* Macros to adjust thread priority for hardware multithreading */
113#define HMT_VERY_LOW or 31,31,31 # very low priority
114#define HMT_LOW or 1,1,1
115#define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
116#define HMT_MEDIUM or 2,2,2
117#define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
118#define HMT_HIGH or 3,3,3
Benjamin Herrenschmidt50fb8eb2011-01-12 17:41:28 +1100119#define HMT_EXTRA_HIGH or 7,7,7 # power7 only
Kumar Gala5f7c6902005-09-09 15:02:25 -0500120
Michael Neulingd72be892012-06-25 13:33:15 +0000121#ifdef CONFIG_PPC64
122#define ULONG_SIZE 8
123#else
124#define ULONG_SIZE 4
125#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000126#define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
127#define VCPU_GPR(n) __VCPU_GPR(__REG_##n)
Michael Neulingd72be892012-06-25 13:33:15 +0000128
Arnd Bergmann88ced032005-12-16 22:43:46 +0100129#ifdef __KERNEL__
Michael Ellerman2eda7f12020-12-18 22:16:19 +1100130
131/*
132 * We use __powerpc64__ here because we want the compat VDSO to use the 32-bit
133 * version below in the else case of the ifdef.
134 */
135#ifdef __powerpc64__
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000136
Michael Neuling44ce6a52012-06-25 13:33:14 +0000137#define STACKFRAMESIZE 256
Michael Neuling0b7673c2012-06-25 13:33:23 +0000138#define __STK_REG(i) (112 + ((i)-14)*8)
139#define STK_REG(i) __STK_REG(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000140
Michael Ellermanf55d9662016-06-06 22:26:10 +0530141#ifdef PPC64_ELF_ABI_v2
Anton Blanchard64031052014-03-10 10:52:17 +1100142#define STK_GOT 24
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100143#define __STK_PARAM(i) (32 + ((i)-3)*8)
144#else
Anton Blanchard64031052014-03-10 10:52:17 +1100145#define STK_GOT 40
Michael Neuling0b7673c2012-06-25 13:33:23 +0000146#define __STK_PARAM(i) (48 + ((i)-3)*8)
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100147#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000148#define STK_PARAM(i) __STK_PARAM(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000149
Michael Ellermanf55d9662016-06-06 22:26:10 +0530150#ifdef PPC64_ELF_ABI_v2
Anton Blanchard7167af72014-02-04 16:07:20 +1100151
152#define _GLOBAL(name) \
Anton Blanchard7167af72014-02-04 16:07:20 +1100153 .align 2 ; \
154 .type name,@function; \
155 .globl name; \
156name:
157
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100158#define _GLOBAL_TOC(name) \
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100159 .align 2 ; \
160 .type name,@function; \
161 .globl name; \
162name: \
1630: addis r2,r12,(.TOC.-0b)@ha; \
164 addi r2,r2,(.TOC.-0b)@l; \
165 .localentry name,.-name
166
Anton Blanchard7167af72014-02-04 16:07:20 +1100167#define DOTSYM(a) a
168
169#else
170
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000171#define XGLUE(a,b) a##b
172#define GLUE(a,b) XGLUE(a,b)
173
174#define _GLOBAL(name) \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000175 .align 2 ; \
176 .globl name; \
177 .globl GLUE(.,name); \
Michael Ellermanbea2dcc2016-09-15 10:40:20 +1000178 .pushsection ".opd","aw"; \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000179name: \
180 .quad GLUE(.,name); \
181 .quad .TOC.@tocbase; \
182 .quad 0; \
Michael Ellermanbea2dcc2016-09-15 10:40:20 +1000183 .popsection; \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000184 .type GLUE(.,name),@function; \
185GLUE(.,name):
186
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100187#define _GLOBAL_TOC(name) _GLOBAL(name)
188
Anton Blanchardc1fb0192014-02-04 16:07:01 +1100189#define DOTSYM(a) GLUE(.,a)
190
Anton Blanchard7167af72014-02-04 16:07:20 +1100191#endif
192
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000193#else /* 32-bit */
194
Kumar Gala748a7682007-09-13 15:42:35 -0500195#define _ENTRY(n) \
196 .globl n; \
197n:
198
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000199#define _GLOBAL(n) \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000200 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
201 .globl n; \
202n:
203
Alexander Graf9715a2e2014-06-26 13:19:40 +0200204#define _GLOBAL_TOC(name) _GLOBAL(name)
205
Christophe Leroyce7d8052020-11-27 00:10:03 +1100206#define DOTSYM(a) a
207
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000208#endif
209
Nicholas Piggin6f698df2016-09-16 20:48:17 +1000210/*
211 * __kprobes (the C annotation) puts the symbol into the .kprobes.text
212 * section, which gets emitted at the end of regular text.
213 *
214 * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
215 * a blacklist. The former is for core kprobe functions/data, the
216 * latter is for those that incdentially must be excluded from probing
217 * and allows them to be linked at more optimal location within text.
218 */
Nicholas Pigginc0a51492016-10-13 13:07:14 +1100219#ifdef CONFIG_KPROBES
Nicholas Piggin6f698df2016-09-16 20:48:17 +1000220#define _ASM_NOKPROBE_SYMBOL(entry) \
221 .pushsection "_kprobe_blacklist","aw"; \
222 PPC_LONG (entry) ; \
223 .popsection
Nicholas Pigginc0a51492016-10-13 13:07:14 +1100224#else
225#define _ASM_NOKPROBE_SYMBOL(entry)
226#endif
Nicholas Piggin6f698df2016-09-16 20:48:17 +1000227
Anton Blanchard151f2512016-07-01 08:19:44 +1000228#define FUNC_START(name) _GLOBAL(name)
229#define FUNC_END(name)
230
Kumar Gala5f7c6902005-09-09 15:02:25 -0500231/*
David Gibsone58c3492006-01-13 14:56:25 +1100232 * LOAD_REG_IMMEDIATE(rn, expr)
233 * Loads the value of the constant expression 'expr' into register 'rn'
234 * using immediate instructions only. Use this when it's important not
235 * to reference other data (i.e. on ppc64 when the TOC pointer is not
Paul Mackerrase31aa452008-08-30 11:41:12 +1000236 * valid) and when 'expr' is a constant or absolute address.
Kumar Gala5f7c6902005-09-09 15:02:25 -0500237 *
David Gibsone58c3492006-01-13 14:56:25 +1100238 * LOAD_REG_ADDR(rn, name)
239 * Loads the address of label 'name' into register 'rn'. Use this when
240 * you don't particularly need immediate instructions only, but you need
241 * the whole address in one register (e.g. it's a structure address and
242 * you want to access various offsets within it). On ppc32 this is
243 * identical to LOAD_REG_IMMEDIATE.
244 *
Kevin Hao1c49abe2013-12-24 15:12:05 +0800245 * LOAD_REG_ADDR_PIC(rn, name)
246 * Loads the address of label 'name' into register 'run'. Use this when
247 * the kernel doesn't run at the linked or relocated address. Please
248 * note that this macro will clobber the lr register.
249 *
David Gibsone58c3492006-01-13 14:56:25 +1100250 * LOAD_REG_ADDRBASE(rn, name)
251 * ADDROFF(name)
252 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
253 * register 'rn'. ADDROFF(name) returns the remainder of the address as
254 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
255 * in size, so is suitable for use directly as an offset in load and store
256 * instructions. Use this when loading/storing a single word or less as:
257 * LOAD_REG_ADDRBASE(rX, name)
258 * ld rY,ADDROFF(name)(rX)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500259 */
Kevin Hao1c49abe2013-12-24 15:12:05 +0800260
261/* Be careful, this will clobber the lr register. */
262#define LOAD_REG_ADDR_PIC(reg, name) \
Christophe Leroyf5007db2021-08-24 07:56:26 +0000263 bcl 20,31,$+4; \
Kevin Hao1c49abe2013-12-24 15:12:05 +08002640: mflr reg; \
265 addis reg,reg,(name - 0b)@ha; \
266 addi reg,reg,(name - 0b)@l;
267
Christophe Leroyc691b4b2019-08-20 14:34:12 +0000268#if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH)
Guenter Roeck7998eb32014-05-15 09:33:42 -0700269#define __AS_ATHIGH high
270#else
271#define __AS_ATHIGH h
272#endif
Christophe Leroyc691b4b2019-08-20 14:34:12 +0000273
274.macro __LOAD_REG_IMMEDIATE_32 r, x
275 .if (\x) >= 0x8000 || (\x) < -0x8000
276 lis \r, (\x)@__AS_ATHIGH
277 .if (\x) & 0xffff != 0
278 ori \r, \r, (\x)@l
279 .endif
280 .else
281 li \r, (\x)@l
282 .endif
283.endm
284
285.macro __LOAD_REG_IMMEDIATE r, x
286 .if (\x) >= 0x80000000 || (\x) < -0x80000000
287 __LOAD_REG_IMMEDIATE_32 \r, (\x) >> 32
288 sldi \r, \r, 32
289 .if (\x) & 0xffff0000 != 0
290 oris \r, \r, (\x)@__AS_ATHIGH
291 .endif
292 .if (\x) & 0xffff != 0
293 ori \r, \r, (\x)@l
294 .endif
295 .else
296 __LOAD_REG_IMMEDIATE_32 \r, \x
297 .endif
298.endm
299
300#ifdef __powerpc64__
301
302#define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE reg, expr
303
Christophe Leroyd7fb5b12019-08-20 14:34:14 +0000304#define LOAD_REG_IMMEDIATE_SYM(reg, tmp, expr) \
305 lis tmp, (expr)@highest; \
306 lis reg, (expr)@__AS_ATHIGH; \
307 ori tmp, tmp, (expr)@higher; \
308 ori reg, reg, (expr)@l; \
309 rldimi reg, tmp, 32, 0
Kumar Gala5f7c6902005-09-09 15:02:25 -0500310
David Gibsone58c3492006-01-13 14:56:25 +1100311#define LOAD_REG_ADDR(reg,name) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000312 ld reg,name@got(r2)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500313
David Gibsone58c3492006-01-13 14:56:25 +1100314#define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
315#define ADDROFF(name) 0
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000316
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000317/* offsets for stack frame layout */
318#define LRSAVE 16
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000319
320#else /* 32-bit */
Stephen Rothwell70620182005-10-12 17:44:55 +1000321
Christophe Leroyc691b4b2019-08-20 14:34:12 +0000322#define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr
323
324#define LOAD_REG_IMMEDIATE_SYM(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000325 lis reg,(expr)@ha; \
326 addi reg,reg,(expr)@l;
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000327
Christophe Leroyc691b4b2019-08-20 14:34:12 +0000328#define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE_SYM(reg, name)
David Gibsone58c3492006-01-13 14:56:25 +1100329
Michael Neuling564aa5c2012-06-25 13:33:09 +0000330#define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha
David Gibsone58c3492006-01-13 14:56:25 +1100331#define ADDROFF(name) name@l
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000332
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000333/* offsets for stack frame layout */
334#define LRSAVE 4
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000335
Kumar Gala5f7c6902005-09-09 15:02:25 -0500336#endif
337
338/* various errata or part fixups */
Scott Woodd52459c2013-07-23 20:21:11 -0500339#if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000340#define MFTB(dest) \
Scott Woodbeb2dc02013-08-20 19:33:12 -050034190: mfspr dest, SPRN_TBRL; \
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000342BEGIN_FTR_SECTION_NESTED(96); \
343 cmpwi dest,0; \
344 beq- 90b; \
345END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
346#else
Christophe Leroy72e4b2c2017-08-08 13:58:50 +0200347#define MFTB(dest) MFTBL(dest)
348#endif
349
350#ifdef CONFIG_PPC_8xx
351#define MFTBL(dest) mftb dest
352#define MFTBU(dest) mftbu dest
353#else
354#define MFTBL(dest) mfspr dest, SPRN_TBRL
355#define MFTBU(dest) mfspr dest, SPRN_TBRU
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000356#endif
Kumar Gala5f7c6902005-09-09 15:02:25 -0500357
Christophe Leroy8b14e1d2020-09-29 06:48:36 +0000358#ifndef CONFIG_SMP
Christophe Leroy12c3f1f2019-08-26 15:52:14 +0000359#define TLBSYNC
360#else
361#define TLBSYNC tlbsync; sync
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#endif
363
Anton Blanchard694caf02012-04-18 02:21:52 +0000364#ifdef CONFIG_PPC64
365#define MTOCRF(FXM, RS) \
366 BEGIN_FTR_SECTION_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000367 mtcrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000368 FTR_SECTION_ELSE_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000369 mtocrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000370 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
371#endif
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373/*
374 * This instruction is not implemented on the PPC 603 or 601; however, on
375 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
376 * All of these instructions exist in the 8xx, they have magical powers,
377 * and they must be used.
378 */
379
Christophe Leroy968159c2017-08-08 13:58:54 +0200380#if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#define tlbia \
382 li r4,1024; \
383 mtctr r4; \
384 lis r4,KERNELBASE@h; \
Russell Curreye3824e42016-03-02 17:12:45 +1100385 .machine push; \
386 .machine "power4"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870: tlbie r4; \
Russell Curreye3824e42016-03-02 17:12:45 +1100388 .machine pop; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 addi r4,r4,0x1000; \
390 bdnz 0b
391#endif
392
Kumar Gala5f7c6902005-09-09 15:02:25 -0500393
Kumar Gala5f7c6902005-09-09 15:02:25 -0500394#ifdef CONFIG_IBM440EP_ERR42
395#define PPC440EP_ERR42 isync
396#else
397#define PPC440EP_ERR42
398#endif
399
Michael Neulinga5153482013-05-29 19:34:27 +0000400/* The following stops all load and store data streams associated with stream
401 * ID (ie. streams created explicitly). The embedded and server mnemonics for
Nicholas Piggin15a32042018-02-21 05:08:26 +1000402 * dcbt are different so this must only be used for server.
Michael Neulinga5153482013-05-29 19:34:27 +0000403 */
Nicholas Piggin15a32042018-02-21 05:08:26 +1000404#define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch) \
405 lis scratch,0x60000000@h; \
406 dcbt 0,scratch,0b01010
Michael Neulinga5153482013-05-29 19:34:27 +0000407
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000408/*
409 * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
410 * keep the address intact to be compatible with code shared with
411 * 32-bit classic.
412 *
413 * On the other hand, I find it useful to have them behave as expected
414 * by their name (ie always do the addition) on 64-bit BookE
415 */
416#if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000417#define toreal(rd)
418#define fromreal(rd)
419
Roland McGrath2ca76332008-05-11 10:40:47 +1000420/*
421 * We use addis to ensure compatibility with the "classic" ppc versions of
422 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
423 * converting the address in r0, and so this version has to do that too
424 * (i.e. set register rd to 0 when rs == 0).
425 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define tophys(rd,rs) \
427 addis rd,rs,0
428
429#define tovirt(rd,rs) \
430 addis rd,rs,0
431
Kumar Gala5f7c6902005-09-09 15:02:25 -0500432#elif defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000433#define toreal(rd) /* we can access c000... in real mode */
434#define fromreal(rd)
435
Kumar Gala5f7c6902005-09-09 15:02:25 -0500436#define tophys(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000437 clrldi rd,rs,2
Kumar Gala5f7c6902005-09-09 15:02:25 -0500438
439#define tovirt(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000440 rotldi rd,rs,16; \
441 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
442 rotldi rd,rd,48
Kumar Gala5f7c6902005-09-09 15:02:25 -0500443#else
Paul Mackerras63162222005-10-27 22:44:39 +1000444#define toreal(rd) tophys(rd,rd)
445#define fromreal(rd) tovirt(rd,rd)
446
Christophe Leroyc62ce9e2018-12-04 17:59:15 +0000447#define tophys(rd, rs) addis rd, rs, -PAGE_OFFSET@h
448#define tovirt(rd, rs) addis rd, rs, PAGE_OFFSET@h
Kumar Gala5f7c6902005-09-09 15:02:25 -0500449#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000451#ifdef CONFIG_PPC_BOOK3S_64
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000452#define MTMSRD(r) mtmsrd r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000453#define MTMSR_EERI(reg) mtmsrd reg,1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define MTMSRD(r) mtmsr r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000456#define MTMSR_EERI(reg) mtmsr reg
Matt Porterc9cf73a2005-07-31 22:34:52 -0700457#endif
458
Arnd Bergmann88ced032005-12-16 22:43:46 +0100459#endif /* __KERNEL__ */
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/* The boring bits... */
462
463/* Condition Register Bit Fields */
464
465#define cr0 0
466#define cr1 1
467#define cr2 2
468#define cr3 3
469#define cr4 4
470#define cr5 5
471#define cr6 6
472#define cr7 7
473
474
Michael Neuling9a13a522012-06-25 13:33:12 +0000475/*
476 * General Purpose Registers (GPRs)
477 *
478 * The lower case r0-r31 should be used in preference to the upper
479 * case R0-R31 as they provide more error checking in the assembler.
480 * Use R0-31 only when really nessesary.
481 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Michael Neuling9a13a522012-06-25 13:33:12 +0000483#define r0 %r0
484#define r1 %r1
485#define r2 %r2
486#define r3 %r3
487#define r4 %r4
488#define r5 %r5
489#define r6 %r6
490#define r7 %r7
491#define r8 %r8
492#define r9 %r9
493#define r10 %r10
494#define r11 %r11
495#define r12 %r12
496#define r13 %r13
497#define r14 %r14
498#define r15 %r15
499#define r16 %r16
500#define r17 %r17
501#define r18 %r18
502#define r19 %r19
503#define r20 %r20
504#define r21 %r21
505#define r22 %r22
506#define r23 %r23
507#define r24 %r24
508#define r25 %r25
509#define r26 %r26
510#define r27 %r27
511#define r28 %r28
512#define r29 %r29
513#define r30 %r30
514#define r31 %r31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516
517/* Floating Point Registers (FPRs) */
518
519#define fr0 0
520#define fr1 1
521#define fr2 2
522#define fr3 3
523#define fr4 4
524#define fr5 5
525#define fr6 6
526#define fr7 7
527#define fr8 8
528#define fr9 9
529#define fr10 10
530#define fr11 11
531#define fr12 12
532#define fr13 13
533#define fr14 14
534#define fr15 15
535#define fr16 16
536#define fr17 17
537#define fr18 18
538#define fr19 19
539#define fr20 20
540#define fr21 21
541#define fr22 22
542#define fr23 23
543#define fr24 24
544#define fr25 25
545#define fr26 26
546#define fr27 27
547#define fr28 28
548#define fr29 29
549#define fr30 30
550#define fr31 31
551
Kumar Gala5f7c6902005-09-09 15:02:25 -0500552/* AltiVec Registers (VPRs) */
553
Anton Blanchardc2ce6f92015-02-10 09:51:22 +1100554#define v0 0
555#define v1 1
556#define v2 2
557#define v3 3
558#define v4 4
559#define v5 5
560#define v6 6
561#define v7 7
562#define v8 8
563#define v9 9
564#define v10 10
565#define v11 11
566#define v12 12
567#define v13 13
568#define v14 14
569#define v15 15
570#define v16 16
571#define v17 17
572#define v18 18
573#define v19 19
574#define v20 20
575#define v21 21
576#define v22 22
577#define v23 23
578#define v24 24
579#define v25 25
580#define v26 26
581#define v27 27
582#define v28 28
583#define v29 29
584#define v30 30
585#define v31 31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Michael Neuling72ffff52008-06-25 14:07:18 +1000587/* VSX Registers (VSRs) */
588
Anton Blancharddf99e6e2015-02-10 09:51:23 +1100589#define vs0 0
590#define vs1 1
591#define vs2 2
592#define vs3 3
593#define vs4 4
594#define vs5 5
595#define vs6 6
596#define vs7 7
597#define vs8 8
598#define vs9 9
599#define vs10 10
600#define vs11 11
601#define vs12 12
602#define vs13 13
603#define vs14 14
604#define vs15 15
605#define vs16 16
606#define vs17 17
607#define vs18 18
608#define vs19 19
609#define vs20 20
610#define vs21 21
611#define vs22 22
612#define vs23 23
613#define vs24 24
614#define vs25 25
615#define vs26 26
616#define vs27 27
617#define vs28 28
618#define vs29 29
619#define vs30 30
620#define vs31 31
621#define vs32 32
622#define vs33 33
623#define vs34 34
624#define vs35 35
625#define vs36 36
626#define vs37 37
627#define vs38 38
628#define vs39 39
629#define vs40 40
630#define vs41 41
631#define vs42 42
632#define vs43 43
633#define vs44 44
634#define vs45 45
635#define vs46 46
636#define vs47 47
637#define vs48 48
638#define vs49 49
639#define vs50 50
640#define vs51 51
641#define vs52 52
642#define vs53 53
643#define vs54 54
644#define vs55 55
645#define vs56 56
646#define vs57 57
647#define vs58 58
648#define vs59 59
649#define vs60 60
650#define vs61 61
651#define vs62 62
652#define vs63 63
Michael Neuling72ffff52008-06-25 14:07:18 +1000653
Kumar Gala5f7c6902005-09-09 15:02:25 -0500654/* SPE Registers (EVPRs) */
655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656#define evr0 0
657#define evr1 1
658#define evr2 2
659#define evr3 3
660#define evr4 4
661#define evr5 5
662#define evr6 6
663#define evr7 7
664#define evr8 8
665#define evr9 9
666#define evr10 10
667#define evr11 11
668#define evr12 12
669#define evr13 13
670#define evr14 14
671#define evr15 15
672#define evr16 16
673#define evr17 17
674#define evr18 18
675#define evr19 19
676#define evr20 20
677#define evr21 21
678#define evr22 22
679#define evr23 23
680#define evr24 24
681#define evr25 25
682#define evr26 26
683#define evr27 27
684#define evr28 28
685#define evr29 29
686#define evr30 30
687#define evr31 31
688
689/* some stab codes */
690#define N_FUN 36
691#define N_RSYM 64
692#define N_SLINE 68
693#define N_SO 100
Kumar Gala5f7c6902005-09-09 15:02:25 -0500694
Nicholas Piggin7fa95f92020-06-11 18:12:03 +1000695#define RFSCV .long 0x4c0000a4
696
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000697/*
698 * Create an endian fixup trampoline
699 *
700 * This starts with a "tdi 0,0,0x48" instruction which is
701 * essentially a "trap never", and thus akin to a nop.
702 *
703 * The opcode for this instruction read with the wrong endian
704 * however results in a b . + 8
705 *
706 * So essentially we use that trick to execute the following
707 * trampoline in "reverse endian" if we are running with the
708 * MSR_LE bit set the "wrong" way for whatever endianness the
709 * kernel is built for.
710 */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500711
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000712#ifdef CONFIG_PPC_BOOK3E
713#define FIXUP_ENDIAN
714#else
Nicholas Piggin8ca9c082017-10-23 17:08:14 +1000715/*
Randy Dunlapdb10f552020-07-25 17:38:06 -0700716 * This version may be used in HV or non-HV context.
Nicholas Piggin8ca9c082017-10-23 17:08:14 +1000717 * MSR[EE] must be disabled.
718 */
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000719#define FIXUP_ENDIAN \
720 tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
Nicholas Pigginf848ea72017-10-23 17:08:13 +1000721 b 191f; /* Skip trampoline if endian is good */ \
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000722 .long 0xa600607d; /* mfmsr r11 */ \
723 .long 0x01006b69; /* xori r11,r11,1 */ \
Nicholas Pigginf1fe5252017-05-01 22:01:09 +1000724 .long 0x00004039; /* li r10,0 */ \
725 .long 0x6401417d; /* mtmsrd r10,1 */ \
726 .long 0x05009f42; /* bcl 20,31,$+4 */ \
727 .long 0xa602487d; /* mflr r10 */ \
728 .long 0x14004a39; /* addi r10,r10,20 */ \
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000729 .long 0xa6035a7d; /* mtsrr0 r10 */ \
730 .long 0xa6037b7d; /* mtsrr1 r11 */ \
Nicholas Pigginf848ea72017-10-23 17:08:13 +1000731 .long 0x2400004c; /* rfid */ \
732191:
Nicholas Pigginf1fe5252017-05-01 22:01:09 +1000733
Nicholas Piggin8ca9c082017-10-23 17:08:14 +1000734/*
735 * This version that may only be used with MSR[HV]=1
736 * - Does not clear MSR[RI], so more robust.
737 * - Slightly smaller and faster.
738 */
739#define FIXUP_ENDIAN_HV \
740 tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
741 b 191f; /* Skip trampoline if endian is good */ \
742 .long 0xa600607d; /* mfmsr r11 */ \
743 .long 0x01006b69; /* xori r11,r11,1 */ \
744 .long 0x05009f42; /* bcl 20,31,$+4 */ \
745 .long 0xa602487d; /* mflr r10 */ \
746 .long 0x14004a39; /* addi r10,r10,20 */ \
747 .long 0xa64b5a7d; /* mthsrr0 r10 */ \
748 .long 0xa64b7b7d; /* mthsrr1 r11 */ \
749 .long 0x2402004c; /* hrfid */ \
750191:
751
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000752#endif /* !CONFIG_PPC_BOOK3E */
Michael Ellermane3f2c6c2016-10-14 15:58:28 +1100753
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000754#endif /* __ASSEMBLY__ */
Michael Ellermane3f2c6c2016-10-14 15:58:28 +1100755
Nicholas Piggin325678f2021-06-30 17:46:16 +1000756#define SOFT_MASK_TABLE(_start, _end) \
757 stringify_in_c(.section __soft_mask_table,"a";)\
758 stringify_in_c(.balign 8;) \
759 stringify_in_c(.llong (_start);) \
760 stringify_in_c(.llong (_end);) \
761 stringify_in_c(.previous)
762
Nicholas Pigginf23699c2021-06-18 01:51:08 +1000763#define RESTART_TABLE(_start, _end, _target) \
764 stringify_in_c(.section __restart_table,"a";)\
765 stringify_in_c(.balign 8;) \
766 stringify_in_c(.llong (_start);) \
767 stringify_in_c(.llong (_end);) \
768 stringify_in_c(.llong (_target);) \
769 stringify_in_c(.previous)
770
Diana Craciun1cbf8992018-12-12 16:03:01 +0200771#ifdef CONFIG_PPC_FSL_BOOK3E
772#define BTB_FLUSH(reg) \
773 lis reg,BUCSR_INIT@h; \
774 ori reg,reg,BUCSR_INIT@l; \
775 mtspr SPRN_BUCSR,reg; \
776 isync;
777#else
778#define BTB_FLUSH(reg)
779#endif /* CONFIG_PPC_FSL_BOOK3E */
780
Kumar Gala5f7c6902005-09-09 15:02:25 -0500781#endif /* _ASM_POWERPC_PPC_ASM_H */