1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 3 * arch/arm/include/asm/opcodes.h 4 */ 5 6 #ifndef __ASM_ARM_OPCODES_H 7 #define __ASM_ARM_OPCODES_H 8 9 #ifndef __ASSEMBLY__ 10 #include <linux/linkage.h> 11 extern asmlinkage unsigned int arm_check_condi 12 #endif 13 14 #define ARM_OPCODE_CONDTEST_FAIL 0 15 #define ARM_OPCODE_CONDTEST_PASS 1 16 #define ARM_OPCODE_CONDTEST_UNCOND 2 17 18 19 /* 20 * Assembler opcode byteswap helpers. 21 * These are only intended for use by this hea 22 * because they will be suboptimal in most cas 23 */ 24 #define ___asm_opcode_swab32(x) ( \ 25 (((x) << 24) & 0xFF000000) \ 26 | (((x) << 8) & 0x00FF0000) \ 27 | (((x) >> 8) & 0x0000FF00) \ 28 | (((x) >> 24) & 0x000000FF) \ 29 ) 30 #define ___asm_opcode_swab16(x) ( \ 31 (((x) << 8) & 0xFF00) \ 32 | (((x) >> 8) & 0x00FF) \ 33 ) 34 #define ___asm_opcode_swahb32(x) ( \ 35 (((x) << 8) & 0xFF00FF00) \ 36 | (((x) >> 8) & 0x00FF00FF) \ 37 ) 38 #define ___asm_opcode_swahw32(x) ( \ 39 (((x) << 16) & 0xFFFF0000) \ 40 | (((x) >> 16) & 0x0000FFFF) \ 41 ) 42 #define ___asm_opcode_identity32(x) ((x) & 0xF 43 #define ___asm_opcode_identity16(x) ((x) & 0xF 44 45 46 /* 47 * Opcode byteswap helpers 48 * 49 * These macros help with converting instructi 50 * format and in-memory representation, in an 51 * 52 * __mem_to_opcode_*() convert from in-memory 53 * __opcode_to_mem_*() convert from canonical 54 * 55 * 56 * Canonical instruction representation: 57 * 58 * ARM: 0xKKLLMMNN 59 * Thumb 16-bit: 0x0000KKLL, where KK < 60 * Thumb 32-bit: 0xKKLLMMNN, where KK > 61 * 62 * There is no way to distinguish an ARM instr 63 * from a Thumb instruction (just as these can 64 * Where this distinction is important, it nee 65 * 66 * Note that values in the range 0x0000E800..0 67 * represent any valid Thumb-2 instruction. F 68 * __opcode_is_thumb32() and __opcode_is_thumb 69 * 70 * The ___asm variants are intended only for u 71 * involving inline assembler. For .S files, 72 * should do the right thing. 73 */ 74 #ifdef __ASSEMBLY__ 75 76 #define ___opcode_swab32(x) ___asm_opcode_swab 77 #define ___opcode_swab16(x) ___asm_opcode_swab 78 #define ___opcode_swahb32(x) ___asm_opcode_swa 79 #define ___opcode_swahw32(x) ___asm_opcode_swa 80 #define ___opcode_identity32(x) ___asm_opcode_ 81 #define ___opcode_identity16(x) ___asm_opcode_ 82 83 #else /* ! __ASSEMBLY__ */ 84 85 #include <linux/types.h> 86 #include <linux/swab.h> 87 88 #define ___opcode_swab32(x) swab32(x) 89 #define ___opcode_swab16(x) swab16(x) 90 #define ___opcode_swahb32(x) swahb32(x) 91 #define ___opcode_swahw32(x) swahw32(x) 92 #define ___opcode_identity32(x) ((u32)(x)) 93 #define ___opcode_identity16(x) ((u16)(x)) 94 95 #endif /* ! __ASSEMBLY__ */ 96 97 98 #ifdef CONFIG_CPU_ENDIAN_BE8 99 100 #define __opcode_to_mem_arm(x) ___opcode_swab3 101 #define __opcode_to_mem_thumb16(x) ___opcode_s 102 #define __opcode_to_mem_thumb32(x) ___opcode_s 103 #define ___asm_opcode_to_mem_arm(x) ___asm_opc 104 #define ___asm_opcode_to_mem_thumb16(x) ___asm 105 #define ___asm_opcode_to_mem_thumb32(x) ___asm 106 107 #else /* ! CONFIG_CPU_ENDIAN_BE8 */ 108 109 #define __opcode_to_mem_arm(x) ___opcode_ident 110 #define __opcode_to_mem_thumb16(x) ___opcode_i 111 #define ___asm_opcode_to_mem_arm(x) ___asm_opc 112 #define ___asm_opcode_to_mem_thumb16(x) ___asm 113 #ifdef CONFIG_CPU_ENDIAN_BE32 114 #ifndef __ASSEMBLY__ 115 /* 116 * On BE32 systems, using 32-bit accesses to s 117 * work in all cases, due to alignment constra 118 * version is not provided for BE32, but the p 119 * to compile patch.c. 120 */ 121 extern __u32 __opcode_to_mem_thumb32(__u32); 122 #endif 123 #else 124 #define __opcode_to_mem_thumb32(x) ___opcode_s 125 #define ___asm_opcode_to_mem_thumb32(x) ___asm 126 #endif 127 128 #endif /* ! CONFIG_CPU_ENDIAN_BE8 */ 129 130 #define __mem_to_opcode_arm(x) __opcode_to_mem 131 #define __mem_to_opcode_thumb16(x) __opcode_to 132 #ifndef CONFIG_CPU_ENDIAN_BE32 133 #define __mem_to_opcode_thumb32(x) __opcode_to 134 #endif 135 136 /* Operations specific to Thumb opcodes */ 137 138 /* Instruction size checks: */ 139 #define __opcode_is_thumb32(x) ( 140 ((x) & 0xF8000000) == 0xE8000000 141 || ((x) & 0xF0000000) == 0xF0000000 142 ) 143 #define __opcode_is_thumb16(x) ( 144 ((x) & 0xFFFF0000) == 0 145 && !(((x) & 0xF800) == 0xE800 || ((x) 146 ) 147 148 /* Operations to construct or split 32-bit Thu 149 #define __opcode_thumb32_first(x) (___opcode_i 150 #define __opcode_thumb32_second(x) (___opcode_ 151 #define __opcode_thumb32_compose(first, second 152 (___opcode_identity32(___opcode_iden 153 | ___opcode_identity32(___opcode_ident 154 ) 155 #define ___asm_opcode_thumb32_first(x) (___asm 156 #define ___asm_opcode_thumb32_second(x) (___as 157 #define ___asm_opcode_thumb32_compose(first, s 158 (___asm_opcode_identity32(___asm_opc 159 | ___asm_opcode_identity32(___asm_opco 160 ) 161 162 /* 163 * Opcode injection helpers 164 * 165 * In rare cases it is necessary to assemble a 166 * assembler does not support directly, or whi 167 * rejected because of the CFLAGS or AFLAGS us 168 * file. 169 * 170 * Before using these macros, consider careful 171 * instead to change the build flags for your 172 * makes sense to support old assembler versio 173 * particular kernel feature. 174 * 175 * The macros defined here should only be used 176 * alternative. 177 * 178 * 179 * __inst_arm(x): emit the specified ARM opcod 180 * __inst_thumb16(x): emit the specified 16-bi 181 * __inst_thumb32(x): emit the specified 32-bi 182 * 183 * __inst_arm_thumb16(arm, thumb): emit either 184 * 16-bit Thumb opcode, depending on whet 185 * kernel is being built 186 * 187 * __inst_arm_thumb32(arm, thumb): emit either 188 * 32-bit Thumb opcode, depending on whet 189 * kernel is being built 190 * 191 * 192 * Note that using these macros directly is po 193 * should use them to define human-readable wr 194 * instructions that you care about. In code 195 * above, you can usually use the __inst_arm_t 196 * specify the ARM and Thumb alternatives at t 197 * that the correct opcode gets emitted depend 198 * used for the kernel build. 199 * 200 * Look at opcodes-virt.h for an example of ho 201 */ 202 #include <linux/stringify.h> 203 204 #define __inst_arm(x) ___inst_arm(___asm_opcod 205 #define __inst_thumb32(x) ___inst_thumb32( 206 ___asm_opcode_to_mem_thumb16(___asm_op 207 ___asm_opcode_to_mem_thumb16(___asm_op 208 ) 209 #define __inst_thumb16(x) ___inst_thumb16(___a 210 211 #ifdef CONFIG_THUMB2_KERNEL 212 #define __inst_arm_thumb16(arm_opcode, thumb_o 213 __inst_thumb16(thumb_opcode) 214 #define __inst_arm_thumb32(arm_opcode, thumb_o 215 __inst_thumb32(thumb_opcode) 216 #else 217 #define __inst_arm_thumb16(arm_opcode, thumb_o 218 #define __inst_arm_thumb32(arm_opcode, thumb_o 219 #endif 220 221 /* Helpers for the helpers. Don't use these d 222 #ifdef __ASSEMBLY__ 223 #define ___inst_arm(x) .long x 224 #define ___inst_thumb16(x) .short x 225 #define ___inst_thumb32(first, second) .short 226 #else 227 #define ___inst_arm(x) ".long " __stringify(x) 228 #define ___inst_thumb16(x) ".short " __stringi 229 #define ___inst_thumb32(first, second) \ 230 ".short " __stringify(first) ", " __st 231 #endif 232 233 #endif /* __ASM_ARM_OPCODES_H */ 234
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.