diff options
| -rw-r--r-- | arch/arm/include/asm/opcodes.h | 97 |
1 files changed, 82 insertions, 15 deletions
diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h index 6bf54f9411a6..f57e417cab95 100644 --- a/arch/arm/include/asm/opcodes.h +++ b/arch/arm/include/asm/opcodes.h | |||
| @@ -19,6 +19,33 @@ extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | /* | 21 | /* |
| 22 | * Assembler opcode byteswap helpers. | ||
| 23 | * These are only intended for use by this header: don't use them directly, | ||
| 24 | * because they will be suboptimal in most cases. | ||
| 25 | */ | ||
| 26 | #define ___asm_opcode_swab32(x) ( \ | ||
| 27 | (((x) << 24) & 0xFF000000) \ | ||
| 28 | | (((x) << 8) & 0x00FF0000) \ | ||
| 29 | | (((x) >> 8) & 0x0000FF00) \ | ||
| 30 | | (((x) >> 24) & 0x000000FF) \ | ||
| 31 | ) | ||
| 32 | #define ___asm_opcode_swab16(x) ( \ | ||
| 33 | (((x) << 8) & 0xFF00) \ | ||
| 34 | | (((x) >> 8) & 0x00FF) \ | ||
| 35 | ) | ||
| 36 | #define ___asm_opcode_swahb32(x) ( \ | ||
| 37 | (((x) << 8) & 0xFF00FF00) \ | ||
| 38 | | (((x) >> 8) & 0x00FF00FF) \ | ||
| 39 | ) | ||
| 40 | #define ___asm_opcode_swahw32(x) ( \ | ||
| 41 | (((x) << 16) & 0xFFFF0000) \ | ||
| 42 | | (((x) >> 16) & 0x0000FFFF) \ | ||
| 43 | ) | ||
| 44 | #define ___asm_opcode_identity32(x) ((x) & 0xFFFFFFFF) | ||
| 45 | #define ___asm_opcode_identity16(x) ((x) & 0xFFFF) | ||
| 46 | |||
| 47 | |||
| 48 | /* | ||
| 22 | * Opcode byteswap helpers | 49 | * Opcode byteswap helpers |
| 23 | * | 50 | * |
| 24 | * These macros help with converting instructions between a canonical integer | 51 | * These macros help with converting instructions between a canonical integer |
| @@ -41,30 +68,58 @@ extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); | |||
| 41 | * Note that values in the range 0x0000E800..0xE7FFFFFF intentionally do not | 68 | * Note that values in the range 0x0000E800..0xE7FFFFFF intentionally do not |
| 42 | * represent any valid Thumb-2 instruction. For this range, | 69 | * represent any valid Thumb-2 instruction. For this range, |
| 43 | * __opcode_is_thumb32() and __opcode_is_thumb16() will both be false. | 70 | * __opcode_is_thumb32() and __opcode_is_thumb16() will both be false. |
| 71 | * | ||
| 72 | * The ___asm variants are intended only for use by this header, in situations | ||
| 73 | * involving inline assembler. For .S files, the normal __opcode_*() macros | ||
| 74 | * should do the right thing. | ||
| 44 | */ | 75 | */ |
| 76 | #ifdef __ASSEMBLY__ | ||
| 45 | 77 | ||
| 46 | #ifndef __ASSEMBLY__ | 78 | #define ___opcode_swab32(x) ___asm_opcode_swab32(x) |
| 79 | #define ___opcode_swab16(x) ___asm_opcode_swab16(x) | ||
| 80 | #define ___opcode_swahb32(x) ___asm_opcode_swahb32(x) | ||
| 81 | #define ___opcode_swahw32(x) ___asm_opcode_swahw32(x) | ||
| 82 | #define ___opcode_identity32(x) ___asm_opcode_identity32(x) | ||
| 83 | #define ___opcode_identity16(x) ___asm_opcode_identity16(x) | ||
| 84 | |||
| 85 | #else /* ! __ASSEMBLY__ */ | ||
| 47 | 86 | ||
| 48 | #include <linux/types.h> | 87 | #include <linux/types.h> |
| 49 | #include <linux/swab.h> | 88 | #include <linux/swab.h> |
| 50 | 89 | ||
| 90 | #define ___opcode_swab32(x) swab32(x) | ||
| 91 | #define ___opcode_swab16(x) swab16(x) | ||
| 92 | #define ___opcode_swahb32(x) swahb32(x) | ||
| 93 | #define ___opcode_swahw32(x) swahw32(x) | ||
| 94 | #define ___opcode_identity32(x) ((u32)(x)) | ||
| 95 | #define ___opcode_identity16(x) ((u16)(x)) | ||
| 96 | |||
| 97 | #endif /* ! __ASSEMBLY__ */ | ||
| 98 | |||
| 99 | |||
| 51 | #ifdef CONFIG_CPU_ENDIAN_BE8 | 100 | #ifdef CONFIG_CPU_ENDIAN_BE8 |
| 52 | 101 | ||
| 53 | #define __opcode_to_mem_arm(x) swab32(x) | 102 | #define __opcode_to_mem_arm(x) ___opcode_swab32(x) |
| 54 | #define __opcode_to_mem_thumb16(x) swab16(x) | 103 | #define __opcode_to_mem_thumb16(x) ___opcode_swab16(x) |
| 55 | #define __opcode_to_mem_thumb32(x) swahb32(x) | 104 | #define __opcode_to_mem_thumb32(x) ___opcode_swahb32(x) |
| 105 | #define ___asm_opcode_to_mem_arm(x) ___asm_opcode_swab32(x) | ||
| 106 | #define ___asm_opcode_to_mem_thumb16(x) ___asm_opcode_swab16(x) | ||
| 107 | #define ___asm_opcode_to_mem_thumb32(x) ___asm_opcode_swahb32(x) | ||
| 56 | 108 | ||
| 57 | #else /* ! CONFIG_CPU_ENDIAN_BE8 */ | 109 | #else /* ! CONFIG_CPU_ENDIAN_BE8 */ |
| 58 | 110 | ||
| 59 | #define __opcode_to_mem_arm(x) ((u32)(x)) | 111 | #define __opcode_to_mem_arm(x) ___opcode_identity32(x) |
| 60 | #define __opcode_to_mem_thumb16(x) ((u16)(x)) | 112 | #define __opcode_to_mem_thumb16(x) ___opcode_identity16(x) |
| 113 | #define ___asm_opcode_to_mem_arm(x) ___asm_opcode_identity32(x) | ||
| 114 | #define ___asm_opcode_to_mem_thumb16(x) ___asm_opcode_identity16(x) | ||
| 61 | #ifndef CONFIG_CPU_ENDIAN_BE32 | 115 | #ifndef CONFIG_CPU_ENDIAN_BE32 |
| 62 | /* | 116 | /* |
| 63 | * On BE32 systems, using 32-bit accesses to store Thumb instructions will not | 117 | * On BE32 systems, using 32-bit accesses to store Thumb instructions will not |
| 64 | * work in all cases, due to alignment constraints. For now, a correct | 118 | * work in all cases, due to alignment constraints. For now, a correct |
| 65 | * version is not provided for BE32. | 119 | * version is not provided for BE32. |
| 66 | */ | 120 | */ |
| 67 | #define __opcode_to_mem_thumb32(x) swahw32(x) | 121 | #define __opcode_to_mem_thumb32(x) ___opcode_swahw32(x) |
| 122 | #define ___asm_opcode_to_mem_thumb32(x) ___asm_opcode_swahw32(x) | ||
| 68 | #endif | 123 | #endif |
| 69 | 124 | ||
| 70 | #endif /* ! CONFIG_CPU_ENDIAN_BE8 */ | 125 | #endif /* ! CONFIG_CPU_ENDIAN_BE8 */ |
| @@ -78,15 +133,27 @@ extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); | |||
| 78 | /* Operations specific to Thumb opcodes */ | 133 | /* Operations specific to Thumb opcodes */ |
| 79 | 134 | ||
| 80 | /* Instruction size checks: */ | 135 | /* Instruction size checks: */ |
| 81 | #define __opcode_is_thumb32(x) ((u32)(x) >= 0xE8000000UL) | 136 | #define __opcode_is_thumb32(x) ( \ |
| 82 | #define __opcode_is_thumb16(x) ((u32)(x) < 0xE800UL) | 137 | ((x) & 0xF8000000) == 0xE8000000 \ |
| 138 | || ((x) & 0xF0000000) == 0xF0000000 \ | ||
| 139 | ) | ||
| 140 | #define __opcode_is_thumb16(x) ( \ | ||
| 141 | ((x) & 0xFFFF0000) == 0 \ | ||
| 142 | && !(((x) & 0xF800) == 0xE800 || ((x) & 0xF000) == 0xF000) \ | ||
| 143 | ) | ||
| 83 | 144 | ||
| 84 | /* Operations to construct or split 32-bit Thumb instructions: */ | 145 | /* Operations to construct or split 32-bit Thumb instructions: */ |
| 85 | #define __opcode_thumb32_first(x) ((u16)((x) >> 16)) | 146 | #define __opcode_thumb32_first(x) (___opcode_identity16((x) >> 16)) |
| 86 | #define __opcode_thumb32_second(x) ((u16)(x)) | 147 | #define __opcode_thumb32_second(x) (___opcode_identity16(x)) |
| 87 | #define __opcode_thumb32_compose(first, second) \ | 148 | #define __opcode_thumb32_compose(first, second) ( \ |
| 88 | (((u32)(u16)(first) << 16) | (u32)(u16)(second)) | 149 | (___opcode_identity32(___opcode_identity16(first)) << 16) \ |
| 89 | 150 | | ___opcode_identity32(___opcode_identity16(second)) \ | |
| 90 | #endif /* __ASSEMBLY__ */ | 151 | ) |
| 152 | #define ___asm_opcode_thumb32_first(x) (___asm_opcode_identity16((x) >> 16)) | ||
| 153 | #define ___asm_opcode_thumb32_second(x) (___asm_opcode_identity16(x)) | ||
| 154 | #define ___asm_opcode_thumb32_compose(first, second) ( \ | ||
| 155 | (___asm_opcode_identity32(___asm_opcode_identity16(first)) << 16) \ | ||
| 156 | | ___asm_opcode_identity32(___asm_opcode_identity16(second)) \ | ||
| 157 | ) | ||
| 91 | 158 | ||
| 92 | #endif /* __ASM_ARM_OPCODES_H */ | 159 | #endif /* __ASM_ARM_OPCODES_H */ |
