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, |
f31fef98 | 3 | 2004, 2005, 2006, 2007, 2008, 2009 |
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 | |
ec2655a6 | 15 | the Free Software Foundation; either version 3, or (at your option) |
b99bd4ef NC |
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 | |
42a68e18 | 28 | #include "as.h" |
5287ad62 | 29 | #include <limits.h> |
037e8744 | 30 | #include <stdarg.h> |
c19d1205 | 31 | #define NO_RELOC 0 |
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 | ||
7ed4c4c5 NC |
45 | #ifdef OBJ_ELF |
46 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
47 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
48 | ||
49 | /* This structure holds the unwinding state. */ | |
50 | ||
51 | static struct | |
52 | { | |
c19d1205 ZW |
53 | symbolS * proc_start; |
54 | symbolS * table_entry; | |
55 | symbolS * personality_routine; | |
56 | int personality_index; | |
7ed4c4c5 | 57 | /* The segment containing the function. */ |
c19d1205 ZW |
58 | segT saved_seg; |
59 | subsegT saved_subseg; | |
7ed4c4c5 NC |
60 | /* Opcodes generated from this function. */ |
61 | unsigned char * opcodes; | |
c19d1205 ZW |
62 | int opcode_count; |
63 | int opcode_alloc; | |
7ed4c4c5 | 64 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 65 | offsetT frame_size; |
7ed4c4c5 NC |
66 | /* We don't add stack adjustment opcodes immediately so that we can merge |
67 | multiple adjustments. We can also omit the final adjustment | |
68 | when using a frame pointer. */ | |
c19d1205 | 69 | offsetT pending_offset; |
7ed4c4c5 | 70 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
71 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
72 | offsetT fp_offset; | |
73 | int fp_reg; | |
7ed4c4c5 | 74 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 75 | unsigned fp_used:1; |
7ed4c4c5 | 76 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 77 | unsigned sp_restored:1; |
7ed4c4c5 NC |
78 | } unwind; |
79 | ||
8b1ad454 NC |
80 | #endif /* OBJ_ELF */ |
81 | ||
4962c51a MS |
82 | /* Results from operand parsing worker functions. */ |
83 | ||
84 | typedef enum | |
85 | { | |
86 | PARSE_OPERAND_SUCCESS, | |
87 | PARSE_OPERAND_FAIL, | |
88 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
89 | } parse_operand_result; | |
90 | ||
33a392fb PB |
91 | enum arm_float_abi |
92 | { | |
93 | ARM_FLOAT_ABI_HARD, | |
94 | ARM_FLOAT_ABI_SOFTFP, | |
95 | ARM_FLOAT_ABI_SOFT | |
96 | }; | |
97 | ||
c19d1205 | 98 | /* Types of processor to assemble for. */ |
b99bd4ef NC |
99 | #ifndef CPU_DEFAULT |
100 | #if defined __XSCALE__ | |
e74cfd16 | 101 | #define CPU_DEFAULT ARM_ARCH_XSCALE |
b99bd4ef NC |
102 | #else |
103 | #if defined __thumb__ | |
e74cfd16 | 104 | #define CPU_DEFAULT ARM_ARCH_V5T |
b99bd4ef NC |
105 | #endif |
106 | #endif | |
107 | #endif | |
108 | ||
109 | #ifndef FPU_DEFAULT | |
c820d418 MM |
110 | # ifdef TE_LINUX |
111 | # define FPU_DEFAULT FPU_ARCH_FPA | |
112 | # elif defined (TE_NetBSD) | |
113 | # ifdef OBJ_ELF | |
114 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
115 | # else | |
116 | /* Legacy a.out format. */ | |
117 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
118 | # endif | |
4e7fd91e PB |
119 | # elif defined (TE_VXWORKS) |
120 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
121 | # else |
122 | /* For backwards compatibility, default to FPA. */ | |
123 | # define FPU_DEFAULT FPU_ARCH_FPA | |
124 | # endif | |
125 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 126 | |
c19d1205 | 127 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 128 | |
e74cfd16 PB |
129 | static arm_feature_set cpu_variant; |
130 | static arm_feature_set arm_arch_used; | |
131 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 132 | |
b99bd4ef | 133 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
134 | static int uses_apcs_26 = FALSE; |
135 | static int atpcs = FALSE; | |
b34976b6 AM |
136 | static int support_interwork = FALSE; |
137 | static int uses_apcs_float = FALSE; | |
c19d1205 | 138 | static int pic_code = FALSE; |
845b51d6 | 139 | static int fix_v4bx = FALSE; |
278df34e NS |
140 | /* Warn on using deprecated features. */ |
141 | static int warn_on_deprecated = TRUE; | |
142 | ||
03b1477f RE |
143 | |
144 | /* Variables that we set while parsing command-line options. Once all | |
145 | options have been read we re-process these values to set the real | |
146 | assembly flags. */ | |
e74cfd16 PB |
147 | static const arm_feature_set *legacy_cpu = NULL; |
148 | static const arm_feature_set *legacy_fpu = NULL; | |
149 | ||
150 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
151 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
152 | static const arm_feature_set *march_cpu_opt = NULL; | |
153 | static const arm_feature_set *march_fpu_opt = NULL; | |
154 | static const arm_feature_set *mfpu_opt = NULL; | |
7a1d4c38 | 155 | static const arm_feature_set *object_arch = NULL; |
e74cfd16 PB |
156 | |
157 | /* Constants for known architecture features. */ | |
158 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
159 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
160 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
161 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
162 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
163 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
164 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
165 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
166 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
167 | ||
168 | #ifdef CPU_DEFAULT | |
169 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
170 | #endif | |
171 | ||
172 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
173 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
174 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
175 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
176 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
177 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
178 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
179 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
180 | static const arm_feature_set arm_ext_v4t_5 = | |
181 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
182 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
183 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
184 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
185 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
186 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
187 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
188 | static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0); | |
189 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); | |
62b3e311 | 190 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
7e806470 PB |
191 | static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0); |
192 | static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0); | |
62b3e311 PB |
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); | |
7e806470 PB |
197 | static const arm_feature_set arm_ext_m = |
198 | ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0); | |
e74cfd16 PB |
199 | |
200 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
201 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
202 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
203 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
204 | ||
2d447fca JM |
205 | static const arm_feature_set arm_cext_iwmmxt2 = |
206 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2); | |
e74cfd16 PB |
207 | static const arm_feature_set arm_cext_iwmmxt = |
208 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
209 | static const arm_feature_set arm_cext_xscale = | |
210 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
211 | static const arm_feature_set arm_cext_maverick = | |
212 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
213 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
214 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
215 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
216 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
217 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
218 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
62f3b8c8 | 219 | static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD); |
5287ad62 | 220 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
b1cc4aeb PB |
221 | static const arm_feature_set fpu_vfp_ext_d32 = |
222 | ARM_FEATURE (0, FPU_VFP_EXT_D32); | |
5287ad62 JB |
223 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); |
224 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
225 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
62f3b8c8 PB |
226 | static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16); |
227 | static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA); | |
228 | static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA); | |
e74cfd16 | 229 | |
33a392fb | 230 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
231 | /* Record user cpu selection for object attributes. */ |
232 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
233 | /* Must be long enough to hold any of the names in arm_cpus. */ |
234 | static char selected_cpu_name[16]; | |
7cc69913 | 235 | #ifdef OBJ_ELF |
deeaaff8 DJ |
236 | # ifdef EABI_DEFAULT |
237 | static int meabi_flags = EABI_DEFAULT; | |
238 | # else | |
d507cf36 | 239 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 240 | # endif |
e1da3f5b | 241 | |
ee3c0378 AS |
242 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
243 | ||
e1da3f5b | 244 | bfd_boolean |
5f4273c7 | 245 | arm_is_eabi (void) |
e1da3f5b PB |
246 | { |
247 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
248 | } | |
7cc69913 | 249 | #endif |
b99bd4ef | 250 | |
b99bd4ef | 251 | #ifdef OBJ_ELF |
c19d1205 | 252 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
253 | symbolS * GOT_symbol; |
254 | #endif | |
255 | ||
b99bd4ef NC |
256 | /* 0: assemble for ARM, |
257 | 1: assemble for Thumb, | |
258 | 2: assemble for Thumb even though target CPU does not support thumb | |
259 | instructions. */ | |
260 | static int thumb_mode = 0; | |
8dc2430f NC |
261 | /* A value distinct from the possible values for thumb_mode that we |
262 | can use to record whether thumb_mode has been copied into the | |
263 | tc_frag_data field of a frag. */ | |
264 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 265 | |
e07e6e58 NC |
266 | /* Specifies the intrinsic IT insn behavior mode. */ |
267 | enum implicit_it_mode | |
268 | { | |
269 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
270 | IMPLICIT_IT_MODE_ARM = 0x01, | |
271 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
272 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
273 | }; | |
274 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
275 | ||
c19d1205 ZW |
276 | /* If unified_syntax is true, we are processing the new unified |
277 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
278 | ||
279 | - Immediate operands do not require a # prefix. | |
280 | - Conditional affixes always appear at the end of the | |
281 | instruction. (For backward compatibility, those instructions | |
282 | that formerly had them in the middle, continue to accept them | |
283 | there.) | |
284 | - The IT instruction may appear, and if it does is validated | |
285 | against subsequent conditional affixes. It does not generate | |
286 | machine code. | |
287 | ||
288 | Important differences from the old Thumb mode: | |
289 | ||
290 | - Immediate operands do not require a # prefix. | |
291 | - Most of the V6T2 instructions are only available in unified mode. | |
292 | - The .N and .W suffixes are recognized and honored (it is an error | |
293 | if they cannot be honored). | |
294 | - All instructions set the flags if and only if they have an 's' affix. | |
295 | - Conditional affixes may be used. They are validated against | |
296 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
297 | conditional affix except in the scope of an IT instruction. */ | |
298 | ||
299 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 300 | |
5287ad62 JB |
301 | enum neon_el_type |
302 | { | |
dcbf9037 | 303 | NT_invtype, |
5287ad62 JB |
304 | NT_untyped, |
305 | NT_integer, | |
306 | NT_float, | |
307 | NT_poly, | |
308 | NT_signed, | |
dcbf9037 | 309 | NT_unsigned |
5287ad62 JB |
310 | }; |
311 | ||
312 | struct neon_type_el | |
313 | { | |
314 | enum neon_el_type type; | |
315 | unsigned size; | |
316 | }; | |
317 | ||
318 | #define NEON_MAX_TYPE_ELS 4 | |
319 | ||
320 | struct neon_type | |
321 | { | |
322 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
323 | unsigned elems; | |
324 | }; | |
325 | ||
e07e6e58 NC |
326 | enum it_instruction_type |
327 | { | |
328 | OUTSIDE_IT_INSN, | |
329 | INSIDE_IT_INSN, | |
330 | INSIDE_IT_LAST_INSN, | |
331 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
332 | if inside, should be the last one. */ | |
333 | NEUTRAL_IT_INSN, /* This could be either inside or outside, | |
334 | i.e. BKPT and NOP. */ | |
335 | IT_INSN /* The IT insn has been parsed. */ | |
336 | }; | |
337 | ||
b99bd4ef NC |
338 | struct arm_it |
339 | { | |
c19d1205 | 340 | const char * error; |
b99bd4ef | 341 | unsigned long instruction; |
c19d1205 ZW |
342 | int size; |
343 | int size_req; | |
344 | int cond; | |
037e8744 JB |
345 | /* "uncond_value" is set to the value in place of the conditional field in |
346 | unconditional versions of the instruction, or -1 if nothing is | |
347 | appropriate. */ | |
348 | int uncond_value; | |
5287ad62 | 349 | struct neon_type vectype; |
0110f2b8 PB |
350 | /* Set to the opcode if the instruction needs relaxation. |
351 | Zero if the instruction is not relaxed. */ | |
352 | unsigned long relax; | |
b99bd4ef NC |
353 | struct |
354 | { | |
355 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
356 | expressionS exp; |
357 | int pc_rel; | |
b99bd4ef | 358 | } reloc; |
b99bd4ef | 359 | |
e07e6e58 NC |
360 | enum it_instruction_type it_insn_type; |
361 | ||
c19d1205 ZW |
362 | struct |
363 | { | |
364 | unsigned reg; | |
ca3f61f7 | 365 | signed int imm; |
dcbf9037 | 366 | struct neon_type_el vectype; |
ca3f61f7 NC |
367 | unsigned present : 1; /* Operand present. */ |
368 | unsigned isreg : 1; /* Operand was a register. */ | |
369 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
370 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
371 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 372 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
373 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
374 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
375 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 376 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 377 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 378 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
379 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
380 | unsigned writeback : 1; /* Operand has trailing ! */ | |
381 | unsigned preind : 1; /* Preindexed address. */ | |
382 | unsigned postind : 1; /* Postindexed address. */ | |
383 | unsigned negative : 1; /* Index register was negated. */ | |
384 | unsigned shifted : 1; /* Shift applied to operation. */ | |
385 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 386 | } operands[6]; |
b99bd4ef NC |
387 | }; |
388 | ||
c19d1205 | 389 | static struct arm_it inst; |
b99bd4ef NC |
390 | |
391 | #define NUM_FLOAT_VALS 8 | |
392 | ||
05d2d07e | 393 | const char * fp_const[] = |
b99bd4ef NC |
394 | { |
395 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
396 | }; | |
397 | ||
c19d1205 | 398 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
399 | #define MAX_LITTLENUMS 6 |
400 | ||
401 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
402 | ||
403 | #define FAIL (-1) | |
404 | #define SUCCESS (0) | |
405 | ||
406 | #define SUFF_S 1 | |
407 | #define SUFF_D 2 | |
408 | #define SUFF_E 3 | |
409 | #define SUFF_P 4 | |
410 | ||
c19d1205 ZW |
411 | #define CP_T_X 0x00008000 |
412 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 413 | |
c19d1205 ZW |
414 | #define CONDS_BIT 0x00100000 |
415 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
416 | |
417 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
418 | ||
419 | struct asm_cond | |
420 | { | |
d3ce72d0 | 421 | const char * template_name; |
c921be7d | 422 | unsigned long value; |
b99bd4ef NC |
423 | }; |
424 | ||
c19d1205 | 425 | #define COND_ALWAYS 0xE |
b99bd4ef | 426 | |
b99bd4ef NC |
427 | struct asm_psr |
428 | { | |
d3ce72d0 | 429 | const char * template_name; |
c921be7d | 430 | unsigned long field; |
b99bd4ef NC |
431 | }; |
432 | ||
62b3e311 PB |
433 | struct asm_barrier_opt |
434 | { | |
d3ce72d0 | 435 | const char * template_name; |
c921be7d | 436 | unsigned long value; |
62b3e311 PB |
437 | }; |
438 | ||
2d2255b5 | 439 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
440 | #define SPSR_BIT (1 << 22) |
441 | ||
c19d1205 ZW |
442 | /* The individual PSR flag bits. */ |
443 | #define PSR_c (1 << 16) | |
444 | #define PSR_x (1 << 17) | |
445 | #define PSR_s (1 << 18) | |
446 | #define PSR_f (1 << 19) | |
b99bd4ef | 447 | |
c19d1205 | 448 | struct reloc_entry |
bfae80f2 | 449 | { |
c921be7d NC |
450 | char * name; |
451 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
452 | }; |
453 | ||
5287ad62 | 454 | enum vfp_reg_pos |
bfae80f2 | 455 | { |
5287ad62 JB |
456 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
457 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
458 | }; |
459 | ||
460 | enum vfp_ldstm_type | |
461 | { | |
462 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
463 | }; | |
464 | ||
dcbf9037 JB |
465 | /* Bits for DEFINED field in neon_typed_alias. */ |
466 | #define NTA_HASTYPE 1 | |
467 | #define NTA_HASINDEX 2 | |
468 | ||
469 | struct neon_typed_alias | |
470 | { | |
c921be7d NC |
471 | unsigned char defined; |
472 | unsigned char index; | |
473 | struct neon_type_el eltype; | |
dcbf9037 JB |
474 | }; |
475 | ||
c19d1205 ZW |
476 | /* ARM register categories. This includes coprocessor numbers and various |
477 | architecture extensions' registers. */ | |
478 | enum arm_reg_type | |
bfae80f2 | 479 | { |
c19d1205 ZW |
480 | REG_TYPE_RN, |
481 | REG_TYPE_CP, | |
482 | REG_TYPE_CN, | |
483 | REG_TYPE_FN, | |
484 | REG_TYPE_VFS, | |
485 | REG_TYPE_VFD, | |
5287ad62 | 486 | REG_TYPE_NQ, |
037e8744 | 487 | REG_TYPE_VFSD, |
5287ad62 | 488 | REG_TYPE_NDQ, |
037e8744 | 489 | REG_TYPE_NSDQ, |
c19d1205 ZW |
490 | REG_TYPE_VFC, |
491 | REG_TYPE_MVF, | |
492 | REG_TYPE_MVD, | |
493 | REG_TYPE_MVFX, | |
494 | REG_TYPE_MVDX, | |
495 | REG_TYPE_MVAX, | |
496 | REG_TYPE_DSPSC, | |
497 | REG_TYPE_MMXWR, | |
498 | REG_TYPE_MMXWC, | |
499 | REG_TYPE_MMXWCG, | |
500 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
501 | }; |
502 | ||
dcbf9037 JB |
503 | /* Structure for a hash table entry for a register. |
504 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
505 | information which states whether a vector type or index is specified (for a | |
506 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
507 | struct reg_entry |
508 | { | |
c921be7d NC |
509 | const char * name; |
510 | unsigned char number; | |
511 | unsigned char type; | |
512 | unsigned char builtin; | |
513 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
514 | }; |
515 | ||
c19d1205 | 516 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 517 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
518 | { |
519 | N_("ARM register expected"), | |
520 | N_("bad or missing co-processor number"), | |
521 | N_("co-processor register expected"), | |
522 | N_("FPA register expected"), | |
523 | N_("VFP single precision register expected"), | |
5287ad62 JB |
524 | N_("VFP/Neon double precision register expected"), |
525 | N_("Neon quad precision register expected"), | |
037e8744 | 526 | N_("VFP single or double precision register expected"), |
5287ad62 | 527 | N_("Neon double or quad precision register expected"), |
037e8744 | 528 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
529 | N_("VFP system register expected"), |
530 | N_("Maverick MVF register expected"), | |
531 | N_("Maverick MVD register expected"), | |
532 | N_("Maverick MVFX register expected"), | |
533 | N_("Maverick MVDX register expected"), | |
534 | N_("Maverick MVAX register expected"), | |
535 | N_("Maverick DSPSC register expected"), | |
536 | N_("iWMMXt data register expected"), | |
537 | N_("iWMMXt control register expected"), | |
538 | N_("iWMMXt scalar register expected"), | |
539 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
540 | }; |
541 | ||
c19d1205 ZW |
542 | /* Some well known registers that we refer to directly elsewhere. */ |
543 | #define REG_SP 13 | |
544 | #define REG_LR 14 | |
545 | #define REG_PC 15 | |
404ff6b5 | 546 | |
b99bd4ef NC |
547 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
548 | take 2: */ | |
c19d1205 | 549 | #define INSN_SIZE 4 |
b99bd4ef NC |
550 | |
551 | struct asm_opcode | |
552 | { | |
553 | /* Basic string to match. */ | |
d3ce72d0 | 554 | const char * template_name; |
c19d1205 ZW |
555 | |
556 | /* Parameters to instruction. */ | |
557 | unsigned char operands[8]; | |
558 | ||
559 | /* Conditional tag - see opcode_lookup. */ | |
560 | unsigned int tag : 4; | |
b99bd4ef NC |
561 | |
562 | /* Basic instruction code. */ | |
c19d1205 | 563 | unsigned int avalue : 28; |
b99bd4ef | 564 | |
c19d1205 ZW |
565 | /* Thumb-format instruction code. */ |
566 | unsigned int tvalue; | |
b99bd4ef | 567 | |
90e4755a | 568 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
569 | const arm_feature_set * avariant; |
570 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
571 | |
572 | /* Function to call to encode instruction in ARM format. */ | |
573 | void (* aencode) (void); | |
b99bd4ef | 574 | |
c19d1205 ZW |
575 | /* Function to call to encode instruction in Thumb format. */ |
576 | void (* tencode) (void); | |
b99bd4ef NC |
577 | }; |
578 | ||
a737bd4d NC |
579 | /* Defines for various bits that we will want to toggle. */ |
580 | #define INST_IMMEDIATE 0x02000000 | |
581 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 582 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
583 | #define SHIFT_BY_REG 0x00000010 |
584 | #define PRE_INDEX 0x01000000 | |
585 | #define INDEX_UP 0x00800000 | |
586 | #define WRITE_BACK 0x00200000 | |
587 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 588 | #define CPSI_MMOD 0x00020000 |
90e4755a | 589 | |
a737bd4d NC |
590 | #define LITERAL_MASK 0xf000f000 |
591 | #define OPCODE_MASK 0xfe1fffff | |
592 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 593 | |
efd81785 PB |
594 | #define T2_SUBS_PC_LR 0xf3de8f00 |
595 | ||
a737bd4d | 596 | #define DATA_OP_SHIFT 21 |
90e4755a | 597 | |
ef8d22e6 PB |
598 | #define T2_OPCODE_MASK 0xfe1fffff |
599 | #define T2_DATA_OP_SHIFT 21 | |
600 | ||
a737bd4d NC |
601 | /* Codes to distinguish the arithmetic instructions. */ |
602 | #define OPCODE_AND 0 | |
603 | #define OPCODE_EOR 1 | |
604 | #define OPCODE_SUB 2 | |
605 | #define OPCODE_RSB 3 | |
606 | #define OPCODE_ADD 4 | |
607 | #define OPCODE_ADC 5 | |
608 | #define OPCODE_SBC 6 | |
609 | #define OPCODE_RSC 7 | |
610 | #define OPCODE_TST 8 | |
611 | #define OPCODE_TEQ 9 | |
612 | #define OPCODE_CMP 10 | |
613 | #define OPCODE_CMN 11 | |
614 | #define OPCODE_ORR 12 | |
615 | #define OPCODE_MOV 13 | |
616 | #define OPCODE_BIC 14 | |
617 | #define OPCODE_MVN 15 | |
90e4755a | 618 | |
ef8d22e6 PB |
619 | #define T2_OPCODE_AND 0 |
620 | #define T2_OPCODE_BIC 1 | |
621 | #define T2_OPCODE_ORR 2 | |
622 | #define T2_OPCODE_ORN 3 | |
623 | #define T2_OPCODE_EOR 4 | |
624 | #define T2_OPCODE_ADD 8 | |
625 | #define T2_OPCODE_ADC 10 | |
626 | #define T2_OPCODE_SBC 11 | |
627 | #define T2_OPCODE_SUB 13 | |
628 | #define T2_OPCODE_RSB 14 | |
629 | ||
a737bd4d NC |
630 | #define T_OPCODE_MUL 0x4340 |
631 | #define T_OPCODE_TST 0x4200 | |
632 | #define T_OPCODE_CMN 0x42c0 | |
633 | #define T_OPCODE_NEG 0x4240 | |
634 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 635 | |
a737bd4d NC |
636 | #define T_OPCODE_ADD_R3 0x1800 |
637 | #define T_OPCODE_SUB_R3 0x1a00 | |
638 | #define T_OPCODE_ADD_HI 0x4400 | |
639 | #define T_OPCODE_ADD_ST 0xb000 | |
640 | #define T_OPCODE_SUB_ST 0xb080 | |
641 | #define T_OPCODE_ADD_SP 0xa800 | |
642 | #define T_OPCODE_ADD_PC 0xa000 | |
643 | #define T_OPCODE_ADD_I8 0x3000 | |
644 | #define T_OPCODE_SUB_I8 0x3800 | |
645 | #define T_OPCODE_ADD_I3 0x1c00 | |
646 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 647 | |
a737bd4d NC |
648 | #define T_OPCODE_ASR_R 0x4100 |
649 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
650 | #define T_OPCODE_LSR_R 0x40c0 |
651 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
652 | #define T_OPCODE_ASR_I 0x1000 |
653 | #define T_OPCODE_LSL_I 0x0000 | |
654 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 655 | |
a737bd4d NC |
656 | #define T_OPCODE_MOV_I8 0x2000 |
657 | #define T_OPCODE_CMP_I8 0x2800 | |
658 | #define T_OPCODE_CMP_LR 0x4280 | |
659 | #define T_OPCODE_MOV_HR 0x4600 | |
660 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 661 | |
a737bd4d NC |
662 | #define T_OPCODE_LDR_PC 0x4800 |
663 | #define T_OPCODE_LDR_SP 0x9800 | |
664 | #define T_OPCODE_STR_SP 0x9000 | |
665 | #define T_OPCODE_LDR_IW 0x6800 | |
666 | #define T_OPCODE_STR_IW 0x6000 | |
667 | #define T_OPCODE_LDR_IH 0x8800 | |
668 | #define T_OPCODE_STR_IH 0x8000 | |
669 | #define T_OPCODE_LDR_IB 0x7800 | |
670 | #define T_OPCODE_STR_IB 0x7000 | |
671 | #define T_OPCODE_LDR_RW 0x5800 | |
672 | #define T_OPCODE_STR_RW 0x5000 | |
673 | #define T_OPCODE_LDR_RH 0x5a00 | |
674 | #define T_OPCODE_STR_RH 0x5200 | |
675 | #define T_OPCODE_LDR_RB 0x5c00 | |
676 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 677 | |
a737bd4d NC |
678 | #define T_OPCODE_PUSH 0xb400 |
679 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 680 | |
2fc8bdac | 681 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 682 | |
a737bd4d | 683 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 684 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 685 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 686 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
687 | |
688 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 689 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
690 | #define BAD_PC _("r15 not allowed here") |
691 | #define BAD_COND _("instruction cannot be conditional") | |
692 | #define BAD_OVERLAP _("registers may not be the same") | |
693 | #define BAD_HIREG _("lo register required") | |
694 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 695 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
696 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
697 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 698 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
699 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
700 | #define BAD_IT_COND _("incorrect condition in IT block") | |
701 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 702 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
c19d1205 | 703 | |
c921be7d NC |
704 | static struct hash_control * arm_ops_hsh; |
705 | static struct hash_control * arm_cond_hsh; | |
706 | static struct hash_control * arm_shift_hsh; | |
707 | static struct hash_control * arm_psr_hsh; | |
708 | static struct hash_control * arm_v7m_psr_hsh; | |
709 | static struct hash_control * arm_reg_hsh; | |
710 | static struct hash_control * arm_reloc_hsh; | |
711 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 712 | |
b99bd4ef NC |
713 | /* Stuff needed to resolve the label ambiguity |
714 | As: | |
715 | ... | |
716 | label: <insn> | |
717 | may differ from: | |
718 | ... | |
719 | label: | |
5f4273c7 | 720 | <insn> */ |
b99bd4ef NC |
721 | |
722 | symbolS * last_label_seen; | |
b34976b6 | 723 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 724 | |
3d0c9500 NC |
725 | /* Literal pool structure. Held on a per-section |
726 | and per-sub-section basis. */ | |
a737bd4d | 727 | |
c19d1205 | 728 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 729 | typedef struct literal_pool |
b99bd4ef | 730 | { |
c921be7d NC |
731 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
732 | unsigned int next_free_entry; | |
733 | unsigned int id; | |
734 | symbolS * symbol; | |
735 | segT section; | |
736 | subsegT sub_section; | |
737 | struct literal_pool * next; | |
3d0c9500 | 738 | } literal_pool; |
b99bd4ef | 739 | |
3d0c9500 NC |
740 | /* Pointer to a linked list of literal pools. */ |
741 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 742 | |
e07e6e58 NC |
743 | #ifdef OBJ_ELF |
744 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
745 | #else | |
746 | static struct current_it now_it; | |
747 | #endif | |
748 | ||
749 | static inline int | |
750 | now_it_compatible (int cond) | |
751 | { | |
752 | return (cond & ~1) == (now_it.cc & ~1); | |
753 | } | |
754 | ||
755 | static inline int | |
756 | conditional_insn (void) | |
757 | { | |
758 | return inst.cond != COND_ALWAYS; | |
759 | } | |
760 | ||
761 | static int in_it_block (void); | |
762 | ||
763 | static int handle_it_state (void); | |
764 | ||
765 | static void force_automatic_it_block_close (void); | |
766 | ||
c921be7d NC |
767 | static void it_fsm_post_encode (void); |
768 | ||
e07e6e58 NC |
769 | #define set_it_insn_type(type) \ |
770 | do \ | |
771 | { \ | |
772 | inst.it_insn_type = type; \ | |
773 | if (handle_it_state () == FAIL) \ | |
774 | return; \ | |
775 | } \ | |
776 | while (0) | |
777 | ||
c921be7d NC |
778 | #define set_it_insn_type_nonvoid(type, failret) \ |
779 | do \ | |
780 | { \ | |
781 | inst.it_insn_type = type; \ | |
782 | if (handle_it_state () == FAIL) \ | |
783 | return failret; \ | |
784 | } \ | |
785 | while(0) | |
786 | ||
e07e6e58 NC |
787 | #define set_it_insn_type_last() \ |
788 | do \ | |
789 | { \ | |
790 | if (inst.cond == COND_ALWAYS) \ | |
791 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ | |
792 | else \ | |
793 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ | |
794 | } \ | |
795 | while (0) | |
796 | ||
c19d1205 | 797 | /* Pure syntax. */ |
b99bd4ef | 798 | |
c19d1205 ZW |
799 | /* This array holds the chars that always start a comment. If the |
800 | pre-processor is disabled, these aren't very useful. */ | |
801 | const char comment_chars[] = "@"; | |
3d0c9500 | 802 | |
c19d1205 ZW |
803 | /* This array holds the chars that only start a comment at the beginning of |
804 | a line. If the line seems to have the form '# 123 filename' | |
805 | .line and .file directives will appear in the pre-processed output. */ | |
806 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
807 | first line of the input file. This is because the compiler outputs | |
808 | #NO_APP at the beginning of its output. */ | |
809 | /* Also note that comments like this one will always work. */ | |
810 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 811 | |
c19d1205 | 812 | const char line_separator_chars[] = ";"; |
b99bd4ef | 813 | |
c19d1205 ZW |
814 | /* Chars that can be used to separate mant |
815 | from exp in floating point numbers. */ | |
816 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 817 | |
c19d1205 ZW |
818 | /* Chars that mean this number is a floating point constant. */ |
819 | /* As in 0f12.456 */ | |
820 | /* or 0d1.2345e12 */ | |
b99bd4ef | 821 | |
c19d1205 | 822 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 823 | |
c19d1205 ZW |
824 | /* Prefix characters that indicate the start of an immediate |
825 | value. */ | |
826 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 827 | |
c19d1205 ZW |
828 | /* Separator character handling. */ |
829 | ||
830 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
831 | ||
832 | static inline int | |
833 | skip_past_char (char ** str, char c) | |
834 | { | |
835 | if (**str == c) | |
836 | { | |
837 | (*str)++; | |
838 | return SUCCESS; | |
3d0c9500 | 839 | } |
c19d1205 ZW |
840 | else |
841 | return FAIL; | |
842 | } | |
c921be7d | 843 | |
c19d1205 | 844 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 845 | |
c19d1205 ZW |
846 | /* Arithmetic expressions (possibly involving symbols). */ |
847 | ||
848 | /* Return TRUE if anything in the expression is a bignum. */ | |
849 | ||
850 | static int | |
851 | walk_no_bignums (symbolS * sp) | |
852 | { | |
853 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
854 | return 1; | |
855 | ||
856 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 857 | { |
c19d1205 ZW |
858 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
859 | || (symbol_get_value_expression (sp)->X_op_symbol | |
860 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
861 | } |
862 | ||
c19d1205 | 863 | return 0; |
3d0c9500 NC |
864 | } |
865 | ||
c19d1205 ZW |
866 | static int in_my_get_expression = 0; |
867 | ||
868 | /* Third argument to my_get_expression. */ | |
869 | #define GE_NO_PREFIX 0 | |
870 | #define GE_IMM_PREFIX 1 | |
871 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
872 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
873 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
874 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 875 | |
b99bd4ef | 876 | static int |
c19d1205 | 877 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 878 | { |
c19d1205 ZW |
879 | char * save_in; |
880 | segT seg; | |
b99bd4ef | 881 | |
c19d1205 ZW |
882 | /* In unified syntax, all prefixes are optional. */ |
883 | if (unified_syntax) | |
5287ad62 JB |
884 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
885 | : GE_OPT_PREFIX; | |
b99bd4ef | 886 | |
c19d1205 | 887 | switch (prefix_mode) |
b99bd4ef | 888 | { |
c19d1205 ZW |
889 | case GE_NO_PREFIX: break; |
890 | case GE_IMM_PREFIX: | |
891 | if (!is_immediate_prefix (**str)) | |
892 | { | |
893 | inst.error = _("immediate expression requires a # prefix"); | |
894 | return FAIL; | |
895 | } | |
896 | (*str)++; | |
897 | break; | |
898 | case GE_OPT_PREFIX: | |
5287ad62 | 899 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
900 | if (is_immediate_prefix (**str)) |
901 | (*str)++; | |
902 | break; | |
903 | default: abort (); | |
904 | } | |
b99bd4ef | 905 | |
c19d1205 | 906 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 907 | |
c19d1205 ZW |
908 | save_in = input_line_pointer; |
909 | input_line_pointer = *str; | |
910 | in_my_get_expression = 1; | |
911 | seg = expression (ep); | |
912 | in_my_get_expression = 0; | |
913 | ||
f86adc07 | 914 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 915 | { |
f86adc07 | 916 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
917 | *str = input_line_pointer; |
918 | input_line_pointer = save_in; | |
919 | if (inst.error == NULL) | |
f86adc07 NS |
920 | inst.error = (ep->X_op == O_absent |
921 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
922 | return 1; |
923 | } | |
b99bd4ef | 924 | |
c19d1205 ZW |
925 | #ifdef OBJ_AOUT |
926 | if (seg != absolute_section | |
927 | && seg != text_section | |
928 | && seg != data_section | |
929 | && seg != bss_section | |
930 | && seg != undefined_section) | |
931 | { | |
932 | inst.error = _("bad segment"); | |
933 | *str = input_line_pointer; | |
934 | input_line_pointer = save_in; | |
935 | return 1; | |
b99bd4ef | 936 | } |
c19d1205 | 937 | #endif |
b99bd4ef | 938 | |
c19d1205 ZW |
939 | /* Get rid of any bignums now, so that we don't generate an error for which |
940 | we can't establish a line number later on. Big numbers are never valid | |
941 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
942 | if (prefix_mode != GE_OPT_PREFIX_BIG |
943 | && (ep->X_op == O_big | |
944 | || (ep->X_add_symbol | |
945 | && (walk_no_bignums (ep->X_add_symbol) | |
946 | || (ep->X_op_symbol | |
947 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
948 | { |
949 | inst.error = _("invalid constant"); | |
950 | *str = input_line_pointer; | |
951 | input_line_pointer = save_in; | |
952 | return 1; | |
953 | } | |
b99bd4ef | 954 | |
c19d1205 ZW |
955 | *str = input_line_pointer; |
956 | input_line_pointer = save_in; | |
957 | return 0; | |
b99bd4ef NC |
958 | } |
959 | ||
c19d1205 ZW |
960 | /* Turn a string in input_line_pointer into a floating point constant |
961 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
962 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
963 | returned, or NULL on OK. | |
b99bd4ef | 964 | |
c19d1205 ZW |
965 | Note that fp constants aren't represent in the normal way on the ARM. |
966 | In big endian mode, things are as expected. However, in little endian | |
967 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
968 | within the words. For example, (double) 1.1 in big endian mode is | |
969 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
970 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 971 | |
c19d1205 | 972 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 973 | |
c19d1205 ZW |
974 | char * |
975 | md_atof (int type, char * litP, int * sizeP) | |
976 | { | |
977 | int prec; | |
978 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
979 | char *t; | |
980 | int i; | |
b99bd4ef | 981 | |
c19d1205 ZW |
982 | switch (type) |
983 | { | |
984 | case 'f': | |
985 | case 'F': | |
986 | case 's': | |
987 | case 'S': | |
988 | prec = 2; | |
989 | break; | |
b99bd4ef | 990 | |
c19d1205 ZW |
991 | case 'd': |
992 | case 'D': | |
993 | case 'r': | |
994 | case 'R': | |
995 | prec = 4; | |
996 | break; | |
b99bd4ef | 997 | |
c19d1205 ZW |
998 | case 'x': |
999 | case 'X': | |
499ac353 | 1000 | prec = 5; |
c19d1205 | 1001 | break; |
b99bd4ef | 1002 | |
c19d1205 ZW |
1003 | case 'p': |
1004 | case 'P': | |
499ac353 | 1005 | prec = 5; |
c19d1205 | 1006 | break; |
a737bd4d | 1007 | |
c19d1205 ZW |
1008 | default: |
1009 | *sizeP = 0; | |
499ac353 | 1010 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1011 | } |
b99bd4ef | 1012 | |
c19d1205 ZW |
1013 | t = atof_ieee (input_line_pointer, type, words); |
1014 | if (t) | |
1015 | input_line_pointer = t; | |
499ac353 | 1016 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1017 | |
c19d1205 ZW |
1018 | if (target_big_endian) |
1019 | { | |
1020 | for (i = 0; i < prec; i++) | |
1021 | { | |
499ac353 NC |
1022 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1023 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1024 | } |
1025 | } | |
1026 | else | |
1027 | { | |
e74cfd16 | 1028 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1029 | for (i = prec - 1; i >= 0; i--) |
1030 | { | |
499ac353 NC |
1031 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1032 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1033 | } |
1034 | else | |
1035 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1036 | For an 8 byte float the order is 1 0 3 2. */ | |
1037 | for (i = 0; i < prec; i += 2) | |
1038 | { | |
499ac353 NC |
1039 | md_number_to_chars (litP, (valueT) words[i + 1], |
1040 | sizeof (LITTLENUM_TYPE)); | |
1041 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1042 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1043 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1044 | } |
1045 | } | |
b99bd4ef | 1046 | |
499ac353 | 1047 | return NULL; |
c19d1205 | 1048 | } |
b99bd4ef | 1049 | |
c19d1205 ZW |
1050 | /* We handle all bad expressions here, so that we can report the faulty |
1051 | instruction in the error message. */ | |
1052 | void | |
1053 | md_operand (expressionS * expr) | |
1054 | { | |
1055 | if (in_my_get_expression) | |
1056 | expr->X_op = O_illegal; | |
b99bd4ef NC |
1057 | } |
1058 | ||
c19d1205 | 1059 | /* Immediate values. */ |
b99bd4ef | 1060 | |
c19d1205 ZW |
1061 | /* Generic immediate-value read function for use in directives. |
1062 | Accepts anything that 'expression' can fold to a constant. | |
1063 | *val receives the number. */ | |
1064 | #ifdef OBJ_ELF | |
1065 | static int | |
1066 | immediate_for_directive (int *val) | |
b99bd4ef | 1067 | { |
c19d1205 ZW |
1068 | expressionS exp; |
1069 | exp.X_op = O_illegal; | |
b99bd4ef | 1070 | |
c19d1205 ZW |
1071 | if (is_immediate_prefix (*input_line_pointer)) |
1072 | { | |
1073 | input_line_pointer++; | |
1074 | expression (&exp); | |
1075 | } | |
b99bd4ef | 1076 | |
c19d1205 ZW |
1077 | if (exp.X_op != O_constant) |
1078 | { | |
1079 | as_bad (_("expected #constant")); | |
1080 | ignore_rest_of_line (); | |
1081 | return FAIL; | |
1082 | } | |
1083 | *val = exp.X_add_number; | |
1084 | return SUCCESS; | |
b99bd4ef | 1085 | } |
c19d1205 | 1086 | #endif |
b99bd4ef | 1087 | |
c19d1205 | 1088 | /* Register parsing. */ |
b99bd4ef | 1089 | |
c19d1205 ZW |
1090 | /* Generic register parser. CCP points to what should be the |
1091 | beginning of a register name. If it is indeed a valid register | |
1092 | name, advance CCP over it and return the reg_entry structure; | |
1093 | otherwise return NULL. Does not issue diagnostics. */ | |
1094 | ||
1095 | static struct reg_entry * | |
1096 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1097 | { |
c19d1205 ZW |
1098 | char *start = *ccp; |
1099 | char *p; | |
1100 | struct reg_entry *reg; | |
b99bd4ef | 1101 | |
c19d1205 ZW |
1102 | #ifdef REGISTER_PREFIX |
1103 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1104 | return NULL; |
c19d1205 ZW |
1105 | start++; |
1106 | #endif | |
1107 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1108 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1109 | start++; | |
1110 | #endif | |
b99bd4ef | 1111 | |
c19d1205 ZW |
1112 | p = start; |
1113 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1114 | return NULL; | |
b99bd4ef | 1115 | |
c19d1205 ZW |
1116 | do |
1117 | p++; | |
1118 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1119 | ||
1120 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1121 | ||
1122 | if (!reg) | |
1123 | return NULL; | |
1124 | ||
1125 | *ccp = p; | |
1126 | return reg; | |
b99bd4ef NC |
1127 | } |
1128 | ||
1129 | static int | |
dcbf9037 JB |
1130 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1131 | enum arm_reg_type type) | |
b99bd4ef | 1132 | { |
c19d1205 ZW |
1133 | /* Alternative syntaxes are accepted for a few register classes. */ |
1134 | switch (type) | |
1135 | { | |
1136 | case REG_TYPE_MVF: | |
1137 | case REG_TYPE_MVD: | |
1138 | case REG_TYPE_MVFX: | |
1139 | case REG_TYPE_MVDX: | |
1140 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1141 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1142 | return reg->number; |
1143 | break; | |
69b97547 | 1144 | |
c19d1205 ZW |
1145 | case REG_TYPE_CP: |
1146 | /* For backward compatibility, a bare number is valid here. */ | |
1147 | { | |
1148 | unsigned long processor = strtoul (start, ccp, 10); | |
1149 | if (*ccp != start && processor <= 15) | |
1150 | return processor; | |
1151 | } | |
6057a28f | 1152 | |
c19d1205 ZW |
1153 | case REG_TYPE_MMXWC: |
1154 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1155 | instructions that take WC registers. */ | |
79134647 | 1156 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1157 | return reg->number; |
6057a28f | 1158 | break; |
c19d1205 | 1159 | |
6057a28f | 1160 | default: |
c19d1205 | 1161 | break; |
6057a28f NC |
1162 | } |
1163 | ||
dcbf9037 JB |
1164 | return FAIL; |
1165 | } | |
1166 | ||
1167 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1168 | return value is the register number or FAIL. */ | |
1169 | ||
1170 | static int | |
1171 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1172 | { | |
1173 | char *start = *ccp; | |
1174 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1175 | int ret; | |
1176 | ||
1177 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1178 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1179 | return FAIL; | |
1180 | ||
1181 | if (reg && reg->type == type) | |
1182 | return reg->number; | |
1183 | ||
1184 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1185 | return ret; | |
1186 | ||
c19d1205 ZW |
1187 | *ccp = start; |
1188 | return FAIL; | |
1189 | } | |
69b97547 | 1190 | |
dcbf9037 JB |
1191 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1192 | character. Does no verification at this stage that the type fits the opcode | |
1193 | properly. E.g., | |
1194 | ||
1195 | .i32.i32.s16 | |
1196 | .s32.f32 | |
1197 | .u16 | |
1198 | ||
1199 | Can all be legally parsed by this function. | |
1200 | ||
1201 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1202 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1203 | type, FAIL if not. */ | |
1204 | ||
1205 | static int | |
1206 | parse_neon_type (struct neon_type *type, char **str) | |
1207 | { | |
1208 | char *ptr = *str; | |
1209 | ||
1210 | if (type) | |
1211 | type->elems = 0; | |
1212 | ||
1213 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1214 | { | |
1215 | enum neon_el_type thistype = NT_untyped; | |
1216 | unsigned thissize = -1u; | |
1217 | ||
1218 | if (*ptr != '.') | |
1219 | break; | |
1220 | ||
1221 | ptr++; | |
1222 | ||
1223 | /* Just a size without an explicit type. */ | |
1224 | if (ISDIGIT (*ptr)) | |
1225 | goto parsesize; | |
1226 | ||
1227 | switch (TOLOWER (*ptr)) | |
1228 | { | |
1229 | case 'i': thistype = NT_integer; break; | |
1230 | case 'f': thistype = NT_float; break; | |
1231 | case 'p': thistype = NT_poly; break; | |
1232 | case 's': thistype = NT_signed; break; | |
1233 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1234 | case 'd': |
1235 | thistype = NT_float; | |
1236 | thissize = 64; | |
1237 | ptr++; | |
1238 | goto done; | |
dcbf9037 JB |
1239 | default: |
1240 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1241 | return FAIL; | |
1242 | } | |
1243 | ||
1244 | ptr++; | |
1245 | ||
1246 | /* .f is an abbreviation for .f32. */ | |
1247 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1248 | thissize = 32; | |
1249 | else | |
1250 | { | |
1251 | parsesize: | |
1252 | thissize = strtoul (ptr, &ptr, 10); | |
1253 | ||
1254 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1255 | && thissize != 64) | |
1256 | { | |
1257 | as_bad (_("bad size %d in type specifier"), thissize); | |
1258 | return FAIL; | |
1259 | } | |
1260 | } | |
1261 | ||
037e8744 | 1262 | done: |
dcbf9037 JB |
1263 | if (type) |
1264 | { | |
1265 | type->el[type->elems].type = thistype; | |
1266 | type->el[type->elems].size = thissize; | |
1267 | type->elems++; | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | /* Empty/missing type is not a successful parse. */ | |
1272 | if (type->elems == 0) | |
1273 | return FAIL; | |
1274 | ||
1275 | *str = ptr; | |
1276 | ||
1277 | return SUCCESS; | |
1278 | } | |
1279 | ||
1280 | /* Errors may be set multiple times during parsing or bit encoding | |
1281 | (particularly in the Neon bits), but usually the earliest error which is set | |
1282 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1283 | errors by calling this function. */ | |
1284 | ||
1285 | static void | |
1286 | first_error (const char *err) | |
1287 | { | |
1288 | if (!inst.error) | |
1289 | inst.error = err; | |
1290 | } | |
1291 | ||
1292 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1293 | static int | |
1294 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1295 | { | |
1296 | char *str = *ccp; | |
1297 | struct neon_type optype; | |
1298 | ||
1299 | if (*str == '.') | |
1300 | { | |
1301 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1302 | { | |
1303 | if (optype.elems == 1) | |
1304 | *vectype = optype.el[0]; | |
1305 | else | |
1306 | { | |
1307 | first_error (_("only one type should be specified for operand")); | |
1308 | return FAIL; | |
1309 | } | |
1310 | } | |
1311 | else | |
1312 | { | |
1313 | first_error (_("vector type expected")); | |
1314 | return FAIL; | |
1315 | } | |
1316 | } | |
1317 | else | |
1318 | return FAIL; | |
5f4273c7 | 1319 | |
dcbf9037 | 1320 | *ccp = str; |
5f4273c7 | 1321 | |
dcbf9037 JB |
1322 | return SUCCESS; |
1323 | } | |
1324 | ||
1325 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1326 | a 4-bit integer. */ | |
1327 | ||
1328 | #define NEON_ALL_LANES 15 | |
1329 | #define NEON_INTERLEAVE_LANES 14 | |
1330 | ||
1331 | /* Parse either a register or a scalar, with an optional type. Return the | |
1332 | register number, and optionally fill in the actual type of the register | |
1333 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1334 | type/index information in *TYPEINFO. */ | |
1335 | ||
1336 | static int | |
1337 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1338 | enum arm_reg_type *rtype, | |
1339 | struct neon_typed_alias *typeinfo) | |
1340 | { | |
1341 | char *str = *ccp; | |
1342 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1343 | struct neon_typed_alias atype; | |
1344 | struct neon_type_el parsetype; | |
1345 | ||
1346 | atype.defined = 0; | |
1347 | atype.index = -1; | |
1348 | atype.eltype.type = NT_invtype; | |
1349 | atype.eltype.size = -1; | |
1350 | ||
1351 | /* Try alternate syntax for some types of register. Note these are mutually | |
1352 | exclusive with the Neon syntax extensions. */ | |
1353 | if (reg == NULL) | |
1354 | { | |
1355 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1356 | if (altreg != FAIL) | |
1357 | *ccp = str; | |
1358 | if (typeinfo) | |
1359 | *typeinfo = atype; | |
1360 | return altreg; | |
1361 | } | |
1362 | ||
037e8744 JB |
1363 | /* Undo polymorphism when a set of register types may be accepted. */ |
1364 | if ((type == REG_TYPE_NDQ | |
1365 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1366 | || (type == REG_TYPE_VFSD | |
1367 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1368 | || (type == REG_TYPE_NSDQ | |
1369 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
f512f76f NC |
1370 | || reg->type == REG_TYPE_NQ)) |
1371 | || (type == REG_TYPE_MMXWC | |
1372 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1373 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1374 | |
1375 | if (type != reg->type) | |
1376 | return FAIL; | |
1377 | ||
1378 | if (reg->neon) | |
1379 | atype = *reg->neon; | |
5f4273c7 | 1380 | |
dcbf9037 JB |
1381 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1382 | { | |
1383 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1384 | { | |
1385 | first_error (_("can't redefine type for operand")); | |
1386 | return FAIL; | |
1387 | } | |
1388 | atype.defined |= NTA_HASTYPE; | |
1389 | atype.eltype = parsetype; | |
1390 | } | |
5f4273c7 | 1391 | |
dcbf9037 JB |
1392 | if (skip_past_char (&str, '[') == SUCCESS) |
1393 | { | |
1394 | if (type != REG_TYPE_VFD) | |
1395 | { | |
1396 | first_error (_("only D registers may be indexed")); | |
1397 | return FAIL; | |
1398 | } | |
5f4273c7 | 1399 | |
dcbf9037 JB |
1400 | if ((atype.defined & NTA_HASINDEX) != 0) |
1401 | { | |
1402 | first_error (_("can't change index for operand")); | |
1403 | return FAIL; | |
1404 | } | |
1405 | ||
1406 | atype.defined |= NTA_HASINDEX; | |
1407 | ||
1408 | if (skip_past_char (&str, ']') == SUCCESS) | |
1409 | atype.index = NEON_ALL_LANES; | |
1410 | else | |
1411 | { | |
1412 | expressionS exp; | |
1413 | ||
1414 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1415 | ||
1416 | if (exp.X_op != O_constant) | |
1417 | { | |
1418 | first_error (_("constant expression required")); | |
1419 | return FAIL; | |
1420 | } | |
1421 | ||
1422 | if (skip_past_char (&str, ']') == FAIL) | |
1423 | return FAIL; | |
1424 | ||
1425 | atype.index = exp.X_add_number; | |
1426 | } | |
1427 | } | |
5f4273c7 | 1428 | |
dcbf9037 JB |
1429 | if (typeinfo) |
1430 | *typeinfo = atype; | |
5f4273c7 | 1431 | |
dcbf9037 JB |
1432 | if (rtype) |
1433 | *rtype = type; | |
5f4273c7 | 1434 | |
dcbf9037 | 1435 | *ccp = str; |
5f4273c7 | 1436 | |
dcbf9037 JB |
1437 | return reg->number; |
1438 | } | |
1439 | ||
1440 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1441 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1442 | register (e.g. Neon double or quad reg when either has been requested). | |
1443 | - If this is a Neon vector type with additional type information, fill | |
1444 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1445 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1446 | |
1447 | static int | |
1448 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1449 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1450 | { | |
1451 | struct neon_typed_alias atype; | |
1452 | char *str = *ccp; | |
1453 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1454 | ||
1455 | if (reg == FAIL) | |
1456 | return FAIL; | |
1457 | ||
1458 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1459 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1460 | { | |
1461 | first_error (_("register operand expected, but got scalar")); | |
1462 | return FAIL; | |
1463 | } | |
1464 | ||
1465 | if (vectype) | |
1466 | *vectype = atype.eltype; | |
1467 | ||
1468 | *ccp = str; | |
1469 | ||
1470 | return reg; | |
1471 | } | |
1472 | ||
1473 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1474 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1475 | ||
5287ad62 JB |
1476 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1477 | have enough information to be able to do a good job bounds-checking. So, we | |
1478 | just do easy checks here, and do further checks later. */ | |
1479 | ||
1480 | static int | |
dcbf9037 | 1481 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1482 | { |
dcbf9037 | 1483 | int reg; |
5287ad62 | 1484 | char *str = *ccp; |
dcbf9037 | 1485 | struct neon_typed_alias atype; |
5f4273c7 | 1486 | |
dcbf9037 | 1487 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1488 | |
dcbf9037 | 1489 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1490 | return FAIL; |
5f4273c7 | 1491 | |
dcbf9037 | 1492 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1493 | { |
dcbf9037 | 1494 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1495 | return FAIL; |
1496 | } | |
dcbf9037 | 1497 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1498 | { |
dcbf9037 | 1499 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1500 | return FAIL; |
1501 | } | |
5f4273c7 | 1502 | |
dcbf9037 JB |
1503 | if (type) |
1504 | *type = atype.eltype; | |
5f4273c7 | 1505 | |
5287ad62 | 1506 | *ccp = str; |
5f4273c7 | 1507 | |
dcbf9037 | 1508 | return reg * 16 + atype.index; |
5287ad62 JB |
1509 | } |
1510 | ||
c19d1205 | 1511 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1512 | |
c19d1205 ZW |
1513 | static long |
1514 | parse_reg_list (char ** strp) | |
1515 | { | |
1516 | char * str = * strp; | |
1517 | long range = 0; | |
1518 | int another_range; | |
a737bd4d | 1519 | |
c19d1205 ZW |
1520 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1521 | do | |
6057a28f | 1522 | { |
c19d1205 | 1523 | another_range = 0; |
a737bd4d | 1524 | |
c19d1205 ZW |
1525 | if (*str == '{') |
1526 | { | |
1527 | int in_range = 0; | |
1528 | int cur_reg = -1; | |
a737bd4d | 1529 | |
c19d1205 ZW |
1530 | str++; |
1531 | do | |
1532 | { | |
1533 | int reg; | |
6057a28f | 1534 | |
dcbf9037 | 1535 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1536 | { |
dcbf9037 | 1537 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1538 | return FAIL; |
1539 | } | |
a737bd4d | 1540 | |
c19d1205 ZW |
1541 | if (in_range) |
1542 | { | |
1543 | int i; | |
a737bd4d | 1544 | |
c19d1205 ZW |
1545 | if (reg <= cur_reg) |
1546 | { | |
dcbf9037 | 1547 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1548 | return FAIL; |
1549 | } | |
40a18ebd | 1550 | |
c19d1205 ZW |
1551 | for (i = cur_reg + 1; i < reg; i++) |
1552 | { | |
1553 | if (range & (1 << i)) | |
1554 | as_tsktsk | |
1555 | (_("Warning: duplicated register (r%d) in register list"), | |
1556 | i); | |
1557 | else | |
1558 | range |= 1 << i; | |
1559 | } | |
1560 | in_range = 0; | |
1561 | } | |
a737bd4d | 1562 | |
c19d1205 ZW |
1563 | if (range & (1 << reg)) |
1564 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1565 | reg); | |
1566 | else if (reg <= cur_reg) | |
1567 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1568 | |
c19d1205 ZW |
1569 | range |= 1 << reg; |
1570 | cur_reg = reg; | |
1571 | } | |
1572 | while (skip_past_comma (&str) != FAIL | |
1573 | || (in_range = 1, *str++ == '-')); | |
1574 | str--; | |
a737bd4d | 1575 | |
c19d1205 ZW |
1576 | if (*str++ != '}') |
1577 | { | |
dcbf9037 | 1578 | first_error (_("missing `}'")); |
c19d1205 ZW |
1579 | return FAIL; |
1580 | } | |
1581 | } | |
1582 | else | |
1583 | { | |
1584 | expressionS expr; | |
40a18ebd | 1585 | |
c19d1205 ZW |
1586 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1587 | return FAIL; | |
40a18ebd | 1588 | |
c19d1205 ZW |
1589 | if (expr.X_op == O_constant) |
1590 | { | |
1591 | if (expr.X_add_number | |
1592 | != (expr.X_add_number & 0x0000ffff)) | |
1593 | { | |
1594 | inst.error = _("invalid register mask"); | |
1595 | return FAIL; | |
1596 | } | |
a737bd4d | 1597 | |
c19d1205 ZW |
1598 | if ((range & expr.X_add_number) != 0) |
1599 | { | |
1600 | int regno = range & expr.X_add_number; | |
a737bd4d | 1601 | |
c19d1205 ZW |
1602 | regno &= -regno; |
1603 | regno = (1 << regno) - 1; | |
1604 | as_tsktsk | |
1605 | (_("Warning: duplicated register (r%d) in register list"), | |
1606 | regno); | |
1607 | } | |
a737bd4d | 1608 | |
c19d1205 ZW |
1609 | range |= expr.X_add_number; |
1610 | } | |
1611 | else | |
1612 | { | |
1613 | if (inst.reloc.type != 0) | |
1614 | { | |
1615 | inst.error = _("expression too complex"); | |
1616 | return FAIL; | |
1617 | } | |
a737bd4d | 1618 | |
c19d1205 ZW |
1619 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1620 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1621 | inst.reloc.pc_rel = 0; | |
1622 | } | |
1623 | } | |
a737bd4d | 1624 | |
c19d1205 ZW |
1625 | if (*str == '|' || *str == '+') |
1626 | { | |
1627 | str++; | |
1628 | another_range = 1; | |
1629 | } | |
a737bd4d | 1630 | } |
c19d1205 | 1631 | while (another_range); |
a737bd4d | 1632 | |
c19d1205 ZW |
1633 | *strp = str; |
1634 | return range; | |
a737bd4d NC |
1635 | } |
1636 | ||
5287ad62 JB |
1637 | /* Types of registers in a list. */ |
1638 | ||
1639 | enum reg_list_els | |
1640 | { | |
1641 | REGLIST_VFP_S, | |
1642 | REGLIST_VFP_D, | |
1643 | REGLIST_NEON_D | |
1644 | }; | |
1645 | ||
c19d1205 ZW |
1646 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1647 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1648 | register. Parses registers of type ETYPE. |
1649 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1650 | - Q registers can be used to specify pairs of D registers | |
1651 | - { } can be omitted from around a singleton register list | |
1652 | FIXME: This is not implemented, as it would require backtracking in | |
1653 | some cases, e.g.: | |
1654 | vtbl.8 d3,d4,d5 | |
1655 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1656 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1657 | - 32 D registers may be used (also true for VFPv3). |
1658 | FIXME: Types are ignored in these register lists, which is probably a | |
1659 | bug. */ | |
6057a28f | 1660 | |
c19d1205 | 1661 | static int |
037e8744 | 1662 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1663 | { |
037e8744 | 1664 | char *str = *ccp; |
c19d1205 ZW |
1665 | int base_reg; |
1666 | int new_base; | |
21d799b5 | 1667 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1668 | int max_regs = 0; |
c19d1205 ZW |
1669 | int count = 0; |
1670 | int warned = 0; | |
1671 | unsigned long mask = 0; | |
a737bd4d | 1672 | int i; |
6057a28f | 1673 | |
037e8744 | 1674 | if (*str != '{') |
5287ad62 JB |
1675 | { |
1676 | inst.error = _("expecting {"); | |
1677 | return FAIL; | |
1678 | } | |
6057a28f | 1679 | |
037e8744 | 1680 | str++; |
6057a28f | 1681 | |
5287ad62 | 1682 | switch (etype) |
c19d1205 | 1683 | { |
5287ad62 | 1684 | case REGLIST_VFP_S: |
c19d1205 ZW |
1685 | regtype = REG_TYPE_VFS; |
1686 | max_regs = 32; | |
5287ad62 | 1687 | break; |
5f4273c7 | 1688 | |
5287ad62 JB |
1689 | case REGLIST_VFP_D: |
1690 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1691 | break; |
5f4273c7 | 1692 | |
b7fc2769 JB |
1693 | case REGLIST_NEON_D: |
1694 | regtype = REG_TYPE_NDQ; | |
1695 | break; | |
1696 | } | |
1697 | ||
1698 | if (etype != REGLIST_VFP_S) | |
1699 | { | |
b1cc4aeb PB |
1700 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1701 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
5287ad62 JB |
1702 | { |
1703 | max_regs = 32; | |
1704 | if (thumb_mode) | |
1705 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 1706 | fpu_vfp_ext_d32); |
5287ad62 JB |
1707 | else |
1708 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 1709 | fpu_vfp_ext_d32); |
5287ad62 JB |
1710 | } |
1711 | else | |
1712 | max_regs = 16; | |
c19d1205 | 1713 | } |
6057a28f | 1714 | |
c19d1205 | 1715 | base_reg = max_regs; |
a737bd4d | 1716 | |
c19d1205 ZW |
1717 | do |
1718 | { | |
5287ad62 | 1719 | int setmask = 1, addregs = 1; |
dcbf9037 | 1720 | |
037e8744 | 1721 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1722 | |
c19d1205 | 1723 | if (new_base == FAIL) |
a737bd4d | 1724 | { |
dcbf9037 | 1725 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1726 | return FAIL; |
1727 | } | |
5f4273c7 | 1728 | |
b7fc2769 JB |
1729 | if (new_base >= max_regs) |
1730 | { | |
1731 | first_error (_("register out of range in list")); | |
1732 | return FAIL; | |
1733 | } | |
5f4273c7 | 1734 | |
5287ad62 JB |
1735 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1736 | if (regtype == REG_TYPE_NQ) | |
1737 | { | |
1738 | setmask = 3; | |
1739 | addregs = 2; | |
1740 | } | |
1741 | ||
c19d1205 ZW |
1742 | if (new_base < base_reg) |
1743 | base_reg = new_base; | |
a737bd4d | 1744 | |
5287ad62 | 1745 | if (mask & (setmask << new_base)) |
c19d1205 | 1746 | { |
dcbf9037 | 1747 | first_error (_("invalid register list")); |
c19d1205 | 1748 | return FAIL; |
a737bd4d | 1749 | } |
a737bd4d | 1750 | |
c19d1205 ZW |
1751 | if ((mask >> new_base) != 0 && ! warned) |
1752 | { | |
1753 | as_tsktsk (_("register list not in ascending order")); | |
1754 | warned = 1; | |
1755 | } | |
0bbf2aa4 | 1756 | |
5287ad62 JB |
1757 | mask |= setmask << new_base; |
1758 | count += addregs; | |
0bbf2aa4 | 1759 | |
037e8744 | 1760 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1761 | { |
1762 | int high_range; | |
0bbf2aa4 | 1763 | |
037e8744 | 1764 | str++; |
0bbf2aa4 | 1765 | |
037e8744 | 1766 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1767 | == FAIL) |
c19d1205 ZW |
1768 | { |
1769 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1770 | return FAIL; | |
1771 | } | |
0bbf2aa4 | 1772 | |
b7fc2769 JB |
1773 | if (high_range >= max_regs) |
1774 | { | |
1775 | first_error (_("register out of range in list")); | |
1776 | return FAIL; | |
1777 | } | |
1778 | ||
5287ad62 JB |
1779 | if (regtype == REG_TYPE_NQ) |
1780 | high_range = high_range + 1; | |
1781 | ||
c19d1205 ZW |
1782 | if (high_range <= new_base) |
1783 | { | |
1784 | inst.error = _("register range not in ascending order"); | |
1785 | return FAIL; | |
1786 | } | |
0bbf2aa4 | 1787 | |
5287ad62 | 1788 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1789 | { |
5287ad62 | 1790 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1791 | { |
c19d1205 ZW |
1792 | inst.error = _("invalid register list"); |
1793 | return FAIL; | |
0bbf2aa4 | 1794 | } |
c19d1205 | 1795 | |
5287ad62 JB |
1796 | mask |= setmask << new_base; |
1797 | count += addregs; | |
0bbf2aa4 | 1798 | } |
0bbf2aa4 | 1799 | } |
0bbf2aa4 | 1800 | } |
037e8744 | 1801 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1802 | |
037e8744 | 1803 | str++; |
0bbf2aa4 | 1804 | |
c19d1205 ZW |
1805 | /* Sanity check -- should have raised a parse error above. */ |
1806 | if (count == 0 || count > max_regs) | |
1807 | abort (); | |
1808 | ||
1809 | *pbase = base_reg; | |
1810 | ||
1811 | /* Final test -- the registers must be consecutive. */ | |
1812 | mask >>= base_reg; | |
1813 | for (i = 0; i < count; i++) | |
1814 | { | |
1815 | if ((mask & (1u << i)) == 0) | |
1816 | { | |
1817 | inst.error = _("non-contiguous register range"); | |
1818 | return FAIL; | |
1819 | } | |
1820 | } | |
1821 | ||
037e8744 JB |
1822 | *ccp = str; |
1823 | ||
c19d1205 | 1824 | return count; |
b99bd4ef NC |
1825 | } |
1826 | ||
dcbf9037 JB |
1827 | /* True if two alias types are the same. */ |
1828 | ||
c921be7d | 1829 | static bfd_boolean |
dcbf9037 JB |
1830 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1831 | { | |
1832 | if (!a && !b) | |
c921be7d | 1833 | return TRUE; |
5f4273c7 | 1834 | |
dcbf9037 | 1835 | if (!a || !b) |
c921be7d | 1836 | return FALSE; |
dcbf9037 JB |
1837 | |
1838 | if (a->defined != b->defined) | |
c921be7d | 1839 | return FALSE; |
5f4273c7 | 1840 | |
dcbf9037 JB |
1841 | if ((a->defined & NTA_HASTYPE) != 0 |
1842 | && (a->eltype.type != b->eltype.type | |
1843 | || a->eltype.size != b->eltype.size)) | |
c921be7d | 1844 | return FALSE; |
dcbf9037 JB |
1845 | |
1846 | if ((a->defined & NTA_HASINDEX) != 0 | |
1847 | && (a->index != b->index)) | |
c921be7d | 1848 | return FALSE; |
5f4273c7 | 1849 | |
c921be7d | 1850 | return TRUE; |
dcbf9037 JB |
1851 | } |
1852 | ||
5287ad62 JB |
1853 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1854 | The base register is put in *PBASE. | |
dcbf9037 | 1855 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1856 | the return value. |
1857 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1858 | Bits [6:5] encode the list length (minus one). |
1859 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1860 | |
5287ad62 | 1861 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1862 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1863 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1864 | ||
1865 | static int | |
dcbf9037 JB |
1866 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1867 | struct neon_type_el *eltype) | |
5287ad62 JB |
1868 | { |
1869 | char *ptr = *str; | |
1870 | int base_reg = -1; | |
1871 | int reg_incr = -1; | |
1872 | int count = 0; | |
1873 | int lane = -1; | |
1874 | int leading_brace = 0; | |
1875 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
1876 | int addregs = 1; | |
20203fb9 NC |
1877 | const char *const incr_error = _("register stride must be 1 or 2"); |
1878 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 1879 | struct neon_typed_alias firsttype; |
5f4273c7 | 1880 | |
5287ad62 JB |
1881 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1882 | leading_brace = 1; | |
5f4273c7 | 1883 | |
5287ad62 JB |
1884 | do |
1885 | { | |
dcbf9037 JB |
1886 | struct neon_typed_alias atype; |
1887 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1888 | ||
5287ad62 JB |
1889 | if (getreg == FAIL) |
1890 | { | |
dcbf9037 | 1891 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1892 | return FAIL; |
1893 | } | |
5f4273c7 | 1894 | |
5287ad62 JB |
1895 | if (base_reg == -1) |
1896 | { | |
1897 | base_reg = getreg; | |
1898 | if (rtype == REG_TYPE_NQ) | |
1899 | { | |
1900 | reg_incr = 1; | |
1901 | addregs = 2; | |
1902 | } | |
dcbf9037 | 1903 | firsttype = atype; |
5287ad62 JB |
1904 | } |
1905 | else if (reg_incr == -1) | |
1906 | { | |
1907 | reg_incr = getreg - base_reg; | |
1908 | if (reg_incr < 1 || reg_incr > 2) | |
1909 | { | |
dcbf9037 | 1910 | first_error (_(incr_error)); |
5287ad62 JB |
1911 | return FAIL; |
1912 | } | |
1913 | } | |
1914 | else if (getreg != base_reg + reg_incr * count) | |
1915 | { | |
dcbf9037 JB |
1916 | first_error (_(incr_error)); |
1917 | return FAIL; | |
1918 | } | |
1919 | ||
c921be7d | 1920 | if (! neon_alias_types_same (&atype, &firsttype)) |
dcbf9037 JB |
1921 | { |
1922 | first_error (_(type_error)); | |
5287ad62 JB |
1923 | return FAIL; |
1924 | } | |
5f4273c7 | 1925 | |
5287ad62 JB |
1926 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
1927 | modes. */ | |
1928 | if (ptr[0] == '-') | |
1929 | { | |
dcbf9037 | 1930 | struct neon_typed_alias htype; |
5287ad62 JB |
1931 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1932 | if (lane == -1) | |
1933 | lane = NEON_INTERLEAVE_LANES; | |
1934 | else if (lane != NEON_INTERLEAVE_LANES) | |
1935 | { | |
dcbf9037 | 1936 | first_error (_(type_error)); |
5287ad62 JB |
1937 | return FAIL; |
1938 | } | |
1939 | if (reg_incr == -1) | |
1940 | reg_incr = 1; | |
1941 | else if (reg_incr != 1) | |
1942 | { | |
dcbf9037 | 1943 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
1944 | return FAIL; |
1945 | } | |
1946 | ptr++; | |
dcbf9037 | 1947 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
1948 | if (hireg == FAIL) |
1949 | { | |
dcbf9037 JB |
1950 | first_error (_(reg_expected_msgs[rtype])); |
1951 | return FAIL; | |
1952 | } | |
c921be7d | 1953 | if (! neon_alias_types_same (&htype, &firsttype)) |
dcbf9037 JB |
1954 | { |
1955 | first_error (_(type_error)); | |
5287ad62 JB |
1956 | return FAIL; |
1957 | } | |
1958 | count += hireg + dregs - getreg; | |
1959 | continue; | |
1960 | } | |
5f4273c7 | 1961 | |
5287ad62 JB |
1962 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
1963 | if (rtype == REG_TYPE_NQ) | |
1964 | { | |
1965 | count += 2; | |
1966 | continue; | |
1967 | } | |
5f4273c7 | 1968 | |
dcbf9037 | 1969 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 1970 | { |
dcbf9037 JB |
1971 | if (lane == -1) |
1972 | lane = atype.index; | |
1973 | else if (lane != atype.index) | |
5287ad62 | 1974 | { |
dcbf9037 JB |
1975 | first_error (_(type_error)); |
1976 | return FAIL; | |
5287ad62 JB |
1977 | } |
1978 | } | |
1979 | else if (lane == -1) | |
1980 | lane = NEON_INTERLEAVE_LANES; | |
1981 | else if (lane != NEON_INTERLEAVE_LANES) | |
1982 | { | |
dcbf9037 | 1983 | first_error (_(type_error)); |
5287ad62 JB |
1984 | return FAIL; |
1985 | } | |
1986 | count++; | |
1987 | } | |
1988 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 1989 | |
5287ad62 JB |
1990 | /* No lane set by [x]. We must be interleaving structures. */ |
1991 | if (lane == -1) | |
1992 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 1993 | |
5287ad62 JB |
1994 | /* Sanity check. */ |
1995 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
1996 | || (count > 1 && reg_incr == -1)) | |
1997 | { | |
dcbf9037 | 1998 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
1999 | return FAIL; |
2000 | } | |
2001 | ||
2002 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2003 | { | |
dcbf9037 | 2004 | first_error (_("expected }")); |
5287ad62 JB |
2005 | return FAIL; |
2006 | } | |
5f4273c7 | 2007 | |
5287ad62 JB |
2008 | if (reg_incr == -1) |
2009 | reg_incr = 1; | |
2010 | ||
dcbf9037 JB |
2011 | if (eltype) |
2012 | *eltype = firsttype.eltype; | |
2013 | ||
5287ad62 JB |
2014 | *pbase = base_reg; |
2015 | *str = ptr; | |
5f4273c7 | 2016 | |
5287ad62 JB |
2017 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2018 | } | |
2019 | ||
c19d1205 ZW |
2020 | /* Parse an explicit relocation suffix on an expression. This is |
2021 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2022 | arm_reloc_hsh contains no entries, so this function can only | |
2023 | succeed if there is no () after the word. Returns -1 on error, | |
2024 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
2025 | static int | |
2026 | parse_reloc (char **str) | |
b99bd4ef | 2027 | { |
c19d1205 ZW |
2028 | struct reloc_entry *r; |
2029 | char *p, *q; | |
b99bd4ef | 2030 | |
c19d1205 ZW |
2031 | if (**str != '(') |
2032 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2033 | |
c19d1205 ZW |
2034 | p = *str + 1; |
2035 | q = p; | |
2036 | ||
2037 | while (*q && *q != ')' && *q != ',') | |
2038 | q++; | |
2039 | if (*q != ')') | |
2040 | return -1; | |
2041 | ||
21d799b5 NC |
2042 | if ((r = (struct reloc_entry *) |
2043 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2044 | return -1; |
2045 | ||
2046 | *str = q + 1; | |
2047 | return r->reloc; | |
b99bd4ef NC |
2048 | } |
2049 | ||
c19d1205 ZW |
2050 | /* Directives: register aliases. */ |
2051 | ||
dcbf9037 | 2052 | static struct reg_entry * |
c19d1205 | 2053 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 2054 | { |
d3ce72d0 | 2055 | struct reg_entry *new_reg; |
c19d1205 | 2056 | const char *name; |
b99bd4ef | 2057 | |
d3ce72d0 | 2058 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2059 | { |
d3ce72d0 | 2060 | if (new_reg->builtin) |
c19d1205 | 2061 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2062 | |
c19d1205 ZW |
2063 | /* Only warn about a redefinition if it's not defined as the |
2064 | same register. */ | |
d3ce72d0 | 2065 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2066 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2067 | |
d929913e | 2068 | return NULL; |
c19d1205 | 2069 | } |
b99bd4ef | 2070 | |
c19d1205 | 2071 | name = xstrdup (str); |
d3ce72d0 | 2072 | new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry)); |
b99bd4ef | 2073 | |
d3ce72d0 NC |
2074 | new_reg->name = name; |
2075 | new_reg->number = number; | |
2076 | new_reg->type = type; | |
2077 | new_reg->builtin = FALSE; | |
2078 | new_reg->neon = NULL; | |
b99bd4ef | 2079 | |
d3ce72d0 | 2080 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2081 | abort (); |
5f4273c7 | 2082 | |
d3ce72d0 | 2083 | return new_reg; |
dcbf9037 JB |
2084 | } |
2085 | ||
2086 | static void | |
2087 | insert_neon_reg_alias (char *str, int number, int type, | |
2088 | struct neon_typed_alias *atype) | |
2089 | { | |
2090 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2091 | |
dcbf9037 JB |
2092 | if (!reg) |
2093 | { | |
2094 | first_error (_("attempt to redefine typed alias")); | |
2095 | return; | |
2096 | } | |
5f4273c7 | 2097 | |
dcbf9037 JB |
2098 | if (atype) |
2099 | { | |
21d799b5 NC |
2100 | reg->neon = (struct neon_typed_alias *) |
2101 | xmalloc (sizeof (struct neon_typed_alias)); | |
dcbf9037 JB |
2102 | *reg->neon = *atype; |
2103 | } | |
c19d1205 | 2104 | } |
b99bd4ef | 2105 | |
c19d1205 | 2106 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2107 | |
c19d1205 | 2108 | new_register_name .req existing_register_name |
b99bd4ef | 2109 | |
c19d1205 | 2110 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2111 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2112 | |
d929913e | 2113 | static bfd_boolean |
c19d1205 ZW |
2114 | create_register_alias (char * newname, char *p) |
2115 | { | |
2116 | struct reg_entry *old; | |
2117 | char *oldname, *nbuf; | |
2118 | size_t nlen; | |
b99bd4ef | 2119 | |
c19d1205 ZW |
2120 | /* The input scrubber ensures that whitespace after the mnemonic is |
2121 | collapsed to single spaces. */ | |
2122 | oldname = p; | |
2123 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2124 | return FALSE; |
b99bd4ef | 2125 | |
c19d1205 ZW |
2126 | oldname += 6; |
2127 | if (*oldname == '\0') | |
d929913e | 2128 | return FALSE; |
b99bd4ef | 2129 | |
21d799b5 | 2130 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2131 | if (!old) |
b99bd4ef | 2132 | { |
c19d1205 | 2133 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2134 | return TRUE; |
b99bd4ef NC |
2135 | } |
2136 | ||
c19d1205 ZW |
2137 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2138 | the desired alias name, and p points to its end. If not, then | |
2139 | the desired alias name is in the global original_case_string. */ | |
2140 | #ifdef TC_CASE_SENSITIVE | |
2141 | nlen = p - newname; | |
2142 | #else | |
2143 | newname = original_case_string; | |
2144 | nlen = strlen (newname); | |
2145 | #endif | |
b99bd4ef | 2146 | |
21d799b5 | 2147 | nbuf = (char *) alloca (nlen + 1); |
c19d1205 ZW |
2148 | memcpy (nbuf, newname, nlen); |
2149 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2150 | |
c19d1205 ZW |
2151 | /* Create aliases under the new name as stated; an all-lowercase |
2152 | version of the new name; and an all-uppercase version of the new | |
2153 | name. */ | |
d929913e NC |
2154 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2155 | { | |
2156 | for (p = nbuf; *p; p++) | |
2157 | *p = TOUPPER (*p); | |
c19d1205 | 2158 | |
d929913e NC |
2159 | if (strncmp (nbuf, newname, nlen)) |
2160 | { | |
2161 | /* If this attempt to create an additional alias fails, do not bother | |
2162 | trying to create the all-lower case alias. We will fail and issue | |
2163 | a second, duplicate error message. This situation arises when the | |
2164 | programmer does something like: | |
2165 | foo .req r0 | |
2166 | Foo .req r1 | |
2167 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2168 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2169 | first .req. */ |
2170 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
2171 | return TRUE; | |
2172 | } | |
c19d1205 | 2173 | |
d929913e NC |
2174 | for (p = nbuf; *p; p++) |
2175 | *p = TOLOWER (*p); | |
c19d1205 | 2176 | |
d929913e NC |
2177 | if (strncmp (nbuf, newname, nlen)) |
2178 | insert_reg_alias (nbuf, old->number, old->type); | |
2179 | } | |
c19d1205 | 2180 | |
d929913e | 2181 | return TRUE; |
b99bd4ef NC |
2182 | } |
2183 | ||
dcbf9037 JB |
2184 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2185 | X .dn d5.s32[1] | |
2186 | Y .qn 6.s16 | |
2187 | Z .dn d7 | |
2188 | T .dn Z[0] | |
2189 | These typed registers can be used instead of the types specified after the | |
2190 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2191 | specified directly, e.g.: | |
5f4273c7 | 2192 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2193 | |
c921be7d | 2194 | static bfd_boolean |
dcbf9037 JB |
2195 | create_neon_reg_alias (char *newname, char *p) |
2196 | { | |
2197 | enum arm_reg_type basetype; | |
2198 | struct reg_entry *basereg; | |
2199 | struct reg_entry mybasereg; | |
2200 | struct neon_type ntype; | |
2201 | struct neon_typed_alias typeinfo; | |
2202 | char *namebuf, *nameend; | |
2203 | int namelen; | |
5f4273c7 | 2204 | |
dcbf9037 JB |
2205 | typeinfo.defined = 0; |
2206 | typeinfo.eltype.type = NT_invtype; | |
2207 | typeinfo.eltype.size = -1; | |
2208 | typeinfo.index = -1; | |
5f4273c7 | 2209 | |
dcbf9037 | 2210 | nameend = p; |
5f4273c7 | 2211 | |
dcbf9037 JB |
2212 | if (strncmp (p, " .dn ", 5) == 0) |
2213 | basetype = REG_TYPE_VFD; | |
2214 | else if (strncmp (p, " .qn ", 5) == 0) | |
2215 | basetype = REG_TYPE_NQ; | |
2216 | else | |
c921be7d | 2217 | return FALSE; |
5f4273c7 | 2218 | |
dcbf9037 | 2219 | p += 5; |
5f4273c7 | 2220 | |
dcbf9037 | 2221 | if (*p == '\0') |
c921be7d | 2222 | return FALSE; |
5f4273c7 | 2223 | |
dcbf9037 JB |
2224 | basereg = arm_reg_parse_multi (&p); |
2225 | ||
2226 | if (basereg && basereg->type != basetype) | |
2227 | { | |
2228 | as_bad (_("bad type for register")); | |
c921be7d | 2229 | return FALSE; |
dcbf9037 JB |
2230 | } |
2231 | ||
2232 | if (basereg == NULL) | |
2233 | { | |
2234 | expressionS exp; | |
2235 | /* Try parsing as an integer. */ | |
2236 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2237 | if (exp.X_op != O_constant) | |
2238 | { | |
2239 | as_bad (_("expression must be constant")); | |
c921be7d | 2240 | return FALSE; |
dcbf9037 JB |
2241 | } |
2242 | basereg = &mybasereg; | |
2243 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2244 | : exp.X_add_number; | |
2245 | basereg->neon = 0; | |
2246 | } | |
2247 | ||
2248 | if (basereg->neon) | |
2249 | typeinfo = *basereg->neon; | |
2250 | ||
2251 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2252 | { | |
2253 | /* We got a type. */ | |
2254 | if (typeinfo.defined & NTA_HASTYPE) | |
2255 | { | |
2256 | as_bad (_("can't redefine the type of a register alias")); | |
c921be7d | 2257 | return FALSE; |
dcbf9037 | 2258 | } |
5f4273c7 | 2259 | |
dcbf9037 JB |
2260 | typeinfo.defined |= NTA_HASTYPE; |
2261 | if (ntype.elems != 1) | |
2262 | { | |
2263 | as_bad (_("you must specify a single type only")); | |
c921be7d | 2264 | return FALSE; |
dcbf9037 JB |
2265 | } |
2266 | typeinfo.eltype = ntype.el[0]; | |
2267 | } | |
5f4273c7 | 2268 | |
dcbf9037 JB |
2269 | if (skip_past_char (&p, '[') == SUCCESS) |
2270 | { | |
2271 | expressionS exp; | |
2272 | /* We got a scalar index. */ | |
5f4273c7 | 2273 | |
dcbf9037 JB |
2274 | if (typeinfo.defined & NTA_HASINDEX) |
2275 | { | |
2276 | as_bad (_("can't redefine the index of a scalar alias")); | |
c921be7d | 2277 | return FALSE; |
dcbf9037 | 2278 | } |
5f4273c7 | 2279 | |
dcbf9037 | 2280 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2281 | |
dcbf9037 JB |
2282 | if (exp.X_op != O_constant) |
2283 | { | |
2284 | as_bad (_("scalar index must be constant")); | |
c921be7d | 2285 | return FALSE; |
dcbf9037 | 2286 | } |
5f4273c7 | 2287 | |
dcbf9037 JB |
2288 | typeinfo.defined |= NTA_HASINDEX; |
2289 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2290 | |
dcbf9037 JB |
2291 | if (skip_past_char (&p, ']') == FAIL) |
2292 | { | |
2293 | as_bad (_("expecting ]")); | |
c921be7d | 2294 | return FALSE; |
dcbf9037 JB |
2295 | } |
2296 | } | |
2297 | ||
2298 | namelen = nameend - newname; | |
21d799b5 | 2299 | namebuf = (char *) alloca (namelen + 1); |
dcbf9037 JB |
2300 | strncpy (namebuf, newname, namelen); |
2301 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2302 | |
dcbf9037 JB |
2303 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
2304 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2305 | |
dcbf9037 JB |
2306 | /* Insert name in all uppercase. */ |
2307 | for (p = namebuf; *p; p++) | |
2308 | *p = TOUPPER (*p); | |
5f4273c7 | 2309 | |
dcbf9037 JB |
2310 | if (strncmp (namebuf, newname, namelen)) |
2311 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2312 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2313 | |
dcbf9037 JB |
2314 | /* Insert name in all lowercase. */ |
2315 | for (p = namebuf; *p; p++) | |
2316 | *p = TOLOWER (*p); | |
5f4273c7 | 2317 | |
dcbf9037 JB |
2318 | if (strncmp (namebuf, newname, namelen)) |
2319 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2320 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2321 | |
c921be7d | 2322 | return TRUE; |
dcbf9037 JB |
2323 | } |
2324 | ||
c19d1205 ZW |
2325 | /* Should never be called, as .req goes between the alias and the |
2326 | register name, not at the beginning of the line. */ | |
c921be7d | 2327 | |
b99bd4ef | 2328 | static void |
c19d1205 | 2329 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2330 | { |
c19d1205 ZW |
2331 | as_bad (_("invalid syntax for .req directive")); |
2332 | } | |
b99bd4ef | 2333 | |
dcbf9037 JB |
2334 | static void |
2335 | s_dn (int a ATTRIBUTE_UNUSED) | |
2336 | { | |
2337 | as_bad (_("invalid syntax for .dn directive")); | |
2338 | } | |
2339 | ||
2340 | static void | |
2341 | s_qn (int a ATTRIBUTE_UNUSED) | |
2342 | { | |
2343 | as_bad (_("invalid syntax for .qn directive")); | |
2344 | } | |
2345 | ||
c19d1205 ZW |
2346 | /* The .unreq directive deletes an alias which was previously defined |
2347 | by .req. For example: | |
b99bd4ef | 2348 | |
c19d1205 ZW |
2349 | my_alias .req r11 |
2350 | .unreq my_alias */ | |
b99bd4ef NC |
2351 | |
2352 | static void | |
c19d1205 | 2353 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2354 | { |
c19d1205 ZW |
2355 | char * name; |
2356 | char saved_char; | |
b99bd4ef | 2357 | |
c19d1205 ZW |
2358 | name = input_line_pointer; |
2359 | ||
2360 | while (*input_line_pointer != 0 | |
2361 | && *input_line_pointer != ' ' | |
2362 | && *input_line_pointer != '\n') | |
2363 | ++input_line_pointer; | |
2364 | ||
2365 | saved_char = *input_line_pointer; | |
2366 | *input_line_pointer = 0; | |
2367 | ||
2368 | if (!*name) | |
2369 | as_bad (_("invalid syntax for .unreq directive")); | |
2370 | else | |
2371 | { | |
21d799b5 NC |
2372 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
2373 | name); | |
c19d1205 ZW |
2374 | |
2375 | if (!reg) | |
2376 | as_bad (_("unknown register alias '%s'"), name); | |
2377 | else if (reg->builtin) | |
2378 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
2379 | name); | |
2380 | else | |
2381 | { | |
d929913e NC |
2382 | char * p; |
2383 | char * nbuf; | |
2384 | ||
db0bc284 | 2385 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2386 | free ((char *) reg->name); |
dcbf9037 JB |
2387 | if (reg->neon) |
2388 | free (reg->neon); | |
c19d1205 | 2389 | free (reg); |
d929913e NC |
2390 | |
2391 | /* Also locate the all upper case and all lower case versions. | |
2392 | Do not complain if we cannot find one or the other as it | |
2393 | was probably deleted above. */ | |
5f4273c7 | 2394 | |
d929913e NC |
2395 | nbuf = strdup (name); |
2396 | for (p = nbuf; *p; p++) | |
2397 | *p = TOUPPER (*p); | |
21d799b5 | 2398 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2399 | if (reg) |
2400 | { | |
db0bc284 | 2401 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2402 | free ((char *) reg->name); |
2403 | if (reg->neon) | |
2404 | free (reg->neon); | |
2405 | free (reg); | |
2406 | } | |
2407 | ||
2408 | for (p = nbuf; *p; p++) | |
2409 | *p = TOLOWER (*p); | |
21d799b5 | 2410 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2411 | if (reg) |
2412 | { | |
db0bc284 | 2413 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2414 | free ((char *) reg->name); |
2415 | if (reg->neon) | |
2416 | free (reg->neon); | |
2417 | free (reg); | |
2418 | } | |
2419 | ||
2420 | free (nbuf); | |
c19d1205 ZW |
2421 | } |
2422 | } | |
b99bd4ef | 2423 | |
c19d1205 | 2424 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2425 | demand_empty_rest_of_line (); |
2426 | } | |
2427 | ||
c19d1205 ZW |
2428 | /* Directives: Instruction set selection. */ |
2429 | ||
2430 | #ifdef OBJ_ELF | |
2431 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2432 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2433 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2434 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2435 | ||
cd000bff DJ |
2436 | /* Create a new mapping symbol for the transition to STATE. */ |
2437 | ||
2438 | static void | |
2439 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2440 | { |
a737bd4d | 2441 | symbolS * symbolP; |
c19d1205 ZW |
2442 | const char * symname; |
2443 | int type; | |
b99bd4ef | 2444 | |
c19d1205 | 2445 | switch (state) |
b99bd4ef | 2446 | { |
c19d1205 ZW |
2447 | case MAP_DATA: |
2448 | symname = "$d"; | |
2449 | type = BSF_NO_FLAGS; | |
2450 | break; | |
2451 | case MAP_ARM: | |
2452 | symname = "$a"; | |
2453 | type = BSF_NO_FLAGS; | |
2454 | break; | |
2455 | case MAP_THUMB: | |
2456 | symname = "$t"; | |
2457 | type = BSF_NO_FLAGS; | |
2458 | break; | |
c19d1205 ZW |
2459 | default: |
2460 | abort (); | |
2461 | } | |
2462 | ||
cd000bff | 2463 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2464 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2465 | ||
2466 | switch (state) | |
2467 | { | |
2468 | case MAP_ARM: | |
2469 | THUMB_SET_FUNC (symbolP, 0); | |
2470 | ARM_SET_THUMB (symbolP, 0); | |
2471 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2472 | break; | |
2473 | ||
2474 | case MAP_THUMB: | |
2475 | THUMB_SET_FUNC (symbolP, 1); | |
2476 | ARM_SET_THUMB (symbolP, 1); | |
2477 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2478 | break; | |
2479 | ||
2480 | case MAP_DATA: | |
2481 | default: | |
cd000bff DJ |
2482 | break; |
2483 | } | |
2484 | ||
2485 | /* Save the mapping symbols for future reference. Also check that | |
2486 | we do not place two mapping symbols at the same offset within a | |
2487 | frag. We'll handle overlap between frags in | |
2488 | check_mapping_symbols. */ | |
2489 | if (value == 0) | |
2490 | { | |
2491 | know (frag->tc_frag_data.first_map == NULL); | |
2492 | frag->tc_frag_data.first_map = symbolP; | |
2493 | } | |
2494 | if (frag->tc_frag_data.last_map != NULL) | |
c5ed243b | 2495 | know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP)); |
cd000bff DJ |
2496 | frag->tc_frag_data.last_map = symbolP; |
2497 | } | |
2498 | ||
2499 | /* We must sometimes convert a region marked as code to data during | |
2500 | code alignment, if an odd number of bytes have to be padded. The | |
2501 | code mapping symbol is pushed to an aligned address. */ | |
2502 | ||
2503 | static void | |
2504 | insert_data_mapping_symbol (enum mstate state, | |
2505 | valueT value, fragS *frag, offsetT bytes) | |
2506 | { | |
2507 | /* If there was already a mapping symbol, remove it. */ | |
2508 | if (frag->tc_frag_data.last_map != NULL | |
2509 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2510 | { | |
2511 | symbolS *symp = frag->tc_frag_data.last_map; | |
2512 | ||
2513 | if (value == 0) | |
2514 | { | |
2515 | know (frag->tc_frag_data.first_map == symp); | |
2516 | frag->tc_frag_data.first_map = NULL; | |
2517 | } | |
2518 | frag->tc_frag_data.last_map = NULL; | |
2519 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2520 | } |
cd000bff DJ |
2521 | |
2522 | make_mapping_symbol (MAP_DATA, value, frag); | |
2523 | make_mapping_symbol (state, value + bytes, frag); | |
2524 | } | |
2525 | ||
2526 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2527 | ||
2528 | /* Set the mapping state to STATE. Only call this when about to | |
2529 | emit some STATE bytes to the file. */ | |
2530 | ||
2531 | void | |
2532 | mapping_state (enum mstate state) | |
2533 | { | |
940b5ce0 DJ |
2534 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2535 | ||
cd000bff DJ |
2536 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
2537 | ||
2538 | if (mapstate == state) | |
2539 | /* The mapping symbol has already been emitted. | |
2540 | There is nothing else to do. */ | |
2541 | return; | |
2542 | else if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
2543 | /* This case will be evaluated later in the next else. */ | |
2544 | return; | |
2545 | else if (TRANSITION (MAP_UNDEFINED, MAP_ARM) | |
2546 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2547 | { | |
2548 | /* Only add the symbol if the offset is > 0: | |
2549 | if we're at the first frag, check it's size > 0; | |
2550 | if we're not at the first frag, then for sure | |
2551 | the offset is > 0. */ | |
2552 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2553 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2554 | ||
2555 | if (add_symbol) | |
2556 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2557 | } | |
2558 | ||
2559 | mapping_state_2 (state, 0); | |
2560 | #undef TRANSITION | |
2561 | } | |
2562 | ||
2563 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2564 | allocated. Put the mapping symbol that far back. */ | |
2565 | ||
2566 | static void | |
2567 | mapping_state_2 (enum mstate state, int max_chars) | |
2568 | { | |
940b5ce0 DJ |
2569 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2570 | ||
2571 | if (!SEG_NORMAL (now_seg)) | |
2572 | return; | |
2573 | ||
cd000bff DJ |
2574 | if (mapstate == state) |
2575 | /* The mapping symbol has already been emitted. | |
2576 | There is nothing else to do. */ | |
2577 | return; | |
2578 | ||
cd000bff DJ |
2579 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2580 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 ZW |
2581 | } |
2582 | #else | |
d3106081 NS |
2583 | #define mapping_state(x) ((void)0) |
2584 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2585 | #endif |
2586 | ||
2587 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2588 | ||
4343666d | 2589 | #ifdef OBJ_COFF |
c19d1205 ZW |
2590 | static symbolS * |
2591 | find_real_start (symbolS * symbolP) | |
2592 | { | |
2593 | char * real_start; | |
2594 | const char * name = S_GET_NAME (symbolP); | |
2595 | symbolS * new_target; | |
2596 | ||
2597 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2598 | #define STUB_NAME ".real_start_of" | |
2599 | ||
2600 | if (name == NULL) | |
2601 | abort (); | |
2602 | ||
37f6032b ZW |
2603 | /* The compiler may generate BL instructions to local labels because |
2604 | it needs to perform a branch to a far away location. These labels | |
2605 | do not have a corresponding ".real_start_of" label. We check | |
2606 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2607 | the ".real_start_of" convention for nonlocal branches. */ | |
2608 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2609 | return symbolP; |
2610 | ||
37f6032b | 2611 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2612 | new_target = symbol_find (real_start); |
2613 | ||
2614 | if (new_target == NULL) | |
2615 | { | |
bd3ba5d1 | 2616 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2617 | new_target = symbolP; |
2618 | } | |
2619 | ||
c19d1205 ZW |
2620 | return new_target; |
2621 | } | |
4343666d | 2622 | #endif |
c19d1205 ZW |
2623 | |
2624 | static void | |
2625 | opcode_select (int width) | |
2626 | { | |
2627 | switch (width) | |
2628 | { | |
2629 | case 16: | |
2630 | if (! thumb_mode) | |
2631 | { | |
e74cfd16 | 2632 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2633 | as_bad (_("selected processor does not support THUMB opcodes")); |
2634 | ||
2635 | thumb_mode = 1; | |
2636 | /* No need to force the alignment, since we will have been | |
2637 | coming from ARM mode, which is word-aligned. */ | |
2638 | record_alignment (now_seg, 1); | |
2639 | } | |
c19d1205 ZW |
2640 | break; |
2641 | ||
2642 | case 32: | |
2643 | if (thumb_mode) | |
2644 | { | |
e74cfd16 | 2645 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2646 | as_bad (_("selected processor does not support ARM opcodes")); |
2647 | ||
2648 | thumb_mode = 0; | |
2649 | ||
2650 | if (!need_pass_2) | |
2651 | frag_align (2, 0, 0); | |
2652 | ||
2653 | record_alignment (now_seg, 1); | |
2654 | } | |
c19d1205 ZW |
2655 | break; |
2656 | ||
2657 | default: | |
2658 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2659 | } | |
2660 | } | |
2661 | ||
2662 | static void | |
2663 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2664 | { | |
2665 | opcode_select (32); | |
2666 | demand_empty_rest_of_line (); | |
2667 | } | |
2668 | ||
2669 | static void | |
2670 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2671 | { | |
2672 | opcode_select (16); | |
2673 | demand_empty_rest_of_line (); | |
2674 | } | |
2675 | ||
2676 | static void | |
2677 | s_code (int unused ATTRIBUTE_UNUSED) | |
2678 | { | |
2679 | int temp; | |
2680 | ||
2681 | temp = get_absolute_expression (); | |
2682 | switch (temp) | |
2683 | { | |
2684 | case 16: | |
2685 | case 32: | |
2686 | opcode_select (temp); | |
2687 | break; | |
2688 | ||
2689 | default: | |
2690 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2691 | } | |
2692 | } | |
2693 | ||
2694 | static void | |
2695 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2696 | { | |
2697 | /* If we are not already in thumb mode go into it, EVEN if | |
2698 | the target processor does not support thumb instructions. | |
2699 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2700 | to compile interworking support functions even if the | |
2701 | target processor should not support interworking. */ | |
2702 | if (! thumb_mode) | |
2703 | { | |
2704 | thumb_mode = 2; | |
2705 | record_alignment (now_seg, 1); | |
2706 | } | |
2707 | ||
2708 | demand_empty_rest_of_line (); | |
2709 | } | |
2710 | ||
2711 | static void | |
2712 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2713 | { | |
2714 | s_thumb (0); | |
2715 | ||
2716 | /* The following label is the name/address of the start of a Thumb function. | |
2717 | We need to know this for the interworking support. */ | |
2718 | label_is_thumb_function_name = TRUE; | |
2719 | } | |
2720 | ||
2721 | /* Perform a .set directive, but also mark the alias as | |
2722 | being a thumb function. */ | |
2723 | ||
2724 | static void | |
2725 | s_thumb_set (int equiv) | |
2726 | { | |
2727 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2728 | We cannot just call that code as we need to get at the symbol that | |
2729 | is created. */ | |
2730 | char * name; | |
2731 | char delim; | |
2732 | char * end_name; | |
2733 | symbolS * symbolP; | |
2734 | ||
2735 | /* Especial apologies for the random logic: | |
2736 | This just grew, and could be parsed much more simply! | |
2737 | Dean - in haste. */ | |
2738 | name = input_line_pointer; | |
2739 | delim = get_symbol_end (); | |
2740 | end_name = input_line_pointer; | |
2741 | *end_name = delim; | |
2742 | ||
2743 | if (*input_line_pointer != ',') | |
2744 | { | |
2745 | *end_name = 0; | |
2746 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2747 | *end_name = delim; |
2748 | ignore_rest_of_line (); | |
2749 | return; | |
2750 | } | |
2751 | ||
2752 | input_line_pointer++; | |
2753 | *end_name = 0; | |
2754 | ||
2755 | if (name[0] == '.' && name[1] == '\0') | |
2756 | { | |
2757 | /* XXX - this should not happen to .thumb_set. */ | |
2758 | abort (); | |
2759 | } | |
2760 | ||
2761 | if ((symbolP = symbol_find (name)) == NULL | |
2762 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2763 | { | |
2764 | #ifndef NO_LISTING | |
2765 | /* When doing symbol listings, play games with dummy fragments living | |
2766 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2767 | for this symbol. */ |
b99bd4ef NC |
2768 | if (listing & LISTING_SYMBOLS) |
2769 | { | |
2770 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 2771 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2772 | |
2773 | memset (dummy_frag, 0, sizeof (fragS)); | |
2774 | dummy_frag->fr_type = rs_fill; | |
2775 | dummy_frag->line = listing_tail; | |
2776 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2777 | dummy_frag->fr_symbol = symbolP; | |
2778 | } | |
2779 | else | |
2780 | #endif | |
2781 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2782 | ||
2783 | #ifdef OBJ_COFF | |
2784 | /* "set" symbols are local unless otherwise specified. */ | |
2785 | SF_SET_LOCAL (symbolP); | |
2786 | #endif /* OBJ_COFF */ | |
2787 | } /* Make a new symbol. */ | |
2788 | ||
2789 | symbol_table_insert (symbolP); | |
2790 | ||
2791 | * end_name = delim; | |
2792 | ||
2793 | if (equiv | |
2794 | && S_IS_DEFINED (symbolP) | |
2795 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2796 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2797 | ||
2798 | pseudo_set (symbolP); | |
2799 | ||
2800 | demand_empty_rest_of_line (); | |
2801 | ||
c19d1205 | 2802 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2803 | |
2804 | THUMB_SET_FUNC (symbolP, 1); | |
2805 | ARM_SET_THUMB (symbolP, 1); | |
2806 | #if defined OBJ_ELF || defined OBJ_COFF | |
2807 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2808 | #endif | |
2809 | } | |
2810 | ||
c19d1205 | 2811 | /* Directives: Mode selection. */ |
b99bd4ef | 2812 | |
c19d1205 ZW |
2813 | /* .syntax [unified|divided] - choose the new unified syntax |
2814 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2815 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2816 | static void |
c19d1205 | 2817 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2818 | { |
c19d1205 ZW |
2819 | char *name, delim; |
2820 | ||
2821 | name = input_line_pointer; | |
2822 | delim = get_symbol_end (); | |
2823 | ||
2824 | if (!strcasecmp (name, "unified")) | |
2825 | unified_syntax = TRUE; | |
2826 | else if (!strcasecmp (name, "divided")) | |
2827 | unified_syntax = FALSE; | |
2828 | else | |
2829 | { | |
2830 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2831 | return; | |
2832 | } | |
2833 | *input_line_pointer = delim; | |
b99bd4ef NC |
2834 | demand_empty_rest_of_line (); |
2835 | } | |
2836 | ||
c19d1205 ZW |
2837 | /* Directives: sectioning and alignment. */ |
2838 | ||
2839 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2840 | ||
b99bd4ef | 2841 | static void |
c19d1205 | 2842 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2843 | { |
a737bd4d | 2844 | int temp; |
dce323d1 | 2845 | bfd_boolean fill_p; |
c19d1205 ZW |
2846 | long temp_fill; |
2847 | long max_alignment = 15; | |
b99bd4ef NC |
2848 | |
2849 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2850 | if (temp > max_alignment) |
2851 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2852 | else if (temp < 0) | |
b99bd4ef | 2853 | { |
c19d1205 ZW |
2854 | as_bad (_("alignment negative. 0 assumed.")); |
2855 | temp = 0; | |
2856 | } | |
b99bd4ef | 2857 | |
c19d1205 ZW |
2858 | if (*input_line_pointer == ',') |
2859 | { | |
2860 | input_line_pointer++; | |
2861 | temp_fill = get_absolute_expression (); | |
dce323d1 | 2862 | fill_p = TRUE; |
b99bd4ef | 2863 | } |
c19d1205 | 2864 | else |
dce323d1 PB |
2865 | { |
2866 | fill_p = FALSE; | |
2867 | temp_fill = 0; | |
2868 | } | |
b99bd4ef | 2869 | |
c19d1205 ZW |
2870 | if (!temp) |
2871 | temp = 2; | |
b99bd4ef | 2872 | |
c19d1205 ZW |
2873 | /* Only make a frag if we HAVE to. */ |
2874 | if (temp && !need_pass_2) | |
dce323d1 PB |
2875 | { |
2876 | if (!fill_p && subseg_text_p (now_seg)) | |
2877 | frag_align_code (temp, 0); | |
2878 | else | |
2879 | frag_align (temp, (int) temp_fill, 0); | |
2880 | } | |
c19d1205 ZW |
2881 | demand_empty_rest_of_line (); |
2882 | ||
2883 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2884 | } |
2885 | ||
c19d1205 ZW |
2886 | static void |
2887 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2888 | { |
c19d1205 ZW |
2889 | /* We don't support putting frags in the BSS segment, we fake it by |
2890 | marking in_bss, then looking at s_skip for clues. */ | |
2891 | subseg_set (bss_section, 0); | |
2892 | demand_empty_rest_of_line (); | |
cd000bff DJ |
2893 | |
2894 | #ifdef md_elf_section_change_hook | |
2895 | md_elf_section_change_hook (); | |
2896 | #endif | |
c19d1205 | 2897 | } |
b99bd4ef | 2898 | |
c19d1205 ZW |
2899 | static void |
2900 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2901 | { | |
2902 | /* Never make frag if expect extra pass. */ | |
2903 | if (!need_pass_2) | |
2904 | frag_align (1, 0, 0); | |
b99bd4ef | 2905 | |
c19d1205 | 2906 | record_alignment (now_seg, 1); |
b99bd4ef | 2907 | |
c19d1205 | 2908 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2909 | } |
2910 | ||
c19d1205 | 2911 | /* Directives: Literal pools. */ |
a737bd4d | 2912 | |
c19d1205 ZW |
2913 | static literal_pool * |
2914 | find_literal_pool (void) | |
a737bd4d | 2915 | { |
c19d1205 | 2916 | literal_pool * pool; |
a737bd4d | 2917 | |
c19d1205 | 2918 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 2919 | { |
c19d1205 ZW |
2920 | if (pool->section == now_seg |
2921 | && pool->sub_section == now_subseg) | |
2922 | break; | |
a737bd4d NC |
2923 | } |
2924 | ||
c19d1205 | 2925 | return pool; |
a737bd4d NC |
2926 | } |
2927 | ||
c19d1205 ZW |
2928 | static literal_pool * |
2929 | find_or_make_literal_pool (void) | |
a737bd4d | 2930 | { |
c19d1205 ZW |
2931 | /* Next literal pool ID number. */ |
2932 | static unsigned int latest_pool_num = 1; | |
2933 | literal_pool * pool; | |
a737bd4d | 2934 | |
c19d1205 | 2935 | pool = find_literal_pool (); |
a737bd4d | 2936 | |
c19d1205 | 2937 | if (pool == NULL) |
a737bd4d | 2938 | { |
c19d1205 | 2939 | /* Create a new pool. */ |
21d799b5 | 2940 | pool = (literal_pool *) xmalloc (sizeof (* pool)); |
c19d1205 ZW |
2941 | if (! pool) |
2942 | return NULL; | |
a737bd4d | 2943 | |
c19d1205 ZW |
2944 | pool->next_free_entry = 0; |
2945 | pool->section = now_seg; | |
2946 | pool->sub_section = now_subseg; | |
2947 | pool->next = list_of_pools; | |
2948 | pool->symbol = NULL; | |
2949 | ||
2950 | /* Add it to the list. */ | |
2951 | list_of_pools = pool; | |
a737bd4d | 2952 | } |
a737bd4d | 2953 | |
c19d1205 ZW |
2954 | /* New pools, and emptied pools, will have a NULL symbol. */ |
2955 | if (pool->symbol == NULL) | |
a737bd4d | 2956 | { |
c19d1205 ZW |
2957 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
2958 | (valueT) 0, &zero_address_frag); | |
2959 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
2960 | } |
2961 | ||
c19d1205 ZW |
2962 | /* Done. */ |
2963 | return pool; | |
a737bd4d NC |
2964 | } |
2965 | ||
c19d1205 | 2966 | /* Add the literal in the global 'inst' |
5f4273c7 | 2967 | structure to the relevant literal pool. */ |
b99bd4ef NC |
2968 | |
2969 | static int | |
c19d1205 | 2970 | add_to_lit_pool (void) |
b99bd4ef | 2971 | { |
c19d1205 ZW |
2972 | literal_pool * pool; |
2973 | unsigned int entry; | |
b99bd4ef | 2974 | |
c19d1205 ZW |
2975 | pool = find_or_make_literal_pool (); |
2976 | ||
2977 | /* Check if this literal value is already in the pool. */ | |
2978 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 2979 | { |
c19d1205 ZW |
2980 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
2981 | && (inst.reloc.exp.X_op == O_constant) | |
2982 | && (pool->literals[entry].X_add_number | |
2983 | == inst.reloc.exp.X_add_number) | |
2984 | && (pool->literals[entry].X_unsigned | |
2985 | == inst.reloc.exp.X_unsigned)) | |
2986 | break; | |
2987 | ||
2988 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
2989 | && (inst.reloc.exp.X_op == O_symbol) | |
2990 | && (pool->literals[entry].X_add_number | |
2991 | == inst.reloc.exp.X_add_number) | |
2992 | && (pool->literals[entry].X_add_symbol | |
2993 | == inst.reloc.exp.X_add_symbol) | |
2994 | && (pool->literals[entry].X_op_symbol | |
2995 | == inst.reloc.exp.X_op_symbol)) | |
2996 | break; | |
b99bd4ef NC |
2997 | } |
2998 | ||
c19d1205 ZW |
2999 | /* Do we need to create a new entry? */ |
3000 | if (entry == pool->next_free_entry) | |
3001 | { | |
3002 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3003 | { | |
3004 | inst.error = _("literal pool overflow"); | |
3005 | return FAIL; | |
3006 | } | |
3007 | ||
3008 | pool->literals[entry] = inst.reloc.exp; | |
3009 | pool->next_free_entry += 1; | |
3010 | } | |
b99bd4ef | 3011 | |
c19d1205 ZW |
3012 | inst.reloc.exp.X_op = O_symbol; |
3013 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
3014 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3015 | |
c19d1205 | 3016 | return SUCCESS; |
b99bd4ef NC |
3017 | } |
3018 | ||
c19d1205 ZW |
3019 | /* Can't use symbol_new here, so have to create a symbol and then at |
3020 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 3021 | |
c19d1205 ZW |
3022 | static void |
3023 | symbol_locate (symbolS * symbolP, | |
3024 | const char * name, /* It is copied, the caller can modify. */ | |
3025 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3026 | valueT valu, /* Symbol value. */ | |
3027 | fragS * frag) /* Associated fragment. */ | |
3028 | { | |
3029 | unsigned int name_length; | |
3030 | char * preserved_copy_of_name; | |
e16bb312 | 3031 | |
c19d1205 ZW |
3032 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3033 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3034 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3035 | |
c19d1205 ZW |
3036 | #ifdef tc_canonicalize_symbol_name |
3037 | preserved_copy_of_name = | |
3038 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3039 | #endif | |
b99bd4ef | 3040 | |
c19d1205 | 3041 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3042 | |
c19d1205 ZW |
3043 | S_SET_SEGMENT (symbolP, segment); |
3044 | S_SET_VALUE (symbolP, valu); | |
3045 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3046 | |
c19d1205 | 3047 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3048 | |
c19d1205 ZW |
3049 | /* Link to end of symbol chain. */ |
3050 | { | |
3051 | extern int symbol_table_frozen; | |
b99bd4ef | 3052 | |
c19d1205 ZW |
3053 | if (symbol_table_frozen) |
3054 | abort (); | |
3055 | } | |
b99bd4ef | 3056 | |
c19d1205 | 3057 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3058 | |
c19d1205 | 3059 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3060 | |
c19d1205 ZW |
3061 | #ifdef tc_symbol_new_hook |
3062 | tc_symbol_new_hook (symbolP); | |
3063 | #endif | |
3064 | ||
3065 | #ifdef DEBUG_SYMS | |
3066 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3067 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3068 | } |
3069 | ||
b99bd4ef | 3070 | |
c19d1205 ZW |
3071 | static void |
3072 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3073 | { |
c19d1205 ZW |
3074 | unsigned int entry; |
3075 | literal_pool * pool; | |
3076 | char sym_name[20]; | |
b99bd4ef | 3077 | |
c19d1205 ZW |
3078 | pool = find_literal_pool (); |
3079 | if (pool == NULL | |
3080 | || pool->symbol == NULL | |
3081 | || pool->next_free_entry == 0) | |
3082 | return; | |
b99bd4ef | 3083 | |
c19d1205 | 3084 | mapping_state (MAP_DATA); |
b99bd4ef | 3085 | |
c19d1205 ZW |
3086 | /* Align pool as you have word accesses. |
3087 | Only make a frag if we have to. */ | |
3088 | if (!need_pass_2) | |
3089 | frag_align (2, 0, 0); | |
b99bd4ef | 3090 | |
c19d1205 | 3091 | record_alignment (now_seg, 2); |
b99bd4ef | 3092 | |
c19d1205 | 3093 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3094 | |
c19d1205 ZW |
3095 | symbol_locate (pool->symbol, sym_name, now_seg, |
3096 | (valueT) frag_now_fix (), frag_now); | |
3097 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3098 | |
c19d1205 | 3099 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3100 | |
c19d1205 ZW |
3101 | #if defined OBJ_COFF || defined OBJ_ELF |
3102 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3103 | #endif | |
6c43fab6 | 3104 | |
c19d1205 ZW |
3105 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
3106 | /* First output the expression in the instruction to the pool. */ | |
3107 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 3108 | |
c19d1205 ZW |
3109 | /* Mark the pool as empty. */ |
3110 | pool->next_free_entry = 0; | |
3111 | pool->symbol = NULL; | |
b99bd4ef NC |
3112 | } |
3113 | ||
c19d1205 ZW |
3114 | #ifdef OBJ_ELF |
3115 | /* Forward declarations for functions below, in the MD interface | |
3116 | section. */ | |
3117 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3118 | static valueT create_unwind_entry (int); | |
3119 | static void start_unwind_section (const segT, int); | |
3120 | static void add_unwind_opcode (valueT, int); | |
3121 | static void flush_pending_unwind (void); | |
b99bd4ef | 3122 | |
c19d1205 | 3123 | /* Directives: Data. */ |
b99bd4ef | 3124 | |
c19d1205 ZW |
3125 | static void |
3126 | s_arm_elf_cons (int nbytes) | |
3127 | { | |
3128 | expressionS exp; | |
b99bd4ef | 3129 | |
c19d1205 ZW |
3130 | #ifdef md_flush_pending_output |
3131 | md_flush_pending_output (); | |
3132 | #endif | |
b99bd4ef | 3133 | |
c19d1205 | 3134 | if (is_it_end_of_statement ()) |
b99bd4ef | 3135 | { |
c19d1205 ZW |
3136 | demand_empty_rest_of_line (); |
3137 | return; | |
b99bd4ef NC |
3138 | } |
3139 | ||
c19d1205 ZW |
3140 | #ifdef md_cons_align |
3141 | md_cons_align (nbytes); | |
3142 | #endif | |
b99bd4ef | 3143 | |
c19d1205 ZW |
3144 | mapping_state (MAP_DATA); |
3145 | do | |
b99bd4ef | 3146 | { |
c19d1205 ZW |
3147 | int reloc; |
3148 | char *base = input_line_pointer; | |
b99bd4ef | 3149 | |
c19d1205 | 3150 | expression (& exp); |
b99bd4ef | 3151 | |
c19d1205 ZW |
3152 | if (exp.X_op != O_symbol) |
3153 | emit_expr (&exp, (unsigned int) nbytes); | |
3154 | else | |
3155 | { | |
3156 | char *before_reloc = input_line_pointer; | |
3157 | reloc = parse_reloc (&input_line_pointer); | |
3158 | if (reloc == -1) | |
3159 | { | |
3160 | as_bad (_("unrecognized relocation suffix")); | |
3161 | ignore_rest_of_line (); | |
3162 | return; | |
3163 | } | |
3164 | else if (reloc == BFD_RELOC_UNUSED) | |
3165 | emit_expr (&exp, (unsigned int) nbytes); | |
3166 | else | |
3167 | { | |
21d799b5 NC |
3168 | reloc_howto_type *howto = (reloc_howto_type *) |
3169 | bfd_reloc_type_lookup (stdoutput, | |
3170 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3171 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3172 | |
2fc8bdac ZW |
3173 | if (reloc == BFD_RELOC_ARM_PLT32) |
3174 | { | |
3175 | as_bad (_("(plt) is only valid on branch targets")); | |
3176 | reloc = BFD_RELOC_UNUSED; | |
3177 | size = 0; | |
3178 | } | |
3179 | ||
c19d1205 | 3180 | if (size > nbytes) |
2fc8bdac | 3181 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3182 | howto->name, nbytes); |
3183 | else | |
3184 | { | |
3185 | /* We've parsed an expression stopping at O_symbol. | |
3186 | But there may be more expression left now that we | |
3187 | have parsed the relocation marker. Parse it again. | |
3188 | XXX Surely there is a cleaner way to do this. */ | |
3189 | char *p = input_line_pointer; | |
3190 | int offset; | |
21d799b5 | 3191 | char *save_buf = (char *) alloca (input_line_pointer - base); |
c19d1205 ZW |
3192 | memcpy (save_buf, base, input_line_pointer - base); |
3193 | memmove (base + (input_line_pointer - before_reloc), | |
3194 | base, before_reloc - base); | |
3195 | ||
3196 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3197 | expression (&exp); | |
3198 | memcpy (base, save_buf, p - base); | |
3199 | ||
3200 | offset = nbytes - size; | |
3201 | p = frag_more ((int) nbytes); | |
3202 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
21d799b5 | 3203 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
c19d1205 ZW |
3204 | } |
3205 | } | |
3206 | } | |
b99bd4ef | 3207 | } |
c19d1205 | 3208 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3209 | |
c19d1205 ZW |
3210 | /* Put terminator back into stream. */ |
3211 | input_line_pointer --; | |
3212 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3213 | } |
3214 | ||
c921be7d NC |
3215 | /* Emit an expression containing a 32-bit thumb instruction. |
3216 | Implementation based on put_thumb32_insn. */ | |
3217 | ||
3218 | static void | |
3219 | emit_thumb32_expr (expressionS * exp) | |
3220 | { | |
3221 | expressionS exp_high = *exp; | |
3222 | ||
3223 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3224 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3225 | exp->X_add_number &= 0xffff; | |
3226 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3227 | } | |
3228 | ||
3229 | /* Guess the instruction size based on the opcode. */ | |
3230 | ||
3231 | static int | |
3232 | thumb_insn_size (int opcode) | |
3233 | { | |
3234 | if ((unsigned int) opcode < 0xe800u) | |
3235 | return 2; | |
3236 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3237 | return 4; | |
3238 | else | |
3239 | return 0; | |
3240 | } | |
3241 | ||
3242 | static bfd_boolean | |
3243 | emit_insn (expressionS *exp, int nbytes) | |
3244 | { | |
3245 | int size = 0; | |
3246 | ||
3247 | if (exp->X_op == O_constant) | |
3248 | { | |
3249 | size = nbytes; | |
3250 | ||
3251 | if (size == 0) | |
3252 | size = thumb_insn_size (exp->X_add_number); | |
3253 | ||
3254 | if (size != 0) | |
3255 | { | |
3256 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3257 | { | |
3258 | as_bad (_(".inst.n operand too big. "\ | |
3259 | "Use .inst.w instead")); | |
3260 | size = 0; | |
3261 | } | |
3262 | else | |
3263 | { | |
3264 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3265 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3266 | else | |
3267 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3268 | ||
3269 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3270 | emit_thumb32_expr (exp); | |
3271 | else | |
3272 | emit_expr (exp, (unsigned int) size); | |
3273 | ||
3274 | it_fsm_post_encode (); | |
3275 | } | |
3276 | } | |
3277 | else | |
3278 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3279 | "Use .inst.n/.inst.w instead")); | |
3280 | } | |
3281 | else | |
3282 | as_bad (_("constant expression required")); | |
3283 | ||
3284 | return (size != 0); | |
3285 | } | |
3286 | ||
3287 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3288 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3289 | ||
3290 | static void | |
3291 | s_arm_elf_inst (int nbytes) | |
3292 | { | |
3293 | if (is_it_end_of_statement ()) | |
3294 | { | |
3295 | demand_empty_rest_of_line (); | |
3296 | return; | |
3297 | } | |
3298 | ||
3299 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3300 | but will ensure not to be in DATA state. */ | |
3301 | ||
3302 | if (thumb_mode) | |
3303 | mapping_state (MAP_THUMB); | |
3304 | else | |
3305 | { | |
3306 | if (nbytes != 0) | |
3307 | { | |
3308 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3309 | ignore_rest_of_line (); | |
3310 | return; | |
3311 | } | |
3312 | ||
3313 | nbytes = 4; | |
3314 | ||
3315 | mapping_state (MAP_ARM); | |
3316 | } | |
3317 | ||
3318 | do | |
3319 | { | |
3320 | expressionS exp; | |
3321 | ||
3322 | expression (& exp); | |
3323 | ||
3324 | if (! emit_insn (& exp, nbytes)) | |
3325 | { | |
3326 | ignore_rest_of_line (); | |
3327 | return; | |
3328 | } | |
3329 | } | |
3330 | while (*input_line_pointer++ == ','); | |
3331 | ||
3332 | /* Put terminator back into stream. */ | |
3333 | input_line_pointer --; | |
3334 | demand_empty_rest_of_line (); | |
3335 | } | |
b99bd4ef | 3336 | |
c19d1205 | 3337 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3338 | |
c19d1205 ZW |
3339 | static void |
3340 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3341 | { | |
3342 | expressionS exp; | |
3343 | char *p; | |
3344 | valueT highbit; | |
b99bd4ef | 3345 | |
c19d1205 ZW |
3346 | highbit = 0; |
3347 | if (*input_line_pointer == '1') | |
3348 | highbit = 0x80000000; | |
3349 | else if (*input_line_pointer != '0') | |
3350 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3351 | |
c19d1205 ZW |
3352 | input_line_pointer++; |
3353 | if (*input_line_pointer != ',') | |
3354 | as_bad (_("missing comma")); | |
3355 | input_line_pointer++; | |
b99bd4ef | 3356 | |
c19d1205 ZW |
3357 | #ifdef md_flush_pending_output |
3358 | md_flush_pending_output (); | |
3359 | #endif | |
b99bd4ef | 3360 | |
c19d1205 ZW |
3361 | #ifdef md_cons_align |
3362 | md_cons_align (4); | |
3363 | #endif | |
b99bd4ef | 3364 | |
c19d1205 | 3365 | mapping_state (MAP_DATA); |
b99bd4ef | 3366 | |
c19d1205 | 3367 | expression (&exp); |
b99bd4ef | 3368 | |
c19d1205 ZW |
3369 | p = frag_more (4); |
3370 | md_number_to_chars (p, highbit, 4); | |
3371 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3372 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3373 | |
c19d1205 | 3374 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3375 | } |
3376 | ||
c19d1205 | 3377 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3378 | |
c19d1205 | 3379 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3380 | |
c19d1205 ZW |
3381 | static void |
3382 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3383 | { | |
3384 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3385 | if (unwind.proc_start) |
3386 | { | |
c921be7d | 3387 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3388 | return; |
3389 | } | |
3390 | ||
c19d1205 ZW |
3391 | /* Mark the start of the function. */ |
3392 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3393 | |
c19d1205 ZW |
3394 | /* Reset the rest of the unwind info. */ |
3395 | unwind.opcode_count = 0; | |
3396 | unwind.table_entry = NULL; | |
3397 | unwind.personality_routine = NULL; | |
3398 | unwind.personality_index = -1; | |
3399 | unwind.frame_size = 0; | |
3400 | unwind.fp_offset = 0; | |
fdfde340 | 3401 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3402 | unwind.fp_used = 0; |
3403 | unwind.sp_restored = 0; | |
3404 | } | |
b99bd4ef | 3405 | |
b99bd4ef | 3406 | |
c19d1205 ZW |
3407 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3408 | for the function. */ | |
b99bd4ef | 3409 | |
c19d1205 ZW |
3410 | static void |
3411 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3412 | { | |
3413 | demand_empty_rest_of_line (); | |
921e5f0a | 3414 | if (!unwind.proc_start) |
c921be7d | 3415 | as_bad (MISSING_FNSTART); |
921e5f0a | 3416 | |
c19d1205 | 3417 | if (unwind.table_entry) |
6decc662 | 3418 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3419 | |
c19d1205 ZW |
3420 | create_unwind_entry (1); |
3421 | } | |
a737bd4d | 3422 | |
c19d1205 | 3423 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3424 | |
c19d1205 ZW |
3425 | static void |
3426 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3427 | { | |
3428 | long where; | |
3429 | char *ptr; | |
3430 | valueT val; | |
940b5ce0 | 3431 | unsigned int marked_pr_dependency; |
f02232aa | 3432 | |
c19d1205 | 3433 | demand_empty_rest_of_line (); |
f02232aa | 3434 | |
921e5f0a PB |
3435 | if (!unwind.proc_start) |
3436 | { | |
c921be7d | 3437 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3438 | return; |
3439 | } | |
3440 | ||
c19d1205 ZW |
3441 | /* Add eh table entry. */ |
3442 | if (unwind.table_entry == NULL) | |
3443 | val = create_unwind_entry (0); | |
3444 | else | |
3445 | val = 0; | |
f02232aa | 3446 | |
c19d1205 ZW |
3447 | /* Add index table entry. This is two words. */ |
3448 | start_unwind_section (unwind.saved_seg, 1); | |
3449 | frag_align (2, 0, 0); | |
3450 | record_alignment (now_seg, 2); | |
b99bd4ef | 3451 | |
c19d1205 ZW |
3452 | ptr = frag_more (8); |
3453 | where = frag_now_fix () - 8; | |
f02232aa | 3454 | |
c19d1205 ZW |
3455 | /* Self relative offset of the function start. */ |
3456 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3457 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3458 | |
c19d1205 ZW |
3459 | /* Indicate dependency on EHABI-defined personality routines to the |
3460 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3461 | marked_pr_dependency |
3462 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3463 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3464 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3465 | { | |
5f4273c7 NC |
3466 | static const char *const name[] = |
3467 | { | |
3468 | "__aeabi_unwind_cpp_pr0", | |
3469 | "__aeabi_unwind_cpp_pr1", | |
3470 | "__aeabi_unwind_cpp_pr2" | |
3471 | }; | |
c19d1205 ZW |
3472 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3473 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3474 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3475 | |= 1 << unwind.personality_index; |
c19d1205 | 3476 | } |
f02232aa | 3477 | |
c19d1205 ZW |
3478 | if (val) |
3479 | /* Inline exception table entry. */ | |
3480 | md_number_to_chars (ptr + 4, val, 4); | |
3481 | else | |
3482 | /* Self relative offset of the table entry. */ | |
3483 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3484 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3485 | |
c19d1205 ZW |
3486 | /* Restore the original section. */ |
3487 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3488 | |
3489 | unwind.proc_start = NULL; | |
c19d1205 | 3490 | } |
f02232aa | 3491 | |
f02232aa | 3492 | |
c19d1205 | 3493 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3494 | |
c19d1205 ZW |
3495 | static void |
3496 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3497 | { | |
3498 | demand_empty_rest_of_line (); | |
921e5f0a | 3499 | if (!unwind.proc_start) |
c921be7d | 3500 | as_bad (MISSING_FNSTART); |
921e5f0a | 3501 | |
c19d1205 ZW |
3502 | if (unwind.personality_routine || unwind.personality_index != -1) |
3503 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3504 | |
c19d1205 ZW |
3505 | unwind.personality_index = -2; |
3506 | } | |
b99bd4ef | 3507 | |
b99bd4ef | 3508 | |
c19d1205 | 3509 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3510 | |
c19d1205 ZW |
3511 | static void |
3512 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3513 | { | |
3514 | expressionS exp; | |
b99bd4ef | 3515 | |
921e5f0a | 3516 | if (!unwind.proc_start) |
c921be7d | 3517 | as_bad (MISSING_FNSTART); |
921e5f0a | 3518 | |
c19d1205 ZW |
3519 | if (unwind.personality_routine || unwind.personality_index != -1) |
3520 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3521 | |
c19d1205 | 3522 | expression (&exp); |
b99bd4ef | 3523 | |
c19d1205 ZW |
3524 | if (exp.X_op != O_constant |
3525 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3526 | { |
c19d1205 ZW |
3527 | as_bad (_("bad personality routine number")); |
3528 | ignore_rest_of_line (); | |
3529 | return; | |
b99bd4ef NC |
3530 | } |
3531 | ||
c19d1205 | 3532 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3533 | |
c19d1205 ZW |
3534 | demand_empty_rest_of_line (); |
3535 | } | |
e16bb312 | 3536 | |
e16bb312 | 3537 | |
c19d1205 | 3538 | /* Parse a personality directive. */ |
e16bb312 | 3539 | |
c19d1205 ZW |
3540 | static void |
3541 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3542 | { | |
3543 | char *name, *p, c; | |
a737bd4d | 3544 | |
921e5f0a | 3545 | if (!unwind.proc_start) |
c921be7d | 3546 | as_bad (MISSING_FNSTART); |
921e5f0a | 3547 | |
c19d1205 ZW |
3548 | if (unwind.personality_routine || unwind.personality_index != -1) |
3549 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3550 | |
c19d1205 ZW |
3551 | name = input_line_pointer; |
3552 | c = get_symbol_end (); | |
3553 | p = input_line_pointer; | |
3554 | unwind.personality_routine = symbol_find_or_make (name); | |
3555 | *p = c; | |
3556 | demand_empty_rest_of_line (); | |
3557 | } | |
e16bb312 | 3558 | |
e16bb312 | 3559 | |
c19d1205 | 3560 | /* Parse a directive saving core registers. */ |
e16bb312 | 3561 | |
c19d1205 ZW |
3562 | static void |
3563 | s_arm_unwind_save_core (void) | |
e16bb312 | 3564 | { |
c19d1205 ZW |
3565 | valueT op; |
3566 | long range; | |
3567 | int n; | |
e16bb312 | 3568 | |
c19d1205 ZW |
3569 | range = parse_reg_list (&input_line_pointer); |
3570 | if (range == FAIL) | |
e16bb312 | 3571 | { |
c19d1205 ZW |
3572 | as_bad (_("expected register list")); |
3573 | ignore_rest_of_line (); | |
3574 | return; | |
3575 | } | |
e16bb312 | 3576 | |
c19d1205 | 3577 | demand_empty_rest_of_line (); |
e16bb312 | 3578 | |
c19d1205 ZW |
3579 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3580 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3581 | ip because it is clobbered by calls. */ | |
3582 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3583 | && (range & 0x3000) == 0x1000) | |
3584 | { | |
3585 | unwind.opcode_count--; | |
3586 | unwind.sp_restored = 0; | |
3587 | range = (range | 0x2000) & ~0x1000; | |
3588 | unwind.pending_offset = 0; | |
3589 | } | |
e16bb312 | 3590 | |
01ae4198 DJ |
3591 | /* Pop r4-r15. */ |
3592 | if (range & 0xfff0) | |
c19d1205 | 3593 | { |
01ae4198 DJ |
3594 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3595 | registers starting with r4, plus maybe r14. */ | |
3596 | for (n = 0; n < 8; n++) | |
3597 | { | |
3598 | /* Break at the first non-saved register. */ | |
3599 | if ((range & (1 << (n + 4))) == 0) | |
3600 | break; | |
3601 | } | |
3602 | /* See if there are any other bits set. */ | |
3603 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3604 | { | |
3605 | /* Use the long form. */ | |
3606 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3607 | add_unwind_opcode (op, 2); | |
3608 | } | |
0dd132b6 | 3609 | else |
01ae4198 DJ |
3610 | { |
3611 | /* Use the short form. */ | |
3612 | if (range & 0x4000) | |
3613 | op = 0xa8; /* Pop r14. */ | |
3614 | else | |
3615 | op = 0xa0; /* Do not pop r14. */ | |
3616 | op |= (n - 1); | |
3617 | add_unwind_opcode (op, 1); | |
3618 | } | |
c19d1205 | 3619 | } |
0dd132b6 | 3620 | |
c19d1205 ZW |
3621 | /* Pop r0-r3. */ |
3622 | if (range & 0xf) | |
3623 | { | |
3624 | op = 0xb100 | (range & 0xf); | |
3625 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3626 | } |
3627 | ||
c19d1205 ZW |
3628 | /* Record the number of bytes pushed. */ |
3629 | for (n = 0; n < 16; n++) | |
3630 | { | |
3631 | if (range & (1 << n)) | |
3632 | unwind.frame_size += 4; | |
3633 | } | |
0dd132b6 NC |
3634 | } |
3635 | ||
c19d1205 ZW |
3636 | |
3637 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3638 | |
3639 | static void | |
c19d1205 | 3640 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3641 | { |
c19d1205 ZW |
3642 | expressionS exp; |
3643 | int num_regs; | |
3644 | valueT op; | |
b99bd4ef | 3645 | |
c19d1205 ZW |
3646 | /* Get Number of registers to transfer. */ |
3647 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3648 | expression (&exp); | |
3649 | else | |
3650 | exp.X_op = O_illegal; | |
b99bd4ef | 3651 | |
c19d1205 | 3652 | if (exp.X_op != O_constant) |
b99bd4ef | 3653 | { |
c19d1205 ZW |
3654 | as_bad (_("expected , <constant>")); |
3655 | ignore_rest_of_line (); | |
b99bd4ef NC |
3656 | return; |
3657 | } | |
3658 | ||
c19d1205 ZW |
3659 | num_regs = exp.X_add_number; |
3660 | ||
3661 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3662 | { |
c19d1205 ZW |
3663 | as_bad (_("number of registers must be in the range [1:4]")); |
3664 | ignore_rest_of_line (); | |
b99bd4ef NC |
3665 | return; |
3666 | } | |
3667 | ||
c19d1205 | 3668 | demand_empty_rest_of_line (); |
b99bd4ef | 3669 | |
c19d1205 ZW |
3670 | if (reg == 4) |
3671 | { | |
3672 | /* Short form. */ | |
3673 | op = 0xb4 | (num_regs - 1); | |
3674 | add_unwind_opcode (op, 1); | |
3675 | } | |
b99bd4ef NC |
3676 | else |
3677 | { | |
c19d1205 ZW |
3678 | /* Long form. */ |
3679 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3680 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3681 | } |
c19d1205 | 3682 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3683 | } |
3684 | ||
c19d1205 | 3685 | |
fa073d69 MS |
3686 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3687 | ||
3688 | static void | |
3689 | s_arm_unwind_save_vfp_armv6 (void) | |
3690 | { | |
3691 | int count; | |
3692 | unsigned int start; | |
3693 | valueT op; | |
3694 | int num_vfpv3_regs = 0; | |
3695 | int num_regs_below_16; | |
3696 | ||
3697 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3698 | if (count == FAIL) | |
3699 | { | |
3700 | as_bad (_("expected register list")); | |
3701 | ignore_rest_of_line (); | |
3702 | return; | |
3703 | } | |
3704 | ||
3705 | demand_empty_rest_of_line (); | |
3706 | ||
3707 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3708 | than FSTMX/FLDMX-style ones). */ | |
3709 | ||
3710 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3711 | if (start >= 16) | |
3712 | num_vfpv3_regs = count; | |
3713 | else if (start + count > 16) | |
3714 | num_vfpv3_regs = start + count - 16; | |
3715 | ||
3716 | if (num_vfpv3_regs > 0) | |
3717 | { | |
3718 | int start_offset = start > 16 ? start - 16 : 0; | |
3719 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3720 | add_unwind_opcode (op, 2); | |
3721 | } | |
3722 | ||
3723 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3724 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 3725 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
3726 | if (num_regs_below_16 > 0) |
3727 | { | |
3728 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3729 | add_unwind_opcode (op, 2); | |
3730 | } | |
3731 | ||
3732 | unwind.frame_size += count * 8; | |
3733 | } | |
3734 | ||
3735 | ||
3736 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3737 | |
3738 | static void | |
c19d1205 | 3739 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3740 | { |
c19d1205 | 3741 | int count; |
ca3f61f7 | 3742 | unsigned int reg; |
c19d1205 | 3743 | valueT op; |
b99bd4ef | 3744 | |
5287ad62 | 3745 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3746 | if (count == FAIL) |
b99bd4ef | 3747 | { |
c19d1205 ZW |
3748 | as_bad (_("expected register list")); |
3749 | ignore_rest_of_line (); | |
b99bd4ef NC |
3750 | return; |
3751 | } | |
3752 | ||
c19d1205 | 3753 | demand_empty_rest_of_line (); |
b99bd4ef | 3754 | |
c19d1205 | 3755 | if (reg == 8) |
b99bd4ef | 3756 | { |
c19d1205 ZW |
3757 | /* Short form. */ |
3758 | op = 0xb8 | (count - 1); | |
3759 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3760 | } |
c19d1205 | 3761 | else |
b99bd4ef | 3762 | { |
c19d1205 ZW |
3763 | /* Long form. */ |
3764 | op = 0xb300 | (reg << 4) | (count - 1); | |
3765 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3766 | } |
c19d1205 ZW |
3767 | unwind.frame_size += count * 8 + 4; |
3768 | } | |
b99bd4ef | 3769 | |
b99bd4ef | 3770 | |
c19d1205 ZW |
3771 | /* Parse a directive saving iWMMXt data registers. */ |
3772 | ||
3773 | static void | |
3774 | s_arm_unwind_save_mmxwr (void) | |
3775 | { | |
3776 | int reg; | |
3777 | int hi_reg; | |
3778 | int i; | |
3779 | unsigned mask = 0; | |
3780 | valueT op; | |
b99bd4ef | 3781 | |
c19d1205 ZW |
3782 | if (*input_line_pointer == '{') |
3783 | input_line_pointer++; | |
b99bd4ef | 3784 | |
c19d1205 | 3785 | do |
b99bd4ef | 3786 | { |
dcbf9037 | 3787 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3788 | |
c19d1205 | 3789 | if (reg == FAIL) |
b99bd4ef | 3790 | { |
9b7132d3 | 3791 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 3792 | goto error; |
b99bd4ef NC |
3793 | } |
3794 | ||
c19d1205 ZW |
3795 | if (mask >> reg) |
3796 | as_tsktsk (_("register list not in ascending order")); | |
3797 | mask |= 1 << reg; | |
b99bd4ef | 3798 | |
c19d1205 ZW |
3799 | if (*input_line_pointer == '-') |
3800 | { | |
3801 | input_line_pointer++; | |
dcbf9037 | 3802 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3803 | if (hi_reg == FAIL) |
3804 | { | |
9b7132d3 | 3805 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
3806 | goto error; |
3807 | } | |
3808 | else if (reg >= hi_reg) | |
3809 | { | |
3810 | as_bad (_("bad register range")); | |
3811 | goto error; | |
3812 | } | |
3813 | for (; reg < hi_reg; reg++) | |
3814 | mask |= 1 << reg; | |
3815 | } | |
3816 | } | |
3817 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3818 | |
c19d1205 ZW |
3819 | if (*input_line_pointer == '}') |
3820 | input_line_pointer++; | |
b99bd4ef | 3821 | |
c19d1205 | 3822 | demand_empty_rest_of_line (); |
b99bd4ef | 3823 | |
708587a4 | 3824 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3825 | the list. */ |
3826 | flush_pending_unwind (); | |
b99bd4ef | 3827 | |
c19d1205 | 3828 | for (i = 0; i < 16; i++) |
b99bd4ef | 3829 | { |
c19d1205 ZW |
3830 | if (mask & (1 << i)) |
3831 | unwind.frame_size += 8; | |
b99bd4ef NC |
3832 | } |
3833 | ||
c19d1205 ZW |
3834 | /* Attempt to combine with a previous opcode. We do this because gcc |
3835 | likes to output separate unwind directives for a single block of | |
3836 | registers. */ | |
3837 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3838 | { |
c19d1205 ZW |
3839 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3840 | if ((i & 0xf8) == 0xc0) | |
3841 | { | |
3842 | i &= 7; | |
3843 | /* Only merge if the blocks are contiguous. */ | |
3844 | if (i < 6) | |
3845 | { | |
3846 | if ((mask & 0xfe00) == (1 << 9)) | |
3847 | { | |
3848 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3849 | unwind.opcode_count--; | |
3850 | } | |
3851 | } | |
3852 | else if (i == 6 && unwind.opcode_count >= 2) | |
3853 | { | |
3854 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3855 | reg = i >> 4; | |
3856 | i &= 0xf; | |
b99bd4ef | 3857 | |
c19d1205 ZW |
3858 | op = 0xffff << (reg - 1); |
3859 | if (reg > 0 | |
87a1fd79 | 3860 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
3861 | { |
3862 | op = (1 << (reg + i + 1)) - 1; | |
3863 | op &= ~((1 << reg) - 1); | |
3864 | mask |= op; | |
3865 | unwind.opcode_count -= 2; | |
3866 | } | |
3867 | } | |
3868 | } | |
b99bd4ef NC |
3869 | } |
3870 | ||
c19d1205 ZW |
3871 | hi_reg = 15; |
3872 | /* We want to generate opcodes in the order the registers have been | |
3873 | saved, ie. descending order. */ | |
3874 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3875 | { |
c19d1205 ZW |
3876 | /* Save registers in blocks. */ |
3877 | if (reg < 0 | |
3878 | || !(mask & (1 << reg))) | |
3879 | { | |
3880 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 3881 | preceding block. */ |
c19d1205 ZW |
3882 | if (reg != hi_reg) |
3883 | { | |
3884 | if (reg == 9) | |
3885 | { | |
3886 | /* Short form. */ | |
3887 | op = 0xc0 | (hi_reg - 10); | |
3888 | add_unwind_opcode (op, 1); | |
3889 | } | |
3890 | else | |
3891 | { | |
3892 | /* Long form. */ | |
3893 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
3894 | add_unwind_opcode (op, 2); | |
3895 | } | |
3896 | } | |
3897 | hi_reg = reg - 1; | |
3898 | } | |
b99bd4ef NC |
3899 | } |
3900 | ||
c19d1205 ZW |
3901 | return; |
3902 | error: | |
3903 | ignore_rest_of_line (); | |
b99bd4ef NC |
3904 | } |
3905 | ||
3906 | static void | |
c19d1205 | 3907 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 3908 | { |
c19d1205 ZW |
3909 | int reg; |
3910 | int hi_reg; | |
3911 | unsigned mask = 0; | |
3912 | valueT op; | |
b99bd4ef | 3913 | |
c19d1205 ZW |
3914 | if (*input_line_pointer == '{') |
3915 | input_line_pointer++; | |
b99bd4ef | 3916 | |
c19d1205 | 3917 | do |
b99bd4ef | 3918 | { |
dcbf9037 | 3919 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 3920 | |
c19d1205 ZW |
3921 | if (reg == FAIL) |
3922 | { | |
9b7132d3 | 3923 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3924 | goto error; |
3925 | } | |
b99bd4ef | 3926 | |
c19d1205 ZW |
3927 | reg -= 8; |
3928 | if (mask >> reg) | |
3929 | as_tsktsk (_("register list not in ascending order")); | |
3930 | mask |= 1 << reg; | |
b99bd4ef | 3931 | |
c19d1205 ZW |
3932 | if (*input_line_pointer == '-') |
3933 | { | |
3934 | input_line_pointer++; | |
dcbf9037 | 3935 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
3936 | if (hi_reg == FAIL) |
3937 | { | |
9b7132d3 | 3938 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3939 | goto error; |
3940 | } | |
3941 | else if (reg >= hi_reg) | |
3942 | { | |
3943 | as_bad (_("bad register range")); | |
3944 | goto error; | |
3945 | } | |
3946 | for (; reg < hi_reg; reg++) | |
3947 | mask |= 1 << reg; | |
3948 | } | |
b99bd4ef | 3949 | } |
c19d1205 | 3950 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 3951 | |
c19d1205 ZW |
3952 | if (*input_line_pointer == '}') |
3953 | input_line_pointer++; | |
b99bd4ef | 3954 | |
c19d1205 ZW |
3955 | demand_empty_rest_of_line (); |
3956 | ||
708587a4 | 3957 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3958 | the list. */ |
3959 | flush_pending_unwind (); | |
b99bd4ef | 3960 | |
c19d1205 | 3961 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 3962 | { |
c19d1205 ZW |
3963 | if (mask & (1 << reg)) |
3964 | unwind.frame_size += 4; | |
b99bd4ef | 3965 | } |
c19d1205 ZW |
3966 | op = 0xc700 | mask; |
3967 | add_unwind_opcode (op, 2); | |
3968 | return; | |
3969 | error: | |
3970 | ignore_rest_of_line (); | |
b99bd4ef NC |
3971 | } |
3972 | ||
c19d1205 | 3973 | |
fa073d69 MS |
3974 | /* Parse an unwind_save directive. |
3975 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 3976 | |
b99bd4ef | 3977 | static void |
fa073d69 | 3978 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 3979 | { |
c19d1205 ZW |
3980 | char *peek; |
3981 | struct reg_entry *reg; | |
3982 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 3983 | |
921e5f0a | 3984 | if (!unwind.proc_start) |
c921be7d | 3985 | as_bad (MISSING_FNSTART); |
921e5f0a | 3986 | |
c19d1205 ZW |
3987 | /* Figure out what sort of save we have. */ |
3988 | peek = input_line_pointer; | |
b99bd4ef | 3989 | |
c19d1205 | 3990 | if (*peek == '{') |
b99bd4ef | 3991 | { |
c19d1205 ZW |
3992 | had_brace = TRUE; |
3993 | peek++; | |
b99bd4ef NC |
3994 | } |
3995 | ||
c19d1205 | 3996 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 3997 | |
c19d1205 | 3998 | if (!reg) |
b99bd4ef | 3999 | { |
c19d1205 ZW |
4000 | as_bad (_("register expected")); |
4001 | ignore_rest_of_line (); | |
b99bd4ef NC |
4002 | return; |
4003 | } | |
4004 | ||
c19d1205 | 4005 | switch (reg->type) |
b99bd4ef | 4006 | { |
c19d1205 ZW |
4007 | case REG_TYPE_FN: |
4008 | if (had_brace) | |
4009 | { | |
4010 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4011 | ignore_rest_of_line (); | |
4012 | return; | |
4013 | } | |
93ac2687 | 4014 | input_line_pointer = peek; |
c19d1205 | 4015 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4016 | return; |
c19d1205 ZW |
4017 | |
4018 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
4019 | case REG_TYPE_VFD: |
4020 | if (arch_v6) | |
4021 | s_arm_unwind_save_vfp_armv6 (); | |
4022 | else | |
4023 | s_arm_unwind_save_vfp (); | |
4024 | return; | |
c19d1205 ZW |
4025 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
4026 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
4027 | ||
4028 | default: | |
4029 | as_bad (_(".unwind_save does not support this kind of register")); | |
4030 | ignore_rest_of_line (); | |
b99bd4ef | 4031 | } |
c19d1205 | 4032 | } |
b99bd4ef | 4033 | |
b99bd4ef | 4034 | |
c19d1205 ZW |
4035 | /* Parse an unwind_movsp directive. */ |
4036 | ||
4037 | static void | |
4038 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4039 | { | |
4040 | int reg; | |
4041 | valueT op; | |
4fa3602b | 4042 | int offset; |
c19d1205 | 4043 | |
921e5f0a | 4044 | if (!unwind.proc_start) |
c921be7d | 4045 | as_bad (MISSING_FNSTART); |
921e5f0a | 4046 | |
dcbf9037 | 4047 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4048 | if (reg == FAIL) |
b99bd4ef | 4049 | { |
9b7132d3 | 4050 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4051 | ignore_rest_of_line (); |
b99bd4ef NC |
4052 | return; |
4053 | } | |
4fa3602b PB |
4054 | |
4055 | /* Optional constant. */ | |
4056 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4057 | { | |
4058 | if (immediate_for_directive (&offset) == FAIL) | |
4059 | return; | |
4060 | } | |
4061 | else | |
4062 | offset = 0; | |
4063 | ||
c19d1205 | 4064 | demand_empty_rest_of_line (); |
b99bd4ef | 4065 | |
c19d1205 | 4066 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4067 | { |
c19d1205 | 4068 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4069 | return; |
4070 | } | |
4071 | ||
c19d1205 ZW |
4072 | if (unwind.fp_reg != REG_SP) |
4073 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4074 | |
c19d1205 ZW |
4075 | /* Generate opcode to restore the value. */ |
4076 | op = 0x90 | reg; | |
4077 | add_unwind_opcode (op, 1); | |
4078 | ||
4079 | /* Record the information for later. */ | |
4080 | unwind.fp_reg = reg; | |
4fa3602b | 4081 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4082 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4083 | } |
4084 | ||
c19d1205 ZW |
4085 | /* Parse an unwind_pad directive. */ |
4086 | ||
b05fe5cf | 4087 | static void |
c19d1205 | 4088 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4089 | { |
c19d1205 | 4090 | int offset; |
b05fe5cf | 4091 | |
921e5f0a | 4092 | if (!unwind.proc_start) |
c921be7d | 4093 | as_bad (MISSING_FNSTART); |
921e5f0a | 4094 | |
c19d1205 ZW |
4095 | if (immediate_for_directive (&offset) == FAIL) |
4096 | return; | |
b99bd4ef | 4097 | |
c19d1205 ZW |
4098 | if (offset & 3) |
4099 | { | |
4100 | as_bad (_("stack increment must be multiple of 4")); | |
4101 | ignore_rest_of_line (); | |
4102 | return; | |
4103 | } | |
b99bd4ef | 4104 | |
c19d1205 ZW |
4105 | /* Don't generate any opcodes, just record the details for later. */ |
4106 | unwind.frame_size += offset; | |
4107 | unwind.pending_offset += offset; | |
4108 | ||
4109 | demand_empty_rest_of_line (); | |
4110 | } | |
4111 | ||
4112 | /* Parse an unwind_setfp directive. */ | |
4113 | ||
4114 | static void | |
4115 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4116 | { |
c19d1205 ZW |
4117 | int sp_reg; |
4118 | int fp_reg; | |
4119 | int offset; | |
4120 | ||
921e5f0a | 4121 | if (!unwind.proc_start) |
c921be7d | 4122 | as_bad (MISSING_FNSTART); |
921e5f0a | 4123 | |
dcbf9037 | 4124 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4125 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4126 | sp_reg = FAIL; | |
4127 | else | |
dcbf9037 | 4128 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4129 | |
c19d1205 ZW |
4130 | if (fp_reg == FAIL || sp_reg == FAIL) |
4131 | { | |
4132 | as_bad (_("expected <reg>, <reg>")); | |
4133 | ignore_rest_of_line (); | |
4134 | return; | |
4135 | } | |
b99bd4ef | 4136 | |
c19d1205 ZW |
4137 | /* Optional constant. */ |
4138 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4139 | { | |
4140 | if (immediate_for_directive (&offset) == FAIL) | |
4141 | return; | |
4142 | } | |
4143 | else | |
4144 | offset = 0; | |
a737bd4d | 4145 | |
c19d1205 | 4146 | demand_empty_rest_of_line (); |
a737bd4d | 4147 | |
fdfde340 | 4148 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4149 | { |
c19d1205 ZW |
4150 | as_bad (_("register must be either sp or set by a previous" |
4151 | "unwind_movsp directive")); | |
4152 | return; | |
a737bd4d NC |
4153 | } |
4154 | ||
c19d1205 ZW |
4155 | /* Don't generate any opcodes, just record the information for later. */ |
4156 | unwind.fp_reg = fp_reg; | |
4157 | unwind.fp_used = 1; | |
fdfde340 | 4158 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4159 | unwind.fp_offset = unwind.frame_size - offset; |
4160 | else | |
4161 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4162 | } |
4163 | ||
c19d1205 ZW |
4164 | /* Parse an unwind_raw directive. */ |
4165 | ||
4166 | static void | |
4167 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4168 | { |
c19d1205 | 4169 | expressionS exp; |
708587a4 | 4170 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4171 | unsigned char op[16]; |
4172 | int count; | |
a737bd4d | 4173 | |
921e5f0a | 4174 | if (!unwind.proc_start) |
c921be7d | 4175 | as_bad (MISSING_FNSTART); |
921e5f0a | 4176 | |
c19d1205 ZW |
4177 | expression (&exp); |
4178 | if (exp.X_op == O_constant | |
4179 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4180 | { |
c19d1205 ZW |
4181 | unwind.frame_size += exp.X_add_number; |
4182 | expression (&exp); | |
4183 | } | |
4184 | else | |
4185 | exp.X_op = O_illegal; | |
a737bd4d | 4186 | |
c19d1205 ZW |
4187 | if (exp.X_op != O_constant) |
4188 | { | |
4189 | as_bad (_("expected <offset>, <opcode>")); | |
4190 | ignore_rest_of_line (); | |
4191 | return; | |
4192 | } | |
a737bd4d | 4193 | |
c19d1205 | 4194 | count = 0; |
a737bd4d | 4195 | |
c19d1205 ZW |
4196 | /* Parse the opcode. */ |
4197 | for (;;) | |
4198 | { | |
4199 | if (count >= 16) | |
4200 | { | |
4201 | as_bad (_("unwind opcode too long")); | |
4202 | ignore_rest_of_line (); | |
a737bd4d | 4203 | } |
c19d1205 | 4204 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4205 | { |
c19d1205 ZW |
4206 | as_bad (_("invalid unwind opcode")); |
4207 | ignore_rest_of_line (); | |
4208 | return; | |
a737bd4d | 4209 | } |
c19d1205 | 4210 | op[count++] = exp.X_add_number; |
a737bd4d | 4211 | |
c19d1205 ZW |
4212 | /* Parse the next byte. */ |
4213 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4214 | break; | |
a737bd4d | 4215 | |
c19d1205 ZW |
4216 | expression (&exp); |
4217 | } | |
b99bd4ef | 4218 | |
c19d1205 ZW |
4219 | /* Add the opcode bytes in reverse order. */ |
4220 | while (count--) | |
4221 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4222 | |
c19d1205 | 4223 | demand_empty_rest_of_line (); |
b99bd4ef | 4224 | } |
ee065d83 PB |
4225 | |
4226 | ||
4227 | /* Parse a .eabi_attribute directive. */ | |
4228 | ||
4229 | static void | |
4230 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4231 | { | |
ee3c0378 AS |
4232 | int tag = s_vendor_attribute (OBJ_ATTR_PROC); |
4233 | ||
4234 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4235 | attributes_set_explicitly[tag] = 1; | |
ee065d83 | 4236 | } |
8463be01 | 4237 | #endif /* OBJ_ELF */ |
ee065d83 PB |
4238 | |
4239 | static void s_arm_arch (int); | |
7a1d4c38 | 4240 | static void s_arm_object_arch (int); |
ee065d83 PB |
4241 | static void s_arm_cpu (int); |
4242 | static void s_arm_fpu (int); | |
b99bd4ef | 4243 | |
f0927246 NC |
4244 | #ifdef TE_PE |
4245 | ||
4246 | static void | |
5f4273c7 | 4247 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4248 | { |
4249 | expressionS exp; | |
4250 | ||
4251 | do | |
4252 | { | |
4253 | expression (&exp); | |
4254 | if (exp.X_op == O_symbol) | |
4255 | exp.X_op = O_secrel; | |
4256 | ||
4257 | emit_expr (&exp, 4); | |
4258 | } | |
4259 | while (*input_line_pointer++ == ','); | |
4260 | ||
4261 | input_line_pointer--; | |
4262 | demand_empty_rest_of_line (); | |
4263 | } | |
4264 | #endif /* TE_PE */ | |
4265 | ||
c19d1205 ZW |
4266 | /* This table describes all the machine specific pseudo-ops the assembler |
4267 | has to support. The fields are: | |
4268 | pseudo-op name without dot | |
4269 | function to call to execute this pseudo-op | |
4270 | Integer arg to pass to the function. */ | |
b99bd4ef | 4271 | |
c19d1205 | 4272 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4273 | { |
c19d1205 ZW |
4274 | /* Never called because '.req' does not start a line. */ |
4275 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4276 | /* Following two are likewise never called. */ |
4277 | { "dn", s_dn, 0 }, | |
4278 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4279 | { "unreq", s_unreq, 0 }, |
4280 | { "bss", s_bss, 0 }, | |
4281 | { "align", s_align, 0 }, | |
4282 | { "arm", s_arm, 0 }, | |
4283 | { "thumb", s_thumb, 0 }, | |
4284 | { "code", s_code, 0 }, | |
4285 | { "force_thumb", s_force_thumb, 0 }, | |
4286 | { "thumb_func", s_thumb_func, 0 }, | |
4287 | { "thumb_set", s_thumb_set, 0 }, | |
4288 | { "even", s_even, 0 }, | |
4289 | { "ltorg", s_ltorg, 0 }, | |
4290 | { "pool", s_ltorg, 0 }, | |
4291 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4292 | { "cpu", s_arm_cpu, 0 }, |
4293 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4294 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4295 | { "fpu", s_arm_fpu, 0 }, |
c19d1205 | 4296 | #ifdef OBJ_ELF |
c921be7d NC |
4297 | { "word", s_arm_elf_cons, 4 }, |
4298 | { "long", s_arm_elf_cons, 4 }, | |
4299 | { "inst.n", s_arm_elf_inst, 2 }, | |
4300 | { "inst.w", s_arm_elf_inst, 4 }, | |
4301 | { "inst", s_arm_elf_inst, 0 }, | |
4302 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4303 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4304 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4305 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4306 | { "personality", s_arm_unwind_personality, 0 }, | |
4307 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4308 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4309 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4310 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4311 | { "movsp", s_arm_unwind_movsp, 0 }, |
4312 | { "pad", s_arm_unwind_pad, 0 }, | |
4313 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4314 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4315 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
4316 | #else |
4317 | { "word", cons, 4}, | |
f0927246 NC |
4318 | |
4319 | /* These are used for dwarf. */ | |
4320 | {"2byte", cons, 2}, | |
4321 | {"4byte", cons, 4}, | |
4322 | {"8byte", cons, 8}, | |
4323 | /* These are used for dwarf2. */ | |
4324 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4325 | { "loc", dwarf2_directive_loc, 0 }, | |
4326 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4327 | #endif |
4328 | { "extend", float_cons, 'x' }, | |
4329 | { "ldouble", float_cons, 'x' }, | |
4330 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4331 | #ifdef TE_PE |
4332 | {"secrel32", pe_directive_secrel, 0}, | |
4333 | #endif | |
c19d1205 ZW |
4334 | { 0, 0, 0 } |
4335 | }; | |
4336 | \f | |
4337 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4338 | |
c19d1205 ZW |
4339 | /* Generic immediate-value read function for use in insn parsing. |
4340 | STR points to the beginning of the immediate (the leading #); | |
4341 | VAL receives the value; if the value is outside [MIN, MAX] | |
4342 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4343 | optional. */ | |
b99bd4ef | 4344 | |
c19d1205 ZW |
4345 | static int |
4346 | parse_immediate (char **str, int *val, int min, int max, | |
4347 | bfd_boolean prefix_opt) | |
4348 | { | |
4349 | expressionS exp; | |
4350 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4351 | if (exp.X_op != O_constant) | |
b99bd4ef | 4352 | { |
c19d1205 ZW |
4353 | inst.error = _("constant expression required"); |
4354 | return FAIL; | |
4355 | } | |
b99bd4ef | 4356 | |
c19d1205 ZW |
4357 | if (exp.X_add_number < min || exp.X_add_number > max) |
4358 | { | |
4359 | inst.error = _("immediate value out of range"); | |
4360 | return FAIL; | |
4361 | } | |
b99bd4ef | 4362 | |
c19d1205 ZW |
4363 | *val = exp.X_add_number; |
4364 | return SUCCESS; | |
4365 | } | |
b99bd4ef | 4366 | |
5287ad62 | 4367 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4368 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4369 | instructions. Puts the result directly in inst.operands[i]. */ |
4370 | ||
4371 | static int | |
4372 | parse_big_immediate (char **str, int i) | |
4373 | { | |
4374 | expressionS exp; | |
4375 | char *ptr = *str; | |
4376 | ||
4377 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
4378 | ||
4379 | if (exp.X_op == O_constant) | |
036dc3f7 PB |
4380 | { |
4381 | inst.operands[i].imm = exp.X_add_number & 0xffffffff; | |
4382 | /* If we're on a 64-bit host, then a 64-bit number can be returned using | |
4383 | O_constant. We have to be careful not to break compilation for | |
4384 | 32-bit X_add_number, though. */ | |
4385 | if ((exp.X_add_number & ~0xffffffffl) != 0) | |
4386 | { | |
4387 | /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */ | |
4388 | inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff; | |
4389 | inst.operands[i].regisimm = 1; | |
4390 | } | |
4391 | } | |
5287ad62 JB |
4392 | else if (exp.X_op == O_big |
4393 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32 | |
4394 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64) | |
4395 | { | |
4396 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
4397 | /* Bignums have their least significant bits in | |
4398 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
4399 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4400 | gas_assert (parts != 0); |
5287ad62 JB |
4401 | inst.operands[i].imm = 0; |
4402 | for (j = 0; j < parts; j++, idx++) | |
4403 | inst.operands[i].imm |= generic_bignum[idx] | |
4404 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4405 | inst.operands[i].reg = 0; | |
4406 | for (j = 0; j < parts; j++, idx++) | |
4407 | inst.operands[i].reg |= generic_bignum[idx] | |
4408 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4409 | inst.operands[i].regisimm = 1; | |
4410 | } | |
4411 | else | |
4412 | return FAIL; | |
5f4273c7 | 4413 | |
5287ad62 JB |
4414 | *str = ptr; |
4415 | ||
4416 | return SUCCESS; | |
4417 | } | |
4418 | ||
c19d1205 ZW |
4419 | /* Returns the pseudo-register number of an FPA immediate constant, |
4420 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4421 | |
c19d1205 ZW |
4422 | static int |
4423 | parse_fpa_immediate (char ** str) | |
4424 | { | |
4425 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4426 | char * save_in; | |
4427 | expressionS exp; | |
4428 | int i; | |
4429 | int j; | |
b99bd4ef | 4430 | |
c19d1205 ZW |
4431 | /* First try and match exact strings, this is to guarantee |
4432 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4433 | |
c19d1205 ZW |
4434 | for (i = 0; fp_const[i]; i++) |
4435 | { | |
4436 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4437 | { |
c19d1205 | 4438 | char *start = *str; |
b99bd4ef | 4439 | |
c19d1205 ZW |
4440 | *str += strlen (fp_const[i]); |
4441 | if (is_end_of_line[(unsigned char) **str]) | |
4442 | return i + 8; | |
4443 | *str = start; | |
4444 | } | |
4445 | } | |
b99bd4ef | 4446 | |
c19d1205 ZW |
4447 | /* Just because we didn't get a match doesn't mean that the constant |
4448 | isn't valid, just that it is in a format that we don't | |
4449 | automatically recognize. Try parsing it with the standard | |
4450 | expression routines. */ | |
b99bd4ef | 4451 | |
c19d1205 | 4452 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4453 | |
c19d1205 ZW |
4454 | /* Look for a raw floating point number. */ |
4455 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4456 | && is_end_of_line[(unsigned char) *save_in]) | |
4457 | { | |
4458 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4459 | { | |
4460 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4461 | { |
c19d1205 ZW |
4462 | if (words[j] != fp_values[i][j]) |
4463 | break; | |
b99bd4ef NC |
4464 | } |
4465 | ||
c19d1205 | 4466 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4467 | { |
c19d1205 ZW |
4468 | *str = save_in; |
4469 | return i + 8; | |
b99bd4ef NC |
4470 | } |
4471 | } | |
4472 | } | |
b99bd4ef | 4473 | |
c19d1205 ZW |
4474 | /* Try and parse a more complex expression, this will probably fail |
4475 | unless the code uses a floating point prefix (eg "0f"). */ | |
4476 | save_in = input_line_pointer; | |
4477 | input_line_pointer = *str; | |
4478 | if (expression (&exp) == absolute_section | |
4479 | && exp.X_op == O_big | |
4480 | && exp.X_add_number < 0) | |
4481 | { | |
4482 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4483 | Ditto for 15. */ | |
4484 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4485 | { | |
4486 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4487 | { | |
4488 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4489 | { | |
4490 | if (words[j] != fp_values[i][j]) | |
4491 | break; | |
4492 | } | |
b99bd4ef | 4493 | |
c19d1205 ZW |
4494 | if (j == MAX_LITTLENUMS) |
4495 | { | |
4496 | *str = input_line_pointer; | |
4497 | input_line_pointer = save_in; | |
4498 | return i + 8; | |
4499 | } | |
4500 | } | |
4501 | } | |
b99bd4ef NC |
4502 | } |
4503 | ||
c19d1205 ZW |
4504 | *str = input_line_pointer; |
4505 | input_line_pointer = save_in; | |
4506 | inst.error = _("invalid FPA immediate expression"); | |
4507 | return FAIL; | |
b99bd4ef NC |
4508 | } |
4509 | ||
136da414 JB |
4510 | /* Returns 1 if a number has "quarter-precision" float format |
4511 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4512 | ||
4513 | static int | |
4514 | is_quarter_float (unsigned imm) | |
4515 | { | |
4516 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4517 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4518 | } | |
4519 | ||
4520 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4521 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4522 | The zero and minus-zero cases need special handling, since they can't be |
4523 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4524 | loaded as integer constants. */ | |
136da414 JB |
4525 | |
4526 | static unsigned | |
4527 | parse_qfloat_immediate (char **ccp, int *immed) | |
4528 | { | |
4529 | char *str = *ccp; | |
c96612cc | 4530 | char *fpnum; |
136da414 | 4531 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4532 | int found_fpchar = 0; |
5f4273c7 | 4533 | |
136da414 | 4534 | skip_past_char (&str, '#'); |
5f4273c7 | 4535 | |
c96612cc JB |
4536 | /* We must not accidentally parse an integer as a floating-point number. Make |
4537 | sure that the value we parse is not an integer by checking for special | |
4538 | characters '.' or 'e'. | |
4539 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4540 | information isn't in a very usable state at parse time. */ | |
4541 | fpnum = str; | |
4542 | skip_whitespace (fpnum); | |
4543 | ||
4544 | if (strncmp (fpnum, "0x", 2) == 0) | |
4545 | return FAIL; | |
4546 | else | |
4547 | { | |
4548 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
4549 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') | |
4550 | { | |
4551 | found_fpchar = 1; | |
4552 | break; | |
4553 | } | |
4554 | ||
4555 | if (!found_fpchar) | |
4556 | return FAIL; | |
4557 | } | |
5f4273c7 | 4558 | |
136da414 JB |
4559 | if ((str = atof_ieee (str, 's', words)) != NULL) |
4560 | { | |
4561 | unsigned fpword = 0; | |
4562 | int i; | |
5f4273c7 | 4563 | |
136da414 JB |
4564 | /* Our FP word must be 32 bits (single-precision FP). */ |
4565 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4566 | { | |
4567 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4568 | fpword |= words[i]; | |
4569 | } | |
5f4273c7 | 4570 | |
c96612cc | 4571 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
136da414 JB |
4572 | *immed = fpword; |
4573 | else | |
4574 | return FAIL; | |
4575 | ||
4576 | *ccp = str; | |
5f4273c7 | 4577 | |
136da414 JB |
4578 | return SUCCESS; |
4579 | } | |
5f4273c7 | 4580 | |
136da414 JB |
4581 | return FAIL; |
4582 | } | |
4583 | ||
c19d1205 ZW |
4584 | /* Shift operands. */ |
4585 | enum shift_kind | |
b99bd4ef | 4586 | { |
c19d1205 ZW |
4587 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4588 | }; | |
b99bd4ef | 4589 | |
c19d1205 ZW |
4590 | struct asm_shift_name |
4591 | { | |
4592 | const char *name; | |
4593 | enum shift_kind kind; | |
4594 | }; | |
b99bd4ef | 4595 | |
c19d1205 ZW |
4596 | /* Third argument to parse_shift. */ |
4597 | enum parse_shift_mode | |
4598 | { | |
4599 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4600 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4601 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4602 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4603 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4604 | }; | |
b99bd4ef | 4605 | |
c19d1205 ZW |
4606 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4607 | This has three forms: | |
b99bd4ef | 4608 | |
c19d1205 ZW |
4609 | (LSL|LSR|ASL|ASR|ROR) Rs |
4610 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4611 | RRX | |
b99bd4ef | 4612 | |
c19d1205 ZW |
4613 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4614 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4615 | |
c19d1205 ZW |
4616 | static int |
4617 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4618 | { |
c19d1205 ZW |
4619 | const struct asm_shift_name *shift_name; |
4620 | enum shift_kind shift; | |
4621 | char *s = *str; | |
4622 | char *p = s; | |
4623 | int reg; | |
b99bd4ef | 4624 | |
c19d1205 ZW |
4625 | for (p = *str; ISALPHA (*p); p++) |
4626 | ; | |
b99bd4ef | 4627 | |
c19d1205 | 4628 | if (p == *str) |
b99bd4ef | 4629 | { |
c19d1205 ZW |
4630 | inst.error = _("shift expression expected"); |
4631 | return FAIL; | |
b99bd4ef NC |
4632 | } |
4633 | ||
21d799b5 NC |
4634 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
4635 | p - *str); | |
c19d1205 ZW |
4636 | |
4637 | if (shift_name == NULL) | |
b99bd4ef | 4638 | { |
c19d1205 ZW |
4639 | inst.error = _("shift expression expected"); |
4640 | return FAIL; | |
b99bd4ef NC |
4641 | } |
4642 | ||
c19d1205 | 4643 | shift = shift_name->kind; |
b99bd4ef | 4644 | |
c19d1205 ZW |
4645 | switch (mode) |
4646 | { | |
4647 | case NO_SHIFT_RESTRICT: | |
4648 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4649 | |
c19d1205 ZW |
4650 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4651 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4652 | { | |
4653 | inst.error = _("'LSL' or 'ASR' required"); | |
4654 | return FAIL; | |
4655 | } | |
4656 | break; | |
b99bd4ef | 4657 | |
c19d1205 ZW |
4658 | case SHIFT_LSL_IMMEDIATE: |
4659 | if (shift != SHIFT_LSL) | |
4660 | { | |
4661 | inst.error = _("'LSL' required"); | |
4662 | return FAIL; | |
4663 | } | |
4664 | break; | |
b99bd4ef | 4665 | |
c19d1205 ZW |
4666 | case SHIFT_ASR_IMMEDIATE: |
4667 | if (shift != SHIFT_ASR) | |
4668 | { | |
4669 | inst.error = _("'ASR' required"); | |
4670 | return FAIL; | |
4671 | } | |
4672 | break; | |
b99bd4ef | 4673 | |
c19d1205 ZW |
4674 | default: abort (); |
4675 | } | |
b99bd4ef | 4676 | |
c19d1205 ZW |
4677 | if (shift != SHIFT_RRX) |
4678 | { | |
4679 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4680 | skip_whitespace (p); | |
b99bd4ef | 4681 | |
c19d1205 | 4682 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4683 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4684 | { |
4685 | inst.operands[i].imm = reg; | |
4686 | inst.operands[i].immisreg = 1; | |
4687 | } | |
4688 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4689 | return FAIL; | |
4690 | } | |
4691 | inst.operands[i].shift_kind = shift; | |
4692 | inst.operands[i].shifted = 1; | |
4693 | *str = p; | |
4694 | return SUCCESS; | |
b99bd4ef NC |
4695 | } |
4696 | ||
c19d1205 | 4697 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4698 | |
c19d1205 ZW |
4699 | #<immediate> |
4700 | #<immediate>, <rotate> | |
4701 | <Rm> | |
4702 | <Rm>, <shift> | |
b99bd4ef | 4703 | |
c19d1205 ZW |
4704 | where <shift> is defined by parse_shift above, and <rotate> is a |
4705 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4706 | is deferred to md_apply_fix. */ |
b99bd4ef | 4707 | |
c19d1205 ZW |
4708 | static int |
4709 | parse_shifter_operand (char **str, int i) | |
4710 | { | |
4711 | int value; | |
4712 | expressionS expr; | |
b99bd4ef | 4713 | |
dcbf9037 | 4714 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4715 | { |
4716 | inst.operands[i].reg = value; | |
4717 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4718 | |
c19d1205 ZW |
4719 | /* parse_shift will override this if appropriate */ |
4720 | inst.reloc.exp.X_op = O_constant; | |
4721 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4722 | |
c19d1205 ZW |
4723 | if (skip_past_comma (str) == FAIL) |
4724 | return SUCCESS; | |
b99bd4ef | 4725 | |
c19d1205 ZW |
4726 | /* Shift operation on register. */ |
4727 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4728 | } |
4729 | ||
c19d1205 ZW |
4730 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4731 | return FAIL; | |
b99bd4ef | 4732 | |
c19d1205 | 4733 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4734 | { |
c19d1205 ZW |
4735 | /* #x, y -- ie explicit rotation by Y. */ |
4736 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
4737 | return FAIL; | |
b99bd4ef | 4738 | |
c19d1205 ZW |
4739 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
4740 | { | |
4741 | inst.error = _("constant expression expected"); | |
4742 | return FAIL; | |
4743 | } | |
b99bd4ef | 4744 | |
c19d1205 ZW |
4745 | value = expr.X_add_number; |
4746 | if (value < 0 || value > 30 || value % 2 != 0) | |
4747 | { | |
4748 | inst.error = _("invalid rotation"); | |
4749 | return FAIL; | |
4750 | } | |
4751 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4752 | { | |
4753 | inst.error = _("invalid constant"); | |
4754 | return FAIL; | |
4755 | } | |
09d92015 | 4756 | |
55cf6793 | 4757 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
4758 | inst.reloc.exp.X_add_number |
4759 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
4760 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
4761 | } |
4762 | ||
c19d1205 ZW |
4763 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4764 | inst.reloc.pc_rel = 0; | |
4765 | return SUCCESS; | |
09d92015 MM |
4766 | } |
4767 | ||
4962c51a MS |
4768 | /* Group relocation information. Each entry in the table contains the |
4769 | textual name of the relocation as may appear in assembler source | |
4770 | and must end with a colon. | |
4771 | Along with this textual name are the relocation codes to be used if | |
4772 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4773 | an LDR, an LDRS, or an LDC. */ | |
4774 | ||
4775 | struct group_reloc_table_entry | |
4776 | { | |
4777 | const char *name; | |
4778 | int alu_code; | |
4779 | int ldr_code; | |
4780 | int ldrs_code; | |
4781 | int ldc_code; | |
4782 | }; | |
4783 | ||
4784 | typedef enum | |
4785 | { | |
4786 | /* Varieties of non-ALU group relocation. */ | |
4787 | ||
4788 | GROUP_LDR, | |
4789 | GROUP_LDRS, | |
4790 | GROUP_LDC | |
4791 | } group_reloc_type; | |
4792 | ||
4793 | static struct group_reloc_table_entry group_reloc_table[] = | |
4794 | { /* Program counter relative: */ | |
4795 | { "pc_g0_nc", | |
4796 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4797 | 0, /* LDR */ | |
4798 | 0, /* LDRS */ | |
4799 | 0 }, /* LDC */ | |
4800 | { "pc_g0", | |
4801 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4802 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4803 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4804 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4805 | { "pc_g1_nc", | |
4806 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4807 | 0, /* LDR */ | |
4808 | 0, /* LDRS */ | |
4809 | 0 }, /* LDC */ | |
4810 | { "pc_g1", | |
4811 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4812 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4813 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4814 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4815 | { "pc_g2", | |
4816 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4817 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4818 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4819 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4820 | /* Section base relative */ | |
4821 | { "sb_g0_nc", | |
4822 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4823 | 0, /* LDR */ | |
4824 | 0, /* LDRS */ | |
4825 | 0 }, /* LDC */ | |
4826 | { "sb_g0", | |
4827 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4828 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4829 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4830 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4831 | { "sb_g1_nc", | |
4832 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4833 | 0, /* LDR */ | |
4834 | 0, /* LDRS */ | |
4835 | 0 }, /* LDC */ | |
4836 | { "sb_g1", | |
4837 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4838 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4839 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4840 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4841 | { "sb_g2", | |
4842 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
4843 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
4844 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
4845 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
4846 | ||
4847 | /* Given the address of a pointer pointing to the textual name of a group | |
4848 | relocation as may appear in assembler source, attempt to find its details | |
4849 | in group_reloc_table. The pointer will be updated to the character after | |
4850 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
4851 | otherwise. On success, *entry will be updated to point at the relevant | |
4852 | group_reloc_table entry. */ | |
4853 | ||
4854 | static int | |
4855 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
4856 | { | |
4857 | unsigned int i; | |
4858 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
4859 | { | |
4860 | int length = strlen (group_reloc_table[i].name); | |
4861 | ||
5f4273c7 NC |
4862 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
4863 | && (*str)[length] == ':') | |
4962c51a MS |
4864 | { |
4865 | *out = &group_reloc_table[i]; | |
4866 | *str += (length + 1); | |
4867 | return SUCCESS; | |
4868 | } | |
4869 | } | |
4870 | ||
4871 | return FAIL; | |
4872 | } | |
4873 | ||
4874 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
4875 | (as for parse_shifter_operand) where group relocations are allowed: | |
4876 | ||
4877 | #<immediate> | |
4878 | #<immediate>, <rotate> | |
4879 | #:<group_reloc>:<expression> | |
4880 | <Rm> | |
4881 | <Rm>, <shift> | |
4882 | ||
4883 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
4884 | The hashes are optional. | |
4885 | ||
4886 | Everything else is as for parse_shifter_operand. */ | |
4887 | ||
4888 | static parse_operand_result | |
4889 | parse_shifter_operand_group_reloc (char **str, int i) | |
4890 | { | |
4891 | /* Determine if we have the sequence of characters #: or just : | |
4892 | coming next. If we do, then we check for a group relocation. | |
4893 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
4894 | ||
4895 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
4896 | || (*str)[0] == ':') | |
4897 | { | |
4898 | struct group_reloc_table_entry *entry; | |
4899 | ||
4900 | if ((*str)[0] == '#') | |
4901 | (*str) += 2; | |
4902 | else | |
4903 | (*str)++; | |
4904 | ||
4905 | /* Try to parse a group relocation. Anything else is an error. */ | |
4906 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
4907 | { | |
4908 | inst.error = _("unknown group relocation"); | |
4909 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4910 | } | |
4911 | ||
4912 | /* We now have the group relocation table entry corresponding to | |
4913 | the name in the assembler source. Next, we parse the expression. */ | |
4914 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
4915 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4916 | ||
4917 | /* Record the relocation type (always the ALU variant here). */ | |
21d799b5 | 4918 | inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code; |
9c2799c2 | 4919 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
4920 | |
4921 | return PARSE_OPERAND_SUCCESS; | |
4922 | } | |
4923 | else | |
4924 | return parse_shifter_operand (str, i) == SUCCESS | |
4925 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
4926 | ||
4927 | /* Never reached. */ | |
4928 | } | |
4929 | ||
c19d1205 ZW |
4930 | /* Parse all forms of an ARM address expression. Information is written |
4931 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 4932 | |
c19d1205 | 4933 | Preindexed addressing (.preind=1): |
09d92015 | 4934 | |
c19d1205 ZW |
4935 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
4936 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4937 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4938 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4939 | |
c19d1205 | 4940 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 4941 | |
c19d1205 | 4942 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 4943 | |
c19d1205 ZW |
4944 | [Rn], #offset .reg=Rn .reloc.exp=offset |
4945 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4946 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4947 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4948 | |
c19d1205 | 4949 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 4950 | |
c19d1205 | 4951 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 4952 | |
c19d1205 | 4953 | Other: |
09d92015 | 4954 | |
c19d1205 ZW |
4955 | [Rn]{!} shorthand for [Rn,#0]{!} |
4956 | =immediate .isreg=0 .reloc.exp=immediate | |
4957 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 4958 | |
c19d1205 ZW |
4959 | It is the caller's responsibility to check for addressing modes not |
4960 | supported by the instruction, and to set inst.reloc.type. */ | |
4961 | ||
4962c51a MS |
4962 | static parse_operand_result |
4963 | parse_address_main (char **str, int i, int group_relocations, | |
4964 | group_reloc_type group_type) | |
09d92015 | 4965 | { |
c19d1205 ZW |
4966 | char *p = *str; |
4967 | int reg; | |
09d92015 | 4968 | |
c19d1205 | 4969 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 4970 | { |
c19d1205 ZW |
4971 | if (skip_past_char (&p, '=') == FAIL) |
4972 | { | |
4973 | /* bare address - translate to PC-relative offset */ | |
4974 | inst.reloc.pc_rel = 1; | |
4975 | inst.operands[i].reg = REG_PC; | |
4976 | inst.operands[i].isreg = 1; | |
4977 | inst.operands[i].preind = 1; | |
4978 | } | |
4979 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 4980 | |
c19d1205 | 4981 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 4982 | return PARSE_OPERAND_FAIL; |
09d92015 | 4983 | |
c19d1205 | 4984 | *str = p; |
4962c51a | 4985 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
4986 | } |
4987 | ||
dcbf9037 | 4988 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 4989 | { |
c19d1205 | 4990 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 4991 | return PARSE_OPERAND_FAIL; |
09d92015 | 4992 | } |
c19d1205 ZW |
4993 | inst.operands[i].reg = reg; |
4994 | inst.operands[i].isreg = 1; | |
09d92015 | 4995 | |
c19d1205 | 4996 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4997 | { |
c19d1205 | 4998 | inst.operands[i].preind = 1; |
09d92015 | 4999 | |
c19d1205 ZW |
5000 | if (*p == '+') p++; |
5001 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5002 | ||
dcbf9037 | 5003 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5004 | { |
c19d1205 ZW |
5005 | inst.operands[i].imm = reg; |
5006 | inst.operands[i].immisreg = 1; | |
5007 | ||
5008 | if (skip_past_comma (&p) == SUCCESS) | |
5009 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5010 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5011 | } |
5287ad62 JB |
5012 | else if (skip_past_char (&p, ':') == SUCCESS) |
5013 | { | |
5014 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5015 | code before we get to see it here. This may be subject to | |
5016 | change. */ | |
5017 | expressionS exp; | |
5018 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5019 | if (exp.X_op != O_constant) | |
5020 | { | |
5021 | inst.error = _("alignment must be constant"); | |
4962c51a | 5022 | return PARSE_OPERAND_FAIL; |
5287ad62 JB |
5023 | } |
5024 | inst.operands[i].imm = exp.X_add_number << 8; | |
5025 | inst.operands[i].immisalign = 1; | |
5026 | /* Alignments are not pre-indexes. */ | |
5027 | inst.operands[i].preind = 0; | |
5028 | } | |
c19d1205 ZW |
5029 | else |
5030 | { | |
5031 | if (inst.operands[i].negative) | |
5032 | { | |
5033 | inst.operands[i].negative = 0; | |
5034 | p--; | |
5035 | } | |
4962c51a | 5036 | |
5f4273c7 NC |
5037 | if (group_relocations |
5038 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5039 | { |
5040 | struct group_reloc_table_entry *entry; | |
5041 | ||
5042 | /* Skip over the #: or : sequence. */ | |
5043 | if (*p == '#') | |
5044 | p += 2; | |
5045 | else | |
5046 | p++; | |
5047 | ||
5048 | /* Try to parse a group relocation. Anything else is an | |
5049 | error. */ | |
5050 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
5051 | { | |
5052 | inst.error = _("unknown group relocation"); | |
5053 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5054 | } | |
5055 | ||
5056 | /* We now have the group relocation table entry corresponding to | |
5057 | the name in the assembler source. Next, we parse the | |
5058 | expression. */ | |
5059 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5060 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5061 | ||
5062 | /* Record the relocation type. */ | |
5063 | switch (group_type) | |
5064 | { | |
5065 | case GROUP_LDR: | |
21d799b5 | 5066 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code; |
4962c51a MS |
5067 | break; |
5068 | ||
5069 | case GROUP_LDRS: | |
21d799b5 | 5070 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code; |
4962c51a MS |
5071 | break; |
5072 | ||
5073 | case GROUP_LDC: | |
21d799b5 | 5074 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code; |
4962c51a MS |
5075 | break; |
5076 | ||
5077 | default: | |
9c2799c2 | 5078 | gas_assert (0); |
4962c51a MS |
5079 | } |
5080 | ||
5081 | if (inst.reloc.type == 0) | |
5082 | { | |
5083 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5084 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5085 | } | |
5086 | } | |
5087 | else | |
5088 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5089 | return PARSE_OPERAND_FAIL; | |
09d92015 MM |
5090 | } |
5091 | } | |
5092 | ||
c19d1205 | 5093 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5094 | { |
c19d1205 | 5095 | inst.error = _("']' expected"); |
4962c51a | 5096 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5097 | } |
5098 | ||
c19d1205 ZW |
5099 | if (skip_past_char (&p, '!') == SUCCESS) |
5100 | inst.operands[i].writeback = 1; | |
09d92015 | 5101 | |
c19d1205 | 5102 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5103 | { |
c19d1205 ZW |
5104 | if (skip_past_char (&p, '{') == SUCCESS) |
5105 | { | |
5106 | /* [Rn], {expr} - unindexed, with option */ | |
5107 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5108 | 0, 255, TRUE) == FAIL) |
4962c51a | 5109 | return PARSE_OPERAND_FAIL; |
09d92015 | 5110 | |
c19d1205 ZW |
5111 | if (skip_past_char (&p, '}') == FAIL) |
5112 | { | |
5113 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5114 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5115 | } |
5116 | if (inst.operands[i].preind) | |
5117 | { | |
5118 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5119 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5120 | } |
5121 | *str = p; | |
4962c51a | 5122 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5123 | } |
c19d1205 ZW |
5124 | else |
5125 | { | |
5126 | inst.operands[i].postind = 1; | |
5127 | inst.operands[i].writeback = 1; | |
09d92015 | 5128 | |
c19d1205 ZW |
5129 | if (inst.operands[i].preind) |
5130 | { | |
5131 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5132 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5133 | } |
09d92015 | 5134 | |
c19d1205 ZW |
5135 | if (*p == '+') p++; |
5136 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5137 | |
dcbf9037 | 5138 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5139 | { |
5287ad62 JB |
5140 | /* We might be using the immediate for alignment already. If we |
5141 | are, OR the register number into the low-order bits. */ | |
5142 | if (inst.operands[i].immisalign) | |
5143 | inst.operands[i].imm |= reg; | |
5144 | else | |
5145 | inst.operands[i].imm = reg; | |
c19d1205 | 5146 | inst.operands[i].immisreg = 1; |
a737bd4d | 5147 | |
c19d1205 ZW |
5148 | if (skip_past_comma (&p) == SUCCESS) |
5149 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5150 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5151 | } |
5152 | else | |
5153 | { | |
5154 | if (inst.operands[i].negative) | |
5155 | { | |
5156 | inst.operands[i].negative = 0; | |
5157 | p--; | |
5158 | } | |
5159 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5160 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5161 | } |
5162 | } | |
a737bd4d NC |
5163 | } |
5164 | ||
c19d1205 ZW |
5165 | /* If at this point neither .preind nor .postind is set, we have a |
5166 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5167 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5168 | { | |
5169 | inst.operands[i].preind = 1; | |
5170 | inst.reloc.exp.X_op = O_constant; | |
5171 | inst.reloc.exp.X_add_number = 0; | |
5172 | } | |
5173 | *str = p; | |
4962c51a MS |
5174 | return PARSE_OPERAND_SUCCESS; |
5175 | } | |
5176 | ||
5177 | static int | |
5178 | parse_address (char **str, int i) | |
5179 | { | |
21d799b5 | 5180 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
4962c51a MS |
5181 | ? SUCCESS : FAIL; |
5182 | } | |
5183 | ||
5184 | static parse_operand_result | |
5185 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5186 | { | |
5187 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5188 | } |
5189 | ||
b6895b4f PB |
5190 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5191 | static int | |
5192 | parse_half (char **str) | |
5193 | { | |
5194 | char * p; | |
5f4273c7 | 5195 | |
b6895b4f PB |
5196 | p = *str; |
5197 | skip_past_char (&p, '#'); | |
5f4273c7 | 5198 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5199 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5200 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5201 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5202 | ||
5203 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5204 | { | |
5205 | p += 9; | |
5f4273c7 | 5206 | skip_whitespace (p); |
b6895b4f PB |
5207 | } |
5208 | ||
5209 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5210 | return FAIL; | |
5211 | ||
5212 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5213 | { | |
5214 | if (inst.reloc.exp.X_op != O_constant) | |
5215 | { | |
5216 | inst.error = _("constant expression expected"); | |
5217 | return FAIL; | |
5218 | } | |
5219 | if (inst.reloc.exp.X_add_number < 0 | |
5220 | || inst.reloc.exp.X_add_number > 0xffff) | |
5221 | { | |
5222 | inst.error = _("immediate value out of range"); | |
5223 | return FAIL; | |
5224 | } | |
5225 | } | |
5226 | *str = p; | |
5227 | return SUCCESS; | |
5228 | } | |
5229 | ||
c19d1205 | 5230 | /* Miscellaneous. */ |
a737bd4d | 5231 | |
c19d1205 ZW |
5232 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5233 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5234 | static int | |
5235 | parse_psr (char **str) | |
09d92015 | 5236 | { |
c19d1205 ZW |
5237 | char *p; |
5238 | unsigned long psr_field; | |
62b3e311 PB |
5239 | const struct asm_psr *psr; |
5240 | char *start; | |
09d92015 | 5241 | |
c19d1205 ZW |
5242 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5243 | feature for ease of use and backwards compatibility. */ | |
5244 | p = *str; | |
62b3e311 | 5245 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 5246 | psr_field = SPSR_BIT; |
62b3e311 | 5247 | else if (strncasecmp (p, "CPSR", 4) == 0) |
c19d1205 ZW |
5248 | psr_field = 0; |
5249 | else | |
62b3e311 PB |
5250 | { |
5251 | start = p; | |
5252 | do | |
5253 | p++; | |
5254 | while (ISALNUM (*p) || *p == '_'); | |
5255 | ||
21d799b5 NC |
5256 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
5257 | p - start); | |
62b3e311 PB |
5258 | if (!psr) |
5259 | return FAIL; | |
09d92015 | 5260 | |
62b3e311 PB |
5261 | *str = p; |
5262 | return psr->field; | |
5263 | } | |
09d92015 | 5264 | |
62b3e311 | 5265 | p += 4; |
c19d1205 ZW |
5266 | if (*p == '_') |
5267 | { | |
5268 | /* A suffix follows. */ | |
c19d1205 ZW |
5269 | p++; |
5270 | start = p; | |
a737bd4d | 5271 | |
c19d1205 ZW |
5272 | do |
5273 | p++; | |
5274 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5275 | |
21d799b5 NC |
5276 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
5277 | p - start); | |
c19d1205 ZW |
5278 | if (!psr) |
5279 | goto error; | |
a737bd4d | 5280 | |
c19d1205 | 5281 | psr_field |= psr->field; |
a737bd4d | 5282 | } |
c19d1205 | 5283 | else |
a737bd4d | 5284 | { |
c19d1205 ZW |
5285 | if (ISALNUM (*p)) |
5286 | goto error; /* Garbage after "[CS]PSR". */ | |
5287 | ||
5288 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5289 | } |
c19d1205 ZW |
5290 | *str = p; |
5291 | return psr_field; | |
a737bd4d | 5292 | |
c19d1205 ZW |
5293 | error: |
5294 | inst.error = _("flag for {c}psr instruction expected"); | |
5295 | return FAIL; | |
a737bd4d NC |
5296 | } |
5297 | ||
c19d1205 ZW |
5298 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5299 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5300 | |
c19d1205 ZW |
5301 | static int |
5302 | parse_cps_flags (char **str) | |
a737bd4d | 5303 | { |
c19d1205 ZW |
5304 | int val = 0; |
5305 | int saw_a_flag = 0; | |
5306 | char *s = *str; | |
a737bd4d | 5307 | |
c19d1205 ZW |
5308 | for (;;) |
5309 | switch (*s++) | |
5310 | { | |
5311 | case '\0': case ',': | |
5312 | goto done; | |
a737bd4d | 5313 | |
c19d1205 ZW |
5314 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5315 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5316 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5317 | |
c19d1205 ZW |
5318 | default: |
5319 | inst.error = _("unrecognized CPS flag"); | |
5320 | return FAIL; | |
5321 | } | |
a737bd4d | 5322 | |
c19d1205 ZW |
5323 | done: |
5324 | if (saw_a_flag == 0) | |
a737bd4d | 5325 | { |
c19d1205 ZW |
5326 | inst.error = _("missing CPS flags"); |
5327 | return FAIL; | |
a737bd4d | 5328 | } |
a737bd4d | 5329 | |
c19d1205 ZW |
5330 | *str = s - 1; |
5331 | return val; | |
a737bd4d NC |
5332 | } |
5333 | ||
c19d1205 ZW |
5334 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
5335 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
5336 | |
5337 | static int | |
c19d1205 | 5338 | parse_endian_specifier (char **str) |
a737bd4d | 5339 | { |
c19d1205 ZW |
5340 | int little_endian; |
5341 | char *s = *str; | |
a737bd4d | 5342 | |
c19d1205 ZW |
5343 | if (strncasecmp (s, "BE", 2)) |
5344 | little_endian = 0; | |
5345 | else if (strncasecmp (s, "LE", 2)) | |
5346 | little_endian = 1; | |
5347 | else | |
a737bd4d | 5348 | { |
c19d1205 | 5349 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5350 | return FAIL; |
5351 | } | |
5352 | ||
c19d1205 | 5353 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 5354 | { |
c19d1205 | 5355 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5356 | return FAIL; |
5357 | } | |
5358 | ||
c19d1205 ZW |
5359 | *str = s + 2; |
5360 | return little_endian; | |
5361 | } | |
a737bd4d | 5362 | |
c19d1205 ZW |
5363 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
5364 | value suitable for poking into the rotate field of an sxt or sxta | |
5365 | instruction, or FAIL on error. */ | |
5366 | ||
5367 | static int | |
5368 | parse_ror (char **str) | |
5369 | { | |
5370 | int rot; | |
5371 | char *s = *str; | |
5372 | ||
5373 | if (strncasecmp (s, "ROR", 3) == 0) | |
5374 | s += 3; | |
5375 | else | |
a737bd4d | 5376 | { |
c19d1205 | 5377 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
5378 | return FAIL; |
5379 | } | |
c19d1205 ZW |
5380 | |
5381 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
5382 | return FAIL; | |
5383 | ||
5384 | switch (rot) | |
a737bd4d | 5385 | { |
c19d1205 ZW |
5386 | case 0: *str = s; return 0x0; |
5387 | case 8: *str = s; return 0x1; | |
5388 | case 16: *str = s; return 0x2; | |
5389 | case 24: *str = s; return 0x3; | |
5390 | ||
5391 | default: | |
5392 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
5393 | return FAIL; |
5394 | } | |
c19d1205 | 5395 | } |
a737bd4d | 5396 | |
c19d1205 ZW |
5397 | /* Parse a conditional code (from conds[] below). The value returned is in the |
5398 | range 0 .. 14, or FAIL. */ | |
5399 | static int | |
5400 | parse_cond (char **str) | |
5401 | { | |
c462b453 | 5402 | char *q; |
c19d1205 | 5403 | const struct asm_cond *c; |
c462b453 PB |
5404 | int n; |
5405 | /* Condition codes are always 2 characters, so matching up to | |
5406 | 3 characters is sufficient. */ | |
5407 | char cond[3]; | |
a737bd4d | 5408 | |
c462b453 PB |
5409 | q = *str; |
5410 | n = 0; | |
5411 | while (ISALPHA (*q) && n < 3) | |
5412 | { | |
e07e6e58 | 5413 | cond[n] = TOLOWER (*q); |
c462b453 PB |
5414 | q++; |
5415 | n++; | |
5416 | } | |
a737bd4d | 5417 | |
21d799b5 | 5418 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 5419 | if (!c) |
a737bd4d | 5420 | { |
c19d1205 | 5421 | inst.error = _("condition required"); |
a737bd4d NC |
5422 | return FAIL; |
5423 | } | |
5424 | ||
c19d1205 ZW |
5425 | *str = q; |
5426 | return c->value; | |
5427 | } | |
5428 | ||
62b3e311 PB |
5429 | /* Parse an option for a barrier instruction. Returns the encoding for the |
5430 | option, or FAIL. */ | |
5431 | static int | |
5432 | parse_barrier (char **str) | |
5433 | { | |
5434 | char *p, *q; | |
5435 | const struct asm_barrier_opt *o; | |
5436 | ||
5437 | p = q = *str; | |
5438 | while (ISALPHA (*q)) | |
5439 | q++; | |
5440 | ||
21d799b5 NC |
5441 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
5442 | q - p); | |
62b3e311 PB |
5443 | if (!o) |
5444 | return FAIL; | |
5445 | ||
5446 | *str = q; | |
5447 | return o->value; | |
5448 | } | |
5449 | ||
92e90b6e PB |
5450 | /* Parse the operands of a table branch instruction. Similar to a memory |
5451 | operand. */ | |
5452 | static int | |
5453 | parse_tb (char **str) | |
5454 | { | |
5455 | char * p = *str; | |
5456 | int reg; | |
5457 | ||
5458 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5459 | { |
5460 | inst.error = _("'[' expected"); | |
5461 | return FAIL; | |
5462 | } | |
92e90b6e | 5463 | |
dcbf9037 | 5464 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5465 | { |
5466 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5467 | return FAIL; | |
5468 | } | |
5469 | inst.operands[0].reg = reg; | |
5470 | ||
5471 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5472 | { |
5473 | inst.error = _("',' expected"); | |
5474 | return FAIL; | |
5475 | } | |
5f4273c7 | 5476 | |
dcbf9037 | 5477 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5478 | { |
5479 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5480 | return FAIL; | |
5481 | } | |
5482 | inst.operands[0].imm = reg; | |
5483 | ||
5484 | if (skip_past_comma (&p) == SUCCESS) | |
5485 | { | |
5486 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5487 | return FAIL; | |
5488 | if (inst.reloc.exp.X_add_number != 1) | |
5489 | { | |
5490 | inst.error = _("invalid shift"); | |
5491 | return FAIL; | |
5492 | } | |
5493 | inst.operands[0].shifted = 1; | |
5494 | } | |
5495 | ||
5496 | if (skip_past_char (&p, ']') == FAIL) | |
5497 | { | |
5498 | inst.error = _("']' expected"); | |
5499 | return FAIL; | |
5500 | } | |
5501 | *str = p; | |
5502 | return SUCCESS; | |
5503 | } | |
5504 | ||
5287ad62 JB |
5505 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5506 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5507 | Up to four operands may be read; this function handles setting the |
5508 | ".present" field for each read operand itself. | |
5287ad62 JB |
5509 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5510 | else returns FAIL. */ | |
5511 | ||
5512 | static int | |
5513 | parse_neon_mov (char **str, int *which_operand) | |
5514 | { | |
5515 | int i = *which_operand, val; | |
5516 | enum arm_reg_type rtype; | |
5517 | char *ptr = *str; | |
dcbf9037 | 5518 | struct neon_type_el optype; |
5f4273c7 | 5519 | |
dcbf9037 | 5520 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5521 | { |
5522 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5523 | inst.operands[i].reg = val; | |
5524 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5525 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5526 | inst.operands[i++].present = 1; |
5527 | ||
5528 | if (skip_past_comma (&ptr) == FAIL) | |
5529 | goto wanted_comma; | |
5f4273c7 | 5530 | |
dcbf9037 | 5531 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 | 5532 | goto wanted_arm; |
5f4273c7 | 5533 | |
5287ad62 JB |
5534 | inst.operands[i].reg = val; |
5535 | inst.operands[i].isreg = 1; | |
5536 | inst.operands[i].present = 1; | |
5537 | } | |
037e8744 | 5538 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5539 | != FAIL) |
5287ad62 JB |
5540 | { |
5541 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5542 | if (skip_past_comma (&ptr) == FAIL) | |
5543 | goto wanted_comma; | |
5f4273c7 | 5544 | |
5287ad62 JB |
5545 | inst.operands[i].reg = val; |
5546 | inst.operands[i].isreg = 1; | |
5547 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5548 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5549 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5550 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5551 | inst.operands[i++].present = 1; |
5552 | ||
dcbf9037 | 5553 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5554 | { |
037e8744 JB |
5555 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5556 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5557 | inst.operands[i].reg = val; |
5558 | inst.operands[i].isreg = 1; | |
037e8744 | 5559 | inst.operands[i].present = 1; |
5287ad62 JB |
5560 | |
5561 | if (rtype == REG_TYPE_NQ) | |
5562 | { | |
dcbf9037 | 5563 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5564 | return FAIL; |
5565 | } | |
037e8744 JB |
5566 | else if (rtype != REG_TYPE_VFS) |
5567 | { | |
5568 | i++; | |
5569 | if (skip_past_comma (&ptr) == FAIL) | |
5570 | goto wanted_comma; | |
5571 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5572 | goto wanted_arm; | |
5573 | inst.operands[i].reg = val; | |
5574 | inst.operands[i].isreg = 1; | |
5575 | inst.operands[i].present = 1; | |
5576 | } | |
5287ad62 | 5577 | } |
037e8744 JB |
5578 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
5579 | &optype)) != FAIL) | |
5287ad62 JB |
5580 | { |
5581 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5582 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5583 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5584 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5585 | |
5586 | inst.operands[i].reg = val; | |
5587 | inst.operands[i].isreg = 1; | |
5588 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5589 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5590 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5591 | inst.operands[i].vectype = optype; |
5287ad62 | 5592 | inst.operands[i].present = 1; |
5f4273c7 | 5593 | |
037e8744 JB |
5594 | if (skip_past_comma (&ptr) == SUCCESS) |
5595 | { | |
5596 | /* Case 15. */ | |
5597 | i++; | |
5598 | ||
5599 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5600 | goto wanted_arm; | |
5601 | ||
5602 | inst.operands[i].reg = val; | |
5603 | inst.operands[i].isreg = 1; | |
5604 | inst.operands[i++].present = 1; | |
5f4273c7 | 5605 | |
037e8744 JB |
5606 | if (skip_past_comma (&ptr) == FAIL) |
5607 | goto wanted_comma; | |
5f4273c7 | 5608 | |
037e8744 JB |
5609 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5610 | goto wanted_arm; | |
5f4273c7 | 5611 | |
037e8744 JB |
5612 | inst.operands[i].reg = val; |
5613 | inst.operands[i].isreg = 1; | |
5614 | inst.operands[i++].present = 1; | |
5615 | } | |
5287ad62 | 5616 | } |
4641781c PB |
5617 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
5618 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> | |
5619 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
5620 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5621 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5622 | inst.operands[i].immisfloat = 1; | |
5623 | else if (parse_big_immediate (&ptr, i) == SUCCESS) | |
5624 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> | |
5625 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
5626 | ; | |
5287ad62 JB |
5627 | else |
5628 | { | |
dcbf9037 | 5629 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
5630 | return FAIL; |
5631 | } | |
5632 | } | |
dcbf9037 | 5633 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5634 | { |
5635 | /* Cases 6, 7. */ | |
5636 | inst.operands[i].reg = val; | |
5637 | inst.operands[i].isreg = 1; | |
5638 | inst.operands[i++].present = 1; | |
5f4273c7 | 5639 | |
5287ad62 JB |
5640 | if (skip_past_comma (&ptr) == FAIL) |
5641 | goto wanted_comma; | |
5f4273c7 | 5642 | |
dcbf9037 | 5643 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5644 | { |
5645 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
5646 | inst.operands[i].reg = val; | |
5647 | inst.operands[i].isscalar = 1; | |
5648 | inst.operands[i].present = 1; | |
dcbf9037 | 5649 | inst.operands[i].vectype = optype; |
5287ad62 | 5650 | } |
dcbf9037 | 5651 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5652 | { |
5653 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
5654 | inst.operands[i].reg = val; | |
5655 | inst.operands[i].isreg = 1; | |
5656 | inst.operands[i++].present = 1; | |
5f4273c7 | 5657 | |
5287ad62 JB |
5658 | if (skip_past_comma (&ptr) == FAIL) |
5659 | goto wanted_comma; | |
5f4273c7 | 5660 | |
037e8744 | 5661 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 5662 | == FAIL) |
5287ad62 | 5663 | { |
037e8744 | 5664 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
5665 | return FAIL; |
5666 | } | |
5667 | ||
5668 | inst.operands[i].reg = val; | |
5669 | inst.operands[i].isreg = 1; | |
037e8744 JB |
5670 | inst.operands[i].isvec = 1; |
5671 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 5672 | inst.operands[i].vectype = optype; |
5287ad62 | 5673 | inst.operands[i].present = 1; |
5f4273c7 | 5674 | |
037e8744 JB |
5675 | if (rtype == REG_TYPE_VFS) |
5676 | { | |
5677 | /* Case 14. */ | |
5678 | i++; | |
5679 | if (skip_past_comma (&ptr) == FAIL) | |
5680 | goto wanted_comma; | |
5681 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
5682 | &optype)) == FAIL) | |
5683 | { | |
5684 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
5685 | return FAIL; | |
5686 | } | |
5687 | inst.operands[i].reg = val; | |
5688 | inst.operands[i].isreg = 1; | |
5689 | inst.operands[i].isvec = 1; | |
5690 | inst.operands[i].issingle = 1; | |
5691 | inst.operands[i].vectype = optype; | |
5692 | inst.operands[i].present = 1; | |
5693 | } | |
5694 | } | |
5695 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
5696 | != FAIL) | |
5697 | { | |
5698 | /* Case 13. */ | |
5699 | inst.operands[i].reg = val; | |
5700 | inst.operands[i].isreg = 1; | |
5701 | inst.operands[i].isvec = 1; | |
5702 | inst.operands[i].issingle = 1; | |
5703 | inst.operands[i].vectype = optype; | |
5704 | inst.operands[i++].present = 1; | |
5287ad62 JB |
5705 | } |
5706 | } | |
5707 | else | |
5708 | { | |
dcbf9037 | 5709 | first_error (_("parse error")); |
5287ad62 JB |
5710 | return FAIL; |
5711 | } | |
5712 | ||
5713 | /* Successfully parsed the operands. Update args. */ | |
5714 | *which_operand = i; | |
5715 | *str = ptr; | |
5716 | return SUCCESS; | |
5717 | ||
5f4273c7 | 5718 | wanted_comma: |
dcbf9037 | 5719 | first_error (_("expected comma")); |
5287ad62 | 5720 | return FAIL; |
5f4273c7 NC |
5721 | |
5722 | wanted_arm: | |
dcbf9037 | 5723 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 5724 | return FAIL; |
5287ad62 JB |
5725 | } |
5726 | ||
c19d1205 ZW |
5727 | /* Matcher codes for parse_operands. */ |
5728 | enum operand_parse_code | |
5729 | { | |
5730 | OP_stop, /* end of line */ | |
5731 | ||
5732 | OP_RR, /* ARM register */ | |
5733 | OP_RRnpc, /* ARM register, not r15 */ | |
5734 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
5735 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
5736 | OP_RCP, /* Coprocessor number */ | |
5737 | OP_RCN, /* Coprocessor register */ | |
5738 | OP_RF, /* FPA register */ | |
5739 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
5740 | OP_RVD, /* VFP double precision register (0..15) */ |
5741 | OP_RND, /* Neon double precision register (0..31) */ | |
5742 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 5743 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 5744 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 5745 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 5746 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
5747 | OP_RVC, /* VFP control register */ |
5748 | OP_RMF, /* Maverick F register */ | |
5749 | OP_RMD, /* Maverick D register */ | |
5750 | OP_RMFX, /* Maverick FX register */ | |
5751 | OP_RMDX, /* Maverick DX register */ | |
5752 | OP_RMAX, /* Maverick AX register */ | |
5753 | OP_RMDS, /* Maverick DSPSC register */ | |
5754 | OP_RIWR, /* iWMMXt wR register */ | |
5755 | OP_RIWC, /* iWMMXt wC register */ | |
5756 | OP_RIWG, /* iWMMXt wCG register */ | |
5757 | OP_RXA, /* XScale accumulator register */ | |
5758 | ||
5759 | OP_REGLST, /* ARM register list */ | |
5760 | OP_VRSLST, /* VFP single-precision register list */ | |
5761 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 5762 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
5763 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
5764 | OP_NSTRLST, /* Neon element/structure list */ | |
5765 | ||
5766 | OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */ | |
5767 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ | |
037e8744 | 5768 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 5769 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 5770 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
5771 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
5772 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
5773 | OP_VMOV, /* Neon VMOV operands. */ | |
5774 | OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */ | |
5775 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ | |
2d447fca | 5776 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
5777 | |
5778 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
5779 | OP_I7, /* immediate value 0 .. 7 */ |
5780 | OP_I15, /* 0 .. 15 */ | |
5781 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 5782 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
5783 | OP_I31, /* 0 .. 31 */ |
5784 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
5785 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
5786 | OP_I32z, /* 0 .. 32 */ |
5787 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 5788 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
5789 | OP_I64, /* 1 .. 64 */ |
5790 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 5791 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
5792 | |
5793 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
5794 | OP_I7b, /* 0 .. 7 */ | |
5795 | OP_I15b, /* 0 .. 15 */ | |
5796 | OP_I31b, /* 0 .. 31 */ | |
5797 | ||
5798 | OP_SH, /* shifter operand */ | |
4962c51a | 5799 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 5800 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
5801 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
5802 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
5803 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
5804 | OP_EXP, /* arbitrary expression */ |
5805 | OP_EXPi, /* same, with optional immediate prefix */ | |
5806 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 5807 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
5808 | |
5809 | OP_CPSF, /* CPS flags */ | |
5810 | OP_ENDI, /* Endianness specifier */ | |
5811 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
5812 | OP_COND, /* conditional code */ | |
92e90b6e | 5813 | OP_TB, /* Table branch. */ |
c19d1205 | 5814 | |
037e8744 JB |
5815 | OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */ |
5816 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ | |
5817 | ||
c19d1205 ZW |
5818 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
5819 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
5820 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
5821 | OP_RF_IF, /* FPA register or immediate */ | |
5822 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 5823 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
5824 | |
5825 | /* Optional operands. */ | |
5826 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
5827 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 5828 | OP_oI32b, /* 1 .. 32 */ |
c19d1205 ZW |
5829 | OP_oIffffb, /* 0 .. 65535 */ |
5830 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
5831 | ||
5832 | OP_oRR, /* ARM register */ | |
5833 | OP_oRRnpc, /* ARM register, not the PC */ | |
b6702015 | 5834 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
5835 | OP_oRND, /* Optional Neon double precision register */ |
5836 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5837 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 5838 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
5839 | OP_oSHll, /* LSL immediate */ |
5840 | OP_oSHar, /* ASR immediate */ | |
5841 | OP_oSHllar, /* LSL or ASR immediate */ | |
5842 | OP_oROR, /* ROR 0/8/16/24 */ | |
62b3e311 | 5843 | OP_oBARRIER, /* Option argument for a barrier instruction. */ |
c19d1205 ZW |
5844 | |
5845 | OP_FIRST_OPTIONAL = OP_oI7b | |
5846 | }; | |
a737bd4d | 5847 | |
c19d1205 ZW |
5848 | /* Generic instruction operand parser. This does no encoding and no |
5849 | semantic validation; it merely squirrels values away in the inst | |
5850 | structure. Returns SUCCESS or FAIL depending on whether the | |
5851 | specified grammar matched. */ | |
5852 | static int | |
ca3f61f7 | 5853 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
5854 | { |
5855 | unsigned const char *upat = pattern; | |
5856 | char *backtrack_pos = 0; | |
5857 | const char *backtrack_error = 0; | |
5858 | int i, val, backtrack_index = 0; | |
5287ad62 | 5859 | enum arm_reg_type rtype; |
4962c51a | 5860 | parse_operand_result result; |
c19d1205 | 5861 | |
e07e6e58 NC |
5862 | #define po_char_or_fail(chr) \ |
5863 | do \ | |
5864 | { \ | |
5865 | if (skip_past_char (&str, chr) == FAIL) \ | |
5866 | goto bad_args; \ | |
5867 | } \ | |
5868 | while (0) | |
c19d1205 | 5869 | |
e07e6e58 NC |
5870 | #define po_reg_or_fail(regtype) \ |
5871 | do \ | |
dcbf9037 | 5872 | { \ |
e07e6e58 NC |
5873 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
5874 | & inst.operands[i].vectype); \ | |
5875 | if (val == FAIL) \ | |
5876 | { \ | |
5877 | first_error (_(reg_expected_msgs[regtype])); \ | |
5878 | goto failure; \ | |
5879 | } \ | |
5880 | inst.operands[i].reg = val; \ | |
5881 | inst.operands[i].isreg = 1; \ | |
5882 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5883 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5884 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5885 | || rtype == REG_TYPE_VFD \ | |
5886 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 5887 | } \ |
e07e6e58 NC |
5888 | while (0) |
5889 | ||
5890 | #define po_reg_or_goto(regtype, label) \ | |
5891 | do \ | |
5892 | { \ | |
5893 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
5894 | & inst.operands[i].vectype); \ | |
5895 | if (val == FAIL) \ | |
5896 | goto label; \ | |
dcbf9037 | 5897 | \ |
e07e6e58 NC |
5898 | inst.operands[i].reg = val; \ |
5899 | inst.operands[i].isreg = 1; \ | |
5900 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5901 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5902 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5903 | || rtype == REG_TYPE_VFD \ | |
5904 | || rtype == REG_TYPE_NQ); \ | |
5905 | } \ | |
5906 | while (0) | |
5907 | ||
5908 | #define po_imm_or_fail(min, max, popt) \ | |
5909 | do \ | |
5910 | { \ | |
5911 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
5912 | goto failure; \ | |
5913 | inst.operands[i].imm = val; \ | |
5914 | } \ | |
5915 | while (0) | |
5916 | ||
5917 | #define po_scalar_or_goto(elsz, label) \ | |
5918 | do \ | |
5919 | { \ | |
5920 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
5921 | if (val == FAIL) \ | |
5922 | goto label; \ | |
5923 | inst.operands[i].reg = val; \ | |
5924 | inst.operands[i].isscalar = 1; \ | |
5925 | } \ | |
5926 | while (0) | |
5927 | ||
5928 | #define po_misc_or_fail(expr) \ | |
5929 | do \ | |
5930 | { \ | |
5931 | if (expr) \ | |
5932 | goto failure; \ | |
5933 | } \ | |
5934 | while (0) | |
5935 | ||
5936 | #define po_misc_or_fail_no_backtrack(expr) \ | |
5937 | do \ | |
5938 | { \ | |
5939 | result = expr; \ | |
5940 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
5941 | backtrack_pos = 0; \ | |
5942 | if (result != PARSE_OPERAND_SUCCESS) \ | |
5943 | goto failure; \ | |
5944 | } \ | |
5945 | while (0) | |
4962c51a | 5946 | |
c19d1205 ZW |
5947 | skip_whitespace (str); |
5948 | ||
5949 | for (i = 0; upat[i] != OP_stop; i++) | |
5950 | { | |
5951 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
5952 | { | |
5953 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 5954 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
5955 | backtrack_pos = str; |
5956 | backtrack_error = inst.error; | |
5957 | backtrack_index = i; | |
5958 | } | |
5959 | ||
b6702015 | 5960 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
5961 | po_char_or_fail (','); |
5962 | ||
5963 | switch (upat[i]) | |
5964 | { | |
5965 | /* Registers */ | |
5966 | case OP_oRRnpc: | |
5967 | case OP_RRnpc: | |
5968 | case OP_oRR: | |
5969 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
5970 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
5971 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
5972 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
5973 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
5974 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
5975 | case OP_oRND: |
5976 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
cd2cf30b PB |
5977 | case OP_RVC: |
5978 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
5979 | break; | |
5980 | /* Also accept generic coprocessor regs for unknown registers. */ | |
5981 | coproc_reg: | |
5982 | po_reg_or_fail (REG_TYPE_CN); | |
5983 | break; | |
c19d1205 ZW |
5984 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
5985 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
5986 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
5987 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
5988 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
5989 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
5990 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
5991 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
5992 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
5993 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
5994 | case OP_oRNQ: |
5995 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
5996 | case OP_oRNDQ: | |
5997 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
5998 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
5999 | case OP_oRNSDQ: | |
6000 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
6001 | |
6002 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6003 | scalars are accepted here, so deal with those in later code. */ | |
6004 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6005 | ||
6006 | /* WARNING: We can expand to two operands here. This has the potential | |
6007 | to totally confuse the backtracking mechanism! It will be OK at | |
6008 | least as long as we don't try to use optional args as well, | |
6009 | though. */ | |
6010 | case OP_NILO: | |
6011 | { | |
6012 | po_reg_or_goto (REG_TYPE_NDQ, try_imm); | |
466bbf93 | 6013 | inst.operands[i].present = 1; |
5287ad62 JB |
6014 | i++; |
6015 | skip_past_comma (&str); | |
6016 | po_reg_or_goto (REG_TYPE_NDQ, one_reg_only); | |
6017 | break; | |
6018 | one_reg_only: | |
6019 | /* Optional register operand was omitted. Unfortunately, it's in | |
6020 | operands[i-1] and we need it to be in inst.operands[i]. Fix that | |
6021 | here (this is a bit grotty). */ | |
6022 | inst.operands[i] = inst.operands[i-1]; | |
6023 | inst.operands[i-1].present = 0; | |
6024 | break; | |
6025 | try_imm: | |
036dc3f7 PB |
6026 | /* There's a possibility of getting a 64-bit immediate here, so |
6027 | we need special handling. */ | |
6028 | if (parse_big_immediate (&str, i) == FAIL) | |
6029 | { | |
6030 | inst.error = _("immediate value is out of range"); | |
6031 | goto failure; | |
6032 | } | |
5287ad62 JB |
6033 | } |
6034 | break; | |
6035 | ||
6036 | case OP_RNDQ_I0: | |
6037 | { | |
6038 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6039 | break; | |
6040 | try_imm0: | |
6041 | po_imm_or_fail (0, 0, TRUE); | |
6042 | } | |
6043 | break; | |
6044 | ||
037e8744 JB |
6045 | case OP_RVSD_I0: |
6046 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6047 | break; | |
6048 | ||
5287ad62 JB |
6049 | case OP_RR_RNSC: |
6050 | { | |
6051 | po_scalar_or_goto (8, try_rr); | |
6052 | break; | |
6053 | try_rr: | |
6054 | po_reg_or_fail (REG_TYPE_RN); | |
6055 | } | |
6056 | break; | |
6057 | ||
037e8744 JB |
6058 | case OP_RNSDQ_RNSC: |
6059 | { | |
6060 | po_scalar_or_goto (8, try_nsdq); | |
6061 | break; | |
6062 | try_nsdq: | |
6063 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6064 | } | |
6065 | break; | |
6066 | ||
5287ad62 JB |
6067 | case OP_RNDQ_RNSC: |
6068 | { | |
6069 | po_scalar_or_goto (8, try_ndq); | |
6070 | break; | |
6071 | try_ndq: | |
6072 | po_reg_or_fail (REG_TYPE_NDQ); | |
6073 | } | |
6074 | break; | |
6075 | ||
6076 | case OP_RND_RNSC: | |
6077 | { | |
6078 | po_scalar_or_goto (8, try_vfd); | |
6079 | break; | |
6080 | try_vfd: | |
6081 | po_reg_or_fail (REG_TYPE_VFD); | |
6082 | } | |
6083 | break; | |
6084 | ||
6085 | case OP_VMOV: | |
6086 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6087 | not careful then bad things might happen. */ | |
6088 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6089 | break; | |
6090 | ||
6091 | case OP_RNDQ_IMVNb: | |
6092 | { | |
6093 | po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm); | |
6094 | break; | |
6095 | try_mvnimm: | |
6096 | /* There's a possibility of getting a 64-bit immediate here, so | |
6097 | we need special handling. */ | |
6098 | if (parse_big_immediate (&str, i) == FAIL) | |
6099 | { | |
6100 | inst.error = _("immediate value is out of range"); | |
6101 | goto failure; | |
6102 | } | |
6103 | } | |
6104 | break; | |
6105 | ||
6106 | case OP_RNDQ_I63b: | |
6107 | { | |
6108 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6109 | break; | |
6110 | try_shimm: | |
6111 | po_imm_or_fail (0, 63, TRUE); | |
6112 | } | |
6113 | break; | |
c19d1205 ZW |
6114 | |
6115 | case OP_RRnpcb: | |
6116 | po_char_or_fail ('['); | |
6117 | po_reg_or_fail (REG_TYPE_RN); | |
6118 | po_char_or_fail (']'); | |
6119 | break; | |
a737bd4d | 6120 | |
c19d1205 | 6121 | case OP_RRw: |
b6702015 | 6122 | case OP_oRRw: |
c19d1205 ZW |
6123 | po_reg_or_fail (REG_TYPE_RN); |
6124 | if (skip_past_char (&str, '!') == SUCCESS) | |
6125 | inst.operands[i].writeback = 1; | |
6126 | break; | |
6127 | ||
6128 | /* Immediates */ | |
6129 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6130 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6131 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 6132 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6133 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6134 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 6135 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6136 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
6137 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6138 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6139 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6140 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6141 | |
6142 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6143 | case OP_oI7b: | |
6144 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6145 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6146 | case OP_oI31b: | |
6147 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 6148 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
c19d1205 ZW |
6149 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6150 | ||
6151 | /* Immediate variants */ | |
6152 | case OP_oI255c: | |
6153 | po_char_or_fail ('{'); | |
6154 | po_imm_or_fail (0, 255, TRUE); | |
6155 | po_char_or_fail ('}'); | |
6156 | break; | |
6157 | ||
6158 | case OP_I31w: | |
6159 | /* The expression parser chokes on a trailing !, so we have | |
6160 | to find it first and zap it. */ | |
6161 | { | |
6162 | char *s = str; | |
6163 | while (*s && *s != ',') | |
6164 | s++; | |
6165 | if (s[-1] == '!') | |
6166 | { | |
6167 | s[-1] = '\0'; | |
6168 | inst.operands[i].writeback = 1; | |
6169 | } | |
6170 | po_imm_or_fail (0, 31, TRUE); | |
6171 | if (str == s - 1) | |
6172 | str = s; | |
6173 | } | |
6174 | break; | |
6175 | ||
6176 | /* Expressions */ | |
6177 | case OP_EXPi: EXPi: | |
6178 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6179 | GE_OPT_PREFIX)); | |
6180 | break; | |
6181 | ||
6182 | case OP_EXP: | |
6183 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6184 | GE_NO_PREFIX)); | |
6185 | break; | |
6186 | ||
6187 | case OP_EXPr: EXPr: | |
6188 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6189 | GE_NO_PREFIX)); | |
6190 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6191 | { |
c19d1205 ZW |
6192 | val = parse_reloc (&str); |
6193 | if (val == -1) | |
6194 | { | |
6195 | inst.error = _("unrecognized relocation suffix"); | |
6196 | goto failure; | |
6197 | } | |
6198 | else if (val != BFD_RELOC_UNUSED) | |
6199 | { | |
6200 | inst.operands[i].imm = val; | |
6201 | inst.operands[i].hasreloc = 1; | |
6202 | } | |
a737bd4d | 6203 | } |
c19d1205 | 6204 | break; |
a737bd4d | 6205 | |
b6895b4f PB |
6206 | /* Operand for MOVW or MOVT. */ |
6207 | case OP_HALF: | |
6208 | po_misc_or_fail (parse_half (&str)); | |
6209 | break; | |
6210 | ||
e07e6e58 | 6211 | /* Register or expression. */ |
c19d1205 ZW |
6212 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6213 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6214 | |
e07e6e58 | 6215 | /* Register or immediate. */ |
c19d1205 ZW |
6216 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6217 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6218 | |
c19d1205 ZW |
6219 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6220 | IF: | |
6221 | if (!is_immediate_prefix (*str)) | |
6222 | goto bad_args; | |
6223 | str++; | |
6224 | val = parse_fpa_immediate (&str); | |
6225 | if (val == FAIL) | |
6226 | goto failure; | |
6227 | /* FPA immediates are encoded as registers 8-15. | |
6228 | parse_fpa_immediate has already applied the offset. */ | |
6229 | inst.operands[i].reg = val; | |
6230 | inst.operands[i].isreg = 1; | |
6231 | break; | |
09d92015 | 6232 | |
2d447fca JM |
6233 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6234 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6235 | ||
e07e6e58 | 6236 | /* Two kinds of register. */ |
c19d1205 ZW |
6237 | case OP_RIWR_RIWC: |
6238 | { | |
6239 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6240 | if (!rege |
6241 | || (rege->type != REG_TYPE_MMXWR | |
6242 | && rege->type != REG_TYPE_MMXWC | |
6243 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6244 | { |
6245 | inst.error = _("iWMMXt data or control register expected"); | |
6246 | goto failure; | |
6247 | } | |
6248 | inst.operands[i].reg = rege->number; | |
6249 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6250 | } | |
6251 | break; | |
09d92015 | 6252 | |
41adaa5c JM |
6253 | case OP_RIWC_RIWG: |
6254 | { | |
6255 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6256 | if (!rege | |
6257 | || (rege->type != REG_TYPE_MMXWC | |
6258 | && rege->type != REG_TYPE_MMXWCG)) | |
6259 | { | |
6260 | inst.error = _("iWMMXt control register expected"); | |
6261 | goto failure; | |
6262 | } | |
6263 | inst.operands[i].reg = rege->number; | |
6264 | inst.operands[i].isreg = 1; | |
6265 | } | |
6266 | break; | |
6267 | ||
c19d1205 ZW |
6268 | /* Misc */ |
6269 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6270 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6271 | case OP_oROR: val = parse_ror (&str); break; | |
6272 | case OP_PSR: val = parse_psr (&str); break; | |
6273 | case OP_COND: val = parse_cond (&str); break; | |
62b3e311 | 6274 | case OP_oBARRIER:val = parse_barrier (&str); break; |
c19d1205 | 6275 | |
037e8744 JB |
6276 | case OP_RVC_PSR: |
6277 | po_reg_or_goto (REG_TYPE_VFC, try_psr); | |
6278 | inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */ | |
6279 | break; | |
6280 | try_psr: | |
6281 | val = parse_psr (&str); | |
6282 | break; | |
6283 | ||
6284 | case OP_APSR_RR: | |
6285 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
6286 | break; | |
6287 | try_apsr: | |
6288 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
6289 | instruction). */ | |
6290 | if (strncasecmp (str, "APSR_", 5) == 0) | |
6291 | { | |
6292 | unsigned found = 0; | |
6293 | str += 5; | |
6294 | while (found < 15) | |
6295 | switch (*str++) | |
6296 | { | |
6297 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
6298 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
6299 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
6300 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
6301 | default: found = 16; | |
6302 | } | |
6303 | if (found != 15) | |
6304 | goto failure; | |
6305 | inst.operands[i].isvec = 1; | |
6306 | } | |
6307 | else | |
6308 | goto failure; | |
6309 | break; | |
6310 | ||
92e90b6e PB |
6311 | case OP_TB: |
6312 | po_misc_or_fail (parse_tb (&str)); | |
6313 | break; | |
6314 | ||
e07e6e58 | 6315 | /* Register lists. */ |
c19d1205 ZW |
6316 | case OP_REGLST: |
6317 | val = parse_reg_list (&str); | |
6318 | if (*str == '^') | |
6319 | { | |
6320 | inst.operands[1].writeback = 1; | |
6321 | str++; | |
6322 | } | |
6323 | break; | |
09d92015 | 6324 | |
c19d1205 | 6325 | case OP_VRSLST: |
5287ad62 | 6326 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 6327 | break; |
09d92015 | 6328 | |
c19d1205 | 6329 | case OP_VRDLST: |
5287ad62 | 6330 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 6331 | break; |
a737bd4d | 6332 | |
037e8744 JB |
6333 | case OP_VRSDLST: |
6334 | /* Allow Q registers too. */ | |
6335 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6336 | REGLIST_NEON_D); | |
6337 | if (val == FAIL) | |
6338 | { | |
6339 | inst.error = NULL; | |
6340 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6341 | REGLIST_VFP_S); | |
6342 | inst.operands[i].issingle = 1; | |
6343 | } | |
6344 | break; | |
6345 | ||
5287ad62 JB |
6346 | case OP_NRDLST: |
6347 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6348 | REGLIST_NEON_D); | |
6349 | break; | |
6350 | ||
6351 | case OP_NSTRLST: | |
dcbf9037 JB |
6352 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
6353 | &inst.operands[i].vectype); | |
5287ad62 JB |
6354 | break; |
6355 | ||
c19d1205 ZW |
6356 | /* Addressing modes */ |
6357 | case OP_ADDR: | |
6358 | po_misc_or_fail (parse_address (&str, i)); | |
6359 | break; | |
09d92015 | 6360 | |
4962c51a MS |
6361 | case OP_ADDRGLDR: |
6362 | po_misc_or_fail_no_backtrack ( | |
6363 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
6364 | break; | |
6365 | ||
6366 | case OP_ADDRGLDRS: | |
6367 | po_misc_or_fail_no_backtrack ( | |
6368 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
6369 | break; | |
6370 | ||
6371 | case OP_ADDRGLDC: | |
6372 | po_misc_or_fail_no_backtrack ( | |
6373 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
6374 | break; | |
6375 | ||
c19d1205 ZW |
6376 | case OP_SH: |
6377 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
6378 | break; | |
09d92015 | 6379 | |
4962c51a MS |
6380 | case OP_SHG: |
6381 | po_misc_or_fail_no_backtrack ( | |
6382 | parse_shifter_operand_group_reloc (&str, i)); | |
6383 | break; | |
6384 | ||
c19d1205 ZW |
6385 | case OP_oSHll: |
6386 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
6387 | break; | |
09d92015 | 6388 | |
c19d1205 ZW |
6389 | case OP_oSHar: |
6390 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
6391 | break; | |
09d92015 | 6392 | |
c19d1205 ZW |
6393 | case OP_oSHllar: |
6394 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
6395 | break; | |
09d92015 | 6396 | |
c19d1205 | 6397 | default: |
bd3ba5d1 | 6398 | as_fatal (_("unhandled operand code %d"), upat[i]); |
c19d1205 | 6399 | } |
09d92015 | 6400 | |
c19d1205 ZW |
6401 | /* Various value-based sanity checks and shared operations. We |
6402 | do not signal immediate failures for the register constraints; | |
6403 | this allows a syntax error to take precedence. */ | |
6404 | switch (upat[i]) | |
6405 | { | |
6406 | case OP_oRRnpc: | |
6407 | case OP_RRnpc: | |
6408 | case OP_RRnpcb: | |
6409 | case OP_RRw: | |
b6702015 | 6410 | case OP_oRRw: |
c19d1205 ZW |
6411 | case OP_RRnpc_I0: |
6412 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
6413 | inst.error = BAD_PC; | |
6414 | break; | |
09d92015 | 6415 | |
c19d1205 ZW |
6416 | case OP_CPSF: |
6417 | case OP_ENDI: | |
6418 | case OP_oROR: | |
6419 | case OP_PSR: | |
037e8744 | 6420 | case OP_RVC_PSR: |
c19d1205 | 6421 | case OP_COND: |
62b3e311 | 6422 | case OP_oBARRIER: |
c19d1205 ZW |
6423 | case OP_REGLST: |
6424 | case OP_VRSLST: | |
6425 | case OP_VRDLST: | |
037e8744 | 6426 | case OP_VRSDLST: |
5287ad62 JB |
6427 | case OP_NRDLST: |
6428 | case OP_NSTRLST: | |
c19d1205 ZW |
6429 | if (val == FAIL) |
6430 | goto failure; | |
6431 | inst.operands[i].imm = val; | |
6432 | break; | |
a737bd4d | 6433 | |
c19d1205 ZW |
6434 | default: |
6435 | break; | |
6436 | } | |
09d92015 | 6437 | |
c19d1205 ZW |
6438 | /* If we get here, this operand was successfully parsed. */ |
6439 | inst.operands[i].present = 1; | |
6440 | continue; | |
09d92015 | 6441 | |
c19d1205 | 6442 | bad_args: |
09d92015 | 6443 | inst.error = BAD_ARGS; |
c19d1205 ZW |
6444 | |
6445 | failure: | |
6446 | if (!backtrack_pos) | |
d252fdde PB |
6447 | { |
6448 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 6449 | default here just in case. */ |
d252fdde PB |
6450 | if (!inst.error) |
6451 | inst.error = _("syntax error"); | |
6452 | return FAIL; | |
6453 | } | |
c19d1205 ZW |
6454 | |
6455 | /* Do not backtrack over a trailing optional argument that | |
6456 | absorbed some text. We will only fail again, with the | |
6457 | 'garbage following instruction' error message, which is | |
6458 | probably less helpful than the current one. */ | |
6459 | if (backtrack_index == i && backtrack_pos != str | |
6460 | && upat[i+1] == OP_stop) | |
d252fdde PB |
6461 | { |
6462 | if (!inst.error) | |
6463 | inst.error = _("syntax error"); | |
6464 | return FAIL; | |
6465 | } | |
c19d1205 ZW |
6466 | |
6467 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
6468 | str = backtrack_pos; | |
6469 | inst.error = backtrack_error; | |
6470 | inst.operands[backtrack_index].present = 0; | |
6471 | i = backtrack_index; | |
6472 | backtrack_pos = 0; | |
09d92015 | 6473 | } |
09d92015 | 6474 | |
c19d1205 ZW |
6475 | /* Check that we have parsed all the arguments. */ |
6476 | if (*str != '\0' && !inst.error) | |
6477 | inst.error = _("garbage following instruction"); | |
09d92015 | 6478 | |
c19d1205 | 6479 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
6480 | } |
6481 | ||
c19d1205 ZW |
6482 | #undef po_char_or_fail |
6483 | #undef po_reg_or_fail | |
6484 | #undef po_reg_or_goto | |
6485 | #undef po_imm_or_fail | |
5287ad62 | 6486 | #undef po_scalar_or_fail |
e07e6e58 | 6487 | |
c19d1205 | 6488 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
6489 | #define constraint(expr, err) \ |
6490 | do \ | |
c19d1205 | 6491 | { \ |
e07e6e58 NC |
6492 | if (expr) \ |
6493 | { \ | |
6494 | inst.error = err; \ | |
6495 | return; \ | |
6496 | } \ | |
c19d1205 | 6497 | } \ |
e07e6e58 | 6498 | while (0) |
c19d1205 | 6499 | |
fdfde340 JM |
6500 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
6501 | instructions are unpredictable if these registers are used. This | |
6502 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
6503 | #define reject_bad_reg(reg) \ | |
6504 | do \ | |
6505 | if (reg == REG_SP || reg == REG_PC) \ | |
6506 | { \ | |
6507 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
6508 | return; \ | |
6509 | } \ | |
6510 | while (0) | |
6511 | ||
94206790 MM |
6512 | /* If REG is R13 (the stack pointer), warn that its use is |
6513 | deprecated. */ | |
6514 | #define warn_deprecated_sp(reg) \ | |
6515 | do \ | |
6516 | if (warn_on_deprecated && reg == REG_SP) \ | |
6517 | as_warn (_("use of r13 is deprecated")); \ | |
6518 | while (0) | |
6519 | ||
c19d1205 ZW |
6520 | /* Functions for operand encoding. ARM, then Thumb. */ |
6521 | ||
6522 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
6523 | ||
6524 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
6525 | return the encoded form. Otherwise, return FAIL. */ | |
6526 | ||
6527 | static unsigned int | |
6528 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6529 | { |
c19d1205 ZW |
6530 | unsigned int a, i; |
6531 | ||
6532 | for (i = 0; i < 32; i += 2) | |
6533 | if ((a = rotate_left (val, i)) <= 0xff) | |
6534 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6535 | ||
6536 | return FAIL; | |
09d92015 MM |
6537 | } |
6538 | ||
c19d1205 ZW |
6539 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6540 | return the encoded form. Otherwise, return FAIL. */ | |
6541 | static unsigned int | |
6542 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6543 | { |
c19d1205 | 6544 | unsigned int a, i; |
09d92015 | 6545 | |
9c3c69f2 | 6546 | if (val <= 0xff) |
c19d1205 | 6547 | return val; |
a737bd4d | 6548 | |
9c3c69f2 | 6549 | for (i = 1; i <= 24; i++) |
09d92015 | 6550 | { |
9c3c69f2 PB |
6551 | a = val >> i; |
6552 | if ((val & ~(0xff << i)) == 0) | |
6553 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6554 | } |
a737bd4d | 6555 | |
c19d1205 ZW |
6556 | a = val & 0xff; |
6557 | if (val == ((a << 16) | a)) | |
6558 | return 0x100 | a; | |
6559 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6560 | return 0x300 | a; | |
09d92015 | 6561 | |
c19d1205 ZW |
6562 | a = val & 0xff00; |
6563 | if (val == ((a << 16) | a)) | |
6564 | return 0x200 | (a >> 8); | |
a737bd4d | 6565 | |
c19d1205 | 6566 | return FAIL; |
09d92015 | 6567 | } |
5287ad62 | 6568 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6569 | |
6570 | static void | |
5287ad62 JB |
6571 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6572 | { | |
6573 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6574 | && reg > 15) | |
6575 | { | |
b1cc4aeb | 6576 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
5287ad62 JB |
6577 | { |
6578 | if (thumb_mode) | |
6579 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 6580 | fpu_vfp_ext_d32); |
5287ad62 JB |
6581 | else |
6582 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 6583 | fpu_vfp_ext_d32); |
5287ad62 JB |
6584 | } |
6585 | else | |
6586 | { | |
dcbf9037 | 6587 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
6588 | return; |
6589 | } | |
6590 | } | |
6591 | ||
c19d1205 | 6592 | switch (pos) |
09d92015 | 6593 | { |
c19d1205 ZW |
6594 | case VFP_REG_Sd: |
6595 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
6596 | break; | |
6597 | ||
6598 | case VFP_REG_Sn: | |
6599 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
6600 | break; | |
6601 | ||
6602 | case VFP_REG_Sm: | |
6603 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
6604 | break; | |
6605 | ||
5287ad62 JB |
6606 | case VFP_REG_Dd: |
6607 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
6608 | break; | |
5f4273c7 | 6609 | |
5287ad62 JB |
6610 | case VFP_REG_Dn: |
6611 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
6612 | break; | |
5f4273c7 | 6613 | |
5287ad62 JB |
6614 | case VFP_REG_Dm: |
6615 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
6616 | break; | |
6617 | ||
c19d1205 ZW |
6618 | default: |
6619 | abort (); | |
09d92015 | 6620 | } |
09d92015 MM |
6621 | } |
6622 | ||
c19d1205 | 6623 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 6624 | if any, is handled by md_apply_fix. */ |
09d92015 | 6625 | static void |
c19d1205 | 6626 | encode_arm_shift (int i) |
09d92015 | 6627 | { |
c19d1205 ZW |
6628 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
6629 | inst.instruction |= SHIFT_ROR << 5; | |
6630 | else | |
09d92015 | 6631 | { |
c19d1205 ZW |
6632 | inst.instruction |= inst.operands[i].shift_kind << 5; |
6633 | if (inst.operands[i].immisreg) | |
6634 | { | |
6635 | inst.instruction |= SHIFT_BY_REG; | |
6636 | inst.instruction |= inst.operands[i].imm << 8; | |
6637 | } | |
6638 | else | |
6639 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 6640 | } |
c19d1205 | 6641 | } |
09d92015 | 6642 | |
c19d1205 ZW |
6643 | static void |
6644 | encode_arm_shifter_operand (int i) | |
6645 | { | |
6646 | if (inst.operands[i].isreg) | |
09d92015 | 6647 | { |
c19d1205 ZW |
6648 | inst.instruction |= inst.operands[i].reg; |
6649 | encode_arm_shift (i); | |
09d92015 | 6650 | } |
c19d1205 ZW |
6651 | else |
6652 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
6653 | } |
6654 | ||
c19d1205 | 6655 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 6656 | static void |
c19d1205 | 6657 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 6658 | { |
9c2799c2 | 6659 | gas_assert (inst.operands[i].isreg); |
c19d1205 | 6660 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6661 | |
c19d1205 | 6662 | if (inst.operands[i].preind) |
09d92015 | 6663 | { |
c19d1205 ZW |
6664 | if (is_t) |
6665 | { | |
6666 | inst.error = _("instruction does not accept preindexed addressing"); | |
6667 | return; | |
6668 | } | |
6669 | inst.instruction |= PRE_INDEX; | |
6670 | if (inst.operands[i].writeback) | |
6671 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6672 | |
c19d1205 ZW |
6673 | } |
6674 | else if (inst.operands[i].postind) | |
6675 | { | |
9c2799c2 | 6676 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
6677 | if (is_t) |
6678 | inst.instruction |= WRITE_BACK; | |
6679 | } | |
6680 | else /* unindexed - only for coprocessor */ | |
09d92015 | 6681 | { |
c19d1205 | 6682 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
6683 | return; |
6684 | } | |
6685 | ||
c19d1205 ZW |
6686 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
6687 | && (((inst.instruction & 0x000f0000) >> 16) | |
6688 | == ((inst.instruction & 0x0000f000) >> 12))) | |
6689 | as_warn ((inst.instruction & LOAD_BIT) | |
6690 | ? _("destination register same as write-back base") | |
6691 | : _("source register same as write-back base")); | |
09d92015 MM |
6692 | } |
6693 | ||
c19d1205 ZW |
6694 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6695 | ARM-format mode 2 load or store instruction. If is_t is true, | |
6696 | reject forms that cannot be used with a T instruction (i.e. not | |
6697 | post-indexed). */ | |
a737bd4d | 6698 | static void |
c19d1205 | 6699 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 6700 | { |
c19d1205 | 6701 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6702 | |
c19d1205 | 6703 | if (inst.operands[i].immisreg) |
09d92015 | 6704 | { |
c19d1205 ZW |
6705 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
6706 | inst.instruction |= inst.operands[i].imm; | |
6707 | if (!inst.operands[i].negative) | |
6708 | inst.instruction |= INDEX_UP; | |
6709 | if (inst.operands[i].shifted) | |
6710 | { | |
6711 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
6712 | inst.instruction |= SHIFT_ROR << 5; | |
6713 | else | |
6714 | { | |
6715 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
6716 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
6717 | } | |
6718 | } | |
09d92015 | 6719 | } |
c19d1205 | 6720 | else /* immediate offset in inst.reloc */ |
09d92015 | 6721 | { |
c19d1205 ZW |
6722 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6723 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 6724 | } |
09d92015 MM |
6725 | } |
6726 | ||
c19d1205 ZW |
6727 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6728 | ARM-format mode 3 load or store instruction. Reject forms that | |
6729 | cannot be used with such instructions. If is_t is true, reject | |
6730 | forms that cannot be used with a T instruction (i.e. not | |
6731 | post-indexed). */ | |
6732 | static void | |
6733 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 6734 | { |
c19d1205 | 6735 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 6736 | { |
c19d1205 ZW |
6737 | inst.error = _("instruction does not accept scaled register index"); |
6738 | return; | |
09d92015 | 6739 | } |
a737bd4d | 6740 | |
c19d1205 | 6741 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6742 | |
c19d1205 ZW |
6743 | if (inst.operands[i].immisreg) |
6744 | { | |
6745 | inst.instruction |= inst.operands[i].imm; | |
6746 | if (!inst.operands[i].negative) | |
6747 | inst.instruction |= INDEX_UP; | |
6748 | } | |
6749 | else /* immediate offset in inst.reloc */ | |
6750 | { | |
6751 | inst.instruction |= HWOFFSET_IMM; | |
6752 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6753 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 6754 | } |
a737bd4d NC |
6755 | } |
6756 | ||
c19d1205 ZW |
6757 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6758 | ARM-format instruction. Reject all forms which cannot be encoded | |
6759 | into a coprocessor load/store instruction. If wb_ok is false, | |
6760 | reject use of writeback; if unind_ok is false, reject use of | |
6761 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
6762 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
6763 | (in which case it is preserved). */ | |
09d92015 | 6764 | |
c19d1205 ZW |
6765 | static int |
6766 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 6767 | { |
c19d1205 | 6768 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6769 | |
9c2799c2 | 6770 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 6771 | |
c19d1205 | 6772 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 6773 | { |
9c2799c2 | 6774 | gas_assert (!inst.operands[i].writeback); |
c19d1205 ZW |
6775 | if (!unind_ok) |
6776 | { | |
6777 | inst.error = _("instruction does not support unindexed addressing"); | |
6778 | return FAIL; | |
6779 | } | |
6780 | inst.instruction |= inst.operands[i].imm; | |
6781 | inst.instruction |= INDEX_UP; | |
6782 | return SUCCESS; | |
09d92015 | 6783 | } |
a737bd4d | 6784 | |
c19d1205 ZW |
6785 | if (inst.operands[i].preind) |
6786 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 6787 | |
c19d1205 | 6788 | if (inst.operands[i].writeback) |
09d92015 | 6789 | { |
c19d1205 ZW |
6790 | if (inst.operands[i].reg == REG_PC) |
6791 | { | |
6792 | inst.error = _("pc may not be used with write-back"); | |
6793 | return FAIL; | |
6794 | } | |
6795 | if (!wb_ok) | |
6796 | { | |
6797 | inst.error = _("instruction does not support writeback"); | |
6798 | return FAIL; | |
6799 | } | |
6800 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6801 | } |
a737bd4d | 6802 | |
c19d1205 | 6803 | if (reloc_override) |
21d799b5 | 6804 | inst.reloc.type = (bfd_reloc_code_real_type) reloc_override; |
4962c51a MS |
6805 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
6806 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
6807 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
6808 | { | |
6809 | if (thumb_mode) | |
6810 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
6811 | else | |
6812 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
6813 | } | |
6814 | ||
c19d1205 ZW |
6815 | return SUCCESS; |
6816 | } | |
a737bd4d | 6817 | |
c19d1205 ZW |
6818 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
6819 | Determine whether it can be performed with a move instruction; if | |
6820 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
6821 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
6822 | load and return FALSE. If this is not a valid thing to do in the | |
6823 | current context, set inst.error and return TRUE. | |
a737bd4d | 6824 | |
c19d1205 ZW |
6825 | inst.operands[i] describes the destination register. */ |
6826 | ||
c921be7d | 6827 | static bfd_boolean |
c19d1205 ZW |
6828 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) |
6829 | { | |
53365c0d PB |
6830 | unsigned long tbit; |
6831 | ||
6832 | if (thumb_p) | |
6833 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
6834 | else | |
6835 | tbit = LOAD_BIT; | |
6836 | ||
6837 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 6838 | { |
c19d1205 | 6839 | inst.error = _("invalid pseudo operation"); |
c921be7d | 6840 | return TRUE; |
09d92015 | 6841 | } |
c19d1205 | 6842 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
6843 | { |
6844 | inst.error = _("constant expression expected"); | |
c921be7d | 6845 | return TRUE; |
09d92015 | 6846 | } |
c19d1205 | 6847 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 6848 | { |
c19d1205 ZW |
6849 | if (thumb_p) |
6850 | { | |
53365c0d | 6851 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
6852 | { |
6853 | /* This can be done with a mov(1) instruction. */ | |
6854 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
6855 | inst.instruction |= inst.reloc.exp.X_add_number; | |
c921be7d | 6856 | return TRUE; |
c19d1205 ZW |
6857 | } |
6858 | } | |
6859 | else | |
6860 | { | |
6861 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
6862 | if (value != FAIL) | |
6863 | { | |
6864 | /* This can be done with a mov instruction. */ | |
6865 | inst.instruction &= LITERAL_MASK; | |
6866 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
6867 | inst.instruction |= value & 0xfff; | |
c921be7d | 6868 | return TRUE; |
c19d1205 | 6869 | } |
09d92015 | 6870 | |
c19d1205 ZW |
6871 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
6872 | if (value != FAIL) | |
6873 | { | |
6874 | /* This can be done with a mvn instruction. */ | |
6875 | inst.instruction &= LITERAL_MASK; | |
6876 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
6877 | inst.instruction |= value & 0xfff; | |
c921be7d | 6878 | return TRUE; |
c19d1205 ZW |
6879 | } |
6880 | } | |
09d92015 MM |
6881 | } |
6882 | ||
c19d1205 ZW |
6883 | if (add_to_lit_pool () == FAIL) |
6884 | { | |
6885 | inst.error = _("literal pool insertion failed"); | |
c921be7d | 6886 | return TRUE; |
c19d1205 ZW |
6887 | } |
6888 | inst.operands[1].reg = REG_PC; | |
6889 | inst.operands[1].isreg = 1; | |
6890 | inst.operands[1].preind = 1; | |
6891 | inst.reloc.pc_rel = 1; | |
6892 | inst.reloc.type = (thumb_p | |
6893 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
6894 | : (mode_3 | |
6895 | ? BFD_RELOC_ARM_HWLITERAL | |
6896 | : BFD_RELOC_ARM_LITERAL)); | |
c921be7d | 6897 | return FALSE; |
09d92015 MM |
6898 | } |
6899 | ||
5f4273c7 | 6900 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
6901 | First some generics; their names are taken from the conventional |
6902 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 6903 | |
a737bd4d | 6904 | static void |
c19d1205 | 6905 | do_noargs (void) |
09d92015 | 6906 | { |
c19d1205 | 6907 | } |
a737bd4d | 6908 | |
c19d1205 ZW |
6909 | static void |
6910 | do_rd (void) | |
6911 | { | |
6912 | inst.instruction |= inst.operands[0].reg << 12; | |
6913 | } | |
a737bd4d | 6914 | |
c19d1205 ZW |
6915 | static void |
6916 | do_rd_rm (void) | |
6917 | { | |
6918 | inst.instruction |= inst.operands[0].reg << 12; | |
6919 | inst.instruction |= inst.operands[1].reg; | |
6920 | } | |
09d92015 | 6921 | |
c19d1205 ZW |
6922 | static void |
6923 | do_rd_rn (void) | |
6924 | { | |
6925 | inst.instruction |= inst.operands[0].reg << 12; | |
6926 | inst.instruction |= inst.operands[1].reg << 16; | |
6927 | } | |
a737bd4d | 6928 | |
c19d1205 ZW |
6929 | static void |
6930 | do_rn_rd (void) | |
6931 | { | |
6932 | inst.instruction |= inst.operands[0].reg << 16; | |
6933 | inst.instruction |= inst.operands[1].reg << 12; | |
6934 | } | |
09d92015 | 6935 | |
c19d1205 ZW |
6936 | static void |
6937 | do_rd_rm_rn (void) | |
6938 | { | |
9a64e435 | 6939 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 6940 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 PB |
6941 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
6942 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
6943 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
6944 | inst.instruction |= inst.operands[0].reg << 12; |
6945 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 6946 | inst.instruction |= Rn << 16; |
c19d1205 | 6947 | } |
09d92015 | 6948 | |
c19d1205 ZW |
6949 | static void |
6950 | do_rd_rn_rm (void) | |
6951 | { | |
6952 | inst.instruction |= inst.operands[0].reg << 12; | |
6953 | inst.instruction |= inst.operands[1].reg << 16; | |
6954 | inst.instruction |= inst.operands[2].reg; | |
6955 | } | |
a737bd4d | 6956 | |
c19d1205 ZW |
6957 | static void |
6958 | do_rm_rd_rn (void) | |
6959 | { | |
6960 | inst.instruction |= inst.operands[0].reg; | |
6961 | inst.instruction |= inst.operands[1].reg << 12; | |
6962 | inst.instruction |= inst.operands[2].reg << 16; | |
6963 | } | |
09d92015 | 6964 | |
c19d1205 ZW |
6965 | static void |
6966 | do_imm0 (void) | |
6967 | { | |
6968 | inst.instruction |= inst.operands[0].imm; | |
6969 | } | |
09d92015 | 6970 | |
c19d1205 ZW |
6971 | static void |
6972 | do_rd_cpaddr (void) | |
6973 | { | |
6974 | inst.instruction |= inst.operands[0].reg << 12; | |
6975 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 6976 | } |
a737bd4d | 6977 | |
c19d1205 ZW |
6978 | /* ARM instructions, in alphabetical order by function name (except |
6979 | that wrapper functions appear immediately after the function they | |
6980 | wrap). */ | |
09d92015 | 6981 | |
c19d1205 ZW |
6982 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
6983 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
6984 | |
6985 | static void | |
c19d1205 | 6986 | do_adr (void) |
09d92015 | 6987 | { |
c19d1205 | 6988 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 6989 | |
c19d1205 ZW |
6990 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6991 | out to be negative. */ | |
6992 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 6993 | inst.reloc.pc_rel = 1; |
2fc8bdac | 6994 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 6995 | } |
b99bd4ef | 6996 | |
c19d1205 ZW |
6997 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
6998 | into a relative address of the form: | |
6999 | add rd, pc, #low(label-.-8)" | |
7000 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 7001 | |
c19d1205 ZW |
7002 | static void |
7003 | do_adrl (void) | |
7004 | { | |
7005 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 7006 | |
c19d1205 ZW |
7007 | /* Frag hacking will turn this into a sub instruction if the offset turns |
7008 | out to be negative. */ | |
7009 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
7010 | inst.reloc.pc_rel = 1; |
7011 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 7012 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
7013 | } |
7014 | ||
b99bd4ef | 7015 | static void |
c19d1205 | 7016 | do_arit (void) |
b99bd4ef | 7017 | { |
c19d1205 ZW |
7018 | if (!inst.operands[1].present) |
7019 | inst.operands[1].reg = inst.operands[0].reg; | |
7020 | inst.instruction |= inst.operands[0].reg << 12; | |
7021 | inst.instruction |= inst.operands[1].reg << 16; | |
7022 | encode_arm_shifter_operand (2); | |
7023 | } | |
b99bd4ef | 7024 | |
62b3e311 PB |
7025 | static void |
7026 | do_barrier (void) | |
7027 | { | |
7028 | if (inst.operands[0].present) | |
7029 | { | |
7030 | constraint ((inst.instruction & 0xf0) != 0x40 | |
7031 | && inst.operands[0].imm != 0xf, | |
bd3ba5d1 | 7032 | _("bad barrier type")); |
62b3e311 PB |
7033 | inst.instruction |= inst.operands[0].imm; |
7034 | } | |
7035 | else | |
7036 | inst.instruction |= 0xf; | |
7037 | } | |
7038 | ||
c19d1205 ZW |
7039 | static void |
7040 | do_bfc (void) | |
7041 | { | |
7042 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
7043 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7044 | /* The instruction encoding stores the LSB and MSB, | |
7045 | not the LSB and width. */ | |
7046 | inst.instruction |= inst.operands[0].reg << 12; | |
7047 | inst.instruction |= inst.operands[1].imm << 7; | |
7048 | inst.instruction |= (msb - 1) << 16; | |
7049 | } | |
b99bd4ef | 7050 | |
c19d1205 ZW |
7051 | static void |
7052 | do_bfi (void) | |
7053 | { | |
7054 | unsigned int msb; | |
b99bd4ef | 7055 | |
c19d1205 ZW |
7056 | /* #0 in second position is alternative syntax for bfc, which is |
7057 | the same instruction but with REG_PC in the Rm field. */ | |
7058 | if (!inst.operands[1].isreg) | |
7059 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 7060 | |
c19d1205 ZW |
7061 | msb = inst.operands[2].imm + inst.operands[3].imm; |
7062 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7063 | /* The instruction encoding stores the LSB and MSB, | |
7064 | not the LSB and width. */ | |
7065 | inst.instruction |= inst.operands[0].reg << 12; | |
7066 | inst.instruction |= inst.operands[1].reg; | |
7067 | inst.instruction |= inst.operands[2].imm << 7; | |
7068 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
7069 | } |
7070 | ||
b99bd4ef | 7071 | static void |
c19d1205 | 7072 | do_bfx (void) |
b99bd4ef | 7073 | { |
c19d1205 ZW |
7074 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
7075 | _("bit-field extends past end of register")); | |
7076 | inst.instruction |= inst.operands[0].reg << 12; | |
7077 | inst.instruction |= inst.operands[1].reg; | |
7078 | inst.instruction |= inst.operands[2].imm << 7; | |
7079 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
7080 | } | |
09d92015 | 7081 | |
c19d1205 ZW |
7082 | /* ARM V5 breakpoint instruction (argument parse) |
7083 | BKPT <16 bit unsigned immediate> | |
7084 | Instruction is not conditional. | |
7085 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
7086 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 7087 | |
c19d1205 ZW |
7088 | static void |
7089 | do_bkpt (void) | |
7090 | { | |
7091 | /* Top 12 of 16 bits to bits 19:8. */ | |
7092 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 7093 | |
c19d1205 ZW |
7094 | /* Bottom 4 of 16 bits to bits 3:0. */ |
7095 | inst.instruction |= inst.operands[0].imm & 0xf; | |
7096 | } | |
09d92015 | 7097 | |
c19d1205 ZW |
7098 | static void |
7099 | encode_branch (int default_reloc) | |
7100 | { | |
7101 | if (inst.operands[0].hasreloc) | |
7102 | { | |
7103 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
7104 | _("the only suffix valid here is '(plt)'")); | |
267bf995 | 7105 | inst.reloc.type = BFD_RELOC_ARM_PLT32; |
c19d1205 | 7106 | } |
b99bd4ef | 7107 | else |
c19d1205 | 7108 | { |
21d799b5 | 7109 | inst.reloc.type = (bfd_reloc_code_real_type) default_reloc; |
c19d1205 | 7110 | } |
2fc8bdac | 7111 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
7112 | } |
7113 | ||
b99bd4ef | 7114 | static void |
c19d1205 | 7115 | do_branch (void) |
b99bd4ef | 7116 | { |
39b41c9c PB |
7117 | #ifdef OBJ_ELF |
7118 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7119 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7120 | else | |
7121 | #endif | |
7122 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
7123 | } | |
7124 | ||
7125 | static void | |
7126 | do_bl (void) | |
7127 | { | |
7128 | #ifdef OBJ_ELF | |
7129 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7130 | { | |
7131 | if (inst.cond == COND_ALWAYS) | |
7132 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
7133 | else | |
7134 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7135 | } | |
7136 | else | |
7137 | #endif | |
7138 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 7139 | } |
b99bd4ef | 7140 | |
c19d1205 ZW |
7141 | /* ARM V5 branch-link-exchange instruction (argument parse) |
7142 | BLX <target_addr> ie BLX(1) | |
7143 | BLX{<condition>} <Rm> ie BLX(2) | |
7144 | Unfortunately, there are two different opcodes for this mnemonic. | |
7145 | So, the insns[].value is not used, and the code here zaps values | |
7146 | into inst.instruction. | |
7147 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 7148 | |
c19d1205 ZW |
7149 | static void |
7150 | do_blx (void) | |
7151 | { | |
7152 | if (inst.operands[0].isreg) | |
b99bd4ef | 7153 | { |
c19d1205 ZW |
7154 | /* Arg is a register; the opcode provided by insns[] is correct. |
7155 | It is not illegal to do "blx pc", just useless. */ | |
7156 | if (inst.operands[0].reg == REG_PC) | |
7157 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 7158 | |
c19d1205 ZW |
7159 | inst.instruction |= inst.operands[0].reg; |
7160 | } | |
7161 | else | |
b99bd4ef | 7162 | { |
c19d1205 | 7163 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
7164 | conditionally, and the opcode must be adjusted. |
7165 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
7166 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 7167 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 7168 | inst.instruction = 0xfa000000; |
267bf995 | 7169 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 7170 | } |
c19d1205 ZW |
7171 | } |
7172 | ||
7173 | static void | |
7174 | do_bx (void) | |
7175 | { | |
845b51d6 PB |
7176 | bfd_boolean want_reloc; |
7177 | ||
c19d1205 ZW |
7178 | if (inst.operands[0].reg == REG_PC) |
7179 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 7180 | |
c19d1205 | 7181 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
7182 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
7183 | it is for ARMv4t or earlier. */ | |
7184 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
7185 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
7186 | want_reloc = TRUE; | |
7187 | ||
5ad34203 | 7188 | #ifdef OBJ_ELF |
845b51d6 | 7189 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 7190 | #endif |
584206db | 7191 | want_reloc = FALSE; |
845b51d6 PB |
7192 | |
7193 | if (want_reloc) | |
7194 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
7195 | } |
7196 | ||
c19d1205 ZW |
7197 | |
7198 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
7199 | |
7200 | static void | |
c19d1205 | 7201 | do_bxj (void) |
a737bd4d | 7202 | { |
c19d1205 ZW |
7203 | if (inst.operands[0].reg == REG_PC) |
7204 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
7205 | ||
7206 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
7207 | } |
7208 | ||
c19d1205 ZW |
7209 | /* Co-processor data operation: |
7210 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
7211 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
7212 | static void | |
7213 | do_cdp (void) | |
7214 | { | |
7215 | inst.instruction |= inst.operands[0].reg << 8; | |
7216 | inst.instruction |= inst.operands[1].imm << 20; | |
7217 | inst.instruction |= inst.operands[2].reg << 12; | |
7218 | inst.instruction |= inst.operands[3].reg << 16; | |
7219 | inst.instruction |= inst.operands[4].reg; | |
7220 | inst.instruction |= inst.operands[5].imm << 5; | |
7221 | } | |
a737bd4d NC |
7222 | |
7223 | static void | |
c19d1205 | 7224 | do_cmp (void) |
a737bd4d | 7225 | { |
c19d1205 ZW |
7226 | inst.instruction |= inst.operands[0].reg << 16; |
7227 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
7228 | } |
7229 | ||
c19d1205 ZW |
7230 | /* Transfer between coprocessor and ARM registers. |
7231 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
7232 | MRC2 | |
7233 | MCR{cond} | |
7234 | MCR2 | |
7235 | ||
7236 | No special properties. */ | |
09d92015 MM |
7237 | |
7238 | static void | |
c19d1205 | 7239 | do_co_reg (void) |
09d92015 | 7240 | { |
fdfde340 JM |
7241 | unsigned Rd; |
7242 | ||
7243 | Rd = inst.operands[2].reg; | |
7244 | if (thumb_mode) | |
7245 | { | |
7246 | if (inst.instruction == 0xee000010 | |
7247 | || inst.instruction == 0xfe000010) | |
7248 | /* MCR, MCR2 */ | |
7249 | reject_bad_reg (Rd); | |
7250 | else | |
7251 | /* MRC, MRC2 */ | |
7252 | constraint (Rd == REG_SP, BAD_SP); | |
7253 | } | |
7254 | else | |
7255 | { | |
7256 | /* MCR */ | |
7257 | if (inst.instruction == 0xe000010) | |
7258 | constraint (Rd == REG_PC, BAD_PC); | |
7259 | } | |
7260 | ||
7261 | ||
c19d1205 ZW |
7262 | inst.instruction |= inst.operands[0].reg << 8; |
7263 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 7264 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
7265 | inst.instruction |= inst.operands[3].reg << 16; |
7266 | inst.instruction |= inst.operands[4].reg; | |
7267 | inst.instruction |= inst.operands[5].imm << 5; | |
7268 | } | |
09d92015 | 7269 | |
c19d1205 ZW |
7270 | /* Transfer between coprocessor register and pair of ARM registers. |
7271 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
7272 | MCRR2 | |
7273 | MRRC{cond} | |
7274 | MRRC2 | |
b99bd4ef | 7275 | |
c19d1205 | 7276 | Two XScale instructions are special cases of these: |
09d92015 | 7277 | |
c19d1205 ZW |
7278 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
7279 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 7280 | |
5f4273c7 | 7281 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 7282 | |
c19d1205 ZW |
7283 | static void |
7284 | do_co_reg2c (void) | |
7285 | { | |
fdfde340 JM |
7286 | unsigned Rd, Rn; |
7287 | ||
7288 | Rd = inst.operands[2].reg; | |
7289 | Rn = inst.operands[3].reg; | |
7290 | ||
7291 | if (thumb_mode) | |
7292 | { | |
7293 | reject_bad_reg (Rd); | |
7294 | reject_bad_reg (Rn); | |
7295 | } | |
7296 | else | |
7297 | { | |
7298 | constraint (Rd == REG_PC, BAD_PC); | |
7299 | constraint (Rn == REG_PC, BAD_PC); | |
7300 | } | |
7301 | ||
c19d1205 ZW |
7302 | inst.instruction |= inst.operands[0].reg << 8; |
7303 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
7304 | inst.instruction |= Rd << 12; |
7305 | inst.instruction |= Rn << 16; | |
c19d1205 | 7306 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
7307 | } |
7308 | ||
c19d1205 ZW |
7309 | static void |
7310 | do_cpsi (void) | |
7311 | { | |
7312 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
7313 | if (inst.operands[1].present) |
7314 | { | |
7315 | inst.instruction |= CPSI_MMOD; | |
7316 | inst.instruction |= inst.operands[1].imm; | |
7317 | } | |
c19d1205 | 7318 | } |
b99bd4ef | 7319 | |
62b3e311 PB |
7320 | static void |
7321 | do_dbg (void) | |
7322 | { | |
7323 | inst.instruction |= inst.operands[0].imm; | |
7324 | } | |
7325 | ||
b99bd4ef | 7326 | static void |
c19d1205 | 7327 | do_it (void) |
b99bd4ef | 7328 | { |
c19d1205 | 7329 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
7330 | process it to do the validation as if in |
7331 | thumb mode, just in case the code gets | |
7332 | assembled for thumb using the unified syntax. */ | |
7333 | ||
c19d1205 | 7334 | inst.size = 0; |
e07e6e58 NC |
7335 | if (unified_syntax) |
7336 | { | |
7337 | set_it_insn_type (IT_INSN); | |
7338 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
7339 | now_it.cc = inst.operands[0].imm; | |
7340 | } | |
09d92015 | 7341 | } |
b99bd4ef | 7342 | |
09d92015 | 7343 | static void |
c19d1205 | 7344 | do_ldmstm (void) |
ea6ef066 | 7345 | { |
c19d1205 ZW |
7346 | int base_reg = inst.operands[0].reg; |
7347 | int range = inst.operands[1].imm; | |
ea6ef066 | 7348 | |
c19d1205 ZW |
7349 | inst.instruction |= base_reg << 16; |
7350 | inst.instruction |= range; | |
ea6ef066 | 7351 | |
c19d1205 ZW |
7352 | if (inst.operands[1].writeback) |
7353 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 7354 | |
c19d1205 | 7355 | if (inst.operands[0].writeback) |
ea6ef066 | 7356 | { |
c19d1205 ZW |
7357 | inst.instruction |= WRITE_BACK; |
7358 | /* Check for unpredictable uses of writeback. */ | |
7359 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 7360 | { |
c19d1205 ZW |
7361 | /* Not allowed in LDM type 2. */ |
7362 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
7363 | && ((range & (1 << REG_PC)) == 0)) | |
7364 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7365 | /* Only allowed if base reg not in list for other types. */ | |
7366 | else if (range & (1 << base_reg)) | |
7367 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
7368 | } | |
7369 | else /* STM. */ | |
7370 | { | |
7371 | /* Not allowed for type 2. */ | |
7372 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
7373 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7374 | /* Only allowed if base reg not in list, or first in list. */ | |
7375 | else if ((range & (1 << base_reg)) | |
7376 | && (range & ((1 << base_reg) - 1))) | |
7377 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 7378 | } |
ea6ef066 | 7379 | } |
a737bd4d NC |
7380 | } |
7381 | ||
c19d1205 ZW |
7382 | /* ARMv5TE load-consecutive (argument parse) |
7383 | Mode is like LDRH. | |
7384 | ||
7385 | LDRccD R, mode | |
7386 | STRccD R, mode. */ | |
7387 | ||
a737bd4d | 7388 | static void |
c19d1205 | 7389 | do_ldrd (void) |
a737bd4d | 7390 | { |
c19d1205 ZW |
7391 | constraint (inst.operands[0].reg % 2 != 0, |
7392 | _("first destination register must be even")); | |
7393 | constraint (inst.operands[1].present | |
7394 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7395 | _("can only load two consecutive registers")); | |
7396 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
7397 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 7398 | |
c19d1205 ZW |
7399 | if (!inst.operands[1].present) |
7400 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 7401 | |
c19d1205 | 7402 | if (inst.instruction & LOAD_BIT) |
a737bd4d | 7403 | { |
c19d1205 ZW |
7404 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
7405 | register and the first register written; we have to diagnose | |
7406 | overlap between the base and the second register written here. */ | |
ea6ef066 | 7407 | |
c19d1205 ZW |
7408 | if (inst.operands[2].reg == inst.operands[1].reg |
7409 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
7410 | as_warn (_("base register written back, and overlaps " | |
7411 | "second destination register")); | |
b05fe5cf | 7412 | |
c19d1205 ZW |
7413 | /* For an index-register load, the index register must not overlap the |
7414 | destination (even if not write-back). */ | |
7415 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
7416 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
7417 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 7418 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 7419 | } |
c19d1205 ZW |
7420 | |
7421 | inst.instruction |= inst.operands[0].reg << 12; | |
7422 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
7423 | } |
7424 | ||
7425 | static void | |
c19d1205 | 7426 | do_ldrex (void) |
b05fe5cf | 7427 | { |
c19d1205 ZW |
7428 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
7429 | || inst.operands[1].postind || inst.operands[1].writeback | |
7430 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
7431 | || inst.operands[1].negative |
7432 | /* This can arise if the programmer has written | |
7433 | strex rN, rM, foo | |
7434 | or if they have mistakenly used a register name as the last | |
7435 | operand, eg: | |
7436 | strex rN, rM, rX | |
7437 | It is very difficult to distinguish between these two cases | |
7438 | because "rX" might actually be a label. ie the register | |
7439 | name has been occluded by a symbol of the same name. So we | |
7440 | just generate a general 'bad addressing mode' type error | |
7441 | message and leave it up to the programmer to discover the | |
7442 | true cause and fix their mistake. */ | |
7443 | || (inst.operands[1].reg == REG_PC), | |
7444 | BAD_ADDR_MODE); | |
b05fe5cf | 7445 | |
c19d1205 ZW |
7446 | constraint (inst.reloc.exp.X_op != O_constant |
7447 | || inst.reloc.exp.X_add_number != 0, | |
7448 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 7449 | |
c19d1205 ZW |
7450 | inst.instruction |= inst.operands[0].reg << 12; |
7451 | inst.instruction |= inst.operands[1].reg << 16; | |
7452 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
7453 | } |
7454 | ||
7455 | static void | |
c19d1205 | 7456 | do_ldrexd (void) |
b05fe5cf | 7457 | { |
c19d1205 ZW |
7458 | constraint (inst.operands[0].reg % 2 != 0, |
7459 | _("even register required")); | |
7460 | constraint (inst.operands[1].present | |
7461 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7462 | _("can only load two consecutive registers")); | |
7463 | /* If op 1 were present and equal to PC, this function wouldn't | |
7464 | have been called in the first place. */ | |
7465 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 7466 | |
c19d1205 ZW |
7467 | inst.instruction |= inst.operands[0].reg << 12; |
7468 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
7469 | } |
7470 | ||
7471 | static void | |
c19d1205 | 7472 | do_ldst (void) |
b05fe5cf | 7473 | { |
c19d1205 ZW |
7474 | inst.instruction |= inst.operands[0].reg << 12; |
7475 | if (!inst.operands[1].isreg) | |
7476 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 7477 | return; |
c19d1205 | 7478 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7479 | } |
7480 | ||
7481 | static void | |
c19d1205 | 7482 | do_ldstt (void) |
b05fe5cf | 7483 | { |
c19d1205 ZW |
7484 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7485 | reject [Rn,...]. */ | |
7486 | if (inst.operands[1].preind) | |
b05fe5cf | 7487 | { |
bd3ba5d1 NC |
7488 | constraint (inst.reloc.exp.X_op != O_constant |
7489 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7490 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7491 | |
c19d1205 ZW |
7492 | inst.operands[1].preind = 0; |
7493 | inst.operands[1].postind = 1; | |
7494 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7495 | } |
c19d1205 ZW |
7496 | inst.instruction |= inst.operands[0].reg << 12; |
7497 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
7498 | } | |
b05fe5cf | 7499 | |
c19d1205 | 7500 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 7501 | |
c19d1205 ZW |
7502 | static void |
7503 | do_ldstv4 (void) | |
7504 | { | |
7505 | inst.instruction |= inst.operands[0].reg << 12; | |
7506 | if (!inst.operands[1].isreg) | |
7507 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 7508 | return; |
c19d1205 | 7509 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7510 | } |
7511 | ||
7512 | static void | |
c19d1205 | 7513 | do_ldsttv4 (void) |
b05fe5cf | 7514 | { |
c19d1205 ZW |
7515 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7516 | reject [Rn,...]. */ | |
7517 | if (inst.operands[1].preind) | |
b05fe5cf | 7518 | { |
bd3ba5d1 NC |
7519 | constraint (inst.reloc.exp.X_op != O_constant |
7520 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7521 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7522 | |
c19d1205 ZW |
7523 | inst.operands[1].preind = 0; |
7524 | inst.operands[1].postind = 1; | |
7525 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7526 | } |
c19d1205 ZW |
7527 | inst.instruction |= inst.operands[0].reg << 12; |
7528 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
7529 | } | |
b05fe5cf | 7530 | |
c19d1205 ZW |
7531 | /* Co-processor register load/store. |
7532 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
7533 | static void | |
7534 | do_lstc (void) | |
7535 | { | |
7536 | inst.instruction |= inst.operands[0].reg << 8; | |
7537 | inst.instruction |= inst.operands[1].reg << 12; | |
7538 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
7539 | } |
7540 | ||
b05fe5cf | 7541 | static void |
c19d1205 | 7542 | do_mlas (void) |
b05fe5cf | 7543 | { |
8fb9d7b9 | 7544 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 7545 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 7546 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 7547 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 7548 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 7549 | |
c19d1205 ZW |
7550 | inst.instruction |= inst.operands[0].reg << 16; |
7551 | inst.instruction |= inst.operands[1].reg; | |
7552 | inst.instruction |= inst.operands[2].reg << 8; | |
7553 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 7554 | } |
b05fe5cf | 7555 | |
c19d1205 ZW |
7556 | static void |
7557 | do_mov (void) | |
7558 | { | |
7559 | inst.instruction |= inst.operands[0].reg << 12; | |
7560 | encode_arm_shifter_operand (1); | |
7561 | } | |
b05fe5cf | 7562 | |
c19d1205 ZW |
7563 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
7564 | static void | |
7565 | do_mov16 (void) | |
7566 | { | |
b6895b4f PB |
7567 | bfd_vma imm; |
7568 | bfd_boolean top; | |
7569 | ||
7570 | top = (inst.instruction & 0x00400000) != 0; | |
7571 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
7572 | _(":lower16: not allowed this instruction")); | |
7573 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
7574 | _(":upper16: not allowed instruction")); | |
c19d1205 | 7575 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
7576 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
7577 | { | |
7578 | imm = inst.reloc.exp.X_add_number; | |
7579 | /* The value is in two pieces: 0:11, 16:19. */ | |
7580 | inst.instruction |= (imm & 0x00000fff); | |
7581 | inst.instruction |= (imm & 0x0000f000) << 4; | |
7582 | } | |
b05fe5cf | 7583 | } |
b99bd4ef | 7584 | |
037e8744 JB |
7585 | static void do_vfp_nsyn_opcode (const char *); |
7586 | ||
7587 | static int | |
7588 | do_vfp_nsyn_mrs (void) | |
7589 | { | |
7590 | if (inst.operands[0].isvec) | |
7591 | { | |
7592 | if (inst.operands[1].reg != 1) | |
7593 | first_error (_("operand 1 must be FPSCR")); | |
7594 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
7595 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
7596 | do_vfp_nsyn_opcode ("fmstat"); | |
7597 | } | |
7598 | else if (inst.operands[1].isvec) | |
7599 | do_vfp_nsyn_opcode ("fmrx"); | |
7600 | else | |
7601 | return FAIL; | |
5f4273c7 | 7602 | |
037e8744 JB |
7603 | return SUCCESS; |
7604 | } | |
7605 | ||
7606 | static int | |
7607 | do_vfp_nsyn_msr (void) | |
7608 | { | |
7609 | if (inst.operands[0].isvec) | |
7610 | do_vfp_nsyn_opcode ("fmxr"); | |
7611 | else | |
7612 | return FAIL; | |
7613 | ||
7614 | return SUCCESS; | |
7615 | } | |
7616 | ||
b99bd4ef | 7617 | static void |
c19d1205 | 7618 | do_mrs (void) |
b99bd4ef | 7619 | { |
037e8744 JB |
7620 | if (do_vfp_nsyn_mrs () == SUCCESS) |
7621 | return; | |
7622 | ||
c19d1205 ZW |
7623 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
7624 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7625 | != (PSR_c|PSR_f), | |
7626 | _("'CPSR' or 'SPSR' expected")); | |
7627 | inst.instruction |= inst.operands[0].reg << 12; | |
7628 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
7629 | } | |
b99bd4ef | 7630 | |
c19d1205 ZW |
7631 | /* Two possible forms: |
7632 | "{C|S}PSR_<field>, Rm", | |
7633 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 7634 | |
c19d1205 ZW |
7635 | static void |
7636 | do_msr (void) | |
7637 | { | |
037e8744 JB |
7638 | if (do_vfp_nsyn_msr () == SUCCESS) |
7639 | return; | |
7640 | ||
c19d1205 ZW |
7641 | inst.instruction |= inst.operands[0].imm; |
7642 | if (inst.operands[1].isreg) | |
7643 | inst.instruction |= inst.operands[1].reg; | |
7644 | else | |
b99bd4ef | 7645 | { |
c19d1205 ZW |
7646 | inst.instruction |= INST_IMMEDIATE; |
7647 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
7648 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 7649 | } |
b99bd4ef NC |
7650 | } |
7651 | ||
c19d1205 ZW |
7652 | static void |
7653 | do_mul (void) | |
a737bd4d | 7654 | { |
c19d1205 ZW |
7655 | if (!inst.operands[2].present) |
7656 | inst.operands[2].reg = inst.operands[0].reg; | |
7657 | inst.instruction |= inst.operands[0].reg << 16; | |
7658 | inst.instruction |= inst.operands[1].reg; | |
7659 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 7660 | |
8fb9d7b9 MS |
7661 | if (inst.operands[0].reg == inst.operands[1].reg |
7662 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
7663 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
7664 | } |
7665 | ||
c19d1205 ZW |
7666 | /* Long Multiply Parser |
7667 | UMULL RdLo, RdHi, Rm, Rs | |
7668 | SMULL RdLo, RdHi, Rm, Rs | |
7669 | UMLAL RdLo, RdHi, Rm, Rs | |
7670 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
7671 | |
7672 | static void | |
c19d1205 | 7673 | do_mull (void) |
b99bd4ef | 7674 | { |
c19d1205 ZW |
7675 | inst.instruction |= inst.operands[0].reg << 12; |
7676 | inst.instruction |= inst.operands[1].reg << 16; | |
7677 | inst.instruction |= inst.operands[2].reg; | |
7678 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 7679 | |
682b27ad PB |
7680 | /* rdhi and rdlo must be different. */ |
7681 | if (inst.operands[0].reg == inst.operands[1].reg) | |
7682 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7683 | ||
7684 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
7685 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 7686 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 7687 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
7688 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
7689 | } | |
b99bd4ef | 7690 | |
c19d1205 ZW |
7691 | static void |
7692 | do_nop (void) | |
7693 | { | |
e7495e45 NS |
7694 | if (inst.operands[0].present |
7695 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
7696 | { |
7697 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
7698 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
7699 | inst.instruction |= 0x0320f000; |
7700 | if (inst.operands[0].present) | |
7701 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 7702 | } |
b99bd4ef NC |
7703 | } |
7704 | ||
c19d1205 ZW |
7705 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
7706 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
7707 | Condition defaults to COND_ALWAYS. | |
7708 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
7709 | |
7710 | static void | |
c19d1205 | 7711 | do_pkhbt (void) |
b99bd4ef | 7712 | { |
c19d1205 ZW |
7713 | inst.instruction |= inst.operands[0].reg << 12; |
7714 | inst.instruction |= inst.operands[1].reg << 16; | |
7715 | inst.instruction |= inst.operands[2].reg; | |
7716 | if (inst.operands[3].present) | |
7717 | encode_arm_shift (3); | |
7718 | } | |
b99bd4ef | 7719 | |
c19d1205 | 7720 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 7721 | |
c19d1205 ZW |
7722 | static void |
7723 | do_pkhtb (void) | |
7724 | { | |
7725 | if (!inst.operands[3].present) | |
b99bd4ef | 7726 | { |
c19d1205 ZW |
7727 | /* If the shift specifier is omitted, turn the instruction |
7728 | into pkhbt rd, rm, rn. */ | |
7729 | inst.instruction &= 0xfff00010; | |
7730 | inst.instruction |= inst.operands[0].reg << 12; | |
7731 | inst.instruction |= inst.operands[1].reg; | |
7732 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7733 | } |
7734 | else | |
7735 | { | |
c19d1205 ZW |
7736 | inst.instruction |= inst.operands[0].reg << 12; |
7737 | inst.instruction |= inst.operands[1].reg << 16; | |
7738 | inst.instruction |= inst.operands[2].reg; | |
7739 | encode_arm_shift (3); | |
b99bd4ef NC |
7740 | } |
7741 | } | |
7742 | ||
c19d1205 ZW |
7743 | /* ARMv5TE: Preload-Cache |
7744 | ||
7745 | PLD <addr_mode> | |
7746 | ||
7747 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
7748 | |
7749 | static void | |
c19d1205 | 7750 | do_pld (void) |
b99bd4ef | 7751 | { |
c19d1205 ZW |
7752 | constraint (!inst.operands[0].isreg, |
7753 | _("'[' expected after PLD mnemonic")); | |
7754 | constraint (inst.operands[0].postind, | |
7755 | _("post-indexed expression used in preload instruction")); | |
7756 | constraint (inst.operands[0].writeback, | |
7757 | _("writeback used in preload instruction")); | |
7758 | constraint (!inst.operands[0].preind, | |
7759 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
7760 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
7761 | } | |
b99bd4ef | 7762 | |
62b3e311 PB |
7763 | /* ARMv7: PLI <addr_mode> */ |
7764 | static void | |
7765 | do_pli (void) | |
7766 | { | |
7767 | constraint (!inst.operands[0].isreg, | |
7768 | _("'[' expected after PLI mnemonic")); | |
7769 | constraint (inst.operands[0].postind, | |
7770 | _("post-indexed expression used in preload instruction")); | |
7771 | constraint (inst.operands[0].writeback, | |
7772 | _("writeback used in preload instruction")); | |
7773 | constraint (!inst.operands[0].preind, | |
7774 | _("unindexed addressing used in preload instruction")); | |
7775 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
7776 | inst.instruction &= ~PRE_INDEX; | |
7777 | } | |
7778 | ||
c19d1205 ZW |
7779 | static void |
7780 | do_push_pop (void) | |
7781 | { | |
7782 | inst.operands[1] = inst.operands[0]; | |
7783 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
7784 | inst.operands[0].isreg = 1; | |
7785 | inst.operands[0].writeback = 1; | |
7786 | inst.operands[0].reg = REG_SP; | |
7787 | do_ldmstm (); | |
7788 | } | |
b99bd4ef | 7789 | |
c19d1205 ZW |
7790 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
7791 | word at the specified address and the following word | |
7792 | respectively. | |
7793 | Unconditionally executed. | |
7794 | Error if Rn is R15. */ | |
b99bd4ef | 7795 | |
c19d1205 ZW |
7796 | static void |
7797 | do_rfe (void) | |
7798 | { | |
7799 | inst.instruction |= inst.operands[0].reg << 16; | |
7800 | if (inst.operands[0].writeback) | |
7801 | inst.instruction |= WRITE_BACK; | |
7802 | } | |
b99bd4ef | 7803 | |
c19d1205 | 7804 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 7805 | |
c19d1205 ZW |
7806 | static void |
7807 | do_ssat (void) | |
7808 | { | |
7809 | inst.instruction |= inst.operands[0].reg << 12; | |
7810 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
7811 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7812 | |
c19d1205 ZW |
7813 | if (inst.operands[3].present) |
7814 | encode_arm_shift (3); | |
b99bd4ef NC |
7815 | } |
7816 | ||
c19d1205 | 7817 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
7818 | |
7819 | static void | |
c19d1205 | 7820 | do_usat (void) |
b99bd4ef | 7821 | { |
c19d1205 ZW |
7822 | inst.instruction |= inst.operands[0].reg << 12; |
7823 | inst.instruction |= inst.operands[1].imm << 16; | |
7824 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7825 | |
c19d1205 ZW |
7826 | if (inst.operands[3].present) |
7827 | encode_arm_shift (3); | |
b99bd4ef NC |
7828 | } |
7829 | ||
c19d1205 | 7830 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
7831 | |
7832 | static void | |
c19d1205 | 7833 | do_ssat16 (void) |
09d92015 | 7834 | { |
c19d1205 ZW |
7835 | inst.instruction |= inst.operands[0].reg << 12; |
7836 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
7837 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
7838 | } |
7839 | ||
c19d1205 ZW |
7840 | static void |
7841 | do_usat16 (void) | |
a737bd4d | 7842 | { |
c19d1205 ZW |
7843 | inst.instruction |= inst.operands[0].reg << 12; |
7844 | inst.instruction |= inst.operands[1].imm << 16; | |
7845 | inst.instruction |= inst.operands[2].reg; | |
7846 | } | |
a737bd4d | 7847 | |
c19d1205 ZW |
7848 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
7849 | preserving the other bits. | |
a737bd4d | 7850 | |
c19d1205 ZW |
7851 | setend <endian_specifier>, where <endian_specifier> is either |
7852 | BE or LE. */ | |
a737bd4d | 7853 | |
c19d1205 ZW |
7854 | static void |
7855 | do_setend (void) | |
7856 | { | |
7857 | if (inst.operands[0].imm) | |
7858 | inst.instruction |= 0x200; | |
a737bd4d NC |
7859 | } |
7860 | ||
7861 | static void | |
c19d1205 | 7862 | do_shift (void) |
a737bd4d | 7863 | { |
c19d1205 ZW |
7864 | unsigned int Rm = (inst.operands[1].present |
7865 | ? inst.operands[1].reg | |
7866 | : inst.operands[0].reg); | |
a737bd4d | 7867 | |
c19d1205 ZW |
7868 | inst.instruction |= inst.operands[0].reg << 12; |
7869 | inst.instruction |= Rm; | |
7870 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 7871 | { |
c19d1205 ZW |
7872 | inst.instruction |= inst.operands[2].reg << 8; |
7873 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
7874 | } |
7875 | else | |
c19d1205 | 7876 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
7877 | } |
7878 | ||
09d92015 | 7879 | static void |
3eb17e6b | 7880 | do_smc (void) |
09d92015 | 7881 | { |
3eb17e6b | 7882 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 7883 | inst.reloc.pc_rel = 0; |
09d92015 MM |
7884 | } |
7885 | ||
09d92015 | 7886 | static void |
c19d1205 | 7887 | do_swi (void) |
09d92015 | 7888 | { |
c19d1205 ZW |
7889 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
7890 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
7891 | } |
7892 | ||
c19d1205 ZW |
7893 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
7894 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
7895 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
7896 | Error if any register is R15. */ | |
e16bb312 | 7897 | |
c19d1205 ZW |
7898 | static void |
7899 | do_smla (void) | |
e16bb312 | 7900 | { |
c19d1205 ZW |
7901 | inst.instruction |= inst.operands[0].reg << 16; |
7902 | inst.instruction |= inst.operands[1].reg; | |
7903 | inst.instruction |= inst.operands[2].reg << 8; | |
7904 | inst.instruction |= inst.operands[3].reg << 12; | |
7905 | } | |
a737bd4d | 7906 | |
c19d1205 ZW |
7907 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
7908 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
7909 | Error if any register is R15. | |
7910 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 7911 | |
c19d1205 ZW |
7912 | static void |
7913 | do_smlal (void) | |
7914 | { | |
7915 | inst.instruction |= inst.operands[0].reg << 12; | |
7916 | inst.instruction |= inst.operands[1].reg << 16; | |
7917 | inst.instruction |= inst.operands[2].reg; | |
7918 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 7919 | |
c19d1205 ZW |
7920 | if (inst.operands[0].reg == inst.operands[1].reg) |
7921 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7922 | } | |
a737bd4d | 7923 | |
c19d1205 ZW |
7924 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
7925 | SMULxy{cond} Rd,Rm,Rs | |
7926 | Error if any register is R15. */ | |
a737bd4d | 7927 | |
c19d1205 ZW |
7928 | static void |
7929 | do_smul (void) | |
7930 | { | |
7931 | inst.instruction |= inst.operands[0].reg << 16; | |
7932 | inst.instruction |= inst.operands[1].reg; | |
7933 | inst.instruction |= inst.operands[2].reg << 8; | |
7934 | } | |
a737bd4d | 7935 | |
b6702015 PB |
7936 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
7937 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 7938 | |
c19d1205 ZW |
7939 | static void |
7940 | do_srs (void) | |
7941 | { | |
b6702015 PB |
7942 | int reg; |
7943 | ||
7944 | if (inst.operands[0].present) | |
7945 | { | |
7946 | reg = inst.operands[0].reg; | |
fdfde340 | 7947 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
7948 | } |
7949 | else | |
fdfde340 | 7950 | reg = REG_SP; |
b6702015 PB |
7951 | |
7952 | inst.instruction |= reg << 16; | |
7953 | inst.instruction |= inst.operands[1].imm; | |
7954 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
7955 | inst.instruction |= WRITE_BACK; |
7956 | } | |
a737bd4d | 7957 | |
c19d1205 | 7958 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 7959 | |
c19d1205 ZW |
7960 | static void |
7961 | do_strex (void) | |
7962 | { | |
7963 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7964 | || inst.operands[2].postind || inst.operands[2].writeback | |
7965 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
7966 | || inst.operands[2].negative |
7967 | /* See comment in do_ldrex(). */ | |
7968 | || (inst.operands[2].reg == REG_PC), | |
7969 | BAD_ADDR_MODE); | |
a737bd4d | 7970 | |
c19d1205 ZW |
7971 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7972 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 7973 | |
c19d1205 ZW |
7974 | constraint (inst.reloc.exp.X_op != O_constant |
7975 | || inst.reloc.exp.X_add_number != 0, | |
7976 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 7977 | |
c19d1205 ZW |
7978 | inst.instruction |= inst.operands[0].reg << 12; |
7979 | inst.instruction |= inst.operands[1].reg; | |
7980 | inst.instruction |= inst.operands[2].reg << 16; | |
7981 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
7982 | } |
7983 | ||
7984 | static void | |
c19d1205 | 7985 | do_strexd (void) |
e16bb312 | 7986 | { |
c19d1205 ZW |
7987 | constraint (inst.operands[1].reg % 2 != 0, |
7988 | _("even register required")); | |
7989 | constraint (inst.operands[2].present | |
7990 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
7991 | _("can only store two consecutive registers")); | |
7992 | /* If op 2 were present and equal to PC, this function wouldn't | |
7993 | have been called in the first place. */ | |
7994 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 7995 | |
c19d1205 ZW |
7996 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7997 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
7998 | || inst.operands[0].reg == inst.operands[3].reg, | |
7999 | BAD_OVERLAP); | |
e16bb312 | 8000 | |
c19d1205 ZW |
8001 | inst.instruction |= inst.operands[0].reg << 12; |
8002 | inst.instruction |= inst.operands[1].reg; | |
8003 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
8004 | } |
8005 | ||
c19d1205 ZW |
8006 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
8007 | extends it to 32-bits, and adds the result to a value in another | |
8008 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
8009 | before extracting the 16-bit value. | |
8010 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
8011 | Condition defaults to COND_ALWAYS. | |
8012 | Error if any register uses R15. */ | |
8013 | ||
e16bb312 | 8014 | static void |
c19d1205 | 8015 | do_sxtah (void) |
e16bb312 | 8016 | { |
c19d1205 ZW |
8017 | inst.instruction |= inst.operands[0].reg << 12; |
8018 | inst.instruction |= inst.operands[1].reg << 16; | |
8019 | inst.instruction |= inst.operands[2].reg; | |
8020 | inst.instruction |= inst.operands[3].imm << 10; | |
8021 | } | |
e16bb312 | 8022 | |
c19d1205 | 8023 | /* ARM V6 SXTH. |
e16bb312 | 8024 | |
c19d1205 ZW |
8025 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
8026 | Condition defaults to COND_ALWAYS. | |
8027 | Error if any register uses R15. */ | |
e16bb312 NC |
8028 | |
8029 | static void | |
c19d1205 | 8030 | do_sxth (void) |
e16bb312 | 8031 | { |
c19d1205 ZW |
8032 | inst.instruction |= inst.operands[0].reg << 12; |
8033 | inst.instruction |= inst.operands[1].reg; | |
8034 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 8035 | } |
c19d1205 ZW |
8036 | \f |
8037 | /* VFP instructions. In a logical order: SP variant first, monad | |
8038 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
8039 | |
8040 | static void | |
c19d1205 | 8041 | do_vfp_sp_monadic (void) |
e16bb312 | 8042 | { |
5287ad62 JB |
8043 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8044 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8045 | } |
8046 | ||
8047 | static void | |
c19d1205 | 8048 | do_vfp_sp_dyadic (void) |
e16bb312 | 8049 | { |
5287ad62 JB |
8050 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8051 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
8052 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
8053 | } |
8054 | ||
8055 | static void | |
c19d1205 | 8056 | do_vfp_sp_compare_z (void) |
e16bb312 | 8057 | { |
5287ad62 | 8058 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
8059 | } |
8060 | ||
8061 | static void | |
c19d1205 | 8062 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 8063 | { |
5287ad62 JB |
8064 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
8065 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8066 | } |
8067 | ||
8068 | static void | |
c19d1205 | 8069 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 8070 | { |
5287ad62 JB |
8071 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8072 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
8073 | } |
8074 | ||
8075 | static void | |
c19d1205 | 8076 | do_vfp_reg_from_sp (void) |
e16bb312 | 8077 | { |
c19d1205 | 8078 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 8079 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
8080 | } |
8081 | ||
8082 | static void | |
c19d1205 | 8083 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 8084 | { |
c19d1205 ZW |
8085 | constraint (inst.operands[2].imm != 2, |
8086 | _("only two consecutive VFP SP registers allowed here")); | |
8087 | inst.instruction |= inst.operands[0].reg << 12; | |
8088 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 8089 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
8090 | } |
8091 | ||
8092 | static void | |
c19d1205 | 8093 | do_vfp_sp_from_reg (void) |
e16bb312 | 8094 | { |
5287ad62 | 8095 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 8096 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
8097 | } |
8098 | ||
8099 | static void | |
c19d1205 | 8100 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 8101 | { |
c19d1205 ZW |
8102 | constraint (inst.operands[0].imm != 2, |
8103 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 8104 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
8105 | inst.instruction |= inst.operands[1].reg << 12; |
8106 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
8107 | } |
8108 | ||
8109 | static void | |
c19d1205 | 8110 | do_vfp_sp_ldst (void) |
e16bb312 | 8111 | { |
5287ad62 | 8112 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 8113 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8114 | } |
8115 | ||
8116 | static void | |
c19d1205 | 8117 | do_vfp_dp_ldst (void) |
e16bb312 | 8118 | { |
5287ad62 | 8119 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 8120 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8121 | } |
8122 | ||
c19d1205 | 8123 | |
e16bb312 | 8124 | static void |
c19d1205 | 8125 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8126 | { |
c19d1205 ZW |
8127 | if (inst.operands[0].writeback) |
8128 | inst.instruction |= WRITE_BACK; | |
8129 | else | |
8130 | constraint (ldstm_type != VFP_LDSTMIA, | |
8131 | _("this addressing mode requires base-register writeback")); | |
8132 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 8133 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 8134 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
8135 | } |
8136 | ||
8137 | static void | |
c19d1205 | 8138 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8139 | { |
c19d1205 | 8140 | int count; |
e16bb312 | 8141 | |
c19d1205 ZW |
8142 | if (inst.operands[0].writeback) |
8143 | inst.instruction |= WRITE_BACK; | |
8144 | else | |
8145 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
8146 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 8147 | |
c19d1205 | 8148 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 8149 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 8150 | |
c19d1205 ZW |
8151 | count = inst.operands[1].imm << 1; |
8152 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
8153 | count += 1; | |
e16bb312 | 8154 | |
c19d1205 | 8155 | inst.instruction |= count; |
e16bb312 NC |
8156 | } |
8157 | ||
8158 | static void | |
c19d1205 | 8159 | do_vfp_sp_ldstmia (void) |
e16bb312 | 8160 | { |
c19d1205 | 8161 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8162 | } |
8163 | ||
8164 | static void | |
c19d1205 | 8165 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 8166 | { |
c19d1205 | 8167 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8168 | } |
8169 | ||
8170 | static void | |
c19d1205 | 8171 | do_vfp_dp_ldstmia (void) |
e16bb312 | 8172 | { |
c19d1205 | 8173 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8174 | } |
8175 | ||
8176 | static void | |
c19d1205 | 8177 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 8178 | { |
c19d1205 | 8179 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8180 | } |
8181 | ||
8182 | static void | |
c19d1205 | 8183 | do_vfp_xp_ldstmia (void) |
e16bb312 | 8184 | { |
c19d1205 ZW |
8185 | vfp_dp_ldstm (VFP_LDSTMIAX); |
8186 | } | |
e16bb312 | 8187 | |
c19d1205 ZW |
8188 | static void |
8189 | do_vfp_xp_ldstmdb (void) | |
8190 | { | |
8191 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 8192 | } |
5287ad62 JB |
8193 | |
8194 | static void | |
8195 | do_vfp_dp_rd_rm (void) | |
8196 | { | |
8197 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8198 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
8199 | } | |
8200 | ||
8201 | static void | |
8202 | do_vfp_dp_rn_rd (void) | |
8203 | { | |
8204 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
8205 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8206 | } | |
8207 | ||
8208 | static void | |
8209 | do_vfp_dp_rd_rn (void) | |
8210 | { | |
8211 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8212 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8213 | } | |
8214 | ||
8215 | static void | |
8216 | do_vfp_dp_rd_rn_rm (void) | |
8217 | { | |
8218 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8219 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8220 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
8221 | } | |
8222 | ||
8223 | static void | |
8224 | do_vfp_dp_rd (void) | |
8225 | { | |
8226 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8227 | } | |
8228 | ||
8229 | static void | |
8230 | do_vfp_dp_rm_rd_rn (void) | |
8231 | { | |
8232 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
8233 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8234 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
8235 | } | |
8236 | ||
8237 | /* VFPv3 instructions. */ | |
8238 | static void | |
8239 | do_vfp_sp_const (void) | |
8240 | { | |
8241 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
8242 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8243 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8244 | } |
8245 | ||
8246 | static void | |
8247 | do_vfp_dp_const (void) | |
8248 | { | |
8249 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
8250 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8251 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8252 | } |
8253 | ||
8254 | static void | |
8255 | vfp_conv (int srcsize) | |
8256 | { | |
8257 | unsigned immbits = srcsize - inst.operands[1].imm; | |
8258 | inst.instruction |= (immbits & 1) << 5; | |
8259 | inst.instruction |= (immbits >> 1); | |
8260 | } | |
8261 | ||
8262 | static void | |
8263 | do_vfp_sp_conv_16 (void) | |
8264 | { | |
8265 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8266 | vfp_conv (16); | |
8267 | } | |
8268 | ||
8269 | static void | |
8270 | do_vfp_dp_conv_16 (void) | |
8271 | { | |
8272 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8273 | vfp_conv (16); | |
8274 | } | |
8275 | ||
8276 | static void | |
8277 | do_vfp_sp_conv_32 (void) | |
8278 | { | |
8279 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8280 | vfp_conv (32); | |
8281 | } | |
8282 | ||
8283 | static void | |
8284 | do_vfp_dp_conv_32 (void) | |
8285 | { | |
8286 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8287 | vfp_conv (32); | |
8288 | } | |
c19d1205 ZW |
8289 | \f |
8290 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 8291 | |
c19d1205 ZW |
8292 | static void |
8293 | do_fpa_cmp (void) | |
8294 | { | |
8295 | inst.instruction |= inst.operands[0].reg << 16; | |
8296 | inst.instruction |= inst.operands[1].reg; | |
8297 | } | |
b99bd4ef NC |
8298 | |
8299 | static void | |
c19d1205 | 8300 | do_fpa_ldmstm (void) |
b99bd4ef | 8301 | { |
c19d1205 ZW |
8302 | inst.instruction |= inst.operands[0].reg << 12; |
8303 | switch (inst.operands[1].imm) | |
8304 | { | |
8305 | case 1: inst.instruction |= CP_T_X; break; | |
8306 | case 2: inst.instruction |= CP_T_Y; break; | |
8307 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
8308 | case 4: break; | |
8309 | default: abort (); | |
8310 | } | |
b99bd4ef | 8311 | |
c19d1205 ZW |
8312 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
8313 | { | |
8314 | /* The instruction specified "ea" or "fd", so we can only accept | |
8315 | [Rn]{!}. The instruction does not really support stacking or | |
8316 | unstacking, so we have to emulate these by setting appropriate | |
8317 | bits and offsets. */ | |
8318 | constraint (inst.reloc.exp.X_op != O_constant | |
8319 | || inst.reloc.exp.X_add_number != 0, | |
8320 | _("this instruction does not support indexing")); | |
b99bd4ef | 8321 | |
c19d1205 ZW |
8322 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
8323 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 8324 | |
c19d1205 ZW |
8325 | if (!(inst.instruction & INDEX_UP)) |
8326 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 8327 | |
c19d1205 ZW |
8328 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
8329 | { | |
8330 | inst.operands[2].preind = 0; | |
8331 | inst.operands[2].postind = 1; | |
8332 | } | |
8333 | } | |
b99bd4ef | 8334 | |
c19d1205 | 8335 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 8336 | } |
c19d1205 ZW |
8337 | \f |
8338 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 8339 | |
c19d1205 ZW |
8340 | static void |
8341 | do_iwmmxt_tandorc (void) | |
8342 | { | |
8343 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
8344 | } | |
b99bd4ef | 8345 | |
c19d1205 ZW |
8346 | static void |
8347 | do_iwmmxt_textrc (void) | |
8348 | { | |
8349 | inst.instruction |= inst.operands[0].reg << 12; | |
8350 | inst.instruction |= inst.operands[1].imm; | |
8351 | } | |
b99bd4ef NC |
8352 | |
8353 | static void | |
c19d1205 | 8354 | do_iwmmxt_textrm (void) |
b99bd4ef | 8355 | { |
c19d1205 ZW |
8356 | inst.instruction |= inst.operands[0].reg << 12; |
8357 | inst.instruction |= inst.operands[1].reg << 16; | |
8358 | inst.instruction |= inst.operands[2].imm; | |
8359 | } | |
b99bd4ef | 8360 | |
c19d1205 ZW |
8361 | static void |
8362 | do_iwmmxt_tinsr (void) | |
8363 | { | |
8364 | inst.instruction |= inst.operands[0].reg << 16; | |
8365 | inst.instruction |= inst.operands[1].reg << 12; | |
8366 | inst.instruction |= inst.operands[2].imm; | |
8367 | } | |
b99bd4ef | 8368 | |
c19d1205 ZW |
8369 | static void |
8370 | do_iwmmxt_tmia (void) | |
8371 | { | |
8372 | inst.instruction |= inst.operands[0].reg << 5; | |
8373 | inst.instruction |= inst.operands[1].reg; | |
8374 | inst.instruction |= inst.operands[2].reg << 12; | |
8375 | } | |
b99bd4ef | 8376 | |
c19d1205 ZW |
8377 | static void |
8378 | do_iwmmxt_waligni (void) | |
8379 | { | |
8380 | inst.instruction |= inst.operands[0].reg << 12; | |
8381 | inst.instruction |= inst.operands[1].reg << 16; | |
8382 | inst.instruction |= inst.operands[2].reg; | |
8383 | inst.instruction |= inst.operands[3].imm << 20; | |
8384 | } | |
b99bd4ef | 8385 | |
2d447fca JM |
8386 | static void |
8387 | do_iwmmxt_wmerge (void) | |
8388 | { | |
8389 | inst.instruction |= inst.operands[0].reg << 12; | |
8390 | inst.instruction |= inst.operands[1].reg << 16; | |
8391 | inst.instruction |= inst.operands[2].reg; | |
8392 | inst.instruction |= inst.operands[3].imm << 21; | |
8393 | } | |
8394 | ||
c19d1205 ZW |
8395 | static void |
8396 | do_iwmmxt_wmov (void) | |
8397 | { | |
8398 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
8399 | inst.instruction |= inst.operands[0].reg << 12; | |
8400 | inst.instruction |= inst.operands[1].reg << 16; | |
8401 | inst.instruction |= inst.operands[1].reg; | |
8402 | } | |
b99bd4ef | 8403 | |
c19d1205 ZW |
8404 | static void |
8405 | do_iwmmxt_wldstbh (void) | |
8406 | { | |
8f06b2d8 | 8407 | int reloc; |
c19d1205 | 8408 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
8409 | if (thumb_mode) |
8410 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
8411 | else | |
8412 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
8413 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
8414 | } |
8415 | ||
c19d1205 ZW |
8416 | static void |
8417 | do_iwmmxt_wldstw (void) | |
8418 | { | |
8419 | /* RIWR_RIWC clears .isreg for a control register. */ | |
8420 | if (!inst.operands[0].isreg) | |
8421 | { | |
8422 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
8423 | inst.instruction |= 0xf0000000; | |
8424 | } | |
b99bd4ef | 8425 | |
c19d1205 ZW |
8426 | inst.instruction |= inst.operands[0].reg << 12; |
8427 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
8428 | } | |
b99bd4ef NC |
8429 | |
8430 | static void | |
c19d1205 | 8431 | do_iwmmxt_wldstd (void) |
b99bd4ef | 8432 | { |
c19d1205 | 8433 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
8434 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
8435 | && inst.operands[1].immisreg) | |
8436 | { | |
8437 | inst.instruction &= ~0x1a000ff; | |
8438 | inst.instruction |= (0xf << 28); | |
8439 | if (inst.operands[1].preind) | |
8440 | inst.instruction |= PRE_INDEX; | |
8441 | if (!inst.operands[1].negative) | |
8442 | inst.instruction |= INDEX_UP; | |
8443 | if (inst.operands[1].writeback) | |
8444 | inst.instruction |= WRITE_BACK; | |
8445 | inst.instruction |= inst.operands[1].reg << 16; | |
8446 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
8447 | inst.instruction |= inst.operands[1].imm; | |
8448 | } | |
8449 | else | |
8450 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 8451 | } |
b99bd4ef | 8452 | |
c19d1205 ZW |
8453 | static void |
8454 | do_iwmmxt_wshufh (void) | |
8455 | { | |
8456 | inst.instruction |= inst.operands[0].reg << 12; | |
8457 | inst.instruction |= inst.operands[1].reg << 16; | |
8458 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
8459 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
8460 | } | |
b99bd4ef | 8461 | |
c19d1205 ZW |
8462 | static void |
8463 | do_iwmmxt_wzero (void) | |
8464 | { | |
8465 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
8466 | inst.instruction |= inst.operands[0].reg; | |
8467 | inst.instruction |= inst.operands[0].reg << 12; | |
8468 | inst.instruction |= inst.operands[0].reg << 16; | |
8469 | } | |
2d447fca JM |
8470 | |
8471 | static void | |
8472 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
8473 | { | |
8474 | if (inst.operands[2].isreg) | |
8475 | do_rd_rn_rm (); | |
8476 | else { | |
8477 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
8478 | _("immediate operand requires iWMMXt2")); | |
8479 | do_rd_rn (); | |
8480 | if (inst.operands[2].imm == 0) | |
8481 | { | |
8482 | switch ((inst.instruction >> 20) & 0xf) | |
8483 | { | |
8484 | case 4: | |
8485 | case 5: | |
8486 | case 6: | |
5f4273c7 | 8487 | case 7: |
2d447fca JM |
8488 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
8489 | inst.operands[2].imm = 16; | |
8490 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
8491 | break; | |
8492 | case 8: | |
8493 | case 9: | |
8494 | case 10: | |
8495 | case 11: | |
8496 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
8497 | inst.operands[2].imm = 32; | |
8498 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
8499 | break; | |
8500 | case 12: | |
8501 | case 13: | |
8502 | case 14: | |
8503 | case 15: | |
8504 | { | |
8505 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
8506 | unsigned long wrn; | |
8507 | wrn = (inst.instruction >> 16) & 0xf; | |
8508 | inst.instruction &= 0xff0fff0f; | |
8509 | inst.instruction |= wrn; | |
8510 | /* Bail out here; the instruction is now assembled. */ | |
8511 | return; | |
8512 | } | |
8513 | } | |
8514 | } | |
8515 | /* Map 32 -> 0, etc. */ | |
8516 | inst.operands[2].imm &= 0x1f; | |
8517 | inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); | |
8518 | } | |
8519 | } | |
c19d1205 ZW |
8520 | \f |
8521 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
8522 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 8523 | |
c19d1205 | 8524 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 8525 | |
c19d1205 ZW |
8526 | static void |
8527 | do_mav_triple (void) | |
8528 | { | |
8529 | inst.instruction |= inst.operands[0].reg << 16; | |
8530 | inst.instruction |= inst.operands[1].reg; | |
8531 | inst.instruction |= inst.operands[2].reg << 12; | |
8532 | } | |
b99bd4ef | 8533 | |
c19d1205 ZW |
8534 | /* Insns like "foo W,X,Y,Z". |
8535 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 8536 | |
c19d1205 ZW |
8537 | static void |
8538 | do_mav_quad (void) | |
8539 | { | |
8540 | inst.instruction |= inst.operands[0].reg << 5; | |
8541 | inst.instruction |= inst.operands[1].reg << 12; | |
8542 | inst.instruction |= inst.operands[2].reg << 16; | |
8543 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
8544 | } |
8545 | ||
c19d1205 ZW |
8546 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
8547 | static void | |
8548 | do_mav_dspsc (void) | |
a737bd4d | 8549 | { |
c19d1205 ZW |
8550 | inst.instruction |= inst.operands[1].reg << 12; |
8551 | } | |
a737bd4d | 8552 | |
c19d1205 ZW |
8553 | /* Maverick shift immediate instructions. |
8554 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
8555 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 8556 | |
c19d1205 ZW |
8557 | static void |
8558 | do_mav_shift (void) | |
8559 | { | |
8560 | int imm = inst.operands[2].imm; | |
a737bd4d | 8561 | |
c19d1205 ZW |
8562 | inst.instruction |= inst.operands[0].reg << 12; |
8563 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 8564 | |
c19d1205 ZW |
8565 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
8566 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
8567 | Bit 4 should be 0. */ | |
8568 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 8569 | |
c19d1205 ZW |
8570 | inst.instruction |= imm; |
8571 | } | |
8572 | \f | |
8573 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 8574 | |
c19d1205 ZW |
8575 | /* Xscale multiply-accumulate (argument parse) |
8576 | MIAcc acc0,Rm,Rs | |
8577 | MIAPHcc acc0,Rm,Rs | |
8578 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 8579 | |
c19d1205 ZW |
8580 | static void |
8581 | do_xsc_mia (void) | |
8582 | { | |
8583 | inst.instruction |= inst.operands[1].reg; | |
8584 | inst.instruction |= inst.operands[2].reg << 12; | |
8585 | } | |
a737bd4d | 8586 | |
c19d1205 | 8587 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 8588 | |
c19d1205 | 8589 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 8590 | |
c19d1205 ZW |
8591 | static void |
8592 | do_xsc_mar (void) | |
8593 | { | |
8594 | inst.instruction |= inst.operands[1].reg << 12; | |
8595 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8596 | } |
8597 | ||
c19d1205 | 8598 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 8599 | |
c19d1205 | 8600 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
8601 | |
8602 | static void | |
c19d1205 | 8603 | do_xsc_mra (void) |
b99bd4ef | 8604 | { |
c19d1205 ZW |
8605 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
8606 | inst.instruction |= inst.operands[0].reg << 12; | |
8607 | inst.instruction |= inst.operands[1].reg << 16; | |
8608 | } | |
8609 | \f | |
8610 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 8611 | |
c19d1205 ZW |
8612 | /* inst.operands[i] is a shifted-register operand; encode |
8613 | it into inst.instruction in the format used by Thumb32. */ | |
8614 | ||
8615 | static void | |
8616 | encode_thumb32_shifted_operand (int i) | |
8617 | { | |
8618 | unsigned int value = inst.reloc.exp.X_add_number; | |
8619 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 8620 | |
9c3c69f2 PB |
8621 | constraint (inst.operands[i].immisreg, |
8622 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
8623 | inst.instruction |= inst.operands[i].reg; |
8624 | if (shift == SHIFT_RRX) | |
8625 | inst.instruction |= SHIFT_ROR << 4; | |
8626 | else | |
b99bd4ef | 8627 | { |
c19d1205 ZW |
8628 | constraint (inst.reloc.exp.X_op != O_constant, |
8629 | _("expression too complex")); | |
8630 | ||
8631 | constraint (value > 32 | |
8632 | || (value == 32 && (shift == SHIFT_LSL | |
8633 | || shift == SHIFT_ROR)), | |
8634 | _("shift expression is too large")); | |
8635 | ||
8636 | if (value == 0) | |
8637 | shift = SHIFT_LSL; | |
8638 | else if (value == 32) | |
8639 | value = 0; | |
8640 | ||
8641 | inst.instruction |= shift << 4; | |
8642 | inst.instruction |= (value & 0x1c) << 10; | |
8643 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 8644 | } |
c19d1205 | 8645 | } |
b99bd4ef | 8646 | |
b99bd4ef | 8647 | |
c19d1205 ZW |
8648 | /* inst.operands[i] was set up by parse_address. Encode it into a |
8649 | Thumb32 format load or store instruction. Reject forms that cannot | |
8650 | be used with such instructions. If is_t is true, reject forms that | |
8651 | cannot be used with a T instruction; if is_d is true, reject forms | |
8652 | that cannot be used with a D instruction. */ | |
b99bd4ef | 8653 | |
c19d1205 ZW |
8654 | static void |
8655 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
8656 | { | |
8657 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
8658 | ||
8659 | constraint (!inst.operands[i].isreg, | |
53365c0d | 8660 | _("Instruction does not support =N addresses")); |
b99bd4ef | 8661 | |
c19d1205 ZW |
8662 | inst.instruction |= inst.operands[i].reg << 16; |
8663 | if (inst.operands[i].immisreg) | |
b99bd4ef | 8664 | { |
c19d1205 ZW |
8665 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
8666 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
8667 | constraint (inst.operands[i].negative, | |
8668 | _("Thumb does not support negative register indexing")); | |
8669 | constraint (inst.operands[i].postind, | |
8670 | _("Thumb does not support register post-indexing")); | |
8671 | constraint (inst.operands[i].writeback, | |
8672 | _("Thumb does not support register indexing with writeback")); | |
8673 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
8674 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 8675 | |
f40d1643 | 8676 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 8677 | if (inst.operands[i].shifted) |
b99bd4ef | 8678 | { |
c19d1205 ZW |
8679 | constraint (inst.reloc.exp.X_op != O_constant, |
8680 | _("expression too complex")); | |
9c3c69f2 PB |
8681 | constraint (inst.reloc.exp.X_add_number < 0 |
8682 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 8683 | _("shift out of range")); |
9c3c69f2 | 8684 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
8685 | } |
8686 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8687 | } | |
8688 | else if (inst.operands[i].preind) | |
8689 | { | |
8690 | constraint (is_pc && inst.operands[i].writeback, | |
8691 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 8692 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
8693 | _("cannot use writeback with this instruction")); |
8694 | ||
8695 | if (is_d) | |
8696 | { | |
8697 | inst.instruction |= 0x01000000; | |
8698 | if (inst.operands[i].writeback) | |
8699 | inst.instruction |= 0x00200000; | |
b99bd4ef | 8700 | } |
c19d1205 | 8701 | else |
b99bd4ef | 8702 | { |
c19d1205 ZW |
8703 | inst.instruction |= 0x00000c00; |
8704 | if (inst.operands[i].writeback) | |
8705 | inst.instruction |= 0x00000100; | |
b99bd4ef | 8706 | } |
c19d1205 | 8707 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 8708 | } |
c19d1205 | 8709 | else if (inst.operands[i].postind) |
b99bd4ef | 8710 | { |
9c2799c2 | 8711 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
8712 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
8713 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
8714 | ||
8715 | if (is_d) | |
8716 | inst.instruction |= 0x00200000; | |
8717 | else | |
8718 | inst.instruction |= 0x00000900; | |
8719 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
8720 | } | |
8721 | else /* unindexed - only for coprocessor */ | |
8722 | inst.error = _("instruction does not accept unindexed addressing"); | |
8723 | } | |
8724 | ||
8725 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
8726 | encodings (the latter only in post-V6T2 cores). The index is the | |
8727 | value used in the insns table below. When there is more than one | |
8728 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
8729 | holds variant (1). |
8730 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 8731 | #define T16_32_TAB \ |
21d799b5 NC |
8732 | X(_adc, 4140, eb400000), \ |
8733 | X(_adcs, 4140, eb500000), \ | |
8734 | X(_add, 1c00, eb000000), \ | |
8735 | X(_adds, 1c00, eb100000), \ | |
8736 | X(_addi, 0000, f1000000), \ | |
8737 | X(_addis, 0000, f1100000), \ | |
8738 | X(_add_pc,000f, f20f0000), \ | |
8739 | X(_add_sp,000d, f10d0000), \ | |
8740 | X(_adr, 000f, f20f0000), \ | |
8741 | X(_and, 4000, ea000000), \ | |
8742 | X(_ands, 4000, ea100000), \ | |
8743 | X(_asr, 1000, fa40f000), \ | |
8744 | X(_asrs, 1000, fa50f000), \ | |
8745 | X(_b, e000, f000b000), \ | |
8746 | X(_bcond, d000, f0008000), \ | |
8747 | X(_bic, 4380, ea200000), \ | |
8748 | X(_bics, 4380, ea300000), \ | |
8749 | X(_cmn, 42c0, eb100f00), \ | |
8750 | X(_cmp, 2800, ebb00f00), \ | |
8751 | X(_cpsie, b660, f3af8400), \ | |
8752 | X(_cpsid, b670, f3af8600), \ | |
8753 | X(_cpy, 4600, ea4f0000), \ | |
8754 | X(_dec_sp,80dd, f1ad0d00), \ | |
8755 | X(_eor, 4040, ea800000), \ | |
8756 | X(_eors, 4040, ea900000), \ | |
8757 | X(_inc_sp,00dd, f10d0d00), \ | |
8758 | X(_ldmia, c800, e8900000), \ | |
8759 | X(_ldr, 6800, f8500000), \ | |
8760 | X(_ldrb, 7800, f8100000), \ | |
8761 | X(_ldrh, 8800, f8300000), \ | |
8762 | X(_ldrsb, 5600, f9100000), \ | |
8763 | X(_ldrsh, 5e00, f9300000), \ | |
8764 | X(_ldr_pc,4800, f85f0000), \ | |
8765 | X(_ldr_pc2,4800, f85f0000), \ | |
8766 | X(_ldr_sp,9800, f85d0000), \ | |
8767 | X(_lsl, 0000, fa00f000), \ | |
8768 | X(_lsls, 0000, fa10f000), \ | |
8769 | X(_lsr, 0800, fa20f000), \ | |
8770 | X(_lsrs, 0800, fa30f000), \ | |
8771 | X(_mov, 2000, ea4f0000), \ | |
8772 | X(_movs, 2000, ea5f0000), \ | |
8773 | X(_mul, 4340, fb00f000), \ | |
8774 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
8775 | X(_mvn, 43c0, ea6f0000), \ | |
8776 | X(_mvns, 43c0, ea7f0000), \ | |
8777 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
8778 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
8779 | X(_orr, 4300, ea400000), \ | |
8780 | X(_orrs, 4300, ea500000), \ | |
8781 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
8782 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
8783 | X(_rev, ba00, fa90f080), \ | |
8784 | X(_rev16, ba40, fa90f090), \ | |
8785 | X(_revsh, bac0, fa90f0b0), \ | |
8786 | X(_ror, 41c0, fa60f000), \ | |
8787 | X(_rors, 41c0, fa70f000), \ | |
8788 | X(_sbc, 4180, eb600000), \ | |
8789 | X(_sbcs, 4180, eb700000), \ | |
8790 | X(_stmia, c000, e8800000), \ | |
8791 | X(_str, 6000, f8400000), \ | |
8792 | X(_strb, 7000, f8000000), \ | |
8793 | X(_strh, 8000, f8200000), \ | |
8794 | X(_str_sp,9000, f84d0000), \ | |
8795 | X(_sub, 1e00, eba00000), \ | |
8796 | X(_subs, 1e00, ebb00000), \ | |
8797 | X(_subi, 8000, f1a00000), \ | |
8798 | X(_subis, 8000, f1b00000), \ | |
8799 | X(_sxtb, b240, fa4ff080), \ | |
8800 | X(_sxth, b200, fa0ff080), \ | |
8801 | X(_tst, 4200, ea100f00), \ | |
8802 | X(_uxtb, b2c0, fa5ff080), \ | |
8803 | X(_uxth, b280, fa1ff080), \ | |
8804 | X(_nop, bf00, f3af8000), \ | |
8805 | X(_yield, bf10, f3af8001), \ | |
8806 | X(_wfe, bf20, f3af8002), \ | |
8807 | X(_wfi, bf30, f3af8003), \ | |
8808 | X(_sev, bf40, f3af8004), | |
c19d1205 ZW |
8809 | |
8810 | /* To catch errors in encoding functions, the codes are all offset by | |
8811 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
8812 | as 16-bit instructions. */ | |
21d799b5 | 8813 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
8814 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
8815 | #undef X | |
8816 | ||
8817 | #define X(a,b,c) 0x##b | |
8818 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
8819 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
8820 | #undef X | |
8821 | ||
8822 | #define X(a,b,c) 0x##c | |
8823 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
8824 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
8825 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
8826 | #undef X |
8827 | #undef T16_32_TAB | |
8828 | ||
8829 | /* Thumb instruction encoders, in alphabetical order. */ | |
8830 | ||
92e90b6e | 8831 | /* ADDW or SUBW. */ |
c921be7d | 8832 | |
92e90b6e PB |
8833 | static void |
8834 | do_t_add_sub_w (void) | |
8835 | { | |
8836 | int Rd, Rn; | |
8837 | ||
8838 | Rd = inst.operands[0].reg; | |
8839 | Rn = inst.operands[1].reg; | |
8840 | ||
539d4391 NC |
8841 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
8842 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
8843 | if (Rn == REG_SP) | |
8844 | constraint (Rd == REG_PC, BAD_PC); | |
8845 | else | |
8846 | reject_bad_reg (Rd); | |
fdfde340 | 8847 | |
92e90b6e PB |
8848 | inst.instruction |= (Rn << 16) | (Rd << 8); |
8849 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8850 | } | |
8851 | ||
c19d1205 ZW |
8852 | /* Parse an add or subtract instruction. We get here with inst.instruction |
8853 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
8854 | ||
8855 | static void | |
8856 | do_t_add_sub (void) | |
8857 | { | |
8858 | int Rd, Rs, Rn; | |
8859 | ||
8860 | Rd = inst.operands[0].reg; | |
8861 | Rs = (inst.operands[1].present | |
8862 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8863 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8864 | ||
e07e6e58 NC |
8865 | if (Rd == REG_PC) |
8866 | set_it_insn_type_last (); | |
8867 | ||
c19d1205 ZW |
8868 | if (unified_syntax) |
8869 | { | |
0110f2b8 PB |
8870 | bfd_boolean flags; |
8871 | bfd_boolean narrow; | |
8872 | int opcode; | |
8873 | ||
8874 | flags = (inst.instruction == T_MNEM_adds | |
8875 | || inst.instruction == T_MNEM_subs); | |
8876 | if (flags) | |
e07e6e58 | 8877 | narrow = !in_it_block (); |
0110f2b8 | 8878 | else |
e07e6e58 | 8879 | narrow = in_it_block (); |
c19d1205 | 8880 | if (!inst.operands[2].isreg) |
b99bd4ef | 8881 | { |
16805f35 PB |
8882 | int add; |
8883 | ||
fdfde340 JM |
8884 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
8885 | ||
16805f35 PB |
8886 | add = (inst.instruction == T_MNEM_add |
8887 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
8888 | opcode = 0; |
8889 | if (inst.size_req != 4) | |
8890 | { | |
0110f2b8 PB |
8891 | /* Attempt to use a narrow opcode, with relaxation if |
8892 | appropriate. */ | |
8893 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
8894 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
8895 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
8896 | opcode = T_MNEM_add_sp; | |
8897 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
8898 | opcode = T_MNEM_add_pc; | |
8899 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
8900 | { | |
8901 | if (flags) | |
8902 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
8903 | else | |
8904 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
8905 | } | |
8906 | if (opcode) | |
8907 | { | |
8908 | inst.instruction = THUMB_OP16(opcode); | |
8909 | inst.instruction |= (Rd << 4) | Rs; | |
8910 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8911 | if (inst.size_req != 2) | |
8912 | inst.relax = opcode; | |
8913 | } | |
8914 | else | |
8915 | constraint (inst.size_req == 2, BAD_HIREG); | |
8916 | } | |
8917 | if (inst.size_req == 4 | |
8918 | || (inst.size_req != 2 && !opcode)) | |
8919 | { | |
efd81785 PB |
8920 | if (Rd == REG_PC) |
8921 | { | |
fdfde340 | 8922 | constraint (add, BAD_PC); |
efd81785 PB |
8923 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
8924 | _("only SUBS PC, LR, #const allowed")); | |
8925 | constraint (inst.reloc.exp.X_op != O_constant, | |
8926 | _("expression too complex")); | |
8927 | constraint (inst.reloc.exp.X_add_number < 0 | |
8928 | || inst.reloc.exp.X_add_number > 0xff, | |
8929 | _("immediate value out of range")); | |
8930 | inst.instruction = T2_SUBS_PC_LR | |
8931 | | inst.reloc.exp.X_add_number; | |
8932 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8933 | return; | |
8934 | } | |
8935 | else if (Rs == REG_PC) | |
16805f35 PB |
8936 | { |
8937 | /* Always use addw/subw. */ | |
8938 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
8939 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8940 | } | |
8941 | else | |
8942 | { | |
8943 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8944 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
8945 | | 0x10000000; | |
8946 | if (flags) | |
8947 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8948 | else | |
8949 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
8950 | } | |
dc4503c6 PB |
8951 | inst.instruction |= Rd << 8; |
8952 | inst.instruction |= Rs << 16; | |
0110f2b8 | 8953 | } |
b99bd4ef | 8954 | } |
c19d1205 ZW |
8955 | else |
8956 | { | |
8957 | Rn = inst.operands[2].reg; | |
8958 | /* See if we can do this with a 16-bit instruction. */ | |
8959 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
8960 | { | |
e27ec89e PB |
8961 | if (Rd > 7 || Rs > 7 || Rn > 7) |
8962 | narrow = FALSE; | |
8963 | ||
8964 | if (narrow) | |
c19d1205 | 8965 | { |
e27ec89e PB |
8966 | inst.instruction = ((inst.instruction == T_MNEM_adds |
8967 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
8968 | ? T_OPCODE_ADD_R3 |
8969 | : T_OPCODE_SUB_R3); | |
8970 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
8971 | return; | |
8972 | } | |
b99bd4ef | 8973 | |
7e806470 | 8974 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 8975 | { |
7e806470 PB |
8976 | /* Thumb-1 cores (except v6-M) require at least one high |
8977 | register in a narrow non flag setting add. */ | |
8978 | if (Rd > 7 || Rn > 7 | |
8979 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
8980 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 8981 | { |
7e806470 PB |
8982 | if (Rd == Rn) |
8983 | { | |
8984 | Rn = Rs; | |
8985 | Rs = Rd; | |
8986 | } | |
c19d1205 ZW |
8987 | inst.instruction = T_OPCODE_ADD_HI; |
8988 | inst.instruction |= (Rd & 8) << 4; | |
8989 | inst.instruction |= (Rd & 7); | |
8990 | inst.instruction |= Rn << 3; | |
8991 | return; | |
8992 | } | |
c19d1205 ZW |
8993 | } |
8994 | } | |
c921be7d | 8995 | |
fdfde340 JM |
8996 | constraint (Rd == REG_PC, BAD_PC); |
8997 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
8998 | constraint (Rs == REG_PC, BAD_PC); | |
8999 | reject_bad_reg (Rn); | |
9000 | ||
c19d1205 ZW |
9001 | /* If we get here, it can't be done in 16 bits. */ |
9002 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
9003 | _("shift must be constant")); | |
9004 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9005 | inst.instruction |= Rd << 8; | |
9006 | inst.instruction |= Rs << 16; | |
9007 | encode_thumb32_shifted_operand (2); | |
9008 | } | |
9009 | } | |
9010 | else | |
9011 | { | |
9012 | constraint (inst.instruction == T_MNEM_adds | |
9013 | || inst.instruction == T_MNEM_subs, | |
9014 | BAD_THUMB32); | |
b99bd4ef | 9015 | |
c19d1205 | 9016 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 9017 | { |
c19d1205 ZW |
9018 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
9019 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
9020 | BAD_HIREG); | |
9021 | ||
9022 | inst.instruction = (inst.instruction == T_MNEM_add | |
9023 | ? 0x0000 : 0x8000); | |
9024 | inst.instruction |= (Rd << 4) | Rs; | |
9025 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
9026 | return; |
9027 | } | |
9028 | ||
c19d1205 ZW |
9029 | Rn = inst.operands[2].reg; |
9030 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 9031 | |
c19d1205 ZW |
9032 | /* We now have Rd, Rs, and Rn set to registers. */ |
9033 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 9034 | { |
c19d1205 ZW |
9035 | /* Can't do this for SUB. */ |
9036 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
9037 | inst.instruction = T_OPCODE_ADD_HI; | |
9038 | inst.instruction |= (Rd & 8) << 4; | |
9039 | inst.instruction |= (Rd & 7); | |
9040 | if (Rs == Rd) | |
9041 | inst.instruction |= Rn << 3; | |
9042 | else if (Rn == Rd) | |
9043 | inst.instruction |= Rs << 3; | |
9044 | else | |
9045 | constraint (1, _("dest must overlap one source register")); | |
9046 | } | |
9047 | else | |
9048 | { | |
9049 | inst.instruction = (inst.instruction == T_MNEM_add | |
9050 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
9051 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 9052 | } |
b99bd4ef | 9053 | } |
b99bd4ef NC |
9054 | } |
9055 | ||
c19d1205 ZW |
9056 | static void |
9057 | do_t_adr (void) | |
9058 | { | |
fdfde340 JM |
9059 | unsigned Rd; |
9060 | ||
9061 | Rd = inst.operands[0].reg; | |
9062 | reject_bad_reg (Rd); | |
9063 | ||
9064 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
9065 | { |
9066 | /* Defer to section relaxation. */ | |
9067 | inst.relax = inst.instruction; | |
9068 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 9069 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
9070 | } |
9071 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 9072 | { |
0110f2b8 | 9073 | /* Generate a 32-bit opcode. */ |
e9f89963 | 9074 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 9075 | inst.instruction |= Rd << 8; |
e9f89963 PB |
9076 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
9077 | inst.reloc.pc_rel = 1; | |
9078 | } | |
9079 | else | |
9080 | { | |
0110f2b8 | 9081 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
9082 | inst.instruction = THUMB_OP16 (inst.instruction); |
9083 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
9084 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
9085 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 9086 | |
fdfde340 | 9087 | inst.instruction |= Rd << 4; |
e9f89963 | 9088 | } |
c19d1205 | 9089 | } |
b99bd4ef | 9090 | |
c19d1205 ZW |
9091 | /* Arithmetic instructions for which there is just one 16-bit |
9092 | instruction encoding, and it allows only two low registers. | |
9093 | For maximal compatibility with ARM syntax, we allow three register | |
9094 | operands even when Thumb-32 instructions are not available, as long | |
9095 | as the first two are identical. For instance, both "sbc r0,r1" and | |
9096 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 9097 | static void |
c19d1205 | 9098 | do_t_arit3 (void) |
b99bd4ef | 9099 | { |
c19d1205 | 9100 | int Rd, Rs, Rn; |
b99bd4ef | 9101 | |
c19d1205 ZW |
9102 | Rd = inst.operands[0].reg; |
9103 | Rs = (inst.operands[1].present | |
9104 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9105 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9106 | Rn = inst.operands[2].reg; | |
b99bd4ef | 9107 | |
fdfde340 JM |
9108 | reject_bad_reg (Rd); |
9109 | reject_bad_reg (Rs); | |
9110 | if (inst.operands[2].isreg) | |
9111 | reject_bad_reg (Rn); | |
9112 | ||
c19d1205 | 9113 | if (unified_syntax) |
b99bd4ef | 9114 | { |
c19d1205 ZW |
9115 | if (!inst.operands[2].isreg) |
9116 | { | |
9117 | /* For an immediate, we always generate a 32-bit opcode; | |
9118 | section relaxation will shrink it later if possible. */ | |
9119 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9120 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9121 | inst.instruction |= Rd << 8; | |
9122 | inst.instruction |= Rs << 16; | |
9123 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9124 | } | |
9125 | else | |
9126 | { | |
e27ec89e PB |
9127 | bfd_boolean narrow; |
9128 | ||
c19d1205 | 9129 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9130 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9131 | narrow = !in_it_block (); |
e27ec89e | 9132 | else |
e07e6e58 | 9133 | narrow = in_it_block (); |
e27ec89e PB |
9134 | |
9135 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9136 | narrow = FALSE; | |
9137 | if (inst.operands[2].shifted) | |
9138 | narrow = FALSE; | |
9139 | if (inst.size_req == 4) | |
9140 | narrow = FALSE; | |
9141 | ||
9142 | if (narrow | |
c19d1205 ZW |
9143 | && Rd == Rs) |
9144 | { | |
9145 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9146 | inst.instruction |= Rd; | |
9147 | inst.instruction |= Rn << 3; | |
9148 | return; | |
9149 | } | |
b99bd4ef | 9150 | |
c19d1205 ZW |
9151 | /* If we get here, it can't be done in 16 bits. */ |
9152 | constraint (inst.operands[2].shifted | |
9153 | && inst.operands[2].immisreg, | |
9154 | _("shift must be constant")); | |
9155 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9156 | inst.instruction |= Rd << 8; | |
9157 | inst.instruction |= Rs << 16; | |
9158 | encode_thumb32_shifted_operand (2); | |
9159 | } | |
a737bd4d | 9160 | } |
c19d1205 | 9161 | else |
b99bd4ef | 9162 | { |
c19d1205 ZW |
9163 | /* On its face this is a lie - the instruction does set the |
9164 | flags. However, the only supported mnemonic in this mode | |
9165 | says it doesn't. */ | |
9166 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9167 | |
c19d1205 ZW |
9168 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9169 | _("unshifted register required")); | |
9170 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9171 | constraint (Rd != Rs, | |
9172 | _("dest and source1 must be the same register")); | |
a737bd4d | 9173 | |
c19d1205 ZW |
9174 | inst.instruction = THUMB_OP16 (inst.instruction); |
9175 | inst.instruction |= Rd; | |
9176 | inst.instruction |= Rn << 3; | |
b99bd4ef | 9177 | } |
a737bd4d | 9178 | } |
b99bd4ef | 9179 | |
c19d1205 ZW |
9180 | /* Similarly, but for instructions where the arithmetic operation is |
9181 | commutative, so we can allow either of them to be different from | |
9182 | the destination operand in a 16-bit instruction. For instance, all | |
9183 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
9184 | accepted. */ | |
9185 | static void | |
9186 | do_t_arit3c (void) | |
a737bd4d | 9187 | { |
c19d1205 | 9188 | int Rd, Rs, Rn; |
b99bd4ef | 9189 | |
c19d1205 ZW |
9190 | Rd = inst.operands[0].reg; |
9191 | Rs = (inst.operands[1].present | |
9192 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9193 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9194 | Rn = inst.operands[2].reg; | |
c921be7d | 9195 | |
fdfde340 JM |
9196 | reject_bad_reg (Rd); |
9197 | reject_bad_reg (Rs); | |
9198 | if (inst.operands[2].isreg) | |
9199 | reject_bad_reg (Rn); | |
a737bd4d | 9200 | |
c19d1205 | 9201 | if (unified_syntax) |
a737bd4d | 9202 | { |
c19d1205 | 9203 | if (!inst.operands[2].isreg) |
b99bd4ef | 9204 | { |
c19d1205 ZW |
9205 | /* For an immediate, we always generate a 32-bit opcode; |
9206 | section relaxation will shrink it later if possible. */ | |
9207 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9208 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9209 | inst.instruction |= Rd << 8; | |
9210 | inst.instruction |= Rs << 16; | |
9211 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 9212 | } |
c19d1205 | 9213 | else |
a737bd4d | 9214 | { |
e27ec89e PB |
9215 | bfd_boolean narrow; |
9216 | ||
c19d1205 | 9217 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9218 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9219 | narrow = !in_it_block (); |
e27ec89e | 9220 | else |
e07e6e58 | 9221 | narrow = in_it_block (); |
e27ec89e PB |
9222 | |
9223 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9224 | narrow = FALSE; | |
9225 | if (inst.operands[2].shifted) | |
9226 | narrow = FALSE; | |
9227 | if (inst.size_req == 4) | |
9228 | narrow = FALSE; | |
9229 | ||
9230 | if (narrow) | |
a737bd4d | 9231 | { |
c19d1205 | 9232 | if (Rd == Rs) |
a737bd4d | 9233 | { |
c19d1205 ZW |
9234 | inst.instruction = THUMB_OP16 (inst.instruction); |
9235 | inst.instruction |= Rd; | |
9236 | inst.instruction |= Rn << 3; | |
9237 | return; | |
a737bd4d | 9238 | } |
c19d1205 | 9239 | if (Rd == Rn) |
a737bd4d | 9240 | { |
c19d1205 ZW |
9241 | inst.instruction = THUMB_OP16 (inst.instruction); |
9242 | inst.instruction |= Rd; | |
9243 | inst.instruction |= Rs << 3; | |
9244 | return; | |
a737bd4d NC |
9245 | } |
9246 | } | |
c19d1205 ZW |
9247 | |
9248 | /* If we get here, it can't be done in 16 bits. */ | |
9249 | constraint (inst.operands[2].shifted | |
9250 | && inst.operands[2].immisreg, | |
9251 | _("shift must be constant")); | |
9252 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9253 | inst.instruction |= Rd << 8; | |
9254 | inst.instruction |= Rs << 16; | |
9255 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 9256 | } |
b99bd4ef | 9257 | } |
c19d1205 ZW |
9258 | else |
9259 | { | |
9260 | /* On its face this is a lie - the instruction does set the | |
9261 | flags. However, the only supported mnemonic in this mode | |
9262 | says it doesn't. */ | |
9263 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9264 | |
c19d1205 ZW |
9265 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9266 | _("unshifted register required")); | |
9267 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9268 | ||
9269 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9270 | inst.instruction |= Rd; | |
9271 | ||
9272 | if (Rd == Rs) | |
9273 | inst.instruction |= Rn << 3; | |
9274 | else if (Rd == Rn) | |
9275 | inst.instruction |= Rs << 3; | |
9276 | else | |
9277 | constraint (1, _("dest must overlap one source register")); | |
9278 | } | |
a737bd4d NC |
9279 | } |
9280 | ||
62b3e311 PB |
9281 | static void |
9282 | do_t_barrier (void) | |
9283 | { | |
9284 | if (inst.operands[0].present) | |
9285 | { | |
9286 | constraint ((inst.instruction & 0xf0) != 0x40 | |
9287 | && inst.operands[0].imm != 0xf, | |
bd3ba5d1 | 9288 | _("bad barrier type")); |
62b3e311 PB |
9289 | inst.instruction |= inst.operands[0].imm; |
9290 | } | |
9291 | else | |
9292 | inst.instruction |= 0xf; | |
9293 | } | |
9294 | ||
c19d1205 ZW |
9295 | static void |
9296 | do_t_bfc (void) | |
a737bd4d | 9297 | { |
fdfde340 | 9298 | unsigned Rd; |
c19d1205 ZW |
9299 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
9300 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9301 | /* The instruction encoding stores the LSB and MSB, | |
9302 | not the LSB and width. */ | |
fdfde340 JM |
9303 | Rd = inst.operands[0].reg; |
9304 | reject_bad_reg (Rd); | |
9305 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
9306 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
9307 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
9308 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9309 | } |
9310 | ||
c19d1205 ZW |
9311 | static void |
9312 | do_t_bfi (void) | |
b99bd4ef | 9313 | { |
fdfde340 | 9314 | int Rd, Rn; |
c19d1205 | 9315 | unsigned int msb; |
b99bd4ef | 9316 | |
fdfde340 JM |
9317 | Rd = inst.operands[0].reg; |
9318 | reject_bad_reg (Rd); | |
9319 | ||
c19d1205 ZW |
9320 | /* #0 in second position is alternative syntax for bfc, which is |
9321 | the same instruction but with REG_PC in the Rm field. */ | |
9322 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
9323 | Rn = REG_PC; |
9324 | else | |
9325 | { | |
9326 | Rn = inst.operands[1].reg; | |
9327 | reject_bad_reg (Rn); | |
9328 | } | |
b99bd4ef | 9329 | |
c19d1205 ZW |
9330 | msb = inst.operands[2].imm + inst.operands[3].imm; |
9331 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9332 | /* The instruction encoding stores the LSB and MSB, | |
9333 | not the LSB and width. */ | |
fdfde340 JM |
9334 | inst.instruction |= Rd << 8; |
9335 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9336 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9337 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9338 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9339 | } |
9340 | ||
c19d1205 ZW |
9341 | static void |
9342 | do_t_bfx (void) | |
b99bd4ef | 9343 | { |
fdfde340 JM |
9344 | unsigned Rd, Rn; |
9345 | ||
9346 | Rd = inst.operands[0].reg; | |
9347 | Rn = inst.operands[1].reg; | |
9348 | ||
9349 | reject_bad_reg (Rd); | |
9350 | reject_bad_reg (Rn); | |
9351 | ||
c19d1205 ZW |
9352 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
9353 | _("bit-field extends past end of register")); | |
fdfde340 JM |
9354 | inst.instruction |= Rd << 8; |
9355 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9356 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9357 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9358 | inst.instruction |= inst.operands[3].imm - 1; | |
9359 | } | |
b99bd4ef | 9360 | |
c19d1205 ZW |
9361 | /* ARM V5 Thumb BLX (argument parse) |
9362 | BLX <target_addr> which is BLX(1) | |
9363 | BLX <Rm> which is BLX(2) | |
9364 | Unfortunately, there are two different opcodes for this mnemonic. | |
9365 | So, the insns[].value is not used, and the code here zaps values | |
9366 | into inst.instruction. | |
b99bd4ef | 9367 | |
c19d1205 ZW |
9368 | ??? How to take advantage of the additional two bits of displacement |
9369 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 9370 | |
c19d1205 ZW |
9371 | static void |
9372 | do_t_blx (void) | |
9373 | { | |
e07e6e58 NC |
9374 | set_it_insn_type_last (); |
9375 | ||
c19d1205 | 9376 | if (inst.operands[0].isreg) |
fdfde340 JM |
9377 | { |
9378 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
9379 | /* We have a register, so this is BLX(2). */ | |
9380 | inst.instruction |= inst.operands[0].reg << 3; | |
9381 | } | |
b99bd4ef NC |
9382 | else |
9383 | { | |
c19d1205 | 9384 | /* No register. This must be BLX(1). */ |
2fc8bdac | 9385 | inst.instruction = 0xf000e800; |
00adf2d4 | 9386 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; |
c19d1205 | 9387 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
9388 | } |
9389 | } | |
9390 | ||
c19d1205 ZW |
9391 | static void |
9392 | do_t_branch (void) | |
b99bd4ef | 9393 | { |
0110f2b8 | 9394 | int opcode; |
dfa9f0d5 PB |
9395 | int cond; |
9396 | ||
e07e6e58 NC |
9397 | cond = inst.cond; |
9398 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
9399 | ||
9400 | if (in_it_block ()) | |
dfa9f0d5 PB |
9401 | { |
9402 | /* Conditional branches inside IT blocks are encoded as unconditional | |
9403 | branches. */ | |
9404 | cond = COND_ALWAYS; | |
dfa9f0d5 PB |
9405 | } |
9406 | else | |
9407 | cond = inst.cond; | |
9408 | ||
9409 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
9410 | opcode = T_MNEM_bcond; |
9411 | else | |
9412 | opcode = inst.instruction; | |
9413 | ||
9414 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 9415 | { |
0110f2b8 | 9416 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 9417 | if (cond == COND_ALWAYS) |
0110f2b8 | 9418 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
9419 | else |
9420 | { | |
9c2799c2 | 9421 | gas_assert (cond != 0xF); |
dfa9f0d5 | 9422 | inst.instruction |= cond << 22; |
c19d1205 ZW |
9423 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
9424 | } | |
9425 | } | |
b99bd4ef NC |
9426 | else |
9427 | { | |
0110f2b8 | 9428 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 9429 | if (cond == COND_ALWAYS) |
c19d1205 ZW |
9430 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; |
9431 | else | |
b99bd4ef | 9432 | { |
dfa9f0d5 | 9433 | inst.instruction |= cond << 8; |
c19d1205 | 9434 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 9435 | } |
0110f2b8 PB |
9436 | /* Allow section relaxation. */ |
9437 | if (unified_syntax && inst.size_req != 2) | |
9438 | inst.relax = opcode; | |
b99bd4ef | 9439 | } |
c19d1205 ZW |
9440 | |
9441 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
9442 | } |
9443 | ||
9444 | static void | |
c19d1205 | 9445 | do_t_bkpt (void) |
b99bd4ef | 9446 | { |
dfa9f0d5 PB |
9447 | constraint (inst.cond != COND_ALWAYS, |
9448 | _("instruction is always unconditional")); | |
c19d1205 | 9449 | if (inst.operands[0].present) |
b99bd4ef | 9450 | { |
c19d1205 ZW |
9451 | constraint (inst.operands[0].imm > 255, |
9452 | _("immediate value out of range")); | |
9453 | inst.instruction |= inst.operands[0].imm; | |
e07e6e58 | 9454 | set_it_insn_type (NEUTRAL_IT_INSN); |
b99bd4ef | 9455 | } |
b99bd4ef NC |
9456 | } |
9457 | ||
9458 | static void | |
c19d1205 | 9459 | do_t_branch23 (void) |
b99bd4ef | 9460 | { |
e07e6e58 | 9461 | set_it_insn_type_last (); |
c19d1205 | 9462 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
9463 | inst.reloc.pc_rel = 1; |
9464 | ||
4343666d | 9465 | #if defined(OBJ_COFF) |
c19d1205 ZW |
9466 | /* If the destination of the branch is a defined symbol which does not have |
9467 | the THUMB_FUNC attribute, then we must be calling a function which has | |
9468 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
9469 | function and change the branch to refer to that function instead. */ | |
9470 | if ( inst.reloc.exp.X_op == O_symbol | |
9471 | && inst.reloc.exp.X_add_symbol != NULL | |
9472 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
9473 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
9474 | inst.reloc.exp.X_add_symbol = | |
9475 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 9476 | #endif |
90e4755a RE |
9477 | } |
9478 | ||
9479 | static void | |
c19d1205 | 9480 | do_t_bx (void) |
90e4755a | 9481 | { |
e07e6e58 | 9482 | set_it_insn_type_last (); |
c19d1205 ZW |
9483 | inst.instruction |= inst.operands[0].reg << 3; |
9484 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
9485 | should cause the alignment to be checked once it is known. This is | |
9486 | because BX PC only works if the instruction is word aligned. */ | |
9487 | } | |
90e4755a | 9488 | |
c19d1205 ZW |
9489 | static void |
9490 | do_t_bxj (void) | |
9491 | { | |
fdfde340 | 9492 | int Rm; |
90e4755a | 9493 | |
e07e6e58 | 9494 | set_it_insn_type_last (); |
fdfde340 JM |
9495 | Rm = inst.operands[0].reg; |
9496 | reject_bad_reg (Rm); | |
9497 | inst.instruction |= Rm << 16; | |
90e4755a RE |
9498 | } |
9499 | ||
9500 | static void | |
c19d1205 | 9501 | do_t_clz (void) |
90e4755a | 9502 | { |
fdfde340 JM |
9503 | unsigned Rd; |
9504 | unsigned Rm; | |
9505 | ||
9506 | Rd = inst.operands[0].reg; | |
9507 | Rm = inst.operands[1].reg; | |
9508 | ||
9509 | reject_bad_reg (Rd); | |
9510 | reject_bad_reg (Rm); | |
9511 | ||
9512 | inst.instruction |= Rd << 8; | |
9513 | inst.instruction |= Rm << 16; | |
9514 | inst.instruction |= Rm; | |
c19d1205 | 9515 | } |
90e4755a | 9516 | |
dfa9f0d5 PB |
9517 | static void |
9518 | do_t_cps (void) | |
9519 | { | |
e07e6e58 | 9520 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
9521 | inst.instruction |= inst.operands[0].imm; |
9522 | } | |
9523 | ||
c19d1205 ZW |
9524 | static void |
9525 | do_t_cpsi (void) | |
9526 | { | |
e07e6e58 | 9527 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 9528 | if (unified_syntax |
62b3e311 PB |
9529 | && (inst.operands[1].present || inst.size_req == 4) |
9530 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 9531 | { |
c19d1205 ZW |
9532 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
9533 | inst.instruction = 0xf3af8000; | |
9534 | inst.instruction |= imod << 9; | |
9535 | inst.instruction |= inst.operands[0].imm << 5; | |
9536 | if (inst.operands[1].present) | |
9537 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 9538 | } |
c19d1205 | 9539 | else |
90e4755a | 9540 | { |
62b3e311 PB |
9541 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
9542 | && (inst.operands[0].imm & 4), | |
9543 | _("selected processor does not support 'A' form " | |
9544 | "of this instruction")); | |
9545 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
9546 | _("Thumb does not support the 2-argument " |
9547 | "form of this instruction")); | |
9548 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 9549 | } |
90e4755a RE |
9550 | } |
9551 | ||
c19d1205 ZW |
9552 | /* THUMB CPY instruction (argument parse). */ |
9553 | ||
90e4755a | 9554 | static void |
c19d1205 | 9555 | do_t_cpy (void) |
90e4755a | 9556 | { |
c19d1205 | 9557 | if (inst.size_req == 4) |
90e4755a | 9558 | { |
c19d1205 ZW |
9559 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
9560 | inst.instruction |= inst.operands[0].reg << 8; | |
9561 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 9562 | } |
c19d1205 | 9563 | else |
90e4755a | 9564 | { |
c19d1205 ZW |
9565 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
9566 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9567 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 9568 | } |
90e4755a RE |
9569 | } |
9570 | ||
90e4755a | 9571 | static void |
25fe350b | 9572 | do_t_cbz (void) |
90e4755a | 9573 | { |
e07e6e58 | 9574 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
9575 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9576 | inst.instruction |= inst.operands[0].reg; | |
9577 | inst.reloc.pc_rel = 1; | |
9578 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
9579 | } | |
90e4755a | 9580 | |
62b3e311 PB |
9581 | static void |
9582 | do_t_dbg (void) | |
9583 | { | |
9584 | inst.instruction |= inst.operands[0].imm; | |
9585 | } | |
9586 | ||
9587 | static void | |
9588 | do_t_div (void) | |
9589 | { | |
fdfde340 JM |
9590 | unsigned Rd, Rn, Rm; |
9591 | ||
9592 | Rd = inst.operands[0].reg; | |
9593 | Rn = (inst.operands[1].present | |
9594 | ? inst.operands[1].reg : Rd); | |
9595 | Rm = inst.operands[2].reg; | |
9596 | ||
9597 | reject_bad_reg (Rd); | |
9598 | reject_bad_reg (Rn); | |
9599 | reject_bad_reg (Rm); | |
9600 | ||
9601 | inst.instruction |= Rd << 8; | |
9602 | inst.instruction |= Rn << 16; | |
9603 | inst.instruction |= Rm; | |
62b3e311 PB |
9604 | } |
9605 | ||
c19d1205 ZW |
9606 | static void |
9607 | do_t_hint (void) | |
9608 | { | |
9609 | if (unified_syntax && inst.size_req == 4) | |
9610 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9611 | else | |
9612 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9613 | } | |
90e4755a | 9614 | |
c19d1205 ZW |
9615 | static void |
9616 | do_t_it (void) | |
9617 | { | |
9618 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 9619 | |
e07e6e58 NC |
9620 | set_it_insn_type (IT_INSN); |
9621 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
9622 | now_it.cc = cond; | |
e27ec89e PB |
9623 | |
9624 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 9625 | if ((cond & 0x1) == 0x0) |
90e4755a | 9626 | { |
c19d1205 | 9627 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 9628 | |
c19d1205 ZW |
9629 | if ((mask & 0x7) == 0) |
9630 | /* no conversion needed */; | |
9631 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
9632 | mask ^= 0x8; |
9633 | else if ((mask & 0x1) == 0) | |
9634 | mask ^= 0xC; | |
c19d1205 | 9635 | else |
e27ec89e | 9636 | mask ^= 0xE; |
90e4755a | 9637 | |
e27ec89e PB |
9638 | inst.instruction &= 0xfff0; |
9639 | inst.instruction |= mask; | |
c19d1205 | 9640 | } |
90e4755a | 9641 | |
c19d1205 ZW |
9642 | inst.instruction |= cond << 4; |
9643 | } | |
90e4755a | 9644 | |
3c707909 PB |
9645 | /* Helper function used for both push/pop and ldm/stm. */ |
9646 | static void | |
9647 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
9648 | { | |
9649 | bfd_boolean load; | |
9650 | ||
9651 | load = (inst.instruction & (1 << 20)) != 0; | |
9652 | ||
9653 | if (mask & (1 << 13)) | |
9654 | inst.error = _("SP not allowed in register list"); | |
9655 | if (load) | |
9656 | { | |
e07e6e58 NC |
9657 | if (mask & (1 << 15)) |
9658 | { | |
9659 | if (mask & (1 << 14)) | |
9660 | inst.error = _("LR and PC should not both be in register list"); | |
9661 | else | |
9662 | set_it_insn_type_last (); | |
9663 | } | |
3c707909 PB |
9664 | |
9665 | if ((mask & (1 << base)) != 0 | |
9666 | && writeback) | |
9667 | as_warn (_("base register should not be in register list " | |
9668 | "when written back")); | |
9669 | } | |
9670 | else | |
9671 | { | |
9672 | if (mask & (1 << 15)) | |
9673 | inst.error = _("PC not allowed in register list"); | |
9674 | ||
9675 | if (mask & (1 << base)) | |
9676 | as_warn (_("value stored for r%d is UNPREDICTABLE"), base); | |
9677 | } | |
9678 | ||
9679 | if ((mask & (mask - 1)) == 0) | |
9680 | { | |
9681 | /* Single register transfers implemented as str/ldr. */ | |
9682 | if (writeback) | |
9683 | { | |
9684 | if (inst.instruction & (1 << 23)) | |
9685 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
9686 | else | |
9687 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
9688 | } | |
9689 | else | |
9690 | { | |
9691 | if (inst.instruction & (1 << 23)) | |
9692 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
9693 | else | |
9694 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
9695 | } | |
9696 | ||
9697 | inst.instruction |= 0xf8400000; | |
9698 | if (load) | |
9699 | inst.instruction |= 0x00100000; | |
9700 | ||
5f4273c7 | 9701 | mask = ffs (mask) - 1; |
3c707909 PB |
9702 | mask <<= 12; |
9703 | } | |
9704 | else if (writeback) | |
9705 | inst.instruction |= WRITE_BACK; | |
9706 | ||
9707 | inst.instruction |= mask; | |
9708 | inst.instruction |= base << 16; | |
9709 | } | |
9710 | ||
c19d1205 ZW |
9711 | static void |
9712 | do_t_ldmstm (void) | |
9713 | { | |
9714 | /* This really doesn't seem worth it. */ | |
9715 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9716 | _("expression too complex")); | |
9717 | constraint (inst.operands[1].writeback, | |
9718 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 9719 | |
c19d1205 ZW |
9720 | if (unified_syntax) |
9721 | { | |
3c707909 PB |
9722 | bfd_boolean narrow; |
9723 | unsigned mask; | |
9724 | ||
9725 | narrow = FALSE; | |
c19d1205 ZW |
9726 | /* See if we can use a 16-bit instruction. */ |
9727 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
9728 | && inst.size_req != 4 | |
3c707909 | 9729 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 9730 | { |
3c707909 | 9731 | mask = 1 << inst.operands[0].reg; |
90e4755a | 9732 | |
3c707909 PB |
9733 | if (inst.operands[0].reg <= 7 |
9734 | && (inst.instruction == T_MNEM_stmia | |
9735 | ? inst.operands[0].writeback | |
9736 | : (inst.operands[0].writeback | |
9737 | == !(inst.operands[1].imm & mask)))) | |
90e4755a | 9738 | { |
3c707909 PB |
9739 | if (inst.instruction == T_MNEM_stmia |
9740 | && (inst.operands[1].imm & mask) | |
9741 | && (inst.operands[1].imm & (mask - 1))) | |
c19d1205 ZW |
9742 | as_warn (_("value stored for r%d is UNPREDICTABLE"), |
9743 | inst.operands[0].reg); | |
3c707909 PB |
9744 | |
9745 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9746 | inst.instruction |= inst.operands[0].reg << 8; | |
9747 | inst.instruction |= inst.operands[1].imm; | |
9748 | narrow = TRUE; | |
90e4755a | 9749 | } |
3c707909 PB |
9750 | else if (inst.operands[0] .reg == REG_SP |
9751 | && inst.operands[0].writeback) | |
90e4755a | 9752 | { |
3c707909 PB |
9753 | inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia |
9754 | ? T_MNEM_push : T_MNEM_pop); | |
9755 | inst.instruction |= inst.operands[1].imm; | |
9756 | narrow = TRUE; | |
90e4755a | 9757 | } |
3c707909 PB |
9758 | } |
9759 | ||
9760 | if (!narrow) | |
9761 | { | |
c19d1205 ZW |
9762 | if (inst.instruction < 0xffff) |
9763 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 9764 | |
5f4273c7 NC |
9765 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
9766 | inst.operands[0].writeback); | |
90e4755a RE |
9767 | } |
9768 | } | |
c19d1205 | 9769 | else |
90e4755a | 9770 | { |
c19d1205 ZW |
9771 | constraint (inst.operands[0].reg > 7 |
9772 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
9773 | constraint (inst.instruction != T_MNEM_ldmia |
9774 | && inst.instruction != T_MNEM_stmia, | |
9775 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 9776 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 9777 | { |
c19d1205 ZW |
9778 | if (!inst.operands[0].writeback) |
9779 | as_warn (_("this instruction will write back the base register")); | |
9780 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9781 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
9782 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
9783 | inst.operands[0].reg); | |
f03698e6 | 9784 | } |
c19d1205 | 9785 | else |
90e4755a | 9786 | { |
c19d1205 ZW |
9787 | if (!inst.operands[0].writeback |
9788 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9789 | as_warn (_("this instruction will write back the base register")); | |
9790 | else if (inst.operands[0].writeback | |
9791 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9792 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
9793 | } |
9794 | ||
c19d1205 ZW |
9795 | inst.instruction = THUMB_OP16 (inst.instruction); |
9796 | inst.instruction |= inst.operands[0].reg << 8; | |
9797 | inst.instruction |= inst.operands[1].imm; | |
9798 | } | |
9799 | } | |
e28cd48c | 9800 | |
c19d1205 ZW |
9801 | static void |
9802 | do_t_ldrex (void) | |
9803 | { | |
9804 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
9805 | || inst.operands[1].postind || inst.operands[1].writeback | |
9806 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
9807 | || inst.operands[1].negative, | |
01cfc07f | 9808 | BAD_ADDR_MODE); |
e28cd48c | 9809 | |
c19d1205 ZW |
9810 | inst.instruction |= inst.operands[0].reg << 12; |
9811 | inst.instruction |= inst.operands[1].reg << 16; | |
9812 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
9813 | } | |
e28cd48c | 9814 | |
c19d1205 ZW |
9815 | static void |
9816 | do_t_ldrexd (void) | |
9817 | { | |
9818 | if (!inst.operands[1].present) | |
1cac9012 | 9819 | { |
c19d1205 ZW |
9820 | constraint (inst.operands[0].reg == REG_LR, |
9821 | _("r14 not allowed as first register " | |
9822 | "when second register is omitted")); | |
9823 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 9824 | } |
c19d1205 ZW |
9825 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
9826 | BAD_OVERLAP); | |
b99bd4ef | 9827 | |
c19d1205 ZW |
9828 | inst.instruction |= inst.operands[0].reg << 12; |
9829 | inst.instruction |= inst.operands[1].reg << 8; | |
9830 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9831 | } |
9832 | ||
9833 | static void | |
c19d1205 | 9834 | do_t_ldst (void) |
b99bd4ef | 9835 | { |
0110f2b8 PB |
9836 | unsigned long opcode; |
9837 | int Rn; | |
9838 | ||
e07e6e58 NC |
9839 | if (inst.operands[0].isreg |
9840 | && !inst.operands[0].preind | |
9841 | && inst.operands[0].reg == REG_PC) | |
9842 | set_it_insn_type_last (); | |
9843 | ||
0110f2b8 | 9844 | opcode = inst.instruction; |
c19d1205 | 9845 | if (unified_syntax) |
b99bd4ef | 9846 | { |
53365c0d PB |
9847 | if (!inst.operands[1].isreg) |
9848 | { | |
9849 | if (opcode <= 0xffff) | |
9850 | inst.instruction = THUMB_OP32 (opcode); | |
9851 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9852 | return; | |
9853 | } | |
0110f2b8 PB |
9854 | if (inst.operands[1].isreg |
9855 | && !inst.operands[1].writeback | |
c19d1205 ZW |
9856 | && !inst.operands[1].shifted && !inst.operands[1].postind |
9857 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
9858 | && opcode <= 0xffff |
9859 | && inst.size_req != 4) | |
c19d1205 | 9860 | { |
0110f2b8 PB |
9861 | /* Insn may have a 16-bit form. */ |
9862 | Rn = inst.operands[1].reg; | |
9863 | if (inst.operands[1].immisreg) | |
9864 | { | |
9865 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 9866 | /* [Rn, Rik] */ |
0110f2b8 PB |
9867 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
9868 | goto op16; | |
9869 | } | |
9870 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
9871 | && opcode != T_MNEM_ldrsb) | |
9872 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
9873 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
9874 | { | |
9875 | /* [Rn, #const] */ | |
9876 | if (Rn > 7) | |
9877 | { | |
9878 | if (Rn == REG_PC) | |
9879 | { | |
9880 | if (inst.reloc.pc_rel) | |
9881 | opcode = T_MNEM_ldr_pc2; | |
9882 | else | |
9883 | opcode = T_MNEM_ldr_pc; | |
9884 | } | |
9885 | else | |
9886 | { | |
9887 | if (opcode == T_MNEM_ldr) | |
9888 | opcode = T_MNEM_ldr_sp; | |
9889 | else | |
9890 | opcode = T_MNEM_str_sp; | |
9891 | } | |
9892 | inst.instruction = inst.operands[0].reg << 8; | |
9893 | } | |
9894 | else | |
9895 | { | |
9896 | inst.instruction = inst.operands[0].reg; | |
9897 | inst.instruction |= inst.operands[1].reg << 3; | |
9898 | } | |
9899 | inst.instruction |= THUMB_OP16 (opcode); | |
9900 | if (inst.size_req == 2) | |
9901 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9902 | else | |
9903 | inst.relax = opcode; | |
9904 | return; | |
9905 | } | |
c19d1205 | 9906 | } |
0110f2b8 PB |
9907 | /* Definitely a 32-bit variant. */ |
9908 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
9909 | inst.instruction |= inst.operands[0].reg << 12; |
9910 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
9911 | return; |
9912 | } | |
9913 | ||
c19d1205 ZW |
9914 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9915 | ||
9916 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 9917 | { |
c19d1205 ZW |
9918 | /* Only [Rn,Rm] is acceptable. */ |
9919 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
9920 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
9921 | || inst.operands[1].postind || inst.operands[1].shifted | |
9922 | || inst.operands[1].negative, | |
9923 | _("Thumb does not support this addressing mode")); | |
9924 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9925 | goto op16; | |
b99bd4ef | 9926 | } |
5f4273c7 | 9927 | |
c19d1205 ZW |
9928 | inst.instruction = THUMB_OP16 (inst.instruction); |
9929 | if (!inst.operands[1].isreg) | |
9930 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9931 | return; | |
b99bd4ef | 9932 | |
c19d1205 ZW |
9933 | constraint (!inst.operands[1].preind |
9934 | || inst.operands[1].shifted | |
9935 | || inst.operands[1].writeback, | |
9936 | _("Thumb does not support this addressing mode")); | |
9937 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 9938 | { |
c19d1205 ZW |
9939 | constraint (inst.instruction & 0x0600, |
9940 | _("byte or halfword not valid for base register")); | |
9941 | constraint (inst.operands[1].reg == REG_PC | |
9942 | && !(inst.instruction & THUMB_LOAD_BIT), | |
9943 | _("r15 based store not allowed")); | |
9944 | constraint (inst.operands[1].immisreg, | |
9945 | _("invalid base register for register offset")); | |
b99bd4ef | 9946 | |
c19d1205 ZW |
9947 | if (inst.operands[1].reg == REG_PC) |
9948 | inst.instruction = T_OPCODE_LDR_PC; | |
9949 | else if (inst.instruction & THUMB_LOAD_BIT) | |
9950 | inst.instruction = T_OPCODE_LDR_SP; | |
9951 | else | |
9952 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 9953 | |
c19d1205 ZW |
9954 | inst.instruction |= inst.operands[0].reg << 8; |
9955 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9956 | return; | |
9957 | } | |
90e4755a | 9958 | |
c19d1205 ZW |
9959 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
9960 | if (!inst.operands[1].immisreg) | |
9961 | { | |
9962 | /* Immediate offset. */ | |
9963 | inst.instruction |= inst.operands[0].reg; | |
9964 | inst.instruction |= inst.operands[1].reg << 3; | |
9965 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9966 | return; | |
9967 | } | |
90e4755a | 9968 | |
c19d1205 ZW |
9969 | /* Register offset. */ |
9970 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
9971 | constraint (inst.operands[1].negative, | |
9972 | _("Thumb does not support this addressing mode")); | |
90e4755a | 9973 | |
c19d1205 ZW |
9974 | op16: |
9975 | switch (inst.instruction) | |
9976 | { | |
9977 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
9978 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
9979 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
9980 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
9981 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
9982 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
9983 | case 0x5600 /* ldrsb */: | |
9984 | case 0x5e00 /* ldrsh */: break; | |
9985 | default: abort (); | |
9986 | } | |
90e4755a | 9987 | |
c19d1205 ZW |
9988 | inst.instruction |= inst.operands[0].reg; |
9989 | inst.instruction |= inst.operands[1].reg << 3; | |
9990 | inst.instruction |= inst.operands[1].imm << 6; | |
9991 | } | |
90e4755a | 9992 | |
c19d1205 ZW |
9993 | static void |
9994 | do_t_ldstd (void) | |
9995 | { | |
9996 | if (!inst.operands[1].present) | |
b99bd4ef | 9997 | { |
c19d1205 ZW |
9998 | inst.operands[1].reg = inst.operands[0].reg + 1; |
9999 | constraint (inst.operands[0].reg == REG_LR, | |
10000 | _("r14 not allowed here")); | |
b99bd4ef | 10001 | } |
c19d1205 ZW |
10002 | inst.instruction |= inst.operands[0].reg << 12; |
10003 | inst.instruction |= inst.operands[1].reg << 8; | |
10004 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
10005 | } |
10006 | ||
c19d1205 ZW |
10007 | static void |
10008 | do_t_ldstt (void) | |
10009 | { | |
10010 | inst.instruction |= inst.operands[0].reg << 12; | |
10011 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
10012 | } | |
a737bd4d | 10013 | |
b99bd4ef | 10014 | static void |
c19d1205 | 10015 | do_t_mla (void) |
b99bd4ef | 10016 | { |
fdfde340 | 10017 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 10018 | |
fdfde340 JM |
10019 | Rd = inst.operands[0].reg; |
10020 | Rn = inst.operands[1].reg; | |
10021 | Rm = inst.operands[2].reg; | |
10022 | Ra = inst.operands[3].reg; | |
10023 | ||
10024 | reject_bad_reg (Rd); | |
10025 | reject_bad_reg (Rn); | |
10026 | reject_bad_reg (Rm); | |
10027 | reject_bad_reg (Ra); | |
10028 | ||
10029 | inst.instruction |= Rd << 8; | |
10030 | inst.instruction |= Rn << 16; | |
10031 | inst.instruction |= Rm; | |
10032 | inst.instruction |= Ra << 12; | |
c19d1205 | 10033 | } |
b99bd4ef | 10034 | |
c19d1205 ZW |
10035 | static void |
10036 | do_t_mlal (void) | |
10037 | { | |
fdfde340 JM |
10038 | unsigned RdLo, RdHi, Rn, Rm; |
10039 | ||
10040 | RdLo = inst.operands[0].reg; | |
10041 | RdHi = inst.operands[1].reg; | |
10042 | Rn = inst.operands[2].reg; | |
10043 | Rm = inst.operands[3].reg; | |
10044 | ||
10045 | reject_bad_reg (RdLo); | |
10046 | reject_bad_reg (RdHi); | |
10047 | reject_bad_reg (Rn); | |
10048 | reject_bad_reg (Rm); | |
10049 | ||
10050 | inst.instruction |= RdLo << 12; | |
10051 | inst.instruction |= RdHi << 8; | |
10052 | inst.instruction |= Rn << 16; | |
10053 | inst.instruction |= Rm; | |
c19d1205 | 10054 | } |
b99bd4ef | 10055 | |
c19d1205 ZW |
10056 | static void |
10057 | do_t_mov_cmp (void) | |
10058 | { | |
fdfde340 JM |
10059 | unsigned Rn, Rm; |
10060 | ||
10061 | Rn = inst.operands[0].reg; | |
10062 | Rm = inst.operands[1].reg; | |
10063 | ||
e07e6e58 NC |
10064 | if (Rn == REG_PC) |
10065 | set_it_insn_type_last (); | |
10066 | ||
c19d1205 | 10067 | if (unified_syntax) |
b99bd4ef | 10068 | { |
c19d1205 ZW |
10069 | int r0off = (inst.instruction == T_MNEM_mov |
10070 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 10071 | unsigned long opcode; |
3d388997 PB |
10072 | bfd_boolean narrow; |
10073 | bfd_boolean low_regs; | |
10074 | ||
fdfde340 | 10075 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 10076 | opcode = inst.instruction; |
e07e6e58 | 10077 | if (in_it_block ()) |
0110f2b8 | 10078 | narrow = opcode != T_MNEM_movs; |
3d388997 | 10079 | else |
0110f2b8 | 10080 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
10081 | if (inst.size_req == 4 |
10082 | || inst.operands[1].shifted) | |
10083 | narrow = FALSE; | |
10084 | ||
efd81785 PB |
10085 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
10086 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
10087 | && !inst.operands[1].shifted | |
fdfde340 JM |
10088 | && Rn == REG_PC |
10089 | && Rm == REG_LR) | |
efd81785 PB |
10090 | { |
10091 | inst.instruction = T2_SUBS_PC_LR; | |
10092 | return; | |
10093 | } | |
10094 | ||
fdfde340 JM |
10095 | if (opcode == T_MNEM_cmp) |
10096 | { | |
10097 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
10098 | if (narrow) |
10099 | { | |
10100 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
10101 | but valid. */ | |
10102 | warn_deprecated_sp (Rm); | |
10103 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
10104 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
10105 | tools reject R15, so we do too. */ | |
10106 | constraint (Rm == REG_PC, BAD_PC); | |
10107 | } | |
10108 | else | |
10109 | reject_bad_reg (Rm); | |
fdfde340 JM |
10110 | } |
10111 | else if (opcode == T_MNEM_mov | |
10112 | || opcode == T_MNEM_movs) | |
10113 | { | |
10114 | if (inst.operands[1].isreg) | |
10115 | { | |
10116 | if (opcode == T_MNEM_movs) | |
10117 | { | |
10118 | reject_bad_reg (Rn); | |
10119 | reject_bad_reg (Rm); | |
10120 | } | |
10121 | else if ((Rn == REG_SP || Rn == REG_PC) | |
10122 | && (Rm == REG_SP || Rm == REG_PC)) | |
10123 | reject_bad_reg (Rm); | |
10124 | } | |
10125 | else | |
10126 | reject_bad_reg (Rn); | |
10127 | } | |
10128 | ||
c19d1205 ZW |
10129 | if (!inst.operands[1].isreg) |
10130 | { | |
0110f2b8 | 10131 | /* Immediate operand. */ |
e07e6e58 | 10132 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
10133 | narrow = 0; |
10134 | if (low_regs && narrow) | |
10135 | { | |
10136 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 10137 | inst.instruction |= Rn << 8; |
0110f2b8 PB |
10138 | if (inst.size_req == 2) |
10139 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
10140 | else | |
10141 | inst.relax = opcode; | |
10142 | } | |
10143 | else | |
10144 | { | |
10145 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10146 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10147 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
10148 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
10149 | } | |
c19d1205 | 10150 | } |
728ca7c9 PB |
10151 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
10152 | && (inst.instruction == T_MNEM_mov | |
10153 | || inst.instruction == T_MNEM_movs)) | |
10154 | { | |
10155 | /* Register shifts are encoded as separate shift instructions. */ | |
10156 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
10157 | ||
e07e6e58 | 10158 | if (in_it_block ()) |
728ca7c9 PB |
10159 | narrow = !flags; |
10160 | else | |
10161 | narrow = flags; | |
10162 | ||
10163 | if (inst.size_req == 4) | |
10164 | narrow = FALSE; | |
10165 | ||
10166 | if (!low_regs || inst.operands[1].imm > 7) | |
10167 | narrow = FALSE; | |
10168 | ||
fdfde340 | 10169 | if (Rn != Rm) |
728ca7c9 PB |
10170 | narrow = FALSE; |
10171 | ||
10172 | switch (inst.operands[1].shift_kind) | |
10173 | { | |
10174 | case SHIFT_LSL: | |
10175 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
10176 | break; | |
10177 | case SHIFT_ASR: | |
10178 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
10179 | break; | |
10180 | case SHIFT_LSR: | |
10181 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
10182 | break; | |
10183 | case SHIFT_ROR: | |
10184 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
10185 | break; | |
10186 | default: | |
5f4273c7 | 10187 | abort (); |
728ca7c9 PB |
10188 | } |
10189 | ||
10190 | inst.instruction = opcode; | |
10191 | if (narrow) | |
10192 | { | |
fdfde340 | 10193 | inst.instruction |= Rn; |
728ca7c9 PB |
10194 | inst.instruction |= inst.operands[1].imm << 3; |
10195 | } | |
10196 | else | |
10197 | { | |
10198 | if (flags) | |
10199 | inst.instruction |= CONDS_BIT; | |
10200 | ||
fdfde340 JM |
10201 | inst.instruction |= Rn << 8; |
10202 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
10203 | inst.instruction |= inst.operands[1].imm; |
10204 | } | |
10205 | } | |
3d388997 | 10206 | else if (!narrow) |
c19d1205 | 10207 | { |
728ca7c9 PB |
10208 | /* Some mov with immediate shift have narrow variants. |
10209 | Register shifts are handled above. */ | |
10210 | if (low_regs && inst.operands[1].shifted | |
10211 | && (inst.instruction == T_MNEM_mov | |
10212 | || inst.instruction == T_MNEM_movs)) | |
10213 | { | |
e07e6e58 | 10214 | if (in_it_block ()) |
728ca7c9 PB |
10215 | narrow = (inst.instruction == T_MNEM_mov); |
10216 | else | |
10217 | narrow = (inst.instruction == T_MNEM_movs); | |
10218 | } | |
10219 | ||
10220 | if (narrow) | |
10221 | { | |
10222 | switch (inst.operands[1].shift_kind) | |
10223 | { | |
10224 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10225 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
10226 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
10227 | default: narrow = FALSE; break; | |
10228 | } | |
10229 | } | |
10230 | ||
10231 | if (narrow) | |
10232 | { | |
fdfde340 JM |
10233 | inst.instruction |= Rn; |
10234 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
10235 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10236 | } | |
10237 | else | |
10238 | { | |
10239 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10240 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
10241 | encode_thumb32_shifted_operand (1); |
10242 | } | |
c19d1205 ZW |
10243 | } |
10244 | else | |
10245 | switch (inst.instruction) | |
10246 | { | |
10247 | case T_MNEM_mov: | |
10248 | inst.instruction = T_OPCODE_MOV_HR; | |
fdfde340 JM |
10249 | inst.instruction |= (Rn & 0x8) << 4; |
10250 | inst.instruction |= (Rn & 0x7); | |
10251 | inst.instruction |= Rm << 3; | |
c19d1205 | 10252 | break; |
b99bd4ef | 10253 | |
c19d1205 ZW |
10254 | case T_MNEM_movs: |
10255 | /* We know we have low registers at this point. | |
10256 | Generate ADD Rd, Rs, #0. */ | |
10257 | inst.instruction = T_OPCODE_ADD_I3; | |
fdfde340 JM |
10258 | inst.instruction |= Rn; |
10259 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10260 | break; |
10261 | ||
10262 | case T_MNEM_cmp: | |
3d388997 | 10263 | if (low_regs) |
c19d1205 ZW |
10264 | { |
10265 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
10266 | inst.instruction |= Rn; |
10267 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10268 | } |
10269 | else | |
10270 | { | |
10271 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
10272 | inst.instruction |= (Rn & 0x8) << 4; |
10273 | inst.instruction |= (Rn & 0x7); | |
10274 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10275 | } |
10276 | break; | |
10277 | } | |
b99bd4ef NC |
10278 | return; |
10279 | } | |
10280 | ||
c19d1205 | 10281 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
10282 | |
10283 | /* PR 10443: Do not silently ignore shifted operands. */ | |
10284 | constraint (inst.operands[1].shifted, | |
10285 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
10286 | ||
c19d1205 | 10287 | if (inst.operands[1].isreg) |
b99bd4ef | 10288 | { |
fdfde340 | 10289 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 10290 | { |
c19d1205 ZW |
10291 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
10292 | since a MOV instruction produces unpredictable results. */ | |
10293 | if (inst.instruction == T_OPCODE_MOV_I8) | |
10294 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 10295 | else |
c19d1205 | 10296 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 10297 | |
fdfde340 JM |
10298 | inst.instruction |= Rn; |
10299 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
10300 | } |
10301 | else | |
10302 | { | |
c19d1205 ZW |
10303 | if (inst.instruction == T_OPCODE_MOV_I8) |
10304 | inst.instruction = T_OPCODE_MOV_HR; | |
10305 | else | |
10306 | inst.instruction = T_OPCODE_CMP_HR; | |
10307 | do_t_cpy (); | |
b99bd4ef NC |
10308 | } |
10309 | } | |
c19d1205 | 10310 | else |
b99bd4ef | 10311 | { |
fdfde340 | 10312 | constraint (Rn > 7, |
c19d1205 | 10313 | _("only lo regs allowed with immediate")); |
fdfde340 | 10314 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
10315 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
10316 | } | |
10317 | } | |
b99bd4ef | 10318 | |
c19d1205 ZW |
10319 | static void |
10320 | do_t_mov16 (void) | |
10321 | { | |
fdfde340 | 10322 | unsigned Rd; |
b6895b4f PB |
10323 | bfd_vma imm; |
10324 | bfd_boolean top; | |
10325 | ||
10326 | top = (inst.instruction & 0x00800000) != 0; | |
10327 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
10328 | { | |
10329 | constraint (top, _(":lower16: not allowed this instruction")); | |
10330 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
10331 | } | |
10332 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
10333 | { | |
10334 | constraint (!top, _(":upper16: not allowed this instruction")); | |
10335 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
10336 | } | |
10337 | ||
fdfde340 JM |
10338 | Rd = inst.operands[0].reg; |
10339 | reject_bad_reg (Rd); | |
10340 | ||
10341 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
10342 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
10343 | { | |
10344 | imm = inst.reloc.exp.X_add_number; | |
10345 | inst.instruction |= (imm & 0xf000) << 4; | |
10346 | inst.instruction |= (imm & 0x0800) << 15; | |
10347 | inst.instruction |= (imm & 0x0700) << 4; | |
10348 | inst.instruction |= (imm & 0x00ff); | |
10349 | } | |
c19d1205 | 10350 | } |
b99bd4ef | 10351 | |
c19d1205 ZW |
10352 | static void |
10353 | do_t_mvn_tst (void) | |
10354 | { | |
fdfde340 | 10355 | unsigned Rn, Rm; |
c921be7d | 10356 | |
fdfde340 JM |
10357 | Rn = inst.operands[0].reg; |
10358 | Rm = inst.operands[1].reg; | |
10359 | ||
10360 | if (inst.instruction == T_MNEM_cmp | |
10361 | || inst.instruction == T_MNEM_cmn) | |
10362 | constraint (Rn == REG_PC, BAD_PC); | |
10363 | else | |
10364 | reject_bad_reg (Rn); | |
10365 | reject_bad_reg (Rm); | |
10366 | ||
c19d1205 ZW |
10367 | if (unified_syntax) |
10368 | { | |
10369 | int r0off = (inst.instruction == T_MNEM_mvn | |
10370 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
10371 | bfd_boolean narrow; |
10372 | ||
10373 | if (inst.size_req == 4 | |
10374 | || inst.instruction > 0xffff | |
10375 | || inst.operands[1].shifted | |
fdfde340 | 10376 | || Rn > 7 || Rm > 7) |
3d388997 PB |
10377 | narrow = FALSE; |
10378 | else if (inst.instruction == T_MNEM_cmn) | |
10379 | narrow = TRUE; | |
10380 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10381 | narrow = !in_it_block (); |
3d388997 | 10382 | else |
e07e6e58 | 10383 | narrow = in_it_block (); |
3d388997 | 10384 | |
c19d1205 | 10385 | if (!inst.operands[1].isreg) |
b99bd4ef | 10386 | { |
c19d1205 ZW |
10387 | /* For an immediate, we always generate a 32-bit opcode; |
10388 | section relaxation will shrink it later if possible. */ | |
10389 | if (inst.instruction < 0xffff) | |
10390 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10391 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10392 | inst.instruction |= Rn << r0off; |
c19d1205 | 10393 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 10394 | } |
c19d1205 | 10395 | else |
b99bd4ef | 10396 | { |
c19d1205 | 10397 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 10398 | if (narrow) |
b99bd4ef | 10399 | { |
c19d1205 | 10400 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10401 | inst.instruction |= Rn; |
10402 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10403 | } |
c19d1205 | 10404 | else |
b99bd4ef | 10405 | { |
c19d1205 ZW |
10406 | constraint (inst.operands[1].shifted |
10407 | && inst.operands[1].immisreg, | |
10408 | _("shift must be constant")); | |
10409 | if (inst.instruction < 0xffff) | |
10410 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10411 | inst.instruction |= Rn << r0off; |
c19d1205 | 10412 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 10413 | } |
b99bd4ef NC |
10414 | } |
10415 | } | |
10416 | else | |
10417 | { | |
c19d1205 ZW |
10418 | constraint (inst.instruction > 0xffff |
10419 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
10420 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
10421 | _("unshifted register required")); | |
fdfde340 | 10422 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10423 | BAD_HIREG); |
b99bd4ef | 10424 | |
c19d1205 | 10425 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10426 | inst.instruction |= Rn; |
10427 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10428 | } |
b99bd4ef NC |
10429 | } |
10430 | ||
b05fe5cf | 10431 | static void |
c19d1205 | 10432 | do_t_mrs (void) |
b05fe5cf | 10433 | { |
fdfde340 | 10434 | unsigned Rd; |
62b3e311 | 10435 | int flags; |
037e8744 JB |
10436 | |
10437 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
10438 | return; | |
10439 | ||
62b3e311 PB |
10440 | flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
10441 | if (flags == 0) | |
10442 | { | |
7e806470 | 10443 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10444 | _("selected processor does not support " |
10445 | "requested special purpose register")); | |
10446 | } | |
10447 | else | |
10448 | { | |
10449 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10450 | _("selected processor does not support " | |
44bf2362 | 10451 | "requested special purpose register")); |
62b3e311 PB |
10452 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
10453 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
10454 | _("'CPSR' or 'SPSR' expected")); | |
10455 | } | |
5f4273c7 | 10456 | |
fdfde340 JM |
10457 | Rd = inst.operands[0].reg; |
10458 | reject_bad_reg (Rd); | |
10459 | ||
10460 | inst.instruction |= Rd << 8; | |
62b3e311 PB |
10461 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10462 | inst.instruction |= inst.operands[1].imm & 0xff; | |
c19d1205 | 10463 | } |
b05fe5cf | 10464 | |
c19d1205 ZW |
10465 | static void |
10466 | do_t_msr (void) | |
10467 | { | |
62b3e311 | 10468 | int flags; |
fdfde340 | 10469 | unsigned Rn; |
62b3e311 | 10470 | |
037e8744 JB |
10471 | if (do_vfp_nsyn_msr () == SUCCESS) |
10472 | return; | |
10473 | ||
c19d1205 ZW |
10474 | constraint (!inst.operands[1].isreg, |
10475 | _("Thumb encoding does not support an immediate here")); | |
62b3e311 PB |
10476 | flags = inst.operands[0].imm; |
10477 | if (flags & ~0xff) | |
10478 | { | |
10479 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10480 | _("selected processor does not support " | |
10481 | "requested special purpose register")); | |
10482 | } | |
10483 | else | |
10484 | { | |
7e806470 | 10485 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10486 | _("selected processor does not support " |
10487 | "requested special purpose register")); | |
10488 | flags |= PSR_f; | |
10489 | } | |
c921be7d | 10490 | |
fdfde340 JM |
10491 | Rn = inst.operands[1].reg; |
10492 | reject_bad_reg (Rn); | |
10493 | ||
62b3e311 PB |
10494 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10495 | inst.instruction |= (flags & ~SPSR_BIT) >> 8; | |
10496 | inst.instruction |= (flags & 0xff); | |
fdfde340 | 10497 | inst.instruction |= Rn << 16; |
c19d1205 | 10498 | } |
b05fe5cf | 10499 | |
c19d1205 ZW |
10500 | static void |
10501 | do_t_mul (void) | |
10502 | { | |
17828f45 | 10503 | bfd_boolean narrow; |
fdfde340 | 10504 | unsigned Rd, Rn, Rm; |
17828f45 | 10505 | |
c19d1205 ZW |
10506 | if (!inst.operands[2].present) |
10507 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 10508 | |
fdfde340 JM |
10509 | Rd = inst.operands[0].reg; |
10510 | Rn = inst.operands[1].reg; | |
10511 | Rm = inst.operands[2].reg; | |
10512 | ||
17828f45 | 10513 | if (unified_syntax) |
b05fe5cf | 10514 | { |
17828f45 | 10515 | if (inst.size_req == 4 |
fdfde340 JM |
10516 | || (Rd != Rn |
10517 | && Rd != Rm) | |
10518 | || Rn > 7 | |
10519 | || Rm > 7) | |
17828f45 JM |
10520 | narrow = FALSE; |
10521 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 10522 | narrow = !in_it_block (); |
17828f45 | 10523 | else |
e07e6e58 | 10524 | narrow = in_it_block (); |
b05fe5cf | 10525 | } |
c19d1205 | 10526 | else |
b05fe5cf | 10527 | { |
17828f45 | 10528 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 10529 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10530 | BAD_HIREG); |
17828f45 JM |
10531 | narrow = TRUE; |
10532 | } | |
b05fe5cf | 10533 | |
17828f45 JM |
10534 | if (narrow) |
10535 | { | |
10536 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 10537 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 10538 | inst.instruction |= Rd; |
b05fe5cf | 10539 | |
fdfde340 JM |
10540 | if (Rd == Rn) |
10541 | inst.instruction |= Rm << 3; | |
10542 | else if (Rd == Rm) | |
10543 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
10544 | else |
10545 | constraint (1, _("dest must overlap one source register")); | |
10546 | } | |
17828f45 JM |
10547 | else |
10548 | { | |
e07e6e58 NC |
10549 | constraint (inst.instruction != T_MNEM_mul, |
10550 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
10551 | /* 32-bit MUL. */ |
10552 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10553 | inst.instruction |= Rd << 8; |
10554 | inst.instruction |= Rn << 16; | |
10555 | inst.instruction |= Rm << 0; | |
10556 | ||
10557 | reject_bad_reg (Rd); | |
10558 | reject_bad_reg (Rn); | |
10559 | reject_bad_reg (Rm); | |
17828f45 | 10560 | } |
c19d1205 | 10561 | } |
b05fe5cf | 10562 | |
c19d1205 ZW |
10563 | static void |
10564 | do_t_mull (void) | |
10565 | { | |
fdfde340 | 10566 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 10567 | |
fdfde340 JM |
10568 | RdLo = inst.operands[0].reg; |
10569 | RdHi = inst.operands[1].reg; | |
10570 | Rn = inst.operands[2].reg; | |
10571 | Rm = inst.operands[3].reg; | |
10572 | ||
10573 | reject_bad_reg (RdLo); | |
10574 | reject_bad_reg (RdHi); | |
10575 | reject_bad_reg (Rn); | |
10576 | reject_bad_reg (Rm); | |
10577 | ||
10578 | inst.instruction |= RdLo << 12; | |
10579 | inst.instruction |= RdHi << 8; | |
10580 | inst.instruction |= Rn << 16; | |
10581 | inst.instruction |= Rm; | |
10582 | ||
10583 | if (RdLo == RdHi) | |
c19d1205 ZW |
10584 | as_tsktsk (_("rdhi and rdlo must be different")); |
10585 | } | |
b05fe5cf | 10586 | |
c19d1205 ZW |
10587 | static void |
10588 | do_t_nop (void) | |
10589 | { | |
e07e6e58 NC |
10590 | set_it_insn_type (NEUTRAL_IT_INSN); |
10591 | ||
c19d1205 ZW |
10592 | if (unified_syntax) |
10593 | { | |
10594 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 10595 | { |
c19d1205 ZW |
10596 | inst.instruction = THUMB_OP32 (inst.instruction); |
10597 | inst.instruction |= inst.operands[0].imm; | |
10598 | } | |
10599 | else | |
10600 | { | |
bc2d1808 NC |
10601 | /* PR9722: Check for Thumb2 availability before |
10602 | generating a thumb2 nop instruction. */ | |
10603 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
10604 | { | |
10605 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10606 | inst.instruction |= inst.operands[0].imm << 4; | |
10607 | } | |
10608 | else | |
10609 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
10610 | } |
10611 | } | |
10612 | else | |
10613 | { | |
10614 | constraint (inst.operands[0].present, | |
10615 | _("Thumb does not support NOP with hints")); | |
10616 | inst.instruction = 0x46c0; | |
10617 | } | |
10618 | } | |
b05fe5cf | 10619 | |
c19d1205 ZW |
10620 | static void |
10621 | do_t_neg (void) | |
10622 | { | |
10623 | if (unified_syntax) | |
10624 | { | |
3d388997 PB |
10625 | bfd_boolean narrow; |
10626 | ||
10627 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10628 | narrow = !in_it_block (); |
3d388997 | 10629 | else |
e07e6e58 | 10630 | narrow = in_it_block (); |
3d388997 PB |
10631 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10632 | narrow = FALSE; | |
10633 | if (inst.size_req == 4) | |
10634 | narrow = FALSE; | |
10635 | ||
10636 | if (!narrow) | |
c19d1205 ZW |
10637 | { |
10638 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10639 | inst.instruction |= inst.operands[0].reg << 8; | |
10640 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
10641 | } |
10642 | else | |
10643 | { | |
c19d1205 ZW |
10644 | inst.instruction = THUMB_OP16 (inst.instruction); |
10645 | inst.instruction |= inst.operands[0].reg; | |
10646 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
10647 | } |
10648 | } | |
10649 | else | |
10650 | { | |
c19d1205 ZW |
10651 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
10652 | BAD_HIREG); | |
10653 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
10654 | ||
10655 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10656 | inst.instruction |= inst.operands[0].reg; | |
10657 | inst.instruction |= inst.operands[1].reg << 3; | |
10658 | } | |
10659 | } | |
10660 | ||
1c444d06 JM |
10661 | static void |
10662 | do_t_orn (void) | |
10663 | { | |
10664 | unsigned Rd, Rn; | |
10665 | ||
10666 | Rd = inst.operands[0].reg; | |
10667 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
10668 | ||
fdfde340 JM |
10669 | reject_bad_reg (Rd); |
10670 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
10671 | reject_bad_reg (Rn); | |
10672 | ||
1c444d06 JM |
10673 | inst.instruction |= Rd << 8; |
10674 | inst.instruction |= Rn << 16; | |
10675 | ||
10676 | if (!inst.operands[2].isreg) | |
10677 | { | |
10678 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10679 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10680 | } | |
10681 | else | |
10682 | { | |
10683 | unsigned Rm; | |
10684 | ||
10685 | Rm = inst.operands[2].reg; | |
fdfde340 | 10686 | reject_bad_reg (Rm); |
1c444d06 JM |
10687 | |
10688 | constraint (inst.operands[2].shifted | |
10689 | && inst.operands[2].immisreg, | |
10690 | _("shift must be constant")); | |
10691 | encode_thumb32_shifted_operand (2); | |
10692 | } | |
10693 | } | |
10694 | ||
c19d1205 ZW |
10695 | static void |
10696 | do_t_pkhbt (void) | |
10697 | { | |
fdfde340 JM |
10698 | unsigned Rd, Rn, Rm; |
10699 | ||
10700 | Rd = inst.operands[0].reg; | |
10701 | Rn = inst.operands[1].reg; | |
10702 | Rm = inst.operands[2].reg; | |
10703 | ||
10704 | reject_bad_reg (Rd); | |
10705 | reject_bad_reg (Rn); | |
10706 | reject_bad_reg (Rm); | |
10707 | ||
10708 | inst.instruction |= Rd << 8; | |
10709 | inst.instruction |= Rn << 16; | |
10710 | inst.instruction |= Rm; | |
c19d1205 ZW |
10711 | if (inst.operands[3].present) |
10712 | { | |
10713 | unsigned int val = inst.reloc.exp.X_add_number; | |
10714 | constraint (inst.reloc.exp.X_op != O_constant, | |
10715 | _("expression too complex")); | |
10716 | inst.instruction |= (val & 0x1c) << 10; | |
10717 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 10718 | } |
c19d1205 | 10719 | } |
b05fe5cf | 10720 | |
c19d1205 ZW |
10721 | static void |
10722 | do_t_pkhtb (void) | |
10723 | { | |
10724 | if (!inst.operands[3].present) | |
1ef52f49 NC |
10725 | { |
10726 | unsigned Rtmp; | |
10727 | ||
10728 | inst.instruction &= ~0x00000020; | |
10729 | ||
10730 | /* PR 10168. Swap the Rm and Rn registers. */ | |
10731 | Rtmp = inst.operands[1].reg; | |
10732 | inst.operands[1].reg = inst.operands[2].reg; | |
10733 | inst.operands[2].reg = Rtmp; | |
10734 | } | |
c19d1205 | 10735 | do_t_pkhbt (); |
b05fe5cf ZW |
10736 | } |
10737 | ||
c19d1205 ZW |
10738 | static void |
10739 | do_t_pld (void) | |
10740 | { | |
fdfde340 JM |
10741 | if (inst.operands[0].immisreg) |
10742 | reject_bad_reg (inst.operands[0].imm); | |
10743 | ||
c19d1205 ZW |
10744 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
10745 | } | |
b05fe5cf | 10746 | |
c19d1205 ZW |
10747 | static void |
10748 | do_t_push_pop (void) | |
b99bd4ef | 10749 | { |
e9f89963 | 10750 | unsigned mask; |
5f4273c7 | 10751 | |
c19d1205 ZW |
10752 | constraint (inst.operands[0].writeback, |
10753 | _("push/pop do not support {reglist}^")); | |
10754 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
10755 | _("expression too complex")); | |
b99bd4ef | 10756 | |
e9f89963 PB |
10757 | mask = inst.operands[0].imm; |
10758 | if ((mask & ~0xff) == 0) | |
3c707909 | 10759 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
c19d1205 | 10760 | else if ((inst.instruction == T_MNEM_push |
e9f89963 | 10761 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 10762 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 10763 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 10764 | { |
c19d1205 ZW |
10765 | inst.instruction = THUMB_OP16 (inst.instruction); |
10766 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 10767 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
10768 | } |
10769 | else if (unified_syntax) | |
10770 | { | |
3c707909 | 10771 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 10772 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
10773 | } |
10774 | else | |
10775 | { | |
10776 | inst.error = _("invalid register list to push/pop instruction"); | |
10777 | return; | |
10778 | } | |
c19d1205 | 10779 | } |
b99bd4ef | 10780 | |
c19d1205 ZW |
10781 | static void |
10782 | do_t_rbit (void) | |
10783 | { | |
fdfde340 JM |
10784 | unsigned Rd, Rm; |
10785 | ||
10786 | Rd = inst.operands[0].reg; | |
10787 | Rm = inst.operands[1].reg; | |
10788 | ||
10789 | reject_bad_reg (Rd); | |
10790 | reject_bad_reg (Rm); | |
10791 | ||
10792 | inst.instruction |= Rd << 8; | |
10793 | inst.instruction |= Rm << 16; | |
10794 | inst.instruction |= Rm; | |
c19d1205 | 10795 | } |
b99bd4ef | 10796 | |
c19d1205 ZW |
10797 | static void |
10798 | do_t_rev (void) | |
10799 | { | |
fdfde340 JM |
10800 | unsigned Rd, Rm; |
10801 | ||
10802 | Rd = inst.operands[0].reg; | |
10803 | Rm = inst.operands[1].reg; | |
10804 | ||
10805 | reject_bad_reg (Rd); | |
10806 | reject_bad_reg (Rm); | |
10807 | ||
10808 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
10809 | && inst.size_req != 4) |
10810 | { | |
10811 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
10812 | inst.instruction |= Rd; |
10813 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10814 | } |
10815 | else if (unified_syntax) | |
10816 | { | |
10817 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10818 | inst.instruction |= Rd << 8; |
10819 | inst.instruction |= Rm << 16; | |
10820 | inst.instruction |= Rm; | |
c19d1205 ZW |
10821 | } |
10822 | else | |
10823 | inst.error = BAD_HIREG; | |
10824 | } | |
b99bd4ef | 10825 | |
1c444d06 JM |
10826 | static void |
10827 | do_t_rrx (void) | |
10828 | { | |
10829 | unsigned Rd, Rm; | |
10830 | ||
10831 | Rd = inst.operands[0].reg; | |
10832 | Rm = inst.operands[1].reg; | |
10833 | ||
fdfde340 JM |
10834 | reject_bad_reg (Rd); |
10835 | reject_bad_reg (Rm); | |
c921be7d | 10836 | |
1c444d06 JM |
10837 | inst.instruction |= Rd << 8; |
10838 | inst.instruction |= Rm; | |
10839 | } | |
10840 | ||
c19d1205 ZW |
10841 | static void |
10842 | do_t_rsb (void) | |
10843 | { | |
fdfde340 | 10844 | unsigned Rd, Rs; |
b99bd4ef | 10845 | |
c19d1205 ZW |
10846 | Rd = inst.operands[0].reg; |
10847 | Rs = (inst.operands[1].present | |
10848 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10849 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 10850 | |
fdfde340 JM |
10851 | reject_bad_reg (Rd); |
10852 | reject_bad_reg (Rs); | |
10853 | if (inst.operands[2].isreg) | |
10854 | reject_bad_reg (inst.operands[2].reg); | |
10855 | ||
c19d1205 ZW |
10856 | inst.instruction |= Rd << 8; |
10857 | inst.instruction |= Rs << 16; | |
10858 | if (!inst.operands[2].isreg) | |
10859 | { | |
026d3abb PB |
10860 | bfd_boolean narrow; |
10861 | ||
10862 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 10863 | narrow = !in_it_block (); |
026d3abb | 10864 | else |
e07e6e58 | 10865 | narrow = in_it_block (); |
026d3abb PB |
10866 | |
10867 | if (Rd > 7 || Rs > 7) | |
10868 | narrow = FALSE; | |
10869 | ||
10870 | if (inst.size_req == 4 || !unified_syntax) | |
10871 | narrow = FALSE; | |
10872 | ||
10873 | if (inst.reloc.exp.X_op != O_constant | |
10874 | || inst.reloc.exp.X_add_number != 0) | |
10875 | narrow = FALSE; | |
10876 | ||
10877 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
10878 | relaxation, but it doesn't seem worth the hassle. */ | |
10879 | if (narrow) | |
10880 | { | |
10881 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10882 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
10883 | inst.instruction |= Rs << 3; | |
10884 | inst.instruction |= Rd; | |
10885 | } | |
10886 | else | |
10887 | { | |
10888 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10889 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10890 | } | |
c19d1205 ZW |
10891 | } |
10892 | else | |
10893 | encode_thumb32_shifted_operand (2); | |
10894 | } | |
b99bd4ef | 10895 | |
c19d1205 ZW |
10896 | static void |
10897 | do_t_setend (void) | |
10898 | { | |
e07e6e58 | 10899 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
10900 | if (inst.operands[0].imm) |
10901 | inst.instruction |= 0x8; | |
10902 | } | |
b99bd4ef | 10903 | |
c19d1205 ZW |
10904 | static void |
10905 | do_t_shift (void) | |
10906 | { | |
10907 | if (!inst.operands[1].present) | |
10908 | inst.operands[1].reg = inst.operands[0].reg; | |
10909 | ||
10910 | if (unified_syntax) | |
10911 | { | |
3d388997 PB |
10912 | bfd_boolean narrow; |
10913 | int shift_kind; | |
10914 | ||
10915 | switch (inst.instruction) | |
10916 | { | |
10917 | case T_MNEM_asr: | |
10918 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
10919 | case T_MNEM_lsl: | |
10920 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
10921 | case T_MNEM_lsr: | |
10922 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
10923 | case T_MNEM_ror: | |
10924 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
10925 | default: abort (); | |
10926 | } | |
10927 | ||
10928 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10929 | narrow = !in_it_block (); |
3d388997 | 10930 | else |
e07e6e58 | 10931 | narrow = in_it_block (); |
3d388997 PB |
10932 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10933 | narrow = FALSE; | |
10934 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
10935 | narrow = FALSE; | |
10936 | if (inst.operands[2].isreg | |
10937 | && (inst.operands[1].reg != inst.operands[0].reg | |
10938 | || inst.operands[2].reg > 7)) | |
10939 | narrow = FALSE; | |
10940 | if (inst.size_req == 4) | |
10941 | narrow = FALSE; | |
10942 | ||
fdfde340 JM |
10943 | reject_bad_reg (inst.operands[0].reg); |
10944 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 10945 | |
3d388997 | 10946 | if (!narrow) |
c19d1205 ZW |
10947 | { |
10948 | if (inst.operands[2].isreg) | |
b99bd4ef | 10949 | { |
fdfde340 | 10950 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
10951 | inst.instruction = THUMB_OP32 (inst.instruction); |
10952 | inst.instruction |= inst.operands[0].reg << 8; | |
10953 | inst.instruction |= inst.operands[1].reg << 16; | |
10954 | inst.instruction |= inst.operands[2].reg; | |
10955 | } | |
10956 | else | |
10957 | { | |
10958 | inst.operands[1].shifted = 1; | |
3d388997 | 10959 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
10960 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
10961 | ? T_MNEM_movs : T_MNEM_mov); | |
10962 | inst.instruction |= inst.operands[0].reg << 8; | |
10963 | encode_thumb32_shifted_operand (1); | |
10964 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
10965 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
10966 | } |
10967 | } | |
10968 | else | |
10969 | { | |
c19d1205 | 10970 | if (inst.operands[2].isreg) |
b99bd4ef | 10971 | { |
3d388997 | 10972 | switch (shift_kind) |
b99bd4ef | 10973 | { |
3d388997 PB |
10974 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
10975 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
10976 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
10977 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 10978 | default: abort (); |
b99bd4ef | 10979 | } |
5f4273c7 | 10980 | |
c19d1205 ZW |
10981 | inst.instruction |= inst.operands[0].reg; |
10982 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
10983 | } |
10984 | else | |
10985 | { | |
3d388997 | 10986 | switch (shift_kind) |
b99bd4ef | 10987 | { |
3d388997 PB |
10988 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
10989 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10990 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 10991 | default: abort (); |
b99bd4ef | 10992 | } |
c19d1205 ZW |
10993 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10994 | inst.instruction |= inst.operands[0].reg; | |
10995 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
10996 | } |
10997 | } | |
c19d1205 ZW |
10998 | } |
10999 | else | |
11000 | { | |
11001 | constraint (inst.operands[0].reg > 7 | |
11002 | || inst.operands[1].reg > 7, BAD_HIREG); | |
11003 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 11004 | |
c19d1205 ZW |
11005 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
11006 | { | |
11007 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
11008 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
11009 | _("source1 and dest must be same register")); | |
b99bd4ef | 11010 | |
c19d1205 ZW |
11011 | switch (inst.instruction) |
11012 | { | |
11013 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
11014 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
11015 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
11016 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
11017 | default: abort (); | |
11018 | } | |
5f4273c7 | 11019 | |
c19d1205 ZW |
11020 | inst.instruction |= inst.operands[0].reg; |
11021 | inst.instruction |= inst.operands[2].reg << 3; | |
11022 | } | |
11023 | else | |
b99bd4ef | 11024 | { |
c19d1205 ZW |
11025 | switch (inst.instruction) |
11026 | { | |
11027 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
11028 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
11029 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
11030 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
11031 | default: abort (); | |
11032 | } | |
11033 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
11034 | inst.instruction |= inst.operands[0].reg; | |
11035 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
11036 | } |
11037 | } | |
b99bd4ef NC |
11038 | } |
11039 | ||
11040 | static void | |
c19d1205 | 11041 | do_t_simd (void) |
b99bd4ef | 11042 | { |
fdfde340 JM |
11043 | unsigned Rd, Rn, Rm; |
11044 | ||
11045 | Rd = inst.operands[0].reg; | |
11046 | Rn = inst.operands[1].reg; | |
11047 | Rm = inst.operands[2].reg; | |
11048 | ||
11049 | reject_bad_reg (Rd); | |
11050 | reject_bad_reg (Rn); | |
11051 | reject_bad_reg (Rm); | |
11052 | ||
11053 | inst.instruction |= Rd << 8; | |
11054 | inst.instruction |= Rn << 16; | |
11055 | inst.instruction |= Rm; | |
c19d1205 | 11056 | } |
b99bd4ef | 11057 | |
c19d1205 | 11058 | static void |
3eb17e6b | 11059 | do_t_smc (void) |
c19d1205 ZW |
11060 | { |
11061 | unsigned int value = inst.reloc.exp.X_add_number; | |
11062 | constraint (inst.reloc.exp.X_op != O_constant, | |
11063 | _("expression too complex")); | |
11064 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11065 | inst.instruction |= (value & 0xf000) >> 12; | |
11066 | inst.instruction |= (value & 0x0ff0); | |
11067 | inst.instruction |= (value & 0x000f) << 16; | |
11068 | } | |
b99bd4ef | 11069 | |
c19d1205 | 11070 | static void |
3a21c15a | 11071 | do_t_ssat_usat (int bias) |
c19d1205 | 11072 | { |
fdfde340 JM |
11073 | unsigned Rd, Rn; |
11074 | ||
11075 | Rd = inst.operands[0].reg; | |
11076 | Rn = inst.operands[2].reg; | |
11077 | ||
11078 | reject_bad_reg (Rd); | |
11079 | reject_bad_reg (Rn); | |
11080 | ||
11081 | inst.instruction |= Rd << 8; | |
3a21c15a | 11082 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 11083 | inst.instruction |= Rn << 16; |
b99bd4ef | 11084 | |
c19d1205 | 11085 | if (inst.operands[3].present) |
b99bd4ef | 11086 | { |
3a21c15a NC |
11087 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
11088 | ||
11089 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11090 | ||
c19d1205 ZW |
11091 | constraint (inst.reloc.exp.X_op != O_constant, |
11092 | _("expression too complex")); | |
b99bd4ef | 11093 | |
3a21c15a | 11094 | if (shift_amount != 0) |
6189168b | 11095 | { |
3a21c15a NC |
11096 | constraint (shift_amount > 31, |
11097 | _("shift expression is too large")); | |
11098 | ||
c19d1205 | 11099 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
11100 | inst.instruction |= 0x00200000; /* sh bit. */ |
11101 | ||
11102 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
11103 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
11104 | } |
11105 | } | |
b99bd4ef | 11106 | } |
c921be7d | 11107 | |
3a21c15a NC |
11108 | static void |
11109 | do_t_ssat (void) | |
11110 | { | |
11111 | do_t_ssat_usat (1); | |
11112 | } | |
b99bd4ef | 11113 | |
0dd132b6 | 11114 | static void |
c19d1205 | 11115 | do_t_ssat16 (void) |
0dd132b6 | 11116 | { |
fdfde340 JM |
11117 | unsigned Rd, Rn; |
11118 | ||
11119 | Rd = inst.operands[0].reg; | |
11120 | Rn = inst.operands[2].reg; | |
11121 | ||
11122 | reject_bad_reg (Rd); | |
11123 | reject_bad_reg (Rn); | |
11124 | ||
11125 | inst.instruction |= Rd << 8; | |
c19d1205 | 11126 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 11127 | inst.instruction |= Rn << 16; |
c19d1205 | 11128 | } |
0dd132b6 | 11129 | |
c19d1205 ZW |
11130 | static void |
11131 | do_t_strex (void) | |
11132 | { | |
11133 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
11134 | || inst.operands[2].postind || inst.operands[2].writeback | |
11135 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
11136 | || inst.operands[2].negative, | |
01cfc07f | 11137 | BAD_ADDR_MODE); |
0dd132b6 | 11138 | |
c19d1205 ZW |
11139 | inst.instruction |= inst.operands[0].reg << 8; |
11140 | inst.instruction |= inst.operands[1].reg << 12; | |
11141 | inst.instruction |= inst.operands[2].reg << 16; | |
11142 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
11143 | } |
11144 | ||
b99bd4ef | 11145 | static void |
c19d1205 | 11146 | do_t_strexd (void) |
b99bd4ef | 11147 | { |
c19d1205 ZW |
11148 | if (!inst.operands[2].present) |
11149 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 11150 | |
c19d1205 ZW |
11151 | constraint (inst.operands[0].reg == inst.operands[1].reg |
11152 | || inst.operands[0].reg == inst.operands[2].reg | |
11153 | || inst.operands[0].reg == inst.operands[3].reg | |
11154 | || inst.operands[1].reg == inst.operands[2].reg, | |
11155 | BAD_OVERLAP); | |
b99bd4ef | 11156 | |
c19d1205 ZW |
11157 | inst.instruction |= inst.operands[0].reg; |
11158 | inst.instruction |= inst.operands[1].reg << 12; | |
11159 | inst.instruction |= inst.operands[2].reg << 8; | |
11160 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
11161 | } |
11162 | ||
11163 | static void | |
c19d1205 | 11164 | do_t_sxtah (void) |
b99bd4ef | 11165 | { |
fdfde340 JM |
11166 | unsigned Rd, Rn, Rm; |
11167 | ||
11168 | Rd = inst.operands[0].reg; | |
11169 | Rn = inst.operands[1].reg; | |
11170 | Rm = inst.operands[2].reg; | |
11171 | ||
11172 | reject_bad_reg (Rd); | |
11173 | reject_bad_reg (Rn); | |
11174 | reject_bad_reg (Rm); | |
11175 | ||
11176 | inst.instruction |= Rd << 8; | |
11177 | inst.instruction |= Rn << 16; | |
11178 | inst.instruction |= Rm; | |
c19d1205 ZW |
11179 | inst.instruction |= inst.operands[3].imm << 4; |
11180 | } | |
b99bd4ef | 11181 | |
c19d1205 ZW |
11182 | static void |
11183 | do_t_sxth (void) | |
11184 | { | |
fdfde340 JM |
11185 | unsigned Rd, Rm; |
11186 | ||
11187 | Rd = inst.operands[0].reg; | |
11188 | Rm = inst.operands[1].reg; | |
11189 | ||
11190 | reject_bad_reg (Rd); | |
11191 | reject_bad_reg (Rm); | |
c921be7d NC |
11192 | |
11193 | if (inst.instruction <= 0xffff | |
11194 | && inst.size_req != 4 | |
fdfde340 | 11195 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 11196 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 11197 | { |
c19d1205 | 11198 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
11199 | inst.instruction |= Rd; |
11200 | inst.instruction |= Rm << 3; | |
b99bd4ef | 11201 | } |
c19d1205 | 11202 | else if (unified_syntax) |
b99bd4ef | 11203 | { |
c19d1205 ZW |
11204 | if (inst.instruction <= 0xffff) |
11205 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11206 | inst.instruction |= Rd << 8; |
11207 | inst.instruction |= Rm; | |
c19d1205 | 11208 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 11209 | } |
c19d1205 | 11210 | else |
b99bd4ef | 11211 | { |
c19d1205 ZW |
11212 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
11213 | _("Thumb encoding does not support rotation")); | |
11214 | constraint (1, BAD_HIREG); | |
b99bd4ef | 11215 | } |
c19d1205 | 11216 | } |
b99bd4ef | 11217 | |
c19d1205 ZW |
11218 | static void |
11219 | do_t_swi (void) | |
11220 | { | |
11221 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
11222 | } | |
b99bd4ef | 11223 | |
92e90b6e PB |
11224 | static void |
11225 | do_t_tb (void) | |
11226 | { | |
fdfde340 | 11227 | unsigned Rn, Rm; |
92e90b6e PB |
11228 | int half; |
11229 | ||
11230 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 11231 | set_it_insn_type_last (); |
dfa9f0d5 PB |
11232 | constraint (inst.operands[0].immisreg, |
11233 | _("instruction requires register index")); | |
fdfde340 JM |
11234 | |
11235 | Rn = inst.operands[0].reg; | |
11236 | Rm = inst.operands[0].imm; | |
c921be7d | 11237 | |
fdfde340 JM |
11238 | constraint (Rn == REG_SP, BAD_SP); |
11239 | reject_bad_reg (Rm); | |
11240 | ||
92e90b6e PB |
11241 | constraint (!half && inst.operands[0].shifted, |
11242 | _("instruction does not allow shifted index")); | |
fdfde340 | 11243 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
11244 | } |
11245 | ||
c19d1205 ZW |
11246 | static void |
11247 | do_t_usat (void) | |
11248 | { | |
3a21c15a | 11249 | do_t_ssat_usat (0); |
b99bd4ef NC |
11250 | } |
11251 | ||
11252 | static void | |
c19d1205 | 11253 | do_t_usat16 (void) |
b99bd4ef | 11254 | { |
fdfde340 JM |
11255 | unsigned Rd, Rn; |
11256 | ||
11257 | Rd = inst.operands[0].reg; | |
11258 | Rn = inst.operands[2].reg; | |
11259 | ||
11260 | reject_bad_reg (Rd); | |
11261 | reject_bad_reg (Rn); | |
11262 | ||
11263 | inst.instruction |= Rd << 8; | |
c19d1205 | 11264 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 11265 | inst.instruction |= Rn << 16; |
b99bd4ef | 11266 | } |
c19d1205 | 11267 | |
5287ad62 | 11268 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 11269 | |
5287ad62 | 11270 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 11271 | |
5287ad62 JB |
11272 | /* An "invalid" code for the following tables. */ |
11273 | #define N_INV -1u | |
11274 | ||
11275 | struct neon_tab_entry | |
b99bd4ef | 11276 | { |
5287ad62 JB |
11277 | unsigned integer; |
11278 | unsigned float_or_poly; | |
11279 | unsigned scalar_or_imm; | |
11280 | }; | |
5f4273c7 | 11281 | |
5287ad62 JB |
11282 | /* Map overloaded Neon opcodes to their respective encodings. */ |
11283 | #define NEON_ENC_TAB \ | |
11284 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
11285 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
11286 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
11287 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
11288 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
11289 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
11290 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
11291 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
11292 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
11293 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
11294 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
11295 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 11296 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
11297 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
11298 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
11299 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
11300 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
11301 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
11302 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
11303 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
11304 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
11305 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
11306 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
11307 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
11308 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
11309 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
11310 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
11311 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
11312 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
11313 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
11314 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
11315 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
11316 | X(veor, 0x1000110, N_INV, N_INV), \ | |
11317 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
11318 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
11319 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
11320 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
11321 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
11322 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
11323 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
11324 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
11325 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
11326 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
11327 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
11328 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
11329 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
11330 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
11331 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
11332 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
11333 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
11334 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
11335 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
11336 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
11337 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
11338 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
11339 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
11340 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
11341 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
11342 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
11343 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV) | |
5287ad62 JB |
11344 | |
11345 | enum neon_opc | |
11346 | { | |
11347 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
11348 | NEON_ENC_TAB | |
11349 | #undef X | |
11350 | }; | |
b99bd4ef | 11351 | |
5287ad62 JB |
11352 | static const struct neon_tab_entry neon_enc_tab[] = |
11353 | { | |
11354 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
11355 | NEON_ENC_TAB | |
11356 | #undef X | |
11357 | }; | |
b99bd4ef | 11358 | |
5287ad62 JB |
11359 | #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer) |
11360 | #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11361 | #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11362 | #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11363 | #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11364 | #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11365 | #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11366 | #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11367 | #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
037e8744 JB |
11368 | #define NEON_ENC_SINGLE(X) \ |
11369 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) | |
11370 | #define NEON_ENC_DOUBLE(X) \ | |
11371 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) | |
5287ad62 | 11372 | |
037e8744 JB |
11373 | /* Define shapes for instruction operands. The following mnemonic characters |
11374 | are used in this table: | |
5287ad62 | 11375 | |
037e8744 | 11376 | F - VFP S<n> register |
5287ad62 JB |
11377 | D - Neon D<n> register |
11378 | Q - Neon Q<n> register | |
11379 | I - Immediate | |
11380 | S - Scalar | |
11381 | R - ARM register | |
11382 | L - D<n> register list | |
5f4273c7 | 11383 | |
037e8744 JB |
11384 | This table is used to generate various data: |
11385 | - enumerations of the form NS_DDR to be used as arguments to | |
11386 | neon_select_shape. | |
11387 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 11388 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 11389 | |
037e8744 JB |
11390 | #define NEON_SHAPE_DEF \ |
11391 | X(3, (D, D, D), DOUBLE), \ | |
11392 | X(3, (Q, Q, Q), QUAD), \ | |
11393 | X(3, (D, D, I), DOUBLE), \ | |
11394 | X(3, (Q, Q, I), QUAD), \ | |
11395 | X(3, (D, D, S), DOUBLE), \ | |
11396 | X(3, (Q, Q, S), QUAD), \ | |
11397 | X(2, (D, D), DOUBLE), \ | |
11398 | X(2, (Q, Q), QUAD), \ | |
11399 | X(2, (D, S), DOUBLE), \ | |
11400 | X(2, (Q, S), QUAD), \ | |
11401 | X(2, (D, R), DOUBLE), \ | |
11402 | X(2, (Q, R), QUAD), \ | |
11403 | X(2, (D, I), DOUBLE), \ | |
11404 | X(2, (Q, I), QUAD), \ | |
11405 | X(3, (D, L, D), DOUBLE), \ | |
11406 | X(2, (D, Q), MIXED), \ | |
11407 | X(2, (Q, D), MIXED), \ | |
11408 | X(3, (D, Q, I), MIXED), \ | |
11409 | X(3, (Q, D, I), MIXED), \ | |
11410 | X(3, (Q, D, D), MIXED), \ | |
11411 | X(3, (D, Q, Q), MIXED), \ | |
11412 | X(3, (Q, Q, D), MIXED), \ | |
11413 | X(3, (Q, D, S), MIXED), \ | |
11414 | X(3, (D, Q, S), MIXED), \ | |
11415 | X(4, (D, D, D, I), DOUBLE), \ | |
11416 | X(4, (Q, Q, Q, I), QUAD), \ | |
11417 | X(2, (F, F), SINGLE), \ | |
11418 | X(3, (F, F, F), SINGLE), \ | |
11419 | X(2, (F, I), SINGLE), \ | |
11420 | X(2, (F, D), MIXED), \ | |
11421 | X(2, (D, F), MIXED), \ | |
11422 | X(3, (F, F, I), MIXED), \ | |
11423 | X(4, (R, R, F, F), SINGLE), \ | |
11424 | X(4, (F, F, R, R), SINGLE), \ | |
11425 | X(3, (D, R, R), DOUBLE), \ | |
11426 | X(3, (R, R, D), DOUBLE), \ | |
11427 | X(2, (S, R), SINGLE), \ | |
11428 | X(2, (R, S), SINGLE), \ | |
11429 | X(2, (F, R), SINGLE), \ | |
11430 | X(2, (R, F), SINGLE) | |
11431 | ||
11432 | #define S2(A,B) NS_##A##B | |
11433 | #define S3(A,B,C) NS_##A##B##C | |
11434 | #define S4(A,B,C,D) NS_##A##B##C##D | |
11435 | ||
11436 | #define X(N, L, C) S##N L | |
11437 | ||
5287ad62 JB |
11438 | enum neon_shape |
11439 | { | |
037e8744 JB |
11440 | NEON_SHAPE_DEF, |
11441 | NS_NULL | |
5287ad62 | 11442 | }; |
b99bd4ef | 11443 | |
037e8744 JB |
11444 | #undef X |
11445 | #undef S2 | |
11446 | #undef S3 | |
11447 | #undef S4 | |
11448 | ||
11449 | enum neon_shape_class | |
11450 | { | |
11451 | SC_SINGLE, | |
11452 | SC_DOUBLE, | |
11453 | SC_QUAD, | |
11454 | SC_MIXED | |
11455 | }; | |
11456 | ||
11457 | #define X(N, L, C) SC_##C | |
11458 | ||
11459 | static enum neon_shape_class neon_shape_class[] = | |
11460 | { | |
11461 | NEON_SHAPE_DEF | |
11462 | }; | |
11463 | ||
11464 | #undef X | |
11465 | ||
11466 | enum neon_shape_el | |
11467 | { | |
11468 | SE_F, | |
11469 | SE_D, | |
11470 | SE_Q, | |
11471 | SE_I, | |
11472 | SE_S, | |
11473 | SE_R, | |
11474 | SE_L | |
11475 | }; | |
11476 | ||
11477 | /* Register widths of above. */ | |
11478 | static unsigned neon_shape_el_size[] = | |
11479 | { | |
11480 | 32, | |
11481 | 64, | |
11482 | 128, | |
11483 | 0, | |
11484 | 32, | |
11485 | 32, | |
11486 | 0 | |
11487 | }; | |
11488 | ||
11489 | struct neon_shape_info | |
11490 | { | |
11491 | unsigned els; | |
11492 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
11493 | }; | |
11494 | ||
11495 | #define S2(A,B) { SE_##A, SE_##B } | |
11496 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
11497 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
11498 | ||
11499 | #define X(N, L, C) { N, S##N L } | |
11500 | ||
11501 | static struct neon_shape_info neon_shape_tab[] = | |
11502 | { | |
11503 | NEON_SHAPE_DEF | |
11504 | }; | |
11505 | ||
11506 | #undef X | |
11507 | #undef S2 | |
11508 | #undef S3 | |
11509 | #undef S4 | |
11510 | ||
5287ad62 JB |
11511 | /* Bit masks used in type checking given instructions. |
11512 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
11513 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
11514 | set, various other bits can be set as well in order to modify the meaning of | |
11515 | the type constraint. */ | |
11516 | ||
11517 | enum neon_type_mask | |
11518 | { | |
8e79c3df CM |
11519 | N_S8 = 0x0000001, |
11520 | N_S16 = 0x0000002, | |
11521 | N_S32 = 0x0000004, | |
11522 | N_S64 = 0x0000008, | |
11523 | N_U8 = 0x0000010, | |
11524 | N_U16 = 0x0000020, | |
11525 | N_U32 = 0x0000040, | |
11526 | N_U64 = 0x0000080, | |
11527 | N_I8 = 0x0000100, | |
11528 | N_I16 = 0x0000200, | |
11529 | N_I32 = 0x0000400, | |
11530 | N_I64 = 0x0000800, | |
11531 | N_8 = 0x0001000, | |
11532 | N_16 = 0x0002000, | |
11533 | N_32 = 0x0004000, | |
11534 | N_64 = 0x0008000, | |
11535 | N_P8 = 0x0010000, | |
11536 | N_P16 = 0x0020000, | |
11537 | N_F16 = 0x0040000, | |
11538 | N_F32 = 0x0080000, | |
11539 | N_F64 = 0x0100000, | |
c921be7d NC |
11540 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
11541 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 11542 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
c921be7d NC |
11543 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
11544 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
11545 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
11546 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
11547 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
11548 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
11549 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 11550 | N_UTYP = 0, |
037e8744 | 11551 | N_MAX_NONSPECIAL = N_F64 |
5287ad62 JB |
11552 | }; |
11553 | ||
dcbf9037 JB |
11554 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
11555 | ||
5287ad62 JB |
11556 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
11557 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
11558 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
11559 | #define N_SUF_32 (N_SU_32 | N_F32) | |
11560 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
11561 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
11562 | ||
11563 | /* Pass this as the first type argument to neon_check_type to ignore types | |
11564 | altogether. */ | |
11565 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
11566 | ||
037e8744 JB |
11567 | /* Select a "shape" for the current instruction (describing register types or |
11568 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
11569 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
11570 | function of operand parsing, so this function doesn't need to be called. | |
11571 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
11572 | |
11573 | static enum neon_shape | |
037e8744 | 11574 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 11575 | { |
037e8744 JB |
11576 | va_list ap; |
11577 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
11578 | |
11579 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
11580 | many arguments we should have, so this makes the assumption that we have | |
11581 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
11582 | true in the future. */ | |
11583 | if (!inst.operands[1].present) | |
11584 | inst.operands[1] = inst.operands[0]; | |
11585 | ||
037e8744 | 11586 | va_start (ap, shape); |
5f4273c7 | 11587 | |
21d799b5 | 11588 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
11589 | { |
11590 | unsigned j; | |
11591 | int matches = 1; | |
11592 | ||
11593 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
11594 | { | |
11595 | if (!inst.operands[j].present) | |
11596 | { | |
11597 | matches = 0; | |
11598 | break; | |
11599 | } | |
11600 | ||
11601 | switch (neon_shape_tab[shape].el[j]) | |
11602 | { | |
11603 | case SE_F: | |
11604 | if (!(inst.operands[j].isreg | |
11605 | && inst.operands[j].isvec | |
11606 | && inst.operands[j].issingle | |
11607 | && !inst.operands[j].isquad)) | |
11608 | matches = 0; | |
11609 | break; | |
11610 | ||
11611 | case SE_D: | |
11612 | if (!(inst.operands[j].isreg | |
11613 | && inst.operands[j].isvec | |
11614 | && !inst.operands[j].isquad | |
11615 | && !inst.operands[j].issingle)) | |
11616 | matches = 0; | |
11617 | break; | |
11618 | ||
11619 | case SE_R: | |
11620 | if (!(inst.operands[j].isreg | |
11621 | && !inst.operands[j].isvec)) | |
11622 | matches = 0; | |
11623 | break; | |
11624 | ||
11625 | case SE_Q: | |
11626 | if (!(inst.operands[j].isreg | |
11627 | && inst.operands[j].isvec | |
11628 | && inst.operands[j].isquad | |
11629 | && !inst.operands[j].issingle)) | |
11630 | matches = 0; | |
11631 | break; | |
11632 | ||
11633 | case SE_I: | |
11634 | if (!(!inst.operands[j].isreg | |
11635 | && !inst.operands[j].isscalar)) | |
11636 | matches = 0; | |
11637 | break; | |
11638 | ||
11639 | case SE_S: | |
11640 | if (!(!inst.operands[j].isreg | |
11641 | && inst.operands[j].isscalar)) | |
11642 | matches = 0; | |
11643 | break; | |
11644 | ||
11645 | case SE_L: | |
11646 | break; | |
11647 | } | |
11648 | } | |
11649 | if (matches) | |
5287ad62 | 11650 | break; |
037e8744 | 11651 | } |
5f4273c7 | 11652 | |
037e8744 | 11653 | va_end (ap); |
5287ad62 | 11654 | |
037e8744 JB |
11655 | if (shape == NS_NULL && first_shape != NS_NULL) |
11656 | first_error (_("invalid instruction shape")); | |
5287ad62 | 11657 | |
037e8744 JB |
11658 | return shape; |
11659 | } | |
5287ad62 | 11660 | |
037e8744 JB |
11661 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
11662 | means the Q bit should be set). */ | |
11663 | ||
11664 | static int | |
11665 | neon_quad (enum neon_shape shape) | |
11666 | { | |
11667 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 11668 | } |
037e8744 | 11669 | |
5287ad62 JB |
11670 | static void |
11671 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
11672 | unsigned *g_size) | |
11673 | { | |
11674 | /* Allow modification to be made to types which are constrained to be | |
11675 | based on the key element, based on bits set alongside N_EQK. */ | |
11676 | if ((typebits & N_EQK) != 0) | |
11677 | { | |
11678 | if ((typebits & N_HLF) != 0) | |
11679 | *g_size /= 2; | |
11680 | else if ((typebits & N_DBL) != 0) | |
11681 | *g_size *= 2; | |
11682 | if ((typebits & N_SGN) != 0) | |
11683 | *g_type = NT_signed; | |
11684 | else if ((typebits & N_UNS) != 0) | |
11685 | *g_type = NT_unsigned; | |
11686 | else if ((typebits & N_INT) != 0) | |
11687 | *g_type = NT_integer; | |
11688 | else if ((typebits & N_FLT) != 0) | |
11689 | *g_type = NT_float; | |
dcbf9037 JB |
11690 | else if ((typebits & N_SIZ) != 0) |
11691 | *g_type = NT_untyped; | |
5287ad62 JB |
11692 | } |
11693 | } | |
5f4273c7 | 11694 | |
5287ad62 JB |
11695 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
11696 | operand type, i.e. the single type specified in a Neon instruction when it | |
11697 | is the only one given. */ | |
11698 | ||
11699 | static struct neon_type_el | |
11700 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
11701 | { | |
11702 | struct neon_type_el dest = *key; | |
5f4273c7 | 11703 | |
9c2799c2 | 11704 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 11705 | |
5287ad62 JB |
11706 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
11707 | ||
11708 | return dest; | |
11709 | } | |
11710 | ||
11711 | /* Convert Neon type and size into compact bitmask representation. */ | |
11712 | ||
11713 | static enum neon_type_mask | |
11714 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
11715 | { | |
11716 | switch (type) | |
11717 | { | |
11718 | case NT_untyped: | |
11719 | switch (size) | |
11720 | { | |
11721 | case 8: return N_8; | |
11722 | case 16: return N_16; | |
11723 | case 32: return N_32; | |
11724 | case 64: return N_64; | |
11725 | default: ; | |
11726 | } | |
11727 | break; | |
11728 | ||
11729 | case NT_integer: | |
11730 | switch (size) | |
11731 | { | |
11732 | case 8: return N_I8; | |
11733 | case 16: return N_I16; | |
11734 | case 32: return N_I32; | |
11735 | case 64: return N_I64; | |
11736 | default: ; | |
11737 | } | |
11738 | break; | |
11739 | ||
11740 | case NT_float: | |
037e8744 JB |
11741 | switch (size) |
11742 | { | |
8e79c3df | 11743 | case 16: return N_F16; |
037e8744 JB |
11744 | case 32: return N_F32; |
11745 | case 64: return N_F64; | |
11746 | default: ; | |
11747 | } | |
5287ad62 JB |
11748 | break; |
11749 | ||
11750 | case NT_poly: | |
11751 | switch (size) | |
11752 | { | |
11753 | case 8: return N_P8; | |
11754 | case 16: return N_P16; | |
11755 | default: ; | |
11756 | } | |
11757 | break; | |
11758 | ||
11759 | case NT_signed: | |
11760 | switch (size) | |
11761 | { | |
11762 | case 8: return N_S8; | |
11763 | case 16: return N_S16; | |
11764 | case 32: return N_S32; | |
11765 | case 64: return N_S64; | |
11766 | default: ; | |
11767 | } | |
11768 | break; | |
11769 | ||
11770 | case NT_unsigned: | |
11771 | switch (size) | |
11772 | { | |
11773 | case 8: return N_U8; | |
11774 | case 16: return N_U16; | |
11775 | case 32: return N_U32; | |
11776 | case 64: return N_U64; | |
11777 | default: ; | |
11778 | } | |
11779 | break; | |
11780 | ||
11781 | default: ; | |
11782 | } | |
5f4273c7 | 11783 | |
5287ad62 JB |
11784 | return N_UTYP; |
11785 | } | |
11786 | ||
11787 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
11788 | handles the case where a single bit is set in the mask. */ | |
11789 | ||
dcbf9037 | 11790 | static int |
5287ad62 JB |
11791 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
11792 | enum neon_type_mask mask) | |
11793 | { | |
dcbf9037 JB |
11794 | if ((mask & N_EQK) != 0) |
11795 | return FAIL; | |
11796 | ||
5287ad62 JB |
11797 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
11798 | *size = 8; | |
dcbf9037 | 11799 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0) |
5287ad62 | 11800 | *size = 16; |
dcbf9037 | 11801 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 11802 | *size = 32; |
037e8744 | 11803 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0) |
5287ad62 | 11804 | *size = 64; |
dcbf9037 JB |
11805 | else |
11806 | return FAIL; | |
11807 | ||
5287ad62 JB |
11808 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
11809 | *type = NT_signed; | |
dcbf9037 | 11810 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 11811 | *type = NT_unsigned; |
dcbf9037 | 11812 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 11813 | *type = NT_integer; |
dcbf9037 | 11814 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 11815 | *type = NT_untyped; |
dcbf9037 | 11816 | else if ((mask & (N_P8 | N_P16)) != 0) |
5287ad62 | 11817 | *type = NT_poly; |
037e8744 | 11818 | else if ((mask & (N_F32 | N_F64)) != 0) |
5287ad62 | 11819 | *type = NT_float; |
dcbf9037 JB |
11820 | else |
11821 | return FAIL; | |
5f4273c7 | 11822 | |
dcbf9037 | 11823 | return SUCCESS; |
5287ad62 JB |
11824 | } |
11825 | ||
11826 | /* Modify a bitmask of allowed types. This is only needed for type | |
11827 | relaxation. */ | |
11828 | ||
11829 | static unsigned | |
11830 | modify_types_allowed (unsigned allowed, unsigned mods) | |
11831 | { | |
11832 | unsigned size; | |
11833 | enum neon_el_type type; | |
11834 | unsigned destmask; | |
11835 | int i; | |
5f4273c7 | 11836 | |
5287ad62 | 11837 | destmask = 0; |
5f4273c7 | 11838 | |
5287ad62 JB |
11839 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
11840 | { | |
21d799b5 NC |
11841 | if (el_type_of_type_chk (&type, &size, |
11842 | (enum neon_type_mask) (allowed & i)) == SUCCESS) | |
dcbf9037 JB |
11843 | { |
11844 | neon_modify_type_size (mods, &type, &size); | |
11845 | destmask |= type_chk_of_el_type (type, size); | |
11846 | } | |
5287ad62 | 11847 | } |
5f4273c7 | 11848 | |
5287ad62 JB |
11849 | return destmask; |
11850 | } | |
11851 | ||
11852 | /* Check type and return type classification. | |
11853 | The manual states (paraphrase): If one datatype is given, it indicates the | |
11854 | type given in: | |
11855 | - the second operand, if there is one | |
11856 | - the operand, if there is no second operand | |
11857 | - the result, if there are no operands. | |
11858 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
11859 | which is set on a per-instruction basis, which is the one which matters when | |
11860 | only one data type is written. | |
11861 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 11862 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
11863 | |
11864 | static struct neon_type_el | |
11865 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
11866 | { | |
11867 | va_list ap; | |
11868 | unsigned i, pass, key_el = 0; | |
11869 | unsigned types[NEON_MAX_TYPE_ELS]; | |
11870 | enum neon_el_type k_type = NT_invtype; | |
11871 | unsigned k_size = -1u; | |
11872 | struct neon_type_el badtype = {NT_invtype, -1}; | |
11873 | unsigned key_allowed = 0; | |
11874 | ||
11875 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
11876 | Fill in the missing operand here, if it was omitted. */ | |
11877 | if (els > 1 && !inst.operands[1].present) | |
11878 | inst.operands[1] = inst.operands[0]; | |
11879 | ||
11880 | /* Suck up all the varargs. */ | |
11881 | va_start (ap, ns); | |
11882 | for (i = 0; i < els; i++) | |
11883 | { | |
11884 | unsigned thisarg = va_arg (ap, unsigned); | |
11885 | if (thisarg == N_IGNORE_TYPE) | |
11886 | { | |
11887 | va_end (ap); | |
11888 | return badtype; | |
11889 | } | |
11890 | types[i] = thisarg; | |
11891 | if ((thisarg & N_KEY) != 0) | |
11892 | key_el = i; | |
11893 | } | |
11894 | va_end (ap); | |
11895 | ||
dcbf9037 JB |
11896 | if (inst.vectype.elems > 0) |
11897 | for (i = 0; i < els; i++) | |
11898 | if (inst.operands[i].vectype.type != NT_invtype) | |
11899 | { | |
11900 | first_error (_("types specified in both the mnemonic and operands")); | |
11901 | return badtype; | |
11902 | } | |
11903 | ||
5287ad62 JB |
11904 | /* Duplicate inst.vectype elements here as necessary. |
11905 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
11906 | particularly when an insn takes one register and one non-register | |
11907 | operand. */ | |
11908 | if (inst.vectype.elems == 1 && els > 1) | |
11909 | { | |
11910 | unsigned j; | |
11911 | inst.vectype.elems = els; | |
11912 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
11913 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
11914 | if (j != key_el) |
11915 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
11916 | types[j]); | |
11917 | } | |
11918 | else if (inst.vectype.elems == 0 && els > 0) | |
11919 | { | |
11920 | unsigned j; | |
11921 | /* No types were given after the mnemonic, so look for types specified | |
11922 | after each operand. We allow some flexibility here; as long as the | |
11923 | "key" operand has a type, we can infer the others. */ | |
11924 | for (j = 0; j < els; j++) | |
11925 | if (inst.operands[j].vectype.type != NT_invtype) | |
11926 | inst.vectype.el[j] = inst.operands[j].vectype; | |
11927 | ||
11928 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 11929 | { |
dcbf9037 JB |
11930 | for (j = 0; j < els; j++) |
11931 | if (inst.operands[j].vectype.type == NT_invtype) | |
11932 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
11933 | types[j]); | |
11934 | } | |
11935 | else | |
11936 | { | |
11937 | first_error (_("operand types can't be inferred")); | |
11938 | return badtype; | |
5287ad62 JB |
11939 | } |
11940 | } | |
11941 | else if (inst.vectype.elems != els) | |
11942 | { | |
dcbf9037 | 11943 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
11944 | return badtype; |
11945 | } | |
11946 | ||
11947 | for (pass = 0; pass < 2; pass++) | |
11948 | { | |
11949 | for (i = 0; i < els; i++) | |
11950 | { | |
11951 | unsigned thisarg = types[i]; | |
11952 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
11953 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
11954 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
11955 | unsigned g_size = inst.vectype.el[i].size; | |
11956 | ||
11957 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
11958 | integer types if sign-specific variants are unavailable. */ | |
11959 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
11960 | && (types_allowed & N_SU_ALL) == 0) | |
11961 | g_type = NT_integer; | |
11962 | ||
11963 | /* If only untyped args are allowed, decay any more specific types to | |
11964 | them. Some instructions only care about signs for some element | |
11965 | sizes, so handle that properly. */ | |
11966 | if ((g_size == 8 && (types_allowed & N_8) != 0) | |
11967 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
11968 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
11969 | || (g_size == 64 && (types_allowed & N_64) != 0)) | |
11970 | g_type = NT_untyped; | |
11971 | ||
11972 | if (pass == 0) | |
11973 | { | |
11974 | if ((thisarg & N_KEY) != 0) | |
11975 | { | |
11976 | k_type = g_type; | |
11977 | k_size = g_size; | |
11978 | key_allowed = thisarg & ~N_KEY; | |
11979 | } | |
11980 | } | |
11981 | else | |
11982 | { | |
037e8744 JB |
11983 | if ((thisarg & N_VFP) != 0) |
11984 | { | |
11985 | enum neon_shape_el regshape = neon_shape_tab[ns].el[i]; | |
11986 | unsigned regwidth = neon_shape_el_size[regshape], match; | |
11987 | ||
11988 | /* In VFP mode, operands must match register widths. If we | |
11989 | have a key operand, use its width, else use the width of | |
11990 | the current operand. */ | |
11991 | if (k_size != -1u) | |
11992 | match = k_size; | |
11993 | else | |
11994 | match = g_size; | |
11995 | ||
11996 | if (regwidth != match) | |
11997 | { | |
11998 | first_error (_("operand size must match register width")); | |
11999 | return badtype; | |
12000 | } | |
12001 | } | |
5f4273c7 | 12002 | |
5287ad62 JB |
12003 | if ((thisarg & N_EQK) == 0) |
12004 | { | |
12005 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
12006 | ||
12007 | if ((given_type & types_allowed) == 0) | |
12008 | { | |
dcbf9037 | 12009 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
12010 | return badtype; |
12011 | } | |
12012 | } | |
12013 | else | |
12014 | { | |
12015 | enum neon_el_type mod_k_type = k_type; | |
12016 | unsigned mod_k_size = k_size; | |
12017 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
12018 | if (g_type != mod_k_type || g_size != mod_k_size) | |
12019 | { | |
dcbf9037 | 12020 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
12021 | return badtype; |
12022 | } | |
12023 | } | |
12024 | } | |
12025 | } | |
12026 | } | |
12027 | ||
12028 | return inst.vectype.el[key_el]; | |
12029 | } | |
12030 | ||
037e8744 | 12031 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 12032 | |
037e8744 JB |
12033 | /* Thumb VFP instructions have 0xE in the condition field. */ |
12034 | ||
12035 | static void | |
12036 | do_vfp_cond_or_thumb (void) | |
5287ad62 JB |
12037 | { |
12038 | if (thumb_mode) | |
037e8744 | 12039 | inst.instruction |= 0xe0000000; |
5287ad62 | 12040 | else |
037e8744 | 12041 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
12042 | } |
12043 | ||
037e8744 JB |
12044 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
12045 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
12046 | etc. It is assumed that operand parsing has already been done, and that the | |
12047 | operands are in the form expected by the given opcode (this isn't necessarily | |
12048 | the same as the form in which they were parsed, hence some massaging must | |
12049 | take place before this function is called). | |
12050 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 12051 | |
037e8744 JB |
12052 | static void |
12053 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 12054 | { |
037e8744 | 12055 | const struct asm_opcode *opcode; |
5f4273c7 | 12056 | |
21d799b5 | 12057 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 12058 | |
037e8744 JB |
12059 | if (!opcode) |
12060 | abort (); | |
5287ad62 | 12061 | |
037e8744 JB |
12062 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
12063 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
12064 | _(BAD_FPU)); | |
5287ad62 | 12065 | |
037e8744 JB |
12066 | if (thumb_mode) |
12067 | { | |
12068 | inst.instruction = opcode->tvalue; | |
12069 | opcode->tencode (); | |
12070 | } | |
12071 | else | |
12072 | { | |
12073 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
12074 | opcode->aencode (); | |
12075 | } | |
12076 | } | |
5287ad62 JB |
12077 | |
12078 | static void | |
037e8744 | 12079 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 12080 | { |
037e8744 JB |
12081 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
12082 | ||
12083 | if (rs == NS_FFF) | |
12084 | { | |
12085 | if (is_add) | |
12086 | do_vfp_nsyn_opcode ("fadds"); | |
12087 | else | |
12088 | do_vfp_nsyn_opcode ("fsubs"); | |
12089 | } | |
12090 | else | |
12091 | { | |
12092 | if (is_add) | |
12093 | do_vfp_nsyn_opcode ("faddd"); | |
12094 | else | |
12095 | do_vfp_nsyn_opcode ("fsubd"); | |
12096 | } | |
12097 | } | |
12098 | ||
12099 | /* Check operand types to see if this is a VFP instruction, and if so call | |
12100 | PFN (). */ | |
12101 | ||
12102 | static int | |
12103 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
12104 | { | |
12105 | enum neon_shape rs; | |
12106 | struct neon_type_el et; | |
12107 | ||
12108 | switch (args) | |
12109 | { | |
12110 | case 2: | |
12111 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12112 | et = neon_check_type (2, rs, | |
12113 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12114 | break; | |
5f4273c7 | 12115 | |
037e8744 JB |
12116 | case 3: |
12117 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12118 | et = neon_check_type (3, rs, | |
12119 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12120 | break; | |
12121 | ||
12122 | default: | |
12123 | abort (); | |
12124 | } | |
12125 | ||
12126 | if (et.type != NT_invtype) | |
12127 | { | |
12128 | pfn (rs); | |
12129 | return SUCCESS; | |
12130 | } | |
12131 | else | |
12132 | inst.error = NULL; | |
12133 | ||
12134 | return FAIL; | |
12135 | } | |
12136 | ||
12137 | static void | |
12138 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
12139 | { | |
12140 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 12141 | |
037e8744 JB |
12142 | if (rs == NS_FFF) |
12143 | { | |
12144 | if (is_mla) | |
12145 | do_vfp_nsyn_opcode ("fmacs"); | |
12146 | else | |
1ee69515 | 12147 | do_vfp_nsyn_opcode ("fnmacs"); |
037e8744 JB |
12148 | } |
12149 | else | |
12150 | { | |
12151 | if (is_mla) | |
12152 | do_vfp_nsyn_opcode ("fmacd"); | |
12153 | else | |
1ee69515 | 12154 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
12155 | } |
12156 | } | |
12157 | ||
62f3b8c8 PB |
12158 | static void |
12159 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
12160 | { | |
12161 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
12162 | ||
12163 | if (rs == NS_FFF) | |
12164 | { | |
12165 | if (is_fma) | |
12166 | do_vfp_nsyn_opcode ("ffmas"); | |
12167 | else | |
12168 | do_vfp_nsyn_opcode ("ffnmas"); | |
12169 | } | |
12170 | else | |
12171 | { | |
12172 | if (is_fma) | |
12173 | do_vfp_nsyn_opcode ("ffmad"); | |
12174 | else | |
12175 | do_vfp_nsyn_opcode ("ffnmad"); | |
12176 | } | |
12177 | } | |
12178 | ||
037e8744 JB |
12179 | static void |
12180 | do_vfp_nsyn_mul (enum neon_shape rs) | |
12181 | { | |
12182 | if (rs == NS_FFF) | |
12183 | do_vfp_nsyn_opcode ("fmuls"); | |
12184 | else | |
12185 | do_vfp_nsyn_opcode ("fmuld"); | |
12186 | } | |
12187 | ||
12188 | static void | |
12189 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
12190 | { | |
12191 | int is_neg = (inst.instruction & 0x80) != 0; | |
12192 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
12193 | ||
12194 | if (rs == NS_FF) | |
12195 | { | |
12196 | if (is_neg) | |
12197 | do_vfp_nsyn_opcode ("fnegs"); | |
12198 | else | |
12199 | do_vfp_nsyn_opcode ("fabss"); | |
12200 | } | |
12201 | else | |
12202 | { | |
12203 | if (is_neg) | |
12204 | do_vfp_nsyn_opcode ("fnegd"); | |
12205 | else | |
12206 | do_vfp_nsyn_opcode ("fabsd"); | |
12207 | } | |
12208 | } | |
12209 | ||
12210 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
12211 | insns belong to Neon, and are handled elsewhere. */ | |
12212 | ||
12213 | static void | |
12214 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
12215 | { | |
12216 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
12217 | if (is_ldm) | |
12218 | { | |
12219 | if (is_dbmode) | |
12220 | do_vfp_nsyn_opcode ("fldmdbs"); | |
12221 | else | |
12222 | do_vfp_nsyn_opcode ("fldmias"); | |
12223 | } | |
12224 | else | |
12225 | { | |
12226 | if (is_dbmode) | |
12227 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12228 | else | |
12229 | do_vfp_nsyn_opcode ("fstmias"); | |
12230 | } | |
12231 | } | |
12232 | ||
037e8744 JB |
12233 | static void |
12234 | do_vfp_nsyn_sqrt (void) | |
12235 | { | |
12236 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12237 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12238 | |
037e8744 JB |
12239 | if (rs == NS_FF) |
12240 | do_vfp_nsyn_opcode ("fsqrts"); | |
12241 | else | |
12242 | do_vfp_nsyn_opcode ("fsqrtd"); | |
12243 | } | |
12244 | ||
12245 | static void | |
12246 | do_vfp_nsyn_div (void) | |
12247 | { | |
12248 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12249 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12250 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12251 | |
037e8744 JB |
12252 | if (rs == NS_FFF) |
12253 | do_vfp_nsyn_opcode ("fdivs"); | |
12254 | else | |
12255 | do_vfp_nsyn_opcode ("fdivd"); | |
12256 | } | |
12257 | ||
12258 | static void | |
12259 | do_vfp_nsyn_nmul (void) | |
12260 | { | |
12261 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12262 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12263 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12264 | |
037e8744 JB |
12265 | if (rs == NS_FFF) |
12266 | { | |
12267 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12268 | do_vfp_sp_dyadic (); | |
12269 | } | |
12270 | else | |
12271 | { | |
12272 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12273 | do_vfp_dp_rd_rn_rm (); | |
12274 | } | |
12275 | do_vfp_cond_or_thumb (); | |
12276 | } | |
12277 | ||
12278 | static void | |
12279 | do_vfp_nsyn_cmp (void) | |
12280 | { | |
12281 | if (inst.operands[1].isreg) | |
12282 | { | |
12283 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12284 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12285 | |
037e8744 JB |
12286 | if (rs == NS_FF) |
12287 | { | |
12288 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12289 | do_vfp_sp_monadic (); | |
12290 | } | |
12291 | else | |
12292 | { | |
12293 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12294 | do_vfp_dp_rd_rm (); | |
12295 | } | |
12296 | } | |
12297 | else | |
12298 | { | |
12299 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
12300 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
12301 | ||
12302 | switch (inst.instruction & 0x0fffffff) | |
12303 | { | |
12304 | case N_MNEM_vcmp: | |
12305 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
12306 | break; | |
12307 | case N_MNEM_vcmpe: | |
12308 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
12309 | break; | |
12310 | default: | |
12311 | abort (); | |
12312 | } | |
5f4273c7 | 12313 | |
037e8744 JB |
12314 | if (rs == NS_FI) |
12315 | { | |
12316 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12317 | do_vfp_sp_compare_z (); | |
12318 | } | |
12319 | else | |
12320 | { | |
12321 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12322 | do_vfp_dp_rd (); | |
12323 | } | |
12324 | } | |
12325 | do_vfp_cond_or_thumb (); | |
12326 | } | |
12327 | ||
12328 | static void | |
12329 | nsyn_insert_sp (void) | |
12330 | { | |
12331 | inst.operands[1] = inst.operands[0]; | |
12332 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 12333 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
12334 | inst.operands[0].isreg = 1; |
12335 | inst.operands[0].writeback = 1; | |
12336 | inst.operands[0].present = 1; | |
12337 | } | |
12338 | ||
12339 | static void | |
12340 | do_vfp_nsyn_push (void) | |
12341 | { | |
12342 | nsyn_insert_sp (); | |
12343 | if (inst.operands[1].issingle) | |
12344 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12345 | else | |
12346 | do_vfp_nsyn_opcode ("fstmdbd"); | |
12347 | } | |
12348 | ||
12349 | static void | |
12350 | do_vfp_nsyn_pop (void) | |
12351 | { | |
12352 | nsyn_insert_sp (); | |
12353 | if (inst.operands[1].issingle) | |
22b5b651 | 12354 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 12355 | else |
22b5b651 | 12356 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
12357 | } |
12358 | ||
12359 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
12360 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
12361 | ||
12362 | static unsigned | |
12363 | neon_dp_fixup (unsigned i) | |
12364 | { | |
12365 | if (thumb_mode) | |
12366 | { | |
12367 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
12368 | if (i & (1 << 24)) | |
12369 | i |= 1 << 28; | |
5f4273c7 | 12370 | |
037e8744 | 12371 | i &= ~(1 << 24); |
5f4273c7 | 12372 | |
037e8744 JB |
12373 | i |= 0xef000000; |
12374 | } | |
12375 | else | |
12376 | i |= 0xf2000000; | |
5f4273c7 | 12377 | |
037e8744 JB |
12378 | return i; |
12379 | } | |
12380 | ||
12381 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
12382 | (0, 1, 2, 3). */ | |
12383 | ||
12384 | static unsigned | |
12385 | neon_logbits (unsigned x) | |
12386 | { | |
12387 | return ffs (x) - 4; | |
12388 | } | |
12389 | ||
12390 | #define LOW4(R) ((R) & 0xf) | |
12391 | #define HI1(R) (((R) >> 4) & 1) | |
12392 | ||
12393 | /* Encode insns with bit pattern: | |
12394 | ||
12395 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
12396 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 12397 | |
037e8744 JB |
12398 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
12399 | different meaning for some instruction. */ | |
12400 | ||
12401 | static void | |
12402 | neon_three_same (int isquad, int ubit, int size) | |
12403 | { | |
12404 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12405 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12406 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12407 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12408 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12409 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12410 | inst.instruction |= (isquad != 0) << 6; | |
12411 | inst.instruction |= (ubit != 0) << 24; | |
12412 | if (size != -1) | |
12413 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 12414 | |
037e8744 JB |
12415 | inst.instruction = neon_dp_fixup (inst.instruction); |
12416 | } | |
12417 | ||
12418 | /* Encode instructions of the form: | |
12419 | ||
12420 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
12421 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
12422 | |
12423 | Don't write size if SIZE == -1. */ | |
12424 | ||
12425 | static void | |
12426 | neon_two_same (int qbit, int ubit, int size) | |
12427 | { | |
12428 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12429 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12430 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12431 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12432 | inst.instruction |= (qbit != 0) << 6; | |
12433 | inst.instruction |= (ubit != 0) << 24; | |
12434 | ||
12435 | if (size != -1) | |
12436 | inst.instruction |= neon_logbits (size) << 18; | |
12437 | ||
12438 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12439 | } | |
12440 | ||
12441 | /* Neon instruction encoders, in approximate order of appearance. */ | |
12442 | ||
12443 | static void | |
12444 | do_neon_dyadic_i_su (void) | |
12445 | { | |
037e8744 | 12446 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12447 | struct neon_type_el et = neon_check_type (3, rs, |
12448 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 12449 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12450 | } |
12451 | ||
12452 | static void | |
12453 | do_neon_dyadic_i64_su (void) | |
12454 | { | |
037e8744 | 12455 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12456 | struct neon_type_el et = neon_check_type (3, rs, |
12457 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 12458 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12459 | } |
12460 | ||
12461 | static void | |
12462 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
12463 | unsigned immbits) | |
12464 | { | |
12465 | unsigned size = et.size >> 3; | |
12466 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12467 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12468 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12469 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12470 | inst.instruction |= (isquad != 0) << 6; | |
12471 | inst.instruction |= immbits << 16; | |
12472 | inst.instruction |= (size >> 3) << 7; | |
12473 | inst.instruction |= (size & 0x7) << 19; | |
12474 | if (write_ubit) | |
12475 | inst.instruction |= (uval != 0) << 24; | |
12476 | ||
12477 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12478 | } | |
12479 | ||
12480 | static void | |
12481 | do_neon_shl_imm (void) | |
12482 | { | |
12483 | if (!inst.operands[2].isreg) | |
12484 | { | |
037e8744 | 12485 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12486 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
12487 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 12488 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
12489 | } |
12490 | else | |
12491 | { | |
037e8744 | 12492 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12493 | struct neon_type_el et = neon_check_type (3, rs, |
12494 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12495 | unsigned int tmp; |
12496 | ||
12497 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
12498 | vshl.xx Dd, Dm, Dn | |
12499 | whereas other 3-register operations encoded by neon_three_same have | |
12500 | syntax like: | |
12501 | vadd.xx Dd, Dn, Dm | |
12502 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
12503 | here. */ | |
12504 | tmp = inst.operands[2].reg; | |
12505 | inst.operands[2].reg = inst.operands[1].reg; | |
12506 | inst.operands[1].reg = tmp; | |
5287ad62 | 12507 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
037e8744 | 12508 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12509 | } |
12510 | } | |
12511 | ||
12512 | static void | |
12513 | do_neon_qshl_imm (void) | |
12514 | { | |
12515 | if (!inst.operands[2].isreg) | |
12516 | { | |
037e8744 | 12517 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 12518 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
627907b7 | 12519 | |
5287ad62 | 12520 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
037e8744 | 12521 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
12522 | inst.operands[2].imm); |
12523 | } | |
12524 | else | |
12525 | { | |
037e8744 | 12526 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12527 | struct neon_type_el et = neon_check_type (3, rs, |
12528 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12529 | unsigned int tmp; |
12530 | ||
12531 | /* See note in do_neon_shl_imm. */ | |
12532 | tmp = inst.operands[2].reg; | |
12533 | inst.operands[2].reg = inst.operands[1].reg; | |
12534 | inst.operands[1].reg = tmp; | |
5287ad62 | 12535 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
037e8744 | 12536 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12537 | } |
12538 | } | |
12539 | ||
627907b7 JB |
12540 | static void |
12541 | do_neon_rshl (void) | |
12542 | { | |
12543 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
12544 | struct neon_type_el et = neon_check_type (3, rs, | |
12545 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
12546 | unsigned int tmp; | |
12547 | ||
12548 | tmp = inst.operands[2].reg; | |
12549 | inst.operands[2].reg = inst.operands[1].reg; | |
12550 | inst.operands[1].reg = tmp; | |
12551 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
12552 | } | |
12553 | ||
5287ad62 JB |
12554 | static int |
12555 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
12556 | { | |
036dc3f7 PB |
12557 | /* Handle .I8 pseudo-instructions. */ |
12558 | if (size == 8) | |
5287ad62 | 12559 | { |
5287ad62 JB |
12560 | /* Unfortunately, this will make everything apart from zero out-of-range. |
12561 | FIXME is this the intended semantics? There doesn't seem much point in | |
12562 | accepting .I8 if so. */ | |
12563 | immediate |= immediate << 8; | |
12564 | size = 16; | |
036dc3f7 PB |
12565 | } |
12566 | ||
12567 | if (size >= 32) | |
12568 | { | |
12569 | if (immediate == (immediate & 0x000000ff)) | |
12570 | { | |
12571 | *immbits = immediate; | |
12572 | return 0x1; | |
12573 | } | |
12574 | else if (immediate == (immediate & 0x0000ff00)) | |
12575 | { | |
12576 | *immbits = immediate >> 8; | |
12577 | return 0x3; | |
12578 | } | |
12579 | else if (immediate == (immediate & 0x00ff0000)) | |
12580 | { | |
12581 | *immbits = immediate >> 16; | |
12582 | return 0x5; | |
12583 | } | |
12584 | else if (immediate == (immediate & 0xff000000)) | |
12585 | { | |
12586 | *immbits = immediate >> 24; | |
12587 | return 0x7; | |
12588 | } | |
12589 | if ((immediate & 0xffff) != (immediate >> 16)) | |
12590 | goto bad_immediate; | |
12591 | immediate &= 0xffff; | |
5287ad62 JB |
12592 | } |
12593 | ||
12594 | if (immediate == (immediate & 0x000000ff)) | |
12595 | { | |
12596 | *immbits = immediate; | |
036dc3f7 | 12597 | return 0x9; |
5287ad62 JB |
12598 | } |
12599 | else if (immediate == (immediate & 0x0000ff00)) | |
12600 | { | |
12601 | *immbits = immediate >> 8; | |
036dc3f7 | 12602 | return 0xb; |
5287ad62 JB |
12603 | } |
12604 | ||
12605 | bad_immediate: | |
dcbf9037 | 12606 | first_error (_("immediate value out of range")); |
5287ad62 JB |
12607 | return FAIL; |
12608 | } | |
12609 | ||
12610 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
12611 | A, B, C, D. */ | |
12612 | ||
12613 | static int | |
12614 | neon_bits_same_in_bytes (unsigned imm) | |
12615 | { | |
12616 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
12617 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
12618 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
12619 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
12620 | } | |
12621 | ||
12622 | /* For immediate of above form, return 0bABCD. */ | |
12623 | ||
12624 | static unsigned | |
12625 | neon_squash_bits (unsigned imm) | |
12626 | { | |
12627 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
12628 | | ((imm & 0x01000000) >> 21); | |
12629 | } | |
12630 | ||
136da414 | 12631 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
12632 | |
12633 | static unsigned | |
12634 | neon_qfloat_bits (unsigned imm) | |
12635 | { | |
136da414 | 12636 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
12637 | } |
12638 | ||
12639 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
12640 | the instruction. *OP is passed as the initial value of the op field, and | |
12641 | may be set to a different value depending on the constant (i.e. | |
12642 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
5f4273c7 | 12643 | MVN). If the immediate looks like a repeated pattern then also |
036dc3f7 | 12644 | try smaller element sizes. */ |
5287ad62 JB |
12645 | |
12646 | static int | |
c96612cc JB |
12647 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, |
12648 | unsigned *immbits, int *op, int size, | |
12649 | enum neon_el_type type) | |
5287ad62 | 12650 | { |
c96612cc JB |
12651 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is |
12652 | float. */ | |
12653 | if (type == NT_float && !float_p) | |
12654 | return FAIL; | |
12655 | ||
136da414 JB |
12656 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
12657 | { | |
12658 | if (size != 32 || *op == 1) | |
12659 | return FAIL; | |
12660 | *immbits = neon_qfloat_bits (immlo); | |
12661 | return 0xf; | |
12662 | } | |
036dc3f7 PB |
12663 | |
12664 | if (size == 64) | |
5287ad62 | 12665 | { |
036dc3f7 PB |
12666 | if (neon_bits_same_in_bytes (immhi) |
12667 | && neon_bits_same_in_bytes (immlo)) | |
12668 | { | |
12669 | if (*op == 1) | |
12670 | return FAIL; | |
12671 | *immbits = (neon_squash_bits (immhi) << 4) | |
12672 | | neon_squash_bits (immlo); | |
12673 | *op = 1; | |
12674 | return 0xe; | |
12675 | } | |
12676 | ||
12677 | if (immhi != immlo) | |
12678 | return FAIL; | |
5287ad62 | 12679 | } |
036dc3f7 PB |
12680 | |
12681 | if (size >= 32) | |
5287ad62 | 12682 | { |
036dc3f7 PB |
12683 | if (immlo == (immlo & 0x000000ff)) |
12684 | { | |
12685 | *immbits = immlo; | |
12686 | return 0x0; | |
12687 | } | |
12688 | else if (immlo == (immlo & 0x0000ff00)) | |
12689 | { | |
12690 | *immbits = immlo >> 8; | |
12691 | return 0x2; | |
12692 | } | |
12693 | else if (immlo == (immlo & 0x00ff0000)) | |
12694 | { | |
12695 | *immbits = immlo >> 16; | |
12696 | return 0x4; | |
12697 | } | |
12698 | else if (immlo == (immlo & 0xff000000)) | |
12699 | { | |
12700 | *immbits = immlo >> 24; | |
12701 | return 0x6; | |
12702 | } | |
12703 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
12704 | { | |
12705 | *immbits = (immlo >> 8) & 0xff; | |
12706 | return 0xc; | |
12707 | } | |
12708 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
12709 | { | |
12710 | *immbits = (immlo >> 16) & 0xff; | |
12711 | return 0xd; | |
12712 | } | |
12713 | ||
12714 | if ((immlo & 0xffff) != (immlo >> 16)) | |
12715 | return FAIL; | |
12716 | immlo &= 0xffff; | |
5287ad62 | 12717 | } |
036dc3f7 PB |
12718 | |
12719 | if (size >= 16) | |
5287ad62 | 12720 | { |
036dc3f7 PB |
12721 | if (immlo == (immlo & 0x000000ff)) |
12722 | { | |
12723 | *immbits = immlo; | |
12724 | return 0x8; | |
12725 | } | |
12726 | else if (immlo == (immlo & 0x0000ff00)) | |
12727 | { | |
12728 | *immbits = immlo >> 8; | |
12729 | return 0xa; | |
12730 | } | |
12731 | ||
12732 | if ((immlo & 0xff) != (immlo >> 8)) | |
12733 | return FAIL; | |
12734 | immlo &= 0xff; | |
5287ad62 | 12735 | } |
036dc3f7 PB |
12736 | |
12737 | if (immlo == (immlo & 0x000000ff)) | |
5287ad62 | 12738 | { |
036dc3f7 PB |
12739 | /* Don't allow MVN with 8-bit immediate. */ |
12740 | if (*op == 1) | |
12741 | return FAIL; | |
12742 | *immbits = immlo; | |
12743 | return 0xe; | |
5287ad62 | 12744 | } |
5287ad62 JB |
12745 | |
12746 | return FAIL; | |
12747 | } | |
12748 | ||
12749 | /* Write immediate bits [7:0] to the following locations: | |
12750 | ||
12751 | |28/24|23 19|18 16|15 4|3 0| | |
12752 | | 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| | |
12753 | ||
12754 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
12755 | ||
12756 | static void | |
12757 | neon_write_immbits (unsigned immbits) | |
12758 | { | |
12759 | inst.instruction |= immbits & 0xf; | |
12760 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
12761 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
12762 | } | |
12763 | ||
12764 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
12765 | ||
12766 | static void | |
12767 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
12768 | { | |
12769 | unsigned immlo = xlo ? *xlo : 0; | |
12770 | unsigned immhi = xhi ? *xhi : 0; | |
12771 | ||
12772 | switch (size) | |
12773 | { | |
12774 | case 8: | |
12775 | immlo = (~immlo) & 0xff; | |
12776 | break; | |
12777 | ||
12778 | case 16: | |
12779 | immlo = (~immlo) & 0xffff; | |
12780 | break; | |
12781 | ||
12782 | case 64: | |
12783 | immhi = (~immhi) & 0xffffffff; | |
12784 | /* fall through. */ | |
12785 | ||
12786 | case 32: | |
12787 | immlo = (~immlo) & 0xffffffff; | |
12788 | break; | |
12789 | ||
12790 | default: | |
12791 | abort (); | |
12792 | } | |
12793 | ||
12794 | if (xlo) | |
12795 | *xlo = immlo; | |
12796 | ||
12797 | if (xhi) | |
12798 | *xhi = immhi; | |
12799 | } | |
12800 | ||
12801 | static void | |
12802 | do_neon_logic (void) | |
12803 | { | |
12804 | if (inst.operands[2].present && inst.operands[2].isreg) | |
12805 | { | |
037e8744 | 12806 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12807 | neon_check_type (3, rs, N_IGNORE_TYPE); |
12808 | /* U bit and size field were set as part of the bitmask. */ | |
12809 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12810 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12811 | } |
12812 | else | |
12813 | { | |
037e8744 JB |
12814 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
12815 | struct neon_type_el et = neon_check_type (2, rs, | |
12816 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
21d799b5 | 12817 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
12818 | unsigned immbits; |
12819 | int cmode; | |
5f4273c7 | 12820 | |
5287ad62 JB |
12821 | if (et.type == NT_invtype) |
12822 | return; | |
5f4273c7 | 12823 | |
5287ad62 JB |
12824 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
12825 | ||
036dc3f7 PB |
12826 | immbits = inst.operands[1].imm; |
12827 | if (et.size == 64) | |
12828 | { | |
12829 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
12830 | pattern. */ | |
12831 | if (immbits != (inst.operands[1].regisimm ? | |
12832 | inst.operands[1].reg : 0)) | |
12833 | { | |
12834 | /* Set immbits to an invalid constant. */ | |
12835 | immbits = 0xdeadbeef; | |
12836 | } | |
12837 | } | |
12838 | ||
5287ad62 JB |
12839 | switch (opcode) |
12840 | { | |
12841 | case N_MNEM_vbic: | |
036dc3f7 | 12842 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 12843 | break; |
5f4273c7 | 12844 | |
5287ad62 | 12845 | case N_MNEM_vorr: |
036dc3f7 | 12846 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 12847 | break; |
5f4273c7 | 12848 | |
5287ad62 JB |
12849 | case N_MNEM_vand: |
12850 | /* Pseudo-instruction for VBIC. */ | |
5287ad62 JB |
12851 | neon_invert_size (&immbits, 0, et.size); |
12852 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
12853 | break; | |
5f4273c7 | 12854 | |
5287ad62 JB |
12855 | case N_MNEM_vorn: |
12856 | /* Pseudo-instruction for VORR. */ | |
5287ad62 JB |
12857 | neon_invert_size (&immbits, 0, et.size); |
12858 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
12859 | break; | |
5f4273c7 | 12860 | |
5287ad62 JB |
12861 | default: |
12862 | abort (); | |
12863 | } | |
12864 | ||
12865 | if (cmode == FAIL) | |
12866 | return; | |
12867 | ||
037e8744 | 12868 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12869 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
12870 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12871 | inst.instruction |= cmode << 8; | |
12872 | neon_write_immbits (immbits); | |
5f4273c7 | 12873 | |
5287ad62 JB |
12874 | inst.instruction = neon_dp_fixup (inst.instruction); |
12875 | } | |
12876 | } | |
12877 | ||
12878 | static void | |
12879 | do_neon_bitfield (void) | |
12880 | { | |
037e8744 | 12881 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 12882 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 12883 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12884 | } |
12885 | ||
12886 | static void | |
dcbf9037 JB |
12887 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
12888 | unsigned destbits) | |
5287ad62 | 12889 | { |
037e8744 | 12890 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
12891 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
12892 | types | N_KEY); | |
5287ad62 JB |
12893 | if (et.type == NT_float) |
12894 | { | |
12895 | inst.instruction = NEON_ENC_FLOAT (inst.instruction); | |
037e8744 | 12896 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12897 | } |
12898 | else | |
12899 | { | |
12900 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12901 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
12902 | } |
12903 | } | |
12904 | ||
12905 | static void | |
12906 | do_neon_dyadic_if_su (void) | |
12907 | { | |
dcbf9037 | 12908 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
12909 | } |
12910 | ||
12911 | static void | |
12912 | do_neon_dyadic_if_su_d (void) | |
12913 | { | |
12914 | /* This version only allow D registers, but that constraint is enforced during | |
12915 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 12916 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
12917 | } |
12918 | ||
5287ad62 JB |
12919 | static void |
12920 | do_neon_dyadic_if_i_d (void) | |
12921 | { | |
428e3f1f PB |
12922 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
12923 | affected if we specify unsigned args. */ | |
12924 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
12925 | } |
12926 | ||
037e8744 JB |
12927 | enum vfp_or_neon_is_neon_bits |
12928 | { | |
12929 | NEON_CHECK_CC = 1, | |
12930 | NEON_CHECK_ARCH = 2 | |
12931 | }; | |
12932 | ||
12933 | /* Call this function if an instruction which may have belonged to the VFP or | |
12934 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
12935 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
12936 | things: | |
12937 | ||
12938 | - Make sure the user hasn't attempted to make a Neon instruction | |
12939 | conditional. | |
12940 | - Alter the value in the condition code field if necessary. | |
12941 | - Make sure that the arch supports Neon instructions. | |
12942 | ||
12943 | Which of these operations take place depends on bits from enum | |
12944 | vfp_or_neon_is_neon_bits. | |
12945 | ||
12946 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
12947 | current instruction's condition is COND_ALWAYS, the condition field is | |
12948 | changed to inst.uncond_value. This is necessary because instructions shared | |
12949 | between VFP and Neon may be conditional for the VFP variants only, and the | |
12950 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
12951 | ||
12952 | static int | |
12953 | vfp_or_neon_is_neon (unsigned check) | |
12954 | { | |
12955 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
12956 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
12957 | { | |
12958 | if (inst.cond != COND_ALWAYS) | |
12959 | { | |
12960 | first_error (_(BAD_COND)); | |
12961 | return FAIL; | |
12962 | } | |
12963 | if (inst.uncond_value != -1) | |
12964 | inst.instruction |= inst.uncond_value << 28; | |
12965 | } | |
5f4273c7 | 12966 | |
037e8744 JB |
12967 | if ((check & NEON_CHECK_ARCH) |
12968 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
12969 | { | |
12970 | first_error (_(BAD_FPU)); | |
12971 | return FAIL; | |
12972 | } | |
5f4273c7 | 12973 | |
037e8744 JB |
12974 | return SUCCESS; |
12975 | } | |
12976 | ||
5287ad62 JB |
12977 | static void |
12978 | do_neon_addsub_if_i (void) | |
12979 | { | |
037e8744 JB |
12980 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
12981 | return; | |
12982 | ||
12983 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12984 | return; | |
12985 | ||
5287ad62 JB |
12986 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
12987 | affected if we specify unsigned args. */ | |
dcbf9037 | 12988 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
12989 | } |
12990 | ||
12991 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
12992 | result to be: | |
12993 | V<op> A,B (A is operand 0, B is operand 2) | |
12994 | to mean: | |
12995 | V<op> A,B,A | |
12996 | not: | |
12997 | V<op> A,B,B | |
12998 | so handle that case specially. */ | |
12999 | ||
13000 | static void | |
13001 | neon_exchange_operands (void) | |
13002 | { | |
13003 | void *scratch = alloca (sizeof (inst.operands[0])); | |
13004 | if (inst.operands[1].present) | |
13005 | { | |
13006 | /* Swap operands[1] and operands[2]. */ | |
13007 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
13008 | inst.operands[1] = inst.operands[2]; | |
13009 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
13010 | } | |
13011 | else | |
13012 | { | |
13013 | inst.operands[1] = inst.operands[2]; | |
13014 | inst.operands[2] = inst.operands[0]; | |
13015 | } | |
13016 | } | |
13017 | ||
13018 | static void | |
13019 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
13020 | { | |
13021 | if (inst.operands[2].isreg) | |
13022 | { | |
13023 | if (invert) | |
13024 | neon_exchange_operands (); | |
dcbf9037 | 13025 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
13026 | } |
13027 | else | |
13028 | { | |
037e8744 | 13029 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
13030 | struct neon_type_el et = neon_check_type (2, rs, |
13031 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 JB |
13032 | |
13033 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13034 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13035 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13036 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13037 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13038 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13039 | inst.instruction |= (et.type == NT_float) << 10; |
13040 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13041 | |
5287ad62 JB |
13042 | inst.instruction = neon_dp_fixup (inst.instruction); |
13043 | } | |
13044 | } | |
13045 | ||
13046 | static void | |
13047 | do_neon_cmp (void) | |
13048 | { | |
13049 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
13050 | } | |
13051 | ||
13052 | static void | |
13053 | do_neon_cmp_inv (void) | |
13054 | { | |
13055 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
13056 | } | |
13057 | ||
13058 | static void | |
13059 | do_neon_ceq (void) | |
13060 | { | |
13061 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
13062 | } | |
13063 | ||
13064 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
13065 | scalars, which are encoded in 5 bits, M : Rm. | |
13066 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
13067 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
13068 | index in M. */ | |
13069 | ||
13070 | static unsigned | |
13071 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
13072 | { | |
dcbf9037 JB |
13073 | unsigned regno = NEON_SCALAR_REG (scalar); |
13074 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
13075 | |
13076 | switch (elsize) | |
13077 | { | |
13078 | case 16: | |
13079 | if (regno > 7 || elno > 3) | |
13080 | goto bad_scalar; | |
13081 | return regno | (elno << 3); | |
5f4273c7 | 13082 | |
5287ad62 JB |
13083 | case 32: |
13084 | if (regno > 15 || elno > 1) | |
13085 | goto bad_scalar; | |
13086 | return regno | (elno << 4); | |
13087 | ||
13088 | default: | |
13089 | bad_scalar: | |
dcbf9037 | 13090 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
13091 | } |
13092 | ||
13093 | return 0; | |
13094 | } | |
13095 | ||
13096 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
13097 | ||
13098 | static void | |
13099 | neon_mul_mac (struct neon_type_el et, int ubit) | |
13100 | { | |
dcbf9037 JB |
13101 | unsigned scalar; |
13102 | ||
13103 | /* Give a more helpful error message if we have an invalid type. */ | |
13104 | if (et.type == NT_invtype) | |
13105 | return; | |
5f4273c7 | 13106 | |
dcbf9037 | 13107 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
13108 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13109 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13110 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13111 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13112 | inst.instruction |= LOW4 (scalar); | |
13113 | inst.instruction |= HI1 (scalar) << 5; | |
13114 | inst.instruction |= (et.type == NT_float) << 8; | |
13115 | inst.instruction |= neon_logbits (et.size) << 20; | |
13116 | inst.instruction |= (ubit != 0) << 24; | |
13117 | ||
13118 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13119 | } | |
13120 | ||
13121 | static void | |
13122 | do_neon_mac_maybe_scalar (void) | |
13123 | { | |
037e8744 JB |
13124 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
13125 | return; | |
13126 | ||
13127 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13128 | return; | |
13129 | ||
5287ad62 JB |
13130 | if (inst.operands[2].isscalar) |
13131 | { | |
037e8744 | 13132 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13133 | struct neon_type_el et = neon_check_type (3, rs, |
13134 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
13135 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 13136 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13137 | } |
13138 | else | |
428e3f1f PB |
13139 | { |
13140 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
13141 | affected if we specify unsigned args. */ | |
13142 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
13143 | } | |
5287ad62 JB |
13144 | } |
13145 | ||
62f3b8c8 PB |
13146 | static void |
13147 | do_neon_fmac (void) | |
13148 | { | |
13149 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
13150 | return; | |
13151 | ||
13152 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13153 | return; | |
13154 | ||
13155 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
13156 | } | |
13157 | ||
5287ad62 JB |
13158 | static void |
13159 | do_neon_tst (void) | |
13160 | { | |
037e8744 | 13161 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13162 | struct neon_type_el et = neon_check_type (3, rs, |
13163 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 13164 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13165 | } |
13166 | ||
13167 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
13168 | same types as the MAC equivalents. The polynomial type for this instruction | |
13169 | is encoded the same as the integer type. */ | |
13170 | ||
13171 | static void | |
13172 | do_neon_mul (void) | |
13173 | { | |
037e8744 JB |
13174 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
13175 | return; | |
13176 | ||
13177 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13178 | return; | |
13179 | ||
5287ad62 JB |
13180 | if (inst.operands[2].isscalar) |
13181 | do_neon_mac_maybe_scalar (); | |
13182 | else | |
dcbf9037 | 13183 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
13184 | } |
13185 | ||
13186 | static void | |
13187 | do_neon_qdmulh (void) | |
13188 | { | |
13189 | if (inst.operands[2].isscalar) | |
13190 | { | |
037e8744 | 13191 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13192 | struct neon_type_el et = neon_check_type (3, rs, |
13193 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
13194 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 13195 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13196 | } |
13197 | else | |
13198 | { | |
037e8744 | 13199 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13200 | struct neon_type_el et = neon_check_type (3, rs, |
13201 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
13202 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13203 | /* The U bit (rounding) comes from bit mask. */ | |
037e8744 | 13204 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13205 | } |
13206 | } | |
13207 | ||
13208 | static void | |
13209 | do_neon_fcmp_absolute (void) | |
13210 | { | |
037e8744 | 13211 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13212 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
13213 | /* Size field comes from bit mask. */ | |
037e8744 | 13214 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
13215 | } |
13216 | ||
13217 | static void | |
13218 | do_neon_fcmp_absolute_inv (void) | |
13219 | { | |
13220 | neon_exchange_operands (); | |
13221 | do_neon_fcmp_absolute (); | |
13222 | } | |
13223 | ||
13224 | static void | |
13225 | do_neon_step (void) | |
13226 | { | |
037e8744 | 13227 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 13228 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 13229 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13230 | } |
13231 | ||
13232 | static void | |
13233 | do_neon_abs_neg (void) | |
13234 | { | |
037e8744 JB |
13235 | enum neon_shape rs; |
13236 | struct neon_type_el et; | |
5f4273c7 | 13237 | |
037e8744 JB |
13238 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
13239 | return; | |
13240 | ||
13241 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13242 | return; | |
13243 | ||
13244 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
13245 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
5f4273c7 | 13246 | |
5287ad62 JB |
13247 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13248 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13249 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13250 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13251 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13252 | inst.instruction |= (et.type == NT_float) << 10; |
13253 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13254 | |
5287ad62 JB |
13255 | inst.instruction = neon_dp_fixup (inst.instruction); |
13256 | } | |
13257 | ||
13258 | static void | |
13259 | do_neon_sli (void) | |
13260 | { | |
037e8744 | 13261 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13262 | struct neon_type_el et = neon_check_type (2, rs, |
13263 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13264 | int imm = inst.operands[2].imm; | |
13265 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13266 | _("immediate out of range for insert")); | |
037e8744 | 13267 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13268 | } |
13269 | ||
13270 | static void | |
13271 | do_neon_sri (void) | |
13272 | { | |
037e8744 | 13273 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13274 | struct neon_type_el et = neon_check_type (2, rs, |
13275 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13276 | int imm = inst.operands[2].imm; | |
13277 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13278 | _("immediate out of range for insert")); | |
037e8744 | 13279 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
13280 | } |
13281 | ||
13282 | static void | |
13283 | do_neon_qshlu_imm (void) | |
13284 | { | |
037e8744 | 13285 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13286 | struct neon_type_el et = neon_check_type (2, rs, |
13287 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
13288 | int imm = inst.operands[2].imm; | |
13289 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13290 | _("immediate out of range for shift")); | |
13291 | /* Only encodes the 'U present' variant of the instruction. | |
13292 | In this case, signed types have OP (bit 8) set to 0. | |
13293 | Unsigned types have OP set to 1. */ | |
13294 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
13295 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 13296 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13297 | } |
13298 | ||
13299 | static void | |
13300 | do_neon_qmovn (void) | |
13301 | { | |
13302 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13303 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13304 | /* Saturating move where operands can be signed or unsigned, and the | |
13305 | destination has the same signedness. */ | |
13306 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13307 | if (et.type == NT_unsigned) | |
13308 | inst.instruction |= 0xc0; | |
13309 | else | |
13310 | inst.instruction |= 0x80; | |
13311 | neon_two_same (0, 1, et.size / 2); | |
13312 | } | |
13313 | ||
13314 | static void | |
13315 | do_neon_qmovun (void) | |
13316 | { | |
13317 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13318 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13319 | /* Saturating move with unsigned results. Operands must be signed. */ | |
13320 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13321 | neon_two_same (0, 1, et.size / 2); | |
13322 | } | |
13323 | ||
13324 | static void | |
13325 | do_neon_rshift_sat_narrow (void) | |
13326 | { | |
13327 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13328 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13329 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13330 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13331 | int imm = inst.operands[2].imm; | |
13332 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13333 | right. */ | |
13334 | et.size /= 2; | |
5f4273c7 | 13335 | |
5287ad62 JB |
13336 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
13337 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
13338 | if (imm == 0) | |
13339 | { | |
13340 | inst.operands[2].present = 0; | |
13341 | inst.instruction = N_MNEM_vqmovn; | |
13342 | do_neon_qmovn (); | |
13343 | return; | |
13344 | } | |
5f4273c7 | 13345 | |
5287ad62 JB |
13346 | constraint (imm < 1 || (unsigned)imm > et.size, |
13347 | _("immediate out of range")); | |
13348 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
13349 | } | |
13350 | ||
13351 | static void | |
13352 | do_neon_rshift_sat_narrow_u (void) | |
13353 | { | |
13354 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13355 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13356 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13357 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13358 | int imm = inst.operands[2].imm; | |
13359 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13360 | right. */ | |
13361 | et.size /= 2; | |
13362 | ||
13363 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
13364 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
13365 | if (imm == 0) | |
13366 | { | |
13367 | inst.operands[2].present = 0; | |
13368 | inst.instruction = N_MNEM_vqmovun; | |
13369 | do_neon_qmovun (); | |
13370 | return; | |
13371 | } | |
13372 | ||
13373 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13374 | _("immediate out of range")); | |
13375 | /* FIXME: The manual is kind of unclear about what value U should have in | |
13376 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
13377 | must be 1. */ | |
13378 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
13379 | } | |
13380 | ||
13381 | static void | |
13382 | do_neon_movn (void) | |
13383 | { | |
13384 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13385 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13386 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13387 | neon_two_same (0, 1, et.size / 2); | |
13388 | } | |
13389 | ||
13390 | static void | |
13391 | do_neon_rshift_narrow (void) | |
13392 | { | |
13393 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13394 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13395 | int imm = inst.operands[2].imm; | |
13396 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13397 | right. */ | |
13398 | et.size /= 2; | |
5f4273c7 | 13399 | |
5287ad62 JB |
13400 | /* If immediate is zero then we are a pseudo-instruction for |
13401 | VMOVN.I<size> <Dd>, <Qm> */ | |
13402 | if (imm == 0) | |
13403 | { | |
13404 | inst.operands[2].present = 0; | |
13405 | inst.instruction = N_MNEM_vmovn; | |
13406 | do_neon_movn (); | |
13407 | return; | |
13408 | } | |
5f4273c7 | 13409 | |
5287ad62 JB |
13410 | constraint (imm < 1 || (unsigned)imm > et.size, |
13411 | _("immediate out of range for narrowing operation")); | |
13412 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
13413 | } | |
13414 | ||
13415 | static void | |
13416 | do_neon_shll (void) | |
13417 | { | |
13418 | /* FIXME: Type checking when lengthening. */ | |
13419 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
13420 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
13421 | unsigned imm = inst.operands[2].imm; | |
13422 | ||
13423 | if (imm == et.size) | |
13424 | { | |
13425 | /* Maximum shift variant. */ | |
13426 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13427 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13428 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13429 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13430 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13431 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13432 | |
5287ad62 JB |
13433 | inst.instruction = neon_dp_fixup (inst.instruction); |
13434 | } | |
13435 | else | |
13436 | { | |
13437 | /* A more-specific type check for non-max versions. */ | |
13438 | et = neon_check_type (2, NS_QDI, | |
13439 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13440 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13441 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); | |
13442 | } | |
13443 | } | |
13444 | ||
037e8744 | 13445 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
13446 | the current instruction is. */ |
13447 | ||
13448 | static int | |
13449 | neon_cvt_flavour (enum neon_shape rs) | |
13450 | { | |
037e8744 JB |
13451 | #define CVT_VAR(C,X,Y) \ |
13452 | et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \ | |
13453 | if (et.type != NT_invtype) \ | |
13454 | { \ | |
13455 | inst.error = NULL; \ | |
13456 | return (C); \ | |
5287ad62 JB |
13457 | } |
13458 | struct neon_type_el et; | |
037e8744 JB |
13459 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
13460 | || rs == NS_FF) ? N_VFP : 0; | |
13461 | /* The instruction versions which take an immediate take one register | |
13462 | argument, which is extended to the width of the full register. Thus the | |
13463 | "source" and "destination" registers must have the same width. Hack that | |
13464 | here by making the size equal to the key (wider, in this case) operand. */ | |
13465 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 13466 | |
5287ad62 JB |
13467 | CVT_VAR (0, N_S32, N_F32); |
13468 | CVT_VAR (1, N_U32, N_F32); | |
13469 | CVT_VAR (2, N_F32, N_S32); | |
13470 | CVT_VAR (3, N_F32, N_U32); | |
8e79c3df CM |
13471 | /* Half-precision conversions. */ |
13472 | CVT_VAR (4, N_F32, N_F16); | |
13473 | CVT_VAR (5, N_F16, N_F32); | |
5f4273c7 | 13474 | |
037e8744 | 13475 | whole_reg = N_VFP; |
5f4273c7 | 13476 | |
037e8744 | 13477 | /* VFP instructions. */ |
8e79c3df CM |
13478 | CVT_VAR (6, N_F32, N_F64); |
13479 | CVT_VAR (7, N_F64, N_F32); | |
13480 | CVT_VAR (8, N_S32, N_F64 | key); | |
13481 | CVT_VAR (9, N_U32, N_F64 | key); | |
13482 | CVT_VAR (10, N_F64 | key, N_S32); | |
13483 | CVT_VAR (11, N_F64 | key, N_U32); | |
037e8744 | 13484 | /* VFP instructions with bitshift. */ |
8e79c3df CM |
13485 | CVT_VAR (12, N_F32 | key, N_S16); |
13486 | CVT_VAR (13, N_F32 | key, N_U16); | |
13487 | CVT_VAR (14, N_F64 | key, N_S16); | |
13488 | CVT_VAR (15, N_F64 | key, N_U16); | |
13489 | CVT_VAR (16, N_S16, N_F32 | key); | |
13490 | CVT_VAR (17, N_U16, N_F32 | key); | |
13491 | CVT_VAR (18, N_S16, N_F64 | key); | |
13492 | CVT_VAR (19, N_U16, N_F64 | key); | |
5f4273c7 | 13493 | |
5287ad62 JB |
13494 | return -1; |
13495 | #undef CVT_VAR | |
13496 | } | |
13497 | ||
037e8744 JB |
13498 | /* Neon-syntax VFP conversions. */ |
13499 | ||
5287ad62 | 13500 | static void |
037e8744 | 13501 | do_vfp_nsyn_cvt (enum neon_shape rs, int flavour) |
5287ad62 | 13502 | { |
037e8744 | 13503 | const char *opname = 0; |
5f4273c7 | 13504 | |
037e8744 | 13505 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) |
5287ad62 | 13506 | { |
037e8744 JB |
13507 | /* Conversions with immediate bitshift. */ |
13508 | const char *enc[] = | |
13509 | { | |
13510 | "ftosls", | |
13511 | "ftouls", | |
13512 | "fsltos", | |
13513 | "fultos", | |
13514 | NULL, | |
13515 | NULL, | |
8e79c3df CM |
13516 | NULL, |
13517 | NULL, | |
037e8744 JB |
13518 | "ftosld", |
13519 | "ftould", | |
13520 | "fsltod", | |
13521 | "fultod", | |
13522 | "fshtos", | |
13523 | "fuhtos", | |
13524 | "fshtod", | |
13525 | "fuhtod", | |
13526 | "ftoshs", | |
13527 | "ftouhs", | |
13528 | "ftoshd", | |
13529 | "ftouhd" | |
13530 | }; | |
13531 | ||
13532 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13533 | { | |
13534 | opname = enc[flavour]; | |
13535 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13536 | _("operands 0 and 1 must be the same register")); | |
13537 | inst.operands[1] = inst.operands[2]; | |
13538 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
13539 | } | |
5287ad62 JB |
13540 | } |
13541 | else | |
13542 | { | |
037e8744 JB |
13543 | /* Conversions without bitshift. */ |
13544 | const char *enc[] = | |
13545 | { | |
13546 | "ftosis", | |
13547 | "ftouis", | |
13548 | "fsitos", | |
13549 | "fuitos", | |
8e79c3df CM |
13550 | "NULL", |
13551 | "NULL", | |
037e8744 JB |
13552 | "fcvtsd", |
13553 | "fcvtds", | |
13554 | "ftosid", | |
13555 | "ftouid", | |
13556 | "fsitod", | |
13557 | "fuitod" | |
13558 | }; | |
13559 | ||
13560 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13561 | opname = enc[flavour]; | |
13562 | } | |
13563 | ||
13564 | if (opname) | |
13565 | do_vfp_nsyn_opcode (opname); | |
13566 | } | |
13567 | ||
13568 | static void | |
13569 | do_vfp_nsyn_cvtz (void) | |
13570 | { | |
13571 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
13572 | int flavour = neon_cvt_flavour (rs); | |
13573 | const char *enc[] = | |
13574 | { | |
13575 | "ftosizs", | |
13576 | "ftouizs", | |
13577 | NULL, | |
13578 | NULL, | |
13579 | NULL, | |
13580 | NULL, | |
8e79c3df CM |
13581 | NULL, |
13582 | NULL, | |
037e8744 JB |
13583 | "ftosizd", |
13584 | "ftouizd" | |
13585 | }; | |
13586 | ||
13587 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) | |
13588 | do_vfp_nsyn_opcode (enc[flavour]); | |
13589 | } | |
f31fef98 | 13590 | |
037e8744 JB |
13591 | static void |
13592 | do_neon_cvt (void) | |
13593 | { | |
13594 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
8e79c3df | 13595 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL); |
037e8744 JB |
13596 | int flavour = neon_cvt_flavour (rs); |
13597 | ||
13598 | /* VFP rather than Neon conversions. */ | |
8e79c3df | 13599 | if (flavour >= 6) |
037e8744 JB |
13600 | { |
13601 | do_vfp_nsyn_cvt (rs, flavour); | |
13602 | return; | |
13603 | } | |
13604 | ||
13605 | switch (rs) | |
13606 | { | |
13607 | case NS_DDI: | |
13608 | case NS_QQI: | |
13609 | { | |
35997600 NC |
13610 | unsigned immbits; |
13611 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
13612 | ||
037e8744 JB |
13613 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
13614 | return; | |
13615 | ||
13616 | /* Fixed-point conversion with #0 immediate is encoded as an | |
13617 | integer conversion. */ | |
13618 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
13619 | goto int_encode; | |
35997600 | 13620 | immbits = 32 - inst.operands[2].imm; |
037e8744 JB |
13621 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
13622 | if (flavour != -1) | |
13623 | inst.instruction |= enctab[flavour]; | |
13624 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13625 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13626 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13627 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13628 | inst.instruction |= neon_quad (rs) << 6; | |
13629 | inst.instruction |= 1 << 21; | |
13630 | inst.instruction |= immbits << 16; | |
13631 | ||
13632 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13633 | } | |
13634 | break; | |
13635 | ||
13636 | case NS_DD: | |
13637 | case NS_QQ: | |
13638 | int_encode: | |
13639 | { | |
13640 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
13641 | ||
13642 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13643 | ||
13644 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13645 | return; | |
13646 | ||
13647 | if (flavour != -1) | |
13648 | inst.instruction |= enctab[flavour]; | |
13649 | ||
13650 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13651 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13652 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13653 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13654 | inst.instruction |= neon_quad (rs) << 6; | |
13655 | inst.instruction |= 2 << 18; | |
13656 | ||
13657 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13658 | } | |
13659 | break; | |
13660 | ||
8e79c3df CM |
13661 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
13662 | case NS_QD: | |
13663 | case NS_DQ: | |
13664 | ||
13665 | if ((rs == NS_DQ) | |
13666 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
13667 | { | |
13668 | as_bad (_("operand size must match register width")); | |
13669 | break; | |
13670 | } | |
13671 | ||
13672 | if ((rs == NS_QD) | |
13673 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
13674 | { | |
13675 | as_bad (_("operand size must match register width")); | |
13676 | break; | |
13677 | } | |
13678 | ||
13679 | if (rs == NS_DQ) | |
13680 | inst.instruction = 0x3b60600; | |
13681 | else | |
13682 | inst.instruction = 0x3b60700; | |
13683 | ||
13684 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13685 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13686 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13687 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13688 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13689 | break; | |
13690 | ||
037e8744 JB |
13691 | default: |
13692 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
13693 | do_vfp_nsyn_cvt (rs, flavour); | |
5287ad62 | 13694 | } |
5287ad62 JB |
13695 | } |
13696 | ||
8e79c3df CM |
13697 | static void |
13698 | do_neon_cvtb (void) | |
13699 | { | |
13700 | inst.instruction = 0xeb20a40; | |
13701 | ||
13702 | /* The sizes are attached to the mnemonic. */ | |
13703 | if (inst.vectype.el[0].type != NT_invtype | |
13704 | && inst.vectype.el[0].size == 16) | |
13705 | inst.instruction |= 0x00010000; | |
13706 | ||
13707 | /* Programmer's syntax: the sizes are attached to the operands. */ | |
13708 | else if (inst.operands[0].vectype.type != NT_invtype | |
13709 | && inst.operands[0].vectype.size == 16) | |
13710 | inst.instruction |= 0x00010000; | |
13711 | ||
13712 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
13713 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
13714 | do_vfp_cond_or_thumb (); | |
13715 | } | |
13716 | ||
13717 | ||
13718 | static void | |
13719 | do_neon_cvtt (void) | |
13720 | { | |
13721 | do_neon_cvtb (); | |
13722 | inst.instruction |= 0x80; | |
13723 | } | |
13724 | ||
5287ad62 JB |
13725 | static void |
13726 | neon_move_immediate (void) | |
13727 | { | |
037e8744 JB |
13728 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
13729 | struct neon_type_el et = neon_check_type (2, rs, | |
13730 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 13731 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 13732 | int op, cmode, float_p; |
5287ad62 | 13733 | |
037e8744 JB |
13734 | constraint (et.type == NT_invtype, |
13735 | _("operand size must be specified for immediate VMOV")); | |
13736 | ||
5287ad62 JB |
13737 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
13738 | op = (inst.instruction & (1 << 5)) != 0; | |
13739 | ||
13740 | immlo = inst.operands[1].imm; | |
13741 | if (inst.operands[1].regisimm) | |
13742 | immhi = inst.operands[1].reg; | |
13743 | ||
13744 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
13745 | _("immediate has bits set outside the operand size")); | |
13746 | ||
c96612cc JB |
13747 | float_p = inst.operands[1].immisfloat; |
13748 | ||
13749 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
136da414 | 13750 | et.size, et.type)) == FAIL) |
5287ad62 JB |
13751 | { |
13752 | /* Invert relevant bits only. */ | |
13753 | neon_invert_size (&immlo, &immhi, et.size); | |
13754 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
13755 | with one or the other; those cases are caught by | |
13756 | neon_cmode_for_move_imm. */ | |
13757 | op = !op; | |
c96612cc JB |
13758 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
13759 | &op, et.size, et.type)) == FAIL) | |
5287ad62 | 13760 | { |
dcbf9037 | 13761 | first_error (_("immediate out of range")); |
5287ad62 JB |
13762 | return; |
13763 | } | |
13764 | } | |
13765 | ||
13766 | inst.instruction &= ~(1 << 5); | |
13767 | inst.instruction |= op << 5; | |
13768 | ||
13769 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13770 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 13771 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13772 | inst.instruction |= cmode << 8; |
13773 | ||
13774 | neon_write_immbits (immbits); | |
13775 | } | |
13776 | ||
13777 | static void | |
13778 | do_neon_mvn (void) | |
13779 | { | |
13780 | if (inst.operands[1].isreg) | |
13781 | { | |
037e8744 | 13782 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 13783 | |
5287ad62 JB |
13784 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
13785 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13786 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13787 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13788 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13789 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13790 | } |
13791 | else | |
13792 | { | |
13793 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13794 | neon_move_immediate (); | |
13795 | } | |
13796 | ||
13797 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13798 | } | |
13799 | ||
13800 | /* Encode instructions of form: | |
13801 | ||
13802 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 13803 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
13804 | |
13805 | static void | |
13806 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
13807 | { | |
13808 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13809 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13810 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13811 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13812 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13813 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
13814 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
13815 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 13816 | |
5287ad62 JB |
13817 | inst.instruction = neon_dp_fixup (inst.instruction); |
13818 | } | |
13819 | ||
13820 | static void | |
13821 | do_neon_dyadic_long (void) | |
13822 | { | |
13823 | /* FIXME: Type checking for lengthening op. */ | |
13824 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13825 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
13826 | neon_mixed_length (et, et.size); | |
13827 | } | |
13828 | ||
13829 | static void | |
13830 | do_neon_abal (void) | |
13831 | { | |
13832 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13833 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
13834 | neon_mixed_length (et, et.size); | |
13835 | } | |
13836 | ||
13837 | static void | |
13838 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
13839 | { | |
13840 | if (inst.operands[2].isscalar) | |
13841 | { | |
dcbf9037 JB |
13842 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
13843 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
5287ad62 JB |
13844 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
13845 | neon_mul_mac (et, et.type == NT_unsigned); | |
13846 | } | |
13847 | else | |
13848 | { | |
13849 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13850 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
13851 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13852 | neon_mixed_length (et, et.size); | |
13853 | } | |
13854 | } | |
13855 | ||
13856 | static void | |
13857 | do_neon_mac_maybe_scalar_long (void) | |
13858 | { | |
13859 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
13860 | } | |
13861 | ||
13862 | static void | |
13863 | do_neon_dyadic_wide (void) | |
13864 | { | |
13865 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
13866 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13867 | neon_mixed_length (et, et.size); | |
13868 | } | |
13869 | ||
13870 | static void | |
13871 | do_neon_dyadic_narrow (void) | |
13872 | { | |
13873 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13874 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
13875 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
13876 | so force the operand type to integer. */ | |
13877 | et.type = NT_integer; | |
5287ad62 JB |
13878 | neon_mixed_length (et, et.size / 2); |
13879 | } | |
13880 | ||
13881 | static void | |
13882 | do_neon_mul_sat_scalar_long (void) | |
13883 | { | |
13884 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
13885 | } | |
13886 | ||
13887 | static void | |
13888 | do_neon_vmull (void) | |
13889 | { | |
13890 | if (inst.operands[2].isscalar) | |
13891 | do_neon_mac_maybe_scalar_long (); | |
13892 | else | |
13893 | { | |
13894 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13895 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY); | |
13896 | if (et.type == NT_poly) | |
13897 | inst.instruction = NEON_ENC_POLY (inst.instruction); | |
13898 | else | |
13899 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13900 | /* For polynomial encoding, size field must be 0b00 and the U bit must be | |
13901 | zero. Should be OK as-is. */ | |
13902 | neon_mixed_length (et, et.size); | |
13903 | } | |
13904 | } | |
13905 | ||
13906 | static void | |
13907 | do_neon_ext (void) | |
13908 | { | |
037e8744 | 13909 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
13910 | struct neon_type_el et = neon_check_type (3, rs, |
13911 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13912 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
13913 | |
13914 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
13915 | _("shift out of range")); | |
5287ad62 JB |
13916 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13917 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13918 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13919 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13920 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13921 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 13922 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 13923 | inst.instruction |= imm << 8; |
5f4273c7 | 13924 | |
5287ad62 JB |
13925 | inst.instruction = neon_dp_fixup (inst.instruction); |
13926 | } | |
13927 | ||
13928 | static void | |
13929 | do_neon_rev (void) | |
13930 | { | |
037e8744 | 13931 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13932 | struct neon_type_el et = neon_check_type (2, rs, |
13933 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
13934 | unsigned op = (inst.instruction >> 7) & 3; | |
13935 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
13936 | extract it here to check the elements to be reversed are smaller. | |
13937 | Otherwise we'd get a reserved instruction. */ | |
13938 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 13939 | gas_assert (elsize != 0); |
5287ad62 JB |
13940 | constraint (et.size >= elsize, |
13941 | _("elements must be smaller than reversal region")); | |
037e8744 | 13942 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13943 | } |
13944 | ||
13945 | static void | |
13946 | do_neon_dup (void) | |
13947 | { | |
13948 | if (inst.operands[1].isscalar) | |
13949 | { | |
037e8744 | 13950 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
13951 | struct neon_type_el et = neon_check_type (2, rs, |
13952 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 13953 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 13954 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 13955 | int logsize = neon_logbits (et.size); |
dcbf9037 | 13956 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
13957 | |
13958 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
13959 | return; | |
13960 | ||
5287ad62 JB |
13961 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
13962 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13963 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13964 | inst.instruction |= LOW4 (dm); | |
13965 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 13966 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13967 | inst.instruction |= x << 17; |
13968 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 13969 | |
5287ad62 JB |
13970 | inst.instruction = neon_dp_fixup (inst.instruction); |
13971 | } | |
13972 | else | |
13973 | { | |
037e8744 JB |
13974 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
13975 | struct neon_type_el et = neon_check_type (2, rs, | |
13976 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 JB |
13977 | /* Duplicate ARM register to lanes of vector. */ |
13978 | inst.instruction = NEON_ENC_ARMREG (inst.instruction); | |
13979 | switch (et.size) | |
13980 | { | |
13981 | case 8: inst.instruction |= 0x400000; break; | |
13982 | case 16: inst.instruction |= 0x000020; break; | |
13983 | case 32: inst.instruction |= 0x000000; break; | |
13984 | default: break; | |
13985 | } | |
13986 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
13987 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
13988 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 13989 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
13990 | /* The encoding for this instruction is identical for the ARM and Thumb |
13991 | variants, except for the condition field. */ | |
037e8744 | 13992 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
13993 | } |
13994 | } | |
13995 | ||
13996 | /* VMOV has particularly many variations. It can be one of: | |
13997 | 0. VMOV<c><q> <Qd>, <Qm> | |
13998 | 1. VMOV<c><q> <Dd>, <Dm> | |
13999 | (Register operations, which are VORR with Rm = Rn.) | |
14000 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
14001 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
14002 | (Immediate loads.) | |
14003 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
14004 | (ARM register to scalar.) | |
14005 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
14006 | (Two ARM registers to vector.) | |
14007 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
14008 | (Scalar to ARM register.) | |
14009 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
14010 | (Vector to two ARM registers.) | |
037e8744 JB |
14011 | 8. VMOV.F32 <Sd>, <Sm> |
14012 | 9. VMOV.F64 <Dd>, <Dm> | |
14013 | (VFP register moves.) | |
14014 | 10. VMOV.F32 <Sd>, #imm | |
14015 | 11. VMOV.F64 <Dd>, #imm | |
14016 | (VFP float immediate load.) | |
14017 | 12. VMOV <Rd>, <Sm> | |
14018 | (VFP single to ARM reg.) | |
14019 | 13. VMOV <Sd>, <Rm> | |
14020 | (ARM reg to VFP single.) | |
14021 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
14022 | (Two ARM regs to two VFP singles.) | |
14023 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
14024 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 14025 | |
037e8744 JB |
14026 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
14027 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 14028 | |
5287ad62 | 14029 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 14030 | |
b7fc2769 JB |
14031 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
14032 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 14033 | |
5287ad62 | 14034 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 14035 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
14036 | |
14037 | static void | |
14038 | do_neon_mov (void) | |
14039 | { | |
037e8744 JB |
14040 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
14041 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
14042 | NS_NULL); | |
14043 | struct neon_type_el et; | |
14044 | const char *ldconst = 0; | |
5287ad62 | 14045 | |
037e8744 | 14046 | switch (rs) |
5287ad62 | 14047 | { |
037e8744 JB |
14048 | case NS_DD: /* case 1/9. */ |
14049 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
14050 | /* It is not an error here if no type is given. */ | |
14051 | inst.error = NULL; | |
14052 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 14053 | { |
037e8744 JB |
14054 | do_vfp_nsyn_opcode ("fcpyd"); |
14055 | break; | |
5287ad62 | 14056 | } |
037e8744 | 14057 | /* fall through. */ |
5287ad62 | 14058 | |
037e8744 JB |
14059 | case NS_QQ: /* case 0/1. */ |
14060 | { | |
14061 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14062 | return; | |
14063 | /* The architecture manual I have doesn't explicitly state which | |
14064 | value the U bit should have for register->register moves, but | |
14065 | the equivalent VORR instruction has U = 0, so do that. */ | |
14066 | inst.instruction = 0x0200110; | |
14067 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14068 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14069 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14070 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14071 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14072 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14073 | inst.instruction |= neon_quad (rs) << 6; | |
14074 | ||
14075 | inst.instruction = neon_dp_fixup (inst.instruction); | |
14076 | } | |
14077 | break; | |
5f4273c7 | 14078 | |
037e8744 JB |
14079 | case NS_DI: /* case 3/11. */ |
14080 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
14081 | inst.error = NULL; | |
14082 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 14083 | { |
037e8744 JB |
14084 | /* case 11 (fconstd). */ |
14085 | ldconst = "fconstd"; | |
14086 | goto encode_fconstd; | |
5287ad62 | 14087 | } |
037e8744 JB |
14088 | /* fall through. */ |
14089 | ||
14090 | case NS_QI: /* case 2/3. */ | |
14091 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14092 | return; | |
14093 | inst.instruction = 0x0800010; | |
14094 | neon_move_immediate (); | |
14095 | inst.instruction = neon_dp_fixup (inst.instruction); | |
5287ad62 | 14096 | break; |
5f4273c7 | 14097 | |
037e8744 JB |
14098 | case NS_SR: /* case 4. */ |
14099 | { | |
14100 | unsigned bcdebits = 0; | |
14101 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
14102 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
14103 | int logsize = neon_logbits (et.size); | |
14104 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
14105 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
14106 | ||
14107 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
14108 | _(BAD_FPU)); | |
14109 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14110 | && et.size != 32, _(BAD_FPU)); | |
14111 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14112 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14113 | ||
14114 | switch (et.size) | |
14115 | { | |
14116 | case 8: bcdebits = 0x8; break; | |
14117 | case 16: bcdebits = 0x1; break; | |
14118 | case 32: bcdebits = 0x0; break; | |
14119 | default: ; | |
14120 | } | |
14121 | ||
14122 | bcdebits |= x << logsize; | |
14123 | ||
14124 | inst.instruction = 0xe000b10; | |
14125 | do_vfp_cond_or_thumb (); | |
14126 | inst.instruction |= LOW4 (dn) << 16; | |
14127 | inst.instruction |= HI1 (dn) << 7; | |
14128 | inst.instruction |= inst.operands[1].reg << 12; | |
14129 | inst.instruction |= (bcdebits & 3) << 5; | |
14130 | inst.instruction |= (bcdebits >> 2) << 21; | |
14131 | } | |
14132 | break; | |
5f4273c7 | 14133 | |
037e8744 | 14134 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 14135 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 14136 | _(BAD_FPU)); |
b7fc2769 | 14137 | |
037e8744 JB |
14138 | inst.instruction = 0xc400b10; |
14139 | do_vfp_cond_or_thumb (); | |
14140 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
14141 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
14142 | inst.instruction |= inst.operands[1].reg << 12; | |
14143 | inst.instruction |= inst.operands[2].reg << 16; | |
14144 | break; | |
5f4273c7 | 14145 | |
037e8744 JB |
14146 | case NS_RS: /* case 6. */ |
14147 | { | |
14148 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
14149 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
14150 | unsigned logsize = neon_logbits (et.size); | |
14151 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
14152 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
14153 | unsigned abcdebits = 0; | |
14154 | ||
14155 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
14156 | _(BAD_FPU)); | |
14157 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14158 | && et.size != 32, _(BAD_FPU)); | |
14159 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14160 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14161 | ||
14162 | switch (et.size) | |
14163 | { | |
14164 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
14165 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
14166 | case 32: abcdebits = 0x00; break; | |
14167 | default: ; | |
14168 | } | |
14169 | ||
14170 | abcdebits |= x << logsize; | |
14171 | inst.instruction = 0xe100b10; | |
14172 | do_vfp_cond_or_thumb (); | |
14173 | inst.instruction |= LOW4 (dn) << 16; | |
14174 | inst.instruction |= HI1 (dn) << 7; | |
14175 | inst.instruction |= inst.operands[0].reg << 12; | |
14176 | inst.instruction |= (abcdebits & 3) << 5; | |
14177 | inst.instruction |= (abcdebits >> 2) << 21; | |
14178 | } | |
14179 | break; | |
5f4273c7 | 14180 | |
037e8744 JB |
14181 | case NS_RRD: /* case 7 (fmrrd). */ |
14182 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
14183 | _(BAD_FPU)); | |
14184 | ||
14185 | inst.instruction = 0xc500b10; | |
14186 | do_vfp_cond_or_thumb (); | |
14187 | inst.instruction |= inst.operands[0].reg << 12; | |
14188 | inst.instruction |= inst.operands[1].reg << 16; | |
14189 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14190 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14191 | break; | |
5f4273c7 | 14192 | |
037e8744 JB |
14193 | case NS_FF: /* case 8 (fcpys). */ |
14194 | do_vfp_nsyn_opcode ("fcpys"); | |
14195 | break; | |
5f4273c7 | 14196 | |
037e8744 JB |
14197 | case NS_FI: /* case 10 (fconsts). */ |
14198 | ldconst = "fconsts"; | |
14199 | encode_fconstd: | |
14200 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 14201 | { |
037e8744 JB |
14202 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
14203 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
14204 | } |
14205 | else | |
037e8744 JB |
14206 | first_error (_("immediate out of range")); |
14207 | break; | |
5f4273c7 | 14208 | |
037e8744 JB |
14209 | case NS_RF: /* case 12 (fmrs). */ |
14210 | do_vfp_nsyn_opcode ("fmrs"); | |
14211 | break; | |
5f4273c7 | 14212 | |
037e8744 JB |
14213 | case NS_FR: /* case 13 (fmsr). */ |
14214 | do_vfp_nsyn_opcode ("fmsr"); | |
14215 | break; | |
5f4273c7 | 14216 | |
037e8744 JB |
14217 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
14218 | (one of which is a list), but we have parsed four. Do some fiddling to | |
14219 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
14220 | expect. */ | |
14221 | case NS_RRFF: /* case 14 (fmrrs). */ | |
14222 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
14223 | _("VFP registers must be adjacent")); | |
14224 | inst.operands[2].imm = 2; | |
14225 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14226 | do_vfp_nsyn_opcode ("fmrrs"); | |
14227 | break; | |
5f4273c7 | 14228 | |
037e8744 JB |
14229 | case NS_FFRR: /* case 15 (fmsrr). */ |
14230 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
14231 | _("VFP registers must be adjacent")); | |
14232 | inst.operands[1] = inst.operands[2]; | |
14233 | inst.operands[2] = inst.operands[3]; | |
14234 | inst.operands[0].imm = 2; | |
14235 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14236 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 14237 | break; |
5f4273c7 | 14238 | |
5287ad62 JB |
14239 | default: |
14240 | abort (); | |
14241 | } | |
14242 | } | |
14243 | ||
14244 | static void | |
14245 | do_neon_rshift_round_imm (void) | |
14246 | { | |
037e8744 | 14247 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14248 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
14249 | int imm = inst.operands[2].imm; | |
14250 | ||
14251 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
14252 | if (imm == 0) | |
14253 | { | |
14254 | inst.operands[2].present = 0; | |
14255 | do_neon_mov (); | |
14256 | return; | |
14257 | } | |
14258 | ||
14259 | constraint (imm < 1 || (unsigned)imm > et.size, | |
14260 | _("immediate out of range for shift")); | |
037e8744 | 14261 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
14262 | et.size - imm); |
14263 | } | |
14264 | ||
14265 | static void | |
14266 | do_neon_movl (void) | |
14267 | { | |
14268 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
14269 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
14270 | unsigned sizebits = et.size >> 3; | |
14271 | inst.instruction |= sizebits << 19; | |
14272 | neon_two_same (0, et.type == NT_unsigned, -1); | |
14273 | } | |
14274 | ||
14275 | static void | |
14276 | do_neon_trn (void) | |
14277 | { | |
037e8744 | 14278 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14279 | struct neon_type_el et = neon_check_type (2, rs, |
14280 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14281 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 14282 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14283 | } |
14284 | ||
14285 | static void | |
14286 | do_neon_zip_uzp (void) | |
14287 | { | |
037e8744 | 14288 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14289 | struct neon_type_el et = neon_check_type (2, rs, |
14290 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14291 | if (rs == NS_DD && et.size == 32) | |
14292 | { | |
14293 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
14294 | inst.instruction = N_MNEM_vtrn; | |
14295 | do_neon_trn (); | |
14296 | return; | |
14297 | } | |
037e8744 | 14298 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14299 | } |
14300 | ||
14301 | static void | |
14302 | do_neon_sat_abs_neg (void) | |
14303 | { | |
037e8744 | 14304 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14305 | struct neon_type_el et = neon_check_type (2, rs, |
14306 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14307 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14308 | } |
14309 | ||
14310 | static void | |
14311 | do_neon_pair_long (void) | |
14312 | { | |
037e8744 | 14313 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14314 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
14315 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
14316 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 14317 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14318 | } |
14319 | ||
14320 | static void | |
14321 | do_neon_recip_est (void) | |
14322 | { | |
037e8744 | 14323 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14324 | struct neon_type_el et = neon_check_type (2, rs, |
14325 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
14326 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 14327 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14328 | } |
14329 | ||
14330 | static void | |
14331 | do_neon_cls (void) | |
14332 | { | |
037e8744 | 14333 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14334 | struct neon_type_el et = neon_check_type (2, rs, |
14335 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14336 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14337 | } |
14338 | ||
14339 | static void | |
14340 | do_neon_clz (void) | |
14341 | { | |
037e8744 | 14342 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14343 | struct neon_type_el et = neon_check_type (2, rs, |
14344 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 14345 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14346 | } |
14347 | ||
14348 | static void | |
14349 | do_neon_cnt (void) | |
14350 | { | |
037e8744 | 14351 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14352 | struct neon_type_el et = neon_check_type (2, rs, |
14353 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 14354 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14355 | } |
14356 | ||
14357 | static void | |
14358 | do_neon_swp (void) | |
14359 | { | |
037e8744 JB |
14360 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
14361 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
14362 | } |
14363 | ||
14364 | static void | |
14365 | do_neon_tbl_tbx (void) | |
14366 | { | |
14367 | unsigned listlenbits; | |
dcbf9037 | 14368 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 14369 | |
5287ad62 JB |
14370 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
14371 | { | |
dcbf9037 | 14372 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
14373 | return; |
14374 | } | |
5f4273c7 | 14375 | |
5287ad62 JB |
14376 | listlenbits = inst.operands[1].imm - 1; |
14377 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14378 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14379 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14380 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14381 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14382 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14383 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 14384 | |
5287ad62 JB |
14385 | inst.instruction = neon_dp_fixup (inst.instruction); |
14386 | } | |
14387 | ||
14388 | static void | |
14389 | do_neon_ldm_stm (void) | |
14390 | { | |
14391 | /* P, U and L bits are part of bitmask. */ | |
14392 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
14393 | unsigned offsetbits = inst.operands[1].imm * 2; | |
14394 | ||
037e8744 JB |
14395 | if (inst.operands[1].issingle) |
14396 | { | |
14397 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
14398 | return; | |
14399 | } | |
14400 | ||
5287ad62 JB |
14401 | constraint (is_dbmode && !inst.operands[0].writeback, |
14402 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
14403 | ||
14404 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14405 | _("register list must contain at least 1 and at most 16 " | |
14406 | "registers")); | |
14407 | ||
14408 | inst.instruction |= inst.operands[0].reg << 16; | |
14409 | inst.instruction |= inst.operands[0].writeback << 21; | |
14410 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
14411 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
14412 | ||
14413 | inst.instruction |= offsetbits; | |
5f4273c7 | 14414 | |
037e8744 | 14415 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
14416 | } |
14417 | ||
14418 | static void | |
14419 | do_neon_ldr_str (void) | |
14420 | { | |
5287ad62 | 14421 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 14422 | |
037e8744 JB |
14423 | if (inst.operands[0].issingle) |
14424 | { | |
cd2f129f JB |
14425 | if (is_ldr) |
14426 | do_vfp_nsyn_opcode ("flds"); | |
14427 | else | |
14428 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
14429 | } |
14430 | else | |
5287ad62 | 14431 | { |
cd2f129f JB |
14432 | if (is_ldr) |
14433 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 14434 | else |
cd2f129f | 14435 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 14436 | } |
5287ad62 JB |
14437 | } |
14438 | ||
14439 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
14440 | instructions. */ | |
14441 | ||
14442 | static void | |
14443 | do_neon_ld_st_interleave (void) | |
14444 | { | |
037e8744 | 14445 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
14446 | N_8 | N_16 | N_32 | N_64); |
14447 | unsigned alignbits = 0; | |
14448 | unsigned idx; | |
14449 | /* The bits in this table go: | |
14450 | 0: register stride of one (0) or two (1) | |
14451 | 1,2: register list length, minus one (1, 2, 3, 4). | |
14452 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
14453 | We use -1 for invalid entries. */ | |
14454 | const int typetable[] = | |
14455 | { | |
14456 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
14457 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
14458 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
14459 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
14460 | }; | |
14461 | int typebits; | |
14462 | ||
dcbf9037 JB |
14463 | if (et.type == NT_invtype) |
14464 | return; | |
14465 | ||
5287ad62 JB |
14466 | if (inst.operands[1].immisalign) |
14467 | switch (inst.operands[1].imm >> 8) | |
14468 | { | |
14469 | case 64: alignbits = 1; break; | |
14470 | case 128: | |
14471 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
14472 | goto bad_alignment; | |
14473 | alignbits = 2; | |
14474 | break; | |
14475 | case 256: | |
14476 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
14477 | goto bad_alignment; | |
14478 | alignbits = 3; | |
14479 | break; | |
14480 | default: | |
14481 | bad_alignment: | |
dcbf9037 | 14482 | first_error (_("bad alignment")); |
5287ad62 JB |
14483 | return; |
14484 | } | |
14485 | ||
14486 | inst.instruction |= alignbits << 4; | |
14487 | inst.instruction |= neon_logbits (et.size) << 6; | |
14488 | ||
14489 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
14490 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
14491 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
14492 | up the right value for "type" in a table based on this value and the given | |
14493 | list style, then stick it back. */ | |
14494 | idx = ((inst.operands[0].imm >> 4) & 7) | |
14495 | | (((inst.instruction >> 8) & 3) << 3); | |
14496 | ||
14497 | typebits = typetable[idx]; | |
5f4273c7 | 14498 | |
5287ad62 JB |
14499 | constraint (typebits == -1, _("bad list type for instruction")); |
14500 | ||
14501 | inst.instruction &= ~0xf00; | |
14502 | inst.instruction |= typebits << 8; | |
14503 | } | |
14504 | ||
14505 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
14506 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
14507 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
14508 | values, terminated with -1. */ | |
14509 | ||
14510 | static int | |
14511 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
14512 | { | |
14513 | va_list ap; | |
14514 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 14515 | |
5287ad62 JB |
14516 | if (!inst.operands[1].immisalign) |
14517 | { | |
14518 | *do_align = 0; | |
14519 | return SUCCESS; | |
14520 | } | |
5f4273c7 | 14521 | |
5287ad62 JB |
14522 | va_start (ap, do_align); |
14523 | ||
14524 | do | |
14525 | { | |
14526 | thissize = va_arg (ap, int); | |
14527 | if (thissize == -1) | |
14528 | break; | |
14529 | thisalign = va_arg (ap, int); | |
14530 | ||
14531 | if (size == thissize && align == thisalign) | |
14532 | result = SUCCESS; | |
14533 | } | |
14534 | while (result != SUCCESS); | |
14535 | ||
14536 | va_end (ap); | |
14537 | ||
14538 | if (result == SUCCESS) | |
14539 | *do_align = 1; | |
14540 | else | |
dcbf9037 | 14541 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 14542 | |
5287ad62 JB |
14543 | return result; |
14544 | } | |
14545 | ||
14546 | static void | |
14547 | do_neon_ld_st_lane (void) | |
14548 | { | |
037e8744 | 14549 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
14550 | int align_good, do_align = 0; |
14551 | int logsize = neon_logbits (et.size); | |
14552 | int align = inst.operands[1].imm >> 8; | |
14553 | int n = (inst.instruction >> 8) & 3; | |
14554 | int max_el = 64 / et.size; | |
5f4273c7 | 14555 | |
dcbf9037 JB |
14556 | if (et.type == NT_invtype) |
14557 | return; | |
5f4273c7 | 14558 | |
5287ad62 JB |
14559 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
14560 | _("bad list length")); | |
14561 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
14562 | _("scalar index out of range")); | |
14563 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
14564 | && et.size == 8, | |
14565 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 14566 | |
5287ad62 JB |
14567 | switch (n) |
14568 | { | |
14569 | case 0: /* VLD1 / VST1. */ | |
14570 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
14571 | 32, 32, -1); | |
14572 | if (align_good == FAIL) | |
14573 | return; | |
14574 | if (do_align) | |
14575 | { | |
14576 | unsigned alignbits = 0; | |
14577 | switch (et.size) | |
14578 | { | |
14579 | case 16: alignbits = 0x1; break; | |
14580 | case 32: alignbits = 0x3; break; | |
14581 | default: ; | |
14582 | } | |
14583 | inst.instruction |= alignbits << 4; | |
14584 | } | |
14585 | break; | |
14586 | ||
14587 | case 1: /* VLD2 / VST2. */ | |
14588 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
14589 | 32, 64, -1); | |
14590 | if (align_good == FAIL) | |
14591 | return; | |
14592 | if (do_align) | |
14593 | inst.instruction |= 1 << 4; | |
14594 | break; | |
14595 | ||
14596 | case 2: /* VLD3 / VST3. */ | |
14597 | constraint (inst.operands[1].immisalign, | |
14598 | _("can't use alignment with this instruction")); | |
14599 | break; | |
14600 | ||
14601 | case 3: /* VLD4 / VST4. */ | |
14602 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
14603 | 16, 64, 32, 64, 32, 128, -1); | |
14604 | if (align_good == FAIL) | |
14605 | return; | |
14606 | if (do_align) | |
14607 | { | |
14608 | unsigned alignbits = 0; | |
14609 | switch (et.size) | |
14610 | { | |
14611 | case 8: alignbits = 0x1; break; | |
14612 | case 16: alignbits = 0x1; break; | |
14613 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
14614 | default: ; | |
14615 | } | |
14616 | inst.instruction |= alignbits << 4; | |
14617 | } | |
14618 | break; | |
14619 | ||
14620 | default: ; | |
14621 | } | |
14622 | ||
14623 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
14624 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14625 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 14626 | |
5287ad62 JB |
14627 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
14628 | inst.instruction |= logsize << 10; | |
14629 | } | |
14630 | ||
14631 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
14632 | ||
14633 | static void | |
14634 | do_neon_ld_dup (void) | |
14635 | { | |
037e8744 | 14636 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
14637 | int align_good, do_align = 0; |
14638 | ||
dcbf9037 JB |
14639 | if (et.type == NT_invtype) |
14640 | return; | |
14641 | ||
5287ad62 JB |
14642 | switch ((inst.instruction >> 8) & 3) |
14643 | { | |
14644 | case 0: /* VLD1. */ | |
9c2799c2 | 14645 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 JB |
14646 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
14647 | &do_align, 16, 16, 32, 32, -1); | |
14648 | if (align_good == FAIL) | |
14649 | return; | |
14650 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
14651 | { | |
14652 | case 1: break; | |
14653 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 14654 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
14655 | } |
14656 | inst.instruction |= neon_logbits (et.size) << 6; | |
14657 | break; | |
14658 | ||
14659 | case 1: /* VLD2. */ | |
14660 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
14661 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
14662 | if (align_good == FAIL) | |
14663 | return; | |
14664 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
14665 | _("bad list length")); | |
14666 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14667 | inst.instruction |= 1 << 5; | |
14668 | inst.instruction |= neon_logbits (et.size) << 6; | |
14669 | break; | |
14670 | ||
14671 | case 2: /* VLD3. */ | |
14672 | constraint (inst.operands[1].immisalign, | |
14673 | _("can't use alignment with this instruction")); | |
14674 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
14675 | _("bad list length")); | |
14676 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14677 | inst.instruction |= 1 << 5; | |
14678 | inst.instruction |= neon_logbits (et.size) << 6; | |
14679 | break; | |
14680 | ||
14681 | case 3: /* VLD4. */ | |
14682 | { | |
14683 | int align = inst.operands[1].imm >> 8; | |
14684 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
14685 | 16, 64, 32, 64, 32, 128, -1); | |
14686 | if (align_good == FAIL) | |
14687 | return; | |
14688 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
14689 | _("bad list length")); | |
14690 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14691 | inst.instruction |= 1 << 5; | |
14692 | if (et.size == 32 && align == 128) | |
14693 | inst.instruction |= 0x3 << 6; | |
14694 | else | |
14695 | inst.instruction |= neon_logbits (et.size) << 6; | |
14696 | } | |
14697 | break; | |
14698 | ||
14699 | default: ; | |
14700 | } | |
14701 | ||
14702 | inst.instruction |= do_align << 4; | |
14703 | } | |
14704 | ||
14705 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
14706 | apart from bits [11:4]. */ | |
14707 | ||
14708 | static void | |
14709 | do_neon_ldx_stx (void) | |
14710 | { | |
14711 | switch (NEON_LANE (inst.operands[0].imm)) | |
14712 | { | |
14713 | case NEON_INTERLEAVE_LANES: | |
14714 | inst.instruction = NEON_ENC_INTERLV (inst.instruction); | |
14715 | do_neon_ld_st_interleave (); | |
14716 | break; | |
5f4273c7 | 14717 | |
5287ad62 JB |
14718 | case NEON_ALL_LANES: |
14719 | inst.instruction = NEON_ENC_DUP (inst.instruction); | |
14720 | do_neon_ld_dup (); | |
14721 | break; | |
5f4273c7 | 14722 | |
5287ad62 JB |
14723 | default: |
14724 | inst.instruction = NEON_ENC_LANE (inst.instruction); | |
14725 | do_neon_ld_st_lane (); | |
14726 | } | |
14727 | ||
14728 | /* L bit comes from bit mask. */ | |
14729 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14730 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14731 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 14732 | |
5287ad62 JB |
14733 | if (inst.operands[1].postind) |
14734 | { | |
14735 | int postreg = inst.operands[1].imm & 0xf; | |
14736 | constraint (!inst.operands[1].immisreg, | |
14737 | _("post-index must be a register")); | |
14738 | constraint (postreg == 0xd || postreg == 0xf, | |
14739 | _("bad register for post-index")); | |
14740 | inst.instruction |= postreg; | |
14741 | } | |
14742 | else if (inst.operands[1].writeback) | |
14743 | { | |
14744 | inst.instruction |= 0xd; | |
14745 | } | |
14746 | else | |
5f4273c7 NC |
14747 | inst.instruction |= 0xf; |
14748 | ||
5287ad62 JB |
14749 | if (thumb_mode) |
14750 | inst.instruction |= 0xf9000000; | |
14751 | else | |
14752 | inst.instruction |= 0xf4000000; | |
14753 | } | |
5287ad62 JB |
14754 | \f |
14755 | /* Overall per-instruction processing. */ | |
14756 | ||
14757 | /* We need to be able to fix up arbitrary expressions in some statements. | |
14758 | This is so that we can handle symbols that are an arbitrary distance from | |
14759 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
14760 | which returns part of an address in a form which will be valid for | |
14761 | a data instruction. We do this by pushing the expression into a symbol | |
14762 | in the expr_section, and creating a fix for that. */ | |
14763 | ||
14764 | static void | |
14765 | fix_new_arm (fragS * frag, | |
14766 | int where, | |
14767 | short int size, | |
14768 | expressionS * exp, | |
14769 | int pc_rel, | |
14770 | int reloc) | |
14771 | { | |
14772 | fixS * new_fix; | |
14773 | ||
14774 | switch (exp->X_op) | |
14775 | { | |
14776 | case O_constant: | |
14777 | case O_symbol: | |
14778 | case O_add: | |
14779 | case O_subtract: | |
21d799b5 NC |
14780 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
14781 | (enum bfd_reloc_code_real) reloc); | |
5287ad62 JB |
14782 | break; |
14783 | ||
14784 | default: | |
21d799b5 NC |
14785 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
14786 | pc_rel, (enum bfd_reloc_code_real) reloc); | |
5287ad62 JB |
14787 | break; |
14788 | } | |
14789 | ||
14790 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
14791 | instruction. */ | |
14792 | new_fix->tc_fix_data = thumb_mode; | |
14793 | } | |
14794 | ||
14795 | /* Create a frg for an instruction requiring relaxation. */ | |
14796 | static void | |
14797 | output_relax_insn (void) | |
14798 | { | |
14799 | char * to; | |
14800 | symbolS *sym; | |
0110f2b8 PB |
14801 | int offset; |
14802 | ||
6e1cb1a6 PB |
14803 | /* The size of the instruction is unknown, so tie the debug info to the |
14804 | start of the instruction. */ | |
14805 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 14806 | |
0110f2b8 PB |
14807 | switch (inst.reloc.exp.X_op) |
14808 | { | |
14809 | case O_symbol: | |
14810 | sym = inst.reloc.exp.X_add_symbol; | |
14811 | offset = inst.reloc.exp.X_add_number; | |
14812 | break; | |
14813 | case O_constant: | |
14814 | sym = NULL; | |
14815 | offset = inst.reloc.exp.X_add_number; | |
14816 | break; | |
14817 | default: | |
14818 | sym = make_expr_symbol (&inst.reloc.exp); | |
14819 | offset = 0; | |
14820 | break; | |
14821 | } | |
14822 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
14823 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
14824 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
14825 | } |
14826 | ||
14827 | /* Write a 32-bit thumb instruction to buf. */ | |
14828 | static void | |
14829 | put_thumb32_insn (char * buf, unsigned long insn) | |
14830 | { | |
14831 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
14832 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
14833 | } | |
14834 | ||
b99bd4ef | 14835 | static void |
c19d1205 | 14836 | output_inst (const char * str) |
b99bd4ef | 14837 | { |
c19d1205 | 14838 | char * to = NULL; |
b99bd4ef | 14839 | |
c19d1205 | 14840 | if (inst.error) |
b99bd4ef | 14841 | { |
c19d1205 | 14842 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
14843 | return; |
14844 | } | |
5f4273c7 NC |
14845 | if (inst.relax) |
14846 | { | |
14847 | output_relax_insn (); | |
0110f2b8 | 14848 | return; |
5f4273c7 | 14849 | } |
c19d1205 ZW |
14850 | if (inst.size == 0) |
14851 | return; | |
b99bd4ef | 14852 | |
c19d1205 | 14853 | to = frag_more (inst.size); |
8dc2430f NC |
14854 | /* PR 9814: Record the thumb mode into the current frag so that we know |
14855 | what type of NOP padding to use, if necessary. We override any previous | |
14856 | setting so that if the mode has changed then the NOPS that we use will | |
14857 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 14858 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
14859 | |
14860 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 14861 | { |
9c2799c2 | 14862 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 14863 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 14864 | } |
c19d1205 | 14865 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 14866 | { |
9c2799c2 | 14867 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
14868 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
14869 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 14870 | } |
c19d1205 ZW |
14871 | else |
14872 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 14873 | |
c19d1205 ZW |
14874 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
14875 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
14876 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
14877 | inst.reloc.type); | |
b99bd4ef | 14878 | |
c19d1205 | 14879 | dwarf2_emit_insn (inst.size); |
c19d1205 | 14880 | } |
b99bd4ef | 14881 | |
e07e6e58 NC |
14882 | static char * |
14883 | output_it_inst (int cond, int mask, char * to) | |
14884 | { | |
14885 | unsigned long instruction = 0xbf00; | |
14886 | ||
14887 | mask &= 0xf; | |
14888 | instruction |= mask; | |
14889 | instruction |= cond << 4; | |
14890 | ||
14891 | if (to == NULL) | |
14892 | { | |
14893 | to = frag_more (2); | |
14894 | #ifdef OBJ_ELF | |
14895 | dwarf2_emit_insn (2); | |
14896 | #endif | |
14897 | } | |
14898 | ||
14899 | md_number_to_chars (to, instruction, 2); | |
14900 | ||
14901 | return to; | |
14902 | } | |
14903 | ||
c19d1205 ZW |
14904 | /* Tag values used in struct asm_opcode's tag field. */ |
14905 | enum opcode_tag | |
14906 | { | |
14907 | OT_unconditional, /* Instruction cannot be conditionalized. | |
14908 | The ARM condition field is still 0xE. */ | |
14909 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
14910 | and carries 0xF in its ARM condition field. */ | |
14911 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
14912 | OT_csuffixF, /* Some forms of the instruction take a conditional |
14913 | suffix, others place 0xF where the condition field | |
14914 | would be. */ | |
c19d1205 ZW |
14915 | OT_cinfix3, /* Instruction takes a conditional infix, |
14916 | beginning at character index 3. (In | |
14917 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
14918 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
14919 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
14920 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
14921 | character index 3, even in unified mode. Used for | |
14922 | legacy instructions where suffix and infix forms | |
14923 | may be ambiguous. */ | |
c19d1205 | 14924 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 14925 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
14926 | OT_odd_infix_unc, /* This is the unconditional variant of an |
14927 | instruction that takes a conditional infix | |
14928 | at an unusual position. In unified mode, | |
14929 | this variant will accept a suffix. */ | |
14930 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
14931 | are the conditional variants of instructions that | |
14932 | take conditional infixes in unusual positions. | |
14933 | The infix appears at character index | |
14934 | (tag - OT_odd_infix_0). These are not accepted | |
14935 | in unified mode. */ | |
14936 | }; | |
b99bd4ef | 14937 | |
c19d1205 ZW |
14938 | /* Subroutine of md_assemble, responsible for looking up the primary |
14939 | opcode from the mnemonic the user wrote. STR points to the | |
14940 | beginning of the mnemonic. | |
14941 | ||
14942 | This is not simply a hash table lookup, because of conditional | |
14943 | variants. Most instructions have conditional variants, which are | |
14944 | expressed with a _conditional affix_ to the mnemonic. If we were | |
14945 | to encode each conditional variant as a literal string in the opcode | |
14946 | table, it would have approximately 20,000 entries. | |
14947 | ||
14948 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
14949 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
14950 | instructions take the affix as an infix, notably the s-variants of | |
14951 | the arithmetic instructions. Of those instructions, all but six | |
14952 | have the infix appear after the third character of the mnemonic. | |
14953 | ||
14954 | Accordingly, the algorithm for looking up primary opcodes given | |
14955 | an identifier is: | |
14956 | ||
14957 | 1. Look up the identifier in the opcode table. | |
14958 | If we find a match, go to step U. | |
14959 | ||
14960 | 2. Look up the last two characters of the identifier in the | |
14961 | conditions table. If we find a match, look up the first N-2 | |
14962 | characters of the identifier in the opcode table. If we | |
14963 | find a match, go to step CE. | |
14964 | ||
14965 | 3. Look up the fourth and fifth characters of the identifier in | |
14966 | the conditions table. If we find a match, extract those | |
14967 | characters from the identifier, and look up the remaining | |
14968 | characters in the opcode table. If we find a match, go | |
14969 | to step CM. | |
14970 | ||
14971 | 4. Fail. | |
14972 | ||
14973 | U. Examine the tag field of the opcode structure, in case this is | |
14974 | one of the six instructions with its conditional infix in an | |
14975 | unusual place. If it is, the tag tells us where to find the | |
14976 | infix; look it up in the conditions table and set inst.cond | |
14977 | accordingly. Otherwise, this is an unconditional instruction. | |
14978 | Again set inst.cond accordingly. Return the opcode structure. | |
14979 | ||
14980 | CE. Examine the tag field to make sure this is an instruction that | |
14981 | should receive a conditional suffix. If it is not, fail. | |
14982 | Otherwise, set inst.cond from the suffix we already looked up, | |
14983 | and return the opcode structure. | |
14984 | ||
14985 | CM. Examine the tag field to make sure this is an instruction that | |
14986 | should receive a conditional infix after the third character. | |
14987 | If it is not, fail. Otherwise, undo the edits to the current | |
14988 | line of input and proceed as for case CE. */ | |
14989 | ||
14990 | static const struct asm_opcode * | |
14991 | opcode_lookup (char **str) | |
14992 | { | |
14993 | char *end, *base; | |
14994 | char *affix; | |
14995 | const struct asm_opcode *opcode; | |
14996 | const struct asm_cond *cond; | |
e3cb604e | 14997 | char save[2]; |
c19d1205 ZW |
14998 | |
14999 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 15000 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 15001 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 15002 | if (*end == ' ' || *end == '.') |
c19d1205 | 15003 | break; |
b99bd4ef | 15004 | |
c19d1205 | 15005 | if (end == base) |
c921be7d | 15006 | return NULL; |
b99bd4ef | 15007 | |
5287ad62 | 15008 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 15009 | if (end[0] == '.') |
b99bd4ef | 15010 | { |
5287ad62 | 15011 | int offset = 2; |
5f4273c7 | 15012 | |
267d2029 JB |
15013 | /* The .w and .n suffixes are only valid if the unified syntax is in |
15014 | use. */ | |
15015 | if (unified_syntax && end[1] == 'w') | |
c19d1205 | 15016 | inst.size_req = 4; |
267d2029 | 15017 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
15018 | inst.size_req = 2; |
15019 | else | |
5287ad62 JB |
15020 | offset = 0; |
15021 | ||
15022 | inst.vectype.elems = 0; | |
15023 | ||
15024 | *str = end + offset; | |
b99bd4ef | 15025 | |
5f4273c7 | 15026 | if (end[offset] == '.') |
5287ad62 | 15027 | { |
267d2029 JB |
15028 | /* See if we have a Neon type suffix (possible in either unified or |
15029 | non-unified ARM syntax mode). */ | |
dcbf9037 | 15030 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
c921be7d | 15031 | return NULL; |
5287ad62 JB |
15032 | } |
15033 | else if (end[offset] != '\0' && end[offset] != ' ') | |
c921be7d | 15034 | return NULL; |
b99bd4ef | 15035 | } |
c19d1205 ZW |
15036 | else |
15037 | *str = end; | |
b99bd4ef | 15038 | |
c19d1205 | 15039 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 NC |
15040 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
15041 | end - base); | |
c19d1205 | 15042 | if (opcode) |
b99bd4ef | 15043 | { |
c19d1205 ZW |
15044 | /* step U */ |
15045 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 15046 | { |
c19d1205 ZW |
15047 | inst.cond = COND_ALWAYS; |
15048 | return opcode; | |
b99bd4ef | 15049 | } |
b99bd4ef | 15050 | |
278df34e | 15051 | if (warn_on_deprecated && unified_syntax) |
c19d1205 ZW |
15052 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
15053 | affix = base + (opcode->tag - OT_odd_infix_0); | |
21d799b5 | 15054 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 15055 | gas_assert (cond); |
b99bd4ef | 15056 | |
c19d1205 ZW |
15057 | inst.cond = cond->value; |
15058 | return opcode; | |
15059 | } | |
b99bd4ef | 15060 | |
c19d1205 ZW |
15061 | /* Cannot have a conditional suffix on a mnemonic of less than two |
15062 | characters. */ | |
15063 | if (end - base < 3) | |
c921be7d | 15064 | return NULL; |
b99bd4ef | 15065 | |
c19d1205 ZW |
15066 | /* Look for suffixed mnemonic. */ |
15067 | affix = end - 2; | |
21d799b5 NC |
15068 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
15069 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
15070 | affix - base); | |
c19d1205 ZW |
15071 | if (opcode && cond) |
15072 | { | |
15073 | /* step CE */ | |
15074 | switch (opcode->tag) | |
15075 | { | |
e3cb604e PB |
15076 | case OT_cinfix3_legacy: |
15077 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
15078 | break; | |
15079 | ||
c19d1205 | 15080 | case OT_cinfix3: |
088fa78e | 15081 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
15082 | case OT_odd_infix_unc: |
15083 | if (!unified_syntax) | |
e3cb604e | 15084 | return 0; |
c19d1205 ZW |
15085 | /* else fall through */ |
15086 | ||
15087 | case OT_csuffix: | |
037e8744 | 15088 | case OT_csuffixF: |
c19d1205 ZW |
15089 | case OT_csuf_or_in3: |
15090 | inst.cond = cond->value; | |
15091 | return opcode; | |
15092 | ||
15093 | case OT_unconditional: | |
15094 | case OT_unconditionalF: | |
dfa9f0d5 | 15095 | if (thumb_mode) |
c921be7d | 15096 | inst.cond = cond->value; |
dfa9f0d5 PB |
15097 | else |
15098 | { | |
c921be7d | 15099 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
15100 | inst.error = BAD_COND; |
15101 | inst.cond = COND_ALWAYS; | |
15102 | } | |
c19d1205 | 15103 | return opcode; |
b99bd4ef | 15104 | |
c19d1205 | 15105 | default: |
c921be7d | 15106 | return NULL; |
c19d1205 ZW |
15107 | } |
15108 | } | |
b99bd4ef | 15109 | |
c19d1205 ZW |
15110 | /* Cannot have a usual-position infix on a mnemonic of less than |
15111 | six characters (five would be a suffix). */ | |
15112 | if (end - base < 6) | |
c921be7d | 15113 | return NULL; |
b99bd4ef | 15114 | |
c19d1205 ZW |
15115 | /* Look for infixed mnemonic in the usual position. */ |
15116 | affix = base + 3; | |
21d799b5 | 15117 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 15118 | if (!cond) |
c921be7d | 15119 | return NULL; |
e3cb604e PB |
15120 | |
15121 | memcpy (save, affix, 2); | |
15122 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 NC |
15123 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
15124 | (end - base) - 2); | |
e3cb604e PB |
15125 | memmove (affix + 2, affix, (end - affix) - 2); |
15126 | memcpy (affix, save, 2); | |
15127 | ||
088fa78e KH |
15128 | if (opcode |
15129 | && (opcode->tag == OT_cinfix3 | |
15130 | || opcode->tag == OT_cinfix3_deprecated | |
15131 | || opcode->tag == OT_csuf_or_in3 | |
15132 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 15133 | { |
c921be7d | 15134 | /* Step CM. */ |
278df34e | 15135 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
15136 | && (opcode->tag == OT_cinfix3 |
15137 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
15138 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
15139 | ||
15140 | inst.cond = cond->value; | |
15141 | return opcode; | |
b99bd4ef NC |
15142 | } |
15143 | ||
c921be7d | 15144 | return NULL; |
b99bd4ef NC |
15145 | } |
15146 | ||
e07e6e58 NC |
15147 | /* This function generates an initial IT instruction, leaving its block |
15148 | virtually open for the new instructions. Eventually, | |
15149 | the mask will be updated by now_it_add_mask () each time | |
15150 | a new instruction needs to be included in the IT block. | |
15151 | Finally, the block is closed with close_automatic_it_block (). | |
15152 | The block closure can be requested either from md_assemble (), | |
15153 | a tencode (), or due to a label hook. */ | |
15154 | ||
15155 | static void | |
15156 | new_automatic_it_block (int cond) | |
15157 | { | |
15158 | now_it.state = AUTOMATIC_IT_BLOCK; | |
15159 | now_it.mask = 0x18; | |
15160 | now_it.cc = cond; | |
15161 | now_it.block_length = 1; | |
cd000bff | 15162 | mapping_state (MAP_THUMB); |
e07e6e58 NC |
15163 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
15164 | } | |
15165 | ||
15166 | /* Close an automatic IT block. | |
15167 | See comments in new_automatic_it_block (). */ | |
15168 | ||
15169 | static void | |
15170 | close_automatic_it_block (void) | |
15171 | { | |
15172 | now_it.mask = 0x10; | |
15173 | now_it.block_length = 0; | |
15174 | } | |
15175 | ||
15176 | /* Update the mask of the current automatically-generated IT | |
15177 | instruction. See comments in new_automatic_it_block (). */ | |
15178 | ||
15179 | static void | |
15180 | now_it_add_mask (int cond) | |
15181 | { | |
15182 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
15183 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
15184 | | ((bitvalue) << (nbit))) | |
e07e6e58 | 15185 | const int resulting_bit = (cond & 1); |
c921be7d | 15186 | |
e07e6e58 NC |
15187 | now_it.mask &= 0xf; |
15188 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15189 | resulting_bit, | |
15190 | (5 - now_it.block_length)); | |
15191 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15192 | 1, | |
15193 | ((5 - now_it.block_length) - 1) ); | |
15194 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); | |
15195 | ||
15196 | #undef CLEAR_BIT | |
15197 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
15198 | } |
15199 | ||
15200 | /* The IT blocks handling machinery is accessed through the these functions: | |
15201 | it_fsm_pre_encode () from md_assemble () | |
15202 | set_it_insn_type () optional, from the tencode functions | |
15203 | set_it_insn_type_last () ditto | |
15204 | in_it_block () ditto | |
15205 | it_fsm_post_encode () from md_assemble () | |
15206 | force_automatic_it_block_close () from label habdling functions | |
15207 | ||
15208 | Rationale: | |
15209 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
15210 | initializing the IT insn type with a generic initial value depending | |
15211 | on the inst.condition. | |
15212 | 2) During the tencode function, two things may happen: | |
15213 | a) The tencode function overrides the IT insn type by | |
15214 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
15215 | b) The tencode function queries the IT block state by | |
15216 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
15217 | ||
15218 | Both set_it_insn_type and in_it_block run the internal FSM state | |
15219 | handling function (handle_it_state), because: a) setting the IT insn | |
15220 | type may incur in an invalid state (exiting the function), | |
15221 | and b) querying the state requires the FSM to be updated. | |
15222 | Specifically we want to avoid creating an IT block for conditional | |
15223 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
15224 | determine whether an IT block is required until the tencode () routine | |
15225 | has decided what type of instruction this actually it. | |
15226 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
15227 | set_it_insn_type has to be called first. | |
15228 | ||
15229 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
15230 | determines the insn IT type depending on the inst.cond code. | |
15231 | When a tencode () routine encodes an instruction that can be | |
15232 | either outside an IT block, or, in the case of being inside, has to be | |
15233 | the last one, set_it_insn_type_last () will determine the proper | |
15234 | IT instruction type based on the inst.cond code. Otherwise, | |
15235 | set_it_insn_type can be called for overriding that logic or | |
15236 | for covering other cases. | |
15237 | ||
15238 | Calling handle_it_state () may not transition the IT block state to | |
15239 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
15240 | still queried. Instead, if the FSM determines that the state should | |
15241 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
15242 | after the tencode () function: that's what it_fsm_post_encode () does. | |
15243 | ||
15244 | Since in_it_block () calls the state handling function to get an | |
15245 | updated state, an error may occur (due to invalid insns combination). | |
15246 | In that case, inst.error is set. | |
15247 | Therefore, inst.error has to be checked after the execution of | |
15248 | the tencode () routine. | |
15249 | ||
15250 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
15251 | any pending state change (if any) that didn't take place in | |
15252 | handle_it_state () as explained above. */ | |
15253 | ||
15254 | static void | |
15255 | it_fsm_pre_encode (void) | |
15256 | { | |
15257 | if (inst.cond != COND_ALWAYS) | |
15258 | inst.it_insn_type = INSIDE_IT_INSN; | |
15259 | else | |
15260 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
15261 | ||
15262 | now_it.state_handled = 0; | |
15263 | } | |
15264 | ||
15265 | /* IT state FSM handling function. */ | |
15266 | ||
15267 | static int | |
15268 | handle_it_state (void) | |
15269 | { | |
15270 | now_it.state_handled = 1; | |
15271 | ||
15272 | switch (now_it.state) | |
15273 | { | |
15274 | case OUTSIDE_IT_BLOCK: | |
15275 | switch (inst.it_insn_type) | |
15276 | { | |
15277 | case OUTSIDE_IT_INSN: | |
15278 | break; | |
15279 | ||
15280 | case INSIDE_IT_INSN: | |
15281 | case INSIDE_IT_LAST_INSN: | |
15282 | if (thumb_mode == 0) | |
15283 | { | |
c921be7d | 15284 | if (unified_syntax |
e07e6e58 NC |
15285 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
15286 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
15287 | " for Thumb.")); | |
15288 | } | |
15289 | else | |
15290 | { | |
15291 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
15292 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
15293 | { | |
15294 | /* Automatically generate the IT instruction. */ | |
15295 | new_automatic_it_block (inst.cond); | |
15296 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
15297 | close_automatic_it_block (); | |
15298 | } | |
15299 | else | |
15300 | { | |
15301 | inst.error = BAD_OUT_IT; | |
15302 | return FAIL; | |
15303 | } | |
15304 | } | |
15305 | break; | |
15306 | ||
15307 | case IF_INSIDE_IT_LAST_INSN: | |
15308 | case NEUTRAL_IT_INSN: | |
15309 | break; | |
15310 | ||
15311 | case IT_INSN: | |
15312 | now_it.state = MANUAL_IT_BLOCK; | |
15313 | now_it.block_length = 0; | |
15314 | break; | |
15315 | } | |
15316 | break; | |
15317 | ||
15318 | case AUTOMATIC_IT_BLOCK: | |
15319 | /* Three things may happen now: | |
15320 | a) We should increment current it block size; | |
15321 | b) We should close current it block (closing insn or 4 insns); | |
15322 | c) We should close current it block and start a new one (due | |
15323 | to incompatible conditions or | |
15324 | 4 insns-length block reached). */ | |
15325 | ||
15326 | switch (inst.it_insn_type) | |
15327 | { | |
15328 | case OUTSIDE_IT_INSN: | |
15329 | /* The closure of the block shall happen immediatelly, | |
15330 | so any in_it_block () call reports the block as closed. */ | |
15331 | force_automatic_it_block_close (); | |
15332 | break; | |
15333 | ||
15334 | case INSIDE_IT_INSN: | |
15335 | case INSIDE_IT_LAST_INSN: | |
15336 | case IF_INSIDE_IT_LAST_INSN: | |
15337 | now_it.block_length++; | |
15338 | ||
15339 | if (now_it.block_length > 4 | |
15340 | || !now_it_compatible (inst.cond)) | |
15341 | { | |
15342 | force_automatic_it_block_close (); | |
15343 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
15344 | new_automatic_it_block (inst.cond); | |
15345 | } | |
15346 | else | |
15347 | { | |
15348 | now_it_add_mask (inst.cond); | |
15349 | } | |
15350 | ||
15351 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
15352 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
15353 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
15354 | close_automatic_it_block (); | |
15355 | break; | |
15356 | ||
15357 | case NEUTRAL_IT_INSN: | |
15358 | now_it.block_length++; | |
15359 | ||
15360 | if (now_it.block_length > 4) | |
15361 | force_automatic_it_block_close (); | |
15362 | else | |
15363 | now_it_add_mask (now_it.cc & 1); | |
15364 | break; | |
15365 | ||
15366 | case IT_INSN: | |
15367 | close_automatic_it_block (); | |
15368 | now_it.state = MANUAL_IT_BLOCK; | |
15369 | break; | |
15370 | } | |
15371 | break; | |
15372 | ||
15373 | case MANUAL_IT_BLOCK: | |
15374 | { | |
15375 | /* Check conditional suffixes. */ | |
15376 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
15377 | int is_last; | |
15378 | now_it.mask <<= 1; | |
15379 | now_it.mask &= 0x1f; | |
15380 | is_last = (now_it.mask == 0x10); | |
15381 | ||
15382 | switch (inst.it_insn_type) | |
15383 | { | |
15384 | case OUTSIDE_IT_INSN: | |
15385 | inst.error = BAD_NOT_IT; | |
15386 | return FAIL; | |
15387 | ||
15388 | case INSIDE_IT_INSN: | |
15389 | if (cond != inst.cond) | |
15390 | { | |
15391 | inst.error = BAD_IT_COND; | |
15392 | return FAIL; | |
15393 | } | |
15394 | break; | |
15395 | ||
15396 | case INSIDE_IT_LAST_INSN: | |
15397 | case IF_INSIDE_IT_LAST_INSN: | |
15398 | if (cond != inst.cond) | |
15399 | { | |
15400 | inst.error = BAD_IT_COND; | |
15401 | return FAIL; | |
15402 | } | |
15403 | if (!is_last) | |
15404 | { | |
15405 | inst.error = BAD_BRANCH; | |
15406 | return FAIL; | |
15407 | } | |
15408 | break; | |
15409 | ||
15410 | case NEUTRAL_IT_INSN: | |
15411 | /* The BKPT instruction is unconditional even in an IT block. */ | |
15412 | break; | |
15413 | ||
15414 | case IT_INSN: | |
15415 | inst.error = BAD_IT_IT; | |
15416 | return FAIL; | |
15417 | } | |
15418 | } | |
15419 | break; | |
15420 | } | |
15421 | ||
15422 | return SUCCESS; | |
15423 | } | |
15424 | ||
15425 | static void | |
15426 | it_fsm_post_encode (void) | |
15427 | { | |
15428 | int is_last; | |
15429 | ||
15430 | if (!now_it.state_handled) | |
15431 | handle_it_state (); | |
15432 | ||
15433 | is_last = (now_it.mask == 0x10); | |
15434 | if (is_last) | |
15435 | { | |
15436 | now_it.state = OUTSIDE_IT_BLOCK; | |
15437 | now_it.mask = 0; | |
15438 | } | |
15439 | } | |
15440 | ||
15441 | static void | |
15442 | force_automatic_it_block_close (void) | |
15443 | { | |
15444 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
15445 | { | |
15446 | close_automatic_it_block (); | |
15447 | now_it.state = OUTSIDE_IT_BLOCK; | |
15448 | now_it.mask = 0; | |
15449 | } | |
15450 | } | |
15451 | ||
15452 | static int | |
15453 | in_it_block (void) | |
15454 | { | |
15455 | if (!now_it.state_handled) | |
15456 | handle_it_state (); | |
15457 | ||
15458 | return now_it.state != OUTSIDE_IT_BLOCK; | |
15459 | } | |
15460 | ||
c19d1205 ZW |
15461 | void |
15462 | md_assemble (char *str) | |
b99bd4ef | 15463 | { |
c19d1205 ZW |
15464 | char *p = str; |
15465 | const struct asm_opcode * opcode; | |
b99bd4ef | 15466 | |
c19d1205 ZW |
15467 | /* Align the previous label if needed. */ |
15468 | if (last_label_seen != NULL) | |
b99bd4ef | 15469 | { |
c19d1205 ZW |
15470 | symbol_set_frag (last_label_seen, frag_now); |
15471 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
15472 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
15473 | } |
15474 | ||
c19d1205 ZW |
15475 | memset (&inst, '\0', sizeof (inst)); |
15476 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 15477 | |
c19d1205 ZW |
15478 | opcode = opcode_lookup (&p); |
15479 | if (!opcode) | |
b99bd4ef | 15480 | { |
c19d1205 | 15481 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 15482 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d NC |
15483 | if (! create_register_alias (str, p) |
15484 | && ! create_neon_reg_alias (str, p)) | |
c19d1205 | 15485 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 15486 | |
b99bd4ef NC |
15487 | return; |
15488 | } | |
15489 | ||
278df34e | 15490 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
088fa78e KH |
15491 | as_warn (_("s suffix on comparison instruction is deprecated")); |
15492 | ||
037e8744 JB |
15493 | /* The value which unconditional instructions should have in place of the |
15494 | condition field. */ | |
15495 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
15496 | ||
c19d1205 | 15497 | if (thumb_mode) |
b99bd4ef | 15498 | { |
e74cfd16 | 15499 | arm_feature_set variant; |
8f06b2d8 PB |
15500 | |
15501 | variant = cpu_variant; | |
15502 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
15503 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
15504 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 15505 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
15506 | if (!opcode->tvariant |
15507 | || (thumb_mode == 1 | |
15508 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 15509 | { |
c19d1205 | 15510 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
15511 | return; |
15512 | } | |
c19d1205 ZW |
15513 | if (inst.cond != COND_ALWAYS && !unified_syntax |
15514 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 15515 | { |
c19d1205 | 15516 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
15517 | return; |
15518 | } | |
15519 | ||
752d5da4 | 15520 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)) |
076d447c | 15521 | { |
7e806470 | 15522 | if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23 |
752d5da4 NC |
15523 | && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr) |
15524 | || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier))) | |
15525 | { | |
15526 | /* Two things are addressed here. | |
15527 | 1) Implicit require narrow instructions on Thumb-1. | |
15528 | This avoids relaxation accidentally introducing Thumb-2 | |
15529 | instructions. | |
15530 | 2) Reject wide instructions in non Thumb-2 cores. */ | |
15531 | if (inst.size_req == 0) | |
15532 | inst.size_req = 2; | |
15533 | else if (inst.size_req == 4) | |
15534 | { | |
15535 | as_bad (_("selected processor does not support `%s'"), str); | |
15536 | return; | |
15537 | } | |
15538 | } | |
076d447c PB |
15539 | } |
15540 | ||
c19d1205 ZW |
15541 | inst.instruction = opcode->tvalue; |
15542 | ||
15543 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15544 | { |
15545 | /* Prepare the it_insn_type for those encodings that don't set | |
15546 | it. */ | |
15547 | it_fsm_pre_encode (); | |
c19d1205 | 15548 | |
e07e6e58 NC |
15549 | opcode->tencode (); |
15550 | ||
15551 | it_fsm_post_encode (); | |
15552 | } | |
e27ec89e | 15553 | |
0110f2b8 | 15554 | if (!(inst.error || inst.relax)) |
b99bd4ef | 15555 | { |
9c2799c2 | 15556 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
15557 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
15558 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 15559 | { |
c19d1205 | 15560 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
15561 | return; |
15562 | } | |
15563 | } | |
076d447c PB |
15564 | |
15565 | /* Something has gone badly wrong if we try to relax a fixed size | |
15566 | instruction. */ | |
9c2799c2 | 15567 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 15568 | |
e74cfd16 PB |
15569 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15570 | *opcode->tvariant); | |
ee065d83 | 15571 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 15572 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
7e806470 | 15573 | anything other than bl/blx and v6-M instructions. |
ee065d83 | 15574 | This is overly pessimistic for relaxable instructions. */ |
7e806470 PB |
15575 | if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) |
15576 | || inst.relax) | |
e07e6e58 NC |
15577 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
15578 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
e74cfd16 PB |
15579 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15580 | arm_ext_v6t2); | |
cd000bff DJ |
15581 | |
15582 | if (!inst.error) | |
c877a2f2 NC |
15583 | { |
15584 | mapping_state (MAP_THUMB); | |
15585 | } | |
c19d1205 | 15586 | } |
3e9e4fcf | 15587 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 15588 | { |
845b51d6 PB |
15589 | bfd_boolean is_bx; |
15590 | ||
15591 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
15592 | is_bx = (opcode->aencode == do_bx); | |
15593 | ||
c19d1205 | 15594 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
15595 | if (!(is_bx && fix_v4bx) |
15596 | && !(opcode->avariant && | |
15597 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 15598 | { |
c19d1205 ZW |
15599 | as_bad (_("selected processor does not support `%s'"), str); |
15600 | return; | |
b99bd4ef | 15601 | } |
c19d1205 | 15602 | if (inst.size_req) |
b99bd4ef | 15603 | { |
c19d1205 ZW |
15604 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
15605 | return; | |
b99bd4ef NC |
15606 | } |
15607 | ||
c19d1205 ZW |
15608 | inst.instruction = opcode->avalue; |
15609 | if (opcode->tag == OT_unconditionalF) | |
15610 | inst.instruction |= 0xF << 28; | |
15611 | else | |
15612 | inst.instruction |= inst.cond << 28; | |
15613 | inst.size = INSN_SIZE; | |
15614 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15615 | { |
15616 | it_fsm_pre_encode (); | |
15617 | opcode->aencode (); | |
15618 | it_fsm_post_encode (); | |
15619 | } | |
ee065d83 PB |
15620 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
15621 | on a hypothetical non-thumb v5 core. */ | |
845b51d6 | 15622 | if (is_bx) |
e74cfd16 | 15623 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 15624 | else |
e74cfd16 PB |
15625 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
15626 | *opcode->avariant); | |
cd000bff | 15627 | if (!inst.error) |
c877a2f2 NC |
15628 | { |
15629 | mapping_state (MAP_ARM); | |
15630 | } | |
b99bd4ef | 15631 | } |
3e9e4fcf JB |
15632 | else |
15633 | { | |
15634 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
15635 | "-- `%s'"), str); | |
15636 | return; | |
15637 | } | |
c19d1205 ZW |
15638 | output_inst (str); |
15639 | } | |
b99bd4ef | 15640 | |
e07e6e58 NC |
15641 | static void |
15642 | check_it_blocks_finished (void) | |
15643 | { | |
15644 | #ifdef OBJ_ELF | |
15645 | asection *sect; | |
15646 | ||
15647 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
15648 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
15649 | == MANUAL_IT_BLOCK) | |
15650 | { | |
15651 | as_warn (_("section '%s' finished with an open IT block."), | |
15652 | sect->name); | |
15653 | } | |
15654 | #else | |
15655 | if (now_it.state == MANUAL_IT_BLOCK) | |
15656 | as_warn (_("file finished with an open IT block.")); | |
15657 | #endif | |
15658 | } | |
15659 | ||
c19d1205 ZW |
15660 | /* Various frobbings of labels and their addresses. */ |
15661 | ||
15662 | void | |
15663 | arm_start_line_hook (void) | |
15664 | { | |
15665 | last_label_seen = NULL; | |
b99bd4ef NC |
15666 | } |
15667 | ||
c19d1205 ZW |
15668 | void |
15669 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 15670 | { |
c19d1205 | 15671 | last_label_seen = sym; |
b99bd4ef | 15672 | |
c19d1205 | 15673 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 15674 | |
c19d1205 ZW |
15675 | #if defined OBJ_COFF || defined OBJ_ELF |
15676 | ARM_SET_INTERWORK (sym, support_interwork); | |
15677 | #endif | |
b99bd4ef | 15678 | |
e07e6e58 NC |
15679 | force_automatic_it_block_close (); |
15680 | ||
5f4273c7 | 15681 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
15682 | as Thumb functions. This is because these labels, whilst |
15683 | they exist inside Thumb code, are not the entry points for | |
15684 | possible ARM->Thumb calls. Also, these labels can be used | |
15685 | as part of a computed goto or switch statement. eg gcc | |
15686 | can generate code that looks like this: | |
b99bd4ef | 15687 | |
c19d1205 ZW |
15688 | ldr r2, [pc, .Laaa] |
15689 | lsl r3, r3, #2 | |
15690 | ldr r2, [r3, r2] | |
15691 | mov pc, r2 | |
b99bd4ef | 15692 | |
c19d1205 ZW |
15693 | .Lbbb: .word .Lxxx |
15694 | .Lccc: .word .Lyyy | |
15695 | ..etc... | |
15696 | .Laaa: .word Lbbb | |
b99bd4ef | 15697 | |
c19d1205 ZW |
15698 | The first instruction loads the address of the jump table. |
15699 | The second instruction converts a table index into a byte offset. | |
15700 | The third instruction gets the jump address out of the table. | |
15701 | The fourth instruction performs the jump. | |
b99bd4ef | 15702 | |
c19d1205 ZW |
15703 | If the address stored at .Laaa is that of a symbol which has the |
15704 | Thumb_Func bit set, then the linker will arrange for this address | |
15705 | to have the bottom bit set, which in turn would mean that the | |
15706 | address computation performed by the third instruction would end | |
15707 | up with the bottom bit set. Since the ARM is capable of unaligned | |
15708 | word loads, the instruction would then load the incorrect address | |
15709 | out of the jump table, and chaos would ensue. */ | |
15710 | if (label_is_thumb_function_name | |
15711 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
15712 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 15713 | { |
c19d1205 ZW |
15714 | /* When the address of a Thumb function is taken the bottom |
15715 | bit of that address should be set. This will allow | |
15716 | interworking between Arm and Thumb functions to work | |
15717 | correctly. */ | |
b99bd4ef | 15718 | |
c19d1205 | 15719 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 15720 | |
c19d1205 | 15721 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 15722 | } |
07a53e5c | 15723 | |
07a53e5c | 15724 | dwarf2_emit_label (sym); |
b99bd4ef NC |
15725 | } |
15726 | ||
c921be7d | 15727 | bfd_boolean |
c19d1205 | 15728 | arm_data_in_code (void) |
b99bd4ef | 15729 | { |
c19d1205 | 15730 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 15731 | { |
c19d1205 ZW |
15732 | *input_line_pointer = '/'; |
15733 | input_line_pointer += 5; | |
15734 | *input_line_pointer = 0; | |
c921be7d | 15735 | return TRUE; |
b99bd4ef NC |
15736 | } |
15737 | ||
c921be7d | 15738 | return FALSE; |
b99bd4ef NC |
15739 | } |
15740 | ||
c19d1205 ZW |
15741 | char * |
15742 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 15743 | { |
c19d1205 | 15744 | int len; |
b99bd4ef | 15745 | |
c19d1205 ZW |
15746 | if (thumb_mode && (len = strlen (name)) > 5 |
15747 | && streq (name + len - 5, "/data")) | |
15748 | *(name + len - 5) = 0; | |
b99bd4ef | 15749 | |
c19d1205 | 15750 | return name; |
b99bd4ef | 15751 | } |
c19d1205 ZW |
15752 | \f |
15753 | /* Table of all register names defined by default. The user can | |
15754 | define additional names with .req. Note that all register names | |
15755 | should appear in both upper and lowercase variants. Some registers | |
15756 | also have mixed-case names. */ | |
b99bd4ef | 15757 | |
dcbf9037 | 15758 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 15759 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 15760 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
15761 | #define REGSET(p,t) \ |
15762 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
15763 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
15764 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
15765 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
15766 | #define REGSETH(p,t) \ |
15767 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
15768 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
15769 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
15770 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
15771 | #define REGSET2(p,t) \ | |
15772 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
15773 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
15774 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
15775 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
7ed4c4c5 | 15776 | |
c19d1205 | 15777 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 15778 | { |
c19d1205 ZW |
15779 | /* ARM integer registers. */ |
15780 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 15781 | |
c19d1205 ZW |
15782 | /* ATPCS synonyms. */ |
15783 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
15784 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
15785 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 15786 | |
c19d1205 ZW |
15787 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
15788 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
15789 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 15790 | |
c19d1205 ZW |
15791 | /* Well-known aliases. */ |
15792 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
15793 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
15794 | ||
15795 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
15796 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
15797 | ||
15798 | /* Coprocessor numbers. */ | |
15799 | REGSET(p, CP), REGSET(P, CP), | |
15800 | ||
15801 | /* Coprocessor register numbers. The "cr" variants are for backward | |
15802 | compatibility. */ | |
15803 | REGSET(c, CN), REGSET(C, CN), | |
15804 | REGSET(cr, CN), REGSET(CR, CN), | |
15805 | ||
15806 | /* FPA registers. */ | |
15807 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
15808 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
15809 | ||
15810 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
15811 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
15812 | ||
15813 | /* VFP SP registers. */ | |
5287ad62 JB |
15814 | REGSET(s,VFS), REGSET(S,VFS), |
15815 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
15816 | |
15817 | /* VFP DP Registers. */ | |
5287ad62 JB |
15818 | REGSET(d,VFD), REGSET(D,VFD), |
15819 | /* Extra Neon DP registers. */ | |
15820 | REGSETH(d,VFD), REGSETH(D,VFD), | |
15821 | ||
15822 | /* Neon QP registers. */ | |
15823 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
15824 | |
15825 | /* VFP control registers. */ | |
15826 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
15827 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
15828 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
15829 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
15830 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
15831 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
15832 | |
15833 | /* Maverick DSP coprocessor registers. */ | |
15834 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
15835 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
15836 | ||
15837 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
15838 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
15839 | REGDEF(dspsc,0,DSPSC), | |
15840 | ||
15841 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
15842 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
15843 | REGDEF(DSPSC,0,DSPSC), | |
15844 | ||
15845 | /* iWMMXt data registers - p0, c0-15. */ | |
15846 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
15847 | ||
15848 | /* iWMMXt control registers - p1, c0-3. */ | |
15849 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
15850 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
15851 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
15852 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
15853 | ||
15854 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
15855 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
15856 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
15857 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
15858 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
15859 | ||
15860 | /* XScale accumulator registers. */ | |
15861 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
15862 | }; | |
15863 | #undef REGDEF | |
15864 | #undef REGNUM | |
15865 | #undef REGSET | |
7ed4c4c5 | 15866 | |
c19d1205 ZW |
15867 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
15868 | within psr_required_here. */ | |
15869 | static const struct asm_psr psrs[] = | |
15870 | { | |
15871 | /* Backward compatibility notation. Note that "all" is no longer | |
15872 | truly all possible PSR bits. */ | |
15873 | {"all", PSR_c | PSR_f}, | |
15874 | {"flg", PSR_f}, | |
15875 | {"ctl", PSR_c}, | |
15876 | ||
15877 | /* Individual flags. */ | |
15878 | {"f", PSR_f}, | |
15879 | {"c", PSR_c}, | |
15880 | {"x", PSR_x}, | |
15881 | {"s", PSR_s}, | |
15882 | /* Combinations of flags. */ | |
15883 | {"fs", PSR_f | PSR_s}, | |
15884 | {"fx", PSR_f | PSR_x}, | |
15885 | {"fc", PSR_f | PSR_c}, | |
15886 | {"sf", PSR_s | PSR_f}, | |
15887 | {"sx", PSR_s | PSR_x}, | |
15888 | {"sc", PSR_s | PSR_c}, | |
15889 | {"xf", PSR_x | PSR_f}, | |
15890 | {"xs", PSR_x | PSR_s}, | |
15891 | {"xc", PSR_x | PSR_c}, | |
15892 | {"cf", PSR_c | PSR_f}, | |
15893 | {"cs", PSR_c | PSR_s}, | |
15894 | {"cx", PSR_c | PSR_x}, | |
15895 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
15896 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
15897 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
15898 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
15899 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
15900 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
15901 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
15902 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
15903 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
15904 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
15905 | {"scf", PSR_s | PSR_c | PSR_f}, | |
15906 | {"scx", PSR_s | PSR_c | PSR_x}, | |
15907 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
15908 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
15909 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
15910 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
15911 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
15912 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
15913 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
15914 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
15915 | {"csf", PSR_c | PSR_s | PSR_f}, | |
15916 | {"csx", PSR_c | PSR_s | PSR_x}, | |
15917 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
15918 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
15919 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
15920 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
15921 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
15922 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
15923 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
15924 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
15925 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
15926 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
15927 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
15928 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
15929 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
15930 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
15931 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
15932 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
15933 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
15934 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
15935 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
15936 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
15937 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
15938 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
15939 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
15940 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
15941 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
15942 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
15943 | }; | |
15944 | ||
62b3e311 PB |
15945 | /* Table of V7M psr names. */ |
15946 | static const struct asm_psr v7m_psrs[] = | |
15947 | { | |
2b744c99 PB |
15948 | {"apsr", 0 }, {"APSR", 0 }, |
15949 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
15950 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
15951 | {"psr", 3 }, {"PSR", 3 }, | |
15952 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
15953 | {"ipsr", 5 }, {"IPSR", 5 }, | |
15954 | {"epsr", 6 }, {"EPSR", 6 }, | |
15955 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
15956 | {"msp", 8 }, {"MSP", 8 }, | |
15957 | {"psp", 9 }, {"PSP", 9 }, | |
15958 | {"primask", 16}, {"PRIMASK", 16}, | |
15959 | {"basepri", 17}, {"BASEPRI", 17}, | |
15960 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, | |
15961 | {"faultmask", 19}, {"FAULTMASK", 19}, | |
15962 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
15963 | }; |
15964 | ||
c19d1205 ZW |
15965 | /* Table of all shift-in-operand names. */ |
15966 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 15967 | { |
c19d1205 ZW |
15968 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
15969 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
15970 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
15971 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
15972 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
15973 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
15974 | }; | |
b99bd4ef | 15975 | |
c19d1205 ZW |
15976 | /* Table of all explicit relocation names. */ |
15977 | #ifdef OBJ_ELF | |
15978 | static struct reloc_entry reloc_names[] = | |
15979 | { | |
15980 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
15981 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
15982 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
15983 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
15984 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
15985 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
15986 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
15987 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
15988 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
15989 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
15990 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
15991 | }; | |
15992 | #endif | |
b99bd4ef | 15993 | |
c19d1205 ZW |
15994 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
15995 | static const struct asm_cond conds[] = | |
15996 | { | |
15997 | {"eq", 0x0}, | |
15998 | {"ne", 0x1}, | |
15999 | {"cs", 0x2}, {"hs", 0x2}, | |
16000 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
16001 | {"mi", 0x4}, | |
16002 | {"pl", 0x5}, | |
16003 | {"vs", 0x6}, | |
16004 | {"vc", 0x7}, | |
16005 | {"hi", 0x8}, | |
16006 | {"ls", 0x9}, | |
16007 | {"ge", 0xa}, | |
16008 | {"lt", 0xb}, | |
16009 | {"gt", 0xc}, | |
16010 | {"le", 0xd}, | |
16011 | {"al", 0xe} | |
16012 | }; | |
bfae80f2 | 16013 | |
62b3e311 PB |
16014 | static struct asm_barrier_opt barrier_opt_names[] = |
16015 | { | |
16016 | { "sy", 0xf }, | |
16017 | { "un", 0x7 }, | |
16018 | { "st", 0xe }, | |
16019 | { "unst", 0x6 } | |
16020 | }; | |
16021 | ||
c19d1205 ZW |
16022 | /* Table of ARM-format instructions. */ |
16023 | ||
16024 | /* Macros for gluing together operand strings. N.B. In all cases | |
16025 | other than OPS0, the trailing OP_stop comes from default | |
16026 | zero-initialization of the unspecified elements of the array. */ | |
16027 | #define OPS0() { OP_stop, } | |
16028 | #define OPS1(a) { OP_##a, } | |
16029 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
16030 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
16031 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
16032 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
16033 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
16034 | ||
16035 | /* These macros abstract out the exact format of the mnemonic table and | |
16036 | save some repeated characters. */ | |
16037 | ||
16038 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
16039 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16040 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 16041 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16042 | |
16043 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
16044 | a T_MNEM_xyz enumerator. */ | |
16045 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 16046 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 16047 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 16048 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
16049 | |
16050 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
16051 | infix after the third character. */ | |
16052 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16053 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 16054 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 16055 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 16056 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 16057 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 16058 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16059 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 16060 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16061 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 16062 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 16063 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 16064 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 16065 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
16066 | |
16067 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
16068 | appear in the condition table. */ | |
16069 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16070 | { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ |
1887dd22 | 16071 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16072 | |
16073 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
16074 | TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \ |
16075 | TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \ | |
16076 | TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \ | |
16077 | TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \ | |
16078 | TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \ | |
16079 | TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \ | |
16080 | TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \ | |
16081 | TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \ | |
16082 | TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \ | |
16083 | TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \ | |
16084 | TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \ | |
16085 | TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \ | |
16086 | TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \ | |
16087 | TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \ | |
16088 | TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \ | |
16089 | TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \ | |
16090 | TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \ | |
16091 | TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \ | |
16092 | TxCM_ (m1, al, m2, op, top, nops, ops, ae, te) | |
c19d1205 ZW |
16093 | |
16094 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
16095 | TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te) |
16096 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
21d799b5 | 16097 | TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
16098 | |
16099 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
16100 | field is still 0xE. Many of the Thumb variants can be executed |
16101 | conditionally, so this is checked separately. */ | |
c19d1205 | 16102 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 16103 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 16104 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16105 | |
16106 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
16107 | condition code field. */ | |
16108 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16109 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 16110 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16111 | |
16112 | /* ARM-only variants of all the above. */ | |
6a86118a | 16113 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 16114 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
16115 | |
16116 | #define C3(mnem, op, nops, ops, ae) \ | |
16117 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
16118 | ||
e3cb604e PB |
16119 | /* Legacy mnemonics that always have conditional infix after the third |
16120 | character. */ | |
16121 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16122 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
16123 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
16124 | ||
8f06b2d8 PB |
16125 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
16126 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16127 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 16128 | |
e3cb604e PB |
16129 | /* Legacy coprocessor instructions where conditional infix and conditional |
16130 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
16131 | not just the potentially ambiguous ones. */ | |
16132 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16133 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
16134 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
16135 | ||
16136 | /* Coprocessor, takes either a suffix or a position-3 infix | |
16137 | (for an FPA corner case). */ | |
16138 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16139 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 16140 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 16141 | |
6a86118a | 16142 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
16143 | { m1 #m2 m3, OPS##nops ops, \ |
16144 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
16145 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
16146 | ||
16147 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
16148 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
16149 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
16150 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
16151 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
16152 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
16153 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
16154 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
16155 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
16156 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
16157 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
16158 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
16159 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
16160 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
16161 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
16162 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
16163 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
16164 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
16165 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
16166 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
16167 | |
16168 | #define UE(mnem, op, nops, ops, ae) \ | |
16169 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16170 | ||
16171 | #define UF(mnem, op, nops, ops, ae) \ | |
16172 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16173 | ||
5287ad62 JB |
16174 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
16175 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
16176 | use the same encoding function for each. */ | |
16177 | #define NUF(mnem, op, nops, ops, enc) \ | |
16178 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
16179 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16180 | ||
16181 | /* Neon data processing, version which indirects through neon_enc_tab for | |
16182 | the various overloaded versions of opcodes. */ | |
16183 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 16184 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
16185 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
16186 | ||
16187 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
16188 | version. */ | |
037e8744 JB |
16189 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
16190 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
16191 | THUMB_VARIANT, do_##enc, do_##enc } |
16192 | ||
037e8744 | 16193 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16194 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16195 | |
16196 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16197 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16198 | |
5287ad62 | 16199 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 16200 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 16201 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
16202 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
16203 | ||
037e8744 | 16204 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16205 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16206 | |
16207 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16208 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16209 | |
c19d1205 ZW |
16210 | #define do_0 0 |
16211 | ||
16212 | /* Thumb-only, unconditional. */ | |
e07e6e58 | 16213 | #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te) |
c19d1205 | 16214 | |
c19d1205 | 16215 | static const struct asm_opcode insns[] = |
bfae80f2 | 16216 | { |
e74cfd16 PB |
16217 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
16218 | #define THUMB_VARIANT &arm_ext_v4t | |
21d799b5 NC |
16219 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
16220 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
16221 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
16222 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
16223 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
16224 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
16225 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
16226 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
16227 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
16228 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16229 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
16230 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
16231 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
16232 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16233 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
16234 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
16235 | |
16236 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
16237 | for setting PSR flag bits. They are obsolete in V6 and do not | |
16238 | have Thumb equivalents. */ | |
21d799b5 NC |
16239 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
16240 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
16241 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
16242 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
16243 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
16244 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
16245 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
16246 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
16247 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
16248 | ||
16249 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
16250 | tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp), | |
16251 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), | |
16252 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
16253 | ||
16254 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16255 | tC3("ldrb", 4500000, _ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16256 | tCE("str", 4000000, _str, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16257 | tC3("strb", 4400000, _strb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16258 | ||
16259 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16260 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16261 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16262 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16263 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16264 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16265 | ||
16266 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
16267 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
16268 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), | |
16269 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 16270 | |
c19d1205 | 16271 | /* Pseudo ops. */ |
21d799b5 | 16272 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 16273 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 16274 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
c19d1205 ZW |
16275 | |
16276 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
16277 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
16278 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
16279 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
16280 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
16281 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
16282 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
16283 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
16284 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
16285 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
16286 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
16287 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
16288 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 16289 | |
16a4cf17 | 16290 | /* These may simplify to neg. */ |
21d799b5 NC |
16291 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
16292 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 16293 | |
c921be7d NC |
16294 | #undef THUMB_VARIANT |
16295 | #define THUMB_VARIANT & arm_ext_v6 | |
16296 | ||
21d799b5 | 16297 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
16298 | |
16299 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
16300 | #undef THUMB_VARIANT |
16301 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16302 | ||
21d799b5 NC |
16303 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
16304 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
16305 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 16306 | |
21d799b5 NC |
16307 | TC3("ldrt", 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), |
16308 | TC3("ldrbt", 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
16309 | TC3("strt", 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
16310 | TC3("strbt", 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
c19d1205 | 16311 | |
21d799b5 NC |
16312 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16313 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 16314 | |
21d799b5 NC |
16315 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16316 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
16317 | |
16318 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 16319 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
16320 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
16321 | ||
16322 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
16323 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
16324 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
16325 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
16326 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
16327 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
16328 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
16329 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
16330 | ||
c921be7d NC |
16331 | #undef ARM_VARIANT |
16332 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
16333 | #undef THUMB_VARIANT | |
16334 | #define THUMB_VARIANT & arm_ext_v4t | |
16335 | ||
21d799b5 NC |
16336 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
16337 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 16338 | |
c921be7d NC |
16339 | #undef THUMB_VARIANT |
16340 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16341 | ||
21d799b5 | 16342 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
16343 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
16344 | ||
16345 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
16346 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
16347 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16348 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16349 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16350 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16351 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16352 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 16353 | |
c921be7d NC |
16354 | #undef ARM_VARIANT |
16355 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
16356 | ||
21d799b5 | 16357 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
16358 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
16359 | ||
c921be7d NC |
16360 | #undef ARM_VARIANT |
16361 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
16362 | #undef THUMB_VARIANT | |
16363 | #define THUMB_VARIANT & arm_ext_msr | |
16364 | ||
21d799b5 NC |
16365 | TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
16366 | TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), | |
c19d1205 | 16367 | |
c921be7d NC |
16368 | #undef ARM_VARIANT |
16369 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
16370 | #undef THUMB_VARIANT | |
16371 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16372 | ||
21d799b5 NC |
16373 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
16374 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16375 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16376 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16377 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16378 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16379 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16380 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 16381 | |
c921be7d NC |
16382 | #undef ARM_VARIANT |
16383 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
16384 | #undef THUMB_VARIANT | |
16385 | #define THUMB_VARIANT & arm_ext_v4t | |
16386 | ||
21d799b5 NC |
16387 | tC3("ldrh", 01000b0, _ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), |
16388 | tC3("strh", 00000b0, _strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16389 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16390 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16391 | tCM("ld","sh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16392 | tCM("ld","sb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 16393 | |
c921be7d NC |
16394 | #undef ARM_VARIANT |
16395 | #define ARM_VARIANT & arm_ext_v4t_5 | |
16396 | ||
c19d1205 ZW |
16397 | /* ARM Architecture 4T. */ |
16398 | /* Note: bx (and blx) are required on V5, even if the processor does | |
16399 | not support Thumb. */ | |
21d799b5 | 16400 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 16401 | |
c921be7d NC |
16402 | #undef ARM_VARIANT |
16403 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
16404 | #undef THUMB_VARIANT | |
16405 | #define THUMB_VARIANT & arm_ext_v5t | |
16406 | ||
c19d1205 ZW |
16407 | /* Note: blx has 2 variants; the .value coded here is for |
16408 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
16409 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
16410 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 16411 | |
c921be7d NC |
16412 | #undef THUMB_VARIANT |
16413 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16414 | ||
21d799b5 NC |
16415 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
16416 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16417 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16418 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16419 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16420 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
16421 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16422 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 16423 | |
c921be7d NC |
16424 | #undef ARM_VARIANT |
16425 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ | |
16426 | ||
21d799b5 NC |
16427 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16428 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16429 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16430 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 16431 | |
21d799b5 NC |
16432 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16433 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 16434 | |
21d799b5 NC |
16435 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
16436 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16437 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16438 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 16439 | |
21d799b5 NC |
16440 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
16441 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16442 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16443 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 16444 | |
21d799b5 NC |
16445 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
16446 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 16447 | |
21d799b5 NC |
16448 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), |
16449 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16450 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16451 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
c19d1205 | 16452 | |
c921be7d NC |
16453 | #undef ARM_VARIANT |
16454 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ | |
16455 | ||
21d799b5 NC |
16456 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
16457 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
16458 | TC3("strd", 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 16459 | |
21d799b5 NC |
16460 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
16461 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 16462 | |
c921be7d NC |
16463 | #undef ARM_VARIANT |
16464 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
16465 | ||
21d799b5 | 16466 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 16467 | |
c921be7d NC |
16468 | #undef ARM_VARIANT |
16469 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
16470 | #undef THUMB_VARIANT | |
16471 | #define THUMB_VARIANT & arm_ext_v6 | |
16472 | ||
21d799b5 NC |
16473 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
16474 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
16475 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16476 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16477 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16478 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16479 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16480 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16481 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16482 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 16483 | |
c921be7d NC |
16484 | #undef THUMB_VARIANT |
16485 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16486 | ||
21d799b5 NC |
16487 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
16488 | TCE("strex", 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), | |
16489 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16490 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 16491 | |
21d799b5 NC |
16492 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
16493 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 PB |
16494 | |
16495 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
c921be7d NC |
16496 | #undef THUMB_VARIANT |
16497 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16498 | ||
21d799b5 NC |
16499 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
16500 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), | |
16501 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
16502 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16503 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16504 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16505 | /* Old name for QASX. */ |
21d799b5 NC |
16506 | TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16507 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16508 | /* Old name for QSAX. */ |
21d799b5 NC |
16509 | TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16510 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16511 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16512 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16513 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16514 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16515 | /* Old name for SASX. */ |
21d799b5 NC |
16516 | TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16517 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16518 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16519 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16520 | /* Old name for SHASX. */ |
21d799b5 NC |
16521 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16522 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16523 | /* Old name for SHSAX. */ |
21d799b5 NC |
16524 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16525 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16526 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16527 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16528 | /* Old name for SSAX. */ |
21d799b5 NC |
16529 | TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16530 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16531 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16532 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16533 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16534 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16535 | /* Old name for UASX. */ |
21d799b5 NC |
16536 | TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16537 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16538 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16539 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16540 | /* Old name for UHASX. */ |
21d799b5 NC |
16541 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16542 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16543 | /* Old name for UHSAX. */ |
21d799b5 NC |
16544 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16545 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16546 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16547 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16548 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16549 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16550 | /* Old name for UQASX. */ |
21d799b5 NC |
16551 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16552 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16553 | /* Old name for UQSAX. */ |
21d799b5 NC |
16554 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16555 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16556 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16557 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16558 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 16559 | /* Old name for USAX. */ |
21d799b5 NC |
16560 | TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16561 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16562 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
c19d1205 ZW |
16563 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
16564 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
21d799b5 NC |
16565 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), |
16566 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
c19d1205 ZW |
16567 | UF(rfefa, 9900a00, 1, (RRw), rfe), |
16568 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
21d799b5 NC |
16569 | TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe), |
16570 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16571 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16572 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16573 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16574 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16575 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16576 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16577 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16578 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16579 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16580 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16581 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16582 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16583 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16584 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16585 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16586 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16587 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16588 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16589 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16590 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16591 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16592 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16593 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16594 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16595 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16596 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16597 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
b6702015 PB |
16598 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
16599 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), | |
21d799b5 NC |
16600 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
16601 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), | |
16602 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
16603 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16604 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16605 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 16606 | |
c921be7d NC |
16607 | #undef ARM_VARIANT |
16608 | #define ARM_VARIANT & arm_ext_v6k | |
16609 | #undef THUMB_VARIANT | |
16610 | #define THUMB_VARIANT & arm_ext_v6k | |
16611 | ||
21d799b5 NC |
16612 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
16613 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
16614 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
16615 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 16616 | |
c921be7d NC |
16617 | #undef THUMB_VARIANT |
16618 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16619 | ||
21d799b5 NC |
16620 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), |
16621 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
ebdca51a | 16622 | |
c921be7d NC |
16623 | #undef THUMB_VARIANT |
16624 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16625 | ||
21d799b5 NC |
16626 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
16627 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
16628 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
16629 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
16630 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), | |
c19d1205 | 16631 | |
c921be7d NC |
16632 | #undef ARM_VARIANT |
16633 | #define ARM_VARIANT & arm_ext_v6z | |
16634 | ||
21d799b5 | 16635 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 16636 | |
c921be7d NC |
16637 | #undef ARM_VARIANT |
16638 | #define ARM_VARIANT & arm_ext_v6t2 | |
16639 | ||
21d799b5 NC |
16640 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
16641 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
16642 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16643 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 16644 | |
21d799b5 NC |
16645 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
16646 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
16647 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
16648 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), | |
c19d1205 | 16649 | |
21d799b5 NC |
16650 | TC3("ldrht", 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), |
16651 | TC3("ldrsht", 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16652 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16653 | TC3("strht", 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 16654 | |
21d799b5 NC |
16655 | UT("cbnz", b900, 2, (RR, EXP), t_cbz), |
16656 | UT("cbz", b100, 2, (RR, EXP), t_cbz), | |
c921be7d NC |
16657 | |
16658 | /* ARM does not really have an IT instruction, so always allow it. | |
16659 | The opcode is copied from Thumb in order to allow warnings in | |
16660 | -mimplicit-it=[never | arm] modes. */ | |
16661 | #undef ARM_VARIANT | |
16662 | #define ARM_VARIANT & arm_ext_v1 | |
16663 | ||
21d799b5 NC |
16664 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
16665 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
16666 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
16667 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
16668 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
16669 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
16670 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
16671 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
16672 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
16673 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
16674 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
16675 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
16676 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
16677 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
16678 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 16679 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
16680 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
16681 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 16682 | |
92e90b6e | 16683 | /* Thumb2 only instructions. */ |
c921be7d NC |
16684 | #undef ARM_VARIANT |
16685 | #define ARM_VARIANT NULL | |
92e90b6e | 16686 | |
21d799b5 NC |
16687 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
16688 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
16689 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
16690 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
16691 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
16692 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 16693 | |
62b3e311 | 16694 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
c921be7d NC |
16695 | #undef THUMB_VARIANT |
16696 | #define THUMB_VARIANT & arm_ext_div | |
16697 | ||
21d799b5 NC |
16698 | TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), |
16699 | TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
62b3e311 | 16700 | |
7e806470 | 16701 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
16702 | #undef ARM_VARIANT |
16703 | #define ARM_VARIANT & arm_ext_barrier | |
16704 | #undef THUMB_VARIANT | |
16705 | #define THUMB_VARIANT & arm_ext_barrier | |
16706 | ||
21d799b5 NC |
16707 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), |
16708 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
16709 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
7e806470 | 16710 | |
62b3e311 | 16711 | /* ARM V7 instructions. */ |
c921be7d NC |
16712 | #undef ARM_VARIANT |
16713 | #define ARM_VARIANT & arm_ext_v7 | |
16714 | #undef THUMB_VARIANT | |
16715 | #define THUMB_VARIANT & arm_ext_v7 | |
16716 | ||
21d799b5 NC |
16717 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
16718 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 16719 | |
c921be7d NC |
16720 | #undef ARM_VARIANT |
16721 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
16722 | ||
21d799b5 NC |
16723 | cCE("wfs", e200110, 1, (RR), rd), |
16724 | cCE("rfs", e300110, 1, (RR), rd), | |
16725 | cCE("wfc", e400110, 1, (RR), rd), | |
16726 | cCE("rfc", e500110, 1, (RR), rd), | |
16727 | ||
16728 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16729 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16730 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16731 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16732 | ||
16733 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16734 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16735 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16736 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16737 | ||
16738 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
16739 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
16740 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
16741 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
16742 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
16743 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
16744 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
16745 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
16746 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
16747 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
16748 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
16749 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
16750 | ||
16751 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
16752 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
16753 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
16754 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
16755 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
16756 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
16757 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
16758 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
16759 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
16760 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
16761 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
16762 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
16763 | ||
16764 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
16765 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
16766 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
16767 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
16768 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
16769 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
16770 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
16771 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
16772 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
16773 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
16774 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
16775 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
16776 | ||
16777 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
16778 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
16779 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
16780 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
16781 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
16782 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
16783 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
16784 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
16785 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
16786 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
16787 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
16788 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
16789 | ||
16790 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
16791 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
16792 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
16793 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
16794 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
16795 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
16796 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
16797 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
16798 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
16799 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
16800 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
16801 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
16802 | ||
16803 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
16804 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
16805 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
16806 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
16807 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
16808 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
16809 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
16810 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
16811 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
16812 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
16813 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
16814 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
16815 | ||
16816 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
16817 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
16818 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
16819 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
16820 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
16821 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
16822 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
16823 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
16824 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
16825 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
16826 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
16827 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
16828 | ||
16829 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
16830 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
16831 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
16832 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
16833 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
16834 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
16835 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
16836 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
16837 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
16838 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
16839 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
16840 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
16841 | ||
16842 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
16843 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
16844 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
16845 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
16846 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
16847 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
16848 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
16849 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
16850 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
16851 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
16852 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
16853 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
16854 | ||
16855 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
16856 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
16857 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
16858 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
16859 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
16860 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
16861 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
16862 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
16863 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
16864 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
16865 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
16866 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
16867 | ||
16868 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
16869 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
16870 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
16871 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
16872 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
16873 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
16874 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
16875 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
16876 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
16877 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
16878 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
16879 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
16880 | ||
16881 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
16882 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
16883 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
16884 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
16885 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
16886 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
16887 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
16888 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
16889 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
16890 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
16891 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
16892 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
16893 | ||
16894 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
16895 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
16896 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
16897 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
16898 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
16899 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
16900 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
16901 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
16902 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
16903 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
16904 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
16905 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
16906 | ||
16907 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
16908 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
16909 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
16910 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
16911 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
16912 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
16913 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
16914 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
16915 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
16916 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
16917 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
16918 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
16919 | ||
16920 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
16921 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
16922 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
16923 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
16924 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
16925 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
16926 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
16927 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
16928 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
16929 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
16930 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
16931 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
16932 | ||
16933 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
16934 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
16935 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
16936 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
16937 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
16938 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
16939 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
16940 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
16941 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
16942 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
16943 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
16944 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
16945 | ||
16946 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16947 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16948 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16949 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16950 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16951 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16952 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16953 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16954 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16955 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16956 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16957 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16958 | ||
16959 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16960 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16961 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16962 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16963 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16964 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16965 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16966 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16967 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16968 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16969 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16970 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16971 | ||
16972 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16973 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16974 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16975 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16976 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16977 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16978 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16979 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16980 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16981 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16982 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16983 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16984 | ||
16985 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16986 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16987 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16988 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16989 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16990 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16991 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16992 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16993 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16994 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16995 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16996 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16997 | ||
16998 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16999 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17000 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17001 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17002 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17003 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17004 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17005 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17006 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17007 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17008 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17009 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17010 | ||
17011 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17012 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17013 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17014 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17015 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17016 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17017 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17018 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17019 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17020 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17021 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17022 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17023 | ||
17024 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17025 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17026 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17027 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17028 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17029 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17030 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17031 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17032 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17033 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17034 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17035 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17036 | ||
17037 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17038 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17039 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17040 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17041 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17042 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17043 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17044 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17045 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17046 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17047 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17048 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17049 | ||
17050 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17051 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17052 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17053 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17054 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17055 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17056 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17057 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17058 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17059 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17060 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17061 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17062 | ||
17063 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17064 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17065 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17066 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17067 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17068 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17069 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17070 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17071 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17072 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17073 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17074 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17075 | ||
17076 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17077 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17078 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17079 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17080 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17081 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17082 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17083 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17084 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17085 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17086 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17087 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17088 | ||
17089 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17090 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17091 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17092 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17093 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17094 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17095 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17096 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17097 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17098 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17099 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17100 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17101 | ||
17102 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17103 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17104 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17105 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17106 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17107 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17108 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17109 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17110 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17111 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17112 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17113 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17114 | ||
17115 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
17116 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
17117 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
17118 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
17119 | ||
17120 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
17121 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
17122 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
17123 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
17124 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
17125 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
17126 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
17127 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
17128 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
17129 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
17130 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
17131 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 17132 | |
c19d1205 ZW |
17133 | /* The implementation of the FIX instruction is broken on some |
17134 | assemblers, in that it accepts a precision specifier as well as a | |
17135 | rounding specifier, despite the fact that this is meaningless. | |
17136 | To be more compatible, we accept it as well, though of course it | |
17137 | does not set any bits. */ | |
21d799b5 NC |
17138 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
17139 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
17140 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
17141 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
17142 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
17143 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
17144 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
17145 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
17146 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
17147 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
17148 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
17149 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
17150 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 17151 | |
c19d1205 | 17152 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
17153 | #undef ARM_VARIANT |
17154 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
17155 | ||
21d799b5 NC |
17156 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
17157 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17158 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17159 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17160 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17161 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 17162 | |
c921be7d NC |
17163 | #undef ARM_VARIANT |
17164 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
17165 | ||
c19d1205 | 17166 | /* Moves and type conversions. */ |
21d799b5 NC |
17167 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
17168 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
17169 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
17170 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
17171 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17172 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17173 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17174 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17175 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17176 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17177 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
17178 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
17179 | |
17180 | /* Memory operations. */ | |
21d799b5 NC |
17181 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
17182 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
17183 | cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17184 | cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17185 | cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17186 | cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17187 | cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17188 | cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17189 | cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17190 | cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17191 | cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17192 | cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17193 | cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17194 | cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17195 | cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17196 | cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17197 | cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17198 | cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 17199 | |
c19d1205 | 17200 | /* Monadic operations. */ |
21d799b5 NC |
17201 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
17202 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17203 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
17204 | |
17205 | /* Dyadic operations. */ | |
21d799b5 NC |
17206 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
17207 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17208 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17209 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17210 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17211 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17212 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17213 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17214 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 17215 | |
c19d1205 | 17216 | /* Comparisons. */ |
21d799b5 NC |
17217 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
17218 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
17219 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17220 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 17221 | |
62f3b8c8 PB |
17222 | /* Double precision load/store are still present on single precision |
17223 | implementations. */ | |
17224 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
17225 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
17226 | cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17227 | cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17228 | cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17229 | cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17230 | cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17231 | cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17232 | cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17233 | cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17234 | ||
c921be7d NC |
17235 | #undef ARM_VARIANT |
17236 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
17237 | ||
c19d1205 | 17238 | /* Moves and type conversions. */ |
21d799b5 NC |
17239 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17240 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17241 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17242 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17243 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17244 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17245 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17246 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17247 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17248 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17249 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17250 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17251 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 17252 | |
c19d1205 | 17253 | /* Monadic operations. */ |
21d799b5 NC |
17254 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
17255 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17256 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
17257 | |
17258 | /* Dyadic operations. */ | |
21d799b5 NC |
17259 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
17260 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17261 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17262 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17263 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17264 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17265 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17266 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17267 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 17268 | |
c19d1205 | 17269 | /* Comparisons. */ |
21d799b5 NC |
17270 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17271 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
17272 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17273 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 17274 | |
c921be7d NC |
17275 | #undef ARM_VARIANT |
17276 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
17277 | ||
21d799b5 NC |
17278 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
17279 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
17280 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
17281 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 17282 | |
037e8744 JB |
17283 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
17284 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
17285 | #undef ARM_VARIANT |
17286 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
17287 | #undef THUMB_VARIANT | |
17288 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
17289 | ||
037e8744 JB |
17290 | /* These mnemonics are unique to VFP. */ |
17291 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
17292 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
17293 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
17294 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17295 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17296 | nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17297 | nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
037e8744 JB |
17298 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
17299 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
17300 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
17301 | ||
17302 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
17303 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
17304 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17305 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 17306 | |
21d799b5 NC |
17307 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
17308 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
17309 | |
17310 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17311 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17312 | ||
17313 | NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17314 | NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17315 | NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17316 | NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17317 | NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17318 | NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
17319 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
17320 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 | 17321 | |
21d799b5 NC |
17322 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), |
17323 | nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb), | |
17324 | nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt), | |
f31fef98 | 17325 | |
037e8744 JB |
17326 | |
17327 | /* NOTE: All VMOV encoding is special-cased! */ | |
17328 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
17329 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
17330 | ||
c921be7d NC |
17331 | #undef THUMB_VARIANT |
17332 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
17333 | #undef ARM_VARIANT | |
17334 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
17335 | ||
5287ad62 JB |
17336 | /* Data processing with three registers of the same length. */ |
17337 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
17338 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
17339 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
17340 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17341 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17342 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17343 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17344 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17345 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17346 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17347 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17348 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
17349 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17350 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
17351 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
17352 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
17353 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
17354 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
17355 | /* If not immediate, fall back to neon_dyadic_i64_su. |
17356 | shl_imm should accept I8 I16 I32 I64, | |
17357 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
17358 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
17359 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
17360 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
17361 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 17362 | /* Logic ops, types optional & ignored. */ |
21d799b5 NC |
17363 | nUF(vand, _vand, 2, (RNDQ, NILO), neon_logic), |
17364 | nUF(vandq, _vand, 2, (RNQ, NILO), neon_logic), | |
17365 | nUF(vbic, _vbic, 2, (RNDQ, NILO), neon_logic), | |
17366 | nUF(vbicq, _vbic, 2, (RNQ, NILO), neon_logic), | |
17367 | nUF(vorr, _vorr, 2, (RNDQ, NILO), neon_logic), | |
17368 | nUF(vorrq, _vorr, 2, (RNQ, NILO), neon_logic), | |
17369 | nUF(vorn, _vorn, 2, (RNDQ, NILO), neon_logic), | |
17370 | nUF(vornq, _vorn, 2, (RNQ, NILO), neon_logic), | |
17371 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
17372 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
17373 | /* Bitfield ops, untyped. */ |
17374 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17375 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17376 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17377 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17378 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17379 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17380 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
21d799b5 NC |
17381 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
17382 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17383 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17384 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17385 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17386 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
17387 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
17388 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
17389 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
17390 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17391 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17392 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17393 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17394 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
17395 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17396 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 17397 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
17398 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
17399 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 17400 | /* As above, D registers only. */ |
21d799b5 NC |
17401 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
17402 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 17403 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
17404 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
17405 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
17406 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 17407 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
17408 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
17409 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
17410 | /* vtst takes sizes 8, 16, 32. */ |
17411 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
17412 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
17413 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 17414 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 17415 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
17416 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
17417 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17418 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17419 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
17420 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
17421 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
17422 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17423 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
17424 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
17425 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
17426 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
17427 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
17428 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
17429 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17430 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
17431 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17432 | ||
17433 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 17434 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
17435 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
17436 | ||
17437 | /* Data processing with two registers and a shift amount. */ | |
17438 | /* Right shifts, and variants with rounding. | |
17439 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17440 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17441 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17442 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17443 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17444 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17445 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17446 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17447 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17448 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
17449 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
17450 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
17451 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
17452 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
17453 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17454 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
17455 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
17456 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
17457 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
17458 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17459 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17460 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
17461 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17462 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17463 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
17464 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17465 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17466 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 17467 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 17468 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 17469 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 17470 | |
21d799b5 NC |
17471 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn), |
17472 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn), | |
5287ad62 JB |
17473 | |
17474 | /* Data processing, three registers of different lengths. */ | |
17475 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
17476 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
17477 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17478 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17479 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17480 | /* If not scalar, fall back to neon_dyadic_long. | |
17481 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
17482 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
17483 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
17484 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
17485 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17486 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17487 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
17488 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17489 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17490 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17491 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17492 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
17493 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
17494 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17495 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
17496 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
17497 | S16 S32 U16 U32. */ | |
21d799b5 | 17498 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
17499 | |
17500 | /* Extract. Size 8. */ | |
3b8d421e PB |
17501 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
17502 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
17503 | |
17504 | /* Two registers, miscellaneous. */ | |
17505 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
17506 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
17507 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
17508 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
17509 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
17510 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
17511 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
17512 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
17513 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
17514 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
17515 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
17516 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
17517 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 17518 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 17519 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 17520 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 17521 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 17522 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
17523 | /* VZIP / VUZP. Sizes 8 16 32. */ |
17524 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17525 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
17526 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17527 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
17528 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
17529 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17530 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17531 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17532 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17533 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
17534 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
17535 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
17536 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
17537 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
17538 | /* Reciprocal estimates. Types U32 F32. */ | |
17539 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
17540 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
17541 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
17542 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
17543 | /* VCLS. Types S8 S16 S32. */ | |
17544 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
17545 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
17546 | /* VCLZ. Types I8 I16 I32. */ | |
17547 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
17548 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
17549 | /* VCNT. Size 8. */ | |
17550 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
17551 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
17552 | /* Two address, untyped. */ | |
17553 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
17554 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
17555 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
17556 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
17557 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
17558 | |
17559 | /* Table lookup. Size 8. */ | |
17560 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17561 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17562 | ||
c921be7d NC |
17563 | #undef THUMB_VARIANT |
17564 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
17565 | #undef ARM_VARIANT | |
17566 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
17567 | ||
5287ad62 | 17568 | /* Neon element/structure load/store. */ |
21d799b5 NC |
17569 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
17570 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17571 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17572 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17573 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17574 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17575 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17576 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 17577 | |
c921be7d | 17578 | #undef THUMB_VARIANT |
62f3b8c8 PB |
17579 | #define THUMB_VARIANT &fpu_vfp_ext_v3xd |
17580 | #undef ARM_VARIANT | |
17581 | #define ARM_VARIANT &fpu_vfp_ext_v3xd | |
17582 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), | |
17583 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17584 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17585 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17586 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17587 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17588 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17589 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17590 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17591 | ||
17592 | #undef THUMB_VARIANT | |
c921be7d NC |
17593 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
17594 | #undef ARM_VARIANT | |
17595 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
17596 | ||
21d799b5 | 17597 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 17598 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 17599 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 17600 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 17601 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 17602 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 17603 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 17604 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 17605 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 17606 | |
62f3b8c8 PB |
17607 | #undef ARM_VARIANT |
17608 | #define ARM_VARIANT &fpu_vfp_ext_fma | |
17609 | #undef THUMB_VARIANT | |
17610 | #define THUMB_VARIANT &fpu_vfp_ext_fma | |
17611 | /* Mnemonics shared by Neon and VFP. These are included in the | |
17612 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
17613 | FMA instructions. */ | |
17614 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
17615 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
17616 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
17617 | the v form should always be used. */ | |
17618 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17619 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17620 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17621 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17622 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17623 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17624 | ||
5287ad62 | 17625 | #undef THUMB_VARIANT |
c921be7d NC |
17626 | #undef ARM_VARIANT |
17627 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
17628 | ||
21d799b5 NC |
17629 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
17630 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17631 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17632 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17633 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17634 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17635 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
17636 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 17637 | |
c921be7d NC |
17638 | #undef ARM_VARIANT |
17639 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
17640 | ||
21d799b5 NC |
17641 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
17642 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
17643 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
17644 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
17645 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
17646 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
17647 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
17648 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
17649 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
17650 | cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17651 | cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17652 | cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17653 | cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17654 | cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17655 | cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17656 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17657 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17658 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17659 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
17660 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
17661 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17662 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17663 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17664 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17665 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17666 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17667 | cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn), | |
17668 | cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn), | |
17669 | cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn), | |
17670 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), | |
17671 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
17672 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
17673 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
17674 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
17675 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
17676 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
17677 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
17678 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17679 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17680 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17681 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17682 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17683 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17684 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17685 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17686 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17687 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
17688 | cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17689 | cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17690 | cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17691 | cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17692 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17693 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17694 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17695 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17696 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17697 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17698 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17699 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17700 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17701 | cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17702 | cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17703 | cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17704 | cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17705 | cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17706 | cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17707 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17708 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17709 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17710 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17711 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17712 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17713 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17714 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17715 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17716 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17717 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17718 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17719 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17720 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17721 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17722 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17723 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17724 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17725 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17726 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17727 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17728 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17729 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
17730 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17731 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17732 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17733 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17734 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17735 | cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17736 | cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17737 | cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17738 | cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17739 | cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17740 | cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17741 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17742 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17743 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17744 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17745 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17746 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17747 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17748 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17749 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17750 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17751 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
17752 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17753 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17754 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17755 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17756 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17757 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17758 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17759 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17760 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17761 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17762 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17763 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17764 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17765 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17766 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17767 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17768 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
17769 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
17770 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17771 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17772 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17773 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17774 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17775 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17776 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17777 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17778 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17779 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17780 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17781 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17782 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17783 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
17784 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
17785 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
17786 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
17787 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
17788 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
17789 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17790 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17791 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17792 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
17793 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
17794 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
17795 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
17796 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
17797 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
17798 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17799 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17800 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17801 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17802 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 17803 | |
c921be7d NC |
17804 | #undef ARM_VARIANT |
17805 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
17806 | ||
21d799b5 NC |
17807 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
17808 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
17809 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
17810 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
17811 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
17812 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
17813 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17814 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17815 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17816 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17817 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17818 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17819 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17820 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17821 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17822 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17823 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17824 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17825 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17826 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17827 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
17828 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17829 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17830 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17831 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17832 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17833 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17834 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17835 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17836 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17837 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17838 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17839 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17840 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17841 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17842 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17843 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17844 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17845 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17846 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17847 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17848 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17849 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17850 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17851 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17852 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17853 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17854 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17855 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17856 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17857 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17858 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17859 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17860 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17861 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17862 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17863 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 17864 | |
c921be7d NC |
17865 | #undef ARM_VARIANT |
17866 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
17867 | ||
21d799b5 NC |
17868 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
17869 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17870 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17871 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
17872 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
17873 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17874 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17875 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
17876 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
17877 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
17878 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
17879 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
17880 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
17881 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
17882 | cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd), | |
17883 | cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn), | |
17884 | cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd), | |
17885 | cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn), | |
17886 | cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn), | |
17887 | cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn), | |
17888 | cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn), | |
17889 | cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn), | |
17890 | cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn), | |
17891 | cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn), | |
17892 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), | |
17893 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
17894 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
17895 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
17896 | cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
17897 | cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd), | |
17898 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), | |
17899 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
17900 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
17901 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
17902 | cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn), | |
17903 | cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn), | |
17904 | cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn), | |
17905 | cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn), | |
17906 | cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn), | |
17907 | cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn), | |
17908 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), | |
17909 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
17910 | cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
17911 | cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
17912 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
17913 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
17914 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
17915 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
17916 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
17917 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
17918 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
17919 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
17920 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
17921 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
17922 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17923 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17924 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17925 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17926 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17927 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17928 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
17929 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
17930 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
17931 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
17932 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17933 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17934 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17935 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17936 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17937 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17938 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17939 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17940 | cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17941 | cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17942 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
17943 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
17944 | }; |
17945 | #undef ARM_VARIANT | |
17946 | #undef THUMB_VARIANT | |
17947 | #undef TCE | |
17948 | #undef TCM | |
17949 | #undef TUE | |
17950 | #undef TUF | |
17951 | #undef TCC | |
8f06b2d8 | 17952 | #undef cCE |
e3cb604e PB |
17953 | #undef cCL |
17954 | #undef C3E | |
c19d1205 ZW |
17955 | #undef CE |
17956 | #undef CM | |
17957 | #undef UE | |
17958 | #undef UF | |
17959 | #undef UT | |
5287ad62 JB |
17960 | #undef NUF |
17961 | #undef nUF | |
17962 | #undef NCE | |
17963 | #undef nCE | |
c19d1205 ZW |
17964 | #undef OPS0 |
17965 | #undef OPS1 | |
17966 | #undef OPS2 | |
17967 | #undef OPS3 | |
17968 | #undef OPS4 | |
17969 | #undef OPS5 | |
17970 | #undef OPS6 | |
17971 | #undef do_0 | |
17972 | \f | |
17973 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 17974 | |
c19d1205 ZW |
17975 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
17976 | for use in the a.out file, and stores them in the array pointed to by buf. | |
17977 | This knows about the endian-ness of the target machine and does | |
17978 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
17979 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
17980 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 17981 | |
c19d1205 ZW |
17982 | void |
17983 | md_number_to_chars (char * buf, valueT val, int n) | |
17984 | { | |
17985 | if (target_big_endian) | |
17986 | number_to_chars_bigendian (buf, val, n); | |
17987 | else | |
17988 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
17989 | } |
17990 | ||
c19d1205 ZW |
17991 | static valueT |
17992 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 17993 | { |
c19d1205 ZW |
17994 | valueT result = 0; |
17995 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 17996 | |
c19d1205 | 17997 | if (target_big_endian) |
b99bd4ef | 17998 | { |
c19d1205 ZW |
17999 | while (n--) |
18000 | { | |
18001 | result <<= 8; | |
18002 | result |= (*where++ & 255); | |
18003 | } | |
b99bd4ef | 18004 | } |
c19d1205 | 18005 | else |
b99bd4ef | 18006 | { |
c19d1205 ZW |
18007 | while (n--) |
18008 | { | |
18009 | result <<= 8; | |
18010 | result |= (where[n] & 255); | |
18011 | } | |
bfae80f2 | 18012 | } |
b99bd4ef | 18013 | |
c19d1205 | 18014 | return result; |
bfae80f2 | 18015 | } |
b99bd4ef | 18016 | |
c19d1205 | 18017 | /* MD interface: Sections. */ |
b99bd4ef | 18018 | |
0110f2b8 PB |
18019 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
18020 | 2 bytes. */ | |
18021 | ||
c19d1205 | 18022 | int |
0110f2b8 | 18023 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
18024 | segT segtype ATTRIBUTE_UNUSED) |
18025 | { | |
0110f2b8 PB |
18026 | fragp->fr_var = 2; |
18027 | return 2; | |
18028 | } | |
18029 | ||
18030 | /* Convert a machine dependent frag. */ | |
18031 | ||
18032 | void | |
18033 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
18034 | { | |
18035 | unsigned long insn; | |
18036 | unsigned long old_op; | |
18037 | char *buf; | |
18038 | expressionS exp; | |
18039 | fixS *fixp; | |
18040 | int reloc_type; | |
18041 | int pc_rel; | |
18042 | int opcode; | |
18043 | ||
18044 | buf = fragp->fr_literal + fragp->fr_fix; | |
18045 | ||
18046 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
18047 | if (fragp->fr_symbol) |
18048 | { | |
0110f2b8 PB |
18049 | exp.X_op = O_symbol; |
18050 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
18051 | } |
18052 | else | |
18053 | { | |
0110f2b8 | 18054 | exp.X_op = O_constant; |
5f4273c7 | 18055 | } |
0110f2b8 PB |
18056 | exp.X_add_number = fragp->fr_offset; |
18057 | opcode = fragp->fr_subtype; | |
18058 | switch (opcode) | |
18059 | { | |
18060 | case T_MNEM_ldr_pc: | |
18061 | case T_MNEM_ldr_pc2: | |
18062 | case T_MNEM_ldr_sp: | |
18063 | case T_MNEM_str_sp: | |
18064 | case T_MNEM_ldr: | |
18065 | case T_MNEM_ldrb: | |
18066 | case T_MNEM_ldrh: | |
18067 | case T_MNEM_str: | |
18068 | case T_MNEM_strb: | |
18069 | case T_MNEM_strh: | |
18070 | if (fragp->fr_var == 4) | |
18071 | { | |
5f4273c7 | 18072 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
18073 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
18074 | { | |
18075 | insn |= (old_op & 0x700) << 4; | |
18076 | } | |
18077 | else | |
18078 | { | |
18079 | insn |= (old_op & 7) << 12; | |
18080 | insn |= (old_op & 0x38) << 13; | |
18081 | } | |
18082 | insn |= 0x00000c00; | |
18083 | put_thumb32_insn (buf, insn); | |
18084 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
18085 | } | |
18086 | else | |
18087 | { | |
18088 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
18089 | } | |
18090 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
18091 | break; | |
18092 | case T_MNEM_adr: | |
18093 | if (fragp->fr_var == 4) | |
18094 | { | |
18095 | insn = THUMB_OP32 (opcode); | |
18096 | insn |= (old_op & 0xf0) << 4; | |
18097 | put_thumb32_insn (buf, insn); | |
18098 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
18099 | } | |
18100 | else | |
18101 | { | |
18102 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18103 | exp.X_add_number -= 4; | |
18104 | } | |
18105 | pc_rel = 1; | |
18106 | break; | |
18107 | case T_MNEM_mov: | |
18108 | case T_MNEM_movs: | |
18109 | case T_MNEM_cmp: | |
18110 | case T_MNEM_cmn: | |
18111 | if (fragp->fr_var == 4) | |
18112 | { | |
18113 | int r0off = (opcode == T_MNEM_mov | |
18114 | || opcode == T_MNEM_movs) ? 0 : 8; | |
18115 | insn = THUMB_OP32 (opcode); | |
18116 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
18117 | insn |= (old_op & 0x700) << r0off; | |
18118 | put_thumb32_insn (buf, insn); | |
18119 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
18120 | } | |
18121 | else | |
18122 | { | |
18123 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
18124 | } | |
18125 | pc_rel = 0; | |
18126 | break; | |
18127 | case T_MNEM_b: | |
18128 | if (fragp->fr_var == 4) | |
18129 | { | |
18130 | insn = THUMB_OP32(opcode); | |
18131 | put_thumb32_insn (buf, insn); | |
18132 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
18133 | } | |
18134 | else | |
18135 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
18136 | pc_rel = 1; | |
18137 | break; | |
18138 | case T_MNEM_bcond: | |
18139 | if (fragp->fr_var == 4) | |
18140 | { | |
18141 | insn = THUMB_OP32(opcode); | |
18142 | insn |= (old_op & 0xf00) << 14; | |
18143 | put_thumb32_insn (buf, insn); | |
18144 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
18145 | } | |
18146 | else | |
18147 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
18148 | pc_rel = 1; | |
18149 | break; | |
18150 | case T_MNEM_add_sp: | |
18151 | case T_MNEM_add_pc: | |
18152 | case T_MNEM_inc_sp: | |
18153 | case T_MNEM_dec_sp: | |
18154 | if (fragp->fr_var == 4) | |
18155 | { | |
18156 | /* ??? Choose between add and addw. */ | |
18157 | insn = THUMB_OP32 (opcode); | |
18158 | insn |= (old_op & 0xf0) << 4; | |
18159 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18160 | if (opcode == T_MNEM_add_pc) |
18161 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
18162 | else | |
18163 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
18164 | } |
18165 | else | |
18166 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18167 | pc_rel = 0; | |
18168 | break; | |
18169 | ||
18170 | case T_MNEM_addi: | |
18171 | case T_MNEM_addis: | |
18172 | case T_MNEM_subi: | |
18173 | case T_MNEM_subis: | |
18174 | if (fragp->fr_var == 4) | |
18175 | { | |
18176 | insn = THUMB_OP32 (opcode); | |
18177 | insn |= (old_op & 0xf0) << 4; | |
18178 | insn |= (old_op & 0xf) << 16; | |
18179 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18180 | if (insn & (1 << 20)) |
18181 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
18182 | else | |
18183 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
18184 | } |
18185 | else | |
18186 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18187 | pc_rel = 0; | |
18188 | break; | |
18189 | default: | |
5f4273c7 | 18190 | abort (); |
0110f2b8 PB |
18191 | } |
18192 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 18193 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
18194 | fixp->fx_file = fragp->fr_file; |
18195 | fixp->fx_line = fragp->fr_line; | |
18196 | fragp->fr_fix += fragp->fr_var; | |
18197 | } | |
18198 | ||
18199 | /* Return the size of a relaxable immediate operand instruction. | |
18200 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
18201 | static int | |
18202 | relax_immediate (fragS *fragp, int size, int shift) | |
18203 | { | |
18204 | offsetT offset; | |
18205 | offsetT mask; | |
18206 | offsetT low; | |
18207 | ||
18208 | /* ??? Should be able to do better than this. */ | |
18209 | if (fragp->fr_symbol) | |
18210 | return 4; | |
18211 | ||
18212 | low = (1 << shift) - 1; | |
18213 | mask = (1 << (shift + size)) - (1 << shift); | |
18214 | offset = fragp->fr_offset; | |
18215 | /* Force misaligned offsets to 32-bit variant. */ | |
18216 | if (offset & low) | |
5e77afaa | 18217 | return 4; |
0110f2b8 PB |
18218 | if (offset & ~mask) |
18219 | return 4; | |
18220 | return 2; | |
18221 | } | |
18222 | ||
5e77afaa PB |
18223 | /* Get the address of a symbol during relaxation. */ |
18224 | static addressT | |
5f4273c7 | 18225 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
18226 | { |
18227 | fragS *sym_frag; | |
18228 | addressT addr; | |
18229 | symbolS *sym; | |
18230 | ||
18231 | sym = fragp->fr_symbol; | |
18232 | sym_frag = symbol_get_frag (sym); | |
18233 | know (S_GET_SEGMENT (sym) != absolute_section | |
18234 | || sym_frag == &zero_address_frag); | |
18235 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
18236 | ||
18237 | /* If frag has yet to be reached on this pass, assume it will | |
18238 | move by STRETCH just as we did. If this is not so, it will | |
18239 | be because some frag between grows, and that will force | |
18240 | another pass. */ | |
18241 | ||
18242 | if (stretch != 0 | |
18243 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
18244 | { |
18245 | fragS *f; | |
18246 | ||
18247 | /* Adjust stretch for any alignment frag. Note that if have | |
18248 | been expanding the earlier code, the symbol may be | |
18249 | defined in what appears to be an earlier frag. FIXME: | |
18250 | This doesn't handle the fr_subtype field, which specifies | |
18251 | a maximum number of bytes to skip when doing an | |
18252 | alignment. */ | |
18253 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
18254 | { | |
18255 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
18256 | { | |
18257 | if (stretch < 0) | |
18258 | stretch = - ((- stretch) | |
18259 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
18260 | else | |
18261 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
18262 | if (stretch == 0) | |
18263 | break; | |
18264 | } | |
18265 | } | |
18266 | if (f != NULL) | |
18267 | addr += stretch; | |
18268 | } | |
5e77afaa PB |
18269 | |
18270 | return addr; | |
18271 | } | |
18272 | ||
0110f2b8 PB |
18273 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
18274 | load. */ | |
18275 | static int | |
5e77afaa | 18276 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
18277 | { |
18278 | addressT addr; | |
18279 | offsetT val; | |
18280 | ||
18281 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18282 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18283 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18284 | return 4; | |
18285 | ||
5f4273c7 | 18286 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18287 | addr = fragp->fr_address + fragp->fr_fix; |
18288 | addr = (addr + 4) & ~3; | |
5e77afaa | 18289 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 18290 | if (val & 3) |
5e77afaa | 18291 | return 4; |
0110f2b8 PB |
18292 | val -= addr; |
18293 | if (val < 0 || val > 1020) | |
18294 | return 4; | |
18295 | return 2; | |
18296 | } | |
18297 | ||
18298 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
18299 | static int | |
18300 | relax_addsub (fragS *fragp, asection *sec) | |
18301 | { | |
18302 | char *buf; | |
18303 | int op; | |
18304 | ||
18305 | buf = fragp->fr_literal + fragp->fr_fix; | |
18306 | op = bfd_get_16(sec->owner, buf); | |
18307 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
18308 | return relax_immediate (fragp, 8, 0); | |
18309 | else | |
18310 | return relax_immediate (fragp, 3, 0); | |
18311 | } | |
18312 | ||
18313 | ||
18314 | /* Return the size of a relaxable branch instruction. BITS is the | |
18315 | size of the offset field in the narrow instruction. */ | |
18316 | ||
18317 | static int | |
5e77afaa | 18318 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
18319 | { |
18320 | addressT addr; | |
18321 | offsetT val; | |
18322 | offsetT limit; | |
18323 | ||
18324 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18325 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18326 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18327 | return 4; | |
18328 | ||
267bf995 RR |
18329 | #ifdef OBJ_ELF |
18330 | if (S_IS_DEFINED (fragp->fr_symbol) | |
18331 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
18332 | return 4; | |
18333 | #endif | |
18334 | ||
5f4273c7 | 18335 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18336 | addr = fragp->fr_address + fragp->fr_fix + 4; |
18337 | val -= addr; | |
18338 | ||
18339 | /* Offset is a signed value *2 */ | |
18340 | limit = 1 << bits; | |
18341 | if (val >= limit || val < -limit) | |
18342 | return 4; | |
18343 | return 2; | |
18344 | } | |
18345 | ||
18346 | ||
18347 | /* Relax a machine dependent frag. This returns the amount by which | |
18348 | the current size of the frag should change. */ | |
18349 | ||
18350 | int | |
5e77afaa | 18351 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
18352 | { |
18353 | int oldsize; | |
18354 | int newsize; | |
18355 | ||
18356 | oldsize = fragp->fr_var; | |
18357 | switch (fragp->fr_subtype) | |
18358 | { | |
18359 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 18360 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18361 | break; |
18362 | case T_MNEM_ldr_pc: | |
18363 | case T_MNEM_ldr_sp: | |
18364 | case T_MNEM_str_sp: | |
5f4273c7 | 18365 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
18366 | break; |
18367 | case T_MNEM_ldr: | |
18368 | case T_MNEM_str: | |
5f4273c7 | 18369 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
18370 | break; |
18371 | case T_MNEM_ldrh: | |
18372 | case T_MNEM_strh: | |
5f4273c7 | 18373 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
18374 | break; |
18375 | case T_MNEM_ldrb: | |
18376 | case T_MNEM_strb: | |
5f4273c7 | 18377 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
18378 | break; |
18379 | case T_MNEM_adr: | |
5f4273c7 | 18380 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18381 | break; |
18382 | case T_MNEM_mov: | |
18383 | case T_MNEM_movs: | |
18384 | case T_MNEM_cmp: | |
18385 | case T_MNEM_cmn: | |
5f4273c7 | 18386 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
18387 | break; |
18388 | case T_MNEM_b: | |
5f4273c7 | 18389 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
18390 | break; |
18391 | case T_MNEM_bcond: | |
5f4273c7 | 18392 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
18393 | break; |
18394 | case T_MNEM_add_sp: | |
18395 | case T_MNEM_add_pc: | |
18396 | newsize = relax_immediate (fragp, 8, 2); | |
18397 | break; | |
18398 | case T_MNEM_inc_sp: | |
18399 | case T_MNEM_dec_sp: | |
18400 | newsize = relax_immediate (fragp, 7, 2); | |
18401 | break; | |
18402 | case T_MNEM_addi: | |
18403 | case T_MNEM_addis: | |
18404 | case T_MNEM_subi: | |
18405 | case T_MNEM_subis: | |
18406 | newsize = relax_addsub (fragp, sec); | |
18407 | break; | |
18408 | default: | |
5f4273c7 | 18409 | abort (); |
0110f2b8 | 18410 | } |
5e77afaa PB |
18411 | |
18412 | fragp->fr_var = newsize; | |
18413 | /* Freeze wide instructions that are at or before the same location as | |
18414 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
18415 | Don't freeze them unconditionally because targets may be artificially |
18416 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 18417 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 18418 | { |
0110f2b8 | 18419 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 18420 | frag_wane (fragp); |
0110f2b8 | 18421 | } |
5e77afaa | 18422 | |
0110f2b8 | 18423 | return newsize - oldsize; |
c19d1205 | 18424 | } |
b99bd4ef | 18425 | |
c19d1205 | 18426 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 18427 | |
c19d1205 ZW |
18428 | valueT |
18429 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
18430 | valueT size) | |
18431 | { | |
f0927246 NC |
18432 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
18433 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
18434 | { | |
18435 | /* For a.out, force the section size to be aligned. If we don't do | |
18436 | this, BFD will align it for us, but it will not write out the | |
18437 | final bytes of the section. This may be a bug in BFD, but it is | |
18438 | easier to fix it here since that is how the other a.out targets | |
18439 | work. */ | |
18440 | int align; | |
18441 | ||
18442 | align = bfd_get_section_alignment (stdoutput, segment); | |
18443 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
18444 | } | |
c19d1205 | 18445 | #endif |
f0927246 NC |
18446 | |
18447 | return size; | |
bfae80f2 | 18448 | } |
b99bd4ef | 18449 | |
c19d1205 ZW |
18450 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
18451 | of an rs_align_code fragment. */ | |
18452 | ||
18453 | void | |
18454 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 18455 | { |
e7495e45 NS |
18456 | static char const arm_noop[2][2][4] = |
18457 | { | |
18458 | { /* ARMv1 */ | |
18459 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
18460 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
18461 | }, | |
18462 | { /* ARMv6k */ | |
18463 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
18464 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
18465 | }, | |
18466 | }; | |
18467 | static char const thumb_noop[2][2][2] = | |
18468 | { | |
18469 | { /* Thumb-1 */ | |
18470 | {0xc0, 0x46}, /* LE */ | |
18471 | {0x46, 0xc0}, /* BE */ | |
18472 | }, | |
18473 | { /* Thumb-2 */ | |
18474 | {0x00, 0xbf}, /* LE */ | |
18475 | {0xbf, 0x00} /* BE */ | |
18476 | } | |
18477 | }; | |
18478 | static char const wide_thumb_noop[2][4] = | |
18479 | { /* Wide Thumb-2 */ | |
18480 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
18481 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
18482 | }; | |
c921be7d | 18483 | |
e7495e45 | 18484 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
18485 | char * p; |
18486 | const char * noop; | |
e7495e45 | 18487 | const char *narrow_noop = NULL; |
cd000bff DJ |
18488 | #ifdef OBJ_ELF |
18489 | enum mstate state; | |
18490 | #endif | |
bfae80f2 | 18491 | |
c19d1205 | 18492 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
18493 | return; |
18494 | ||
c19d1205 ZW |
18495 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
18496 | p = fragP->fr_literal + fragP->fr_fix; | |
18497 | fix = 0; | |
bfae80f2 | 18498 | |
c19d1205 ZW |
18499 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
18500 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 18501 | |
539d4391 | 18502 | #ifdef OBJ_ELF |
cd000bff | 18503 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
539d4391 | 18504 | #endif |
8dc2430f | 18505 | |
cd000bff | 18506 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 18507 | { |
e7495e45 NS |
18508 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
18509 | { | |
18510 | narrow_noop = thumb_noop[1][target_big_endian]; | |
18511 | noop = wide_thumb_noop[target_big_endian]; | |
18512 | } | |
c19d1205 | 18513 | else |
e7495e45 NS |
18514 | noop = thumb_noop[0][target_big_endian]; |
18515 | noop_size = 2; | |
cd000bff DJ |
18516 | #ifdef OBJ_ELF |
18517 | state = MAP_THUMB; | |
18518 | #endif | |
7ed4c4c5 NC |
18519 | } |
18520 | else | |
18521 | { | |
e7495e45 NS |
18522 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0] |
18523 | [target_big_endian]; | |
18524 | noop_size = 4; | |
cd000bff DJ |
18525 | #ifdef OBJ_ELF |
18526 | state = MAP_ARM; | |
18527 | #endif | |
7ed4c4c5 | 18528 | } |
c921be7d | 18529 | |
e7495e45 | 18530 | fragP->fr_var = noop_size; |
c921be7d | 18531 | |
c19d1205 | 18532 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 18533 | { |
c19d1205 | 18534 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
18535 | #ifdef OBJ_ELF |
18536 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
18537 | #endif | |
c19d1205 ZW |
18538 | memset (p, 0, fix); |
18539 | p += fix; | |
18540 | bytes -= fix; | |
a737bd4d | 18541 | } |
a737bd4d | 18542 | |
e7495e45 NS |
18543 | if (narrow_noop) |
18544 | { | |
18545 | if (bytes & noop_size) | |
18546 | { | |
18547 | /* Insert a narrow noop. */ | |
18548 | memcpy (p, narrow_noop, noop_size); | |
18549 | p += noop_size; | |
18550 | bytes -= noop_size; | |
18551 | fix += noop_size; | |
18552 | } | |
18553 | ||
18554 | /* Use wide noops for the remainder */ | |
18555 | noop_size = 4; | |
18556 | } | |
18557 | ||
c19d1205 | 18558 | while (bytes >= noop_size) |
a737bd4d | 18559 | { |
c19d1205 ZW |
18560 | memcpy (p, noop, noop_size); |
18561 | p += noop_size; | |
18562 | bytes -= noop_size; | |
18563 | fix += noop_size; | |
a737bd4d NC |
18564 | } |
18565 | ||
c19d1205 | 18566 | fragP->fr_fix += fix; |
a737bd4d NC |
18567 | } |
18568 | ||
c19d1205 ZW |
18569 | /* Called from md_do_align. Used to create an alignment |
18570 | frag in a code section. */ | |
18571 | ||
18572 | void | |
18573 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 18574 | { |
c19d1205 | 18575 | char * p; |
7ed4c4c5 | 18576 | |
c19d1205 | 18577 | /* We assume that there will never be a requirement |
6ec8e702 | 18578 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 18579 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
18580 | { |
18581 | char err_msg[128]; | |
18582 | ||
18583 | sprintf (err_msg, | |
18584 | _("alignments greater than %d bytes not supported in .text sections."), | |
18585 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 18586 | as_fatal ("%s", err_msg); |
6ec8e702 | 18587 | } |
bfae80f2 | 18588 | |
c19d1205 ZW |
18589 | p = frag_var (rs_align_code, |
18590 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
18591 | 1, | |
18592 | (relax_substateT) max, | |
18593 | (symbolS *) NULL, | |
18594 | (offsetT) n, | |
18595 | (char *) NULL); | |
18596 | *p = 0; | |
18597 | } | |
bfae80f2 | 18598 | |
8dc2430f NC |
18599 | /* Perform target specific initialisation of a frag. |
18600 | Note - despite the name this initialisation is not done when the frag | |
18601 | is created, but only when its type is assigned. A frag can be created | |
18602 | and used a long time before its type is set, so beware of assuming that | |
18603 | this initialisationis performed first. */ | |
bfae80f2 | 18604 | |
cd000bff DJ |
18605 | #ifndef OBJ_ELF |
18606 | void | |
18607 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
18608 | { | |
18609 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
18610 | fragP->tc_frag_data.thumb_mode = thumb_mode; | |
18611 | } | |
18612 | ||
18613 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 18614 | void |
cd000bff | 18615 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 18616 | { |
8dc2430f NC |
18617 | /* If the current ARM vs THUMB mode has not already |
18618 | been recorded into this frag then do so now. */ | |
cd000bff DJ |
18619 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
18620 | { | |
18621 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; | |
18622 | ||
18623 | /* Record a mapping symbol for alignment frags. We will delete this | |
18624 | later if the alignment ends up empty. */ | |
18625 | switch (fragP->fr_type) | |
18626 | { | |
18627 | case rs_align: | |
18628 | case rs_align_test: | |
18629 | case rs_fill: | |
18630 | mapping_state_2 (MAP_DATA, max_chars); | |
18631 | break; | |
18632 | case rs_align_code: | |
18633 | mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); | |
18634 | break; | |
18635 | default: | |
18636 | break; | |
18637 | } | |
18638 | } | |
bfae80f2 RE |
18639 | } |
18640 | ||
c19d1205 ZW |
18641 | /* When we change sections we need to issue a new mapping symbol. */ |
18642 | ||
18643 | void | |
18644 | arm_elf_change_section (void) | |
bfae80f2 | 18645 | { |
c19d1205 ZW |
18646 | /* Link an unlinked unwind index table section to the .text section. */ |
18647 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
18648 | && elf_linked_to_section (now_seg) == NULL) | |
18649 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
18650 | } |
18651 | ||
c19d1205 ZW |
18652 | int |
18653 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 18654 | { |
c19d1205 ZW |
18655 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
18656 | return SHT_ARM_EXIDX; | |
e45d0630 | 18657 | |
c19d1205 ZW |
18658 | return -1; |
18659 | } | |
18660 | \f | |
18661 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 18662 | |
c19d1205 | 18663 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 18664 | |
5f4273c7 | 18665 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 18666 | |
bfae80f2 | 18667 | static void |
c19d1205 | 18668 | flush_pending_unwind (void) |
bfae80f2 | 18669 | { |
c19d1205 | 18670 | offsetT offset; |
bfae80f2 | 18671 | |
c19d1205 ZW |
18672 | offset = unwind.pending_offset; |
18673 | unwind.pending_offset = 0; | |
18674 | if (offset != 0) | |
18675 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
18676 | } |
18677 | ||
c19d1205 ZW |
18678 | /* Add an opcode to this list for this function. Two-byte opcodes should |
18679 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
18680 | order. */ | |
18681 | ||
bfae80f2 | 18682 | static void |
c19d1205 | 18683 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 18684 | { |
c19d1205 ZW |
18685 | /* Add any deferred stack adjustment. */ |
18686 | if (unwind.pending_offset) | |
18687 | flush_pending_unwind (); | |
bfae80f2 | 18688 | |
c19d1205 | 18689 | unwind.sp_restored = 0; |
bfae80f2 | 18690 | |
c19d1205 | 18691 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 18692 | { |
c19d1205 ZW |
18693 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
18694 | if (unwind.opcodes) | |
21d799b5 NC |
18695 | unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes, |
18696 | unwind.opcode_alloc); | |
c19d1205 | 18697 | else |
21d799b5 | 18698 | unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc); |
bfae80f2 | 18699 | } |
c19d1205 | 18700 | while (length > 0) |
bfae80f2 | 18701 | { |
c19d1205 ZW |
18702 | length--; |
18703 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
18704 | op >>= 8; | |
18705 | unwind.opcode_count++; | |
bfae80f2 | 18706 | } |
bfae80f2 RE |
18707 | } |
18708 | ||
c19d1205 ZW |
18709 | /* Add unwind opcodes to adjust the stack pointer. */ |
18710 | ||
bfae80f2 | 18711 | static void |
c19d1205 | 18712 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 18713 | { |
c19d1205 | 18714 | valueT op; |
bfae80f2 | 18715 | |
c19d1205 | 18716 | if (offset > 0x200) |
bfae80f2 | 18717 | { |
c19d1205 ZW |
18718 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
18719 | char bytes[5]; | |
18720 | int n; | |
18721 | valueT o; | |
bfae80f2 | 18722 | |
c19d1205 ZW |
18723 | /* Long form: 0xb2, uleb128. */ |
18724 | /* This might not fit in a word so add the individual bytes, | |
18725 | remembering the list is built in reverse order. */ | |
18726 | o = (valueT) ((offset - 0x204) >> 2); | |
18727 | if (o == 0) | |
18728 | add_unwind_opcode (0, 1); | |
bfae80f2 | 18729 | |
c19d1205 ZW |
18730 | /* Calculate the uleb128 encoding of the offset. */ |
18731 | n = 0; | |
18732 | while (o) | |
18733 | { | |
18734 | bytes[n] = o & 0x7f; | |
18735 | o >>= 7; | |
18736 | if (o) | |
18737 | bytes[n] |= 0x80; | |
18738 | n++; | |
18739 | } | |
18740 | /* Add the insn. */ | |
18741 | for (; n; n--) | |
18742 | add_unwind_opcode (bytes[n - 1], 1); | |
18743 | add_unwind_opcode (0xb2, 1); | |
18744 | } | |
18745 | else if (offset > 0x100) | |
bfae80f2 | 18746 | { |
c19d1205 ZW |
18747 | /* Two short opcodes. */ |
18748 | add_unwind_opcode (0x3f, 1); | |
18749 | op = (offset - 0x104) >> 2; | |
18750 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18751 | } |
c19d1205 ZW |
18752 | else if (offset > 0) |
18753 | { | |
18754 | /* Short opcode. */ | |
18755 | op = (offset - 4) >> 2; | |
18756 | add_unwind_opcode (op, 1); | |
18757 | } | |
18758 | else if (offset < 0) | |
bfae80f2 | 18759 | { |
c19d1205 ZW |
18760 | offset = -offset; |
18761 | while (offset > 0x100) | |
bfae80f2 | 18762 | { |
c19d1205 ZW |
18763 | add_unwind_opcode (0x7f, 1); |
18764 | offset -= 0x100; | |
bfae80f2 | 18765 | } |
c19d1205 ZW |
18766 | op = ((offset - 4) >> 2) | 0x40; |
18767 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18768 | } |
bfae80f2 RE |
18769 | } |
18770 | ||
c19d1205 ZW |
18771 | /* Finish the list of unwind opcodes for this function. */ |
18772 | static void | |
18773 | finish_unwind_opcodes (void) | |
bfae80f2 | 18774 | { |
c19d1205 | 18775 | valueT op; |
bfae80f2 | 18776 | |
c19d1205 | 18777 | if (unwind.fp_used) |
bfae80f2 | 18778 | { |
708587a4 | 18779 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
18780 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
18781 | flush_pending_unwind (); | |
bfae80f2 | 18782 | |
c19d1205 ZW |
18783 | /* After restoring sp from the frame pointer. */ |
18784 | op = 0x90 | unwind.fp_reg; | |
18785 | add_unwind_opcode (op, 1); | |
18786 | } | |
18787 | else | |
18788 | flush_pending_unwind (); | |
bfae80f2 RE |
18789 | } |
18790 | ||
bfae80f2 | 18791 | |
c19d1205 ZW |
18792 | /* Start an exception table entry. If idx is nonzero this is an index table |
18793 | entry. */ | |
bfae80f2 RE |
18794 | |
18795 | static void | |
c19d1205 | 18796 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 18797 | { |
c19d1205 ZW |
18798 | const char * text_name; |
18799 | const char * prefix; | |
18800 | const char * prefix_once; | |
18801 | const char * group_name; | |
18802 | size_t prefix_len; | |
18803 | size_t text_len; | |
18804 | char * sec_name; | |
18805 | size_t sec_name_len; | |
18806 | int type; | |
18807 | int flags; | |
18808 | int linkonce; | |
bfae80f2 | 18809 | |
c19d1205 | 18810 | if (idx) |
bfae80f2 | 18811 | { |
c19d1205 ZW |
18812 | prefix = ELF_STRING_ARM_unwind; |
18813 | prefix_once = ELF_STRING_ARM_unwind_once; | |
18814 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 18815 | } |
c19d1205 | 18816 | else |
bfae80f2 | 18817 | { |
c19d1205 ZW |
18818 | prefix = ELF_STRING_ARM_unwind_info; |
18819 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
18820 | type = SHT_PROGBITS; | |
bfae80f2 RE |
18821 | } |
18822 | ||
c19d1205 ZW |
18823 | text_name = segment_name (text_seg); |
18824 | if (streq (text_name, ".text")) | |
18825 | text_name = ""; | |
18826 | ||
18827 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
18828 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 18829 | { |
c19d1205 ZW |
18830 | prefix = prefix_once; |
18831 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
18832 | } |
18833 | ||
c19d1205 ZW |
18834 | prefix_len = strlen (prefix); |
18835 | text_len = strlen (text_name); | |
18836 | sec_name_len = prefix_len + text_len; | |
21d799b5 | 18837 | sec_name = (char *) xmalloc (sec_name_len + 1); |
c19d1205 ZW |
18838 | memcpy (sec_name, prefix, prefix_len); |
18839 | memcpy (sec_name + prefix_len, text_name, text_len); | |
18840 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 18841 | |
c19d1205 ZW |
18842 | flags = SHF_ALLOC; |
18843 | linkonce = 0; | |
18844 | group_name = 0; | |
bfae80f2 | 18845 | |
c19d1205 ZW |
18846 | /* Handle COMDAT group. */ |
18847 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 18848 | { |
c19d1205 ZW |
18849 | group_name = elf_group_name (text_seg); |
18850 | if (group_name == NULL) | |
18851 | { | |
bd3ba5d1 | 18852 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
18853 | segment_name (text_seg)); |
18854 | ignore_rest_of_line (); | |
18855 | return; | |
18856 | } | |
18857 | flags |= SHF_GROUP; | |
18858 | linkonce = 1; | |
bfae80f2 RE |
18859 | } |
18860 | ||
c19d1205 | 18861 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 18862 | |
5f4273c7 | 18863 | /* Set the section link for index tables. */ |
c19d1205 ZW |
18864 | if (idx) |
18865 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
18866 | } |
18867 | ||
bfae80f2 | 18868 | |
c19d1205 ZW |
18869 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
18870 | personality routine data. Returns zero, or the index table value for | |
18871 | and inline entry. */ | |
18872 | ||
18873 | static valueT | |
18874 | create_unwind_entry (int have_data) | |
bfae80f2 | 18875 | { |
c19d1205 ZW |
18876 | int size; |
18877 | addressT where; | |
18878 | char *ptr; | |
18879 | /* The current word of data. */ | |
18880 | valueT data; | |
18881 | /* The number of bytes left in this word. */ | |
18882 | int n; | |
bfae80f2 | 18883 | |
c19d1205 | 18884 | finish_unwind_opcodes (); |
bfae80f2 | 18885 | |
c19d1205 ZW |
18886 | /* Remember the current text section. */ |
18887 | unwind.saved_seg = now_seg; | |
18888 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 18889 | |
c19d1205 | 18890 | start_unwind_section (now_seg, 0); |
bfae80f2 | 18891 | |
c19d1205 | 18892 | if (unwind.personality_routine == NULL) |
bfae80f2 | 18893 | { |
c19d1205 ZW |
18894 | if (unwind.personality_index == -2) |
18895 | { | |
18896 | if (have_data) | |
5f4273c7 | 18897 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
18898 | return 1; /* EXIDX_CANTUNWIND. */ |
18899 | } | |
bfae80f2 | 18900 | |
c19d1205 ZW |
18901 | /* Use a default personality routine if none is specified. */ |
18902 | if (unwind.personality_index == -1) | |
18903 | { | |
18904 | if (unwind.opcode_count > 3) | |
18905 | unwind.personality_index = 1; | |
18906 | else | |
18907 | unwind.personality_index = 0; | |
18908 | } | |
bfae80f2 | 18909 | |
c19d1205 ZW |
18910 | /* Space for the personality routine entry. */ |
18911 | if (unwind.personality_index == 0) | |
18912 | { | |
18913 | if (unwind.opcode_count > 3) | |
18914 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 18915 | |
c19d1205 ZW |
18916 | if (!have_data) |
18917 | { | |
18918 | /* All the data is inline in the index table. */ | |
18919 | data = 0x80; | |
18920 | n = 3; | |
18921 | while (unwind.opcode_count > 0) | |
18922 | { | |
18923 | unwind.opcode_count--; | |
18924 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18925 | n--; | |
18926 | } | |
bfae80f2 | 18927 | |
c19d1205 ZW |
18928 | /* Pad with "finish" opcodes. */ |
18929 | while (n--) | |
18930 | data = (data << 8) | 0xb0; | |
bfae80f2 | 18931 | |
c19d1205 ZW |
18932 | return data; |
18933 | } | |
18934 | size = 0; | |
18935 | } | |
18936 | else | |
18937 | /* We get two opcodes "free" in the first word. */ | |
18938 | size = unwind.opcode_count - 2; | |
18939 | } | |
18940 | else | |
18941 | /* An extra byte is required for the opcode count. */ | |
18942 | size = unwind.opcode_count + 1; | |
bfae80f2 | 18943 | |
c19d1205 ZW |
18944 | size = (size + 3) >> 2; |
18945 | if (size > 0xff) | |
18946 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 18947 | |
c19d1205 ZW |
18948 | frag_align (2, 0, 0); |
18949 | record_alignment (now_seg, 2); | |
18950 | unwind.table_entry = expr_build_dot (); | |
18951 | ||
18952 | /* Allocate the table entry. */ | |
18953 | ptr = frag_more ((size << 2) + 4); | |
18954 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 18955 | |
c19d1205 | 18956 | switch (unwind.personality_index) |
bfae80f2 | 18957 | { |
c19d1205 ZW |
18958 | case -1: |
18959 | /* ??? Should this be a PLT generating relocation? */ | |
18960 | /* Custom personality routine. */ | |
18961 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
18962 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 18963 | |
c19d1205 ZW |
18964 | where += 4; |
18965 | ptr += 4; | |
bfae80f2 | 18966 | |
c19d1205 ZW |
18967 | /* Set the first byte to the number of additional words. */ |
18968 | data = size - 1; | |
18969 | n = 3; | |
18970 | break; | |
bfae80f2 | 18971 | |
c19d1205 ZW |
18972 | /* ABI defined personality routines. */ |
18973 | case 0: | |
18974 | /* Three opcodes bytes are packed into the first word. */ | |
18975 | data = 0x80; | |
18976 | n = 3; | |
18977 | break; | |
bfae80f2 | 18978 | |
c19d1205 ZW |
18979 | case 1: |
18980 | case 2: | |
18981 | /* The size and first two opcode bytes go in the first word. */ | |
18982 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
18983 | n = 2; | |
18984 | break; | |
bfae80f2 | 18985 | |
c19d1205 ZW |
18986 | default: |
18987 | /* Should never happen. */ | |
18988 | abort (); | |
18989 | } | |
bfae80f2 | 18990 | |
c19d1205 ZW |
18991 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
18992 | time. */ | |
18993 | while (unwind.opcode_count > 0) | |
18994 | { | |
18995 | if (n == 0) | |
18996 | { | |
18997 | md_number_to_chars (ptr, data, 4); | |
18998 | ptr += 4; | |
18999 | n = 4; | |
19000 | data = 0; | |
19001 | } | |
19002 | unwind.opcode_count--; | |
19003 | n--; | |
19004 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
19005 | } | |
19006 | ||
19007 | /* Finish off the last word. */ | |
19008 | if (n < 4) | |
19009 | { | |
19010 | /* Pad with "finish" opcodes. */ | |
19011 | while (n--) | |
19012 | data = (data << 8) | 0xb0; | |
19013 | ||
19014 | md_number_to_chars (ptr, data, 4); | |
19015 | } | |
19016 | ||
19017 | if (!have_data) | |
19018 | { | |
19019 | /* Add an empty descriptor if there is no user-specified data. */ | |
19020 | ptr = frag_more (4); | |
19021 | md_number_to_chars (ptr, 0, 4); | |
19022 | } | |
19023 | ||
19024 | return 0; | |
bfae80f2 RE |
19025 | } |
19026 | ||
f0927246 NC |
19027 | |
19028 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
19029 | ||
19030 | void | |
19031 | tc_arm_frame_initial_instructions (void) | |
19032 | { | |
19033 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
19034 | } | |
19035 | #endif /* OBJ_ELF */ | |
19036 | ||
c19d1205 ZW |
19037 | /* Convert REGNAME to a DWARF-2 register number. */ |
19038 | ||
19039 | int | |
1df69f4f | 19040 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 19041 | { |
1df69f4f | 19042 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
19043 | |
19044 | if (reg == FAIL) | |
19045 | return -1; | |
19046 | ||
19047 | return reg; | |
bfae80f2 RE |
19048 | } |
19049 | ||
f0927246 | 19050 | #ifdef TE_PE |
c19d1205 | 19051 | void |
f0927246 | 19052 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 19053 | { |
f0927246 | 19054 | expressionS expr; |
bfae80f2 | 19055 | |
f0927246 NC |
19056 | expr.X_op = O_secrel; |
19057 | expr.X_add_symbol = symbol; | |
19058 | expr.X_add_number = 0; | |
19059 | emit_expr (&expr, size); | |
19060 | } | |
19061 | #endif | |
bfae80f2 | 19062 | |
c19d1205 | 19063 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 19064 | |
2fc8bdac ZW |
19065 | /* Return the address within the segment that a PC-relative fixup is |
19066 | relative to. For ARM, PC-relative fixups applied to instructions | |
19067 | are generally relative to the location of the fixup plus 8 bytes. | |
19068 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
19069 | require special handling. */ | |
bfae80f2 | 19070 | |
c19d1205 | 19071 | long |
2fc8bdac | 19072 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 19073 | { |
2fc8bdac ZW |
19074 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
19075 | ||
19076 | /* If this is pc-relative and we are going to emit a relocation | |
19077 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
19078 | will need. Otherwise we want to use the calculated base. |
19079 | For WinCE we skip the bias for externals as well, since this | |
19080 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 19081 | if (fixP->fx_pcrel |
2fc8bdac | 19082 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
19083 | || (arm_force_relocation (fixP) |
19084 | #ifdef TE_WINCE | |
19085 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19086 | #endif | |
19087 | ))) | |
2fc8bdac | 19088 | base = 0; |
bfae80f2 | 19089 | |
267bf995 | 19090 | |
c19d1205 | 19091 | switch (fixP->fx_r_type) |
bfae80f2 | 19092 | { |
2fc8bdac ZW |
19093 | /* PC relative addressing on the Thumb is slightly odd as the |
19094 | bottom two bits of the PC are forced to zero for the | |
19095 | calculation. This happens *after* application of the | |
19096 | pipeline offset. However, Thumb adrl already adjusts for | |
19097 | this, so we need not do it again. */ | |
c19d1205 | 19098 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 19099 | return base & ~3; |
c19d1205 ZW |
19100 | |
19101 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
19102 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 19103 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 19104 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 19105 | return (base + 4) & ~3; |
c19d1205 | 19106 | |
2fc8bdac ZW |
19107 | /* Thumb branches are simply offset by +4. */ |
19108 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
19109 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
19110 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
19111 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 19112 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 19113 | return base + 4; |
bfae80f2 | 19114 | |
267bf995 RR |
19115 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
19116 | if (fixP->fx_addsy | |
19117 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19118 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19119 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19120 | return base + 4; | |
19121 | ||
00adf2d4 JB |
19122 | /* BLX is like branches above, but forces the low two bits of PC to |
19123 | zero. */ | |
267bf995 RR |
19124 | case BFD_RELOC_THUMB_PCREL_BLX: |
19125 | if (fixP->fx_addsy | |
19126 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
19127 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19128 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
19129 | return (base + 4) & ~3; |
19130 | ||
2fc8bdac ZW |
19131 | /* ARM mode branches are offset by +8. However, the Windows CE |
19132 | loader expects the relocation not to take this into account. */ | |
267bf995 RR |
19133 | case BFD_RELOC_ARM_PCREL_BLX: |
19134 | if (fixP->fx_addsy | |
19135 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19136 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19137 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19138 | return base + 8; | |
19139 | ||
19140 | case BFD_RELOC_ARM_PCREL_CALL: | |
19141 | if (fixP->fx_addsy | |
19142 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
19143 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19144 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19145 | return base + 8; | |
19146 | ||
2fc8bdac | 19147 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 19148 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 19149 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19150 | #ifdef TE_WINCE |
5f4273c7 | 19151 | /* When handling fixups immediately, because we have already |
53baae48 NC |
19152 | discovered the value of a symbol, or the address of the frag involved |
19153 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
19154 | see fixup_segment() in write.c | |
19155 | The S_IS_EXTERNAL test handles the case of global symbols. | |
19156 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
19157 | if (fixP->fx_pcrel | |
19158 | && fixP->fx_addsy != NULL | |
19159 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19160 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
19161 | return base + 8; | |
2fc8bdac | 19162 | return base; |
c19d1205 | 19163 | #else |
2fc8bdac | 19164 | return base + 8; |
c19d1205 | 19165 | #endif |
2fc8bdac | 19166 | |
267bf995 | 19167 | |
2fc8bdac ZW |
19168 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
19169 | branches, the Windows CE loader *does* expect the relocation | |
19170 | to take this into account. */ | |
19171 | case BFD_RELOC_ARM_OFFSET_IMM: | |
19172 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
19173 | case BFD_RELOC_ARM_HWLITERAL: | |
19174 | case BFD_RELOC_ARM_LITERAL: | |
19175 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
19176 | return base + 8; | |
19177 | ||
19178 | ||
19179 | /* Other PC-relative relocations are un-offset. */ | |
19180 | default: | |
19181 | return base; | |
19182 | } | |
bfae80f2 RE |
19183 | } |
19184 | ||
c19d1205 ZW |
19185 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
19186 | Otherwise we have no need to default values of symbols. */ | |
19187 | ||
19188 | symbolS * | |
19189 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 19190 | { |
c19d1205 ZW |
19191 | #ifdef OBJ_ELF |
19192 | if (name[0] == '_' && name[1] == 'G' | |
19193 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
19194 | { | |
19195 | if (!GOT_symbol) | |
19196 | { | |
19197 | if (symbol_find (name)) | |
bd3ba5d1 | 19198 | as_bad (_("GOT already in the symbol table")); |
bfae80f2 | 19199 | |
c19d1205 ZW |
19200 | GOT_symbol = symbol_new (name, undefined_section, |
19201 | (valueT) 0, & zero_address_frag); | |
19202 | } | |
bfae80f2 | 19203 | |
c19d1205 | 19204 | return GOT_symbol; |
bfae80f2 | 19205 | } |
c19d1205 | 19206 | #endif |
bfae80f2 | 19207 | |
c921be7d | 19208 | return NULL; |
bfae80f2 RE |
19209 | } |
19210 | ||
55cf6793 | 19211 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
19212 | computed as two separate immediate values, added together. We |
19213 | already know that this value cannot be computed by just one ARM | |
19214 | instruction. */ | |
19215 | ||
19216 | static unsigned int | |
19217 | validate_immediate_twopart (unsigned int val, | |
19218 | unsigned int * highpart) | |
bfae80f2 | 19219 | { |
c19d1205 ZW |
19220 | unsigned int a; |
19221 | unsigned int i; | |
bfae80f2 | 19222 | |
c19d1205 ZW |
19223 | for (i = 0; i < 32; i += 2) |
19224 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
19225 | { | |
19226 | if (a & 0xff00) | |
19227 | { | |
19228 | if (a & ~ 0xffff) | |
19229 | continue; | |
19230 | * highpart = (a >> 8) | ((i + 24) << 7); | |
19231 | } | |
19232 | else if (a & 0xff0000) | |
19233 | { | |
19234 | if (a & 0xff000000) | |
19235 | continue; | |
19236 | * highpart = (a >> 16) | ((i + 16) << 7); | |
19237 | } | |
19238 | else | |
19239 | { | |
9c2799c2 | 19240 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
19241 | * highpart = (a >> 24) | ((i + 8) << 7); |
19242 | } | |
bfae80f2 | 19243 | |
c19d1205 ZW |
19244 | return (a & 0xff) | (i << 7); |
19245 | } | |
bfae80f2 | 19246 | |
c19d1205 | 19247 | return FAIL; |
bfae80f2 RE |
19248 | } |
19249 | ||
c19d1205 ZW |
19250 | static int |
19251 | validate_offset_imm (unsigned int val, int hwse) | |
19252 | { | |
19253 | if ((hwse && val > 255) || val > 4095) | |
19254 | return FAIL; | |
19255 | return val; | |
19256 | } | |
bfae80f2 | 19257 | |
55cf6793 | 19258 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
19259 | negative immediate constant by altering the instruction. A bit of |
19260 | a hack really. | |
19261 | MOV <-> MVN | |
19262 | AND <-> BIC | |
19263 | ADC <-> SBC | |
19264 | by inverting the second operand, and | |
19265 | ADD <-> SUB | |
19266 | CMP <-> CMN | |
19267 | by negating the second operand. */ | |
bfae80f2 | 19268 | |
c19d1205 ZW |
19269 | static int |
19270 | negate_data_op (unsigned long * instruction, | |
19271 | unsigned long value) | |
bfae80f2 | 19272 | { |
c19d1205 ZW |
19273 | int op, new_inst; |
19274 | unsigned long negated, inverted; | |
bfae80f2 | 19275 | |
c19d1205 ZW |
19276 | negated = encode_arm_immediate (-value); |
19277 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 19278 | |
c19d1205 ZW |
19279 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
19280 | switch (op) | |
bfae80f2 | 19281 | { |
c19d1205 ZW |
19282 | /* First negates. */ |
19283 | case OPCODE_SUB: /* ADD <-> SUB */ | |
19284 | new_inst = OPCODE_ADD; | |
19285 | value = negated; | |
19286 | break; | |
bfae80f2 | 19287 | |
c19d1205 ZW |
19288 | case OPCODE_ADD: |
19289 | new_inst = OPCODE_SUB; | |
19290 | value = negated; | |
19291 | break; | |
bfae80f2 | 19292 | |
c19d1205 ZW |
19293 | case OPCODE_CMP: /* CMP <-> CMN */ |
19294 | new_inst = OPCODE_CMN; | |
19295 | value = negated; | |
19296 | break; | |
bfae80f2 | 19297 | |
c19d1205 ZW |
19298 | case OPCODE_CMN: |
19299 | new_inst = OPCODE_CMP; | |
19300 | value = negated; | |
19301 | break; | |
bfae80f2 | 19302 | |
c19d1205 ZW |
19303 | /* Now Inverted ops. */ |
19304 | case OPCODE_MOV: /* MOV <-> MVN */ | |
19305 | new_inst = OPCODE_MVN; | |
19306 | value = inverted; | |
19307 | break; | |
bfae80f2 | 19308 | |
c19d1205 ZW |
19309 | case OPCODE_MVN: |
19310 | new_inst = OPCODE_MOV; | |
19311 | value = inverted; | |
19312 | break; | |
bfae80f2 | 19313 | |
c19d1205 ZW |
19314 | case OPCODE_AND: /* AND <-> BIC */ |
19315 | new_inst = OPCODE_BIC; | |
19316 | value = inverted; | |
19317 | break; | |
bfae80f2 | 19318 | |
c19d1205 ZW |
19319 | case OPCODE_BIC: |
19320 | new_inst = OPCODE_AND; | |
19321 | value = inverted; | |
19322 | break; | |
bfae80f2 | 19323 | |
c19d1205 ZW |
19324 | case OPCODE_ADC: /* ADC <-> SBC */ |
19325 | new_inst = OPCODE_SBC; | |
19326 | value = inverted; | |
19327 | break; | |
bfae80f2 | 19328 | |
c19d1205 ZW |
19329 | case OPCODE_SBC: |
19330 | new_inst = OPCODE_ADC; | |
19331 | value = inverted; | |
19332 | break; | |
bfae80f2 | 19333 | |
c19d1205 ZW |
19334 | /* We cannot do anything. */ |
19335 | default: | |
19336 | return FAIL; | |
b99bd4ef NC |
19337 | } |
19338 | ||
c19d1205 ZW |
19339 | if (value == (unsigned) FAIL) |
19340 | return FAIL; | |
19341 | ||
19342 | *instruction &= OPCODE_MASK; | |
19343 | *instruction |= new_inst << DATA_OP_SHIFT; | |
19344 | return value; | |
b99bd4ef NC |
19345 | } |
19346 | ||
ef8d22e6 PB |
19347 | /* Like negate_data_op, but for Thumb-2. */ |
19348 | ||
19349 | static unsigned int | |
16dd5e42 | 19350 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
19351 | { |
19352 | int op, new_inst; | |
19353 | int rd; | |
16dd5e42 | 19354 | unsigned int negated, inverted; |
ef8d22e6 PB |
19355 | |
19356 | negated = encode_thumb32_immediate (-value); | |
19357 | inverted = encode_thumb32_immediate (~value); | |
19358 | ||
19359 | rd = (*instruction >> 8) & 0xf; | |
19360 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
19361 | switch (op) | |
19362 | { | |
19363 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
19364 | case T2_OPCODE_SUB: | |
19365 | new_inst = T2_OPCODE_ADD; | |
19366 | value = negated; | |
19367 | break; | |
19368 | ||
19369 | case T2_OPCODE_ADD: | |
19370 | new_inst = T2_OPCODE_SUB; | |
19371 | value = negated; | |
19372 | break; | |
19373 | ||
19374 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
19375 | case T2_OPCODE_ORR: | |
19376 | new_inst = T2_OPCODE_ORN; | |
19377 | value = inverted; | |
19378 | break; | |
19379 | ||
19380 | case T2_OPCODE_ORN: | |
19381 | new_inst = T2_OPCODE_ORR; | |
19382 | value = inverted; | |
19383 | break; | |
19384 | ||
19385 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
19386 | case T2_OPCODE_AND: | |
19387 | new_inst = T2_OPCODE_BIC; | |
19388 | if (rd == 15) | |
19389 | value = FAIL; | |
19390 | else | |
19391 | value = inverted; | |
19392 | break; | |
19393 | ||
19394 | case T2_OPCODE_BIC: | |
19395 | new_inst = T2_OPCODE_AND; | |
19396 | value = inverted; | |
19397 | break; | |
19398 | ||
19399 | /* ADC <-> SBC */ | |
19400 | case T2_OPCODE_ADC: | |
19401 | new_inst = T2_OPCODE_SBC; | |
19402 | value = inverted; | |
19403 | break; | |
19404 | ||
19405 | case T2_OPCODE_SBC: | |
19406 | new_inst = T2_OPCODE_ADC; | |
19407 | value = inverted; | |
19408 | break; | |
19409 | ||
19410 | /* We cannot do anything. */ | |
19411 | default: | |
19412 | return FAIL; | |
19413 | } | |
19414 | ||
16dd5e42 | 19415 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
19416 | return FAIL; |
19417 | ||
19418 | *instruction &= T2_OPCODE_MASK; | |
19419 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
19420 | return value; | |
19421 | } | |
19422 | ||
8f06b2d8 PB |
19423 | /* Read a 32-bit thumb instruction from buf. */ |
19424 | static unsigned long | |
19425 | get_thumb32_insn (char * buf) | |
19426 | { | |
19427 | unsigned long insn; | |
19428 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
19429 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19430 | ||
19431 | return insn; | |
19432 | } | |
19433 | ||
a8bc6c78 PB |
19434 | |
19435 | /* We usually want to set the low bit on the address of thumb function | |
19436 | symbols. In particular .word foo - . should have the low bit set. | |
19437 | Generic code tries to fold the difference of two symbols to | |
19438 | a constant. Prevent this and force a relocation when the first symbols | |
19439 | is a thumb function. */ | |
c921be7d NC |
19440 | |
19441 | bfd_boolean | |
a8bc6c78 PB |
19442 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
19443 | { | |
19444 | if (op == O_subtract | |
19445 | && l->X_op == O_symbol | |
19446 | && r->X_op == O_symbol | |
19447 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
19448 | { | |
19449 | l->X_op = O_subtract; | |
19450 | l->X_op_symbol = r->X_add_symbol; | |
19451 | l->X_add_number -= r->X_add_number; | |
c921be7d | 19452 | return TRUE; |
a8bc6c78 | 19453 | } |
c921be7d | 19454 | |
a8bc6c78 | 19455 | /* Process as normal. */ |
c921be7d | 19456 | return FALSE; |
a8bc6c78 PB |
19457 | } |
19458 | ||
c19d1205 | 19459 | void |
55cf6793 | 19460 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
19461 | valueT * valP, |
19462 | segT seg) | |
19463 | { | |
19464 | offsetT value = * valP; | |
19465 | offsetT newval; | |
19466 | unsigned int newimm; | |
19467 | unsigned long temp; | |
19468 | int sign; | |
19469 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 19470 | |
9c2799c2 | 19471 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 19472 | |
c19d1205 | 19473 | /* Note whether this will delete the relocation. */ |
4962c51a | 19474 | |
c19d1205 ZW |
19475 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
19476 | fixP->fx_done = 1; | |
b99bd4ef | 19477 | |
adbaf948 | 19478 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 19479 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
19480 | for emit_reloc. */ |
19481 | value &= 0xffffffff; | |
19482 | value ^= 0x80000000; | |
5f4273c7 | 19483 | value -= 0x80000000; |
adbaf948 ZW |
19484 | |
19485 | *valP = value; | |
c19d1205 | 19486 | fixP->fx_addnumber = value; |
b99bd4ef | 19487 | |
adbaf948 ZW |
19488 | /* Same treatment for fixP->fx_offset. */ |
19489 | fixP->fx_offset &= 0xffffffff; | |
19490 | fixP->fx_offset ^= 0x80000000; | |
19491 | fixP->fx_offset -= 0x80000000; | |
19492 | ||
c19d1205 | 19493 | switch (fixP->fx_r_type) |
b99bd4ef | 19494 | { |
c19d1205 ZW |
19495 | case BFD_RELOC_NONE: |
19496 | /* This will need to go in the object file. */ | |
19497 | fixP->fx_done = 0; | |
19498 | break; | |
b99bd4ef | 19499 | |
c19d1205 ZW |
19500 | case BFD_RELOC_ARM_IMMEDIATE: |
19501 | /* We claim that this fixup has been processed here, | |
19502 | even if in fact we generate an error because we do | |
19503 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19504 | fixP->fx_done = 1; | |
b99bd4ef | 19505 | |
c19d1205 ZW |
19506 | if (fixP->fx_addsy |
19507 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 19508 | { |
c19d1205 ZW |
19509 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19510 | _("undefined symbol %s used as an immediate value"), | |
19511 | S_GET_NAME (fixP->fx_addsy)); | |
19512 | break; | |
b99bd4ef NC |
19513 | } |
19514 | ||
42e5fcbf AS |
19515 | if (fixP->fx_addsy |
19516 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19517 | { | |
19518 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19519 | _("symbol %s is in a different section"), | |
19520 | S_GET_NAME (fixP->fx_addsy)); | |
19521 | break; | |
19522 | } | |
19523 | ||
c19d1205 ZW |
19524 | newimm = encode_arm_immediate (value); |
19525 | temp = md_chars_to_number (buf, INSN_SIZE); | |
19526 | ||
19527 | /* If the instruction will fail, see if we can fix things up by | |
19528 | changing the opcode. */ | |
19529 | if (newimm == (unsigned int) FAIL | |
19530 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 19531 | { |
c19d1205 ZW |
19532 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19533 | _("invalid constant (%lx) after fixup"), | |
19534 | (unsigned long) value); | |
19535 | break; | |
b99bd4ef | 19536 | } |
b99bd4ef | 19537 | |
c19d1205 ZW |
19538 | newimm |= (temp & 0xfffff000); |
19539 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
19540 | break; | |
b99bd4ef | 19541 | |
c19d1205 ZW |
19542 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
19543 | { | |
19544 | unsigned int highpart = 0; | |
19545 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 19546 | |
42e5fcbf AS |
19547 | if (fixP->fx_addsy |
19548 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19549 | { | |
19550 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19551 | _("undefined symbol %s used as an immediate value"), | |
19552 | S_GET_NAME (fixP->fx_addsy)); | |
19553 | break; | |
19554 | } | |
19555 | ||
19556 | if (fixP->fx_addsy | |
19557 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19558 | { | |
19559 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19560 | _("symbol %s is in a different section"), | |
19561 | S_GET_NAME (fixP->fx_addsy)); | |
19562 | break; | |
19563 | } | |
19564 | ||
c19d1205 ZW |
19565 | newimm = encode_arm_immediate (value); |
19566 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 19567 | |
c19d1205 ZW |
19568 | /* If the instruction will fail, see if we can fix things up by |
19569 | changing the opcode. */ | |
19570 | if (newimm == (unsigned int) FAIL | |
19571 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
19572 | { | |
19573 | /* No ? OK - try using two ADD instructions to generate | |
19574 | the value. */ | |
19575 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 19576 | |
c19d1205 ZW |
19577 | /* Yes - then make sure that the second instruction is |
19578 | also an add. */ | |
19579 | if (newimm != (unsigned int) FAIL) | |
19580 | newinsn = temp; | |
19581 | /* Still No ? Try using a negated value. */ | |
19582 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
19583 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
19584 | /* Otherwise - give up. */ | |
19585 | else | |
19586 | { | |
19587 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19588 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
19589 | (long) value); | |
19590 | break; | |
19591 | } | |
b99bd4ef | 19592 | |
c19d1205 ZW |
19593 | /* Replace the first operand in the 2nd instruction (which |
19594 | is the PC) with the destination register. We have | |
19595 | already added in the PC in the first instruction and we | |
19596 | do not want to do it again. */ | |
19597 | newinsn &= ~ 0xf0000; | |
19598 | newinsn |= ((newinsn & 0x0f000) << 4); | |
19599 | } | |
b99bd4ef | 19600 | |
c19d1205 ZW |
19601 | newimm |= (temp & 0xfffff000); |
19602 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 19603 | |
c19d1205 ZW |
19604 | highpart |= (newinsn & 0xfffff000); |
19605 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
19606 | } | |
19607 | break; | |
b99bd4ef | 19608 | |
c19d1205 | 19609 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
19610 | if (!fixP->fx_done && seg->use_rela_p) |
19611 | value = 0; | |
19612 | ||
c19d1205 ZW |
19613 | case BFD_RELOC_ARM_LITERAL: |
19614 | sign = value >= 0; | |
b99bd4ef | 19615 | |
c19d1205 ZW |
19616 | if (value < 0) |
19617 | value = - value; | |
b99bd4ef | 19618 | |
c19d1205 | 19619 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 19620 | { |
c19d1205 ZW |
19621 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
19622 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19623 | _("invalid literal constant: pool needs to be closer")); | |
19624 | else | |
19625 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19626 | _("bad immediate value for offset (%ld)"), | |
19627 | (long) value); | |
19628 | break; | |
f03698e6 RE |
19629 | } |
19630 | ||
c19d1205 ZW |
19631 | newval = md_chars_to_number (buf, INSN_SIZE); |
19632 | newval &= 0xff7ff000; | |
19633 | newval |= value | (sign ? INDEX_UP : 0); | |
19634 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19635 | break; | |
b99bd4ef | 19636 | |
c19d1205 ZW |
19637 | case BFD_RELOC_ARM_OFFSET_IMM8: |
19638 | case BFD_RELOC_ARM_HWLITERAL: | |
19639 | sign = value >= 0; | |
b99bd4ef | 19640 | |
c19d1205 ZW |
19641 | if (value < 0) |
19642 | value = - value; | |
b99bd4ef | 19643 | |
c19d1205 | 19644 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 19645 | { |
c19d1205 ZW |
19646 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
19647 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19648 | _("invalid literal constant: pool needs to be closer")); | |
19649 | else | |
f9d4405b | 19650 | as_bad (_("bad immediate value for 8-bit offset (%ld)"), |
c19d1205 ZW |
19651 | (long) value); |
19652 | break; | |
b99bd4ef NC |
19653 | } |
19654 | ||
c19d1205 ZW |
19655 | newval = md_chars_to_number (buf, INSN_SIZE); |
19656 | newval &= 0xff7ff0f0; | |
19657 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
19658 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19659 | break; | |
b99bd4ef | 19660 | |
c19d1205 ZW |
19661 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
19662 | if (value < 0 || value > 1020 || value % 4 != 0) | |
19663 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19664 | _("bad immediate value for offset (%ld)"), (long) value); | |
19665 | value /= 4; | |
b99bd4ef | 19666 | |
c19d1205 | 19667 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
19668 | newval |= value; |
19669 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
19670 | break; | |
b99bd4ef | 19671 | |
c19d1205 ZW |
19672 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
19673 | /* This is a complicated relocation used for all varieties of Thumb32 | |
19674 | load/store instruction with immediate offset: | |
19675 | ||
19676 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
19677 | *4, optional writeback(W) | |
19678 | (doubleword load/store) | |
19679 | ||
19680 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
19681 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
19682 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
19683 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
19684 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
19685 | ||
19686 | Uppercase letters indicate bits that are already encoded at | |
19687 | this point. Lowercase letters are our problem. For the | |
19688 | second block of instructions, the secondary opcode nybble | |
19689 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
19690 | a PC-relative operation. */ | |
19691 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19692 | newval <<= 16; | |
19693 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 19694 | |
c19d1205 | 19695 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 19696 | { |
c19d1205 ZW |
19697 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
19698 | if (value >= 0) | |
19699 | newval |= (1 << 23); | |
19700 | else | |
19701 | value = -value; | |
19702 | if (value % 4 != 0) | |
19703 | { | |
19704 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19705 | _("offset not a multiple of 4")); | |
19706 | break; | |
19707 | } | |
19708 | value /= 4; | |
216d22bc | 19709 | if (value > 0xff) |
c19d1205 ZW |
19710 | { |
19711 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19712 | _("offset out of range")); | |
19713 | break; | |
19714 | } | |
19715 | newval &= ~0xff; | |
b99bd4ef | 19716 | } |
c19d1205 | 19717 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 19718 | { |
c19d1205 ZW |
19719 | /* PC-relative, 12-bit offset. */ |
19720 | if (value >= 0) | |
19721 | newval |= (1 << 23); | |
19722 | else | |
19723 | value = -value; | |
216d22bc | 19724 | if (value > 0xfff) |
c19d1205 ZW |
19725 | { |
19726 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19727 | _("offset out of range")); | |
19728 | break; | |
19729 | } | |
19730 | newval &= ~0xfff; | |
b99bd4ef | 19731 | } |
c19d1205 | 19732 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 19733 | { |
c19d1205 ZW |
19734 | /* Writeback: 8-bit, +/- offset. */ |
19735 | if (value >= 0) | |
19736 | newval |= (1 << 9); | |
19737 | else | |
19738 | value = -value; | |
216d22bc | 19739 | if (value > 0xff) |
c19d1205 ZW |
19740 | { |
19741 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19742 | _("offset out of range")); | |
19743 | break; | |
19744 | } | |
19745 | newval &= ~0xff; | |
b99bd4ef | 19746 | } |
c19d1205 | 19747 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 19748 | { |
c19d1205 | 19749 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 19750 | if (value < 0 || value > 0xff) |
b99bd4ef | 19751 | { |
c19d1205 ZW |
19752 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19753 | _("offset out of range")); | |
19754 | break; | |
b99bd4ef | 19755 | } |
c19d1205 ZW |
19756 | newval &= ~0xff; |
19757 | newval |= value; | |
b99bd4ef NC |
19758 | } |
19759 | else | |
b99bd4ef | 19760 | { |
c19d1205 ZW |
19761 | /* Positive 12-bit or negative 8-bit offset. */ |
19762 | int limit; | |
19763 | if (value >= 0) | |
b99bd4ef | 19764 | { |
c19d1205 ZW |
19765 | newval |= (1 << 23); |
19766 | limit = 0xfff; | |
19767 | } | |
19768 | else | |
19769 | { | |
19770 | value = -value; | |
19771 | limit = 0xff; | |
19772 | } | |
19773 | if (value > limit) | |
19774 | { | |
19775 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19776 | _("offset out of range")); | |
19777 | break; | |
b99bd4ef | 19778 | } |
c19d1205 | 19779 | newval &= ~limit; |
b99bd4ef | 19780 | } |
b99bd4ef | 19781 | |
c19d1205 ZW |
19782 | newval |= value; |
19783 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
19784 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
19785 | break; | |
404ff6b5 | 19786 | |
c19d1205 ZW |
19787 | case BFD_RELOC_ARM_SHIFT_IMM: |
19788 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19789 | if (((unsigned long) value) > 32 | |
19790 | || (value == 32 | |
19791 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
19792 | { | |
19793 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19794 | _("shift expression is too large")); | |
19795 | break; | |
19796 | } | |
404ff6b5 | 19797 | |
c19d1205 ZW |
19798 | if (value == 0) |
19799 | /* Shifts of zero must be done as lsl. */ | |
19800 | newval &= ~0x60; | |
19801 | else if (value == 32) | |
19802 | value = 0; | |
19803 | newval &= 0xfffff07f; | |
19804 | newval |= (value & 0x1f) << 7; | |
19805 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19806 | break; | |
404ff6b5 | 19807 | |
c19d1205 | 19808 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 19809 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 19810 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 19811 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
19812 | /* We claim that this fixup has been processed here, |
19813 | even if in fact we generate an error because we do | |
19814 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19815 | fixP->fx_done = 1; | |
404ff6b5 | 19816 | |
c19d1205 ZW |
19817 | if (fixP->fx_addsy |
19818 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19819 | { | |
19820 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19821 | _("undefined symbol %s used as an immediate value"), | |
19822 | S_GET_NAME (fixP->fx_addsy)); | |
19823 | break; | |
19824 | } | |
404ff6b5 | 19825 | |
c19d1205 ZW |
19826 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19827 | newval <<= 16; | |
19828 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 19829 | |
16805f35 PB |
19830 | newimm = FAIL; |
19831 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
19832 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
19833 | { |
19834 | newimm = encode_thumb32_immediate (value); | |
19835 | if (newimm == (unsigned int) FAIL) | |
19836 | newimm = thumb32_negate_data_op (&newval, value); | |
19837 | } | |
16805f35 PB |
19838 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
19839 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 19840 | { |
16805f35 PB |
19841 | /* Turn add/sum into addw/subw. */ |
19842 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
19843 | newval = (newval & 0xfeffffff) | 0x02000000; | |
19844 | ||
e9f89963 PB |
19845 | /* 12 bit immediate for addw/subw. */ |
19846 | if (value < 0) | |
19847 | { | |
19848 | value = -value; | |
19849 | newval ^= 0x00a00000; | |
19850 | } | |
92e90b6e PB |
19851 | if (value > 0xfff) |
19852 | newimm = (unsigned int) FAIL; | |
19853 | else | |
19854 | newimm = value; | |
19855 | } | |
cc8a6dd0 | 19856 | |
c19d1205 | 19857 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 19858 | { |
c19d1205 ZW |
19859 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19860 | _("invalid constant (%lx) after fixup"), | |
19861 | (unsigned long) value); | |
19862 | break; | |
3631a3c8 NC |
19863 | } |
19864 | ||
c19d1205 ZW |
19865 | newval |= (newimm & 0x800) << 15; |
19866 | newval |= (newimm & 0x700) << 4; | |
19867 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 19868 | |
c19d1205 ZW |
19869 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
19870 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
19871 | break; | |
a737bd4d | 19872 | |
3eb17e6b | 19873 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
19874 | if (((unsigned long) value) > 0xffff) |
19875 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 19876 | _("invalid smc expression")); |
2fc8bdac | 19877 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19878 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
19879 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19880 | break; | |
a737bd4d | 19881 | |
c19d1205 | 19882 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 19883 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
19884 | { |
19885 | if (((unsigned long) value) > 0xff) | |
19886 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19887 | _("invalid swi expression")); | |
2fc8bdac | 19888 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
19889 | newval |= value; |
19890 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19891 | } | |
19892 | else | |
19893 | { | |
19894 | if (((unsigned long) value) > 0x00ffffff) | |
19895 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19896 | _("invalid swi expression")); | |
2fc8bdac | 19897 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19898 | newval |= value; |
19899 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19900 | } | |
19901 | break; | |
a737bd4d | 19902 | |
c19d1205 ZW |
19903 | case BFD_RELOC_ARM_MULTI: |
19904 | if (((unsigned long) value) > 0xffff) | |
19905 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19906 | _("invalid expression in load/store multiple")); | |
19907 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
19908 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19909 | break; | |
a737bd4d | 19910 | |
c19d1205 | 19911 | #ifdef OBJ_ELF |
39b41c9c | 19912 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
19913 | |
19914 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
19915 | && fixP->fx_addsy | |
19916 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19917 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19918 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19919 | /* Flip the bl to blx. This is a simple flip | |
19920 | bit here because we generate PCREL_CALL for | |
19921 | unconditional bls. */ | |
19922 | { | |
19923 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19924 | newval = newval | 0x10000000; | |
19925 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19926 | temp = 1; | |
19927 | fixP->fx_done = 1; | |
19928 | } | |
39b41c9c PB |
19929 | else |
19930 | temp = 3; | |
19931 | goto arm_branch_common; | |
19932 | ||
19933 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
19934 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19935 | && fixP->fx_addsy | |
19936 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19937 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19938 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19939 | { | |
19940 | /* This would map to a bl<cond>, b<cond>, | |
19941 | b<always> to a Thumb function. We | |
19942 | need to force a relocation for this particular | |
19943 | case. */ | |
19944 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19945 | fixP->fx_done = 0; | |
19946 | } | |
19947 | ||
2fc8bdac | 19948 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19949 | #endif |
39b41c9c PB |
19950 | case BFD_RELOC_ARM_PCREL_BRANCH: |
19951 | temp = 3; | |
19952 | goto arm_branch_common; | |
a737bd4d | 19953 | |
39b41c9c | 19954 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 19955 | |
39b41c9c | 19956 | temp = 1; |
267bf995 RR |
19957 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19958 | && fixP->fx_addsy | |
19959 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19960 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19961 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
19962 | { | |
19963 | /* Flip the blx to a bl and warn. */ | |
19964 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
19965 | newval = 0xeb000000; | |
19966 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
19967 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
19968 | name); | |
19969 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19970 | temp = 3; | |
19971 | fixP->fx_done = 1; | |
19972 | } | |
19973 | ||
19974 | #ifdef OBJ_ELF | |
19975 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
19976 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; | |
19977 | #endif | |
19978 | ||
39b41c9c | 19979 | arm_branch_common: |
c19d1205 | 19980 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
19981 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
19982 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
19983 | also be be clear. */ | |
19984 | if (value & temp) | |
c19d1205 | 19985 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
19986 | _("misaligned branch destination")); |
19987 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
19988 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
19989 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19990 | _("branch out of range")); | |
a737bd4d | 19991 | |
2fc8bdac | 19992 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19993 | { |
2fc8bdac ZW |
19994 | newval = md_chars_to_number (buf, INSN_SIZE); |
19995 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
19996 | /* Set the H bit on BLX instructions. */ |
19997 | if (temp == 1) | |
19998 | { | |
19999 | if (value & 2) | |
20000 | newval |= 0x01000000; | |
20001 | else | |
20002 | newval &= ~0x01000000; | |
20003 | } | |
2fc8bdac | 20004 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 20005 | } |
c19d1205 | 20006 | break; |
a737bd4d | 20007 | |
25fe350b MS |
20008 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
20009 | /* CBZ can only branch forward. */ | |
a737bd4d | 20010 | |
738755b0 MS |
20011 | /* Attempts to use CBZ to branch to the next instruction |
20012 | (which, strictly speaking, are prohibited) will be turned into | |
20013 | no-ops. | |
20014 | ||
20015 | FIXME: It may be better to remove the instruction completely and | |
20016 | perform relaxation. */ | |
20017 | if (value == -2) | |
2fc8bdac ZW |
20018 | { |
20019 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 20020 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
20021 | md_number_to_chars (buf, newval, THUMB_SIZE); |
20022 | } | |
738755b0 MS |
20023 | else |
20024 | { | |
20025 | if (value & ~0x7e) | |
20026 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20027 | _("branch out of range")); | |
20028 | ||
20029 | if (fixP->fx_done || !seg->use_rela_p) | |
20030 | { | |
20031 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20032 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
20033 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20034 | } | |
20035 | } | |
c19d1205 | 20036 | break; |
a737bd4d | 20037 | |
c19d1205 | 20038 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
20039 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
20040 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20041 | _("branch out of range")); | |
a737bd4d | 20042 | |
2fc8bdac ZW |
20043 | if (fixP->fx_done || !seg->use_rela_p) |
20044 | { | |
20045 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20046 | newval |= (value & 0x1ff) >> 1; | |
20047 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20048 | } | |
c19d1205 | 20049 | break; |
a737bd4d | 20050 | |
c19d1205 | 20051 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
20052 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
20053 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20054 | _("branch out of range")); | |
a737bd4d | 20055 | |
2fc8bdac ZW |
20056 | if (fixP->fx_done || !seg->use_rela_p) |
20057 | { | |
20058 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20059 | newval |= (value & 0xfff) >> 1; | |
20060 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20061 | } | |
c19d1205 | 20062 | break; |
a737bd4d | 20063 | |
c19d1205 | 20064 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
20065 | if (fixP->fx_addsy |
20066 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20067 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20068 | && S_IS_DEFINED (fixP->fx_addsy) | |
20069 | && ARM_IS_FUNC (fixP->fx_addsy) | |
20070 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20071 | { | |
20072 | /* Force a relocation for a branch 20 bits wide. */ | |
20073 | fixP->fx_done = 0; | |
20074 | } | |
2fc8bdac ZW |
20075 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
20076 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20077 | _("conditional branch out of range")); | |
404ff6b5 | 20078 | |
2fc8bdac ZW |
20079 | if (fixP->fx_done || !seg->use_rela_p) |
20080 | { | |
20081 | offsetT newval2; | |
20082 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 20083 | |
2fc8bdac ZW |
20084 | S = (value & 0x00100000) >> 20; |
20085 | J2 = (value & 0x00080000) >> 19; | |
20086 | J1 = (value & 0x00040000) >> 18; | |
20087 | hi = (value & 0x0003f000) >> 12; | |
20088 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 20089 | |
2fc8bdac ZW |
20090 | newval = md_chars_to_number (buf, THUMB_SIZE); |
20091 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20092 | newval |= (S << 10) | hi; | |
20093 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
20094 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20095 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
20096 | } | |
c19d1205 | 20097 | break; |
6c43fab6 | 20098 | |
c19d1205 | 20099 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
20100 | |
20101 | /* If there is a blx from a thumb state function to | |
20102 | another thumb function flip this to a bl and warn | |
20103 | about it. */ | |
20104 | ||
20105 | if (fixP->fx_addsy | |
20106 | && S_IS_DEFINED (fixP->fx_addsy) | |
20107 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20108 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20109 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
20110 | { | |
20111 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
20112 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
20113 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
20114 | name); | |
20115 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20116 | newval = newval | 0x1000; | |
20117 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
20118 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20119 | fixP->fx_done = 1; | |
20120 | } | |
20121 | ||
20122 | ||
20123 | goto thumb_bl_common; | |
20124 | ||
c19d1205 | 20125 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
20126 | |
20127 | /* A bl from Thumb state ISA to an internal ARM state function | |
20128 | is converted to a blx. */ | |
20129 | if (fixP->fx_addsy | |
20130 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20131 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20132 | && S_IS_DEFINED (fixP->fx_addsy) | |
20133 | && ARM_IS_FUNC (fixP->fx_addsy) | |
20134 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20135 | { | |
20136 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20137 | newval = newval & ~0x1000; | |
20138 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
20139 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
20140 | fixP->fx_done = 1; | |
20141 | } | |
20142 | ||
20143 | thumb_bl_common: | |
20144 | ||
20145 | #ifdef OBJ_ELF | |
20146 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 && | |
20147 | fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
20148 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20149 | #endif | |
20150 | ||
2fc8bdac ZW |
20151 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
20152 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20153 | _("branch out of range")); | |
404ff6b5 | 20154 | |
2fc8bdac ZW |
20155 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
20156 | /* For a BLX instruction, make sure that the relocation is rounded up | |
20157 | to a word boundary. This follows the semantics of the instruction | |
20158 | which specifies that bit 1 of the target address will come from bit | |
20159 | 1 of the base address. */ | |
20160 | value = (value + 1) & ~ 1; | |
404ff6b5 | 20161 | |
2fc8bdac | 20162 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20163 | { |
2fc8bdac ZW |
20164 | offsetT newval2; |
20165 | ||
20166 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20167 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20168 | newval |= (value & 0x7fffff) >> 12; | |
20169 | newval2 |= (value & 0xfff) >> 1; | |
20170 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20171 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 20172 | } |
c19d1205 | 20173 | break; |
404ff6b5 | 20174 | |
c19d1205 | 20175 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
20176 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
20177 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20178 | _("branch out of range")); | |
6c43fab6 | 20179 | |
2fc8bdac ZW |
20180 | if (fixP->fx_done || !seg->use_rela_p) |
20181 | { | |
20182 | offsetT newval2; | |
20183 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 20184 | |
2fc8bdac ZW |
20185 | S = (value & 0x01000000) >> 24; |
20186 | I1 = (value & 0x00800000) >> 23; | |
20187 | I2 = (value & 0x00400000) >> 22; | |
20188 | hi = (value & 0x003ff000) >> 12; | |
20189 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 20190 | |
2fc8bdac ZW |
20191 | I1 = !(I1 ^ S); |
20192 | I2 = !(I2 ^ S); | |
a737bd4d | 20193 | |
2fc8bdac ZW |
20194 | newval = md_chars_to_number (buf, THUMB_SIZE); |
20195 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20196 | newval |= (S << 10) | hi; | |
20197 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
20198 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20199 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
20200 | } | |
20201 | break; | |
a737bd4d | 20202 | |
2fc8bdac ZW |
20203 | case BFD_RELOC_8: |
20204 | if (fixP->fx_done || !seg->use_rela_p) | |
20205 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 20206 | break; |
a737bd4d | 20207 | |
c19d1205 | 20208 | case BFD_RELOC_16: |
2fc8bdac | 20209 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20210 | md_number_to_chars (buf, value, 2); |
c19d1205 | 20211 | break; |
a737bd4d | 20212 | |
c19d1205 ZW |
20213 | #ifdef OBJ_ELF |
20214 | case BFD_RELOC_ARM_TLS_GD32: | |
20215 | case BFD_RELOC_ARM_TLS_LE32: | |
20216 | case BFD_RELOC_ARM_TLS_IE32: | |
20217 | case BFD_RELOC_ARM_TLS_LDM32: | |
20218 | case BFD_RELOC_ARM_TLS_LDO32: | |
20219 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
20220 | /* fall through */ | |
6c43fab6 | 20221 | |
c19d1205 ZW |
20222 | case BFD_RELOC_ARM_GOT32: |
20223 | case BFD_RELOC_ARM_GOTOFF: | |
2fc8bdac ZW |
20224 | if (fixP->fx_done || !seg->use_rela_p) |
20225 | md_number_to_chars (buf, 0, 4); | |
c19d1205 | 20226 | break; |
9a6f4e97 NS |
20227 | |
20228 | case BFD_RELOC_ARM_TARGET2: | |
20229 | /* TARGET2 is not partial-inplace, so we need to write the | |
20230 | addend here for REL targets, because it won't be written out | |
20231 | during reloc processing later. */ | |
20232 | if (fixP->fx_done || !seg->use_rela_p) | |
20233 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
20234 | break; | |
c19d1205 | 20235 | #endif |
6c43fab6 | 20236 | |
c19d1205 ZW |
20237 | case BFD_RELOC_RVA: |
20238 | case BFD_RELOC_32: | |
20239 | case BFD_RELOC_ARM_TARGET1: | |
20240 | case BFD_RELOC_ARM_ROSEGREL32: | |
20241 | case BFD_RELOC_ARM_SBREL32: | |
20242 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
20243 | #ifdef TE_PE |
20244 | case BFD_RELOC_32_SECREL: | |
20245 | #endif | |
2fc8bdac | 20246 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
20247 | #ifdef TE_WINCE |
20248 | /* For WinCE we only do this for pcrel fixups. */ | |
20249 | if (fixP->fx_done || fixP->fx_pcrel) | |
20250 | #endif | |
20251 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 20252 | break; |
6c43fab6 | 20253 | |
c19d1205 ZW |
20254 | #ifdef OBJ_ELF |
20255 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 20256 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
20257 | { |
20258 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
20259 | if ((value ^ (value >> 1)) & 0x40000000) | |
20260 | { | |
20261 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20262 | _("rel31 relocation overflow")); | |
20263 | } | |
20264 | newval |= value & 0x7fffffff; | |
20265 | md_number_to_chars (buf, newval, 4); | |
20266 | } | |
20267 | break; | |
c19d1205 | 20268 | #endif |
a737bd4d | 20269 | |
c19d1205 | 20270 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 20271 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
20272 | if (value < -1023 || value > 1023 || (value & 3)) |
20273 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20274 | _("co-processor offset out of range")); | |
20275 | cp_off_common: | |
20276 | sign = value >= 0; | |
20277 | if (value < 0) | |
20278 | value = -value; | |
8f06b2d8 PB |
20279 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20280 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20281 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20282 | else | |
20283 | newval = get_thumb32_insn (buf); | |
20284 | newval &= 0xff7fff00; | |
c19d1205 | 20285 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
8f06b2d8 PB |
20286 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20287 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20288 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20289 | else | |
20290 | put_thumb32_insn (buf, newval); | |
c19d1205 | 20291 | break; |
a737bd4d | 20292 | |
c19d1205 | 20293 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 20294 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
20295 | if (value < -255 || value > 255) |
20296 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20297 | _("co-processor offset out of range")); | |
df7849c5 | 20298 | value *= 4; |
c19d1205 | 20299 | goto cp_off_common; |
6c43fab6 | 20300 | |
c19d1205 ZW |
20301 | case BFD_RELOC_ARM_THUMB_OFFSET: |
20302 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20303 | /* Exactly what ranges, and where the offset is inserted depends | |
20304 | on the type of instruction, we can establish this from the | |
20305 | top 4 bits. */ | |
20306 | switch (newval >> 12) | |
20307 | { | |
20308 | case 4: /* PC load. */ | |
20309 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
20310 | forced to zero for these loads; md_pcrel_from has already | |
20311 | compensated for this. */ | |
20312 | if (value & 3) | |
20313 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20314 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
20315 | (((unsigned long) fixP->fx_frag->fr_address |
20316 | + (unsigned long) fixP->fx_where) & ~3) | |
20317 | + (unsigned long) value); | |
a737bd4d | 20318 | |
c19d1205 ZW |
20319 | if (value & ~0x3fc) |
20320 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20321 | _("invalid offset, value too big (0x%08lX)"), | |
20322 | (long) value); | |
a737bd4d | 20323 | |
c19d1205 ZW |
20324 | newval |= value >> 2; |
20325 | break; | |
a737bd4d | 20326 | |
c19d1205 ZW |
20327 | case 9: /* SP load/store. */ |
20328 | if (value & ~0x3fc) | |
20329 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20330 | _("invalid offset, value too big (0x%08lX)"), | |
20331 | (long) value); | |
20332 | newval |= value >> 2; | |
20333 | break; | |
6c43fab6 | 20334 | |
c19d1205 ZW |
20335 | case 6: /* Word load/store. */ |
20336 | if (value & ~0x7c) | |
20337 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20338 | _("invalid offset, value too big (0x%08lX)"), | |
20339 | (long) value); | |
20340 | newval |= value << 4; /* 6 - 2. */ | |
20341 | break; | |
a737bd4d | 20342 | |
c19d1205 ZW |
20343 | case 7: /* Byte load/store. */ |
20344 | if (value & ~0x1f) | |
20345 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20346 | _("invalid offset, value too big (0x%08lX)"), | |
20347 | (long) value); | |
20348 | newval |= value << 6; | |
20349 | break; | |
a737bd4d | 20350 | |
c19d1205 ZW |
20351 | case 8: /* Halfword load/store. */ |
20352 | if (value & ~0x3e) | |
20353 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20354 | _("invalid offset, value too big (0x%08lX)"), | |
20355 | (long) value); | |
20356 | newval |= value << 5; /* 6 - 1. */ | |
20357 | break; | |
a737bd4d | 20358 | |
c19d1205 ZW |
20359 | default: |
20360 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20361 | "Unable to process relocation for thumb opcode: %lx", | |
20362 | (unsigned long) newval); | |
20363 | break; | |
20364 | } | |
20365 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20366 | break; | |
a737bd4d | 20367 | |
c19d1205 ZW |
20368 | case BFD_RELOC_ARM_THUMB_ADD: |
20369 | /* This is a complicated relocation, since we use it for all of | |
20370 | the following immediate relocations: | |
a737bd4d | 20371 | |
c19d1205 ZW |
20372 | 3bit ADD/SUB |
20373 | 8bit ADD/SUB | |
20374 | 9bit ADD/SUB SP word-aligned | |
20375 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 20376 | |
c19d1205 ZW |
20377 | The type of instruction being processed is encoded in the |
20378 | instruction field: | |
a737bd4d | 20379 | |
c19d1205 ZW |
20380 | 0x8000 SUB |
20381 | 0x00F0 Rd | |
20382 | 0x000F Rs | |
20383 | */ | |
20384 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20385 | { | |
20386 | int rd = (newval >> 4) & 0xf; | |
20387 | int rs = newval & 0xf; | |
20388 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 20389 | |
c19d1205 ZW |
20390 | /* Check for HI regs, only very restricted cases allowed: |
20391 | Adjusting SP, and using PC or SP to get an address. */ | |
20392 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
20393 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
20394 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20395 | _("invalid Hi register with immediate")); | |
a737bd4d | 20396 | |
c19d1205 ZW |
20397 | /* If value is negative, choose the opposite instruction. */ |
20398 | if (value < 0) | |
20399 | { | |
20400 | value = -value; | |
20401 | subtract = !subtract; | |
20402 | if (value < 0) | |
20403 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20404 | _("immediate value out of range")); | |
20405 | } | |
a737bd4d | 20406 | |
c19d1205 ZW |
20407 | if (rd == REG_SP) |
20408 | { | |
20409 | if (value & ~0x1fc) | |
20410 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20411 | _("invalid immediate for stack address calculation")); | |
20412 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
20413 | newval |= value >> 2; | |
20414 | } | |
20415 | else if (rs == REG_PC || rs == REG_SP) | |
20416 | { | |
20417 | if (subtract || value & ~0x3fc) | |
20418 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20419 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
20420 | (unsigned long) value); | |
20421 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
20422 | newval |= rd << 8; | |
20423 | newval |= value >> 2; | |
20424 | } | |
20425 | else if (rs == rd) | |
20426 | { | |
20427 | if (value & ~0xff) | |
20428 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20429 | _("immediate value out of range")); | |
20430 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
20431 | newval |= (rd << 8) | value; | |
20432 | } | |
20433 | else | |
20434 | { | |
20435 | if (value & ~0x7) | |
20436 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20437 | _("immediate value out of range")); | |
20438 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
20439 | newval |= rd | (rs << 3) | (value << 6); | |
20440 | } | |
20441 | } | |
20442 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20443 | break; | |
a737bd4d | 20444 | |
c19d1205 ZW |
20445 | case BFD_RELOC_ARM_THUMB_IMM: |
20446 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20447 | if (value < 0 || value > 255) | |
20448 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 20449 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
20450 | (long) value); |
20451 | newval |= value; | |
20452 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20453 | break; | |
a737bd4d | 20454 | |
c19d1205 ZW |
20455 | case BFD_RELOC_ARM_THUMB_SHIFT: |
20456 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
20457 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
20458 | temp = newval & 0xf800; | |
20459 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
20460 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20461 | _("invalid shift value: %ld"), (long) value); | |
20462 | /* Shifts of zero must be encoded as LSL. */ | |
20463 | if (value == 0) | |
20464 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
20465 | /* Shifts of 32 are encoded as zero. */ | |
20466 | else if (value == 32) | |
20467 | value = 0; | |
20468 | newval |= value << 6; | |
20469 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20470 | break; | |
a737bd4d | 20471 | |
c19d1205 ZW |
20472 | case BFD_RELOC_VTABLE_INHERIT: |
20473 | case BFD_RELOC_VTABLE_ENTRY: | |
20474 | fixP->fx_done = 0; | |
20475 | return; | |
6c43fab6 | 20476 | |
b6895b4f PB |
20477 | case BFD_RELOC_ARM_MOVW: |
20478 | case BFD_RELOC_ARM_MOVT: | |
20479 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20480 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20481 | if (fixP->fx_done || !seg->use_rela_p) | |
20482 | { | |
20483 | /* REL format relocations are limited to a 16-bit addend. */ | |
20484 | if (!fixP->fx_done) | |
20485 | { | |
39623e12 | 20486 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 20487 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 20488 | _("offset out of range")); |
b6895b4f PB |
20489 | } |
20490 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
20491 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20492 | { | |
20493 | value >>= 16; | |
20494 | } | |
20495 | ||
20496 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
20497 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20498 | { | |
20499 | newval = get_thumb32_insn (buf); | |
20500 | newval &= 0xfbf08f00; | |
20501 | newval |= (value & 0xf000) << 4; | |
20502 | newval |= (value & 0x0800) << 15; | |
20503 | newval |= (value & 0x0700) << 4; | |
20504 | newval |= (value & 0x00ff); | |
20505 | put_thumb32_insn (buf, newval); | |
20506 | } | |
20507 | else | |
20508 | { | |
20509 | newval = md_chars_to_number (buf, 4); | |
20510 | newval &= 0xfff0f000; | |
20511 | newval |= value & 0x0fff; | |
20512 | newval |= (value & 0xf000) << 4; | |
20513 | md_number_to_chars (buf, newval, 4); | |
20514 | } | |
20515 | } | |
20516 | return; | |
20517 | ||
4962c51a MS |
20518 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20519 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20520 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20521 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20522 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20523 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20524 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20525 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20526 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20527 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 20528 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20529 | if (!seg->use_rela_p) |
20530 | { | |
20531 | bfd_vma insn; | |
20532 | bfd_vma encoded_addend; | |
20533 | bfd_vma addend_abs = abs (value); | |
20534 | ||
20535 | /* Check that the absolute value of the addend can be | |
20536 | expressed as an 8-bit constant plus a rotation. */ | |
20537 | encoded_addend = encode_arm_immediate (addend_abs); | |
20538 | if (encoded_addend == (unsigned int) FAIL) | |
20539 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20540 | _("the offset 0x%08lX is not representable"), | |
495bde8e | 20541 | (unsigned long) addend_abs); |
4962c51a MS |
20542 | |
20543 | /* Extract the instruction. */ | |
20544 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20545 | ||
20546 | /* If the addend is positive, use an ADD instruction. | |
20547 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
20548 | insn &= 0xff1fffff; | |
20549 | if (value < 0) | |
20550 | insn |= 1 << 22; | |
20551 | else | |
20552 | insn |= 1 << 23; | |
20553 | ||
20554 | /* Place the encoded addend into the first 12 bits of the | |
20555 | instruction. */ | |
20556 | insn &= 0xfffff000; | |
20557 | insn |= encoded_addend; | |
5f4273c7 NC |
20558 | |
20559 | /* Update the instruction. */ | |
4962c51a MS |
20560 | md_number_to_chars (buf, insn, INSN_SIZE); |
20561 | } | |
20562 | break; | |
20563 | ||
20564 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20565 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20566 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20567 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20568 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20569 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 20570 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20571 | if (!seg->use_rela_p) |
20572 | { | |
20573 | bfd_vma insn; | |
20574 | bfd_vma addend_abs = abs (value); | |
20575 | ||
20576 | /* Check that the absolute value of the addend can be | |
20577 | encoded in 12 bits. */ | |
20578 | if (addend_abs >= 0x1000) | |
20579 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20580 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
495bde8e | 20581 | (unsigned long) addend_abs); |
4962c51a MS |
20582 | |
20583 | /* Extract the instruction. */ | |
20584 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20585 | ||
20586 | /* If the addend is negative, clear bit 23 of the instruction. | |
20587 | Otherwise set it. */ | |
20588 | if (value < 0) | |
20589 | insn &= ~(1 << 23); | |
20590 | else | |
20591 | insn |= 1 << 23; | |
20592 | ||
20593 | /* Place the absolute value of the addend into the first 12 bits | |
20594 | of the instruction. */ | |
20595 | insn &= 0xfffff000; | |
20596 | insn |= addend_abs; | |
5f4273c7 NC |
20597 | |
20598 | /* Update the instruction. */ | |
4962c51a MS |
20599 | md_number_to_chars (buf, insn, INSN_SIZE); |
20600 | } | |
20601 | break; | |
20602 | ||
20603 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20604 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20605 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20606 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20607 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20608 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 20609 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20610 | if (!seg->use_rela_p) |
20611 | { | |
20612 | bfd_vma insn; | |
20613 | bfd_vma addend_abs = abs (value); | |
20614 | ||
20615 | /* Check that the absolute value of the addend can be | |
20616 | encoded in 8 bits. */ | |
20617 | if (addend_abs >= 0x100) | |
20618 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20619 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
495bde8e | 20620 | (unsigned long) addend_abs); |
4962c51a MS |
20621 | |
20622 | /* Extract the instruction. */ | |
20623 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20624 | ||
20625 | /* If the addend is negative, clear bit 23 of the instruction. | |
20626 | Otherwise set it. */ | |
20627 | if (value < 0) | |
20628 | insn &= ~(1 << 23); | |
20629 | else | |
20630 | insn |= 1 << 23; | |
20631 | ||
20632 | /* Place the first four bits of the absolute value of the addend | |
20633 | into the first 4 bits of the instruction, and the remaining | |
20634 | four into bits 8 .. 11. */ | |
20635 | insn &= 0xfffff0f0; | |
20636 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
5f4273c7 NC |
20637 | |
20638 | /* Update the instruction. */ | |
4962c51a MS |
20639 | md_number_to_chars (buf, insn, INSN_SIZE); |
20640 | } | |
20641 | break; | |
20642 | ||
20643 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20644 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20645 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20646 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20647 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20648 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 20649 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20650 | if (!seg->use_rela_p) |
20651 | { | |
20652 | bfd_vma insn; | |
20653 | bfd_vma addend_abs = abs (value); | |
20654 | ||
20655 | /* Check that the absolute value of the addend is a multiple of | |
20656 | four and, when divided by four, fits in 8 bits. */ | |
20657 | if (addend_abs & 0x3) | |
20658 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20659 | _("bad offset 0x%08lX (must be word-aligned)"), | |
495bde8e | 20660 | (unsigned long) addend_abs); |
4962c51a MS |
20661 | |
20662 | if ((addend_abs >> 2) > 0xff) | |
20663 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20664 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
495bde8e | 20665 | (unsigned long) addend_abs); |
4962c51a MS |
20666 | |
20667 | /* Extract the instruction. */ | |
20668 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20669 | ||
20670 | /* If the addend is negative, clear bit 23 of the instruction. | |
20671 | Otherwise set it. */ | |
20672 | if (value < 0) | |
20673 | insn &= ~(1 << 23); | |
20674 | else | |
20675 | insn |= 1 << 23; | |
20676 | ||
20677 | /* Place the addend (divided by four) into the first eight | |
20678 | bits of the instruction. */ | |
20679 | insn &= 0xfffffff0; | |
20680 | insn |= addend_abs >> 2; | |
5f4273c7 NC |
20681 | |
20682 | /* Update the instruction. */ | |
4962c51a MS |
20683 | md_number_to_chars (buf, insn, INSN_SIZE); |
20684 | } | |
20685 | break; | |
20686 | ||
845b51d6 PB |
20687 | case BFD_RELOC_ARM_V4BX: |
20688 | /* This will need to go in the object file. */ | |
20689 | fixP->fx_done = 0; | |
20690 | break; | |
20691 | ||
c19d1205 ZW |
20692 | case BFD_RELOC_UNUSED: |
20693 | default: | |
20694 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20695 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
20696 | } | |
6c43fab6 RE |
20697 | } |
20698 | ||
c19d1205 ZW |
20699 | /* Translate internal representation of relocation info to BFD target |
20700 | format. */ | |
a737bd4d | 20701 | |
c19d1205 | 20702 | arelent * |
00a97672 | 20703 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 20704 | { |
c19d1205 ZW |
20705 | arelent * reloc; |
20706 | bfd_reloc_code_real_type code; | |
a737bd4d | 20707 | |
21d799b5 | 20708 | reloc = (arelent *) xmalloc (sizeof (arelent)); |
a737bd4d | 20709 | |
21d799b5 | 20710 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
c19d1205 ZW |
20711 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
20712 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 20713 | |
2fc8bdac | 20714 | if (fixp->fx_pcrel) |
00a97672 RS |
20715 | { |
20716 | if (section->use_rela_p) | |
20717 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
20718 | else | |
20719 | fixp->fx_offset = reloc->address; | |
20720 | } | |
c19d1205 | 20721 | reloc->addend = fixp->fx_offset; |
a737bd4d | 20722 | |
c19d1205 | 20723 | switch (fixp->fx_r_type) |
a737bd4d | 20724 | { |
c19d1205 ZW |
20725 | case BFD_RELOC_8: |
20726 | if (fixp->fx_pcrel) | |
20727 | { | |
20728 | code = BFD_RELOC_8_PCREL; | |
20729 | break; | |
20730 | } | |
a737bd4d | 20731 | |
c19d1205 ZW |
20732 | case BFD_RELOC_16: |
20733 | if (fixp->fx_pcrel) | |
20734 | { | |
20735 | code = BFD_RELOC_16_PCREL; | |
20736 | break; | |
20737 | } | |
6c43fab6 | 20738 | |
c19d1205 ZW |
20739 | case BFD_RELOC_32: |
20740 | if (fixp->fx_pcrel) | |
20741 | { | |
20742 | code = BFD_RELOC_32_PCREL; | |
20743 | break; | |
20744 | } | |
a737bd4d | 20745 | |
b6895b4f PB |
20746 | case BFD_RELOC_ARM_MOVW: |
20747 | if (fixp->fx_pcrel) | |
20748 | { | |
20749 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
20750 | break; | |
20751 | } | |
20752 | ||
20753 | case BFD_RELOC_ARM_MOVT: | |
20754 | if (fixp->fx_pcrel) | |
20755 | { | |
20756 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
20757 | break; | |
20758 | } | |
20759 | ||
20760 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20761 | if (fixp->fx_pcrel) | |
20762 | { | |
20763 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
20764 | break; | |
20765 | } | |
20766 | ||
20767 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20768 | if (fixp->fx_pcrel) | |
20769 | { | |
20770 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
20771 | break; | |
20772 | } | |
20773 | ||
c19d1205 ZW |
20774 | case BFD_RELOC_NONE: |
20775 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
20776 | case BFD_RELOC_ARM_PCREL_BLX: | |
20777 | case BFD_RELOC_RVA: | |
20778 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
20779 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
20780 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
20781 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20782 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20783 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
20784 | case BFD_RELOC_VTABLE_ENTRY: |
20785 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
20786 | #ifdef TE_PE |
20787 | case BFD_RELOC_32_SECREL: | |
20788 | #endif | |
c19d1205 ZW |
20789 | code = fixp->fx_r_type; |
20790 | break; | |
a737bd4d | 20791 | |
00adf2d4 JB |
20792 | case BFD_RELOC_THUMB_PCREL_BLX: |
20793 | #ifdef OBJ_ELF | |
20794 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
20795 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20796 | else | |
20797 | #endif | |
20798 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
20799 | break; | |
20800 | ||
c19d1205 ZW |
20801 | case BFD_RELOC_ARM_LITERAL: |
20802 | case BFD_RELOC_ARM_HWLITERAL: | |
20803 | /* If this is called then the a literal has | |
20804 | been referenced across a section boundary. */ | |
20805 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20806 | _("literal referenced across section boundary")); | |
20807 | return NULL; | |
a737bd4d | 20808 | |
c19d1205 ZW |
20809 | #ifdef OBJ_ELF |
20810 | case BFD_RELOC_ARM_GOT32: | |
20811 | case BFD_RELOC_ARM_GOTOFF: | |
20812 | case BFD_RELOC_ARM_PLT32: | |
20813 | case BFD_RELOC_ARM_TARGET1: | |
20814 | case BFD_RELOC_ARM_ROSEGREL32: | |
20815 | case BFD_RELOC_ARM_SBREL32: | |
20816 | case BFD_RELOC_ARM_PREL31: | |
20817 | case BFD_RELOC_ARM_TARGET2: | |
20818 | case BFD_RELOC_ARM_TLS_LE32: | |
20819 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
20820 | case BFD_RELOC_ARM_PCREL_CALL: |
20821 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
20822 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20823 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20824 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20825 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20826 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20827 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20828 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20829 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20830 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20831 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20832 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20833 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20834 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20835 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20836 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20837 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20838 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20839 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20840 | case BFD_RELOC_ARM_ALU_SB_G2: | |
20841 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20842 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20843 | case BFD_RELOC_ARM_LDR_SB_G2: | |
20844 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20845 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20846 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
20847 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20848 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20849 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 20850 | case BFD_RELOC_ARM_V4BX: |
c19d1205 ZW |
20851 | code = fixp->fx_r_type; |
20852 | break; | |
a737bd4d | 20853 | |
c19d1205 ZW |
20854 | case BFD_RELOC_ARM_TLS_GD32: |
20855 | case BFD_RELOC_ARM_TLS_IE32: | |
20856 | case BFD_RELOC_ARM_TLS_LDM32: | |
20857 | /* BFD will include the symbol's address in the addend. | |
20858 | But we don't want that, so subtract it out again here. */ | |
20859 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
20860 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
20861 | code = fixp->fx_r_type; | |
20862 | break; | |
20863 | #endif | |
a737bd4d | 20864 | |
c19d1205 ZW |
20865 | case BFD_RELOC_ARM_IMMEDIATE: |
20866 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20867 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
20868 | return NULL; | |
a737bd4d | 20869 | |
c19d1205 ZW |
20870 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
20871 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20872 | _("ADRL used for a symbol not defined in the same file")); | |
20873 | return NULL; | |
a737bd4d | 20874 | |
c19d1205 | 20875 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
20876 | if (section->use_rela_p) |
20877 | { | |
20878 | code = fixp->fx_r_type; | |
20879 | break; | |
20880 | } | |
20881 | ||
c19d1205 ZW |
20882 | if (fixp->fx_addsy != NULL |
20883 | && !S_IS_DEFINED (fixp->fx_addsy) | |
20884 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 20885 | { |
c19d1205 ZW |
20886 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20887 | _("undefined local label `%s'"), | |
20888 | S_GET_NAME (fixp->fx_addsy)); | |
20889 | return NULL; | |
a737bd4d NC |
20890 | } |
20891 | ||
c19d1205 ZW |
20892 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20893 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
20894 | return NULL; | |
a737bd4d | 20895 | |
c19d1205 ZW |
20896 | default: |
20897 | { | |
20898 | char * type; | |
6c43fab6 | 20899 | |
c19d1205 ZW |
20900 | switch (fixp->fx_r_type) |
20901 | { | |
20902 | case BFD_RELOC_NONE: type = "NONE"; break; | |
20903 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
20904 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 20905 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
20906 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
20907 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
20908 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 20909 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
20910 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
20911 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
20912 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
20913 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
20914 | default: type = _("<unknown>"); break; | |
20915 | } | |
20916 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20917 | _("cannot represent %s relocation in this object file format"), | |
20918 | type); | |
20919 | return NULL; | |
20920 | } | |
a737bd4d | 20921 | } |
6c43fab6 | 20922 | |
c19d1205 ZW |
20923 | #ifdef OBJ_ELF |
20924 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
20925 | && GOT_symbol | |
20926 | && fixp->fx_addsy == GOT_symbol) | |
20927 | { | |
20928 | code = BFD_RELOC_ARM_GOTPC; | |
20929 | reloc->addend = fixp->fx_offset = reloc->address; | |
20930 | } | |
20931 | #endif | |
6c43fab6 | 20932 | |
c19d1205 | 20933 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 20934 | |
c19d1205 ZW |
20935 | if (reloc->howto == NULL) |
20936 | { | |
20937 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20938 | _("cannot represent %s relocation in this object file format"), | |
20939 | bfd_get_reloc_code_name (code)); | |
20940 | return NULL; | |
20941 | } | |
6c43fab6 | 20942 | |
c19d1205 ZW |
20943 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
20944 | vtable entry to be used in the relocation's section offset. */ | |
20945 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
20946 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 20947 | |
c19d1205 | 20948 | return reloc; |
6c43fab6 RE |
20949 | } |
20950 | ||
c19d1205 | 20951 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 20952 | |
c19d1205 ZW |
20953 | void |
20954 | cons_fix_new_arm (fragS * frag, | |
20955 | int where, | |
20956 | int size, | |
20957 | expressionS * exp) | |
6c43fab6 | 20958 | { |
c19d1205 ZW |
20959 | bfd_reloc_code_real_type type; |
20960 | int pcrel = 0; | |
6c43fab6 | 20961 | |
c19d1205 ZW |
20962 | /* Pick a reloc. |
20963 | FIXME: @@ Should look at CPU word size. */ | |
20964 | switch (size) | |
20965 | { | |
20966 | case 1: | |
20967 | type = BFD_RELOC_8; | |
20968 | break; | |
20969 | case 2: | |
20970 | type = BFD_RELOC_16; | |
20971 | break; | |
20972 | case 4: | |
20973 | default: | |
20974 | type = BFD_RELOC_32; | |
20975 | break; | |
20976 | case 8: | |
20977 | type = BFD_RELOC_64; | |
20978 | break; | |
20979 | } | |
6c43fab6 | 20980 | |
f0927246 NC |
20981 | #ifdef TE_PE |
20982 | if (exp->X_op == O_secrel) | |
20983 | { | |
20984 | exp->X_op = O_symbol; | |
20985 | type = BFD_RELOC_32_SECREL; | |
20986 | } | |
20987 | #endif | |
20988 | ||
c19d1205 ZW |
20989 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
20990 | } | |
6c43fab6 | 20991 | |
4343666d | 20992 | #if defined (OBJ_COFF) |
c19d1205 ZW |
20993 | void |
20994 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 20995 | { |
c19d1205 ZW |
20996 | /* If the destination of the branch is a defined symbol which does not have |
20997 | the THUMB_FUNC attribute, then we must be calling a function which has | |
20998 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
20999 | function and change the branch to refer to that function instead. */ | |
21000 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
21001 | && fixP->fx_addsy != NULL | |
21002 | && S_IS_DEFINED (fixP->fx_addsy) | |
21003 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 21004 | { |
c19d1205 | 21005 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 21006 | } |
c19d1205 ZW |
21007 | } |
21008 | #endif | |
6c43fab6 | 21009 | |
267bf995 | 21010 | |
c19d1205 ZW |
21011 | int |
21012 | arm_force_relocation (struct fix * fixp) | |
21013 | { | |
21014 | #if defined (OBJ_COFF) && defined (TE_PE) | |
21015 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
21016 | return 1; | |
21017 | #endif | |
6c43fab6 | 21018 | |
267bf995 RR |
21019 | /* In case we have a call or a branch to a function in ARM ISA mode from |
21020 | a thumb function or vice-versa force the relocation. These relocations | |
21021 | are cleared off for some cores that might have blx and simple transformations | |
21022 | are possible. */ | |
21023 | ||
21024 | #ifdef OBJ_ELF | |
21025 | switch (fixp->fx_r_type) | |
21026 | { | |
21027 | case BFD_RELOC_ARM_PCREL_JUMP: | |
21028 | case BFD_RELOC_ARM_PCREL_CALL: | |
21029 | case BFD_RELOC_THUMB_PCREL_BLX: | |
21030 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
21031 | return 1; | |
21032 | break; | |
21033 | ||
21034 | case BFD_RELOC_ARM_PCREL_BLX: | |
21035 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
21036 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
21037 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
21038 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
21039 | return 1; | |
21040 | break; | |
21041 | ||
21042 | default: | |
21043 | break; | |
21044 | } | |
21045 | #endif | |
21046 | ||
c19d1205 ZW |
21047 | /* Resolve these relocations even if the symbol is extern or weak. */ |
21048 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
21049 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 | 21050 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
16805f35 | 21051 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
21052 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
21053 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
21054 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 21055 | return 0; |
a737bd4d | 21056 | |
4962c51a MS |
21057 | /* Always leave these relocations for the linker. */ |
21058 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
21059 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
21060 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
21061 | return 1; | |
21062 | ||
f0291e4c PB |
21063 | /* Always generate relocations against function symbols. */ |
21064 | if (fixp->fx_r_type == BFD_RELOC_32 | |
21065 | && fixp->fx_addsy | |
21066 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
21067 | return 1; | |
21068 | ||
c19d1205 | 21069 | return generic_force_reloc (fixp); |
404ff6b5 AH |
21070 | } |
21071 | ||
0ffdc86c | 21072 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
21073 | /* Relocations against function names must be left unadjusted, |
21074 | so that the linker can use this information to generate interworking | |
21075 | stubs. The MIPS version of this function | |
c19d1205 ZW |
21076 | also prevents relocations that are mips-16 specific, but I do not |
21077 | know why it does this. | |
404ff6b5 | 21078 | |
c19d1205 ZW |
21079 | FIXME: |
21080 | There is one other problem that ought to be addressed here, but | |
21081 | which currently is not: Taking the address of a label (rather | |
21082 | than a function) and then later jumping to that address. Such | |
21083 | addresses also ought to have their bottom bit set (assuming that | |
21084 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 21085 | |
c19d1205 ZW |
21086 | bfd_boolean |
21087 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 21088 | { |
c19d1205 ZW |
21089 | if (fixP->fx_addsy == NULL) |
21090 | return 1; | |
404ff6b5 | 21091 | |
e28387c3 PB |
21092 | /* Preserve relocations against symbols with function type. */ |
21093 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 21094 | return FALSE; |
e28387c3 | 21095 | |
c19d1205 ZW |
21096 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
21097 | && fixP->fx_subsy == NULL) | |
c921be7d | 21098 | return FALSE; |
a737bd4d | 21099 | |
c19d1205 ZW |
21100 | /* We need the symbol name for the VTABLE entries. */ |
21101 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
21102 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 21103 | return FALSE; |
404ff6b5 | 21104 | |
c19d1205 ZW |
21105 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
21106 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
21107 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
21108 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
21109 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
21110 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
21111 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
21112 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
21113 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
21114 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
c921be7d | 21115 | return FALSE; |
a737bd4d | 21116 | |
4962c51a MS |
21117 | /* Similarly for group relocations. */ |
21118 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
21119 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
21120 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 21121 | return FALSE; |
4962c51a | 21122 | |
79947c54 CD |
21123 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
21124 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
21125 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
21126 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
21127 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
21128 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
21129 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
21130 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
21131 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 21132 | return FALSE; |
79947c54 | 21133 | |
c921be7d | 21134 | return TRUE; |
a737bd4d | 21135 | } |
0ffdc86c NC |
21136 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
21137 | ||
21138 | #ifdef OBJ_ELF | |
404ff6b5 | 21139 | |
c19d1205 ZW |
21140 | const char * |
21141 | elf32_arm_target_format (void) | |
404ff6b5 | 21142 | { |
c19d1205 ZW |
21143 | #ifdef TE_SYMBIAN |
21144 | return (target_big_endian | |
21145 | ? "elf32-bigarm-symbian" | |
21146 | : "elf32-littlearm-symbian"); | |
21147 | #elif defined (TE_VXWORKS) | |
21148 | return (target_big_endian | |
21149 | ? "elf32-bigarm-vxworks" | |
21150 | : "elf32-littlearm-vxworks"); | |
21151 | #else | |
21152 | if (target_big_endian) | |
21153 | return "elf32-bigarm"; | |
21154 | else | |
21155 | return "elf32-littlearm"; | |
21156 | #endif | |
404ff6b5 AH |
21157 | } |
21158 | ||
c19d1205 ZW |
21159 | void |
21160 | armelf_frob_symbol (symbolS * symp, | |
21161 | int * puntp) | |
404ff6b5 | 21162 | { |
c19d1205 ZW |
21163 | elf_frob_symbol (symp, puntp); |
21164 | } | |
21165 | #endif | |
404ff6b5 | 21166 | |
c19d1205 | 21167 | /* MD interface: Finalization. */ |
a737bd4d | 21168 | |
c19d1205 ZW |
21169 | void |
21170 | arm_cleanup (void) | |
21171 | { | |
21172 | literal_pool * pool; | |
a737bd4d | 21173 | |
e07e6e58 NC |
21174 | /* Ensure that all the IT blocks are properly closed. */ |
21175 | check_it_blocks_finished (); | |
21176 | ||
c19d1205 ZW |
21177 | for (pool = list_of_pools; pool; pool = pool->next) |
21178 | { | |
5f4273c7 | 21179 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
21180 | subseg_set (pool->section, pool->sub_section); |
21181 | #ifdef OBJ_ELF | |
21182 | arm_elf_change_section (); | |
21183 | #endif | |
21184 | s_ltorg (0); | |
21185 | } | |
404ff6b5 AH |
21186 | } |
21187 | ||
cd000bff DJ |
21188 | #ifdef OBJ_ELF |
21189 | /* Remove any excess mapping symbols generated for alignment frags in | |
21190 | SEC. We may have created a mapping symbol before a zero byte | |
21191 | alignment; remove it if there's a mapping symbol after the | |
21192 | alignment. */ | |
21193 | static void | |
21194 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
21195 | void *dummy ATTRIBUTE_UNUSED) | |
21196 | { | |
21197 | segment_info_type *seginfo = seg_info (sec); | |
21198 | fragS *fragp; | |
21199 | ||
21200 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
21201 | return; | |
21202 | ||
21203 | for (fragp = seginfo->frchainP->frch_root; | |
21204 | fragp != NULL; | |
21205 | fragp = fragp->fr_next) | |
21206 | { | |
21207 | symbolS *sym = fragp->tc_frag_data.last_map; | |
21208 | fragS *next = fragp->fr_next; | |
21209 | ||
21210 | /* Variable-sized frags have been converted to fixed size by | |
21211 | this point. But if this was variable-sized to start with, | |
21212 | there will be a fixed-size frag after it. So don't handle | |
21213 | next == NULL. */ | |
21214 | if (sym == NULL || next == NULL) | |
21215 | continue; | |
21216 | ||
21217 | if (S_GET_VALUE (sym) < next->fr_address) | |
21218 | /* Not at the end of this frag. */ | |
21219 | continue; | |
21220 | know (S_GET_VALUE (sym) == next->fr_address); | |
21221 | ||
21222 | do | |
21223 | { | |
21224 | if (next->tc_frag_data.first_map != NULL) | |
21225 | { | |
21226 | /* Next frag starts with a mapping symbol. Discard this | |
21227 | one. */ | |
21228 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
21229 | break; | |
21230 | } | |
21231 | ||
21232 | if (next->fr_next == NULL) | |
21233 | { | |
21234 | /* This mapping symbol is at the end of the section. Discard | |
21235 | it. */ | |
21236 | know (next->fr_fix == 0 && next->fr_var == 0); | |
21237 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
21238 | break; | |
21239 | } | |
21240 | ||
21241 | /* As long as we have empty frags without any mapping symbols, | |
21242 | keep looking. */ | |
21243 | /* If the next frag is non-empty and does not start with a | |
21244 | mapping symbol, then this mapping symbol is required. */ | |
21245 | if (next->fr_address != next->fr_next->fr_address) | |
21246 | break; | |
21247 | ||
21248 | next = next->fr_next; | |
21249 | } | |
21250 | while (next != NULL); | |
21251 | } | |
21252 | } | |
21253 | #endif | |
21254 | ||
c19d1205 ZW |
21255 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
21256 | ARM ones. */ | |
404ff6b5 | 21257 | |
c19d1205 ZW |
21258 | void |
21259 | arm_adjust_symtab (void) | |
404ff6b5 | 21260 | { |
c19d1205 ZW |
21261 | #ifdef OBJ_COFF |
21262 | symbolS * sym; | |
404ff6b5 | 21263 | |
c19d1205 ZW |
21264 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
21265 | { | |
21266 | if (ARM_IS_THUMB (sym)) | |
21267 | { | |
21268 | if (THUMB_IS_FUNC (sym)) | |
21269 | { | |
21270 | /* Mark the symbol as a Thumb function. */ | |
21271 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
21272 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
21273 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 21274 | |
c19d1205 ZW |
21275 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
21276 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
21277 | else | |
21278 | as_bad (_("%s: unexpected function type: %d"), | |
21279 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
21280 | } | |
21281 | else switch (S_GET_STORAGE_CLASS (sym)) | |
21282 | { | |
21283 | case C_EXT: | |
21284 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
21285 | break; | |
21286 | case C_STAT: | |
21287 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
21288 | break; | |
21289 | case C_LABEL: | |
21290 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
21291 | break; | |
21292 | default: | |
21293 | /* Do nothing. */ | |
21294 | break; | |
21295 | } | |
21296 | } | |
a737bd4d | 21297 | |
c19d1205 ZW |
21298 | if (ARM_IS_INTERWORK (sym)) |
21299 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 21300 | } |
c19d1205 ZW |
21301 | #endif |
21302 | #ifdef OBJ_ELF | |
21303 | symbolS * sym; | |
21304 | char bind; | |
404ff6b5 | 21305 | |
c19d1205 | 21306 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 21307 | { |
c19d1205 ZW |
21308 | if (ARM_IS_THUMB (sym)) |
21309 | { | |
21310 | elf_symbol_type * elf_sym; | |
404ff6b5 | 21311 | |
c19d1205 ZW |
21312 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
21313 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 21314 | |
b0796911 PB |
21315 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
21316 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
21317 | { |
21318 | /* If it's a .thumb_func, declare it as so, | |
21319 | otherwise tag label as .code 16. */ | |
21320 | if (THUMB_IS_FUNC (sym)) | |
21321 | elf_sym->internal_elf_sym.st_info = | |
21322 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
3ba67470 | 21323 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
21324 | elf_sym->internal_elf_sym.st_info = |
21325 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
21326 | } | |
21327 | } | |
21328 | } | |
cd000bff DJ |
21329 | |
21330 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
21331 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
c19d1205 | 21332 | #endif |
404ff6b5 AH |
21333 | } |
21334 | ||
c19d1205 | 21335 | /* MD interface: Initialization. */ |
404ff6b5 | 21336 | |
a737bd4d | 21337 | static void |
c19d1205 | 21338 | set_constant_flonums (void) |
a737bd4d | 21339 | { |
c19d1205 | 21340 | int i; |
404ff6b5 | 21341 | |
c19d1205 ZW |
21342 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
21343 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
21344 | abort (); | |
a737bd4d | 21345 | } |
404ff6b5 | 21346 | |
3e9e4fcf JB |
21347 | /* Auto-select Thumb mode if it's the only available instruction set for the |
21348 | given architecture. */ | |
21349 | ||
21350 | static void | |
21351 | autoselect_thumb_from_cpu_variant (void) | |
21352 | { | |
21353 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
21354 | opcode_select (16); | |
21355 | } | |
21356 | ||
c19d1205 ZW |
21357 | void |
21358 | md_begin (void) | |
a737bd4d | 21359 | { |
c19d1205 ZW |
21360 | unsigned mach; |
21361 | unsigned int i; | |
404ff6b5 | 21362 | |
c19d1205 ZW |
21363 | if ( (arm_ops_hsh = hash_new ()) == NULL |
21364 | || (arm_cond_hsh = hash_new ()) == NULL | |
21365 | || (arm_shift_hsh = hash_new ()) == NULL | |
21366 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 21367 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 21368 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
21369 | || (arm_reloc_hsh = hash_new ()) == NULL |
21370 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
21371 | as_fatal (_("virtual memory exhausted")); |
21372 | ||
21373 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 21374 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 21375 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 21376 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 21377 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 21378 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 21379 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 21380 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 21381 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 NC |
21382 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
21383 | (void *) (v7m_psrs + i)); | |
c19d1205 | 21384 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 21385 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
21386 | for (i = 0; |
21387 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
21388 | i++) | |
d3ce72d0 | 21389 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 21390 | (void *) (barrier_opt_names + i)); |
c19d1205 ZW |
21391 | #ifdef OBJ_ELF |
21392 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
5a49b8ac | 21393 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i)); |
c19d1205 ZW |
21394 | #endif |
21395 | ||
21396 | set_constant_flonums (); | |
404ff6b5 | 21397 | |
c19d1205 ZW |
21398 | /* Set the cpu variant based on the command-line options. We prefer |
21399 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
21400 | -mfpu= over any other way of setting the floating point unit. | |
21401 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 21402 | if (legacy_cpu) |
404ff6b5 | 21403 | { |
e74cfd16 | 21404 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
21405 | as_bad (_("use of old and new-style options to set CPU type")); |
21406 | ||
21407 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 21408 | } |
e74cfd16 | 21409 | else if (!mcpu_cpu_opt) |
c19d1205 | 21410 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 21411 | |
e74cfd16 | 21412 | if (legacy_fpu) |
c19d1205 | 21413 | { |
e74cfd16 | 21414 | if (mfpu_opt) |
c19d1205 | 21415 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
21416 | |
21417 | mfpu_opt = legacy_fpu; | |
21418 | } | |
e74cfd16 | 21419 | else if (!mfpu_opt) |
03b1477f | 21420 | { |
45eb4c1b NS |
21421 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
21422 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
21423 | /* Some environments specify a default FPU. If they don't, infer it |
21424 | from the processor. */ | |
e74cfd16 | 21425 | if (mcpu_fpu_opt) |
03b1477f RE |
21426 | mfpu_opt = mcpu_fpu_opt; |
21427 | else | |
21428 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 21429 | #else |
e74cfd16 | 21430 | mfpu_opt = &fpu_default; |
39c2da32 | 21431 | #endif |
03b1477f RE |
21432 | } |
21433 | ||
e74cfd16 | 21434 | if (!mfpu_opt) |
03b1477f | 21435 | { |
493cb6ef | 21436 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 21437 | mfpu_opt = &fpu_default; |
493cb6ef | 21438 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 21439 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 21440 | else |
e74cfd16 | 21441 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
21442 | } |
21443 | ||
ee065d83 | 21444 | #ifdef CPU_DEFAULT |
e74cfd16 | 21445 | if (!mcpu_cpu_opt) |
ee065d83 | 21446 | { |
e74cfd16 PB |
21447 | mcpu_cpu_opt = &cpu_default; |
21448 | selected_cpu = cpu_default; | |
ee065d83 | 21449 | } |
e74cfd16 PB |
21450 | #else |
21451 | if (mcpu_cpu_opt) | |
21452 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 21453 | else |
e74cfd16 | 21454 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 21455 | #endif |
03b1477f | 21456 | |
e74cfd16 | 21457 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 21458 | |
3e9e4fcf JB |
21459 | autoselect_thumb_from_cpu_variant (); |
21460 | ||
e74cfd16 | 21461 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 21462 | |
f17c130b | 21463 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 21464 | { |
7cc69913 NC |
21465 | unsigned int flags = 0; |
21466 | ||
21467 | #if defined OBJ_ELF | |
21468 | flags = meabi_flags; | |
d507cf36 PB |
21469 | |
21470 | switch (meabi_flags) | |
33a392fb | 21471 | { |
d507cf36 | 21472 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 21473 | #endif |
d507cf36 PB |
21474 | /* Set the flags in the private structure. */ |
21475 | if (uses_apcs_26) flags |= F_APCS26; | |
21476 | if (support_interwork) flags |= F_INTERWORK; | |
21477 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 21478 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 21479 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
21480 | flags |= F_SOFT_FLOAT; |
21481 | ||
d507cf36 PB |
21482 | switch (mfloat_abi_opt) |
21483 | { | |
21484 | case ARM_FLOAT_ABI_SOFT: | |
21485 | case ARM_FLOAT_ABI_SOFTFP: | |
21486 | flags |= F_SOFT_FLOAT; | |
21487 | break; | |
33a392fb | 21488 | |
d507cf36 PB |
21489 | case ARM_FLOAT_ABI_HARD: |
21490 | if (flags & F_SOFT_FLOAT) | |
21491 | as_bad (_("hard-float conflicts with specified fpu")); | |
21492 | break; | |
21493 | } | |
03b1477f | 21494 | |
e74cfd16 PB |
21495 | /* Using pure-endian doubles (even if soft-float). */ |
21496 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 21497 | flags |= F_VFP_FLOAT; |
f17c130b | 21498 | |
fde78edd | 21499 | #if defined OBJ_ELF |
e74cfd16 | 21500 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 21501 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
21502 | break; |
21503 | ||
8cb51566 | 21504 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 21505 | case EF_ARM_EABI_VER5: |
c19d1205 | 21506 | /* No additional flags to set. */ |
d507cf36 PB |
21507 | break; |
21508 | ||
21509 | default: | |
21510 | abort (); | |
21511 | } | |
7cc69913 | 21512 | #endif |
b99bd4ef NC |
21513 | bfd_set_private_flags (stdoutput, flags); |
21514 | ||
21515 | /* We have run out flags in the COFF header to encode the | |
21516 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 21517 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
21518 | if (atpcs) |
21519 | { | |
21520 | asection * sec; | |
21521 | ||
21522 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
21523 | ||
21524 | if (sec != NULL) | |
21525 | { | |
21526 | bfd_set_section_flags | |
21527 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
21528 | bfd_set_section_size (stdoutput, sec, 0); | |
21529 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
21530 | } | |
21531 | } | |
7cc69913 | 21532 | } |
f17c130b | 21533 | #endif |
b99bd4ef NC |
21534 | |
21535 | /* Record the CPU type as well. */ | |
2d447fca JM |
21536 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
21537 | mach = bfd_mach_arm_iWMMXt2; | |
21538 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 21539 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 21540 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 21541 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 21542 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 21543 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 21544 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 21545 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 21546 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 21547 | { |
e74cfd16 | 21548 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21549 | mach = bfd_mach_arm_5T; |
21550 | else | |
21551 | mach = bfd_mach_arm_5; | |
21552 | } | |
e74cfd16 | 21553 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 21554 | { |
e74cfd16 | 21555 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21556 | mach = bfd_mach_arm_4T; |
21557 | else | |
21558 | mach = bfd_mach_arm_4; | |
21559 | } | |
e74cfd16 | 21560 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 21561 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
21562 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
21563 | mach = bfd_mach_arm_3; | |
21564 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
21565 | mach = bfd_mach_arm_2a; | |
21566 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
21567 | mach = bfd_mach_arm_2; | |
21568 | else | |
21569 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
21570 | |
21571 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
21572 | } | |
21573 | ||
c19d1205 | 21574 | /* Command line processing. */ |
b99bd4ef | 21575 | |
c19d1205 ZW |
21576 | /* md_parse_option |
21577 | Invocation line includes a switch not recognized by the base assembler. | |
21578 | See if it's a processor-specific option. | |
b99bd4ef | 21579 | |
c19d1205 ZW |
21580 | This routine is somewhat complicated by the need for backwards |
21581 | compatibility (since older releases of gcc can't be changed). | |
21582 | The new options try to make the interface as compatible as | |
21583 | possible with GCC. | |
b99bd4ef | 21584 | |
c19d1205 | 21585 | New options (supported) are: |
b99bd4ef | 21586 | |
c19d1205 ZW |
21587 | -mcpu=<cpu name> Assemble for selected processor |
21588 | -march=<architecture name> Assemble for selected architecture | |
21589 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
21590 | -EB/-mbig-endian Big-endian | |
21591 | -EL/-mlittle-endian Little-endian | |
21592 | -k Generate PIC code | |
21593 | -mthumb Start in Thumb mode | |
21594 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 21595 | |
278df34e | 21596 | -m[no-]warn-deprecated Warn about deprecated features |
267bf995 | 21597 | |
c19d1205 | 21598 | For now we will also provide support for: |
b99bd4ef | 21599 | |
c19d1205 ZW |
21600 | -mapcs-32 32-bit Program counter |
21601 | -mapcs-26 26-bit Program counter | |
21602 | -macps-float Floats passed in FP registers | |
21603 | -mapcs-reentrant Reentrant code | |
21604 | -matpcs | |
21605 | (sometime these will probably be replaced with -mapcs=<list of options> | |
21606 | and -matpcs=<list of options>) | |
b99bd4ef | 21607 | |
c19d1205 ZW |
21608 | The remaining options are only supported for back-wards compatibility. |
21609 | Cpu variants, the arm part is optional: | |
21610 | -m[arm]1 Currently not supported. | |
21611 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
21612 | -m[arm]3 Arm 3 processor | |
21613 | -m[arm]6[xx], Arm 6 processors | |
21614 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
21615 | -m[arm]8[10] Arm 8 processors | |
21616 | -m[arm]9[20][tdmi] Arm 9 processors | |
21617 | -mstrongarm[110[0]] StrongARM processors | |
21618 | -mxscale XScale processors | |
21619 | -m[arm]v[2345[t[e]]] Arm architectures | |
21620 | -mall All (except the ARM1) | |
21621 | FP variants: | |
21622 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
21623 | -mfpe-old (No float load/store multiples) | |
21624 | -mvfpxd VFP Single precision | |
21625 | -mvfp All VFP | |
21626 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 21627 | |
c19d1205 ZW |
21628 | The following CPU names are recognized: |
21629 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
21630 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
21631 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
21632 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
21633 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
21634 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
21635 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 21636 | |
c19d1205 | 21637 | */ |
b99bd4ef | 21638 | |
c19d1205 | 21639 | const char * md_shortopts = "m:k"; |
b99bd4ef | 21640 | |
c19d1205 ZW |
21641 | #ifdef ARM_BI_ENDIAN |
21642 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
21643 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 21644 | #else |
c19d1205 ZW |
21645 | #if TARGET_BYTES_BIG_ENDIAN |
21646 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 21647 | #else |
c19d1205 ZW |
21648 | #define OPTION_EL (OPTION_MD_BASE + 1) |
21649 | #endif | |
b99bd4ef | 21650 | #endif |
845b51d6 | 21651 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 21652 | |
c19d1205 | 21653 | struct option md_longopts[] = |
b99bd4ef | 21654 | { |
c19d1205 ZW |
21655 | #ifdef OPTION_EB |
21656 | {"EB", no_argument, NULL, OPTION_EB}, | |
21657 | #endif | |
21658 | #ifdef OPTION_EL | |
21659 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 21660 | #endif |
845b51d6 | 21661 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
21662 | {NULL, no_argument, NULL, 0} |
21663 | }; | |
b99bd4ef | 21664 | |
c19d1205 | 21665 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 21666 | |
c19d1205 | 21667 | struct arm_option_table |
b99bd4ef | 21668 | { |
c19d1205 ZW |
21669 | char *option; /* Option name to match. */ |
21670 | char *help; /* Help information. */ | |
21671 | int *var; /* Variable to change. */ | |
21672 | int value; /* What to change it to. */ | |
21673 | char *deprecated; /* If non-null, print this message. */ | |
21674 | }; | |
b99bd4ef | 21675 | |
c19d1205 ZW |
21676 | struct arm_option_table arm_opts[] = |
21677 | { | |
21678 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
21679 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
21680 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
21681 | &support_interwork, 1, NULL}, | |
21682 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
21683 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
21684 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
21685 | 1, NULL}, | |
21686 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
21687 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
21688 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
21689 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
21690 | NULL}, | |
b99bd4ef | 21691 | |
c19d1205 ZW |
21692 | /* These are recognized by the assembler, but have no affect on code. */ |
21693 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
21694 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
21695 | |
21696 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
21697 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
21698 | &warn_on_deprecated, 0, NULL}, | |
e74cfd16 PB |
21699 | {NULL, NULL, NULL, 0, NULL} |
21700 | }; | |
21701 | ||
21702 | struct arm_legacy_option_table | |
21703 | { | |
21704 | char *option; /* Option name to match. */ | |
21705 | const arm_feature_set **var; /* Variable to change. */ | |
21706 | const arm_feature_set value; /* What to change it to. */ | |
21707 | char *deprecated; /* If non-null, print this message. */ | |
21708 | }; | |
b99bd4ef | 21709 | |
e74cfd16 PB |
21710 | const struct arm_legacy_option_table arm_legacy_opts[] = |
21711 | { | |
c19d1205 ZW |
21712 | /* DON'T add any new processors to this list -- we want the whole list |
21713 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
21714 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
21715 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
21716 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21717 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21718 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21719 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21720 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21721 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21722 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21723 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21724 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21725 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21726 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21727 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21728 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21729 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21730 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21731 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21732 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21733 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21734 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21735 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21736 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21737 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21738 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21739 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21740 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21741 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21742 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21743 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21744 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21745 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21746 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21747 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21748 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21749 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21750 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21751 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21752 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21753 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21754 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21755 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21756 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21757 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21758 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21759 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21760 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21761 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21762 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21763 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21764 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21765 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21766 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21767 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21768 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21769 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21770 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21771 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21772 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21773 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21774 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21775 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21776 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21777 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21778 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21779 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21780 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21781 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21782 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
21783 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 21784 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 21785 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21786 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 21787 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21788 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
21789 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
21790 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
21791 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 21792 | |
c19d1205 | 21793 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21794 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
21795 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
21796 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21797 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21798 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21799 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21800 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21801 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21802 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21803 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21804 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21805 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21806 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21807 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21808 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21809 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21810 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
21811 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 21812 | |
c19d1205 | 21813 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21814 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
21815 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
21816 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
21817 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 21818 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 21819 | |
e74cfd16 | 21820 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 21821 | }; |
7ed4c4c5 | 21822 | |
c19d1205 | 21823 | struct arm_cpu_option_table |
7ed4c4c5 | 21824 | { |
c19d1205 | 21825 | char *name; |
e74cfd16 | 21826 | const arm_feature_set value; |
c19d1205 ZW |
21827 | /* For some CPUs we assume an FPU unless the user explicitly sets |
21828 | -mfpu=... */ | |
e74cfd16 | 21829 | const arm_feature_set default_fpu; |
ee065d83 PB |
21830 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
21831 | case. */ | |
21832 | const char *canonical_name; | |
c19d1205 | 21833 | }; |
7ed4c4c5 | 21834 | |
c19d1205 ZW |
21835 | /* This list should, at a minimum, contain all the cpu names |
21836 | recognized by GCC. */ | |
e74cfd16 | 21837 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 21838 | { |
ee065d83 PB |
21839 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
21840 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
21841 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
21842 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21843 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21844 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21845 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21846 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21847 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21848 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21849 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21850 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21851 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21852 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21853 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21854 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21855 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21856 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21857 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21858 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21859 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21860 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21861 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21862 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21863 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21864 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21865 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21866 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21867 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21868 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21869 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21870 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21871 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21872 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21873 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21874 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21875 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21876 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21877 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21878 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
21879 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21880 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21881 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21882 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
7fac0536 NC |
21883 | {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, |
21884 | {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
21885 | /* For V5 or later processors we default to using VFP; but the user |
21886 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
21887 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
21888 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21889 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21890 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21891 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
21892 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21893 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
21894 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21895 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21896 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
21897 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21898 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21899 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21900 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21901 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21902 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
21903 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21904 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21905 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21906 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
21907 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
7fac0536 NC |
21908 | {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL}, |
21909 | {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
ee065d83 PB |
21910 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, |
21911 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
21912 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
21913 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
21914 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
21915 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
21916 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
21917 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
21918 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
21919 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
b38f9f31 | 21920 | {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL}, |
e07e6e58 | 21921 | {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
5287ad62 | 21922 | | FPU_NEON_EXT_V1), |
15290f0a | 21923 | NULL}, |
e07e6e58 | 21924 | {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
15290f0a | 21925 | | FPU_NEON_EXT_V1), |
5287ad62 | 21926 | NULL}, |
62b3e311 | 21927 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, |
307c948d | 21928 | {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL}, |
62b3e311 | 21929 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, |
7e806470 | 21930 | {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL}, |
5b19eaba | 21931 | {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL}, |
c19d1205 | 21932 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 21933 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21934 | /* ??? iwmmxt is not a processor. */ |
ee065d83 | 21935 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
2d447fca | 21936 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL}, |
ee065d83 | 21937 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21938 | /* Maverick */ |
e07e6e58 | 21939 | {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
e74cfd16 | 21940 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} |
c19d1205 | 21941 | }; |
7ed4c4c5 | 21942 | |
c19d1205 | 21943 | struct arm_arch_option_table |
7ed4c4c5 | 21944 | { |
c19d1205 | 21945 | char *name; |
e74cfd16 PB |
21946 | const arm_feature_set value; |
21947 | const arm_feature_set default_fpu; | |
c19d1205 | 21948 | }; |
7ed4c4c5 | 21949 | |
c19d1205 ZW |
21950 | /* This list should, at a minimum, contain all the architecture names |
21951 | recognized by GCC. */ | |
e74cfd16 | 21952 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
21953 | { |
21954 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
21955 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
21956 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
21957 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21958 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21959 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
21960 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
21961 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
21962 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
21963 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
21964 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
21965 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
21966 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
21967 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
21968 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
21969 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
21970 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
21971 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21972 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21973 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
21974 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
21975 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
21976 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
21977 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
21978 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
21979 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
7e806470 | 21980 | {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP}, |
62b3e311 | 21981 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
c450d570 PB |
21982 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
21983 | Accept the non-dashed form for compatibility with old toolchains. */ | |
62b3e311 PB |
21984 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21985 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21986 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c450d570 PB |
21987 | {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21988 | {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21989 | {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
21990 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
21991 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
2d447fca | 21992 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP}, |
e74cfd16 | 21993 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 21994 | }; |
7ed4c4c5 | 21995 | |
c19d1205 | 21996 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 21997 | struct arm_option_cpu_value_table |
c19d1205 ZW |
21998 | { |
21999 | char *name; | |
e74cfd16 | 22000 | const arm_feature_set value; |
c19d1205 | 22001 | }; |
7ed4c4c5 | 22002 | |
e74cfd16 | 22003 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 22004 | { |
e74cfd16 PB |
22005 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
22006 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
22007 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
2d447fca | 22008 | {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)}, |
e74cfd16 | 22009 | {NULL, ARM_ARCH_NONE} |
c19d1205 | 22010 | }; |
7ed4c4c5 | 22011 | |
c19d1205 ZW |
22012 | /* This list should, at a minimum, contain all the fpu names |
22013 | recognized by GCC. */ | |
e74cfd16 | 22014 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
22015 | { |
22016 | {"softfpa", FPU_NONE}, | |
22017 | {"fpe", FPU_ARCH_FPE}, | |
22018 | {"fpe2", FPU_ARCH_FPE}, | |
22019 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
22020 | {"fpa", FPU_ARCH_FPA}, | |
22021 | {"fpa10", FPU_ARCH_FPA}, | |
22022 | {"fpa11", FPU_ARCH_FPA}, | |
22023 | {"arm7500fe", FPU_ARCH_FPA}, | |
22024 | {"softvfp", FPU_ARCH_VFP}, | |
22025 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
22026 | {"vfp", FPU_ARCH_VFP_V2}, | |
22027 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 22028 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
22029 | {"vfp10", FPU_ARCH_VFP_V2}, |
22030 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
22031 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
22032 | {"vfpv2", FPU_ARCH_VFP_V2}, |
22033 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 22034 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 22035 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
22036 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
22037 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
22038 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
22039 | {"arm1020t", FPU_ARCH_VFP_V1}, |
22040 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
22041 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
22042 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
22043 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 22044 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 22045 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
22046 | {"vfpv4", FPU_ARCH_VFP_V4}, |
22047 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
22048 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, | |
e74cfd16 PB |
22049 | {NULL, ARM_ARCH_NONE} |
22050 | }; | |
22051 | ||
22052 | struct arm_option_value_table | |
22053 | { | |
22054 | char *name; | |
22055 | long value; | |
c19d1205 | 22056 | }; |
7ed4c4c5 | 22057 | |
e74cfd16 | 22058 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
22059 | { |
22060 | {"hard", ARM_FLOAT_ABI_HARD}, | |
22061 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
22062 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 22063 | {NULL, 0} |
c19d1205 | 22064 | }; |
7ed4c4c5 | 22065 | |
c19d1205 | 22066 | #ifdef OBJ_ELF |
3a4a14e9 | 22067 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 22068 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
22069 | { |
22070 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
22071 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 22072 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 22073 | {NULL, 0} |
c19d1205 ZW |
22074 | }; |
22075 | #endif | |
7ed4c4c5 | 22076 | |
c19d1205 ZW |
22077 | struct arm_long_option_table |
22078 | { | |
22079 | char * option; /* Substring to match. */ | |
22080 | char * help; /* Help information. */ | |
22081 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
22082 | char * deprecated; /* If non-null, print this message. */ | |
22083 | }; | |
7ed4c4c5 | 22084 | |
c921be7d | 22085 | static bfd_boolean |
e74cfd16 | 22086 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 22087 | { |
21d799b5 NC |
22088 | arm_feature_set *ext_set = (arm_feature_set *) |
22089 | xmalloc (sizeof (arm_feature_set)); | |
e74cfd16 PB |
22090 | |
22091 | /* Copy the feature set, so that we can modify it. */ | |
22092 | *ext_set = **opt_p; | |
22093 | *opt_p = ext_set; | |
22094 | ||
c19d1205 | 22095 | while (str != NULL && *str != 0) |
7ed4c4c5 | 22096 | { |
e74cfd16 | 22097 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
22098 | char * ext; |
22099 | int optlen; | |
7ed4c4c5 | 22100 | |
c19d1205 ZW |
22101 | if (*str != '+') |
22102 | { | |
22103 | as_bad (_("invalid architectural extension")); | |
c921be7d | 22104 | return FALSE; |
c19d1205 | 22105 | } |
7ed4c4c5 | 22106 | |
c19d1205 ZW |
22107 | str++; |
22108 | ext = strchr (str, '+'); | |
7ed4c4c5 | 22109 | |
c19d1205 ZW |
22110 | if (ext != NULL) |
22111 | optlen = ext - str; | |
22112 | else | |
22113 | optlen = strlen (str); | |
7ed4c4c5 | 22114 | |
c19d1205 ZW |
22115 | if (optlen == 0) |
22116 | { | |
22117 | as_bad (_("missing architectural extension")); | |
c921be7d | 22118 | return FALSE; |
c19d1205 | 22119 | } |
7ed4c4c5 | 22120 | |
c19d1205 ZW |
22121 | for (opt = arm_extensions; opt->name != NULL; opt++) |
22122 | if (strncmp (opt->name, str, optlen) == 0) | |
22123 | { | |
e74cfd16 | 22124 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
22125 | break; |
22126 | } | |
7ed4c4c5 | 22127 | |
c19d1205 ZW |
22128 | if (opt->name == NULL) |
22129 | { | |
5f4273c7 | 22130 | as_bad (_("unknown architectural extension `%s'"), str); |
c921be7d | 22131 | return FALSE; |
c19d1205 | 22132 | } |
7ed4c4c5 | 22133 | |
c19d1205 ZW |
22134 | str = ext; |
22135 | }; | |
7ed4c4c5 | 22136 | |
c921be7d | 22137 | return TRUE; |
c19d1205 | 22138 | } |
7ed4c4c5 | 22139 | |
c921be7d | 22140 | static bfd_boolean |
c19d1205 | 22141 | arm_parse_cpu (char * str) |
7ed4c4c5 | 22142 | { |
e74cfd16 | 22143 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
22144 | char * ext = strchr (str, '+'); |
22145 | int optlen; | |
7ed4c4c5 | 22146 | |
c19d1205 ZW |
22147 | if (ext != NULL) |
22148 | optlen = ext - str; | |
7ed4c4c5 | 22149 | else |
c19d1205 | 22150 | optlen = strlen (str); |
7ed4c4c5 | 22151 | |
c19d1205 | 22152 | if (optlen == 0) |
7ed4c4c5 | 22153 | { |
c19d1205 | 22154 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 22155 | return FALSE; |
7ed4c4c5 NC |
22156 | } |
22157 | ||
c19d1205 ZW |
22158 | for (opt = arm_cpus; opt->name != NULL; opt++) |
22159 | if (strncmp (opt->name, str, optlen) == 0) | |
22160 | { | |
e74cfd16 PB |
22161 | mcpu_cpu_opt = &opt->value; |
22162 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 22163 | if (opt->canonical_name) |
5f4273c7 | 22164 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22165 | else |
22166 | { | |
22167 | int i; | |
c921be7d | 22168 | |
ee065d83 PB |
22169 | for (i = 0; i < optlen; i++) |
22170 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22171 | selected_cpu_name[i] = 0; | |
22172 | } | |
7ed4c4c5 | 22173 | |
c19d1205 ZW |
22174 | if (ext != NULL) |
22175 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 22176 | |
c921be7d | 22177 | return TRUE; |
c19d1205 | 22178 | } |
7ed4c4c5 | 22179 | |
c19d1205 | 22180 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 22181 | return FALSE; |
7ed4c4c5 NC |
22182 | } |
22183 | ||
c921be7d | 22184 | static bfd_boolean |
c19d1205 | 22185 | arm_parse_arch (char * str) |
7ed4c4c5 | 22186 | { |
e74cfd16 | 22187 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
22188 | char *ext = strchr (str, '+'); |
22189 | int optlen; | |
7ed4c4c5 | 22190 | |
c19d1205 ZW |
22191 | if (ext != NULL) |
22192 | optlen = ext - str; | |
7ed4c4c5 | 22193 | else |
c19d1205 | 22194 | optlen = strlen (str); |
7ed4c4c5 | 22195 | |
c19d1205 | 22196 | if (optlen == 0) |
7ed4c4c5 | 22197 | { |
c19d1205 | 22198 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 22199 | return FALSE; |
7ed4c4c5 NC |
22200 | } |
22201 | ||
c19d1205 ZW |
22202 | for (opt = arm_archs; opt->name != NULL; opt++) |
22203 | if (streq (opt->name, str)) | |
22204 | { | |
e74cfd16 PB |
22205 | march_cpu_opt = &opt->value; |
22206 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 22207 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 22208 | |
c19d1205 ZW |
22209 | if (ext != NULL) |
22210 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 22211 | |
c921be7d | 22212 | return TRUE; |
c19d1205 ZW |
22213 | } |
22214 | ||
22215 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 22216 | return FALSE; |
7ed4c4c5 | 22217 | } |
eb043451 | 22218 | |
c921be7d | 22219 | static bfd_boolean |
c19d1205 ZW |
22220 | arm_parse_fpu (char * str) |
22221 | { | |
e74cfd16 | 22222 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 22223 | |
c19d1205 ZW |
22224 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22225 | if (streq (opt->name, str)) | |
22226 | { | |
e74cfd16 | 22227 | mfpu_opt = &opt->value; |
c921be7d | 22228 | return TRUE; |
c19d1205 | 22229 | } |
b99bd4ef | 22230 | |
c19d1205 | 22231 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 22232 | return FALSE; |
c19d1205 ZW |
22233 | } |
22234 | ||
c921be7d | 22235 | static bfd_boolean |
c19d1205 | 22236 | arm_parse_float_abi (char * str) |
b99bd4ef | 22237 | { |
e74cfd16 | 22238 | const struct arm_option_value_table * opt; |
b99bd4ef | 22239 | |
c19d1205 ZW |
22240 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
22241 | if (streq (opt->name, str)) | |
22242 | { | |
22243 | mfloat_abi_opt = opt->value; | |
c921be7d | 22244 | return TRUE; |
c19d1205 | 22245 | } |
cc8a6dd0 | 22246 | |
c19d1205 | 22247 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 22248 | return FALSE; |
c19d1205 | 22249 | } |
b99bd4ef | 22250 | |
c19d1205 | 22251 | #ifdef OBJ_ELF |
c921be7d | 22252 | static bfd_boolean |
c19d1205 ZW |
22253 | arm_parse_eabi (char * str) |
22254 | { | |
e74cfd16 | 22255 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 22256 | |
c19d1205 ZW |
22257 | for (opt = arm_eabis; opt->name != NULL; opt++) |
22258 | if (streq (opt->name, str)) | |
22259 | { | |
22260 | meabi_flags = opt->value; | |
c921be7d | 22261 | return TRUE; |
c19d1205 ZW |
22262 | } |
22263 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 22264 | return FALSE; |
c19d1205 ZW |
22265 | } |
22266 | #endif | |
cc8a6dd0 | 22267 | |
c921be7d | 22268 | static bfd_boolean |
e07e6e58 NC |
22269 | arm_parse_it_mode (char * str) |
22270 | { | |
c921be7d | 22271 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
22272 | |
22273 | if (streq ("arm", str)) | |
22274 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
22275 | else if (streq ("thumb", str)) | |
22276 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
22277 | else if (streq ("always", str)) | |
22278 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
22279 | else if (streq ("never", str)) | |
22280 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
22281 | else | |
22282 | { | |
22283 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
22284 | "arm, thumb, always, or never."), str); | |
c921be7d | 22285 | ret = FALSE; |
e07e6e58 NC |
22286 | } |
22287 | ||
22288 | return ret; | |
22289 | } | |
22290 | ||
c19d1205 ZW |
22291 | struct arm_long_option_table arm_long_opts[] = |
22292 | { | |
22293 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
22294 | arm_parse_cpu, NULL}, | |
22295 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
22296 | arm_parse_arch, NULL}, | |
22297 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
22298 | arm_parse_fpu, NULL}, | |
22299 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
22300 | arm_parse_float_abi, NULL}, | |
22301 | #ifdef OBJ_ELF | |
7fac0536 | 22302 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
22303 | arm_parse_eabi, NULL}, |
22304 | #endif | |
e07e6e58 NC |
22305 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
22306 | arm_parse_it_mode, NULL}, | |
c19d1205 ZW |
22307 | {NULL, NULL, 0, NULL} |
22308 | }; | |
cc8a6dd0 | 22309 | |
c19d1205 ZW |
22310 | int |
22311 | md_parse_option (int c, char * arg) | |
22312 | { | |
22313 | struct arm_option_table *opt; | |
e74cfd16 | 22314 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 22315 | struct arm_long_option_table *lopt; |
b99bd4ef | 22316 | |
c19d1205 | 22317 | switch (c) |
b99bd4ef | 22318 | { |
c19d1205 ZW |
22319 | #ifdef OPTION_EB |
22320 | case OPTION_EB: | |
22321 | target_big_endian = 1; | |
22322 | break; | |
22323 | #endif | |
cc8a6dd0 | 22324 | |
c19d1205 ZW |
22325 | #ifdef OPTION_EL |
22326 | case OPTION_EL: | |
22327 | target_big_endian = 0; | |
22328 | break; | |
22329 | #endif | |
b99bd4ef | 22330 | |
845b51d6 PB |
22331 | case OPTION_FIX_V4BX: |
22332 | fix_v4bx = TRUE; | |
22333 | break; | |
22334 | ||
c19d1205 ZW |
22335 | case 'a': |
22336 | /* Listing option. Just ignore these, we don't support additional | |
22337 | ones. */ | |
22338 | return 0; | |
b99bd4ef | 22339 | |
c19d1205 ZW |
22340 | default: |
22341 | for (opt = arm_opts; opt->option != NULL; opt++) | |
22342 | { | |
22343 | if (c == opt->option[0] | |
22344 | && ((arg == NULL && opt->option[1] == 0) | |
22345 | || streq (arg, opt->option + 1))) | |
22346 | { | |
c19d1205 | 22347 | /* If the option is deprecated, tell the user. */ |
278df34e | 22348 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
22349 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22350 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 22351 | |
c19d1205 ZW |
22352 | if (opt->var != NULL) |
22353 | *opt->var = opt->value; | |
cc8a6dd0 | 22354 | |
c19d1205 ZW |
22355 | return 1; |
22356 | } | |
22357 | } | |
b99bd4ef | 22358 | |
e74cfd16 PB |
22359 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
22360 | { | |
22361 | if (c == fopt->option[0] | |
22362 | && ((arg == NULL && fopt->option[1] == 0) | |
22363 | || streq (arg, fopt->option + 1))) | |
22364 | { | |
e74cfd16 | 22365 | /* If the option is deprecated, tell the user. */ |
278df34e | 22366 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
22367 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22368 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
22369 | |
22370 | if (fopt->var != NULL) | |
22371 | *fopt->var = &fopt->value; | |
22372 | ||
22373 | return 1; | |
22374 | } | |
22375 | } | |
22376 | ||
c19d1205 ZW |
22377 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22378 | { | |
22379 | /* These options are expected to have an argument. */ | |
22380 | if (c == lopt->option[0] | |
22381 | && arg != NULL | |
22382 | && strncmp (arg, lopt->option + 1, | |
22383 | strlen (lopt->option + 1)) == 0) | |
22384 | { | |
c19d1205 | 22385 | /* If the option is deprecated, tell the user. */ |
278df34e | 22386 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
22387 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
22388 | _(lopt->deprecated)); | |
b99bd4ef | 22389 | |
c19d1205 ZW |
22390 | /* Call the sup-option parser. */ |
22391 | return lopt->func (arg + strlen (lopt->option) - 1); | |
22392 | } | |
22393 | } | |
a737bd4d | 22394 | |
c19d1205 ZW |
22395 | return 0; |
22396 | } | |
a394c00f | 22397 | |
c19d1205 ZW |
22398 | return 1; |
22399 | } | |
a394c00f | 22400 | |
c19d1205 ZW |
22401 | void |
22402 | md_show_usage (FILE * fp) | |
a394c00f | 22403 | { |
c19d1205 ZW |
22404 | struct arm_option_table *opt; |
22405 | struct arm_long_option_table *lopt; | |
a394c00f | 22406 | |
c19d1205 | 22407 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 22408 | |
c19d1205 ZW |
22409 | for (opt = arm_opts; opt->option != NULL; opt++) |
22410 | if (opt->help != NULL) | |
22411 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 22412 | |
c19d1205 ZW |
22413 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22414 | if (lopt->help != NULL) | |
22415 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 22416 | |
c19d1205 ZW |
22417 | #ifdef OPTION_EB |
22418 | fprintf (fp, _("\ | |
22419 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
22420 | #endif |
22421 | ||
c19d1205 ZW |
22422 | #ifdef OPTION_EL |
22423 | fprintf (fp, _("\ | |
22424 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 22425 | #endif |
845b51d6 PB |
22426 | |
22427 | fprintf (fp, _("\ | |
22428 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 22429 | } |
ee065d83 PB |
22430 | |
22431 | ||
22432 | #ifdef OBJ_ELF | |
62b3e311 PB |
22433 | typedef struct |
22434 | { | |
22435 | int val; | |
22436 | arm_feature_set flags; | |
22437 | } cpu_arch_ver_table; | |
22438 | ||
22439 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
22440 | least features first. */ | |
22441 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
22442 | { | |
22443 | {1, ARM_ARCH_V4}, | |
22444 | {2, ARM_ARCH_V4T}, | |
22445 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 22446 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
22447 | {4, ARM_ARCH_V5TE}, |
22448 | {5, ARM_ARCH_V5TEJ}, | |
22449 | {6, ARM_ARCH_V6}, | |
22450 | {7, ARM_ARCH_V6Z}, | |
7e806470 | 22451 | {9, ARM_ARCH_V6K}, |
91e22acd | 22452 | {11, ARM_ARCH_V6M}, |
7e806470 | 22453 | {8, ARM_ARCH_V6T2}, |
62b3e311 PB |
22454 | {10, ARM_ARCH_V7A}, |
22455 | {10, ARM_ARCH_V7R}, | |
22456 | {10, ARM_ARCH_V7M}, | |
22457 | {0, ARM_ARCH_NONE} | |
22458 | }; | |
22459 | ||
ee3c0378 AS |
22460 | /* Set an attribute if it has not already been set by the user. */ |
22461 | static void | |
22462 | aeabi_set_attribute_int (int tag, int value) | |
22463 | { | |
22464 | if (tag < 1 | |
22465 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22466 | || !attributes_set_explicitly[tag]) | |
22467 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
22468 | } | |
22469 | ||
22470 | static void | |
22471 | aeabi_set_attribute_string (int tag, const char *value) | |
22472 | { | |
22473 | if (tag < 1 | |
22474 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22475 | || !attributes_set_explicitly[tag]) | |
22476 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
22477 | } | |
22478 | ||
ee065d83 PB |
22479 | /* Set the public EABI object attributes. */ |
22480 | static void | |
22481 | aeabi_set_public_attributes (void) | |
22482 | { | |
22483 | int arch; | |
e74cfd16 | 22484 | arm_feature_set flags; |
62b3e311 PB |
22485 | arm_feature_set tmp; |
22486 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
22487 | |
22488 | /* Choose the architecture based on the capabilities of the requested cpu | |
22489 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
22490 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
22491 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
22492 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
7a1d4c38 PB |
22493 | /*Allow the user to override the reported architecture. */ |
22494 | if (object_arch) | |
22495 | { | |
22496 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
22497 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
22498 | } | |
22499 | ||
62b3e311 PB |
22500 | tmp = flags; |
22501 | arch = 0; | |
22502 | for (p = cpu_arch_ver; p->val; p++) | |
22503 | { | |
22504 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
22505 | { | |
22506 | arch = p->val; | |
22507 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
22508 | } | |
22509 | } | |
ee065d83 PB |
22510 | |
22511 | /* Tag_CPU_name. */ | |
22512 | if (selected_cpu_name[0]) | |
22513 | { | |
22514 | char *p; | |
22515 | ||
22516 | p = selected_cpu_name; | |
5f4273c7 | 22517 | if (strncmp (p, "armv", 4) == 0) |
ee065d83 PB |
22518 | { |
22519 | int i; | |
5f4273c7 | 22520 | |
ee065d83 PB |
22521 | p += 4; |
22522 | for (i = 0; p[i]; i++) | |
22523 | p[i] = TOUPPER (p[i]); | |
22524 | } | |
ee3c0378 | 22525 | aeabi_set_attribute_string (Tag_CPU_name, p); |
ee065d83 | 22526 | } |
62f3b8c8 | 22527 | |
ee065d83 | 22528 | /* Tag_CPU_arch. */ |
ee3c0378 | 22529 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 22530 | |
62b3e311 PB |
22531 | /* Tag_CPU_arch_profile. */ |
22532 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
ee3c0378 | 22533 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A'); |
62b3e311 | 22534 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
ee3c0378 | 22535 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R'); |
7e806470 | 22536 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
ee3c0378 | 22537 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M'); |
62f3b8c8 | 22538 | |
ee065d83 | 22539 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
22540 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
22541 | || arch == 0) | |
22542 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
62f3b8c8 | 22543 | |
ee065d83 | 22544 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
22545 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
22546 | || arch == 0) | |
22547 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, | |
22548 | ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1); | |
62f3b8c8 | 22549 | |
ee065d83 | 22550 | /* Tag_VFP_arch. */ |
62f3b8c8 PB |
22551 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
22552 | aeabi_set_attribute_int (Tag_VFP_arch, | |
22553 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
22554 | ? 5 : 6); | |
22555 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
ee3c0378 AS |
22556 | aeabi_set_attribute_int (Tag_VFP_arch, 3); |
22557 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3)) | |
22558 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
22559 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) | |
22560 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
22561 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
22562 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) | |
22563 | aeabi_set_attribute_int (Tag_VFP_arch, 1); | |
62f3b8c8 | 22564 | |
ee065d83 | 22565 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
22566 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
22567 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
22568 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
22569 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 22570 | |
ee3c0378 | 22571 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
8e79c3df | 22572 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) |
62f3b8c8 PB |
22573 | aeabi_set_attribute_int |
22574 | (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma) | |
22575 | ? 2 : 1)); | |
22576 | ||
ee3c0378 | 22577 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
62f3b8c8 | 22578 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16)) |
ee3c0378 | 22579 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
ee065d83 PB |
22580 | } |
22581 | ||
104d59d1 | 22582 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
22583 | void |
22584 | arm_md_end (void) | |
22585 | { | |
ee065d83 PB |
22586 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
22587 | return; | |
22588 | ||
22589 | aeabi_set_public_attributes (); | |
ee065d83 | 22590 | } |
8463be01 | 22591 | #endif /* OBJ_ELF */ |
ee065d83 PB |
22592 | |
22593 | ||
22594 | /* Parse a .cpu directive. */ | |
22595 | ||
22596 | static void | |
22597 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
22598 | { | |
e74cfd16 | 22599 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
22600 | char *name; |
22601 | char saved_char; | |
22602 | ||
22603 | name = input_line_pointer; | |
5f4273c7 | 22604 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22605 | input_line_pointer++; |
22606 | saved_char = *input_line_pointer; | |
22607 | *input_line_pointer = 0; | |
22608 | ||
22609 | /* Skip the first "all" entry. */ | |
22610 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
22611 | if (streq (opt->name, name)) | |
22612 | { | |
e74cfd16 PB |
22613 | mcpu_cpu_opt = &opt->value; |
22614 | selected_cpu = opt->value; | |
ee065d83 | 22615 | if (opt->canonical_name) |
5f4273c7 | 22616 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22617 | else |
22618 | { | |
22619 | int i; | |
22620 | for (i = 0; opt->name[i]; i++) | |
22621 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22622 | selected_cpu_name[i] = 0; | |
22623 | } | |
e74cfd16 | 22624 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22625 | *input_line_pointer = saved_char; |
22626 | demand_empty_rest_of_line (); | |
22627 | return; | |
22628 | } | |
22629 | as_bad (_("unknown cpu `%s'"), name); | |
22630 | *input_line_pointer = saved_char; | |
22631 | ignore_rest_of_line (); | |
22632 | } | |
22633 | ||
22634 | ||
22635 | /* Parse a .arch directive. */ | |
22636 | ||
22637 | static void | |
22638 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
22639 | { | |
e74cfd16 | 22640 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
22641 | char saved_char; |
22642 | char *name; | |
22643 | ||
22644 | name = input_line_pointer; | |
5f4273c7 | 22645 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22646 | input_line_pointer++; |
22647 | saved_char = *input_line_pointer; | |
22648 | *input_line_pointer = 0; | |
22649 | ||
22650 | /* Skip the first "all" entry. */ | |
22651 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22652 | if (streq (opt->name, name)) | |
22653 | { | |
e74cfd16 PB |
22654 | mcpu_cpu_opt = &opt->value; |
22655 | selected_cpu = opt->value; | |
5f4273c7 | 22656 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 22657 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22658 | *input_line_pointer = saved_char; |
22659 | demand_empty_rest_of_line (); | |
22660 | return; | |
22661 | } | |
22662 | ||
22663 | as_bad (_("unknown architecture `%s'\n"), name); | |
22664 | *input_line_pointer = saved_char; | |
22665 | ignore_rest_of_line (); | |
22666 | } | |
22667 | ||
22668 | ||
7a1d4c38 PB |
22669 | /* Parse a .object_arch directive. */ |
22670 | ||
22671 | static void | |
22672 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
22673 | { | |
22674 | const struct arm_arch_option_table *opt; | |
22675 | char saved_char; | |
22676 | char *name; | |
22677 | ||
22678 | name = input_line_pointer; | |
5f4273c7 | 22679 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
22680 | input_line_pointer++; |
22681 | saved_char = *input_line_pointer; | |
22682 | *input_line_pointer = 0; | |
22683 | ||
22684 | /* Skip the first "all" entry. */ | |
22685 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22686 | if (streq (opt->name, name)) | |
22687 | { | |
22688 | object_arch = &opt->value; | |
22689 | *input_line_pointer = saved_char; | |
22690 | demand_empty_rest_of_line (); | |
22691 | return; | |
22692 | } | |
22693 | ||
22694 | as_bad (_("unknown architecture `%s'\n"), name); | |
22695 | *input_line_pointer = saved_char; | |
22696 | ignore_rest_of_line (); | |
22697 | } | |
22698 | ||
ee065d83 PB |
22699 | /* Parse a .fpu directive. */ |
22700 | ||
22701 | static void | |
22702 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
22703 | { | |
e74cfd16 | 22704 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
22705 | char saved_char; |
22706 | char *name; | |
22707 | ||
22708 | name = input_line_pointer; | |
5f4273c7 | 22709 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22710 | input_line_pointer++; |
22711 | saved_char = *input_line_pointer; | |
22712 | *input_line_pointer = 0; | |
5f4273c7 | 22713 | |
ee065d83 PB |
22714 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22715 | if (streq (opt->name, name)) | |
22716 | { | |
e74cfd16 PB |
22717 | mfpu_opt = &opt->value; |
22718 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
22719 | *input_line_pointer = saved_char; |
22720 | demand_empty_rest_of_line (); | |
22721 | return; | |
22722 | } | |
22723 | ||
22724 | as_bad (_("unknown floating point format `%s'\n"), name); | |
22725 | *input_line_pointer = saved_char; | |
22726 | ignore_rest_of_line (); | |
22727 | } | |
ee065d83 | 22728 | |
794ba86a | 22729 | /* Copy symbol information. */ |
f31fef98 | 22730 | |
794ba86a DJ |
22731 | void |
22732 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
22733 | { | |
22734 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
22735 | } | |
e04befd0 | 22736 | |
f31fef98 | 22737 | #ifdef OBJ_ELF |
e04befd0 AS |
22738 | /* Given a symbolic attribute NAME, return the proper integer value. |
22739 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 22740 | |
e04befd0 AS |
22741 | int |
22742 | arm_convert_symbolic_attribute (const char *name) | |
22743 | { | |
f31fef98 NC |
22744 | static const struct |
22745 | { | |
22746 | const char * name; | |
22747 | const int tag; | |
22748 | } | |
22749 | attribute_table[] = | |
22750 | { | |
22751 | /* When you modify this table you should | |
22752 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 22753 | #define T(tag) {#tag, tag} |
f31fef98 NC |
22754 | T (Tag_CPU_raw_name), |
22755 | T (Tag_CPU_name), | |
22756 | T (Tag_CPU_arch), | |
22757 | T (Tag_CPU_arch_profile), | |
22758 | T (Tag_ARM_ISA_use), | |
22759 | T (Tag_THUMB_ISA_use), | |
22760 | T (Tag_VFP_arch), | |
22761 | T (Tag_WMMX_arch), | |
22762 | T (Tag_Advanced_SIMD_arch), | |
22763 | T (Tag_PCS_config), | |
22764 | T (Tag_ABI_PCS_R9_use), | |
22765 | T (Tag_ABI_PCS_RW_data), | |
22766 | T (Tag_ABI_PCS_RO_data), | |
22767 | T (Tag_ABI_PCS_GOT_use), | |
22768 | T (Tag_ABI_PCS_wchar_t), | |
22769 | T (Tag_ABI_FP_rounding), | |
22770 | T (Tag_ABI_FP_denormal), | |
22771 | T (Tag_ABI_FP_exceptions), | |
22772 | T (Tag_ABI_FP_user_exceptions), | |
22773 | T (Tag_ABI_FP_number_model), | |
22774 | T (Tag_ABI_align8_needed), | |
22775 | T (Tag_ABI_align8_preserved), | |
22776 | T (Tag_ABI_enum_size), | |
22777 | T (Tag_ABI_HardFP_use), | |
22778 | T (Tag_ABI_VFP_args), | |
22779 | T (Tag_ABI_WMMX_args), | |
22780 | T (Tag_ABI_optimization_goals), | |
22781 | T (Tag_ABI_FP_optimization_goals), | |
22782 | T (Tag_compatibility), | |
22783 | T (Tag_CPU_unaligned_access), | |
22784 | T (Tag_VFP_HP_extension), | |
22785 | T (Tag_ABI_FP_16bit_format), | |
22786 | T (Tag_nodefaults), | |
22787 | T (Tag_also_compatible_with), | |
22788 | T (Tag_conformance), | |
22789 | T (Tag_T2EE_use), | |
22790 | T (Tag_Virtualization_use), | |
22791 | T (Tag_MPextension_use) | |
e04befd0 | 22792 | #undef T |
f31fef98 | 22793 | }; |
e04befd0 AS |
22794 | unsigned int i; |
22795 | ||
22796 | if (name == NULL) | |
22797 | return -1; | |
22798 | ||
f31fef98 | 22799 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 22800 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
22801 | return attribute_table[i].tag; |
22802 | ||
22803 | return -1; | |
22804 | } | |
267bf995 RR |
22805 | |
22806 | ||
22807 | /* Apply sym value for relocations only in the case that | |
22808 | they are for local symbols and you have the respective | |
22809 | architectural feature for blx and simple switches. */ | |
22810 | int | |
22811 | arm_apply_sym_value (struct fix * fixP) | |
22812 | { | |
22813 | if (fixP->fx_addsy | |
22814 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
22815 | && !S_IS_EXTERNAL (fixP->fx_addsy)) | |
22816 | { | |
22817 | switch (fixP->fx_r_type) | |
22818 | { | |
22819 | case BFD_RELOC_ARM_PCREL_BLX: | |
22820 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
22821 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
22822 | return 1; | |
22823 | break; | |
22824 | ||
22825 | case BFD_RELOC_ARM_PCREL_CALL: | |
22826 | case BFD_RELOC_THUMB_PCREL_BLX: | |
22827 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
22828 | return 1; | |
22829 | break; | |
22830 | ||
22831 | default: | |
22832 | break; | |
22833 | } | |
22834 | ||
22835 | } | |
22836 | return 0; | |
22837 | } | |
f31fef98 | 22838 | #endif /* OBJ_ELF */ |