Leif Lindholm | 0c9030d | 2011-12-12 19:31:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/include/asm/opcodes.h |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ASM_ARM_OPCODES_H |
| 10 | #define __ASM_ARM_OPCODES_H |
| 11 | |
| 12 | #ifndef __ASSEMBLY__ |
| 13 | extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); |
| 14 | #endif |
| 15 | |
| 16 | #define ARM_OPCODE_CONDTEST_FAIL 0 |
| 17 | #define ARM_OPCODE_CONDTEST_PASS 1 |
| 18 | #define ARM_OPCODE_CONDTEST_UNCOND 2 |
| 19 | |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 20 | |
| 21 | /* |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 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 | /* |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 49 | * Opcode byteswap helpers |
| 50 | * |
| 51 | * These macros help with converting instructions between a canonical integer |
| 52 | * format and in-memory representation, in an endianness-agnostic manner. |
| 53 | * |
| 54 | * __mem_to_opcode_*() convert from in-memory representation to canonical form. |
| 55 | * __opcode_to_mem_*() convert from canonical form to in-memory representation. |
| 56 | * |
| 57 | * |
| 58 | * Canonical instruction representation: |
| 59 | * |
| 60 | * ARM: 0xKKLLMMNN |
| 61 | * Thumb 16-bit: 0x0000KKLL, where KK < 0xE8 |
| 62 | * Thumb 32-bit: 0xKKLLMMNN, where KK >= 0xE8 |
| 63 | * |
| 64 | * There is no way to distinguish an ARM instruction in canonical representation |
| 65 | * from a Thumb instruction (just as these cannot be distinguished in memory). |
| 66 | * Where this distinction is important, it needs to be tracked separately. |
| 67 | * |
| 68 | * Note that values in the range 0x0000E800..0xE7FFFFFF intentionally do not |
| 69 | * represent any valid Thumb-2 instruction. For this range, |
| 70 | * __opcode_is_thumb32() and __opcode_is_thumb16() will both be false. |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 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. |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 75 | */ |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 76 | #ifdef __ASSEMBLY__ |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 77 | |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 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__ */ |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 86 | |
| 87 | #include <linux/types.h> |
| 88 | #include <linux/swab.h> |
| 89 | |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 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 | |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 100 | #ifdef CONFIG_CPU_ENDIAN_BE8 |
Dave Martin | 57b9da3 | 2012-09-03 13:49:22 +0100 | [diff] [blame] | 101 | |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 102 | #define __opcode_to_mem_arm(x) ___opcode_swab32(x) |
| 103 | #define __opcode_to_mem_thumb16(x) ___opcode_swab16(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) |
Dave Martin | 57b9da3 | 2012-09-03 13:49:22 +0100 | [diff] [blame] | 108 | |
| 109 | #else /* ! CONFIG_CPU_ENDIAN_BE8 */ |
| 110 | |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 111 | #define __opcode_to_mem_arm(x) ___opcode_identity32(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) |
Dave Martin | 57b9da3 | 2012-09-03 13:49:22 +0100 | [diff] [blame] | 115 | #ifndef CONFIG_CPU_ENDIAN_BE32 |
| 116 | /* |
| 117 | * On BE32 systems, using 32-bit accesses to store Thumb instructions will not |
| 118 | * work in all cases, due to alignment constraints. For now, a correct |
| 119 | * version is not provided for BE32. |
| 120 | */ |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 121 | #define __opcode_to_mem_thumb32(x) ___opcode_swahw32(x) |
| 122 | #define ___asm_opcode_to_mem_thumb32(x) ___asm_opcode_swahw32(x) |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 123 | #endif |
| 124 | |
Dave Martin | 57b9da3 | 2012-09-03 13:49:22 +0100 | [diff] [blame] | 125 | #endif /* ! CONFIG_CPU_ENDIAN_BE8 */ |
| 126 | |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 127 | #define __mem_to_opcode_arm(x) __opcode_to_mem_arm(x) |
| 128 | #define __mem_to_opcode_thumb16(x) __opcode_to_mem_thumb16(x) |
Dave Martin | 57b9da3 | 2012-09-03 13:49:22 +0100 | [diff] [blame] | 129 | #ifndef CONFIG_CPU_ENDIAN_BE32 |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 130 | #define __mem_to_opcode_thumb32(x) __opcode_to_mem_thumb32(x) |
Dave Martin | 57b9da3 | 2012-09-03 13:49:22 +0100 | [diff] [blame] | 131 | #endif |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 132 | |
| 133 | /* Operations specific to Thumb opcodes */ |
| 134 | |
| 135 | /* Instruction size checks: */ |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 136 | #define __opcode_is_thumb32(x) ( \ |
| 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 | ) |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 144 | |
| 145 | /* Operations to construct or split 32-bit Thumb instructions: */ |
Dave Martin | 0ce3de2 | 2012-09-03 13:49:23 +0100 | [diff] [blame^] | 146 | #define __opcode_thumb32_first(x) (___opcode_identity16((x) >> 16)) |
| 147 | #define __opcode_thumb32_second(x) (___opcode_identity16(x)) |
| 148 | #define __opcode_thumb32_compose(first, second) ( \ |
| 149 | (___opcode_identity32(___opcode_identity16(first)) << 16) \ |
| 150 | | ___opcode_identity32(___opcode_identity16(second)) \ |
| 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 | ) |
Dave Martin | f5f5195 | 2012-02-01 10:42:22 +0100 | [diff] [blame] | 158 | |
Leif Lindholm | 0c9030d | 2011-12-12 19:31:55 +0100 | [diff] [blame] | 159 | #endif /* __ASM_ARM_OPCODES_H */ |