]>
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" | |
a394c00f | 40 | #include "dw2gencfi.h" |
b99bd4ef NC |
41 | #endif |
42 | ||
f0927246 NC |
43 | #include "dwarf2dbg.h" |
44 | ||
720abc60 | 45 | #define WARN_DEPRECATED 1 |
03b1477f | 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 | ||
2d447fca JM |
204 | static const arm_feature_set arm_cext_iwmmxt2 = |
205 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2); | |
e74cfd16 PB |
206 | static const arm_feature_set arm_cext_iwmmxt = |
207 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
208 | static const arm_feature_set arm_cext_xscale = | |
209 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
210 | static const arm_feature_set arm_cext_maverick = | |
211 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
212 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
213 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
214 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
215 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
216 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
217 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
5287ad62 JB |
218 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
219 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); | |
220 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
221 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
e74cfd16 | 222 | |
33a392fb | 223 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
224 | /* Record user cpu selection for object attributes. */ |
225 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
226 | /* Must be long enough to hold any of the names in arm_cpus. */ |
227 | static char selected_cpu_name[16]; | |
7cc69913 | 228 | #ifdef OBJ_ELF |
deeaaff8 DJ |
229 | # ifdef EABI_DEFAULT |
230 | static int meabi_flags = EABI_DEFAULT; | |
231 | # else | |
d507cf36 | 232 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 233 | # endif |
7cc69913 | 234 | #endif |
b99bd4ef | 235 | |
b99bd4ef | 236 | #ifdef OBJ_ELF |
c19d1205 | 237 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
238 | symbolS * GOT_symbol; |
239 | #endif | |
240 | ||
b99bd4ef NC |
241 | /* 0: assemble for ARM, |
242 | 1: assemble for Thumb, | |
243 | 2: assemble for Thumb even though target CPU does not support thumb | |
244 | instructions. */ | |
245 | static int thumb_mode = 0; | |
246 | ||
c19d1205 ZW |
247 | /* If unified_syntax is true, we are processing the new unified |
248 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
249 | ||
250 | - Immediate operands do not require a # prefix. | |
251 | - Conditional affixes always appear at the end of the | |
252 | instruction. (For backward compatibility, those instructions | |
253 | that formerly had them in the middle, continue to accept them | |
254 | there.) | |
255 | - The IT instruction may appear, and if it does is validated | |
256 | against subsequent conditional affixes. It does not generate | |
257 | machine code. | |
258 | ||
259 | Important differences from the old Thumb mode: | |
260 | ||
261 | - Immediate operands do not require a # prefix. | |
262 | - Most of the V6T2 instructions are only available in unified mode. | |
263 | - The .N and .W suffixes are recognized and honored (it is an error | |
264 | if they cannot be honored). | |
265 | - All instructions set the flags if and only if they have an 's' affix. | |
266 | - Conditional affixes may be used. They are validated against | |
267 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
268 | conditional affix except in the scope of an IT instruction. */ | |
269 | ||
270 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 271 | |
5287ad62 JB |
272 | enum neon_el_type |
273 | { | |
dcbf9037 | 274 | NT_invtype, |
5287ad62 JB |
275 | NT_untyped, |
276 | NT_integer, | |
277 | NT_float, | |
278 | NT_poly, | |
279 | NT_signed, | |
dcbf9037 | 280 | NT_unsigned |
5287ad62 JB |
281 | }; |
282 | ||
283 | struct neon_type_el | |
284 | { | |
285 | enum neon_el_type type; | |
286 | unsigned size; | |
287 | }; | |
288 | ||
289 | #define NEON_MAX_TYPE_ELS 4 | |
290 | ||
291 | struct neon_type | |
292 | { | |
293 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
294 | unsigned elems; | |
295 | }; | |
296 | ||
b99bd4ef NC |
297 | struct arm_it |
298 | { | |
c19d1205 | 299 | const char * error; |
b99bd4ef | 300 | unsigned long instruction; |
c19d1205 ZW |
301 | int size; |
302 | int size_req; | |
303 | int cond; | |
037e8744 JB |
304 | /* "uncond_value" is set to the value in place of the conditional field in |
305 | unconditional versions of the instruction, or -1 if nothing is | |
306 | appropriate. */ | |
307 | int uncond_value; | |
5287ad62 | 308 | struct neon_type vectype; |
0110f2b8 PB |
309 | /* Set to the opcode if the instruction needs relaxation. |
310 | Zero if the instruction is not relaxed. */ | |
311 | unsigned long relax; | |
b99bd4ef NC |
312 | struct |
313 | { | |
314 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
315 | expressionS exp; |
316 | int pc_rel; | |
b99bd4ef | 317 | } reloc; |
b99bd4ef | 318 | |
c19d1205 ZW |
319 | struct |
320 | { | |
321 | unsigned reg; | |
ca3f61f7 | 322 | signed int imm; |
dcbf9037 | 323 | struct neon_type_el vectype; |
ca3f61f7 NC |
324 | unsigned present : 1; /* Operand present. */ |
325 | unsigned isreg : 1; /* Operand was a register. */ | |
326 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
327 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
328 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
329 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV | |
330 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
331 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 332 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 333 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 334 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
335 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
336 | unsigned writeback : 1; /* Operand has trailing ! */ | |
337 | unsigned preind : 1; /* Preindexed address. */ | |
338 | unsigned postind : 1; /* Postindexed address. */ | |
339 | unsigned negative : 1; /* Index register was negated. */ | |
340 | unsigned shifted : 1; /* Shift applied to operation. */ | |
341 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 342 | } operands[6]; |
b99bd4ef NC |
343 | }; |
344 | ||
c19d1205 | 345 | static struct arm_it inst; |
b99bd4ef NC |
346 | |
347 | #define NUM_FLOAT_VALS 8 | |
348 | ||
05d2d07e | 349 | const char * fp_const[] = |
b99bd4ef NC |
350 | { |
351 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
352 | }; | |
353 | ||
c19d1205 | 354 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
355 | #define MAX_LITTLENUMS 6 |
356 | ||
357 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
358 | ||
359 | #define FAIL (-1) | |
360 | #define SUCCESS (0) | |
361 | ||
362 | #define SUFF_S 1 | |
363 | #define SUFF_D 2 | |
364 | #define SUFF_E 3 | |
365 | #define SUFF_P 4 | |
366 | ||
c19d1205 ZW |
367 | #define CP_T_X 0x00008000 |
368 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 369 | |
c19d1205 ZW |
370 | #define CONDS_BIT 0x00100000 |
371 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
372 | |
373 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
374 | ||
375 | struct asm_cond | |
376 | { | |
c19d1205 | 377 | const char * template; |
b99bd4ef NC |
378 | unsigned long value; |
379 | }; | |
380 | ||
c19d1205 | 381 | #define COND_ALWAYS 0xE |
b99bd4ef | 382 | |
b99bd4ef NC |
383 | struct asm_psr |
384 | { | |
b34976b6 | 385 | const char *template; |
b99bd4ef NC |
386 | unsigned long field; |
387 | }; | |
388 | ||
62b3e311 PB |
389 | struct asm_barrier_opt |
390 | { | |
391 | const char *template; | |
392 | unsigned long value; | |
393 | }; | |
394 | ||
2d2255b5 | 395 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
396 | #define SPSR_BIT (1 << 22) |
397 | ||
c19d1205 ZW |
398 | /* The individual PSR flag bits. */ |
399 | #define PSR_c (1 << 16) | |
400 | #define PSR_x (1 << 17) | |
401 | #define PSR_s (1 << 18) | |
402 | #define PSR_f (1 << 19) | |
b99bd4ef | 403 | |
c19d1205 | 404 | struct reloc_entry |
bfae80f2 | 405 | { |
c19d1205 ZW |
406 | char *name; |
407 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
408 | }; |
409 | ||
5287ad62 | 410 | enum vfp_reg_pos |
bfae80f2 | 411 | { |
5287ad62 JB |
412 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
413 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
414 | }; |
415 | ||
416 | enum vfp_ldstm_type | |
417 | { | |
418 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
419 | }; | |
420 | ||
dcbf9037 JB |
421 | /* Bits for DEFINED field in neon_typed_alias. */ |
422 | #define NTA_HASTYPE 1 | |
423 | #define NTA_HASINDEX 2 | |
424 | ||
425 | struct neon_typed_alias | |
426 | { | |
427 | unsigned char defined; | |
428 | unsigned char index; | |
429 | struct neon_type_el eltype; | |
430 | }; | |
431 | ||
c19d1205 ZW |
432 | /* ARM register categories. This includes coprocessor numbers and various |
433 | architecture extensions' registers. */ | |
434 | enum arm_reg_type | |
bfae80f2 | 435 | { |
c19d1205 ZW |
436 | REG_TYPE_RN, |
437 | REG_TYPE_CP, | |
438 | REG_TYPE_CN, | |
439 | REG_TYPE_FN, | |
440 | REG_TYPE_VFS, | |
441 | REG_TYPE_VFD, | |
5287ad62 | 442 | REG_TYPE_NQ, |
037e8744 | 443 | REG_TYPE_VFSD, |
5287ad62 | 444 | REG_TYPE_NDQ, |
037e8744 | 445 | REG_TYPE_NSDQ, |
c19d1205 ZW |
446 | REG_TYPE_VFC, |
447 | REG_TYPE_MVF, | |
448 | REG_TYPE_MVD, | |
449 | REG_TYPE_MVFX, | |
450 | REG_TYPE_MVDX, | |
451 | REG_TYPE_MVAX, | |
452 | REG_TYPE_DSPSC, | |
453 | REG_TYPE_MMXWR, | |
454 | REG_TYPE_MMXWC, | |
455 | REG_TYPE_MMXWCG, | |
456 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
457 | }; |
458 | ||
dcbf9037 JB |
459 | /* Structure for a hash table entry for a register. |
460 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
461 | information which states whether a vector type or index is specified (for a | |
462 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
463 | struct reg_entry |
464 | { | |
dcbf9037 JB |
465 | const char *name; |
466 | unsigned char number; | |
467 | unsigned char type; | |
468 | unsigned char builtin; | |
469 | struct neon_typed_alias *neon; | |
6c43fab6 RE |
470 | }; |
471 | ||
c19d1205 ZW |
472 | /* Diagnostics used when we don't get a register of the expected type. */ |
473 | const char *const reg_expected_msgs[] = | |
474 | { | |
475 | N_("ARM register expected"), | |
476 | N_("bad or missing co-processor number"), | |
477 | N_("co-processor register expected"), | |
478 | N_("FPA register expected"), | |
479 | N_("VFP single precision register expected"), | |
5287ad62 JB |
480 | N_("VFP/Neon double precision register expected"), |
481 | N_("Neon quad precision register expected"), | |
037e8744 | 482 | N_("VFP single or double precision register expected"), |
5287ad62 | 483 | N_("Neon double or quad precision register expected"), |
037e8744 | 484 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
485 | N_("VFP system register expected"), |
486 | N_("Maverick MVF register expected"), | |
487 | N_("Maverick MVD register expected"), | |
488 | N_("Maverick MVFX register expected"), | |
489 | N_("Maverick MVDX register expected"), | |
490 | N_("Maverick MVAX register expected"), | |
491 | N_("Maverick DSPSC register expected"), | |
492 | N_("iWMMXt data register expected"), | |
493 | N_("iWMMXt control register expected"), | |
494 | N_("iWMMXt scalar register expected"), | |
495 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
496 | }; |
497 | ||
c19d1205 ZW |
498 | /* Some well known registers that we refer to directly elsewhere. */ |
499 | #define REG_SP 13 | |
500 | #define REG_LR 14 | |
501 | #define REG_PC 15 | |
404ff6b5 | 502 | |
b99bd4ef NC |
503 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
504 | take 2: */ | |
c19d1205 | 505 | #define INSN_SIZE 4 |
b99bd4ef NC |
506 | |
507 | struct asm_opcode | |
508 | { | |
509 | /* Basic string to match. */ | |
c19d1205 ZW |
510 | const char *template; |
511 | ||
512 | /* Parameters to instruction. */ | |
513 | unsigned char operands[8]; | |
514 | ||
515 | /* Conditional tag - see opcode_lookup. */ | |
516 | unsigned int tag : 4; | |
b99bd4ef NC |
517 | |
518 | /* Basic instruction code. */ | |
c19d1205 | 519 | unsigned int avalue : 28; |
b99bd4ef | 520 | |
c19d1205 ZW |
521 | /* Thumb-format instruction code. */ |
522 | unsigned int tvalue; | |
b99bd4ef | 523 | |
90e4755a | 524 | /* Which architecture variant provides this instruction. */ |
e74cfd16 PB |
525 | const arm_feature_set *avariant; |
526 | const arm_feature_set *tvariant; | |
c19d1205 ZW |
527 | |
528 | /* Function to call to encode instruction in ARM format. */ | |
529 | void (* aencode) (void); | |
b99bd4ef | 530 | |
c19d1205 ZW |
531 | /* Function to call to encode instruction in Thumb format. */ |
532 | void (* tencode) (void); | |
b99bd4ef NC |
533 | }; |
534 | ||
a737bd4d NC |
535 | /* Defines for various bits that we will want to toggle. */ |
536 | #define INST_IMMEDIATE 0x02000000 | |
537 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 538 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
539 | #define SHIFT_BY_REG 0x00000010 |
540 | #define PRE_INDEX 0x01000000 | |
541 | #define INDEX_UP 0x00800000 | |
542 | #define WRITE_BACK 0x00200000 | |
543 | #define LDM_TYPE_2_OR_3 0x00400000 | |
90e4755a | 544 | |
a737bd4d NC |
545 | #define LITERAL_MASK 0xf000f000 |
546 | #define OPCODE_MASK 0xfe1fffff | |
547 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 548 | |
a737bd4d | 549 | #define DATA_OP_SHIFT 21 |
90e4755a | 550 | |
ef8d22e6 PB |
551 | #define T2_OPCODE_MASK 0xfe1fffff |
552 | #define T2_DATA_OP_SHIFT 21 | |
553 | ||
a737bd4d NC |
554 | /* Codes to distinguish the arithmetic instructions. */ |
555 | #define OPCODE_AND 0 | |
556 | #define OPCODE_EOR 1 | |
557 | #define OPCODE_SUB 2 | |
558 | #define OPCODE_RSB 3 | |
559 | #define OPCODE_ADD 4 | |
560 | #define OPCODE_ADC 5 | |
561 | #define OPCODE_SBC 6 | |
562 | #define OPCODE_RSC 7 | |
563 | #define OPCODE_TST 8 | |
564 | #define OPCODE_TEQ 9 | |
565 | #define OPCODE_CMP 10 | |
566 | #define OPCODE_CMN 11 | |
567 | #define OPCODE_ORR 12 | |
568 | #define OPCODE_MOV 13 | |
569 | #define OPCODE_BIC 14 | |
570 | #define OPCODE_MVN 15 | |
90e4755a | 571 | |
ef8d22e6 PB |
572 | #define T2_OPCODE_AND 0 |
573 | #define T2_OPCODE_BIC 1 | |
574 | #define T2_OPCODE_ORR 2 | |
575 | #define T2_OPCODE_ORN 3 | |
576 | #define T2_OPCODE_EOR 4 | |
577 | #define T2_OPCODE_ADD 8 | |
578 | #define T2_OPCODE_ADC 10 | |
579 | #define T2_OPCODE_SBC 11 | |
580 | #define T2_OPCODE_SUB 13 | |
581 | #define T2_OPCODE_RSB 14 | |
582 | ||
a737bd4d NC |
583 | #define T_OPCODE_MUL 0x4340 |
584 | #define T_OPCODE_TST 0x4200 | |
585 | #define T_OPCODE_CMN 0x42c0 | |
586 | #define T_OPCODE_NEG 0x4240 | |
587 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 588 | |
a737bd4d NC |
589 | #define T_OPCODE_ADD_R3 0x1800 |
590 | #define T_OPCODE_SUB_R3 0x1a00 | |
591 | #define T_OPCODE_ADD_HI 0x4400 | |
592 | #define T_OPCODE_ADD_ST 0xb000 | |
593 | #define T_OPCODE_SUB_ST 0xb080 | |
594 | #define T_OPCODE_ADD_SP 0xa800 | |
595 | #define T_OPCODE_ADD_PC 0xa000 | |
596 | #define T_OPCODE_ADD_I8 0x3000 | |
597 | #define T_OPCODE_SUB_I8 0x3800 | |
598 | #define T_OPCODE_ADD_I3 0x1c00 | |
599 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 600 | |
a737bd4d NC |
601 | #define T_OPCODE_ASR_R 0x4100 |
602 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
603 | #define T_OPCODE_LSR_R 0x40c0 |
604 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
605 | #define T_OPCODE_ASR_I 0x1000 |
606 | #define T_OPCODE_LSL_I 0x0000 | |
607 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 608 | |
a737bd4d NC |
609 | #define T_OPCODE_MOV_I8 0x2000 |
610 | #define T_OPCODE_CMP_I8 0x2800 | |
611 | #define T_OPCODE_CMP_LR 0x4280 | |
612 | #define T_OPCODE_MOV_HR 0x4600 | |
613 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 614 | |
a737bd4d NC |
615 | #define T_OPCODE_LDR_PC 0x4800 |
616 | #define T_OPCODE_LDR_SP 0x9800 | |
617 | #define T_OPCODE_STR_SP 0x9000 | |
618 | #define T_OPCODE_LDR_IW 0x6800 | |
619 | #define T_OPCODE_STR_IW 0x6000 | |
620 | #define T_OPCODE_LDR_IH 0x8800 | |
621 | #define T_OPCODE_STR_IH 0x8000 | |
622 | #define T_OPCODE_LDR_IB 0x7800 | |
623 | #define T_OPCODE_STR_IB 0x7000 | |
624 | #define T_OPCODE_LDR_RW 0x5800 | |
625 | #define T_OPCODE_STR_RW 0x5000 | |
626 | #define T_OPCODE_LDR_RH 0x5a00 | |
627 | #define T_OPCODE_STR_RH 0x5200 | |
628 | #define T_OPCODE_LDR_RB 0x5c00 | |
629 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 630 | |
a737bd4d NC |
631 | #define T_OPCODE_PUSH 0xb400 |
632 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 633 | |
2fc8bdac | 634 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 635 | |
a737bd4d | 636 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 637 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 638 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 639 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
640 | |
641 | #define BAD_ARGS _("bad arguments to instruction") | |
642 | #define BAD_PC _("r15 not allowed here") | |
643 | #define BAD_COND _("instruction cannot be conditional") | |
644 | #define BAD_OVERLAP _("registers may not be the same") | |
645 | #define BAD_HIREG _("lo register required") | |
646 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 647 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
648 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
649 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 650 | #define BAD_FPU _("selected FPU does not support instruction") |
c19d1205 ZW |
651 | |
652 | static struct hash_control *arm_ops_hsh; | |
653 | static struct hash_control *arm_cond_hsh; | |
654 | static struct hash_control *arm_shift_hsh; | |
655 | static struct hash_control *arm_psr_hsh; | |
62b3e311 | 656 | static struct hash_control *arm_v7m_psr_hsh; |
c19d1205 ZW |
657 | static struct hash_control *arm_reg_hsh; |
658 | static struct hash_control *arm_reloc_hsh; | |
62b3e311 | 659 | static struct hash_control *arm_barrier_opt_hsh; |
b99bd4ef | 660 | |
b99bd4ef NC |
661 | /* Stuff needed to resolve the label ambiguity |
662 | As: | |
663 | ... | |
664 | label: <insn> | |
665 | may differ from: | |
666 | ... | |
667 | label: | |
c19d1205 | 668 | <insn> |
b99bd4ef NC |
669 | */ |
670 | ||
671 | symbolS * last_label_seen; | |
b34976b6 | 672 | static int label_is_thumb_function_name = FALSE; |
a737bd4d | 673 | \f |
3d0c9500 NC |
674 | /* Literal pool structure. Held on a per-section |
675 | and per-sub-section basis. */ | |
a737bd4d | 676 | |
c19d1205 | 677 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 678 | typedef struct literal_pool |
b99bd4ef | 679 | { |
c19d1205 ZW |
680 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
681 | unsigned int next_free_entry; | |
682 | unsigned int id; | |
683 | symbolS * symbol; | |
684 | segT section; | |
685 | subsegT sub_section; | |
61b5f74b | 686 | struct literal_pool * next; |
3d0c9500 | 687 | } literal_pool; |
b99bd4ef | 688 | |
3d0c9500 NC |
689 | /* Pointer to a linked list of literal pools. */ |
690 | literal_pool * list_of_pools = NULL; | |
e27ec89e PB |
691 | |
692 | /* State variables for IT block handling. */ | |
693 | static bfd_boolean current_it_mask = 0; | |
694 | static int current_cc; | |
695 | ||
c19d1205 ZW |
696 | \f |
697 | /* Pure syntax. */ | |
b99bd4ef | 698 | |
c19d1205 ZW |
699 | /* This array holds the chars that always start a comment. If the |
700 | pre-processor is disabled, these aren't very useful. */ | |
701 | const char comment_chars[] = "@"; | |
3d0c9500 | 702 | |
c19d1205 ZW |
703 | /* This array holds the chars that only start a comment at the beginning of |
704 | a line. If the line seems to have the form '# 123 filename' | |
705 | .line and .file directives will appear in the pre-processed output. */ | |
706 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
707 | first line of the input file. This is because the compiler outputs | |
708 | #NO_APP at the beginning of its output. */ | |
709 | /* Also note that comments like this one will always work. */ | |
710 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 711 | |
c19d1205 | 712 | const char line_separator_chars[] = ";"; |
b99bd4ef | 713 | |
c19d1205 ZW |
714 | /* Chars that can be used to separate mant |
715 | from exp in floating point numbers. */ | |
716 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 717 | |
c19d1205 ZW |
718 | /* Chars that mean this number is a floating point constant. */ |
719 | /* As in 0f12.456 */ | |
720 | /* or 0d1.2345e12 */ | |
b99bd4ef | 721 | |
c19d1205 | 722 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 723 | |
c19d1205 ZW |
724 | /* Prefix characters that indicate the start of an immediate |
725 | value. */ | |
726 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 727 | |
c19d1205 ZW |
728 | /* Separator character handling. */ |
729 | ||
730 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
731 | ||
732 | static inline int | |
733 | skip_past_char (char ** str, char c) | |
734 | { | |
735 | if (**str == c) | |
736 | { | |
737 | (*str)++; | |
738 | return SUCCESS; | |
3d0c9500 | 739 | } |
c19d1205 ZW |
740 | else |
741 | return FAIL; | |
742 | } | |
743 | #define skip_past_comma(str) skip_past_char (str, ',') | |
3d0c9500 | 744 | |
c19d1205 ZW |
745 | /* Arithmetic expressions (possibly involving symbols). */ |
746 | ||
747 | /* Return TRUE if anything in the expression is a bignum. */ | |
748 | ||
749 | static int | |
750 | walk_no_bignums (symbolS * sp) | |
751 | { | |
752 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
753 | return 1; | |
754 | ||
755 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 756 | { |
c19d1205 ZW |
757 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
758 | || (symbol_get_value_expression (sp)->X_op_symbol | |
759 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
760 | } |
761 | ||
c19d1205 | 762 | return 0; |
3d0c9500 NC |
763 | } |
764 | ||
c19d1205 ZW |
765 | static int in_my_get_expression = 0; |
766 | ||
767 | /* Third argument to my_get_expression. */ | |
768 | #define GE_NO_PREFIX 0 | |
769 | #define GE_IMM_PREFIX 1 | |
770 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
771 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
772 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
773 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 774 | |
b99bd4ef | 775 | static int |
c19d1205 | 776 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 777 | { |
c19d1205 ZW |
778 | char * save_in; |
779 | segT seg; | |
b99bd4ef | 780 | |
c19d1205 ZW |
781 | /* In unified syntax, all prefixes are optional. */ |
782 | if (unified_syntax) | |
5287ad62 JB |
783 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
784 | : GE_OPT_PREFIX; | |
b99bd4ef | 785 | |
c19d1205 | 786 | switch (prefix_mode) |
b99bd4ef | 787 | { |
c19d1205 ZW |
788 | case GE_NO_PREFIX: break; |
789 | case GE_IMM_PREFIX: | |
790 | if (!is_immediate_prefix (**str)) | |
791 | { | |
792 | inst.error = _("immediate expression requires a # prefix"); | |
793 | return FAIL; | |
794 | } | |
795 | (*str)++; | |
796 | break; | |
797 | case GE_OPT_PREFIX: | |
5287ad62 | 798 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
799 | if (is_immediate_prefix (**str)) |
800 | (*str)++; | |
801 | break; | |
802 | default: abort (); | |
803 | } | |
b99bd4ef | 804 | |
c19d1205 | 805 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 806 | |
c19d1205 ZW |
807 | save_in = input_line_pointer; |
808 | input_line_pointer = *str; | |
809 | in_my_get_expression = 1; | |
810 | seg = expression (ep); | |
811 | in_my_get_expression = 0; | |
812 | ||
813 | if (ep->X_op == O_illegal) | |
b99bd4ef | 814 | { |
c19d1205 ZW |
815 | /* We found a bad expression in md_operand(). */ |
816 | *str = input_line_pointer; | |
817 | input_line_pointer = save_in; | |
818 | if (inst.error == NULL) | |
819 | inst.error = _("bad expression"); | |
820 | return 1; | |
821 | } | |
b99bd4ef | 822 | |
c19d1205 ZW |
823 | #ifdef OBJ_AOUT |
824 | if (seg != absolute_section | |
825 | && seg != text_section | |
826 | && seg != data_section | |
827 | && seg != bss_section | |
828 | && seg != undefined_section) | |
829 | { | |
830 | inst.error = _("bad segment"); | |
831 | *str = input_line_pointer; | |
832 | input_line_pointer = save_in; | |
833 | return 1; | |
b99bd4ef | 834 | } |
c19d1205 | 835 | #endif |
b99bd4ef | 836 | |
c19d1205 ZW |
837 | /* Get rid of any bignums now, so that we don't generate an error for which |
838 | we can't establish a line number later on. Big numbers are never valid | |
839 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
840 | if (prefix_mode != GE_OPT_PREFIX_BIG |
841 | && (ep->X_op == O_big | |
842 | || (ep->X_add_symbol | |
843 | && (walk_no_bignums (ep->X_add_symbol) | |
844 | || (ep->X_op_symbol | |
845 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
846 | { |
847 | inst.error = _("invalid constant"); | |
848 | *str = input_line_pointer; | |
849 | input_line_pointer = save_in; | |
850 | return 1; | |
851 | } | |
b99bd4ef | 852 | |
c19d1205 ZW |
853 | *str = input_line_pointer; |
854 | input_line_pointer = save_in; | |
855 | return 0; | |
b99bd4ef NC |
856 | } |
857 | ||
c19d1205 ZW |
858 | /* Turn a string in input_line_pointer into a floating point constant |
859 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
860 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
861 | returned, or NULL on OK. | |
b99bd4ef | 862 | |
c19d1205 ZW |
863 | Note that fp constants aren't represent in the normal way on the ARM. |
864 | In big endian mode, things are as expected. However, in little endian | |
865 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
866 | within the words. For example, (double) 1.1 in big endian mode is | |
867 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
868 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 869 | |
c19d1205 | 870 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 871 | |
c19d1205 ZW |
872 | char * |
873 | md_atof (int type, char * litP, int * sizeP) | |
874 | { | |
875 | int prec; | |
876 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
877 | char *t; | |
878 | int i; | |
b99bd4ef | 879 | |
c19d1205 ZW |
880 | switch (type) |
881 | { | |
882 | case 'f': | |
883 | case 'F': | |
884 | case 's': | |
885 | case 'S': | |
886 | prec = 2; | |
887 | break; | |
b99bd4ef | 888 | |
c19d1205 ZW |
889 | case 'd': |
890 | case 'D': | |
891 | case 'r': | |
892 | case 'R': | |
893 | prec = 4; | |
894 | break; | |
b99bd4ef | 895 | |
c19d1205 ZW |
896 | case 'x': |
897 | case 'X': | |
898 | prec = 6; | |
899 | break; | |
b99bd4ef | 900 | |
c19d1205 ZW |
901 | case 'p': |
902 | case 'P': | |
903 | prec = 6; | |
904 | break; | |
a737bd4d | 905 | |
c19d1205 ZW |
906 | default: |
907 | *sizeP = 0; | |
908 | return _("bad call to MD_ATOF()"); | |
909 | } | |
b99bd4ef | 910 | |
c19d1205 ZW |
911 | t = atof_ieee (input_line_pointer, type, words); |
912 | if (t) | |
913 | input_line_pointer = t; | |
914 | *sizeP = prec * 2; | |
b99bd4ef | 915 | |
c19d1205 ZW |
916 | if (target_big_endian) |
917 | { | |
918 | for (i = 0; i < prec; i++) | |
919 | { | |
920 | md_number_to_chars (litP, (valueT) words[i], 2); | |
921 | litP += 2; | |
922 | } | |
923 | } | |
924 | else | |
925 | { | |
e74cfd16 | 926 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
927 | for (i = prec - 1; i >= 0; i--) |
928 | { | |
929 | md_number_to_chars (litP, (valueT) words[i], 2); | |
930 | litP += 2; | |
931 | } | |
932 | else | |
933 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
934 | For an 8 byte float the order is 1 0 3 2. */ | |
935 | for (i = 0; i < prec; i += 2) | |
936 | { | |
937 | md_number_to_chars (litP, (valueT) words[i + 1], 2); | |
938 | md_number_to_chars (litP + 2, (valueT) words[i], 2); | |
939 | litP += 4; | |
940 | } | |
941 | } | |
b99bd4ef | 942 | |
c19d1205 ZW |
943 | return 0; |
944 | } | |
b99bd4ef | 945 | |
c19d1205 ZW |
946 | /* We handle all bad expressions here, so that we can report the faulty |
947 | instruction in the error message. */ | |
948 | void | |
949 | md_operand (expressionS * expr) | |
950 | { | |
951 | if (in_my_get_expression) | |
952 | expr->X_op = O_illegal; | |
b99bd4ef NC |
953 | } |
954 | ||
c19d1205 | 955 | /* Immediate values. */ |
b99bd4ef | 956 | |
c19d1205 ZW |
957 | /* Generic immediate-value read function for use in directives. |
958 | Accepts anything that 'expression' can fold to a constant. | |
959 | *val receives the number. */ | |
960 | #ifdef OBJ_ELF | |
961 | static int | |
962 | immediate_for_directive (int *val) | |
b99bd4ef | 963 | { |
c19d1205 ZW |
964 | expressionS exp; |
965 | exp.X_op = O_illegal; | |
b99bd4ef | 966 | |
c19d1205 ZW |
967 | if (is_immediate_prefix (*input_line_pointer)) |
968 | { | |
969 | input_line_pointer++; | |
970 | expression (&exp); | |
971 | } | |
b99bd4ef | 972 | |
c19d1205 ZW |
973 | if (exp.X_op != O_constant) |
974 | { | |
975 | as_bad (_("expected #constant")); | |
976 | ignore_rest_of_line (); | |
977 | return FAIL; | |
978 | } | |
979 | *val = exp.X_add_number; | |
980 | return SUCCESS; | |
b99bd4ef | 981 | } |
c19d1205 | 982 | #endif |
b99bd4ef | 983 | |
c19d1205 | 984 | /* Register parsing. */ |
b99bd4ef | 985 | |
c19d1205 ZW |
986 | /* Generic register parser. CCP points to what should be the |
987 | beginning of a register name. If it is indeed a valid register | |
988 | name, advance CCP over it and return the reg_entry structure; | |
989 | otherwise return NULL. Does not issue diagnostics. */ | |
990 | ||
991 | static struct reg_entry * | |
992 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 993 | { |
c19d1205 ZW |
994 | char *start = *ccp; |
995 | char *p; | |
996 | struct reg_entry *reg; | |
b99bd4ef | 997 | |
c19d1205 ZW |
998 | #ifdef REGISTER_PREFIX |
999 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1000 | return NULL; |
c19d1205 ZW |
1001 | start++; |
1002 | #endif | |
1003 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1004 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1005 | start++; | |
1006 | #endif | |
b99bd4ef | 1007 | |
c19d1205 ZW |
1008 | p = start; |
1009 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1010 | return NULL; | |
b99bd4ef | 1011 | |
c19d1205 ZW |
1012 | do |
1013 | p++; | |
1014 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1015 | ||
1016 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1017 | ||
1018 | if (!reg) | |
1019 | return NULL; | |
1020 | ||
1021 | *ccp = p; | |
1022 | return reg; | |
b99bd4ef NC |
1023 | } |
1024 | ||
1025 | static int | |
dcbf9037 JB |
1026 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1027 | enum arm_reg_type type) | |
b99bd4ef | 1028 | { |
c19d1205 ZW |
1029 | /* Alternative syntaxes are accepted for a few register classes. */ |
1030 | switch (type) | |
1031 | { | |
1032 | case REG_TYPE_MVF: | |
1033 | case REG_TYPE_MVD: | |
1034 | case REG_TYPE_MVFX: | |
1035 | case REG_TYPE_MVDX: | |
1036 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1037 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1038 | return reg->number; |
1039 | break; | |
69b97547 | 1040 | |
c19d1205 ZW |
1041 | case REG_TYPE_CP: |
1042 | /* For backward compatibility, a bare number is valid here. */ | |
1043 | { | |
1044 | unsigned long processor = strtoul (start, ccp, 10); | |
1045 | if (*ccp != start && processor <= 15) | |
1046 | return processor; | |
1047 | } | |
6057a28f | 1048 | |
c19d1205 ZW |
1049 | case REG_TYPE_MMXWC: |
1050 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1051 | instructions that take WC registers. */ | |
79134647 | 1052 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1053 | return reg->number; |
6057a28f | 1054 | break; |
c19d1205 | 1055 | |
6057a28f | 1056 | default: |
c19d1205 | 1057 | break; |
6057a28f NC |
1058 | } |
1059 | ||
dcbf9037 JB |
1060 | return FAIL; |
1061 | } | |
1062 | ||
1063 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1064 | return value is the register number or FAIL. */ | |
1065 | ||
1066 | static int | |
1067 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1068 | { | |
1069 | char *start = *ccp; | |
1070 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1071 | int ret; | |
1072 | ||
1073 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1074 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1075 | return FAIL; | |
1076 | ||
1077 | if (reg && reg->type == type) | |
1078 | return reg->number; | |
1079 | ||
1080 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1081 | return ret; | |
1082 | ||
c19d1205 ZW |
1083 | *ccp = start; |
1084 | return FAIL; | |
1085 | } | |
69b97547 | 1086 | |
dcbf9037 JB |
1087 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1088 | character. Does no verification at this stage that the type fits the opcode | |
1089 | properly. E.g., | |
1090 | ||
1091 | .i32.i32.s16 | |
1092 | .s32.f32 | |
1093 | .u16 | |
1094 | ||
1095 | Can all be legally parsed by this function. | |
1096 | ||
1097 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1098 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1099 | type, FAIL if not. */ | |
1100 | ||
1101 | static int | |
1102 | parse_neon_type (struct neon_type *type, char **str) | |
1103 | { | |
1104 | char *ptr = *str; | |
1105 | ||
1106 | if (type) | |
1107 | type->elems = 0; | |
1108 | ||
1109 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1110 | { | |
1111 | enum neon_el_type thistype = NT_untyped; | |
1112 | unsigned thissize = -1u; | |
1113 | ||
1114 | if (*ptr != '.') | |
1115 | break; | |
1116 | ||
1117 | ptr++; | |
1118 | ||
1119 | /* Just a size without an explicit type. */ | |
1120 | if (ISDIGIT (*ptr)) | |
1121 | goto parsesize; | |
1122 | ||
1123 | switch (TOLOWER (*ptr)) | |
1124 | { | |
1125 | case 'i': thistype = NT_integer; break; | |
1126 | case 'f': thistype = NT_float; break; | |
1127 | case 'p': thistype = NT_poly; break; | |
1128 | case 's': thistype = NT_signed; break; | |
1129 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1130 | case 'd': |
1131 | thistype = NT_float; | |
1132 | thissize = 64; | |
1133 | ptr++; | |
1134 | goto done; | |
dcbf9037 JB |
1135 | default: |
1136 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1137 | return FAIL; | |
1138 | } | |
1139 | ||
1140 | ptr++; | |
1141 | ||
1142 | /* .f is an abbreviation for .f32. */ | |
1143 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1144 | thissize = 32; | |
1145 | else | |
1146 | { | |
1147 | parsesize: | |
1148 | thissize = strtoul (ptr, &ptr, 10); | |
1149 | ||
1150 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1151 | && thissize != 64) | |
1152 | { | |
1153 | as_bad (_("bad size %d in type specifier"), thissize); | |
1154 | return FAIL; | |
1155 | } | |
1156 | } | |
1157 | ||
037e8744 | 1158 | done: |
dcbf9037 JB |
1159 | if (type) |
1160 | { | |
1161 | type->el[type->elems].type = thistype; | |
1162 | type->el[type->elems].size = thissize; | |
1163 | type->elems++; | |
1164 | } | |
1165 | } | |
1166 | ||
1167 | /* Empty/missing type is not a successful parse. */ | |
1168 | if (type->elems == 0) | |
1169 | return FAIL; | |
1170 | ||
1171 | *str = ptr; | |
1172 | ||
1173 | return SUCCESS; | |
1174 | } | |
1175 | ||
1176 | /* Errors may be set multiple times during parsing or bit encoding | |
1177 | (particularly in the Neon bits), but usually the earliest error which is set | |
1178 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1179 | errors by calling this function. */ | |
1180 | ||
1181 | static void | |
1182 | first_error (const char *err) | |
1183 | { | |
1184 | if (!inst.error) | |
1185 | inst.error = err; | |
1186 | } | |
1187 | ||
1188 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1189 | static int | |
1190 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1191 | { | |
1192 | char *str = *ccp; | |
1193 | struct neon_type optype; | |
1194 | ||
1195 | if (*str == '.') | |
1196 | { | |
1197 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1198 | { | |
1199 | if (optype.elems == 1) | |
1200 | *vectype = optype.el[0]; | |
1201 | else | |
1202 | { | |
1203 | first_error (_("only one type should be specified for operand")); | |
1204 | return FAIL; | |
1205 | } | |
1206 | } | |
1207 | else | |
1208 | { | |
1209 | first_error (_("vector type expected")); | |
1210 | return FAIL; | |
1211 | } | |
1212 | } | |
1213 | else | |
1214 | return FAIL; | |
1215 | ||
1216 | *ccp = str; | |
1217 | ||
1218 | return SUCCESS; | |
1219 | } | |
1220 | ||
1221 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1222 | a 4-bit integer. */ | |
1223 | ||
1224 | #define NEON_ALL_LANES 15 | |
1225 | #define NEON_INTERLEAVE_LANES 14 | |
1226 | ||
1227 | /* Parse either a register or a scalar, with an optional type. Return the | |
1228 | register number, and optionally fill in the actual type of the register | |
1229 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1230 | type/index information in *TYPEINFO. */ | |
1231 | ||
1232 | static int | |
1233 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1234 | enum arm_reg_type *rtype, | |
1235 | struct neon_typed_alias *typeinfo) | |
1236 | { | |
1237 | char *str = *ccp; | |
1238 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1239 | struct neon_typed_alias atype; | |
1240 | struct neon_type_el parsetype; | |
1241 | ||
1242 | atype.defined = 0; | |
1243 | atype.index = -1; | |
1244 | atype.eltype.type = NT_invtype; | |
1245 | atype.eltype.size = -1; | |
1246 | ||
1247 | /* Try alternate syntax for some types of register. Note these are mutually | |
1248 | exclusive with the Neon syntax extensions. */ | |
1249 | if (reg == NULL) | |
1250 | { | |
1251 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1252 | if (altreg != FAIL) | |
1253 | *ccp = str; | |
1254 | if (typeinfo) | |
1255 | *typeinfo = atype; | |
1256 | return altreg; | |
1257 | } | |
1258 | ||
037e8744 JB |
1259 | /* Undo polymorphism when a set of register types may be accepted. */ |
1260 | if ((type == REG_TYPE_NDQ | |
1261 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1262 | || (type == REG_TYPE_VFSD | |
1263 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1264 | || (type == REG_TYPE_NSDQ | |
1265 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
f512f76f NC |
1266 | || reg->type == REG_TYPE_NQ)) |
1267 | || (type == REG_TYPE_MMXWC | |
1268 | && (reg->type == REG_TYPE_MMXWCG))) | |
dcbf9037 JB |
1269 | type = reg->type; |
1270 | ||
1271 | if (type != reg->type) | |
1272 | return FAIL; | |
1273 | ||
1274 | if (reg->neon) | |
1275 | atype = *reg->neon; | |
1276 | ||
1277 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) | |
1278 | { | |
1279 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1280 | { | |
1281 | first_error (_("can't redefine type for operand")); | |
1282 | return FAIL; | |
1283 | } | |
1284 | atype.defined |= NTA_HASTYPE; | |
1285 | atype.eltype = parsetype; | |
1286 | } | |
1287 | ||
1288 | if (skip_past_char (&str, '[') == SUCCESS) | |
1289 | { | |
1290 | if (type != REG_TYPE_VFD) | |
1291 | { | |
1292 | first_error (_("only D registers may be indexed")); | |
1293 | return FAIL; | |
1294 | } | |
1295 | ||
1296 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1297 | { | |
1298 | first_error (_("can't change index for operand")); | |
1299 | return FAIL; | |
1300 | } | |
1301 | ||
1302 | atype.defined |= NTA_HASINDEX; | |
1303 | ||
1304 | if (skip_past_char (&str, ']') == SUCCESS) | |
1305 | atype.index = NEON_ALL_LANES; | |
1306 | else | |
1307 | { | |
1308 | expressionS exp; | |
1309 | ||
1310 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1311 | ||
1312 | if (exp.X_op != O_constant) | |
1313 | { | |
1314 | first_error (_("constant expression required")); | |
1315 | return FAIL; | |
1316 | } | |
1317 | ||
1318 | if (skip_past_char (&str, ']') == FAIL) | |
1319 | return FAIL; | |
1320 | ||
1321 | atype.index = exp.X_add_number; | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | if (typeinfo) | |
1326 | *typeinfo = atype; | |
1327 | ||
1328 | if (rtype) | |
1329 | *rtype = type; | |
1330 | ||
1331 | *ccp = str; | |
1332 | ||
1333 | return reg->number; | |
1334 | } | |
1335 | ||
1336 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1337 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1338 | register (e.g. Neon double or quad reg when either has been requested). | |
1339 | - If this is a Neon vector type with additional type information, fill | |
1340 | in the struct pointed to by VECTYPE (if non-NULL). | |
1341 | This function will fault on encountering a scalar. | |
1342 | */ | |
1343 | ||
1344 | static int | |
1345 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1346 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1347 | { | |
1348 | struct neon_typed_alias atype; | |
1349 | char *str = *ccp; | |
1350 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1351 | ||
1352 | if (reg == FAIL) | |
1353 | return FAIL; | |
1354 | ||
1355 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1356 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1357 | { | |
1358 | first_error (_("register operand expected, but got scalar")); | |
1359 | return FAIL; | |
1360 | } | |
1361 | ||
1362 | if (vectype) | |
1363 | *vectype = atype.eltype; | |
1364 | ||
1365 | *ccp = str; | |
1366 | ||
1367 | return reg; | |
1368 | } | |
1369 | ||
1370 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1371 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1372 | ||
5287ad62 JB |
1373 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1374 | have enough information to be able to do a good job bounds-checking. So, we | |
1375 | just do easy checks here, and do further checks later. */ | |
1376 | ||
1377 | static int | |
dcbf9037 | 1378 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1379 | { |
dcbf9037 | 1380 | int reg; |
5287ad62 | 1381 | char *str = *ccp; |
dcbf9037 | 1382 | struct neon_typed_alias atype; |
5287ad62 | 1383 | |
dcbf9037 | 1384 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5287ad62 | 1385 | |
dcbf9037 | 1386 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 JB |
1387 | return FAIL; |
1388 | ||
dcbf9037 | 1389 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1390 | { |
dcbf9037 | 1391 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1392 | return FAIL; |
1393 | } | |
dcbf9037 | 1394 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1395 | { |
dcbf9037 | 1396 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1397 | return FAIL; |
1398 | } | |
1399 | ||
dcbf9037 JB |
1400 | if (type) |
1401 | *type = atype.eltype; | |
5287ad62 | 1402 | |
5287ad62 JB |
1403 | *ccp = str; |
1404 | ||
dcbf9037 | 1405 | return reg * 16 + atype.index; |
5287ad62 JB |
1406 | } |
1407 | ||
c19d1205 ZW |
1408 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
1409 | static long | |
1410 | parse_reg_list (char ** strp) | |
1411 | { | |
1412 | char * str = * strp; | |
1413 | long range = 0; | |
1414 | int another_range; | |
a737bd4d | 1415 | |
c19d1205 ZW |
1416 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1417 | do | |
6057a28f | 1418 | { |
c19d1205 | 1419 | another_range = 0; |
a737bd4d | 1420 | |
c19d1205 ZW |
1421 | if (*str == '{') |
1422 | { | |
1423 | int in_range = 0; | |
1424 | int cur_reg = -1; | |
a737bd4d | 1425 | |
c19d1205 ZW |
1426 | str++; |
1427 | do | |
1428 | { | |
1429 | int reg; | |
6057a28f | 1430 | |
dcbf9037 | 1431 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1432 | { |
dcbf9037 | 1433 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1434 | return FAIL; |
1435 | } | |
a737bd4d | 1436 | |
c19d1205 ZW |
1437 | if (in_range) |
1438 | { | |
1439 | int i; | |
a737bd4d | 1440 | |
c19d1205 ZW |
1441 | if (reg <= cur_reg) |
1442 | { | |
dcbf9037 | 1443 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1444 | return FAIL; |
1445 | } | |
40a18ebd | 1446 | |
c19d1205 ZW |
1447 | for (i = cur_reg + 1; i < reg; i++) |
1448 | { | |
1449 | if (range & (1 << i)) | |
1450 | as_tsktsk | |
1451 | (_("Warning: duplicated register (r%d) in register list"), | |
1452 | i); | |
1453 | else | |
1454 | range |= 1 << i; | |
1455 | } | |
1456 | in_range = 0; | |
1457 | } | |
a737bd4d | 1458 | |
c19d1205 ZW |
1459 | if (range & (1 << reg)) |
1460 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1461 | reg); | |
1462 | else if (reg <= cur_reg) | |
1463 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1464 | |
c19d1205 ZW |
1465 | range |= 1 << reg; |
1466 | cur_reg = reg; | |
1467 | } | |
1468 | while (skip_past_comma (&str) != FAIL | |
1469 | || (in_range = 1, *str++ == '-')); | |
1470 | str--; | |
a737bd4d | 1471 | |
c19d1205 ZW |
1472 | if (*str++ != '}') |
1473 | { | |
dcbf9037 | 1474 | first_error (_("missing `}'")); |
c19d1205 ZW |
1475 | return FAIL; |
1476 | } | |
1477 | } | |
1478 | else | |
1479 | { | |
1480 | expressionS expr; | |
40a18ebd | 1481 | |
c19d1205 ZW |
1482 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1483 | return FAIL; | |
40a18ebd | 1484 | |
c19d1205 ZW |
1485 | if (expr.X_op == O_constant) |
1486 | { | |
1487 | if (expr.X_add_number | |
1488 | != (expr.X_add_number & 0x0000ffff)) | |
1489 | { | |
1490 | inst.error = _("invalid register mask"); | |
1491 | return FAIL; | |
1492 | } | |
a737bd4d | 1493 | |
c19d1205 ZW |
1494 | if ((range & expr.X_add_number) != 0) |
1495 | { | |
1496 | int regno = range & expr.X_add_number; | |
a737bd4d | 1497 | |
c19d1205 ZW |
1498 | regno &= -regno; |
1499 | regno = (1 << regno) - 1; | |
1500 | as_tsktsk | |
1501 | (_("Warning: duplicated register (r%d) in register list"), | |
1502 | regno); | |
1503 | } | |
a737bd4d | 1504 | |
c19d1205 ZW |
1505 | range |= expr.X_add_number; |
1506 | } | |
1507 | else | |
1508 | { | |
1509 | if (inst.reloc.type != 0) | |
1510 | { | |
1511 | inst.error = _("expression too complex"); | |
1512 | return FAIL; | |
1513 | } | |
a737bd4d | 1514 | |
c19d1205 ZW |
1515 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1516 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1517 | inst.reloc.pc_rel = 0; | |
1518 | } | |
1519 | } | |
a737bd4d | 1520 | |
c19d1205 ZW |
1521 | if (*str == '|' || *str == '+') |
1522 | { | |
1523 | str++; | |
1524 | another_range = 1; | |
1525 | } | |
a737bd4d | 1526 | } |
c19d1205 | 1527 | while (another_range); |
a737bd4d | 1528 | |
c19d1205 ZW |
1529 | *strp = str; |
1530 | return range; | |
a737bd4d NC |
1531 | } |
1532 | ||
5287ad62 JB |
1533 | /* Types of registers in a list. */ |
1534 | ||
1535 | enum reg_list_els | |
1536 | { | |
1537 | REGLIST_VFP_S, | |
1538 | REGLIST_VFP_D, | |
1539 | REGLIST_NEON_D | |
1540 | }; | |
1541 | ||
c19d1205 ZW |
1542 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1543 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1544 | register. Parses registers of type ETYPE. |
1545 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1546 | - Q registers can be used to specify pairs of D registers | |
1547 | - { } can be omitted from around a singleton register list | |
1548 | FIXME: This is not implemented, as it would require backtracking in | |
1549 | some cases, e.g.: | |
1550 | vtbl.8 d3,d4,d5 | |
1551 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1552 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1553 | - 32 D registers may be used (also true for VFPv3). |
1554 | FIXME: Types are ignored in these register lists, which is probably a | |
1555 | bug. */ | |
6057a28f | 1556 | |
c19d1205 | 1557 | static int |
037e8744 | 1558 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1559 | { |
037e8744 | 1560 | char *str = *ccp; |
c19d1205 ZW |
1561 | int base_reg; |
1562 | int new_base; | |
5287ad62 JB |
1563 | enum arm_reg_type regtype = 0; |
1564 | int max_regs = 0; | |
c19d1205 ZW |
1565 | int count = 0; |
1566 | int warned = 0; | |
1567 | unsigned long mask = 0; | |
a737bd4d | 1568 | int i; |
6057a28f | 1569 | |
037e8744 | 1570 | if (*str != '{') |
5287ad62 JB |
1571 | { |
1572 | inst.error = _("expecting {"); | |
1573 | return FAIL; | |
1574 | } | |
6057a28f | 1575 | |
037e8744 | 1576 | str++; |
6057a28f | 1577 | |
5287ad62 | 1578 | switch (etype) |
c19d1205 | 1579 | { |
5287ad62 | 1580 | case REGLIST_VFP_S: |
c19d1205 ZW |
1581 | regtype = REG_TYPE_VFS; |
1582 | max_regs = 32; | |
5287ad62 JB |
1583 | break; |
1584 | ||
1585 | case REGLIST_VFP_D: | |
1586 | regtype = REG_TYPE_VFD; | |
b7fc2769 JB |
1587 | break; |
1588 | ||
1589 | case REGLIST_NEON_D: | |
1590 | regtype = REG_TYPE_NDQ; | |
1591 | break; | |
1592 | } | |
1593 | ||
1594 | if (etype != REGLIST_VFP_S) | |
1595 | { | |
5287ad62 JB |
1596 | /* VFPv3 allows 32 D registers. */ |
1597 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
1598 | { | |
1599 | max_regs = 32; | |
1600 | if (thumb_mode) | |
1601 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
1602 | fpu_vfp_ext_v3); | |
1603 | else | |
1604 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
1605 | fpu_vfp_ext_v3); | |
1606 | } | |
1607 | else | |
1608 | max_regs = 16; | |
c19d1205 | 1609 | } |
6057a28f | 1610 | |
c19d1205 | 1611 | base_reg = max_regs; |
a737bd4d | 1612 | |
c19d1205 ZW |
1613 | do |
1614 | { | |
5287ad62 | 1615 | int setmask = 1, addregs = 1; |
dcbf9037 | 1616 | |
037e8744 | 1617 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1618 | |
c19d1205 | 1619 | if (new_base == FAIL) |
a737bd4d | 1620 | { |
dcbf9037 | 1621 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1622 | return FAIL; |
1623 | } | |
dcbf9037 | 1624 | |
b7fc2769 JB |
1625 | if (new_base >= max_regs) |
1626 | { | |
1627 | first_error (_("register out of range in list")); | |
1628 | return FAIL; | |
1629 | } | |
1630 | ||
5287ad62 JB |
1631 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1632 | if (regtype == REG_TYPE_NQ) | |
1633 | { | |
1634 | setmask = 3; | |
1635 | addregs = 2; | |
1636 | } | |
1637 | ||
c19d1205 ZW |
1638 | if (new_base < base_reg) |
1639 | base_reg = new_base; | |
a737bd4d | 1640 | |
5287ad62 | 1641 | if (mask & (setmask << new_base)) |
c19d1205 | 1642 | { |
dcbf9037 | 1643 | first_error (_("invalid register list")); |
c19d1205 | 1644 | return FAIL; |
a737bd4d | 1645 | } |
a737bd4d | 1646 | |
c19d1205 ZW |
1647 | if ((mask >> new_base) != 0 && ! warned) |
1648 | { | |
1649 | as_tsktsk (_("register list not in ascending order")); | |
1650 | warned = 1; | |
1651 | } | |
0bbf2aa4 | 1652 | |
5287ad62 JB |
1653 | mask |= setmask << new_base; |
1654 | count += addregs; | |
0bbf2aa4 | 1655 | |
037e8744 | 1656 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1657 | { |
1658 | int high_range; | |
0bbf2aa4 | 1659 | |
037e8744 | 1660 | str++; |
0bbf2aa4 | 1661 | |
037e8744 | 1662 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1663 | == FAIL) |
c19d1205 ZW |
1664 | { |
1665 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1666 | return FAIL; | |
1667 | } | |
0bbf2aa4 | 1668 | |
b7fc2769 JB |
1669 | if (high_range >= max_regs) |
1670 | { | |
1671 | first_error (_("register out of range in list")); | |
1672 | return FAIL; | |
1673 | } | |
1674 | ||
5287ad62 JB |
1675 | if (regtype == REG_TYPE_NQ) |
1676 | high_range = high_range + 1; | |
1677 | ||
c19d1205 ZW |
1678 | if (high_range <= new_base) |
1679 | { | |
1680 | inst.error = _("register range not in ascending order"); | |
1681 | return FAIL; | |
1682 | } | |
0bbf2aa4 | 1683 | |
5287ad62 | 1684 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1685 | { |
5287ad62 | 1686 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1687 | { |
c19d1205 ZW |
1688 | inst.error = _("invalid register list"); |
1689 | return FAIL; | |
0bbf2aa4 | 1690 | } |
c19d1205 | 1691 | |
5287ad62 JB |
1692 | mask |= setmask << new_base; |
1693 | count += addregs; | |
0bbf2aa4 | 1694 | } |
0bbf2aa4 | 1695 | } |
0bbf2aa4 | 1696 | } |
037e8744 | 1697 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1698 | |
037e8744 | 1699 | str++; |
0bbf2aa4 | 1700 | |
c19d1205 ZW |
1701 | /* Sanity check -- should have raised a parse error above. */ |
1702 | if (count == 0 || count > max_regs) | |
1703 | abort (); | |
1704 | ||
1705 | *pbase = base_reg; | |
1706 | ||
1707 | /* Final test -- the registers must be consecutive. */ | |
1708 | mask >>= base_reg; | |
1709 | for (i = 0; i < count; i++) | |
1710 | { | |
1711 | if ((mask & (1u << i)) == 0) | |
1712 | { | |
1713 | inst.error = _("non-contiguous register range"); | |
1714 | return FAIL; | |
1715 | } | |
1716 | } | |
1717 | ||
037e8744 JB |
1718 | *ccp = str; |
1719 | ||
c19d1205 | 1720 | return count; |
b99bd4ef NC |
1721 | } |
1722 | ||
dcbf9037 JB |
1723 | /* True if two alias types are the same. */ |
1724 | ||
1725 | static int | |
1726 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) | |
1727 | { | |
1728 | if (!a && !b) | |
1729 | return 1; | |
1730 | ||
1731 | if (!a || !b) | |
1732 | return 0; | |
1733 | ||
1734 | if (a->defined != b->defined) | |
1735 | return 0; | |
1736 | ||
1737 | if ((a->defined & NTA_HASTYPE) != 0 | |
1738 | && (a->eltype.type != b->eltype.type | |
1739 | || a->eltype.size != b->eltype.size)) | |
1740 | return 0; | |
1741 | ||
1742 | if ((a->defined & NTA_HASINDEX) != 0 | |
1743 | && (a->index != b->index)) | |
1744 | return 0; | |
1745 | ||
1746 | return 1; | |
1747 | } | |
1748 | ||
5287ad62 JB |
1749 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1750 | The base register is put in *PBASE. | |
dcbf9037 | 1751 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1752 | the return value. |
1753 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1754 | Bits [6:5] encode the list length (minus one). |
1755 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1756 | |
5287ad62 | 1757 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1758 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1759 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1760 | ||
1761 | static int | |
dcbf9037 JB |
1762 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1763 | struct neon_type_el *eltype) | |
5287ad62 JB |
1764 | { |
1765 | char *ptr = *str; | |
1766 | int base_reg = -1; | |
1767 | int reg_incr = -1; | |
1768 | int count = 0; | |
1769 | int lane = -1; | |
1770 | int leading_brace = 0; | |
1771 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
1772 | int addregs = 1; | |
1773 | const char *const incr_error = "register stride must be 1 or 2"; | |
1774 | const char *const type_error = "mismatched element/structure types in list"; | |
dcbf9037 | 1775 | struct neon_typed_alias firsttype; |
5287ad62 JB |
1776 | |
1777 | if (skip_past_char (&ptr, '{') == SUCCESS) | |
1778 | leading_brace = 1; | |
1779 | ||
1780 | do | |
1781 | { | |
dcbf9037 JB |
1782 | struct neon_typed_alias atype; |
1783 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1784 | ||
5287ad62 JB |
1785 | if (getreg == FAIL) |
1786 | { | |
dcbf9037 | 1787 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1788 | return FAIL; |
1789 | } | |
1790 | ||
1791 | if (base_reg == -1) | |
1792 | { | |
1793 | base_reg = getreg; | |
1794 | if (rtype == REG_TYPE_NQ) | |
1795 | { | |
1796 | reg_incr = 1; | |
1797 | addregs = 2; | |
1798 | } | |
dcbf9037 | 1799 | firsttype = atype; |
5287ad62 JB |
1800 | } |
1801 | else if (reg_incr == -1) | |
1802 | { | |
1803 | reg_incr = getreg - base_reg; | |
1804 | if (reg_incr < 1 || reg_incr > 2) | |
1805 | { | |
dcbf9037 | 1806 | first_error (_(incr_error)); |
5287ad62 JB |
1807 | return FAIL; |
1808 | } | |
1809 | } | |
1810 | else if (getreg != base_reg + reg_incr * count) | |
1811 | { | |
dcbf9037 JB |
1812 | first_error (_(incr_error)); |
1813 | return FAIL; | |
1814 | } | |
1815 | ||
1816 | if (!neon_alias_types_same (&atype, &firsttype)) | |
1817 | { | |
1818 | first_error (_(type_error)); | |
5287ad62 JB |
1819 | return FAIL; |
1820 | } | |
1821 | ||
1822 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list | |
1823 | modes. */ | |
1824 | if (ptr[0] == '-') | |
1825 | { | |
dcbf9037 | 1826 | struct neon_typed_alias htype; |
5287ad62 JB |
1827 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1828 | if (lane == -1) | |
1829 | lane = NEON_INTERLEAVE_LANES; | |
1830 | else if (lane != NEON_INTERLEAVE_LANES) | |
1831 | { | |
dcbf9037 | 1832 | first_error (_(type_error)); |
5287ad62 JB |
1833 | return FAIL; |
1834 | } | |
1835 | if (reg_incr == -1) | |
1836 | reg_incr = 1; | |
1837 | else if (reg_incr != 1) | |
1838 | { | |
dcbf9037 | 1839 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
1840 | return FAIL; |
1841 | } | |
1842 | ptr++; | |
dcbf9037 | 1843 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
1844 | if (hireg == FAIL) |
1845 | { | |
dcbf9037 JB |
1846 | first_error (_(reg_expected_msgs[rtype])); |
1847 | return FAIL; | |
1848 | } | |
1849 | if (!neon_alias_types_same (&htype, &firsttype)) | |
1850 | { | |
1851 | first_error (_(type_error)); | |
5287ad62 JB |
1852 | return FAIL; |
1853 | } | |
1854 | count += hireg + dregs - getreg; | |
1855 | continue; | |
1856 | } | |
1857 | ||
1858 | /* If we're using Q registers, we can't use [] or [n] syntax. */ | |
1859 | if (rtype == REG_TYPE_NQ) | |
1860 | { | |
1861 | count += 2; | |
1862 | continue; | |
1863 | } | |
1864 | ||
dcbf9037 | 1865 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 1866 | { |
dcbf9037 JB |
1867 | if (lane == -1) |
1868 | lane = atype.index; | |
1869 | else if (lane != atype.index) | |
5287ad62 | 1870 | { |
dcbf9037 JB |
1871 | first_error (_(type_error)); |
1872 | return FAIL; | |
5287ad62 JB |
1873 | } |
1874 | } | |
1875 | else if (lane == -1) | |
1876 | lane = NEON_INTERLEAVE_LANES; | |
1877 | else if (lane != NEON_INTERLEAVE_LANES) | |
1878 | { | |
dcbf9037 | 1879 | first_error (_(type_error)); |
5287ad62 JB |
1880 | return FAIL; |
1881 | } | |
1882 | count++; | |
1883 | } | |
1884 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
1885 | ||
1886 | /* No lane set by [x]. We must be interleaving structures. */ | |
1887 | if (lane == -1) | |
1888 | lane = NEON_INTERLEAVE_LANES; | |
1889 | ||
1890 | /* Sanity check. */ | |
1891 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
1892 | || (count > 1 && reg_incr == -1)) | |
1893 | { | |
dcbf9037 | 1894 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
1895 | return FAIL; |
1896 | } | |
1897 | ||
1898 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
1899 | { | |
dcbf9037 | 1900 | first_error (_("expected }")); |
5287ad62 JB |
1901 | return FAIL; |
1902 | } | |
1903 | ||
1904 | if (reg_incr == -1) | |
1905 | reg_incr = 1; | |
1906 | ||
dcbf9037 JB |
1907 | if (eltype) |
1908 | *eltype = firsttype.eltype; | |
1909 | ||
5287ad62 JB |
1910 | *pbase = base_reg; |
1911 | *str = ptr; | |
1912 | ||
1913 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); | |
1914 | } | |
1915 | ||
c19d1205 ZW |
1916 | /* Parse an explicit relocation suffix on an expression. This is |
1917 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
1918 | arm_reloc_hsh contains no entries, so this function can only | |
1919 | succeed if there is no () after the word. Returns -1 on error, | |
1920 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
1921 | static int | |
1922 | parse_reloc (char **str) | |
b99bd4ef | 1923 | { |
c19d1205 ZW |
1924 | struct reloc_entry *r; |
1925 | char *p, *q; | |
b99bd4ef | 1926 | |
c19d1205 ZW |
1927 | if (**str != '(') |
1928 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 1929 | |
c19d1205 ZW |
1930 | p = *str + 1; |
1931 | q = p; | |
1932 | ||
1933 | while (*q && *q != ')' && *q != ',') | |
1934 | q++; | |
1935 | if (*q != ')') | |
1936 | return -1; | |
1937 | ||
1938 | if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
1939 | return -1; | |
1940 | ||
1941 | *str = q + 1; | |
1942 | return r->reloc; | |
b99bd4ef NC |
1943 | } |
1944 | ||
c19d1205 ZW |
1945 | /* Directives: register aliases. */ |
1946 | ||
dcbf9037 | 1947 | static struct reg_entry * |
c19d1205 | 1948 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 1949 | { |
c19d1205 ZW |
1950 | struct reg_entry *new; |
1951 | const char *name; | |
b99bd4ef | 1952 | |
c19d1205 ZW |
1953 | if ((new = hash_find (arm_reg_hsh, str)) != 0) |
1954 | { | |
1955 | if (new->builtin) | |
1956 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); | |
b99bd4ef | 1957 | |
c19d1205 ZW |
1958 | /* Only warn about a redefinition if it's not defined as the |
1959 | same register. */ | |
1960 | else if (new->number != number || new->type != type) | |
1961 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
69b97547 | 1962 | |
dcbf9037 | 1963 | return 0; |
c19d1205 | 1964 | } |
b99bd4ef | 1965 | |
c19d1205 ZW |
1966 | name = xstrdup (str); |
1967 | new = xmalloc (sizeof (struct reg_entry)); | |
b99bd4ef | 1968 | |
c19d1205 ZW |
1969 | new->name = name; |
1970 | new->number = number; | |
1971 | new->type = type; | |
1972 | new->builtin = FALSE; | |
dcbf9037 | 1973 | new->neon = NULL; |
b99bd4ef | 1974 | |
c19d1205 ZW |
1975 | if (hash_insert (arm_reg_hsh, name, (PTR) new)) |
1976 | abort (); | |
dcbf9037 JB |
1977 | |
1978 | return new; | |
1979 | } | |
1980 | ||
1981 | static void | |
1982 | insert_neon_reg_alias (char *str, int number, int type, | |
1983 | struct neon_typed_alias *atype) | |
1984 | { | |
1985 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
1986 | ||
1987 | if (!reg) | |
1988 | { | |
1989 | first_error (_("attempt to redefine typed alias")); | |
1990 | return; | |
1991 | } | |
1992 | ||
1993 | if (atype) | |
1994 | { | |
1995 | reg->neon = xmalloc (sizeof (struct neon_typed_alias)); | |
1996 | *reg->neon = *atype; | |
1997 | } | |
c19d1205 | 1998 | } |
b99bd4ef | 1999 | |
c19d1205 | 2000 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2001 | |
c19d1205 | 2002 | new_register_name .req existing_register_name |
b99bd4ef | 2003 | |
c19d1205 ZW |
2004 | If we find one, or if it looks sufficiently like one that we want to |
2005 | handle any error here, return non-zero. Otherwise return zero. */ | |
b99bd4ef | 2006 | |
c19d1205 ZW |
2007 | static int |
2008 | create_register_alias (char * newname, char *p) | |
2009 | { | |
2010 | struct reg_entry *old; | |
2011 | char *oldname, *nbuf; | |
2012 | size_t nlen; | |
b99bd4ef | 2013 | |
c19d1205 ZW |
2014 | /* The input scrubber ensures that whitespace after the mnemonic is |
2015 | collapsed to single spaces. */ | |
2016 | oldname = p; | |
2017 | if (strncmp (oldname, " .req ", 6) != 0) | |
2018 | return 0; | |
b99bd4ef | 2019 | |
c19d1205 ZW |
2020 | oldname += 6; |
2021 | if (*oldname == '\0') | |
2022 | return 0; | |
b99bd4ef | 2023 | |
c19d1205 ZW |
2024 | old = hash_find (arm_reg_hsh, oldname); |
2025 | if (!old) | |
b99bd4ef | 2026 | { |
c19d1205 ZW |
2027 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
2028 | return 1; | |
b99bd4ef NC |
2029 | } |
2030 | ||
c19d1205 ZW |
2031 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2032 | the desired alias name, and p points to its end. If not, then | |
2033 | the desired alias name is in the global original_case_string. */ | |
2034 | #ifdef TC_CASE_SENSITIVE | |
2035 | nlen = p - newname; | |
2036 | #else | |
2037 | newname = original_case_string; | |
2038 | nlen = strlen (newname); | |
2039 | #endif | |
b99bd4ef | 2040 | |
c19d1205 ZW |
2041 | nbuf = alloca (nlen + 1); |
2042 | memcpy (nbuf, newname, nlen); | |
2043 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2044 | |
c19d1205 ZW |
2045 | /* Create aliases under the new name as stated; an all-lowercase |
2046 | version of the new name; and an all-uppercase version of the new | |
2047 | name. */ | |
2048 | insert_reg_alias (nbuf, old->number, old->type); | |
b99bd4ef | 2049 | |
c19d1205 ZW |
2050 | for (p = nbuf; *p; p++) |
2051 | *p = TOUPPER (*p); | |
2052 | ||
2053 | if (strncmp (nbuf, newname, nlen)) | |
2054 | insert_reg_alias (nbuf, old->number, old->type); | |
2055 | ||
2056 | for (p = nbuf; *p; p++) | |
2057 | *p = TOLOWER (*p); | |
2058 | ||
2059 | if (strncmp (nbuf, newname, nlen)) | |
2060 | insert_reg_alias (nbuf, old->number, old->type); | |
2061 | ||
2062 | return 1; | |
b99bd4ef NC |
2063 | } |
2064 | ||
dcbf9037 JB |
2065 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2066 | X .dn d5.s32[1] | |
2067 | Y .qn 6.s16 | |
2068 | Z .dn d7 | |
2069 | T .dn Z[0] | |
2070 | These typed registers can be used instead of the types specified after the | |
2071 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2072 | specified directly, e.g.: | |
2073 | vadd d0.s32, d1.s32, d2.s32 | |
2074 | */ | |
2075 | ||
2076 | static int | |
2077 | create_neon_reg_alias (char *newname, char *p) | |
2078 | { | |
2079 | enum arm_reg_type basetype; | |
2080 | struct reg_entry *basereg; | |
2081 | struct reg_entry mybasereg; | |
2082 | struct neon_type ntype; | |
2083 | struct neon_typed_alias typeinfo; | |
2084 | char *namebuf, *nameend; | |
2085 | int namelen; | |
2086 | ||
2087 | typeinfo.defined = 0; | |
2088 | typeinfo.eltype.type = NT_invtype; | |
2089 | typeinfo.eltype.size = -1; | |
2090 | typeinfo.index = -1; | |
2091 | ||
2092 | nameend = p; | |
2093 | ||
2094 | if (strncmp (p, " .dn ", 5) == 0) | |
2095 | basetype = REG_TYPE_VFD; | |
2096 | else if (strncmp (p, " .qn ", 5) == 0) | |
2097 | basetype = REG_TYPE_NQ; | |
2098 | else | |
2099 | return 0; | |
2100 | ||
2101 | p += 5; | |
2102 | ||
2103 | if (*p == '\0') | |
2104 | return 0; | |
2105 | ||
2106 | basereg = arm_reg_parse_multi (&p); | |
2107 | ||
2108 | if (basereg && basereg->type != basetype) | |
2109 | { | |
2110 | as_bad (_("bad type for register")); | |
2111 | return 0; | |
2112 | } | |
2113 | ||
2114 | if (basereg == NULL) | |
2115 | { | |
2116 | expressionS exp; | |
2117 | /* Try parsing as an integer. */ | |
2118 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2119 | if (exp.X_op != O_constant) | |
2120 | { | |
2121 | as_bad (_("expression must be constant")); | |
2122 | return 0; | |
2123 | } | |
2124 | basereg = &mybasereg; | |
2125 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2126 | : exp.X_add_number; | |
2127 | basereg->neon = 0; | |
2128 | } | |
2129 | ||
2130 | if (basereg->neon) | |
2131 | typeinfo = *basereg->neon; | |
2132 | ||
2133 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2134 | { | |
2135 | /* We got a type. */ | |
2136 | if (typeinfo.defined & NTA_HASTYPE) | |
2137 | { | |
2138 | as_bad (_("can't redefine the type of a register alias")); | |
2139 | return 0; | |
2140 | } | |
2141 | ||
2142 | typeinfo.defined |= NTA_HASTYPE; | |
2143 | if (ntype.elems != 1) | |
2144 | { | |
2145 | as_bad (_("you must specify a single type only")); | |
2146 | return 0; | |
2147 | } | |
2148 | typeinfo.eltype = ntype.el[0]; | |
2149 | } | |
2150 | ||
2151 | if (skip_past_char (&p, '[') == SUCCESS) | |
2152 | { | |
2153 | expressionS exp; | |
2154 | /* We got a scalar index. */ | |
2155 | ||
2156 | if (typeinfo.defined & NTA_HASINDEX) | |
2157 | { | |
2158 | as_bad (_("can't redefine the index of a scalar alias")); | |
2159 | return 0; | |
2160 | } | |
2161 | ||
2162 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2163 | ||
2164 | if (exp.X_op != O_constant) | |
2165 | { | |
2166 | as_bad (_("scalar index must be constant")); | |
2167 | return 0; | |
2168 | } | |
2169 | ||
2170 | typeinfo.defined |= NTA_HASINDEX; | |
2171 | typeinfo.index = exp.X_add_number; | |
2172 | ||
2173 | if (skip_past_char (&p, ']') == FAIL) | |
2174 | { | |
2175 | as_bad (_("expecting ]")); | |
2176 | return 0; | |
2177 | } | |
2178 | } | |
2179 | ||
2180 | namelen = nameend - newname; | |
2181 | namebuf = alloca (namelen + 1); | |
2182 | strncpy (namebuf, newname, namelen); | |
2183 | namebuf[namelen] = '\0'; | |
2184 | ||
2185 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2186 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
2187 | ||
2188 | /* Insert name in all uppercase. */ | |
2189 | for (p = namebuf; *p; p++) | |
2190 | *p = TOUPPER (*p); | |
2191 | ||
2192 | if (strncmp (namebuf, newname, namelen)) | |
2193 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2194 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
2195 | ||
2196 | /* Insert name in all lowercase. */ | |
2197 | for (p = namebuf; *p; p++) | |
2198 | *p = TOLOWER (*p); | |
2199 | ||
2200 | if (strncmp (namebuf, newname, namelen)) | |
2201 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2202 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
2203 | ||
2204 | return 1; | |
2205 | } | |
2206 | ||
c19d1205 ZW |
2207 | /* Should never be called, as .req goes between the alias and the |
2208 | register name, not at the beginning of the line. */ | |
b99bd4ef | 2209 | static void |
c19d1205 | 2210 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2211 | { |
c19d1205 ZW |
2212 | as_bad (_("invalid syntax for .req directive")); |
2213 | } | |
b99bd4ef | 2214 | |
dcbf9037 JB |
2215 | static void |
2216 | s_dn (int a ATTRIBUTE_UNUSED) | |
2217 | { | |
2218 | as_bad (_("invalid syntax for .dn directive")); | |
2219 | } | |
2220 | ||
2221 | static void | |
2222 | s_qn (int a ATTRIBUTE_UNUSED) | |
2223 | { | |
2224 | as_bad (_("invalid syntax for .qn directive")); | |
2225 | } | |
2226 | ||
c19d1205 ZW |
2227 | /* The .unreq directive deletes an alias which was previously defined |
2228 | by .req. For example: | |
b99bd4ef | 2229 | |
c19d1205 ZW |
2230 | my_alias .req r11 |
2231 | .unreq my_alias */ | |
b99bd4ef NC |
2232 | |
2233 | static void | |
c19d1205 | 2234 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2235 | { |
c19d1205 ZW |
2236 | char * name; |
2237 | char saved_char; | |
b99bd4ef | 2238 | |
c19d1205 ZW |
2239 | name = input_line_pointer; |
2240 | ||
2241 | while (*input_line_pointer != 0 | |
2242 | && *input_line_pointer != ' ' | |
2243 | && *input_line_pointer != '\n') | |
2244 | ++input_line_pointer; | |
2245 | ||
2246 | saved_char = *input_line_pointer; | |
2247 | *input_line_pointer = 0; | |
2248 | ||
2249 | if (!*name) | |
2250 | as_bad (_("invalid syntax for .unreq directive")); | |
2251 | else | |
2252 | { | |
2253 | struct reg_entry *reg = hash_find (arm_reg_hsh, name); | |
2254 | ||
2255 | if (!reg) | |
2256 | as_bad (_("unknown register alias '%s'"), name); | |
2257 | else if (reg->builtin) | |
2258 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
2259 | name); | |
2260 | else | |
2261 | { | |
2262 | hash_delete (arm_reg_hsh, name); | |
2263 | free ((char *) reg->name); | |
dcbf9037 JB |
2264 | if (reg->neon) |
2265 | free (reg->neon); | |
c19d1205 ZW |
2266 | free (reg); |
2267 | } | |
2268 | } | |
b99bd4ef | 2269 | |
c19d1205 | 2270 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2271 | demand_empty_rest_of_line (); |
2272 | } | |
2273 | ||
c19d1205 ZW |
2274 | /* Directives: Instruction set selection. */ |
2275 | ||
2276 | #ifdef OBJ_ELF | |
2277 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2278 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2279 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2280 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2281 | ||
2282 | static enum mstate mapstate = MAP_UNDEFINED; | |
b99bd4ef NC |
2283 | |
2284 | static void | |
c19d1205 | 2285 | mapping_state (enum mstate state) |
b99bd4ef | 2286 | { |
a737bd4d | 2287 | symbolS * symbolP; |
c19d1205 ZW |
2288 | const char * symname; |
2289 | int type; | |
b99bd4ef | 2290 | |
c19d1205 ZW |
2291 | if (mapstate == state) |
2292 | /* The mapping symbol has already been emitted. | |
2293 | There is nothing else to do. */ | |
2294 | return; | |
b99bd4ef | 2295 | |
c19d1205 | 2296 | mapstate = state; |
b99bd4ef | 2297 | |
c19d1205 | 2298 | switch (state) |
b99bd4ef | 2299 | { |
c19d1205 ZW |
2300 | case MAP_DATA: |
2301 | symname = "$d"; | |
2302 | type = BSF_NO_FLAGS; | |
2303 | break; | |
2304 | case MAP_ARM: | |
2305 | symname = "$a"; | |
2306 | type = BSF_NO_FLAGS; | |
2307 | break; | |
2308 | case MAP_THUMB: | |
2309 | symname = "$t"; | |
2310 | type = BSF_NO_FLAGS; | |
2311 | break; | |
2312 | case MAP_UNDEFINED: | |
2313 | return; | |
2314 | default: | |
2315 | abort (); | |
2316 | } | |
2317 | ||
2318 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; | |
2319 | ||
2320 | symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now); | |
2321 | symbol_table_insert (symbolP); | |
2322 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; | |
2323 | ||
2324 | switch (state) | |
2325 | { | |
2326 | case MAP_ARM: | |
2327 | THUMB_SET_FUNC (symbolP, 0); | |
2328 | ARM_SET_THUMB (symbolP, 0); | |
2329 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2330 | break; | |
2331 | ||
2332 | case MAP_THUMB: | |
2333 | THUMB_SET_FUNC (symbolP, 1); | |
2334 | ARM_SET_THUMB (symbolP, 1); | |
2335 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2336 | break; | |
2337 | ||
2338 | case MAP_DATA: | |
2339 | default: | |
2340 | return; | |
2341 | } | |
2342 | } | |
2343 | #else | |
2344 | #define mapping_state(x) /* nothing */ | |
2345 | #endif | |
2346 | ||
2347 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2348 | ||
2349 | static symbolS * | |
2350 | find_real_start (symbolS * symbolP) | |
2351 | { | |
2352 | char * real_start; | |
2353 | const char * name = S_GET_NAME (symbolP); | |
2354 | symbolS * new_target; | |
2355 | ||
2356 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2357 | #define STUB_NAME ".real_start_of" | |
2358 | ||
2359 | if (name == NULL) | |
2360 | abort (); | |
2361 | ||
37f6032b ZW |
2362 | /* The compiler may generate BL instructions to local labels because |
2363 | it needs to perform a branch to a far away location. These labels | |
2364 | do not have a corresponding ".real_start_of" label. We check | |
2365 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2366 | the ".real_start_of" convention for nonlocal branches. */ | |
2367 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2368 | return symbolP; |
2369 | ||
37f6032b | 2370 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2371 | new_target = symbol_find (real_start); |
2372 | ||
2373 | if (new_target == NULL) | |
2374 | { | |
2375 | as_warn ("Failed to find real start of function: %s\n", name); | |
2376 | new_target = symbolP; | |
2377 | } | |
2378 | ||
c19d1205 ZW |
2379 | return new_target; |
2380 | } | |
2381 | ||
2382 | static void | |
2383 | opcode_select (int width) | |
2384 | { | |
2385 | switch (width) | |
2386 | { | |
2387 | case 16: | |
2388 | if (! thumb_mode) | |
2389 | { | |
e74cfd16 | 2390 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2391 | as_bad (_("selected processor does not support THUMB opcodes")); |
2392 | ||
2393 | thumb_mode = 1; | |
2394 | /* No need to force the alignment, since we will have been | |
2395 | coming from ARM mode, which is word-aligned. */ | |
2396 | record_alignment (now_seg, 1); | |
2397 | } | |
2398 | mapping_state (MAP_THUMB); | |
2399 | break; | |
2400 | ||
2401 | case 32: | |
2402 | if (thumb_mode) | |
2403 | { | |
e74cfd16 | 2404 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2405 | as_bad (_("selected processor does not support ARM opcodes")); |
2406 | ||
2407 | thumb_mode = 0; | |
2408 | ||
2409 | if (!need_pass_2) | |
2410 | frag_align (2, 0, 0); | |
2411 | ||
2412 | record_alignment (now_seg, 1); | |
2413 | } | |
2414 | mapping_state (MAP_ARM); | |
2415 | break; | |
2416 | ||
2417 | default: | |
2418 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2419 | } | |
2420 | } | |
2421 | ||
2422 | static void | |
2423 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2424 | { | |
2425 | opcode_select (32); | |
2426 | demand_empty_rest_of_line (); | |
2427 | } | |
2428 | ||
2429 | static void | |
2430 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2431 | { | |
2432 | opcode_select (16); | |
2433 | demand_empty_rest_of_line (); | |
2434 | } | |
2435 | ||
2436 | static void | |
2437 | s_code (int unused ATTRIBUTE_UNUSED) | |
2438 | { | |
2439 | int temp; | |
2440 | ||
2441 | temp = get_absolute_expression (); | |
2442 | switch (temp) | |
2443 | { | |
2444 | case 16: | |
2445 | case 32: | |
2446 | opcode_select (temp); | |
2447 | break; | |
2448 | ||
2449 | default: | |
2450 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2451 | } | |
2452 | } | |
2453 | ||
2454 | static void | |
2455 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2456 | { | |
2457 | /* If we are not already in thumb mode go into it, EVEN if | |
2458 | the target processor does not support thumb instructions. | |
2459 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2460 | to compile interworking support functions even if the | |
2461 | target processor should not support interworking. */ | |
2462 | if (! thumb_mode) | |
2463 | { | |
2464 | thumb_mode = 2; | |
2465 | record_alignment (now_seg, 1); | |
2466 | } | |
2467 | ||
2468 | demand_empty_rest_of_line (); | |
2469 | } | |
2470 | ||
2471 | static void | |
2472 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2473 | { | |
2474 | s_thumb (0); | |
2475 | ||
2476 | /* The following label is the name/address of the start of a Thumb function. | |
2477 | We need to know this for the interworking support. */ | |
2478 | label_is_thumb_function_name = TRUE; | |
2479 | } | |
2480 | ||
2481 | /* Perform a .set directive, but also mark the alias as | |
2482 | being a thumb function. */ | |
2483 | ||
2484 | static void | |
2485 | s_thumb_set (int equiv) | |
2486 | { | |
2487 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2488 | We cannot just call that code as we need to get at the symbol that | |
2489 | is created. */ | |
2490 | char * name; | |
2491 | char delim; | |
2492 | char * end_name; | |
2493 | symbolS * symbolP; | |
2494 | ||
2495 | /* Especial apologies for the random logic: | |
2496 | This just grew, and could be parsed much more simply! | |
2497 | Dean - in haste. */ | |
2498 | name = input_line_pointer; | |
2499 | delim = get_symbol_end (); | |
2500 | end_name = input_line_pointer; | |
2501 | *end_name = delim; | |
2502 | ||
2503 | if (*input_line_pointer != ',') | |
2504 | { | |
2505 | *end_name = 0; | |
2506 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2507 | *end_name = delim; |
2508 | ignore_rest_of_line (); | |
2509 | return; | |
2510 | } | |
2511 | ||
2512 | input_line_pointer++; | |
2513 | *end_name = 0; | |
2514 | ||
2515 | if (name[0] == '.' && name[1] == '\0') | |
2516 | { | |
2517 | /* XXX - this should not happen to .thumb_set. */ | |
2518 | abort (); | |
2519 | } | |
2520 | ||
2521 | if ((symbolP = symbol_find (name)) == NULL | |
2522 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2523 | { | |
2524 | #ifndef NO_LISTING | |
2525 | /* When doing symbol listings, play games with dummy fragments living | |
2526 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2527 | for this symbol. */ |
b99bd4ef NC |
2528 | if (listing & LISTING_SYMBOLS) |
2529 | { | |
2530 | extern struct list_info_struct * listing_tail; | |
a737bd4d | 2531 | fragS * dummy_frag = xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2532 | |
2533 | memset (dummy_frag, 0, sizeof (fragS)); | |
2534 | dummy_frag->fr_type = rs_fill; | |
2535 | dummy_frag->line = listing_tail; | |
2536 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2537 | dummy_frag->fr_symbol = symbolP; | |
2538 | } | |
2539 | else | |
2540 | #endif | |
2541 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2542 | ||
2543 | #ifdef OBJ_COFF | |
2544 | /* "set" symbols are local unless otherwise specified. */ | |
2545 | SF_SET_LOCAL (symbolP); | |
2546 | #endif /* OBJ_COFF */ | |
2547 | } /* Make a new symbol. */ | |
2548 | ||
2549 | symbol_table_insert (symbolP); | |
2550 | ||
2551 | * end_name = delim; | |
2552 | ||
2553 | if (equiv | |
2554 | && S_IS_DEFINED (symbolP) | |
2555 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2556 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2557 | ||
2558 | pseudo_set (symbolP); | |
2559 | ||
2560 | demand_empty_rest_of_line (); | |
2561 | ||
c19d1205 | 2562 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2563 | |
2564 | THUMB_SET_FUNC (symbolP, 1); | |
2565 | ARM_SET_THUMB (symbolP, 1); | |
2566 | #if defined OBJ_ELF || defined OBJ_COFF | |
2567 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2568 | #endif | |
2569 | } | |
2570 | ||
c19d1205 | 2571 | /* Directives: Mode selection. */ |
b99bd4ef | 2572 | |
c19d1205 ZW |
2573 | /* .syntax [unified|divided] - choose the new unified syntax |
2574 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2575 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2576 | static void |
c19d1205 | 2577 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2578 | { |
c19d1205 ZW |
2579 | char *name, delim; |
2580 | ||
2581 | name = input_line_pointer; | |
2582 | delim = get_symbol_end (); | |
2583 | ||
2584 | if (!strcasecmp (name, "unified")) | |
2585 | unified_syntax = TRUE; | |
2586 | else if (!strcasecmp (name, "divided")) | |
2587 | unified_syntax = FALSE; | |
2588 | else | |
2589 | { | |
2590 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2591 | return; | |
2592 | } | |
2593 | *input_line_pointer = delim; | |
b99bd4ef NC |
2594 | demand_empty_rest_of_line (); |
2595 | } | |
2596 | ||
c19d1205 ZW |
2597 | /* Directives: sectioning and alignment. */ |
2598 | ||
2599 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2600 | ||
b99bd4ef | 2601 | static void |
c19d1205 | 2602 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2603 | { |
a737bd4d | 2604 | int temp; |
c19d1205 ZW |
2605 | long temp_fill; |
2606 | long max_alignment = 15; | |
b99bd4ef NC |
2607 | |
2608 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2609 | if (temp > max_alignment) |
2610 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2611 | else if (temp < 0) | |
b99bd4ef | 2612 | { |
c19d1205 ZW |
2613 | as_bad (_("alignment negative. 0 assumed.")); |
2614 | temp = 0; | |
2615 | } | |
b99bd4ef | 2616 | |
c19d1205 ZW |
2617 | if (*input_line_pointer == ',') |
2618 | { | |
2619 | input_line_pointer++; | |
2620 | temp_fill = get_absolute_expression (); | |
b99bd4ef | 2621 | } |
c19d1205 ZW |
2622 | else |
2623 | temp_fill = 0; | |
b99bd4ef | 2624 | |
c19d1205 ZW |
2625 | if (!temp) |
2626 | temp = 2; | |
b99bd4ef | 2627 | |
c19d1205 ZW |
2628 | /* Only make a frag if we HAVE to. */ |
2629 | if (temp && !need_pass_2) | |
2630 | frag_align (temp, (int) temp_fill, 0); | |
2631 | demand_empty_rest_of_line (); | |
2632 | ||
2633 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2634 | } |
2635 | ||
c19d1205 ZW |
2636 | static void |
2637 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2638 | { |
c19d1205 ZW |
2639 | /* We don't support putting frags in the BSS segment, we fake it by |
2640 | marking in_bss, then looking at s_skip for clues. */ | |
2641 | subseg_set (bss_section, 0); | |
2642 | demand_empty_rest_of_line (); | |
2643 | mapping_state (MAP_DATA); | |
2644 | } | |
b99bd4ef | 2645 | |
c19d1205 ZW |
2646 | static void |
2647 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2648 | { | |
2649 | /* Never make frag if expect extra pass. */ | |
2650 | if (!need_pass_2) | |
2651 | frag_align (1, 0, 0); | |
b99bd4ef | 2652 | |
c19d1205 | 2653 | record_alignment (now_seg, 1); |
b99bd4ef | 2654 | |
c19d1205 | 2655 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2656 | } |
2657 | ||
c19d1205 | 2658 | /* Directives: Literal pools. */ |
a737bd4d | 2659 | |
c19d1205 ZW |
2660 | static literal_pool * |
2661 | find_literal_pool (void) | |
a737bd4d | 2662 | { |
c19d1205 | 2663 | literal_pool * pool; |
a737bd4d | 2664 | |
c19d1205 | 2665 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 2666 | { |
c19d1205 ZW |
2667 | if (pool->section == now_seg |
2668 | && pool->sub_section == now_subseg) | |
2669 | break; | |
a737bd4d NC |
2670 | } |
2671 | ||
c19d1205 | 2672 | return pool; |
a737bd4d NC |
2673 | } |
2674 | ||
c19d1205 ZW |
2675 | static literal_pool * |
2676 | find_or_make_literal_pool (void) | |
a737bd4d | 2677 | { |
c19d1205 ZW |
2678 | /* Next literal pool ID number. */ |
2679 | static unsigned int latest_pool_num = 1; | |
2680 | literal_pool * pool; | |
a737bd4d | 2681 | |
c19d1205 | 2682 | pool = find_literal_pool (); |
a737bd4d | 2683 | |
c19d1205 | 2684 | if (pool == NULL) |
a737bd4d | 2685 | { |
c19d1205 ZW |
2686 | /* Create a new pool. */ |
2687 | pool = xmalloc (sizeof (* pool)); | |
2688 | if (! pool) | |
2689 | return NULL; | |
a737bd4d | 2690 | |
c19d1205 ZW |
2691 | pool->next_free_entry = 0; |
2692 | pool->section = now_seg; | |
2693 | pool->sub_section = now_subseg; | |
2694 | pool->next = list_of_pools; | |
2695 | pool->symbol = NULL; | |
2696 | ||
2697 | /* Add it to the list. */ | |
2698 | list_of_pools = pool; | |
a737bd4d | 2699 | } |
a737bd4d | 2700 | |
c19d1205 ZW |
2701 | /* New pools, and emptied pools, will have a NULL symbol. */ |
2702 | if (pool->symbol == NULL) | |
a737bd4d | 2703 | { |
c19d1205 ZW |
2704 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
2705 | (valueT) 0, &zero_address_frag); | |
2706 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
2707 | } |
2708 | ||
c19d1205 ZW |
2709 | /* Done. */ |
2710 | return pool; | |
a737bd4d NC |
2711 | } |
2712 | ||
c19d1205 ZW |
2713 | /* Add the literal in the global 'inst' |
2714 | structure to the relevent literal pool. */ | |
b99bd4ef NC |
2715 | |
2716 | static int | |
c19d1205 | 2717 | add_to_lit_pool (void) |
b99bd4ef | 2718 | { |
c19d1205 ZW |
2719 | literal_pool * pool; |
2720 | unsigned int entry; | |
b99bd4ef | 2721 | |
c19d1205 ZW |
2722 | pool = find_or_make_literal_pool (); |
2723 | ||
2724 | /* Check if this literal value is already in the pool. */ | |
2725 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 2726 | { |
c19d1205 ZW |
2727 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
2728 | && (inst.reloc.exp.X_op == O_constant) | |
2729 | && (pool->literals[entry].X_add_number | |
2730 | == inst.reloc.exp.X_add_number) | |
2731 | && (pool->literals[entry].X_unsigned | |
2732 | == inst.reloc.exp.X_unsigned)) | |
2733 | break; | |
2734 | ||
2735 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
2736 | && (inst.reloc.exp.X_op == O_symbol) | |
2737 | && (pool->literals[entry].X_add_number | |
2738 | == inst.reloc.exp.X_add_number) | |
2739 | && (pool->literals[entry].X_add_symbol | |
2740 | == inst.reloc.exp.X_add_symbol) | |
2741 | && (pool->literals[entry].X_op_symbol | |
2742 | == inst.reloc.exp.X_op_symbol)) | |
2743 | break; | |
b99bd4ef NC |
2744 | } |
2745 | ||
c19d1205 ZW |
2746 | /* Do we need to create a new entry? */ |
2747 | if (entry == pool->next_free_entry) | |
2748 | { | |
2749 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
2750 | { | |
2751 | inst.error = _("literal pool overflow"); | |
2752 | return FAIL; | |
2753 | } | |
2754 | ||
2755 | pool->literals[entry] = inst.reloc.exp; | |
2756 | pool->next_free_entry += 1; | |
2757 | } | |
b99bd4ef | 2758 | |
c19d1205 ZW |
2759 | inst.reloc.exp.X_op = O_symbol; |
2760 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
2761 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 2762 | |
c19d1205 | 2763 | return SUCCESS; |
b99bd4ef NC |
2764 | } |
2765 | ||
c19d1205 ZW |
2766 | /* Can't use symbol_new here, so have to create a symbol and then at |
2767 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 2768 | |
c19d1205 ZW |
2769 | static void |
2770 | symbol_locate (symbolS * symbolP, | |
2771 | const char * name, /* It is copied, the caller can modify. */ | |
2772 | segT segment, /* Segment identifier (SEG_<something>). */ | |
2773 | valueT valu, /* Symbol value. */ | |
2774 | fragS * frag) /* Associated fragment. */ | |
2775 | { | |
2776 | unsigned int name_length; | |
2777 | char * preserved_copy_of_name; | |
e16bb312 | 2778 | |
c19d1205 ZW |
2779 | name_length = strlen (name) + 1; /* +1 for \0. */ |
2780 | obstack_grow (¬es, name, name_length); | |
2781 | preserved_copy_of_name = obstack_finish (¬es); | |
e16bb312 | 2782 | |
c19d1205 ZW |
2783 | #ifdef tc_canonicalize_symbol_name |
2784 | preserved_copy_of_name = | |
2785 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
2786 | #endif | |
b99bd4ef | 2787 | |
c19d1205 | 2788 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 2789 | |
c19d1205 ZW |
2790 | S_SET_SEGMENT (symbolP, segment); |
2791 | S_SET_VALUE (symbolP, valu); | |
2792 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 2793 | |
c19d1205 | 2794 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 2795 | |
c19d1205 ZW |
2796 | /* Link to end of symbol chain. */ |
2797 | { | |
2798 | extern int symbol_table_frozen; | |
b99bd4ef | 2799 | |
c19d1205 ZW |
2800 | if (symbol_table_frozen) |
2801 | abort (); | |
2802 | } | |
b99bd4ef | 2803 | |
c19d1205 | 2804 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 2805 | |
c19d1205 | 2806 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 2807 | |
c19d1205 ZW |
2808 | #ifdef tc_symbol_new_hook |
2809 | tc_symbol_new_hook (symbolP); | |
2810 | #endif | |
2811 | ||
2812 | #ifdef DEBUG_SYMS | |
2813 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
2814 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
2815 | } |
2816 | ||
b99bd4ef | 2817 | |
c19d1205 ZW |
2818 | static void |
2819 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 2820 | { |
c19d1205 ZW |
2821 | unsigned int entry; |
2822 | literal_pool * pool; | |
2823 | char sym_name[20]; | |
b99bd4ef | 2824 | |
c19d1205 ZW |
2825 | pool = find_literal_pool (); |
2826 | if (pool == NULL | |
2827 | || pool->symbol == NULL | |
2828 | || pool->next_free_entry == 0) | |
2829 | return; | |
b99bd4ef | 2830 | |
c19d1205 | 2831 | mapping_state (MAP_DATA); |
b99bd4ef | 2832 | |
c19d1205 ZW |
2833 | /* Align pool as you have word accesses. |
2834 | Only make a frag if we have to. */ | |
2835 | if (!need_pass_2) | |
2836 | frag_align (2, 0, 0); | |
b99bd4ef | 2837 | |
c19d1205 | 2838 | record_alignment (now_seg, 2); |
b99bd4ef | 2839 | |
c19d1205 | 2840 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 2841 | |
c19d1205 ZW |
2842 | symbol_locate (pool->symbol, sym_name, now_seg, |
2843 | (valueT) frag_now_fix (), frag_now); | |
2844 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 2845 | |
c19d1205 | 2846 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 2847 | |
c19d1205 ZW |
2848 | #if defined OBJ_COFF || defined OBJ_ELF |
2849 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
2850 | #endif | |
6c43fab6 | 2851 | |
c19d1205 ZW |
2852 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
2853 | /* First output the expression in the instruction to the pool. */ | |
2854 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 2855 | |
c19d1205 ZW |
2856 | /* Mark the pool as empty. */ |
2857 | pool->next_free_entry = 0; | |
2858 | pool->symbol = NULL; | |
b99bd4ef NC |
2859 | } |
2860 | ||
c19d1205 ZW |
2861 | #ifdef OBJ_ELF |
2862 | /* Forward declarations for functions below, in the MD interface | |
2863 | section. */ | |
2864 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
2865 | static valueT create_unwind_entry (int); | |
2866 | static void start_unwind_section (const segT, int); | |
2867 | static void add_unwind_opcode (valueT, int); | |
2868 | static void flush_pending_unwind (void); | |
b99bd4ef | 2869 | |
c19d1205 | 2870 | /* Directives: Data. */ |
b99bd4ef | 2871 | |
c19d1205 ZW |
2872 | static void |
2873 | s_arm_elf_cons (int nbytes) | |
2874 | { | |
2875 | expressionS exp; | |
b99bd4ef | 2876 | |
c19d1205 ZW |
2877 | #ifdef md_flush_pending_output |
2878 | md_flush_pending_output (); | |
2879 | #endif | |
b99bd4ef | 2880 | |
c19d1205 | 2881 | if (is_it_end_of_statement ()) |
b99bd4ef | 2882 | { |
c19d1205 ZW |
2883 | demand_empty_rest_of_line (); |
2884 | return; | |
b99bd4ef NC |
2885 | } |
2886 | ||
c19d1205 ZW |
2887 | #ifdef md_cons_align |
2888 | md_cons_align (nbytes); | |
2889 | #endif | |
b99bd4ef | 2890 | |
c19d1205 ZW |
2891 | mapping_state (MAP_DATA); |
2892 | do | |
b99bd4ef | 2893 | { |
c19d1205 ZW |
2894 | int reloc; |
2895 | char *base = input_line_pointer; | |
b99bd4ef | 2896 | |
c19d1205 | 2897 | expression (& exp); |
b99bd4ef | 2898 | |
c19d1205 ZW |
2899 | if (exp.X_op != O_symbol) |
2900 | emit_expr (&exp, (unsigned int) nbytes); | |
2901 | else | |
2902 | { | |
2903 | char *before_reloc = input_line_pointer; | |
2904 | reloc = parse_reloc (&input_line_pointer); | |
2905 | if (reloc == -1) | |
2906 | { | |
2907 | as_bad (_("unrecognized relocation suffix")); | |
2908 | ignore_rest_of_line (); | |
2909 | return; | |
2910 | } | |
2911 | else if (reloc == BFD_RELOC_UNUSED) | |
2912 | emit_expr (&exp, (unsigned int) nbytes); | |
2913 | else | |
2914 | { | |
2915 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
2916 | int size = bfd_get_reloc_size (howto); | |
b99bd4ef | 2917 | |
2fc8bdac ZW |
2918 | if (reloc == BFD_RELOC_ARM_PLT32) |
2919 | { | |
2920 | as_bad (_("(plt) is only valid on branch targets")); | |
2921 | reloc = BFD_RELOC_UNUSED; | |
2922 | size = 0; | |
2923 | } | |
2924 | ||
c19d1205 | 2925 | if (size > nbytes) |
2fc8bdac | 2926 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
2927 | howto->name, nbytes); |
2928 | else | |
2929 | { | |
2930 | /* We've parsed an expression stopping at O_symbol. | |
2931 | But there may be more expression left now that we | |
2932 | have parsed the relocation marker. Parse it again. | |
2933 | XXX Surely there is a cleaner way to do this. */ | |
2934 | char *p = input_line_pointer; | |
2935 | int offset; | |
2936 | char *save_buf = alloca (input_line_pointer - base); | |
2937 | memcpy (save_buf, base, input_line_pointer - base); | |
2938 | memmove (base + (input_line_pointer - before_reloc), | |
2939 | base, before_reloc - base); | |
2940 | ||
2941 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
2942 | expression (&exp); | |
2943 | memcpy (base, save_buf, p - base); | |
2944 | ||
2945 | offset = nbytes - size; | |
2946 | p = frag_more ((int) nbytes); | |
2947 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
2948 | size, &exp, 0, reloc); | |
2949 | } | |
2950 | } | |
2951 | } | |
b99bd4ef | 2952 | } |
c19d1205 | 2953 | while (*input_line_pointer++ == ','); |
b99bd4ef | 2954 | |
c19d1205 ZW |
2955 | /* Put terminator back into stream. */ |
2956 | input_line_pointer --; | |
2957 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
2958 | } |
2959 | ||
b99bd4ef | 2960 | |
c19d1205 | 2961 | /* Parse a .rel31 directive. */ |
b99bd4ef | 2962 | |
c19d1205 ZW |
2963 | static void |
2964 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
2965 | { | |
2966 | expressionS exp; | |
2967 | char *p; | |
2968 | valueT highbit; | |
b99bd4ef | 2969 | |
c19d1205 ZW |
2970 | highbit = 0; |
2971 | if (*input_line_pointer == '1') | |
2972 | highbit = 0x80000000; | |
2973 | else if (*input_line_pointer != '0') | |
2974 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 2975 | |
c19d1205 ZW |
2976 | input_line_pointer++; |
2977 | if (*input_line_pointer != ',') | |
2978 | as_bad (_("missing comma")); | |
2979 | input_line_pointer++; | |
b99bd4ef | 2980 | |
c19d1205 ZW |
2981 | #ifdef md_flush_pending_output |
2982 | md_flush_pending_output (); | |
2983 | #endif | |
b99bd4ef | 2984 | |
c19d1205 ZW |
2985 | #ifdef md_cons_align |
2986 | md_cons_align (4); | |
2987 | #endif | |
b99bd4ef | 2988 | |
c19d1205 | 2989 | mapping_state (MAP_DATA); |
b99bd4ef | 2990 | |
c19d1205 | 2991 | expression (&exp); |
b99bd4ef | 2992 | |
c19d1205 ZW |
2993 | p = frag_more (4); |
2994 | md_number_to_chars (p, highbit, 4); | |
2995 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
2996 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 2997 | |
c19d1205 | 2998 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2999 | } |
3000 | ||
c19d1205 | 3001 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3002 | |
c19d1205 | 3003 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3004 | |
c19d1205 ZW |
3005 | static void |
3006 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3007 | { | |
3008 | demand_empty_rest_of_line (); | |
3009 | /* Mark the start of the function. */ | |
3010 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3011 | |
c19d1205 ZW |
3012 | /* Reset the rest of the unwind info. */ |
3013 | unwind.opcode_count = 0; | |
3014 | unwind.table_entry = NULL; | |
3015 | unwind.personality_routine = NULL; | |
3016 | unwind.personality_index = -1; | |
3017 | unwind.frame_size = 0; | |
3018 | unwind.fp_offset = 0; | |
3019 | unwind.fp_reg = 13; | |
3020 | unwind.fp_used = 0; | |
3021 | unwind.sp_restored = 0; | |
3022 | } | |
b99bd4ef | 3023 | |
b99bd4ef | 3024 | |
c19d1205 ZW |
3025 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3026 | for the function. */ | |
b99bd4ef | 3027 | |
c19d1205 ZW |
3028 | static void |
3029 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3030 | { | |
3031 | demand_empty_rest_of_line (); | |
3032 | if (unwind.table_entry) | |
3033 | as_bad (_("dupicate .handlerdata directive")); | |
f02232aa | 3034 | |
c19d1205 ZW |
3035 | create_unwind_entry (1); |
3036 | } | |
a737bd4d | 3037 | |
c19d1205 | 3038 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3039 | |
c19d1205 ZW |
3040 | static void |
3041 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3042 | { | |
3043 | long where; | |
3044 | char *ptr; | |
3045 | valueT val; | |
f02232aa | 3046 | |
c19d1205 | 3047 | demand_empty_rest_of_line (); |
f02232aa | 3048 | |
c19d1205 ZW |
3049 | /* Add eh table entry. */ |
3050 | if (unwind.table_entry == NULL) | |
3051 | val = create_unwind_entry (0); | |
3052 | else | |
3053 | val = 0; | |
f02232aa | 3054 | |
c19d1205 ZW |
3055 | /* Add index table entry. This is two words. */ |
3056 | start_unwind_section (unwind.saved_seg, 1); | |
3057 | frag_align (2, 0, 0); | |
3058 | record_alignment (now_seg, 2); | |
b99bd4ef | 3059 | |
c19d1205 ZW |
3060 | ptr = frag_more (8); |
3061 | where = frag_now_fix () - 8; | |
f02232aa | 3062 | |
c19d1205 ZW |
3063 | /* Self relative offset of the function start. */ |
3064 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3065 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3066 | |
c19d1205 ZW |
3067 | /* Indicate dependency on EHABI-defined personality routines to the |
3068 | linker, if it hasn't been done already. */ | |
3069 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 | |
3070 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3071 | { | |
3072 | static const char *const name[] = { | |
3073 | "__aeabi_unwind_cpp_pr0", | |
3074 | "__aeabi_unwind_cpp_pr1", | |
3075 | "__aeabi_unwind_cpp_pr2" | |
3076 | }; | |
3077 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); | |
3078 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
3079 | marked_pr_dependency |= 1 << unwind.personality_index; | |
3080 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency | |
3081 | = marked_pr_dependency; | |
3082 | } | |
f02232aa | 3083 | |
c19d1205 ZW |
3084 | if (val) |
3085 | /* Inline exception table entry. */ | |
3086 | md_number_to_chars (ptr + 4, val, 4); | |
3087 | else | |
3088 | /* Self relative offset of the table entry. */ | |
3089 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3090 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3091 | |
c19d1205 ZW |
3092 | /* Restore the original section. */ |
3093 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
3094 | } | |
f02232aa | 3095 | |
f02232aa | 3096 | |
c19d1205 | 3097 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3098 | |
c19d1205 ZW |
3099 | static void |
3100 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3101 | { | |
3102 | demand_empty_rest_of_line (); | |
3103 | if (unwind.personality_routine || unwind.personality_index != -1) | |
3104 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3105 | |
c19d1205 ZW |
3106 | unwind.personality_index = -2; |
3107 | } | |
b99bd4ef | 3108 | |
b99bd4ef | 3109 | |
c19d1205 | 3110 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3111 | |
c19d1205 ZW |
3112 | static void |
3113 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3114 | { | |
3115 | expressionS exp; | |
b99bd4ef | 3116 | |
c19d1205 ZW |
3117 | if (unwind.personality_routine || unwind.personality_index != -1) |
3118 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3119 | |
c19d1205 | 3120 | expression (&exp); |
b99bd4ef | 3121 | |
c19d1205 ZW |
3122 | if (exp.X_op != O_constant |
3123 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3124 | { |
c19d1205 ZW |
3125 | as_bad (_("bad personality routine number")); |
3126 | ignore_rest_of_line (); | |
3127 | return; | |
b99bd4ef NC |
3128 | } |
3129 | ||
c19d1205 | 3130 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3131 | |
c19d1205 ZW |
3132 | demand_empty_rest_of_line (); |
3133 | } | |
e16bb312 | 3134 | |
e16bb312 | 3135 | |
c19d1205 | 3136 | /* Parse a personality directive. */ |
e16bb312 | 3137 | |
c19d1205 ZW |
3138 | static void |
3139 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3140 | { | |
3141 | char *name, *p, c; | |
a737bd4d | 3142 | |
c19d1205 ZW |
3143 | if (unwind.personality_routine || unwind.personality_index != -1) |
3144 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3145 | |
c19d1205 ZW |
3146 | name = input_line_pointer; |
3147 | c = get_symbol_end (); | |
3148 | p = input_line_pointer; | |
3149 | unwind.personality_routine = symbol_find_or_make (name); | |
3150 | *p = c; | |
3151 | demand_empty_rest_of_line (); | |
3152 | } | |
e16bb312 | 3153 | |
e16bb312 | 3154 | |
c19d1205 | 3155 | /* Parse a directive saving core registers. */ |
e16bb312 | 3156 | |
c19d1205 ZW |
3157 | static void |
3158 | s_arm_unwind_save_core (void) | |
e16bb312 | 3159 | { |
c19d1205 ZW |
3160 | valueT op; |
3161 | long range; | |
3162 | int n; | |
e16bb312 | 3163 | |
c19d1205 ZW |
3164 | range = parse_reg_list (&input_line_pointer); |
3165 | if (range == FAIL) | |
e16bb312 | 3166 | { |
c19d1205 ZW |
3167 | as_bad (_("expected register list")); |
3168 | ignore_rest_of_line (); | |
3169 | return; | |
3170 | } | |
e16bb312 | 3171 | |
c19d1205 | 3172 | demand_empty_rest_of_line (); |
e16bb312 | 3173 | |
c19d1205 ZW |
3174 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3175 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3176 | ip because it is clobbered by calls. */ | |
3177 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3178 | && (range & 0x3000) == 0x1000) | |
3179 | { | |
3180 | unwind.opcode_count--; | |
3181 | unwind.sp_restored = 0; | |
3182 | range = (range | 0x2000) & ~0x1000; | |
3183 | unwind.pending_offset = 0; | |
3184 | } | |
e16bb312 | 3185 | |
01ae4198 DJ |
3186 | /* Pop r4-r15. */ |
3187 | if (range & 0xfff0) | |
c19d1205 | 3188 | { |
01ae4198 DJ |
3189 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3190 | registers starting with r4, plus maybe r14. */ | |
3191 | for (n = 0; n < 8; n++) | |
3192 | { | |
3193 | /* Break at the first non-saved register. */ | |
3194 | if ((range & (1 << (n + 4))) == 0) | |
3195 | break; | |
3196 | } | |
3197 | /* See if there are any other bits set. */ | |
3198 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3199 | { | |
3200 | /* Use the long form. */ | |
3201 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3202 | add_unwind_opcode (op, 2); | |
3203 | } | |
0dd132b6 | 3204 | else |
01ae4198 DJ |
3205 | { |
3206 | /* Use the short form. */ | |
3207 | if (range & 0x4000) | |
3208 | op = 0xa8; /* Pop r14. */ | |
3209 | else | |
3210 | op = 0xa0; /* Do not pop r14. */ | |
3211 | op |= (n - 1); | |
3212 | add_unwind_opcode (op, 1); | |
3213 | } | |
c19d1205 | 3214 | } |
0dd132b6 | 3215 | |
c19d1205 ZW |
3216 | /* Pop r0-r3. */ |
3217 | if (range & 0xf) | |
3218 | { | |
3219 | op = 0xb100 | (range & 0xf); | |
3220 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3221 | } |
3222 | ||
c19d1205 ZW |
3223 | /* Record the number of bytes pushed. */ |
3224 | for (n = 0; n < 16; n++) | |
3225 | { | |
3226 | if (range & (1 << n)) | |
3227 | unwind.frame_size += 4; | |
3228 | } | |
0dd132b6 NC |
3229 | } |
3230 | ||
c19d1205 ZW |
3231 | |
3232 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3233 | |
3234 | static void | |
c19d1205 | 3235 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3236 | { |
c19d1205 ZW |
3237 | expressionS exp; |
3238 | int num_regs; | |
3239 | valueT op; | |
b99bd4ef | 3240 | |
c19d1205 ZW |
3241 | /* Get Number of registers to transfer. */ |
3242 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3243 | expression (&exp); | |
3244 | else | |
3245 | exp.X_op = O_illegal; | |
b99bd4ef | 3246 | |
c19d1205 | 3247 | if (exp.X_op != O_constant) |
b99bd4ef | 3248 | { |
c19d1205 ZW |
3249 | as_bad (_("expected , <constant>")); |
3250 | ignore_rest_of_line (); | |
b99bd4ef NC |
3251 | return; |
3252 | } | |
3253 | ||
c19d1205 ZW |
3254 | num_regs = exp.X_add_number; |
3255 | ||
3256 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3257 | { |
c19d1205 ZW |
3258 | as_bad (_("number of registers must be in the range [1:4]")); |
3259 | ignore_rest_of_line (); | |
b99bd4ef NC |
3260 | return; |
3261 | } | |
3262 | ||
c19d1205 | 3263 | demand_empty_rest_of_line (); |
b99bd4ef | 3264 | |
c19d1205 ZW |
3265 | if (reg == 4) |
3266 | { | |
3267 | /* Short form. */ | |
3268 | op = 0xb4 | (num_regs - 1); | |
3269 | add_unwind_opcode (op, 1); | |
3270 | } | |
b99bd4ef NC |
3271 | else |
3272 | { | |
c19d1205 ZW |
3273 | /* Long form. */ |
3274 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3275 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3276 | } |
c19d1205 | 3277 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3278 | } |
3279 | ||
c19d1205 | 3280 | |
fa073d69 MS |
3281 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3282 | ||
3283 | static void | |
3284 | s_arm_unwind_save_vfp_armv6 (void) | |
3285 | { | |
3286 | int count; | |
3287 | unsigned int start; | |
3288 | valueT op; | |
3289 | int num_vfpv3_regs = 0; | |
3290 | int num_regs_below_16; | |
3291 | ||
3292 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3293 | if (count == FAIL) | |
3294 | { | |
3295 | as_bad (_("expected register list")); | |
3296 | ignore_rest_of_line (); | |
3297 | return; | |
3298 | } | |
3299 | ||
3300 | demand_empty_rest_of_line (); | |
3301 | ||
3302 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3303 | than FSTMX/FLDMX-style ones). */ | |
3304 | ||
3305 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3306 | if (start >= 16) | |
3307 | num_vfpv3_regs = count; | |
3308 | else if (start + count > 16) | |
3309 | num_vfpv3_regs = start + count - 16; | |
3310 | ||
3311 | if (num_vfpv3_regs > 0) | |
3312 | { | |
3313 | int start_offset = start > 16 ? start - 16 : 0; | |
3314 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3315 | add_unwind_opcode (op, 2); | |
3316 | } | |
3317 | ||
3318 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3319 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
3320 | assert (num_regs_below_16 + num_vfpv3_regs == count); | |
3321 | if (num_regs_below_16 > 0) | |
3322 | { | |
3323 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3324 | add_unwind_opcode (op, 2); | |
3325 | } | |
3326 | ||
3327 | unwind.frame_size += count * 8; | |
3328 | } | |
3329 | ||
3330 | ||
3331 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3332 | |
3333 | static void | |
c19d1205 | 3334 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3335 | { |
c19d1205 | 3336 | int count; |
ca3f61f7 | 3337 | unsigned int reg; |
c19d1205 | 3338 | valueT op; |
b99bd4ef | 3339 | |
5287ad62 | 3340 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3341 | if (count == FAIL) |
b99bd4ef | 3342 | { |
c19d1205 ZW |
3343 | as_bad (_("expected register list")); |
3344 | ignore_rest_of_line (); | |
b99bd4ef NC |
3345 | return; |
3346 | } | |
3347 | ||
c19d1205 | 3348 | demand_empty_rest_of_line (); |
b99bd4ef | 3349 | |
c19d1205 | 3350 | if (reg == 8) |
b99bd4ef | 3351 | { |
c19d1205 ZW |
3352 | /* Short form. */ |
3353 | op = 0xb8 | (count - 1); | |
3354 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3355 | } |
c19d1205 | 3356 | else |
b99bd4ef | 3357 | { |
c19d1205 ZW |
3358 | /* Long form. */ |
3359 | op = 0xb300 | (reg << 4) | (count - 1); | |
3360 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3361 | } |
c19d1205 ZW |
3362 | unwind.frame_size += count * 8 + 4; |
3363 | } | |
b99bd4ef | 3364 | |
b99bd4ef | 3365 | |
c19d1205 ZW |
3366 | /* Parse a directive saving iWMMXt data registers. */ |
3367 | ||
3368 | static void | |
3369 | s_arm_unwind_save_mmxwr (void) | |
3370 | { | |
3371 | int reg; | |
3372 | int hi_reg; | |
3373 | int i; | |
3374 | unsigned mask = 0; | |
3375 | valueT op; | |
b99bd4ef | 3376 | |
c19d1205 ZW |
3377 | if (*input_line_pointer == '{') |
3378 | input_line_pointer++; | |
b99bd4ef | 3379 | |
c19d1205 | 3380 | do |
b99bd4ef | 3381 | { |
dcbf9037 | 3382 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3383 | |
c19d1205 | 3384 | if (reg == FAIL) |
b99bd4ef | 3385 | { |
c19d1205 ZW |
3386 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); |
3387 | goto error; | |
b99bd4ef NC |
3388 | } |
3389 | ||
c19d1205 ZW |
3390 | if (mask >> reg) |
3391 | as_tsktsk (_("register list not in ascending order")); | |
3392 | mask |= 1 << reg; | |
b99bd4ef | 3393 | |
c19d1205 ZW |
3394 | if (*input_line_pointer == '-') |
3395 | { | |
3396 | input_line_pointer++; | |
dcbf9037 | 3397 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3398 | if (hi_reg == FAIL) |
3399 | { | |
3400 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); | |
3401 | goto error; | |
3402 | } | |
3403 | else if (reg >= hi_reg) | |
3404 | { | |
3405 | as_bad (_("bad register range")); | |
3406 | goto error; | |
3407 | } | |
3408 | for (; reg < hi_reg; reg++) | |
3409 | mask |= 1 << reg; | |
3410 | } | |
3411 | } | |
3412 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3413 | |
c19d1205 ZW |
3414 | if (*input_line_pointer == '}') |
3415 | input_line_pointer++; | |
b99bd4ef | 3416 | |
c19d1205 | 3417 | demand_empty_rest_of_line (); |
b99bd4ef | 3418 | |
708587a4 | 3419 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3420 | the list. */ |
3421 | flush_pending_unwind (); | |
b99bd4ef | 3422 | |
c19d1205 | 3423 | for (i = 0; i < 16; i++) |
b99bd4ef | 3424 | { |
c19d1205 ZW |
3425 | if (mask & (1 << i)) |
3426 | unwind.frame_size += 8; | |
b99bd4ef NC |
3427 | } |
3428 | ||
c19d1205 ZW |
3429 | /* Attempt to combine with a previous opcode. We do this because gcc |
3430 | likes to output separate unwind directives for a single block of | |
3431 | registers. */ | |
3432 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3433 | { |
c19d1205 ZW |
3434 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3435 | if ((i & 0xf8) == 0xc0) | |
3436 | { | |
3437 | i &= 7; | |
3438 | /* Only merge if the blocks are contiguous. */ | |
3439 | if (i < 6) | |
3440 | { | |
3441 | if ((mask & 0xfe00) == (1 << 9)) | |
3442 | { | |
3443 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3444 | unwind.opcode_count--; | |
3445 | } | |
3446 | } | |
3447 | else if (i == 6 && unwind.opcode_count >= 2) | |
3448 | { | |
3449 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3450 | reg = i >> 4; | |
3451 | i &= 0xf; | |
b99bd4ef | 3452 | |
c19d1205 ZW |
3453 | op = 0xffff << (reg - 1); |
3454 | if (reg > 0 | |
87a1fd79 | 3455 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
3456 | { |
3457 | op = (1 << (reg + i + 1)) - 1; | |
3458 | op &= ~((1 << reg) - 1); | |
3459 | mask |= op; | |
3460 | unwind.opcode_count -= 2; | |
3461 | } | |
3462 | } | |
3463 | } | |
b99bd4ef NC |
3464 | } |
3465 | ||
c19d1205 ZW |
3466 | hi_reg = 15; |
3467 | /* We want to generate opcodes in the order the registers have been | |
3468 | saved, ie. descending order. */ | |
3469 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3470 | { |
c19d1205 ZW |
3471 | /* Save registers in blocks. */ |
3472 | if (reg < 0 | |
3473 | || !(mask & (1 << reg))) | |
3474 | { | |
3475 | /* We found an unsaved reg. Generate opcodes to save the | |
3476 | preceeding block. */ | |
3477 | if (reg != hi_reg) | |
3478 | { | |
3479 | if (reg == 9) | |
3480 | { | |
3481 | /* Short form. */ | |
3482 | op = 0xc0 | (hi_reg - 10); | |
3483 | add_unwind_opcode (op, 1); | |
3484 | } | |
3485 | else | |
3486 | { | |
3487 | /* Long form. */ | |
3488 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
3489 | add_unwind_opcode (op, 2); | |
3490 | } | |
3491 | } | |
3492 | hi_reg = reg - 1; | |
3493 | } | |
b99bd4ef NC |
3494 | } |
3495 | ||
c19d1205 ZW |
3496 | return; |
3497 | error: | |
3498 | ignore_rest_of_line (); | |
b99bd4ef NC |
3499 | } |
3500 | ||
3501 | static void | |
c19d1205 | 3502 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 3503 | { |
c19d1205 ZW |
3504 | int reg; |
3505 | int hi_reg; | |
3506 | unsigned mask = 0; | |
3507 | valueT op; | |
b99bd4ef | 3508 | |
c19d1205 ZW |
3509 | if (*input_line_pointer == '{') |
3510 | input_line_pointer++; | |
b99bd4ef | 3511 | |
c19d1205 | 3512 | do |
b99bd4ef | 3513 | { |
dcbf9037 | 3514 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 3515 | |
c19d1205 ZW |
3516 | if (reg == FAIL) |
3517 | { | |
3518 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
3519 | goto error; | |
3520 | } | |
b99bd4ef | 3521 | |
c19d1205 ZW |
3522 | reg -= 8; |
3523 | if (mask >> reg) | |
3524 | as_tsktsk (_("register list not in ascending order")); | |
3525 | mask |= 1 << reg; | |
b99bd4ef | 3526 | |
c19d1205 ZW |
3527 | if (*input_line_pointer == '-') |
3528 | { | |
3529 | input_line_pointer++; | |
dcbf9037 | 3530 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
3531 | if (hi_reg == FAIL) |
3532 | { | |
3533 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
3534 | goto error; | |
3535 | } | |
3536 | else if (reg >= hi_reg) | |
3537 | { | |
3538 | as_bad (_("bad register range")); | |
3539 | goto error; | |
3540 | } | |
3541 | for (; reg < hi_reg; reg++) | |
3542 | mask |= 1 << reg; | |
3543 | } | |
b99bd4ef | 3544 | } |
c19d1205 | 3545 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 3546 | |
c19d1205 ZW |
3547 | if (*input_line_pointer == '}') |
3548 | input_line_pointer++; | |
b99bd4ef | 3549 | |
c19d1205 ZW |
3550 | demand_empty_rest_of_line (); |
3551 | ||
708587a4 | 3552 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3553 | the list. */ |
3554 | flush_pending_unwind (); | |
b99bd4ef | 3555 | |
c19d1205 | 3556 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 3557 | { |
c19d1205 ZW |
3558 | if (mask & (1 << reg)) |
3559 | unwind.frame_size += 4; | |
b99bd4ef | 3560 | } |
c19d1205 ZW |
3561 | op = 0xc700 | mask; |
3562 | add_unwind_opcode (op, 2); | |
3563 | return; | |
3564 | error: | |
3565 | ignore_rest_of_line (); | |
b99bd4ef NC |
3566 | } |
3567 | ||
c19d1205 | 3568 | |
fa073d69 MS |
3569 | /* Parse an unwind_save directive. |
3570 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 3571 | |
b99bd4ef | 3572 | static void |
fa073d69 | 3573 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 3574 | { |
c19d1205 ZW |
3575 | char *peek; |
3576 | struct reg_entry *reg; | |
3577 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 3578 | |
c19d1205 ZW |
3579 | /* Figure out what sort of save we have. */ |
3580 | peek = input_line_pointer; | |
b99bd4ef | 3581 | |
c19d1205 | 3582 | if (*peek == '{') |
b99bd4ef | 3583 | { |
c19d1205 ZW |
3584 | had_brace = TRUE; |
3585 | peek++; | |
b99bd4ef NC |
3586 | } |
3587 | ||
c19d1205 | 3588 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 3589 | |
c19d1205 | 3590 | if (!reg) |
b99bd4ef | 3591 | { |
c19d1205 ZW |
3592 | as_bad (_("register expected")); |
3593 | ignore_rest_of_line (); | |
b99bd4ef NC |
3594 | return; |
3595 | } | |
3596 | ||
c19d1205 | 3597 | switch (reg->type) |
b99bd4ef | 3598 | { |
c19d1205 ZW |
3599 | case REG_TYPE_FN: |
3600 | if (had_brace) | |
3601 | { | |
3602 | as_bad (_("FPA .unwind_save does not take a register list")); | |
3603 | ignore_rest_of_line (); | |
3604 | return; | |
3605 | } | |
3606 | s_arm_unwind_save_fpa (reg->number); | |
b99bd4ef | 3607 | return; |
c19d1205 ZW |
3608 | |
3609 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
3610 | case REG_TYPE_VFD: |
3611 | if (arch_v6) | |
3612 | s_arm_unwind_save_vfp_armv6 (); | |
3613 | else | |
3614 | s_arm_unwind_save_vfp (); | |
3615 | return; | |
c19d1205 ZW |
3616 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
3617 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
3618 | ||
3619 | default: | |
3620 | as_bad (_(".unwind_save does not support this kind of register")); | |
3621 | ignore_rest_of_line (); | |
b99bd4ef | 3622 | } |
c19d1205 | 3623 | } |
b99bd4ef | 3624 | |
b99bd4ef | 3625 | |
c19d1205 ZW |
3626 | /* Parse an unwind_movsp directive. */ |
3627 | ||
3628 | static void | |
3629 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
3630 | { | |
3631 | int reg; | |
3632 | valueT op; | |
4fa3602b | 3633 | int offset; |
c19d1205 | 3634 | |
dcbf9037 | 3635 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 3636 | if (reg == FAIL) |
b99bd4ef | 3637 | { |
c19d1205 ZW |
3638 | as_bad (_(reg_expected_msgs[REG_TYPE_RN])); |
3639 | ignore_rest_of_line (); | |
b99bd4ef NC |
3640 | return; |
3641 | } | |
4fa3602b PB |
3642 | |
3643 | /* Optional constant. */ | |
3644 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3645 | { | |
3646 | if (immediate_for_directive (&offset) == FAIL) | |
3647 | return; | |
3648 | } | |
3649 | else | |
3650 | offset = 0; | |
3651 | ||
c19d1205 | 3652 | demand_empty_rest_of_line (); |
b99bd4ef | 3653 | |
c19d1205 | 3654 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 3655 | { |
c19d1205 | 3656 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
3657 | return; |
3658 | } | |
3659 | ||
c19d1205 ZW |
3660 | if (unwind.fp_reg != REG_SP) |
3661 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 3662 | |
c19d1205 ZW |
3663 | /* Generate opcode to restore the value. */ |
3664 | op = 0x90 | reg; | |
3665 | add_unwind_opcode (op, 1); | |
3666 | ||
3667 | /* Record the information for later. */ | |
3668 | unwind.fp_reg = reg; | |
4fa3602b | 3669 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 3670 | unwind.sp_restored = 1; |
b05fe5cf ZW |
3671 | } |
3672 | ||
c19d1205 ZW |
3673 | /* Parse an unwind_pad directive. */ |
3674 | ||
b05fe5cf | 3675 | static void |
c19d1205 | 3676 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 3677 | { |
c19d1205 | 3678 | int offset; |
b05fe5cf | 3679 | |
c19d1205 ZW |
3680 | if (immediate_for_directive (&offset) == FAIL) |
3681 | return; | |
b99bd4ef | 3682 | |
c19d1205 ZW |
3683 | if (offset & 3) |
3684 | { | |
3685 | as_bad (_("stack increment must be multiple of 4")); | |
3686 | ignore_rest_of_line (); | |
3687 | return; | |
3688 | } | |
b99bd4ef | 3689 | |
c19d1205 ZW |
3690 | /* Don't generate any opcodes, just record the details for later. */ |
3691 | unwind.frame_size += offset; | |
3692 | unwind.pending_offset += offset; | |
3693 | ||
3694 | demand_empty_rest_of_line (); | |
3695 | } | |
3696 | ||
3697 | /* Parse an unwind_setfp directive. */ | |
3698 | ||
3699 | static void | |
3700 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3701 | { |
c19d1205 ZW |
3702 | int sp_reg; |
3703 | int fp_reg; | |
3704 | int offset; | |
3705 | ||
dcbf9037 | 3706 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
3707 | if (skip_past_comma (&input_line_pointer) == FAIL) |
3708 | sp_reg = FAIL; | |
3709 | else | |
dcbf9037 | 3710 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 3711 | |
c19d1205 ZW |
3712 | if (fp_reg == FAIL || sp_reg == FAIL) |
3713 | { | |
3714 | as_bad (_("expected <reg>, <reg>")); | |
3715 | ignore_rest_of_line (); | |
3716 | return; | |
3717 | } | |
b99bd4ef | 3718 | |
c19d1205 ZW |
3719 | /* Optional constant. */ |
3720 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3721 | { | |
3722 | if (immediate_for_directive (&offset) == FAIL) | |
3723 | return; | |
3724 | } | |
3725 | else | |
3726 | offset = 0; | |
a737bd4d | 3727 | |
c19d1205 | 3728 | demand_empty_rest_of_line (); |
a737bd4d | 3729 | |
c19d1205 | 3730 | if (sp_reg != 13 && sp_reg != unwind.fp_reg) |
a737bd4d | 3731 | { |
c19d1205 ZW |
3732 | as_bad (_("register must be either sp or set by a previous" |
3733 | "unwind_movsp directive")); | |
3734 | return; | |
a737bd4d NC |
3735 | } |
3736 | ||
c19d1205 ZW |
3737 | /* Don't generate any opcodes, just record the information for later. */ |
3738 | unwind.fp_reg = fp_reg; | |
3739 | unwind.fp_used = 1; | |
3740 | if (sp_reg == 13) | |
3741 | unwind.fp_offset = unwind.frame_size - offset; | |
3742 | else | |
3743 | unwind.fp_offset -= offset; | |
a737bd4d NC |
3744 | } |
3745 | ||
c19d1205 ZW |
3746 | /* Parse an unwind_raw directive. */ |
3747 | ||
3748 | static void | |
3749 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 3750 | { |
c19d1205 | 3751 | expressionS exp; |
708587a4 | 3752 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
3753 | unsigned char op[16]; |
3754 | int count; | |
a737bd4d | 3755 | |
c19d1205 ZW |
3756 | expression (&exp); |
3757 | if (exp.X_op == O_constant | |
3758 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 3759 | { |
c19d1205 ZW |
3760 | unwind.frame_size += exp.X_add_number; |
3761 | expression (&exp); | |
3762 | } | |
3763 | else | |
3764 | exp.X_op = O_illegal; | |
a737bd4d | 3765 | |
c19d1205 ZW |
3766 | if (exp.X_op != O_constant) |
3767 | { | |
3768 | as_bad (_("expected <offset>, <opcode>")); | |
3769 | ignore_rest_of_line (); | |
3770 | return; | |
3771 | } | |
a737bd4d | 3772 | |
c19d1205 | 3773 | count = 0; |
a737bd4d | 3774 | |
c19d1205 ZW |
3775 | /* Parse the opcode. */ |
3776 | for (;;) | |
3777 | { | |
3778 | if (count >= 16) | |
3779 | { | |
3780 | as_bad (_("unwind opcode too long")); | |
3781 | ignore_rest_of_line (); | |
a737bd4d | 3782 | } |
c19d1205 | 3783 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 3784 | { |
c19d1205 ZW |
3785 | as_bad (_("invalid unwind opcode")); |
3786 | ignore_rest_of_line (); | |
3787 | return; | |
a737bd4d | 3788 | } |
c19d1205 | 3789 | op[count++] = exp.X_add_number; |
a737bd4d | 3790 | |
c19d1205 ZW |
3791 | /* Parse the next byte. */ |
3792 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
3793 | break; | |
a737bd4d | 3794 | |
c19d1205 ZW |
3795 | expression (&exp); |
3796 | } | |
b99bd4ef | 3797 | |
c19d1205 ZW |
3798 | /* Add the opcode bytes in reverse order. */ |
3799 | while (count--) | |
3800 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 3801 | |
c19d1205 | 3802 | demand_empty_rest_of_line (); |
b99bd4ef | 3803 | } |
ee065d83 PB |
3804 | |
3805 | ||
3806 | /* Parse a .eabi_attribute directive. */ | |
3807 | ||
3808 | static void | |
3809 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
3810 | { | |
3811 | expressionS exp; | |
3812 | bfd_boolean is_string; | |
3813 | int tag; | |
3814 | unsigned int i = 0; | |
3815 | char *s = NULL; | |
3816 | char saved_char; | |
3817 | ||
3818 | expression (& exp); | |
3819 | if (exp.X_op != O_constant) | |
3820 | goto bad; | |
3821 | ||
3822 | tag = exp.X_add_number; | |
3823 | if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0)) | |
3824 | is_string = 1; | |
3825 | else | |
3826 | is_string = 0; | |
3827 | ||
3828 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
3829 | goto bad; | |
3830 | if (tag == 32 || !is_string) | |
3831 | { | |
3832 | expression (& exp); | |
3833 | if (exp.X_op != O_constant) | |
3834 | { | |
3835 | as_bad (_("expected numeric constant")); | |
3836 | ignore_rest_of_line (); | |
3837 | return; | |
3838 | } | |
3839 | i = exp.X_add_number; | |
3840 | } | |
3841 | if (tag == Tag_compatibility | |
3842 | && skip_past_comma (&input_line_pointer) == FAIL) | |
3843 | { | |
3844 | as_bad (_("expected comma")); | |
3845 | ignore_rest_of_line (); | |
3846 | return; | |
3847 | } | |
3848 | if (is_string) | |
3849 | { | |
3850 | skip_whitespace(input_line_pointer); | |
3851 | if (*input_line_pointer != '"') | |
3852 | goto bad_string; | |
3853 | input_line_pointer++; | |
3854 | s = input_line_pointer; | |
3855 | while (*input_line_pointer && *input_line_pointer != '"') | |
3856 | input_line_pointer++; | |
3857 | if (*input_line_pointer != '"') | |
3858 | goto bad_string; | |
3859 | saved_char = *input_line_pointer; | |
3860 | *input_line_pointer = 0; | |
3861 | } | |
3862 | else | |
3863 | { | |
3864 | s = NULL; | |
3865 | saved_char = 0; | |
3866 | } | |
3867 | ||
3868 | if (tag == Tag_compatibility) | |
3869 | elf32_arm_add_eabi_attr_compat (stdoutput, i, s); | |
3870 | else if (is_string) | |
3871 | elf32_arm_add_eabi_attr_string (stdoutput, tag, s); | |
3872 | else | |
3873 | elf32_arm_add_eabi_attr_int (stdoutput, tag, i); | |
3874 | ||
3875 | if (s) | |
3876 | { | |
3877 | *input_line_pointer = saved_char; | |
3878 | input_line_pointer++; | |
3879 | } | |
3880 | demand_empty_rest_of_line (); | |
3881 | return; | |
3882 | bad_string: | |
3883 | as_bad (_("bad string constant")); | |
3884 | ignore_rest_of_line (); | |
3885 | return; | |
3886 | bad: | |
3887 | as_bad (_("expected <tag> , <value>")); | |
3888 | ignore_rest_of_line (); | |
3889 | } | |
8463be01 | 3890 | #endif /* OBJ_ELF */ |
ee065d83 PB |
3891 | |
3892 | static void s_arm_arch (int); | |
3893 | static void s_arm_cpu (int); | |
3894 | static void s_arm_fpu (int); | |
b99bd4ef | 3895 | |
f0927246 NC |
3896 | #ifdef TE_PE |
3897 | ||
3898 | static void | |
3899 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) | |
3900 | { | |
3901 | expressionS exp; | |
3902 | ||
3903 | do | |
3904 | { | |
3905 | expression (&exp); | |
3906 | if (exp.X_op == O_symbol) | |
3907 | exp.X_op = O_secrel; | |
3908 | ||
3909 | emit_expr (&exp, 4); | |
3910 | } | |
3911 | while (*input_line_pointer++ == ','); | |
3912 | ||
3913 | input_line_pointer--; | |
3914 | demand_empty_rest_of_line (); | |
3915 | } | |
3916 | #endif /* TE_PE */ | |
3917 | ||
c19d1205 ZW |
3918 | /* This table describes all the machine specific pseudo-ops the assembler |
3919 | has to support. The fields are: | |
3920 | pseudo-op name without dot | |
3921 | function to call to execute this pseudo-op | |
3922 | Integer arg to pass to the function. */ | |
b99bd4ef | 3923 | |
c19d1205 | 3924 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 3925 | { |
c19d1205 ZW |
3926 | /* Never called because '.req' does not start a line. */ |
3927 | { "req", s_req, 0 }, | |
dcbf9037 JB |
3928 | /* Following two are likewise never called. */ |
3929 | { "dn", s_dn, 0 }, | |
3930 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
3931 | { "unreq", s_unreq, 0 }, |
3932 | { "bss", s_bss, 0 }, | |
3933 | { "align", s_align, 0 }, | |
3934 | { "arm", s_arm, 0 }, | |
3935 | { "thumb", s_thumb, 0 }, | |
3936 | { "code", s_code, 0 }, | |
3937 | { "force_thumb", s_force_thumb, 0 }, | |
3938 | { "thumb_func", s_thumb_func, 0 }, | |
3939 | { "thumb_set", s_thumb_set, 0 }, | |
3940 | { "even", s_even, 0 }, | |
3941 | { "ltorg", s_ltorg, 0 }, | |
3942 | { "pool", s_ltorg, 0 }, | |
3943 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
3944 | { "cpu", s_arm_cpu, 0 }, |
3945 | { "arch", s_arm_arch, 0 }, | |
3946 | { "fpu", s_arm_fpu, 0 }, | |
c19d1205 ZW |
3947 | #ifdef OBJ_ELF |
3948 | { "word", s_arm_elf_cons, 4 }, | |
3949 | { "long", s_arm_elf_cons, 4 }, | |
3950 | { "rel31", s_arm_rel31, 0 }, | |
3951 | { "fnstart", s_arm_unwind_fnstart, 0 }, | |
3952 | { "fnend", s_arm_unwind_fnend, 0 }, | |
3953 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
3954 | { "personality", s_arm_unwind_personality, 0 }, | |
3955 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
3956 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
3957 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 3958 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
3959 | { "movsp", s_arm_unwind_movsp, 0 }, |
3960 | { "pad", s_arm_unwind_pad, 0 }, | |
3961 | { "setfp", s_arm_unwind_setfp, 0 }, | |
3962 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 3963 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
3964 | #else |
3965 | { "word", cons, 4}, | |
f0927246 NC |
3966 | |
3967 | /* These are used for dwarf. */ | |
3968 | {"2byte", cons, 2}, | |
3969 | {"4byte", cons, 4}, | |
3970 | {"8byte", cons, 8}, | |
3971 | /* These are used for dwarf2. */ | |
3972 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
3973 | { "loc", dwarf2_directive_loc, 0 }, | |
3974 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
3975 | #endif |
3976 | { "extend", float_cons, 'x' }, | |
3977 | { "ldouble", float_cons, 'x' }, | |
3978 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
3979 | #ifdef TE_PE |
3980 | {"secrel32", pe_directive_secrel, 0}, | |
3981 | #endif | |
c19d1205 ZW |
3982 | { 0, 0, 0 } |
3983 | }; | |
3984 | \f | |
3985 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 3986 | |
c19d1205 ZW |
3987 | /* Generic immediate-value read function for use in insn parsing. |
3988 | STR points to the beginning of the immediate (the leading #); | |
3989 | VAL receives the value; if the value is outside [MIN, MAX] | |
3990 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
3991 | optional. */ | |
b99bd4ef | 3992 | |
c19d1205 ZW |
3993 | static int |
3994 | parse_immediate (char **str, int *val, int min, int max, | |
3995 | bfd_boolean prefix_opt) | |
3996 | { | |
3997 | expressionS exp; | |
3998 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
3999 | if (exp.X_op != O_constant) | |
b99bd4ef | 4000 | { |
c19d1205 ZW |
4001 | inst.error = _("constant expression required"); |
4002 | return FAIL; | |
4003 | } | |
b99bd4ef | 4004 | |
c19d1205 ZW |
4005 | if (exp.X_add_number < min || exp.X_add_number > max) |
4006 | { | |
4007 | inst.error = _("immediate value out of range"); | |
4008 | return FAIL; | |
4009 | } | |
b99bd4ef | 4010 | |
c19d1205 ZW |
4011 | *val = exp.X_add_number; |
4012 | return SUCCESS; | |
4013 | } | |
b99bd4ef | 4014 | |
5287ad62 | 4015 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4016 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4017 | instructions. Puts the result directly in inst.operands[i]. */ |
4018 | ||
4019 | static int | |
4020 | parse_big_immediate (char **str, int i) | |
4021 | { | |
4022 | expressionS exp; | |
4023 | char *ptr = *str; | |
4024 | ||
4025 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
4026 | ||
4027 | if (exp.X_op == O_constant) | |
036dc3f7 PB |
4028 | { |
4029 | inst.operands[i].imm = exp.X_add_number & 0xffffffff; | |
4030 | /* If we're on a 64-bit host, then a 64-bit number can be returned using | |
4031 | O_constant. We have to be careful not to break compilation for | |
4032 | 32-bit X_add_number, though. */ | |
4033 | if ((exp.X_add_number & ~0xffffffffl) != 0) | |
4034 | { | |
4035 | /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */ | |
4036 | inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff; | |
4037 | inst.operands[i].regisimm = 1; | |
4038 | } | |
4039 | } | |
5287ad62 JB |
4040 | else if (exp.X_op == O_big |
4041 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32 | |
4042 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64) | |
4043 | { | |
4044 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
4045 | /* Bignums have their least significant bits in | |
4046 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
4047 | 32 bits in reg, in a (hopefully) portable way. */ | |
4048 | assert (parts != 0); | |
4049 | inst.operands[i].imm = 0; | |
4050 | for (j = 0; j < parts; j++, idx++) | |
4051 | inst.operands[i].imm |= generic_bignum[idx] | |
4052 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4053 | inst.operands[i].reg = 0; | |
4054 | for (j = 0; j < parts; j++, idx++) | |
4055 | inst.operands[i].reg |= generic_bignum[idx] | |
4056 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4057 | inst.operands[i].regisimm = 1; | |
4058 | } | |
4059 | else | |
4060 | return FAIL; | |
4061 | ||
4062 | *str = ptr; | |
4063 | ||
4064 | return SUCCESS; | |
4065 | } | |
4066 | ||
c19d1205 ZW |
4067 | /* Returns the pseudo-register number of an FPA immediate constant, |
4068 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4069 | |
c19d1205 ZW |
4070 | static int |
4071 | parse_fpa_immediate (char ** str) | |
4072 | { | |
4073 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4074 | char * save_in; | |
4075 | expressionS exp; | |
4076 | int i; | |
4077 | int j; | |
b99bd4ef | 4078 | |
c19d1205 ZW |
4079 | /* First try and match exact strings, this is to guarantee |
4080 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4081 | |
c19d1205 ZW |
4082 | for (i = 0; fp_const[i]; i++) |
4083 | { | |
4084 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4085 | { |
c19d1205 | 4086 | char *start = *str; |
b99bd4ef | 4087 | |
c19d1205 ZW |
4088 | *str += strlen (fp_const[i]); |
4089 | if (is_end_of_line[(unsigned char) **str]) | |
4090 | return i + 8; | |
4091 | *str = start; | |
4092 | } | |
4093 | } | |
b99bd4ef | 4094 | |
c19d1205 ZW |
4095 | /* Just because we didn't get a match doesn't mean that the constant |
4096 | isn't valid, just that it is in a format that we don't | |
4097 | automatically recognize. Try parsing it with the standard | |
4098 | expression routines. */ | |
b99bd4ef | 4099 | |
c19d1205 | 4100 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4101 | |
c19d1205 ZW |
4102 | /* Look for a raw floating point number. */ |
4103 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4104 | && is_end_of_line[(unsigned char) *save_in]) | |
4105 | { | |
4106 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4107 | { | |
4108 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4109 | { |
c19d1205 ZW |
4110 | if (words[j] != fp_values[i][j]) |
4111 | break; | |
b99bd4ef NC |
4112 | } |
4113 | ||
c19d1205 | 4114 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4115 | { |
c19d1205 ZW |
4116 | *str = save_in; |
4117 | return i + 8; | |
b99bd4ef NC |
4118 | } |
4119 | } | |
4120 | } | |
b99bd4ef | 4121 | |
c19d1205 ZW |
4122 | /* Try and parse a more complex expression, this will probably fail |
4123 | unless the code uses a floating point prefix (eg "0f"). */ | |
4124 | save_in = input_line_pointer; | |
4125 | input_line_pointer = *str; | |
4126 | if (expression (&exp) == absolute_section | |
4127 | && exp.X_op == O_big | |
4128 | && exp.X_add_number < 0) | |
4129 | { | |
4130 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4131 | Ditto for 15. */ | |
4132 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4133 | { | |
4134 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4135 | { | |
4136 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4137 | { | |
4138 | if (words[j] != fp_values[i][j]) | |
4139 | break; | |
4140 | } | |
b99bd4ef | 4141 | |
c19d1205 ZW |
4142 | if (j == MAX_LITTLENUMS) |
4143 | { | |
4144 | *str = input_line_pointer; | |
4145 | input_line_pointer = save_in; | |
4146 | return i + 8; | |
4147 | } | |
4148 | } | |
4149 | } | |
b99bd4ef NC |
4150 | } |
4151 | ||
c19d1205 ZW |
4152 | *str = input_line_pointer; |
4153 | input_line_pointer = save_in; | |
4154 | inst.error = _("invalid FPA immediate expression"); | |
4155 | return FAIL; | |
b99bd4ef NC |
4156 | } |
4157 | ||
136da414 JB |
4158 | /* Returns 1 if a number has "quarter-precision" float format |
4159 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4160 | ||
4161 | static int | |
4162 | is_quarter_float (unsigned imm) | |
4163 | { | |
4164 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4165 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4166 | } | |
4167 | ||
4168 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4169 | 0baBbbbbbc defgh000 00000000 00000000. | |
4170 | The minus-zero case needs special handling, since it can't be encoded in the | |
4171 | "quarter-precision" float format, but can nonetheless be loaded as an integer | |
4172 | constant. */ | |
4173 | ||
4174 | static unsigned | |
4175 | parse_qfloat_immediate (char **ccp, int *immed) | |
4176 | { | |
4177 | char *str = *ccp; | |
4178 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4179 | ||
4180 | skip_past_char (&str, '#'); | |
4181 | ||
4182 | if ((str = atof_ieee (str, 's', words)) != NULL) | |
4183 | { | |
4184 | unsigned fpword = 0; | |
4185 | int i; | |
4186 | ||
4187 | /* Our FP word must be 32 bits (single-precision FP). */ | |
4188 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4189 | { | |
4190 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4191 | fpword |= words[i]; | |
4192 | } | |
4193 | ||
4194 | if (is_quarter_float (fpword) || fpword == 0x80000000) | |
4195 | *immed = fpword; | |
4196 | else | |
4197 | return FAIL; | |
4198 | ||
4199 | *ccp = str; | |
4200 | ||
4201 | return SUCCESS; | |
4202 | } | |
4203 | ||
4204 | return FAIL; | |
4205 | } | |
4206 | ||
c19d1205 ZW |
4207 | /* Shift operands. */ |
4208 | enum shift_kind | |
b99bd4ef | 4209 | { |
c19d1205 ZW |
4210 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4211 | }; | |
b99bd4ef | 4212 | |
c19d1205 ZW |
4213 | struct asm_shift_name |
4214 | { | |
4215 | const char *name; | |
4216 | enum shift_kind kind; | |
4217 | }; | |
b99bd4ef | 4218 | |
c19d1205 ZW |
4219 | /* Third argument to parse_shift. */ |
4220 | enum parse_shift_mode | |
4221 | { | |
4222 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4223 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4224 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4225 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4226 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4227 | }; | |
b99bd4ef | 4228 | |
c19d1205 ZW |
4229 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4230 | This has three forms: | |
b99bd4ef | 4231 | |
c19d1205 ZW |
4232 | (LSL|LSR|ASL|ASR|ROR) Rs |
4233 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4234 | RRX | |
b99bd4ef | 4235 | |
c19d1205 ZW |
4236 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4237 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4238 | |
c19d1205 ZW |
4239 | static int |
4240 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4241 | { |
c19d1205 ZW |
4242 | const struct asm_shift_name *shift_name; |
4243 | enum shift_kind shift; | |
4244 | char *s = *str; | |
4245 | char *p = s; | |
4246 | int reg; | |
b99bd4ef | 4247 | |
c19d1205 ZW |
4248 | for (p = *str; ISALPHA (*p); p++) |
4249 | ; | |
b99bd4ef | 4250 | |
c19d1205 | 4251 | if (p == *str) |
b99bd4ef | 4252 | { |
c19d1205 ZW |
4253 | inst.error = _("shift expression expected"); |
4254 | return FAIL; | |
b99bd4ef NC |
4255 | } |
4256 | ||
c19d1205 ZW |
4257 | shift_name = hash_find_n (arm_shift_hsh, *str, p - *str); |
4258 | ||
4259 | if (shift_name == NULL) | |
b99bd4ef | 4260 | { |
c19d1205 ZW |
4261 | inst.error = _("shift expression expected"); |
4262 | return FAIL; | |
b99bd4ef NC |
4263 | } |
4264 | ||
c19d1205 | 4265 | shift = shift_name->kind; |
b99bd4ef | 4266 | |
c19d1205 ZW |
4267 | switch (mode) |
4268 | { | |
4269 | case NO_SHIFT_RESTRICT: | |
4270 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4271 | |
c19d1205 ZW |
4272 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4273 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4274 | { | |
4275 | inst.error = _("'LSL' or 'ASR' required"); | |
4276 | return FAIL; | |
4277 | } | |
4278 | break; | |
b99bd4ef | 4279 | |
c19d1205 ZW |
4280 | case SHIFT_LSL_IMMEDIATE: |
4281 | if (shift != SHIFT_LSL) | |
4282 | { | |
4283 | inst.error = _("'LSL' required"); | |
4284 | return FAIL; | |
4285 | } | |
4286 | break; | |
b99bd4ef | 4287 | |
c19d1205 ZW |
4288 | case SHIFT_ASR_IMMEDIATE: |
4289 | if (shift != SHIFT_ASR) | |
4290 | { | |
4291 | inst.error = _("'ASR' required"); | |
4292 | return FAIL; | |
4293 | } | |
4294 | break; | |
b99bd4ef | 4295 | |
c19d1205 ZW |
4296 | default: abort (); |
4297 | } | |
b99bd4ef | 4298 | |
c19d1205 ZW |
4299 | if (shift != SHIFT_RRX) |
4300 | { | |
4301 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4302 | skip_whitespace (p); | |
b99bd4ef | 4303 | |
c19d1205 | 4304 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4305 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4306 | { |
4307 | inst.operands[i].imm = reg; | |
4308 | inst.operands[i].immisreg = 1; | |
4309 | } | |
4310 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4311 | return FAIL; | |
4312 | } | |
4313 | inst.operands[i].shift_kind = shift; | |
4314 | inst.operands[i].shifted = 1; | |
4315 | *str = p; | |
4316 | return SUCCESS; | |
b99bd4ef NC |
4317 | } |
4318 | ||
c19d1205 | 4319 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4320 | |
c19d1205 ZW |
4321 | #<immediate> |
4322 | #<immediate>, <rotate> | |
4323 | <Rm> | |
4324 | <Rm>, <shift> | |
b99bd4ef | 4325 | |
c19d1205 ZW |
4326 | where <shift> is defined by parse_shift above, and <rotate> is a |
4327 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4328 | is deferred to md_apply_fix. */ |
b99bd4ef | 4329 | |
c19d1205 ZW |
4330 | static int |
4331 | parse_shifter_operand (char **str, int i) | |
4332 | { | |
4333 | int value; | |
4334 | expressionS expr; | |
b99bd4ef | 4335 | |
dcbf9037 | 4336 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4337 | { |
4338 | inst.operands[i].reg = value; | |
4339 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4340 | |
c19d1205 ZW |
4341 | /* parse_shift will override this if appropriate */ |
4342 | inst.reloc.exp.X_op = O_constant; | |
4343 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4344 | |
c19d1205 ZW |
4345 | if (skip_past_comma (str) == FAIL) |
4346 | return SUCCESS; | |
b99bd4ef | 4347 | |
c19d1205 ZW |
4348 | /* Shift operation on register. */ |
4349 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4350 | } |
4351 | ||
c19d1205 ZW |
4352 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4353 | return FAIL; | |
b99bd4ef | 4354 | |
c19d1205 | 4355 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4356 | { |
c19d1205 ZW |
4357 | /* #x, y -- ie explicit rotation by Y. */ |
4358 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
4359 | return FAIL; | |
b99bd4ef | 4360 | |
c19d1205 ZW |
4361 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
4362 | { | |
4363 | inst.error = _("constant expression expected"); | |
4364 | return FAIL; | |
4365 | } | |
b99bd4ef | 4366 | |
c19d1205 ZW |
4367 | value = expr.X_add_number; |
4368 | if (value < 0 || value > 30 || value % 2 != 0) | |
4369 | { | |
4370 | inst.error = _("invalid rotation"); | |
4371 | return FAIL; | |
4372 | } | |
4373 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4374 | { | |
4375 | inst.error = _("invalid constant"); | |
4376 | return FAIL; | |
4377 | } | |
09d92015 | 4378 | |
55cf6793 | 4379 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
4380 | inst.reloc.exp.X_add_number |
4381 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
4382 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
4383 | } |
4384 | ||
c19d1205 ZW |
4385 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4386 | inst.reloc.pc_rel = 0; | |
4387 | return SUCCESS; | |
09d92015 MM |
4388 | } |
4389 | ||
4962c51a MS |
4390 | /* Group relocation information. Each entry in the table contains the |
4391 | textual name of the relocation as may appear in assembler source | |
4392 | and must end with a colon. | |
4393 | Along with this textual name are the relocation codes to be used if | |
4394 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4395 | an LDR, an LDRS, or an LDC. */ | |
4396 | ||
4397 | struct group_reloc_table_entry | |
4398 | { | |
4399 | const char *name; | |
4400 | int alu_code; | |
4401 | int ldr_code; | |
4402 | int ldrs_code; | |
4403 | int ldc_code; | |
4404 | }; | |
4405 | ||
4406 | typedef enum | |
4407 | { | |
4408 | /* Varieties of non-ALU group relocation. */ | |
4409 | ||
4410 | GROUP_LDR, | |
4411 | GROUP_LDRS, | |
4412 | GROUP_LDC | |
4413 | } group_reloc_type; | |
4414 | ||
4415 | static struct group_reloc_table_entry group_reloc_table[] = | |
4416 | { /* Program counter relative: */ | |
4417 | { "pc_g0_nc", | |
4418 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4419 | 0, /* LDR */ | |
4420 | 0, /* LDRS */ | |
4421 | 0 }, /* LDC */ | |
4422 | { "pc_g0", | |
4423 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4424 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4425 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4426 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4427 | { "pc_g1_nc", | |
4428 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4429 | 0, /* LDR */ | |
4430 | 0, /* LDRS */ | |
4431 | 0 }, /* LDC */ | |
4432 | { "pc_g1", | |
4433 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4434 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4435 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4436 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4437 | { "pc_g2", | |
4438 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4439 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4440 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4441 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4442 | /* Section base relative */ | |
4443 | { "sb_g0_nc", | |
4444 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4445 | 0, /* LDR */ | |
4446 | 0, /* LDRS */ | |
4447 | 0 }, /* LDC */ | |
4448 | { "sb_g0", | |
4449 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4450 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4451 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4452 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4453 | { "sb_g1_nc", | |
4454 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4455 | 0, /* LDR */ | |
4456 | 0, /* LDRS */ | |
4457 | 0 }, /* LDC */ | |
4458 | { "sb_g1", | |
4459 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4460 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4461 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4462 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4463 | { "sb_g2", | |
4464 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
4465 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
4466 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
4467 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
4468 | ||
4469 | /* Given the address of a pointer pointing to the textual name of a group | |
4470 | relocation as may appear in assembler source, attempt to find its details | |
4471 | in group_reloc_table. The pointer will be updated to the character after | |
4472 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
4473 | otherwise. On success, *entry will be updated to point at the relevant | |
4474 | group_reloc_table entry. */ | |
4475 | ||
4476 | static int | |
4477 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
4478 | { | |
4479 | unsigned int i; | |
4480 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
4481 | { | |
4482 | int length = strlen (group_reloc_table[i].name); | |
4483 | ||
4484 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 && | |
4485 | (*str)[length] == ':') | |
4486 | { | |
4487 | *out = &group_reloc_table[i]; | |
4488 | *str += (length + 1); | |
4489 | return SUCCESS; | |
4490 | } | |
4491 | } | |
4492 | ||
4493 | return FAIL; | |
4494 | } | |
4495 | ||
4496 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
4497 | (as for parse_shifter_operand) where group relocations are allowed: | |
4498 | ||
4499 | #<immediate> | |
4500 | #<immediate>, <rotate> | |
4501 | #:<group_reloc>:<expression> | |
4502 | <Rm> | |
4503 | <Rm>, <shift> | |
4504 | ||
4505 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
4506 | The hashes are optional. | |
4507 | ||
4508 | Everything else is as for parse_shifter_operand. */ | |
4509 | ||
4510 | static parse_operand_result | |
4511 | parse_shifter_operand_group_reloc (char **str, int i) | |
4512 | { | |
4513 | /* Determine if we have the sequence of characters #: or just : | |
4514 | coming next. If we do, then we check for a group relocation. | |
4515 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
4516 | ||
4517 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
4518 | || (*str)[0] == ':') | |
4519 | { | |
4520 | struct group_reloc_table_entry *entry; | |
4521 | ||
4522 | if ((*str)[0] == '#') | |
4523 | (*str) += 2; | |
4524 | else | |
4525 | (*str)++; | |
4526 | ||
4527 | /* Try to parse a group relocation. Anything else is an error. */ | |
4528 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
4529 | { | |
4530 | inst.error = _("unknown group relocation"); | |
4531 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4532 | } | |
4533 | ||
4534 | /* We now have the group relocation table entry corresponding to | |
4535 | the name in the assembler source. Next, we parse the expression. */ | |
4536 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
4537 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4538 | ||
4539 | /* Record the relocation type (always the ALU variant here). */ | |
4540 | inst.reloc.type = entry->alu_code; | |
4541 | assert (inst.reloc.type != 0); | |
4542 | ||
4543 | return PARSE_OPERAND_SUCCESS; | |
4544 | } | |
4545 | else | |
4546 | return parse_shifter_operand (str, i) == SUCCESS | |
4547 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
4548 | ||
4549 | /* Never reached. */ | |
4550 | } | |
4551 | ||
c19d1205 ZW |
4552 | /* Parse all forms of an ARM address expression. Information is written |
4553 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 4554 | |
c19d1205 | 4555 | Preindexed addressing (.preind=1): |
09d92015 | 4556 | |
c19d1205 ZW |
4557 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
4558 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4559 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4560 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4561 | |
c19d1205 | 4562 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 4563 | |
c19d1205 | 4564 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 4565 | |
c19d1205 ZW |
4566 | [Rn], #offset .reg=Rn .reloc.exp=offset |
4567 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4568 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4569 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4570 | |
c19d1205 | 4571 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 4572 | |
c19d1205 | 4573 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 4574 | |
c19d1205 | 4575 | Other: |
09d92015 | 4576 | |
c19d1205 ZW |
4577 | [Rn]{!} shorthand for [Rn,#0]{!} |
4578 | =immediate .isreg=0 .reloc.exp=immediate | |
4579 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 4580 | |
c19d1205 ZW |
4581 | It is the caller's responsibility to check for addressing modes not |
4582 | supported by the instruction, and to set inst.reloc.type. */ | |
4583 | ||
4962c51a MS |
4584 | static parse_operand_result |
4585 | parse_address_main (char **str, int i, int group_relocations, | |
4586 | group_reloc_type group_type) | |
09d92015 | 4587 | { |
c19d1205 ZW |
4588 | char *p = *str; |
4589 | int reg; | |
09d92015 | 4590 | |
c19d1205 | 4591 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 4592 | { |
c19d1205 ZW |
4593 | if (skip_past_char (&p, '=') == FAIL) |
4594 | { | |
4595 | /* bare address - translate to PC-relative offset */ | |
4596 | inst.reloc.pc_rel = 1; | |
4597 | inst.operands[i].reg = REG_PC; | |
4598 | inst.operands[i].isreg = 1; | |
4599 | inst.operands[i].preind = 1; | |
4600 | } | |
4601 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 4602 | |
c19d1205 | 4603 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 4604 | return PARSE_OPERAND_FAIL; |
09d92015 | 4605 | |
c19d1205 | 4606 | *str = p; |
4962c51a | 4607 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
4608 | } |
4609 | ||
dcbf9037 | 4610 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 4611 | { |
c19d1205 | 4612 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 4613 | return PARSE_OPERAND_FAIL; |
09d92015 | 4614 | } |
c19d1205 ZW |
4615 | inst.operands[i].reg = reg; |
4616 | inst.operands[i].isreg = 1; | |
09d92015 | 4617 | |
c19d1205 | 4618 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4619 | { |
c19d1205 | 4620 | inst.operands[i].preind = 1; |
09d92015 | 4621 | |
c19d1205 ZW |
4622 | if (*p == '+') p++; |
4623 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
4624 | ||
dcbf9037 | 4625 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 4626 | { |
c19d1205 ZW |
4627 | inst.operands[i].imm = reg; |
4628 | inst.operands[i].immisreg = 1; | |
4629 | ||
4630 | if (skip_past_comma (&p) == SUCCESS) | |
4631 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 4632 | return PARSE_OPERAND_FAIL; |
c19d1205 | 4633 | } |
5287ad62 JB |
4634 | else if (skip_past_char (&p, ':') == SUCCESS) |
4635 | { | |
4636 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
4637 | code before we get to see it here. This may be subject to | |
4638 | change. */ | |
4639 | expressionS exp; | |
4640 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
4641 | if (exp.X_op != O_constant) | |
4642 | { | |
4643 | inst.error = _("alignment must be constant"); | |
4962c51a | 4644 | return PARSE_OPERAND_FAIL; |
5287ad62 JB |
4645 | } |
4646 | inst.operands[i].imm = exp.X_add_number << 8; | |
4647 | inst.operands[i].immisalign = 1; | |
4648 | /* Alignments are not pre-indexes. */ | |
4649 | inst.operands[i].preind = 0; | |
4650 | } | |
c19d1205 ZW |
4651 | else |
4652 | { | |
4653 | if (inst.operands[i].negative) | |
4654 | { | |
4655 | inst.operands[i].negative = 0; | |
4656 | p--; | |
4657 | } | |
4962c51a MS |
4658 | |
4659 | if (group_relocations && | |
4660 | ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4661 | ||
4662 | { | |
4663 | struct group_reloc_table_entry *entry; | |
4664 | ||
4665 | /* Skip over the #: or : sequence. */ | |
4666 | if (*p == '#') | |
4667 | p += 2; | |
4668 | else | |
4669 | p++; | |
4670 | ||
4671 | /* Try to parse a group relocation. Anything else is an | |
4672 | error. */ | |
4673 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
4674 | { | |
4675 | inst.error = _("unknown group relocation"); | |
4676 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4677 | } | |
4678 | ||
4679 | /* We now have the group relocation table entry corresponding to | |
4680 | the name in the assembler source. Next, we parse the | |
4681 | expression. */ | |
4682 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
4683 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4684 | ||
4685 | /* Record the relocation type. */ | |
4686 | switch (group_type) | |
4687 | { | |
4688 | case GROUP_LDR: | |
4689 | inst.reloc.type = entry->ldr_code; | |
4690 | break; | |
4691 | ||
4692 | case GROUP_LDRS: | |
4693 | inst.reloc.type = entry->ldrs_code; | |
4694 | break; | |
4695 | ||
4696 | case GROUP_LDC: | |
4697 | inst.reloc.type = entry->ldc_code; | |
4698 | break; | |
4699 | ||
4700 | default: | |
4701 | assert (0); | |
4702 | } | |
4703 | ||
4704 | if (inst.reloc.type == 0) | |
4705 | { | |
4706 | inst.error = _("this group relocation is not allowed on this instruction"); | |
4707 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4708 | } | |
4709 | } | |
4710 | else | |
4711 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4712 | return PARSE_OPERAND_FAIL; | |
09d92015 MM |
4713 | } |
4714 | } | |
4715 | ||
c19d1205 | 4716 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 4717 | { |
c19d1205 | 4718 | inst.error = _("']' expected"); |
4962c51a | 4719 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
4720 | } |
4721 | ||
c19d1205 ZW |
4722 | if (skip_past_char (&p, '!') == SUCCESS) |
4723 | inst.operands[i].writeback = 1; | |
09d92015 | 4724 | |
c19d1205 | 4725 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4726 | { |
c19d1205 ZW |
4727 | if (skip_past_char (&p, '{') == SUCCESS) |
4728 | { | |
4729 | /* [Rn], {expr} - unindexed, with option */ | |
4730 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 4731 | 0, 255, TRUE) == FAIL) |
4962c51a | 4732 | return PARSE_OPERAND_FAIL; |
09d92015 | 4733 | |
c19d1205 ZW |
4734 | if (skip_past_char (&p, '}') == FAIL) |
4735 | { | |
4736 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 4737 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4738 | } |
4739 | if (inst.operands[i].preind) | |
4740 | { | |
4741 | inst.error = _("cannot combine index with option"); | |
4962c51a | 4742 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4743 | } |
4744 | *str = p; | |
4962c51a | 4745 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 4746 | } |
c19d1205 ZW |
4747 | else |
4748 | { | |
4749 | inst.operands[i].postind = 1; | |
4750 | inst.operands[i].writeback = 1; | |
09d92015 | 4751 | |
c19d1205 ZW |
4752 | if (inst.operands[i].preind) |
4753 | { | |
4754 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 4755 | return PARSE_OPERAND_FAIL; |
c19d1205 | 4756 | } |
09d92015 | 4757 | |
c19d1205 ZW |
4758 | if (*p == '+') p++; |
4759 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 4760 | |
dcbf9037 | 4761 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 4762 | { |
5287ad62 JB |
4763 | /* We might be using the immediate for alignment already. If we |
4764 | are, OR the register number into the low-order bits. */ | |
4765 | if (inst.operands[i].immisalign) | |
4766 | inst.operands[i].imm |= reg; | |
4767 | else | |
4768 | inst.operands[i].imm = reg; | |
c19d1205 | 4769 | inst.operands[i].immisreg = 1; |
a737bd4d | 4770 | |
c19d1205 ZW |
4771 | if (skip_past_comma (&p) == SUCCESS) |
4772 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 4773 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4774 | } |
4775 | else | |
4776 | { | |
4777 | if (inst.operands[i].negative) | |
4778 | { | |
4779 | inst.operands[i].negative = 0; | |
4780 | p--; | |
4781 | } | |
4782 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 4783 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
4784 | } |
4785 | } | |
a737bd4d NC |
4786 | } |
4787 | ||
c19d1205 ZW |
4788 | /* If at this point neither .preind nor .postind is set, we have a |
4789 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
4790 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
4791 | { | |
4792 | inst.operands[i].preind = 1; | |
4793 | inst.reloc.exp.X_op = O_constant; | |
4794 | inst.reloc.exp.X_add_number = 0; | |
4795 | } | |
4796 | *str = p; | |
4962c51a MS |
4797 | return PARSE_OPERAND_SUCCESS; |
4798 | } | |
4799 | ||
4800 | static int | |
4801 | parse_address (char **str, int i) | |
4802 | { | |
4803 | return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS | |
4804 | ? SUCCESS : FAIL; | |
4805 | } | |
4806 | ||
4807 | static parse_operand_result | |
4808 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
4809 | { | |
4810 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
4811 | } |
4812 | ||
b6895b4f PB |
4813 | /* Parse an operand for a MOVW or MOVT instruction. */ |
4814 | static int | |
4815 | parse_half (char **str) | |
4816 | { | |
4817 | char * p; | |
4818 | ||
4819 | p = *str; | |
4820 | skip_past_char (&p, '#'); | |
4821 | if (strncasecmp (p, ":lower16:", 9) == 0) | |
4822 | inst.reloc.type = BFD_RELOC_ARM_MOVW; | |
4823 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
4824 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
4825 | ||
4826 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
4827 | { | |
4828 | p += 9; | |
4829 | skip_whitespace(p); | |
4830 | } | |
4831 | ||
4832 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
4833 | return FAIL; | |
4834 | ||
4835 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
4836 | { | |
4837 | if (inst.reloc.exp.X_op != O_constant) | |
4838 | { | |
4839 | inst.error = _("constant expression expected"); | |
4840 | return FAIL; | |
4841 | } | |
4842 | if (inst.reloc.exp.X_add_number < 0 | |
4843 | || inst.reloc.exp.X_add_number > 0xffff) | |
4844 | { | |
4845 | inst.error = _("immediate value out of range"); | |
4846 | return FAIL; | |
4847 | } | |
4848 | } | |
4849 | *str = p; | |
4850 | return SUCCESS; | |
4851 | } | |
4852 | ||
c19d1205 | 4853 | /* Miscellaneous. */ |
a737bd4d | 4854 | |
c19d1205 ZW |
4855 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
4856 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
4857 | static int | |
4858 | parse_psr (char **str) | |
09d92015 | 4859 | { |
c19d1205 ZW |
4860 | char *p; |
4861 | unsigned long psr_field; | |
62b3e311 PB |
4862 | const struct asm_psr *psr; |
4863 | char *start; | |
09d92015 | 4864 | |
c19d1205 ZW |
4865 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
4866 | feature for ease of use and backwards compatibility. */ | |
4867 | p = *str; | |
62b3e311 | 4868 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 4869 | psr_field = SPSR_BIT; |
62b3e311 | 4870 | else if (strncasecmp (p, "CPSR", 4) == 0) |
c19d1205 ZW |
4871 | psr_field = 0; |
4872 | else | |
62b3e311 PB |
4873 | { |
4874 | start = p; | |
4875 | do | |
4876 | p++; | |
4877 | while (ISALNUM (*p) || *p == '_'); | |
4878 | ||
4879 | psr = hash_find_n (arm_v7m_psr_hsh, start, p - start); | |
4880 | if (!psr) | |
4881 | return FAIL; | |
09d92015 | 4882 | |
62b3e311 PB |
4883 | *str = p; |
4884 | return psr->field; | |
4885 | } | |
09d92015 | 4886 | |
62b3e311 | 4887 | p += 4; |
c19d1205 ZW |
4888 | if (*p == '_') |
4889 | { | |
4890 | /* A suffix follows. */ | |
c19d1205 ZW |
4891 | p++; |
4892 | start = p; | |
a737bd4d | 4893 | |
c19d1205 ZW |
4894 | do |
4895 | p++; | |
4896 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 4897 | |
c19d1205 ZW |
4898 | psr = hash_find_n (arm_psr_hsh, start, p - start); |
4899 | if (!psr) | |
4900 | goto error; | |
a737bd4d | 4901 | |
c19d1205 | 4902 | psr_field |= psr->field; |
a737bd4d | 4903 | } |
c19d1205 | 4904 | else |
a737bd4d | 4905 | { |
c19d1205 ZW |
4906 | if (ISALNUM (*p)) |
4907 | goto error; /* Garbage after "[CS]PSR". */ | |
4908 | ||
4909 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 4910 | } |
c19d1205 ZW |
4911 | *str = p; |
4912 | return psr_field; | |
a737bd4d | 4913 | |
c19d1205 ZW |
4914 | error: |
4915 | inst.error = _("flag for {c}psr instruction expected"); | |
4916 | return FAIL; | |
a737bd4d NC |
4917 | } |
4918 | ||
c19d1205 ZW |
4919 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
4920 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 4921 | |
c19d1205 ZW |
4922 | static int |
4923 | parse_cps_flags (char **str) | |
a737bd4d | 4924 | { |
c19d1205 ZW |
4925 | int val = 0; |
4926 | int saw_a_flag = 0; | |
4927 | char *s = *str; | |
a737bd4d | 4928 | |
c19d1205 ZW |
4929 | for (;;) |
4930 | switch (*s++) | |
4931 | { | |
4932 | case '\0': case ',': | |
4933 | goto done; | |
a737bd4d | 4934 | |
c19d1205 ZW |
4935 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
4936 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
4937 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 4938 | |
c19d1205 ZW |
4939 | default: |
4940 | inst.error = _("unrecognized CPS flag"); | |
4941 | return FAIL; | |
4942 | } | |
a737bd4d | 4943 | |
c19d1205 ZW |
4944 | done: |
4945 | if (saw_a_flag == 0) | |
a737bd4d | 4946 | { |
c19d1205 ZW |
4947 | inst.error = _("missing CPS flags"); |
4948 | return FAIL; | |
a737bd4d | 4949 | } |
a737bd4d | 4950 | |
c19d1205 ZW |
4951 | *str = s - 1; |
4952 | return val; | |
a737bd4d NC |
4953 | } |
4954 | ||
c19d1205 ZW |
4955 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
4956 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
4957 | |
4958 | static int | |
c19d1205 | 4959 | parse_endian_specifier (char **str) |
a737bd4d | 4960 | { |
c19d1205 ZW |
4961 | int little_endian; |
4962 | char *s = *str; | |
a737bd4d | 4963 | |
c19d1205 ZW |
4964 | if (strncasecmp (s, "BE", 2)) |
4965 | little_endian = 0; | |
4966 | else if (strncasecmp (s, "LE", 2)) | |
4967 | little_endian = 1; | |
4968 | else | |
a737bd4d | 4969 | { |
c19d1205 | 4970 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
4971 | return FAIL; |
4972 | } | |
4973 | ||
c19d1205 | 4974 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 4975 | { |
c19d1205 | 4976 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
4977 | return FAIL; |
4978 | } | |
4979 | ||
c19d1205 ZW |
4980 | *str = s + 2; |
4981 | return little_endian; | |
4982 | } | |
a737bd4d | 4983 | |
c19d1205 ZW |
4984 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
4985 | value suitable for poking into the rotate field of an sxt or sxta | |
4986 | instruction, or FAIL on error. */ | |
4987 | ||
4988 | static int | |
4989 | parse_ror (char **str) | |
4990 | { | |
4991 | int rot; | |
4992 | char *s = *str; | |
4993 | ||
4994 | if (strncasecmp (s, "ROR", 3) == 0) | |
4995 | s += 3; | |
4996 | else | |
a737bd4d | 4997 | { |
c19d1205 | 4998 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
4999 | return FAIL; |
5000 | } | |
c19d1205 ZW |
5001 | |
5002 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
5003 | return FAIL; | |
5004 | ||
5005 | switch (rot) | |
a737bd4d | 5006 | { |
c19d1205 ZW |
5007 | case 0: *str = s; return 0x0; |
5008 | case 8: *str = s; return 0x1; | |
5009 | case 16: *str = s; return 0x2; | |
5010 | case 24: *str = s; return 0x3; | |
5011 | ||
5012 | default: | |
5013 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
5014 | return FAIL; |
5015 | } | |
c19d1205 | 5016 | } |
a737bd4d | 5017 | |
c19d1205 ZW |
5018 | /* Parse a conditional code (from conds[] below). The value returned is in the |
5019 | range 0 .. 14, or FAIL. */ | |
5020 | static int | |
5021 | parse_cond (char **str) | |
5022 | { | |
5023 | char *p, *q; | |
5024 | const struct asm_cond *c; | |
a737bd4d | 5025 | |
c19d1205 ZW |
5026 | p = q = *str; |
5027 | while (ISALPHA (*q)) | |
5028 | q++; | |
a737bd4d | 5029 | |
c19d1205 ZW |
5030 | c = hash_find_n (arm_cond_hsh, p, q - p); |
5031 | if (!c) | |
a737bd4d | 5032 | { |
c19d1205 | 5033 | inst.error = _("condition required"); |
a737bd4d NC |
5034 | return FAIL; |
5035 | } | |
5036 | ||
c19d1205 ZW |
5037 | *str = q; |
5038 | return c->value; | |
5039 | } | |
5040 | ||
62b3e311 PB |
5041 | /* Parse an option for a barrier instruction. Returns the encoding for the |
5042 | option, or FAIL. */ | |
5043 | static int | |
5044 | parse_barrier (char **str) | |
5045 | { | |
5046 | char *p, *q; | |
5047 | const struct asm_barrier_opt *o; | |
5048 | ||
5049 | p = q = *str; | |
5050 | while (ISALPHA (*q)) | |
5051 | q++; | |
5052 | ||
5053 | o = hash_find_n (arm_barrier_opt_hsh, p, q - p); | |
5054 | if (!o) | |
5055 | return FAIL; | |
5056 | ||
5057 | *str = q; | |
5058 | return o->value; | |
5059 | } | |
5060 | ||
92e90b6e PB |
5061 | /* Parse the operands of a table branch instruction. Similar to a memory |
5062 | operand. */ | |
5063 | static int | |
5064 | parse_tb (char **str) | |
5065 | { | |
5066 | char * p = *str; | |
5067 | int reg; | |
5068 | ||
5069 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5070 | { |
5071 | inst.error = _("'[' expected"); | |
5072 | return FAIL; | |
5073 | } | |
92e90b6e | 5074 | |
dcbf9037 | 5075 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5076 | { |
5077 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5078 | return FAIL; | |
5079 | } | |
5080 | inst.operands[0].reg = reg; | |
5081 | ||
5082 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5083 | { |
5084 | inst.error = _("',' expected"); | |
5085 | return FAIL; | |
5086 | } | |
92e90b6e | 5087 | |
dcbf9037 | 5088 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5089 | { |
5090 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5091 | return FAIL; | |
5092 | } | |
5093 | inst.operands[0].imm = reg; | |
5094 | ||
5095 | if (skip_past_comma (&p) == SUCCESS) | |
5096 | { | |
5097 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5098 | return FAIL; | |
5099 | if (inst.reloc.exp.X_add_number != 1) | |
5100 | { | |
5101 | inst.error = _("invalid shift"); | |
5102 | return FAIL; | |
5103 | } | |
5104 | inst.operands[0].shifted = 1; | |
5105 | } | |
5106 | ||
5107 | if (skip_past_char (&p, ']') == FAIL) | |
5108 | { | |
5109 | inst.error = _("']' expected"); | |
5110 | return FAIL; | |
5111 | } | |
5112 | *str = p; | |
5113 | return SUCCESS; | |
5114 | } | |
5115 | ||
5287ad62 JB |
5116 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5117 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5118 | Up to four operands may be read; this function handles setting the |
5119 | ".present" field for each read operand itself. | |
5287ad62 JB |
5120 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5121 | else returns FAIL. */ | |
5122 | ||
5123 | static int | |
5124 | parse_neon_mov (char **str, int *which_operand) | |
5125 | { | |
5126 | int i = *which_operand, val; | |
5127 | enum arm_reg_type rtype; | |
5128 | char *ptr = *str; | |
dcbf9037 | 5129 | struct neon_type_el optype; |
5287ad62 | 5130 | |
dcbf9037 | 5131 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5132 | { |
5133 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5134 | inst.operands[i].reg = val; | |
5135 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5136 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5137 | inst.operands[i++].present = 1; |
5138 | ||
5139 | if (skip_past_comma (&ptr) == FAIL) | |
5140 | goto wanted_comma; | |
5141 | ||
dcbf9037 | 5142 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 JB |
5143 | goto wanted_arm; |
5144 | ||
5145 | inst.operands[i].reg = val; | |
5146 | inst.operands[i].isreg = 1; | |
5147 | inst.operands[i].present = 1; | |
5148 | } | |
037e8744 | 5149 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5150 | != FAIL) |
5287ad62 JB |
5151 | { |
5152 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5153 | if (skip_past_comma (&ptr) == FAIL) | |
5154 | goto wanted_comma; | |
5155 | ||
5156 | inst.operands[i].reg = val; | |
5157 | inst.operands[i].isreg = 1; | |
5158 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5159 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5160 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5161 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5162 | inst.operands[i++].present = 1; |
5163 | ||
dcbf9037 | 5164 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5165 | { |
037e8744 JB |
5166 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5167 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5168 | inst.operands[i].reg = val; |
5169 | inst.operands[i].isreg = 1; | |
037e8744 | 5170 | inst.operands[i].present = 1; |
5287ad62 JB |
5171 | |
5172 | if (rtype == REG_TYPE_NQ) | |
5173 | { | |
dcbf9037 | 5174 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5175 | return FAIL; |
5176 | } | |
037e8744 JB |
5177 | else if (rtype != REG_TYPE_VFS) |
5178 | { | |
5179 | i++; | |
5180 | if (skip_past_comma (&ptr) == FAIL) | |
5181 | goto wanted_comma; | |
5182 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5183 | goto wanted_arm; | |
5184 | inst.operands[i].reg = val; | |
5185 | inst.operands[i].isreg = 1; | |
5186 | inst.operands[i].present = 1; | |
5187 | } | |
5287ad62 | 5188 | } |
136da414 | 5189 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
136da414 | 5190 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
037e8744 JB |
5191 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> |
5192 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5193 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5194 | ; | |
5287ad62 | 5195 | else if (parse_big_immediate (&ptr, i) == SUCCESS) |
5287ad62 JB |
5196 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
5197 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
037e8744 JB |
5198 | ; |
5199 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, | |
5200 | &optype)) != FAIL) | |
5287ad62 JB |
5201 | { |
5202 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5203 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5204 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5205 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5206 | |
5207 | inst.operands[i].reg = val; | |
5208 | inst.operands[i].isreg = 1; | |
5209 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5210 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5211 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5212 | inst.operands[i].vectype = optype; |
5287ad62 | 5213 | inst.operands[i].present = 1; |
037e8744 JB |
5214 | |
5215 | if (skip_past_comma (&ptr) == SUCCESS) | |
5216 | { | |
5217 | /* Case 15. */ | |
5218 | i++; | |
5219 | ||
5220 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5221 | goto wanted_arm; | |
5222 | ||
5223 | inst.operands[i].reg = val; | |
5224 | inst.operands[i].isreg = 1; | |
5225 | inst.operands[i++].present = 1; | |
5226 | ||
5227 | if (skip_past_comma (&ptr) == FAIL) | |
5228 | goto wanted_comma; | |
5229 | ||
5230 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5231 | goto wanted_arm; | |
5232 | ||
5233 | inst.operands[i].reg = val; | |
5234 | inst.operands[i].isreg = 1; | |
5235 | inst.operands[i++].present = 1; | |
5236 | } | |
5287ad62 JB |
5237 | } |
5238 | else | |
5239 | { | |
dcbf9037 | 5240 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
5241 | return FAIL; |
5242 | } | |
5243 | } | |
dcbf9037 | 5244 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5245 | { |
5246 | /* Cases 6, 7. */ | |
5247 | inst.operands[i].reg = val; | |
5248 | inst.operands[i].isreg = 1; | |
5249 | inst.operands[i++].present = 1; | |
5250 | ||
5251 | if (skip_past_comma (&ptr) == FAIL) | |
5252 | goto wanted_comma; | |
5253 | ||
dcbf9037 | 5254 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5255 | { |
5256 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
5257 | inst.operands[i].reg = val; | |
5258 | inst.operands[i].isscalar = 1; | |
5259 | inst.operands[i].present = 1; | |
dcbf9037 | 5260 | inst.operands[i].vectype = optype; |
5287ad62 | 5261 | } |
dcbf9037 | 5262 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5263 | { |
5264 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
5265 | inst.operands[i].reg = val; | |
5266 | inst.operands[i].isreg = 1; | |
5267 | inst.operands[i++].present = 1; | |
5268 | ||
5269 | if (skip_past_comma (&ptr) == FAIL) | |
5270 | goto wanted_comma; | |
5271 | ||
037e8744 | 5272 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 5273 | == FAIL) |
5287ad62 | 5274 | { |
037e8744 | 5275 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
5276 | return FAIL; |
5277 | } | |
5278 | ||
5279 | inst.operands[i].reg = val; | |
5280 | inst.operands[i].isreg = 1; | |
037e8744 JB |
5281 | inst.operands[i].isvec = 1; |
5282 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 5283 | inst.operands[i].vectype = optype; |
5287ad62 | 5284 | inst.operands[i].present = 1; |
037e8744 JB |
5285 | |
5286 | if (rtype == REG_TYPE_VFS) | |
5287 | { | |
5288 | /* Case 14. */ | |
5289 | i++; | |
5290 | if (skip_past_comma (&ptr) == FAIL) | |
5291 | goto wanted_comma; | |
5292 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
5293 | &optype)) == FAIL) | |
5294 | { | |
5295 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
5296 | return FAIL; | |
5297 | } | |
5298 | inst.operands[i].reg = val; | |
5299 | inst.operands[i].isreg = 1; | |
5300 | inst.operands[i].isvec = 1; | |
5301 | inst.operands[i].issingle = 1; | |
5302 | inst.operands[i].vectype = optype; | |
5303 | inst.operands[i].present = 1; | |
5304 | } | |
5305 | } | |
5306 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
5307 | != FAIL) | |
5308 | { | |
5309 | /* Case 13. */ | |
5310 | inst.operands[i].reg = val; | |
5311 | inst.operands[i].isreg = 1; | |
5312 | inst.operands[i].isvec = 1; | |
5313 | inst.operands[i].issingle = 1; | |
5314 | inst.operands[i].vectype = optype; | |
5315 | inst.operands[i++].present = 1; | |
5287ad62 JB |
5316 | } |
5317 | } | |
5318 | else | |
5319 | { | |
dcbf9037 | 5320 | first_error (_("parse error")); |
5287ad62 JB |
5321 | return FAIL; |
5322 | } | |
5323 | ||
5324 | /* Successfully parsed the operands. Update args. */ | |
5325 | *which_operand = i; | |
5326 | *str = ptr; | |
5327 | return SUCCESS; | |
5328 | ||
5329 | wanted_comma: | |
dcbf9037 | 5330 | first_error (_("expected comma")); |
5287ad62 JB |
5331 | return FAIL; |
5332 | ||
5333 | wanted_arm: | |
dcbf9037 | 5334 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 5335 | return FAIL; |
5287ad62 JB |
5336 | } |
5337 | ||
c19d1205 ZW |
5338 | /* Matcher codes for parse_operands. */ |
5339 | enum operand_parse_code | |
5340 | { | |
5341 | OP_stop, /* end of line */ | |
5342 | ||
5343 | OP_RR, /* ARM register */ | |
5344 | OP_RRnpc, /* ARM register, not r15 */ | |
5345 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
5346 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
5347 | OP_RCP, /* Coprocessor number */ | |
5348 | OP_RCN, /* Coprocessor register */ | |
5349 | OP_RF, /* FPA register */ | |
5350 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
5351 | OP_RVD, /* VFP double precision register (0..15) */ |
5352 | OP_RND, /* Neon double precision register (0..31) */ | |
5353 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 5354 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 5355 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 5356 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 5357 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
5358 | OP_RVC, /* VFP control register */ |
5359 | OP_RMF, /* Maverick F register */ | |
5360 | OP_RMD, /* Maverick D register */ | |
5361 | OP_RMFX, /* Maverick FX register */ | |
5362 | OP_RMDX, /* Maverick DX register */ | |
5363 | OP_RMAX, /* Maverick AX register */ | |
5364 | OP_RMDS, /* Maverick DSPSC register */ | |
5365 | OP_RIWR, /* iWMMXt wR register */ | |
5366 | OP_RIWC, /* iWMMXt wC register */ | |
5367 | OP_RIWG, /* iWMMXt wCG register */ | |
5368 | OP_RXA, /* XScale accumulator register */ | |
5369 | ||
5370 | OP_REGLST, /* ARM register list */ | |
5371 | OP_VRSLST, /* VFP single-precision register list */ | |
5372 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 5373 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
5374 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
5375 | OP_NSTRLST, /* Neon element/structure list */ | |
5376 | ||
5377 | OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */ | |
5378 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ | |
037e8744 | 5379 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 5380 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 5381 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
5382 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
5383 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
5384 | OP_VMOV, /* Neon VMOV operands. */ | |
5385 | OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */ | |
5386 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ | |
2d447fca | 5387 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
5388 | |
5389 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
5390 | OP_I7, /* immediate value 0 .. 7 */ |
5391 | OP_I15, /* 0 .. 15 */ | |
5392 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 5393 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
5394 | OP_I31, /* 0 .. 31 */ |
5395 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
5396 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
5397 | OP_I32z, /* 0 .. 32 */ |
5398 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 5399 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
5400 | OP_I64, /* 1 .. 64 */ |
5401 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 5402 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
5403 | |
5404 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
5405 | OP_I7b, /* 0 .. 7 */ | |
5406 | OP_I15b, /* 0 .. 15 */ | |
5407 | OP_I31b, /* 0 .. 31 */ | |
5408 | ||
5409 | OP_SH, /* shifter operand */ | |
4962c51a | 5410 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 5411 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
5412 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
5413 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
5414 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
5415 | OP_EXP, /* arbitrary expression */ |
5416 | OP_EXPi, /* same, with optional immediate prefix */ | |
5417 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 5418 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
5419 | |
5420 | OP_CPSF, /* CPS flags */ | |
5421 | OP_ENDI, /* Endianness specifier */ | |
5422 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
5423 | OP_COND, /* conditional code */ | |
92e90b6e | 5424 | OP_TB, /* Table branch. */ |
c19d1205 | 5425 | |
037e8744 JB |
5426 | OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */ |
5427 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ | |
5428 | ||
c19d1205 ZW |
5429 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
5430 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
5431 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
5432 | OP_RF_IF, /* FPA register or immediate */ | |
5433 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 5434 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
5435 | |
5436 | /* Optional operands. */ | |
5437 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
5438 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 5439 | OP_oI32b, /* 1 .. 32 */ |
c19d1205 ZW |
5440 | OP_oIffffb, /* 0 .. 65535 */ |
5441 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
5442 | ||
5443 | OP_oRR, /* ARM register */ | |
5444 | OP_oRRnpc, /* ARM register, not the PC */ | |
5287ad62 JB |
5445 | OP_oRND, /* Optional Neon double precision register */ |
5446 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5447 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 5448 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
5449 | OP_oSHll, /* LSL immediate */ |
5450 | OP_oSHar, /* ASR immediate */ | |
5451 | OP_oSHllar, /* LSL or ASR immediate */ | |
5452 | OP_oROR, /* ROR 0/8/16/24 */ | |
62b3e311 | 5453 | OP_oBARRIER, /* Option argument for a barrier instruction. */ |
c19d1205 ZW |
5454 | |
5455 | OP_FIRST_OPTIONAL = OP_oI7b | |
5456 | }; | |
a737bd4d | 5457 | |
c19d1205 ZW |
5458 | /* Generic instruction operand parser. This does no encoding and no |
5459 | semantic validation; it merely squirrels values away in the inst | |
5460 | structure. Returns SUCCESS or FAIL depending on whether the | |
5461 | specified grammar matched. */ | |
5462 | static int | |
ca3f61f7 | 5463 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
5464 | { |
5465 | unsigned const char *upat = pattern; | |
5466 | char *backtrack_pos = 0; | |
5467 | const char *backtrack_error = 0; | |
5468 | int i, val, backtrack_index = 0; | |
5287ad62 | 5469 | enum arm_reg_type rtype; |
4962c51a | 5470 | parse_operand_result result; |
c19d1205 ZW |
5471 | |
5472 | #define po_char_or_fail(chr) do { \ | |
5473 | if (skip_past_char (&str, chr) == FAIL) \ | |
5474 | goto bad_args; \ | |
5475 | } while (0) | |
5476 | ||
dcbf9037 JB |
5477 | #define po_reg_or_fail(regtype) do { \ |
5478 | val = arm_typed_reg_parse (&str, regtype, &rtype, \ | |
5479 | &inst.operands[i].vectype); \ | |
5480 | if (val == FAIL) \ | |
5481 | { \ | |
5482 | first_error (_(reg_expected_msgs[regtype])); \ | |
5483 | goto failure; \ | |
5484 | } \ | |
5485 | inst.operands[i].reg = val; \ | |
5486 | inst.operands[i].isreg = 1; \ | |
5487 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
037e8744 JB |
5488 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ |
5489 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5490 | || rtype == REG_TYPE_VFD \ | |
5491 | || rtype == REG_TYPE_NQ); \ | |
c19d1205 ZW |
5492 | } while (0) |
5493 | ||
dcbf9037 JB |
5494 | #define po_reg_or_goto(regtype, label) do { \ |
5495 | val = arm_typed_reg_parse (&str, regtype, &rtype, \ | |
5496 | &inst.operands[i].vectype); \ | |
5497 | if (val == FAIL) \ | |
5498 | goto label; \ | |
5499 | \ | |
5500 | inst.operands[i].reg = val; \ | |
5501 | inst.operands[i].isreg = 1; \ | |
5502 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
037e8744 JB |
5503 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ |
5504 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5505 | || rtype == REG_TYPE_VFD \ | |
5506 | || rtype == REG_TYPE_NQ); \ | |
c19d1205 ZW |
5507 | } while (0) |
5508 | ||
5509 | #define po_imm_or_fail(min, max, popt) do { \ | |
5510 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
5511 | goto failure; \ | |
5512 | inst.operands[i].imm = val; \ | |
5513 | } while (0) | |
5514 | ||
dcbf9037 JB |
5515 | #define po_scalar_or_goto(elsz, label) do { \ |
5516 | val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \ | |
5517 | if (val == FAIL) \ | |
5518 | goto label; \ | |
5519 | inst.operands[i].reg = val; \ | |
5520 | inst.operands[i].isscalar = 1; \ | |
5287ad62 JB |
5521 | } while (0) |
5522 | ||
c19d1205 ZW |
5523 | #define po_misc_or_fail(expr) do { \ |
5524 | if (expr) \ | |
5525 | goto failure; \ | |
5526 | } while (0) | |
5527 | ||
4962c51a MS |
5528 | #define po_misc_or_fail_no_backtrack(expr) do { \ |
5529 | result = expr; \ | |
5530 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\ | |
5531 | backtrack_pos = 0; \ | |
5532 | if (result != PARSE_OPERAND_SUCCESS) \ | |
5533 | goto failure; \ | |
5534 | } while (0) | |
5535 | ||
c19d1205 ZW |
5536 | skip_whitespace (str); |
5537 | ||
5538 | for (i = 0; upat[i] != OP_stop; i++) | |
5539 | { | |
5540 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
5541 | { | |
5542 | /* Remember where we are in case we need to backtrack. */ | |
5543 | assert (!backtrack_pos); | |
5544 | backtrack_pos = str; | |
5545 | backtrack_error = inst.error; | |
5546 | backtrack_index = i; | |
5547 | } | |
5548 | ||
5549 | if (i > 0) | |
5550 | po_char_or_fail (','); | |
5551 | ||
5552 | switch (upat[i]) | |
5553 | { | |
5554 | /* Registers */ | |
5555 | case OP_oRRnpc: | |
5556 | case OP_RRnpc: | |
5557 | case OP_oRR: | |
5558 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
5559 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
5560 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
5561 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
5562 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
5563 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
5564 | case OP_oRND: |
5565 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
c19d1205 ZW |
5566 | case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break; |
5567 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; | |
5568 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
5569 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
5570 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
5571 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
5572 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
5573 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
5574 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
5575 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
5576 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
5577 | case OP_oRNQ: |
5578 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
5579 | case OP_oRNDQ: | |
5580 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
5581 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
5582 | case OP_oRNSDQ: | |
5583 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
5584 | |
5585 | /* Neon scalar. Using an element size of 8 means that some invalid | |
5586 | scalars are accepted here, so deal with those in later code. */ | |
5587 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
5588 | ||
5589 | /* WARNING: We can expand to two operands here. This has the potential | |
5590 | to totally confuse the backtracking mechanism! It will be OK at | |
5591 | least as long as we don't try to use optional args as well, | |
5592 | though. */ | |
5593 | case OP_NILO: | |
5594 | { | |
5595 | po_reg_or_goto (REG_TYPE_NDQ, try_imm); | |
466bbf93 | 5596 | inst.operands[i].present = 1; |
5287ad62 JB |
5597 | i++; |
5598 | skip_past_comma (&str); | |
5599 | po_reg_or_goto (REG_TYPE_NDQ, one_reg_only); | |
5600 | break; | |
5601 | one_reg_only: | |
5602 | /* Optional register operand was omitted. Unfortunately, it's in | |
5603 | operands[i-1] and we need it to be in inst.operands[i]. Fix that | |
5604 | here (this is a bit grotty). */ | |
5605 | inst.operands[i] = inst.operands[i-1]; | |
5606 | inst.operands[i-1].present = 0; | |
5607 | break; | |
5608 | try_imm: | |
036dc3f7 PB |
5609 | /* There's a possibility of getting a 64-bit immediate here, so |
5610 | we need special handling. */ | |
5611 | if (parse_big_immediate (&str, i) == FAIL) | |
5612 | { | |
5613 | inst.error = _("immediate value is out of range"); | |
5614 | goto failure; | |
5615 | } | |
5287ad62 JB |
5616 | } |
5617 | break; | |
5618 | ||
5619 | case OP_RNDQ_I0: | |
5620 | { | |
5621 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
5622 | break; | |
5623 | try_imm0: | |
5624 | po_imm_or_fail (0, 0, TRUE); | |
5625 | } | |
5626 | break; | |
5627 | ||
037e8744 JB |
5628 | case OP_RVSD_I0: |
5629 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
5630 | break; | |
5631 | ||
5287ad62 JB |
5632 | case OP_RR_RNSC: |
5633 | { | |
5634 | po_scalar_or_goto (8, try_rr); | |
5635 | break; | |
5636 | try_rr: | |
5637 | po_reg_or_fail (REG_TYPE_RN); | |
5638 | } | |
5639 | break; | |
5640 | ||
037e8744 JB |
5641 | case OP_RNSDQ_RNSC: |
5642 | { | |
5643 | po_scalar_or_goto (8, try_nsdq); | |
5644 | break; | |
5645 | try_nsdq: | |
5646 | po_reg_or_fail (REG_TYPE_NSDQ); | |
5647 | } | |
5648 | break; | |
5649 | ||
5287ad62 JB |
5650 | case OP_RNDQ_RNSC: |
5651 | { | |
5652 | po_scalar_or_goto (8, try_ndq); | |
5653 | break; | |
5654 | try_ndq: | |
5655 | po_reg_or_fail (REG_TYPE_NDQ); | |
5656 | } | |
5657 | break; | |
5658 | ||
5659 | case OP_RND_RNSC: | |
5660 | { | |
5661 | po_scalar_or_goto (8, try_vfd); | |
5662 | break; | |
5663 | try_vfd: | |
5664 | po_reg_or_fail (REG_TYPE_VFD); | |
5665 | } | |
5666 | break; | |
5667 | ||
5668 | case OP_VMOV: | |
5669 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
5670 | not careful then bad things might happen. */ | |
5671 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
5672 | break; | |
5673 | ||
5674 | case OP_RNDQ_IMVNb: | |
5675 | { | |
5676 | po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm); | |
5677 | break; | |
5678 | try_mvnimm: | |
5679 | /* There's a possibility of getting a 64-bit immediate here, so | |
5680 | we need special handling. */ | |
5681 | if (parse_big_immediate (&str, i) == FAIL) | |
5682 | { | |
5683 | inst.error = _("immediate value is out of range"); | |
5684 | goto failure; | |
5685 | } | |
5686 | } | |
5687 | break; | |
5688 | ||
5689 | case OP_RNDQ_I63b: | |
5690 | { | |
5691 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
5692 | break; | |
5693 | try_shimm: | |
5694 | po_imm_or_fail (0, 63, TRUE); | |
5695 | } | |
5696 | break; | |
c19d1205 ZW |
5697 | |
5698 | case OP_RRnpcb: | |
5699 | po_char_or_fail ('['); | |
5700 | po_reg_or_fail (REG_TYPE_RN); | |
5701 | po_char_or_fail (']'); | |
5702 | break; | |
a737bd4d | 5703 | |
c19d1205 ZW |
5704 | case OP_RRw: |
5705 | po_reg_or_fail (REG_TYPE_RN); | |
5706 | if (skip_past_char (&str, '!') == SUCCESS) | |
5707 | inst.operands[i].writeback = 1; | |
5708 | break; | |
5709 | ||
5710 | /* Immediates */ | |
5711 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
5712 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
5713 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 5714 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
5715 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
5716 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 5717 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 5718 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
5719 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
5720 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
5721 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 5722 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
5723 | |
5724 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
5725 | case OP_oI7b: | |
5726 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
5727 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
5728 | case OP_oI31b: | |
5729 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 5730 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
c19d1205 ZW |
5731 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
5732 | ||
5733 | /* Immediate variants */ | |
5734 | case OP_oI255c: | |
5735 | po_char_or_fail ('{'); | |
5736 | po_imm_or_fail (0, 255, TRUE); | |
5737 | po_char_or_fail ('}'); | |
5738 | break; | |
5739 | ||
5740 | case OP_I31w: | |
5741 | /* The expression parser chokes on a trailing !, so we have | |
5742 | to find it first and zap it. */ | |
5743 | { | |
5744 | char *s = str; | |
5745 | while (*s && *s != ',') | |
5746 | s++; | |
5747 | if (s[-1] == '!') | |
5748 | { | |
5749 | s[-1] = '\0'; | |
5750 | inst.operands[i].writeback = 1; | |
5751 | } | |
5752 | po_imm_or_fail (0, 31, TRUE); | |
5753 | if (str == s - 1) | |
5754 | str = s; | |
5755 | } | |
5756 | break; | |
5757 | ||
5758 | /* Expressions */ | |
5759 | case OP_EXPi: EXPi: | |
5760 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
5761 | GE_OPT_PREFIX)); | |
5762 | break; | |
5763 | ||
5764 | case OP_EXP: | |
5765 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
5766 | GE_NO_PREFIX)); | |
5767 | break; | |
5768 | ||
5769 | case OP_EXPr: EXPr: | |
5770 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
5771 | GE_NO_PREFIX)); | |
5772 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 5773 | { |
c19d1205 ZW |
5774 | val = parse_reloc (&str); |
5775 | if (val == -1) | |
5776 | { | |
5777 | inst.error = _("unrecognized relocation suffix"); | |
5778 | goto failure; | |
5779 | } | |
5780 | else if (val != BFD_RELOC_UNUSED) | |
5781 | { | |
5782 | inst.operands[i].imm = val; | |
5783 | inst.operands[i].hasreloc = 1; | |
5784 | } | |
a737bd4d | 5785 | } |
c19d1205 | 5786 | break; |
a737bd4d | 5787 | |
b6895b4f PB |
5788 | /* Operand for MOVW or MOVT. */ |
5789 | case OP_HALF: | |
5790 | po_misc_or_fail (parse_half (&str)); | |
5791 | break; | |
5792 | ||
c19d1205 ZW |
5793 | /* Register or expression */ |
5794 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; | |
5795 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 5796 | |
c19d1205 ZW |
5797 | /* Register or immediate */ |
5798 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; | |
5799 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 5800 | |
c19d1205 ZW |
5801 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
5802 | IF: | |
5803 | if (!is_immediate_prefix (*str)) | |
5804 | goto bad_args; | |
5805 | str++; | |
5806 | val = parse_fpa_immediate (&str); | |
5807 | if (val == FAIL) | |
5808 | goto failure; | |
5809 | /* FPA immediates are encoded as registers 8-15. | |
5810 | parse_fpa_immediate has already applied the offset. */ | |
5811 | inst.operands[i].reg = val; | |
5812 | inst.operands[i].isreg = 1; | |
5813 | break; | |
09d92015 | 5814 | |
2d447fca JM |
5815 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
5816 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
5817 | ||
c19d1205 ZW |
5818 | /* Two kinds of register */ |
5819 | case OP_RIWR_RIWC: | |
5820 | { | |
5821 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
5822 | if (!rege |
5823 | || (rege->type != REG_TYPE_MMXWR | |
5824 | && rege->type != REG_TYPE_MMXWC | |
5825 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
5826 | { |
5827 | inst.error = _("iWMMXt data or control register expected"); | |
5828 | goto failure; | |
5829 | } | |
5830 | inst.operands[i].reg = rege->number; | |
5831 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
5832 | } | |
5833 | break; | |
09d92015 | 5834 | |
41adaa5c JM |
5835 | case OP_RIWC_RIWG: |
5836 | { | |
5837 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
5838 | if (!rege | |
5839 | || (rege->type != REG_TYPE_MMXWC | |
5840 | && rege->type != REG_TYPE_MMXWCG)) | |
5841 | { | |
5842 | inst.error = _("iWMMXt control register expected"); | |
5843 | goto failure; | |
5844 | } | |
5845 | inst.operands[i].reg = rege->number; | |
5846 | inst.operands[i].isreg = 1; | |
5847 | } | |
5848 | break; | |
5849 | ||
c19d1205 ZW |
5850 | /* Misc */ |
5851 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
5852 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
5853 | case OP_oROR: val = parse_ror (&str); break; | |
5854 | case OP_PSR: val = parse_psr (&str); break; | |
5855 | case OP_COND: val = parse_cond (&str); break; | |
62b3e311 | 5856 | case OP_oBARRIER:val = parse_barrier (&str); break; |
c19d1205 | 5857 | |
037e8744 JB |
5858 | case OP_RVC_PSR: |
5859 | po_reg_or_goto (REG_TYPE_VFC, try_psr); | |
5860 | inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */ | |
5861 | break; | |
5862 | try_psr: | |
5863 | val = parse_psr (&str); | |
5864 | break; | |
5865 | ||
5866 | case OP_APSR_RR: | |
5867 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
5868 | break; | |
5869 | try_apsr: | |
5870 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
5871 | instruction). */ | |
5872 | if (strncasecmp (str, "APSR_", 5) == 0) | |
5873 | { | |
5874 | unsigned found = 0; | |
5875 | str += 5; | |
5876 | while (found < 15) | |
5877 | switch (*str++) | |
5878 | { | |
5879 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
5880 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
5881 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
5882 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
5883 | default: found = 16; | |
5884 | } | |
5885 | if (found != 15) | |
5886 | goto failure; | |
5887 | inst.operands[i].isvec = 1; | |
5888 | } | |
5889 | else | |
5890 | goto failure; | |
5891 | break; | |
5892 | ||
92e90b6e PB |
5893 | case OP_TB: |
5894 | po_misc_or_fail (parse_tb (&str)); | |
5895 | break; | |
5896 | ||
c19d1205 ZW |
5897 | /* Register lists */ |
5898 | case OP_REGLST: | |
5899 | val = parse_reg_list (&str); | |
5900 | if (*str == '^') | |
5901 | { | |
5902 | inst.operands[1].writeback = 1; | |
5903 | str++; | |
5904 | } | |
5905 | break; | |
09d92015 | 5906 | |
c19d1205 | 5907 | case OP_VRSLST: |
5287ad62 | 5908 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 5909 | break; |
09d92015 | 5910 | |
c19d1205 | 5911 | case OP_VRDLST: |
5287ad62 | 5912 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 5913 | break; |
a737bd4d | 5914 | |
037e8744 JB |
5915 | case OP_VRSDLST: |
5916 | /* Allow Q registers too. */ | |
5917 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
5918 | REGLIST_NEON_D); | |
5919 | if (val == FAIL) | |
5920 | { | |
5921 | inst.error = NULL; | |
5922 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
5923 | REGLIST_VFP_S); | |
5924 | inst.operands[i].issingle = 1; | |
5925 | } | |
5926 | break; | |
5927 | ||
5287ad62 JB |
5928 | case OP_NRDLST: |
5929 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
5930 | REGLIST_NEON_D); | |
5931 | break; | |
5932 | ||
5933 | case OP_NSTRLST: | |
dcbf9037 JB |
5934 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
5935 | &inst.operands[i].vectype); | |
5287ad62 JB |
5936 | break; |
5937 | ||
c19d1205 ZW |
5938 | /* Addressing modes */ |
5939 | case OP_ADDR: | |
5940 | po_misc_or_fail (parse_address (&str, i)); | |
5941 | break; | |
09d92015 | 5942 | |
4962c51a MS |
5943 | case OP_ADDRGLDR: |
5944 | po_misc_or_fail_no_backtrack ( | |
5945 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
5946 | break; | |
5947 | ||
5948 | case OP_ADDRGLDRS: | |
5949 | po_misc_or_fail_no_backtrack ( | |
5950 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
5951 | break; | |
5952 | ||
5953 | case OP_ADDRGLDC: | |
5954 | po_misc_or_fail_no_backtrack ( | |
5955 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
5956 | break; | |
5957 | ||
c19d1205 ZW |
5958 | case OP_SH: |
5959 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
5960 | break; | |
09d92015 | 5961 | |
4962c51a MS |
5962 | case OP_SHG: |
5963 | po_misc_or_fail_no_backtrack ( | |
5964 | parse_shifter_operand_group_reloc (&str, i)); | |
5965 | break; | |
5966 | ||
c19d1205 ZW |
5967 | case OP_oSHll: |
5968 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
5969 | break; | |
09d92015 | 5970 | |
c19d1205 ZW |
5971 | case OP_oSHar: |
5972 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
5973 | break; | |
09d92015 | 5974 | |
c19d1205 ZW |
5975 | case OP_oSHllar: |
5976 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
5977 | break; | |
09d92015 | 5978 | |
c19d1205 ZW |
5979 | default: |
5980 | as_fatal ("unhandled operand code %d", upat[i]); | |
5981 | } | |
09d92015 | 5982 | |
c19d1205 ZW |
5983 | /* Various value-based sanity checks and shared operations. We |
5984 | do not signal immediate failures for the register constraints; | |
5985 | this allows a syntax error to take precedence. */ | |
5986 | switch (upat[i]) | |
5987 | { | |
5988 | case OP_oRRnpc: | |
5989 | case OP_RRnpc: | |
5990 | case OP_RRnpcb: | |
5991 | case OP_RRw: | |
5992 | case OP_RRnpc_I0: | |
5993 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
5994 | inst.error = BAD_PC; | |
5995 | break; | |
09d92015 | 5996 | |
c19d1205 ZW |
5997 | case OP_CPSF: |
5998 | case OP_ENDI: | |
5999 | case OP_oROR: | |
6000 | case OP_PSR: | |
037e8744 | 6001 | case OP_RVC_PSR: |
c19d1205 | 6002 | case OP_COND: |
62b3e311 | 6003 | case OP_oBARRIER: |
c19d1205 ZW |
6004 | case OP_REGLST: |
6005 | case OP_VRSLST: | |
6006 | case OP_VRDLST: | |
037e8744 | 6007 | case OP_VRSDLST: |
5287ad62 JB |
6008 | case OP_NRDLST: |
6009 | case OP_NSTRLST: | |
c19d1205 ZW |
6010 | if (val == FAIL) |
6011 | goto failure; | |
6012 | inst.operands[i].imm = val; | |
6013 | break; | |
a737bd4d | 6014 | |
c19d1205 ZW |
6015 | default: |
6016 | break; | |
6017 | } | |
09d92015 | 6018 | |
c19d1205 ZW |
6019 | /* If we get here, this operand was successfully parsed. */ |
6020 | inst.operands[i].present = 1; | |
6021 | continue; | |
09d92015 | 6022 | |
c19d1205 | 6023 | bad_args: |
09d92015 | 6024 | inst.error = BAD_ARGS; |
c19d1205 ZW |
6025 | |
6026 | failure: | |
6027 | if (!backtrack_pos) | |
d252fdde PB |
6028 | { |
6029 | /* The parse routine should already have set inst.error, but set a | |
6030 | defaut here just in case. */ | |
6031 | if (!inst.error) | |
6032 | inst.error = _("syntax error"); | |
6033 | return FAIL; | |
6034 | } | |
c19d1205 ZW |
6035 | |
6036 | /* Do not backtrack over a trailing optional argument that | |
6037 | absorbed some text. We will only fail again, with the | |
6038 | 'garbage following instruction' error message, which is | |
6039 | probably less helpful than the current one. */ | |
6040 | if (backtrack_index == i && backtrack_pos != str | |
6041 | && upat[i+1] == OP_stop) | |
d252fdde PB |
6042 | { |
6043 | if (!inst.error) | |
6044 | inst.error = _("syntax error"); | |
6045 | return FAIL; | |
6046 | } | |
c19d1205 ZW |
6047 | |
6048 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
6049 | str = backtrack_pos; | |
6050 | inst.error = backtrack_error; | |
6051 | inst.operands[backtrack_index].present = 0; | |
6052 | i = backtrack_index; | |
6053 | backtrack_pos = 0; | |
09d92015 | 6054 | } |
09d92015 | 6055 | |
c19d1205 ZW |
6056 | /* Check that we have parsed all the arguments. */ |
6057 | if (*str != '\0' && !inst.error) | |
6058 | inst.error = _("garbage following instruction"); | |
09d92015 | 6059 | |
c19d1205 | 6060 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
6061 | } |
6062 | ||
c19d1205 ZW |
6063 | #undef po_char_or_fail |
6064 | #undef po_reg_or_fail | |
6065 | #undef po_reg_or_goto | |
6066 | #undef po_imm_or_fail | |
5287ad62 | 6067 | #undef po_scalar_or_fail |
c19d1205 ZW |
6068 | \f |
6069 | /* Shorthand macro for instruction encoding functions issuing errors. */ | |
6070 | #define constraint(expr, err) do { \ | |
6071 | if (expr) \ | |
6072 | { \ | |
6073 | inst.error = err; \ | |
6074 | return; \ | |
6075 | } \ | |
6076 | } while (0) | |
6077 | ||
6078 | /* Functions for operand encoding. ARM, then Thumb. */ | |
6079 | ||
6080 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
6081 | ||
6082 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
6083 | return the encoded form. Otherwise, return FAIL. */ | |
6084 | ||
6085 | static unsigned int | |
6086 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6087 | { |
c19d1205 ZW |
6088 | unsigned int a, i; |
6089 | ||
6090 | for (i = 0; i < 32; i += 2) | |
6091 | if ((a = rotate_left (val, i)) <= 0xff) | |
6092 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6093 | ||
6094 | return FAIL; | |
09d92015 MM |
6095 | } |
6096 | ||
c19d1205 ZW |
6097 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6098 | return the encoded form. Otherwise, return FAIL. */ | |
6099 | static unsigned int | |
6100 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6101 | { |
c19d1205 | 6102 | unsigned int a, i; |
09d92015 | 6103 | |
9c3c69f2 | 6104 | if (val <= 0xff) |
c19d1205 | 6105 | return val; |
a737bd4d | 6106 | |
9c3c69f2 | 6107 | for (i = 1; i <= 24; i++) |
09d92015 | 6108 | { |
9c3c69f2 PB |
6109 | a = val >> i; |
6110 | if ((val & ~(0xff << i)) == 0) | |
6111 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6112 | } |
a737bd4d | 6113 | |
c19d1205 ZW |
6114 | a = val & 0xff; |
6115 | if (val == ((a << 16) | a)) | |
6116 | return 0x100 | a; | |
6117 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6118 | return 0x300 | a; | |
09d92015 | 6119 | |
c19d1205 ZW |
6120 | a = val & 0xff00; |
6121 | if (val == ((a << 16) | a)) | |
6122 | return 0x200 | (a >> 8); | |
a737bd4d | 6123 | |
c19d1205 | 6124 | return FAIL; |
09d92015 | 6125 | } |
5287ad62 | 6126 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6127 | |
6128 | static void | |
5287ad62 JB |
6129 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6130 | { | |
6131 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6132 | && reg > 15) | |
6133 | { | |
6134 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
6135 | { | |
6136 | if (thumb_mode) | |
6137 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
6138 | fpu_vfp_ext_v3); | |
6139 | else | |
6140 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
6141 | fpu_vfp_ext_v3); | |
6142 | } | |
6143 | else | |
6144 | { | |
dcbf9037 | 6145 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
6146 | return; |
6147 | } | |
6148 | } | |
6149 | ||
c19d1205 | 6150 | switch (pos) |
09d92015 | 6151 | { |
c19d1205 ZW |
6152 | case VFP_REG_Sd: |
6153 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
6154 | break; | |
6155 | ||
6156 | case VFP_REG_Sn: | |
6157 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
6158 | break; | |
6159 | ||
6160 | case VFP_REG_Sm: | |
6161 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
6162 | break; | |
6163 | ||
5287ad62 JB |
6164 | case VFP_REG_Dd: |
6165 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
6166 | break; | |
6167 | ||
6168 | case VFP_REG_Dn: | |
6169 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
6170 | break; | |
6171 | ||
6172 | case VFP_REG_Dm: | |
6173 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
6174 | break; | |
6175 | ||
c19d1205 ZW |
6176 | default: |
6177 | abort (); | |
09d92015 | 6178 | } |
09d92015 MM |
6179 | } |
6180 | ||
c19d1205 | 6181 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 6182 | if any, is handled by md_apply_fix. */ |
09d92015 | 6183 | static void |
c19d1205 | 6184 | encode_arm_shift (int i) |
09d92015 | 6185 | { |
c19d1205 ZW |
6186 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
6187 | inst.instruction |= SHIFT_ROR << 5; | |
6188 | else | |
09d92015 | 6189 | { |
c19d1205 ZW |
6190 | inst.instruction |= inst.operands[i].shift_kind << 5; |
6191 | if (inst.operands[i].immisreg) | |
6192 | { | |
6193 | inst.instruction |= SHIFT_BY_REG; | |
6194 | inst.instruction |= inst.operands[i].imm << 8; | |
6195 | } | |
6196 | else | |
6197 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 6198 | } |
c19d1205 | 6199 | } |
09d92015 | 6200 | |
c19d1205 ZW |
6201 | static void |
6202 | encode_arm_shifter_operand (int i) | |
6203 | { | |
6204 | if (inst.operands[i].isreg) | |
09d92015 | 6205 | { |
c19d1205 ZW |
6206 | inst.instruction |= inst.operands[i].reg; |
6207 | encode_arm_shift (i); | |
09d92015 | 6208 | } |
c19d1205 ZW |
6209 | else |
6210 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
6211 | } |
6212 | ||
c19d1205 | 6213 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 6214 | static void |
c19d1205 | 6215 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 6216 | { |
c19d1205 ZW |
6217 | assert (inst.operands[i].isreg); |
6218 | inst.instruction |= inst.operands[i].reg << 16; | |
a737bd4d | 6219 | |
c19d1205 | 6220 | if (inst.operands[i].preind) |
09d92015 | 6221 | { |
c19d1205 ZW |
6222 | if (is_t) |
6223 | { | |
6224 | inst.error = _("instruction does not accept preindexed addressing"); | |
6225 | return; | |
6226 | } | |
6227 | inst.instruction |= PRE_INDEX; | |
6228 | if (inst.operands[i].writeback) | |
6229 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6230 | |
c19d1205 ZW |
6231 | } |
6232 | else if (inst.operands[i].postind) | |
6233 | { | |
6234 | assert (inst.operands[i].writeback); | |
6235 | if (is_t) | |
6236 | inst.instruction |= WRITE_BACK; | |
6237 | } | |
6238 | else /* unindexed - only for coprocessor */ | |
09d92015 | 6239 | { |
c19d1205 | 6240 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
6241 | return; |
6242 | } | |
6243 | ||
c19d1205 ZW |
6244 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
6245 | && (((inst.instruction & 0x000f0000) >> 16) | |
6246 | == ((inst.instruction & 0x0000f000) >> 12))) | |
6247 | as_warn ((inst.instruction & LOAD_BIT) | |
6248 | ? _("destination register same as write-back base") | |
6249 | : _("source register same as write-back base")); | |
09d92015 MM |
6250 | } |
6251 | ||
c19d1205 ZW |
6252 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6253 | ARM-format mode 2 load or store instruction. If is_t is true, | |
6254 | reject forms that cannot be used with a T instruction (i.e. not | |
6255 | post-indexed). */ | |
a737bd4d | 6256 | static void |
c19d1205 | 6257 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 6258 | { |
c19d1205 | 6259 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6260 | |
c19d1205 | 6261 | if (inst.operands[i].immisreg) |
09d92015 | 6262 | { |
c19d1205 ZW |
6263 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
6264 | inst.instruction |= inst.operands[i].imm; | |
6265 | if (!inst.operands[i].negative) | |
6266 | inst.instruction |= INDEX_UP; | |
6267 | if (inst.operands[i].shifted) | |
6268 | { | |
6269 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
6270 | inst.instruction |= SHIFT_ROR << 5; | |
6271 | else | |
6272 | { | |
6273 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
6274 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
6275 | } | |
6276 | } | |
09d92015 | 6277 | } |
c19d1205 | 6278 | else /* immediate offset in inst.reloc */ |
09d92015 | 6279 | { |
c19d1205 ZW |
6280 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6281 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 6282 | } |
09d92015 MM |
6283 | } |
6284 | ||
c19d1205 ZW |
6285 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6286 | ARM-format mode 3 load or store instruction. Reject forms that | |
6287 | cannot be used with such instructions. If is_t is true, reject | |
6288 | forms that cannot be used with a T instruction (i.e. not | |
6289 | post-indexed). */ | |
6290 | static void | |
6291 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 6292 | { |
c19d1205 | 6293 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 6294 | { |
c19d1205 ZW |
6295 | inst.error = _("instruction does not accept scaled register index"); |
6296 | return; | |
09d92015 | 6297 | } |
a737bd4d | 6298 | |
c19d1205 | 6299 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6300 | |
c19d1205 ZW |
6301 | if (inst.operands[i].immisreg) |
6302 | { | |
6303 | inst.instruction |= inst.operands[i].imm; | |
6304 | if (!inst.operands[i].negative) | |
6305 | inst.instruction |= INDEX_UP; | |
6306 | } | |
6307 | else /* immediate offset in inst.reloc */ | |
6308 | { | |
6309 | inst.instruction |= HWOFFSET_IMM; | |
6310 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6311 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 6312 | } |
a737bd4d NC |
6313 | } |
6314 | ||
c19d1205 ZW |
6315 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6316 | ARM-format instruction. Reject all forms which cannot be encoded | |
6317 | into a coprocessor load/store instruction. If wb_ok is false, | |
6318 | reject use of writeback; if unind_ok is false, reject use of | |
6319 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
6320 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
6321 | (in which case it is preserved). */ | |
09d92015 | 6322 | |
c19d1205 ZW |
6323 | static int |
6324 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 6325 | { |
c19d1205 | 6326 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6327 | |
c19d1205 | 6328 | assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 6329 | |
c19d1205 | 6330 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 6331 | { |
c19d1205 ZW |
6332 | assert (!inst.operands[i].writeback); |
6333 | if (!unind_ok) | |
6334 | { | |
6335 | inst.error = _("instruction does not support unindexed addressing"); | |
6336 | return FAIL; | |
6337 | } | |
6338 | inst.instruction |= inst.operands[i].imm; | |
6339 | inst.instruction |= INDEX_UP; | |
6340 | return SUCCESS; | |
09d92015 | 6341 | } |
a737bd4d | 6342 | |
c19d1205 ZW |
6343 | if (inst.operands[i].preind) |
6344 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 6345 | |
c19d1205 | 6346 | if (inst.operands[i].writeback) |
09d92015 | 6347 | { |
c19d1205 ZW |
6348 | if (inst.operands[i].reg == REG_PC) |
6349 | { | |
6350 | inst.error = _("pc may not be used with write-back"); | |
6351 | return FAIL; | |
6352 | } | |
6353 | if (!wb_ok) | |
6354 | { | |
6355 | inst.error = _("instruction does not support writeback"); | |
6356 | return FAIL; | |
6357 | } | |
6358 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6359 | } |
a737bd4d | 6360 | |
c19d1205 ZW |
6361 | if (reloc_override) |
6362 | inst.reloc.type = reloc_override; | |
4962c51a MS |
6363 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
6364 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
6365 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
6366 | { | |
6367 | if (thumb_mode) | |
6368 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
6369 | else | |
6370 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
6371 | } | |
6372 | ||
c19d1205 ZW |
6373 | return SUCCESS; |
6374 | } | |
a737bd4d | 6375 | |
c19d1205 ZW |
6376 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
6377 | Determine whether it can be performed with a move instruction; if | |
6378 | it can, convert inst.instruction to that move instruction and | |
6379 | return 1; if it can't, convert inst.instruction to a literal-pool | |
6380 | load and return 0. If this is not a valid thing to do in the | |
6381 | current context, set inst.error and return 1. | |
a737bd4d | 6382 | |
c19d1205 ZW |
6383 | inst.operands[i] describes the destination register. */ |
6384 | ||
6385 | static int | |
6386 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) | |
6387 | { | |
53365c0d PB |
6388 | unsigned long tbit; |
6389 | ||
6390 | if (thumb_p) | |
6391 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
6392 | else | |
6393 | tbit = LOAD_BIT; | |
6394 | ||
6395 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 6396 | { |
c19d1205 ZW |
6397 | inst.error = _("invalid pseudo operation"); |
6398 | return 1; | |
09d92015 | 6399 | } |
c19d1205 | 6400 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
6401 | { |
6402 | inst.error = _("constant expression expected"); | |
c19d1205 | 6403 | return 1; |
09d92015 | 6404 | } |
c19d1205 | 6405 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 6406 | { |
c19d1205 ZW |
6407 | if (thumb_p) |
6408 | { | |
53365c0d | 6409 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
6410 | { |
6411 | /* This can be done with a mov(1) instruction. */ | |
6412 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
6413 | inst.instruction |= inst.reloc.exp.X_add_number; | |
6414 | return 1; | |
6415 | } | |
6416 | } | |
6417 | else | |
6418 | { | |
6419 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
6420 | if (value != FAIL) | |
6421 | { | |
6422 | /* This can be done with a mov instruction. */ | |
6423 | inst.instruction &= LITERAL_MASK; | |
6424 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
6425 | inst.instruction |= value & 0xfff; | |
6426 | return 1; | |
6427 | } | |
09d92015 | 6428 | |
c19d1205 ZW |
6429 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
6430 | if (value != FAIL) | |
6431 | { | |
6432 | /* This can be done with a mvn instruction. */ | |
6433 | inst.instruction &= LITERAL_MASK; | |
6434 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
6435 | inst.instruction |= value & 0xfff; | |
6436 | return 1; | |
6437 | } | |
6438 | } | |
09d92015 MM |
6439 | } |
6440 | ||
c19d1205 ZW |
6441 | if (add_to_lit_pool () == FAIL) |
6442 | { | |
6443 | inst.error = _("literal pool insertion failed"); | |
6444 | return 1; | |
6445 | } | |
6446 | inst.operands[1].reg = REG_PC; | |
6447 | inst.operands[1].isreg = 1; | |
6448 | inst.operands[1].preind = 1; | |
6449 | inst.reloc.pc_rel = 1; | |
6450 | inst.reloc.type = (thumb_p | |
6451 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
6452 | : (mode_3 | |
6453 | ? BFD_RELOC_ARM_HWLITERAL | |
6454 | : BFD_RELOC_ARM_LITERAL)); | |
6455 | return 0; | |
09d92015 MM |
6456 | } |
6457 | ||
c19d1205 ZW |
6458 | /* Functions for instruction encoding, sorted by subarchitecture. |
6459 | First some generics; their names are taken from the conventional | |
6460 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 6461 | |
a737bd4d | 6462 | static void |
c19d1205 | 6463 | do_noargs (void) |
09d92015 | 6464 | { |
c19d1205 | 6465 | } |
a737bd4d | 6466 | |
c19d1205 ZW |
6467 | static void |
6468 | do_rd (void) | |
6469 | { | |
6470 | inst.instruction |= inst.operands[0].reg << 12; | |
6471 | } | |
a737bd4d | 6472 | |
c19d1205 ZW |
6473 | static void |
6474 | do_rd_rm (void) | |
6475 | { | |
6476 | inst.instruction |= inst.operands[0].reg << 12; | |
6477 | inst.instruction |= inst.operands[1].reg; | |
6478 | } | |
09d92015 | 6479 | |
c19d1205 ZW |
6480 | static void |
6481 | do_rd_rn (void) | |
6482 | { | |
6483 | inst.instruction |= inst.operands[0].reg << 12; | |
6484 | inst.instruction |= inst.operands[1].reg << 16; | |
6485 | } | |
a737bd4d | 6486 | |
c19d1205 ZW |
6487 | static void |
6488 | do_rn_rd (void) | |
6489 | { | |
6490 | inst.instruction |= inst.operands[0].reg << 16; | |
6491 | inst.instruction |= inst.operands[1].reg << 12; | |
6492 | } | |
09d92015 | 6493 | |
c19d1205 ZW |
6494 | static void |
6495 | do_rd_rm_rn (void) | |
6496 | { | |
9a64e435 | 6497 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 6498 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 PB |
6499 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
6500 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
6501 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
6502 | inst.instruction |= inst.operands[0].reg << 12; |
6503 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 6504 | inst.instruction |= Rn << 16; |
c19d1205 | 6505 | } |
09d92015 | 6506 | |
c19d1205 ZW |
6507 | static void |
6508 | do_rd_rn_rm (void) | |
6509 | { | |
6510 | inst.instruction |= inst.operands[0].reg << 12; | |
6511 | inst.instruction |= inst.operands[1].reg << 16; | |
6512 | inst.instruction |= inst.operands[2].reg; | |
6513 | } | |
a737bd4d | 6514 | |
c19d1205 ZW |
6515 | static void |
6516 | do_rm_rd_rn (void) | |
6517 | { | |
6518 | inst.instruction |= inst.operands[0].reg; | |
6519 | inst.instruction |= inst.operands[1].reg << 12; | |
6520 | inst.instruction |= inst.operands[2].reg << 16; | |
6521 | } | |
09d92015 | 6522 | |
c19d1205 ZW |
6523 | static void |
6524 | do_imm0 (void) | |
6525 | { | |
6526 | inst.instruction |= inst.operands[0].imm; | |
6527 | } | |
09d92015 | 6528 | |
c19d1205 ZW |
6529 | static void |
6530 | do_rd_cpaddr (void) | |
6531 | { | |
6532 | inst.instruction |= inst.operands[0].reg << 12; | |
6533 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 6534 | } |
a737bd4d | 6535 | |
c19d1205 ZW |
6536 | /* ARM instructions, in alphabetical order by function name (except |
6537 | that wrapper functions appear immediately after the function they | |
6538 | wrap). */ | |
09d92015 | 6539 | |
c19d1205 ZW |
6540 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
6541 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
6542 | |
6543 | static void | |
c19d1205 | 6544 | do_adr (void) |
09d92015 | 6545 | { |
c19d1205 | 6546 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 6547 | |
c19d1205 ZW |
6548 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6549 | out to be negative. */ | |
6550 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 6551 | inst.reloc.pc_rel = 1; |
2fc8bdac | 6552 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 6553 | } |
b99bd4ef | 6554 | |
c19d1205 ZW |
6555 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
6556 | into a relative address of the form: | |
6557 | add rd, pc, #low(label-.-8)" | |
6558 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 6559 | |
c19d1205 ZW |
6560 | static void |
6561 | do_adrl (void) | |
6562 | { | |
6563 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 6564 | |
c19d1205 ZW |
6565 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6566 | out to be negative. */ | |
6567 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
6568 | inst.reloc.pc_rel = 1; |
6569 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 6570 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
6571 | } |
6572 | ||
b99bd4ef | 6573 | static void |
c19d1205 | 6574 | do_arit (void) |
b99bd4ef | 6575 | { |
c19d1205 ZW |
6576 | if (!inst.operands[1].present) |
6577 | inst.operands[1].reg = inst.operands[0].reg; | |
6578 | inst.instruction |= inst.operands[0].reg << 12; | |
6579 | inst.instruction |= inst.operands[1].reg << 16; | |
6580 | encode_arm_shifter_operand (2); | |
6581 | } | |
b99bd4ef | 6582 | |
62b3e311 PB |
6583 | static void |
6584 | do_barrier (void) | |
6585 | { | |
6586 | if (inst.operands[0].present) | |
6587 | { | |
6588 | constraint ((inst.instruction & 0xf0) != 0x40 | |
6589 | && inst.operands[0].imm != 0xf, | |
6590 | "bad barrier type"); | |
6591 | inst.instruction |= inst.operands[0].imm; | |
6592 | } | |
6593 | else | |
6594 | inst.instruction |= 0xf; | |
6595 | } | |
6596 | ||
c19d1205 ZW |
6597 | static void |
6598 | do_bfc (void) | |
6599 | { | |
6600 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
6601 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6602 | /* The instruction encoding stores the LSB and MSB, | |
6603 | not the LSB and width. */ | |
6604 | inst.instruction |= inst.operands[0].reg << 12; | |
6605 | inst.instruction |= inst.operands[1].imm << 7; | |
6606 | inst.instruction |= (msb - 1) << 16; | |
6607 | } | |
b99bd4ef | 6608 | |
c19d1205 ZW |
6609 | static void |
6610 | do_bfi (void) | |
6611 | { | |
6612 | unsigned int msb; | |
b99bd4ef | 6613 | |
c19d1205 ZW |
6614 | /* #0 in second position is alternative syntax for bfc, which is |
6615 | the same instruction but with REG_PC in the Rm field. */ | |
6616 | if (!inst.operands[1].isreg) | |
6617 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 6618 | |
c19d1205 ZW |
6619 | msb = inst.operands[2].imm + inst.operands[3].imm; |
6620 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6621 | /* The instruction encoding stores the LSB and MSB, | |
6622 | not the LSB and width. */ | |
6623 | inst.instruction |= inst.operands[0].reg << 12; | |
6624 | inst.instruction |= inst.operands[1].reg; | |
6625 | inst.instruction |= inst.operands[2].imm << 7; | |
6626 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
6627 | } |
6628 | ||
b99bd4ef | 6629 | static void |
c19d1205 | 6630 | do_bfx (void) |
b99bd4ef | 6631 | { |
c19d1205 ZW |
6632 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
6633 | _("bit-field extends past end of register")); | |
6634 | inst.instruction |= inst.operands[0].reg << 12; | |
6635 | inst.instruction |= inst.operands[1].reg; | |
6636 | inst.instruction |= inst.operands[2].imm << 7; | |
6637 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
6638 | } | |
09d92015 | 6639 | |
c19d1205 ZW |
6640 | /* ARM V5 breakpoint instruction (argument parse) |
6641 | BKPT <16 bit unsigned immediate> | |
6642 | Instruction is not conditional. | |
6643 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
6644 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 6645 | |
c19d1205 ZW |
6646 | static void |
6647 | do_bkpt (void) | |
6648 | { | |
6649 | /* Top 12 of 16 bits to bits 19:8. */ | |
6650 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 6651 | |
c19d1205 ZW |
6652 | /* Bottom 4 of 16 bits to bits 3:0. */ |
6653 | inst.instruction |= inst.operands[0].imm & 0xf; | |
6654 | } | |
09d92015 | 6655 | |
c19d1205 ZW |
6656 | static void |
6657 | encode_branch (int default_reloc) | |
6658 | { | |
6659 | if (inst.operands[0].hasreloc) | |
6660 | { | |
6661 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
6662 | _("the only suffix valid here is '(plt)'")); | |
6663 | inst.reloc.type = BFD_RELOC_ARM_PLT32; | |
c19d1205 | 6664 | } |
b99bd4ef | 6665 | else |
c19d1205 ZW |
6666 | { |
6667 | inst.reloc.type = default_reloc; | |
c19d1205 | 6668 | } |
2fc8bdac | 6669 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
6670 | } |
6671 | ||
b99bd4ef | 6672 | static void |
c19d1205 | 6673 | do_branch (void) |
b99bd4ef | 6674 | { |
39b41c9c PB |
6675 | #ifdef OBJ_ELF |
6676 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6677 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
6678 | else | |
6679 | #endif | |
6680 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
6681 | } | |
6682 | ||
6683 | static void | |
6684 | do_bl (void) | |
6685 | { | |
6686 | #ifdef OBJ_ELF | |
6687 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6688 | { | |
6689 | if (inst.cond == COND_ALWAYS) | |
6690 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
6691 | else | |
6692 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
6693 | } | |
6694 | else | |
6695 | #endif | |
6696 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 6697 | } |
b99bd4ef | 6698 | |
c19d1205 ZW |
6699 | /* ARM V5 branch-link-exchange instruction (argument parse) |
6700 | BLX <target_addr> ie BLX(1) | |
6701 | BLX{<condition>} <Rm> ie BLX(2) | |
6702 | Unfortunately, there are two different opcodes for this mnemonic. | |
6703 | So, the insns[].value is not used, and the code here zaps values | |
6704 | into inst.instruction. | |
6705 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 6706 | |
c19d1205 ZW |
6707 | static void |
6708 | do_blx (void) | |
6709 | { | |
6710 | if (inst.operands[0].isreg) | |
b99bd4ef | 6711 | { |
c19d1205 ZW |
6712 | /* Arg is a register; the opcode provided by insns[] is correct. |
6713 | It is not illegal to do "blx pc", just useless. */ | |
6714 | if (inst.operands[0].reg == REG_PC) | |
6715 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 6716 | |
c19d1205 ZW |
6717 | inst.instruction |= inst.operands[0].reg; |
6718 | } | |
6719 | else | |
b99bd4ef | 6720 | { |
c19d1205 ZW |
6721 | /* Arg is an address; this instruction cannot be executed |
6722 | conditionally, and the opcode must be adjusted. */ | |
6723 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
2fc8bdac | 6724 | inst.instruction = 0xfa000000; |
39b41c9c PB |
6725 | #ifdef OBJ_ELF |
6726 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6727 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
6728 | else | |
6729 | #endif | |
6730 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); | |
b99bd4ef | 6731 | } |
c19d1205 ZW |
6732 | } |
6733 | ||
6734 | static void | |
6735 | do_bx (void) | |
6736 | { | |
6737 | if (inst.operands[0].reg == REG_PC) | |
6738 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 6739 | |
c19d1205 | 6740 | inst.instruction |= inst.operands[0].reg; |
09d92015 MM |
6741 | } |
6742 | ||
c19d1205 ZW |
6743 | |
6744 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
6745 | |
6746 | static void | |
c19d1205 | 6747 | do_bxj (void) |
a737bd4d | 6748 | { |
c19d1205 ZW |
6749 | if (inst.operands[0].reg == REG_PC) |
6750 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
6751 | ||
6752 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
6753 | } |
6754 | ||
c19d1205 ZW |
6755 | /* Co-processor data operation: |
6756 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
6757 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
6758 | static void | |
6759 | do_cdp (void) | |
6760 | { | |
6761 | inst.instruction |= inst.operands[0].reg << 8; | |
6762 | inst.instruction |= inst.operands[1].imm << 20; | |
6763 | inst.instruction |= inst.operands[2].reg << 12; | |
6764 | inst.instruction |= inst.operands[3].reg << 16; | |
6765 | inst.instruction |= inst.operands[4].reg; | |
6766 | inst.instruction |= inst.operands[5].imm << 5; | |
6767 | } | |
a737bd4d NC |
6768 | |
6769 | static void | |
c19d1205 | 6770 | do_cmp (void) |
a737bd4d | 6771 | { |
c19d1205 ZW |
6772 | inst.instruction |= inst.operands[0].reg << 16; |
6773 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
6774 | } |
6775 | ||
c19d1205 ZW |
6776 | /* Transfer between coprocessor and ARM registers. |
6777 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
6778 | MRC2 | |
6779 | MCR{cond} | |
6780 | MCR2 | |
6781 | ||
6782 | No special properties. */ | |
09d92015 MM |
6783 | |
6784 | static void | |
c19d1205 | 6785 | do_co_reg (void) |
09d92015 | 6786 | { |
c19d1205 ZW |
6787 | inst.instruction |= inst.operands[0].reg << 8; |
6788 | inst.instruction |= inst.operands[1].imm << 21; | |
6789 | inst.instruction |= inst.operands[2].reg << 12; | |
6790 | inst.instruction |= inst.operands[3].reg << 16; | |
6791 | inst.instruction |= inst.operands[4].reg; | |
6792 | inst.instruction |= inst.operands[5].imm << 5; | |
6793 | } | |
09d92015 | 6794 | |
c19d1205 ZW |
6795 | /* Transfer between coprocessor register and pair of ARM registers. |
6796 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
6797 | MCRR2 | |
6798 | MRRC{cond} | |
6799 | MRRC2 | |
b99bd4ef | 6800 | |
c19d1205 | 6801 | Two XScale instructions are special cases of these: |
09d92015 | 6802 | |
c19d1205 ZW |
6803 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
6804 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 6805 | |
c19d1205 | 6806 | Result unpredicatable if Rd or Rn is R15. */ |
a737bd4d | 6807 | |
c19d1205 ZW |
6808 | static void |
6809 | do_co_reg2c (void) | |
6810 | { | |
6811 | inst.instruction |= inst.operands[0].reg << 8; | |
6812 | inst.instruction |= inst.operands[1].imm << 4; | |
6813 | inst.instruction |= inst.operands[2].reg << 12; | |
6814 | inst.instruction |= inst.operands[3].reg << 16; | |
6815 | inst.instruction |= inst.operands[4].reg; | |
b99bd4ef NC |
6816 | } |
6817 | ||
c19d1205 ZW |
6818 | static void |
6819 | do_cpsi (void) | |
6820 | { | |
6821 | inst.instruction |= inst.operands[0].imm << 6; | |
6822 | inst.instruction |= inst.operands[1].imm; | |
6823 | } | |
b99bd4ef | 6824 | |
62b3e311 PB |
6825 | static void |
6826 | do_dbg (void) | |
6827 | { | |
6828 | inst.instruction |= inst.operands[0].imm; | |
6829 | } | |
6830 | ||
b99bd4ef | 6831 | static void |
c19d1205 | 6832 | do_it (void) |
b99bd4ef | 6833 | { |
c19d1205 ZW |
6834 | /* There is no IT instruction in ARM mode. We |
6835 | process it but do not generate code for it. */ | |
6836 | inst.size = 0; | |
09d92015 | 6837 | } |
b99bd4ef | 6838 | |
09d92015 | 6839 | static void |
c19d1205 | 6840 | do_ldmstm (void) |
ea6ef066 | 6841 | { |
c19d1205 ZW |
6842 | int base_reg = inst.operands[0].reg; |
6843 | int range = inst.operands[1].imm; | |
ea6ef066 | 6844 | |
c19d1205 ZW |
6845 | inst.instruction |= base_reg << 16; |
6846 | inst.instruction |= range; | |
ea6ef066 | 6847 | |
c19d1205 ZW |
6848 | if (inst.operands[1].writeback) |
6849 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 6850 | |
c19d1205 | 6851 | if (inst.operands[0].writeback) |
ea6ef066 | 6852 | { |
c19d1205 ZW |
6853 | inst.instruction |= WRITE_BACK; |
6854 | /* Check for unpredictable uses of writeback. */ | |
6855 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 6856 | { |
c19d1205 ZW |
6857 | /* Not allowed in LDM type 2. */ |
6858 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
6859 | && ((range & (1 << REG_PC)) == 0)) | |
6860 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
6861 | /* Only allowed if base reg not in list for other types. */ | |
6862 | else if (range & (1 << base_reg)) | |
6863 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
6864 | } | |
6865 | else /* STM. */ | |
6866 | { | |
6867 | /* Not allowed for type 2. */ | |
6868 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
6869 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
6870 | /* Only allowed if base reg not in list, or first in list. */ | |
6871 | else if ((range & (1 << base_reg)) | |
6872 | && (range & ((1 << base_reg) - 1))) | |
6873 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 6874 | } |
ea6ef066 | 6875 | } |
a737bd4d NC |
6876 | } |
6877 | ||
c19d1205 ZW |
6878 | /* ARMv5TE load-consecutive (argument parse) |
6879 | Mode is like LDRH. | |
6880 | ||
6881 | LDRccD R, mode | |
6882 | STRccD R, mode. */ | |
6883 | ||
a737bd4d | 6884 | static void |
c19d1205 | 6885 | do_ldrd (void) |
a737bd4d | 6886 | { |
c19d1205 ZW |
6887 | constraint (inst.operands[0].reg % 2 != 0, |
6888 | _("first destination register must be even")); | |
6889 | constraint (inst.operands[1].present | |
6890 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
6891 | _("can only load two consecutive registers")); | |
6892 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
6893 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 6894 | |
c19d1205 ZW |
6895 | if (!inst.operands[1].present) |
6896 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
6897 | ||
6898 | if (inst.instruction & LOAD_BIT) | |
a737bd4d | 6899 | { |
c19d1205 ZW |
6900 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
6901 | register and the first register written; we have to diagnose | |
6902 | overlap between the base and the second register written here. */ | |
ea6ef066 | 6903 | |
c19d1205 ZW |
6904 | if (inst.operands[2].reg == inst.operands[1].reg |
6905 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
6906 | as_warn (_("base register written back, and overlaps " | |
6907 | "second destination register")); | |
b05fe5cf | 6908 | |
c19d1205 ZW |
6909 | /* For an index-register load, the index register must not overlap the |
6910 | destination (even if not write-back). */ | |
6911 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
6912 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
6913 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 6914 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 6915 | } |
c19d1205 ZW |
6916 | |
6917 | inst.instruction |= inst.operands[0].reg << 12; | |
6918 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
6919 | } |
6920 | ||
6921 | static void | |
c19d1205 | 6922 | do_ldrex (void) |
b05fe5cf | 6923 | { |
c19d1205 ZW |
6924 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
6925 | || inst.operands[1].postind || inst.operands[1].writeback | |
6926 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
6927 | || inst.operands[1].negative |
6928 | /* This can arise if the programmer has written | |
6929 | strex rN, rM, foo | |
6930 | or if they have mistakenly used a register name as the last | |
6931 | operand, eg: | |
6932 | strex rN, rM, rX | |
6933 | It is very difficult to distinguish between these two cases | |
6934 | because "rX" might actually be a label. ie the register | |
6935 | name has been occluded by a symbol of the same name. So we | |
6936 | just generate a general 'bad addressing mode' type error | |
6937 | message and leave it up to the programmer to discover the | |
6938 | true cause and fix their mistake. */ | |
6939 | || (inst.operands[1].reg == REG_PC), | |
6940 | BAD_ADDR_MODE); | |
b05fe5cf | 6941 | |
c19d1205 ZW |
6942 | constraint (inst.reloc.exp.X_op != O_constant |
6943 | || inst.reloc.exp.X_add_number != 0, | |
6944 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 6945 | |
c19d1205 ZW |
6946 | inst.instruction |= inst.operands[0].reg << 12; |
6947 | inst.instruction |= inst.operands[1].reg << 16; | |
6948 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
6949 | } |
6950 | ||
6951 | static void | |
c19d1205 | 6952 | do_ldrexd (void) |
b05fe5cf | 6953 | { |
c19d1205 ZW |
6954 | constraint (inst.operands[0].reg % 2 != 0, |
6955 | _("even register required")); | |
6956 | constraint (inst.operands[1].present | |
6957 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
6958 | _("can only load two consecutive registers")); | |
6959 | /* If op 1 were present and equal to PC, this function wouldn't | |
6960 | have been called in the first place. */ | |
6961 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 6962 | |
c19d1205 ZW |
6963 | inst.instruction |= inst.operands[0].reg << 12; |
6964 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
6965 | } |
6966 | ||
6967 | static void | |
c19d1205 | 6968 | do_ldst (void) |
b05fe5cf | 6969 | { |
c19d1205 ZW |
6970 | inst.instruction |= inst.operands[0].reg << 12; |
6971 | if (!inst.operands[1].isreg) | |
6972 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 6973 | return; |
c19d1205 | 6974 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
6975 | } |
6976 | ||
6977 | static void | |
c19d1205 | 6978 | do_ldstt (void) |
b05fe5cf | 6979 | { |
c19d1205 ZW |
6980 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
6981 | reject [Rn,...]. */ | |
6982 | if (inst.operands[1].preind) | |
b05fe5cf | 6983 | { |
c19d1205 ZW |
6984 | constraint (inst.reloc.exp.X_op != O_constant || |
6985 | inst.reloc.exp.X_add_number != 0, | |
6986 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 6987 | |
c19d1205 ZW |
6988 | inst.operands[1].preind = 0; |
6989 | inst.operands[1].postind = 1; | |
6990 | inst.operands[1].writeback = 1; | |
b05fe5cf | 6991 | } |
c19d1205 ZW |
6992 | inst.instruction |= inst.operands[0].reg << 12; |
6993 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
6994 | } | |
b05fe5cf | 6995 | |
c19d1205 | 6996 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 6997 | |
c19d1205 ZW |
6998 | static void |
6999 | do_ldstv4 (void) | |
7000 | { | |
7001 | inst.instruction |= inst.operands[0].reg << 12; | |
7002 | if (!inst.operands[1].isreg) | |
7003 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 7004 | return; |
c19d1205 | 7005 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7006 | } |
7007 | ||
7008 | static void | |
c19d1205 | 7009 | do_ldsttv4 (void) |
b05fe5cf | 7010 | { |
c19d1205 ZW |
7011 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7012 | reject [Rn,...]. */ | |
7013 | if (inst.operands[1].preind) | |
b05fe5cf | 7014 | { |
c19d1205 ZW |
7015 | constraint (inst.reloc.exp.X_op != O_constant || |
7016 | inst.reloc.exp.X_add_number != 0, | |
7017 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 7018 | |
c19d1205 ZW |
7019 | inst.operands[1].preind = 0; |
7020 | inst.operands[1].postind = 1; | |
7021 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7022 | } |
c19d1205 ZW |
7023 | inst.instruction |= inst.operands[0].reg << 12; |
7024 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
7025 | } | |
b05fe5cf | 7026 | |
c19d1205 ZW |
7027 | /* Co-processor register load/store. |
7028 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
7029 | static void | |
7030 | do_lstc (void) | |
7031 | { | |
7032 | inst.instruction |= inst.operands[0].reg << 8; | |
7033 | inst.instruction |= inst.operands[1].reg << 12; | |
7034 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
7035 | } |
7036 | ||
b05fe5cf | 7037 | static void |
c19d1205 | 7038 | do_mlas (void) |
b05fe5cf | 7039 | { |
c19d1205 ZW |
7040 | /* This restriction does not apply to mls (nor to mla in v6, but |
7041 | that's hard to detect at present). */ | |
7042 | if (inst.operands[0].reg == inst.operands[1].reg | |
7043 | && !(inst.instruction & 0x00400000)) | |
7044 | as_tsktsk (_("rd and rm should be different in mla")); | |
b05fe5cf | 7045 | |
c19d1205 ZW |
7046 | inst.instruction |= inst.operands[0].reg << 16; |
7047 | inst.instruction |= inst.operands[1].reg; | |
7048 | inst.instruction |= inst.operands[2].reg << 8; | |
7049 | inst.instruction |= inst.operands[3].reg << 12; | |
b05fe5cf | 7050 | |
c19d1205 | 7051 | } |
b05fe5cf | 7052 | |
c19d1205 ZW |
7053 | static void |
7054 | do_mov (void) | |
7055 | { | |
7056 | inst.instruction |= inst.operands[0].reg << 12; | |
7057 | encode_arm_shifter_operand (1); | |
7058 | } | |
b05fe5cf | 7059 | |
c19d1205 ZW |
7060 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
7061 | static void | |
7062 | do_mov16 (void) | |
7063 | { | |
b6895b4f PB |
7064 | bfd_vma imm; |
7065 | bfd_boolean top; | |
7066 | ||
7067 | top = (inst.instruction & 0x00400000) != 0; | |
7068 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
7069 | _(":lower16: not allowed this instruction")); | |
7070 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
7071 | _(":upper16: not allowed instruction")); | |
c19d1205 | 7072 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
7073 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
7074 | { | |
7075 | imm = inst.reloc.exp.X_add_number; | |
7076 | /* The value is in two pieces: 0:11, 16:19. */ | |
7077 | inst.instruction |= (imm & 0x00000fff); | |
7078 | inst.instruction |= (imm & 0x0000f000) << 4; | |
7079 | } | |
b05fe5cf | 7080 | } |
b99bd4ef | 7081 | |
037e8744 JB |
7082 | static void do_vfp_nsyn_opcode (const char *); |
7083 | ||
7084 | static int | |
7085 | do_vfp_nsyn_mrs (void) | |
7086 | { | |
7087 | if (inst.operands[0].isvec) | |
7088 | { | |
7089 | if (inst.operands[1].reg != 1) | |
7090 | first_error (_("operand 1 must be FPSCR")); | |
7091 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
7092 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
7093 | do_vfp_nsyn_opcode ("fmstat"); | |
7094 | } | |
7095 | else if (inst.operands[1].isvec) | |
7096 | do_vfp_nsyn_opcode ("fmrx"); | |
7097 | else | |
7098 | return FAIL; | |
7099 | ||
7100 | return SUCCESS; | |
7101 | } | |
7102 | ||
7103 | static int | |
7104 | do_vfp_nsyn_msr (void) | |
7105 | { | |
7106 | if (inst.operands[0].isvec) | |
7107 | do_vfp_nsyn_opcode ("fmxr"); | |
7108 | else | |
7109 | return FAIL; | |
7110 | ||
7111 | return SUCCESS; | |
7112 | } | |
7113 | ||
b99bd4ef | 7114 | static void |
c19d1205 | 7115 | do_mrs (void) |
b99bd4ef | 7116 | { |
037e8744 JB |
7117 | if (do_vfp_nsyn_mrs () == SUCCESS) |
7118 | return; | |
7119 | ||
c19d1205 ZW |
7120 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
7121 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7122 | != (PSR_c|PSR_f), | |
7123 | _("'CPSR' or 'SPSR' expected")); | |
7124 | inst.instruction |= inst.operands[0].reg << 12; | |
7125 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
7126 | } | |
b99bd4ef | 7127 | |
c19d1205 ZW |
7128 | /* Two possible forms: |
7129 | "{C|S}PSR_<field>, Rm", | |
7130 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 7131 | |
c19d1205 ZW |
7132 | static void |
7133 | do_msr (void) | |
7134 | { | |
037e8744 JB |
7135 | if (do_vfp_nsyn_msr () == SUCCESS) |
7136 | return; | |
7137 | ||
c19d1205 ZW |
7138 | inst.instruction |= inst.operands[0].imm; |
7139 | if (inst.operands[1].isreg) | |
7140 | inst.instruction |= inst.operands[1].reg; | |
7141 | else | |
b99bd4ef | 7142 | { |
c19d1205 ZW |
7143 | inst.instruction |= INST_IMMEDIATE; |
7144 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
7145 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 7146 | } |
b99bd4ef NC |
7147 | } |
7148 | ||
c19d1205 ZW |
7149 | static void |
7150 | do_mul (void) | |
a737bd4d | 7151 | { |
c19d1205 ZW |
7152 | if (!inst.operands[2].present) |
7153 | inst.operands[2].reg = inst.operands[0].reg; | |
7154 | inst.instruction |= inst.operands[0].reg << 16; | |
7155 | inst.instruction |= inst.operands[1].reg; | |
7156 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 7157 | |
c19d1205 ZW |
7158 | if (inst.operands[0].reg == inst.operands[1].reg) |
7159 | as_tsktsk (_("rd and rm should be different in mul")); | |
a737bd4d NC |
7160 | } |
7161 | ||
c19d1205 ZW |
7162 | /* Long Multiply Parser |
7163 | UMULL RdLo, RdHi, Rm, Rs | |
7164 | SMULL RdLo, RdHi, Rm, Rs | |
7165 | UMLAL RdLo, RdHi, Rm, Rs | |
7166 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
7167 | |
7168 | static void | |
c19d1205 | 7169 | do_mull (void) |
b99bd4ef | 7170 | { |
c19d1205 ZW |
7171 | inst.instruction |= inst.operands[0].reg << 12; |
7172 | inst.instruction |= inst.operands[1].reg << 16; | |
7173 | inst.instruction |= inst.operands[2].reg; | |
7174 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 7175 | |
c19d1205 ZW |
7176 | /* rdhi, rdlo and rm must all be different. */ |
7177 | if (inst.operands[0].reg == inst.operands[1].reg | |
7178 | || inst.operands[0].reg == inst.operands[2].reg | |
7179 | || inst.operands[1].reg == inst.operands[2].reg) | |
7180 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); | |
7181 | } | |
b99bd4ef | 7182 | |
c19d1205 ZW |
7183 | static void |
7184 | do_nop (void) | |
7185 | { | |
7186 | if (inst.operands[0].present) | |
7187 | { | |
7188 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
7189 | inst.instruction &= 0xf0000000; | |
7190 | inst.instruction |= 0x0320f000 + inst.operands[0].imm; | |
7191 | } | |
b99bd4ef NC |
7192 | } |
7193 | ||
c19d1205 ZW |
7194 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
7195 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
7196 | Condition defaults to COND_ALWAYS. | |
7197 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
7198 | |
7199 | static void | |
c19d1205 | 7200 | do_pkhbt (void) |
b99bd4ef | 7201 | { |
c19d1205 ZW |
7202 | inst.instruction |= inst.operands[0].reg << 12; |
7203 | inst.instruction |= inst.operands[1].reg << 16; | |
7204 | inst.instruction |= inst.operands[2].reg; | |
7205 | if (inst.operands[3].present) | |
7206 | encode_arm_shift (3); | |
7207 | } | |
b99bd4ef | 7208 | |
c19d1205 | 7209 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 7210 | |
c19d1205 ZW |
7211 | static void |
7212 | do_pkhtb (void) | |
7213 | { | |
7214 | if (!inst.operands[3].present) | |
b99bd4ef | 7215 | { |
c19d1205 ZW |
7216 | /* If the shift specifier is omitted, turn the instruction |
7217 | into pkhbt rd, rm, rn. */ | |
7218 | inst.instruction &= 0xfff00010; | |
7219 | inst.instruction |= inst.operands[0].reg << 12; | |
7220 | inst.instruction |= inst.operands[1].reg; | |
7221 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7222 | } |
7223 | else | |
7224 | { | |
c19d1205 ZW |
7225 | inst.instruction |= inst.operands[0].reg << 12; |
7226 | inst.instruction |= inst.operands[1].reg << 16; | |
7227 | inst.instruction |= inst.operands[2].reg; | |
7228 | encode_arm_shift (3); | |
b99bd4ef NC |
7229 | } |
7230 | } | |
7231 | ||
c19d1205 ZW |
7232 | /* ARMv5TE: Preload-Cache |
7233 | ||
7234 | PLD <addr_mode> | |
7235 | ||
7236 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
7237 | |
7238 | static void | |
c19d1205 | 7239 | do_pld (void) |
b99bd4ef | 7240 | { |
c19d1205 ZW |
7241 | constraint (!inst.operands[0].isreg, |
7242 | _("'[' expected after PLD mnemonic")); | |
7243 | constraint (inst.operands[0].postind, | |
7244 | _("post-indexed expression used in preload instruction")); | |
7245 | constraint (inst.operands[0].writeback, | |
7246 | _("writeback used in preload instruction")); | |
7247 | constraint (!inst.operands[0].preind, | |
7248 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
7249 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
7250 | } | |
b99bd4ef | 7251 | |
62b3e311 PB |
7252 | /* ARMv7: PLI <addr_mode> */ |
7253 | static void | |
7254 | do_pli (void) | |
7255 | { | |
7256 | constraint (!inst.operands[0].isreg, | |
7257 | _("'[' expected after PLI mnemonic")); | |
7258 | constraint (inst.operands[0].postind, | |
7259 | _("post-indexed expression used in preload instruction")); | |
7260 | constraint (inst.operands[0].writeback, | |
7261 | _("writeback used in preload instruction")); | |
7262 | constraint (!inst.operands[0].preind, | |
7263 | _("unindexed addressing used in preload instruction")); | |
7264 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
7265 | inst.instruction &= ~PRE_INDEX; | |
7266 | } | |
7267 | ||
c19d1205 ZW |
7268 | static void |
7269 | do_push_pop (void) | |
7270 | { | |
7271 | inst.operands[1] = inst.operands[0]; | |
7272 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
7273 | inst.operands[0].isreg = 1; | |
7274 | inst.operands[0].writeback = 1; | |
7275 | inst.operands[0].reg = REG_SP; | |
7276 | do_ldmstm (); | |
7277 | } | |
b99bd4ef | 7278 | |
c19d1205 ZW |
7279 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
7280 | word at the specified address and the following word | |
7281 | respectively. | |
7282 | Unconditionally executed. | |
7283 | Error if Rn is R15. */ | |
b99bd4ef | 7284 | |
c19d1205 ZW |
7285 | static void |
7286 | do_rfe (void) | |
7287 | { | |
7288 | inst.instruction |= inst.operands[0].reg << 16; | |
7289 | if (inst.operands[0].writeback) | |
7290 | inst.instruction |= WRITE_BACK; | |
7291 | } | |
b99bd4ef | 7292 | |
c19d1205 | 7293 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 7294 | |
c19d1205 ZW |
7295 | static void |
7296 | do_ssat (void) | |
7297 | { | |
7298 | inst.instruction |= inst.operands[0].reg << 12; | |
7299 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
7300 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7301 | |
c19d1205 ZW |
7302 | if (inst.operands[3].present) |
7303 | encode_arm_shift (3); | |
b99bd4ef NC |
7304 | } |
7305 | ||
c19d1205 | 7306 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
7307 | |
7308 | static void | |
c19d1205 | 7309 | do_usat (void) |
b99bd4ef | 7310 | { |
c19d1205 ZW |
7311 | inst.instruction |= inst.operands[0].reg << 12; |
7312 | inst.instruction |= inst.operands[1].imm << 16; | |
7313 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7314 | |
c19d1205 ZW |
7315 | if (inst.operands[3].present) |
7316 | encode_arm_shift (3); | |
b99bd4ef NC |
7317 | } |
7318 | ||
c19d1205 | 7319 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
7320 | |
7321 | static void | |
c19d1205 | 7322 | do_ssat16 (void) |
09d92015 | 7323 | { |
c19d1205 ZW |
7324 | inst.instruction |= inst.operands[0].reg << 12; |
7325 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
7326 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
7327 | } |
7328 | ||
c19d1205 ZW |
7329 | static void |
7330 | do_usat16 (void) | |
a737bd4d | 7331 | { |
c19d1205 ZW |
7332 | inst.instruction |= inst.operands[0].reg << 12; |
7333 | inst.instruction |= inst.operands[1].imm << 16; | |
7334 | inst.instruction |= inst.operands[2].reg; | |
7335 | } | |
a737bd4d | 7336 | |
c19d1205 ZW |
7337 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
7338 | preserving the other bits. | |
a737bd4d | 7339 | |
c19d1205 ZW |
7340 | setend <endian_specifier>, where <endian_specifier> is either |
7341 | BE or LE. */ | |
a737bd4d | 7342 | |
c19d1205 ZW |
7343 | static void |
7344 | do_setend (void) | |
7345 | { | |
7346 | if (inst.operands[0].imm) | |
7347 | inst.instruction |= 0x200; | |
a737bd4d NC |
7348 | } |
7349 | ||
7350 | static void | |
c19d1205 | 7351 | do_shift (void) |
a737bd4d | 7352 | { |
c19d1205 ZW |
7353 | unsigned int Rm = (inst.operands[1].present |
7354 | ? inst.operands[1].reg | |
7355 | : inst.operands[0].reg); | |
a737bd4d | 7356 | |
c19d1205 ZW |
7357 | inst.instruction |= inst.operands[0].reg << 12; |
7358 | inst.instruction |= Rm; | |
7359 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 7360 | { |
c19d1205 ZW |
7361 | inst.instruction |= inst.operands[2].reg << 8; |
7362 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
7363 | } |
7364 | else | |
c19d1205 | 7365 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
7366 | } |
7367 | ||
09d92015 | 7368 | static void |
3eb17e6b | 7369 | do_smc (void) |
09d92015 | 7370 | { |
3eb17e6b | 7371 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 7372 | inst.reloc.pc_rel = 0; |
09d92015 MM |
7373 | } |
7374 | ||
09d92015 | 7375 | static void |
c19d1205 | 7376 | do_swi (void) |
09d92015 | 7377 | { |
c19d1205 ZW |
7378 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
7379 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
7380 | } |
7381 | ||
c19d1205 ZW |
7382 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
7383 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
7384 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
7385 | Error if any register is R15. */ | |
e16bb312 | 7386 | |
c19d1205 ZW |
7387 | static void |
7388 | do_smla (void) | |
e16bb312 | 7389 | { |
c19d1205 ZW |
7390 | inst.instruction |= inst.operands[0].reg << 16; |
7391 | inst.instruction |= inst.operands[1].reg; | |
7392 | inst.instruction |= inst.operands[2].reg << 8; | |
7393 | inst.instruction |= inst.operands[3].reg << 12; | |
7394 | } | |
a737bd4d | 7395 | |
c19d1205 ZW |
7396 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
7397 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
7398 | Error if any register is R15. | |
7399 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 7400 | |
c19d1205 ZW |
7401 | static void |
7402 | do_smlal (void) | |
7403 | { | |
7404 | inst.instruction |= inst.operands[0].reg << 12; | |
7405 | inst.instruction |= inst.operands[1].reg << 16; | |
7406 | inst.instruction |= inst.operands[2].reg; | |
7407 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 7408 | |
c19d1205 ZW |
7409 | if (inst.operands[0].reg == inst.operands[1].reg) |
7410 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7411 | } | |
a737bd4d | 7412 | |
c19d1205 ZW |
7413 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
7414 | SMULxy{cond} Rd,Rm,Rs | |
7415 | Error if any register is R15. */ | |
a737bd4d | 7416 | |
c19d1205 ZW |
7417 | static void |
7418 | do_smul (void) | |
7419 | { | |
7420 | inst.instruction |= inst.operands[0].reg << 16; | |
7421 | inst.instruction |= inst.operands[1].reg; | |
7422 | inst.instruction |= inst.operands[2].reg << 8; | |
7423 | } | |
a737bd4d | 7424 | |
c19d1205 | 7425 | /* ARM V6 srs (argument parse). */ |
a737bd4d | 7426 | |
c19d1205 ZW |
7427 | static void |
7428 | do_srs (void) | |
7429 | { | |
7430 | inst.instruction |= inst.operands[0].imm; | |
7431 | if (inst.operands[0].writeback) | |
7432 | inst.instruction |= WRITE_BACK; | |
7433 | } | |
a737bd4d | 7434 | |
c19d1205 | 7435 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 7436 | |
c19d1205 ZW |
7437 | static void |
7438 | do_strex (void) | |
7439 | { | |
7440 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7441 | || inst.operands[2].postind || inst.operands[2].writeback | |
7442 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
7443 | || inst.operands[2].negative |
7444 | /* See comment in do_ldrex(). */ | |
7445 | || (inst.operands[2].reg == REG_PC), | |
7446 | BAD_ADDR_MODE); | |
a737bd4d | 7447 | |
c19d1205 ZW |
7448 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7449 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 7450 | |
c19d1205 ZW |
7451 | constraint (inst.reloc.exp.X_op != O_constant |
7452 | || inst.reloc.exp.X_add_number != 0, | |
7453 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 7454 | |
c19d1205 ZW |
7455 | inst.instruction |= inst.operands[0].reg << 12; |
7456 | inst.instruction |= inst.operands[1].reg; | |
7457 | inst.instruction |= inst.operands[2].reg << 16; | |
7458 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
7459 | } |
7460 | ||
7461 | static void | |
c19d1205 | 7462 | do_strexd (void) |
e16bb312 | 7463 | { |
c19d1205 ZW |
7464 | constraint (inst.operands[1].reg % 2 != 0, |
7465 | _("even register required")); | |
7466 | constraint (inst.operands[2].present | |
7467 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
7468 | _("can only store two consecutive registers")); | |
7469 | /* If op 2 were present and equal to PC, this function wouldn't | |
7470 | have been called in the first place. */ | |
7471 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 7472 | |
c19d1205 ZW |
7473 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7474 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
7475 | || inst.operands[0].reg == inst.operands[3].reg, | |
7476 | BAD_OVERLAP); | |
e16bb312 | 7477 | |
c19d1205 ZW |
7478 | inst.instruction |= inst.operands[0].reg << 12; |
7479 | inst.instruction |= inst.operands[1].reg; | |
7480 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
7481 | } |
7482 | ||
c19d1205 ZW |
7483 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
7484 | extends it to 32-bits, and adds the result to a value in another | |
7485 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
7486 | before extracting the 16-bit value. | |
7487 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
7488 | Condition defaults to COND_ALWAYS. | |
7489 | Error if any register uses R15. */ | |
7490 | ||
e16bb312 | 7491 | static void |
c19d1205 | 7492 | do_sxtah (void) |
e16bb312 | 7493 | { |
c19d1205 ZW |
7494 | inst.instruction |= inst.operands[0].reg << 12; |
7495 | inst.instruction |= inst.operands[1].reg << 16; | |
7496 | inst.instruction |= inst.operands[2].reg; | |
7497 | inst.instruction |= inst.operands[3].imm << 10; | |
7498 | } | |
e16bb312 | 7499 | |
c19d1205 | 7500 | /* ARM V6 SXTH. |
e16bb312 | 7501 | |
c19d1205 ZW |
7502 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
7503 | Condition defaults to COND_ALWAYS. | |
7504 | Error if any register uses R15. */ | |
e16bb312 NC |
7505 | |
7506 | static void | |
c19d1205 | 7507 | do_sxth (void) |
e16bb312 | 7508 | { |
c19d1205 ZW |
7509 | inst.instruction |= inst.operands[0].reg << 12; |
7510 | inst.instruction |= inst.operands[1].reg; | |
7511 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 7512 | } |
c19d1205 ZW |
7513 | \f |
7514 | /* VFP instructions. In a logical order: SP variant first, monad | |
7515 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
7516 | |
7517 | static void | |
c19d1205 | 7518 | do_vfp_sp_monadic (void) |
e16bb312 | 7519 | { |
5287ad62 JB |
7520 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7521 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
7522 | } |
7523 | ||
7524 | static void | |
c19d1205 | 7525 | do_vfp_sp_dyadic (void) |
e16bb312 | 7526 | { |
5287ad62 JB |
7527 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7528 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
7529 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
7530 | } |
7531 | ||
7532 | static void | |
c19d1205 | 7533 | do_vfp_sp_compare_z (void) |
e16bb312 | 7534 | { |
5287ad62 | 7535 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
7536 | } |
7537 | ||
7538 | static void | |
c19d1205 | 7539 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 7540 | { |
5287ad62 JB |
7541 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
7542 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
7543 | } |
7544 | ||
7545 | static void | |
c19d1205 | 7546 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 7547 | { |
5287ad62 JB |
7548 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7549 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
7550 | } |
7551 | ||
7552 | static void | |
c19d1205 | 7553 | do_vfp_reg_from_sp (void) |
e16bb312 | 7554 | { |
c19d1205 | 7555 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 7556 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
7557 | } |
7558 | ||
7559 | static void | |
c19d1205 | 7560 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 7561 | { |
c19d1205 ZW |
7562 | constraint (inst.operands[2].imm != 2, |
7563 | _("only two consecutive VFP SP registers allowed here")); | |
7564 | inst.instruction |= inst.operands[0].reg << 12; | |
7565 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 7566 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
7567 | } |
7568 | ||
7569 | static void | |
c19d1205 | 7570 | do_vfp_sp_from_reg (void) |
e16bb312 | 7571 | { |
5287ad62 | 7572 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 7573 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
7574 | } |
7575 | ||
7576 | static void | |
c19d1205 | 7577 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 7578 | { |
c19d1205 ZW |
7579 | constraint (inst.operands[0].imm != 2, |
7580 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 7581 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
7582 | inst.instruction |= inst.operands[1].reg << 12; |
7583 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
7584 | } |
7585 | ||
7586 | static void | |
c19d1205 | 7587 | do_vfp_sp_ldst (void) |
e16bb312 | 7588 | { |
5287ad62 | 7589 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 7590 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
7591 | } |
7592 | ||
7593 | static void | |
c19d1205 | 7594 | do_vfp_dp_ldst (void) |
e16bb312 | 7595 | { |
5287ad62 | 7596 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 7597 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
7598 | } |
7599 | ||
c19d1205 | 7600 | |
e16bb312 | 7601 | static void |
c19d1205 | 7602 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 7603 | { |
c19d1205 ZW |
7604 | if (inst.operands[0].writeback) |
7605 | inst.instruction |= WRITE_BACK; | |
7606 | else | |
7607 | constraint (ldstm_type != VFP_LDSTMIA, | |
7608 | _("this addressing mode requires base-register writeback")); | |
7609 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 7610 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 7611 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
7612 | } |
7613 | ||
7614 | static void | |
c19d1205 | 7615 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 7616 | { |
c19d1205 | 7617 | int count; |
e16bb312 | 7618 | |
c19d1205 ZW |
7619 | if (inst.operands[0].writeback) |
7620 | inst.instruction |= WRITE_BACK; | |
7621 | else | |
7622 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
7623 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 7624 | |
c19d1205 | 7625 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 7626 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 7627 | |
c19d1205 ZW |
7628 | count = inst.operands[1].imm << 1; |
7629 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
7630 | count += 1; | |
e16bb312 | 7631 | |
c19d1205 | 7632 | inst.instruction |= count; |
e16bb312 NC |
7633 | } |
7634 | ||
7635 | static void | |
c19d1205 | 7636 | do_vfp_sp_ldstmia (void) |
e16bb312 | 7637 | { |
c19d1205 | 7638 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
7639 | } |
7640 | ||
7641 | static void | |
c19d1205 | 7642 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 7643 | { |
c19d1205 | 7644 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
7645 | } |
7646 | ||
7647 | static void | |
c19d1205 | 7648 | do_vfp_dp_ldstmia (void) |
e16bb312 | 7649 | { |
c19d1205 | 7650 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
7651 | } |
7652 | ||
7653 | static void | |
c19d1205 | 7654 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 7655 | { |
c19d1205 | 7656 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
7657 | } |
7658 | ||
7659 | static void | |
c19d1205 | 7660 | do_vfp_xp_ldstmia (void) |
e16bb312 | 7661 | { |
c19d1205 ZW |
7662 | vfp_dp_ldstm (VFP_LDSTMIAX); |
7663 | } | |
e16bb312 | 7664 | |
c19d1205 ZW |
7665 | static void |
7666 | do_vfp_xp_ldstmdb (void) | |
7667 | { | |
7668 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 7669 | } |
5287ad62 JB |
7670 | |
7671 | static void | |
7672 | do_vfp_dp_rd_rm (void) | |
7673 | { | |
7674 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7675 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
7676 | } | |
7677 | ||
7678 | static void | |
7679 | do_vfp_dp_rn_rd (void) | |
7680 | { | |
7681 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
7682 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
7683 | } | |
7684 | ||
7685 | static void | |
7686 | do_vfp_dp_rd_rn (void) | |
7687 | { | |
7688 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7689 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
7690 | } | |
7691 | ||
7692 | static void | |
7693 | do_vfp_dp_rd_rn_rm (void) | |
7694 | { | |
7695 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7696 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
7697 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
7698 | } | |
7699 | ||
7700 | static void | |
7701 | do_vfp_dp_rd (void) | |
7702 | { | |
7703 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7704 | } | |
7705 | ||
7706 | static void | |
7707 | do_vfp_dp_rm_rd_rn (void) | |
7708 | { | |
7709 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
7710 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
7711 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
7712 | } | |
7713 | ||
7714 | /* VFPv3 instructions. */ | |
7715 | static void | |
7716 | do_vfp_sp_const (void) | |
7717 | { | |
7718 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
7719 | inst.instruction |= (inst.operands[1].imm & 15) << 16; | |
7720 | inst.instruction |= (inst.operands[1].imm >> 4); | |
7721 | } | |
7722 | ||
7723 | static void | |
7724 | do_vfp_dp_const (void) | |
7725 | { | |
7726 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7727 | inst.instruction |= (inst.operands[1].imm & 15) << 16; | |
7728 | inst.instruction |= (inst.operands[1].imm >> 4); | |
7729 | } | |
7730 | ||
7731 | static void | |
7732 | vfp_conv (int srcsize) | |
7733 | { | |
7734 | unsigned immbits = srcsize - inst.operands[1].imm; | |
7735 | inst.instruction |= (immbits & 1) << 5; | |
7736 | inst.instruction |= (immbits >> 1); | |
7737 | } | |
7738 | ||
7739 | static void | |
7740 | do_vfp_sp_conv_16 (void) | |
7741 | { | |
7742 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
7743 | vfp_conv (16); | |
7744 | } | |
7745 | ||
7746 | static void | |
7747 | do_vfp_dp_conv_16 (void) | |
7748 | { | |
7749 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7750 | vfp_conv (16); | |
7751 | } | |
7752 | ||
7753 | static void | |
7754 | do_vfp_sp_conv_32 (void) | |
7755 | { | |
7756 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
7757 | vfp_conv (32); | |
7758 | } | |
7759 | ||
7760 | static void | |
7761 | do_vfp_dp_conv_32 (void) | |
7762 | { | |
7763 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
7764 | vfp_conv (32); | |
7765 | } | |
7766 | ||
c19d1205 ZW |
7767 | \f |
7768 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 7769 | |
c19d1205 ZW |
7770 | static void |
7771 | do_fpa_cmp (void) | |
7772 | { | |
7773 | inst.instruction |= inst.operands[0].reg << 16; | |
7774 | inst.instruction |= inst.operands[1].reg; | |
7775 | } | |
b99bd4ef NC |
7776 | |
7777 | static void | |
c19d1205 | 7778 | do_fpa_ldmstm (void) |
b99bd4ef | 7779 | { |
c19d1205 ZW |
7780 | inst.instruction |= inst.operands[0].reg << 12; |
7781 | switch (inst.operands[1].imm) | |
7782 | { | |
7783 | case 1: inst.instruction |= CP_T_X; break; | |
7784 | case 2: inst.instruction |= CP_T_Y; break; | |
7785 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
7786 | case 4: break; | |
7787 | default: abort (); | |
7788 | } | |
b99bd4ef | 7789 | |
c19d1205 ZW |
7790 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
7791 | { | |
7792 | /* The instruction specified "ea" or "fd", so we can only accept | |
7793 | [Rn]{!}. The instruction does not really support stacking or | |
7794 | unstacking, so we have to emulate these by setting appropriate | |
7795 | bits and offsets. */ | |
7796 | constraint (inst.reloc.exp.X_op != O_constant | |
7797 | || inst.reloc.exp.X_add_number != 0, | |
7798 | _("this instruction does not support indexing")); | |
b99bd4ef | 7799 | |
c19d1205 ZW |
7800 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
7801 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 7802 | |
c19d1205 ZW |
7803 | if (!(inst.instruction & INDEX_UP)) |
7804 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 7805 | |
c19d1205 ZW |
7806 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
7807 | { | |
7808 | inst.operands[2].preind = 0; | |
7809 | inst.operands[2].postind = 1; | |
7810 | } | |
7811 | } | |
b99bd4ef | 7812 | |
c19d1205 | 7813 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 7814 | } |
037e8744 | 7815 | |
c19d1205 ZW |
7816 | \f |
7817 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 7818 | |
c19d1205 ZW |
7819 | static void |
7820 | do_iwmmxt_tandorc (void) | |
7821 | { | |
7822 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
7823 | } | |
b99bd4ef | 7824 | |
c19d1205 ZW |
7825 | static void |
7826 | do_iwmmxt_textrc (void) | |
7827 | { | |
7828 | inst.instruction |= inst.operands[0].reg << 12; | |
7829 | inst.instruction |= inst.operands[1].imm; | |
7830 | } | |
b99bd4ef NC |
7831 | |
7832 | static void | |
c19d1205 | 7833 | do_iwmmxt_textrm (void) |
b99bd4ef | 7834 | { |
c19d1205 ZW |
7835 | inst.instruction |= inst.operands[0].reg << 12; |
7836 | inst.instruction |= inst.operands[1].reg << 16; | |
7837 | inst.instruction |= inst.operands[2].imm; | |
7838 | } | |
b99bd4ef | 7839 | |
c19d1205 ZW |
7840 | static void |
7841 | do_iwmmxt_tinsr (void) | |
7842 | { | |
7843 | inst.instruction |= inst.operands[0].reg << 16; | |
7844 | inst.instruction |= inst.operands[1].reg << 12; | |
7845 | inst.instruction |= inst.operands[2].imm; | |
7846 | } | |
b99bd4ef | 7847 | |
c19d1205 ZW |
7848 | static void |
7849 | do_iwmmxt_tmia (void) | |
7850 | { | |
7851 | inst.instruction |= inst.operands[0].reg << 5; | |
7852 | inst.instruction |= inst.operands[1].reg; | |
7853 | inst.instruction |= inst.operands[2].reg << 12; | |
7854 | } | |
b99bd4ef | 7855 | |
c19d1205 ZW |
7856 | static void |
7857 | do_iwmmxt_waligni (void) | |
7858 | { | |
7859 | inst.instruction |= inst.operands[0].reg << 12; | |
7860 | inst.instruction |= inst.operands[1].reg << 16; | |
7861 | inst.instruction |= inst.operands[2].reg; | |
7862 | inst.instruction |= inst.operands[3].imm << 20; | |
7863 | } | |
b99bd4ef | 7864 | |
2d447fca JM |
7865 | static void |
7866 | do_iwmmxt_wmerge (void) | |
7867 | { | |
7868 | inst.instruction |= inst.operands[0].reg << 12; | |
7869 | inst.instruction |= inst.operands[1].reg << 16; | |
7870 | inst.instruction |= inst.operands[2].reg; | |
7871 | inst.instruction |= inst.operands[3].imm << 21; | |
7872 | } | |
7873 | ||
c19d1205 ZW |
7874 | static void |
7875 | do_iwmmxt_wmov (void) | |
7876 | { | |
7877 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
7878 | inst.instruction |= inst.operands[0].reg << 12; | |
7879 | inst.instruction |= inst.operands[1].reg << 16; | |
7880 | inst.instruction |= inst.operands[1].reg; | |
7881 | } | |
b99bd4ef | 7882 | |
c19d1205 ZW |
7883 | static void |
7884 | do_iwmmxt_wldstbh (void) | |
7885 | { | |
8f06b2d8 | 7886 | int reloc; |
c19d1205 | 7887 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
7888 | if (thumb_mode) |
7889 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
7890 | else | |
7891 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
7892 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
7893 | } |
7894 | ||
c19d1205 ZW |
7895 | static void |
7896 | do_iwmmxt_wldstw (void) | |
7897 | { | |
7898 | /* RIWR_RIWC clears .isreg for a control register. */ | |
7899 | if (!inst.operands[0].isreg) | |
7900 | { | |
7901 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
7902 | inst.instruction |= 0xf0000000; | |
7903 | } | |
b99bd4ef | 7904 | |
c19d1205 ZW |
7905 | inst.instruction |= inst.operands[0].reg << 12; |
7906 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
7907 | } | |
b99bd4ef NC |
7908 | |
7909 | static void | |
c19d1205 | 7910 | do_iwmmxt_wldstd (void) |
b99bd4ef | 7911 | { |
c19d1205 | 7912 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
7913 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
7914 | && inst.operands[1].immisreg) | |
7915 | { | |
7916 | inst.instruction &= ~0x1a000ff; | |
7917 | inst.instruction |= (0xf << 28); | |
7918 | if (inst.operands[1].preind) | |
7919 | inst.instruction |= PRE_INDEX; | |
7920 | if (!inst.operands[1].negative) | |
7921 | inst.instruction |= INDEX_UP; | |
7922 | if (inst.operands[1].writeback) | |
7923 | inst.instruction |= WRITE_BACK; | |
7924 | inst.instruction |= inst.operands[1].reg << 16; | |
7925 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
7926 | inst.instruction |= inst.operands[1].imm; | |
7927 | } | |
7928 | else | |
7929 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 7930 | } |
b99bd4ef | 7931 | |
c19d1205 ZW |
7932 | static void |
7933 | do_iwmmxt_wshufh (void) | |
7934 | { | |
7935 | inst.instruction |= inst.operands[0].reg << 12; | |
7936 | inst.instruction |= inst.operands[1].reg << 16; | |
7937 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
7938 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
7939 | } | |
b99bd4ef | 7940 | |
c19d1205 ZW |
7941 | static void |
7942 | do_iwmmxt_wzero (void) | |
7943 | { | |
7944 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
7945 | inst.instruction |= inst.operands[0].reg; | |
7946 | inst.instruction |= inst.operands[0].reg << 12; | |
7947 | inst.instruction |= inst.operands[0].reg << 16; | |
7948 | } | |
2d447fca JM |
7949 | |
7950 | static void | |
7951 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
7952 | { | |
7953 | if (inst.operands[2].isreg) | |
7954 | do_rd_rn_rm (); | |
7955 | else { | |
7956 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
7957 | _("immediate operand requires iWMMXt2")); | |
7958 | do_rd_rn (); | |
7959 | if (inst.operands[2].imm == 0) | |
7960 | { | |
7961 | switch ((inst.instruction >> 20) & 0xf) | |
7962 | { | |
7963 | case 4: | |
7964 | case 5: | |
7965 | case 6: | |
7966 | case 7: | |
7967 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ | |
7968 | inst.operands[2].imm = 16; | |
7969 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
7970 | break; | |
7971 | case 8: | |
7972 | case 9: | |
7973 | case 10: | |
7974 | case 11: | |
7975 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
7976 | inst.operands[2].imm = 32; | |
7977 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
7978 | break; | |
7979 | case 12: | |
7980 | case 13: | |
7981 | case 14: | |
7982 | case 15: | |
7983 | { | |
7984 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
7985 | unsigned long wrn; | |
7986 | wrn = (inst.instruction >> 16) & 0xf; | |
7987 | inst.instruction &= 0xff0fff0f; | |
7988 | inst.instruction |= wrn; | |
7989 | /* Bail out here; the instruction is now assembled. */ | |
7990 | return; | |
7991 | } | |
7992 | } | |
7993 | } | |
7994 | /* Map 32 -> 0, etc. */ | |
7995 | inst.operands[2].imm &= 0x1f; | |
7996 | inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); | |
7997 | } | |
7998 | } | |
c19d1205 ZW |
7999 | \f |
8000 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
8001 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 8002 | |
c19d1205 | 8003 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 8004 | |
c19d1205 ZW |
8005 | static void |
8006 | do_mav_triple (void) | |
8007 | { | |
8008 | inst.instruction |= inst.operands[0].reg << 16; | |
8009 | inst.instruction |= inst.operands[1].reg; | |
8010 | inst.instruction |= inst.operands[2].reg << 12; | |
8011 | } | |
b99bd4ef | 8012 | |
c19d1205 ZW |
8013 | /* Insns like "foo W,X,Y,Z". |
8014 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 8015 | |
c19d1205 ZW |
8016 | static void |
8017 | do_mav_quad (void) | |
8018 | { | |
8019 | inst.instruction |= inst.operands[0].reg << 5; | |
8020 | inst.instruction |= inst.operands[1].reg << 12; | |
8021 | inst.instruction |= inst.operands[2].reg << 16; | |
8022 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
8023 | } |
8024 | ||
c19d1205 ZW |
8025 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
8026 | static void | |
8027 | do_mav_dspsc (void) | |
a737bd4d | 8028 | { |
c19d1205 ZW |
8029 | inst.instruction |= inst.operands[1].reg << 12; |
8030 | } | |
a737bd4d | 8031 | |
c19d1205 ZW |
8032 | /* Maverick shift immediate instructions. |
8033 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
8034 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 8035 | |
c19d1205 ZW |
8036 | static void |
8037 | do_mav_shift (void) | |
8038 | { | |
8039 | int imm = inst.operands[2].imm; | |
a737bd4d | 8040 | |
c19d1205 ZW |
8041 | inst.instruction |= inst.operands[0].reg << 12; |
8042 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 8043 | |
c19d1205 ZW |
8044 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
8045 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
8046 | Bit 4 should be 0. */ | |
8047 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 8048 | |
c19d1205 ZW |
8049 | inst.instruction |= imm; |
8050 | } | |
8051 | \f | |
8052 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 8053 | |
c19d1205 ZW |
8054 | /* Xscale multiply-accumulate (argument parse) |
8055 | MIAcc acc0,Rm,Rs | |
8056 | MIAPHcc acc0,Rm,Rs | |
8057 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 8058 | |
c19d1205 ZW |
8059 | static void |
8060 | do_xsc_mia (void) | |
8061 | { | |
8062 | inst.instruction |= inst.operands[1].reg; | |
8063 | inst.instruction |= inst.operands[2].reg << 12; | |
8064 | } | |
a737bd4d | 8065 | |
c19d1205 | 8066 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 8067 | |
c19d1205 | 8068 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 8069 | |
c19d1205 ZW |
8070 | static void |
8071 | do_xsc_mar (void) | |
8072 | { | |
8073 | inst.instruction |= inst.operands[1].reg << 12; | |
8074 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8075 | } |
8076 | ||
c19d1205 | 8077 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 8078 | |
c19d1205 | 8079 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
8080 | |
8081 | static void | |
c19d1205 | 8082 | do_xsc_mra (void) |
b99bd4ef | 8083 | { |
c19d1205 ZW |
8084 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
8085 | inst.instruction |= inst.operands[0].reg << 12; | |
8086 | inst.instruction |= inst.operands[1].reg << 16; | |
8087 | } | |
8088 | \f | |
8089 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 8090 | |
c19d1205 ZW |
8091 | /* inst.operands[i] is a shifted-register operand; encode |
8092 | it into inst.instruction in the format used by Thumb32. */ | |
8093 | ||
8094 | static void | |
8095 | encode_thumb32_shifted_operand (int i) | |
8096 | { | |
8097 | unsigned int value = inst.reloc.exp.X_add_number; | |
8098 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 8099 | |
9c3c69f2 PB |
8100 | constraint (inst.operands[i].immisreg, |
8101 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
8102 | inst.instruction |= inst.operands[i].reg; |
8103 | if (shift == SHIFT_RRX) | |
8104 | inst.instruction |= SHIFT_ROR << 4; | |
8105 | else | |
b99bd4ef | 8106 | { |
c19d1205 ZW |
8107 | constraint (inst.reloc.exp.X_op != O_constant, |
8108 | _("expression too complex")); | |
8109 | ||
8110 | constraint (value > 32 | |
8111 | || (value == 32 && (shift == SHIFT_LSL | |
8112 | || shift == SHIFT_ROR)), | |
8113 | _("shift expression is too large")); | |
8114 | ||
8115 | if (value == 0) | |
8116 | shift = SHIFT_LSL; | |
8117 | else if (value == 32) | |
8118 | value = 0; | |
8119 | ||
8120 | inst.instruction |= shift << 4; | |
8121 | inst.instruction |= (value & 0x1c) << 10; | |
8122 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 8123 | } |
c19d1205 | 8124 | } |
b99bd4ef | 8125 | |
b99bd4ef | 8126 | |
c19d1205 ZW |
8127 | /* inst.operands[i] was set up by parse_address. Encode it into a |
8128 | Thumb32 format load or store instruction. Reject forms that cannot | |
8129 | be used with such instructions. If is_t is true, reject forms that | |
8130 | cannot be used with a T instruction; if is_d is true, reject forms | |
8131 | that cannot be used with a D instruction. */ | |
b99bd4ef | 8132 | |
c19d1205 ZW |
8133 | static void |
8134 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
8135 | { | |
8136 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
8137 | ||
8138 | constraint (!inst.operands[i].isreg, | |
53365c0d | 8139 | _("Instruction does not support =N addresses")); |
b99bd4ef | 8140 | |
c19d1205 ZW |
8141 | inst.instruction |= inst.operands[i].reg << 16; |
8142 | if (inst.operands[i].immisreg) | |
b99bd4ef | 8143 | { |
c19d1205 ZW |
8144 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
8145 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
8146 | constraint (inst.operands[i].negative, | |
8147 | _("Thumb does not support negative register indexing")); | |
8148 | constraint (inst.operands[i].postind, | |
8149 | _("Thumb does not support register post-indexing")); | |
8150 | constraint (inst.operands[i].writeback, | |
8151 | _("Thumb does not support register indexing with writeback")); | |
8152 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
8153 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 8154 | |
f40d1643 | 8155 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 8156 | if (inst.operands[i].shifted) |
b99bd4ef | 8157 | { |
c19d1205 ZW |
8158 | constraint (inst.reloc.exp.X_op != O_constant, |
8159 | _("expression too complex")); | |
9c3c69f2 PB |
8160 | constraint (inst.reloc.exp.X_add_number < 0 |
8161 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 8162 | _("shift out of range")); |
9c3c69f2 | 8163 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
8164 | } |
8165 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8166 | } | |
8167 | else if (inst.operands[i].preind) | |
8168 | { | |
8169 | constraint (is_pc && inst.operands[i].writeback, | |
8170 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 8171 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
8172 | _("cannot use writeback with this instruction")); |
8173 | ||
8174 | if (is_d) | |
8175 | { | |
8176 | inst.instruction |= 0x01000000; | |
8177 | if (inst.operands[i].writeback) | |
8178 | inst.instruction |= 0x00200000; | |
b99bd4ef | 8179 | } |
c19d1205 | 8180 | else |
b99bd4ef | 8181 | { |
c19d1205 ZW |
8182 | inst.instruction |= 0x00000c00; |
8183 | if (inst.operands[i].writeback) | |
8184 | inst.instruction |= 0x00000100; | |
b99bd4ef | 8185 | } |
c19d1205 | 8186 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 8187 | } |
c19d1205 | 8188 | else if (inst.operands[i].postind) |
b99bd4ef | 8189 | { |
c19d1205 ZW |
8190 | assert (inst.operands[i].writeback); |
8191 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); | |
8192 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
8193 | ||
8194 | if (is_d) | |
8195 | inst.instruction |= 0x00200000; | |
8196 | else | |
8197 | inst.instruction |= 0x00000900; | |
8198 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
8199 | } | |
8200 | else /* unindexed - only for coprocessor */ | |
8201 | inst.error = _("instruction does not accept unindexed addressing"); | |
8202 | } | |
8203 | ||
8204 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
8205 | encodings (the latter only in post-V6T2 cores). The index is the | |
8206 | value used in the insns table below. When there is more than one | |
8207 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
8208 | holds variant (1). |
8209 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 ZW |
8210 | #define T16_32_TAB \ |
8211 | X(adc, 4140, eb400000), \ | |
8212 | X(adcs, 4140, eb500000), \ | |
8213 | X(add, 1c00, eb000000), \ | |
8214 | X(adds, 1c00, eb100000), \ | |
0110f2b8 PB |
8215 | X(addi, 0000, f1000000), \ |
8216 | X(addis, 0000, f1100000), \ | |
8217 | X(add_pc,000f, f20f0000), \ | |
8218 | X(add_sp,000d, f10d0000), \ | |
e9f89963 | 8219 | X(adr, 000f, f20f0000), \ |
c19d1205 ZW |
8220 | X(and, 4000, ea000000), \ |
8221 | X(ands, 4000, ea100000), \ | |
8222 | X(asr, 1000, fa40f000), \ | |
8223 | X(asrs, 1000, fa50f000), \ | |
0110f2b8 PB |
8224 | X(b, e000, f000b000), \ |
8225 | X(bcond, d000, f0008000), \ | |
c19d1205 ZW |
8226 | X(bic, 4380, ea200000), \ |
8227 | X(bics, 4380, ea300000), \ | |
8228 | X(cmn, 42c0, eb100f00), \ | |
8229 | X(cmp, 2800, ebb00f00), \ | |
8230 | X(cpsie, b660, f3af8400), \ | |
8231 | X(cpsid, b670, f3af8600), \ | |
8232 | X(cpy, 4600, ea4f0000), \ | |
0110f2b8 | 8233 | X(dec_sp,80dd, f1bd0d00), \ |
c19d1205 ZW |
8234 | X(eor, 4040, ea800000), \ |
8235 | X(eors, 4040, ea900000), \ | |
0110f2b8 | 8236 | X(inc_sp,00dd, f10d0d00), \ |
c19d1205 ZW |
8237 | X(ldmia, c800, e8900000), \ |
8238 | X(ldr, 6800, f8500000), \ | |
8239 | X(ldrb, 7800, f8100000), \ | |
8240 | X(ldrh, 8800, f8300000), \ | |
8241 | X(ldrsb, 5600, f9100000), \ | |
8242 | X(ldrsh, 5e00, f9300000), \ | |
0110f2b8 PB |
8243 | X(ldr_pc,4800, f85f0000), \ |
8244 | X(ldr_pc2,4800, f85f0000), \ | |
8245 | X(ldr_sp,9800, f85d0000), \ | |
c19d1205 ZW |
8246 | X(lsl, 0000, fa00f000), \ |
8247 | X(lsls, 0000, fa10f000), \ | |
8248 | X(lsr, 0800, fa20f000), \ | |
8249 | X(lsrs, 0800, fa30f000), \ | |
8250 | X(mov, 2000, ea4f0000), \ | |
8251 | X(movs, 2000, ea5f0000), \ | |
8252 | X(mul, 4340, fb00f000), \ | |
8253 | X(muls, 4340, ffffffff), /* no 32b muls */ \ | |
8254 | X(mvn, 43c0, ea6f0000), \ | |
8255 | X(mvns, 43c0, ea7f0000), \ | |
8256 | X(neg, 4240, f1c00000), /* rsb #0 */ \ | |
8257 | X(negs, 4240, f1d00000), /* rsbs #0 */ \ | |
8258 | X(orr, 4300, ea400000), \ | |
8259 | X(orrs, 4300, ea500000), \ | |
e9f89963 PB |
8260 | X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \ |
8261 | X(push, b400, e92d0000), /* stmdb sp!,... */ \ | |
c19d1205 ZW |
8262 | X(rev, ba00, fa90f080), \ |
8263 | X(rev16, ba40, fa90f090), \ | |
8264 | X(revsh, bac0, fa90f0b0), \ | |
8265 | X(ror, 41c0, fa60f000), \ | |
8266 | X(rors, 41c0, fa70f000), \ | |
8267 | X(sbc, 4180, eb600000), \ | |
8268 | X(sbcs, 4180, eb700000), \ | |
8269 | X(stmia, c000, e8800000), \ | |
8270 | X(str, 6000, f8400000), \ | |
8271 | X(strb, 7000, f8000000), \ | |
8272 | X(strh, 8000, f8200000), \ | |
0110f2b8 | 8273 | X(str_sp,9000, f84d0000), \ |
c19d1205 ZW |
8274 | X(sub, 1e00, eba00000), \ |
8275 | X(subs, 1e00, ebb00000), \ | |
0110f2b8 PB |
8276 | X(subi, 8000, f1a00000), \ |
8277 | X(subis, 8000, f1b00000), \ | |
c19d1205 ZW |
8278 | X(sxtb, b240, fa4ff080), \ |
8279 | X(sxth, b200, fa0ff080), \ | |
8280 | X(tst, 4200, ea100f00), \ | |
8281 | X(uxtb, b2c0, fa5ff080), \ | |
8282 | X(uxth, b280, fa1ff080), \ | |
8283 | X(nop, bf00, f3af8000), \ | |
8284 | X(yield, bf10, f3af8001), \ | |
8285 | X(wfe, bf20, f3af8002), \ | |
8286 | X(wfi, bf30, f3af8003), \ | |
8287 | X(sev, bf40, f3af9004), /* typo, 8004? */ | |
8288 | ||
8289 | /* To catch errors in encoding functions, the codes are all offset by | |
8290 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
8291 | as 16-bit instructions. */ | |
8292 | #define X(a,b,c) T_MNEM_##a | |
8293 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; | |
8294 | #undef X | |
8295 | ||
8296 | #define X(a,b,c) 0x##b | |
8297 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
8298 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
8299 | #undef X | |
8300 | ||
8301 | #define X(a,b,c) 0x##c | |
8302 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
8303 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) | |
8304 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
8305 | #undef X | |
8306 | #undef T16_32_TAB | |
8307 | ||
8308 | /* Thumb instruction encoders, in alphabetical order. */ | |
8309 | ||
92e90b6e PB |
8310 | /* ADDW or SUBW. */ |
8311 | static void | |
8312 | do_t_add_sub_w (void) | |
8313 | { | |
8314 | int Rd, Rn; | |
8315 | ||
8316 | Rd = inst.operands[0].reg; | |
8317 | Rn = inst.operands[1].reg; | |
8318 | ||
8319 | constraint (Rd == 15, _("PC not allowed as destination")); | |
8320 | inst.instruction |= (Rn << 16) | (Rd << 8); | |
8321 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8322 | } | |
8323 | ||
c19d1205 ZW |
8324 | /* Parse an add or subtract instruction. We get here with inst.instruction |
8325 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
8326 | ||
8327 | static void | |
8328 | do_t_add_sub (void) | |
8329 | { | |
8330 | int Rd, Rs, Rn; | |
8331 | ||
8332 | Rd = inst.operands[0].reg; | |
8333 | Rs = (inst.operands[1].present | |
8334 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8335 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8336 | ||
8337 | if (unified_syntax) | |
8338 | { | |
0110f2b8 PB |
8339 | bfd_boolean flags; |
8340 | bfd_boolean narrow; | |
8341 | int opcode; | |
8342 | ||
8343 | flags = (inst.instruction == T_MNEM_adds | |
8344 | || inst.instruction == T_MNEM_subs); | |
8345 | if (flags) | |
8346 | narrow = (current_it_mask == 0); | |
8347 | else | |
8348 | narrow = (current_it_mask != 0); | |
c19d1205 | 8349 | if (!inst.operands[2].isreg) |
b99bd4ef | 8350 | { |
16805f35 PB |
8351 | int add; |
8352 | ||
8353 | add = (inst.instruction == T_MNEM_add | |
8354 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
8355 | opcode = 0; |
8356 | if (inst.size_req != 4) | |
8357 | { | |
0110f2b8 PB |
8358 | /* Attempt to use a narrow opcode, with relaxation if |
8359 | appropriate. */ | |
8360 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
8361 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
8362 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
8363 | opcode = T_MNEM_add_sp; | |
8364 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
8365 | opcode = T_MNEM_add_pc; | |
8366 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
8367 | { | |
8368 | if (flags) | |
8369 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
8370 | else | |
8371 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
8372 | } | |
8373 | if (opcode) | |
8374 | { | |
8375 | inst.instruction = THUMB_OP16(opcode); | |
8376 | inst.instruction |= (Rd << 4) | Rs; | |
8377 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8378 | if (inst.size_req != 2) | |
8379 | inst.relax = opcode; | |
8380 | } | |
8381 | else | |
8382 | constraint (inst.size_req == 2, BAD_HIREG); | |
8383 | } | |
8384 | if (inst.size_req == 4 | |
8385 | || (inst.size_req != 2 && !opcode)) | |
8386 | { | |
16805f35 PB |
8387 | if (Rs == REG_PC) |
8388 | { | |
8389 | /* Always use addw/subw. */ | |
8390 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
8391 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8392 | } | |
8393 | else | |
8394 | { | |
8395 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8396 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
8397 | | 0x10000000; | |
8398 | if (flags) | |
8399 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8400 | else | |
8401 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
8402 | } | |
0110f2b8 PB |
8403 | inst.instruction |= inst.operands[0].reg << 8; |
8404 | inst.instruction |= inst.operands[1].reg << 16; | |
0110f2b8 | 8405 | } |
b99bd4ef | 8406 | } |
c19d1205 ZW |
8407 | else |
8408 | { | |
8409 | Rn = inst.operands[2].reg; | |
8410 | /* See if we can do this with a 16-bit instruction. */ | |
8411 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
8412 | { | |
e27ec89e PB |
8413 | if (Rd > 7 || Rs > 7 || Rn > 7) |
8414 | narrow = FALSE; | |
8415 | ||
8416 | if (narrow) | |
c19d1205 | 8417 | { |
e27ec89e PB |
8418 | inst.instruction = ((inst.instruction == T_MNEM_adds |
8419 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
8420 | ? T_OPCODE_ADD_R3 |
8421 | : T_OPCODE_SUB_R3); | |
8422 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
8423 | return; | |
8424 | } | |
b99bd4ef | 8425 | |
c19d1205 ZW |
8426 | if (inst.instruction == T_MNEM_add) |
8427 | { | |
8428 | if (Rd == Rs) | |
8429 | { | |
8430 | inst.instruction = T_OPCODE_ADD_HI; | |
8431 | inst.instruction |= (Rd & 8) << 4; | |
8432 | inst.instruction |= (Rd & 7); | |
8433 | inst.instruction |= Rn << 3; | |
8434 | return; | |
8435 | } | |
8436 | /* ... because addition is commutative! */ | |
8437 | else if (Rd == Rn) | |
8438 | { | |
8439 | inst.instruction = T_OPCODE_ADD_HI; | |
8440 | inst.instruction |= (Rd & 8) << 4; | |
8441 | inst.instruction |= (Rd & 7); | |
8442 | inst.instruction |= Rs << 3; | |
8443 | return; | |
8444 | } | |
8445 | } | |
8446 | } | |
8447 | /* If we get here, it can't be done in 16 bits. */ | |
8448 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
8449 | _("shift must be constant")); | |
8450 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8451 | inst.instruction |= Rd << 8; | |
8452 | inst.instruction |= Rs << 16; | |
8453 | encode_thumb32_shifted_operand (2); | |
8454 | } | |
8455 | } | |
8456 | else | |
8457 | { | |
8458 | constraint (inst.instruction == T_MNEM_adds | |
8459 | || inst.instruction == T_MNEM_subs, | |
8460 | BAD_THUMB32); | |
b99bd4ef | 8461 | |
c19d1205 | 8462 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 8463 | { |
c19d1205 ZW |
8464 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
8465 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
8466 | BAD_HIREG); | |
8467 | ||
8468 | inst.instruction = (inst.instruction == T_MNEM_add | |
8469 | ? 0x0000 : 0x8000); | |
8470 | inst.instruction |= (Rd << 4) | Rs; | |
8471 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
8472 | return; |
8473 | } | |
8474 | ||
c19d1205 ZW |
8475 | Rn = inst.operands[2].reg; |
8476 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 8477 | |
c19d1205 ZW |
8478 | /* We now have Rd, Rs, and Rn set to registers. */ |
8479 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 8480 | { |
c19d1205 ZW |
8481 | /* Can't do this for SUB. */ |
8482 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
8483 | inst.instruction = T_OPCODE_ADD_HI; | |
8484 | inst.instruction |= (Rd & 8) << 4; | |
8485 | inst.instruction |= (Rd & 7); | |
8486 | if (Rs == Rd) | |
8487 | inst.instruction |= Rn << 3; | |
8488 | else if (Rn == Rd) | |
8489 | inst.instruction |= Rs << 3; | |
8490 | else | |
8491 | constraint (1, _("dest must overlap one source register")); | |
8492 | } | |
8493 | else | |
8494 | { | |
8495 | inst.instruction = (inst.instruction == T_MNEM_add | |
8496 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
8497 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 8498 | } |
b99bd4ef | 8499 | } |
b99bd4ef NC |
8500 | } |
8501 | ||
c19d1205 ZW |
8502 | static void |
8503 | do_t_adr (void) | |
8504 | { | |
0110f2b8 PB |
8505 | if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7) |
8506 | { | |
8507 | /* Defer to section relaxation. */ | |
8508 | inst.relax = inst.instruction; | |
8509 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8510 | inst.instruction |= inst.operands[0].reg << 4; | |
8511 | } | |
8512 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 8513 | { |
0110f2b8 | 8514 | /* Generate a 32-bit opcode. */ |
e9f89963 PB |
8515 | inst.instruction = THUMB_OP32 (inst.instruction); |
8516 | inst.instruction |= inst.operands[0].reg << 8; | |
8517 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; | |
8518 | inst.reloc.pc_rel = 1; | |
8519 | } | |
8520 | else | |
8521 | { | |
0110f2b8 | 8522 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
8523 | inst.instruction = THUMB_OP16 (inst.instruction); |
8524 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8525 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
8526 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 8527 | |
e9f89963 PB |
8528 | inst.instruction |= inst.operands[0].reg << 4; |
8529 | } | |
c19d1205 | 8530 | } |
b99bd4ef | 8531 | |
c19d1205 ZW |
8532 | /* Arithmetic instructions for which there is just one 16-bit |
8533 | instruction encoding, and it allows only two low registers. | |
8534 | For maximal compatibility with ARM syntax, we allow three register | |
8535 | operands even when Thumb-32 instructions are not available, as long | |
8536 | as the first two are identical. For instance, both "sbc r0,r1" and | |
8537 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 8538 | static void |
c19d1205 | 8539 | do_t_arit3 (void) |
b99bd4ef | 8540 | { |
c19d1205 | 8541 | int Rd, Rs, Rn; |
b99bd4ef | 8542 | |
c19d1205 ZW |
8543 | Rd = inst.operands[0].reg; |
8544 | Rs = (inst.operands[1].present | |
8545 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8546 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8547 | Rn = inst.operands[2].reg; | |
b99bd4ef | 8548 | |
c19d1205 | 8549 | if (unified_syntax) |
b99bd4ef | 8550 | { |
c19d1205 ZW |
8551 | if (!inst.operands[2].isreg) |
8552 | { | |
8553 | /* For an immediate, we always generate a 32-bit opcode; | |
8554 | section relaxation will shrink it later if possible. */ | |
8555 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8556 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
8557 | inst.instruction |= Rd << 8; | |
8558 | inst.instruction |= Rs << 16; | |
8559 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8560 | } | |
8561 | else | |
8562 | { | |
e27ec89e PB |
8563 | bfd_boolean narrow; |
8564 | ||
c19d1205 | 8565 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
8566 | if (THUMB_SETS_FLAGS (inst.instruction)) |
8567 | narrow = current_it_mask == 0; | |
8568 | else | |
8569 | narrow = current_it_mask != 0; | |
8570 | ||
8571 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
8572 | narrow = FALSE; | |
8573 | if (inst.operands[2].shifted) | |
8574 | narrow = FALSE; | |
8575 | if (inst.size_req == 4) | |
8576 | narrow = FALSE; | |
8577 | ||
8578 | if (narrow | |
c19d1205 ZW |
8579 | && Rd == Rs) |
8580 | { | |
8581 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8582 | inst.instruction |= Rd; | |
8583 | inst.instruction |= Rn << 3; | |
8584 | return; | |
8585 | } | |
b99bd4ef | 8586 | |
c19d1205 ZW |
8587 | /* If we get here, it can't be done in 16 bits. */ |
8588 | constraint (inst.operands[2].shifted | |
8589 | && inst.operands[2].immisreg, | |
8590 | _("shift must be constant")); | |
8591 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8592 | inst.instruction |= Rd << 8; | |
8593 | inst.instruction |= Rs << 16; | |
8594 | encode_thumb32_shifted_operand (2); | |
8595 | } | |
a737bd4d | 8596 | } |
c19d1205 | 8597 | else |
b99bd4ef | 8598 | { |
c19d1205 ZW |
8599 | /* On its face this is a lie - the instruction does set the |
8600 | flags. However, the only supported mnemonic in this mode | |
8601 | says it doesn't. */ | |
8602 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 8603 | |
c19d1205 ZW |
8604 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
8605 | _("unshifted register required")); | |
8606 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
8607 | constraint (Rd != Rs, | |
8608 | _("dest and source1 must be the same register")); | |
a737bd4d | 8609 | |
c19d1205 ZW |
8610 | inst.instruction = THUMB_OP16 (inst.instruction); |
8611 | inst.instruction |= Rd; | |
8612 | inst.instruction |= Rn << 3; | |
b99bd4ef | 8613 | } |
a737bd4d | 8614 | } |
b99bd4ef | 8615 | |
c19d1205 ZW |
8616 | /* Similarly, but for instructions where the arithmetic operation is |
8617 | commutative, so we can allow either of them to be different from | |
8618 | the destination operand in a 16-bit instruction. For instance, all | |
8619 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
8620 | accepted. */ | |
8621 | static void | |
8622 | do_t_arit3c (void) | |
a737bd4d | 8623 | { |
c19d1205 | 8624 | int Rd, Rs, Rn; |
b99bd4ef | 8625 | |
c19d1205 ZW |
8626 | Rd = inst.operands[0].reg; |
8627 | Rs = (inst.operands[1].present | |
8628 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8629 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8630 | Rn = inst.operands[2].reg; | |
a737bd4d | 8631 | |
c19d1205 | 8632 | if (unified_syntax) |
a737bd4d | 8633 | { |
c19d1205 | 8634 | if (!inst.operands[2].isreg) |
b99bd4ef | 8635 | { |
c19d1205 ZW |
8636 | /* For an immediate, we always generate a 32-bit opcode; |
8637 | section relaxation will shrink it later if possible. */ | |
8638 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8639 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
8640 | inst.instruction |= Rd << 8; | |
8641 | inst.instruction |= Rs << 16; | |
8642 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 8643 | } |
c19d1205 | 8644 | else |
a737bd4d | 8645 | { |
e27ec89e PB |
8646 | bfd_boolean narrow; |
8647 | ||
c19d1205 | 8648 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
8649 | if (THUMB_SETS_FLAGS (inst.instruction)) |
8650 | narrow = current_it_mask == 0; | |
8651 | else | |
8652 | narrow = current_it_mask != 0; | |
8653 | ||
8654 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
8655 | narrow = FALSE; | |
8656 | if (inst.operands[2].shifted) | |
8657 | narrow = FALSE; | |
8658 | if (inst.size_req == 4) | |
8659 | narrow = FALSE; | |
8660 | ||
8661 | if (narrow) | |
a737bd4d | 8662 | { |
c19d1205 | 8663 | if (Rd == Rs) |
a737bd4d | 8664 | { |
c19d1205 ZW |
8665 | inst.instruction = THUMB_OP16 (inst.instruction); |
8666 | inst.instruction |= Rd; | |
8667 | inst.instruction |= Rn << 3; | |
8668 | return; | |
a737bd4d | 8669 | } |
c19d1205 | 8670 | if (Rd == Rn) |
a737bd4d | 8671 | { |
c19d1205 ZW |
8672 | inst.instruction = THUMB_OP16 (inst.instruction); |
8673 | inst.instruction |= Rd; | |
8674 | inst.instruction |= Rs << 3; | |
8675 | return; | |
a737bd4d NC |
8676 | } |
8677 | } | |
c19d1205 ZW |
8678 | |
8679 | /* If we get here, it can't be done in 16 bits. */ | |
8680 | constraint (inst.operands[2].shifted | |
8681 | && inst.operands[2].immisreg, | |
8682 | _("shift must be constant")); | |
8683 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8684 | inst.instruction |= Rd << 8; | |
8685 | inst.instruction |= Rs << 16; | |
8686 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 8687 | } |
b99bd4ef | 8688 | } |
c19d1205 ZW |
8689 | else |
8690 | { | |
8691 | /* On its face this is a lie - the instruction does set the | |
8692 | flags. However, the only supported mnemonic in this mode | |
8693 | says it doesn't. */ | |
8694 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 8695 | |
c19d1205 ZW |
8696 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
8697 | _("unshifted register required")); | |
8698 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
8699 | ||
8700 | inst.instruction = THUMB_OP16 (inst.instruction); | |
8701 | inst.instruction |= Rd; | |
8702 | ||
8703 | if (Rd == Rs) | |
8704 | inst.instruction |= Rn << 3; | |
8705 | else if (Rd == Rn) | |
8706 | inst.instruction |= Rs << 3; | |
8707 | else | |
8708 | constraint (1, _("dest must overlap one source register")); | |
8709 | } | |
a737bd4d NC |
8710 | } |
8711 | ||
62b3e311 PB |
8712 | static void |
8713 | do_t_barrier (void) | |
8714 | { | |
8715 | if (inst.operands[0].present) | |
8716 | { | |
8717 | constraint ((inst.instruction & 0xf0) != 0x40 | |
8718 | && inst.operands[0].imm != 0xf, | |
8719 | "bad barrier type"); | |
8720 | inst.instruction |= inst.operands[0].imm; | |
8721 | } | |
8722 | else | |
8723 | inst.instruction |= 0xf; | |
8724 | } | |
8725 | ||
c19d1205 ZW |
8726 | static void |
8727 | do_t_bfc (void) | |
a737bd4d | 8728 | { |
c19d1205 ZW |
8729 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
8730 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8731 | /* The instruction encoding stores the LSB and MSB, | |
8732 | not the LSB and width. */ | |
8733 | inst.instruction |= inst.operands[0].reg << 8; | |
8734 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; | |
8735 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
8736 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
8737 | } |
8738 | ||
c19d1205 ZW |
8739 | static void |
8740 | do_t_bfi (void) | |
b99bd4ef | 8741 | { |
c19d1205 | 8742 | unsigned int msb; |
b99bd4ef | 8743 | |
c19d1205 ZW |
8744 | /* #0 in second position is alternative syntax for bfc, which is |
8745 | the same instruction but with REG_PC in the Rm field. */ | |
8746 | if (!inst.operands[1].isreg) | |
8747 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 8748 | |
c19d1205 ZW |
8749 | msb = inst.operands[2].imm + inst.operands[3].imm; |
8750 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8751 | /* The instruction encoding stores the LSB and MSB, | |
8752 | not the LSB and width. */ | |
8753 | inst.instruction |= inst.operands[0].reg << 8; | |
8754 | inst.instruction |= inst.operands[1].reg << 16; | |
8755 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
8756 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
8757 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
8758 | } |
8759 | ||
c19d1205 ZW |
8760 | static void |
8761 | do_t_bfx (void) | |
b99bd4ef | 8762 | { |
c19d1205 ZW |
8763 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
8764 | _("bit-field extends past end of register")); | |
8765 | inst.instruction |= inst.operands[0].reg << 8; | |
8766 | inst.instruction |= inst.operands[1].reg << 16; | |
8767 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
8768 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
8769 | inst.instruction |= inst.operands[3].imm - 1; | |
8770 | } | |
b99bd4ef | 8771 | |
c19d1205 ZW |
8772 | /* ARM V5 Thumb BLX (argument parse) |
8773 | BLX <target_addr> which is BLX(1) | |
8774 | BLX <Rm> which is BLX(2) | |
8775 | Unfortunately, there are two different opcodes for this mnemonic. | |
8776 | So, the insns[].value is not used, and the code here zaps values | |
8777 | into inst.instruction. | |
b99bd4ef | 8778 | |
c19d1205 ZW |
8779 | ??? How to take advantage of the additional two bits of displacement |
8780 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 8781 | |
c19d1205 ZW |
8782 | static void |
8783 | do_t_blx (void) | |
8784 | { | |
dfa9f0d5 | 8785 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
8786 | if (inst.operands[0].isreg) |
8787 | /* We have a register, so this is BLX(2). */ | |
8788 | inst.instruction |= inst.operands[0].reg << 3; | |
b99bd4ef NC |
8789 | else |
8790 | { | |
c19d1205 | 8791 | /* No register. This must be BLX(1). */ |
2fc8bdac | 8792 | inst.instruction = 0xf000e800; |
39b41c9c PB |
8793 | #ifdef OBJ_ELF |
8794 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8795 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
8796 | else | |
8797 | #endif | |
8798 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; | |
c19d1205 | 8799 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
8800 | } |
8801 | } | |
8802 | ||
c19d1205 ZW |
8803 | static void |
8804 | do_t_branch (void) | |
b99bd4ef | 8805 | { |
0110f2b8 | 8806 | int opcode; |
dfa9f0d5 PB |
8807 | int cond; |
8808 | ||
8809 | if (current_it_mask) | |
8810 | { | |
8811 | /* Conditional branches inside IT blocks are encoded as unconditional | |
8812 | branches. */ | |
8813 | cond = COND_ALWAYS; | |
8814 | /* A branch must be the last instruction in an IT block. */ | |
8815 | constraint (current_it_mask != 0x10, BAD_BRANCH); | |
8816 | } | |
8817 | else | |
8818 | cond = inst.cond; | |
8819 | ||
8820 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
8821 | opcode = T_MNEM_bcond; |
8822 | else | |
8823 | opcode = inst.instruction; | |
8824 | ||
8825 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 8826 | { |
0110f2b8 | 8827 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 8828 | if (cond == COND_ALWAYS) |
0110f2b8 | 8829 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
8830 | else |
8831 | { | |
dfa9f0d5 PB |
8832 | assert (cond != 0xF); |
8833 | inst.instruction |= cond << 22; | |
c19d1205 ZW |
8834 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
8835 | } | |
8836 | } | |
b99bd4ef NC |
8837 | else |
8838 | { | |
0110f2b8 | 8839 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 8840 | if (cond == COND_ALWAYS) |
c19d1205 ZW |
8841 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; |
8842 | else | |
b99bd4ef | 8843 | { |
dfa9f0d5 | 8844 | inst.instruction |= cond << 8; |
c19d1205 | 8845 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 8846 | } |
0110f2b8 PB |
8847 | /* Allow section relaxation. */ |
8848 | if (unified_syntax && inst.size_req != 2) | |
8849 | inst.relax = opcode; | |
b99bd4ef | 8850 | } |
c19d1205 ZW |
8851 | |
8852 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
8853 | } |
8854 | ||
8855 | static void | |
c19d1205 | 8856 | do_t_bkpt (void) |
b99bd4ef | 8857 | { |
dfa9f0d5 PB |
8858 | constraint (inst.cond != COND_ALWAYS, |
8859 | _("instruction is always unconditional")); | |
c19d1205 | 8860 | if (inst.operands[0].present) |
b99bd4ef | 8861 | { |
c19d1205 ZW |
8862 | constraint (inst.operands[0].imm > 255, |
8863 | _("immediate value out of range")); | |
8864 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 8865 | } |
b99bd4ef NC |
8866 | } |
8867 | ||
8868 | static void | |
c19d1205 | 8869 | do_t_branch23 (void) |
b99bd4ef | 8870 | { |
dfa9f0d5 | 8871 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 | 8872 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
8873 | inst.reloc.pc_rel = 1; |
8874 | ||
c19d1205 ZW |
8875 | /* If the destination of the branch is a defined symbol which does not have |
8876 | the THUMB_FUNC attribute, then we must be calling a function which has | |
8877 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
8878 | function and change the branch to refer to that function instead. */ | |
8879 | if ( inst.reloc.exp.X_op == O_symbol | |
8880 | && inst.reloc.exp.X_add_symbol != NULL | |
8881 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
8882 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
8883 | inst.reloc.exp.X_add_symbol = | |
8884 | find_real_start (inst.reloc.exp.X_add_symbol); | |
90e4755a RE |
8885 | } |
8886 | ||
8887 | static void | |
c19d1205 | 8888 | do_t_bx (void) |
90e4755a | 8889 | { |
dfa9f0d5 | 8890 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
8891 | inst.instruction |= inst.operands[0].reg << 3; |
8892 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
8893 | should cause the alignment to be checked once it is known. This is | |
8894 | because BX PC only works if the instruction is word aligned. */ | |
8895 | } | |
90e4755a | 8896 | |
c19d1205 ZW |
8897 | static void |
8898 | do_t_bxj (void) | |
8899 | { | |
dfa9f0d5 | 8900 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
8901 | if (inst.operands[0].reg == REG_PC) |
8902 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
90e4755a | 8903 | |
c19d1205 | 8904 | inst.instruction |= inst.operands[0].reg << 16; |
90e4755a RE |
8905 | } |
8906 | ||
8907 | static void | |
c19d1205 | 8908 | do_t_clz (void) |
90e4755a | 8909 | { |
c19d1205 ZW |
8910 | inst.instruction |= inst.operands[0].reg << 8; |
8911 | inst.instruction |= inst.operands[1].reg << 16; | |
8912 | inst.instruction |= inst.operands[1].reg; | |
8913 | } | |
90e4755a | 8914 | |
dfa9f0d5 PB |
8915 | static void |
8916 | do_t_cps (void) | |
8917 | { | |
8918 | constraint (current_it_mask, BAD_NOT_IT); | |
8919 | inst.instruction |= inst.operands[0].imm; | |
8920 | } | |
8921 | ||
c19d1205 ZW |
8922 | static void |
8923 | do_t_cpsi (void) | |
8924 | { | |
dfa9f0d5 | 8925 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 | 8926 | if (unified_syntax |
62b3e311 PB |
8927 | && (inst.operands[1].present || inst.size_req == 4) |
8928 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 8929 | { |
c19d1205 ZW |
8930 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
8931 | inst.instruction = 0xf3af8000; | |
8932 | inst.instruction |= imod << 9; | |
8933 | inst.instruction |= inst.operands[0].imm << 5; | |
8934 | if (inst.operands[1].present) | |
8935 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 8936 | } |
c19d1205 | 8937 | else |
90e4755a | 8938 | { |
62b3e311 PB |
8939 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
8940 | && (inst.operands[0].imm & 4), | |
8941 | _("selected processor does not support 'A' form " | |
8942 | "of this instruction")); | |
8943 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
8944 | _("Thumb does not support the 2-argument " |
8945 | "form of this instruction")); | |
8946 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 8947 | } |
90e4755a RE |
8948 | } |
8949 | ||
c19d1205 ZW |
8950 | /* THUMB CPY instruction (argument parse). */ |
8951 | ||
90e4755a | 8952 | static void |
c19d1205 | 8953 | do_t_cpy (void) |
90e4755a | 8954 | { |
c19d1205 | 8955 | if (inst.size_req == 4) |
90e4755a | 8956 | { |
c19d1205 ZW |
8957 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
8958 | inst.instruction |= inst.operands[0].reg << 8; | |
8959 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 8960 | } |
c19d1205 | 8961 | else |
90e4755a | 8962 | { |
c19d1205 ZW |
8963 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
8964 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
8965 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 8966 | } |
90e4755a RE |
8967 | } |
8968 | ||
90e4755a | 8969 | static void |
c19d1205 | 8970 | do_t_czb (void) |
90e4755a | 8971 | { |
dfa9f0d5 | 8972 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 ZW |
8973 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
8974 | inst.instruction |= inst.operands[0].reg; | |
8975 | inst.reloc.pc_rel = 1; | |
8976 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
8977 | } | |
90e4755a | 8978 | |
62b3e311 PB |
8979 | static void |
8980 | do_t_dbg (void) | |
8981 | { | |
8982 | inst.instruction |= inst.operands[0].imm; | |
8983 | } | |
8984 | ||
8985 | static void | |
8986 | do_t_div (void) | |
8987 | { | |
8988 | if (!inst.operands[1].present) | |
8989 | inst.operands[1].reg = inst.operands[0].reg; | |
8990 | inst.instruction |= inst.operands[0].reg << 8; | |
8991 | inst.instruction |= inst.operands[1].reg << 16; | |
8992 | inst.instruction |= inst.operands[2].reg; | |
8993 | } | |
8994 | ||
c19d1205 ZW |
8995 | static void |
8996 | do_t_hint (void) | |
8997 | { | |
8998 | if (unified_syntax && inst.size_req == 4) | |
8999 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9000 | else | |
9001 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9002 | } | |
90e4755a | 9003 | |
c19d1205 ZW |
9004 | static void |
9005 | do_t_it (void) | |
9006 | { | |
9007 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 9008 | |
dfa9f0d5 | 9009 | constraint (current_it_mask, BAD_NOT_IT); |
e27ec89e PB |
9010 | current_it_mask = (inst.instruction & 0xf) | 0x10; |
9011 | current_cc = cond; | |
9012 | ||
9013 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 9014 | if ((cond & 0x1) == 0x0) |
90e4755a | 9015 | { |
c19d1205 | 9016 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 9017 | |
c19d1205 ZW |
9018 | if ((mask & 0x7) == 0) |
9019 | /* no conversion needed */; | |
9020 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
9021 | mask ^= 0x8; |
9022 | else if ((mask & 0x1) == 0) | |
9023 | mask ^= 0xC; | |
c19d1205 | 9024 | else |
e27ec89e | 9025 | mask ^= 0xE; |
90e4755a | 9026 | |
e27ec89e PB |
9027 | inst.instruction &= 0xfff0; |
9028 | inst.instruction |= mask; | |
c19d1205 | 9029 | } |
90e4755a | 9030 | |
c19d1205 ZW |
9031 | inst.instruction |= cond << 4; |
9032 | } | |
90e4755a | 9033 | |
c19d1205 ZW |
9034 | static void |
9035 | do_t_ldmstm (void) | |
9036 | { | |
9037 | /* This really doesn't seem worth it. */ | |
9038 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9039 | _("expression too complex")); | |
9040 | constraint (inst.operands[1].writeback, | |
9041 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 9042 | |
c19d1205 ZW |
9043 | if (unified_syntax) |
9044 | { | |
9045 | /* See if we can use a 16-bit instruction. */ | |
9046 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
9047 | && inst.size_req != 4 | |
9048 | && inst.operands[0].reg <= 7 | |
9049 | && !(inst.operands[1].imm & ~0xff) | |
9050 | && (inst.instruction == T_MNEM_stmia | |
9051 | ? inst.operands[0].writeback | |
9052 | : (inst.operands[0].writeback | |
9053 | == !(inst.operands[1].imm & (1 << inst.operands[0].reg))))) | |
90e4755a | 9054 | { |
c19d1205 ZW |
9055 | if (inst.instruction == T_MNEM_stmia |
9056 | && (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9057 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
9058 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
9059 | inst.operands[0].reg); | |
90e4755a | 9060 | |
c19d1205 ZW |
9061 | inst.instruction = THUMB_OP16 (inst.instruction); |
9062 | inst.instruction |= inst.operands[0].reg << 8; | |
9063 | inst.instruction |= inst.operands[1].imm; | |
9064 | } | |
9065 | else | |
9066 | { | |
9067 | if (inst.operands[1].imm & (1 << 13)) | |
9068 | as_warn (_("SP should not be in register list")); | |
9069 | if (inst.instruction == T_MNEM_stmia) | |
90e4755a | 9070 | { |
c19d1205 ZW |
9071 | if (inst.operands[1].imm & (1 << 15)) |
9072 | as_warn (_("PC should not be in register list")); | |
9073 | if (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9074 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
9075 | inst.operands[0].reg); | |
90e4755a RE |
9076 | } |
9077 | else | |
9078 | { | |
c19d1205 ZW |
9079 | if (inst.operands[1].imm & (1 << 14) |
9080 | && inst.operands[1].imm & (1 << 15)) | |
9081 | as_warn (_("LR and PC should not both be in register list")); | |
9082 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9083 | && inst.operands[0].writeback) | |
9084 | as_warn (_("base register should not be in register list " | |
9085 | "when written back")); | |
90e4755a | 9086 | } |
c19d1205 ZW |
9087 | if (inst.instruction < 0xffff) |
9088 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9089 | inst.instruction |= inst.operands[0].reg << 16; | |
9090 | inst.instruction |= inst.operands[1].imm; | |
9091 | if (inst.operands[0].writeback) | |
9092 | inst.instruction |= WRITE_BACK; | |
90e4755a RE |
9093 | } |
9094 | } | |
c19d1205 | 9095 | else |
90e4755a | 9096 | { |
c19d1205 ZW |
9097 | constraint (inst.operands[0].reg > 7 |
9098 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
9099 | if (inst.instruction == T_MNEM_stmia) | |
f03698e6 | 9100 | { |
c19d1205 ZW |
9101 | if (!inst.operands[0].writeback) |
9102 | as_warn (_("this instruction will write back the base register")); | |
9103 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9104 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
9105 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
9106 | inst.operands[0].reg); | |
f03698e6 | 9107 | } |
c19d1205 | 9108 | else |
90e4755a | 9109 | { |
c19d1205 ZW |
9110 | if (!inst.operands[0].writeback |
9111 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9112 | as_warn (_("this instruction will write back the base register")); | |
9113 | else if (inst.operands[0].writeback | |
9114 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9115 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
9116 | } |
9117 | ||
c19d1205 ZW |
9118 | inst.instruction = THUMB_OP16 (inst.instruction); |
9119 | inst.instruction |= inst.operands[0].reg << 8; | |
9120 | inst.instruction |= inst.operands[1].imm; | |
9121 | } | |
9122 | } | |
e28cd48c | 9123 | |
c19d1205 ZW |
9124 | static void |
9125 | do_t_ldrex (void) | |
9126 | { | |
9127 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
9128 | || inst.operands[1].postind || inst.operands[1].writeback | |
9129 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
9130 | || inst.operands[1].negative, | |
01cfc07f | 9131 | BAD_ADDR_MODE); |
e28cd48c | 9132 | |
c19d1205 ZW |
9133 | inst.instruction |= inst.operands[0].reg << 12; |
9134 | inst.instruction |= inst.operands[1].reg << 16; | |
9135 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
9136 | } | |
e28cd48c | 9137 | |
c19d1205 ZW |
9138 | static void |
9139 | do_t_ldrexd (void) | |
9140 | { | |
9141 | if (!inst.operands[1].present) | |
1cac9012 | 9142 | { |
c19d1205 ZW |
9143 | constraint (inst.operands[0].reg == REG_LR, |
9144 | _("r14 not allowed as first register " | |
9145 | "when second register is omitted")); | |
9146 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 9147 | } |
c19d1205 ZW |
9148 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
9149 | BAD_OVERLAP); | |
b99bd4ef | 9150 | |
c19d1205 ZW |
9151 | inst.instruction |= inst.operands[0].reg << 12; |
9152 | inst.instruction |= inst.operands[1].reg << 8; | |
9153 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9154 | } |
9155 | ||
9156 | static void | |
c19d1205 | 9157 | do_t_ldst (void) |
b99bd4ef | 9158 | { |
0110f2b8 PB |
9159 | unsigned long opcode; |
9160 | int Rn; | |
9161 | ||
9162 | opcode = inst.instruction; | |
c19d1205 | 9163 | if (unified_syntax) |
b99bd4ef | 9164 | { |
53365c0d PB |
9165 | if (!inst.operands[1].isreg) |
9166 | { | |
9167 | if (opcode <= 0xffff) | |
9168 | inst.instruction = THUMB_OP32 (opcode); | |
9169 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9170 | return; | |
9171 | } | |
0110f2b8 PB |
9172 | if (inst.operands[1].isreg |
9173 | && !inst.operands[1].writeback | |
c19d1205 ZW |
9174 | && !inst.operands[1].shifted && !inst.operands[1].postind |
9175 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
9176 | && opcode <= 0xffff |
9177 | && inst.size_req != 4) | |
c19d1205 | 9178 | { |
0110f2b8 PB |
9179 | /* Insn may have a 16-bit form. */ |
9180 | Rn = inst.operands[1].reg; | |
9181 | if (inst.operands[1].immisreg) | |
9182 | { | |
9183 | inst.instruction = THUMB_OP16 (opcode); | |
9184 | /* [Rn, Ri] */ | |
9185 | if (Rn <= 7 && inst.operands[1].imm <= 7) | |
9186 | goto op16; | |
9187 | } | |
9188 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
9189 | && opcode != T_MNEM_ldrsb) | |
9190 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
9191 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
9192 | { | |
9193 | /* [Rn, #const] */ | |
9194 | if (Rn > 7) | |
9195 | { | |
9196 | if (Rn == REG_PC) | |
9197 | { | |
9198 | if (inst.reloc.pc_rel) | |
9199 | opcode = T_MNEM_ldr_pc2; | |
9200 | else | |
9201 | opcode = T_MNEM_ldr_pc; | |
9202 | } | |
9203 | else | |
9204 | { | |
9205 | if (opcode == T_MNEM_ldr) | |
9206 | opcode = T_MNEM_ldr_sp; | |
9207 | else | |
9208 | opcode = T_MNEM_str_sp; | |
9209 | } | |
9210 | inst.instruction = inst.operands[0].reg << 8; | |
9211 | } | |
9212 | else | |
9213 | { | |
9214 | inst.instruction = inst.operands[0].reg; | |
9215 | inst.instruction |= inst.operands[1].reg << 3; | |
9216 | } | |
9217 | inst.instruction |= THUMB_OP16 (opcode); | |
9218 | if (inst.size_req == 2) | |
9219 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9220 | else | |
9221 | inst.relax = opcode; | |
9222 | return; | |
9223 | } | |
c19d1205 | 9224 | } |
0110f2b8 PB |
9225 | /* Definitely a 32-bit variant. */ |
9226 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
9227 | inst.instruction |= inst.operands[0].reg << 12; |
9228 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
9229 | return; |
9230 | } | |
9231 | ||
c19d1205 ZW |
9232 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9233 | ||
9234 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 9235 | { |
c19d1205 ZW |
9236 | /* Only [Rn,Rm] is acceptable. */ |
9237 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
9238 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
9239 | || inst.operands[1].postind || inst.operands[1].shifted | |
9240 | || inst.operands[1].negative, | |
9241 | _("Thumb does not support this addressing mode")); | |
9242 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9243 | goto op16; | |
b99bd4ef | 9244 | } |
c19d1205 ZW |
9245 | |
9246 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9247 | if (!inst.operands[1].isreg) | |
9248 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9249 | return; | |
b99bd4ef | 9250 | |
c19d1205 ZW |
9251 | constraint (!inst.operands[1].preind |
9252 | || inst.operands[1].shifted | |
9253 | || inst.operands[1].writeback, | |
9254 | _("Thumb does not support this addressing mode")); | |
9255 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 9256 | { |
c19d1205 ZW |
9257 | constraint (inst.instruction & 0x0600, |
9258 | _("byte or halfword not valid for base register")); | |
9259 | constraint (inst.operands[1].reg == REG_PC | |
9260 | && !(inst.instruction & THUMB_LOAD_BIT), | |
9261 | _("r15 based store not allowed")); | |
9262 | constraint (inst.operands[1].immisreg, | |
9263 | _("invalid base register for register offset")); | |
b99bd4ef | 9264 | |
c19d1205 ZW |
9265 | if (inst.operands[1].reg == REG_PC) |
9266 | inst.instruction = T_OPCODE_LDR_PC; | |
9267 | else if (inst.instruction & THUMB_LOAD_BIT) | |
9268 | inst.instruction = T_OPCODE_LDR_SP; | |
9269 | else | |
9270 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 9271 | |
c19d1205 ZW |
9272 | inst.instruction |= inst.operands[0].reg << 8; |
9273 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9274 | return; | |
9275 | } | |
90e4755a | 9276 | |
c19d1205 ZW |
9277 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
9278 | if (!inst.operands[1].immisreg) | |
9279 | { | |
9280 | /* Immediate offset. */ | |
9281 | inst.instruction |= inst.operands[0].reg; | |
9282 | inst.instruction |= inst.operands[1].reg << 3; | |
9283 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9284 | return; | |
9285 | } | |
90e4755a | 9286 | |
c19d1205 ZW |
9287 | /* Register offset. */ |
9288 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
9289 | constraint (inst.operands[1].negative, | |
9290 | _("Thumb does not support this addressing mode")); | |
90e4755a | 9291 | |
c19d1205 ZW |
9292 | op16: |
9293 | switch (inst.instruction) | |
9294 | { | |
9295 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
9296 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
9297 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
9298 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
9299 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
9300 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
9301 | case 0x5600 /* ldrsb */: | |
9302 | case 0x5e00 /* ldrsh */: break; | |
9303 | default: abort (); | |
9304 | } | |
90e4755a | 9305 | |
c19d1205 ZW |
9306 | inst.instruction |= inst.operands[0].reg; |
9307 | inst.instruction |= inst.operands[1].reg << 3; | |
9308 | inst.instruction |= inst.operands[1].imm << 6; | |
9309 | } | |
90e4755a | 9310 | |
c19d1205 ZW |
9311 | static void |
9312 | do_t_ldstd (void) | |
9313 | { | |
9314 | if (!inst.operands[1].present) | |
b99bd4ef | 9315 | { |
c19d1205 ZW |
9316 | inst.operands[1].reg = inst.operands[0].reg + 1; |
9317 | constraint (inst.operands[0].reg == REG_LR, | |
9318 | _("r14 not allowed here")); | |
b99bd4ef | 9319 | } |
c19d1205 ZW |
9320 | inst.instruction |= inst.operands[0].reg << 12; |
9321 | inst.instruction |= inst.operands[1].reg << 8; | |
9322 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
9323 | ||
b99bd4ef NC |
9324 | } |
9325 | ||
c19d1205 ZW |
9326 | static void |
9327 | do_t_ldstt (void) | |
9328 | { | |
9329 | inst.instruction |= inst.operands[0].reg << 12; | |
9330 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
9331 | } | |
a737bd4d | 9332 | |
b99bd4ef | 9333 | static void |
c19d1205 | 9334 | do_t_mla (void) |
b99bd4ef | 9335 | { |
c19d1205 ZW |
9336 | inst.instruction |= inst.operands[0].reg << 8; |
9337 | inst.instruction |= inst.operands[1].reg << 16; | |
9338 | inst.instruction |= inst.operands[2].reg; | |
9339 | inst.instruction |= inst.operands[3].reg << 12; | |
9340 | } | |
b99bd4ef | 9341 | |
c19d1205 ZW |
9342 | static void |
9343 | do_t_mlal (void) | |
9344 | { | |
9345 | inst.instruction |= inst.operands[0].reg << 12; | |
9346 | inst.instruction |= inst.operands[1].reg << 8; | |
9347 | inst.instruction |= inst.operands[2].reg << 16; | |
9348 | inst.instruction |= inst.operands[3].reg; | |
9349 | } | |
b99bd4ef | 9350 | |
c19d1205 ZW |
9351 | static void |
9352 | do_t_mov_cmp (void) | |
9353 | { | |
9354 | if (unified_syntax) | |
b99bd4ef | 9355 | { |
c19d1205 ZW |
9356 | int r0off = (inst.instruction == T_MNEM_mov |
9357 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 9358 | unsigned long opcode; |
3d388997 PB |
9359 | bfd_boolean narrow; |
9360 | bfd_boolean low_regs; | |
9361 | ||
9362 | low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7); | |
0110f2b8 | 9363 | opcode = inst.instruction; |
3d388997 | 9364 | if (current_it_mask) |
0110f2b8 | 9365 | narrow = opcode != T_MNEM_movs; |
3d388997 | 9366 | else |
0110f2b8 | 9367 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
9368 | if (inst.size_req == 4 |
9369 | || inst.operands[1].shifted) | |
9370 | narrow = FALSE; | |
9371 | ||
c19d1205 ZW |
9372 | if (!inst.operands[1].isreg) |
9373 | { | |
0110f2b8 PB |
9374 | /* Immediate operand. */ |
9375 | if (current_it_mask == 0 && opcode == T_MNEM_mov) | |
9376 | narrow = 0; | |
9377 | if (low_regs && narrow) | |
9378 | { | |
9379 | inst.instruction = THUMB_OP16 (opcode); | |
9380 | inst.instruction |= inst.operands[0].reg << 8; | |
9381 | if (inst.size_req == 2) | |
9382 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
9383 | else | |
9384 | inst.relax = opcode; | |
9385 | } | |
9386 | else | |
9387 | { | |
9388 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9389 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9390 | inst.instruction |= inst.operands[0].reg << r0off; | |
9391 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9392 | } | |
c19d1205 | 9393 | } |
3d388997 | 9394 | else if (!narrow) |
c19d1205 ZW |
9395 | { |
9396 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9397 | inst.instruction |= inst.operands[0].reg << r0off; | |
9398 | encode_thumb32_shifted_operand (1); | |
9399 | } | |
9400 | else | |
9401 | switch (inst.instruction) | |
9402 | { | |
9403 | case T_MNEM_mov: | |
9404 | inst.instruction = T_OPCODE_MOV_HR; | |
9405 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
9406 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9407 | inst.instruction |= inst.operands[1].reg << 3; | |
9408 | break; | |
b99bd4ef | 9409 | |
c19d1205 ZW |
9410 | case T_MNEM_movs: |
9411 | /* We know we have low registers at this point. | |
9412 | Generate ADD Rd, Rs, #0. */ | |
9413 | inst.instruction = T_OPCODE_ADD_I3; | |
9414 | inst.instruction |= inst.operands[0].reg; | |
9415 | inst.instruction |= inst.operands[1].reg << 3; | |
9416 | break; | |
9417 | ||
9418 | case T_MNEM_cmp: | |
3d388997 | 9419 | if (low_regs) |
c19d1205 ZW |
9420 | { |
9421 | inst.instruction = T_OPCODE_CMP_LR; | |
9422 | inst.instruction |= inst.operands[0].reg; | |
9423 | inst.instruction |= inst.operands[1].reg << 3; | |
9424 | } | |
9425 | else | |
9426 | { | |
9427 | inst.instruction = T_OPCODE_CMP_HR; | |
9428 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
9429 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9430 | inst.instruction |= inst.operands[1].reg << 3; | |
9431 | } | |
9432 | break; | |
9433 | } | |
b99bd4ef NC |
9434 | return; |
9435 | } | |
9436 | ||
c19d1205 ZW |
9437 | inst.instruction = THUMB_OP16 (inst.instruction); |
9438 | if (inst.operands[1].isreg) | |
b99bd4ef | 9439 | { |
c19d1205 | 9440 | if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8) |
b99bd4ef | 9441 | { |
c19d1205 ZW |
9442 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
9443 | since a MOV instruction produces unpredictable results. */ | |
9444 | if (inst.instruction == T_OPCODE_MOV_I8) | |
9445 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 9446 | else |
c19d1205 | 9447 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 9448 | |
c19d1205 ZW |
9449 | inst.instruction |= inst.operands[0].reg; |
9450 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
9451 | } |
9452 | else | |
9453 | { | |
c19d1205 ZW |
9454 | if (inst.instruction == T_OPCODE_MOV_I8) |
9455 | inst.instruction = T_OPCODE_MOV_HR; | |
9456 | else | |
9457 | inst.instruction = T_OPCODE_CMP_HR; | |
9458 | do_t_cpy (); | |
b99bd4ef NC |
9459 | } |
9460 | } | |
c19d1205 | 9461 | else |
b99bd4ef | 9462 | { |
c19d1205 ZW |
9463 | constraint (inst.operands[0].reg > 7, |
9464 | _("only lo regs allowed with immediate")); | |
9465 | inst.instruction |= inst.operands[0].reg << 8; | |
9466 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
9467 | } | |
9468 | } | |
b99bd4ef | 9469 | |
c19d1205 ZW |
9470 | static void |
9471 | do_t_mov16 (void) | |
9472 | { | |
b6895b4f PB |
9473 | bfd_vma imm; |
9474 | bfd_boolean top; | |
9475 | ||
9476 | top = (inst.instruction & 0x00800000) != 0; | |
9477 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
9478 | { | |
9479 | constraint (top, _(":lower16: not allowed this instruction")); | |
9480 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
9481 | } | |
9482 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
9483 | { | |
9484 | constraint (!top, _(":upper16: not allowed this instruction")); | |
9485 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
9486 | } | |
9487 | ||
c19d1205 | 9488 | inst.instruction |= inst.operands[0].reg << 8; |
b6895b4f PB |
9489 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
9490 | { | |
9491 | imm = inst.reloc.exp.X_add_number; | |
9492 | inst.instruction |= (imm & 0xf000) << 4; | |
9493 | inst.instruction |= (imm & 0x0800) << 15; | |
9494 | inst.instruction |= (imm & 0x0700) << 4; | |
9495 | inst.instruction |= (imm & 0x00ff); | |
9496 | } | |
c19d1205 | 9497 | } |
b99bd4ef | 9498 | |
c19d1205 ZW |
9499 | static void |
9500 | do_t_mvn_tst (void) | |
9501 | { | |
9502 | if (unified_syntax) | |
9503 | { | |
9504 | int r0off = (inst.instruction == T_MNEM_mvn | |
9505 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
9506 | bfd_boolean narrow; |
9507 | ||
9508 | if (inst.size_req == 4 | |
9509 | || inst.instruction > 0xffff | |
9510 | || inst.operands[1].shifted | |
9511 | || inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
9512 | narrow = FALSE; | |
9513 | else if (inst.instruction == T_MNEM_cmn) | |
9514 | narrow = TRUE; | |
9515 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
9516 | narrow = (current_it_mask == 0); | |
9517 | else | |
9518 | narrow = (current_it_mask != 0); | |
9519 | ||
c19d1205 | 9520 | if (!inst.operands[1].isreg) |
b99bd4ef | 9521 | { |
c19d1205 ZW |
9522 | /* For an immediate, we always generate a 32-bit opcode; |
9523 | section relaxation will shrink it later if possible. */ | |
9524 | if (inst.instruction < 0xffff) | |
9525 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9526 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9527 | inst.instruction |= inst.operands[0].reg << r0off; | |
9528 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 9529 | } |
c19d1205 | 9530 | else |
b99bd4ef | 9531 | { |
c19d1205 | 9532 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 9533 | if (narrow) |
b99bd4ef | 9534 | { |
c19d1205 ZW |
9535 | inst.instruction = THUMB_OP16 (inst.instruction); |
9536 | inst.instruction |= inst.operands[0].reg; | |
9537 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 9538 | } |
c19d1205 | 9539 | else |
b99bd4ef | 9540 | { |
c19d1205 ZW |
9541 | constraint (inst.operands[1].shifted |
9542 | && inst.operands[1].immisreg, | |
9543 | _("shift must be constant")); | |
9544 | if (inst.instruction < 0xffff) | |
9545 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9546 | inst.instruction |= inst.operands[0].reg << r0off; | |
9547 | encode_thumb32_shifted_operand (1); | |
b99bd4ef | 9548 | } |
b99bd4ef NC |
9549 | } |
9550 | } | |
9551 | else | |
9552 | { | |
c19d1205 ZW |
9553 | constraint (inst.instruction > 0xffff |
9554 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
9555 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
9556 | _("unshifted register required")); | |
9557 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
9558 | BAD_HIREG); | |
b99bd4ef | 9559 | |
c19d1205 ZW |
9560 | inst.instruction = THUMB_OP16 (inst.instruction); |
9561 | inst.instruction |= inst.operands[0].reg; | |
9562 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 9563 | } |
b99bd4ef NC |
9564 | } |
9565 | ||
b05fe5cf | 9566 | static void |
c19d1205 | 9567 | do_t_mrs (void) |
b05fe5cf | 9568 | { |
62b3e311 | 9569 | int flags; |
037e8744 JB |
9570 | |
9571 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
9572 | return; | |
9573 | ||
62b3e311 PB |
9574 | flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
9575 | if (flags == 0) | |
9576 | { | |
9577 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m), | |
9578 | _("selected processor does not support " | |
9579 | "requested special purpose register")); | |
9580 | } | |
9581 | else | |
9582 | { | |
9583 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
9584 | _("selected processor does not support " | |
9585 | "requested special purpose register %x")); | |
9586 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
9587 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
9588 | _("'CPSR' or 'SPSR' expected")); | |
9589 | } | |
9590 | ||
c19d1205 | 9591 | inst.instruction |= inst.operands[0].reg << 8; |
62b3e311 PB |
9592 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
9593 | inst.instruction |= inst.operands[1].imm & 0xff; | |
c19d1205 | 9594 | } |
b05fe5cf | 9595 | |
c19d1205 ZW |
9596 | static void |
9597 | do_t_msr (void) | |
9598 | { | |
62b3e311 PB |
9599 | int flags; |
9600 | ||
037e8744 JB |
9601 | if (do_vfp_nsyn_msr () == SUCCESS) |
9602 | return; | |
9603 | ||
c19d1205 ZW |
9604 | constraint (!inst.operands[1].isreg, |
9605 | _("Thumb encoding does not support an immediate here")); | |
62b3e311 PB |
9606 | flags = inst.operands[0].imm; |
9607 | if (flags & ~0xff) | |
9608 | { | |
9609 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
9610 | _("selected processor does not support " | |
9611 | "requested special purpose register")); | |
9612 | } | |
9613 | else | |
9614 | { | |
9615 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m), | |
9616 | _("selected processor does not support " | |
9617 | "requested special purpose register")); | |
9618 | flags |= PSR_f; | |
9619 | } | |
9620 | inst.instruction |= (flags & SPSR_BIT) >> 2; | |
9621 | inst.instruction |= (flags & ~SPSR_BIT) >> 8; | |
9622 | inst.instruction |= (flags & 0xff); | |
c19d1205 ZW |
9623 | inst.instruction |= inst.operands[1].reg << 16; |
9624 | } | |
b05fe5cf | 9625 | |
c19d1205 ZW |
9626 | static void |
9627 | do_t_mul (void) | |
9628 | { | |
9629 | if (!inst.operands[2].present) | |
9630 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 9631 | |
c19d1205 ZW |
9632 | /* There is no 32-bit MULS and no 16-bit MUL. */ |
9633 | if (unified_syntax && inst.instruction == T_MNEM_mul) | |
b05fe5cf | 9634 | { |
c19d1205 ZW |
9635 | inst.instruction = THUMB_OP32 (inst.instruction); |
9636 | inst.instruction |= inst.operands[0].reg << 8; | |
9637 | inst.instruction |= inst.operands[1].reg << 16; | |
9638 | inst.instruction |= inst.operands[2].reg << 0; | |
b05fe5cf | 9639 | } |
c19d1205 | 9640 | else |
b05fe5cf | 9641 | { |
c19d1205 ZW |
9642 | constraint (!unified_syntax |
9643 | && inst.instruction == T_MNEM_muls, BAD_THUMB32); | |
9644 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
9645 | BAD_HIREG); | |
b05fe5cf | 9646 | |
c19d1205 ZW |
9647 | inst.instruction = THUMB_OP16 (inst.instruction); |
9648 | inst.instruction |= inst.operands[0].reg; | |
b05fe5cf | 9649 | |
c19d1205 ZW |
9650 | if (inst.operands[0].reg == inst.operands[1].reg) |
9651 | inst.instruction |= inst.operands[2].reg << 3; | |
9652 | else if (inst.operands[0].reg == inst.operands[2].reg) | |
9653 | inst.instruction |= inst.operands[1].reg << 3; | |
9654 | else | |
9655 | constraint (1, _("dest must overlap one source register")); | |
9656 | } | |
9657 | } | |
b05fe5cf | 9658 | |
c19d1205 ZW |
9659 | static void |
9660 | do_t_mull (void) | |
9661 | { | |
9662 | inst.instruction |= inst.operands[0].reg << 12; | |
9663 | inst.instruction |= inst.operands[1].reg << 8; | |
9664 | inst.instruction |= inst.operands[2].reg << 16; | |
9665 | inst.instruction |= inst.operands[3].reg; | |
b05fe5cf | 9666 | |
c19d1205 ZW |
9667 | if (inst.operands[0].reg == inst.operands[1].reg) |
9668 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9669 | } | |
b05fe5cf | 9670 | |
c19d1205 ZW |
9671 | static void |
9672 | do_t_nop (void) | |
9673 | { | |
9674 | if (unified_syntax) | |
9675 | { | |
9676 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 9677 | { |
c19d1205 ZW |
9678 | inst.instruction = THUMB_OP32 (inst.instruction); |
9679 | inst.instruction |= inst.operands[0].imm; | |
9680 | } | |
9681 | else | |
9682 | { | |
9683 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9684 | inst.instruction |= inst.operands[0].imm << 4; | |
9685 | } | |
9686 | } | |
9687 | else | |
9688 | { | |
9689 | constraint (inst.operands[0].present, | |
9690 | _("Thumb does not support NOP with hints")); | |
9691 | inst.instruction = 0x46c0; | |
9692 | } | |
9693 | } | |
b05fe5cf | 9694 | |
c19d1205 ZW |
9695 | static void |
9696 | do_t_neg (void) | |
9697 | { | |
9698 | if (unified_syntax) | |
9699 | { | |
3d388997 PB |
9700 | bfd_boolean narrow; |
9701 | ||
9702 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
9703 | narrow = (current_it_mask == 0); | |
9704 | else | |
9705 | narrow = (current_it_mask != 0); | |
9706 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
9707 | narrow = FALSE; | |
9708 | if (inst.size_req == 4) | |
9709 | narrow = FALSE; | |
9710 | ||
9711 | if (!narrow) | |
c19d1205 ZW |
9712 | { |
9713 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9714 | inst.instruction |= inst.operands[0].reg << 8; | |
9715 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
9716 | } |
9717 | else | |
9718 | { | |
c19d1205 ZW |
9719 | inst.instruction = THUMB_OP16 (inst.instruction); |
9720 | inst.instruction |= inst.operands[0].reg; | |
9721 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
9722 | } |
9723 | } | |
9724 | else | |
9725 | { | |
c19d1205 ZW |
9726 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
9727 | BAD_HIREG); | |
9728 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
9729 | ||
9730 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9731 | inst.instruction |= inst.operands[0].reg; | |
9732 | inst.instruction |= inst.operands[1].reg << 3; | |
9733 | } | |
9734 | } | |
9735 | ||
9736 | static void | |
9737 | do_t_pkhbt (void) | |
9738 | { | |
9739 | inst.instruction |= inst.operands[0].reg << 8; | |
9740 | inst.instruction |= inst.operands[1].reg << 16; | |
9741 | inst.instruction |= inst.operands[2].reg; | |
9742 | if (inst.operands[3].present) | |
9743 | { | |
9744 | unsigned int val = inst.reloc.exp.X_add_number; | |
9745 | constraint (inst.reloc.exp.X_op != O_constant, | |
9746 | _("expression too complex")); | |
9747 | inst.instruction |= (val & 0x1c) << 10; | |
9748 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 9749 | } |
c19d1205 | 9750 | } |
b05fe5cf | 9751 | |
c19d1205 ZW |
9752 | static void |
9753 | do_t_pkhtb (void) | |
9754 | { | |
9755 | if (!inst.operands[3].present) | |
9756 | inst.instruction &= ~0x00000020; | |
9757 | do_t_pkhbt (); | |
b05fe5cf ZW |
9758 | } |
9759 | ||
c19d1205 ZW |
9760 | static void |
9761 | do_t_pld (void) | |
9762 | { | |
9763 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
9764 | } | |
b05fe5cf | 9765 | |
c19d1205 ZW |
9766 | static void |
9767 | do_t_push_pop (void) | |
b99bd4ef | 9768 | { |
e9f89963 PB |
9769 | unsigned mask; |
9770 | ||
c19d1205 ZW |
9771 | constraint (inst.operands[0].writeback, |
9772 | _("push/pop do not support {reglist}^")); | |
9773 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9774 | _("expression too complex")); | |
b99bd4ef | 9775 | |
e9f89963 PB |
9776 | mask = inst.operands[0].imm; |
9777 | if ((mask & ~0xff) == 0) | |
c19d1205 ZW |
9778 | inst.instruction = THUMB_OP16 (inst.instruction); |
9779 | else if ((inst.instruction == T_MNEM_push | |
e9f89963 | 9780 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 9781 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 9782 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 9783 | { |
c19d1205 ZW |
9784 | inst.instruction = THUMB_OP16 (inst.instruction); |
9785 | inst.instruction |= THUMB_PP_PC_LR; | |
e9f89963 | 9786 | mask &= 0xff; |
c19d1205 ZW |
9787 | } |
9788 | else if (unified_syntax) | |
9789 | { | |
e9f89963 PB |
9790 | if (mask & (1 << 13)) |
9791 | inst.error = _("SP not allowed in register list"); | |
c19d1205 | 9792 | if (inst.instruction == T_MNEM_push) |
b99bd4ef | 9793 | { |
e9f89963 PB |
9794 | if (mask & (1 << 15)) |
9795 | inst.error = _("PC not allowed in register list"); | |
c19d1205 ZW |
9796 | } |
9797 | else | |
9798 | { | |
e9f89963 PB |
9799 | if (mask & (1 << 14) |
9800 | && mask & (1 << 15)) | |
9801 | inst.error = _("LR and PC should not both be in register list"); | |
c19d1205 | 9802 | } |
e9f89963 PB |
9803 | if ((mask & (mask - 1)) == 0) |
9804 | { | |
9805 | /* Single register push/pop implemented as str/ldr. */ | |
9806 | if (inst.instruction == T_MNEM_push) | |
9807 | inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */ | |
9808 | else | |
9809 | inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */ | |
9810 | mask = ffs(mask) - 1; | |
9811 | mask <<= 12; | |
9812 | } | |
9813 | else | |
9814 | inst.instruction = THUMB_OP32 (inst.instruction); | |
c19d1205 ZW |
9815 | } |
9816 | else | |
9817 | { | |
9818 | inst.error = _("invalid register list to push/pop instruction"); | |
9819 | return; | |
9820 | } | |
b99bd4ef | 9821 | |
e9f89963 | 9822 | inst.instruction |= mask; |
c19d1205 | 9823 | } |
b99bd4ef | 9824 | |
c19d1205 ZW |
9825 | static void |
9826 | do_t_rbit (void) | |
9827 | { | |
9828 | inst.instruction |= inst.operands[0].reg << 8; | |
9829 | inst.instruction |= inst.operands[1].reg << 16; | |
9830 | } | |
b99bd4ef | 9831 | |
c19d1205 ZW |
9832 | static void |
9833 | do_t_rev (void) | |
9834 | { | |
9835 | if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
9836 | && inst.size_req != 4) | |
9837 | { | |
9838 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9839 | inst.instruction |= inst.operands[0].reg; | |
9840 | inst.instruction |= inst.operands[1].reg << 3; | |
9841 | } | |
9842 | else if (unified_syntax) | |
9843 | { | |
9844 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9845 | inst.instruction |= inst.operands[0].reg << 8; | |
9846 | inst.instruction |= inst.operands[1].reg << 16; | |
9847 | inst.instruction |= inst.operands[1].reg; | |
9848 | } | |
9849 | else | |
9850 | inst.error = BAD_HIREG; | |
9851 | } | |
b99bd4ef | 9852 | |
c19d1205 ZW |
9853 | static void |
9854 | do_t_rsb (void) | |
9855 | { | |
9856 | int Rd, Rs; | |
b99bd4ef | 9857 | |
c19d1205 ZW |
9858 | Rd = inst.operands[0].reg; |
9859 | Rs = (inst.operands[1].present | |
9860 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9861 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 9862 | |
c19d1205 ZW |
9863 | inst.instruction |= Rd << 8; |
9864 | inst.instruction |= Rs << 16; | |
9865 | if (!inst.operands[2].isreg) | |
9866 | { | |
9867 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9868 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9869 | } | |
9870 | else | |
9871 | encode_thumb32_shifted_operand (2); | |
9872 | } | |
b99bd4ef | 9873 | |
c19d1205 ZW |
9874 | static void |
9875 | do_t_setend (void) | |
9876 | { | |
dfa9f0d5 | 9877 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 ZW |
9878 | if (inst.operands[0].imm) |
9879 | inst.instruction |= 0x8; | |
9880 | } | |
b99bd4ef | 9881 | |
c19d1205 ZW |
9882 | static void |
9883 | do_t_shift (void) | |
9884 | { | |
9885 | if (!inst.operands[1].present) | |
9886 | inst.operands[1].reg = inst.operands[0].reg; | |
9887 | ||
9888 | if (unified_syntax) | |
9889 | { | |
3d388997 PB |
9890 | bfd_boolean narrow; |
9891 | int shift_kind; | |
9892 | ||
9893 | switch (inst.instruction) | |
9894 | { | |
9895 | case T_MNEM_asr: | |
9896 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
9897 | case T_MNEM_lsl: | |
9898 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
9899 | case T_MNEM_lsr: | |
9900 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
9901 | case T_MNEM_ror: | |
9902 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
9903 | default: abort (); | |
9904 | } | |
9905 | ||
9906 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
9907 | narrow = (current_it_mask == 0); | |
9908 | else | |
9909 | narrow = (current_it_mask != 0); | |
9910 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
9911 | narrow = FALSE; | |
9912 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
9913 | narrow = FALSE; | |
9914 | if (inst.operands[2].isreg | |
9915 | && (inst.operands[1].reg != inst.operands[0].reg | |
9916 | || inst.operands[2].reg > 7)) | |
9917 | narrow = FALSE; | |
9918 | if (inst.size_req == 4) | |
9919 | narrow = FALSE; | |
9920 | ||
9921 | if (!narrow) | |
c19d1205 ZW |
9922 | { |
9923 | if (inst.operands[2].isreg) | |
b99bd4ef | 9924 | { |
c19d1205 ZW |
9925 | inst.instruction = THUMB_OP32 (inst.instruction); |
9926 | inst.instruction |= inst.operands[0].reg << 8; | |
9927 | inst.instruction |= inst.operands[1].reg << 16; | |
9928 | inst.instruction |= inst.operands[2].reg; | |
9929 | } | |
9930 | else | |
9931 | { | |
9932 | inst.operands[1].shifted = 1; | |
3d388997 | 9933 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
9934 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
9935 | ? T_MNEM_movs : T_MNEM_mov); | |
9936 | inst.instruction |= inst.operands[0].reg << 8; | |
9937 | encode_thumb32_shifted_operand (1); | |
9938 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
9939 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
9940 | } |
9941 | } | |
9942 | else | |
9943 | { | |
c19d1205 | 9944 | if (inst.operands[2].isreg) |
b99bd4ef | 9945 | { |
3d388997 | 9946 | switch (shift_kind) |
b99bd4ef | 9947 | { |
3d388997 PB |
9948 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
9949 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
9950 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
9951 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 9952 | default: abort (); |
b99bd4ef | 9953 | } |
c19d1205 ZW |
9954 | |
9955 | inst.instruction |= inst.operands[0].reg; | |
9956 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
9957 | } |
9958 | else | |
9959 | { | |
3d388997 | 9960 | switch (shift_kind) |
b99bd4ef | 9961 | { |
3d388997 PB |
9962 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
9963 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
9964 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 9965 | default: abort (); |
b99bd4ef | 9966 | } |
c19d1205 ZW |
9967 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
9968 | inst.instruction |= inst.operands[0].reg; | |
9969 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
9970 | } |
9971 | } | |
c19d1205 ZW |
9972 | } |
9973 | else | |
9974 | { | |
9975 | constraint (inst.operands[0].reg > 7 | |
9976 | || inst.operands[1].reg > 7, BAD_HIREG); | |
9977 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 9978 | |
c19d1205 ZW |
9979 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
9980 | { | |
9981 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
9982 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
9983 | _("source1 and dest must be same register")); | |
b99bd4ef | 9984 | |
c19d1205 ZW |
9985 | switch (inst.instruction) |
9986 | { | |
9987 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
9988 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
9989 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
9990 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
9991 | default: abort (); | |
9992 | } | |
9993 | ||
9994 | inst.instruction |= inst.operands[0].reg; | |
9995 | inst.instruction |= inst.operands[2].reg << 3; | |
9996 | } | |
9997 | else | |
b99bd4ef | 9998 | { |
c19d1205 ZW |
9999 | switch (inst.instruction) |
10000 | { | |
10001 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
10002 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
10003 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
10004 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
10005 | default: abort (); | |
10006 | } | |
10007 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
10008 | inst.instruction |= inst.operands[0].reg; | |
10009 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
10010 | } |
10011 | } | |
b99bd4ef NC |
10012 | } |
10013 | ||
10014 | static void | |
c19d1205 | 10015 | do_t_simd (void) |
b99bd4ef | 10016 | { |
c19d1205 ZW |
10017 | inst.instruction |= inst.operands[0].reg << 8; |
10018 | inst.instruction |= inst.operands[1].reg << 16; | |
10019 | inst.instruction |= inst.operands[2].reg; | |
10020 | } | |
b99bd4ef | 10021 | |
c19d1205 | 10022 | static void |
3eb17e6b | 10023 | do_t_smc (void) |
c19d1205 ZW |
10024 | { |
10025 | unsigned int value = inst.reloc.exp.X_add_number; | |
10026 | constraint (inst.reloc.exp.X_op != O_constant, | |
10027 | _("expression too complex")); | |
10028 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10029 | inst.instruction |= (value & 0xf000) >> 12; | |
10030 | inst.instruction |= (value & 0x0ff0); | |
10031 | inst.instruction |= (value & 0x000f) << 16; | |
10032 | } | |
b99bd4ef | 10033 | |
c19d1205 ZW |
10034 | static void |
10035 | do_t_ssat (void) | |
10036 | { | |
10037 | inst.instruction |= inst.operands[0].reg << 8; | |
10038 | inst.instruction |= inst.operands[1].imm - 1; | |
10039 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 10040 | |
c19d1205 | 10041 | if (inst.operands[3].present) |
b99bd4ef | 10042 | { |
c19d1205 ZW |
10043 | constraint (inst.reloc.exp.X_op != O_constant, |
10044 | _("expression too complex")); | |
b99bd4ef | 10045 | |
c19d1205 | 10046 | if (inst.reloc.exp.X_add_number != 0) |
6189168b | 10047 | { |
c19d1205 ZW |
10048 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
10049 | inst.instruction |= 0x00200000; /* sh bit */ | |
10050 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; | |
10051 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
6189168b | 10052 | } |
c19d1205 | 10053 | inst.reloc.type = BFD_RELOC_UNUSED; |
6189168b | 10054 | } |
b99bd4ef NC |
10055 | } |
10056 | ||
0dd132b6 | 10057 | static void |
c19d1205 | 10058 | do_t_ssat16 (void) |
0dd132b6 | 10059 | { |
c19d1205 ZW |
10060 | inst.instruction |= inst.operands[0].reg << 8; |
10061 | inst.instruction |= inst.operands[1].imm - 1; | |
10062 | inst.instruction |= inst.operands[2].reg << 16; | |
10063 | } | |
0dd132b6 | 10064 | |
c19d1205 ZW |
10065 | static void |
10066 | do_t_strex (void) | |
10067 | { | |
10068 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
10069 | || inst.operands[2].postind || inst.operands[2].writeback | |
10070 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
10071 | || inst.operands[2].negative, | |
01cfc07f | 10072 | BAD_ADDR_MODE); |
0dd132b6 | 10073 | |
c19d1205 ZW |
10074 | inst.instruction |= inst.operands[0].reg << 8; |
10075 | inst.instruction |= inst.operands[1].reg << 12; | |
10076 | inst.instruction |= inst.operands[2].reg << 16; | |
10077 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
10078 | } |
10079 | ||
b99bd4ef | 10080 | static void |
c19d1205 | 10081 | do_t_strexd (void) |
b99bd4ef | 10082 | { |
c19d1205 ZW |
10083 | if (!inst.operands[2].present) |
10084 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 10085 | |
c19d1205 ZW |
10086 | constraint (inst.operands[0].reg == inst.operands[1].reg |
10087 | || inst.operands[0].reg == inst.operands[2].reg | |
10088 | || inst.operands[0].reg == inst.operands[3].reg | |
10089 | || inst.operands[1].reg == inst.operands[2].reg, | |
10090 | BAD_OVERLAP); | |
b99bd4ef | 10091 | |
c19d1205 ZW |
10092 | inst.instruction |= inst.operands[0].reg; |
10093 | inst.instruction |= inst.operands[1].reg << 12; | |
10094 | inst.instruction |= inst.operands[2].reg << 8; | |
10095 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
10096 | } |
10097 | ||
10098 | static void | |
c19d1205 | 10099 | do_t_sxtah (void) |
b99bd4ef | 10100 | { |
c19d1205 ZW |
10101 | inst.instruction |= inst.operands[0].reg << 8; |
10102 | inst.instruction |= inst.operands[1].reg << 16; | |
10103 | inst.instruction |= inst.operands[2].reg; | |
10104 | inst.instruction |= inst.operands[3].imm << 4; | |
10105 | } | |
b99bd4ef | 10106 | |
c19d1205 ZW |
10107 | static void |
10108 | do_t_sxth (void) | |
10109 | { | |
10110 | if (inst.instruction <= 0xffff && inst.size_req != 4 | |
10111 | && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
10112 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) | |
b99bd4ef | 10113 | { |
c19d1205 ZW |
10114 | inst.instruction = THUMB_OP16 (inst.instruction); |
10115 | inst.instruction |= inst.operands[0].reg; | |
10116 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 10117 | } |
c19d1205 | 10118 | else if (unified_syntax) |
b99bd4ef | 10119 | { |
c19d1205 ZW |
10120 | if (inst.instruction <= 0xffff) |
10121 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10122 | inst.instruction |= inst.operands[0].reg << 8; | |
10123 | inst.instruction |= inst.operands[1].reg; | |
10124 | inst.instruction |= inst.operands[2].imm << 4; | |
b99bd4ef | 10125 | } |
c19d1205 | 10126 | else |
b99bd4ef | 10127 | { |
c19d1205 ZW |
10128 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
10129 | _("Thumb encoding does not support rotation")); | |
10130 | constraint (1, BAD_HIREG); | |
b99bd4ef | 10131 | } |
c19d1205 | 10132 | } |
b99bd4ef | 10133 | |
c19d1205 ZW |
10134 | static void |
10135 | do_t_swi (void) | |
10136 | { | |
10137 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
10138 | } | |
b99bd4ef | 10139 | |
92e90b6e PB |
10140 | static void |
10141 | do_t_tb (void) | |
10142 | { | |
10143 | int half; | |
10144 | ||
10145 | half = (inst.instruction & 0x10) != 0; | |
dfa9f0d5 PB |
10146 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
10147 | constraint (inst.operands[0].immisreg, | |
10148 | _("instruction requires register index")); | |
92e90b6e PB |
10149 | constraint (inst.operands[0].imm == 15, |
10150 | _("PC is not a valid index register")); | |
10151 | constraint (!half && inst.operands[0].shifted, | |
10152 | _("instruction does not allow shifted index")); | |
92e90b6e PB |
10153 | inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm; |
10154 | } | |
10155 | ||
c19d1205 ZW |
10156 | static void |
10157 | do_t_usat (void) | |
10158 | { | |
10159 | inst.instruction |= inst.operands[0].reg << 8; | |
10160 | inst.instruction |= inst.operands[1].imm; | |
10161 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 10162 | |
c19d1205 | 10163 | if (inst.operands[3].present) |
b99bd4ef | 10164 | { |
c19d1205 ZW |
10165 | constraint (inst.reloc.exp.X_op != O_constant, |
10166 | _("expression too complex")); | |
10167 | if (inst.reloc.exp.X_add_number != 0) | |
10168 | { | |
10169 | if (inst.operands[3].shift_kind == SHIFT_ASR) | |
10170 | inst.instruction |= 0x00200000; /* sh bit */ | |
b99bd4ef | 10171 | |
c19d1205 ZW |
10172 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; |
10173 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
10174 | } | |
10175 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 10176 | } |
b99bd4ef NC |
10177 | } |
10178 | ||
10179 | static void | |
c19d1205 | 10180 | do_t_usat16 (void) |
b99bd4ef | 10181 | { |
c19d1205 ZW |
10182 | inst.instruction |= inst.operands[0].reg << 8; |
10183 | inst.instruction |= inst.operands[1].imm; | |
10184 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 10185 | } |
c19d1205 | 10186 | |
5287ad62 JB |
10187 | /* Neon instruction encoder helpers. */ |
10188 | ||
10189 | /* Encodings for the different types for various Neon opcodes. */ | |
b99bd4ef | 10190 | |
5287ad62 JB |
10191 | /* An "invalid" code for the following tables. */ |
10192 | #define N_INV -1u | |
10193 | ||
10194 | struct neon_tab_entry | |
b99bd4ef | 10195 | { |
5287ad62 JB |
10196 | unsigned integer; |
10197 | unsigned float_or_poly; | |
10198 | unsigned scalar_or_imm; | |
10199 | }; | |
10200 | ||
10201 | /* Map overloaded Neon opcodes to their respective encodings. */ | |
10202 | #define NEON_ENC_TAB \ | |
10203 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
10204 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
10205 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
10206 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
10207 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
10208 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
10209 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
10210 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
10211 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
10212 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
10213 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
10214 | /* Register variants of the following two instructions are encoded as | |
10215 | vcge / vcgt with the operands reversed. */ \ | |
10216 | X(vclt, 0x0000310, 0x1000e00, 0x1b10200), \ | |
10217 | X(vcle, 0x0000300, 0x1200e00, 0x1b10180), \ | |
10218 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ | |
10219 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
10220 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
10221 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
10222 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
10223 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
10224 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
10225 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
10226 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
10227 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
10228 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
10229 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
10230 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
10231 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
10232 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
10233 | X(veor, 0x1000110, N_INV, N_INV), \ | |
10234 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
10235 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
10236 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
10237 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
10238 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
10239 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
10240 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
10241 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
10242 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
10243 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
10244 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
10245 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
10246 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
10247 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
10248 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
10249 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
10250 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
10251 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
10252 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
10253 | X(vnmla, 0xe000a40, 0xe000b40, N_INV), \ | |
10254 | X(vnmls, 0xe100a40, 0xe100b40, N_INV), \ | |
10255 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ | |
10256 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
10257 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
10258 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV) | |
5287ad62 JB |
10259 | |
10260 | enum neon_opc | |
10261 | { | |
10262 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
10263 | NEON_ENC_TAB | |
10264 | #undef X | |
10265 | }; | |
b99bd4ef | 10266 | |
5287ad62 JB |
10267 | static const struct neon_tab_entry neon_enc_tab[] = |
10268 | { | |
10269 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
10270 | NEON_ENC_TAB | |
10271 | #undef X | |
10272 | }; | |
b99bd4ef | 10273 | |
5287ad62 JB |
10274 | #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer) |
10275 | #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
10276 | #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
10277 | #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
10278 | #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
10279 | #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
10280 | #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
10281 | #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
10282 | #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
037e8744 JB |
10283 | #define NEON_ENC_SINGLE(X) \ |
10284 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) | |
10285 | #define NEON_ENC_DOUBLE(X) \ | |
10286 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) | |
5287ad62 | 10287 | |
037e8744 JB |
10288 | /* Define shapes for instruction operands. The following mnemonic characters |
10289 | are used in this table: | |
5287ad62 | 10290 | |
037e8744 | 10291 | F - VFP S<n> register |
5287ad62 JB |
10292 | D - Neon D<n> register |
10293 | Q - Neon Q<n> register | |
10294 | I - Immediate | |
10295 | S - Scalar | |
10296 | R - ARM register | |
10297 | L - D<n> register list | |
037e8744 JB |
10298 | |
10299 | This table is used to generate various data: | |
10300 | - enumerations of the form NS_DDR to be used as arguments to | |
10301 | neon_select_shape. | |
10302 | - a table classifying shapes into single, double, quad, mixed. | |
10303 | - a table used to drive neon_select_shape. | |
5287ad62 | 10304 | */ |
b99bd4ef | 10305 | |
037e8744 JB |
10306 | #define NEON_SHAPE_DEF \ |
10307 | X(3, (D, D, D), DOUBLE), \ | |
10308 | X(3, (Q, Q, Q), QUAD), \ | |
10309 | X(3, (D, D, I), DOUBLE), \ | |
10310 | X(3, (Q, Q, I), QUAD), \ | |
10311 | X(3, (D, D, S), DOUBLE), \ | |
10312 | X(3, (Q, Q, S), QUAD), \ | |
10313 | X(2, (D, D), DOUBLE), \ | |
10314 | X(2, (Q, Q), QUAD), \ | |
10315 | X(2, (D, S), DOUBLE), \ | |
10316 | X(2, (Q, S), QUAD), \ | |
10317 | X(2, (D, R), DOUBLE), \ | |
10318 | X(2, (Q, R), QUAD), \ | |
10319 | X(2, (D, I), DOUBLE), \ | |
10320 | X(2, (Q, I), QUAD), \ | |
10321 | X(3, (D, L, D), DOUBLE), \ | |
10322 | X(2, (D, Q), MIXED), \ | |
10323 | X(2, (Q, D), MIXED), \ | |
10324 | X(3, (D, Q, I), MIXED), \ | |
10325 | X(3, (Q, D, I), MIXED), \ | |
10326 | X(3, (Q, D, D), MIXED), \ | |
10327 | X(3, (D, Q, Q), MIXED), \ | |
10328 | X(3, (Q, Q, D), MIXED), \ | |
10329 | X(3, (Q, D, S), MIXED), \ | |
10330 | X(3, (D, Q, S), MIXED), \ | |
10331 | X(4, (D, D, D, I), DOUBLE), \ | |
10332 | X(4, (Q, Q, Q, I), QUAD), \ | |
10333 | X(2, (F, F), SINGLE), \ | |
10334 | X(3, (F, F, F), SINGLE), \ | |
10335 | X(2, (F, I), SINGLE), \ | |
10336 | X(2, (F, D), MIXED), \ | |
10337 | X(2, (D, F), MIXED), \ | |
10338 | X(3, (F, F, I), MIXED), \ | |
10339 | X(4, (R, R, F, F), SINGLE), \ | |
10340 | X(4, (F, F, R, R), SINGLE), \ | |
10341 | X(3, (D, R, R), DOUBLE), \ | |
10342 | X(3, (R, R, D), DOUBLE), \ | |
10343 | X(2, (S, R), SINGLE), \ | |
10344 | X(2, (R, S), SINGLE), \ | |
10345 | X(2, (F, R), SINGLE), \ | |
10346 | X(2, (R, F), SINGLE) | |
10347 | ||
10348 | #define S2(A,B) NS_##A##B | |
10349 | #define S3(A,B,C) NS_##A##B##C | |
10350 | #define S4(A,B,C,D) NS_##A##B##C##D | |
10351 | ||
10352 | #define X(N, L, C) S##N L | |
10353 | ||
5287ad62 JB |
10354 | enum neon_shape |
10355 | { | |
037e8744 JB |
10356 | NEON_SHAPE_DEF, |
10357 | NS_NULL | |
5287ad62 | 10358 | }; |
b99bd4ef | 10359 | |
037e8744 JB |
10360 | #undef X |
10361 | #undef S2 | |
10362 | #undef S3 | |
10363 | #undef S4 | |
10364 | ||
10365 | enum neon_shape_class | |
10366 | { | |
10367 | SC_SINGLE, | |
10368 | SC_DOUBLE, | |
10369 | SC_QUAD, | |
10370 | SC_MIXED | |
10371 | }; | |
10372 | ||
10373 | #define X(N, L, C) SC_##C | |
10374 | ||
10375 | static enum neon_shape_class neon_shape_class[] = | |
10376 | { | |
10377 | NEON_SHAPE_DEF | |
10378 | }; | |
10379 | ||
10380 | #undef X | |
10381 | ||
10382 | enum neon_shape_el | |
10383 | { | |
10384 | SE_F, | |
10385 | SE_D, | |
10386 | SE_Q, | |
10387 | SE_I, | |
10388 | SE_S, | |
10389 | SE_R, | |
10390 | SE_L | |
10391 | }; | |
10392 | ||
10393 | /* Register widths of above. */ | |
10394 | static unsigned neon_shape_el_size[] = | |
10395 | { | |
10396 | 32, | |
10397 | 64, | |
10398 | 128, | |
10399 | 0, | |
10400 | 32, | |
10401 | 32, | |
10402 | 0 | |
10403 | }; | |
10404 | ||
10405 | struct neon_shape_info | |
10406 | { | |
10407 | unsigned els; | |
10408 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
10409 | }; | |
10410 | ||
10411 | #define S2(A,B) { SE_##A, SE_##B } | |
10412 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
10413 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
10414 | ||
10415 | #define X(N, L, C) { N, S##N L } | |
10416 | ||
10417 | static struct neon_shape_info neon_shape_tab[] = | |
10418 | { | |
10419 | NEON_SHAPE_DEF | |
10420 | }; | |
10421 | ||
10422 | #undef X | |
10423 | #undef S2 | |
10424 | #undef S3 | |
10425 | #undef S4 | |
10426 | ||
5287ad62 JB |
10427 | /* Bit masks used in type checking given instructions. |
10428 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
10429 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
10430 | set, various other bits can be set as well in order to modify the meaning of | |
10431 | the type constraint. */ | |
10432 | ||
10433 | enum neon_type_mask | |
10434 | { | |
10435 | N_S8 = 0x000001, | |
10436 | N_S16 = 0x000002, | |
10437 | N_S32 = 0x000004, | |
10438 | N_S64 = 0x000008, | |
10439 | N_U8 = 0x000010, | |
10440 | N_U16 = 0x000020, | |
10441 | N_U32 = 0x000040, | |
10442 | N_U64 = 0x000080, | |
10443 | N_I8 = 0x000100, | |
10444 | N_I16 = 0x000200, | |
10445 | N_I32 = 0x000400, | |
10446 | N_I64 = 0x000800, | |
10447 | N_8 = 0x001000, | |
10448 | N_16 = 0x002000, | |
10449 | N_32 = 0x004000, | |
10450 | N_64 = 0x008000, | |
10451 | N_P8 = 0x010000, | |
10452 | N_P16 = 0x020000, | |
10453 | N_F32 = 0x040000, | |
037e8744 JB |
10454 | N_F64 = 0x080000, |
10455 | N_KEY = 0x100000, /* key element (main type specifier). */ | |
10456 | N_EQK = 0x200000, /* given operand has the same type & size as the key. */ | |
10457 | N_VFP = 0x400000, /* VFP mode: operand size must match register width. */ | |
5287ad62 JB |
10458 | N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */ |
10459 | N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */ | |
10460 | N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */ | |
10461 | N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */ | |
10462 | N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */ | |
10463 | N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */ | |
dcbf9037 | 10464 | N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */ |
5287ad62 | 10465 | N_UTYP = 0, |
037e8744 | 10466 | N_MAX_NONSPECIAL = N_F64 |
5287ad62 JB |
10467 | }; |
10468 | ||
dcbf9037 JB |
10469 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
10470 | ||
5287ad62 JB |
10471 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
10472 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
10473 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
10474 | #define N_SUF_32 (N_SU_32 | N_F32) | |
10475 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
10476 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
10477 | ||
10478 | /* Pass this as the first type argument to neon_check_type to ignore types | |
10479 | altogether. */ | |
10480 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
10481 | ||
037e8744 JB |
10482 | /* Select a "shape" for the current instruction (describing register types or |
10483 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
10484 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
10485 | function of operand parsing, so this function doesn't need to be called. | |
10486 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
10487 | |
10488 | static enum neon_shape | |
037e8744 | 10489 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 10490 | { |
037e8744 JB |
10491 | va_list ap; |
10492 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
10493 | |
10494 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
10495 | many arguments we should have, so this makes the assumption that we have | |
10496 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
10497 | true in the future. */ | |
10498 | if (!inst.operands[1].present) | |
10499 | inst.operands[1] = inst.operands[0]; | |
10500 | ||
037e8744 | 10501 | va_start (ap, shape); |
5287ad62 | 10502 | |
037e8744 JB |
10503 | for (; shape != NS_NULL; shape = va_arg (ap, int)) |
10504 | { | |
10505 | unsigned j; | |
10506 | int matches = 1; | |
10507 | ||
10508 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
10509 | { | |
10510 | if (!inst.operands[j].present) | |
10511 | { | |
10512 | matches = 0; | |
10513 | break; | |
10514 | } | |
10515 | ||
10516 | switch (neon_shape_tab[shape].el[j]) | |
10517 | { | |
10518 | case SE_F: | |
10519 | if (!(inst.operands[j].isreg | |
10520 | && inst.operands[j].isvec | |
10521 | && inst.operands[j].issingle | |
10522 | && !inst.operands[j].isquad)) | |
10523 | matches = 0; | |
10524 | break; | |
10525 | ||
10526 | case SE_D: | |
10527 | if (!(inst.operands[j].isreg | |
10528 | && inst.operands[j].isvec | |
10529 | && !inst.operands[j].isquad | |
10530 | && !inst.operands[j].issingle)) | |
10531 | matches = 0; | |
10532 | break; | |
10533 | ||
10534 | case SE_R: | |
10535 | if (!(inst.operands[j].isreg | |
10536 | && !inst.operands[j].isvec)) | |
10537 | matches = 0; | |
10538 | break; | |
10539 | ||
10540 | case SE_Q: | |
10541 | if (!(inst.operands[j].isreg | |
10542 | && inst.operands[j].isvec | |
10543 | && inst.operands[j].isquad | |
10544 | && !inst.operands[j].issingle)) | |
10545 | matches = 0; | |
10546 | break; | |
10547 | ||
10548 | case SE_I: | |
10549 | if (!(!inst.operands[j].isreg | |
10550 | && !inst.operands[j].isscalar)) | |
10551 | matches = 0; | |
10552 | break; | |
10553 | ||
10554 | case SE_S: | |
10555 | if (!(!inst.operands[j].isreg | |
10556 | && inst.operands[j].isscalar)) | |
10557 | matches = 0; | |
10558 | break; | |
10559 | ||
10560 | case SE_L: | |
10561 | break; | |
10562 | } | |
10563 | } | |
10564 | if (matches) | |
5287ad62 | 10565 | break; |
037e8744 | 10566 | } |
5287ad62 | 10567 | |
037e8744 | 10568 | va_end (ap); |
5287ad62 | 10569 | |
037e8744 JB |
10570 | if (shape == NS_NULL && first_shape != NS_NULL) |
10571 | first_error (_("invalid instruction shape")); | |
5287ad62 | 10572 | |
037e8744 JB |
10573 | return shape; |
10574 | } | |
5287ad62 | 10575 | |
037e8744 JB |
10576 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
10577 | means the Q bit should be set). */ | |
10578 | ||
10579 | static int | |
10580 | neon_quad (enum neon_shape shape) | |
10581 | { | |
10582 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 10583 | } |
037e8744 | 10584 | |
5287ad62 JB |
10585 | static void |
10586 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
10587 | unsigned *g_size) | |
10588 | { | |
10589 | /* Allow modification to be made to types which are constrained to be | |
10590 | based on the key element, based on bits set alongside N_EQK. */ | |
10591 | if ((typebits & N_EQK) != 0) | |
10592 | { | |
10593 | if ((typebits & N_HLF) != 0) | |
10594 | *g_size /= 2; | |
10595 | else if ((typebits & N_DBL) != 0) | |
10596 | *g_size *= 2; | |
10597 | if ((typebits & N_SGN) != 0) | |
10598 | *g_type = NT_signed; | |
10599 | else if ((typebits & N_UNS) != 0) | |
10600 | *g_type = NT_unsigned; | |
10601 | else if ((typebits & N_INT) != 0) | |
10602 | *g_type = NT_integer; | |
10603 | else if ((typebits & N_FLT) != 0) | |
10604 | *g_type = NT_float; | |
dcbf9037 JB |
10605 | else if ((typebits & N_SIZ) != 0) |
10606 | *g_type = NT_untyped; | |
5287ad62 JB |
10607 | } |
10608 | } | |
10609 | ||
10610 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" | |
10611 | operand type, i.e. the single type specified in a Neon instruction when it | |
10612 | is the only one given. */ | |
10613 | ||
10614 | static struct neon_type_el | |
10615 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
10616 | { | |
10617 | struct neon_type_el dest = *key; | |
10618 | ||
10619 | assert ((thisarg & N_EQK) != 0); | |
10620 | ||
10621 | neon_modify_type_size (thisarg, &dest.type, &dest.size); | |
10622 | ||
10623 | return dest; | |
10624 | } | |
10625 | ||
10626 | /* Convert Neon type and size into compact bitmask representation. */ | |
10627 | ||
10628 | static enum neon_type_mask | |
10629 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
10630 | { | |
10631 | switch (type) | |
10632 | { | |
10633 | case NT_untyped: | |
10634 | switch (size) | |
10635 | { | |
10636 | case 8: return N_8; | |
10637 | case 16: return N_16; | |
10638 | case 32: return N_32; | |
10639 | case 64: return N_64; | |
10640 | default: ; | |
10641 | } | |
10642 | break; | |
10643 | ||
10644 | case NT_integer: | |
10645 | switch (size) | |
10646 | { | |
10647 | case 8: return N_I8; | |
10648 | case 16: return N_I16; | |
10649 | case 32: return N_I32; | |
10650 | case 64: return N_I64; | |
10651 | default: ; | |
10652 | } | |
10653 | break; | |
10654 | ||
10655 | case NT_float: | |
037e8744 JB |
10656 | switch (size) |
10657 | { | |
10658 | case 32: return N_F32; | |
10659 | case 64: return N_F64; | |
10660 | default: ; | |
10661 | } | |
5287ad62 JB |
10662 | break; |
10663 | ||
10664 | case NT_poly: | |
10665 | switch (size) | |
10666 | { | |
10667 | case 8: return N_P8; | |
10668 | case 16: return N_P16; | |
10669 | default: ; | |
10670 | } | |
10671 | break; | |
10672 | ||
10673 | case NT_signed: | |
10674 | switch (size) | |
10675 | { | |
10676 | case 8: return N_S8; | |
10677 | case 16: return N_S16; | |
10678 | case 32: return N_S32; | |
10679 | case 64: return N_S64; | |
10680 | default: ; | |
10681 | } | |
10682 | break; | |
10683 | ||
10684 | case NT_unsigned: | |
10685 | switch (size) | |
10686 | { | |
10687 | case 8: return N_U8; | |
10688 | case 16: return N_U16; | |
10689 | case 32: return N_U32; | |
10690 | case 64: return N_U64; | |
10691 | default: ; | |
10692 | } | |
10693 | break; | |
10694 | ||
10695 | default: ; | |
10696 | } | |
10697 | ||
10698 | return N_UTYP; | |
10699 | } | |
10700 | ||
10701 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
10702 | handles the case where a single bit is set in the mask. */ | |
10703 | ||
dcbf9037 | 10704 | static int |
5287ad62 JB |
10705 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
10706 | enum neon_type_mask mask) | |
10707 | { | |
dcbf9037 JB |
10708 | if ((mask & N_EQK) != 0) |
10709 | return FAIL; | |
10710 | ||
5287ad62 JB |
10711 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
10712 | *size = 8; | |
dcbf9037 | 10713 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0) |
5287ad62 | 10714 | *size = 16; |
dcbf9037 | 10715 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 10716 | *size = 32; |
037e8744 | 10717 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0) |
5287ad62 | 10718 | *size = 64; |
dcbf9037 JB |
10719 | else |
10720 | return FAIL; | |
10721 | ||
5287ad62 JB |
10722 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
10723 | *type = NT_signed; | |
dcbf9037 | 10724 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 10725 | *type = NT_unsigned; |
dcbf9037 | 10726 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 10727 | *type = NT_integer; |
dcbf9037 | 10728 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 10729 | *type = NT_untyped; |
dcbf9037 | 10730 | else if ((mask & (N_P8 | N_P16)) != 0) |
5287ad62 | 10731 | *type = NT_poly; |
037e8744 | 10732 | else if ((mask & (N_F32 | N_F64)) != 0) |
5287ad62 | 10733 | *type = NT_float; |
dcbf9037 JB |
10734 | else |
10735 | return FAIL; | |
10736 | ||
10737 | return SUCCESS; | |
5287ad62 JB |
10738 | } |
10739 | ||
10740 | /* Modify a bitmask of allowed types. This is only needed for type | |
10741 | relaxation. */ | |
10742 | ||
10743 | static unsigned | |
10744 | modify_types_allowed (unsigned allowed, unsigned mods) | |
10745 | { | |
10746 | unsigned size; | |
10747 | enum neon_el_type type; | |
10748 | unsigned destmask; | |
10749 | int i; | |
10750 | ||
10751 | destmask = 0; | |
10752 | ||
10753 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) | |
10754 | { | |
dcbf9037 JB |
10755 | if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS) |
10756 | { | |
10757 | neon_modify_type_size (mods, &type, &size); | |
10758 | destmask |= type_chk_of_el_type (type, size); | |
10759 | } | |
5287ad62 JB |
10760 | } |
10761 | ||
10762 | return destmask; | |
10763 | } | |
10764 | ||
10765 | /* Check type and return type classification. | |
10766 | The manual states (paraphrase): If one datatype is given, it indicates the | |
10767 | type given in: | |
10768 | - the second operand, if there is one | |
10769 | - the operand, if there is no second operand | |
10770 | - the result, if there are no operands. | |
10771 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
10772 | which is set on a per-instruction basis, which is the one which matters when | |
10773 | only one data type is written. | |
10774 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 10775 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
10776 | |
10777 | static struct neon_type_el | |
10778 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
10779 | { | |
10780 | va_list ap; | |
10781 | unsigned i, pass, key_el = 0; | |
10782 | unsigned types[NEON_MAX_TYPE_ELS]; | |
10783 | enum neon_el_type k_type = NT_invtype; | |
10784 | unsigned k_size = -1u; | |
10785 | struct neon_type_el badtype = {NT_invtype, -1}; | |
10786 | unsigned key_allowed = 0; | |
10787 | ||
10788 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
10789 | Fill in the missing operand here, if it was omitted. */ | |
10790 | if (els > 1 && !inst.operands[1].present) | |
10791 | inst.operands[1] = inst.operands[0]; | |
10792 | ||
10793 | /* Suck up all the varargs. */ | |
10794 | va_start (ap, ns); | |
10795 | for (i = 0; i < els; i++) | |
10796 | { | |
10797 | unsigned thisarg = va_arg (ap, unsigned); | |
10798 | if (thisarg == N_IGNORE_TYPE) | |
10799 | { | |
10800 | va_end (ap); | |
10801 | return badtype; | |
10802 | } | |
10803 | types[i] = thisarg; | |
10804 | if ((thisarg & N_KEY) != 0) | |
10805 | key_el = i; | |
10806 | } | |
10807 | va_end (ap); | |
10808 | ||
dcbf9037 JB |
10809 | if (inst.vectype.elems > 0) |
10810 | for (i = 0; i < els; i++) | |
10811 | if (inst.operands[i].vectype.type != NT_invtype) | |
10812 | { | |
10813 | first_error (_("types specified in both the mnemonic and operands")); | |
10814 | return badtype; | |
10815 | } | |
10816 | ||
5287ad62 JB |
10817 | /* Duplicate inst.vectype elements here as necessary. |
10818 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
10819 | particularly when an insn takes one register and one non-register | |
10820 | operand. */ | |
10821 | if (inst.vectype.elems == 1 && els > 1) | |
10822 | { | |
10823 | unsigned j; | |
10824 | inst.vectype.elems = els; | |
10825 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
10826 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
10827 | if (j != key_el) |
10828 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
10829 | types[j]); | |
10830 | } | |
10831 | else if (inst.vectype.elems == 0 && els > 0) | |
10832 | { | |
10833 | unsigned j; | |
10834 | /* No types were given after the mnemonic, so look for types specified | |
10835 | after each operand. We allow some flexibility here; as long as the | |
10836 | "key" operand has a type, we can infer the others. */ | |
10837 | for (j = 0; j < els; j++) | |
10838 | if (inst.operands[j].vectype.type != NT_invtype) | |
10839 | inst.vectype.el[j] = inst.operands[j].vectype; | |
10840 | ||
10841 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 10842 | { |
dcbf9037 JB |
10843 | for (j = 0; j < els; j++) |
10844 | if (inst.operands[j].vectype.type == NT_invtype) | |
10845 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
10846 | types[j]); | |
10847 | } | |
10848 | else | |
10849 | { | |
10850 | first_error (_("operand types can't be inferred")); | |
10851 | return badtype; | |
5287ad62 JB |
10852 | } |
10853 | } | |
10854 | else if (inst.vectype.elems != els) | |
10855 | { | |
dcbf9037 | 10856 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
10857 | return badtype; |
10858 | } | |
10859 | ||
10860 | for (pass = 0; pass < 2; pass++) | |
10861 | { | |
10862 | for (i = 0; i < els; i++) | |
10863 | { | |
10864 | unsigned thisarg = types[i]; | |
10865 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
10866 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
10867 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
10868 | unsigned g_size = inst.vectype.el[i].size; | |
10869 | ||
10870 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
10871 | integer types if sign-specific variants are unavailable. */ | |
10872 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
10873 | && (types_allowed & N_SU_ALL) == 0) | |
10874 | g_type = NT_integer; | |
10875 | ||
10876 | /* If only untyped args are allowed, decay any more specific types to | |
10877 | them. Some instructions only care about signs for some element | |
10878 | sizes, so handle that properly. */ | |
10879 | if ((g_size == 8 && (types_allowed & N_8) != 0) | |
10880 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
10881 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
10882 | || (g_size == 64 && (types_allowed & N_64) != 0)) | |
10883 | g_type = NT_untyped; | |
10884 | ||
10885 | if (pass == 0) | |
10886 | { | |
10887 | if ((thisarg & N_KEY) != 0) | |
10888 | { | |
10889 | k_type = g_type; | |
10890 | k_size = g_size; | |
10891 | key_allowed = thisarg & ~N_KEY; | |
10892 | } | |
10893 | } | |
10894 | else | |
10895 | { | |
037e8744 JB |
10896 | if ((thisarg & N_VFP) != 0) |
10897 | { | |
10898 | enum neon_shape_el regshape = neon_shape_tab[ns].el[i]; | |
10899 | unsigned regwidth = neon_shape_el_size[regshape], match; | |
10900 | ||
10901 | /* In VFP mode, operands must match register widths. If we | |
10902 | have a key operand, use its width, else use the width of | |
10903 | the current operand. */ | |
10904 | if (k_size != -1u) | |
10905 | match = k_size; | |
10906 | else | |
10907 | match = g_size; | |
10908 | ||
10909 | if (regwidth != match) | |
10910 | { | |
10911 | first_error (_("operand size must match register width")); | |
10912 | return badtype; | |
10913 | } | |
10914 | } | |
10915 | ||
5287ad62 JB |
10916 | if ((thisarg & N_EQK) == 0) |
10917 | { | |
10918 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
10919 | ||
10920 | if ((given_type & types_allowed) == 0) | |
10921 | { | |
dcbf9037 | 10922 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
10923 | return badtype; |
10924 | } | |
10925 | } | |
10926 | else | |
10927 | { | |
10928 | enum neon_el_type mod_k_type = k_type; | |
10929 | unsigned mod_k_size = k_size; | |
10930 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
10931 | if (g_type != mod_k_type || g_size != mod_k_size) | |
10932 | { | |
dcbf9037 | 10933 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
10934 | return badtype; |
10935 | } | |
10936 | } | |
10937 | } | |
10938 | } | |
10939 | } | |
10940 | ||
10941 | return inst.vectype.el[key_el]; | |
10942 | } | |
10943 | ||
037e8744 | 10944 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 10945 | |
037e8744 JB |
10946 | /* Thumb VFP instructions have 0xE in the condition field. */ |
10947 | ||
10948 | static void | |
10949 | do_vfp_cond_or_thumb (void) | |
5287ad62 JB |
10950 | { |
10951 | if (thumb_mode) | |
037e8744 | 10952 | inst.instruction |= 0xe0000000; |
5287ad62 | 10953 | else |
037e8744 | 10954 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
10955 | } |
10956 | ||
037e8744 JB |
10957 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
10958 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
10959 | etc. It is assumed that operand parsing has already been done, and that the | |
10960 | operands are in the form expected by the given opcode (this isn't necessarily | |
10961 | the same as the form in which they were parsed, hence some massaging must | |
10962 | take place before this function is called). | |
10963 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 10964 | |
037e8744 JB |
10965 | static void |
10966 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 10967 | { |
037e8744 JB |
10968 | const struct asm_opcode *opcode; |
10969 | ||
10970 | opcode = hash_find (arm_ops_hsh, opname); | |
5287ad62 | 10971 | |
037e8744 JB |
10972 | if (!opcode) |
10973 | abort (); | |
5287ad62 | 10974 | |
037e8744 JB |
10975 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
10976 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
10977 | _(BAD_FPU)); | |
5287ad62 | 10978 | |
037e8744 JB |
10979 | if (thumb_mode) |
10980 | { | |
10981 | inst.instruction = opcode->tvalue; | |
10982 | opcode->tencode (); | |
10983 | } | |
10984 | else | |
10985 | { | |
10986 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
10987 | opcode->aencode (); | |
10988 | } | |
10989 | } | |
5287ad62 JB |
10990 | |
10991 | static void | |
037e8744 | 10992 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 10993 | { |
037e8744 JB |
10994 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
10995 | ||
10996 | if (rs == NS_FFF) | |
10997 | { | |
10998 | if (is_add) | |
10999 | do_vfp_nsyn_opcode ("fadds"); | |
11000 | else | |
11001 | do_vfp_nsyn_opcode ("fsubs"); | |
11002 | } | |
11003 | else | |
11004 | { | |
11005 | if (is_add) | |
11006 | do_vfp_nsyn_opcode ("faddd"); | |
11007 | else | |
11008 | do_vfp_nsyn_opcode ("fsubd"); | |
11009 | } | |
11010 | } | |
11011 | ||
11012 | /* Check operand types to see if this is a VFP instruction, and if so call | |
11013 | PFN (). */ | |
11014 | ||
11015 | static int | |
11016 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
11017 | { | |
11018 | enum neon_shape rs; | |
11019 | struct neon_type_el et; | |
11020 | ||
11021 | switch (args) | |
11022 | { | |
11023 | case 2: | |
11024 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
11025 | et = neon_check_type (2, rs, | |
11026 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
11027 | break; | |
11028 | ||
11029 | case 3: | |
11030 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
11031 | et = neon_check_type (3, rs, | |
11032 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
11033 | break; | |
11034 | ||
11035 | default: | |
11036 | abort (); | |
11037 | } | |
11038 | ||
11039 | if (et.type != NT_invtype) | |
11040 | { | |
11041 | pfn (rs); | |
11042 | return SUCCESS; | |
11043 | } | |
11044 | else | |
11045 | inst.error = NULL; | |
11046 | ||
11047 | return FAIL; | |
11048 | } | |
11049 | ||
11050 | static void | |
11051 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
11052 | { | |
11053 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
11054 | ||
11055 | if (rs == NS_FFF) | |
11056 | { | |
11057 | if (is_mla) | |
11058 | do_vfp_nsyn_opcode ("fmacs"); | |
11059 | else | |
11060 | do_vfp_nsyn_opcode ("fmscs"); | |
11061 | } | |
11062 | else | |
11063 | { | |
11064 | if (is_mla) | |
11065 | do_vfp_nsyn_opcode ("fmacd"); | |
11066 | else | |
11067 | do_vfp_nsyn_opcode ("fmscd"); | |
11068 | } | |
11069 | } | |
11070 | ||
11071 | static void | |
11072 | do_vfp_nsyn_mul (enum neon_shape rs) | |
11073 | { | |
11074 | if (rs == NS_FFF) | |
11075 | do_vfp_nsyn_opcode ("fmuls"); | |
11076 | else | |
11077 | do_vfp_nsyn_opcode ("fmuld"); | |
11078 | } | |
11079 | ||
11080 | static void | |
11081 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
11082 | { | |
11083 | int is_neg = (inst.instruction & 0x80) != 0; | |
11084 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
11085 | ||
11086 | if (rs == NS_FF) | |
11087 | { | |
11088 | if (is_neg) | |
11089 | do_vfp_nsyn_opcode ("fnegs"); | |
11090 | else | |
11091 | do_vfp_nsyn_opcode ("fabss"); | |
11092 | } | |
11093 | else | |
11094 | { | |
11095 | if (is_neg) | |
11096 | do_vfp_nsyn_opcode ("fnegd"); | |
11097 | else | |
11098 | do_vfp_nsyn_opcode ("fabsd"); | |
11099 | } | |
11100 | } | |
11101 | ||
11102 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
11103 | insns belong to Neon, and are handled elsewhere. */ | |
11104 | ||
11105 | static void | |
11106 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
11107 | { | |
11108 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
11109 | if (is_ldm) | |
11110 | { | |
11111 | if (is_dbmode) | |
11112 | do_vfp_nsyn_opcode ("fldmdbs"); | |
11113 | else | |
11114 | do_vfp_nsyn_opcode ("fldmias"); | |
11115 | } | |
11116 | else | |
11117 | { | |
11118 | if (is_dbmode) | |
11119 | do_vfp_nsyn_opcode ("fstmdbs"); | |
11120 | else | |
11121 | do_vfp_nsyn_opcode ("fstmias"); | |
11122 | } | |
11123 | } | |
11124 | ||
037e8744 JB |
11125 | static void |
11126 | do_vfp_nsyn_sqrt (void) | |
11127 | { | |
11128 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
11129 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
11130 | ||
11131 | if (rs == NS_FF) | |
11132 | do_vfp_nsyn_opcode ("fsqrts"); | |
11133 | else | |
11134 | do_vfp_nsyn_opcode ("fsqrtd"); | |
11135 | } | |
11136 | ||
11137 | static void | |
11138 | do_vfp_nsyn_div (void) | |
11139 | { | |
11140 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
11141 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
11142 | N_F32 | N_F64 | N_KEY | N_VFP); | |
11143 | ||
11144 | if (rs == NS_FFF) | |
11145 | do_vfp_nsyn_opcode ("fdivs"); | |
11146 | else | |
11147 | do_vfp_nsyn_opcode ("fdivd"); | |
11148 | } | |
11149 | ||
11150 | static void | |
11151 | do_vfp_nsyn_nmul (void) | |
11152 | { | |
11153 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
11154 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
11155 | N_F32 | N_F64 | N_KEY | N_VFP); | |
11156 | ||
11157 | if (rs == NS_FFF) | |
11158 | { | |
11159 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
11160 | do_vfp_sp_dyadic (); | |
11161 | } | |
11162 | else | |
11163 | { | |
11164 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
11165 | do_vfp_dp_rd_rn_rm (); | |
11166 | } | |
11167 | do_vfp_cond_or_thumb (); | |
11168 | } | |
11169 | ||
11170 | static void | |
11171 | do_vfp_nsyn_cmp (void) | |
11172 | { | |
11173 | if (inst.operands[1].isreg) | |
11174 | { | |
11175 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
11176 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
11177 | ||
11178 | if (rs == NS_FF) | |
11179 | { | |
11180 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
11181 | do_vfp_sp_monadic (); | |
11182 | } | |
11183 | else | |
11184 | { | |
11185 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
11186 | do_vfp_dp_rd_rm (); | |
11187 | } | |
11188 | } | |
11189 | else | |
11190 | { | |
11191 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
11192 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
11193 | ||
11194 | switch (inst.instruction & 0x0fffffff) | |
11195 | { | |
11196 | case N_MNEM_vcmp: | |
11197 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
11198 | break; | |
11199 | case N_MNEM_vcmpe: | |
11200 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
11201 | break; | |
11202 | default: | |
11203 | abort (); | |
11204 | } | |
11205 | ||
11206 | if (rs == NS_FI) | |
11207 | { | |
11208 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
11209 | do_vfp_sp_compare_z (); | |
11210 | } | |
11211 | else | |
11212 | { | |
11213 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
11214 | do_vfp_dp_rd (); | |
11215 | } | |
11216 | } | |
11217 | do_vfp_cond_or_thumb (); | |
11218 | } | |
11219 | ||
11220 | static void | |
11221 | nsyn_insert_sp (void) | |
11222 | { | |
11223 | inst.operands[1] = inst.operands[0]; | |
11224 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
11225 | inst.operands[0].reg = 13; | |
11226 | inst.operands[0].isreg = 1; | |
11227 | inst.operands[0].writeback = 1; | |
11228 | inst.operands[0].present = 1; | |
11229 | } | |
11230 | ||
11231 | static void | |
11232 | do_vfp_nsyn_push (void) | |
11233 | { | |
11234 | nsyn_insert_sp (); | |
11235 | if (inst.operands[1].issingle) | |
11236 | do_vfp_nsyn_opcode ("fstmdbs"); | |
11237 | else | |
11238 | do_vfp_nsyn_opcode ("fstmdbd"); | |
11239 | } | |
11240 | ||
11241 | static void | |
11242 | do_vfp_nsyn_pop (void) | |
11243 | { | |
11244 | nsyn_insert_sp (); | |
11245 | if (inst.operands[1].issingle) | |
11246 | do_vfp_nsyn_opcode ("fldmdbs"); | |
11247 | else | |
11248 | do_vfp_nsyn_opcode ("fldmdbd"); | |
11249 | } | |
11250 | ||
11251 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
11252 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
11253 | ||
11254 | static unsigned | |
11255 | neon_dp_fixup (unsigned i) | |
11256 | { | |
11257 | if (thumb_mode) | |
11258 | { | |
11259 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
11260 | if (i & (1 << 24)) | |
11261 | i |= 1 << 28; | |
11262 | ||
11263 | i &= ~(1 << 24); | |
11264 | ||
11265 | i |= 0xef000000; | |
11266 | } | |
11267 | else | |
11268 | i |= 0xf2000000; | |
11269 | ||
11270 | return i; | |
11271 | } | |
11272 | ||
11273 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
11274 | (0, 1, 2, 3). */ | |
11275 | ||
11276 | static unsigned | |
11277 | neon_logbits (unsigned x) | |
11278 | { | |
11279 | return ffs (x) - 4; | |
11280 | } | |
11281 | ||
11282 | #define LOW4(R) ((R) & 0xf) | |
11283 | #define HI1(R) (((R) >> 4) & 1) | |
11284 | ||
11285 | /* Encode insns with bit pattern: | |
11286 | ||
11287 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
11288 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
11289 | ||
11290 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a | |
11291 | different meaning for some instruction. */ | |
11292 | ||
11293 | static void | |
11294 | neon_three_same (int isquad, int ubit, int size) | |
11295 | { | |
11296 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11297 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11298 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
11299 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
11300 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
11301 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
11302 | inst.instruction |= (isquad != 0) << 6; | |
11303 | inst.instruction |= (ubit != 0) << 24; | |
11304 | if (size != -1) | |
11305 | inst.instruction |= neon_logbits (size) << 20; | |
11306 | ||
11307 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11308 | } | |
11309 | ||
11310 | /* Encode instructions of the form: | |
11311 | ||
11312 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
11313 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
11314 | |
11315 | Don't write size if SIZE == -1. */ | |
11316 | ||
11317 | static void | |
11318 | neon_two_same (int qbit, int ubit, int size) | |
11319 | { | |
11320 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11321 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11322 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11323 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
11324 | inst.instruction |= (qbit != 0) << 6; | |
11325 | inst.instruction |= (ubit != 0) << 24; | |
11326 | ||
11327 | if (size != -1) | |
11328 | inst.instruction |= neon_logbits (size) << 18; | |
11329 | ||
11330 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11331 | } | |
11332 | ||
11333 | /* Neon instruction encoders, in approximate order of appearance. */ | |
11334 | ||
11335 | static void | |
11336 | do_neon_dyadic_i_su (void) | |
11337 | { | |
037e8744 | 11338 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11339 | struct neon_type_el et = neon_check_type (3, rs, |
11340 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 11341 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11342 | } |
11343 | ||
11344 | static void | |
11345 | do_neon_dyadic_i64_su (void) | |
11346 | { | |
037e8744 | 11347 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11348 | struct neon_type_el et = neon_check_type (3, rs, |
11349 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 11350 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11351 | } |
11352 | ||
11353 | static void | |
11354 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
11355 | unsigned immbits) | |
11356 | { | |
11357 | unsigned size = et.size >> 3; | |
11358 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11359 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11360 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11361 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
11362 | inst.instruction |= (isquad != 0) << 6; | |
11363 | inst.instruction |= immbits << 16; | |
11364 | inst.instruction |= (size >> 3) << 7; | |
11365 | inst.instruction |= (size & 0x7) << 19; | |
11366 | if (write_ubit) | |
11367 | inst.instruction |= (uval != 0) << 24; | |
11368 | ||
11369 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11370 | } | |
11371 | ||
11372 | static void | |
11373 | do_neon_shl_imm (void) | |
11374 | { | |
11375 | if (!inst.operands[2].isreg) | |
11376 | { | |
037e8744 | 11377 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11378 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
11379 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 11380 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
11381 | } |
11382 | else | |
11383 | { | |
037e8744 | 11384 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11385 | struct neon_type_el et = neon_check_type (3, rs, |
11386 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
11387 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11388 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11389 | } |
11390 | } | |
11391 | ||
11392 | static void | |
11393 | do_neon_qshl_imm (void) | |
11394 | { | |
11395 | if (!inst.operands[2].isreg) | |
11396 | { | |
037e8744 | 11397 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
11398 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
11399 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 11400 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
11401 | inst.operands[2].imm); |
11402 | } | |
11403 | else | |
11404 | { | |
037e8744 | 11405 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11406 | struct neon_type_el et = neon_check_type (3, rs, |
11407 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
11408 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11409 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
11410 | } |
11411 | } | |
11412 | ||
11413 | static int | |
11414 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
11415 | { | |
036dc3f7 PB |
11416 | /* Handle .I8 pseudo-instructions. */ |
11417 | if (size == 8) | |
5287ad62 | 11418 | { |
5287ad62 JB |
11419 | /* Unfortunately, this will make everything apart from zero out-of-range. |
11420 | FIXME is this the intended semantics? There doesn't seem much point in | |
11421 | accepting .I8 if so. */ | |
11422 | immediate |= immediate << 8; | |
11423 | size = 16; | |
036dc3f7 PB |
11424 | } |
11425 | ||
11426 | if (size >= 32) | |
11427 | { | |
11428 | if (immediate == (immediate & 0x000000ff)) | |
11429 | { | |
11430 | *immbits = immediate; | |
11431 | return 0x1; | |
11432 | } | |
11433 | else if (immediate == (immediate & 0x0000ff00)) | |
11434 | { | |
11435 | *immbits = immediate >> 8; | |
11436 | return 0x3; | |
11437 | } | |
11438 | else if (immediate == (immediate & 0x00ff0000)) | |
11439 | { | |
11440 | *immbits = immediate >> 16; | |
11441 | return 0x5; | |
11442 | } | |
11443 | else if (immediate == (immediate & 0xff000000)) | |
11444 | { | |
11445 | *immbits = immediate >> 24; | |
11446 | return 0x7; | |
11447 | } | |
11448 | if ((immediate & 0xffff) != (immediate >> 16)) | |
11449 | goto bad_immediate; | |
11450 | immediate &= 0xffff; | |
5287ad62 JB |
11451 | } |
11452 | ||
11453 | if (immediate == (immediate & 0x000000ff)) | |
11454 | { | |
11455 | *immbits = immediate; | |
036dc3f7 | 11456 | return 0x9; |
5287ad62 JB |
11457 | } |
11458 | else if (immediate == (immediate & 0x0000ff00)) | |
11459 | { | |
11460 | *immbits = immediate >> 8; | |
036dc3f7 | 11461 | return 0xb; |
5287ad62 JB |
11462 | } |
11463 | ||
11464 | bad_immediate: | |
dcbf9037 | 11465 | first_error (_("immediate value out of range")); |
5287ad62 JB |
11466 | return FAIL; |
11467 | } | |
11468 | ||
11469 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
11470 | A, B, C, D. */ | |
11471 | ||
11472 | static int | |
11473 | neon_bits_same_in_bytes (unsigned imm) | |
11474 | { | |
11475 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
11476 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
11477 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
11478 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
11479 | } | |
11480 | ||
11481 | /* For immediate of above form, return 0bABCD. */ | |
11482 | ||
11483 | static unsigned | |
11484 | neon_squash_bits (unsigned imm) | |
11485 | { | |
11486 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
11487 | | ((imm & 0x01000000) >> 21); | |
11488 | } | |
11489 | ||
136da414 | 11490 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
11491 | |
11492 | static unsigned | |
11493 | neon_qfloat_bits (unsigned imm) | |
11494 | { | |
136da414 | 11495 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
11496 | } |
11497 | ||
11498 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
11499 | the instruction. *OP is passed as the initial value of the op field, and | |
11500 | may be set to a different value depending on the constant (i.e. | |
11501 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
036dc3f7 PB |
11502 | MVN). If the immediate looks like a repeated parttern then also |
11503 | try smaller element sizes. */ | |
5287ad62 JB |
11504 | |
11505 | static int | |
11506 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, unsigned *immbits, | |
136da414 | 11507 | int *op, int size, enum neon_el_type type) |
5287ad62 | 11508 | { |
136da414 JB |
11509 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
11510 | { | |
11511 | if (size != 32 || *op == 1) | |
11512 | return FAIL; | |
11513 | *immbits = neon_qfloat_bits (immlo); | |
11514 | return 0xf; | |
11515 | } | |
036dc3f7 PB |
11516 | |
11517 | if (size == 64) | |
5287ad62 | 11518 | { |
036dc3f7 PB |
11519 | if (neon_bits_same_in_bytes (immhi) |
11520 | && neon_bits_same_in_bytes (immlo)) | |
11521 | { | |
11522 | if (*op == 1) | |
11523 | return FAIL; | |
11524 | *immbits = (neon_squash_bits (immhi) << 4) | |
11525 | | neon_squash_bits (immlo); | |
11526 | *op = 1; | |
11527 | return 0xe; | |
11528 | } | |
11529 | ||
11530 | if (immhi != immlo) | |
11531 | return FAIL; | |
5287ad62 | 11532 | } |
036dc3f7 PB |
11533 | |
11534 | if (size >= 32) | |
5287ad62 | 11535 | { |
036dc3f7 PB |
11536 | if (immlo == (immlo & 0x000000ff)) |
11537 | { | |
11538 | *immbits = immlo; | |
11539 | return 0x0; | |
11540 | } | |
11541 | else if (immlo == (immlo & 0x0000ff00)) | |
11542 | { | |
11543 | *immbits = immlo >> 8; | |
11544 | return 0x2; | |
11545 | } | |
11546 | else if (immlo == (immlo & 0x00ff0000)) | |
11547 | { | |
11548 | *immbits = immlo >> 16; | |
11549 | return 0x4; | |
11550 | } | |
11551 | else if (immlo == (immlo & 0xff000000)) | |
11552 | { | |
11553 | *immbits = immlo >> 24; | |
11554 | return 0x6; | |
11555 | } | |
11556 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
11557 | { | |
11558 | *immbits = (immlo >> 8) & 0xff; | |
11559 | return 0xc; | |
11560 | } | |
11561 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
11562 | { | |
11563 | *immbits = (immlo >> 16) & 0xff; | |
11564 | return 0xd; | |
11565 | } | |
11566 | ||
11567 | if ((immlo & 0xffff) != (immlo >> 16)) | |
11568 | return FAIL; | |
11569 | immlo &= 0xffff; | |
5287ad62 | 11570 | } |
036dc3f7 PB |
11571 | |
11572 | if (size >= 16) | |
5287ad62 | 11573 | { |
036dc3f7 PB |
11574 | if (immlo == (immlo & 0x000000ff)) |
11575 | { | |
11576 | *immbits = immlo; | |
11577 | return 0x8; | |
11578 | } | |
11579 | else if (immlo == (immlo & 0x0000ff00)) | |
11580 | { | |
11581 | *immbits = immlo >> 8; | |
11582 | return 0xa; | |
11583 | } | |
11584 | ||
11585 | if ((immlo & 0xff) != (immlo >> 8)) | |
11586 | return FAIL; | |
11587 | immlo &= 0xff; | |
5287ad62 | 11588 | } |
036dc3f7 PB |
11589 | |
11590 | if (immlo == (immlo & 0x000000ff)) | |
5287ad62 | 11591 | { |
036dc3f7 PB |
11592 | /* Don't allow MVN with 8-bit immediate. */ |
11593 | if (*op == 1) | |
11594 | return FAIL; | |
11595 | *immbits = immlo; | |
11596 | return 0xe; | |
5287ad62 | 11597 | } |
5287ad62 JB |
11598 | |
11599 | return FAIL; | |
11600 | } | |
11601 | ||
11602 | /* Write immediate bits [7:0] to the following locations: | |
11603 | ||
11604 | |28/24|23 19|18 16|15 4|3 0| | |
11605 | | 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| | |
11606 | ||
11607 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
11608 | ||
11609 | static void | |
11610 | neon_write_immbits (unsigned immbits) | |
11611 | { | |
11612 | inst.instruction |= immbits & 0xf; | |
11613 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
11614 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
11615 | } | |
11616 | ||
11617 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
11618 | ||
11619 | static void | |
11620 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
11621 | { | |
11622 | unsigned immlo = xlo ? *xlo : 0; | |
11623 | unsigned immhi = xhi ? *xhi : 0; | |
11624 | ||
11625 | switch (size) | |
11626 | { | |
11627 | case 8: | |
11628 | immlo = (~immlo) & 0xff; | |
11629 | break; | |
11630 | ||
11631 | case 16: | |
11632 | immlo = (~immlo) & 0xffff; | |
11633 | break; | |
11634 | ||
11635 | case 64: | |
11636 | immhi = (~immhi) & 0xffffffff; | |
11637 | /* fall through. */ | |
11638 | ||
11639 | case 32: | |
11640 | immlo = (~immlo) & 0xffffffff; | |
11641 | break; | |
11642 | ||
11643 | default: | |
11644 | abort (); | |
11645 | } | |
11646 | ||
11647 | if (xlo) | |
11648 | *xlo = immlo; | |
11649 | ||
11650 | if (xhi) | |
11651 | *xhi = immhi; | |
11652 | } | |
11653 | ||
11654 | static void | |
11655 | do_neon_logic (void) | |
11656 | { | |
11657 | if (inst.operands[2].present && inst.operands[2].isreg) | |
11658 | { | |
037e8744 | 11659 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
11660 | neon_check_type (3, rs, N_IGNORE_TYPE); |
11661 | /* U bit and size field were set as part of the bitmask. */ | |
11662 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11663 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11664 | } |
11665 | else | |
11666 | { | |
037e8744 JB |
11667 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
11668 | struct neon_type_el et = neon_check_type (2, rs, | |
11669 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 JB |
11670 | enum neon_opc opcode = inst.instruction & 0x0fffffff; |
11671 | unsigned immbits; | |
11672 | int cmode; | |
11673 | ||
11674 | if (et.type == NT_invtype) | |
11675 | return; | |
11676 | ||
11677 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
11678 | ||
036dc3f7 PB |
11679 | immbits = inst.operands[1].imm; |
11680 | if (et.size == 64) | |
11681 | { | |
11682 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
11683 | pattern. */ | |
11684 | if (immbits != (inst.operands[1].regisimm ? | |
11685 | inst.operands[1].reg : 0)) | |
11686 | { | |
11687 | /* Set immbits to an invalid constant. */ | |
11688 | immbits = 0xdeadbeef; | |
11689 | } | |
11690 | } | |
11691 | ||
5287ad62 JB |
11692 | switch (opcode) |
11693 | { | |
11694 | case N_MNEM_vbic: | |
036dc3f7 | 11695 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 JB |
11696 | break; |
11697 | ||
11698 | case N_MNEM_vorr: | |
036dc3f7 | 11699 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 JB |
11700 | break; |
11701 | ||
11702 | case N_MNEM_vand: | |
11703 | /* Pseudo-instruction for VBIC. */ | |
5287ad62 JB |
11704 | neon_invert_size (&immbits, 0, et.size); |
11705 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
11706 | break; | |
11707 | ||
11708 | case N_MNEM_vorn: | |
11709 | /* Pseudo-instruction for VORR. */ | |
5287ad62 JB |
11710 | neon_invert_size (&immbits, 0, et.size); |
11711 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
11712 | break; | |
11713 | ||
11714 | default: | |
11715 | abort (); | |
11716 | } | |
11717 | ||
11718 | if (cmode == FAIL) | |
11719 | return; | |
11720 | ||
037e8744 | 11721 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
11722 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
11723 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11724 | inst.instruction |= cmode << 8; | |
11725 | neon_write_immbits (immbits); | |
11726 | ||
11727 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11728 | } | |
11729 | } | |
11730 | ||
11731 | static void | |
11732 | do_neon_bitfield (void) | |
11733 | { | |
037e8744 | 11734 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 11735 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 11736 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11737 | } |
11738 | ||
11739 | static void | |
dcbf9037 JB |
11740 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
11741 | unsigned destbits) | |
5287ad62 | 11742 | { |
037e8744 | 11743 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
11744 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
11745 | types | N_KEY); | |
5287ad62 JB |
11746 | if (et.type == NT_float) |
11747 | { | |
11748 | inst.instruction = NEON_ENC_FLOAT (inst.instruction); | |
037e8744 | 11749 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
11750 | } |
11751 | else | |
11752 | { | |
11753 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 11754 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
11755 | } |
11756 | } | |
11757 | ||
11758 | static void | |
11759 | do_neon_dyadic_if_su (void) | |
11760 | { | |
dcbf9037 | 11761 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
11762 | } |
11763 | ||
11764 | static void | |
11765 | do_neon_dyadic_if_su_d (void) | |
11766 | { | |
11767 | /* This version only allow D registers, but that constraint is enforced during | |
11768 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 11769 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
11770 | } |
11771 | ||
5287ad62 JB |
11772 | static void |
11773 | do_neon_dyadic_if_i_d (void) | |
11774 | { | |
428e3f1f PB |
11775 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
11776 | affected if we specify unsigned args. */ | |
11777 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
11778 | } |
11779 | ||
037e8744 JB |
11780 | enum vfp_or_neon_is_neon_bits |
11781 | { | |
11782 | NEON_CHECK_CC = 1, | |
11783 | NEON_CHECK_ARCH = 2 | |
11784 | }; | |
11785 | ||
11786 | /* Call this function if an instruction which may have belonged to the VFP or | |
11787 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
11788 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
11789 | things: | |
11790 | ||
11791 | - Make sure the user hasn't attempted to make a Neon instruction | |
11792 | conditional. | |
11793 | - Alter the value in the condition code field if necessary. | |
11794 | - Make sure that the arch supports Neon instructions. | |
11795 | ||
11796 | Which of these operations take place depends on bits from enum | |
11797 | vfp_or_neon_is_neon_bits. | |
11798 | ||
11799 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
11800 | current instruction's condition is COND_ALWAYS, the condition field is | |
11801 | changed to inst.uncond_value. This is necessary because instructions shared | |
11802 | between VFP and Neon may be conditional for the VFP variants only, and the | |
11803 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
11804 | ||
11805 | static int | |
11806 | vfp_or_neon_is_neon (unsigned check) | |
11807 | { | |
11808 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
11809 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
11810 | { | |
11811 | if (inst.cond != COND_ALWAYS) | |
11812 | { | |
11813 | first_error (_(BAD_COND)); | |
11814 | return FAIL; | |
11815 | } | |
11816 | if (inst.uncond_value != -1) | |
11817 | inst.instruction |= inst.uncond_value << 28; | |
11818 | } | |
11819 | ||
11820 | if ((check & NEON_CHECK_ARCH) | |
11821 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
11822 | { | |
11823 | first_error (_(BAD_FPU)); | |
11824 | return FAIL; | |
11825 | } | |
11826 | ||
11827 | return SUCCESS; | |
11828 | } | |
11829 | ||
5287ad62 JB |
11830 | static void |
11831 | do_neon_addsub_if_i (void) | |
11832 | { | |
037e8744 JB |
11833 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
11834 | return; | |
11835 | ||
11836 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
11837 | return; | |
11838 | ||
5287ad62 JB |
11839 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
11840 | affected if we specify unsigned args. */ | |
dcbf9037 | 11841 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
11842 | } |
11843 | ||
11844 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
11845 | result to be: | |
11846 | V<op> A,B (A is operand 0, B is operand 2) | |
11847 | to mean: | |
11848 | V<op> A,B,A | |
11849 | not: | |
11850 | V<op> A,B,B | |
11851 | so handle that case specially. */ | |
11852 | ||
11853 | static void | |
11854 | neon_exchange_operands (void) | |
11855 | { | |
11856 | void *scratch = alloca (sizeof (inst.operands[0])); | |
11857 | if (inst.operands[1].present) | |
11858 | { | |
11859 | /* Swap operands[1] and operands[2]. */ | |
11860 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
11861 | inst.operands[1] = inst.operands[2]; | |
11862 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
11863 | } | |
11864 | else | |
11865 | { | |
11866 | inst.operands[1] = inst.operands[2]; | |
11867 | inst.operands[2] = inst.operands[0]; | |
11868 | } | |
11869 | } | |
11870 | ||
11871 | static void | |
11872 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
11873 | { | |
11874 | if (inst.operands[2].isreg) | |
11875 | { | |
11876 | if (invert) | |
11877 | neon_exchange_operands (); | |
dcbf9037 | 11878 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
11879 | } |
11880 | else | |
11881 | { | |
037e8744 | 11882 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
11883 | struct neon_type_el et = neon_check_type (2, rs, |
11884 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 JB |
11885 | |
11886 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
11887 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
11888 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11889 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
11890 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 11891 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
11892 | inst.instruction |= (et.type == NT_float) << 10; |
11893 | inst.instruction |= neon_logbits (et.size) << 18; | |
11894 | ||
11895 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11896 | } | |
11897 | } | |
11898 | ||
11899 | static void | |
11900 | do_neon_cmp (void) | |
11901 | { | |
11902 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
11903 | } | |
11904 | ||
11905 | static void | |
11906 | do_neon_cmp_inv (void) | |
11907 | { | |
11908 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
11909 | } | |
11910 | ||
11911 | static void | |
11912 | do_neon_ceq (void) | |
11913 | { | |
11914 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
11915 | } | |
11916 | ||
11917 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
11918 | scalars, which are encoded in 5 bits, M : Rm. | |
11919 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
11920 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
11921 | index in M. */ | |
11922 | ||
11923 | static unsigned | |
11924 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
11925 | { | |
dcbf9037 JB |
11926 | unsigned regno = NEON_SCALAR_REG (scalar); |
11927 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
11928 | |
11929 | switch (elsize) | |
11930 | { | |
11931 | case 16: | |
11932 | if (regno > 7 || elno > 3) | |
11933 | goto bad_scalar; | |
11934 | return regno | (elno << 3); | |
11935 | ||
11936 | case 32: | |
11937 | if (regno > 15 || elno > 1) | |
11938 | goto bad_scalar; | |
11939 | return regno | (elno << 4); | |
11940 | ||
11941 | default: | |
11942 | bad_scalar: | |
dcbf9037 | 11943 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
11944 | } |
11945 | ||
11946 | return 0; | |
11947 | } | |
11948 | ||
11949 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
11950 | ||
11951 | static void | |
11952 | neon_mul_mac (struct neon_type_el et, int ubit) | |
11953 | { | |
dcbf9037 JB |
11954 | unsigned scalar; |
11955 | ||
11956 | /* Give a more helpful error message if we have an invalid type. */ | |
11957 | if (et.type == NT_invtype) | |
11958 | return; | |
11959 | ||
11960 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); | |
5287ad62 JB |
11961 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
11962 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
11963 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
11964 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
11965 | inst.instruction |= LOW4 (scalar); | |
11966 | inst.instruction |= HI1 (scalar) << 5; | |
11967 | inst.instruction |= (et.type == NT_float) << 8; | |
11968 | inst.instruction |= neon_logbits (et.size) << 20; | |
11969 | inst.instruction |= (ubit != 0) << 24; | |
11970 | ||
11971 | inst.instruction = neon_dp_fixup (inst.instruction); | |
11972 | } | |
11973 | ||
11974 | static void | |
11975 | do_neon_mac_maybe_scalar (void) | |
11976 | { | |
037e8744 JB |
11977 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
11978 | return; | |
11979 | ||
11980 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
11981 | return; | |
11982 | ||
5287ad62 JB |
11983 | if (inst.operands[2].isscalar) |
11984 | { | |
037e8744 | 11985 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
11986 | struct neon_type_el et = neon_check_type (3, rs, |
11987 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
11988 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 11989 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
11990 | } |
11991 | else | |
428e3f1f PB |
11992 | { |
11993 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
11994 | affected if we specify unsigned args. */ | |
11995 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
11996 | } | |
5287ad62 JB |
11997 | } |
11998 | ||
11999 | static void | |
12000 | do_neon_tst (void) | |
12001 | { | |
037e8744 | 12002 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12003 | struct neon_type_el et = neon_check_type (3, rs, |
12004 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 12005 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
12006 | } |
12007 | ||
12008 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
12009 | same types as the MAC equivalents. The polynomial type for this instruction | |
12010 | is encoded the same as the integer type. */ | |
12011 | ||
12012 | static void | |
12013 | do_neon_mul (void) | |
12014 | { | |
037e8744 JB |
12015 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
12016 | return; | |
12017 | ||
12018 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12019 | return; | |
12020 | ||
5287ad62 JB |
12021 | if (inst.operands[2].isscalar) |
12022 | do_neon_mac_maybe_scalar (); | |
12023 | else | |
dcbf9037 | 12024 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
12025 | } |
12026 | ||
12027 | static void | |
12028 | do_neon_qdmulh (void) | |
12029 | { | |
12030 | if (inst.operands[2].isscalar) | |
12031 | { | |
037e8744 | 12032 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
12033 | struct neon_type_el et = neon_check_type (3, rs, |
12034 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
12035 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 12036 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
12037 | } |
12038 | else | |
12039 | { | |
037e8744 | 12040 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12041 | struct neon_type_el et = neon_check_type (3, rs, |
12042 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
12043 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12044 | /* The U bit (rounding) comes from bit mask. */ | |
037e8744 | 12045 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
12046 | } |
12047 | } | |
12048 | ||
12049 | static void | |
12050 | do_neon_fcmp_absolute (void) | |
12051 | { | |
037e8744 | 12052 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12053 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
12054 | /* Size field comes from bit mask. */ | |
037e8744 | 12055 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
12056 | } |
12057 | ||
12058 | static void | |
12059 | do_neon_fcmp_absolute_inv (void) | |
12060 | { | |
12061 | neon_exchange_operands (); | |
12062 | do_neon_fcmp_absolute (); | |
12063 | } | |
12064 | ||
12065 | static void | |
12066 | do_neon_step (void) | |
12067 | { | |
037e8744 | 12068 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 12069 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 12070 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12071 | } |
12072 | ||
12073 | static void | |
12074 | do_neon_abs_neg (void) | |
12075 | { | |
037e8744 JB |
12076 | enum neon_shape rs; |
12077 | struct neon_type_el et; | |
12078 | ||
12079 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) | |
12080 | return; | |
12081 | ||
12082 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12083 | return; | |
12084 | ||
12085 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
12086 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
12087 | ||
5287ad62 JB |
12088 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
12089 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12090 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12091 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 12092 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12093 | inst.instruction |= (et.type == NT_float) << 10; |
12094 | inst.instruction |= neon_logbits (et.size) << 18; | |
12095 | ||
12096 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12097 | } | |
12098 | ||
12099 | static void | |
12100 | do_neon_sli (void) | |
12101 | { | |
037e8744 | 12102 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12103 | struct neon_type_el et = neon_check_type (2, rs, |
12104 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
12105 | int imm = inst.operands[2].imm; | |
12106 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
12107 | _("immediate out of range for insert")); | |
037e8744 | 12108 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
12109 | } |
12110 | ||
12111 | static void | |
12112 | do_neon_sri (void) | |
12113 | { | |
037e8744 | 12114 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12115 | struct neon_type_el et = neon_check_type (2, rs, |
12116 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
12117 | int imm = inst.operands[2].imm; | |
12118 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12119 | _("immediate out of range for insert")); | |
037e8744 | 12120 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
12121 | } |
12122 | ||
12123 | static void | |
12124 | do_neon_qshlu_imm (void) | |
12125 | { | |
037e8744 | 12126 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12127 | struct neon_type_el et = neon_check_type (2, rs, |
12128 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
12129 | int imm = inst.operands[2].imm; | |
12130 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
12131 | _("immediate out of range for shift")); | |
12132 | /* Only encodes the 'U present' variant of the instruction. | |
12133 | In this case, signed types have OP (bit 8) set to 0. | |
12134 | Unsigned types have OP set to 1. */ | |
12135 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
12136 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 12137 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
12138 | } |
12139 | ||
12140 | static void | |
12141 | do_neon_qmovn (void) | |
12142 | { | |
12143 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
12144 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
12145 | /* Saturating move where operands can be signed or unsigned, and the | |
12146 | destination has the same signedness. */ | |
12147 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12148 | if (et.type == NT_unsigned) | |
12149 | inst.instruction |= 0xc0; | |
12150 | else | |
12151 | inst.instruction |= 0x80; | |
12152 | neon_two_same (0, 1, et.size / 2); | |
12153 | } | |
12154 | ||
12155 | static void | |
12156 | do_neon_qmovun (void) | |
12157 | { | |
12158 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
12159 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
12160 | /* Saturating move with unsigned results. Operands must be signed. */ | |
12161 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12162 | neon_two_same (0, 1, et.size / 2); | |
12163 | } | |
12164 | ||
12165 | static void | |
12166 | do_neon_rshift_sat_narrow (void) | |
12167 | { | |
12168 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
12169 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
12170 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
12171 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
12172 | int imm = inst.operands[2].imm; | |
12173 | /* This gets the bounds check, size encoding and immediate bits calculation | |
12174 | right. */ | |
12175 | et.size /= 2; | |
12176 | ||
12177 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
12178 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
12179 | if (imm == 0) | |
12180 | { | |
12181 | inst.operands[2].present = 0; | |
12182 | inst.instruction = N_MNEM_vqmovn; | |
12183 | do_neon_qmovn (); | |
12184 | return; | |
12185 | } | |
12186 | ||
12187 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12188 | _("immediate out of range")); | |
12189 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
12190 | } | |
12191 | ||
12192 | static void | |
12193 | do_neon_rshift_sat_narrow_u (void) | |
12194 | { | |
12195 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
12196 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
12197 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
12198 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
12199 | int imm = inst.operands[2].imm; | |
12200 | /* This gets the bounds check, size encoding and immediate bits calculation | |
12201 | right. */ | |
12202 | et.size /= 2; | |
12203 | ||
12204 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
12205 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
12206 | if (imm == 0) | |
12207 | { | |
12208 | inst.operands[2].present = 0; | |
12209 | inst.instruction = N_MNEM_vqmovun; | |
12210 | do_neon_qmovun (); | |
12211 | return; | |
12212 | } | |
12213 | ||
12214 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12215 | _("immediate out of range")); | |
12216 | /* FIXME: The manual is kind of unclear about what value U should have in | |
12217 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
12218 | must be 1. */ | |
12219 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
12220 | } | |
12221 | ||
12222 | static void | |
12223 | do_neon_movn (void) | |
12224 | { | |
12225 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
12226 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
12227 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12228 | neon_two_same (0, 1, et.size / 2); | |
12229 | } | |
12230 | ||
12231 | static void | |
12232 | do_neon_rshift_narrow (void) | |
12233 | { | |
12234 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
12235 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
12236 | int imm = inst.operands[2].imm; | |
12237 | /* This gets the bounds check, size encoding and immediate bits calculation | |
12238 | right. */ | |
12239 | et.size /= 2; | |
12240 | ||
12241 | /* If immediate is zero then we are a pseudo-instruction for | |
12242 | VMOVN.I<size> <Dd>, <Qm> */ | |
12243 | if (imm == 0) | |
12244 | { | |
12245 | inst.operands[2].present = 0; | |
12246 | inst.instruction = N_MNEM_vmovn; | |
12247 | do_neon_movn (); | |
12248 | return; | |
12249 | } | |
12250 | ||
12251 | constraint (imm < 1 || (unsigned)imm > et.size, | |
12252 | _("immediate out of range for narrowing operation")); | |
12253 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
12254 | } | |
12255 | ||
12256 | static void | |
12257 | do_neon_shll (void) | |
12258 | { | |
12259 | /* FIXME: Type checking when lengthening. */ | |
12260 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
12261 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
12262 | unsigned imm = inst.operands[2].imm; | |
12263 | ||
12264 | if (imm == et.size) | |
12265 | { | |
12266 | /* Maximum shift variant. */ | |
12267 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12268 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12269 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12270 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12271 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12272 | inst.instruction |= neon_logbits (et.size) << 18; | |
12273 | ||
12274 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12275 | } | |
12276 | else | |
12277 | { | |
12278 | /* A more-specific type check for non-max versions. */ | |
12279 | et = neon_check_type (2, NS_QDI, | |
12280 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
12281 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12282 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); | |
12283 | } | |
12284 | } | |
12285 | ||
037e8744 | 12286 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
12287 | the current instruction is. */ |
12288 | ||
12289 | static int | |
12290 | neon_cvt_flavour (enum neon_shape rs) | |
12291 | { | |
037e8744 JB |
12292 | #define CVT_VAR(C,X,Y) \ |
12293 | et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \ | |
12294 | if (et.type != NT_invtype) \ | |
12295 | { \ | |
12296 | inst.error = NULL; \ | |
12297 | return (C); \ | |
5287ad62 JB |
12298 | } |
12299 | struct neon_type_el et; | |
037e8744 JB |
12300 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
12301 | || rs == NS_FF) ? N_VFP : 0; | |
12302 | /* The instruction versions which take an immediate take one register | |
12303 | argument, which is extended to the width of the full register. Thus the | |
12304 | "source" and "destination" registers must have the same width. Hack that | |
12305 | here by making the size equal to the key (wider, in this case) operand. */ | |
12306 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5287ad62 JB |
12307 | |
12308 | CVT_VAR (0, N_S32, N_F32); | |
12309 | CVT_VAR (1, N_U32, N_F32); | |
12310 | CVT_VAR (2, N_F32, N_S32); | |
12311 | CVT_VAR (3, N_F32, N_U32); | |
12312 | ||
037e8744 JB |
12313 | whole_reg = N_VFP; |
12314 | ||
12315 | /* VFP instructions. */ | |
12316 | CVT_VAR (4, N_F32, N_F64); | |
12317 | CVT_VAR (5, N_F64, N_F32); | |
12318 | CVT_VAR (6, N_S32, N_F64 | key); | |
12319 | CVT_VAR (7, N_U32, N_F64 | key); | |
12320 | CVT_VAR (8, N_F64 | key, N_S32); | |
12321 | CVT_VAR (9, N_F64 | key, N_U32); | |
12322 | /* VFP instructions with bitshift. */ | |
12323 | CVT_VAR (10, N_F32 | key, N_S16); | |
12324 | CVT_VAR (11, N_F32 | key, N_U16); | |
12325 | CVT_VAR (12, N_F64 | key, N_S16); | |
12326 | CVT_VAR (13, N_F64 | key, N_U16); | |
12327 | CVT_VAR (14, N_S16, N_F32 | key); | |
12328 | CVT_VAR (15, N_U16, N_F32 | key); | |
12329 | CVT_VAR (16, N_S16, N_F64 | key); | |
12330 | CVT_VAR (17, N_U16, N_F64 | key); | |
12331 | ||
5287ad62 JB |
12332 | return -1; |
12333 | #undef CVT_VAR | |
12334 | } | |
12335 | ||
037e8744 JB |
12336 | /* Neon-syntax VFP conversions. */ |
12337 | ||
5287ad62 | 12338 | static void |
037e8744 | 12339 | do_vfp_nsyn_cvt (enum neon_shape rs, int flavour) |
5287ad62 | 12340 | { |
037e8744 JB |
12341 | const char *opname = 0; |
12342 | ||
12343 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) | |
5287ad62 | 12344 | { |
037e8744 JB |
12345 | /* Conversions with immediate bitshift. */ |
12346 | const char *enc[] = | |
12347 | { | |
12348 | "ftosls", | |
12349 | "ftouls", | |
12350 | "fsltos", | |
12351 | "fultos", | |
12352 | NULL, | |
12353 | NULL, | |
12354 | "ftosld", | |
12355 | "ftould", | |
12356 | "fsltod", | |
12357 | "fultod", | |
12358 | "fshtos", | |
12359 | "fuhtos", | |
12360 | "fshtod", | |
12361 | "fuhtod", | |
12362 | "ftoshs", | |
12363 | "ftouhs", | |
12364 | "ftoshd", | |
12365 | "ftouhd" | |
12366 | }; | |
12367 | ||
12368 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
12369 | { | |
12370 | opname = enc[flavour]; | |
12371 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
12372 | _("operands 0 and 1 must be the same register")); | |
12373 | inst.operands[1] = inst.operands[2]; | |
12374 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
12375 | } | |
5287ad62 JB |
12376 | } |
12377 | else | |
12378 | { | |
037e8744 JB |
12379 | /* Conversions without bitshift. */ |
12380 | const char *enc[] = | |
12381 | { | |
12382 | "ftosis", | |
12383 | "ftouis", | |
12384 | "fsitos", | |
12385 | "fuitos", | |
12386 | "fcvtsd", | |
12387 | "fcvtds", | |
12388 | "ftosid", | |
12389 | "ftouid", | |
12390 | "fsitod", | |
12391 | "fuitod" | |
12392 | }; | |
12393 | ||
12394 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
12395 | opname = enc[flavour]; | |
12396 | } | |
12397 | ||
12398 | if (opname) | |
12399 | do_vfp_nsyn_opcode (opname); | |
12400 | } | |
12401 | ||
12402 | static void | |
12403 | do_vfp_nsyn_cvtz (void) | |
12404 | { | |
12405 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
12406 | int flavour = neon_cvt_flavour (rs); | |
12407 | const char *enc[] = | |
12408 | { | |
12409 | "ftosizs", | |
12410 | "ftouizs", | |
12411 | NULL, | |
12412 | NULL, | |
12413 | NULL, | |
12414 | NULL, | |
12415 | "ftosizd", | |
12416 | "ftouizd" | |
12417 | }; | |
12418 | ||
12419 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) | |
12420 | do_vfp_nsyn_opcode (enc[flavour]); | |
12421 | } | |
12422 | ||
12423 | static void | |
12424 | do_neon_cvt (void) | |
12425 | { | |
12426 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
12427 | NS_FD, NS_DF, NS_FF, NS_NULL); | |
12428 | int flavour = neon_cvt_flavour (rs); | |
12429 | ||
12430 | /* VFP rather than Neon conversions. */ | |
12431 | if (flavour >= 4) | |
12432 | { | |
12433 | do_vfp_nsyn_cvt (rs, flavour); | |
12434 | return; | |
12435 | } | |
12436 | ||
12437 | switch (rs) | |
12438 | { | |
12439 | case NS_DDI: | |
12440 | case NS_QQI: | |
12441 | { | |
12442 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12443 | return; | |
12444 | ||
12445 | /* Fixed-point conversion with #0 immediate is encoded as an | |
12446 | integer conversion. */ | |
12447 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
12448 | goto int_encode; | |
12449 | unsigned immbits = 32 - inst.operands[2].imm; | |
12450 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
12451 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12452 | if (flavour != -1) | |
12453 | inst.instruction |= enctab[flavour]; | |
12454 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12455 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12456 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12457 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12458 | inst.instruction |= neon_quad (rs) << 6; | |
12459 | inst.instruction |= 1 << 21; | |
12460 | inst.instruction |= immbits << 16; | |
12461 | ||
12462 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12463 | } | |
12464 | break; | |
12465 | ||
12466 | case NS_DD: | |
12467 | case NS_QQ: | |
12468 | int_encode: | |
12469 | { | |
12470 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
12471 | ||
12472 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12473 | ||
12474 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12475 | return; | |
12476 | ||
12477 | if (flavour != -1) | |
12478 | inst.instruction |= enctab[flavour]; | |
12479 | ||
12480 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12481 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12482 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12483 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12484 | inst.instruction |= neon_quad (rs) << 6; | |
12485 | inst.instruction |= 2 << 18; | |
12486 | ||
12487 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12488 | } | |
12489 | break; | |
12490 | ||
12491 | default: | |
12492 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
12493 | do_vfp_nsyn_cvt (rs, flavour); | |
5287ad62 | 12494 | } |
5287ad62 JB |
12495 | } |
12496 | ||
12497 | static void | |
12498 | neon_move_immediate (void) | |
12499 | { | |
037e8744 JB |
12500 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
12501 | struct neon_type_el et = neon_check_type (2, rs, | |
12502 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 JB |
12503 | unsigned immlo, immhi = 0, immbits; |
12504 | int op, cmode; | |
12505 | ||
037e8744 JB |
12506 | constraint (et.type == NT_invtype, |
12507 | _("operand size must be specified for immediate VMOV")); | |
12508 | ||
5287ad62 JB |
12509 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
12510 | op = (inst.instruction & (1 << 5)) != 0; | |
12511 | ||
12512 | immlo = inst.operands[1].imm; | |
12513 | if (inst.operands[1].regisimm) | |
12514 | immhi = inst.operands[1].reg; | |
12515 | ||
12516 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
12517 | _("immediate has bits set outside the operand size")); | |
12518 | ||
12519 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op, | |
136da414 | 12520 | et.size, et.type)) == FAIL) |
5287ad62 JB |
12521 | { |
12522 | /* Invert relevant bits only. */ | |
12523 | neon_invert_size (&immlo, &immhi, et.size); | |
12524 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
12525 | with one or the other; those cases are caught by | |
12526 | neon_cmode_for_move_imm. */ | |
12527 | op = !op; | |
12528 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op, | |
136da414 | 12529 | et.size, et.type)) == FAIL) |
5287ad62 | 12530 | { |
dcbf9037 | 12531 | first_error (_("immediate out of range")); |
5287ad62 JB |
12532 | return; |
12533 | } | |
12534 | } | |
12535 | ||
12536 | inst.instruction &= ~(1 << 5); | |
12537 | inst.instruction |= op << 5; | |
12538 | ||
12539 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12540 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 12541 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12542 | inst.instruction |= cmode << 8; |
12543 | ||
12544 | neon_write_immbits (immbits); | |
12545 | } | |
12546 | ||
12547 | static void | |
12548 | do_neon_mvn (void) | |
12549 | { | |
12550 | if (inst.operands[1].isreg) | |
12551 | { | |
037e8744 | 12552 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12553 | |
12554 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12555 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12556 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12557 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12558 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 12559 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12560 | } |
12561 | else | |
12562 | { | |
12563 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12564 | neon_move_immediate (); | |
12565 | } | |
12566 | ||
12567 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12568 | } | |
12569 | ||
12570 | /* Encode instructions of form: | |
12571 | ||
12572 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
12573 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | | |
12574 | ||
12575 | */ | |
12576 | ||
12577 | static void | |
12578 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
12579 | { | |
12580 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12581 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12582 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12583 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12584 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12585 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12586 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
12587 | inst.instruction |= neon_logbits (size) << 20; | |
12588 | ||
12589 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12590 | } | |
12591 | ||
12592 | static void | |
12593 | do_neon_dyadic_long (void) | |
12594 | { | |
12595 | /* FIXME: Type checking for lengthening op. */ | |
12596 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12597 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
12598 | neon_mixed_length (et, et.size); | |
12599 | } | |
12600 | ||
12601 | static void | |
12602 | do_neon_abal (void) | |
12603 | { | |
12604 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12605 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
12606 | neon_mixed_length (et, et.size); | |
12607 | } | |
12608 | ||
12609 | static void | |
12610 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
12611 | { | |
12612 | if (inst.operands[2].isscalar) | |
12613 | { | |
dcbf9037 JB |
12614 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
12615 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
5287ad62 JB |
12616 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
12617 | neon_mul_mac (et, et.type == NT_unsigned); | |
12618 | } | |
12619 | else | |
12620 | { | |
12621 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12622 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
12623 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12624 | neon_mixed_length (et, et.size); | |
12625 | } | |
12626 | } | |
12627 | ||
12628 | static void | |
12629 | do_neon_mac_maybe_scalar_long (void) | |
12630 | { | |
12631 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
12632 | } | |
12633 | ||
12634 | static void | |
12635 | do_neon_dyadic_wide (void) | |
12636 | { | |
12637 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
12638 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
12639 | neon_mixed_length (et, et.size); | |
12640 | } | |
12641 | ||
12642 | static void | |
12643 | do_neon_dyadic_narrow (void) | |
12644 | { | |
12645 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12646 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
12647 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
12648 | so force the operand type to integer. */ | |
12649 | et.type = NT_integer; | |
5287ad62 JB |
12650 | neon_mixed_length (et, et.size / 2); |
12651 | } | |
12652 | ||
12653 | static void | |
12654 | do_neon_mul_sat_scalar_long (void) | |
12655 | { | |
12656 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
12657 | } | |
12658 | ||
12659 | static void | |
12660 | do_neon_vmull (void) | |
12661 | { | |
12662 | if (inst.operands[2].isscalar) | |
12663 | do_neon_mac_maybe_scalar_long (); | |
12664 | else | |
12665 | { | |
12666 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
12667 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY); | |
12668 | if (et.type == NT_poly) | |
12669 | inst.instruction = NEON_ENC_POLY (inst.instruction); | |
12670 | else | |
12671 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
12672 | /* For polynomial encoding, size field must be 0b00 and the U bit must be | |
12673 | zero. Should be OK as-is. */ | |
12674 | neon_mixed_length (et, et.size); | |
12675 | } | |
12676 | } | |
12677 | ||
12678 | static void | |
12679 | do_neon_ext (void) | |
12680 | { | |
037e8744 | 12681 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
12682 | struct neon_type_el et = neon_check_type (3, rs, |
12683 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
12684 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
12685 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12686 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12687 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12688 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12689 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12690 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 12691 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12692 | inst.instruction |= imm << 8; |
12693 | ||
12694 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12695 | } | |
12696 | ||
12697 | static void | |
12698 | do_neon_rev (void) | |
12699 | { | |
037e8744 | 12700 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
12701 | struct neon_type_el et = neon_check_type (2, rs, |
12702 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
12703 | unsigned op = (inst.instruction >> 7) & 3; | |
12704 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
12705 | extract it here to check the elements to be reversed are smaller. | |
12706 | Otherwise we'd get a reserved instruction. */ | |
12707 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
12708 | assert (elsize != 0); | |
12709 | constraint (et.size >= elsize, | |
12710 | _("elements must be smaller than reversal region")); | |
037e8744 | 12711 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
12712 | } |
12713 | ||
12714 | static void | |
12715 | do_neon_dup (void) | |
12716 | { | |
12717 | if (inst.operands[1].isscalar) | |
12718 | { | |
037e8744 | 12719 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
12720 | struct neon_type_el et = neon_check_type (2, rs, |
12721 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 12722 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 12723 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 12724 | int logsize = neon_logbits (et.size); |
dcbf9037 | 12725 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
12726 | |
12727 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
12728 | return; | |
12729 | ||
5287ad62 JB |
12730 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
12731 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12732 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12733 | inst.instruction |= LOW4 (dm); | |
12734 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 12735 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12736 | inst.instruction |= x << 17; |
12737 | inst.instruction |= sizebits << 16; | |
12738 | ||
12739 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12740 | } | |
12741 | else | |
12742 | { | |
037e8744 JB |
12743 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
12744 | struct neon_type_el et = neon_check_type (2, rs, | |
12745 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 JB |
12746 | /* Duplicate ARM register to lanes of vector. */ |
12747 | inst.instruction = NEON_ENC_ARMREG (inst.instruction); | |
12748 | switch (et.size) | |
12749 | { | |
12750 | case 8: inst.instruction |= 0x400000; break; | |
12751 | case 16: inst.instruction |= 0x000020; break; | |
12752 | case 32: inst.instruction |= 0x000000; break; | |
12753 | default: break; | |
12754 | } | |
12755 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
12756 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
12757 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 12758 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
12759 | /* The encoding for this instruction is identical for the ARM and Thumb |
12760 | variants, except for the condition field. */ | |
037e8744 | 12761 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
12762 | } |
12763 | } | |
12764 | ||
12765 | /* VMOV has particularly many variations. It can be one of: | |
12766 | 0. VMOV<c><q> <Qd>, <Qm> | |
12767 | 1. VMOV<c><q> <Dd>, <Dm> | |
12768 | (Register operations, which are VORR with Rm = Rn.) | |
12769 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
12770 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
12771 | (Immediate loads.) | |
12772 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
12773 | (ARM register to scalar.) | |
12774 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
12775 | (Two ARM registers to vector.) | |
12776 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
12777 | (Scalar to ARM register.) | |
12778 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
12779 | (Vector to two ARM registers.) | |
037e8744 JB |
12780 | 8. VMOV.F32 <Sd>, <Sm> |
12781 | 9. VMOV.F64 <Dd>, <Dm> | |
12782 | (VFP register moves.) | |
12783 | 10. VMOV.F32 <Sd>, #imm | |
12784 | 11. VMOV.F64 <Dd>, #imm | |
12785 | (VFP float immediate load.) | |
12786 | 12. VMOV <Rd>, <Sm> | |
12787 | (VFP single to ARM reg.) | |
12788 | 13. VMOV <Sd>, <Rm> | |
12789 | (ARM reg to VFP single.) | |
12790 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
12791 | (Two ARM regs to two VFP singles.) | |
12792 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
12793 | (Two VFP singles to two ARM regs.) | |
5287ad62 | 12794 | |
037e8744 JB |
12795 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
12796 | and 3/11 which depend on the operand type too. | |
5287ad62 JB |
12797 | |
12798 | All the encoded bits are hardcoded by this function. | |
12799 | ||
b7fc2769 JB |
12800 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
12801 | Cases 5, 7 may be used with VFPv2 and above. | |
12802 | ||
5287ad62 JB |
12803 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
12804 | can specify a type where it doesn't make sense to, and is ignored). | |
12805 | */ | |
12806 | ||
12807 | static void | |
12808 | do_neon_mov (void) | |
12809 | { | |
037e8744 JB |
12810 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
12811 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
12812 | NS_NULL); | |
12813 | struct neon_type_el et; | |
12814 | const char *ldconst = 0; | |
5287ad62 | 12815 | |
037e8744 | 12816 | switch (rs) |
5287ad62 | 12817 | { |
037e8744 JB |
12818 | case NS_DD: /* case 1/9. */ |
12819 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
12820 | /* It is not an error here if no type is given. */ | |
12821 | inst.error = NULL; | |
12822 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 12823 | { |
037e8744 JB |
12824 | do_vfp_nsyn_opcode ("fcpyd"); |
12825 | break; | |
5287ad62 | 12826 | } |
037e8744 | 12827 | /* fall through. */ |
5287ad62 | 12828 | |
037e8744 JB |
12829 | case NS_QQ: /* case 0/1. */ |
12830 | { | |
12831 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12832 | return; | |
12833 | /* The architecture manual I have doesn't explicitly state which | |
12834 | value the U bit should have for register->register moves, but | |
12835 | the equivalent VORR instruction has U = 0, so do that. */ | |
12836 | inst.instruction = 0x0200110; | |
12837 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12838 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12839 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12840 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12841 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12842 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12843 | inst.instruction |= neon_quad (rs) << 6; | |
12844 | ||
12845 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12846 | } | |
12847 | break; | |
12848 | ||
12849 | case NS_DI: /* case 3/11. */ | |
12850 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
12851 | inst.error = NULL; | |
12852 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 12853 | { |
037e8744 JB |
12854 | /* case 11 (fconstd). */ |
12855 | ldconst = "fconstd"; | |
12856 | goto encode_fconstd; | |
5287ad62 | 12857 | } |
037e8744 JB |
12858 | /* fall through. */ |
12859 | ||
12860 | case NS_QI: /* case 2/3. */ | |
12861 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12862 | return; | |
12863 | inst.instruction = 0x0800010; | |
12864 | neon_move_immediate (); | |
12865 | inst.instruction = neon_dp_fixup (inst.instruction); | |
5287ad62 JB |
12866 | break; |
12867 | ||
037e8744 JB |
12868 | case NS_SR: /* case 4. */ |
12869 | { | |
12870 | unsigned bcdebits = 0; | |
12871 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
12872 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
12873 | int logsize = neon_logbits (et.size); | |
12874 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
12875 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
12876 | ||
12877 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
12878 | _(BAD_FPU)); | |
12879 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
12880 | && et.size != 32, _(BAD_FPU)); | |
12881 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
12882 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
12883 | ||
12884 | switch (et.size) | |
12885 | { | |
12886 | case 8: bcdebits = 0x8; break; | |
12887 | case 16: bcdebits = 0x1; break; | |
12888 | case 32: bcdebits = 0x0; break; | |
12889 | default: ; | |
12890 | } | |
12891 | ||
12892 | bcdebits |= x << logsize; | |
12893 | ||
12894 | inst.instruction = 0xe000b10; | |
12895 | do_vfp_cond_or_thumb (); | |
12896 | inst.instruction |= LOW4 (dn) << 16; | |
12897 | inst.instruction |= HI1 (dn) << 7; | |
12898 | inst.instruction |= inst.operands[1].reg << 12; | |
12899 | inst.instruction |= (bcdebits & 3) << 5; | |
12900 | inst.instruction |= (bcdebits >> 2) << 21; | |
12901 | } | |
12902 | break; | |
12903 | ||
12904 | case NS_DRR: /* case 5 (fmdrr). */ | |
b7fc2769 | 12905 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 12906 | _(BAD_FPU)); |
b7fc2769 | 12907 | |
037e8744 JB |
12908 | inst.instruction = 0xc400b10; |
12909 | do_vfp_cond_or_thumb (); | |
12910 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
12911 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
12912 | inst.instruction |= inst.operands[1].reg << 12; | |
12913 | inst.instruction |= inst.operands[2].reg << 16; | |
12914 | break; | |
12915 | ||
12916 | case NS_RS: /* case 6. */ | |
12917 | { | |
12918 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
12919 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
12920 | unsigned logsize = neon_logbits (et.size); | |
12921 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
12922 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
12923 | unsigned abcdebits = 0; | |
12924 | ||
12925 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
12926 | _(BAD_FPU)); | |
12927 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
12928 | && et.size != 32, _(BAD_FPU)); | |
12929 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
12930 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
12931 | ||
12932 | switch (et.size) | |
12933 | { | |
12934 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
12935 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
12936 | case 32: abcdebits = 0x00; break; | |
12937 | default: ; | |
12938 | } | |
12939 | ||
12940 | abcdebits |= x << logsize; | |
12941 | inst.instruction = 0xe100b10; | |
12942 | do_vfp_cond_or_thumb (); | |
12943 | inst.instruction |= LOW4 (dn) << 16; | |
12944 | inst.instruction |= HI1 (dn) << 7; | |
12945 | inst.instruction |= inst.operands[0].reg << 12; | |
12946 | inst.instruction |= (abcdebits & 3) << 5; | |
12947 | inst.instruction |= (abcdebits >> 2) << 21; | |
12948 | } | |
12949 | break; | |
12950 | ||
12951 | case NS_RRD: /* case 7 (fmrrd). */ | |
12952 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
12953 | _(BAD_FPU)); | |
12954 | ||
12955 | inst.instruction = 0xc500b10; | |
12956 | do_vfp_cond_or_thumb (); | |
12957 | inst.instruction |= inst.operands[0].reg << 12; | |
12958 | inst.instruction |= inst.operands[1].reg << 16; | |
12959 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12960 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12961 | break; | |
12962 | ||
12963 | case NS_FF: /* case 8 (fcpys). */ | |
12964 | do_vfp_nsyn_opcode ("fcpys"); | |
12965 | break; | |
12966 | ||
12967 | case NS_FI: /* case 10 (fconsts). */ | |
12968 | ldconst = "fconsts"; | |
12969 | encode_fconstd: | |
12970 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 12971 | { |
037e8744 JB |
12972 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
12973 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
12974 | } |
12975 | else | |
037e8744 JB |
12976 | first_error (_("immediate out of range")); |
12977 | break; | |
12978 | ||
12979 | case NS_RF: /* case 12 (fmrs). */ | |
12980 | do_vfp_nsyn_opcode ("fmrs"); | |
12981 | break; | |
12982 | ||
12983 | case NS_FR: /* case 13 (fmsr). */ | |
12984 | do_vfp_nsyn_opcode ("fmsr"); | |
12985 | break; | |
12986 | ||
12987 | /* The encoders for the fmrrs and fmsrr instructions expect three operands | |
12988 | (one of which is a list), but we have parsed four. Do some fiddling to | |
12989 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
12990 | expect. */ | |
12991 | case NS_RRFF: /* case 14 (fmrrs). */ | |
12992 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
12993 | _("VFP registers must be adjacent")); | |
12994 | inst.operands[2].imm = 2; | |
12995 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
12996 | do_vfp_nsyn_opcode ("fmrrs"); | |
12997 | break; | |
12998 | ||
12999 | case NS_FFRR: /* case 15 (fmsrr). */ | |
13000 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
13001 | _("VFP registers must be adjacent")); | |
13002 | inst.operands[1] = inst.operands[2]; | |
13003 | inst.operands[2] = inst.operands[3]; | |
13004 | inst.operands[0].imm = 2; | |
13005 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
13006 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 JB |
13007 | break; |
13008 | ||
13009 | default: | |
13010 | abort (); | |
13011 | } | |
13012 | } | |
13013 | ||
13014 | static void | |
13015 | do_neon_rshift_round_imm (void) | |
13016 | { | |
037e8744 | 13017 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13018 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
13019 | int imm = inst.operands[2].imm; | |
13020 | ||
13021 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
13022 | if (imm == 0) | |
13023 | { | |
13024 | inst.operands[2].present = 0; | |
13025 | do_neon_mov (); | |
13026 | return; | |
13027 | } | |
13028 | ||
13029 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13030 | _("immediate out of range for shift")); | |
037e8744 | 13031 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
13032 | et.size - imm); |
13033 | } | |
13034 | ||
13035 | static void | |
13036 | do_neon_movl (void) | |
13037 | { | |
13038 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
13039 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13040 | unsigned sizebits = et.size >> 3; | |
13041 | inst.instruction |= sizebits << 19; | |
13042 | neon_two_same (0, et.type == NT_unsigned, -1); | |
13043 | } | |
13044 | ||
13045 | static void | |
13046 | do_neon_trn (void) | |
13047 | { | |
037e8744 | 13048 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13049 | struct neon_type_el et = neon_check_type (2, rs, |
13050 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
13051 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 13052 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13053 | } |
13054 | ||
13055 | static void | |
13056 | do_neon_zip_uzp (void) | |
13057 | { | |
037e8744 | 13058 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13059 | struct neon_type_el et = neon_check_type (2, rs, |
13060 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
13061 | if (rs == NS_DD && et.size == 32) | |
13062 | { | |
13063 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
13064 | inst.instruction = N_MNEM_vtrn; | |
13065 | do_neon_trn (); | |
13066 | return; | |
13067 | } | |
037e8744 | 13068 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13069 | } |
13070 | ||
13071 | static void | |
13072 | do_neon_sat_abs_neg (void) | |
13073 | { | |
037e8744 | 13074 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13075 | struct neon_type_el et = neon_check_type (2, rs, |
13076 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 13077 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13078 | } |
13079 | ||
13080 | static void | |
13081 | do_neon_pair_long (void) | |
13082 | { | |
037e8744 | 13083 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13084 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
13085 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
13086 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 13087 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13088 | } |
13089 | ||
13090 | static void | |
13091 | do_neon_recip_est (void) | |
13092 | { | |
037e8744 | 13093 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13094 | struct neon_type_el et = neon_check_type (2, rs, |
13095 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
13096 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 13097 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13098 | } |
13099 | ||
13100 | static void | |
13101 | do_neon_cls (void) | |
13102 | { | |
037e8744 | 13103 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13104 | struct neon_type_el et = neon_check_type (2, rs, |
13105 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 13106 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13107 | } |
13108 | ||
13109 | static void | |
13110 | do_neon_clz (void) | |
13111 | { | |
037e8744 | 13112 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13113 | struct neon_type_el et = neon_check_type (2, rs, |
13114 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 13115 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13116 | } |
13117 | ||
13118 | static void | |
13119 | do_neon_cnt (void) | |
13120 | { | |
037e8744 | 13121 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13122 | struct neon_type_el et = neon_check_type (2, rs, |
13123 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 13124 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13125 | } |
13126 | ||
13127 | static void | |
13128 | do_neon_swp (void) | |
13129 | { | |
037e8744 JB |
13130 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
13131 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
13132 | } |
13133 | ||
13134 | static void | |
13135 | do_neon_tbl_tbx (void) | |
13136 | { | |
13137 | unsigned listlenbits; | |
dcbf9037 | 13138 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5287ad62 JB |
13139 | |
13140 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) | |
13141 | { | |
dcbf9037 | 13142 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
13143 | return; |
13144 | } | |
13145 | ||
13146 | listlenbits = inst.operands[1].imm - 1; | |
13147 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13148 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13149 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13150 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13151 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13152 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
13153 | inst.instruction |= listlenbits << 8; | |
13154 | ||
13155 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13156 | } | |
13157 | ||
13158 | static void | |
13159 | do_neon_ldm_stm (void) | |
13160 | { | |
13161 | /* P, U and L bits are part of bitmask. */ | |
13162 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
13163 | unsigned offsetbits = inst.operands[1].imm * 2; | |
13164 | ||
037e8744 JB |
13165 | if (inst.operands[1].issingle) |
13166 | { | |
13167 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
13168 | return; | |
13169 | } | |
13170 | ||
5287ad62 JB |
13171 | constraint (is_dbmode && !inst.operands[0].writeback, |
13172 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
13173 | ||
13174 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
13175 | _("register list must contain at least 1 and at most 16 " | |
13176 | "registers")); | |
13177 | ||
13178 | inst.instruction |= inst.operands[0].reg << 16; | |
13179 | inst.instruction |= inst.operands[0].writeback << 21; | |
13180 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
13181 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
13182 | ||
13183 | inst.instruction |= offsetbits; | |
13184 | ||
037e8744 | 13185 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
13186 | } |
13187 | ||
13188 | static void | |
13189 | do_neon_ldr_str (void) | |
13190 | { | |
5287ad62 JB |
13191 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
13192 | ||
037e8744 JB |
13193 | if (inst.operands[0].issingle) |
13194 | { | |
cd2f129f JB |
13195 | if (is_ldr) |
13196 | do_vfp_nsyn_opcode ("flds"); | |
13197 | else | |
13198 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
13199 | } |
13200 | else | |
5287ad62 | 13201 | { |
cd2f129f JB |
13202 | if (is_ldr) |
13203 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 13204 | else |
cd2f129f | 13205 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 13206 | } |
5287ad62 JB |
13207 | } |
13208 | ||
13209 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
13210 | instructions. */ | |
13211 | ||
13212 | static void | |
13213 | do_neon_ld_st_interleave (void) | |
13214 | { | |
037e8744 | 13215 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
13216 | N_8 | N_16 | N_32 | N_64); |
13217 | unsigned alignbits = 0; | |
13218 | unsigned idx; | |
13219 | /* The bits in this table go: | |
13220 | 0: register stride of one (0) or two (1) | |
13221 | 1,2: register list length, minus one (1, 2, 3, 4). | |
13222 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
13223 | We use -1 for invalid entries. */ | |
13224 | const int typetable[] = | |
13225 | { | |
13226 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
13227 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
13228 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
13229 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
13230 | }; | |
13231 | int typebits; | |
13232 | ||
dcbf9037 JB |
13233 | if (et.type == NT_invtype) |
13234 | return; | |
13235 | ||
5287ad62 JB |
13236 | if (inst.operands[1].immisalign) |
13237 | switch (inst.operands[1].imm >> 8) | |
13238 | { | |
13239 | case 64: alignbits = 1; break; | |
13240 | case 128: | |
13241 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
13242 | goto bad_alignment; | |
13243 | alignbits = 2; | |
13244 | break; | |
13245 | case 256: | |
13246 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
13247 | goto bad_alignment; | |
13248 | alignbits = 3; | |
13249 | break; | |
13250 | default: | |
13251 | bad_alignment: | |
dcbf9037 | 13252 | first_error (_("bad alignment")); |
5287ad62 JB |
13253 | return; |
13254 | } | |
13255 | ||
13256 | inst.instruction |= alignbits << 4; | |
13257 | inst.instruction |= neon_logbits (et.size) << 6; | |
13258 | ||
13259 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
13260 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
13261 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
13262 | up the right value for "type" in a table based on this value and the given | |
13263 | list style, then stick it back. */ | |
13264 | idx = ((inst.operands[0].imm >> 4) & 7) | |
13265 | | (((inst.instruction >> 8) & 3) << 3); | |
13266 | ||
13267 | typebits = typetable[idx]; | |
13268 | ||
13269 | constraint (typebits == -1, _("bad list type for instruction")); | |
13270 | ||
13271 | inst.instruction &= ~0xf00; | |
13272 | inst.instruction |= typebits << 8; | |
13273 | } | |
13274 | ||
13275 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
13276 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
13277 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
13278 | values, terminated with -1. */ | |
13279 | ||
13280 | static int | |
13281 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
13282 | { | |
13283 | va_list ap; | |
13284 | int result = FAIL, thissize, thisalign; | |
13285 | ||
13286 | if (!inst.operands[1].immisalign) | |
13287 | { | |
13288 | *do_align = 0; | |
13289 | return SUCCESS; | |
13290 | } | |
13291 | ||
13292 | va_start (ap, do_align); | |
13293 | ||
13294 | do | |
13295 | { | |
13296 | thissize = va_arg (ap, int); | |
13297 | if (thissize == -1) | |
13298 | break; | |
13299 | thisalign = va_arg (ap, int); | |
13300 | ||
13301 | if (size == thissize && align == thisalign) | |
13302 | result = SUCCESS; | |
13303 | } | |
13304 | while (result != SUCCESS); | |
13305 | ||
13306 | va_end (ap); | |
13307 | ||
13308 | if (result == SUCCESS) | |
13309 | *do_align = 1; | |
13310 | else | |
dcbf9037 | 13311 | first_error (_("unsupported alignment for instruction")); |
5287ad62 JB |
13312 | |
13313 | return result; | |
13314 | } | |
13315 | ||
13316 | static void | |
13317 | do_neon_ld_st_lane (void) | |
13318 | { | |
037e8744 | 13319 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
13320 | int align_good, do_align = 0; |
13321 | int logsize = neon_logbits (et.size); | |
13322 | int align = inst.operands[1].imm >> 8; | |
13323 | int n = (inst.instruction >> 8) & 3; | |
13324 | int max_el = 64 / et.size; | |
13325 | ||
dcbf9037 JB |
13326 | if (et.type == NT_invtype) |
13327 | return; | |
13328 | ||
5287ad62 JB |
13329 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
13330 | _("bad list length")); | |
13331 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
13332 | _("scalar index out of range")); | |
13333 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
13334 | && et.size == 8, | |
13335 | _("stride of 2 unavailable when element size is 8")); | |
13336 | ||
13337 | switch (n) | |
13338 | { | |
13339 | case 0: /* VLD1 / VST1. */ | |
13340 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
13341 | 32, 32, -1); | |
13342 | if (align_good == FAIL) | |
13343 | return; | |
13344 | if (do_align) | |
13345 | { | |
13346 | unsigned alignbits = 0; | |
13347 | switch (et.size) | |
13348 | { | |
13349 | case 16: alignbits = 0x1; break; | |
13350 | case 32: alignbits = 0x3; break; | |
13351 | default: ; | |
13352 | } | |
13353 | inst.instruction |= alignbits << 4; | |
13354 | } | |
13355 | break; | |
13356 | ||
13357 | case 1: /* VLD2 / VST2. */ | |
13358 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
13359 | 32, 64, -1); | |
13360 | if (align_good == FAIL) | |
13361 | return; | |
13362 | if (do_align) | |
13363 | inst.instruction |= 1 << 4; | |
13364 | break; | |
13365 | ||
13366 | case 2: /* VLD3 / VST3. */ | |
13367 | constraint (inst.operands[1].immisalign, | |
13368 | _("can't use alignment with this instruction")); | |
13369 | break; | |
13370 | ||
13371 | case 3: /* VLD4 / VST4. */ | |
13372 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
13373 | 16, 64, 32, 64, 32, 128, -1); | |
13374 | if (align_good == FAIL) | |
13375 | return; | |
13376 | if (do_align) | |
13377 | { | |
13378 | unsigned alignbits = 0; | |
13379 | switch (et.size) | |
13380 | { | |
13381 | case 8: alignbits = 0x1; break; | |
13382 | case 16: alignbits = 0x1; break; | |
13383 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
13384 | default: ; | |
13385 | } | |
13386 | inst.instruction |= alignbits << 4; | |
13387 | } | |
13388 | break; | |
13389 | ||
13390 | default: ; | |
13391 | } | |
13392 | ||
13393 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
13394 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13395 | inst.instruction |= 1 << (4 + logsize); | |
13396 | ||
13397 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); | |
13398 | inst.instruction |= logsize << 10; | |
13399 | } | |
13400 | ||
13401 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
13402 | ||
13403 | static void | |
13404 | do_neon_ld_dup (void) | |
13405 | { | |
037e8744 | 13406 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
13407 | int align_good, do_align = 0; |
13408 | ||
dcbf9037 JB |
13409 | if (et.type == NT_invtype) |
13410 | return; | |
13411 | ||
5287ad62 JB |
13412 | switch ((inst.instruction >> 8) & 3) |
13413 | { | |
13414 | case 0: /* VLD1. */ | |
13415 | assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); | |
13416 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
13417 | &do_align, 16, 16, 32, 32, -1); | |
13418 | if (align_good == FAIL) | |
13419 | return; | |
13420 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
13421 | { | |
13422 | case 1: break; | |
13423 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 13424 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
13425 | } |
13426 | inst.instruction |= neon_logbits (et.size) << 6; | |
13427 | break; | |
13428 | ||
13429 | case 1: /* VLD2. */ | |
13430 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
13431 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
13432 | if (align_good == FAIL) | |
13433 | return; | |
13434 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
13435 | _("bad list length")); | |
13436 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13437 | inst.instruction |= 1 << 5; | |
13438 | inst.instruction |= neon_logbits (et.size) << 6; | |
13439 | break; | |
13440 | ||
13441 | case 2: /* VLD3. */ | |
13442 | constraint (inst.operands[1].immisalign, | |
13443 | _("can't use alignment with this instruction")); | |
13444 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
13445 | _("bad list length")); | |
13446 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13447 | inst.instruction |= 1 << 5; | |
13448 | inst.instruction |= neon_logbits (et.size) << 6; | |
13449 | break; | |
13450 | ||
13451 | case 3: /* VLD4. */ | |
13452 | { | |
13453 | int align = inst.operands[1].imm >> 8; | |
13454 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
13455 | 16, 64, 32, 64, 32, 128, -1); | |
13456 | if (align_good == FAIL) | |
13457 | return; | |
13458 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
13459 | _("bad list length")); | |
13460 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
13461 | inst.instruction |= 1 << 5; | |
13462 | if (et.size == 32 && align == 128) | |
13463 | inst.instruction |= 0x3 << 6; | |
13464 | else | |
13465 | inst.instruction |= neon_logbits (et.size) << 6; | |
13466 | } | |
13467 | break; | |
13468 | ||
13469 | default: ; | |
13470 | } | |
13471 | ||
13472 | inst.instruction |= do_align << 4; | |
13473 | } | |
13474 | ||
13475 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
13476 | apart from bits [11:4]. */ | |
13477 | ||
13478 | static void | |
13479 | do_neon_ldx_stx (void) | |
13480 | { | |
13481 | switch (NEON_LANE (inst.operands[0].imm)) | |
13482 | { | |
13483 | case NEON_INTERLEAVE_LANES: | |
13484 | inst.instruction = NEON_ENC_INTERLV (inst.instruction); | |
13485 | do_neon_ld_st_interleave (); | |
13486 | break; | |
13487 | ||
13488 | case NEON_ALL_LANES: | |
13489 | inst.instruction = NEON_ENC_DUP (inst.instruction); | |
13490 | do_neon_ld_dup (); | |
13491 | break; | |
13492 | ||
13493 | default: | |
13494 | inst.instruction = NEON_ENC_LANE (inst.instruction); | |
13495 | do_neon_ld_st_lane (); | |
13496 | } | |
13497 | ||
13498 | /* L bit comes from bit mask. */ | |
13499 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13500 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13501 | inst.instruction |= inst.operands[1].reg << 16; | |
13502 | ||
13503 | if (inst.operands[1].postind) | |
13504 | { | |
13505 | int postreg = inst.operands[1].imm & 0xf; | |
13506 | constraint (!inst.operands[1].immisreg, | |
13507 | _("post-index must be a register")); | |
13508 | constraint (postreg == 0xd || postreg == 0xf, | |
13509 | _("bad register for post-index")); | |
13510 | inst.instruction |= postreg; | |
13511 | } | |
13512 | else if (inst.operands[1].writeback) | |
13513 | { | |
13514 | inst.instruction |= 0xd; | |
13515 | } | |
13516 | else | |
13517 | inst.instruction |= 0xf; | |
13518 | ||
13519 | if (thumb_mode) | |
13520 | inst.instruction |= 0xf9000000; | |
13521 | else | |
13522 | inst.instruction |= 0xf4000000; | |
13523 | } | |
13524 | ||
13525 | \f | |
13526 | /* Overall per-instruction processing. */ | |
13527 | ||
13528 | /* We need to be able to fix up arbitrary expressions in some statements. | |
13529 | This is so that we can handle symbols that are an arbitrary distance from | |
13530 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
13531 | which returns part of an address in a form which will be valid for | |
13532 | a data instruction. We do this by pushing the expression into a symbol | |
13533 | in the expr_section, and creating a fix for that. */ | |
13534 | ||
13535 | static void | |
13536 | fix_new_arm (fragS * frag, | |
13537 | int where, | |
13538 | short int size, | |
13539 | expressionS * exp, | |
13540 | int pc_rel, | |
13541 | int reloc) | |
13542 | { | |
13543 | fixS * new_fix; | |
13544 | ||
13545 | switch (exp->X_op) | |
13546 | { | |
13547 | case O_constant: | |
13548 | case O_symbol: | |
13549 | case O_add: | |
13550 | case O_subtract: | |
13551 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
13552 | break; | |
13553 | ||
13554 | default: | |
13555 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
13556 | pc_rel, reloc); | |
13557 | break; | |
13558 | } | |
13559 | ||
13560 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
13561 | instruction. */ | |
13562 | new_fix->tc_fix_data = thumb_mode; | |
13563 | } | |
13564 | ||
13565 | /* Create a frg for an instruction requiring relaxation. */ | |
13566 | static void | |
13567 | output_relax_insn (void) | |
13568 | { | |
13569 | char * to; | |
13570 | symbolS *sym; | |
0110f2b8 PB |
13571 | int offset; |
13572 | ||
6e1cb1a6 PB |
13573 | /* The size of the instruction is unknown, so tie the debug info to the |
13574 | start of the instruction. */ | |
13575 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 13576 | |
0110f2b8 PB |
13577 | switch (inst.reloc.exp.X_op) |
13578 | { | |
13579 | case O_symbol: | |
13580 | sym = inst.reloc.exp.X_add_symbol; | |
13581 | offset = inst.reloc.exp.X_add_number; | |
13582 | break; | |
13583 | case O_constant: | |
13584 | sym = NULL; | |
13585 | offset = inst.reloc.exp.X_add_number; | |
13586 | break; | |
13587 | default: | |
13588 | sym = make_expr_symbol (&inst.reloc.exp); | |
13589 | offset = 0; | |
13590 | break; | |
13591 | } | |
13592 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
13593 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
13594 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
13595 | } |
13596 | ||
13597 | /* Write a 32-bit thumb instruction to buf. */ | |
13598 | static void | |
13599 | put_thumb32_insn (char * buf, unsigned long insn) | |
13600 | { | |
13601 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
13602 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
13603 | } | |
13604 | ||
b99bd4ef | 13605 | static void |
c19d1205 | 13606 | output_inst (const char * str) |
b99bd4ef | 13607 | { |
c19d1205 | 13608 | char * to = NULL; |
b99bd4ef | 13609 | |
c19d1205 | 13610 | if (inst.error) |
b99bd4ef | 13611 | { |
c19d1205 | 13612 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
13613 | return; |
13614 | } | |
0110f2b8 PB |
13615 | if (inst.relax) { |
13616 | output_relax_insn(); | |
13617 | return; | |
13618 | } | |
c19d1205 ZW |
13619 | if (inst.size == 0) |
13620 | return; | |
b99bd4ef | 13621 | |
c19d1205 ZW |
13622 | to = frag_more (inst.size); |
13623 | ||
13624 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 13625 | { |
c19d1205 | 13626 | assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 13627 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 13628 | } |
c19d1205 | 13629 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 13630 | { |
c19d1205 ZW |
13631 | assert (inst.size == (2 * INSN_SIZE)); |
13632 | md_number_to_chars (to, inst.instruction, INSN_SIZE); | |
13633 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 13634 | } |
c19d1205 ZW |
13635 | else |
13636 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 13637 | |
c19d1205 ZW |
13638 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
13639 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
13640 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
13641 | inst.reloc.type); | |
b99bd4ef | 13642 | |
c19d1205 | 13643 | dwarf2_emit_insn (inst.size); |
c19d1205 | 13644 | } |
b99bd4ef | 13645 | |
c19d1205 ZW |
13646 | /* Tag values used in struct asm_opcode's tag field. */ |
13647 | enum opcode_tag | |
13648 | { | |
13649 | OT_unconditional, /* Instruction cannot be conditionalized. | |
13650 | The ARM condition field is still 0xE. */ | |
13651 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
13652 | and carries 0xF in its ARM condition field. */ | |
13653 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
13654 | OT_csuffixF, /* Some forms of the instruction take a conditional |
13655 | suffix, others place 0xF where the condition field | |
13656 | would be. */ | |
c19d1205 ZW |
13657 | OT_cinfix3, /* Instruction takes a conditional infix, |
13658 | beginning at character index 3. (In | |
13659 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
13660 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
13661 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
13662 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
13663 | character index 3, even in unified mode. Used for | |
13664 | legacy instructions where suffix and infix forms | |
13665 | may be ambiguous. */ | |
c19d1205 | 13666 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 13667 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
13668 | OT_odd_infix_unc, /* This is the unconditional variant of an |
13669 | instruction that takes a conditional infix | |
13670 | at an unusual position. In unified mode, | |
13671 | this variant will accept a suffix. */ | |
13672 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
13673 | are the conditional variants of instructions that | |
13674 | take conditional infixes in unusual positions. | |
13675 | The infix appears at character index | |
13676 | (tag - OT_odd_infix_0). These are not accepted | |
13677 | in unified mode. */ | |
13678 | }; | |
b99bd4ef | 13679 | |
c19d1205 ZW |
13680 | /* Subroutine of md_assemble, responsible for looking up the primary |
13681 | opcode from the mnemonic the user wrote. STR points to the | |
13682 | beginning of the mnemonic. | |
13683 | ||
13684 | This is not simply a hash table lookup, because of conditional | |
13685 | variants. Most instructions have conditional variants, which are | |
13686 | expressed with a _conditional affix_ to the mnemonic. If we were | |
13687 | to encode each conditional variant as a literal string in the opcode | |
13688 | table, it would have approximately 20,000 entries. | |
13689 | ||
13690 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
13691 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
13692 | instructions take the affix as an infix, notably the s-variants of | |
13693 | the arithmetic instructions. Of those instructions, all but six | |
13694 | have the infix appear after the third character of the mnemonic. | |
13695 | ||
13696 | Accordingly, the algorithm for looking up primary opcodes given | |
13697 | an identifier is: | |
13698 | ||
13699 | 1. Look up the identifier in the opcode table. | |
13700 | If we find a match, go to step U. | |
13701 | ||
13702 | 2. Look up the last two characters of the identifier in the | |
13703 | conditions table. If we find a match, look up the first N-2 | |
13704 | characters of the identifier in the opcode table. If we | |
13705 | find a match, go to step CE. | |
13706 | ||
13707 | 3. Look up the fourth and fifth characters of the identifier in | |
13708 | the conditions table. If we find a match, extract those | |
13709 | characters from the identifier, and look up the remaining | |
13710 | characters in the opcode table. If we find a match, go | |
13711 | to step CM. | |
13712 | ||
13713 | 4. Fail. | |
13714 | ||
13715 | U. Examine the tag field of the opcode structure, in case this is | |
13716 | one of the six instructions with its conditional infix in an | |
13717 | unusual place. If it is, the tag tells us where to find the | |
13718 | infix; look it up in the conditions table and set inst.cond | |
13719 | accordingly. Otherwise, this is an unconditional instruction. | |
13720 | Again set inst.cond accordingly. Return the opcode structure. | |
13721 | ||
13722 | CE. Examine the tag field to make sure this is an instruction that | |
13723 | should receive a conditional suffix. If it is not, fail. | |
13724 | Otherwise, set inst.cond from the suffix we already looked up, | |
13725 | and return the opcode structure. | |
13726 | ||
13727 | CM. Examine the tag field to make sure this is an instruction that | |
13728 | should receive a conditional infix after the third character. | |
13729 | If it is not, fail. Otherwise, undo the edits to the current | |
13730 | line of input and proceed as for case CE. */ | |
13731 | ||
13732 | static const struct asm_opcode * | |
13733 | opcode_lookup (char **str) | |
13734 | { | |
13735 | char *end, *base; | |
13736 | char *affix; | |
13737 | const struct asm_opcode *opcode; | |
13738 | const struct asm_cond *cond; | |
e3cb604e | 13739 | char save[2]; |
267d2029 JB |
13740 | bfd_boolean neon_supported; |
13741 | ||
13742 | neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1); | |
c19d1205 ZW |
13743 | |
13744 | /* Scan up to the end of the mnemonic, which must end in white space, | |
267d2029 | 13745 | '.' (in unified mode, or for Neon instructions), or end of string. */ |
c19d1205 | 13746 | for (base = end = *str; *end != '\0'; end++) |
267d2029 | 13747 | if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.')) |
c19d1205 | 13748 | break; |
b99bd4ef | 13749 | |
c19d1205 ZW |
13750 | if (end == base) |
13751 | return 0; | |
b99bd4ef | 13752 | |
5287ad62 | 13753 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 13754 | if (end[0] == '.') |
b99bd4ef | 13755 | { |
5287ad62 JB |
13756 | int offset = 2; |
13757 | ||
267d2029 JB |
13758 | /* The .w and .n suffixes are only valid if the unified syntax is in |
13759 | use. */ | |
13760 | if (unified_syntax && end[1] == 'w') | |
c19d1205 | 13761 | inst.size_req = 4; |
267d2029 | 13762 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
13763 | inst.size_req = 2; |
13764 | else | |
5287ad62 JB |
13765 | offset = 0; |
13766 | ||
13767 | inst.vectype.elems = 0; | |
13768 | ||
13769 | *str = end + offset; | |
b99bd4ef | 13770 | |
5287ad62 JB |
13771 | if (end[offset] == '.') |
13772 | { | |
267d2029 JB |
13773 | /* See if we have a Neon type suffix (possible in either unified or |
13774 | non-unified ARM syntax mode). */ | |
dcbf9037 | 13775 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
5287ad62 JB |
13776 | return 0; |
13777 | } | |
13778 | else if (end[offset] != '\0' && end[offset] != ' ') | |
13779 | return 0; | |
b99bd4ef | 13780 | } |
c19d1205 ZW |
13781 | else |
13782 | *str = end; | |
b99bd4ef | 13783 | |
c19d1205 ZW |
13784 | /* Look for unaffixed or special-case affixed mnemonic. */ |
13785 | opcode = hash_find_n (arm_ops_hsh, base, end - base); | |
13786 | if (opcode) | |
b99bd4ef | 13787 | { |
c19d1205 ZW |
13788 | /* step U */ |
13789 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 13790 | { |
c19d1205 ZW |
13791 | inst.cond = COND_ALWAYS; |
13792 | return opcode; | |
b99bd4ef | 13793 | } |
b99bd4ef | 13794 | |
c19d1205 ZW |
13795 | if (unified_syntax) |
13796 | as_warn (_("conditional infixes are deprecated in unified syntax")); | |
13797 | affix = base + (opcode->tag - OT_odd_infix_0); | |
13798 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
13799 | assert (cond); | |
b99bd4ef | 13800 | |
c19d1205 ZW |
13801 | inst.cond = cond->value; |
13802 | return opcode; | |
13803 | } | |
b99bd4ef | 13804 | |
c19d1205 ZW |
13805 | /* Cannot have a conditional suffix on a mnemonic of less than two |
13806 | characters. */ | |
13807 | if (end - base < 3) | |
13808 | return 0; | |
b99bd4ef | 13809 | |
c19d1205 ZW |
13810 | /* Look for suffixed mnemonic. */ |
13811 | affix = end - 2; | |
13812 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
13813 | opcode = hash_find_n (arm_ops_hsh, base, affix - base); | |
13814 | if (opcode && cond) | |
13815 | { | |
13816 | /* step CE */ | |
13817 | switch (opcode->tag) | |
13818 | { | |
e3cb604e PB |
13819 | case OT_cinfix3_legacy: |
13820 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
13821 | break; | |
13822 | ||
c19d1205 | 13823 | case OT_cinfix3: |
088fa78e | 13824 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
13825 | case OT_odd_infix_unc: |
13826 | if (!unified_syntax) | |
e3cb604e | 13827 | return 0; |
c19d1205 ZW |
13828 | /* else fall through */ |
13829 | ||
13830 | case OT_csuffix: | |
037e8744 | 13831 | case OT_csuffixF: |
c19d1205 ZW |
13832 | case OT_csuf_or_in3: |
13833 | inst.cond = cond->value; | |
13834 | return opcode; | |
13835 | ||
13836 | case OT_unconditional: | |
13837 | case OT_unconditionalF: | |
dfa9f0d5 PB |
13838 | if (thumb_mode) |
13839 | { | |
13840 | inst.cond = cond->value; | |
13841 | } | |
13842 | else | |
13843 | { | |
13844 | /* delayed diagnostic */ | |
13845 | inst.error = BAD_COND; | |
13846 | inst.cond = COND_ALWAYS; | |
13847 | } | |
c19d1205 | 13848 | return opcode; |
b99bd4ef | 13849 | |
c19d1205 ZW |
13850 | default: |
13851 | return 0; | |
13852 | } | |
13853 | } | |
b99bd4ef | 13854 | |
c19d1205 ZW |
13855 | /* Cannot have a usual-position infix on a mnemonic of less than |
13856 | six characters (five would be a suffix). */ | |
13857 | if (end - base < 6) | |
13858 | return 0; | |
b99bd4ef | 13859 | |
c19d1205 ZW |
13860 | /* Look for infixed mnemonic in the usual position. */ |
13861 | affix = base + 3; | |
13862 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
e3cb604e PB |
13863 | if (!cond) |
13864 | return 0; | |
13865 | ||
13866 | memcpy (save, affix, 2); | |
13867 | memmove (affix, affix + 2, (end - affix) - 2); | |
13868 | opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2); | |
13869 | memmove (affix + 2, affix, (end - affix) - 2); | |
13870 | memcpy (affix, save, 2); | |
13871 | ||
088fa78e KH |
13872 | if (opcode |
13873 | && (opcode->tag == OT_cinfix3 | |
13874 | || opcode->tag == OT_cinfix3_deprecated | |
13875 | || opcode->tag == OT_csuf_or_in3 | |
13876 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 13877 | { |
c19d1205 | 13878 | /* step CM */ |
088fa78e KH |
13879 | if (unified_syntax |
13880 | && (opcode->tag == OT_cinfix3 | |
13881 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
13882 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
13883 | ||
13884 | inst.cond = cond->value; | |
13885 | return opcode; | |
b99bd4ef NC |
13886 | } |
13887 | ||
c19d1205 | 13888 | return 0; |
b99bd4ef NC |
13889 | } |
13890 | ||
c19d1205 ZW |
13891 | void |
13892 | md_assemble (char *str) | |
b99bd4ef | 13893 | { |
c19d1205 ZW |
13894 | char *p = str; |
13895 | const struct asm_opcode * opcode; | |
b99bd4ef | 13896 | |
c19d1205 ZW |
13897 | /* Align the previous label if needed. */ |
13898 | if (last_label_seen != NULL) | |
b99bd4ef | 13899 | { |
c19d1205 ZW |
13900 | symbol_set_frag (last_label_seen, frag_now); |
13901 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
13902 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
13903 | } |
13904 | ||
c19d1205 ZW |
13905 | memset (&inst, '\0', sizeof (inst)); |
13906 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 13907 | |
c19d1205 ZW |
13908 | opcode = opcode_lookup (&p); |
13909 | if (!opcode) | |
b99bd4ef | 13910 | { |
c19d1205 | 13911 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 JB |
13912 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
13913 | if (!create_register_alias (str, p) | |
13914 | && !create_neon_reg_alias (str, p)) | |
c19d1205 | 13915 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 13916 | |
b99bd4ef NC |
13917 | return; |
13918 | } | |
13919 | ||
088fa78e KH |
13920 | if (opcode->tag == OT_cinfix3_deprecated) |
13921 | as_warn (_("s suffix on comparison instruction is deprecated")); | |
13922 | ||
037e8744 JB |
13923 | /* The value which unconditional instructions should have in place of the |
13924 | condition field. */ | |
13925 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
13926 | ||
c19d1205 | 13927 | if (thumb_mode) |
b99bd4ef | 13928 | { |
e74cfd16 | 13929 | arm_feature_set variant; |
8f06b2d8 PB |
13930 | |
13931 | variant = cpu_variant; | |
13932 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
13933 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
13934 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 13935 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
13936 | if (!opcode->tvariant |
13937 | || (thumb_mode == 1 | |
13938 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 13939 | { |
c19d1205 | 13940 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
13941 | return; |
13942 | } | |
c19d1205 ZW |
13943 | if (inst.cond != COND_ALWAYS && !unified_syntax |
13944 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 13945 | { |
c19d1205 | 13946 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
13947 | return; |
13948 | } | |
13949 | ||
e27ec89e PB |
13950 | /* Check conditional suffixes. */ |
13951 | if (current_it_mask) | |
13952 | { | |
13953 | int cond; | |
13954 | cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1; | |
dfa9f0d5 PB |
13955 | current_it_mask <<= 1; |
13956 | current_it_mask &= 0x1f; | |
13957 | /* The BKPT instruction is unconditional even in an IT block. */ | |
13958 | if (!inst.error | |
13959 | && cond != inst.cond && opcode->tencode != do_t_bkpt) | |
e27ec89e PB |
13960 | { |
13961 | as_bad (_("incorrect condition in IT block")); | |
13962 | return; | |
13963 | } | |
e27ec89e PB |
13964 | } |
13965 | else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch) | |
13966 | { | |
13967 | as_bad (_("thumb conditional instrunction not in IT block")); | |
13968 | return; | |
13969 | } | |
13970 | ||
c19d1205 ZW |
13971 | mapping_state (MAP_THUMB); |
13972 | inst.instruction = opcode->tvalue; | |
13973 | ||
13974 | if (!parse_operands (p, opcode->operands)) | |
13975 | opcode->tencode (); | |
13976 | ||
e27ec89e PB |
13977 | /* Clear current_it_mask at the end of an IT block. */ |
13978 | if (current_it_mask == 0x10) | |
13979 | current_it_mask = 0; | |
13980 | ||
0110f2b8 | 13981 | if (!(inst.error || inst.relax)) |
b99bd4ef | 13982 | { |
c19d1205 ZW |
13983 | assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
13984 | inst.size = (inst.instruction > 0xffff ? 4 : 2); | |
13985 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 13986 | { |
c19d1205 | 13987 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
13988 | return; |
13989 | } | |
13990 | } | |
e74cfd16 PB |
13991 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
13992 | *opcode->tvariant); | |
ee065d83 | 13993 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 13994 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
ee065d83 PB |
13995 | anything other than bl/blx. |
13996 | This is overly pessimistic for relaxable instructions. */ | |
13997 | if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) | |
13998 | || inst.relax) | |
e74cfd16 PB |
13999 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
14000 | arm_ext_v6t2); | |
c19d1205 | 14001 | } |
3e9e4fcf | 14002 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
14003 | { |
14004 | /* Check that this instruction is supported for this CPU. */ | |
62b3e311 PB |
14005 | if (!opcode->avariant || |
14006 | !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)) | |
b99bd4ef | 14007 | { |
c19d1205 ZW |
14008 | as_bad (_("selected processor does not support `%s'"), str); |
14009 | return; | |
b99bd4ef | 14010 | } |
c19d1205 | 14011 | if (inst.size_req) |
b99bd4ef | 14012 | { |
c19d1205 ZW |
14013 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
14014 | return; | |
b99bd4ef NC |
14015 | } |
14016 | ||
c19d1205 ZW |
14017 | mapping_state (MAP_ARM); |
14018 | inst.instruction = opcode->avalue; | |
14019 | if (opcode->tag == OT_unconditionalF) | |
14020 | inst.instruction |= 0xF << 28; | |
14021 | else | |
14022 | inst.instruction |= inst.cond << 28; | |
14023 | inst.size = INSN_SIZE; | |
14024 | if (!parse_operands (p, opcode->operands)) | |
14025 | opcode->aencode (); | |
ee065d83 PB |
14026 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
14027 | on a hypothetical non-thumb v5 core. */ | |
e74cfd16 PB |
14028 | if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t) |
14029 | || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5)) | |
14030 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); | |
ee065d83 | 14031 | else |
e74cfd16 PB |
14032 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
14033 | *opcode->avariant); | |
b99bd4ef | 14034 | } |
3e9e4fcf JB |
14035 | else |
14036 | { | |
14037 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
14038 | "-- `%s'"), str); | |
14039 | return; | |
14040 | } | |
c19d1205 ZW |
14041 | output_inst (str); |
14042 | } | |
b99bd4ef | 14043 | |
c19d1205 ZW |
14044 | /* Various frobbings of labels and their addresses. */ |
14045 | ||
14046 | void | |
14047 | arm_start_line_hook (void) | |
14048 | { | |
14049 | last_label_seen = NULL; | |
b99bd4ef NC |
14050 | } |
14051 | ||
c19d1205 ZW |
14052 | void |
14053 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 14054 | { |
c19d1205 | 14055 | last_label_seen = sym; |
b99bd4ef | 14056 | |
c19d1205 | 14057 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 14058 | |
c19d1205 ZW |
14059 | #if defined OBJ_COFF || defined OBJ_ELF |
14060 | ARM_SET_INTERWORK (sym, support_interwork); | |
14061 | #endif | |
b99bd4ef | 14062 | |
c19d1205 ZW |
14063 | /* Note - do not allow local symbols (.Lxxx) to be labeled |
14064 | as Thumb functions. This is because these labels, whilst | |
14065 | they exist inside Thumb code, are not the entry points for | |
14066 | possible ARM->Thumb calls. Also, these labels can be used | |
14067 | as part of a computed goto or switch statement. eg gcc | |
14068 | can generate code that looks like this: | |
b99bd4ef | 14069 | |
c19d1205 ZW |
14070 | ldr r2, [pc, .Laaa] |
14071 | lsl r3, r3, #2 | |
14072 | ldr r2, [r3, r2] | |
14073 | mov pc, r2 | |
b99bd4ef | 14074 | |
c19d1205 ZW |
14075 | .Lbbb: .word .Lxxx |
14076 | .Lccc: .word .Lyyy | |
14077 | ..etc... | |
14078 | .Laaa: .word Lbbb | |
b99bd4ef | 14079 | |
c19d1205 ZW |
14080 | The first instruction loads the address of the jump table. |
14081 | The second instruction converts a table index into a byte offset. | |
14082 | The third instruction gets the jump address out of the table. | |
14083 | The fourth instruction performs the jump. | |
b99bd4ef | 14084 | |
c19d1205 ZW |
14085 | If the address stored at .Laaa is that of a symbol which has the |
14086 | Thumb_Func bit set, then the linker will arrange for this address | |
14087 | to have the bottom bit set, which in turn would mean that the | |
14088 | address computation performed by the third instruction would end | |
14089 | up with the bottom bit set. Since the ARM is capable of unaligned | |
14090 | word loads, the instruction would then load the incorrect address | |
14091 | out of the jump table, and chaos would ensue. */ | |
14092 | if (label_is_thumb_function_name | |
14093 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
14094 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 14095 | { |
c19d1205 ZW |
14096 | /* When the address of a Thumb function is taken the bottom |
14097 | bit of that address should be set. This will allow | |
14098 | interworking between Arm and Thumb functions to work | |
14099 | correctly. */ | |
b99bd4ef | 14100 | |
c19d1205 | 14101 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 14102 | |
c19d1205 | 14103 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 14104 | } |
07a53e5c | 14105 | |
07a53e5c | 14106 | dwarf2_emit_label (sym); |
b99bd4ef NC |
14107 | } |
14108 | ||
c19d1205 ZW |
14109 | int |
14110 | arm_data_in_code (void) | |
b99bd4ef | 14111 | { |
c19d1205 | 14112 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 14113 | { |
c19d1205 ZW |
14114 | *input_line_pointer = '/'; |
14115 | input_line_pointer += 5; | |
14116 | *input_line_pointer = 0; | |
14117 | return 1; | |
b99bd4ef NC |
14118 | } |
14119 | ||
c19d1205 | 14120 | return 0; |
b99bd4ef NC |
14121 | } |
14122 | ||
c19d1205 ZW |
14123 | char * |
14124 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 14125 | { |
c19d1205 | 14126 | int len; |
b99bd4ef | 14127 | |
c19d1205 ZW |
14128 | if (thumb_mode && (len = strlen (name)) > 5 |
14129 | && streq (name + len - 5, "/data")) | |
14130 | *(name + len - 5) = 0; | |
b99bd4ef | 14131 | |
c19d1205 | 14132 | return name; |
b99bd4ef | 14133 | } |
c19d1205 ZW |
14134 | \f |
14135 | /* Table of all register names defined by default. The user can | |
14136 | define additional names with .req. Note that all register names | |
14137 | should appear in both upper and lowercase variants. Some registers | |
14138 | also have mixed-case names. */ | |
b99bd4ef | 14139 | |
dcbf9037 | 14140 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 14141 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 14142 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
14143 | #define REGSET(p,t) \ |
14144 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
14145 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
14146 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
14147 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
14148 | #define REGSETH(p,t) \ |
14149 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
14150 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
14151 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
14152 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
14153 | #define REGSET2(p,t) \ | |
14154 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
14155 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
14156 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
14157 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
7ed4c4c5 | 14158 | |
c19d1205 | 14159 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 14160 | { |
c19d1205 ZW |
14161 | /* ARM integer registers. */ |
14162 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 14163 | |
c19d1205 ZW |
14164 | /* ATPCS synonyms. */ |
14165 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
14166 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
14167 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 14168 | |
c19d1205 ZW |
14169 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
14170 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
14171 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 14172 | |
c19d1205 ZW |
14173 | /* Well-known aliases. */ |
14174 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
14175 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
14176 | ||
14177 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
14178 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
14179 | ||
14180 | /* Coprocessor numbers. */ | |
14181 | REGSET(p, CP), REGSET(P, CP), | |
14182 | ||
14183 | /* Coprocessor register numbers. The "cr" variants are for backward | |
14184 | compatibility. */ | |
14185 | REGSET(c, CN), REGSET(C, CN), | |
14186 | REGSET(cr, CN), REGSET(CR, CN), | |
14187 | ||
14188 | /* FPA registers. */ | |
14189 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
14190 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
14191 | ||
14192 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
14193 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
14194 | ||
14195 | /* VFP SP registers. */ | |
5287ad62 JB |
14196 | REGSET(s,VFS), REGSET(S,VFS), |
14197 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
14198 | |
14199 | /* VFP DP Registers. */ | |
5287ad62 JB |
14200 | REGSET(d,VFD), REGSET(D,VFD), |
14201 | /* Extra Neon DP registers. */ | |
14202 | REGSETH(d,VFD), REGSETH(D,VFD), | |
14203 | ||
14204 | /* Neon QP registers. */ | |
14205 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
14206 | |
14207 | /* VFP control registers. */ | |
14208 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
14209 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
14210 | ||
14211 | /* Maverick DSP coprocessor registers. */ | |
14212 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
14213 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
14214 | ||
14215 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
14216 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
14217 | REGDEF(dspsc,0,DSPSC), | |
14218 | ||
14219 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
14220 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
14221 | REGDEF(DSPSC,0,DSPSC), | |
14222 | ||
14223 | /* iWMMXt data registers - p0, c0-15. */ | |
14224 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
14225 | ||
14226 | /* iWMMXt control registers - p1, c0-3. */ | |
14227 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
14228 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
14229 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
14230 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
14231 | ||
14232 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
14233 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
14234 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
14235 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
14236 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
14237 | ||
14238 | /* XScale accumulator registers. */ | |
14239 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
14240 | }; | |
14241 | #undef REGDEF | |
14242 | #undef REGNUM | |
14243 | #undef REGSET | |
7ed4c4c5 | 14244 | |
c19d1205 ZW |
14245 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
14246 | within psr_required_here. */ | |
14247 | static const struct asm_psr psrs[] = | |
14248 | { | |
14249 | /* Backward compatibility notation. Note that "all" is no longer | |
14250 | truly all possible PSR bits. */ | |
14251 | {"all", PSR_c | PSR_f}, | |
14252 | {"flg", PSR_f}, | |
14253 | {"ctl", PSR_c}, | |
14254 | ||
14255 | /* Individual flags. */ | |
14256 | {"f", PSR_f}, | |
14257 | {"c", PSR_c}, | |
14258 | {"x", PSR_x}, | |
14259 | {"s", PSR_s}, | |
14260 | /* Combinations of flags. */ | |
14261 | {"fs", PSR_f | PSR_s}, | |
14262 | {"fx", PSR_f | PSR_x}, | |
14263 | {"fc", PSR_f | PSR_c}, | |
14264 | {"sf", PSR_s | PSR_f}, | |
14265 | {"sx", PSR_s | PSR_x}, | |
14266 | {"sc", PSR_s | PSR_c}, | |
14267 | {"xf", PSR_x | PSR_f}, | |
14268 | {"xs", PSR_x | PSR_s}, | |
14269 | {"xc", PSR_x | PSR_c}, | |
14270 | {"cf", PSR_c | PSR_f}, | |
14271 | {"cs", PSR_c | PSR_s}, | |
14272 | {"cx", PSR_c | PSR_x}, | |
14273 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
14274 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
14275 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
14276 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
14277 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
14278 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
14279 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
14280 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
14281 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
14282 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
14283 | {"scf", PSR_s | PSR_c | PSR_f}, | |
14284 | {"scx", PSR_s | PSR_c | PSR_x}, | |
14285 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
14286 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
14287 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
14288 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
14289 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
14290 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
14291 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
14292 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
14293 | {"csf", PSR_c | PSR_s | PSR_f}, | |
14294 | {"csx", PSR_c | PSR_s | PSR_x}, | |
14295 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
14296 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
14297 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
14298 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
14299 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
14300 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
14301 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
14302 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
14303 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
14304 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
14305 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
14306 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
14307 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
14308 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
14309 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
14310 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
14311 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
14312 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
14313 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
14314 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
14315 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
14316 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
14317 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
14318 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
14319 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
14320 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
14321 | }; | |
14322 | ||
62b3e311 PB |
14323 | /* Table of V7M psr names. */ |
14324 | static const struct asm_psr v7m_psrs[] = | |
14325 | { | |
14326 | {"apsr", 0 }, | |
14327 | {"iapsr", 1 }, | |
14328 | {"eapsr", 2 }, | |
14329 | {"psr", 3 }, | |
14330 | {"ipsr", 5 }, | |
14331 | {"epsr", 6 }, | |
14332 | {"iepsr", 7 }, | |
14333 | {"msp", 8 }, | |
14334 | {"psp", 9 }, | |
14335 | {"primask", 16}, | |
14336 | {"basepri", 17}, | |
14337 | {"basepri_max", 18}, | |
14338 | {"faultmask", 19}, | |
14339 | {"control", 20} | |
14340 | }; | |
14341 | ||
c19d1205 ZW |
14342 | /* Table of all shift-in-operand names. */ |
14343 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 14344 | { |
c19d1205 ZW |
14345 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
14346 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
14347 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
14348 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
14349 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
14350 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
14351 | }; | |
b99bd4ef | 14352 | |
c19d1205 ZW |
14353 | /* Table of all explicit relocation names. */ |
14354 | #ifdef OBJ_ELF | |
14355 | static struct reloc_entry reloc_names[] = | |
14356 | { | |
14357 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
14358 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
14359 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
14360 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
14361 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
14362 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
14363 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
14364 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
14365 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
14366 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
14367 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
14368 | }; | |
14369 | #endif | |
b99bd4ef | 14370 | |
c19d1205 ZW |
14371 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
14372 | static const struct asm_cond conds[] = | |
14373 | { | |
14374 | {"eq", 0x0}, | |
14375 | {"ne", 0x1}, | |
14376 | {"cs", 0x2}, {"hs", 0x2}, | |
14377 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
14378 | {"mi", 0x4}, | |
14379 | {"pl", 0x5}, | |
14380 | {"vs", 0x6}, | |
14381 | {"vc", 0x7}, | |
14382 | {"hi", 0x8}, | |
14383 | {"ls", 0x9}, | |
14384 | {"ge", 0xa}, | |
14385 | {"lt", 0xb}, | |
14386 | {"gt", 0xc}, | |
14387 | {"le", 0xd}, | |
14388 | {"al", 0xe} | |
14389 | }; | |
bfae80f2 | 14390 | |
62b3e311 PB |
14391 | static struct asm_barrier_opt barrier_opt_names[] = |
14392 | { | |
14393 | { "sy", 0xf }, | |
14394 | { "un", 0x7 }, | |
14395 | { "st", 0xe }, | |
14396 | { "unst", 0x6 } | |
14397 | }; | |
14398 | ||
c19d1205 ZW |
14399 | /* Table of ARM-format instructions. */ |
14400 | ||
14401 | /* Macros for gluing together operand strings. N.B. In all cases | |
14402 | other than OPS0, the trailing OP_stop comes from default | |
14403 | zero-initialization of the unspecified elements of the array. */ | |
14404 | #define OPS0() { OP_stop, } | |
14405 | #define OPS1(a) { OP_##a, } | |
14406 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
14407 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
14408 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
14409 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
14410 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
14411 | ||
14412 | /* These macros abstract out the exact format of the mnemonic table and | |
14413 | save some repeated characters. */ | |
14414 | ||
14415 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
14416 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
14417 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 14418 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14419 | |
14420 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
14421 | a T_MNEM_xyz enumerator. */ | |
14422 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
14423 | TxCE(mnem, aop, 0x##top, nops, ops, ae, te) | |
14424 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ | |
14425 | TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
14426 | ||
14427 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
14428 | infix after the third character. */ | |
14429 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
14430 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 14431 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e KH |
14432 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
14433 | { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ | |
14434 | THUMB_VARIANT, do_##ae, do_##te } | |
c19d1205 ZW |
14435 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
14436 | TxC3(mnem, aop, 0x##top, nops, ops, ae, te) | |
088fa78e KH |
14437 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
14438 | TxC3w(mnem, aop, 0x##top, nops, ops, ae, te) | |
c19d1205 ZW |
14439 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
14440 | TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
088fa78e KH |
14441 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
14442 | TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
c19d1205 ZW |
14443 | |
14444 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
14445 | appear in the condition table. */ | |
14446 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
14447 | { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
1887dd22 | 14448 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14449 | |
14450 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
14451 | TxCM_(m1, , m2, op, top, nops, ops, ae, te), \ | |
14452 | TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \ | |
14453 | TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \ | |
14454 | TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \ | |
14455 | TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \ | |
14456 | TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \ | |
14457 | TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \ | |
14458 | TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \ | |
14459 | TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \ | |
14460 | TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \ | |
14461 | TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \ | |
14462 | TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \ | |
14463 | TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \ | |
14464 | TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \ | |
14465 | TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \ | |
14466 | TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \ | |
14467 | TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \ | |
14468 | TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \ | |
14469 | TxCM_(m1, al, m2, op, top, nops, ops, ae, te) | |
14470 | ||
14471 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
14472 | TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te) | |
14473 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
14474 | TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
14475 | ||
14476 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
14477 | field is still 0xE. Many of the Thumb variants can be executed |
14478 | conditionally, so this is checked separately. */ | |
c19d1205 ZW |
14479 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
14480 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 14481 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14482 | |
14483 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
14484 | condition code field. */ | |
14485 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
14486 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 14487 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
14488 | |
14489 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
14490 | #define CE(mnem, op, nops, ops, ae) \ |
14491 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14492 | ||
14493 | #define C3(mnem, op, nops, ops, ae) \ | |
14494 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14495 | ||
e3cb604e PB |
14496 | /* Legacy mnemonics that always have conditional infix after the third |
14497 | character. */ | |
14498 | #define CL(mnem, op, nops, ops, ae) \ | |
14499 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
14500 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14501 | ||
8f06b2d8 PB |
14502 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
14503 | #define cCE(mnem, op, nops, ops, ae) \ | |
14504 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
14505 | ||
e3cb604e PB |
14506 | /* Legacy coprocessor instructions where conditional infix and conditional |
14507 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
14508 | not just the potentially ambiguous ones. */ | |
14509 | #define cCL(mnem, op, nops, ops, ae) \ | |
14510 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
14511 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
14512 | ||
14513 | /* Coprocessor, takes either a suffix or a position-3 infix | |
14514 | (for an FPA corner case). */ | |
14515 | #define C3E(mnem, op, nops, ops, ae) \ | |
14516 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
14517 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 14518 | |
6a86118a NC |
14519 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
14520 | { #m1 #m2 #m3, OPS##nops ops, \ | |
14521 | sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
14522 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
14523 | ||
14524 | #define CM(m1, m2, op, nops, ops, ae) \ | |
14525 | xCM_(m1, , m2, op, nops, ops, ae), \ | |
14526 | xCM_(m1, eq, m2, op, nops, ops, ae), \ | |
14527 | xCM_(m1, ne, m2, op, nops, ops, ae), \ | |
14528 | xCM_(m1, cs, m2, op, nops, ops, ae), \ | |
14529 | xCM_(m1, hs, m2, op, nops, ops, ae), \ | |
14530 | xCM_(m1, cc, m2, op, nops, ops, ae), \ | |
14531 | xCM_(m1, ul, m2, op, nops, ops, ae), \ | |
14532 | xCM_(m1, lo, m2, op, nops, ops, ae), \ | |
14533 | xCM_(m1, mi, m2, op, nops, ops, ae), \ | |
14534 | xCM_(m1, pl, m2, op, nops, ops, ae), \ | |
14535 | xCM_(m1, vs, m2, op, nops, ops, ae), \ | |
14536 | xCM_(m1, vc, m2, op, nops, ops, ae), \ | |
14537 | xCM_(m1, hi, m2, op, nops, ops, ae), \ | |
14538 | xCM_(m1, ls, m2, op, nops, ops, ae), \ | |
14539 | xCM_(m1, ge, m2, op, nops, ops, ae), \ | |
14540 | xCM_(m1, lt, m2, op, nops, ops, ae), \ | |
14541 | xCM_(m1, gt, m2, op, nops, ops, ae), \ | |
14542 | xCM_(m1, le, m2, op, nops, ops, ae), \ | |
14543 | xCM_(m1, al, m2, op, nops, ops, ae) | |
14544 | ||
14545 | #define UE(mnem, op, nops, ops, ae) \ | |
14546 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
14547 | ||
14548 | #define UF(mnem, op, nops, ops, ae) \ | |
14549 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
14550 | ||
5287ad62 JB |
14551 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
14552 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
14553 | use the same encoding function for each. */ | |
14554 | #define NUF(mnem, op, nops, ops, enc) \ | |
14555 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
14556 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
14557 | ||
14558 | /* Neon data processing, version which indirects through neon_enc_tab for | |
14559 | the various overloaded versions of opcodes. */ | |
14560 | #define nUF(mnem, op, nops, ops, enc) \ | |
14561 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \ | |
14562 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
14563 | ||
14564 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
14565 | version. */ | |
037e8744 JB |
14566 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
14567 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
14568 | THUMB_VARIANT, do_##enc, do_##enc } |
14569 | ||
037e8744 JB |
14570 | #define NCE(mnem, op, nops, ops, enc) \ |
14571 | NCE_tag(mnem, op, nops, ops, enc, OT_csuffix) | |
14572 | ||
14573 | #define NCEF(mnem, op, nops, ops, enc) \ | |
14574 | NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF) | |
14575 | ||
5287ad62 | 14576 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 JB |
14577 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
14578 | { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \ | |
5287ad62 JB |
14579 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
14580 | ||
037e8744 JB |
14581 | #define nCE(mnem, op, nops, ops, enc) \ |
14582 | nCE_tag(mnem, op, nops, ops, enc, OT_csuffix) | |
14583 | ||
14584 | #define nCEF(mnem, op, nops, ops, enc) \ | |
14585 | nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF) | |
14586 | ||
c19d1205 ZW |
14587 | #define do_0 0 |
14588 | ||
14589 | /* Thumb-only, unconditional. */ | |
14590 | #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te) | |
14591 | ||
c19d1205 | 14592 | static const struct asm_opcode insns[] = |
bfae80f2 | 14593 | { |
e74cfd16 PB |
14594 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
14595 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
14596 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
14597 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
14598 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
14599 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
14600 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
14601 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
4962c51a MS |
14602 | tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub), |
14603 | tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
c19d1205 ZW |
14604 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), |
14605 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
14606 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
14607 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
14608 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
14609 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
14610 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
14611 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
14612 | ||
14613 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
14614 | for setting PSR flag bits. They are obsolete in V6 and do not | |
14615 | have Thumb equivalents. */ | |
14616 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 14617 | tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 14618 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 | 14619 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
088fa78e | 14620 | tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
e3cb604e | 14621 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 | 14622 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 14623 | tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 14624 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
14625 | |
14626 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
14627 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
14628 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
14629 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
14630 | ||
4962c51a MS |
14631 | tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), |
14632 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
14633 | tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
14634 | tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
c19d1205 | 14635 | |
f5208ef2 | 14636 | tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
14637 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14638 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
f5208ef2 | 14639 | tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
14640 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14641 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
14642 | ||
14643 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
c16d2bf0 | 14644 | TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi), |
0110f2b8 | 14645 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 14646 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 14647 | |
c19d1205 | 14648 | /* Pseudo ops. */ |
e9f89963 | 14649 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
14650 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
14651 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
14652 | |
14653 | /* Thumb-compatibility pseudo ops. */ | |
14654 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
14655 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
14656 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
14657 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
14658 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 14659 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
14660 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
14661 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
14662 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
14663 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
14664 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
14665 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
14666 | ||
14667 | #undef THUMB_VARIANT | |
e74cfd16 | 14668 | #define THUMB_VARIANT &arm_ext_v6 |
2fc8bdac | 14669 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
14670 | |
14671 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
14672 | #undef THUMB_VARIANT | |
e74cfd16 | 14673 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14674 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
14675 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
14676 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 14677 | TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 14678 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
14679 | |
14680 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
3e94bf1a | 14681 | TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 14682 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), |
3e94bf1a | 14683 | TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 14684 | |
9c3c69f2 PB |
14685 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14686 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 14687 | |
9c3c69f2 PB |
14688 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
14689 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
14690 | |
14691 | /* V1 instructions with no Thumb analogue at all. */ | |
14692 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
14693 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
14694 | ||
14695 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
14696 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
14697 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
14698 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
14699 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
14700 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
14701 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
14702 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
14703 | ||
14704 | #undef ARM_VARIANT | |
e74cfd16 | 14705 | #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */ |
c19d1205 | 14706 | #undef THUMB_VARIANT |
e74cfd16 | 14707 | #define THUMB_VARIANT &arm_ext_v4t |
c19d1205 ZW |
14708 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
14709 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
14710 | ||
14711 | #undef THUMB_VARIANT | |
e74cfd16 | 14712 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14713 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
14714 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
14715 | ||
14716 | /* Generic coprocessor instructions. */ | |
14717 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
4962c51a MS |
14718 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
14719 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14720 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14721 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
14722 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), |
14723 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
14724 | ||
14725 | #undef ARM_VARIANT | |
e74cfd16 | 14726 | #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */ |
c19d1205 ZW |
14727 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
14728 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
14729 | ||
14730 | #undef ARM_VARIANT | |
e74cfd16 | 14731 | #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */ |
037e8744 JB |
14732 | TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
14733 | TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), | |
c19d1205 ZW |
14734 | |
14735 | #undef ARM_VARIANT | |
e74cfd16 | 14736 | #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */ |
c19d1205 ZW |
14737 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
14738 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14739 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
14740 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14741 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
14742 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14743 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
14744 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
14745 | ||
14746 | #undef ARM_VARIANT | |
e74cfd16 | 14747 | #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */ |
c19d1205 | 14748 | #undef THUMB_VARIANT |
e74cfd16 | 14749 | #define THUMB_VARIANT &arm_ext_v4t |
4962c51a MS |
14750 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), |
14751 | tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14752 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14753 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14754 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
14755 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 ZW |
14756 | |
14757 | #undef ARM_VARIANT | |
e74cfd16 | 14758 | #define ARM_VARIANT &arm_ext_v4t_5 |
c19d1205 ZW |
14759 | /* ARM Architecture 4T. */ |
14760 | /* Note: bx (and blx) are required on V5, even if the processor does | |
14761 | not support Thumb. */ | |
14762 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
14763 | ||
14764 | #undef ARM_VARIANT | |
e74cfd16 | 14765 | #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */ |
c19d1205 | 14766 | #undef THUMB_VARIANT |
e74cfd16 | 14767 | #define THUMB_VARIANT &arm_ext_v5t |
c19d1205 ZW |
14768 | /* Note: blx has 2 variants; the .value coded here is for |
14769 | BLX(2). Only this variant has conditional execution. */ | |
14770 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
14771 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
14772 | ||
14773 | #undef THUMB_VARIANT | |
e74cfd16 | 14774 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 | 14775 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
4962c51a MS |
14776 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
14777 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14778 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
14779 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
14780 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
14781 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
14782 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
14783 | ||
14784 | #undef ARM_VARIANT | |
e74cfd16 | 14785 | #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */ |
c19d1205 ZW |
14786 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
14787 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14788 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14789 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14790 | ||
14791 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14792 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
14793 | ||
14794 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14795 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14796 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14797 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
14798 | ||
14799 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14800 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14801 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14802 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14803 | ||
14804 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14805 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14806 | ||
14807 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14808 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14809 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14810 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
14811 | ||
14812 | #undef ARM_VARIANT | |
e74cfd16 | 14813 | #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */ |
c19d1205 | 14814 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
4962c51a MS |
14815 | TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), |
14816 | TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 ZW |
14817 | |
14818 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
14819 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
14820 | ||
14821 | #undef ARM_VARIANT | |
e74cfd16 | 14822 | #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */ |
c19d1205 ZW |
14823 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
14824 | ||
14825 | #undef ARM_VARIANT | |
e74cfd16 | 14826 | #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */ |
c19d1205 | 14827 | #undef THUMB_VARIANT |
e74cfd16 | 14828 | #define THUMB_VARIANT &arm_ext_v6 |
c19d1205 ZW |
14829 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
14830 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
14831 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
14832 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
14833 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
14834 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14835 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14836 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14837 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14838 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
14839 | ||
14840 | #undef THUMB_VARIANT | |
e74cfd16 | 14841 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14842 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
14843 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
14844 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 PB |
14845 | |
14846 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
14847 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
14848 | ||
14849 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
14850 | #undef THUMB_VARIANT | |
14851 | #define THUMB_VARIANT &arm_ext_v6_notm | |
dfa9f0d5 | 14852 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c19d1205 ZW |
14853 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
14854 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
14855 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14856 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14857 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14858 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14859 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14860 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14861 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14862 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14863 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14864 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14865 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14866 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14867 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14868 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14869 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14870 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14871 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14872 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14873 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14874 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14875 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14876 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14877 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14878 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14879 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14880 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14881 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14882 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14883 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14884 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14885 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14886 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14887 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14888 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14889 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14890 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
14891 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
14892 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
14893 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
14894 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
14895 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
14896 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
14897 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
14898 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
14899 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14900 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14901 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14902 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
14903 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14904 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14905 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
14906 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 14907 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
14908 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
14909 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14910 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14911 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14912 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14913 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14914 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14915 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
14916 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14917 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14918 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14919 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
14920 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14921 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14922 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14923 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14924 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14925 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14926 | TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs), | |
14927 | UF(srsib, 9cd0500, 1, (I31w), srs), | |
14928 | UF(srsda, 84d0500, 1, (I31w), srs), | |
14929 | TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs), | |
c19d1205 ZW |
14930 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
14931 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), | |
14932 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
14933 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
14934 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
c19d1205 ZW |
14935 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), |
14936 | ||
14937 | #undef ARM_VARIANT | |
e74cfd16 | 14938 | #define ARM_VARIANT &arm_ext_v6k |
c19d1205 | 14939 | #undef THUMB_VARIANT |
e74cfd16 | 14940 | #define THUMB_VARIANT &arm_ext_v6k |
c19d1205 ZW |
14941 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
14942 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
14943 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
14944 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
14945 | ||
ebdca51a PB |
14946 | #undef THUMB_VARIANT |
14947 | #define THUMB_VARIANT &arm_ext_v6_notm | |
14948 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), | |
14949 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
14950 | ||
c19d1205 | 14951 | #undef THUMB_VARIANT |
e74cfd16 | 14952 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14953 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
14954 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
c19d1205 ZW |
14955 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), |
14956 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
c19d1205 ZW |
14957 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
14958 | ||
14959 | #undef ARM_VARIANT | |
e74cfd16 | 14960 | #define ARM_VARIANT &arm_ext_v6z |
3eb17e6b | 14961 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 ZW |
14962 | |
14963 | #undef ARM_VARIANT | |
e74cfd16 | 14964 | #define ARM_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
14965 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
14966 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
14967 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
14968 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
14969 | ||
14970 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
b6895b4f PB |
14971 | TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), |
14972 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
401a54cf | 14973 | TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 ZW |
14974 | |
14975 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14976 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14977 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14978 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
14979 | ||
14980 | UT(cbnz, b900, 2, (RR, EXP), t_czb), | |
14981 | UT(cbz, b100, 2, (RR, EXP), t_czb), | |
f91e006c PB |
14982 | /* ARM does not really have an IT instruction, so always allow it. */ |
14983 | #undef ARM_VARIANT | |
14984 | #define ARM_VARIANT &arm_ext_v1 | |
c19d1205 ZW |
14985 | TUE(it, 0, bf08, 1, (COND), it, t_it), |
14986 | TUE(itt, 0, bf0c, 1, (COND), it, t_it), | |
14987 | TUE(ite, 0, bf04, 1, (COND), it, t_it), | |
14988 | TUE(ittt, 0, bf0e, 1, (COND), it, t_it), | |
14989 | TUE(itet, 0, bf06, 1, (COND), it, t_it), | |
14990 | TUE(itte, 0, bf0a, 1, (COND), it, t_it), | |
14991 | TUE(itee, 0, bf02, 1, (COND), it, t_it), | |
14992 | TUE(itttt, 0, bf0f, 1, (COND), it, t_it), | |
14993 | TUE(itett, 0, bf07, 1, (COND), it, t_it), | |
14994 | TUE(ittet, 0, bf0b, 1, (COND), it, t_it), | |
14995 | TUE(iteet, 0, bf03, 1, (COND), it, t_it), | |
14996 | TUE(ittte, 0, bf0d, 1, (COND), it, t_it), | |
14997 | TUE(itete, 0, bf05, 1, (COND), it, t_it), | |
14998 | TUE(ittee, 0, bf09, 1, (COND), it, t_it), | |
14999 | TUE(iteee, 0, bf01, 1, (COND), it, t_it), | |
15000 | ||
92e90b6e PB |
15001 | /* Thumb2 only instructions. */ |
15002 | #undef ARM_VARIANT | |
e74cfd16 | 15003 | #define ARM_VARIANT NULL |
92e90b6e PB |
15004 | |
15005 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
15006 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
15007 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), | |
15008 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
15009 | ||
62b3e311 PB |
15010 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
15011 | #undef THUMB_VARIANT | |
15012 | #define THUMB_VARIANT &arm_ext_div | |
15013 | TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), | |
15014 | TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
15015 | ||
15016 | /* ARM V7 instructions. */ | |
15017 | #undef ARM_VARIANT | |
15018 | #define ARM_VARIANT &arm_ext_v7 | |
15019 | #undef THUMB_VARIANT | |
15020 | #define THUMB_VARIANT &arm_ext_v7 | |
15021 | TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld), | |
15022 | TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
15023 | TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), | |
15024 | TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
15025 | TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
15026 | ||
c19d1205 | 15027 | #undef ARM_VARIANT |
e74cfd16 | 15028 | #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ |
8f06b2d8 PB |
15029 | cCE(wfs, e200110, 1, (RR), rd), |
15030 | cCE(rfs, e300110, 1, (RR), rd), | |
15031 | cCE(wfc, e400110, 1, (RR), rd), | |
15032 | cCE(rfc, e500110, 1, (RR), rd), | |
15033 | ||
4962c51a MS |
15034 | cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr), |
15035 | cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
15036 | cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
15037 | cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e | 15038 | |
4962c51a MS |
15039 | cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr), |
15040 | cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
15041 | cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
15042 | cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e PB |
15043 | |
15044 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
15045 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
15046 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
15047 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
15048 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
15049 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
15050 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
15051 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
15052 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
15053 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
15054 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
15055 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
15056 | ||
15057 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
15058 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
15059 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
15060 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
15061 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
15062 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
15063 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
15064 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
15065 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
15066 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
15067 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
15068 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
15069 | ||
15070 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
15071 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
15072 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
15073 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
15074 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
15075 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
15076 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
15077 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
15078 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
15079 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
15080 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
15081 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
15082 | ||
15083 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
15084 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
15085 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
15086 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
15087 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
15088 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
15089 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
15090 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
15091 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
15092 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
15093 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
15094 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
15095 | ||
15096 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
15097 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
15098 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
15099 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
15100 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
15101 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
15102 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
15103 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
15104 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
15105 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
15106 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
15107 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
15108 | ||
15109 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
15110 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
15111 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
15112 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
15113 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
15114 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
15115 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
15116 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
15117 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
15118 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
15119 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
15120 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
15121 | ||
15122 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
15123 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
15124 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
15125 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
15126 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
15127 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
15128 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
15129 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
15130 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
15131 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
15132 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
15133 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
15134 | ||
15135 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
15136 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
15137 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
15138 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
15139 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
15140 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
15141 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
15142 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
15143 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
15144 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
15145 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
15146 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
15147 | ||
15148 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
15149 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
15150 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
15151 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
15152 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
15153 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
15154 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
15155 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
15156 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
15157 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
15158 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
15159 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
15160 | ||
15161 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
15162 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
15163 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
15164 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
15165 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
15166 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
15167 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
15168 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
15169 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
15170 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
15171 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
15172 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
15173 | ||
15174 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
15175 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
15176 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
15177 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
15178 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
15179 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
15180 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
15181 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
15182 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
15183 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
15184 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
15185 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
15186 | ||
15187 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
15188 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
15189 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
15190 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
15191 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
15192 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
15193 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
15194 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
15195 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
15196 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
15197 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
15198 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
15199 | ||
15200 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
15201 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
15202 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
15203 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
15204 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
15205 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
15206 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
15207 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
15208 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
15209 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
15210 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
15211 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
15212 | ||
15213 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
15214 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
15215 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
15216 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
15217 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
15218 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
15219 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
15220 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
15221 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
15222 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
15223 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
15224 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
15225 | ||
15226 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
15227 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
15228 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
15229 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
15230 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
15231 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
15232 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
15233 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
15234 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
15235 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
15236 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
15237 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
15238 | ||
15239 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
15240 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
15241 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
15242 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
15243 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
15244 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
15245 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
15246 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
15247 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
15248 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
15249 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
15250 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
15251 | ||
15252 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15253 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15254 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15255 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15256 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15257 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15258 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15259 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15260 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15261 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15262 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15263 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15264 | ||
15265 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15266 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15267 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15268 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15269 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15270 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15271 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15272 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15273 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15274 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15275 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15276 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15277 | ||
15278 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15279 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15280 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15281 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15282 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15283 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15284 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15285 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15286 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15287 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15288 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15289 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15290 | ||
15291 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15292 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15293 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15294 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15295 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15296 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15297 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15298 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15299 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15300 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15301 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15302 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15303 | ||
15304 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15305 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15306 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15307 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15308 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15309 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15310 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15311 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15312 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15313 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15314 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15315 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15316 | ||
15317 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15318 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15319 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15320 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15321 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15322 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15323 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15324 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15325 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15326 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15327 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15328 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15329 | ||
15330 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15331 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15332 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15333 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15334 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15335 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15336 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15337 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15338 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15339 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15340 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15341 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15342 | ||
15343 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15344 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15345 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15346 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15347 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15348 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15349 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15350 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15351 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15352 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15353 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15354 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15355 | ||
15356 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15357 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15358 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15359 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15360 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15361 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15362 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15363 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15364 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15365 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15366 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15367 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15368 | ||
15369 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15370 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15371 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15372 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15373 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15374 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15375 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15376 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15377 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15378 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15379 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15380 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15381 | ||
15382 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15383 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15384 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15385 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15386 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15387 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15388 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15389 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15390 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15391 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15392 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15393 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15394 | ||
15395 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15396 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15397 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15398 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15399 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15400 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15401 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15402 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15403 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15404 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15405 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15406 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15407 | ||
15408 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15409 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15410 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15411 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15412 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15413 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15414 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15415 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15416 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15417 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15418 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
15419 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
15420 | |
15421 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 15422 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 15423 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
15424 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
15425 | ||
e3cb604e PB |
15426 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
15427 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
15428 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
15429 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
15430 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
15431 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
15432 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
15433 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
15434 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
15435 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
15436 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
15437 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 15438 | |
c19d1205 ZW |
15439 | /* The implementation of the FIX instruction is broken on some |
15440 | assemblers, in that it accepts a precision specifier as well as a | |
15441 | rounding specifier, despite the fact that this is meaningless. | |
15442 | To be more compatible, we accept it as well, though of course it | |
15443 | does not set any bits. */ | |
8f06b2d8 | 15444 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
15445 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
15446 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
15447 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
15448 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
15449 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
15450 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
15451 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
15452 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
15453 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
15454 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
15455 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
15456 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 15457 | |
c19d1205 ZW |
15458 | /* Instructions that were new with the real FPA, call them V2. */ |
15459 | #undef ARM_VARIANT | |
e74cfd16 | 15460 | #define ARM_VARIANT &fpu_fpa_ext_v2 |
8f06b2d8 | 15461 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
15462 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
15463 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 15464 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
15465 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
15466 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 ZW |
15467 | |
15468 | #undef ARM_VARIANT | |
e74cfd16 | 15469 | #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ |
c19d1205 | 15470 | /* Moves and type conversions. */ |
8f06b2d8 PB |
15471 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
15472 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
15473 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
15474 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
15475 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15476 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15477 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15478 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15479 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15480 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15481 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
15482 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
15483 | |
15484 | /* Memory operations. */ | |
4962c51a MS |
15485 | cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
15486 | cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
8f06b2d8 PB |
15487 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), |
15488 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
15489 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15490 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15491 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15492 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15493 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
15494 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
15495 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
15496 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
15497 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15498 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
15499 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15500 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
15501 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
15502 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 15503 | |
c19d1205 | 15504 | /* Monadic operations. */ |
8f06b2d8 PB |
15505 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
15506 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
15507 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
15508 | |
15509 | /* Dyadic operations. */ | |
8f06b2d8 PB |
15510 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
15511 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15512 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15513 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15514 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15515 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15516 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15517 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
15518 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 15519 | |
c19d1205 | 15520 | /* Comparisons. */ |
8f06b2d8 PB |
15521 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
15522 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
15523 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
15524 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 15525 | |
c19d1205 | 15526 | #undef ARM_VARIANT |
e74cfd16 | 15527 | #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ |
c19d1205 | 15528 | /* Moves and type conversions. */ |
5287ad62 | 15529 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
8f06b2d8 PB |
15530 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
15531 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
5287ad62 JB |
15532 | cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd), |
15533 | cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
15534 | cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
15535 | cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
8f06b2d8 PB |
15536 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
15537 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
15538 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
15539 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
15540 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
15541 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
15542 | |
15543 | /* Memory operations. */ | |
4962c51a MS |
15544 | cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), |
15545 | cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
8f06b2d8 PB |
15546 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), |
15547 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
15548 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
15549 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
15550 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
15551 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
15552 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
15553 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 15554 | |
c19d1205 | 15555 | /* Monadic operations. */ |
5287ad62 JB |
15556 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
15557 | cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
15558 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
15559 | |
15560 | /* Dyadic operations. */ | |
5287ad62 JB |
15561 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
15562 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15563 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15564 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15565 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15566 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15567 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15568 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
15569 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 15570 | |
c19d1205 | 15571 | /* Comparisons. */ |
5287ad62 JB |
15572 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
15573 | cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd), | |
15574 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
15575 | cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 ZW |
15576 | |
15577 | #undef ARM_VARIANT | |
e74cfd16 | 15578 | #define ARM_VARIANT &fpu_vfp_ext_v2 |
8f06b2d8 PB |
15579 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
15580 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
5287ad62 JB |
15581 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), |
15582 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
15583 | ||
037e8744 JB |
15584 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
15585 | Individual encoder functions perform additional architecture checks. */ | |
15586 | #undef ARM_VARIANT | |
15587 | #define ARM_VARIANT &fpu_vfp_ext_v1xd | |
15588 | #undef THUMB_VARIANT | |
15589 | #define THUMB_VARIANT &fpu_vfp_ext_v1xd | |
15590 | /* These mnemonics are unique to VFP. */ | |
15591 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
15592 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
15593 | nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
15594 | nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
15595 | nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
15596 | nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
15597 | nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
15598 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), | |
15599 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
15600 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
15601 | ||
15602 | /* Mnemonics shared by Neon and VFP. */ | |
15603 | nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), | |
15604 | nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
15605 | nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
15606 | ||
15607 | nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
15608 | nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
15609 | ||
15610 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
15611 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
15612 | ||
15613 | NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15614 | NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15615 | NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15616 | NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15617 | NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
15618 | NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
15619 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
15620 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 JB |
15621 | |
15622 | nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), | |
15623 | ||
15624 | /* NOTE: All VMOV encoding is special-cased! */ | |
15625 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
15626 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
15627 | ||
5287ad62 JB |
15628 | #undef THUMB_VARIANT |
15629 | #define THUMB_VARIANT &fpu_neon_ext_v1 | |
15630 | #undef ARM_VARIANT | |
15631 | #define ARM_VARIANT &fpu_neon_ext_v1 | |
15632 | /* Data processing with three registers of the same length. */ | |
15633 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
15634 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
15635 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
15636 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
15637 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
15638 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
15639 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
15640 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
15641 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
15642 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15643 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15644 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15645 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15646 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15647 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15648 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15649 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
15650 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
15651 | /* If not immediate, fall back to neon_dyadic_i64_su. | |
15652 | shl_imm should accept I8 I16 I32 I64, | |
15653 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15654 | nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), | |
15655 | nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
15656 | nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
15657 | nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
15658 | /* Logic ops, types optional & ignored. */ | |
15659 | nUF(vand, vand, 2, (RNDQ, NILO), neon_logic), | |
15660 | nUF(vandq, vand, 2, (RNQ, NILO), neon_logic), | |
15661 | nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic), | |
15662 | nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic), | |
15663 | nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic), | |
15664 | nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic), | |
15665 | nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic), | |
15666 | nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic), | |
15667 | nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
15668 | nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
15669 | /* Bitfield ops, untyped. */ | |
15670 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
15671 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
15672 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
15673 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
15674 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
15675 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
15676 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
15677 | nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
15678 | nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
15679 | nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
15680 | nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
15681 | nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
15682 | nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
15683 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall | |
15684 | back to neon_dyadic_if_su. */ | |
15685 | nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
15686 | nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
15687 | nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
15688 | nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
15689 | nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
15690 | nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
15691 | nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
15692 | nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 15693 | /* Comparison. Type I8 I16 I32 F32. */ |
5287ad62 JB |
15694 | nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
15695 | nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
15696 | /* As above, D registers only. */ | |
15697 | nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
15698 | nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
15699 | /* Int and float variants, signedness unimportant. */ | |
5287ad62 | 15700 | nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
5287ad62 JB |
15701 | nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
15702 | nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
15703 | /* Add/sub take types I8 I16 I32 I64 F32. */ | |
5287ad62 | 15704 | nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
5287ad62 JB |
15705 | nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
15706 | /* vtst takes sizes 8, 16, 32. */ | |
15707 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
15708 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
15709 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
037e8744 | 15710 | nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 JB |
15711 | /* VQD{R}MULH takes S16 S32. */ |
15712 | nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
15713 | nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
15714 | nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
15715 | nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
15716 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
15717 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
15718 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
15719 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
15720 | NUF(vaclt, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
15721 | NUF(vacltq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
15722 | NUF(vacle, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
15723 | NUF(vacleq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
15724 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
15725 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
15726 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
15727 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
15728 | ||
15729 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 15730 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
15731 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
15732 | ||
15733 | /* Data processing with two registers and a shift amount. */ | |
15734 | /* Right shifts, and variants with rounding. | |
15735 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15736 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
15737 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
15738 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
15739 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
15740 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
15741 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
15742 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
15743 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
15744 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
15745 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
15746 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
15747 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
15748 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
15749 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
15750 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
15751 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
15752 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
15753 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
15754 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
15755 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
15756 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
15757 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
15758 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
15759 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
15760 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
15761 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
15762 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
15763 | nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll), | |
15764 | /* CVT with optional immediate for fixed-point variant. */ | |
037e8744 | 15765 | nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 15766 | |
5287ad62 JB |
15767 | nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn), |
15768 | nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn), | |
15769 | ||
15770 | /* Data processing, three registers of different lengths. */ | |
15771 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
15772 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
15773 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
15774 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
15775 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
15776 | /* If not scalar, fall back to neon_dyadic_long. | |
15777 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
15778 | nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
15779 | nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
15780 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ | |
15781 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
15782 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
15783 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
15784 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15785 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15786 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15787 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
15788 | /* Saturating doubling multiplies. Types S16 S32. */ | |
15789 | nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
15790 | nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
15791 | nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
15792 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types | |
15793 | S16 S32 U16 U32. */ | |
15794 | nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), | |
15795 | ||
15796 | /* Extract. Size 8. */ | |
15797 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I7), neon_ext), | |
15798 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I7), neon_ext), | |
15799 | ||
15800 | /* Two registers, miscellaneous. */ | |
15801 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
15802 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
15803 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
15804 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
15805 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
15806 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
15807 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
15808 | /* Vector replicate. Sizes 8 16 32. */ | |
15809 | nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup), | |
15810 | nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
15811 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ | |
15812 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
15813 | /* VMOVN. Types I16 I32 I64. */ | |
15814 | nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn), | |
15815 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ | |
15816 | nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn), | |
15817 | /* VQMOVUN. Types S16 S32 S64. */ | |
15818 | nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun), | |
15819 | /* VZIP / VUZP. Sizes 8 16 32. */ | |
15820 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
15821 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
15822 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
15823 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
15824 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
15825 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
15826 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
15827 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
15828 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
15829 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
15830 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
15831 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
15832 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
15833 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
15834 | /* Reciprocal estimates. Types U32 F32. */ | |
15835 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
15836 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
15837 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
15838 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
15839 | /* VCLS. Types S8 S16 S32. */ | |
15840 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
15841 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
15842 | /* VCLZ. Types I8 I16 I32. */ | |
15843 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
15844 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
15845 | /* VCNT. Size 8. */ | |
15846 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
15847 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
15848 | /* Two address, untyped. */ | |
15849 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
15850 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
15851 | /* VTRN. Sizes 8 16 32. */ | |
15852 | nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn), | |
15853 | nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn), | |
15854 | ||
15855 | /* Table lookup. Size 8. */ | |
15856 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
15857 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
15858 | ||
b7fc2769 JB |
15859 | #undef THUMB_VARIANT |
15860 | #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext | |
15861 | #undef ARM_VARIANT | |
15862 | #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext | |
5287ad62 JB |
15863 | /* Neon element/structure load/store. */ |
15864 | nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15865 | nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15866 | nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15867 | nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15868 | nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15869 | nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15870 | nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15871 | nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
15872 | ||
15873 | #undef THUMB_VARIANT | |
15874 | #define THUMB_VARIANT &fpu_vfp_ext_v3 | |
15875 | #undef ARM_VARIANT | |
15876 | #define ARM_VARIANT &fpu_vfp_ext_v3 | |
5287ad62 JB |
15877 | cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const), |
15878 | cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const), | |
15879 | cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15880 | cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15881 | cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15882 | cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
15883 | cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15884 | cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15885 | cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15886 | cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
15887 | cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15888 | cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15889 | cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15890 | cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
15891 | cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
15892 | cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
15893 | cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
15894 | cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
c19d1205 | 15895 | |
5287ad62 | 15896 | #undef THUMB_VARIANT |
c19d1205 | 15897 | #undef ARM_VARIANT |
e74cfd16 | 15898 | #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */ |
8f06b2d8 PB |
15899 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
15900 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15901 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15902 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15903 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15904 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
15905 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
15906 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 ZW |
15907 | |
15908 | #undef ARM_VARIANT | |
e74cfd16 | 15909 | #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */ |
8f06b2d8 PB |
15910 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
15911 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
15912 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
15913 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
15914 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
15915 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
15916 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
15917 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
15918 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
15919 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15920 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15921 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15922 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15923 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15924 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
15925 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
15926 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
15927 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
41adaa5c | 15928 | cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd), |
8f06b2d8 PB |
15929 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), |
15930 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15931 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15932 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15933 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15934 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15935 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
15936 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
15937 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
15938 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
41adaa5c | 15939 | cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn), |
8f06b2d8 PB |
15940 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), |
15941 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
15942 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
15943 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
15944 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
15945 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
15946 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
15947 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15948 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15949 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15950 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15951 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15952 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15953 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15954 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15955 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15956 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
15957 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15958 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15959 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15960 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15961 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15962 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15963 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15964 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15965 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15966 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15967 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15968 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15969 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15970 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15971 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15972 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15973 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15974 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15975 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15976 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
15977 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
15978 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
15979 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
15980 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15981 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15982 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15983 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15984 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15985 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15986 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15987 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15988 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15989 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15990 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15991 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15992 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15993 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15994 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15995 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15996 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15997 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
15998 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
15999 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16000 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16001 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16002 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16003 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16004 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16005 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16006 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16007 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16008 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16009 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 16010 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16011 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16012 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16013 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16014 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
16015 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
16016 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16017 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16018 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16019 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16020 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
2d447fca | 16021 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16022 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16023 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16024 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16025 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16026 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16027 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16028 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16029 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16030 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16031 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16032 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16033 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16034 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16035 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 16036 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 16037 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
16038 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
16039 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
16040 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
16041 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
16042 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
16043 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16044 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16045 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16046 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16047 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16048 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16049 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16050 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16051 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16052 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
16053 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
16054 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
16055 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
16056 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
16057 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
16058 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16059 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16060 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16061 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
16062 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
16063 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
16064 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
16065 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
16066 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
16067 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16068 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16069 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16070 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16071 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 16072 | |
2d447fca JM |
16073 | #undef ARM_VARIANT |
16074 | #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
16075 | cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc), | |
16076 | cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc), | |
16077 | cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc), | |
16078 | cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn), | |
16079 | cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn), | |
16080 | cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn), | |
16081 | cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16082 | cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16083 | cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16084 | cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16085 | cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16086 | cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16087 | cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16088 | cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16089 | cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16090 | cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16091 | cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16092 | cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16093 | cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16094 | cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16095 | cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
16096 | cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16097 | cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16098 | cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16099 | cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16100 | cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16101 | cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16102 | cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16103 | cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16104 | cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16105 | cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16106 | cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16107 | cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16108 | cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16109 | cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16110 | cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16111 | cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16112 | cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16113 | cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16114 | cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16115 | cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16116 | cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16117 | cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16118 | cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16119 | cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16120 | cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16121 | cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16122 | cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16123 | cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16124 | cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16125 | cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16126 | cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16127 | cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16128 | cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16129 | cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16130 | cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16131 | cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
16132 | ||
c19d1205 | 16133 | #undef ARM_VARIANT |
e74cfd16 | 16134 | #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */ |
4962c51a MS |
16135 | cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
16136 | cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
16137 | cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
16138 | cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
16139 | cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
16140 | cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
16141 | cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
16142 | cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
8f06b2d8 PB |
16143 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), |
16144 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
16145 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
16146 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
16147 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
16148 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
16149 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
16150 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
16151 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
16152 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
16153 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
16154 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
16155 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
16156 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
16157 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
16158 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
16159 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
16160 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
16161 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
16162 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
16163 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
16164 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
16165 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
16166 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
16167 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
16168 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
16169 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
16170 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
16171 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
16172 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
16173 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
16174 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
16175 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
16176 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
16177 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
16178 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
16179 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
16180 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
16181 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
16182 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
16183 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
16184 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
16185 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
16186 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
16187 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
16188 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
16189 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
16190 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
16191 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
16192 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
16193 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
16194 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
16195 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
16196 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
16197 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
16198 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
16199 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
16200 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
16201 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
16202 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
16203 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
16204 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
16205 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
16206 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
16207 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
16208 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
16209 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
16210 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
16211 | }; |
16212 | #undef ARM_VARIANT | |
16213 | #undef THUMB_VARIANT | |
16214 | #undef TCE | |
16215 | #undef TCM | |
16216 | #undef TUE | |
16217 | #undef TUF | |
16218 | #undef TCC | |
8f06b2d8 | 16219 | #undef cCE |
e3cb604e PB |
16220 | #undef cCL |
16221 | #undef C3E | |
c19d1205 ZW |
16222 | #undef CE |
16223 | #undef CM | |
16224 | #undef UE | |
16225 | #undef UF | |
16226 | #undef UT | |
5287ad62 JB |
16227 | #undef NUF |
16228 | #undef nUF | |
16229 | #undef NCE | |
16230 | #undef nCE | |
c19d1205 ZW |
16231 | #undef OPS0 |
16232 | #undef OPS1 | |
16233 | #undef OPS2 | |
16234 | #undef OPS3 | |
16235 | #undef OPS4 | |
16236 | #undef OPS5 | |
16237 | #undef OPS6 | |
16238 | #undef do_0 | |
16239 | \f | |
16240 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 16241 | |
c19d1205 ZW |
16242 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
16243 | for use in the a.out file, and stores them in the array pointed to by buf. | |
16244 | This knows about the endian-ness of the target machine and does | |
16245 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
16246 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
16247 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 16248 | |
c19d1205 ZW |
16249 | void |
16250 | md_number_to_chars (char * buf, valueT val, int n) | |
16251 | { | |
16252 | if (target_big_endian) | |
16253 | number_to_chars_bigendian (buf, val, n); | |
16254 | else | |
16255 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
16256 | } |
16257 | ||
c19d1205 ZW |
16258 | static valueT |
16259 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 16260 | { |
c19d1205 ZW |
16261 | valueT result = 0; |
16262 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 16263 | |
c19d1205 | 16264 | if (target_big_endian) |
b99bd4ef | 16265 | { |
c19d1205 ZW |
16266 | while (n--) |
16267 | { | |
16268 | result <<= 8; | |
16269 | result |= (*where++ & 255); | |
16270 | } | |
b99bd4ef | 16271 | } |
c19d1205 | 16272 | else |
b99bd4ef | 16273 | { |
c19d1205 ZW |
16274 | while (n--) |
16275 | { | |
16276 | result <<= 8; | |
16277 | result |= (where[n] & 255); | |
16278 | } | |
bfae80f2 | 16279 | } |
b99bd4ef | 16280 | |
c19d1205 | 16281 | return result; |
bfae80f2 | 16282 | } |
b99bd4ef | 16283 | |
c19d1205 | 16284 | /* MD interface: Sections. */ |
b99bd4ef | 16285 | |
0110f2b8 PB |
16286 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
16287 | 2 bytes. */ | |
16288 | ||
c19d1205 | 16289 | int |
0110f2b8 | 16290 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
16291 | segT segtype ATTRIBUTE_UNUSED) |
16292 | { | |
0110f2b8 PB |
16293 | fragp->fr_var = 2; |
16294 | return 2; | |
16295 | } | |
16296 | ||
16297 | /* Convert a machine dependent frag. */ | |
16298 | ||
16299 | void | |
16300 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
16301 | { | |
16302 | unsigned long insn; | |
16303 | unsigned long old_op; | |
16304 | char *buf; | |
16305 | expressionS exp; | |
16306 | fixS *fixp; | |
16307 | int reloc_type; | |
16308 | int pc_rel; | |
16309 | int opcode; | |
16310 | ||
16311 | buf = fragp->fr_literal + fragp->fr_fix; | |
16312 | ||
16313 | old_op = bfd_get_16(abfd, buf); | |
16314 | if (fragp->fr_symbol) { | |
16315 | exp.X_op = O_symbol; | |
16316 | exp.X_add_symbol = fragp->fr_symbol; | |
16317 | } else { | |
16318 | exp.X_op = O_constant; | |
16319 | } | |
16320 | exp.X_add_number = fragp->fr_offset; | |
16321 | opcode = fragp->fr_subtype; | |
16322 | switch (opcode) | |
16323 | { | |
16324 | case T_MNEM_ldr_pc: | |
16325 | case T_MNEM_ldr_pc2: | |
16326 | case T_MNEM_ldr_sp: | |
16327 | case T_MNEM_str_sp: | |
16328 | case T_MNEM_ldr: | |
16329 | case T_MNEM_ldrb: | |
16330 | case T_MNEM_ldrh: | |
16331 | case T_MNEM_str: | |
16332 | case T_MNEM_strb: | |
16333 | case T_MNEM_strh: | |
16334 | if (fragp->fr_var == 4) | |
16335 | { | |
16336 | insn = THUMB_OP32(opcode); | |
16337 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) | |
16338 | { | |
16339 | insn |= (old_op & 0x700) << 4; | |
16340 | } | |
16341 | else | |
16342 | { | |
16343 | insn |= (old_op & 7) << 12; | |
16344 | insn |= (old_op & 0x38) << 13; | |
16345 | } | |
16346 | insn |= 0x00000c00; | |
16347 | put_thumb32_insn (buf, insn); | |
16348 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
16349 | } | |
16350 | else | |
16351 | { | |
16352 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
16353 | } | |
16354 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
16355 | break; | |
16356 | case T_MNEM_adr: | |
16357 | if (fragp->fr_var == 4) | |
16358 | { | |
16359 | insn = THUMB_OP32 (opcode); | |
16360 | insn |= (old_op & 0xf0) << 4; | |
16361 | put_thumb32_insn (buf, insn); | |
16362 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
16363 | } | |
16364 | else | |
16365 | { | |
16366 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
16367 | exp.X_add_number -= 4; | |
16368 | } | |
16369 | pc_rel = 1; | |
16370 | break; | |
16371 | case T_MNEM_mov: | |
16372 | case T_MNEM_movs: | |
16373 | case T_MNEM_cmp: | |
16374 | case T_MNEM_cmn: | |
16375 | if (fragp->fr_var == 4) | |
16376 | { | |
16377 | int r0off = (opcode == T_MNEM_mov | |
16378 | || opcode == T_MNEM_movs) ? 0 : 8; | |
16379 | insn = THUMB_OP32 (opcode); | |
16380 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
16381 | insn |= (old_op & 0x700) << r0off; | |
16382 | put_thumb32_insn (buf, insn); | |
16383 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
16384 | } | |
16385 | else | |
16386 | { | |
16387 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
16388 | } | |
16389 | pc_rel = 0; | |
16390 | break; | |
16391 | case T_MNEM_b: | |
16392 | if (fragp->fr_var == 4) | |
16393 | { | |
16394 | insn = THUMB_OP32(opcode); | |
16395 | put_thumb32_insn (buf, insn); | |
16396 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
16397 | } | |
16398 | else | |
16399 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
16400 | pc_rel = 1; | |
16401 | break; | |
16402 | case T_MNEM_bcond: | |
16403 | if (fragp->fr_var == 4) | |
16404 | { | |
16405 | insn = THUMB_OP32(opcode); | |
16406 | insn |= (old_op & 0xf00) << 14; | |
16407 | put_thumb32_insn (buf, insn); | |
16408 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
16409 | } | |
16410 | else | |
16411 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
16412 | pc_rel = 1; | |
16413 | break; | |
16414 | case T_MNEM_add_sp: | |
16415 | case T_MNEM_add_pc: | |
16416 | case T_MNEM_inc_sp: | |
16417 | case T_MNEM_dec_sp: | |
16418 | if (fragp->fr_var == 4) | |
16419 | { | |
16420 | /* ??? Choose between add and addw. */ | |
16421 | insn = THUMB_OP32 (opcode); | |
16422 | insn |= (old_op & 0xf0) << 4; | |
16423 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
16424 | if (opcode == T_MNEM_add_pc) |
16425 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
16426 | else | |
16427 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
16428 | } |
16429 | else | |
16430 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
16431 | pc_rel = 0; | |
16432 | break; | |
16433 | ||
16434 | case T_MNEM_addi: | |
16435 | case T_MNEM_addis: | |
16436 | case T_MNEM_subi: | |
16437 | case T_MNEM_subis: | |
16438 | if (fragp->fr_var == 4) | |
16439 | { | |
16440 | insn = THUMB_OP32 (opcode); | |
16441 | insn |= (old_op & 0xf0) << 4; | |
16442 | insn |= (old_op & 0xf) << 16; | |
16443 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
16444 | if (insn & (1 << 20)) |
16445 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
16446 | else | |
16447 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
16448 | } |
16449 | else | |
16450 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
16451 | pc_rel = 0; | |
16452 | break; | |
16453 | default: | |
16454 | abort(); | |
16455 | } | |
16456 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
16457 | reloc_type); | |
16458 | fixp->fx_file = fragp->fr_file; | |
16459 | fixp->fx_line = fragp->fr_line; | |
16460 | fragp->fr_fix += fragp->fr_var; | |
16461 | } | |
16462 | ||
16463 | /* Return the size of a relaxable immediate operand instruction. | |
16464 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
16465 | static int | |
16466 | relax_immediate (fragS *fragp, int size, int shift) | |
16467 | { | |
16468 | offsetT offset; | |
16469 | offsetT mask; | |
16470 | offsetT low; | |
16471 | ||
16472 | /* ??? Should be able to do better than this. */ | |
16473 | if (fragp->fr_symbol) | |
16474 | return 4; | |
16475 | ||
16476 | low = (1 << shift) - 1; | |
16477 | mask = (1 << (shift + size)) - (1 << shift); | |
16478 | offset = fragp->fr_offset; | |
16479 | /* Force misaligned offsets to 32-bit variant. */ | |
16480 | if (offset & low) | |
16481 | return -4; | |
16482 | if (offset & ~mask) | |
16483 | return 4; | |
16484 | return 2; | |
16485 | } | |
16486 | ||
16487 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative | |
16488 | load. */ | |
16489 | static int | |
16490 | relax_adr (fragS *fragp, asection *sec) | |
16491 | { | |
16492 | addressT addr; | |
16493 | offsetT val; | |
16494 | ||
16495 | /* Assume worst case for symbols not known to be in the same section. */ | |
16496 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
16497 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
16498 | return 4; | |
16499 | ||
16500 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
16501 | addr = fragp->fr_address + fragp->fr_fix; | |
16502 | addr = (addr + 4) & ~3; | |
16503 | /* Fix the insn as the 4-byte version if the target address is not | |
16504 | sufficiently aligned. This is prevents an infinite loop when two | |
16505 | instructions have contradictory range/alignment requirements. */ | |
16506 | if (val & 3) | |
16507 | return -4; | |
16508 | val -= addr; | |
16509 | if (val < 0 || val > 1020) | |
16510 | return 4; | |
16511 | return 2; | |
16512 | } | |
16513 | ||
16514 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
16515 | static int | |
16516 | relax_addsub (fragS *fragp, asection *sec) | |
16517 | { | |
16518 | char *buf; | |
16519 | int op; | |
16520 | ||
16521 | buf = fragp->fr_literal + fragp->fr_fix; | |
16522 | op = bfd_get_16(sec->owner, buf); | |
16523 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
16524 | return relax_immediate (fragp, 8, 0); | |
16525 | else | |
16526 | return relax_immediate (fragp, 3, 0); | |
16527 | } | |
16528 | ||
16529 | ||
16530 | /* Return the size of a relaxable branch instruction. BITS is the | |
16531 | size of the offset field in the narrow instruction. */ | |
16532 | ||
16533 | static int | |
16534 | relax_branch (fragS *fragp, asection *sec, int bits) | |
16535 | { | |
16536 | addressT addr; | |
16537 | offsetT val; | |
16538 | offsetT limit; | |
16539 | ||
16540 | /* Assume worst case for symbols not known to be in the same section. */ | |
16541 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
16542 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
16543 | return 4; | |
16544 | ||
16545 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
16546 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
16547 | val -= addr; | |
16548 | ||
16549 | /* Offset is a signed value *2 */ | |
16550 | limit = 1 << bits; | |
16551 | if (val >= limit || val < -limit) | |
16552 | return 4; | |
16553 | return 2; | |
16554 | } | |
16555 | ||
16556 | ||
16557 | /* Relax a machine dependent frag. This returns the amount by which | |
16558 | the current size of the frag should change. */ | |
16559 | ||
16560 | int | |
16561 | arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED) | |
16562 | { | |
16563 | int oldsize; | |
16564 | int newsize; | |
16565 | ||
16566 | oldsize = fragp->fr_var; | |
16567 | switch (fragp->fr_subtype) | |
16568 | { | |
16569 | case T_MNEM_ldr_pc2: | |
16570 | newsize = relax_adr(fragp, sec); | |
16571 | break; | |
16572 | case T_MNEM_ldr_pc: | |
16573 | case T_MNEM_ldr_sp: | |
16574 | case T_MNEM_str_sp: | |
16575 | newsize = relax_immediate(fragp, 8, 2); | |
16576 | break; | |
16577 | case T_MNEM_ldr: | |
16578 | case T_MNEM_str: | |
16579 | newsize = relax_immediate(fragp, 5, 2); | |
16580 | break; | |
16581 | case T_MNEM_ldrh: | |
16582 | case T_MNEM_strh: | |
16583 | newsize = relax_immediate(fragp, 5, 1); | |
16584 | break; | |
16585 | case T_MNEM_ldrb: | |
16586 | case T_MNEM_strb: | |
16587 | newsize = relax_immediate(fragp, 5, 0); | |
16588 | break; | |
16589 | case T_MNEM_adr: | |
16590 | newsize = relax_adr(fragp, sec); | |
16591 | break; | |
16592 | case T_MNEM_mov: | |
16593 | case T_MNEM_movs: | |
16594 | case T_MNEM_cmp: | |
16595 | case T_MNEM_cmn: | |
16596 | newsize = relax_immediate(fragp, 8, 0); | |
16597 | break; | |
16598 | case T_MNEM_b: | |
16599 | newsize = relax_branch(fragp, sec, 11); | |
16600 | break; | |
16601 | case T_MNEM_bcond: | |
16602 | newsize = relax_branch(fragp, sec, 8); | |
16603 | break; | |
16604 | case T_MNEM_add_sp: | |
16605 | case T_MNEM_add_pc: | |
16606 | newsize = relax_immediate (fragp, 8, 2); | |
16607 | break; | |
16608 | case T_MNEM_inc_sp: | |
16609 | case T_MNEM_dec_sp: | |
16610 | newsize = relax_immediate (fragp, 7, 2); | |
16611 | break; | |
16612 | case T_MNEM_addi: | |
16613 | case T_MNEM_addis: | |
16614 | case T_MNEM_subi: | |
16615 | case T_MNEM_subis: | |
16616 | newsize = relax_addsub (fragp, sec); | |
16617 | break; | |
16618 | default: | |
16619 | abort(); | |
16620 | } | |
16621 | if (newsize < 0) | |
16622 | { | |
16623 | fragp->fr_var = -newsize; | |
16624 | md_convert_frag (sec->owner, sec, fragp); | |
16625 | frag_wane(fragp); | |
16626 | return -(newsize + oldsize); | |
16627 | } | |
16628 | fragp->fr_var = newsize; | |
16629 | return newsize - oldsize; | |
c19d1205 | 16630 | } |
b99bd4ef | 16631 | |
c19d1205 | 16632 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 16633 | |
c19d1205 ZW |
16634 | valueT |
16635 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
16636 | valueT size) | |
16637 | { | |
f0927246 NC |
16638 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
16639 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
16640 | { | |
16641 | /* For a.out, force the section size to be aligned. If we don't do | |
16642 | this, BFD will align it for us, but it will not write out the | |
16643 | final bytes of the section. This may be a bug in BFD, but it is | |
16644 | easier to fix it here since that is how the other a.out targets | |
16645 | work. */ | |
16646 | int align; | |
16647 | ||
16648 | align = bfd_get_section_alignment (stdoutput, segment); | |
16649 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
16650 | } | |
c19d1205 | 16651 | #endif |
f0927246 NC |
16652 | |
16653 | return size; | |
bfae80f2 | 16654 | } |
b99bd4ef | 16655 | |
c19d1205 ZW |
16656 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
16657 | of an rs_align_code fragment. */ | |
16658 | ||
16659 | void | |
16660 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 16661 | { |
c19d1205 ZW |
16662 | static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 }; |
16663 | static char const thumb_noop[2] = { 0xc0, 0x46 }; | |
16664 | static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 }; | |
16665 | static char const thumb_bigend_noop[2] = { 0x46, 0xc0 }; | |
16666 | ||
16667 | int bytes, fix, noop_size; | |
16668 | char * p; | |
16669 | const char * noop; | |
bfae80f2 | 16670 | |
c19d1205 | 16671 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
16672 | return; |
16673 | ||
c19d1205 ZW |
16674 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
16675 | p = fragP->fr_literal + fragP->fr_fix; | |
16676 | fix = 0; | |
bfae80f2 | 16677 | |
c19d1205 ZW |
16678 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
16679 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 16680 | |
c19d1205 | 16681 | if (fragP->tc_frag_data) |
a737bd4d | 16682 | { |
c19d1205 ZW |
16683 | if (target_big_endian) |
16684 | noop = thumb_bigend_noop; | |
16685 | else | |
16686 | noop = thumb_noop; | |
16687 | noop_size = sizeof (thumb_noop); | |
7ed4c4c5 NC |
16688 | } |
16689 | else | |
16690 | { | |
c19d1205 ZW |
16691 | if (target_big_endian) |
16692 | noop = arm_bigend_noop; | |
16693 | else | |
16694 | noop = arm_noop; | |
16695 | noop_size = sizeof (arm_noop); | |
7ed4c4c5 | 16696 | } |
a737bd4d | 16697 | |
c19d1205 | 16698 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 16699 | { |
c19d1205 ZW |
16700 | fix = bytes & (noop_size - 1); |
16701 | memset (p, 0, fix); | |
16702 | p += fix; | |
16703 | bytes -= fix; | |
a737bd4d | 16704 | } |
a737bd4d | 16705 | |
c19d1205 | 16706 | while (bytes >= noop_size) |
a737bd4d | 16707 | { |
c19d1205 ZW |
16708 | memcpy (p, noop, noop_size); |
16709 | p += noop_size; | |
16710 | bytes -= noop_size; | |
16711 | fix += noop_size; | |
a737bd4d NC |
16712 | } |
16713 | ||
c19d1205 ZW |
16714 | fragP->fr_fix += fix; |
16715 | fragP->fr_var = noop_size; | |
a737bd4d NC |
16716 | } |
16717 | ||
c19d1205 ZW |
16718 | /* Called from md_do_align. Used to create an alignment |
16719 | frag in a code section. */ | |
16720 | ||
16721 | void | |
16722 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 16723 | { |
c19d1205 | 16724 | char * p; |
7ed4c4c5 | 16725 | |
c19d1205 ZW |
16726 | /* We assume that there will never be a requirement |
16727 | to support alignments greater than 32 bytes. */ | |
16728 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) | |
16729 | as_fatal (_("alignments greater than 32 bytes not supported in .text sections.")); | |
bfae80f2 | 16730 | |
c19d1205 ZW |
16731 | p = frag_var (rs_align_code, |
16732 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
16733 | 1, | |
16734 | (relax_substateT) max, | |
16735 | (symbolS *) NULL, | |
16736 | (offsetT) n, | |
16737 | (char *) NULL); | |
16738 | *p = 0; | |
16739 | } | |
bfae80f2 | 16740 | |
c19d1205 | 16741 | /* Perform target specific initialisation of a frag. */ |
bfae80f2 | 16742 | |
c19d1205 ZW |
16743 | void |
16744 | arm_init_frag (fragS * fragP) | |
16745 | { | |
16746 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
16747 | fragP->tc_frag_data = thumb_mode; | |
bfae80f2 RE |
16748 | } |
16749 | ||
c19d1205 ZW |
16750 | #ifdef OBJ_ELF |
16751 | /* When we change sections we need to issue a new mapping symbol. */ | |
16752 | ||
16753 | void | |
16754 | arm_elf_change_section (void) | |
bfae80f2 | 16755 | { |
c19d1205 ZW |
16756 | flagword flags; |
16757 | segment_info_type *seginfo; | |
bfae80f2 | 16758 | |
c19d1205 ZW |
16759 | /* Link an unlinked unwind index table section to the .text section. */ |
16760 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
16761 | && elf_linked_to_section (now_seg) == NULL) | |
16762 | elf_linked_to_section (now_seg) = text_section; | |
16763 | ||
16764 | if (!SEG_NORMAL (now_seg)) | |
bfae80f2 RE |
16765 | return; |
16766 | ||
c19d1205 ZW |
16767 | flags = bfd_get_section_flags (stdoutput, now_seg); |
16768 | ||
16769 | /* We can ignore sections that only contain debug info. */ | |
16770 | if ((flags & SEC_ALLOC) == 0) | |
16771 | return; | |
bfae80f2 | 16772 | |
c19d1205 ZW |
16773 | seginfo = seg_info (now_seg); |
16774 | mapstate = seginfo->tc_segment_info_data.mapstate; | |
16775 | marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency; | |
bfae80f2 RE |
16776 | } |
16777 | ||
c19d1205 ZW |
16778 | int |
16779 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 16780 | { |
c19d1205 ZW |
16781 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
16782 | return SHT_ARM_EXIDX; | |
e45d0630 | 16783 | |
c19d1205 ZW |
16784 | return -1; |
16785 | } | |
16786 | \f | |
16787 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 16788 | |
c19d1205 | 16789 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 16790 | |
c19d1205 | 16791 | /* Cenerate and deferred unwind frame offset. */ |
e45d0630 | 16792 | |
bfae80f2 | 16793 | static void |
c19d1205 | 16794 | flush_pending_unwind (void) |
bfae80f2 | 16795 | { |
c19d1205 | 16796 | offsetT offset; |
bfae80f2 | 16797 | |
c19d1205 ZW |
16798 | offset = unwind.pending_offset; |
16799 | unwind.pending_offset = 0; | |
16800 | if (offset != 0) | |
16801 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
16802 | } |
16803 | ||
c19d1205 ZW |
16804 | /* Add an opcode to this list for this function. Two-byte opcodes should |
16805 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
16806 | order. */ | |
16807 | ||
bfae80f2 | 16808 | static void |
c19d1205 | 16809 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 16810 | { |
c19d1205 ZW |
16811 | /* Add any deferred stack adjustment. */ |
16812 | if (unwind.pending_offset) | |
16813 | flush_pending_unwind (); | |
bfae80f2 | 16814 | |
c19d1205 | 16815 | unwind.sp_restored = 0; |
bfae80f2 | 16816 | |
c19d1205 | 16817 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 16818 | { |
c19d1205 ZW |
16819 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
16820 | if (unwind.opcodes) | |
16821 | unwind.opcodes = xrealloc (unwind.opcodes, | |
16822 | unwind.opcode_alloc); | |
16823 | else | |
16824 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 16825 | } |
c19d1205 | 16826 | while (length > 0) |
bfae80f2 | 16827 | { |
c19d1205 ZW |
16828 | length--; |
16829 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
16830 | op >>= 8; | |
16831 | unwind.opcode_count++; | |
bfae80f2 | 16832 | } |
bfae80f2 RE |
16833 | } |
16834 | ||
c19d1205 ZW |
16835 | /* Add unwind opcodes to adjust the stack pointer. */ |
16836 | ||
bfae80f2 | 16837 | static void |
c19d1205 | 16838 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 16839 | { |
c19d1205 | 16840 | valueT op; |
bfae80f2 | 16841 | |
c19d1205 | 16842 | if (offset > 0x200) |
bfae80f2 | 16843 | { |
c19d1205 ZW |
16844 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
16845 | char bytes[5]; | |
16846 | int n; | |
16847 | valueT o; | |
bfae80f2 | 16848 | |
c19d1205 ZW |
16849 | /* Long form: 0xb2, uleb128. */ |
16850 | /* This might not fit in a word so add the individual bytes, | |
16851 | remembering the list is built in reverse order. */ | |
16852 | o = (valueT) ((offset - 0x204) >> 2); | |
16853 | if (o == 0) | |
16854 | add_unwind_opcode (0, 1); | |
bfae80f2 | 16855 | |
c19d1205 ZW |
16856 | /* Calculate the uleb128 encoding of the offset. */ |
16857 | n = 0; | |
16858 | while (o) | |
16859 | { | |
16860 | bytes[n] = o & 0x7f; | |
16861 | o >>= 7; | |
16862 | if (o) | |
16863 | bytes[n] |= 0x80; | |
16864 | n++; | |
16865 | } | |
16866 | /* Add the insn. */ | |
16867 | for (; n; n--) | |
16868 | add_unwind_opcode (bytes[n - 1], 1); | |
16869 | add_unwind_opcode (0xb2, 1); | |
16870 | } | |
16871 | else if (offset > 0x100) | |
bfae80f2 | 16872 | { |
c19d1205 ZW |
16873 | /* Two short opcodes. */ |
16874 | add_unwind_opcode (0x3f, 1); | |
16875 | op = (offset - 0x104) >> 2; | |
16876 | add_unwind_opcode (op, 1); | |
bfae80f2 | 16877 | } |
c19d1205 ZW |
16878 | else if (offset > 0) |
16879 | { | |
16880 | /* Short opcode. */ | |
16881 | op = (offset - 4) >> 2; | |
16882 | add_unwind_opcode (op, 1); | |
16883 | } | |
16884 | else if (offset < 0) | |
bfae80f2 | 16885 | { |
c19d1205 ZW |
16886 | offset = -offset; |
16887 | while (offset > 0x100) | |
bfae80f2 | 16888 | { |
c19d1205 ZW |
16889 | add_unwind_opcode (0x7f, 1); |
16890 | offset -= 0x100; | |
bfae80f2 | 16891 | } |
c19d1205 ZW |
16892 | op = ((offset - 4) >> 2) | 0x40; |
16893 | add_unwind_opcode (op, 1); | |
bfae80f2 | 16894 | } |
bfae80f2 RE |
16895 | } |
16896 | ||
c19d1205 ZW |
16897 | /* Finish the list of unwind opcodes for this function. */ |
16898 | static void | |
16899 | finish_unwind_opcodes (void) | |
bfae80f2 | 16900 | { |
c19d1205 | 16901 | valueT op; |
bfae80f2 | 16902 | |
c19d1205 | 16903 | if (unwind.fp_used) |
bfae80f2 | 16904 | { |
708587a4 | 16905 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
16906 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
16907 | flush_pending_unwind (); | |
bfae80f2 | 16908 | |
c19d1205 ZW |
16909 | /* After restoring sp from the frame pointer. */ |
16910 | op = 0x90 | unwind.fp_reg; | |
16911 | add_unwind_opcode (op, 1); | |
16912 | } | |
16913 | else | |
16914 | flush_pending_unwind (); | |
bfae80f2 RE |
16915 | } |
16916 | ||
bfae80f2 | 16917 | |
c19d1205 ZW |
16918 | /* Start an exception table entry. If idx is nonzero this is an index table |
16919 | entry. */ | |
bfae80f2 RE |
16920 | |
16921 | static void | |
c19d1205 | 16922 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 16923 | { |
c19d1205 ZW |
16924 | const char * text_name; |
16925 | const char * prefix; | |
16926 | const char * prefix_once; | |
16927 | const char * group_name; | |
16928 | size_t prefix_len; | |
16929 | size_t text_len; | |
16930 | char * sec_name; | |
16931 | size_t sec_name_len; | |
16932 | int type; | |
16933 | int flags; | |
16934 | int linkonce; | |
bfae80f2 | 16935 | |
c19d1205 | 16936 | if (idx) |
bfae80f2 | 16937 | { |
c19d1205 ZW |
16938 | prefix = ELF_STRING_ARM_unwind; |
16939 | prefix_once = ELF_STRING_ARM_unwind_once; | |
16940 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 16941 | } |
c19d1205 | 16942 | else |
bfae80f2 | 16943 | { |
c19d1205 ZW |
16944 | prefix = ELF_STRING_ARM_unwind_info; |
16945 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
16946 | type = SHT_PROGBITS; | |
bfae80f2 RE |
16947 | } |
16948 | ||
c19d1205 ZW |
16949 | text_name = segment_name (text_seg); |
16950 | if (streq (text_name, ".text")) | |
16951 | text_name = ""; | |
16952 | ||
16953 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
16954 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 16955 | { |
c19d1205 ZW |
16956 | prefix = prefix_once; |
16957 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
16958 | } |
16959 | ||
c19d1205 ZW |
16960 | prefix_len = strlen (prefix); |
16961 | text_len = strlen (text_name); | |
16962 | sec_name_len = prefix_len + text_len; | |
16963 | sec_name = xmalloc (sec_name_len + 1); | |
16964 | memcpy (sec_name, prefix, prefix_len); | |
16965 | memcpy (sec_name + prefix_len, text_name, text_len); | |
16966 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 16967 | |
c19d1205 ZW |
16968 | flags = SHF_ALLOC; |
16969 | linkonce = 0; | |
16970 | group_name = 0; | |
bfae80f2 | 16971 | |
c19d1205 ZW |
16972 | /* Handle COMDAT group. */ |
16973 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 16974 | { |
c19d1205 ZW |
16975 | group_name = elf_group_name (text_seg); |
16976 | if (group_name == NULL) | |
16977 | { | |
16978 | as_bad ("Group section `%s' has no group signature", | |
16979 | segment_name (text_seg)); | |
16980 | ignore_rest_of_line (); | |
16981 | return; | |
16982 | } | |
16983 | flags |= SHF_GROUP; | |
16984 | linkonce = 1; | |
bfae80f2 RE |
16985 | } |
16986 | ||
c19d1205 | 16987 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 16988 | |
c19d1205 ZW |
16989 | /* Set the setion link for index tables. */ |
16990 | if (idx) | |
16991 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
16992 | } |
16993 | ||
bfae80f2 | 16994 | |
c19d1205 ZW |
16995 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
16996 | personality routine data. Returns zero, or the index table value for | |
16997 | and inline entry. */ | |
16998 | ||
16999 | static valueT | |
17000 | create_unwind_entry (int have_data) | |
bfae80f2 | 17001 | { |
c19d1205 ZW |
17002 | int size; |
17003 | addressT where; | |
17004 | char *ptr; | |
17005 | /* The current word of data. */ | |
17006 | valueT data; | |
17007 | /* The number of bytes left in this word. */ | |
17008 | int n; | |
bfae80f2 | 17009 | |
c19d1205 | 17010 | finish_unwind_opcodes (); |
bfae80f2 | 17011 | |
c19d1205 ZW |
17012 | /* Remember the current text section. */ |
17013 | unwind.saved_seg = now_seg; | |
17014 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 17015 | |
c19d1205 | 17016 | start_unwind_section (now_seg, 0); |
bfae80f2 | 17017 | |
c19d1205 | 17018 | if (unwind.personality_routine == NULL) |
bfae80f2 | 17019 | { |
c19d1205 ZW |
17020 | if (unwind.personality_index == -2) |
17021 | { | |
17022 | if (have_data) | |
17023 | as_bad (_("handerdata in cantunwind frame")); | |
17024 | return 1; /* EXIDX_CANTUNWIND. */ | |
17025 | } | |
bfae80f2 | 17026 | |
c19d1205 ZW |
17027 | /* Use a default personality routine if none is specified. */ |
17028 | if (unwind.personality_index == -1) | |
17029 | { | |
17030 | if (unwind.opcode_count > 3) | |
17031 | unwind.personality_index = 1; | |
17032 | else | |
17033 | unwind.personality_index = 0; | |
17034 | } | |
bfae80f2 | 17035 | |
c19d1205 ZW |
17036 | /* Space for the personality routine entry. */ |
17037 | if (unwind.personality_index == 0) | |
17038 | { | |
17039 | if (unwind.opcode_count > 3) | |
17040 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 17041 | |
c19d1205 ZW |
17042 | if (!have_data) |
17043 | { | |
17044 | /* All the data is inline in the index table. */ | |
17045 | data = 0x80; | |
17046 | n = 3; | |
17047 | while (unwind.opcode_count > 0) | |
17048 | { | |
17049 | unwind.opcode_count--; | |
17050 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
17051 | n--; | |
17052 | } | |
bfae80f2 | 17053 | |
c19d1205 ZW |
17054 | /* Pad with "finish" opcodes. */ |
17055 | while (n--) | |
17056 | data = (data << 8) | 0xb0; | |
bfae80f2 | 17057 | |
c19d1205 ZW |
17058 | return data; |
17059 | } | |
17060 | size = 0; | |
17061 | } | |
17062 | else | |
17063 | /* We get two opcodes "free" in the first word. */ | |
17064 | size = unwind.opcode_count - 2; | |
17065 | } | |
17066 | else | |
17067 | /* An extra byte is required for the opcode count. */ | |
17068 | size = unwind.opcode_count + 1; | |
bfae80f2 | 17069 | |
c19d1205 ZW |
17070 | size = (size + 3) >> 2; |
17071 | if (size > 0xff) | |
17072 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 17073 | |
c19d1205 ZW |
17074 | frag_align (2, 0, 0); |
17075 | record_alignment (now_seg, 2); | |
17076 | unwind.table_entry = expr_build_dot (); | |
17077 | ||
17078 | /* Allocate the table entry. */ | |
17079 | ptr = frag_more ((size << 2) + 4); | |
17080 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 17081 | |
c19d1205 | 17082 | switch (unwind.personality_index) |
bfae80f2 | 17083 | { |
c19d1205 ZW |
17084 | case -1: |
17085 | /* ??? Should this be a PLT generating relocation? */ | |
17086 | /* Custom personality routine. */ | |
17087 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
17088 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 17089 | |
c19d1205 ZW |
17090 | where += 4; |
17091 | ptr += 4; | |
bfae80f2 | 17092 | |
c19d1205 ZW |
17093 | /* Set the first byte to the number of additional words. */ |
17094 | data = size - 1; | |
17095 | n = 3; | |
17096 | break; | |
bfae80f2 | 17097 | |
c19d1205 ZW |
17098 | /* ABI defined personality routines. */ |
17099 | case 0: | |
17100 | /* Three opcodes bytes are packed into the first word. */ | |
17101 | data = 0x80; | |
17102 | n = 3; | |
17103 | break; | |
bfae80f2 | 17104 | |
c19d1205 ZW |
17105 | case 1: |
17106 | case 2: | |
17107 | /* The size and first two opcode bytes go in the first word. */ | |
17108 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
17109 | n = 2; | |
17110 | break; | |
bfae80f2 | 17111 | |
c19d1205 ZW |
17112 | default: |
17113 | /* Should never happen. */ | |
17114 | abort (); | |
17115 | } | |
bfae80f2 | 17116 | |
c19d1205 ZW |
17117 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
17118 | time. */ | |
17119 | while (unwind.opcode_count > 0) | |
17120 | { | |
17121 | if (n == 0) | |
17122 | { | |
17123 | md_number_to_chars (ptr, data, 4); | |
17124 | ptr += 4; | |
17125 | n = 4; | |
17126 | data = 0; | |
17127 | } | |
17128 | unwind.opcode_count--; | |
17129 | n--; | |
17130 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
17131 | } | |
17132 | ||
17133 | /* Finish off the last word. */ | |
17134 | if (n < 4) | |
17135 | { | |
17136 | /* Pad with "finish" opcodes. */ | |
17137 | while (n--) | |
17138 | data = (data << 8) | 0xb0; | |
17139 | ||
17140 | md_number_to_chars (ptr, data, 4); | |
17141 | } | |
17142 | ||
17143 | if (!have_data) | |
17144 | { | |
17145 | /* Add an empty descriptor if there is no user-specified data. */ | |
17146 | ptr = frag_more (4); | |
17147 | md_number_to_chars (ptr, 0, 4); | |
17148 | } | |
17149 | ||
17150 | return 0; | |
bfae80f2 RE |
17151 | } |
17152 | ||
f0927246 NC |
17153 | |
17154 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
17155 | ||
17156 | void | |
17157 | tc_arm_frame_initial_instructions (void) | |
17158 | { | |
17159 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
17160 | } | |
17161 | #endif /* OBJ_ELF */ | |
17162 | ||
c19d1205 ZW |
17163 | /* Convert REGNAME to a DWARF-2 register number. */ |
17164 | ||
17165 | int | |
1df69f4f | 17166 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 17167 | { |
1df69f4f | 17168 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
17169 | |
17170 | if (reg == FAIL) | |
17171 | return -1; | |
17172 | ||
17173 | return reg; | |
bfae80f2 RE |
17174 | } |
17175 | ||
f0927246 | 17176 | #ifdef TE_PE |
c19d1205 | 17177 | void |
f0927246 | 17178 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 17179 | { |
f0927246 | 17180 | expressionS expr; |
bfae80f2 | 17181 | |
f0927246 NC |
17182 | expr.X_op = O_secrel; |
17183 | expr.X_add_symbol = symbol; | |
17184 | expr.X_add_number = 0; | |
17185 | emit_expr (&expr, size); | |
17186 | } | |
17187 | #endif | |
bfae80f2 | 17188 | |
c19d1205 | 17189 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 17190 | |
2fc8bdac ZW |
17191 | /* Return the address within the segment that a PC-relative fixup is |
17192 | relative to. For ARM, PC-relative fixups applied to instructions | |
17193 | are generally relative to the location of the fixup plus 8 bytes. | |
17194 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
17195 | require special handling. */ | |
bfae80f2 | 17196 | |
c19d1205 | 17197 | long |
2fc8bdac | 17198 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 17199 | { |
2fc8bdac ZW |
17200 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
17201 | ||
17202 | /* If this is pc-relative and we are going to emit a relocation | |
17203 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
17204 | will need. Otherwise we want to use the calculated base. |
17205 | For WinCE we skip the bias for externals as well, since this | |
17206 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
2fc8bdac ZW |
17207 | if (fixP->fx_pcrel |
17208 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
53baae48 NC |
17209 | || (arm_force_relocation (fixP) |
17210 | #ifdef TE_WINCE | |
17211 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
17212 | #endif | |
17213 | ))) | |
2fc8bdac | 17214 | base = 0; |
bfae80f2 | 17215 | |
c19d1205 | 17216 | switch (fixP->fx_r_type) |
bfae80f2 | 17217 | { |
2fc8bdac ZW |
17218 | /* PC relative addressing on the Thumb is slightly odd as the |
17219 | bottom two bits of the PC are forced to zero for the | |
17220 | calculation. This happens *after* application of the | |
17221 | pipeline offset. However, Thumb adrl already adjusts for | |
17222 | this, so we need not do it again. */ | |
c19d1205 | 17223 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 17224 | return base & ~3; |
c19d1205 ZW |
17225 | |
17226 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
17227 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 17228 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 17229 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 17230 | return (base + 4) & ~3; |
c19d1205 | 17231 | |
2fc8bdac ZW |
17232 | /* Thumb branches are simply offset by +4. */ |
17233 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
17234 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
17235 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
17236 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
17237 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
17238 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
17239 | case BFD_RELOC_THUMB_PCREL_BLX: | |
17240 | return base + 4; | |
bfae80f2 | 17241 | |
2fc8bdac ZW |
17242 | /* ARM mode branches are offset by +8. However, the Windows CE |
17243 | loader expects the relocation not to take this into account. */ | |
17244 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
39b41c9c PB |
17245 | case BFD_RELOC_ARM_PCREL_CALL: |
17246 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac ZW |
17247 | case BFD_RELOC_ARM_PCREL_BLX: |
17248 | case BFD_RELOC_ARM_PLT32: | |
c19d1205 | 17249 | #ifdef TE_WINCE |
53baae48 NC |
17250 | /* When handling fixups immediately, because we have already |
17251 | discovered the value of a symbol, or the address of the frag involved | |
17252 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
17253 | see fixup_segment() in write.c | |
17254 | The S_IS_EXTERNAL test handles the case of global symbols. | |
17255 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
17256 | if (fixP->fx_pcrel | |
17257 | && fixP->fx_addsy != NULL | |
17258 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
17259 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
17260 | return base + 8; | |
2fc8bdac | 17261 | return base; |
c19d1205 | 17262 | #else |
2fc8bdac | 17263 | return base + 8; |
c19d1205 | 17264 | #endif |
2fc8bdac ZW |
17265 | |
17266 | /* ARM mode loads relative to PC are also offset by +8. Unlike | |
17267 | branches, the Windows CE loader *does* expect the relocation | |
17268 | to take this into account. */ | |
17269 | case BFD_RELOC_ARM_OFFSET_IMM: | |
17270 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
17271 | case BFD_RELOC_ARM_HWLITERAL: | |
17272 | case BFD_RELOC_ARM_LITERAL: | |
17273 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
17274 | return base + 8; | |
17275 | ||
17276 | ||
17277 | /* Other PC-relative relocations are un-offset. */ | |
17278 | default: | |
17279 | return base; | |
17280 | } | |
bfae80f2 RE |
17281 | } |
17282 | ||
c19d1205 ZW |
17283 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
17284 | Otherwise we have no need to default values of symbols. */ | |
17285 | ||
17286 | symbolS * | |
17287 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 17288 | { |
c19d1205 ZW |
17289 | #ifdef OBJ_ELF |
17290 | if (name[0] == '_' && name[1] == 'G' | |
17291 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
17292 | { | |
17293 | if (!GOT_symbol) | |
17294 | { | |
17295 | if (symbol_find (name)) | |
17296 | as_bad ("GOT already in the symbol table"); | |
bfae80f2 | 17297 | |
c19d1205 ZW |
17298 | GOT_symbol = symbol_new (name, undefined_section, |
17299 | (valueT) 0, & zero_address_frag); | |
17300 | } | |
bfae80f2 | 17301 | |
c19d1205 | 17302 | return GOT_symbol; |
bfae80f2 | 17303 | } |
c19d1205 | 17304 | #endif |
bfae80f2 | 17305 | |
c19d1205 | 17306 | return 0; |
bfae80f2 RE |
17307 | } |
17308 | ||
55cf6793 | 17309 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
17310 | computed as two separate immediate values, added together. We |
17311 | already know that this value cannot be computed by just one ARM | |
17312 | instruction. */ | |
17313 | ||
17314 | static unsigned int | |
17315 | validate_immediate_twopart (unsigned int val, | |
17316 | unsigned int * highpart) | |
bfae80f2 | 17317 | { |
c19d1205 ZW |
17318 | unsigned int a; |
17319 | unsigned int i; | |
bfae80f2 | 17320 | |
c19d1205 ZW |
17321 | for (i = 0; i < 32; i += 2) |
17322 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
17323 | { | |
17324 | if (a & 0xff00) | |
17325 | { | |
17326 | if (a & ~ 0xffff) | |
17327 | continue; | |
17328 | * highpart = (a >> 8) | ((i + 24) << 7); | |
17329 | } | |
17330 | else if (a & 0xff0000) | |
17331 | { | |
17332 | if (a & 0xff000000) | |
17333 | continue; | |
17334 | * highpart = (a >> 16) | ((i + 16) << 7); | |
17335 | } | |
17336 | else | |
17337 | { | |
17338 | assert (a & 0xff000000); | |
17339 | * highpart = (a >> 24) | ((i + 8) << 7); | |
17340 | } | |
bfae80f2 | 17341 | |
c19d1205 ZW |
17342 | return (a & 0xff) | (i << 7); |
17343 | } | |
bfae80f2 | 17344 | |
c19d1205 | 17345 | return FAIL; |
bfae80f2 RE |
17346 | } |
17347 | ||
c19d1205 ZW |
17348 | static int |
17349 | validate_offset_imm (unsigned int val, int hwse) | |
17350 | { | |
17351 | if ((hwse && val > 255) || val > 4095) | |
17352 | return FAIL; | |
17353 | return val; | |
17354 | } | |
bfae80f2 | 17355 | |
55cf6793 | 17356 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
17357 | negative immediate constant by altering the instruction. A bit of |
17358 | a hack really. | |
17359 | MOV <-> MVN | |
17360 | AND <-> BIC | |
17361 | ADC <-> SBC | |
17362 | by inverting the second operand, and | |
17363 | ADD <-> SUB | |
17364 | CMP <-> CMN | |
17365 | by negating the second operand. */ | |
bfae80f2 | 17366 | |
c19d1205 ZW |
17367 | static int |
17368 | negate_data_op (unsigned long * instruction, | |
17369 | unsigned long value) | |
bfae80f2 | 17370 | { |
c19d1205 ZW |
17371 | int op, new_inst; |
17372 | unsigned long negated, inverted; | |
bfae80f2 | 17373 | |
c19d1205 ZW |
17374 | negated = encode_arm_immediate (-value); |
17375 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 17376 | |
c19d1205 ZW |
17377 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
17378 | switch (op) | |
bfae80f2 | 17379 | { |
c19d1205 ZW |
17380 | /* First negates. */ |
17381 | case OPCODE_SUB: /* ADD <-> SUB */ | |
17382 | new_inst = OPCODE_ADD; | |
17383 | value = negated; | |
17384 | break; | |
bfae80f2 | 17385 | |
c19d1205 ZW |
17386 | case OPCODE_ADD: |
17387 | new_inst = OPCODE_SUB; | |
17388 | value = negated; | |
17389 | break; | |
bfae80f2 | 17390 | |
c19d1205 ZW |
17391 | case OPCODE_CMP: /* CMP <-> CMN */ |
17392 | new_inst = OPCODE_CMN; | |
17393 | value = negated; | |
17394 | break; | |
bfae80f2 | 17395 | |
c19d1205 ZW |
17396 | case OPCODE_CMN: |
17397 | new_inst = OPCODE_CMP; | |
17398 | value = negated; | |
17399 | break; | |
bfae80f2 | 17400 | |
c19d1205 ZW |
17401 | /* Now Inverted ops. */ |
17402 | case OPCODE_MOV: /* MOV <-> MVN */ | |
17403 | new_inst = OPCODE_MVN; | |
17404 | value = inverted; | |
17405 | break; | |
bfae80f2 | 17406 | |
c19d1205 ZW |
17407 | case OPCODE_MVN: |
17408 | new_inst = OPCODE_MOV; | |
17409 | value = inverted; | |
17410 | break; | |
bfae80f2 | 17411 | |
c19d1205 ZW |
17412 | case OPCODE_AND: /* AND <-> BIC */ |
17413 | new_inst = OPCODE_BIC; | |
17414 | value = inverted; | |
17415 | break; | |
bfae80f2 | 17416 | |
c19d1205 ZW |
17417 | case OPCODE_BIC: |
17418 | new_inst = OPCODE_AND; | |
17419 | value = inverted; | |
17420 | break; | |
bfae80f2 | 17421 | |
c19d1205 ZW |
17422 | case OPCODE_ADC: /* ADC <-> SBC */ |
17423 | new_inst = OPCODE_SBC; | |
17424 | value = inverted; | |
17425 | break; | |
bfae80f2 | 17426 | |
c19d1205 ZW |
17427 | case OPCODE_SBC: |
17428 | new_inst = OPCODE_ADC; | |
17429 | value = inverted; | |
17430 | break; | |
bfae80f2 | 17431 | |
c19d1205 ZW |
17432 | /* We cannot do anything. */ |
17433 | default: | |
17434 | return FAIL; | |
b99bd4ef NC |
17435 | } |
17436 | ||
c19d1205 ZW |
17437 | if (value == (unsigned) FAIL) |
17438 | return FAIL; | |
17439 | ||
17440 | *instruction &= OPCODE_MASK; | |
17441 | *instruction |= new_inst << DATA_OP_SHIFT; | |
17442 | return value; | |
b99bd4ef NC |
17443 | } |
17444 | ||
ef8d22e6 PB |
17445 | /* Like negate_data_op, but for Thumb-2. */ |
17446 | ||
17447 | static unsigned int | |
16dd5e42 | 17448 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
17449 | { |
17450 | int op, new_inst; | |
17451 | int rd; | |
16dd5e42 | 17452 | unsigned int negated, inverted; |
ef8d22e6 PB |
17453 | |
17454 | negated = encode_thumb32_immediate (-value); | |
17455 | inverted = encode_thumb32_immediate (~value); | |
17456 | ||
17457 | rd = (*instruction >> 8) & 0xf; | |
17458 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
17459 | switch (op) | |
17460 | { | |
17461 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
17462 | case T2_OPCODE_SUB: | |
17463 | new_inst = T2_OPCODE_ADD; | |
17464 | value = negated; | |
17465 | break; | |
17466 | ||
17467 | case T2_OPCODE_ADD: | |
17468 | new_inst = T2_OPCODE_SUB; | |
17469 | value = negated; | |
17470 | break; | |
17471 | ||
17472 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
17473 | case T2_OPCODE_ORR: | |
17474 | new_inst = T2_OPCODE_ORN; | |
17475 | value = inverted; | |
17476 | break; | |
17477 | ||
17478 | case T2_OPCODE_ORN: | |
17479 | new_inst = T2_OPCODE_ORR; | |
17480 | value = inverted; | |
17481 | break; | |
17482 | ||
17483 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
17484 | case T2_OPCODE_AND: | |
17485 | new_inst = T2_OPCODE_BIC; | |
17486 | if (rd == 15) | |
17487 | value = FAIL; | |
17488 | else | |
17489 | value = inverted; | |
17490 | break; | |
17491 | ||
17492 | case T2_OPCODE_BIC: | |
17493 | new_inst = T2_OPCODE_AND; | |
17494 | value = inverted; | |
17495 | break; | |
17496 | ||
17497 | /* ADC <-> SBC */ | |
17498 | case T2_OPCODE_ADC: | |
17499 | new_inst = T2_OPCODE_SBC; | |
17500 | value = inverted; | |
17501 | break; | |
17502 | ||
17503 | case T2_OPCODE_SBC: | |
17504 | new_inst = T2_OPCODE_ADC; | |
17505 | value = inverted; | |
17506 | break; | |
17507 | ||
17508 | /* We cannot do anything. */ | |
17509 | default: | |
17510 | return FAIL; | |
17511 | } | |
17512 | ||
16dd5e42 | 17513 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
17514 | return FAIL; |
17515 | ||
17516 | *instruction &= T2_OPCODE_MASK; | |
17517 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
17518 | return value; | |
17519 | } | |
17520 | ||
8f06b2d8 PB |
17521 | /* Read a 32-bit thumb instruction from buf. */ |
17522 | static unsigned long | |
17523 | get_thumb32_insn (char * buf) | |
17524 | { | |
17525 | unsigned long insn; | |
17526 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
17527 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
17528 | ||
17529 | return insn; | |
17530 | } | |
17531 | ||
a8bc6c78 PB |
17532 | |
17533 | /* We usually want to set the low bit on the address of thumb function | |
17534 | symbols. In particular .word foo - . should have the low bit set. | |
17535 | Generic code tries to fold the difference of two symbols to | |
17536 | a constant. Prevent this and force a relocation when the first symbols | |
17537 | is a thumb function. */ | |
17538 | int | |
17539 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) | |
17540 | { | |
17541 | if (op == O_subtract | |
17542 | && l->X_op == O_symbol | |
17543 | && r->X_op == O_symbol | |
17544 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
17545 | { | |
17546 | l->X_op = O_subtract; | |
17547 | l->X_op_symbol = r->X_add_symbol; | |
17548 | l->X_add_number -= r->X_add_number; | |
17549 | return 1; | |
17550 | } | |
17551 | /* Process as normal. */ | |
17552 | return 0; | |
17553 | } | |
17554 | ||
c19d1205 | 17555 | void |
55cf6793 | 17556 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
17557 | valueT * valP, |
17558 | segT seg) | |
17559 | { | |
17560 | offsetT value = * valP; | |
17561 | offsetT newval; | |
17562 | unsigned int newimm; | |
17563 | unsigned long temp; | |
17564 | int sign; | |
17565 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 17566 | |
c19d1205 | 17567 | assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 17568 | |
c19d1205 | 17569 | /* Note whether this will delete the relocation. */ |
4962c51a | 17570 | |
c19d1205 ZW |
17571 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
17572 | fixP->fx_done = 1; | |
b99bd4ef | 17573 | |
adbaf948 ZW |
17574 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
17575 | consistency with the behavior on 32-bit hosts. Remember value | |
17576 | for emit_reloc. */ | |
17577 | value &= 0xffffffff; | |
17578 | value ^= 0x80000000; | |
17579 | value -= 0x80000000; | |
17580 | ||
17581 | *valP = value; | |
c19d1205 | 17582 | fixP->fx_addnumber = value; |
b99bd4ef | 17583 | |
adbaf948 ZW |
17584 | /* Same treatment for fixP->fx_offset. */ |
17585 | fixP->fx_offset &= 0xffffffff; | |
17586 | fixP->fx_offset ^= 0x80000000; | |
17587 | fixP->fx_offset -= 0x80000000; | |
17588 | ||
c19d1205 | 17589 | switch (fixP->fx_r_type) |
b99bd4ef | 17590 | { |
c19d1205 ZW |
17591 | case BFD_RELOC_NONE: |
17592 | /* This will need to go in the object file. */ | |
17593 | fixP->fx_done = 0; | |
17594 | break; | |
b99bd4ef | 17595 | |
c19d1205 ZW |
17596 | case BFD_RELOC_ARM_IMMEDIATE: |
17597 | /* We claim that this fixup has been processed here, | |
17598 | even if in fact we generate an error because we do | |
17599 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
17600 | fixP->fx_done = 1; | |
b99bd4ef | 17601 | |
c19d1205 ZW |
17602 | if (fixP->fx_addsy |
17603 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 17604 | { |
c19d1205 ZW |
17605 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17606 | _("undefined symbol %s used as an immediate value"), | |
17607 | S_GET_NAME (fixP->fx_addsy)); | |
17608 | break; | |
b99bd4ef NC |
17609 | } |
17610 | ||
c19d1205 ZW |
17611 | newimm = encode_arm_immediate (value); |
17612 | temp = md_chars_to_number (buf, INSN_SIZE); | |
17613 | ||
17614 | /* If the instruction will fail, see if we can fix things up by | |
17615 | changing the opcode. */ | |
17616 | if (newimm == (unsigned int) FAIL | |
17617 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 17618 | { |
c19d1205 ZW |
17619 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17620 | _("invalid constant (%lx) after fixup"), | |
17621 | (unsigned long) value); | |
17622 | break; | |
b99bd4ef | 17623 | } |
b99bd4ef | 17624 | |
c19d1205 ZW |
17625 | newimm |= (temp & 0xfffff000); |
17626 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
17627 | break; | |
b99bd4ef | 17628 | |
c19d1205 ZW |
17629 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
17630 | { | |
17631 | unsigned int highpart = 0; | |
17632 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 17633 | |
c19d1205 ZW |
17634 | newimm = encode_arm_immediate (value); |
17635 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 17636 | |
c19d1205 ZW |
17637 | /* If the instruction will fail, see if we can fix things up by |
17638 | changing the opcode. */ | |
17639 | if (newimm == (unsigned int) FAIL | |
17640 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
17641 | { | |
17642 | /* No ? OK - try using two ADD instructions to generate | |
17643 | the value. */ | |
17644 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 17645 | |
c19d1205 ZW |
17646 | /* Yes - then make sure that the second instruction is |
17647 | also an add. */ | |
17648 | if (newimm != (unsigned int) FAIL) | |
17649 | newinsn = temp; | |
17650 | /* Still No ? Try using a negated value. */ | |
17651 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
17652 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
17653 | /* Otherwise - give up. */ | |
17654 | else | |
17655 | { | |
17656 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17657 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
17658 | (long) value); | |
17659 | break; | |
17660 | } | |
b99bd4ef | 17661 | |
c19d1205 ZW |
17662 | /* Replace the first operand in the 2nd instruction (which |
17663 | is the PC) with the destination register. We have | |
17664 | already added in the PC in the first instruction and we | |
17665 | do not want to do it again. */ | |
17666 | newinsn &= ~ 0xf0000; | |
17667 | newinsn |= ((newinsn & 0x0f000) << 4); | |
17668 | } | |
b99bd4ef | 17669 | |
c19d1205 ZW |
17670 | newimm |= (temp & 0xfffff000); |
17671 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 17672 | |
c19d1205 ZW |
17673 | highpart |= (newinsn & 0xfffff000); |
17674 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
17675 | } | |
17676 | break; | |
b99bd4ef | 17677 | |
c19d1205 | 17678 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
17679 | if (!fixP->fx_done && seg->use_rela_p) |
17680 | value = 0; | |
17681 | ||
c19d1205 ZW |
17682 | case BFD_RELOC_ARM_LITERAL: |
17683 | sign = value >= 0; | |
b99bd4ef | 17684 | |
c19d1205 ZW |
17685 | if (value < 0) |
17686 | value = - value; | |
b99bd4ef | 17687 | |
c19d1205 | 17688 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 17689 | { |
c19d1205 ZW |
17690 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
17691 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17692 | _("invalid literal constant: pool needs to be closer")); | |
17693 | else | |
17694 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17695 | _("bad immediate value for offset (%ld)"), | |
17696 | (long) value); | |
17697 | break; | |
f03698e6 RE |
17698 | } |
17699 | ||
c19d1205 ZW |
17700 | newval = md_chars_to_number (buf, INSN_SIZE); |
17701 | newval &= 0xff7ff000; | |
17702 | newval |= value | (sign ? INDEX_UP : 0); | |
17703 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17704 | break; | |
b99bd4ef | 17705 | |
c19d1205 ZW |
17706 | case BFD_RELOC_ARM_OFFSET_IMM8: |
17707 | case BFD_RELOC_ARM_HWLITERAL: | |
17708 | sign = value >= 0; | |
b99bd4ef | 17709 | |
c19d1205 ZW |
17710 | if (value < 0) |
17711 | value = - value; | |
b99bd4ef | 17712 | |
c19d1205 | 17713 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 17714 | { |
c19d1205 ZW |
17715 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
17716 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17717 | _("invalid literal constant: pool needs to be closer")); | |
17718 | else | |
17719 | as_bad (_("bad immediate value for half-word offset (%ld)"), | |
17720 | (long) value); | |
17721 | break; | |
b99bd4ef NC |
17722 | } |
17723 | ||
c19d1205 ZW |
17724 | newval = md_chars_to_number (buf, INSN_SIZE); |
17725 | newval &= 0xff7ff0f0; | |
17726 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
17727 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17728 | break; | |
b99bd4ef | 17729 | |
c19d1205 ZW |
17730 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
17731 | if (value < 0 || value > 1020 || value % 4 != 0) | |
17732 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17733 | _("bad immediate value for offset (%ld)"), (long) value); | |
17734 | value /= 4; | |
b99bd4ef | 17735 | |
c19d1205 | 17736 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
17737 | newval |= value; |
17738 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
17739 | break; | |
b99bd4ef | 17740 | |
c19d1205 ZW |
17741 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
17742 | /* This is a complicated relocation used for all varieties of Thumb32 | |
17743 | load/store instruction with immediate offset: | |
17744 | ||
17745 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
17746 | *4, optional writeback(W) | |
17747 | (doubleword load/store) | |
17748 | ||
17749 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
17750 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
17751 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
17752 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
17753 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
17754 | ||
17755 | Uppercase letters indicate bits that are already encoded at | |
17756 | this point. Lowercase letters are our problem. For the | |
17757 | second block of instructions, the secondary opcode nybble | |
17758 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
17759 | a PC-relative operation. */ | |
17760 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
17761 | newval <<= 16; | |
17762 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 17763 | |
c19d1205 | 17764 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 17765 | { |
c19d1205 ZW |
17766 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
17767 | if (value >= 0) | |
17768 | newval |= (1 << 23); | |
17769 | else | |
17770 | value = -value; | |
17771 | if (value % 4 != 0) | |
17772 | { | |
17773 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17774 | _("offset not a multiple of 4")); | |
17775 | break; | |
17776 | } | |
17777 | value /= 4; | |
216d22bc | 17778 | if (value > 0xff) |
c19d1205 ZW |
17779 | { |
17780 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17781 | _("offset out of range")); | |
17782 | break; | |
17783 | } | |
17784 | newval &= ~0xff; | |
b99bd4ef | 17785 | } |
c19d1205 | 17786 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 17787 | { |
c19d1205 ZW |
17788 | /* PC-relative, 12-bit offset. */ |
17789 | if (value >= 0) | |
17790 | newval |= (1 << 23); | |
17791 | else | |
17792 | value = -value; | |
216d22bc | 17793 | if (value > 0xfff) |
c19d1205 ZW |
17794 | { |
17795 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17796 | _("offset out of range")); | |
17797 | break; | |
17798 | } | |
17799 | newval &= ~0xfff; | |
b99bd4ef | 17800 | } |
c19d1205 | 17801 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 17802 | { |
c19d1205 ZW |
17803 | /* Writeback: 8-bit, +/- offset. */ |
17804 | if (value >= 0) | |
17805 | newval |= (1 << 9); | |
17806 | else | |
17807 | value = -value; | |
216d22bc | 17808 | if (value > 0xff) |
c19d1205 ZW |
17809 | { |
17810 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17811 | _("offset out of range")); | |
17812 | break; | |
17813 | } | |
17814 | newval &= ~0xff; | |
b99bd4ef | 17815 | } |
c19d1205 | 17816 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 17817 | { |
c19d1205 | 17818 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 17819 | if (value < 0 || value > 0xff) |
b99bd4ef | 17820 | { |
c19d1205 ZW |
17821 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17822 | _("offset out of range")); | |
17823 | break; | |
b99bd4ef | 17824 | } |
c19d1205 ZW |
17825 | newval &= ~0xff; |
17826 | newval |= value; | |
b99bd4ef NC |
17827 | } |
17828 | else | |
b99bd4ef | 17829 | { |
c19d1205 ZW |
17830 | /* Positive 12-bit or negative 8-bit offset. */ |
17831 | int limit; | |
17832 | if (value >= 0) | |
b99bd4ef | 17833 | { |
c19d1205 ZW |
17834 | newval |= (1 << 23); |
17835 | limit = 0xfff; | |
17836 | } | |
17837 | else | |
17838 | { | |
17839 | value = -value; | |
17840 | limit = 0xff; | |
17841 | } | |
17842 | if (value > limit) | |
17843 | { | |
17844 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17845 | _("offset out of range")); | |
17846 | break; | |
b99bd4ef | 17847 | } |
c19d1205 | 17848 | newval &= ~limit; |
b99bd4ef | 17849 | } |
b99bd4ef | 17850 | |
c19d1205 ZW |
17851 | newval |= value; |
17852 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
17853 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
17854 | break; | |
404ff6b5 | 17855 | |
c19d1205 ZW |
17856 | case BFD_RELOC_ARM_SHIFT_IMM: |
17857 | newval = md_chars_to_number (buf, INSN_SIZE); | |
17858 | if (((unsigned long) value) > 32 | |
17859 | || (value == 32 | |
17860 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
17861 | { | |
17862 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17863 | _("shift expression is too large")); | |
17864 | break; | |
17865 | } | |
404ff6b5 | 17866 | |
c19d1205 ZW |
17867 | if (value == 0) |
17868 | /* Shifts of zero must be done as lsl. */ | |
17869 | newval &= ~0x60; | |
17870 | else if (value == 32) | |
17871 | value = 0; | |
17872 | newval &= 0xfffff07f; | |
17873 | newval |= (value & 0x1f) << 7; | |
17874 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17875 | break; | |
404ff6b5 | 17876 | |
c19d1205 | 17877 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 17878 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 17879 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 17880 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
17881 | /* We claim that this fixup has been processed here, |
17882 | even if in fact we generate an error because we do | |
17883 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
17884 | fixP->fx_done = 1; | |
404ff6b5 | 17885 | |
c19d1205 ZW |
17886 | if (fixP->fx_addsy |
17887 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
17888 | { | |
17889 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17890 | _("undefined symbol %s used as an immediate value"), | |
17891 | S_GET_NAME (fixP->fx_addsy)); | |
17892 | break; | |
17893 | } | |
404ff6b5 | 17894 | |
c19d1205 ZW |
17895 | newval = md_chars_to_number (buf, THUMB_SIZE); |
17896 | newval <<= 16; | |
17897 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 17898 | |
16805f35 PB |
17899 | newimm = FAIL; |
17900 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
17901 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
17902 | { |
17903 | newimm = encode_thumb32_immediate (value); | |
17904 | if (newimm == (unsigned int) FAIL) | |
17905 | newimm = thumb32_negate_data_op (&newval, value); | |
17906 | } | |
16805f35 PB |
17907 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
17908 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 17909 | { |
16805f35 PB |
17910 | /* Turn add/sum into addw/subw. */ |
17911 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
17912 | newval = (newval & 0xfeffffff) | 0x02000000; | |
17913 | ||
e9f89963 PB |
17914 | /* 12 bit immediate for addw/subw. */ |
17915 | if (value < 0) | |
17916 | { | |
17917 | value = -value; | |
17918 | newval ^= 0x00a00000; | |
17919 | } | |
92e90b6e PB |
17920 | if (value > 0xfff) |
17921 | newimm = (unsigned int) FAIL; | |
17922 | else | |
17923 | newimm = value; | |
17924 | } | |
cc8a6dd0 | 17925 | |
c19d1205 | 17926 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 17927 | { |
c19d1205 ZW |
17928 | as_bad_where (fixP->fx_file, fixP->fx_line, |
17929 | _("invalid constant (%lx) after fixup"), | |
17930 | (unsigned long) value); | |
17931 | break; | |
3631a3c8 NC |
17932 | } |
17933 | ||
c19d1205 ZW |
17934 | newval |= (newimm & 0x800) << 15; |
17935 | newval |= (newimm & 0x700) << 4; | |
17936 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 17937 | |
c19d1205 ZW |
17938 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
17939 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
17940 | break; | |
a737bd4d | 17941 | |
3eb17e6b | 17942 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
17943 | if (((unsigned long) value) > 0xffff) |
17944 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 17945 | _("invalid smc expression")); |
2fc8bdac | 17946 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
17947 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
17948 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17949 | break; | |
a737bd4d | 17950 | |
c19d1205 | 17951 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 17952 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
17953 | { |
17954 | if (((unsigned long) value) > 0xff) | |
17955 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17956 | _("invalid swi expression")); | |
2fc8bdac | 17957 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
17958 | newval |= value; |
17959 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
17960 | } | |
17961 | else | |
17962 | { | |
17963 | if (((unsigned long) value) > 0x00ffffff) | |
17964 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17965 | _("invalid swi expression")); | |
2fc8bdac | 17966 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
17967 | newval |= value; |
17968 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17969 | } | |
17970 | break; | |
a737bd4d | 17971 | |
c19d1205 ZW |
17972 | case BFD_RELOC_ARM_MULTI: |
17973 | if (((unsigned long) value) > 0xffff) | |
17974 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
17975 | _("invalid expression in load/store multiple")); | |
17976 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
17977 | md_number_to_chars (buf, newval, INSN_SIZE); | |
17978 | break; | |
a737bd4d | 17979 | |
c19d1205 | 17980 | #ifdef OBJ_ELF |
39b41c9c PB |
17981 | case BFD_RELOC_ARM_PCREL_CALL: |
17982 | newval = md_chars_to_number (buf, INSN_SIZE); | |
17983 | if ((newval & 0xf0000000) == 0xf0000000) | |
17984 | temp = 1; | |
17985 | else | |
17986 | temp = 3; | |
17987 | goto arm_branch_common; | |
17988 | ||
17989 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac | 17990 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 17991 | #endif |
39b41c9c PB |
17992 | case BFD_RELOC_ARM_PCREL_BRANCH: |
17993 | temp = 3; | |
17994 | goto arm_branch_common; | |
a737bd4d | 17995 | |
39b41c9c PB |
17996 | case BFD_RELOC_ARM_PCREL_BLX: |
17997 | temp = 1; | |
17998 | arm_branch_common: | |
c19d1205 | 17999 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
18000 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
18001 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
18002 | also be be clear. */ | |
18003 | if (value & temp) | |
c19d1205 | 18004 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
18005 | _("misaligned branch destination")); |
18006 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
18007 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
18008 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18009 | _("branch out of range")); | |
a737bd4d | 18010 | |
2fc8bdac | 18011 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 18012 | { |
2fc8bdac ZW |
18013 | newval = md_chars_to_number (buf, INSN_SIZE); |
18014 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
18015 | /* Set the H bit on BLX instructions. */ |
18016 | if (temp == 1) | |
18017 | { | |
18018 | if (value & 2) | |
18019 | newval |= 0x01000000; | |
18020 | else | |
18021 | newval &= ~0x01000000; | |
18022 | } | |
2fc8bdac | 18023 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 18024 | } |
c19d1205 | 18025 | break; |
a737bd4d | 18026 | |
c19d1205 | 18027 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */ |
2fc8bdac ZW |
18028 | /* CZB can only branch forward. */ |
18029 | if (value & ~0x7e) | |
18030 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18031 | _("branch out of range")); | |
a737bd4d | 18032 | |
2fc8bdac ZW |
18033 | if (fixP->fx_done || !seg->use_rela_p) |
18034 | { | |
18035 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
080eb7fe | 18036 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); |
2fc8bdac ZW |
18037 | md_number_to_chars (buf, newval, THUMB_SIZE); |
18038 | } | |
c19d1205 | 18039 | break; |
a737bd4d | 18040 | |
c19d1205 | 18041 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
18042 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
18043 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18044 | _("branch out of range")); | |
a737bd4d | 18045 | |
2fc8bdac ZW |
18046 | if (fixP->fx_done || !seg->use_rela_p) |
18047 | { | |
18048 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18049 | newval |= (value & 0x1ff) >> 1; | |
18050 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18051 | } | |
c19d1205 | 18052 | break; |
a737bd4d | 18053 | |
c19d1205 | 18054 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
18055 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
18056 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18057 | _("branch out of range")); | |
a737bd4d | 18058 | |
2fc8bdac ZW |
18059 | if (fixP->fx_done || !seg->use_rela_p) |
18060 | { | |
18061 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18062 | newval |= (value & 0xfff) >> 1; | |
18063 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18064 | } | |
c19d1205 | 18065 | break; |
a737bd4d | 18066 | |
c19d1205 | 18067 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
2fc8bdac ZW |
18068 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
18069 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18070 | _("conditional branch out of range")); | |
404ff6b5 | 18071 | |
2fc8bdac ZW |
18072 | if (fixP->fx_done || !seg->use_rela_p) |
18073 | { | |
18074 | offsetT newval2; | |
18075 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 18076 | |
2fc8bdac ZW |
18077 | S = (value & 0x00100000) >> 20; |
18078 | J2 = (value & 0x00080000) >> 19; | |
18079 | J1 = (value & 0x00040000) >> 18; | |
18080 | hi = (value & 0x0003f000) >> 12; | |
18081 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 18082 | |
2fc8bdac ZW |
18083 | newval = md_chars_to_number (buf, THUMB_SIZE); |
18084 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
18085 | newval |= (S << 10) | hi; | |
18086 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
18087 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18088 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
18089 | } | |
c19d1205 | 18090 | break; |
6c43fab6 | 18091 | |
c19d1205 ZW |
18092 | case BFD_RELOC_THUMB_PCREL_BLX: |
18093 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
2fc8bdac ZW |
18094 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
18095 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18096 | _("branch out of range")); | |
404ff6b5 | 18097 | |
2fc8bdac ZW |
18098 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
18099 | /* For a BLX instruction, make sure that the relocation is rounded up | |
18100 | to a word boundary. This follows the semantics of the instruction | |
18101 | which specifies that bit 1 of the target address will come from bit | |
18102 | 1 of the base address. */ | |
18103 | value = (value + 1) & ~ 1; | |
404ff6b5 | 18104 | |
2fc8bdac | 18105 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 18106 | { |
2fc8bdac ZW |
18107 | offsetT newval2; |
18108 | ||
18109 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18110 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
18111 | newval |= (value & 0x7fffff) >> 12; | |
18112 | newval2 |= (value & 0xfff) >> 1; | |
18113 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18114 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 18115 | } |
c19d1205 | 18116 | break; |
404ff6b5 | 18117 | |
c19d1205 | 18118 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
18119 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
18120 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18121 | _("branch out of range")); | |
6c43fab6 | 18122 | |
2fc8bdac ZW |
18123 | if (fixP->fx_done || !seg->use_rela_p) |
18124 | { | |
18125 | offsetT newval2; | |
18126 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 18127 | |
2fc8bdac ZW |
18128 | S = (value & 0x01000000) >> 24; |
18129 | I1 = (value & 0x00800000) >> 23; | |
18130 | I2 = (value & 0x00400000) >> 22; | |
18131 | hi = (value & 0x003ff000) >> 12; | |
18132 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 18133 | |
2fc8bdac ZW |
18134 | I1 = !(I1 ^ S); |
18135 | I2 = !(I2 ^ S); | |
a737bd4d | 18136 | |
2fc8bdac ZW |
18137 | newval = md_chars_to_number (buf, THUMB_SIZE); |
18138 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
18139 | newval |= (S << 10) | hi; | |
18140 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
18141 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18142 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
18143 | } | |
18144 | break; | |
a737bd4d | 18145 | |
2fc8bdac ZW |
18146 | case BFD_RELOC_8: |
18147 | if (fixP->fx_done || !seg->use_rela_p) | |
18148 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 18149 | break; |
a737bd4d | 18150 | |
c19d1205 | 18151 | case BFD_RELOC_16: |
2fc8bdac | 18152 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 18153 | md_number_to_chars (buf, value, 2); |
c19d1205 | 18154 | break; |
a737bd4d | 18155 | |
c19d1205 ZW |
18156 | #ifdef OBJ_ELF |
18157 | case BFD_RELOC_ARM_TLS_GD32: | |
18158 | case BFD_RELOC_ARM_TLS_LE32: | |
18159 | case BFD_RELOC_ARM_TLS_IE32: | |
18160 | case BFD_RELOC_ARM_TLS_LDM32: | |
18161 | case BFD_RELOC_ARM_TLS_LDO32: | |
18162 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
18163 | /* fall through */ | |
6c43fab6 | 18164 | |
c19d1205 ZW |
18165 | case BFD_RELOC_ARM_GOT32: |
18166 | case BFD_RELOC_ARM_GOTOFF: | |
18167 | case BFD_RELOC_ARM_TARGET2: | |
2fc8bdac ZW |
18168 | if (fixP->fx_done || !seg->use_rela_p) |
18169 | md_number_to_chars (buf, 0, 4); | |
c19d1205 ZW |
18170 | break; |
18171 | #endif | |
6c43fab6 | 18172 | |
c19d1205 ZW |
18173 | case BFD_RELOC_RVA: |
18174 | case BFD_RELOC_32: | |
18175 | case BFD_RELOC_ARM_TARGET1: | |
18176 | case BFD_RELOC_ARM_ROSEGREL32: | |
18177 | case BFD_RELOC_ARM_SBREL32: | |
18178 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
18179 | #ifdef TE_PE |
18180 | case BFD_RELOC_32_SECREL: | |
18181 | #endif | |
2fc8bdac | 18182 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
18183 | #ifdef TE_WINCE |
18184 | /* For WinCE we only do this for pcrel fixups. */ | |
18185 | if (fixP->fx_done || fixP->fx_pcrel) | |
18186 | #endif | |
18187 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 18188 | break; |
6c43fab6 | 18189 | |
c19d1205 ZW |
18190 | #ifdef OBJ_ELF |
18191 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 18192 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
18193 | { |
18194 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
18195 | if ((value ^ (value >> 1)) & 0x40000000) | |
18196 | { | |
18197 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18198 | _("rel31 relocation overflow")); | |
18199 | } | |
18200 | newval |= value & 0x7fffffff; | |
18201 | md_number_to_chars (buf, newval, 4); | |
18202 | } | |
18203 | break; | |
c19d1205 | 18204 | #endif |
a737bd4d | 18205 | |
c19d1205 | 18206 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 18207 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
18208 | if (value < -1023 || value > 1023 || (value & 3)) |
18209 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18210 | _("co-processor offset out of range")); | |
18211 | cp_off_common: | |
18212 | sign = value >= 0; | |
18213 | if (value < 0) | |
18214 | value = -value; | |
8f06b2d8 PB |
18215 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
18216 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
18217 | newval = md_chars_to_number (buf, INSN_SIZE); | |
18218 | else | |
18219 | newval = get_thumb32_insn (buf); | |
18220 | newval &= 0xff7fff00; | |
c19d1205 | 18221 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
8f06b2d8 PB |
18222 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
18223 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
18224 | md_number_to_chars (buf, newval, INSN_SIZE); | |
18225 | else | |
18226 | put_thumb32_insn (buf, newval); | |
c19d1205 | 18227 | break; |
a737bd4d | 18228 | |
c19d1205 | 18229 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 18230 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
18231 | if (value < -255 || value > 255) |
18232 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18233 | _("co-processor offset out of range")); | |
df7849c5 | 18234 | value *= 4; |
c19d1205 | 18235 | goto cp_off_common; |
6c43fab6 | 18236 | |
c19d1205 ZW |
18237 | case BFD_RELOC_ARM_THUMB_OFFSET: |
18238 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18239 | /* Exactly what ranges, and where the offset is inserted depends | |
18240 | on the type of instruction, we can establish this from the | |
18241 | top 4 bits. */ | |
18242 | switch (newval >> 12) | |
18243 | { | |
18244 | case 4: /* PC load. */ | |
18245 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
18246 | forced to zero for these loads; md_pcrel_from has already | |
18247 | compensated for this. */ | |
18248 | if (value & 3) | |
18249 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18250 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
18251 | (((unsigned long) fixP->fx_frag->fr_address |
18252 | + (unsigned long) fixP->fx_where) & ~3) | |
18253 | + (unsigned long) value); | |
a737bd4d | 18254 | |
c19d1205 ZW |
18255 | if (value & ~0x3fc) |
18256 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18257 | _("invalid offset, value too big (0x%08lX)"), | |
18258 | (long) value); | |
a737bd4d | 18259 | |
c19d1205 ZW |
18260 | newval |= value >> 2; |
18261 | break; | |
a737bd4d | 18262 | |
c19d1205 ZW |
18263 | case 9: /* SP load/store. */ |
18264 | if (value & ~0x3fc) | |
18265 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18266 | _("invalid offset, value too big (0x%08lX)"), | |
18267 | (long) value); | |
18268 | newval |= value >> 2; | |
18269 | break; | |
6c43fab6 | 18270 | |
c19d1205 ZW |
18271 | case 6: /* Word load/store. */ |
18272 | if (value & ~0x7c) | |
18273 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18274 | _("invalid offset, value too big (0x%08lX)"), | |
18275 | (long) value); | |
18276 | newval |= value << 4; /* 6 - 2. */ | |
18277 | break; | |
a737bd4d | 18278 | |
c19d1205 ZW |
18279 | case 7: /* Byte load/store. */ |
18280 | if (value & ~0x1f) | |
18281 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18282 | _("invalid offset, value too big (0x%08lX)"), | |
18283 | (long) value); | |
18284 | newval |= value << 6; | |
18285 | break; | |
a737bd4d | 18286 | |
c19d1205 ZW |
18287 | case 8: /* Halfword load/store. */ |
18288 | if (value & ~0x3e) | |
18289 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18290 | _("invalid offset, value too big (0x%08lX)"), | |
18291 | (long) value); | |
18292 | newval |= value << 5; /* 6 - 1. */ | |
18293 | break; | |
a737bd4d | 18294 | |
c19d1205 ZW |
18295 | default: |
18296 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18297 | "Unable to process relocation for thumb opcode: %lx", | |
18298 | (unsigned long) newval); | |
18299 | break; | |
18300 | } | |
18301 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18302 | break; | |
a737bd4d | 18303 | |
c19d1205 ZW |
18304 | case BFD_RELOC_ARM_THUMB_ADD: |
18305 | /* This is a complicated relocation, since we use it for all of | |
18306 | the following immediate relocations: | |
a737bd4d | 18307 | |
c19d1205 ZW |
18308 | 3bit ADD/SUB |
18309 | 8bit ADD/SUB | |
18310 | 9bit ADD/SUB SP word-aligned | |
18311 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 18312 | |
c19d1205 ZW |
18313 | The type of instruction being processed is encoded in the |
18314 | instruction field: | |
a737bd4d | 18315 | |
c19d1205 ZW |
18316 | 0x8000 SUB |
18317 | 0x00F0 Rd | |
18318 | 0x000F Rs | |
18319 | */ | |
18320 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18321 | { | |
18322 | int rd = (newval >> 4) & 0xf; | |
18323 | int rs = newval & 0xf; | |
18324 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 18325 | |
c19d1205 ZW |
18326 | /* Check for HI regs, only very restricted cases allowed: |
18327 | Adjusting SP, and using PC or SP to get an address. */ | |
18328 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
18329 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
18330 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18331 | _("invalid Hi register with immediate")); | |
a737bd4d | 18332 | |
c19d1205 ZW |
18333 | /* If value is negative, choose the opposite instruction. */ |
18334 | if (value < 0) | |
18335 | { | |
18336 | value = -value; | |
18337 | subtract = !subtract; | |
18338 | if (value < 0) | |
18339 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18340 | _("immediate value out of range")); | |
18341 | } | |
a737bd4d | 18342 | |
c19d1205 ZW |
18343 | if (rd == REG_SP) |
18344 | { | |
18345 | if (value & ~0x1fc) | |
18346 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18347 | _("invalid immediate for stack address calculation")); | |
18348 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
18349 | newval |= value >> 2; | |
18350 | } | |
18351 | else if (rs == REG_PC || rs == REG_SP) | |
18352 | { | |
18353 | if (subtract || value & ~0x3fc) | |
18354 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18355 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
18356 | (unsigned long) value); | |
18357 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
18358 | newval |= rd << 8; | |
18359 | newval |= value >> 2; | |
18360 | } | |
18361 | else if (rs == rd) | |
18362 | { | |
18363 | if (value & ~0xff) | |
18364 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18365 | _("immediate value out of range")); | |
18366 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
18367 | newval |= (rd << 8) | value; | |
18368 | } | |
18369 | else | |
18370 | { | |
18371 | if (value & ~0x7) | |
18372 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18373 | _("immediate value out of range")); | |
18374 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
18375 | newval |= rd | (rs << 3) | (value << 6); | |
18376 | } | |
18377 | } | |
18378 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18379 | break; | |
a737bd4d | 18380 | |
c19d1205 ZW |
18381 | case BFD_RELOC_ARM_THUMB_IMM: |
18382 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
18383 | if (value < 0 || value > 255) | |
18384 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18385 | _("invalid immediate: %ld is too large"), | |
18386 | (long) value); | |
18387 | newval |= value; | |
18388 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18389 | break; | |
a737bd4d | 18390 | |
c19d1205 ZW |
18391 | case BFD_RELOC_ARM_THUMB_SHIFT: |
18392 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
18393 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
18394 | temp = newval & 0xf800; | |
18395 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
18396 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18397 | _("invalid shift value: %ld"), (long) value); | |
18398 | /* Shifts of zero must be encoded as LSL. */ | |
18399 | if (value == 0) | |
18400 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
18401 | /* Shifts of 32 are encoded as zero. */ | |
18402 | else if (value == 32) | |
18403 | value = 0; | |
18404 | newval |= value << 6; | |
18405 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
18406 | break; | |
a737bd4d | 18407 | |
c19d1205 ZW |
18408 | case BFD_RELOC_VTABLE_INHERIT: |
18409 | case BFD_RELOC_VTABLE_ENTRY: | |
18410 | fixP->fx_done = 0; | |
18411 | return; | |
6c43fab6 | 18412 | |
b6895b4f PB |
18413 | case BFD_RELOC_ARM_MOVW: |
18414 | case BFD_RELOC_ARM_MOVT: | |
18415 | case BFD_RELOC_ARM_THUMB_MOVW: | |
18416 | case BFD_RELOC_ARM_THUMB_MOVT: | |
18417 | if (fixP->fx_done || !seg->use_rela_p) | |
18418 | { | |
18419 | /* REL format relocations are limited to a 16-bit addend. */ | |
18420 | if (!fixP->fx_done) | |
18421 | { | |
18422 | if (value < -0x1000 || value > 0xffff) | |
18423 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18424 | _("offset too big")); | |
18425 | } | |
18426 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
18427 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
18428 | { | |
18429 | value >>= 16; | |
18430 | } | |
18431 | ||
18432 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
18433 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
18434 | { | |
18435 | newval = get_thumb32_insn (buf); | |
18436 | newval &= 0xfbf08f00; | |
18437 | newval |= (value & 0xf000) << 4; | |
18438 | newval |= (value & 0x0800) << 15; | |
18439 | newval |= (value & 0x0700) << 4; | |
18440 | newval |= (value & 0x00ff); | |
18441 | put_thumb32_insn (buf, newval); | |
18442 | } | |
18443 | else | |
18444 | { | |
18445 | newval = md_chars_to_number (buf, 4); | |
18446 | newval &= 0xfff0f000; | |
18447 | newval |= value & 0x0fff; | |
18448 | newval |= (value & 0xf000) << 4; | |
18449 | md_number_to_chars (buf, newval, 4); | |
18450 | } | |
18451 | } | |
18452 | return; | |
18453 | ||
4962c51a MS |
18454 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
18455 | case BFD_RELOC_ARM_ALU_PC_G0: | |
18456 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
18457 | case BFD_RELOC_ARM_ALU_PC_G1: | |
18458 | case BFD_RELOC_ARM_ALU_PC_G2: | |
18459 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
18460 | case BFD_RELOC_ARM_ALU_SB_G0: | |
18461 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
18462 | case BFD_RELOC_ARM_ALU_SB_G1: | |
18463 | case BFD_RELOC_ARM_ALU_SB_G2: | |
18464 | assert (!fixP->fx_done); | |
18465 | if (!seg->use_rela_p) | |
18466 | { | |
18467 | bfd_vma insn; | |
18468 | bfd_vma encoded_addend; | |
18469 | bfd_vma addend_abs = abs (value); | |
18470 | ||
18471 | /* Check that the absolute value of the addend can be | |
18472 | expressed as an 8-bit constant plus a rotation. */ | |
18473 | encoded_addend = encode_arm_immediate (addend_abs); | |
18474 | if (encoded_addend == (unsigned int) FAIL) | |
18475 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18476 | _("the offset 0x%08lX is not representable"), | |
18477 | addend_abs); | |
18478 | ||
18479 | /* Extract the instruction. */ | |
18480 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18481 | ||
18482 | /* If the addend is positive, use an ADD instruction. | |
18483 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
18484 | insn &= 0xff1fffff; | |
18485 | if (value < 0) | |
18486 | insn |= 1 << 22; | |
18487 | else | |
18488 | insn |= 1 << 23; | |
18489 | ||
18490 | /* Place the encoded addend into the first 12 bits of the | |
18491 | instruction. */ | |
18492 | insn &= 0xfffff000; | |
18493 | insn |= encoded_addend; | |
18494 | ||
18495 | /* Update the instruction. */ | |
18496 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18497 | } | |
18498 | break; | |
18499 | ||
18500 | case BFD_RELOC_ARM_LDR_PC_G0: | |
18501 | case BFD_RELOC_ARM_LDR_PC_G1: | |
18502 | case BFD_RELOC_ARM_LDR_PC_G2: | |
18503 | case BFD_RELOC_ARM_LDR_SB_G0: | |
18504 | case BFD_RELOC_ARM_LDR_SB_G1: | |
18505 | case BFD_RELOC_ARM_LDR_SB_G2: | |
18506 | assert (!fixP->fx_done); | |
18507 | if (!seg->use_rela_p) | |
18508 | { | |
18509 | bfd_vma insn; | |
18510 | bfd_vma addend_abs = abs (value); | |
18511 | ||
18512 | /* Check that the absolute value of the addend can be | |
18513 | encoded in 12 bits. */ | |
18514 | if (addend_abs >= 0x1000) | |
18515 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18516 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
18517 | addend_abs); | |
18518 | ||
18519 | /* Extract the instruction. */ | |
18520 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18521 | ||
18522 | /* If the addend is negative, clear bit 23 of the instruction. | |
18523 | Otherwise set it. */ | |
18524 | if (value < 0) | |
18525 | insn &= ~(1 << 23); | |
18526 | else | |
18527 | insn |= 1 << 23; | |
18528 | ||
18529 | /* Place the absolute value of the addend into the first 12 bits | |
18530 | of the instruction. */ | |
18531 | insn &= 0xfffff000; | |
18532 | insn |= addend_abs; | |
18533 | ||
18534 | /* Update the instruction. */ | |
18535 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18536 | } | |
18537 | break; | |
18538 | ||
18539 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
18540 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
18541 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
18542 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
18543 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
18544 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
18545 | assert (!fixP->fx_done); | |
18546 | if (!seg->use_rela_p) | |
18547 | { | |
18548 | bfd_vma insn; | |
18549 | bfd_vma addend_abs = abs (value); | |
18550 | ||
18551 | /* Check that the absolute value of the addend can be | |
18552 | encoded in 8 bits. */ | |
18553 | if (addend_abs >= 0x100) | |
18554 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18555 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
18556 | addend_abs); | |
18557 | ||
18558 | /* Extract the instruction. */ | |
18559 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18560 | ||
18561 | /* If the addend is negative, clear bit 23 of the instruction. | |
18562 | Otherwise set it. */ | |
18563 | if (value < 0) | |
18564 | insn &= ~(1 << 23); | |
18565 | else | |
18566 | insn |= 1 << 23; | |
18567 | ||
18568 | /* Place the first four bits of the absolute value of the addend | |
18569 | into the first 4 bits of the instruction, and the remaining | |
18570 | four into bits 8 .. 11. */ | |
18571 | insn &= 0xfffff0f0; | |
18572 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
18573 | ||
18574 | /* Update the instruction. */ | |
18575 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18576 | } | |
18577 | break; | |
18578 | ||
18579 | case BFD_RELOC_ARM_LDC_PC_G0: | |
18580 | case BFD_RELOC_ARM_LDC_PC_G1: | |
18581 | case BFD_RELOC_ARM_LDC_PC_G2: | |
18582 | case BFD_RELOC_ARM_LDC_SB_G0: | |
18583 | case BFD_RELOC_ARM_LDC_SB_G1: | |
18584 | case BFD_RELOC_ARM_LDC_SB_G2: | |
18585 | assert (!fixP->fx_done); | |
18586 | if (!seg->use_rela_p) | |
18587 | { | |
18588 | bfd_vma insn; | |
18589 | bfd_vma addend_abs = abs (value); | |
18590 | ||
18591 | /* Check that the absolute value of the addend is a multiple of | |
18592 | four and, when divided by four, fits in 8 bits. */ | |
18593 | if (addend_abs & 0x3) | |
18594 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18595 | _("bad offset 0x%08lX (must be word-aligned)"), | |
18596 | addend_abs); | |
18597 | ||
18598 | if ((addend_abs >> 2) > 0xff) | |
18599 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18600 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
18601 | addend_abs); | |
18602 | ||
18603 | /* Extract the instruction. */ | |
18604 | insn = md_chars_to_number (buf, INSN_SIZE); | |
18605 | ||
18606 | /* If the addend is negative, clear bit 23 of the instruction. | |
18607 | Otherwise set it. */ | |
18608 | if (value < 0) | |
18609 | insn &= ~(1 << 23); | |
18610 | else | |
18611 | insn |= 1 << 23; | |
18612 | ||
18613 | /* Place the addend (divided by four) into the first eight | |
18614 | bits of the instruction. */ | |
18615 | insn &= 0xfffffff0; | |
18616 | insn |= addend_abs >> 2; | |
18617 | ||
18618 | /* Update the instruction. */ | |
18619 | md_number_to_chars (buf, insn, INSN_SIZE); | |
18620 | } | |
18621 | break; | |
18622 | ||
c19d1205 ZW |
18623 | case BFD_RELOC_UNUSED: |
18624 | default: | |
18625 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
18626 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
18627 | } | |
6c43fab6 RE |
18628 | } |
18629 | ||
c19d1205 ZW |
18630 | /* Translate internal representation of relocation info to BFD target |
18631 | format. */ | |
a737bd4d | 18632 | |
c19d1205 | 18633 | arelent * |
00a97672 | 18634 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 18635 | { |
c19d1205 ZW |
18636 | arelent * reloc; |
18637 | bfd_reloc_code_real_type code; | |
a737bd4d | 18638 | |
c19d1205 | 18639 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 18640 | |
c19d1205 ZW |
18641 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
18642 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
18643 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 18644 | |
2fc8bdac | 18645 | if (fixp->fx_pcrel) |
00a97672 RS |
18646 | { |
18647 | if (section->use_rela_p) | |
18648 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
18649 | else | |
18650 | fixp->fx_offset = reloc->address; | |
18651 | } | |
c19d1205 | 18652 | reloc->addend = fixp->fx_offset; |
a737bd4d | 18653 | |
c19d1205 | 18654 | switch (fixp->fx_r_type) |
a737bd4d | 18655 | { |
c19d1205 ZW |
18656 | case BFD_RELOC_8: |
18657 | if (fixp->fx_pcrel) | |
18658 | { | |
18659 | code = BFD_RELOC_8_PCREL; | |
18660 | break; | |
18661 | } | |
a737bd4d | 18662 | |
c19d1205 ZW |
18663 | case BFD_RELOC_16: |
18664 | if (fixp->fx_pcrel) | |
18665 | { | |
18666 | code = BFD_RELOC_16_PCREL; | |
18667 | break; | |
18668 | } | |
6c43fab6 | 18669 | |
c19d1205 ZW |
18670 | case BFD_RELOC_32: |
18671 | if (fixp->fx_pcrel) | |
18672 | { | |
18673 | code = BFD_RELOC_32_PCREL; | |
18674 | break; | |
18675 | } | |
a737bd4d | 18676 | |
b6895b4f PB |
18677 | case BFD_RELOC_ARM_MOVW: |
18678 | if (fixp->fx_pcrel) | |
18679 | { | |
18680 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
18681 | break; | |
18682 | } | |
18683 | ||
18684 | case BFD_RELOC_ARM_MOVT: | |
18685 | if (fixp->fx_pcrel) | |
18686 | { | |
18687 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
18688 | break; | |
18689 | } | |
18690 | ||
18691 | case BFD_RELOC_ARM_THUMB_MOVW: | |
18692 | if (fixp->fx_pcrel) | |
18693 | { | |
18694 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
18695 | break; | |
18696 | } | |
18697 | ||
18698 | case BFD_RELOC_ARM_THUMB_MOVT: | |
18699 | if (fixp->fx_pcrel) | |
18700 | { | |
18701 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
18702 | break; | |
18703 | } | |
18704 | ||
c19d1205 ZW |
18705 | case BFD_RELOC_NONE: |
18706 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
18707 | case BFD_RELOC_ARM_PCREL_BLX: | |
18708 | case BFD_RELOC_RVA: | |
18709 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
18710 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
18711 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
18712 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
18713 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
18714 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
18715 | case BFD_RELOC_THUMB_PCREL_BLX: | |
18716 | case BFD_RELOC_VTABLE_ENTRY: | |
18717 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
18718 | #ifdef TE_PE |
18719 | case BFD_RELOC_32_SECREL: | |
18720 | #endif | |
c19d1205 ZW |
18721 | code = fixp->fx_r_type; |
18722 | break; | |
a737bd4d | 18723 | |
c19d1205 ZW |
18724 | case BFD_RELOC_ARM_LITERAL: |
18725 | case BFD_RELOC_ARM_HWLITERAL: | |
18726 | /* If this is called then the a literal has | |
18727 | been referenced across a section boundary. */ | |
18728 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18729 | _("literal referenced across section boundary")); | |
18730 | return NULL; | |
a737bd4d | 18731 | |
c19d1205 ZW |
18732 | #ifdef OBJ_ELF |
18733 | case BFD_RELOC_ARM_GOT32: | |
18734 | case BFD_RELOC_ARM_GOTOFF: | |
18735 | case BFD_RELOC_ARM_PLT32: | |
18736 | case BFD_RELOC_ARM_TARGET1: | |
18737 | case BFD_RELOC_ARM_ROSEGREL32: | |
18738 | case BFD_RELOC_ARM_SBREL32: | |
18739 | case BFD_RELOC_ARM_PREL31: | |
18740 | case BFD_RELOC_ARM_TARGET2: | |
18741 | case BFD_RELOC_ARM_TLS_LE32: | |
18742 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
18743 | case BFD_RELOC_ARM_PCREL_CALL: |
18744 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
18745 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
18746 | case BFD_RELOC_ARM_ALU_PC_G0: | |
18747 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
18748 | case BFD_RELOC_ARM_ALU_PC_G1: | |
18749 | case BFD_RELOC_ARM_ALU_PC_G2: | |
18750 | case BFD_RELOC_ARM_LDR_PC_G0: | |
18751 | case BFD_RELOC_ARM_LDR_PC_G1: | |
18752 | case BFD_RELOC_ARM_LDR_PC_G2: | |
18753 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
18754 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
18755 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
18756 | case BFD_RELOC_ARM_LDC_PC_G0: | |
18757 | case BFD_RELOC_ARM_LDC_PC_G1: | |
18758 | case BFD_RELOC_ARM_LDC_PC_G2: | |
18759 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
18760 | case BFD_RELOC_ARM_ALU_SB_G0: | |
18761 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
18762 | case BFD_RELOC_ARM_ALU_SB_G1: | |
18763 | case BFD_RELOC_ARM_ALU_SB_G2: | |
18764 | case BFD_RELOC_ARM_LDR_SB_G0: | |
18765 | case BFD_RELOC_ARM_LDR_SB_G1: | |
18766 | case BFD_RELOC_ARM_LDR_SB_G2: | |
18767 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
18768 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
18769 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
18770 | case BFD_RELOC_ARM_LDC_SB_G0: | |
18771 | case BFD_RELOC_ARM_LDC_SB_G1: | |
18772 | case BFD_RELOC_ARM_LDC_SB_G2: | |
c19d1205 ZW |
18773 | code = fixp->fx_r_type; |
18774 | break; | |
a737bd4d | 18775 | |
c19d1205 ZW |
18776 | case BFD_RELOC_ARM_TLS_GD32: |
18777 | case BFD_RELOC_ARM_TLS_IE32: | |
18778 | case BFD_RELOC_ARM_TLS_LDM32: | |
18779 | /* BFD will include the symbol's address in the addend. | |
18780 | But we don't want that, so subtract it out again here. */ | |
18781 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
18782 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
18783 | code = fixp->fx_r_type; | |
18784 | break; | |
18785 | #endif | |
a737bd4d | 18786 | |
c19d1205 ZW |
18787 | case BFD_RELOC_ARM_IMMEDIATE: |
18788 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18789 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
18790 | return NULL; | |
a737bd4d | 18791 | |
c19d1205 ZW |
18792 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
18793 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18794 | _("ADRL used for a symbol not defined in the same file")); | |
18795 | return NULL; | |
a737bd4d | 18796 | |
c19d1205 | 18797 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
18798 | if (section->use_rela_p) |
18799 | { | |
18800 | code = fixp->fx_r_type; | |
18801 | break; | |
18802 | } | |
18803 | ||
c19d1205 ZW |
18804 | if (fixp->fx_addsy != NULL |
18805 | && !S_IS_DEFINED (fixp->fx_addsy) | |
18806 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 18807 | { |
c19d1205 ZW |
18808 | as_bad_where (fixp->fx_file, fixp->fx_line, |
18809 | _("undefined local label `%s'"), | |
18810 | S_GET_NAME (fixp->fx_addsy)); | |
18811 | return NULL; | |
a737bd4d NC |
18812 | } |
18813 | ||
c19d1205 ZW |
18814 | as_bad_where (fixp->fx_file, fixp->fx_line, |
18815 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
18816 | return NULL; | |
a737bd4d | 18817 | |
c19d1205 ZW |
18818 | default: |
18819 | { | |
18820 | char * type; | |
6c43fab6 | 18821 | |
c19d1205 ZW |
18822 | switch (fixp->fx_r_type) |
18823 | { | |
18824 | case BFD_RELOC_NONE: type = "NONE"; break; | |
18825 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
18826 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 18827 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
18828 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
18829 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
18830 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 18831 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
18832 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
18833 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
18834 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
18835 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
18836 | default: type = _("<unknown>"); break; | |
18837 | } | |
18838 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18839 | _("cannot represent %s relocation in this object file format"), | |
18840 | type); | |
18841 | return NULL; | |
18842 | } | |
a737bd4d | 18843 | } |
6c43fab6 | 18844 | |
c19d1205 ZW |
18845 | #ifdef OBJ_ELF |
18846 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
18847 | && GOT_symbol | |
18848 | && fixp->fx_addsy == GOT_symbol) | |
18849 | { | |
18850 | code = BFD_RELOC_ARM_GOTPC; | |
18851 | reloc->addend = fixp->fx_offset = reloc->address; | |
18852 | } | |
18853 | #endif | |
6c43fab6 | 18854 | |
c19d1205 | 18855 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 18856 | |
c19d1205 ZW |
18857 | if (reloc->howto == NULL) |
18858 | { | |
18859 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
18860 | _("cannot represent %s relocation in this object file format"), | |
18861 | bfd_get_reloc_code_name (code)); | |
18862 | return NULL; | |
18863 | } | |
6c43fab6 | 18864 | |
c19d1205 ZW |
18865 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
18866 | vtable entry to be used in the relocation's section offset. */ | |
18867 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
18868 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 18869 | |
c19d1205 | 18870 | return reloc; |
6c43fab6 RE |
18871 | } |
18872 | ||
c19d1205 | 18873 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 18874 | |
c19d1205 ZW |
18875 | void |
18876 | cons_fix_new_arm (fragS * frag, | |
18877 | int where, | |
18878 | int size, | |
18879 | expressionS * exp) | |
6c43fab6 | 18880 | { |
c19d1205 ZW |
18881 | bfd_reloc_code_real_type type; |
18882 | int pcrel = 0; | |
6c43fab6 | 18883 | |
c19d1205 ZW |
18884 | /* Pick a reloc. |
18885 | FIXME: @@ Should look at CPU word size. */ | |
18886 | switch (size) | |
18887 | { | |
18888 | case 1: | |
18889 | type = BFD_RELOC_8; | |
18890 | break; | |
18891 | case 2: | |
18892 | type = BFD_RELOC_16; | |
18893 | break; | |
18894 | case 4: | |
18895 | default: | |
18896 | type = BFD_RELOC_32; | |
18897 | break; | |
18898 | case 8: | |
18899 | type = BFD_RELOC_64; | |
18900 | break; | |
18901 | } | |
6c43fab6 | 18902 | |
f0927246 NC |
18903 | #ifdef TE_PE |
18904 | if (exp->X_op == O_secrel) | |
18905 | { | |
18906 | exp->X_op = O_symbol; | |
18907 | type = BFD_RELOC_32_SECREL; | |
18908 | } | |
18909 | #endif | |
18910 | ||
c19d1205 ZW |
18911 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
18912 | } | |
6c43fab6 | 18913 | |
c19d1205 ZW |
18914 | #if defined OBJ_COFF || defined OBJ_ELF |
18915 | void | |
18916 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 18917 | { |
c19d1205 ZW |
18918 | /* If the destination of the branch is a defined symbol which does not have |
18919 | the THUMB_FUNC attribute, then we must be calling a function which has | |
18920 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
18921 | function and change the branch to refer to that function instead. */ | |
18922 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
18923 | && fixP->fx_addsy != NULL | |
18924 | && S_IS_DEFINED (fixP->fx_addsy) | |
18925 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 18926 | { |
c19d1205 | 18927 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 18928 | } |
c19d1205 ZW |
18929 | } |
18930 | #endif | |
6c43fab6 | 18931 | |
c19d1205 ZW |
18932 | int |
18933 | arm_force_relocation (struct fix * fixp) | |
18934 | { | |
18935 | #if defined (OBJ_COFF) && defined (TE_PE) | |
18936 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
18937 | return 1; | |
18938 | #endif | |
6c43fab6 | 18939 | |
c19d1205 ZW |
18940 | /* Resolve these relocations even if the symbol is extern or weak. */ |
18941 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
18942 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 | 18943 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
16805f35 | 18944 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
18945 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
18946 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
18947 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 18948 | return 0; |
a737bd4d | 18949 | |
4962c51a MS |
18950 | /* Always leave these relocations for the linker. */ |
18951 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
18952 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
18953 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
18954 | return 1; | |
18955 | ||
c19d1205 | 18956 | return generic_force_reloc (fixp); |
404ff6b5 AH |
18957 | } |
18958 | ||
c19d1205 | 18959 | #ifdef OBJ_COFF |
c19d1205 ZW |
18960 | bfd_boolean |
18961 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 18962 | { |
337ff0a5 NC |
18963 | /* This is a little hack to help the gas/arm/adrl.s test. It prevents |
18964 | local labels from being added to the output symbol table when they | |
18965 | are used with the ADRL pseudo op. The ADRL relocation should always | |
18966 | be resolved before the binbary is emitted, so it is safe to say that | |
18967 | it is adjustable. */ | |
c19d1205 ZW |
18968 | if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE) |
18969 | return 1; | |
337ff0a5 NC |
18970 | |
18971 | /* This is a hack for the gas/all/redef2.s test. This test causes symbols | |
18972 | to be cloned, and without this test relocs would still be generated | |
6e0080dd | 18973 | against the original, pre-cloned symbol. Such symbols would not appear |
337ff0a5 NC |
18974 | in the symbol table however, and so a valid reloc could not be |
18975 | generated. So check to see if the fixup is against a symbol which has | |
18976 | been removed from the symbol chain, and if it is, then allow it to be | |
18977 | adjusted into a reloc against a section symbol. */ | |
6e0080dd NC |
18978 | if (fixP->fx_addsy != NULL |
18979 | && ! S_IS_LOCAL (fixP->fx_addsy) | |
18980 | && symbol_next (fixP->fx_addsy) == NULL | |
18981 | && symbol_next (fixP->fx_addsy) == symbol_previous (fixP->fx_addsy)) | |
18982 | return 1; | |
337ff0a5 | 18983 | |
c19d1205 | 18984 | return 0; |
404ff6b5 | 18985 | } |
c19d1205 | 18986 | #endif |
404ff6b5 | 18987 | |
c19d1205 | 18988 | #ifdef OBJ_ELF |
e28387c3 PB |
18989 | /* Relocations against function names must be left unadjusted, |
18990 | so that the linker can use this information to generate interworking | |
18991 | stubs. The MIPS version of this function | |
c19d1205 ZW |
18992 | also prevents relocations that are mips-16 specific, but I do not |
18993 | know why it does this. | |
404ff6b5 | 18994 | |
c19d1205 ZW |
18995 | FIXME: |
18996 | There is one other problem that ought to be addressed here, but | |
18997 | which currently is not: Taking the address of a label (rather | |
18998 | than a function) and then later jumping to that address. Such | |
18999 | addresses also ought to have their bottom bit set (assuming that | |
19000 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 19001 | |
c19d1205 ZW |
19002 | bfd_boolean |
19003 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 19004 | { |
c19d1205 ZW |
19005 | if (fixP->fx_addsy == NULL) |
19006 | return 1; | |
404ff6b5 | 19007 | |
e28387c3 PB |
19008 | /* Preserve relocations against symbols with function type. */ |
19009 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
19010 | return 0; | |
19011 | ||
c19d1205 ZW |
19012 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
19013 | && fixP->fx_subsy == NULL) | |
19014 | return 0; | |
a737bd4d | 19015 | |
c19d1205 ZW |
19016 | /* We need the symbol name for the VTABLE entries. */ |
19017 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
19018 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
19019 | return 0; | |
404ff6b5 | 19020 | |
c19d1205 ZW |
19021 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
19022 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
19023 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
19024 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
19025 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
19026 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
19027 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
19028 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
19029 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
19030 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
19031 | return 0; | |
a737bd4d | 19032 | |
4962c51a MS |
19033 | /* Similarly for group relocations. */ |
19034 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
19035 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
19036 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
19037 | return 0; | |
19038 | ||
c19d1205 | 19039 | return 1; |
a737bd4d | 19040 | } |
404ff6b5 | 19041 | |
c19d1205 ZW |
19042 | const char * |
19043 | elf32_arm_target_format (void) | |
404ff6b5 | 19044 | { |
c19d1205 ZW |
19045 | #ifdef TE_SYMBIAN |
19046 | return (target_big_endian | |
19047 | ? "elf32-bigarm-symbian" | |
19048 | : "elf32-littlearm-symbian"); | |
19049 | #elif defined (TE_VXWORKS) | |
19050 | return (target_big_endian | |
19051 | ? "elf32-bigarm-vxworks" | |
19052 | : "elf32-littlearm-vxworks"); | |
19053 | #else | |
19054 | if (target_big_endian) | |
19055 | return "elf32-bigarm"; | |
19056 | else | |
19057 | return "elf32-littlearm"; | |
19058 | #endif | |
404ff6b5 AH |
19059 | } |
19060 | ||
c19d1205 ZW |
19061 | void |
19062 | armelf_frob_symbol (symbolS * symp, | |
19063 | int * puntp) | |
404ff6b5 | 19064 | { |
c19d1205 ZW |
19065 | elf_frob_symbol (symp, puntp); |
19066 | } | |
19067 | #endif | |
404ff6b5 | 19068 | |
c19d1205 | 19069 | /* MD interface: Finalization. */ |
a737bd4d | 19070 | |
c19d1205 ZW |
19071 | /* A good place to do this, although this was probably not intended |
19072 | for this kind of use. We need to dump the literal pool before | |
19073 | references are made to a null symbol pointer. */ | |
a737bd4d | 19074 | |
c19d1205 ZW |
19075 | void |
19076 | arm_cleanup (void) | |
19077 | { | |
19078 | literal_pool * pool; | |
a737bd4d | 19079 | |
c19d1205 ZW |
19080 | for (pool = list_of_pools; pool; pool = pool->next) |
19081 | { | |
19082 | /* Put it at the end of the relevent section. */ | |
19083 | subseg_set (pool->section, pool->sub_section); | |
19084 | #ifdef OBJ_ELF | |
19085 | arm_elf_change_section (); | |
19086 | #endif | |
19087 | s_ltorg (0); | |
19088 | } | |
404ff6b5 AH |
19089 | } |
19090 | ||
c19d1205 ZW |
19091 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
19092 | ARM ones. */ | |
404ff6b5 | 19093 | |
c19d1205 ZW |
19094 | void |
19095 | arm_adjust_symtab (void) | |
404ff6b5 | 19096 | { |
c19d1205 ZW |
19097 | #ifdef OBJ_COFF |
19098 | symbolS * sym; | |
404ff6b5 | 19099 | |
c19d1205 ZW |
19100 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
19101 | { | |
19102 | if (ARM_IS_THUMB (sym)) | |
19103 | { | |
19104 | if (THUMB_IS_FUNC (sym)) | |
19105 | { | |
19106 | /* Mark the symbol as a Thumb function. */ | |
19107 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
19108 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
19109 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 19110 | |
c19d1205 ZW |
19111 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
19112 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
19113 | else | |
19114 | as_bad (_("%s: unexpected function type: %d"), | |
19115 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
19116 | } | |
19117 | else switch (S_GET_STORAGE_CLASS (sym)) | |
19118 | { | |
19119 | case C_EXT: | |
19120 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
19121 | break; | |
19122 | case C_STAT: | |
19123 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
19124 | break; | |
19125 | case C_LABEL: | |
19126 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
19127 | break; | |
19128 | default: | |
19129 | /* Do nothing. */ | |
19130 | break; | |
19131 | } | |
19132 | } | |
a737bd4d | 19133 | |
c19d1205 ZW |
19134 | if (ARM_IS_INTERWORK (sym)) |
19135 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 19136 | } |
c19d1205 ZW |
19137 | #endif |
19138 | #ifdef OBJ_ELF | |
19139 | symbolS * sym; | |
19140 | char bind; | |
404ff6b5 | 19141 | |
c19d1205 | 19142 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 19143 | { |
c19d1205 ZW |
19144 | if (ARM_IS_THUMB (sym)) |
19145 | { | |
19146 | elf_symbol_type * elf_sym; | |
404ff6b5 | 19147 | |
c19d1205 ZW |
19148 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
19149 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 19150 | |
b0796911 PB |
19151 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
19152 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
19153 | { |
19154 | /* If it's a .thumb_func, declare it as so, | |
19155 | otherwise tag label as .code 16. */ | |
19156 | if (THUMB_IS_FUNC (sym)) | |
19157 | elf_sym->internal_elf_sym.st_info = | |
19158 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
19159 | else | |
19160 | elf_sym->internal_elf_sym.st_info = | |
19161 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
19162 | } | |
19163 | } | |
19164 | } | |
19165 | #endif | |
404ff6b5 AH |
19166 | } |
19167 | ||
c19d1205 | 19168 | /* MD interface: Initialization. */ |
404ff6b5 | 19169 | |
a737bd4d | 19170 | static void |
c19d1205 | 19171 | set_constant_flonums (void) |
a737bd4d | 19172 | { |
c19d1205 | 19173 | int i; |
404ff6b5 | 19174 | |
c19d1205 ZW |
19175 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
19176 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
19177 | abort (); | |
a737bd4d | 19178 | } |
404ff6b5 | 19179 | |
3e9e4fcf JB |
19180 | /* Auto-select Thumb mode if it's the only available instruction set for the |
19181 | given architecture. */ | |
19182 | ||
19183 | static void | |
19184 | autoselect_thumb_from_cpu_variant (void) | |
19185 | { | |
19186 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
19187 | opcode_select (16); | |
19188 | } | |
19189 | ||
c19d1205 ZW |
19190 | void |
19191 | md_begin (void) | |
a737bd4d | 19192 | { |
c19d1205 ZW |
19193 | unsigned mach; |
19194 | unsigned int i; | |
404ff6b5 | 19195 | |
c19d1205 ZW |
19196 | if ( (arm_ops_hsh = hash_new ()) == NULL |
19197 | || (arm_cond_hsh = hash_new ()) == NULL | |
19198 | || (arm_shift_hsh = hash_new ()) == NULL | |
19199 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 19200 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 19201 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
19202 | || (arm_reloc_hsh = hash_new ()) == NULL |
19203 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
19204 | as_fatal (_("virtual memory exhausted")); |
19205 | ||
19206 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
19207 | hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i)); | |
19208 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) | |
19209 | hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i)); | |
19210 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) | |
19211 | hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i)); | |
19212 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) | |
19213 | hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i)); | |
62b3e311 PB |
19214 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
19215 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i)); | |
c19d1205 ZW |
19216 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
19217 | hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i)); | |
62b3e311 PB |
19218 | for (i = 0; |
19219 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
19220 | i++) | |
19221 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template, | |
19222 | (PTR) (barrier_opt_names + i)); | |
c19d1205 ZW |
19223 | #ifdef OBJ_ELF |
19224 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
19225 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i)); | |
19226 | #endif | |
19227 | ||
19228 | set_constant_flonums (); | |
404ff6b5 | 19229 | |
c19d1205 ZW |
19230 | /* Set the cpu variant based on the command-line options. We prefer |
19231 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
19232 | -mfpu= over any other way of setting the floating point unit. | |
19233 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 19234 | if (legacy_cpu) |
404ff6b5 | 19235 | { |
e74cfd16 | 19236 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
19237 | as_bad (_("use of old and new-style options to set CPU type")); |
19238 | ||
19239 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 19240 | } |
e74cfd16 | 19241 | else if (!mcpu_cpu_opt) |
c19d1205 | 19242 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 19243 | |
e74cfd16 | 19244 | if (legacy_fpu) |
c19d1205 | 19245 | { |
e74cfd16 | 19246 | if (mfpu_opt) |
c19d1205 | 19247 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
19248 | |
19249 | mfpu_opt = legacy_fpu; | |
19250 | } | |
e74cfd16 | 19251 | else if (!mfpu_opt) |
03b1477f | 19252 | { |
c19d1205 | 19253 | #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS)) |
39c2da32 RE |
19254 | /* Some environments specify a default FPU. If they don't, infer it |
19255 | from the processor. */ | |
e74cfd16 | 19256 | if (mcpu_fpu_opt) |
03b1477f RE |
19257 | mfpu_opt = mcpu_fpu_opt; |
19258 | else | |
19259 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 19260 | #else |
e74cfd16 | 19261 | mfpu_opt = &fpu_default; |
39c2da32 | 19262 | #endif |
03b1477f RE |
19263 | } |
19264 | ||
e74cfd16 | 19265 | if (!mfpu_opt) |
03b1477f | 19266 | { |
e74cfd16 PB |
19267 | if (!mcpu_cpu_opt) |
19268 | mfpu_opt = &fpu_default; | |
19269 | else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) | |
19270 | mfpu_opt = &fpu_arch_vfp_v2; | |
03b1477f | 19271 | else |
e74cfd16 | 19272 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
19273 | } |
19274 | ||
ee065d83 | 19275 | #ifdef CPU_DEFAULT |
e74cfd16 | 19276 | if (!mcpu_cpu_opt) |
ee065d83 | 19277 | { |
e74cfd16 PB |
19278 | mcpu_cpu_opt = &cpu_default; |
19279 | selected_cpu = cpu_default; | |
ee065d83 | 19280 | } |
e74cfd16 PB |
19281 | #else |
19282 | if (mcpu_cpu_opt) | |
19283 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 19284 | else |
e74cfd16 | 19285 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 19286 | #endif |
03b1477f | 19287 | |
e74cfd16 | 19288 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 19289 | |
3e9e4fcf JB |
19290 | autoselect_thumb_from_cpu_variant (); |
19291 | ||
e74cfd16 | 19292 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 19293 | |
f17c130b | 19294 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 19295 | { |
7cc69913 NC |
19296 | unsigned int flags = 0; |
19297 | ||
19298 | #if defined OBJ_ELF | |
19299 | flags = meabi_flags; | |
d507cf36 PB |
19300 | |
19301 | switch (meabi_flags) | |
33a392fb | 19302 | { |
d507cf36 | 19303 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 19304 | #endif |
d507cf36 PB |
19305 | /* Set the flags in the private structure. */ |
19306 | if (uses_apcs_26) flags |= F_APCS26; | |
19307 | if (support_interwork) flags |= F_INTERWORK; | |
19308 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 19309 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 19310 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
19311 | flags |= F_SOFT_FLOAT; |
19312 | ||
d507cf36 PB |
19313 | switch (mfloat_abi_opt) |
19314 | { | |
19315 | case ARM_FLOAT_ABI_SOFT: | |
19316 | case ARM_FLOAT_ABI_SOFTFP: | |
19317 | flags |= F_SOFT_FLOAT; | |
19318 | break; | |
33a392fb | 19319 | |
d507cf36 PB |
19320 | case ARM_FLOAT_ABI_HARD: |
19321 | if (flags & F_SOFT_FLOAT) | |
19322 | as_bad (_("hard-float conflicts with specified fpu")); | |
19323 | break; | |
19324 | } | |
03b1477f | 19325 | |
e74cfd16 PB |
19326 | /* Using pure-endian doubles (even if soft-float). */ |
19327 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 19328 | flags |= F_VFP_FLOAT; |
f17c130b | 19329 | |
fde78edd | 19330 | #if defined OBJ_ELF |
e74cfd16 | 19331 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 19332 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
19333 | break; |
19334 | ||
8cb51566 | 19335 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 19336 | case EF_ARM_EABI_VER5: |
c19d1205 | 19337 | /* No additional flags to set. */ |
d507cf36 PB |
19338 | break; |
19339 | ||
19340 | default: | |
19341 | abort (); | |
19342 | } | |
7cc69913 | 19343 | #endif |
b99bd4ef NC |
19344 | bfd_set_private_flags (stdoutput, flags); |
19345 | ||
19346 | /* We have run out flags in the COFF header to encode the | |
19347 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 19348 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
19349 | if (atpcs) |
19350 | { | |
19351 | asection * sec; | |
19352 | ||
19353 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
19354 | ||
19355 | if (sec != NULL) | |
19356 | { | |
19357 | bfd_set_section_flags | |
19358 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
19359 | bfd_set_section_size (stdoutput, sec, 0); | |
19360 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
19361 | } | |
19362 | } | |
7cc69913 | 19363 | } |
f17c130b | 19364 | #endif |
b99bd4ef NC |
19365 | |
19366 | /* Record the CPU type as well. */ | |
2d447fca JM |
19367 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
19368 | mach = bfd_mach_arm_iWMMXt2; | |
19369 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 19370 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 19371 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 19372 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 19373 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 19374 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 19375 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 19376 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 19377 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 19378 | { |
e74cfd16 | 19379 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
19380 | mach = bfd_mach_arm_5T; |
19381 | else | |
19382 | mach = bfd_mach_arm_5; | |
19383 | } | |
e74cfd16 | 19384 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 19385 | { |
e74cfd16 | 19386 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
19387 | mach = bfd_mach_arm_4T; |
19388 | else | |
19389 | mach = bfd_mach_arm_4; | |
19390 | } | |
e74cfd16 | 19391 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 19392 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
19393 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
19394 | mach = bfd_mach_arm_3; | |
19395 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
19396 | mach = bfd_mach_arm_2a; | |
19397 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
19398 | mach = bfd_mach_arm_2; | |
19399 | else | |
19400 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
19401 | |
19402 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
19403 | } | |
19404 | ||
c19d1205 | 19405 | /* Command line processing. */ |
b99bd4ef | 19406 | |
c19d1205 ZW |
19407 | /* md_parse_option |
19408 | Invocation line includes a switch not recognized by the base assembler. | |
19409 | See if it's a processor-specific option. | |
b99bd4ef | 19410 | |
c19d1205 ZW |
19411 | This routine is somewhat complicated by the need for backwards |
19412 | compatibility (since older releases of gcc can't be changed). | |
19413 | The new options try to make the interface as compatible as | |
19414 | possible with GCC. | |
b99bd4ef | 19415 | |
c19d1205 | 19416 | New options (supported) are: |
b99bd4ef | 19417 | |
c19d1205 ZW |
19418 | -mcpu=<cpu name> Assemble for selected processor |
19419 | -march=<architecture name> Assemble for selected architecture | |
19420 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
19421 | -EB/-mbig-endian Big-endian | |
19422 | -EL/-mlittle-endian Little-endian | |
19423 | -k Generate PIC code | |
19424 | -mthumb Start in Thumb mode | |
19425 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 19426 | |
c19d1205 | 19427 | For now we will also provide support for: |
b99bd4ef | 19428 | |
c19d1205 ZW |
19429 | -mapcs-32 32-bit Program counter |
19430 | -mapcs-26 26-bit Program counter | |
19431 | -macps-float Floats passed in FP registers | |
19432 | -mapcs-reentrant Reentrant code | |
19433 | -matpcs | |
19434 | (sometime these will probably be replaced with -mapcs=<list of options> | |
19435 | and -matpcs=<list of options>) | |
b99bd4ef | 19436 | |
c19d1205 ZW |
19437 | The remaining options are only supported for back-wards compatibility. |
19438 | Cpu variants, the arm part is optional: | |
19439 | -m[arm]1 Currently not supported. | |
19440 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
19441 | -m[arm]3 Arm 3 processor | |
19442 | -m[arm]6[xx], Arm 6 processors | |
19443 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
19444 | -m[arm]8[10] Arm 8 processors | |
19445 | -m[arm]9[20][tdmi] Arm 9 processors | |
19446 | -mstrongarm[110[0]] StrongARM processors | |
19447 | -mxscale XScale processors | |
19448 | -m[arm]v[2345[t[e]]] Arm architectures | |
19449 | -mall All (except the ARM1) | |
19450 | FP variants: | |
19451 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
19452 | -mfpe-old (No float load/store multiples) | |
19453 | -mvfpxd VFP Single precision | |
19454 | -mvfp All VFP | |
19455 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 19456 | |
c19d1205 ZW |
19457 | The following CPU names are recognized: |
19458 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
19459 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
19460 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
19461 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
19462 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
19463 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
19464 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 19465 | |
c19d1205 | 19466 | */ |
b99bd4ef | 19467 | |
c19d1205 | 19468 | const char * md_shortopts = "m:k"; |
b99bd4ef | 19469 | |
c19d1205 ZW |
19470 | #ifdef ARM_BI_ENDIAN |
19471 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
19472 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 19473 | #else |
c19d1205 ZW |
19474 | #if TARGET_BYTES_BIG_ENDIAN |
19475 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 19476 | #else |
c19d1205 ZW |
19477 | #define OPTION_EL (OPTION_MD_BASE + 1) |
19478 | #endif | |
b99bd4ef | 19479 | #endif |
b99bd4ef | 19480 | |
c19d1205 | 19481 | struct option md_longopts[] = |
b99bd4ef | 19482 | { |
c19d1205 ZW |
19483 | #ifdef OPTION_EB |
19484 | {"EB", no_argument, NULL, OPTION_EB}, | |
19485 | #endif | |
19486 | #ifdef OPTION_EL | |
19487 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 19488 | #endif |
c19d1205 ZW |
19489 | {NULL, no_argument, NULL, 0} |
19490 | }; | |
b99bd4ef | 19491 | |
c19d1205 | 19492 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 19493 | |
c19d1205 | 19494 | struct arm_option_table |
b99bd4ef | 19495 | { |
c19d1205 ZW |
19496 | char *option; /* Option name to match. */ |
19497 | char *help; /* Help information. */ | |
19498 | int *var; /* Variable to change. */ | |
19499 | int value; /* What to change it to. */ | |
19500 | char *deprecated; /* If non-null, print this message. */ | |
19501 | }; | |
b99bd4ef | 19502 | |
c19d1205 ZW |
19503 | struct arm_option_table arm_opts[] = |
19504 | { | |
19505 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
19506 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
19507 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
19508 | &support_interwork, 1, NULL}, | |
19509 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
19510 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
19511 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
19512 | 1, NULL}, | |
19513 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
19514 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
19515 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
19516 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
19517 | NULL}, | |
b99bd4ef | 19518 | |
c19d1205 ZW |
19519 | /* These are recognized by the assembler, but have no affect on code. */ |
19520 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
19521 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
e74cfd16 PB |
19522 | {NULL, NULL, NULL, 0, NULL} |
19523 | }; | |
19524 | ||
19525 | struct arm_legacy_option_table | |
19526 | { | |
19527 | char *option; /* Option name to match. */ | |
19528 | const arm_feature_set **var; /* Variable to change. */ | |
19529 | const arm_feature_set value; /* What to change it to. */ | |
19530 | char *deprecated; /* If non-null, print this message. */ | |
19531 | }; | |
b99bd4ef | 19532 | |
e74cfd16 PB |
19533 | const struct arm_legacy_option_table arm_legacy_opts[] = |
19534 | { | |
c19d1205 ZW |
19535 | /* DON'T add any new processors to this list -- we want the whole list |
19536 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
19537 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
19538 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
19539 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
19540 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
19541 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
19542 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
19543 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
19544 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
19545 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
19546 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
19547 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
19548 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
19549 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
19550 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
19551 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
19552 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
19553 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
19554 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
19555 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
19556 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
19557 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
19558 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
19559 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
19560 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
19561 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
19562 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
19563 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
19564 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
19565 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
19566 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
19567 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
19568 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
19569 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
19570 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
19571 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
19572 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
19573 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
19574 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
19575 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
19576 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
19577 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
19578 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
19579 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
19580 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
19581 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
19582 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
19583 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19584 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19585 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19586 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
19587 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
19588 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
19589 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
19590 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
19591 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
19592 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
19593 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
19594 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
19595 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
19596 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
19597 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
19598 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
19599 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
19600 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
19601 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
19602 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
19603 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
19604 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
19605 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
19606 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 19607 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 19608 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 19609 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 19610 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 19611 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
19612 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
19613 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
19614 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 19615 | |
c19d1205 | 19616 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
19617 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
19618 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
19619 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
19620 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
19621 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
19622 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
19623 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
19624 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
19625 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
19626 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
19627 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
19628 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
19629 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
19630 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
19631 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
19632 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
19633 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
19634 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 19635 | |
c19d1205 | 19636 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
19637 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
19638 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
19639 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
19640 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 19641 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 19642 | |
e74cfd16 | 19643 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 19644 | }; |
7ed4c4c5 | 19645 | |
c19d1205 | 19646 | struct arm_cpu_option_table |
7ed4c4c5 | 19647 | { |
c19d1205 | 19648 | char *name; |
e74cfd16 | 19649 | const arm_feature_set value; |
c19d1205 ZW |
19650 | /* For some CPUs we assume an FPU unless the user explicitly sets |
19651 | -mfpu=... */ | |
e74cfd16 | 19652 | const arm_feature_set default_fpu; |
ee065d83 PB |
19653 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
19654 | case. */ | |
19655 | const char *canonical_name; | |
c19d1205 | 19656 | }; |
7ed4c4c5 | 19657 | |
c19d1205 ZW |
19658 | /* This list should, at a minimum, contain all the cpu names |
19659 | recognized by GCC. */ | |
e74cfd16 | 19660 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 19661 | { |
ee065d83 PB |
19662 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
19663 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
19664 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
19665 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
19666 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
19667 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19668 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19669 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19670 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19671 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19672 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19673 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
19674 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19675 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
19676 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19677 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
19678 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19679 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19680 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19681 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19682 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19683 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19684 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19685 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19686 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19687 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19688 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19689 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
19690 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19691 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19692 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19693 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19694 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19695 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19696 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19697 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19698 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19699 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
19700 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19701 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
19702 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19703 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19704 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
19705 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
19706 | /* For V5 or later processors we default to using VFP; but the user |
19707 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
19708 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
19709 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19710 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
19711 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
19712 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
19713 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
19714 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
19715 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19716 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
19717 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
19718 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19719 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19720 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
19721 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
19722 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19723 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
19724 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
19725 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19726 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
19727 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
19728 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
19729 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, | |
19730 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
19731 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
19732 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
19733 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
19734 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
19735 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
19736 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
19737 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
19738 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
5287ad62 JB |
19739 | {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3 |
19740 | | FPU_NEON_EXT_V1), | |
19741 | NULL}, | |
62b3e311 PB |
19742 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, |
19743 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, | |
c19d1205 | 19744 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 19745 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 19746 | /* ??? iwmmxt is not a processor. */ |
ee065d83 | 19747 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
2d447fca | 19748 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL}, |
ee065d83 | 19749 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 19750 | /* Maverick */ |
e74cfd16 PB |
19751 | {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
19752 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} | |
c19d1205 | 19753 | }; |
7ed4c4c5 | 19754 | |
c19d1205 | 19755 | struct arm_arch_option_table |
7ed4c4c5 | 19756 | { |
c19d1205 | 19757 | char *name; |
e74cfd16 PB |
19758 | const arm_feature_set value; |
19759 | const arm_feature_set default_fpu; | |
c19d1205 | 19760 | }; |
7ed4c4c5 | 19761 | |
c19d1205 ZW |
19762 | /* This list should, at a minimum, contain all the architecture names |
19763 | recognized by GCC. */ | |
e74cfd16 | 19764 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
19765 | { |
19766 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
19767 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
19768 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
19769 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
19770 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
19771 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
19772 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
19773 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
19774 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
19775 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
19776 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
19777 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
19778 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
19779 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
19780 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
19781 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
19782 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
19783 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
19784 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
19785 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
19786 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
19787 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
19788 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
19789 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
19790 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
19791 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
62b3e311 PB |
19792 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
19793 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, | |
19794 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
19795 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
19796 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
19797 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
2d447fca | 19798 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP}, |
e74cfd16 | 19799 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 19800 | }; |
7ed4c4c5 | 19801 | |
c19d1205 | 19802 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 19803 | struct arm_option_cpu_value_table |
c19d1205 ZW |
19804 | { |
19805 | char *name; | |
e74cfd16 | 19806 | const arm_feature_set value; |
c19d1205 | 19807 | }; |
7ed4c4c5 | 19808 | |
e74cfd16 | 19809 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 19810 | { |
e74cfd16 PB |
19811 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
19812 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
19813 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
2d447fca | 19814 | {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)}, |
e74cfd16 | 19815 | {NULL, ARM_ARCH_NONE} |
c19d1205 | 19816 | }; |
7ed4c4c5 | 19817 | |
c19d1205 ZW |
19818 | /* This list should, at a minimum, contain all the fpu names |
19819 | recognized by GCC. */ | |
e74cfd16 | 19820 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
19821 | { |
19822 | {"softfpa", FPU_NONE}, | |
19823 | {"fpe", FPU_ARCH_FPE}, | |
19824 | {"fpe2", FPU_ARCH_FPE}, | |
19825 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
19826 | {"fpa", FPU_ARCH_FPA}, | |
19827 | {"fpa10", FPU_ARCH_FPA}, | |
19828 | {"fpa11", FPU_ARCH_FPA}, | |
19829 | {"arm7500fe", FPU_ARCH_FPA}, | |
19830 | {"softvfp", FPU_ARCH_VFP}, | |
19831 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
19832 | {"vfp", FPU_ARCH_VFP_V2}, | |
19833 | {"vfp9", FPU_ARCH_VFP_V2}, | |
5287ad62 | 19834 | {"vfp3", FPU_ARCH_VFP_V3}, |
c19d1205 ZW |
19835 | {"vfp10", FPU_ARCH_VFP_V2}, |
19836 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
19837 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
19838 | {"arm1020t", FPU_ARCH_VFP_V1}, | |
19839 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
19840 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
19841 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
19842 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 19843 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
e74cfd16 PB |
19844 | {NULL, ARM_ARCH_NONE} |
19845 | }; | |
19846 | ||
19847 | struct arm_option_value_table | |
19848 | { | |
19849 | char *name; | |
19850 | long value; | |
c19d1205 | 19851 | }; |
7ed4c4c5 | 19852 | |
e74cfd16 | 19853 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
19854 | { |
19855 | {"hard", ARM_FLOAT_ABI_HARD}, | |
19856 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
19857 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 19858 | {NULL, 0} |
c19d1205 | 19859 | }; |
7ed4c4c5 | 19860 | |
c19d1205 | 19861 | #ifdef OBJ_ELF |
3a4a14e9 | 19862 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 19863 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
19864 | { |
19865 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
19866 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 19867 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 19868 | {NULL, 0} |
c19d1205 ZW |
19869 | }; |
19870 | #endif | |
7ed4c4c5 | 19871 | |
c19d1205 ZW |
19872 | struct arm_long_option_table |
19873 | { | |
19874 | char * option; /* Substring to match. */ | |
19875 | char * help; /* Help information. */ | |
19876 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
19877 | char * deprecated; /* If non-null, print this message. */ | |
19878 | }; | |
7ed4c4c5 NC |
19879 | |
19880 | static int | |
e74cfd16 | 19881 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 19882 | { |
e74cfd16 PB |
19883 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
19884 | ||
19885 | /* Copy the feature set, so that we can modify it. */ | |
19886 | *ext_set = **opt_p; | |
19887 | *opt_p = ext_set; | |
19888 | ||
c19d1205 | 19889 | while (str != NULL && *str != 0) |
7ed4c4c5 | 19890 | { |
e74cfd16 | 19891 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
19892 | char * ext; |
19893 | int optlen; | |
7ed4c4c5 | 19894 | |
c19d1205 ZW |
19895 | if (*str != '+') |
19896 | { | |
19897 | as_bad (_("invalid architectural extension")); | |
19898 | return 0; | |
19899 | } | |
7ed4c4c5 | 19900 | |
c19d1205 ZW |
19901 | str++; |
19902 | ext = strchr (str, '+'); | |
7ed4c4c5 | 19903 | |
c19d1205 ZW |
19904 | if (ext != NULL) |
19905 | optlen = ext - str; | |
19906 | else | |
19907 | optlen = strlen (str); | |
7ed4c4c5 | 19908 | |
c19d1205 ZW |
19909 | if (optlen == 0) |
19910 | { | |
19911 | as_bad (_("missing architectural extension")); | |
19912 | return 0; | |
19913 | } | |
7ed4c4c5 | 19914 | |
c19d1205 ZW |
19915 | for (opt = arm_extensions; opt->name != NULL; opt++) |
19916 | if (strncmp (opt->name, str, optlen) == 0) | |
19917 | { | |
e74cfd16 | 19918 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
19919 | break; |
19920 | } | |
7ed4c4c5 | 19921 | |
c19d1205 ZW |
19922 | if (opt->name == NULL) |
19923 | { | |
19924 | as_bad (_("unknown architectural extnsion `%s'"), str); | |
19925 | return 0; | |
19926 | } | |
7ed4c4c5 | 19927 | |
c19d1205 ZW |
19928 | str = ext; |
19929 | }; | |
7ed4c4c5 | 19930 | |
c19d1205 ZW |
19931 | return 1; |
19932 | } | |
7ed4c4c5 | 19933 | |
c19d1205 ZW |
19934 | static int |
19935 | arm_parse_cpu (char * str) | |
7ed4c4c5 | 19936 | { |
e74cfd16 | 19937 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
19938 | char * ext = strchr (str, '+'); |
19939 | int optlen; | |
7ed4c4c5 | 19940 | |
c19d1205 ZW |
19941 | if (ext != NULL) |
19942 | optlen = ext - str; | |
7ed4c4c5 | 19943 | else |
c19d1205 | 19944 | optlen = strlen (str); |
7ed4c4c5 | 19945 | |
c19d1205 | 19946 | if (optlen == 0) |
7ed4c4c5 | 19947 | { |
c19d1205 ZW |
19948 | as_bad (_("missing cpu name `%s'"), str); |
19949 | return 0; | |
7ed4c4c5 NC |
19950 | } |
19951 | ||
c19d1205 ZW |
19952 | for (opt = arm_cpus; opt->name != NULL; opt++) |
19953 | if (strncmp (opt->name, str, optlen) == 0) | |
19954 | { | |
e74cfd16 PB |
19955 | mcpu_cpu_opt = &opt->value; |
19956 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 PB |
19957 | if (opt->canonical_name) |
19958 | strcpy(selected_cpu_name, opt->canonical_name); | |
19959 | else | |
19960 | { | |
19961 | int i; | |
19962 | for (i = 0; i < optlen; i++) | |
19963 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
19964 | selected_cpu_name[i] = 0; | |
19965 | } | |
7ed4c4c5 | 19966 | |
c19d1205 ZW |
19967 | if (ext != NULL) |
19968 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 19969 | |
c19d1205 ZW |
19970 | return 1; |
19971 | } | |
7ed4c4c5 | 19972 | |
c19d1205 ZW |
19973 | as_bad (_("unknown cpu `%s'"), str); |
19974 | return 0; | |
7ed4c4c5 NC |
19975 | } |
19976 | ||
c19d1205 ZW |
19977 | static int |
19978 | arm_parse_arch (char * str) | |
7ed4c4c5 | 19979 | { |
e74cfd16 | 19980 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
19981 | char *ext = strchr (str, '+'); |
19982 | int optlen; | |
7ed4c4c5 | 19983 | |
c19d1205 ZW |
19984 | if (ext != NULL) |
19985 | optlen = ext - str; | |
7ed4c4c5 | 19986 | else |
c19d1205 | 19987 | optlen = strlen (str); |
7ed4c4c5 | 19988 | |
c19d1205 | 19989 | if (optlen == 0) |
7ed4c4c5 | 19990 | { |
c19d1205 ZW |
19991 | as_bad (_("missing architecture name `%s'"), str); |
19992 | return 0; | |
7ed4c4c5 NC |
19993 | } |
19994 | ||
c19d1205 ZW |
19995 | for (opt = arm_archs; opt->name != NULL; opt++) |
19996 | if (streq (opt->name, str)) | |
19997 | { | |
e74cfd16 PB |
19998 | march_cpu_opt = &opt->value; |
19999 | march_fpu_opt = &opt->default_fpu; | |
ee065d83 | 20000 | strcpy(selected_cpu_name, opt->name); |
7ed4c4c5 | 20001 | |
c19d1205 ZW |
20002 | if (ext != NULL) |
20003 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 20004 | |
c19d1205 ZW |
20005 | return 1; |
20006 | } | |
20007 | ||
20008 | as_bad (_("unknown architecture `%s'\n"), str); | |
20009 | return 0; | |
7ed4c4c5 | 20010 | } |
eb043451 | 20011 | |
c19d1205 ZW |
20012 | static int |
20013 | arm_parse_fpu (char * str) | |
20014 | { | |
e74cfd16 | 20015 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 20016 | |
c19d1205 ZW |
20017 | for (opt = arm_fpus; opt->name != NULL; opt++) |
20018 | if (streq (opt->name, str)) | |
20019 | { | |
e74cfd16 | 20020 | mfpu_opt = &opt->value; |
c19d1205 ZW |
20021 | return 1; |
20022 | } | |
b99bd4ef | 20023 | |
c19d1205 ZW |
20024 | as_bad (_("unknown floating point format `%s'\n"), str); |
20025 | return 0; | |
20026 | } | |
20027 | ||
20028 | static int | |
20029 | arm_parse_float_abi (char * str) | |
b99bd4ef | 20030 | { |
e74cfd16 | 20031 | const struct arm_option_value_table * opt; |
b99bd4ef | 20032 | |
c19d1205 ZW |
20033 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
20034 | if (streq (opt->name, str)) | |
20035 | { | |
20036 | mfloat_abi_opt = opt->value; | |
20037 | return 1; | |
20038 | } | |
cc8a6dd0 | 20039 | |
c19d1205 ZW |
20040 | as_bad (_("unknown floating point abi `%s'\n"), str); |
20041 | return 0; | |
20042 | } | |
b99bd4ef | 20043 | |
c19d1205 ZW |
20044 | #ifdef OBJ_ELF |
20045 | static int | |
20046 | arm_parse_eabi (char * str) | |
20047 | { | |
e74cfd16 | 20048 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 20049 | |
c19d1205 ZW |
20050 | for (opt = arm_eabis; opt->name != NULL; opt++) |
20051 | if (streq (opt->name, str)) | |
20052 | { | |
20053 | meabi_flags = opt->value; | |
20054 | return 1; | |
20055 | } | |
20056 | as_bad (_("unknown EABI `%s'\n"), str); | |
20057 | return 0; | |
20058 | } | |
20059 | #endif | |
cc8a6dd0 | 20060 | |
c19d1205 ZW |
20061 | struct arm_long_option_table arm_long_opts[] = |
20062 | { | |
20063 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
20064 | arm_parse_cpu, NULL}, | |
20065 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
20066 | arm_parse_arch, NULL}, | |
20067 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
20068 | arm_parse_fpu, NULL}, | |
20069 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
20070 | arm_parse_float_abi, NULL}, | |
20071 | #ifdef OBJ_ELF | |
20072 | {"meabi=", N_("<ver>\t assemble for eabi version <ver>"), | |
20073 | arm_parse_eabi, NULL}, | |
20074 | #endif | |
20075 | {NULL, NULL, 0, NULL} | |
20076 | }; | |
cc8a6dd0 | 20077 | |
c19d1205 ZW |
20078 | int |
20079 | md_parse_option (int c, char * arg) | |
20080 | { | |
20081 | struct arm_option_table *opt; | |
e74cfd16 | 20082 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 20083 | struct arm_long_option_table *lopt; |
b99bd4ef | 20084 | |
c19d1205 | 20085 | switch (c) |
b99bd4ef | 20086 | { |
c19d1205 ZW |
20087 | #ifdef OPTION_EB |
20088 | case OPTION_EB: | |
20089 | target_big_endian = 1; | |
20090 | break; | |
20091 | #endif | |
cc8a6dd0 | 20092 | |
c19d1205 ZW |
20093 | #ifdef OPTION_EL |
20094 | case OPTION_EL: | |
20095 | target_big_endian = 0; | |
20096 | break; | |
20097 | #endif | |
b99bd4ef | 20098 | |
c19d1205 ZW |
20099 | case 'a': |
20100 | /* Listing option. Just ignore these, we don't support additional | |
20101 | ones. */ | |
20102 | return 0; | |
b99bd4ef | 20103 | |
c19d1205 ZW |
20104 | default: |
20105 | for (opt = arm_opts; opt->option != NULL; opt++) | |
20106 | { | |
20107 | if (c == opt->option[0] | |
20108 | && ((arg == NULL && opt->option[1] == 0) | |
20109 | || streq (arg, opt->option + 1))) | |
20110 | { | |
20111 | #if WARN_DEPRECATED | |
20112 | /* If the option is deprecated, tell the user. */ | |
20113 | if (opt->deprecated != NULL) | |
20114 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
20115 | arg ? arg : "", _(opt->deprecated)); | |
20116 | #endif | |
b99bd4ef | 20117 | |
c19d1205 ZW |
20118 | if (opt->var != NULL) |
20119 | *opt->var = opt->value; | |
cc8a6dd0 | 20120 | |
c19d1205 ZW |
20121 | return 1; |
20122 | } | |
20123 | } | |
b99bd4ef | 20124 | |
e74cfd16 PB |
20125 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
20126 | { | |
20127 | if (c == fopt->option[0] | |
20128 | && ((arg == NULL && fopt->option[1] == 0) | |
20129 | || streq (arg, fopt->option + 1))) | |
20130 | { | |
20131 | #if WARN_DEPRECATED | |
20132 | /* If the option is deprecated, tell the user. */ | |
20133 | if (fopt->deprecated != NULL) | |
20134 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
20135 | arg ? arg : "", _(fopt->deprecated)); | |
20136 | #endif | |
20137 | ||
20138 | if (fopt->var != NULL) | |
20139 | *fopt->var = &fopt->value; | |
20140 | ||
20141 | return 1; | |
20142 | } | |
20143 | } | |
20144 | ||
c19d1205 ZW |
20145 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
20146 | { | |
20147 | /* These options are expected to have an argument. */ | |
20148 | if (c == lopt->option[0] | |
20149 | && arg != NULL | |
20150 | && strncmp (arg, lopt->option + 1, | |
20151 | strlen (lopt->option + 1)) == 0) | |
20152 | { | |
20153 | #if WARN_DEPRECATED | |
20154 | /* If the option is deprecated, tell the user. */ | |
20155 | if (lopt->deprecated != NULL) | |
20156 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, | |
20157 | _(lopt->deprecated)); | |
20158 | #endif | |
b99bd4ef | 20159 | |
c19d1205 ZW |
20160 | /* Call the sup-option parser. */ |
20161 | return lopt->func (arg + strlen (lopt->option) - 1); | |
20162 | } | |
20163 | } | |
a737bd4d | 20164 | |
c19d1205 ZW |
20165 | return 0; |
20166 | } | |
a394c00f | 20167 | |
c19d1205 ZW |
20168 | return 1; |
20169 | } | |
a394c00f | 20170 | |
c19d1205 ZW |
20171 | void |
20172 | md_show_usage (FILE * fp) | |
a394c00f | 20173 | { |
c19d1205 ZW |
20174 | struct arm_option_table *opt; |
20175 | struct arm_long_option_table *lopt; | |
a394c00f | 20176 | |
c19d1205 | 20177 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 20178 | |
c19d1205 ZW |
20179 | for (opt = arm_opts; opt->option != NULL; opt++) |
20180 | if (opt->help != NULL) | |
20181 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 20182 | |
c19d1205 ZW |
20183 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
20184 | if (lopt->help != NULL) | |
20185 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 20186 | |
c19d1205 ZW |
20187 | #ifdef OPTION_EB |
20188 | fprintf (fp, _("\ | |
20189 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
20190 | #endif |
20191 | ||
c19d1205 ZW |
20192 | #ifdef OPTION_EL |
20193 | fprintf (fp, _("\ | |
20194 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 20195 | #endif |
c19d1205 | 20196 | } |
ee065d83 PB |
20197 | |
20198 | ||
20199 | #ifdef OBJ_ELF | |
62b3e311 PB |
20200 | typedef struct |
20201 | { | |
20202 | int val; | |
20203 | arm_feature_set flags; | |
20204 | } cpu_arch_ver_table; | |
20205 | ||
20206 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
20207 | least features first. */ | |
20208 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
20209 | { | |
20210 | {1, ARM_ARCH_V4}, | |
20211 | {2, ARM_ARCH_V4T}, | |
20212 | {3, ARM_ARCH_V5}, | |
20213 | {4, ARM_ARCH_V5TE}, | |
20214 | {5, ARM_ARCH_V5TEJ}, | |
20215 | {6, ARM_ARCH_V6}, | |
20216 | {7, ARM_ARCH_V6Z}, | |
20217 | {8, ARM_ARCH_V6K}, | |
20218 | {9, ARM_ARCH_V6T2}, | |
20219 | {10, ARM_ARCH_V7A}, | |
20220 | {10, ARM_ARCH_V7R}, | |
20221 | {10, ARM_ARCH_V7M}, | |
20222 | {0, ARM_ARCH_NONE} | |
20223 | }; | |
20224 | ||
ee065d83 PB |
20225 | /* Set the public EABI object attributes. */ |
20226 | static void | |
20227 | aeabi_set_public_attributes (void) | |
20228 | { | |
20229 | int arch; | |
e74cfd16 | 20230 | arm_feature_set flags; |
62b3e311 PB |
20231 | arm_feature_set tmp; |
20232 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
20233 | |
20234 | /* Choose the architecture based on the capabilities of the requested cpu | |
20235 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
20236 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
20237 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
20238 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
5287ad62 | 20239 | |
62b3e311 PB |
20240 | tmp = flags; |
20241 | arch = 0; | |
20242 | for (p = cpu_arch_ver; p->val; p++) | |
20243 | { | |
20244 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
20245 | { | |
20246 | arch = p->val; | |
20247 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
20248 | } | |
20249 | } | |
ee065d83 PB |
20250 | |
20251 | /* Tag_CPU_name. */ | |
20252 | if (selected_cpu_name[0]) | |
20253 | { | |
20254 | char *p; | |
20255 | ||
20256 | p = selected_cpu_name; | |
20257 | if (strncmp(p, "armv", 4) == 0) | |
20258 | { | |
20259 | int i; | |
20260 | ||
20261 | p += 4; | |
20262 | for (i = 0; p[i]; i++) | |
20263 | p[i] = TOUPPER (p[i]); | |
20264 | } | |
20265 | elf32_arm_add_eabi_attr_string (stdoutput, 5, p); | |
20266 | } | |
20267 | /* Tag_CPU_arch. */ | |
20268 | elf32_arm_add_eabi_attr_int (stdoutput, 6, arch); | |
62b3e311 PB |
20269 | /* Tag_CPU_arch_profile. */ |
20270 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
20271 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A'); | |
20272 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) | |
20273 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R'); | |
20274 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)) | |
20275 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M'); | |
ee065d83 | 20276 | /* Tag_ARM_ISA_use. */ |
e74cfd16 | 20277 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full)) |
ee065d83 PB |
20278 | elf32_arm_add_eabi_attr_int (stdoutput, 8, 1); |
20279 | /* Tag_THUMB_ISA_use. */ | |
e74cfd16 | 20280 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full)) |
ee065d83 | 20281 | elf32_arm_add_eabi_attr_int (stdoutput, 9, |
e74cfd16 | 20282 | ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1); |
ee065d83 | 20283 | /* Tag_VFP_arch. */ |
5287ad62 JB |
20284 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3) |
20285 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3)) | |
20286 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 3); | |
20287 | else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2) | |
20288 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2)) | |
ee065d83 | 20289 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 2); |
5287ad62 JB |
20290 | else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1) |
20291 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1) | |
20292 | || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd) | |
20293 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd)) | |
ee065d83 PB |
20294 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 1); |
20295 | /* Tag_WMMX_arch. */ | |
e74cfd16 PB |
20296 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt) |
20297 | || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt)) | |
ee065d83 | 20298 | elf32_arm_add_eabi_attr_int (stdoutput, 11, 1); |
5287ad62 JB |
20299 | /* Tag_NEON_arch. */ |
20300 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1) | |
20301 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1)) | |
20302 | elf32_arm_add_eabi_attr_int (stdoutput, 12, 1); | |
ee065d83 PB |
20303 | } |
20304 | ||
20305 | /* Add the .ARM.attributes section. */ | |
20306 | void | |
20307 | arm_md_end (void) | |
20308 | { | |
20309 | segT s; | |
20310 | char *p; | |
20311 | addressT addr; | |
20312 | offsetT size; | |
20313 | ||
20314 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) | |
20315 | return; | |
20316 | ||
20317 | aeabi_set_public_attributes (); | |
20318 | size = elf32_arm_eabi_attr_size (stdoutput); | |
20319 | s = subseg_new (".ARM.attributes", 0); | |
20320 | bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA); | |
20321 | addr = frag_now_fix (); | |
20322 | p = frag_more (size); | |
20323 | elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size); | |
20324 | } | |
8463be01 | 20325 | #endif /* OBJ_ELF */ |
ee065d83 PB |
20326 | |
20327 | ||
20328 | /* Parse a .cpu directive. */ | |
20329 | ||
20330 | static void | |
20331 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
20332 | { | |
e74cfd16 | 20333 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
20334 | char *name; |
20335 | char saved_char; | |
20336 | ||
20337 | name = input_line_pointer; | |
20338 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
20339 | input_line_pointer++; | |
20340 | saved_char = *input_line_pointer; | |
20341 | *input_line_pointer = 0; | |
20342 | ||
20343 | /* Skip the first "all" entry. */ | |
20344 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
20345 | if (streq (opt->name, name)) | |
20346 | { | |
e74cfd16 PB |
20347 | mcpu_cpu_opt = &opt->value; |
20348 | selected_cpu = opt->value; | |
ee065d83 PB |
20349 | if (opt->canonical_name) |
20350 | strcpy(selected_cpu_name, opt->canonical_name); | |
20351 | else | |
20352 | { | |
20353 | int i; | |
20354 | for (i = 0; opt->name[i]; i++) | |
20355 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
20356 | selected_cpu_name[i] = 0; | |
20357 | } | |
e74cfd16 | 20358 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
20359 | *input_line_pointer = saved_char; |
20360 | demand_empty_rest_of_line (); | |
20361 | return; | |
20362 | } | |
20363 | as_bad (_("unknown cpu `%s'"), name); | |
20364 | *input_line_pointer = saved_char; | |
20365 | ignore_rest_of_line (); | |
20366 | } | |
20367 | ||
20368 | ||
20369 | /* Parse a .arch directive. */ | |
20370 | ||
20371 | static void | |
20372 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
20373 | { | |
e74cfd16 | 20374 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
20375 | char saved_char; |
20376 | char *name; | |
20377 | ||
20378 | name = input_line_pointer; | |
20379 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
20380 | input_line_pointer++; | |
20381 | saved_char = *input_line_pointer; | |
20382 | *input_line_pointer = 0; | |
20383 | ||
20384 | /* Skip the first "all" entry. */ | |
20385 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
20386 | if (streq (opt->name, name)) | |
20387 | { | |
e74cfd16 PB |
20388 | mcpu_cpu_opt = &opt->value; |
20389 | selected_cpu = opt->value; | |
ee065d83 | 20390 | strcpy(selected_cpu_name, opt->name); |
e74cfd16 | 20391 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
20392 | *input_line_pointer = saved_char; |
20393 | demand_empty_rest_of_line (); | |
20394 | return; | |
20395 | } | |
20396 | ||
20397 | as_bad (_("unknown architecture `%s'\n"), name); | |
20398 | *input_line_pointer = saved_char; | |
20399 | ignore_rest_of_line (); | |
20400 | } | |
20401 | ||
20402 | ||
20403 | /* Parse a .fpu directive. */ | |
20404 | ||
20405 | static void | |
20406 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
20407 | { | |
e74cfd16 | 20408 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
20409 | char saved_char; |
20410 | char *name; | |
20411 | ||
20412 | name = input_line_pointer; | |
20413 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
20414 | input_line_pointer++; | |
20415 | saved_char = *input_line_pointer; | |
20416 | *input_line_pointer = 0; | |
20417 | ||
20418 | for (opt = arm_fpus; opt->name != NULL; opt++) | |
20419 | if (streq (opt->name, name)) | |
20420 | { | |
e74cfd16 PB |
20421 | mfpu_opt = &opt->value; |
20422 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
20423 | *input_line_pointer = saved_char; |
20424 | demand_empty_rest_of_line (); | |
20425 | return; | |
20426 | } | |
20427 | ||
20428 | as_bad (_("unknown floating point format `%s'\n"), name); | |
20429 | *input_line_pointer = saved_char; | |
20430 | ignore_rest_of_line (); | |
20431 | } | |
ee065d83 | 20432 |