blob: 28ab87e5b739397f748585a8b6731e30830f7ac4 [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
Michael Ellermane3f2c6c2016-10-14 15:58:28 +110013#ifdef __ASSEMBLY__
David Gibson3ddfbcf2005-11-10 12:56:55 +110014
15#define SZL (BITS_PER_LONG/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/*
Paul Mackerrasc6622f62006-02-24 10:06:59 +110018 * Stuff for accurate CPU time accounting.
19 * These macros handle transitions between user and system state
20 * in exception entry and exit and accumulate time to the
21 * user_time and system_time fields in the paca.
22 */
23
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020024#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
Christophe Leroyc223c902016-05-17 08:33:46 +020025#define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb)
26#define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb)
Paul Mackerrascf9efce2010-08-26 19:56:43 +000027#define ACCOUNT_STOLEN_TIME
Paul Mackerrasc6622f62006-02-24 10:06:59 +110028#else
Christophe Leroyc223c902016-05-17 08:33:46 +020029#define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000030 MFTB(ra); /* get timebase */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020031 PPC_LL rb, ACCOUNT_STARTTIME_USER(ptr); \
32 PPC_STL ra, ACCOUNT_STARTTIME(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110033 subf rb,rb,ra; /* subtract start value */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020034 PPC_LL ra, ACCOUNT_USER_TIME(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110035 add ra,ra,rb; /* add on to user time */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020036 PPC_STL ra, ACCOUNT_USER_TIME(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110037
Christophe Leroyc223c902016-05-17 08:33:46 +020038#define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb) \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000039 MFTB(ra); /* get timebase */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020040 PPC_LL rb, ACCOUNT_STARTTIME(ptr); \
41 PPC_STL ra, ACCOUNT_STARTTIME_USER(ptr); \
Paul Mackerrasc6622f62006-02-24 10:06:59 +110042 subf rb,rb,ra; /* subtract start value */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020043 PPC_LL ra, ACCOUNT_SYSTEM_TIME(ptr); \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000044 add ra,ra,rb; /* add on to system time */ \
Christophe Leroyc223c902016-05-17 08:33:46 +020045 PPC_STL ra, ACCOUNT_SYSTEM_TIME(ptr)
Paul Mackerrascf9efce2010-08-26 19:56:43 +000046
47#ifdef CONFIG_PPC_SPLPAR
48#define ACCOUNT_STOLEN_TIME \
49BEGIN_FW_FTR_SECTION; \
50 beq 33f; \
51 /* from user - see if there are any DTL entries to process */ \
52 ld r10,PACALPPACAPTR(r13); /* get ptr to VPA */ \
53 ld r11,PACA_DTL_RIDX(r13); /* get log read index */ \
Anton Blanchard7ffcf8e2013-08-07 02:01:46 +100054 addi r10,r10,LPPACA_DTLIDX; \
55 LDX_BE r10,0,r10; /* get log write index */ \
Paul Mackerrascf9efce2010-08-26 19:56:43 +000056 cmpd cr1,r11,r10; \
57 beq+ cr1,33f; \
Anton Blanchardb1576fe2014-02-04 16:04:35 +110058 bl accumulate_stolen_time; \
Benjamin Herrenschmidt990118c2012-03-02 11:01:31 +110059 ld r12,_MSR(r1); \
60 andi. r10,r12,MSR_PR; /* Restore cr0 (coming from user) */ \
Paul Mackerrascf9efce2010-08-26 19:56:43 +00006133: \
62END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
63
64#else /* CONFIG_PPC_SPLPAR */
65#define ACCOUNT_STOLEN_TIME
66
67#endif /* CONFIG_PPC_SPLPAR */
68
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020069#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
Paul Mackerrasc6622f62006-02-24 10:06:59 +110070
71/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * Macros for storing registers into and loading registers from
73 * exception frames.
74 */
Kumar Gala5f7c6902005-09-09 15:02:25 -050075#ifdef __powerpc64__
76#define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
77#define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
78#define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
79#define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
80#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
84 SAVE_10GPRS(22, base)
85#define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
86 REST_10GPRS(22, base)
Kumar Gala5f7c6902005-09-09 15:02:25 -050087#endif
88
Kumar Gala5f7c6902005-09-09 15:02:25 -050089#define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
90#define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
91#define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
92#define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
93#define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
94#define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
95#define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
96#define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Paul Mackerrasde79f7b2013-09-10 20:20:42 +100098#define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
100#define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
101#define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
102#define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
103#define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000104#define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
106#define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
107#define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
108#define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
109#define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
110
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000111#define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -0500112#define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
113#define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
114#define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
115#define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
116#define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000117#define REST_VR(n,b,base) li b,16*(n); lvx n,base,b
Kumar Gala5f7c6902005-09-09 15:02:25 -0500118#define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
119#define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
120#define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
121#define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
122#define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Anton Blanchard926f1602013-09-23 12:04:39 +1000124#ifdef __BIG_ENDIAN__
125#define STXVD2X_ROT(n,b,base) STXVD2X(n,b,base)
126#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base)
127#else
128#define STXVD2X_ROT(n,b,base) XXSWAPD(n,n); \
129 STXVD2X(n,b,base); \
130 XXSWAPD(n,n)
131
132#define LXVD2X_ROT(n,b,base) LXVD2X(n,b,base); \
133 XXSWAPD(n,n)
134#endif
Michael Neuling72ffff52008-06-25 14:07:18 +1000135/* Save the lower 32 VSRs in the thread VSR region */
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100136#define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +1000137#define SAVE_2VSRS(n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
138#define SAVE_4VSRS(n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
139#define SAVE_8VSRS(n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
140#define SAVE_16VSRS(n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
141#define SAVE_32VSRS(n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100142#define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b)
Michael Neuling72ffff52008-06-25 14:07:18 +1000143#define REST_2VSRS(n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)
144#define REST_4VSRS(n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
145#define REST_8VSRS(n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
146#define REST_16VSRS(n,b,base) REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
147#define REST_32VSRS(n,b,base) REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
Michael Neuling72ffff52008-06-25 14:07:18 +1000148
Scott Woodc51584d2011-06-14 18:34:27 -0500149/*
150 * b = base register for addressing, o = base offset from register of 1st EVR
151 * n = first EVR, s = scratch
152 */
153#define SAVE_EVR(n,s,b,o) evmergehi s,s,n; stw s,o+4*(n)(b)
154#define SAVE_2EVRS(n,s,b,o) SAVE_EVR(n,s,b,o); SAVE_EVR(n+1,s,b,o)
155#define SAVE_4EVRS(n,s,b,o) SAVE_2EVRS(n,s,b,o); SAVE_2EVRS(n+2,s,b,o)
156#define SAVE_8EVRS(n,s,b,o) SAVE_4EVRS(n,s,b,o); SAVE_4EVRS(n+4,s,b,o)
157#define SAVE_16EVRS(n,s,b,o) SAVE_8EVRS(n,s,b,o); SAVE_8EVRS(n+8,s,b,o)
158#define SAVE_32EVRS(n,s,b,o) SAVE_16EVRS(n,s,b,o); SAVE_16EVRS(n+16,s,b,o)
159#define REST_EVR(n,s,b,o) lwz s,o+4*(n)(b); evmergelo n,s,n
160#define REST_2EVRS(n,s,b,o) REST_EVR(n,s,b,o); REST_EVR(n+1,s,b,o)
161#define REST_4EVRS(n,s,b,o) REST_2EVRS(n,s,b,o); REST_2EVRS(n+2,s,b,o)
162#define REST_8EVRS(n,s,b,o) REST_4EVRS(n,s,b,o); REST_4EVRS(n+4,s,b,o)
163#define REST_16EVRS(n,s,b,o) REST_8EVRS(n,s,b,o); REST_8EVRS(n+8,s,b,o)
164#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 -0700165
Michael Ellerman8c716322005-10-24 15:07:27 +1000166/* Macros to adjust thread priority for hardware multithreading */
167#define HMT_VERY_LOW or 31,31,31 # very low priority
168#define HMT_LOW or 1,1,1
169#define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
170#define HMT_MEDIUM or 2,2,2
171#define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
172#define HMT_HIGH or 3,3,3
Benjamin Herrenschmidt50fb8eb2011-01-12 17:41:28 +1100173#define HMT_EXTRA_HIGH or 7,7,7 # power7 only
Kumar Gala5f7c6902005-09-09 15:02:25 -0500174
Michael Neulingd72be892012-06-25 13:33:15 +0000175#ifdef CONFIG_PPC64
176#define ULONG_SIZE 8
177#else
178#define ULONG_SIZE 4
179#endif
Michael Neuling0b7673c2012-06-25 13:33:23 +0000180#define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
181#define VCPU_GPR(n) __VCPU_GPR(__REG_##n)
Michael Neulingd72be892012-06-25 13:33:15 +0000182
Arnd Bergmann88ced032005-12-16 22:43:46 +0100183#ifdef __KERNEL__
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000184#ifdef CONFIG_PPC64
185
Michael Neuling44ce6a52012-06-25 13:33:14 +0000186#define STACKFRAMESIZE 256
Michael Neuling0b7673c2012-06-25 13:33:23 +0000187#define __STK_REG(i) (112 + ((i)-14)*8)
188#define STK_REG(i) __STK_REG(__REG_##i)
Michael Neuling44ce6a52012-06-25 13:33:14 +0000189
Michael Ellermanf55d9662016-06-06 22:26:10 +0530190#ifdef PPC64_ELF_ABI_v2
Anton Blanchard64031052014-03-10 10:52:17 +1100191#define STK_GOT 24
Anton Blanchardb37c10d2014-02-04 16:09:02 +1100192#define __STK_PARAM(i) (32 + ((i)-3)*8)
193#else
Anton Blanchard64031052014-03-10 10:52:17 +1100194#define STK_GOT 40
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
Michael Ellermanf55d9662016-06-06 22:26:10 +0530199#ifdef PPC64_ELF_ABI_v2
Anton Blanchard7167af72014-02-04 16:07:20 +1100200
201#define _GLOBAL(name) \
Anton Blanchard7167af72014-02-04 16:07:20 +1100202 .align 2 ; \
203 .type name,@function; \
204 .globl name; \
205name:
206
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100207#define _GLOBAL_TOC(name) \
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100208 .align 2 ; \
209 .type name,@function; \
210 .globl name; \
211name: \
2120: addis r2,r12,(.TOC.-0b)@ha; \
213 addi r2,r2,(.TOC.-0b)@l; \
214 .localentry name,.-name
215
Anton Blanchard7167af72014-02-04 16:07:20 +1100216#define DOTSYM(a) a
217
218#else
219
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000220#define XGLUE(a,b) a##b
221#define GLUE(a,b) XGLUE(a,b)
222
223#define _GLOBAL(name) \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000224 .align 2 ; \
225 .globl name; \
226 .globl GLUE(.,name); \
Michael Ellermanbea2dcc2016-09-15 10:40:20 +1000227 .pushsection ".opd","aw"; \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000228name: \
229 .quad GLUE(.,name); \
230 .quad .TOC.@tocbase; \
231 .quad 0; \
Michael Ellermanbea2dcc2016-09-15 10:40:20 +1000232 .popsection; \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000233 .type GLUE(.,name),@function; \
234GLUE(.,name):
235
Anton Blanchard169c7ce2014-04-03 16:01:11 +1100236#define _GLOBAL_TOC(name) _GLOBAL(name)
237
Anton Blanchardc1fb0192014-02-04 16:07:01 +1100238#define DOTSYM(a) GLUE(.,a)
239
Anton Blanchard7167af72014-02-04 16:07:20 +1100240#endif
241
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000242#else /* 32-bit */
243
Kumar Gala748a7682007-09-13 15:42:35 -0500244#define _ENTRY(n) \
245 .globl n; \
246n:
247
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000248#define _GLOBAL(n) \
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000249 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
250 .globl n; \
251n:
252
Alexander Graf9715a2e2014-06-26 13:19:40 +0200253#define _GLOBAL_TOC(name) _GLOBAL(name)
254
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000255#endif
256
Nicholas Piggin6f698df2016-09-16 20:48:17 +1000257/*
258 * __kprobes (the C annotation) puts the symbol into the .kprobes.text
259 * section, which gets emitted at the end of regular text.
260 *
261 * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
262 * a blacklist. The former is for core kprobe functions/data, the
263 * latter is for those that incdentially must be excluded from probing
264 * and allows them to be linked at more optimal location within text.
265 */
266#define _ASM_NOKPROBE_SYMBOL(entry) \
267 .pushsection "_kprobe_blacklist","aw"; \
268 PPC_LONG (entry) ; \
269 .popsection
270
Anton Blanchard151f2512016-07-01 08:19:44 +1000271#define FUNC_START(name) _GLOBAL(name)
272#define FUNC_END(name)
273
Kumar Gala5f7c6902005-09-09 15:02:25 -0500274/*
David Gibsone58c3492006-01-13 14:56:25 +1100275 * LOAD_REG_IMMEDIATE(rn, expr)
276 * Loads the value of the constant expression 'expr' into register 'rn'
277 * using immediate instructions only. Use this when it's important not
278 * to reference other data (i.e. on ppc64 when the TOC pointer is not
Paul Mackerrase31aa452008-08-30 11:41:12 +1000279 * valid) and when 'expr' is a constant or absolute address.
Kumar Gala5f7c6902005-09-09 15:02:25 -0500280 *
David Gibsone58c3492006-01-13 14:56:25 +1100281 * LOAD_REG_ADDR(rn, name)
282 * Loads the address of label 'name' into register 'rn'. Use this when
283 * you don't particularly need immediate instructions only, but you need
284 * the whole address in one register (e.g. it's a structure address and
285 * you want to access various offsets within it). On ppc32 this is
286 * identical to LOAD_REG_IMMEDIATE.
287 *
Kevin Hao1c49abe2013-12-24 15:12:05 +0800288 * LOAD_REG_ADDR_PIC(rn, name)
289 * Loads the address of label 'name' into register 'run'. Use this when
290 * the kernel doesn't run at the linked or relocated address. Please
291 * note that this macro will clobber the lr register.
292 *
David Gibsone58c3492006-01-13 14:56:25 +1100293 * LOAD_REG_ADDRBASE(rn, name)
294 * ADDROFF(name)
295 * LOAD_REG_ADDRBASE loads part of the address of label 'name' into
296 * register 'rn'. ADDROFF(name) returns the remainder of the address as
297 * a constant expression. ADDROFF(name) is a signed expression < 16 bits
298 * in size, so is suitable for use directly as an offset in load and store
299 * instructions. Use this when loading/storing a single word or less as:
300 * LOAD_REG_ADDRBASE(rX, name)
301 * ld rY,ADDROFF(name)(rX)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500302 */
Kevin Hao1c49abe2013-12-24 15:12:05 +0800303
304/* Be careful, this will clobber the lr register. */
305#define LOAD_REG_ADDR_PIC(reg, name) \
306 bl 0f; \
3070: mflr reg; \
308 addis reg,reg,(name - 0b)@ha; \
309 addi reg,reg,(name - 0b)@l;
310
Kumar Gala5f7c6902005-09-09 15:02:25 -0500311#ifdef __powerpc64__
Guenter Roeck7998eb32014-05-15 09:33:42 -0700312#ifdef HAVE_AS_ATHIGH
313#define __AS_ATHIGH high
314#else
315#define __AS_ATHIGH h
316#endif
David Gibsone58c3492006-01-13 14:56:25 +1100317#define LOAD_REG_IMMEDIATE(reg,expr) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000318 lis reg,(expr)@highest; \
319 ori reg,reg,(expr)@higher; \
320 rldicr reg,reg,32,31; \
Guenter Roeck7998eb32014-05-15 09:33:42 -0700321 oris reg,reg,(expr)@__AS_ATHIGH; \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000322 ori reg,reg,(expr)@l;
Kumar Gala5f7c6902005-09-09 15:02:25 -0500323
David Gibsone58c3492006-01-13 14:56:25 +1100324#define LOAD_REG_ADDR(reg,name) \
Michael Neuling564aa5c2012-06-25 13:33:09 +0000325 ld reg,name@got(r2)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500326
David Gibsone58c3492006-01-13 14:56:25 +1100327#define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name)
328#define ADDROFF(name) 0
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000329
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000330/* offsets for stack frame layout */
331#define LRSAVE 16
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000332
333#else /* 32-bit */
Stephen Rothwell70620182005-10-12 17:44:55 +1000334
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)@ha; \
337 addi reg,reg,(expr)@l;
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000338
David Gibsone58c3492006-01-13 14:56:25 +1100339#define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE(reg, name)
340
Michael Neuling564aa5c2012-06-25 13:33:09 +0000341#define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha
David Gibsone58c3492006-01-13 14:56:25 +1100342#define ADDROFF(name) name@l
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000343
Paul Mackerrasf78541dc2005-10-28 22:53:37 +1000344/* offsets for stack frame layout */
345#define LRSAVE 4
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000346
Kumar Gala5f7c6902005-09-09 15:02:25 -0500347#endif
348
349/* various errata or part fixups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#ifdef CONFIG_PPC601_SYNC_FIX
351#define SYNC \
352BEGIN_FTR_SECTION \
353 sync; \
354 isync; \
355END_FTR_SECTION_IFSET(CPU_FTR_601)
356#define SYNC_601 \
357BEGIN_FTR_SECTION \
358 sync; \
359END_FTR_SECTION_IFSET(CPU_FTR_601)
360#define ISYNC_601 \
361BEGIN_FTR_SECTION \
362 isync; \
363END_FTR_SECTION_IFSET(CPU_FTR_601)
364#else
365#define SYNC
366#define SYNC_601
367#define ISYNC_601
368#endif
369
Scott Woodd52459c2013-07-23 20:21:11 -0500370#if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000371#define MFTB(dest) \
Scott Woodbeb2dc02013-08-20 19:33:12 -050037290: mfspr dest, SPRN_TBRL; \
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000373BEGIN_FTR_SECTION_NESTED(96); \
374 cmpwi dest,0; \
375 beq- 90b; \
376END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96)
LEROY Christopheae2163b2013-11-22 17:57:31 +0100377#elif defined(CONFIG_8xx)
378#define MFTB(dest) mftb dest
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000379#else
Scott Woodbeb2dc02013-08-20 19:33:12 -0500380#define MFTB(dest) mfspr dest, SPRN_TBRL
Benjamin Herrenschmidt859deea2006-10-20 14:37:05 +1000381#endif
Kumar Gala5f7c6902005-09-09 15:02:25 -0500382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#ifndef CONFIG_SMP
384#define TLBSYNC
385#else /* CONFIG_SMP */
386/* tlbsync is not implemented on 601 */
387#define TLBSYNC \
388BEGIN_FTR_SECTION \
389 tlbsync; \
390 sync; \
391END_FTR_SECTION_IFCLR(CPU_FTR_601)
392#endif
393
Anton Blanchard694caf02012-04-18 02:21:52 +0000394#ifdef CONFIG_PPC64
395#define MTOCRF(FXM, RS) \
396 BEGIN_FTR_SECTION_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000397 mtcrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000398 FTR_SECTION_ELSE_NESTED(848); \
Michael Neuling86e32fd2012-06-25 13:33:16 +0000399 mtocrf (FXM), RS; \
Anton Blanchard694caf02012-04-18 02:21:52 +0000400 ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848)
401#endif
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403/*
404 * This instruction is not implemented on the PPC 603 or 601; however, on
405 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
406 * All of these instructions exist in the 8xx, they have magical powers,
407 * and they must be used.
408 */
409
410#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
411#define tlbia \
412 li r4,1024; \
413 mtctr r4; \
414 lis r4,KERNELBASE@h; \
Russell Curreye3824e42016-03-02 17:12:45 +1100415 .machine push; \
416 .machine "power4"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170: tlbie r4; \
Russell Curreye3824e42016-03-02 17:12:45 +1100418 .machine pop; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 addi r4,r4,0x1000; \
420 bdnz 0b
421#endif
422
Kumar Gala5f7c6902005-09-09 15:02:25 -0500423
Kumar Gala5f7c6902005-09-09 15:02:25 -0500424#ifdef CONFIG_IBM440EP_ERR42
425#define PPC440EP_ERR42 isync
426#else
427#define PPC440EP_ERR42
428#endif
429
Michael Neulinga5153482013-05-29 19:34:27 +0000430/* The following stops all load and store data streams associated with stream
431 * ID (ie. streams created explicitly). The embedded and server mnemonics for
432 * dcbt are different so we use machine "power4" here explicitly.
433 */
434#define DCBT_STOP_ALL_STREAM_IDS(scratch) \
435.machine push ; \
436.machine "power4" ; \
437 lis scratch,0x60000000@h; \
438 dcbt r0,scratch,0b01010; \
439.machine pop
440
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000441/*
442 * toreal/fromreal/tophys/tovirt macros. 32-bit BookE makes them
443 * keep the address intact to be compatible with code shared with
444 * 32-bit classic.
445 *
446 * On the other hand, I find it useful to have them behave as expected
447 * by their name (ie always do the addition) on 64-bit BookE
448 */
449#if defined(CONFIG_BOOKE) && !defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000450#define toreal(rd)
451#define fromreal(rd)
452
Roland McGrath2ca76332008-05-11 10:40:47 +1000453/*
454 * We use addis to ensure compatibility with the "classic" ppc versions of
455 * these macros, which use rs = 0 to get the tophys offset in rd, rather than
456 * converting the address in r0, and so this version has to do that too
457 * (i.e. set register rd to 0 when rs == 0).
458 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define tophys(rd,rs) \
460 addis rd,rs,0
461
462#define tovirt(rd,rs) \
463 addis rd,rs,0
464
Kumar Gala5f7c6902005-09-09 15:02:25 -0500465#elif defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000466#define toreal(rd) /* we can access c000... in real mode */
467#define fromreal(rd)
468
Kumar Gala5f7c6902005-09-09 15:02:25 -0500469#define tophys(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000470 clrldi rd,rs,2
Kumar Gala5f7c6902005-09-09 15:02:25 -0500471
472#define tovirt(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000473 rotldi rd,rs,16; \
474 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
475 rotldi rd,rd,48
Kumar Gala5f7c6902005-09-09 15:02:25 -0500476#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477/*
478 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
479 * physical base address of RAM at compile time.
480 */
Paul Mackerras63162222005-10-27 22:44:39 +1000481#define toreal(rd) tophys(rd,rd)
482#define fromreal(rd) tovirt(rd,rd)
483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484#define tophys(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00004850: addis rd,rs,-PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .section ".vtop_fixup","aw"; \
487 .align 1; \
488 .long 0b; \
489 .previous
490
491#define tovirt(rd,rs) \
Dale Farnsworthccdcef72008-12-17 10:09:13 +00004920: addis rd,rs,PAGE_OFFSET@h; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .section ".ptov_fixup","aw"; \
494 .align 1; \
495 .long 0b; \
496 .previous
Kumar Gala5f7c6902005-09-09 15:02:25 -0500497#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Benjamin Herrenschmidt44c58cc2009-07-23 23:15:20 +0000499#ifdef CONFIG_PPC_BOOK3S_64
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000500#define RFI rfid
501#define MTMSRD(r) mtmsrd r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000502#define MTMSR_EERI(reg) mtmsrd reg,1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#else
504#define FIX_SRR1(ra, rb)
505#ifndef CONFIG_40x
506#define RFI rfi
507#else
508#define RFI rfi; b . /* Prevent prefetch past rfi */
509#endif
510#define MTMSRD(r) mtmsr r
Benjamin Herrenschmidtb38c77d2012-07-04 14:49:12 +1000511#define MTMSR_EERI(reg) mtmsr reg
Matt Porterc9cf73a2005-07-31 22:34:52 -0700512#endif
513
Arnd Bergmann88ced032005-12-16 22:43:46 +0100514#endif /* __KERNEL__ */
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516/* The boring bits... */
517
518/* Condition Register Bit Fields */
519
520#define cr0 0
521#define cr1 1
522#define cr2 2
523#define cr3 3
524#define cr4 4
525#define cr5 5
526#define cr6 6
527#define cr7 7
528
529
Michael Neuling9a13a522012-06-25 13:33:12 +0000530/*
531 * General Purpose Registers (GPRs)
532 *
533 * The lower case r0-r31 should be used in preference to the upper
534 * case R0-R31 as they provide more error checking in the assembler.
535 * Use R0-31 only when really nessesary.
536 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Michael Neuling9a13a522012-06-25 13:33:12 +0000538#define r0 %r0
539#define r1 %r1
540#define r2 %r2
541#define r3 %r3
542#define r4 %r4
543#define r5 %r5
544#define r6 %r6
545#define r7 %r7
546#define r8 %r8
547#define r9 %r9
548#define r10 %r10
549#define r11 %r11
550#define r12 %r12
551#define r13 %r13
552#define r14 %r14
553#define r15 %r15
554#define r16 %r16
555#define r17 %r17
556#define r18 %r18
557#define r19 %r19
558#define r20 %r20
559#define r21 %r21
560#define r22 %r22
561#define r23 %r23
562#define r24 %r24
563#define r25 %r25
564#define r26 %r26
565#define r27 %r27
566#define r28 %r28
567#define r29 %r29
568#define r30 %r30
569#define r31 %r31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571
572/* Floating Point Registers (FPRs) */
573
574#define fr0 0
575#define fr1 1
576#define fr2 2
577#define fr3 3
578#define fr4 4
579#define fr5 5
580#define fr6 6
581#define fr7 7
582#define fr8 8
583#define fr9 9
584#define fr10 10
585#define fr11 11
586#define fr12 12
587#define fr13 13
588#define fr14 14
589#define fr15 15
590#define fr16 16
591#define fr17 17
592#define fr18 18
593#define fr19 19
594#define fr20 20
595#define fr21 21
596#define fr22 22
597#define fr23 23
598#define fr24 24
599#define fr25 25
600#define fr26 26
601#define fr27 27
602#define fr28 28
603#define fr29 29
604#define fr30 30
605#define fr31 31
606
Kumar Gala5f7c6902005-09-09 15:02:25 -0500607/* AltiVec Registers (VPRs) */
608
Anton Blanchardc2ce6f92015-02-10 09:51:22 +1100609#define v0 0
610#define v1 1
611#define v2 2
612#define v3 3
613#define v4 4
614#define v5 5
615#define v6 6
616#define v7 7
617#define v8 8
618#define v9 9
619#define v10 10
620#define v11 11
621#define v12 12
622#define v13 13
623#define v14 14
624#define v15 15
625#define v16 16
626#define v17 17
627#define v18 18
628#define v19 19
629#define v20 20
630#define v21 21
631#define v22 22
632#define v23 23
633#define v24 24
634#define v25 25
635#define v26 26
636#define v27 27
637#define v28 28
638#define v29 29
639#define v30 30
640#define v31 31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Michael Neuling72ffff52008-06-25 14:07:18 +1000642/* VSX Registers (VSRs) */
643
Anton Blancharddf99e6e2015-02-10 09:51:23 +1100644#define vs0 0
645#define vs1 1
646#define vs2 2
647#define vs3 3
648#define vs4 4
649#define vs5 5
650#define vs6 6
651#define vs7 7
652#define vs8 8
653#define vs9 9
654#define vs10 10
655#define vs11 11
656#define vs12 12
657#define vs13 13
658#define vs14 14
659#define vs15 15
660#define vs16 16
661#define vs17 17
662#define vs18 18
663#define vs19 19
664#define vs20 20
665#define vs21 21
666#define vs22 22
667#define vs23 23
668#define vs24 24
669#define vs25 25
670#define vs26 26
671#define vs27 27
672#define vs28 28
673#define vs29 29
674#define vs30 30
675#define vs31 31
676#define vs32 32
677#define vs33 33
678#define vs34 34
679#define vs35 35
680#define vs36 36
681#define vs37 37
682#define vs38 38
683#define vs39 39
684#define vs40 40
685#define vs41 41
686#define vs42 42
687#define vs43 43
688#define vs44 44
689#define vs45 45
690#define vs46 46
691#define vs47 47
692#define vs48 48
693#define vs49 49
694#define vs50 50
695#define vs51 51
696#define vs52 52
697#define vs53 53
698#define vs54 54
699#define vs55 55
700#define vs56 56
701#define vs57 57
702#define vs58 58
703#define vs59 59
704#define vs60 60
705#define vs61 61
706#define vs62 62
707#define vs63 63
Michael Neuling72ffff52008-06-25 14:07:18 +1000708
Kumar Gala5f7c6902005-09-09 15:02:25 -0500709/* SPE Registers (EVPRs) */
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711#define evr0 0
712#define evr1 1
713#define evr2 2
714#define evr3 3
715#define evr4 4
716#define evr5 5
717#define evr6 6
718#define evr7 7
719#define evr8 8
720#define evr9 9
721#define evr10 10
722#define evr11 11
723#define evr12 12
724#define evr13 13
725#define evr14 14
726#define evr15 15
727#define evr16 16
728#define evr17 17
729#define evr18 18
730#define evr19 19
731#define evr20 20
732#define evr21 21
733#define evr22 22
734#define evr23 23
735#define evr24 24
736#define evr25 25
737#define evr26 26
738#define evr27 27
739#define evr28 28
740#define evr29 29
741#define evr30 30
742#define evr31 31
743
744/* some stab codes */
745#define N_FUN 36
746#define N_RSYM 64
747#define N_SLINE 68
748#define N_SO 100
Kumar Gala5f7c6902005-09-09 15:02:25 -0500749
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000750/*
751 * Create an endian fixup trampoline
752 *
753 * This starts with a "tdi 0,0,0x48" instruction which is
754 * essentially a "trap never", and thus akin to a nop.
755 *
756 * The opcode for this instruction read with the wrong endian
757 * however results in a b . + 8
758 *
759 * So essentially we use that trick to execute the following
760 * trampoline in "reverse endian" if we are running with the
761 * MSR_LE bit set the "wrong" way for whatever endianness the
762 * kernel is built for.
763 */
Kumar Gala5f7c6902005-09-09 15:02:25 -0500764
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000765#ifdef CONFIG_PPC_BOOK3E
766#define FIXUP_ENDIAN
767#else
768#define FIXUP_ENDIAN \
769 tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \
770 b $+36; /* Skip trampoline if endian is good */ \
771 .long 0x05009f42; /* bcl 20,31,$+4 */ \
772 .long 0xa602487d; /* mflr r10 */ \
773 .long 0x1c004a39; /* addi r10,r10,28 */ \
774 .long 0xa600607d; /* mfmsr r11 */ \
775 .long 0x01006b69; /* xori r11,r11,1 */ \
776 .long 0xa6035a7d; /* mtsrr0 r10 */ \
777 .long 0xa6037b7d; /* mtsrr1 r11 */ \
778 .long 0x2400004c /* rfid */
779#endif /* !CONFIG_PPC_BOOK3E */
Michael Ellermane3f2c6c2016-10-14 15:58:28 +1100780
Benjamin Herrenschmidt5c0484e2013-09-23 12:04:45 +1000781#endif /* __ASSEMBLY__ */
Michael Ellermane3f2c6c2016-10-14 15:58:28 +1100782
Kumar Gala5f7c6902005-09-09 15:02:25 -0500783#endif /* _ASM_POWERPC_PPC_ASM_H */