Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | */ |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 4 | #ifndef _ASM_POWERPC_PPC_ASM_H |
| 5 | #define _ASM_POWERPC_PPC_ASM_H |
| 6 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 7 | #include <linux/stringify.h> |
David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 8 | #include <asm/asm-compat.h> |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 9 | #include <asm/processor.h> |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 10 | #include <asm/ppc-opcode.h> |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 11 | #include <asm/firmware.h> |
Christophe Leroy | 2c86cd1 | 2018-07-05 16:25:01 +0000 | [diff] [blame] | 12 | #include <asm/feature-fixups.h> |
Christophe Leroy | 1e688dd2 | 2021-04-13 16:38:10 +0000 | [diff] [blame] | 13 | #include <asm/extable.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 14 | |
Michael Ellerman | e3f2c6c | 2016-10-14 15:58:28 +1100 | [diff] [blame] | 15 | #ifdef __ASSEMBLY__ |
David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 16 | |
| 17 | #define SZL (BITS_PER_LONG/8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Macros for storing registers into and loading registers from |
| 21 | * exception frames. |
| 22 | */ |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 23 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base) |
Christophe Leroy | a1f3ae3 | 2018-04-17 19:08:18 +0200 | [diff] [blame] | 31 | #define SAVE_NVGPRS(base) stmw 13, GPR0+4*13(base) |
| 32 | #define REST_NVGPRS(base) lmw 13, GPR0+4*13(base) |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 33 | #endif |
| 34 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 35 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 44 | #define SAVE_FPR(n, base) stfd n,8*TS_FPRWIDTH*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #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 Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 50 | #define REST_FPR(n, base) lfd n,8*TS_FPRWIDTH*(n)(base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #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 Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 57 | #define SAVE_VR(n,b,base) li b,16*(n); stvx n,base,b |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 58 | #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 Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 63 | #define REST_VR(n,b,base) li b,16*(n); lvx n,base,b |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 64 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Anton Blanchard | 926f160 | 2013-09-23 12:04:39 +1000 | [diff] [blame] | 70 | #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 Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 81 | /* Save the lower 32 VSRs in the thread VSR region */ |
Benjamin Herrenschmidt | 3ad26e5 | 2013-10-11 18:23:53 +1100 | [diff] [blame] | 82 | #define SAVE_VSR(n,b,base) li b,16*(n); STXVD2X_ROT(n,R##base,R##b) |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 83 | #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 Herrenschmidt | 3ad26e5 | 2013-10-11 18:23:53 +1100 | [diff] [blame] | 88 | #define REST_VSR(n,b,base) li b,16*(n); LXVD2X_ROT(n,R##base,R##b) |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 89 | #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 Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 94 | |
Scott Wood | c51584d | 2011-06-14 18:34:27 -0500 | [diff] [blame] | 95 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Michael Ellerman | 8c71632 | 2005-10-24 15:07:27 +1000 | [diff] [blame] | 112 | /* 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 Herrenschmidt | 50fb8eb | 2011-01-12 17:41:28 +1100 | [diff] [blame] | 119 | #define HMT_EXTRA_HIGH or 7,7,7 # power7 only |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 120 | |
Michael Neuling | d72be89 | 2012-06-25 13:33:15 +0000 | [diff] [blame] | 121 | #ifdef CONFIG_PPC64 |
| 122 | #define ULONG_SIZE 8 |
| 123 | #else |
| 124 | #define ULONG_SIZE 4 |
| 125 | #endif |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 126 | #define __VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE)) |
| 127 | #define VCPU_GPR(n) __VCPU_GPR(__REG_##n) |
Michael Neuling | d72be89 | 2012-06-25 13:33:15 +0000 | [diff] [blame] | 128 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 129 | #ifdef __KERNEL__ |
Michael Ellerman | 2eda7f1 | 2020-12-18 22:16:19 +1100 | [diff] [blame] | 130 | |
| 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 Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 136 | |
Michael Neuling | 44ce6a5 | 2012-06-25 13:33:14 +0000 | [diff] [blame] | 137 | #define STACKFRAMESIZE 256 |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 138 | #define __STK_REG(i) (112 + ((i)-14)*8) |
| 139 | #define STK_REG(i) __STK_REG(__REG_##i) |
Michael Neuling | 44ce6a5 | 2012-06-25 13:33:14 +0000 | [diff] [blame] | 140 | |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 141 | #ifdef PPC64_ELF_ABI_v2 |
Anton Blanchard | 6403105 | 2014-03-10 10:52:17 +1100 | [diff] [blame] | 142 | #define STK_GOT 24 |
Anton Blanchard | b37c10d | 2014-02-04 16:09:02 +1100 | [diff] [blame] | 143 | #define __STK_PARAM(i) (32 + ((i)-3)*8) |
| 144 | #else |
Anton Blanchard | 6403105 | 2014-03-10 10:52:17 +1100 | [diff] [blame] | 145 | #define STK_GOT 40 |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 146 | #define __STK_PARAM(i) (48 + ((i)-3)*8) |
Anton Blanchard | b37c10d | 2014-02-04 16:09:02 +1100 | [diff] [blame] | 147 | #endif |
Michael Neuling | 0b7673c | 2012-06-25 13:33:23 +0000 | [diff] [blame] | 148 | #define STK_PARAM(i) __STK_PARAM(__REG_##i) |
Michael Neuling | 44ce6a5 | 2012-06-25 13:33:14 +0000 | [diff] [blame] | 149 | |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 150 | #ifdef PPC64_ELF_ABI_v2 |
Anton Blanchard | 7167af7 | 2014-02-04 16:07:20 +1100 | [diff] [blame] | 151 | |
| 152 | #define _GLOBAL(name) \ |
Anton Blanchard | 7167af7 | 2014-02-04 16:07:20 +1100 | [diff] [blame] | 153 | .align 2 ; \ |
| 154 | .type name,@function; \ |
| 155 | .globl name; \ |
| 156 | name: |
| 157 | |
Anton Blanchard | 169c7ce | 2014-04-03 16:01:11 +1100 | [diff] [blame] | 158 | #define _GLOBAL_TOC(name) \ |
Anton Blanchard | 169c7ce | 2014-04-03 16:01:11 +1100 | [diff] [blame] | 159 | .align 2 ; \ |
| 160 | .type name,@function; \ |
| 161 | .globl name; \ |
| 162 | name: \ |
| 163 | 0: addis r2,r12,(.TOC.-0b)@ha; \ |
| 164 | addi r2,r2,(.TOC.-0b)@l; \ |
| 165 | .localentry name,.-name |
| 166 | |
Anton Blanchard | 7167af7 | 2014-02-04 16:07:20 +1100 | [diff] [blame] | 167 | #define DOTSYM(a) a |
| 168 | |
| 169 | #else |
| 170 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 171 | #define XGLUE(a,b) a##b |
| 172 | #define GLUE(a,b) XGLUE(a,b) |
| 173 | |
| 174 | #define _GLOBAL(name) \ |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 175 | .align 2 ; \ |
| 176 | .globl name; \ |
| 177 | .globl GLUE(.,name); \ |
Michael Ellerman | bea2dcc | 2016-09-15 10:40:20 +1000 | [diff] [blame] | 178 | .pushsection ".opd","aw"; \ |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 179 | name: \ |
| 180 | .quad GLUE(.,name); \ |
| 181 | .quad .TOC.@tocbase; \ |
| 182 | .quad 0; \ |
Michael Ellerman | bea2dcc | 2016-09-15 10:40:20 +1000 | [diff] [blame] | 183 | .popsection; \ |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 184 | .type GLUE(.,name),@function; \ |
| 185 | GLUE(.,name): |
| 186 | |
Anton Blanchard | 169c7ce | 2014-04-03 16:01:11 +1100 | [diff] [blame] | 187 | #define _GLOBAL_TOC(name) _GLOBAL(name) |
| 188 | |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 189 | #define DOTSYM(a) GLUE(.,a) |
| 190 | |
Anton Blanchard | 7167af7 | 2014-02-04 16:07:20 +1100 | [diff] [blame] | 191 | #endif |
| 192 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 193 | #else /* 32-bit */ |
| 194 | |
Kumar Gala | 748a768 | 2007-09-13 15:42:35 -0500 | [diff] [blame] | 195 | #define _ENTRY(n) \ |
| 196 | .globl n; \ |
| 197 | n: |
| 198 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 199 | #define _GLOBAL(n) \ |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 200 | .stabs __stringify(n:F-1),N_FUN,0,0,n;\ |
| 201 | .globl n; \ |
| 202 | n: |
| 203 | |
Alexander Graf | 9715a2e | 2014-06-26 13:19:40 +0200 | [diff] [blame] | 204 | #define _GLOBAL_TOC(name) _GLOBAL(name) |
| 205 | |
Christophe Leroy | ce7d805 | 2020-11-27 00:10:03 +1100 | [diff] [blame] | 206 | #define DOTSYM(a) a |
| 207 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 208 | #endif |
| 209 | |
Nicholas Piggin | 6f698df | 2016-09-16 20:48:17 +1000 | [diff] [blame] | 210 | /* |
| 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 Piggin | c0a5149 | 2016-10-13 13:07:14 +1100 | [diff] [blame] | 219 | #ifdef CONFIG_KPROBES |
Nicholas Piggin | 6f698df | 2016-09-16 20:48:17 +1000 | [diff] [blame] | 220 | #define _ASM_NOKPROBE_SYMBOL(entry) \ |
| 221 | .pushsection "_kprobe_blacklist","aw"; \ |
| 222 | PPC_LONG (entry) ; \ |
| 223 | .popsection |
Nicholas Piggin | c0a5149 | 2016-10-13 13:07:14 +1100 | [diff] [blame] | 224 | #else |
| 225 | #define _ASM_NOKPROBE_SYMBOL(entry) |
| 226 | #endif |
Nicholas Piggin | 6f698df | 2016-09-16 20:48:17 +1000 | [diff] [blame] | 227 | |
Anton Blanchard | 151f251 | 2016-07-01 08:19:44 +1000 | [diff] [blame] | 228 | #define FUNC_START(name) _GLOBAL(name) |
| 229 | #define FUNC_END(name) |
| 230 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 231 | /* |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 232 | * 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 Mackerras | e31aa45 | 2008-08-30 11:41:12 +1000 | [diff] [blame] | 236 | * valid) and when 'expr' is a constant or absolute address. |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 237 | * |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 238 | * 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 Hao | 1c49abe | 2013-12-24 15:12:05 +0800 | [diff] [blame] | 245 | * 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 Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 250 | * 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 Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 259 | */ |
Kevin Hao | 1c49abe | 2013-12-24 15:12:05 +0800 | [diff] [blame] | 260 | |
| 261 | /* Be careful, this will clobber the lr register. */ |
| 262 | #define LOAD_REG_ADDR_PIC(reg, name) \ |
Christophe Leroy | f5007db | 2021-08-24 07:56:26 +0000 | [diff] [blame] | 263 | bcl 20,31,$+4; \ |
Kevin Hao | 1c49abe | 2013-12-24 15:12:05 +0800 | [diff] [blame] | 264 | 0: mflr reg; \ |
| 265 | addis reg,reg,(name - 0b)@ha; \ |
| 266 | addi reg,reg,(name - 0b)@l; |
| 267 | |
Christophe Leroy | c691b4b | 2019-08-20 14:34:12 +0000 | [diff] [blame] | 268 | #if defined(__powerpc64__) && defined(HAVE_AS_ATHIGH) |
Guenter Roeck | 7998eb3 | 2014-05-15 09:33:42 -0700 | [diff] [blame] | 269 | #define __AS_ATHIGH high |
| 270 | #else |
| 271 | #define __AS_ATHIGH h |
| 272 | #endif |
Christophe Leroy | c691b4b | 2019-08-20 14:34:12 +0000 | [diff] [blame] | 273 | |
| 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 Leroy | d7fb5b1 | 2019-08-20 14:34:14 +0000 | [diff] [blame] | 304 | #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 Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 310 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 311 | #define LOAD_REG_ADDR(reg,name) \ |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 312 | ld reg,name@got(r2) |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 313 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 314 | #define LOAD_REG_ADDRBASE(reg,name) LOAD_REG_ADDR(reg,name) |
| 315 | #define ADDROFF(name) 0 |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 316 | |
Paul Mackerras | f78541dc | 2005-10-28 22:53:37 +1000 | [diff] [blame] | 317 | /* offsets for stack frame layout */ |
| 318 | #define LRSAVE 16 |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 319 | |
| 320 | #else /* 32-bit */ |
Stephen Rothwell | 7062018 | 2005-10-12 17:44:55 +1000 | [diff] [blame] | 321 | |
Christophe Leroy | c691b4b | 2019-08-20 14:34:12 +0000 | [diff] [blame] | 322 | #define LOAD_REG_IMMEDIATE(reg, expr) __LOAD_REG_IMMEDIATE_32 reg, expr |
| 323 | |
| 324 | #define LOAD_REG_IMMEDIATE_SYM(reg,expr) \ |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 325 | lis reg,(expr)@ha; \ |
| 326 | addi reg,reg,(expr)@l; |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 327 | |
Christophe Leroy | c691b4b | 2019-08-20 14:34:12 +0000 | [diff] [blame] | 328 | #define LOAD_REG_ADDR(reg,name) LOAD_REG_IMMEDIATE_SYM(reg, name) |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 329 | |
Michael Neuling | 564aa5c | 2012-06-25 13:33:09 +0000 | [diff] [blame] | 330 | #define LOAD_REG_ADDRBASE(reg, name) lis reg,name@ha |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 331 | #define ADDROFF(name) name@l |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 332 | |
Paul Mackerras | f78541dc | 2005-10-28 22:53:37 +1000 | [diff] [blame] | 333 | /* offsets for stack frame layout */ |
| 334 | #define LRSAVE 4 |
Paul Mackerras | b85a046 | 2005-10-06 10:59:19 +1000 | [diff] [blame] | 335 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 336 | #endif |
| 337 | |
| 338 | /* various errata or part fixups */ |
Scott Wood | d52459c | 2013-07-23 20:21:11 -0500 | [diff] [blame] | 339 | #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E) |
Benjamin Herrenschmidt | 859deea | 2006-10-20 14:37:05 +1000 | [diff] [blame] | 340 | #define MFTB(dest) \ |
Scott Wood | beb2dc0 | 2013-08-20 19:33:12 -0500 | [diff] [blame] | 341 | 90: mfspr dest, SPRN_TBRL; \ |
Benjamin Herrenschmidt | 859deea | 2006-10-20 14:37:05 +1000 | [diff] [blame] | 342 | BEGIN_FTR_SECTION_NESTED(96); \ |
| 343 | cmpwi dest,0; \ |
| 344 | beq- 90b; \ |
| 345 | END_FTR_SECTION_NESTED(CPU_FTR_CELL_TB_BUG, CPU_FTR_CELL_TB_BUG, 96) |
| 346 | #else |
Christophe Leroy | 72e4b2c | 2017-08-08 13:58:50 +0200 | [diff] [blame] | 347 | #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 Herrenschmidt | 859deea | 2006-10-20 14:37:05 +1000 | [diff] [blame] | 356 | #endif |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 357 | |
Christophe Leroy | 8b14e1d | 2020-09-29 06:48:36 +0000 | [diff] [blame] | 358 | #ifndef CONFIG_SMP |
Christophe Leroy | 12c3f1f | 2019-08-26 15:52:14 +0000 | [diff] [blame] | 359 | #define TLBSYNC |
| 360 | #else |
| 361 | #define TLBSYNC tlbsync; sync |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | #endif |
| 363 | |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 364 | #ifdef CONFIG_PPC64 |
| 365 | #define MTOCRF(FXM, RS) \ |
| 366 | BEGIN_FTR_SECTION_NESTED(848); \ |
Michael Neuling | 86e32fd | 2012-06-25 13:33:16 +0000 | [diff] [blame] | 367 | mtcrf (FXM), RS; \ |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 368 | FTR_SECTION_ELSE_NESTED(848); \ |
Michael Neuling | 86e32fd | 2012-06-25 13:33:16 +0000 | [diff] [blame] | 369 | mtocrf (FXM), RS; \ |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 370 | ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_NOEXECUTE, 848) |
| 371 | #endif |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | /* |
| 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 Leroy | 968159c | 2017-08-08 13:58:54 +0200 | [diff] [blame] | 380 | #if !defined(CONFIG_4xx) && !defined(CONFIG_PPC_8xx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | #define tlbia \ |
| 382 | li r4,1024; \ |
| 383 | mtctr r4; \ |
| 384 | lis r4,KERNELBASE@h; \ |
Russell Currey | e3824e4 | 2016-03-02 17:12:45 +1100 | [diff] [blame] | 385 | .machine push; \ |
| 386 | .machine "power4"; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | 0: tlbie r4; \ |
Russell Currey | e3824e4 | 2016-03-02 17:12:45 +1100 | [diff] [blame] | 388 | .machine pop; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | addi r4,r4,0x1000; \ |
| 390 | bdnz 0b |
| 391 | #endif |
| 392 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 393 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 394 | #ifdef CONFIG_IBM440EP_ERR42 |
| 395 | #define PPC440EP_ERR42 isync |
| 396 | #else |
| 397 | #define PPC440EP_ERR42 |
| 398 | #endif |
| 399 | |
Michael Neuling | a515348 | 2013-05-29 19:34:27 +0000 | [diff] [blame] | 400 | /* 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 Piggin | 15a3204 | 2018-02-21 05:08:26 +1000 | [diff] [blame] | 402 | * dcbt are different so this must only be used for server. |
Michael Neuling | a515348 | 2013-05-29 19:34:27 +0000 | [diff] [blame] | 403 | */ |
Nicholas Piggin | 15a3204 | 2018-02-21 05:08:26 +1000 | [diff] [blame] | 404 | #define DCBT_BOOK3S_STOP_ALL_STREAM_IDS(scratch) \ |
| 405 | lis scratch,0x60000000@h; \ |
| 406 | dcbt 0,scratch,0b01010 |
Michael Neuling | a515348 | 2013-05-29 19:34:27 +0000 | [diff] [blame] | 407 | |
Benjamin Herrenschmidt | 44c58cc | 2009-07-23 23:15:20 +0000 | [diff] [blame] | 408 | /* |
| 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 Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 417 | #define toreal(rd) |
| 418 | #define fromreal(rd) |
| 419 | |
Roland McGrath | 2ca7633 | 2008-05-11 10:40:47 +1000 | [diff] [blame] | 420 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | #define tophys(rd,rs) \ |
| 427 | addis rd,rs,0 |
| 428 | |
| 429 | #define tovirt(rd,rs) \ |
| 430 | addis rd,rs,0 |
| 431 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 432 | #elif defined(CONFIG_PPC64) |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 433 | #define toreal(rd) /* we can access c000... in real mode */ |
| 434 | #define fromreal(rd) |
| 435 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 436 | #define tophys(rd,rs) \ |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 437 | clrldi rd,rs,2 |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 438 | |
| 439 | #define tovirt(rd,rs) \ |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 440 | rotldi rd,rs,16; \ |
| 441 | ori rd,rd,((KERNELBASE>>48)&0xFFFF);\ |
| 442 | rotldi rd,rd,48 |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 443 | #else |
Paul Mackerras | 6316222 | 2005-10-27 22:44:39 +1000 | [diff] [blame] | 444 | #define toreal(rd) tophys(rd,rd) |
| 445 | #define fromreal(rd) tovirt(rd,rd) |
| 446 | |
Christophe Leroy | c62ce9e | 2018-12-04 17:59:15 +0000 | [diff] [blame] | 447 | #define tophys(rd, rs) addis rd, rs, -PAGE_OFFSET@h |
| 448 | #define tovirt(rd, rs) addis rd, rs, PAGE_OFFSET@h |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 449 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Benjamin Herrenschmidt | 44c58cc | 2009-07-23 23:15:20 +0000 | [diff] [blame] | 451 | #ifdef CONFIG_PPC_BOOK3S_64 |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 452 | #define MTMSRD(r) mtmsrd r |
Benjamin Herrenschmidt | b38c77d | 2012-07-04 14:49:12 +1000 | [diff] [blame] | 453 | #define MTMSR_EERI(reg) mtmsrd reg,1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | #define MTMSRD(r) mtmsr r |
Benjamin Herrenschmidt | b38c77d | 2012-07-04 14:49:12 +1000 | [diff] [blame] | 456 | #define MTMSR_EERI(reg) mtmsr reg |
Matt Porter | c9cf73a | 2005-07-31 22:34:52 -0700 | [diff] [blame] | 457 | #endif |
| 458 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 459 | #endif /* __KERNEL__ */ |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | /* 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 Neuling | 9a13a52 | 2012-06-25 13:33:12 +0000 | [diff] [blame] | 475 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Michael Neuling | 9a13a52 | 2012-06-25 13:33:12 +0000 | [diff] [blame] | 483 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
| 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 Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 552 | /* AltiVec Registers (VPRs) */ |
| 553 | |
Anton Blanchard | c2ce6f9 | 2015-02-10 09:51:22 +1100 | [diff] [blame] | 554 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Michael Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 587 | /* VSX Registers (VSRs) */ |
| 588 | |
Anton Blanchard | df99e6e | 2015-02-10 09:51:23 +1100 | [diff] [blame] | 589 | #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 Neuling | 72ffff5 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 653 | |
Kumar Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 654 | /* SPE Registers (EVPRs) */ |
| 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | #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 Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 694 | |
Nicholas Piggin | 7fa95f9 | 2020-06-11 18:12:03 +1000 | [diff] [blame] | 695 | #define RFSCV .long 0x4c0000a4 |
| 696 | |
Benjamin Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 697 | /* |
| 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 Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 711 | |
Benjamin Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 712 | #ifdef CONFIG_PPC_BOOK3E |
| 713 | #define FIXUP_ENDIAN |
| 714 | #else |
Nicholas Piggin | 8ca9c08 | 2017-10-23 17:08:14 +1000 | [diff] [blame] | 715 | /* |
Randy Dunlap | db10f55 | 2020-07-25 17:38:06 -0700 | [diff] [blame] | 716 | * This version may be used in HV or non-HV context. |
Nicholas Piggin | 8ca9c08 | 2017-10-23 17:08:14 +1000 | [diff] [blame] | 717 | * MSR[EE] must be disabled. |
| 718 | */ |
Benjamin Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 719 | #define FIXUP_ENDIAN \ |
| 720 | tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ |
Nicholas Piggin | f848ea7 | 2017-10-23 17:08:13 +1000 | [diff] [blame] | 721 | b 191f; /* Skip trampoline if endian is good */ \ |
Benjamin Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 722 | .long 0xa600607d; /* mfmsr r11 */ \ |
| 723 | .long 0x01006b69; /* xori r11,r11,1 */ \ |
Nicholas Piggin | f1fe525 | 2017-05-01 22:01:09 +1000 | [diff] [blame] | 724 | .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 Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 729 | .long 0xa6035a7d; /* mtsrr0 r10 */ \ |
| 730 | .long 0xa6037b7d; /* mtsrr1 r11 */ \ |
Nicholas Piggin | f848ea7 | 2017-10-23 17:08:13 +1000 | [diff] [blame] | 731 | .long 0x2400004c; /* rfid */ \ |
| 732 | 191: |
Nicholas Piggin | f1fe525 | 2017-05-01 22:01:09 +1000 | [diff] [blame] | 733 | |
Nicholas Piggin | 8ca9c08 | 2017-10-23 17:08:14 +1000 | [diff] [blame] | 734 | /* |
| 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 */ \ |
| 750 | 191: |
| 751 | |
Benjamin Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 752 | #endif /* !CONFIG_PPC_BOOK3E */ |
Michael Ellerman | e3f2c6c | 2016-10-14 15:58:28 +1100 | [diff] [blame] | 753 | |
Benjamin Herrenschmidt | 5c0484e | 2013-09-23 12:04:45 +1000 | [diff] [blame] | 754 | #endif /* __ASSEMBLY__ */ |
Michael Ellerman | e3f2c6c | 2016-10-14 15:58:28 +1100 | [diff] [blame] | 755 | |
Nicholas Piggin | 325678f | 2021-06-30 17:46:16 +1000 | [diff] [blame] | 756 | #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 Piggin | f23699c | 2021-06-18 01:51:08 +1000 | [diff] [blame] | 763 | #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 Craciun | 1cbf899 | 2018-12-12 16:03:01 +0200 | [diff] [blame] | 771 | #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 Gala | 5f7c690 | 2005-09-09 15:02:25 -0500 | [diff] [blame] | 781 | #endif /* _ASM_POWERPC_PPC_ASM_H */ |