]>
Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
f17c130b | 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
ebd1c875 | 3 | 2004, 2005, 2006 |
b99bd4ef NC |
4 | Free Software Foundation, Inc. |
5 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) | |
6 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 7 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
8 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
9 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
10 | |
11 | This file is part of GAS, the GNU Assembler. | |
12 | ||
13 | GAS is free software; you can redistribute it and/or modify | |
14 | it under the terms of the GNU General Public License as published by | |
15 | the Free Software Foundation; either version 2, or (at your option) | |
16 | any later version. | |
17 | ||
18 | GAS is distributed in the hope that it will be useful, | |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c19d1205 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
21 | GNU General Public License for more details. |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
24 | along with GAS; see the file COPYING. If not, write to the Free | |
699d2810 NC |
25 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
26 | 02110-1301, USA. */ | |
b99bd4ef | 27 | |
5287ad62 | 28 | #include <limits.h> |
037e8744 | 29 | #include <stdarg.h> |
c19d1205 | 30 | #define NO_RELOC 0 |
b99bd4ef | 31 | #include "as.h" |
3882b010 | 32 | #include "safe-ctype.h" |
b99bd4ef NC |
33 | #include "subsegs.h" |
34 | #include "obstack.h" | |
b99bd4ef | 35 | |
f263249b RE |
36 | #include "opcode/arm.h" |
37 | ||
b99bd4ef NC |
38 | #ifdef OBJ_ELF |
39 | #include "elf/arm.h" | |
40 | #include "dwarf2dbg.h" | |
a394c00f | 41 | #include "dw2gencfi.h" |
b99bd4ef NC |
42 | #endif |
43 | ||
7ed4c4c5 | 44 | /* XXX Set this to 1 after the next binutils release. */ |
03b1477f RE |
45 | #define WARN_DEPRECATED 0 |
46 | ||
7ed4c4c5 NC |
47 | #ifdef OBJ_ELF |
48 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
49 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
50 | ||
51 | /* This structure holds the unwinding state. */ | |
52 | ||
53 | static struct | |
54 | { | |
c19d1205 ZW |
55 | symbolS * proc_start; |
56 | symbolS * table_entry; | |
57 | symbolS * personality_routine; | |
58 | int personality_index; | |
7ed4c4c5 | 59 | /* The segment containing the function. */ |
c19d1205 ZW |
60 | segT saved_seg; |
61 | subsegT saved_subseg; | |
7ed4c4c5 NC |
62 | /* Opcodes generated from this function. */ |
63 | unsigned char * opcodes; | |
c19d1205 ZW |
64 | int opcode_count; |
65 | int opcode_alloc; | |
7ed4c4c5 | 66 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 67 | offsetT frame_size; |
7ed4c4c5 NC |
68 | /* We don't add stack adjustment opcodes immediately so that we can merge |
69 | multiple adjustments. We can also omit the final adjustment | |
70 | when using a frame pointer. */ | |
c19d1205 | 71 | offsetT pending_offset; |
7ed4c4c5 | 72 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
73 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
74 | offsetT fp_offset; | |
75 | int fp_reg; | |
7ed4c4c5 | 76 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 77 | unsigned fp_used:1; |
7ed4c4c5 | 78 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 79 | unsigned sp_restored:1; |
7ed4c4c5 NC |
80 | } unwind; |
81 | ||
8b1ad454 NC |
82 | /* Bit N indicates that an R_ARM_NONE relocation has been output for |
83 | __aeabi_unwind_cpp_prN already if set. This enables dependencies to be | |
84 | emitted only once per section, to save unnecessary bloat. */ | |
85 | static unsigned int marked_pr_dependency = 0; | |
86 | ||
87 | #endif /* OBJ_ELF */ | |
88 | ||
4962c51a MS |
89 | /* Results from operand parsing worker functions. */ |
90 | ||
91 | typedef enum | |
92 | { | |
93 | PARSE_OPERAND_SUCCESS, | |
94 | PARSE_OPERAND_FAIL, | |
95 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
96 | } parse_operand_result; | |
97 | ||
33a392fb PB |
98 | enum arm_float_abi |
99 | { | |
100 | ARM_FLOAT_ABI_HARD, | |
101 | ARM_FLOAT_ABI_SOFTFP, | |
102 | ARM_FLOAT_ABI_SOFT | |
103 | }; | |
104 | ||
c19d1205 | 105 | /* Types of processor to assemble for. */ |
b99bd4ef NC |
106 | #ifndef CPU_DEFAULT |
107 | #if defined __XSCALE__ | |
e74cfd16 | 108 | #define CPU_DEFAULT ARM_ARCH_XSCALE |
b99bd4ef NC |
109 | #else |
110 | #if defined __thumb__ | |
e74cfd16 | 111 | #define CPU_DEFAULT ARM_ARCH_V5T |
b99bd4ef NC |
112 | #endif |
113 | #endif | |
114 | #endif | |
115 | ||
116 | #ifndef FPU_DEFAULT | |
c820d418 MM |
117 | # ifdef TE_LINUX |
118 | # define FPU_DEFAULT FPU_ARCH_FPA | |
119 | # elif defined (TE_NetBSD) | |
120 | # ifdef OBJ_ELF | |
121 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
122 | # else | |
123 | /* Legacy a.out format. */ | |
124 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
125 | # endif | |
4e7fd91e PB |
126 | # elif defined (TE_VXWORKS) |
127 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
128 | # else |
129 | /* For backwards compatibility, default to FPA. */ | |
130 | # define FPU_DEFAULT FPU_ARCH_FPA | |
131 | # endif | |
132 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 133 | |
c19d1205 | 134 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 135 | |
e74cfd16 PB |
136 | static arm_feature_set cpu_variant; |
137 | static arm_feature_set arm_arch_used; | |
138 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 139 | |
b99bd4ef | 140 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
141 | static int uses_apcs_26 = FALSE; |
142 | static int atpcs = FALSE; | |
b34976b6 AM |
143 | static int support_interwork = FALSE; |
144 | static int uses_apcs_float = FALSE; | |
c19d1205 | 145 | static int pic_code = FALSE; |
03b1477f RE |
146 | |
147 | /* Variables that we set while parsing command-line options. Once all | |
148 | options have been read we re-process these values to set the real | |
149 | assembly flags. */ | |
e74cfd16 PB |
150 | static const arm_feature_set *legacy_cpu = NULL; |
151 | static const arm_feature_set *legacy_fpu = NULL; | |
152 | ||
153 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
154 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
155 | static const arm_feature_set *march_cpu_opt = NULL; | |
156 | static const arm_feature_set *march_fpu_opt = NULL; | |
157 | static const arm_feature_set *mfpu_opt = NULL; | |
158 | ||
159 | /* Constants for known architecture features. */ | |
160 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
161 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
162 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
163 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
164 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
165 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
166 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
167 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
168 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
169 | ||
170 | #ifdef CPU_DEFAULT | |
171 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
172 | #endif | |
173 | ||
174 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
175 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
176 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
177 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
178 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
179 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
180 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
181 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
182 | static const arm_feature_set arm_ext_v4t_5 = | |
183 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
184 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
185 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
186 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
187 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
188 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
189 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
190 | static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0); | |
191 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); | |
62b3e311 PB |
192 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
193 | static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0); | |
194 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0); | |
195 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0); | |
196 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0); | |
197 | static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0); | |
e74cfd16 PB |
198 | |
199 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
200 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
201 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
202 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
203 | ||
204 | static const arm_feature_set arm_cext_iwmmxt = | |
205 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
206 | static const arm_feature_set arm_cext_xscale = | |
207 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
208 | static const arm_feature_set arm_cext_maverick = | |
209 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
210 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
211 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
212 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
213 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
214 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
215 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
5287ad62 JB |
216 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
217 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); | |
218 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
219 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
e74cfd16 | 220 | |
33a392fb | 221 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
222 | /* Record user cpu selection for object attributes. */ |
223 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
224 | /* Must be long enough to hold any of the names in arm_cpus. */ |
225 | static char selected_cpu_name[16]; | |
7cc69913 | 226 | #ifdef OBJ_ELF |
deeaaff8 DJ |
227 | # ifdef EABI_DEFAULT |
228 | static int meabi_flags = EABI_DEFAULT; | |
229 | # else | |
d507cf36 | 230 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 231 | # endif |
7cc69913 | 232 | #endif |
b99bd4ef | 233 | |
b99bd4ef | 234 | #ifdef OBJ_ELF |
c19d1205 | 235 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
236 | symbolS * GOT_symbol; |
237 | #endif | |
238 | ||
b99bd4ef NC |
239 | /* 0: assemble for ARM, |
240 | 1: assemble for Thumb, | |
241 | 2: assemble for Thumb even though target CPU does not support thumb | |
242 | instructions. */ | |
243 | static int thumb_mode = 0; | |
244 | ||
c19d1205 ZW |
245 | /* If unified_syntax is true, we are processing the new unified |
246 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
247 | ||
248 | - Immediate operands do not require a # prefix. | |
249 | - Conditional affixes always appear at the end of the | |
250 | instruction. (For backward compatibility, those instructions | |
251 | that formerly had them in the middle, continue to accept them | |
252 | there.) | |
253 | - The IT instruction may appear, and if it does is validated | |
254 | against subsequent conditional affixes. It does not generate | |
255 | machine code. | |
256 | ||
257 | Important differences from the old Thumb mode: | |
258 | ||
259 | - Immediate operands do not require a # prefix. | |
260 | - Most of the V6T2 instructions are only available in unified mode. | |
261 | - The .N and .W suffixes are recognized and honored (it is an error | |
262 | if they cannot be honored). | |
263 | - All instructions set the flags if and only if they have an 's' affix. | |
264 | - Conditional affixes may be used. They are validated against | |
265 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
266 | conditional affix except in the scope of an IT instruction. */ | |
267 | ||
268 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 269 | |
5287ad62 JB |
270 | enum neon_el_type |
271 | { | |
dcbf9037 | 272 | NT_invtype, |
5287ad62 JB |
273 | NT_untyped, |
274 | NT_integer, | |
275 | NT_float, | |
276 | NT_poly, | |
277 | NT_signed, | |
dcbf9037 | 278 | NT_unsigned |
5287ad62 JB |
279 | }; |
280 | ||
281 | struct neon_type_el | |
282 | { | |
283 | enum neon_el_type type; | |
284 | unsigned size; | |
285 | }; | |
286 | ||
287 | #define NEON_MAX_TYPE_ELS 4 | |
288 | ||
289 | struct neon_type | |
290 | { | |
291 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
292 | unsigned elems; | |
293 | }; | |
294 | ||
b99bd4ef NC |
295 | struct arm_it |
296 | { | |
c19d1205 | 297 | const char * error; |
b99bd4ef | 298 | unsigned long instruction; |
c19d1205 ZW |
299 | int size; |
300 | int size_req; | |
301 | int cond; | |
037e8744 JB |
302 | /* "uncond_value" is set to the value in place of the conditional field in |
303 | unconditional versions of the instruction, or -1 if nothing is | |
304 | appropriate. */ | |
305 | int uncond_value; | |
5287ad62 | 306 | struct neon_type vectype; |
0110f2b8 PB |
307 | /* Set to the opcode if the instruction needs relaxation. |
308 | Zero if the instruction is not relaxed. */ | |
309 | unsigned long relax; | |
b99bd4ef NC |
310 | struct |
311 | { | |
312 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
313 | expressionS exp; |
314 | int pc_rel; | |
b99bd4ef | 315 | } reloc; |
b99bd4ef | 316 | |
c19d1205 ZW |
317 | struct |
318 | { | |
319 | unsigned reg; | |
ca3f61f7 | 320 | signed int imm; |
dcbf9037 | 321 | struct neon_type_el vectype; |
ca3f61f7 NC |
322 | unsigned present : 1; /* Operand present. */ |
323 | unsigned isreg : 1; /* Operand was a register. */ | |
324 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
325 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
326 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
327 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV | |
328 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
329 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 330 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 331 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 332 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
333 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
334 | unsigned writeback : 1; /* Operand has trailing ! */ | |
335 | unsigned preind : 1; /* Preindexed address. */ | |
336 | unsigned postind : 1; /* Postindexed address. */ | |
337 | unsigned negative : 1; /* Index register was negated. */ | |
338 | unsigned shifted : 1; /* Shift applied to operation. */ | |
339 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 340 | } operands[6]; |
b99bd4ef NC |
341 | }; |
342 | ||
c19d1205 | 343 | static struct arm_it inst; |
b99bd4ef NC |
344 | |
345 | #define NUM_FLOAT_VALS 8 | |
346 | ||
05d2d07e | 347 | const char * fp_const[] = |
b99bd4ef NC |
348 | { |
349 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
350 | }; | |
351 | ||
c19d1205 | 352 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
353 | #define MAX_LITTLENUMS 6 |
354 | ||
355 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
356 | ||
357 | #define FAIL (-1) | |
358 | #define SUCCESS (0) | |
359 | ||
360 | #define SUFF_S 1 | |
361 | #define SUFF_D 2 | |
362 | #define SUFF_E 3 | |
363 | #define SUFF_P 4 | |
364 | ||
c19d1205 ZW |
365 | #define CP_T_X 0x00008000 |
366 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 367 | |
c19d1205 ZW |
368 | #define CONDS_BIT 0x00100000 |
369 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
370 | |
371 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
372 | ||
373 | struct asm_cond | |
374 | { | |
c19d1205 | 375 | const char * template; |
b99bd4ef NC |
376 | unsigned long value; |
377 | }; | |
378 | ||
c19d1205 | 379 | #define COND_ALWAYS 0xE |
b99bd4ef | 380 | |
b99bd4ef NC |
381 | struct asm_psr |
382 | { | |
b34976b6 | 383 | const char *template; |
b99bd4ef NC |
384 | unsigned long field; |
385 | }; | |
386 | ||
62b3e311 PB |
387 | struct asm_barrier_opt |
388 | { | |
389 | const char *template; | |
390 | unsigned long value; | |
391 | }; | |
392 | ||
2d2255b5 | 393 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
394 | #define SPSR_BIT (1 << 22) |
395 | ||
c19d1205 ZW |
396 | /* The individual PSR flag bits. */ |
397 | #define PSR_c (1 << 16) | |
398 | #define PSR_x (1 << 17) | |
399 | #define PSR_s (1 << 18) | |
400 | #define PSR_f (1 << 19) | |
b99bd4ef | 401 | |
c19d1205 | 402 | struct reloc_entry |
bfae80f2 | 403 | { |
c19d1205 ZW |
404 | char *name; |
405 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
406 | }; |
407 | ||
5287ad62 | 408 | enum vfp_reg_pos |
bfae80f2 | 409 | { |
5287ad62 JB |
410 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
411 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
412 | }; |
413 | ||
414 | enum vfp_ldstm_type | |
415 | { | |
416 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
417 | }; | |
418 | ||
dcbf9037 JB |
419 | /* Bits for DEFINED field in neon_typed_alias. */ |
420 | #define NTA_HASTYPE 1 | |
421 | #define NTA_HASINDEX 2 | |
422 | ||
423 | struct neon_typed_alias | |
424 | { | |
425 | unsigned char defined; | |
426 | unsigned char index; | |
427 | struct neon_type_el eltype; | |
428 | }; | |
429 | ||
c19d1205 ZW |
430 | /* ARM register categories. This includes coprocessor numbers and various |
431 | architecture extensions' registers. */ | |
432 | enum arm_reg_type | |
bfae80f2 | 433 | { |
c19d1205 ZW |
434 | REG_TYPE_RN, |
435 | REG_TYPE_CP, | |
436 | REG_TYPE_CN, | |
437 | REG_TYPE_FN, | |
438 | REG_TYPE_VFS, | |
439 | REG_TYPE_VFD, | |
5287ad62 | 440 | REG_TYPE_NQ, |
037e8744 | 441 | REG_TYPE_VFSD, |
5287ad62 | 442 | REG_TYPE_NDQ, |
037e8744 | 443 | REG_TYPE_NSDQ, |
c19d1205 ZW |
444 | REG_TYPE_VFC, |
445 | REG_TYPE_MVF, | |
446 | REG_TYPE_MVD, | |
447 | REG_TYPE_MVFX, | |
448 | REG_TYPE_MVDX, | |
449 | REG_TYPE_MVAX, | |
450 | REG_TYPE_DSPSC, | |
451 | REG_TYPE_MMXWR, | |
452 | REG_TYPE_MMXWC, | |
453 | REG_TYPE_MMXWCG, | |
454 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
455 | }; |
456 | ||
dcbf9037 JB |
457 | /* Structure for a hash table entry for a register. |
458 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
459 | information which states whether a vector type or index is specified (for a | |
460 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
461 | struct reg_entry |
462 | { | |
dcbf9037 JB |
463 | const char *name; |
464 | unsigned char number; | |
465 | unsigned char type; | |
466 | unsigned char builtin; | |
467 | struct neon_typed_alias *neon; | |
6c43fab6 RE |
468 | }; |
469 | ||
c19d1205 ZW |
470 | /* Diagnostics used when we don't get a register of the expected type. */ |
471 | const char *const reg_expected_msgs[] = | |
472 | { | |
473 | N_("ARM register expected"), | |
474 | N_("bad or missing co-processor number"), | |
475 | N_("co-processor register expected"), | |
476 | N_("FPA register expected"), | |
477 | N_("VFP single precision register expected"), | |
5287ad62 JB |
478 | N_("VFP/Neon double precision register expected"), |
479 | N_("Neon quad precision register expected"), | |
037e8744 | 480 | N_("VFP single or double precision register expected"), |
5287ad62 | 481 | N_("Neon double or quad precision register expected"), |
037e8744 | 482 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
483 | N_("VFP system register expected"), |
484 | N_("Maverick MVF register expected"), | |
485 | N_("Maverick MVD register expected"), | |
486 | N_("Maverick MVFX register expected"), | |
487 | N_("Maverick MVDX register expected"), | |
488 | N_("Maverick MVAX register expected"), | |
489 | N_("Maverick DSPSC register expected"), | |
490 | N_("iWMMXt data register expected"), | |
491 | N_("iWMMXt control register expected"), | |
492 | N_("iWMMXt scalar register expected"), | |
493 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
494 | }; |
495 | ||
c19d1205 ZW |
496 | /* Some well known registers that we refer to directly elsewhere. */ |
497 | #define REG_SP 13 | |
498 | #define REG_LR 14 | |
499 | #define REG_PC 15 | |
404ff6b5 | 500 | |
b99bd4ef NC |
501 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
502 | take 2: */ | |
c19d1205 | 503 | #define INSN_SIZE 4 |
b99bd4ef NC |
504 | |
505 | struct asm_opcode | |
506 | { | |
507 | /* Basic string to match. */ | |
c19d1205 ZW |
508 | const char *template; |
509 | ||
510 | /* Parameters to instruction. */ | |
511 | unsigned char operands[8]; | |
512 | ||
513 | /* Conditional tag - see opcode_lookup. */ | |
514 | unsigned int tag : 4; | |
b99bd4ef NC |
515 | |
516 | /* Basic instruction code. */ | |
c19d1205 | 517 | unsigned int avalue : 28; |
b99bd4ef | 518 | |
c19d1205 ZW |
519 | /* Thumb-format instruction code. */ |
520 | unsigned int tvalue; | |
b99bd4ef | 521 | |
90e4755a | 522 | /* Which architecture variant provides this instruction. */ |
e74cfd16 PB |
523 | const arm_feature_set *avariant; |
524 | const arm_feature_set *tvariant; | |
c19d1205 ZW |
525 | |
526 | /* Function to call to encode instruction in ARM format. */ | |
527 | void (* aencode) (void); | |
b99bd4ef | 528 | |
c19d1205 ZW |
529 | /* Function to call to encode instruction in Thumb format. */ |
530 | void (* tencode) (void); | |
b99bd4ef NC |
531 | }; |
532 | ||
a737bd4d NC |
533 | /* Defines for various bits that we will want to toggle. */ |
534 | #define INST_IMMEDIATE 0x02000000 | |
535 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 536 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
537 | #define SHIFT_BY_REG 0x00000010 |
538 | #define PRE_INDEX 0x01000000 | |
539 | #define INDEX_UP 0x00800000 | |
540 | #define WRITE_BACK 0x00200000 | |
541 | #define LDM_TYPE_2_OR_3 0x00400000 | |
90e4755a | 542 | |
a737bd4d NC |
543 | #define LITERAL_MASK 0xf000f000 |
544 | #define OPCODE_MASK 0xfe1fffff | |
545 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 546 | |
a737bd4d | 547 | #define DATA_OP_SHIFT 21 |
90e4755a | 548 | |
ef8d22e6 PB |
549 | #define T2_OPCODE_MASK 0xfe1fffff |
550 | #define T2_DATA_OP_SHIFT 21 | |
551 | ||
a737bd4d NC |
552 | /* Codes to distinguish the arithmetic instructions. */ |
553 | #define OPCODE_AND 0 | |
554 | #define OPCODE_EOR 1 | |
555 | #define OPCODE_SUB 2 | |
556 | #define OPCODE_RSB 3 | |
557 | #define OPCODE_ADD 4 | |
558 | #define OPCODE_ADC 5 | |
559 | #define OPCODE_SBC 6 | |
560 | #define OPCODE_RSC 7 | |
561 | #define OPCODE_TST 8 | |
562 | #define OPCODE_TEQ 9 | |
563 | #define OPCODE_CMP 10 | |
564 | #define OPCODE_CMN 11 | |
565 | #define OPCODE_ORR 12 | |
566 | #define OPCODE_MOV 13 | |
567 | #define OPCODE_BIC 14 | |
568 | #define OPCODE_MVN 15 | |
90e4755a | 569 | |
ef8d22e6 PB |
570 | #define T2_OPCODE_AND 0 |
571 | #define T2_OPCODE_BIC 1 | |
572 | #define T2_OPCODE_ORR 2 | |
573 | #define T2_OPCODE_ORN 3 | |
574 | #define T2_OPCODE_EOR 4 | |
575 | #define T2_OPCODE_ADD 8 | |
576 | #define T2_OPCODE_ADC 10 | |
577 | #define T2_OPCODE_SBC 11 | |
578 | #define T2_OPCODE_SUB 13 | |
579 | #define T2_OPCODE_RSB 14 | |
580 | ||
a737bd4d NC |
581 | #define T_OPCODE_MUL 0x4340 |
582 | #define T_OPCODE_TST 0x4200 | |
583 | #define T_OPCODE_CMN 0x42c0 | |
584 | #define T_OPCODE_NEG 0x4240 | |
585 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 586 | |
a737bd4d NC |
587 | #define T_OPCODE_ADD_R3 0x1800 |
588 | #define T_OPCODE_SUB_R3 0x1a00 | |
589 | #define T_OPCODE_ADD_HI 0x4400 | |
590 | #define T_OPCODE_ADD_ST 0xb000 | |
591 | #define T_OPCODE_SUB_ST 0xb080 | |
592 | #define T_OPCODE_ADD_SP 0xa800 | |
593 | #define T_OPCODE_ADD_PC 0xa000 | |
594 | #define T_OPCODE_ADD_I8 0x3000 | |
595 | #define T_OPCODE_SUB_I8 0x3800 | |
596 | #define T_OPCODE_ADD_I3 0x1c00 | |
597 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 598 | |
a737bd4d NC |
599 | #define T_OPCODE_ASR_R 0x4100 |
600 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
601 | #define T_OPCODE_LSR_R 0x40c0 |
602 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
603 | #define T_OPCODE_ASR_I 0x1000 |
604 | #define T_OPCODE_LSL_I 0x0000 | |
605 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 606 | |
a737bd4d NC |
607 | #define T_OPCODE_MOV_I8 0x2000 |
608 | #define T_OPCODE_CMP_I8 0x2800 | |
609 | #define T_OPCODE_CMP_LR 0x4280 | |
610 | #define T_OPCODE_MOV_HR 0x4600 | |
611 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 612 | |
a737bd4d NC |
613 | #define T_OPCODE_LDR_PC 0x4800 |
614 | #define T_OPCODE_LDR_SP 0x9800 | |
615 | #define T_OPCODE_STR_SP 0x9000 | |
616 | #define T_OPCODE_LDR_IW 0x6800 | |
617 | #define T_OPCODE_STR_IW 0x6000 | |
618 | #define T_OPCODE_LDR_IH 0x8800 | |
619 | #define T_OPCODE_STR_IH 0x8000 | |
620 | #define T_OPCODE_LDR_IB 0x7800 | |
621 | #define T_OPCODE_STR_IB 0x7000 | |
622 | #define T_OPCODE_LDR_RW 0x5800 | |
623 | #define T_OPCODE_STR_RW 0x5000 | |
624 | #define T_OPCODE_LDR_RH 0x5a00 | |
625 | #define T_OPCODE_STR_RH 0x5200 | |
626 | #define T_OPCODE_LDR_RB 0x5c00 | |
627 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 628 | |
a737bd4d NC |
629 | #define T_OPCODE_PUSH 0xb400 |
630 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 631 | |
2fc8bdac | 632 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 633 | |
a737bd4d | 634 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 635 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 636 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 637 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
638 | |
639 | #define BAD_ARGS _("bad arguments to instruction") | |
640 | #define BAD_PC _("r15 not allowed here") | |
641 | #define BAD_COND _("instruction cannot be conditional") | |
642 | #define BAD_OVERLAP _("registers may not be the same") | |
643 | #define BAD_HIREG _("lo register required") | |
644 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 645 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
646 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
647 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 648 | #define BAD_FPU _("selected FPU does not support instruction") |
c19d1205 ZW |
649 | |
650 | static struct hash_control *arm_ops_hsh; | |
651 | static struct hash_control *arm_cond_hsh; | |
652 | static struct hash_control *arm_shift_hsh; | |
653 | static struct hash_control *arm_psr_hsh; | |
62b3e311 | 654 | static struct hash_control *arm_v7m_psr_hsh; |
c19d1205 ZW |
655 | static struct hash_control *arm_reg_hsh; |
656 | static struct hash_control *arm_reloc_hsh; | |
62b3e311 | 657 | static struct hash_control *arm_barrier_opt_hsh; |
b99bd4ef | 658 | |
b99bd4ef NC |
659 | /* Stuff needed to resolve the label ambiguity |
660 | As: | |
661 | ... | |
662 | label: <insn> | |
663 | may differ from: | |
664 | ... | |
665 | label: | |
c19d1205 | 666 | <insn> |
b99bd4ef NC |
667 | */ |
668 | ||
669 | symbolS * last_label_seen; | |
b34976b6 | 670 | static int label_is_thumb_function_name = FALSE; |
a737bd4d | 671 | \f |
3d0c9500 NC |
672 | /* Literal pool structure. Held on a per-section |
673 | and per-sub-section basis. */ | |
a737bd4d | 674 | |
c19d1205 | 675 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 676 | typedef struct literal_pool |
b99bd4ef | 677 | { |
c19d1205 ZW |
678 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
679 | unsigned int next_free_entry; | |
680 | unsigned int id; | |
681 | symbolS * symbol; | |
682 | segT section; | |
683 | subsegT sub_section; | |
61b5f74b | 684 | struct literal_pool * next; |
3d0c9500 | 685 | } literal_pool; |
b99bd4ef | 686 | |
3d0c9500 NC |
687 | /* Pointer to a linked list of literal pools. */ |
688 | literal_pool * list_of_pools = NULL; | |
e27ec89e PB |
689 | |
690 | /* State variables for IT block handling. */ | |
691 | static bfd_boolean current_it_mask = 0; | |
692 | static int current_cc; | |
693 | ||
c19d1205 ZW |
694 | \f |
695 | /* Pure syntax. */ | |
b99bd4ef | 696 | |
c19d1205 ZW |
697 | /* This array holds the chars that always start a comment. If the |
698 | pre-processor is disabled, these aren't very useful. */ | |
699 | const char comment_chars[] = "@"; | |
3d0c9500 | 700 | |
c19d1205 ZW |
701 | /* This array holds the chars that only start a comment at the beginning of |
702 | a line. If the line seems to have the form '# 123 filename' | |
703 | .line and .file directives will appear in the pre-processed output. */ | |
704 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
705 | first line of the input file. This is because the compiler outputs | |
706 | #NO_APP at the beginning of its output. */ | |
707 | /* Also note that comments like this one will always work. */ | |
708 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 709 | |
c19d1205 | 710 | const char line_separator_chars[] = ";"; |
b99bd4ef | 711 | |
c19d1205 ZW |
712 | /* Chars that can be used to separate mant |
713 | from exp in floating point numbers. */ | |
714 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 715 | |
c19d1205 ZW |
716 | /* Chars that mean this number is a floating point constant. */ |
717 | /* As in 0f12.456 */ | |
718 | /* or 0d1.2345e12 */ | |
b99bd4ef | 719 | |
c19d1205 | 720 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 721 | |
c19d1205 ZW |
722 | /* Prefix characters that indicate the start of an immediate |
723 | value. */ | |
724 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 725 | |
c19d1205 ZW |
726 | /* Separator character handling. */ |
727 | ||
728 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
729 | ||
730 | static inline int | |
731 | skip_past_char (char ** str, char c) | |
732 | { | |
733 | if (**str == c) | |
734 | { | |
735 | (*str)++; | |
736 | return SUCCESS; | |
3d0c9500 | 737 | } |
c19d1205 ZW |
738 | else |
739 | return FAIL; | |
740 | } | |
741 | #define skip_past_comma(str) skip_past_char (str, ',') | |
3d0c9500 | 742 | |
c19d1205 ZW |
743 | /* Arithmetic expressions (possibly involving symbols). */ |
744 | ||
745 | /* Return TRUE if anything in the expression is a bignum. */ | |
746 | ||
747 | static int | |
748 | walk_no_bignums (symbolS * sp) | |
749 | { | |
750 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
751 | return 1; | |
752 | ||
753 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 754 | { |
c19d1205 ZW |
755 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
756 | || (symbol_get_value_expression (sp)->X_op_symbol | |
757 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
758 | } |
759 | ||
c19d1205 | 760 | return 0; |
3d0c9500 NC |
761 | } |
762 | ||
c19d1205 ZW |
763 | static int in_my_get_expression = 0; |
764 | ||
765 | /* Third argument to my_get_expression. */ | |
766 | #define GE_NO_PREFIX 0 | |
767 | #define GE_IMM_PREFIX 1 | |
768 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
769 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
770 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
771 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 772 | |
b99bd4ef | 773 | static int |
c19d1205 | 774 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 775 | { |
c19d1205 ZW |
776 | char * save_in; |
777 | segT seg; | |
b99bd4ef | 778 | |
c19d1205 ZW |
779 | /* In unified syntax, all prefixes are optional. */ |
780 | if (unified_syntax) | |
5287ad62 JB |
781 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
782 | : GE_OPT_PREFIX; | |
b99bd4ef | 783 | |
c19d1205 | 784 | switch (prefix_mode) |
b99bd4ef | 785 | { |
c19d1205 ZW |
786 | case GE_NO_PREFIX: break; |
787 | case GE_IMM_PREFIX: | |
788 | if (!is_immediate_prefix (**str)) | |
789 | { | |
790 | inst.error = _("immediate expression requires a # prefix"); | |
791 | return FAIL; | |
792 | } | |
793 | (*str)++; | |
794 | break; | |
795 | case GE_OPT_PREFIX: | |
5287ad62 | 796 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
797 | if (is_immediate_prefix (**str)) |
798 | (*str)++; | |
799 | break; | |
800 | default: abort (); | |
801 | } | |
b99bd4ef | 802 | |
c19d1205 | 803 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 804 | |
c19d1205 ZW |
805 | save_in = input_line_pointer; |
806 | input_line_pointer = *str; | |
807 | in_my_get_expression = 1; | |
808 | seg = expression (ep); | |
809 | in_my_get_expression = 0; | |
810 | ||
811 | if (ep->X_op == O_illegal) | |
b99bd4ef | 812 | { |
c19d1205 ZW |
813 | /* We found a bad expression in md_operand(). */ |
814 | *str = input_line_pointer; | |
815 | input_line_pointer = save_in; | |
816 | if (inst.error == NULL) | |
817 | inst.error = _("bad expression"); | |
818 | return 1; | |
819 | } | |
b99bd4ef | 820 | |
c19d1205 ZW |
821 | #ifdef OBJ_AOUT |
822 | if (seg != absolute_section | |
823 | && seg != text_section | |
824 | && seg != data_section | |
825 | && seg != bss_section | |
826 | && seg != undefined_section) | |
827 | { | |
828 | inst.error = _("bad segment"); | |
829 | *str = input_line_pointer; | |
830 | input_line_pointer = save_in; | |
831 | return 1; | |
b99bd4ef | 832 | } |
c19d1205 | 833 | #endif |
b99bd4ef | 834 | |
c19d1205 ZW |
835 | /* Get rid of any bignums now, so that we don't generate an error for which |
836 | we can't establish a line number later on. Big numbers are never valid | |
837 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
838 | if (prefix_mode != GE_OPT_PREFIX_BIG |
839 | && (ep->X_op == O_big | |
840 | || (ep->X_add_symbol | |
841 | && (walk_no_bignums (ep->X_add_symbol) | |
842 | || (ep->X_op_symbol | |
843 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
844 | { |
845 | inst.error = _("invalid constant"); | |
846 | *str = input_line_pointer; | |
847 | input_line_pointer = save_in; | |
848 | return 1; | |
849 | } | |
b99bd4ef | 850 | |
c19d1205 ZW |
851 | *str = input_line_pointer; |
852 | input_line_pointer = save_in; | |
853 | return 0; | |
b99bd4ef NC |
854 | } |
855 | ||
c19d1205 ZW |
856 | /* Turn a string in input_line_pointer into a floating point constant |
857 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
858 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
859 | returned, or NULL on OK. | |
b99bd4ef | 860 | |
c19d1205 ZW |
861 | Note that fp constants aren't represent in the normal way on the ARM. |
862 | In big endian mode, things are as expected. However, in little endian | |
863 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
864 | within the words. For example, (double) 1.1 in big endian mode is | |
865 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
866 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 867 | |
c19d1205 | 868 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 869 | |
c19d1205 ZW |
870 | char * |
871 | md_atof (int type, char * litP, int * sizeP) | |
872 | { | |
873 | int prec; | |
874 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
875 | char *t; | |
876 | int i; | |
b99bd4ef | 877 | |
c19d1205 ZW |
878 | switch (type) |
879 | { | |
880 | case 'f': | |
881 | case 'F': | |
882 | case 's': | |
883 | case 'S': | |
884 | prec = 2; | |
885 | break; | |
b99bd4ef | 886 | |
c19d1205 ZW |
887 | case 'd': |
888 | case 'D': | |
889 | case 'r': | |
890 | case 'R': | |
891 | prec = 4; | |
892 | break; | |
b99bd4ef | 893 | |
c19d1205 ZW |
894 | case 'x': |
895 | case 'X': | |
896 | prec = 6; | |
897 | break; | |
b99bd4ef | 898 | |
c19d1205 ZW |
899 | case 'p': |
900 | case 'P': | |
901 | prec = 6; | |
902 | break; | |
a737bd4d | 903 | |
c19d1205 ZW |
904 | default: |
905 | *sizeP = 0; | |
906 | return _("bad call to MD_ATOF()"); | |
907 | } | |
b99bd4ef | 908 | |
c19d1205 ZW |
909 | t = atof_ieee (input_line_pointer, type, words); |
910 | if (t) | |
911 | input_line_pointer = t; | |
912 | *sizeP = prec * 2; | |
b99bd4ef | 913 | |
c19d1205 ZW |
914 | if (target_big_endian) |
915 | { | |
916 | for (i = 0; i < prec; i++) | |
917 | { | |
918 | md_number_to_chars (litP, (valueT) words[i], 2); | |
919 | litP += 2; | |
920 | } | |
921 | } | |
922 | else | |
923 | { | |
e74cfd16 | 924 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
925 | for (i = prec - 1; i >= 0; i--) |
926 | { | |
927 | md_number_to_chars (litP, (valueT) words[i], 2); | |
928 | litP += 2; | |
929 | } | |
930 | else | |
931 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
932 | For an 8 byte float the order is 1 0 3 2. */ | |
933 | for (i = 0; i < prec; i += 2) | |
934 | { | |
935 | md_number_to_chars (litP, (valueT) words[i + 1], 2); | |
936 | md_number_to_chars (litP + 2, (valueT) words[i], 2); | |
937 | litP += 4; | |
938 | } | |
939 | } | |
b99bd4ef | 940 | |
c19d1205 ZW |
941 | return 0; |
942 | } | |
b99bd4ef | 943 | |
c19d1205 ZW |
944 | /* We handle all bad expressions here, so that we can report the faulty |
945 | instruction in the error message. */ | |
946 | void | |
947 | md_operand (expressionS * expr) | |
948 | { | |
949 | if (in_my_get_expression) | |
950 | expr->X_op = O_illegal; | |
b99bd4ef NC |
951 | } |
952 | ||
c19d1205 | 953 | /* Immediate values. */ |
b99bd4ef | 954 | |
c19d1205 ZW |
955 | /* Generic immediate-value read function for use in directives. |
956 | Accepts anything that 'expression' can fold to a constant. | |
957 | *val receives the number. */ | |
958 | #ifdef OBJ_ELF | |
959 | static int | |
960 | immediate_for_directive (int *val) | |
b99bd4ef | 961 | { |
c19d1205 ZW |
962 | expressionS exp; |
963 | exp.X_op = O_illegal; | |
b99bd4ef | 964 | |
c19d1205 ZW |
965 | if (is_immediate_prefix (*input_line_pointer)) |
966 | { | |
967 | input_line_pointer++; | |
968 | expression (&exp); | |
969 | } | |
b99bd4ef | 970 | |
c19d1205 ZW |
971 | if (exp.X_op != O_constant) |
972 | { | |
973 | as_bad (_("expected #constant")); | |
974 | ignore_rest_of_line (); | |
975 | return FAIL; | |
976 | } | |
977 | *val = exp.X_add_number; | |
978 | return SUCCESS; | |
b99bd4ef | 979 | } |
c19d1205 | 980 | #endif |
b99bd4ef | 981 | |
c19d1205 | 982 | /* Register parsing. */ |
b99bd4ef | 983 | |
c19d1205 ZW |
984 | /* Generic register parser. CCP points to what should be the |
985 | beginning of a register name. If it is indeed a valid register | |
986 | name, advance CCP over it and return the reg_entry structure; | |
987 | otherwise return NULL. Does not issue diagnostics. */ | |
988 | ||
989 | static struct reg_entry * | |
990 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 991 | { |
c19d1205 ZW |
992 | char *start = *ccp; |
993 | char *p; | |
994 | struct reg_entry *reg; | |
b99bd4ef | 995 | |
c19d1205 ZW |
996 | #ifdef REGISTER_PREFIX |
997 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 998 | return NULL; |
c19d1205 ZW |
999 | start++; |
1000 | #endif | |
1001 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1002 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1003 | start++; | |
1004 | #endif | |
b99bd4ef | 1005 | |
c19d1205 ZW |
1006 | p = start; |
1007 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1008 | return NULL; | |
b99bd4ef | 1009 | |
c19d1205 ZW |
1010 | do |
1011 | p++; | |
1012 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1013 | ||
1014 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1015 | ||
1016 | if (!reg) | |
1017 | return NULL; | |
1018 | ||
1019 | *ccp = p; | |
1020 | return reg; | |
b99bd4ef NC |
1021 | } |
1022 | ||
1023 | static int | |
dcbf9037 JB |
1024 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1025 | enum arm_reg_type type) | |
b99bd4ef | 1026 | { |
c19d1205 ZW |
1027 | /* Alternative syntaxes are accepted for a few register classes. */ |
1028 | switch (type) | |
1029 | { | |
1030 | case REG_TYPE_MVF: | |
1031 | case REG_TYPE_MVD: | |
1032 | case REG_TYPE_MVFX: | |
1033 | case REG_TYPE_MVDX: | |
1034 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1035 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1036 | return reg->number; |
1037 | break; | |
69b97547 | 1038 | |
c19d1205 ZW |
1039 | case REG_TYPE_CP: |
1040 | /* For backward compatibility, a bare number is valid here. */ | |
1041 | { | |
1042 | unsigned long processor = strtoul (start, ccp, 10); | |
1043 | if (*ccp != start && processor <= 15) | |
1044 | return processor; | |
1045 | } | |
6057a28f | 1046 | |
c19d1205 ZW |
1047 | case REG_TYPE_MMXWC: |
1048 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1049 | instructions that take WC registers. */ | |
79134647 | 1050 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1051 | return reg->number; |
6057a28f | 1052 | break; |
c19d1205 | 1053 | |
6057a28f | 1054 | default: |
c19d1205 | 1055 | break; |
6057a28f NC |
1056 | } |
1057 | ||
dcbf9037 JB |
1058 | return FAIL; |
1059 | } | |
1060 | ||
1061 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1062 | return value is the register number or FAIL. */ | |
1063 | ||
1064 | static int | |
1065 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1066 | { | |
1067 | char *start = *ccp; | |
1068 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1069 | int ret; | |
1070 | ||
1071 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1072 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1073 | return FAIL; | |
1074 | ||
1075 | if (reg && reg->type == type) | |
1076 | return reg->number; | |
1077 | ||
1078 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1079 | return ret; | |
1080 | ||
c19d1205 ZW |
1081 | *ccp = start; |
1082 | return FAIL; | |
1083 | } | |
69b97547 | 1084 | |
dcbf9037 JB |
1085 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1086 | character. Does no verification at this stage that the type fits the opcode | |
1087 | properly. E.g., | |
1088 | ||
1089 | .i32.i32.s16 | |
1090 | .s32.f32 | |
1091 | .u16 | |
1092 | ||
1093 | Can all be legally parsed by this function. | |
1094 | ||
1095 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1096 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1097 | type, FAIL if not. */ | |
1098 | ||
1099 | static int | |
1100 | parse_neon_type (struct neon_type *type, char **str) | |
1101 | { | |
1102 | char *ptr = *str; | |
1103 | ||
1104 | if (type) | |
1105 | type->elems = 0; | |
1106 | ||
1107 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1108 | { | |
1109 | enum neon_el_type thistype = NT_untyped; | |
1110 | unsigned thissize = -1u; | |
1111 | ||
1112 | if (*ptr != '.') | |
1113 | break; | |
1114 | ||
1115 | ptr++; | |
1116 | ||
1117 | /* Just a size without an explicit type. */ | |
1118 | if (ISDIGIT (*ptr)) | |
1119 | goto parsesize; | |
1120 | ||
1121 | switch (TOLOWER (*ptr)) | |
1122 | { | |
1123 | case 'i': thistype = NT_integer; break; | |
1124 | case 'f': thistype = NT_float; break; | |
1125 | case 'p': thistype = NT_poly; break; | |
1126 | case 's': thistype = NT_signed; break; | |
1127 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1128 | case 'd': |
1129 | thistype = NT_float; | |
1130 | thissize = 64; | |
1131 | ptr++; | |
1132 | goto done; | |
dcbf9037 JB |
1133 | default: |
1134 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1135 | return FAIL; | |
1136 | } | |
1137 | ||
1138 | ptr++; | |
1139 | ||
1140 | /* .f is an abbreviation for .f32. */ | |
1141 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1142 | thissize = 32; | |
1143 | else | |
1144 | { | |
1145 | parsesize: | |
1146 | thissize = strtoul (ptr, &ptr, 10); | |
1147 | ||
1148 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1149 | && thissize != 64) | |
1150 | { | |
1151 | as_bad (_("bad size %d in type specifier"), thissize); | |
1152 | return FAIL; | |
1153 | } | |
1154 | } | |
1155 | ||
037e8744 | 1156 | done: |
dcbf9037 JB |
1157 | if (type) |
1158 | { | |
1159 | type->el[type->elems].type = thistype; | |
1160 | type->el[type->elems].size = thissize; | |
1161 | type->elems++; | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | /* Empty/missing type is not a successful parse. */ | |
1166 | if (type->elems == 0) | |
1167 | return FAIL; | |
1168 | ||
1169 | *str = ptr; | |
1170 | ||
1171 | return SUCCESS; | |
1172 | } | |
1173 | ||
1174 | /* Errors may be set multiple times during parsing or bit encoding | |
1175 | (particularly in the Neon bits), but usually the earliest error which is set | |
1176 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1177 | errors by calling this function. */ | |
1178 | ||
1179 | static void | |
1180 | first_error (const char *err) | |
1181 | { | |
1182 | if (!inst.error) | |
1183 | inst.error = err; | |
1184 | } | |
1185 | ||
1186 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1187 | static int | |
1188 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1189 | { | |
1190 | char *str = *ccp; | |
1191 | struct neon_type optype; | |
1192 | ||
1193 | if (*str == '.') | |
1194 | { | |
1195 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1196 | { | |
1197 | if (optype.elems == 1) | |
1198 | *vectype = optype.el[0]; | |
1199 | else | |
1200 | { | |
1201 | first_error (_("only one type should be specified for operand")); | |
1202 | return FAIL; | |
1203 | } | |
1204 | } | |
1205 | else | |
1206 | { | |
1207 | first_error (_("vector type expected")); | |
1208 | return FAIL; | |
1209 | } | |
1210 | } | |
1211 | else | |
1212 | return FAIL; | |
1213 | ||
1214 | *ccp = str; | |
1215 | ||
1216 | return SUCCESS; | |
1217 | } | |
1218 | ||
1219 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1220 | a 4-bit integer. */ | |
1221 | ||
1222 | #define NEON_ALL_LANES 15 | |
1223 | #define NEON_INTERLEAVE_LANES 14 | |
1224 | ||
1225 | /* Parse either a register or a scalar, with an optional type. Return the | |
1226 | register number, and optionally fill in the actual type of the register | |
1227 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1228 | type/index information in *TYPEINFO. */ | |
1229 | ||
1230 | static int | |
1231 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1232 | enum arm_reg_type *rtype, | |
1233 | struct neon_typed_alias *typeinfo) | |
1234 | { | |
1235 | char *str = *ccp; | |
1236 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1237 | struct neon_typed_alias atype; | |
1238 | struct neon_type_el parsetype; | |
1239 | ||
1240 | atype.defined = 0; | |
1241 | atype.index = -1; | |
1242 | atype.eltype.type = NT_invtype; | |
1243 | atype.eltype.size = -1; | |
1244 | ||
1245 | /* Try alternate syntax for some types of register. Note these are mutually | |
1246 | exclusive with the Neon syntax extensions. */ | |
1247 | if (reg == NULL) | |
1248 | { | |
1249 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1250 | if (altreg != FAIL) | |
1251 | *ccp = str; | |
1252 | if (typeinfo) | |
1253 | *typeinfo = atype; | |
1254 | return altreg; | |
1255 | } | |
1256 | ||
037e8744 JB |
1257 | /* Undo polymorphism when a set of register types may be accepted. */ |
1258 | if ((type == REG_TYPE_NDQ | |
1259 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1260 | || (type == REG_TYPE_VFSD | |
1261 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1262 | || (type == REG_TYPE_NSDQ | |
1263 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
1264 | || reg->type == REG_TYPE_NQ))) | |
dcbf9037 JB |
1265 | type = reg->type; |
1266 | ||
1267 | if (type != reg->type) | |
1268 | return FAIL; | |
1269 | ||
1270 | if (reg->neon) | |
1271 | atype = *reg->neon; | |
1272 | ||
1273 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) | |
1274 | { | |
1275 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1276 | { | |
1277 | first_error (_("can't redefine type for operand")); | |
1278 | return FAIL; | |
1279 | } | |
1280 | atype.defined |= NTA_HASTYPE; | |
1281 | atype.eltype = parsetype; | |
1282 | } | |
1283 | ||
1284 | if (skip_past_char (&str, '[') == SUCCESS) | |
1285 | { | |
1286 | if (type != REG_TYPE_VFD) | |
1287 | { | |
1288 | first_error (_("only D registers may be indexed")); | |
1289 | return FAIL; | |
1290 | } | |
1291 | ||
1292 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1293 | { | |
1294 | first_error (_("can't change index for operand")); | |
1295 | return FAIL; | |
1296 | } | |
1297 | ||
1298 | atype.defined |= NTA_HASINDEX; | |
1299 | ||
1300 | if (skip_past_char (&str, ']') == SUCCESS) | |
1301 | atype.index = NEON_ALL_LANES; | |
1302 | else | |
1303 | { | |
1304 | expressionS exp; | |
1305 | ||
1306 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1307 | ||
1308 | if (exp.X_op != O_constant) | |
1309 | { | |
1310 | first_error (_("constant expression required")); | |
1311 | return FAIL; | |
1312 | } | |
1313 | ||
1314 | if (skip_past_char (&str, ']') == FAIL) | |
1315 | return FAIL; | |
1316 | ||
1317 | atype.index = exp.X_add_number; | |
1318 | } | |
1319 | } | |
1320 | ||
1321 | if (typeinfo) | |
1322 | *typeinfo = atype; | |
1323 | ||
1324 | if (rtype) | |
1325 | *rtype = type; | |
1326 | ||
1327 | *ccp = str; | |
1328 | ||
1329 | return reg->number; | |
1330 | } | |
1331 | ||
1332 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1333 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1334 | register (e.g. Neon double or quad reg when either has been requested). | |
1335 | - If this is a Neon vector type with additional type information, fill | |
1336 | in the struct pointed to by VECTYPE (if non-NULL). | |
1337 | This function will fault on encountering a scalar. | |
1338 | */ | |
1339 | ||
1340 | static int | |
1341 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1342 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1343 | { | |
1344 | struct neon_typed_alias atype; | |
1345 | char *str = *ccp; | |
1346 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1347 | ||
1348 | if (reg == FAIL) | |
1349 | return FAIL; | |
1350 | ||
1351 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1352 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1353 | { | |
1354 | first_error (_("register operand expected, but got scalar")); | |
1355 | return FAIL; | |
1356 | } | |
1357 | ||
1358 | if (vectype) | |
1359 | *vectype = atype.eltype; | |
1360 | ||
1361 | *ccp = str; | |
1362 | ||
1363 | return reg; | |
1364 | } | |
1365 | ||
1366 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1367 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1368 | ||
5287ad62 JB |
1369 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1370 | have enough information to be able to do a good job bounds-checking. So, we | |
1371 | just do easy checks here, and do further checks later. */ | |
1372 | ||
1373 | static int | |
dcbf9037 | 1374 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1375 | { |
dcbf9037 | 1376 | int reg; |
5287ad62 | 1377 | char *str = *ccp; |
dcbf9037 | 1378 | struct neon_typed_alias atype; |
5287ad62 | 1379 | |
dcbf9037 | 1380 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5287ad62 | 1381 | |
dcbf9037 | 1382 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 JB |
1383 | return FAIL; |
1384 | ||
dcbf9037 | 1385 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1386 | { |
dcbf9037 | 1387 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1388 | return FAIL; |
1389 | } | |
dcbf9037 | 1390 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1391 | { |
dcbf9037 | 1392 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1393 | return FAIL; |
1394 | } | |
1395 | ||
dcbf9037 JB |
1396 | if (type) |
1397 | *type = atype.eltype; | |
5287ad62 | 1398 | |
5287ad62 JB |
1399 | *ccp = str; |
1400 | ||
dcbf9037 | 1401 | return reg * 16 + atype.index; |
5287ad62 JB |
1402 | } |
1403 | ||
c19d1205 ZW |
1404 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
1405 | static long | |
1406 | parse_reg_list (char ** strp) | |
1407 | { | |
1408 | char * str = * strp; | |
1409 | long range = 0; | |
1410 | int another_range; | |
a737bd4d | 1411 | |
c19d1205 ZW |
1412 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1413 | do | |
6057a28f | 1414 | { |
c19d1205 | 1415 | another_range = 0; |
a737bd4d | 1416 | |
c19d1205 ZW |
1417 | if (*str == '{') |
1418 | { | |
1419 | int in_range = 0; | |
1420 | int cur_reg = -1; | |
a737bd4d | 1421 | |
c19d1205 ZW |
1422 | str++; |
1423 | do | |
1424 | { | |
1425 | int reg; | |
6057a28f | 1426 | |
dcbf9037 | 1427 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1428 | { |
dcbf9037 | 1429 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1430 | return FAIL; |
1431 | } | |
a737bd4d | 1432 | |
c19d1205 ZW |
1433 | if (in_range) |
1434 | { | |
1435 | int i; | |
a737bd4d | 1436 | |
c19d1205 ZW |
1437 | if (reg <= cur_reg) |
1438 | { | |
dcbf9037 | 1439 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1440 | return FAIL; |
1441 | } | |
40a18ebd | 1442 | |
c19d1205 ZW |
1443 | for (i = cur_reg + 1; i < reg; i++) |
1444 | { | |
1445 | if (range & (1 << i)) | |
1446 | as_tsktsk | |
1447 | (_("Warning: duplicated register (r%d) in register list"), | |
1448 | i); | |
1449 | else | |
1450 | range |= 1 << i; | |
1451 | } | |
1452 | in_range = 0; | |
1453 | } | |
a737bd4d | 1454 | |
c19d1205 ZW |
1455 | if (range & (1 << reg)) |
1456 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1457 | reg); | |
1458 | else if (reg <= cur_reg) | |
1459 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1460 | |
c19d1205 ZW |
1461 | range |= 1 << reg; |
1462 | cur_reg = reg; | |
1463 | } | |
1464 | while (skip_past_comma (&str) != FAIL | |
1465 | || (in_range = 1, *str++ == '-')); | |
1466 | str--; | |
a737bd4d | 1467 | |
c19d1205 ZW |
1468 | if (*str++ != '}') |
1469 | { | |
dcbf9037 | 1470 | first_error (_("missing `}'")); |
c19d1205 ZW |
1471 | return FAIL; |
1472 | } | |
1473 | } | |
1474 | else | |
1475 | { | |
1476 | expressionS expr; | |
40a18ebd | 1477 | |
c19d1205 ZW |
1478 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1479 | return FAIL; | |
40a18ebd | 1480 | |
c19d1205 ZW |
1481 | if (expr.X_op == O_constant) |
1482 | { | |
1483 | if (expr.X_add_number | |
1484 | != (expr.X_add_number & 0x0000ffff)) | |
1485 | { | |
1486 | inst.error = _("invalid register mask"); | |
1487 | return FAIL; | |
1488 | } | |
a737bd4d | 1489 | |
c19d1205 ZW |
1490 | if ((range & expr.X_add_number) != 0) |
1491 | { | |
1492 | int regno = range & expr.X_add_number; | |
a737bd4d | 1493 | |
c19d1205 ZW |
1494 | regno &= -regno; |
1495 | regno = (1 << regno) - 1; | |
1496 | as_tsktsk | |
1497 | (_("Warning: duplicated register (r%d) in register list"), | |
1498 | regno); | |
1499 | } | |
a737bd4d | 1500 | |
c19d1205 ZW |
1501 | range |= expr.X_add_number; |
1502 | } | |
1503 | else | |
1504 | { | |
1505 | if (inst.reloc.type != 0) | |
1506 | { | |
1507 | inst.error = _("expression too complex"); | |
1508 | return FAIL; | |
1509 | } | |
a737bd4d | 1510 | |
c19d1205 ZW |
1511 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1512 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1513 | inst.reloc.pc_rel = 0; | |
1514 | } | |
1515 | } | |
a737bd4d | 1516 | |
c19d1205 ZW |
1517 | if (*str == '|' || *str == '+') |
1518 | { | |
1519 | str++; | |
1520 | another_range = 1; | |
1521 | } | |
a737bd4d | 1522 | } |
c19d1205 | 1523 | while (another_range); |
a737bd4d | 1524 | |
c19d1205 ZW |
1525 | *strp = str; |
1526 | return range; | |
a737bd4d NC |
1527 | } |
1528 | ||
5287ad62 JB |
1529 | /* Types of registers in a list. */ |
1530 | ||
1531 | enum reg_list_els | |
1532 | { | |
1533 | REGLIST_VFP_S, | |
1534 | REGLIST_VFP_D, | |
1535 | REGLIST_NEON_D | |
1536 | }; | |
1537 | ||
c19d1205 ZW |
1538 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1539 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1540 | register. Parses registers of type ETYPE. |
1541 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1542 | - Q registers can be used to specify pairs of D registers | |
1543 | - { } can be omitted from around a singleton register list | |
1544 | FIXME: This is not implemented, as it would require backtracking in | |
1545 | some cases, e.g.: | |
1546 | vtbl.8 d3,d4,d5 | |
1547 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1548 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1549 | - 32 D registers may be used (also true for VFPv3). |
1550 | FIXME: Types are ignored in these register lists, which is probably a | |
1551 | bug. */ | |
6057a28f | 1552 | |
c19d1205 | 1553 | static int |
037e8744 | 1554 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1555 | { |
037e8744 | 1556 | char *str = *ccp; |
c19d1205 ZW |
1557 | int base_reg; |
1558 | int new_base; | |
5287ad62 JB |
1559 | enum arm_reg_type regtype = 0; |
1560 | int max_regs = 0; | |
c19d1205 ZW |
1561 | int count = 0; |
1562 | int warned = 0; | |
1563 | unsigned long mask = 0; | |
a737bd4d | 1564 | int i; |
6057a28f | 1565 | |
037e8744 | 1566 | if (*str != '{') |
5287ad62 JB |
1567 | { |
1568 | inst.error = _("expecting {"); | |
1569 | return FAIL; | |
1570 | } | |
6057a28f | 1571 | |
037e8744 | 1572 | str++; |
6057a28f | 1573 | |
5287ad62 | 1574 | switch (etype) |
c19d1205 | 1575 | { |
5287ad62 | 1576 | case REGLIST_VFP_S: |
c19d1205 ZW |
1577 | regtype = REG_TYPE_VFS; |
1578 | max_regs = 32; | |
5287ad62 JB |
1579 | break; |
1580 | ||
1581 | case REGLIST_VFP_D: | |
1582 | regtype = REG_TYPE_VFD; | |
b7fc2769 JB |
1583 | break; |
1584 | ||
1585 | case REGLIST_NEON_D: | |
1586 | regtype = REG_TYPE_NDQ; | |
1587 | break; | |
1588 | } | |
1589 | ||
1590 | if (etype != REGLIST_VFP_S) | |
1591 | { | |
5287ad62 JB |
1592 | /* VFPv3 allows 32 D registers. */ |
1593 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
1594 | { | |
1595 | max_regs = 32; | |
1596 | if (thumb_mode) | |
1597 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
1598 | fpu_vfp_ext_v3); | |
1599 | else | |
1600 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
1601 | fpu_vfp_ext_v3); | |
1602 | } | |
1603 | else | |
1604 | max_regs = 16; | |
c19d1205 | 1605 | } |
6057a28f | 1606 | |
c19d1205 | 1607 | base_reg = max_regs; |
a737bd4d | 1608 | |
c19d1205 ZW |
1609 | do |
1610 | { | |
5287ad62 | 1611 | int setmask = 1, addregs = 1; |
dcbf9037 | 1612 | |
037e8744 | 1613 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1614 | |
c19d1205 | 1615 | if (new_base == FAIL) |
a737bd4d | 1616 | { |
dcbf9037 | 1617 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1618 | return FAIL; |
1619 | } | |
dcbf9037 | 1620 | |
b7fc2769 JB |
1621 | if (new_base >= max_regs) |
1622 | { | |
1623 | first_error (_("register out of range in list")); | |
1624 | return FAIL; | |
1625 | } | |
1626 | ||
5287ad62 JB |
1627 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1628 | if (regtype == REG_TYPE_NQ) | |
1629 | { | |
1630 | setmask = 3; | |
1631 | addregs = 2; | |
1632 | } | |
1633 | ||
c19d1205 ZW |
1634 | if (new_base < base_reg) |
1635 | base_reg = new_base; | |
a737bd4d | 1636 | |
5287ad62 | 1637 | if (mask & (setmask << new_base)) |
c19d1205 | 1638 | { |
dcbf9037 | 1639 | first_error (_("invalid register list")); |
c19d1205 | 1640 | return FAIL; |
a737bd4d | 1641 | } |
a737bd4d | 1642 | |
c19d1205 ZW |
1643 | if ((mask >> new_base) != 0 && ! warned) |
1644 | { | |
1645 | as_tsktsk (_("register list not in ascending order")); | |
1646 | warned = 1; | |
1647 | } | |
0bbf2aa4 | 1648 | |
5287ad62 JB |
1649 | mask |= setmask << new_base; |
1650 | count += addregs; | |
0bbf2aa4 | 1651 | |
037e8744 | 1652 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1653 | { |
1654 | int high_range; | |
0bbf2aa4 | 1655 | |
037e8744 | 1656 | str++; |
0bbf2aa4 | 1657 | |
037e8744 | 1658 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1659 | == FAIL) |
c19d1205 ZW |
1660 | { |
1661 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1662 | return FAIL; | |
1663 | } | |
0bbf2aa4 | 1664 | |
b7fc2769 JB |
1665 | if (high_range >= max_regs) |
1666 | { | |
1667 | first_error (_("register out of range in list")); | |
1668 | return FAIL; | |
1669 | } | |
1670 | ||
5287ad62 JB |
1671 | if (regtype == REG_TYPE_NQ) |
1672 | high_range = high_range + 1; | |
1673 | ||
c19d1205 ZW |
1674 | if (high_range <= new_base) |
1675 | { | |
1676 | inst.error = _("register range not in ascending order"); | |
1677 | return FAIL; | |
1678 | } | |
0bbf2aa4 | 1679 | |
5287ad62 | 1680 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1681 | { |
5287ad62 | 1682 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1683 | { |
c19d1205 ZW |
1684 | inst.error = _("invalid register list"); |
1685 | return FAIL; | |
0bbf2aa4 | 1686 | } |
c19d1205 | 1687 | |
5287ad62 JB |
1688 | mask |= setmask << new_base; |
1689 | count += addregs; | |
0bbf2aa4 | 1690 | } |
0bbf2aa4 | 1691 | } |
0bbf2aa4 | 1692 | } |
037e8744 | 1693 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1694 | |
037e8744 | 1695 | str++; |
0bbf2aa4 | 1696 | |
c19d1205 ZW |
1697 | /* Sanity check -- should have raised a parse error above. */ |
1698 | if (count == 0 || count > max_regs) | |
1699 | abort (); | |
1700 | ||
1701 | *pbase = base_reg; | |
1702 | ||
1703 | /* Final test -- the registers must be consecutive. */ | |
1704 | mask >>= base_reg; | |
1705 | for (i = 0; i < count; i++) | |
1706 | { | |
1707 | if ((mask & (1u << i)) == 0) | |
1708 | { | |
1709 | inst.error = _("non-contiguous register range"); | |
1710 | return FAIL; | |
1711 | } | |
1712 | } | |
1713 | ||
037e8744 JB |
1714 | *ccp = str; |
1715 | ||
c19d1205 | 1716 | return count; |
b99bd4ef NC |
1717 | } |
1718 | ||
dcbf9037 JB |
1719 | /* True if two alias types are the same. */ |
1720 | ||
1721 | static int | |
1722 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) | |
1723 | { | |
1724 | if (!a && !b) | |
1725 | return 1; | |
1726 | ||
1727 | if (!a || !b) | |
1728 | return 0; | |
1729 | ||
1730 | if (a->defined != b->defined) | |
1731 | return 0; | |
1732 | ||
1733 | if ((a->defined & NTA_HASTYPE) != 0 | |
1734 | && (a->eltype.type != b->eltype.type | |
1735 | || a->eltype.size != b->eltype.size)) | |
1736 | return 0; | |
1737 | ||
1738 | if ((a->defined & NTA_HASINDEX) != 0 | |
1739 | && (a->index != b->index)) | |
1740 | return 0; | |
1741 | ||
1742 | return 1; | |
1743 | } | |
1744 | ||
5287ad62 JB |
1745 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1746 | The base register is put in *PBASE. | |
dcbf9037 | 1747 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1748 | the return value. |
1749 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1750 | Bits [6:5] encode the list length (minus one). |
1751 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1752 | |
5287ad62 | 1753 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1754 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1755 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1756 | ||
1757 | static int | |
dcbf9037 JB |
1758 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1759 | struct neon_type_el *eltype) | |
5287ad62 JB |
1760 | { |
1761 | char *ptr = *str; | |
1762 | int base_reg = -1; | |
1763 | int reg_incr = -1; | |
1764 | int count = 0; | |
1765 | int lane = -1; | |
1766 | int leading_brace = 0; | |
1767 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
1768 | int addregs = 1; | |
1769 | const char *const incr_error = "register stride must be 1 or 2"; | |
1770 | const char *const type_error = "mismatched element/structure types in list"; | |
dcbf9037 | 1771 | struct neon_typed_alias firsttype; |
5287ad62 JB |
1772 | |
1773 | if (skip_past_char (&ptr, '{') == SUCCESS) | |
1774 | leading_brace = 1; | |
1775 | ||
1776 | do | |
1777 | { | |
dcbf9037 JB |
1778 | struct neon_typed_alias atype; |
1779 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1780 | ||
5287ad62 JB |
1781 | if (getreg == FAIL) |
1782 | { | |
dcbf9037 | 1783 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1784 | return FAIL; |
1785 | } | |
1786 | ||
1787 | if (base_reg == -1) | |
1788 | { | |
1789 | base_reg = getreg; | |
1790 | if (rtype == REG_TYPE_NQ) | |
1791 | { | |
1792 | reg_incr = 1; | |
1793 | addregs = 2; | |
1794 | } | |
dcbf9037 | 1795 | firsttype = atype; |
5287ad62 JB |
1796 | } |
1797 | else if (reg_incr == -1) | |
1798 | { | |
1799 | reg_incr = getreg - base_reg; | |
1800 | if (reg_incr < 1 || reg_incr > 2) | |
1801 | { | |
dcbf9037 | 1802 | first_error (_(incr_error)); |
5287ad62 JB |
1803 | return FAIL; |
1804 | } | |
1805 | } | |
1806 | else if (getreg != base_reg + reg_incr * count) | |
1807 | { | |
dcbf9037 JB |
1808 | first_error (_(incr_error)); |
1809 | return FAIL; | |
1810 | } | |
1811 | ||
1812 | if (!neon_alias_types_same (&atype, &firsttype)) | |
1813 | { | |
1814 | first_error (_(type_error)); | |
5287ad62 JB |
1815 | return FAIL; |
1816 | } | |
1817 | ||
1818 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list | |
1819 | modes. */ | |
1820 | if (ptr[0] == '-') | |
1821 | { | |
dcbf9037 | 1822 | struct neon_typed_alias htype; |
5287ad62 JB |
1823 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1824 | if (lane == -1) | |
1825 | lane = NEON_INTERLEAVE_LANES; | |
1826 | else if (lane != NEON_INTERLEAVE_LANES) | |
1827 | { | |
dcbf9037 | 1828 | first_error (_(type_error)); |
5287ad62 JB |
1829 | return FAIL; |
1830 | } | |
1831 | if (reg_incr == -1) | |
1832 | reg_incr = 1; | |
1833 | else if (reg_incr != 1) | |
1834 | { | |
dcbf9037 | 1835 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
1836 | return FAIL; |
1837 | } | |
1838 | ptr++; | |
dcbf9037 | 1839 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
1840 | if (hireg == FAIL) |
1841 | { | |
dcbf9037 JB |
1842 | first_error (_(reg_expected_msgs[rtype])); |
1843 | return FAIL; | |
1844 | } | |
1845 | if (!neon_alias_types_same (&htype, &firsttype)) | |
1846 | { | |
1847 | first_error (_(type_error)); | |
5287ad62 JB |
1848 | return FAIL; |
1849 | } | |
1850 | count += hireg + dregs - getreg; | |
1851 | continue; | |
1852 | } | |
1853 | ||
1854 | /* If we're using Q registers, we can't use [] or [n] syntax. */ | |
1855 | if (rtype == REG_TYPE_NQ) | |
1856 | { | |
1857 | count += 2; | |
1858 | continue; | |
1859 | } | |
1860 | ||
dcbf9037 | 1861 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 1862 | { |
dcbf9037 JB |
1863 | if (lane == -1) |
1864 | lane = atype.index; | |
1865 | else if (lane != atype.index) | |
5287ad62 | 1866 | { |
dcbf9037 JB |
1867 | first_error (_(type_error)); |
1868 | return FAIL; | |
5287ad62 JB |
1869 | } |
1870 | } | |
1871 | else if (lane == -1) | |
1872 | lane = NEON_INTERLEAVE_LANES; | |
1873 | else if (lane != NEON_INTERLEAVE_LANES) | |
1874 | { | |
dcbf9037 | 1875 | first_error (_(type_error)); |
5287ad62 JB |
1876 | return FAIL; |
1877 | } | |
1878 | count++; | |
1879 | } | |
1880 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
1881 | ||
1882 | /* No lane set by [x]. We must be interleaving structures. */ | |
1883 | if (lane == -1) | |
1884 | lane = NEON_INTERLEAVE_LANES; | |
1885 | ||
1886 | /* Sanity check. */ | |
1887 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
1888 | || (count > 1 && reg_incr == -1)) | |
1889 | { | |
dcbf9037 | 1890 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
1891 | return FAIL; |
1892 | } | |
1893 | ||
1894 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
1895 | { | |
dcbf9037 | 1896 | first_error (_("expected }")); |
5287ad62 JB |
1897 | return FAIL; |
1898 | } | |
1899 | ||
1900 | if (reg_incr == -1) | |
1901 | reg_incr = 1; | |
1902 | ||
dcbf9037 JB |
1903 | if (eltype) |
1904 | *eltype = firsttype.eltype; | |
1905 | ||
5287ad62 JB |
1906 | *pbase = base_reg; |
1907 | *str = ptr; | |
1908 | ||
1909 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); | |
1910 | } | |
1911 | ||
c19d1205 ZW |
1912 | /* Parse an explicit relocation suffix on an expression. This is |
1913 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
1914 | arm_reloc_hsh contains no entries, so this function can only | |
1915 | succeed if there is no () after the word. Returns -1 on error, | |
1916 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
1917 | static int | |
1918 | parse_reloc (char **str) | |
b99bd4ef | 1919 | { |
c19d1205 ZW |
1920 | struct reloc_entry *r; |
1921 | char *p, *q; | |
b99bd4ef | 1922 | |
c19d1205 ZW |
1923 | if (**str != '(') |
1924 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 1925 | |
c19d1205 ZW |
1926 | p = *str + 1; |
1927 | q = p; | |
1928 | ||
1929 | while (*q && *q != ')' && *q != ',') | |
1930 | q++; | |
1931 | if (*q != ')') | |
1932 | return -1; | |
1933 | ||
1934 | if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
1935 | return -1; | |
1936 | ||
1937 | *str = q + 1; | |
1938 | return r->reloc; | |
b99bd4ef NC |
1939 | } |
1940 | ||
c19d1205 ZW |
1941 | /* Directives: register aliases. */ |
1942 | ||
dcbf9037 | 1943 | static struct reg_entry * |
c19d1205 | 1944 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 1945 | { |
c19d1205 ZW |
1946 | struct reg_entry *new; |
1947 | const char *name; | |
b99bd4ef | 1948 | |
c19d1205 ZW |
1949 | if ((new = hash_find (arm_reg_hsh, str)) != 0) |
1950 | { | |
1951 | if (new->builtin) | |
1952 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); | |
b99bd4ef | 1953 | |
c19d1205 ZW |
1954 | /* Only warn about a redefinition if it's not defined as the |
1955 | same register. */ | |
1956 | else if (new->number != number || new->type != type) | |
1957 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
69b97547 | 1958 | |
dcbf9037 | 1959 | return 0; |
c19d1205 | 1960 | } |
b99bd4ef | 1961 | |
c19d1205 ZW |
1962 | name = xstrdup (str); |
1963 | new = xmalloc (sizeof (struct reg_entry)); | |
b99bd4ef | 1964 | |
c19d1205 ZW |
1965 | new->name = name; |
1966 | new->number = number; | |
1967 | new->type = type; | |
1968 | new->builtin = FALSE; | |
dcbf9037 | 1969 | new->neon = NULL; |
b99bd4ef | 1970 | |
c19d1205 ZW |
1971 | if (hash_insert (arm_reg_hsh, name, (PTR) new)) |
1972 | abort (); | |
dcbf9037 JB |
1973 | |
1974 | return new; | |
1975 | } | |
1976 | ||
1977 | static void | |
1978 | insert_neon_reg_alias (char *str, int number, int type, | |
1979 | struct neon_typed_alias *atype) | |
1980 | { | |
1981 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
1982 | ||
1983 | if (!reg) | |
1984 | { | |
1985 | first_error (_("attempt to redefine typed alias")); | |
1986 | return; | |
1987 | } | |
1988 | ||
1989 | if (atype) | |
1990 | { | |
1991 | reg->neon = xmalloc (sizeof (struct neon_typed_alias)); | |
1992 | *reg->neon = *atype; | |
1993 | } | |
c19d1205 | 1994 | } |
b99bd4ef | 1995 | |
c19d1205 | 1996 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 1997 | |
c19d1205 | 1998 | new_register_name .req existing_register_name |
b99bd4ef | 1999 | |
c19d1205 ZW |
2000 | If we find one, or if it looks sufficiently like one that we want to |
2001 | handle any error here, return non-zero. Otherwise return zero. */ | |
b99bd4ef | 2002 | |
c19d1205 ZW |
2003 | static int |
2004 | create_register_alias (char * newname, char *p) | |
2005 | { | |
2006 | struct reg_entry *old; | |
2007 | char *oldname, *nbuf; | |
2008 | size_t nlen; | |
b99bd4ef | 2009 | |
c19d1205 ZW |
2010 | /* The input scrubber ensures that whitespace after the mnemonic is |
2011 | collapsed to single spaces. */ | |
2012 | oldname = p; | |
2013 | if (strncmp (oldname, " .req ", 6) != 0) | |
2014 | return 0; | |
b99bd4ef | 2015 | |
c19d1205 ZW |
2016 | oldname += 6; |
2017 | if (*oldname == '\0') | |
2018 | return 0; | |
b99bd4ef | 2019 | |
c19d1205 ZW |
2020 | old = hash_find (arm_reg_hsh, oldname); |
2021 | if (!old) | |
b99bd4ef | 2022 | { |
c19d1205 ZW |
2023 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
2024 | return 1; | |
b99bd4ef NC |
2025 | } |
2026 | ||
c19d1205 ZW |
2027 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2028 | the desired alias name, and p points to its end. If not, then | |
2029 | the desired alias name is in the global original_case_string. */ | |
2030 | #ifdef TC_CASE_SENSITIVE | |
2031 | nlen = p - newname; | |
2032 | #else | |
2033 | newname = original_case_string; | |
2034 | nlen = strlen (newname); | |
2035 | #endif | |
b99bd4ef | 2036 | |
c19d1205 ZW |
2037 | nbuf = alloca (nlen + 1); |
2038 | memcpy (nbuf, newname, nlen); | |
2039 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2040 | |
c19d1205 ZW |
2041 | /* Create aliases under the new name as stated; an all-lowercase |
2042 | version of the new name; and an all-uppercase version of the new | |
2043 | name. */ | |
2044 | insert_reg_alias (nbuf, old->number, old->type); | |
b99bd4ef | 2045 | |
c19d1205 ZW |
2046 | for (p = nbuf; *p; p++) |
2047 | *p = TOUPPER (*p); | |
2048 | ||
2049 | if (strncmp (nbuf, newname, nlen)) | |
2050 | insert_reg_alias (nbuf, old->number, old->type); | |
2051 | ||
2052 | for (p = nbuf; *p; p++) | |
2053 | *p = TOLOWER (*p); | |
2054 | ||
2055 | if (strncmp (nbuf, newname, nlen)) | |
2056 | insert_reg_alias (nbuf, old->number, old->type); | |
2057 | ||
2058 | return 1; | |
b99bd4ef NC |
2059 | } |
2060 | ||
dcbf9037 JB |
2061 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2062 | X .dn d5.s32[1] | |
2063 | Y .qn 6.s16 | |
2064 | Z .dn d7 | |
2065 | T .dn Z[0] | |
2066 | These typed registers can be used instead of the types specified after the | |
2067 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2068 | specified directly, e.g.: | |
2069 | vadd d0.s32, d1.s32, d2.s32 | |
2070 | */ | |
2071 | ||
2072 | static int | |
2073 | create_neon_reg_alias (char *newname, char *p) | |
2074 | { | |
2075 | enum arm_reg_type basetype; | |
2076 | struct reg_entry *basereg; | |
2077 | struct reg_entry mybasereg; | |
2078 | struct neon_type ntype; | |
2079 | struct neon_typed_alias typeinfo; | |
2080 | char *namebuf, *nameend; | |
2081 | int namelen; | |
2082 | ||
2083 | typeinfo.defined = 0; | |
2084 | typeinfo.eltype.type = NT_invtype; | |
2085 | typeinfo.eltype.size = -1; | |
2086 | typeinfo.index = -1; | |
2087 | ||
2088 | nameend = p; | |
2089 | ||
2090 | if (strncmp (p, " .dn ", 5) == 0) | |
2091 | basetype = REG_TYPE_VFD; | |
2092 | else if (strncmp (p, " .qn ", 5) == 0) | |
2093 | basetype = REG_TYPE_NQ; | |
2094 | else | |
2095 | return 0; | |
2096 | ||
2097 | p += 5; | |
2098 | ||
2099 | if (*p == '\0') | |
2100 | return 0; | |
2101 | ||
2102 | basereg = arm_reg_parse_multi (&p); | |
2103 | ||
2104 | if (basereg && basereg->type != basetype) | |
2105 | { | |
2106 | as_bad (_("bad type for register")); | |
2107 | return 0; | |
2108 | } | |
2109 | ||
2110 | if (basereg == NULL) | |
2111 | { | |
2112 | expressionS exp; | |
2113 | /* Try parsing as an integer. */ | |
2114 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2115 | if (exp.X_op != O_constant) | |
2116 | { | |
2117 | as_bad (_("expression must be constant")); | |
2118 | return 0; | |
2119 | } | |
2120 | basereg = &mybasereg; | |
2121 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2122 | : exp.X_add_number; | |
2123 | basereg->neon = 0; | |
2124 | } | |
2125 | ||
2126 | if (basereg->neon) | |
2127 | typeinfo = *basereg->neon; | |
2128 | ||
2129 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2130 | { | |
2131 | /* We got a type. */ | |
2132 | if (typeinfo.defined & NTA_HASTYPE) | |
2133 | { | |
2134 | as_bad (_("can't redefine the type of a register alias")); | |
2135 | return 0; | |
2136 | } | |
2137 | ||
2138 | typeinfo.defined |= NTA_HASTYPE; | |
2139 | if (ntype.elems != 1) | |
2140 | { | |
2141 | as_bad (_("you must specify a single type only")); | |
2142 | return 0; | |
2143 | } | |
2144 | typeinfo.eltype = ntype.el[0]; | |
2145 | } | |
2146 | ||
2147 | if (skip_past_char (&p, '[') == SUCCESS) | |
2148 | { | |
2149 | expressionS exp; | |
2150 | /* We got a scalar index. */ | |
2151 | ||
2152 | if (typeinfo.defined & NTA_HASINDEX) | |
2153 | { | |
2154 | as_bad (_("can't redefine the index of a scalar alias")); | |
2155 | return 0; | |
2156 | } | |
2157 | ||
2158 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2159 | ||
2160 | if (exp.X_op != O_constant) | |
2161 | { | |
2162 | as_bad (_("scalar index must be constant")); | |
2163 | return 0; | |
2164 | } | |
2165 | ||
2166 | typeinfo.defined |= NTA_HASINDEX; | |
2167 | typeinfo.index = exp.X_add_number; | |
2168 | ||
2169 | if (skip_past_char (&p, ']') == FAIL) | |
2170 | { | |
2171 | as_bad (_("expecting ]")); | |
2172 | return 0; | |
2173 | } | |
2174 | } | |
2175 | ||
2176 | namelen = nameend - newname; | |
2177 | namebuf = alloca (namelen + 1); | |
2178 | strncpy (namebuf, newname, namelen); | |
2179 | namebuf[namelen] = '\0'; | |
2180 | ||
2181 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2182 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
2183 | ||
2184 | /* Insert name in all uppercase. */ | |
2185 | for (p = namebuf; *p; p++) | |
2186 | *p = TOUPPER (*p); | |
2187 | ||
2188 | if (strncmp (namebuf, newname, namelen)) | |
2189 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2190 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
2191 | ||
2192 | /* Insert name in all lowercase. */ | |
2193 | for (p = namebuf; *p; p++) | |
2194 | *p = TOLOWER (*p); | |
2195 | ||
2196 | if (strncmp (namebuf, newname, namelen)) | |
2197 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2198 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
2199 | ||
2200 | return 1; | |
2201 | } | |
2202 | ||
c19d1205 ZW |
2203 | /* Should never be called, as .req goes between the alias and the |
2204 | register name, not at the beginning of the line. */ | |
b99bd4ef | 2205 | static void |
c19d1205 | 2206 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2207 | { |
c19d1205 ZW |
2208 | as_bad (_("invalid syntax for .req directive")); |
2209 | } | |
b99bd4ef | 2210 | |
dcbf9037 JB |
2211 | static void |
2212 | s_dn (int a ATTRIBUTE_UNUSED) | |
2213 | { | |
2214 | as_bad (_("invalid syntax for .dn directive")); | |
2215 | } | |
2216 | ||
2217 | static void | |
2218 | s_qn (int a ATTRIBUTE_UNUSED) | |
2219 | { | |
2220 | as_bad (_("invalid syntax for .qn directive")); | |
2221 | } | |
2222 | ||
c19d1205 ZW |
2223 | /* The .unreq directive deletes an alias which was previously defined |
2224 | by .req. For example: | |
b99bd4ef | 2225 | |
c19d1205 ZW |
2226 | my_alias .req r11 |
2227 | .unreq my_alias */ | |
b99bd4ef NC |
2228 | |
2229 | static void | |
c19d1205 | 2230 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2231 | { |
c19d1205 ZW |
2232 | char * name; |
2233 | char saved_char; | |
b99bd4ef | 2234 | |
c19d1205 ZW |
2235 | name = input_line_pointer; |
2236 | ||
2237 | while (*input_line_pointer != 0 | |
2238 | && *input_line_pointer != ' ' | |
2239 | && *input_line_pointer != '\n') | |
2240 | ++input_line_pointer; | |
2241 | ||
2242 | saved_char = *input_line_pointer; | |
2243 | *input_line_pointer = 0; | |
2244 | ||
2245 | if (!*name) | |
2246 | as_bad (_("invalid syntax for .unreq directive")); | |
2247 | else | |
2248 | { | |
2249 | struct reg_entry *reg = hash_find (arm_reg_hsh, name); | |
2250 | ||
2251 | if (!reg) | |
2252 | as_bad (_("unknown register alias '%s'"), name); | |
2253 | else if (reg->builtin) | |
2254 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
2255 | name); | |
2256 | else | |
2257 | { | |
2258 | hash_delete (arm_reg_hsh, name); | |
2259 | free ((char *) reg->name); | |
dcbf9037 JB |
2260 | if (reg->neon) |
2261 | free (reg->neon); | |
c19d1205 ZW |
2262 | free (reg); |
2263 | } | |
2264 | } | |
b99bd4ef | 2265 | |
c19d1205 | 2266 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2267 | demand_empty_rest_of_line (); |
2268 | } | |
2269 | ||
c19d1205 ZW |
2270 | /* Directives: Instruction set selection. */ |
2271 | ||
2272 | #ifdef OBJ_ELF | |
2273 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2274 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2275 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2276 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2277 | ||
2278 | static enum mstate mapstate = MAP_UNDEFINED; | |
b99bd4ef NC |
2279 | |
2280 | static void | |
c19d1205 | 2281 | mapping_state (enum mstate state) |
b99bd4ef | 2282 | { |
a737bd4d | 2283 | symbolS * symbolP; |
c19d1205 ZW |
2284 | const char * symname; |
2285 | int type; | |
b99bd4ef | 2286 | |
c19d1205 ZW |
2287 | if (mapstate == state) |
2288 | /* The mapping symbol has already been emitted. | |
2289 | There is nothing else to do. */ | |
2290 | return; | |
b99bd4ef | 2291 | |
c19d1205 | 2292 | mapstate = state; |
b99bd4ef | 2293 | |
c19d1205 | 2294 | switch (state) |
b99bd4ef | 2295 | { |
c19d1205 ZW |
2296 | case MAP_DATA: |
2297 | symname = "$d"; | |
2298 | type = BSF_NO_FLAGS; | |
2299 | break; | |
2300 | case MAP_ARM: | |
2301 | symname = "$a"; | |
2302 | type = BSF_NO_FLAGS; | |
2303 | break; | |
2304 | case MAP_THUMB: | |
2305 | symname = "$t"; | |
2306 | type = BSF_NO_FLAGS; | |
2307 | break; | |
2308 | case MAP_UNDEFINED: | |
2309 | return; | |
2310 | default: | |
2311 | abort (); | |
2312 | } | |
2313 | ||
2314 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; | |
2315 | ||
2316 | symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now); | |
2317 | symbol_table_insert (symbolP); | |
2318 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; | |
2319 | ||
2320 | switch (state) | |
2321 | { | |
2322 | case MAP_ARM: | |
2323 | THUMB_SET_FUNC (symbolP, 0); | |
2324 | ARM_SET_THUMB (symbolP, 0); | |
2325 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2326 | break; | |
2327 | ||
2328 | case MAP_THUMB: | |
2329 | THUMB_SET_FUNC (symbolP, 1); | |
2330 | ARM_SET_THUMB (symbolP, 1); | |
2331 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2332 | break; | |
2333 | ||
2334 | case MAP_DATA: | |
2335 | default: | |
2336 | return; | |
2337 | } | |
2338 | } | |
2339 | #else | |
2340 | #define mapping_state(x) /* nothing */ | |
2341 | #endif | |
2342 | ||
2343 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2344 | ||
2345 | static symbolS * | |
2346 | find_real_start (symbolS * symbolP) | |
2347 | { | |
2348 | char * real_start; | |
2349 | const char * name = S_GET_NAME (symbolP); | |
2350 | symbolS * new_target; | |
2351 | ||
2352 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2353 | #define STUB_NAME ".real_start_of" | |
2354 | ||
2355 | if (name == NULL) | |
2356 | abort (); | |
2357 | ||
37f6032b ZW |
2358 | /* The compiler may generate BL instructions to local labels because |
2359 | it needs to perform a branch to a far away location. These labels | |
2360 | do not have a corresponding ".real_start_of" label. We check | |
2361 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2362 | the ".real_start_of" convention for nonlocal branches. */ | |
2363 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2364 | return symbolP; |
2365 | ||
37f6032b | 2366 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2367 | new_target = symbol_find (real_start); |
2368 | ||
2369 | if (new_target == NULL) | |
2370 | { | |
2371 | as_warn ("Failed to find real start of function: %s\n", name); | |
2372 | new_target = symbolP; | |
2373 | } | |
2374 | ||
c19d1205 ZW |
2375 | return new_target; |
2376 | } | |
2377 | ||
2378 | static void | |
2379 | opcode_select (int width) | |
2380 | { | |
2381 | switch (width) | |
2382 | { | |
2383 | case 16: | |
2384 | if (! thumb_mode) | |
2385 | { | |
e74cfd16 | 2386 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2387 | as_bad (_("selected processor does not support THUMB opcodes")); |
2388 | ||
2389 | thumb_mode = 1; | |
2390 | /* No need to force the alignment, since we will have been | |
2391 | coming from ARM mode, which is word-aligned. */ | |
2392 | record_alignment (now_seg, 1); | |
2393 | } | |
2394 | mapping_state (MAP_THUMB); | |
2395 | break; | |
2396 | ||
2397 | case 32: | |
2398 | if (thumb_mode) | |
2399 | { | |
e74cfd16 | 2400 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2401 | as_bad (_("selected processor does not support ARM opcodes")); |
2402 | ||
2403 | thumb_mode = 0; | |
2404 | ||
2405 | if (!need_pass_2) | |
2406 | frag_align (2, 0, 0); | |
2407 | ||
2408 | record_alignment (now_seg, 1); | |
2409 | } | |
2410 | mapping_state (MAP_ARM); | |
2411 | break; | |
2412 | ||
2413 | default: | |
2414 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2415 | } | |
2416 | } | |
2417 | ||
2418 | static void | |
2419 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2420 | { | |
2421 | opcode_select (32); | |
2422 | demand_empty_rest_of_line (); | |
2423 | } | |
2424 | ||
2425 | static void | |
2426 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2427 | { | |
2428 | opcode_select (16); | |
2429 | demand_empty_rest_of_line (); | |
2430 | } | |
2431 | ||
2432 | static void | |
2433 | s_code (int unused ATTRIBUTE_UNUSED) | |
2434 | { | |
2435 | int temp; | |
2436 | ||
2437 | temp = get_absolute_expression (); | |
2438 | switch (temp) | |
2439 | { | |
2440 | case 16: | |
2441 | case 32: | |
2442 | opcode_select (temp); | |
2443 | break; | |
2444 | ||
2445 | default: | |
2446 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2447 | } | |
2448 | } | |
2449 | ||
2450 | static void | |
2451 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2452 | { | |
2453 | /* If we are not already in thumb mode go into it, EVEN if | |
2454 | the target processor does not support thumb instructions. | |
2455 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2456 | to compile interworking support functions even if the | |
2457 | target processor should not support interworking. */ | |
2458 | if (! thumb_mode) | |
2459 | { | |
2460 | thumb_mode = 2; | |
2461 | record_alignment (now_seg, 1); | |
2462 | } | |
2463 | ||
2464 | demand_empty_rest_of_line (); | |
2465 | } | |
2466 | ||
2467 | static void | |
2468 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2469 | { | |
2470 | s_thumb (0); | |
2471 | ||
2472 | /* The following label is the name/address of the start of a Thumb function. | |
2473 | We need to know this for the interworking support. */ | |
2474 | label_is_thumb_function_name = TRUE; | |
2475 | } | |
2476 | ||
2477 | /* Perform a .set directive, but also mark the alias as | |
2478 | being a thumb function. */ | |
2479 | ||
2480 | static void | |
2481 | s_thumb_set (int equiv) | |
2482 | { | |
2483 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2484 | We cannot just call that code as we need to get at the symbol that | |
2485 | is created. */ | |
2486 | char * name; | |
2487 | char delim; | |
2488 | char * end_name; | |
2489 | symbolS * symbolP; | |
2490 | ||
2491 | /* Especial apologies for the random logic: | |
2492 | This just grew, and could be parsed much more simply! | |
2493 | Dean - in haste. */ | |
2494 | name = input_line_pointer; | |
2495 | delim = get_symbol_end (); | |
2496 | end_name = input_line_pointer; | |
2497 | *end_name = delim; | |
2498 | ||
2499 | if (*input_line_pointer != ',') | |
2500 | { | |
2501 | *end_name = 0; | |
2502 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2503 | *end_name = delim; |
2504 | ignore_rest_of_line (); | |
2505 | return; | |
2506 | } | |
2507 | ||
2508 | input_line_pointer++; | |
2509 | *end_name = 0; | |
2510 | ||
2511 | if (name[0] == '.' && name[1] == '\0') | |
2512 | { | |
2513 | /* XXX - this should not happen to .thumb_set. */ | |
2514 | abort (); | |
2515 | } | |
2516 | ||
2517 | if ((symbolP = symbol_find (name)) == NULL | |
2518 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2519 | { | |
2520 | #ifndef NO_LISTING | |
2521 | /* When doing symbol listings, play games with dummy fragments living | |
2522 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2523 | for this symbol. */ |
b99bd4ef NC |
2524 | if (listing & LISTING_SYMBOLS) |
2525 | { | |
2526 | extern struct list_info_struct * listing_tail; | |
a737bd4d | 2527 | fragS * dummy_frag = xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2528 | |
2529 | memset (dummy_frag, 0, sizeof (fragS)); | |
2530 | dummy_frag->fr_type = rs_fill; | |
2531 | dummy_frag->line = listing_tail; | |
2532 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2533 | dummy_frag->fr_symbol = symbolP; | |
2534 | } | |
2535 | else | |
2536 | #endif | |
2537 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2538 | ||
2539 | #ifdef OBJ_COFF | |
2540 | /* "set" symbols are local unless otherwise specified. */ | |
2541 | SF_SET_LOCAL (symbolP); | |
2542 | #endif /* OBJ_COFF */ | |
2543 | } /* Make a new symbol. */ | |
2544 | ||
2545 | symbol_table_insert (symbolP); | |
2546 | ||
2547 | * end_name = delim; | |
2548 | ||
2549 | if (equiv | |
2550 | && S_IS_DEFINED (symbolP) | |
2551 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2552 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2553 | ||
2554 | pseudo_set (symbolP); | |
2555 | ||
2556 | demand_empty_rest_of_line (); | |
2557 | ||
c19d1205 | 2558 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2559 | |
2560 | THUMB_SET_FUNC (symbolP, 1); | |
2561 | ARM_SET_THUMB (symbolP, 1); | |
2562 | #if defined OBJ_ELF || defined OBJ_COFF | |
2563 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2564 | #endif | |
2565 | } | |
2566 | ||
c19d1205 | 2567 | /* Directives: Mode selection. */ |
b99bd4ef | 2568 | |
c19d1205 ZW |
2569 | /* .syntax [unified|divided] - choose the new unified syntax |
2570 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2571 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2572 | static void |
c19d1205 | 2573 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2574 | { |
c19d1205 ZW |
2575 | char *name, delim; |
2576 | ||
2577 | name = input_line_pointer; | |
2578 | delim = get_symbol_end (); | |
2579 | ||
2580 | if (!strcasecmp (name, "unified")) | |
2581 | unified_syntax = TRUE; | |
2582 | else if (!strcasecmp (name, "divided")) | |
2583 | unified_syntax = FALSE; | |
2584 | else | |
2585 | { | |
2586 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2587 | return; | |
2588 | } | |
2589 | *input_line_pointer = delim; | |
b99bd4ef NC |
2590 | demand_empty_rest_of_line (); |
2591 | } | |
2592 | ||
c19d1205 ZW |
2593 | /* Directives: sectioning and alignment. */ |
2594 | ||
2595 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2596 | ||
b99bd4ef | 2597 | static void |
c19d1205 | 2598 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2599 | { |
a737bd4d | 2600 | int temp; |
c19d1205 ZW |
2601 | long temp_fill; |
2602 | long max_alignment = 15; | |
b99bd4ef NC |
2603 | |
2604 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2605 | if (temp > max_alignment) |
2606 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2607 | else if (temp < 0) | |
b99bd4ef | 2608 | { |
c19d1205 ZW |
2609 | as_bad (_("alignment negative. 0 assumed.")); |
2610 | temp = 0; | |
2611 | } | |
b99bd4ef | 2612 | |
c19d1205 ZW |
2613 | if (*input_line_pointer == ',') |
2614 | { | |
2615 | input_line_pointer++; | |
2616 | temp_fill = get_absolute_expression (); | |
b99bd4ef | 2617 | } |
c19d1205 ZW |
2618 | else |
2619 | temp_fill = 0; | |
b99bd4ef | 2620 | |
c19d1205 ZW |
2621 | if (!temp) |
2622 | temp = 2; | |
b99bd4ef | 2623 | |
c19d1205 ZW |
2624 | /* Only make a frag if we HAVE to. */ |
2625 | if (temp && !need_pass_2) | |
2626 | frag_align (temp, (int) temp_fill, 0); | |
2627 | demand_empty_rest_of_line (); | |
2628 | ||
2629 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2630 | } |
2631 | ||
c19d1205 ZW |
2632 | static void |
2633 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2634 | { |
c19d1205 ZW |
2635 | /* We don't support putting frags in the BSS segment, we fake it by |
2636 | marking in_bss, then looking at s_skip for clues. */ | |
2637 | subseg_set (bss_section, 0); | |
2638 | demand_empty_rest_of_line (); | |
2639 | mapping_state (MAP_DATA); | |
2640 | } | |
b99bd4ef | 2641 | |
c19d1205 ZW |
2642 | static void |
2643 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2644 | { | |
2645 | /* Never make frag if expect extra pass. */ | |
2646 | if (!need_pass_2) | |
2647 | frag_align (1, 0, 0); | |
b99bd4ef | 2648 | |
c19d1205 | 2649 | record_alignment (now_seg, 1); |
b99bd4ef | 2650 | |
c19d1205 | 2651 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2652 | } |
2653 | ||
c19d1205 | 2654 | /* Directives: Literal pools. */ |
a737bd4d | 2655 | |
c19d1205 ZW |
2656 | static literal_pool * |
2657 | find_literal_pool (void) | |
a737bd4d | 2658 | { |
c19d1205 | 2659 | literal_pool * pool; |
a737bd4d | 2660 | |
c19d1205 | 2661 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 2662 | { |
c19d1205 ZW |
2663 | if (pool->section == now_seg |
2664 | && pool->sub_section == now_subseg) | |
2665 | break; | |
a737bd4d NC |
2666 | } |
2667 | ||
c19d1205 | 2668 | return pool; |
a737bd4d NC |
2669 | } |
2670 | ||
c19d1205 ZW |
2671 | static literal_pool * |
2672 | find_or_make_literal_pool (void) | |
a737bd4d | 2673 | { |
c19d1205 ZW |
2674 | /* Next literal pool ID number. */ |
2675 | static unsigned int latest_pool_num = 1; | |
2676 | literal_pool * pool; | |
a737bd4d | 2677 | |
c19d1205 | 2678 | pool = find_literal_pool (); |
a737bd4d | 2679 | |
c19d1205 | 2680 | if (pool == NULL) |
a737bd4d | 2681 | { |
c19d1205 ZW |
2682 | /* Create a new pool. */ |
2683 | pool = xmalloc (sizeof (* pool)); | |
2684 | if (! pool) | |
2685 | return NULL; | |
a737bd4d | 2686 | |
c19d1205 ZW |
2687 | pool->next_free_entry = 0; |
2688 | pool->section = now_seg; | |
2689 | pool->sub_section = now_subseg; | |
2690 | pool->next = list_of_pools; | |
2691 | pool->symbol = NULL; | |
2692 | ||
2693 | /* Add it to the list. */ | |
2694 | list_of_pools = pool; | |
a737bd4d | 2695 | } |
a737bd4d | 2696 | |
c19d1205 ZW |
2697 | /* New pools, and emptied pools, will have a NULL symbol. */ |
2698 | if (pool->symbol == NULL) | |
a737bd4d | 2699 | { |
c19d1205 ZW |
2700 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
2701 | (valueT) 0, &zero_address_frag); | |
2702 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
2703 | } |
2704 | ||
c19d1205 ZW |
2705 | /* Done. */ |
2706 | return pool; | |
a737bd4d NC |
2707 | } |
2708 | ||
c19d1205 ZW |
2709 | /* Add the literal in the global 'inst' |
2710 | structure to the relevent literal pool. */ | |
b99bd4ef NC |
2711 | |
2712 | static int | |
c19d1205 | 2713 | add_to_lit_pool (void) |
b99bd4ef | 2714 | { |
c19d1205 ZW |
2715 | literal_pool * pool; |
2716 | unsigned int entry; | |
b99bd4ef | 2717 | |
c19d1205 ZW |
2718 | pool = find_or_make_literal_pool (); |
2719 | ||
2720 | /* Check if this literal value is already in the pool. */ | |
2721 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 2722 | { |
c19d1205 ZW |
2723 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
2724 | && (inst.reloc.exp.X_op == O_constant) | |
2725 | && (pool->literals[entry].X_add_number | |
2726 | == inst.reloc.exp.X_add_number) | |
2727 | && (pool->literals[entry].X_unsigned | |
2728 | == inst.reloc.exp.X_unsigned)) | |
2729 | break; | |
2730 | ||
2731 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
2732 | && (inst.reloc.exp.X_op == O_symbol) | |
2733 | && (pool->literals[entry].X_add_number | |
2734 | == inst.reloc.exp.X_add_number) | |
2735 | && (pool->literals[entry].X_add_symbol | |
2736 | == inst.reloc.exp.X_add_symbol) | |
2737 | && (pool->literals[entry].X_op_symbol | |
2738 | == inst.reloc.exp.X_op_symbol)) | |
2739 | break; | |
b99bd4ef NC |
2740 | } |
2741 | ||
c19d1205 ZW |
2742 | /* Do we need to create a new entry? */ |
2743 | if (entry == pool->next_free_entry) | |
2744 | { | |
2745 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
2746 | { | |
2747 | inst.error = _("literal pool overflow"); | |
2748 | return FAIL; | |
2749 | } | |
2750 | ||
2751 | pool->literals[entry] = inst.reloc.exp; | |
2752 | pool->next_free_entry += 1; | |
2753 | } | |
b99bd4ef | 2754 | |
c19d1205 ZW |
2755 | inst.reloc.exp.X_op = O_symbol; |
2756 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
2757 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 2758 | |
c19d1205 | 2759 | return SUCCESS; |
b99bd4ef NC |
2760 | } |
2761 | ||
c19d1205 ZW |
2762 | /* Can't use symbol_new here, so have to create a symbol and then at |
2763 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 2764 | |
c19d1205 ZW |
2765 | static void |
2766 | symbol_locate (symbolS * symbolP, | |
2767 | const char * name, /* It is copied, the caller can modify. */ | |
2768 | segT segment, /* Segment identifier (SEG_<something>). */ | |
2769 | valueT valu, /* Symbol value. */ | |
2770 | fragS * frag) /* Associated fragment. */ | |
2771 | { | |
2772 | unsigned int name_length; | |
2773 | char * preserved_copy_of_name; | |
e16bb312 | 2774 | |
c19d1205 ZW |
2775 | name_length = strlen (name) + 1; /* +1 for \0. */ |
2776 | obstack_grow (¬es, name, name_length); | |
2777 | preserved_copy_of_name = obstack_finish (¬es); | |
e16bb312 | 2778 | |
c19d1205 ZW |
2779 | #ifdef tc_canonicalize_symbol_name |
2780 | preserved_copy_of_name = | |
2781 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
2782 | #endif | |
b99bd4ef | 2783 | |
c19d1205 | 2784 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 2785 | |
c19d1205 ZW |
2786 | S_SET_SEGMENT (symbolP, segment); |
2787 | S_SET_VALUE (symbolP, valu); | |
2788 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 2789 | |
c19d1205 | 2790 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 2791 | |
c19d1205 ZW |
2792 | /* Link to end of symbol chain. */ |
2793 | { | |
2794 | extern int symbol_table_frozen; | |
b99bd4ef | 2795 | |
c19d1205 ZW |
2796 | if (symbol_table_frozen) |
2797 | abort (); | |
2798 | } | |
b99bd4ef | 2799 | |
c19d1205 | 2800 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 2801 | |
c19d1205 | 2802 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 2803 | |
c19d1205 ZW |
2804 | #ifdef tc_symbol_new_hook |
2805 | tc_symbol_new_hook (symbolP); | |
2806 | #endif | |
2807 | ||
2808 | #ifdef DEBUG_SYMS | |
2809 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
2810 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
2811 | } |
2812 | ||
b99bd4ef | 2813 | |
c19d1205 ZW |
2814 | static void |
2815 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 2816 | { |
c19d1205 ZW |
2817 | unsigned int entry; |
2818 | literal_pool * pool; | |
2819 | char sym_name[20]; | |
b99bd4ef | 2820 | |
c19d1205 ZW |
2821 | pool = find_literal_pool (); |
2822 | if (pool == NULL | |
2823 | || pool->symbol == NULL | |
2824 | || pool->next_free_entry == 0) | |
2825 | return; | |
b99bd4ef | 2826 | |
c19d1205 | 2827 | mapping_state (MAP_DATA); |
b99bd4ef | 2828 | |
c19d1205 ZW |
2829 | /* Align pool as you have word accesses. |
2830 | Only make a frag if we have to. */ | |
2831 | if (!need_pass_2) | |
2832 | frag_align (2, 0, 0); | |
b99bd4ef | 2833 | |
c19d1205 | 2834 | record_alignment (now_seg, 2); |
b99bd4ef | 2835 | |
c19d1205 | 2836 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 2837 | |
c19d1205 ZW |
2838 | symbol_locate (pool->symbol, sym_name, now_seg, |
2839 | (valueT) frag_now_fix (), frag_now); | |
2840 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 2841 | |
c19d1205 | 2842 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 2843 | |
c19d1205 ZW |
2844 | #if defined OBJ_COFF || defined OBJ_ELF |
2845 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
2846 | #endif | |
6c43fab6 | 2847 | |
c19d1205 ZW |
2848 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
2849 | /* First output the expression in the instruction to the pool. */ | |
2850 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 2851 | |
c19d1205 ZW |
2852 | /* Mark the pool as empty. */ |
2853 | pool->next_free_entry = 0; | |
2854 | pool->symbol = NULL; | |
b99bd4ef NC |
2855 | } |
2856 | ||
c19d1205 ZW |
2857 | #ifdef OBJ_ELF |
2858 | /* Forward declarations for functions below, in the MD interface | |
2859 | section. */ | |
2860 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
2861 | static valueT create_unwind_entry (int); | |
2862 | static void start_unwind_section (const segT, int); | |
2863 | static void add_unwind_opcode (valueT, int); | |
2864 | static void flush_pending_unwind (void); | |
b99bd4ef | 2865 | |
c19d1205 | 2866 | /* Directives: Data. */ |
b99bd4ef | 2867 | |
c19d1205 ZW |
2868 | static void |
2869 | s_arm_elf_cons (int nbytes) | |
2870 | { | |
2871 | expressionS exp; | |
b99bd4ef | 2872 | |
c19d1205 ZW |
2873 | #ifdef md_flush_pending_output |
2874 | md_flush_pending_output (); | |
2875 | #endif | |
b99bd4ef | 2876 | |
c19d1205 | 2877 | if (is_it_end_of_statement ()) |
b99bd4ef | 2878 | { |
c19d1205 ZW |
2879 | demand_empty_rest_of_line (); |
2880 | return; | |
b99bd4ef NC |
2881 | } |
2882 | ||
c19d1205 ZW |
2883 | #ifdef md_cons_align |
2884 | md_cons_align (nbytes); | |
2885 | #endif | |
b99bd4ef | 2886 | |
c19d1205 ZW |
2887 | mapping_state (MAP_DATA); |
2888 | do | |
b99bd4ef | 2889 | { |
c19d1205 ZW |
2890 | int reloc; |
2891 | char *base = input_line_pointer; | |
b99bd4ef | 2892 | |
c19d1205 | 2893 | expression (& exp); |
b99bd4ef | 2894 | |
c19d1205 ZW |
2895 | if (exp.X_op != O_symbol) |
2896 | emit_expr (&exp, (unsigned int) nbytes); | |
2897 | else | |
2898 | { | |
2899 | char *before_reloc = input_line_pointer; | |
2900 | reloc = parse_reloc (&input_line_pointer); | |
2901 | if (reloc == -1) | |
2902 | { | |
2903 | as_bad (_("unrecognized relocation suffix")); | |
2904 | ignore_rest_of_line (); | |
2905 | return; | |
2906 | } | |
2907 | else if (reloc == BFD_RELOC_UNUSED) | |
2908 | emit_expr (&exp, (unsigned int) nbytes); | |
2909 | else | |
2910 | { | |
2911 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
2912 | int size = bfd_get_reloc_size (howto); | |
b99bd4ef | 2913 | |
2fc8bdac ZW |
2914 | if (reloc == BFD_RELOC_ARM_PLT32) |
2915 | { | |
2916 | as_bad (_("(plt) is only valid on branch targets")); | |
2917 | reloc = BFD_RELOC_UNUSED; | |
2918 | size = 0; | |
2919 | } | |
2920 | ||
c19d1205 | 2921 | if (size > nbytes) |
2fc8bdac | 2922 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
2923 | howto->name, nbytes); |
2924 | else | |
2925 | { | |
2926 | /* We've parsed an expression stopping at O_symbol. | |
2927 | But there may be more expression left now that we | |
2928 | have parsed the relocation marker. Parse it again. | |
2929 | XXX Surely there is a cleaner way to do this. */ | |
2930 | char *p = input_line_pointer; | |
2931 | int offset; | |
2932 | char *save_buf = alloca (input_line_pointer - base); | |
2933 | memcpy (save_buf, base, input_line_pointer - base); | |
2934 | memmove (base + (input_line_pointer - before_reloc), | |
2935 | base, before_reloc - base); | |
2936 | ||
2937 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
2938 | expression (&exp); | |
2939 | memcpy (base, save_buf, p - base); | |
2940 | ||
2941 | offset = nbytes - size; | |
2942 | p = frag_more ((int) nbytes); | |
2943 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
2944 | size, &exp, 0, reloc); | |
2945 | } | |
2946 | } | |
2947 | } | |
b99bd4ef | 2948 | } |
c19d1205 | 2949 | while (*input_line_pointer++ == ','); |
b99bd4ef | 2950 | |
c19d1205 ZW |
2951 | /* Put terminator back into stream. */ |
2952 | input_line_pointer --; | |
2953 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
2954 | } |
2955 | ||
b99bd4ef | 2956 | |
c19d1205 | 2957 | /* Parse a .rel31 directive. */ |
b99bd4ef | 2958 | |
c19d1205 ZW |
2959 | static void |
2960 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
2961 | { | |
2962 | expressionS exp; | |
2963 | char *p; | |
2964 | valueT highbit; | |
b99bd4ef | 2965 | |
c19d1205 ZW |
2966 | highbit = 0; |
2967 | if (*input_line_pointer == '1') | |
2968 | highbit = 0x80000000; | |
2969 | else if (*input_line_pointer != '0') | |
2970 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 2971 | |
c19d1205 ZW |
2972 | input_line_pointer++; |
2973 | if (*input_line_pointer != ',') | |
2974 | as_bad (_("missing comma")); | |
2975 | input_line_pointer++; | |
b99bd4ef | 2976 | |
c19d1205 ZW |
2977 | #ifdef md_flush_pending_output |
2978 | md_flush_pending_output (); | |
2979 | #endif | |
b99bd4ef | 2980 | |
c19d1205 ZW |
2981 | #ifdef md_cons_align |
2982 | md_cons_align (4); | |
2983 | #endif | |
b99bd4ef | 2984 | |
c19d1205 | 2985 | mapping_state (MAP_DATA); |
b99bd4ef | 2986 | |
c19d1205 | 2987 | expression (&exp); |
b99bd4ef | 2988 | |
c19d1205 ZW |
2989 | p = frag_more (4); |
2990 | md_number_to_chars (p, highbit, 4); | |
2991 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
2992 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 2993 | |
c19d1205 | 2994 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2995 | } |
2996 | ||
c19d1205 | 2997 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 2998 | |
c19d1205 | 2999 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3000 | |
c19d1205 ZW |
3001 | static void |
3002 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3003 | { | |
3004 | demand_empty_rest_of_line (); | |
3005 | /* Mark the start of the function. */ | |
3006 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3007 | |
c19d1205 ZW |
3008 | /* Reset the rest of the unwind info. */ |
3009 | unwind.opcode_count = 0; | |
3010 | unwind.table_entry = NULL; | |
3011 | unwind.personality_routine = NULL; | |
3012 | unwind.personality_index = -1; | |
3013 | unwind.frame_size = 0; | |
3014 | unwind.fp_offset = 0; | |
3015 | unwind.fp_reg = 13; | |
3016 | unwind.fp_used = 0; | |
3017 | unwind.sp_restored = 0; | |
3018 | } | |
b99bd4ef | 3019 | |
b99bd4ef | 3020 | |
c19d1205 ZW |
3021 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3022 | for the function. */ | |
b99bd4ef | 3023 | |
c19d1205 ZW |
3024 | static void |
3025 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3026 | { | |
3027 | demand_empty_rest_of_line (); | |
3028 | if (unwind.table_entry) | |
3029 | as_bad (_("dupicate .handlerdata directive")); | |
f02232aa | 3030 | |
c19d1205 ZW |
3031 | create_unwind_entry (1); |
3032 | } | |
a737bd4d | 3033 | |
c19d1205 | 3034 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3035 | |
c19d1205 ZW |
3036 | static void |
3037 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3038 | { | |
3039 | long where; | |
3040 | char *ptr; | |
3041 | valueT val; | |
f02232aa | 3042 | |
c19d1205 | 3043 | demand_empty_rest_of_line (); |
f02232aa | 3044 | |
c19d1205 ZW |
3045 | /* Add eh table entry. */ |
3046 | if (unwind.table_entry == NULL) | |
3047 | val = create_unwind_entry (0); | |
3048 | else | |
3049 | val = 0; | |
f02232aa | 3050 | |
c19d1205 ZW |
3051 | /* Add index table entry. This is two words. */ |
3052 | start_unwind_section (unwind.saved_seg, 1); | |
3053 | frag_align (2, 0, 0); | |
3054 | record_alignment (now_seg, 2); | |
b99bd4ef | 3055 | |
c19d1205 ZW |
3056 | ptr = frag_more (8); |
3057 | where = frag_now_fix () - 8; | |
f02232aa | 3058 | |
c19d1205 ZW |
3059 | /* Self relative offset of the function start. */ |
3060 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3061 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3062 | |
c19d1205 ZW |
3063 | /* Indicate dependency on EHABI-defined personality routines to the |
3064 | linker, if it hasn't been done already. */ | |
3065 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 | |
3066 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3067 | { | |
3068 | static const char *const name[] = { | |
3069 | "__aeabi_unwind_cpp_pr0", | |
3070 | "__aeabi_unwind_cpp_pr1", | |
3071 | "__aeabi_unwind_cpp_pr2" | |
3072 | }; | |
3073 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); | |
3074 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
3075 | marked_pr_dependency |= 1 << unwind.personality_index; | |
3076 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency | |
3077 | = marked_pr_dependency; | |
3078 | } | |
f02232aa | 3079 | |
c19d1205 ZW |
3080 | if (val) |
3081 | /* Inline exception table entry. */ | |
3082 | md_number_to_chars (ptr + 4, val, 4); | |
3083 | else | |
3084 | /* Self relative offset of the table entry. */ | |
3085 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3086 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3087 | |
c19d1205 ZW |
3088 | /* Restore the original section. */ |
3089 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
3090 | } | |
f02232aa | 3091 | |
f02232aa | 3092 | |
c19d1205 | 3093 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3094 | |
c19d1205 ZW |
3095 | static void |
3096 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3097 | { | |
3098 | demand_empty_rest_of_line (); | |
3099 | if (unwind.personality_routine || unwind.personality_index != -1) | |
3100 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3101 | |
c19d1205 ZW |
3102 | unwind.personality_index = -2; |
3103 | } | |
b99bd4ef | 3104 | |
b99bd4ef | 3105 | |
c19d1205 | 3106 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3107 | |
c19d1205 ZW |
3108 | static void |
3109 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3110 | { | |
3111 | expressionS exp; | |
b99bd4ef | 3112 | |
c19d1205 ZW |
3113 | if (unwind.personality_routine || unwind.personality_index != -1) |
3114 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3115 | |
c19d1205 | 3116 | expression (&exp); |
b99bd4ef | 3117 | |
c19d1205 ZW |
3118 | if (exp.X_op != O_constant |
3119 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3120 | { |
c19d1205 ZW |
3121 | as_bad (_("bad personality routine number")); |
3122 | ignore_rest_of_line (); | |
3123 | return; | |
b99bd4ef NC |
3124 | } |
3125 | ||
c19d1205 | 3126 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3127 | |
c19d1205 ZW |
3128 | demand_empty_rest_of_line (); |
3129 | } | |
e16bb312 | 3130 | |
e16bb312 | 3131 | |
c19d1205 | 3132 | /* Parse a personality directive. */ |
e16bb312 | 3133 | |
c19d1205 ZW |
3134 | static void |
3135 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3136 | { | |
3137 | char *name, *p, c; | |
a737bd4d | 3138 | |
c19d1205 ZW |
3139 | if (unwind.personality_routine || unwind.personality_index != -1) |
3140 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3141 | |
c19d1205 ZW |
3142 | name = input_line_pointer; |
3143 | c = get_symbol_end (); | |
3144 | p = input_line_pointer; | |
3145 | unwind.personality_routine = symbol_find_or_make (name); | |
3146 | *p = c; | |
3147 | demand_empty_rest_of_line (); | |
3148 | } | |
e16bb312 | 3149 | |
e16bb312 | 3150 | |
c19d1205 | 3151 | /* Parse a directive saving core registers. */ |
e16bb312 | 3152 | |
c19d1205 ZW |
3153 | static void |
3154 | s_arm_unwind_save_core (void) | |
e16bb312 | 3155 | { |
c19d1205 ZW |
3156 | valueT op; |
3157 | long range; | |
3158 | int n; | |
e16bb312 | 3159 | |
c19d1205 ZW |
3160 | range = parse_reg_list (&input_line_pointer); |
3161 | if (range == FAIL) | |
e16bb312 | 3162 | { |
c19d1205 ZW |
3163 | as_bad (_("expected register list")); |
3164 | ignore_rest_of_line (); | |
3165 | return; | |
3166 | } | |
e16bb312 | 3167 | |
c19d1205 | 3168 | demand_empty_rest_of_line (); |
e16bb312 | 3169 | |
c19d1205 ZW |
3170 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3171 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3172 | ip because it is clobbered by calls. */ | |
3173 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3174 | && (range & 0x3000) == 0x1000) | |
3175 | { | |
3176 | unwind.opcode_count--; | |
3177 | unwind.sp_restored = 0; | |
3178 | range = (range | 0x2000) & ~0x1000; | |
3179 | unwind.pending_offset = 0; | |
3180 | } | |
e16bb312 | 3181 | |
01ae4198 DJ |
3182 | /* Pop r4-r15. */ |
3183 | if (range & 0xfff0) | |
c19d1205 | 3184 | { |
01ae4198 DJ |
3185 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3186 | registers starting with r4, plus maybe r14. */ | |
3187 | for (n = 0; n < 8; n++) | |
3188 | { | |
3189 | /* Break at the first non-saved register. */ | |
3190 | if ((range & (1 << (n + 4))) == 0) | |
3191 | break; | |
3192 | } | |
3193 | /* See if there are any other bits set. */ | |
3194 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3195 | { | |
3196 | /* Use the long form. */ | |
3197 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3198 | add_unwind_opcode (op, 2); | |
3199 | } | |
0dd132b6 | 3200 | else |
01ae4198 DJ |
3201 | { |
3202 | /* Use the short form. */ | |
3203 | if (range & 0x4000) | |
3204 | op = 0xa8; /* Pop r14. */ | |
3205 | else | |
3206 | op = 0xa0; /* Do not pop r14. */ | |
3207 | op |= (n - 1); | |
3208 | add_unwind_opcode (op, 1); | |
3209 | } | |
c19d1205 | 3210 | } |
0dd132b6 | 3211 | |
c19d1205 ZW |
3212 | /* Pop r0-r3. */ |
3213 | if (range & 0xf) | |
3214 | { | |
3215 | op = 0xb100 | (range & 0xf); | |
3216 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3217 | } |
3218 | ||
c19d1205 ZW |
3219 | /* Record the number of bytes pushed. */ |
3220 | for (n = 0; n < 16; n++) | |
3221 | { | |
3222 | if (range & (1 << n)) | |
3223 | unwind.frame_size += 4; | |
3224 | } | |
0dd132b6 NC |
3225 | } |
3226 | ||
c19d1205 ZW |
3227 | |
3228 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3229 | |
3230 | static void | |
c19d1205 | 3231 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3232 | { |
c19d1205 ZW |
3233 | expressionS exp; |
3234 | int num_regs; | |
3235 | valueT op; | |
b99bd4ef | 3236 | |
c19d1205 ZW |
3237 | /* Get Number of registers to transfer. */ |
3238 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3239 | expression (&exp); | |
3240 | else | |
3241 | exp.X_op = O_illegal; | |
b99bd4ef | 3242 | |
c19d1205 | 3243 | if (exp.X_op != O_constant) |
b99bd4ef | 3244 | { |
c19d1205 ZW |
3245 | as_bad (_("expected , <constant>")); |
3246 | ignore_rest_of_line (); | |
b99bd4ef NC |
3247 | return; |
3248 | } | |
3249 | ||
c19d1205 ZW |
3250 | num_regs = exp.X_add_number; |
3251 | ||
3252 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3253 | { |
c19d1205 ZW |
3254 | as_bad (_("number of registers must be in the range [1:4]")); |
3255 | ignore_rest_of_line (); | |
b99bd4ef NC |
3256 | return; |
3257 | } | |
3258 | ||
c19d1205 | 3259 | demand_empty_rest_of_line (); |
b99bd4ef | 3260 | |
c19d1205 ZW |
3261 | if (reg == 4) |
3262 | { | |
3263 | /* Short form. */ | |
3264 | op = 0xb4 | (num_regs - 1); | |
3265 | add_unwind_opcode (op, 1); | |
3266 | } | |
b99bd4ef NC |
3267 | else |
3268 | { | |
c19d1205 ZW |
3269 | /* Long form. */ |
3270 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3271 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3272 | } |
c19d1205 | 3273 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3274 | } |
3275 | ||
c19d1205 | 3276 | |
fa073d69 MS |
3277 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3278 | ||
3279 | static void | |
3280 | s_arm_unwind_save_vfp_armv6 (void) | |
3281 | { | |
3282 | int count; | |
3283 | unsigned int start; | |
3284 | valueT op; | |
3285 | int num_vfpv3_regs = 0; | |
3286 | int num_regs_below_16; | |
3287 | ||
3288 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3289 | if (count == FAIL) | |
3290 | { | |
3291 | as_bad (_("expected register list")); | |
3292 | ignore_rest_of_line (); | |
3293 | return; | |
3294 | } | |
3295 | ||
3296 | demand_empty_rest_of_line (); | |
3297 | ||
3298 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3299 | than FSTMX/FLDMX-style ones). */ | |
3300 | ||
3301 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3302 | if (start >= 16) | |
3303 | num_vfpv3_regs = count; | |
3304 | else if (start + count > 16) | |
3305 | num_vfpv3_regs = start + count - 16; | |
3306 | ||
3307 | if (num_vfpv3_regs > 0) | |
3308 | { | |
3309 | int start_offset = start > 16 ? start - 16 : 0; | |
3310 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3311 | add_unwind_opcode (op, 2); | |
3312 | } | |
3313 | ||
3314 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3315 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
3316 | assert (num_regs_below_16 + num_vfpv3_regs == count); | |
3317 | if (num_regs_below_16 > 0) | |
3318 | { | |
3319 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3320 | add_unwind_opcode (op, 2); | |
3321 | } | |
3322 | ||
3323 | unwind.frame_size += count * 8; | |
3324 | } | |
3325 | ||
3326 | ||
3327 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3328 | |
3329 | static void | |
c19d1205 | 3330 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3331 | { |
c19d1205 | 3332 | int count; |
ca3f61f7 | 3333 | unsigned int reg; |
c19d1205 | 3334 | valueT op; |
b99bd4ef | 3335 | |
5287ad62 | 3336 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3337 | if (count == FAIL) |
b99bd4ef | 3338 | { |
c19d1205 ZW |
3339 | as_bad (_("expected register list")); |
3340 | ignore_rest_of_line (); | |
b99bd4ef NC |
3341 | return; |
3342 | } | |
3343 | ||
c19d1205 | 3344 | demand_empty_rest_of_line (); |
b99bd4ef | 3345 | |
c19d1205 | 3346 | if (reg == 8) |
b99bd4ef | 3347 | { |
c19d1205 ZW |
3348 | /* Short form. */ |
3349 | op = 0xb8 | (count - 1); | |
3350 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3351 | } |
c19d1205 | 3352 | else |
b99bd4ef | 3353 | { |
c19d1205 ZW |
3354 | /* Long form. */ |
3355 | op = 0xb300 | (reg << 4) | (count - 1); | |
3356 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3357 | } |
c19d1205 ZW |
3358 | unwind.frame_size += count * 8 + 4; |
3359 | } | |
b99bd4ef | 3360 | |
b99bd4ef | 3361 | |
c19d1205 ZW |
3362 | /* Parse a directive saving iWMMXt data registers. */ |
3363 | ||
3364 | static void | |
3365 | s_arm_unwind_save_mmxwr (void) | |
3366 | { | |
3367 | int reg; | |
3368 | int hi_reg; | |
3369 | int i; | |
3370 | unsigned mask = 0; | |
3371 | valueT op; | |
b99bd4ef | 3372 | |
c19d1205 ZW |
3373 | if (*input_line_pointer == '{') |
3374 | input_line_pointer++; | |
b99bd4ef | 3375 | |
c19d1205 | 3376 | do |
b99bd4ef | 3377 | { |
dcbf9037 | 3378 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3379 | |
c19d1205 | 3380 | if (reg == FAIL) |
b99bd4ef | 3381 | { |
c19d1205 ZW |
3382 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); |
3383 | goto error; | |
b99bd4ef NC |
3384 | } |
3385 | ||
c19d1205 ZW |
3386 | if (mask >> reg) |
3387 | as_tsktsk (_("register list not in ascending order")); | |
3388 | mask |= 1 << reg; | |
b99bd4ef | 3389 | |
c19d1205 ZW |
3390 | if (*input_line_pointer == '-') |
3391 | { | |
3392 | input_line_pointer++; | |
dcbf9037 | 3393 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3394 | if (hi_reg == FAIL) |
3395 | { | |
3396 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); | |
3397 | goto error; | |
3398 | } | |
3399 | else if (reg >= hi_reg) | |
3400 | { | |
3401 | as_bad (_("bad register range")); | |
3402 | goto error; | |
3403 | } | |
3404 | for (; reg < hi_reg; reg++) | |
3405 | mask |= 1 << reg; | |
3406 | } | |
3407 | } | |
3408 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3409 | |
c19d1205 ZW |
3410 | if (*input_line_pointer == '}') |
3411 | input_line_pointer++; | |
b99bd4ef | 3412 | |
c19d1205 | 3413 | demand_empty_rest_of_line (); |
b99bd4ef | 3414 | |
708587a4 | 3415 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3416 | the list. */ |
3417 | flush_pending_unwind (); | |
b99bd4ef | 3418 | |
c19d1205 | 3419 | for (i = 0; i < 16; i++) |
b99bd4ef | 3420 | { |
c19d1205 ZW |
3421 | if (mask & (1 << i)) |
3422 | unwind.frame_size += 8; | |
b99bd4ef NC |
3423 | } |
3424 | ||
c19d1205 ZW |
3425 | /* Attempt to combine with a previous opcode. We do this because gcc |
3426 | likes to output separate unwind directives for a single block of | |
3427 | registers. */ | |
3428 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3429 | { |
c19d1205 ZW |
3430 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3431 | if ((i & 0xf8) == 0xc0) | |
3432 | { | |
3433 | i &= 7; | |
3434 | /* Only merge if the blocks are contiguous. */ | |
3435 | if (i < 6) | |
3436 | { | |
3437 | if ((mask & 0xfe00) == (1 << 9)) | |
3438 | { | |
3439 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3440 | unwind.opcode_count--; | |
3441 | } | |
3442 | } | |
3443 | else if (i == 6 && unwind.opcode_count >= 2) | |
3444 | { | |
3445 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3446 | reg = i >> 4; | |
3447 | i &= 0xf; | |
b99bd4ef | 3448 | |
c19d1205 ZW |
3449 | op = 0xffff << (reg - 1); |
3450 | if (reg > 0 | |
3451 | || ((mask & op) == (1u << (reg - 1)))) | |
3452 | { | |
3453 | op = (1 << (reg + i + 1)) - 1; | |
3454 | op &= ~((1 << reg) - 1); | |
3455 | mask |= op; | |
3456 | unwind.opcode_count -= 2; | |
3457 | } | |
3458 | } | |
3459 | } | |
b99bd4ef NC |
3460 | } |
3461 | ||
c19d1205 ZW |
3462 | hi_reg = 15; |
3463 | /* We want to generate opcodes in the order the registers have been | |
3464 | saved, ie. descending order. */ | |
3465 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3466 | { |
c19d1205 ZW |
3467 | /* Save registers in blocks. */ |
3468 | if (reg < 0 | |
3469 | || !(mask & (1 << reg))) | |
3470 | { | |
3471 | /* We found an unsaved reg. Generate opcodes to save the | |
3472 | preceeding block. */ | |
3473 | if (reg != hi_reg) | |
3474 | { | |
3475 | if (reg == 9) | |
3476 | { | |
3477 | /* Short form. */ | |
3478 | op = 0xc0 | (hi_reg - 10); | |
3479 | add_unwind_opcode (op, 1); | |
3480 | } | |
3481 | else | |
3482 | { | |
3483 | /* Long form. */ | |
3484 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
3485 | add_unwind_opcode (op, 2); | |
3486 | } | |
3487 | } | |
3488 | hi_reg = reg - 1; | |
3489 | } | |
b99bd4ef NC |
3490 | } |
3491 | ||
c19d1205 ZW |
3492 | return; |
3493 | error: | |
3494 | ignore_rest_of_line (); | |
b99bd4ef NC |
3495 | } |
3496 | ||
3497 | static void | |
c19d1205 | 3498 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 3499 | { |
c19d1205 ZW |
3500 | int reg; |
3501 | int hi_reg; | |
3502 | unsigned mask = 0; | |
3503 | valueT op; | |
b99bd4ef | 3504 | |
c19d1205 ZW |
3505 | if (*input_line_pointer == '{') |
3506 | input_line_pointer++; | |
b99bd4ef | 3507 | |
c19d1205 | 3508 | do |
b99bd4ef | 3509 | { |
dcbf9037 | 3510 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 3511 | |
c19d1205 ZW |
3512 | if (reg == FAIL) |
3513 | { | |
3514 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
3515 | goto error; | |
3516 | } | |
b99bd4ef | 3517 | |
c19d1205 ZW |
3518 | reg -= 8; |
3519 | if (mask >> reg) | |
3520 | as_tsktsk (_("register list not in ascending order")); | |
3521 | mask |= 1 << reg; | |
b99bd4ef | 3522 | |
c19d1205 ZW |
3523 | if (*input_line_pointer == '-') |
3524 | { | |
3525 | input_line_pointer++; | |
dcbf9037 | 3526 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
3527 | if (hi_reg == FAIL) |
3528 | { | |
3529 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
3530 | goto error; | |
3531 | } | |
3532 | else if (reg >= hi_reg) | |
3533 | { | |
3534 | as_bad (_("bad register range")); | |
3535 | goto error; | |
3536 | } | |
3537 | for (; reg < hi_reg; reg++) | |
3538 | mask |= 1 << reg; | |
3539 | } | |
b99bd4ef | 3540 | } |
c19d1205 | 3541 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 3542 | |
c19d1205 ZW |
3543 | if (*input_line_pointer == '}') |
3544 | input_line_pointer++; | |
b99bd4ef | 3545 | |
c19d1205 ZW |
3546 | demand_empty_rest_of_line (); |
3547 | ||
708587a4 | 3548 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3549 | the list. */ |
3550 | flush_pending_unwind (); | |
b99bd4ef | 3551 | |
c19d1205 | 3552 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 3553 | { |
c19d1205 ZW |
3554 | if (mask & (1 << reg)) |
3555 | unwind.frame_size += 4; | |
b99bd4ef | 3556 | } |
c19d1205 ZW |
3557 | op = 0xc700 | mask; |
3558 | add_unwind_opcode (op, 2); | |
3559 | return; | |
3560 | error: | |
3561 | ignore_rest_of_line (); | |
b99bd4ef NC |
3562 | } |
3563 | ||
c19d1205 | 3564 | |
fa073d69 MS |
3565 | /* Parse an unwind_save directive. |
3566 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 3567 | |
b99bd4ef | 3568 | static void |
fa073d69 | 3569 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 3570 | { |
c19d1205 ZW |
3571 | char *peek; |
3572 | struct reg_entry *reg; | |
3573 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 3574 | |
c19d1205 ZW |
3575 | /* Figure out what sort of save we have. */ |
3576 | peek = input_line_pointer; | |
b99bd4ef | 3577 | |
c19d1205 | 3578 | if (*peek == '{') |
b99bd4ef | 3579 | { |
c19d1205 ZW |
3580 | had_brace = TRUE; |
3581 | peek++; | |
b99bd4ef NC |
3582 | } |
3583 | ||
c19d1205 | 3584 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 3585 | |
c19d1205 | 3586 | if (!reg) |
b99bd4ef | 3587 | { |
c19d1205 ZW |
3588 | as_bad (_("register expected")); |
3589 | ignore_rest_of_line (); | |
b99bd4ef NC |
3590 | return; |
3591 | } | |
3592 | ||
c19d1205 | 3593 | switch (reg->type) |
b99bd4ef | 3594 | { |
c19d1205 ZW |
3595 | case REG_TYPE_FN: |
3596 | if (had_brace) | |
3597 | { | |
3598 | as_bad (_("FPA .unwind_save does not take a register list")); | |
3599 | ignore_rest_of_line (); | |
3600 | return; | |
3601 | } | |
3602 | s_arm_unwind_save_fpa (reg->number); | |
b99bd4ef | 3603 | return; |
c19d1205 ZW |
3604 | |
3605 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
3606 | case REG_TYPE_VFD: |
3607 | if (arch_v6) | |
3608 | s_arm_unwind_save_vfp_armv6 (); | |
3609 | else | |
3610 | s_arm_unwind_save_vfp (); | |
3611 | return; | |
c19d1205 ZW |
3612 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
3613 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
3614 | ||
3615 | default: | |
3616 | as_bad (_(".unwind_save does not support this kind of register")); | |
3617 | ignore_rest_of_line (); | |
b99bd4ef | 3618 | } |
c19d1205 | 3619 | } |
b99bd4ef | 3620 | |
b99bd4ef | 3621 | |
c19d1205 ZW |
3622 | /* Parse an unwind_movsp directive. */ |
3623 | ||
3624 | static void | |
3625 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
3626 | { | |
3627 | int reg; | |
3628 | valueT op; | |
3629 | ||
dcbf9037 | 3630 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 3631 | if (reg == FAIL) |
b99bd4ef | 3632 | { |
c19d1205 ZW |
3633 | as_bad (_(reg_expected_msgs[REG_TYPE_RN])); |
3634 | ignore_rest_of_line (); | |
b99bd4ef NC |
3635 | return; |
3636 | } | |
c19d1205 | 3637 | demand_empty_rest_of_line (); |
b99bd4ef | 3638 | |
c19d1205 | 3639 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 3640 | { |
c19d1205 | 3641 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
3642 | return; |
3643 | } | |
3644 | ||
c19d1205 ZW |
3645 | if (unwind.fp_reg != REG_SP) |
3646 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 3647 | |
c19d1205 ZW |
3648 | /* Generate opcode to restore the value. */ |
3649 | op = 0x90 | reg; | |
3650 | add_unwind_opcode (op, 1); | |
3651 | ||
3652 | /* Record the information for later. */ | |
3653 | unwind.fp_reg = reg; | |
3654 | unwind.fp_offset = unwind.frame_size; | |
3655 | unwind.sp_restored = 1; | |
b05fe5cf ZW |
3656 | } |
3657 | ||
c19d1205 ZW |
3658 | /* Parse an unwind_pad directive. */ |
3659 | ||
b05fe5cf | 3660 | static void |
c19d1205 | 3661 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 3662 | { |
c19d1205 | 3663 | int offset; |
b05fe5cf | 3664 | |
c19d1205 ZW |
3665 | if (immediate_for_directive (&offset) == FAIL) |
3666 | return; | |
b99bd4ef | 3667 | |
c19d1205 ZW |
3668 | if (offset & 3) |
3669 | { | |
3670 | as_bad (_("stack increment must be multiple of 4")); | |
3671 | ignore_rest_of_line (); | |
3672 | return; | |
3673 | } | |
b99bd4ef | 3674 | |
c19d1205 ZW |
3675 | /* Don't generate any opcodes, just record the details for later. */ |
3676 | unwind.frame_size += offset; | |
3677 | unwind.pending_offset += offset; | |
3678 | ||
3679 | demand_empty_rest_of_line (); | |
3680 | } | |
3681 | ||
3682 | /* Parse an unwind_setfp directive. */ | |
3683 | ||
3684 | static void | |
3685 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3686 | { |
c19d1205 ZW |
3687 | int sp_reg; |
3688 | int fp_reg; | |
3689 | int offset; | |
3690 | ||
dcbf9037 | 3691 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
3692 | if (skip_past_comma (&input_line_pointer) == FAIL) |
3693 | sp_reg = FAIL; | |
3694 | else | |
dcbf9037 | 3695 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 3696 | |
c19d1205 ZW |
3697 | if (fp_reg == FAIL || sp_reg == FAIL) |
3698 | { | |
3699 | as_bad (_("expected <reg>, <reg>")); | |
3700 | ignore_rest_of_line (); | |
3701 | return; | |
3702 | } | |
b99bd4ef | 3703 | |
c19d1205 ZW |
3704 | /* Optional constant. */ |
3705 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3706 | { | |
3707 | if (immediate_for_directive (&offset) == FAIL) | |
3708 | return; | |
3709 | } | |
3710 | else | |
3711 | offset = 0; | |
a737bd4d | 3712 | |
c19d1205 | 3713 | demand_empty_rest_of_line (); |
a737bd4d | 3714 | |
c19d1205 | 3715 | if (sp_reg != 13 && sp_reg != unwind.fp_reg) |
a737bd4d | 3716 | { |
c19d1205 ZW |
3717 | as_bad (_("register must be either sp or set by a previous" |
3718 | "unwind_movsp directive")); | |
3719 | return; | |
a737bd4d NC |
3720 | } |
3721 | ||
c19d1205 ZW |
3722 | /* Don't generate any opcodes, just record the information for later. */ |
3723 | unwind.fp_reg = fp_reg; | |
3724 | unwind.fp_used = 1; | |
3725 | if (sp_reg == 13) | |
3726 | unwind.fp_offset = unwind.frame_size - offset; | |
3727 | else | |
3728 | unwind.fp_offset -= offset; | |
a737bd4d NC |
3729 | } |
3730 | ||
c19d1205 ZW |
3731 | /* Parse an unwind_raw directive. */ |
3732 | ||
3733 | static void | |
3734 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 3735 | { |
c19d1205 | 3736 | expressionS exp; |
708587a4 | 3737 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
3738 | unsigned char op[16]; |
3739 | int count; | |
a737bd4d | 3740 | |
c19d1205 ZW |
3741 | expression (&exp); |
3742 | if (exp.X_op == O_constant | |
3743 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 3744 | { |
c19d1205 ZW |
3745 | unwind.frame_size += exp.X_add_number; |
3746 | expression (&exp); | |
3747 | } | |
3748 | else | |
3749 | exp.X_op = O_illegal; | |
a737bd4d | 3750 | |
c19d1205 ZW |
3751 | if (exp.X_op != O_constant) |
3752 | { | |
3753 | as_bad (_("expected <offset>, <opcode>")); | |
3754 | ignore_rest_of_line (); | |
3755 | return; | |
3756 | } | |
a737bd4d | 3757 | |
c19d1205 | 3758 | count = 0; |
a737bd4d | 3759 | |
c19d1205 ZW |
3760 | /* Parse the opcode. */ |
3761 | for (;;) | |
3762 | { | |
3763 | if (count >= 16) | |
3764 | { | |
3765 | as_bad (_("unwind opcode too long")); | |
3766 | ignore_rest_of_line (); | |
a737bd4d | 3767 | } |
c19d1205 | 3768 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 3769 | { |
c19d1205 ZW |
3770 | as_bad (_("invalid unwind opcode")); |
3771 | ignore_rest_of_line (); | |
3772 | return; | |
a737bd4d | 3773 | } |
c19d1205 | 3774 | op[count++] = exp.X_add_number; |
a737bd4d | 3775 | |
c19d1205 ZW |
3776 | /* Parse the next byte. */ |
3777 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
3778 | break; | |
a737bd4d | 3779 | |
c19d1205 ZW |
3780 | expression (&exp); |
3781 | } | |
b99bd4ef | 3782 | |
c19d1205 ZW |
3783 | /* Add the opcode bytes in reverse order. */ |
3784 | while (count--) | |
3785 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 3786 | |
c19d1205 | 3787 | demand_empty_rest_of_line (); |
b99bd4ef | 3788 | } |
ee065d83 PB |
3789 | |
3790 | ||
3791 | /* Parse a .eabi_attribute directive. */ | |
3792 | ||
3793 | static void | |
3794 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
3795 | { | |
3796 | expressionS exp; | |
3797 | bfd_boolean is_string; | |
3798 | int tag; | |
3799 | unsigned int i = 0; | |
3800 | char *s = NULL; | |
3801 | char saved_char; | |
3802 | ||
3803 | expression (& exp); | |
3804 | if (exp.X_op != O_constant) | |
3805 | goto bad; | |
3806 | ||
3807 | tag = exp.X_add_number; | |
3808 | if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0)) | |
3809 | is_string = 1; | |
3810 | else | |
3811 | is_string = 0; | |
3812 | ||
3813 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
3814 | goto bad; | |
3815 | if (tag == 32 || !is_string) | |
3816 | { | |
3817 | expression (& exp); | |
3818 | if (exp.X_op != O_constant) | |
3819 | { | |
3820 | as_bad (_("expected numeric constant")); | |
3821 | ignore_rest_of_line (); | |
3822 | return; | |
3823 | } | |
3824 | i = exp.X_add_number; | |
3825 | } | |
3826 | if (tag == Tag_compatibility | |
3827 | && skip_past_comma (&input_line_pointer) == FAIL) | |
3828 | { | |
3829 | as_bad (_("expected comma")); | |
3830 | ignore_rest_of_line (); | |
3831 | return; | |
3832 | } | |
3833 | if (is_string) | |
3834 | { | |
3835 | skip_whitespace(input_line_pointer); | |
3836 | if (*input_line_pointer != '"') | |
3837 | goto bad_string; | |
3838 | input_line_pointer++; | |
3839 | s = input_line_pointer; | |
3840 | while (*input_line_pointer && *input_line_pointer != '"') | |
3841 | input_line_pointer++; | |
3842 | if (*input_line_pointer != '"') | |
3843 | goto bad_string; | |
3844 | saved_char = *input_line_pointer; | |
3845 | *input_line_pointer = 0; | |
3846 | } | |
3847 | else | |
3848 | { | |
3849 | s = NULL; | |
3850 | saved_char = 0; | |
3851 | } | |
3852 | ||
3853 | if (tag == Tag_compatibility) | |
3854 | elf32_arm_add_eabi_attr_compat (stdoutput, i, s); | |
3855 | else if (is_string) | |
3856 | elf32_arm_add_eabi_attr_string (stdoutput, tag, s); | |
3857 | else | |
3858 | elf32_arm_add_eabi_attr_int (stdoutput, tag, i); | |
3859 | ||
3860 | if (s) | |
3861 | { | |
3862 | *input_line_pointer = saved_char; | |
3863 | input_line_pointer++; | |
3864 | } | |
3865 | demand_empty_rest_of_line (); | |
3866 | return; | |
3867 | bad_string: | |
3868 | as_bad (_("bad string constant")); | |
3869 | ignore_rest_of_line (); | |
3870 | return; | |
3871 | bad: | |
3872 | as_bad (_("expected <tag> , <value>")); | |
3873 | ignore_rest_of_line (); | |
3874 | } | |
8463be01 | 3875 | #endif /* OBJ_ELF */ |
ee065d83 PB |
3876 | |
3877 | static void s_arm_arch (int); | |
3878 | static void s_arm_cpu (int); | |
3879 | static void s_arm_fpu (int); | |
b99bd4ef | 3880 | |
c19d1205 ZW |
3881 | /* This table describes all the machine specific pseudo-ops the assembler |
3882 | has to support. The fields are: | |
3883 | pseudo-op name without dot | |
3884 | function to call to execute this pseudo-op | |
3885 | Integer arg to pass to the function. */ | |
b99bd4ef | 3886 | |
c19d1205 | 3887 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 3888 | { |
c19d1205 ZW |
3889 | /* Never called because '.req' does not start a line. */ |
3890 | { "req", s_req, 0 }, | |
dcbf9037 JB |
3891 | /* Following two are likewise never called. */ |
3892 | { "dn", s_dn, 0 }, | |
3893 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
3894 | { "unreq", s_unreq, 0 }, |
3895 | { "bss", s_bss, 0 }, | |
3896 | { "align", s_align, 0 }, | |
3897 | { "arm", s_arm, 0 }, | |
3898 | { "thumb", s_thumb, 0 }, | |
3899 | { "code", s_code, 0 }, | |
3900 | { "force_thumb", s_force_thumb, 0 }, | |
3901 | { "thumb_func", s_thumb_func, 0 }, | |
3902 | { "thumb_set", s_thumb_set, 0 }, | |
3903 | { "even", s_even, 0 }, | |
3904 | { "ltorg", s_ltorg, 0 }, | |
3905 | { "pool", s_ltorg, 0 }, | |
3906 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
3907 | { "cpu", s_arm_cpu, 0 }, |
3908 | { "arch", s_arm_arch, 0 }, | |
3909 | { "fpu", s_arm_fpu, 0 }, | |
c19d1205 ZW |
3910 | #ifdef OBJ_ELF |
3911 | { "word", s_arm_elf_cons, 4 }, | |
3912 | { "long", s_arm_elf_cons, 4 }, | |
3913 | { "rel31", s_arm_rel31, 0 }, | |
3914 | { "fnstart", s_arm_unwind_fnstart, 0 }, | |
3915 | { "fnend", s_arm_unwind_fnend, 0 }, | |
3916 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
3917 | { "personality", s_arm_unwind_personality, 0 }, | |
3918 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
3919 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
3920 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 3921 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
3922 | { "movsp", s_arm_unwind_movsp, 0 }, |
3923 | { "pad", s_arm_unwind_pad, 0 }, | |
3924 | { "setfp", s_arm_unwind_setfp, 0 }, | |
3925 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 3926 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
3927 | #else |
3928 | { "word", cons, 4}, | |
3929 | #endif | |
3930 | { "extend", float_cons, 'x' }, | |
3931 | { "ldouble", float_cons, 'x' }, | |
3932 | { "packed", float_cons, 'p' }, | |
3933 | { 0, 0, 0 } | |
3934 | }; | |
3935 | \f | |
3936 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 3937 | |
c19d1205 ZW |
3938 | /* Generic immediate-value read function for use in insn parsing. |
3939 | STR points to the beginning of the immediate (the leading #); | |
3940 | VAL receives the value; if the value is outside [MIN, MAX] | |
3941 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
3942 | optional. */ | |
b99bd4ef | 3943 | |
c19d1205 ZW |
3944 | static int |
3945 | parse_immediate (char **str, int *val, int min, int max, | |
3946 | bfd_boolean prefix_opt) | |
3947 | { | |
3948 | expressionS exp; | |
3949 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
3950 | if (exp.X_op != O_constant) | |
b99bd4ef | 3951 | { |
c19d1205 ZW |
3952 | inst.error = _("constant expression required"); |
3953 | return FAIL; | |
3954 | } | |
b99bd4ef | 3955 | |
c19d1205 ZW |
3956 | if (exp.X_add_number < min || exp.X_add_number > max) |
3957 | { | |
3958 | inst.error = _("immediate value out of range"); | |
3959 | return FAIL; | |
3960 | } | |
b99bd4ef | 3961 | |
c19d1205 ZW |
3962 | *val = exp.X_add_number; |
3963 | return SUCCESS; | |
3964 | } | |
b99bd4ef | 3965 | |
5287ad62 JB |
3966 | /* Less-generic immediate-value read function with the possibility of loading a |
3967 | big (64-bit) immediate, as required by Neon VMOV and VMVN immediate | |
3968 | instructions. Puts the result directly in inst.operands[i]. */ | |
3969 | ||
3970 | static int | |
3971 | parse_big_immediate (char **str, int i) | |
3972 | { | |
3973 | expressionS exp; | |
3974 | char *ptr = *str; | |
3975 | ||
3976 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
3977 | ||
3978 | if (exp.X_op == O_constant) | |
3979 | inst.operands[i].imm = exp.X_add_number; | |
3980 | else if (exp.X_op == O_big | |
3981 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32 | |
3982 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64) | |
3983 | { | |
3984 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
3985 | /* Bignums have their least significant bits in | |
3986 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
3987 | 32 bits in reg, in a (hopefully) portable way. */ | |
3988 | assert (parts != 0); | |
3989 | inst.operands[i].imm = 0; | |
3990 | for (j = 0; j < parts; j++, idx++) | |
3991 | inst.operands[i].imm |= generic_bignum[idx] | |
3992 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
3993 | inst.operands[i].reg = 0; | |
3994 | for (j = 0; j < parts; j++, idx++) | |
3995 | inst.operands[i].reg |= generic_bignum[idx] | |
3996 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
3997 | inst.operands[i].regisimm = 1; | |
3998 | } | |
3999 | else | |
4000 | return FAIL; | |
4001 | ||
4002 | *str = ptr; | |
4003 | ||
4004 | return SUCCESS; | |
4005 | } | |
4006 | ||
c19d1205 ZW |
4007 | /* Returns the pseudo-register number of an FPA immediate constant, |
4008 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4009 | |
c19d1205 ZW |
4010 | static int |
4011 | parse_fpa_immediate (char ** str) | |
4012 | { | |
4013 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4014 | char * save_in; | |
4015 | expressionS exp; | |
4016 | int i; | |
4017 | int j; | |
b99bd4ef | 4018 | |
c19d1205 ZW |
4019 | /* First try and match exact strings, this is to guarantee |
4020 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4021 | |
c19d1205 ZW |
4022 | for (i = 0; fp_const[i]; i++) |
4023 | { | |
4024 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4025 | { |
c19d1205 | 4026 | char *start = *str; |
b99bd4ef | 4027 | |
c19d1205 ZW |
4028 | *str += strlen (fp_const[i]); |
4029 | if (is_end_of_line[(unsigned char) **str]) | |
4030 | return i + 8; | |
4031 | *str = start; | |
4032 | } | |
4033 | } | |
b99bd4ef | 4034 | |
c19d1205 ZW |
4035 | /* Just because we didn't get a match doesn't mean that the constant |
4036 | isn't valid, just that it is in a format that we don't | |
4037 | automatically recognize. Try parsing it with the standard | |
4038 | expression routines. */ | |
b99bd4ef | 4039 | |
c19d1205 | 4040 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4041 | |
c19d1205 ZW |
4042 | /* Look for a raw floating point number. */ |
4043 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4044 | && is_end_of_line[(unsigned char) *save_in]) | |
4045 | { | |
4046 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4047 | { | |
4048 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4049 | { |
c19d1205 ZW |
4050 | if (words[j] != fp_values[i][j]) |
4051 | break; | |
b99bd4ef NC |
4052 | } |
4053 | ||
c19d1205 | 4054 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4055 | { |
c19d1205 ZW |
4056 | *str = save_in; |
4057 | return i + 8; | |
b99bd4ef NC |
4058 | } |
4059 | } | |
4060 | } | |
b99bd4ef | 4061 | |
c19d1205 ZW |
4062 | /* Try and parse a more complex expression, this will probably fail |
4063 | unless the code uses a floating point prefix (eg "0f"). */ | |
4064 | save_in = input_line_pointer; | |
4065 | input_line_pointer = *str; | |
4066 | if (expression (&exp) == absolute_section | |
4067 | && exp.X_op == O_big | |
4068 | && exp.X_add_number < 0) | |
4069 | { | |
4070 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4071 | Ditto for 15. */ | |
4072 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4073 | { | |
4074 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4075 | { | |
4076 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4077 | { | |
4078 | if (words[j] != fp_values[i][j]) | |
4079 | break; | |
4080 | } | |
b99bd4ef | 4081 | |
c19d1205 ZW |
4082 | if (j == MAX_LITTLENUMS) |
4083 | { | |
4084 | *str = input_line_pointer; | |
4085 | input_line_pointer = save_in; | |
4086 | return i + 8; | |
4087 | } | |
4088 | } | |
4089 | } | |
b99bd4ef NC |
4090 | } |
4091 | ||
c19d1205 ZW |
4092 | *str = input_line_pointer; |
4093 | input_line_pointer = save_in; | |
4094 | inst.error = _("invalid FPA immediate expression"); | |
4095 | return FAIL; | |
b99bd4ef NC |
4096 | } |
4097 | ||
136da414 JB |
4098 | /* Returns 1 if a number has "quarter-precision" float format |
4099 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4100 | ||
4101 | static int | |
4102 | is_quarter_float (unsigned imm) | |
4103 | { | |
4104 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4105 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4106 | } | |
4107 | ||
4108 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4109 | 0baBbbbbbc defgh000 00000000 00000000. | |
4110 | The minus-zero case needs special handling, since it can't be encoded in the | |
4111 | "quarter-precision" float format, but can nonetheless be loaded as an integer | |
4112 | constant. */ | |
4113 | ||
4114 | static unsigned | |
4115 | parse_qfloat_immediate (char **ccp, int *immed) | |
4116 | { | |
4117 | char *str = *ccp; | |
4118 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4119 | ||
4120 | skip_past_char (&str, '#'); | |
4121 | ||
4122 | if ((str = atof_ieee (str, 's', words)) != NULL) | |
4123 | { | |
4124 | unsigned fpword = 0; | |
4125 | int i; | |
4126 | ||
4127 | /* Our FP word must be 32 bits (single-precision FP). */ | |
4128 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4129 | { | |
4130 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4131 | fpword |= words[i]; | |
4132 | } | |
4133 | ||
4134 | if (is_quarter_float (fpword) || fpword == 0x80000000) | |
4135 | *immed = fpword; | |
4136 | else | |
4137 | return FAIL; | |
4138 | ||
4139 | *ccp = str; | |
4140 | ||
4141 | return SUCCESS; | |
4142 | } | |
4143 | ||
4144 | return FAIL; | |
4145 | } | |
4146 | ||
c19d1205 ZW |
4147 | /* Shift operands. */ |
4148 | enum shift_kind | |
b99bd4ef | 4149 | { |
c19d1205 ZW |
4150 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4151 | }; | |
b99bd4ef | 4152 | |
c19d1205 ZW |
4153 | struct asm_shift_name |
4154 | { | |
4155 | const char *name; | |
4156 | enum shift_kind kind; | |
4157 | }; | |
b99bd4ef | 4158 | |
c19d1205 ZW |
4159 | /* Third argument to parse_shift. */ |
4160 | enum parse_shift_mode | |
4161 | { | |
4162 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4163 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4164 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4165 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4166 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4167 | }; | |
b99bd4ef | 4168 | |
c19d1205 ZW |
4169 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4170 | This has three forms: | |
b99bd4ef | 4171 | |
c19d1205 ZW |
4172 | (LSL|LSR|ASL|ASR|ROR) Rs |
4173 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4174 | RRX | |
b99bd4ef | 4175 | |
c19d1205 ZW |
4176 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4177 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4178 | |
c19d1205 ZW |
4179 | static int |
4180 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4181 | { |
c19d1205 ZW |
4182 | const struct asm_shift_name *shift_name; |
4183 | enum shift_kind shift; | |
4184 | char *s = *str; | |
4185 | char *p = s; | |
4186 | int reg; | |
b99bd4ef | 4187 | |
c19d1205 ZW |
4188 | for (p = *str; ISALPHA (*p); p++) |
4189 | ; | |
b99bd4ef | 4190 | |
c19d1205 | 4191 | if (p == *str) |
b99bd4ef | 4192 | { |
c19d1205 ZW |
4193 | inst.error = _("shift expression expected"); |
4194 | return FAIL; | |
b99bd4ef NC |
4195 | } |
4196 | ||
c19d1205 ZW |
4197 | shift_name = hash_find_n (arm_shift_hsh, *str, p - *str); |
4198 | ||
4199 | if (shift_name == NULL) | |
b99bd4ef | 4200 | { |
c19d1205 ZW |
4201 | inst.error = _("shift expression expected"); |
4202 | return FAIL; | |
b99bd4ef NC |
4203 | } |
4204 | ||
c19d1205 | 4205 | shift = shift_name->kind; |
b99bd4ef | 4206 | |
c19d1205 ZW |
4207 | switch (mode) |
4208 | { | |
4209 | case NO_SHIFT_RESTRICT: | |
4210 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4211 | |
c19d1205 ZW |
4212 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4213 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4214 | { | |
4215 | inst.error = _("'LSL' or 'ASR' required"); | |
4216 | return FAIL; | |
4217 | } | |
4218 | break; | |
b99bd4ef | 4219 | |
c19d1205 ZW |
4220 | case SHIFT_LSL_IMMEDIATE: |
4221 | if (shift != SHIFT_LSL) | |
4222 | { | |
4223 | inst.error = _("'LSL' required"); | |
4224 | return FAIL; | |
4225 | } | |
4226 | break; | |
b99bd4ef | 4227 | |
c19d1205 ZW |
4228 | case SHIFT_ASR_IMMEDIATE: |
4229 | if (shift != SHIFT_ASR) | |
4230 | { | |
4231 | inst.error = _("'ASR' required"); | |
4232 | return FAIL; | |
4233 | } | |
4234 | break; | |
b99bd4ef | 4235 | |
c19d1205 ZW |
4236 | default: abort (); |
4237 | } | |
b99bd4ef | 4238 | |
c19d1205 ZW |
4239 | if (shift != SHIFT_RRX) |
4240 | { | |
4241 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4242 | skip_whitespace (p); | |
b99bd4ef | 4243 | |
c19d1205 | 4244 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4245 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4246 | { |
4247 | inst.operands[i].imm = reg; | |
4248 | inst.operands[i].immisreg = 1; | |
4249 | } | |
4250 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4251 | return FAIL; | |
4252 | } | |
4253 | inst.operands[i].shift_kind = shift; | |
4254 | inst.operands[i].shifted = 1; | |
4255 | *str = p; | |
4256 | return SUCCESS; | |
b99bd4ef NC |
4257 | } |
4258 | ||
c19d1205 | 4259 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4260 | |
c19d1205 ZW |
4261 | #<immediate> |
4262 | #<immediate>, <rotate> | |
4263 | <Rm> | |
4264 | <Rm>, <shift> | |
b99bd4ef | 4265 | |
c19d1205 ZW |
4266 | where <shift> is defined by parse_shift above, and <rotate> is a |
4267 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4268 | is deferred to md_apply_fix. */ |
b99bd4ef | 4269 | |
c19d1205 ZW |
4270 | static int |
4271 | parse_shifter_operand (char **str, int i) | |
4272 | { | |
4273 | int value; | |
4274 | expressionS expr; | |
b99bd4ef | 4275 | |
dcbf9037 | 4276 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4277 | { |
4278 | inst.operands[i].reg = value; | |
4279 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4280 | |
c19d1205 ZW |
4281 | /* parse_shift will override this if appropriate */ |
4282 | inst.reloc.exp.X_op = O_constant; | |
4283 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4284 | |
c19d1205 ZW |
4285 | if (skip_past_comma (str) == FAIL) |
4286 | return SUCCESS; | |
b99bd4ef | 4287 | |
c19d1205 ZW |
4288 | /* Shift operation on register. */ |
4289 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4290 | } |
4291 | ||
c19d1205 ZW |
4292 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4293 | return FAIL; | |
b99bd4ef | 4294 | |
c19d1205 | 4295 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4296 | { |
c19d1205 ZW |
4297 | /* #x, y -- ie explicit rotation by Y. */ |
4298 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
4299 | return FAIL; | |
b99bd4ef | 4300 | |
c19d1205 ZW |
4301 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
4302 | { | |
4303 | inst.error = _("constant expression expected"); | |
4304 | return FAIL; | |
4305 | } | |
b99bd4ef | 4306 | |
c19d1205 ZW |
4307 | value = expr.X_add_number; |
4308 | if (value < 0 || value > 30 || value % 2 != 0) | |
4309 | { | |
4310 | inst.error = _("invalid rotation"); | |
4311 | return FAIL; | |
4312 | } | |
4313 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4314 | { | |
4315 | inst.error = _("invalid constant"); | |
4316 | return FAIL; | |
4317 | } | |
09d92015 | 4318 | |
55cf6793 | 4319 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
4320 | inst.reloc.exp.X_add_number |
4321 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
4322 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
4323 | } |
4324 | ||
c19d1205 ZW |
4325 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4326 | inst.reloc.pc_rel = 0; | |
4327 | return SUCCESS; | |
09d92015 MM |
4328 | } |
4329 | ||
4962c51a MS |
4330 | /* Group relocation information. Each entry in the table contains the |
4331 | textual name of the relocation as may appear in assembler source | |
4332 | and must end with a colon. | |
4333 | Along with this textual name are the relocation codes to be used if | |
4334 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4335 | an LDR, an LDRS, or an LDC. */ | |
4336 | ||
4337 | struct group_reloc_table_entry | |
4338 | { | |
4339 | const char *name; | |
4340 | int alu_code; | |
4341 | int ldr_code; | |
4342 | int ldrs_code; | |
4343 | int ldc_code; | |
4344 | }; | |
4345 | ||
4346 | typedef enum | |
4347 | { | |
4348 | /* Varieties of non-ALU group relocation. */ | |
4349 | ||
4350 | GROUP_LDR, | |
4351 | GROUP_LDRS, | |
4352 | GROUP_LDC | |
4353 | } group_reloc_type; | |
4354 | ||
4355 | static struct group_reloc_table_entry group_reloc_table[] = | |
4356 | { /* Program counter relative: */ | |
4357 | { "pc_g0_nc", | |
4358 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4359 | 0, /* LDR */ | |
4360 | 0, /* LDRS */ | |
4361 | 0 }, /* LDC */ | |
4362 | { "pc_g0", | |
4363 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4364 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4365 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4366 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4367 | { "pc_g1_nc", | |
4368 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4369 | 0, /* LDR */ | |
4370 | 0, /* LDRS */ | |
4371 | 0 }, /* LDC */ | |
4372 | { "pc_g1", | |
4373 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4374 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4375 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4376 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4377 | { "pc_g2", | |
4378 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4379 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4380 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4381 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4382 | /* Section base relative */ | |
4383 | { "sb_g0_nc", | |
4384 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4385 | 0, /* LDR */ | |
4386 | 0, /* LDRS */ | |
4387 | 0 }, /* LDC */ | |
4388 | { "sb_g0", | |
4389 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4390 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4391 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4392 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4393 | { "sb_g1_nc", | |
4394 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4395 | 0, /* LDR */ | |
4396 | 0, /* LDRS */ | |
4397 | 0 }, /* LDC */ | |
4398 | { "sb_g1", | |
4399 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4400 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4401 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4402 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4403 | { "sb_g2", | |
4404 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
4405 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
4406 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
4407 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
4408 | ||
4409 | /* Given the address of a pointer pointing to the textual name of a group | |
4410 | relocation as may appear in assembler source, attempt to find its details | |
4411 | in group_reloc_table. The pointer will be updated to the character after | |
4412 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
4413 | otherwise. On success, *entry will be updated to point at the relevant | |
4414 | group_reloc_table entry. */ | |
4415 | ||
4416 | static int | |
4417 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
4418 | { | |
4419 | unsigned int i; | |
4420 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
4421 | { | |
4422 | int length = strlen (group_reloc_table[i].name); | |
4423 | ||
4424 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 && | |
4425 | (*str)[length] == ':') | |
4426 | { | |
4427 | *out = &group_reloc_table[i]; | |
4428 | *str += (length + 1); | |
4429 | return SUCCESS; | |
4430 | } | |
4431 | } | |
4432 | ||
4433 | return FAIL; | |
4434 | } | |
4435 | ||
4436 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
4437 | (as for parse_shifter_operand) where group relocations are allowed: | |
4438 | ||
4439 | #<immediate> | |
4440 | #<immediate>, <rotate> | |
4441 | #:<group_reloc>:<expression> | |
4442 | <Rm> | |
4443 | <Rm>, <shift> | |
4444 | ||
4445 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
4446 | The hashes are optional. | |
4447 | ||
4448 | Everything else is as for parse_shifter_operand. */ | |
4449 | ||
4450 | static parse_operand_result | |
4451 | parse_shifter_operand_group_reloc (char **str, int i) | |
4452 | { | |
4453 | /* Determine if we have the sequence of characters #: or just : | |
4454 | coming next. If we do, then we check for a group relocation. | |
4455 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
4456 | ||
4457 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
4458 | || (*str)[0] == ':') | |
4459 | { | |
4460 | struct group_reloc_table_entry *entry; | |
4461 | ||
4462 | if ((*str)[0] == '#') | |
4463 | (*str) += 2; | |
4464 | else | |
4465 | (*str)++; | |
4466 | ||
4467 | /* Try to parse a group relocation. Anything else is an error. */ | |
4468 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
4469 | { | |
4470 | inst.error = _("unknown group relocation"); | |
4471 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4472 | } | |
4473 | ||
4474 | /* We now have the group relocation table entry corresponding to | |
4475 | the name in the assembler source. Next, we parse the expression. */ | |
4476 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
4477 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4478 | ||
4479 | /* Record the relocation type (always the ALU variant here). */ | |
4480 | inst.reloc.type = entry->alu_code; | |
4481 | assert (inst.reloc.type != 0); | |
4482 | ||
4483 | return PARSE_OPERAND_SUCCESS; | |
4484 | } | |
4485 | else | |
4486 | return parse_shifter_operand (str, i) == SUCCESS | |
4487 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
4488 | ||
4489 | /* Never reached. */ | |
4490 | } | |
4491 | ||
c19d1205 ZW |
4492 | /* Parse all forms of an ARM address expression. Information is written |
4493 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 4494 | |
c19d1205 | 4495 | Preindexed addressing (.preind=1): |
09d92015 | 4496 | |
c19d1205 ZW |
4497 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
4498 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4499 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4500 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4501 | |
c19d1205 | 4502 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 4503 | |
c19d1205 | 4504 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 4505 | |
c19d1205 ZW |
4506 | [Rn], #offset .reg=Rn .reloc.exp=offset |
4507 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4508 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4509 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4510 | |
c19d1205 | 4511 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 4512 | |
c19d1205 | 4513 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 4514 | |
c19d1205 | 4515 | Other: |
09d92015 | 4516 | |
c19d1205 ZW |
4517 | [Rn]{!} shorthand for [Rn,#0]{!} |
4518 | =immediate .isreg=0 .reloc.exp=immediate | |
4519 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 4520 | |
c19d1205 ZW |
4521 | It is the caller's responsibility to check for addressing modes not |
4522 | supported by the instruction, and to set inst.reloc.type. */ | |
4523 | ||
4962c51a MS |
4524 | static parse_operand_result |
4525 | parse_address_main (char **str, int i, int group_relocations, | |
4526 | group_reloc_type group_type) | |
09d92015 | 4527 | { |
c19d1205 ZW |
4528 | char *p = *str; |
4529 | int reg; | |
09d92015 | 4530 | |
c19d1205 | 4531 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 4532 | { |
c19d1205 ZW |
4533 | if (skip_past_char (&p, '=') == FAIL) |
4534 | { | |
4535 | /* bare address - translate to PC-relative offset */ | |
4536 | inst.reloc.pc_rel = 1; | |
4537 | inst.operands[i].reg = REG_PC; | |
4538 | inst.operands[i].isreg = 1; | |
4539 | inst.operands[i].preind = 1; | |
4540 | } | |
4541 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 4542 | |
c19d1205 | 4543 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 4544 | return PARSE_OPERAND_FAIL; |
09d92015 | 4545 | |
c19d1205 | 4546 | *str = p; |
4962c51a | 4547 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
4548 | } |
4549 | ||
dcbf9037 | 4550 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 4551 | { |
c19d1205 | 4552 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 4553 | return PARSE_OPERAND_FAIL; |
09d92015 | 4554 | } |
c19d1205 ZW |
4555 | inst.operands[i].reg = reg; |
4556 | inst.operands[i].isreg = 1; | |
09d92015 | 4557 | |
c19d1205 | 4558 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4559 | { |
c19d1205 | 4560 | inst.operands[i].preind = 1; |
09d92015 | 4561 | |
c19d1205 ZW |
4562 | if (*p == '+') p++; |
4563 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
4564 | ||
dcbf9037 | 4565 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 4566 | { |
c19d1205 ZW |
4567 | inst.operands[i].imm = reg; |
4568 | inst.operands[i].immisreg = 1; | |
4569 | ||
4570 | if (skip_past_comma (&p) == SUCCESS) | |
4571 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 4572 | return PARSE_OPERAND_FAIL; |
c19d1205 | 4573 | } |
5287ad62 JB |
4574 | else if (skip_past_char (&p, ':') == SUCCESS) |
4575 | { | |
4576 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
4577 | code before we get to see it here. This may be subject to | |
4578 | change. */ | |
4579 | expressionS exp; | |
4580 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
4581 | if (exp.X_op != O_constant) | |
4582 | { | |
4583 | inst.error = _("alignment must be constant"); | |
4962c51a | 4584 | return PARSE_OPERAND_FAIL; |
5287ad62 JB |
4585 | } |
4586 | inst.operands[i].imm = exp.X_add_number << 8; | |
4587 | inst.operands[i].immisalign = 1; | |
4588 | /* Alignments are not pre-indexes. */ | |
4589 | inst.operands[i].preind = 0; | |
4590 | } | |
c19d1205 ZW |
4591 | else |
4592 | { | |
4593 | if (inst.operands[i].negative) | |
4594 | { | |
4595 | inst.operands[i].negative = 0; | |
4596 | p--; | |
4597 | } | |
4962c51a MS |
4598 | |
4599 | if (group_relocations && | |
4600 | ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4601 | ||
4602 | { | |
4603 | struct group_reloc_table_entry *entry; | |
4604 | ||
4605 | /* Skip over the #: or : sequence. */ | |
4606 | if (*p == '#') | |
4607 | p += 2; | |
4608 | else | |
4609 | p++; | |
4610 | ||
4611 | /* Try to parse a group relocation. Anything else is an | |
4612 | error. */ | |
4613 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
4614 | { | |
4615 | inst.error = _("unknown group relocation"); | |
4616 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4617 | } | |
4618 | ||
4619 | /* We now have the group relocation table entry corresponding to | |
4620 | the name in the assembler source. Next, we parse the | |
4621 | expression. */ | |
4622 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
4623 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4624 | ||
4625 | /* Record the relocation type. */ | |
4626 | switch (group_type) | |
4627 | { | |
4628 | case GROUP_LDR: | |
4629 | inst.reloc.type = entry->ldr_code; | |
4630 | break; | |
4631 | ||
4632 | case GROUP_LDRS: | |
4633 | inst.reloc.type = entry->ldrs_code; | |
4634 | break; | |
4635 | ||
4636 | case GROUP_LDC: | |
4637 | inst.reloc.type = entry->ldc_code; | |
4638 | break; | |
4639 | ||
4640 | default: | |
4641 | assert (0); | |
4642 | } | |
4643 | ||
4644 | if (inst.reloc.type == 0) | |
4645 | { | |
4646 | inst.error = _("this group relocation is not allowed on this instruction"); | |
4647 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4648 | } | |
4649 | } | |
4650 | else | |
4651 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4652 | return PARSE_OPERAND_FAIL; | |
09d92015 MM |
4653 | } |
4654 | } | |
4655 | ||
c19d1205 | 4656 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 4657 | { |
c19d1205 | 4658 | inst.error = _("']' expected"); |
4962c51a | 4659 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
4660 | } |
4661 | ||
c19d1205 ZW |
4662 | if (skip_past_char (&p, '!') == SUCCESS) |
4663 | inst.operands[i].writeback = 1; | |
09d92015 | 4664 | |
c19d1205 | 4665 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4666 | { |
c19d1205 ZW |
4667 | if (skip_past_char (&p, '{') == SUCCESS) |
4668 | { | |
4669 | /* [Rn], {expr} - unindexed, with option */ | |
4670 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 4671 | 0, 255, TRUE) == FAIL) |
4962c51a | 4672 | return PARSE_OPERAND_FAIL; |
09d92015 | 4673 | |
c19d1205 ZW |
4674 | if (skip_past_char (&p, '}') == FAIL) |
4675 | { | |
4676 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 4677 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4678 | } |
4679 | if (inst.operands[i].preind) | |
4680 | { | |
4681 | inst.error = _("cannot combine index with option"); | |
4962c51a | 4682 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4683 | } |
4684 | *str = p; | |
4962c51a | 4685 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 4686 | } |
c19d1205 ZW |
4687 | else |
4688 | { | |
4689 | inst.operands[i].postind = 1; | |
4690 | inst.operands[i].writeback = 1; | |
09d92015 | 4691 | |
c19d1205 ZW |
4692 | if (inst.operands[i].preind) |
4693 | { | |
4694 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 4695 | return PARSE_OPERAND_FAIL; |
c19d1205 | 4696 | } |
09d92015 | 4697 | |
c19d1205 ZW |
4698 | if (*p == '+') p++; |
4699 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 4700 | |
dcbf9037 | 4701 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 4702 | { |
5287ad62 JB |
4703 | /* We might be using the immediate for alignment already. If we |
4704 | are, OR the register number into the low-order bits. */ | |
4705 | if (inst.operands[i].immisalign) | |
4706 | inst.operands[i].imm |= reg; | |
4707 | else | |
4708 | inst.operands[i].imm = reg; | |
c19d1205 | 4709 | inst.operands[i].immisreg = 1; |
a737bd4d | 4710 | |
c19d1205 ZW |
4711 | if (skip_past_comma (&p) == SUCCESS) |
4712 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 4713 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4714 | } |
4715 | else | |
4716 | { | |
4717 | if (inst.operands[i].negative) | |
4718 | { | |
4719 | inst.operands[i].negative = 0; | |
4720 | p--; | |
4721 | } | |
4722 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 4723 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4724 | } |
4725 | } | |
a737bd4d NC |
4726 | } |
4727 | ||
c19d1205 ZW |
4728 | /* If at this point neither .preind nor .postind is set, we have a |
4729 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
4730 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
4731 | { | |
4732 | inst.operands[i].preind = 1; | |
4733 | inst.reloc.exp.X_op = O_constant; | |
4734 | inst.reloc.exp.X_add_number = 0; | |
4735 | } | |
4736 | *str = p; | |
4962c51a MS |
4737 | return PARSE_OPERAND_SUCCESS; |
4738 | } | |
4739 | ||
4740 | static int | |
4741 | parse_address (char **str, int i) | |
4742 | { | |
4743 | return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS | |
4744 | ? SUCCESS : FAIL; | |
4745 | } | |
4746 | ||
4747 | static parse_operand_result | |
4748 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
4749 | { | |
4750 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
4751 | } |
4752 | ||
b6895b4f PB |
4753 | /* Parse an operand for a MOVW or MOVT instruction. */ |
4754 | static int | |
4755 | parse_half (char **str) | |
4756 | { | |
4757 | char * p; | |
4758 | ||
4759 | p = *str; | |
4760 | skip_past_char (&p, '#'); | |
4761 | if (strncasecmp (p, ":lower16:", 9) == 0) | |
4762 | inst.reloc.type = BFD_RELOC_ARM_MOVW; | |
4763 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
4764 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
4765 | ||
4766 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
4767 | { | |
4768 | p += 9; | |
4769 | skip_whitespace(p); | |
4770 | } | |
4771 | ||
4772 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
4773 | return FAIL; | |
4774 | ||
4775 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
4776 | { | |
4777 | if (inst.reloc.exp.X_op != O_constant) | |
4778 | { | |
4779 | inst.error = _("constant expression expected"); | |
4780 | return FAIL; | |
4781 | } | |
4782 | if (inst.reloc.exp.X_add_number < 0 | |
4783 | || inst.reloc.exp.X_add_number > 0xffff) | |
4784 | { | |
4785 | inst.error = _("immediate value out of range"); | |
4786 | return FAIL; | |
4787 | } | |
4788 | } | |
4789 | *str = p; | |
4790 | return SUCCESS; | |
4791 | } | |
4792 | ||
c19d1205 | 4793 | /* Miscellaneous. */ |
a737bd4d | 4794 | |
c19d1205 ZW |
4795 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
4796 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
4797 | static int | |
4798 | parse_psr (char **str) | |
09d92015 | 4799 | { |
c19d1205 ZW |
4800 | char *p; |
4801 | unsigned long psr_field; | |
62b3e311 PB |
4802 | const struct asm_psr *psr; |
4803 | char *start; | |
09d92015 | 4804 | |
c19d1205 ZW |
4805 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
4806 | feature for ease of use and backwards compatibility. */ | |
4807 | p = *str; | |
62b3e311 | 4808 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 4809 | psr_field = SPSR_BIT; |
62b3e311 | 4810 | else if (strncasecmp (p, "CPSR", 4) == 0) |
c19d1205 ZW |
4811 | psr_field = 0; |
4812 | else | |
62b3e311 PB |
4813 | { |
4814 | start = p; | |
4815 | do | |
4816 | p++; | |
4817 | while (ISALNUM (*p) || *p == '_'); | |
4818 | ||
4819 | psr = hash_find_n (arm_v7m_psr_hsh, start, p - start); | |
4820 | if (!psr) | |
4821 | return FAIL; | |
09d92015 | 4822 | |
62b3e311 PB |
4823 | *str = p; |
4824 | return psr->field; | |
4825 | } | |
09d92015 | 4826 | |
62b3e311 | 4827 | p += 4; |
c19d1205 ZW |
4828 | if (*p == '_') |
4829 | { | |
4830 | /* A suffix follows. */ | |
c19d1205 ZW |
4831 | p++; |
4832 | start = p; | |
a737bd4d | 4833 | |
c19d1205 ZW |
4834 | do |
4835 | p++; | |
4836 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 4837 | |
c19d1205 ZW |
4838 | psr = hash_find_n (arm_psr_hsh, start, p - start); |
4839 | if (!psr) | |
4840 | goto error; | |
a737bd4d | 4841 | |
c19d1205 | 4842 | psr_field |= psr->field; |
a737bd4d | 4843 | } |
c19d1205 | 4844 | else |
a737bd4d | 4845 | { |
c19d1205 ZW |
4846 | if (ISALNUM (*p)) |
4847 | goto error; /* Garbage after "[CS]PSR". */ | |
4848 | ||
4849 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 4850 | } |
c19d1205 ZW |
4851 | *str = p; |
4852 | return psr_field; | |
a737bd4d | 4853 | |
c19d1205 ZW |
4854 | error: |
4855 | inst.error = _("flag for {c}psr instruction expected"); | |
4856 | return FAIL; | |
a737bd4d NC |
4857 | } |
4858 | ||
c19d1205 ZW |
4859 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
4860 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 4861 | |
c19d1205 ZW |
4862 | static int |
4863 | parse_cps_flags (char **str) | |
a737bd4d | 4864 | { |
c19d1205 ZW |
4865 | int val = 0; |
4866 | int saw_a_flag = 0; | |
4867 | char *s = *str; | |
a737bd4d | 4868 | |
c19d1205 ZW |
4869 | for (;;) |
4870 | switch (*s++) | |
4871 | { | |
4872 | case '\0': case ',': | |
4873 | goto done; | |
a737bd4d | 4874 | |
c19d1205 ZW |
4875 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
4876 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
4877 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 4878 | |
c19d1205 ZW |
4879 | default: |
4880 | inst.error = _("unrecognized CPS flag"); | |
4881 | return FAIL; | |
4882 | } | |
a737bd4d | 4883 | |
c19d1205 ZW |
4884 | done: |
4885 | if (saw_a_flag == 0) | |
a737bd4d | 4886 | { |
c19d1205 ZW |
4887 | inst.error = _("missing CPS flags"); |
4888 | return FAIL; | |
a737bd4d | 4889 | } |
a737bd4d | 4890 | |
c19d1205 ZW |
4891 | *str = s - 1; |
4892 | return val; | |
a737bd4d NC |
4893 | } |
4894 | ||
c19d1205 ZW |
4895 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
4896 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
4897 | |
4898 | static int | |
c19d1205 | 4899 | parse_endian_specifier (char **str) |
a737bd4d | 4900 | { |
c19d1205 ZW |
4901 | int little_endian; |
4902 | char *s = *str; | |
a737bd4d | 4903 | |
c19d1205 ZW |
4904 | if (strncasecmp (s, "BE", 2)) |
4905 | little_endian = 0; | |
4906 | else if (strncasecmp (s, "LE", 2)) | |
4907 | little_endian = 1; | |
4908 | else | |
a737bd4d | 4909 | { |
c19d1205 | 4910 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
4911 | return FAIL; |
4912 | } | |
4913 | ||
c19d1205 | 4914 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 4915 | { |
c19d1205 | 4916 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
4917 | return FAIL; |
4918 | } | |
4919 | ||
c19d1205 ZW |
4920 | *str = s + 2; |
4921 | return little_endian; | |
4922 | } | |
a737bd4d | 4923 | |
c19d1205 ZW |
4924 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
4925 | value suitable for poking into the rotate field of an sxt or sxta | |
4926 | instruction, or FAIL on error. */ | |
4927 | ||
4928 | static int | |
4929 | parse_ror (char **str) | |
4930 | { | |
4931 | int rot; | |
4932 | char *s = *str; | |
4933 | ||
4934 | if (strncasecmp (s, "ROR", 3) == 0) | |
4935 | s += 3; | |
4936 | else | |
a737bd4d | 4937 | { |
c19d1205 | 4938 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
4939 | return FAIL; |
4940 | } | |
c19d1205 ZW |
4941 | |
4942 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
4943 | return FAIL; | |
4944 | ||
4945 | switch (rot) | |
a737bd4d | 4946 | { |
c19d1205 ZW |
4947 | case 0: *str = s; return 0x0; |
4948 | case 8: *str = s; return 0x1; | |
4949 | case 16: *str = s; return 0x2; | |
4950 | case 24: *str = s; return 0x3; | |
4951 | ||
4952 | default: | |
4953 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
4954 | return FAIL; |
4955 | } | |
c19d1205 | 4956 | } |
a737bd4d | 4957 | |
c19d1205 ZW |
4958 | /* Parse a conditional code (from conds[] below). The value returned is in the |
4959 | range 0 .. 14, or FAIL. */ | |
4960 | static int | |
4961 | parse_cond (char **str) | |
4962 | { | |
4963 | char *p, *q; | |
4964 | const struct asm_cond *c; | |
a737bd4d | 4965 | |
c19d1205 ZW |
4966 | p = q = *str; |
4967 | while (ISALPHA (*q)) | |
4968 | q++; | |
a737bd4d | 4969 | |
c19d1205 ZW |
4970 | c = hash_find_n (arm_cond_hsh, p, q - p); |
4971 | if (!c) | |
a737bd4d | 4972 | { |
c19d1205 | 4973 | inst.error = _("condition required"); |
a737bd4d NC |
4974 | return FAIL; |
4975 | } | |
4976 | ||
c19d1205 ZW |
4977 | *str = q; |
4978 | return c->value; | |
4979 | } | |
4980 | ||
62b3e311 PB |
4981 | /* Parse an option for a barrier instruction. Returns the encoding for the |
4982 | option, or FAIL. */ | |
4983 | static int | |
4984 | parse_barrier (char **str) | |
4985 | { | |
4986 | char *p, *q; | |
4987 | const struct asm_barrier_opt *o; | |
4988 | ||
4989 | p = q = *str; | |
4990 | while (ISALPHA (*q)) | |
4991 | q++; | |
4992 | ||
4993 | o = hash_find_n (arm_barrier_opt_hsh, p, q - p); | |
4994 | if (!o) | |
4995 | return FAIL; | |
4996 | ||
4997 | *str = q; | |
4998 | return o->value; | |
4999 | } | |
5000 | ||
92e90b6e PB |
5001 | /* Parse the operands of a table branch instruction. Similar to a memory |
5002 | operand. */ | |
5003 | static int | |
5004 | parse_tb (char **str) | |
5005 | { | |
5006 | char * p = *str; | |
5007 | int reg; | |
5008 | ||
5009 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5010 | { |
5011 | inst.error = _("'[' expected"); | |
5012 | return FAIL; | |
5013 | } | |
92e90b6e | 5014 | |
dcbf9037 | 5015 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5016 | { |
5017 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5018 | return FAIL; | |
5019 | } | |
5020 | inst.operands[0].reg = reg; | |
5021 | ||
5022 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5023 | { |
5024 | inst.error = _("',' expected"); | |
5025 | return FAIL; | |
5026 | } | |
92e90b6e | 5027 | |
dcbf9037 | 5028 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5029 | { |
5030 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5031 | return FAIL; | |
5032 | } | |
5033 | inst.operands[0].imm = reg; | |
5034 | ||
5035 | if (skip_past_comma (&p) == SUCCESS) | |
5036 | { | |
5037 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5038 | return FAIL; | |
5039 | if (inst.reloc.exp.X_add_number != 1) | |
5040 | { | |
5041 | inst.error = _("invalid shift"); | |
5042 | return FAIL; | |
5043 | } | |
5044 | inst.operands[0].shifted = 1; | |
5045 | } | |
5046 | ||
5047 | if (skip_past_char (&p, ']') == FAIL) | |
5048 | { | |
5049 | inst.error = _("']' expected"); | |
5050 | return FAIL; | |
5051 | } | |
5052 | *str = p; | |
5053 | return SUCCESS; | |
5054 | } | |
5055 | ||
5287ad62 JB |
5056 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5057 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5058 | Up to four operands may be read; this function handles setting the |
5059 | ".present" field for each read operand itself. | |
5287ad62 JB |
5060 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5061 | else returns FAIL. */ | |
5062 | ||
5063 | static int | |
5064 | parse_neon_mov (char **str, int *which_operand) | |
5065 | { | |
5066 | int i = *which_operand, val; | |
5067 | enum arm_reg_type rtype; | |
5068 | char *ptr = *str; | |
dcbf9037 | 5069 | struct neon_type_el optype; |
5287ad62 | 5070 | |
dcbf9037 | 5071 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5072 | { |
5073 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5074 | inst.operands[i].reg = val; | |
5075 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5076 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5077 | inst.operands[i++].present = 1; |
5078 | ||
5079 | if (skip_past_comma (&ptr) == FAIL) | |
5080 | goto wanted_comma; | |
5081 | ||
dcbf9037 | 5082 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 JB |
5083 | goto wanted_arm; |
5084 | ||
5085 | inst.operands[i].reg = val; | |
5086 | inst.operands[i].isreg = 1; | |
5087 | inst.operands[i].present = 1; | |
5088 | } | |
037e8744 | 5089 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5090 | != FAIL) |
5287ad62 JB |
5091 | { |
5092 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5093 | if (skip_past_comma (&ptr) == FAIL) | |
5094 | goto wanted_comma; | |
5095 | ||
5096 | inst.operands[i].reg = val; | |
5097 | inst.operands[i].isreg = 1; | |
5098 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5099 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5100 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5101 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5102 | inst.operands[i++].present = 1; |
5103 | ||
dcbf9037 | 5104 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5105 | { |
037e8744 JB |
5106 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5107 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5108 | inst.operands[i].reg = val; |
5109 | inst.operands[i].isreg = 1; | |
037e8744 | 5110 | inst.operands[i].present = 1; |
5287ad62 JB |
5111 | |
5112 | if (rtype == REG_TYPE_NQ) | |
5113 | { | |
dcbf9037 | 5114 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5115 | return FAIL; |
5116 | } | |
037e8744 JB |
5117 | else if (rtype != REG_TYPE_VFS) |
5118 | { | |
5119 | i++; | |
5120 | if (skip_past_comma (&ptr) == FAIL) | |
5121 | goto wanted_comma; | |
5122 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5123 | goto wanted_arm; | |
5124 | inst.operands[i].reg = val; | |
5125 | inst.operands[i].isreg = 1; | |
5126 | inst.operands[i].present = 1; | |
5127 | } | |
5287ad62 | 5128 | } |
136da414 | 5129 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
136da414 | 5130 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
037e8744 JB |
5131 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> |
5132 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5133 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5134 | ; | |
5287ad62 | 5135 | else if (parse_big_immediate (&ptr, i) == SUCCESS) |
5287ad62 JB |
5136 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
5137 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
037e8744 JB |
5138 | ; |
5139 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, | |
5140 | &optype)) != FAIL) | |
5287ad62 JB |
5141 | { |
5142 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5143 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5144 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5145 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5146 | |
5147 | inst.operands[i].reg = val; | |
5148 | inst.operands[i].isreg = 1; | |
5149 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5150 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5151 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5152 | inst.operands[i].vectype = optype; |
5287ad62 | 5153 | inst.operands[i].present = 1; |
037e8744 JB |
5154 | |
5155 | if (skip_past_comma (&ptr) == SUCCESS) | |
5156 | { | |
5157 | /* Case 15. */ | |
5158 | i++; | |
5159 | ||
5160 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5161 | goto wanted_arm; | |
5162 | ||
5163 | inst.operands[i].reg = val; | |
5164 | inst.operands[i].isreg = 1; | |
5165 | inst.operands[i++].present = 1; | |
5166 | ||
5167 | if (skip_past_comma (&ptr) == FAIL) | |
5168 | goto wanted_comma; | |
5169 | ||
5170 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5171 | goto wanted_arm; | |
5172 | ||
5173 | inst.operands[i].reg = val; | |
5174 | inst.operands[i].isreg = 1; | |
5175 | inst.operands[i++].present = 1; | |
5176 | } | |
5287ad62 JB |
5177 | } |
5178 | else | |
5179 | { | |
dcbf9037 | 5180 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
5181 | return FAIL; |
5182 | } | |
5183 | } | |
dcbf9037 | 5184 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5185 | { |
5186 | /* Cases 6, 7. */ | |
5187 | inst.operands[i].reg = val; | |
5188 | inst.operands[i].isreg = 1; | |
5189 | inst.operands[i++].present = 1; | |
5190 | ||
5191 | if (skip_past_comma (&ptr) == FAIL) | |
5192 | goto wanted_comma; | |
5193 | ||
dcbf9037 | 5194 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5195 | { |
5196 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
5197 | inst.operands[i].reg = val; | |
5198 | inst.operands[i].isscalar = 1; | |
5199 | inst.operands[i].present = 1; | |
dcbf9037 | 5200 | inst.operands[i].vectype = optype; |
5287ad62 | 5201 | } |
dcbf9037 | 5202 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5203 | { |
5204 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
5205 | inst.operands[i].reg = val; | |
5206 | inst.operands[i].isreg = 1; | |
5207 | inst.operands[i++].present = 1; | |
5208 | ||
5209 | if (skip_past_comma (&ptr) == FAIL) | |
5210 | goto wanted_comma; | |
5211 | ||
037e8744 | 5212 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 5213 | == FAIL) |
5287ad62 | 5214 | { |
037e8744 | 5215 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
5216 | return FAIL; |
5217 | } | |
5218 | ||
5219 | inst.operands[i].reg = val; | |
5220 | inst.operands[i].isreg = 1; | |
037e8744 JB |
5221 | inst.operands[i].isvec = 1; |
5222 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 5223 | inst.operands[i].vectype = optype; |
5287ad62 | 5224 | inst.operands[i].present = 1; |
037e8744 JB |
5225 | |
5226 | if (rtype == REG_TYPE_VFS) | |
5227 | { | |
5228 | /* Case 14. */ | |
5229 | i++; | |
5230 | if (skip_past_comma (&ptr) == FAIL) | |
5231 | goto wanted_comma; | |
5232 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
5233 | &optype)) == FAIL) | |
5234 | { | |
5235 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
5236 | return FAIL; | |
5237 | } | |
5238 | inst.operands[i].reg = val; | |
5239 | inst.operands[i].isreg = 1; | |
5240 | inst.operands[i].isvec = 1; | |
5241 | inst.operands[i].issingle = 1; | |
5242 | inst.operands[i].vectype = optype; | |
5243 | inst.operands[i].present = 1; | |
5244 | } | |
5245 | } | |
5246 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
5247 | != FAIL) | |
5248 | { | |
5249 | /* Case 13. */ | |
5250 | inst.operands[i].reg = val; | |
5251 | inst.operands[i].isreg = 1; | |
5252 | inst.operands[i].isvec = 1; | |
5253 | inst.operands[i].issingle = 1; | |
5254 | inst.operands[i].vectype = optype; | |
5255 | inst.operands[i++].present = 1; | |
5287ad62 JB |
5256 | } |
5257 | } | |
5258 | else | |
5259 | { | |
dcbf9037 | 5260 | first_error (_("parse error")); |
5287ad62 JB |
5261 | return FAIL; |
5262 | } | |
5263 | ||
5264 | /* Successfully parsed the operands. Update args. */ | |
5265 | *which_operand = i; | |
5266 | *str = ptr; | |
5267 | return SUCCESS; | |
5268 | ||
5269 | wanted_comma: | |
dcbf9037 | 5270 | first_error (_("expected comma")); |
5287ad62 JB |
5271 | return FAIL; |
5272 | ||
5273 | wanted_arm: | |
dcbf9037 | 5274 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 5275 | return FAIL; |
5287ad62 JB |
5276 | } |
5277 | ||
c19d1205 ZW |
5278 | /* Matcher codes for parse_operands. */ |
5279 | enum operand_parse_code | |
5280 | { | |
5281 | OP_stop, /* end of line */ | |
5282 | ||
5283 | OP_RR, /* ARM register */ | |
5284 | OP_RRnpc, /* ARM register, not r15 */ | |
5285 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
5286 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
5287 | OP_RCP, /* Coprocessor number */ | |
5288 | OP_RCN, /* Coprocessor register */ | |
5289 | OP_RF, /* FPA register */ | |
5290 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
5291 | OP_RVD, /* VFP double precision register (0..15) */ |
5292 | OP_RND, /* Neon double precision register (0..31) */ | |
5293 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 5294 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 5295 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 5296 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 5297 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
5298 | OP_RVC, /* VFP control register */ |
5299 | OP_RMF, /* Maverick F register */ | |
5300 | OP_RMD, /* Maverick D register */ | |
5301 | OP_RMFX, /* Maverick FX register */ | |
5302 | OP_RMDX, /* Maverick DX register */ | |
5303 | OP_RMAX, /* Maverick AX register */ | |
5304 | OP_RMDS, /* Maverick DSPSC register */ | |
5305 | OP_RIWR, /* iWMMXt wR register */ | |
5306 | OP_RIWC, /* iWMMXt wC register */ | |
5307 | OP_RIWG, /* iWMMXt wCG register */ | |
5308 | OP_RXA, /* XScale accumulator register */ | |
5309 | ||
5310 | OP_REGLST, /* ARM register list */ | |
5311 | OP_VRSLST, /* VFP single-precision register list */ | |
5312 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 5313 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
5314 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
5315 | OP_NSTRLST, /* Neon element/structure list */ | |
5316 | ||
5317 | OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */ | |
5318 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ | |
037e8744 | 5319 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 5320 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 5321 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
5322 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
5323 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
5324 | OP_VMOV, /* Neon VMOV operands. */ | |
5325 | OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */ | |
5326 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ | |
5327 | ||
5328 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
5329 | OP_I7, /* immediate value 0 .. 7 */ |
5330 | OP_I15, /* 0 .. 15 */ | |
5331 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 5332 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
5333 | OP_I31, /* 0 .. 31 */ |
5334 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
5335 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
5336 | OP_I32z, /* 0 .. 32 */ |
5337 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 5338 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
5339 | OP_I64, /* 1 .. 64 */ |
5340 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 5341 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
5342 | |
5343 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
5344 | OP_I7b, /* 0 .. 7 */ | |
5345 | OP_I15b, /* 0 .. 15 */ | |
5346 | OP_I31b, /* 0 .. 31 */ | |
5347 | ||
5348 | OP_SH, /* shifter operand */ | |
4962c51a | 5349 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 5350 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
5351 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
5352 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
5353 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
5354 | OP_EXP, /* arbitrary expression */ |
5355 | OP_EXPi, /* same, with optional immediate prefix */ | |
5356 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 5357 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
5358 | |
5359 | OP_CPSF, /* CPS flags */ | |
5360 | OP_ENDI, /* Endianness specifier */ | |
5361 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
5362 | OP_COND, /* conditional code */ | |
92e90b6e | 5363 | OP_TB, /* Table branch. */ |
c19d1205 | 5364 | |
037e8744 JB |
5365 | OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */ |
5366 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ | |
5367 | ||
c19d1205 ZW |
5368 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
5369 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
5370 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
5371 | OP_RF_IF, /* FPA register or immediate */ | |
5372 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
5373 | ||
5374 | /* Optional operands. */ | |
5375 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
5376 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 5377 | OP_oI32b, /* 1 .. 32 */ |
c19d1205 ZW |
5378 | OP_oIffffb, /* 0 .. 65535 */ |
5379 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
5380 | ||
5381 | OP_oRR, /* ARM register */ | |
5382 | OP_oRRnpc, /* ARM register, not the PC */ | |
5287ad62 JB |
5383 | OP_oRND, /* Optional Neon double precision register */ |
5384 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5385 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 5386 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
5387 | OP_oSHll, /* LSL immediate */ |
5388 | OP_oSHar, /* ASR immediate */ | |
5389 | OP_oSHllar, /* LSL or ASR immediate */ | |
5390 | OP_oROR, /* ROR 0/8/16/24 */ | |
62b3e311 | 5391 | OP_oBARRIER, /* Option argument for a barrier instruction. */ |
c19d1205 ZW |
5392 | |
5393 | OP_FIRST_OPTIONAL = OP_oI7b | |
5394 | }; | |
a737bd4d | 5395 | |
c19d1205 ZW |
5396 | /* Generic instruction operand parser. This does no encoding and no |
5397 | semantic validation; it merely squirrels values away in the inst | |
5398 | structure. Returns SUCCESS or FAIL depending on whether the | |
5399 | specified grammar matched. */ | |
5400 | static int | |
ca3f61f7 | 5401 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
5402 | { |
5403 | unsigned const char *upat = pattern; | |
5404 | char *backtrack_pos = 0; | |
5405 | const char *backtrack_error = 0; | |
5406 | int i, val, backtrack_index = 0; | |
5287ad62 | 5407 | enum arm_reg_type rtype; |
4962c51a | 5408 | parse_operand_result result; |
c19d1205 ZW |
5409 | |
5410 | #define po_char_or_fail(chr) do { \ | |
5411 | if (skip_past_char (&str, chr) == FAIL) \ | |
5412 | goto bad_args; \ | |
5413 | } while (0) | |
5414 | ||
dcbf9037 JB |
5415 | #define po_reg_or_fail(regtype) do { \ |
5416 | val = arm_typed_reg_parse (&str, regtype, &rtype, \ | |
5417 | &inst.operands[i].vectype); \ | |
5418 | if (val == FAIL) \ | |
5419 | { \ | |
5420 | first_error (_(reg_expected_msgs[regtype])); \ | |
5421 | goto failure; \ | |
5422 | } \ | |
5423 | inst.operands[i].reg = val; \ | |
5424 | inst.operands[i].isreg = 1; \ | |
5425 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
037e8744 JB |
5426 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ |
5427 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5428 | || rtype == REG_TYPE_VFD \ | |
5429 | || rtype == REG_TYPE_NQ); \ | |
c19d1205 ZW |
5430 | } while (0) |
5431 | ||
dcbf9037 JB |
5432 | #define po_reg_or_goto(regtype, label) do { \ |
5433 | val = arm_typed_reg_parse (&str, regtype, &rtype, \ | |
5434 | &inst.operands[i].vectype); \ | |
5435 | if (val == FAIL) \ | |
5436 | goto label; \ | |
5437 | \ | |
5438 | inst.operands[i].reg = val; \ | |
5439 | inst.operands[i].isreg = 1; \ | |
5440 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
037e8744 JB |
5441 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ |
5442 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5443 | || rtype == REG_TYPE_VFD \ | |
5444 | || rtype == REG_TYPE_NQ); \ | |
c19d1205 ZW |
5445 | } while (0) |
5446 | ||
5447 | #define po_imm_or_fail(min, max, popt) do { \ | |
5448 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
5449 | goto failure; \ | |
5450 | inst.operands[i].imm = val; \ | |
5451 | } while (0) | |
5452 | ||
dcbf9037 JB |
5453 | #define po_scalar_or_goto(elsz, label) do { \ |
5454 | val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \ | |
5455 | if (val == FAIL) \ | |
5456 | goto label; \ | |
5457 | inst.operands[i].reg = val; \ | |
5458 | inst.operands[i].isscalar = 1; \ | |
5287ad62 JB |
5459 | } while (0) |
5460 | ||
c19d1205 ZW |
5461 | #define po_misc_or_fail(expr) do { \ |
5462 | if (expr) \ | |
5463 | goto failure; \ | |
5464 | } while (0) | |
5465 | ||
4962c51a MS |
5466 | #define po_misc_or_fail_no_backtrack(expr) do { \ |
5467 | result = expr; \ | |
5468 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\ | |
5469 | backtrack_pos = 0; \ | |
5470 | if (result != PARSE_OPERAND_SUCCESS) \ | |
5471 | goto failure; \ | |
5472 | } while (0) | |
5473 | ||
c19d1205 ZW |
5474 | skip_whitespace (str); |
5475 | ||
5476 | for (i = 0; upat[i] != OP_stop; i++) | |
5477 | { | |
5478 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
5479 | { | |
5480 | /* Remember where we are in case we need to backtrack. */ | |
5481 | assert (!backtrack_pos); | |
5482 | backtrack_pos = str; | |
5483 | backtrack_error = inst.error; | |
5484 | backtrack_index = i; | |
5485 | } | |
5486 | ||
5487 | if (i > 0) | |
5488 | po_char_or_fail (','); | |
5489 | ||
5490 | switch (upat[i]) | |
5491 | { | |
5492 | /* Registers */ | |
5493 | case OP_oRRnpc: | |
5494 | case OP_RRnpc: | |
5495 | case OP_oRR: | |
5496 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
5497 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
5498 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
5499 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
5500 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
5501 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
5502 | case OP_oRND: |
5503 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
c19d1205 ZW |
5504 | case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break; |
5505 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; | |
5506 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
5507 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
5508 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
5509 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
5510 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
5511 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
5512 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
5513 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
5514 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
5515 | case OP_oRNQ: |
5516 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
5517 | case OP_oRNDQ: | |
5518 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
5519 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
5520 | case OP_oRNSDQ: | |
5521 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
5522 | |
5523 | /* Neon scalar. Using an element size of 8 means that some invalid | |
5524 | scalars are accepted here, so deal with those in later code. */ | |
5525 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
5526 | ||
5527 | /* WARNING: We can expand to two operands here. This has the potential | |
5528 | to totally confuse the backtracking mechanism! It will be OK at | |
5529 | least as long as we don't try to use optional args as well, | |
5530 | though. */ | |
5531 | case OP_NILO: | |
5532 | { | |
5533 | po_reg_or_goto (REG_TYPE_NDQ, try_imm); | |
5534 | i++; | |
5535 | skip_past_comma (&str); | |
5536 | po_reg_or_goto (REG_TYPE_NDQ, one_reg_only); | |
5537 | break; | |
5538 | one_reg_only: | |
5539 | /* Optional register operand was omitted. Unfortunately, it's in | |
5540 | operands[i-1] and we need it to be in inst.operands[i]. Fix that | |
5541 | here (this is a bit grotty). */ | |
5542 | inst.operands[i] = inst.operands[i-1]; | |
5543 | inst.operands[i-1].present = 0; | |
5544 | break; | |
5545 | try_imm: | |
5546 | /* Immediate gets verified properly later, so accept any now. */ | |
5547 | po_imm_or_fail (INT_MIN, INT_MAX, TRUE); | |
5548 | } | |
5549 | break; | |
5550 | ||
5551 | case OP_RNDQ_I0: | |
5552 | { | |
5553 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
5554 | break; | |
5555 | try_imm0: | |
5556 | po_imm_or_fail (0, 0, TRUE); | |
5557 | } | |
5558 | break; | |
5559 | ||
037e8744 JB |
5560 | case OP_RVSD_I0: |
5561 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
5562 | break; | |
5563 | ||
5287ad62 JB |
5564 | case OP_RR_RNSC: |
5565 | { | |
5566 | po_scalar_or_goto (8, try_rr); | |
5567 | break; | |
5568 | try_rr: | |
5569 | po_reg_or_fail (REG_TYPE_RN); | |
5570 | } | |
5571 | break; | |
5572 | ||
037e8744 JB |
5573 | case OP_RNSDQ_RNSC: |
5574 | { | |
5575 | po_scalar_or_goto (8, try_nsdq); | |
5576 | break; | |
5577 | try_nsdq: | |
5578 | po_reg_or_fail (REG_TYPE_NSDQ); | |
5579 | } | |
5580 | break; | |
5581 | ||
5287ad62 JB |
5582 | case OP_RNDQ_RNSC: |
5583 | { | |
5584 | po_scalar_or_goto (8, try_ndq); | |
5585 | break; | |
5586 | try_ndq: | |
5587 | po_reg_or_fail (REG_TYPE_NDQ); | |
5588 | } | |
5589 | break; | |
5590 | ||
5591 | case OP_RND_RNSC: | |
5592 | { | |
5593 | po_scalar_or_goto (8, try_vfd); | |
5594 | break; | |
5595 | try_vfd: | |
5596 | po_reg_or_fail (REG_TYPE_VFD); | |
5597 | } | |
5598 | break; | |
5599 | ||
5600 | case OP_VMOV: | |
5601 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
5602 | not careful then bad things might happen. */ | |
5603 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
5604 | break; | |
5605 | ||
5606 | case OP_RNDQ_IMVNb: | |
5607 | { | |
5608 | po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm); | |
5609 | break; | |
5610 | try_mvnimm: | |
5611 | /* There's a possibility of getting a 64-bit immediate here, so | |
5612 | we need special handling. */ | |
5613 | if (parse_big_immediate (&str, i) == FAIL) | |
5614 | { | |
5615 | inst.error = _("immediate value is out of range"); | |
5616 | goto failure; | |
5617 | } | |
5618 | } | |
5619 | break; | |
5620 | ||
5621 | case OP_RNDQ_I63b: | |
5622 | { | |
5623 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
5624 | break; | |
5625 | try_shimm: | |
5626 | po_imm_or_fail (0, 63, TRUE); | |
5627 | } | |
5628 | break; | |
c19d1205 ZW |
5629 | |
5630 | case OP_RRnpcb: | |
5631 | po_char_or_fail ('['); | |
5632 | po_reg_or_fail (REG_TYPE_RN); | |
5633 | po_char_or_fail (']'); | |
5634 | break; | |
a737bd4d | 5635 | |
c19d1205 ZW |
5636 | case OP_RRw: |
5637 | po_reg_or_fail (REG_TYPE_RN); | |
5638 | if (skip_past_char (&str, '!') == SUCCESS) | |
5639 | inst.operands[i].writeback = 1; | |
5640 | break; | |
5641 | ||
5642 | /* Immediates */ | |
5643 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
5644 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
5645 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 5646 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
5647 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
5648 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 5649 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 5650 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
5651 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
5652 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
5653 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 5654 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
5655 | |
5656 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
5657 | case OP_oI7b: | |
5658 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
5659 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
5660 | case OP_oI31b: | |
5661 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 5662 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
c19d1205 ZW |
5663 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
5664 | ||
5665 | /* Immediate variants */ | |
5666 | case OP_oI255c: | |
5667 | po_char_or_fail ('{'); | |
5668 | po_imm_or_fail (0, 255, TRUE); | |
5669 | po_char_or_fail ('}'); | |
5670 | break; | |
5671 | ||
5672 | case OP_I31w: | |
5673 | /* The expression parser chokes on a trailing !, so we have | |
5674 | to find it first and zap it. */ | |
5675 | { | |
5676 | char *s = str; | |
5677 | while (*s && *s != ',') | |
5678 | s++; | |
5679 | if (s[-1] == '!') | |
5680 | { | |
5681 | s[-1] = '\0'; | |
5682 | inst.operands[i].writeback = 1; | |
5683 | } | |
5684 | po_imm_or_fail (0, 31, TRUE); | |
5685 | if (str == s - 1) | |
5686 | str = s; | |
5687 | } | |
5688 | break; | |
5689 | ||
5690 | /* Expressions */ | |
5691 | case OP_EXPi: EXPi: | |
5692 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
5693 | GE_OPT_PREFIX)); | |
5694 | break; | |
5695 | ||
5696 | case OP_EXP: | |
5697 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
5698 | GE_NO_PREFIX)); | |
5699 | break; | |
5700 | ||
5701 | case OP_EXPr: EXPr: | |
5702 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
5703 | GE_NO_PREFIX)); | |
5704 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 5705 | { |
c19d1205 ZW |
5706 | val = parse_reloc (&str); |
5707 | if (val == -1) | |
5708 | { | |
5709 | inst.error = _("unrecognized relocation suffix"); | |
5710 | goto failure; | |
5711 | } | |
5712 | else if (val != BFD_RELOC_UNUSED) | |
5713 | { | |
5714 | inst.operands[i].imm = val; | |
5715 | inst.operands[i].hasreloc = 1; | |
5716 | } | |
a737bd4d | 5717 | } |
c19d1205 | 5718 | break; |
a737bd4d | 5719 | |
b6895b4f PB |
5720 | /* Operand for MOVW or MOVT. */ |
5721 | case OP_HALF: | |
5722 | po_misc_or_fail (parse_half (&str)); | |
5723 | break; | |
5724 | ||
c19d1205 ZW |
5725 | /* Register or expression */ |
5726 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; | |
5727 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 5728 | |
c19d1205 ZW |
5729 | /* Register or immediate */ |
5730 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; | |
5731 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 5732 | |
c19d1205 ZW |
5733 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
5734 | IF: | |
5735 | if (!is_immediate_prefix (*str)) | |
5736 | goto bad_args; | |
5737 | str++; | |
5738 | val = parse_fpa_immediate (&str); | |
5739 | if (val == FAIL) | |
5740 | goto failure; | |
5741 | /* FPA immediates are encoded as registers 8-15. | |
5742 | parse_fpa_immediate has already applied the offset. */ | |
5743 | inst.operands[i].reg = val; | |
5744 | inst.operands[i].isreg = 1; | |
5745 | break; | |
09d92015 | 5746 | |
c19d1205 ZW |
5747 | /* Two kinds of register */ |
5748 | case OP_RIWR_RIWC: | |
5749 | { | |
5750 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
5751 | if (rege->type != REG_TYPE_MMXWR | |
5752 | && rege->type != REG_TYPE_MMXWC | |
5753 | && rege->type != REG_TYPE_MMXWCG) | |
5754 | { | |
5755 | inst.error = _("iWMMXt data or control register expected"); | |
5756 | goto failure; | |
5757 | } | |
5758 | inst.operands[i].reg = rege->number; | |
5759 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
5760 | } | |
5761 | break; | |
09d92015 | 5762 | |
c19d1205 ZW |
5763 | /* Misc */ |
5764 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
5765 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
5766 | case OP_oROR: val = parse_ror (&str); break; | |
5767 | case OP_PSR: val = parse_psr (&str); break; | |
5768 | case OP_COND: val = parse_cond (&str); break; | |
62b3e311 | 5769 | case OP_oBARRIER:val = parse_barrier (&str); break; |
c19d1205 | 5770 | |
037e8744 JB |
5771 | case OP_RVC_PSR: |
5772 | po_reg_or_goto (REG_TYPE_VFC, try_psr); | |
5773 | inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */ | |
5774 | break; | |
5775 | try_psr: | |
5776 | val = parse_psr (&str); | |
5777 | break; | |
5778 | ||
5779 | case OP_APSR_RR: | |
5780 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
5781 | break; | |
5782 | try_apsr: | |
5783 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
5784 | instruction). */ | |
5785 | if (strncasecmp (str, "APSR_", 5) == 0) | |
5786 | { | |
5787 | unsigned found = 0; | |
5788 | str += 5; | |
5789 | while (found < 15) | |
5790 | switch (*str++) | |
5791 | { | |
5792 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
5793 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
5794 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
5795 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
5796 | default: found = 16; | |
5797 | } | |
5798 | if (found != 15) | |
5799 | goto failure; | |
5800 | inst.operands[i].isvec = 1; | |
5801 | } | |
5802 | else | |
5803 | goto failure; | |
5804 | break; | |
5805 | ||
92e90b6e PB |
5806 | case OP_TB: |
5807 | po_misc_or_fail (parse_tb (&str)); | |
5808 | break; | |
5809 | ||
c19d1205 ZW |
5810 | /* Register lists */ |
5811 | case OP_REGLST: | |
5812 | val = parse_reg_list (&str); | |
5813 | if (*str == '^') | |
5814 | { | |
5815 | inst.operands[1].writeback = 1; | |
5816 | str++; | |
5817 | } | |
5818 | break; | |
09d92015 | 5819 | |
c19d1205 | 5820 | case OP_VRSLST: |
5287ad62 | 5821 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 5822 | break; |
09d92015 | 5823 | |
c19d1205 | 5824 | case OP_VRDLST: |
5287ad62 | 5825 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 5826 | break; |
a737bd4d | 5827 | |
037e8744 JB |
5828 | case OP_VRSDLST: |
5829 | /* Allow Q registers too. */ | |
5830 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
5831 | REGLIST_NEON_D); | |
5832 | if (val == FAIL) | |
5833 | { | |
5834 | inst.error = NULL; | |
5835 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
5836 | REGLIST_VFP_S); | |
5837 | inst.operands[i].issingle = 1; | |
5838 | } | |
5839 | break; | |
5840 | ||
5287ad62 JB |
5841 | case OP_NRDLST: |
5842 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
5843 | REGLIST_NEON_D); | |
5844 | break; | |
5845 | ||
5846 | case OP_NSTRLST: | |
dcbf9037 JB |
5847 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
5848 | &inst.operands[i].vectype); | |
5287ad62 JB |
5849 | break; |
5850 | ||
c19d1205 ZW |
5851 | /* Addressing modes */ |
5852 | case OP_ADDR: | |
5853 | po_misc_or_fail (parse_address (&str, i)); | |
5854 | break; | |
09d92015 | 5855 | |
4962c51a MS |
5856 | case OP_ADDRGLDR: |
5857 | po_misc_or_fail_no_backtrack ( | |
5858 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
5859 | break; | |
5860 | ||
5861 | case OP_ADDRGLDRS: | |
5862 | po_misc_or_fail_no_backtrack ( | |
5863 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
5864 | break; | |
5865 | ||
5866 | case OP_ADDRGLDC: | |
5867 | po_misc_or_fail_no_backtrack ( | |
5868 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
5869 | break; | |
5870 | ||
c19d1205 ZW |
5871 | case OP_SH: |
5872 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
5873 | break; | |
09d92015 | 5874 | |
4962c51a MS |
5875 | case OP_SHG: |
5876 | po_misc_or_fail_no_backtrack ( | |
5877 | parse_shifter_operand_group_reloc (&str, i)); | |
5878 | break; | |
5879 | ||
c19d1205 ZW |
5880 | case OP_oSHll: |
5881 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
5882 | break; | |
09d92015 | 5883 | |
c19d1205 ZW |
5884 | case OP_oSHar: |
5885 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
5886 | break; | |
09d92015 | 5887 | |
c19d1205 ZW |
5888 | case OP_oSHllar: |
5889 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
5890 | break; | |
09d92015 | 5891 | |
c19d1205 ZW |
5892 | default: |
5893 | as_fatal ("unhandled operand code %d", upat[i]); | |
5894 | } | |
09d92015 | 5895 | |
c19d1205 ZW |
5896 | /* Various value-based sanity checks and shared operations. We |
5897 | do not signal immediate failures for the register constraints; | |
5898 | this allows a syntax error to take precedence. */ | |
5899 | switch (upat[i]) | |
5900 | { | |
5901 | case OP_oRRnpc: | |
5902 | case OP_RRnpc: | |
5903 | case OP_RRnpcb: | |
5904 | case OP_RRw: | |
5905 | case OP_RRnpc_I0: | |
5906 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
5907 | inst.error = BAD_PC; | |
5908 | break; | |
09d92015 | 5909 | |
c19d1205 ZW |
5910 | case OP_CPSF: |
5911 | case OP_ENDI: | |
5912 | case OP_oROR: | |
5913 | case OP_PSR: | |
037e8744 | 5914 | case OP_RVC_PSR: |
c19d1205 | 5915 | case OP_COND: |
62b3e311 | 5916 | case OP_oBARRIER: |
c19d1205 ZW |
5917 | case OP_REGLST: |
5918 | case OP_VRSLST: | |
5919 | case OP_VRDLST: | |
037e8744 | 5920 | case OP_VRSDLST: |
5287ad62 JB |
5921 | case OP_NRDLST: |
5922 | case OP_NSTRLST: | |
c19d1205 ZW |
5923 | if (val == FAIL) |
5924 | goto failure; | |
5925 | inst.operands[i].imm = val; | |
5926 | break; | |
a737bd4d | 5927 | |
c19d1205 ZW |
5928 | default: |
5929 | break; | |
5930 | } | |
09d92015 | 5931 | |
c19d1205 ZW |
5932 | /* If we get here, this operand was successfully parsed. */ |
5933 | inst.operands[i].present = 1; | |
5934 | continue; | |
09d92015 | 5935 | |
c19d1205 | 5936 | bad_args: |
09d92015 | 5937 | inst.error = BAD_ARGS; |
c19d1205 ZW |
5938 | |
5939 | failure: | |
5940 | if (!backtrack_pos) | |
d252fdde PB |
5941 | { |
5942 | /* The parse routine should already have set inst.error, but set a | |
5943 | defaut here just in case. */ | |
5944 | if (!inst.error) | |
5945 | inst.error = _("syntax error"); | |
5946 | return FAIL; | |
5947 | } | |
c19d1205 ZW |
5948 | |
5949 | /* Do not backtrack over a trailing optional argument that | |
5950 | absorbed some text. We will only fail again, with the | |
5951 | 'garbage following instruction' error message, which is | |
5952 | probably less helpful than the current one. */ | |
5953 | if (backtrack_index == i && backtrack_pos != str | |
5954 | && upat[i+1] == OP_stop) | |
d252fdde PB |
5955 | { |
5956 | if (!inst.error) | |
5957 | inst.error = _("syntax error"); | |
5958 | return FAIL; | |
5959 | } | |
c19d1205 ZW |
5960 | |
5961 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
5962 | str = backtrack_pos; | |
5963 | inst.error = backtrack_error; | |
5964 | inst.operands[backtrack_index].present = 0; | |
5965 | i = backtrack_index; | |
5966 | backtrack_pos = 0; | |
09d92015 | 5967 | } |
09d92015 | 5968 | |
c19d1205 ZW |
5969 | /* Check that we have parsed all the arguments. */ |
5970 | if (*str != '\0' && !inst.error) | |
5971 | inst.error = _("garbage following instruction"); | |
09d92015 | 5972 | |
c19d1205 | 5973 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
5974 | } |
5975 | ||
c19d1205 ZW |
5976 | #undef po_char_or_fail |
5977 | #undef po_reg_or_fail | |
5978 | #undef po_reg_or_goto | |
5979 | #undef po_imm_or_fail | |
5287ad62 | 5980 | #undef po_scalar_or_fail |
c19d1205 ZW |
5981 | \f |
5982 | /* Shorthand macro for instruction encoding functions issuing errors. */ | |
5983 | #define constraint(expr, err) do { \ | |
5984 | if (expr) \ | |
5985 | { \ | |
5986 | inst.error = err; \ | |
5987 | return; \ | |
5988 | } \ | |
5989 | } while (0) | |
5990 | ||
5991 | /* Functions for operand encoding. ARM, then Thumb. */ | |
5992 | ||
5993 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
5994 | ||
5995 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
5996 | return the encoded form. Otherwise, return FAIL. */ | |
5997 | ||
5998 | static unsigned int | |
5999 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6000 | { |
c19d1205 ZW |
6001 | unsigned int a, i; |
6002 | ||
6003 | for (i = 0; i < 32; i += 2) | |
6004 | if ((a = rotate_left (val, i)) <= 0xff) | |
6005 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6006 | ||
6007 | return FAIL; | |
09d92015 MM |
6008 | } |
6009 | ||
c19d1205 ZW |
6010 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6011 | return the encoded form. Otherwise, return FAIL. */ | |
6012 | static unsigned int | |
6013 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6014 | { |
c19d1205 | 6015 | unsigned int a, i; |
09d92015 | 6016 | |
9c3c69f2 | 6017 | if (val <= 0xff) |
c19d1205 | 6018 | return val; |
a737bd4d | 6019 | |
9c3c69f2 | 6020 | for (i = 1; i <= 24; i++) |
09d92015 | 6021 | { |
9c3c69f2 PB |
6022 | a = val >> i; |
6023 | if ((val & ~(0xff << i)) == 0) | |
6024 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6025 | } |
a737bd4d | 6026 | |
c19d1205 ZW |
6027 | a = val & 0xff; |
6028 | if (val == ((a << 16) | a)) | |
6029 | return 0x100 | a; | |
6030 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6031 | return 0x300 | a; | |
09d92015 | 6032 | |
c19d1205 ZW |
6033 | a = val & 0xff00; |
6034 | if (val == ((a << 16) | a)) | |
6035 | return 0x200 | (a >> 8); | |
a737bd4d | 6036 | |
c19d1205 | 6037 | return FAIL; |
09d92015 | 6038 | } |
5287ad62 | 6039 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6040 | |
6041 | static void | |
5287ad62 JB |
6042 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6043 | { | |
6044 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6045 | && reg > 15) | |
6046 | { | |
6047 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
6048 | { | |
6049 | if (thumb_mode) | |
6050 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
6051 | fpu_vfp_ext_v3); | |
6052 | else | |
6053 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
6054 | fpu_vfp_ext_v3); | |
6055 | } | |
6056 | else | |
6057 | { | |
dcbf9037 | 6058 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
6059 | return; |
6060 | } | |
6061 | } | |
6062 | ||
c19d1205 | 6063 | switch (pos) |
09d92015 | 6064 | { |
c19d1205 ZW |
6065 | case VFP_REG_Sd: |
6066 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
6067 | break; | |
6068 | ||
6069 | case VFP_REG_Sn: | |
6070 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
6071 | break; | |
6072 | ||
6073 | case VFP_REG_Sm: | |
6074 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
6075 | break; | |
6076 | ||
5287ad62 JB |
6077 | case VFP_REG_Dd: |
6078 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
6079 | break; | |
6080 | ||
6081 | case VFP_REG_Dn: | |
6082 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
6083 | break; | |
6084 | ||
6085 | case VFP_REG_Dm: | |
6086 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
6087 | break; | |
6088 | ||
c19d1205 ZW |
6089 | default: |
6090 | abort (); | |
09d92015 | 6091 | } |
09d92015 MM |
6092 | } |
6093 | ||
c19d1205 | 6094 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 6095 | if any, is handled by md_apply_fix. */ |
09d92015 | 6096 | static void |
c19d1205 | 6097 | encode_arm_shift (int i) |
09d92015 | 6098 | { |
c19d1205 ZW |
6099 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
6100 | inst.instruction |= SHIFT_ROR << 5; | |
6101 | else | |
09d92015 | 6102 | { |
c19d1205 ZW |
6103 | inst.instruction |= inst.operands[i].shift_kind << 5; |
6104 | if (inst.operands[i].immisreg) | |
6105 | { | |
6106 | inst.instruction |= SHIFT_BY_REG; | |
6107 | inst.instruction |= inst.operands[i].imm << 8; | |
6108 | } | |
6109 | else | |
6110 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 6111 | } |
c19d1205 | 6112 | } |
09d92015 | 6113 | |
c19d1205 ZW |
6114 | static void |
6115 | encode_arm_shifter_operand (int i) | |
6116 | { | |
6117 | if (inst.operands[i].isreg) | |
09d92015 | 6118 | { |
c19d1205 ZW |
6119 | inst.instruction |= inst.operands[i].reg; |
6120 | encode_arm_shift (i); | |
09d92015 | 6121 | } |
c19d1205 ZW |
6122 | else |
6123 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
6124 | } |
6125 | ||
c19d1205 | 6126 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 6127 | static void |
c19d1205 | 6128 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 6129 | { |
c19d1205 ZW |
6130 | assert (inst.operands[i].isreg); |
6131 | inst.instruction |= inst.operands[i].reg << 16; | |
a737bd4d | 6132 | |
c19d1205 | 6133 | if (inst.operands[i].preind) |
09d92015 | 6134 | { |
c19d1205 ZW |
6135 | if (is_t) |
6136 | { | |
6137 | inst.error = _("instruction does not accept preindexed addressing"); | |
6138 | return; | |
6139 | } | |
6140 | inst.instruction |= PRE_INDEX; | |
6141 | if (inst.operands[i].writeback) | |
6142 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6143 | |
c19d1205 ZW |
6144 | } |
6145 | else if (inst.operands[i].postind) | |
6146 | { | |
6147 | assert (inst.operands[i].writeback); | |
6148 | if (is_t) | |
6149 | inst.instruction |= WRITE_BACK; | |
6150 | } | |
6151 | else /* unindexed - only for coprocessor */ | |
09d92015 | 6152 | { |
c19d1205 | 6153 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
6154 | return; |
6155 | } | |
6156 | ||
c19d1205 ZW |
6157 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
6158 | && (((inst.instruction & 0x000f0000) >> 16) | |
6159 | == ((inst.instruction & 0x0000f000) >> 12))) | |
6160 | as_warn ((inst.instruction & LOAD_BIT) | |
6161 | ? _("destination register same as write-back base") | |
6162 | : _("source register same as write-back base")); | |
09d92015 MM |
6163 | } |
6164 | ||
c19d1205 ZW |
6165 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6166 | ARM-format mode 2 load or store instruction. If is_t is true, | |
6167 | reject forms that cannot be used with a T instruction (i.e. not | |
6168 | post-indexed). */ | |
a737bd4d | 6169 | static void |
c19d1205 | 6170 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 6171 | { |
c19d1205 | 6172 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6173 | |
c19d1205 | 6174 | if (inst.operands[i].immisreg) |
09d92015 | 6175 | { |
c19d1205 ZW |
6176 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
6177 | inst.instruction |= inst.operands[i].imm; | |
6178 | if (!inst.operands[i].negative) | |
6179 | inst.instruction |= INDEX_UP; | |
6180 | if (inst.operands[i].shifted) | |
6181 | { | |
6182 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
6183 | inst.instruction |= SHIFT_ROR << 5; | |
6184 | else | |
6185 | { | |
6186 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
6187 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
6188 | } | |
6189 | } | |
09d92015 | 6190 | } |
c19d1205 | 6191 | else /* immediate offset in inst.reloc */ |
09d92015 | 6192 | { |
c19d1205 ZW |
6193 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6194 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 6195 | } |
09d92015 MM |
6196 | } |
6197 | ||
c19d1205 ZW |
6198 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6199 | ARM-format mode 3 load or store instruction. Reject forms that | |
6200 | cannot be used with such instructions. If is_t is true, reject | |
6201 | forms that cannot be used with a T instruction (i.e. not | |
6202 | post-indexed). */ | |
6203 | static void | |
6204 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 6205 | { |
c19d1205 | 6206 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 6207 | { |
c19d1205 ZW |
6208 | inst.error = _("instruction does not accept scaled register index"); |
6209 | return; | |
09d92015 | 6210 | } |
a737bd4d | 6211 | |
c19d1205 | 6212 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6213 | |
c19d1205 ZW |
6214 | if (inst.operands[i].immisreg) |
6215 | { | |
6216 | inst.instruction |= inst.operands[i].imm; | |
6217 | if (!inst.operands[i].negative) | |
6218 | inst.instruction |= INDEX_UP; | |
6219 | } | |
6220 | else /* immediate offset in inst.reloc */ | |
6221 | { | |
6222 | inst.instruction |= HWOFFSET_IMM; | |
6223 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6224 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 6225 | } |
a737bd4d NC |
6226 | } |
6227 | ||
c19d1205 ZW |
6228 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6229 | ARM-format instruction. Reject all forms which cannot be encoded | |
6230 | into a coprocessor load/store instruction. If wb_ok is false, | |
6231 | reject use of writeback; if unind_ok is false, reject use of | |
6232 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
6233 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
6234 | (in which case it is preserved). */ | |
09d92015 | 6235 | |
c19d1205 ZW |
6236 | static int |
6237 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 6238 | { |
c19d1205 | 6239 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6240 | |
c19d1205 | 6241 | assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 6242 | |
c19d1205 | 6243 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 6244 | { |
c19d1205 ZW |
6245 | assert (!inst.operands[i].writeback); |
6246 | if (!unind_ok) | |
6247 | { | |
6248 | inst.error = _("instruction does not support unindexed addressing"); | |
6249 | return FAIL; | |
6250 | } | |
6251 | inst.instruction |= inst.operands[i].imm; | |
6252 | inst.instruction |= INDEX_UP; | |
6253 | return SUCCESS; | |
09d92015 | 6254 | } |
a737bd4d | 6255 | |
c19d1205 ZW |
6256 | if (inst.operands[i].preind) |
6257 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 6258 | |
c19d1205 | 6259 | if (inst.operands[i].writeback) |
09d92015 | 6260 | { |
c19d1205 ZW |
6261 | if (inst.operands[i].reg == REG_PC) |
6262 | { | |
6263 | inst.error = _("pc may not be used with write-back"); | |
6264 | return FAIL; | |
6265 | } | |
6266 | if (!wb_ok) | |
6267 | { | |
6268 | inst.error = _("instruction does not support writeback"); | |
6269 | return FAIL; | |
6270 | } | |
6271 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6272 | } |
a737bd4d | 6273 | |
c19d1205 ZW |
6274 | if (reloc_override) |
6275 | inst.reloc.type = reloc_override; | |
4962c51a MS |
6276 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
6277 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
6278 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
6279 | { | |
6280 | if (thumb_mode) | |
6281 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
6282 | else | |
6283 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
6284 | } | |
6285 | ||
c19d1205 ZW |
6286 | return SUCCESS; |
6287 | } | |
a737bd4d | 6288 | |
c19d1205 ZW |
6289 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
6290 | Determine whether it can be performed with a move instruction; if | |
6291 | it can, convert inst.instruction to that move instruction and | |
6292 | return 1; if it can't, convert inst.instruction to a literal-pool | |
6293 | load and return 0. If this is not a valid thing to do in the | |
6294 | current context, set inst.error and return 1. | |
a737bd4d | 6295 | |
c19d1205 ZW |
6296 | inst.operands[i] describes the destination register. */ |
6297 | ||
6298 | static int | |
6299 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) | |
6300 | { | |
53365c0d PB |
6301 | unsigned long tbit; |
6302 | ||
6303 | if (thumb_p) | |
6304 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
6305 | else | |
6306 | tbit = LOAD_BIT; | |
6307 | ||
6308 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 6309 | { |
c19d1205 ZW |
6310 | inst.error = _("invalid pseudo operation"); |
6311 | return 1; | |
09d92015 | 6312 | } |
c19d1205 | 6313 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
6314 | { |
6315 | inst.error = _("constant expression expected"); | |
c19d1205 | 6316 | return 1; |
09d92015 | 6317 | } |
c19d1205 | 6318 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 6319 | { |
c19d1205 ZW |
6320 | if (thumb_p) |
6321 | { | |
53365c0d | 6322 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
6323 | { |
6324 | /* This can be done with a mov(1) instruction. */ | |
6325 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
6326 | inst.instruction |= inst.reloc.exp.X_add_number; | |
6327 | return 1; | |
6328 | } | |
6329 | } | |
6330 | else | |
6331 | { | |
6332 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
6333 | if (value != FAIL) | |
6334 | { | |
6335 | /* This can be done with a mov instruction. */ | |
6336 | inst.instruction &= LITERAL_MASK; | |
6337 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
6338 | inst.instruction |= value & 0xfff; | |
6339 | return 1; | |
6340 | } | |
09d92015 | 6341 | |
c19d1205 ZW |
6342 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
6343 | if (value != FAIL) | |
6344 | { | |
6345 | /* This can be done with a mvn instruction. */ | |
6346 | inst.instruction &= LITERAL_MASK; | |
6347 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
6348 | inst.instruction |= value & 0xfff; | |
6349 | return 1; | |
6350 | } | |
6351 | } | |
09d92015 MM |
6352 | } |
6353 | ||
c19d1205 ZW |
6354 | if (add_to_lit_pool () == FAIL) |
6355 | { | |
6356 | inst.error = _("literal pool insertion failed"); | |
6357 | return 1; | |
6358 | } | |
6359 | inst.operands[1].reg = REG_PC; | |
6360 | inst.operands[1].isreg = 1; | |
6361 | inst.operands[1].preind = 1; | |
6362 | inst.reloc.pc_rel = 1; | |
6363 | inst.reloc.type = (thumb_p | |
6364 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
6365 | : (mode_3 | |
6366 | ? BFD_RELOC_ARM_HWLITERAL | |
6367 | : BFD_RELOC_ARM_LITERAL)); | |
6368 | return 0; | |
09d92015 MM |
6369 | } |
6370 | ||
c19d1205 ZW |
6371 | /* Functions for instruction encoding, sorted by subarchitecture. |
6372 | First some generics; their names are taken from the conventional | |
6373 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 6374 | |
a737bd4d | 6375 | static void |
c19d1205 | 6376 | do_noargs (void) |
09d92015 | 6377 | { |
c19d1205 | 6378 | } |
a737bd4d | 6379 | |
c19d1205 ZW |
6380 | static void |
6381 | do_rd (void) | |
6382 | { | |
6383 | inst.instruction |= inst.operands[0].reg << 12; | |
6384 | } | |
a737bd4d | 6385 | |
c19d1205 ZW |
6386 | static void |
6387 | do_rd_rm (void) | |
6388 | { | |
6389 | inst.instruction |= inst.operands[0].reg << 12; | |
6390 | inst.instruction |= inst.operands[1].reg; | |
6391 | } | |
09d92015 | 6392 | |
c19d1205 ZW |
6393 | static void |
6394 | do_rd_rn (void) | |
6395 | { | |
6396 | inst.instruction |= inst.operands[0].reg << 12; | |
6397 | inst.instruction |= inst.operands[1].reg << 16; | |
6398 | } | |
a737bd4d | 6399 | |
c19d1205 ZW |
6400 | static void |
6401 | do_rn_rd (void) | |
6402 | { | |
6403 | inst.instruction |= inst.operands[0].reg << 16; | |
6404 | inst.instruction |= inst.operands[1].reg << 12; | |
6405 | } | |
09d92015 | 6406 | |
c19d1205 ZW |
6407 | static void |
6408 | do_rd_rm_rn (void) | |
6409 | { | |
9a64e435 | 6410 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 6411 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 PB |
6412 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
6413 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
6414 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
6415 | inst.instruction |= inst.operands[0].reg << 12; |
6416 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 6417 | inst.instruction |= Rn << 16; |
c19d1205 | 6418 | } |
09d92015 | 6419 | |
c19d1205 ZW |
6420 | static void |
6421 | do_rd_rn_rm (void) | |
6422 | { | |
6423 | inst.instruction |= inst.operands[0].reg << 12; | |
6424 | inst.instruction |= inst.operands[1].reg << 16; | |
6425 | inst.instruction |= inst.operands[2].reg; | |
6426 | } | |
a737bd4d | 6427 | |
c19d1205 ZW |
6428 | static void |
6429 | do_rm_rd_rn (void) | |
6430 | { | |
6431 | inst.instruction |= inst.operands[0].reg; | |
6432 | inst.instruction |= inst.operands[1].reg << 12; | |
6433 | inst.instruction |= inst.operands[2].reg << 16; | |
6434 | } | |
09d92015 | 6435 | |
c19d1205 ZW |
6436 | static void |
6437 | do_imm0 (void) | |
6438 | { | |
6439 | inst.instruction |= inst.operands[0].imm; | |
6440 | } | |
09d92015 | 6441 | |
c19d1205 ZW |
6442 | static void |
6443 | do_rd_cpaddr (void) | |
6444 | { | |
6445 | inst.instruction |= inst.operands[0].reg << 12; | |
6446 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 6447 | } |
a737bd4d | 6448 | |
c19d1205 ZW |
6449 | /* ARM instructions, in alphabetical order by function name (except |
6450 | that wrapper functions appear immediately after the function they | |
6451 | wrap). */ | |
09d92015 | 6452 | |
c19d1205 ZW |
6453 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
6454 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
6455 | |
6456 | static void | |
c19d1205 | 6457 | do_adr (void) |
09d92015 | 6458 | { |
c19d1205 | 6459 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 6460 | |
c19d1205 ZW |
6461 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6462 | out to be negative. */ | |
6463 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 6464 | inst.reloc.pc_rel = 1; |
2fc8bdac | 6465 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 6466 | } |
b99bd4ef | 6467 | |
c19d1205 ZW |
6468 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
6469 | into a relative address of the form: | |
6470 | add rd, pc, #low(label-.-8)" | |
6471 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 6472 | |
c19d1205 ZW |
6473 | static void |
6474 | do_adrl (void) | |
6475 | { | |
6476 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 6477 | |
c19d1205 ZW |
6478 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6479 | out to be negative. */ | |
6480 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
6481 | inst.reloc.pc_rel = 1; |
6482 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 6483 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
6484 | } |
6485 | ||
b99bd4ef | 6486 | static void |
c19d1205 | 6487 | do_arit (void) |
b99bd4ef | 6488 | { |
c19d1205 ZW |
6489 | if (!inst.operands[1].present) |
6490 | inst.operands[1].reg = inst.operands[0].reg; | |
6491 | inst.instruction |= inst.operands[0].reg << 12; | |
6492 | inst.instruction |= inst.operands[1].reg << 16; | |
6493 | encode_arm_shifter_operand (2); | |
6494 | } | |
b99bd4ef | 6495 | |
62b3e311 PB |
6496 | static void |
6497 | do_barrier (void) | |
6498 | { | |
6499 | if (inst.operands[0].present) | |
6500 | { | |
6501 | constraint ((inst.instruction & 0xf0) != 0x40 | |
6502 | && inst.operands[0].imm != 0xf, | |
6503 | "bad barrier type"); | |
6504 | inst.instruction |= inst.operands[0].imm; | |
6505 | } | |
6506 | else | |
6507 | inst.instruction |= 0xf; | |
6508 | } | |
6509 | ||
c19d1205 ZW |
6510 | static void |
6511 | do_bfc (void) | |
6512 | { | |
6513 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
6514 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6515 | /* The instruction encoding stores the LSB and MSB, | |
6516 | not the LSB and width. */ | |
6517 | inst.instruction |= inst.operands[0].reg << 12; | |
6518 | inst.instruction |= inst.operands[1].imm << 7; | |
6519 | inst.instruction |= (msb - 1) << 16; | |
6520 | } | |
b99bd4ef | 6521 | |
c19d1205 ZW |
6522 | static void |
6523 | do_bfi (void) | |
6524 | { | |
6525 | unsigned int msb; | |
b99bd4ef | 6526 | |
c19d1205 ZW |
6527 | /* #0 in second position is alternative syntax for bfc, which is |
6528 | the same instruction but with REG_PC in the Rm field. */ | |
6529 | if (!inst.operands[1].isreg) | |
6530 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 6531 | |
c19d1205 ZW |
6532 | msb = inst.operands[2].imm + inst.operands[3].imm; |
6533 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6534 | /* The instruction encoding stores the LSB and MSB, | |
6535 | not the LSB and width. */ | |
6536 | inst.instruction |= inst.operands[0].reg << 12; | |
6537 | inst.instruction |= inst.operands[1].reg; | |
6538 | inst.instruction |= inst.operands[2].imm << 7; | |
6539 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
6540 | } |
6541 | ||
b99bd4ef | 6542 | static void |
c19d1205 | 6543 | do_bfx (void) |
b99bd4ef | 6544 | { |
c19d1205 ZW |
6545 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
6546 | _("bit-field extends past end of register")); | |
6547 | inst.instruction |= inst.operands[0].reg << 12; | |
6548 | inst.instruction |= inst.operands[1].reg; | |
6549 | inst.instruction |= inst.operands[2].imm << 7; | |
6550 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
6551 | } | |
09d92015 | 6552 | |
c19d1205 ZW |
6553 | /* ARM V5 breakpoint instruction (argument parse) |
6554 | BKPT <16 bit unsigned immediate> | |
6555 | Instruction is not conditional. | |
6556 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
6557 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 6558 | |
c19d1205 ZW |
6559 | static void |
6560 | do_bkpt (void) | |
6561 | { | |
6562 | /* Top 12 of 16 bits to bits 19:8. */ | |
6563 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 6564 | |
c19d1205 ZW |
6565 | /* Bottom 4 of 16 bits to bits 3:0. */ |
6566 | inst.instruction |= inst.operands[0].imm & 0xf; | |
6567 | } | |
09d92015 | 6568 | |
c19d1205 ZW |
6569 | static void |
6570 | encode_branch (int default_reloc) | |
6571 | { | |
6572 | if (inst.operands[0].hasreloc) | |
6573 | { | |
6574 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
6575 | _("the only suffix valid here is '(plt)'")); | |
6576 | inst.reloc.type = BFD_RELOC_ARM_PLT32; | |
c19d1205 | 6577 | } |
b99bd4ef | 6578 | else |
c19d1205 ZW |
6579 | { |
6580 | inst.reloc.type = default_reloc; | |
c19d1205 | 6581 | } |
2fc8bdac | 6582 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
6583 | } |
6584 | ||
b99bd4ef | 6585 | static void |
c19d1205 | 6586 | do_branch (void) |
b99bd4ef | 6587 | { |
39b41c9c PB |
6588 | #ifdef OBJ_ELF |
6589 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6590 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
6591 | else | |
6592 | #endif | |
6593 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
6594 | } | |
6595 | ||
6596 | static void | |
6597 | do_bl (void) | |
6598 | { | |
6599 | #ifdef OBJ_ELF | |
6600 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6601 | { | |
6602 | if (inst.cond == COND_ALWAYS) | |
6603 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
6604 | else | |
6605 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
6606 | } | |
6607 | else | |
6608 | #endif | |
6609 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 6610 | } |
b99bd4ef | 6611 | |
c19d1205 ZW |
6612 | /* ARM V5 branch-link-exchange instruction (argument parse) |
6613 | BLX <target_addr> ie BLX(1) | |
6614 | BLX{<condition>} <Rm> ie BLX(2) | |
6615 | Unfortunately, there are two different opcodes for this mnemonic. | |
6616 | So, the insns[].value is not used, and the code here zaps values | |
6617 | into inst.instruction. | |
6618 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 6619 | |
c19d1205 ZW |
6620 | static void |
6621 | do_blx (void) | |
6622 | { | |
6623 | if (inst.operands[0].isreg) | |
b99bd4ef | 6624 | { |
c19d1205 ZW |
6625 | /* Arg is a register; the opcode provided by insns[] is correct. |
6626 | It is not illegal to do "blx pc", just useless. */ | |
6627 | if (inst.operands[0].reg == REG_PC) | |
6628 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 6629 | |
c19d1205 ZW |
6630 | inst.instruction |= inst.operands[0].reg; |
6631 | } | |
6632 | else | |
b99bd4ef | 6633 | { |
c19d1205 ZW |
6634 | /* Arg is an address; this instruction cannot be executed |
6635 | conditionally, and the opcode must be adjusted. */ | |
6636 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
2fc8bdac | 6637 | inst.instruction = 0xfa000000; |
39b41c9c PB |
6638 | #ifdef OBJ_ELF |
6639 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6640 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
6641 | else | |
6642 | #endif | |
6643 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); | |
b99bd4ef | 6644 | } |
c19d1205 ZW |
6645 | } |
6646 | ||
6647 | static void | |
6648 | do_bx (void) | |
6649 | { | |
6650 | if (inst.operands[0].reg == REG_PC) | |
6651 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 6652 | |
c19d1205 | 6653 | inst.instruction |= inst.operands[0].reg; |
09d92015 MM |
6654 | } |
6655 | ||
c19d1205 ZW |
6656 | |
6657 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
6658 | |
6659 | static void | |
c19d1205 | 6660 | do_bxj (void) |
a737bd4d | 6661 | { |
c19d1205 ZW |
6662 | if (inst.operands[0].reg == REG_PC) |
6663 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
6664 | ||
6665 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
6666 | } |
6667 | ||
c19d1205 ZW |
6668 | /* Co-processor data operation: |
6669 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
6670 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
6671 | static void | |
6672 | do_cdp (void) | |
6673 | { | |
6674 | inst.instruction |= inst.operands[0].reg << 8; | |
6675 | inst.instruction |= inst.operands[1].imm << 20; | |
6676 | inst.instruction |= inst.operands[2].reg << 12; | |
6677 | inst.instruction |= inst.operands[3].reg << 16; | |
6678 | inst.instruction |= inst.operands[4].reg; | |
6679 | inst.instruction |= inst.operands[5].imm << 5; | |
6680 | } | |
a737bd4d NC |
6681 | |
6682 | static void | |
c19d1205 | 6683 | do_cmp (void) |
a737bd4d | 6684 | { |
c19d1205 ZW |
6685 | inst.instruction |= inst.operands[0].reg << 16; |
6686 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
6687 | } |
6688 | ||
c19d1205 ZW |
6689 | /* Transfer between coprocessor and ARM registers. |
6690 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
6691 | MRC2 | |
6692 | MCR{cond} | |
6693 | MCR2 | |
6694 | ||
6695 | No special properties. */ | |
09d92015 MM |
6696 | |
6697 | static void | |
c19d1205 | 6698 | do_co_reg (void) |
09d92015 | 6699 | { |
c19d1205 ZW |
6700 | inst.instruction |= inst.operands[0].reg << 8; |
6701 | inst.instruction |= inst.operands[1].imm << 21; | |
6702 | inst.instruction |= inst.operands[2].reg << 12; | |
6703 | inst.instruction |= inst.operands[3].reg << 16; | |
6704 | inst.instruction |= inst.operands[4].reg; | |
6705 | inst.instruction |= inst.operands[5].imm << 5; | |
6706 | } | |
09d92015 | 6707 | |
c19d1205 ZW |
6708 | /* Transfer between coprocessor register and pair of ARM registers. |
6709 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
6710 | MCRR2 | |
6711 | MRRC{cond} | |
6712 | MRRC2 | |
b99bd4ef | 6713 | |
c19d1205 | 6714 | Two XScale instructions are special cases of these: |
09d92015 | 6715 | |
c19d1205 ZW |
6716 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
6717 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 6718 | |
c19d1205 | 6719 | Result unpredicatable if Rd or Rn is R15. */ |
a737bd4d | 6720 | |
c19d1205 ZW |
6721 | static void |
6722 | do_co_reg2c (void) | |
6723 | { | |
6724 | inst.instruction |= inst.operands[0].reg << 8; | |
6725 | inst.instruction |= inst.operands[1].imm << 4; | |
6726 | inst.instruction |= inst.operands[2].reg << 12; | |
6727 | inst.instruction |= inst.operands[3].reg << 16; | |
6728 | inst.instruction |= inst.operands[4].reg; | |
b99bd4ef NC |
6729 | } |
6730 | ||
c19d1205 ZW |
6731 | static void |
6732 | do_cpsi (void) | |
6733 | { | |
6734 | inst.instruction |= inst.operands[0].imm << 6; | |
6735 | inst.instruction |= inst.operands[1].imm; | |
6736 | } | |
b99bd4ef | 6737 | |
62b3e311 PB |
6738 | static void |
6739 | do_dbg (void) | |
6740 | { | |
6741 | inst.instruction |= inst.operands[0].imm; | |
6742 | } | |
6743 | ||
b99bd4ef | 6744 | static void |
c19d1205 | 6745 | do_it (void) |
b99bd4ef | 6746 | { |
c19d1205 ZW |
6747 | /* There is no IT instruction in ARM mode. We |
6748 | process it but do not generate code for it. */ | |
6749 | inst.size = 0; | |
09d92015 | 6750 | } |
b99bd4ef | 6751 | |
09d92015 | 6752 | static void |
c19d1205 | 6753 | do_ldmstm (void) |
ea6ef066 | 6754 | { |
c19d1205 ZW |
6755 | int base_reg = inst.operands[0].reg; |
6756 | int range = inst.operands[1].imm; | |
ea6ef066 | 6757 | |
c19d1205 ZW |
6758 | inst.instruction |= base_reg << 16; |
6759 | inst.instruction |= range; | |
ea6ef066 | 6760 | |
c19d1205 ZW |
6761 | if (inst.operands[1].writeback) |
6762 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 6763 | |
c19d1205 | 6764 | if (inst.operands[0].writeback) |
ea6ef066 | 6765 | { |
c19d1205 ZW |
6766 | inst.instruction |= WRITE_BACK; |
6767 | /* Check for unpredictable uses of writeback. */ | |
6768 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 6769 | { |
c19d1205 ZW |
6770 | /* Not allowed in LDM type 2. */ |
6771 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
6772 | && ((range & (1 << REG_PC)) == 0)) | |
6773 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
6774 | /* Only allowed if base reg not in list for other types. */ | |
6775 | else if (range & (1 << base_reg)) | |
6776 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
6777 | } | |
6778 | else /* STM. */ | |
6779 | { | |
6780 | /* Not allowed for type 2. */ | |
6781 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
6782 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
6783 | /* Only allowed if base reg not in list, or first in list. */ | |
6784 | else if ((range & (1 << base_reg)) | |
6785 | && (range & ((1 << base_reg) - 1))) | |
6786 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 6787 | } |
ea6ef066 | 6788 | } |
a737bd4d NC |
6789 | } |
6790 | ||
c19d1205 ZW |
6791 | /* ARMv5TE load-consecutive (argument parse) |
6792 | Mode is like LDRH. | |
6793 | ||
6794 | LDRccD R, mode | |
6795 | STRccD R, mode. */ | |
6796 | ||
a737bd4d | 6797 | static void |
c19d1205 | 6798 | do_ldrd (void) |
a737bd4d | 6799 | { |
c19d1205 ZW |
6800 | constraint (inst.operands[0].reg % 2 != 0, |
6801 | _("first destination register must be even")); | |
6802 | constraint (inst.operands[1].present | |
6803 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
6804 | _("can only load two consecutive registers")); | |
6805 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
6806 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 6807 | |
c19d1205 ZW |
6808 | if (!inst.operands[1].present) |
6809 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
6810 | ||
6811 | if (inst.instruction & LOAD_BIT) | |
a737bd4d | 6812 | { |
c19d1205 ZW |
6813 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
6814 | register and the first register written; we have to diagnose | |
6815 | overlap between the base and the second register written here. */ | |
ea6ef066 | 6816 | |
c19d1205 ZW |
6817 | if (inst.operands[2].reg == inst.operands[1].reg |
6818 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
6819 | as_warn (_("base register written back, and overlaps " | |
6820 | "second destination register")); | |
b05fe5cf | 6821 | |
c19d1205 ZW |
6822 | /* For an index-register load, the index register must not overlap the |
6823 | destination (even if not write-back). */ | |
6824 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
6825 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
6826 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 6827 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 6828 | } |
c19d1205 ZW |
6829 | |
6830 | inst.instruction |= inst.operands[0].reg << 12; | |
6831 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
6832 | } |
6833 | ||
6834 | static void | |
c19d1205 | 6835 | do_ldrex (void) |
b05fe5cf | 6836 | { |
c19d1205 ZW |
6837 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
6838 | || inst.operands[1].postind || inst.operands[1].writeback | |
6839 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
6840 | || inst.operands[1].negative |
6841 | /* This can arise if the programmer has written | |
6842 | strex rN, rM, foo | |
6843 | or if they have mistakenly used a register name as the last | |
6844 | operand, eg: | |
6845 | strex rN, rM, rX | |
6846 | It is very difficult to distinguish between these two cases | |
6847 | because "rX" might actually be a label. ie the register | |
6848 | name has been occluded by a symbol of the same name. So we | |
6849 | just generate a general 'bad addressing mode' type error | |
6850 | message and leave it up to the programmer to discover the | |
6851 | true cause and fix their mistake. */ | |
6852 | || (inst.operands[1].reg == REG_PC), | |
6853 | BAD_ADDR_MODE); | |
b05fe5cf | 6854 | |
c19d1205 ZW |
6855 | constraint (inst.reloc.exp.X_op != O_constant |
6856 | || inst.reloc.exp.X_add_number != 0, | |
6857 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 6858 | |
c19d1205 ZW |
6859 | inst.instruction |= inst.operands[0].reg << 12; |
6860 | inst.instruction |= inst.operands[1].reg << 16; | |
6861 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
6862 | } |
6863 | ||
6864 | static void | |
c19d1205 | 6865 | do_ldrexd (void) |
b05fe5cf | 6866 | { |
c19d1205 ZW |
6867 | constraint (inst.operands[0].reg % 2 != 0, |
6868 | _("even register required")); | |
6869 | constraint (inst.operands[1].present | |
6870 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
6871 | _("can only load two consecutive registers")); | |
6872 | /* If op 1 were present and equal to PC, this function wouldn't | |
6873 | have been called in the first place. */ | |
6874 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 6875 | |
c19d1205 ZW |
6876 | inst.instruction |= inst.operands[0].reg << 12; |
6877 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
6878 | } |
6879 | ||
6880 | static void | |
c19d1205 | 6881 | do_ldst (void) |
b05fe5cf | 6882 | { |
c19d1205 ZW |
6883 | inst.instruction |= inst.operands[0].reg << 12; |
6884 | if (!inst.operands[1].isreg) | |
6885 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 6886 | return; |
c19d1205 | 6887 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
6888 | } |
6889 | ||
6890 | static void | |
c19d1205 | 6891 | do_ldstt (void) |
b05fe5cf | 6892 | { |
c19d1205 ZW |
6893 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
6894 | reject [Rn,...]. */ | |
6895 | if (inst.operands[1].preind) | |
b05fe5cf | 6896 | { |
c19d1205 ZW |
6897 | constraint (inst.reloc.exp.X_op != O_constant || |
6898 | inst.reloc.exp.X_add_number != 0, | |
6899 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 6900 | |
c19d1205 ZW |
6901 | inst.operands[1].preind = 0; |
6902 | inst.operands[1].postind = 1; | |
6903 | inst.operands[1].writeback = 1; | |
b05fe5cf | 6904 | } |
c19d1205 ZW |
6905 | inst.instruction |= inst.operands[0].reg << 12; |
6906 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
6907 | } | |
b05fe5cf | 6908 | |
c19d1205 | 6909 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 6910 | |
c19d1205 ZW |
6911 | static void |
6912 | do_ldstv4 (void) | |
6913 | { | |
6914 | inst.instruction |= inst.operands[0].reg << 12; | |
6915 | if (!inst.operands[1].isreg) | |
6916 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 6917 | return; |
c19d1205 | 6918 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
6919 | } |
6920 | ||
6921 | static void | |
c19d1205 | 6922 | do_ldsttv4 (void) |
b05fe5cf | 6923 | { |
c19d1205 ZW |
6924 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
6925 | reject [Rn,...]. */ | |
6926 | if (inst.operands[1].preind) | |
b05fe5cf | 6927 | { |
c19d1205 ZW |
6928 | constraint (inst.reloc.exp.X_op != O_constant || |
6929 | inst.reloc.exp.X_add_number != 0, | |
6930 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 6931 | |
c19d1205 ZW |
6932 | inst.operands[1].preind = 0; |
6933 | inst.operands[1].postind = 1; | |
6934 | inst.operands[1].writeback = 1; | |
b05fe5cf | 6935 | } |
c19d1205 ZW |
6936 | inst.instruction |= inst.operands[0].reg << 12; |
6937 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
6938 | } | |
b05fe5cf | 6939 | |
c19d1205 ZW |
6940 | /* Co-processor register load/store. |
6941 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
6942 | static void | |
6943 | do_lstc (void) | |
6944 | { | |
6945 | inst.instruction |= inst.operands[0].reg << 8; | |
6946 | inst.instruction |= inst.operands[1].reg << 12; | |
6947 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
6948 | } |
6949 | ||
b05fe5cf | 6950 | static void |
c19d1205 | 6951 | do_mlas (void) |
b05fe5cf | 6952 | { |
c19d1205 ZW |
6953 | /* This restriction does not apply to mls (nor to mla in v6, but |
6954 | that's hard to detect at present). */ | |
6955 | if (inst.operands[0].reg == inst.operands[1].reg | |
6956 | && !(inst.instruction & 0x00400000)) | |
6957 | as_tsktsk (_("rd and rm should be different in mla")); | |
b05fe5cf | 6958 | |
c19d1205 ZW |
6959 | inst.instruction |= inst.operands[0].reg << 16; |
6960 | inst.instruction |= inst.operands[1].reg; | |
6961 | inst.instruction |= inst.operands[2].reg << 8; | |
6962 | inst.instruction |= inst.operands[3].reg << 12; | |
b05fe5cf | 6963 | |
c19d1205 | 6964 | } |
b05fe5cf | 6965 | |
c19d1205 ZW |
6966 | static void |
6967 | do_mov (void) | |
6968 | { | |
6969 | inst.instruction |= inst.operands[0].reg << 12; | |
6970 | encode_arm_shifter_operand (1); | |
6971 | } | |
b05fe5cf | 6972 | |
c19d1205 ZW |
6973 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
6974 | static void | |
6975 | do_mov16 (void) | |
6976 | { | |
b6895b4f PB |
6977 | bfd_vma imm; |
6978 | bfd_boolean top; | |
6979 | ||
6980 | top = (inst.instruction & 0x00400000) != 0; | |
6981 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
6982 | _(":lower16: not allowed this instruction")); | |
6983 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
6984 | _(":upper16: not allowed instruction")); | |
c19d1205 | 6985 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
6986 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6987 | { | |
6988 | imm = inst.reloc.exp.X_add_number; | |
6989 | /* The value is in two pieces: 0:11, 16:19. */ | |
6990 | inst.instruction |= (imm & 0x00000fff); | |
6991 | inst.instruction |= (imm & 0x0000f000) << 4; | |
6992 | } | |
b05fe5cf | 6993 | } |
b99bd4ef | 6994 | |
037e8744 JB |
6995 | static void do_vfp_nsyn_opcode (const char *); |
6996 | ||
6997 | static int | |
6998 | do_vfp_nsyn_mrs (void) | |
6999 | { | |
7000 | if (inst.operands[0].isvec) | |
7001 | { | |
7002 | if (inst.operands[1].reg != 1) | |
7003 | first_error (_("operand 1 must be FPSCR")); | |
7004 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
7005 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
7006 | do_vfp_nsyn_opcode ("fmstat"); | |
7007 | } | |
7008 | else if (inst.operands[1].isvec) | |
7009 | do_vfp_nsyn_opcode ("fmrx"); | |
7010 | else | |
7011 | return FAIL; | |
7012 | ||
7013 | return SUCCESS; | |
7014 | } | |
7015 | ||
7016 | static int | |
7017 | do_vfp_nsyn_msr (void) | |
7018 | { | |
7019 | if (inst.operands[0].isvec) | |
7020 | do_vfp_nsyn_opcode ("fmxr"); | |
7021 | else | |
7022 | return FAIL; | |
7023 | ||
7024 | return SUCCESS; | |
7025 | } | |
7026 | ||
b99bd4ef | 7027 | static void |
c19d1205 | 7028 | do_mrs (void) |
b99bd4ef | 7029 | { |
037e8744 JB |
7030 | if (do_vfp_nsyn_mrs () == SUCCESS) |
7031 | return; | |
7032 | ||
c19d1205 ZW |
7033 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
7034 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7035 | != (PSR_c|PSR_f), | |
7036 | _("'CPSR' or 'SPSR' expected")); | |
7037 | inst.instruction |= inst.operands[0].reg << 12; | |
7038 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
7039 | } | |
b99bd4ef | 7040 | |
c19d1205 ZW |
7041 | /* Two possible forms: |
7042 | "{C|S}PSR_<field>, Rm", | |
7043 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 7044 | |
c19d1205 ZW |
7045 | static void |
7046 | do_msr (void) | |
7047 | { | |
037e8744 JB |
7048 | if (do_vfp_nsyn_msr () == SUCCESS) |
7049 | return; | |
7050 | ||
c19d1205 ZW |
7051 | inst.instruction |= inst.operands[0].imm; |
7052 | if (inst.operands[1].isreg) | |
7053 | inst.instruction |= inst.operands[1].reg; | |
7054 | else | |
b99bd4ef | 7055 | { |
c19d1205 ZW |
7056 | inst.instruction |= INST_IMMEDIATE; |
7057 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
7058 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 7059 | } |
b99bd4ef NC |
7060 | } |
7061 | ||
c19d1205 ZW |
7062 | static void |
7063 | do_mul (void) | |
a737bd4d | 7064 | { |
c19d1205 ZW |
7065 | if (!inst.operands[2].present) |
7066 | inst.operands[2].reg = inst.operands[0].reg; | |
7067 | inst.instruction |= inst.operands[0].reg << 16; | |
7068 | inst.instruction |= inst.operands[1].reg; | |
7069 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 7070 | |
c19d1205 ZW |
7071 | if (inst.operands[0].reg == inst.operands[1].reg) |
7072 | as_tsktsk (_("rd and rm should be different in mul")); | |
a737bd4d NC |
7073 | } |
7074 | ||
c19d1205 ZW |
7075 | /* Long Multiply Parser |
7076 | UMULL RdLo, RdHi, Rm, Rs | |
7077 | SMULL RdLo, RdHi, Rm, Rs | |
7078 | UMLAL RdLo, RdHi, Rm, Rs | |
7079 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
7080 | |
7081 | static void | |
c19d1205 | 7082 | do_mull (void) |
b99bd4ef | 7083 | { |
c19d1205 ZW |
7084 | inst.instruction |= inst.operands[0].reg << 12; |
7085 | inst.instruction |= inst.operands[1].reg << 16; | |
7086 | inst.instruction |= inst.operands[2].reg; | |
7087 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 7088 | |
c19d1205 ZW |
7089 | /* rdhi, rdlo and rm must all be different. */ |
7090 | if (inst.operands[0].reg == inst.operands[1].reg | |
7091 | || inst.operands[0].reg == inst.operands[2].reg | |
7092 | || inst.operands[1].reg == inst.operands[2].reg) | |
7093 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); | |
7094 | } | |
b99bd4ef | 7095 | |
c19d1205 ZW |
7096 | static void |
7097 | do_nop (void) | |
7098 | { | |
7099 | if (inst.operands[0].present) | |
7100 | { | |
7101 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
7102 | inst.instruction &= 0xf0000000; | |
7103 | inst.instruction |= 0x0320f000 + inst.operands[0].imm; | |
7104 | } | |
b99bd4ef NC |
7105 | } |
7106 | ||
c19d1205 ZW |
7107 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
7108 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
7109 | Condition defaults to COND_ALWAYS. | |
7110 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
7111 | |
7112 | static void | |
c19d1205 | 7113 | do_pkhbt (void) |
b99bd4ef | 7114 | { |
c19d1205 ZW |
7115 | inst.instruction |= inst.operands[0].reg << 12; |
7116 | inst.instruction |= inst.operands[1].reg << 16; | |
7117 | inst.instruction |= inst.operands[2].reg; | |
7118 | if (inst.operands[3].present) | |
7119 | encode_arm_shift (3); | |
7120 | } | |
b99bd4ef | 7121 | |
c19d1205 | 7122 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 7123 | |
c19d1205 ZW |
7124 | static void |
7125 | do_pkhtb (void) | |
7126 | { | |
7127 | if (!inst.operands[3].present) | |
b99bd4ef | 7128 | { |
c19d1205 ZW |
7129 | /* If the shift specifier is omitted, turn the instruction |
7130 | into pkhbt rd, rm, rn. */ | |
7131 | inst.instruction &= 0xfff00010; | |
7132 | inst.instruction |= inst.operands[0].reg << 12; | |
7133 | inst.instruction |= inst.operands[1].reg; | |
7134 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7135 | } |
7136 | else | |
7137 | { | |
c19d1205 ZW |
7138 | inst.instruction |= inst.operands[0].reg << 12; |
7139 | inst.instruction |= inst.operands[1].reg << 16; | |
7140 | inst.instruction |= inst.operands[2].reg; | |
7141 | encode_arm_shift (3); | |
b99bd4ef NC |
7142 | } |
7143 | } | |
7144 | ||
c19d1205 ZW |
7145 | /* ARMv5TE: Preload-Cache |
7146 | ||
7147 | PLD <addr_mode> | |
7148 | ||
7149 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
7150 | |
7151 | static void | |
c19d1205 | 7152 | do_pld (void) |
b99bd4ef | 7153 | { |
c19d1205 ZW |
7154 | constraint (!inst.operands[0].isreg, |
7155 | _("'[' expected after PLD mnemonic")); | |
7156 | constraint (inst.operands[0].postind, | |
7157 | _("post-indexed expression used in preload instruction")); | |
7158 | constraint (inst.operands[0].writeback, | |
7159 | _("writeback used in preload instruction")); | |
7160 | constraint (!inst.operands[0].preind, | |
7161 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
7162 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
7163 | } | |
b99bd4ef | 7164 | |
62b3e311 PB |
7165 | /* ARMv7: PLI <addr_mode> */ |
7166 | static void | |
7167 | do_pli (void) | |
7168 | { | |
7169 | constraint (!inst.operands[0].isreg, | |
7170 | _("'[' expected after PLI mnemonic")); | |
7171 | constraint (inst.operands[0].postind, | |
7172 | _("post-indexed expression used in preload instruction")); | |
7173 | constraint (inst.operands[0].writeback, | |
7174 | _("writeback used in preload instruction")); | |
7175 | constraint (!inst.operands[0].preind, | |
7176 | _("unindexed addressing used in preload instruction")); | |
7177 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
7178 | inst.instruction &= ~PRE_INDEX; | |
7179 | } | |
7180 | ||
c19d1205 ZW |
7181 | static void |
7182 | do_push_pop (void) | |
7183 | { | |
7184 | inst.operands[1] = inst.operands[0]; | |
7185 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
7186 | inst.operands[0].isreg = 1; | |
7187 | inst.operands[0].writeback = 1; | |
7188 | inst.operands[0].reg = REG_SP; | |
7189 | do_ldmstm (); | |
7190 | } | |
b99bd4ef | 7191 | |
c19d1205 ZW |
7192 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
7193 | word at the specified address and the following word | |
7194 | respectively. | |
7195 | Unconditionally executed. | |
7196 | Error if Rn is R15. */ | |
b99bd4ef | 7197 | |
c19d1205 ZW |
7198 | static void |
7199 | do_rfe (void) | |
7200 | { | |
7201 | inst.instruction |= inst.operands[0].reg << 16; | |
7202 | if (inst.operands[0].writeback) | |
7203 | inst.instruction |= WRITE_BACK; | |
7204 | } | |
b99bd4ef | 7205 | |
c19d1205 | 7206 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 7207 | |
c19d1205 ZW |
7208 | static void |
7209 | do_ssat (void) | |
7210 | { | |
7211 | inst.instruction |= inst.operands[0].reg << 12; | |
7212 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
7213 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7214 | |
c19d1205 ZW |
7215 | if (inst.operands[3].present) |
7216 | encode_arm_shift (3); | |
b99bd4ef NC |
7217 | } |
7218 | ||
c19d1205 | 7219 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
7220 | |
7221 | static void | |
c19d1205 | 7222 | do_usat (void) |
b99bd4ef | 7223 | { |
c19d1205 ZW |
7224 | inst.instruction |= inst.operands[0].reg << 12; |
7225 | inst.instruction |= inst.operands[1].imm << 16; | |
7226 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7227 | |
c19d1205 ZW |
7228 | if (inst.operands[3].present) |
7229 | encode_arm_shift (3); | |
b99bd4ef NC |
7230 | } |
7231 | ||
c19d1205 | 7232 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
7233 | |
7234 | static void | |
c19d1205 | 7235 | do_ssat16 (void) |
09d92015 | 7236 | { |
c19d1205 ZW |
7237 | inst.instruction |= inst.operands[0].reg << 12; |
7238 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
7239 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
7240 | } |
7241 | ||
c19d1205 ZW |
7242 | static void |
7243 | do_usat16 (void) | |
a737bd4d | 7244 | { |
c19d1205 ZW |
7245 | inst.instruction |= inst.operands[0].reg << 12; |
7246 | inst.instruction |= inst.operands[1].imm << 16; | |
7247 | inst.instruction |= inst.operands[2].reg; | |
7248 | } | |
a737bd4d | 7249 | |
c19d1205 ZW |
7250 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
7251 | preserving the other bits. | |
a737bd4d | 7252 | |
c19d1205 ZW |
7253 | setend <endian_specifier>, where <endian_specifier> is either |
7254 | BE or LE. */ | |
a737bd4d | 7255 | |
c19d1205 ZW |
7256 | static void |
7257 | do_setend (void) | |
7258 | { | |
7259 | if (inst.operands[0].imm) | |
7260 | inst.instruction |= 0x200; | |
a737bd4d NC |
7261 | } |
7262 | ||
7263 | static void | |
c19d1205 | 7264 | do_shift (void) |
a737bd4d | 7265 | { |
c19d1205 ZW |
7266 | unsigned int Rm = (inst.operands[1].present |
7267 | ? inst.operands[1].reg | |
7268 | : inst.operands[0].reg); | |
a737bd4d | 7269 | |
c19d1205 ZW |
7270 | inst.instruction |= inst.operands[0].reg << 12; |
7271 | inst.instruction |= Rm; | |
7272 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 7273 | { |
c19d1205 ZW |
7274 | inst.instruction |= inst.operands[2].reg << 8; |
7275 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
7276 | } |
7277 | else | |
c19d1205 | 7278 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
7279 | } |
7280 | ||
09d92015 | 7281 | static void |
3eb17e6b | 7282 | do_smc (void) |
09d92015 | 7283 | { |
3eb17e6b | 7284 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 7285 | inst.reloc.pc_rel = 0; |
09d92015 MM |
7286 | } |
7287 | ||
09d92015 | 7288 | static void |
c19d1205 | 7289 | do_swi (void) |
09d92015 | 7290 | { |
c19d1205 ZW |
7291 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
7292 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
7293 | } |
7294 | ||
c19d1205 ZW |
7295 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
7296 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
7297 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
7298 | Error if any register is R15. */ | |
e16bb312 | 7299 | |
c19d1205 ZW |
7300 | static void |
7301 | do_smla (void) | |
e16bb312 | 7302 | { |
c19d1205 ZW |
7303 | inst.instruction |= inst.operands[0].reg << 16; |
7304 | inst.instruction |= inst.operands[1].reg; | |
7305 | inst.instruction |= inst.operands[2].reg << 8; | |
7306 | inst.instruction |= inst.operands[3].reg << 12; | |
7307 | } | |
a737bd4d | 7308 | |
c19d1205 ZW |
7309 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
7310 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
7311 | Error if any register is R15. | |
7312 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 7313 | |
c19d1205 ZW |
7314 | static void |
7315 | do_smlal (void) | |
7316 | { | |
7317 | inst.instruction |= inst.operands[0].reg << 12; | |
7318 | inst.instruction |= inst.operands[1].reg << 16; | |
7319 | inst.instruction |= inst.operands[2].reg; | |
7320 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 7321 | |
c19d1205 ZW |
7322 | if (inst.operands[0].reg == inst.operands[1].reg) |
7323 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7324 | } | |
a737bd4d | 7325 | |
c19d1205 ZW |
7326 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
7327 | SMULxy{cond} Rd,Rm,Rs | |
7328 | Error if any register is R15. */ | |
a737bd4d | 7329 | |
c19d1205 ZW |
7330 | static void |
7331 | do_smul (void) | |
7332 | { | |
7333 | inst.instruction |= inst.operands[0].reg << 16; | |
7334 | inst.instruction |= inst.operands[1].reg; | |
7335 | inst.instruction |= inst.operands[2].reg << 8; | |
7336 | } | |
a737bd4d | 7337 | |
c19d1205 | 7338 | /* ARM V6 srs (argument parse). */ |
a737bd4d | 7339 | |
c19d1205 ZW |
7340 | static void |
7341 | do_srs (void) | |
7342 | { | |
7343 | inst.instruction |= inst.operands[0].imm; | |
7344 | if (inst.operands[0].writeback) | |
7345 | inst.instruction |= WRITE_BACK; | |
7346 | } | |
a737bd4d | 7347 | |
c19d1205 | 7348 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 7349 | |
c19d1205 ZW |
7350 | static void |
7351 | do_strex (void) | |
7352 | { | |
7353 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7354 | || inst.operands[2].postind || inst.operands[2].writeback | |
7355 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
7356 | || inst.operands[2].negative |
7357 | /* See comment in do_ldrex(). */ | |
7358 | || (inst.operands[2].reg == REG_PC), | |
7359 | BAD_ADDR_MODE); | |
a737bd4d | 7360 | |
c19d1205 ZW |
7361 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7362 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 7363 | |
c19d1205 ZW |
7364 | constraint (inst.reloc.exp.X_op != O_constant |
7365 | || inst.reloc.exp.X_add_number != 0, | |
7366 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 7367 | |
c19d1205 ZW |
7368 | inst.instruction |= inst.operands[0].reg << 12; |
7369 | inst.instruction |= inst.operands[1].reg; | |
7370 | inst.instruction |= inst.operands[2].reg << 16; | |
7371 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
7372 | } |
7373 | ||
7374 | static void | |
c19d1205 | 7375 | do_strexd (void) |
e16bb312 | 7376 | { |
c19d1205 ZW |
7377 | constraint (inst.operands[1].reg % 2 != 0, |
7378 | _("even register required")); | |
7379 | constraint (inst.operands[2].present | |
7380 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
7381 | _("can only store two consecutive registers")); | |
7382 | /* If op 2 were present and equal to PC, this function wouldn't | |
7383 | have been called in the first place. */ | |
7384 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 7385 | |
c19d1205 ZW |
7386 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7387 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
7388 | || inst.operands[0].reg == inst.operands[3].reg, | |
7389 | BAD_OVERLAP); | |
e16bb312 | 7390 | |
c19d1205 ZW |
7391 | inst.instruction |= inst.operands[0].reg << 12; |
7392 | inst.instruction |= inst.operands[1].reg; | |
7393 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
7394 | } |
7395 | ||
c19d1205 ZW |
7396 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
7397 | extends it to 32-bits, and adds the result to a value in another | |
7398 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
7399 | before extracting the 16-bit value. | |
7400 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
7401 | Condition defaults to COND_ALWAYS. | |
7402 | Error if any register uses R15. */ | |
7403 | ||
e16bb312 | 7404 | static void |
c19d1205 | 7405 | do_sxtah (void) |
e16bb312 | 7406 | { |
c19d1205 ZW |
7407 | inst.instruction |= inst.operands[0].reg << 12; |
7408 | inst.instruction |= inst.operands[1].reg << 16; | |
7409 | inst.instruction |= inst.operands[2].reg; | |
7410 | inst.instruction |= inst.operands[3].imm << 10; | |
7411 | } | |
e16bb312 | 7412 | |
c19d1205 | 7413 | /* ARM V6 SXTH. |
e16bb312 | 7414 | |
c19d1205 ZW |
7415 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
7416 | Condition defaults to COND_ALWAYS. | |
7417 | Error if any register uses R15. */ | |
e16bb312 NC |
7418 | |
7419 | static void | |
c19d1205 | 7420 | do_sxth (void) |
e16bb312 | 7421 | { |
c19d1205 ZW |
7422 | inst.instruction |= inst.operands[0].reg << 12; |
7423 | inst.instruction |= inst.operands[1].reg; | |
7424 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 7425 | } |
c19d1205 ZW |
7426 | \f |
7427 | /* VFP instructions. In a logical order: SP variant first, monad | |
7428 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
7429 | |
7430 | static void | |
c19d1205 | 7431 | do_vfp_sp_monadic (void) |
e16bb312 | 7432 | { |
5287ad62 JB |
7433 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7434 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
7435 | } |
7436 | ||
7437 | static void | |
c19d1205 | 7438 | do_vfp_sp_dyadic (void) |
e16bb312 | 7439 | { |
5287ad62 JB |
7440 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7441 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
7442 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
7443 | } |
7444 | ||
7445 | static void | |
c19d1205 | 7446 | do_vfp_sp_compare_z (void) |
e16bb312 | 7447 | { |
5287ad62 | 7448 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
7449 | } |
7450 | ||
7451 | static void | |
c19d1205 | 7452 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 7453 | { |
5287ad62 JB |
7454 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
7455 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
7456 | } |
7457 | ||
7458 | static void | |
c19d1205 | 7459 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 7460 | { |
5287ad62 JB |
7461 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7462 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
7463 | } |
7464 | ||
7465 | static void | |
c19d1205 | 7466 | do_vfp_reg_from_sp (void) |
e16bb312 | 7467 | { |
c19d1205 | 7468 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 7469 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
7470 | } |
7471 | ||
7472 | static void | |
c19d1205 | 7473 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 7474 | { |
c19d1205 ZW |
7475 | constraint (inst.operands[2].imm != 2, |
7476 | _("only two consecutive VFP SP registers allowed here")); | |
7477 | inst.instruction |= inst.operands[0].reg << 12; | |
7478 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 7479 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
7480 | } |
7481 | ||
7482 | static void | |
c19d1205 | 7483 | do_vfp_sp_from_reg (void) |
e16bb312 | 7484 | { |
5287ad62 | 7485 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 7486 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
7487 | } |
7488 | ||
7489 | static void | |
c19d1205 | 7490 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 7491 | { |
c19d1205 ZW |
7492 | constraint (inst.operands[0].imm != 2, |
7493 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 7494 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
7495 | inst.instruction |= inst.operands[1].reg << 12; |
7496 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
7497 | } |
7498 | ||
7499 | static void | |
c19d1205 | 7500 | do_vfp_sp_ldst (void) |
e16bb312 | 7501 | { |
5287ad62 | 7502 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 7503 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
7504 | } |
7505 | ||
7506 | static void | |
c19d1205 | 7507 | do_vfp_dp_ldst (void) |
e16bb312 | 7508 | { |
5287ad62 | 7509 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 7510 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
7511 | } |
7512 | ||
c19d1205 | 7513 | |
e16bb312 | 7514 | static void |
c19d1205 | 7515 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 7516 | { |
c19d1205 ZW |
7517 | if (inst.operands[0].writeback) |
7518 | inst.instruction |= WRITE_BACK; | |
7519 | else | |
7520 | constraint (ldstm_type != VFP_LDSTMIA, | |
7521 | _("this addressing mode requires base-register writeback")); | |
7522 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 7523 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 7524 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
7525 | } |
7526 | ||
7527 | static void | |
c19d1205 | 7528 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 7529 | { |
c19d1205 | 7530 | int count; |
e16bb312 | 7531 | |
c19d1205 ZW |
7532 | if (inst.operands[0].writeback) |
7533 | inst.instruction |= WRITE_BACK; | |
7534 | else | |
7535 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
7536 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 7537 | |
c19d1205 | 7538 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 7539 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 7540 | |
c19d1205 ZW |
7541 | count = inst.operands[1].imm << 1; |
7542 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
7543 | count += 1; | |
e16bb312 | 7544 | |
c19d1205 | 7545 | inst.instruction |= count; |
e16bb312 NC |
7546 | } |
7547 | ||
7548 | static void | |
c19d1205 | 7549 | do_vfp_sp_ldstmia (void) |
e16bb312 | 7550 | { |
c19d1205 | 7551 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
7552 | } |
7553 | ||
7554 | static void | |
c19d1205 | 7555 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 7556 | { |
c19d1205 | 7557 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
7558 | } |
7559 | ||
7560 | static void | |
c19d1205 | 7561 | do_vfp_dp_ldstmia (void) |
e16bb312 | 7562 | { |
c19d1205 | 7563 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
7564 | } |
7565 | ||
7566 | static void | |
c19d1205 | 7567 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 7568 | { |
c19d1205 | 7569 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
7570 | } |
7571 | ||
7572 | static void | |
c19d1205 | 7573 | do_vfp_xp_ldstmia (void) |
e16bb312 | 7574 | { |
c19d1205 ZW |
7575 | vfp_dp_ldstm (VFP_LDSTMIAX); |
7576 | } | |
e16bb312 | 7577 | |
c19d1205 ZW |
7578 | static void |
7579 | do_vfp_xp_ldstmdb (void) | |
7580 | { | |
7581 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 7582 | } |
5287ad62 JB |
7583 | |
7584 | static void | |
7585 | do_vfp_dp_rd_rm (void) | |
7586 | { | |
7587 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7588 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
7589 | } | |
7590 | ||
7591 | static void | |
7592 | do_vfp_dp_rn_rd (void) | |
7593 | { | |
7594 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
7595 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
7596 | } | |
7597 | ||
7598 | static void | |
7599 | do_vfp_dp_rd_rn (void) | |
7600 | { | |
7601 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7602 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
7603 | } | |
7604 | ||
7605 | static void | |
7606 | do_vfp_dp_rd_rn_rm (void) | |
7607 | { | |
7608 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7609 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
7610 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
7611 | } | |
7612 | ||
7613 | static void | |
7614 | do_vfp_dp_rd (void) | |
7615 | { | |
7616 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7617 | } | |
7618 | ||
7619 | static void | |
7620 | do_vfp_dp_rm_rd_rn (void) | |
7621 | { | |
7622 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
7623 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
7624 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
7625 | } | |
7626 | ||
7627 | /* VFPv3 instructions. */ | |
7628 | static void | |
7629 | do_vfp_sp_const (void) | |
7630 | { | |
7631 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
7632 | inst.instruction |= (inst.operands[1].imm & 15) << 16; | |
7633 | inst.instruction |= (inst.operands[1].imm >> 4); | |
7634 | } | |
7635 | ||
7636 | static void | |
7637 | do_vfp_dp_const (void) | |
7638 | { | |
7639 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7640 | inst.instruction |= (inst.operands[1].imm & 15) << 16; | |
7641 | inst.instruction |= (inst.operands[1].imm >> 4); | |
7642 | } | |
7643 | ||
7644 | static void | |
7645 | vfp_conv (int srcsize) | |
7646 | { | |
7647 | unsigned immbits = srcsize - inst.operands[1].imm; | |
7648 | inst.instruction |= (immbits & 1) << 5; | |
7649 | inst.instruction |= (immbits >> 1); | |
7650 | } | |
7651 | ||
7652 | static void | |
7653 | do_vfp_sp_conv_16 (void) | |
7654 | { | |
7655 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
7656 | vfp_conv (16); | |
7657 | } | |
7658 | ||
7659 | static void | |
7660 | do_vfp_dp_conv_16 (void) | |
7661 | { | |
7662 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7663 | vfp_conv (16); | |
7664 | } | |
7665 | ||
7666 | static void | |
7667 | do_vfp_sp_conv_32 (void) | |
7668 | { | |
7669 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
7670 | vfp_conv (32); | |
7671 | } | |
7672 | ||
7673 | static void | |
7674 | do_vfp_dp_conv_32 (void) | |
7675 | { | |
7676 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7677 | vfp_conv (32); | |
7678 | } | |
7679 | ||
c19d1205 ZW |
7680 | \f |
7681 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 7682 | |
c19d1205 ZW |
7683 | static void |
7684 | do_fpa_cmp (void) | |
7685 | { | |
7686 | inst.instruction |= inst.operands[0].reg << 16; | |
7687 | inst.instruction |= inst.operands[1].reg; | |
7688 | } | |
b99bd4ef NC |
7689 | |
7690 | static void | |
c19d1205 | 7691 | do_fpa_ldmstm (void) |
b99bd4ef | 7692 | { |
c19d1205 ZW |
7693 | inst.instruction |= inst.operands[0].reg << 12; |
7694 | switch (inst.operands[1].imm) | |
7695 | { | |
7696 | case 1: inst.instruction |= CP_T_X; break; | |
7697 | case 2: inst.instruction |= CP_T_Y; break; | |
7698 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
7699 | case 4: break; | |
7700 | default: abort (); | |
7701 | } | |
b99bd4ef | 7702 | |
c19d1205 ZW |
7703 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
7704 | { | |
7705 | /* The instruction specified "ea" or "fd", so we can only accept | |
7706 | [Rn]{!}. The instruction does not really support stacking or | |
7707 | unstacking, so we have to emulate these by setting appropriate | |
7708 | bits and offsets. */ | |
7709 | constraint (inst.reloc.exp.X_op != O_constant | |
7710 | || inst.reloc.exp.X_add_number != 0, | |
7711 | _("this instruction does not support indexing")); | |
b99bd4ef | 7712 | |
c19d1205 ZW |
7713 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
7714 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 7715 | |
c19d1205 ZW |
7716 | if (!(inst.instruction & INDEX_UP)) |
7717 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 7718 | |
c19d1205 ZW |
7719 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
7720 | { | |
7721 | inst.operands[2].preind = 0; | |
7722 | inst.operands[2].postind = 1; | |
7723 | } | |
7724 | } | |
b99bd4ef | 7725 | |
c19d1205 | 7726 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 7727 | } |
037e8744 | 7728 | |
c19d1205 ZW |
7729 | \f |
7730 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 7731 | |
c19d1205 ZW |
7732 | static void |
7733 | do_iwmmxt_tandorc (void) | |
7734 | { | |
7735 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
7736 | } | |
b99bd4ef | 7737 | |
c19d1205 ZW |
7738 | static void |
7739 | do_iwmmxt_textrc (void) | |
7740 | { | |
7741 | inst.instruction |= inst.operands[0].reg << 12; | |
7742 | inst.instruction |= inst.operands[1].imm; | |
7743 | } | |
b99bd4ef NC |
7744 | |
7745 | static void | |
c19d1205 | 7746 | do_iwmmxt_textrm (void) |
b99bd4ef | 7747 | { |
c19d1205 ZW |
7748 | inst.instruction |= inst.operands[0].reg << 12; |
7749 | inst.instruction |= inst.operands[1].reg << 16; | |
7750 | inst.instruction |= inst.operands[2].imm; | |
7751 | } | |
b99bd4ef | 7752 | |
c19d1205 ZW |
7753 | static void |
7754 | do_iwmmxt_tinsr (void) | |
7755 | { | |
7756 | inst.instruction |= inst.operands[0].reg << 16; | |
7757 | inst.instruction |= inst.operands[1].reg << 12; | |
7758 | inst.instruction |= inst.operands[2].imm; | |
7759 | } | |
b99bd4ef | 7760 | |
c19d1205 ZW |
7761 | static void |
7762 | do_iwmmxt_tmia (void) | |
7763 | { | |
7764 | inst.instruction |= inst.operands[0].reg << 5; | |
7765 | inst.instruction |= inst.operands[1].reg; | |
7766 | inst.instruction |= inst.operands[2].reg << 12; | |
7767 | } | |
b99bd4ef | 7768 | |
c19d1205 ZW |
7769 | static void |
7770 | do_iwmmxt_waligni (void) | |
7771 | { | |
7772 | inst.instruction |= inst.operands[0].reg << 12; | |
7773 | inst.instruction |= inst.operands[1].reg << 16; | |
7774 | inst.instruction |= inst.operands[2].reg; | |
7775 | inst.instruction |= inst.operands[3].imm << 20; | |
7776 | } | |
b99bd4ef | 7777 | |
c19d1205 ZW |
7778 | static void |
7779 | do_iwmmxt_wmov (void) | |
7780 | { | |
7781 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
7782 | inst.instruction |= inst.operands[0].reg << 12; | |
7783 | inst.instruction |= inst.operands[1].reg << 16; | |
7784 | inst.instruction |= inst.operands[1].reg; | |
7785 | } | |
b99bd4ef | 7786 | |
c19d1205 ZW |
7787 | static void |
7788 | do_iwmmxt_wldstbh (void) | |
7789 | { | |
8f06b2d8 | 7790 | int reloc; |
c19d1205 | 7791 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
7792 | if (thumb_mode) |
7793 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
7794 | else | |
7795 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
7796 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
7797 | } |
7798 | ||
c19d1205 ZW |
7799 | static void |
7800 | do_iwmmxt_wldstw (void) | |
7801 | { | |
7802 | /* RIWR_RIWC clears .isreg for a control register. */ | |
7803 | if (!inst.operands[0].isreg) | |
7804 | { | |
7805 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
7806 | inst.instruction |= 0xf0000000; | |
7807 | } | |
b99bd4ef | 7808 | |
c19d1205 ZW |
7809 | inst.instruction |= inst.operands[0].reg << 12; |
7810 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
7811 | } | |
b99bd4ef NC |
7812 | |
7813 | static void | |
c19d1205 | 7814 | do_iwmmxt_wldstd (void) |
b99bd4ef | 7815 | { |
c19d1205 | 7816 | inst.instruction |= inst.operands[0].reg << 12; |
f2184508 | 7817 | encode_arm_cp_address (1, TRUE, FALSE, 0); |
c19d1205 | 7818 | } |
b99bd4ef | 7819 | |
c19d1205 ZW |
7820 | static void |
7821 | do_iwmmxt_wshufh (void) | |
7822 | { | |
7823 | inst.instruction |= inst.operands[0].reg << 12; | |
7824 | inst.instruction |= inst.operands[1].reg << 16; | |
7825 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
7826 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
7827 | } | |
b99bd4ef | 7828 | |
c19d1205 ZW |
7829 | static void |
7830 | do_iwmmxt_wzero (void) | |
7831 | { | |
7832 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
7833 | inst.instruction |= inst.operands[0].reg; | |
7834 | inst.instruction |= inst.operands[0].reg << 12; | |
7835 | inst.instruction |= inst.operands[0].reg << 16; | |
7836 | } | |
7837 | \f | |
7838 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
7839 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 7840 | |
c19d1205 | 7841 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 7842 | |
c19d1205 ZW |
7843 | static void |
7844 | do_mav_triple (void) | |
7845 | { | |
7846 | inst.instruction |= inst.operands[0].reg << 16; | |
7847 | inst.instruction |= inst.operands[1].reg; | |
7848 | inst.instruction |= inst.operands[2].reg << 12; | |
7849 | } | |
b99bd4ef | 7850 | |
c19d1205 ZW |
7851 | /* Insns like "foo W,X,Y,Z". |
7852 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 7853 | |
c19d1205 ZW |
7854 | static void |
7855 | do_mav_quad (void) | |
7856 | { | |
7857 | inst.instruction |= inst.operands[0].reg << 5; | |
7858 | inst.instruction |= inst.operands[1].reg << 12; | |
7859 | inst.instruction |= inst.operands[2].reg << 16; | |
7860 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
7861 | } |
7862 | ||
c19d1205 ZW |
7863 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
7864 | static void | |
7865 | do_mav_dspsc (void) | |
a737bd4d | 7866 | { |
c19d1205 ZW |
7867 | inst.instruction |= inst.operands[1].reg << 12; |
7868 | } | |
a737bd4d | 7869 | |
c19d1205 ZW |
7870 | /* Maverick shift immediate instructions. |
7871 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
7872 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 7873 | |
c19d1205 ZW |
7874 | static void |
7875 | do_mav_shift (void) | |
7876 | { | |
7877 | int imm = inst.operands[2].imm; | |
a737bd4d | 7878 | |
c19d1205 ZW |
7879 | inst.instruction |= inst.operands[0].reg << 12; |
7880 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 7881 | |
c19d1205 ZW |
7882 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
7883 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
7884 | Bit 4 should be 0. */ | |
7885 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 7886 | |
c19d1205 ZW |
7887 | inst.instruction |= imm; |
7888 | } | |
7889 | \f | |
7890 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 7891 | |
c19d1205 ZW |
7892 | /* Xscale multiply-accumulate (argument parse) |
7893 | MIAcc acc0,Rm,Rs | |
7894 | MIAPHcc acc0,Rm,Rs | |
7895 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 7896 | |
c19d1205 ZW |
7897 | static void |
7898 | do_xsc_mia (void) | |
7899 | { | |
7900 | inst.instruction |= inst.operands[1].reg; | |
7901 | inst.instruction |= inst.operands[2].reg << 12; | |
7902 | } | |
a737bd4d | 7903 | |
c19d1205 | 7904 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 7905 | |
c19d1205 | 7906 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 7907 | |
c19d1205 ZW |
7908 | static void |
7909 | do_xsc_mar (void) | |
7910 | { | |
7911 | inst.instruction |= inst.operands[1].reg << 12; | |
7912 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7913 | } |
7914 | ||
c19d1205 | 7915 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 7916 | |
c19d1205 | 7917 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
7918 | |
7919 | static void | |
c19d1205 | 7920 | do_xsc_mra (void) |
b99bd4ef | 7921 | { |
c19d1205 ZW |
7922 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
7923 | inst.instruction |= inst.operands[0].reg << 12; | |
7924 | inst.instruction |= inst.operands[1].reg << 16; | |
7925 | } | |
7926 | \f | |
7927 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 7928 | |
c19d1205 ZW |
7929 | /* inst.operands[i] is a shifted-register operand; encode |
7930 | it into inst.instruction in the format used by Thumb32. */ | |
7931 | ||
7932 | static void | |
7933 | encode_thumb32_shifted_operand (int i) | |
7934 | { | |
7935 | unsigned int value = inst.reloc.exp.X_add_number; | |
7936 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 7937 | |
9c3c69f2 PB |
7938 | constraint (inst.operands[i].immisreg, |
7939 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
7940 | inst.instruction |= inst.operands[i].reg; |
7941 | if (shift == SHIFT_RRX) | |
7942 | inst.instruction |= SHIFT_ROR << 4; | |
7943 | else | |
b99bd4ef | 7944 | { |
c19d1205 ZW |
7945 | constraint (inst.reloc.exp.X_op != O_constant, |
7946 | _("expression too complex")); | |
7947 | ||
7948 | constraint (value > 32 | |
7949 | || (value == 32 && (shift == SHIFT_LSL | |
7950 | || shift == SHIFT_ROR)), | |
7951 | _("shift expression is too large")); | |
7952 | ||
7953 | if (value == 0) | |
7954 | shift = SHIFT_LSL; | |
7955 | else if (value == 32) | |
7956 | value = 0; | |
7957 | ||
7958 | inst.instruction |= shift << 4; | |
7959 | inst.instruction |= (value & 0x1c) << 10; | |
7960 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 7961 | } |
c19d1205 | 7962 | } |
b99bd4ef | 7963 | |
b99bd4ef | 7964 | |
c19d1205 ZW |
7965 | /* inst.operands[i] was set up by parse_address. Encode it into a |
7966 | Thumb32 format load or store instruction. Reject forms that cannot | |
7967 | be used with such instructions. If is_t is true, reject forms that | |
7968 | cannot be used with a T instruction; if is_d is true, reject forms | |
7969 | that cannot be used with a D instruction. */ | |
b99bd4ef | 7970 | |
c19d1205 ZW |
7971 | static void |
7972 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
7973 | { | |
7974 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
7975 | ||
7976 | constraint (!inst.operands[i].isreg, | |
53365c0d | 7977 | _("Instruction does not support =N addresses")); |
b99bd4ef | 7978 | |
c19d1205 ZW |
7979 | inst.instruction |= inst.operands[i].reg << 16; |
7980 | if (inst.operands[i].immisreg) | |
b99bd4ef | 7981 | { |
c19d1205 ZW |
7982 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
7983 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
7984 | constraint (inst.operands[i].negative, | |
7985 | _("Thumb does not support negative register indexing")); | |
7986 | constraint (inst.operands[i].postind, | |
7987 | _("Thumb does not support register post-indexing")); | |
7988 | constraint (inst.operands[i].writeback, | |
7989 | _("Thumb does not support register indexing with writeback")); | |
7990 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
7991 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 7992 | |
f40d1643 | 7993 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 7994 | if (inst.operands[i].shifted) |
b99bd4ef | 7995 | { |
c19d1205 ZW |
7996 | constraint (inst.reloc.exp.X_op != O_constant, |
7997 | _("expression too complex")); | |
9c3c69f2 PB |
7998 | constraint (inst.reloc.exp.X_add_number < 0 |
7999 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 8000 | _("shift out of range")); |
9c3c69f2 | 8001 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
8002 | } |
8003 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8004 | } | |
8005 | else if (inst.operands[i].preind) | |
8006 | { | |
8007 | constraint (is_pc && inst.operands[i].writeback, | |
8008 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 8009 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
8010 | _("cannot use writeback with this instruction")); |
8011 | ||
8012 | if (is_d) | |
8013 | { | |
8014 | inst.instruction |= 0x01000000; | |
8015 | if (inst.operands[i].writeback) | |
8016 | inst.instruction |= 0x00200000; | |
b99bd4ef | 8017 | } |
c19d1205 | 8018 | else |
b99bd4ef | 8019 | { |
c19d1205 ZW |
8020 | inst.instruction |= 0x00000c00; |
8021 | if (inst.operands[i].writeback) | |
8022 | inst.instruction |= 0x00000100; | |
b99bd4ef | 8023 | } |
c19d1205 | 8024 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 8025 | } |
c19d1205 | 8026 | else if (inst.operands[i].postind) |
b99bd4ef | 8027 | { |
c19d1205 ZW |
8028 | assert (inst.operands[i].writeback); |
8029 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); | |
8030 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
8031 | ||
8032 | if (is_d) | |
8033 | inst.instruction |= 0x00200000; | |
8034 | else | |
8035 | inst.instruction |= 0x00000900; | |
8036 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
8037 | } | |
8038 | else /* unindexed - only for coprocessor */ | |
8039 | inst.error = _("instruction does not accept unindexed addressing"); | |
8040 | } | |
8041 | ||
8042 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
8043 | encodings (the latter only in post-V6T2 cores). The index is the | |
8044 | value used in the insns table below. When there is more than one | |
8045 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
8046 | holds variant (1). |
8047 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 ZW |
8048 | #define T16_32_TAB \ |
8049 | X(adc, 4140, eb400000), \ | |
8050 | X(adcs, 4140, eb500000), \ | |
8051 | X(add, 1c00, eb000000), \ | |
8052 | X(adds, 1c00, eb100000), \ | |
0110f2b8 PB |
8053 | X(addi, 0000, f1000000), \ |
8054 | X(addis, 0000, f1100000), \ | |
8055 | X(add_pc,000f, f20f0000), \ | |
8056 | X(add_sp,000d, f10d0000), \ | |
e9f89963 | 8057 | X(adr, 000f, f20f0000), \ |
c19d1205 ZW |
8058 | X(and, 4000, ea000000), \ |
8059 | X(ands, 4000, ea100000), \ | |
8060 | X(asr, 1000, fa40f000), \ | |
8061 | X(asrs, 1000, fa50f000), \ | |
0110f2b8 PB |
8062 | X(b, e000, f000b000), \ |
8063 | X(bcond, d000, f0008000), \ | |
c19d1205 ZW |
8064 | X(bic, 4380, ea200000), \ |
8065 | X(bics, 4380, ea300000), \ | |
8066 | X(cmn, 42c0, eb100f00), \ | |
8067 | X(cmp, 2800, ebb00f00), \ | |
8068 | X(cpsie, b660, f3af8400), \ | |
8069 | X(cpsid, b670, f3af8600), \ | |
8070 | X(cpy, 4600, ea4f0000), \ | |
0110f2b8 | 8071 | X(dec_sp,80dd, f1bd0d00), \ |
c19d1205 ZW |
8072 | X(eor, 4040, ea800000), \ |
8073 | X(eors, 4040, ea900000), \ | |
0110f2b8 | 8074 | X(inc_sp,00dd, f10d0d00), \ |
c19d1205 ZW |
8075 | X(ldmia, c800, e8900000), \ |
8076 | X(ldr, 6800, f8500000), \ | |
8077 | X(ldrb, 7800, f8100000), \ | |
8078 | X(ldrh, 8800, f8300000), \ | |
8079 | X(ldrsb, 5600, f9100000), \ | |
8080 | X(ldrsh, 5e00, f9300000), \ | |
0110f2b8 PB |
8081 | X(ldr_pc,4800, f85f0000), \ |
8082 | X(ldr_pc2,4800, f85f0000), \ | |
8083 | X(ldr_sp,9800, f85d0000), \ | |
c19d1205 ZW |
8084 | X(lsl, 0000, fa00f000), \ |
8085 | X(lsls, 0000, fa10f000), \ | |
8086 | X(lsr, 0800, fa20f000), \ | |
8087 | X(lsrs, 0800, fa30f000), \ | |
8088 | X(mov, 2000, ea4f0000), \ | |
8089 | X(movs, 2000, ea5f0000), \ | |
8090 | X(mul, 4340, fb00f000), \ | |
8091 | X(muls, 4340, ffffffff), /* no 32b muls */ \ | |
8092 | X(mvn, 43c0, ea6f0000), \ | |
8093 | X(mvns, 43c0, ea7f0000), \ | |
8094 | X(neg, 4240, f1c00000), /* rsb #0 */ \ | |
8095 | X(negs, 4240, f1d00000), /* rsbs #0 */ \ | |
8096 | X(orr, 4300, ea400000), \ | |
8097 | X(orrs, 4300, ea500000), \ | |
e9f89963 PB |
8098 | X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \ |
8099 | X(push, b400, e92d0000), /* stmdb sp!,... */ \ | |
c19d1205 ZW |
8100 | X(rev, ba00, fa90f080), \ |
8101 | X(rev16, ba40, fa90f090), \ | |
8102 | X(revsh, bac0, fa90f0b0), \ | |
8103 | X(ror, 41c0, fa60f000), \ | |
8104 | X(rors, 41c0, fa70f000), \ | |
8105 | X(sbc, 4180, eb600000), \ | |
8106 | X(sbcs, 4180, eb700000), \ | |
8107 | X(stmia, c000, e8800000), \ | |
8108 | X(str, 6000, f8400000), \ | |
8109 | X(strb, 7000, f8000000), \ | |
8110 | X(strh, 8000, f8200000), \ | |
0110f2b8 | 8111 | X(str_sp,9000, f84d0000), \ |
c19d1205 ZW |
8112 | X(sub, 1e00, eba00000), \ |
8113 | X(subs, 1e00, ebb00000), \ | |
0110f2b8 PB |
8114 | X(subi, 8000, f1a00000), \ |
8115 | X(subis, 8000, f1b00000), \ | |
c19d1205 ZW |
8116 | X(sxtb, b240, fa4ff080), \ |
8117 | X(sxth, b200, fa0ff080), \ | |
8118 | X(tst, 4200, ea100f00), \ | |
8119 | X(uxtb, b2c0, fa5ff080), \ | |
8120 | X(uxth, b280, fa1ff080), \ | |
8121 | X(nop, bf00, f3af8000), \ | |
8122 | X(yield, bf10, f3af8001), \ | |
8123 | X(wfe, bf20, f3af8002), \ | |
8124 | X(wfi, bf30, f3af8003), \ | |
8125 | X(sev, bf40, f3af9004), /* typo, 8004? */ | |
8126 | ||
8127 | /* To catch errors in encoding functions, the codes are all offset by | |
8128 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
8129 | as 16-bit instructions. */ | |
8130 | #define X(a,b,c) T_MNEM_##a | |
8131 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; | |
8132 | #undef X | |
8133 | ||
8134 | #define X(a,b,c) 0x##b | |
8135 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
8136 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
8137 | #undef X | |
8138 | ||
8139 | #define X(a,b,c) 0x##c | |
8140 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
8141 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) | |
8142 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
8143 | #undef X | |
8144 | #undef T16_32_TAB | |
8145 | ||
8146 | /* Thumb instruction encoders, in alphabetical order. */ | |
8147 | ||
92e90b6e PB |
8148 | /* ADDW or SUBW. */ |
8149 | static void | |
8150 | do_t_add_sub_w (void) | |
8151 | { | |
8152 | int Rd, Rn; | |
8153 | ||
8154 | Rd = inst.operands[0].reg; | |
8155 | Rn = inst.operands[1].reg; | |
8156 | ||
8157 | constraint (Rd == 15, _("PC not allowed as destination")); | |
8158 | inst.instruction |= (Rn << 16) | (Rd << 8); | |
8159 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8160 | } | |
8161 | ||
c19d1205 ZW |
8162 | /* Parse an add or subtract instruction. We get here with inst.instruction |
8163 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
8164 | ||
8165 | static void | |
8166 | do_t_add_sub (void) | |
8167 | { | |
8168 | int Rd, Rs, Rn; | |
8169 | ||
8170 | Rd = inst.operands[0].reg; | |
8171 | Rs = (inst.operands[1].present | |
8172 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8173 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8174 | ||
8175 | if (unified_syntax) | |
8176 | { | |
0110f2b8 PB |
8177 | bfd_boolean flags; |
8178 | bfd_boolean narrow; | |
8179 | int opcode; | |
8180 | ||
8181 | flags = (inst.instruction == T_MNEM_adds | |
8182 | || inst.instruction == T_MNEM_subs); | |
8183 | if (flags) | |
8184 | narrow = (current_it_mask == 0); | |
8185 | else | |
8186 | narrow = (current_it_mask != 0); | |
c19d1205 | 8187 | if (!inst.operands[2].isreg) |
b99bd4ef | 8188 | { |
0110f2b8 PB |
8189 | opcode = 0; |
8190 | if (inst.size_req != 4) | |
8191 | { | |
8192 | int add; | |
8193 | ||
8194 | add = (inst.instruction == T_MNEM_add | |
8195 | || inst.instruction == T_MNEM_adds); | |
8196 | /* Attempt to use a narrow opcode, with relaxation if | |
8197 | appropriate. */ | |
8198 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
8199 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
8200 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
8201 | opcode = T_MNEM_add_sp; | |
8202 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
8203 | opcode = T_MNEM_add_pc; | |
8204 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
8205 | { | |
8206 | if (flags) | |
8207 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
8208 | else | |
8209 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
8210 | } | |
8211 | if (opcode) | |
8212 | { | |
8213 | inst.instruction = THUMB_OP16(opcode); | |
8214 | inst.instruction |= (Rd << 4) | Rs; | |
8215 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8216 | if (inst.size_req != 2) | |
8217 | inst.relax = opcode; | |
8218 | } | |
8219 | else | |
8220 | constraint (inst.size_req == 2, BAD_HIREG); | |
8221 | } | |
8222 | if (inst.size_req == 4 | |
8223 | || (inst.size_req != 2 && !opcode)) | |
8224 | { | |
8225 | /* ??? Convert large immediates to addw/subw. */ | |
8226 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8227 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
8228 | inst.instruction |= inst.operands[0].reg << 8; | |
8229 | inst.instruction |= inst.operands[1].reg << 16; | |
8230 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8231 | } | |
b99bd4ef | 8232 | } |
c19d1205 ZW |
8233 | else |
8234 | { | |
8235 | Rn = inst.operands[2].reg; | |
8236 | /* See if we can do this with a 16-bit instruction. */ | |
8237 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
8238 | { | |
e27ec89e PB |
8239 | if (Rd > 7 || Rs > 7 || Rn > 7) |
8240 | narrow = FALSE; | |
8241 | ||
8242 | if (narrow) | |
c19d1205 | 8243 | { |
e27ec89e PB |
8244 | inst.instruction = ((inst.instruction == T_MNEM_adds |
8245 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
8246 | ? T_OPCODE_ADD_R3 |
8247 | : T_OPCODE_SUB_R3); | |
8248 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
8249 | return; | |
8250 | } | |
b99bd4ef | 8251 | |
c19d1205 ZW |
8252 | if (inst.instruction == T_MNEM_add) |
8253 | { | |
8254 | if (Rd == Rs) | |
8255 | { | |
8256 | inst.instruction = T_OPCODE_ADD_HI; | |
8257 | inst.instruction |= (Rd & 8) << 4; | |
8258 | inst.instruction |= (Rd & 7); | |
8259 | inst.instruction |= Rn << 3; | |
8260 | return; | |
8261 | } | |
8262 | /* ... because addition is commutative! */ | |
8263 | else if (Rd == Rn) | |
8264 | { | |
8265 | inst.instruction = T_OPCODE_ADD_HI; | |
8266 | inst.instruction |= (Rd & 8) << 4; | |
8267 | inst.instruction |= (Rd & 7); | |
8268 | inst.instruction |= Rs << 3; | |
8269 | return; | |
8270 | } | |
8271 | } | |
8272 | } | |
8273 | /* If we get here, it can't be done in 16 bits. */ | |
8274 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
8275 | _("shift must be constant")); | |
8276 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8277 | inst.instruction |= Rd << 8; | |
8278 | inst.instruction |= Rs << 16; | |
8279 | encode_thumb32_shifted_operand (2); | |
8280 | } | |
8281 | } | |
8282 | else | |
8283 | { | |
8284 | constraint (inst.instruction == T_MNEM_adds | |
8285 | || inst.instruction == T_MNEM_subs, | |
8286 | BAD_THUMB32); | |
b99bd4ef | 8287 | |
c19d1205 | 8288 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 8289 | { |
c19d1205 ZW |
8290 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
8291 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
8292 | BAD_HIREG); | |
8293 | ||
8294 | inst.instruction = (inst.instruction == T_MNEM_add | |
8295 | ? 0x0000 : 0x8000); | |
8296 | inst.instruction |= (Rd << 4) | Rs; | |
8297 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
8298 | return; |
8299 | } | |
8300 | ||
c19d1205 ZW |
8301 | Rn = inst.operands[2].reg; |
8302 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 8303 | |
c19d1205 ZW |
8304 | /* We now have Rd, Rs, and Rn set to registers. */ |
8305 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 8306 | { |
c19d1205 ZW |
8307 | /* Can't do this for SUB. */ |
8308 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
8309 | inst.instruction = T_OPCODE_ADD_HI; | |
8310 | inst.instruction |= (Rd & 8) << 4; | |
8311 | inst.instruction |= (Rd & 7); | |
8312 | if (Rs == Rd) | |
8313 | inst.instruction |= Rn << 3; | |
8314 | else if (Rn == Rd) | |
8315 | inst.instruction |= Rs << 3; | |
8316 | else | |
8317 | constraint (1, _("dest must overlap one source register")); | |
8318 | } | |
8319 | else | |
8320 | { | |
8321 | inst.instruction = (inst.instruction == T_MNEM_add | |
8322 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
8323 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 8324 | } |
b99bd4ef | 8325 | } |
b99bd4ef NC |
8326 | } |
8327 | ||
c19d1205 ZW |
8328 | static void |
8329 | do_t_adr (void) | |
8330 | { | |
0110f2b8 PB |
8331 | if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7) |
8332 | { | |
8333 | /* Defer to section relaxation. */ | |
8334 | inst.relax = inst.instruction; | |
8335 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8336 | inst.instruction |= inst.operands[0].reg << 4; | |
8337 | } | |
8338 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 8339 | { |
0110f2b8 | 8340 | /* Generate a 32-bit opcode. */ |
e9f89963 PB |
8341 | inst.instruction = THUMB_OP32 (inst.instruction); |
8342 | inst.instruction |= inst.operands[0].reg << 8; | |
8343 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; | |
8344 | inst.reloc.pc_rel = 1; | |
8345 | } | |
8346 | else | |
8347 | { | |
0110f2b8 | 8348 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
8349 | inst.instruction = THUMB_OP16 (inst.instruction); |
8350 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8351 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
8352 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 8353 | |
e9f89963 PB |
8354 | inst.instruction |= inst.operands[0].reg << 4; |
8355 | } | |
c19d1205 | 8356 | } |
b99bd4ef | 8357 | |
c19d1205 ZW |
8358 | /* Arithmetic instructions for which there is just one 16-bit |
8359 | instruction encoding, and it allows only two low registers. | |
8360 | For maximal compatibility with ARM syntax, we allow three register | |
8361 | operands even when Thumb-32 instructions are not available, as long | |
8362 | as the first two are identical. For instance, both "sbc r0,r1" and | |
8363 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 8364 | static void |
c19d1205 | 8365 | do_t_arit3 (void) |
b99bd4ef | 8366 | { |
c19d1205 | 8367 | int Rd, Rs, Rn; |
b99bd4ef | 8368 | |
c19d1205 ZW |
8369 | Rd = inst.operands[0].reg; |
8370 | Rs = (inst.operands[1].present | |
8371 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8372 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8373 | Rn = inst.operands[2].reg; | |
b99bd4ef | 8374 | |
c19d1205 | 8375 | if (unified_syntax) |
b99bd4ef | 8376 | { |
c19d1205 ZW |
8377 | if (!inst.operands[2].isreg) |
8378 | { | |
8379 | /* For an immediate, we always generate a 32-bit opcode; | |
8380 | section relaxation will shrink it later if possible. */ | |
8381 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8382 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
8383 | inst.instruction |= Rd << 8; | |
8384 | inst.instruction |= Rs << 16; | |
8385 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8386 | } | |
8387 | else | |
8388 | { | |
e27ec89e PB |
8389 | bfd_boolean narrow; |
8390 | ||
c19d1205 | 8391 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
8392 | if (THUMB_SETS_FLAGS (inst.instruction)) |
8393 | narrow = current_it_mask == 0; | |
8394 | else | |
8395 | narrow = current_it_mask != 0; | |
8396 | ||
8397 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
8398 | narrow = FALSE; | |
8399 | if (inst.operands[2].shifted) | |
8400 | narrow = FALSE; | |
8401 | if (inst.size_req == 4) | |
8402 | narrow = FALSE; | |
8403 | ||
8404 | if (narrow | |
c19d1205 ZW |
8405 | && Rd == Rs) |
8406 | { | |
8407 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8408 | inst.instruction |= Rd; | |
8409 | inst.instruction |= Rn << 3; | |
8410 | return; | |
8411 | } | |
b99bd4ef | 8412 | |
c19d1205 ZW |
8413 | /* If we get here, it can't be done in 16 bits. */ |
8414 | constraint (inst.operands[2].shifted | |
8415 | && inst.operands[2].immisreg, | |
8416 | _("shift must be constant")); | |
8417 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8418 | inst.instruction |= Rd << 8; | |
8419 | inst.instruction |= Rs << 16; | |
8420 | encode_thumb32_shifted_operand (2); | |
8421 | } | |
a737bd4d | 8422 | } |
c19d1205 | 8423 | else |
b99bd4ef | 8424 | { |
c19d1205 ZW |
8425 | /* On its face this is a lie - the instruction does set the |
8426 | flags. However, the only supported mnemonic in this mode | |
8427 | says it doesn't. */ | |
8428 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 8429 | |
c19d1205 ZW |
8430 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
8431 | _("unshifted register required")); | |
8432 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
8433 | constraint (Rd != Rs, | |
8434 | _("dest and source1 must be the same register")); | |
a737bd4d | 8435 | |
c19d1205 ZW |
8436 | inst.instruction = THUMB_OP16 (inst.instruction); |
8437 | inst.instruction |= Rd; | |
8438 | inst.instruction |= Rn << 3; | |
b99bd4ef | 8439 | } |
a737bd4d | 8440 | } |
b99bd4ef | 8441 | |
c19d1205 ZW |
8442 | /* Similarly, but for instructions where the arithmetic operation is |
8443 | commutative, so we can allow either of them to be different from | |
8444 | the destination operand in a 16-bit instruction. For instance, all | |
8445 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
8446 | accepted. */ | |
8447 | static void | |
8448 | do_t_arit3c (void) | |
a737bd4d | 8449 | { |
c19d1205 | 8450 | int Rd, Rs, Rn; |
b99bd4ef | 8451 | |
c19d1205 ZW |
8452 | Rd = inst.operands[0].reg; |
8453 | Rs = (inst.operands[1].present | |
8454 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8455 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8456 | Rn = inst.operands[2].reg; | |
a737bd4d | 8457 | |
c19d1205 | 8458 | if (unified_syntax) |
a737bd4d | 8459 | { |
c19d1205 | 8460 | if (!inst.operands[2].isreg) |
b99bd4ef | 8461 | { |
c19d1205 ZW |
8462 | /* For an immediate, we always generate a 32-bit opcode; |
8463 | section relaxation will shrink it later if possible. */ | |
8464 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8465 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
8466 | inst.instruction |= Rd << 8; | |
8467 | inst.instruction |= Rs << 16; | |
8468 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 8469 | } |
c19d1205 | 8470 | else |
a737bd4d | 8471 | { |
e27ec89e PB |
8472 | bfd_boolean narrow; |
8473 | ||
c19d1205 | 8474 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
8475 | if (THUMB_SETS_FLAGS (inst.instruction)) |
8476 | narrow = current_it_mask == 0; | |
8477 | else | |
8478 | narrow = current_it_mask != 0; | |
8479 | ||
8480 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
8481 | narrow = FALSE; | |
8482 | if (inst.operands[2].shifted) | |
8483 | narrow = FALSE; | |
8484 | if (inst.size_req == 4) | |
8485 | narrow = FALSE; | |
8486 | ||
8487 | if (narrow) | |
a737bd4d | 8488 | { |
c19d1205 | 8489 | if (Rd == Rs) |
a737bd4d | 8490 | { |
c19d1205 ZW |
8491 | inst.instruction = THUMB_OP16 (inst.instruction); |
8492 | inst.instruction |= Rd; | |
8493 | inst.instruction |= Rn << 3; | |
8494 | return; | |
a737bd4d | 8495 | } |
c19d1205 | 8496 | if (Rd == Rn) |
a737bd4d | 8497 | { |
c19d1205 ZW |
8498 | inst.instruction = THUMB_OP16 (inst.instruction); |
8499 | inst.instruction |= Rd; | |
8500 | inst.instruction |= Rs << 3; | |
8501 | return; | |
a737bd4d NC |
8502 | } |
8503 | } | |
c19d1205 ZW |
8504 | |
8505 | /* If we get here, it can't be done in 16 bits. */ | |
8506 | constraint (inst.operands[2].shifted | |
8507 | && inst.operands[2].immisreg, | |
8508 | _("shift must be constant")); | |
8509 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8510 | inst.instruction |= Rd << 8; | |
8511 | inst.instruction |= Rs << 16; | |
8512 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 8513 | } |
b99bd4ef | 8514 | } |
c19d1205 ZW |
8515 | else |
8516 | { | |
8517 | /* On its face this is a lie - the instruction does set the | |
8518 | flags. However, the only supported mnemonic in this mode | |
8519 | says it doesn't. */ | |
8520 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 8521 | |
c19d1205 ZW |
8522 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
8523 | _("unshifted register required")); | |
8524 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
8525 | ||
8526 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8527 | inst.instruction |= Rd; | |
8528 | ||
8529 | if (Rd == Rs) | |
8530 | inst.instruction |= Rn << 3; | |
8531 | else if (Rd == Rn) | |
8532 | inst.instruction |= Rs << 3; | |
8533 | else | |
8534 | constraint (1, _("dest must overlap one source register")); | |
8535 | } | |
a737bd4d NC |
8536 | } |
8537 | ||
62b3e311 PB |
8538 | static void |
8539 | do_t_barrier (void) | |
8540 | { | |
8541 | if (inst.operands[0].present) | |
8542 | { | |
8543 | constraint ((inst.instruction & 0xf0) != 0x40 | |
8544 | && inst.operands[0].imm != 0xf, | |
8545 | "bad barrier type"); | |
8546 | inst.instruction |= inst.operands[0].imm; | |
8547 | } | |
8548 | else | |
8549 | inst.instruction |= 0xf; | |
8550 | } | |
8551 | ||
c19d1205 ZW |
8552 | static void |
8553 | do_t_bfc (void) | |
a737bd4d | 8554 | { |
c19d1205 ZW |
8555 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
8556 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8557 | /* The instruction encoding stores the LSB and MSB, | |
8558 | not the LSB and width. */ | |
8559 | inst.instruction |= inst.operands[0].reg << 8; | |
8560 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; | |
8561 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
8562 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
8563 | } |
8564 | ||
c19d1205 ZW |
8565 | static void |
8566 | do_t_bfi (void) | |
b99bd4ef | 8567 | { |
c19d1205 | 8568 | unsigned int msb; |
b99bd4ef | 8569 | |
c19d1205 ZW |
8570 | /* #0 in second position is alternative syntax for bfc, which is |
8571 | the same instruction but with REG_PC in the Rm field. */ | |
8572 | if (!inst.operands[1].isreg) | |
8573 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 8574 | |
c19d1205 ZW |
8575 | msb = inst.operands[2].imm + inst.operands[3].imm; |
8576 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8577 | /* The instruction encoding stores the LSB and MSB, | |
8578 | not the LSB and width. */ | |
8579 | inst.instruction |= inst.operands[0].reg << 8; | |
8580 | inst.instruction |= inst.operands[1].reg << 16; | |
8581 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
8582 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
8583 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
8584 | } |
8585 | ||
c19d1205 ZW |
8586 | static void |
8587 | do_t_bfx (void) | |
b99bd4ef | 8588 | { |
c19d1205 ZW |
8589 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
8590 | _("bit-field extends past end of register")); | |
8591 | inst.instruction |= inst.operands[0].reg << 8; | |
8592 | inst.instruction |= inst.operands[1].reg << 16; | |
8593 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
8594 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
8595 | inst.instruction |= inst.operands[3].imm - 1; | |
8596 | } | |
b99bd4ef | 8597 | |
c19d1205 ZW |
8598 | /* ARM V5 Thumb BLX (argument parse) |
8599 | BLX <target_addr> which is BLX(1) | |
8600 | BLX <Rm> which is BLX(2) | |
8601 | Unfortunately, there are two different opcodes for this mnemonic. | |
8602 | So, the insns[].value is not used, and the code here zaps values | |
8603 | into inst.instruction. | |
b99bd4ef | 8604 | |
c19d1205 ZW |
8605 | ??? How to take advantage of the additional two bits of displacement |
8606 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 8607 | |
c19d1205 ZW |
8608 | static void |
8609 | do_t_blx (void) | |
8610 | { | |
dfa9f0d5 | 8611 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
8612 | if (inst.operands[0].isreg) |
8613 | /* We have a register, so this is BLX(2). */ | |
8614 | inst.instruction |= inst.operands[0].reg << 3; | |
b99bd4ef NC |
8615 | else |
8616 | { | |
c19d1205 | 8617 | /* No register. This must be BLX(1). */ |
2fc8bdac | 8618 | inst.instruction = 0xf000e800; |
39b41c9c PB |
8619 | #ifdef OBJ_ELF |
8620 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8621 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
8622 | else | |
8623 | #endif | |
8624 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; | |
c19d1205 | 8625 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
8626 | } |
8627 | } | |
8628 | ||
c19d1205 ZW |
8629 | static void |
8630 | do_t_branch (void) | |
b99bd4ef | 8631 | { |
0110f2b8 | 8632 | int opcode; |
dfa9f0d5 PB |
8633 | int cond; |
8634 | ||
8635 | if (current_it_mask) | |
8636 | { | |
8637 | /* Conditional branches inside IT blocks are encoded as unconditional | |
8638 | branches. */ | |
8639 | cond = COND_ALWAYS; | |
8640 | /* A branch must be the last instruction in an IT block. */ | |
8641 | constraint (current_it_mask != 0x10, BAD_BRANCH); | |
8642 | } | |
8643 | else | |
8644 | cond = inst.cond; | |
8645 | ||
8646 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
8647 | opcode = T_MNEM_bcond; |
8648 | else | |
8649 | opcode = inst.instruction; | |
8650 | ||
8651 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 8652 | { |
0110f2b8 | 8653 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 8654 | if (cond == COND_ALWAYS) |
0110f2b8 | 8655 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
8656 | else |
8657 | { | |
dfa9f0d5 PB |
8658 | assert (cond != 0xF); |
8659 | inst.instruction |= cond << 22; | |
c19d1205 ZW |
8660 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
8661 | } | |
8662 | } | |
b99bd4ef NC |
8663 | else |
8664 | { | |
0110f2b8 | 8665 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 8666 | if (cond == COND_ALWAYS) |
c19d1205 ZW |
8667 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; |
8668 | else | |
b99bd4ef | 8669 | { |
dfa9f0d5 | 8670 | inst.instruction |= cond << 8; |
c19d1205 | 8671 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 8672 | } |
0110f2b8 PB |
8673 | /* Allow section relaxation. */ |
8674 | if (unified_syntax && inst.size_req != 2) | |
8675 | inst.relax = opcode; | |
b99bd4ef | 8676 | } |
c19d1205 ZW |
8677 | |
8678 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
8679 | } |
8680 | ||
8681 | static void | |
c19d1205 | 8682 | do_t_bkpt (void) |
b99bd4ef | 8683 | { |
dfa9f0d5 PB |
8684 | constraint (inst.cond != COND_ALWAYS, |
8685 | _("instruction is always unconditional")); | |
c19d1205 | 8686 | if (inst.operands[0].present) |
b99bd4ef | 8687 | { |
c19d1205 ZW |
8688 | constraint (inst.operands[0].imm > 255, |
8689 | _("immediate value out of range")); | |
8690 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 8691 | } |
b99bd4ef NC |
8692 | } |
8693 | ||
8694 | static void | |
c19d1205 | 8695 | do_t_branch23 (void) |
b99bd4ef | 8696 | { |
dfa9f0d5 | 8697 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 | 8698 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
8699 | inst.reloc.pc_rel = 1; |
8700 | ||
c19d1205 ZW |
8701 | /* If the destination of the branch is a defined symbol which does not have |
8702 | the THUMB_FUNC attribute, then we must be calling a function which has | |
8703 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
8704 | function and change the branch to refer to that function instead. */ | |
8705 | if ( inst.reloc.exp.X_op == O_symbol | |
8706 | && inst.reloc.exp.X_add_symbol != NULL | |
8707 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
8708 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
8709 | inst.reloc.exp.X_add_symbol = | |
8710 | find_real_start (inst.reloc.exp.X_add_symbol); | |
90e4755a RE |
8711 | } |
8712 | ||
8713 | static void | |
c19d1205 | 8714 | do_t_bx (void) |
90e4755a | 8715 | { |
dfa9f0d5 | 8716 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
8717 | inst.instruction |= inst.operands[0].reg << 3; |
8718 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
8719 | should cause the alignment to be checked once it is known. This is | |
8720 | because BX PC only works if the instruction is word aligned. */ | |
8721 | } | |
90e4755a | 8722 | |
c19d1205 ZW |
8723 | static void |
8724 | do_t_bxj (void) | |
8725 | { | |
dfa9f0d5 | 8726 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
8727 | if (inst.operands[0].reg == REG_PC) |
8728 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
90e4755a | 8729 | |
c19d1205 | 8730 | inst.instruction |= inst.operands[0].reg << 16; |
90e4755a RE |
8731 | } |
8732 | ||
8733 | static void | |
c19d1205 | 8734 | do_t_clz (void) |
90e4755a | 8735 | { |
c19d1205 ZW |
8736 | inst.instruction |= inst.operands[0].reg << 8; |
8737 | inst.instruction |= inst.operands[1].reg << 16; | |
8738 | inst.instruction |= inst.operands[1].reg; | |
8739 | } | |
90e4755a | 8740 | |
dfa9f0d5 PB |
8741 | static void |
8742 | do_t_cps (void) | |
8743 | { | |
8744 | constraint (current_it_mask, BAD_NOT_IT); | |
8745 | inst.instruction |= inst.operands[0].imm; | |
8746 | } | |
8747 | ||
c19d1205 ZW |
8748 | static void |
8749 | do_t_cpsi (void) | |
8750 | { | |
dfa9f0d5 | 8751 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 | 8752 | if (unified_syntax |
62b3e311 PB |
8753 | && (inst.operands[1].present || inst.size_req == 4) |
8754 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 8755 | { |
c19d1205 ZW |
8756 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
8757 | inst.instruction = 0xf3af8000; | |
8758 | inst.instruction |= imod << 9; | |
8759 | inst.instruction |= inst.operands[0].imm << 5; | |
8760 | if (inst.operands[1].present) | |
8761 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 8762 | } |
c19d1205 | 8763 | else |
90e4755a | 8764 | { |
62b3e311 PB |
8765 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
8766 | && (inst.operands[0].imm & 4), | |
8767 | _("selected processor does not support 'A' form " | |
8768 | "of this instruction")); | |
8769 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
8770 | _("Thumb does not support the 2-argument " |
8771 | "form of this instruction")); | |
8772 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 8773 | } |
90e4755a RE |
8774 | } |
8775 | ||
c19d1205 ZW |
8776 | /* THUMB CPY instruction (argument parse). */ |
8777 | ||
90e4755a | 8778 | static void |
c19d1205 | 8779 | do_t_cpy (void) |
90e4755a | 8780 | { |
c19d1205 | 8781 | if (inst.size_req == 4) |
90e4755a | 8782 | { |
c19d1205 ZW |
8783 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
8784 | inst.instruction |= inst.operands[0].reg << 8; | |
8785 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 8786 | } |
c19d1205 | 8787 | else |
90e4755a | 8788 | { |
c19d1205 ZW |
8789 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
8790 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
8791 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 8792 | } |
90e4755a RE |
8793 | } |
8794 | ||
90e4755a | 8795 | static void |
c19d1205 | 8796 | do_t_czb (void) |
90e4755a | 8797 | { |
dfa9f0d5 | 8798 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 ZW |
8799 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
8800 | inst.instruction |= inst.operands[0].reg; | |
8801 | inst.reloc.pc_rel = 1; | |
8802 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
8803 | } | |
90e4755a | 8804 | |
62b3e311 PB |
8805 | static void |
8806 | do_t_dbg (void) | |
8807 | { | |
8808 | inst.instruction |= inst.operands[0].imm; | |
8809 | } | |
8810 | ||
8811 | static void | |
8812 | do_t_div (void) | |
8813 | { | |
8814 | if (!inst.operands[1].present) | |
8815 | inst.operands[1].reg = inst.operands[0].reg; | |
8816 | inst.instruction |= inst.operands[0].reg << 8; | |
8817 | inst.instruction |= inst.operands[1].reg << 16; | |
8818 | inst.instruction |= inst.operands[2].reg; | |
8819 | } | |
8820 | ||
c19d1205 ZW |
8821 | static void |
8822 | do_t_hint (void) | |
8823 | { | |
8824 | if (unified_syntax && inst.size_req == 4) | |
8825 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8826 | else | |
8827 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8828 | } | |
90e4755a | 8829 | |
c19d1205 ZW |
8830 | static void |
8831 | do_t_it (void) | |
8832 | { | |
8833 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 8834 | |
dfa9f0d5 | 8835 | constraint (current_it_mask, BAD_NOT_IT); |
e27ec89e PB |
8836 | current_it_mask = (inst.instruction & 0xf) | 0x10; |
8837 | current_cc = cond; | |
8838 | ||
8839 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 8840 | if ((cond & 0x1) == 0x0) |
90e4755a | 8841 | { |
c19d1205 | 8842 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 8843 | |
c19d1205 ZW |
8844 | if ((mask & 0x7) == 0) |
8845 | /* no conversion needed */; | |
8846 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
8847 | mask ^= 0x8; |
8848 | else if ((mask & 0x1) == 0) | |
8849 | mask ^= 0xC; | |
c19d1205 | 8850 | else |
e27ec89e | 8851 | mask ^= 0xE; |
90e4755a | 8852 | |
e27ec89e PB |
8853 | inst.instruction &= 0xfff0; |
8854 | inst.instruction |= mask; | |
c19d1205 | 8855 | } |
90e4755a | 8856 | |
c19d1205 ZW |
8857 | inst.instruction |= cond << 4; |
8858 | } | |
90e4755a | 8859 | |
c19d1205 ZW |
8860 | static void |
8861 | do_t_ldmstm (void) | |
8862 | { | |
8863 | /* This really doesn't seem worth it. */ | |
8864 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
8865 | _("expression too complex")); | |
8866 | constraint (inst.operands[1].writeback, | |
8867 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 8868 | |
c19d1205 ZW |
8869 | if (unified_syntax) |
8870 | { | |
8871 | /* See if we can use a 16-bit instruction. */ | |
8872 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
8873 | && inst.size_req != 4 | |
8874 | && inst.operands[0].reg <= 7 | |
8875 | && !(inst.operands[1].imm & ~0xff) | |
8876 | && (inst.instruction == T_MNEM_stmia | |
8877 | ? inst.operands[0].writeback | |
8878 | : (inst.operands[0].writeback | |
8879 | == !(inst.operands[1].imm & (1 << inst.operands[0].reg))))) | |
90e4755a | 8880 | { |
c19d1205 ZW |
8881 | if (inst.instruction == T_MNEM_stmia |
8882 | && (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
8883 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
8884 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
8885 | inst.operands[0].reg); | |
90e4755a | 8886 | |
c19d1205 ZW |
8887 | inst.instruction = THUMB_OP16 (inst.instruction); |
8888 | inst.instruction |= inst.operands[0].reg << 8; | |
8889 | inst.instruction |= inst.operands[1].imm; | |
8890 | } | |
8891 | else | |
8892 | { | |
8893 | if (inst.operands[1].imm & (1 << 13)) | |
8894 | as_warn (_("SP should not be in register list")); | |
8895 | if (inst.instruction == T_MNEM_stmia) | |
90e4755a | 8896 | { |
c19d1205 ZW |
8897 | if (inst.operands[1].imm & (1 << 15)) |
8898 | as_warn (_("PC should not be in register list")); | |
8899 | if (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
8900 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
8901 | inst.operands[0].reg); | |
90e4755a RE |
8902 | } |
8903 | else | |
8904 | { | |
c19d1205 ZW |
8905 | if (inst.operands[1].imm & (1 << 14) |
8906 | && inst.operands[1].imm & (1 << 15)) | |
8907 | as_warn (_("LR and PC should not both be in register list")); | |
8908 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
8909 | && inst.operands[0].writeback) | |
8910 | as_warn (_("base register should not be in register list " | |
8911 | "when written back")); | |
90e4755a | 8912 | } |
c19d1205 ZW |
8913 | if (inst.instruction < 0xffff) |
8914 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8915 | inst.instruction |= inst.operands[0].reg << 16; | |
8916 | inst.instruction |= inst.operands[1].imm; | |
8917 | if (inst.operands[0].writeback) | |
8918 | inst.instruction |= WRITE_BACK; | |
90e4755a RE |
8919 | } |
8920 | } | |
c19d1205 | 8921 | else |
90e4755a | 8922 | { |
c19d1205 ZW |
8923 | constraint (inst.operands[0].reg > 7 |
8924 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
8925 | if (inst.instruction == T_MNEM_stmia) | |
f03698e6 | 8926 | { |
c19d1205 ZW |
8927 | if (!inst.operands[0].writeback) |
8928 | as_warn (_("this instruction will write back the base register")); | |
8929 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
8930 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
8931 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
8932 | inst.operands[0].reg); | |
f03698e6 | 8933 | } |
c19d1205 | 8934 | else |
90e4755a | 8935 | { |
c19d1205 ZW |
8936 | if (!inst.operands[0].writeback |
8937 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
8938 | as_warn (_("this instruction will write back the base register")); | |
8939 | else if (inst.operands[0].writeback | |
8940 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
8941 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
8942 | } |
8943 | ||
c19d1205 ZW |
8944 | inst.instruction = THUMB_OP16 (inst.instruction); |
8945 | inst.instruction |= inst.operands[0].reg << 8; | |
8946 | inst.instruction |= inst.operands[1].imm; | |
8947 | } | |
8948 | } | |
e28cd48c | 8949 | |
c19d1205 ZW |
8950 | static void |
8951 | do_t_ldrex (void) | |
8952 | { | |
8953 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
8954 | || inst.operands[1].postind || inst.operands[1].writeback | |
8955 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
8956 | || inst.operands[1].negative, | |
01cfc07f | 8957 | BAD_ADDR_MODE); |
e28cd48c | 8958 | |
c19d1205 ZW |
8959 | inst.instruction |= inst.operands[0].reg << 12; |
8960 | inst.instruction |= inst.operands[1].reg << 16; | |
8961 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
8962 | } | |
e28cd48c | 8963 | |
c19d1205 ZW |
8964 | static void |
8965 | do_t_ldrexd (void) | |
8966 | { | |
8967 | if (!inst.operands[1].present) | |
1cac9012 | 8968 | { |
c19d1205 ZW |
8969 | constraint (inst.operands[0].reg == REG_LR, |
8970 | _("r14 not allowed as first register " | |
8971 | "when second register is omitted")); | |
8972 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 8973 | } |
c19d1205 ZW |
8974 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
8975 | BAD_OVERLAP); | |
b99bd4ef | 8976 | |
c19d1205 ZW |
8977 | inst.instruction |= inst.operands[0].reg << 12; |
8978 | inst.instruction |= inst.operands[1].reg << 8; | |
8979 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8980 | } |
8981 | ||
8982 | static void | |
c19d1205 | 8983 | do_t_ldst (void) |
b99bd4ef | 8984 | { |
0110f2b8 PB |
8985 | unsigned long opcode; |
8986 | int Rn; | |
8987 | ||
8988 | opcode = inst.instruction; | |
c19d1205 | 8989 | if (unified_syntax) |
b99bd4ef | 8990 | { |
53365c0d PB |
8991 | if (!inst.operands[1].isreg) |
8992 | { | |
8993 | if (opcode <= 0xffff) | |
8994 | inst.instruction = THUMB_OP32 (opcode); | |
8995 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
8996 | return; | |
8997 | } | |
0110f2b8 PB |
8998 | if (inst.operands[1].isreg |
8999 | && !inst.operands[1].writeback | |
c19d1205 ZW |
9000 | && !inst.operands[1].shifted && !inst.operands[1].postind |
9001 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
9002 | && opcode <= 0xffff |
9003 | && inst.size_req != 4) | |
c19d1205 | 9004 | { |
0110f2b8 PB |
9005 | /* Insn may have a 16-bit form. */ |
9006 | Rn = inst.operands[1].reg; | |
9007 | if (inst.operands[1].immisreg) | |
9008 | { | |
9009 | inst.instruction = THUMB_OP16 (opcode); | |
9010 | /* [Rn, Ri] */ | |
9011 | if (Rn <= 7 && inst.operands[1].imm <= 7) | |
9012 | goto op16; | |
9013 | } | |
9014 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
9015 | && opcode != T_MNEM_ldrsb) | |
9016 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
9017 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
9018 | { | |
9019 | /* [Rn, #const] */ | |
9020 | if (Rn > 7) | |
9021 | { | |
9022 | if (Rn == REG_PC) | |
9023 | { | |
9024 | if (inst.reloc.pc_rel) | |
9025 | opcode = T_MNEM_ldr_pc2; | |
9026 | else | |
9027 | opcode = T_MNEM_ldr_pc; | |
9028 | } | |
9029 | else | |
9030 | { | |
9031 | if (opcode == T_MNEM_ldr) | |
9032 | opcode = T_MNEM_ldr_sp; | |
9033 | else | |
9034 | opcode = T_MNEM_str_sp; | |
9035 | } | |
9036 | inst.instruction = inst.operands[0].reg << 8; | |
9037 | } | |
9038 | else | |
9039 | { | |
9040 | inst.instruction = inst.operands[0].reg; | |
9041 | inst.instruction |= inst.operands[1].reg << 3; | |
9042 | } | |
9043 | inst.instruction |= THUMB_OP16 (opcode); | |
9044 | if (inst.size_req == 2) | |
9045 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9046 | else | |
9047 | inst.relax = opcode; | |
9048 | return; | |
9049 | } | |
c19d1205 | 9050 | } |
0110f2b8 PB |
9051 | /* Definitely a 32-bit variant. */ |
9052 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
9053 | inst.instruction |= inst.operands[0].reg << 12; |
9054 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
9055 | return; |
9056 | } | |
9057 | ||
c19d1205 ZW |
9058 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9059 | ||
9060 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 9061 | { |
c19d1205 ZW |
9062 | /* Only [Rn,Rm] is acceptable. */ |
9063 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
9064 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
9065 | || inst.operands[1].postind || inst.operands[1].shifted | |
9066 | || inst.operands[1].negative, | |
9067 | _("Thumb does not support this addressing mode")); | |
9068 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9069 | goto op16; | |
b99bd4ef | 9070 | } |
c19d1205 ZW |
9071 | |
9072 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9073 | if (!inst.operands[1].isreg) | |
9074 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9075 | return; | |
b99bd4ef | 9076 | |
c19d1205 ZW |
9077 | constraint (!inst.operands[1].preind |
9078 | || inst.operands[1].shifted | |
9079 | || inst.operands[1].writeback, | |
9080 | _("Thumb does not support this addressing mode")); | |
9081 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 9082 | { |
c19d1205 ZW |
9083 | constraint (inst.instruction & 0x0600, |
9084 | _("byte or halfword not valid for base register")); | |
9085 | constraint (inst.operands[1].reg == REG_PC | |
9086 | && !(inst.instruction & THUMB_LOAD_BIT), | |
9087 | _("r15 based store not allowed")); | |
9088 | constraint (inst.operands[1].immisreg, | |
9089 | _("invalid base register for register offset")); | |
b99bd4ef | 9090 | |
c19d1205 ZW |
9091 | if (inst.operands[1].reg == REG_PC) |
9092 | inst.instruction = T_OPCODE_LDR_PC; | |
9093 | else if (inst.instruction & THUMB_LOAD_BIT) | |
9094 | inst.instruction = T_OPCODE_LDR_SP; | |
9095 | else | |
9096 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 9097 | |
c19d1205 ZW |
9098 | inst.instruction |= inst.operands[0].reg << 8; |
9099 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9100 | return; | |
9101 | } | |
90e4755a | 9102 | |
c19d1205 ZW |
9103 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
9104 | if (!inst.operands[1].immisreg) | |
9105 | { | |
9106 | /* Immediate offset. */ | |
9107 | inst.instruction |= inst.operands[0].reg; | |
9108 | inst.instruction |= inst.operands[1].reg << 3; | |
9109 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9110 | return; | |
9111 | } | |
90e4755a | 9112 | |
c19d1205 ZW |
9113 | /* Register offset. */ |
9114 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
9115 | constraint (inst.operands[1].negative, | |
9116 | _("Thumb does not support this addressing mode")); | |
90e4755a | 9117 | |
c19d1205 ZW |
9118 | op16: |
9119 | switch (inst.instruction) | |
9120 | { | |
9121 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
9122 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
9123 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
9124 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
9125 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
9126 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
9127 | case 0x5600 /* ldrsb */: | |
9128 | case 0x5e00 /* ldrsh */: break; | |
9129 | default: abort (); | |
9130 | } | |
90e4755a | 9131 | |
c19d1205 ZW |
9132 | inst.instruction |= inst.operands[0].reg; |
9133 | inst.instruction |= inst.operands[1].reg << 3; | |
9134 | inst.instruction |= inst.operands[1].imm << 6; | |
9135 | } | |
90e4755a | 9136 | |
c19d1205 ZW |
9137 | static void |
9138 | do_t_ldstd (void) | |
9139 | { | |
9140 | if (!inst.operands[1].present) | |
b99bd4ef | 9141 | { |
c19d1205 ZW |
9142 | inst.operands[1].reg = inst.operands[0].reg + 1; |
9143 | constraint (inst.operands[0].reg == REG_LR, | |
9144 | _("r14 not allowed here")); | |
b99bd4ef | 9145 | } |
c19d1205 ZW |
9146 | inst.instruction |= inst.operands[0].reg << 12; |
9147 | inst.instruction |= inst.operands[1].reg << 8; | |
9148 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
9149 | ||
b99bd4ef NC |
9150 | } |
9151 | ||
c19d1205 ZW |
9152 | static void |
9153 | do_t_ldstt (void) | |
9154 | { | |
9155 | inst.instruction |= inst.operands[0].reg << 12; | |
9156 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
9157 | } | |
a737bd4d | 9158 | |
b99bd4ef | 9159 | static void |
c19d1205 | 9160 | do_t_mla (void) |
b99bd4ef | 9161 | { |
c19d1205 ZW |
9162 | inst.instruction |= inst.operands[0].reg << 8; |
9163 | inst.instruction |= inst.operands[1].reg << 16; | |
9164 | inst.instruction |= inst.operands[2].reg; | |
9165 | inst.instruction |= inst.operands[3].reg << 12; | |
9166 | } | |
b99bd4ef | 9167 | |
c19d1205 ZW |
9168 | static void |
9169 | do_t_mlal (void) | |
9170 | { | |
9171 | inst.instruction |= inst.operands[0].reg << 12; | |
9172 | inst.instruction |= inst.operands[1].reg << 8; | |
9173 | inst.instruction |= inst.operands[2].reg << 16; | |
9174 | inst.instruction |= inst.operands[3].reg; | |
9175 | } | |
b99bd4ef | 9176 | |
c19d1205 ZW |
9177 | static void |
9178 | do_t_mov_cmp (void) | |
9179 | { | |
9180 | if (unified_syntax) | |
b99bd4ef | 9181 | { |
c19d1205 ZW |
9182 | int r0off = (inst.instruction == T_MNEM_mov |
9183 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 9184 | unsigned long opcode; |
3d388997 PB |
9185 | bfd_boolean narrow; |
9186 | bfd_boolean low_regs; | |
9187 | ||
9188 | low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7); | |
0110f2b8 | 9189 | opcode = inst.instruction; |
3d388997 | 9190 | if (current_it_mask) |
0110f2b8 | 9191 | narrow = opcode != T_MNEM_movs; |
3d388997 | 9192 | else |
0110f2b8 | 9193 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
9194 | if (inst.size_req == 4 |
9195 | || inst.operands[1].shifted) | |
9196 | narrow = FALSE; | |
9197 | ||
c19d1205 ZW |
9198 | if (!inst.operands[1].isreg) |
9199 | { | |
0110f2b8 PB |
9200 | /* Immediate operand. */ |
9201 | if (current_it_mask == 0 && opcode == T_MNEM_mov) | |
9202 | narrow = 0; | |
9203 | if (low_regs && narrow) | |
9204 | { | |
9205 | inst.instruction = THUMB_OP16 (opcode); | |
9206 | inst.instruction |= inst.operands[0].reg << 8; | |
9207 | if (inst.size_req == 2) | |
9208 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
9209 | else | |
9210 | inst.relax = opcode; | |
9211 | } | |
9212 | else | |
9213 | { | |
9214 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9215 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9216 | inst.instruction |= inst.operands[0].reg << r0off; | |
9217 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9218 | } | |
c19d1205 | 9219 | } |
3d388997 | 9220 | else if (!narrow) |
c19d1205 ZW |
9221 | { |
9222 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9223 | inst.instruction |= inst.operands[0].reg << r0off; | |
9224 | encode_thumb32_shifted_operand (1); | |
9225 | } | |
9226 | else | |
9227 | switch (inst.instruction) | |
9228 | { | |
9229 | case T_MNEM_mov: | |
9230 | inst.instruction = T_OPCODE_MOV_HR; | |
9231 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
9232 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9233 | inst.instruction |= inst.operands[1].reg << 3; | |
9234 | break; | |
b99bd4ef | 9235 | |
c19d1205 ZW |
9236 | case T_MNEM_movs: |
9237 | /* We know we have low registers at this point. | |
9238 | Generate ADD Rd, Rs, #0. */ | |
9239 | inst.instruction = T_OPCODE_ADD_I3; | |
9240 | inst.instruction |= inst.operands[0].reg; | |
9241 | inst.instruction |= inst.operands[1].reg << 3; | |
9242 | break; | |
9243 | ||
9244 | case T_MNEM_cmp: | |
3d388997 | 9245 | if (low_regs) |
c19d1205 ZW |
9246 | { |
9247 | inst.instruction = T_OPCODE_CMP_LR; | |
9248 | inst.instruction |= inst.operands[0].reg; | |
9249 | inst.instruction |= inst.operands[1].reg << 3; | |
9250 | } | |
9251 | else | |
9252 | { | |
9253 | inst.instruction = T_OPCODE_CMP_HR; | |
9254 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
9255 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9256 | inst.instruction |= inst.operands[1].reg << 3; | |
9257 | } | |
9258 | break; | |
9259 | } | |
b99bd4ef NC |
9260 | return; |
9261 | } | |
9262 | ||
c19d1205 ZW |
9263 | inst.instruction = THUMB_OP16 (inst.instruction); |
9264 | if (inst.operands[1].isreg) | |
b99bd4ef | 9265 | { |
c19d1205 | 9266 | if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8) |
b99bd4ef | 9267 | { |
c19d1205 ZW |
9268 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
9269 | since a MOV instruction produces unpredictable results. */ | |
9270 | if (inst.instruction == T_OPCODE_MOV_I8) | |
9271 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 9272 | else |
c19d1205 | 9273 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 9274 | |
c19d1205 ZW |
9275 | inst.instruction |= inst.operands[0].reg; |
9276 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
9277 | } |
9278 | else | |
9279 | { | |
c19d1205 ZW |
9280 | if (inst.instruction == T_OPCODE_MOV_I8) |
9281 | inst.instruction = T_OPCODE_MOV_HR; | |
9282 | else | |
9283 | inst.instruction = T_OPCODE_CMP_HR; | |
9284 | do_t_cpy (); | |
b99bd4ef NC |
9285 | } |
9286 | } | |
c19d1205 | 9287 | else |
b99bd4ef | 9288 | { |
c19d1205 ZW |
9289 | constraint (inst.operands[0].reg > 7, |
9290 | _("only lo regs allowed with immediate")); | |
9291 | inst.instruction |= inst.operands[0].reg << 8; | |
9292 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
9293 | } | |
9294 | } | |
b99bd4ef | 9295 | |
c19d1205 ZW |
9296 | static void |
9297 | do_t_mov16 (void) | |
9298 | { | |
b6895b4f PB |
9299 | bfd_vma imm; |
9300 | bfd_boolean top; | |
9301 | ||
9302 | top = (inst.instruction & 0x00800000) != 0; | |
9303 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
9304 | { | |
9305 | constraint (top, _(":lower16: not allowed this instruction")); | |
9306 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
9307 | } | |
9308 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
9309 | { | |
9310 | constraint (!top, _(":upper16: not allowed this instruction")); | |
9311 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
9312 | } | |
9313 | ||
c19d1205 | 9314 | inst.instruction |= inst.operands[0].reg << 8; |
b6895b4f PB |
9315 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
9316 | { | |
9317 | imm = inst.reloc.exp.X_add_number; | |
9318 | inst.instruction |= (imm & 0xf000) << 4; | |
9319 | inst.instruction |= (imm & 0x0800) << 15; | |
9320 | inst.instruction |= (imm & 0x0700) << 4; | |
9321 | inst.instruction |= (imm & 0x00ff); | |
9322 | } | |
c19d1205 | 9323 | } |
b99bd4ef | 9324 | |
c19d1205 ZW |
9325 | static void |
9326 | do_t_mvn_tst (void) | |
9327 | { | |
9328 | if (unified_syntax) | |
9329 | { | |
9330 | int r0off = (inst.instruction == T_MNEM_mvn | |
9331 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
9332 | bfd_boolean narrow; |
9333 | ||
9334 | if (inst.size_req == 4 | |
9335 | || inst.instruction > 0xffff | |
9336 | || inst.operands[1].shifted | |
9337 | || inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
9338 | narrow = FALSE; | |
9339 | else if (inst.instruction == T_MNEM_cmn) | |
9340 | narrow = TRUE; | |
9341 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
9342 | narrow = (current_it_mask == 0); | |
9343 | else | |
9344 | narrow = (current_it_mask != 0); | |
9345 | ||
c19d1205 | 9346 | if (!inst.operands[1].isreg) |
b99bd4ef | 9347 | { |
c19d1205 ZW |
9348 | /* For an immediate, we always generate a 32-bit opcode; |
9349 | section relaxation will shrink it later if possible. */ | |
9350 | if (inst.instruction < 0xffff) | |
9351 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9352 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9353 | inst.instruction |= inst.operands[0].reg << r0off; | |
9354 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 9355 | } |
c19d1205 | 9356 | else |
b99bd4ef | 9357 | { |
c19d1205 | 9358 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 9359 | if (narrow) |
b99bd4ef | 9360 | { |
c19d1205 ZW |
9361 | inst.instruction = THUMB_OP16 (inst.instruction); |
9362 | inst.instruction |= inst.operands[0].reg; | |
9363 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 9364 | } |
c19d1205 | 9365 | else |
b99bd4ef | 9366 | { |
c19d1205 ZW |
9367 | constraint (inst.operands[1].shifted |
9368 | && inst.operands[1].immisreg, | |
9369 | _("shift must be constant")); | |
9370 | if (inst.instruction < 0xffff) | |
9371 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9372 | inst.instruction |= inst.operands[0].reg << r0off; | |
9373 | encode_thumb32_shifted_operand (1); | |
b99bd4ef | 9374 | } |
b99bd4ef NC |
9375 | } |
9376 | } | |
9377 | else | |
9378 | { | |
c19d1205 ZW |
9379 | constraint (inst.instruction > 0xffff |
9380 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
9381 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
9382 | _("unshifted register required")); | |
9383 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
9384 | BAD_HIREG); | |
b99bd4ef | 9385 | |
c19d1205 ZW |
9386 | inst.instruction = THUMB_OP16 (inst.instruction); |
9387 | inst.instruction |= inst.operands[0].reg; | |
9388 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 9389 | } |
b99bd4ef NC |
9390 | } |
9391 | ||
b05fe5cf | 9392 | static void |
c19d1205 | 9393 | do_t_mrs (void) |
b05fe5cf | 9394 | { |
62b3e311 | 9395 | int flags; |
037e8744 JB |
9396 | |
9397 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
9398 | return; | |
9399 | ||
62b3e311 PB |
9400 | flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
9401 | if (flags == 0) | |
9402 | { | |
9403 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m), | |
9404 | _("selected processor does not support " | |
9405 | "requested special purpose register")); | |
9406 | } | |
9407 | else | |
9408 | { | |
9409 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
9410 | _("selected processor does not support " | |
9411 | "requested special purpose register %x")); | |
9412 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
9413 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
9414 | _("'CPSR' or 'SPSR' expected")); | |
9415 | } | |
9416 | ||
c19d1205 | 9417 | inst.instruction |= inst.operands[0].reg << 8; |
62b3e311 PB |
9418 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
9419 | inst.instruction |= inst.operands[1].imm & 0xff; | |
c19d1205 | 9420 | } |
b05fe5cf | 9421 | |
c19d1205 ZW |
9422 | static void |
9423 | do_t_msr (void) | |
9424 | { | |
62b3e311 PB |
9425 | int flags; |
9426 | ||
037e8744 JB |
9427 | if (do_vfp_nsyn_msr () == SUCCESS) |
9428 | return; | |
9429 | ||
c19d1205 ZW |
9430 | constraint (!inst.operands[1].isreg, |
9431 | _("Thumb encoding does not support an immediate here")); | |
62b3e311 PB |
9432 | flags = inst.operands[0].imm; |
9433 | if (flags & ~0xff) | |
9434 | { | |
9435 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
9436 | _("selected processor does not support " | |
9437 | "requested special purpose register")); | |
9438 | } | |
9439 | else | |
9440 | { | |
9441 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m), | |
9442 | _("selected processor does not support " | |
9443 | "requested special purpose register")); | |
9444 | flags |= PSR_f; | |
9445 | } | |
9446 | inst.instruction |= (flags & SPSR_BIT) >> 2; | |
9447 | inst.instruction |= (flags & ~SPSR_BIT) >> 8; | |
9448 | inst.instruction |= (flags & 0xff); | |
c19d1205 ZW |
9449 | inst.instruction |= inst.operands[1].reg << 16; |
9450 | } | |
b05fe5cf | 9451 | |
c19d1205 ZW |
9452 | static void |
9453 | do_t_mul (void) | |
9454 | { | |
9455 | if (!inst.operands[2].present) | |
9456 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 9457 | |
c19d1205 ZW |
9458 | /* There is no 32-bit MULS and no 16-bit MUL. */ |
9459 | if (unified_syntax && inst.instruction == T_MNEM_mul) | |
b05fe5cf | 9460 | { |
c19d1205 ZW |
9461 | inst.instruction = THUMB_OP32 (inst.instruction); |
9462 | inst.instruction |= inst.operands[0].reg << 8; | |
9463 | inst.instruction |= inst.operands[1].reg << 16; | |
9464 | inst.instruction |= inst.operands[2].reg << 0; | |
b05fe5cf | 9465 | } |
c19d1205 | 9466 | else |
b05fe5cf | 9467 | { |
c19d1205 ZW |
9468 | constraint (!unified_syntax |
9469 | && inst.instruction == T_MNEM_muls, BAD_THUMB32); | |
9470 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
9471 | BAD_HIREG); | |
b05fe5cf | 9472 | |
c19d1205 ZW |
9473 | inst.instruction = THUMB_OP16 (inst.instruction); |
9474 | inst.instruction |= inst.operands[0].reg; | |
b05fe5cf | 9475 | |
c19d1205 ZW |
9476 | if (inst.operands[0].reg == inst.operands[1].reg) |
9477 | inst.instruction |= inst.operands[2].reg << 3; | |
9478 | else if (inst.operands[0].reg == inst.operands[2].reg) | |
9479 | inst.instruction |= inst.operands[1].reg << 3; | |
9480 | else | |
9481 | constraint (1, _("dest must overlap one source register")); | |
9482 | } | |
9483 | } | |
b05fe5cf | 9484 | |
c19d1205 ZW |
9485 | static void |
9486 | do_t_mull (void) | |
9487 | { | |
9488 | inst.instruction |= inst.operands[0].reg << 12; | |
9489 | inst.instruction |= inst.operands[1].reg << 8; | |
9490 | inst.instruction |= inst.operands[2].reg << 16; | |
9491 | inst.instruction |= inst.operands[3].reg; | |
b05fe5cf | 9492 | |
c19d1205 ZW |
9493 | if (inst.operands[0].reg == inst.operands[1].reg) |
9494 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9495 | } | |
b05fe5cf | 9496 | |
c19d1205 ZW |
9497 | static void |
9498 | do_t_nop (void) | |
9499 | { | |
9500 | if (unified_syntax) | |
9501 | { | |
9502 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 9503 | { |
c19d1205 ZW |
9504 | inst.instruction = THUMB_OP32 (inst.instruction); |
9505 | inst.instruction |= inst.operands[0].imm; | |
9506 | } | |
9507 | else | |
9508 | { | |
9509 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9510 | inst.instruction |= inst.operands[0].imm << 4; | |
9511 | } | |
9512 | } | |
9513 | else | |
9514 | { | |
9515 | constraint (inst.operands[0].present, | |
9516 | _("Thumb does not support NOP with hints")); | |
9517 | inst.instruction = 0x46c0; | |
9518 | } | |
9519 | } | |
b05fe5cf | 9520 | |
c19d1205 ZW |
9521 | static void |
9522 | do_t_neg (void) | |
9523 | { | |
9524 | if (unified_syntax) | |
9525 | { | |
3d388997 PB |
9526 | bfd_boolean narrow; |
9527 | ||
9528 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
9529 | narrow = (current_it_mask == 0); | |
9530 | else | |
9531 | narrow = (current_it_mask != 0); | |
9532 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
9533 | narrow = FALSE; | |
9534 | if (inst.size_req == 4) | |
9535 | narrow = FALSE; | |
9536 | ||
9537 | if (!narrow) | |
c19d1205 ZW |
9538 | { |
9539 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9540 | inst.instruction |= inst.operands[0].reg << 8; | |
9541 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
9542 | } |
9543 | else | |
9544 | { | |
c19d1205 ZW |
9545 | inst.instruction = THUMB_OP16 (inst.instruction); |
9546 | inst.instruction |= inst.operands[0].reg; | |
9547 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
9548 | } |
9549 | } | |
9550 | else | |
9551 | { | |
c19d1205 ZW |
9552 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
9553 | BAD_HIREG); | |
9554 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
9555 | ||
9556 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9557 | inst.instruction |= inst.operands[0].reg; | |
9558 | inst.instruction |= inst.operands[1].reg << 3; | |
9559 | } | |
9560 | } | |
9561 | ||
9562 | static void | |
9563 | do_t_pkhbt (void) | |
9564 | { | |
9565 | inst.instruction |= inst.operands[0].reg << 8; | |
9566 | inst.instruction |= inst.operands[1].reg << 16; | |
9567 | inst.instruction |= inst.operands[2].reg; | |
9568 | if (inst.operands[3].present) | |
9569 | { | |
9570 | unsigned int val = inst.reloc.exp.X_add_number; | |
9571 | constraint (inst.reloc.exp.X_op != O_constant, | |
9572 | _("expression too complex")); | |
9573 | inst.instruction |= (val & 0x1c) << 10; | |
9574 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 9575 | } |
c19d1205 | 9576 | } |
b05fe5cf | 9577 | |
c19d1205 ZW |
9578 | static void |
9579 | do_t_pkhtb (void) | |
9580 | { | |
9581 | if (!inst.operands[3].present) | |
9582 | inst.instruction &= ~0x00000020; | |
9583 | do_t_pkhbt (); | |
b05fe5cf ZW |
9584 | } |
9585 | ||
c19d1205 ZW |
9586 | static void |
9587 | do_t_pld (void) | |
9588 | { | |
9589 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
9590 | } | |
b05fe5cf | 9591 | |
c19d1205 ZW |
9592 | static void |
9593 | do_t_push_pop (void) | |
b99bd4ef | 9594 | { |
e9f89963 PB |
9595 | unsigned mask; |
9596 | ||
c19d1205 ZW |
9597 | constraint (inst.operands[0].writeback, |
9598 | _("push/pop do not support {reglist}^")); | |
9599 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9600 | _("expression too complex")); | |
b99bd4ef | 9601 | |
e9f89963 PB |
9602 | mask = inst.operands[0].imm; |
9603 | if ((mask & ~0xff) == 0) | |
c19d1205 ZW |
9604 | inst.instruction = THUMB_OP16 (inst.instruction); |
9605 | else if ((inst.instruction == T_MNEM_push | |
e9f89963 | 9606 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 9607 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 9608 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 9609 | { |
c19d1205 ZW |
9610 | inst.instruction = THUMB_OP16 (inst.instruction); |
9611 | inst.instruction |= THUMB_PP_PC_LR; | |
e9f89963 | 9612 | mask &= 0xff; |
c19d1205 ZW |
9613 | } |
9614 | else if (unified_syntax) | |
9615 | { | |
e9f89963 PB |
9616 | if (mask & (1 << 13)) |
9617 | inst.error = _("SP not allowed in register list"); | |
c19d1205 | 9618 | if (inst.instruction == T_MNEM_push) |
b99bd4ef | 9619 | { |
e9f89963 PB |
9620 | if (mask & (1 << 15)) |
9621 | inst.error = _("PC not allowed in register list"); | |
c19d1205 ZW |
9622 | } |
9623 | else | |
9624 | { | |
e9f89963 PB |
9625 | if (mask & (1 << 14) |
9626 | && mask & (1 << 15)) | |
9627 | inst.error = _("LR and PC should not both be in register list"); | |
c19d1205 | 9628 | } |
e9f89963 PB |
9629 | if ((mask & (mask - 1)) == 0) |
9630 | { | |
9631 | /* Single register push/pop implemented as str/ldr. */ | |
9632 | if (inst.instruction == T_MNEM_push) | |
9633 | inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */ | |
9634 | else | |
9635 | inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */ | |
9636 | mask = ffs(mask) - 1; | |
9637 | mask <<= 12; | |
9638 | } | |
9639 | else | |
9640 | inst.instruction = THUMB_OP32 (inst.instruction); | |
c19d1205 ZW |
9641 | } |
9642 | else | |
9643 | { | |
9644 | inst.error = _("invalid register list to push/pop instruction"); | |
9645 | return; | |
9646 | } | |
b99bd4ef | 9647 | |
e9f89963 | 9648 | inst.instruction |= mask; |
c19d1205 | 9649 | } |
b99bd4ef | 9650 | |
c19d1205 ZW |
9651 | static void |
9652 | do_t_rbit (void) | |
9653 | { | |
9654 | inst.instruction |= inst.operands[0].reg << 8; | |
9655 | inst.instruction |= inst.operands[1].reg << 16; | |
9656 | } | |
b99bd4ef | 9657 | |
c19d1205 ZW |
9658 | static void |
9659 | do_t_rev (void) | |
9660 | { | |
9661 | if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
9662 | && inst.size_req != 4) | |
9663 | { | |
9664 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9665 | inst.instruction |= inst.operands[0].reg; | |
9666 | inst.instruction |= inst.operands[1].reg << 3; | |
9667 | } | |
9668 | else if (unified_syntax) | |
9669 | { | |
9670 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9671 | inst.instruction |= inst.operands[0].reg << 8; | |
9672 | inst.instruction |= inst.operands[1].reg << 16; | |
9673 | inst.instruction |= inst.operands[1].reg; | |
9674 | } | |
9675 | else | |
9676 | inst.error = BAD_HIREG; | |
9677 | } | |
b99bd4ef | 9678 | |
c19d1205 ZW |
9679 | static void |
9680 | do_t_rsb (void) | |
9681 | { | |
9682 | int Rd, Rs; | |
b99bd4ef | 9683 | |
c19d1205 ZW |
9684 | Rd = inst.operands[0].reg; |
9685 | Rs = (inst.operands[1].present | |
9686 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9687 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 9688 | |
c19d1205 ZW |
9689 | inst.instruction |= Rd << 8; |
9690 | inst.instruction |= Rs << 16; | |
9691 | if (!inst.operands[2].isreg) | |
9692 | { | |
9693 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9694 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9695 | } | |
9696 | else | |
9697 | encode_thumb32_shifted_operand (2); | |
9698 | } | |
b99bd4ef | 9699 | |
c19d1205 ZW |
9700 | static void |
9701 | do_t_setend (void) | |
9702 | { | |
dfa9f0d5 | 9703 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 ZW |
9704 | if (inst.operands[0].imm) |
9705 | inst.instruction |= 0x8; | |
9706 | } | |
b99bd4ef | 9707 | |
c19d1205 ZW |
9708 | static void |
9709 | do_t_shift (void) | |
9710 | { | |
9711 | if (!inst.operands[1].present) | |
9712 | inst.operands[1].reg = inst.operands[0].reg; | |
9713 | ||
9714 | if (unified_syntax) | |
9715 | { | |
3d388997 PB |
9716 | bfd_boolean narrow; |
9717 | int shift_kind; | |
9718 | ||
9719 | switch (inst.instruction) | |
9720 | { | |
9721 | case T_MNEM_asr: | |
9722 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
9723 | case T_MNEM_lsl: | |
9724 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
9725 | case T_MNEM_lsr: | |
9726 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
9727 | case T_MNEM_ror: | |
9728 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
9729 | default: abort (); | |
9730 | } | |
9731 | ||
9732 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
9733 | narrow = (current_it_mask == 0); | |
9734 | else | |
9735 | narrow = (current_it_mask != 0); | |
9736 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
9737 | narrow = FALSE; | |
9738 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
9739 | narrow = FALSE; | |
9740 | if (inst.operands[2].isreg | |
9741 | && (inst.operands[1].reg != inst.operands[0].reg | |
9742 | || inst.operands[2].reg > 7)) | |
9743 | narrow = FALSE; | |
9744 | if (inst.size_req == 4) | |
9745 | narrow = FALSE; | |
9746 | ||
9747 | if (!narrow) | |
c19d1205 ZW |
9748 | { |
9749 | if (inst.operands[2].isreg) | |
b99bd4ef | 9750 | { |
c19d1205 ZW |
9751 | inst.instruction = THUMB_OP32 (inst.instruction); |
9752 | inst.instruction |= inst.operands[0].reg << 8; | |
9753 | inst.instruction |= inst.operands[1].reg << 16; | |
9754 | inst.instruction |= inst.operands[2].reg; | |
9755 | } | |
9756 | else | |
9757 | { | |
9758 | inst.operands[1].shifted = 1; | |
3d388997 | 9759 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
9760 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
9761 | ? T_MNEM_movs : T_MNEM_mov); | |
9762 | inst.instruction |= inst.operands[0].reg << 8; | |
9763 | encode_thumb32_shifted_operand (1); | |
9764 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
9765 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
9766 | } |
9767 | } | |
9768 | else | |
9769 | { | |
c19d1205 | 9770 | if (inst.operands[2].isreg) |
b99bd4ef | 9771 | { |
3d388997 | 9772 | switch (shift_kind) |
b99bd4ef | 9773 | { |
3d388997 PB |
9774 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
9775 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
9776 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
9777 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 9778 | default: abort (); |
b99bd4ef | 9779 | } |
c19d1205 ZW |
9780 | |
9781 | inst.instruction |= inst.operands[0].reg; | |
9782 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
9783 | } |
9784 | else | |
9785 | { | |
3d388997 | 9786 | switch (shift_kind) |
b99bd4ef | 9787 | { |
3d388997 PB |
9788 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
9789 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
9790 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 9791 | default: abort (); |
b99bd4ef | 9792 | } |
c19d1205 ZW |
9793 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
9794 | inst.instruction |= inst.operands[0].reg; | |
9795 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
9796 | } |
9797 | } | |
c19d1205 ZW |
9798 | } |
9799 | else | |
9800 | { | |
9801 | constraint (inst.operands[0].reg > 7 | |
9802 | || inst.operands[1].reg > 7, BAD_HIREG); | |
9803 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 9804 | |
c19d1205 ZW |
9805 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
9806 | { | |
9807 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
9808 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
9809 | _("source1 and dest must be same register")); | |
b99bd4ef | 9810 | |
c19d1205 ZW |
9811 | switch (inst.instruction) |
9812 | { | |
9813 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
9814 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
9815 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
9816 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
9817 | default: abort (); | |
9818 | } | |
9819 | ||
9820 | inst.instruction |= inst.operands[0].reg; | |
9821 | inst.instruction |= inst.operands[2].reg << 3; | |
9822 | } | |
9823 | else | |
b99bd4ef | 9824 | { |
c19d1205 ZW |
9825 | switch (inst.instruction) |
9826 | { | |
9827 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
9828 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
9829 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
9830 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
9831 | default: abort (); | |
9832 | } | |
9833 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
9834 | inst.instruction |= inst.operands[0].reg; | |
9835 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
9836 | } |
9837 | } | |
b99bd4ef NC |
9838 | } |
9839 | ||
9840 | static void | |
c19d1205 | 9841 | do_t_simd (void) |
b99bd4ef | 9842 | { |
c19d1205 ZW |
9843 | inst.instruction |= inst.operands[0].reg << 8; |
9844 | inst.instruction |= inst.operands[1].reg << 16; | |
9845 | inst.instruction |= inst.operands[2].reg; | |
9846 | } | |
b99bd4ef | 9847 | |
c19d1205 | 9848 | static void |
3eb17e6b | 9849 | do_t_smc (void) |
c19d1205 ZW |
9850 | { |
9851 | unsigned int value = inst.reloc.exp.X_add_number; | |
9852 | constraint (inst.reloc.exp.X_op != O_constant, | |
9853 | _("expression too complex")); | |
9854 | inst.reloc.type = BFD_RELOC_UNUSED; | |
9855 | inst.instruction |= (value & 0xf000) >> 12; | |
9856 | inst.instruction |= (value & 0x0ff0); | |
9857 | inst.instruction |= (value & 0x000f) << 16; | |
9858 | } | |
b99bd4ef | 9859 | |
c19d1205 ZW |
9860 | static void |
9861 | do_t_ssat (void) | |
9862 | { | |
9863 | inst.instruction |= inst.operands[0].reg << 8; | |
9864 | inst.instruction |= inst.operands[1].imm - 1; | |
9865 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 9866 | |
c19d1205 | 9867 | if (inst.operands[3].present) |
b99bd4ef | 9868 | { |
c19d1205 ZW |
9869 | constraint (inst.reloc.exp.X_op != O_constant, |
9870 | _("expression too complex")); | |
b99bd4ef | 9871 | |
c19d1205 | 9872 | if (inst.reloc.exp.X_add_number != 0) |
6189168b | 9873 | { |
c19d1205 ZW |
9874 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
9875 | inst.instruction |= 0x00200000; /* sh bit */ | |
9876 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; | |
9877 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
6189168b | 9878 | } |
c19d1205 | 9879 | inst.reloc.type = BFD_RELOC_UNUSED; |
6189168b | 9880 | } |
b99bd4ef NC |
9881 | } |
9882 | ||
0dd132b6 | 9883 | static void |
c19d1205 | 9884 | do_t_ssat16 (void) |
0dd132b6 | 9885 | { |
c19d1205 ZW |
9886 | inst.instruction |= inst.operands[0].reg << 8; |
9887 | inst.instruction |= inst.operands[1].imm - 1; | |
9888 | inst.instruction |= inst.operands[2].reg << 16; | |
9889 | } | |
0dd132b6 | 9890 | |
c19d1205 ZW |
9891 | static void |
9892 | do_t_strex (void) | |
9893 | { | |
9894 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9895 | || inst.operands[2].postind || inst.operands[2].writeback | |
9896 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
9897 | || inst.operands[2].negative, | |
01cfc07f | 9898 | BAD_ADDR_MODE); |
0dd132b6 | 9899 | |
c19d1205 ZW |
9900 | inst.instruction |= inst.operands[0].reg << 8; |
9901 | inst.instruction |= inst.operands[1].reg << 12; | |
9902 | inst.instruction |= inst.operands[2].reg << 16; | |
9903 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
9904 | } |
9905 | ||
b99bd4ef | 9906 | static void |
c19d1205 | 9907 | do_t_strexd (void) |
b99bd4ef | 9908 | { |
c19d1205 ZW |
9909 | if (!inst.operands[2].present) |
9910 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 9911 | |
c19d1205 ZW |
9912 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9913 | || inst.operands[0].reg == inst.operands[2].reg | |
9914 | || inst.operands[0].reg == inst.operands[3].reg | |
9915 | || inst.operands[1].reg == inst.operands[2].reg, | |
9916 | BAD_OVERLAP); | |
b99bd4ef | 9917 | |
c19d1205 ZW |
9918 | inst.instruction |= inst.operands[0].reg; |
9919 | inst.instruction |= inst.operands[1].reg << 12; | |
9920 | inst.instruction |= inst.operands[2].reg << 8; | |
9921 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
9922 | } |
9923 | ||
9924 | static void | |
c19d1205 | 9925 | do_t_sxtah (void) |
b99bd4ef | 9926 | { |
c19d1205 ZW |
9927 | inst.instruction |= inst.operands[0].reg << 8; |
9928 | inst.instruction |= inst.operands[1].reg << 16; | |
9929 | inst.instruction |= inst.operands[2].reg; | |
9930 | inst.instruction |= inst.operands[3].imm << 4; | |
9931 | } | |
b99bd4ef | 9932 | |
c19d1205 ZW |
9933 | static void |
9934 | do_t_sxth (void) | |
9935 | { | |
9936 | if (inst.instruction <= 0xffff && inst.size_req != 4 | |
9937 | && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
9938 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) | |
b99bd4ef | 9939 | { |
c19d1205 ZW |
9940 | inst.instruction = THUMB_OP16 (inst.instruction); |
9941 | inst.instruction |= inst.operands[0].reg; | |
9942 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 9943 | } |
c19d1205 | 9944 | else if (unified_syntax) |
b99bd4ef | 9945 | { |
c19d1205 ZW |
9946 | if (inst.instruction <= 0xffff) |
9947 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9948 | inst.instruction |= inst.operands[0].reg << 8; | |
9949 | inst.instruction |= inst.operands[1].reg; | |
9950 | inst.instruction |= inst.operands[2].imm << 4; | |
b99bd4ef | 9951 | } |
c19d1205 | 9952 | else |
b99bd4ef | 9953 | { |
c19d1205 ZW |
9954 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
9955 | _("Thumb encoding does not support rotation")); | |
9956 | constraint (1, BAD_HIREG); | |
b99bd4ef | 9957 | } |
c19d1205 | 9958 | } |
b99bd4ef | 9959 | |
c19d1205 ZW |
9960 | static void |
9961 | do_t_swi (void) | |
9962 | { | |
9963 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
9964 | } | |
b99bd4ef | 9965 | |
92e90b6e PB |
9966 | static void |
9967 | do_t_tb (void) | |
9968 | { | |
9969 | int half; | |
9970 | ||
9971 | half = (inst.instruction & 0x10) != 0; | |
dfa9f0d5 PB |
9972 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
9973 | constraint (inst.operands[0].immisreg, | |
9974 | _("instruction requires register index")); | |
92e90b6e PB |
9975 | constraint (inst.operands[0].imm == 15, |
9976 | _("PC is not a valid index register")); | |
9977 | constraint (!half && inst.operands[0].shifted, | |
9978 | _("instruction does not allow shifted index")); | |
92e90b6e PB |
9979 | inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm; |
9980 | } | |
9981 | ||
c19d1205 ZW |
9982 | static void |
9983 | do_t_usat (void) | |
9984 | { | |
9985 | inst.instruction |= inst.operands[0].reg << 8; | |
9986 | inst.instruction |= inst.operands[1].imm; | |
9987 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 9988 | |
c19d1205 | 9989 | if (inst.operands[3].present) |
b99bd4ef | 9990 | { |
c19d1205 ZW |
9991 | constraint (inst.reloc.exp.X_op != O_constant, |
9992 | _("expression too complex")); | |
9993 | if (inst.reloc.exp.X_add_number != 0) | |
9994 | { | |
9995 | if (inst.operands[3].shift_kind == SHIFT_ASR) | |
9996 | inst.instruction |= 0x00200000; /* sh bit */ | |
b99bd4ef | 9997 | |
c19d1205 ZW |
9998 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; |
9999 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
10000 | } | |
10001 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 10002 | } |
b99bd4ef NC |
10003 | } |
10004 | ||
10005 | static void | |
c19d1205 | 10006 | do_t_usat16 (void) |
b99bd4ef | 10007 | { |
c19d1205 ZW |
10008 | inst.instruction |= inst.operands[0].reg << 8; |
10009 | inst.instruction |= inst.operands[1].imm; | |
10010 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 10011 | } |
c19d1205 | 10012 | |
5287ad62 JB |
10013 | /* Neon instruction encoder helpers. */ |
10014 | ||
10015 | /* Encodings for the different types for various Neon opcodes. */ | |
b99bd4ef | 10016 | |
5287ad62 JB |
10017 | /* An "invalid" code for the following tables. */ |
10018 | #define N_INV -1u | |
10019 | ||
10020 | struct neon_tab_entry | |
b99bd4ef | 10021 | { |
5287ad62 JB |
10022 | unsigned integer; |
10023 | unsigned float_or_poly; | |
10024 | unsigned scalar_or_imm; | |
10025 | }; | |
10026 | ||
10027 | /* Map overloaded Neon opcodes to their respective encodings. */ | |
10028 | #define NEON_ENC_TAB \ | |
10029 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
10030 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
10031 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
10032 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
10033 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
10034 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
10035 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
10036 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
10037 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
10038 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
10039 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
10040 | /* Register variants of the following two instructions are encoded as | |
10041 | vcge / vcgt with the operands reversed. */ \ | |
10042 | X(vclt, 0x0000310, 0x1000e00, 0x1b10200), \ | |
10043 | X(vcle, 0x0000300, 0x1200e00, 0x1b10180), \ | |
10044 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ | |
10045 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
10046 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
10047 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
10048 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
10049 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
10050 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
10051 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
10052 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
10053 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
10054 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
10055 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
10056 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
10057 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
10058 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
10059 | X(veor, 0x1000110, N_INV, N_INV), \ | |
10060 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
10061 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
10062 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
10063 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
10064 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
10065 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
10066 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
10067 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
10068 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
10069 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
10070 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
10071 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
10072 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
10073 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
10074 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
10075 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
10076 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
10077 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
10078 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
10079 | X(vnmla, 0xe000a40, 0xe000b40, N_INV), \ | |
10080 | X(vnmls, 0xe100a40, 0xe100b40, N_INV), \ | |
10081 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ | |
10082 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
10083 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
10084 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV) | |
5287ad62 JB |
10085 | |
10086 | enum neon_opc | |
10087 | { | |
10088 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
10089 | NEON_ENC_TAB | |
10090 | #undef X | |
10091 | }; | |
b99bd4ef | 10092 | |
5287ad62 JB |
10093 | static const struct neon_tab_entry neon_enc_tab[] = |
10094 | { | |
10095 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
10096 | NEON_ENC_TAB | |
10097 | #undef X | |
10098 | }; | |
b99bd4ef | 10099 | |
5287ad62 JB |
10100 | #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer) |
10101 | #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
10102 | #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
10103 | #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
10104 | #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
10105 | #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
10106 | #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
10107 | #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
10108 | #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
037e8744 JB |
10109 | #define NEON_ENC_SINGLE(X) \ |
10110 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) | |
10111 | #define NEON_ENC_DOUBLE(X) \ | |
10112 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) | |
5287ad62 | 10113 | |
037e8744 JB |
10114 | /* Define shapes for instruction operands. The following mnemonic characters |
10115 | are used in this table: | |
5287ad62 | 10116 | |
037e8744 | 10117 | F - VFP S<n> register |
5287ad62 JB |
10118 | D - Neon D<n> register |
10119 | Q - Neon Q<n> register | |
10120 | I - Immediate | |
10121 | S - Scalar | |
10122 | R - ARM register | |
10123 | L - D<n> register list | |
037e8744 JB |
10124 | |
10125 | This table is used to generate various data: | |
10126 | - enumerations of the form NS_DDR to be used as arguments to | |
10127 | neon_select_shape. | |
10128 | - a table classifying shapes into single, double, quad, mixed. | |
10129 | - a table used to drive neon_select_shape. | |
5287ad62 | 10130 | */ |
b99bd4ef | 10131 | |
037e8744 JB |
10132 | #define NEON_SHAPE_DEF \ |
10133 | X(3, (D, D, D), DOUBLE), \ | |
10134 | X(3, (Q, Q, Q), QUAD), \ | |
10135 | X(3, (D, D, I), DOUBLE), \ | |
10136 | X(3, (Q, Q, I), QUAD), \ | |
10137 | X(3, (D, D, S), DOUBLE), \ | |
10138 | X(3, (Q, Q, S), QUAD), \ | |
10139 | X(2, (D, D), DOUBLE), \ | |
10140 | X(2, (Q, Q), QUAD), \ | |
10141 | X(2, (D, S), DOUBLE), \ | |
10142 | X(2, (Q, S), QUAD), \ | |
10143 | X(2, (D, R), DOUBLE), \ | |
10144 | X(2, (Q, R), QUAD), \ | |
10145 | X(2, (D, I), DOUBLE), \ | |
10146 | X(2, (Q, I), QUAD), \ | |
10147 | X(3, (D, L, D), DOUBLE), \ | |
10148 | X(2, (D, Q), MIXED), \ | |
10149 | X(2, (Q, D), MIXED), \ | |
10150 | X(3, (D, Q, I), MIXED), \ | |
10151 | X(3, (Q, D, I), MIXED), \ | |
10152 | X(3, (Q, D, D), MIXED), \ | |
10153 | X(3, (D, Q, Q), MIXED), \ | |
10154 | X(3, (Q, Q, D), MIXED), \ | |
10155 | X(3, (Q, D, S), MIXED), \ | |
10156 | X(3, (D, Q, S), MIXED), \ | |
10157 | X(4, (D, D, D, I), DOUBLE), \ | |
10158 | X(4, (Q, Q, Q, I), QUAD), \ | |
10159 | X(2, (F, F), SINGLE), \ | |
10160 | X(3, (F, F, F), SINGLE), \ | |
10161 | X(2, (F, I), SINGLE), \ | |
10162 | X(2, (F, D), MIXED), \ | |
10163 | X(2, (D, F), MIXED), \ | |
10164 | X(3, (F, F, I), MIXED), \ | |
10165 | X(4, (R, R, F, F), SINGLE), \ | |
10166 | X(4, (F, F, R, R), SINGLE), \ | |
10167 | X(3, (D, R, R), DOUBLE), \ | |
10168 | X(3, (R, R, D), DOUBLE), \ | |
10169 | X(2, (S, R), SINGLE), \ | |
10170 | X(2, (R, S), SINGLE), \ | |
10171 | X(2, (F, R), SINGLE), \ | |
10172 | X(2, (R, F), SINGLE) | |
10173 | ||
10174 | #define S2(A,B) NS_##A##B | |
10175 | #define S3(A,B,C) NS_##A##B##C | |
10176 | #define S4(A,B,C,D) NS_##A##B##C##D | |
10177 | ||
10178 | #define X(N, L, C) S##N L | |
10179 | ||
5287ad62 JB |
10180 | enum neon_shape |
10181 | { | |
037e8744 JB |
10182 | NEON_SHAPE_DEF, |
10183 | NS_NULL | |
5287ad62 | 10184 | }; |
b99bd4ef | 10185 | |
037e8744 JB |
10186 | #undef X |
10187 | #undef S2 | |
10188 | #undef S3 | |
10189 | #undef S4 | |
10190 | ||
10191 | enum neon_shape_class | |
10192 | { | |
10193 | SC_SINGLE, | |
10194 | SC_DOUBLE, | |
10195 | SC_QUAD, | |
10196 | SC_MIXED | |
10197 | }; | |
10198 | ||
10199 | #define X(N, L, C) SC_##C | |
10200 | ||
10201 | static enum neon_shape_class neon_shape_class[] = | |
10202 | { | |
10203 | NEON_SHAPE_DEF | |
10204 | }; | |
10205 | ||
10206 | #undef X | |
10207 | ||
10208 | enum neon_shape_el | |
10209 | { | |
10210 | SE_F, | |
10211 | SE_D, | |
10212 | SE_Q, | |
10213 | SE_I, | |
10214 | SE_S, | |
10215 | SE_R, | |
10216 | SE_L | |
10217 | }; | |
10218 | ||
10219 | /* Register widths of above. */ | |
10220 | static unsigned neon_shape_el_size[] = | |
10221 | { | |
10222 | 32, | |
10223 | 64, | |
10224 | 128, | |
10225 | 0, | |
10226 | 32, | |
10227 | 32, | |
10228 | 0 | |
10229 | }; | |
10230 | ||
10231 | struct neon_shape_info | |
10232 | { | |
10233 | unsigned els; | |
10234 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
10235 | }; | |
10236 | ||
10237 | #define S2(A,B) { SE_##A, SE_##B } | |
10238 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
10239 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
10240 | ||
10241 | #define X(N, L, C) { N, S##N L } | |
10242 | ||
10243 | static struct neon_shape_info neon_shape_tab[] = | |
10244 | { | |
10245 | NEON_SHAPE_DEF | |
10246 | }; | |
10247 | ||
10248 | #undef X | |
10249 | #undef S2 | |
10250 | #undef S3 | |
10251 | #undef S4 | |
10252 | ||
5287ad62 JB |
10253 | /* Bit masks used in type checking given instructions. |
10254 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
10255 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
10256 | set, various other bits can be set as well in order to modify the meaning of | |
10257 | the type constraint. */ | |
10258 | ||
10259 | enum neon_type_mask | |
10260 | { | |
10261 | N_S8 = 0x000001, | |
10262 | N_S16 = 0x000002, | |
10263 | N_S32 = 0x000004, | |
10264 | N_S64 = 0x000008, | |
10265 | N_U8 = 0x000010, | |
10266 | N_U16 = 0x000020, | |
10267 | N_U32 = 0x000040, | |
10268 | N_U64 = 0x000080, | |
10269 | N_I8 = 0x000100, | |
10270 | N_I16 = 0x000200, | |
10271 | N_I32 = 0x000400, | |
10272 | N_I64 = 0x000800, | |
10273 | N_8 = 0x001000, | |
10274 | N_16 = 0x002000, | |
10275 | N_32 = 0x004000, | |
10276 | N_64 = 0x008000, | |
10277 | N_P8 = 0x010000, | |
10278 | N_P16 = 0x020000, | |
10279 | N_F32 = 0x040000, | |
037e8744 JB |
10280 | N_F64 = 0x080000, |
10281 | N_KEY = 0x100000, /* key element (main type specifier). */ | |
10282 | N_EQK = 0x200000, /* given operand has the same type & size as the key. */ | |
10283 | N_VFP = 0x400000, /* VFP mode: operand size must match register width. */ | |
5287ad62 JB |
10284 | N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */ |
10285 | N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */ | |
10286 | N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */ | |
10287 | N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */ | |
10288 | N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */ | |
10289 | N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */ | |
dcbf9037 | 10290 | N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */ |
5287ad62 | 10291 | N_UTYP = 0, |
037e8744 | 10292 | N_MAX_NONSPECIAL = N_F64 |
5287ad62 JB |
10293 | }; |
10294 | ||
dcbf9037 JB |
10295 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
10296 | ||
5287ad62 JB |
10297 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
10298 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
10299 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
10300 | #define N_SUF_32 (N_SU_32 | N_F32) | |
10301 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
10302 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
10303 | ||
10304 | /* Pass this as the first type argument to neon_check_type to ignore types | |
10305 | altogether. */ | |
10306 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
10307 | ||
037e8744 JB |
10308 | /* Select a "shape" for the current instruction (describing register types or |
10309 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
10310 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
10311 | function of operand parsing, so this function doesn't need to be called. | |
10312 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
10313 | |
10314 | static enum neon_shape | |
037e8744 | 10315 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 10316 | { |
037e8744 JB |
10317 | va_list ap; |
10318 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
10319 | |
10320 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
10321 | many arguments we should have, so this makes the assumption that we have | |
10322 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
10323 | true in the future. */ | |
10324 | if (!inst.operands[1].present) | |
10325 | inst.operands[1] = inst.operands[0]; | |
10326 | ||
037e8744 | 10327 | va_start (ap, shape); |
5287ad62 | 10328 | |
037e8744 JB |
10329 | for (; shape != NS_NULL; shape = va_arg (ap, int)) |
10330 | { | |
10331 | unsigned j; | |
10332 | int matches = 1; | |
10333 | ||
10334 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
10335 | { | |
10336 | if (!inst.operands[j].present) | |
10337 | { | |
10338 | matches = 0; | |
10339 | break; | |
10340 | } | |
10341 | ||
10342 | switch (neon_shape_tab[shape].el[j]) | |
10343 | { | |
10344 | case SE_F: | |
10345 | if (!(inst.operands[j].isreg | |
10346 | && inst.operands[j].isvec | |
10347 | && inst.operands[j].issingle | |
10348 | && !inst.operands[j].isquad)) | |
10349 | matches = 0; | |
10350 | break; | |
10351 | ||
10352 | case SE_D: | |
10353 | if (!(inst.operands[j].isreg | |
10354 | && inst.operands[j].isvec | |
10355 | && !inst.operands[j].isquad | |
10356 | && !inst.operands[j].issingle)) | |
10357 | matches = 0; | |
10358 | break; | |
10359 | ||
10360 | case SE_R: | |
10361 | if (!(inst.operands[j].isreg | |
10362 | && !inst.operands[j].isvec)) | |
10363 | matches = 0; | |
10364 | break; | |
10365 | ||
10366 | case SE_Q: | |
10367 | if (!(inst.operands[j].isreg | |
10368 | && inst.operands[j].isvec | |
10369 | && inst.operands[j].isquad | |
10370 | && !inst.operands[j].issingle)) | |
10371 | matches = 0; | |
10372 | break; | |
10373 | ||
10374 | case SE_I: | |
10375 | if (!(!inst.operands[j].isreg | |
10376 | && !inst.operands[j].isscalar)) | |
10377 | matches = 0; | |
10378 | break; | |
10379 | ||
10380 | case SE_S: | |
10381 | if (!(!inst.operands[j].isreg | |
10382 | && inst.operands[j].isscalar)) | |
10383 | matches = 0; | |
10384 | break; | |
10385 | ||
10386 | case SE_L: | |
10387 | break; | |
10388 | } | |
10389 | } | |
10390 | if (matches) | |
5287ad62 | 10391 | break; |
037e8744 | 10392 | } |
5287ad62 | 10393 | |
037e8744 | 10394 | va_end (ap); |
5287ad62 | 10395 | |
037e8744 JB |
10396 | if (shape == NS_NULL && first_shape != NS_NULL) |
10397 | first_error (_("invalid instruction shape")); | |
5287ad62 | 10398 | |
037e8744 JB |
10399 | return shape; |
10400 | } | |
5287ad62 | 10401 | |
037e8744 JB |
10402 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
10403 | means the Q bit should be set). */ | |
10404 | ||
10405 | static int | |
10406 | neon_quad (enum neon_shape shape) | |
10407 | { | |
10408 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 10409 | } |
037e8744 | 10410 | |
5287ad62 JB |
10411 | static void |
10412 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
10413 | unsigned *g_size) | |
10414 | { | |
10415 | /* Allow modification to be made to types which are constrained to be | |
10416 | based on the key element, based on bits set alongside N_EQK. */ | |
10417 | if ((typebits & N_EQK) != 0) | |
10418 | { | |
10419 | if ((typebits & N_HLF) != 0) | |
10420 | *g_size /= 2; | |
10421 | else if ((typebits & N_DBL) != 0) | |
10422 | *g_size *= 2; | |
10423 | if ((typebits & N_SGN) != 0) | |
10424 | *g_type = NT_signed; | |
10425 | else if ((typebits & N_UNS) != 0) | |
10426 | *g_type = NT_unsigned; | |
10427 | else if ((typebits & N_INT) != 0) | |
10428 | *g_type = NT_integer; | |
10429 | else if ((typebits & N_FLT) != 0) | |
10430 | *g_type = NT_float; | |
dcbf9037 JB |
10431 | else if ((typebits & N_SIZ) != 0) |
10432 | *g_type = NT_untyped; | |
5287ad62 JB |
10433 | } |
10434 | } | |
10435 | ||
10436 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" | |
10437 | operand type, i.e. the single type specified in a Neon instruction when it | |
10438 | is the only one given. */ | |
10439 | ||
10440 | static struct neon_type_el | |
10441 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
10442 | { | |
10443 | struct neon_type_el dest = *key; | |
10444 | ||
10445 | assert ((thisarg & N_EQK) != 0); | |
10446 | ||
10447 | neon_modify_type_size (thisarg, &dest.type, &dest.size); | |
10448 | ||
10449 | return dest; | |
10450 | } | |
10451 | ||
10452 | /* Convert Neon type and size into compact bitmask representation. */ | |
10453 | ||
10454 | static enum neon_type_mask | |
10455 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
10456 | { | |
10457 | switch (type) | |
10458 | { | |
10459 | case NT_untyped: | |
10460 | switch (size) | |
10461 | { | |
10462 | case 8: return N_8; | |
10463 | case 16: return N_16; | |
10464 | case 32: return N_32; | |
10465 | case 64: return N_64; | |
10466 | default: ; | |
10467 | } | |
10468 | break; | |
10469 | ||
10470 | case NT_integer: | |
10471 | switch (size) | |
10472 | { | |
10473 | case 8: return N_I8; | |
10474 | case 16: return N_I16; | |
10475 | case 32: return N_I32; | |
10476 | case 64: return N_I64; | |
10477 | default: ; | |
10478 | } | |
10479 | break; | |
10480 | ||
10481 | case NT_float: | |
037e8744 JB |
10482 | switch (size) |
10483 | { | |
10484 | case 32: return N_F32; | |
10485 | case 64: return N_F64; | |
10486 | default: ; | |
10487 | } | |
5287ad62 JB |
10488 | break; |
10489 | ||
10490 | case NT_poly: | |
10491 | switch (size) | |
10492 | { | |
10493 | case 8: return N_P8; | |
10494 | case 16: return N_P16; | |
10495 | default: ; | |
10496 | } | |
10497 | break; | |
10498 | ||
10499 | case NT_signed: | |
10500 | switch (size) | |
10501 | { | |
10502 | case 8: return N_S8; | |
10503 | case 16: return N_S16; | |
10504 | case 32: return N_S32; | |
10505 | case 64: return N_S64; | |
10506 | default: ; | |
10507 | } | |
10508 | break; | |
10509 | ||
10510 | case NT_unsigned: | |
10511 | switch (size) | |
10512 | { | |
10513 | case 8: return N_U8; | |
10514 | case 16: return N_U16; | |
10515 | case 32: return N_U32; | |
10516 | case 64: return N_U64; | |
10517 | default: ; | |
10518 | } | |
10519 | break; | |
10520 | ||
10521 | default: ; | |
10522 | } | |
10523 | ||
10524 | return N_UTYP; | |
10525 | } | |
10526 | ||
10527 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
10528 | handles the case where a single bit is set in the mask. */ | |
10529 | ||
dcbf9037 | 10530 | static int |
5287ad62 JB |
10531 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
10532 | enum neon_type_mask mask) | |
10533 | { | |
dcbf9037 JB |
10534 | if ((mask & N_EQK) != 0) |
10535 | return FAIL; | |
10536 | ||
5287ad62 JB |
10537 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
10538 | *size = 8; | |
dcbf9037 | 10539 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0) |
5287ad62 | 10540 | *size = 16; |
dcbf9037 | 10541 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 10542 | *size = 32; |
037e8744 | 10543 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0) |
5287ad62 | 10544 | *size = 64; |
dcbf9037 JB |
10545 | else |
10546 | return FAIL; | |
10547 | ||
5287ad62 JB |
10548 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
10549 | *type = NT_signed; | |
dcbf9037 | 10550 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 10551 | *type = NT_unsigned; |
dcbf9037 | 10552 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 10553 | *type = NT_integer; |
dcbf9037 | 10554 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 10555 | *type = NT_untyped; |
dcbf9037 | 10556 | else if ((mask & (N_P8 | N_P16)) != 0) |
5287ad62 | 10557 | *type = NT_poly; |
037e8744 | 10558 | else if ((mask & (N_F32 | N_F64)) != 0) |
5287ad62 | 10559 | *type = NT_float; |
dcbf9037 JB |
10560 | else |
10561 | return FAIL; | |
10562 | ||
10563 | return SUCCESS; | |
5287ad62 JB |
10564 | } |
10565 | ||
10566 | /* Modify a bitmask of allowed types. This is only needed for type | |
10567 | relaxation. */ | |
10568 | ||
10569 | static unsigned | |
10570 | modify_types_allowed (unsigned allowed, unsigned mods) | |
10571 | { | |
10572 | unsigned size; | |
10573 | enum neon_el_type type; | |
10574 | unsigned destmask; | |
10575 | int i; | |
10576 | ||
10577 | destmask = 0; | |
10578 | ||
10579 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) | |
10580 | { | |
dcbf9037 JB |
10581 | if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS) |
10582 | { | |
10583 | neon_modify_type_size (mods, &type, &size); | |
10584 | destmask |= type_chk_of_el_type (type, size); | |
10585 | } | |
5287ad62 JB |
10586 | } |
10587 | ||
10588 | return destmask; | |
10589 | } | |
10590 | ||
10591 | /* Check type and return type classification. | |
10592 | The manual states (paraphrase): If one datatype is given, it indicates the | |
10593 | type given in: | |
10594 | - the second operand, if there is one | |
10595 | - the operand, if there is no second operand | |
10596 | - the result, if there are no operands. | |
10597 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
10598 | which is set on a per-instruction basis, which is the one which matters when | |
10599 | only one data type is written. | |
10600 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 10601 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
10602 | |
10603 | static struct neon_type_el | |
10604 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
10605 | { | |
10606 | va_list ap; | |
10607 | unsigned i, pass, key_el = 0; | |
10608 | unsigned types[NEON_MAX_TYPE_ELS]; | |
10609 | enum neon_el_type k_type = NT_invtype; | |
10610 | unsigned k_size = -1u; | |
10611 | struct neon_type_el badtype = {NT_invtype, -1}; | |
10612 | unsigned key_allowed = 0; | |
10613 | ||
10614 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
10615 | Fill in the missing operand here, if it was omitted. */ | |
10616 | if (els > 1 && !inst.operands[1].present) | |
10617 | inst.operands[1] = inst.operands[0]; | |
10618 | ||
10619 | /* Suck up all the varargs. */ | |
10620 | va_start (ap, ns); | |
10621 | for (i = 0; i < els; i++) | |
10622 | { | |
10623 | unsigned thisarg = va_arg (ap, unsigned); | |
10624 | if (thisarg == N_IGNORE_TYPE) | |
10625 | { | |
10626 | va_end (ap); | |
10627 | return badtype; | |
10628 | } | |
10629 | types[i] = thisarg; | |
10630 | if ((thisarg & N_KEY) != 0) | |
10631 | key_el = i; | |
10632 | } | |
10633 | va_end (ap); | |
10634 | ||
dcbf9037 JB |
10635 | if (inst.vectype.elems > 0) |
10636 | for (i = 0; i < els; i++) | |
10637 | if (inst.operands[i].vectype.type != NT_invtype) | |
10638 | { | |
10639 | first_error (_("types specified in both the mnemonic and operands")); | |
10640 | return badtype; | |
10641 | } | |
10642 | ||
5287ad62 JB |
10643 | /* Duplicate inst.vectype elements here as necessary. |
10644 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
10645 | particularly when an insn takes one register and one non-register | |
10646 | operand. */ | |
10647 | if (inst.vectype.elems == 1 && els > 1) | |
10648 | { | |
10649 | unsigned j; | |
10650 | inst.vectype.elems = els; | |
10651 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
10652 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
10653 | if (j != key_el) |
10654 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
10655 | types[j]); | |
10656 | } | |
10657 | else if (inst.vectype.elems == 0 && els > 0) | |
10658 | { | |
10659 | unsigned j; | |
10660 | /* No types were given after the mnemonic, so look for types specified | |
10661 | after each operand. We allow some flexibility here; as long as the | |
10662 | "key" operand has a type, we can infer the others. */ | |
10663 | for (j = 0; j < els; j++) | |
10664 | if (inst.operands[j].vectype.type != NT_invtype) | |
10665 | inst.vectype.el[j] = inst.operands[j].vectype; | |
10666 | ||
10667 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 10668 | { |
dcbf9037 JB |
10669 | for (j = 0; j < els; j++) |
10670 | if (inst.operands[j].vectype.type == NT_invtype) | |
10671 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
10672 | types[j]); | |
10673 | } | |
10674 | else | |
10675 | { | |
10676 | first_error (_("operand types can't be inferred")); | |
10677 | return badtype; | |
5287ad62 JB |
10678 | } |
10679 | } | |
10680 | else if (inst.vectype.elems != els) | |
10681 | { | |
dcbf9037 | 10682 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
10683 | return badtype; |
10684 | } | |
10685 | ||
10686 | for (pass = 0; pass < 2; pass++) | |
10687 | { | |
10688 | for (i = 0; i < els; i++) | |
10689 | { | |
10690 | unsigned thisarg = types[i]; | |
10691 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
10692 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
10693 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
10694 | unsigned g_size = inst.vectype.el[i].size; | |
10695 | ||
10696 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
10697 | integer types if sign-specific variants are unavailable. */ | |
10698 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
10699 | && (types_allowed & N_SU_ALL) == 0) | |
10700 | g_type = NT_integer; | |
10701 | ||
10702 | /* If only untyped args are allowed, decay any more specific types to | |
10703 | them. Some instructions only care about signs for some element | |
10704 | sizes, so handle that properly. */ | |
10705 | if ((g_size == 8 && (types_allowed & N_8) != 0) | |
10706 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
10707 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
10708 | || (g_size == 64 && (types_allowed & N_64) != 0)) | |
10709 | g_type = NT_untyped; | |
10710 | ||
10711 | if (pass == 0) | |
10712 | { | |
10713 | if ((thisarg & N_KEY) != 0) | |
10714 | { | |
10715 | k_type = g_type; | |
10716 | k_size = g_size; | |
10717 | key_allowed = thisarg & ~N_KEY; | |
10718 | } | |
10719 | } | |
10720 | else | |
10721 | { | |
037e8744 JB |
10722 | if ((thisarg & N_VFP) != 0) |
10723 | { | |
10724 | enum neon_shape_el regshape = neon_shape_tab[ns].el[i]; | |
10725 | unsigned regwidth = neon_shape_el_size[regshape], match; | |
10726 | ||
10727 | /* In VFP mode, operands must match register widths. If we | |
10728 | have a key operand, use its width, else use the width of | |
10729 | the current operand. */ | |
10730 | if (k_size != -1u) | |
10731 | match = k_size; | |
10732 | else | |
10733 | match = g_size; | |
10734 | ||
10735 | if (regwidth != match) | |
10736 | { | |
10737 | first_error (_("operand size must match register width")); | |
10738 | return badtype; | |
10739 | } | |
10740 | } | |
10741 | ||
5287ad62 JB |
10742 | if ((thisarg & N_EQK) == 0) |
10743 | { | |
10744 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
10745 | ||
10746 | if ((given_type & types_allowed) == 0) | |
10747 | { | |
dcbf9037 | 10748 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
10749 | return badtype; |
10750 | } | |
10751 | } | |
10752 | else | |
10753 | { | |
10754 | enum neon_el_type mod_k_type = k_type; | |
10755 | unsigned mod_k_size = k_size; | |
10756 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
10757 | if (g_type != mod_k_type || g_size != mod_k_size) | |
10758 | { | |
dcbf9037 | 10759 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
10760 | return badtype; |
10761 | } | |
10762 | } | |
10763 | } | |
10764 | } | |
10765 | } | |
10766 | ||
10767 | return inst.vectype.el[key_el]; | |
10768 | } | |
10769 | ||
037e8744 | 10770 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 10771 | |
037e8744 JB |
10772 | /* Thumb VFP instructions have 0xE in the condition field. */ |
10773 | ||
10774 | static void | |
10775 | do_vfp_cond_or_thumb (void) | |
5287ad62 JB |
10776 | { |
10777 | if (thumb_mode) | |
037e8744 | 10778 | inst.instruction |= 0xe0000000; |
5287ad62 | 10779 | else |
037e8744 | 10780 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
10781 | } |
10782 | ||
037e8744 JB |
10783 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
10784 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
10785 | etc. It is assumed that operand parsing has already been done, and that the | |
10786 | operands are in the form expected by the given opcode (this isn't necessarily | |
10787 | the same as the form in which they were parsed, hence some massaging must | |
10788 | take place before this function is called). | |
10789 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 10790 | |
037e8744 JB |
10791 | static void |
10792 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 10793 | { |
037e8744 JB |
10794 | const struct asm_opcode *opcode; |
10795 | ||
10796 | opcode = hash_find (arm_ops_hsh, opname); | |
5287ad62 | 10797 | |
037e8744 JB |
10798 | if (!opcode) |
10799 | abort (); | |
5287ad62 | 10800 | |
037e8744 JB |
10801 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
10802 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
10803 | _(BAD_FPU)); | |
5287ad62 | 10804 | |
037e8744 JB |
10805 | if (thumb_mode) |
10806 | { | |
10807 | inst.instruction = opcode->tvalue; | |
10808 | opcode->tencode (); | |
10809 | } | |
10810 | else | |
10811 | { | |
10812 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
10813 | opcode->aencode (); | |
10814 | } | |
10815 | } | |
5287ad62 JB |
10816 | |
10817 | static void | |
037e8744 | 10818 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 10819 | { |
037e8744 JB |
10820 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
10821 | ||
10822 | if (rs == NS_FFF) | |
10823 | { | |
10824 | if (is_add) | |
10825 | do_vfp_nsyn_opcode ("fadds"); | |
10826 | else | |
10827 | do_vfp_nsyn_opcode ("fsubs"); | |
10828 | } | |
10829 | else | |
10830 | { | |
10831 | if (is_add) | |
10832 | do_vfp_nsyn_opcode ("faddd"); | |
10833 | else | |
10834 | do_vfp_nsyn_opcode ("fsubd"); | |
10835 | } | |
10836 | } | |
10837 | ||
10838 | /* Check operand types to see if this is a VFP instruction, and if so call | |
10839 | PFN (). */ | |
10840 | ||
10841 | static int | |
10842 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
10843 | { | |
10844 | enum neon_shape rs; | |
10845 | struct neon_type_el et; | |
10846 | ||
10847 | switch (args) | |
10848 | { | |
10849 | case 2: | |
10850 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
10851 | et = neon_check_type (2, rs, | |
10852 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
10853 | break; | |
10854 | ||
10855 | case 3: | |
10856 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
10857 | et = neon_check_type (3, rs, | |
10858 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
10859 | break; | |
10860 | ||
10861 | default: | |
10862 | abort (); | |
10863 | } | |
10864 | ||
10865 | if (et.type != NT_invtype) | |
10866 | { | |
10867 | pfn (rs); | |
10868 | return SUCCESS; | |
10869 | } | |
10870 | else | |
10871 | inst.error = NULL; | |
10872 | ||
10873 | return FAIL; | |
10874 | } | |
10875 | ||
10876 | static void | |
10877 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
10878 | { | |
10879 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
10880 | ||
10881 | if (rs == NS_FFF) | |
10882 | { | |
10883 | if (is_mla) | |
10884 | do_vfp_nsyn_opcode ("fmacs"); | |
10885 | else | |
10886 | do_vfp_nsyn_opcode ("fmscs"); | |
10887 | } | |
10888 | else | |
10889 | { | |
10890 | if (is_mla) | |
10891 | do_vfp_nsyn_opcode ("fmacd"); | |
10892 | else | |
10893 | do_vfp_nsyn_opcode ("fmscd"); | |
10894 | } | |
10895 | } | |
10896 | ||
10897 | static void | |
10898 | do_vfp_nsyn_mul (enum neon_shape rs) | |
10899 | { | |
10900 | if (rs == NS_FFF) | |
10901 | do_vfp_nsyn_opcode ("fmuls"); | |
10902 | else | |
10903 | do_vfp_nsyn_opcode ("fmuld"); | |
10904 | } | |
10905 | ||
10906 | static void | |
10907 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
10908 | { | |
10909 | int is_neg = (inst.instruction & 0x80) != 0; | |
10910 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
10911 | ||
10912 | if (rs == NS_FF) | |
10913 | { | |
10914 | if (is_neg) | |
10915 | do_vfp_nsyn_opcode ("fnegs"); | |
10916 | else | |
10917 | do_vfp_nsyn_opcode ("fabss"); | |
10918 | } | |
10919 | else | |
10920 | { | |
10921 | if (is_neg) | |
10922 | do_vfp_nsyn_opcode ("fnegd"); | |
10923 | else | |
10924 | do_vfp_nsyn_opcode ("fabsd"); | |
10925 | } | |
10926 | } | |
10927 | ||
10928 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
10929 | insns belong to Neon, and are handled elsewhere. */ | |
10930 | ||
10931 | static void | |
10932 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
10933 | { | |
10934 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
10935 | if (is_ldm) | |
10936 | { | |
10937 | if (is_dbmode) | |
10938 | do_vfp_nsyn_opcode ("fldmdbs"); | |
10939 | else | |
10940 | do_vfp_nsyn_opcode ("fldmias"); | |
10941 | } | |
10942 | else | |
10943 | { | |
10944 | if (is_dbmode) | |
10945 | do_vfp_nsyn_opcode ("fstmdbs"); | |
10946 | else | |
10947 | do_vfp_nsyn_opcode ("fstmias"); | |
10948 | } | |
10949 | } | |
10950 | ||
037e8744 JB |
10951 | static void |
10952 | do_vfp_nsyn_sqrt (void) | |
10953 | { | |
10954 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
10955 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
10956 | ||
10957 | if (rs == NS_FF) | |
10958 | do_vfp_nsyn_opcode ("fsqrts"); | |
10959 | else | |
10960 | do_vfp_nsyn_opcode ("fsqrtd"); | |
10961 | } | |
10962 | ||
10963 | static void | |
10964 | do_vfp_nsyn_div (void) | |
10965 | { | |
10966 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
10967 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
10968 | N_F32 | N_F64 | N_KEY | N_VFP); | |
10969 | ||
10970 | if (rs == NS_FFF) | |
10971 | do_vfp_nsyn_opcode ("fdivs"); | |
10972 | else | |
10973 | do_vfp_nsyn_opcode ("fdivd"); | |
10974 | } | |
10975 | ||
10976 | static void | |
10977 | do_vfp_nsyn_nmul (void) | |
10978 | { | |
10979 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
10980 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
10981 | N_F32 | N_F64 | N_KEY | N_VFP); | |
10982 | ||
10983 | if (rs == NS_FFF) | |
10984 | { | |
10985 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
10986 | do_vfp_sp_dyadic (); | |
10987 | } | |
10988 | else | |
10989 | { | |
10990 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
10991 | do_vfp_dp_rd_rn_rm (); | |
10992 | } | |
10993 | do_vfp_cond_or_thumb (); | |
10994 | } | |
10995 | ||
10996 | static void | |
10997 | do_vfp_nsyn_cmp (void) | |
10998 | { | |
10999 | if (inst.operands[1].isreg) | |
11000 | { | |
11001 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
11002 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
11003 | ||
11004 | if (rs == NS_FF) | |
11005 | { | |
11006 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
11007 | do_vfp_sp_monadic (); | |
11008 | } | |
11009 | else | |
11010 | { | |
11011 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
11012 | do_vfp_dp_rd_rm (); | |
11013 | } | |
11014 | } | |
11015 | else | |
11016 | { | |
11017 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
11018 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
11019 | ||
11020 | switch (inst.instruction & 0x0fffffff) | |
11021 | { | |
11022 | case N_MNEM_vcmp: | |
11023 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
11024 | break; | |
11025 | case N_MNEM_vcmpe: | |
11026 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
11027 | break; | |
11028 | default: | |
11029 | abort (); | |
11030 | } | |
11031 | ||
11032 | if (rs == NS_FI) | |
11033 | { | |
11034 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
11035 | do_vfp_sp_compare_z (); | |
11036 | } | |
11037 | else | |
11038 | { | |
11039 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
11040 | do_vfp_dp_rd (); | |
11041 | } | |
11042 | } | |
11043 | do_vfp_cond_or_thumb (); | |
11044 | } | |
11045 | ||
11046 | static void | |
11047 | nsyn_insert_sp (void) | |
11048 | { | |
11049 | inst.operands[1] = inst.operands[0]; | |
11050 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
11051 | inst.operands[0].reg = 13; | |
11052 | inst.operands[0].isreg = 1; | |
11053 | inst.operands[0].writeback = 1; | |
11054 | inst.operands[0].present = 1; | |
11055 | } | |
11056 | ||
11057 | static void | |
11058 | do_vfp_nsyn_push (void) | |
11059 | { | |
11060 | nsyn_insert_sp (); | |
11061 | if (inst.operands[1].issingle) | |
11062 | do_vfp_nsyn_opcode ("fstmdbs"); | |
11063 | else | |
11064 | do_vfp_nsyn_opcode ("fstmdbd"); | |
11065 | } | |
11066 | ||
11067 | static void | |
11068 | do_vfp_nsyn_pop (void) | |
11069 | { | |
11070 | nsyn_insert_sp (); | |
11071 | if (inst.operands[1].issingle) | |
11072 | do_vfp_nsyn_opcode ("fldmdbs"); | |
11073 | else | |
11074 | do_vfp_nsyn_opcode ("fldmdbd"); | |
11075 | } | |
11076 | ||
11077 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
11078 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
11079 | ||
11080 | static unsigned | |
11081 | neon_dp_fixup (unsigned i) | |
11082 | { | |
11083 | if (thumb_mode) | |
11084 | { | |
11085 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
11086 | if (i & (1 << 24)) | |
11087 | i |= 1 << 28; | |
11088 | ||
11089 | i &= ~(1 << 24); | |
11090 | ||
11091 | i |= 0xef000000; | |
11092 | } | |
11093 | else | |
11094 | i |= 0xf2000000; | |
11095 | ||
11096 | return i; | |
11097 | } | |
11098 | ||
11099 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
11100 | (0, 1, 2, 3). */ | |
11101 | ||
11102 | static unsigned | |
11103 | neon_logbits (unsigned x) | |
11104 | { | |
11105 | return ffs (x) - 4; | |
11106 | } | |
11107 | ||
11108 | #define LOW4(R) ((R) & 0xf) | |
11109 | #define HI1(R) (((R) >> 4) & 1) | |
11110 | ||
11111 | /* Encode insns with bit pattern: | |
11112 | ||
11113 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
11114 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
11115 | ||
11116 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a | |
11117 | different meaning for some instruction. */ | |
11118 | ||
11119 | static void | |
11120 | neon_three_same (int isquad, int ubit, int size) | |
11121 | { | |
11122 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11123 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11124 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
11125 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
11126 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
11127 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
11128 | inst.instruction |= (isquad != 0) << 6; | |
11129 | inst.instruction |= (ubit != 0) << 24; | |
11130 | if (size != -1) | |
11131 | inst.instruction |= neon_logbits (size) << 20; | |
11132 | ||
11133 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11134 | } | |
11135 | ||
11136 | /* Encode instructions of the form: | |
11137 | ||
11138 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
11139 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
11140 | |
11141 | Don't write size if SIZE == -1. */ | |
11142 | ||
11143 | static void | |
11144 | neon_two_same (int qbit, int ubit, int size) | |
11145 | { | |
11146 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11147 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11148 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11149 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
11150 | inst.instruction |= (qbit != 0) << 6; | |
11151 | inst.instruction |= (ubit != 0) << 24; | |
11152 | ||
11153 | if (size != -1) | |
11154 | inst.instruction |= neon_logbits (size) << 18; | |
11155 | ||
11156 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11157 | } | |
11158 | ||
11159 | /* Neon instruction encoders, in approximate order of appearance. */ | |
11160 | ||
11161 | static void | |
11162 | do_neon_dyadic_i_su (void) | |
11163 | { | |
037e8744 | 11164 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11165 | struct neon_type_el et = neon_check_type (3, rs, |
11166 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 11167 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11168 | } |
11169 | ||
11170 | static void | |
11171 | do_neon_dyadic_i64_su (void) | |
11172 | { | |
037e8744 | 11173 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11174 | struct neon_type_el et = neon_check_type (3, rs, |
11175 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 11176 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11177 | } |
11178 | ||
11179 | static void | |
11180 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
11181 | unsigned immbits) | |
11182 | { | |
11183 | unsigned size = et.size >> 3; | |
11184 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11185 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11186 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11187 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
11188 | inst.instruction |= (isquad != 0) << 6; | |
11189 | inst.instruction |= immbits << 16; | |
11190 | inst.instruction |= (size >> 3) << 7; | |
11191 | inst.instruction |= (size & 0x7) << 19; | |
11192 | if (write_ubit) | |
11193 | inst.instruction |= (uval != 0) << 24; | |
11194 | ||
11195 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11196 | } | |
11197 | ||
11198 | static void | |
11199 | do_neon_shl_imm (void) | |
11200 | { | |
11201 | if (!inst.operands[2].isreg) | |
11202 | { | |
037e8744 | 11203 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11204 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
11205 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 11206 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
11207 | } |
11208 | else | |
11209 | { | |
037e8744 | 11210 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11211 | struct neon_type_el et = neon_check_type (3, rs, |
11212 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
11213 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11214 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11215 | } |
11216 | } | |
11217 | ||
11218 | static void | |
11219 | do_neon_qshl_imm (void) | |
11220 | { | |
11221 | if (!inst.operands[2].isreg) | |
11222 | { | |
037e8744 | 11223 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11224 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
11225 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 11226 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
11227 | inst.operands[2].imm); |
11228 | } | |
11229 | else | |
11230 | { | |
037e8744 | 11231 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11232 | struct neon_type_el et = neon_check_type (3, rs, |
11233 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
11234 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11235 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11236 | } |
11237 | } | |
11238 | ||
11239 | static int | |
11240 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
11241 | { | |
11242 | /* Handle .I8 and .I64 as pseudo-instructions. */ | |
11243 | switch (size) | |
11244 | { | |
11245 | case 8: | |
11246 | /* Unfortunately, this will make everything apart from zero out-of-range. | |
11247 | FIXME is this the intended semantics? There doesn't seem much point in | |
11248 | accepting .I8 if so. */ | |
11249 | immediate |= immediate << 8; | |
11250 | size = 16; | |
11251 | break; | |
11252 | case 64: | |
11253 | /* Similarly, anything other than zero will be replicated in bits [63:32], | |
11254 | which probably isn't want we want if we specified .I64. */ | |
11255 | if (immediate != 0) | |
11256 | goto bad_immediate; | |
11257 | size = 32; | |
11258 | break; | |
11259 | default: ; | |
11260 | } | |
11261 | ||
11262 | if (immediate == (immediate & 0x000000ff)) | |
11263 | { | |
11264 | *immbits = immediate; | |
11265 | return (size == 16) ? 0x9 : 0x1; | |
11266 | } | |
11267 | else if (immediate == (immediate & 0x0000ff00)) | |
11268 | { | |
11269 | *immbits = immediate >> 8; | |
11270 | return (size == 16) ? 0xb : 0x3; | |
11271 | } | |
11272 | else if (immediate == (immediate & 0x00ff0000)) | |
11273 | { | |
11274 | *immbits = immediate >> 16; | |
11275 | return 0x5; | |
11276 | } | |
11277 | else if (immediate == (immediate & 0xff000000)) | |
11278 | { | |
11279 | *immbits = immediate >> 24; | |
11280 | return 0x7; | |
11281 | } | |
11282 | ||
11283 | bad_immediate: | |
dcbf9037 | 11284 | first_error (_("immediate value out of range")); |
5287ad62 JB |
11285 | return FAIL; |
11286 | } | |
11287 | ||
11288 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
11289 | A, B, C, D. */ | |
11290 | ||
11291 | static int | |
11292 | neon_bits_same_in_bytes (unsigned imm) | |
11293 | { | |
11294 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
11295 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
11296 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
11297 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
11298 | } | |
11299 | ||
11300 | /* For immediate of above form, return 0bABCD. */ | |
11301 | ||
11302 | static unsigned | |
11303 | neon_squash_bits (unsigned imm) | |
11304 | { | |
11305 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
11306 | | ((imm & 0x01000000) >> 21); | |
11307 | } | |
11308 | ||
136da414 | 11309 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
11310 | |
11311 | static unsigned | |
11312 | neon_qfloat_bits (unsigned imm) | |
11313 | { | |
136da414 | 11314 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
11315 | } |
11316 | ||
11317 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
11318 | the instruction. *OP is passed as the initial value of the op field, and | |
11319 | may be set to a different value depending on the constant (i.e. | |
11320 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
11321 | MVN). */ | |
11322 | ||
11323 | static int | |
11324 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, unsigned *immbits, | |
136da414 | 11325 | int *op, int size, enum neon_el_type type) |
5287ad62 | 11326 | { |
136da414 JB |
11327 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
11328 | { | |
11329 | if (size != 32 || *op == 1) | |
11330 | return FAIL; | |
11331 | *immbits = neon_qfloat_bits (immlo); | |
11332 | return 0xf; | |
11333 | } | |
11334 | else if (size == 64 && neon_bits_same_in_bytes (immhi) | |
5287ad62 JB |
11335 | && neon_bits_same_in_bytes (immlo)) |
11336 | { | |
11337 | /* Check this one first so we don't have to bother with immhi in later | |
11338 | tests. */ | |
11339 | if (*op == 1) | |
11340 | return FAIL; | |
11341 | *immbits = (neon_squash_bits (immhi) << 4) | neon_squash_bits (immlo); | |
11342 | *op = 1; | |
11343 | return 0xe; | |
11344 | } | |
11345 | else if (immhi != 0) | |
11346 | return FAIL; | |
11347 | else if (immlo == (immlo & 0x000000ff)) | |
11348 | { | |
11349 | /* 64-bit case was already handled. Don't allow MVN with 8-bit | |
11350 | immediate. */ | |
11351 | if ((size != 8 && size != 16 && size != 32) | |
11352 | || (size == 8 && *op == 1)) | |
11353 | return FAIL; | |
11354 | *immbits = immlo; | |
11355 | return (size == 8) ? 0xe : (size == 16) ? 0x8 : 0x0; | |
11356 | } | |
11357 | else if (immlo == (immlo & 0x0000ff00)) | |
11358 | { | |
11359 | if (size != 16 && size != 32) | |
11360 | return FAIL; | |
11361 | *immbits = immlo >> 8; | |
11362 | return (size == 16) ? 0xa : 0x2; | |
11363 | } | |
11364 | else if (immlo == (immlo & 0x00ff0000)) | |
11365 | { | |
11366 | if (size != 32) | |
11367 | return FAIL; | |
11368 | *immbits = immlo >> 16; | |
11369 | return 0x4; | |
11370 | } | |
11371 | else if (immlo == (immlo & 0xff000000)) | |
11372 | { | |
11373 | if (size != 32) | |
11374 | return FAIL; | |
11375 | *immbits = immlo >> 24; | |
11376 | return 0x6; | |
11377 | } | |
11378 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
11379 | { | |
11380 | if (size != 32) | |
11381 | return FAIL; | |
11382 | *immbits = (immlo >> 8) & 0xff; | |
11383 | return 0xc; | |
11384 | } | |
11385 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
11386 | { | |
11387 | if (size != 32) | |
11388 | return FAIL; | |
11389 | *immbits = (immlo >> 16) & 0xff; | |
11390 | return 0xd; | |
11391 | } | |
5287ad62 JB |
11392 | |
11393 | return FAIL; | |
11394 | } | |
11395 | ||
11396 | /* Write immediate bits [7:0] to the following locations: | |
11397 | ||
11398 | |28/24|23 19|18 16|15 4|3 0| | |
11399 | | a |x x x x x|b c d|x x x x x x x x x x x x|e f g h| | |
11400 | ||
11401 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
11402 | ||
11403 | static void | |
11404 | neon_write_immbits (unsigned immbits) | |
11405 | { | |
11406 | inst.instruction |= immbits & 0xf; | |
11407 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
11408 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
11409 | } | |
11410 | ||
11411 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
11412 | ||
11413 | static void | |
11414 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
11415 | { | |
11416 | unsigned immlo = xlo ? *xlo : 0; | |
11417 | unsigned immhi = xhi ? *xhi : 0; | |
11418 | ||
11419 | switch (size) | |
11420 | { | |
11421 | case 8: | |
11422 | immlo = (~immlo) & 0xff; | |
11423 | break; | |
11424 | ||
11425 | case 16: | |
11426 | immlo = (~immlo) & 0xffff; | |
11427 | break; | |
11428 | ||
11429 | case 64: | |
11430 | immhi = (~immhi) & 0xffffffff; | |
11431 | /* fall through. */ | |
11432 | ||
11433 | case 32: | |
11434 | immlo = (~immlo) & 0xffffffff; | |
11435 | break; | |
11436 | ||
11437 | default: | |
11438 | abort (); | |
11439 | } | |
11440 | ||
11441 | if (xlo) | |
11442 | *xlo = immlo; | |
11443 | ||
11444 | if (xhi) | |
11445 | *xhi = immhi; | |
11446 | } | |
11447 | ||
11448 | static void | |
11449 | do_neon_logic (void) | |
11450 | { | |
11451 | if (inst.operands[2].present && inst.operands[2].isreg) | |
11452 | { | |
037e8744 | 11453 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11454 | neon_check_type (3, rs, N_IGNORE_TYPE); |
11455 | /* U bit and size field were set as part of the bitmask. */ | |
11456 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11457 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11458 | } |
11459 | else | |
11460 | { | |
037e8744 JB |
11461 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
11462 | struct neon_type_el et = neon_check_type (2, rs, | |
11463 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 JB |
11464 | enum neon_opc opcode = inst.instruction & 0x0fffffff; |
11465 | unsigned immbits; | |
11466 | int cmode; | |
11467 | ||
11468 | if (et.type == NT_invtype) | |
11469 | return; | |
11470 | ||
11471 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
11472 | ||
11473 | switch (opcode) | |
11474 | { | |
11475 | case N_MNEM_vbic: | |
11476 | cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits, | |
11477 | et.size); | |
11478 | break; | |
11479 | ||
11480 | case N_MNEM_vorr: | |
11481 | cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits, | |
11482 | et.size); | |
11483 | break; | |
11484 | ||
11485 | case N_MNEM_vand: | |
11486 | /* Pseudo-instruction for VBIC. */ | |
11487 | immbits = inst.operands[1].imm; | |
11488 | neon_invert_size (&immbits, 0, et.size); | |
11489 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
11490 | break; | |
11491 | ||
11492 | case N_MNEM_vorn: | |
11493 | /* Pseudo-instruction for VORR. */ | |
11494 | immbits = inst.operands[1].imm; | |
11495 | neon_invert_size (&immbits, 0, et.size); | |
11496 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
11497 | break; | |
11498 | ||
11499 | default: | |
11500 | abort (); | |
11501 | } | |
11502 | ||
11503 | if (cmode == FAIL) | |
11504 | return; | |
11505 | ||
037e8744 | 11506 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
11507 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
11508 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11509 | inst.instruction |= cmode << 8; | |
11510 | neon_write_immbits (immbits); | |
11511 | ||
11512 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11513 | } | |
11514 | } | |
11515 | ||
11516 | static void | |
11517 | do_neon_bitfield (void) | |
11518 | { | |
037e8744 | 11519 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 11520 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 11521 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11522 | } |
11523 | ||
11524 | static void | |
dcbf9037 JB |
11525 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
11526 | unsigned destbits) | |
5287ad62 | 11527 | { |
037e8744 | 11528 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
11529 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
11530 | types | N_KEY); | |
5287ad62 JB |
11531 | if (et.type == NT_float) |
11532 | { | |
11533 | inst.instruction = NEON_ENC_FLOAT (inst.instruction); | |
037e8744 | 11534 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11535 | } |
11536 | else | |
11537 | { | |
11538 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11539 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
11540 | } |
11541 | } | |
11542 | ||
11543 | static void | |
11544 | do_neon_dyadic_if_su (void) | |
11545 | { | |
dcbf9037 | 11546 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
11547 | } |
11548 | ||
11549 | static void | |
11550 | do_neon_dyadic_if_su_d (void) | |
11551 | { | |
11552 | /* This version only allow D registers, but that constraint is enforced during | |
11553 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 11554 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
11555 | } |
11556 | ||
11557 | static void | |
11558 | do_neon_dyadic_if_i (void) | |
11559 | { | |
dcbf9037 | 11560 | neon_dyadic_misc (NT_unsigned, N_IF_32, 0); |
5287ad62 JB |
11561 | } |
11562 | ||
11563 | static void | |
11564 | do_neon_dyadic_if_i_d (void) | |
11565 | { | |
dcbf9037 | 11566 | neon_dyadic_misc (NT_unsigned, N_IF_32, 0); |
5287ad62 JB |
11567 | } |
11568 | ||
037e8744 JB |
11569 | enum vfp_or_neon_is_neon_bits |
11570 | { | |
11571 | NEON_CHECK_CC = 1, | |
11572 | NEON_CHECK_ARCH = 2 | |
11573 | }; | |
11574 | ||
11575 | /* Call this function if an instruction which may have belonged to the VFP or | |
11576 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
11577 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
11578 | things: | |
11579 | ||
11580 | - Make sure the user hasn't attempted to make a Neon instruction | |
11581 | conditional. | |
11582 | - Alter the value in the condition code field if necessary. | |
11583 | - Make sure that the arch supports Neon instructions. | |
11584 | ||
11585 | Which of these operations take place depends on bits from enum | |
11586 | vfp_or_neon_is_neon_bits. | |
11587 | ||
11588 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
11589 | current instruction's condition is COND_ALWAYS, the condition field is | |
11590 | changed to inst.uncond_value. This is necessary because instructions shared | |
11591 | between VFP and Neon may be conditional for the VFP variants only, and the | |
11592 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
11593 | ||
11594 | static int | |
11595 | vfp_or_neon_is_neon (unsigned check) | |
11596 | { | |
11597 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
11598 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
11599 | { | |
11600 | if (inst.cond != COND_ALWAYS) | |
11601 | { | |
11602 | first_error (_(BAD_COND)); | |
11603 | return FAIL; | |
11604 | } | |
11605 | if (inst.uncond_value != -1) | |
11606 | inst.instruction |= inst.uncond_value << 28; | |
11607 | } | |
11608 | ||
11609 | if ((check & NEON_CHECK_ARCH) | |
11610 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
11611 | { | |
11612 | first_error (_(BAD_FPU)); | |
11613 | return FAIL; | |
11614 | } | |
11615 | ||
11616 | return SUCCESS; | |
11617 | } | |
11618 | ||
5287ad62 JB |
11619 | static void |
11620 | do_neon_addsub_if_i (void) | |
11621 | { | |
037e8744 JB |
11622 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
11623 | return; | |
11624 | ||
11625 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
11626 | return; | |
11627 | ||
5287ad62 JB |
11628 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
11629 | affected if we specify unsigned args. */ | |
dcbf9037 | 11630 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
11631 | } |
11632 | ||
11633 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
11634 | result to be: | |
11635 | V<op> A,B (A is operand 0, B is operand 2) | |
11636 | to mean: | |
11637 | V<op> A,B,A | |
11638 | not: | |
11639 | V<op> A,B,B | |
11640 | so handle that case specially. */ | |
11641 | ||
11642 | static void | |
11643 | neon_exchange_operands (void) | |
11644 | { | |
11645 | void *scratch = alloca (sizeof (inst.operands[0])); | |
11646 | if (inst.operands[1].present) | |
11647 | { | |
11648 | /* Swap operands[1] and operands[2]. */ | |
11649 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
11650 | inst.operands[1] = inst.operands[2]; | |
11651 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
11652 | } | |
11653 | else | |
11654 | { | |
11655 | inst.operands[1] = inst.operands[2]; | |
11656 | inst.operands[2] = inst.operands[0]; | |
11657 | } | |
11658 | } | |
11659 | ||
11660 | static void | |
11661 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
11662 | { | |
11663 | if (inst.operands[2].isreg) | |
11664 | { | |
11665 | if (invert) | |
11666 | neon_exchange_operands (); | |
dcbf9037 | 11667 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
11668 | } |
11669 | else | |
11670 | { | |
037e8744 | 11671 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
11672 | struct neon_type_el et = neon_check_type (2, rs, |
11673 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 JB |
11674 | |
11675 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
11676 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11677 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11678 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11679 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 11680 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
11681 | inst.instruction |= (et.type == NT_float) << 10; |
11682 | inst.instruction |= neon_logbits (et.size) << 18; | |
11683 | ||
11684 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11685 | } | |
11686 | } | |
11687 | ||
11688 | static void | |
11689 | do_neon_cmp (void) | |
11690 | { | |
11691 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
11692 | } | |
11693 | ||
11694 | static void | |
11695 | do_neon_cmp_inv (void) | |
11696 | { | |
11697 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
11698 | } | |
11699 | ||
11700 | static void | |
11701 | do_neon_ceq (void) | |
11702 | { | |
11703 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
11704 | } | |
11705 | ||
11706 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
11707 | scalars, which are encoded in 5 bits, M : Rm. | |
11708 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
11709 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
11710 | index in M. */ | |
11711 | ||
11712 | static unsigned | |
11713 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
11714 | { | |
dcbf9037 JB |
11715 | unsigned regno = NEON_SCALAR_REG (scalar); |
11716 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
11717 | |
11718 | switch (elsize) | |
11719 | { | |
11720 | case 16: | |
11721 | if (regno > 7 || elno > 3) | |
11722 | goto bad_scalar; | |
11723 | return regno | (elno << 3); | |
11724 | ||
11725 | case 32: | |
11726 | if (regno > 15 || elno > 1) | |
11727 | goto bad_scalar; | |
11728 | return regno | (elno << 4); | |
11729 | ||
11730 | default: | |
11731 | bad_scalar: | |
dcbf9037 | 11732 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
11733 | } |
11734 | ||
11735 | return 0; | |
11736 | } | |
11737 | ||
11738 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
11739 | ||
11740 | static void | |
11741 | neon_mul_mac (struct neon_type_el et, int ubit) | |
11742 | { | |
dcbf9037 JB |
11743 | unsigned scalar; |
11744 | ||
11745 | /* Give a more helpful error message if we have an invalid type. */ | |
11746 | if (et.type == NT_invtype) | |
11747 | return; | |
11748 | ||
11749 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); | |
5287ad62 JB |
11750 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
11751 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11752 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
11753 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
11754 | inst.instruction |= LOW4 (scalar); | |
11755 | inst.instruction |= HI1 (scalar) << 5; | |
11756 | inst.instruction |= (et.type == NT_float) << 8; | |
11757 | inst.instruction |= neon_logbits (et.size) << 20; | |
11758 | inst.instruction |= (ubit != 0) << 24; | |
11759 | ||
11760 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11761 | } | |
11762 | ||
11763 | static void | |
11764 | do_neon_mac_maybe_scalar (void) | |
11765 | { | |
037e8744 JB |
11766 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
11767 | return; | |
11768 | ||
11769 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
11770 | return; | |
11771 | ||
5287ad62 JB |
11772 | if (inst.operands[2].isscalar) |
11773 | { | |
037e8744 | 11774 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
11775 | struct neon_type_el et = neon_check_type (3, rs, |
11776 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
11777 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 11778 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
11779 | } |
11780 | else | |
11781 | do_neon_dyadic_if_i (); | |
11782 | } | |
11783 | ||
11784 | static void | |
11785 | do_neon_tst (void) | |
11786 | { | |
037e8744 | 11787 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11788 | struct neon_type_el et = neon_check_type (3, rs, |
11789 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 11790 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
11791 | } |
11792 | ||
11793 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
11794 | same types as the MAC equivalents. The polynomial type for this instruction | |
11795 | is encoded the same as the integer type. */ | |
11796 | ||
11797 | static void | |
11798 | do_neon_mul (void) | |
11799 | { | |
037e8744 JB |
11800 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
11801 | return; | |
11802 | ||
11803 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
11804 | return; | |
11805 | ||
5287ad62 JB |
11806 | if (inst.operands[2].isscalar) |
11807 | do_neon_mac_maybe_scalar (); | |
11808 | else | |
dcbf9037 | 11809 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
11810 | } |
11811 | ||
11812 | static void | |
11813 | do_neon_qdmulh (void) | |
11814 | { | |
11815 | if (inst.operands[2].isscalar) | |
11816 | { | |
037e8744 | 11817 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
11818 | struct neon_type_el et = neon_check_type (3, rs, |
11819 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
11820 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 11821 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
11822 | } |
11823 | else | |
11824 | { | |
037e8744 | 11825 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11826 | struct neon_type_el et = neon_check_type (3, rs, |
11827 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
11828 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
11829 | /* The U bit (rounding) comes from bit mask. */ | |
037e8744 | 11830 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
11831 | } |
11832 | } | |
11833 | ||
11834 | static void | |
11835 | do_neon_fcmp_absolute (void) | |
11836 | { | |
037e8744 | 11837 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11838 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
11839 | /* Size field comes from bit mask. */ | |
037e8744 | 11840 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
11841 | } |
11842 | ||
11843 | static void | |
11844 | do_neon_fcmp_absolute_inv (void) | |
11845 | { | |
11846 | neon_exchange_operands (); | |
11847 | do_neon_fcmp_absolute (); | |
11848 | } | |
11849 | ||
11850 | static void | |
11851 | do_neon_step (void) | |
11852 | { | |
037e8744 | 11853 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 11854 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 11855 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11856 | } |
11857 | ||
11858 | static void | |
11859 | do_neon_abs_neg (void) | |
11860 | { | |
037e8744 JB |
11861 | enum neon_shape rs; |
11862 | struct neon_type_el et; | |
11863 | ||
11864 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) | |
11865 | return; | |
11866 | ||
11867 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
11868 | return; | |
11869 | ||
11870 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
11871 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
11872 | ||
5287ad62 JB |
11873 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
11874 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11875 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11876 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 11877 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
11878 | inst.instruction |= (et.type == NT_float) << 10; |
11879 | inst.instruction |= neon_logbits (et.size) << 18; | |
11880 | ||
11881 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11882 | } | |
11883 | ||
11884 | static void | |
11885 | do_neon_sli (void) | |
11886 | { | |
037e8744 | 11887 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11888 | struct neon_type_el et = neon_check_type (2, rs, |
11889 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
11890 | int imm = inst.operands[2].imm; | |
11891 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
11892 | _("immediate out of range for insert")); | |
037e8744 | 11893 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
11894 | } |
11895 | ||
11896 | static void | |
11897 | do_neon_sri (void) | |
11898 | { | |
037e8744 | 11899 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11900 | struct neon_type_el et = neon_check_type (2, rs, |
11901 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
11902 | int imm = inst.operands[2].imm; | |
11903 | constraint (imm < 1 || (unsigned)imm > et.size, | |
11904 | _("immediate out of range for insert")); | |
037e8744 | 11905 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
11906 | } |
11907 | ||
11908 | static void | |
11909 | do_neon_qshlu_imm (void) | |
11910 | { | |
037e8744 | 11911 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11912 | struct neon_type_el et = neon_check_type (2, rs, |
11913 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
11914 | int imm = inst.operands[2].imm; | |
11915 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
11916 | _("immediate out of range for shift")); | |
11917 | /* Only encodes the 'U present' variant of the instruction. | |
11918 | In this case, signed types have OP (bit 8) set to 0. | |
11919 | Unsigned types have OP set to 1. */ | |
11920 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
11921 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 11922 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
11923 | } |
11924 | ||
11925 | static void | |
11926 | do_neon_qmovn (void) | |
11927 | { | |
11928 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
11929 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
11930 | /* Saturating move where operands can be signed or unsigned, and the | |
11931 | destination has the same signedness. */ | |
11932 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
11933 | if (et.type == NT_unsigned) | |
11934 | inst.instruction |= 0xc0; | |
11935 | else | |
11936 | inst.instruction |= 0x80; | |
11937 | neon_two_same (0, 1, et.size / 2); | |
11938 | } | |
11939 | ||
11940 | static void | |
11941 | do_neon_qmovun (void) | |
11942 | { | |
11943 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
11944 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
11945 | /* Saturating move with unsigned results. Operands must be signed. */ | |
11946 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
11947 | neon_two_same (0, 1, et.size / 2); | |
11948 | } | |
11949 | ||
11950 | static void | |
11951 | do_neon_rshift_sat_narrow (void) | |
11952 | { | |
11953 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
11954 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
11955 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
11956 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
11957 | int imm = inst.operands[2].imm; | |
11958 | /* This gets the bounds check, size encoding and immediate bits calculation | |
11959 | right. */ | |
11960 | et.size /= 2; | |
11961 | ||
11962 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
11963 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
11964 | if (imm == 0) | |
11965 | { | |
11966 | inst.operands[2].present = 0; | |
11967 | inst.instruction = N_MNEM_vqmovn; | |
11968 | do_neon_qmovn (); | |
11969 | return; | |
11970 | } | |
11971 | ||
11972 | constraint (imm < 1 || (unsigned)imm > et.size, | |
11973 | _("immediate out of range")); | |
11974 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
11975 | } | |
11976 | ||
11977 | static void | |
11978 | do_neon_rshift_sat_narrow_u (void) | |
11979 | { | |
11980 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
11981 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
11982 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
11983 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
11984 | int imm = inst.operands[2].imm; | |
11985 | /* This gets the bounds check, size encoding and immediate bits calculation | |
11986 | right. */ | |
11987 | et.size /= 2; | |
11988 | ||
11989 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
11990 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
11991 | if (imm == 0) | |
11992 | { | |
11993 | inst.operands[2].present = 0; | |
11994 | inst.instruction = N_MNEM_vqmovun; | |
11995 | do_neon_qmovun (); | |
11996 | return; | |
11997 | } | |
11998 | ||
11999 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12000 | _("immediate out of range")); | |
12001 | /* FIXME: The manual is kind of unclear about what value U should have in | |
12002 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
12003 | must be 1. */ | |
12004 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
12005 | } | |
12006 | ||
12007 | static void | |
12008 | do_neon_movn (void) | |
12009 | { | |
12010 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
12011 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
12012 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12013 | neon_two_same (0, 1, et.size / 2); | |
12014 | } | |
12015 | ||
12016 | static void | |
12017 | do_neon_rshift_narrow (void) | |
12018 | { | |
12019 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
12020 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
12021 | int imm = inst.operands[2].imm; | |
12022 | /* This gets the bounds check, size encoding and immediate bits calculation | |
12023 | right. */ | |
12024 | et.size /= 2; | |
12025 | ||
12026 | /* If immediate is zero then we are a pseudo-instruction for | |
12027 | VMOVN.I<size> <Dd>, <Qm> */ | |
12028 | if (imm == 0) | |
12029 | { | |
12030 | inst.operands[2].present = 0; | |
12031 | inst.instruction = N_MNEM_vmovn; | |
12032 | do_neon_movn (); | |
12033 | return; | |
12034 | } | |
12035 | ||
12036 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12037 | _("immediate out of range for narrowing operation")); | |
12038 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
12039 | } | |
12040 | ||
12041 | static void | |
12042 | do_neon_shll (void) | |
12043 | { | |
12044 | /* FIXME: Type checking when lengthening. */ | |
12045 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
12046 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
12047 | unsigned imm = inst.operands[2].imm; | |
12048 | ||
12049 | if (imm == et.size) | |
12050 | { | |
12051 | /* Maximum shift variant. */ | |
12052 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12053 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12054 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12055 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12056 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12057 | inst.instruction |= neon_logbits (et.size) << 18; | |
12058 | ||
12059 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12060 | } | |
12061 | else | |
12062 | { | |
12063 | /* A more-specific type check for non-max versions. */ | |
12064 | et = neon_check_type (2, NS_QDI, | |
12065 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
12066 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12067 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); | |
12068 | } | |
12069 | } | |
12070 | ||
037e8744 | 12071 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
12072 | the current instruction is. */ |
12073 | ||
12074 | static int | |
12075 | neon_cvt_flavour (enum neon_shape rs) | |
12076 | { | |
037e8744 JB |
12077 | #define CVT_VAR(C,X,Y) \ |
12078 | et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \ | |
12079 | if (et.type != NT_invtype) \ | |
12080 | { \ | |
12081 | inst.error = NULL; \ | |
12082 | return (C); \ | |
5287ad62 JB |
12083 | } |
12084 | struct neon_type_el et; | |
037e8744 JB |
12085 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
12086 | || rs == NS_FF) ? N_VFP : 0; | |
12087 | /* The instruction versions which take an immediate take one register | |
12088 | argument, which is extended to the width of the full register. Thus the | |
12089 | "source" and "destination" registers must have the same width. Hack that | |
12090 | here by making the size equal to the key (wider, in this case) operand. */ | |
12091 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5287ad62 JB |
12092 | |
12093 | CVT_VAR (0, N_S32, N_F32); | |
12094 | CVT_VAR (1, N_U32, N_F32); | |
12095 | CVT_VAR (2, N_F32, N_S32); | |
12096 | CVT_VAR (3, N_F32, N_U32); | |
12097 | ||
037e8744 JB |
12098 | whole_reg = N_VFP; |
12099 | ||
12100 | /* VFP instructions. */ | |
12101 | CVT_VAR (4, N_F32, N_F64); | |
12102 | CVT_VAR (5, N_F64, N_F32); | |
12103 | CVT_VAR (6, N_S32, N_F64 | key); | |
12104 | CVT_VAR (7, N_U32, N_F64 | key); | |
12105 | CVT_VAR (8, N_F64 | key, N_S32); | |
12106 | CVT_VAR (9, N_F64 | key, N_U32); | |
12107 | /* VFP instructions with bitshift. */ | |
12108 | CVT_VAR (10, N_F32 | key, N_S16); | |
12109 | CVT_VAR (11, N_F32 | key, N_U16); | |
12110 | CVT_VAR (12, N_F64 | key, N_S16); | |
12111 | CVT_VAR (13, N_F64 | key, N_U16); | |
12112 | CVT_VAR (14, N_S16, N_F32 | key); | |
12113 | CVT_VAR (15, N_U16, N_F32 | key); | |
12114 | CVT_VAR (16, N_S16, N_F64 | key); | |
12115 | CVT_VAR (17, N_U16, N_F64 | key); | |
12116 | ||
5287ad62 JB |
12117 | return -1; |
12118 | #undef CVT_VAR | |
12119 | } | |
12120 | ||
037e8744 JB |
12121 | /* Neon-syntax VFP conversions. */ |
12122 | ||
5287ad62 | 12123 | static void |
037e8744 | 12124 | do_vfp_nsyn_cvt (enum neon_shape rs, int flavour) |
5287ad62 | 12125 | { |
037e8744 JB |
12126 | const char *opname = 0; |
12127 | ||
12128 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) | |
5287ad62 | 12129 | { |
037e8744 JB |
12130 | /* Conversions with immediate bitshift. */ |
12131 | const char *enc[] = | |
12132 | { | |
12133 | "ftosls", | |
12134 | "ftouls", | |
12135 | "fsltos", | |
12136 | "fultos", | |
12137 | NULL, | |
12138 | NULL, | |
12139 | "ftosld", | |
12140 | "ftould", | |
12141 | "fsltod", | |
12142 | "fultod", | |
12143 | "fshtos", | |
12144 | "fuhtos", | |
12145 | "fshtod", | |
12146 | "fuhtod", | |
12147 | "ftoshs", | |
12148 | "ftouhs", | |
12149 | "ftoshd", | |
12150 | "ftouhd" | |
12151 | }; | |
12152 | ||
12153 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
12154 | { | |
12155 | opname = enc[flavour]; | |
12156 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
12157 | _("operands 0 and 1 must be the same register")); | |
12158 | inst.operands[1] = inst.operands[2]; | |
12159 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
12160 | } | |
5287ad62 JB |
12161 | } |
12162 | else | |
12163 | { | |
037e8744 JB |
12164 | /* Conversions without bitshift. */ |
12165 | const char *enc[] = | |
12166 | { | |
12167 | "ftosis", | |
12168 | "ftouis", | |
12169 | "fsitos", | |
12170 | "fuitos", | |
12171 | "fcvtsd", | |
12172 | "fcvtds", | |
12173 | "ftosid", | |
12174 | "ftouid", | |
12175 | "fsitod", | |
12176 | "fuitod" | |
12177 | }; | |
12178 | ||
12179 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
12180 | opname = enc[flavour]; | |
12181 | } | |
12182 | ||
12183 | if (opname) | |
12184 | do_vfp_nsyn_opcode (opname); | |
12185 | } | |
12186 | ||
12187 | static void | |
12188 | do_vfp_nsyn_cvtz (void) | |
12189 | { | |
12190 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
12191 | int flavour = neon_cvt_flavour (rs); | |
12192 | const char *enc[] = | |
12193 | { | |
12194 | "ftosizs", | |
12195 | "ftouizs", | |
12196 | NULL, | |
12197 | NULL, | |
12198 | NULL, | |
12199 | NULL, | |
12200 | "ftosizd", | |
12201 | "ftouizd" | |
12202 | }; | |
12203 | ||
12204 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) | |
12205 | do_vfp_nsyn_opcode (enc[flavour]); | |
12206 | } | |
12207 | ||
12208 | static void | |
12209 | do_neon_cvt (void) | |
12210 | { | |
12211 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
12212 | NS_FD, NS_DF, NS_FF, NS_NULL); | |
12213 | int flavour = neon_cvt_flavour (rs); | |
12214 | ||
12215 | /* VFP rather than Neon conversions. */ | |
12216 | if (flavour >= 4) | |
12217 | { | |
12218 | do_vfp_nsyn_cvt (rs, flavour); | |
12219 | return; | |
12220 | } | |
12221 | ||
12222 | switch (rs) | |
12223 | { | |
12224 | case NS_DDI: | |
12225 | case NS_QQI: | |
12226 | { | |
12227 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12228 | return; | |
12229 | ||
12230 | /* Fixed-point conversion with #0 immediate is encoded as an | |
12231 | integer conversion. */ | |
12232 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
12233 | goto int_encode; | |
12234 | unsigned immbits = 32 - inst.operands[2].imm; | |
12235 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
12236 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12237 | if (flavour != -1) | |
12238 | inst.instruction |= enctab[flavour]; | |
12239 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12240 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12241 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12242 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12243 | inst.instruction |= neon_quad (rs) << 6; | |
12244 | inst.instruction |= 1 << 21; | |
12245 | inst.instruction |= immbits << 16; | |
12246 | ||
12247 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12248 | } | |
12249 | break; | |
12250 | ||
12251 | case NS_DD: | |
12252 | case NS_QQ: | |
12253 | int_encode: | |
12254 | { | |
12255 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
12256 | ||
12257 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12258 | ||
12259 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12260 | return; | |
12261 | ||
12262 | if (flavour != -1) | |
12263 | inst.instruction |= enctab[flavour]; | |
12264 | ||
12265 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12266 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12267 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12268 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12269 | inst.instruction |= neon_quad (rs) << 6; | |
12270 | inst.instruction |= 2 << 18; | |
12271 | ||
12272 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12273 | } | |
12274 | break; | |
12275 | ||
12276 | default: | |
12277 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
12278 | do_vfp_nsyn_cvt (rs, flavour); | |
5287ad62 | 12279 | } |
5287ad62 JB |
12280 | } |
12281 | ||
12282 | static void | |
12283 | neon_move_immediate (void) | |
12284 | { | |
037e8744 JB |
12285 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
12286 | struct neon_type_el et = neon_check_type (2, rs, | |
12287 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 JB |
12288 | unsigned immlo, immhi = 0, immbits; |
12289 | int op, cmode; | |
12290 | ||
037e8744 JB |
12291 | constraint (et.type == NT_invtype, |
12292 | _("operand size must be specified for immediate VMOV")); | |
12293 | ||
5287ad62 JB |
12294 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
12295 | op = (inst.instruction & (1 << 5)) != 0; | |
12296 | ||
12297 | immlo = inst.operands[1].imm; | |
12298 | if (inst.operands[1].regisimm) | |
12299 | immhi = inst.operands[1].reg; | |
12300 | ||
12301 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
12302 | _("immediate has bits set outside the operand size")); | |
12303 | ||
12304 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op, | |
136da414 | 12305 | et.size, et.type)) == FAIL) |
5287ad62 JB |
12306 | { |
12307 | /* Invert relevant bits only. */ | |
12308 | neon_invert_size (&immlo, &immhi, et.size); | |
12309 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
12310 | with one or the other; those cases are caught by | |
12311 | neon_cmode_for_move_imm. */ | |
12312 | op = !op; | |
12313 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op, | |
136da414 | 12314 | et.size, et.type)) == FAIL) |
5287ad62 | 12315 | { |
dcbf9037 | 12316 | first_error (_("immediate out of range")); |
5287ad62 JB |
12317 | return; |
12318 | } | |
12319 | } | |
12320 | ||
12321 | inst.instruction &= ~(1 << 5); | |
12322 | inst.instruction |= op << 5; | |
12323 | ||
12324 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12325 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 12326 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12327 | inst.instruction |= cmode << 8; |
12328 | ||
12329 | neon_write_immbits (immbits); | |
12330 | } | |
12331 | ||
12332 | static void | |
12333 | do_neon_mvn (void) | |
12334 | { | |
12335 | if (inst.operands[1].isreg) | |
12336 | { | |
037e8744 | 12337 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12338 | |
12339 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12340 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12341 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12342 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12343 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 12344 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12345 | } |
12346 | else | |
12347 | { | |
12348 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12349 | neon_move_immediate (); | |
12350 | } | |
12351 | ||
12352 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12353 | } | |
12354 | ||
12355 | /* Encode instructions of form: | |
12356 | ||
12357 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
12358 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | | |
12359 | ||
12360 | */ | |
12361 | ||
12362 | static void | |
12363 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
12364 | { | |
12365 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12366 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12367 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12368 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12369 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12370 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12371 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
12372 | inst.instruction |= neon_logbits (size) << 20; | |
12373 | ||
12374 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12375 | } | |
12376 | ||
12377 | static void | |
12378 | do_neon_dyadic_long (void) | |
12379 | { | |
12380 | /* FIXME: Type checking for lengthening op. */ | |
12381 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12382 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
12383 | neon_mixed_length (et, et.size); | |
12384 | } | |
12385 | ||
12386 | static void | |
12387 | do_neon_abal (void) | |
12388 | { | |
12389 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12390 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
12391 | neon_mixed_length (et, et.size); | |
12392 | } | |
12393 | ||
12394 | static void | |
12395 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
12396 | { | |
12397 | if (inst.operands[2].isscalar) | |
12398 | { | |
dcbf9037 JB |
12399 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
12400 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
5287ad62 JB |
12401 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
12402 | neon_mul_mac (et, et.type == NT_unsigned); | |
12403 | } | |
12404 | else | |
12405 | { | |
12406 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12407 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
12408 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12409 | neon_mixed_length (et, et.size); | |
12410 | } | |
12411 | } | |
12412 | ||
12413 | static void | |
12414 | do_neon_mac_maybe_scalar_long (void) | |
12415 | { | |
12416 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
12417 | } | |
12418 | ||
12419 | static void | |
12420 | do_neon_dyadic_wide (void) | |
12421 | { | |
12422 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
12423 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
12424 | neon_mixed_length (et, et.size); | |
12425 | } | |
12426 | ||
12427 | static void | |
12428 | do_neon_dyadic_narrow (void) | |
12429 | { | |
12430 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12431 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
12432 | neon_mixed_length (et, et.size / 2); | |
12433 | } | |
12434 | ||
12435 | static void | |
12436 | do_neon_mul_sat_scalar_long (void) | |
12437 | { | |
12438 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
12439 | } | |
12440 | ||
12441 | static void | |
12442 | do_neon_vmull (void) | |
12443 | { | |
12444 | if (inst.operands[2].isscalar) | |
12445 | do_neon_mac_maybe_scalar_long (); | |
12446 | else | |
12447 | { | |
12448 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12449 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY); | |
12450 | if (et.type == NT_poly) | |
12451 | inst.instruction = NEON_ENC_POLY (inst.instruction); | |
12452 | else | |
12453 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12454 | /* For polynomial encoding, size field must be 0b00 and the U bit must be | |
12455 | zero. Should be OK as-is. */ | |
12456 | neon_mixed_length (et, et.size); | |
12457 | } | |
12458 | } | |
12459 | ||
12460 | static void | |
12461 | do_neon_ext (void) | |
12462 | { | |
037e8744 | 12463 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
12464 | struct neon_type_el et = neon_check_type (3, rs, |
12465 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
12466 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
12467 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12468 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12469 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12470 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12471 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12472 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 12473 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12474 | inst.instruction |= imm << 8; |
12475 | ||
12476 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12477 | } | |
12478 | ||
12479 | static void | |
12480 | do_neon_rev (void) | |
12481 | { | |
037e8744 | 12482 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12483 | struct neon_type_el et = neon_check_type (2, rs, |
12484 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
12485 | unsigned op = (inst.instruction >> 7) & 3; | |
12486 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
12487 | extract it here to check the elements to be reversed are smaller. | |
12488 | Otherwise we'd get a reserved instruction. */ | |
12489 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
12490 | assert (elsize != 0); | |
12491 | constraint (et.size >= elsize, | |
12492 | _("elements must be smaller than reversal region")); | |
037e8744 | 12493 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12494 | } |
12495 | ||
12496 | static void | |
12497 | do_neon_dup (void) | |
12498 | { | |
12499 | if (inst.operands[1].isscalar) | |
12500 | { | |
037e8744 | 12501 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
12502 | struct neon_type_el et = neon_check_type (2, rs, |
12503 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 12504 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 12505 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 12506 | int logsize = neon_logbits (et.size); |
dcbf9037 | 12507 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
12508 | |
12509 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
12510 | return; | |
12511 | ||
5287ad62 JB |
12512 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
12513 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12514 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12515 | inst.instruction |= LOW4 (dm); | |
12516 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 12517 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12518 | inst.instruction |= x << 17; |
12519 | inst.instruction |= sizebits << 16; | |
12520 | ||
12521 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12522 | } | |
12523 | else | |
12524 | { | |
037e8744 JB |
12525 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
12526 | struct neon_type_el et = neon_check_type (2, rs, | |
12527 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 JB |
12528 | /* Duplicate ARM register to lanes of vector. */ |
12529 | inst.instruction = NEON_ENC_ARMREG (inst.instruction); | |
12530 | switch (et.size) | |
12531 | { | |
12532 | case 8: inst.instruction |= 0x400000; break; | |
12533 | case 16: inst.instruction |= 0x000020; break; | |
12534 | case 32: inst.instruction |= 0x000000; break; | |
12535 | default: break; | |
12536 | } | |
12537 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
12538 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
12539 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 12540 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
12541 | /* The encoding for this instruction is identical for the ARM and Thumb |
12542 | variants, except for the condition field. */ | |
037e8744 | 12543 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
12544 | } |
12545 | } | |
12546 | ||
12547 | /* VMOV has particularly many variations. It can be one of: | |
12548 | 0. VMOV<c><q> <Qd>, <Qm> | |
12549 | 1. VMOV<c><q> <Dd>, <Dm> | |
12550 | (Register operations, which are VORR with Rm = Rn.) | |
12551 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
12552 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
12553 | (Immediate loads.) | |
12554 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
12555 | (ARM register to scalar.) | |
12556 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
12557 | (Two ARM registers to vector.) | |
12558 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
12559 | (Scalar to ARM register.) | |
12560 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
12561 | (Vector to two ARM registers.) | |
037e8744 JB |
12562 | 8. VMOV.F32 <Sd>, <Sm> |
12563 | 9. VMOV.F64 <Dd>, <Dm> | |
12564 | (VFP register moves.) | |
12565 | 10. VMOV.F32 <Sd>, #imm | |
12566 | 11. VMOV.F64 <Dd>, #imm | |
12567 | (VFP float immediate load.) | |
12568 | 12. VMOV <Rd>, <Sm> | |
12569 | (VFP single to ARM reg.) | |
12570 | 13. VMOV <Sd>, <Rm> | |
12571 | (ARM reg to VFP single.) | |
12572 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
12573 | (Two ARM regs to two VFP singles.) | |
12574 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
12575 | (Two VFP singles to two ARM regs.) | |
5287ad62 | 12576 | |
037e8744 JB |
12577 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
12578 | and 3/11 which depend on the operand type too. | |
5287ad62 JB |
12579 | |
12580 | All the encoded bits are hardcoded by this function. | |
12581 | ||
b7fc2769 JB |
12582 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
12583 | Cases 5, 7 may be used with VFPv2 and above. | |
12584 | ||
5287ad62 JB |
12585 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
12586 | can specify a type where it doesn't make sense to, and is ignored). | |
12587 | */ | |
12588 | ||
12589 | static void | |
12590 | do_neon_mov (void) | |
12591 | { | |
037e8744 JB |
12592 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
12593 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
12594 | NS_NULL); | |
12595 | struct neon_type_el et; | |
12596 | const char *ldconst = 0; | |
5287ad62 | 12597 | |
037e8744 | 12598 | switch (rs) |
5287ad62 | 12599 | { |
037e8744 JB |
12600 | case NS_DD: /* case 1/9. */ |
12601 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
12602 | /* It is not an error here if no type is given. */ | |
12603 | inst.error = NULL; | |
12604 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 12605 | { |
037e8744 JB |
12606 | do_vfp_nsyn_opcode ("fcpyd"); |
12607 | break; | |
5287ad62 | 12608 | } |
037e8744 | 12609 | /* fall through. */ |
5287ad62 | 12610 | |
037e8744 JB |
12611 | case NS_QQ: /* case 0/1. */ |
12612 | { | |
12613 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12614 | return; | |
12615 | /* The architecture manual I have doesn't explicitly state which | |
12616 | value the U bit should have for register->register moves, but | |
12617 | the equivalent VORR instruction has U = 0, so do that. */ | |
12618 | inst.instruction = 0x0200110; | |
12619 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12620 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12621 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12622 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12623 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12624 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12625 | inst.instruction |= neon_quad (rs) << 6; | |
12626 | ||
12627 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12628 | } | |
12629 | break; | |
12630 | ||
12631 | case NS_DI: /* case 3/11. */ | |
12632 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
12633 | inst.error = NULL; | |
12634 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 12635 | { |
037e8744 JB |
12636 | /* case 11 (fconstd). */ |
12637 | ldconst = "fconstd"; | |
12638 | goto encode_fconstd; | |
5287ad62 | 12639 | } |
037e8744 JB |
12640 | /* fall through. */ |
12641 | ||
12642 | case NS_QI: /* case 2/3. */ | |
12643 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12644 | return; | |
12645 | inst.instruction = 0x0800010; | |
12646 | neon_move_immediate (); | |
12647 | inst.instruction = neon_dp_fixup (inst.instruction); | |
5287ad62 JB |
12648 | break; |
12649 | ||
037e8744 JB |
12650 | case NS_SR: /* case 4. */ |
12651 | { | |
12652 | unsigned bcdebits = 0; | |
12653 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
12654 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
12655 | int logsize = neon_logbits (et.size); | |
12656 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
12657 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
12658 | ||
12659 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
12660 | _(BAD_FPU)); | |
12661 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
12662 | && et.size != 32, _(BAD_FPU)); | |
12663 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
12664 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
12665 | ||
12666 | switch (et.size) | |
12667 | { | |
12668 | case 8: bcdebits = 0x8; break; | |
12669 | case 16: bcdebits = 0x1; break; | |
12670 | case 32: bcdebits = 0x0; break; | |
12671 | default: ; | |
12672 | } | |
12673 | ||
12674 | bcdebits |= x << logsize; | |
12675 | ||
12676 | inst.instruction = 0xe000b10; | |
12677 | do_vfp_cond_or_thumb (); | |
12678 | inst.instruction |= LOW4 (dn) << 16; | |
12679 | inst.instruction |= HI1 (dn) << 7; | |
12680 | inst.instruction |= inst.operands[1].reg << 12; | |
12681 | inst.instruction |= (bcdebits & 3) << 5; | |
12682 | inst.instruction |= (bcdebits >> 2) << 21; | |
12683 | } | |
12684 | break; | |
12685 | ||
12686 | case NS_DRR: /* case 5 (fmdrr). */ | |
b7fc2769 | 12687 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 12688 | _(BAD_FPU)); |
b7fc2769 | 12689 | |
037e8744 JB |
12690 | inst.instruction = 0xc400b10; |
12691 | do_vfp_cond_or_thumb (); | |
12692 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
12693 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
12694 | inst.instruction |= inst.operands[1].reg << 12; | |
12695 | inst.instruction |= inst.operands[2].reg << 16; | |
12696 | break; | |
12697 | ||
12698 | case NS_RS: /* case 6. */ | |
12699 | { | |
12700 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
12701 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
12702 | unsigned logsize = neon_logbits (et.size); | |
12703 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
12704 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
12705 | unsigned abcdebits = 0; | |
12706 | ||
12707 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
12708 | _(BAD_FPU)); | |
12709 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
12710 | && et.size != 32, _(BAD_FPU)); | |
12711 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
12712 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
12713 | ||
12714 | switch (et.size) | |
12715 | { | |
12716 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
12717 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
12718 | case 32: abcdebits = 0x00; break; | |
12719 | default: ; | |
12720 | } | |
12721 | ||
12722 | abcdebits |= x << logsize; | |
12723 | inst.instruction = 0xe100b10; | |
12724 | do_vfp_cond_or_thumb (); | |
12725 | inst.instruction |= LOW4 (dn) << 16; | |
12726 | inst.instruction |= HI1 (dn) << 7; | |
12727 | inst.instruction |= inst.operands[0].reg << 12; | |
12728 | inst.instruction |= (abcdebits & 3) << 5; | |
12729 | inst.instruction |= (abcdebits >> 2) << 21; | |
12730 | } | |
12731 | break; | |
12732 | ||
12733 | case NS_RRD: /* case 7 (fmrrd). */ | |
12734 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
12735 | _(BAD_FPU)); | |
12736 | ||
12737 | inst.instruction = 0xc500b10; | |
12738 | do_vfp_cond_or_thumb (); | |
12739 | inst.instruction |= inst.operands[0].reg << 12; | |
12740 | inst.instruction |= inst.operands[1].reg << 16; | |
12741 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12742 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12743 | break; | |
12744 | ||
12745 | case NS_FF: /* case 8 (fcpys). */ | |
12746 | do_vfp_nsyn_opcode ("fcpys"); | |
12747 | break; | |
12748 | ||
12749 | case NS_FI: /* case 10 (fconsts). */ | |
12750 | ldconst = "fconsts"; | |
12751 | encode_fconstd: | |
12752 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 12753 | { |
037e8744 JB |
12754 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
12755 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
12756 | } |
12757 | else | |
037e8744 JB |
12758 | first_error (_("immediate out of range")); |
12759 | break; | |
12760 | ||
12761 | case NS_RF: /* case 12 (fmrs). */ | |
12762 | do_vfp_nsyn_opcode ("fmrs"); | |
12763 | break; | |
12764 | ||
12765 | case NS_FR: /* case 13 (fmsr). */ | |
12766 | do_vfp_nsyn_opcode ("fmsr"); | |
12767 | break; | |
12768 | ||
12769 | /* The encoders for the fmrrs and fmsrr instructions expect three operands | |
12770 | (one of which is a list), but we have parsed four. Do some fiddling to | |
12771 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
12772 | expect. */ | |
12773 | case NS_RRFF: /* case 14 (fmrrs). */ | |
12774 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
12775 | _("VFP registers must be adjacent")); | |
12776 | inst.operands[2].imm = 2; | |
12777 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
12778 | do_vfp_nsyn_opcode ("fmrrs"); | |
12779 | break; | |
12780 | ||
12781 | case NS_FFRR: /* case 15 (fmsrr). */ | |
12782 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
12783 | _("VFP registers must be adjacent")); | |
12784 | inst.operands[1] = inst.operands[2]; | |
12785 | inst.operands[2] = inst.operands[3]; | |
12786 | inst.operands[0].imm = 2; | |
12787 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
12788 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 JB |
12789 | break; |
12790 | ||
12791 | default: | |
12792 | abort (); | |
12793 | } | |
12794 | } | |
12795 | ||
12796 | static void | |
12797 | do_neon_rshift_round_imm (void) | |
12798 | { | |
037e8744 | 12799 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12800 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
12801 | int imm = inst.operands[2].imm; | |
12802 | ||
12803 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
12804 | if (imm == 0) | |
12805 | { | |
12806 | inst.operands[2].present = 0; | |
12807 | do_neon_mov (); | |
12808 | return; | |
12809 | } | |
12810 | ||
12811 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12812 | _("immediate out of range for shift")); | |
037e8744 | 12813 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
12814 | et.size - imm); |
12815 | } | |
12816 | ||
12817 | static void | |
12818 | do_neon_movl (void) | |
12819 | { | |
12820 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
12821 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
12822 | unsigned sizebits = et.size >> 3; | |
12823 | inst.instruction |= sizebits << 19; | |
12824 | neon_two_same (0, et.type == NT_unsigned, -1); | |
12825 | } | |
12826 | ||
12827 | static void | |
12828 | do_neon_trn (void) | |
12829 | { | |
037e8744 | 12830 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12831 | struct neon_type_el et = neon_check_type (2, rs, |
12832 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
12833 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12834 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12835 | } |
12836 | ||
12837 | static void | |
12838 | do_neon_zip_uzp (void) | |
12839 | { | |
037e8744 | 12840 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12841 | struct neon_type_el et = neon_check_type (2, rs, |
12842 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
12843 | if (rs == NS_DD && et.size == 32) | |
12844 | { | |
12845 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
12846 | inst.instruction = N_MNEM_vtrn; | |
12847 | do_neon_trn (); | |
12848 | return; | |
12849 | } | |
037e8744 | 12850 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12851 | } |
12852 | ||
12853 | static void | |
12854 | do_neon_sat_abs_neg (void) | |
12855 | { | |
037e8744 | 12856 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12857 | struct neon_type_el et = neon_check_type (2, rs, |
12858 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 12859 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12860 | } |
12861 | ||
12862 | static void | |
12863 | do_neon_pair_long (void) | |
12864 | { | |
037e8744 | 12865 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12866 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
12867 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
12868 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 12869 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12870 | } |
12871 | ||
12872 | static void | |
12873 | do_neon_recip_est (void) | |
12874 | { | |
037e8744 | 12875 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12876 | struct neon_type_el et = neon_check_type (2, rs, |
12877 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
12878 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 12879 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12880 | } |
12881 | ||
12882 | static void | |
12883 | do_neon_cls (void) | |
12884 | { | |
037e8744 | 12885 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12886 | struct neon_type_el et = neon_check_type (2, rs, |
12887 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 12888 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12889 | } |
12890 | ||
12891 | static void | |
12892 | do_neon_clz (void) | |
12893 | { | |
037e8744 | 12894 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12895 | struct neon_type_el et = neon_check_type (2, rs, |
12896 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 12897 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12898 | } |
12899 | ||
12900 | static void | |
12901 | do_neon_cnt (void) | |
12902 | { | |
037e8744 | 12903 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12904 | struct neon_type_el et = neon_check_type (2, rs, |
12905 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 12906 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12907 | } |
12908 | ||
12909 | static void | |
12910 | do_neon_swp (void) | |
12911 | { | |
037e8744 JB |
12912 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
12913 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
12914 | } |
12915 | ||
12916 | static void | |
12917 | do_neon_tbl_tbx (void) | |
12918 | { | |
12919 | unsigned listlenbits; | |
dcbf9037 | 12920 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5287ad62 JB |
12921 | |
12922 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) | |
12923 | { | |
dcbf9037 | 12924 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
12925 | return; |
12926 | } | |
12927 | ||
12928 | listlenbits = inst.operands[1].imm - 1; | |
12929 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12930 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12931 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12932 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12933 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12934 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12935 | inst.instruction |= listlenbits << 8; | |
12936 | ||
12937 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12938 | } | |
12939 | ||
12940 | static void | |
12941 | do_neon_ldm_stm (void) | |
12942 | { | |
12943 | /* P, U and L bits are part of bitmask. */ | |
12944 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
12945 | unsigned offsetbits = inst.operands[1].imm * 2; | |
12946 | ||
037e8744 JB |
12947 | if (inst.operands[1].issingle) |
12948 | { | |
12949 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
12950 | return; | |
12951 | } | |
12952 | ||
5287ad62 JB |
12953 | constraint (is_dbmode && !inst.operands[0].writeback, |
12954 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
12955 | ||
12956 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
12957 | _("register list must contain at least 1 and at most 16 " | |
12958 | "registers")); | |
12959 | ||
12960 | inst.instruction |= inst.operands[0].reg << 16; | |
12961 | inst.instruction |= inst.operands[0].writeback << 21; | |
12962 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
12963 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
12964 | ||
12965 | inst.instruction |= offsetbits; | |
12966 | ||
037e8744 | 12967 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
12968 | } |
12969 | ||
12970 | static void | |
12971 | do_neon_ldr_str (void) | |
12972 | { | |
5287ad62 JB |
12973 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
12974 | ||
037e8744 JB |
12975 | if (inst.operands[0].issingle) |
12976 | { | |
cd2f129f JB |
12977 | if (is_ldr) |
12978 | do_vfp_nsyn_opcode ("flds"); | |
12979 | else | |
12980 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
12981 | } |
12982 | else | |
5287ad62 | 12983 | { |
cd2f129f JB |
12984 | if (is_ldr) |
12985 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 12986 | else |
cd2f129f | 12987 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 12988 | } |
5287ad62 JB |
12989 | } |
12990 | ||
12991 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
12992 | instructions. */ | |
12993 | ||
12994 | static void | |
12995 | do_neon_ld_st_interleave (void) | |
12996 | { | |
037e8744 | 12997 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
12998 | N_8 | N_16 | N_32 | N_64); |
12999 | unsigned alignbits = 0; | |
13000 | unsigned idx; | |
13001 | /* The bits in this table go: | |
13002 | 0: register stride of one (0) or two (1) | |
13003 | 1,2: register list length, minus one (1, 2, 3, 4). | |
13004 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
13005 | We use -1 for invalid entries. */ | |
13006 | const int typetable[] = | |
13007 | { | |
13008 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
13009 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
13010 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
13011 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
13012 | }; | |
13013 | int typebits; | |
13014 | ||
dcbf9037 JB |
13015 | if (et.type == NT_invtype) |
13016 | return; | |
13017 | ||
5287ad62 JB |
13018 | if (inst.operands[1].immisalign) |
13019 | switch (inst.operands[1].imm >> 8) | |
13020 | { | |
13021 | case 64: alignbits = 1; break; | |
13022 | case 128: | |
13023 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
13024 | goto bad_alignment; | |
13025 | alignbits = 2; | |
13026 | break; | |
13027 | case 256: | |
13028 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
13029 | goto bad_alignment; | |
13030 | alignbits = 3; | |
13031 | break; | |
13032 | default: | |
13033 | bad_alignment: | |
dcbf9037 | 13034 | first_error (_("bad alignment")); |
5287ad62 JB |
13035 | return; |
13036 | } | |
13037 | ||
13038 | inst.instruction |= alignbits << 4; | |
13039 | inst.instruction |= neon_logbits (et.size) << 6; | |
13040 | ||
13041 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
13042 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
13043 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
13044 | up the right value for "type" in a table based on this value and the given | |
13045 | list style, then stick it back. */ | |
13046 | idx = ((inst.operands[0].imm >> 4) & 7) | |
13047 | | (((inst.instruction >> 8) & 3) << 3); | |
13048 | ||
13049 | typebits = typetable[idx]; | |
13050 | ||
13051 | constraint (typebits == -1, _("bad list type for instruction")); | |
13052 | ||
13053 | inst.instruction &= ~0xf00; | |
13054 | inst.instruction |= typebits << 8; | |
13055 | } | |
13056 | ||
13057 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
13058 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
13059 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
13060 | values, terminated with -1. */ | |
13061 | ||
13062 | static int | |
13063 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
13064 | { | |
13065 | va_list ap; | |
13066 | int result = FAIL, thissize, thisalign; | |
13067 | ||
13068 | if (!inst.operands[1].immisalign) | |
13069 | { | |
13070 | *do_align = 0; | |
13071 | return SUCCESS; | |
13072 | } | |
13073 | ||
13074 | va_start (ap, do_align); | |
13075 | ||
13076 | do | |
13077 | { | |
13078 | thissize = va_arg (ap, int); | |
13079 | if (thissize == -1) | |
13080 | break; | |
13081 | thisalign = va_arg (ap, int); | |
13082 | ||
13083 | if (size == thissize && align == thisalign) | |
13084 | result = SUCCESS; | |
13085 | } | |
13086 | while (result != SUCCESS); | |
13087 | ||
13088 | va_end (ap); | |
13089 | ||
13090 | if (result == SUCCESS) | |
13091 | *do_align = 1; | |
13092 | else | |
dcbf9037 | 13093 | first_error (_("unsupported alignment for instruction")); |
5287ad62 JB |
13094 | |
13095 | return result; | |
13096 | } | |
13097 | ||
13098 | static void | |
13099 | do_neon_ld_st_lane (void) | |
13100 | { | |
037e8744 | 13101 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
13102 | int align_good, do_align = 0; |
13103 | int logsize = neon_logbits (et.size); | |
13104 | int align = inst.operands[1].imm >> 8; | |
13105 | int n = (inst.instruction >> 8) & 3; | |
13106 | int max_el = 64 / et.size; | |
13107 | ||
dcbf9037 JB |
13108 | if (et.type == NT_invtype) |
13109 | return; | |
13110 | ||
5287ad62 JB |
13111 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
13112 | _("bad list length")); | |
13113 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
13114 | _("scalar index out of range")); | |
13115 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
13116 | && et.size == 8, | |
13117 | _("stride of 2 unavailable when element size is 8")); | |
13118 | ||
13119 | switch (n) | |
13120 | { | |
13121 | case 0: /* VLD1 / VST1. */ | |
13122 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
13123 | 32, 32, -1); | |
13124 | if (align_good == FAIL) | |
13125 | return; | |
13126 | if (do_align) | |
13127 | { | |
13128 | unsigned alignbits = 0; | |
13129 | switch (et.size) | |
13130 | { | |
13131 | case 16: alignbits = 0x1; break; | |
13132 | case 32: alignbits = 0x3; break; | |
13133 | default: ; | |
13134 | } | |
13135 | inst.instruction |= alignbits << 4; | |
13136 | } | |
13137 | break; | |
13138 | ||
13139 | case 1: /* VLD2 / VST2. */ | |
13140 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
13141 | 32, 64, -1); | |
13142 | if (align_good == FAIL) | |
13143 | return; | |
13144 | if (do_align) | |
13145 | inst.instruction |= 1 << 4; | |
13146 | break; | |
13147 | ||
13148 | case 2: /* VLD3 / VST3. */ | |
13149 | constraint (inst.operands[1].immisalign, | |
13150 | _("can't use alignment with this instruction")); | |
13151 | break; | |
13152 | ||
13153 | case 3: /* VLD4 / VST4. */ | |
13154 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
13155 | 16, 64, 32, 64, 32, 128, -1); | |
13156 | if (align_good == FAIL) | |
13157 | return; | |
13158 | if (do_align) | |
13159 | { | |
13160 | unsigned alignbits = 0; | |
13161 | switch (et.size) | |
13162 | { | |
13163 | case 8: alignbits = 0x1; break; | |
13164 | case 16: alignbits = 0x1; break; | |
13165 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
13166 | default: ; | |
13167 | } | |
13168 | inst.instruction |= alignbits << 4; | |
13169 | } | |
13170 | break; | |
13171 | ||
13172 | default: ; | |
13173 | } | |
13174 | ||
13175 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
13176 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13177 | inst.instruction |= 1 << (4 + logsize); | |
13178 | ||
13179 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); | |
13180 | inst.instruction |= logsize << 10; | |
13181 | } | |
13182 | ||
13183 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
13184 | ||
13185 | static void | |
13186 | do_neon_ld_dup (void) | |
13187 | { | |
037e8744 | 13188 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
13189 | int align_good, do_align = 0; |
13190 | ||
dcbf9037 JB |
13191 | if (et.type == NT_invtype) |
13192 | return; | |
13193 | ||
5287ad62 JB |
13194 | switch ((inst.instruction >> 8) & 3) |
13195 | { | |
13196 | case 0: /* VLD1. */ | |
13197 | assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); | |
13198 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
13199 | &do_align, 16, 16, 32, 32, -1); | |
13200 | if (align_good == FAIL) | |
13201 | return; | |
13202 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
13203 | { | |
13204 | case 1: break; | |
13205 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 13206 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
13207 | } |
13208 | inst.instruction |= neon_logbits (et.size) << 6; | |
13209 | break; | |
13210 | ||
13211 | case 1: /* VLD2. */ | |
13212 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
13213 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
13214 | if (align_good == FAIL) | |
13215 | return; | |
13216 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
13217 | _("bad list length")); | |
13218 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13219 | inst.instruction |= 1 << 5; | |
13220 | inst.instruction |= neon_logbits (et.size) << 6; | |
13221 | break; | |
13222 | ||
13223 | case 2: /* VLD3. */ | |
13224 | constraint (inst.operands[1].immisalign, | |
13225 | _("can't use alignment with this instruction")); | |
13226 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
13227 | _("bad list length")); | |
13228 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13229 | inst.instruction |= 1 << 5; | |
13230 | inst.instruction |= neon_logbits (et.size) << 6; | |
13231 | break; | |
13232 | ||
13233 | case 3: /* VLD4. */ | |
13234 | { | |
13235 | int align = inst.operands[1].imm >> 8; | |
13236 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
13237 | 16, 64, 32, 64, 32, 128, -1); | |
13238 | if (align_good == FAIL) | |
13239 | return; | |
13240 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
13241 | _("bad list length")); | |
13242 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13243 | inst.instruction |= 1 << 5; | |
13244 | if (et.size == 32 && align == 128) | |
13245 | inst.instruction |= 0x3 << 6; | |
13246 | else | |
13247 | inst.instruction |= neon_logbits (et.size) << 6; | |
13248 | } | |
13249 | break; | |
13250 | ||
13251 | default: ; | |
13252 | } | |
13253 | ||
13254 | inst.instruction |= do_align << 4; | |
13255 | } | |
13256 | ||
13257 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
13258 | apart from bits [11:4]. */ | |
13259 | ||
13260 | static void | |
13261 | do_neon_ldx_stx (void) | |
13262 | { | |
13263 | switch (NEON_LANE (inst.operands[0].imm)) | |
13264 | { | |
13265 | case NEON_INTERLEAVE_LANES: | |
13266 | inst.instruction = NEON_ENC_INTERLV (inst.instruction); | |
13267 | do_neon_ld_st_interleave (); | |
13268 | break; | |
13269 | ||
13270 | case NEON_ALL_LANES: | |
13271 | inst.instruction = NEON_ENC_DUP (inst.instruction); | |
13272 | do_neon_ld_dup (); | |
13273 | break; | |
13274 | ||
13275 | default: | |
13276 | inst.instruction = NEON_ENC_LANE (inst.instruction); | |
13277 | do_neon_ld_st_lane (); | |
13278 | } | |
13279 | ||
13280 | /* L bit comes from bit mask. */ | |
13281 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13282 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13283 | inst.instruction |= inst.operands[1].reg << 16; | |
13284 | ||
13285 | if (inst.operands[1].postind) | |
13286 | { | |
13287 | int postreg = inst.operands[1].imm & 0xf; | |
13288 | constraint (!inst.operands[1].immisreg, | |
13289 | _("post-index must be a register")); | |
13290 | constraint (postreg == 0xd || postreg == 0xf, | |
13291 | _("bad register for post-index")); | |
13292 | inst.instruction |= postreg; | |
13293 | } | |
13294 | else if (inst.operands[1].writeback) | |
13295 | { | |
13296 | inst.instruction |= 0xd; | |
13297 | } | |
13298 | else | |
13299 | inst.instruction |= 0xf; | |
13300 | ||
13301 | if (thumb_mode) | |
13302 | inst.instruction |= 0xf9000000; | |
13303 | else | |
13304 | inst.instruction |= 0xf4000000; | |
13305 | } | |
13306 | ||
13307 | \f | |
13308 | /* Overall per-instruction processing. */ | |
13309 | ||
13310 | /* We need to be able to fix up arbitrary expressions in some statements. | |
13311 | This is so that we can handle symbols that are an arbitrary distance from | |
13312 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
13313 | which returns part of an address in a form which will be valid for | |
13314 | a data instruction. We do this by pushing the expression into a symbol | |
13315 | in the expr_section, and creating a fix for that. */ | |
13316 | ||
13317 | static void | |
13318 | fix_new_arm (fragS * frag, | |
13319 | int where, | |
13320 | short int size, | |
13321 | expressionS * exp, | |
13322 | int pc_rel, | |
13323 | int reloc) | |
13324 | { | |
13325 | fixS * new_fix; | |
13326 | ||
13327 | switch (exp->X_op) | |
13328 | { | |
13329 | case O_constant: | |
13330 | case O_symbol: | |
13331 | case O_add: | |
13332 | case O_subtract: | |
13333 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
13334 | break; | |
13335 | ||
13336 | default: | |
13337 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
13338 | pc_rel, reloc); | |
13339 | break; | |
13340 | } | |
13341 | ||
13342 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
13343 | instruction. */ | |
13344 | new_fix->tc_fix_data = thumb_mode; | |
13345 | } | |
13346 | ||
13347 | /* Create a frg for an instruction requiring relaxation. */ | |
13348 | static void | |
13349 | output_relax_insn (void) | |
13350 | { | |
13351 | char * to; | |
13352 | symbolS *sym; | |
0110f2b8 PB |
13353 | int offset; |
13354 | ||
6e1cb1a6 PB |
13355 | #ifdef OBJ_ELF |
13356 | /* The size of the instruction is unknown, so tie the debug info to the | |
13357 | start of the instruction. */ | |
13358 | dwarf2_emit_insn (0); | |
13359 | #endif | |
13360 | ||
0110f2b8 PB |
13361 | switch (inst.reloc.exp.X_op) |
13362 | { | |
13363 | case O_symbol: | |
13364 | sym = inst.reloc.exp.X_add_symbol; | |
13365 | offset = inst.reloc.exp.X_add_number; | |
13366 | break; | |
13367 | case O_constant: | |
13368 | sym = NULL; | |
13369 | offset = inst.reloc.exp.X_add_number; | |
13370 | break; | |
13371 | default: | |
13372 | sym = make_expr_symbol (&inst.reloc.exp); | |
13373 | offset = 0; | |
13374 | break; | |
13375 | } | |
13376 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
13377 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
13378 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
13379 | } |
13380 | ||
13381 | /* Write a 32-bit thumb instruction to buf. */ | |
13382 | static void | |
13383 | put_thumb32_insn (char * buf, unsigned long insn) | |
13384 | { | |
13385 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
13386 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
13387 | } | |
13388 | ||
b99bd4ef | 13389 | static void |
c19d1205 | 13390 | output_inst (const char * str) |
b99bd4ef | 13391 | { |
c19d1205 | 13392 | char * to = NULL; |
b99bd4ef | 13393 | |
c19d1205 | 13394 | if (inst.error) |
b99bd4ef | 13395 | { |
c19d1205 | 13396 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
13397 | return; |
13398 | } | |
0110f2b8 PB |
13399 | if (inst.relax) { |
13400 | output_relax_insn(); | |
13401 | return; | |
13402 | } | |
c19d1205 ZW |
13403 | if (inst.size == 0) |
13404 | return; | |
b99bd4ef | 13405 | |
c19d1205 ZW |
13406 | to = frag_more (inst.size); |
13407 | ||
13408 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 13409 | { |
c19d1205 | 13410 | assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 13411 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 13412 | } |
c19d1205 | 13413 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 13414 | { |
c19d1205 ZW |
13415 | assert (inst.size == (2 * INSN_SIZE)); |
13416 | md_number_to_chars (to, inst.instruction, INSN_SIZE); | |
13417 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 13418 | } |
c19d1205 ZW |
13419 | else |
13420 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 13421 | |
c19d1205 ZW |
13422 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
13423 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
13424 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
13425 | inst.reloc.type); | |
b99bd4ef | 13426 | |
c19d1205 ZW |
13427 | #ifdef OBJ_ELF |
13428 | dwarf2_emit_insn (inst.size); | |
13429 | #endif | |
13430 | } | |
b99bd4ef | 13431 | |
c19d1205 ZW |
13432 | /* Tag values used in struct asm_opcode's tag field. */ |
13433 | enum opcode_tag | |
13434 | { | |
13435 | OT_unconditional, /* Instruction cannot be conditionalized. | |
13436 | The ARM condition field is still 0xE. */ | |
13437 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
13438 | and carries 0xF in its ARM condition field. */ | |
13439 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
13440 | OT_csuffixF, /* Some forms of the instruction take a conditional |
13441 | suffix, others place 0xF where the condition field | |
13442 | would be. */ | |
c19d1205 ZW |
13443 | OT_cinfix3, /* Instruction takes a conditional infix, |
13444 | beginning at character index 3. (In | |
13445 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
13446 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
13447 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
13448 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
13449 | character index 3, even in unified mode. Used for | |
13450 | legacy instructions where suffix and infix forms | |
13451 | may be ambiguous. */ | |
c19d1205 | 13452 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 13453 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
13454 | OT_odd_infix_unc, /* This is the unconditional variant of an |
13455 | instruction that takes a conditional infix | |
13456 | at an unusual position. In unified mode, | |
13457 | this variant will accept a suffix. */ | |
13458 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
13459 | are the conditional variants of instructions that | |
13460 | take conditional infixes in unusual positions. | |
13461 | The infix appears at character index | |
13462 | (tag - OT_odd_infix_0). These are not accepted | |
13463 | in unified mode. */ | |
13464 | }; | |
b99bd4ef | 13465 | |
c19d1205 ZW |
13466 | /* Subroutine of md_assemble, responsible for looking up the primary |
13467 | opcode from the mnemonic the user wrote. STR points to the | |
13468 | beginning of the mnemonic. | |
13469 | ||
13470 | This is not simply a hash table lookup, because of conditional | |
13471 | variants. Most instructions have conditional variants, which are | |
13472 | expressed with a _conditional affix_ to the mnemonic. If we were | |
13473 | to encode each conditional variant as a literal string in the opcode | |
13474 | table, it would have approximately 20,000 entries. | |
13475 | ||
13476 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
13477 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
13478 | instructions take the affix as an infix, notably the s-variants of | |
13479 | the arithmetic instructions. Of those instructions, all but six | |
13480 | have the infix appear after the third character of the mnemonic. | |
13481 | ||
13482 | Accordingly, the algorithm for looking up primary opcodes given | |
13483 | an identifier is: | |
13484 | ||
13485 | 1. Look up the identifier in the opcode table. | |
13486 | If we find a match, go to step U. | |
13487 | ||
13488 | 2. Look up the last two characters of the identifier in the | |
13489 | conditions table. If we find a match, look up the first N-2 | |
13490 | characters of the identifier in the opcode table. If we | |
13491 | find a match, go to step CE. | |
13492 | ||
13493 | 3. Look up the fourth and fifth characters of the identifier in | |
13494 | the conditions table. If we find a match, extract those | |
13495 | characters from the identifier, and look up the remaining | |
13496 | characters in the opcode table. If we find a match, go | |
13497 | to step CM. | |
13498 | ||
13499 | 4. Fail. | |
13500 | ||
13501 | U. Examine the tag field of the opcode structure, in case this is | |
13502 | one of the six instructions with its conditional infix in an | |
13503 | unusual place. If it is, the tag tells us where to find the | |
13504 | infix; look it up in the conditions table and set inst.cond | |
13505 | accordingly. Otherwise, this is an unconditional instruction. | |
13506 | Again set inst.cond accordingly. Return the opcode structure. | |
13507 | ||
13508 | CE. Examine the tag field to make sure this is an instruction that | |
13509 | should receive a conditional suffix. If it is not, fail. | |
13510 | Otherwise, set inst.cond from the suffix we already looked up, | |
13511 | and return the opcode structure. | |
13512 | ||
13513 | CM. Examine the tag field to make sure this is an instruction that | |
13514 | should receive a conditional infix after the third character. | |
13515 | If it is not, fail. Otherwise, undo the edits to the current | |
13516 | line of input and proceed as for case CE. */ | |
13517 | ||
13518 | static const struct asm_opcode * | |
13519 | opcode_lookup (char **str) | |
13520 | { | |
13521 | char *end, *base; | |
13522 | char *affix; | |
13523 | const struct asm_opcode *opcode; | |
13524 | const struct asm_cond *cond; | |
e3cb604e | 13525 | char save[2]; |
c19d1205 ZW |
13526 | |
13527 | /* Scan up to the end of the mnemonic, which must end in white space, | |
13528 | '.' (in unified mode only), or end of string. */ | |
13529 | for (base = end = *str; *end != '\0'; end++) | |
13530 | if (*end == ' ' || (unified_syntax && *end == '.')) | |
13531 | break; | |
b99bd4ef | 13532 | |
c19d1205 ZW |
13533 | if (end == base) |
13534 | return 0; | |
b99bd4ef | 13535 | |
5287ad62 | 13536 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 13537 | if (end[0] == '.') |
b99bd4ef | 13538 | { |
5287ad62 JB |
13539 | int offset = 2; |
13540 | ||
13541 | if (end[1] == 'w') | |
c19d1205 | 13542 | inst.size_req = 4; |
5287ad62 | 13543 | else if (end[1] == 'n') |
c19d1205 ZW |
13544 | inst.size_req = 2; |
13545 | else | |
5287ad62 JB |
13546 | offset = 0; |
13547 | ||
13548 | inst.vectype.elems = 0; | |
13549 | ||
13550 | *str = end + offset; | |
b99bd4ef | 13551 | |
5287ad62 JB |
13552 | if (end[offset] == '.') |
13553 | { | |
13554 | /* See if we have a Neon type suffix. */ | |
dcbf9037 | 13555 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
5287ad62 JB |
13556 | return 0; |
13557 | } | |
13558 | else if (end[offset] != '\0' && end[offset] != ' ') | |
13559 | return 0; | |
b99bd4ef | 13560 | } |
c19d1205 ZW |
13561 | else |
13562 | *str = end; | |
b99bd4ef | 13563 | |
c19d1205 ZW |
13564 | /* Look for unaffixed or special-case affixed mnemonic. */ |
13565 | opcode = hash_find_n (arm_ops_hsh, base, end - base); | |
13566 | if (opcode) | |
b99bd4ef | 13567 | { |
c19d1205 ZW |
13568 | /* step U */ |
13569 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 13570 | { |
c19d1205 ZW |
13571 | inst.cond = COND_ALWAYS; |
13572 | return opcode; | |
b99bd4ef | 13573 | } |
b99bd4ef | 13574 | |
c19d1205 ZW |
13575 | if (unified_syntax) |
13576 | as_warn (_("conditional infixes are deprecated in unified syntax")); | |
13577 | affix = base + (opcode->tag - OT_odd_infix_0); | |
13578 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
13579 | assert (cond); | |
b99bd4ef | 13580 | |
c19d1205 ZW |
13581 | inst.cond = cond->value; |
13582 | return opcode; | |
13583 | } | |
b99bd4ef | 13584 | |
c19d1205 ZW |
13585 | /* Cannot have a conditional suffix on a mnemonic of less than two |
13586 | characters. */ | |
13587 | if (end - base < 3) | |
13588 | return 0; | |
b99bd4ef | 13589 | |
c19d1205 ZW |
13590 | /* Look for suffixed mnemonic. */ |
13591 | affix = end - 2; | |
13592 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
13593 | opcode = hash_find_n (arm_ops_hsh, base, affix - base); | |
13594 | if (opcode && cond) | |
13595 | { | |
13596 | /* step CE */ | |
13597 | switch (opcode->tag) | |
13598 | { | |
e3cb604e PB |
13599 | case OT_cinfix3_legacy: |
13600 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
13601 | break; | |
13602 | ||
c19d1205 | 13603 | case OT_cinfix3: |
088fa78e | 13604 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
13605 | case OT_odd_infix_unc: |
13606 | if (!unified_syntax) | |
e3cb604e | 13607 | return 0; |
c19d1205 ZW |
13608 | /* else fall through */ |
13609 | ||
13610 | case OT_csuffix: | |
037e8744 | 13611 | case OT_csuffixF: |
c19d1205 ZW |
13612 | case OT_csuf_or_in3: |
13613 | inst.cond = cond->value; | |
13614 | return opcode; | |
13615 | ||
13616 | case OT_unconditional: | |
13617 | case OT_unconditionalF: | |
dfa9f0d5 PB |
13618 | if (thumb_mode) |
13619 | { | |
13620 | inst.cond = cond->value; | |
13621 | } | |
13622 | else | |
13623 | { | |
13624 | /* delayed diagnostic */ | |
13625 | inst.error = BAD_COND; | |
13626 | inst.cond = COND_ALWAYS; | |
13627 | } | |
c19d1205 | 13628 | return opcode; |
b99bd4ef | 13629 | |
c19d1205 ZW |
13630 | default: |
13631 | return 0; | |
13632 | } | |
13633 | } | |
b99bd4ef | 13634 | |
c19d1205 ZW |
13635 | /* Cannot have a usual-position infix on a mnemonic of less than |
13636 | six characters (five would be a suffix). */ | |
13637 | if (end - base < 6) | |
13638 | return 0; | |
b99bd4ef | 13639 | |
c19d1205 ZW |
13640 | /* Look for infixed mnemonic in the usual position. */ |
13641 | affix = base + 3; | |
13642 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
e3cb604e PB |
13643 | if (!cond) |
13644 | return 0; | |
13645 | ||
13646 | memcpy (save, affix, 2); | |
13647 | memmove (affix, affix + 2, (end - affix) - 2); | |
13648 | opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2); | |
13649 | memmove (affix + 2, affix, (end - affix) - 2); | |
13650 | memcpy (affix, save, 2); | |
13651 | ||
088fa78e KH |
13652 | if (opcode |
13653 | && (opcode->tag == OT_cinfix3 | |
13654 | || opcode->tag == OT_cinfix3_deprecated | |
13655 | || opcode->tag == OT_csuf_or_in3 | |
13656 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 13657 | { |
c19d1205 | 13658 | /* step CM */ |
088fa78e KH |
13659 | if (unified_syntax |
13660 | && (opcode->tag == OT_cinfix3 | |
13661 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
13662 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
13663 | ||
13664 | inst.cond = cond->value; | |
13665 | return opcode; | |
b99bd4ef NC |
13666 | } |
13667 | ||
c19d1205 | 13668 | return 0; |
b99bd4ef NC |
13669 | } |
13670 | ||
c19d1205 ZW |
13671 | void |
13672 | md_assemble (char *str) | |
b99bd4ef | 13673 | { |
c19d1205 ZW |
13674 | char *p = str; |
13675 | const struct asm_opcode * opcode; | |
b99bd4ef | 13676 | |
c19d1205 ZW |
13677 | /* Align the previous label if needed. */ |
13678 | if (last_label_seen != NULL) | |
b99bd4ef | 13679 | { |
c19d1205 ZW |
13680 | symbol_set_frag (last_label_seen, frag_now); |
13681 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
13682 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
13683 | } |
13684 | ||
c19d1205 ZW |
13685 | memset (&inst, '\0', sizeof (inst)); |
13686 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 13687 | |
c19d1205 ZW |
13688 | opcode = opcode_lookup (&p); |
13689 | if (!opcode) | |
b99bd4ef | 13690 | { |
c19d1205 | 13691 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 JB |
13692 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
13693 | if (!create_register_alias (str, p) | |
13694 | && !create_neon_reg_alias (str, p)) | |
c19d1205 | 13695 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 13696 | |
b99bd4ef NC |
13697 | return; |
13698 | } | |
13699 | ||
088fa78e KH |
13700 | if (opcode->tag == OT_cinfix3_deprecated) |
13701 | as_warn (_("s suffix on comparison instruction is deprecated")); | |
13702 | ||
037e8744 JB |
13703 | /* The value which unconditional instructions should have in place of the |
13704 | condition field. */ | |
13705 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
13706 | ||
c19d1205 | 13707 | if (thumb_mode) |
b99bd4ef | 13708 | { |
e74cfd16 | 13709 | arm_feature_set variant; |
8f06b2d8 PB |
13710 | |
13711 | variant = cpu_variant; | |
13712 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
13713 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
13714 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 13715 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
13716 | if (!opcode->tvariant |
13717 | || (thumb_mode == 1 | |
13718 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 13719 | { |
c19d1205 | 13720 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
13721 | return; |
13722 | } | |
c19d1205 ZW |
13723 | if (inst.cond != COND_ALWAYS && !unified_syntax |
13724 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 13725 | { |
c19d1205 | 13726 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
13727 | return; |
13728 | } | |
13729 | ||
e27ec89e PB |
13730 | /* Check conditional suffixes. */ |
13731 | if (current_it_mask) | |
13732 | { | |
13733 | int cond; | |
13734 | cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1; | |
dfa9f0d5 PB |
13735 | current_it_mask <<= 1; |
13736 | current_it_mask &= 0x1f; | |
13737 | /* The BKPT instruction is unconditional even in an IT block. */ | |
13738 | if (!inst.error | |
13739 | && cond != inst.cond && opcode->tencode != do_t_bkpt) | |
e27ec89e PB |
13740 | { |
13741 | as_bad (_("incorrect condition in IT block")); | |
13742 | return; | |
13743 | } | |
e27ec89e PB |
13744 | } |
13745 | else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch) | |
13746 | { | |
13747 | as_bad (_("thumb conditional instrunction not in IT block")); | |
13748 | return; | |
13749 | } | |
13750 | ||
c19d1205 ZW |
13751 | mapping_state (MAP_THUMB); |
13752 | inst.instruction = opcode->tvalue; | |
13753 | ||
13754 | if (!parse_operands (p, opcode->operands)) | |
13755 | opcode->tencode (); | |
13756 | ||
e27ec89e PB |
13757 | /* Clear current_it_mask at the end of an IT block. */ |
13758 | if (current_it_mask == 0x10) | |
13759 | current_it_mask = 0; | |
13760 | ||
0110f2b8 | 13761 | if (!(inst.error || inst.relax)) |
b99bd4ef | 13762 | { |
c19d1205 ZW |
13763 | assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
13764 | inst.size = (inst.instruction > 0xffff ? 4 : 2); | |
13765 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 13766 | { |
c19d1205 | 13767 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
13768 | return; |
13769 | } | |
13770 | } | |
e74cfd16 PB |
13771 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
13772 | *opcode->tvariant); | |
ee065d83 | 13773 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 13774 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
ee065d83 PB |
13775 | anything other than bl/blx. |
13776 | This is overly pessimistic for relaxable instructions. */ | |
13777 | if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) | |
13778 | || inst.relax) | |
e74cfd16 PB |
13779 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
13780 | arm_ext_v6t2); | |
c19d1205 ZW |
13781 | } |
13782 | else | |
13783 | { | |
13784 | /* Check that this instruction is supported for this CPU. */ | |
62b3e311 PB |
13785 | if (!opcode->avariant || |
13786 | !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)) | |
b99bd4ef | 13787 | { |
c19d1205 ZW |
13788 | as_bad (_("selected processor does not support `%s'"), str); |
13789 | return; | |
b99bd4ef | 13790 | } |
c19d1205 | 13791 | if (inst.size_req) |
b99bd4ef | 13792 | { |
c19d1205 ZW |
13793 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
13794 | return; | |
b99bd4ef NC |
13795 | } |
13796 | ||
c19d1205 ZW |
13797 | mapping_state (MAP_ARM); |
13798 | inst.instruction = opcode->avalue; | |
13799 | if (opcode->tag == OT_unconditionalF) | |
13800 | inst.instruction |= 0xF << 28; | |
13801 | else | |
13802 | inst.instruction |= inst.cond << 28; | |
13803 | inst.size = INSN_SIZE; | |
13804 | if (!parse_operands (p, opcode->operands)) | |
13805 | opcode->aencode (); | |
ee065d83 PB |
13806 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
13807 | on a hypothetical non-thumb v5 core. */ | |
e74cfd16 PB |
13808 | if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t) |
13809 | || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5)) | |
13810 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); | |
ee065d83 | 13811 | else |
e74cfd16 PB |
13812 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
13813 | *opcode->avariant); | |
b99bd4ef | 13814 | } |
c19d1205 ZW |
13815 | output_inst (str); |
13816 | } | |
b99bd4ef | 13817 | |
c19d1205 ZW |
13818 | /* Various frobbings of labels and their addresses. */ |
13819 | ||
13820 | void | |
13821 | arm_start_line_hook (void) | |
13822 | { | |
13823 | last_label_seen = NULL; | |
b99bd4ef NC |
13824 | } |
13825 | ||
c19d1205 ZW |
13826 | void |
13827 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 13828 | { |
c19d1205 | 13829 | last_label_seen = sym; |
b99bd4ef | 13830 | |
c19d1205 | 13831 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 13832 | |
c19d1205 ZW |
13833 | #if defined OBJ_COFF || defined OBJ_ELF |
13834 | ARM_SET_INTERWORK (sym, support_interwork); | |
13835 | #endif | |
b99bd4ef | 13836 | |
c19d1205 ZW |
13837 | /* Note - do not allow local symbols (.Lxxx) to be labeled |
13838 | as Thumb functions. This is because these labels, whilst | |
13839 | they exist inside Thumb code, are not the entry points for | |
13840 | possible ARM->Thumb calls. Also, these labels can be used | |
13841 | as part of a computed goto or switch statement. eg gcc | |
13842 | can generate code that looks like this: | |
b99bd4ef | 13843 | |
c19d1205 ZW |
13844 | ldr r2, [pc, .Laaa] |
13845 | lsl r3, r3, #2 | |
13846 | ldr r2, [r3, r2] | |
13847 | mov pc, r2 | |
b99bd4ef | 13848 | |
c19d1205 ZW |
13849 | .Lbbb: .word .Lxxx |
13850 | .Lccc: .word .Lyyy | |
13851 | ..etc... | |
13852 | .Laaa: .word Lbbb | |
b99bd4ef | 13853 | |
c19d1205 ZW |
13854 | The first instruction loads the address of the jump table. |
13855 | The second instruction converts a table index into a byte offset. | |
13856 | The third instruction gets the jump address out of the table. | |
13857 | The fourth instruction performs the jump. | |
b99bd4ef | 13858 | |
c19d1205 ZW |
13859 | If the address stored at .Laaa is that of a symbol which has the |
13860 | Thumb_Func bit set, then the linker will arrange for this address | |
13861 | to have the bottom bit set, which in turn would mean that the | |
13862 | address computation performed by the third instruction would end | |
13863 | up with the bottom bit set. Since the ARM is capable of unaligned | |
13864 | word loads, the instruction would then load the incorrect address | |
13865 | out of the jump table, and chaos would ensue. */ | |
13866 | if (label_is_thumb_function_name | |
13867 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
13868 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 13869 | { |
c19d1205 ZW |
13870 | /* When the address of a Thumb function is taken the bottom |
13871 | bit of that address should be set. This will allow | |
13872 | interworking between Arm and Thumb functions to work | |
13873 | correctly. */ | |
b99bd4ef | 13874 | |
c19d1205 | 13875 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 13876 | |
c19d1205 | 13877 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 13878 | } |
07a53e5c RH |
13879 | |
13880 | #ifdef OBJ_ELF | |
13881 | dwarf2_emit_label (sym); | |
13882 | #endif | |
b99bd4ef NC |
13883 | } |
13884 | ||
c19d1205 ZW |
13885 | int |
13886 | arm_data_in_code (void) | |
b99bd4ef | 13887 | { |
c19d1205 | 13888 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 13889 | { |
c19d1205 ZW |
13890 | *input_line_pointer = '/'; |
13891 | input_line_pointer += 5; | |
13892 | *input_line_pointer = 0; | |
13893 | return 1; | |
b99bd4ef NC |
13894 | } |
13895 | ||
c19d1205 | 13896 | return 0; |
b99bd4ef NC |
13897 | } |
13898 | ||
c19d1205 ZW |
13899 | char * |
13900 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 13901 | { |
c19d1205 | 13902 | int len; |
b99bd4ef | 13903 | |
c19d1205 ZW |
13904 | if (thumb_mode && (len = strlen (name)) > 5 |
13905 | && streq (name + len - 5, "/data")) | |
13906 | *(name + len - 5) = 0; | |
b99bd4ef | 13907 | |
c19d1205 | 13908 | return name; |
b99bd4ef | 13909 | } |
c19d1205 ZW |
13910 | \f |
13911 | /* Table of all register names defined by default. The user can | |
13912 | define additional names with .req. Note that all register names | |
13913 | should appear in both upper and lowercase variants. Some registers | |
13914 | also have mixed-case names. */ | |
b99bd4ef | 13915 | |
dcbf9037 | 13916 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 13917 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 13918 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
13919 | #define REGSET(p,t) \ |
13920 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
13921 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
13922 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
13923 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
13924 | #define REGSETH(p,t) \ |
13925 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
13926 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
13927 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
13928 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
13929 | #define REGSET2(p,t) \ | |
13930 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
13931 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
13932 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
13933 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
7ed4c4c5 | 13934 | |
c19d1205 | 13935 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 13936 | { |
c19d1205 ZW |
13937 | /* ARM integer registers. */ |
13938 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 13939 | |
c19d1205 ZW |
13940 | /* ATPCS synonyms. */ |
13941 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
13942 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
13943 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 13944 | |
c19d1205 ZW |
13945 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
13946 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
13947 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 13948 | |
c19d1205 ZW |
13949 | /* Well-known aliases. */ |
13950 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
13951 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
13952 | ||
13953 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
13954 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
13955 | ||
13956 | /* Coprocessor numbers. */ | |
13957 | REGSET(p, CP), REGSET(P, CP), | |
13958 | ||
13959 | /* Coprocessor register numbers. The "cr" variants are for backward | |
13960 | compatibility. */ | |
13961 | REGSET(c, CN), REGSET(C, CN), | |
13962 | REGSET(cr, CN), REGSET(CR, CN), | |
13963 | ||
13964 | /* FPA registers. */ | |
13965 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
13966 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
13967 | ||
13968 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
13969 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
13970 | ||
13971 | /* VFP SP registers. */ | |
5287ad62 JB |
13972 | REGSET(s,VFS), REGSET(S,VFS), |
13973 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
13974 | |
13975 | /* VFP DP Registers. */ | |
5287ad62 JB |
13976 | REGSET(d,VFD), REGSET(D,VFD), |
13977 | /* Extra Neon DP registers. */ | |
13978 | REGSETH(d,VFD), REGSETH(D,VFD), | |
13979 | ||
13980 | /* Neon QP registers. */ | |
13981 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
13982 | |
13983 | /* VFP control registers. */ | |
13984 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
13985 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
13986 | ||
13987 | /* Maverick DSP coprocessor registers. */ | |
13988 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
13989 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
13990 | ||
13991 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
13992 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
13993 | REGDEF(dspsc,0,DSPSC), | |
13994 | ||
13995 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
13996 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
13997 | REGDEF(DSPSC,0,DSPSC), | |
13998 | ||
13999 | /* iWMMXt data registers - p0, c0-15. */ | |
14000 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
14001 | ||
14002 | /* iWMMXt control registers - p1, c0-3. */ | |
14003 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
14004 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
14005 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
14006 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
14007 | ||
14008 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
14009 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
14010 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
14011 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
14012 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
14013 | ||
14014 | /* XScale accumulator registers. */ | |
14015 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
14016 | }; | |
14017 | #undef REGDEF | |
14018 | #undef REGNUM | |
14019 | #undef REGSET | |
7ed4c4c5 | 14020 | |
c19d1205 ZW |
14021 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
14022 | within psr_required_here. */ | |
14023 | static const struct asm_psr psrs[] = | |
14024 | { | |
14025 | /* Backward compatibility notation. Note that "all" is no longer | |
14026 | truly all possible PSR bits. */ | |
14027 | {"all", PSR_c | PSR_f}, | |
14028 | {"flg", PSR_f}, | |
14029 | {"ctl", PSR_c}, | |
14030 | ||
14031 | /* Individual flags. */ | |
14032 | {"f", PSR_f}, | |
14033 | {"c", PSR_c}, | |
14034 | {"x", PSR_x}, | |
14035 | {"s", PSR_s}, | |
14036 | /* Combinations of flags. */ | |
14037 | {"fs", PSR_f | PSR_s}, | |
14038 | {"fx", PSR_f | PSR_x}, | |
14039 | {"fc", PSR_f | PSR_c}, | |
14040 | {"sf", PSR_s | PSR_f}, | |
14041 | {"sx", PSR_s | PSR_x}, | |
14042 | {"sc", PSR_s | PSR_c}, | |
14043 | {"xf", PSR_x | PSR_f}, | |
14044 | {"xs", PSR_x | PSR_s}, | |
14045 | {"xc", PSR_x | PSR_c}, | |
14046 | {"cf", PSR_c | PSR_f}, | |
14047 | {"cs", PSR_c | PSR_s}, | |
14048 | {"cx", PSR_c | PSR_x}, | |
14049 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
14050 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
14051 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
14052 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
14053 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
14054 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
14055 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
14056 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
14057 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
14058 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
14059 | {"scf", PSR_s | PSR_c | PSR_f}, | |
14060 | {"scx", PSR_s | PSR_c | PSR_x}, | |
14061 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
14062 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
14063 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
14064 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
14065 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
14066 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
14067 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
14068 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
14069 | {"csf", PSR_c | PSR_s | PSR_f}, | |
14070 | {"csx", PSR_c | PSR_s | PSR_x}, | |
14071 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
14072 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
14073 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
14074 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
14075 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
14076 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
14077 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
14078 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
14079 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
14080 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
14081 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
14082 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
14083 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
14084 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
14085 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
14086 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
14087 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
14088 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
14089 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
14090 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
14091 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
14092 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
14093 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
14094 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
14095 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
14096 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
14097 | }; | |
14098 | ||
62b3e311 PB |
14099 | /* Table of V7M psr names. */ |
14100 | static const struct asm_psr v7m_psrs[] = | |
14101 | { | |
14102 | {"apsr", 0 }, | |
14103 | {"iapsr", 1 }, | |
14104 | {"eapsr", 2 }, | |
14105 | {"psr", 3 }, | |
14106 | {"ipsr", 5 }, | |
14107 | {"epsr", 6 }, | |
14108 | {"iepsr", 7 }, | |
14109 | {"msp", 8 }, | |
14110 | {"psp", 9 }, | |
14111 | {"primask", 16}, | |
14112 | {"basepri", 17}, | |
14113 | {"basepri_max", 18}, | |
14114 | {"faultmask", 19}, | |
14115 | {"control", 20} | |
14116 | }; | |
14117 | ||
c19d1205 ZW |
14118 | /* Table of all shift-in-operand names. */ |
14119 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 14120 | { |
c19d1205 ZW |
14121 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
14122 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
14123 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
14124 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
14125 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
14126 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
14127 | }; | |
b99bd4ef | 14128 | |
c19d1205 ZW |
14129 | /* Table of all explicit relocation names. */ |
14130 | #ifdef OBJ_ELF | |
14131 | static struct reloc_entry reloc_names[] = | |
14132 | { | |
14133 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
14134 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
14135 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
14136 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
14137 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
14138 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
14139 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
14140 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
14141 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
14142 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
14143 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
14144 | }; | |
14145 | #endif | |
b99bd4ef | 14146 | |
c19d1205 ZW |
14147 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
14148 | static const struct asm_cond conds[] = | |
14149 | { | |
14150 | {"eq", 0x0}, | |
14151 | {"ne", 0x1}, | |
14152 | {"cs", 0x2}, {"hs", 0x2}, | |
14153 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
14154 | {"mi", 0x4}, | |
14155 | {"pl", 0x5}, | |
14156 | {"vs", 0x6}, | |
14157 | {"vc", 0x7}, | |
14158 | {"hi", 0x8}, | |
14159 | {"ls", 0x9}, | |
14160 | {"ge", 0xa}, | |
14161 | {"lt", 0xb}, | |
14162 | {"gt", 0xc}, | |
14163 | {"le", 0xd}, | |
14164 | {"al", 0xe} | |
14165 | }; | |
bfae80f2 | 14166 | |
62b3e311 PB |
14167 | static struct asm_barrier_opt barrier_opt_names[] = |
14168 | { | |
14169 | { "sy", 0xf }, | |
14170 | { "un", 0x7 }, | |
14171 | { "st", 0xe }, | |
14172 | { "unst", 0x6 } | |
14173 | }; | |
14174 | ||
c19d1205 ZW |
14175 | /* Table of ARM-format instructions. */ |
14176 | ||
14177 | /* Macros for gluing together operand strings. N.B. In all cases | |
14178 | other than OPS0, the trailing OP_stop comes from default | |
14179 | zero-initialization of the unspecified elements of the array. */ | |
14180 | #define OPS0() { OP_stop, } | |
14181 | #define OPS1(a) { OP_##a, } | |
14182 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
14183 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
14184 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
14185 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
14186 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
14187 | ||
14188 | /* These macros abstract out the exact format of the mnemonic table and | |
14189 | save some repeated characters. */ | |
14190 | ||
14191 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
14192 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
14193 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 14194 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14195 | |
14196 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
14197 | a T_MNEM_xyz enumerator. */ | |
14198 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
14199 | TxCE(mnem, aop, 0x##top, nops, ops, ae, te) | |
14200 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ | |
14201 | TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
14202 | ||
14203 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
14204 | infix after the third character. */ | |
14205 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
14206 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 14207 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e KH |
14208 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
14209 | { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ | |
14210 | THUMB_VARIANT, do_##ae, do_##te } | |
c19d1205 ZW |
14211 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
14212 | TxC3(mnem, aop, 0x##top, nops, ops, ae, te) | |
088fa78e KH |
14213 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
14214 | TxC3w(mnem, aop, 0x##top, nops, ops, ae, te) | |
c19d1205 ZW |
14215 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
14216 | TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
088fa78e KH |
14217 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
14218 | TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
c19d1205 ZW |
14219 | |
14220 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
14221 | appear in the condition table. */ | |
14222 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
14223 | { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
1887dd22 | 14224 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14225 | |
14226 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
14227 | TxCM_(m1, , m2, op, top, nops, ops, ae, te), \ | |
14228 | TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \ | |
14229 | TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \ | |
14230 | TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \ | |
14231 | TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \ | |
14232 | TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \ | |
14233 | TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \ | |
14234 | TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \ | |
14235 | TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \ | |
14236 | TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \ | |
14237 | TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \ | |
14238 | TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \ | |
14239 | TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \ | |
14240 | TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \ | |
14241 | TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \ | |
14242 | TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \ | |
14243 | TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \ | |
14244 | TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \ | |
14245 | TxCM_(m1, al, m2, op, top, nops, ops, ae, te) | |
14246 | ||
14247 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
14248 | TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te) | |
14249 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
14250 | TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
14251 | ||
14252 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
14253 | field is still 0xE. Many of the Thumb variants can be executed |
14254 | conditionally, so this is checked separately. */ | |
c19d1205 ZW |
14255 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
14256 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 14257 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14258 | |
14259 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
14260 | condition code field. */ | |
14261 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
14262 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 14263 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14264 | |
14265 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
14266 | #define CE(mnem, op, nops, ops, ae) \ |
14267 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14268 | ||
14269 | #define C3(mnem, op, nops, ops, ae) \ | |
14270 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14271 | ||
e3cb604e PB |
14272 | /* Legacy mnemonics that always have conditional infix after the third |
14273 | character. */ | |
14274 | #define CL(mnem, op, nops, ops, ae) \ | |
14275 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
14276 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14277 | ||
8f06b2d8 PB |
14278 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
14279 | #define cCE(mnem, op, nops, ops, ae) \ | |
14280 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
14281 | ||
e3cb604e PB |
14282 | /* Legacy coprocessor instructions where conditional infix and conditional |
14283 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
14284 | not just the potentially ambiguous ones. */ | |
14285 | #define cCL(mnem, op, nops, ops, ae) \ | |
14286 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
14287 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
14288 | ||
14289 | /* Coprocessor, takes either a suffix or a position-3 infix | |
14290 | (for an FPA corner case). */ | |
14291 | #define C3E(mnem, op, nops, ops, ae) \ | |
14292 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
14293 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 14294 | |
6a86118a NC |
14295 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
14296 | { #m1 #m2 #m3, OPS##nops ops, \ | |
14297 | sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
14298 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14299 | ||
14300 | #define CM(m1, m2, op, nops, ops, ae) \ | |
14301 | xCM_(m1, , m2, op, nops, ops, ae), \ | |
14302 | xCM_(m1, eq, m2, op, nops, ops, ae), \ | |
14303 | xCM_(m1, ne, m2, op, nops, ops, ae), \ | |
14304 | xCM_(m1, cs, m2, op, nops, ops, ae), \ | |
14305 | xCM_(m1, hs, m2, op, nops, ops, ae), \ | |
14306 | xCM_(m1, cc, m2, op, nops, ops, ae), \ | |
14307 | xCM_(m1, ul, m2, op, nops, ops, ae), \ | |
14308 | xCM_(m1, lo, m2, op, nops, ops, ae), \ | |
14309 | xCM_(m1, mi, m2, op, nops, ops, ae), \ | |
14310 | xCM_(m1, pl, m2, op, nops, ops, ae), \ | |
14311 | xCM_(m1, vs, m2, op, nops, ops, ae), \ | |
14312 | xCM_(m1, vc, m2, op, nops, ops, ae), \ | |
14313 | xCM_(m1, hi, m2, op, nops, ops, ae), \ | |
14314 | xCM_(m1, ls, m2, op, nops, ops, ae), \ | |
14315 | xCM_(m1, ge, m2, op, nops, ops, ae), \ | |
14316 | xCM_(m1, lt, m2, op, nops, ops, ae), \ | |
14317 | xCM_(m1, gt, m2, op, nops, ops, ae), \ | |
14318 | xCM_(m1, le, m2, op, nops, ops, ae), \ | |
14319 | xCM_(m1, al, m2, op, nops, ops, ae) | |
14320 | ||
14321 | #define UE(mnem, op, nops, ops, ae) \ | |
14322 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
14323 | ||
14324 | #define UF(mnem, op, nops, ops, ae) \ | |
14325 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
14326 | ||
5287ad62 JB |
14327 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
14328 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
14329 | use the same encoding function for each. */ | |
14330 | #define NUF(mnem, op, nops, ops, enc) \ | |
14331 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
14332 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
14333 | ||
14334 | /* Neon data processing, version which indirects through neon_enc_tab for | |
14335 | the various overloaded versions of opcodes. */ | |
14336 | #define nUF(mnem, op, nops, ops, enc) \ | |
14337 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \ | |
14338 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
14339 | ||
14340 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
14341 | version. */ | |
037e8744 JB |
14342 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
14343 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
14344 | THUMB_VARIANT, do_##enc, do_##enc } |
14345 | ||
037e8744 JB |
14346 | #define NCE(mnem, op, nops, ops, enc) \ |
14347 | NCE_tag(mnem, op, nops, ops, enc, OT_csuffix) | |
14348 | ||
14349 | #define NCEF(mnem, op, nops, ops, enc) \ | |
14350 | NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF) | |
14351 | ||
5287ad62 | 14352 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 JB |
14353 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
14354 | { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \ | |
5287ad62 JB |
14355 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
14356 | ||
037e8744 JB |
14357 | #define nCE(mnem, op, nops, ops, enc) \ |
14358 | nCE_tag(mnem, op, nops, ops, enc, OT_csuffix) | |
14359 | ||
14360 | #define nCEF(mnem, op, nops, ops, enc) \ | |
14361 | nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF) | |
14362 | ||
c19d1205 ZW |
14363 | #define do_0 0 |
14364 | ||
14365 | /* Thumb-only, unconditional. */ | |
14366 | #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te) | |
14367 | ||
c19d1205 | 14368 | static const struct asm_opcode insns[] = |
bfae80f2 | 14369 | { |
e74cfd16 PB |
14370 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
14371 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
14372 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
14373 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
14374 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
14375 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
14376 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
14377 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
4962c51a MS |
14378 | tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub), |
14379 | tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
c19d1205 ZW |
14380 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), |
14381 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
14382 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
14383 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
14384 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
14385 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
14386 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
14387 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
14388 | ||
14389 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
14390 | for setting PSR flag bits. They are obsolete in V6 and do not | |
14391 | have Thumb equivalents. */ | |
14392 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 14393 | tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 14394 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 | 14395 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
088fa78e | 14396 | tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
e3cb604e | 14397 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 | 14398 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 14399 | tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 14400 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
14401 | |
14402 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
14403 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
14404 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
14405 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
14406 | ||
4962c51a MS |
14407 | tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), |
14408 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
14409 | tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
14410 | tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
c19d1205 | 14411 | |
f5208ef2 | 14412 | tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
14413 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14414 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
f5208ef2 | 14415 | tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
14416 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14417 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
14418 | ||
14419 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
c16d2bf0 | 14420 | TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi), |
0110f2b8 | 14421 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 14422 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 14423 | |
c19d1205 | 14424 | /* Pseudo ops. */ |
e9f89963 | 14425 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
14426 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
14427 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
14428 | |
14429 | /* Thumb-compatibility pseudo ops. */ | |
14430 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
14431 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
14432 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
14433 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
14434 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 14435 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
14436 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
14437 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
14438 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
14439 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
14440 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
14441 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
14442 | ||
14443 | #undef THUMB_VARIANT | |
e74cfd16 | 14444 | #define THUMB_VARIANT &arm_ext_v6 |
2fc8bdac | 14445 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
14446 | |
14447 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
14448 | #undef THUMB_VARIANT | |
e74cfd16 | 14449 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14450 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
14451 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
14452 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 14453 | TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 14454 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
14455 | |
14456 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
3e94bf1a | 14457 | TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 14458 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), |
3e94bf1a | 14459 | TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 14460 | |
9c3c69f2 PB |
14461 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14462 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 14463 | |
9c3c69f2 PB |
14464 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14465 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
14466 | |
14467 | /* V1 instructions with no Thumb analogue at all. */ | |
14468 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
14469 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
14470 | ||
14471 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
14472 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
14473 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
14474 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
14475 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
14476 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
14477 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
14478 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
14479 | ||
14480 | #undef ARM_VARIANT | |
e74cfd16 | 14481 | #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */ |
c19d1205 | 14482 | #undef THUMB_VARIANT |
e74cfd16 | 14483 | #define THUMB_VARIANT &arm_ext_v4t |
c19d1205 ZW |
14484 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
14485 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
14486 | ||
14487 | #undef THUMB_VARIANT | |
e74cfd16 | 14488 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14489 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
14490 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
14491 | ||
14492 | /* Generic coprocessor instructions. */ | |
14493 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
4962c51a MS |
14494 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
14495 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14496 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14497 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
14498 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), |
14499 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
14500 | ||
14501 | #undef ARM_VARIANT | |
e74cfd16 | 14502 | #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */ |
c19d1205 ZW |
14503 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
14504 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
14505 | ||
14506 | #undef ARM_VARIANT | |
e74cfd16 | 14507 | #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */ |
037e8744 JB |
14508 | TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
14509 | TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), | |
c19d1205 ZW |
14510 | |
14511 | #undef ARM_VARIANT | |
e74cfd16 | 14512 | #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */ |
c19d1205 ZW |
14513 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
14514 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14515 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
14516 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14517 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
14518 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14519 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
14520 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14521 | ||
14522 | #undef ARM_VARIANT | |
e74cfd16 | 14523 | #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */ |
c19d1205 | 14524 | #undef THUMB_VARIANT |
e74cfd16 | 14525 | #define THUMB_VARIANT &arm_ext_v4t |
4962c51a MS |
14526 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), |
14527 | tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14528 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14529 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14530 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14531 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 ZW |
14532 | |
14533 | #undef ARM_VARIANT | |
e74cfd16 | 14534 | #define ARM_VARIANT &arm_ext_v4t_5 |
c19d1205 ZW |
14535 | /* ARM Architecture 4T. */ |
14536 | /* Note: bx (and blx) are required on V5, even if the processor does | |
14537 | not support Thumb. */ | |
14538 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
14539 | ||
14540 | #undef ARM_VARIANT | |
e74cfd16 | 14541 | #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */ |
c19d1205 | 14542 | #undef THUMB_VARIANT |
e74cfd16 | 14543 | #define THUMB_VARIANT &arm_ext_v5t |
c19d1205 ZW |
14544 | /* Note: blx has 2 variants; the .value coded here is for |
14545 | BLX(2). Only this variant has conditional execution. */ | |
14546 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
14547 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
14548 | ||
14549 | #undef THUMB_VARIANT | |
e74cfd16 | 14550 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 | 14551 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
4962c51a MS |
14552 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
14553 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14554 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14555 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
14556 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
14557 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
14558 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
14559 | ||
14560 | #undef ARM_VARIANT | |
e74cfd16 | 14561 | #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */ |
c19d1205 ZW |
14562 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
14563 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14564 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14565 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14566 | ||
14567 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14568 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14569 | ||
14570 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14571 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14572 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14573 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14574 | ||
14575 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14576 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14577 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14578 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14579 | ||
14580 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14581 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14582 | ||
14583 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14584 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14585 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14586 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14587 | ||
14588 | #undef ARM_VARIANT | |
e74cfd16 | 14589 | #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */ |
c19d1205 | 14590 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
4962c51a MS |
14591 | TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), |
14592 | TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 ZW |
14593 | |
14594 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
14595 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
14596 | ||
14597 | #undef ARM_VARIANT | |
e74cfd16 | 14598 | #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */ |
c19d1205 ZW |
14599 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
14600 | ||
14601 | #undef ARM_VARIANT | |
e74cfd16 | 14602 | #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */ |
c19d1205 | 14603 | #undef THUMB_VARIANT |
e74cfd16 | 14604 | #define THUMB_VARIANT &arm_ext_v6 |
c19d1205 ZW |
14605 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
14606 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
14607 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
14608 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
14609 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
14610 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14611 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14612 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14613 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14614 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
14615 | ||
14616 | #undef THUMB_VARIANT | |
e74cfd16 | 14617 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14618 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
14619 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
14620 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 PB |
14621 | |
14622 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
14623 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
14624 | ||
14625 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
14626 | #undef THUMB_VARIANT | |
14627 | #define THUMB_VARIANT &arm_ext_v6_notm | |
dfa9f0d5 | 14628 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c19d1205 ZW |
14629 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
14630 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
14631 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14632 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14633 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14634 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14635 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14636 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14637 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14638 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14639 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14640 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14641 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14642 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14643 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14644 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14645 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14646 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14647 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14648 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14649 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14650 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14651 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14652 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14653 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14654 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14655 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14656 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14657 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14658 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14659 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14660 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14661 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14662 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14663 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14664 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14665 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14666 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14667 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
14668 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
14669 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
14670 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
14671 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
14672 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
14673 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
14674 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
14675 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14676 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14677 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14678 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14679 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14680 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14681 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14682 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 14683 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
14684 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
14685 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14686 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14687 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14688 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14689 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14690 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14691 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14692 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14693 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14694 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14695 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14696 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14697 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14698 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14699 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14700 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14701 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14702 | TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs), | |
14703 | UF(srsib, 9cd0500, 1, (I31w), srs), | |
14704 | UF(srsda, 84d0500, 1, (I31w), srs), | |
14705 | TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs), | |
c19d1205 ZW |
14706 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
14707 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), | |
14708 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
14709 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14710 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
c19d1205 ZW |
14711 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), |
14712 | ||
14713 | #undef ARM_VARIANT | |
e74cfd16 | 14714 | #define ARM_VARIANT &arm_ext_v6k |
c19d1205 | 14715 | #undef THUMB_VARIANT |
e74cfd16 | 14716 | #define THUMB_VARIANT &arm_ext_v6k |
c19d1205 ZW |
14717 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
14718 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
14719 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
14720 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
14721 | ||
ebdca51a PB |
14722 | #undef THUMB_VARIANT |
14723 | #define THUMB_VARIANT &arm_ext_v6_notm | |
14724 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), | |
14725 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
14726 | ||
c19d1205 | 14727 | #undef THUMB_VARIANT |
e74cfd16 | 14728 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14729 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
14730 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
c19d1205 ZW |
14731 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), |
14732 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
c19d1205 ZW |
14733 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
14734 | ||
14735 | #undef ARM_VARIANT | |
e74cfd16 | 14736 | #define ARM_VARIANT &arm_ext_v6z |
3eb17e6b | 14737 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 ZW |
14738 | |
14739 | #undef ARM_VARIANT | |
e74cfd16 | 14740 | #define ARM_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14741 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
14742 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
14743 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
14744 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
14745 | ||
14746 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
b6895b4f PB |
14747 | TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), |
14748 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
c19d1205 ZW |
14749 | TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
14750 | ||
14751 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14752 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14753 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14754 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14755 | ||
14756 | UT(cbnz, b900, 2, (RR, EXP), t_czb), | |
14757 | UT(cbz, b100, 2, (RR, EXP), t_czb), | |
14758 | /* ARM does not really have an IT instruction. */ | |
14759 | TUE(it, 0, bf08, 1, (COND), it, t_it), | |
14760 | TUE(itt, 0, bf0c, 1, (COND), it, t_it), | |
14761 | TUE(ite, 0, bf04, 1, (COND), it, t_it), | |
14762 | TUE(ittt, 0, bf0e, 1, (COND), it, t_it), | |
14763 | TUE(itet, 0, bf06, 1, (COND), it, t_it), | |
14764 | TUE(itte, 0, bf0a, 1, (COND), it, t_it), | |
14765 | TUE(itee, 0, bf02, 1, (COND), it, t_it), | |
14766 | TUE(itttt, 0, bf0f, 1, (COND), it, t_it), | |
14767 | TUE(itett, 0, bf07, 1, (COND), it, t_it), | |
14768 | TUE(ittet, 0, bf0b, 1, (COND), it, t_it), | |
14769 | TUE(iteet, 0, bf03, 1, (COND), it, t_it), | |
14770 | TUE(ittte, 0, bf0d, 1, (COND), it, t_it), | |
14771 | TUE(itete, 0, bf05, 1, (COND), it, t_it), | |
14772 | TUE(ittee, 0, bf09, 1, (COND), it, t_it), | |
14773 | TUE(iteee, 0, bf01, 1, (COND), it, t_it), | |
14774 | ||
92e90b6e PB |
14775 | /* Thumb2 only instructions. */ |
14776 | #undef ARM_VARIANT | |
e74cfd16 | 14777 | #define ARM_VARIANT NULL |
92e90b6e PB |
14778 | |
14779 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
14780 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
14781 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), | |
14782 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
14783 | ||
62b3e311 PB |
14784 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
14785 | #undef THUMB_VARIANT | |
14786 | #define THUMB_VARIANT &arm_ext_div | |
14787 | TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), | |
14788 | TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
14789 | ||
14790 | /* ARM V7 instructions. */ | |
14791 | #undef ARM_VARIANT | |
14792 | #define ARM_VARIANT &arm_ext_v7 | |
14793 | #undef THUMB_VARIANT | |
14794 | #define THUMB_VARIANT &arm_ext_v7 | |
14795 | TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld), | |
14796 | TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
14797 | TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), | |
14798 | TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
14799 | TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
14800 | ||
c19d1205 | 14801 | #undef ARM_VARIANT |
e74cfd16 | 14802 | #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ |
8f06b2d8 PB |
14803 | cCE(wfs, e200110, 1, (RR), rd), |
14804 | cCE(rfs, e300110, 1, (RR), rd), | |
14805 | cCE(wfc, e400110, 1, (RR), rd), | |
14806 | cCE(rfc, e500110, 1, (RR), rd), | |
14807 | ||
4962c51a MS |
14808 | cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr), |
14809 | cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
14810 | cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
14811 | cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e | 14812 | |
4962c51a MS |
14813 | cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr), |
14814 | cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
14815 | cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
14816 | cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e PB |
14817 | |
14818 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
14819 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
14820 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
14821 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
14822 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
14823 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
14824 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
14825 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
14826 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
14827 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
14828 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
14829 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
14830 | ||
14831 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
14832 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
14833 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
14834 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
14835 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
14836 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
14837 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
14838 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
14839 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
14840 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
14841 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
14842 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
14843 | ||
14844 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
14845 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
14846 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
14847 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
14848 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
14849 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
14850 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
14851 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
14852 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
14853 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
14854 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
14855 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
14856 | ||
14857 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
14858 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
14859 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
14860 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
14861 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
14862 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
14863 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
14864 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
14865 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
14866 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
14867 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
14868 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
14869 | ||
14870 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
14871 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
14872 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
14873 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
14874 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
14875 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
14876 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
14877 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
14878 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
14879 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
14880 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
14881 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
14882 | ||
14883 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
14884 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
14885 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
14886 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
14887 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
14888 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
14889 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
14890 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
14891 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
14892 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
14893 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
14894 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
14895 | ||
14896 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
14897 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
14898 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
14899 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
14900 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
14901 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
14902 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
14903 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
14904 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
14905 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
14906 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
14907 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
14908 | ||
14909 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
14910 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
14911 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
14912 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
14913 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
14914 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
14915 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
14916 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
14917 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
14918 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
14919 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
14920 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
14921 | ||
14922 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
14923 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
14924 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
14925 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
14926 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
14927 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
14928 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
14929 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
14930 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
14931 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
14932 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
14933 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
14934 | ||
14935 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
14936 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
14937 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
14938 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
14939 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
14940 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
14941 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
14942 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
14943 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
14944 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
14945 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
14946 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
14947 | ||
14948 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
14949 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
14950 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
14951 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
14952 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
14953 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
14954 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
14955 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
14956 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
14957 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
14958 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
14959 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
14960 | ||
14961 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
14962 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
14963 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
14964 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
14965 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
14966 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
14967 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
14968 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
14969 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
14970 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
14971 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
14972 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
14973 | ||
14974 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
14975 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
14976 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
14977 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
14978 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
14979 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
14980 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
14981 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
14982 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
14983 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
14984 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
14985 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
14986 | ||
14987 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
14988 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
14989 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
14990 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
14991 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
14992 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
14993 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
14994 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
14995 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
14996 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
14997 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
14998 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
14999 | ||
15000 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
15001 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
15002 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
15003 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
15004 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
15005 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
15006 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
15007 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
15008 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
15009 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
15010 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
15011 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
15012 | ||
15013 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
15014 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
15015 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
15016 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
15017 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
15018 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
15019 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
15020 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
15021 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
15022 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
15023 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
15024 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
15025 | ||
15026 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15027 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15028 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15029 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15030 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15031 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15032 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15033 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15034 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15035 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15036 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15037 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15038 | ||
15039 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15040 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15041 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15042 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15043 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15044 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15045 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15046 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15047 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15048 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15049 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15050 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15051 | ||
15052 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15053 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15054 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15055 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15056 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15057 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15058 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15059 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15060 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15061 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15062 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15063 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15064 | ||
15065 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15066 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15067 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15068 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15069 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15070 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15071 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15072 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15073 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15074 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15075 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15076 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15077 | ||
15078 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15079 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15080 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15081 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15082 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15083 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15084 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15085 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15086 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15087 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15088 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15089 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15090 | ||
15091 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15092 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15093 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15094 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15095 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15096 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15097 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15098 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15099 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15100 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15101 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15102 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15103 | ||
15104 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15105 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15106 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15107 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15108 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15109 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15110 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15111 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15112 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15113 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15114 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15115 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15116 | ||
15117 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15118 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15119 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15120 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15121 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15122 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15123 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15124 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15125 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15126 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15127 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15128 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15129 | ||
15130 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15131 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15132 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15133 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15134 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15135 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15136 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15137 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15138 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15139 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15140 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15141 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15142 | ||
15143 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15144 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15145 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15146 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15147 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15148 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15149 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15150 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15151 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15152 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15153 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15154 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15155 | ||
15156 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15157 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15158 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15159 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15160 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15161 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15162 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15163 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15164 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15165 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15166 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15167 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15168 | ||
15169 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15170 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15171 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15172 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15173 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15174 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15175 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15176 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15177 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15178 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15179 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15180 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15181 | ||
15182 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15183 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15184 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15185 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15186 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15187 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15188 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15189 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15190 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15191 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15192 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15193 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
15194 | |
15195 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 15196 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 15197 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
15198 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
15199 | ||
e3cb604e PB |
15200 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
15201 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
15202 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
15203 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
15204 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
15205 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
15206 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
15207 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
15208 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
15209 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
15210 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
15211 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 15212 | |
c19d1205 ZW |
15213 | /* The implementation of the FIX instruction is broken on some |
15214 | assemblers, in that it accepts a precision specifier as well as a | |
15215 | rounding specifier, despite the fact that this is meaningless. | |
15216 | To be more compatible, we accept it as well, though of course it | |
15217 | does not set any bits. */ | |
8f06b2d8 | 15218 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
15219 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
15220 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
15221 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
15222 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
15223 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
15224 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
15225 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
15226 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
15227 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
15228 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
15229 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
15230 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 15231 | |
c19d1205 ZW |
15232 | /* Instructions that were new with the real FPA, call them V2. */ |
15233 | #undef ARM_VARIANT | |
e74cfd16 | 15234 | #define ARM_VARIANT &fpu_fpa_ext_v2 |
8f06b2d8 | 15235 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
15236 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
15237 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 15238 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
15239 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
15240 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 ZW |
15241 | |
15242 | #undef ARM_VARIANT | |
e74cfd16 | 15243 | #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ |
c19d1205 | 15244 | /* Moves and type conversions. */ |
8f06b2d8 PB |
15245 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
15246 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
15247 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
15248 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
15249 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15250 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15251 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15252 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15253 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15254 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15255 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
15256 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
15257 | |
15258 | /* Memory operations. */ | |
4962c51a MS |
15259 | cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
15260 | cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
8f06b2d8 PB |
15261 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), |
15262 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
15263 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15264 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15265 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15266 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15267 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
15268 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
15269 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
15270 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
15271 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15272 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15273 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15274 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15275 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
15276 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 15277 | |
c19d1205 | 15278 | /* Monadic operations. */ |
8f06b2d8 PB |
15279 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
15280 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15281 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
15282 | |
15283 | /* Dyadic operations. */ | |
8f06b2d8 PB |
15284 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
15285 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15286 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15287 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15288 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15289 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15290 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15291 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15292 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 15293 | |
c19d1205 | 15294 | /* Comparisons. */ |
8f06b2d8 PB |
15295 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
15296 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
15297 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15298 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 15299 | |
c19d1205 | 15300 | #undef ARM_VARIANT |
e74cfd16 | 15301 | #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ |
c19d1205 | 15302 | /* Moves and type conversions. */ |
5287ad62 | 15303 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
8f06b2d8 PB |
15304 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
15305 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
5287ad62 JB |
15306 | cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd), |
15307 | cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
15308 | cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
15309 | cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
8f06b2d8 PB |
15310 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
15311 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
15312 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
15313 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
15314 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
15315 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
15316 | |
15317 | /* Memory operations. */ | |
4962c51a MS |
15318 | cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), |
15319 | cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
8f06b2d8 PB |
15320 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), |
15321 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
15322 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
15323 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
15324 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
15325 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
15326 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
15327 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 15328 | |
c19d1205 | 15329 | /* Monadic operations. */ |
5287ad62 JB |
15330 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
15331 | cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
15332 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
15333 | |
15334 | /* Dyadic operations. */ | |
5287ad62 JB |
15335 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
15336 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15337 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15338 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15339 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15340 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15341 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15342 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15343 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 15344 | |
c19d1205 | 15345 | /* Comparisons. */ |
5287ad62 JB |
15346 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
15347 | cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd), | |
15348 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
15349 | cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 ZW |
15350 | |
15351 | #undef ARM_VARIANT | |
e74cfd16 | 15352 | #define ARM_VARIANT &fpu_vfp_ext_v2 |
8f06b2d8 PB |
15353 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
15354 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
5287ad62 JB |
15355 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), |
15356 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
15357 | ||
037e8744 JB |
15358 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
15359 | Individual encoder functions perform additional architecture checks. */ | |
15360 | #undef ARM_VARIANT | |
15361 | #define ARM_VARIANT &fpu_vfp_ext_v1xd | |
15362 | #undef THUMB_VARIANT | |
15363 | #define THUMB_VARIANT &fpu_vfp_ext_v1xd | |
15364 | /* These mnemonics are unique to VFP. */ | |
15365 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
15366 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
15367 | nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
15368 | nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
15369 | nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
15370 | nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
15371 | nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
15372 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), | |
15373 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
15374 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
15375 | ||
15376 | /* Mnemonics shared by Neon and VFP. */ | |
15377 | nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), | |
15378 | nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
15379 | nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
15380 | ||
15381 | nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
15382 | nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
15383 | ||
15384 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
15385 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
15386 | ||
15387 | NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15388 | NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15389 | NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15390 | NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15391 | NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15392 | NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
15393 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
15394 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 JB |
15395 | |
15396 | nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), | |
15397 | ||
15398 | /* NOTE: All VMOV encoding is special-cased! */ | |
15399 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
15400 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
15401 | ||
5287ad62 JB |
15402 | #undef THUMB_VARIANT |
15403 | #define THUMB_VARIANT &fpu_neon_ext_v1 | |
15404 | #undef ARM_VARIANT | |
15405 | #define ARM_VARIANT &fpu_neon_ext_v1 | |
15406 | /* Data processing with three registers of the same length. */ | |
15407 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
15408 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
15409 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
15410 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
15411 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
15412 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
15413 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
15414 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
15415 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
15416 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15417 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15418 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15419 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15420 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15421 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15422 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15423 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15424 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15425 | /* If not immediate, fall back to neon_dyadic_i64_su. | |
15426 | shl_imm should accept I8 I16 I32 I64, | |
15427 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15428 | nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), | |
15429 | nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
15430 | nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
15431 | nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
15432 | /* Logic ops, types optional & ignored. */ | |
15433 | nUF(vand, vand, 2, (RNDQ, NILO), neon_logic), | |
15434 | nUF(vandq, vand, 2, (RNQ, NILO), neon_logic), | |
15435 | nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic), | |
15436 | nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic), | |
15437 | nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic), | |
15438 | nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic), | |
15439 | nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic), | |
15440 | nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic), | |
15441 | nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
15442 | nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
15443 | /* Bitfield ops, untyped. */ | |
15444 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
15445 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
15446 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
15447 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
15448 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
15449 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
15450 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
15451 | nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
15452 | nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
15453 | nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
15454 | nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
15455 | nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
15456 | nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
15457 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall | |
15458 | back to neon_dyadic_if_su. */ | |
15459 | nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
15460 | nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
15461 | nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
15462 | nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
15463 | nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
15464 | nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
15465 | nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
15466 | nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
15467 | /* Comparison. Type I8 I16 I32 F32. Non-immediate -> neon_dyadic_if_i. */ | |
15468 | nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), | |
15469 | nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
15470 | /* As above, D registers only. */ | |
15471 | nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
15472 | nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
15473 | /* Int and float variants, signedness unimportant. */ | |
15474 | /* If not scalar, fall back to neon_dyadic_if_i. */ | |
5287ad62 | 15475 | nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
5287ad62 JB |
15476 | nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
15477 | nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
15478 | /* Add/sub take types I8 I16 I32 I64 F32. */ | |
5287ad62 | 15479 | nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
5287ad62 JB |
15480 | nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
15481 | /* vtst takes sizes 8, 16, 32. */ | |
15482 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
15483 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
15484 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
037e8744 | 15485 | nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 JB |
15486 | /* VQD{R}MULH takes S16 S32. */ |
15487 | nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
15488 | nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
15489 | nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
15490 | nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
15491 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
15492 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
15493 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
15494 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
15495 | NUF(vaclt, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
15496 | NUF(vacltq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
15497 | NUF(vacle, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
15498 | NUF(vacleq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
15499 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
15500 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
15501 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
15502 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
15503 | ||
15504 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 15505 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
15506 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
15507 | ||
15508 | /* Data processing with two registers and a shift amount. */ | |
15509 | /* Right shifts, and variants with rounding. | |
15510 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15511 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
15512 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
15513 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
15514 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
15515 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
15516 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
15517 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
15518 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
15519 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
15520 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
15521 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
15522 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
15523 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
15524 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15525 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
15526 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
15527 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
15528 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
15529 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
15530 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
15531 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
15532 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
15533 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
15534 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
15535 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
15536 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
15537 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
15538 | nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll), | |
15539 | /* CVT with optional immediate for fixed-point variant. */ | |
037e8744 | 15540 | nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 15541 | |
5287ad62 JB |
15542 | nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn), |
15543 | nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn), | |
15544 | ||
15545 | /* Data processing, three registers of different lengths. */ | |
15546 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
15547 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
15548 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
15549 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
15550 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
15551 | /* If not scalar, fall back to neon_dyadic_long. | |
15552 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
15553 | nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
15554 | nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
15555 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ | |
15556 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
15557 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
15558 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
15559 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15560 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15561 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15562 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15563 | /* Saturating doubling multiplies. Types S16 S32. */ | |
15564 | nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
15565 | nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
15566 | nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
15567 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types | |
15568 | S16 S32 U16 U32. */ | |
15569 | nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), | |
15570 | ||
15571 | /* Extract. Size 8. */ | |
15572 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I7), neon_ext), | |
15573 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I7), neon_ext), | |
15574 | ||
15575 | /* Two registers, miscellaneous. */ | |
15576 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
15577 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
15578 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
15579 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
15580 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
15581 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
15582 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
15583 | /* Vector replicate. Sizes 8 16 32. */ | |
15584 | nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup), | |
15585 | nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
15586 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ | |
15587 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
15588 | /* VMOVN. Types I16 I32 I64. */ | |
15589 | nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn), | |
15590 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ | |
15591 | nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn), | |
15592 | /* VQMOVUN. Types S16 S32 S64. */ | |
15593 | nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun), | |
15594 | /* VZIP / VUZP. Sizes 8 16 32. */ | |
15595 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
15596 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
15597 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
15598 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
15599 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
15600 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
15601 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
15602 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
15603 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
15604 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
15605 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
15606 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
15607 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
15608 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
15609 | /* Reciprocal estimates. Types U32 F32. */ | |
15610 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
15611 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
15612 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
15613 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
15614 | /* VCLS. Types S8 S16 S32. */ | |
15615 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
15616 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
15617 | /* VCLZ. Types I8 I16 I32. */ | |
15618 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
15619 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
15620 | /* VCNT. Size 8. */ | |
15621 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
15622 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
15623 | /* Two address, untyped. */ | |
15624 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
15625 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
15626 | /* VTRN. Sizes 8 16 32. */ | |
15627 | nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn), | |
15628 | nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn), | |
15629 | ||
15630 | /* Table lookup. Size 8. */ | |
15631 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
15632 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
15633 | ||
b7fc2769 JB |
15634 | #undef THUMB_VARIANT |
15635 | #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext | |
15636 | #undef ARM_VARIANT | |
15637 | #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext | |
5287ad62 JB |
15638 | /* Neon element/structure load/store. */ |
15639 | nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15640 | nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15641 | nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15642 | nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15643 | nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15644 | nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15645 | nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15646 | nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15647 | ||
15648 | #undef THUMB_VARIANT | |
15649 | #define THUMB_VARIANT &fpu_vfp_ext_v3 | |
15650 | #undef ARM_VARIANT | |
15651 | #define ARM_VARIANT &fpu_vfp_ext_v3 | |
5287ad62 JB |
15652 | cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const), |
15653 | cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const), | |
15654 | cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15655 | cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15656 | cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15657 | cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
15658 | cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15659 | cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15660 | cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15661 | cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
15662 | cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15663 | cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15664 | cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15665 | cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
15666 | cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15667 | cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15668 | cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15669 | cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
c19d1205 | 15670 | |
5287ad62 | 15671 | #undef THUMB_VARIANT |
c19d1205 | 15672 | #undef ARM_VARIANT |
e74cfd16 | 15673 | #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */ |
8f06b2d8 PB |
15674 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
15675 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15676 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15677 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15678 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15679 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15680 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
15681 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 ZW |
15682 | |
15683 | #undef ARM_VARIANT | |
e74cfd16 | 15684 | #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */ |
8f06b2d8 PB |
15685 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
15686 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
15687 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
15688 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
15689 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
15690 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
15691 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
15692 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
15693 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
15694 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15695 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15696 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15697 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15698 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15699 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15700 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
15701 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
15702 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
15703 | cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd), | |
15704 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
15705 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15706 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15707 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15708 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15709 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15710 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15711 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
15712 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
15713 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
15714 | cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn), | |
15715 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
15716 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
15717 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
15718 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
15719 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
15720 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
15721 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
15722 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15723 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15724 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15725 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15726 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15727 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15728 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15729 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15730 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15731 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
15732 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15733 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15734 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15735 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15736 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15737 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15738 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15739 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15740 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15741 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15742 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15743 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15744 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15745 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15746 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15747 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15748 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15749 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15750 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15751 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
15752 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
15753 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
15754 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
15755 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15756 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15757 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15758 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15759 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15760 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15761 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15762 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15763 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15764 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15765 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15766 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15767 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15768 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15769 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15770 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15771 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15772 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15773 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
15774 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15775 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15776 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15777 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15778 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15779 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15780 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15781 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15782 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15783 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15784 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15785 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15786 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15787 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15788 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15789 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15790 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15791 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15792 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15793 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15794 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15795 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
15796 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15797 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15798 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15799 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15800 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15801 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15802 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15803 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15804 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15805 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15806 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15807 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15808 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15809 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15810 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15811 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15812 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15813 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
15814 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
15815 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
15816 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
15817 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
15818 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15819 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15820 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15821 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15822 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15823 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15824 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15825 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15826 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15827 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
15828 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
15829 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
15830 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
15831 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
15832 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
15833 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15834 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15835 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15836 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
15837 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
15838 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
15839 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
15840 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
15841 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
15842 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15843 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15844 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15845 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15846 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 ZW |
15847 | |
15848 | #undef ARM_VARIANT | |
e74cfd16 | 15849 | #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */ |
4962c51a MS |
15850 | cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
15851 | cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
15852 | cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
15853 | cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
15854 | cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
15855 | cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
15856 | cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
15857 | cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
8f06b2d8 PB |
15858 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), |
15859 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
15860 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
15861 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
15862 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
15863 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
15864 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
15865 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
15866 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
15867 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
15868 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
15869 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
15870 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
15871 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
15872 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
15873 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
15874 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
15875 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
15876 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
15877 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
15878 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
15879 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
15880 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
15881 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
15882 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
15883 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
15884 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
15885 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
15886 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
15887 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
15888 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
15889 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
15890 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
15891 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
15892 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
15893 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
15894 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
15895 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
15896 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
15897 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
15898 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
15899 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
15900 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
15901 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
15902 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
15903 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
15904 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
15905 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
15906 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
15907 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
15908 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
15909 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
15910 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
15911 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
15912 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
15913 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
15914 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
15915 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
15916 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
15917 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
15918 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
15919 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
15920 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
15921 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
15922 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
15923 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
15924 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
15925 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
15926 | }; |
15927 | #undef ARM_VARIANT | |
15928 | #undef THUMB_VARIANT | |
15929 | #undef TCE | |
15930 | #undef TCM | |
15931 | #undef TUE | |
15932 | #undef TUF | |
15933 | #undef TCC | |
8f06b2d8 | 15934 | #undef cCE |
e3cb604e PB |
15935 | #undef cCL |
15936 | #undef C3E | |
c19d1205 ZW |
15937 | #undef CE |
15938 | #undef CM | |
15939 | #undef UE | |
15940 | #undef UF | |
15941 | #undef UT | |
5287ad62 JB |
15942 | #undef NUF |
15943 | #undef nUF | |
15944 | #undef NCE | |
15945 | #undef nCE | |
c19d1205 ZW |
15946 | #undef OPS0 |
15947 | #undef OPS1 | |
15948 | #undef OPS2 | |
15949 | #undef OPS3 | |
15950 | #undef OPS4 | |
15951 | #undef OPS5 | |
15952 | #undef OPS6 | |
15953 | #undef do_0 | |
15954 | \f | |
15955 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 15956 | |
c19d1205 ZW |
15957 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
15958 | for use in the a.out file, and stores them in the array pointed to by buf. | |
15959 | This knows about the endian-ness of the target machine and does | |
15960 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
15961 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
15962 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 15963 | |
c19d1205 ZW |
15964 | void |
15965 | md_number_to_chars (char * buf, valueT val, int n) | |
15966 | { | |
15967 | if (target_big_endian) | |
15968 | number_to_chars_bigendian (buf, val, n); | |
15969 | else | |
15970 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
15971 | } |
15972 | ||
c19d1205 ZW |
15973 | static valueT |
15974 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 15975 | { |
c19d1205 ZW |
15976 | valueT result = 0; |
15977 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 15978 | |
c19d1205 | 15979 | if (target_big_endian) |
b99bd4ef | 15980 | { |
c19d1205 ZW |
15981 | while (n--) |
15982 | { | |
15983 | result <<= 8; | |
15984 | result |= (*where++ & 255); | |
15985 | } | |
b99bd4ef | 15986 | } |
c19d1205 | 15987 | else |
b99bd4ef | 15988 | { |
c19d1205 ZW |
15989 | while (n--) |
15990 | { | |
15991 | result <<= 8; | |
15992 | result |= (where[n] & 255); | |
15993 | } | |
bfae80f2 | 15994 | } |
b99bd4ef | 15995 | |
c19d1205 | 15996 | return result; |
bfae80f2 | 15997 | } |
b99bd4ef | 15998 | |
c19d1205 | 15999 | /* MD interface: Sections. */ |
b99bd4ef | 16000 | |
0110f2b8 PB |
16001 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
16002 | 2 bytes. */ | |
16003 | ||
c19d1205 | 16004 | int |
0110f2b8 | 16005 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
16006 | segT segtype ATTRIBUTE_UNUSED) |
16007 | { | |
0110f2b8 PB |
16008 | fragp->fr_var = 2; |
16009 | return 2; | |
16010 | } | |
16011 | ||
16012 | /* Convert a machine dependent frag. */ | |
16013 | ||
16014 | void | |
16015 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
16016 | { | |
16017 | unsigned long insn; | |
16018 | unsigned long old_op; | |
16019 | char *buf; | |
16020 | expressionS exp; | |
16021 | fixS *fixp; | |
16022 | int reloc_type; | |
16023 | int pc_rel; | |
16024 | int opcode; | |
16025 | ||
16026 | buf = fragp->fr_literal + fragp->fr_fix; | |
16027 | ||
16028 | old_op = bfd_get_16(abfd, buf); | |
16029 | if (fragp->fr_symbol) { | |
16030 | exp.X_op = O_symbol; | |
16031 | exp.X_add_symbol = fragp->fr_symbol; | |
16032 | } else { | |
16033 | exp.X_op = O_constant; | |
16034 | } | |
16035 | exp.X_add_number = fragp->fr_offset; | |
16036 | opcode = fragp->fr_subtype; | |
16037 | switch (opcode) | |
16038 | { | |
16039 | case T_MNEM_ldr_pc: | |
16040 | case T_MNEM_ldr_pc2: | |
16041 | case T_MNEM_ldr_sp: | |
16042 | case T_MNEM_str_sp: | |
16043 | case T_MNEM_ldr: | |
16044 | case T_MNEM_ldrb: | |
16045 | case T_MNEM_ldrh: | |
16046 | case T_MNEM_str: | |
16047 | case T_MNEM_strb: | |
16048 | case T_MNEM_strh: | |
16049 | if (fragp->fr_var == 4) | |
16050 | { | |
16051 | insn = THUMB_OP32(opcode); | |
16052 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) | |
16053 | { | |
16054 | insn |= (old_op & 0x700) << 4; | |
16055 | } | |
16056 | else | |
16057 | { | |
16058 | insn |= (old_op & 7) << 12; | |
16059 | insn |= (old_op & 0x38) << 13; | |
16060 | } | |
16061 | insn |= 0x00000c00; | |
16062 | put_thumb32_insn (buf, insn); | |
16063 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
16064 | } | |
16065 | else | |
16066 | { | |
16067 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
16068 | } | |
16069 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
16070 | break; | |
16071 | case T_MNEM_adr: | |
16072 | if (fragp->fr_var == 4) | |
16073 | { | |
16074 | insn = THUMB_OP32 (opcode); | |
16075 | insn |= (old_op & 0xf0) << 4; | |
16076 | put_thumb32_insn (buf, insn); | |
16077 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
16078 | } | |
16079 | else | |
16080 | { | |
16081 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
16082 | exp.X_add_number -= 4; | |
16083 | } | |
16084 | pc_rel = 1; | |
16085 | break; | |
16086 | case T_MNEM_mov: | |
16087 | case T_MNEM_movs: | |
16088 | case T_MNEM_cmp: | |
16089 | case T_MNEM_cmn: | |
16090 | if (fragp->fr_var == 4) | |
16091 | { | |
16092 | int r0off = (opcode == T_MNEM_mov | |
16093 | || opcode == T_MNEM_movs) ? 0 : 8; | |
16094 | insn = THUMB_OP32 (opcode); | |
16095 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
16096 | insn |= (old_op & 0x700) << r0off; | |
16097 | put_thumb32_insn (buf, insn); | |
16098 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
16099 | } | |
16100 | else | |
16101 | { | |
16102 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
16103 | } | |
16104 | pc_rel = 0; | |
16105 | break; | |
16106 | case T_MNEM_b: | |
16107 | if (fragp->fr_var == 4) | |
16108 | { | |
16109 | insn = THUMB_OP32(opcode); | |
16110 | put_thumb32_insn (buf, insn); | |
16111 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
16112 | } | |
16113 | else | |
16114 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
16115 | pc_rel = 1; | |
16116 | break; | |
16117 | case T_MNEM_bcond: | |
16118 | if (fragp->fr_var == 4) | |
16119 | { | |
16120 | insn = THUMB_OP32(opcode); | |
16121 | insn |= (old_op & 0xf00) << 14; | |
16122 | put_thumb32_insn (buf, insn); | |
16123 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
16124 | } | |
16125 | else | |
16126 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
16127 | pc_rel = 1; | |
16128 | break; | |
16129 | case T_MNEM_add_sp: | |
16130 | case T_MNEM_add_pc: | |
16131 | case T_MNEM_inc_sp: | |
16132 | case T_MNEM_dec_sp: | |
16133 | if (fragp->fr_var == 4) | |
16134 | { | |
16135 | /* ??? Choose between add and addw. */ | |
16136 | insn = THUMB_OP32 (opcode); | |
16137 | insn |= (old_op & 0xf0) << 4; | |
16138 | put_thumb32_insn (buf, insn); | |
16139 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
16140 | } | |
16141 | else | |
16142 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
16143 | pc_rel = 0; | |
16144 | break; | |
16145 | ||
16146 | case T_MNEM_addi: | |
16147 | case T_MNEM_addis: | |
16148 | case T_MNEM_subi: | |
16149 | case T_MNEM_subis: | |
16150 | if (fragp->fr_var == 4) | |
16151 | { | |
16152 | insn = THUMB_OP32 (opcode); | |
16153 | insn |= (old_op & 0xf0) << 4; | |
16154 | insn |= (old_op & 0xf) << 16; | |
16155 | put_thumb32_insn (buf, insn); | |
16156 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
16157 | } | |
16158 | else | |
16159 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
16160 | pc_rel = 0; | |
16161 | break; | |
16162 | default: | |
16163 | abort(); | |
16164 | } | |
16165 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
16166 | reloc_type); | |
16167 | fixp->fx_file = fragp->fr_file; | |
16168 | fixp->fx_line = fragp->fr_line; | |
16169 | fragp->fr_fix += fragp->fr_var; | |
16170 | } | |
16171 | ||
16172 | /* Return the size of a relaxable immediate operand instruction. | |
16173 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
16174 | static int | |
16175 | relax_immediate (fragS *fragp, int size, int shift) | |
16176 | { | |
16177 | offsetT offset; | |
16178 | offsetT mask; | |
16179 | offsetT low; | |
16180 | ||
16181 | /* ??? Should be able to do better than this. */ | |
16182 | if (fragp->fr_symbol) | |
16183 | return 4; | |
16184 | ||
16185 | low = (1 << shift) - 1; | |
16186 | mask = (1 << (shift + size)) - (1 << shift); | |
16187 | offset = fragp->fr_offset; | |
16188 | /* Force misaligned offsets to 32-bit variant. */ | |
16189 | if (offset & low) | |
16190 | return -4; | |
16191 | if (offset & ~mask) | |
16192 | return 4; | |
16193 | return 2; | |
16194 | } | |
16195 | ||
16196 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative | |
16197 | load. */ | |
16198 | static int | |
16199 | relax_adr (fragS *fragp, asection *sec) | |
16200 | { | |
16201 | addressT addr; | |
16202 | offsetT val; | |
16203 | ||
16204 | /* Assume worst case for symbols not known to be in the same section. */ | |
16205 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
16206 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
16207 | return 4; | |
16208 | ||
16209 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
16210 | addr = fragp->fr_address + fragp->fr_fix; | |
16211 | addr = (addr + 4) & ~3; | |
16212 | /* Fix the insn as the 4-byte version if the target address is not | |
16213 | sufficiently aligned. This is prevents an infinite loop when two | |
16214 | instructions have contradictory range/alignment requirements. */ | |
16215 | if (val & 3) | |
16216 | return -4; | |
16217 | val -= addr; | |
16218 | if (val < 0 || val > 1020) | |
16219 | return 4; | |
16220 | return 2; | |
16221 | } | |
16222 | ||
16223 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
16224 | static int | |
16225 | relax_addsub (fragS *fragp, asection *sec) | |
16226 | { | |
16227 | char *buf; | |
16228 | int op; | |
16229 | ||
16230 | buf = fragp->fr_literal + fragp->fr_fix; | |
16231 | op = bfd_get_16(sec->owner, buf); | |
16232 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
16233 | return relax_immediate (fragp, 8, 0); | |
16234 | else | |
16235 | return relax_immediate (fragp, 3, 0); | |
16236 | } | |
16237 | ||
16238 | ||
16239 | /* Return the size of a relaxable branch instruction. BITS is the | |
16240 | size of the offset field in the narrow instruction. */ | |
16241 | ||
16242 | static int | |
16243 | relax_branch (fragS *fragp, asection *sec, int bits) | |
16244 | { | |
16245 | addressT addr; | |
16246 | offsetT val; | |
16247 | offsetT limit; | |
16248 | ||
16249 | /* Assume worst case for symbols not known to be in the same section. */ | |
16250 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
16251 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
16252 | return 4; | |
16253 | ||
16254 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
16255 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
16256 | val -= addr; | |
16257 | ||
16258 | /* Offset is a signed value *2 */ | |
16259 | limit = 1 << bits; | |
16260 | if (val >= limit || val < -limit) | |
16261 | return 4; | |
16262 | return 2; | |
16263 | } | |
16264 | ||
16265 | ||
16266 | /* Relax a machine dependent frag. This returns the amount by which | |
16267 | the current size of the frag should change. */ | |
16268 | ||
16269 | int | |
16270 | arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED) | |
16271 | { | |
16272 | int oldsize; | |
16273 | int newsize; | |
16274 | ||
16275 | oldsize = fragp->fr_var; | |
16276 | switch (fragp->fr_subtype) | |
16277 | { | |
16278 | case T_MNEM_ldr_pc2: | |
16279 | newsize = relax_adr(fragp, sec); | |
16280 | break; | |
16281 | case T_MNEM_ldr_pc: | |
16282 | case T_MNEM_ldr_sp: | |
16283 | case T_MNEM_str_sp: | |
16284 | newsize = relax_immediate(fragp, 8, 2); | |
16285 | break; | |
16286 | case T_MNEM_ldr: | |
16287 | case T_MNEM_str: | |
16288 | newsize = relax_immediate(fragp, 5, 2); | |
16289 | break; | |
16290 | case T_MNEM_ldrh: | |
16291 | case T_MNEM_strh: | |
16292 | newsize = relax_immediate(fragp, 5, 1); | |
16293 | break; | |
16294 | case T_MNEM_ldrb: | |
16295 | case T_MNEM_strb: | |
16296 | newsize = relax_immediate(fragp, 5, 0); | |
16297 | break; | |
16298 | case T_MNEM_adr: | |
16299 | newsize = relax_adr(fragp, sec); | |
16300 | break; | |
16301 | case T_MNEM_mov: | |
16302 | case T_MNEM_movs: | |
16303 | case T_MNEM_cmp: | |
16304 | case T_MNEM_cmn: | |
16305 | newsize = relax_immediate(fragp, 8, 0); | |
16306 | break; | |
16307 | case T_MNEM_b: | |
16308 | newsize = relax_branch(fragp, sec, 11); | |
16309 | break; | |
16310 | case T_MNEM_bcond: | |
16311 | newsize = relax_branch(fragp, sec, 8); | |
16312 | break; | |
16313 | case T_MNEM_add_sp: | |
16314 | case T_MNEM_add_pc: | |
16315 | newsize = relax_immediate (fragp, 8, 2); | |
16316 | break; | |
16317 | case T_MNEM_inc_sp: | |
16318 | case T_MNEM_dec_sp: | |
16319 | newsize = relax_immediate (fragp, 7, 2); | |
16320 | break; | |
16321 | case T_MNEM_addi: | |
16322 | case T_MNEM_addis: | |
16323 | case T_MNEM_subi: | |
16324 | case T_MNEM_subis: | |
16325 | newsize = relax_addsub (fragp, sec); | |
16326 | break; | |
16327 | default: | |
16328 | abort(); | |
16329 | } | |
16330 | if (newsize < 0) | |
16331 | { | |
16332 | fragp->fr_var = -newsize; | |
16333 | md_convert_frag (sec->owner, sec, fragp); | |
16334 | frag_wane(fragp); | |
16335 | return -(newsize + oldsize); | |
16336 | } | |
16337 | fragp->fr_var = newsize; | |
16338 | return newsize - oldsize; | |
c19d1205 | 16339 | } |
b99bd4ef | 16340 | |
c19d1205 | 16341 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 16342 | |
c19d1205 ZW |
16343 | valueT |
16344 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
16345 | valueT size) | |
16346 | { | |
16347 | #ifdef OBJ_ELF | |
16348 | return size; | |
16349 | #else | |
16350 | /* Round all sects to multiple of 4. */ | |
16351 | return (size + 3) & ~3; | |
16352 | #endif | |
bfae80f2 | 16353 | } |
b99bd4ef | 16354 | |
c19d1205 ZW |
16355 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
16356 | of an rs_align_code fragment. */ | |
16357 | ||
16358 | void | |
16359 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 16360 | { |
c19d1205 ZW |
16361 | static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 }; |
16362 | static char const thumb_noop[2] = { 0xc0, 0x46 }; | |
16363 | static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 }; | |
16364 | static char const thumb_bigend_noop[2] = { 0x46, 0xc0 }; | |
16365 | ||
16366 | int bytes, fix, noop_size; | |
16367 | char * p; | |
16368 | const char * noop; | |
bfae80f2 | 16369 | |
c19d1205 | 16370 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
16371 | return; |
16372 | ||
c19d1205 ZW |
16373 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
16374 | p = fragP->fr_literal + fragP->fr_fix; | |
16375 | fix = 0; | |
bfae80f2 | 16376 | |
c19d1205 ZW |
16377 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
16378 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 16379 | |
c19d1205 | 16380 | if (fragP->tc_frag_data) |
a737bd4d | 16381 | { |
c19d1205 ZW |
16382 | if (target_big_endian) |
16383 | noop = thumb_bigend_noop; | |
16384 | else | |
16385 | noop = thumb_noop; | |
16386 | noop_size = sizeof (thumb_noop); | |
7ed4c4c5 NC |
16387 | } |
16388 | else | |
16389 | { | |
c19d1205 ZW |
16390 | if (target_big_endian) |
16391 | noop = arm_bigend_noop; | |
16392 | else | |
16393 | noop = arm_noop; | |
16394 | noop_size = sizeof (arm_noop); | |
7ed4c4c5 | 16395 | } |
a737bd4d | 16396 | |
c19d1205 | 16397 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 16398 | { |
c19d1205 ZW |
16399 | fix = bytes & (noop_size - 1); |
16400 | memset (p, 0, fix); | |
16401 | p += fix; | |
16402 | bytes -= fix; | |
a737bd4d | 16403 | } |
a737bd4d | 16404 | |
c19d1205 | 16405 | while (bytes >= noop_size) |
a737bd4d | 16406 | { |
c19d1205 ZW |
16407 | memcpy (p, noop, noop_size); |
16408 | p += noop_size; | |
16409 | bytes -= noop_size; | |
16410 | fix += noop_size; | |
a737bd4d NC |
16411 | } |
16412 | ||
c19d1205 ZW |
16413 | fragP->fr_fix += fix; |
16414 | fragP->fr_var = noop_size; | |
a737bd4d NC |
16415 | } |
16416 | ||
c19d1205 ZW |
16417 | /* Called from md_do_align. Used to create an alignment |
16418 | frag in a code section. */ | |
16419 | ||
16420 | void | |
16421 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 16422 | { |
c19d1205 | 16423 | char * p; |
7ed4c4c5 | 16424 | |
c19d1205 ZW |
16425 | /* We assume that there will never be a requirement |
16426 | to support alignments greater than 32 bytes. */ | |
16427 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) | |
16428 | as_fatal (_("alignments greater than 32 bytes not supported in .text sections.")); | |
bfae80f2 | 16429 | |
c19d1205 ZW |
16430 | p = frag_var (rs_align_code, |
16431 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
16432 | 1, | |
16433 | (relax_substateT) max, | |
16434 | (symbolS *) NULL, | |
16435 | (offsetT) n, | |
16436 | (char *) NULL); | |
16437 | *p = 0; | |
16438 | } | |
bfae80f2 | 16439 | |
c19d1205 | 16440 | /* Perform target specific initialisation of a frag. */ |
bfae80f2 | 16441 | |
c19d1205 ZW |
16442 | void |
16443 | arm_init_frag (fragS * fragP) | |
16444 | { | |
16445 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
16446 | fragP->tc_frag_data = thumb_mode; | |
bfae80f2 RE |
16447 | } |
16448 | ||
c19d1205 ZW |
16449 | #ifdef OBJ_ELF |
16450 | /* When we change sections we need to issue a new mapping symbol. */ | |
16451 | ||
16452 | void | |
16453 | arm_elf_change_section (void) | |
bfae80f2 | 16454 | { |
c19d1205 ZW |
16455 | flagword flags; |
16456 | segment_info_type *seginfo; | |
bfae80f2 | 16457 | |
c19d1205 ZW |
16458 | /* Link an unlinked unwind index table section to the .text section. */ |
16459 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
16460 | && elf_linked_to_section (now_seg) == NULL) | |
16461 | elf_linked_to_section (now_seg) = text_section; | |
16462 | ||
16463 | if (!SEG_NORMAL (now_seg)) | |
bfae80f2 RE |
16464 | return; |
16465 | ||
c19d1205 ZW |
16466 | flags = bfd_get_section_flags (stdoutput, now_seg); |
16467 | ||
16468 | /* We can ignore sections that only contain debug info. */ | |
16469 | if ((flags & SEC_ALLOC) == 0) | |
16470 | return; | |
bfae80f2 | 16471 | |
c19d1205 ZW |
16472 | seginfo = seg_info (now_seg); |
16473 | mapstate = seginfo->tc_segment_info_data.mapstate; | |
16474 | marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency; | |
bfae80f2 RE |
16475 | } |
16476 | ||
c19d1205 ZW |
16477 | int |
16478 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 16479 | { |
c19d1205 ZW |
16480 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
16481 | return SHT_ARM_EXIDX; | |
e45d0630 | 16482 | |
c19d1205 ZW |
16483 | return -1; |
16484 | } | |
16485 | \f | |
16486 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 16487 | |
c19d1205 | 16488 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 16489 | |
c19d1205 | 16490 | /* Cenerate and deferred unwind frame offset. */ |
e45d0630 | 16491 | |
bfae80f2 | 16492 | static void |
c19d1205 | 16493 | flush_pending_unwind (void) |
bfae80f2 | 16494 | { |
c19d1205 | 16495 | offsetT offset; |
bfae80f2 | 16496 | |
c19d1205 ZW |
16497 | offset = unwind.pending_offset; |
16498 | unwind.pending_offset = 0; | |
16499 | if (offset != 0) | |
16500 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
16501 | } |
16502 | ||
c19d1205 ZW |
16503 | /* Add an opcode to this list for this function. Two-byte opcodes should |
16504 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
16505 | order. */ | |
16506 | ||
bfae80f2 | 16507 | static void |
c19d1205 | 16508 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 16509 | { |
c19d1205 ZW |
16510 | /* Add any deferred stack adjustment. */ |
16511 | if (unwind.pending_offset) | |
16512 | flush_pending_unwind (); | |
bfae80f2 | 16513 | |
c19d1205 | 16514 | unwind.sp_restored = 0; |
bfae80f2 | 16515 | |
c19d1205 | 16516 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 16517 | { |
c19d1205 ZW |
16518 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
16519 | if (unwind.opcodes) | |
16520 | unwind.opcodes = xrealloc (unwind.opcodes, | |
16521 | unwind.opcode_alloc); | |
16522 | else | |
16523 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 16524 | } |
c19d1205 | 16525 | while (length > 0) |
bfae80f2 | 16526 | { |
c19d1205 ZW |
16527 | length--; |
16528 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
16529 | op >>= 8; | |
16530 | unwind.opcode_count++; | |
bfae80f2 | 16531 | } |
bfae80f2 RE |
16532 | } |
16533 | ||
c19d1205 ZW |
16534 | /* Add unwind opcodes to adjust the stack pointer. */ |
16535 | ||
bfae80f2 | 16536 | static void |
c19d1205 | 16537 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 16538 | { |
c19d1205 | 16539 | valueT op; |
bfae80f2 | 16540 | |
c19d1205 | 16541 | if (offset > 0x200) |
bfae80f2 | 16542 | { |
c19d1205 ZW |
16543 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
16544 | char bytes[5]; | |
16545 | int n; | |
16546 | valueT o; | |
bfae80f2 | 16547 | |
c19d1205 ZW |
16548 | /* Long form: 0xb2, uleb128. */ |
16549 | /* This might not fit in a word so add the individual bytes, | |
16550 | remembering the list is built in reverse order. */ | |
16551 | o = (valueT) ((offset - 0x204) >> 2); | |
16552 | if (o == 0) | |
16553 | add_unwind_opcode (0, 1); | |
bfae80f2 | 16554 | |
c19d1205 ZW |
16555 | /* Calculate the uleb128 encoding of the offset. */ |
16556 | n = 0; | |
16557 | while (o) | |
16558 | { | |
16559 | bytes[n] = o & 0x7f; | |
16560 | o >>= 7; | |
16561 | if (o) | |
16562 | bytes[n] |= 0x80; | |
16563 | n++; | |
16564 | } | |
16565 | /* Add the insn. */ | |
16566 | for (; n; n--) | |
16567 | add_unwind_opcode (bytes[n - 1], 1); | |
16568 | add_unwind_opcode (0xb2, 1); | |
16569 | } | |
16570 | else if (offset > 0x100) | |
bfae80f2 | 16571 | { |
c19d1205 ZW |
16572 | /* Two short opcodes. */ |
16573 | add_unwind_opcode (0x3f, 1); | |
16574 | op = (offset - 0x104) >> 2; | |
16575 | add_unwind_opcode (op, 1); | |
bfae80f2 | 16576 | } |
c19d1205 ZW |
16577 | else if (offset > 0) |
16578 | { | |
16579 | /* Short opcode. */ | |
16580 | op = (offset - 4) >> 2; | |
16581 | add_unwind_opcode (op, 1); | |
16582 | } | |
16583 | else if (offset < 0) | |
bfae80f2 | 16584 | { |
c19d1205 ZW |
16585 | offset = -offset; |
16586 | while (offset > 0x100) | |
bfae80f2 | 16587 | { |
c19d1205 ZW |
16588 | add_unwind_opcode (0x7f, 1); |
16589 | offset -= 0x100; | |
bfae80f2 | 16590 | } |
c19d1205 ZW |
16591 | op = ((offset - 4) >> 2) | 0x40; |
16592 | add_unwind_opcode (op, 1); | |
bfae80f2 | 16593 | } |
bfae80f2 RE |
16594 | } |
16595 | ||
c19d1205 ZW |
16596 | /* Finish the list of unwind opcodes for this function. */ |
16597 | static void | |
16598 | finish_unwind_opcodes (void) | |
bfae80f2 | 16599 | { |
c19d1205 | 16600 | valueT op; |
bfae80f2 | 16601 | |
c19d1205 | 16602 | if (unwind.fp_used) |
bfae80f2 | 16603 | { |
708587a4 | 16604 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
16605 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
16606 | flush_pending_unwind (); | |
bfae80f2 | 16607 | |
c19d1205 ZW |
16608 | /* After restoring sp from the frame pointer. */ |
16609 | op = 0x90 | unwind.fp_reg; | |
16610 | add_unwind_opcode (op, 1); | |
16611 | } | |
16612 | else | |
16613 | flush_pending_unwind (); | |
bfae80f2 RE |
16614 | } |
16615 | ||
bfae80f2 | 16616 | |
c19d1205 ZW |
16617 | /* Start an exception table entry. If idx is nonzero this is an index table |
16618 | entry. */ | |
bfae80f2 RE |
16619 | |
16620 | static void | |
c19d1205 | 16621 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 16622 | { |
c19d1205 ZW |
16623 | const char * text_name; |
16624 | const char * prefix; | |
16625 | const char * prefix_once; | |
16626 | const char * group_name; | |
16627 | size_t prefix_len; | |
16628 | size_t text_len; | |
16629 | char * sec_name; | |
16630 | size_t sec_name_len; | |
16631 | int type; | |
16632 | int flags; | |
16633 | int linkonce; | |
bfae80f2 | 16634 | |
c19d1205 | 16635 | if (idx) |
bfae80f2 | 16636 | { |
c19d1205 ZW |
16637 | prefix = ELF_STRING_ARM_unwind; |
16638 | prefix_once = ELF_STRING_ARM_unwind_once; | |
16639 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 16640 | } |
c19d1205 | 16641 | else |
bfae80f2 | 16642 | { |
c19d1205 ZW |
16643 | prefix = ELF_STRING_ARM_unwind_info; |
16644 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
16645 | type = SHT_PROGBITS; | |
bfae80f2 RE |
16646 | } |
16647 | ||
c19d1205 ZW |
16648 | text_name = segment_name (text_seg); |
16649 | if (streq (text_name, ".text")) | |
16650 | text_name = ""; | |
16651 | ||
16652 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
16653 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 16654 | { |
c19d1205 ZW |
16655 | prefix = prefix_once; |
16656 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
16657 | } |
16658 | ||
c19d1205 ZW |
16659 | prefix_len = strlen (prefix); |
16660 | text_len = strlen (text_name); | |
16661 | sec_name_len = prefix_len + text_len; | |
16662 | sec_name = xmalloc (sec_name_len + 1); | |
16663 | memcpy (sec_name, prefix, prefix_len); | |
16664 | memcpy (sec_name + prefix_len, text_name, text_len); | |
16665 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 16666 | |
c19d1205 ZW |
16667 | flags = SHF_ALLOC; |
16668 | linkonce = 0; | |
16669 | group_name = 0; | |
bfae80f2 | 16670 | |
c19d1205 ZW |
16671 | /* Handle COMDAT group. */ |
16672 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 16673 | { |
c19d1205 ZW |
16674 | group_name = elf_group_name (text_seg); |
16675 | if (group_name == NULL) | |
16676 | { | |
16677 | as_bad ("Group section `%s' has no group signature", | |
16678 | segment_name (text_seg)); | |
16679 | ignore_rest_of_line (); | |
16680 | return; | |
16681 | } | |
16682 | flags |= SHF_GROUP; | |
16683 | linkonce = 1; | |
bfae80f2 RE |
16684 | } |
16685 | ||
c19d1205 | 16686 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 16687 | |
c19d1205 ZW |
16688 | /* Set the setion link for index tables. */ |
16689 | if (idx) | |
16690 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
16691 | } |
16692 | ||
bfae80f2 | 16693 | |
c19d1205 ZW |
16694 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
16695 | personality routine data. Returns zero, or the index table value for | |
16696 | and inline entry. */ | |
16697 | ||
16698 | static valueT | |
16699 | create_unwind_entry (int have_data) | |
bfae80f2 | 16700 | { |
c19d1205 ZW |
16701 | int size; |
16702 | addressT where; | |
16703 | char *ptr; | |
16704 | /* The current word of data. */ | |
16705 | valueT data; | |
16706 | /* The number of bytes left in this word. */ | |
16707 | int n; | |
bfae80f2 | 16708 | |
c19d1205 | 16709 | finish_unwind_opcodes (); |
bfae80f2 | 16710 | |
c19d1205 ZW |
16711 | /* Remember the current text section. */ |
16712 | unwind.saved_seg = now_seg; | |
16713 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 16714 | |
c19d1205 | 16715 | start_unwind_section (now_seg, 0); |
bfae80f2 | 16716 | |
c19d1205 | 16717 | if (unwind.personality_routine == NULL) |
bfae80f2 | 16718 | { |
c19d1205 ZW |
16719 | if (unwind.personality_index == -2) |
16720 | { | |
16721 | if (have_data) | |
16722 | as_bad (_("handerdata in cantunwind frame")); | |
16723 | return 1; /* EXIDX_CANTUNWIND. */ | |
16724 | } | |
bfae80f2 | 16725 | |
c19d1205 ZW |
16726 | /* Use a default personality routine if none is specified. */ |
16727 | if (unwind.personality_index == -1) | |
16728 | { | |
16729 | if (unwind.opcode_count > 3) | |
16730 | unwind.personality_index = 1; | |
16731 | else | |
16732 | unwind.personality_index = 0; | |
16733 | } | |
bfae80f2 | 16734 | |
c19d1205 ZW |
16735 | /* Space for the personality routine entry. */ |
16736 | if (unwind.personality_index == 0) | |
16737 | { | |
16738 | if (unwind.opcode_count > 3) | |
16739 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 16740 | |
c19d1205 ZW |
16741 | if (!have_data) |
16742 | { | |
16743 | /* All the data is inline in the index table. */ | |
16744 | data = 0x80; | |
16745 | n = 3; | |
16746 | while (unwind.opcode_count > 0) | |
16747 | { | |
16748 | unwind.opcode_count--; | |
16749 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
16750 | n--; | |
16751 | } | |
bfae80f2 | 16752 | |
c19d1205 ZW |
16753 | /* Pad with "finish" opcodes. */ |
16754 | while (n--) | |
16755 | data = (data << 8) | 0xb0; | |
bfae80f2 | 16756 | |
c19d1205 ZW |
16757 | return data; |
16758 | } | |
16759 | size = 0; | |
16760 | } | |
16761 | else | |
16762 | /* We get two opcodes "free" in the first word. */ | |
16763 | size = unwind.opcode_count - 2; | |
16764 | } | |
16765 | else | |
16766 | /* An extra byte is required for the opcode count. */ | |
16767 | size = unwind.opcode_count + 1; | |
bfae80f2 | 16768 | |
c19d1205 ZW |
16769 | size = (size + 3) >> 2; |
16770 | if (size > 0xff) | |
16771 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 16772 | |
c19d1205 ZW |
16773 | frag_align (2, 0, 0); |
16774 | record_alignment (now_seg, 2); | |
16775 | unwind.table_entry = expr_build_dot (); | |
16776 | ||
16777 | /* Allocate the table entry. */ | |
16778 | ptr = frag_more ((size << 2) + 4); | |
16779 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 16780 | |
c19d1205 | 16781 | switch (unwind.personality_index) |
bfae80f2 | 16782 | { |
c19d1205 ZW |
16783 | case -1: |
16784 | /* ??? Should this be a PLT generating relocation? */ | |
16785 | /* Custom personality routine. */ | |
16786 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
16787 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 16788 | |
c19d1205 ZW |
16789 | where += 4; |
16790 | ptr += 4; | |
bfae80f2 | 16791 | |
c19d1205 ZW |
16792 | /* Set the first byte to the number of additional words. */ |
16793 | data = size - 1; | |
16794 | n = 3; | |
16795 | break; | |
bfae80f2 | 16796 | |
c19d1205 ZW |
16797 | /* ABI defined personality routines. */ |
16798 | case 0: | |
16799 | /* Three opcodes bytes are packed into the first word. */ | |
16800 | data = 0x80; | |
16801 | n = 3; | |
16802 | break; | |
bfae80f2 | 16803 | |
c19d1205 ZW |
16804 | case 1: |
16805 | case 2: | |
16806 | /* The size and first two opcode bytes go in the first word. */ | |
16807 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
16808 | n = 2; | |
16809 | break; | |
bfae80f2 | 16810 | |
c19d1205 ZW |
16811 | default: |
16812 | /* Should never happen. */ | |
16813 | abort (); | |
16814 | } | |
bfae80f2 | 16815 | |
c19d1205 ZW |
16816 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
16817 | time. */ | |
16818 | while (unwind.opcode_count > 0) | |
16819 | { | |
16820 | if (n == 0) | |
16821 | { | |
16822 | md_number_to_chars (ptr, data, 4); | |
16823 | ptr += 4; | |
16824 | n = 4; | |
16825 | data = 0; | |
16826 | } | |
16827 | unwind.opcode_count--; | |
16828 | n--; | |
16829 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
16830 | } | |
16831 | ||
16832 | /* Finish off the last word. */ | |
16833 | if (n < 4) | |
16834 | { | |
16835 | /* Pad with "finish" opcodes. */ | |
16836 | while (n--) | |
16837 | data = (data << 8) | 0xb0; | |
16838 | ||
16839 | md_number_to_chars (ptr, data, 4); | |
16840 | } | |
16841 | ||
16842 | if (!have_data) | |
16843 | { | |
16844 | /* Add an empty descriptor if there is no user-specified data. */ | |
16845 | ptr = frag_more (4); | |
16846 | md_number_to_chars (ptr, 0, 4); | |
16847 | } | |
16848 | ||
16849 | return 0; | |
bfae80f2 RE |
16850 | } |
16851 | ||
c19d1205 ZW |
16852 | /* Convert REGNAME to a DWARF-2 register number. */ |
16853 | ||
16854 | int | |
1df69f4f | 16855 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 16856 | { |
1df69f4f | 16857 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
16858 | |
16859 | if (reg == FAIL) | |
16860 | return -1; | |
16861 | ||
16862 | return reg; | |
bfae80f2 RE |
16863 | } |
16864 | ||
c19d1205 ZW |
16865 | /* Initialize the DWARF-2 unwind information for this procedure. */ |
16866 | ||
16867 | void | |
16868 | tc_arm_frame_initial_instructions (void) | |
bfae80f2 | 16869 | { |
c19d1205 | 16870 | cfi_add_CFA_def_cfa (REG_SP, 0); |
bfae80f2 | 16871 | } |
c19d1205 | 16872 | #endif /* OBJ_ELF */ |
bfae80f2 | 16873 | |
bfae80f2 | 16874 | |
c19d1205 | 16875 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 16876 | |
2fc8bdac ZW |
16877 | /* Return the address within the segment that a PC-relative fixup is |
16878 | relative to. For ARM, PC-relative fixups applied to instructions | |
16879 | are generally relative to the location of the fixup plus 8 bytes. | |
16880 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
16881 | require special handling. */ | |
bfae80f2 | 16882 | |
c19d1205 | 16883 | long |
2fc8bdac | 16884 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 16885 | { |
2fc8bdac ZW |
16886 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
16887 | ||
16888 | /* If this is pc-relative and we are going to emit a relocation | |
16889 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
16890 | will need. Otherwise we want to use the calculated base. |
16891 | For WinCE we skip the bias for externals as well, since this | |
16892 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
2fc8bdac ZW |
16893 | if (fixP->fx_pcrel |
16894 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
53baae48 NC |
16895 | || (arm_force_relocation (fixP) |
16896 | #ifdef TE_WINCE | |
16897 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
16898 | #endif | |
16899 | ))) | |
2fc8bdac | 16900 | base = 0; |
bfae80f2 | 16901 | |
c19d1205 | 16902 | switch (fixP->fx_r_type) |
bfae80f2 | 16903 | { |
2fc8bdac ZW |
16904 | /* PC relative addressing on the Thumb is slightly odd as the |
16905 | bottom two bits of the PC are forced to zero for the | |
16906 | calculation. This happens *after* application of the | |
16907 | pipeline offset. However, Thumb adrl already adjusts for | |
16908 | this, so we need not do it again. */ | |
c19d1205 | 16909 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 16910 | return base & ~3; |
c19d1205 ZW |
16911 | |
16912 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
16913 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 16914 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 16915 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 16916 | return (base + 4) & ~3; |
c19d1205 | 16917 | |
2fc8bdac ZW |
16918 | /* Thumb branches are simply offset by +4. */ |
16919 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
16920 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
16921 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
16922 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
16923 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
16924 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
16925 | case BFD_RELOC_THUMB_PCREL_BLX: | |
16926 | return base + 4; | |
bfae80f2 | 16927 | |
2fc8bdac ZW |
16928 | /* ARM mode branches are offset by +8. However, the Windows CE |
16929 | loader expects the relocation not to take this into account. */ | |
16930 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
39b41c9c PB |
16931 | case BFD_RELOC_ARM_PCREL_CALL: |
16932 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac ZW |
16933 | case BFD_RELOC_ARM_PCREL_BLX: |
16934 | case BFD_RELOC_ARM_PLT32: | |
c19d1205 | 16935 | #ifdef TE_WINCE |
53baae48 NC |
16936 | /* When handling fixups immediately, because we have already |
16937 | discovered the value of a symbol, or the address of the frag involved | |
16938 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
16939 | see fixup_segment() in write.c | |
16940 | The S_IS_EXTERNAL test handles the case of global symbols. | |
16941 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
16942 | if (fixP->fx_pcrel | |
16943 | && fixP->fx_addsy != NULL | |
16944 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
16945 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
16946 | return base + 8; | |
2fc8bdac | 16947 | return base; |
c19d1205 | 16948 | #else |
2fc8bdac | 16949 | return base + 8; |
c19d1205 | 16950 | #endif |
2fc8bdac ZW |
16951 | |
16952 | /* ARM mode loads relative to PC are also offset by +8. Unlike | |
16953 | branches, the Windows CE loader *does* expect the relocation | |
16954 | to take this into account. */ | |
16955 | case BFD_RELOC_ARM_OFFSET_IMM: | |
16956 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
16957 | case BFD_RELOC_ARM_HWLITERAL: | |
16958 | case BFD_RELOC_ARM_LITERAL: | |
16959 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
16960 | return base + 8; | |
16961 | ||
16962 | ||
16963 | /* Other PC-relative relocations are un-offset. */ | |
16964 | default: | |
16965 | return base; | |
16966 | } | |
bfae80f2 RE |
16967 | } |
16968 | ||
c19d1205 ZW |
16969 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
16970 | Otherwise we have no need to default values of symbols. */ | |
16971 | ||
16972 | symbolS * | |
16973 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 16974 | { |
c19d1205 ZW |
16975 | #ifdef OBJ_ELF |
16976 | if (name[0] == '_' && name[1] == 'G' | |
16977 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
16978 | { | |
16979 | if (!GOT_symbol) | |
16980 | { | |
16981 | if (symbol_find (name)) | |
16982 | as_bad ("GOT already in the symbol table"); | |
bfae80f2 | 16983 | |
c19d1205 ZW |
16984 | GOT_symbol = symbol_new (name, undefined_section, |
16985 | (valueT) 0, & zero_address_frag); | |
16986 | } | |
bfae80f2 | 16987 | |
c19d1205 | 16988 | return GOT_symbol; |
bfae80f2 | 16989 | } |
c19d1205 | 16990 | #endif |
bfae80f2 | 16991 | |
c19d1205 | 16992 | return 0; |
bfae80f2 RE |
16993 | } |
16994 | ||
55cf6793 | 16995 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
16996 | computed as two separate immediate values, added together. We |
16997 | already know that this value cannot be computed by just one ARM | |
16998 | instruction. */ | |
16999 | ||
17000 | static unsigned int | |
17001 | validate_immediate_twopart (unsigned int val, | |
17002 | unsigned int * highpart) | |
bfae80f2 | 17003 | { |
c19d1205 ZW |
17004 | unsigned int a; |
17005 | unsigned int i; | |
bfae80f2 | 17006 | |
c19d1205 ZW |
17007 | for (i = 0; i < 32; i += 2) |
17008 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
17009 | { | |
17010 | if (a & 0xff00) | |
17011 | { | |
17012 | if (a & ~ 0xffff) | |
17013 | continue; | |
17014 | * highpart = (a >> 8) | ((i + 24) << 7); | |
17015 | } | |
17016 | else if (a & 0xff0000) | |
17017 | { | |
17018 | if (a & 0xff000000) | |
17019 | continue; | |
17020 | * highpart = (a >> 16) | ((i + 16) << 7); | |
17021 | } | |
17022 | else | |
17023 | { | |
17024 | assert (a & 0xff000000); | |
17025 | * highpart = (a >> 24) | ((i + 8) << 7); | |
17026 | } | |
bfae80f2 | 17027 | |
c19d1205 ZW |
17028 | return (a & 0xff) | (i << 7); |
17029 | } | |
bfae80f2 | 17030 | |
c19d1205 | 17031 | return FAIL; |
bfae80f2 RE |
17032 | } |
17033 | ||
c19d1205 ZW |
17034 | static int |
17035 | validate_offset_imm (unsigned int val, int hwse) | |
17036 | { | |
17037 | if ((hwse && val > 255) || val > 4095) | |
17038 | return FAIL; | |
17039 | return val; | |
17040 | } | |
bfae80f2 | 17041 | |
55cf6793 | 17042 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
17043 | negative immediate constant by altering the instruction. A bit of |
17044 | a hack really. | |
17045 | MOV <-> MVN | |
17046 | AND <-> BIC | |
17047 | ADC <-> SBC | |
17048 | by inverting the second operand, and | |
17049 | ADD <-> SUB | |
17050 | CMP <-> CMN | |
17051 | by negating the second operand. */ | |
bfae80f2 | 17052 | |
c19d1205 ZW |
17053 | static int |
17054 | negate_data_op (unsigned long * instruction, | |
17055 | unsigned long value) | |
bfae80f2 | 17056 | { |
c19d1205 ZW |
17057 | int op, new_inst; |
17058 | unsigned long negated, inverted; | |
bfae80f2 | 17059 | |
c19d1205 ZW |
17060 | negated = encode_arm_immediate (-value); |
17061 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 17062 | |
c19d1205 ZW |
17063 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
17064 | switch (op) | |
bfae80f2 | 17065 | { |
c19d1205 ZW |
17066 | /* First negates. */ |
17067 | case OPCODE_SUB: /* ADD <-> SUB */ | |
17068 | new_inst = OPCODE_ADD; | |
17069 | value = negated; | |
17070 | break; | |
bfae80f2 | 17071 | |
c19d1205 ZW |
17072 | case OPCODE_ADD: |
17073 | new_inst = OPCODE_SUB; | |
17074 | value = negated; | |
17075 | break; | |
bfae80f2 | 17076 | |
c19d1205 ZW |
17077 | case OPCODE_CMP: /* CMP <-> CMN */ |
17078 | new_inst = OPCODE_CMN; | |
17079 | value = negated; | |
17080 | break; | |
bfae80f2 | 17081 | |
c19d1205 ZW |
17082 | case OPCODE_CMN: |
17083 | new_inst = OPCODE_CMP; | |
17084 | value = negated; | |
17085 | break; | |
bfae80f2 | 17086 | |
c19d1205 ZW |
17087 | /* Now Inverted ops. */ |
17088 | case OPCODE_MOV: /* MOV <-> MVN */ | |
17089 | new_inst = OPCODE_MVN; | |
17090 | value = inverted; | |
17091 | break; | |
bfae80f2 | 17092 | |
c19d1205 ZW |
17093 | case OPCODE_MVN: |
17094 | new_inst = OPCODE_MOV; | |
17095 | value = inverted; | |
17096 | break; | |
bfae80f2 | 17097 | |
c19d1205 ZW |
17098 | case OPCODE_AND: /* AND <-> BIC */ |
17099 | new_inst = OPCODE_BIC; | |
17100 | value = inverted; | |
17101 | break; | |
bfae80f2 | 17102 | |
c19d1205 ZW |
17103 | case OPCODE_BIC: |
17104 | new_inst = OPCODE_AND; | |
17105 | value = inverted; | |
17106 | break; | |
bfae80f2 | 17107 | |
c19d1205 ZW |
17108 | case OPCODE_ADC: /* ADC <-> SBC */ |
17109 | new_inst = OPCODE_SBC; | |
17110 | value = inverted; | |
17111 | break; | |
bfae80f2 | 17112 | |
c19d1205 ZW |
17113 | case OPCODE_SBC: |
17114 | new_inst = OPCODE_ADC; | |
17115 | value = inverted; | |
17116 | break; | |
bfae80f2 | 17117 | |
c19d1205 ZW |
17118 | /* We cannot do anything. */ |
17119 | default: | |
17120 | return FAIL; | |
b99bd4ef NC |
17121 | } |
17122 | ||
c19d1205 ZW |
17123 | if (value == (unsigned) FAIL) |
17124 | return FAIL; | |
17125 | ||
17126 | *instruction &= OPCODE_MASK; | |
17127 | *instruction |= new_inst << DATA_OP_SHIFT; | |
17128 | return value; | |
b99bd4ef NC |
17129 | } |
17130 | ||
ef8d22e6 PB |
17131 | /* Like negate_data_op, but for Thumb-2. */ |
17132 | ||
17133 | static unsigned int | |
17134 | thumb32_negate_data_op (offsetT *instruction, offsetT value) | |
17135 | { | |
17136 | int op, new_inst; | |
17137 | int rd; | |
17138 | offsetT negated, inverted; | |
17139 | ||
17140 | negated = encode_thumb32_immediate (-value); | |
17141 | inverted = encode_thumb32_immediate (~value); | |
17142 | ||
17143 | rd = (*instruction >> 8) & 0xf; | |
17144 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
17145 | switch (op) | |
17146 | { | |
17147 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
17148 | case T2_OPCODE_SUB: | |
17149 | new_inst = T2_OPCODE_ADD; | |
17150 | value = negated; | |
17151 | break; | |
17152 | ||
17153 | case T2_OPCODE_ADD: | |
17154 | new_inst = T2_OPCODE_SUB; | |
17155 | value = negated; | |
17156 | break; | |
17157 | ||
17158 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
17159 | case T2_OPCODE_ORR: | |
17160 | new_inst = T2_OPCODE_ORN; | |
17161 | value = inverted; | |
17162 | break; | |
17163 | ||
17164 | case T2_OPCODE_ORN: | |
17165 | new_inst = T2_OPCODE_ORR; | |
17166 | value = inverted; | |
17167 | break; | |
17168 | ||
17169 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
17170 | case T2_OPCODE_AND: | |
17171 | new_inst = T2_OPCODE_BIC; | |
17172 | if (rd == 15) | |
17173 | value = FAIL; | |
17174 | else | |
17175 | value = inverted; | |
17176 | break; | |
17177 | ||
17178 | case T2_OPCODE_BIC: | |
17179 | new_inst = T2_OPCODE_AND; | |
17180 | value = inverted; | |
17181 | break; | |
17182 | ||
17183 | /* ADC <-> SBC */ | |
17184 | case T2_OPCODE_ADC: | |
17185 | new_inst = T2_OPCODE_SBC; | |
17186 | value = inverted; | |
17187 | break; | |
17188 | ||
17189 | case T2_OPCODE_SBC: | |
17190 | new_inst = T2_OPCODE_ADC; | |
17191 | value = inverted; | |
17192 | break; | |
17193 | ||
17194 | /* We cannot do anything. */ | |
17195 | default: | |
17196 | return FAIL; | |
17197 | } | |
17198 | ||
17199 | if (value == FAIL) | |
17200 | return FAIL; | |
17201 | ||
17202 | *instruction &= T2_OPCODE_MASK; | |
17203 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
17204 | return value; | |
17205 | } | |
17206 | ||
8f06b2d8 PB |
17207 | /* Read a 32-bit thumb instruction from buf. */ |
17208 | static unsigned long | |
17209 | get_thumb32_insn (char * buf) | |
17210 | { | |
17211 | unsigned long insn; | |
17212 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
17213 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
17214 | ||
17215 | return insn; | |
17216 | } | |
17217 | ||
a8bc6c78 PB |
17218 | |
17219 | /* We usually want to set the low bit on the address of thumb function | |
17220 | symbols. In particular .word foo - . should have the low bit set. | |
17221 | Generic code tries to fold the difference of two symbols to | |
17222 | a constant. Prevent this and force a relocation when the first symbols | |
17223 | is a thumb function. */ | |
17224 | int | |
17225 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) | |
17226 | { | |
17227 | if (op == O_subtract | |
17228 | && l->X_op == O_symbol | |
17229 | && r->X_op == O_symbol | |
17230 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
17231 | { | |
17232 | l->X_op = O_subtract; | |
17233 | l->X_op_symbol = r->X_add_symbol; | |
17234 | l->X_add_number -= r->X_add_number; | |
17235 | return 1; | |
17236 | } | |
17237 | /* Process as normal. */ | |
17238 | return 0; | |
17239 | } | |
17240 | ||
c19d1205 | 17241 | void |
55cf6793 | 17242 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
17243 | valueT * valP, |
17244 | segT seg) | |
17245 | { | |
17246 | offsetT value = * valP; | |
17247 | offsetT newval; | |
17248 | unsigned int newimm; | |
17249 | unsigned long temp; | |
17250 | int sign; | |
17251 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 17252 | |
c19d1205 | 17253 | assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 17254 | |
c19d1205 | 17255 | /* Note whether this will delete the relocation. */ |
4962c51a | 17256 | |
c19d1205 ZW |
17257 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
17258 | fixP->fx_done = 1; | |
b99bd4ef | 17259 | |
adbaf948 ZW |
17260 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
17261 | consistency with the behavior on 32-bit hosts. Remember value | |
17262 | for emit_reloc. */ | |
17263 | value &= 0xffffffff; | |
17264 | value ^= 0x80000000; | |
17265 | value -= 0x80000000; | |
17266 | ||
17267 | *valP = value; | |
c19d1205 | 17268 | fixP->fx_addnumber = value; |
b99bd4ef | 17269 | |
adbaf948 ZW |
17270 | /* Same treatment for fixP->fx_offset. */ |
17271 | fixP->fx_offset &= 0xffffffff; | |
17272 | fixP->fx_offset ^= 0x80000000; | |
17273 | fixP->fx_offset -= 0x80000000; | |
17274 | ||
c19d1205 | 17275 | switch (fixP->fx_r_type) |
b99bd4ef | 17276 | { |
c19d1205 ZW |
17277 | case BFD_RELOC_NONE: |
17278 | /* This will need to go in the object file. */ | |
17279 | fixP->fx_done = 0; | |
17280 | break; | |
b99bd4ef | 17281 | |
c19d1205 ZW |
17282 | case BFD_RELOC_ARM_IMMEDIATE: |
17283 | /* We claim that this fixup has been processed here, | |
17284 | even if in fact we generate an error because we do | |
17285 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
17286 | fixP->fx_done = 1; | |
b99bd4ef | 17287 | |
c19d1205 ZW |
17288 | if (fixP->fx_addsy |
17289 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 17290 | { |
c19d1205 ZW |
17291 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17292 | _("undefined symbol %s used as an immediate value"), | |
17293 | S_GET_NAME (fixP->fx_addsy)); | |
17294 | break; | |
b99bd4ef NC |
17295 | } |
17296 | ||
c19d1205 ZW |
17297 | newimm = encode_arm_immediate (value); |
17298 | temp = md_chars_to_number (buf, INSN_SIZE); | |
17299 | ||
17300 | /* If the instruction will fail, see if we can fix things up by | |
17301 | changing the opcode. */ | |
17302 | if (newimm == (unsigned int) FAIL | |
17303 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 17304 | { |
c19d1205 ZW |
17305 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17306 | _("invalid constant (%lx) after fixup"), | |
17307 | (unsigned long) value); | |
17308 | break; | |
b99bd4ef | 17309 | } |
b99bd4ef | 17310 | |
c19d1205 ZW |
17311 | newimm |= (temp & 0xfffff000); |
17312 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
17313 | break; | |
b99bd4ef | 17314 | |
c19d1205 ZW |
17315 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
17316 | { | |
17317 | unsigned int highpart = 0; | |
17318 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 17319 | |
c19d1205 ZW |
17320 | newimm = encode_arm_immediate (value); |
17321 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 17322 | |
c19d1205 ZW |
17323 | /* If the instruction will fail, see if we can fix things up by |
17324 | changing the opcode. */ | |
17325 | if (newimm == (unsigned int) FAIL | |
17326 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
17327 | { | |
17328 | /* No ? OK - try using two ADD instructions to generate | |
17329 | the value. */ | |
17330 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 17331 | |
c19d1205 ZW |
17332 | /* Yes - then make sure that the second instruction is |
17333 | also an add. */ | |
17334 | if (newimm != (unsigned int) FAIL) | |
17335 | newinsn = temp; | |
17336 | /* Still No ? Try using a negated value. */ | |
17337 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
17338 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
17339 | /* Otherwise - give up. */ | |
17340 | else | |
17341 | { | |
17342 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17343 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
17344 | (long) value); | |
17345 | break; | |
17346 | } | |
b99bd4ef | 17347 | |
c19d1205 ZW |
17348 | /* Replace the first operand in the 2nd instruction (which |
17349 | is the PC) with the destination register. We have | |
17350 | already added in the PC in the first instruction and we | |
17351 | do not want to do it again. */ | |
17352 | newinsn &= ~ 0xf0000; | |
17353 | newinsn |= ((newinsn & 0x0f000) << 4); | |
17354 | } | |
b99bd4ef | 17355 | |
c19d1205 ZW |
17356 | newimm |= (temp & 0xfffff000); |
17357 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 17358 | |
c19d1205 ZW |
17359 | highpart |= (newinsn & 0xfffff000); |
17360 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
17361 | } | |
17362 | break; | |
b99bd4ef | 17363 | |
c19d1205 | 17364 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
17365 | if (!fixP->fx_done && seg->use_rela_p) |
17366 | value = 0; | |
17367 | ||
c19d1205 ZW |
17368 | case BFD_RELOC_ARM_LITERAL: |
17369 | sign = value >= 0; | |
b99bd4ef | 17370 | |
c19d1205 ZW |
17371 | if (value < 0) |
17372 | value = - value; | |
b99bd4ef | 17373 | |
c19d1205 | 17374 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 17375 | { |
c19d1205 ZW |
17376 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
17377 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17378 | _("invalid literal constant: pool needs to be closer")); | |
17379 | else | |
17380 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17381 | _("bad immediate value for offset (%ld)"), | |
17382 | (long) value); | |
17383 | break; | |
f03698e6 RE |
17384 | } |
17385 | ||
c19d1205 ZW |
17386 | newval = md_chars_to_number (buf, INSN_SIZE); |
17387 | newval &= 0xff7ff000; | |
17388 | newval |= value | (sign ? INDEX_UP : 0); | |
17389 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17390 | break; | |
b99bd4ef | 17391 | |
c19d1205 ZW |
17392 | case BFD_RELOC_ARM_OFFSET_IMM8: |
17393 | case BFD_RELOC_ARM_HWLITERAL: | |
17394 | sign = value >= 0; | |
b99bd4ef | 17395 | |
c19d1205 ZW |
17396 | if (value < 0) |
17397 | value = - value; | |
b99bd4ef | 17398 | |
c19d1205 | 17399 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 17400 | { |
c19d1205 ZW |
17401 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
17402 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17403 | _("invalid literal constant: pool needs to be closer")); | |
17404 | else | |
17405 | as_bad (_("bad immediate value for half-word offset (%ld)"), | |
17406 | (long) value); | |
17407 | break; | |
b99bd4ef NC |
17408 | } |
17409 | ||
c19d1205 ZW |
17410 | newval = md_chars_to_number (buf, INSN_SIZE); |
17411 | newval &= 0xff7ff0f0; | |
17412 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
17413 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17414 | break; | |
b99bd4ef | 17415 | |
c19d1205 ZW |
17416 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
17417 | if (value < 0 || value > 1020 || value % 4 != 0) | |
17418 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17419 | _("bad immediate value for offset (%ld)"), (long) value); | |
17420 | value /= 4; | |
b99bd4ef | 17421 | |
c19d1205 | 17422 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
17423 | newval |= value; |
17424 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
17425 | break; | |
b99bd4ef | 17426 | |
c19d1205 ZW |
17427 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
17428 | /* This is a complicated relocation used for all varieties of Thumb32 | |
17429 | load/store instruction with immediate offset: | |
17430 | ||
17431 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
17432 | *4, optional writeback(W) | |
17433 | (doubleword load/store) | |
17434 | ||
17435 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
17436 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
17437 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
17438 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
17439 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
17440 | ||
17441 | Uppercase letters indicate bits that are already encoded at | |
17442 | this point. Lowercase letters are our problem. For the | |
17443 | second block of instructions, the secondary opcode nybble | |
17444 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
17445 | a PC-relative operation. */ | |
17446 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17447 | newval <<= 16; | |
17448 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 17449 | |
c19d1205 | 17450 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 17451 | { |
c19d1205 ZW |
17452 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
17453 | if (value >= 0) | |
17454 | newval |= (1 << 23); | |
17455 | else | |
17456 | value = -value; | |
17457 | if (value % 4 != 0) | |
17458 | { | |
17459 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17460 | _("offset not a multiple of 4")); | |
17461 | break; | |
17462 | } | |
17463 | value /= 4; | |
216d22bc | 17464 | if (value > 0xff) |
c19d1205 ZW |
17465 | { |
17466 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17467 | _("offset out of range")); | |
17468 | break; | |
17469 | } | |
17470 | newval &= ~0xff; | |
b99bd4ef | 17471 | } |
c19d1205 | 17472 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 17473 | { |
c19d1205 ZW |
17474 | /* PC-relative, 12-bit offset. */ |
17475 | if (value >= 0) | |
17476 | newval |= (1 << 23); | |
17477 | else | |
17478 | value = -value; | |
216d22bc | 17479 | if (value > 0xfff) |
c19d1205 ZW |
17480 | { |
17481 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17482 | _("offset out of range")); | |
17483 | break; | |
17484 | } | |
17485 | newval &= ~0xfff; | |
b99bd4ef | 17486 | } |
c19d1205 | 17487 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 17488 | { |
c19d1205 ZW |
17489 | /* Writeback: 8-bit, +/- offset. */ |
17490 | if (value >= 0) | |
17491 | newval |= (1 << 9); | |
17492 | else | |
17493 | value = -value; | |
216d22bc | 17494 | if (value > 0xff) |
c19d1205 ZW |
17495 | { |
17496 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17497 | _("offset out of range")); | |
17498 | break; | |
17499 | } | |
17500 | newval &= ~0xff; | |
b99bd4ef | 17501 | } |
c19d1205 | 17502 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 17503 | { |
c19d1205 | 17504 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 17505 | if (value < 0 || value > 0xff) |
b99bd4ef | 17506 | { |
c19d1205 ZW |
17507 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17508 | _("offset out of range")); | |
17509 | break; | |
b99bd4ef | 17510 | } |
c19d1205 ZW |
17511 | newval &= ~0xff; |
17512 | newval |= value; | |
b99bd4ef NC |
17513 | } |
17514 | else | |
b99bd4ef | 17515 | { |
c19d1205 ZW |
17516 | /* Positive 12-bit or negative 8-bit offset. */ |
17517 | int limit; | |
17518 | if (value >= 0) | |
b99bd4ef | 17519 | { |
c19d1205 ZW |
17520 | newval |= (1 << 23); |
17521 | limit = 0xfff; | |
17522 | } | |
17523 | else | |
17524 | { | |
17525 | value = -value; | |
17526 | limit = 0xff; | |
17527 | } | |
17528 | if (value > limit) | |
17529 | { | |
17530 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17531 | _("offset out of range")); | |
17532 | break; | |
b99bd4ef | 17533 | } |
c19d1205 | 17534 | newval &= ~limit; |
b99bd4ef | 17535 | } |
b99bd4ef | 17536 | |
c19d1205 ZW |
17537 | newval |= value; |
17538 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
17539 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
17540 | break; | |
404ff6b5 | 17541 | |
c19d1205 ZW |
17542 | case BFD_RELOC_ARM_SHIFT_IMM: |
17543 | newval = md_chars_to_number (buf, INSN_SIZE); | |
17544 | if (((unsigned long) value) > 32 | |
17545 | || (value == 32 | |
17546 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
17547 | { | |
17548 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17549 | _("shift expression is too large")); | |
17550 | break; | |
17551 | } | |
404ff6b5 | 17552 | |
c19d1205 ZW |
17553 | if (value == 0) |
17554 | /* Shifts of zero must be done as lsl. */ | |
17555 | newval &= ~0x60; | |
17556 | else if (value == 32) | |
17557 | value = 0; | |
17558 | newval &= 0xfffff07f; | |
17559 | newval |= (value & 0x1f) << 7; | |
17560 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17561 | break; | |
404ff6b5 | 17562 | |
c19d1205 | 17563 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
92e90b6e | 17564 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 17565 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
17566 | /* We claim that this fixup has been processed here, |
17567 | even if in fact we generate an error because we do | |
17568 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
17569 | fixP->fx_done = 1; | |
404ff6b5 | 17570 | |
c19d1205 ZW |
17571 | if (fixP->fx_addsy |
17572 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
17573 | { | |
17574 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17575 | _("undefined symbol %s used as an immediate value"), | |
17576 | S_GET_NAME (fixP->fx_addsy)); | |
17577 | break; | |
17578 | } | |
404ff6b5 | 17579 | |
c19d1205 ZW |
17580 | newval = md_chars_to_number (buf, THUMB_SIZE); |
17581 | newval <<= 16; | |
17582 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 17583 | |
e9f89963 PB |
17584 | /* FUTURE: Implement analogue of negate_data_op for T32. */ |
17585 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE) | |
ef8d22e6 PB |
17586 | { |
17587 | newimm = encode_thumb32_immediate (value); | |
17588 | if (newimm == (unsigned int) FAIL) | |
17589 | newimm = thumb32_negate_data_op (&newval, value); | |
17590 | } | |
e9f89963 | 17591 | else |
92e90b6e | 17592 | { |
e9f89963 PB |
17593 | /* 12 bit immediate for addw/subw. */ |
17594 | if (value < 0) | |
17595 | { | |
17596 | value = -value; | |
17597 | newval ^= 0x00a00000; | |
17598 | } | |
92e90b6e PB |
17599 | if (value > 0xfff) |
17600 | newimm = (unsigned int) FAIL; | |
17601 | else | |
17602 | newimm = value; | |
17603 | } | |
cc8a6dd0 | 17604 | |
c19d1205 | 17605 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 17606 | { |
c19d1205 ZW |
17607 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17608 | _("invalid constant (%lx) after fixup"), | |
17609 | (unsigned long) value); | |
17610 | break; | |
3631a3c8 NC |
17611 | } |
17612 | ||
c19d1205 ZW |
17613 | newval |= (newimm & 0x800) << 15; |
17614 | newval |= (newimm & 0x700) << 4; | |
17615 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 17616 | |
c19d1205 ZW |
17617 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
17618 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
17619 | break; | |
a737bd4d | 17620 | |
3eb17e6b | 17621 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
17622 | if (((unsigned long) value) > 0xffff) |
17623 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 17624 | _("invalid smc expression")); |
2fc8bdac | 17625 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
17626 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
17627 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17628 | break; | |
a737bd4d | 17629 | |
c19d1205 | 17630 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 17631 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
17632 | { |
17633 | if (((unsigned long) value) > 0xff) | |
17634 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17635 | _("invalid swi expression")); | |
2fc8bdac | 17636 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
17637 | newval |= value; |
17638 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17639 | } | |
17640 | else | |
17641 | { | |
17642 | if (((unsigned long) value) > 0x00ffffff) | |
17643 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17644 | _("invalid swi expression")); | |
2fc8bdac | 17645 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
17646 | newval |= value; |
17647 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17648 | } | |
17649 | break; | |
a737bd4d | 17650 | |
c19d1205 ZW |
17651 | case BFD_RELOC_ARM_MULTI: |
17652 | if (((unsigned long) value) > 0xffff) | |
17653 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17654 | _("invalid expression in load/store multiple")); | |
17655 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
17656 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17657 | break; | |
a737bd4d | 17658 | |
c19d1205 | 17659 | #ifdef OBJ_ELF |
39b41c9c PB |
17660 | case BFD_RELOC_ARM_PCREL_CALL: |
17661 | newval = md_chars_to_number (buf, INSN_SIZE); | |
17662 | if ((newval & 0xf0000000) == 0xf0000000) | |
17663 | temp = 1; | |
17664 | else | |
17665 | temp = 3; | |
17666 | goto arm_branch_common; | |
17667 | ||
17668 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac | 17669 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 17670 | #endif |
39b41c9c PB |
17671 | case BFD_RELOC_ARM_PCREL_BRANCH: |
17672 | temp = 3; | |
17673 | goto arm_branch_common; | |
a737bd4d | 17674 | |
39b41c9c PB |
17675 | case BFD_RELOC_ARM_PCREL_BLX: |
17676 | temp = 1; | |
17677 | arm_branch_common: | |
c19d1205 | 17678 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
17679 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
17680 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
17681 | also be be clear. */ | |
17682 | if (value & temp) | |
c19d1205 | 17683 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
17684 | _("misaligned branch destination")); |
17685 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
17686 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
17687 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17688 | _("branch out of range")); | |
a737bd4d | 17689 | |
2fc8bdac | 17690 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 17691 | { |
2fc8bdac ZW |
17692 | newval = md_chars_to_number (buf, INSN_SIZE); |
17693 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
17694 | /* Set the H bit on BLX instructions. */ |
17695 | if (temp == 1) | |
17696 | { | |
17697 | if (value & 2) | |
17698 | newval |= 0x01000000; | |
17699 | else | |
17700 | newval &= ~0x01000000; | |
17701 | } | |
2fc8bdac | 17702 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 17703 | } |
c19d1205 | 17704 | break; |
a737bd4d | 17705 | |
c19d1205 | 17706 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */ |
2fc8bdac ZW |
17707 | /* CZB can only branch forward. */ |
17708 | if (value & ~0x7e) | |
17709 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17710 | _("branch out of range")); | |
a737bd4d | 17711 | |
2fc8bdac ZW |
17712 | if (fixP->fx_done || !seg->use_rela_p) |
17713 | { | |
17714 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
080eb7fe | 17715 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); |
2fc8bdac ZW |
17716 | md_number_to_chars (buf, newval, THUMB_SIZE); |
17717 | } | |
c19d1205 | 17718 | break; |
a737bd4d | 17719 | |
c19d1205 | 17720 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
17721 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
17722 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17723 | _("branch out of range")); | |
a737bd4d | 17724 | |
2fc8bdac ZW |
17725 | if (fixP->fx_done || !seg->use_rela_p) |
17726 | { | |
17727 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17728 | newval |= (value & 0x1ff) >> 1; | |
17729 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17730 | } | |
c19d1205 | 17731 | break; |
a737bd4d | 17732 | |
c19d1205 | 17733 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
17734 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
17735 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17736 | _("branch out of range")); | |
a737bd4d | 17737 | |
2fc8bdac ZW |
17738 | if (fixP->fx_done || !seg->use_rela_p) |
17739 | { | |
17740 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17741 | newval |= (value & 0xfff) >> 1; | |
17742 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17743 | } | |
c19d1205 | 17744 | break; |
a737bd4d | 17745 | |
c19d1205 | 17746 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
2fc8bdac ZW |
17747 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
17748 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17749 | _("conditional branch out of range")); | |
404ff6b5 | 17750 | |
2fc8bdac ZW |
17751 | if (fixP->fx_done || !seg->use_rela_p) |
17752 | { | |
17753 | offsetT newval2; | |
17754 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 17755 | |
2fc8bdac ZW |
17756 | S = (value & 0x00100000) >> 20; |
17757 | J2 = (value & 0x00080000) >> 19; | |
17758 | J1 = (value & 0x00040000) >> 18; | |
17759 | hi = (value & 0x0003f000) >> 12; | |
17760 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 17761 | |
2fc8bdac ZW |
17762 | newval = md_chars_to_number (buf, THUMB_SIZE); |
17763 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
17764 | newval |= (S << 10) | hi; | |
17765 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
17766 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17767 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
17768 | } | |
c19d1205 | 17769 | break; |
6c43fab6 | 17770 | |
c19d1205 ZW |
17771 | case BFD_RELOC_THUMB_PCREL_BLX: |
17772 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
2fc8bdac ZW |
17773 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
17774 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17775 | _("branch out of range")); | |
404ff6b5 | 17776 | |
2fc8bdac ZW |
17777 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
17778 | /* For a BLX instruction, make sure that the relocation is rounded up | |
17779 | to a word boundary. This follows the semantics of the instruction | |
17780 | which specifies that bit 1 of the target address will come from bit | |
17781 | 1 of the base address. */ | |
17782 | value = (value + 1) & ~ 1; | |
404ff6b5 | 17783 | |
2fc8bdac | 17784 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 17785 | { |
2fc8bdac ZW |
17786 | offsetT newval2; |
17787 | ||
17788 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17789 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
17790 | newval |= (value & 0x7fffff) >> 12; | |
17791 | newval2 |= (value & 0xfff) >> 1; | |
17792 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17793 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 17794 | } |
c19d1205 | 17795 | break; |
404ff6b5 | 17796 | |
c19d1205 | 17797 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
17798 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
17799 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17800 | _("branch out of range")); | |
6c43fab6 | 17801 | |
2fc8bdac ZW |
17802 | if (fixP->fx_done || !seg->use_rela_p) |
17803 | { | |
17804 | offsetT newval2; | |
17805 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 17806 | |
2fc8bdac ZW |
17807 | S = (value & 0x01000000) >> 24; |
17808 | I1 = (value & 0x00800000) >> 23; | |
17809 | I2 = (value & 0x00400000) >> 22; | |
17810 | hi = (value & 0x003ff000) >> 12; | |
17811 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 17812 | |
2fc8bdac ZW |
17813 | I1 = !(I1 ^ S); |
17814 | I2 = !(I2 ^ S); | |
a737bd4d | 17815 | |
2fc8bdac ZW |
17816 | newval = md_chars_to_number (buf, THUMB_SIZE); |
17817 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
17818 | newval |= (S << 10) | hi; | |
17819 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
17820 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17821 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
17822 | } | |
17823 | break; | |
a737bd4d | 17824 | |
2fc8bdac ZW |
17825 | case BFD_RELOC_8: |
17826 | if (fixP->fx_done || !seg->use_rela_p) | |
17827 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 17828 | break; |
a737bd4d | 17829 | |
c19d1205 | 17830 | case BFD_RELOC_16: |
2fc8bdac | 17831 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 17832 | md_number_to_chars (buf, value, 2); |
c19d1205 | 17833 | break; |
a737bd4d | 17834 | |
c19d1205 ZW |
17835 | #ifdef OBJ_ELF |
17836 | case BFD_RELOC_ARM_TLS_GD32: | |
17837 | case BFD_RELOC_ARM_TLS_LE32: | |
17838 | case BFD_RELOC_ARM_TLS_IE32: | |
17839 | case BFD_RELOC_ARM_TLS_LDM32: | |
17840 | case BFD_RELOC_ARM_TLS_LDO32: | |
17841 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
17842 | /* fall through */ | |
6c43fab6 | 17843 | |
c19d1205 ZW |
17844 | case BFD_RELOC_ARM_GOT32: |
17845 | case BFD_RELOC_ARM_GOTOFF: | |
17846 | case BFD_RELOC_ARM_TARGET2: | |
2fc8bdac ZW |
17847 | if (fixP->fx_done || !seg->use_rela_p) |
17848 | md_number_to_chars (buf, 0, 4); | |
c19d1205 ZW |
17849 | break; |
17850 | #endif | |
6c43fab6 | 17851 | |
c19d1205 ZW |
17852 | case BFD_RELOC_RVA: |
17853 | case BFD_RELOC_32: | |
17854 | case BFD_RELOC_ARM_TARGET1: | |
17855 | case BFD_RELOC_ARM_ROSEGREL32: | |
17856 | case BFD_RELOC_ARM_SBREL32: | |
17857 | case BFD_RELOC_32_PCREL: | |
2fc8bdac | 17858 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
17859 | #ifdef TE_WINCE |
17860 | /* For WinCE we only do this for pcrel fixups. */ | |
17861 | if (fixP->fx_done || fixP->fx_pcrel) | |
17862 | #endif | |
17863 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 17864 | break; |
6c43fab6 | 17865 | |
c19d1205 ZW |
17866 | #ifdef OBJ_ELF |
17867 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 17868 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
17869 | { |
17870 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
17871 | if ((value ^ (value >> 1)) & 0x40000000) | |
17872 | { | |
17873 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17874 | _("rel31 relocation overflow")); | |
17875 | } | |
17876 | newval |= value & 0x7fffffff; | |
17877 | md_number_to_chars (buf, newval, 4); | |
17878 | } | |
17879 | break; | |
c19d1205 | 17880 | #endif |
a737bd4d | 17881 | |
c19d1205 | 17882 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 17883 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
17884 | if (value < -1023 || value > 1023 || (value & 3)) |
17885 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17886 | _("co-processor offset out of range")); | |
17887 | cp_off_common: | |
17888 | sign = value >= 0; | |
17889 | if (value < 0) | |
17890 | value = -value; | |
8f06b2d8 PB |
17891 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
17892 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
17893 | newval = md_chars_to_number (buf, INSN_SIZE); | |
17894 | else | |
17895 | newval = get_thumb32_insn (buf); | |
17896 | newval &= 0xff7fff00; | |
c19d1205 ZW |
17897 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
17898 | if (value == 0) | |
17899 | newval &= ~WRITE_BACK; | |
8f06b2d8 PB |
17900 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
17901 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
17902 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17903 | else | |
17904 | put_thumb32_insn (buf, newval); | |
c19d1205 | 17905 | break; |
a737bd4d | 17906 | |
c19d1205 | 17907 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 17908 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
17909 | if (value < -255 || value > 255) |
17910 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17911 | _("co-processor offset out of range")); | |
df7849c5 | 17912 | value *= 4; |
c19d1205 | 17913 | goto cp_off_common; |
6c43fab6 | 17914 | |
c19d1205 ZW |
17915 | case BFD_RELOC_ARM_THUMB_OFFSET: |
17916 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17917 | /* Exactly what ranges, and where the offset is inserted depends | |
17918 | on the type of instruction, we can establish this from the | |
17919 | top 4 bits. */ | |
17920 | switch (newval >> 12) | |
17921 | { | |
17922 | case 4: /* PC load. */ | |
17923 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
17924 | forced to zero for these loads; md_pcrel_from has already | |
17925 | compensated for this. */ | |
17926 | if (value & 3) | |
17927 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17928 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
17929 | (((unsigned long) fixP->fx_frag->fr_address |
17930 | + (unsigned long) fixP->fx_where) & ~3) | |
17931 | + (unsigned long) value); | |
a737bd4d | 17932 | |
c19d1205 ZW |
17933 | if (value & ~0x3fc) |
17934 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17935 | _("invalid offset, value too big (0x%08lX)"), | |
17936 | (long) value); | |
a737bd4d | 17937 | |
c19d1205 ZW |
17938 | newval |= value >> 2; |
17939 | break; | |
a737bd4d | 17940 | |
c19d1205 ZW |
17941 | case 9: /* SP load/store. */ |
17942 | if (value & ~0x3fc) | |
17943 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17944 | _("invalid offset, value too big (0x%08lX)"), | |
17945 | (long) value); | |
17946 | newval |= value >> 2; | |
17947 | break; | |
6c43fab6 | 17948 | |
c19d1205 ZW |
17949 | case 6: /* Word load/store. */ |
17950 | if (value & ~0x7c) | |
17951 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17952 | _("invalid offset, value too big (0x%08lX)"), | |
17953 | (long) value); | |
17954 | newval |= value << 4; /* 6 - 2. */ | |
17955 | break; | |
a737bd4d | 17956 | |
c19d1205 ZW |
17957 | case 7: /* Byte load/store. */ |
17958 | if (value & ~0x1f) | |
17959 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17960 | _("invalid offset, value too big (0x%08lX)"), | |
17961 | (long) value); | |
17962 | newval |= value << 6; | |
17963 | break; | |
a737bd4d | 17964 | |
c19d1205 ZW |
17965 | case 8: /* Halfword load/store. */ |
17966 | if (value & ~0x3e) | |
17967 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17968 | _("invalid offset, value too big (0x%08lX)"), | |
17969 | (long) value); | |
17970 | newval |= value << 5; /* 6 - 1. */ | |
17971 | break; | |
a737bd4d | 17972 | |
c19d1205 ZW |
17973 | default: |
17974 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17975 | "Unable to process relocation for thumb opcode: %lx", | |
17976 | (unsigned long) newval); | |
17977 | break; | |
17978 | } | |
17979 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17980 | break; | |
a737bd4d | 17981 | |
c19d1205 ZW |
17982 | case BFD_RELOC_ARM_THUMB_ADD: |
17983 | /* This is a complicated relocation, since we use it for all of | |
17984 | the following immediate relocations: | |
a737bd4d | 17985 | |
c19d1205 ZW |
17986 | 3bit ADD/SUB |
17987 | 8bit ADD/SUB | |
17988 | 9bit ADD/SUB SP word-aligned | |
17989 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 17990 | |
c19d1205 ZW |
17991 | The type of instruction being processed is encoded in the |
17992 | instruction field: | |
a737bd4d | 17993 | |
c19d1205 ZW |
17994 | 0x8000 SUB |
17995 | 0x00F0 Rd | |
17996 | 0x000F Rs | |
17997 | */ | |
17998 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17999 | { | |
18000 | int rd = (newval >> 4) & 0xf; | |
18001 | int rs = newval & 0xf; | |
18002 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 18003 | |
c19d1205 ZW |
18004 | /* Check for HI regs, only very restricted cases allowed: |
18005 | Adjusting SP, and using PC or SP to get an address. */ | |
18006 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
18007 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
18008 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18009 | _("invalid Hi register with immediate")); | |
a737bd4d | 18010 | |
c19d1205 ZW |
18011 | /* If value is negative, choose the opposite instruction. */ |
18012 | if (value < 0) | |
18013 | { | |
18014 | value = -value; | |
18015 | subtract = !subtract; | |
18016 | if (value < 0) | |
18017 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18018 | _("immediate value out of range")); | |
18019 | } | |
a737bd4d | 18020 | |
c19d1205 ZW |
18021 | if (rd == REG_SP) |
18022 | { | |
18023 | if (value & ~0x1fc) | |
18024 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18025 | _("invalid immediate for stack address calculation")); | |
18026 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
18027 | newval |= value >> 2; | |
18028 | } | |
18029 | else if (rs == REG_PC || rs == REG_SP) | |
18030 | { | |
18031 | if (subtract || value & ~0x3fc) | |
18032 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18033 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
18034 | (unsigned long) value); | |
18035 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
18036 | newval |= rd << 8; | |
18037 | newval |= value >> 2; | |
18038 | } | |
18039 | else if (rs == rd) | |
18040 | { | |
18041 | if (value & ~0xff) | |
18042 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18043 | _("immediate value out of range")); | |
18044 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
18045 | newval |= (rd << 8) | value; | |
18046 | } | |
18047 | else | |
18048 | { | |
18049 | if (value & ~0x7) | |
18050 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18051 | _("immediate value out of range")); | |
18052 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
18053 | newval |= rd | (rs << 3) | (value << 6); | |
18054 | } | |
18055 | } | |
18056 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18057 | break; | |
a737bd4d | 18058 | |
c19d1205 ZW |
18059 | case BFD_RELOC_ARM_THUMB_IMM: |
18060 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18061 | if (value < 0 || value > 255) | |
18062 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18063 | _("invalid immediate: %ld is too large"), | |
18064 | (long) value); | |
18065 | newval |= value; | |
18066 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18067 | break; | |
a737bd4d | 18068 | |
c19d1205 ZW |
18069 | case BFD_RELOC_ARM_THUMB_SHIFT: |
18070 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
18071 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
18072 | temp = newval & 0xf800; | |
18073 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
18074 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18075 | _("invalid shift value: %ld"), (long) value); | |
18076 | /* Shifts of zero must be encoded as LSL. */ | |
18077 | if (value == 0) | |
18078 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
18079 | /* Shifts of 32 are encoded as zero. */ | |
18080 | else if (value == 32) | |
18081 | value = 0; | |
18082 | newval |= value << 6; | |
18083 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18084 | break; | |
a737bd4d | 18085 | |
c19d1205 ZW |
18086 | case BFD_RELOC_VTABLE_INHERIT: |
18087 | case BFD_RELOC_VTABLE_ENTRY: | |
18088 | fixP->fx_done = 0; | |
18089 | return; | |
6c43fab6 | 18090 | |
b6895b4f PB |
18091 | case BFD_RELOC_ARM_MOVW: |
18092 | case BFD_RELOC_ARM_MOVT: | |
18093 | case BFD_RELOC_ARM_THUMB_MOVW: | |
18094 | case BFD_RELOC_ARM_THUMB_MOVT: | |
18095 | if (fixP->fx_done || !seg->use_rela_p) | |
18096 | { | |
18097 | /* REL format relocations are limited to a 16-bit addend. */ | |
18098 | if (!fixP->fx_done) | |
18099 | { | |
18100 | if (value < -0x1000 || value > 0xffff) | |
18101 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18102 | _("offset too big")); | |
18103 | } | |
18104 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
18105 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
18106 | { | |
18107 | value >>= 16; | |
18108 | } | |
18109 | ||
18110 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
18111 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
18112 | { | |
18113 | newval = get_thumb32_insn (buf); | |
18114 | newval &= 0xfbf08f00; | |
18115 | newval |= (value & 0xf000) << 4; | |
18116 | newval |= (value & 0x0800) << 15; | |
18117 | newval |= (value & 0x0700) << 4; | |
18118 | newval |= (value & 0x00ff); | |
18119 | put_thumb32_insn (buf, newval); | |
18120 | } | |
18121 | else | |
18122 | { | |
18123 | newval = md_chars_to_number (buf, 4); | |
18124 | newval &= 0xfff0f000; | |
18125 | newval |= value & 0x0fff; | |
18126 | newval |= (value & 0xf000) << 4; | |
18127 | md_number_to_chars (buf, newval, 4); | |
18128 | } | |
18129 | } | |
18130 | return; | |
18131 | ||
4962c51a MS |
18132 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
18133 | case BFD_RELOC_ARM_ALU_PC_G0: | |
18134 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
18135 | case BFD_RELOC_ARM_ALU_PC_G1: | |
18136 | case BFD_RELOC_ARM_ALU_PC_G2: | |
18137 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
18138 | case BFD_RELOC_ARM_ALU_SB_G0: | |
18139 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
18140 | case BFD_RELOC_ARM_ALU_SB_G1: | |
18141 | case BFD_RELOC_ARM_ALU_SB_G2: | |
18142 | assert (!fixP->fx_done); | |
18143 | if (!seg->use_rela_p) | |
18144 | { | |
18145 | bfd_vma insn; | |
18146 | bfd_vma encoded_addend; | |
18147 | bfd_vma addend_abs = abs (value); | |
18148 | ||
18149 | /* Check that the absolute value of the addend can be | |
18150 | expressed as an 8-bit constant plus a rotation. */ | |
18151 | encoded_addend = encode_arm_immediate (addend_abs); | |
18152 | if (encoded_addend == (unsigned int) FAIL) | |
18153 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18154 | _("the offset 0x%08lX is not representable"), | |
18155 | addend_abs); | |
18156 | ||
18157 | /* Extract the instruction. */ | |
18158 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18159 | ||
18160 | /* If the addend is positive, use an ADD instruction. | |
18161 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
18162 | insn &= 0xff1fffff; | |
18163 | if (value < 0) | |
18164 | insn |= 1 << 22; | |
18165 | else | |
18166 | insn |= 1 << 23; | |
18167 | ||
18168 | /* Place the encoded addend into the first 12 bits of the | |
18169 | instruction. */ | |
18170 | insn &= 0xfffff000; | |
18171 | insn |= encoded_addend; | |
18172 | ||
18173 | /* Update the instruction. */ | |
18174 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18175 | } | |
18176 | break; | |
18177 | ||
18178 | case BFD_RELOC_ARM_LDR_PC_G0: | |
18179 | case BFD_RELOC_ARM_LDR_PC_G1: | |
18180 | case BFD_RELOC_ARM_LDR_PC_G2: | |
18181 | case BFD_RELOC_ARM_LDR_SB_G0: | |
18182 | case BFD_RELOC_ARM_LDR_SB_G1: | |
18183 | case BFD_RELOC_ARM_LDR_SB_G2: | |
18184 | assert (!fixP->fx_done); | |
18185 | if (!seg->use_rela_p) | |
18186 | { | |
18187 | bfd_vma insn; | |
18188 | bfd_vma addend_abs = abs (value); | |
18189 | ||
18190 | /* Check that the absolute value of the addend can be | |
18191 | encoded in 12 bits. */ | |
18192 | if (addend_abs >= 0x1000) | |
18193 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18194 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
18195 | addend_abs); | |
18196 | ||
18197 | /* Extract the instruction. */ | |
18198 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18199 | ||
18200 | /* If the addend is negative, clear bit 23 of the instruction. | |
18201 | Otherwise set it. */ | |
18202 | if (value < 0) | |
18203 | insn &= ~(1 << 23); | |
18204 | else | |
18205 | insn |= 1 << 23; | |
18206 | ||
18207 | /* Place the absolute value of the addend into the first 12 bits | |
18208 | of the instruction. */ | |
18209 | insn &= 0xfffff000; | |
18210 | insn |= addend_abs; | |
18211 | ||
18212 | /* Update the instruction. */ | |
18213 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18214 | } | |
18215 | break; | |
18216 | ||
18217 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
18218 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
18219 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
18220 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
18221 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
18222 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
18223 | assert (!fixP->fx_done); | |
18224 | if (!seg->use_rela_p) | |
18225 | { | |
18226 | bfd_vma insn; | |
18227 | bfd_vma addend_abs = abs (value); | |
18228 | ||
18229 | /* Check that the absolute value of the addend can be | |
18230 | encoded in 8 bits. */ | |
18231 | if (addend_abs >= 0x100) | |
18232 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18233 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
18234 | addend_abs); | |
18235 | ||
18236 | /* Extract the instruction. */ | |
18237 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18238 | ||
18239 | /* If the addend is negative, clear bit 23 of the instruction. | |
18240 | Otherwise set it. */ | |
18241 | if (value < 0) | |
18242 | insn &= ~(1 << 23); | |
18243 | else | |
18244 | insn |= 1 << 23; | |
18245 | ||
18246 | /* Place the first four bits of the absolute value of the addend | |
18247 | into the first 4 bits of the instruction, and the remaining | |
18248 | four into bits 8 .. 11. */ | |
18249 | insn &= 0xfffff0f0; | |
18250 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
18251 | ||
18252 | /* Update the instruction. */ | |
18253 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18254 | } | |
18255 | break; | |
18256 | ||
18257 | case BFD_RELOC_ARM_LDC_PC_G0: | |
18258 | case BFD_RELOC_ARM_LDC_PC_G1: | |
18259 | case BFD_RELOC_ARM_LDC_PC_G2: | |
18260 | case BFD_RELOC_ARM_LDC_SB_G0: | |
18261 | case BFD_RELOC_ARM_LDC_SB_G1: | |
18262 | case BFD_RELOC_ARM_LDC_SB_G2: | |
18263 | assert (!fixP->fx_done); | |
18264 | if (!seg->use_rela_p) | |
18265 | { | |
18266 | bfd_vma insn; | |
18267 | bfd_vma addend_abs = abs (value); | |
18268 | ||
18269 | /* Check that the absolute value of the addend is a multiple of | |
18270 | four and, when divided by four, fits in 8 bits. */ | |
18271 | if (addend_abs & 0x3) | |
18272 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18273 | _("bad offset 0x%08lX (must be word-aligned)"), | |
18274 | addend_abs); | |
18275 | ||
18276 | if ((addend_abs >> 2) > 0xff) | |
18277 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18278 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
18279 | addend_abs); | |
18280 | ||
18281 | /* Extract the instruction. */ | |
18282 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18283 | ||
18284 | /* If the addend is negative, clear bit 23 of the instruction. | |
18285 | Otherwise set it. */ | |
18286 | if (value < 0) | |
18287 | insn &= ~(1 << 23); | |
18288 | else | |
18289 | insn |= 1 << 23; | |
18290 | ||
18291 | /* Place the addend (divided by four) into the first eight | |
18292 | bits of the instruction. */ | |
18293 | insn &= 0xfffffff0; | |
18294 | insn |= addend_abs >> 2; | |
18295 | ||
18296 | /* Update the instruction. */ | |
18297 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18298 | } | |
18299 | break; | |
18300 | ||
c19d1205 ZW |
18301 | case BFD_RELOC_UNUSED: |
18302 | default: | |
18303 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18304 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
18305 | } | |
6c43fab6 RE |
18306 | } |
18307 | ||
c19d1205 ZW |
18308 | /* Translate internal representation of relocation info to BFD target |
18309 | format. */ | |
a737bd4d | 18310 | |
c19d1205 | 18311 | arelent * |
00a97672 | 18312 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 18313 | { |
c19d1205 ZW |
18314 | arelent * reloc; |
18315 | bfd_reloc_code_real_type code; | |
a737bd4d | 18316 | |
c19d1205 | 18317 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 18318 | |
c19d1205 ZW |
18319 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
18320 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
18321 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 18322 | |
2fc8bdac | 18323 | if (fixp->fx_pcrel) |
00a97672 RS |
18324 | { |
18325 | if (section->use_rela_p) | |
18326 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
18327 | else | |
18328 | fixp->fx_offset = reloc->address; | |
18329 | } | |
c19d1205 | 18330 | reloc->addend = fixp->fx_offset; |
a737bd4d | 18331 | |
c19d1205 | 18332 | switch (fixp->fx_r_type) |
a737bd4d | 18333 | { |
c19d1205 ZW |
18334 | case BFD_RELOC_8: |
18335 | if (fixp->fx_pcrel) | |
18336 | { | |
18337 | code = BFD_RELOC_8_PCREL; | |
18338 | break; | |
18339 | } | |
a737bd4d | 18340 | |
c19d1205 ZW |
18341 | case BFD_RELOC_16: |
18342 | if (fixp->fx_pcrel) | |
18343 | { | |
18344 | code = BFD_RELOC_16_PCREL; | |
18345 | break; | |
18346 | } | |
6c43fab6 | 18347 | |
c19d1205 ZW |
18348 | case BFD_RELOC_32: |
18349 | if (fixp->fx_pcrel) | |
18350 | { | |
18351 | code = BFD_RELOC_32_PCREL; | |
18352 | break; | |
18353 | } | |
a737bd4d | 18354 | |
b6895b4f PB |
18355 | case BFD_RELOC_ARM_MOVW: |
18356 | if (fixp->fx_pcrel) | |
18357 | { | |
18358 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
18359 | break; | |
18360 | } | |
18361 | ||
18362 | case BFD_RELOC_ARM_MOVT: | |
18363 | if (fixp->fx_pcrel) | |
18364 | { | |
18365 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
18366 | break; | |
18367 | } | |
18368 | ||
18369 | case BFD_RELOC_ARM_THUMB_MOVW: | |
18370 | if (fixp->fx_pcrel) | |
18371 | { | |
18372 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
18373 | break; | |
18374 | } | |
18375 | ||
18376 | case BFD_RELOC_ARM_THUMB_MOVT: | |
18377 | if (fixp->fx_pcrel) | |
18378 | { | |
18379 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
18380 | break; | |
18381 | } | |
18382 | ||
c19d1205 ZW |
18383 | case BFD_RELOC_NONE: |
18384 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
18385 | case BFD_RELOC_ARM_PCREL_BLX: | |
18386 | case BFD_RELOC_RVA: | |
18387 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
18388 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
18389 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
18390 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
18391 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
18392 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
18393 | case BFD_RELOC_THUMB_PCREL_BLX: | |
18394 | case BFD_RELOC_VTABLE_ENTRY: | |
18395 | case BFD_RELOC_VTABLE_INHERIT: | |
18396 | code = fixp->fx_r_type; | |
18397 | break; | |
a737bd4d | 18398 | |
c19d1205 ZW |
18399 | case BFD_RELOC_ARM_LITERAL: |
18400 | case BFD_RELOC_ARM_HWLITERAL: | |
18401 | /* If this is called then the a literal has | |
18402 | been referenced across a section boundary. */ | |
18403 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18404 | _("literal referenced across section boundary")); | |
18405 | return NULL; | |
a737bd4d | 18406 | |
c19d1205 ZW |
18407 | #ifdef OBJ_ELF |
18408 | case BFD_RELOC_ARM_GOT32: | |
18409 | case BFD_RELOC_ARM_GOTOFF: | |
18410 | case BFD_RELOC_ARM_PLT32: | |
18411 | case BFD_RELOC_ARM_TARGET1: | |
18412 | case BFD_RELOC_ARM_ROSEGREL32: | |
18413 | case BFD_RELOC_ARM_SBREL32: | |
18414 | case BFD_RELOC_ARM_PREL31: | |
18415 | case BFD_RELOC_ARM_TARGET2: | |
18416 | case BFD_RELOC_ARM_TLS_LE32: | |
18417 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
18418 | case BFD_RELOC_ARM_PCREL_CALL: |
18419 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
18420 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
18421 | case BFD_RELOC_ARM_ALU_PC_G0: | |
18422 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
18423 | case BFD_RELOC_ARM_ALU_PC_G1: | |
18424 | case BFD_RELOC_ARM_ALU_PC_G2: | |
18425 | case BFD_RELOC_ARM_LDR_PC_G0: | |
18426 | case BFD_RELOC_ARM_LDR_PC_G1: | |
18427 | case BFD_RELOC_ARM_LDR_PC_G2: | |
18428 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
18429 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
18430 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
18431 | case BFD_RELOC_ARM_LDC_PC_G0: | |
18432 | case BFD_RELOC_ARM_LDC_PC_G1: | |
18433 | case BFD_RELOC_ARM_LDC_PC_G2: | |
18434 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
18435 | case BFD_RELOC_ARM_ALU_SB_G0: | |
18436 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
18437 | case BFD_RELOC_ARM_ALU_SB_G1: | |
18438 | case BFD_RELOC_ARM_ALU_SB_G2: | |
18439 | case BFD_RELOC_ARM_LDR_SB_G0: | |
18440 | case BFD_RELOC_ARM_LDR_SB_G1: | |
18441 | case BFD_RELOC_ARM_LDR_SB_G2: | |
18442 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
18443 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
18444 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
18445 | case BFD_RELOC_ARM_LDC_SB_G0: | |
18446 | case BFD_RELOC_ARM_LDC_SB_G1: | |
18447 | case BFD_RELOC_ARM_LDC_SB_G2: | |
c19d1205 ZW |
18448 | code = fixp->fx_r_type; |
18449 | break; | |
a737bd4d | 18450 | |
c19d1205 ZW |
18451 | case BFD_RELOC_ARM_TLS_GD32: |
18452 | case BFD_RELOC_ARM_TLS_IE32: | |
18453 | case BFD_RELOC_ARM_TLS_LDM32: | |
18454 | /* BFD will include the symbol's address in the addend. | |
18455 | But we don't want that, so subtract it out again here. */ | |
18456 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
18457 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
18458 | code = fixp->fx_r_type; | |
18459 | break; | |
18460 | #endif | |
a737bd4d | 18461 | |
c19d1205 ZW |
18462 | case BFD_RELOC_ARM_IMMEDIATE: |
18463 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18464 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
18465 | return NULL; | |
a737bd4d | 18466 | |
c19d1205 ZW |
18467 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
18468 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18469 | _("ADRL used for a symbol not defined in the same file")); | |
18470 | return NULL; | |
a737bd4d | 18471 | |
c19d1205 | 18472 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
18473 | if (section->use_rela_p) |
18474 | { | |
18475 | code = fixp->fx_r_type; | |
18476 | break; | |
18477 | } | |
18478 | ||
c19d1205 ZW |
18479 | if (fixp->fx_addsy != NULL |
18480 | && !S_IS_DEFINED (fixp->fx_addsy) | |
18481 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 18482 | { |
c19d1205 ZW |
18483 | as_bad_where (fixp->fx_file, fixp->fx_line, |
18484 | _("undefined local label `%s'"), | |
18485 | S_GET_NAME (fixp->fx_addsy)); | |
18486 | return NULL; | |
a737bd4d NC |
18487 | } |
18488 | ||
c19d1205 ZW |
18489 | as_bad_where (fixp->fx_file, fixp->fx_line, |
18490 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
18491 | return NULL; | |
a737bd4d | 18492 | |
c19d1205 ZW |
18493 | default: |
18494 | { | |
18495 | char * type; | |
6c43fab6 | 18496 | |
c19d1205 ZW |
18497 | switch (fixp->fx_r_type) |
18498 | { | |
18499 | case BFD_RELOC_NONE: type = "NONE"; break; | |
18500 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
18501 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 18502 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
18503 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
18504 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
18505 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 18506 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
18507 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
18508 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
18509 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
18510 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
18511 | default: type = _("<unknown>"); break; | |
18512 | } | |
18513 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18514 | _("cannot represent %s relocation in this object file format"), | |
18515 | type); | |
18516 | return NULL; | |
18517 | } | |
a737bd4d | 18518 | } |
6c43fab6 | 18519 | |
c19d1205 ZW |
18520 | #ifdef OBJ_ELF |
18521 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
18522 | && GOT_symbol | |
18523 | && fixp->fx_addsy == GOT_symbol) | |
18524 | { | |
18525 | code = BFD_RELOC_ARM_GOTPC; | |
18526 | reloc->addend = fixp->fx_offset = reloc->address; | |
18527 | } | |
18528 | #endif | |
6c43fab6 | 18529 | |
c19d1205 | 18530 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 18531 | |
c19d1205 ZW |
18532 | if (reloc->howto == NULL) |
18533 | { | |
18534 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18535 | _("cannot represent %s relocation in this object file format"), | |
18536 | bfd_get_reloc_code_name (code)); | |
18537 | return NULL; | |
18538 | } | |
6c43fab6 | 18539 | |
c19d1205 ZW |
18540 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
18541 | vtable entry to be used in the relocation's section offset. */ | |
18542 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
18543 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 18544 | |
c19d1205 | 18545 | return reloc; |
6c43fab6 RE |
18546 | } |
18547 | ||
c19d1205 | 18548 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 18549 | |
c19d1205 ZW |
18550 | void |
18551 | cons_fix_new_arm (fragS * frag, | |
18552 | int where, | |
18553 | int size, | |
18554 | expressionS * exp) | |
6c43fab6 | 18555 | { |
c19d1205 ZW |
18556 | bfd_reloc_code_real_type type; |
18557 | int pcrel = 0; | |
6c43fab6 | 18558 | |
c19d1205 ZW |
18559 | /* Pick a reloc. |
18560 | FIXME: @@ Should look at CPU word size. */ | |
18561 | switch (size) | |
18562 | { | |
18563 | case 1: | |
18564 | type = BFD_RELOC_8; | |
18565 | break; | |
18566 | case 2: | |
18567 | type = BFD_RELOC_16; | |
18568 | break; | |
18569 | case 4: | |
18570 | default: | |
18571 | type = BFD_RELOC_32; | |
18572 | break; | |
18573 | case 8: | |
18574 | type = BFD_RELOC_64; | |
18575 | break; | |
18576 | } | |
6c43fab6 | 18577 | |
c19d1205 ZW |
18578 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
18579 | } | |
6c43fab6 | 18580 | |
c19d1205 ZW |
18581 | #if defined OBJ_COFF || defined OBJ_ELF |
18582 | void | |
18583 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 18584 | { |
c19d1205 ZW |
18585 | /* If the destination of the branch is a defined symbol which does not have |
18586 | the THUMB_FUNC attribute, then we must be calling a function which has | |
18587 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
18588 | function and change the branch to refer to that function instead. */ | |
18589 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
18590 | && fixP->fx_addsy != NULL | |
18591 | && S_IS_DEFINED (fixP->fx_addsy) | |
18592 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 18593 | { |
c19d1205 | 18594 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 18595 | } |
c19d1205 ZW |
18596 | } |
18597 | #endif | |
6c43fab6 | 18598 | |
c19d1205 ZW |
18599 | int |
18600 | arm_force_relocation (struct fix * fixp) | |
18601 | { | |
18602 | #if defined (OBJ_COFF) && defined (TE_PE) | |
18603 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
18604 | return 1; | |
18605 | #endif | |
6c43fab6 | 18606 | |
c19d1205 ZW |
18607 | /* Resolve these relocations even if the symbol is extern or weak. */ |
18608 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
18609 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 PB |
18610 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
18611 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
18612 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
18613 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 18614 | return 0; |
a737bd4d | 18615 | |
4962c51a MS |
18616 | /* Always leave these relocations for the linker. */ |
18617 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
18618 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
18619 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
18620 | return 1; | |
18621 | ||
c19d1205 | 18622 | return generic_force_reloc (fixp); |
404ff6b5 AH |
18623 | } |
18624 | ||
c19d1205 | 18625 | #ifdef OBJ_COFF |
c19d1205 ZW |
18626 | bfd_boolean |
18627 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 18628 | { |
337ff0a5 NC |
18629 | /* This is a little hack to help the gas/arm/adrl.s test. It prevents |
18630 | local labels from being added to the output symbol table when they | |
18631 | are used with the ADRL pseudo op. The ADRL relocation should always | |
18632 | be resolved before the binbary is emitted, so it is safe to say that | |
18633 | it is adjustable. */ | |
c19d1205 ZW |
18634 | if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE) |
18635 | return 1; | |
337ff0a5 NC |
18636 | |
18637 | /* This is a hack for the gas/all/redef2.s test. This test causes symbols | |
18638 | to be cloned, and without this test relocs would still be generated | |
6e0080dd | 18639 | against the original, pre-cloned symbol. Such symbols would not appear |
337ff0a5 NC |
18640 | in the symbol table however, and so a valid reloc could not be |
18641 | generated. So check to see if the fixup is against a symbol which has | |
18642 | been removed from the symbol chain, and if it is, then allow it to be | |
18643 | adjusted into a reloc against a section symbol. */ | |
6e0080dd NC |
18644 | if (fixP->fx_addsy != NULL |
18645 | && ! S_IS_LOCAL (fixP->fx_addsy) | |
18646 | && symbol_next (fixP->fx_addsy) == NULL | |
18647 | && symbol_next (fixP->fx_addsy) == symbol_previous (fixP->fx_addsy)) | |
18648 | return 1; | |
337ff0a5 | 18649 | |
c19d1205 | 18650 | return 0; |
404ff6b5 | 18651 | } |
c19d1205 | 18652 | #endif |
404ff6b5 | 18653 | |
c19d1205 | 18654 | #ifdef OBJ_ELF |
e28387c3 PB |
18655 | /* Relocations against function names must be left unadjusted, |
18656 | so that the linker can use this information to generate interworking | |
18657 | stubs. The MIPS version of this function | |
c19d1205 ZW |
18658 | also prevents relocations that are mips-16 specific, but I do not |
18659 | know why it does this. | |
404ff6b5 | 18660 | |
c19d1205 ZW |
18661 | FIXME: |
18662 | There is one other problem that ought to be addressed here, but | |
18663 | which currently is not: Taking the address of a label (rather | |
18664 | than a function) and then later jumping to that address. Such | |
18665 | addresses also ought to have their bottom bit set (assuming that | |
18666 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 18667 | |
c19d1205 ZW |
18668 | bfd_boolean |
18669 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 18670 | { |
c19d1205 ZW |
18671 | if (fixP->fx_addsy == NULL) |
18672 | return 1; | |
404ff6b5 | 18673 | |
e28387c3 PB |
18674 | /* Preserve relocations against symbols with function type. */ |
18675 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
18676 | return 0; | |
18677 | ||
c19d1205 ZW |
18678 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
18679 | && fixP->fx_subsy == NULL) | |
18680 | return 0; | |
a737bd4d | 18681 | |
c19d1205 ZW |
18682 | /* We need the symbol name for the VTABLE entries. */ |
18683 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
18684 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
18685 | return 0; | |
404ff6b5 | 18686 | |
c19d1205 ZW |
18687 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
18688 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
18689 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
18690 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
18691 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
18692 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
18693 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
18694 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
18695 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
18696 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
18697 | return 0; | |
a737bd4d | 18698 | |
4962c51a MS |
18699 | /* Similarly for group relocations. */ |
18700 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
18701 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
18702 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
18703 | return 0; | |
18704 | ||
c19d1205 | 18705 | return 1; |
a737bd4d | 18706 | } |
404ff6b5 | 18707 | |
c19d1205 ZW |
18708 | const char * |
18709 | elf32_arm_target_format (void) | |
404ff6b5 | 18710 | { |
c19d1205 ZW |
18711 | #ifdef TE_SYMBIAN |
18712 | return (target_big_endian | |
18713 | ? "elf32-bigarm-symbian" | |
18714 | : "elf32-littlearm-symbian"); | |
18715 | #elif defined (TE_VXWORKS) | |
18716 | return (target_big_endian | |
18717 | ? "elf32-bigarm-vxworks" | |
18718 | : "elf32-littlearm-vxworks"); | |
18719 | #else | |
18720 | if (target_big_endian) | |
18721 | return "elf32-bigarm"; | |
18722 | else | |
18723 | return "elf32-littlearm"; | |
18724 | #endif | |
404ff6b5 AH |
18725 | } |
18726 | ||
c19d1205 ZW |
18727 | void |
18728 | armelf_frob_symbol (symbolS * symp, | |
18729 | int * puntp) | |
404ff6b5 | 18730 | { |
c19d1205 ZW |
18731 | elf_frob_symbol (symp, puntp); |
18732 | } | |
18733 | #endif | |
404ff6b5 | 18734 | |
c19d1205 | 18735 | /* MD interface: Finalization. */ |
a737bd4d | 18736 | |
c19d1205 ZW |
18737 | /* A good place to do this, although this was probably not intended |
18738 | for this kind of use. We need to dump the literal pool before | |
18739 | references are made to a null symbol pointer. */ | |
a737bd4d | 18740 | |
c19d1205 ZW |
18741 | void |
18742 | arm_cleanup (void) | |
18743 | { | |
18744 | literal_pool * pool; | |
a737bd4d | 18745 | |
c19d1205 ZW |
18746 | for (pool = list_of_pools; pool; pool = pool->next) |
18747 | { | |
18748 | /* Put it at the end of the relevent section. */ | |
18749 | subseg_set (pool->section, pool->sub_section); | |
18750 | #ifdef OBJ_ELF | |
18751 | arm_elf_change_section (); | |
18752 | #endif | |
18753 | s_ltorg (0); | |
18754 | } | |
404ff6b5 AH |
18755 | } |
18756 | ||
c19d1205 ZW |
18757 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
18758 | ARM ones. */ | |
404ff6b5 | 18759 | |
c19d1205 ZW |
18760 | void |
18761 | arm_adjust_symtab (void) | |
404ff6b5 | 18762 | { |
c19d1205 ZW |
18763 | #ifdef OBJ_COFF |
18764 | symbolS * sym; | |
404ff6b5 | 18765 | |
c19d1205 ZW |
18766 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
18767 | { | |
18768 | if (ARM_IS_THUMB (sym)) | |
18769 | { | |
18770 | if (THUMB_IS_FUNC (sym)) | |
18771 | { | |
18772 | /* Mark the symbol as a Thumb function. */ | |
18773 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
18774 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
18775 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 18776 | |
c19d1205 ZW |
18777 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
18778 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
18779 | else | |
18780 | as_bad (_("%s: unexpected function type: %d"), | |
18781 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
18782 | } | |
18783 | else switch (S_GET_STORAGE_CLASS (sym)) | |
18784 | { | |
18785 | case C_EXT: | |
18786 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
18787 | break; | |
18788 | case C_STAT: | |
18789 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
18790 | break; | |
18791 | case C_LABEL: | |
18792 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
18793 | break; | |
18794 | default: | |
18795 | /* Do nothing. */ | |
18796 | break; | |
18797 | } | |
18798 | } | |
a737bd4d | 18799 | |
c19d1205 ZW |
18800 | if (ARM_IS_INTERWORK (sym)) |
18801 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 18802 | } |
c19d1205 ZW |
18803 | #endif |
18804 | #ifdef OBJ_ELF | |
18805 | symbolS * sym; | |
18806 | char bind; | |
404ff6b5 | 18807 | |
c19d1205 | 18808 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 18809 | { |
c19d1205 ZW |
18810 | if (ARM_IS_THUMB (sym)) |
18811 | { | |
18812 | elf_symbol_type * elf_sym; | |
404ff6b5 | 18813 | |
c19d1205 ZW |
18814 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
18815 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 18816 | |
b0796911 PB |
18817 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
18818 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
18819 | { |
18820 | /* If it's a .thumb_func, declare it as so, | |
18821 | otherwise tag label as .code 16. */ | |
18822 | if (THUMB_IS_FUNC (sym)) | |
18823 | elf_sym->internal_elf_sym.st_info = | |
18824 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
18825 | else | |
18826 | elf_sym->internal_elf_sym.st_info = | |
18827 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
18828 | } | |
18829 | } | |
18830 | } | |
18831 | #endif | |
404ff6b5 AH |
18832 | } |
18833 | ||
c19d1205 | 18834 | /* MD interface: Initialization. */ |
404ff6b5 | 18835 | |
a737bd4d | 18836 | static void |
c19d1205 | 18837 | set_constant_flonums (void) |
a737bd4d | 18838 | { |
c19d1205 | 18839 | int i; |
404ff6b5 | 18840 | |
c19d1205 ZW |
18841 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
18842 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
18843 | abort (); | |
a737bd4d | 18844 | } |
404ff6b5 | 18845 | |
c19d1205 ZW |
18846 | void |
18847 | md_begin (void) | |
a737bd4d | 18848 | { |
c19d1205 ZW |
18849 | unsigned mach; |
18850 | unsigned int i; | |
404ff6b5 | 18851 | |
c19d1205 ZW |
18852 | if ( (arm_ops_hsh = hash_new ()) == NULL |
18853 | || (arm_cond_hsh = hash_new ()) == NULL | |
18854 | || (arm_shift_hsh = hash_new ()) == NULL | |
18855 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 18856 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 18857 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
18858 | || (arm_reloc_hsh = hash_new ()) == NULL |
18859 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
18860 | as_fatal (_("virtual memory exhausted")); |
18861 | ||
18862 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
18863 | hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i)); | |
18864 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) | |
18865 | hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i)); | |
18866 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) | |
18867 | hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i)); | |
18868 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) | |
18869 | hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i)); | |
62b3e311 PB |
18870 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
18871 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i)); | |
c19d1205 ZW |
18872 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
18873 | hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i)); | |
62b3e311 PB |
18874 | for (i = 0; |
18875 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
18876 | i++) | |
18877 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template, | |
18878 | (PTR) (barrier_opt_names + i)); | |
c19d1205 ZW |
18879 | #ifdef OBJ_ELF |
18880 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
18881 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i)); | |
18882 | #endif | |
18883 | ||
18884 | set_constant_flonums (); | |
404ff6b5 | 18885 | |
c19d1205 ZW |
18886 | /* Set the cpu variant based on the command-line options. We prefer |
18887 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
18888 | -mfpu= over any other way of setting the floating point unit. | |
18889 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 18890 | if (legacy_cpu) |
404ff6b5 | 18891 | { |
e74cfd16 | 18892 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
18893 | as_bad (_("use of old and new-style options to set CPU type")); |
18894 | ||
18895 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 18896 | } |
e74cfd16 | 18897 | else if (!mcpu_cpu_opt) |
c19d1205 | 18898 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 18899 | |
e74cfd16 | 18900 | if (legacy_fpu) |
c19d1205 | 18901 | { |
e74cfd16 | 18902 | if (mfpu_opt) |
c19d1205 | 18903 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
18904 | |
18905 | mfpu_opt = legacy_fpu; | |
18906 | } | |
e74cfd16 | 18907 | else if (!mfpu_opt) |
03b1477f | 18908 | { |
c19d1205 | 18909 | #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS)) |
39c2da32 RE |
18910 | /* Some environments specify a default FPU. If they don't, infer it |
18911 | from the processor. */ | |
e74cfd16 | 18912 | if (mcpu_fpu_opt) |
03b1477f RE |
18913 | mfpu_opt = mcpu_fpu_opt; |
18914 | else | |
18915 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 18916 | #else |
e74cfd16 | 18917 | mfpu_opt = &fpu_default; |
39c2da32 | 18918 | #endif |
03b1477f RE |
18919 | } |
18920 | ||
e74cfd16 | 18921 | if (!mfpu_opt) |
03b1477f | 18922 | { |
e74cfd16 PB |
18923 | if (!mcpu_cpu_opt) |
18924 | mfpu_opt = &fpu_default; | |
18925 | else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) | |
18926 | mfpu_opt = &fpu_arch_vfp_v2; | |
03b1477f | 18927 | else |
e74cfd16 | 18928 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
18929 | } |
18930 | ||
ee065d83 | 18931 | #ifdef CPU_DEFAULT |
e74cfd16 | 18932 | if (!mcpu_cpu_opt) |
ee065d83 | 18933 | { |
e74cfd16 PB |
18934 | mcpu_cpu_opt = &cpu_default; |
18935 | selected_cpu = cpu_default; | |
ee065d83 | 18936 | } |
e74cfd16 PB |
18937 | #else |
18938 | if (mcpu_cpu_opt) | |
18939 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 18940 | else |
e74cfd16 | 18941 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 18942 | #endif |
03b1477f | 18943 | |
e74cfd16 | 18944 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 18945 | |
e74cfd16 | 18946 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 18947 | |
f17c130b | 18948 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 18949 | { |
7cc69913 NC |
18950 | unsigned int flags = 0; |
18951 | ||
18952 | #if defined OBJ_ELF | |
18953 | flags = meabi_flags; | |
d507cf36 PB |
18954 | |
18955 | switch (meabi_flags) | |
33a392fb | 18956 | { |
d507cf36 | 18957 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 18958 | #endif |
d507cf36 PB |
18959 | /* Set the flags in the private structure. */ |
18960 | if (uses_apcs_26) flags |= F_APCS26; | |
18961 | if (support_interwork) flags |= F_INTERWORK; | |
18962 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 18963 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 18964 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
18965 | flags |= F_SOFT_FLOAT; |
18966 | ||
d507cf36 PB |
18967 | switch (mfloat_abi_opt) |
18968 | { | |
18969 | case ARM_FLOAT_ABI_SOFT: | |
18970 | case ARM_FLOAT_ABI_SOFTFP: | |
18971 | flags |= F_SOFT_FLOAT; | |
18972 | break; | |
33a392fb | 18973 | |
d507cf36 PB |
18974 | case ARM_FLOAT_ABI_HARD: |
18975 | if (flags & F_SOFT_FLOAT) | |
18976 | as_bad (_("hard-float conflicts with specified fpu")); | |
18977 | break; | |
18978 | } | |
03b1477f | 18979 | |
e74cfd16 PB |
18980 | /* Using pure-endian doubles (even if soft-float). */ |
18981 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 18982 | flags |= F_VFP_FLOAT; |
f17c130b | 18983 | |
fde78edd | 18984 | #if defined OBJ_ELF |
e74cfd16 | 18985 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 18986 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
18987 | break; |
18988 | ||
8cb51566 | 18989 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 18990 | case EF_ARM_EABI_VER5: |
c19d1205 | 18991 | /* No additional flags to set. */ |
d507cf36 PB |
18992 | break; |
18993 | ||
18994 | default: | |
18995 | abort (); | |
18996 | } | |
7cc69913 | 18997 | #endif |
b99bd4ef NC |
18998 | bfd_set_private_flags (stdoutput, flags); |
18999 | ||
19000 | /* We have run out flags in the COFF header to encode the | |
19001 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 19002 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
19003 | if (atpcs) |
19004 | { | |
19005 | asection * sec; | |
19006 | ||
19007 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
19008 | ||
19009 | if (sec != NULL) | |
19010 | { | |
19011 | bfd_set_section_flags | |
19012 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
19013 | bfd_set_section_size (stdoutput, sec, 0); | |
19014 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
19015 | } | |
19016 | } | |
7cc69913 | 19017 | } |
f17c130b | 19018 | #endif |
b99bd4ef NC |
19019 | |
19020 | /* Record the CPU type as well. */ | |
e74cfd16 | 19021 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) |
e16bb312 | 19022 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 19023 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 19024 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 19025 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 19026 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 19027 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 19028 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 19029 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 19030 | { |
e74cfd16 | 19031 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
19032 | mach = bfd_mach_arm_5T; |
19033 | else | |
19034 | mach = bfd_mach_arm_5; | |
19035 | } | |
e74cfd16 | 19036 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 19037 | { |
e74cfd16 | 19038 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
19039 | mach = bfd_mach_arm_4T; |
19040 | else | |
19041 | mach = bfd_mach_arm_4; | |
19042 | } | |
e74cfd16 | 19043 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 19044 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
19045 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
19046 | mach = bfd_mach_arm_3; | |
19047 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
19048 | mach = bfd_mach_arm_2a; | |
19049 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
19050 | mach = bfd_mach_arm_2; | |
19051 | else | |
19052 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
19053 | |
19054 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
19055 | } | |
19056 | ||
c19d1205 | 19057 | /* Command line processing. */ |
b99bd4ef | 19058 | |
c19d1205 ZW |
19059 | /* md_parse_option |
19060 | Invocation line includes a switch not recognized by the base assembler. | |
19061 | See if it's a processor-specific option. | |
b99bd4ef | 19062 | |
c19d1205 ZW |
19063 | This routine is somewhat complicated by the need for backwards |
19064 | compatibility (since older releases of gcc can't be changed). | |
19065 | The new options try to make the interface as compatible as | |
19066 | possible with GCC. | |
b99bd4ef | 19067 | |
c19d1205 | 19068 | New options (supported) are: |
b99bd4ef | 19069 | |
c19d1205 ZW |
19070 | -mcpu=<cpu name> Assemble for selected processor |
19071 | -march=<architecture name> Assemble for selected architecture | |
19072 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
19073 | -EB/-mbig-endian Big-endian | |
19074 | -EL/-mlittle-endian Little-endian | |
19075 | -k Generate PIC code | |
19076 | -mthumb Start in Thumb mode | |
19077 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 19078 | |
c19d1205 | 19079 | For now we will also provide support for: |
b99bd4ef | 19080 | |
c19d1205 ZW |
19081 | -mapcs-32 32-bit Program counter |
19082 | -mapcs-26 26-bit Program counter | |
19083 | -macps-float Floats passed in FP registers | |
19084 | -mapcs-reentrant Reentrant code | |
19085 | -matpcs | |
19086 | (sometime these will probably be replaced with -mapcs=<list of options> | |
19087 | and -matpcs=<list of options>) | |
b99bd4ef | 19088 | |
c19d1205 ZW |
19089 | The remaining options are only supported for back-wards compatibility. |
19090 | Cpu variants, the arm part is optional: | |
19091 | -m[arm]1 Currently not supported. | |
19092 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
19093 | -m[arm]3 Arm 3 processor | |
19094 | -m[arm]6[xx], Arm 6 processors | |
19095 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
19096 | -m[arm]8[10] Arm 8 processors | |
19097 | -m[arm]9[20][tdmi] Arm 9 processors | |
19098 | -mstrongarm[110[0]] StrongARM processors | |
19099 | -mxscale XScale processors | |
19100 | -m[arm]v[2345[t[e]]] Arm architectures | |
19101 | -mall All (except the ARM1) | |
19102 | FP variants: | |
19103 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
19104 | -mfpe-old (No float load/store multiples) | |
19105 | -mvfpxd VFP Single precision | |
19106 | -mvfp All VFP | |
19107 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 19108 | |
c19d1205 ZW |
19109 | The following CPU names are recognized: |
19110 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
19111 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
19112 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
19113 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
19114 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
19115 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
19116 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 19117 | |
c19d1205 | 19118 | */ |
b99bd4ef | 19119 | |
c19d1205 | 19120 | const char * md_shortopts = "m:k"; |
b99bd4ef | 19121 | |
c19d1205 ZW |
19122 | #ifdef ARM_BI_ENDIAN |
19123 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
19124 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 19125 | #else |
c19d1205 ZW |
19126 | #if TARGET_BYTES_BIG_ENDIAN |
19127 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 19128 | #else |
c19d1205 ZW |
19129 | #define OPTION_EL (OPTION_MD_BASE + 1) |
19130 | #endif | |
b99bd4ef | 19131 | #endif |
b99bd4ef | 19132 | |
c19d1205 | 19133 | struct option md_longopts[] = |
b99bd4ef | 19134 | { |
c19d1205 ZW |
19135 | #ifdef OPTION_EB |
19136 | {"EB", no_argument, NULL, OPTION_EB}, | |
19137 | #endif | |
19138 | #ifdef OPTION_EL | |
19139 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 19140 | #endif |
c19d1205 ZW |
19141 | {NULL, no_argument, NULL, 0} |
19142 | }; | |
b99bd4ef | 19143 | |
c19d1205 | 19144 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 19145 | |
c19d1205 | 19146 | struct arm_option_table |
b99bd4ef | 19147 | { |
c19d1205 ZW |
19148 | char *option; /* Option name to match. */ |
19149 | char *help; /* Help information. */ | |
19150 | int *var; /* Variable to change. */ | |
19151 | int value; /* What to change it to. */ | |
19152 | char *deprecated; /* If non-null, print this message. */ | |
19153 | }; | |
b99bd4ef | 19154 | |
c19d1205 ZW |
19155 | struct arm_option_table arm_opts[] = |
19156 | { | |
19157 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
19158 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
19159 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
19160 | &support_interwork, 1, NULL}, | |
19161 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
19162 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
19163 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
19164 | 1, NULL}, | |
19165 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
19166 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
19167 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
19168 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
19169 | NULL}, | |
b99bd4ef | 19170 | |
c19d1205 ZW |
19171 | /* These are recognized by the assembler, but have no affect on code. */ |
19172 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
19173 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
e74cfd16 PB |
19174 | {NULL, NULL, NULL, 0, NULL} |
19175 | }; | |
19176 | ||
19177 | struct arm_legacy_option_table | |
19178 | { | |
19179 | char *option; /* Option name to match. */ | |
19180 | const arm_feature_set **var; /* Variable to change. */ | |
19181 | const arm_feature_set value; /* What to change it to. */ | |
19182 | char *deprecated; /* If non-null, print this message. */ | |
19183 | }; | |
b99bd4ef | 19184 | |
e74cfd16 PB |
19185 | const struct arm_legacy_option_table arm_legacy_opts[] = |
19186 | { | |
c19d1205 ZW |
19187 | /* DON'T add any new processors to this list -- we want the whole list |
19188 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
19189 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
19190 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
19191 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
19192 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
19193 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
19194 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
19195 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
19196 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
19197 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
19198 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
19199 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
19200 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
19201 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
19202 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
19203 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
19204 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
19205 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
19206 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
19207 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
19208 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
19209 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
19210 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
19211 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
19212 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
19213 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
19214 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
19215 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
19216 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
19217 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
19218 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
19219 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
19220 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
19221 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
19222 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
19223 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
19224 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
19225 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
19226 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
19227 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
19228 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
19229 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
19230 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
19231 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
19232 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
19233 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
19234 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
19235 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19236 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19237 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19238 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19239 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
19240 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
19241 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
19242 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
19243 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
19244 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
19245 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
19246 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
19247 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
19248 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
19249 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
19250 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
19251 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
19252 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
19253 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
19254 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
19255 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
19256 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
19257 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
19258 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 19259 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 19260 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 19261 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 19262 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 19263 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
19264 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
19265 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
19266 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 19267 | |
c19d1205 | 19268 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
19269 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
19270 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
19271 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
19272 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
19273 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
19274 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
19275 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
19276 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
19277 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
19278 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
19279 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
19280 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
19281 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
19282 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
19283 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
19284 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
19285 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
19286 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 19287 | |
c19d1205 | 19288 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
19289 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
19290 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
19291 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
19292 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 19293 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 19294 | |
e74cfd16 | 19295 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 19296 | }; |
7ed4c4c5 | 19297 | |
c19d1205 | 19298 | struct arm_cpu_option_table |
7ed4c4c5 | 19299 | { |
c19d1205 | 19300 | char *name; |
e74cfd16 | 19301 | const arm_feature_set value; |
c19d1205 ZW |
19302 | /* For some CPUs we assume an FPU unless the user explicitly sets |
19303 | -mfpu=... */ | |
e74cfd16 | 19304 | const arm_feature_set default_fpu; |
ee065d83 PB |
19305 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
19306 | case. */ | |
19307 | const char *canonical_name; | |
c19d1205 | 19308 | }; |
7ed4c4c5 | 19309 | |
c19d1205 ZW |
19310 | /* This list should, at a minimum, contain all the cpu names |
19311 | recognized by GCC. */ | |
e74cfd16 | 19312 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 19313 | { |
ee065d83 PB |
19314 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
19315 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
19316 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
19317 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
19318 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
19319 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19320 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19321 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19322 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19323 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19324 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19325 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
19326 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19327 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
19328 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19329 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
19330 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19331 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19332 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19333 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19334 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19335 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19336 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19337 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19338 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19339 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19340 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19341 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19342 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19343 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19344 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19345 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19346 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19347 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19348 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19349 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19350 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19351 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19352 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19353 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
19354 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19355 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19356 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19357 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
19358 | /* For V5 or later processors we default to using VFP; but the user |
19359 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
19360 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
19361 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19362 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
19363 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
19364 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
19365 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
19366 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
19367 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19368 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
19369 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
19370 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19371 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19372 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
19373 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
19374 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19375 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
19376 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
19377 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19378 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19379 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
19380 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
19381 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, | |
19382 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
19383 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
19384 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
19385 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
19386 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
19387 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
19388 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
19389 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
19390 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
5287ad62 JB |
19391 | {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3 |
19392 | | FPU_NEON_EXT_V1), | |
19393 | NULL}, | |
62b3e311 PB |
19394 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, |
19395 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, | |
c19d1205 | 19396 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 19397 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 19398 | /* ??? iwmmxt is not a processor. */ |
ee065d83 PB |
19399 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
19400 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, | |
c19d1205 | 19401 | /* Maverick */ |
e74cfd16 PB |
19402 | {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
19403 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} | |
c19d1205 | 19404 | }; |
7ed4c4c5 | 19405 | |
c19d1205 | 19406 | struct arm_arch_option_table |
7ed4c4c5 | 19407 | { |
c19d1205 | 19408 | char *name; |
e74cfd16 PB |
19409 | const arm_feature_set value; |
19410 | const arm_feature_set default_fpu; | |
c19d1205 | 19411 | }; |
7ed4c4c5 | 19412 | |
c19d1205 ZW |
19413 | /* This list should, at a minimum, contain all the architecture names |
19414 | recognized by GCC. */ | |
e74cfd16 | 19415 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
19416 | { |
19417 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
19418 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
19419 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
19420 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
19421 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
19422 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
19423 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
19424 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
19425 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
19426 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
19427 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
19428 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
19429 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
19430 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
19431 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
19432 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
19433 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
19434 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
19435 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
19436 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
19437 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
19438 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
19439 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
19440 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
19441 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
19442 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
62b3e311 PB |
19443 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
19444 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, | |
19445 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
19446 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
19447 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
19448 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
e74cfd16 | 19449 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 19450 | }; |
7ed4c4c5 | 19451 | |
c19d1205 | 19452 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 19453 | struct arm_option_cpu_value_table |
c19d1205 ZW |
19454 | { |
19455 | char *name; | |
e74cfd16 | 19456 | const arm_feature_set value; |
c19d1205 | 19457 | }; |
7ed4c4c5 | 19458 | |
e74cfd16 | 19459 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 19460 | { |
e74cfd16 PB |
19461 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
19462 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
19463 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
19464 | {NULL, ARM_ARCH_NONE} | |
c19d1205 | 19465 | }; |
7ed4c4c5 | 19466 | |
c19d1205 ZW |
19467 | /* This list should, at a minimum, contain all the fpu names |
19468 | recognized by GCC. */ | |
e74cfd16 | 19469 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
19470 | { |
19471 | {"softfpa", FPU_NONE}, | |
19472 | {"fpe", FPU_ARCH_FPE}, | |
19473 | {"fpe2", FPU_ARCH_FPE}, | |
19474 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
19475 | {"fpa", FPU_ARCH_FPA}, | |
19476 | {"fpa10", FPU_ARCH_FPA}, | |
19477 | {"fpa11", FPU_ARCH_FPA}, | |
19478 | {"arm7500fe", FPU_ARCH_FPA}, | |
19479 | {"softvfp", FPU_ARCH_VFP}, | |
19480 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
19481 | {"vfp", FPU_ARCH_VFP_V2}, | |
19482 | {"vfp9", FPU_ARCH_VFP_V2}, | |
5287ad62 | 19483 | {"vfp3", FPU_ARCH_VFP_V3}, |
c19d1205 ZW |
19484 | {"vfp10", FPU_ARCH_VFP_V2}, |
19485 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
19486 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
19487 | {"arm1020t", FPU_ARCH_VFP_V1}, | |
19488 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
19489 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
19490 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
19491 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 19492 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
e74cfd16 PB |
19493 | {NULL, ARM_ARCH_NONE} |
19494 | }; | |
19495 | ||
19496 | struct arm_option_value_table | |
19497 | { | |
19498 | char *name; | |
19499 | long value; | |
c19d1205 | 19500 | }; |
7ed4c4c5 | 19501 | |
e74cfd16 | 19502 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
19503 | { |
19504 | {"hard", ARM_FLOAT_ABI_HARD}, | |
19505 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
19506 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 19507 | {NULL, 0} |
c19d1205 | 19508 | }; |
7ed4c4c5 | 19509 | |
c19d1205 | 19510 | #ifdef OBJ_ELF |
3a4a14e9 | 19511 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 19512 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
19513 | { |
19514 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
19515 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 19516 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 19517 | {NULL, 0} |
c19d1205 ZW |
19518 | }; |
19519 | #endif | |
7ed4c4c5 | 19520 | |
c19d1205 ZW |
19521 | struct arm_long_option_table |
19522 | { | |
19523 | char * option; /* Substring to match. */ | |
19524 | char * help; /* Help information. */ | |
19525 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
19526 | char * deprecated; /* If non-null, print this message. */ | |
19527 | }; | |
7ed4c4c5 NC |
19528 | |
19529 | static int | |
e74cfd16 | 19530 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 19531 | { |
e74cfd16 PB |
19532 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
19533 | ||
19534 | /* Copy the feature set, so that we can modify it. */ | |
19535 | *ext_set = **opt_p; | |
19536 | *opt_p = ext_set; | |
19537 | ||
c19d1205 | 19538 | while (str != NULL && *str != 0) |
7ed4c4c5 | 19539 | { |
e74cfd16 | 19540 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
19541 | char * ext; |
19542 | int optlen; | |
7ed4c4c5 | 19543 | |
c19d1205 ZW |
19544 | if (*str != '+') |
19545 | { | |
19546 | as_bad (_("invalid architectural extension")); | |
19547 | return 0; | |
19548 | } | |
7ed4c4c5 | 19549 | |
c19d1205 ZW |
19550 | str++; |
19551 | ext = strchr (str, '+'); | |
7ed4c4c5 | 19552 | |
c19d1205 ZW |
19553 | if (ext != NULL) |
19554 | optlen = ext - str; | |
19555 | else | |
19556 | optlen = strlen (str); | |
7ed4c4c5 | 19557 | |
c19d1205 ZW |
19558 | if (optlen == 0) |
19559 | { | |
19560 | as_bad (_("missing architectural extension")); | |
19561 | return 0; | |
19562 | } | |
7ed4c4c5 | 19563 | |
c19d1205 ZW |
19564 | for (opt = arm_extensions; opt->name != NULL; opt++) |
19565 | if (strncmp (opt->name, str, optlen) == 0) | |
19566 | { | |
e74cfd16 | 19567 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
19568 | break; |
19569 | } | |
7ed4c4c5 | 19570 | |
c19d1205 ZW |
19571 | if (opt->name == NULL) |
19572 | { | |
19573 | as_bad (_("unknown architectural extnsion `%s'"), str); | |
19574 | return 0; | |
19575 | } | |
7ed4c4c5 | 19576 | |
c19d1205 ZW |
19577 | str = ext; |
19578 | }; | |
7ed4c4c5 | 19579 | |
c19d1205 ZW |
19580 | return 1; |
19581 | } | |
7ed4c4c5 | 19582 | |
c19d1205 ZW |
19583 | static int |
19584 | arm_parse_cpu (char * str) | |
7ed4c4c5 | 19585 | { |
e74cfd16 | 19586 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
19587 | char * ext = strchr (str, '+'); |
19588 | int optlen; | |
7ed4c4c5 | 19589 | |
c19d1205 ZW |
19590 | if (ext != NULL) |
19591 | optlen = ext - str; | |
7ed4c4c5 | 19592 | else |
c19d1205 | 19593 | optlen = strlen (str); |
7ed4c4c5 | 19594 | |
c19d1205 | 19595 | if (optlen == 0) |
7ed4c4c5 | 19596 | { |
c19d1205 ZW |
19597 | as_bad (_("missing cpu name `%s'"), str); |
19598 | return 0; | |
7ed4c4c5 NC |
19599 | } |
19600 | ||
c19d1205 ZW |
19601 | for (opt = arm_cpus; opt->name != NULL; opt++) |
19602 | if (strncmp (opt->name, str, optlen) == 0) | |
19603 | { | |
e74cfd16 PB |
19604 | mcpu_cpu_opt = &opt->value; |
19605 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 PB |
19606 | if (opt->canonical_name) |
19607 | strcpy(selected_cpu_name, opt->canonical_name); | |
19608 | else | |
19609 | { | |
19610 | int i; | |
19611 | for (i = 0; i < optlen; i++) | |
19612 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
19613 | selected_cpu_name[i] = 0; | |
19614 | } | |
7ed4c4c5 | 19615 | |
c19d1205 ZW |
19616 | if (ext != NULL) |
19617 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 19618 | |
c19d1205 ZW |
19619 | return 1; |
19620 | } | |
7ed4c4c5 | 19621 | |
c19d1205 ZW |
19622 | as_bad (_("unknown cpu `%s'"), str); |
19623 | return 0; | |
7ed4c4c5 NC |
19624 | } |
19625 | ||
c19d1205 ZW |
19626 | static int |
19627 | arm_parse_arch (char * str) | |
7ed4c4c5 | 19628 | { |
e74cfd16 | 19629 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
19630 | char *ext = strchr (str, '+'); |
19631 | int optlen; | |
7ed4c4c5 | 19632 | |
c19d1205 ZW |
19633 | if (ext != NULL) |
19634 | optlen = ext - str; | |
7ed4c4c5 | 19635 | else |
c19d1205 | 19636 | optlen = strlen (str); |
7ed4c4c5 | 19637 | |
c19d1205 | 19638 | if (optlen == 0) |
7ed4c4c5 | 19639 | { |
c19d1205 ZW |
19640 | as_bad (_("missing architecture name `%s'"), str); |
19641 | return 0; | |
7ed4c4c5 NC |
19642 | } |
19643 | ||
c19d1205 ZW |
19644 | for (opt = arm_archs; opt->name != NULL; opt++) |
19645 | if (streq (opt->name, str)) | |
19646 | { | |
e74cfd16 PB |
19647 | march_cpu_opt = &opt->value; |
19648 | march_fpu_opt = &opt->default_fpu; | |
ee065d83 | 19649 | strcpy(selected_cpu_name, opt->name); |
7ed4c4c5 | 19650 | |
c19d1205 ZW |
19651 | if (ext != NULL) |
19652 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 19653 | |
c19d1205 ZW |
19654 | return 1; |
19655 | } | |
19656 | ||
19657 | as_bad (_("unknown architecture `%s'\n"), str); | |
19658 | return 0; | |
7ed4c4c5 | 19659 | } |
eb043451 | 19660 | |
c19d1205 ZW |
19661 | static int |
19662 | arm_parse_fpu (char * str) | |
19663 | { | |
e74cfd16 | 19664 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 19665 | |
c19d1205 ZW |
19666 | for (opt = arm_fpus; opt->name != NULL; opt++) |
19667 | if (streq (opt->name, str)) | |
19668 | { | |
e74cfd16 | 19669 | mfpu_opt = &opt->value; |
c19d1205 ZW |
19670 | return 1; |
19671 | } | |
b99bd4ef | 19672 | |
c19d1205 ZW |
19673 | as_bad (_("unknown floating point format `%s'\n"), str); |
19674 | return 0; | |
19675 | } | |
19676 | ||
19677 | static int | |
19678 | arm_parse_float_abi (char * str) | |
b99bd4ef | 19679 | { |
e74cfd16 | 19680 | const struct arm_option_value_table * opt; |
b99bd4ef | 19681 | |
c19d1205 ZW |
19682 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
19683 | if (streq (opt->name, str)) | |
19684 | { | |
19685 | mfloat_abi_opt = opt->value; | |
19686 | return 1; | |
19687 | } | |
cc8a6dd0 | 19688 | |
c19d1205 ZW |
19689 | as_bad (_("unknown floating point abi `%s'\n"), str); |
19690 | return 0; | |
19691 | } | |
b99bd4ef | 19692 | |
c19d1205 ZW |
19693 | #ifdef OBJ_ELF |
19694 | static int | |
19695 | arm_parse_eabi (char * str) | |
19696 | { | |
e74cfd16 | 19697 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 19698 | |
c19d1205 ZW |
19699 | for (opt = arm_eabis; opt->name != NULL; opt++) |
19700 | if (streq (opt->name, str)) | |
19701 | { | |
19702 | meabi_flags = opt->value; | |
19703 | return 1; | |
19704 | } | |
19705 | as_bad (_("unknown EABI `%s'\n"), str); | |
19706 | return 0; | |
19707 | } | |
19708 | #endif | |
cc8a6dd0 | 19709 | |
c19d1205 ZW |
19710 | struct arm_long_option_table arm_long_opts[] = |
19711 | { | |
19712 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
19713 | arm_parse_cpu, NULL}, | |
19714 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
19715 | arm_parse_arch, NULL}, | |
19716 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
19717 | arm_parse_fpu, NULL}, | |
19718 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
19719 | arm_parse_float_abi, NULL}, | |
19720 | #ifdef OBJ_ELF | |
19721 | {"meabi=", N_("<ver>\t assemble for eabi version <ver>"), | |
19722 | arm_parse_eabi, NULL}, | |
19723 | #endif | |
19724 | {NULL, NULL, 0, NULL} | |
19725 | }; | |
cc8a6dd0 | 19726 | |
c19d1205 ZW |
19727 | int |
19728 | md_parse_option (int c, char * arg) | |
19729 | { | |
19730 | struct arm_option_table *opt; | |
e74cfd16 | 19731 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 19732 | struct arm_long_option_table *lopt; |
b99bd4ef | 19733 | |
c19d1205 | 19734 | switch (c) |
b99bd4ef | 19735 | { |
c19d1205 ZW |
19736 | #ifdef OPTION_EB |
19737 | case OPTION_EB: | |
19738 | target_big_endian = 1; | |
19739 | break; | |
19740 | #endif | |
cc8a6dd0 | 19741 | |
c19d1205 ZW |
19742 | #ifdef OPTION_EL |
19743 | case OPTION_EL: | |
19744 | target_big_endian = 0; | |
19745 | break; | |
19746 | #endif | |
b99bd4ef | 19747 | |
c19d1205 ZW |
19748 | case 'a': |
19749 | /* Listing option. Just ignore these, we don't support additional | |
19750 | ones. */ | |
19751 | return 0; | |
b99bd4ef | 19752 | |
c19d1205 ZW |
19753 | default: |
19754 | for (opt = arm_opts; opt->option != NULL; opt++) | |
19755 | { | |
19756 | if (c == opt->option[0] | |
19757 | && ((arg == NULL && opt->option[1] == 0) | |
19758 | || streq (arg, opt->option + 1))) | |
19759 | { | |
19760 | #if WARN_DEPRECATED | |
19761 | /* If the option is deprecated, tell the user. */ | |
19762 | if (opt->deprecated != NULL) | |
19763 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
19764 | arg ? arg : "", _(opt->deprecated)); | |
19765 | #endif | |
b99bd4ef | 19766 | |
c19d1205 ZW |
19767 | if (opt->var != NULL) |
19768 | *opt->var = opt->value; | |
cc8a6dd0 | 19769 | |
c19d1205 ZW |
19770 | return 1; |
19771 | } | |
19772 | } | |
b99bd4ef | 19773 | |
e74cfd16 PB |
19774 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
19775 | { | |
19776 | if (c == fopt->option[0] | |
19777 | && ((arg == NULL && fopt->option[1] == 0) | |
19778 | || streq (arg, fopt->option + 1))) | |
19779 | { | |
19780 | #if WARN_DEPRECATED | |
19781 | /* If the option is deprecated, tell the user. */ | |
19782 | if (fopt->deprecated != NULL) | |
19783 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
19784 | arg ? arg : "", _(fopt->deprecated)); | |
19785 | #endif | |
19786 | ||
19787 | if (fopt->var != NULL) | |
19788 | *fopt->var = &fopt->value; | |
19789 | ||
19790 | return 1; | |
19791 | } | |
19792 | } | |
19793 | ||
c19d1205 ZW |
19794 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
19795 | { | |
19796 | /* These options are expected to have an argument. */ | |
19797 | if (c == lopt->option[0] | |
19798 | && arg != NULL | |
19799 | && strncmp (arg, lopt->option + 1, | |
19800 | strlen (lopt->option + 1)) == 0) | |
19801 | { | |
19802 | #if WARN_DEPRECATED | |
19803 | /* If the option is deprecated, tell the user. */ | |
19804 | if (lopt->deprecated != NULL) | |
19805 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, | |
19806 | _(lopt->deprecated)); | |
19807 | #endif | |
b99bd4ef | 19808 | |
c19d1205 ZW |
19809 | /* Call the sup-option parser. */ |
19810 | return lopt->func (arg + strlen (lopt->option) - 1); | |
19811 | } | |
19812 | } | |
a737bd4d | 19813 | |
c19d1205 ZW |
19814 | return 0; |
19815 | } | |
a394c00f | 19816 | |
c19d1205 ZW |
19817 | return 1; |
19818 | } | |
a394c00f | 19819 | |
c19d1205 ZW |
19820 | void |
19821 | md_show_usage (FILE * fp) | |
a394c00f | 19822 | { |
c19d1205 ZW |
19823 | struct arm_option_table *opt; |
19824 | struct arm_long_option_table *lopt; | |
a394c00f | 19825 | |
c19d1205 | 19826 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 19827 | |
c19d1205 ZW |
19828 | for (opt = arm_opts; opt->option != NULL; opt++) |
19829 | if (opt->help != NULL) | |
19830 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 19831 | |
c19d1205 ZW |
19832 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
19833 | if (lopt->help != NULL) | |
19834 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 19835 | |
c19d1205 ZW |
19836 | #ifdef OPTION_EB |
19837 | fprintf (fp, _("\ | |
19838 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
19839 | #endif |
19840 | ||
c19d1205 ZW |
19841 | #ifdef OPTION_EL |
19842 | fprintf (fp, _("\ | |
19843 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 19844 | #endif |
c19d1205 | 19845 | } |
ee065d83 PB |
19846 | |
19847 | ||
19848 | #ifdef OBJ_ELF | |
62b3e311 PB |
19849 | typedef struct |
19850 | { | |
19851 | int val; | |
19852 | arm_feature_set flags; | |
19853 | } cpu_arch_ver_table; | |
19854 | ||
19855 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
19856 | least features first. */ | |
19857 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
19858 | { | |
19859 | {1, ARM_ARCH_V4}, | |
19860 | {2, ARM_ARCH_V4T}, | |
19861 | {3, ARM_ARCH_V5}, | |
19862 | {4, ARM_ARCH_V5TE}, | |
19863 | {5, ARM_ARCH_V5TEJ}, | |
19864 | {6, ARM_ARCH_V6}, | |
19865 | {7, ARM_ARCH_V6Z}, | |
19866 | {8, ARM_ARCH_V6K}, | |
19867 | {9, ARM_ARCH_V6T2}, | |
19868 | {10, ARM_ARCH_V7A}, | |
19869 | {10, ARM_ARCH_V7R}, | |
19870 | {10, ARM_ARCH_V7M}, | |
19871 | {0, ARM_ARCH_NONE} | |
19872 | }; | |
19873 | ||
ee065d83 PB |
19874 | /* Set the public EABI object attributes. */ |
19875 | static void | |
19876 | aeabi_set_public_attributes (void) | |
19877 | { | |
19878 | int arch; | |
e74cfd16 | 19879 | arm_feature_set flags; |
62b3e311 PB |
19880 | arm_feature_set tmp; |
19881 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
19882 | |
19883 | /* Choose the architecture based on the capabilities of the requested cpu | |
19884 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
19885 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
19886 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
19887 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
5287ad62 | 19888 | |
62b3e311 PB |
19889 | tmp = flags; |
19890 | arch = 0; | |
19891 | for (p = cpu_arch_ver; p->val; p++) | |
19892 | { | |
19893 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
19894 | { | |
19895 | arch = p->val; | |
19896 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
19897 | } | |
19898 | } | |
ee065d83 PB |
19899 | |
19900 | /* Tag_CPU_name. */ | |
19901 | if (selected_cpu_name[0]) | |
19902 | { | |
19903 | char *p; | |
19904 | ||
19905 | p = selected_cpu_name; | |
19906 | if (strncmp(p, "armv", 4) == 0) | |
19907 | { | |
19908 | int i; | |
19909 | ||
19910 | p += 4; | |
19911 | for (i = 0; p[i]; i++) | |
19912 | p[i] = TOUPPER (p[i]); | |
19913 | } | |
19914 | elf32_arm_add_eabi_attr_string (stdoutput, 5, p); | |
19915 | } | |
19916 | /* Tag_CPU_arch. */ | |
19917 | elf32_arm_add_eabi_attr_int (stdoutput, 6, arch); | |
62b3e311 PB |
19918 | /* Tag_CPU_arch_profile. */ |
19919 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
19920 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A'); | |
19921 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) | |
19922 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R'); | |
19923 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)) | |
19924 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M'); | |
ee065d83 | 19925 | /* Tag_ARM_ISA_use. */ |
e74cfd16 | 19926 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full)) |
ee065d83 PB |
19927 | elf32_arm_add_eabi_attr_int (stdoutput, 8, 1); |
19928 | /* Tag_THUMB_ISA_use. */ | |
e74cfd16 | 19929 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full)) |
ee065d83 | 19930 | elf32_arm_add_eabi_attr_int (stdoutput, 9, |
e74cfd16 | 19931 | ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1); |
ee065d83 | 19932 | /* Tag_VFP_arch. */ |
5287ad62 JB |
19933 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3) |
19934 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3)) | |
19935 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 3); | |
19936 | else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2) | |
19937 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2)) | |
ee065d83 | 19938 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 2); |
5287ad62 JB |
19939 | else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1) |
19940 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1) | |
19941 | || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd) | |
19942 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd)) | |
ee065d83 PB |
19943 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 1); |
19944 | /* Tag_WMMX_arch. */ | |
e74cfd16 PB |
19945 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt) |
19946 | || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt)) | |
ee065d83 | 19947 | elf32_arm_add_eabi_attr_int (stdoutput, 11, 1); |
5287ad62 JB |
19948 | /* Tag_NEON_arch. */ |
19949 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1) | |
19950 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1)) | |
19951 | elf32_arm_add_eabi_attr_int (stdoutput, 12, 1); | |
ee065d83 PB |
19952 | } |
19953 | ||
19954 | /* Add the .ARM.attributes section. */ | |
19955 | void | |
19956 | arm_md_end (void) | |
19957 | { | |
19958 | segT s; | |
19959 | char *p; | |
19960 | addressT addr; | |
19961 | offsetT size; | |
19962 | ||
19963 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) | |
19964 | return; | |
19965 | ||
19966 | aeabi_set_public_attributes (); | |
19967 | size = elf32_arm_eabi_attr_size (stdoutput); | |
19968 | s = subseg_new (".ARM.attributes", 0); | |
19969 | bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA); | |
19970 | addr = frag_now_fix (); | |
19971 | p = frag_more (size); | |
19972 | elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size); | |
19973 | } | |
8463be01 | 19974 | #endif /* OBJ_ELF */ |
ee065d83 PB |
19975 | |
19976 | ||
19977 | /* Parse a .cpu directive. */ | |
19978 | ||
19979 | static void | |
19980 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
19981 | { | |
e74cfd16 | 19982 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
19983 | char *name; |
19984 | char saved_char; | |
19985 | ||
19986 | name = input_line_pointer; | |
19987 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
19988 | input_line_pointer++; | |
19989 | saved_char = *input_line_pointer; | |
19990 | *input_line_pointer = 0; | |
19991 | ||
19992 | /* Skip the first "all" entry. */ | |
19993 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
19994 | if (streq (opt->name, name)) | |
19995 | { | |
e74cfd16 PB |
19996 | mcpu_cpu_opt = &opt->value; |
19997 | selected_cpu = opt->value; | |
ee065d83 PB |
19998 | if (opt->canonical_name) |
19999 | strcpy(selected_cpu_name, opt->canonical_name); | |
20000 | else | |
20001 | { | |
20002 | int i; | |
20003 | for (i = 0; opt->name[i]; i++) | |
20004 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
20005 | selected_cpu_name[i] = 0; | |
20006 | } | |
e74cfd16 | 20007 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
20008 | *input_line_pointer = saved_char; |
20009 | demand_empty_rest_of_line (); | |
20010 | return; | |
20011 | } | |
20012 | as_bad (_("unknown cpu `%s'"), name); | |
20013 | *input_line_pointer = saved_char; | |
20014 | ignore_rest_of_line (); | |
20015 | } | |
20016 | ||
20017 | ||
20018 | /* Parse a .arch directive. */ | |
20019 | ||
20020 | static void | |
20021 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
20022 | { | |
e74cfd16 | 20023 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
20024 | char saved_char; |
20025 | char *name; | |
20026 | ||
20027 | name = input_line_pointer; | |
20028 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
20029 | input_line_pointer++; | |
20030 | saved_char = *input_line_pointer; | |
20031 | *input_line_pointer = 0; | |
20032 | ||
20033 | /* Skip the first "all" entry. */ | |
20034 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
20035 | if (streq (opt->name, name)) | |
20036 | { | |
e74cfd16 PB |
20037 | mcpu_cpu_opt = &opt->value; |
20038 | selected_cpu = opt->value; | |
ee065d83 | 20039 | strcpy(selected_cpu_name, opt->name); |
e74cfd16 | 20040 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
20041 | *input_line_pointer = saved_char; |
20042 | demand_empty_rest_of_line (); | |
20043 | return; | |
20044 | } | |
20045 | ||
20046 | as_bad (_("unknown architecture `%s'\n"), name); | |
20047 | *input_line_pointer = saved_char; | |
20048 | ignore_rest_of_line (); | |
20049 | } | |
20050 | ||
20051 | ||
20052 | /* Parse a .fpu directive. */ | |
20053 | ||
20054 | static void | |
20055 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
20056 | { | |
e74cfd16 | 20057 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
20058 | char saved_char; |
20059 | char *name; | |
20060 | ||
20061 | name = input_line_pointer; | |
20062 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
20063 | input_line_pointer++; | |
20064 | saved_char = *input_line_pointer; | |
20065 | *input_line_pointer = 0; | |
20066 | ||
20067 | for (opt = arm_fpus; opt->name != NULL; opt++) | |
20068 | if (streq (opt->name, name)) | |
20069 | { | |
e74cfd16 PB |
20070 | mfpu_opt = &opt->value; |
20071 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
20072 | *input_line_pointer = saved_char; |
20073 | demand_empty_rest_of_line (); | |
20074 | return; | |
20075 | } | |
20076 | ||
20077 | as_bad (_("unknown floating point format `%s'\n"), name); | |
20078 | *input_line_pointer = saved_char; | |
20079 | ignore_rest_of_line (); | |
20080 | } | |
ee065d83 | 20081 |