1
2
3
4
5
6
7
8
9#ifndef __ASM_ARM_OPCODES_H
10#define __ASM_ARM_OPCODES_H
11
12#ifndef __ASSEMBLY__
13#include <linux/linkage.h>
14extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
15#endif
16
17#define ARM_OPCODE_CONDTEST_FAIL 0
18#define ARM_OPCODE_CONDTEST_PASS 1
19#define ARM_OPCODE_CONDTEST_UNCOND 2
20
21
22
23
24
25
26
27#define ___asm_opcode_swab32(x) ( \
28 (((x) << 24) & 0xFF000000) \
29 | (((x) << 8) & 0x00FF0000) \
30 | (((x) >> 8) & 0x0000FF00) \
31 | (((x) >> 24) & 0x000000FF) \
32)
33#define ___asm_opcode_swab16(x) ( \
34 (((x) << 8) & 0xFF00) \
35 | (((x) >> 8) & 0x00FF) \
36)
37#define ___asm_opcode_swahb32(x) ( \
38 (((x) << 8) & 0xFF00FF00) \
39 | (((x) >> 8) & 0x00FF00FF) \
40)
41#define ___asm_opcode_swahw32(x) ( \
42 (((x) << 16) & 0xFFFF0000) \
43 | (((x) >> 16) & 0x0000FFFF) \
44)
45#define ___asm_opcode_identity32(x) ((x) & 0xFFFFFFFF)
46#define ___asm_opcode_identity16(x) ((x) & 0xFFFF)
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77#ifdef __ASSEMBLY__
78
79#define ___opcode_swab32(x) ___asm_opcode_swab32(x)
80#define ___opcode_swab16(x) ___asm_opcode_swab16(x)
81#define ___opcode_swahb32(x) ___asm_opcode_swahb32(x)
82#define ___opcode_swahw32(x) ___asm_opcode_swahw32(x)
83#define ___opcode_identity32(x) ___asm_opcode_identity32(x)
84#define ___opcode_identity16(x) ___asm_opcode_identity16(x)
85
86#else
87
88#include <linux/types.h>
89#include <linux/swab.h>
90
91#define ___opcode_swab32(x) swab32(x)
92#define ___opcode_swab16(x) swab16(x)
93#define ___opcode_swahb32(x) swahb32(x)
94#define ___opcode_swahw32(x) swahw32(x)
95#define ___opcode_identity32(x) ((u32)(x))
96#define ___opcode_identity16(x) ((u16)(x))
97
98#endif
99
100
101#ifdef CONFIG_CPU_ENDIAN_BE8
102
103#define __opcode_to_mem_arm(x) ___opcode_swab32(x)
104#define __opcode_to_mem_thumb16(x) ___opcode_swab16(x)
105#define __opcode_to_mem_thumb32(x) ___opcode_swahb32(x)
106#define ___asm_opcode_to_mem_arm(x) ___asm_opcode_swab32(x)
107#define ___asm_opcode_to_mem_thumb16(x) ___asm_opcode_swab16(x)
108#define ___asm_opcode_to_mem_thumb32(x) ___asm_opcode_swahb32(x)
109
110#else
111
112#define __opcode_to_mem_arm(x) ___opcode_identity32(x)
113#define __opcode_to_mem_thumb16(x) ___opcode_identity16(x)
114#define ___asm_opcode_to_mem_arm(x) ___asm_opcode_identity32(x)
115#define ___asm_opcode_to_mem_thumb16(x) ___asm_opcode_identity16(x)
116#ifndef CONFIG_CPU_ENDIAN_BE32
117
118
119
120
121
122#define __opcode_to_mem_thumb32(x) ___opcode_swahw32(x)
123#define ___asm_opcode_to_mem_thumb32(x) ___asm_opcode_swahw32(x)
124#endif
125
126#endif
127
128#define __mem_to_opcode_arm(x) __opcode_to_mem_arm(x)
129#define __mem_to_opcode_thumb16(x) __opcode_to_mem_thumb16(x)
130#ifndef CONFIG_CPU_ENDIAN_BE32
131#define __mem_to_opcode_thumb32(x) __opcode_to_mem_thumb32(x)
132#endif
133
134
135
136
137#define __opcode_is_thumb32(x) ( \
138 ((x) & 0xF8000000) == 0xE8000000 \
139 || ((x) & 0xF0000000) == 0xF0000000 \
140)
141#define __opcode_is_thumb16(x) ( \
142 ((x) & 0xFFFF0000) == 0 \
143 && !(((x) & 0xF800) == 0xE800 || ((x) & 0xF000) == 0xF000) \
144)
145
146
147#define __opcode_thumb32_first(x) (___opcode_identity16((x) >> 16))
148#define __opcode_thumb32_second(x) (___opcode_identity16(x))
149#define __opcode_thumb32_compose(first, second) ( \
150 (___opcode_identity32(___opcode_identity16(first)) << 16) \
151 | ___opcode_identity32(___opcode_identity16(second)) \
152)
153#define ___asm_opcode_thumb32_first(x) (___asm_opcode_identity16((x) >> 16))
154#define ___asm_opcode_thumb32_second(x) (___asm_opcode_identity16(x))
155#define ___asm_opcode_thumb32_compose(first, second) ( \
156 (___asm_opcode_identity32(___asm_opcode_identity16(first)) << 16) \
157 | ___asm_opcode_identity32(___asm_opcode_identity16(second)) \
158)
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200#include <linux/stringify.h>
201
202#define __inst_arm(x) ___inst_arm(___asm_opcode_to_mem_arm(x))
203#define __inst_thumb32(x) ___inst_thumb32( \
204 ___asm_opcode_to_mem_thumb16(___asm_opcode_thumb32_first(x)), \
205 ___asm_opcode_to_mem_thumb16(___asm_opcode_thumb32_second(x)) \
206)
207#define __inst_thumb16(x) ___inst_thumb16(___asm_opcode_to_mem_thumb16(x))
208
209#ifdef CONFIG_THUMB2_KERNEL
210#define __inst_arm_thumb16(arm_opcode, thumb_opcode) \
211 __inst_thumb16(thumb_opcode)
212#define __inst_arm_thumb32(arm_opcode, thumb_opcode) \
213 __inst_thumb32(thumb_opcode)
214#else
215#define __inst_arm_thumb16(arm_opcode, thumb_opcode) __inst_arm(arm_opcode)
216#define __inst_arm_thumb32(arm_opcode, thumb_opcode) __inst_arm(arm_opcode)
217#endif
218
219
220#ifdef __ASSEMBLY__
221#define ___inst_arm(x) .long x
222#define ___inst_thumb16(x) .short x
223#define ___inst_thumb32(first, second) .short first, second
224#else
225#define ___inst_arm(x) ".long " __stringify(x) "\n\t"
226#define ___inst_thumb16(x) ".short " __stringify(x) "\n\t"
227#define ___inst_thumb32(first, second) \
228 ".short " __stringify(first) ", " __stringify(second) "\n\t"
229#endif
230
231#endif
232