Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
da4339ed | 2 | Copyright 1994-2013 Free Software Foundation, Inc. |
b99bd4ef NC |
3 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) |
4 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 5 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
6 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
7 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
8 | |
9 | This file is part of GAS, the GNU Assembler. | |
10 | ||
11 | GAS is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 13 | the Free Software Foundation; either version 3, or (at your option) |
b99bd4ef NC |
14 | any later version. |
15 | ||
16 | GAS is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c19d1205 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
19 | GNU General Public License for more details. |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with GAS; see the file COPYING. If not, write to the Free | |
699d2810 NC |
23 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
24 | 02110-1301, USA. */ | |
b99bd4ef | 25 | |
42a68e18 | 26 | #include "as.h" |
5287ad62 | 27 | #include <limits.h> |
037e8744 | 28 | #include <stdarg.h> |
c19d1205 | 29 | #define NO_RELOC 0 |
3882b010 | 30 | #include "safe-ctype.h" |
b99bd4ef NC |
31 | #include "subsegs.h" |
32 | #include "obstack.h" | |
3da1d841 | 33 | #include "libiberty.h" |
f263249b RE |
34 | #include "opcode/arm.h" |
35 | ||
b99bd4ef NC |
36 | #ifdef OBJ_ELF |
37 | #include "elf/arm.h" | |
a394c00f | 38 | #include "dw2gencfi.h" |
b99bd4ef NC |
39 | #endif |
40 | ||
f0927246 NC |
41 | #include "dwarf2dbg.h" |
42 | ||
7ed4c4c5 NC |
43 | #ifdef OBJ_ELF |
44 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
45 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
46 | ||
47 | /* This structure holds the unwinding state. */ | |
48 | ||
49 | static struct | |
50 | { | |
c19d1205 ZW |
51 | symbolS * proc_start; |
52 | symbolS * table_entry; | |
53 | symbolS * personality_routine; | |
54 | int personality_index; | |
7ed4c4c5 | 55 | /* The segment containing the function. */ |
c19d1205 ZW |
56 | segT saved_seg; |
57 | subsegT saved_subseg; | |
7ed4c4c5 NC |
58 | /* Opcodes generated from this function. */ |
59 | unsigned char * opcodes; | |
c19d1205 ZW |
60 | int opcode_count; |
61 | int opcode_alloc; | |
7ed4c4c5 | 62 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 63 | offsetT frame_size; |
7ed4c4c5 NC |
64 | /* We don't add stack adjustment opcodes immediately so that we can merge |
65 | multiple adjustments. We can also omit the final adjustment | |
66 | when using a frame pointer. */ | |
c19d1205 | 67 | offsetT pending_offset; |
7ed4c4c5 | 68 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
69 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
70 | offsetT fp_offset; | |
71 | int fp_reg; | |
7ed4c4c5 | 72 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 73 | unsigned fp_used:1; |
7ed4c4c5 | 74 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 75 | unsigned sp_restored:1; |
7ed4c4c5 NC |
76 | } unwind; |
77 | ||
8b1ad454 NC |
78 | #endif /* OBJ_ELF */ |
79 | ||
4962c51a MS |
80 | /* Results from operand parsing worker functions. */ |
81 | ||
82 | typedef enum | |
83 | { | |
84 | PARSE_OPERAND_SUCCESS, | |
85 | PARSE_OPERAND_FAIL, | |
86 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
87 | } parse_operand_result; | |
88 | ||
33a392fb PB |
89 | enum arm_float_abi |
90 | { | |
91 | ARM_FLOAT_ABI_HARD, | |
92 | ARM_FLOAT_ABI_SOFTFP, | |
93 | ARM_FLOAT_ABI_SOFT | |
94 | }; | |
95 | ||
c19d1205 | 96 | /* Types of processor to assemble for. */ |
b99bd4ef | 97 | #ifndef CPU_DEFAULT |
8a59fff3 | 98 | /* The code that was here used to select a default CPU depending on compiler |
fa94de6b | 99 | pre-defines which were only present when doing native builds, thus |
8a59fff3 MGD |
100 | changing gas' default behaviour depending upon the build host. |
101 | ||
102 | If you have a target that requires a default CPU option then the you | |
103 | should define CPU_DEFAULT here. */ | |
b99bd4ef NC |
104 | #endif |
105 | ||
106 | #ifndef FPU_DEFAULT | |
c820d418 MM |
107 | # ifdef TE_LINUX |
108 | # define FPU_DEFAULT FPU_ARCH_FPA | |
109 | # elif defined (TE_NetBSD) | |
110 | # ifdef OBJ_ELF | |
111 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
112 | # else | |
113 | /* Legacy a.out format. */ | |
114 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
115 | # endif | |
4e7fd91e PB |
116 | # elif defined (TE_VXWORKS) |
117 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
118 | # else |
119 | /* For backwards compatibility, default to FPA. */ | |
120 | # define FPU_DEFAULT FPU_ARCH_FPA | |
121 | # endif | |
122 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 123 | |
c19d1205 | 124 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 125 | |
e74cfd16 PB |
126 | static arm_feature_set cpu_variant; |
127 | static arm_feature_set arm_arch_used; | |
128 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 129 | |
b99bd4ef | 130 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
131 | static int uses_apcs_26 = FALSE; |
132 | static int atpcs = FALSE; | |
b34976b6 AM |
133 | static int support_interwork = FALSE; |
134 | static int uses_apcs_float = FALSE; | |
c19d1205 | 135 | static int pic_code = FALSE; |
845b51d6 | 136 | static int fix_v4bx = FALSE; |
278df34e NS |
137 | /* Warn on using deprecated features. */ |
138 | static int warn_on_deprecated = TRUE; | |
139 | ||
03b1477f RE |
140 | |
141 | /* Variables that we set while parsing command-line options. Once all | |
142 | options have been read we re-process these values to set the real | |
143 | assembly flags. */ | |
e74cfd16 PB |
144 | static const arm_feature_set *legacy_cpu = NULL; |
145 | static const arm_feature_set *legacy_fpu = NULL; | |
146 | ||
147 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
148 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
149 | static const arm_feature_set *march_cpu_opt = NULL; | |
150 | static const arm_feature_set *march_fpu_opt = NULL; | |
151 | static const arm_feature_set *mfpu_opt = NULL; | |
7a1d4c38 | 152 | static const arm_feature_set *object_arch = NULL; |
e74cfd16 PB |
153 | |
154 | /* Constants for known architecture features. */ | |
155 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
156 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
157 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
158 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
159 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
160 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
161 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
162 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
163 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
164 | ||
165 | #ifdef CPU_DEFAULT | |
166 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
167 | #endif | |
168 | ||
169 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
170 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
171 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
172 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
173 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
174 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
175 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
176 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
177 | static const arm_feature_set arm_ext_v4t_5 = | |
178 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
179 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
180 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
181 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
182 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
183 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
184 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
e74cfd16 | 185 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); |
b2a5fbdc | 186 | static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0); |
62b3e311 | 187 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
9e3c6df6 | 188 | static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0); |
7e806470 PB |
189 | static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0); |
190 | static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0); | |
62b3e311 PB |
191 | static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0); |
192 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0); | |
193 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0); | |
194 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0); | |
9e3c6df6 | 195 | static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0); |
bca38921 | 196 | static const arm_feature_set arm_ext_v8 = ARM_FEATURE (ARM_EXT_V8, 0); |
7e806470 | 197 | static const arm_feature_set arm_ext_m = |
b2a5fbdc | 198 | ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0); |
60e5ef9f | 199 | static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0); |
f4c65163 | 200 | static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0); |
b2a5fbdc | 201 | static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0); |
eea54501 | 202 | static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0); |
90ec0d68 | 203 | static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0); |
e74cfd16 PB |
204 | |
205 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
206 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
207 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
208 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
251665fc | 209 | static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY; |
e74cfd16 | 210 | |
2d447fca JM |
211 | static const arm_feature_set arm_cext_iwmmxt2 = |
212 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2); | |
e74cfd16 PB |
213 | static const arm_feature_set arm_cext_iwmmxt = |
214 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
215 | static const arm_feature_set arm_cext_xscale = | |
216 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
217 | static const arm_feature_set arm_cext_maverick = | |
218 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
219 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
220 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
221 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
222 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
223 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
224 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
62f3b8c8 | 225 | static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD); |
5287ad62 | 226 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
b1cc4aeb PB |
227 | static const arm_feature_set fpu_vfp_ext_d32 = |
228 | ARM_FEATURE (0, FPU_VFP_EXT_D32); | |
5287ad62 JB |
229 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); |
230 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
231 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
62f3b8c8 PB |
232 | static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16); |
233 | static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA); | |
234 | static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA); | |
bca38921 MGD |
235 | static const arm_feature_set fpu_vfp_ext_armv8 = |
236 | ARM_FEATURE (0, FPU_VFP_EXT_ARMV8); | |
237 | static const arm_feature_set fpu_neon_ext_armv8 = | |
238 | ARM_FEATURE (0, FPU_NEON_EXT_ARMV8); | |
239 | static const arm_feature_set fpu_crypto_ext_armv8 = | |
240 | ARM_FEATURE (0, FPU_CRYPTO_EXT_ARMV8); | |
e74cfd16 | 241 | |
33a392fb | 242 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
243 | /* Record user cpu selection for object attributes. */ |
244 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
245 | /* Must be long enough to hold any of the names in arm_cpus. */ |
246 | static char selected_cpu_name[16]; | |
8d67f500 NC |
247 | |
248 | /* Return if no cpu was selected on command-line. */ | |
249 | static bfd_boolean | |
250 | no_cpu_selected (void) | |
251 | { | |
252 | return selected_cpu.core == arm_arch_none.core | |
253 | && selected_cpu.coproc == arm_arch_none.coproc; | |
254 | } | |
255 | ||
7cc69913 | 256 | #ifdef OBJ_ELF |
deeaaff8 DJ |
257 | # ifdef EABI_DEFAULT |
258 | static int meabi_flags = EABI_DEFAULT; | |
259 | # else | |
d507cf36 | 260 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 261 | # endif |
e1da3f5b | 262 | |
ee3c0378 AS |
263 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
264 | ||
e1da3f5b | 265 | bfd_boolean |
5f4273c7 | 266 | arm_is_eabi (void) |
e1da3f5b PB |
267 | { |
268 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
269 | } | |
7cc69913 | 270 | #endif |
b99bd4ef | 271 | |
b99bd4ef | 272 | #ifdef OBJ_ELF |
c19d1205 | 273 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
274 | symbolS * GOT_symbol; |
275 | #endif | |
276 | ||
b99bd4ef NC |
277 | /* 0: assemble for ARM, |
278 | 1: assemble for Thumb, | |
279 | 2: assemble for Thumb even though target CPU does not support thumb | |
280 | instructions. */ | |
281 | static int thumb_mode = 0; | |
8dc2430f NC |
282 | /* A value distinct from the possible values for thumb_mode that we |
283 | can use to record whether thumb_mode has been copied into the | |
284 | tc_frag_data field of a frag. */ | |
285 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 286 | |
e07e6e58 NC |
287 | /* Specifies the intrinsic IT insn behavior mode. */ |
288 | enum implicit_it_mode | |
289 | { | |
290 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
291 | IMPLICIT_IT_MODE_ARM = 0x01, | |
292 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
293 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
294 | }; | |
295 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
296 | ||
c19d1205 ZW |
297 | /* If unified_syntax is true, we are processing the new unified |
298 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
299 | ||
300 | - Immediate operands do not require a # prefix. | |
301 | - Conditional affixes always appear at the end of the | |
302 | instruction. (For backward compatibility, those instructions | |
303 | that formerly had them in the middle, continue to accept them | |
304 | there.) | |
305 | - The IT instruction may appear, and if it does is validated | |
306 | against subsequent conditional affixes. It does not generate | |
307 | machine code. | |
308 | ||
309 | Important differences from the old Thumb mode: | |
310 | ||
311 | - Immediate operands do not require a # prefix. | |
312 | - Most of the V6T2 instructions are only available in unified mode. | |
313 | - The .N and .W suffixes are recognized and honored (it is an error | |
314 | if they cannot be honored). | |
315 | - All instructions set the flags if and only if they have an 's' affix. | |
316 | - Conditional affixes may be used. They are validated against | |
317 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
318 | conditional affix except in the scope of an IT instruction. */ | |
319 | ||
320 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 321 | |
bacebabc RM |
322 | /* An immediate operand can start with #, and ld*, st*, pld operands |
323 | can contain [ and ]. We need to tell APP not to elide whitespace | |
324 | before a [, which can appear as the first operand for pld. */ | |
325 | const char arm_symbol_chars[] = "#[]"; | |
326 | ||
5287ad62 JB |
327 | enum neon_el_type |
328 | { | |
dcbf9037 | 329 | NT_invtype, |
5287ad62 JB |
330 | NT_untyped, |
331 | NT_integer, | |
332 | NT_float, | |
333 | NT_poly, | |
334 | NT_signed, | |
dcbf9037 | 335 | NT_unsigned |
5287ad62 JB |
336 | }; |
337 | ||
338 | struct neon_type_el | |
339 | { | |
340 | enum neon_el_type type; | |
341 | unsigned size; | |
342 | }; | |
343 | ||
344 | #define NEON_MAX_TYPE_ELS 4 | |
345 | ||
346 | struct neon_type | |
347 | { | |
348 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
349 | unsigned elems; | |
350 | }; | |
351 | ||
e07e6e58 NC |
352 | enum it_instruction_type |
353 | { | |
354 | OUTSIDE_IT_INSN, | |
355 | INSIDE_IT_INSN, | |
356 | INSIDE_IT_LAST_INSN, | |
357 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
358 | if inside, should be the last one. */ | |
359 | NEUTRAL_IT_INSN, /* This could be either inside or outside, | |
360 | i.e. BKPT and NOP. */ | |
361 | IT_INSN /* The IT insn has been parsed. */ | |
362 | }; | |
363 | ||
ad6cec43 MGD |
364 | /* The maximum number of operands we need. */ |
365 | #define ARM_IT_MAX_OPERANDS 6 | |
366 | ||
b99bd4ef NC |
367 | struct arm_it |
368 | { | |
c19d1205 | 369 | const char * error; |
b99bd4ef | 370 | unsigned long instruction; |
c19d1205 ZW |
371 | int size; |
372 | int size_req; | |
373 | int cond; | |
037e8744 JB |
374 | /* "uncond_value" is set to the value in place of the conditional field in |
375 | unconditional versions of the instruction, or -1 if nothing is | |
376 | appropriate. */ | |
377 | int uncond_value; | |
5287ad62 | 378 | struct neon_type vectype; |
88714cb8 DG |
379 | /* This does not indicate an actual NEON instruction, only that |
380 | the mnemonic accepts neon-style type suffixes. */ | |
381 | int is_neon; | |
0110f2b8 PB |
382 | /* Set to the opcode if the instruction needs relaxation. |
383 | Zero if the instruction is not relaxed. */ | |
384 | unsigned long relax; | |
b99bd4ef NC |
385 | struct |
386 | { | |
387 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
388 | expressionS exp; |
389 | int pc_rel; | |
b99bd4ef | 390 | } reloc; |
b99bd4ef | 391 | |
e07e6e58 NC |
392 | enum it_instruction_type it_insn_type; |
393 | ||
c19d1205 ZW |
394 | struct |
395 | { | |
396 | unsigned reg; | |
ca3f61f7 | 397 | signed int imm; |
dcbf9037 | 398 | struct neon_type_el vectype; |
ca3f61f7 NC |
399 | unsigned present : 1; /* Operand present. */ |
400 | unsigned isreg : 1; /* Operand was a register. */ | |
401 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
402 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
403 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 404 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
405 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
406 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
407 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 408 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 409 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 410 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
411 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
412 | unsigned writeback : 1; /* Operand has trailing ! */ | |
413 | unsigned preind : 1; /* Preindexed address. */ | |
414 | unsigned postind : 1; /* Postindexed address. */ | |
415 | unsigned negative : 1; /* Index register was negated. */ | |
416 | unsigned shifted : 1; /* Shift applied to operation. */ | |
417 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
ad6cec43 | 418 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
419 | }; |
420 | ||
c19d1205 | 421 | static struct arm_it inst; |
b99bd4ef NC |
422 | |
423 | #define NUM_FLOAT_VALS 8 | |
424 | ||
05d2d07e | 425 | const char * fp_const[] = |
b99bd4ef NC |
426 | { |
427 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
428 | }; | |
429 | ||
c19d1205 | 430 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
431 | #define MAX_LITTLENUMS 6 |
432 | ||
433 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
434 | ||
435 | #define FAIL (-1) | |
436 | #define SUCCESS (0) | |
437 | ||
438 | #define SUFF_S 1 | |
439 | #define SUFF_D 2 | |
440 | #define SUFF_E 3 | |
441 | #define SUFF_P 4 | |
442 | ||
c19d1205 ZW |
443 | #define CP_T_X 0x00008000 |
444 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 445 | |
c19d1205 ZW |
446 | #define CONDS_BIT 0x00100000 |
447 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
448 | |
449 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
450 | ||
451 | struct asm_cond | |
452 | { | |
d3ce72d0 | 453 | const char * template_name; |
c921be7d | 454 | unsigned long value; |
b99bd4ef NC |
455 | }; |
456 | ||
c19d1205 | 457 | #define COND_ALWAYS 0xE |
b99bd4ef | 458 | |
b99bd4ef NC |
459 | struct asm_psr |
460 | { | |
d3ce72d0 | 461 | const char * template_name; |
c921be7d | 462 | unsigned long field; |
b99bd4ef NC |
463 | }; |
464 | ||
62b3e311 PB |
465 | struct asm_barrier_opt |
466 | { | |
e797f7e0 MGD |
467 | const char * template_name; |
468 | unsigned long value; | |
469 | const arm_feature_set arch; | |
62b3e311 PB |
470 | }; |
471 | ||
2d2255b5 | 472 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
473 | #define SPSR_BIT (1 << 22) |
474 | ||
c19d1205 ZW |
475 | /* The individual PSR flag bits. */ |
476 | #define PSR_c (1 << 16) | |
477 | #define PSR_x (1 << 17) | |
478 | #define PSR_s (1 << 18) | |
479 | #define PSR_f (1 << 19) | |
b99bd4ef | 480 | |
c19d1205 | 481 | struct reloc_entry |
bfae80f2 | 482 | { |
c921be7d NC |
483 | char * name; |
484 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
485 | }; |
486 | ||
5287ad62 | 487 | enum vfp_reg_pos |
bfae80f2 | 488 | { |
5287ad62 JB |
489 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
490 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
491 | }; |
492 | ||
493 | enum vfp_ldstm_type | |
494 | { | |
495 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
496 | }; | |
497 | ||
dcbf9037 JB |
498 | /* Bits for DEFINED field in neon_typed_alias. */ |
499 | #define NTA_HASTYPE 1 | |
500 | #define NTA_HASINDEX 2 | |
501 | ||
502 | struct neon_typed_alias | |
503 | { | |
c921be7d NC |
504 | unsigned char defined; |
505 | unsigned char index; | |
506 | struct neon_type_el eltype; | |
dcbf9037 JB |
507 | }; |
508 | ||
c19d1205 ZW |
509 | /* ARM register categories. This includes coprocessor numbers and various |
510 | architecture extensions' registers. */ | |
511 | enum arm_reg_type | |
bfae80f2 | 512 | { |
c19d1205 ZW |
513 | REG_TYPE_RN, |
514 | REG_TYPE_CP, | |
515 | REG_TYPE_CN, | |
516 | REG_TYPE_FN, | |
517 | REG_TYPE_VFS, | |
518 | REG_TYPE_VFD, | |
5287ad62 | 519 | REG_TYPE_NQ, |
037e8744 | 520 | REG_TYPE_VFSD, |
5287ad62 | 521 | REG_TYPE_NDQ, |
037e8744 | 522 | REG_TYPE_NSDQ, |
c19d1205 ZW |
523 | REG_TYPE_VFC, |
524 | REG_TYPE_MVF, | |
525 | REG_TYPE_MVD, | |
526 | REG_TYPE_MVFX, | |
527 | REG_TYPE_MVDX, | |
528 | REG_TYPE_MVAX, | |
529 | REG_TYPE_DSPSC, | |
530 | REG_TYPE_MMXWR, | |
531 | REG_TYPE_MMXWC, | |
532 | REG_TYPE_MMXWCG, | |
533 | REG_TYPE_XSCALE, | |
90ec0d68 | 534 | REG_TYPE_RNB |
bfae80f2 RE |
535 | }; |
536 | ||
dcbf9037 JB |
537 | /* Structure for a hash table entry for a register. |
538 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
539 | information which states whether a vector type or index is specified (for a | |
540 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
541 | struct reg_entry |
542 | { | |
c921be7d | 543 | const char * name; |
90ec0d68 | 544 | unsigned int number; |
c921be7d NC |
545 | unsigned char type; |
546 | unsigned char builtin; | |
547 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
548 | }; |
549 | ||
c19d1205 | 550 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 551 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
552 | { |
553 | N_("ARM register expected"), | |
554 | N_("bad or missing co-processor number"), | |
555 | N_("co-processor register expected"), | |
556 | N_("FPA register expected"), | |
557 | N_("VFP single precision register expected"), | |
5287ad62 JB |
558 | N_("VFP/Neon double precision register expected"), |
559 | N_("Neon quad precision register expected"), | |
037e8744 | 560 | N_("VFP single or double precision register expected"), |
5287ad62 | 561 | N_("Neon double or quad precision register expected"), |
037e8744 | 562 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
563 | N_("VFP system register expected"), |
564 | N_("Maverick MVF register expected"), | |
565 | N_("Maverick MVD register expected"), | |
566 | N_("Maverick MVFX register expected"), | |
567 | N_("Maverick MVDX register expected"), | |
568 | N_("Maverick MVAX register expected"), | |
569 | N_("Maverick DSPSC register expected"), | |
570 | N_("iWMMXt data register expected"), | |
571 | N_("iWMMXt control register expected"), | |
572 | N_("iWMMXt scalar register expected"), | |
573 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
574 | }; |
575 | ||
c19d1205 | 576 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 577 | #define REG_R12 12 |
c19d1205 ZW |
578 | #define REG_SP 13 |
579 | #define REG_LR 14 | |
580 | #define REG_PC 15 | |
404ff6b5 | 581 | |
b99bd4ef NC |
582 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
583 | take 2: */ | |
c19d1205 | 584 | #define INSN_SIZE 4 |
b99bd4ef NC |
585 | |
586 | struct asm_opcode | |
587 | { | |
588 | /* Basic string to match. */ | |
d3ce72d0 | 589 | const char * template_name; |
c19d1205 ZW |
590 | |
591 | /* Parameters to instruction. */ | |
5be8be5d | 592 | unsigned int operands[8]; |
c19d1205 ZW |
593 | |
594 | /* Conditional tag - see opcode_lookup. */ | |
595 | unsigned int tag : 4; | |
b99bd4ef NC |
596 | |
597 | /* Basic instruction code. */ | |
c19d1205 | 598 | unsigned int avalue : 28; |
b99bd4ef | 599 | |
c19d1205 ZW |
600 | /* Thumb-format instruction code. */ |
601 | unsigned int tvalue; | |
b99bd4ef | 602 | |
90e4755a | 603 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
604 | const arm_feature_set * avariant; |
605 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
606 | |
607 | /* Function to call to encode instruction in ARM format. */ | |
608 | void (* aencode) (void); | |
b99bd4ef | 609 | |
c19d1205 ZW |
610 | /* Function to call to encode instruction in Thumb format. */ |
611 | void (* tencode) (void); | |
b99bd4ef NC |
612 | }; |
613 | ||
a737bd4d NC |
614 | /* Defines for various bits that we will want to toggle. */ |
615 | #define INST_IMMEDIATE 0x02000000 | |
616 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 617 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
618 | #define SHIFT_BY_REG 0x00000010 |
619 | #define PRE_INDEX 0x01000000 | |
620 | #define INDEX_UP 0x00800000 | |
621 | #define WRITE_BACK 0x00200000 | |
622 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 623 | #define CPSI_MMOD 0x00020000 |
90e4755a | 624 | |
a737bd4d NC |
625 | #define LITERAL_MASK 0xf000f000 |
626 | #define OPCODE_MASK 0xfe1fffff | |
627 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 628 | |
efd81785 PB |
629 | #define T2_SUBS_PC_LR 0xf3de8f00 |
630 | ||
a737bd4d | 631 | #define DATA_OP_SHIFT 21 |
90e4755a | 632 | |
ef8d22e6 PB |
633 | #define T2_OPCODE_MASK 0xfe1fffff |
634 | #define T2_DATA_OP_SHIFT 21 | |
635 | ||
6530b175 NC |
636 | #define A_COND_MASK 0xf0000000 |
637 | #define A_PUSH_POP_OP_MASK 0x0fff0000 | |
638 | ||
639 | /* Opcodes for pushing/poping registers to/from the stack. */ | |
640 | #define A1_OPCODE_PUSH 0x092d0000 | |
641 | #define A2_OPCODE_PUSH 0x052d0004 | |
642 | #define A2_OPCODE_POP 0x049d0004 | |
643 | ||
a737bd4d NC |
644 | /* Codes to distinguish the arithmetic instructions. */ |
645 | #define OPCODE_AND 0 | |
646 | #define OPCODE_EOR 1 | |
647 | #define OPCODE_SUB 2 | |
648 | #define OPCODE_RSB 3 | |
649 | #define OPCODE_ADD 4 | |
650 | #define OPCODE_ADC 5 | |
651 | #define OPCODE_SBC 6 | |
652 | #define OPCODE_RSC 7 | |
653 | #define OPCODE_TST 8 | |
654 | #define OPCODE_TEQ 9 | |
655 | #define OPCODE_CMP 10 | |
656 | #define OPCODE_CMN 11 | |
657 | #define OPCODE_ORR 12 | |
658 | #define OPCODE_MOV 13 | |
659 | #define OPCODE_BIC 14 | |
660 | #define OPCODE_MVN 15 | |
90e4755a | 661 | |
ef8d22e6 PB |
662 | #define T2_OPCODE_AND 0 |
663 | #define T2_OPCODE_BIC 1 | |
664 | #define T2_OPCODE_ORR 2 | |
665 | #define T2_OPCODE_ORN 3 | |
666 | #define T2_OPCODE_EOR 4 | |
667 | #define T2_OPCODE_ADD 8 | |
668 | #define T2_OPCODE_ADC 10 | |
669 | #define T2_OPCODE_SBC 11 | |
670 | #define T2_OPCODE_SUB 13 | |
671 | #define T2_OPCODE_RSB 14 | |
672 | ||
a737bd4d NC |
673 | #define T_OPCODE_MUL 0x4340 |
674 | #define T_OPCODE_TST 0x4200 | |
675 | #define T_OPCODE_CMN 0x42c0 | |
676 | #define T_OPCODE_NEG 0x4240 | |
677 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 678 | |
a737bd4d NC |
679 | #define T_OPCODE_ADD_R3 0x1800 |
680 | #define T_OPCODE_SUB_R3 0x1a00 | |
681 | #define T_OPCODE_ADD_HI 0x4400 | |
682 | #define T_OPCODE_ADD_ST 0xb000 | |
683 | #define T_OPCODE_SUB_ST 0xb080 | |
684 | #define T_OPCODE_ADD_SP 0xa800 | |
685 | #define T_OPCODE_ADD_PC 0xa000 | |
686 | #define T_OPCODE_ADD_I8 0x3000 | |
687 | #define T_OPCODE_SUB_I8 0x3800 | |
688 | #define T_OPCODE_ADD_I3 0x1c00 | |
689 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 690 | |
a737bd4d NC |
691 | #define T_OPCODE_ASR_R 0x4100 |
692 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
693 | #define T_OPCODE_LSR_R 0x40c0 |
694 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
695 | #define T_OPCODE_ASR_I 0x1000 |
696 | #define T_OPCODE_LSL_I 0x0000 | |
697 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 698 | |
a737bd4d NC |
699 | #define T_OPCODE_MOV_I8 0x2000 |
700 | #define T_OPCODE_CMP_I8 0x2800 | |
701 | #define T_OPCODE_CMP_LR 0x4280 | |
702 | #define T_OPCODE_MOV_HR 0x4600 | |
703 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 704 | |
a737bd4d NC |
705 | #define T_OPCODE_LDR_PC 0x4800 |
706 | #define T_OPCODE_LDR_SP 0x9800 | |
707 | #define T_OPCODE_STR_SP 0x9000 | |
708 | #define T_OPCODE_LDR_IW 0x6800 | |
709 | #define T_OPCODE_STR_IW 0x6000 | |
710 | #define T_OPCODE_LDR_IH 0x8800 | |
711 | #define T_OPCODE_STR_IH 0x8000 | |
712 | #define T_OPCODE_LDR_IB 0x7800 | |
713 | #define T_OPCODE_STR_IB 0x7000 | |
714 | #define T_OPCODE_LDR_RW 0x5800 | |
715 | #define T_OPCODE_STR_RW 0x5000 | |
716 | #define T_OPCODE_LDR_RH 0x5a00 | |
717 | #define T_OPCODE_STR_RH 0x5200 | |
718 | #define T_OPCODE_LDR_RB 0x5c00 | |
719 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 720 | |
a737bd4d NC |
721 | #define T_OPCODE_PUSH 0xb400 |
722 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 723 | |
2fc8bdac | 724 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 725 | |
a737bd4d | 726 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 727 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 728 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 729 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
730 | |
731 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 732 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
733 | #define BAD_PC _("r15 not allowed here") |
734 | #define BAD_COND _("instruction cannot be conditional") | |
735 | #define BAD_OVERLAP _("registers may not be the same") | |
736 | #define BAD_HIREG _("lo register required") | |
737 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 738 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
739 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
740 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 741 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
742 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
743 | #define BAD_IT_COND _("incorrect condition in IT block") | |
744 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 745 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
746 | #define BAD_PC_ADDRESSING \ |
747 | _("cannot use register index with PC-relative addressing") | |
748 | #define BAD_PC_WRITEBACK \ | |
749 | _("cannot use writeback with PC-relative addressing") | |
08f10d51 | 750 | #define BAD_RANGE _("branch out of range") |
c19d1205 | 751 | |
c921be7d NC |
752 | static struct hash_control * arm_ops_hsh; |
753 | static struct hash_control * arm_cond_hsh; | |
754 | static struct hash_control * arm_shift_hsh; | |
755 | static struct hash_control * arm_psr_hsh; | |
756 | static struct hash_control * arm_v7m_psr_hsh; | |
757 | static struct hash_control * arm_reg_hsh; | |
758 | static struct hash_control * arm_reloc_hsh; | |
759 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 760 | |
b99bd4ef NC |
761 | /* Stuff needed to resolve the label ambiguity |
762 | As: | |
763 | ... | |
764 | label: <insn> | |
765 | may differ from: | |
766 | ... | |
767 | label: | |
5f4273c7 | 768 | <insn> */ |
b99bd4ef NC |
769 | |
770 | symbolS * last_label_seen; | |
b34976b6 | 771 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 772 | |
3d0c9500 NC |
773 | /* Literal pool structure. Held on a per-section |
774 | and per-sub-section basis. */ | |
a737bd4d | 775 | |
c19d1205 | 776 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 777 | typedef struct literal_pool |
b99bd4ef | 778 | { |
c921be7d NC |
779 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
780 | unsigned int next_free_entry; | |
781 | unsigned int id; | |
782 | symbolS * symbol; | |
783 | segT section; | |
784 | subsegT sub_section; | |
a8040cf2 NC |
785 | #ifdef OBJ_ELF |
786 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
787 | #endif | |
c921be7d | 788 | struct literal_pool * next; |
3d0c9500 | 789 | } literal_pool; |
b99bd4ef | 790 | |
3d0c9500 NC |
791 | /* Pointer to a linked list of literal pools. */ |
792 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 793 | |
e07e6e58 NC |
794 | #ifdef OBJ_ELF |
795 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
796 | #else | |
797 | static struct current_it now_it; | |
798 | #endif | |
799 | ||
800 | static inline int | |
801 | now_it_compatible (int cond) | |
802 | { | |
803 | return (cond & ~1) == (now_it.cc & ~1); | |
804 | } | |
805 | ||
806 | static inline int | |
807 | conditional_insn (void) | |
808 | { | |
809 | return inst.cond != COND_ALWAYS; | |
810 | } | |
811 | ||
812 | static int in_it_block (void); | |
813 | ||
814 | static int handle_it_state (void); | |
815 | ||
816 | static void force_automatic_it_block_close (void); | |
817 | ||
c921be7d NC |
818 | static void it_fsm_post_encode (void); |
819 | ||
e07e6e58 NC |
820 | #define set_it_insn_type(type) \ |
821 | do \ | |
822 | { \ | |
823 | inst.it_insn_type = type; \ | |
824 | if (handle_it_state () == FAIL) \ | |
825 | return; \ | |
826 | } \ | |
827 | while (0) | |
828 | ||
c921be7d NC |
829 | #define set_it_insn_type_nonvoid(type, failret) \ |
830 | do \ | |
831 | { \ | |
832 | inst.it_insn_type = type; \ | |
833 | if (handle_it_state () == FAIL) \ | |
834 | return failret; \ | |
835 | } \ | |
836 | while(0) | |
837 | ||
e07e6e58 NC |
838 | #define set_it_insn_type_last() \ |
839 | do \ | |
840 | { \ | |
841 | if (inst.cond == COND_ALWAYS) \ | |
842 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ | |
843 | else \ | |
844 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ | |
845 | } \ | |
846 | while (0) | |
847 | ||
c19d1205 | 848 | /* Pure syntax. */ |
b99bd4ef | 849 | |
c19d1205 ZW |
850 | /* This array holds the chars that always start a comment. If the |
851 | pre-processor is disabled, these aren't very useful. */ | |
852 | const char comment_chars[] = "@"; | |
3d0c9500 | 853 | |
c19d1205 ZW |
854 | /* This array holds the chars that only start a comment at the beginning of |
855 | a line. If the line seems to have the form '# 123 filename' | |
856 | .line and .file directives will appear in the pre-processed output. */ | |
857 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
858 | first line of the input file. This is because the compiler outputs | |
859 | #NO_APP at the beginning of its output. */ | |
860 | /* Also note that comments like this one will always work. */ | |
861 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 862 | |
c19d1205 | 863 | const char line_separator_chars[] = ";"; |
b99bd4ef | 864 | |
c19d1205 ZW |
865 | /* Chars that can be used to separate mant |
866 | from exp in floating point numbers. */ | |
867 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 868 | |
c19d1205 ZW |
869 | /* Chars that mean this number is a floating point constant. */ |
870 | /* As in 0f12.456 */ | |
871 | /* or 0d1.2345e12 */ | |
b99bd4ef | 872 | |
c19d1205 | 873 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 874 | |
c19d1205 ZW |
875 | /* Prefix characters that indicate the start of an immediate |
876 | value. */ | |
877 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 878 | |
c19d1205 ZW |
879 | /* Separator character handling. */ |
880 | ||
881 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
882 | ||
883 | static inline int | |
884 | skip_past_char (char ** str, char c) | |
885 | { | |
8ab8155f NC |
886 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
887 | skip_whitespace (*str); | |
427d0db6 | 888 | |
c19d1205 ZW |
889 | if (**str == c) |
890 | { | |
891 | (*str)++; | |
892 | return SUCCESS; | |
3d0c9500 | 893 | } |
c19d1205 ZW |
894 | else |
895 | return FAIL; | |
896 | } | |
c921be7d | 897 | |
c19d1205 | 898 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 899 | |
c19d1205 ZW |
900 | /* Arithmetic expressions (possibly involving symbols). */ |
901 | ||
902 | /* Return TRUE if anything in the expression is a bignum. */ | |
903 | ||
904 | static int | |
905 | walk_no_bignums (symbolS * sp) | |
906 | { | |
907 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
908 | return 1; | |
909 | ||
910 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 911 | { |
c19d1205 ZW |
912 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
913 | || (symbol_get_value_expression (sp)->X_op_symbol | |
914 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
915 | } |
916 | ||
c19d1205 | 917 | return 0; |
3d0c9500 NC |
918 | } |
919 | ||
c19d1205 ZW |
920 | static int in_my_get_expression = 0; |
921 | ||
922 | /* Third argument to my_get_expression. */ | |
923 | #define GE_NO_PREFIX 0 | |
924 | #define GE_IMM_PREFIX 1 | |
925 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
926 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
927 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
928 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 929 | |
b99bd4ef | 930 | static int |
c19d1205 | 931 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 932 | { |
c19d1205 ZW |
933 | char * save_in; |
934 | segT seg; | |
b99bd4ef | 935 | |
c19d1205 ZW |
936 | /* In unified syntax, all prefixes are optional. */ |
937 | if (unified_syntax) | |
5287ad62 JB |
938 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
939 | : GE_OPT_PREFIX; | |
b99bd4ef | 940 | |
c19d1205 | 941 | switch (prefix_mode) |
b99bd4ef | 942 | { |
c19d1205 ZW |
943 | case GE_NO_PREFIX: break; |
944 | case GE_IMM_PREFIX: | |
945 | if (!is_immediate_prefix (**str)) | |
946 | { | |
947 | inst.error = _("immediate expression requires a # prefix"); | |
948 | return FAIL; | |
949 | } | |
950 | (*str)++; | |
951 | break; | |
952 | case GE_OPT_PREFIX: | |
5287ad62 | 953 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
954 | if (is_immediate_prefix (**str)) |
955 | (*str)++; | |
956 | break; | |
957 | default: abort (); | |
958 | } | |
b99bd4ef | 959 | |
c19d1205 | 960 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 961 | |
c19d1205 ZW |
962 | save_in = input_line_pointer; |
963 | input_line_pointer = *str; | |
964 | in_my_get_expression = 1; | |
965 | seg = expression (ep); | |
966 | in_my_get_expression = 0; | |
967 | ||
f86adc07 | 968 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 969 | { |
f86adc07 | 970 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
971 | *str = input_line_pointer; |
972 | input_line_pointer = save_in; | |
973 | if (inst.error == NULL) | |
f86adc07 NS |
974 | inst.error = (ep->X_op == O_absent |
975 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
976 | return 1; |
977 | } | |
b99bd4ef | 978 | |
c19d1205 ZW |
979 | #ifdef OBJ_AOUT |
980 | if (seg != absolute_section | |
981 | && seg != text_section | |
982 | && seg != data_section | |
983 | && seg != bss_section | |
984 | && seg != undefined_section) | |
985 | { | |
986 | inst.error = _("bad segment"); | |
987 | *str = input_line_pointer; | |
988 | input_line_pointer = save_in; | |
989 | return 1; | |
b99bd4ef | 990 | } |
87975d2a AM |
991 | #else |
992 | (void) seg; | |
c19d1205 | 993 | #endif |
b99bd4ef | 994 | |
c19d1205 ZW |
995 | /* Get rid of any bignums now, so that we don't generate an error for which |
996 | we can't establish a line number later on. Big numbers are never valid | |
997 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
998 | if (prefix_mode != GE_OPT_PREFIX_BIG |
999 | && (ep->X_op == O_big | |
1000 | || (ep->X_add_symbol | |
1001 | && (walk_no_bignums (ep->X_add_symbol) | |
1002 | || (ep->X_op_symbol | |
1003 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
1004 | { |
1005 | inst.error = _("invalid constant"); | |
1006 | *str = input_line_pointer; | |
1007 | input_line_pointer = save_in; | |
1008 | return 1; | |
1009 | } | |
b99bd4ef | 1010 | |
c19d1205 ZW |
1011 | *str = input_line_pointer; |
1012 | input_line_pointer = save_in; | |
1013 | return 0; | |
b99bd4ef NC |
1014 | } |
1015 | ||
c19d1205 ZW |
1016 | /* Turn a string in input_line_pointer into a floating point constant |
1017 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1018 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1019 | returned, or NULL on OK. | |
b99bd4ef | 1020 | |
c19d1205 ZW |
1021 | Note that fp constants aren't represent in the normal way on the ARM. |
1022 | In big endian mode, things are as expected. However, in little endian | |
1023 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
1024 | within the words. For example, (double) 1.1 in big endian mode is | |
1025 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
1026 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 1027 | |
c19d1205 | 1028 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1029 | |
c19d1205 ZW |
1030 | char * |
1031 | md_atof (int type, char * litP, int * sizeP) | |
1032 | { | |
1033 | int prec; | |
1034 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1035 | char *t; | |
1036 | int i; | |
b99bd4ef | 1037 | |
c19d1205 ZW |
1038 | switch (type) |
1039 | { | |
1040 | case 'f': | |
1041 | case 'F': | |
1042 | case 's': | |
1043 | case 'S': | |
1044 | prec = 2; | |
1045 | break; | |
b99bd4ef | 1046 | |
c19d1205 ZW |
1047 | case 'd': |
1048 | case 'D': | |
1049 | case 'r': | |
1050 | case 'R': | |
1051 | prec = 4; | |
1052 | break; | |
b99bd4ef | 1053 | |
c19d1205 ZW |
1054 | case 'x': |
1055 | case 'X': | |
499ac353 | 1056 | prec = 5; |
c19d1205 | 1057 | break; |
b99bd4ef | 1058 | |
c19d1205 ZW |
1059 | case 'p': |
1060 | case 'P': | |
499ac353 | 1061 | prec = 5; |
c19d1205 | 1062 | break; |
a737bd4d | 1063 | |
c19d1205 ZW |
1064 | default: |
1065 | *sizeP = 0; | |
499ac353 | 1066 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1067 | } |
b99bd4ef | 1068 | |
c19d1205 ZW |
1069 | t = atof_ieee (input_line_pointer, type, words); |
1070 | if (t) | |
1071 | input_line_pointer = t; | |
499ac353 | 1072 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1073 | |
c19d1205 ZW |
1074 | if (target_big_endian) |
1075 | { | |
1076 | for (i = 0; i < prec; i++) | |
1077 | { | |
499ac353 NC |
1078 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1079 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1080 | } |
1081 | } | |
1082 | else | |
1083 | { | |
e74cfd16 | 1084 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1085 | for (i = prec - 1; i >= 0; i--) |
1086 | { | |
499ac353 NC |
1087 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1088 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1089 | } |
1090 | else | |
1091 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1092 | For an 8 byte float the order is 1 0 3 2. */ | |
1093 | for (i = 0; i < prec; i += 2) | |
1094 | { | |
499ac353 NC |
1095 | md_number_to_chars (litP, (valueT) words[i + 1], |
1096 | sizeof (LITTLENUM_TYPE)); | |
1097 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1098 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1099 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1100 | } |
1101 | } | |
b99bd4ef | 1102 | |
499ac353 | 1103 | return NULL; |
c19d1205 | 1104 | } |
b99bd4ef | 1105 | |
c19d1205 ZW |
1106 | /* We handle all bad expressions here, so that we can report the faulty |
1107 | instruction in the error message. */ | |
1108 | void | |
91d6fa6a | 1109 | md_operand (expressionS * exp) |
c19d1205 ZW |
1110 | { |
1111 | if (in_my_get_expression) | |
91d6fa6a | 1112 | exp->X_op = O_illegal; |
b99bd4ef NC |
1113 | } |
1114 | ||
c19d1205 | 1115 | /* Immediate values. */ |
b99bd4ef | 1116 | |
c19d1205 ZW |
1117 | /* Generic immediate-value read function for use in directives. |
1118 | Accepts anything that 'expression' can fold to a constant. | |
1119 | *val receives the number. */ | |
1120 | #ifdef OBJ_ELF | |
1121 | static int | |
1122 | immediate_for_directive (int *val) | |
b99bd4ef | 1123 | { |
c19d1205 ZW |
1124 | expressionS exp; |
1125 | exp.X_op = O_illegal; | |
b99bd4ef | 1126 | |
c19d1205 ZW |
1127 | if (is_immediate_prefix (*input_line_pointer)) |
1128 | { | |
1129 | input_line_pointer++; | |
1130 | expression (&exp); | |
1131 | } | |
b99bd4ef | 1132 | |
c19d1205 ZW |
1133 | if (exp.X_op != O_constant) |
1134 | { | |
1135 | as_bad (_("expected #constant")); | |
1136 | ignore_rest_of_line (); | |
1137 | return FAIL; | |
1138 | } | |
1139 | *val = exp.X_add_number; | |
1140 | return SUCCESS; | |
b99bd4ef | 1141 | } |
c19d1205 | 1142 | #endif |
b99bd4ef | 1143 | |
c19d1205 | 1144 | /* Register parsing. */ |
b99bd4ef | 1145 | |
c19d1205 ZW |
1146 | /* Generic register parser. CCP points to what should be the |
1147 | beginning of a register name. If it is indeed a valid register | |
1148 | name, advance CCP over it and return the reg_entry structure; | |
1149 | otherwise return NULL. Does not issue diagnostics. */ | |
1150 | ||
1151 | static struct reg_entry * | |
1152 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1153 | { |
c19d1205 ZW |
1154 | char *start = *ccp; |
1155 | char *p; | |
1156 | struct reg_entry *reg; | |
b99bd4ef | 1157 | |
c19d1205 ZW |
1158 | #ifdef REGISTER_PREFIX |
1159 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1160 | return NULL; |
c19d1205 ZW |
1161 | start++; |
1162 | #endif | |
1163 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1164 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1165 | start++; | |
1166 | #endif | |
b99bd4ef | 1167 | |
c19d1205 ZW |
1168 | p = start; |
1169 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1170 | return NULL; | |
b99bd4ef | 1171 | |
c19d1205 ZW |
1172 | do |
1173 | p++; | |
1174 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1175 | ||
1176 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1177 | ||
1178 | if (!reg) | |
1179 | return NULL; | |
1180 | ||
1181 | *ccp = p; | |
1182 | return reg; | |
b99bd4ef NC |
1183 | } |
1184 | ||
1185 | static int | |
dcbf9037 JB |
1186 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1187 | enum arm_reg_type type) | |
b99bd4ef | 1188 | { |
c19d1205 ZW |
1189 | /* Alternative syntaxes are accepted for a few register classes. */ |
1190 | switch (type) | |
1191 | { | |
1192 | case REG_TYPE_MVF: | |
1193 | case REG_TYPE_MVD: | |
1194 | case REG_TYPE_MVFX: | |
1195 | case REG_TYPE_MVDX: | |
1196 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1197 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1198 | return reg->number; |
1199 | break; | |
69b97547 | 1200 | |
c19d1205 ZW |
1201 | case REG_TYPE_CP: |
1202 | /* For backward compatibility, a bare number is valid here. */ | |
1203 | { | |
1204 | unsigned long processor = strtoul (start, ccp, 10); | |
1205 | if (*ccp != start && processor <= 15) | |
1206 | return processor; | |
1207 | } | |
6057a28f | 1208 | |
c19d1205 ZW |
1209 | case REG_TYPE_MMXWC: |
1210 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1211 | instructions that take WC registers. */ | |
79134647 | 1212 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1213 | return reg->number; |
6057a28f | 1214 | break; |
c19d1205 | 1215 | |
6057a28f | 1216 | default: |
c19d1205 | 1217 | break; |
6057a28f NC |
1218 | } |
1219 | ||
dcbf9037 JB |
1220 | return FAIL; |
1221 | } | |
1222 | ||
1223 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1224 | return value is the register number or FAIL. */ | |
1225 | ||
1226 | static int | |
1227 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1228 | { | |
1229 | char *start = *ccp; | |
1230 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1231 | int ret; | |
1232 | ||
1233 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1234 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1235 | return FAIL; | |
1236 | ||
1237 | if (reg && reg->type == type) | |
1238 | return reg->number; | |
1239 | ||
1240 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1241 | return ret; | |
1242 | ||
c19d1205 ZW |
1243 | *ccp = start; |
1244 | return FAIL; | |
1245 | } | |
69b97547 | 1246 | |
dcbf9037 JB |
1247 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1248 | character. Does no verification at this stage that the type fits the opcode | |
1249 | properly. E.g., | |
1250 | ||
1251 | .i32.i32.s16 | |
1252 | .s32.f32 | |
1253 | .u16 | |
1254 | ||
1255 | Can all be legally parsed by this function. | |
1256 | ||
1257 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1258 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1259 | type, FAIL if not. */ | |
1260 | ||
1261 | static int | |
1262 | parse_neon_type (struct neon_type *type, char **str) | |
1263 | { | |
1264 | char *ptr = *str; | |
1265 | ||
1266 | if (type) | |
1267 | type->elems = 0; | |
1268 | ||
1269 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1270 | { | |
1271 | enum neon_el_type thistype = NT_untyped; | |
1272 | unsigned thissize = -1u; | |
1273 | ||
1274 | if (*ptr != '.') | |
1275 | break; | |
1276 | ||
1277 | ptr++; | |
1278 | ||
1279 | /* Just a size without an explicit type. */ | |
1280 | if (ISDIGIT (*ptr)) | |
1281 | goto parsesize; | |
1282 | ||
1283 | switch (TOLOWER (*ptr)) | |
1284 | { | |
1285 | case 'i': thistype = NT_integer; break; | |
1286 | case 'f': thistype = NT_float; break; | |
1287 | case 'p': thistype = NT_poly; break; | |
1288 | case 's': thistype = NT_signed; break; | |
1289 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1290 | case 'd': |
1291 | thistype = NT_float; | |
1292 | thissize = 64; | |
1293 | ptr++; | |
1294 | goto done; | |
dcbf9037 JB |
1295 | default: |
1296 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1297 | return FAIL; | |
1298 | } | |
1299 | ||
1300 | ptr++; | |
1301 | ||
1302 | /* .f is an abbreviation for .f32. */ | |
1303 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1304 | thissize = 32; | |
1305 | else | |
1306 | { | |
1307 | parsesize: | |
1308 | thissize = strtoul (ptr, &ptr, 10); | |
1309 | ||
1310 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1311 | && thissize != 64) | |
1312 | { | |
1313 | as_bad (_("bad size %d in type specifier"), thissize); | |
1314 | return FAIL; | |
1315 | } | |
1316 | } | |
1317 | ||
037e8744 | 1318 | done: |
dcbf9037 JB |
1319 | if (type) |
1320 | { | |
1321 | type->el[type->elems].type = thistype; | |
1322 | type->el[type->elems].size = thissize; | |
1323 | type->elems++; | |
1324 | } | |
1325 | } | |
1326 | ||
1327 | /* Empty/missing type is not a successful parse. */ | |
1328 | if (type->elems == 0) | |
1329 | return FAIL; | |
1330 | ||
1331 | *str = ptr; | |
1332 | ||
1333 | return SUCCESS; | |
1334 | } | |
1335 | ||
1336 | /* Errors may be set multiple times during parsing or bit encoding | |
1337 | (particularly in the Neon bits), but usually the earliest error which is set | |
1338 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1339 | errors by calling this function. */ | |
1340 | ||
1341 | static void | |
1342 | first_error (const char *err) | |
1343 | { | |
1344 | if (!inst.error) | |
1345 | inst.error = err; | |
1346 | } | |
1347 | ||
1348 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1349 | static int | |
1350 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1351 | { | |
1352 | char *str = *ccp; | |
1353 | struct neon_type optype; | |
1354 | ||
1355 | if (*str == '.') | |
1356 | { | |
1357 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1358 | { | |
1359 | if (optype.elems == 1) | |
1360 | *vectype = optype.el[0]; | |
1361 | else | |
1362 | { | |
1363 | first_error (_("only one type should be specified for operand")); | |
1364 | return FAIL; | |
1365 | } | |
1366 | } | |
1367 | else | |
1368 | { | |
1369 | first_error (_("vector type expected")); | |
1370 | return FAIL; | |
1371 | } | |
1372 | } | |
1373 | else | |
1374 | return FAIL; | |
5f4273c7 | 1375 | |
dcbf9037 | 1376 | *ccp = str; |
5f4273c7 | 1377 | |
dcbf9037 JB |
1378 | return SUCCESS; |
1379 | } | |
1380 | ||
1381 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1382 | a 4-bit integer. */ | |
1383 | ||
1384 | #define NEON_ALL_LANES 15 | |
1385 | #define NEON_INTERLEAVE_LANES 14 | |
1386 | ||
1387 | /* Parse either a register or a scalar, with an optional type. Return the | |
1388 | register number, and optionally fill in the actual type of the register | |
1389 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1390 | type/index information in *TYPEINFO. */ | |
1391 | ||
1392 | static int | |
1393 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1394 | enum arm_reg_type *rtype, | |
1395 | struct neon_typed_alias *typeinfo) | |
1396 | { | |
1397 | char *str = *ccp; | |
1398 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1399 | struct neon_typed_alias atype; | |
1400 | struct neon_type_el parsetype; | |
1401 | ||
1402 | atype.defined = 0; | |
1403 | atype.index = -1; | |
1404 | atype.eltype.type = NT_invtype; | |
1405 | atype.eltype.size = -1; | |
1406 | ||
1407 | /* Try alternate syntax for some types of register. Note these are mutually | |
1408 | exclusive with the Neon syntax extensions. */ | |
1409 | if (reg == NULL) | |
1410 | { | |
1411 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1412 | if (altreg != FAIL) | |
1413 | *ccp = str; | |
1414 | if (typeinfo) | |
1415 | *typeinfo = atype; | |
1416 | return altreg; | |
1417 | } | |
1418 | ||
037e8744 JB |
1419 | /* Undo polymorphism when a set of register types may be accepted. */ |
1420 | if ((type == REG_TYPE_NDQ | |
1421 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1422 | || (type == REG_TYPE_VFSD | |
1423 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1424 | || (type == REG_TYPE_NSDQ | |
1425 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
f512f76f NC |
1426 | || reg->type == REG_TYPE_NQ)) |
1427 | || (type == REG_TYPE_MMXWC | |
1428 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1429 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1430 | |
1431 | if (type != reg->type) | |
1432 | return FAIL; | |
1433 | ||
1434 | if (reg->neon) | |
1435 | atype = *reg->neon; | |
5f4273c7 | 1436 | |
dcbf9037 JB |
1437 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1438 | { | |
1439 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1440 | { | |
1441 | first_error (_("can't redefine type for operand")); | |
1442 | return FAIL; | |
1443 | } | |
1444 | atype.defined |= NTA_HASTYPE; | |
1445 | atype.eltype = parsetype; | |
1446 | } | |
5f4273c7 | 1447 | |
dcbf9037 JB |
1448 | if (skip_past_char (&str, '[') == SUCCESS) |
1449 | { | |
1450 | if (type != REG_TYPE_VFD) | |
1451 | { | |
1452 | first_error (_("only D registers may be indexed")); | |
1453 | return FAIL; | |
1454 | } | |
5f4273c7 | 1455 | |
dcbf9037 JB |
1456 | if ((atype.defined & NTA_HASINDEX) != 0) |
1457 | { | |
1458 | first_error (_("can't change index for operand")); | |
1459 | return FAIL; | |
1460 | } | |
1461 | ||
1462 | atype.defined |= NTA_HASINDEX; | |
1463 | ||
1464 | if (skip_past_char (&str, ']') == SUCCESS) | |
1465 | atype.index = NEON_ALL_LANES; | |
1466 | else | |
1467 | { | |
1468 | expressionS exp; | |
1469 | ||
1470 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1471 | ||
1472 | if (exp.X_op != O_constant) | |
1473 | { | |
1474 | first_error (_("constant expression required")); | |
1475 | return FAIL; | |
1476 | } | |
1477 | ||
1478 | if (skip_past_char (&str, ']') == FAIL) | |
1479 | return FAIL; | |
1480 | ||
1481 | atype.index = exp.X_add_number; | |
1482 | } | |
1483 | } | |
5f4273c7 | 1484 | |
dcbf9037 JB |
1485 | if (typeinfo) |
1486 | *typeinfo = atype; | |
5f4273c7 | 1487 | |
dcbf9037 JB |
1488 | if (rtype) |
1489 | *rtype = type; | |
5f4273c7 | 1490 | |
dcbf9037 | 1491 | *ccp = str; |
5f4273c7 | 1492 | |
dcbf9037 JB |
1493 | return reg->number; |
1494 | } | |
1495 | ||
1496 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1497 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1498 | register (e.g. Neon double or quad reg when either has been requested). | |
1499 | - If this is a Neon vector type with additional type information, fill | |
1500 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1501 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1502 | |
1503 | static int | |
1504 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1505 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1506 | { | |
1507 | struct neon_typed_alias atype; | |
1508 | char *str = *ccp; | |
1509 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1510 | ||
1511 | if (reg == FAIL) | |
1512 | return FAIL; | |
1513 | ||
0855e32b NS |
1514 | /* Do not allow regname(... to parse as a register. */ |
1515 | if (*str == '(') | |
1516 | return FAIL; | |
1517 | ||
dcbf9037 JB |
1518 | /* Do not allow a scalar (reg+index) to parse as a register. */ |
1519 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1520 | { | |
1521 | first_error (_("register operand expected, but got scalar")); | |
1522 | return FAIL; | |
1523 | } | |
1524 | ||
1525 | if (vectype) | |
1526 | *vectype = atype.eltype; | |
1527 | ||
1528 | *ccp = str; | |
1529 | ||
1530 | return reg; | |
1531 | } | |
1532 | ||
1533 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1534 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1535 | ||
5287ad62 JB |
1536 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1537 | have enough information to be able to do a good job bounds-checking. So, we | |
1538 | just do easy checks here, and do further checks later. */ | |
1539 | ||
1540 | static int | |
dcbf9037 | 1541 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1542 | { |
dcbf9037 | 1543 | int reg; |
5287ad62 | 1544 | char *str = *ccp; |
dcbf9037 | 1545 | struct neon_typed_alias atype; |
5f4273c7 | 1546 | |
dcbf9037 | 1547 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1548 | |
dcbf9037 | 1549 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1550 | return FAIL; |
5f4273c7 | 1551 | |
dcbf9037 | 1552 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1553 | { |
dcbf9037 | 1554 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1555 | return FAIL; |
1556 | } | |
dcbf9037 | 1557 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1558 | { |
dcbf9037 | 1559 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1560 | return FAIL; |
1561 | } | |
5f4273c7 | 1562 | |
dcbf9037 JB |
1563 | if (type) |
1564 | *type = atype.eltype; | |
5f4273c7 | 1565 | |
5287ad62 | 1566 | *ccp = str; |
5f4273c7 | 1567 | |
dcbf9037 | 1568 | return reg * 16 + atype.index; |
5287ad62 JB |
1569 | } |
1570 | ||
c19d1205 | 1571 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1572 | |
c19d1205 ZW |
1573 | static long |
1574 | parse_reg_list (char ** strp) | |
1575 | { | |
1576 | char * str = * strp; | |
1577 | long range = 0; | |
1578 | int another_range; | |
a737bd4d | 1579 | |
c19d1205 ZW |
1580 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1581 | do | |
6057a28f | 1582 | { |
c19d1205 | 1583 | another_range = 0; |
a737bd4d | 1584 | |
c19d1205 ZW |
1585 | if (*str == '{') |
1586 | { | |
1587 | int in_range = 0; | |
1588 | int cur_reg = -1; | |
a737bd4d | 1589 | |
c19d1205 ZW |
1590 | str++; |
1591 | do | |
1592 | { | |
1593 | int reg; | |
6057a28f | 1594 | |
dcbf9037 | 1595 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1596 | { |
dcbf9037 | 1597 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1598 | return FAIL; |
1599 | } | |
a737bd4d | 1600 | |
c19d1205 ZW |
1601 | if (in_range) |
1602 | { | |
1603 | int i; | |
a737bd4d | 1604 | |
c19d1205 ZW |
1605 | if (reg <= cur_reg) |
1606 | { | |
dcbf9037 | 1607 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1608 | return FAIL; |
1609 | } | |
40a18ebd | 1610 | |
c19d1205 ZW |
1611 | for (i = cur_reg + 1; i < reg; i++) |
1612 | { | |
1613 | if (range & (1 << i)) | |
1614 | as_tsktsk | |
1615 | (_("Warning: duplicated register (r%d) in register list"), | |
1616 | i); | |
1617 | else | |
1618 | range |= 1 << i; | |
1619 | } | |
1620 | in_range = 0; | |
1621 | } | |
a737bd4d | 1622 | |
c19d1205 ZW |
1623 | if (range & (1 << reg)) |
1624 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1625 | reg); | |
1626 | else if (reg <= cur_reg) | |
1627 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1628 | |
c19d1205 ZW |
1629 | range |= 1 << reg; |
1630 | cur_reg = reg; | |
1631 | } | |
1632 | while (skip_past_comma (&str) != FAIL | |
1633 | || (in_range = 1, *str++ == '-')); | |
1634 | str--; | |
a737bd4d | 1635 | |
c19d1205 ZW |
1636 | if (*str++ != '}') |
1637 | { | |
dcbf9037 | 1638 | first_error (_("missing `}'")); |
c19d1205 ZW |
1639 | return FAIL; |
1640 | } | |
1641 | } | |
1642 | else | |
1643 | { | |
91d6fa6a | 1644 | expressionS exp; |
40a18ebd | 1645 | |
91d6fa6a | 1646 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1647 | return FAIL; |
40a18ebd | 1648 | |
91d6fa6a | 1649 | if (exp.X_op == O_constant) |
c19d1205 | 1650 | { |
91d6fa6a NC |
1651 | if (exp.X_add_number |
1652 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1653 | { |
1654 | inst.error = _("invalid register mask"); | |
1655 | return FAIL; | |
1656 | } | |
a737bd4d | 1657 | |
91d6fa6a | 1658 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1659 | { |
91d6fa6a | 1660 | int regno = range & exp.X_add_number; |
a737bd4d | 1661 | |
c19d1205 ZW |
1662 | regno &= -regno; |
1663 | regno = (1 << regno) - 1; | |
1664 | as_tsktsk | |
1665 | (_("Warning: duplicated register (r%d) in register list"), | |
1666 | regno); | |
1667 | } | |
a737bd4d | 1668 | |
91d6fa6a | 1669 | range |= exp.X_add_number; |
c19d1205 ZW |
1670 | } |
1671 | else | |
1672 | { | |
1673 | if (inst.reloc.type != 0) | |
1674 | { | |
1675 | inst.error = _("expression too complex"); | |
1676 | return FAIL; | |
1677 | } | |
a737bd4d | 1678 | |
91d6fa6a | 1679 | memcpy (&inst.reloc.exp, &exp, sizeof (expressionS)); |
c19d1205 ZW |
1680 | inst.reloc.type = BFD_RELOC_ARM_MULTI; |
1681 | inst.reloc.pc_rel = 0; | |
1682 | } | |
1683 | } | |
a737bd4d | 1684 | |
c19d1205 ZW |
1685 | if (*str == '|' || *str == '+') |
1686 | { | |
1687 | str++; | |
1688 | another_range = 1; | |
1689 | } | |
a737bd4d | 1690 | } |
c19d1205 | 1691 | while (another_range); |
a737bd4d | 1692 | |
c19d1205 ZW |
1693 | *strp = str; |
1694 | return range; | |
a737bd4d NC |
1695 | } |
1696 | ||
5287ad62 JB |
1697 | /* Types of registers in a list. */ |
1698 | ||
1699 | enum reg_list_els | |
1700 | { | |
1701 | REGLIST_VFP_S, | |
1702 | REGLIST_VFP_D, | |
1703 | REGLIST_NEON_D | |
1704 | }; | |
1705 | ||
c19d1205 ZW |
1706 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1707 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1708 | register. Parses registers of type ETYPE. |
1709 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1710 | - Q registers can be used to specify pairs of D registers | |
1711 | - { } can be omitted from around a singleton register list | |
1712 | FIXME: This is not implemented, as it would require backtracking in | |
1713 | some cases, e.g.: | |
1714 | vtbl.8 d3,d4,d5 | |
1715 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1716 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1717 | - 32 D registers may be used (also true for VFPv3). |
1718 | FIXME: Types are ignored in these register lists, which is probably a | |
1719 | bug. */ | |
6057a28f | 1720 | |
c19d1205 | 1721 | static int |
037e8744 | 1722 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1723 | { |
037e8744 | 1724 | char *str = *ccp; |
c19d1205 ZW |
1725 | int base_reg; |
1726 | int new_base; | |
21d799b5 | 1727 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1728 | int max_regs = 0; |
c19d1205 ZW |
1729 | int count = 0; |
1730 | int warned = 0; | |
1731 | unsigned long mask = 0; | |
a737bd4d | 1732 | int i; |
6057a28f | 1733 | |
037e8744 | 1734 | if (*str != '{') |
5287ad62 JB |
1735 | { |
1736 | inst.error = _("expecting {"); | |
1737 | return FAIL; | |
1738 | } | |
6057a28f | 1739 | |
037e8744 | 1740 | str++; |
6057a28f | 1741 | |
5287ad62 | 1742 | switch (etype) |
c19d1205 | 1743 | { |
5287ad62 | 1744 | case REGLIST_VFP_S: |
c19d1205 ZW |
1745 | regtype = REG_TYPE_VFS; |
1746 | max_regs = 32; | |
5287ad62 | 1747 | break; |
5f4273c7 | 1748 | |
5287ad62 JB |
1749 | case REGLIST_VFP_D: |
1750 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1751 | break; |
5f4273c7 | 1752 | |
b7fc2769 JB |
1753 | case REGLIST_NEON_D: |
1754 | regtype = REG_TYPE_NDQ; | |
1755 | break; | |
1756 | } | |
1757 | ||
1758 | if (etype != REGLIST_VFP_S) | |
1759 | { | |
b1cc4aeb PB |
1760 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1761 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
5287ad62 JB |
1762 | { |
1763 | max_regs = 32; | |
1764 | if (thumb_mode) | |
1765 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 1766 | fpu_vfp_ext_d32); |
5287ad62 JB |
1767 | else |
1768 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 1769 | fpu_vfp_ext_d32); |
5287ad62 JB |
1770 | } |
1771 | else | |
1772 | max_regs = 16; | |
c19d1205 | 1773 | } |
6057a28f | 1774 | |
c19d1205 | 1775 | base_reg = max_regs; |
a737bd4d | 1776 | |
c19d1205 ZW |
1777 | do |
1778 | { | |
5287ad62 | 1779 | int setmask = 1, addregs = 1; |
dcbf9037 | 1780 | |
037e8744 | 1781 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1782 | |
c19d1205 | 1783 | if (new_base == FAIL) |
a737bd4d | 1784 | { |
dcbf9037 | 1785 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1786 | return FAIL; |
1787 | } | |
5f4273c7 | 1788 | |
b7fc2769 JB |
1789 | if (new_base >= max_regs) |
1790 | { | |
1791 | first_error (_("register out of range in list")); | |
1792 | return FAIL; | |
1793 | } | |
5f4273c7 | 1794 | |
5287ad62 JB |
1795 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1796 | if (regtype == REG_TYPE_NQ) | |
1797 | { | |
1798 | setmask = 3; | |
1799 | addregs = 2; | |
1800 | } | |
1801 | ||
c19d1205 ZW |
1802 | if (new_base < base_reg) |
1803 | base_reg = new_base; | |
a737bd4d | 1804 | |
5287ad62 | 1805 | if (mask & (setmask << new_base)) |
c19d1205 | 1806 | { |
dcbf9037 | 1807 | first_error (_("invalid register list")); |
c19d1205 | 1808 | return FAIL; |
a737bd4d | 1809 | } |
a737bd4d | 1810 | |
c19d1205 ZW |
1811 | if ((mask >> new_base) != 0 && ! warned) |
1812 | { | |
1813 | as_tsktsk (_("register list not in ascending order")); | |
1814 | warned = 1; | |
1815 | } | |
0bbf2aa4 | 1816 | |
5287ad62 JB |
1817 | mask |= setmask << new_base; |
1818 | count += addregs; | |
0bbf2aa4 | 1819 | |
037e8744 | 1820 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1821 | { |
1822 | int high_range; | |
0bbf2aa4 | 1823 | |
037e8744 | 1824 | str++; |
0bbf2aa4 | 1825 | |
037e8744 | 1826 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1827 | == FAIL) |
c19d1205 ZW |
1828 | { |
1829 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1830 | return FAIL; | |
1831 | } | |
0bbf2aa4 | 1832 | |
b7fc2769 JB |
1833 | if (high_range >= max_regs) |
1834 | { | |
1835 | first_error (_("register out of range in list")); | |
1836 | return FAIL; | |
1837 | } | |
1838 | ||
5287ad62 JB |
1839 | if (regtype == REG_TYPE_NQ) |
1840 | high_range = high_range + 1; | |
1841 | ||
c19d1205 ZW |
1842 | if (high_range <= new_base) |
1843 | { | |
1844 | inst.error = _("register range not in ascending order"); | |
1845 | return FAIL; | |
1846 | } | |
0bbf2aa4 | 1847 | |
5287ad62 | 1848 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1849 | { |
5287ad62 | 1850 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1851 | { |
c19d1205 ZW |
1852 | inst.error = _("invalid register list"); |
1853 | return FAIL; | |
0bbf2aa4 | 1854 | } |
c19d1205 | 1855 | |
5287ad62 JB |
1856 | mask |= setmask << new_base; |
1857 | count += addregs; | |
0bbf2aa4 | 1858 | } |
0bbf2aa4 | 1859 | } |
0bbf2aa4 | 1860 | } |
037e8744 | 1861 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1862 | |
037e8744 | 1863 | str++; |
0bbf2aa4 | 1864 | |
c19d1205 ZW |
1865 | /* Sanity check -- should have raised a parse error above. */ |
1866 | if (count == 0 || count > max_regs) | |
1867 | abort (); | |
1868 | ||
1869 | *pbase = base_reg; | |
1870 | ||
1871 | /* Final test -- the registers must be consecutive. */ | |
1872 | mask >>= base_reg; | |
1873 | for (i = 0; i < count; i++) | |
1874 | { | |
1875 | if ((mask & (1u << i)) == 0) | |
1876 | { | |
1877 | inst.error = _("non-contiguous register range"); | |
1878 | return FAIL; | |
1879 | } | |
1880 | } | |
1881 | ||
037e8744 JB |
1882 | *ccp = str; |
1883 | ||
c19d1205 | 1884 | return count; |
b99bd4ef NC |
1885 | } |
1886 | ||
dcbf9037 JB |
1887 | /* True if two alias types are the same. */ |
1888 | ||
c921be7d | 1889 | static bfd_boolean |
dcbf9037 JB |
1890 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1891 | { | |
1892 | if (!a && !b) | |
c921be7d | 1893 | return TRUE; |
5f4273c7 | 1894 | |
dcbf9037 | 1895 | if (!a || !b) |
c921be7d | 1896 | return FALSE; |
dcbf9037 JB |
1897 | |
1898 | if (a->defined != b->defined) | |
c921be7d | 1899 | return FALSE; |
5f4273c7 | 1900 | |
dcbf9037 JB |
1901 | if ((a->defined & NTA_HASTYPE) != 0 |
1902 | && (a->eltype.type != b->eltype.type | |
1903 | || a->eltype.size != b->eltype.size)) | |
c921be7d | 1904 | return FALSE; |
dcbf9037 JB |
1905 | |
1906 | if ((a->defined & NTA_HASINDEX) != 0 | |
1907 | && (a->index != b->index)) | |
c921be7d | 1908 | return FALSE; |
5f4273c7 | 1909 | |
c921be7d | 1910 | return TRUE; |
dcbf9037 JB |
1911 | } |
1912 | ||
5287ad62 JB |
1913 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1914 | The base register is put in *PBASE. | |
dcbf9037 | 1915 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1916 | the return value. |
1917 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1918 | Bits [6:5] encode the list length (minus one). |
1919 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1920 | |
5287ad62 | 1921 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1922 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1923 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1924 | ||
1925 | static int | |
dcbf9037 JB |
1926 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1927 | struct neon_type_el *eltype) | |
5287ad62 JB |
1928 | { |
1929 | char *ptr = *str; | |
1930 | int base_reg = -1; | |
1931 | int reg_incr = -1; | |
1932 | int count = 0; | |
1933 | int lane = -1; | |
1934 | int leading_brace = 0; | |
1935 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
20203fb9 NC |
1936 | const char *const incr_error = _("register stride must be 1 or 2"); |
1937 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 1938 | struct neon_typed_alias firsttype; |
5f4273c7 | 1939 | |
5287ad62 JB |
1940 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1941 | leading_brace = 1; | |
5f4273c7 | 1942 | |
5287ad62 JB |
1943 | do |
1944 | { | |
dcbf9037 JB |
1945 | struct neon_typed_alias atype; |
1946 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1947 | ||
5287ad62 JB |
1948 | if (getreg == FAIL) |
1949 | { | |
dcbf9037 | 1950 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1951 | return FAIL; |
1952 | } | |
5f4273c7 | 1953 | |
5287ad62 JB |
1954 | if (base_reg == -1) |
1955 | { | |
1956 | base_reg = getreg; | |
1957 | if (rtype == REG_TYPE_NQ) | |
1958 | { | |
1959 | reg_incr = 1; | |
5287ad62 | 1960 | } |
dcbf9037 | 1961 | firsttype = atype; |
5287ad62 JB |
1962 | } |
1963 | else if (reg_incr == -1) | |
1964 | { | |
1965 | reg_incr = getreg - base_reg; | |
1966 | if (reg_incr < 1 || reg_incr > 2) | |
1967 | { | |
dcbf9037 | 1968 | first_error (_(incr_error)); |
5287ad62 JB |
1969 | return FAIL; |
1970 | } | |
1971 | } | |
1972 | else if (getreg != base_reg + reg_incr * count) | |
1973 | { | |
dcbf9037 JB |
1974 | first_error (_(incr_error)); |
1975 | return FAIL; | |
1976 | } | |
1977 | ||
c921be7d | 1978 | if (! neon_alias_types_same (&atype, &firsttype)) |
dcbf9037 JB |
1979 | { |
1980 | first_error (_(type_error)); | |
5287ad62 JB |
1981 | return FAIL; |
1982 | } | |
5f4273c7 | 1983 | |
5287ad62 JB |
1984 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
1985 | modes. */ | |
1986 | if (ptr[0] == '-') | |
1987 | { | |
dcbf9037 | 1988 | struct neon_typed_alias htype; |
5287ad62 JB |
1989 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1990 | if (lane == -1) | |
1991 | lane = NEON_INTERLEAVE_LANES; | |
1992 | else if (lane != NEON_INTERLEAVE_LANES) | |
1993 | { | |
dcbf9037 | 1994 | first_error (_(type_error)); |
5287ad62 JB |
1995 | return FAIL; |
1996 | } | |
1997 | if (reg_incr == -1) | |
1998 | reg_incr = 1; | |
1999 | else if (reg_incr != 1) | |
2000 | { | |
dcbf9037 | 2001 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
2002 | return FAIL; |
2003 | } | |
2004 | ptr++; | |
dcbf9037 | 2005 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
2006 | if (hireg == FAIL) |
2007 | { | |
dcbf9037 JB |
2008 | first_error (_(reg_expected_msgs[rtype])); |
2009 | return FAIL; | |
2010 | } | |
c921be7d | 2011 | if (! neon_alias_types_same (&htype, &firsttype)) |
dcbf9037 JB |
2012 | { |
2013 | first_error (_(type_error)); | |
5287ad62 JB |
2014 | return FAIL; |
2015 | } | |
2016 | count += hireg + dregs - getreg; | |
2017 | continue; | |
2018 | } | |
5f4273c7 | 2019 | |
5287ad62 JB |
2020 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2021 | if (rtype == REG_TYPE_NQ) | |
2022 | { | |
2023 | count += 2; | |
2024 | continue; | |
2025 | } | |
5f4273c7 | 2026 | |
dcbf9037 | 2027 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 2028 | { |
dcbf9037 JB |
2029 | if (lane == -1) |
2030 | lane = atype.index; | |
2031 | else if (lane != atype.index) | |
5287ad62 | 2032 | { |
dcbf9037 JB |
2033 | first_error (_(type_error)); |
2034 | return FAIL; | |
5287ad62 JB |
2035 | } |
2036 | } | |
2037 | else if (lane == -1) | |
2038 | lane = NEON_INTERLEAVE_LANES; | |
2039 | else if (lane != NEON_INTERLEAVE_LANES) | |
2040 | { | |
dcbf9037 | 2041 | first_error (_(type_error)); |
5287ad62 JB |
2042 | return FAIL; |
2043 | } | |
2044 | count++; | |
2045 | } | |
2046 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2047 | |
5287ad62 JB |
2048 | /* No lane set by [x]. We must be interleaving structures. */ |
2049 | if (lane == -1) | |
2050 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2051 | |
5287ad62 JB |
2052 | /* Sanity check. */ |
2053 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
2054 | || (count > 1 && reg_incr == -1)) | |
2055 | { | |
dcbf9037 | 2056 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2057 | return FAIL; |
2058 | } | |
2059 | ||
2060 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2061 | { | |
dcbf9037 | 2062 | first_error (_("expected }")); |
5287ad62 JB |
2063 | return FAIL; |
2064 | } | |
5f4273c7 | 2065 | |
5287ad62 JB |
2066 | if (reg_incr == -1) |
2067 | reg_incr = 1; | |
2068 | ||
dcbf9037 JB |
2069 | if (eltype) |
2070 | *eltype = firsttype.eltype; | |
2071 | ||
5287ad62 JB |
2072 | *pbase = base_reg; |
2073 | *str = ptr; | |
5f4273c7 | 2074 | |
5287ad62 JB |
2075 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2076 | } | |
2077 | ||
c19d1205 ZW |
2078 | /* Parse an explicit relocation suffix on an expression. This is |
2079 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2080 | arm_reloc_hsh contains no entries, so this function can only | |
2081 | succeed if there is no () after the word. Returns -1 on error, | |
2082 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
3da1d841 | 2083 | |
c19d1205 ZW |
2084 | static int |
2085 | parse_reloc (char **str) | |
b99bd4ef | 2086 | { |
c19d1205 ZW |
2087 | struct reloc_entry *r; |
2088 | char *p, *q; | |
b99bd4ef | 2089 | |
c19d1205 ZW |
2090 | if (**str != '(') |
2091 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2092 | |
c19d1205 ZW |
2093 | p = *str + 1; |
2094 | q = p; | |
2095 | ||
2096 | while (*q && *q != ')' && *q != ',') | |
2097 | q++; | |
2098 | if (*q != ')') | |
2099 | return -1; | |
2100 | ||
21d799b5 NC |
2101 | if ((r = (struct reloc_entry *) |
2102 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2103 | return -1; |
2104 | ||
2105 | *str = q + 1; | |
2106 | return r->reloc; | |
b99bd4ef NC |
2107 | } |
2108 | ||
c19d1205 ZW |
2109 | /* Directives: register aliases. */ |
2110 | ||
dcbf9037 | 2111 | static struct reg_entry * |
90ec0d68 | 2112 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2113 | { |
d3ce72d0 | 2114 | struct reg_entry *new_reg; |
c19d1205 | 2115 | const char *name; |
b99bd4ef | 2116 | |
d3ce72d0 | 2117 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2118 | { |
d3ce72d0 | 2119 | if (new_reg->builtin) |
c19d1205 | 2120 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2121 | |
c19d1205 ZW |
2122 | /* Only warn about a redefinition if it's not defined as the |
2123 | same register. */ | |
d3ce72d0 | 2124 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2125 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2126 | |
d929913e | 2127 | return NULL; |
c19d1205 | 2128 | } |
b99bd4ef | 2129 | |
c19d1205 | 2130 | name = xstrdup (str); |
d3ce72d0 | 2131 | new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry)); |
b99bd4ef | 2132 | |
d3ce72d0 NC |
2133 | new_reg->name = name; |
2134 | new_reg->number = number; | |
2135 | new_reg->type = type; | |
2136 | new_reg->builtin = FALSE; | |
2137 | new_reg->neon = NULL; | |
b99bd4ef | 2138 | |
d3ce72d0 | 2139 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2140 | abort (); |
5f4273c7 | 2141 | |
d3ce72d0 | 2142 | return new_reg; |
dcbf9037 JB |
2143 | } |
2144 | ||
2145 | static void | |
2146 | insert_neon_reg_alias (char *str, int number, int type, | |
2147 | struct neon_typed_alias *atype) | |
2148 | { | |
2149 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2150 | |
dcbf9037 JB |
2151 | if (!reg) |
2152 | { | |
2153 | first_error (_("attempt to redefine typed alias")); | |
2154 | return; | |
2155 | } | |
5f4273c7 | 2156 | |
dcbf9037 JB |
2157 | if (atype) |
2158 | { | |
21d799b5 NC |
2159 | reg->neon = (struct neon_typed_alias *) |
2160 | xmalloc (sizeof (struct neon_typed_alias)); | |
dcbf9037 JB |
2161 | *reg->neon = *atype; |
2162 | } | |
c19d1205 | 2163 | } |
b99bd4ef | 2164 | |
c19d1205 | 2165 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2166 | |
c19d1205 | 2167 | new_register_name .req existing_register_name |
b99bd4ef | 2168 | |
c19d1205 | 2169 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2170 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2171 | |
d929913e | 2172 | static bfd_boolean |
c19d1205 ZW |
2173 | create_register_alias (char * newname, char *p) |
2174 | { | |
2175 | struct reg_entry *old; | |
2176 | char *oldname, *nbuf; | |
2177 | size_t nlen; | |
b99bd4ef | 2178 | |
c19d1205 ZW |
2179 | /* The input scrubber ensures that whitespace after the mnemonic is |
2180 | collapsed to single spaces. */ | |
2181 | oldname = p; | |
2182 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2183 | return FALSE; |
b99bd4ef | 2184 | |
c19d1205 ZW |
2185 | oldname += 6; |
2186 | if (*oldname == '\0') | |
d929913e | 2187 | return FALSE; |
b99bd4ef | 2188 | |
21d799b5 | 2189 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2190 | if (!old) |
b99bd4ef | 2191 | { |
c19d1205 | 2192 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2193 | return TRUE; |
b99bd4ef NC |
2194 | } |
2195 | ||
c19d1205 ZW |
2196 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2197 | the desired alias name, and p points to its end. If not, then | |
2198 | the desired alias name is in the global original_case_string. */ | |
2199 | #ifdef TC_CASE_SENSITIVE | |
2200 | nlen = p - newname; | |
2201 | #else | |
2202 | newname = original_case_string; | |
2203 | nlen = strlen (newname); | |
2204 | #endif | |
b99bd4ef | 2205 | |
21d799b5 | 2206 | nbuf = (char *) alloca (nlen + 1); |
c19d1205 ZW |
2207 | memcpy (nbuf, newname, nlen); |
2208 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2209 | |
c19d1205 ZW |
2210 | /* Create aliases under the new name as stated; an all-lowercase |
2211 | version of the new name; and an all-uppercase version of the new | |
2212 | name. */ | |
d929913e NC |
2213 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2214 | { | |
2215 | for (p = nbuf; *p; p++) | |
2216 | *p = TOUPPER (*p); | |
c19d1205 | 2217 | |
d929913e NC |
2218 | if (strncmp (nbuf, newname, nlen)) |
2219 | { | |
2220 | /* If this attempt to create an additional alias fails, do not bother | |
2221 | trying to create the all-lower case alias. We will fail and issue | |
2222 | a second, duplicate error message. This situation arises when the | |
2223 | programmer does something like: | |
2224 | foo .req r0 | |
2225 | Foo .req r1 | |
2226 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2227 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2228 | first .req. */ |
2229 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
2230 | return TRUE; | |
2231 | } | |
c19d1205 | 2232 | |
d929913e NC |
2233 | for (p = nbuf; *p; p++) |
2234 | *p = TOLOWER (*p); | |
c19d1205 | 2235 | |
d929913e NC |
2236 | if (strncmp (nbuf, newname, nlen)) |
2237 | insert_reg_alias (nbuf, old->number, old->type); | |
2238 | } | |
c19d1205 | 2239 | |
d929913e | 2240 | return TRUE; |
b99bd4ef NC |
2241 | } |
2242 | ||
dcbf9037 JB |
2243 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2244 | X .dn d5.s32[1] | |
2245 | Y .qn 6.s16 | |
2246 | Z .dn d7 | |
2247 | T .dn Z[0] | |
2248 | These typed registers can be used instead of the types specified after the | |
2249 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2250 | specified directly, e.g.: | |
5f4273c7 | 2251 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2252 | |
c921be7d | 2253 | static bfd_boolean |
dcbf9037 JB |
2254 | create_neon_reg_alias (char *newname, char *p) |
2255 | { | |
2256 | enum arm_reg_type basetype; | |
2257 | struct reg_entry *basereg; | |
2258 | struct reg_entry mybasereg; | |
2259 | struct neon_type ntype; | |
2260 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2261 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2262 | int namelen; |
5f4273c7 | 2263 | |
dcbf9037 JB |
2264 | typeinfo.defined = 0; |
2265 | typeinfo.eltype.type = NT_invtype; | |
2266 | typeinfo.eltype.size = -1; | |
2267 | typeinfo.index = -1; | |
5f4273c7 | 2268 | |
dcbf9037 | 2269 | nameend = p; |
5f4273c7 | 2270 | |
dcbf9037 JB |
2271 | if (strncmp (p, " .dn ", 5) == 0) |
2272 | basetype = REG_TYPE_VFD; | |
2273 | else if (strncmp (p, " .qn ", 5) == 0) | |
2274 | basetype = REG_TYPE_NQ; | |
2275 | else | |
c921be7d | 2276 | return FALSE; |
5f4273c7 | 2277 | |
dcbf9037 | 2278 | p += 5; |
5f4273c7 | 2279 | |
dcbf9037 | 2280 | if (*p == '\0') |
c921be7d | 2281 | return FALSE; |
5f4273c7 | 2282 | |
dcbf9037 JB |
2283 | basereg = arm_reg_parse_multi (&p); |
2284 | ||
2285 | if (basereg && basereg->type != basetype) | |
2286 | { | |
2287 | as_bad (_("bad type for register")); | |
c921be7d | 2288 | return FALSE; |
dcbf9037 JB |
2289 | } |
2290 | ||
2291 | if (basereg == NULL) | |
2292 | { | |
2293 | expressionS exp; | |
2294 | /* Try parsing as an integer. */ | |
2295 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2296 | if (exp.X_op != O_constant) | |
2297 | { | |
2298 | as_bad (_("expression must be constant")); | |
c921be7d | 2299 | return FALSE; |
dcbf9037 JB |
2300 | } |
2301 | basereg = &mybasereg; | |
2302 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2303 | : exp.X_add_number; | |
2304 | basereg->neon = 0; | |
2305 | } | |
2306 | ||
2307 | if (basereg->neon) | |
2308 | typeinfo = *basereg->neon; | |
2309 | ||
2310 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2311 | { | |
2312 | /* We got a type. */ | |
2313 | if (typeinfo.defined & NTA_HASTYPE) | |
2314 | { | |
2315 | as_bad (_("can't redefine the type of a register alias")); | |
c921be7d | 2316 | return FALSE; |
dcbf9037 | 2317 | } |
5f4273c7 | 2318 | |
dcbf9037 JB |
2319 | typeinfo.defined |= NTA_HASTYPE; |
2320 | if (ntype.elems != 1) | |
2321 | { | |
2322 | as_bad (_("you must specify a single type only")); | |
c921be7d | 2323 | return FALSE; |
dcbf9037 JB |
2324 | } |
2325 | typeinfo.eltype = ntype.el[0]; | |
2326 | } | |
5f4273c7 | 2327 | |
dcbf9037 JB |
2328 | if (skip_past_char (&p, '[') == SUCCESS) |
2329 | { | |
2330 | expressionS exp; | |
2331 | /* We got a scalar index. */ | |
5f4273c7 | 2332 | |
dcbf9037 JB |
2333 | if (typeinfo.defined & NTA_HASINDEX) |
2334 | { | |
2335 | as_bad (_("can't redefine the index of a scalar alias")); | |
c921be7d | 2336 | return FALSE; |
dcbf9037 | 2337 | } |
5f4273c7 | 2338 | |
dcbf9037 | 2339 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2340 | |
dcbf9037 JB |
2341 | if (exp.X_op != O_constant) |
2342 | { | |
2343 | as_bad (_("scalar index must be constant")); | |
c921be7d | 2344 | return FALSE; |
dcbf9037 | 2345 | } |
5f4273c7 | 2346 | |
dcbf9037 JB |
2347 | typeinfo.defined |= NTA_HASINDEX; |
2348 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2349 | |
dcbf9037 JB |
2350 | if (skip_past_char (&p, ']') == FAIL) |
2351 | { | |
2352 | as_bad (_("expecting ]")); | |
c921be7d | 2353 | return FALSE; |
dcbf9037 JB |
2354 | } |
2355 | } | |
2356 | ||
15735687 NS |
2357 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2358 | the desired alias name, and p points to its end. If not, then | |
2359 | the desired alias name is in the global original_case_string. */ | |
2360 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2361 | namelen = nameend - newname; |
15735687 NS |
2362 | #else |
2363 | newname = original_case_string; | |
2364 | namelen = strlen (newname); | |
2365 | #endif | |
2366 | ||
21d799b5 | 2367 | namebuf = (char *) alloca (namelen + 1); |
dcbf9037 JB |
2368 | strncpy (namebuf, newname, namelen); |
2369 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2370 | |
dcbf9037 JB |
2371 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
2372 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2373 | |
dcbf9037 JB |
2374 | /* Insert name in all uppercase. */ |
2375 | for (p = namebuf; *p; p++) | |
2376 | *p = TOUPPER (*p); | |
5f4273c7 | 2377 | |
dcbf9037 JB |
2378 | if (strncmp (namebuf, newname, namelen)) |
2379 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2380 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2381 | |
dcbf9037 JB |
2382 | /* Insert name in all lowercase. */ |
2383 | for (p = namebuf; *p; p++) | |
2384 | *p = TOLOWER (*p); | |
5f4273c7 | 2385 | |
dcbf9037 JB |
2386 | if (strncmp (namebuf, newname, namelen)) |
2387 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2388 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2389 | |
c921be7d | 2390 | return TRUE; |
dcbf9037 JB |
2391 | } |
2392 | ||
c19d1205 ZW |
2393 | /* Should never be called, as .req goes between the alias and the |
2394 | register name, not at the beginning of the line. */ | |
c921be7d | 2395 | |
b99bd4ef | 2396 | static void |
c19d1205 | 2397 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2398 | { |
c19d1205 ZW |
2399 | as_bad (_("invalid syntax for .req directive")); |
2400 | } | |
b99bd4ef | 2401 | |
dcbf9037 JB |
2402 | static void |
2403 | s_dn (int a ATTRIBUTE_UNUSED) | |
2404 | { | |
2405 | as_bad (_("invalid syntax for .dn directive")); | |
2406 | } | |
2407 | ||
2408 | static void | |
2409 | s_qn (int a ATTRIBUTE_UNUSED) | |
2410 | { | |
2411 | as_bad (_("invalid syntax for .qn directive")); | |
2412 | } | |
2413 | ||
c19d1205 ZW |
2414 | /* The .unreq directive deletes an alias which was previously defined |
2415 | by .req. For example: | |
b99bd4ef | 2416 | |
c19d1205 ZW |
2417 | my_alias .req r11 |
2418 | .unreq my_alias */ | |
b99bd4ef NC |
2419 | |
2420 | static void | |
c19d1205 | 2421 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2422 | { |
c19d1205 ZW |
2423 | char * name; |
2424 | char saved_char; | |
b99bd4ef | 2425 | |
c19d1205 ZW |
2426 | name = input_line_pointer; |
2427 | ||
2428 | while (*input_line_pointer != 0 | |
2429 | && *input_line_pointer != ' ' | |
2430 | && *input_line_pointer != '\n') | |
2431 | ++input_line_pointer; | |
2432 | ||
2433 | saved_char = *input_line_pointer; | |
2434 | *input_line_pointer = 0; | |
2435 | ||
2436 | if (!*name) | |
2437 | as_bad (_("invalid syntax for .unreq directive")); | |
2438 | else | |
2439 | { | |
21d799b5 NC |
2440 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
2441 | name); | |
c19d1205 ZW |
2442 | |
2443 | if (!reg) | |
2444 | as_bad (_("unknown register alias '%s'"), name); | |
2445 | else if (reg->builtin) | |
a1727c1a | 2446 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2447 | name); |
2448 | else | |
2449 | { | |
d929913e NC |
2450 | char * p; |
2451 | char * nbuf; | |
2452 | ||
db0bc284 | 2453 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2454 | free ((char *) reg->name); |
dcbf9037 JB |
2455 | if (reg->neon) |
2456 | free (reg->neon); | |
c19d1205 | 2457 | free (reg); |
d929913e NC |
2458 | |
2459 | /* Also locate the all upper case and all lower case versions. | |
2460 | Do not complain if we cannot find one or the other as it | |
2461 | was probably deleted above. */ | |
5f4273c7 | 2462 | |
d929913e NC |
2463 | nbuf = strdup (name); |
2464 | for (p = nbuf; *p; p++) | |
2465 | *p = TOUPPER (*p); | |
21d799b5 | 2466 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2467 | if (reg) |
2468 | { | |
db0bc284 | 2469 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2470 | free ((char *) reg->name); |
2471 | if (reg->neon) | |
2472 | free (reg->neon); | |
2473 | free (reg); | |
2474 | } | |
2475 | ||
2476 | for (p = nbuf; *p; p++) | |
2477 | *p = TOLOWER (*p); | |
21d799b5 | 2478 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2479 | if (reg) |
2480 | { | |
db0bc284 | 2481 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2482 | free ((char *) reg->name); |
2483 | if (reg->neon) | |
2484 | free (reg->neon); | |
2485 | free (reg); | |
2486 | } | |
2487 | ||
2488 | free (nbuf); | |
c19d1205 ZW |
2489 | } |
2490 | } | |
b99bd4ef | 2491 | |
c19d1205 | 2492 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2493 | demand_empty_rest_of_line (); |
2494 | } | |
2495 | ||
c19d1205 ZW |
2496 | /* Directives: Instruction set selection. */ |
2497 | ||
2498 | #ifdef OBJ_ELF | |
2499 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2500 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2501 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2502 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2503 | ||
cd000bff DJ |
2504 | /* Create a new mapping symbol for the transition to STATE. */ |
2505 | ||
2506 | static void | |
2507 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2508 | { |
a737bd4d | 2509 | symbolS * symbolP; |
c19d1205 ZW |
2510 | const char * symname; |
2511 | int type; | |
b99bd4ef | 2512 | |
c19d1205 | 2513 | switch (state) |
b99bd4ef | 2514 | { |
c19d1205 ZW |
2515 | case MAP_DATA: |
2516 | symname = "$d"; | |
2517 | type = BSF_NO_FLAGS; | |
2518 | break; | |
2519 | case MAP_ARM: | |
2520 | symname = "$a"; | |
2521 | type = BSF_NO_FLAGS; | |
2522 | break; | |
2523 | case MAP_THUMB: | |
2524 | symname = "$t"; | |
2525 | type = BSF_NO_FLAGS; | |
2526 | break; | |
c19d1205 ZW |
2527 | default: |
2528 | abort (); | |
2529 | } | |
2530 | ||
cd000bff | 2531 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2532 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2533 | ||
2534 | switch (state) | |
2535 | { | |
2536 | case MAP_ARM: | |
2537 | THUMB_SET_FUNC (symbolP, 0); | |
2538 | ARM_SET_THUMB (symbolP, 0); | |
2539 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2540 | break; | |
2541 | ||
2542 | case MAP_THUMB: | |
2543 | THUMB_SET_FUNC (symbolP, 1); | |
2544 | ARM_SET_THUMB (symbolP, 1); | |
2545 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2546 | break; | |
2547 | ||
2548 | case MAP_DATA: | |
2549 | default: | |
cd000bff DJ |
2550 | break; |
2551 | } | |
2552 | ||
2553 | /* Save the mapping symbols for future reference. Also check that | |
2554 | we do not place two mapping symbols at the same offset within a | |
2555 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2556 | check_mapping_symbols. |
2557 | ||
2558 | If .fill or other data filling directive generates zero sized data, | |
2559 | the mapping symbol for the following code will have the same value | |
2560 | as the one generated for the data filling directive. In this case, | |
2561 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2562 | if (value == 0) |
2563 | { | |
2de7820f JZ |
2564 | if (frag->tc_frag_data.first_map != NULL) |
2565 | { | |
2566 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2567 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2568 | } | |
cd000bff DJ |
2569 | frag->tc_frag_data.first_map = symbolP; |
2570 | } | |
2571 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2572 | { |
2573 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2574 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2575 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2576 | } | |
cd000bff DJ |
2577 | frag->tc_frag_data.last_map = symbolP; |
2578 | } | |
2579 | ||
2580 | /* We must sometimes convert a region marked as code to data during | |
2581 | code alignment, if an odd number of bytes have to be padded. The | |
2582 | code mapping symbol is pushed to an aligned address. */ | |
2583 | ||
2584 | static void | |
2585 | insert_data_mapping_symbol (enum mstate state, | |
2586 | valueT value, fragS *frag, offsetT bytes) | |
2587 | { | |
2588 | /* If there was already a mapping symbol, remove it. */ | |
2589 | if (frag->tc_frag_data.last_map != NULL | |
2590 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2591 | { | |
2592 | symbolS *symp = frag->tc_frag_data.last_map; | |
2593 | ||
2594 | if (value == 0) | |
2595 | { | |
2596 | know (frag->tc_frag_data.first_map == symp); | |
2597 | frag->tc_frag_data.first_map = NULL; | |
2598 | } | |
2599 | frag->tc_frag_data.last_map = NULL; | |
2600 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2601 | } |
cd000bff DJ |
2602 | |
2603 | make_mapping_symbol (MAP_DATA, value, frag); | |
2604 | make_mapping_symbol (state, value + bytes, frag); | |
2605 | } | |
2606 | ||
2607 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2608 | ||
2609 | /* Set the mapping state to STATE. Only call this when about to | |
2610 | emit some STATE bytes to the file. */ | |
2611 | ||
2612 | void | |
2613 | mapping_state (enum mstate state) | |
2614 | { | |
940b5ce0 DJ |
2615 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2616 | ||
cd000bff DJ |
2617 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
2618 | ||
2619 | if (mapstate == state) | |
2620 | /* The mapping symbol has already been emitted. | |
2621 | There is nothing else to do. */ | |
2622 | return; | |
49c62a33 NC |
2623 | |
2624 | if (state == MAP_ARM || state == MAP_THUMB) | |
2625 | /* PR gas/12931 | |
2626 | All ARM instructions require 4-byte alignment. | |
2627 | (Almost) all Thumb instructions require 2-byte alignment. | |
2628 | ||
2629 | When emitting instructions into any section, mark the section | |
2630 | appropriately. | |
2631 | ||
2632 | Some Thumb instructions are alignment-sensitive modulo 4 bytes, | |
2633 | but themselves require 2-byte alignment; this applies to some | |
2634 | PC- relative forms. However, these cases will invovle implicit | |
2635 | literal pool generation or an explicit .align >=2, both of | |
2636 | which will cause the section to me marked with sufficient | |
2637 | alignment. Thus, we don't handle those cases here. */ | |
2638 | record_alignment (now_seg, state == MAP_ARM ? 2 : 1); | |
2639 | ||
2640 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
cd000bff DJ |
2641 | /* This case will be evaluated later in the next else. */ |
2642 | return; | |
2643 | else if (TRANSITION (MAP_UNDEFINED, MAP_ARM) | |
2644 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2645 | { | |
2646 | /* Only add the symbol if the offset is > 0: | |
2647 | if we're at the first frag, check it's size > 0; | |
2648 | if we're not at the first frag, then for sure | |
2649 | the offset is > 0. */ | |
2650 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2651 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2652 | ||
2653 | if (add_symbol) | |
2654 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2655 | } | |
2656 | ||
2657 | mapping_state_2 (state, 0); | |
2658 | #undef TRANSITION | |
2659 | } | |
2660 | ||
2661 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2662 | allocated. Put the mapping symbol that far back. */ | |
2663 | ||
2664 | static void | |
2665 | mapping_state_2 (enum mstate state, int max_chars) | |
2666 | { | |
940b5ce0 DJ |
2667 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2668 | ||
2669 | if (!SEG_NORMAL (now_seg)) | |
2670 | return; | |
2671 | ||
cd000bff DJ |
2672 | if (mapstate == state) |
2673 | /* The mapping symbol has already been emitted. | |
2674 | There is nothing else to do. */ | |
2675 | return; | |
2676 | ||
cd000bff DJ |
2677 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2678 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 ZW |
2679 | } |
2680 | #else | |
d3106081 NS |
2681 | #define mapping_state(x) ((void)0) |
2682 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2683 | #endif |
2684 | ||
2685 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2686 | ||
4343666d | 2687 | #ifdef OBJ_COFF |
c19d1205 ZW |
2688 | static symbolS * |
2689 | find_real_start (symbolS * symbolP) | |
2690 | { | |
2691 | char * real_start; | |
2692 | const char * name = S_GET_NAME (symbolP); | |
2693 | symbolS * new_target; | |
2694 | ||
2695 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2696 | #define STUB_NAME ".real_start_of" | |
2697 | ||
2698 | if (name == NULL) | |
2699 | abort (); | |
2700 | ||
37f6032b ZW |
2701 | /* The compiler may generate BL instructions to local labels because |
2702 | it needs to perform a branch to a far away location. These labels | |
2703 | do not have a corresponding ".real_start_of" label. We check | |
2704 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2705 | the ".real_start_of" convention for nonlocal branches. */ | |
2706 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2707 | return symbolP; |
2708 | ||
37f6032b | 2709 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2710 | new_target = symbol_find (real_start); |
2711 | ||
2712 | if (new_target == NULL) | |
2713 | { | |
bd3ba5d1 | 2714 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2715 | new_target = symbolP; |
2716 | } | |
2717 | ||
c19d1205 ZW |
2718 | return new_target; |
2719 | } | |
4343666d | 2720 | #endif |
c19d1205 ZW |
2721 | |
2722 | static void | |
2723 | opcode_select (int width) | |
2724 | { | |
2725 | switch (width) | |
2726 | { | |
2727 | case 16: | |
2728 | if (! thumb_mode) | |
2729 | { | |
e74cfd16 | 2730 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2731 | as_bad (_("selected processor does not support THUMB opcodes")); |
2732 | ||
2733 | thumb_mode = 1; | |
2734 | /* No need to force the alignment, since we will have been | |
2735 | coming from ARM mode, which is word-aligned. */ | |
2736 | record_alignment (now_seg, 1); | |
2737 | } | |
c19d1205 ZW |
2738 | break; |
2739 | ||
2740 | case 32: | |
2741 | if (thumb_mode) | |
2742 | { | |
e74cfd16 | 2743 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2744 | as_bad (_("selected processor does not support ARM opcodes")); |
2745 | ||
2746 | thumb_mode = 0; | |
2747 | ||
2748 | if (!need_pass_2) | |
2749 | frag_align (2, 0, 0); | |
2750 | ||
2751 | record_alignment (now_seg, 1); | |
2752 | } | |
c19d1205 ZW |
2753 | break; |
2754 | ||
2755 | default: | |
2756 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2757 | } | |
2758 | } | |
2759 | ||
2760 | static void | |
2761 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2762 | { | |
2763 | opcode_select (32); | |
2764 | demand_empty_rest_of_line (); | |
2765 | } | |
2766 | ||
2767 | static void | |
2768 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2769 | { | |
2770 | opcode_select (16); | |
2771 | demand_empty_rest_of_line (); | |
2772 | } | |
2773 | ||
2774 | static void | |
2775 | s_code (int unused ATTRIBUTE_UNUSED) | |
2776 | { | |
2777 | int temp; | |
2778 | ||
2779 | temp = get_absolute_expression (); | |
2780 | switch (temp) | |
2781 | { | |
2782 | case 16: | |
2783 | case 32: | |
2784 | opcode_select (temp); | |
2785 | break; | |
2786 | ||
2787 | default: | |
2788 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2789 | } | |
2790 | } | |
2791 | ||
2792 | static void | |
2793 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2794 | { | |
2795 | /* If we are not already in thumb mode go into it, EVEN if | |
2796 | the target processor does not support thumb instructions. | |
2797 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2798 | to compile interworking support functions even if the | |
2799 | target processor should not support interworking. */ | |
2800 | if (! thumb_mode) | |
2801 | { | |
2802 | thumb_mode = 2; | |
2803 | record_alignment (now_seg, 1); | |
2804 | } | |
2805 | ||
2806 | demand_empty_rest_of_line (); | |
2807 | } | |
2808 | ||
2809 | static void | |
2810 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2811 | { | |
2812 | s_thumb (0); | |
2813 | ||
2814 | /* The following label is the name/address of the start of a Thumb function. | |
2815 | We need to know this for the interworking support. */ | |
2816 | label_is_thumb_function_name = TRUE; | |
2817 | } | |
2818 | ||
2819 | /* Perform a .set directive, but also mark the alias as | |
2820 | being a thumb function. */ | |
2821 | ||
2822 | static void | |
2823 | s_thumb_set (int equiv) | |
2824 | { | |
2825 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2826 | We cannot just call that code as we need to get at the symbol that | |
2827 | is created. */ | |
2828 | char * name; | |
2829 | char delim; | |
2830 | char * end_name; | |
2831 | symbolS * symbolP; | |
2832 | ||
2833 | /* Especial apologies for the random logic: | |
2834 | This just grew, and could be parsed much more simply! | |
2835 | Dean - in haste. */ | |
2836 | name = input_line_pointer; | |
2837 | delim = get_symbol_end (); | |
2838 | end_name = input_line_pointer; | |
2839 | *end_name = delim; | |
2840 | ||
2841 | if (*input_line_pointer != ',') | |
2842 | { | |
2843 | *end_name = 0; | |
2844 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2845 | *end_name = delim; |
2846 | ignore_rest_of_line (); | |
2847 | return; | |
2848 | } | |
2849 | ||
2850 | input_line_pointer++; | |
2851 | *end_name = 0; | |
2852 | ||
2853 | if (name[0] == '.' && name[1] == '\0') | |
2854 | { | |
2855 | /* XXX - this should not happen to .thumb_set. */ | |
2856 | abort (); | |
2857 | } | |
2858 | ||
2859 | if ((symbolP = symbol_find (name)) == NULL | |
2860 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2861 | { | |
2862 | #ifndef NO_LISTING | |
2863 | /* When doing symbol listings, play games with dummy fragments living | |
2864 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2865 | for this symbol. */ |
b99bd4ef NC |
2866 | if (listing & LISTING_SYMBOLS) |
2867 | { | |
2868 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 2869 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2870 | |
2871 | memset (dummy_frag, 0, sizeof (fragS)); | |
2872 | dummy_frag->fr_type = rs_fill; | |
2873 | dummy_frag->line = listing_tail; | |
2874 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2875 | dummy_frag->fr_symbol = symbolP; | |
2876 | } | |
2877 | else | |
2878 | #endif | |
2879 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2880 | ||
2881 | #ifdef OBJ_COFF | |
2882 | /* "set" symbols are local unless otherwise specified. */ | |
2883 | SF_SET_LOCAL (symbolP); | |
2884 | #endif /* OBJ_COFF */ | |
2885 | } /* Make a new symbol. */ | |
2886 | ||
2887 | symbol_table_insert (symbolP); | |
2888 | ||
2889 | * end_name = delim; | |
2890 | ||
2891 | if (equiv | |
2892 | && S_IS_DEFINED (symbolP) | |
2893 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2894 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2895 | ||
2896 | pseudo_set (symbolP); | |
2897 | ||
2898 | demand_empty_rest_of_line (); | |
2899 | ||
c19d1205 | 2900 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2901 | |
2902 | THUMB_SET_FUNC (symbolP, 1); | |
2903 | ARM_SET_THUMB (symbolP, 1); | |
2904 | #if defined OBJ_ELF || defined OBJ_COFF | |
2905 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2906 | #endif | |
2907 | } | |
2908 | ||
c19d1205 | 2909 | /* Directives: Mode selection. */ |
b99bd4ef | 2910 | |
c19d1205 ZW |
2911 | /* .syntax [unified|divided] - choose the new unified syntax |
2912 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2913 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2914 | static void |
c19d1205 | 2915 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2916 | { |
c19d1205 ZW |
2917 | char *name, delim; |
2918 | ||
2919 | name = input_line_pointer; | |
2920 | delim = get_symbol_end (); | |
2921 | ||
2922 | if (!strcasecmp (name, "unified")) | |
2923 | unified_syntax = TRUE; | |
2924 | else if (!strcasecmp (name, "divided")) | |
2925 | unified_syntax = FALSE; | |
2926 | else | |
2927 | { | |
2928 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2929 | return; | |
2930 | } | |
2931 | *input_line_pointer = delim; | |
b99bd4ef NC |
2932 | demand_empty_rest_of_line (); |
2933 | } | |
2934 | ||
c19d1205 ZW |
2935 | /* Directives: sectioning and alignment. */ |
2936 | ||
2937 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2938 | ||
b99bd4ef | 2939 | static void |
c19d1205 | 2940 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2941 | { |
a737bd4d | 2942 | int temp; |
dce323d1 | 2943 | bfd_boolean fill_p; |
c19d1205 ZW |
2944 | long temp_fill; |
2945 | long max_alignment = 15; | |
b99bd4ef NC |
2946 | |
2947 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2948 | if (temp > max_alignment) |
2949 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2950 | else if (temp < 0) | |
b99bd4ef | 2951 | { |
c19d1205 ZW |
2952 | as_bad (_("alignment negative. 0 assumed.")); |
2953 | temp = 0; | |
2954 | } | |
b99bd4ef | 2955 | |
c19d1205 ZW |
2956 | if (*input_line_pointer == ',') |
2957 | { | |
2958 | input_line_pointer++; | |
2959 | temp_fill = get_absolute_expression (); | |
dce323d1 | 2960 | fill_p = TRUE; |
b99bd4ef | 2961 | } |
c19d1205 | 2962 | else |
dce323d1 PB |
2963 | { |
2964 | fill_p = FALSE; | |
2965 | temp_fill = 0; | |
2966 | } | |
b99bd4ef | 2967 | |
c19d1205 ZW |
2968 | if (!temp) |
2969 | temp = 2; | |
b99bd4ef | 2970 | |
c19d1205 ZW |
2971 | /* Only make a frag if we HAVE to. */ |
2972 | if (temp && !need_pass_2) | |
dce323d1 PB |
2973 | { |
2974 | if (!fill_p && subseg_text_p (now_seg)) | |
2975 | frag_align_code (temp, 0); | |
2976 | else | |
2977 | frag_align (temp, (int) temp_fill, 0); | |
2978 | } | |
c19d1205 ZW |
2979 | demand_empty_rest_of_line (); |
2980 | ||
2981 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2982 | } |
2983 | ||
c19d1205 ZW |
2984 | static void |
2985 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2986 | { |
c19d1205 ZW |
2987 | /* We don't support putting frags in the BSS segment, we fake it by |
2988 | marking in_bss, then looking at s_skip for clues. */ | |
2989 | subseg_set (bss_section, 0); | |
2990 | demand_empty_rest_of_line (); | |
cd000bff DJ |
2991 | |
2992 | #ifdef md_elf_section_change_hook | |
2993 | md_elf_section_change_hook (); | |
2994 | #endif | |
c19d1205 | 2995 | } |
b99bd4ef | 2996 | |
c19d1205 ZW |
2997 | static void |
2998 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2999 | { | |
3000 | /* Never make frag if expect extra pass. */ | |
3001 | if (!need_pass_2) | |
3002 | frag_align (1, 0, 0); | |
b99bd4ef | 3003 | |
c19d1205 | 3004 | record_alignment (now_seg, 1); |
b99bd4ef | 3005 | |
c19d1205 | 3006 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3007 | } |
3008 | ||
c19d1205 | 3009 | /* Directives: Literal pools. */ |
a737bd4d | 3010 | |
c19d1205 ZW |
3011 | static literal_pool * |
3012 | find_literal_pool (void) | |
a737bd4d | 3013 | { |
c19d1205 | 3014 | literal_pool * pool; |
a737bd4d | 3015 | |
c19d1205 | 3016 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3017 | { |
c19d1205 ZW |
3018 | if (pool->section == now_seg |
3019 | && pool->sub_section == now_subseg) | |
3020 | break; | |
a737bd4d NC |
3021 | } |
3022 | ||
c19d1205 | 3023 | return pool; |
a737bd4d NC |
3024 | } |
3025 | ||
c19d1205 ZW |
3026 | static literal_pool * |
3027 | find_or_make_literal_pool (void) | |
a737bd4d | 3028 | { |
c19d1205 ZW |
3029 | /* Next literal pool ID number. */ |
3030 | static unsigned int latest_pool_num = 1; | |
3031 | literal_pool * pool; | |
a737bd4d | 3032 | |
c19d1205 | 3033 | pool = find_literal_pool (); |
a737bd4d | 3034 | |
c19d1205 | 3035 | if (pool == NULL) |
a737bd4d | 3036 | { |
c19d1205 | 3037 | /* Create a new pool. */ |
21d799b5 | 3038 | pool = (literal_pool *) xmalloc (sizeof (* pool)); |
c19d1205 ZW |
3039 | if (! pool) |
3040 | return NULL; | |
a737bd4d | 3041 | |
c19d1205 ZW |
3042 | pool->next_free_entry = 0; |
3043 | pool->section = now_seg; | |
3044 | pool->sub_section = now_subseg; | |
3045 | pool->next = list_of_pools; | |
3046 | pool->symbol = NULL; | |
3047 | ||
3048 | /* Add it to the list. */ | |
3049 | list_of_pools = pool; | |
a737bd4d | 3050 | } |
a737bd4d | 3051 | |
c19d1205 ZW |
3052 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3053 | if (pool->symbol == NULL) | |
a737bd4d | 3054 | { |
c19d1205 ZW |
3055 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
3056 | (valueT) 0, &zero_address_frag); | |
3057 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
3058 | } |
3059 | ||
c19d1205 ZW |
3060 | /* Done. */ |
3061 | return pool; | |
a737bd4d NC |
3062 | } |
3063 | ||
c19d1205 | 3064 | /* Add the literal in the global 'inst' |
5f4273c7 | 3065 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3066 | |
3067 | static int | |
c19d1205 | 3068 | add_to_lit_pool (void) |
b99bd4ef | 3069 | { |
c19d1205 ZW |
3070 | literal_pool * pool; |
3071 | unsigned int entry; | |
b99bd4ef | 3072 | |
c19d1205 ZW |
3073 | pool = find_or_make_literal_pool (); |
3074 | ||
3075 | /* Check if this literal value is already in the pool. */ | |
3076 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3077 | { |
c19d1205 ZW |
3078 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
3079 | && (inst.reloc.exp.X_op == O_constant) | |
3080 | && (pool->literals[entry].X_add_number | |
3081 | == inst.reloc.exp.X_add_number) | |
3082 | && (pool->literals[entry].X_unsigned | |
3083 | == inst.reloc.exp.X_unsigned)) | |
3084 | break; | |
3085 | ||
3086 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
3087 | && (inst.reloc.exp.X_op == O_symbol) | |
3088 | && (pool->literals[entry].X_add_number | |
3089 | == inst.reloc.exp.X_add_number) | |
3090 | && (pool->literals[entry].X_add_symbol | |
3091 | == inst.reloc.exp.X_add_symbol) | |
3092 | && (pool->literals[entry].X_op_symbol | |
3093 | == inst.reloc.exp.X_op_symbol)) | |
3094 | break; | |
b99bd4ef NC |
3095 | } |
3096 | ||
c19d1205 ZW |
3097 | /* Do we need to create a new entry? */ |
3098 | if (entry == pool->next_free_entry) | |
3099 | { | |
3100 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3101 | { | |
3102 | inst.error = _("literal pool overflow"); | |
3103 | return FAIL; | |
3104 | } | |
3105 | ||
3106 | pool->literals[entry] = inst.reloc.exp; | |
a8040cf2 NC |
3107 | #ifdef OBJ_ELF |
3108 | /* PR ld/12974: Record the location of the first source line to reference | |
3109 | this entry in the literal pool. If it turns out during linking that the | |
3110 | symbol does not exist we will be able to give an accurate line number for | |
3111 | the (first use of the) missing reference. */ | |
3112 | if (debug_type == DEBUG_DWARF2) | |
3113 | dwarf2_where (pool->locs + entry); | |
3114 | #endif | |
c19d1205 ZW |
3115 | pool->next_free_entry += 1; |
3116 | } | |
b99bd4ef | 3117 | |
c19d1205 ZW |
3118 | inst.reloc.exp.X_op = O_symbol; |
3119 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
3120 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3121 | |
c19d1205 | 3122 | return SUCCESS; |
b99bd4ef NC |
3123 | } |
3124 | ||
c19d1205 ZW |
3125 | /* Can't use symbol_new here, so have to create a symbol and then at |
3126 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 3127 | |
c19d1205 ZW |
3128 | static void |
3129 | symbol_locate (symbolS * symbolP, | |
3130 | const char * name, /* It is copied, the caller can modify. */ | |
3131 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3132 | valueT valu, /* Symbol value. */ | |
3133 | fragS * frag) /* Associated fragment. */ | |
3134 | { | |
3135 | unsigned int name_length; | |
3136 | char * preserved_copy_of_name; | |
e16bb312 | 3137 | |
c19d1205 ZW |
3138 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3139 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3140 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3141 | |
c19d1205 ZW |
3142 | #ifdef tc_canonicalize_symbol_name |
3143 | preserved_copy_of_name = | |
3144 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3145 | #endif | |
b99bd4ef | 3146 | |
c19d1205 | 3147 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3148 | |
c19d1205 ZW |
3149 | S_SET_SEGMENT (symbolP, segment); |
3150 | S_SET_VALUE (symbolP, valu); | |
3151 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3152 | |
c19d1205 | 3153 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3154 | |
c19d1205 ZW |
3155 | /* Link to end of symbol chain. */ |
3156 | { | |
3157 | extern int symbol_table_frozen; | |
b99bd4ef | 3158 | |
c19d1205 ZW |
3159 | if (symbol_table_frozen) |
3160 | abort (); | |
3161 | } | |
b99bd4ef | 3162 | |
c19d1205 | 3163 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3164 | |
c19d1205 | 3165 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3166 | |
c19d1205 ZW |
3167 | #ifdef tc_symbol_new_hook |
3168 | tc_symbol_new_hook (symbolP); | |
3169 | #endif | |
3170 | ||
3171 | #ifdef DEBUG_SYMS | |
3172 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3173 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3174 | } |
3175 | ||
b99bd4ef | 3176 | |
c19d1205 ZW |
3177 | static void |
3178 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3179 | { |
c19d1205 ZW |
3180 | unsigned int entry; |
3181 | literal_pool * pool; | |
3182 | char sym_name[20]; | |
b99bd4ef | 3183 | |
c19d1205 ZW |
3184 | pool = find_literal_pool (); |
3185 | if (pool == NULL | |
3186 | || pool->symbol == NULL | |
3187 | || pool->next_free_entry == 0) | |
3188 | return; | |
b99bd4ef | 3189 | |
c19d1205 | 3190 | mapping_state (MAP_DATA); |
b99bd4ef | 3191 | |
c19d1205 ZW |
3192 | /* Align pool as you have word accesses. |
3193 | Only make a frag if we have to. */ | |
3194 | if (!need_pass_2) | |
3195 | frag_align (2, 0, 0); | |
b99bd4ef | 3196 | |
c19d1205 | 3197 | record_alignment (now_seg, 2); |
b99bd4ef | 3198 | |
c19d1205 | 3199 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3200 | |
c19d1205 ZW |
3201 | symbol_locate (pool->symbol, sym_name, now_seg, |
3202 | (valueT) frag_now_fix (), frag_now); | |
3203 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3204 | |
c19d1205 | 3205 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3206 | |
c19d1205 ZW |
3207 | #if defined OBJ_COFF || defined OBJ_ELF |
3208 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3209 | #endif | |
6c43fab6 | 3210 | |
c19d1205 | 3211 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
3212 | { |
3213 | #ifdef OBJ_ELF | |
3214 | if (debug_type == DEBUG_DWARF2) | |
3215 | dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry); | |
3216 | #endif | |
3217 | /* First output the expression in the instruction to the pool. */ | |
3218 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
3219 | } | |
b99bd4ef | 3220 | |
c19d1205 ZW |
3221 | /* Mark the pool as empty. */ |
3222 | pool->next_free_entry = 0; | |
3223 | pool->symbol = NULL; | |
b99bd4ef NC |
3224 | } |
3225 | ||
c19d1205 ZW |
3226 | #ifdef OBJ_ELF |
3227 | /* Forward declarations for functions below, in the MD interface | |
3228 | section. */ | |
3229 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3230 | static valueT create_unwind_entry (int); | |
3231 | static void start_unwind_section (const segT, int); | |
3232 | static void add_unwind_opcode (valueT, int); | |
3233 | static void flush_pending_unwind (void); | |
b99bd4ef | 3234 | |
c19d1205 | 3235 | /* Directives: Data. */ |
b99bd4ef | 3236 | |
c19d1205 ZW |
3237 | static void |
3238 | s_arm_elf_cons (int nbytes) | |
3239 | { | |
3240 | expressionS exp; | |
b99bd4ef | 3241 | |
c19d1205 ZW |
3242 | #ifdef md_flush_pending_output |
3243 | md_flush_pending_output (); | |
3244 | #endif | |
b99bd4ef | 3245 | |
c19d1205 | 3246 | if (is_it_end_of_statement ()) |
b99bd4ef | 3247 | { |
c19d1205 ZW |
3248 | demand_empty_rest_of_line (); |
3249 | return; | |
b99bd4ef NC |
3250 | } |
3251 | ||
c19d1205 ZW |
3252 | #ifdef md_cons_align |
3253 | md_cons_align (nbytes); | |
3254 | #endif | |
b99bd4ef | 3255 | |
c19d1205 ZW |
3256 | mapping_state (MAP_DATA); |
3257 | do | |
b99bd4ef | 3258 | { |
c19d1205 ZW |
3259 | int reloc; |
3260 | char *base = input_line_pointer; | |
b99bd4ef | 3261 | |
c19d1205 | 3262 | expression (& exp); |
b99bd4ef | 3263 | |
c19d1205 ZW |
3264 | if (exp.X_op != O_symbol) |
3265 | emit_expr (&exp, (unsigned int) nbytes); | |
3266 | else | |
3267 | { | |
3268 | char *before_reloc = input_line_pointer; | |
3269 | reloc = parse_reloc (&input_line_pointer); | |
3270 | if (reloc == -1) | |
3271 | { | |
3272 | as_bad (_("unrecognized relocation suffix")); | |
3273 | ignore_rest_of_line (); | |
3274 | return; | |
3275 | } | |
3276 | else if (reloc == BFD_RELOC_UNUSED) | |
3277 | emit_expr (&exp, (unsigned int) nbytes); | |
3278 | else | |
3279 | { | |
21d799b5 NC |
3280 | reloc_howto_type *howto = (reloc_howto_type *) |
3281 | bfd_reloc_type_lookup (stdoutput, | |
3282 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3283 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3284 | |
2fc8bdac ZW |
3285 | if (reloc == BFD_RELOC_ARM_PLT32) |
3286 | { | |
3287 | as_bad (_("(plt) is only valid on branch targets")); | |
3288 | reloc = BFD_RELOC_UNUSED; | |
3289 | size = 0; | |
3290 | } | |
3291 | ||
c19d1205 | 3292 | if (size > nbytes) |
2fc8bdac | 3293 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3294 | howto->name, nbytes); |
3295 | else | |
3296 | { | |
3297 | /* We've parsed an expression stopping at O_symbol. | |
3298 | But there may be more expression left now that we | |
3299 | have parsed the relocation marker. Parse it again. | |
3300 | XXX Surely there is a cleaner way to do this. */ | |
3301 | char *p = input_line_pointer; | |
3302 | int offset; | |
21d799b5 | 3303 | char *save_buf = (char *) alloca (input_line_pointer - base); |
c19d1205 ZW |
3304 | memcpy (save_buf, base, input_line_pointer - base); |
3305 | memmove (base + (input_line_pointer - before_reloc), | |
3306 | base, before_reloc - base); | |
3307 | ||
3308 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3309 | expression (&exp); | |
3310 | memcpy (base, save_buf, p - base); | |
3311 | ||
3312 | offset = nbytes - size; | |
3313 | p = frag_more ((int) nbytes); | |
3314 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
21d799b5 | 3315 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
c19d1205 ZW |
3316 | } |
3317 | } | |
3318 | } | |
b99bd4ef | 3319 | } |
c19d1205 | 3320 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3321 | |
c19d1205 ZW |
3322 | /* Put terminator back into stream. */ |
3323 | input_line_pointer --; | |
3324 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3325 | } |
3326 | ||
c921be7d NC |
3327 | /* Emit an expression containing a 32-bit thumb instruction. |
3328 | Implementation based on put_thumb32_insn. */ | |
3329 | ||
3330 | static void | |
3331 | emit_thumb32_expr (expressionS * exp) | |
3332 | { | |
3333 | expressionS exp_high = *exp; | |
3334 | ||
3335 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3336 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3337 | exp->X_add_number &= 0xffff; | |
3338 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3339 | } | |
3340 | ||
3341 | /* Guess the instruction size based on the opcode. */ | |
3342 | ||
3343 | static int | |
3344 | thumb_insn_size (int opcode) | |
3345 | { | |
3346 | if ((unsigned int) opcode < 0xe800u) | |
3347 | return 2; | |
3348 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3349 | return 4; | |
3350 | else | |
3351 | return 0; | |
3352 | } | |
3353 | ||
3354 | static bfd_boolean | |
3355 | emit_insn (expressionS *exp, int nbytes) | |
3356 | { | |
3357 | int size = 0; | |
3358 | ||
3359 | if (exp->X_op == O_constant) | |
3360 | { | |
3361 | size = nbytes; | |
3362 | ||
3363 | if (size == 0) | |
3364 | size = thumb_insn_size (exp->X_add_number); | |
3365 | ||
3366 | if (size != 0) | |
3367 | { | |
3368 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3369 | { | |
3370 | as_bad (_(".inst.n operand too big. "\ | |
3371 | "Use .inst.w instead")); | |
3372 | size = 0; | |
3373 | } | |
3374 | else | |
3375 | { | |
3376 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3377 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3378 | else | |
3379 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3380 | ||
3381 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3382 | emit_thumb32_expr (exp); | |
3383 | else | |
3384 | emit_expr (exp, (unsigned int) size); | |
3385 | ||
3386 | it_fsm_post_encode (); | |
3387 | } | |
3388 | } | |
3389 | else | |
3390 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3391 | "Use .inst.n/.inst.w instead")); | |
3392 | } | |
3393 | else | |
3394 | as_bad (_("constant expression required")); | |
3395 | ||
3396 | return (size != 0); | |
3397 | } | |
3398 | ||
3399 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3400 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3401 | ||
3402 | static void | |
3403 | s_arm_elf_inst (int nbytes) | |
3404 | { | |
3405 | if (is_it_end_of_statement ()) | |
3406 | { | |
3407 | demand_empty_rest_of_line (); | |
3408 | return; | |
3409 | } | |
3410 | ||
3411 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3412 | but will ensure not to be in DATA state. */ | |
3413 | ||
3414 | if (thumb_mode) | |
3415 | mapping_state (MAP_THUMB); | |
3416 | else | |
3417 | { | |
3418 | if (nbytes != 0) | |
3419 | { | |
3420 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3421 | ignore_rest_of_line (); | |
3422 | return; | |
3423 | } | |
3424 | ||
3425 | nbytes = 4; | |
3426 | ||
3427 | mapping_state (MAP_ARM); | |
3428 | } | |
3429 | ||
3430 | do | |
3431 | { | |
3432 | expressionS exp; | |
3433 | ||
3434 | expression (& exp); | |
3435 | ||
3436 | if (! emit_insn (& exp, nbytes)) | |
3437 | { | |
3438 | ignore_rest_of_line (); | |
3439 | return; | |
3440 | } | |
3441 | } | |
3442 | while (*input_line_pointer++ == ','); | |
3443 | ||
3444 | /* Put terminator back into stream. */ | |
3445 | input_line_pointer --; | |
3446 | demand_empty_rest_of_line (); | |
3447 | } | |
b99bd4ef | 3448 | |
c19d1205 | 3449 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3450 | |
c19d1205 ZW |
3451 | static void |
3452 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3453 | { | |
3454 | expressionS exp; | |
3455 | char *p; | |
3456 | valueT highbit; | |
b99bd4ef | 3457 | |
c19d1205 ZW |
3458 | highbit = 0; |
3459 | if (*input_line_pointer == '1') | |
3460 | highbit = 0x80000000; | |
3461 | else if (*input_line_pointer != '0') | |
3462 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3463 | |
c19d1205 ZW |
3464 | input_line_pointer++; |
3465 | if (*input_line_pointer != ',') | |
3466 | as_bad (_("missing comma")); | |
3467 | input_line_pointer++; | |
b99bd4ef | 3468 | |
c19d1205 ZW |
3469 | #ifdef md_flush_pending_output |
3470 | md_flush_pending_output (); | |
3471 | #endif | |
b99bd4ef | 3472 | |
c19d1205 ZW |
3473 | #ifdef md_cons_align |
3474 | md_cons_align (4); | |
3475 | #endif | |
b99bd4ef | 3476 | |
c19d1205 | 3477 | mapping_state (MAP_DATA); |
b99bd4ef | 3478 | |
c19d1205 | 3479 | expression (&exp); |
b99bd4ef | 3480 | |
c19d1205 ZW |
3481 | p = frag_more (4); |
3482 | md_number_to_chars (p, highbit, 4); | |
3483 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3484 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3485 | |
c19d1205 | 3486 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3487 | } |
3488 | ||
c19d1205 | 3489 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3490 | |
c19d1205 | 3491 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3492 | |
c19d1205 ZW |
3493 | static void |
3494 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3495 | { | |
3496 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3497 | if (unwind.proc_start) |
3498 | { | |
c921be7d | 3499 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3500 | return; |
3501 | } | |
3502 | ||
c19d1205 ZW |
3503 | /* Mark the start of the function. */ |
3504 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3505 | |
c19d1205 ZW |
3506 | /* Reset the rest of the unwind info. */ |
3507 | unwind.opcode_count = 0; | |
3508 | unwind.table_entry = NULL; | |
3509 | unwind.personality_routine = NULL; | |
3510 | unwind.personality_index = -1; | |
3511 | unwind.frame_size = 0; | |
3512 | unwind.fp_offset = 0; | |
fdfde340 | 3513 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3514 | unwind.fp_used = 0; |
3515 | unwind.sp_restored = 0; | |
3516 | } | |
b99bd4ef | 3517 | |
b99bd4ef | 3518 | |
c19d1205 ZW |
3519 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3520 | for the function. */ | |
b99bd4ef | 3521 | |
c19d1205 ZW |
3522 | static void |
3523 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3524 | { | |
3525 | demand_empty_rest_of_line (); | |
921e5f0a | 3526 | if (!unwind.proc_start) |
c921be7d | 3527 | as_bad (MISSING_FNSTART); |
921e5f0a | 3528 | |
c19d1205 | 3529 | if (unwind.table_entry) |
6decc662 | 3530 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3531 | |
c19d1205 ZW |
3532 | create_unwind_entry (1); |
3533 | } | |
a737bd4d | 3534 | |
c19d1205 | 3535 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3536 | |
c19d1205 ZW |
3537 | static void |
3538 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3539 | { | |
3540 | long where; | |
3541 | char *ptr; | |
3542 | valueT val; | |
940b5ce0 | 3543 | unsigned int marked_pr_dependency; |
f02232aa | 3544 | |
c19d1205 | 3545 | demand_empty_rest_of_line (); |
f02232aa | 3546 | |
921e5f0a PB |
3547 | if (!unwind.proc_start) |
3548 | { | |
c921be7d | 3549 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3550 | return; |
3551 | } | |
3552 | ||
c19d1205 ZW |
3553 | /* Add eh table entry. */ |
3554 | if (unwind.table_entry == NULL) | |
3555 | val = create_unwind_entry (0); | |
3556 | else | |
3557 | val = 0; | |
f02232aa | 3558 | |
c19d1205 ZW |
3559 | /* Add index table entry. This is two words. */ |
3560 | start_unwind_section (unwind.saved_seg, 1); | |
3561 | frag_align (2, 0, 0); | |
3562 | record_alignment (now_seg, 2); | |
b99bd4ef | 3563 | |
c19d1205 | 3564 | ptr = frag_more (8); |
5011093d | 3565 | memset (ptr, 0, 8); |
c19d1205 | 3566 | where = frag_now_fix () - 8; |
f02232aa | 3567 | |
c19d1205 ZW |
3568 | /* Self relative offset of the function start. */ |
3569 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3570 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3571 | |
c19d1205 ZW |
3572 | /* Indicate dependency on EHABI-defined personality routines to the |
3573 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3574 | marked_pr_dependency |
3575 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3576 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3577 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3578 | { | |
5f4273c7 NC |
3579 | static const char *const name[] = |
3580 | { | |
3581 | "__aeabi_unwind_cpp_pr0", | |
3582 | "__aeabi_unwind_cpp_pr1", | |
3583 | "__aeabi_unwind_cpp_pr2" | |
3584 | }; | |
c19d1205 ZW |
3585 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3586 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3587 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3588 | |= 1 << unwind.personality_index; |
c19d1205 | 3589 | } |
f02232aa | 3590 | |
c19d1205 ZW |
3591 | if (val) |
3592 | /* Inline exception table entry. */ | |
3593 | md_number_to_chars (ptr + 4, val, 4); | |
3594 | else | |
3595 | /* Self relative offset of the table entry. */ | |
3596 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3597 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3598 | |
c19d1205 ZW |
3599 | /* Restore the original section. */ |
3600 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3601 | |
3602 | unwind.proc_start = NULL; | |
c19d1205 | 3603 | } |
f02232aa | 3604 | |
f02232aa | 3605 | |
c19d1205 | 3606 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3607 | |
c19d1205 ZW |
3608 | static void |
3609 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3610 | { | |
3611 | demand_empty_rest_of_line (); | |
921e5f0a | 3612 | if (!unwind.proc_start) |
c921be7d | 3613 | as_bad (MISSING_FNSTART); |
921e5f0a | 3614 | |
c19d1205 ZW |
3615 | if (unwind.personality_routine || unwind.personality_index != -1) |
3616 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3617 | |
c19d1205 ZW |
3618 | unwind.personality_index = -2; |
3619 | } | |
b99bd4ef | 3620 | |
b99bd4ef | 3621 | |
c19d1205 | 3622 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3623 | |
c19d1205 ZW |
3624 | static void |
3625 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3626 | { | |
3627 | expressionS exp; | |
b99bd4ef | 3628 | |
921e5f0a | 3629 | if (!unwind.proc_start) |
c921be7d | 3630 | as_bad (MISSING_FNSTART); |
921e5f0a | 3631 | |
c19d1205 ZW |
3632 | if (unwind.personality_routine || unwind.personality_index != -1) |
3633 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3634 | |
c19d1205 | 3635 | expression (&exp); |
b99bd4ef | 3636 | |
c19d1205 ZW |
3637 | if (exp.X_op != O_constant |
3638 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3639 | { |
c19d1205 ZW |
3640 | as_bad (_("bad personality routine number")); |
3641 | ignore_rest_of_line (); | |
3642 | return; | |
b99bd4ef NC |
3643 | } |
3644 | ||
c19d1205 | 3645 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3646 | |
c19d1205 ZW |
3647 | demand_empty_rest_of_line (); |
3648 | } | |
e16bb312 | 3649 | |
e16bb312 | 3650 | |
c19d1205 | 3651 | /* Parse a personality directive. */ |
e16bb312 | 3652 | |
c19d1205 ZW |
3653 | static void |
3654 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3655 | { | |
3656 | char *name, *p, c; | |
a737bd4d | 3657 | |
921e5f0a | 3658 | if (!unwind.proc_start) |
c921be7d | 3659 | as_bad (MISSING_FNSTART); |
921e5f0a | 3660 | |
c19d1205 ZW |
3661 | if (unwind.personality_routine || unwind.personality_index != -1) |
3662 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3663 | |
c19d1205 ZW |
3664 | name = input_line_pointer; |
3665 | c = get_symbol_end (); | |
3666 | p = input_line_pointer; | |
3667 | unwind.personality_routine = symbol_find_or_make (name); | |
3668 | *p = c; | |
3669 | demand_empty_rest_of_line (); | |
3670 | } | |
e16bb312 | 3671 | |
e16bb312 | 3672 | |
c19d1205 | 3673 | /* Parse a directive saving core registers. */ |
e16bb312 | 3674 | |
c19d1205 ZW |
3675 | static void |
3676 | s_arm_unwind_save_core (void) | |
e16bb312 | 3677 | { |
c19d1205 ZW |
3678 | valueT op; |
3679 | long range; | |
3680 | int n; | |
e16bb312 | 3681 | |
c19d1205 ZW |
3682 | range = parse_reg_list (&input_line_pointer); |
3683 | if (range == FAIL) | |
e16bb312 | 3684 | { |
c19d1205 ZW |
3685 | as_bad (_("expected register list")); |
3686 | ignore_rest_of_line (); | |
3687 | return; | |
3688 | } | |
e16bb312 | 3689 | |
c19d1205 | 3690 | demand_empty_rest_of_line (); |
e16bb312 | 3691 | |
c19d1205 ZW |
3692 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3693 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3694 | ip because it is clobbered by calls. */ | |
3695 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3696 | && (range & 0x3000) == 0x1000) | |
3697 | { | |
3698 | unwind.opcode_count--; | |
3699 | unwind.sp_restored = 0; | |
3700 | range = (range | 0x2000) & ~0x1000; | |
3701 | unwind.pending_offset = 0; | |
3702 | } | |
e16bb312 | 3703 | |
01ae4198 DJ |
3704 | /* Pop r4-r15. */ |
3705 | if (range & 0xfff0) | |
c19d1205 | 3706 | { |
01ae4198 DJ |
3707 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3708 | registers starting with r4, plus maybe r14. */ | |
3709 | for (n = 0; n < 8; n++) | |
3710 | { | |
3711 | /* Break at the first non-saved register. */ | |
3712 | if ((range & (1 << (n + 4))) == 0) | |
3713 | break; | |
3714 | } | |
3715 | /* See if there are any other bits set. */ | |
3716 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3717 | { | |
3718 | /* Use the long form. */ | |
3719 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3720 | add_unwind_opcode (op, 2); | |
3721 | } | |
0dd132b6 | 3722 | else |
01ae4198 DJ |
3723 | { |
3724 | /* Use the short form. */ | |
3725 | if (range & 0x4000) | |
3726 | op = 0xa8; /* Pop r14. */ | |
3727 | else | |
3728 | op = 0xa0; /* Do not pop r14. */ | |
3729 | op |= (n - 1); | |
3730 | add_unwind_opcode (op, 1); | |
3731 | } | |
c19d1205 | 3732 | } |
0dd132b6 | 3733 | |
c19d1205 ZW |
3734 | /* Pop r0-r3. */ |
3735 | if (range & 0xf) | |
3736 | { | |
3737 | op = 0xb100 | (range & 0xf); | |
3738 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3739 | } |
3740 | ||
c19d1205 ZW |
3741 | /* Record the number of bytes pushed. */ |
3742 | for (n = 0; n < 16; n++) | |
3743 | { | |
3744 | if (range & (1 << n)) | |
3745 | unwind.frame_size += 4; | |
3746 | } | |
0dd132b6 NC |
3747 | } |
3748 | ||
c19d1205 ZW |
3749 | |
3750 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3751 | |
3752 | static void | |
c19d1205 | 3753 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3754 | { |
c19d1205 ZW |
3755 | expressionS exp; |
3756 | int num_regs; | |
3757 | valueT op; | |
b99bd4ef | 3758 | |
c19d1205 ZW |
3759 | /* Get Number of registers to transfer. */ |
3760 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3761 | expression (&exp); | |
3762 | else | |
3763 | exp.X_op = O_illegal; | |
b99bd4ef | 3764 | |
c19d1205 | 3765 | if (exp.X_op != O_constant) |
b99bd4ef | 3766 | { |
c19d1205 ZW |
3767 | as_bad (_("expected , <constant>")); |
3768 | ignore_rest_of_line (); | |
b99bd4ef NC |
3769 | return; |
3770 | } | |
3771 | ||
c19d1205 ZW |
3772 | num_regs = exp.X_add_number; |
3773 | ||
3774 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3775 | { |
c19d1205 ZW |
3776 | as_bad (_("number of registers must be in the range [1:4]")); |
3777 | ignore_rest_of_line (); | |
b99bd4ef NC |
3778 | return; |
3779 | } | |
3780 | ||
c19d1205 | 3781 | demand_empty_rest_of_line (); |
b99bd4ef | 3782 | |
c19d1205 ZW |
3783 | if (reg == 4) |
3784 | { | |
3785 | /* Short form. */ | |
3786 | op = 0xb4 | (num_regs - 1); | |
3787 | add_unwind_opcode (op, 1); | |
3788 | } | |
b99bd4ef NC |
3789 | else |
3790 | { | |
c19d1205 ZW |
3791 | /* Long form. */ |
3792 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3793 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3794 | } |
c19d1205 | 3795 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3796 | } |
3797 | ||
c19d1205 | 3798 | |
fa073d69 MS |
3799 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3800 | ||
3801 | static void | |
3802 | s_arm_unwind_save_vfp_armv6 (void) | |
3803 | { | |
3804 | int count; | |
3805 | unsigned int start; | |
3806 | valueT op; | |
3807 | int num_vfpv3_regs = 0; | |
3808 | int num_regs_below_16; | |
3809 | ||
3810 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3811 | if (count == FAIL) | |
3812 | { | |
3813 | as_bad (_("expected register list")); | |
3814 | ignore_rest_of_line (); | |
3815 | return; | |
3816 | } | |
3817 | ||
3818 | demand_empty_rest_of_line (); | |
3819 | ||
3820 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3821 | than FSTMX/FLDMX-style ones). */ | |
3822 | ||
3823 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3824 | if (start >= 16) | |
3825 | num_vfpv3_regs = count; | |
3826 | else if (start + count > 16) | |
3827 | num_vfpv3_regs = start + count - 16; | |
3828 | ||
3829 | if (num_vfpv3_regs > 0) | |
3830 | { | |
3831 | int start_offset = start > 16 ? start - 16 : 0; | |
3832 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3833 | add_unwind_opcode (op, 2); | |
3834 | } | |
3835 | ||
3836 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3837 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 3838 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
3839 | if (num_regs_below_16 > 0) |
3840 | { | |
3841 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3842 | add_unwind_opcode (op, 2); | |
3843 | } | |
3844 | ||
3845 | unwind.frame_size += count * 8; | |
3846 | } | |
3847 | ||
3848 | ||
3849 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3850 | |
3851 | static void | |
c19d1205 | 3852 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3853 | { |
c19d1205 | 3854 | int count; |
ca3f61f7 | 3855 | unsigned int reg; |
c19d1205 | 3856 | valueT op; |
b99bd4ef | 3857 | |
5287ad62 | 3858 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3859 | if (count == FAIL) |
b99bd4ef | 3860 | { |
c19d1205 ZW |
3861 | as_bad (_("expected register list")); |
3862 | ignore_rest_of_line (); | |
b99bd4ef NC |
3863 | return; |
3864 | } | |
3865 | ||
c19d1205 | 3866 | demand_empty_rest_of_line (); |
b99bd4ef | 3867 | |
c19d1205 | 3868 | if (reg == 8) |
b99bd4ef | 3869 | { |
c19d1205 ZW |
3870 | /* Short form. */ |
3871 | op = 0xb8 | (count - 1); | |
3872 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3873 | } |
c19d1205 | 3874 | else |
b99bd4ef | 3875 | { |
c19d1205 ZW |
3876 | /* Long form. */ |
3877 | op = 0xb300 | (reg << 4) | (count - 1); | |
3878 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3879 | } |
c19d1205 ZW |
3880 | unwind.frame_size += count * 8 + 4; |
3881 | } | |
b99bd4ef | 3882 | |
b99bd4ef | 3883 | |
c19d1205 ZW |
3884 | /* Parse a directive saving iWMMXt data registers. */ |
3885 | ||
3886 | static void | |
3887 | s_arm_unwind_save_mmxwr (void) | |
3888 | { | |
3889 | int reg; | |
3890 | int hi_reg; | |
3891 | int i; | |
3892 | unsigned mask = 0; | |
3893 | valueT op; | |
b99bd4ef | 3894 | |
c19d1205 ZW |
3895 | if (*input_line_pointer == '{') |
3896 | input_line_pointer++; | |
b99bd4ef | 3897 | |
c19d1205 | 3898 | do |
b99bd4ef | 3899 | { |
dcbf9037 | 3900 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3901 | |
c19d1205 | 3902 | if (reg == FAIL) |
b99bd4ef | 3903 | { |
9b7132d3 | 3904 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 3905 | goto error; |
b99bd4ef NC |
3906 | } |
3907 | ||
c19d1205 ZW |
3908 | if (mask >> reg) |
3909 | as_tsktsk (_("register list not in ascending order")); | |
3910 | mask |= 1 << reg; | |
b99bd4ef | 3911 | |
c19d1205 ZW |
3912 | if (*input_line_pointer == '-') |
3913 | { | |
3914 | input_line_pointer++; | |
dcbf9037 | 3915 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3916 | if (hi_reg == FAIL) |
3917 | { | |
9b7132d3 | 3918 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
3919 | goto error; |
3920 | } | |
3921 | else if (reg >= hi_reg) | |
3922 | { | |
3923 | as_bad (_("bad register range")); | |
3924 | goto error; | |
3925 | } | |
3926 | for (; reg < hi_reg; reg++) | |
3927 | mask |= 1 << reg; | |
3928 | } | |
3929 | } | |
3930 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3931 | |
c19d1205 ZW |
3932 | if (*input_line_pointer == '}') |
3933 | input_line_pointer++; | |
b99bd4ef | 3934 | |
c19d1205 | 3935 | demand_empty_rest_of_line (); |
b99bd4ef | 3936 | |
708587a4 | 3937 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3938 | the list. */ |
3939 | flush_pending_unwind (); | |
b99bd4ef | 3940 | |
c19d1205 | 3941 | for (i = 0; i < 16; i++) |
b99bd4ef | 3942 | { |
c19d1205 ZW |
3943 | if (mask & (1 << i)) |
3944 | unwind.frame_size += 8; | |
b99bd4ef NC |
3945 | } |
3946 | ||
c19d1205 ZW |
3947 | /* Attempt to combine with a previous opcode. We do this because gcc |
3948 | likes to output separate unwind directives for a single block of | |
3949 | registers. */ | |
3950 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3951 | { |
c19d1205 ZW |
3952 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3953 | if ((i & 0xf8) == 0xc0) | |
3954 | { | |
3955 | i &= 7; | |
3956 | /* Only merge if the blocks are contiguous. */ | |
3957 | if (i < 6) | |
3958 | { | |
3959 | if ((mask & 0xfe00) == (1 << 9)) | |
3960 | { | |
3961 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3962 | unwind.opcode_count--; | |
3963 | } | |
3964 | } | |
3965 | else if (i == 6 && unwind.opcode_count >= 2) | |
3966 | { | |
3967 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3968 | reg = i >> 4; | |
3969 | i &= 0xf; | |
b99bd4ef | 3970 | |
c19d1205 ZW |
3971 | op = 0xffff << (reg - 1); |
3972 | if (reg > 0 | |
87a1fd79 | 3973 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
3974 | { |
3975 | op = (1 << (reg + i + 1)) - 1; | |
3976 | op &= ~((1 << reg) - 1); | |
3977 | mask |= op; | |
3978 | unwind.opcode_count -= 2; | |
3979 | } | |
3980 | } | |
3981 | } | |
b99bd4ef NC |
3982 | } |
3983 | ||
c19d1205 ZW |
3984 | hi_reg = 15; |
3985 | /* We want to generate opcodes in the order the registers have been | |
3986 | saved, ie. descending order. */ | |
3987 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3988 | { |
c19d1205 ZW |
3989 | /* Save registers in blocks. */ |
3990 | if (reg < 0 | |
3991 | || !(mask & (1 << reg))) | |
3992 | { | |
3993 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 3994 | preceding block. */ |
c19d1205 ZW |
3995 | if (reg != hi_reg) |
3996 | { | |
3997 | if (reg == 9) | |
3998 | { | |
3999 | /* Short form. */ | |
4000 | op = 0xc0 | (hi_reg - 10); | |
4001 | add_unwind_opcode (op, 1); | |
4002 | } | |
4003 | else | |
4004 | { | |
4005 | /* Long form. */ | |
4006 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
4007 | add_unwind_opcode (op, 2); | |
4008 | } | |
4009 | } | |
4010 | hi_reg = reg - 1; | |
4011 | } | |
b99bd4ef NC |
4012 | } |
4013 | ||
c19d1205 ZW |
4014 | return; |
4015 | error: | |
4016 | ignore_rest_of_line (); | |
b99bd4ef NC |
4017 | } |
4018 | ||
4019 | static void | |
c19d1205 | 4020 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4021 | { |
c19d1205 ZW |
4022 | int reg; |
4023 | int hi_reg; | |
4024 | unsigned mask = 0; | |
4025 | valueT op; | |
b99bd4ef | 4026 | |
c19d1205 ZW |
4027 | if (*input_line_pointer == '{') |
4028 | input_line_pointer++; | |
b99bd4ef | 4029 | |
c19d1205 | 4030 | do |
b99bd4ef | 4031 | { |
dcbf9037 | 4032 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4033 | |
c19d1205 ZW |
4034 | if (reg == FAIL) |
4035 | { | |
9b7132d3 | 4036 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4037 | goto error; |
4038 | } | |
b99bd4ef | 4039 | |
c19d1205 ZW |
4040 | reg -= 8; |
4041 | if (mask >> reg) | |
4042 | as_tsktsk (_("register list not in ascending order")); | |
4043 | mask |= 1 << reg; | |
b99bd4ef | 4044 | |
c19d1205 ZW |
4045 | if (*input_line_pointer == '-') |
4046 | { | |
4047 | input_line_pointer++; | |
dcbf9037 | 4048 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4049 | if (hi_reg == FAIL) |
4050 | { | |
9b7132d3 | 4051 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4052 | goto error; |
4053 | } | |
4054 | else if (reg >= hi_reg) | |
4055 | { | |
4056 | as_bad (_("bad register range")); | |
4057 | goto error; | |
4058 | } | |
4059 | for (; reg < hi_reg; reg++) | |
4060 | mask |= 1 << reg; | |
4061 | } | |
b99bd4ef | 4062 | } |
c19d1205 | 4063 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4064 | |
c19d1205 ZW |
4065 | if (*input_line_pointer == '}') |
4066 | input_line_pointer++; | |
b99bd4ef | 4067 | |
c19d1205 ZW |
4068 | demand_empty_rest_of_line (); |
4069 | ||
708587a4 | 4070 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4071 | the list. */ |
4072 | flush_pending_unwind (); | |
b99bd4ef | 4073 | |
c19d1205 | 4074 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4075 | { |
c19d1205 ZW |
4076 | if (mask & (1 << reg)) |
4077 | unwind.frame_size += 4; | |
b99bd4ef | 4078 | } |
c19d1205 ZW |
4079 | op = 0xc700 | mask; |
4080 | add_unwind_opcode (op, 2); | |
4081 | return; | |
4082 | error: | |
4083 | ignore_rest_of_line (); | |
b99bd4ef NC |
4084 | } |
4085 | ||
c19d1205 | 4086 | |
fa073d69 MS |
4087 | /* Parse an unwind_save directive. |
4088 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4089 | |
b99bd4ef | 4090 | static void |
fa073d69 | 4091 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4092 | { |
c19d1205 ZW |
4093 | char *peek; |
4094 | struct reg_entry *reg; | |
4095 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4096 | |
921e5f0a | 4097 | if (!unwind.proc_start) |
c921be7d | 4098 | as_bad (MISSING_FNSTART); |
921e5f0a | 4099 | |
c19d1205 ZW |
4100 | /* Figure out what sort of save we have. */ |
4101 | peek = input_line_pointer; | |
b99bd4ef | 4102 | |
c19d1205 | 4103 | if (*peek == '{') |
b99bd4ef | 4104 | { |
c19d1205 ZW |
4105 | had_brace = TRUE; |
4106 | peek++; | |
b99bd4ef NC |
4107 | } |
4108 | ||
c19d1205 | 4109 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4110 | |
c19d1205 | 4111 | if (!reg) |
b99bd4ef | 4112 | { |
c19d1205 ZW |
4113 | as_bad (_("register expected")); |
4114 | ignore_rest_of_line (); | |
b99bd4ef NC |
4115 | return; |
4116 | } | |
4117 | ||
c19d1205 | 4118 | switch (reg->type) |
b99bd4ef | 4119 | { |
c19d1205 ZW |
4120 | case REG_TYPE_FN: |
4121 | if (had_brace) | |
4122 | { | |
4123 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4124 | ignore_rest_of_line (); | |
4125 | return; | |
4126 | } | |
93ac2687 | 4127 | input_line_pointer = peek; |
c19d1205 | 4128 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4129 | return; |
c19d1205 ZW |
4130 | |
4131 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
4132 | case REG_TYPE_VFD: |
4133 | if (arch_v6) | |
4134 | s_arm_unwind_save_vfp_armv6 (); | |
4135 | else | |
4136 | s_arm_unwind_save_vfp (); | |
4137 | return; | |
c19d1205 ZW |
4138 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
4139 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
4140 | ||
4141 | default: | |
4142 | as_bad (_(".unwind_save does not support this kind of register")); | |
4143 | ignore_rest_of_line (); | |
b99bd4ef | 4144 | } |
c19d1205 | 4145 | } |
b99bd4ef | 4146 | |
b99bd4ef | 4147 | |
c19d1205 ZW |
4148 | /* Parse an unwind_movsp directive. */ |
4149 | ||
4150 | static void | |
4151 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4152 | { | |
4153 | int reg; | |
4154 | valueT op; | |
4fa3602b | 4155 | int offset; |
c19d1205 | 4156 | |
921e5f0a | 4157 | if (!unwind.proc_start) |
c921be7d | 4158 | as_bad (MISSING_FNSTART); |
921e5f0a | 4159 | |
dcbf9037 | 4160 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4161 | if (reg == FAIL) |
b99bd4ef | 4162 | { |
9b7132d3 | 4163 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4164 | ignore_rest_of_line (); |
b99bd4ef NC |
4165 | return; |
4166 | } | |
4fa3602b PB |
4167 | |
4168 | /* Optional constant. */ | |
4169 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4170 | { | |
4171 | if (immediate_for_directive (&offset) == FAIL) | |
4172 | return; | |
4173 | } | |
4174 | else | |
4175 | offset = 0; | |
4176 | ||
c19d1205 | 4177 | demand_empty_rest_of_line (); |
b99bd4ef | 4178 | |
c19d1205 | 4179 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4180 | { |
c19d1205 | 4181 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4182 | return; |
4183 | } | |
4184 | ||
c19d1205 ZW |
4185 | if (unwind.fp_reg != REG_SP) |
4186 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4187 | |
c19d1205 ZW |
4188 | /* Generate opcode to restore the value. */ |
4189 | op = 0x90 | reg; | |
4190 | add_unwind_opcode (op, 1); | |
4191 | ||
4192 | /* Record the information for later. */ | |
4193 | unwind.fp_reg = reg; | |
4fa3602b | 4194 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4195 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4196 | } |
4197 | ||
c19d1205 ZW |
4198 | /* Parse an unwind_pad directive. */ |
4199 | ||
b05fe5cf | 4200 | static void |
c19d1205 | 4201 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4202 | { |
c19d1205 | 4203 | int offset; |
b05fe5cf | 4204 | |
921e5f0a | 4205 | if (!unwind.proc_start) |
c921be7d | 4206 | as_bad (MISSING_FNSTART); |
921e5f0a | 4207 | |
c19d1205 ZW |
4208 | if (immediate_for_directive (&offset) == FAIL) |
4209 | return; | |
b99bd4ef | 4210 | |
c19d1205 ZW |
4211 | if (offset & 3) |
4212 | { | |
4213 | as_bad (_("stack increment must be multiple of 4")); | |
4214 | ignore_rest_of_line (); | |
4215 | return; | |
4216 | } | |
b99bd4ef | 4217 | |
c19d1205 ZW |
4218 | /* Don't generate any opcodes, just record the details for later. */ |
4219 | unwind.frame_size += offset; | |
4220 | unwind.pending_offset += offset; | |
4221 | ||
4222 | demand_empty_rest_of_line (); | |
4223 | } | |
4224 | ||
4225 | /* Parse an unwind_setfp directive. */ | |
4226 | ||
4227 | static void | |
4228 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4229 | { |
c19d1205 ZW |
4230 | int sp_reg; |
4231 | int fp_reg; | |
4232 | int offset; | |
4233 | ||
921e5f0a | 4234 | if (!unwind.proc_start) |
c921be7d | 4235 | as_bad (MISSING_FNSTART); |
921e5f0a | 4236 | |
dcbf9037 | 4237 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4238 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4239 | sp_reg = FAIL; | |
4240 | else | |
dcbf9037 | 4241 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4242 | |
c19d1205 ZW |
4243 | if (fp_reg == FAIL || sp_reg == FAIL) |
4244 | { | |
4245 | as_bad (_("expected <reg>, <reg>")); | |
4246 | ignore_rest_of_line (); | |
4247 | return; | |
4248 | } | |
b99bd4ef | 4249 | |
c19d1205 ZW |
4250 | /* Optional constant. */ |
4251 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4252 | { | |
4253 | if (immediate_for_directive (&offset) == FAIL) | |
4254 | return; | |
4255 | } | |
4256 | else | |
4257 | offset = 0; | |
a737bd4d | 4258 | |
c19d1205 | 4259 | demand_empty_rest_of_line (); |
a737bd4d | 4260 | |
fdfde340 | 4261 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4262 | { |
c19d1205 ZW |
4263 | as_bad (_("register must be either sp or set by a previous" |
4264 | "unwind_movsp directive")); | |
4265 | return; | |
a737bd4d NC |
4266 | } |
4267 | ||
c19d1205 ZW |
4268 | /* Don't generate any opcodes, just record the information for later. */ |
4269 | unwind.fp_reg = fp_reg; | |
4270 | unwind.fp_used = 1; | |
fdfde340 | 4271 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4272 | unwind.fp_offset = unwind.frame_size - offset; |
4273 | else | |
4274 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4275 | } |
4276 | ||
c19d1205 ZW |
4277 | /* Parse an unwind_raw directive. */ |
4278 | ||
4279 | static void | |
4280 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4281 | { |
c19d1205 | 4282 | expressionS exp; |
708587a4 | 4283 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4284 | unsigned char op[16]; |
4285 | int count; | |
a737bd4d | 4286 | |
921e5f0a | 4287 | if (!unwind.proc_start) |
c921be7d | 4288 | as_bad (MISSING_FNSTART); |
921e5f0a | 4289 | |
c19d1205 ZW |
4290 | expression (&exp); |
4291 | if (exp.X_op == O_constant | |
4292 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4293 | { |
c19d1205 ZW |
4294 | unwind.frame_size += exp.X_add_number; |
4295 | expression (&exp); | |
4296 | } | |
4297 | else | |
4298 | exp.X_op = O_illegal; | |
a737bd4d | 4299 | |
c19d1205 ZW |
4300 | if (exp.X_op != O_constant) |
4301 | { | |
4302 | as_bad (_("expected <offset>, <opcode>")); | |
4303 | ignore_rest_of_line (); | |
4304 | return; | |
4305 | } | |
a737bd4d | 4306 | |
c19d1205 | 4307 | count = 0; |
a737bd4d | 4308 | |
c19d1205 ZW |
4309 | /* Parse the opcode. */ |
4310 | for (;;) | |
4311 | { | |
4312 | if (count >= 16) | |
4313 | { | |
4314 | as_bad (_("unwind opcode too long")); | |
4315 | ignore_rest_of_line (); | |
a737bd4d | 4316 | } |
c19d1205 | 4317 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4318 | { |
c19d1205 ZW |
4319 | as_bad (_("invalid unwind opcode")); |
4320 | ignore_rest_of_line (); | |
4321 | return; | |
a737bd4d | 4322 | } |
c19d1205 | 4323 | op[count++] = exp.X_add_number; |
a737bd4d | 4324 | |
c19d1205 ZW |
4325 | /* Parse the next byte. */ |
4326 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4327 | break; | |
a737bd4d | 4328 | |
c19d1205 ZW |
4329 | expression (&exp); |
4330 | } | |
b99bd4ef | 4331 | |
c19d1205 ZW |
4332 | /* Add the opcode bytes in reverse order. */ |
4333 | while (count--) | |
4334 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4335 | |
c19d1205 | 4336 | demand_empty_rest_of_line (); |
b99bd4ef | 4337 | } |
ee065d83 PB |
4338 | |
4339 | ||
4340 | /* Parse a .eabi_attribute directive. */ | |
4341 | ||
4342 | static void | |
4343 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4344 | { | |
0420f52b | 4345 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 AS |
4346 | |
4347 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4348 | attributes_set_explicitly[tag] = 1; | |
ee065d83 PB |
4349 | } |
4350 | ||
0855e32b NS |
4351 | /* Emit a tls fix for the symbol. */ |
4352 | ||
4353 | static void | |
4354 | s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED) | |
4355 | { | |
4356 | char *p; | |
4357 | expressionS exp; | |
4358 | #ifdef md_flush_pending_output | |
4359 | md_flush_pending_output (); | |
4360 | #endif | |
4361 | ||
4362 | #ifdef md_cons_align | |
4363 | md_cons_align (4); | |
4364 | #endif | |
4365 | ||
4366 | /* Since we're just labelling the code, there's no need to define a | |
4367 | mapping symbol. */ | |
4368 | expression (&exp); | |
4369 | p = obstack_next_free (&frchain_now->frch_obstack); | |
4370 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0, | |
4371 | thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
4372 | : BFD_RELOC_ARM_TLS_DESCSEQ); | |
4373 | } | |
cdf9ccec | 4374 | #endif /* OBJ_ELF */ |
0855e32b | 4375 | |
ee065d83 | 4376 | static void s_arm_arch (int); |
7a1d4c38 | 4377 | static void s_arm_object_arch (int); |
ee065d83 PB |
4378 | static void s_arm_cpu (int); |
4379 | static void s_arm_fpu (int); | |
69133863 | 4380 | static void s_arm_arch_extension (int); |
b99bd4ef | 4381 | |
f0927246 NC |
4382 | #ifdef TE_PE |
4383 | ||
4384 | static void | |
5f4273c7 | 4385 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4386 | { |
4387 | expressionS exp; | |
4388 | ||
4389 | do | |
4390 | { | |
4391 | expression (&exp); | |
4392 | if (exp.X_op == O_symbol) | |
4393 | exp.X_op = O_secrel; | |
4394 | ||
4395 | emit_expr (&exp, 4); | |
4396 | } | |
4397 | while (*input_line_pointer++ == ','); | |
4398 | ||
4399 | input_line_pointer--; | |
4400 | demand_empty_rest_of_line (); | |
4401 | } | |
4402 | #endif /* TE_PE */ | |
4403 | ||
c19d1205 ZW |
4404 | /* This table describes all the machine specific pseudo-ops the assembler |
4405 | has to support. The fields are: | |
4406 | pseudo-op name without dot | |
4407 | function to call to execute this pseudo-op | |
4408 | Integer arg to pass to the function. */ | |
b99bd4ef | 4409 | |
c19d1205 | 4410 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4411 | { |
c19d1205 ZW |
4412 | /* Never called because '.req' does not start a line. */ |
4413 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4414 | /* Following two are likewise never called. */ |
4415 | { "dn", s_dn, 0 }, | |
4416 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4417 | { "unreq", s_unreq, 0 }, |
4418 | { "bss", s_bss, 0 }, | |
4419 | { "align", s_align, 0 }, | |
4420 | { "arm", s_arm, 0 }, | |
4421 | { "thumb", s_thumb, 0 }, | |
4422 | { "code", s_code, 0 }, | |
4423 | { "force_thumb", s_force_thumb, 0 }, | |
4424 | { "thumb_func", s_thumb_func, 0 }, | |
4425 | { "thumb_set", s_thumb_set, 0 }, | |
4426 | { "even", s_even, 0 }, | |
4427 | { "ltorg", s_ltorg, 0 }, | |
4428 | { "pool", s_ltorg, 0 }, | |
4429 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4430 | { "cpu", s_arm_cpu, 0 }, |
4431 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4432 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4433 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 4434 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 4435 | #ifdef OBJ_ELF |
c921be7d NC |
4436 | { "word", s_arm_elf_cons, 4 }, |
4437 | { "long", s_arm_elf_cons, 4 }, | |
4438 | { "inst.n", s_arm_elf_inst, 2 }, | |
4439 | { "inst.w", s_arm_elf_inst, 4 }, | |
4440 | { "inst", s_arm_elf_inst, 0 }, | |
4441 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4442 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4443 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4444 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4445 | { "personality", s_arm_unwind_personality, 0 }, | |
4446 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4447 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4448 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4449 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4450 | { "movsp", s_arm_unwind_movsp, 0 }, |
4451 | { "pad", s_arm_unwind_pad, 0 }, | |
4452 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4453 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4454 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 4455 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
4456 | #else |
4457 | { "word", cons, 4}, | |
f0927246 NC |
4458 | |
4459 | /* These are used for dwarf. */ | |
4460 | {"2byte", cons, 2}, | |
4461 | {"4byte", cons, 4}, | |
4462 | {"8byte", cons, 8}, | |
4463 | /* These are used for dwarf2. */ | |
4464 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4465 | { "loc", dwarf2_directive_loc, 0 }, | |
4466 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4467 | #endif |
4468 | { "extend", float_cons, 'x' }, | |
4469 | { "ldouble", float_cons, 'x' }, | |
4470 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4471 | #ifdef TE_PE |
4472 | {"secrel32", pe_directive_secrel, 0}, | |
4473 | #endif | |
c19d1205 ZW |
4474 | { 0, 0, 0 } |
4475 | }; | |
4476 | \f | |
4477 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4478 | |
c19d1205 ZW |
4479 | /* Generic immediate-value read function for use in insn parsing. |
4480 | STR points to the beginning of the immediate (the leading #); | |
4481 | VAL receives the value; if the value is outside [MIN, MAX] | |
4482 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4483 | optional. */ | |
b99bd4ef | 4484 | |
c19d1205 ZW |
4485 | static int |
4486 | parse_immediate (char **str, int *val, int min, int max, | |
4487 | bfd_boolean prefix_opt) | |
4488 | { | |
4489 | expressionS exp; | |
4490 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4491 | if (exp.X_op != O_constant) | |
b99bd4ef | 4492 | { |
c19d1205 ZW |
4493 | inst.error = _("constant expression required"); |
4494 | return FAIL; | |
4495 | } | |
b99bd4ef | 4496 | |
c19d1205 ZW |
4497 | if (exp.X_add_number < min || exp.X_add_number > max) |
4498 | { | |
4499 | inst.error = _("immediate value out of range"); | |
4500 | return FAIL; | |
4501 | } | |
b99bd4ef | 4502 | |
c19d1205 ZW |
4503 | *val = exp.X_add_number; |
4504 | return SUCCESS; | |
4505 | } | |
b99bd4ef | 4506 | |
5287ad62 | 4507 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4508 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4509 | instructions. Puts the result directly in inst.operands[i]. */ |
4510 | ||
4511 | static int | |
4512 | parse_big_immediate (char **str, int i) | |
4513 | { | |
4514 | expressionS exp; | |
4515 | char *ptr = *str; | |
4516 | ||
4517 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
4518 | ||
4519 | if (exp.X_op == O_constant) | |
036dc3f7 PB |
4520 | { |
4521 | inst.operands[i].imm = exp.X_add_number & 0xffffffff; | |
4522 | /* If we're on a 64-bit host, then a 64-bit number can be returned using | |
4523 | O_constant. We have to be careful not to break compilation for | |
4524 | 32-bit X_add_number, though. */ | |
58ad575f | 4525 | if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 PB |
4526 | { |
4527 | /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */ | |
4528 | inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff; | |
4529 | inst.operands[i].regisimm = 1; | |
4530 | } | |
4531 | } | |
5287ad62 | 4532 | else if (exp.X_op == O_big |
95b75c01 | 4533 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32) |
5287ad62 JB |
4534 | { |
4535 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 4536 | |
5287ad62 JB |
4537 | /* Bignums have their least significant bits in |
4538 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
4539 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4540 | gas_assert (parts != 0); |
95b75c01 NC |
4541 | |
4542 | /* Make sure that the number is not too big. | |
4543 | PR 11972: Bignums can now be sign-extended to the | |
4544 | size of a .octa so check that the out of range bits | |
4545 | are all zero or all one. */ | |
4546 | if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64) | |
4547 | { | |
4548 | LITTLENUM_TYPE m = -1; | |
4549 | ||
4550 | if (generic_bignum[parts * 2] != 0 | |
4551 | && generic_bignum[parts * 2] != m) | |
4552 | return FAIL; | |
4553 | ||
4554 | for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++) | |
4555 | if (generic_bignum[j] != generic_bignum[j-1]) | |
4556 | return FAIL; | |
4557 | } | |
4558 | ||
5287ad62 JB |
4559 | inst.operands[i].imm = 0; |
4560 | for (j = 0; j < parts; j++, idx++) | |
4561 | inst.operands[i].imm |= generic_bignum[idx] | |
4562 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4563 | inst.operands[i].reg = 0; | |
4564 | for (j = 0; j < parts; j++, idx++) | |
4565 | inst.operands[i].reg |= generic_bignum[idx] | |
4566 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4567 | inst.operands[i].regisimm = 1; | |
4568 | } | |
4569 | else | |
4570 | return FAIL; | |
5f4273c7 | 4571 | |
5287ad62 JB |
4572 | *str = ptr; |
4573 | ||
4574 | return SUCCESS; | |
4575 | } | |
4576 | ||
c19d1205 ZW |
4577 | /* Returns the pseudo-register number of an FPA immediate constant, |
4578 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4579 | |
c19d1205 ZW |
4580 | static int |
4581 | parse_fpa_immediate (char ** str) | |
4582 | { | |
4583 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4584 | char * save_in; | |
4585 | expressionS exp; | |
4586 | int i; | |
4587 | int j; | |
b99bd4ef | 4588 | |
c19d1205 ZW |
4589 | /* First try and match exact strings, this is to guarantee |
4590 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4591 | |
c19d1205 ZW |
4592 | for (i = 0; fp_const[i]; i++) |
4593 | { | |
4594 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4595 | { |
c19d1205 | 4596 | char *start = *str; |
b99bd4ef | 4597 | |
c19d1205 ZW |
4598 | *str += strlen (fp_const[i]); |
4599 | if (is_end_of_line[(unsigned char) **str]) | |
4600 | return i + 8; | |
4601 | *str = start; | |
4602 | } | |
4603 | } | |
b99bd4ef | 4604 | |
c19d1205 ZW |
4605 | /* Just because we didn't get a match doesn't mean that the constant |
4606 | isn't valid, just that it is in a format that we don't | |
4607 | automatically recognize. Try parsing it with the standard | |
4608 | expression routines. */ | |
b99bd4ef | 4609 | |
c19d1205 | 4610 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4611 | |
c19d1205 ZW |
4612 | /* Look for a raw floating point number. */ |
4613 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4614 | && is_end_of_line[(unsigned char) *save_in]) | |
4615 | { | |
4616 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4617 | { | |
4618 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4619 | { |
c19d1205 ZW |
4620 | if (words[j] != fp_values[i][j]) |
4621 | break; | |
b99bd4ef NC |
4622 | } |
4623 | ||
c19d1205 | 4624 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4625 | { |
c19d1205 ZW |
4626 | *str = save_in; |
4627 | return i + 8; | |
b99bd4ef NC |
4628 | } |
4629 | } | |
4630 | } | |
b99bd4ef | 4631 | |
c19d1205 ZW |
4632 | /* Try and parse a more complex expression, this will probably fail |
4633 | unless the code uses a floating point prefix (eg "0f"). */ | |
4634 | save_in = input_line_pointer; | |
4635 | input_line_pointer = *str; | |
4636 | if (expression (&exp) == absolute_section | |
4637 | && exp.X_op == O_big | |
4638 | && exp.X_add_number < 0) | |
4639 | { | |
4640 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4641 | Ditto for 15. */ | |
4642 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4643 | { | |
4644 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4645 | { | |
4646 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4647 | { | |
4648 | if (words[j] != fp_values[i][j]) | |
4649 | break; | |
4650 | } | |
b99bd4ef | 4651 | |
c19d1205 ZW |
4652 | if (j == MAX_LITTLENUMS) |
4653 | { | |
4654 | *str = input_line_pointer; | |
4655 | input_line_pointer = save_in; | |
4656 | return i + 8; | |
4657 | } | |
4658 | } | |
4659 | } | |
b99bd4ef NC |
4660 | } |
4661 | ||
c19d1205 ZW |
4662 | *str = input_line_pointer; |
4663 | input_line_pointer = save_in; | |
4664 | inst.error = _("invalid FPA immediate expression"); | |
4665 | return FAIL; | |
b99bd4ef NC |
4666 | } |
4667 | ||
136da414 JB |
4668 | /* Returns 1 if a number has "quarter-precision" float format |
4669 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4670 | ||
4671 | static int | |
4672 | is_quarter_float (unsigned imm) | |
4673 | { | |
4674 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4675 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4676 | } | |
4677 | ||
4678 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4679 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4680 | The zero and minus-zero cases need special handling, since they can't be |
4681 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4682 | loaded as integer constants. */ | |
136da414 JB |
4683 | |
4684 | static unsigned | |
4685 | parse_qfloat_immediate (char **ccp, int *immed) | |
4686 | { | |
4687 | char *str = *ccp; | |
c96612cc | 4688 | char *fpnum; |
136da414 | 4689 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4690 | int found_fpchar = 0; |
5f4273c7 | 4691 | |
136da414 | 4692 | skip_past_char (&str, '#'); |
5f4273c7 | 4693 | |
c96612cc JB |
4694 | /* We must not accidentally parse an integer as a floating-point number. Make |
4695 | sure that the value we parse is not an integer by checking for special | |
4696 | characters '.' or 'e'. | |
4697 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4698 | information isn't in a very usable state at parse time. */ | |
4699 | fpnum = str; | |
4700 | skip_whitespace (fpnum); | |
4701 | ||
4702 | if (strncmp (fpnum, "0x", 2) == 0) | |
4703 | return FAIL; | |
4704 | else | |
4705 | { | |
4706 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
4707 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') | |
4708 | { | |
4709 | found_fpchar = 1; | |
4710 | break; | |
4711 | } | |
4712 | ||
4713 | if (!found_fpchar) | |
4714 | return FAIL; | |
4715 | } | |
5f4273c7 | 4716 | |
136da414 JB |
4717 | if ((str = atof_ieee (str, 's', words)) != NULL) |
4718 | { | |
4719 | unsigned fpword = 0; | |
4720 | int i; | |
5f4273c7 | 4721 | |
136da414 JB |
4722 | /* Our FP word must be 32 bits (single-precision FP). */ |
4723 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4724 | { | |
4725 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4726 | fpword |= words[i]; | |
4727 | } | |
5f4273c7 | 4728 | |
c96612cc | 4729 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
136da414 JB |
4730 | *immed = fpword; |
4731 | else | |
4732 | return FAIL; | |
4733 | ||
4734 | *ccp = str; | |
5f4273c7 | 4735 | |
136da414 JB |
4736 | return SUCCESS; |
4737 | } | |
5f4273c7 | 4738 | |
136da414 JB |
4739 | return FAIL; |
4740 | } | |
4741 | ||
c19d1205 ZW |
4742 | /* Shift operands. */ |
4743 | enum shift_kind | |
b99bd4ef | 4744 | { |
c19d1205 ZW |
4745 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4746 | }; | |
b99bd4ef | 4747 | |
c19d1205 ZW |
4748 | struct asm_shift_name |
4749 | { | |
4750 | const char *name; | |
4751 | enum shift_kind kind; | |
4752 | }; | |
b99bd4ef | 4753 | |
c19d1205 ZW |
4754 | /* Third argument to parse_shift. */ |
4755 | enum parse_shift_mode | |
4756 | { | |
4757 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4758 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4759 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4760 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4761 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4762 | }; | |
b99bd4ef | 4763 | |
c19d1205 ZW |
4764 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4765 | This has three forms: | |
b99bd4ef | 4766 | |
c19d1205 ZW |
4767 | (LSL|LSR|ASL|ASR|ROR) Rs |
4768 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4769 | RRX | |
b99bd4ef | 4770 | |
c19d1205 ZW |
4771 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4772 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4773 | |
c19d1205 ZW |
4774 | static int |
4775 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4776 | { |
c19d1205 ZW |
4777 | const struct asm_shift_name *shift_name; |
4778 | enum shift_kind shift; | |
4779 | char *s = *str; | |
4780 | char *p = s; | |
4781 | int reg; | |
b99bd4ef | 4782 | |
c19d1205 ZW |
4783 | for (p = *str; ISALPHA (*p); p++) |
4784 | ; | |
b99bd4ef | 4785 | |
c19d1205 | 4786 | if (p == *str) |
b99bd4ef | 4787 | { |
c19d1205 ZW |
4788 | inst.error = _("shift expression expected"); |
4789 | return FAIL; | |
b99bd4ef NC |
4790 | } |
4791 | ||
21d799b5 NC |
4792 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
4793 | p - *str); | |
c19d1205 ZW |
4794 | |
4795 | if (shift_name == NULL) | |
b99bd4ef | 4796 | { |
c19d1205 ZW |
4797 | inst.error = _("shift expression expected"); |
4798 | return FAIL; | |
b99bd4ef NC |
4799 | } |
4800 | ||
c19d1205 | 4801 | shift = shift_name->kind; |
b99bd4ef | 4802 | |
c19d1205 ZW |
4803 | switch (mode) |
4804 | { | |
4805 | case NO_SHIFT_RESTRICT: | |
4806 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4807 | |
c19d1205 ZW |
4808 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4809 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4810 | { | |
4811 | inst.error = _("'LSL' or 'ASR' required"); | |
4812 | return FAIL; | |
4813 | } | |
4814 | break; | |
b99bd4ef | 4815 | |
c19d1205 ZW |
4816 | case SHIFT_LSL_IMMEDIATE: |
4817 | if (shift != SHIFT_LSL) | |
4818 | { | |
4819 | inst.error = _("'LSL' required"); | |
4820 | return FAIL; | |
4821 | } | |
4822 | break; | |
b99bd4ef | 4823 | |
c19d1205 ZW |
4824 | case SHIFT_ASR_IMMEDIATE: |
4825 | if (shift != SHIFT_ASR) | |
4826 | { | |
4827 | inst.error = _("'ASR' required"); | |
4828 | return FAIL; | |
4829 | } | |
4830 | break; | |
b99bd4ef | 4831 | |
c19d1205 ZW |
4832 | default: abort (); |
4833 | } | |
b99bd4ef | 4834 | |
c19d1205 ZW |
4835 | if (shift != SHIFT_RRX) |
4836 | { | |
4837 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4838 | skip_whitespace (p); | |
b99bd4ef | 4839 | |
c19d1205 | 4840 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4841 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4842 | { |
4843 | inst.operands[i].imm = reg; | |
4844 | inst.operands[i].immisreg = 1; | |
4845 | } | |
4846 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4847 | return FAIL; | |
4848 | } | |
4849 | inst.operands[i].shift_kind = shift; | |
4850 | inst.operands[i].shifted = 1; | |
4851 | *str = p; | |
4852 | return SUCCESS; | |
b99bd4ef NC |
4853 | } |
4854 | ||
c19d1205 | 4855 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4856 | |
c19d1205 ZW |
4857 | #<immediate> |
4858 | #<immediate>, <rotate> | |
4859 | <Rm> | |
4860 | <Rm>, <shift> | |
b99bd4ef | 4861 | |
c19d1205 ZW |
4862 | where <shift> is defined by parse_shift above, and <rotate> is a |
4863 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4864 | is deferred to md_apply_fix. */ |
b99bd4ef | 4865 | |
c19d1205 ZW |
4866 | static int |
4867 | parse_shifter_operand (char **str, int i) | |
4868 | { | |
4869 | int value; | |
91d6fa6a | 4870 | expressionS exp; |
b99bd4ef | 4871 | |
dcbf9037 | 4872 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4873 | { |
4874 | inst.operands[i].reg = value; | |
4875 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4876 | |
c19d1205 ZW |
4877 | /* parse_shift will override this if appropriate */ |
4878 | inst.reloc.exp.X_op = O_constant; | |
4879 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4880 | |
c19d1205 ZW |
4881 | if (skip_past_comma (str) == FAIL) |
4882 | return SUCCESS; | |
b99bd4ef | 4883 | |
c19d1205 ZW |
4884 | /* Shift operation on register. */ |
4885 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4886 | } |
4887 | ||
c19d1205 ZW |
4888 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4889 | return FAIL; | |
b99bd4ef | 4890 | |
c19d1205 | 4891 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4892 | { |
c19d1205 | 4893 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 4894 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 4895 | return FAIL; |
b99bd4ef | 4896 | |
91d6fa6a | 4897 | if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
c19d1205 ZW |
4898 | { |
4899 | inst.error = _("constant expression expected"); | |
4900 | return FAIL; | |
4901 | } | |
b99bd4ef | 4902 | |
91d6fa6a | 4903 | value = exp.X_add_number; |
c19d1205 ZW |
4904 | if (value < 0 || value > 30 || value % 2 != 0) |
4905 | { | |
4906 | inst.error = _("invalid rotation"); | |
4907 | return FAIL; | |
4908 | } | |
4909 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4910 | { | |
4911 | inst.error = _("invalid constant"); | |
4912 | return FAIL; | |
4913 | } | |
09d92015 | 4914 | |
a415b1cd JB |
4915 | /* Encode as specified. */ |
4916 | inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7; | |
4917 | return SUCCESS; | |
09d92015 MM |
4918 | } |
4919 | ||
c19d1205 ZW |
4920 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4921 | inst.reloc.pc_rel = 0; | |
4922 | return SUCCESS; | |
09d92015 MM |
4923 | } |
4924 | ||
4962c51a MS |
4925 | /* Group relocation information. Each entry in the table contains the |
4926 | textual name of the relocation as may appear in assembler source | |
4927 | and must end with a colon. | |
4928 | Along with this textual name are the relocation codes to be used if | |
4929 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4930 | an LDR, an LDRS, or an LDC. */ | |
4931 | ||
4932 | struct group_reloc_table_entry | |
4933 | { | |
4934 | const char *name; | |
4935 | int alu_code; | |
4936 | int ldr_code; | |
4937 | int ldrs_code; | |
4938 | int ldc_code; | |
4939 | }; | |
4940 | ||
4941 | typedef enum | |
4942 | { | |
4943 | /* Varieties of non-ALU group relocation. */ | |
4944 | ||
4945 | GROUP_LDR, | |
4946 | GROUP_LDRS, | |
4947 | GROUP_LDC | |
4948 | } group_reloc_type; | |
4949 | ||
4950 | static struct group_reloc_table_entry group_reloc_table[] = | |
4951 | { /* Program counter relative: */ | |
4952 | { "pc_g0_nc", | |
4953 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4954 | 0, /* LDR */ | |
4955 | 0, /* LDRS */ | |
4956 | 0 }, /* LDC */ | |
4957 | { "pc_g0", | |
4958 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4959 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4960 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4961 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4962 | { "pc_g1_nc", | |
4963 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4964 | 0, /* LDR */ | |
4965 | 0, /* LDRS */ | |
4966 | 0 }, /* LDC */ | |
4967 | { "pc_g1", | |
4968 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4969 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4970 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4971 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4972 | { "pc_g2", | |
4973 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4974 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4975 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4976 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4977 | /* Section base relative */ | |
4978 | { "sb_g0_nc", | |
4979 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4980 | 0, /* LDR */ | |
4981 | 0, /* LDRS */ | |
4982 | 0 }, /* LDC */ | |
4983 | { "sb_g0", | |
4984 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4985 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4986 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4987 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4988 | { "sb_g1_nc", | |
4989 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4990 | 0, /* LDR */ | |
4991 | 0, /* LDRS */ | |
4992 | 0 }, /* LDC */ | |
4993 | { "sb_g1", | |
4994 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4995 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4996 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4997 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4998 | { "sb_g2", | |
4999 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
5000 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
5001 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
5002 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
5003 | ||
5004 | /* Given the address of a pointer pointing to the textual name of a group | |
5005 | relocation as may appear in assembler source, attempt to find its details | |
5006 | in group_reloc_table. The pointer will be updated to the character after | |
5007 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
5008 | otherwise. On success, *entry will be updated to point at the relevant | |
5009 | group_reloc_table entry. */ | |
5010 | ||
5011 | static int | |
5012 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
5013 | { | |
5014 | unsigned int i; | |
5015 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
5016 | { | |
5017 | int length = strlen (group_reloc_table[i].name); | |
5018 | ||
5f4273c7 NC |
5019 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5020 | && (*str)[length] == ':') | |
4962c51a MS |
5021 | { |
5022 | *out = &group_reloc_table[i]; | |
5023 | *str += (length + 1); | |
5024 | return SUCCESS; | |
5025 | } | |
5026 | } | |
5027 | ||
5028 | return FAIL; | |
5029 | } | |
5030 | ||
5031 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
5032 | (as for parse_shifter_operand) where group relocations are allowed: | |
5033 | ||
5034 | #<immediate> | |
5035 | #<immediate>, <rotate> | |
5036 | #:<group_reloc>:<expression> | |
5037 | <Rm> | |
5038 | <Rm>, <shift> | |
5039 | ||
5040 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
5041 | The hashes are optional. | |
5042 | ||
5043 | Everything else is as for parse_shifter_operand. */ | |
5044 | ||
5045 | static parse_operand_result | |
5046 | parse_shifter_operand_group_reloc (char **str, int i) | |
5047 | { | |
5048 | /* Determine if we have the sequence of characters #: or just : | |
5049 | coming next. If we do, then we check for a group relocation. | |
5050 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
5051 | ||
5052 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
5053 | || (*str)[0] == ':') | |
5054 | { | |
5055 | struct group_reloc_table_entry *entry; | |
5056 | ||
5057 | if ((*str)[0] == '#') | |
5058 | (*str) += 2; | |
5059 | else | |
5060 | (*str)++; | |
5061 | ||
5062 | /* Try to parse a group relocation. Anything else is an error. */ | |
5063 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
5064 | { | |
5065 | inst.error = _("unknown group relocation"); | |
5066 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5067 | } | |
5068 | ||
5069 | /* We now have the group relocation table entry corresponding to | |
5070 | the name in the assembler source. Next, we parse the expression. */ | |
5071 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
5072 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5073 | ||
5074 | /* Record the relocation type (always the ALU variant here). */ | |
21d799b5 | 5075 | inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code; |
9c2799c2 | 5076 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
5077 | |
5078 | return PARSE_OPERAND_SUCCESS; | |
5079 | } | |
5080 | else | |
5081 | return parse_shifter_operand (str, i) == SUCCESS | |
5082 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
5083 | ||
5084 | /* Never reached. */ | |
5085 | } | |
5086 | ||
8e560766 MGD |
5087 | /* Parse a Neon alignment expression. Information is written to |
5088 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5089 | |
8e560766 MGD |
5090 | align .imm = align << 8, .immisalign=1, .preind=0 */ |
5091 | static parse_operand_result | |
5092 | parse_neon_alignment (char **str, int i) | |
5093 | { | |
5094 | char *p = *str; | |
5095 | expressionS exp; | |
5096 | ||
5097 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5098 | ||
5099 | if (exp.X_op != O_constant) | |
5100 | { | |
5101 | inst.error = _("alignment must be constant"); | |
5102 | return PARSE_OPERAND_FAIL; | |
5103 | } | |
5104 | ||
5105 | inst.operands[i].imm = exp.X_add_number << 8; | |
5106 | inst.operands[i].immisalign = 1; | |
5107 | /* Alignments are not pre-indexes. */ | |
5108 | inst.operands[i].preind = 0; | |
5109 | ||
5110 | *str = p; | |
5111 | return PARSE_OPERAND_SUCCESS; | |
5112 | } | |
5113 | ||
c19d1205 ZW |
5114 | /* Parse all forms of an ARM address expression. Information is written |
5115 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 5116 | |
c19d1205 | 5117 | Preindexed addressing (.preind=1): |
09d92015 | 5118 | |
c19d1205 ZW |
5119 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
5120 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5121 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5122 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5123 | |
c19d1205 | 5124 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5125 | |
c19d1205 | 5126 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5127 | |
c19d1205 ZW |
5128 | [Rn], #offset .reg=Rn .reloc.exp=offset |
5129 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5130 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5131 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5132 | |
c19d1205 | 5133 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5134 | |
c19d1205 | 5135 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5136 | |
c19d1205 | 5137 | Other: |
09d92015 | 5138 | |
c19d1205 ZW |
5139 | [Rn]{!} shorthand for [Rn,#0]{!} |
5140 | =immediate .isreg=0 .reloc.exp=immediate | |
5141 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 5142 | |
c19d1205 ZW |
5143 | It is the caller's responsibility to check for addressing modes not |
5144 | supported by the instruction, and to set inst.reloc.type. */ | |
5145 | ||
4962c51a MS |
5146 | static parse_operand_result |
5147 | parse_address_main (char **str, int i, int group_relocations, | |
5148 | group_reloc_type group_type) | |
09d92015 | 5149 | { |
c19d1205 ZW |
5150 | char *p = *str; |
5151 | int reg; | |
09d92015 | 5152 | |
c19d1205 | 5153 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5154 | { |
c19d1205 ZW |
5155 | if (skip_past_char (&p, '=') == FAIL) |
5156 | { | |
974da60d | 5157 | /* Bare address - translate to PC-relative offset. */ |
c19d1205 ZW |
5158 | inst.reloc.pc_rel = 1; |
5159 | inst.operands[i].reg = REG_PC; | |
5160 | inst.operands[i].isreg = 1; | |
5161 | inst.operands[i].preind = 1; | |
5162 | } | |
974da60d | 5163 | /* Otherwise a load-constant pseudo op, no special treatment needed here. */ |
09d92015 | 5164 | |
c19d1205 | 5165 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 5166 | return PARSE_OPERAND_FAIL; |
09d92015 | 5167 | |
c19d1205 | 5168 | *str = p; |
4962c51a | 5169 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5170 | } |
5171 | ||
8ab8155f NC |
5172 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5173 | skip_whitespace (p); | |
5174 | ||
dcbf9037 | 5175 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 5176 | { |
c19d1205 | 5177 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 5178 | return PARSE_OPERAND_FAIL; |
09d92015 | 5179 | } |
c19d1205 ZW |
5180 | inst.operands[i].reg = reg; |
5181 | inst.operands[i].isreg = 1; | |
09d92015 | 5182 | |
c19d1205 | 5183 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5184 | { |
c19d1205 | 5185 | inst.operands[i].preind = 1; |
09d92015 | 5186 | |
c19d1205 ZW |
5187 | if (*p == '+') p++; |
5188 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5189 | ||
dcbf9037 | 5190 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5191 | { |
c19d1205 ZW |
5192 | inst.operands[i].imm = reg; |
5193 | inst.operands[i].immisreg = 1; | |
5194 | ||
5195 | if (skip_past_comma (&p) == SUCCESS) | |
5196 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5197 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5198 | } |
5287ad62 | 5199 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5200 | { |
5201 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5202 | code before we get to see it here. This may be subject to | |
5203 | change. */ | |
5204 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5205 | |
8e560766 MGD |
5206 | if (result != PARSE_OPERAND_SUCCESS) |
5207 | return result; | |
5208 | } | |
c19d1205 ZW |
5209 | else |
5210 | { | |
5211 | if (inst.operands[i].negative) | |
5212 | { | |
5213 | inst.operands[i].negative = 0; | |
5214 | p--; | |
5215 | } | |
4962c51a | 5216 | |
5f4273c7 NC |
5217 | if (group_relocations |
5218 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5219 | { |
5220 | struct group_reloc_table_entry *entry; | |
5221 | ||
5222 | /* Skip over the #: or : sequence. */ | |
5223 | if (*p == '#') | |
5224 | p += 2; | |
5225 | else | |
5226 | p++; | |
5227 | ||
5228 | /* Try to parse a group relocation. Anything else is an | |
5229 | error. */ | |
5230 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
5231 | { | |
5232 | inst.error = _("unknown group relocation"); | |
5233 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5234 | } | |
5235 | ||
5236 | /* We now have the group relocation table entry corresponding to | |
5237 | the name in the assembler source. Next, we parse the | |
5238 | expression. */ | |
5239 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5240 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5241 | ||
5242 | /* Record the relocation type. */ | |
5243 | switch (group_type) | |
5244 | { | |
5245 | case GROUP_LDR: | |
21d799b5 | 5246 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code; |
4962c51a MS |
5247 | break; |
5248 | ||
5249 | case GROUP_LDRS: | |
21d799b5 | 5250 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code; |
4962c51a MS |
5251 | break; |
5252 | ||
5253 | case GROUP_LDC: | |
21d799b5 | 5254 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code; |
4962c51a MS |
5255 | break; |
5256 | ||
5257 | default: | |
9c2799c2 | 5258 | gas_assert (0); |
4962c51a MS |
5259 | } |
5260 | ||
5261 | if (inst.reloc.type == 0) | |
5262 | { | |
5263 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5264 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5265 | } | |
5266 | } | |
5267 | else | |
26d97720 NS |
5268 | { |
5269 | char *q = p; | |
5270 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5271 | return PARSE_OPERAND_FAIL; | |
5272 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
5273 | if (inst.reloc.exp.X_op == O_constant | |
5274 | && inst.reloc.exp.X_add_number == 0) | |
5275 | { | |
5276 | skip_whitespace (q); | |
5277 | if (*q == '#') | |
5278 | { | |
5279 | q++; | |
5280 | skip_whitespace (q); | |
5281 | } | |
5282 | if (*q == '-') | |
5283 | inst.operands[i].negative = 1; | |
5284 | } | |
5285 | } | |
09d92015 MM |
5286 | } |
5287 | } | |
8e560766 MGD |
5288 | else if (skip_past_char (&p, ':') == SUCCESS) |
5289 | { | |
5290 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
5291 | before we get to see it here. This may be subject to change. */ | |
5292 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5293 | |
8e560766 MGD |
5294 | if (result != PARSE_OPERAND_SUCCESS) |
5295 | return result; | |
5296 | } | |
09d92015 | 5297 | |
c19d1205 | 5298 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5299 | { |
c19d1205 | 5300 | inst.error = _("']' expected"); |
4962c51a | 5301 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5302 | } |
5303 | ||
c19d1205 ZW |
5304 | if (skip_past_char (&p, '!') == SUCCESS) |
5305 | inst.operands[i].writeback = 1; | |
09d92015 | 5306 | |
c19d1205 | 5307 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5308 | { |
c19d1205 ZW |
5309 | if (skip_past_char (&p, '{') == SUCCESS) |
5310 | { | |
5311 | /* [Rn], {expr} - unindexed, with option */ | |
5312 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5313 | 0, 255, TRUE) == FAIL) |
4962c51a | 5314 | return PARSE_OPERAND_FAIL; |
09d92015 | 5315 | |
c19d1205 ZW |
5316 | if (skip_past_char (&p, '}') == FAIL) |
5317 | { | |
5318 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5319 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5320 | } |
5321 | if (inst.operands[i].preind) | |
5322 | { | |
5323 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5324 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5325 | } |
5326 | *str = p; | |
4962c51a | 5327 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5328 | } |
c19d1205 ZW |
5329 | else |
5330 | { | |
5331 | inst.operands[i].postind = 1; | |
5332 | inst.operands[i].writeback = 1; | |
09d92015 | 5333 | |
c19d1205 ZW |
5334 | if (inst.operands[i].preind) |
5335 | { | |
5336 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5337 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5338 | } |
09d92015 | 5339 | |
c19d1205 ZW |
5340 | if (*p == '+') p++; |
5341 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5342 | |
dcbf9037 | 5343 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5344 | { |
5287ad62 JB |
5345 | /* We might be using the immediate for alignment already. If we |
5346 | are, OR the register number into the low-order bits. */ | |
5347 | if (inst.operands[i].immisalign) | |
5348 | inst.operands[i].imm |= reg; | |
5349 | else | |
5350 | inst.operands[i].imm = reg; | |
c19d1205 | 5351 | inst.operands[i].immisreg = 1; |
a737bd4d | 5352 | |
c19d1205 ZW |
5353 | if (skip_past_comma (&p) == SUCCESS) |
5354 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5355 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5356 | } |
5357 | else | |
5358 | { | |
26d97720 | 5359 | char *q = p; |
c19d1205 ZW |
5360 | if (inst.operands[i].negative) |
5361 | { | |
5362 | inst.operands[i].negative = 0; | |
5363 | p--; | |
5364 | } | |
5365 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5366 | return PARSE_OPERAND_FAIL; |
26d97720 NS |
5367 | /* If the offset is 0, find out if it's a +0 or -0. */ |
5368 | if (inst.reloc.exp.X_op == O_constant | |
5369 | && inst.reloc.exp.X_add_number == 0) | |
5370 | { | |
5371 | skip_whitespace (q); | |
5372 | if (*q == '#') | |
5373 | { | |
5374 | q++; | |
5375 | skip_whitespace (q); | |
5376 | } | |
5377 | if (*q == '-') | |
5378 | inst.operands[i].negative = 1; | |
5379 | } | |
c19d1205 ZW |
5380 | } |
5381 | } | |
a737bd4d NC |
5382 | } |
5383 | ||
c19d1205 ZW |
5384 | /* If at this point neither .preind nor .postind is set, we have a |
5385 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5386 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5387 | { | |
5388 | inst.operands[i].preind = 1; | |
5389 | inst.reloc.exp.X_op = O_constant; | |
5390 | inst.reloc.exp.X_add_number = 0; | |
5391 | } | |
5392 | *str = p; | |
4962c51a MS |
5393 | return PARSE_OPERAND_SUCCESS; |
5394 | } | |
5395 | ||
5396 | static int | |
5397 | parse_address (char **str, int i) | |
5398 | { | |
21d799b5 | 5399 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
4962c51a MS |
5400 | ? SUCCESS : FAIL; |
5401 | } | |
5402 | ||
5403 | static parse_operand_result | |
5404 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5405 | { | |
5406 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5407 | } |
5408 | ||
b6895b4f PB |
5409 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5410 | static int | |
5411 | parse_half (char **str) | |
5412 | { | |
5413 | char * p; | |
5f4273c7 | 5414 | |
b6895b4f PB |
5415 | p = *str; |
5416 | skip_past_char (&p, '#'); | |
5f4273c7 | 5417 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5418 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5419 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5420 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5421 | ||
5422 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5423 | { | |
5424 | p += 9; | |
5f4273c7 | 5425 | skip_whitespace (p); |
b6895b4f PB |
5426 | } |
5427 | ||
5428 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5429 | return FAIL; | |
5430 | ||
5431 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5432 | { | |
5433 | if (inst.reloc.exp.X_op != O_constant) | |
5434 | { | |
5435 | inst.error = _("constant expression expected"); | |
5436 | return FAIL; | |
5437 | } | |
5438 | if (inst.reloc.exp.X_add_number < 0 | |
5439 | || inst.reloc.exp.X_add_number > 0xffff) | |
5440 | { | |
5441 | inst.error = _("immediate value out of range"); | |
5442 | return FAIL; | |
5443 | } | |
5444 | } | |
5445 | *str = p; | |
5446 | return SUCCESS; | |
5447 | } | |
5448 | ||
c19d1205 | 5449 | /* Miscellaneous. */ |
a737bd4d | 5450 | |
c19d1205 ZW |
5451 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5452 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5453 | static int | |
d2cd1205 | 5454 | parse_psr (char **str, bfd_boolean lhs) |
09d92015 | 5455 | { |
c19d1205 ZW |
5456 | char *p; |
5457 | unsigned long psr_field; | |
62b3e311 PB |
5458 | const struct asm_psr *psr; |
5459 | char *start; | |
d2cd1205 | 5460 | bfd_boolean is_apsr = FALSE; |
ac7f631b | 5461 | bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); |
09d92015 | 5462 | |
a4482bb6 NC |
5463 | /* PR gas/12698: If the user has specified -march=all then m_profile will |
5464 | be TRUE, but we want to ignore it in this case as we are building for any | |
5465 | CPU type, including non-m variants. */ | |
5466 | if (selected_cpu.core == arm_arch_any.core) | |
5467 | m_profile = FALSE; | |
5468 | ||
c19d1205 ZW |
5469 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5470 | feature for ease of use and backwards compatibility. */ | |
5471 | p = *str; | |
62b3e311 | 5472 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
5473 | { |
5474 | if (m_profile) | |
5475 | goto unsupported_psr; | |
fa94de6b | 5476 | |
d2cd1205 JB |
5477 | psr_field = SPSR_BIT; |
5478 | } | |
5479 | else if (strncasecmp (p, "CPSR", 4) == 0) | |
5480 | { | |
5481 | if (m_profile) | |
5482 | goto unsupported_psr; | |
5483 | ||
5484 | psr_field = 0; | |
5485 | } | |
5486 | else if (strncasecmp (p, "APSR", 4) == 0) | |
5487 | { | |
5488 | /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A | |
5489 | and ARMv7-R architecture CPUs. */ | |
5490 | is_apsr = TRUE; | |
5491 | psr_field = 0; | |
5492 | } | |
5493 | else if (m_profile) | |
62b3e311 PB |
5494 | { |
5495 | start = p; | |
5496 | do | |
5497 | p++; | |
5498 | while (ISALNUM (*p) || *p == '_'); | |
5499 | ||
d2cd1205 JB |
5500 | if (strncasecmp (start, "iapsr", 5) == 0 |
5501 | || strncasecmp (start, "eapsr", 5) == 0 | |
5502 | || strncasecmp (start, "xpsr", 4) == 0 | |
5503 | || strncasecmp (start, "psr", 3) == 0) | |
5504 | p = start + strcspn (start, "rR") + 1; | |
5505 | ||
21d799b5 NC |
5506 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
5507 | p - start); | |
d2cd1205 | 5508 | |
62b3e311 PB |
5509 | if (!psr) |
5510 | return FAIL; | |
09d92015 | 5511 | |
d2cd1205 JB |
5512 | /* If APSR is being written, a bitfield may be specified. Note that |
5513 | APSR itself is handled above. */ | |
5514 | if (psr->field <= 3) | |
5515 | { | |
5516 | psr_field = psr->field; | |
5517 | is_apsr = TRUE; | |
5518 | goto check_suffix; | |
5519 | } | |
5520 | ||
62b3e311 | 5521 | *str = p; |
d2cd1205 JB |
5522 | /* M-profile MSR instructions have the mask field set to "10", except |
5523 | *PSR variants which modify APSR, which may use a different mask (and | |
5524 | have been handled already). Do that by setting the PSR_f field | |
5525 | here. */ | |
5526 | return psr->field | (lhs ? PSR_f : 0); | |
62b3e311 | 5527 | } |
d2cd1205 JB |
5528 | else |
5529 | goto unsupported_psr; | |
09d92015 | 5530 | |
62b3e311 | 5531 | p += 4; |
d2cd1205 | 5532 | check_suffix: |
c19d1205 ZW |
5533 | if (*p == '_') |
5534 | { | |
5535 | /* A suffix follows. */ | |
c19d1205 ZW |
5536 | p++; |
5537 | start = p; | |
a737bd4d | 5538 | |
c19d1205 ZW |
5539 | do |
5540 | p++; | |
5541 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5542 | |
d2cd1205 JB |
5543 | if (is_apsr) |
5544 | { | |
5545 | /* APSR uses a notation for bits, rather than fields. */ | |
5546 | unsigned int nzcvq_bits = 0; | |
5547 | unsigned int g_bit = 0; | |
5548 | char *bit; | |
fa94de6b | 5549 | |
d2cd1205 JB |
5550 | for (bit = start; bit != p; bit++) |
5551 | { | |
5552 | switch (TOLOWER (*bit)) | |
5553 | { | |
5554 | case 'n': | |
5555 | nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01; | |
5556 | break; | |
5557 | ||
5558 | case 'z': | |
5559 | nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02; | |
5560 | break; | |
5561 | ||
5562 | case 'c': | |
5563 | nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04; | |
5564 | break; | |
5565 | ||
5566 | case 'v': | |
5567 | nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08; | |
5568 | break; | |
fa94de6b | 5569 | |
d2cd1205 JB |
5570 | case 'q': |
5571 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
5572 | break; | |
fa94de6b | 5573 | |
d2cd1205 JB |
5574 | case 'g': |
5575 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
5576 | break; | |
fa94de6b | 5577 | |
d2cd1205 JB |
5578 | default: |
5579 | inst.error = _("unexpected bit specified after APSR"); | |
5580 | return FAIL; | |
5581 | } | |
5582 | } | |
fa94de6b | 5583 | |
d2cd1205 JB |
5584 | if (nzcvq_bits == 0x1f) |
5585 | psr_field |= PSR_f; | |
fa94de6b | 5586 | |
d2cd1205 JB |
5587 | if (g_bit == 0x1) |
5588 | { | |
5589 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
5590 | { | |
5591 | inst.error = _("selected processor does not " | |
5592 | "support DSP extension"); | |
5593 | return FAIL; | |
5594 | } | |
5595 | ||
5596 | psr_field |= PSR_s; | |
5597 | } | |
fa94de6b | 5598 | |
d2cd1205 JB |
5599 | if ((nzcvq_bits & 0x20) != 0 |
5600 | || (nzcvq_bits != 0x1f && nzcvq_bits != 0) | |
5601 | || (g_bit & 0x2) != 0) | |
5602 | { | |
5603 | inst.error = _("bad bitmask specified after APSR"); | |
5604 | return FAIL; | |
5605 | } | |
5606 | } | |
5607 | else | |
5608 | { | |
5609 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, | |
5610 | p - start); | |
5611 | if (!psr) | |
5612 | goto error; | |
a737bd4d | 5613 | |
d2cd1205 JB |
5614 | psr_field |= psr->field; |
5615 | } | |
a737bd4d | 5616 | } |
c19d1205 | 5617 | else |
a737bd4d | 5618 | { |
c19d1205 ZW |
5619 | if (ISALNUM (*p)) |
5620 | goto error; /* Garbage after "[CS]PSR". */ | |
5621 | ||
d2cd1205 JB |
5622 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
5623 | is deprecated, but allow it anyway. */ | |
5624 | if (is_apsr && lhs) | |
5625 | { | |
5626 | psr_field |= PSR_f; | |
5627 | as_tsktsk (_("writing to APSR without specifying a bitmask is " | |
5628 | "deprecated")); | |
5629 | } | |
5630 | else if (!m_profile) | |
5631 | /* These bits are never right for M-profile devices: don't set them | |
5632 | (only code paths which read/write APSR reach here). */ | |
5633 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5634 | } |
c19d1205 ZW |
5635 | *str = p; |
5636 | return psr_field; | |
a737bd4d | 5637 | |
d2cd1205 JB |
5638 | unsupported_psr: |
5639 | inst.error = _("selected processor does not support requested special " | |
5640 | "purpose register"); | |
5641 | return FAIL; | |
5642 | ||
c19d1205 ZW |
5643 | error: |
5644 | inst.error = _("flag for {c}psr instruction expected"); | |
5645 | return FAIL; | |
a737bd4d NC |
5646 | } |
5647 | ||
c19d1205 ZW |
5648 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5649 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5650 | |
c19d1205 ZW |
5651 | static int |
5652 | parse_cps_flags (char **str) | |
a737bd4d | 5653 | { |
c19d1205 ZW |
5654 | int val = 0; |
5655 | int saw_a_flag = 0; | |
5656 | char *s = *str; | |
a737bd4d | 5657 | |
c19d1205 ZW |
5658 | for (;;) |
5659 | switch (*s++) | |
5660 | { | |
5661 | case '\0': case ',': | |
5662 | goto done; | |
a737bd4d | 5663 | |
c19d1205 ZW |
5664 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5665 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5666 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5667 | |
c19d1205 ZW |
5668 | default: |
5669 | inst.error = _("unrecognized CPS flag"); | |
5670 | return FAIL; | |
5671 | } | |
a737bd4d | 5672 | |
c19d1205 ZW |
5673 | done: |
5674 | if (saw_a_flag == 0) | |
a737bd4d | 5675 | { |
c19d1205 ZW |
5676 | inst.error = _("missing CPS flags"); |
5677 | return FAIL; | |
a737bd4d | 5678 | } |
a737bd4d | 5679 | |
c19d1205 ZW |
5680 | *str = s - 1; |
5681 | return val; | |
a737bd4d NC |
5682 | } |
5683 | ||
c19d1205 ZW |
5684 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
5685 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
5686 | |
5687 | static int | |
c19d1205 | 5688 | parse_endian_specifier (char **str) |
a737bd4d | 5689 | { |
c19d1205 ZW |
5690 | int little_endian; |
5691 | char *s = *str; | |
a737bd4d | 5692 | |
c19d1205 ZW |
5693 | if (strncasecmp (s, "BE", 2)) |
5694 | little_endian = 0; | |
5695 | else if (strncasecmp (s, "LE", 2)) | |
5696 | little_endian = 1; | |
5697 | else | |
a737bd4d | 5698 | { |
c19d1205 | 5699 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5700 | return FAIL; |
5701 | } | |
5702 | ||
c19d1205 | 5703 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 5704 | { |
c19d1205 | 5705 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5706 | return FAIL; |
5707 | } | |
5708 | ||
c19d1205 ZW |
5709 | *str = s + 2; |
5710 | return little_endian; | |
5711 | } | |
a737bd4d | 5712 | |
c19d1205 ZW |
5713 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
5714 | value suitable for poking into the rotate field of an sxt or sxta | |
5715 | instruction, or FAIL on error. */ | |
5716 | ||
5717 | static int | |
5718 | parse_ror (char **str) | |
5719 | { | |
5720 | int rot; | |
5721 | char *s = *str; | |
5722 | ||
5723 | if (strncasecmp (s, "ROR", 3) == 0) | |
5724 | s += 3; | |
5725 | else | |
a737bd4d | 5726 | { |
c19d1205 | 5727 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
5728 | return FAIL; |
5729 | } | |
c19d1205 ZW |
5730 | |
5731 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
5732 | return FAIL; | |
5733 | ||
5734 | switch (rot) | |
a737bd4d | 5735 | { |
c19d1205 ZW |
5736 | case 0: *str = s; return 0x0; |
5737 | case 8: *str = s; return 0x1; | |
5738 | case 16: *str = s; return 0x2; | |
5739 | case 24: *str = s; return 0x3; | |
5740 | ||
5741 | default: | |
5742 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
5743 | return FAIL; |
5744 | } | |
c19d1205 | 5745 | } |
a737bd4d | 5746 | |
c19d1205 ZW |
5747 | /* Parse a conditional code (from conds[] below). The value returned is in the |
5748 | range 0 .. 14, or FAIL. */ | |
5749 | static int | |
5750 | parse_cond (char **str) | |
5751 | { | |
c462b453 | 5752 | char *q; |
c19d1205 | 5753 | const struct asm_cond *c; |
c462b453 PB |
5754 | int n; |
5755 | /* Condition codes are always 2 characters, so matching up to | |
5756 | 3 characters is sufficient. */ | |
5757 | char cond[3]; | |
a737bd4d | 5758 | |
c462b453 PB |
5759 | q = *str; |
5760 | n = 0; | |
5761 | while (ISALPHA (*q) && n < 3) | |
5762 | { | |
e07e6e58 | 5763 | cond[n] = TOLOWER (*q); |
c462b453 PB |
5764 | q++; |
5765 | n++; | |
5766 | } | |
a737bd4d | 5767 | |
21d799b5 | 5768 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 5769 | if (!c) |
a737bd4d | 5770 | { |
c19d1205 | 5771 | inst.error = _("condition required"); |
a737bd4d NC |
5772 | return FAIL; |
5773 | } | |
5774 | ||
c19d1205 ZW |
5775 | *str = q; |
5776 | return c->value; | |
5777 | } | |
5778 | ||
e797f7e0 MGD |
5779 | /* If the given feature available in the selected CPU, mark it as used. |
5780 | Returns TRUE iff feature is available. */ | |
5781 | static bfd_boolean | |
5782 | mark_feature_used (const arm_feature_set *feature) | |
5783 | { | |
5784 | /* Ensure the option is valid on the current architecture. */ | |
5785 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
5786 | return FALSE; | |
5787 | ||
5788 | /* Add the appropriate architecture feature for the barrier option used. | |
5789 | */ | |
5790 | if (thumb_mode) | |
5791 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature); | |
5792 | else | |
5793 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature); | |
5794 | ||
5795 | return TRUE; | |
5796 | } | |
5797 | ||
62b3e311 PB |
5798 | /* Parse an option for a barrier instruction. Returns the encoding for the |
5799 | option, or FAIL. */ | |
5800 | static int | |
5801 | parse_barrier (char **str) | |
5802 | { | |
5803 | char *p, *q; | |
5804 | const struct asm_barrier_opt *o; | |
5805 | ||
5806 | p = q = *str; | |
5807 | while (ISALPHA (*q)) | |
5808 | q++; | |
5809 | ||
21d799b5 NC |
5810 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
5811 | q - p); | |
62b3e311 PB |
5812 | if (!o) |
5813 | return FAIL; | |
5814 | ||
e797f7e0 MGD |
5815 | if (!mark_feature_used (&o->arch)) |
5816 | return FAIL; | |
5817 | ||
62b3e311 PB |
5818 | *str = q; |
5819 | return o->value; | |
5820 | } | |
5821 | ||
92e90b6e PB |
5822 | /* Parse the operands of a table branch instruction. Similar to a memory |
5823 | operand. */ | |
5824 | static int | |
5825 | parse_tb (char **str) | |
5826 | { | |
5827 | char * p = *str; | |
5828 | int reg; | |
5829 | ||
5830 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5831 | { |
5832 | inst.error = _("'[' expected"); | |
5833 | return FAIL; | |
5834 | } | |
92e90b6e | 5835 | |
dcbf9037 | 5836 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5837 | { |
5838 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5839 | return FAIL; | |
5840 | } | |
5841 | inst.operands[0].reg = reg; | |
5842 | ||
5843 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5844 | { |
5845 | inst.error = _("',' expected"); | |
5846 | return FAIL; | |
5847 | } | |
5f4273c7 | 5848 | |
dcbf9037 | 5849 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5850 | { |
5851 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5852 | return FAIL; | |
5853 | } | |
5854 | inst.operands[0].imm = reg; | |
5855 | ||
5856 | if (skip_past_comma (&p) == SUCCESS) | |
5857 | { | |
5858 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5859 | return FAIL; | |
5860 | if (inst.reloc.exp.X_add_number != 1) | |
5861 | { | |
5862 | inst.error = _("invalid shift"); | |
5863 | return FAIL; | |
5864 | } | |
5865 | inst.operands[0].shifted = 1; | |
5866 | } | |
5867 | ||
5868 | if (skip_past_char (&p, ']') == FAIL) | |
5869 | { | |
5870 | inst.error = _("']' expected"); | |
5871 | return FAIL; | |
5872 | } | |
5873 | *str = p; | |
5874 | return SUCCESS; | |
5875 | } | |
5876 | ||
5287ad62 JB |
5877 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5878 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5879 | Up to four operands may be read; this function handles setting the |
5880 | ".present" field for each read operand itself. | |
5287ad62 JB |
5881 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5882 | else returns FAIL. */ | |
5883 | ||
5884 | static int | |
5885 | parse_neon_mov (char **str, int *which_operand) | |
5886 | { | |
5887 | int i = *which_operand, val; | |
5888 | enum arm_reg_type rtype; | |
5889 | char *ptr = *str; | |
dcbf9037 | 5890 | struct neon_type_el optype; |
5f4273c7 | 5891 | |
dcbf9037 | 5892 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5893 | { |
5894 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5895 | inst.operands[i].reg = val; | |
5896 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5897 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5898 | inst.operands[i++].present = 1; |
5899 | ||
5900 | if (skip_past_comma (&ptr) == FAIL) | |
5901 | goto wanted_comma; | |
5f4273c7 | 5902 | |
dcbf9037 | 5903 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 | 5904 | goto wanted_arm; |
5f4273c7 | 5905 | |
5287ad62 JB |
5906 | inst.operands[i].reg = val; |
5907 | inst.operands[i].isreg = 1; | |
5908 | inst.operands[i].present = 1; | |
5909 | } | |
037e8744 | 5910 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5911 | != FAIL) |
5287ad62 JB |
5912 | { |
5913 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5914 | if (skip_past_comma (&ptr) == FAIL) | |
5915 | goto wanted_comma; | |
5f4273c7 | 5916 | |
5287ad62 JB |
5917 | inst.operands[i].reg = val; |
5918 | inst.operands[i].isreg = 1; | |
5919 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5920 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5921 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5922 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5923 | inst.operands[i++].present = 1; |
5924 | ||
dcbf9037 | 5925 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5926 | { |
037e8744 JB |
5927 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5928 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5929 | inst.operands[i].reg = val; |
5930 | inst.operands[i].isreg = 1; | |
037e8744 | 5931 | inst.operands[i].present = 1; |
5287ad62 JB |
5932 | |
5933 | if (rtype == REG_TYPE_NQ) | |
5934 | { | |
dcbf9037 | 5935 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5936 | return FAIL; |
5937 | } | |
037e8744 JB |
5938 | else if (rtype != REG_TYPE_VFS) |
5939 | { | |
5940 | i++; | |
5941 | if (skip_past_comma (&ptr) == FAIL) | |
5942 | goto wanted_comma; | |
5943 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5944 | goto wanted_arm; | |
5945 | inst.operands[i].reg = val; | |
5946 | inst.operands[i].isreg = 1; | |
5947 | inst.operands[i].present = 1; | |
5948 | } | |
5287ad62 | 5949 | } |
037e8744 JB |
5950 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
5951 | &optype)) != FAIL) | |
5287ad62 JB |
5952 | { |
5953 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5954 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5955 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5956 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5957 | |
5958 | inst.operands[i].reg = val; | |
5959 | inst.operands[i].isreg = 1; | |
5960 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5961 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5962 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5963 | inst.operands[i].vectype = optype; |
5287ad62 | 5964 | inst.operands[i].present = 1; |
5f4273c7 | 5965 | |
037e8744 JB |
5966 | if (skip_past_comma (&ptr) == SUCCESS) |
5967 | { | |
5968 | /* Case 15. */ | |
5969 | i++; | |
5970 | ||
5971 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5972 | goto wanted_arm; | |
5973 | ||
5974 | inst.operands[i].reg = val; | |
5975 | inst.operands[i].isreg = 1; | |
5976 | inst.operands[i++].present = 1; | |
5f4273c7 | 5977 | |
037e8744 JB |
5978 | if (skip_past_comma (&ptr) == FAIL) |
5979 | goto wanted_comma; | |
5f4273c7 | 5980 | |
037e8744 JB |
5981 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5982 | goto wanted_arm; | |
5f4273c7 | 5983 | |
037e8744 JB |
5984 | inst.operands[i].reg = val; |
5985 | inst.operands[i].isreg = 1; | |
1b11b49f | 5986 | inst.operands[i].present = 1; |
037e8744 | 5987 | } |
5287ad62 | 5988 | } |
4641781c PB |
5989 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
5990 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> | |
5991 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
5992 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5993 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5994 | inst.operands[i].immisfloat = 1; | |
5995 | else if (parse_big_immediate (&ptr, i) == SUCCESS) | |
5996 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> | |
5997 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
5998 | ; | |
5287ad62 JB |
5999 | else |
6000 | { | |
dcbf9037 | 6001 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
6002 | return FAIL; |
6003 | } | |
6004 | } | |
dcbf9037 | 6005 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
6006 | { |
6007 | /* Cases 6, 7. */ | |
6008 | inst.operands[i].reg = val; | |
6009 | inst.operands[i].isreg = 1; | |
6010 | inst.operands[i++].present = 1; | |
5f4273c7 | 6011 | |
5287ad62 JB |
6012 | if (skip_past_comma (&ptr) == FAIL) |
6013 | goto wanted_comma; | |
5f4273c7 | 6014 | |
dcbf9037 | 6015 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
6016 | { |
6017 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
6018 | inst.operands[i].reg = val; | |
6019 | inst.operands[i].isscalar = 1; | |
6020 | inst.operands[i].present = 1; | |
dcbf9037 | 6021 | inst.operands[i].vectype = optype; |
5287ad62 | 6022 | } |
dcbf9037 | 6023 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
6024 | { |
6025 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
6026 | inst.operands[i].reg = val; | |
6027 | inst.operands[i].isreg = 1; | |
6028 | inst.operands[i++].present = 1; | |
5f4273c7 | 6029 | |
5287ad62 JB |
6030 | if (skip_past_comma (&ptr) == FAIL) |
6031 | goto wanted_comma; | |
5f4273c7 | 6032 | |
037e8744 | 6033 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 6034 | == FAIL) |
5287ad62 | 6035 | { |
037e8744 | 6036 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
6037 | return FAIL; |
6038 | } | |
6039 | ||
6040 | inst.operands[i].reg = val; | |
6041 | inst.operands[i].isreg = 1; | |
037e8744 JB |
6042 | inst.operands[i].isvec = 1; |
6043 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 6044 | inst.operands[i].vectype = optype; |
5287ad62 | 6045 | inst.operands[i].present = 1; |
5f4273c7 | 6046 | |
037e8744 JB |
6047 | if (rtype == REG_TYPE_VFS) |
6048 | { | |
6049 | /* Case 14. */ | |
6050 | i++; | |
6051 | if (skip_past_comma (&ptr) == FAIL) | |
6052 | goto wanted_comma; | |
6053 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
6054 | &optype)) == FAIL) | |
6055 | { | |
6056 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
6057 | return FAIL; | |
6058 | } | |
6059 | inst.operands[i].reg = val; | |
6060 | inst.operands[i].isreg = 1; | |
6061 | inst.operands[i].isvec = 1; | |
6062 | inst.operands[i].issingle = 1; | |
6063 | inst.operands[i].vectype = optype; | |
6064 | inst.operands[i].present = 1; | |
6065 | } | |
6066 | } | |
6067 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
6068 | != FAIL) | |
6069 | { | |
6070 | /* Case 13. */ | |
6071 | inst.operands[i].reg = val; | |
6072 | inst.operands[i].isreg = 1; | |
6073 | inst.operands[i].isvec = 1; | |
6074 | inst.operands[i].issingle = 1; | |
6075 | inst.operands[i].vectype = optype; | |
1b11b49f | 6076 | inst.operands[i].present = 1; |
5287ad62 JB |
6077 | } |
6078 | } | |
6079 | else | |
6080 | { | |
dcbf9037 | 6081 | first_error (_("parse error")); |
5287ad62 JB |
6082 | return FAIL; |
6083 | } | |
6084 | ||
6085 | /* Successfully parsed the operands. Update args. */ | |
6086 | *which_operand = i; | |
6087 | *str = ptr; | |
6088 | return SUCCESS; | |
6089 | ||
5f4273c7 | 6090 | wanted_comma: |
dcbf9037 | 6091 | first_error (_("expected comma")); |
5287ad62 | 6092 | return FAIL; |
5f4273c7 NC |
6093 | |
6094 | wanted_arm: | |
dcbf9037 | 6095 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 6096 | return FAIL; |
5287ad62 JB |
6097 | } |
6098 | ||
5be8be5d DG |
6099 | /* Use this macro when the operand constraints are different |
6100 | for ARM and THUMB (e.g. ldrd). */ | |
6101 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
6102 | ((arm_operand) | ((thumb_operand) << 16)) | |
6103 | ||
c19d1205 ZW |
6104 | /* Matcher codes for parse_operands. */ |
6105 | enum operand_parse_code | |
6106 | { | |
6107 | OP_stop, /* end of line */ | |
6108 | ||
6109 | OP_RR, /* ARM register */ | |
6110 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 6111 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 6112 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 6113 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 6114 | optional trailing ! */ |
c19d1205 ZW |
6115 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
6116 | OP_RCP, /* Coprocessor number */ | |
6117 | OP_RCN, /* Coprocessor register */ | |
6118 | OP_RF, /* FPA register */ | |
6119 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
6120 | OP_RVD, /* VFP double precision register (0..15) */ |
6121 | OP_RND, /* Neon double precision register (0..31) */ | |
6122 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 6123 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 6124 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 6125 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 6126 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
6127 | OP_RVC, /* VFP control register */ |
6128 | OP_RMF, /* Maverick F register */ | |
6129 | OP_RMD, /* Maverick D register */ | |
6130 | OP_RMFX, /* Maverick FX register */ | |
6131 | OP_RMDX, /* Maverick DX register */ | |
6132 | OP_RMAX, /* Maverick AX register */ | |
6133 | OP_RMDS, /* Maverick DSPSC register */ | |
6134 | OP_RIWR, /* iWMMXt wR register */ | |
6135 | OP_RIWC, /* iWMMXt wC register */ | |
6136 | OP_RIWG, /* iWMMXt wCG register */ | |
6137 | OP_RXA, /* XScale accumulator register */ | |
6138 | ||
6139 | OP_REGLST, /* ARM register list */ | |
6140 | OP_VRSLST, /* VFP single-precision register list */ | |
6141 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 6142 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
6143 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
6144 | OP_NSTRLST, /* Neon element/structure list */ | |
6145 | ||
5287ad62 | 6146 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 6147 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 6148 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 6149 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
6150 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
6151 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
6152 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 6153 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
5287ad62 | 6154 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
2d447fca | 6155 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
6156 | |
6157 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
6158 | OP_I7, /* immediate value 0 .. 7 */ |
6159 | OP_I15, /* 0 .. 15 */ | |
6160 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 6161 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
6162 | OP_I31, /* 0 .. 31 */ |
6163 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
6164 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
6165 | OP_I32z, /* 0 .. 32 */ |
6166 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 6167 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
6168 | OP_I64, /* 1 .. 64 */ |
6169 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 6170 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
6171 | |
6172 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
6173 | OP_I7b, /* 0 .. 7 */ | |
6174 | OP_I15b, /* 0 .. 15 */ | |
6175 | OP_I31b, /* 0 .. 31 */ | |
6176 | ||
6177 | OP_SH, /* shifter operand */ | |
4962c51a | 6178 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 6179 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
6180 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
6181 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
6182 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
6183 | OP_EXP, /* arbitrary expression */ |
6184 | OP_EXPi, /* same, with optional immediate prefix */ | |
6185 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 6186 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
6187 | |
6188 | OP_CPSF, /* CPS flags */ | |
6189 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
6190 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
6191 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 6192 | OP_COND, /* conditional code */ |
92e90b6e | 6193 | OP_TB, /* Table branch. */ |
c19d1205 | 6194 | |
037e8744 JB |
6195 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
6196 | ||
c19d1205 ZW |
6197 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
6198 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
6199 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
6200 | OP_RF_IF, /* FPA register or immediate */ | |
6201 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 6202 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
6203 | |
6204 | /* Optional operands. */ | |
6205 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
6206 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 6207 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 6208 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
6209 | OP_oIffffb, /* 0 .. 65535 */ |
6210 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
6211 | ||
6212 | OP_oRR, /* ARM register */ | |
6213 | OP_oRRnpc, /* ARM register, not the PC */ | |
5be8be5d | 6214 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 6215 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
6216 | OP_oRND, /* Optional Neon double precision register */ |
6217 | OP_oRNQ, /* Optional Neon quad precision register */ | |
6218 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 6219 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
6220 | OP_oSHll, /* LSL immediate */ |
6221 | OP_oSHar, /* ASR immediate */ | |
6222 | OP_oSHllar, /* LSL or ASR immediate */ | |
6223 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 6224 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 6225 | |
5be8be5d DG |
6226 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
6227 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
6228 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
6229 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
6230 | ||
c19d1205 ZW |
6231 | OP_FIRST_OPTIONAL = OP_oI7b |
6232 | }; | |
a737bd4d | 6233 | |
c19d1205 ZW |
6234 | /* Generic instruction operand parser. This does no encoding and no |
6235 | semantic validation; it merely squirrels values away in the inst | |
6236 | structure. Returns SUCCESS or FAIL depending on whether the | |
6237 | specified grammar matched. */ | |
6238 | static int | |
5be8be5d | 6239 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 6240 | { |
5be8be5d | 6241 | unsigned const int *upat = pattern; |
c19d1205 ZW |
6242 | char *backtrack_pos = 0; |
6243 | const char *backtrack_error = 0; | |
99aad254 | 6244 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 6245 | enum arm_reg_type rtype; |
4962c51a | 6246 | parse_operand_result result; |
5be8be5d | 6247 | unsigned int op_parse_code; |
c19d1205 | 6248 | |
e07e6e58 NC |
6249 | #define po_char_or_fail(chr) \ |
6250 | do \ | |
6251 | { \ | |
6252 | if (skip_past_char (&str, chr) == FAIL) \ | |
6253 | goto bad_args; \ | |
6254 | } \ | |
6255 | while (0) | |
c19d1205 | 6256 | |
e07e6e58 NC |
6257 | #define po_reg_or_fail(regtype) \ |
6258 | do \ | |
dcbf9037 | 6259 | { \ |
e07e6e58 NC |
6260 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
6261 | & inst.operands[i].vectype); \ | |
6262 | if (val == FAIL) \ | |
6263 | { \ | |
6264 | first_error (_(reg_expected_msgs[regtype])); \ | |
6265 | goto failure; \ | |
6266 | } \ | |
6267 | inst.operands[i].reg = val; \ | |
6268 | inst.operands[i].isreg = 1; \ | |
6269 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6270 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6271 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
6272 | || rtype == REG_TYPE_VFD \ | |
6273 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 6274 | } \ |
e07e6e58 NC |
6275 | while (0) |
6276 | ||
6277 | #define po_reg_or_goto(regtype, label) \ | |
6278 | do \ | |
6279 | { \ | |
6280 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
6281 | & inst.operands[i].vectype); \ | |
6282 | if (val == FAIL) \ | |
6283 | goto label; \ | |
dcbf9037 | 6284 | \ |
e07e6e58 NC |
6285 | inst.operands[i].reg = val; \ |
6286 | inst.operands[i].isreg = 1; \ | |
6287 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6288 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6289 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
6290 | || rtype == REG_TYPE_VFD \ | |
6291 | || rtype == REG_TYPE_NQ); \ | |
6292 | } \ | |
6293 | while (0) | |
6294 | ||
6295 | #define po_imm_or_fail(min, max, popt) \ | |
6296 | do \ | |
6297 | { \ | |
6298 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
6299 | goto failure; \ | |
6300 | inst.operands[i].imm = val; \ | |
6301 | } \ | |
6302 | while (0) | |
6303 | ||
6304 | #define po_scalar_or_goto(elsz, label) \ | |
6305 | do \ | |
6306 | { \ | |
6307 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
6308 | if (val == FAIL) \ | |
6309 | goto label; \ | |
6310 | inst.operands[i].reg = val; \ | |
6311 | inst.operands[i].isscalar = 1; \ | |
6312 | } \ | |
6313 | while (0) | |
6314 | ||
6315 | #define po_misc_or_fail(expr) \ | |
6316 | do \ | |
6317 | { \ | |
6318 | if (expr) \ | |
6319 | goto failure; \ | |
6320 | } \ | |
6321 | while (0) | |
6322 | ||
6323 | #define po_misc_or_fail_no_backtrack(expr) \ | |
6324 | do \ | |
6325 | { \ | |
6326 | result = expr; \ | |
6327 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
6328 | backtrack_pos = 0; \ | |
6329 | if (result != PARSE_OPERAND_SUCCESS) \ | |
6330 | goto failure; \ | |
6331 | } \ | |
6332 | while (0) | |
4962c51a | 6333 | |
52e7f43d RE |
6334 | #define po_barrier_or_imm(str) \ |
6335 | do \ | |
6336 | { \ | |
6337 | val = parse_barrier (&str); \ | |
6338 | if (val == FAIL) \ | |
6339 | { \ | |
6340 | if (ISALPHA (*str)) \ | |
6341 | goto failure; \ | |
6342 | else \ | |
6343 | goto immediate; \ | |
6344 | } \ | |
6345 | else \ | |
6346 | { \ | |
6347 | if ((inst.instruction & 0xf0) == 0x60 \ | |
6348 | && val != 0xf) \ | |
6349 | { \ | |
6350 | /* ISB can only take SY as an option. */ \ | |
6351 | inst.error = _("invalid barrier type"); \ | |
6352 | goto failure; \ | |
6353 | } \ | |
6354 | } \ | |
6355 | } \ | |
6356 | while (0) | |
6357 | ||
c19d1205 ZW |
6358 | skip_whitespace (str); |
6359 | ||
6360 | for (i = 0; upat[i] != OP_stop; i++) | |
6361 | { | |
5be8be5d DG |
6362 | op_parse_code = upat[i]; |
6363 | if (op_parse_code >= 1<<16) | |
6364 | op_parse_code = thumb ? (op_parse_code >> 16) | |
6365 | : (op_parse_code & ((1<<16)-1)); | |
6366 | ||
6367 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
6368 | { |
6369 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 6370 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
6371 | backtrack_pos = str; |
6372 | backtrack_error = inst.error; | |
6373 | backtrack_index = i; | |
6374 | } | |
6375 | ||
b6702015 | 6376 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
6377 | po_char_or_fail (','); |
6378 | ||
5be8be5d | 6379 | switch (op_parse_code) |
c19d1205 ZW |
6380 | { |
6381 | /* Registers */ | |
6382 | case OP_oRRnpc: | |
5be8be5d | 6383 | case OP_oRRnpcsp: |
c19d1205 | 6384 | case OP_RRnpc: |
5be8be5d | 6385 | case OP_RRnpcsp: |
c19d1205 ZW |
6386 | case OP_oRR: |
6387 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
6388 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
6389 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
6390 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
6391 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
6392 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
6393 | case OP_oRND: |
6394 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
cd2cf30b PB |
6395 | case OP_RVC: |
6396 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
6397 | break; | |
6398 | /* Also accept generic coprocessor regs for unknown registers. */ | |
6399 | coproc_reg: | |
6400 | po_reg_or_fail (REG_TYPE_CN); | |
6401 | break; | |
c19d1205 ZW |
6402 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
6403 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
6404 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
6405 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
6406 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
6407 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
6408 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
6409 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
6410 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
6411 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
6412 | case OP_oRNQ: |
6413 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
6414 | case OP_oRNDQ: | |
6415 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
6416 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
6417 | case OP_oRNSDQ: | |
6418 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
6419 | |
6420 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6421 | scalars are accepted here, so deal with those in later code. */ | |
6422 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6423 | ||
5287ad62 JB |
6424 | case OP_RNDQ_I0: |
6425 | { | |
6426 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6427 | break; | |
6428 | try_imm0: | |
6429 | po_imm_or_fail (0, 0, TRUE); | |
6430 | } | |
6431 | break; | |
6432 | ||
037e8744 JB |
6433 | case OP_RVSD_I0: |
6434 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6435 | break; | |
6436 | ||
5287ad62 JB |
6437 | case OP_RR_RNSC: |
6438 | { | |
6439 | po_scalar_or_goto (8, try_rr); | |
6440 | break; | |
6441 | try_rr: | |
6442 | po_reg_or_fail (REG_TYPE_RN); | |
6443 | } | |
6444 | break; | |
6445 | ||
037e8744 JB |
6446 | case OP_RNSDQ_RNSC: |
6447 | { | |
6448 | po_scalar_or_goto (8, try_nsdq); | |
6449 | break; | |
6450 | try_nsdq: | |
6451 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6452 | } | |
6453 | break; | |
6454 | ||
5287ad62 JB |
6455 | case OP_RNDQ_RNSC: |
6456 | { | |
6457 | po_scalar_or_goto (8, try_ndq); | |
6458 | break; | |
6459 | try_ndq: | |
6460 | po_reg_or_fail (REG_TYPE_NDQ); | |
6461 | } | |
6462 | break; | |
6463 | ||
6464 | case OP_RND_RNSC: | |
6465 | { | |
6466 | po_scalar_or_goto (8, try_vfd); | |
6467 | break; | |
6468 | try_vfd: | |
6469 | po_reg_or_fail (REG_TYPE_VFD); | |
6470 | } | |
6471 | break; | |
6472 | ||
6473 | case OP_VMOV: | |
6474 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6475 | not careful then bad things might happen. */ | |
6476 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6477 | break; | |
6478 | ||
4316f0d2 | 6479 | case OP_RNDQ_Ibig: |
5287ad62 | 6480 | { |
4316f0d2 | 6481 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); |
5287ad62 | 6482 | break; |
4316f0d2 | 6483 | try_immbig: |
5287ad62 JB |
6484 | /* There's a possibility of getting a 64-bit immediate here, so |
6485 | we need special handling. */ | |
6486 | if (parse_big_immediate (&str, i) == FAIL) | |
6487 | { | |
6488 | inst.error = _("immediate value is out of range"); | |
6489 | goto failure; | |
6490 | } | |
6491 | } | |
6492 | break; | |
6493 | ||
6494 | case OP_RNDQ_I63b: | |
6495 | { | |
6496 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6497 | break; | |
6498 | try_shimm: | |
6499 | po_imm_or_fail (0, 63, TRUE); | |
6500 | } | |
6501 | break; | |
c19d1205 ZW |
6502 | |
6503 | case OP_RRnpcb: | |
6504 | po_char_or_fail ('['); | |
6505 | po_reg_or_fail (REG_TYPE_RN); | |
6506 | po_char_or_fail (']'); | |
6507 | break; | |
a737bd4d | 6508 | |
55881a11 | 6509 | case OP_RRnpctw: |
c19d1205 | 6510 | case OP_RRw: |
b6702015 | 6511 | case OP_oRRw: |
c19d1205 ZW |
6512 | po_reg_or_fail (REG_TYPE_RN); |
6513 | if (skip_past_char (&str, '!') == SUCCESS) | |
6514 | inst.operands[i].writeback = 1; | |
6515 | break; | |
6516 | ||
6517 | /* Immediates */ | |
6518 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6519 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6520 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 6521 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6522 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6523 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 6524 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6525 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
6526 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6527 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6528 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6529 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6530 | |
6531 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6532 | case OP_oI7b: | |
6533 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6534 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6535 | case OP_oI31b: | |
6536 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 6537 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
5f1af56b | 6538 | case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break; |
c19d1205 ZW |
6539 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6540 | ||
6541 | /* Immediate variants */ | |
6542 | case OP_oI255c: | |
6543 | po_char_or_fail ('{'); | |
6544 | po_imm_or_fail (0, 255, TRUE); | |
6545 | po_char_or_fail ('}'); | |
6546 | break; | |
6547 | ||
6548 | case OP_I31w: | |
6549 | /* The expression parser chokes on a trailing !, so we have | |
6550 | to find it first and zap it. */ | |
6551 | { | |
6552 | char *s = str; | |
6553 | while (*s && *s != ',') | |
6554 | s++; | |
6555 | if (s[-1] == '!') | |
6556 | { | |
6557 | s[-1] = '\0'; | |
6558 | inst.operands[i].writeback = 1; | |
6559 | } | |
6560 | po_imm_or_fail (0, 31, TRUE); | |
6561 | if (str == s - 1) | |
6562 | str = s; | |
6563 | } | |
6564 | break; | |
6565 | ||
6566 | /* Expressions */ | |
6567 | case OP_EXPi: EXPi: | |
6568 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6569 | GE_OPT_PREFIX)); | |
6570 | break; | |
6571 | ||
6572 | case OP_EXP: | |
6573 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6574 | GE_NO_PREFIX)); | |
6575 | break; | |
6576 | ||
6577 | case OP_EXPr: EXPr: | |
6578 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6579 | GE_NO_PREFIX)); | |
6580 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6581 | { |
c19d1205 ZW |
6582 | val = parse_reloc (&str); |
6583 | if (val == -1) | |
6584 | { | |
6585 | inst.error = _("unrecognized relocation suffix"); | |
6586 | goto failure; | |
6587 | } | |
6588 | else if (val != BFD_RELOC_UNUSED) | |
6589 | { | |
6590 | inst.operands[i].imm = val; | |
6591 | inst.operands[i].hasreloc = 1; | |
6592 | } | |
a737bd4d | 6593 | } |
c19d1205 | 6594 | break; |
a737bd4d | 6595 | |
b6895b4f PB |
6596 | /* Operand for MOVW or MOVT. */ |
6597 | case OP_HALF: | |
6598 | po_misc_or_fail (parse_half (&str)); | |
6599 | break; | |
6600 | ||
e07e6e58 | 6601 | /* Register or expression. */ |
c19d1205 ZW |
6602 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6603 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6604 | |
e07e6e58 | 6605 | /* Register or immediate. */ |
c19d1205 ZW |
6606 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6607 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6608 | |
c19d1205 ZW |
6609 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6610 | IF: | |
6611 | if (!is_immediate_prefix (*str)) | |
6612 | goto bad_args; | |
6613 | str++; | |
6614 | val = parse_fpa_immediate (&str); | |
6615 | if (val == FAIL) | |
6616 | goto failure; | |
6617 | /* FPA immediates are encoded as registers 8-15. | |
6618 | parse_fpa_immediate has already applied the offset. */ | |
6619 | inst.operands[i].reg = val; | |
6620 | inst.operands[i].isreg = 1; | |
6621 | break; | |
09d92015 | 6622 | |
2d447fca JM |
6623 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6624 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6625 | ||
e07e6e58 | 6626 | /* Two kinds of register. */ |
c19d1205 ZW |
6627 | case OP_RIWR_RIWC: |
6628 | { | |
6629 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6630 | if (!rege |
6631 | || (rege->type != REG_TYPE_MMXWR | |
6632 | && rege->type != REG_TYPE_MMXWC | |
6633 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6634 | { |
6635 | inst.error = _("iWMMXt data or control register expected"); | |
6636 | goto failure; | |
6637 | } | |
6638 | inst.operands[i].reg = rege->number; | |
6639 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6640 | } | |
6641 | break; | |
09d92015 | 6642 | |
41adaa5c JM |
6643 | case OP_RIWC_RIWG: |
6644 | { | |
6645 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6646 | if (!rege | |
6647 | || (rege->type != REG_TYPE_MMXWC | |
6648 | && rege->type != REG_TYPE_MMXWCG)) | |
6649 | { | |
6650 | inst.error = _("iWMMXt control register expected"); | |
6651 | goto failure; | |
6652 | } | |
6653 | inst.operands[i].reg = rege->number; | |
6654 | inst.operands[i].isreg = 1; | |
6655 | } | |
6656 | break; | |
6657 | ||
c19d1205 ZW |
6658 | /* Misc */ |
6659 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6660 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6661 | case OP_oROR: val = parse_ror (&str); break; | |
c19d1205 | 6662 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
6663 | case OP_oBARRIER_I15: |
6664 | po_barrier_or_imm (str); break; | |
6665 | immediate: | |
6666 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
6667 | goto failure; | |
6668 | break; | |
c19d1205 | 6669 | |
fa94de6b | 6670 | case OP_wPSR: |
d2cd1205 | 6671 | case OP_rPSR: |
90ec0d68 MGD |
6672 | po_reg_or_goto (REG_TYPE_RNB, try_psr); |
6673 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
6674 | { | |
6675 | inst.error = _("Banked registers are not available with this " | |
6676 | "architecture."); | |
6677 | goto failure; | |
6678 | } | |
6679 | break; | |
d2cd1205 JB |
6680 | try_psr: |
6681 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
6682 | break; | |
037e8744 JB |
6683 | |
6684 | case OP_APSR_RR: | |
6685 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
6686 | break; | |
6687 | try_apsr: | |
6688 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
6689 | instruction). */ | |
6690 | if (strncasecmp (str, "APSR_", 5) == 0) | |
6691 | { | |
6692 | unsigned found = 0; | |
6693 | str += 5; | |
6694 | while (found < 15) | |
6695 | switch (*str++) | |
6696 | { | |
6697 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
6698 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
6699 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
6700 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
6701 | default: found = 16; | |
6702 | } | |
6703 | if (found != 15) | |
6704 | goto failure; | |
6705 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
6706 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
6707 | inst.operands[i].reg = REG_PC; | |
037e8744 JB |
6708 | } |
6709 | else | |
6710 | goto failure; | |
6711 | break; | |
6712 | ||
92e90b6e PB |
6713 | case OP_TB: |
6714 | po_misc_or_fail (parse_tb (&str)); | |
6715 | break; | |
6716 | ||
e07e6e58 | 6717 | /* Register lists. */ |
c19d1205 ZW |
6718 | case OP_REGLST: |
6719 | val = parse_reg_list (&str); | |
6720 | if (*str == '^') | |
6721 | { | |
6722 | inst.operands[1].writeback = 1; | |
6723 | str++; | |
6724 | } | |
6725 | break; | |
09d92015 | 6726 | |
c19d1205 | 6727 | case OP_VRSLST: |
5287ad62 | 6728 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 6729 | break; |
09d92015 | 6730 | |
c19d1205 | 6731 | case OP_VRDLST: |
5287ad62 | 6732 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 6733 | break; |
a737bd4d | 6734 | |
037e8744 JB |
6735 | case OP_VRSDLST: |
6736 | /* Allow Q registers too. */ | |
6737 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6738 | REGLIST_NEON_D); | |
6739 | if (val == FAIL) | |
6740 | { | |
6741 | inst.error = NULL; | |
6742 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6743 | REGLIST_VFP_S); | |
6744 | inst.operands[i].issingle = 1; | |
6745 | } | |
6746 | break; | |
6747 | ||
5287ad62 JB |
6748 | case OP_NRDLST: |
6749 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6750 | REGLIST_NEON_D); | |
6751 | break; | |
6752 | ||
6753 | case OP_NSTRLST: | |
dcbf9037 JB |
6754 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
6755 | &inst.operands[i].vectype); | |
5287ad62 JB |
6756 | break; |
6757 | ||
c19d1205 ZW |
6758 | /* Addressing modes */ |
6759 | case OP_ADDR: | |
6760 | po_misc_or_fail (parse_address (&str, i)); | |
6761 | break; | |
09d92015 | 6762 | |
4962c51a MS |
6763 | case OP_ADDRGLDR: |
6764 | po_misc_or_fail_no_backtrack ( | |
6765 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
6766 | break; | |
6767 | ||
6768 | case OP_ADDRGLDRS: | |
6769 | po_misc_or_fail_no_backtrack ( | |
6770 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
6771 | break; | |
6772 | ||
6773 | case OP_ADDRGLDC: | |
6774 | po_misc_or_fail_no_backtrack ( | |
6775 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
6776 | break; | |
6777 | ||
c19d1205 ZW |
6778 | case OP_SH: |
6779 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
6780 | break; | |
09d92015 | 6781 | |
4962c51a MS |
6782 | case OP_SHG: |
6783 | po_misc_or_fail_no_backtrack ( | |
6784 | parse_shifter_operand_group_reloc (&str, i)); | |
6785 | break; | |
6786 | ||
c19d1205 ZW |
6787 | case OP_oSHll: |
6788 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
6789 | break; | |
09d92015 | 6790 | |
c19d1205 ZW |
6791 | case OP_oSHar: |
6792 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
6793 | break; | |
09d92015 | 6794 | |
c19d1205 ZW |
6795 | case OP_oSHllar: |
6796 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
6797 | break; | |
09d92015 | 6798 | |
c19d1205 | 6799 | default: |
5be8be5d | 6800 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 6801 | } |
09d92015 | 6802 | |
c19d1205 ZW |
6803 | /* Various value-based sanity checks and shared operations. We |
6804 | do not signal immediate failures for the register constraints; | |
6805 | this allows a syntax error to take precedence. */ | |
5be8be5d | 6806 | switch (op_parse_code) |
c19d1205 ZW |
6807 | { |
6808 | case OP_oRRnpc: | |
6809 | case OP_RRnpc: | |
6810 | case OP_RRnpcb: | |
6811 | case OP_RRw: | |
b6702015 | 6812 | case OP_oRRw: |
c19d1205 ZW |
6813 | case OP_RRnpc_I0: |
6814 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
6815 | inst.error = BAD_PC; | |
6816 | break; | |
09d92015 | 6817 | |
5be8be5d DG |
6818 | case OP_oRRnpcsp: |
6819 | case OP_RRnpcsp: | |
6820 | if (inst.operands[i].isreg) | |
6821 | { | |
6822 | if (inst.operands[i].reg == REG_PC) | |
6823 | inst.error = BAD_PC; | |
6824 | else if (inst.operands[i].reg == REG_SP) | |
6825 | inst.error = BAD_SP; | |
6826 | } | |
6827 | break; | |
6828 | ||
55881a11 | 6829 | case OP_RRnpctw: |
fa94de6b RM |
6830 | if (inst.operands[i].isreg |
6831 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
6832 | && (inst.operands[i].writeback || thumb)) |
6833 | inst.error = BAD_PC; | |
6834 | break; | |
6835 | ||
c19d1205 ZW |
6836 | case OP_CPSF: |
6837 | case OP_ENDI: | |
6838 | case OP_oROR: | |
d2cd1205 JB |
6839 | case OP_wPSR: |
6840 | case OP_rPSR: | |
c19d1205 | 6841 | case OP_COND: |
52e7f43d | 6842 | case OP_oBARRIER_I15: |
c19d1205 ZW |
6843 | case OP_REGLST: |
6844 | case OP_VRSLST: | |
6845 | case OP_VRDLST: | |
037e8744 | 6846 | case OP_VRSDLST: |
5287ad62 JB |
6847 | case OP_NRDLST: |
6848 | case OP_NSTRLST: | |
c19d1205 ZW |
6849 | if (val == FAIL) |
6850 | goto failure; | |
6851 | inst.operands[i].imm = val; | |
6852 | break; | |
a737bd4d | 6853 | |
c19d1205 ZW |
6854 | default: |
6855 | break; | |
6856 | } | |
09d92015 | 6857 | |
c19d1205 ZW |
6858 | /* If we get here, this operand was successfully parsed. */ |
6859 | inst.operands[i].present = 1; | |
6860 | continue; | |
09d92015 | 6861 | |
c19d1205 | 6862 | bad_args: |
09d92015 | 6863 | inst.error = BAD_ARGS; |
c19d1205 ZW |
6864 | |
6865 | failure: | |
6866 | if (!backtrack_pos) | |
d252fdde PB |
6867 | { |
6868 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 6869 | default here just in case. */ |
d252fdde PB |
6870 | if (!inst.error) |
6871 | inst.error = _("syntax error"); | |
6872 | return FAIL; | |
6873 | } | |
c19d1205 ZW |
6874 | |
6875 | /* Do not backtrack over a trailing optional argument that | |
6876 | absorbed some text. We will only fail again, with the | |
6877 | 'garbage following instruction' error message, which is | |
6878 | probably less helpful than the current one. */ | |
6879 | if (backtrack_index == i && backtrack_pos != str | |
6880 | && upat[i+1] == OP_stop) | |
d252fdde PB |
6881 | { |
6882 | if (!inst.error) | |
6883 | inst.error = _("syntax error"); | |
6884 | return FAIL; | |
6885 | } | |
c19d1205 ZW |
6886 | |
6887 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
6888 | str = backtrack_pos; | |
6889 | inst.error = backtrack_error; | |
6890 | inst.operands[backtrack_index].present = 0; | |
6891 | i = backtrack_index; | |
6892 | backtrack_pos = 0; | |
09d92015 | 6893 | } |
09d92015 | 6894 | |
c19d1205 ZW |
6895 | /* Check that we have parsed all the arguments. */ |
6896 | if (*str != '\0' && !inst.error) | |
6897 | inst.error = _("garbage following instruction"); | |
09d92015 | 6898 | |
c19d1205 | 6899 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
6900 | } |
6901 | ||
c19d1205 ZW |
6902 | #undef po_char_or_fail |
6903 | #undef po_reg_or_fail | |
6904 | #undef po_reg_or_goto | |
6905 | #undef po_imm_or_fail | |
5287ad62 | 6906 | #undef po_scalar_or_fail |
52e7f43d | 6907 | #undef po_barrier_or_imm |
e07e6e58 | 6908 | |
c19d1205 | 6909 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
6910 | #define constraint(expr, err) \ |
6911 | do \ | |
c19d1205 | 6912 | { \ |
e07e6e58 NC |
6913 | if (expr) \ |
6914 | { \ | |
6915 | inst.error = err; \ | |
6916 | return; \ | |
6917 | } \ | |
c19d1205 | 6918 | } \ |
e07e6e58 | 6919 | while (0) |
c19d1205 | 6920 | |
fdfde340 JM |
6921 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
6922 | instructions are unpredictable if these registers are used. This | |
6923 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
6924 | #define reject_bad_reg(reg) \ | |
6925 | do \ | |
6926 | if (reg == REG_SP || reg == REG_PC) \ | |
6927 | { \ | |
6928 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
6929 | return; \ | |
6930 | } \ | |
6931 | while (0) | |
6932 | ||
94206790 MM |
6933 | /* If REG is R13 (the stack pointer), warn that its use is |
6934 | deprecated. */ | |
6935 | #define warn_deprecated_sp(reg) \ | |
6936 | do \ | |
6937 | if (warn_on_deprecated && reg == REG_SP) \ | |
6938 | as_warn (_("use of r13 is deprecated")); \ | |
6939 | while (0) | |
6940 | ||
c19d1205 ZW |
6941 | /* Functions for operand encoding. ARM, then Thumb. */ |
6942 | ||
6943 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
6944 | ||
6945 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
6946 | return the encoded form. Otherwise, return FAIL. */ | |
6947 | ||
6948 | static unsigned int | |
6949 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6950 | { |
c19d1205 ZW |
6951 | unsigned int a, i; |
6952 | ||
6953 | for (i = 0; i < 32; i += 2) | |
6954 | if ((a = rotate_left (val, i)) <= 0xff) | |
6955 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6956 | ||
6957 | return FAIL; | |
09d92015 MM |
6958 | } |
6959 | ||
c19d1205 ZW |
6960 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6961 | return the encoded form. Otherwise, return FAIL. */ | |
6962 | static unsigned int | |
6963 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6964 | { |
c19d1205 | 6965 | unsigned int a, i; |
09d92015 | 6966 | |
9c3c69f2 | 6967 | if (val <= 0xff) |
c19d1205 | 6968 | return val; |
a737bd4d | 6969 | |
9c3c69f2 | 6970 | for (i = 1; i <= 24; i++) |
09d92015 | 6971 | { |
9c3c69f2 PB |
6972 | a = val >> i; |
6973 | if ((val & ~(0xff << i)) == 0) | |
6974 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6975 | } |
a737bd4d | 6976 | |
c19d1205 ZW |
6977 | a = val & 0xff; |
6978 | if (val == ((a << 16) | a)) | |
6979 | return 0x100 | a; | |
6980 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6981 | return 0x300 | a; | |
09d92015 | 6982 | |
c19d1205 ZW |
6983 | a = val & 0xff00; |
6984 | if (val == ((a << 16) | a)) | |
6985 | return 0x200 | (a >> 8); | |
a737bd4d | 6986 | |
c19d1205 | 6987 | return FAIL; |
09d92015 | 6988 | } |
5287ad62 | 6989 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6990 | |
6991 | static void | |
5287ad62 JB |
6992 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6993 | { | |
6994 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6995 | && reg > 15) | |
6996 | { | |
b1cc4aeb | 6997 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
5287ad62 JB |
6998 | { |
6999 | if (thumb_mode) | |
7000 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 7001 | fpu_vfp_ext_d32); |
5287ad62 JB |
7002 | else |
7003 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 7004 | fpu_vfp_ext_d32); |
5287ad62 JB |
7005 | } |
7006 | else | |
7007 | { | |
dcbf9037 | 7008 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
7009 | return; |
7010 | } | |
7011 | } | |
7012 | ||
c19d1205 | 7013 | switch (pos) |
09d92015 | 7014 | { |
c19d1205 ZW |
7015 | case VFP_REG_Sd: |
7016 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
7017 | break; | |
7018 | ||
7019 | case VFP_REG_Sn: | |
7020 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
7021 | break; | |
7022 | ||
7023 | case VFP_REG_Sm: | |
7024 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
7025 | break; | |
7026 | ||
5287ad62 JB |
7027 | case VFP_REG_Dd: |
7028 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
7029 | break; | |
5f4273c7 | 7030 | |
5287ad62 JB |
7031 | case VFP_REG_Dn: |
7032 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
7033 | break; | |
5f4273c7 | 7034 | |
5287ad62 JB |
7035 | case VFP_REG_Dm: |
7036 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
7037 | break; | |
7038 | ||
c19d1205 ZW |
7039 | default: |
7040 | abort (); | |
09d92015 | 7041 | } |
09d92015 MM |
7042 | } |
7043 | ||
c19d1205 | 7044 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 7045 | if any, is handled by md_apply_fix. */ |
09d92015 | 7046 | static void |
c19d1205 | 7047 | encode_arm_shift (int i) |
09d92015 | 7048 | { |
c19d1205 ZW |
7049 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
7050 | inst.instruction |= SHIFT_ROR << 5; | |
7051 | else | |
09d92015 | 7052 | { |
c19d1205 ZW |
7053 | inst.instruction |= inst.operands[i].shift_kind << 5; |
7054 | if (inst.operands[i].immisreg) | |
7055 | { | |
7056 | inst.instruction |= SHIFT_BY_REG; | |
7057 | inst.instruction |= inst.operands[i].imm << 8; | |
7058 | } | |
7059 | else | |
7060 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 7061 | } |
c19d1205 | 7062 | } |
09d92015 | 7063 | |
c19d1205 ZW |
7064 | static void |
7065 | encode_arm_shifter_operand (int i) | |
7066 | { | |
7067 | if (inst.operands[i].isreg) | |
09d92015 | 7068 | { |
c19d1205 ZW |
7069 | inst.instruction |= inst.operands[i].reg; |
7070 | encode_arm_shift (i); | |
09d92015 | 7071 | } |
c19d1205 | 7072 | else |
a415b1cd JB |
7073 | { |
7074 | inst.instruction |= INST_IMMEDIATE; | |
7075 | if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE) | |
7076 | inst.instruction |= inst.operands[i].imm; | |
7077 | } | |
09d92015 MM |
7078 | } |
7079 | ||
c19d1205 | 7080 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 7081 | static void |
c19d1205 | 7082 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 7083 | { |
2b2f5df9 NC |
7084 | /* PR 14260: |
7085 | Generate an error if the operand is not a register. */ | |
7086 | constraint (!inst.operands[i].isreg, | |
7087 | _("Instruction does not support =N addresses")); | |
7088 | ||
c19d1205 | 7089 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 7090 | |
c19d1205 | 7091 | if (inst.operands[i].preind) |
09d92015 | 7092 | { |
c19d1205 ZW |
7093 | if (is_t) |
7094 | { | |
7095 | inst.error = _("instruction does not accept preindexed addressing"); | |
7096 | return; | |
7097 | } | |
7098 | inst.instruction |= PRE_INDEX; | |
7099 | if (inst.operands[i].writeback) | |
7100 | inst.instruction |= WRITE_BACK; | |
09d92015 | 7101 | |
c19d1205 ZW |
7102 | } |
7103 | else if (inst.operands[i].postind) | |
7104 | { | |
9c2799c2 | 7105 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
7106 | if (is_t) |
7107 | inst.instruction |= WRITE_BACK; | |
7108 | } | |
7109 | else /* unindexed - only for coprocessor */ | |
09d92015 | 7110 | { |
c19d1205 | 7111 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
7112 | return; |
7113 | } | |
7114 | ||
c19d1205 ZW |
7115 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
7116 | && (((inst.instruction & 0x000f0000) >> 16) | |
7117 | == ((inst.instruction & 0x0000f000) >> 12))) | |
7118 | as_warn ((inst.instruction & LOAD_BIT) | |
7119 | ? _("destination register same as write-back base") | |
7120 | : _("source register same as write-back base")); | |
09d92015 MM |
7121 | } |
7122 | ||
c19d1205 ZW |
7123 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7124 | ARM-format mode 2 load or store instruction. If is_t is true, | |
7125 | reject forms that cannot be used with a T instruction (i.e. not | |
7126 | post-indexed). */ | |
a737bd4d | 7127 | static void |
c19d1205 | 7128 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 7129 | { |
5be8be5d DG |
7130 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
7131 | ||
c19d1205 | 7132 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7133 | |
c19d1205 | 7134 | if (inst.operands[i].immisreg) |
09d92015 | 7135 | { |
5be8be5d DG |
7136 | constraint ((inst.operands[i].imm == REG_PC |
7137 | || (is_pc && inst.operands[i].writeback)), | |
7138 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
7139 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
7140 | inst.instruction |= inst.operands[i].imm; | |
7141 | if (!inst.operands[i].negative) | |
7142 | inst.instruction |= INDEX_UP; | |
7143 | if (inst.operands[i].shifted) | |
7144 | { | |
7145 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
7146 | inst.instruction |= SHIFT_ROR << 5; | |
7147 | else | |
7148 | { | |
7149 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
7150 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
7151 | } | |
7152 | } | |
09d92015 | 7153 | } |
c19d1205 | 7154 | else /* immediate offset in inst.reloc */ |
09d92015 | 7155 | { |
5be8be5d DG |
7156 | if (is_pc && !inst.reloc.pc_rel) |
7157 | { | |
7158 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
7159 | |
7160 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
7161 | cannot use PC in addressing. | |
7162 | PC cannot be used in writeback addressing, either. */ | |
7163 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 7164 | BAD_PC_ADDRESSING); |
23a10334 | 7165 | |
dc5ec521 | 7166 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
7167 | if (warn_on_deprecated |
7168 | && !is_load | |
7169 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
7170 | as_warn (_("use of PC in this instruction is deprecated")); | |
5be8be5d DG |
7171 | } |
7172 | ||
c19d1205 | 7173 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
26d97720 NS |
7174 | { |
7175 | /* Prefer + for zero encoded value. */ | |
7176 | if (!inst.operands[i].negative) | |
7177 | inst.instruction |= INDEX_UP; | |
7178 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
7179 | } | |
09d92015 | 7180 | } |
09d92015 MM |
7181 | } |
7182 | ||
c19d1205 ZW |
7183 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7184 | ARM-format mode 3 load or store instruction. Reject forms that | |
7185 | cannot be used with such instructions. If is_t is true, reject | |
7186 | forms that cannot be used with a T instruction (i.e. not | |
7187 | post-indexed). */ | |
7188 | static void | |
7189 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 7190 | { |
c19d1205 | 7191 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 7192 | { |
c19d1205 ZW |
7193 | inst.error = _("instruction does not accept scaled register index"); |
7194 | return; | |
09d92015 | 7195 | } |
a737bd4d | 7196 | |
c19d1205 | 7197 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7198 | |
c19d1205 ZW |
7199 | if (inst.operands[i].immisreg) |
7200 | { | |
5be8be5d DG |
7201 | constraint ((inst.operands[i].imm == REG_PC |
7202 | || inst.operands[i].reg == REG_PC), | |
7203 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
7204 | inst.instruction |= inst.operands[i].imm; |
7205 | if (!inst.operands[i].negative) | |
7206 | inst.instruction |= INDEX_UP; | |
7207 | } | |
7208 | else /* immediate offset in inst.reloc */ | |
7209 | { | |
5be8be5d DG |
7210 | constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel |
7211 | && inst.operands[i].writeback), | |
7212 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7213 | inst.instruction |= HWOFFSET_IMM; |
7214 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
26d97720 NS |
7215 | { |
7216 | /* Prefer + for zero encoded value. */ | |
7217 | if (!inst.operands[i].negative) | |
7218 | inst.instruction |= INDEX_UP; | |
7219 | ||
7220 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
7221 | } | |
c19d1205 | 7222 | } |
a737bd4d NC |
7223 | } |
7224 | ||
c19d1205 ZW |
7225 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7226 | ARM-format instruction. Reject all forms which cannot be encoded | |
7227 | into a coprocessor load/store instruction. If wb_ok is false, | |
7228 | reject use of writeback; if unind_ok is false, reject use of | |
7229 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
7230 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
7231 | (in which case it is preserved). */ | |
09d92015 | 7232 | |
c19d1205 ZW |
7233 | static int |
7234 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 7235 | { |
c19d1205 | 7236 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 7237 | |
9c2799c2 | 7238 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 7239 | |
c19d1205 | 7240 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 7241 | { |
9c2799c2 | 7242 | gas_assert (!inst.operands[i].writeback); |
c19d1205 ZW |
7243 | if (!unind_ok) |
7244 | { | |
7245 | inst.error = _("instruction does not support unindexed addressing"); | |
7246 | return FAIL; | |
7247 | } | |
7248 | inst.instruction |= inst.operands[i].imm; | |
7249 | inst.instruction |= INDEX_UP; | |
7250 | return SUCCESS; | |
09d92015 | 7251 | } |
a737bd4d | 7252 | |
c19d1205 ZW |
7253 | if (inst.operands[i].preind) |
7254 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 7255 | |
c19d1205 | 7256 | if (inst.operands[i].writeback) |
09d92015 | 7257 | { |
c19d1205 ZW |
7258 | if (inst.operands[i].reg == REG_PC) |
7259 | { | |
7260 | inst.error = _("pc may not be used with write-back"); | |
7261 | return FAIL; | |
7262 | } | |
7263 | if (!wb_ok) | |
7264 | { | |
7265 | inst.error = _("instruction does not support writeback"); | |
7266 | return FAIL; | |
7267 | } | |
7268 | inst.instruction |= WRITE_BACK; | |
09d92015 | 7269 | } |
a737bd4d | 7270 | |
c19d1205 | 7271 | if (reloc_override) |
21d799b5 | 7272 | inst.reloc.type = (bfd_reloc_code_real_type) reloc_override; |
4962c51a MS |
7273 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
7274 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
7275 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
7276 | { | |
7277 | if (thumb_mode) | |
7278 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
7279 | else | |
7280 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
7281 | } | |
7282 | ||
26d97720 NS |
7283 | /* Prefer + for zero encoded value. */ |
7284 | if (!inst.operands[i].negative) | |
7285 | inst.instruction |= INDEX_UP; | |
7286 | ||
c19d1205 ZW |
7287 | return SUCCESS; |
7288 | } | |
a737bd4d | 7289 | |
c19d1205 ZW |
7290 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
7291 | Determine whether it can be performed with a move instruction; if | |
7292 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
7293 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
7294 | load and return FALSE. If this is not a valid thing to do in the | |
7295 | current context, set inst.error and return TRUE. | |
a737bd4d | 7296 | |
c19d1205 ZW |
7297 | inst.operands[i] describes the destination register. */ |
7298 | ||
c921be7d | 7299 | static bfd_boolean |
c19d1205 ZW |
7300 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) |
7301 | { | |
53365c0d PB |
7302 | unsigned long tbit; |
7303 | ||
7304 | if (thumb_p) | |
7305 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
7306 | else | |
7307 | tbit = LOAD_BIT; | |
7308 | ||
7309 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 7310 | { |
c19d1205 | 7311 | inst.error = _("invalid pseudo operation"); |
c921be7d | 7312 | return TRUE; |
09d92015 | 7313 | } |
c19d1205 | 7314 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
7315 | { |
7316 | inst.error = _("constant expression expected"); | |
c921be7d | 7317 | return TRUE; |
09d92015 | 7318 | } |
c19d1205 | 7319 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 7320 | { |
c19d1205 ZW |
7321 | if (thumb_p) |
7322 | { | |
53365c0d | 7323 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
7324 | { |
7325 | /* This can be done with a mov(1) instruction. */ | |
7326 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
7327 | inst.instruction |= inst.reloc.exp.X_add_number; | |
c921be7d | 7328 | return TRUE; |
c19d1205 ZW |
7329 | } |
7330 | } | |
7331 | else | |
7332 | { | |
7333 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
7334 | if (value != FAIL) | |
7335 | { | |
7336 | /* This can be done with a mov instruction. */ | |
7337 | inst.instruction &= LITERAL_MASK; | |
7338 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
7339 | inst.instruction |= value & 0xfff; | |
c921be7d | 7340 | return TRUE; |
c19d1205 | 7341 | } |
09d92015 | 7342 | |
c19d1205 ZW |
7343 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
7344 | if (value != FAIL) | |
7345 | { | |
7346 | /* This can be done with a mvn instruction. */ | |
7347 | inst.instruction &= LITERAL_MASK; | |
7348 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
7349 | inst.instruction |= value & 0xfff; | |
c921be7d | 7350 | return TRUE; |
c19d1205 ZW |
7351 | } |
7352 | } | |
09d92015 MM |
7353 | } |
7354 | ||
c19d1205 ZW |
7355 | if (add_to_lit_pool () == FAIL) |
7356 | { | |
7357 | inst.error = _("literal pool insertion failed"); | |
c921be7d | 7358 | return TRUE; |
c19d1205 ZW |
7359 | } |
7360 | inst.operands[1].reg = REG_PC; | |
7361 | inst.operands[1].isreg = 1; | |
7362 | inst.operands[1].preind = 1; | |
7363 | inst.reloc.pc_rel = 1; | |
7364 | inst.reloc.type = (thumb_p | |
7365 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
7366 | : (mode_3 | |
7367 | ? BFD_RELOC_ARM_HWLITERAL | |
7368 | : BFD_RELOC_ARM_LITERAL)); | |
c921be7d | 7369 | return FALSE; |
09d92015 MM |
7370 | } |
7371 | ||
5f4273c7 | 7372 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
7373 | First some generics; their names are taken from the conventional |
7374 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 7375 | |
a737bd4d | 7376 | static void |
c19d1205 | 7377 | do_noargs (void) |
09d92015 | 7378 | { |
c19d1205 | 7379 | } |
a737bd4d | 7380 | |
c19d1205 ZW |
7381 | static void |
7382 | do_rd (void) | |
7383 | { | |
7384 | inst.instruction |= inst.operands[0].reg << 12; | |
7385 | } | |
a737bd4d | 7386 | |
c19d1205 ZW |
7387 | static void |
7388 | do_rd_rm (void) | |
7389 | { | |
7390 | inst.instruction |= inst.operands[0].reg << 12; | |
7391 | inst.instruction |= inst.operands[1].reg; | |
7392 | } | |
09d92015 | 7393 | |
9eb6c0f1 MGD |
7394 | static void |
7395 | do_rm_rn (void) | |
7396 | { | |
7397 | inst.instruction |= inst.operands[0].reg; | |
7398 | inst.instruction |= inst.operands[1].reg << 16; | |
7399 | } | |
7400 | ||
c19d1205 ZW |
7401 | static void |
7402 | do_rd_rn (void) | |
7403 | { | |
7404 | inst.instruction |= inst.operands[0].reg << 12; | |
7405 | inst.instruction |= inst.operands[1].reg << 16; | |
7406 | } | |
a737bd4d | 7407 | |
c19d1205 ZW |
7408 | static void |
7409 | do_rn_rd (void) | |
7410 | { | |
7411 | inst.instruction |= inst.operands[0].reg << 16; | |
7412 | inst.instruction |= inst.operands[1].reg << 12; | |
7413 | } | |
09d92015 | 7414 | |
59d09be6 MGD |
7415 | static bfd_boolean |
7416 | check_obsolete (const arm_feature_set *feature, const char *msg) | |
7417 | { | |
7418 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
7419 | { | |
7420 | as_warn ("%s", msg); | |
7421 | return TRUE; | |
7422 | } | |
7423 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
7424 | { | |
7425 | as_bad ("%s", msg); | |
7426 | return TRUE; | |
7427 | } | |
7428 | ||
7429 | return FALSE; | |
7430 | } | |
7431 | ||
c19d1205 ZW |
7432 | static void |
7433 | do_rd_rm_rn (void) | |
7434 | { | |
9a64e435 | 7435 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 7436 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 7437 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
7438 | { |
7439 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
7440 | _("Rn must not overlap other operands")); | |
7441 | ||
59d09be6 MGD |
7442 | /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7. |
7443 | */ | |
7444 | if (!check_obsolete (&arm_ext_v8, | |
7445 | _("swp{b} use is obsoleted for ARMv8 and later")) | |
7446 | && warn_on_deprecated | |
7447 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6)) | |
7448 | as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7")); | |
56adecf4 | 7449 | } |
59d09be6 | 7450 | |
c19d1205 ZW |
7451 | inst.instruction |= inst.operands[0].reg << 12; |
7452 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 7453 | inst.instruction |= Rn << 16; |
c19d1205 | 7454 | } |
09d92015 | 7455 | |
c19d1205 ZW |
7456 | static void |
7457 | do_rd_rn_rm (void) | |
7458 | { | |
7459 | inst.instruction |= inst.operands[0].reg << 12; | |
7460 | inst.instruction |= inst.operands[1].reg << 16; | |
7461 | inst.instruction |= inst.operands[2].reg; | |
7462 | } | |
a737bd4d | 7463 | |
c19d1205 ZW |
7464 | static void |
7465 | do_rm_rd_rn (void) | |
7466 | { | |
5be8be5d DG |
7467 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
7468 | constraint (((inst.reloc.exp.X_op != O_constant | |
7469 | && inst.reloc.exp.X_op != O_illegal) | |
7470 | || inst.reloc.exp.X_add_number != 0), | |
7471 | BAD_ADDR_MODE); | |
c19d1205 ZW |
7472 | inst.instruction |= inst.operands[0].reg; |
7473 | inst.instruction |= inst.operands[1].reg << 12; | |
7474 | inst.instruction |= inst.operands[2].reg << 16; | |
7475 | } | |
09d92015 | 7476 | |
c19d1205 ZW |
7477 | static void |
7478 | do_imm0 (void) | |
7479 | { | |
7480 | inst.instruction |= inst.operands[0].imm; | |
7481 | } | |
09d92015 | 7482 | |
c19d1205 ZW |
7483 | static void |
7484 | do_rd_cpaddr (void) | |
7485 | { | |
7486 | inst.instruction |= inst.operands[0].reg << 12; | |
7487 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 7488 | } |
a737bd4d | 7489 | |
c19d1205 ZW |
7490 | /* ARM instructions, in alphabetical order by function name (except |
7491 | that wrapper functions appear immediately after the function they | |
7492 | wrap). */ | |
09d92015 | 7493 | |
c19d1205 ZW |
7494 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
7495 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
7496 | |
7497 | static void | |
c19d1205 | 7498 | do_adr (void) |
09d92015 | 7499 | { |
c19d1205 | 7500 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 7501 | |
c19d1205 ZW |
7502 | /* Frag hacking will turn this into a sub instruction if the offset turns |
7503 | out to be negative. */ | |
7504 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 7505 | inst.reloc.pc_rel = 1; |
2fc8bdac | 7506 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 7507 | } |
b99bd4ef | 7508 | |
c19d1205 ZW |
7509 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
7510 | into a relative address of the form: | |
7511 | add rd, pc, #low(label-.-8)" | |
7512 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 7513 | |
c19d1205 ZW |
7514 | static void |
7515 | do_adrl (void) | |
7516 | { | |
7517 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 7518 | |
c19d1205 ZW |
7519 | /* Frag hacking will turn this into a sub instruction if the offset turns |
7520 | out to be negative. */ | |
7521 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
7522 | inst.reloc.pc_rel = 1; |
7523 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 7524 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
7525 | } |
7526 | ||
b99bd4ef | 7527 | static void |
c19d1205 | 7528 | do_arit (void) |
b99bd4ef | 7529 | { |
c19d1205 ZW |
7530 | if (!inst.operands[1].present) |
7531 | inst.operands[1].reg = inst.operands[0].reg; | |
7532 | inst.instruction |= inst.operands[0].reg << 12; | |
7533 | inst.instruction |= inst.operands[1].reg << 16; | |
7534 | encode_arm_shifter_operand (2); | |
7535 | } | |
b99bd4ef | 7536 | |
62b3e311 PB |
7537 | static void |
7538 | do_barrier (void) | |
7539 | { | |
7540 | if (inst.operands[0].present) | |
7541 | { | |
7542 | constraint ((inst.instruction & 0xf0) != 0x40 | |
52e7f43d RE |
7543 | && inst.operands[0].imm > 0xf |
7544 | && inst.operands[0].imm < 0x0, | |
bd3ba5d1 | 7545 | _("bad barrier type")); |
62b3e311 PB |
7546 | inst.instruction |= inst.operands[0].imm; |
7547 | } | |
7548 | else | |
7549 | inst.instruction |= 0xf; | |
7550 | } | |
7551 | ||
c19d1205 ZW |
7552 | static void |
7553 | do_bfc (void) | |
7554 | { | |
7555 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
7556 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7557 | /* The instruction encoding stores the LSB and MSB, | |
7558 | not the LSB and width. */ | |
7559 | inst.instruction |= inst.operands[0].reg << 12; | |
7560 | inst.instruction |= inst.operands[1].imm << 7; | |
7561 | inst.instruction |= (msb - 1) << 16; | |
7562 | } | |
b99bd4ef | 7563 | |
c19d1205 ZW |
7564 | static void |
7565 | do_bfi (void) | |
7566 | { | |
7567 | unsigned int msb; | |
b99bd4ef | 7568 | |
c19d1205 ZW |
7569 | /* #0 in second position is alternative syntax for bfc, which is |
7570 | the same instruction but with REG_PC in the Rm field. */ | |
7571 | if (!inst.operands[1].isreg) | |
7572 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 7573 | |
c19d1205 ZW |
7574 | msb = inst.operands[2].imm + inst.operands[3].imm; |
7575 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7576 | /* The instruction encoding stores the LSB and MSB, | |
7577 | not the LSB and width. */ | |
7578 | inst.instruction |= inst.operands[0].reg << 12; | |
7579 | inst.instruction |= inst.operands[1].reg; | |
7580 | inst.instruction |= inst.operands[2].imm << 7; | |
7581 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
7582 | } |
7583 | ||
b99bd4ef | 7584 | static void |
c19d1205 | 7585 | do_bfx (void) |
b99bd4ef | 7586 | { |
c19d1205 ZW |
7587 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
7588 | _("bit-field extends past end of register")); | |
7589 | inst.instruction |= inst.operands[0].reg << 12; | |
7590 | inst.instruction |= inst.operands[1].reg; | |
7591 | inst.instruction |= inst.operands[2].imm << 7; | |
7592 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
7593 | } | |
09d92015 | 7594 | |
c19d1205 ZW |
7595 | /* ARM V5 breakpoint instruction (argument parse) |
7596 | BKPT <16 bit unsigned immediate> | |
7597 | Instruction is not conditional. | |
7598 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
7599 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 7600 | |
c19d1205 ZW |
7601 | static void |
7602 | do_bkpt (void) | |
7603 | { | |
7604 | /* Top 12 of 16 bits to bits 19:8. */ | |
7605 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 7606 | |
c19d1205 ZW |
7607 | /* Bottom 4 of 16 bits to bits 3:0. */ |
7608 | inst.instruction |= inst.operands[0].imm & 0xf; | |
7609 | } | |
09d92015 | 7610 | |
c19d1205 ZW |
7611 | static void |
7612 | encode_branch (int default_reloc) | |
7613 | { | |
7614 | if (inst.operands[0].hasreloc) | |
7615 | { | |
0855e32b NS |
7616 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32 |
7617 | && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL, | |
7618 | _("the only valid suffixes here are '(plt)' and '(tlscall)'")); | |
7619 | inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 | |
7620 | ? BFD_RELOC_ARM_PLT32 | |
7621 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 7622 | } |
b99bd4ef | 7623 | else |
9ae92b05 | 7624 | inst.reloc.type = (bfd_reloc_code_real_type) default_reloc; |
2fc8bdac | 7625 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
7626 | } |
7627 | ||
b99bd4ef | 7628 | static void |
c19d1205 | 7629 | do_branch (void) |
b99bd4ef | 7630 | { |
39b41c9c PB |
7631 | #ifdef OBJ_ELF |
7632 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7633 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7634 | else | |
7635 | #endif | |
7636 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
7637 | } | |
7638 | ||
7639 | static void | |
7640 | do_bl (void) | |
7641 | { | |
7642 | #ifdef OBJ_ELF | |
7643 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7644 | { | |
7645 | if (inst.cond == COND_ALWAYS) | |
7646 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
7647 | else | |
7648 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7649 | } | |
7650 | else | |
7651 | #endif | |
7652 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 7653 | } |
b99bd4ef | 7654 | |
c19d1205 ZW |
7655 | /* ARM V5 branch-link-exchange instruction (argument parse) |
7656 | BLX <target_addr> ie BLX(1) | |
7657 | BLX{<condition>} <Rm> ie BLX(2) | |
7658 | Unfortunately, there are two different opcodes for this mnemonic. | |
7659 | So, the insns[].value is not used, and the code here zaps values | |
7660 | into inst.instruction. | |
7661 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 7662 | |
c19d1205 ZW |
7663 | static void |
7664 | do_blx (void) | |
7665 | { | |
7666 | if (inst.operands[0].isreg) | |
b99bd4ef | 7667 | { |
c19d1205 ZW |
7668 | /* Arg is a register; the opcode provided by insns[] is correct. |
7669 | It is not illegal to do "blx pc", just useless. */ | |
7670 | if (inst.operands[0].reg == REG_PC) | |
7671 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 7672 | |
c19d1205 ZW |
7673 | inst.instruction |= inst.operands[0].reg; |
7674 | } | |
7675 | else | |
b99bd4ef | 7676 | { |
c19d1205 | 7677 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
7678 | conditionally, and the opcode must be adjusted. |
7679 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
7680 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 7681 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 7682 | inst.instruction = 0xfa000000; |
267bf995 | 7683 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 7684 | } |
c19d1205 ZW |
7685 | } |
7686 | ||
7687 | static void | |
7688 | do_bx (void) | |
7689 | { | |
845b51d6 PB |
7690 | bfd_boolean want_reloc; |
7691 | ||
c19d1205 ZW |
7692 | if (inst.operands[0].reg == REG_PC) |
7693 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 7694 | |
c19d1205 | 7695 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
7696 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
7697 | it is for ARMv4t or earlier. */ | |
7698 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
7699 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
7700 | want_reloc = TRUE; | |
7701 | ||
5ad34203 | 7702 | #ifdef OBJ_ELF |
845b51d6 | 7703 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 7704 | #endif |
584206db | 7705 | want_reloc = FALSE; |
845b51d6 PB |
7706 | |
7707 | if (want_reloc) | |
7708 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
7709 | } |
7710 | ||
c19d1205 ZW |
7711 | |
7712 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
7713 | |
7714 | static void | |
c19d1205 | 7715 | do_bxj (void) |
a737bd4d | 7716 | { |
c19d1205 ZW |
7717 | if (inst.operands[0].reg == REG_PC) |
7718 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
7719 | ||
7720 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
7721 | } |
7722 | ||
c19d1205 ZW |
7723 | /* Co-processor data operation: |
7724 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
7725 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
7726 | static void | |
7727 | do_cdp (void) | |
7728 | { | |
7729 | inst.instruction |= inst.operands[0].reg << 8; | |
7730 | inst.instruction |= inst.operands[1].imm << 20; | |
7731 | inst.instruction |= inst.operands[2].reg << 12; | |
7732 | inst.instruction |= inst.operands[3].reg << 16; | |
7733 | inst.instruction |= inst.operands[4].reg; | |
7734 | inst.instruction |= inst.operands[5].imm << 5; | |
7735 | } | |
a737bd4d NC |
7736 | |
7737 | static void | |
c19d1205 | 7738 | do_cmp (void) |
a737bd4d | 7739 | { |
c19d1205 ZW |
7740 | inst.instruction |= inst.operands[0].reg << 16; |
7741 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
7742 | } |
7743 | ||
c19d1205 ZW |
7744 | /* Transfer between coprocessor and ARM registers. |
7745 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
7746 | MRC2 | |
7747 | MCR{cond} | |
7748 | MCR2 | |
7749 | ||
7750 | No special properties. */ | |
09d92015 | 7751 | |
dcbd0d71 MGD |
7752 | struct deprecated_coproc_regs_s |
7753 | { | |
7754 | unsigned cp; | |
7755 | int opc1; | |
7756 | unsigned crn; | |
7757 | unsigned crm; | |
7758 | int opc2; | |
7759 | arm_feature_set deprecated; | |
7760 | arm_feature_set obsoleted; | |
7761 | const char *dep_msg; | |
7762 | const char *obs_msg; | |
7763 | }; | |
7764 | ||
7765 | #define DEPR_ACCESS_V8 \ | |
7766 | N_("This coprocessor register access is deprecated in ARMv8") | |
7767 | ||
7768 | /* Table of all deprecated coprocessor registers. */ | |
7769 | static struct deprecated_coproc_regs_s deprecated_coproc_regs[] = | |
7770 | { | |
7771 | {15, 0, 7, 10, 5, /* CP15DMB. */ | |
7772 | ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0), | |
7773 | DEPR_ACCESS_V8, NULL}, | |
7774 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
7775 | ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0), | |
7776 | DEPR_ACCESS_V8, NULL}, | |
7777 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
7778 | ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0), | |
7779 | DEPR_ACCESS_V8, NULL}, | |
7780 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
7781 | ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0), | |
7782 | DEPR_ACCESS_V8, NULL}, | |
7783 | {14, 6, 0, 0, 0, /* TEECR. */ | |
7784 | ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0), | |
7785 | DEPR_ACCESS_V8, NULL}, | |
7786 | }; | |
7787 | ||
7788 | #undef DEPR_ACCESS_V8 | |
7789 | ||
7790 | static const size_t deprecated_coproc_reg_count = | |
7791 | sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]); | |
7792 | ||
09d92015 | 7793 | static void |
c19d1205 | 7794 | do_co_reg (void) |
09d92015 | 7795 | { |
fdfde340 | 7796 | unsigned Rd; |
dcbd0d71 | 7797 | size_t i; |
fdfde340 JM |
7798 | |
7799 | Rd = inst.operands[2].reg; | |
7800 | if (thumb_mode) | |
7801 | { | |
7802 | if (inst.instruction == 0xee000010 | |
7803 | || inst.instruction == 0xfe000010) | |
7804 | /* MCR, MCR2 */ | |
7805 | reject_bad_reg (Rd); | |
7806 | else | |
7807 | /* MRC, MRC2 */ | |
7808 | constraint (Rd == REG_SP, BAD_SP); | |
7809 | } | |
7810 | else | |
7811 | { | |
7812 | /* MCR */ | |
7813 | if (inst.instruction == 0xe000010) | |
7814 | constraint (Rd == REG_PC, BAD_PC); | |
7815 | } | |
7816 | ||
dcbd0d71 MGD |
7817 | for (i = 0; i < deprecated_coproc_reg_count; ++i) |
7818 | { | |
7819 | const struct deprecated_coproc_regs_s *r = | |
7820 | deprecated_coproc_regs + i; | |
7821 | ||
7822 | if (inst.operands[0].reg == r->cp | |
7823 | && inst.operands[1].imm == r->opc1 | |
7824 | && inst.operands[3].reg == r->crn | |
7825 | && inst.operands[4].reg == r->crm | |
7826 | && inst.operands[5].imm == r->opc2) | |
7827 | { | |
7828 | if (!check_obsolete (&r->obsoleted, r->obs_msg) | |
7829 | && warn_on_deprecated | |
7830 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) | |
7831 | as_warn ("%s", r->dep_msg); | |
7832 | } | |
7833 | } | |
fdfde340 | 7834 | |
c19d1205 ZW |
7835 | inst.instruction |= inst.operands[0].reg << 8; |
7836 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 7837 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
7838 | inst.instruction |= inst.operands[3].reg << 16; |
7839 | inst.instruction |= inst.operands[4].reg; | |
7840 | inst.instruction |= inst.operands[5].imm << 5; | |
7841 | } | |
09d92015 | 7842 | |
c19d1205 ZW |
7843 | /* Transfer between coprocessor register and pair of ARM registers. |
7844 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
7845 | MCRR2 | |
7846 | MRRC{cond} | |
7847 | MRRC2 | |
b99bd4ef | 7848 | |
c19d1205 | 7849 | Two XScale instructions are special cases of these: |
09d92015 | 7850 | |
c19d1205 ZW |
7851 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
7852 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 7853 | |
5f4273c7 | 7854 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 7855 | |
c19d1205 ZW |
7856 | static void |
7857 | do_co_reg2c (void) | |
7858 | { | |
fdfde340 JM |
7859 | unsigned Rd, Rn; |
7860 | ||
7861 | Rd = inst.operands[2].reg; | |
7862 | Rn = inst.operands[3].reg; | |
7863 | ||
7864 | if (thumb_mode) | |
7865 | { | |
7866 | reject_bad_reg (Rd); | |
7867 | reject_bad_reg (Rn); | |
7868 | } | |
7869 | else | |
7870 | { | |
7871 | constraint (Rd == REG_PC, BAD_PC); | |
7872 | constraint (Rn == REG_PC, BAD_PC); | |
7873 | } | |
7874 | ||
c19d1205 ZW |
7875 | inst.instruction |= inst.operands[0].reg << 8; |
7876 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
7877 | inst.instruction |= Rd << 12; |
7878 | inst.instruction |= Rn << 16; | |
c19d1205 | 7879 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
7880 | } |
7881 | ||
c19d1205 ZW |
7882 | static void |
7883 | do_cpsi (void) | |
7884 | { | |
7885 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
7886 | if (inst.operands[1].present) |
7887 | { | |
7888 | inst.instruction |= CPSI_MMOD; | |
7889 | inst.instruction |= inst.operands[1].imm; | |
7890 | } | |
c19d1205 | 7891 | } |
b99bd4ef | 7892 | |
62b3e311 PB |
7893 | static void |
7894 | do_dbg (void) | |
7895 | { | |
7896 | inst.instruction |= inst.operands[0].imm; | |
7897 | } | |
7898 | ||
eea54501 MGD |
7899 | static void |
7900 | do_div (void) | |
7901 | { | |
7902 | unsigned Rd, Rn, Rm; | |
7903 | ||
7904 | Rd = inst.operands[0].reg; | |
7905 | Rn = (inst.operands[1].present | |
7906 | ? inst.operands[1].reg : Rd); | |
7907 | Rm = inst.operands[2].reg; | |
7908 | ||
7909 | constraint ((Rd == REG_PC), BAD_PC); | |
7910 | constraint ((Rn == REG_PC), BAD_PC); | |
7911 | constraint ((Rm == REG_PC), BAD_PC); | |
7912 | ||
7913 | inst.instruction |= Rd << 16; | |
7914 | inst.instruction |= Rn << 0; | |
7915 | inst.instruction |= Rm << 8; | |
7916 | } | |
7917 | ||
b99bd4ef | 7918 | static void |
c19d1205 | 7919 | do_it (void) |
b99bd4ef | 7920 | { |
c19d1205 | 7921 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
7922 | process it to do the validation as if in |
7923 | thumb mode, just in case the code gets | |
7924 | assembled for thumb using the unified syntax. */ | |
7925 | ||
c19d1205 | 7926 | inst.size = 0; |
e07e6e58 NC |
7927 | if (unified_syntax) |
7928 | { | |
7929 | set_it_insn_type (IT_INSN); | |
7930 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
7931 | now_it.cc = inst.operands[0].imm; | |
7932 | } | |
09d92015 | 7933 | } |
b99bd4ef | 7934 | |
6530b175 NC |
7935 | /* If there is only one register in the register list, |
7936 | then return its register number. Otherwise return -1. */ | |
7937 | static int | |
7938 | only_one_reg_in_list (int range) | |
7939 | { | |
7940 | int i = ffs (range) - 1; | |
7941 | return (i > 15 || range != (1 << i)) ? -1 : i; | |
7942 | } | |
7943 | ||
09d92015 | 7944 | static void |
6530b175 | 7945 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 7946 | { |
c19d1205 ZW |
7947 | int base_reg = inst.operands[0].reg; |
7948 | int range = inst.operands[1].imm; | |
6530b175 | 7949 | int one_reg; |
ea6ef066 | 7950 | |
c19d1205 ZW |
7951 | inst.instruction |= base_reg << 16; |
7952 | inst.instruction |= range; | |
ea6ef066 | 7953 | |
c19d1205 ZW |
7954 | if (inst.operands[1].writeback) |
7955 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 7956 | |
c19d1205 | 7957 | if (inst.operands[0].writeback) |
ea6ef066 | 7958 | { |
c19d1205 ZW |
7959 | inst.instruction |= WRITE_BACK; |
7960 | /* Check for unpredictable uses of writeback. */ | |
7961 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 7962 | { |
c19d1205 ZW |
7963 | /* Not allowed in LDM type 2. */ |
7964 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
7965 | && ((range & (1 << REG_PC)) == 0)) | |
7966 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7967 | /* Only allowed if base reg not in list for other types. */ | |
7968 | else if (range & (1 << base_reg)) | |
7969 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
7970 | } | |
7971 | else /* STM. */ | |
7972 | { | |
7973 | /* Not allowed for type 2. */ | |
7974 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
7975 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7976 | /* Only allowed if base reg not in list, or first in list. */ | |
7977 | else if ((range & (1 << base_reg)) | |
7978 | && (range & ((1 << base_reg) - 1))) | |
7979 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 7980 | } |
ea6ef066 | 7981 | } |
6530b175 NC |
7982 | |
7983 | /* If PUSH/POP has only one register, then use the A2 encoding. */ | |
7984 | one_reg = only_one_reg_in_list (range); | |
7985 | if (from_push_pop_mnem && one_reg >= 0) | |
7986 | { | |
7987 | int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH; | |
7988 | ||
7989 | inst.instruction &= A_COND_MASK; | |
7990 | inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP; | |
7991 | inst.instruction |= one_reg << 12; | |
7992 | } | |
7993 | } | |
7994 | ||
7995 | static void | |
7996 | do_ldmstm (void) | |
7997 | { | |
7998 | encode_ldmstm (/*from_push_pop_mnem=*/FALSE); | |
a737bd4d NC |
7999 | } |
8000 | ||
c19d1205 ZW |
8001 | /* ARMv5TE load-consecutive (argument parse) |
8002 | Mode is like LDRH. | |
8003 | ||
8004 | LDRccD R, mode | |
8005 | STRccD R, mode. */ | |
8006 | ||
a737bd4d | 8007 | static void |
c19d1205 | 8008 | do_ldrd (void) |
a737bd4d | 8009 | { |
c19d1205 | 8010 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 8011 | _("first transfer register must be even")); |
c19d1205 ZW |
8012 | constraint (inst.operands[1].present |
8013 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 8014 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
8015 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
8016 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 8017 | |
c19d1205 ZW |
8018 | if (!inst.operands[1].present) |
8019 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 8020 | |
c56791bb RE |
8021 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
8022 | register and the first register written; we have to diagnose | |
8023 | overlap between the base and the second register written here. */ | |
ea6ef066 | 8024 | |
c56791bb RE |
8025 | if (inst.operands[2].reg == inst.operands[1].reg |
8026 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
8027 | as_warn (_("base register written back, and overlaps " | |
8028 | "second transfer register")); | |
b05fe5cf | 8029 | |
c56791bb RE |
8030 | if (!(inst.instruction & V4_STR_BIT)) |
8031 | { | |
c19d1205 | 8032 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
8033 | destination (even if not write-back). */ |
8034 | if (inst.operands[2].immisreg | |
8035 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg | |
8036 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
8037 | as_warn (_("index register overlaps transfer register")); | |
b05fe5cf | 8038 | } |
c19d1205 ZW |
8039 | inst.instruction |= inst.operands[0].reg << 12; |
8040 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
8041 | } |
8042 | ||
8043 | static void | |
c19d1205 | 8044 | do_ldrex (void) |
b05fe5cf | 8045 | { |
c19d1205 ZW |
8046 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
8047 | || inst.operands[1].postind || inst.operands[1].writeback | |
8048 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
8049 | || inst.operands[1].negative |
8050 | /* This can arise if the programmer has written | |
8051 | strex rN, rM, foo | |
8052 | or if they have mistakenly used a register name as the last | |
8053 | operand, eg: | |
8054 | strex rN, rM, rX | |
8055 | It is very difficult to distinguish between these two cases | |
8056 | because "rX" might actually be a label. ie the register | |
8057 | name has been occluded by a symbol of the same name. So we | |
8058 | just generate a general 'bad addressing mode' type error | |
8059 | message and leave it up to the programmer to discover the | |
8060 | true cause and fix their mistake. */ | |
8061 | || (inst.operands[1].reg == REG_PC), | |
8062 | BAD_ADDR_MODE); | |
b05fe5cf | 8063 | |
c19d1205 ZW |
8064 | constraint (inst.reloc.exp.X_op != O_constant |
8065 | || inst.reloc.exp.X_add_number != 0, | |
8066 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 8067 | |
5be8be5d DG |
8068 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
8069 | ||
c19d1205 ZW |
8070 | inst.instruction |= inst.operands[0].reg << 12; |
8071 | inst.instruction |= inst.operands[1].reg << 16; | |
8072 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
8073 | } |
8074 | ||
8075 | static void | |
c19d1205 | 8076 | do_ldrexd (void) |
b05fe5cf | 8077 | { |
c19d1205 ZW |
8078 | constraint (inst.operands[0].reg % 2 != 0, |
8079 | _("even register required")); | |
8080 | constraint (inst.operands[1].present | |
8081 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
8082 | _("can only load two consecutive registers")); | |
8083 | /* If op 1 were present and equal to PC, this function wouldn't | |
8084 | have been called in the first place. */ | |
8085 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 8086 | |
c19d1205 ZW |
8087 | inst.instruction |= inst.operands[0].reg << 12; |
8088 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
8089 | } |
8090 | ||
1be5fd2e NC |
8091 | /* In both ARM and thumb state 'ldr pc, #imm' with an immediate |
8092 | which is not a multiple of four is UNPREDICTABLE. */ | |
8093 | static void | |
8094 | check_ldr_r15_aligned (void) | |
8095 | { | |
8096 | constraint (!(inst.operands[1].immisreg) | |
8097 | && (inst.operands[0].reg == REG_PC | |
8098 | && inst.operands[1].reg == REG_PC | |
8099 | && (inst.reloc.exp.X_add_number & 0x3)), | |
8100 | _("ldr to register 15 must be 4-byte alligned")); | |
8101 | } | |
8102 | ||
b05fe5cf | 8103 | static void |
c19d1205 | 8104 | do_ldst (void) |
b05fe5cf | 8105 | { |
c19d1205 ZW |
8106 | inst.instruction |= inst.operands[0].reg << 12; |
8107 | if (!inst.operands[1].isreg) | |
8108 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 8109 | return; |
c19d1205 | 8110 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
1be5fd2e | 8111 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
8112 | } |
8113 | ||
8114 | static void | |
c19d1205 | 8115 | do_ldstt (void) |
b05fe5cf | 8116 | { |
c19d1205 ZW |
8117 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
8118 | reject [Rn,...]. */ | |
8119 | if (inst.operands[1].preind) | |
b05fe5cf | 8120 | { |
bd3ba5d1 NC |
8121 | constraint (inst.reloc.exp.X_op != O_constant |
8122 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 8123 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 8124 | |
c19d1205 ZW |
8125 | inst.operands[1].preind = 0; |
8126 | inst.operands[1].postind = 1; | |
8127 | inst.operands[1].writeback = 1; | |
b05fe5cf | 8128 | } |
c19d1205 ZW |
8129 | inst.instruction |= inst.operands[0].reg << 12; |
8130 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
8131 | } | |
b05fe5cf | 8132 | |
c19d1205 | 8133 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 8134 | |
c19d1205 ZW |
8135 | static void |
8136 | do_ldstv4 (void) | |
8137 | { | |
ff4a8d2b | 8138 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
8139 | inst.instruction |= inst.operands[0].reg << 12; |
8140 | if (!inst.operands[1].isreg) | |
8141 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 8142 | return; |
c19d1205 | 8143 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
8144 | } |
8145 | ||
8146 | static void | |
c19d1205 | 8147 | do_ldsttv4 (void) |
b05fe5cf | 8148 | { |
c19d1205 ZW |
8149 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
8150 | reject [Rn,...]. */ | |
8151 | if (inst.operands[1].preind) | |
b05fe5cf | 8152 | { |
bd3ba5d1 NC |
8153 | constraint (inst.reloc.exp.X_op != O_constant |
8154 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 8155 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 8156 | |
c19d1205 ZW |
8157 | inst.operands[1].preind = 0; |
8158 | inst.operands[1].postind = 1; | |
8159 | inst.operands[1].writeback = 1; | |
b05fe5cf | 8160 | } |
c19d1205 ZW |
8161 | inst.instruction |= inst.operands[0].reg << 12; |
8162 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
8163 | } | |
b05fe5cf | 8164 | |
c19d1205 ZW |
8165 | /* Co-processor register load/store. |
8166 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
8167 | static void | |
8168 | do_lstc (void) | |
8169 | { | |
8170 | inst.instruction |= inst.operands[0].reg << 8; | |
8171 | inst.instruction |= inst.operands[1].reg << 12; | |
8172 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
8173 | } |
8174 | ||
b05fe5cf | 8175 | static void |
c19d1205 | 8176 | do_mlas (void) |
b05fe5cf | 8177 | { |
8fb9d7b9 | 8178 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 8179 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 8180 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 8181 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 8182 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 8183 | |
c19d1205 ZW |
8184 | inst.instruction |= inst.operands[0].reg << 16; |
8185 | inst.instruction |= inst.operands[1].reg; | |
8186 | inst.instruction |= inst.operands[2].reg << 8; | |
8187 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 8188 | } |
b05fe5cf | 8189 | |
c19d1205 ZW |
8190 | static void |
8191 | do_mov (void) | |
8192 | { | |
8193 | inst.instruction |= inst.operands[0].reg << 12; | |
8194 | encode_arm_shifter_operand (1); | |
8195 | } | |
b05fe5cf | 8196 | |
c19d1205 ZW |
8197 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
8198 | static void | |
8199 | do_mov16 (void) | |
8200 | { | |
b6895b4f PB |
8201 | bfd_vma imm; |
8202 | bfd_boolean top; | |
8203 | ||
8204 | top = (inst.instruction & 0x00400000) != 0; | |
8205 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
8206 | _(":lower16: not allowed this instruction")); | |
8207 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
8208 | _(":upper16: not allowed instruction")); | |
c19d1205 | 8209 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
8210 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
8211 | { | |
8212 | imm = inst.reloc.exp.X_add_number; | |
8213 | /* The value is in two pieces: 0:11, 16:19. */ | |
8214 | inst.instruction |= (imm & 0x00000fff); | |
8215 | inst.instruction |= (imm & 0x0000f000) << 4; | |
8216 | } | |
b05fe5cf | 8217 | } |
b99bd4ef | 8218 | |
037e8744 JB |
8219 | static void do_vfp_nsyn_opcode (const char *); |
8220 | ||
8221 | static int | |
8222 | do_vfp_nsyn_mrs (void) | |
8223 | { | |
8224 | if (inst.operands[0].isvec) | |
8225 | { | |
8226 | if (inst.operands[1].reg != 1) | |
8227 | first_error (_("operand 1 must be FPSCR")); | |
8228 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
8229 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
8230 | do_vfp_nsyn_opcode ("fmstat"); | |
8231 | } | |
8232 | else if (inst.operands[1].isvec) | |
8233 | do_vfp_nsyn_opcode ("fmrx"); | |
8234 | else | |
8235 | return FAIL; | |
5f4273c7 | 8236 | |
037e8744 JB |
8237 | return SUCCESS; |
8238 | } | |
8239 | ||
8240 | static int | |
8241 | do_vfp_nsyn_msr (void) | |
8242 | { | |
8243 | if (inst.operands[0].isvec) | |
8244 | do_vfp_nsyn_opcode ("fmxr"); | |
8245 | else | |
8246 | return FAIL; | |
8247 | ||
8248 | return SUCCESS; | |
8249 | } | |
8250 | ||
f7c21dc7 NC |
8251 | static void |
8252 | do_vmrs (void) | |
8253 | { | |
8254 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 8255 | |
f7c21dc7 NC |
8256 | if (thumb_mode && inst.operands[0].reg == REG_SP) |
8257 | { | |
8258 | inst.error = BAD_SP; | |
8259 | return; | |
8260 | } | |
8261 | ||
8262 | /* APSR_ sets isvec. All other refs to PC are illegal. */ | |
8263 | if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC) | |
8264 | { | |
8265 | inst.error = BAD_PC; | |
8266 | return; | |
8267 | } | |
8268 | ||
7465e07a NC |
8269 | switch (inst.operands[1].reg) |
8270 | { | |
8271 | case 0: /* FPSID */ | |
8272 | case 1: /* FPSCR */ | |
8273 | case 6: /* MVFR1 */ | |
8274 | case 7: /* MVFR0 */ | |
8275 | case 8: /* FPEXC */ | |
8276 | inst.instruction |= (inst.operands[1].reg << 16); | |
8277 | break; | |
8278 | default: | |
8279 | first_error (_("operand 1 must be a VFP extension System Register")); | |
8280 | } | |
f7c21dc7 NC |
8281 | |
8282 | inst.instruction |= (Rt << 12); | |
8283 | } | |
8284 | ||
8285 | static void | |
8286 | do_vmsr (void) | |
8287 | { | |
8288 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 8289 | |
f7c21dc7 NC |
8290 | if (thumb_mode) |
8291 | reject_bad_reg (Rt); | |
8292 | else if (Rt == REG_PC) | |
8293 | { | |
8294 | inst.error = BAD_PC; | |
8295 | return; | |
8296 | } | |
8297 | ||
7465e07a NC |
8298 | switch (inst.operands[0].reg) |
8299 | { | |
8300 | case 0: /* FPSID */ | |
8301 | case 1: /* FPSCR */ | |
8302 | case 8: /* FPEXC */ | |
8303 | inst.instruction |= (inst.operands[0].reg << 16); | |
8304 | break; | |
8305 | default: | |
8306 | first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC")); | |
8307 | } | |
f7c21dc7 NC |
8308 | |
8309 | inst.instruction |= (Rt << 12); | |
8310 | } | |
8311 | ||
b99bd4ef | 8312 | static void |
c19d1205 | 8313 | do_mrs (void) |
b99bd4ef | 8314 | { |
90ec0d68 MGD |
8315 | unsigned br; |
8316 | ||
037e8744 JB |
8317 | if (do_vfp_nsyn_mrs () == SUCCESS) |
8318 | return; | |
8319 | ||
ff4a8d2b | 8320 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 8321 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
8322 | |
8323 | if (inst.operands[1].isreg) | |
8324 | { | |
8325 | br = inst.operands[1].reg; | |
8326 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000)) | |
8327 | as_bad (_("bad register for mrs")); | |
8328 | } | |
8329 | else | |
8330 | { | |
8331 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
8332 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
8333 | != (PSR_c|PSR_f), | |
d2cd1205 | 8334 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
8335 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
8336 | } | |
8337 | ||
8338 | inst.instruction |= br; | |
c19d1205 | 8339 | } |
b99bd4ef | 8340 | |
c19d1205 ZW |
8341 | /* Two possible forms: |
8342 | "{C|S}PSR_<field>, Rm", | |
8343 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 8344 | |
c19d1205 ZW |
8345 | static void |
8346 | do_msr (void) | |
8347 | { | |
037e8744 JB |
8348 | if (do_vfp_nsyn_msr () == SUCCESS) |
8349 | return; | |
8350 | ||
c19d1205 ZW |
8351 | inst.instruction |= inst.operands[0].imm; |
8352 | if (inst.operands[1].isreg) | |
8353 | inst.instruction |= inst.operands[1].reg; | |
8354 | else | |
b99bd4ef | 8355 | { |
c19d1205 ZW |
8356 | inst.instruction |= INST_IMMEDIATE; |
8357 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
8358 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 8359 | } |
b99bd4ef NC |
8360 | } |
8361 | ||
c19d1205 ZW |
8362 | static void |
8363 | do_mul (void) | |
a737bd4d | 8364 | { |
ff4a8d2b NC |
8365 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
8366 | ||
c19d1205 ZW |
8367 | if (!inst.operands[2].present) |
8368 | inst.operands[2].reg = inst.operands[0].reg; | |
8369 | inst.instruction |= inst.operands[0].reg << 16; | |
8370 | inst.instruction |= inst.operands[1].reg; | |
8371 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 8372 | |
8fb9d7b9 MS |
8373 | if (inst.operands[0].reg == inst.operands[1].reg |
8374 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
8375 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
8376 | } |
8377 | ||
c19d1205 ZW |
8378 | /* Long Multiply Parser |
8379 | UMULL RdLo, RdHi, Rm, Rs | |
8380 | SMULL RdLo, RdHi, Rm, Rs | |
8381 | UMLAL RdLo, RdHi, Rm, Rs | |
8382 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
8383 | |
8384 | static void | |
c19d1205 | 8385 | do_mull (void) |
b99bd4ef | 8386 | { |
c19d1205 ZW |
8387 | inst.instruction |= inst.operands[0].reg << 12; |
8388 | inst.instruction |= inst.operands[1].reg << 16; | |
8389 | inst.instruction |= inst.operands[2].reg; | |
8390 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 8391 | |
682b27ad PB |
8392 | /* rdhi and rdlo must be different. */ |
8393 | if (inst.operands[0].reg == inst.operands[1].reg) | |
8394 | as_tsktsk (_("rdhi and rdlo must be different")); | |
8395 | ||
8396 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
8397 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 8398 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 8399 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
8400 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
8401 | } | |
b99bd4ef | 8402 | |
c19d1205 ZW |
8403 | static void |
8404 | do_nop (void) | |
8405 | { | |
e7495e45 NS |
8406 | if (inst.operands[0].present |
8407 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
8408 | { |
8409 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
8410 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
8411 | inst.instruction |= 0x0320f000; |
8412 | if (inst.operands[0].present) | |
8413 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 8414 | } |
b99bd4ef NC |
8415 | } |
8416 | ||
c19d1205 ZW |
8417 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
8418 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
8419 | Condition defaults to COND_ALWAYS. | |
8420 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
8421 | |
8422 | static void | |
c19d1205 | 8423 | do_pkhbt (void) |
b99bd4ef | 8424 | { |
c19d1205 ZW |
8425 | inst.instruction |= inst.operands[0].reg << 12; |
8426 | inst.instruction |= inst.operands[1].reg << 16; | |
8427 | inst.instruction |= inst.operands[2].reg; | |
8428 | if (inst.operands[3].present) | |
8429 | encode_arm_shift (3); | |
8430 | } | |
b99bd4ef | 8431 | |
c19d1205 | 8432 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 8433 | |
c19d1205 ZW |
8434 | static void |
8435 | do_pkhtb (void) | |
8436 | { | |
8437 | if (!inst.operands[3].present) | |
b99bd4ef | 8438 | { |
c19d1205 ZW |
8439 | /* If the shift specifier is omitted, turn the instruction |
8440 | into pkhbt rd, rm, rn. */ | |
8441 | inst.instruction &= 0xfff00010; | |
8442 | inst.instruction |= inst.operands[0].reg << 12; | |
8443 | inst.instruction |= inst.operands[1].reg; | |
8444 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8445 | } |
8446 | else | |
8447 | { | |
c19d1205 ZW |
8448 | inst.instruction |= inst.operands[0].reg << 12; |
8449 | inst.instruction |= inst.operands[1].reg << 16; | |
8450 | inst.instruction |= inst.operands[2].reg; | |
8451 | encode_arm_shift (3); | |
b99bd4ef NC |
8452 | } |
8453 | } | |
8454 | ||
c19d1205 | 8455 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 8456 | MP Extensions: Preload for write |
c19d1205 | 8457 | |
60e5ef9f | 8458 | PLD(W) <addr_mode> |
c19d1205 ZW |
8459 | |
8460 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
8461 | |
8462 | static void | |
c19d1205 | 8463 | do_pld (void) |
b99bd4ef | 8464 | { |
c19d1205 ZW |
8465 | constraint (!inst.operands[0].isreg, |
8466 | _("'[' expected after PLD mnemonic")); | |
8467 | constraint (inst.operands[0].postind, | |
8468 | _("post-indexed expression used in preload instruction")); | |
8469 | constraint (inst.operands[0].writeback, | |
8470 | _("writeback used in preload instruction")); | |
8471 | constraint (!inst.operands[0].preind, | |
8472 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
8473 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
8474 | } | |
b99bd4ef | 8475 | |
62b3e311 PB |
8476 | /* ARMv7: PLI <addr_mode> */ |
8477 | static void | |
8478 | do_pli (void) | |
8479 | { | |
8480 | constraint (!inst.operands[0].isreg, | |
8481 | _("'[' expected after PLI mnemonic")); | |
8482 | constraint (inst.operands[0].postind, | |
8483 | _("post-indexed expression used in preload instruction")); | |
8484 | constraint (inst.operands[0].writeback, | |
8485 | _("writeback used in preload instruction")); | |
8486 | constraint (!inst.operands[0].preind, | |
8487 | _("unindexed addressing used in preload instruction")); | |
8488 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
8489 | inst.instruction &= ~PRE_INDEX; | |
8490 | } | |
8491 | ||
c19d1205 ZW |
8492 | static void |
8493 | do_push_pop (void) | |
8494 | { | |
8495 | inst.operands[1] = inst.operands[0]; | |
8496 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
8497 | inst.operands[0].isreg = 1; | |
8498 | inst.operands[0].writeback = 1; | |
8499 | inst.operands[0].reg = REG_SP; | |
6530b175 | 8500 | encode_ldmstm (/*from_push_pop_mnem=*/TRUE); |
c19d1205 | 8501 | } |
b99bd4ef | 8502 | |
c19d1205 ZW |
8503 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
8504 | word at the specified address and the following word | |
8505 | respectively. | |
8506 | Unconditionally executed. | |
8507 | Error if Rn is R15. */ | |
b99bd4ef | 8508 | |
c19d1205 ZW |
8509 | static void |
8510 | do_rfe (void) | |
8511 | { | |
8512 | inst.instruction |= inst.operands[0].reg << 16; | |
8513 | if (inst.operands[0].writeback) | |
8514 | inst.instruction |= WRITE_BACK; | |
8515 | } | |
b99bd4ef | 8516 | |
c19d1205 | 8517 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 8518 | |
c19d1205 ZW |
8519 | static void |
8520 | do_ssat (void) | |
8521 | { | |
8522 | inst.instruction |= inst.operands[0].reg << 12; | |
8523 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
8524 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 8525 | |
c19d1205 ZW |
8526 | if (inst.operands[3].present) |
8527 | encode_arm_shift (3); | |
b99bd4ef NC |
8528 | } |
8529 | ||
c19d1205 | 8530 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
8531 | |
8532 | static void | |
c19d1205 | 8533 | do_usat (void) |
b99bd4ef | 8534 | { |
c19d1205 ZW |
8535 | inst.instruction |= inst.operands[0].reg << 12; |
8536 | inst.instruction |= inst.operands[1].imm << 16; | |
8537 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 8538 | |
c19d1205 ZW |
8539 | if (inst.operands[3].present) |
8540 | encode_arm_shift (3); | |
b99bd4ef NC |
8541 | } |
8542 | ||
c19d1205 | 8543 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
8544 | |
8545 | static void | |
c19d1205 | 8546 | do_ssat16 (void) |
09d92015 | 8547 | { |
c19d1205 ZW |
8548 | inst.instruction |= inst.operands[0].reg << 12; |
8549 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
8550 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
8551 | } |
8552 | ||
c19d1205 ZW |
8553 | static void |
8554 | do_usat16 (void) | |
a737bd4d | 8555 | { |
c19d1205 ZW |
8556 | inst.instruction |= inst.operands[0].reg << 12; |
8557 | inst.instruction |= inst.operands[1].imm << 16; | |
8558 | inst.instruction |= inst.operands[2].reg; | |
8559 | } | |
a737bd4d | 8560 | |
c19d1205 ZW |
8561 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
8562 | preserving the other bits. | |
a737bd4d | 8563 | |
c19d1205 ZW |
8564 | setend <endian_specifier>, where <endian_specifier> is either |
8565 | BE or LE. */ | |
a737bd4d | 8566 | |
c19d1205 ZW |
8567 | static void |
8568 | do_setend (void) | |
8569 | { | |
12e37cbc MGD |
8570 | if (warn_on_deprecated |
8571 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
8572 | as_warn (_("setend use is deprecated for ARMv8")); | |
8573 | ||
c19d1205 ZW |
8574 | if (inst.operands[0].imm) |
8575 | inst.instruction |= 0x200; | |
a737bd4d NC |
8576 | } |
8577 | ||
8578 | static void | |
c19d1205 | 8579 | do_shift (void) |
a737bd4d | 8580 | { |
c19d1205 ZW |
8581 | unsigned int Rm = (inst.operands[1].present |
8582 | ? inst.operands[1].reg | |
8583 | : inst.operands[0].reg); | |
a737bd4d | 8584 | |
c19d1205 ZW |
8585 | inst.instruction |= inst.operands[0].reg << 12; |
8586 | inst.instruction |= Rm; | |
8587 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 8588 | { |
c19d1205 ZW |
8589 | inst.instruction |= inst.operands[2].reg << 8; |
8590 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
8591 | /* PR 12854: Error on extraneous shifts. */ |
8592 | constraint (inst.operands[2].shifted, | |
8593 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
8594 | } |
8595 | else | |
c19d1205 | 8596 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
8597 | } |
8598 | ||
09d92015 | 8599 | static void |
3eb17e6b | 8600 | do_smc (void) |
09d92015 | 8601 | { |
3eb17e6b | 8602 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 8603 | inst.reloc.pc_rel = 0; |
09d92015 MM |
8604 | } |
8605 | ||
90ec0d68 MGD |
8606 | static void |
8607 | do_hvc (void) | |
8608 | { | |
8609 | inst.reloc.type = BFD_RELOC_ARM_HVC; | |
8610 | inst.reloc.pc_rel = 0; | |
8611 | } | |
8612 | ||
09d92015 | 8613 | static void |
c19d1205 | 8614 | do_swi (void) |
09d92015 | 8615 | { |
c19d1205 ZW |
8616 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
8617 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
8618 | } |
8619 | ||
c19d1205 ZW |
8620 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
8621 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
8622 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
8623 | Error if any register is R15. */ | |
e16bb312 | 8624 | |
c19d1205 ZW |
8625 | static void |
8626 | do_smla (void) | |
e16bb312 | 8627 | { |
c19d1205 ZW |
8628 | inst.instruction |= inst.operands[0].reg << 16; |
8629 | inst.instruction |= inst.operands[1].reg; | |
8630 | inst.instruction |= inst.operands[2].reg << 8; | |
8631 | inst.instruction |= inst.operands[3].reg << 12; | |
8632 | } | |
a737bd4d | 8633 | |
c19d1205 ZW |
8634 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
8635 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
8636 | Error if any register is R15. | |
8637 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 8638 | |
c19d1205 ZW |
8639 | static void |
8640 | do_smlal (void) | |
8641 | { | |
8642 | inst.instruction |= inst.operands[0].reg << 12; | |
8643 | inst.instruction |= inst.operands[1].reg << 16; | |
8644 | inst.instruction |= inst.operands[2].reg; | |
8645 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 8646 | |
c19d1205 ZW |
8647 | if (inst.operands[0].reg == inst.operands[1].reg) |
8648 | as_tsktsk (_("rdhi and rdlo must be different")); | |
8649 | } | |
a737bd4d | 8650 | |
c19d1205 ZW |
8651 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
8652 | SMULxy{cond} Rd,Rm,Rs | |
8653 | Error if any register is R15. */ | |
a737bd4d | 8654 | |
c19d1205 ZW |
8655 | static void |
8656 | do_smul (void) | |
8657 | { | |
8658 | inst.instruction |= inst.operands[0].reg << 16; | |
8659 | inst.instruction |= inst.operands[1].reg; | |
8660 | inst.instruction |= inst.operands[2].reg << 8; | |
8661 | } | |
a737bd4d | 8662 | |
b6702015 PB |
8663 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
8664 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 8665 | |
c19d1205 ZW |
8666 | static void |
8667 | do_srs (void) | |
8668 | { | |
b6702015 PB |
8669 | int reg; |
8670 | ||
8671 | if (inst.operands[0].present) | |
8672 | { | |
8673 | reg = inst.operands[0].reg; | |
fdfde340 | 8674 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
8675 | } |
8676 | else | |
fdfde340 | 8677 | reg = REG_SP; |
b6702015 PB |
8678 | |
8679 | inst.instruction |= reg << 16; | |
8680 | inst.instruction |= inst.operands[1].imm; | |
8681 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
8682 | inst.instruction |= WRITE_BACK; |
8683 | } | |
a737bd4d | 8684 | |
c19d1205 | 8685 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 8686 | |
c19d1205 ZW |
8687 | static void |
8688 | do_strex (void) | |
8689 | { | |
8690 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
8691 | || inst.operands[2].postind || inst.operands[2].writeback | |
8692 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
8693 | || inst.operands[2].negative |
8694 | /* See comment in do_ldrex(). */ | |
8695 | || (inst.operands[2].reg == REG_PC), | |
8696 | BAD_ADDR_MODE); | |
a737bd4d | 8697 | |
c19d1205 ZW |
8698 | constraint (inst.operands[0].reg == inst.operands[1].reg |
8699 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 8700 | |
c19d1205 ZW |
8701 | constraint (inst.reloc.exp.X_op != O_constant |
8702 | || inst.reloc.exp.X_add_number != 0, | |
8703 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 8704 | |
c19d1205 ZW |
8705 | inst.instruction |= inst.operands[0].reg << 12; |
8706 | inst.instruction |= inst.operands[1].reg; | |
8707 | inst.instruction |= inst.operands[2].reg << 16; | |
8708 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
8709 | } |
8710 | ||
877807f8 NC |
8711 | static void |
8712 | do_t_strexbh (void) | |
8713 | { | |
8714 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
8715 | || inst.operands[2].postind || inst.operands[2].writeback | |
8716 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
8717 | || inst.operands[2].negative, | |
8718 | BAD_ADDR_MODE); | |
8719 | ||
8720 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
8721 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
8722 | ||
8723 | do_rm_rd_rn (); | |
8724 | } | |
8725 | ||
e16bb312 | 8726 | static void |
c19d1205 | 8727 | do_strexd (void) |
e16bb312 | 8728 | { |
c19d1205 ZW |
8729 | constraint (inst.operands[1].reg % 2 != 0, |
8730 | _("even register required")); | |
8731 | constraint (inst.operands[2].present | |
8732 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
8733 | _("can only store two consecutive registers")); | |
8734 | /* If op 2 were present and equal to PC, this function wouldn't | |
8735 | have been called in the first place. */ | |
8736 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 8737 | |
c19d1205 ZW |
8738 | constraint (inst.operands[0].reg == inst.operands[1].reg |
8739 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
8740 | || inst.operands[0].reg == inst.operands[3].reg, | |
8741 | BAD_OVERLAP); | |
e16bb312 | 8742 | |
c19d1205 ZW |
8743 | inst.instruction |= inst.operands[0].reg << 12; |
8744 | inst.instruction |= inst.operands[1].reg; | |
8745 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
8746 | } |
8747 | ||
9eb6c0f1 MGD |
8748 | /* ARM V8 STRL. */ |
8749 | static void | |
4b8c8c02 | 8750 | do_stlex (void) |
9eb6c0f1 MGD |
8751 | { |
8752 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
8753 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
8754 | ||
8755 | do_rd_rm_rn (); | |
8756 | } | |
8757 | ||
8758 | static void | |
4b8c8c02 | 8759 | do_t_stlex (void) |
9eb6c0f1 MGD |
8760 | { |
8761 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
8762 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
8763 | ||
8764 | do_rm_rd_rn (); | |
8765 | } | |
8766 | ||
c19d1205 ZW |
8767 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
8768 | extends it to 32-bits, and adds the result to a value in another | |
8769 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
8770 | before extracting the 16-bit value. | |
8771 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
8772 | Condition defaults to COND_ALWAYS. | |
8773 | Error if any register uses R15. */ | |
8774 | ||
e16bb312 | 8775 | static void |
c19d1205 | 8776 | do_sxtah (void) |
e16bb312 | 8777 | { |
c19d1205 ZW |
8778 | inst.instruction |= inst.operands[0].reg << 12; |
8779 | inst.instruction |= inst.operands[1].reg << 16; | |
8780 | inst.instruction |= inst.operands[2].reg; | |
8781 | inst.instruction |= inst.operands[3].imm << 10; | |
8782 | } | |
e16bb312 | 8783 | |
c19d1205 | 8784 | /* ARM V6 SXTH. |
e16bb312 | 8785 | |
c19d1205 ZW |
8786 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
8787 | Condition defaults to COND_ALWAYS. | |
8788 | Error if any register uses R15. */ | |
e16bb312 NC |
8789 | |
8790 | static void | |
c19d1205 | 8791 | do_sxth (void) |
e16bb312 | 8792 | { |
c19d1205 ZW |
8793 | inst.instruction |= inst.operands[0].reg << 12; |
8794 | inst.instruction |= inst.operands[1].reg; | |
8795 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 8796 | } |
c19d1205 ZW |
8797 | \f |
8798 | /* VFP instructions. In a logical order: SP variant first, monad | |
8799 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
8800 | |
8801 | static void | |
c19d1205 | 8802 | do_vfp_sp_monadic (void) |
e16bb312 | 8803 | { |
5287ad62 JB |
8804 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8805 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8806 | } |
8807 | ||
8808 | static void | |
c19d1205 | 8809 | do_vfp_sp_dyadic (void) |
e16bb312 | 8810 | { |
5287ad62 JB |
8811 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8812 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
8813 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
8814 | } |
8815 | ||
8816 | static void | |
c19d1205 | 8817 | do_vfp_sp_compare_z (void) |
e16bb312 | 8818 | { |
5287ad62 | 8819 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
8820 | } |
8821 | ||
8822 | static void | |
c19d1205 | 8823 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 8824 | { |
5287ad62 JB |
8825 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
8826 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8827 | } |
8828 | ||
8829 | static void | |
c19d1205 | 8830 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 8831 | { |
5287ad62 JB |
8832 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8833 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
8834 | } |
8835 | ||
8836 | static void | |
c19d1205 | 8837 | do_vfp_reg_from_sp (void) |
e16bb312 | 8838 | { |
c19d1205 | 8839 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 8840 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
8841 | } |
8842 | ||
8843 | static void | |
c19d1205 | 8844 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 8845 | { |
c19d1205 ZW |
8846 | constraint (inst.operands[2].imm != 2, |
8847 | _("only two consecutive VFP SP registers allowed here")); | |
8848 | inst.instruction |= inst.operands[0].reg << 12; | |
8849 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 8850 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
8851 | } |
8852 | ||
8853 | static void | |
c19d1205 | 8854 | do_vfp_sp_from_reg (void) |
e16bb312 | 8855 | { |
5287ad62 | 8856 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 8857 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
8858 | } |
8859 | ||
8860 | static void | |
c19d1205 | 8861 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 8862 | { |
c19d1205 ZW |
8863 | constraint (inst.operands[0].imm != 2, |
8864 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 8865 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
8866 | inst.instruction |= inst.operands[1].reg << 12; |
8867 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
8868 | } |
8869 | ||
8870 | static void | |
c19d1205 | 8871 | do_vfp_sp_ldst (void) |
e16bb312 | 8872 | { |
5287ad62 | 8873 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 8874 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8875 | } |
8876 | ||
8877 | static void | |
c19d1205 | 8878 | do_vfp_dp_ldst (void) |
e16bb312 | 8879 | { |
5287ad62 | 8880 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 8881 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8882 | } |
8883 | ||
c19d1205 | 8884 | |
e16bb312 | 8885 | static void |
c19d1205 | 8886 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8887 | { |
c19d1205 ZW |
8888 | if (inst.operands[0].writeback) |
8889 | inst.instruction |= WRITE_BACK; | |
8890 | else | |
8891 | constraint (ldstm_type != VFP_LDSTMIA, | |
8892 | _("this addressing mode requires base-register writeback")); | |
8893 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 8894 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 8895 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
8896 | } |
8897 | ||
8898 | static void | |
c19d1205 | 8899 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8900 | { |
c19d1205 | 8901 | int count; |
e16bb312 | 8902 | |
c19d1205 ZW |
8903 | if (inst.operands[0].writeback) |
8904 | inst.instruction |= WRITE_BACK; | |
8905 | else | |
8906 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
8907 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 8908 | |
c19d1205 | 8909 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 8910 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 8911 | |
c19d1205 ZW |
8912 | count = inst.operands[1].imm << 1; |
8913 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
8914 | count += 1; | |
e16bb312 | 8915 | |
c19d1205 | 8916 | inst.instruction |= count; |
e16bb312 NC |
8917 | } |
8918 | ||
8919 | static void | |
c19d1205 | 8920 | do_vfp_sp_ldstmia (void) |
e16bb312 | 8921 | { |
c19d1205 | 8922 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8923 | } |
8924 | ||
8925 | static void | |
c19d1205 | 8926 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 8927 | { |
c19d1205 | 8928 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8929 | } |
8930 | ||
8931 | static void | |
c19d1205 | 8932 | do_vfp_dp_ldstmia (void) |
e16bb312 | 8933 | { |
c19d1205 | 8934 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8935 | } |
8936 | ||
8937 | static void | |
c19d1205 | 8938 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 8939 | { |
c19d1205 | 8940 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8941 | } |
8942 | ||
8943 | static void | |
c19d1205 | 8944 | do_vfp_xp_ldstmia (void) |
e16bb312 | 8945 | { |
c19d1205 ZW |
8946 | vfp_dp_ldstm (VFP_LDSTMIAX); |
8947 | } | |
e16bb312 | 8948 | |
c19d1205 ZW |
8949 | static void |
8950 | do_vfp_xp_ldstmdb (void) | |
8951 | { | |
8952 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 8953 | } |
5287ad62 JB |
8954 | |
8955 | static void | |
8956 | do_vfp_dp_rd_rm (void) | |
8957 | { | |
8958 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8959 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
8960 | } | |
8961 | ||
8962 | static void | |
8963 | do_vfp_dp_rn_rd (void) | |
8964 | { | |
8965 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
8966 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8967 | } | |
8968 | ||
8969 | static void | |
8970 | do_vfp_dp_rd_rn (void) | |
8971 | { | |
8972 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8973 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8974 | } | |
8975 | ||
8976 | static void | |
8977 | do_vfp_dp_rd_rn_rm (void) | |
8978 | { | |
8979 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8980 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8981 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
8982 | } | |
8983 | ||
8984 | static void | |
8985 | do_vfp_dp_rd (void) | |
8986 | { | |
8987 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8988 | } | |
8989 | ||
8990 | static void | |
8991 | do_vfp_dp_rm_rd_rn (void) | |
8992 | { | |
8993 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
8994 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8995 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
8996 | } | |
8997 | ||
8998 | /* VFPv3 instructions. */ | |
8999 | static void | |
9000 | do_vfp_sp_const (void) | |
9001 | { | |
9002 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
9003 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9004 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9005 | } |
9006 | ||
9007 | static void | |
9008 | do_vfp_dp_const (void) | |
9009 | { | |
9010 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
9011 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9012 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9013 | } |
9014 | ||
9015 | static void | |
9016 | vfp_conv (int srcsize) | |
9017 | { | |
5f1af56b MGD |
9018 | int immbits = srcsize - inst.operands[1].imm; |
9019 | ||
fa94de6b RM |
9020 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
9021 | { | |
5f1af56b MGD |
9022 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
9023 | i.e. immbits must be in range 0 - 16. */ | |
9024 | inst.error = _("immediate value out of range, expected range [0, 16]"); | |
9025 | return; | |
9026 | } | |
fa94de6b | 9027 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
9028 | { |
9029 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
9030 | i.e. immbits must be in range 0 - 31. */ | |
9031 | inst.error = _("immediate value out of range, expected range [1, 32]"); | |
9032 | return; | |
9033 | } | |
9034 | ||
5287ad62 JB |
9035 | inst.instruction |= (immbits & 1) << 5; |
9036 | inst.instruction |= (immbits >> 1); | |
9037 | } | |
9038 | ||
9039 | static void | |
9040 | do_vfp_sp_conv_16 (void) | |
9041 | { | |
9042 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
9043 | vfp_conv (16); | |
9044 | } | |
9045 | ||
9046 | static void | |
9047 | do_vfp_dp_conv_16 (void) | |
9048 | { | |
9049 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9050 | vfp_conv (16); | |
9051 | } | |
9052 | ||
9053 | static void | |
9054 | do_vfp_sp_conv_32 (void) | |
9055 | { | |
9056 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
9057 | vfp_conv (32); | |
9058 | } | |
9059 | ||
9060 | static void | |
9061 | do_vfp_dp_conv_32 (void) | |
9062 | { | |
9063 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9064 | vfp_conv (32); | |
9065 | } | |
c19d1205 ZW |
9066 | \f |
9067 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 9068 | |
c19d1205 ZW |
9069 | static void |
9070 | do_fpa_cmp (void) | |
9071 | { | |
9072 | inst.instruction |= inst.operands[0].reg << 16; | |
9073 | inst.instruction |= inst.operands[1].reg; | |
9074 | } | |
b99bd4ef NC |
9075 | |
9076 | static void | |
c19d1205 | 9077 | do_fpa_ldmstm (void) |
b99bd4ef | 9078 | { |
c19d1205 ZW |
9079 | inst.instruction |= inst.operands[0].reg << 12; |
9080 | switch (inst.operands[1].imm) | |
9081 | { | |
9082 | case 1: inst.instruction |= CP_T_X; break; | |
9083 | case 2: inst.instruction |= CP_T_Y; break; | |
9084 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
9085 | case 4: break; | |
9086 | default: abort (); | |
9087 | } | |
b99bd4ef | 9088 | |
c19d1205 ZW |
9089 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
9090 | { | |
9091 | /* The instruction specified "ea" or "fd", so we can only accept | |
9092 | [Rn]{!}. The instruction does not really support stacking or | |
9093 | unstacking, so we have to emulate these by setting appropriate | |
9094 | bits and offsets. */ | |
9095 | constraint (inst.reloc.exp.X_op != O_constant | |
9096 | || inst.reloc.exp.X_add_number != 0, | |
9097 | _("this instruction does not support indexing")); | |
b99bd4ef | 9098 | |
c19d1205 ZW |
9099 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
9100 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 9101 | |
c19d1205 ZW |
9102 | if (!(inst.instruction & INDEX_UP)) |
9103 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 9104 | |
c19d1205 ZW |
9105 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
9106 | { | |
9107 | inst.operands[2].preind = 0; | |
9108 | inst.operands[2].postind = 1; | |
9109 | } | |
9110 | } | |
b99bd4ef | 9111 | |
c19d1205 | 9112 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 9113 | } |
c19d1205 ZW |
9114 | \f |
9115 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 9116 | |
c19d1205 ZW |
9117 | static void |
9118 | do_iwmmxt_tandorc (void) | |
9119 | { | |
9120 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
9121 | } | |
b99bd4ef | 9122 | |
c19d1205 ZW |
9123 | static void |
9124 | do_iwmmxt_textrc (void) | |
9125 | { | |
9126 | inst.instruction |= inst.operands[0].reg << 12; | |
9127 | inst.instruction |= inst.operands[1].imm; | |
9128 | } | |
b99bd4ef NC |
9129 | |
9130 | static void | |
c19d1205 | 9131 | do_iwmmxt_textrm (void) |
b99bd4ef | 9132 | { |
c19d1205 ZW |
9133 | inst.instruction |= inst.operands[0].reg << 12; |
9134 | inst.instruction |= inst.operands[1].reg << 16; | |
9135 | inst.instruction |= inst.operands[2].imm; | |
9136 | } | |
b99bd4ef | 9137 | |
c19d1205 ZW |
9138 | static void |
9139 | do_iwmmxt_tinsr (void) | |
9140 | { | |
9141 | inst.instruction |= inst.operands[0].reg << 16; | |
9142 | inst.instruction |= inst.operands[1].reg << 12; | |
9143 | inst.instruction |= inst.operands[2].imm; | |
9144 | } | |
b99bd4ef | 9145 | |
c19d1205 ZW |
9146 | static void |
9147 | do_iwmmxt_tmia (void) | |
9148 | { | |
9149 | inst.instruction |= inst.operands[0].reg << 5; | |
9150 | inst.instruction |= inst.operands[1].reg; | |
9151 | inst.instruction |= inst.operands[2].reg << 12; | |
9152 | } | |
b99bd4ef | 9153 | |
c19d1205 ZW |
9154 | static void |
9155 | do_iwmmxt_waligni (void) | |
9156 | { | |
9157 | inst.instruction |= inst.operands[0].reg << 12; | |
9158 | inst.instruction |= inst.operands[1].reg << 16; | |
9159 | inst.instruction |= inst.operands[2].reg; | |
9160 | inst.instruction |= inst.operands[3].imm << 20; | |
9161 | } | |
b99bd4ef | 9162 | |
2d447fca JM |
9163 | static void |
9164 | do_iwmmxt_wmerge (void) | |
9165 | { | |
9166 | inst.instruction |= inst.operands[0].reg << 12; | |
9167 | inst.instruction |= inst.operands[1].reg << 16; | |
9168 | inst.instruction |= inst.operands[2].reg; | |
9169 | inst.instruction |= inst.operands[3].imm << 21; | |
9170 | } | |
9171 | ||
c19d1205 ZW |
9172 | static void |
9173 | do_iwmmxt_wmov (void) | |
9174 | { | |
9175 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
9176 | inst.instruction |= inst.operands[0].reg << 12; | |
9177 | inst.instruction |= inst.operands[1].reg << 16; | |
9178 | inst.instruction |= inst.operands[1].reg; | |
9179 | } | |
b99bd4ef | 9180 | |
c19d1205 ZW |
9181 | static void |
9182 | do_iwmmxt_wldstbh (void) | |
9183 | { | |
8f06b2d8 | 9184 | int reloc; |
c19d1205 | 9185 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
9186 | if (thumb_mode) |
9187 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
9188 | else | |
9189 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
9190 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
9191 | } |
9192 | ||
c19d1205 ZW |
9193 | static void |
9194 | do_iwmmxt_wldstw (void) | |
9195 | { | |
9196 | /* RIWR_RIWC clears .isreg for a control register. */ | |
9197 | if (!inst.operands[0].isreg) | |
9198 | { | |
9199 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
9200 | inst.instruction |= 0xf0000000; | |
9201 | } | |
b99bd4ef | 9202 | |
c19d1205 ZW |
9203 | inst.instruction |= inst.operands[0].reg << 12; |
9204 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
9205 | } | |
b99bd4ef NC |
9206 | |
9207 | static void | |
c19d1205 | 9208 | do_iwmmxt_wldstd (void) |
b99bd4ef | 9209 | { |
c19d1205 | 9210 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
9211 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
9212 | && inst.operands[1].immisreg) | |
9213 | { | |
9214 | inst.instruction &= ~0x1a000ff; | |
9215 | inst.instruction |= (0xf << 28); | |
9216 | if (inst.operands[1].preind) | |
9217 | inst.instruction |= PRE_INDEX; | |
9218 | if (!inst.operands[1].negative) | |
9219 | inst.instruction |= INDEX_UP; | |
9220 | if (inst.operands[1].writeback) | |
9221 | inst.instruction |= WRITE_BACK; | |
9222 | inst.instruction |= inst.operands[1].reg << 16; | |
9223 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
9224 | inst.instruction |= inst.operands[1].imm; | |
9225 | } | |
9226 | else | |
9227 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 9228 | } |
b99bd4ef | 9229 | |
c19d1205 ZW |
9230 | static void |
9231 | do_iwmmxt_wshufh (void) | |
9232 | { | |
9233 | inst.instruction |= inst.operands[0].reg << 12; | |
9234 | inst.instruction |= inst.operands[1].reg << 16; | |
9235 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
9236 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
9237 | } | |
b99bd4ef | 9238 | |
c19d1205 ZW |
9239 | static void |
9240 | do_iwmmxt_wzero (void) | |
9241 | { | |
9242 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
9243 | inst.instruction |= inst.operands[0].reg; | |
9244 | inst.instruction |= inst.operands[0].reg << 12; | |
9245 | inst.instruction |= inst.operands[0].reg << 16; | |
9246 | } | |
2d447fca JM |
9247 | |
9248 | static void | |
9249 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
9250 | { | |
9251 | if (inst.operands[2].isreg) | |
9252 | do_rd_rn_rm (); | |
9253 | else { | |
9254 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
9255 | _("immediate operand requires iWMMXt2")); | |
9256 | do_rd_rn (); | |
9257 | if (inst.operands[2].imm == 0) | |
9258 | { | |
9259 | switch ((inst.instruction >> 20) & 0xf) | |
9260 | { | |
9261 | case 4: | |
9262 | case 5: | |
9263 | case 6: | |
5f4273c7 | 9264 | case 7: |
2d447fca JM |
9265 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
9266 | inst.operands[2].imm = 16; | |
9267 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
9268 | break; | |
9269 | case 8: | |
9270 | case 9: | |
9271 | case 10: | |
9272 | case 11: | |
9273 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
9274 | inst.operands[2].imm = 32; | |
9275 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
9276 | break; | |
9277 | case 12: | |
9278 | case 13: | |
9279 | case 14: | |
9280 | case 15: | |
9281 | { | |
9282 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
9283 | unsigned long wrn; | |
9284 | wrn = (inst.instruction >> 16) & 0xf; | |
9285 | inst.instruction &= 0xff0fff0f; | |
9286 | inst.instruction |= wrn; | |
9287 | /* Bail out here; the instruction is now assembled. */ | |
9288 | return; | |
9289 | } | |
9290 | } | |
9291 | } | |
9292 | /* Map 32 -> 0, etc. */ | |
9293 | inst.operands[2].imm &= 0x1f; | |
9294 | inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); | |
9295 | } | |
9296 | } | |
c19d1205 ZW |
9297 | \f |
9298 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
9299 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 9300 | |
c19d1205 | 9301 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 9302 | |
c19d1205 ZW |
9303 | static void |
9304 | do_mav_triple (void) | |
9305 | { | |
9306 | inst.instruction |= inst.operands[0].reg << 16; | |
9307 | inst.instruction |= inst.operands[1].reg; | |
9308 | inst.instruction |= inst.operands[2].reg << 12; | |
9309 | } | |
b99bd4ef | 9310 | |
c19d1205 ZW |
9311 | /* Insns like "foo W,X,Y,Z". |
9312 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 9313 | |
c19d1205 ZW |
9314 | static void |
9315 | do_mav_quad (void) | |
9316 | { | |
9317 | inst.instruction |= inst.operands[0].reg << 5; | |
9318 | inst.instruction |= inst.operands[1].reg << 12; | |
9319 | inst.instruction |= inst.operands[2].reg << 16; | |
9320 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
9321 | } |
9322 | ||
c19d1205 ZW |
9323 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
9324 | static void | |
9325 | do_mav_dspsc (void) | |
a737bd4d | 9326 | { |
c19d1205 ZW |
9327 | inst.instruction |= inst.operands[1].reg << 12; |
9328 | } | |
a737bd4d | 9329 | |
c19d1205 ZW |
9330 | /* Maverick shift immediate instructions. |
9331 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
9332 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 9333 | |
c19d1205 ZW |
9334 | static void |
9335 | do_mav_shift (void) | |
9336 | { | |
9337 | int imm = inst.operands[2].imm; | |
a737bd4d | 9338 | |
c19d1205 ZW |
9339 | inst.instruction |= inst.operands[0].reg << 12; |
9340 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 9341 | |
c19d1205 ZW |
9342 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
9343 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
9344 | Bit 4 should be 0. */ | |
9345 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 9346 | |
c19d1205 ZW |
9347 | inst.instruction |= imm; |
9348 | } | |
9349 | \f | |
9350 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 9351 | |
c19d1205 ZW |
9352 | /* Xscale multiply-accumulate (argument parse) |
9353 | MIAcc acc0,Rm,Rs | |
9354 | MIAPHcc acc0,Rm,Rs | |
9355 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 9356 | |
c19d1205 ZW |
9357 | static void |
9358 | do_xsc_mia (void) | |
9359 | { | |
9360 | inst.instruction |= inst.operands[1].reg; | |
9361 | inst.instruction |= inst.operands[2].reg << 12; | |
9362 | } | |
a737bd4d | 9363 | |
c19d1205 | 9364 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 9365 | |
c19d1205 | 9366 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 9367 | |
c19d1205 ZW |
9368 | static void |
9369 | do_xsc_mar (void) | |
9370 | { | |
9371 | inst.instruction |= inst.operands[1].reg << 12; | |
9372 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9373 | } |
9374 | ||
c19d1205 | 9375 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 9376 | |
c19d1205 | 9377 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
9378 | |
9379 | static void | |
c19d1205 | 9380 | do_xsc_mra (void) |
b99bd4ef | 9381 | { |
c19d1205 ZW |
9382 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
9383 | inst.instruction |= inst.operands[0].reg << 12; | |
9384 | inst.instruction |= inst.operands[1].reg << 16; | |
9385 | } | |
9386 | \f | |
9387 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 9388 | |
c19d1205 ZW |
9389 | /* inst.operands[i] is a shifted-register operand; encode |
9390 | it into inst.instruction in the format used by Thumb32. */ | |
9391 | ||
9392 | static void | |
9393 | encode_thumb32_shifted_operand (int i) | |
9394 | { | |
9395 | unsigned int value = inst.reloc.exp.X_add_number; | |
9396 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 9397 | |
9c3c69f2 PB |
9398 | constraint (inst.operands[i].immisreg, |
9399 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
9400 | inst.instruction |= inst.operands[i].reg; |
9401 | if (shift == SHIFT_RRX) | |
9402 | inst.instruction |= SHIFT_ROR << 4; | |
9403 | else | |
b99bd4ef | 9404 | { |
c19d1205 ZW |
9405 | constraint (inst.reloc.exp.X_op != O_constant, |
9406 | _("expression too complex")); | |
9407 | ||
9408 | constraint (value > 32 | |
9409 | || (value == 32 && (shift == SHIFT_LSL | |
9410 | || shift == SHIFT_ROR)), | |
9411 | _("shift expression is too large")); | |
9412 | ||
9413 | if (value == 0) | |
9414 | shift = SHIFT_LSL; | |
9415 | else if (value == 32) | |
9416 | value = 0; | |
9417 | ||
9418 | inst.instruction |= shift << 4; | |
9419 | inst.instruction |= (value & 0x1c) << 10; | |
9420 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 9421 | } |
c19d1205 | 9422 | } |
b99bd4ef | 9423 | |
b99bd4ef | 9424 | |
c19d1205 ZW |
9425 | /* inst.operands[i] was set up by parse_address. Encode it into a |
9426 | Thumb32 format load or store instruction. Reject forms that cannot | |
9427 | be used with such instructions. If is_t is true, reject forms that | |
9428 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
9429 | that cannot be used with a D instruction. If it is a store insn, |
9430 | reject PC in Rn. */ | |
b99bd4ef | 9431 | |
c19d1205 ZW |
9432 | static void |
9433 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
9434 | { | |
5be8be5d | 9435 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
9436 | |
9437 | constraint (!inst.operands[i].isreg, | |
53365c0d | 9438 | _("Instruction does not support =N addresses")); |
b99bd4ef | 9439 | |
c19d1205 ZW |
9440 | inst.instruction |= inst.operands[i].reg << 16; |
9441 | if (inst.operands[i].immisreg) | |
b99bd4ef | 9442 | { |
5be8be5d | 9443 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
9444 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
9445 | constraint (inst.operands[i].negative, | |
9446 | _("Thumb does not support negative register indexing")); | |
9447 | constraint (inst.operands[i].postind, | |
9448 | _("Thumb does not support register post-indexing")); | |
9449 | constraint (inst.operands[i].writeback, | |
9450 | _("Thumb does not support register indexing with writeback")); | |
9451 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
9452 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 9453 | |
f40d1643 | 9454 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 9455 | if (inst.operands[i].shifted) |
b99bd4ef | 9456 | { |
c19d1205 ZW |
9457 | constraint (inst.reloc.exp.X_op != O_constant, |
9458 | _("expression too complex")); | |
9c3c69f2 PB |
9459 | constraint (inst.reloc.exp.X_add_number < 0 |
9460 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 9461 | _("shift out of range")); |
9c3c69f2 | 9462 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
9463 | } |
9464 | inst.reloc.type = BFD_RELOC_UNUSED; | |
9465 | } | |
9466 | else if (inst.operands[i].preind) | |
9467 | { | |
5be8be5d | 9468 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 9469 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 9470 | _("cannot use writeback with this instruction")); |
5be8be5d DG |
9471 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0) |
9472 | && !inst.reloc.pc_rel, BAD_PC_ADDRESSING); | |
c19d1205 ZW |
9473 | |
9474 | if (is_d) | |
9475 | { | |
9476 | inst.instruction |= 0x01000000; | |
9477 | if (inst.operands[i].writeback) | |
9478 | inst.instruction |= 0x00200000; | |
b99bd4ef | 9479 | } |
c19d1205 | 9480 | else |
b99bd4ef | 9481 | { |
c19d1205 ZW |
9482 | inst.instruction |= 0x00000c00; |
9483 | if (inst.operands[i].writeback) | |
9484 | inst.instruction |= 0x00000100; | |
b99bd4ef | 9485 | } |
c19d1205 | 9486 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 9487 | } |
c19d1205 | 9488 | else if (inst.operands[i].postind) |
b99bd4ef | 9489 | { |
9c2799c2 | 9490 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
9491 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
9492 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
9493 | ||
9494 | if (is_d) | |
9495 | inst.instruction |= 0x00200000; | |
9496 | else | |
9497 | inst.instruction |= 0x00000900; | |
9498 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
9499 | } | |
9500 | else /* unindexed - only for coprocessor */ | |
9501 | inst.error = _("instruction does not accept unindexed addressing"); | |
9502 | } | |
9503 | ||
9504 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
9505 | encodings (the latter only in post-V6T2 cores). The index is the | |
9506 | value used in the insns table below. When there is more than one | |
9507 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
9508 | holds variant (1). |
9509 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 9510 | #define T16_32_TAB \ |
21d799b5 NC |
9511 | X(_adc, 4140, eb400000), \ |
9512 | X(_adcs, 4140, eb500000), \ | |
9513 | X(_add, 1c00, eb000000), \ | |
9514 | X(_adds, 1c00, eb100000), \ | |
9515 | X(_addi, 0000, f1000000), \ | |
9516 | X(_addis, 0000, f1100000), \ | |
9517 | X(_add_pc,000f, f20f0000), \ | |
9518 | X(_add_sp,000d, f10d0000), \ | |
9519 | X(_adr, 000f, f20f0000), \ | |
9520 | X(_and, 4000, ea000000), \ | |
9521 | X(_ands, 4000, ea100000), \ | |
9522 | X(_asr, 1000, fa40f000), \ | |
9523 | X(_asrs, 1000, fa50f000), \ | |
9524 | X(_b, e000, f000b000), \ | |
9525 | X(_bcond, d000, f0008000), \ | |
9526 | X(_bic, 4380, ea200000), \ | |
9527 | X(_bics, 4380, ea300000), \ | |
9528 | X(_cmn, 42c0, eb100f00), \ | |
9529 | X(_cmp, 2800, ebb00f00), \ | |
9530 | X(_cpsie, b660, f3af8400), \ | |
9531 | X(_cpsid, b670, f3af8600), \ | |
9532 | X(_cpy, 4600, ea4f0000), \ | |
9533 | X(_dec_sp,80dd, f1ad0d00), \ | |
9534 | X(_eor, 4040, ea800000), \ | |
9535 | X(_eors, 4040, ea900000), \ | |
9536 | X(_inc_sp,00dd, f10d0d00), \ | |
9537 | X(_ldmia, c800, e8900000), \ | |
9538 | X(_ldr, 6800, f8500000), \ | |
9539 | X(_ldrb, 7800, f8100000), \ | |
9540 | X(_ldrh, 8800, f8300000), \ | |
9541 | X(_ldrsb, 5600, f9100000), \ | |
9542 | X(_ldrsh, 5e00, f9300000), \ | |
9543 | X(_ldr_pc,4800, f85f0000), \ | |
9544 | X(_ldr_pc2,4800, f85f0000), \ | |
9545 | X(_ldr_sp,9800, f85d0000), \ | |
9546 | X(_lsl, 0000, fa00f000), \ | |
9547 | X(_lsls, 0000, fa10f000), \ | |
9548 | X(_lsr, 0800, fa20f000), \ | |
9549 | X(_lsrs, 0800, fa30f000), \ | |
9550 | X(_mov, 2000, ea4f0000), \ | |
9551 | X(_movs, 2000, ea5f0000), \ | |
9552 | X(_mul, 4340, fb00f000), \ | |
9553 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
9554 | X(_mvn, 43c0, ea6f0000), \ | |
9555 | X(_mvns, 43c0, ea7f0000), \ | |
9556 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
9557 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
9558 | X(_orr, 4300, ea400000), \ | |
9559 | X(_orrs, 4300, ea500000), \ | |
9560 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
9561 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
9562 | X(_rev, ba00, fa90f080), \ | |
9563 | X(_rev16, ba40, fa90f090), \ | |
9564 | X(_revsh, bac0, fa90f0b0), \ | |
9565 | X(_ror, 41c0, fa60f000), \ | |
9566 | X(_rors, 41c0, fa70f000), \ | |
9567 | X(_sbc, 4180, eb600000), \ | |
9568 | X(_sbcs, 4180, eb700000), \ | |
9569 | X(_stmia, c000, e8800000), \ | |
9570 | X(_str, 6000, f8400000), \ | |
9571 | X(_strb, 7000, f8000000), \ | |
9572 | X(_strh, 8000, f8200000), \ | |
9573 | X(_str_sp,9000, f84d0000), \ | |
9574 | X(_sub, 1e00, eba00000), \ | |
9575 | X(_subs, 1e00, ebb00000), \ | |
9576 | X(_subi, 8000, f1a00000), \ | |
9577 | X(_subis, 8000, f1b00000), \ | |
9578 | X(_sxtb, b240, fa4ff080), \ | |
9579 | X(_sxth, b200, fa0ff080), \ | |
9580 | X(_tst, 4200, ea100f00), \ | |
9581 | X(_uxtb, b2c0, fa5ff080), \ | |
9582 | X(_uxth, b280, fa1ff080), \ | |
9583 | X(_nop, bf00, f3af8000), \ | |
9584 | X(_yield, bf10, f3af8001), \ | |
9585 | X(_wfe, bf20, f3af8002), \ | |
9586 | X(_wfi, bf30, f3af8003), \ | |
53c4b28b MGD |
9587 | X(_sev, bf40, f3af8004), \ |
9588 | X(_sevl, bf50, f3af8005) | |
c19d1205 ZW |
9589 | |
9590 | /* To catch errors in encoding functions, the codes are all offset by | |
9591 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
9592 | as 16-bit instructions. */ | |
21d799b5 | 9593 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
9594 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
9595 | #undef X | |
9596 | ||
9597 | #define X(a,b,c) 0x##b | |
9598 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
9599 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
9600 | #undef X | |
9601 | ||
9602 | #define X(a,b,c) 0x##c | |
9603 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
9604 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
9605 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
9606 | #undef X |
9607 | #undef T16_32_TAB | |
9608 | ||
9609 | /* Thumb instruction encoders, in alphabetical order. */ | |
9610 | ||
92e90b6e | 9611 | /* ADDW or SUBW. */ |
c921be7d | 9612 | |
92e90b6e PB |
9613 | static void |
9614 | do_t_add_sub_w (void) | |
9615 | { | |
9616 | int Rd, Rn; | |
9617 | ||
9618 | Rd = inst.operands[0].reg; | |
9619 | Rn = inst.operands[1].reg; | |
9620 | ||
539d4391 NC |
9621 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
9622 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
9623 | if (Rn == REG_SP) | |
9624 | constraint (Rd == REG_PC, BAD_PC); | |
9625 | else | |
9626 | reject_bad_reg (Rd); | |
fdfde340 | 9627 | |
92e90b6e PB |
9628 | inst.instruction |= (Rn << 16) | (Rd << 8); |
9629 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
9630 | } | |
9631 | ||
c19d1205 ZW |
9632 | /* Parse an add or subtract instruction. We get here with inst.instruction |
9633 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
9634 | ||
9635 | static void | |
9636 | do_t_add_sub (void) | |
9637 | { | |
9638 | int Rd, Rs, Rn; | |
9639 | ||
9640 | Rd = inst.operands[0].reg; | |
9641 | Rs = (inst.operands[1].present | |
9642 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9643 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9644 | ||
e07e6e58 NC |
9645 | if (Rd == REG_PC) |
9646 | set_it_insn_type_last (); | |
9647 | ||
c19d1205 ZW |
9648 | if (unified_syntax) |
9649 | { | |
0110f2b8 PB |
9650 | bfd_boolean flags; |
9651 | bfd_boolean narrow; | |
9652 | int opcode; | |
9653 | ||
9654 | flags = (inst.instruction == T_MNEM_adds | |
9655 | || inst.instruction == T_MNEM_subs); | |
9656 | if (flags) | |
e07e6e58 | 9657 | narrow = !in_it_block (); |
0110f2b8 | 9658 | else |
e07e6e58 | 9659 | narrow = in_it_block (); |
c19d1205 | 9660 | if (!inst.operands[2].isreg) |
b99bd4ef | 9661 | { |
16805f35 PB |
9662 | int add; |
9663 | ||
fdfde340 JM |
9664 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
9665 | ||
16805f35 PB |
9666 | add = (inst.instruction == T_MNEM_add |
9667 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
9668 | opcode = 0; |
9669 | if (inst.size_req != 4) | |
9670 | { | |
0110f2b8 PB |
9671 | /* Attempt to use a narrow opcode, with relaxation if |
9672 | appropriate. */ | |
9673 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
9674 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
9675 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
9676 | opcode = T_MNEM_add_sp; | |
9677 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
9678 | opcode = T_MNEM_add_pc; | |
9679 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
9680 | { | |
9681 | if (flags) | |
9682 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
9683 | else | |
9684 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
9685 | } | |
9686 | if (opcode) | |
9687 | { | |
9688 | inst.instruction = THUMB_OP16(opcode); | |
9689 | inst.instruction |= (Rd << 4) | Rs; | |
9690 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
9691 | if (inst.size_req != 2) | |
9692 | inst.relax = opcode; | |
9693 | } | |
9694 | else | |
9695 | constraint (inst.size_req == 2, BAD_HIREG); | |
9696 | } | |
9697 | if (inst.size_req == 4 | |
9698 | || (inst.size_req != 2 && !opcode)) | |
9699 | { | |
efd81785 PB |
9700 | if (Rd == REG_PC) |
9701 | { | |
fdfde340 | 9702 | constraint (add, BAD_PC); |
efd81785 PB |
9703 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
9704 | _("only SUBS PC, LR, #const allowed")); | |
9705 | constraint (inst.reloc.exp.X_op != O_constant, | |
9706 | _("expression too complex")); | |
9707 | constraint (inst.reloc.exp.X_add_number < 0 | |
9708 | || inst.reloc.exp.X_add_number > 0xff, | |
9709 | _("immediate value out of range")); | |
9710 | inst.instruction = T2_SUBS_PC_LR | |
9711 | | inst.reloc.exp.X_add_number; | |
9712 | inst.reloc.type = BFD_RELOC_UNUSED; | |
9713 | return; | |
9714 | } | |
9715 | else if (Rs == REG_PC) | |
16805f35 PB |
9716 | { |
9717 | /* Always use addw/subw. */ | |
9718 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
9719 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
9720 | } | |
9721 | else | |
9722 | { | |
9723 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9724 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
9725 | | 0x10000000; | |
9726 | if (flags) | |
9727 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9728 | else | |
9729 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
9730 | } | |
dc4503c6 PB |
9731 | inst.instruction |= Rd << 8; |
9732 | inst.instruction |= Rs << 16; | |
0110f2b8 | 9733 | } |
b99bd4ef | 9734 | } |
c19d1205 ZW |
9735 | else |
9736 | { | |
5f4cb198 NC |
9737 | unsigned int value = inst.reloc.exp.X_add_number; |
9738 | unsigned int shift = inst.operands[2].shift_kind; | |
9739 | ||
c19d1205 ZW |
9740 | Rn = inst.operands[2].reg; |
9741 | /* See if we can do this with a 16-bit instruction. */ | |
9742 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
9743 | { | |
e27ec89e PB |
9744 | if (Rd > 7 || Rs > 7 || Rn > 7) |
9745 | narrow = FALSE; | |
9746 | ||
9747 | if (narrow) | |
c19d1205 | 9748 | { |
e27ec89e PB |
9749 | inst.instruction = ((inst.instruction == T_MNEM_adds |
9750 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
9751 | ? T_OPCODE_ADD_R3 |
9752 | : T_OPCODE_SUB_R3); | |
9753 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
9754 | return; | |
9755 | } | |
b99bd4ef | 9756 | |
7e806470 | 9757 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 9758 | { |
7e806470 PB |
9759 | /* Thumb-1 cores (except v6-M) require at least one high |
9760 | register in a narrow non flag setting add. */ | |
9761 | if (Rd > 7 || Rn > 7 | |
9762 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
9763 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 9764 | { |
7e806470 PB |
9765 | if (Rd == Rn) |
9766 | { | |
9767 | Rn = Rs; | |
9768 | Rs = Rd; | |
9769 | } | |
c19d1205 ZW |
9770 | inst.instruction = T_OPCODE_ADD_HI; |
9771 | inst.instruction |= (Rd & 8) << 4; | |
9772 | inst.instruction |= (Rd & 7); | |
9773 | inst.instruction |= Rn << 3; | |
9774 | return; | |
9775 | } | |
c19d1205 ZW |
9776 | } |
9777 | } | |
c921be7d | 9778 | |
fdfde340 JM |
9779 | constraint (Rd == REG_PC, BAD_PC); |
9780 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
9781 | constraint (Rs == REG_PC, BAD_PC); | |
9782 | reject_bad_reg (Rn); | |
9783 | ||
c19d1205 ZW |
9784 | /* If we get here, it can't be done in 16 bits. */ |
9785 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
9786 | _("shift must be constant")); | |
9787 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9788 | inst.instruction |= Rd << 8; | |
9789 | inst.instruction |= Rs << 16; | |
5f4cb198 NC |
9790 | constraint (Rd == REG_SP && Rs == REG_SP && value > 3, |
9791 | _("shift value over 3 not allowed in thumb mode")); | |
9792 | constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL, | |
9793 | _("only LSL shift allowed in thumb mode")); | |
c19d1205 ZW |
9794 | encode_thumb32_shifted_operand (2); |
9795 | } | |
9796 | } | |
9797 | else | |
9798 | { | |
9799 | constraint (inst.instruction == T_MNEM_adds | |
9800 | || inst.instruction == T_MNEM_subs, | |
9801 | BAD_THUMB32); | |
b99bd4ef | 9802 | |
c19d1205 | 9803 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 9804 | { |
c19d1205 ZW |
9805 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
9806 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
9807 | BAD_HIREG); | |
9808 | ||
9809 | inst.instruction = (inst.instruction == T_MNEM_add | |
9810 | ? 0x0000 : 0x8000); | |
9811 | inst.instruction |= (Rd << 4) | Rs; | |
9812 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
9813 | return; |
9814 | } | |
9815 | ||
c19d1205 ZW |
9816 | Rn = inst.operands[2].reg; |
9817 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 9818 | |
c19d1205 ZW |
9819 | /* We now have Rd, Rs, and Rn set to registers. */ |
9820 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 9821 | { |
c19d1205 ZW |
9822 | /* Can't do this for SUB. */ |
9823 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
9824 | inst.instruction = T_OPCODE_ADD_HI; | |
9825 | inst.instruction |= (Rd & 8) << 4; | |
9826 | inst.instruction |= (Rd & 7); | |
9827 | if (Rs == Rd) | |
9828 | inst.instruction |= Rn << 3; | |
9829 | else if (Rn == Rd) | |
9830 | inst.instruction |= Rs << 3; | |
9831 | else | |
9832 | constraint (1, _("dest must overlap one source register")); | |
9833 | } | |
9834 | else | |
9835 | { | |
9836 | inst.instruction = (inst.instruction == T_MNEM_add | |
9837 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
9838 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 9839 | } |
b99bd4ef | 9840 | } |
b99bd4ef NC |
9841 | } |
9842 | ||
c19d1205 ZW |
9843 | static void |
9844 | do_t_adr (void) | |
9845 | { | |
fdfde340 JM |
9846 | unsigned Rd; |
9847 | ||
9848 | Rd = inst.operands[0].reg; | |
9849 | reject_bad_reg (Rd); | |
9850 | ||
9851 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
9852 | { |
9853 | /* Defer to section relaxation. */ | |
9854 | inst.relax = inst.instruction; | |
9855 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 9856 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
9857 | } |
9858 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 9859 | { |
0110f2b8 | 9860 | /* Generate a 32-bit opcode. */ |
e9f89963 | 9861 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 9862 | inst.instruction |= Rd << 8; |
e9f89963 PB |
9863 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
9864 | inst.reloc.pc_rel = 1; | |
9865 | } | |
9866 | else | |
9867 | { | |
0110f2b8 | 9868 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
9869 | inst.instruction = THUMB_OP16 (inst.instruction); |
9870 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
9871 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
9872 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 9873 | |
fdfde340 | 9874 | inst.instruction |= Rd << 4; |
e9f89963 | 9875 | } |
c19d1205 | 9876 | } |
b99bd4ef | 9877 | |
c19d1205 ZW |
9878 | /* Arithmetic instructions for which there is just one 16-bit |
9879 | instruction encoding, and it allows only two low registers. | |
9880 | For maximal compatibility with ARM syntax, we allow three register | |
9881 | operands even when Thumb-32 instructions are not available, as long | |
9882 | as the first two are identical. For instance, both "sbc r0,r1" and | |
9883 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 9884 | static void |
c19d1205 | 9885 | do_t_arit3 (void) |
b99bd4ef | 9886 | { |
c19d1205 | 9887 | int Rd, Rs, Rn; |
b99bd4ef | 9888 | |
c19d1205 ZW |
9889 | Rd = inst.operands[0].reg; |
9890 | Rs = (inst.operands[1].present | |
9891 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9892 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9893 | Rn = inst.operands[2].reg; | |
b99bd4ef | 9894 | |
fdfde340 JM |
9895 | reject_bad_reg (Rd); |
9896 | reject_bad_reg (Rs); | |
9897 | if (inst.operands[2].isreg) | |
9898 | reject_bad_reg (Rn); | |
9899 | ||
c19d1205 | 9900 | if (unified_syntax) |
b99bd4ef | 9901 | { |
c19d1205 ZW |
9902 | if (!inst.operands[2].isreg) |
9903 | { | |
9904 | /* For an immediate, we always generate a 32-bit opcode; | |
9905 | section relaxation will shrink it later if possible. */ | |
9906 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9907 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9908 | inst.instruction |= Rd << 8; | |
9909 | inst.instruction |= Rs << 16; | |
9910 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9911 | } | |
9912 | else | |
9913 | { | |
e27ec89e PB |
9914 | bfd_boolean narrow; |
9915 | ||
c19d1205 | 9916 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9917 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9918 | narrow = !in_it_block (); |
e27ec89e | 9919 | else |
e07e6e58 | 9920 | narrow = in_it_block (); |
e27ec89e PB |
9921 | |
9922 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9923 | narrow = FALSE; | |
9924 | if (inst.operands[2].shifted) | |
9925 | narrow = FALSE; | |
9926 | if (inst.size_req == 4) | |
9927 | narrow = FALSE; | |
9928 | ||
9929 | if (narrow | |
c19d1205 ZW |
9930 | && Rd == Rs) |
9931 | { | |
9932 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9933 | inst.instruction |= Rd; | |
9934 | inst.instruction |= Rn << 3; | |
9935 | return; | |
9936 | } | |
b99bd4ef | 9937 | |
c19d1205 ZW |
9938 | /* If we get here, it can't be done in 16 bits. */ |
9939 | constraint (inst.operands[2].shifted | |
9940 | && inst.operands[2].immisreg, | |
9941 | _("shift must be constant")); | |
9942 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9943 | inst.instruction |= Rd << 8; | |
9944 | inst.instruction |= Rs << 16; | |
9945 | encode_thumb32_shifted_operand (2); | |
9946 | } | |
a737bd4d | 9947 | } |
c19d1205 | 9948 | else |
b99bd4ef | 9949 | { |
c19d1205 ZW |
9950 | /* On its face this is a lie - the instruction does set the |
9951 | flags. However, the only supported mnemonic in this mode | |
9952 | says it doesn't. */ | |
9953 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9954 | |
c19d1205 ZW |
9955 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9956 | _("unshifted register required")); | |
9957 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9958 | constraint (Rd != Rs, | |
9959 | _("dest and source1 must be the same register")); | |
a737bd4d | 9960 | |
c19d1205 ZW |
9961 | inst.instruction = THUMB_OP16 (inst.instruction); |
9962 | inst.instruction |= Rd; | |
9963 | inst.instruction |= Rn << 3; | |
b99bd4ef | 9964 | } |
a737bd4d | 9965 | } |
b99bd4ef | 9966 | |
c19d1205 ZW |
9967 | /* Similarly, but for instructions where the arithmetic operation is |
9968 | commutative, so we can allow either of them to be different from | |
9969 | the destination operand in a 16-bit instruction. For instance, all | |
9970 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
9971 | accepted. */ | |
9972 | static void | |
9973 | do_t_arit3c (void) | |
a737bd4d | 9974 | { |
c19d1205 | 9975 | int Rd, Rs, Rn; |
b99bd4ef | 9976 | |
c19d1205 ZW |
9977 | Rd = inst.operands[0].reg; |
9978 | Rs = (inst.operands[1].present | |
9979 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9980 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9981 | Rn = inst.operands[2].reg; | |
c921be7d | 9982 | |
fdfde340 JM |
9983 | reject_bad_reg (Rd); |
9984 | reject_bad_reg (Rs); | |
9985 | if (inst.operands[2].isreg) | |
9986 | reject_bad_reg (Rn); | |
a737bd4d | 9987 | |
c19d1205 | 9988 | if (unified_syntax) |
a737bd4d | 9989 | { |
c19d1205 | 9990 | if (!inst.operands[2].isreg) |
b99bd4ef | 9991 | { |
c19d1205 ZW |
9992 | /* For an immediate, we always generate a 32-bit opcode; |
9993 | section relaxation will shrink it later if possible. */ | |
9994 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9995 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9996 | inst.instruction |= Rd << 8; | |
9997 | inst.instruction |= Rs << 16; | |
9998 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 9999 | } |
c19d1205 | 10000 | else |
a737bd4d | 10001 | { |
e27ec89e PB |
10002 | bfd_boolean narrow; |
10003 | ||
c19d1205 | 10004 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 10005 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 10006 | narrow = !in_it_block (); |
e27ec89e | 10007 | else |
e07e6e58 | 10008 | narrow = in_it_block (); |
e27ec89e PB |
10009 | |
10010 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
10011 | narrow = FALSE; | |
10012 | if (inst.operands[2].shifted) | |
10013 | narrow = FALSE; | |
10014 | if (inst.size_req == 4) | |
10015 | narrow = FALSE; | |
10016 | ||
10017 | if (narrow) | |
a737bd4d | 10018 | { |
c19d1205 | 10019 | if (Rd == Rs) |
a737bd4d | 10020 | { |
c19d1205 ZW |
10021 | inst.instruction = THUMB_OP16 (inst.instruction); |
10022 | inst.instruction |= Rd; | |
10023 | inst.instruction |= Rn << 3; | |
10024 | return; | |
a737bd4d | 10025 | } |
c19d1205 | 10026 | if (Rd == Rn) |
a737bd4d | 10027 | { |
c19d1205 ZW |
10028 | inst.instruction = THUMB_OP16 (inst.instruction); |
10029 | inst.instruction |= Rd; | |
10030 | inst.instruction |= Rs << 3; | |
10031 | return; | |
a737bd4d NC |
10032 | } |
10033 | } | |
c19d1205 ZW |
10034 | |
10035 | /* If we get here, it can't be done in 16 bits. */ | |
10036 | constraint (inst.operands[2].shifted | |
10037 | && inst.operands[2].immisreg, | |
10038 | _("shift must be constant")); | |
10039 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10040 | inst.instruction |= Rd << 8; | |
10041 | inst.instruction |= Rs << 16; | |
10042 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 10043 | } |
b99bd4ef | 10044 | } |
c19d1205 ZW |
10045 | else |
10046 | { | |
10047 | /* On its face this is a lie - the instruction does set the | |
10048 | flags. However, the only supported mnemonic in this mode | |
10049 | says it doesn't. */ | |
10050 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 10051 | |
c19d1205 ZW |
10052 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
10053 | _("unshifted register required")); | |
10054 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
10055 | ||
10056 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10057 | inst.instruction |= Rd; | |
10058 | ||
10059 | if (Rd == Rs) | |
10060 | inst.instruction |= Rn << 3; | |
10061 | else if (Rd == Rn) | |
10062 | inst.instruction |= Rs << 3; | |
10063 | else | |
10064 | constraint (1, _("dest must overlap one source register")); | |
10065 | } | |
a737bd4d NC |
10066 | } |
10067 | ||
62b3e311 PB |
10068 | static void |
10069 | do_t_barrier (void) | |
10070 | { | |
10071 | if (inst.operands[0].present) | |
10072 | { | |
10073 | constraint ((inst.instruction & 0xf0) != 0x40 | |
52e7f43d RE |
10074 | && inst.operands[0].imm > 0xf |
10075 | && inst.operands[0].imm < 0x0, | |
bd3ba5d1 | 10076 | _("bad barrier type")); |
62b3e311 PB |
10077 | inst.instruction |= inst.operands[0].imm; |
10078 | } | |
10079 | else | |
10080 | inst.instruction |= 0xf; | |
10081 | } | |
10082 | ||
c19d1205 ZW |
10083 | static void |
10084 | do_t_bfc (void) | |
a737bd4d | 10085 | { |
fdfde340 | 10086 | unsigned Rd; |
c19d1205 ZW |
10087 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
10088 | constraint (msb > 32, _("bit-field extends past end of register")); | |
10089 | /* The instruction encoding stores the LSB and MSB, | |
10090 | not the LSB and width. */ | |
fdfde340 JM |
10091 | Rd = inst.operands[0].reg; |
10092 | reject_bad_reg (Rd); | |
10093 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
10094 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
10095 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
10096 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
10097 | } |
10098 | ||
c19d1205 ZW |
10099 | static void |
10100 | do_t_bfi (void) | |
b99bd4ef | 10101 | { |
fdfde340 | 10102 | int Rd, Rn; |
c19d1205 | 10103 | unsigned int msb; |
b99bd4ef | 10104 | |
fdfde340 JM |
10105 | Rd = inst.operands[0].reg; |
10106 | reject_bad_reg (Rd); | |
10107 | ||
c19d1205 ZW |
10108 | /* #0 in second position is alternative syntax for bfc, which is |
10109 | the same instruction but with REG_PC in the Rm field. */ | |
10110 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
10111 | Rn = REG_PC; |
10112 | else | |
10113 | { | |
10114 | Rn = inst.operands[1].reg; | |
10115 | reject_bad_reg (Rn); | |
10116 | } | |
b99bd4ef | 10117 | |
c19d1205 ZW |
10118 | msb = inst.operands[2].imm + inst.operands[3].imm; |
10119 | constraint (msb > 32, _("bit-field extends past end of register")); | |
10120 | /* The instruction encoding stores the LSB and MSB, | |
10121 | not the LSB and width. */ | |
fdfde340 JM |
10122 | inst.instruction |= Rd << 8; |
10123 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
10124 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
10125 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
10126 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
10127 | } |
10128 | ||
c19d1205 ZW |
10129 | static void |
10130 | do_t_bfx (void) | |
b99bd4ef | 10131 | { |
fdfde340 JM |
10132 | unsigned Rd, Rn; |
10133 | ||
10134 | Rd = inst.operands[0].reg; | |
10135 | Rn = inst.operands[1].reg; | |
10136 | ||
10137 | reject_bad_reg (Rd); | |
10138 | reject_bad_reg (Rn); | |
10139 | ||
c19d1205 ZW |
10140 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
10141 | _("bit-field extends past end of register")); | |
fdfde340 JM |
10142 | inst.instruction |= Rd << 8; |
10143 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
10144 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
10145 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
10146 | inst.instruction |= inst.operands[3].imm - 1; | |
10147 | } | |
b99bd4ef | 10148 | |
c19d1205 ZW |
10149 | /* ARM V5 Thumb BLX (argument parse) |
10150 | BLX <target_addr> which is BLX(1) | |
10151 | BLX <Rm> which is BLX(2) | |
10152 | Unfortunately, there are two different opcodes for this mnemonic. | |
10153 | So, the insns[].value is not used, and the code here zaps values | |
10154 | into inst.instruction. | |
b99bd4ef | 10155 | |
c19d1205 ZW |
10156 | ??? How to take advantage of the additional two bits of displacement |
10157 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 10158 | |
c19d1205 ZW |
10159 | static void |
10160 | do_t_blx (void) | |
10161 | { | |
e07e6e58 NC |
10162 | set_it_insn_type_last (); |
10163 | ||
c19d1205 | 10164 | if (inst.operands[0].isreg) |
fdfde340 JM |
10165 | { |
10166 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
10167 | /* We have a register, so this is BLX(2). */ | |
10168 | inst.instruction |= inst.operands[0].reg << 3; | |
10169 | } | |
b99bd4ef NC |
10170 | else |
10171 | { | |
c19d1205 | 10172 | /* No register. This must be BLX(1). */ |
2fc8bdac | 10173 | inst.instruction = 0xf000e800; |
0855e32b | 10174 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
10175 | } |
10176 | } | |
10177 | ||
c19d1205 ZW |
10178 | static void |
10179 | do_t_branch (void) | |
b99bd4ef | 10180 | { |
0110f2b8 | 10181 | int opcode; |
dfa9f0d5 | 10182 | int cond; |
9ae92b05 | 10183 | int reloc; |
dfa9f0d5 | 10184 | |
e07e6e58 NC |
10185 | cond = inst.cond; |
10186 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
10187 | ||
10188 | if (in_it_block ()) | |
dfa9f0d5 PB |
10189 | { |
10190 | /* Conditional branches inside IT blocks are encoded as unconditional | |
10191 | branches. */ | |
10192 | cond = COND_ALWAYS; | |
dfa9f0d5 PB |
10193 | } |
10194 | else | |
10195 | cond = inst.cond; | |
10196 | ||
10197 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
10198 | opcode = T_MNEM_bcond; |
10199 | else | |
10200 | opcode = inst.instruction; | |
10201 | ||
12d6b0b7 RS |
10202 | if (unified_syntax |
10203 | && (inst.size_req == 4 | |
10960bfb PB |
10204 | || (inst.size_req != 2 |
10205 | && (inst.operands[0].hasreloc | |
10206 | || inst.reloc.exp.X_op == O_constant)))) | |
c19d1205 | 10207 | { |
0110f2b8 | 10208 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 10209 | if (cond == COND_ALWAYS) |
9ae92b05 | 10210 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
10211 | else |
10212 | { | |
9c2799c2 | 10213 | gas_assert (cond != 0xF); |
dfa9f0d5 | 10214 | inst.instruction |= cond << 22; |
9ae92b05 | 10215 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
10216 | } |
10217 | } | |
b99bd4ef NC |
10218 | else |
10219 | { | |
0110f2b8 | 10220 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 10221 | if (cond == COND_ALWAYS) |
9ae92b05 | 10222 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 10223 | else |
b99bd4ef | 10224 | { |
dfa9f0d5 | 10225 | inst.instruction |= cond << 8; |
9ae92b05 | 10226 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 10227 | } |
0110f2b8 PB |
10228 | /* Allow section relaxation. */ |
10229 | if (unified_syntax && inst.size_req != 2) | |
10230 | inst.relax = opcode; | |
b99bd4ef | 10231 | } |
9ae92b05 | 10232 | inst.reloc.type = reloc; |
c19d1205 | 10233 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
10234 | } |
10235 | ||
8884b720 | 10236 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 10237 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 10238 | RANGE. */ |
b99bd4ef | 10239 | static void |
8884b720 | 10240 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 10241 | { |
dfa9f0d5 PB |
10242 | constraint (inst.cond != COND_ALWAYS, |
10243 | _("instruction is always unconditional")); | |
c19d1205 | 10244 | if (inst.operands[0].present) |
b99bd4ef | 10245 | { |
8884b720 | 10246 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
10247 | _("immediate value out of range")); |
10248 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 10249 | } |
8884b720 MGD |
10250 | |
10251 | set_it_insn_type (NEUTRAL_IT_INSN); | |
10252 | } | |
10253 | ||
10254 | static void | |
10255 | do_t_hlt (void) | |
10256 | { | |
10257 | do_t_bkpt_hlt1 (63); | |
10258 | } | |
10259 | ||
10260 | static void | |
10261 | do_t_bkpt (void) | |
10262 | { | |
10263 | do_t_bkpt_hlt1 (255); | |
b99bd4ef NC |
10264 | } |
10265 | ||
10266 | static void | |
c19d1205 | 10267 | do_t_branch23 (void) |
b99bd4ef | 10268 | { |
e07e6e58 | 10269 | set_it_insn_type_last (); |
0855e32b | 10270 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 10271 | |
0855e32b NS |
10272 | /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in |
10273 | this file. We used to simply ignore the PLT reloc type here -- | |
10274 | the branch encoding is now needed to deal with TLSCALL relocs. | |
10275 | So if we see a PLT reloc now, put it back to how it used to be to | |
10276 | keep the preexisting behaviour. */ | |
10277 | if (inst.reloc.type == BFD_RELOC_ARM_PLT32) | |
10278 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 10279 | |
4343666d | 10280 | #if defined(OBJ_COFF) |
c19d1205 ZW |
10281 | /* If the destination of the branch is a defined symbol which does not have |
10282 | the THUMB_FUNC attribute, then we must be calling a function which has | |
10283 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
10284 | function and change the branch to refer to that function instead. */ | |
10285 | if ( inst.reloc.exp.X_op == O_symbol | |
10286 | && inst.reloc.exp.X_add_symbol != NULL | |
10287 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
10288 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
10289 | inst.reloc.exp.X_add_symbol = | |
10290 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 10291 | #endif |
90e4755a RE |
10292 | } |
10293 | ||
10294 | static void | |
c19d1205 | 10295 | do_t_bx (void) |
90e4755a | 10296 | { |
e07e6e58 | 10297 | set_it_insn_type_last (); |
c19d1205 ZW |
10298 | inst.instruction |= inst.operands[0].reg << 3; |
10299 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
10300 | should cause the alignment to be checked once it is known. This is | |
10301 | because BX PC only works if the instruction is word aligned. */ | |
10302 | } | |
90e4755a | 10303 | |
c19d1205 ZW |
10304 | static void |
10305 | do_t_bxj (void) | |
10306 | { | |
fdfde340 | 10307 | int Rm; |
90e4755a | 10308 | |
e07e6e58 | 10309 | set_it_insn_type_last (); |
fdfde340 JM |
10310 | Rm = inst.operands[0].reg; |
10311 | reject_bad_reg (Rm); | |
10312 | inst.instruction |= Rm << 16; | |
90e4755a RE |
10313 | } |
10314 | ||
10315 | static void | |
c19d1205 | 10316 | do_t_clz (void) |
90e4755a | 10317 | { |
fdfde340 JM |
10318 | unsigned Rd; |
10319 | unsigned Rm; | |
10320 | ||
10321 | Rd = inst.operands[0].reg; | |
10322 | Rm = inst.operands[1].reg; | |
10323 | ||
10324 | reject_bad_reg (Rd); | |
10325 | reject_bad_reg (Rm); | |
10326 | ||
10327 | inst.instruction |= Rd << 8; | |
10328 | inst.instruction |= Rm << 16; | |
10329 | inst.instruction |= Rm; | |
c19d1205 | 10330 | } |
90e4755a | 10331 | |
dfa9f0d5 PB |
10332 | static void |
10333 | do_t_cps (void) | |
10334 | { | |
e07e6e58 | 10335 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
10336 | inst.instruction |= inst.operands[0].imm; |
10337 | } | |
10338 | ||
c19d1205 ZW |
10339 | static void |
10340 | do_t_cpsi (void) | |
10341 | { | |
e07e6e58 | 10342 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 10343 | if (unified_syntax |
62b3e311 PB |
10344 | && (inst.operands[1].present || inst.size_req == 4) |
10345 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 10346 | { |
c19d1205 ZW |
10347 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
10348 | inst.instruction = 0xf3af8000; | |
10349 | inst.instruction |= imod << 9; | |
10350 | inst.instruction |= inst.operands[0].imm << 5; | |
10351 | if (inst.operands[1].present) | |
10352 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 10353 | } |
c19d1205 | 10354 | else |
90e4755a | 10355 | { |
62b3e311 PB |
10356 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
10357 | && (inst.operands[0].imm & 4), | |
10358 | _("selected processor does not support 'A' form " | |
10359 | "of this instruction")); | |
10360 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
10361 | _("Thumb does not support the 2-argument " |
10362 | "form of this instruction")); | |
10363 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 10364 | } |
90e4755a RE |
10365 | } |
10366 | ||
c19d1205 ZW |
10367 | /* THUMB CPY instruction (argument parse). */ |
10368 | ||
90e4755a | 10369 | static void |
c19d1205 | 10370 | do_t_cpy (void) |
90e4755a | 10371 | { |
c19d1205 | 10372 | if (inst.size_req == 4) |
90e4755a | 10373 | { |
c19d1205 ZW |
10374 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
10375 | inst.instruction |= inst.operands[0].reg << 8; | |
10376 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 10377 | } |
c19d1205 | 10378 | else |
90e4755a | 10379 | { |
c19d1205 ZW |
10380 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
10381 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
10382 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 10383 | } |
90e4755a RE |
10384 | } |
10385 | ||
90e4755a | 10386 | static void |
25fe350b | 10387 | do_t_cbz (void) |
90e4755a | 10388 | { |
e07e6e58 | 10389 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
10390 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
10391 | inst.instruction |= inst.operands[0].reg; | |
10392 | inst.reloc.pc_rel = 1; | |
10393 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
10394 | } | |
90e4755a | 10395 | |
62b3e311 PB |
10396 | static void |
10397 | do_t_dbg (void) | |
10398 | { | |
10399 | inst.instruction |= inst.operands[0].imm; | |
10400 | } | |
10401 | ||
10402 | static void | |
10403 | do_t_div (void) | |
10404 | { | |
fdfde340 JM |
10405 | unsigned Rd, Rn, Rm; |
10406 | ||
10407 | Rd = inst.operands[0].reg; | |
10408 | Rn = (inst.operands[1].present | |
10409 | ? inst.operands[1].reg : Rd); | |
10410 | Rm = inst.operands[2].reg; | |
10411 | ||
10412 | reject_bad_reg (Rd); | |
10413 | reject_bad_reg (Rn); | |
10414 | reject_bad_reg (Rm); | |
10415 | ||
10416 | inst.instruction |= Rd << 8; | |
10417 | inst.instruction |= Rn << 16; | |
10418 | inst.instruction |= Rm; | |
62b3e311 PB |
10419 | } |
10420 | ||
c19d1205 ZW |
10421 | static void |
10422 | do_t_hint (void) | |
10423 | { | |
10424 | if (unified_syntax && inst.size_req == 4) | |
10425 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10426 | else | |
10427 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10428 | } | |
90e4755a | 10429 | |
c19d1205 ZW |
10430 | static void |
10431 | do_t_it (void) | |
10432 | { | |
10433 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 10434 | |
e07e6e58 NC |
10435 | set_it_insn_type (IT_INSN); |
10436 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
10437 | now_it.cc = cond; | |
5a01bb1d | 10438 | now_it.warn_deprecated = FALSE; |
e27ec89e PB |
10439 | |
10440 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 10441 | if ((cond & 0x1) == 0x0) |
90e4755a | 10442 | { |
c19d1205 | 10443 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 10444 | |
c19d1205 | 10445 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
10446 | { |
10447 | /* No conversion needed. */ | |
10448 | now_it.block_length = 1; | |
10449 | } | |
c19d1205 | 10450 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
10451 | { |
10452 | mask ^= 0x8; | |
10453 | now_it.block_length = 2; | |
10454 | } | |
e27ec89e | 10455 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
10456 | { |
10457 | mask ^= 0xC; | |
10458 | now_it.block_length = 3; | |
10459 | } | |
c19d1205 | 10460 | else |
5a01bb1d MGD |
10461 | { |
10462 | mask ^= 0xE; | |
10463 | now_it.block_length = 4; | |
10464 | } | |
90e4755a | 10465 | |
e27ec89e PB |
10466 | inst.instruction &= 0xfff0; |
10467 | inst.instruction |= mask; | |
c19d1205 | 10468 | } |
90e4755a | 10469 | |
c19d1205 ZW |
10470 | inst.instruction |= cond << 4; |
10471 | } | |
90e4755a | 10472 | |
3c707909 PB |
10473 | /* Helper function used for both push/pop and ldm/stm. */ |
10474 | static void | |
10475 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
10476 | { | |
10477 | bfd_boolean load; | |
10478 | ||
10479 | load = (inst.instruction & (1 << 20)) != 0; | |
10480 | ||
10481 | if (mask & (1 << 13)) | |
10482 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 NC |
10483 | |
10484 | if ((mask & (1 << base)) != 0 | |
10485 | && writeback) | |
10486 | inst.error = _("having the base register in the register list when " | |
10487 | "using write back is UNPREDICTABLE"); | |
10488 | ||
3c707909 PB |
10489 | if (load) |
10490 | { | |
e07e6e58 NC |
10491 | if (mask & (1 << 15)) |
10492 | { | |
10493 | if (mask & (1 << 14)) | |
10494 | inst.error = _("LR and PC should not both be in register list"); | |
10495 | else | |
10496 | set_it_insn_type_last (); | |
10497 | } | |
3c707909 PB |
10498 | } |
10499 | else | |
10500 | { | |
10501 | if (mask & (1 << 15)) | |
10502 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
10503 | } |
10504 | ||
10505 | if ((mask & (mask - 1)) == 0) | |
10506 | { | |
10507 | /* Single register transfers implemented as str/ldr. */ | |
10508 | if (writeback) | |
10509 | { | |
10510 | if (inst.instruction & (1 << 23)) | |
10511 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
10512 | else | |
10513 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
10514 | } | |
10515 | else | |
10516 | { | |
10517 | if (inst.instruction & (1 << 23)) | |
10518 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
10519 | else | |
10520 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
10521 | } | |
10522 | ||
10523 | inst.instruction |= 0xf8400000; | |
10524 | if (load) | |
10525 | inst.instruction |= 0x00100000; | |
10526 | ||
5f4273c7 | 10527 | mask = ffs (mask) - 1; |
3c707909 PB |
10528 | mask <<= 12; |
10529 | } | |
10530 | else if (writeback) | |
10531 | inst.instruction |= WRITE_BACK; | |
10532 | ||
10533 | inst.instruction |= mask; | |
10534 | inst.instruction |= base << 16; | |
10535 | } | |
10536 | ||
c19d1205 ZW |
10537 | static void |
10538 | do_t_ldmstm (void) | |
10539 | { | |
10540 | /* This really doesn't seem worth it. */ | |
10541 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
10542 | _("expression too complex")); | |
10543 | constraint (inst.operands[1].writeback, | |
10544 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 10545 | |
c19d1205 ZW |
10546 | if (unified_syntax) |
10547 | { | |
3c707909 PB |
10548 | bfd_boolean narrow; |
10549 | unsigned mask; | |
10550 | ||
10551 | narrow = FALSE; | |
c19d1205 ZW |
10552 | /* See if we can use a 16-bit instruction. */ |
10553 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
10554 | && inst.size_req != 4 | |
3c707909 | 10555 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 10556 | { |
3c707909 | 10557 | mask = 1 << inst.operands[0].reg; |
90e4755a | 10558 | |
eab4f823 | 10559 | if (inst.operands[0].reg <= 7) |
90e4755a | 10560 | { |
3c707909 | 10561 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
10562 | ? inst.operands[0].writeback |
10563 | : (inst.operands[0].writeback | |
10564 | == !(inst.operands[1].imm & mask))) | |
10565 | { | |
10566 | if (inst.instruction == T_MNEM_stmia | |
10567 | && (inst.operands[1].imm & mask) | |
10568 | && (inst.operands[1].imm & (mask - 1))) | |
10569 | as_warn (_("value stored for r%d is UNKNOWN"), | |
10570 | inst.operands[0].reg); | |
3c707909 | 10571 | |
eab4f823 MGD |
10572 | inst.instruction = THUMB_OP16 (inst.instruction); |
10573 | inst.instruction |= inst.operands[0].reg << 8; | |
10574 | inst.instruction |= inst.operands[1].imm; | |
10575 | narrow = TRUE; | |
10576 | } | |
10577 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
10578 | { | |
10579 | /* This means 1 register in reg list one of 3 situations: | |
10580 | 1. Instruction is stmia, but without writeback. | |
10581 | 2. lmdia without writeback, but with Rn not in | |
10582 | reglist. | |
10583 | 3. ldmia with writeback, but with Rn in reglist. | |
10584 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
10585 | case 1 and 2 which can be converted into a 16-bit | |
10586 | str or ldr. The SP cases are handled below. */ | |
10587 | unsigned long opcode; | |
10588 | /* First, record an error for Case 3. */ | |
10589 | if (inst.operands[1].imm & mask | |
10590 | && inst.operands[0].writeback) | |
fa94de6b | 10591 | inst.error = |
eab4f823 MGD |
10592 | _("having the base register in the register list when " |
10593 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
10594 | |
10595 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
10596 | : T_MNEM_ldr); |
10597 | inst.instruction = THUMB_OP16 (opcode); | |
10598 | inst.instruction |= inst.operands[0].reg << 3; | |
10599 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
10600 | narrow = TRUE; | |
10601 | } | |
90e4755a | 10602 | } |
eab4f823 | 10603 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 10604 | { |
eab4f823 MGD |
10605 | if (inst.operands[0].writeback) |
10606 | { | |
fa94de6b | 10607 | inst.instruction = |
eab4f823 MGD |
10608 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
10609 | ? T_MNEM_push : T_MNEM_pop); | |
10610 | inst.instruction |= inst.operands[1].imm; | |
10611 | narrow = TRUE; | |
10612 | } | |
10613 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
10614 | { | |
fa94de6b | 10615 | inst.instruction = |
eab4f823 MGD |
10616 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
10617 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); | |
10618 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); | |
10619 | narrow = TRUE; | |
10620 | } | |
90e4755a | 10621 | } |
3c707909 PB |
10622 | } |
10623 | ||
10624 | if (!narrow) | |
10625 | { | |
c19d1205 ZW |
10626 | if (inst.instruction < 0xffff) |
10627 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 10628 | |
5f4273c7 NC |
10629 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
10630 | inst.operands[0].writeback); | |
90e4755a RE |
10631 | } |
10632 | } | |
c19d1205 | 10633 | else |
90e4755a | 10634 | { |
c19d1205 ZW |
10635 | constraint (inst.operands[0].reg > 7 |
10636 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
10637 | constraint (inst.instruction != T_MNEM_ldmia |
10638 | && inst.instruction != T_MNEM_stmia, | |
10639 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 10640 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 10641 | { |
c19d1205 ZW |
10642 | if (!inst.operands[0].writeback) |
10643 | as_warn (_("this instruction will write back the base register")); | |
10644 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
10645 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 10646 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 10647 | inst.operands[0].reg); |
f03698e6 | 10648 | } |
c19d1205 | 10649 | else |
90e4755a | 10650 | { |
c19d1205 ZW |
10651 | if (!inst.operands[0].writeback |
10652 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
10653 | as_warn (_("this instruction will write back the base register")); | |
10654 | else if (inst.operands[0].writeback | |
10655 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
10656 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
10657 | } |
10658 | ||
c19d1205 ZW |
10659 | inst.instruction = THUMB_OP16 (inst.instruction); |
10660 | inst.instruction |= inst.operands[0].reg << 8; | |
10661 | inst.instruction |= inst.operands[1].imm; | |
10662 | } | |
10663 | } | |
e28cd48c | 10664 | |
c19d1205 ZW |
10665 | static void |
10666 | do_t_ldrex (void) | |
10667 | { | |
10668 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
10669 | || inst.operands[1].postind || inst.operands[1].writeback | |
10670 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
10671 | || inst.operands[1].negative, | |
01cfc07f | 10672 | BAD_ADDR_MODE); |
e28cd48c | 10673 | |
5be8be5d DG |
10674 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
10675 | ||
c19d1205 ZW |
10676 | inst.instruction |= inst.operands[0].reg << 12; |
10677 | inst.instruction |= inst.operands[1].reg << 16; | |
10678 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
10679 | } | |
e28cd48c | 10680 | |
c19d1205 ZW |
10681 | static void |
10682 | do_t_ldrexd (void) | |
10683 | { | |
10684 | if (!inst.operands[1].present) | |
1cac9012 | 10685 | { |
c19d1205 ZW |
10686 | constraint (inst.operands[0].reg == REG_LR, |
10687 | _("r14 not allowed as first register " | |
10688 | "when second register is omitted")); | |
10689 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 10690 | } |
c19d1205 ZW |
10691 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
10692 | BAD_OVERLAP); | |
b99bd4ef | 10693 | |
c19d1205 ZW |
10694 | inst.instruction |= inst.operands[0].reg << 12; |
10695 | inst.instruction |= inst.operands[1].reg << 8; | |
10696 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10697 | } |
10698 | ||
10699 | static void | |
c19d1205 | 10700 | do_t_ldst (void) |
b99bd4ef | 10701 | { |
0110f2b8 PB |
10702 | unsigned long opcode; |
10703 | int Rn; | |
10704 | ||
e07e6e58 NC |
10705 | if (inst.operands[0].isreg |
10706 | && !inst.operands[0].preind | |
10707 | && inst.operands[0].reg == REG_PC) | |
10708 | set_it_insn_type_last (); | |
10709 | ||
0110f2b8 | 10710 | opcode = inst.instruction; |
c19d1205 | 10711 | if (unified_syntax) |
b99bd4ef | 10712 | { |
53365c0d PB |
10713 | if (!inst.operands[1].isreg) |
10714 | { | |
10715 | if (opcode <= 0xffff) | |
10716 | inst.instruction = THUMB_OP32 (opcode); | |
10717 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
10718 | return; | |
10719 | } | |
0110f2b8 PB |
10720 | if (inst.operands[1].isreg |
10721 | && !inst.operands[1].writeback | |
c19d1205 ZW |
10722 | && !inst.operands[1].shifted && !inst.operands[1].postind |
10723 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
10724 | && opcode <= 0xffff |
10725 | && inst.size_req != 4) | |
c19d1205 | 10726 | { |
0110f2b8 PB |
10727 | /* Insn may have a 16-bit form. */ |
10728 | Rn = inst.operands[1].reg; | |
10729 | if (inst.operands[1].immisreg) | |
10730 | { | |
10731 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 10732 | /* [Rn, Rik] */ |
0110f2b8 PB |
10733 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
10734 | goto op16; | |
5be8be5d DG |
10735 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
10736 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
10737 | } |
10738 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
10739 | && opcode != T_MNEM_ldrsb) | |
10740 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
10741 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
10742 | { | |
10743 | /* [Rn, #const] */ | |
10744 | if (Rn > 7) | |
10745 | { | |
10746 | if (Rn == REG_PC) | |
10747 | { | |
10748 | if (inst.reloc.pc_rel) | |
10749 | opcode = T_MNEM_ldr_pc2; | |
10750 | else | |
10751 | opcode = T_MNEM_ldr_pc; | |
10752 | } | |
10753 | else | |
10754 | { | |
10755 | if (opcode == T_MNEM_ldr) | |
10756 | opcode = T_MNEM_ldr_sp; | |
10757 | else | |
10758 | opcode = T_MNEM_str_sp; | |
10759 | } | |
10760 | inst.instruction = inst.operands[0].reg << 8; | |
10761 | } | |
10762 | else | |
10763 | { | |
10764 | inst.instruction = inst.operands[0].reg; | |
10765 | inst.instruction |= inst.operands[1].reg << 3; | |
10766 | } | |
10767 | inst.instruction |= THUMB_OP16 (opcode); | |
10768 | if (inst.size_req == 2) | |
10769 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10770 | else | |
10771 | inst.relax = opcode; | |
10772 | return; | |
10773 | } | |
c19d1205 | 10774 | } |
0110f2b8 | 10775 | /* Definitely a 32-bit variant. */ |
5be8be5d | 10776 | |
8d67f500 NC |
10777 | /* Warning for Erratum 752419. */ |
10778 | if (opcode == T_MNEM_ldr | |
10779 | && inst.operands[0].reg == REG_SP | |
10780 | && inst.operands[1].writeback == 1 | |
10781 | && !inst.operands[1].immisreg) | |
10782 | { | |
10783 | if (no_cpu_selected () | |
10784 | || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7) | |
10785 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) | |
10786 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
10787 | as_warn (_("This instruction may be unpredictable " | |
10788 | "if executed on M-profile cores " | |
10789 | "with interrupts enabled.")); | |
10790 | } | |
10791 | ||
5be8be5d | 10792 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 10793 | if (inst.operands[1].immisreg) |
5be8be5d DG |
10794 | reject_bad_reg (inst.operands[1].imm); |
10795 | ||
1be5fd2e NC |
10796 | constraint (inst.operands[1].writeback == 1 |
10797 | && inst.operands[0].reg == inst.operands[1].reg, | |
10798 | BAD_OVERLAP); | |
10799 | ||
0110f2b8 | 10800 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
10801 | inst.instruction |= inst.operands[0].reg << 12; |
10802 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
1be5fd2e | 10803 | check_ldr_r15_aligned (); |
b99bd4ef NC |
10804 | return; |
10805 | } | |
10806 | ||
c19d1205 ZW |
10807 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
10808 | ||
10809 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 10810 | { |
c19d1205 ZW |
10811 | /* Only [Rn,Rm] is acceptable. */ |
10812 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
10813 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
10814 | || inst.operands[1].postind || inst.operands[1].shifted | |
10815 | || inst.operands[1].negative, | |
10816 | _("Thumb does not support this addressing mode")); | |
10817 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10818 | goto op16; | |
b99bd4ef | 10819 | } |
5f4273c7 | 10820 | |
c19d1205 ZW |
10821 | inst.instruction = THUMB_OP16 (inst.instruction); |
10822 | if (!inst.operands[1].isreg) | |
10823 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
10824 | return; | |
b99bd4ef | 10825 | |
c19d1205 ZW |
10826 | constraint (!inst.operands[1].preind |
10827 | || inst.operands[1].shifted | |
10828 | || inst.operands[1].writeback, | |
10829 | _("Thumb does not support this addressing mode")); | |
10830 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 10831 | { |
c19d1205 ZW |
10832 | constraint (inst.instruction & 0x0600, |
10833 | _("byte or halfword not valid for base register")); | |
10834 | constraint (inst.operands[1].reg == REG_PC | |
10835 | && !(inst.instruction & THUMB_LOAD_BIT), | |
10836 | _("r15 based store not allowed")); | |
10837 | constraint (inst.operands[1].immisreg, | |
10838 | _("invalid base register for register offset")); | |
b99bd4ef | 10839 | |
c19d1205 ZW |
10840 | if (inst.operands[1].reg == REG_PC) |
10841 | inst.instruction = T_OPCODE_LDR_PC; | |
10842 | else if (inst.instruction & THUMB_LOAD_BIT) | |
10843 | inst.instruction = T_OPCODE_LDR_SP; | |
10844 | else | |
10845 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 10846 | |
c19d1205 ZW |
10847 | inst.instruction |= inst.operands[0].reg << 8; |
10848 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10849 | return; | |
10850 | } | |
90e4755a | 10851 | |
c19d1205 ZW |
10852 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
10853 | if (!inst.operands[1].immisreg) | |
10854 | { | |
10855 | /* Immediate offset. */ | |
10856 | inst.instruction |= inst.operands[0].reg; | |
10857 | inst.instruction |= inst.operands[1].reg << 3; | |
10858 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10859 | return; | |
10860 | } | |
90e4755a | 10861 | |
c19d1205 ZW |
10862 | /* Register offset. */ |
10863 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
10864 | constraint (inst.operands[1].negative, | |
10865 | _("Thumb does not support this addressing mode")); | |
90e4755a | 10866 | |
c19d1205 ZW |
10867 | op16: |
10868 | switch (inst.instruction) | |
10869 | { | |
10870 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
10871 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
10872 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
10873 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
10874 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
10875 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
10876 | case 0x5600 /* ldrsb */: | |
10877 | case 0x5e00 /* ldrsh */: break; | |
10878 | default: abort (); | |
10879 | } | |
90e4755a | 10880 | |
c19d1205 ZW |
10881 | inst.instruction |= inst.operands[0].reg; |
10882 | inst.instruction |= inst.operands[1].reg << 3; | |
10883 | inst.instruction |= inst.operands[1].imm << 6; | |
10884 | } | |
90e4755a | 10885 | |
c19d1205 ZW |
10886 | static void |
10887 | do_t_ldstd (void) | |
10888 | { | |
10889 | if (!inst.operands[1].present) | |
b99bd4ef | 10890 | { |
c19d1205 ZW |
10891 | inst.operands[1].reg = inst.operands[0].reg + 1; |
10892 | constraint (inst.operands[0].reg == REG_LR, | |
10893 | _("r14 not allowed here")); | |
bd340a04 MGD |
10894 | constraint (inst.operands[0].reg == REG_R12, |
10895 | _("r12 not allowed here")); | |
b99bd4ef | 10896 | } |
bd340a04 MGD |
10897 | |
10898 | if (inst.operands[2].writeback | |
10899 | && (inst.operands[0].reg == inst.operands[2].reg | |
10900 | || inst.operands[1].reg == inst.operands[2].reg)) | |
10901 | as_warn (_("base register written back, and overlaps " | |
10902 | "one of transfer registers")); | |
10903 | ||
c19d1205 ZW |
10904 | inst.instruction |= inst.operands[0].reg << 12; |
10905 | inst.instruction |= inst.operands[1].reg << 8; | |
10906 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
10907 | } |
10908 | ||
c19d1205 ZW |
10909 | static void |
10910 | do_t_ldstt (void) | |
10911 | { | |
10912 | inst.instruction |= inst.operands[0].reg << 12; | |
10913 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
10914 | } | |
a737bd4d | 10915 | |
b99bd4ef | 10916 | static void |
c19d1205 | 10917 | do_t_mla (void) |
b99bd4ef | 10918 | { |
fdfde340 | 10919 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 10920 | |
fdfde340 JM |
10921 | Rd = inst.operands[0].reg; |
10922 | Rn = inst.operands[1].reg; | |
10923 | Rm = inst.operands[2].reg; | |
10924 | Ra = inst.operands[3].reg; | |
10925 | ||
10926 | reject_bad_reg (Rd); | |
10927 | reject_bad_reg (Rn); | |
10928 | reject_bad_reg (Rm); | |
10929 | reject_bad_reg (Ra); | |
10930 | ||
10931 | inst.instruction |= Rd << 8; | |
10932 | inst.instruction |= Rn << 16; | |
10933 | inst.instruction |= Rm; | |
10934 | inst.instruction |= Ra << 12; | |
c19d1205 | 10935 | } |
b99bd4ef | 10936 | |
c19d1205 ZW |
10937 | static void |
10938 | do_t_mlal (void) | |
10939 | { | |
fdfde340 JM |
10940 | unsigned RdLo, RdHi, Rn, Rm; |
10941 | ||
10942 | RdLo = inst.operands[0].reg; | |
10943 | RdHi = inst.operands[1].reg; | |
10944 | Rn = inst.operands[2].reg; | |
10945 | Rm = inst.operands[3].reg; | |
10946 | ||
10947 | reject_bad_reg (RdLo); | |
10948 | reject_bad_reg (RdHi); | |
10949 | reject_bad_reg (Rn); | |
10950 | reject_bad_reg (Rm); | |
10951 | ||
10952 | inst.instruction |= RdLo << 12; | |
10953 | inst.instruction |= RdHi << 8; | |
10954 | inst.instruction |= Rn << 16; | |
10955 | inst.instruction |= Rm; | |
c19d1205 | 10956 | } |
b99bd4ef | 10957 | |
c19d1205 ZW |
10958 | static void |
10959 | do_t_mov_cmp (void) | |
10960 | { | |
fdfde340 JM |
10961 | unsigned Rn, Rm; |
10962 | ||
10963 | Rn = inst.operands[0].reg; | |
10964 | Rm = inst.operands[1].reg; | |
10965 | ||
e07e6e58 NC |
10966 | if (Rn == REG_PC) |
10967 | set_it_insn_type_last (); | |
10968 | ||
c19d1205 | 10969 | if (unified_syntax) |
b99bd4ef | 10970 | { |
c19d1205 ZW |
10971 | int r0off = (inst.instruction == T_MNEM_mov |
10972 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 10973 | unsigned long opcode; |
3d388997 PB |
10974 | bfd_boolean narrow; |
10975 | bfd_boolean low_regs; | |
10976 | ||
fdfde340 | 10977 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 10978 | opcode = inst.instruction; |
e07e6e58 | 10979 | if (in_it_block ()) |
0110f2b8 | 10980 | narrow = opcode != T_MNEM_movs; |
3d388997 | 10981 | else |
0110f2b8 | 10982 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
10983 | if (inst.size_req == 4 |
10984 | || inst.operands[1].shifted) | |
10985 | narrow = FALSE; | |
10986 | ||
efd81785 PB |
10987 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
10988 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
10989 | && !inst.operands[1].shifted | |
fdfde340 JM |
10990 | && Rn == REG_PC |
10991 | && Rm == REG_LR) | |
efd81785 PB |
10992 | { |
10993 | inst.instruction = T2_SUBS_PC_LR; | |
10994 | return; | |
10995 | } | |
10996 | ||
fdfde340 JM |
10997 | if (opcode == T_MNEM_cmp) |
10998 | { | |
10999 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
11000 | if (narrow) |
11001 | { | |
11002 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
11003 | but valid. */ | |
11004 | warn_deprecated_sp (Rm); | |
11005 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
11006 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
11007 | tools reject R15, so we do too. */ | |
11008 | constraint (Rm == REG_PC, BAD_PC); | |
11009 | } | |
11010 | else | |
11011 | reject_bad_reg (Rm); | |
fdfde340 JM |
11012 | } |
11013 | else if (opcode == T_MNEM_mov | |
11014 | || opcode == T_MNEM_movs) | |
11015 | { | |
11016 | if (inst.operands[1].isreg) | |
11017 | { | |
11018 | if (opcode == T_MNEM_movs) | |
11019 | { | |
11020 | reject_bad_reg (Rn); | |
11021 | reject_bad_reg (Rm); | |
11022 | } | |
76fa04a4 MGD |
11023 | else if (narrow) |
11024 | { | |
11025 | /* This is mov.n. */ | |
11026 | if ((Rn == REG_SP || Rn == REG_PC) | |
11027 | && (Rm == REG_SP || Rm == REG_PC)) | |
11028 | { | |
11029 | as_warn (_("Use of r%u as a source register is " | |
11030 | "deprecated when r%u is the destination " | |
11031 | "register."), Rm, Rn); | |
11032 | } | |
11033 | } | |
11034 | else | |
11035 | { | |
11036 | /* This is mov.w. */ | |
11037 | constraint (Rn == REG_PC, BAD_PC); | |
11038 | constraint (Rm == REG_PC, BAD_PC); | |
11039 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
11040 | } | |
fdfde340 JM |
11041 | } |
11042 | else | |
11043 | reject_bad_reg (Rn); | |
11044 | } | |
11045 | ||
c19d1205 ZW |
11046 | if (!inst.operands[1].isreg) |
11047 | { | |
0110f2b8 | 11048 | /* Immediate operand. */ |
e07e6e58 | 11049 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
11050 | narrow = 0; |
11051 | if (low_regs && narrow) | |
11052 | { | |
11053 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 11054 | inst.instruction |= Rn << 8; |
0110f2b8 PB |
11055 | if (inst.size_req == 2) |
11056 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
11057 | else | |
11058 | inst.relax = opcode; | |
11059 | } | |
11060 | else | |
11061 | { | |
11062 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11063 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 11064 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
11065 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
11066 | } | |
c19d1205 | 11067 | } |
728ca7c9 PB |
11068 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
11069 | && (inst.instruction == T_MNEM_mov | |
11070 | || inst.instruction == T_MNEM_movs)) | |
11071 | { | |
11072 | /* Register shifts are encoded as separate shift instructions. */ | |
11073 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
11074 | ||
e07e6e58 | 11075 | if (in_it_block ()) |
728ca7c9 PB |
11076 | narrow = !flags; |
11077 | else | |
11078 | narrow = flags; | |
11079 | ||
11080 | if (inst.size_req == 4) | |
11081 | narrow = FALSE; | |
11082 | ||
11083 | if (!low_regs || inst.operands[1].imm > 7) | |
11084 | narrow = FALSE; | |
11085 | ||
fdfde340 | 11086 | if (Rn != Rm) |
728ca7c9 PB |
11087 | narrow = FALSE; |
11088 | ||
11089 | switch (inst.operands[1].shift_kind) | |
11090 | { | |
11091 | case SHIFT_LSL: | |
11092 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
11093 | break; | |
11094 | case SHIFT_ASR: | |
11095 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
11096 | break; | |
11097 | case SHIFT_LSR: | |
11098 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
11099 | break; | |
11100 | case SHIFT_ROR: | |
11101 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
11102 | break; | |
11103 | default: | |
5f4273c7 | 11104 | abort (); |
728ca7c9 PB |
11105 | } |
11106 | ||
11107 | inst.instruction = opcode; | |
11108 | if (narrow) | |
11109 | { | |
fdfde340 | 11110 | inst.instruction |= Rn; |
728ca7c9 PB |
11111 | inst.instruction |= inst.operands[1].imm << 3; |
11112 | } | |
11113 | else | |
11114 | { | |
11115 | if (flags) | |
11116 | inst.instruction |= CONDS_BIT; | |
11117 | ||
fdfde340 JM |
11118 | inst.instruction |= Rn << 8; |
11119 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
11120 | inst.instruction |= inst.operands[1].imm; |
11121 | } | |
11122 | } | |
3d388997 | 11123 | else if (!narrow) |
c19d1205 | 11124 | { |
728ca7c9 PB |
11125 | /* Some mov with immediate shift have narrow variants. |
11126 | Register shifts are handled above. */ | |
11127 | if (low_regs && inst.operands[1].shifted | |
11128 | && (inst.instruction == T_MNEM_mov | |
11129 | || inst.instruction == T_MNEM_movs)) | |
11130 | { | |
e07e6e58 | 11131 | if (in_it_block ()) |
728ca7c9 PB |
11132 | narrow = (inst.instruction == T_MNEM_mov); |
11133 | else | |
11134 | narrow = (inst.instruction == T_MNEM_movs); | |
11135 | } | |
11136 | ||
11137 | if (narrow) | |
11138 | { | |
11139 | switch (inst.operands[1].shift_kind) | |
11140 | { | |
11141 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
11142 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
11143 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
11144 | default: narrow = FALSE; break; | |
11145 | } | |
11146 | } | |
11147 | ||
11148 | if (narrow) | |
11149 | { | |
fdfde340 JM |
11150 | inst.instruction |= Rn; |
11151 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
11152 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
11153 | } | |
11154 | else | |
11155 | { | |
11156 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 11157 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
11158 | encode_thumb32_shifted_operand (1); |
11159 | } | |
c19d1205 ZW |
11160 | } |
11161 | else | |
11162 | switch (inst.instruction) | |
11163 | { | |
11164 | case T_MNEM_mov: | |
837b3435 | 11165 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
11166 | results. Don't allow this. */ |
11167 | if (low_regs) | |
11168 | { | |
11169 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6), | |
11170 | "MOV Rd, Rs with two low registers is not " | |
11171 | "permitted on this architecture"); | |
fa94de6b | 11172 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
11173 | arm_ext_v6); |
11174 | } | |
11175 | ||
c19d1205 | 11176 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
11177 | inst.instruction |= (Rn & 0x8) << 4; |
11178 | inst.instruction |= (Rn & 0x7); | |
11179 | inst.instruction |= Rm << 3; | |
c19d1205 | 11180 | break; |
b99bd4ef | 11181 | |
c19d1205 ZW |
11182 | case T_MNEM_movs: |
11183 | /* We know we have low registers at this point. | |
941a8a52 MGD |
11184 | Generate LSLS Rd, Rs, #0. */ |
11185 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
11186 | inst.instruction |= Rn; |
11187 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11188 | break; |
11189 | ||
11190 | case T_MNEM_cmp: | |
3d388997 | 11191 | if (low_regs) |
c19d1205 ZW |
11192 | { |
11193 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
11194 | inst.instruction |= Rn; |
11195 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11196 | } |
11197 | else | |
11198 | { | |
11199 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
11200 | inst.instruction |= (Rn & 0x8) << 4; |
11201 | inst.instruction |= (Rn & 0x7); | |
11202 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11203 | } |
11204 | break; | |
11205 | } | |
b99bd4ef NC |
11206 | return; |
11207 | } | |
11208 | ||
c19d1205 | 11209 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
11210 | |
11211 | /* PR 10443: Do not silently ignore shifted operands. */ | |
11212 | constraint (inst.operands[1].shifted, | |
11213 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
11214 | ||
c19d1205 | 11215 | if (inst.operands[1].isreg) |
b99bd4ef | 11216 | { |
fdfde340 | 11217 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 11218 | { |
c19d1205 ZW |
11219 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
11220 | since a MOV instruction produces unpredictable results. */ | |
11221 | if (inst.instruction == T_OPCODE_MOV_I8) | |
11222 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 11223 | else |
c19d1205 | 11224 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 11225 | |
fdfde340 JM |
11226 | inst.instruction |= Rn; |
11227 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
11228 | } |
11229 | else | |
11230 | { | |
c19d1205 ZW |
11231 | if (inst.instruction == T_OPCODE_MOV_I8) |
11232 | inst.instruction = T_OPCODE_MOV_HR; | |
11233 | else | |
11234 | inst.instruction = T_OPCODE_CMP_HR; | |
11235 | do_t_cpy (); | |
b99bd4ef NC |
11236 | } |
11237 | } | |
c19d1205 | 11238 | else |
b99bd4ef | 11239 | { |
fdfde340 | 11240 | constraint (Rn > 7, |
c19d1205 | 11241 | _("only lo regs allowed with immediate")); |
fdfde340 | 11242 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
11243 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
11244 | } | |
11245 | } | |
b99bd4ef | 11246 | |
c19d1205 ZW |
11247 | static void |
11248 | do_t_mov16 (void) | |
11249 | { | |
fdfde340 | 11250 | unsigned Rd; |
b6895b4f PB |
11251 | bfd_vma imm; |
11252 | bfd_boolean top; | |
11253 | ||
11254 | top = (inst.instruction & 0x00800000) != 0; | |
11255 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
11256 | { | |
11257 | constraint (top, _(":lower16: not allowed this instruction")); | |
11258 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
11259 | } | |
11260 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
11261 | { | |
11262 | constraint (!top, _(":upper16: not allowed this instruction")); | |
11263 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
11264 | } | |
11265 | ||
fdfde340 JM |
11266 | Rd = inst.operands[0].reg; |
11267 | reject_bad_reg (Rd); | |
11268 | ||
11269 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
11270 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
11271 | { | |
11272 | imm = inst.reloc.exp.X_add_number; | |
11273 | inst.instruction |= (imm & 0xf000) << 4; | |
11274 | inst.instruction |= (imm & 0x0800) << 15; | |
11275 | inst.instruction |= (imm & 0x0700) << 4; | |
11276 | inst.instruction |= (imm & 0x00ff); | |
11277 | } | |
c19d1205 | 11278 | } |
b99bd4ef | 11279 | |
c19d1205 ZW |
11280 | static void |
11281 | do_t_mvn_tst (void) | |
11282 | { | |
fdfde340 | 11283 | unsigned Rn, Rm; |
c921be7d | 11284 | |
fdfde340 JM |
11285 | Rn = inst.operands[0].reg; |
11286 | Rm = inst.operands[1].reg; | |
11287 | ||
11288 | if (inst.instruction == T_MNEM_cmp | |
11289 | || inst.instruction == T_MNEM_cmn) | |
11290 | constraint (Rn == REG_PC, BAD_PC); | |
11291 | else | |
11292 | reject_bad_reg (Rn); | |
11293 | reject_bad_reg (Rm); | |
11294 | ||
c19d1205 ZW |
11295 | if (unified_syntax) |
11296 | { | |
11297 | int r0off = (inst.instruction == T_MNEM_mvn | |
11298 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
11299 | bfd_boolean narrow; |
11300 | ||
11301 | if (inst.size_req == 4 | |
11302 | || inst.instruction > 0xffff | |
11303 | || inst.operands[1].shifted | |
fdfde340 | 11304 | || Rn > 7 || Rm > 7) |
3d388997 PB |
11305 | narrow = FALSE; |
11306 | else if (inst.instruction == T_MNEM_cmn) | |
11307 | narrow = TRUE; | |
11308 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 11309 | narrow = !in_it_block (); |
3d388997 | 11310 | else |
e07e6e58 | 11311 | narrow = in_it_block (); |
3d388997 | 11312 | |
c19d1205 | 11313 | if (!inst.operands[1].isreg) |
b99bd4ef | 11314 | { |
c19d1205 ZW |
11315 | /* For an immediate, we always generate a 32-bit opcode; |
11316 | section relaxation will shrink it later if possible. */ | |
11317 | if (inst.instruction < 0xffff) | |
11318 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11319 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 11320 | inst.instruction |= Rn << r0off; |
c19d1205 | 11321 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 11322 | } |
c19d1205 | 11323 | else |
b99bd4ef | 11324 | { |
c19d1205 | 11325 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 11326 | if (narrow) |
b99bd4ef | 11327 | { |
c19d1205 | 11328 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
11329 | inst.instruction |= Rn; |
11330 | inst.instruction |= Rm << 3; | |
b99bd4ef | 11331 | } |
c19d1205 | 11332 | else |
b99bd4ef | 11333 | { |
c19d1205 ZW |
11334 | constraint (inst.operands[1].shifted |
11335 | && inst.operands[1].immisreg, | |
11336 | _("shift must be constant")); | |
11337 | if (inst.instruction < 0xffff) | |
11338 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 11339 | inst.instruction |= Rn << r0off; |
c19d1205 | 11340 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 11341 | } |
b99bd4ef NC |
11342 | } |
11343 | } | |
11344 | else | |
11345 | { | |
c19d1205 ZW |
11346 | constraint (inst.instruction > 0xffff |
11347 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
11348 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
11349 | _("unshifted register required")); | |
fdfde340 | 11350 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 11351 | BAD_HIREG); |
b99bd4ef | 11352 | |
c19d1205 | 11353 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
11354 | inst.instruction |= Rn; |
11355 | inst.instruction |= Rm << 3; | |
b99bd4ef | 11356 | } |
b99bd4ef NC |
11357 | } |
11358 | ||
b05fe5cf | 11359 | static void |
c19d1205 | 11360 | do_t_mrs (void) |
b05fe5cf | 11361 | { |
fdfde340 | 11362 | unsigned Rd; |
037e8744 JB |
11363 | |
11364 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
11365 | return; | |
11366 | ||
90ec0d68 MGD |
11367 | Rd = inst.operands[0].reg; |
11368 | reject_bad_reg (Rd); | |
11369 | inst.instruction |= Rd << 8; | |
11370 | ||
11371 | if (inst.operands[1].isreg) | |
62b3e311 | 11372 | { |
90ec0d68 MGD |
11373 | unsigned br = inst.operands[1].reg; |
11374 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
11375 | as_bad (_("bad register for mrs")); | |
11376 | ||
11377 | inst.instruction |= br & (0xf << 16); | |
11378 | inst.instruction |= (br & 0x300) >> 4; | |
11379 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
11380 | } |
11381 | else | |
11382 | { | |
90ec0d68 | 11383 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 11384 | |
d2cd1205 | 11385 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
11386 | { |
11387 | /* PR gas/12698: The constraint is only applied for m_profile. | |
11388 | If the user has specified -march=all, we want to ignore it as | |
11389 | we are building for any CPU type, including non-m variants. */ | |
11390 | bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core; | |
11391 | constraint ((flags != 0) && m_profile, _("selected processor does " | |
11392 | "not support requested special purpose register")); | |
11393 | } | |
90ec0d68 | 11394 | else |
d2cd1205 JB |
11395 | /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile |
11396 | devices). */ | |
11397 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
11398 | _("'APSR', 'CPSR' or 'SPSR' expected")); | |
fdfde340 | 11399 | |
90ec0d68 MGD |
11400 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
11401 | inst.instruction |= inst.operands[1].imm & 0xff; | |
11402 | inst.instruction |= 0xf0000; | |
11403 | } | |
c19d1205 | 11404 | } |
b05fe5cf | 11405 | |
c19d1205 ZW |
11406 | static void |
11407 | do_t_msr (void) | |
11408 | { | |
62b3e311 | 11409 | int flags; |
fdfde340 | 11410 | unsigned Rn; |
62b3e311 | 11411 | |
037e8744 JB |
11412 | if (do_vfp_nsyn_msr () == SUCCESS) |
11413 | return; | |
11414 | ||
c19d1205 ZW |
11415 | constraint (!inst.operands[1].isreg, |
11416 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
11417 | |
11418 | if (inst.operands[0].isreg) | |
11419 | flags = (int)(inst.operands[0].reg); | |
11420 | else | |
11421 | flags = inst.operands[0].imm; | |
11422 | ||
d2cd1205 | 11423 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 11424 | { |
d2cd1205 JB |
11425 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
11426 | ||
1a43faaf NC |
11427 | /* PR gas/12698: The constraint is only applied for m_profile. |
11428 | If the user has specified -march=all, we want to ignore it as | |
11429 | we are building for any CPU type, including non-m variants. */ | |
11430 | bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core; | |
11431 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
11432 | && (bits & ~(PSR_s | PSR_f)) != 0) | |
11433 | || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
11434 | && bits != PSR_f)) && m_profile, | |
11435 | _("selected processor does not support requested special " | |
11436 | "purpose register")); | |
62b3e311 PB |
11437 | } |
11438 | else | |
d2cd1205 JB |
11439 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
11440 | "requested special purpose register")); | |
c921be7d | 11441 | |
fdfde340 JM |
11442 | Rn = inst.operands[1].reg; |
11443 | reject_bad_reg (Rn); | |
11444 | ||
62b3e311 | 11445 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
11446 | inst.instruction |= (flags & 0xf0000) >> 8; |
11447 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 11448 | inst.instruction |= (flags & 0xff); |
fdfde340 | 11449 | inst.instruction |= Rn << 16; |
c19d1205 | 11450 | } |
b05fe5cf | 11451 | |
c19d1205 ZW |
11452 | static void |
11453 | do_t_mul (void) | |
11454 | { | |
17828f45 | 11455 | bfd_boolean narrow; |
fdfde340 | 11456 | unsigned Rd, Rn, Rm; |
17828f45 | 11457 | |
c19d1205 ZW |
11458 | if (!inst.operands[2].present) |
11459 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 11460 | |
fdfde340 JM |
11461 | Rd = inst.operands[0].reg; |
11462 | Rn = inst.operands[1].reg; | |
11463 | Rm = inst.operands[2].reg; | |
11464 | ||
17828f45 | 11465 | if (unified_syntax) |
b05fe5cf | 11466 | { |
17828f45 | 11467 | if (inst.size_req == 4 |
fdfde340 JM |
11468 | || (Rd != Rn |
11469 | && Rd != Rm) | |
11470 | || Rn > 7 | |
11471 | || Rm > 7) | |
17828f45 JM |
11472 | narrow = FALSE; |
11473 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 11474 | narrow = !in_it_block (); |
17828f45 | 11475 | else |
e07e6e58 | 11476 | narrow = in_it_block (); |
b05fe5cf | 11477 | } |
c19d1205 | 11478 | else |
b05fe5cf | 11479 | { |
17828f45 | 11480 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 11481 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 11482 | BAD_HIREG); |
17828f45 JM |
11483 | narrow = TRUE; |
11484 | } | |
b05fe5cf | 11485 | |
17828f45 JM |
11486 | if (narrow) |
11487 | { | |
11488 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 11489 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 11490 | inst.instruction |= Rd; |
b05fe5cf | 11491 | |
fdfde340 JM |
11492 | if (Rd == Rn) |
11493 | inst.instruction |= Rm << 3; | |
11494 | else if (Rd == Rm) | |
11495 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
11496 | else |
11497 | constraint (1, _("dest must overlap one source register")); | |
11498 | } | |
17828f45 JM |
11499 | else |
11500 | { | |
e07e6e58 NC |
11501 | constraint (inst.instruction != T_MNEM_mul, |
11502 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
11503 | /* 32-bit MUL. */ |
11504 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11505 | inst.instruction |= Rd << 8; |
11506 | inst.instruction |= Rn << 16; | |
11507 | inst.instruction |= Rm << 0; | |
11508 | ||
11509 | reject_bad_reg (Rd); | |
11510 | reject_bad_reg (Rn); | |
11511 | reject_bad_reg (Rm); | |
17828f45 | 11512 | } |
c19d1205 | 11513 | } |
b05fe5cf | 11514 | |
c19d1205 ZW |
11515 | static void |
11516 | do_t_mull (void) | |
11517 | { | |
fdfde340 | 11518 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 11519 | |
fdfde340 JM |
11520 | RdLo = inst.operands[0].reg; |
11521 | RdHi = inst.operands[1].reg; | |
11522 | Rn = inst.operands[2].reg; | |
11523 | Rm = inst.operands[3].reg; | |
11524 | ||
11525 | reject_bad_reg (RdLo); | |
11526 | reject_bad_reg (RdHi); | |
11527 | reject_bad_reg (Rn); | |
11528 | reject_bad_reg (Rm); | |
11529 | ||
11530 | inst.instruction |= RdLo << 12; | |
11531 | inst.instruction |= RdHi << 8; | |
11532 | inst.instruction |= Rn << 16; | |
11533 | inst.instruction |= Rm; | |
11534 | ||
11535 | if (RdLo == RdHi) | |
c19d1205 ZW |
11536 | as_tsktsk (_("rdhi and rdlo must be different")); |
11537 | } | |
b05fe5cf | 11538 | |
c19d1205 ZW |
11539 | static void |
11540 | do_t_nop (void) | |
11541 | { | |
e07e6e58 NC |
11542 | set_it_insn_type (NEUTRAL_IT_INSN); |
11543 | ||
c19d1205 ZW |
11544 | if (unified_syntax) |
11545 | { | |
11546 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 11547 | { |
c19d1205 ZW |
11548 | inst.instruction = THUMB_OP32 (inst.instruction); |
11549 | inst.instruction |= inst.operands[0].imm; | |
11550 | } | |
11551 | else | |
11552 | { | |
bc2d1808 NC |
11553 | /* PR9722: Check for Thumb2 availability before |
11554 | generating a thumb2 nop instruction. */ | |
afa62d5e | 11555 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
11556 | { |
11557 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11558 | inst.instruction |= inst.operands[0].imm << 4; | |
11559 | } | |
11560 | else | |
11561 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
11562 | } |
11563 | } | |
11564 | else | |
11565 | { | |
11566 | constraint (inst.operands[0].present, | |
11567 | _("Thumb does not support NOP with hints")); | |
11568 | inst.instruction = 0x46c0; | |
11569 | } | |
11570 | } | |
b05fe5cf | 11571 | |
c19d1205 ZW |
11572 | static void |
11573 | do_t_neg (void) | |
11574 | { | |
11575 | if (unified_syntax) | |
11576 | { | |
3d388997 PB |
11577 | bfd_boolean narrow; |
11578 | ||
11579 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 11580 | narrow = !in_it_block (); |
3d388997 | 11581 | else |
e07e6e58 | 11582 | narrow = in_it_block (); |
3d388997 PB |
11583 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
11584 | narrow = FALSE; | |
11585 | if (inst.size_req == 4) | |
11586 | narrow = FALSE; | |
11587 | ||
11588 | if (!narrow) | |
c19d1205 ZW |
11589 | { |
11590 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11591 | inst.instruction |= inst.operands[0].reg << 8; | |
11592 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
11593 | } |
11594 | else | |
11595 | { | |
c19d1205 ZW |
11596 | inst.instruction = THUMB_OP16 (inst.instruction); |
11597 | inst.instruction |= inst.operands[0].reg; | |
11598 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
11599 | } |
11600 | } | |
11601 | else | |
11602 | { | |
c19d1205 ZW |
11603 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
11604 | BAD_HIREG); | |
11605 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
11606 | ||
11607 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11608 | inst.instruction |= inst.operands[0].reg; | |
11609 | inst.instruction |= inst.operands[1].reg << 3; | |
11610 | } | |
11611 | } | |
11612 | ||
1c444d06 JM |
11613 | static void |
11614 | do_t_orn (void) | |
11615 | { | |
11616 | unsigned Rd, Rn; | |
11617 | ||
11618 | Rd = inst.operands[0].reg; | |
11619 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
11620 | ||
fdfde340 JM |
11621 | reject_bad_reg (Rd); |
11622 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
11623 | reject_bad_reg (Rn); | |
11624 | ||
1c444d06 JM |
11625 | inst.instruction |= Rd << 8; |
11626 | inst.instruction |= Rn << 16; | |
11627 | ||
11628 | if (!inst.operands[2].isreg) | |
11629 | { | |
11630 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11631 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
11632 | } | |
11633 | else | |
11634 | { | |
11635 | unsigned Rm; | |
11636 | ||
11637 | Rm = inst.operands[2].reg; | |
fdfde340 | 11638 | reject_bad_reg (Rm); |
1c444d06 JM |
11639 | |
11640 | constraint (inst.operands[2].shifted | |
11641 | && inst.operands[2].immisreg, | |
11642 | _("shift must be constant")); | |
11643 | encode_thumb32_shifted_operand (2); | |
11644 | } | |
11645 | } | |
11646 | ||
c19d1205 ZW |
11647 | static void |
11648 | do_t_pkhbt (void) | |
11649 | { | |
fdfde340 JM |
11650 | unsigned Rd, Rn, Rm; |
11651 | ||
11652 | Rd = inst.operands[0].reg; | |
11653 | Rn = inst.operands[1].reg; | |
11654 | Rm = inst.operands[2].reg; | |
11655 | ||
11656 | reject_bad_reg (Rd); | |
11657 | reject_bad_reg (Rn); | |
11658 | reject_bad_reg (Rm); | |
11659 | ||
11660 | inst.instruction |= Rd << 8; | |
11661 | inst.instruction |= Rn << 16; | |
11662 | inst.instruction |= Rm; | |
c19d1205 ZW |
11663 | if (inst.operands[3].present) |
11664 | { | |
11665 | unsigned int val = inst.reloc.exp.X_add_number; | |
11666 | constraint (inst.reloc.exp.X_op != O_constant, | |
11667 | _("expression too complex")); | |
11668 | inst.instruction |= (val & 0x1c) << 10; | |
11669 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 11670 | } |
c19d1205 | 11671 | } |
b05fe5cf | 11672 | |
c19d1205 ZW |
11673 | static void |
11674 | do_t_pkhtb (void) | |
11675 | { | |
11676 | if (!inst.operands[3].present) | |
1ef52f49 NC |
11677 | { |
11678 | unsigned Rtmp; | |
11679 | ||
11680 | inst.instruction &= ~0x00000020; | |
11681 | ||
11682 | /* PR 10168. Swap the Rm and Rn registers. */ | |
11683 | Rtmp = inst.operands[1].reg; | |
11684 | inst.operands[1].reg = inst.operands[2].reg; | |
11685 | inst.operands[2].reg = Rtmp; | |
11686 | } | |
c19d1205 | 11687 | do_t_pkhbt (); |
b05fe5cf ZW |
11688 | } |
11689 | ||
c19d1205 ZW |
11690 | static void |
11691 | do_t_pld (void) | |
11692 | { | |
fdfde340 JM |
11693 | if (inst.operands[0].immisreg) |
11694 | reject_bad_reg (inst.operands[0].imm); | |
11695 | ||
c19d1205 ZW |
11696 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
11697 | } | |
b05fe5cf | 11698 | |
c19d1205 ZW |
11699 | static void |
11700 | do_t_push_pop (void) | |
b99bd4ef | 11701 | { |
e9f89963 | 11702 | unsigned mask; |
5f4273c7 | 11703 | |
c19d1205 ZW |
11704 | constraint (inst.operands[0].writeback, |
11705 | _("push/pop do not support {reglist}^")); | |
11706 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
11707 | _("expression too complex")); | |
b99bd4ef | 11708 | |
e9f89963 PB |
11709 | mask = inst.operands[0].imm; |
11710 | if ((mask & ~0xff) == 0) | |
3c707909 | 11711 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
c19d1205 | 11712 | else if ((inst.instruction == T_MNEM_push |
e9f89963 | 11713 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 11714 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 11715 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 11716 | { |
c19d1205 ZW |
11717 | inst.instruction = THUMB_OP16 (inst.instruction); |
11718 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 11719 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
11720 | } |
11721 | else if (unified_syntax) | |
11722 | { | |
3c707909 | 11723 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 11724 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
11725 | } |
11726 | else | |
11727 | { | |
11728 | inst.error = _("invalid register list to push/pop instruction"); | |
11729 | return; | |
11730 | } | |
c19d1205 | 11731 | } |
b99bd4ef | 11732 | |
c19d1205 ZW |
11733 | static void |
11734 | do_t_rbit (void) | |
11735 | { | |
fdfde340 JM |
11736 | unsigned Rd, Rm; |
11737 | ||
11738 | Rd = inst.operands[0].reg; | |
11739 | Rm = inst.operands[1].reg; | |
11740 | ||
11741 | reject_bad_reg (Rd); | |
11742 | reject_bad_reg (Rm); | |
11743 | ||
11744 | inst.instruction |= Rd << 8; | |
11745 | inst.instruction |= Rm << 16; | |
11746 | inst.instruction |= Rm; | |
c19d1205 | 11747 | } |
b99bd4ef | 11748 | |
c19d1205 ZW |
11749 | static void |
11750 | do_t_rev (void) | |
11751 | { | |
fdfde340 JM |
11752 | unsigned Rd, Rm; |
11753 | ||
11754 | Rd = inst.operands[0].reg; | |
11755 | Rm = inst.operands[1].reg; | |
11756 | ||
11757 | reject_bad_reg (Rd); | |
11758 | reject_bad_reg (Rm); | |
11759 | ||
11760 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
11761 | && inst.size_req != 4) |
11762 | { | |
11763 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
11764 | inst.instruction |= Rd; |
11765 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11766 | } |
11767 | else if (unified_syntax) | |
11768 | { | |
11769 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11770 | inst.instruction |= Rd << 8; |
11771 | inst.instruction |= Rm << 16; | |
11772 | inst.instruction |= Rm; | |
c19d1205 ZW |
11773 | } |
11774 | else | |
11775 | inst.error = BAD_HIREG; | |
11776 | } | |
b99bd4ef | 11777 | |
1c444d06 JM |
11778 | static void |
11779 | do_t_rrx (void) | |
11780 | { | |
11781 | unsigned Rd, Rm; | |
11782 | ||
11783 | Rd = inst.operands[0].reg; | |
11784 | Rm = inst.operands[1].reg; | |
11785 | ||
fdfde340 JM |
11786 | reject_bad_reg (Rd); |
11787 | reject_bad_reg (Rm); | |
c921be7d | 11788 | |
1c444d06 JM |
11789 | inst.instruction |= Rd << 8; |
11790 | inst.instruction |= Rm; | |
11791 | } | |
11792 | ||
c19d1205 ZW |
11793 | static void |
11794 | do_t_rsb (void) | |
11795 | { | |
fdfde340 | 11796 | unsigned Rd, Rs; |
b99bd4ef | 11797 | |
c19d1205 ZW |
11798 | Rd = inst.operands[0].reg; |
11799 | Rs = (inst.operands[1].present | |
11800 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11801 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 11802 | |
fdfde340 JM |
11803 | reject_bad_reg (Rd); |
11804 | reject_bad_reg (Rs); | |
11805 | if (inst.operands[2].isreg) | |
11806 | reject_bad_reg (inst.operands[2].reg); | |
11807 | ||
c19d1205 ZW |
11808 | inst.instruction |= Rd << 8; |
11809 | inst.instruction |= Rs << 16; | |
11810 | if (!inst.operands[2].isreg) | |
11811 | { | |
026d3abb PB |
11812 | bfd_boolean narrow; |
11813 | ||
11814 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 11815 | narrow = !in_it_block (); |
026d3abb | 11816 | else |
e07e6e58 | 11817 | narrow = in_it_block (); |
026d3abb PB |
11818 | |
11819 | if (Rd > 7 || Rs > 7) | |
11820 | narrow = FALSE; | |
11821 | ||
11822 | if (inst.size_req == 4 || !unified_syntax) | |
11823 | narrow = FALSE; | |
11824 | ||
11825 | if (inst.reloc.exp.X_op != O_constant | |
11826 | || inst.reloc.exp.X_add_number != 0) | |
11827 | narrow = FALSE; | |
11828 | ||
11829 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
11830 | relaxation, but it doesn't seem worth the hassle. */ | |
11831 | if (narrow) | |
11832 | { | |
11833 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11834 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
11835 | inst.instruction |= Rs << 3; | |
11836 | inst.instruction |= Rd; | |
11837 | } | |
11838 | else | |
11839 | { | |
11840 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11841 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
11842 | } | |
c19d1205 ZW |
11843 | } |
11844 | else | |
11845 | encode_thumb32_shifted_operand (2); | |
11846 | } | |
b99bd4ef | 11847 | |
c19d1205 ZW |
11848 | static void |
11849 | do_t_setend (void) | |
11850 | { | |
12e37cbc MGD |
11851 | if (warn_on_deprecated |
11852 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
11853 | as_warn (_("setend use is deprecated for ARMv8")); | |
11854 | ||
e07e6e58 | 11855 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
11856 | if (inst.operands[0].imm) |
11857 | inst.instruction |= 0x8; | |
11858 | } | |
b99bd4ef | 11859 | |
c19d1205 ZW |
11860 | static void |
11861 | do_t_shift (void) | |
11862 | { | |
11863 | if (!inst.operands[1].present) | |
11864 | inst.operands[1].reg = inst.operands[0].reg; | |
11865 | ||
11866 | if (unified_syntax) | |
11867 | { | |
3d388997 PB |
11868 | bfd_boolean narrow; |
11869 | int shift_kind; | |
11870 | ||
11871 | switch (inst.instruction) | |
11872 | { | |
11873 | case T_MNEM_asr: | |
11874 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
11875 | case T_MNEM_lsl: | |
11876 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
11877 | case T_MNEM_lsr: | |
11878 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
11879 | case T_MNEM_ror: | |
11880 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
11881 | default: abort (); | |
11882 | } | |
11883 | ||
11884 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 11885 | narrow = !in_it_block (); |
3d388997 | 11886 | else |
e07e6e58 | 11887 | narrow = in_it_block (); |
3d388997 PB |
11888 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
11889 | narrow = FALSE; | |
11890 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
11891 | narrow = FALSE; | |
11892 | if (inst.operands[2].isreg | |
11893 | && (inst.operands[1].reg != inst.operands[0].reg | |
11894 | || inst.operands[2].reg > 7)) | |
11895 | narrow = FALSE; | |
11896 | if (inst.size_req == 4) | |
11897 | narrow = FALSE; | |
11898 | ||
fdfde340 JM |
11899 | reject_bad_reg (inst.operands[0].reg); |
11900 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 11901 | |
3d388997 | 11902 | if (!narrow) |
c19d1205 ZW |
11903 | { |
11904 | if (inst.operands[2].isreg) | |
b99bd4ef | 11905 | { |
fdfde340 | 11906 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
11907 | inst.instruction = THUMB_OP32 (inst.instruction); |
11908 | inst.instruction |= inst.operands[0].reg << 8; | |
11909 | inst.instruction |= inst.operands[1].reg << 16; | |
11910 | inst.instruction |= inst.operands[2].reg; | |
94342ec3 NC |
11911 | |
11912 | /* PR 12854: Error on extraneous shifts. */ | |
11913 | constraint (inst.operands[2].shifted, | |
11914 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
11915 | } |
11916 | else | |
11917 | { | |
11918 | inst.operands[1].shifted = 1; | |
3d388997 | 11919 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
11920 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
11921 | ? T_MNEM_movs : T_MNEM_mov); | |
11922 | inst.instruction |= inst.operands[0].reg << 8; | |
11923 | encode_thumb32_shifted_operand (1); | |
11924 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
11925 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
11926 | } |
11927 | } | |
11928 | else | |
11929 | { | |
c19d1205 | 11930 | if (inst.operands[2].isreg) |
b99bd4ef | 11931 | { |
3d388997 | 11932 | switch (shift_kind) |
b99bd4ef | 11933 | { |
3d388997 PB |
11934 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
11935 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
11936 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
11937 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 11938 | default: abort (); |
b99bd4ef | 11939 | } |
5f4273c7 | 11940 | |
c19d1205 ZW |
11941 | inst.instruction |= inst.operands[0].reg; |
11942 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
11943 | |
11944 | /* PR 12854: Error on extraneous shifts. */ | |
11945 | constraint (inst.operands[2].shifted, | |
11946 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
11947 | } |
11948 | else | |
11949 | { | |
3d388997 | 11950 | switch (shift_kind) |
b99bd4ef | 11951 | { |
3d388997 PB |
11952 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
11953 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
11954 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 11955 | default: abort (); |
b99bd4ef | 11956 | } |
c19d1205 ZW |
11957 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
11958 | inst.instruction |= inst.operands[0].reg; | |
11959 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
11960 | } |
11961 | } | |
c19d1205 ZW |
11962 | } |
11963 | else | |
11964 | { | |
11965 | constraint (inst.operands[0].reg > 7 | |
11966 | || inst.operands[1].reg > 7, BAD_HIREG); | |
11967 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 11968 | |
c19d1205 ZW |
11969 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
11970 | { | |
11971 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
11972 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
11973 | _("source1 and dest must be same register")); | |
b99bd4ef | 11974 | |
c19d1205 ZW |
11975 | switch (inst.instruction) |
11976 | { | |
11977 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
11978 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
11979 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
11980 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
11981 | default: abort (); | |
11982 | } | |
5f4273c7 | 11983 | |
c19d1205 ZW |
11984 | inst.instruction |= inst.operands[0].reg; |
11985 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
11986 | |
11987 | /* PR 12854: Error on extraneous shifts. */ | |
11988 | constraint (inst.operands[2].shifted, | |
11989 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
11990 | } |
11991 | else | |
b99bd4ef | 11992 | { |
c19d1205 ZW |
11993 | switch (inst.instruction) |
11994 | { | |
11995 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
11996 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
11997 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
11998 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
11999 | default: abort (); | |
12000 | } | |
12001 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
12002 | inst.instruction |= inst.operands[0].reg; | |
12003 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
12004 | } |
12005 | } | |
b99bd4ef NC |
12006 | } |
12007 | ||
12008 | static void | |
c19d1205 | 12009 | do_t_simd (void) |
b99bd4ef | 12010 | { |
fdfde340 JM |
12011 | unsigned Rd, Rn, Rm; |
12012 | ||
12013 | Rd = inst.operands[0].reg; | |
12014 | Rn = inst.operands[1].reg; | |
12015 | Rm = inst.operands[2].reg; | |
12016 | ||
12017 | reject_bad_reg (Rd); | |
12018 | reject_bad_reg (Rn); | |
12019 | reject_bad_reg (Rm); | |
12020 | ||
12021 | inst.instruction |= Rd << 8; | |
12022 | inst.instruction |= Rn << 16; | |
12023 | inst.instruction |= Rm; | |
c19d1205 | 12024 | } |
b99bd4ef | 12025 | |
03ee1b7f NC |
12026 | static void |
12027 | do_t_simd2 (void) | |
12028 | { | |
12029 | unsigned Rd, Rn, Rm; | |
12030 | ||
12031 | Rd = inst.operands[0].reg; | |
12032 | Rm = inst.operands[1].reg; | |
12033 | Rn = inst.operands[2].reg; | |
12034 | ||
12035 | reject_bad_reg (Rd); | |
12036 | reject_bad_reg (Rn); | |
12037 | reject_bad_reg (Rm); | |
12038 | ||
12039 | inst.instruction |= Rd << 8; | |
12040 | inst.instruction |= Rn << 16; | |
12041 | inst.instruction |= Rm; | |
12042 | } | |
12043 | ||
c19d1205 | 12044 | static void |
3eb17e6b | 12045 | do_t_smc (void) |
c19d1205 ZW |
12046 | { |
12047 | unsigned int value = inst.reloc.exp.X_add_number; | |
f4c65163 MGD |
12048 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
12049 | _("SMC is not permitted on this architecture")); | |
c19d1205 ZW |
12050 | constraint (inst.reloc.exp.X_op != O_constant, |
12051 | _("expression too complex")); | |
12052 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12053 | inst.instruction |= (value & 0xf000) >> 12; | |
12054 | inst.instruction |= (value & 0x0ff0); | |
12055 | inst.instruction |= (value & 0x000f) << 16; | |
12056 | } | |
b99bd4ef | 12057 | |
90ec0d68 MGD |
12058 | static void |
12059 | do_t_hvc (void) | |
12060 | { | |
12061 | unsigned int value = inst.reloc.exp.X_add_number; | |
12062 | ||
12063 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12064 | inst.instruction |= (value & 0x0fff); | |
12065 | inst.instruction |= (value & 0xf000) << 4; | |
12066 | } | |
12067 | ||
c19d1205 | 12068 | static void |
3a21c15a | 12069 | do_t_ssat_usat (int bias) |
c19d1205 | 12070 | { |
fdfde340 JM |
12071 | unsigned Rd, Rn; |
12072 | ||
12073 | Rd = inst.operands[0].reg; | |
12074 | Rn = inst.operands[2].reg; | |
12075 | ||
12076 | reject_bad_reg (Rd); | |
12077 | reject_bad_reg (Rn); | |
12078 | ||
12079 | inst.instruction |= Rd << 8; | |
3a21c15a | 12080 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 12081 | inst.instruction |= Rn << 16; |
b99bd4ef | 12082 | |
c19d1205 | 12083 | if (inst.operands[3].present) |
b99bd4ef | 12084 | { |
3a21c15a NC |
12085 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
12086 | ||
12087 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12088 | ||
c19d1205 ZW |
12089 | constraint (inst.reloc.exp.X_op != O_constant, |
12090 | _("expression too complex")); | |
b99bd4ef | 12091 | |
3a21c15a | 12092 | if (shift_amount != 0) |
6189168b | 12093 | { |
3a21c15a NC |
12094 | constraint (shift_amount > 31, |
12095 | _("shift expression is too large")); | |
12096 | ||
c19d1205 | 12097 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
12098 | inst.instruction |= 0x00200000; /* sh bit. */ |
12099 | ||
12100 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
12101 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
12102 | } |
12103 | } | |
b99bd4ef | 12104 | } |
c921be7d | 12105 | |
3a21c15a NC |
12106 | static void |
12107 | do_t_ssat (void) | |
12108 | { | |
12109 | do_t_ssat_usat (1); | |
12110 | } | |
b99bd4ef | 12111 | |
0dd132b6 | 12112 | static void |
c19d1205 | 12113 | do_t_ssat16 (void) |
0dd132b6 | 12114 | { |
fdfde340 JM |
12115 | unsigned Rd, Rn; |
12116 | ||
12117 | Rd = inst.operands[0].reg; | |
12118 | Rn = inst.operands[2].reg; | |
12119 | ||
12120 | reject_bad_reg (Rd); | |
12121 | reject_bad_reg (Rn); | |
12122 | ||
12123 | inst.instruction |= Rd << 8; | |
c19d1205 | 12124 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 12125 | inst.instruction |= Rn << 16; |
c19d1205 | 12126 | } |
0dd132b6 | 12127 | |
c19d1205 ZW |
12128 | static void |
12129 | do_t_strex (void) | |
12130 | { | |
12131 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
12132 | || inst.operands[2].postind || inst.operands[2].writeback | |
12133 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
12134 | || inst.operands[2].negative, | |
01cfc07f | 12135 | BAD_ADDR_MODE); |
0dd132b6 | 12136 | |
5be8be5d DG |
12137 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
12138 | ||
c19d1205 ZW |
12139 | inst.instruction |= inst.operands[0].reg << 8; |
12140 | inst.instruction |= inst.operands[1].reg << 12; | |
12141 | inst.instruction |= inst.operands[2].reg << 16; | |
12142 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
12143 | } |
12144 | ||
b99bd4ef | 12145 | static void |
c19d1205 | 12146 | do_t_strexd (void) |
b99bd4ef | 12147 | { |
c19d1205 ZW |
12148 | if (!inst.operands[2].present) |
12149 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 12150 | |
c19d1205 ZW |
12151 | constraint (inst.operands[0].reg == inst.operands[1].reg |
12152 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 12153 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 12154 | BAD_OVERLAP); |
b99bd4ef | 12155 | |
c19d1205 ZW |
12156 | inst.instruction |= inst.operands[0].reg; |
12157 | inst.instruction |= inst.operands[1].reg << 12; | |
12158 | inst.instruction |= inst.operands[2].reg << 8; | |
12159 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
12160 | } |
12161 | ||
12162 | static void | |
c19d1205 | 12163 | do_t_sxtah (void) |
b99bd4ef | 12164 | { |
fdfde340 JM |
12165 | unsigned Rd, Rn, Rm; |
12166 | ||
12167 | Rd = inst.operands[0].reg; | |
12168 | Rn = inst.operands[1].reg; | |
12169 | Rm = inst.operands[2].reg; | |
12170 | ||
12171 | reject_bad_reg (Rd); | |
12172 | reject_bad_reg (Rn); | |
12173 | reject_bad_reg (Rm); | |
12174 | ||
12175 | inst.instruction |= Rd << 8; | |
12176 | inst.instruction |= Rn << 16; | |
12177 | inst.instruction |= Rm; | |
c19d1205 ZW |
12178 | inst.instruction |= inst.operands[3].imm << 4; |
12179 | } | |
b99bd4ef | 12180 | |
c19d1205 ZW |
12181 | static void |
12182 | do_t_sxth (void) | |
12183 | { | |
fdfde340 JM |
12184 | unsigned Rd, Rm; |
12185 | ||
12186 | Rd = inst.operands[0].reg; | |
12187 | Rm = inst.operands[1].reg; | |
12188 | ||
12189 | reject_bad_reg (Rd); | |
12190 | reject_bad_reg (Rm); | |
c921be7d NC |
12191 | |
12192 | if (inst.instruction <= 0xffff | |
12193 | && inst.size_req != 4 | |
fdfde340 | 12194 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 12195 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 12196 | { |
c19d1205 | 12197 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12198 | inst.instruction |= Rd; |
12199 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12200 | } |
c19d1205 | 12201 | else if (unified_syntax) |
b99bd4ef | 12202 | { |
c19d1205 ZW |
12203 | if (inst.instruction <= 0xffff) |
12204 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12205 | inst.instruction |= Rd << 8; |
12206 | inst.instruction |= Rm; | |
c19d1205 | 12207 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 12208 | } |
c19d1205 | 12209 | else |
b99bd4ef | 12210 | { |
c19d1205 ZW |
12211 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
12212 | _("Thumb encoding does not support rotation")); | |
12213 | constraint (1, BAD_HIREG); | |
b99bd4ef | 12214 | } |
c19d1205 | 12215 | } |
b99bd4ef | 12216 | |
c19d1205 ZW |
12217 | static void |
12218 | do_t_swi (void) | |
12219 | { | |
b2a5fbdc MGD |
12220 | /* We have to do the following check manually as ARM_EXT_OS only applies |
12221 | to ARM_EXT_V6M. */ | |
12222 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m)) | |
12223 | { | |
ac7f631b NC |
12224 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os) |
12225 | /* This only applies to the v6m howver, not later architectures. */ | |
12226 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)) | |
b2a5fbdc MGD |
12227 | as_bad (_("SVC is not permitted on this architecture")); |
12228 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os); | |
12229 | } | |
12230 | ||
c19d1205 ZW |
12231 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
12232 | } | |
b99bd4ef | 12233 | |
92e90b6e PB |
12234 | static void |
12235 | do_t_tb (void) | |
12236 | { | |
fdfde340 | 12237 | unsigned Rn, Rm; |
92e90b6e PB |
12238 | int half; |
12239 | ||
12240 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 12241 | set_it_insn_type_last (); |
dfa9f0d5 PB |
12242 | constraint (inst.operands[0].immisreg, |
12243 | _("instruction requires register index")); | |
fdfde340 JM |
12244 | |
12245 | Rn = inst.operands[0].reg; | |
12246 | Rm = inst.operands[0].imm; | |
c921be7d | 12247 | |
fdfde340 JM |
12248 | constraint (Rn == REG_SP, BAD_SP); |
12249 | reject_bad_reg (Rm); | |
12250 | ||
92e90b6e PB |
12251 | constraint (!half && inst.operands[0].shifted, |
12252 | _("instruction does not allow shifted index")); | |
fdfde340 | 12253 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
12254 | } |
12255 | ||
c19d1205 ZW |
12256 | static void |
12257 | do_t_usat (void) | |
12258 | { | |
3a21c15a | 12259 | do_t_ssat_usat (0); |
b99bd4ef NC |
12260 | } |
12261 | ||
12262 | static void | |
c19d1205 | 12263 | do_t_usat16 (void) |
b99bd4ef | 12264 | { |
fdfde340 JM |
12265 | unsigned Rd, Rn; |
12266 | ||
12267 | Rd = inst.operands[0].reg; | |
12268 | Rn = inst.operands[2].reg; | |
12269 | ||
12270 | reject_bad_reg (Rd); | |
12271 | reject_bad_reg (Rn); | |
12272 | ||
12273 | inst.instruction |= Rd << 8; | |
c19d1205 | 12274 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 12275 | inst.instruction |= Rn << 16; |
b99bd4ef | 12276 | } |
c19d1205 | 12277 | |
5287ad62 | 12278 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 12279 | |
5287ad62 | 12280 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 12281 | |
5287ad62 JB |
12282 | /* An "invalid" code for the following tables. */ |
12283 | #define N_INV -1u | |
12284 | ||
12285 | struct neon_tab_entry | |
b99bd4ef | 12286 | { |
5287ad62 JB |
12287 | unsigned integer; |
12288 | unsigned float_or_poly; | |
12289 | unsigned scalar_or_imm; | |
12290 | }; | |
5f4273c7 | 12291 | |
5287ad62 JB |
12292 | /* Map overloaded Neon opcodes to their respective encodings. */ |
12293 | #define NEON_ENC_TAB \ | |
12294 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
12295 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
12296 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
12297 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
12298 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
12299 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
12300 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
12301 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
12302 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
12303 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
12304 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
12305 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 12306 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
12307 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
12308 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
12309 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
12310 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
12311 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
12312 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
12313 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
12314 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
12315 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
12316 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
12317 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
12318 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
12319 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
12320 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
12321 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
12322 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
12323 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
12324 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
12325 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
12326 | X(veor, 0x1000110, N_INV, N_INV), \ | |
12327 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
12328 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
12329 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
12330 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
12331 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
12332 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
12333 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
12334 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
12335 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
12336 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
12337 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
12338 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
12339 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
12340 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
12341 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
12342 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
12343 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
12344 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
12345 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
12346 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
12347 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
12348 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
12349 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
12350 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
12351 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
12352 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
12353 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \ |
12354 | X(vseleq, 0xe000a00, N_INV, N_INV), \ | |
12355 | X(vselvs, 0xe100a00, N_INV, N_INV), \ | |
12356 | X(vselge, 0xe200a00, N_INV, N_INV), \ | |
73924fbc MGD |
12357 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
12358 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 12359 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
12360 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
12361 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 12362 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 12363 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
12364 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
12365 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
12366 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
12367 | |
12368 | enum neon_opc | |
12369 | { | |
12370 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
12371 | NEON_ENC_TAB | |
12372 | #undef X | |
12373 | }; | |
b99bd4ef | 12374 | |
5287ad62 JB |
12375 | static const struct neon_tab_entry neon_enc_tab[] = |
12376 | { | |
12377 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
12378 | NEON_ENC_TAB | |
12379 | #undef X | |
12380 | }; | |
b99bd4ef | 12381 | |
88714cb8 DG |
12382 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
12383 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
12384 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
12385 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
12386 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
12387 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
12388 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
12389 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
12390 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
12391 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
12392 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 12393 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 12394 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 12395 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
12396 | #define NEON_ENC_FPV8_(X) \ |
12397 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 12398 | |
88714cb8 DG |
12399 | #define NEON_ENCODE(type, inst) \ |
12400 | do \ | |
12401 | { \ | |
12402 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
12403 | inst.is_neon = 1; \ | |
12404 | } \ | |
12405 | while (0) | |
12406 | ||
12407 | #define check_neon_suffixes \ | |
12408 | do \ | |
12409 | { \ | |
12410 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
12411 | { \ | |
12412 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
12413 | return; \ | |
12414 | } \ | |
12415 | } \ | |
12416 | while (0) | |
12417 | ||
037e8744 JB |
12418 | /* Define shapes for instruction operands. The following mnemonic characters |
12419 | are used in this table: | |
5287ad62 | 12420 | |
037e8744 | 12421 | F - VFP S<n> register |
5287ad62 JB |
12422 | D - Neon D<n> register |
12423 | Q - Neon Q<n> register | |
12424 | I - Immediate | |
12425 | S - Scalar | |
12426 | R - ARM register | |
12427 | L - D<n> register list | |
5f4273c7 | 12428 | |
037e8744 JB |
12429 | This table is used to generate various data: |
12430 | - enumerations of the form NS_DDR to be used as arguments to | |
12431 | neon_select_shape. | |
12432 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 12433 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 12434 | |
037e8744 JB |
12435 | #define NEON_SHAPE_DEF \ |
12436 | X(3, (D, D, D), DOUBLE), \ | |
12437 | X(3, (Q, Q, Q), QUAD), \ | |
12438 | X(3, (D, D, I), DOUBLE), \ | |
12439 | X(3, (Q, Q, I), QUAD), \ | |
12440 | X(3, (D, D, S), DOUBLE), \ | |
12441 | X(3, (Q, Q, S), QUAD), \ | |
12442 | X(2, (D, D), DOUBLE), \ | |
12443 | X(2, (Q, Q), QUAD), \ | |
12444 | X(2, (D, S), DOUBLE), \ | |
12445 | X(2, (Q, S), QUAD), \ | |
12446 | X(2, (D, R), DOUBLE), \ | |
12447 | X(2, (Q, R), QUAD), \ | |
12448 | X(2, (D, I), DOUBLE), \ | |
12449 | X(2, (Q, I), QUAD), \ | |
12450 | X(3, (D, L, D), DOUBLE), \ | |
12451 | X(2, (D, Q), MIXED), \ | |
12452 | X(2, (Q, D), MIXED), \ | |
12453 | X(3, (D, Q, I), MIXED), \ | |
12454 | X(3, (Q, D, I), MIXED), \ | |
12455 | X(3, (Q, D, D), MIXED), \ | |
12456 | X(3, (D, Q, Q), MIXED), \ | |
12457 | X(3, (Q, Q, D), MIXED), \ | |
12458 | X(3, (Q, D, S), MIXED), \ | |
12459 | X(3, (D, Q, S), MIXED), \ | |
12460 | X(4, (D, D, D, I), DOUBLE), \ | |
12461 | X(4, (Q, Q, Q, I), QUAD), \ | |
12462 | X(2, (F, F), SINGLE), \ | |
12463 | X(3, (F, F, F), SINGLE), \ | |
12464 | X(2, (F, I), SINGLE), \ | |
12465 | X(2, (F, D), MIXED), \ | |
12466 | X(2, (D, F), MIXED), \ | |
12467 | X(3, (F, F, I), MIXED), \ | |
12468 | X(4, (R, R, F, F), SINGLE), \ | |
12469 | X(4, (F, F, R, R), SINGLE), \ | |
12470 | X(3, (D, R, R), DOUBLE), \ | |
12471 | X(3, (R, R, D), DOUBLE), \ | |
12472 | X(2, (S, R), SINGLE), \ | |
12473 | X(2, (R, S), SINGLE), \ | |
12474 | X(2, (F, R), SINGLE), \ | |
12475 | X(2, (R, F), SINGLE) | |
12476 | ||
12477 | #define S2(A,B) NS_##A##B | |
12478 | #define S3(A,B,C) NS_##A##B##C | |
12479 | #define S4(A,B,C,D) NS_##A##B##C##D | |
12480 | ||
12481 | #define X(N, L, C) S##N L | |
12482 | ||
5287ad62 JB |
12483 | enum neon_shape |
12484 | { | |
037e8744 JB |
12485 | NEON_SHAPE_DEF, |
12486 | NS_NULL | |
5287ad62 | 12487 | }; |
b99bd4ef | 12488 | |
037e8744 JB |
12489 | #undef X |
12490 | #undef S2 | |
12491 | #undef S3 | |
12492 | #undef S4 | |
12493 | ||
12494 | enum neon_shape_class | |
12495 | { | |
12496 | SC_SINGLE, | |
12497 | SC_DOUBLE, | |
12498 | SC_QUAD, | |
12499 | SC_MIXED | |
12500 | }; | |
12501 | ||
12502 | #define X(N, L, C) SC_##C | |
12503 | ||
12504 | static enum neon_shape_class neon_shape_class[] = | |
12505 | { | |
12506 | NEON_SHAPE_DEF | |
12507 | }; | |
12508 | ||
12509 | #undef X | |
12510 | ||
12511 | enum neon_shape_el | |
12512 | { | |
12513 | SE_F, | |
12514 | SE_D, | |
12515 | SE_Q, | |
12516 | SE_I, | |
12517 | SE_S, | |
12518 | SE_R, | |
12519 | SE_L | |
12520 | }; | |
12521 | ||
12522 | /* Register widths of above. */ | |
12523 | static unsigned neon_shape_el_size[] = | |
12524 | { | |
12525 | 32, | |
12526 | 64, | |
12527 | 128, | |
12528 | 0, | |
12529 | 32, | |
12530 | 32, | |
12531 | 0 | |
12532 | }; | |
12533 | ||
12534 | struct neon_shape_info | |
12535 | { | |
12536 | unsigned els; | |
12537 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
12538 | }; | |
12539 | ||
12540 | #define S2(A,B) { SE_##A, SE_##B } | |
12541 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
12542 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
12543 | ||
12544 | #define X(N, L, C) { N, S##N L } | |
12545 | ||
12546 | static struct neon_shape_info neon_shape_tab[] = | |
12547 | { | |
12548 | NEON_SHAPE_DEF | |
12549 | }; | |
12550 | ||
12551 | #undef X | |
12552 | #undef S2 | |
12553 | #undef S3 | |
12554 | #undef S4 | |
12555 | ||
5287ad62 JB |
12556 | /* Bit masks used in type checking given instructions. |
12557 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
12558 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
12559 | set, various other bits can be set as well in order to modify the meaning of | |
12560 | the type constraint. */ | |
12561 | ||
12562 | enum neon_type_mask | |
12563 | { | |
8e79c3df CM |
12564 | N_S8 = 0x0000001, |
12565 | N_S16 = 0x0000002, | |
12566 | N_S32 = 0x0000004, | |
12567 | N_S64 = 0x0000008, | |
12568 | N_U8 = 0x0000010, | |
12569 | N_U16 = 0x0000020, | |
12570 | N_U32 = 0x0000040, | |
12571 | N_U64 = 0x0000080, | |
12572 | N_I8 = 0x0000100, | |
12573 | N_I16 = 0x0000200, | |
12574 | N_I32 = 0x0000400, | |
12575 | N_I64 = 0x0000800, | |
12576 | N_8 = 0x0001000, | |
12577 | N_16 = 0x0002000, | |
12578 | N_32 = 0x0004000, | |
12579 | N_64 = 0x0008000, | |
12580 | N_P8 = 0x0010000, | |
12581 | N_P16 = 0x0020000, | |
12582 | N_F16 = 0x0040000, | |
12583 | N_F32 = 0x0080000, | |
12584 | N_F64 = 0x0100000, | |
4f51b4bd | 12585 | N_P64 = 0x0200000, |
c921be7d NC |
12586 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
12587 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 12588 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 12589 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
12590 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
12591 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
12592 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
12593 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
12594 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
12595 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
12596 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 12597 | N_UTYP = 0, |
4f51b4bd | 12598 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
12599 | }; |
12600 | ||
dcbf9037 JB |
12601 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
12602 | ||
5287ad62 JB |
12603 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
12604 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
12605 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
12606 | #define N_SUF_32 (N_SU_32 | N_F32) | |
12607 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
12608 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
12609 | ||
12610 | /* Pass this as the first type argument to neon_check_type to ignore types | |
12611 | altogether. */ | |
12612 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
12613 | ||
037e8744 JB |
12614 | /* Select a "shape" for the current instruction (describing register types or |
12615 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
12616 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
12617 | function of operand parsing, so this function doesn't need to be called. | |
12618 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
12619 | |
12620 | static enum neon_shape | |
037e8744 | 12621 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 12622 | { |
037e8744 JB |
12623 | va_list ap; |
12624 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
12625 | |
12626 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
12627 | many arguments we should have, so this makes the assumption that we have | |
12628 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
12629 | true in the future. */ | |
12630 | if (!inst.operands[1].present) | |
12631 | inst.operands[1] = inst.operands[0]; | |
12632 | ||
037e8744 | 12633 | va_start (ap, shape); |
5f4273c7 | 12634 | |
21d799b5 | 12635 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
12636 | { |
12637 | unsigned j; | |
12638 | int matches = 1; | |
12639 | ||
12640 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
12641 | { | |
12642 | if (!inst.operands[j].present) | |
12643 | { | |
12644 | matches = 0; | |
12645 | break; | |
12646 | } | |
12647 | ||
12648 | switch (neon_shape_tab[shape].el[j]) | |
12649 | { | |
12650 | case SE_F: | |
12651 | if (!(inst.operands[j].isreg | |
12652 | && inst.operands[j].isvec | |
12653 | && inst.operands[j].issingle | |
12654 | && !inst.operands[j].isquad)) | |
12655 | matches = 0; | |
12656 | break; | |
12657 | ||
12658 | case SE_D: | |
12659 | if (!(inst.operands[j].isreg | |
12660 | && inst.operands[j].isvec | |
12661 | && !inst.operands[j].isquad | |
12662 | && !inst.operands[j].issingle)) | |
12663 | matches = 0; | |
12664 | break; | |
12665 | ||
12666 | case SE_R: | |
12667 | if (!(inst.operands[j].isreg | |
12668 | && !inst.operands[j].isvec)) | |
12669 | matches = 0; | |
12670 | break; | |
12671 | ||
12672 | case SE_Q: | |
12673 | if (!(inst.operands[j].isreg | |
12674 | && inst.operands[j].isvec | |
12675 | && inst.operands[j].isquad | |
12676 | && !inst.operands[j].issingle)) | |
12677 | matches = 0; | |
12678 | break; | |
12679 | ||
12680 | case SE_I: | |
12681 | if (!(!inst.operands[j].isreg | |
12682 | && !inst.operands[j].isscalar)) | |
12683 | matches = 0; | |
12684 | break; | |
12685 | ||
12686 | case SE_S: | |
12687 | if (!(!inst.operands[j].isreg | |
12688 | && inst.operands[j].isscalar)) | |
12689 | matches = 0; | |
12690 | break; | |
12691 | ||
12692 | case SE_L: | |
12693 | break; | |
12694 | } | |
3fde54a2 JZ |
12695 | if (!matches) |
12696 | break; | |
037e8744 | 12697 | } |
ad6cec43 MGD |
12698 | if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present)) |
12699 | /* We've matched all the entries in the shape table, and we don't | |
12700 | have any left over operands which have not been matched. */ | |
5287ad62 | 12701 | break; |
037e8744 | 12702 | } |
5f4273c7 | 12703 | |
037e8744 | 12704 | va_end (ap); |
5287ad62 | 12705 | |
037e8744 JB |
12706 | if (shape == NS_NULL && first_shape != NS_NULL) |
12707 | first_error (_("invalid instruction shape")); | |
5287ad62 | 12708 | |
037e8744 JB |
12709 | return shape; |
12710 | } | |
5287ad62 | 12711 | |
037e8744 JB |
12712 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
12713 | means the Q bit should be set). */ | |
12714 | ||
12715 | static int | |
12716 | neon_quad (enum neon_shape shape) | |
12717 | { | |
12718 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 12719 | } |
037e8744 | 12720 | |
5287ad62 JB |
12721 | static void |
12722 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
12723 | unsigned *g_size) | |
12724 | { | |
12725 | /* Allow modification to be made to types which are constrained to be | |
12726 | based on the key element, based on bits set alongside N_EQK. */ | |
12727 | if ((typebits & N_EQK) != 0) | |
12728 | { | |
12729 | if ((typebits & N_HLF) != 0) | |
12730 | *g_size /= 2; | |
12731 | else if ((typebits & N_DBL) != 0) | |
12732 | *g_size *= 2; | |
12733 | if ((typebits & N_SGN) != 0) | |
12734 | *g_type = NT_signed; | |
12735 | else if ((typebits & N_UNS) != 0) | |
12736 | *g_type = NT_unsigned; | |
12737 | else if ((typebits & N_INT) != 0) | |
12738 | *g_type = NT_integer; | |
12739 | else if ((typebits & N_FLT) != 0) | |
12740 | *g_type = NT_float; | |
dcbf9037 JB |
12741 | else if ((typebits & N_SIZ) != 0) |
12742 | *g_type = NT_untyped; | |
5287ad62 JB |
12743 | } |
12744 | } | |
5f4273c7 | 12745 | |
5287ad62 JB |
12746 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
12747 | operand type, i.e. the single type specified in a Neon instruction when it | |
12748 | is the only one given. */ | |
12749 | ||
12750 | static struct neon_type_el | |
12751 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
12752 | { | |
12753 | struct neon_type_el dest = *key; | |
5f4273c7 | 12754 | |
9c2799c2 | 12755 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 12756 | |
5287ad62 JB |
12757 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
12758 | ||
12759 | return dest; | |
12760 | } | |
12761 | ||
12762 | /* Convert Neon type and size into compact bitmask representation. */ | |
12763 | ||
12764 | static enum neon_type_mask | |
12765 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
12766 | { | |
12767 | switch (type) | |
12768 | { | |
12769 | case NT_untyped: | |
12770 | switch (size) | |
12771 | { | |
12772 | case 8: return N_8; | |
12773 | case 16: return N_16; | |
12774 | case 32: return N_32; | |
12775 | case 64: return N_64; | |
12776 | default: ; | |
12777 | } | |
12778 | break; | |
12779 | ||
12780 | case NT_integer: | |
12781 | switch (size) | |
12782 | { | |
12783 | case 8: return N_I8; | |
12784 | case 16: return N_I16; | |
12785 | case 32: return N_I32; | |
12786 | case 64: return N_I64; | |
12787 | default: ; | |
12788 | } | |
12789 | break; | |
12790 | ||
12791 | case NT_float: | |
037e8744 JB |
12792 | switch (size) |
12793 | { | |
8e79c3df | 12794 | case 16: return N_F16; |
037e8744 JB |
12795 | case 32: return N_F32; |
12796 | case 64: return N_F64; | |
12797 | default: ; | |
12798 | } | |
5287ad62 JB |
12799 | break; |
12800 | ||
12801 | case NT_poly: | |
12802 | switch (size) | |
12803 | { | |
12804 | case 8: return N_P8; | |
12805 | case 16: return N_P16; | |
4f51b4bd | 12806 | case 64: return N_P64; |
5287ad62 JB |
12807 | default: ; |
12808 | } | |
12809 | break; | |
12810 | ||
12811 | case NT_signed: | |
12812 | switch (size) | |
12813 | { | |
12814 | case 8: return N_S8; | |
12815 | case 16: return N_S16; | |
12816 | case 32: return N_S32; | |
12817 | case 64: return N_S64; | |
12818 | default: ; | |
12819 | } | |
12820 | break; | |
12821 | ||
12822 | case NT_unsigned: | |
12823 | switch (size) | |
12824 | { | |
12825 | case 8: return N_U8; | |
12826 | case 16: return N_U16; | |
12827 | case 32: return N_U32; | |
12828 | case 64: return N_U64; | |
12829 | default: ; | |
12830 | } | |
12831 | break; | |
12832 | ||
12833 | default: ; | |
12834 | } | |
5f4273c7 | 12835 | |
5287ad62 JB |
12836 | return N_UTYP; |
12837 | } | |
12838 | ||
12839 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
12840 | handles the case where a single bit is set in the mask. */ | |
12841 | ||
dcbf9037 | 12842 | static int |
5287ad62 JB |
12843 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
12844 | enum neon_type_mask mask) | |
12845 | { | |
dcbf9037 JB |
12846 | if ((mask & N_EQK) != 0) |
12847 | return FAIL; | |
12848 | ||
5287ad62 JB |
12849 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
12850 | *size = 8; | |
c70a8987 | 12851 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0) |
5287ad62 | 12852 | *size = 16; |
dcbf9037 | 12853 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 12854 | *size = 32; |
4f51b4bd | 12855 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 12856 | *size = 64; |
dcbf9037 JB |
12857 | else |
12858 | return FAIL; | |
12859 | ||
5287ad62 JB |
12860 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
12861 | *type = NT_signed; | |
dcbf9037 | 12862 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 12863 | *type = NT_unsigned; |
dcbf9037 | 12864 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 12865 | *type = NT_integer; |
dcbf9037 | 12866 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 12867 | *type = NT_untyped; |
4f51b4bd | 12868 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 12869 | *type = NT_poly; |
c70a8987 | 12870 | else if ((mask & (N_F16 | N_F32 | N_F64)) != 0) |
5287ad62 | 12871 | *type = NT_float; |
dcbf9037 JB |
12872 | else |
12873 | return FAIL; | |
5f4273c7 | 12874 | |
dcbf9037 | 12875 | return SUCCESS; |
5287ad62 JB |
12876 | } |
12877 | ||
12878 | /* Modify a bitmask of allowed types. This is only needed for type | |
12879 | relaxation. */ | |
12880 | ||
12881 | static unsigned | |
12882 | modify_types_allowed (unsigned allowed, unsigned mods) | |
12883 | { | |
12884 | unsigned size; | |
12885 | enum neon_el_type type; | |
12886 | unsigned destmask; | |
12887 | int i; | |
5f4273c7 | 12888 | |
5287ad62 | 12889 | destmask = 0; |
5f4273c7 | 12890 | |
5287ad62 JB |
12891 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
12892 | { | |
21d799b5 NC |
12893 | if (el_type_of_type_chk (&type, &size, |
12894 | (enum neon_type_mask) (allowed & i)) == SUCCESS) | |
dcbf9037 JB |
12895 | { |
12896 | neon_modify_type_size (mods, &type, &size); | |
12897 | destmask |= type_chk_of_el_type (type, size); | |
12898 | } | |
5287ad62 | 12899 | } |
5f4273c7 | 12900 | |
5287ad62 JB |
12901 | return destmask; |
12902 | } | |
12903 | ||
12904 | /* Check type and return type classification. | |
12905 | The manual states (paraphrase): If one datatype is given, it indicates the | |
12906 | type given in: | |
12907 | - the second operand, if there is one | |
12908 | - the operand, if there is no second operand | |
12909 | - the result, if there are no operands. | |
12910 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
12911 | which is set on a per-instruction basis, which is the one which matters when | |
12912 | only one data type is written. | |
12913 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 12914 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
12915 | |
12916 | static struct neon_type_el | |
12917 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
12918 | { | |
12919 | va_list ap; | |
12920 | unsigned i, pass, key_el = 0; | |
12921 | unsigned types[NEON_MAX_TYPE_ELS]; | |
12922 | enum neon_el_type k_type = NT_invtype; | |
12923 | unsigned k_size = -1u; | |
12924 | struct neon_type_el badtype = {NT_invtype, -1}; | |
12925 | unsigned key_allowed = 0; | |
12926 | ||
12927 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
12928 | Fill in the missing operand here, if it was omitted. */ | |
12929 | if (els > 1 && !inst.operands[1].present) | |
12930 | inst.operands[1] = inst.operands[0]; | |
12931 | ||
12932 | /* Suck up all the varargs. */ | |
12933 | va_start (ap, ns); | |
12934 | for (i = 0; i < els; i++) | |
12935 | { | |
12936 | unsigned thisarg = va_arg (ap, unsigned); | |
12937 | if (thisarg == N_IGNORE_TYPE) | |
12938 | { | |
12939 | va_end (ap); | |
12940 | return badtype; | |
12941 | } | |
12942 | types[i] = thisarg; | |
12943 | if ((thisarg & N_KEY) != 0) | |
12944 | key_el = i; | |
12945 | } | |
12946 | va_end (ap); | |
12947 | ||
dcbf9037 JB |
12948 | if (inst.vectype.elems > 0) |
12949 | for (i = 0; i < els; i++) | |
12950 | if (inst.operands[i].vectype.type != NT_invtype) | |
12951 | { | |
12952 | first_error (_("types specified in both the mnemonic and operands")); | |
12953 | return badtype; | |
12954 | } | |
12955 | ||
5287ad62 JB |
12956 | /* Duplicate inst.vectype elements here as necessary. |
12957 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
12958 | particularly when an insn takes one register and one non-register | |
12959 | operand. */ | |
12960 | if (inst.vectype.elems == 1 && els > 1) | |
12961 | { | |
12962 | unsigned j; | |
12963 | inst.vectype.elems = els; | |
12964 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
12965 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
12966 | if (j != key_el) |
12967 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
12968 | types[j]); | |
12969 | } | |
12970 | else if (inst.vectype.elems == 0 && els > 0) | |
12971 | { | |
12972 | unsigned j; | |
12973 | /* No types were given after the mnemonic, so look for types specified | |
12974 | after each operand. We allow some flexibility here; as long as the | |
12975 | "key" operand has a type, we can infer the others. */ | |
12976 | for (j = 0; j < els; j++) | |
12977 | if (inst.operands[j].vectype.type != NT_invtype) | |
12978 | inst.vectype.el[j] = inst.operands[j].vectype; | |
12979 | ||
12980 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 12981 | { |
dcbf9037 JB |
12982 | for (j = 0; j < els; j++) |
12983 | if (inst.operands[j].vectype.type == NT_invtype) | |
12984 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
12985 | types[j]); | |
12986 | } | |
12987 | else | |
12988 | { | |
12989 | first_error (_("operand types can't be inferred")); | |
12990 | return badtype; | |
5287ad62 JB |
12991 | } |
12992 | } | |
12993 | else if (inst.vectype.elems != els) | |
12994 | { | |
dcbf9037 | 12995 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
12996 | return badtype; |
12997 | } | |
12998 | ||
12999 | for (pass = 0; pass < 2; pass++) | |
13000 | { | |
13001 | for (i = 0; i < els; i++) | |
13002 | { | |
13003 | unsigned thisarg = types[i]; | |
13004 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
13005 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
13006 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
13007 | unsigned g_size = inst.vectype.el[i].size; | |
13008 | ||
13009 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
13010 | integer types if sign-specific variants are unavailable. */ | |
13011 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
13012 | && (types_allowed & N_SU_ALL) == 0) | |
13013 | g_type = NT_integer; | |
13014 | ||
13015 | /* If only untyped args are allowed, decay any more specific types to | |
13016 | them. Some instructions only care about signs for some element | |
13017 | sizes, so handle that properly. */ | |
91ff7894 MGD |
13018 | if (((types_allowed & N_UNT) == 0) |
13019 | && ((g_size == 8 && (types_allowed & N_8) != 0) | |
13020 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
13021 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
13022 | || (g_size == 64 && (types_allowed & N_64) != 0))) | |
5287ad62 JB |
13023 | g_type = NT_untyped; |
13024 | ||
13025 | if (pass == 0) | |
13026 | { | |
13027 | if ((thisarg & N_KEY) != 0) | |
13028 | { | |
13029 | k_type = g_type; | |
13030 | k_size = g_size; | |
13031 | key_allowed = thisarg & ~N_KEY; | |
13032 | } | |
13033 | } | |
13034 | else | |
13035 | { | |
037e8744 JB |
13036 | if ((thisarg & N_VFP) != 0) |
13037 | { | |
99b253c5 NC |
13038 | enum neon_shape_el regshape; |
13039 | unsigned regwidth, match; | |
13040 | ||
13041 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
13042 | if (ns == NS_NULL) | |
13043 | { | |
13044 | first_error (_("invalid instruction shape")); | |
13045 | return badtype; | |
13046 | } | |
13047 | regshape = neon_shape_tab[ns].el[i]; | |
13048 | regwidth = neon_shape_el_size[regshape]; | |
037e8744 JB |
13049 | |
13050 | /* In VFP mode, operands must match register widths. If we | |
13051 | have a key operand, use its width, else use the width of | |
13052 | the current operand. */ | |
13053 | if (k_size != -1u) | |
13054 | match = k_size; | |
13055 | else | |
13056 | match = g_size; | |
13057 | ||
13058 | if (regwidth != match) | |
13059 | { | |
13060 | first_error (_("operand size must match register width")); | |
13061 | return badtype; | |
13062 | } | |
13063 | } | |
5f4273c7 | 13064 | |
5287ad62 JB |
13065 | if ((thisarg & N_EQK) == 0) |
13066 | { | |
13067 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
13068 | ||
13069 | if ((given_type & types_allowed) == 0) | |
13070 | { | |
dcbf9037 | 13071 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
13072 | return badtype; |
13073 | } | |
13074 | } | |
13075 | else | |
13076 | { | |
13077 | enum neon_el_type mod_k_type = k_type; | |
13078 | unsigned mod_k_size = k_size; | |
13079 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
13080 | if (g_type != mod_k_type || g_size != mod_k_size) | |
13081 | { | |
dcbf9037 | 13082 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
13083 | return badtype; |
13084 | } | |
13085 | } | |
13086 | } | |
13087 | } | |
13088 | } | |
13089 | ||
13090 | return inst.vectype.el[key_el]; | |
13091 | } | |
13092 | ||
037e8744 | 13093 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 13094 | |
037e8744 JB |
13095 | /* Thumb VFP instructions have 0xE in the condition field. */ |
13096 | ||
13097 | static void | |
13098 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 13099 | { |
88714cb8 DG |
13100 | inst.is_neon = 1; |
13101 | ||
5287ad62 | 13102 | if (thumb_mode) |
037e8744 | 13103 | inst.instruction |= 0xe0000000; |
5287ad62 | 13104 | else |
037e8744 | 13105 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
13106 | } |
13107 | ||
037e8744 JB |
13108 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
13109 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
13110 | etc. It is assumed that operand parsing has already been done, and that the | |
13111 | operands are in the form expected by the given opcode (this isn't necessarily | |
13112 | the same as the form in which they were parsed, hence some massaging must | |
13113 | take place before this function is called). | |
13114 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 13115 | |
037e8744 JB |
13116 | static void |
13117 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 13118 | { |
037e8744 | 13119 | const struct asm_opcode *opcode; |
5f4273c7 | 13120 | |
21d799b5 | 13121 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 13122 | |
037e8744 JB |
13123 | if (!opcode) |
13124 | abort (); | |
5287ad62 | 13125 | |
037e8744 JB |
13126 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
13127 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
13128 | _(BAD_FPU)); | |
5287ad62 | 13129 | |
88714cb8 DG |
13130 | inst.is_neon = 1; |
13131 | ||
037e8744 JB |
13132 | if (thumb_mode) |
13133 | { | |
13134 | inst.instruction = opcode->tvalue; | |
13135 | opcode->tencode (); | |
13136 | } | |
13137 | else | |
13138 | { | |
13139 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
13140 | opcode->aencode (); | |
13141 | } | |
13142 | } | |
5287ad62 JB |
13143 | |
13144 | static void | |
037e8744 | 13145 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 13146 | { |
037e8744 JB |
13147 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
13148 | ||
13149 | if (rs == NS_FFF) | |
13150 | { | |
13151 | if (is_add) | |
13152 | do_vfp_nsyn_opcode ("fadds"); | |
13153 | else | |
13154 | do_vfp_nsyn_opcode ("fsubs"); | |
13155 | } | |
13156 | else | |
13157 | { | |
13158 | if (is_add) | |
13159 | do_vfp_nsyn_opcode ("faddd"); | |
13160 | else | |
13161 | do_vfp_nsyn_opcode ("fsubd"); | |
13162 | } | |
13163 | } | |
13164 | ||
13165 | /* Check operand types to see if this is a VFP instruction, and if so call | |
13166 | PFN (). */ | |
13167 | ||
13168 | static int | |
13169 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
13170 | { | |
13171 | enum neon_shape rs; | |
13172 | struct neon_type_el et; | |
13173 | ||
13174 | switch (args) | |
13175 | { | |
13176 | case 2: | |
13177 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
13178 | et = neon_check_type (2, rs, | |
13179 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
13180 | break; | |
5f4273c7 | 13181 | |
037e8744 JB |
13182 | case 3: |
13183 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
13184 | et = neon_check_type (3, rs, | |
13185 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
13186 | break; | |
13187 | ||
13188 | default: | |
13189 | abort (); | |
13190 | } | |
13191 | ||
13192 | if (et.type != NT_invtype) | |
13193 | { | |
13194 | pfn (rs); | |
13195 | return SUCCESS; | |
13196 | } | |
037e8744 | 13197 | |
99b253c5 | 13198 | inst.error = NULL; |
037e8744 JB |
13199 | return FAIL; |
13200 | } | |
13201 | ||
13202 | static void | |
13203 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
13204 | { | |
13205 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 13206 | |
037e8744 JB |
13207 | if (rs == NS_FFF) |
13208 | { | |
13209 | if (is_mla) | |
13210 | do_vfp_nsyn_opcode ("fmacs"); | |
13211 | else | |
1ee69515 | 13212 | do_vfp_nsyn_opcode ("fnmacs"); |
037e8744 JB |
13213 | } |
13214 | else | |
13215 | { | |
13216 | if (is_mla) | |
13217 | do_vfp_nsyn_opcode ("fmacd"); | |
13218 | else | |
1ee69515 | 13219 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
13220 | } |
13221 | } | |
13222 | ||
62f3b8c8 PB |
13223 | static void |
13224 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
13225 | { | |
13226 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
13227 | ||
13228 | if (rs == NS_FFF) | |
13229 | { | |
13230 | if (is_fma) | |
13231 | do_vfp_nsyn_opcode ("ffmas"); | |
13232 | else | |
13233 | do_vfp_nsyn_opcode ("ffnmas"); | |
13234 | } | |
13235 | else | |
13236 | { | |
13237 | if (is_fma) | |
13238 | do_vfp_nsyn_opcode ("ffmad"); | |
13239 | else | |
13240 | do_vfp_nsyn_opcode ("ffnmad"); | |
13241 | } | |
13242 | } | |
13243 | ||
037e8744 JB |
13244 | static void |
13245 | do_vfp_nsyn_mul (enum neon_shape rs) | |
13246 | { | |
13247 | if (rs == NS_FFF) | |
13248 | do_vfp_nsyn_opcode ("fmuls"); | |
13249 | else | |
13250 | do_vfp_nsyn_opcode ("fmuld"); | |
13251 | } | |
13252 | ||
13253 | static void | |
13254 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
13255 | { | |
13256 | int is_neg = (inst.instruction & 0x80) != 0; | |
13257 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
13258 | ||
13259 | if (rs == NS_FF) | |
13260 | { | |
13261 | if (is_neg) | |
13262 | do_vfp_nsyn_opcode ("fnegs"); | |
13263 | else | |
13264 | do_vfp_nsyn_opcode ("fabss"); | |
13265 | } | |
13266 | else | |
13267 | { | |
13268 | if (is_neg) | |
13269 | do_vfp_nsyn_opcode ("fnegd"); | |
13270 | else | |
13271 | do_vfp_nsyn_opcode ("fabsd"); | |
13272 | } | |
13273 | } | |
13274 | ||
13275 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
13276 | insns belong to Neon, and are handled elsewhere. */ | |
13277 | ||
13278 | static void | |
13279 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
13280 | { | |
13281 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
13282 | if (is_ldm) | |
13283 | { | |
13284 | if (is_dbmode) | |
13285 | do_vfp_nsyn_opcode ("fldmdbs"); | |
13286 | else | |
13287 | do_vfp_nsyn_opcode ("fldmias"); | |
13288 | } | |
13289 | else | |
13290 | { | |
13291 | if (is_dbmode) | |
13292 | do_vfp_nsyn_opcode ("fstmdbs"); | |
13293 | else | |
13294 | do_vfp_nsyn_opcode ("fstmias"); | |
13295 | } | |
13296 | } | |
13297 | ||
037e8744 JB |
13298 | static void |
13299 | do_vfp_nsyn_sqrt (void) | |
13300 | { | |
13301 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
13302 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 13303 | |
037e8744 JB |
13304 | if (rs == NS_FF) |
13305 | do_vfp_nsyn_opcode ("fsqrts"); | |
13306 | else | |
13307 | do_vfp_nsyn_opcode ("fsqrtd"); | |
13308 | } | |
13309 | ||
13310 | static void | |
13311 | do_vfp_nsyn_div (void) | |
13312 | { | |
13313 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
13314 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
13315 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 13316 | |
037e8744 JB |
13317 | if (rs == NS_FFF) |
13318 | do_vfp_nsyn_opcode ("fdivs"); | |
13319 | else | |
13320 | do_vfp_nsyn_opcode ("fdivd"); | |
13321 | } | |
13322 | ||
13323 | static void | |
13324 | do_vfp_nsyn_nmul (void) | |
13325 | { | |
13326 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
13327 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
13328 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 13329 | |
037e8744 JB |
13330 | if (rs == NS_FFF) |
13331 | { | |
88714cb8 | 13332 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
13333 | do_vfp_sp_dyadic (); |
13334 | } | |
13335 | else | |
13336 | { | |
88714cb8 | 13337 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
13338 | do_vfp_dp_rd_rn_rm (); |
13339 | } | |
13340 | do_vfp_cond_or_thumb (); | |
13341 | } | |
13342 | ||
13343 | static void | |
13344 | do_vfp_nsyn_cmp (void) | |
13345 | { | |
13346 | if (inst.operands[1].isreg) | |
13347 | { | |
13348 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
13349 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 13350 | |
037e8744 JB |
13351 | if (rs == NS_FF) |
13352 | { | |
88714cb8 | 13353 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
13354 | do_vfp_sp_monadic (); |
13355 | } | |
13356 | else | |
13357 | { | |
88714cb8 | 13358 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
13359 | do_vfp_dp_rd_rm (); |
13360 | } | |
13361 | } | |
13362 | else | |
13363 | { | |
13364 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
13365 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
13366 | ||
13367 | switch (inst.instruction & 0x0fffffff) | |
13368 | { | |
13369 | case N_MNEM_vcmp: | |
13370 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
13371 | break; | |
13372 | case N_MNEM_vcmpe: | |
13373 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
13374 | break; | |
13375 | default: | |
13376 | abort (); | |
13377 | } | |
5f4273c7 | 13378 | |
037e8744 JB |
13379 | if (rs == NS_FI) |
13380 | { | |
88714cb8 | 13381 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
13382 | do_vfp_sp_compare_z (); |
13383 | } | |
13384 | else | |
13385 | { | |
88714cb8 | 13386 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
13387 | do_vfp_dp_rd (); |
13388 | } | |
13389 | } | |
13390 | do_vfp_cond_or_thumb (); | |
13391 | } | |
13392 | ||
13393 | static void | |
13394 | nsyn_insert_sp (void) | |
13395 | { | |
13396 | inst.operands[1] = inst.operands[0]; | |
13397 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 13398 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
13399 | inst.operands[0].isreg = 1; |
13400 | inst.operands[0].writeback = 1; | |
13401 | inst.operands[0].present = 1; | |
13402 | } | |
13403 | ||
13404 | static void | |
13405 | do_vfp_nsyn_push (void) | |
13406 | { | |
13407 | nsyn_insert_sp (); | |
13408 | if (inst.operands[1].issingle) | |
13409 | do_vfp_nsyn_opcode ("fstmdbs"); | |
13410 | else | |
13411 | do_vfp_nsyn_opcode ("fstmdbd"); | |
13412 | } | |
13413 | ||
13414 | static void | |
13415 | do_vfp_nsyn_pop (void) | |
13416 | { | |
13417 | nsyn_insert_sp (); | |
13418 | if (inst.operands[1].issingle) | |
22b5b651 | 13419 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 13420 | else |
22b5b651 | 13421 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
13422 | } |
13423 | ||
13424 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
13425 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
13426 | ||
88714cb8 DG |
13427 | static void |
13428 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 13429 | { |
88714cb8 DG |
13430 | unsigned int i = insn->instruction; |
13431 | insn->is_neon = 1; | |
13432 | ||
037e8744 JB |
13433 | if (thumb_mode) |
13434 | { | |
13435 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
13436 | if (i & (1 << 24)) | |
13437 | i |= 1 << 28; | |
5f4273c7 | 13438 | |
037e8744 | 13439 | i &= ~(1 << 24); |
5f4273c7 | 13440 | |
037e8744 JB |
13441 | i |= 0xef000000; |
13442 | } | |
13443 | else | |
13444 | i |= 0xf2000000; | |
5f4273c7 | 13445 | |
88714cb8 | 13446 | insn->instruction = i; |
037e8744 JB |
13447 | } |
13448 | ||
13449 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
13450 | (0, 1, 2, 3). */ | |
13451 | ||
13452 | static unsigned | |
13453 | neon_logbits (unsigned x) | |
13454 | { | |
13455 | return ffs (x) - 4; | |
13456 | } | |
13457 | ||
13458 | #define LOW4(R) ((R) & 0xf) | |
13459 | #define HI1(R) (((R) >> 4) & 1) | |
13460 | ||
13461 | /* Encode insns with bit pattern: | |
13462 | ||
13463 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
13464 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 13465 | |
037e8744 JB |
13466 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
13467 | different meaning for some instruction. */ | |
13468 | ||
13469 | static void | |
13470 | neon_three_same (int isquad, int ubit, int size) | |
13471 | { | |
13472 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13473 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13474 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13475 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13476 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13477 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
13478 | inst.instruction |= (isquad != 0) << 6; | |
13479 | inst.instruction |= (ubit != 0) << 24; | |
13480 | if (size != -1) | |
13481 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 13482 | |
88714cb8 | 13483 | neon_dp_fixup (&inst); |
037e8744 JB |
13484 | } |
13485 | ||
13486 | /* Encode instructions of the form: | |
13487 | ||
13488 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
13489 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
13490 | |
13491 | Don't write size if SIZE == -1. */ | |
13492 | ||
13493 | static void | |
13494 | neon_two_same (int qbit, int ubit, int size) | |
13495 | { | |
13496 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13497 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13498 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13499 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13500 | inst.instruction |= (qbit != 0) << 6; | |
13501 | inst.instruction |= (ubit != 0) << 24; | |
13502 | ||
13503 | if (size != -1) | |
13504 | inst.instruction |= neon_logbits (size) << 18; | |
13505 | ||
88714cb8 | 13506 | neon_dp_fixup (&inst); |
5287ad62 JB |
13507 | } |
13508 | ||
13509 | /* Neon instruction encoders, in approximate order of appearance. */ | |
13510 | ||
13511 | static void | |
13512 | do_neon_dyadic_i_su (void) | |
13513 | { | |
037e8744 | 13514 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13515 | struct neon_type_el et = neon_check_type (3, rs, |
13516 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 13517 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
13518 | } |
13519 | ||
13520 | static void | |
13521 | do_neon_dyadic_i64_su (void) | |
13522 | { | |
037e8744 | 13523 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13524 | struct neon_type_el et = neon_check_type (3, rs, |
13525 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 13526 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
13527 | } |
13528 | ||
13529 | static void | |
13530 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
13531 | unsigned immbits) | |
13532 | { | |
13533 | unsigned size = et.size >> 3; | |
13534 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13535 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13536 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13537 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13538 | inst.instruction |= (isquad != 0) << 6; | |
13539 | inst.instruction |= immbits << 16; | |
13540 | inst.instruction |= (size >> 3) << 7; | |
13541 | inst.instruction |= (size & 0x7) << 19; | |
13542 | if (write_ubit) | |
13543 | inst.instruction |= (uval != 0) << 24; | |
13544 | ||
88714cb8 | 13545 | neon_dp_fixup (&inst); |
5287ad62 JB |
13546 | } |
13547 | ||
13548 | static void | |
13549 | do_neon_shl_imm (void) | |
13550 | { | |
13551 | if (!inst.operands[2].isreg) | |
13552 | { | |
037e8744 | 13553 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 13554 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
88714cb8 | 13555 | NEON_ENCODE (IMMED, inst); |
037e8744 | 13556 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
13557 | } |
13558 | else | |
13559 | { | |
037e8744 | 13560 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13561 | struct neon_type_el et = neon_check_type (3, rs, |
13562 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
13563 | unsigned int tmp; |
13564 | ||
13565 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
13566 | vshl.xx Dd, Dm, Dn | |
13567 | whereas other 3-register operations encoded by neon_three_same have | |
13568 | syntax like: | |
13569 | vadd.xx Dd, Dn, Dm | |
13570 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
13571 | here. */ | |
13572 | tmp = inst.operands[2].reg; | |
13573 | inst.operands[2].reg = inst.operands[1].reg; | |
13574 | inst.operands[1].reg = tmp; | |
88714cb8 | 13575 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 13576 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
13577 | } |
13578 | } | |
13579 | ||
13580 | static void | |
13581 | do_neon_qshl_imm (void) | |
13582 | { | |
13583 | if (!inst.operands[2].isreg) | |
13584 | { | |
037e8744 | 13585 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 13586 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
627907b7 | 13587 | |
88714cb8 | 13588 | NEON_ENCODE (IMMED, inst); |
037e8744 | 13589 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
13590 | inst.operands[2].imm); |
13591 | } | |
13592 | else | |
13593 | { | |
037e8744 | 13594 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13595 | struct neon_type_el et = neon_check_type (3, rs, |
13596 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
13597 | unsigned int tmp; |
13598 | ||
13599 | /* See note in do_neon_shl_imm. */ | |
13600 | tmp = inst.operands[2].reg; | |
13601 | inst.operands[2].reg = inst.operands[1].reg; | |
13602 | inst.operands[1].reg = tmp; | |
88714cb8 | 13603 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 13604 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
13605 | } |
13606 | } | |
13607 | ||
627907b7 JB |
13608 | static void |
13609 | do_neon_rshl (void) | |
13610 | { | |
13611 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
13612 | struct neon_type_el et = neon_check_type (3, rs, | |
13613 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
13614 | unsigned int tmp; | |
13615 | ||
13616 | tmp = inst.operands[2].reg; | |
13617 | inst.operands[2].reg = inst.operands[1].reg; | |
13618 | inst.operands[1].reg = tmp; | |
13619 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
13620 | } | |
13621 | ||
5287ad62 JB |
13622 | static int |
13623 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
13624 | { | |
036dc3f7 PB |
13625 | /* Handle .I8 pseudo-instructions. */ |
13626 | if (size == 8) | |
5287ad62 | 13627 | { |
5287ad62 JB |
13628 | /* Unfortunately, this will make everything apart from zero out-of-range. |
13629 | FIXME is this the intended semantics? There doesn't seem much point in | |
13630 | accepting .I8 if so. */ | |
13631 | immediate |= immediate << 8; | |
13632 | size = 16; | |
036dc3f7 PB |
13633 | } |
13634 | ||
13635 | if (size >= 32) | |
13636 | { | |
13637 | if (immediate == (immediate & 0x000000ff)) | |
13638 | { | |
13639 | *immbits = immediate; | |
13640 | return 0x1; | |
13641 | } | |
13642 | else if (immediate == (immediate & 0x0000ff00)) | |
13643 | { | |
13644 | *immbits = immediate >> 8; | |
13645 | return 0x3; | |
13646 | } | |
13647 | else if (immediate == (immediate & 0x00ff0000)) | |
13648 | { | |
13649 | *immbits = immediate >> 16; | |
13650 | return 0x5; | |
13651 | } | |
13652 | else if (immediate == (immediate & 0xff000000)) | |
13653 | { | |
13654 | *immbits = immediate >> 24; | |
13655 | return 0x7; | |
13656 | } | |
13657 | if ((immediate & 0xffff) != (immediate >> 16)) | |
13658 | goto bad_immediate; | |
13659 | immediate &= 0xffff; | |
5287ad62 JB |
13660 | } |
13661 | ||
13662 | if (immediate == (immediate & 0x000000ff)) | |
13663 | { | |
13664 | *immbits = immediate; | |
036dc3f7 | 13665 | return 0x9; |
5287ad62 JB |
13666 | } |
13667 | else if (immediate == (immediate & 0x0000ff00)) | |
13668 | { | |
13669 | *immbits = immediate >> 8; | |
036dc3f7 | 13670 | return 0xb; |
5287ad62 JB |
13671 | } |
13672 | ||
13673 | bad_immediate: | |
dcbf9037 | 13674 | first_error (_("immediate value out of range")); |
5287ad62 JB |
13675 | return FAIL; |
13676 | } | |
13677 | ||
13678 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
13679 | A, B, C, D. */ | |
13680 | ||
13681 | static int | |
13682 | neon_bits_same_in_bytes (unsigned imm) | |
13683 | { | |
13684 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
13685 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
13686 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
13687 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
13688 | } | |
13689 | ||
13690 | /* For immediate of above form, return 0bABCD. */ | |
13691 | ||
13692 | static unsigned | |
13693 | neon_squash_bits (unsigned imm) | |
13694 | { | |
13695 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
13696 | | ((imm & 0x01000000) >> 21); | |
13697 | } | |
13698 | ||
136da414 | 13699 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
13700 | |
13701 | static unsigned | |
13702 | neon_qfloat_bits (unsigned imm) | |
13703 | { | |
136da414 | 13704 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
13705 | } |
13706 | ||
13707 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
13708 | the instruction. *OP is passed as the initial value of the op field, and | |
13709 | may be set to a different value depending on the constant (i.e. | |
13710 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
5f4273c7 | 13711 | MVN). If the immediate looks like a repeated pattern then also |
036dc3f7 | 13712 | try smaller element sizes. */ |
5287ad62 JB |
13713 | |
13714 | static int | |
c96612cc JB |
13715 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, |
13716 | unsigned *immbits, int *op, int size, | |
13717 | enum neon_el_type type) | |
5287ad62 | 13718 | { |
c96612cc JB |
13719 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is |
13720 | float. */ | |
13721 | if (type == NT_float && !float_p) | |
13722 | return FAIL; | |
13723 | ||
136da414 JB |
13724 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
13725 | { | |
13726 | if (size != 32 || *op == 1) | |
13727 | return FAIL; | |
13728 | *immbits = neon_qfloat_bits (immlo); | |
13729 | return 0xf; | |
13730 | } | |
036dc3f7 PB |
13731 | |
13732 | if (size == 64) | |
5287ad62 | 13733 | { |
036dc3f7 PB |
13734 | if (neon_bits_same_in_bytes (immhi) |
13735 | && neon_bits_same_in_bytes (immlo)) | |
13736 | { | |
13737 | if (*op == 1) | |
13738 | return FAIL; | |
13739 | *immbits = (neon_squash_bits (immhi) << 4) | |
13740 | | neon_squash_bits (immlo); | |
13741 | *op = 1; | |
13742 | return 0xe; | |
13743 | } | |
13744 | ||
13745 | if (immhi != immlo) | |
13746 | return FAIL; | |
5287ad62 | 13747 | } |
036dc3f7 PB |
13748 | |
13749 | if (size >= 32) | |
5287ad62 | 13750 | { |
036dc3f7 PB |
13751 | if (immlo == (immlo & 0x000000ff)) |
13752 | { | |
13753 | *immbits = immlo; | |
13754 | return 0x0; | |
13755 | } | |
13756 | else if (immlo == (immlo & 0x0000ff00)) | |
13757 | { | |
13758 | *immbits = immlo >> 8; | |
13759 | return 0x2; | |
13760 | } | |
13761 | else if (immlo == (immlo & 0x00ff0000)) | |
13762 | { | |
13763 | *immbits = immlo >> 16; | |
13764 | return 0x4; | |
13765 | } | |
13766 | else if (immlo == (immlo & 0xff000000)) | |
13767 | { | |
13768 | *immbits = immlo >> 24; | |
13769 | return 0x6; | |
13770 | } | |
13771 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
13772 | { | |
13773 | *immbits = (immlo >> 8) & 0xff; | |
13774 | return 0xc; | |
13775 | } | |
13776 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
13777 | { | |
13778 | *immbits = (immlo >> 16) & 0xff; | |
13779 | return 0xd; | |
13780 | } | |
13781 | ||
13782 | if ((immlo & 0xffff) != (immlo >> 16)) | |
13783 | return FAIL; | |
13784 | immlo &= 0xffff; | |
5287ad62 | 13785 | } |
036dc3f7 PB |
13786 | |
13787 | if (size >= 16) | |
5287ad62 | 13788 | { |
036dc3f7 PB |
13789 | if (immlo == (immlo & 0x000000ff)) |
13790 | { | |
13791 | *immbits = immlo; | |
13792 | return 0x8; | |
13793 | } | |
13794 | else if (immlo == (immlo & 0x0000ff00)) | |
13795 | { | |
13796 | *immbits = immlo >> 8; | |
13797 | return 0xa; | |
13798 | } | |
13799 | ||
13800 | if ((immlo & 0xff) != (immlo >> 8)) | |
13801 | return FAIL; | |
13802 | immlo &= 0xff; | |
5287ad62 | 13803 | } |
036dc3f7 PB |
13804 | |
13805 | if (immlo == (immlo & 0x000000ff)) | |
5287ad62 | 13806 | { |
036dc3f7 PB |
13807 | /* Don't allow MVN with 8-bit immediate. */ |
13808 | if (*op == 1) | |
13809 | return FAIL; | |
13810 | *immbits = immlo; | |
13811 | return 0xe; | |
5287ad62 | 13812 | } |
5287ad62 JB |
13813 | |
13814 | return FAIL; | |
13815 | } | |
13816 | ||
13817 | /* Write immediate bits [7:0] to the following locations: | |
13818 | ||
13819 | |28/24|23 19|18 16|15 4|3 0| | |
13820 | | 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| | |
13821 | ||
13822 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
13823 | ||
13824 | static void | |
13825 | neon_write_immbits (unsigned immbits) | |
13826 | { | |
13827 | inst.instruction |= immbits & 0xf; | |
13828 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
13829 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
13830 | } | |
13831 | ||
13832 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
13833 | ||
13834 | static void | |
13835 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
13836 | { | |
13837 | unsigned immlo = xlo ? *xlo : 0; | |
13838 | unsigned immhi = xhi ? *xhi : 0; | |
13839 | ||
13840 | switch (size) | |
13841 | { | |
13842 | case 8: | |
13843 | immlo = (~immlo) & 0xff; | |
13844 | break; | |
13845 | ||
13846 | case 16: | |
13847 | immlo = (~immlo) & 0xffff; | |
13848 | break; | |
13849 | ||
13850 | case 64: | |
13851 | immhi = (~immhi) & 0xffffffff; | |
13852 | /* fall through. */ | |
13853 | ||
13854 | case 32: | |
13855 | immlo = (~immlo) & 0xffffffff; | |
13856 | break; | |
13857 | ||
13858 | default: | |
13859 | abort (); | |
13860 | } | |
13861 | ||
13862 | if (xlo) | |
13863 | *xlo = immlo; | |
13864 | ||
13865 | if (xhi) | |
13866 | *xhi = immhi; | |
13867 | } | |
13868 | ||
13869 | static void | |
13870 | do_neon_logic (void) | |
13871 | { | |
13872 | if (inst.operands[2].present && inst.operands[2].isreg) | |
13873 | { | |
037e8744 | 13874 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13875 | neon_check_type (3, rs, N_IGNORE_TYPE); |
13876 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 13877 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 13878 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13879 | } |
13880 | else | |
13881 | { | |
4316f0d2 DG |
13882 | const int three_ops_form = (inst.operands[2].present |
13883 | && !inst.operands[2].isreg); | |
13884 | const int immoperand = (three_ops_form ? 2 : 1); | |
13885 | enum neon_shape rs = (three_ops_form | |
13886 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
13887 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
037e8744 JB |
13888 | struct neon_type_el et = neon_check_type (2, rs, |
13889 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
21d799b5 | 13890 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
13891 | unsigned immbits; |
13892 | int cmode; | |
5f4273c7 | 13893 | |
5287ad62 JB |
13894 | if (et.type == NT_invtype) |
13895 | return; | |
5f4273c7 | 13896 | |
4316f0d2 DG |
13897 | if (three_ops_form) |
13898 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13899 | _("first and second operands shall be the same register")); | |
13900 | ||
88714cb8 | 13901 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 13902 | |
4316f0d2 | 13903 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
13904 | if (et.size == 64) |
13905 | { | |
13906 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
13907 | pattern. */ | |
4316f0d2 DG |
13908 | if (immbits != (inst.operands[immoperand].regisimm ? |
13909 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
13910 | { |
13911 | /* Set immbits to an invalid constant. */ | |
13912 | immbits = 0xdeadbeef; | |
13913 | } | |
13914 | } | |
13915 | ||
5287ad62 JB |
13916 | switch (opcode) |
13917 | { | |
13918 | case N_MNEM_vbic: | |
036dc3f7 | 13919 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 13920 | break; |
5f4273c7 | 13921 | |
5287ad62 | 13922 | case N_MNEM_vorr: |
036dc3f7 | 13923 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 13924 | break; |
5f4273c7 | 13925 | |
5287ad62 JB |
13926 | case N_MNEM_vand: |
13927 | /* Pseudo-instruction for VBIC. */ | |
5287ad62 JB |
13928 | neon_invert_size (&immbits, 0, et.size); |
13929 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
13930 | break; | |
5f4273c7 | 13931 | |
5287ad62 JB |
13932 | case N_MNEM_vorn: |
13933 | /* Pseudo-instruction for VORR. */ | |
5287ad62 JB |
13934 | neon_invert_size (&immbits, 0, et.size); |
13935 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
13936 | break; | |
5f4273c7 | 13937 | |
5287ad62 JB |
13938 | default: |
13939 | abort (); | |
13940 | } | |
13941 | ||
13942 | if (cmode == FAIL) | |
13943 | return; | |
13944 | ||
037e8744 | 13945 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13946 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13947 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13948 | inst.instruction |= cmode << 8; | |
13949 | neon_write_immbits (immbits); | |
5f4273c7 | 13950 | |
88714cb8 | 13951 | neon_dp_fixup (&inst); |
5287ad62 JB |
13952 | } |
13953 | } | |
13954 | ||
13955 | static void | |
13956 | do_neon_bitfield (void) | |
13957 | { | |
037e8744 | 13958 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 13959 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 13960 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13961 | } |
13962 | ||
13963 | static void | |
dcbf9037 JB |
13964 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
13965 | unsigned destbits) | |
5287ad62 | 13966 | { |
037e8744 | 13967 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
13968 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
13969 | types | N_KEY); | |
5287ad62 JB |
13970 | if (et.type == NT_float) |
13971 | { | |
88714cb8 | 13972 | NEON_ENCODE (FLOAT, inst); |
037e8744 | 13973 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13974 | } |
13975 | else | |
13976 | { | |
88714cb8 | 13977 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 13978 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
13979 | } |
13980 | } | |
13981 | ||
13982 | static void | |
13983 | do_neon_dyadic_if_su (void) | |
13984 | { | |
dcbf9037 | 13985 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
13986 | } |
13987 | ||
13988 | static void | |
13989 | do_neon_dyadic_if_su_d (void) | |
13990 | { | |
13991 | /* This version only allow D registers, but that constraint is enforced during | |
13992 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 13993 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
13994 | } |
13995 | ||
5287ad62 JB |
13996 | static void |
13997 | do_neon_dyadic_if_i_d (void) | |
13998 | { | |
428e3f1f PB |
13999 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
14000 | affected if we specify unsigned args. */ | |
14001 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
14002 | } |
14003 | ||
037e8744 JB |
14004 | enum vfp_or_neon_is_neon_bits |
14005 | { | |
14006 | NEON_CHECK_CC = 1, | |
73924fbc MGD |
14007 | NEON_CHECK_ARCH = 2, |
14008 | NEON_CHECK_ARCH8 = 4 | |
037e8744 JB |
14009 | }; |
14010 | ||
14011 | /* Call this function if an instruction which may have belonged to the VFP or | |
14012 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
14013 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
14014 | things: | |
14015 | ||
14016 | - Make sure the user hasn't attempted to make a Neon instruction | |
14017 | conditional. | |
14018 | - Alter the value in the condition code field if necessary. | |
14019 | - Make sure that the arch supports Neon instructions. | |
14020 | ||
14021 | Which of these operations take place depends on bits from enum | |
14022 | vfp_or_neon_is_neon_bits. | |
14023 | ||
14024 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
14025 | current instruction's condition is COND_ALWAYS, the condition field is | |
14026 | changed to inst.uncond_value. This is necessary because instructions shared | |
14027 | between VFP and Neon may be conditional for the VFP variants only, and the | |
14028 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
14029 | ||
14030 | static int | |
14031 | vfp_or_neon_is_neon (unsigned check) | |
14032 | { | |
14033 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
14034 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
14035 | { | |
14036 | if (inst.cond != COND_ALWAYS) | |
14037 | { | |
14038 | first_error (_(BAD_COND)); | |
14039 | return FAIL; | |
14040 | } | |
14041 | if (inst.uncond_value != -1) | |
14042 | inst.instruction |= inst.uncond_value << 28; | |
14043 | } | |
5f4273c7 | 14044 | |
037e8744 | 14045 | if ((check & NEON_CHECK_ARCH) |
73924fbc MGD |
14046 | && !mark_feature_used (&fpu_neon_ext_v1)) |
14047 | { | |
14048 | first_error (_(BAD_FPU)); | |
14049 | return FAIL; | |
14050 | } | |
14051 | ||
14052 | if ((check & NEON_CHECK_ARCH8) | |
14053 | && !mark_feature_used (&fpu_neon_ext_armv8)) | |
037e8744 JB |
14054 | { |
14055 | first_error (_(BAD_FPU)); | |
14056 | return FAIL; | |
14057 | } | |
5f4273c7 | 14058 | |
037e8744 JB |
14059 | return SUCCESS; |
14060 | } | |
14061 | ||
5287ad62 JB |
14062 | static void |
14063 | do_neon_addsub_if_i (void) | |
14064 | { | |
037e8744 JB |
14065 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
14066 | return; | |
14067 | ||
14068 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14069 | return; | |
14070 | ||
5287ad62 JB |
14071 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
14072 | affected if we specify unsigned args. */ | |
dcbf9037 | 14073 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
14074 | } |
14075 | ||
14076 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
14077 | result to be: | |
14078 | V<op> A,B (A is operand 0, B is operand 2) | |
14079 | to mean: | |
14080 | V<op> A,B,A | |
14081 | not: | |
14082 | V<op> A,B,B | |
14083 | so handle that case specially. */ | |
14084 | ||
14085 | static void | |
14086 | neon_exchange_operands (void) | |
14087 | { | |
14088 | void *scratch = alloca (sizeof (inst.operands[0])); | |
14089 | if (inst.operands[1].present) | |
14090 | { | |
14091 | /* Swap operands[1] and operands[2]. */ | |
14092 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
14093 | inst.operands[1] = inst.operands[2]; | |
14094 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
14095 | } | |
14096 | else | |
14097 | { | |
14098 | inst.operands[1] = inst.operands[2]; | |
14099 | inst.operands[2] = inst.operands[0]; | |
14100 | } | |
14101 | } | |
14102 | ||
14103 | static void | |
14104 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
14105 | { | |
14106 | if (inst.operands[2].isreg) | |
14107 | { | |
14108 | if (invert) | |
14109 | neon_exchange_operands (); | |
dcbf9037 | 14110 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
14111 | } |
14112 | else | |
14113 | { | |
037e8744 | 14114 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
14115 | struct neon_type_el et = neon_check_type (2, rs, |
14116 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 | 14117 | |
88714cb8 | 14118 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
14119 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14120 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14121 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14122 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 14123 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14124 | inst.instruction |= (et.type == NT_float) << 10; |
14125 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 14126 | |
88714cb8 | 14127 | neon_dp_fixup (&inst); |
5287ad62 JB |
14128 | } |
14129 | } | |
14130 | ||
14131 | static void | |
14132 | do_neon_cmp (void) | |
14133 | { | |
14134 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
14135 | } | |
14136 | ||
14137 | static void | |
14138 | do_neon_cmp_inv (void) | |
14139 | { | |
14140 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
14141 | } | |
14142 | ||
14143 | static void | |
14144 | do_neon_ceq (void) | |
14145 | { | |
14146 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
14147 | } | |
14148 | ||
14149 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
14150 | scalars, which are encoded in 5 bits, M : Rm. | |
14151 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
14152 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
14153 | index in M. */ | |
14154 | ||
14155 | static unsigned | |
14156 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
14157 | { | |
dcbf9037 JB |
14158 | unsigned regno = NEON_SCALAR_REG (scalar); |
14159 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
14160 | |
14161 | switch (elsize) | |
14162 | { | |
14163 | case 16: | |
14164 | if (regno > 7 || elno > 3) | |
14165 | goto bad_scalar; | |
14166 | return regno | (elno << 3); | |
5f4273c7 | 14167 | |
5287ad62 JB |
14168 | case 32: |
14169 | if (regno > 15 || elno > 1) | |
14170 | goto bad_scalar; | |
14171 | return regno | (elno << 4); | |
14172 | ||
14173 | default: | |
14174 | bad_scalar: | |
dcbf9037 | 14175 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
14176 | } |
14177 | ||
14178 | return 0; | |
14179 | } | |
14180 | ||
14181 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
14182 | ||
14183 | static void | |
14184 | neon_mul_mac (struct neon_type_el et, int ubit) | |
14185 | { | |
dcbf9037 JB |
14186 | unsigned scalar; |
14187 | ||
14188 | /* Give a more helpful error message if we have an invalid type. */ | |
14189 | if (et.type == NT_invtype) | |
14190 | return; | |
5f4273c7 | 14191 | |
dcbf9037 | 14192 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
14193 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14194 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14195 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14196 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14197 | inst.instruction |= LOW4 (scalar); | |
14198 | inst.instruction |= HI1 (scalar) << 5; | |
14199 | inst.instruction |= (et.type == NT_float) << 8; | |
14200 | inst.instruction |= neon_logbits (et.size) << 20; | |
14201 | inst.instruction |= (ubit != 0) << 24; | |
14202 | ||
88714cb8 | 14203 | neon_dp_fixup (&inst); |
5287ad62 JB |
14204 | } |
14205 | ||
14206 | static void | |
14207 | do_neon_mac_maybe_scalar (void) | |
14208 | { | |
037e8744 JB |
14209 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
14210 | return; | |
14211 | ||
14212 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14213 | return; | |
14214 | ||
5287ad62 JB |
14215 | if (inst.operands[2].isscalar) |
14216 | { | |
037e8744 | 14217 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
14218 | struct neon_type_el et = neon_check_type (3, rs, |
14219 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
88714cb8 | 14220 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 14221 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
14222 | } |
14223 | else | |
428e3f1f PB |
14224 | { |
14225 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
14226 | affected if we specify unsigned args. */ | |
14227 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
14228 | } | |
5287ad62 JB |
14229 | } |
14230 | ||
62f3b8c8 PB |
14231 | static void |
14232 | do_neon_fmac (void) | |
14233 | { | |
14234 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
14235 | return; | |
14236 | ||
14237 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14238 | return; | |
14239 | ||
14240 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
14241 | } | |
14242 | ||
5287ad62 JB |
14243 | static void |
14244 | do_neon_tst (void) | |
14245 | { | |
037e8744 | 14246 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14247 | struct neon_type_el et = neon_check_type (3, rs, |
14248 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 14249 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
14250 | } |
14251 | ||
14252 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
14253 | same types as the MAC equivalents. The polynomial type for this instruction | |
14254 | is encoded the same as the integer type. */ | |
14255 | ||
14256 | static void | |
14257 | do_neon_mul (void) | |
14258 | { | |
037e8744 JB |
14259 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
14260 | return; | |
14261 | ||
14262 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14263 | return; | |
14264 | ||
5287ad62 JB |
14265 | if (inst.operands[2].isscalar) |
14266 | do_neon_mac_maybe_scalar (); | |
14267 | else | |
dcbf9037 | 14268 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
14269 | } |
14270 | ||
14271 | static void | |
14272 | do_neon_qdmulh (void) | |
14273 | { | |
14274 | if (inst.operands[2].isscalar) | |
14275 | { | |
037e8744 | 14276 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
14277 | struct neon_type_el et = neon_check_type (3, rs, |
14278 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
88714cb8 | 14279 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 14280 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
14281 | } |
14282 | else | |
14283 | { | |
037e8744 | 14284 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14285 | struct neon_type_el et = neon_check_type (3, rs, |
14286 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
88714cb8 | 14287 | NEON_ENCODE (INTEGER, inst); |
5287ad62 | 14288 | /* The U bit (rounding) comes from bit mask. */ |
037e8744 | 14289 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
14290 | } |
14291 | } | |
14292 | ||
14293 | static void | |
14294 | do_neon_fcmp_absolute (void) | |
14295 | { | |
037e8744 | 14296 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14297 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
14298 | /* Size field comes from bit mask. */ | |
037e8744 | 14299 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
14300 | } |
14301 | ||
14302 | static void | |
14303 | do_neon_fcmp_absolute_inv (void) | |
14304 | { | |
14305 | neon_exchange_operands (); | |
14306 | do_neon_fcmp_absolute (); | |
14307 | } | |
14308 | ||
14309 | static void | |
14310 | do_neon_step (void) | |
14311 | { | |
037e8744 | 14312 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14313 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 14314 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14315 | } |
14316 | ||
14317 | static void | |
14318 | do_neon_abs_neg (void) | |
14319 | { | |
037e8744 JB |
14320 | enum neon_shape rs; |
14321 | struct neon_type_el et; | |
5f4273c7 | 14322 | |
037e8744 JB |
14323 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
14324 | return; | |
14325 | ||
14326 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14327 | return; | |
14328 | ||
14329 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
14330 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
5f4273c7 | 14331 | |
5287ad62 JB |
14332 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14333 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14334 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14335 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 14336 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14337 | inst.instruction |= (et.type == NT_float) << 10; |
14338 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 14339 | |
88714cb8 | 14340 | neon_dp_fixup (&inst); |
5287ad62 JB |
14341 | } |
14342 | ||
14343 | static void | |
14344 | do_neon_sli (void) | |
14345 | { | |
037e8744 | 14346 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14347 | struct neon_type_el et = neon_check_type (2, rs, |
14348 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
14349 | int imm = inst.operands[2].imm; | |
14350 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
14351 | _("immediate out of range for insert")); | |
037e8744 | 14352 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14353 | } |
14354 | ||
14355 | static void | |
14356 | do_neon_sri (void) | |
14357 | { | |
037e8744 | 14358 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14359 | struct neon_type_el et = neon_check_type (2, rs, |
14360 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
14361 | int imm = inst.operands[2].imm; | |
14362 | constraint (imm < 1 || (unsigned)imm > et.size, | |
14363 | _("immediate out of range for insert")); | |
037e8744 | 14364 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
14365 | } |
14366 | ||
14367 | static void | |
14368 | do_neon_qshlu_imm (void) | |
14369 | { | |
037e8744 | 14370 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14371 | struct neon_type_el et = neon_check_type (2, rs, |
14372 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
14373 | int imm = inst.operands[2].imm; | |
14374 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
14375 | _("immediate out of range for shift")); | |
14376 | /* Only encodes the 'U present' variant of the instruction. | |
14377 | In this case, signed types have OP (bit 8) set to 0. | |
14378 | Unsigned types have OP set to 1. */ | |
14379 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
14380 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 14381 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14382 | } |
14383 | ||
14384 | static void | |
14385 | do_neon_qmovn (void) | |
14386 | { | |
14387 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
14388 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
14389 | /* Saturating move where operands can be signed or unsigned, and the | |
14390 | destination has the same signedness. */ | |
88714cb8 | 14391 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14392 | if (et.type == NT_unsigned) |
14393 | inst.instruction |= 0xc0; | |
14394 | else | |
14395 | inst.instruction |= 0x80; | |
14396 | neon_two_same (0, 1, et.size / 2); | |
14397 | } | |
14398 | ||
14399 | static void | |
14400 | do_neon_qmovun (void) | |
14401 | { | |
14402 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
14403 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
14404 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 14405 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14406 | neon_two_same (0, 1, et.size / 2); |
14407 | } | |
14408 | ||
14409 | static void | |
14410 | do_neon_rshift_sat_narrow (void) | |
14411 | { | |
14412 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
14413 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
14414 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
14415 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
14416 | int imm = inst.operands[2].imm; | |
14417 | /* This gets the bounds check, size encoding and immediate bits calculation | |
14418 | right. */ | |
14419 | et.size /= 2; | |
5f4273c7 | 14420 | |
5287ad62 JB |
14421 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
14422 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
14423 | if (imm == 0) | |
14424 | { | |
14425 | inst.operands[2].present = 0; | |
14426 | inst.instruction = N_MNEM_vqmovn; | |
14427 | do_neon_qmovn (); | |
14428 | return; | |
14429 | } | |
5f4273c7 | 14430 | |
5287ad62 JB |
14431 | constraint (imm < 1 || (unsigned)imm > et.size, |
14432 | _("immediate out of range")); | |
14433 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
14434 | } | |
14435 | ||
14436 | static void | |
14437 | do_neon_rshift_sat_narrow_u (void) | |
14438 | { | |
14439 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
14440 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
14441 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
14442 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
14443 | int imm = inst.operands[2].imm; | |
14444 | /* This gets the bounds check, size encoding and immediate bits calculation | |
14445 | right. */ | |
14446 | et.size /= 2; | |
14447 | ||
14448 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
14449 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
14450 | if (imm == 0) | |
14451 | { | |
14452 | inst.operands[2].present = 0; | |
14453 | inst.instruction = N_MNEM_vqmovun; | |
14454 | do_neon_qmovun (); | |
14455 | return; | |
14456 | } | |
14457 | ||
14458 | constraint (imm < 1 || (unsigned)imm > et.size, | |
14459 | _("immediate out of range")); | |
14460 | /* FIXME: The manual is kind of unclear about what value U should have in | |
14461 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
14462 | must be 1. */ | |
14463 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
14464 | } | |
14465 | ||
14466 | static void | |
14467 | do_neon_movn (void) | |
14468 | { | |
14469 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
14470 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 14471 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14472 | neon_two_same (0, 1, et.size / 2); |
14473 | } | |
14474 | ||
14475 | static void | |
14476 | do_neon_rshift_narrow (void) | |
14477 | { | |
14478 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
14479 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
14480 | int imm = inst.operands[2].imm; | |
14481 | /* This gets the bounds check, size encoding and immediate bits calculation | |
14482 | right. */ | |
14483 | et.size /= 2; | |
5f4273c7 | 14484 | |
5287ad62 JB |
14485 | /* If immediate is zero then we are a pseudo-instruction for |
14486 | VMOVN.I<size> <Dd>, <Qm> */ | |
14487 | if (imm == 0) | |
14488 | { | |
14489 | inst.operands[2].present = 0; | |
14490 | inst.instruction = N_MNEM_vmovn; | |
14491 | do_neon_movn (); | |
14492 | return; | |
14493 | } | |
5f4273c7 | 14494 | |
5287ad62 JB |
14495 | constraint (imm < 1 || (unsigned)imm > et.size, |
14496 | _("immediate out of range for narrowing operation")); | |
14497 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
14498 | } | |
14499 | ||
14500 | static void | |
14501 | do_neon_shll (void) | |
14502 | { | |
14503 | /* FIXME: Type checking when lengthening. */ | |
14504 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
14505 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
14506 | unsigned imm = inst.operands[2].imm; | |
14507 | ||
14508 | if (imm == et.size) | |
14509 | { | |
14510 | /* Maximum shift variant. */ | |
88714cb8 | 14511 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14512 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14513 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14514 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14515 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14516 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 14517 | |
88714cb8 | 14518 | neon_dp_fixup (&inst); |
5287ad62 JB |
14519 | } |
14520 | else | |
14521 | { | |
14522 | /* A more-specific type check for non-max versions. */ | |
14523 | et = neon_check_type (2, NS_QDI, | |
14524 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
88714cb8 | 14525 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
14526 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
14527 | } | |
14528 | } | |
14529 | ||
037e8744 | 14530 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
14531 | the current instruction is. */ |
14532 | ||
6b9a8b67 MGD |
14533 | #define CVT_FLAVOUR_VAR \ |
14534 | CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \ | |
14535 | CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \ | |
14536 | CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \ | |
14537 | CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \ | |
14538 | /* Half-precision conversions. */ \ | |
14539 | CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \ | |
14540 | CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \ | |
14541 | /* VFP instructions. */ \ | |
14542 | CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \ | |
14543 | CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \ | |
14544 | CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \ | |
14545 | CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \ | |
14546 | CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \ | |
14547 | CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \ | |
14548 | /* VFP instructions with bitshift. */ \ | |
14549 | CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \ | |
14550 | CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \ | |
14551 | CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \ | |
14552 | CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \ | |
14553 | CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \ | |
14554 | CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \ | |
14555 | CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \ | |
14556 | CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL) | |
14557 | ||
14558 | #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \ | |
14559 | neon_cvt_flavour_##C, | |
14560 | ||
14561 | /* The different types of conversions we can do. */ | |
14562 | enum neon_cvt_flavour | |
14563 | { | |
14564 | CVT_FLAVOUR_VAR | |
14565 | neon_cvt_flavour_invalid, | |
14566 | neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64 | |
14567 | }; | |
14568 | ||
14569 | #undef CVT_VAR | |
14570 | ||
14571 | static enum neon_cvt_flavour | |
14572 | get_neon_cvt_flavour (enum neon_shape rs) | |
5287ad62 | 14573 | { |
6b9a8b67 MGD |
14574 | #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \ |
14575 | et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \ | |
14576 | if (et.type != NT_invtype) \ | |
14577 | { \ | |
14578 | inst.error = NULL; \ | |
14579 | return (neon_cvt_flavour_##C); \ | |
5287ad62 | 14580 | } |
6b9a8b67 | 14581 | |
5287ad62 | 14582 | struct neon_type_el et; |
037e8744 JB |
14583 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
14584 | || rs == NS_FF) ? N_VFP : 0; | |
14585 | /* The instruction versions which take an immediate take one register | |
14586 | argument, which is extended to the width of the full register. Thus the | |
14587 | "source" and "destination" registers must have the same width. Hack that | |
14588 | here by making the size equal to the key (wider, in this case) operand. */ | |
14589 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 14590 | |
6b9a8b67 MGD |
14591 | CVT_FLAVOUR_VAR; |
14592 | ||
14593 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
14594 | #undef CVT_VAR |
14595 | } | |
14596 | ||
7e8e6784 MGD |
14597 | enum neon_cvt_mode |
14598 | { | |
14599 | neon_cvt_mode_a, | |
14600 | neon_cvt_mode_n, | |
14601 | neon_cvt_mode_p, | |
14602 | neon_cvt_mode_m, | |
14603 | neon_cvt_mode_z, | |
30bdf752 MGD |
14604 | neon_cvt_mode_x, |
14605 | neon_cvt_mode_r | |
7e8e6784 MGD |
14606 | }; |
14607 | ||
037e8744 JB |
14608 | /* Neon-syntax VFP conversions. */ |
14609 | ||
5287ad62 | 14610 | static void |
6b9a8b67 | 14611 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 14612 | { |
037e8744 | 14613 | const char *opname = 0; |
5f4273c7 | 14614 | |
037e8744 | 14615 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) |
5287ad62 | 14616 | { |
037e8744 JB |
14617 | /* Conversions with immediate bitshift. */ |
14618 | const char *enc[] = | |
14619 | { | |
6b9a8b67 MGD |
14620 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
14621 | CVT_FLAVOUR_VAR | |
14622 | NULL | |
14623 | #undef CVT_VAR | |
037e8744 JB |
14624 | }; |
14625 | ||
6b9a8b67 | 14626 | if (flavour < (int) ARRAY_SIZE (enc)) |
037e8744 JB |
14627 | { |
14628 | opname = enc[flavour]; | |
14629 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
14630 | _("operands 0 and 1 must be the same register")); | |
14631 | inst.operands[1] = inst.operands[2]; | |
14632 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
14633 | } | |
5287ad62 JB |
14634 | } |
14635 | else | |
14636 | { | |
037e8744 JB |
14637 | /* Conversions without bitshift. */ |
14638 | const char *enc[] = | |
14639 | { | |
6b9a8b67 MGD |
14640 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
14641 | CVT_FLAVOUR_VAR | |
14642 | NULL | |
14643 | #undef CVT_VAR | |
037e8744 JB |
14644 | }; |
14645 | ||
6b9a8b67 | 14646 | if (flavour < (int) ARRAY_SIZE (enc)) |
037e8744 JB |
14647 | opname = enc[flavour]; |
14648 | } | |
14649 | ||
14650 | if (opname) | |
14651 | do_vfp_nsyn_opcode (opname); | |
14652 | } | |
14653 | ||
14654 | static void | |
14655 | do_vfp_nsyn_cvtz (void) | |
14656 | { | |
14657 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
6b9a8b67 | 14658 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
14659 | const char *enc[] = |
14660 | { | |
6b9a8b67 MGD |
14661 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
14662 | CVT_FLAVOUR_VAR | |
14663 | NULL | |
14664 | #undef CVT_VAR | |
037e8744 JB |
14665 | }; |
14666 | ||
6b9a8b67 | 14667 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
14668 | do_vfp_nsyn_opcode (enc[flavour]); |
14669 | } | |
f31fef98 | 14670 | |
037e8744 | 14671 | static void |
bacebabc | 14672 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
14673 | enum neon_cvt_mode mode) |
14674 | { | |
14675 | int sz, op; | |
14676 | int rm; | |
14677 | ||
14678 | set_it_insn_type (OUTSIDE_IT_INSN); | |
14679 | ||
14680 | switch (flavour) | |
14681 | { | |
14682 | case neon_cvt_flavour_s32_f64: | |
14683 | sz = 1; | |
14684 | op = 0; | |
14685 | break; | |
14686 | case neon_cvt_flavour_s32_f32: | |
14687 | sz = 0; | |
14688 | op = 1; | |
14689 | break; | |
14690 | case neon_cvt_flavour_u32_f64: | |
14691 | sz = 1; | |
14692 | op = 0; | |
14693 | break; | |
14694 | case neon_cvt_flavour_u32_f32: | |
14695 | sz = 0; | |
14696 | op = 0; | |
14697 | break; | |
14698 | default: | |
14699 | first_error (_("invalid instruction shape")); | |
14700 | return; | |
14701 | } | |
14702 | ||
14703 | switch (mode) | |
14704 | { | |
14705 | case neon_cvt_mode_a: rm = 0; break; | |
14706 | case neon_cvt_mode_n: rm = 1; break; | |
14707 | case neon_cvt_mode_p: rm = 2; break; | |
14708 | case neon_cvt_mode_m: rm = 3; break; | |
14709 | default: first_error (_("invalid rounding mode")); return; | |
14710 | } | |
14711 | ||
14712 | NEON_ENCODE (FPV8, inst); | |
14713 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
14714 | encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm); | |
14715 | inst.instruction |= sz << 8; | |
14716 | inst.instruction |= op << 7; | |
14717 | inst.instruction |= rm << 16; | |
14718 | inst.instruction |= 0xf0000000; | |
14719 | inst.is_neon = TRUE; | |
14720 | } | |
14721 | ||
14722 | static void | |
14723 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
14724 | { |
14725 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
8e79c3df | 14726 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL); |
6b9a8b67 | 14727 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 14728 | |
e3e535bc | 14729 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 14730 | if (mode == neon_cvt_mode_z |
e3e535bc | 14731 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
bacebabc RM |
14732 | && (flavour == neon_cvt_flavour_s32_f32 |
14733 | || flavour == neon_cvt_flavour_u32_f32 | |
14734 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 14735 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
14736 | && (rs == NS_FD || rs == NS_FF)) |
14737 | { | |
14738 | do_vfp_nsyn_cvtz (); | |
14739 | return; | |
14740 | } | |
14741 | ||
037e8744 | 14742 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 14743 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 14744 | { |
7e8e6784 MGD |
14745 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
14746 | do_vfp_nsyn_cvt (rs, flavour); | |
14747 | else | |
14748 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
14749 | ||
037e8744 JB |
14750 | return; |
14751 | } | |
14752 | ||
14753 | switch (rs) | |
14754 | { | |
14755 | case NS_DDI: | |
14756 | case NS_QQI: | |
14757 | { | |
35997600 NC |
14758 | unsigned immbits; |
14759 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
14760 | ||
037e8744 JB |
14761 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
14762 | return; | |
14763 | ||
14764 | /* Fixed-point conversion with #0 immediate is encoded as an | |
14765 | integer conversion. */ | |
14766 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
14767 | goto int_encode; | |
35997600 | 14768 | immbits = 32 - inst.operands[2].imm; |
88714cb8 | 14769 | NEON_ENCODE (IMMED, inst); |
6b9a8b67 | 14770 | if (flavour != neon_cvt_flavour_invalid) |
037e8744 JB |
14771 | inst.instruction |= enctab[flavour]; |
14772 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14773 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14774 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14775 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14776 | inst.instruction |= neon_quad (rs) << 6; | |
14777 | inst.instruction |= 1 << 21; | |
14778 | inst.instruction |= immbits << 16; | |
14779 | ||
88714cb8 | 14780 | neon_dp_fixup (&inst); |
037e8744 JB |
14781 | } |
14782 | break; | |
14783 | ||
14784 | case NS_DD: | |
14785 | case NS_QQ: | |
7e8e6784 MGD |
14786 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
14787 | { | |
14788 | NEON_ENCODE (FLOAT, inst); | |
14789 | set_it_insn_type (OUTSIDE_IT_INSN); | |
14790 | ||
14791 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
14792 | return; | |
14793 | ||
14794 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14795 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14796 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14797 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14798 | inst.instruction |= neon_quad (rs) << 6; | |
14799 | inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7; | |
14800 | inst.instruction |= mode << 8; | |
14801 | if (thumb_mode) | |
14802 | inst.instruction |= 0xfc000000; | |
14803 | else | |
14804 | inst.instruction |= 0xf0000000; | |
14805 | } | |
14806 | else | |
14807 | { | |
037e8744 | 14808 | int_encode: |
7e8e6784 MGD |
14809 | { |
14810 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
037e8744 | 14811 | |
7e8e6784 | 14812 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14813 | |
7e8e6784 MGD |
14814 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
14815 | return; | |
037e8744 | 14816 | |
7e8e6784 MGD |
14817 | if (flavour != neon_cvt_flavour_invalid) |
14818 | inst.instruction |= enctab[flavour]; | |
037e8744 | 14819 | |
7e8e6784 MGD |
14820 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14821 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14822 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14823 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14824 | inst.instruction |= neon_quad (rs) << 6; | |
14825 | inst.instruction |= 2 << 18; | |
037e8744 | 14826 | |
7e8e6784 MGD |
14827 | neon_dp_fixup (&inst); |
14828 | } | |
14829 | } | |
14830 | break; | |
037e8744 | 14831 | |
8e79c3df CM |
14832 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
14833 | case NS_QD: | |
14834 | case NS_DQ: | |
14835 | ||
14836 | if ((rs == NS_DQ) | |
14837 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
14838 | { | |
14839 | as_bad (_("operand size must match register width")); | |
14840 | break; | |
14841 | } | |
14842 | ||
14843 | if ((rs == NS_QD) | |
14844 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
14845 | { | |
14846 | as_bad (_("operand size must match register width")); | |
14847 | break; | |
14848 | } | |
14849 | ||
14850 | if (rs == NS_DQ) | |
14851 | inst.instruction = 0x3b60600; | |
14852 | else | |
14853 | inst.instruction = 0x3b60700; | |
14854 | ||
14855 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14856 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14857 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14858 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 14859 | neon_dp_fixup (&inst); |
8e79c3df CM |
14860 | break; |
14861 | ||
037e8744 JB |
14862 | default: |
14863 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
14864 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
14865 | do_vfp_nsyn_cvt (rs, flavour); | |
14866 | else | |
14867 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
5287ad62 | 14868 | } |
5287ad62 JB |
14869 | } |
14870 | ||
e3e535bc NC |
14871 | static void |
14872 | do_neon_cvtr (void) | |
14873 | { | |
7e8e6784 | 14874 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
14875 | } |
14876 | ||
14877 | static void | |
14878 | do_neon_cvt (void) | |
14879 | { | |
7e8e6784 MGD |
14880 | do_neon_cvt_1 (neon_cvt_mode_z); |
14881 | } | |
14882 | ||
14883 | static void | |
14884 | do_neon_cvta (void) | |
14885 | { | |
14886 | do_neon_cvt_1 (neon_cvt_mode_a); | |
14887 | } | |
14888 | ||
14889 | static void | |
14890 | do_neon_cvtn (void) | |
14891 | { | |
14892 | do_neon_cvt_1 (neon_cvt_mode_n); | |
14893 | } | |
14894 | ||
14895 | static void | |
14896 | do_neon_cvtp (void) | |
14897 | { | |
14898 | do_neon_cvt_1 (neon_cvt_mode_p); | |
14899 | } | |
14900 | ||
14901 | static void | |
14902 | do_neon_cvtm (void) | |
14903 | { | |
14904 | do_neon_cvt_1 (neon_cvt_mode_m); | |
e3e535bc NC |
14905 | } |
14906 | ||
8e79c3df | 14907 | static void |
c70a8987 | 14908 | do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double) |
8e79c3df | 14909 | { |
c70a8987 MGD |
14910 | if (is_double) |
14911 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 14912 | |
c70a8987 MGD |
14913 | encode_arm_vfp_reg (inst.operands[0].reg, |
14914 | (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd); | |
14915 | encode_arm_vfp_reg (inst.operands[1].reg, | |
14916 | (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm); | |
14917 | inst.instruction |= to ? 0x10000 : 0; | |
14918 | inst.instruction |= t ? 0x80 : 0; | |
14919 | inst.instruction |= is_double ? 0x100 : 0; | |
14920 | do_vfp_cond_or_thumb (); | |
14921 | } | |
8e79c3df | 14922 | |
c70a8987 MGD |
14923 | static void |
14924 | do_neon_cvttb_1 (bfd_boolean t) | |
14925 | { | |
14926 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL); | |
8e79c3df | 14927 | |
c70a8987 MGD |
14928 | if (rs == NS_NULL) |
14929 | return; | |
14930 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) | |
14931 | { | |
14932 | inst.error = NULL; | |
14933 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE); | |
14934 | } | |
14935 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
14936 | { | |
14937 | inst.error = NULL; | |
14938 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE); | |
14939 | } | |
14940 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
14941 | { | |
14942 | inst.error = NULL; | |
14943 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE); | |
14944 | } | |
14945 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
14946 | { | |
14947 | inst.error = NULL; | |
14948 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE); | |
14949 | } | |
14950 | else | |
14951 | return; | |
14952 | } | |
14953 | ||
14954 | static void | |
14955 | do_neon_cvtb (void) | |
14956 | { | |
14957 | do_neon_cvttb_1 (FALSE); | |
8e79c3df CM |
14958 | } |
14959 | ||
14960 | ||
14961 | static void | |
14962 | do_neon_cvtt (void) | |
14963 | { | |
c70a8987 | 14964 | do_neon_cvttb_1 (TRUE); |
8e79c3df CM |
14965 | } |
14966 | ||
5287ad62 JB |
14967 | static void |
14968 | neon_move_immediate (void) | |
14969 | { | |
037e8744 JB |
14970 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
14971 | struct neon_type_el et = neon_check_type (2, rs, | |
14972 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 14973 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 14974 | int op, cmode, float_p; |
5287ad62 | 14975 | |
037e8744 JB |
14976 | constraint (et.type == NT_invtype, |
14977 | _("operand size must be specified for immediate VMOV")); | |
14978 | ||
5287ad62 JB |
14979 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
14980 | op = (inst.instruction & (1 << 5)) != 0; | |
14981 | ||
14982 | immlo = inst.operands[1].imm; | |
14983 | if (inst.operands[1].regisimm) | |
14984 | immhi = inst.operands[1].reg; | |
14985 | ||
14986 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
14987 | _("immediate has bits set outside the operand size")); | |
14988 | ||
c96612cc JB |
14989 | float_p = inst.operands[1].immisfloat; |
14990 | ||
14991 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
136da414 | 14992 | et.size, et.type)) == FAIL) |
5287ad62 JB |
14993 | { |
14994 | /* Invert relevant bits only. */ | |
14995 | neon_invert_size (&immlo, &immhi, et.size); | |
14996 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
14997 | with one or the other; those cases are caught by | |
14998 | neon_cmode_for_move_imm. */ | |
14999 | op = !op; | |
c96612cc JB |
15000 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
15001 | &op, et.size, et.type)) == FAIL) | |
5287ad62 | 15002 | { |
dcbf9037 | 15003 | first_error (_("immediate out of range")); |
5287ad62 JB |
15004 | return; |
15005 | } | |
15006 | } | |
15007 | ||
15008 | inst.instruction &= ~(1 << 5); | |
15009 | inst.instruction |= op << 5; | |
15010 | ||
15011 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15012 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 15013 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15014 | inst.instruction |= cmode << 8; |
15015 | ||
15016 | neon_write_immbits (immbits); | |
15017 | } | |
15018 | ||
15019 | static void | |
15020 | do_neon_mvn (void) | |
15021 | { | |
15022 | if (inst.operands[1].isreg) | |
15023 | { | |
037e8744 | 15024 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 15025 | |
88714cb8 | 15026 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15027 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15028 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15029 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15030 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15031 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15032 | } |
15033 | else | |
15034 | { | |
88714cb8 | 15035 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15036 | neon_move_immediate (); |
15037 | } | |
15038 | ||
88714cb8 | 15039 | neon_dp_fixup (&inst); |
5287ad62 JB |
15040 | } |
15041 | ||
15042 | /* Encode instructions of form: | |
15043 | ||
15044 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 15045 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
15046 | |
15047 | static void | |
15048 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
15049 | { | |
15050 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15051 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15052 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15053 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15054 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15055 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15056 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
15057 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 15058 | |
88714cb8 | 15059 | neon_dp_fixup (&inst); |
5287ad62 JB |
15060 | } |
15061 | ||
15062 | static void | |
15063 | do_neon_dyadic_long (void) | |
15064 | { | |
15065 | /* FIXME: Type checking for lengthening op. */ | |
15066 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15067 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
15068 | neon_mixed_length (et, et.size); | |
15069 | } | |
15070 | ||
15071 | static void | |
15072 | do_neon_abal (void) | |
15073 | { | |
15074 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15075 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
15076 | neon_mixed_length (et, et.size); | |
15077 | } | |
15078 | ||
15079 | static void | |
15080 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
15081 | { | |
15082 | if (inst.operands[2].isscalar) | |
15083 | { | |
dcbf9037 JB |
15084 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
15085 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
88714cb8 | 15086 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
15087 | neon_mul_mac (et, et.type == NT_unsigned); |
15088 | } | |
15089 | else | |
15090 | { | |
15091 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15092 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
88714cb8 | 15093 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15094 | neon_mixed_length (et, et.size); |
15095 | } | |
15096 | } | |
15097 | ||
15098 | static void | |
15099 | do_neon_mac_maybe_scalar_long (void) | |
15100 | { | |
15101 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
15102 | } | |
15103 | ||
15104 | static void | |
15105 | do_neon_dyadic_wide (void) | |
15106 | { | |
15107 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
15108 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
15109 | neon_mixed_length (et, et.size); | |
15110 | } | |
15111 | ||
15112 | static void | |
15113 | do_neon_dyadic_narrow (void) | |
15114 | { | |
15115 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15116 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
15117 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
15118 | so force the operand type to integer. */ | |
15119 | et.type = NT_integer; | |
5287ad62 JB |
15120 | neon_mixed_length (et, et.size / 2); |
15121 | } | |
15122 | ||
15123 | static void | |
15124 | do_neon_mul_sat_scalar_long (void) | |
15125 | { | |
15126 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
15127 | } | |
15128 | ||
15129 | static void | |
15130 | do_neon_vmull (void) | |
15131 | { | |
15132 | if (inst.operands[2].isscalar) | |
15133 | do_neon_mac_maybe_scalar_long (); | |
15134 | else | |
15135 | { | |
15136 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
4f51b4bd MGD |
15137 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
15138 | ||
5287ad62 | 15139 | if (et.type == NT_poly) |
88714cb8 | 15140 | NEON_ENCODE (POLY, inst); |
5287ad62 | 15141 | else |
88714cb8 | 15142 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
15143 | |
15144 | /* For polynomial encoding the U bit must be zero, and the size must | |
15145 | be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non | |
15146 | obviously, as 0b10). */ | |
15147 | if (et.size == 64) | |
15148 | { | |
15149 | /* Check we're on the correct architecture. */ | |
15150 | if (!mark_feature_used (&fpu_crypto_ext_armv8)) | |
15151 | inst.error = | |
15152 | _("Instruction form not available on this architecture."); | |
15153 | ||
15154 | et.size = 32; | |
15155 | } | |
15156 | ||
5287ad62 JB |
15157 | neon_mixed_length (et, et.size); |
15158 | } | |
15159 | } | |
15160 | ||
15161 | static void | |
15162 | do_neon_ext (void) | |
15163 | { | |
037e8744 | 15164 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
15165 | struct neon_type_el et = neon_check_type (3, rs, |
15166 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15167 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
15168 | |
15169 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
15170 | _("shift out of range")); | |
5287ad62 JB |
15171 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15172 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15173 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15174 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15175 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15176 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 15177 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 15178 | inst.instruction |= imm << 8; |
5f4273c7 | 15179 | |
88714cb8 | 15180 | neon_dp_fixup (&inst); |
5287ad62 JB |
15181 | } |
15182 | ||
15183 | static void | |
15184 | do_neon_rev (void) | |
15185 | { | |
037e8744 | 15186 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15187 | struct neon_type_el et = neon_check_type (2, rs, |
15188 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
15189 | unsigned op = (inst.instruction >> 7) & 3; | |
15190 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
15191 | extract it here to check the elements to be reversed are smaller. | |
15192 | Otherwise we'd get a reserved instruction. */ | |
15193 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 15194 | gas_assert (elsize != 0); |
5287ad62 JB |
15195 | constraint (et.size >= elsize, |
15196 | _("elements must be smaller than reversal region")); | |
037e8744 | 15197 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15198 | } |
15199 | ||
15200 | static void | |
15201 | do_neon_dup (void) | |
15202 | { | |
15203 | if (inst.operands[1].isscalar) | |
15204 | { | |
037e8744 | 15205 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
15206 | struct neon_type_el et = neon_check_type (2, rs, |
15207 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 15208 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 15209 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 15210 | int logsize = neon_logbits (et.size); |
dcbf9037 | 15211 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
15212 | |
15213 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
15214 | return; | |
15215 | ||
88714cb8 | 15216 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
15217 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15218 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15219 | inst.instruction |= LOW4 (dm); | |
15220 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 15221 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15222 | inst.instruction |= x << 17; |
15223 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 15224 | |
88714cb8 | 15225 | neon_dp_fixup (&inst); |
5287ad62 JB |
15226 | } |
15227 | else | |
15228 | { | |
037e8744 JB |
15229 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
15230 | struct neon_type_el et = neon_check_type (2, rs, | |
15231 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 | 15232 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 15233 | NEON_ENCODE (ARMREG, inst); |
5287ad62 JB |
15234 | switch (et.size) |
15235 | { | |
15236 | case 8: inst.instruction |= 0x400000; break; | |
15237 | case 16: inst.instruction |= 0x000020; break; | |
15238 | case 32: inst.instruction |= 0x000000; break; | |
15239 | default: break; | |
15240 | } | |
15241 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
15242 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
15243 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 15244 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
15245 | /* The encoding for this instruction is identical for the ARM and Thumb |
15246 | variants, except for the condition field. */ | |
037e8744 | 15247 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
15248 | } |
15249 | } | |
15250 | ||
15251 | /* VMOV has particularly many variations. It can be one of: | |
15252 | 0. VMOV<c><q> <Qd>, <Qm> | |
15253 | 1. VMOV<c><q> <Dd>, <Dm> | |
15254 | (Register operations, which are VORR with Rm = Rn.) | |
15255 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
15256 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
15257 | (Immediate loads.) | |
15258 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
15259 | (ARM register to scalar.) | |
15260 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
15261 | (Two ARM registers to vector.) | |
15262 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
15263 | (Scalar to ARM register.) | |
15264 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
15265 | (Vector to two ARM registers.) | |
037e8744 JB |
15266 | 8. VMOV.F32 <Sd>, <Sm> |
15267 | 9. VMOV.F64 <Dd>, <Dm> | |
15268 | (VFP register moves.) | |
15269 | 10. VMOV.F32 <Sd>, #imm | |
15270 | 11. VMOV.F64 <Dd>, #imm | |
15271 | (VFP float immediate load.) | |
15272 | 12. VMOV <Rd>, <Sm> | |
15273 | (VFP single to ARM reg.) | |
15274 | 13. VMOV <Sd>, <Rm> | |
15275 | (ARM reg to VFP single.) | |
15276 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
15277 | (Two ARM regs to two VFP singles.) | |
15278 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
15279 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 15280 | |
037e8744 JB |
15281 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
15282 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 15283 | |
5287ad62 | 15284 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 15285 | |
b7fc2769 JB |
15286 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
15287 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 15288 | |
5287ad62 | 15289 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 15290 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
15291 | |
15292 | static void | |
15293 | do_neon_mov (void) | |
15294 | { | |
037e8744 JB |
15295 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
15296 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
15297 | NS_NULL); | |
15298 | struct neon_type_el et; | |
15299 | const char *ldconst = 0; | |
5287ad62 | 15300 | |
037e8744 | 15301 | switch (rs) |
5287ad62 | 15302 | { |
037e8744 JB |
15303 | case NS_DD: /* case 1/9. */ |
15304 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
15305 | /* It is not an error here if no type is given. */ | |
15306 | inst.error = NULL; | |
15307 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 15308 | { |
037e8744 JB |
15309 | do_vfp_nsyn_opcode ("fcpyd"); |
15310 | break; | |
5287ad62 | 15311 | } |
037e8744 | 15312 | /* fall through. */ |
5287ad62 | 15313 | |
037e8744 JB |
15314 | case NS_QQ: /* case 0/1. */ |
15315 | { | |
15316 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15317 | return; | |
15318 | /* The architecture manual I have doesn't explicitly state which | |
15319 | value the U bit should have for register->register moves, but | |
15320 | the equivalent VORR instruction has U = 0, so do that. */ | |
15321 | inst.instruction = 0x0200110; | |
15322 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15323 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15324 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15325 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15326 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15327 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15328 | inst.instruction |= neon_quad (rs) << 6; | |
15329 | ||
88714cb8 | 15330 | neon_dp_fixup (&inst); |
037e8744 JB |
15331 | } |
15332 | break; | |
5f4273c7 | 15333 | |
037e8744 JB |
15334 | case NS_DI: /* case 3/11. */ |
15335 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
15336 | inst.error = NULL; | |
15337 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 15338 | { |
037e8744 JB |
15339 | /* case 11 (fconstd). */ |
15340 | ldconst = "fconstd"; | |
15341 | goto encode_fconstd; | |
5287ad62 | 15342 | } |
037e8744 JB |
15343 | /* fall through. */ |
15344 | ||
15345 | case NS_QI: /* case 2/3. */ | |
15346 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15347 | return; | |
15348 | inst.instruction = 0x0800010; | |
15349 | neon_move_immediate (); | |
88714cb8 | 15350 | neon_dp_fixup (&inst); |
5287ad62 | 15351 | break; |
5f4273c7 | 15352 | |
037e8744 JB |
15353 | case NS_SR: /* case 4. */ |
15354 | { | |
15355 | unsigned bcdebits = 0; | |
91d6fa6a | 15356 | int logsize; |
037e8744 JB |
15357 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); |
15358 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
15359 | ||
91d6fa6a NC |
15360 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
15361 | logsize = neon_logbits (et.size); | |
15362 | ||
037e8744 JB |
15363 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), |
15364 | _(BAD_FPU)); | |
15365 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
15366 | && et.size != 32, _(BAD_FPU)); | |
15367 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
15368 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
15369 | ||
15370 | switch (et.size) | |
15371 | { | |
15372 | case 8: bcdebits = 0x8; break; | |
15373 | case 16: bcdebits = 0x1; break; | |
15374 | case 32: bcdebits = 0x0; break; | |
15375 | default: ; | |
15376 | } | |
15377 | ||
15378 | bcdebits |= x << logsize; | |
15379 | ||
15380 | inst.instruction = 0xe000b10; | |
15381 | do_vfp_cond_or_thumb (); | |
15382 | inst.instruction |= LOW4 (dn) << 16; | |
15383 | inst.instruction |= HI1 (dn) << 7; | |
15384 | inst.instruction |= inst.operands[1].reg << 12; | |
15385 | inst.instruction |= (bcdebits & 3) << 5; | |
15386 | inst.instruction |= (bcdebits >> 2) << 21; | |
15387 | } | |
15388 | break; | |
5f4273c7 | 15389 | |
037e8744 | 15390 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 15391 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 15392 | _(BAD_FPU)); |
b7fc2769 | 15393 | |
037e8744 JB |
15394 | inst.instruction = 0xc400b10; |
15395 | do_vfp_cond_or_thumb (); | |
15396 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
15397 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
15398 | inst.instruction |= inst.operands[1].reg << 12; | |
15399 | inst.instruction |= inst.operands[2].reg << 16; | |
15400 | break; | |
5f4273c7 | 15401 | |
037e8744 JB |
15402 | case NS_RS: /* case 6. */ |
15403 | { | |
91d6fa6a | 15404 | unsigned logsize; |
037e8744 JB |
15405 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); |
15406 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
15407 | unsigned abcdebits = 0; | |
15408 | ||
91d6fa6a NC |
15409 | et = neon_check_type (2, NS_NULL, |
15410 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
15411 | logsize = neon_logbits (et.size); | |
15412 | ||
037e8744 JB |
15413 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), |
15414 | _(BAD_FPU)); | |
15415 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
15416 | && et.size != 32, _(BAD_FPU)); | |
15417 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
15418 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
15419 | ||
15420 | switch (et.size) | |
15421 | { | |
15422 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
15423 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
15424 | case 32: abcdebits = 0x00; break; | |
15425 | default: ; | |
15426 | } | |
15427 | ||
15428 | abcdebits |= x << logsize; | |
15429 | inst.instruction = 0xe100b10; | |
15430 | do_vfp_cond_or_thumb (); | |
15431 | inst.instruction |= LOW4 (dn) << 16; | |
15432 | inst.instruction |= HI1 (dn) << 7; | |
15433 | inst.instruction |= inst.operands[0].reg << 12; | |
15434 | inst.instruction |= (abcdebits & 3) << 5; | |
15435 | inst.instruction |= (abcdebits >> 2) << 21; | |
15436 | } | |
15437 | break; | |
5f4273c7 | 15438 | |
037e8744 JB |
15439 | case NS_RRD: /* case 7 (fmrrd). */ |
15440 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
15441 | _(BAD_FPU)); | |
15442 | ||
15443 | inst.instruction = 0xc500b10; | |
15444 | do_vfp_cond_or_thumb (); | |
15445 | inst.instruction |= inst.operands[0].reg << 12; | |
15446 | inst.instruction |= inst.operands[1].reg << 16; | |
15447 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15448 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15449 | break; | |
5f4273c7 | 15450 | |
037e8744 JB |
15451 | case NS_FF: /* case 8 (fcpys). */ |
15452 | do_vfp_nsyn_opcode ("fcpys"); | |
15453 | break; | |
5f4273c7 | 15454 | |
037e8744 JB |
15455 | case NS_FI: /* case 10 (fconsts). */ |
15456 | ldconst = "fconsts"; | |
15457 | encode_fconstd: | |
15458 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 15459 | { |
037e8744 JB |
15460 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
15461 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
15462 | } |
15463 | else | |
037e8744 JB |
15464 | first_error (_("immediate out of range")); |
15465 | break; | |
5f4273c7 | 15466 | |
037e8744 JB |
15467 | case NS_RF: /* case 12 (fmrs). */ |
15468 | do_vfp_nsyn_opcode ("fmrs"); | |
15469 | break; | |
5f4273c7 | 15470 | |
037e8744 JB |
15471 | case NS_FR: /* case 13 (fmsr). */ |
15472 | do_vfp_nsyn_opcode ("fmsr"); | |
15473 | break; | |
5f4273c7 | 15474 | |
037e8744 JB |
15475 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
15476 | (one of which is a list), but we have parsed four. Do some fiddling to | |
15477 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
15478 | expect. */ | |
15479 | case NS_RRFF: /* case 14 (fmrrs). */ | |
15480 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
15481 | _("VFP registers must be adjacent")); | |
15482 | inst.operands[2].imm = 2; | |
15483 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
15484 | do_vfp_nsyn_opcode ("fmrrs"); | |
15485 | break; | |
5f4273c7 | 15486 | |
037e8744 JB |
15487 | case NS_FFRR: /* case 15 (fmsrr). */ |
15488 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
15489 | _("VFP registers must be adjacent")); | |
15490 | inst.operands[1] = inst.operands[2]; | |
15491 | inst.operands[2] = inst.operands[3]; | |
15492 | inst.operands[0].imm = 2; | |
15493 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
15494 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 15495 | break; |
5f4273c7 | 15496 | |
4c261dff NC |
15497 | case NS_NULL: |
15498 | /* neon_select_shape has determined that the instruction | |
15499 | shape is wrong and has already set the error message. */ | |
15500 | break; | |
15501 | ||
5287ad62 JB |
15502 | default: |
15503 | abort (); | |
15504 | } | |
15505 | } | |
15506 | ||
15507 | static void | |
15508 | do_neon_rshift_round_imm (void) | |
15509 | { | |
037e8744 | 15510 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15511 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
15512 | int imm = inst.operands[2].imm; | |
15513 | ||
15514 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
15515 | if (imm == 0) | |
15516 | { | |
15517 | inst.operands[2].present = 0; | |
15518 | do_neon_mov (); | |
15519 | return; | |
15520 | } | |
15521 | ||
15522 | constraint (imm < 1 || (unsigned)imm > et.size, | |
15523 | _("immediate out of range for shift")); | |
037e8744 | 15524 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
15525 | et.size - imm); |
15526 | } | |
15527 | ||
15528 | static void | |
15529 | do_neon_movl (void) | |
15530 | { | |
15531 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
15532 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
15533 | unsigned sizebits = et.size >> 3; | |
15534 | inst.instruction |= sizebits << 19; | |
15535 | neon_two_same (0, et.type == NT_unsigned, -1); | |
15536 | } | |
15537 | ||
15538 | static void | |
15539 | do_neon_trn (void) | |
15540 | { | |
037e8744 | 15541 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15542 | struct neon_type_el et = neon_check_type (2, rs, |
15543 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 15544 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15545 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15546 | } |
15547 | ||
15548 | static void | |
15549 | do_neon_zip_uzp (void) | |
15550 | { | |
037e8744 | 15551 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15552 | struct neon_type_el et = neon_check_type (2, rs, |
15553 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
15554 | if (rs == NS_DD && et.size == 32) | |
15555 | { | |
15556 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
15557 | inst.instruction = N_MNEM_vtrn; | |
15558 | do_neon_trn (); | |
15559 | return; | |
15560 | } | |
037e8744 | 15561 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15562 | } |
15563 | ||
15564 | static void | |
15565 | do_neon_sat_abs_neg (void) | |
15566 | { | |
037e8744 | 15567 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15568 | struct neon_type_el et = neon_check_type (2, rs, |
15569 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 15570 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15571 | } |
15572 | ||
15573 | static void | |
15574 | do_neon_pair_long (void) | |
15575 | { | |
037e8744 | 15576 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15577 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
15578 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
15579 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 15580 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15581 | } |
15582 | ||
15583 | static void | |
15584 | do_neon_recip_est (void) | |
15585 | { | |
037e8744 | 15586 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15587 | struct neon_type_el et = neon_check_type (2, rs, |
15588 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
15589 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 15590 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15591 | } |
15592 | ||
15593 | static void | |
15594 | do_neon_cls (void) | |
15595 | { | |
037e8744 | 15596 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15597 | struct neon_type_el et = neon_check_type (2, rs, |
15598 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 15599 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15600 | } |
15601 | ||
15602 | static void | |
15603 | do_neon_clz (void) | |
15604 | { | |
037e8744 | 15605 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15606 | struct neon_type_el et = neon_check_type (2, rs, |
15607 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 15608 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15609 | } |
15610 | ||
15611 | static void | |
15612 | do_neon_cnt (void) | |
15613 | { | |
037e8744 | 15614 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15615 | struct neon_type_el et = neon_check_type (2, rs, |
15616 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 15617 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15618 | } |
15619 | ||
15620 | static void | |
15621 | do_neon_swp (void) | |
15622 | { | |
037e8744 JB |
15623 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
15624 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
15625 | } |
15626 | ||
15627 | static void | |
15628 | do_neon_tbl_tbx (void) | |
15629 | { | |
15630 | unsigned listlenbits; | |
dcbf9037 | 15631 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 15632 | |
5287ad62 JB |
15633 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
15634 | { | |
dcbf9037 | 15635 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
15636 | return; |
15637 | } | |
5f4273c7 | 15638 | |
5287ad62 JB |
15639 | listlenbits = inst.operands[1].imm - 1; |
15640 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15641 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15642 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15643 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15644 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15645 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15646 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 15647 | |
88714cb8 | 15648 | neon_dp_fixup (&inst); |
5287ad62 JB |
15649 | } |
15650 | ||
15651 | static void | |
15652 | do_neon_ldm_stm (void) | |
15653 | { | |
15654 | /* P, U and L bits are part of bitmask. */ | |
15655 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
15656 | unsigned offsetbits = inst.operands[1].imm * 2; | |
15657 | ||
037e8744 JB |
15658 | if (inst.operands[1].issingle) |
15659 | { | |
15660 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
15661 | return; | |
15662 | } | |
15663 | ||
5287ad62 JB |
15664 | constraint (is_dbmode && !inst.operands[0].writeback, |
15665 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
15666 | ||
15667 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
15668 | _("register list must contain at least 1 and at most 16 " | |
15669 | "registers")); | |
15670 | ||
15671 | inst.instruction |= inst.operands[0].reg << 16; | |
15672 | inst.instruction |= inst.operands[0].writeback << 21; | |
15673 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
15674 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
15675 | ||
15676 | inst.instruction |= offsetbits; | |
5f4273c7 | 15677 | |
037e8744 | 15678 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
15679 | } |
15680 | ||
15681 | static void | |
15682 | do_neon_ldr_str (void) | |
15683 | { | |
5287ad62 | 15684 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 15685 | |
6844b2c2 MGD |
15686 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
15687 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 15688 | if (!is_ldr |
6844b2c2 MGD |
15689 | && inst.operands[1].reg == REG_PC |
15690 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
15691 | { | |
15692 | if (!thumb_mode && warn_on_deprecated) | |
15693 | as_warn (_("Use of PC here is deprecated")); | |
15694 | else | |
15695 | inst.error = _("Use of PC here is UNPREDICTABLE"); | |
15696 | } | |
15697 | ||
037e8744 JB |
15698 | if (inst.operands[0].issingle) |
15699 | { | |
cd2f129f JB |
15700 | if (is_ldr) |
15701 | do_vfp_nsyn_opcode ("flds"); | |
15702 | else | |
15703 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
15704 | } |
15705 | else | |
5287ad62 | 15706 | { |
cd2f129f JB |
15707 | if (is_ldr) |
15708 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 15709 | else |
cd2f129f | 15710 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 15711 | } |
5287ad62 JB |
15712 | } |
15713 | ||
15714 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
15715 | instructions. */ | |
15716 | ||
15717 | static void | |
15718 | do_neon_ld_st_interleave (void) | |
15719 | { | |
037e8744 | 15720 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
15721 | N_8 | N_16 | N_32 | N_64); |
15722 | unsigned alignbits = 0; | |
15723 | unsigned idx; | |
15724 | /* The bits in this table go: | |
15725 | 0: register stride of one (0) or two (1) | |
15726 | 1,2: register list length, minus one (1, 2, 3, 4). | |
15727 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
15728 | We use -1 for invalid entries. */ | |
15729 | const int typetable[] = | |
15730 | { | |
15731 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
15732 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
15733 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
15734 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
15735 | }; | |
15736 | int typebits; | |
15737 | ||
dcbf9037 JB |
15738 | if (et.type == NT_invtype) |
15739 | return; | |
15740 | ||
5287ad62 JB |
15741 | if (inst.operands[1].immisalign) |
15742 | switch (inst.operands[1].imm >> 8) | |
15743 | { | |
15744 | case 64: alignbits = 1; break; | |
15745 | case 128: | |
e23c0ad8 JZ |
15746 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
15747 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) | |
5287ad62 JB |
15748 | goto bad_alignment; |
15749 | alignbits = 2; | |
15750 | break; | |
15751 | case 256: | |
e23c0ad8 | 15752 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
5287ad62 JB |
15753 | goto bad_alignment; |
15754 | alignbits = 3; | |
15755 | break; | |
15756 | default: | |
15757 | bad_alignment: | |
dcbf9037 | 15758 | first_error (_("bad alignment")); |
5287ad62 JB |
15759 | return; |
15760 | } | |
15761 | ||
15762 | inst.instruction |= alignbits << 4; | |
15763 | inst.instruction |= neon_logbits (et.size) << 6; | |
15764 | ||
15765 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
15766 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
15767 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
15768 | up the right value for "type" in a table based on this value and the given | |
15769 | list style, then stick it back. */ | |
15770 | idx = ((inst.operands[0].imm >> 4) & 7) | |
15771 | | (((inst.instruction >> 8) & 3) << 3); | |
15772 | ||
15773 | typebits = typetable[idx]; | |
5f4273c7 | 15774 | |
5287ad62 JB |
15775 | constraint (typebits == -1, _("bad list type for instruction")); |
15776 | ||
15777 | inst.instruction &= ~0xf00; | |
15778 | inst.instruction |= typebits << 8; | |
15779 | } | |
15780 | ||
15781 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
15782 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
15783 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
15784 | values, terminated with -1. */ | |
15785 | ||
15786 | static int | |
15787 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
15788 | { | |
15789 | va_list ap; | |
15790 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 15791 | |
5287ad62 JB |
15792 | if (!inst.operands[1].immisalign) |
15793 | { | |
15794 | *do_align = 0; | |
15795 | return SUCCESS; | |
15796 | } | |
5f4273c7 | 15797 | |
5287ad62 JB |
15798 | va_start (ap, do_align); |
15799 | ||
15800 | do | |
15801 | { | |
15802 | thissize = va_arg (ap, int); | |
15803 | if (thissize == -1) | |
15804 | break; | |
15805 | thisalign = va_arg (ap, int); | |
15806 | ||
15807 | if (size == thissize && align == thisalign) | |
15808 | result = SUCCESS; | |
15809 | } | |
15810 | while (result != SUCCESS); | |
15811 | ||
15812 | va_end (ap); | |
15813 | ||
15814 | if (result == SUCCESS) | |
15815 | *do_align = 1; | |
15816 | else | |
dcbf9037 | 15817 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 15818 | |
5287ad62 JB |
15819 | return result; |
15820 | } | |
15821 | ||
15822 | static void | |
15823 | do_neon_ld_st_lane (void) | |
15824 | { | |
037e8744 | 15825 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
15826 | int align_good, do_align = 0; |
15827 | int logsize = neon_logbits (et.size); | |
15828 | int align = inst.operands[1].imm >> 8; | |
15829 | int n = (inst.instruction >> 8) & 3; | |
15830 | int max_el = 64 / et.size; | |
5f4273c7 | 15831 | |
dcbf9037 JB |
15832 | if (et.type == NT_invtype) |
15833 | return; | |
5f4273c7 | 15834 | |
5287ad62 JB |
15835 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
15836 | _("bad list length")); | |
15837 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
15838 | _("scalar index out of range")); | |
15839 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
15840 | && et.size == 8, | |
15841 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 15842 | |
5287ad62 JB |
15843 | switch (n) |
15844 | { | |
15845 | case 0: /* VLD1 / VST1. */ | |
15846 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
15847 | 32, 32, -1); | |
15848 | if (align_good == FAIL) | |
15849 | return; | |
15850 | if (do_align) | |
15851 | { | |
15852 | unsigned alignbits = 0; | |
15853 | switch (et.size) | |
15854 | { | |
15855 | case 16: alignbits = 0x1; break; | |
15856 | case 32: alignbits = 0x3; break; | |
15857 | default: ; | |
15858 | } | |
15859 | inst.instruction |= alignbits << 4; | |
15860 | } | |
15861 | break; | |
15862 | ||
15863 | case 1: /* VLD2 / VST2. */ | |
15864 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
15865 | 32, 64, -1); | |
15866 | if (align_good == FAIL) | |
15867 | return; | |
15868 | if (do_align) | |
15869 | inst.instruction |= 1 << 4; | |
15870 | break; | |
15871 | ||
15872 | case 2: /* VLD3 / VST3. */ | |
15873 | constraint (inst.operands[1].immisalign, | |
15874 | _("can't use alignment with this instruction")); | |
15875 | break; | |
15876 | ||
15877 | case 3: /* VLD4 / VST4. */ | |
15878 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
15879 | 16, 64, 32, 64, 32, 128, -1); | |
15880 | if (align_good == FAIL) | |
15881 | return; | |
15882 | if (do_align) | |
15883 | { | |
15884 | unsigned alignbits = 0; | |
15885 | switch (et.size) | |
15886 | { | |
15887 | case 8: alignbits = 0x1; break; | |
15888 | case 16: alignbits = 0x1; break; | |
15889 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
15890 | default: ; | |
15891 | } | |
15892 | inst.instruction |= alignbits << 4; | |
15893 | } | |
15894 | break; | |
15895 | ||
15896 | default: ; | |
15897 | } | |
15898 | ||
15899 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
15900 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15901 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 15902 | |
5287ad62 JB |
15903 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
15904 | inst.instruction |= logsize << 10; | |
15905 | } | |
15906 | ||
15907 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
15908 | ||
15909 | static void | |
15910 | do_neon_ld_dup (void) | |
15911 | { | |
037e8744 | 15912 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
15913 | int align_good, do_align = 0; |
15914 | ||
dcbf9037 JB |
15915 | if (et.type == NT_invtype) |
15916 | return; | |
15917 | ||
5287ad62 JB |
15918 | switch ((inst.instruction >> 8) & 3) |
15919 | { | |
15920 | case 0: /* VLD1. */ | |
9c2799c2 | 15921 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 JB |
15922 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
15923 | &do_align, 16, 16, 32, 32, -1); | |
15924 | if (align_good == FAIL) | |
15925 | return; | |
15926 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
15927 | { | |
15928 | case 1: break; | |
15929 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 15930 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
15931 | } |
15932 | inst.instruction |= neon_logbits (et.size) << 6; | |
15933 | break; | |
15934 | ||
15935 | case 1: /* VLD2. */ | |
15936 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
15937 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
15938 | if (align_good == FAIL) | |
15939 | return; | |
15940 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
15941 | _("bad list length")); | |
15942 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15943 | inst.instruction |= 1 << 5; | |
15944 | inst.instruction |= neon_logbits (et.size) << 6; | |
15945 | break; | |
15946 | ||
15947 | case 2: /* VLD3. */ | |
15948 | constraint (inst.operands[1].immisalign, | |
15949 | _("can't use alignment with this instruction")); | |
15950 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
15951 | _("bad list length")); | |
15952 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15953 | inst.instruction |= 1 << 5; | |
15954 | inst.instruction |= neon_logbits (et.size) << 6; | |
15955 | break; | |
15956 | ||
15957 | case 3: /* VLD4. */ | |
15958 | { | |
15959 | int align = inst.operands[1].imm >> 8; | |
15960 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
15961 | 16, 64, 32, 64, 32, 128, -1); | |
15962 | if (align_good == FAIL) | |
15963 | return; | |
15964 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
15965 | _("bad list length")); | |
15966 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15967 | inst.instruction |= 1 << 5; | |
15968 | if (et.size == 32 && align == 128) | |
15969 | inst.instruction |= 0x3 << 6; | |
15970 | else | |
15971 | inst.instruction |= neon_logbits (et.size) << 6; | |
15972 | } | |
15973 | break; | |
15974 | ||
15975 | default: ; | |
15976 | } | |
15977 | ||
15978 | inst.instruction |= do_align << 4; | |
15979 | } | |
15980 | ||
15981 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
15982 | apart from bits [11:4]. */ | |
15983 | ||
15984 | static void | |
15985 | do_neon_ldx_stx (void) | |
15986 | { | |
b1a769ed DG |
15987 | if (inst.operands[1].isreg) |
15988 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
15989 | ||
5287ad62 JB |
15990 | switch (NEON_LANE (inst.operands[0].imm)) |
15991 | { | |
15992 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 15993 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
15994 | do_neon_ld_st_interleave (); |
15995 | break; | |
5f4273c7 | 15996 | |
5287ad62 | 15997 | case NEON_ALL_LANES: |
88714cb8 | 15998 | NEON_ENCODE (DUP, inst); |
5287ad62 JB |
15999 | do_neon_ld_dup (); |
16000 | break; | |
5f4273c7 | 16001 | |
5287ad62 | 16002 | default: |
88714cb8 | 16003 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
16004 | do_neon_ld_st_lane (); |
16005 | } | |
16006 | ||
16007 | /* L bit comes from bit mask. */ | |
16008 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16009 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16010 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 16011 | |
5287ad62 JB |
16012 | if (inst.operands[1].postind) |
16013 | { | |
16014 | int postreg = inst.operands[1].imm & 0xf; | |
16015 | constraint (!inst.operands[1].immisreg, | |
16016 | _("post-index must be a register")); | |
16017 | constraint (postreg == 0xd || postreg == 0xf, | |
16018 | _("bad register for post-index")); | |
16019 | inst.instruction |= postreg; | |
16020 | } | |
16021 | else if (inst.operands[1].writeback) | |
16022 | { | |
16023 | inst.instruction |= 0xd; | |
16024 | } | |
16025 | else | |
5f4273c7 NC |
16026 | inst.instruction |= 0xf; |
16027 | ||
5287ad62 JB |
16028 | if (thumb_mode) |
16029 | inst.instruction |= 0xf9000000; | |
16030 | else | |
16031 | inst.instruction |= 0xf4000000; | |
16032 | } | |
33399f07 MGD |
16033 | |
16034 | /* FP v8. */ | |
16035 | static void | |
16036 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
16037 | { | |
16038 | NEON_ENCODE (FPV8, inst); | |
16039 | ||
16040 | if (rs == NS_FFF) | |
16041 | do_vfp_sp_dyadic (); | |
16042 | else | |
16043 | do_vfp_dp_rd_rn_rm (); | |
16044 | ||
16045 | if (rs == NS_DDD) | |
16046 | inst.instruction |= 0x100; | |
16047 | ||
16048 | inst.instruction |= 0xf0000000; | |
16049 | } | |
16050 | ||
16051 | static void | |
16052 | do_vsel (void) | |
16053 | { | |
16054 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16055 | ||
16056 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
16057 | first_error (_("invalid instruction shape")); | |
16058 | } | |
16059 | ||
73924fbc MGD |
16060 | static void |
16061 | do_vmaxnm (void) | |
16062 | { | |
16063 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16064 | ||
16065 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
16066 | return; | |
16067 | ||
16068 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
16069 | return; | |
16070 | ||
16071 | neon_dyadic_misc (NT_untyped, N_F32, 0); | |
16072 | } | |
16073 | ||
30bdf752 MGD |
16074 | static void |
16075 | do_vrint_1 (enum neon_cvt_mode mode) | |
16076 | { | |
16077 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL); | |
16078 | struct neon_type_el et; | |
16079 | ||
16080 | if (rs == NS_NULL) | |
16081 | return; | |
16082 | ||
16083 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
16084 | if (et.type != NT_invtype) | |
16085 | { | |
16086 | /* VFP encodings. */ | |
16087 | if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n | |
16088 | || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m) | |
16089 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16090 | ||
16091 | NEON_ENCODE (FPV8, inst); | |
16092 | if (rs == NS_FF) | |
16093 | do_vfp_sp_monadic (); | |
16094 | else | |
16095 | do_vfp_dp_rd_rm (); | |
16096 | ||
16097 | switch (mode) | |
16098 | { | |
16099 | case neon_cvt_mode_r: inst.instruction |= 0x00000000; break; | |
16100 | case neon_cvt_mode_z: inst.instruction |= 0x00000080; break; | |
16101 | case neon_cvt_mode_x: inst.instruction |= 0x00010000; break; | |
16102 | case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break; | |
16103 | case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break; | |
16104 | case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break; | |
16105 | case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break; | |
16106 | default: abort (); | |
16107 | } | |
16108 | ||
16109 | inst.instruction |= (rs == NS_DD) << 8; | |
16110 | do_vfp_cond_or_thumb (); | |
16111 | } | |
16112 | else | |
16113 | { | |
16114 | /* Neon encodings (or something broken...). */ | |
16115 | inst.error = NULL; | |
16116 | et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY); | |
16117 | ||
16118 | if (et.type == NT_invtype) | |
16119 | return; | |
16120 | ||
16121 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16122 | NEON_ENCODE (FLOAT, inst); | |
16123 | ||
16124 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
16125 | return; | |
16126 | ||
16127 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16128 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16129 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16130 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16131 | inst.instruction |= neon_quad (rs) << 6; | |
16132 | switch (mode) | |
16133 | { | |
16134 | case neon_cvt_mode_z: inst.instruction |= 3 << 7; break; | |
16135 | case neon_cvt_mode_x: inst.instruction |= 1 << 7; break; | |
16136 | case neon_cvt_mode_a: inst.instruction |= 2 << 7; break; | |
16137 | case neon_cvt_mode_n: inst.instruction |= 0 << 7; break; | |
16138 | case neon_cvt_mode_p: inst.instruction |= 7 << 7; break; | |
16139 | case neon_cvt_mode_m: inst.instruction |= 5 << 7; break; | |
16140 | case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break; | |
16141 | default: abort (); | |
16142 | } | |
16143 | ||
16144 | if (thumb_mode) | |
16145 | inst.instruction |= 0xfc000000; | |
16146 | else | |
16147 | inst.instruction |= 0xf0000000; | |
16148 | } | |
16149 | } | |
16150 | ||
16151 | static void | |
16152 | do_vrintx (void) | |
16153 | { | |
16154 | do_vrint_1 (neon_cvt_mode_x); | |
16155 | } | |
16156 | ||
16157 | static void | |
16158 | do_vrintz (void) | |
16159 | { | |
16160 | do_vrint_1 (neon_cvt_mode_z); | |
16161 | } | |
16162 | ||
16163 | static void | |
16164 | do_vrintr (void) | |
16165 | { | |
16166 | do_vrint_1 (neon_cvt_mode_r); | |
16167 | } | |
16168 | ||
16169 | static void | |
16170 | do_vrinta (void) | |
16171 | { | |
16172 | do_vrint_1 (neon_cvt_mode_a); | |
16173 | } | |
16174 | ||
16175 | static void | |
16176 | do_vrintn (void) | |
16177 | { | |
16178 | do_vrint_1 (neon_cvt_mode_n); | |
16179 | } | |
16180 | ||
16181 | static void | |
16182 | do_vrintp (void) | |
16183 | { | |
16184 | do_vrint_1 (neon_cvt_mode_p); | |
16185 | } | |
16186 | ||
16187 | static void | |
16188 | do_vrintm (void) | |
16189 | { | |
16190 | do_vrint_1 (neon_cvt_mode_m); | |
16191 | } | |
16192 | ||
91ff7894 MGD |
16193 | /* Crypto v1 instructions. */ |
16194 | static void | |
16195 | do_crypto_2op_1 (unsigned elttype, int op) | |
16196 | { | |
16197 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16198 | ||
16199 | if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type | |
16200 | == NT_invtype) | |
16201 | return; | |
16202 | ||
16203 | inst.error = NULL; | |
16204 | ||
16205 | NEON_ENCODE (INTEGER, inst); | |
16206 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16207 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16208 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16209 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16210 | if (op != -1) | |
16211 | inst.instruction |= op << 6; | |
16212 | ||
16213 | if (thumb_mode) | |
16214 | inst.instruction |= 0xfc000000; | |
16215 | else | |
16216 | inst.instruction |= 0xf0000000; | |
16217 | } | |
16218 | ||
48adcd8e MGD |
16219 | static void |
16220 | do_crypto_3op_1 (int u, int op) | |
16221 | { | |
16222 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16223 | ||
16224 | if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT, | |
16225 | N_32 | N_UNT | N_KEY).type == NT_invtype) | |
16226 | return; | |
16227 | ||
16228 | inst.error = NULL; | |
16229 | ||
16230 | NEON_ENCODE (INTEGER, inst); | |
16231 | neon_three_same (1, u, 8 << op); | |
16232 | } | |
16233 | ||
91ff7894 MGD |
16234 | static void |
16235 | do_aese (void) | |
16236 | { | |
16237 | do_crypto_2op_1 (N_8, 0); | |
16238 | } | |
16239 | ||
16240 | static void | |
16241 | do_aesd (void) | |
16242 | { | |
16243 | do_crypto_2op_1 (N_8, 1); | |
16244 | } | |
16245 | ||
16246 | static void | |
16247 | do_aesmc (void) | |
16248 | { | |
16249 | do_crypto_2op_1 (N_8, 2); | |
16250 | } | |
16251 | ||
16252 | static void | |
16253 | do_aesimc (void) | |
16254 | { | |
16255 | do_crypto_2op_1 (N_8, 3); | |
16256 | } | |
16257 | ||
48adcd8e MGD |
16258 | static void |
16259 | do_sha1c (void) | |
16260 | { | |
16261 | do_crypto_3op_1 (0, 0); | |
16262 | } | |
16263 | ||
16264 | static void | |
16265 | do_sha1p (void) | |
16266 | { | |
16267 | do_crypto_3op_1 (0, 1); | |
16268 | } | |
16269 | ||
16270 | static void | |
16271 | do_sha1m (void) | |
16272 | { | |
16273 | do_crypto_3op_1 (0, 2); | |
16274 | } | |
16275 | ||
16276 | static void | |
16277 | do_sha1su0 (void) | |
16278 | { | |
16279 | do_crypto_3op_1 (0, 3); | |
16280 | } | |
91ff7894 | 16281 | |
48adcd8e MGD |
16282 | static void |
16283 | do_sha256h (void) | |
16284 | { | |
16285 | do_crypto_3op_1 (1, 0); | |
16286 | } | |
16287 | ||
16288 | static void | |
16289 | do_sha256h2 (void) | |
16290 | { | |
16291 | do_crypto_3op_1 (1, 1); | |
16292 | } | |
16293 | ||
16294 | static void | |
16295 | do_sha256su1 (void) | |
16296 | { | |
16297 | do_crypto_3op_1 (1, 2); | |
16298 | } | |
3c9017d2 MGD |
16299 | |
16300 | static void | |
16301 | do_sha1h (void) | |
16302 | { | |
16303 | do_crypto_2op_1 (N_32, -1); | |
16304 | } | |
16305 | ||
16306 | static void | |
16307 | do_sha1su1 (void) | |
16308 | { | |
16309 | do_crypto_2op_1 (N_32, 0); | |
16310 | } | |
16311 | ||
16312 | static void | |
16313 | do_sha256su0 (void) | |
16314 | { | |
16315 | do_crypto_2op_1 (N_32, 1); | |
16316 | } | |
5287ad62 JB |
16317 | \f |
16318 | /* Overall per-instruction processing. */ | |
16319 | ||
16320 | /* We need to be able to fix up arbitrary expressions in some statements. | |
16321 | This is so that we can handle symbols that are an arbitrary distance from | |
16322 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
16323 | which returns part of an address in a form which will be valid for | |
16324 | a data instruction. We do this by pushing the expression into a symbol | |
16325 | in the expr_section, and creating a fix for that. */ | |
16326 | ||
16327 | static void | |
16328 | fix_new_arm (fragS * frag, | |
16329 | int where, | |
16330 | short int size, | |
16331 | expressionS * exp, | |
16332 | int pc_rel, | |
16333 | int reloc) | |
16334 | { | |
16335 | fixS * new_fix; | |
16336 | ||
16337 | switch (exp->X_op) | |
16338 | { | |
16339 | case O_constant: | |
6e7ce2cd PB |
16340 | if (pc_rel) |
16341 | { | |
16342 | /* Create an absolute valued symbol, so we have something to | |
16343 | refer to in the object file. Unfortunately for us, gas's | |
16344 | generic expression parsing will already have folded out | |
16345 | any use of .set foo/.type foo %function that may have | |
16346 | been used to set type information of the target location, | |
16347 | that's being specified symbolically. We have to presume | |
16348 | the user knows what they are doing. */ | |
16349 | char name[16 + 8]; | |
16350 | symbolS *symbol; | |
16351 | ||
16352 | sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number); | |
16353 | ||
16354 | symbol = symbol_find_or_make (name); | |
16355 | S_SET_SEGMENT (symbol, absolute_section); | |
16356 | symbol_set_frag (symbol, &zero_address_frag); | |
16357 | S_SET_VALUE (symbol, exp->X_add_number); | |
16358 | exp->X_op = O_symbol; | |
16359 | exp->X_add_symbol = symbol; | |
16360 | exp->X_add_number = 0; | |
16361 | } | |
16362 | /* FALLTHROUGH */ | |
5287ad62 JB |
16363 | case O_symbol: |
16364 | case O_add: | |
16365 | case O_subtract: | |
21d799b5 NC |
16366 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
16367 | (enum bfd_reloc_code_real) reloc); | |
5287ad62 JB |
16368 | break; |
16369 | ||
16370 | default: | |
21d799b5 NC |
16371 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
16372 | pc_rel, (enum bfd_reloc_code_real) reloc); | |
5287ad62 JB |
16373 | break; |
16374 | } | |
16375 | ||
16376 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
16377 | instruction. */ | |
16378 | new_fix->tc_fix_data = thumb_mode; | |
16379 | } | |
16380 | ||
16381 | /* Create a frg for an instruction requiring relaxation. */ | |
16382 | static void | |
16383 | output_relax_insn (void) | |
16384 | { | |
16385 | char * to; | |
16386 | symbolS *sym; | |
0110f2b8 PB |
16387 | int offset; |
16388 | ||
6e1cb1a6 PB |
16389 | /* The size of the instruction is unknown, so tie the debug info to the |
16390 | start of the instruction. */ | |
16391 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 16392 | |
0110f2b8 PB |
16393 | switch (inst.reloc.exp.X_op) |
16394 | { | |
16395 | case O_symbol: | |
16396 | sym = inst.reloc.exp.X_add_symbol; | |
16397 | offset = inst.reloc.exp.X_add_number; | |
16398 | break; | |
16399 | case O_constant: | |
16400 | sym = NULL; | |
16401 | offset = inst.reloc.exp.X_add_number; | |
16402 | break; | |
16403 | default: | |
16404 | sym = make_expr_symbol (&inst.reloc.exp); | |
16405 | offset = 0; | |
16406 | break; | |
16407 | } | |
16408 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
16409 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
16410 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
16411 | } |
16412 | ||
16413 | /* Write a 32-bit thumb instruction to buf. */ | |
16414 | static void | |
16415 | put_thumb32_insn (char * buf, unsigned long insn) | |
16416 | { | |
16417 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
16418 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
16419 | } | |
16420 | ||
b99bd4ef | 16421 | static void |
c19d1205 | 16422 | output_inst (const char * str) |
b99bd4ef | 16423 | { |
c19d1205 | 16424 | char * to = NULL; |
b99bd4ef | 16425 | |
c19d1205 | 16426 | if (inst.error) |
b99bd4ef | 16427 | { |
c19d1205 | 16428 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
16429 | return; |
16430 | } | |
5f4273c7 NC |
16431 | if (inst.relax) |
16432 | { | |
16433 | output_relax_insn (); | |
0110f2b8 | 16434 | return; |
5f4273c7 | 16435 | } |
c19d1205 ZW |
16436 | if (inst.size == 0) |
16437 | return; | |
b99bd4ef | 16438 | |
c19d1205 | 16439 | to = frag_more (inst.size); |
8dc2430f NC |
16440 | /* PR 9814: Record the thumb mode into the current frag so that we know |
16441 | what type of NOP padding to use, if necessary. We override any previous | |
16442 | setting so that if the mode has changed then the NOPS that we use will | |
16443 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 16444 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
16445 | |
16446 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 16447 | { |
9c2799c2 | 16448 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 16449 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 16450 | } |
c19d1205 | 16451 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 16452 | { |
9c2799c2 | 16453 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
16454 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
16455 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 16456 | } |
c19d1205 ZW |
16457 | else |
16458 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 16459 | |
c19d1205 ZW |
16460 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
16461 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
16462 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
16463 | inst.reloc.type); | |
b99bd4ef | 16464 | |
c19d1205 | 16465 | dwarf2_emit_insn (inst.size); |
c19d1205 | 16466 | } |
b99bd4ef | 16467 | |
e07e6e58 NC |
16468 | static char * |
16469 | output_it_inst (int cond, int mask, char * to) | |
16470 | { | |
16471 | unsigned long instruction = 0xbf00; | |
16472 | ||
16473 | mask &= 0xf; | |
16474 | instruction |= mask; | |
16475 | instruction |= cond << 4; | |
16476 | ||
16477 | if (to == NULL) | |
16478 | { | |
16479 | to = frag_more (2); | |
16480 | #ifdef OBJ_ELF | |
16481 | dwarf2_emit_insn (2); | |
16482 | #endif | |
16483 | } | |
16484 | ||
16485 | md_number_to_chars (to, instruction, 2); | |
16486 | ||
16487 | return to; | |
16488 | } | |
16489 | ||
c19d1205 ZW |
16490 | /* Tag values used in struct asm_opcode's tag field. */ |
16491 | enum opcode_tag | |
16492 | { | |
16493 | OT_unconditional, /* Instruction cannot be conditionalized. | |
16494 | The ARM condition field is still 0xE. */ | |
16495 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
16496 | and carries 0xF in its ARM condition field. */ | |
16497 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
16498 | OT_csuffixF, /* Some forms of the instruction take a conditional |
16499 | suffix, others place 0xF where the condition field | |
16500 | would be. */ | |
c19d1205 ZW |
16501 | OT_cinfix3, /* Instruction takes a conditional infix, |
16502 | beginning at character index 3. (In | |
16503 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
16504 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
16505 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
16506 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
16507 | character index 3, even in unified mode. Used for | |
16508 | legacy instructions where suffix and infix forms | |
16509 | may be ambiguous. */ | |
c19d1205 | 16510 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 16511 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
16512 | OT_odd_infix_unc, /* This is the unconditional variant of an |
16513 | instruction that takes a conditional infix | |
16514 | at an unusual position. In unified mode, | |
16515 | this variant will accept a suffix. */ | |
16516 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
16517 | are the conditional variants of instructions that | |
16518 | take conditional infixes in unusual positions. | |
16519 | The infix appears at character index | |
16520 | (tag - OT_odd_infix_0). These are not accepted | |
16521 | in unified mode. */ | |
16522 | }; | |
b99bd4ef | 16523 | |
c19d1205 ZW |
16524 | /* Subroutine of md_assemble, responsible for looking up the primary |
16525 | opcode from the mnemonic the user wrote. STR points to the | |
16526 | beginning of the mnemonic. | |
16527 | ||
16528 | This is not simply a hash table lookup, because of conditional | |
16529 | variants. Most instructions have conditional variants, which are | |
16530 | expressed with a _conditional affix_ to the mnemonic. If we were | |
16531 | to encode each conditional variant as a literal string in the opcode | |
16532 | table, it would have approximately 20,000 entries. | |
16533 | ||
16534 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
16535 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
16536 | instructions take the affix as an infix, notably the s-variants of | |
16537 | the arithmetic instructions. Of those instructions, all but six | |
16538 | have the infix appear after the third character of the mnemonic. | |
16539 | ||
16540 | Accordingly, the algorithm for looking up primary opcodes given | |
16541 | an identifier is: | |
16542 | ||
16543 | 1. Look up the identifier in the opcode table. | |
16544 | If we find a match, go to step U. | |
16545 | ||
16546 | 2. Look up the last two characters of the identifier in the | |
16547 | conditions table. If we find a match, look up the first N-2 | |
16548 | characters of the identifier in the opcode table. If we | |
16549 | find a match, go to step CE. | |
16550 | ||
16551 | 3. Look up the fourth and fifth characters of the identifier in | |
16552 | the conditions table. If we find a match, extract those | |
16553 | characters from the identifier, and look up the remaining | |
16554 | characters in the opcode table. If we find a match, go | |
16555 | to step CM. | |
16556 | ||
16557 | 4. Fail. | |
16558 | ||
16559 | U. Examine the tag field of the opcode structure, in case this is | |
16560 | one of the six instructions with its conditional infix in an | |
16561 | unusual place. If it is, the tag tells us where to find the | |
16562 | infix; look it up in the conditions table and set inst.cond | |
16563 | accordingly. Otherwise, this is an unconditional instruction. | |
16564 | Again set inst.cond accordingly. Return the opcode structure. | |
16565 | ||
16566 | CE. Examine the tag field to make sure this is an instruction that | |
16567 | should receive a conditional suffix. If it is not, fail. | |
16568 | Otherwise, set inst.cond from the suffix we already looked up, | |
16569 | and return the opcode structure. | |
16570 | ||
16571 | CM. Examine the tag field to make sure this is an instruction that | |
16572 | should receive a conditional infix after the third character. | |
16573 | If it is not, fail. Otherwise, undo the edits to the current | |
16574 | line of input and proceed as for case CE. */ | |
16575 | ||
16576 | static const struct asm_opcode * | |
16577 | opcode_lookup (char **str) | |
16578 | { | |
16579 | char *end, *base; | |
16580 | char *affix; | |
16581 | const struct asm_opcode *opcode; | |
16582 | const struct asm_cond *cond; | |
e3cb604e | 16583 | char save[2]; |
c19d1205 ZW |
16584 | |
16585 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 16586 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 16587 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 16588 | if (*end == ' ' || *end == '.') |
c19d1205 | 16589 | break; |
b99bd4ef | 16590 | |
c19d1205 | 16591 | if (end == base) |
c921be7d | 16592 | return NULL; |
b99bd4ef | 16593 | |
5287ad62 | 16594 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 16595 | if (end[0] == '.') |
b99bd4ef | 16596 | { |
5287ad62 | 16597 | int offset = 2; |
5f4273c7 | 16598 | |
267d2029 JB |
16599 | /* The .w and .n suffixes are only valid if the unified syntax is in |
16600 | use. */ | |
16601 | if (unified_syntax && end[1] == 'w') | |
c19d1205 | 16602 | inst.size_req = 4; |
267d2029 | 16603 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
16604 | inst.size_req = 2; |
16605 | else | |
5287ad62 JB |
16606 | offset = 0; |
16607 | ||
16608 | inst.vectype.elems = 0; | |
16609 | ||
16610 | *str = end + offset; | |
b99bd4ef | 16611 | |
5f4273c7 | 16612 | if (end[offset] == '.') |
5287ad62 | 16613 | { |
267d2029 JB |
16614 | /* See if we have a Neon type suffix (possible in either unified or |
16615 | non-unified ARM syntax mode). */ | |
dcbf9037 | 16616 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
c921be7d | 16617 | return NULL; |
5287ad62 JB |
16618 | } |
16619 | else if (end[offset] != '\0' && end[offset] != ' ') | |
c921be7d | 16620 | return NULL; |
b99bd4ef | 16621 | } |
c19d1205 ZW |
16622 | else |
16623 | *str = end; | |
b99bd4ef | 16624 | |
c19d1205 | 16625 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 NC |
16626 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
16627 | end - base); | |
c19d1205 | 16628 | if (opcode) |
b99bd4ef | 16629 | { |
c19d1205 ZW |
16630 | /* step U */ |
16631 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 16632 | { |
c19d1205 ZW |
16633 | inst.cond = COND_ALWAYS; |
16634 | return opcode; | |
b99bd4ef | 16635 | } |
b99bd4ef | 16636 | |
278df34e | 16637 | if (warn_on_deprecated && unified_syntax) |
c19d1205 ZW |
16638 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
16639 | affix = base + (opcode->tag - OT_odd_infix_0); | |
21d799b5 | 16640 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 16641 | gas_assert (cond); |
b99bd4ef | 16642 | |
c19d1205 ZW |
16643 | inst.cond = cond->value; |
16644 | return opcode; | |
16645 | } | |
b99bd4ef | 16646 | |
c19d1205 ZW |
16647 | /* Cannot have a conditional suffix on a mnemonic of less than two |
16648 | characters. */ | |
16649 | if (end - base < 3) | |
c921be7d | 16650 | return NULL; |
b99bd4ef | 16651 | |
c19d1205 ZW |
16652 | /* Look for suffixed mnemonic. */ |
16653 | affix = end - 2; | |
21d799b5 NC |
16654 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
16655 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
16656 | affix - base); | |
c19d1205 ZW |
16657 | if (opcode && cond) |
16658 | { | |
16659 | /* step CE */ | |
16660 | switch (opcode->tag) | |
16661 | { | |
e3cb604e PB |
16662 | case OT_cinfix3_legacy: |
16663 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
16664 | break; | |
16665 | ||
c19d1205 | 16666 | case OT_cinfix3: |
088fa78e | 16667 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
16668 | case OT_odd_infix_unc: |
16669 | if (!unified_syntax) | |
e3cb604e | 16670 | return 0; |
c19d1205 ZW |
16671 | /* else fall through */ |
16672 | ||
16673 | case OT_csuffix: | |
037e8744 | 16674 | case OT_csuffixF: |
c19d1205 ZW |
16675 | case OT_csuf_or_in3: |
16676 | inst.cond = cond->value; | |
16677 | return opcode; | |
16678 | ||
16679 | case OT_unconditional: | |
16680 | case OT_unconditionalF: | |
dfa9f0d5 | 16681 | if (thumb_mode) |
c921be7d | 16682 | inst.cond = cond->value; |
dfa9f0d5 PB |
16683 | else |
16684 | { | |
c921be7d | 16685 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
16686 | inst.error = BAD_COND; |
16687 | inst.cond = COND_ALWAYS; | |
16688 | } | |
c19d1205 | 16689 | return opcode; |
b99bd4ef | 16690 | |
c19d1205 | 16691 | default: |
c921be7d | 16692 | return NULL; |
c19d1205 ZW |
16693 | } |
16694 | } | |
b99bd4ef | 16695 | |
c19d1205 ZW |
16696 | /* Cannot have a usual-position infix on a mnemonic of less than |
16697 | six characters (five would be a suffix). */ | |
16698 | if (end - base < 6) | |
c921be7d | 16699 | return NULL; |
b99bd4ef | 16700 | |
c19d1205 ZW |
16701 | /* Look for infixed mnemonic in the usual position. */ |
16702 | affix = base + 3; | |
21d799b5 | 16703 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 16704 | if (!cond) |
c921be7d | 16705 | return NULL; |
e3cb604e PB |
16706 | |
16707 | memcpy (save, affix, 2); | |
16708 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 NC |
16709 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
16710 | (end - base) - 2); | |
e3cb604e PB |
16711 | memmove (affix + 2, affix, (end - affix) - 2); |
16712 | memcpy (affix, save, 2); | |
16713 | ||
088fa78e KH |
16714 | if (opcode |
16715 | && (opcode->tag == OT_cinfix3 | |
16716 | || opcode->tag == OT_cinfix3_deprecated | |
16717 | || opcode->tag == OT_csuf_or_in3 | |
16718 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 16719 | { |
c921be7d | 16720 | /* Step CM. */ |
278df34e | 16721 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
16722 | && (opcode->tag == OT_cinfix3 |
16723 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
16724 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
16725 | ||
16726 | inst.cond = cond->value; | |
16727 | return opcode; | |
b99bd4ef NC |
16728 | } |
16729 | ||
c921be7d | 16730 | return NULL; |
b99bd4ef NC |
16731 | } |
16732 | ||
e07e6e58 NC |
16733 | /* This function generates an initial IT instruction, leaving its block |
16734 | virtually open for the new instructions. Eventually, | |
16735 | the mask will be updated by now_it_add_mask () each time | |
16736 | a new instruction needs to be included in the IT block. | |
16737 | Finally, the block is closed with close_automatic_it_block (). | |
16738 | The block closure can be requested either from md_assemble (), | |
16739 | a tencode (), or due to a label hook. */ | |
16740 | ||
16741 | static void | |
16742 | new_automatic_it_block (int cond) | |
16743 | { | |
16744 | now_it.state = AUTOMATIC_IT_BLOCK; | |
16745 | now_it.mask = 0x18; | |
16746 | now_it.cc = cond; | |
16747 | now_it.block_length = 1; | |
cd000bff | 16748 | mapping_state (MAP_THUMB); |
e07e6e58 | 16749 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
5a01bb1d MGD |
16750 | now_it.warn_deprecated = FALSE; |
16751 | now_it.insn_cond = TRUE; | |
e07e6e58 NC |
16752 | } |
16753 | ||
16754 | /* Close an automatic IT block. | |
16755 | See comments in new_automatic_it_block (). */ | |
16756 | ||
16757 | static void | |
16758 | close_automatic_it_block (void) | |
16759 | { | |
16760 | now_it.mask = 0x10; | |
16761 | now_it.block_length = 0; | |
16762 | } | |
16763 | ||
16764 | /* Update the mask of the current automatically-generated IT | |
16765 | instruction. See comments in new_automatic_it_block (). */ | |
16766 | ||
16767 | static void | |
16768 | now_it_add_mask (int cond) | |
16769 | { | |
16770 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
16771 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
16772 | | ((bitvalue) << (nbit))) | |
e07e6e58 | 16773 | const int resulting_bit = (cond & 1); |
c921be7d | 16774 | |
e07e6e58 NC |
16775 | now_it.mask &= 0xf; |
16776 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
16777 | resulting_bit, | |
16778 | (5 - now_it.block_length)); | |
16779 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
16780 | 1, | |
16781 | ((5 - now_it.block_length) - 1) ); | |
16782 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); | |
16783 | ||
16784 | #undef CLEAR_BIT | |
16785 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
16786 | } |
16787 | ||
16788 | /* The IT blocks handling machinery is accessed through the these functions: | |
16789 | it_fsm_pre_encode () from md_assemble () | |
16790 | set_it_insn_type () optional, from the tencode functions | |
16791 | set_it_insn_type_last () ditto | |
16792 | in_it_block () ditto | |
16793 | it_fsm_post_encode () from md_assemble () | |
16794 | force_automatic_it_block_close () from label habdling functions | |
16795 | ||
16796 | Rationale: | |
16797 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
16798 | initializing the IT insn type with a generic initial value depending | |
16799 | on the inst.condition. | |
16800 | 2) During the tencode function, two things may happen: | |
16801 | a) The tencode function overrides the IT insn type by | |
16802 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
16803 | b) The tencode function queries the IT block state by | |
16804 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
16805 | ||
16806 | Both set_it_insn_type and in_it_block run the internal FSM state | |
16807 | handling function (handle_it_state), because: a) setting the IT insn | |
16808 | type may incur in an invalid state (exiting the function), | |
16809 | and b) querying the state requires the FSM to be updated. | |
16810 | Specifically we want to avoid creating an IT block for conditional | |
16811 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
16812 | determine whether an IT block is required until the tencode () routine | |
16813 | has decided what type of instruction this actually it. | |
16814 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
16815 | set_it_insn_type has to be called first. | |
16816 | ||
16817 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
16818 | determines the insn IT type depending on the inst.cond code. | |
16819 | When a tencode () routine encodes an instruction that can be | |
16820 | either outside an IT block, or, in the case of being inside, has to be | |
16821 | the last one, set_it_insn_type_last () will determine the proper | |
16822 | IT instruction type based on the inst.cond code. Otherwise, | |
16823 | set_it_insn_type can be called for overriding that logic or | |
16824 | for covering other cases. | |
16825 | ||
16826 | Calling handle_it_state () may not transition the IT block state to | |
16827 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
16828 | still queried. Instead, if the FSM determines that the state should | |
16829 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
16830 | after the tencode () function: that's what it_fsm_post_encode () does. | |
16831 | ||
16832 | Since in_it_block () calls the state handling function to get an | |
16833 | updated state, an error may occur (due to invalid insns combination). | |
16834 | In that case, inst.error is set. | |
16835 | Therefore, inst.error has to be checked after the execution of | |
16836 | the tencode () routine. | |
16837 | ||
16838 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
16839 | any pending state change (if any) that didn't take place in | |
16840 | handle_it_state () as explained above. */ | |
16841 | ||
16842 | static void | |
16843 | it_fsm_pre_encode (void) | |
16844 | { | |
16845 | if (inst.cond != COND_ALWAYS) | |
16846 | inst.it_insn_type = INSIDE_IT_INSN; | |
16847 | else | |
16848 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
16849 | ||
16850 | now_it.state_handled = 0; | |
16851 | } | |
16852 | ||
16853 | /* IT state FSM handling function. */ | |
16854 | ||
16855 | static int | |
16856 | handle_it_state (void) | |
16857 | { | |
16858 | now_it.state_handled = 1; | |
5a01bb1d | 16859 | now_it.insn_cond = FALSE; |
e07e6e58 NC |
16860 | |
16861 | switch (now_it.state) | |
16862 | { | |
16863 | case OUTSIDE_IT_BLOCK: | |
16864 | switch (inst.it_insn_type) | |
16865 | { | |
16866 | case OUTSIDE_IT_INSN: | |
16867 | break; | |
16868 | ||
16869 | case INSIDE_IT_INSN: | |
16870 | case INSIDE_IT_LAST_INSN: | |
16871 | if (thumb_mode == 0) | |
16872 | { | |
c921be7d | 16873 | if (unified_syntax |
e07e6e58 NC |
16874 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
16875 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
16876 | " for Thumb.")); | |
16877 | } | |
16878 | else | |
16879 | { | |
16880 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
16881 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
16882 | { | |
16883 | /* Automatically generate the IT instruction. */ | |
16884 | new_automatic_it_block (inst.cond); | |
16885 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
16886 | close_automatic_it_block (); | |
16887 | } | |
16888 | else | |
16889 | { | |
16890 | inst.error = BAD_OUT_IT; | |
16891 | return FAIL; | |
16892 | } | |
16893 | } | |
16894 | break; | |
16895 | ||
16896 | case IF_INSIDE_IT_LAST_INSN: | |
16897 | case NEUTRAL_IT_INSN: | |
16898 | break; | |
16899 | ||
16900 | case IT_INSN: | |
16901 | now_it.state = MANUAL_IT_BLOCK; | |
16902 | now_it.block_length = 0; | |
16903 | break; | |
16904 | } | |
16905 | break; | |
16906 | ||
16907 | case AUTOMATIC_IT_BLOCK: | |
16908 | /* Three things may happen now: | |
16909 | a) We should increment current it block size; | |
16910 | b) We should close current it block (closing insn or 4 insns); | |
16911 | c) We should close current it block and start a new one (due | |
16912 | to incompatible conditions or | |
16913 | 4 insns-length block reached). */ | |
16914 | ||
16915 | switch (inst.it_insn_type) | |
16916 | { | |
16917 | case OUTSIDE_IT_INSN: | |
16918 | /* The closure of the block shall happen immediatelly, | |
16919 | so any in_it_block () call reports the block as closed. */ | |
16920 | force_automatic_it_block_close (); | |
16921 | break; | |
16922 | ||
16923 | case INSIDE_IT_INSN: | |
16924 | case INSIDE_IT_LAST_INSN: | |
16925 | case IF_INSIDE_IT_LAST_INSN: | |
16926 | now_it.block_length++; | |
16927 | ||
16928 | if (now_it.block_length > 4 | |
16929 | || !now_it_compatible (inst.cond)) | |
16930 | { | |
16931 | force_automatic_it_block_close (); | |
16932 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
16933 | new_automatic_it_block (inst.cond); | |
16934 | } | |
16935 | else | |
16936 | { | |
5a01bb1d | 16937 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
16938 | now_it_add_mask (inst.cond); |
16939 | } | |
16940 | ||
16941 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
16942 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
16943 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
16944 | close_automatic_it_block (); | |
16945 | break; | |
16946 | ||
16947 | case NEUTRAL_IT_INSN: | |
16948 | now_it.block_length++; | |
5a01bb1d | 16949 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
16950 | |
16951 | if (now_it.block_length > 4) | |
16952 | force_automatic_it_block_close (); | |
16953 | else | |
16954 | now_it_add_mask (now_it.cc & 1); | |
16955 | break; | |
16956 | ||
16957 | case IT_INSN: | |
16958 | close_automatic_it_block (); | |
16959 | now_it.state = MANUAL_IT_BLOCK; | |
16960 | break; | |
16961 | } | |
16962 | break; | |
16963 | ||
16964 | case MANUAL_IT_BLOCK: | |
16965 | { | |
16966 | /* Check conditional suffixes. */ | |
16967 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
16968 | int is_last; | |
16969 | now_it.mask <<= 1; | |
16970 | now_it.mask &= 0x1f; | |
16971 | is_last = (now_it.mask == 0x10); | |
5a01bb1d | 16972 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
16973 | |
16974 | switch (inst.it_insn_type) | |
16975 | { | |
16976 | case OUTSIDE_IT_INSN: | |
16977 | inst.error = BAD_NOT_IT; | |
16978 | return FAIL; | |
16979 | ||
16980 | case INSIDE_IT_INSN: | |
16981 | if (cond != inst.cond) | |
16982 | { | |
16983 | inst.error = BAD_IT_COND; | |
16984 | return FAIL; | |
16985 | } | |
16986 | break; | |
16987 | ||
16988 | case INSIDE_IT_LAST_INSN: | |
16989 | case IF_INSIDE_IT_LAST_INSN: | |
16990 | if (cond != inst.cond) | |
16991 | { | |
16992 | inst.error = BAD_IT_COND; | |
16993 | return FAIL; | |
16994 | } | |
16995 | if (!is_last) | |
16996 | { | |
16997 | inst.error = BAD_BRANCH; | |
16998 | return FAIL; | |
16999 | } | |
17000 | break; | |
17001 | ||
17002 | case NEUTRAL_IT_INSN: | |
17003 | /* The BKPT instruction is unconditional even in an IT block. */ | |
17004 | break; | |
17005 | ||
17006 | case IT_INSN: | |
17007 | inst.error = BAD_IT_IT; | |
17008 | return FAIL; | |
17009 | } | |
17010 | } | |
17011 | break; | |
17012 | } | |
17013 | ||
17014 | return SUCCESS; | |
17015 | } | |
17016 | ||
5a01bb1d MGD |
17017 | struct depr_insn_mask |
17018 | { | |
17019 | unsigned long pattern; | |
17020 | unsigned long mask; | |
17021 | const char* description; | |
17022 | }; | |
17023 | ||
17024 | /* List of 16-bit instruction patterns deprecated in an IT block in | |
17025 | ARMv8. */ | |
17026 | static const struct depr_insn_mask depr_it_insns[] = { | |
17027 | { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") }, | |
17028 | { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") }, | |
17029 | { 0xa000, 0xb800, N_("ADR") }, | |
17030 | { 0x4800, 0xf800, N_("Literal loads") }, | |
17031 | { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") }, | |
17032 | { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") }, | |
17033 | { 0, 0, NULL } | |
17034 | }; | |
17035 | ||
e07e6e58 NC |
17036 | static void |
17037 | it_fsm_post_encode (void) | |
17038 | { | |
17039 | int is_last; | |
17040 | ||
17041 | if (!now_it.state_handled) | |
17042 | handle_it_state (); | |
17043 | ||
5a01bb1d MGD |
17044 | if (now_it.insn_cond |
17045 | && !now_it.warn_deprecated | |
17046 | && warn_on_deprecated | |
17047 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
17048 | { | |
17049 | if (inst.instruction >= 0x10000) | |
17050 | { | |
17051 | as_warn (_("it blocks containing wide Thumb instructions are " | |
17052 | "deprecated in ARMv8")); | |
17053 | now_it.warn_deprecated = TRUE; | |
17054 | } | |
17055 | else | |
17056 | { | |
17057 | const struct depr_insn_mask *p = depr_it_insns; | |
17058 | ||
17059 | while (p->mask != 0) | |
17060 | { | |
17061 | if ((inst.instruction & p->mask) == p->pattern) | |
17062 | { | |
17063 | as_warn (_("it blocks containing 16-bit Thumb intsructions " | |
17064 | "of the following class are deprecated in ARMv8: " | |
17065 | "%s"), p->description); | |
17066 | now_it.warn_deprecated = TRUE; | |
17067 | break; | |
17068 | } | |
17069 | ||
17070 | ++p; | |
17071 | } | |
17072 | } | |
17073 | ||
17074 | if (now_it.block_length > 1) | |
17075 | { | |
17076 | as_warn (_("it blocks of more than one conditional instruction are " | |
17077 | "deprecated in ARMv8")); | |
17078 | now_it.warn_deprecated = TRUE; | |
17079 | } | |
17080 | } | |
17081 | ||
e07e6e58 NC |
17082 | is_last = (now_it.mask == 0x10); |
17083 | if (is_last) | |
17084 | { | |
17085 | now_it.state = OUTSIDE_IT_BLOCK; | |
17086 | now_it.mask = 0; | |
17087 | } | |
17088 | } | |
17089 | ||
17090 | static void | |
17091 | force_automatic_it_block_close (void) | |
17092 | { | |
17093 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
17094 | { | |
17095 | close_automatic_it_block (); | |
17096 | now_it.state = OUTSIDE_IT_BLOCK; | |
17097 | now_it.mask = 0; | |
17098 | } | |
17099 | } | |
17100 | ||
17101 | static int | |
17102 | in_it_block (void) | |
17103 | { | |
17104 | if (!now_it.state_handled) | |
17105 | handle_it_state (); | |
17106 | ||
17107 | return now_it.state != OUTSIDE_IT_BLOCK; | |
17108 | } | |
17109 | ||
c19d1205 ZW |
17110 | void |
17111 | md_assemble (char *str) | |
b99bd4ef | 17112 | { |
c19d1205 ZW |
17113 | char *p = str; |
17114 | const struct asm_opcode * opcode; | |
b99bd4ef | 17115 | |
c19d1205 ZW |
17116 | /* Align the previous label if needed. */ |
17117 | if (last_label_seen != NULL) | |
b99bd4ef | 17118 | { |
c19d1205 ZW |
17119 | symbol_set_frag (last_label_seen, frag_now); |
17120 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
17121 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
17122 | } |
17123 | ||
c19d1205 ZW |
17124 | memset (&inst, '\0', sizeof (inst)); |
17125 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 17126 | |
c19d1205 ZW |
17127 | opcode = opcode_lookup (&p); |
17128 | if (!opcode) | |
b99bd4ef | 17129 | { |
c19d1205 | 17130 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 17131 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d NC |
17132 | if (! create_register_alias (str, p) |
17133 | && ! create_neon_reg_alias (str, p)) | |
c19d1205 | 17134 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 17135 | |
b99bd4ef NC |
17136 | return; |
17137 | } | |
17138 | ||
278df34e | 17139 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
088fa78e KH |
17140 | as_warn (_("s suffix on comparison instruction is deprecated")); |
17141 | ||
037e8744 JB |
17142 | /* The value which unconditional instructions should have in place of the |
17143 | condition field. */ | |
17144 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
17145 | ||
c19d1205 | 17146 | if (thumb_mode) |
b99bd4ef | 17147 | { |
e74cfd16 | 17148 | arm_feature_set variant; |
8f06b2d8 PB |
17149 | |
17150 | variant = cpu_variant; | |
17151 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
17152 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
17153 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 17154 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
17155 | if (!opcode->tvariant |
17156 | || (thumb_mode == 1 | |
17157 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 17158 | { |
bf3eeda7 | 17159 | as_bad (_("selected processor does not support Thumb mode `%s'"), str); |
b99bd4ef NC |
17160 | return; |
17161 | } | |
c19d1205 ZW |
17162 | if (inst.cond != COND_ALWAYS && !unified_syntax |
17163 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 17164 | { |
c19d1205 | 17165 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
17166 | return; |
17167 | } | |
17168 | ||
752d5da4 | 17169 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)) |
076d447c | 17170 | { |
7e806470 | 17171 | if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23 |
752d5da4 NC |
17172 | && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr) |
17173 | || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier))) | |
17174 | { | |
17175 | /* Two things are addressed here. | |
17176 | 1) Implicit require narrow instructions on Thumb-1. | |
17177 | This avoids relaxation accidentally introducing Thumb-2 | |
17178 | instructions. | |
17179 | 2) Reject wide instructions in non Thumb-2 cores. */ | |
17180 | if (inst.size_req == 0) | |
17181 | inst.size_req = 2; | |
17182 | else if (inst.size_req == 4) | |
17183 | { | |
bf3eeda7 | 17184 | as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str); |
752d5da4 NC |
17185 | return; |
17186 | } | |
17187 | } | |
076d447c PB |
17188 | } |
17189 | ||
c19d1205 ZW |
17190 | inst.instruction = opcode->tvalue; |
17191 | ||
5be8be5d | 17192 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
e07e6e58 NC |
17193 | { |
17194 | /* Prepare the it_insn_type for those encodings that don't set | |
17195 | it. */ | |
17196 | it_fsm_pre_encode (); | |
c19d1205 | 17197 | |
e07e6e58 NC |
17198 | opcode->tencode (); |
17199 | ||
17200 | it_fsm_post_encode (); | |
17201 | } | |
e27ec89e | 17202 | |
0110f2b8 | 17203 | if (!(inst.error || inst.relax)) |
b99bd4ef | 17204 | { |
9c2799c2 | 17205 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
17206 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
17207 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 17208 | { |
c19d1205 | 17209 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
17210 | return; |
17211 | } | |
17212 | } | |
076d447c PB |
17213 | |
17214 | /* Something has gone badly wrong if we try to relax a fixed size | |
17215 | instruction. */ | |
9c2799c2 | 17216 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 17217 | |
e74cfd16 PB |
17218 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
17219 | *opcode->tvariant); | |
ee065d83 | 17220 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 17221 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
7e806470 | 17222 | anything other than bl/blx and v6-M instructions. |
ee065d83 | 17223 | This is overly pessimistic for relaxable instructions. */ |
7e806470 PB |
17224 | if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) |
17225 | || inst.relax) | |
e07e6e58 NC |
17226 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
17227 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
e74cfd16 PB |
17228 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
17229 | arm_ext_v6t2); | |
cd000bff | 17230 | |
88714cb8 DG |
17231 | check_neon_suffixes; |
17232 | ||
cd000bff | 17233 | if (!inst.error) |
c877a2f2 NC |
17234 | { |
17235 | mapping_state (MAP_THUMB); | |
17236 | } | |
c19d1205 | 17237 | } |
3e9e4fcf | 17238 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 17239 | { |
845b51d6 PB |
17240 | bfd_boolean is_bx; |
17241 | ||
17242 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
17243 | is_bx = (opcode->aencode == do_bx); | |
17244 | ||
c19d1205 | 17245 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
17246 | if (!(is_bx && fix_v4bx) |
17247 | && !(opcode->avariant && | |
17248 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 17249 | { |
bf3eeda7 | 17250 | as_bad (_("selected processor does not support ARM mode `%s'"), str); |
c19d1205 | 17251 | return; |
b99bd4ef | 17252 | } |
c19d1205 | 17253 | if (inst.size_req) |
b99bd4ef | 17254 | { |
c19d1205 ZW |
17255 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
17256 | return; | |
b99bd4ef NC |
17257 | } |
17258 | ||
c19d1205 ZW |
17259 | inst.instruction = opcode->avalue; |
17260 | if (opcode->tag == OT_unconditionalF) | |
17261 | inst.instruction |= 0xF << 28; | |
17262 | else | |
17263 | inst.instruction |= inst.cond << 28; | |
17264 | inst.size = INSN_SIZE; | |
5be8be5d | 17265 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
e07e6e58 NC |
17266 | { |
17267 | it_fsm_pre_encode (); | |
17268 | opcode->aencode (); | |
17269 | it_fsm_post_encode (); | |
17270 | } | |
ee065d83 PB |
17271 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
17272 | on a hypothetical non-thumb v5 core. */ | |
845b51d6 | 17273 | if (is_bx) |
e74cfd16 | 17274 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 17275 | else |
e74cfd16 PB |
17276 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
17277 | *opcode->avariant); | |
88714cb8 DG |
17278 | |
17279 | check_neon_suffixes; | |
17280 | ||
cd000bff | 17281 | if (!inst.error) |
c877a2f2 NC |
17282 | { |
17283 | mapping_state (MAP_ARM); | |
17284 | } | |
b99bd4ef | 17285 | } |
3e9e4fcf JB |
17286 | else |
17287 | { | |
17288 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
17289 | "-- `%s'"), str); | |
17290 | return; | |
17291 | } | |
c19d1205 ZW |
17292 | output_inst (str); |
17293 | } | |
b99bd4ef | 17294 | |
e07e6e58 NC |
17295 | static void |
17296 | check_it_blocks_finished (void) | |
17297 | { | |
17298 | #ifdef OBJ_ELF | |
17299 | asection *sect; | |
17300 | ||
17301 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
17302 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
17303 | == MANUAL_IT_BLOCK) | |
17304 | { | |
17305 | as_warn (_("section '%s' finished with an open IT block."), | |
17306 | sect->name); | |
17307 | } | |
17308 | #else | |
17309 | if (now_it.state == MANUAL_IT_BLOCK) | |
17310 | as_warn (_("file finished with an open IT block.")); | |
17311 | #endif | |
17312 | } | |
17313 | ||
c19d1205 ZW |
17314 | /* Various frobbings of labels and their addresses. */ |
17315 | ||
17316 | void | |
17317 | arm_start_line_hook (void) | |
17318 | { | |
17319 | last_label_seen = NULL; | |
b99bd4ef NC |
17320 | } |
17321 | ||
c19d1205 ZW |
17322 | void |
17323 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 17324 | { |
c19d1205 | 17325 | last_label_seen = sym; |
b99bd4ef | 17326 | |
c19d1205 | 17327 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 17328 | |
c19d1205 ZW |
17329 | #if defined OBJ_COFF || defined OBJ_ELF |
17330 | ARM_SET_INTERWORK (sym, support_interwork); | |
17331 | #endif | |
b99bd4ef | 17332 | |
e07e6e58 NC |
17333 | force_automatic_it_block_close (); |
17334 | ||
5f4273c7 | 17335 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
17336 | as Thumb functions. This is because these labels, whilst |
17337 | they exist inside Thumb code, are not the entry points for | |
17338 | possible ARM->Thumb calls. Also, these labels can be used | |
17339 | as part of a computed goto or switch statement. eg gcc | |
17340 | can generate code that looks like this: | |
b99bd4ef | 17341 | |
c19d1205 ZW |
17342 | ldr r2, [pc, .Laaa] |
17343 | lsl r3, r3, #2 | |
17344 | ldr r2, [r3, r2] | |
17345 | mov pc, r2 | |
b99bd4ef | 17346 | |
c19d1205 ZW |
17347 | .Lbbb: .word .Lxxx |
17348 | .Lccc: .word .Lyyy | |
17349 | ..etc... | |
17350 | .Laaa: .word Lbbb | |
b99bd4ef | 17351 | |
c19d1205 ZW |
17352 | The first instruction loads the address of the jump table. |
17353 | The second instruction converts a table index into a byte offset. | |
17354 | The third instruction gets the jump address out of the table. | |
17355 | The fourth instruction performs the jump. | |
b99bd4ef | 17356 | |
c19d1205 ZW |
17357 | If the address stored at .Laaa is that of a symbol which has the |
17358 | Thumb_Func bit set, then the linker will arrange for this address | |
17359 | to have the bottom bit set, which in turn would mean that the | |
17360 | address computation performed by the third instruction would end | |
17361 | up with the bottom bit set. Since the ARM is capable of unaligned | |
17362 | word loads, the instruction would then load the incorrect address | |
17363 | out of the jump table, and chaos would ensue. */ | |
17364 | if (label_is_thumb_function_name | |
17365 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
17366 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 17367 | { |
c19d1205 ZW |
17368 | /* When the address of a Thumb function is taken the bottom |
17369 | bit of that address should be set. This will allow | |
17370 | interworking between Arm and Thumb functions to work | |
17371 | correctly. */ | |
b99bd4ef | 17372 | |
c19d1205 | 17373 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 17374 | |
c19d1205 | 17375 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 17376 | } |
07a53e5c | 17377 | |
07a53e5c | 17378 | dwarf2_emit_label (sym); |
b99bd4ef NC |
17379 | } |
17380 | ||
c921be7d | 17381 | bfd_boolean |
c19d1205 | 17382 | arm_data_in_code (void) |
b99bd4ef | 17383 | { |
c19d1205 | 17384 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 17385 | { |
c19d1205 ZW |
17386 | *input_line_pointer = '/'; |
17387 | input_line_pointer += 5; | |
17388 | *input_line_pointer = 0; | |
c921be7d | 17389 | return TRUE; |
b99bd4ef NC |
17390 | } |
17391 | ||
c921be7d | 17392 | return FALSE; |
b99bd4ef NC |
17393 | } |
17394 | ||
c19d1205 ZW |
17395 | char * |
17396 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 17397 | { |
c19d1205 | 17398 | int len; |
b99bd4ef | 17399 | |
c19d1205 ZW |
17400 | if (thumb_mode && (len = strlen (name)) > 5 |
17401 | && streq (name + len - 5, "/data")) | |
17402 | *(name + len - 5) = 0; | |
b99bd4ef | 17403 | |
c19d1205 | 17404 | return name; |
b99bd4ef | 17405 | } |
c19d1205 ZW |
17406 | \f |
17407 | /* Table of all register names defined by default. The user can | |
17408 | define additional names with .req. Note that all register names | |
17409 | should appear in both upper and lowercase variants. Some registers | |
17410 | also have mixed-case names. */ | |
b99bd4ef | 17411 | |
dcbf9037 | 17412 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 17413 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 17414 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
17415 | #define REGSET(p,t) \ |
17416 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
17417 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
17418 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
17419 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
17420 | #define REGSETH(p,t) \ |
17421 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
17422 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
17423 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
17424 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
17425 | #define REGSET2(p,t) \ | |
17426 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
17427 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
17428 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
17429 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
17430 | #define SPLRBANK(base,bank,t) \ |
17431 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
17432 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
17433 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
17434 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
17435 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
17436 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 17437 | |
c19d1205 | 17438 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 17439 | { |
c19d1205 ZW |
17440 | /* ARM integer registers. */ |
17441 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 17442 | |
c19d1205 ZW |
17443 | /* ATPCS synonyms. */ |
17444 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
17445 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
17446 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 17447 | |
c19d1205 ZW |
17448 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
17449 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
17450 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 17451 | |
c19d1205 ZW |
17452 | /* Well-known aliases. */ |
17453 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
17454 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
17455 | ||
17456 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
17457 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
17458 | ||
17459 | /* Coprocessor numbers. */ | |
17460 | REGSET(p, CP), REGSET(P, CP), | |
17461 | ||
17462 | /* Coprocessor register numbers. The "cr" variants are for backward | |
17463 | compatibility. */ | |
17464 | REGSET(c, CN), REGSET(C, CN), | |
17465 | REGSET(cr, CN), REGSET(CR, CN), | |
17466 | ||
90ec0d68 MGD |
17467 | /* ARM banked registers. */ |
17468 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
17469 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
17470 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
17471 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
17472 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
17473 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
17474 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
17475 | ||
17476 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
17477 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
17478 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
17479 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
17480 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
17481 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB), | |
17482 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), | |
17483 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
17484 | ||
17485 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
17486 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
17487 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
17488 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
17489 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
17490 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
17491 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
fa94de6b | 17492 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
17493 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
17494 | ||
c19d1205 ZW |
17495 | /* FPA registers. */ |
17496 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
17497 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
17498 | ||
17499 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
17500 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
17501 | ||
17502 | /* VFP SP registers. */ | |
5287ad62 JB |
17503 | REGSET(s,VFS), REGSET(S,VFS), |
17504 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
17505 | |
17506 | /* VFP DP Registers. */ | |
5287ad62 JB |
17507 | REGSET(d,VFD), REGSET(D,VFD), |
17508 | /* Extra Neon DP registers. */ | |
17509 | REGSETH(d,VFD), REGSETH(D,VFD), | |
17510 | ||
17511 | /* Neon QP registers. */ | |
17512 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
17513 | |
17514 | /* VFP control registers. */ | |
17515 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
17516 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
17517 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
17518 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
17519 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
17520 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
17521 | |
17522 | /* Maverick DSP coprocessor registers. */ | |
17523 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
17524 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
17525 | ||
17526 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
17527 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
17528 | REGDEF(dspsc,0,DSPSC), | |
17529 | ||
17530 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
17531 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
17532 | REGDEF(DSPSC,0,DSPSC), | |
17533 | ||
17534 | /* iWMMXt data registers - p0, c0-15. */ | |
17535 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
17536 | ||
17537 | /* iWMMXt control registers - p1, c0-3. */ | |
17538 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
17539 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
17540 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
17541 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
17542 | ||
17543 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
17544 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
17545 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
17546 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
17547 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
17548 | ||
17549 | /* XScale accumulator registers. */ | |
17550 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
17551 | }; | |
17552 | #undef REGDEF | |
17553 | #undef REGNUM | |
17554 | #undef REGSET | |
7ed4c4c5 | 17555 | |
c19d1205 ZW |
17556 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
17557 | within psr_required_here. */ | |
17558 | static const struct asm_psr psrs[] = | |
17559 | { | |
17560 | /* Backward compatibility notation. Note that "all" is no longer | |
17561 | truly all possible PSR bits. */ | |
17562 | {"all", PSR_c | PSR_f}, | |
17563 | {"flg", PSR_f}, | |
17564 | {"ctl", PSR_c}, | |
17565 | ||
17566 | /* Individual flags. */ | |
17567 | {"f", PSR_f}, | |
17568 | {"c", PSR_c}, | |
17569 | {"x", PSR_x}, | |
17570 | {"s", PSR_s}, | |
59b42a0d | 17571 | |
c19d1205 ZW |
17572 | /* Combinations of flags. */ |
17573 | {"fs", PSR_f | PSR_s}, | |
17574 | {"fx", PSR_f | PSR_x}, | |
17575 | {"fc", PSR_f | PSR_c}, | |
17576 | {"sf", PSR_s | PSR_f}, | |
17577 | {"sx", PSR_s | PSR_x}, | |
17578 | {"sc", PSR_s | PSR_c}, | |
17579 | {"xf", PSR_x | PSR_f}, | |
17580 | {"xs", PSR_x | PSR_s}, | |
17581 | {"xc", PSR_x | PSR_c}, | |
17582 | {"cf", PSR_c | PSR_f}, | |
17583 | {"cs", PSR_c | PSR_s}, | |
17584 | {"cx", PSR_c | PSR_x}, | |
17585 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
17586 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
17587 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
17588 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
17589 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
17590 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
17591 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
17592 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
17593 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
17594 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
17595 | {"scf", PSR_s | PSR_c | PSR_f}, | |
17596 | {"scx", PSR_s | PSR_c | PSR_x}, | |
17597 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
17598 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
17599 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
17600 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
17601 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
17602 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
17603 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
17604 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
17605 | {"csf", PSR_c | PSR_s | PSR_f}, | |
17606 | {"csx", PSR_c | PSR_s | PSR_x}, | |
17607 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
17608 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
17609 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
17610 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
17611 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
17612 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
17613 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
17614 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
17615 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
17616 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
17617 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
17618 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
17619 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
17620 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
17621 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
17622 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
17623 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
17624 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
17625 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
17626 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
17627 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
17628 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
17629 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
17630 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
17631 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
17632 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
17633 | }; | |
17634 | ||
62b3e311 PB |
17635 | /* Table of V7M psr names. */ |
17636 | static const struct asm_psr v7m_psrs[] = | |
17637 | { | |
2b744c99 PB |
17638 | {"apsr", 0 }, {"APSR", 0 }, |
17639 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
17640 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
17641 | {"psr", 3 }, {"PSR", 3 }, | |
17642 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
17643 | {"ipsr", 5 }, {"IPSR", 5 }, | |
17644 | {"epsr", 6 }, {"EPSR", 6 }, | |
17645 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
17646 | {"msp", 8 }, {"MSP", 8 }, | |
17647 | {"psp", 9 }, {"PSP", 9 }, | |
17648 | {"primask", 16}, {"PRIMASK", 16}, | |
17649 | {"basepri", 17}, {"BASEPRI", 17}, | |
00bbc0bd NC |
17650 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, |
17651 | {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */ | |
2b744c99 PB |
17652 | {"faultmask", 19}, {"FAULTMASK", 19}, |
17653 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
17654 | }; |
17655 | ||
c19d1205 ZW |
17656 | /* Table of all shift-in-operand names. */ |
17657 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 17658 | { |
c19d1205 ZW |
17659 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
17660 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
17661 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
17662 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
17663 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
17664 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
17665 | }; | |
b99bd4ef | 17666 | |
c19d1205 ZW |
17667 | /* Table of all explicit relocation names. */ |
17668 | #ifdef OBJ_ELF | |
17669 | static struct reloc_entry reloc_names[] = | |
17670 | { | |
17671 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
17672 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
17673 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
17674 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
17675 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
17676 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
17677 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
17678 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
17679 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
17680 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 | 17681 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
17682 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
17683 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
17684 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, | |
17685 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, | |
17686 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, | |
17687 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, | |
17688 | { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ} | |
c19d1205 ZW |
17689 | }; |
17690 | #endif | |
b99bd4ef | 17691 | |
c19d1205 ZW |
17692 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
17693 | static const struct asm_cond conds[] = | |
17694 | { | |
17695 | {"eq", 0x0}, | |
17696 | {"ne", 0x1}, | |
17697 | {"cs", 0x2}, {"hs", 0x2}, | |
17698 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
17699 | {"mi", 0x4}, | |
17700 | {"pl", 0x5}, | |
17701 | {"vs", 0x6}, | |
17702 | {"vc", 0x7}, | |
17703 | {"hi", 0x8}, | |
17704 | {"ls", 0x9}, | |
17705 | {"ge", 0xa}, | |
17706 | {"lt", 0xb}, | |
17707 | {"gt", 0xc}, | |
17708 | {"le", 0xd}, | |
17709 | {"al", 0xe} | |
17710 | }; | |
bfae80f2 | 17711 | |
e797f7e0 MGD |
17712 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
17713 | { L, CODE, ARM_FEATURE (FEAT, 0) }, \ | |
17714 | { U, CODE, ARM_FEATURE (FEAT, 0) } | |
17715 | ||
62b3e311 PB |
17716 | static struct asm_barrier_opt barrier_opt_names[] = |
17717 | { | |
e797f7e0 MGD |
17718 | UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER), |
17719 | UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER), | |
17720 | UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8), | |
17721 | UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER), | |
17722 | UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER), | |
17723 | UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER), | |
17724 | UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER), | |
17725 | UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8), | |
17726 | UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER), | |
17727 | UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER), | |
17728 | UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER), | |
17729 | UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER), | |
17730 | UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8), | |
17731 | UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER), | |
17732 | UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER), | |
17733 | UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8) | |
62b3e311 PB |
17734 | }; |
17735 | ||
e797f7e0 MGD |
17736 | #undef UL_BARRIER |
17737 | ||
c19d1205 ZW |
17738 | /* Table of ARM-format instructions. */ |
17739 | ||
17740 | /* Macros for gluing together operand strings. N.B. In all cases | |
17741 | other than OPS0, the trailing OP_stop comes from default | |
17742 | zero-initialization of the unspecified elements of the array. */ | |
17743 | #define OPS0() { OP_stop, } | |
17744 | #define OPS1(a) { OP_##a, } | |
17745 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
17746 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
17747 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
17748 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
17749 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
17750 | ||
5be8be5d DG |
17751 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
17752 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
17753 | MIX_ARM_THUMB_OPERANDS macro. | |
17754 | In order to use these macros, prefix the number of operands with _ | |
17755 | e.g. _3. */ | |
17756 | #define OPS_1(a) { a, } | |
17757 | #define OPS_2(a,b) { a,b, } | |
17758 | #define OPS_3(a,b,c) { a,b,c, } | |
17759 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
17760 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
17761 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
17762 | ||
c19d1205 ZW |
17763 | /* These macros abstract out the exact format of the mnemonic table and |
17764 | save some repeated characters. */ | |
17765 | ||
17766 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
17767 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 17768 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 17769 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
17770 | |
17771 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
17772 | a T_MNEM_xyz enumerator. */ | |
17773 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 17774 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 17775 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 17776 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
17777 | |
17778 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
17779 | infix after the third character. */ | |
17780 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 17781 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 17782 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 17783 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 17784 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 17785 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 17786 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 17787 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 17788 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 17789 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 17790 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 17791 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 17792 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 17793 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 17794 | |
c19d1205 | 17795 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
17796 | field is still 0xE. Many of the Thumb variants can be executed |
17797 | conditionally, so this is checked separately. */ | |
c19d1205 | 17798 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 17799 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 17800 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
17801 | |
17802 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
17803 | condition code field. */ | |
17804 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 17805 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 17806 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
17807 | |
17808 | /* ARM-only variants of all the above. */ | |
6a86118a | 17809 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 17810 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
17811 | |
17812 | #define C3(mnem, op, nops, ops, ae) \ | |
17813 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
17814 | ||
e3cb604e PB |
17815 | /* Legacy mnemonics that always have conditional infix after the third |
17816 | character. */ | |
17817 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 17818 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
17819 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
17820 | ||
8f06b2d8 PB |
17821 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
17822 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 17823 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 17824 | |
e3cb604e PB |
17825 | /* Legacy coprocessor instructions where conditional infix and conditional |
17826 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
17827 | not just the potentially ambiguous ones. */ | |
17828 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 17829 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
17830 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
17831 | ||
17832 | /* Coprocessor, takes either a suffix or a position-3 infix | |
17833 | (for an FPA corner case). */ | |
17834 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 17835 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 17836 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 17837 | |
6a86118a | 17838 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
17839 | { m1 #m2 m3, OPS##nops ops, \ |
17840 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
17841 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
17842 | ||
17843 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
17844 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
17845 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
17846 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
17847 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
17848 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
17849 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
17850 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
17851 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
17852 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
17853 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
17854 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
17855 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
17856 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
17857 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
17858 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
17859 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
17860 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
17861 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
17862 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
17863 | |
17864 | #define UE(mnem, op, nops, ops, ae) \ | |
17865 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
17866 | ||
17867 | #define UF(mnem, op, nops, ops, ae) \ | |
17868 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
17869 | ||
5287ad62 JB |
17870 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
17871 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
17872 | use the same encoding function for each. */ | |
17873 | #define NUF(mnem, op, nops, ops, enc) \ | |
17874 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
17875 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
17876 | ||
17877 | /* Neon data processing, version which indirects through neon_enc_tab for | |
17878 | the various overloaded versions of opcodes. */ | |
17879 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 17880 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
17881 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
17882 | ||
17883 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
17884 | version. */ | |
037e8744 JB |
17885 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
17886 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
17887 | THUMB_VARIANT, do_##enc, do_##enc } |
17888 | ||
037e8744 | 17889 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 17890 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
17891 | |
17892 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 17893 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 17894 | |
5287ad62 | 17895 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 17896 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 17897 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
17898 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
17899 | ||
037e8744 | 17900 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 17901 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
17902 | |
17903 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 17904 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 17905 | |
c19d1205 ZW |
17906 | #define do_0 0 |
17907 | ||
c19d1205 | 17908 | static const struct asm_opcode insns[] = |
bfae80f2 | 17909 | { |
e74cfd16 PB |
17910 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
17911 | #define THUMB_VARIANT &arm_ext_v4t | |
21d799b5 NC |
17912 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
17913 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
17914 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
17915 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
17916 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
17917 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
17918 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
17919 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
17920 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
17921 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
17922 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
17923 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
17924 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
17925 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
17926 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
17927 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
17928 | |
17929 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
17930 | for setting PSR flag bits. They are obsolete in V6 and do not | |
17931 | have Thumb equivalents. */ | |
21d799b5 NC |
17932 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
17933 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
17934 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
17935 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
17936 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
17937 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
17938 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
17939 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
17940 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
17941 | ||
17942 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
17943 | tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp), | |
17944 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), | |
17945 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
17946 | ||
17947 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
17948 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
17949 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
17950 | OP_RRnpc), | |
17951 | OP_ADDRGLDR),ldst, t_ldst), | |
17952 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
17953 | |
17954 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
17955 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
17956 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
17957 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
17958 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
17959 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
17960 | ||
17961 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
17962 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
17963 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), | |
17964 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 17965 | |
c19d1205 | 17966 | /* Pseudo ops. */ |
21d799b5 | 17967 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 17968 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 17969 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
c19d1205 ZW |
17970 | |
17971 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
17972 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
17973 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
17974 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
17975 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
17976 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
17977 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
17978 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
17979 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
17980 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
17981 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
17982 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
17983 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 17984 | |
16a4cf17 | 17985 | /* These may simplify to neg. */ |
21d799b5 NC |
17986 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
17987 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 17988 | |
c921be7d NC |
17989 | #undef THUMB_VARIANT |
17990 | #define THUMB_VARIANT & arm_ext_v6 | |
17991 | ||
21d799b5 | 17992 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
17993 | |
17994 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
17995 | #undef THUMB_VARIANT |
17996 | #define THUMB_VARIANT & arm_ext_v6t2 | |
17997 | ||
21d799b5 NC |
17998 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
17999 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
18000 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 18001 | |
5be8be5d DG |
18002 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
18003 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
18004 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
18005 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 18006 | |
21d799b5 NC |
18007 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
18008 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 18009 | |
21d799b5 NC |
18010 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
18011 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
18012 | |
18013 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 18014 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
18015 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
18016 | ||
18017 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
18018 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
18019 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
18020 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
18021 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
18022 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
18023 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
18024 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
18025 | ||
c921be7d NC |
18026 | #undef ARM_VARIANT |
18027 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
18028 | #undef THUMB_VARIANT | |
18029 | #define THUMB_VARIANT & arm_ext_v4t | |
18030 | ||
21d799b5 NC |
18031 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
18032 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 18033 | |
c921be7d NC |
18034 | #undef THUMB_VARIANT |
18035 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18036 | ||
21d799b5 | 18037 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
18038 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
18039 | ||
18040 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
18041 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
18042 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18043 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18044 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18045 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18046 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 18047 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 18048 | |
c921be7d NC |
18049 | #undef ARM_VARIANT |
18050 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
18051 | ||
21d799b5 | 18052 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
18053 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
18054 | ||
c921be7d NC |
18055 | #undef ARM_VARIANT |
18056 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
18057 | #undef THUMB_VARIANT | |
18058 | #define THUMB_VARIANT & arm_ext_msr | |
18059 | ||
d2cd1205 JB |
18060 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
18061 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 18062 | |
c921be7d NC |
18063 | #undef ARM_VARIANT |
18064 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
18065 | #undef THUMB_VARIANT | |
18066 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18067 | ||
21d799b5 NC |
18068 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
18069 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
18070 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
18071 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
18072 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
18073 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
18074 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
18075 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 18076 | |
c921be7d NC |
18077 | #undef ARM_VARIANT |
18078 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
18079 | #undef THUMB_VARIANT | |
18080 | #define THUMB_VARIANT & arm_ext_v4t | |
18081 | ||
5be8be5d DG |
18082 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
18083 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
18084 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
18085 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
56c0a61f RE |
18086 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
18087 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 18088 | |
c921be7d NC |
18089 | #undef ARM_VARIANT |
18090 | #define ARM_VARIANT & arm_ext_v4t_5 | |
18091 | ||
c19d1205 ZW |
18092 | /* ARM Architecture 4T. */ |
18093 | /* Note: bx (and blx) are required on V5, even if the processor does | |
18094 | not support Thumb. */ | |
21d799b5 | 18095 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 18096 | |
c921be7d NC |
18097 | #undef ARM_VARIANT |
18098 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
18099 | #undef THUMB_VARIANT | |
18100 | #define THUMB_VARIANT & arm_ext_v5t | |
18101 | ||
c19d1205 ZW |
18102 | /* Note: blx has 2 variants; the .value coded here is for |
18103 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
18104 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
18105 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 18106 | |
c921be7d NC |
18107 | #undef THUMB_VARIANT |
18108 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18109 | ||
21d799b5 NC |
18110 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
18111 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18112 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18113 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18114 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18115 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
18116 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
18117 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 18118 | |
c921be7d NC |
18119 | #undef ARM_VARIANT |
18120 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ | |
9e3c6df6 PB |
18121 | #undef THUMB_VARIANT |
18122 | #define THUMB_VARIANT &arm_ext_v5exp | |
c921be7d | 18123 | |
21d799b5 NC |
18124 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
18125 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
18126 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
18127 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 18128 | |
21d799b5 NC |
18129 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
18130 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 18131 | |
21d799b5 NC |
18132 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
18133 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
18134 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
18135 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 18136 | |
21d799b5 NC |
18137 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
18138 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18139 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18140 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 18141 | |
21d799b5 NC |
18142 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
18143 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 18144 | |
03ee1b7f NC |
18145 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
18146 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
18147 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
18148 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 18149 | |
c921be7d NC |
18150 | #undef ARM_VARIANT |
18151 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ | |
9e3c6df6 PB |
18152 | #undef THUMB_VARIANT |
18153 | #define THUMB_VARIANT &arm_ext_v6t2 | |
c921be7d | 18154 | |
21d799b5 | 18155 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
18156 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
18157 | ldrd, t_ldstd), | |
18158 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
18159 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 18160 | |
21d799b5 NC |
18161 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
18162 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 18163 | |
c921be7d NC |
18164 | #undef ARM_VARIANT |
18165 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
18166 | ||
21d799b5 | 18167 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 18168 | |
c921be7d NC |
18169 | #undef ARM_VARIANT |
18170 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
18171 | #undef THUMB_VARIANT | |
18172 | #define THUMB_VARIANT & arm_ext_v6 | |
18173 | ||
21d799b5 NC |
18174 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
18175 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
18176 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
18177 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
18178 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
18179 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18180 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18181 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18182 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18183 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 18184 | |
c921be7d NC |
18185 | #undef THUMB_VARIANT |
18186 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18187 | ||
5be8be5d DG |
18188 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
18189 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
18190 | strex, t_strex), | |
21d799b5 NC |
18191 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
18192 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 18193 | |
21d799b5 NC |
18194 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
18195 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 18196 | |
9e3c6df6 | 18197 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
18198 | #undef THUMB_VARIANT |
18199 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 18200 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 18201 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
18202 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
18203 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
18204 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
18205 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
d709e4e6 RE |
18206 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
18207 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
18208 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 18209 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
18210 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
18211 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 18212 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 18213 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 18214 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 18215 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 18216 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 18217 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
c921be7d | 18218 | |
9e3c6df6 PB |
18219 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
18220 | #undef THUMB_VARIANT | |
18221 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
18222 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
18223 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), | |
18224 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
18225 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18226 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18227 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18228 | /* Old name for QASX. */ |
21d799b5 NC |
18229 | TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18230 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18231 | /* Old name for QSAX. */ |
21d799b5 NC |
18232 | TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18233 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18234 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18235 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18236 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18237 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18238 | /* Old name for SASX. */ |
21d799b5 NC |
18239 | TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18240 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18241 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18242 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18243 | /* Old name for SHASX. */ |
21d799b5 NC |
18244 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18245 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18246 | /* Old name for SHSAX. */ |
21d799b5 NC |
18247 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18248 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18249 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18250 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18251 | /* Old name for SSAX. */ |
21d799b5 NC |
18252 | TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18253 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18254 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18255 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18256 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18257 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18258 | /* Old name for UASX. */ |
21d799b5 NC |
18259 | TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18260 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18261 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18262 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18263 | /* Old name for UHASX. */ |
21d799b5 NC |
18264 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18265 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18266 | /* Old name for UHSAX. */ |
21d799b5 NC |
18267 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18268 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18269 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18270 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18271 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18272 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18273 | /* Old name for UQASX. */ |
21d799b5 NC |
18274 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18275 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18276 | /* Old name for UQSAX. */ |
21d799b5 NC |
18277 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18278 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18279 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18280 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18281 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 18282 | /* Old name for USAX. */ |
21d799b5 NC |
18283 | TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
18284 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
21d799b5 NC |
18285 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
18286 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
18287 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
18288 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18289 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
18290 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
18291 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
18292 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18293 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
18294 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18295 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18296 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
18297 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
18298 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18299 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18300 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
18301 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
18302 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18303 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18304 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18305 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18306 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18307 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18308 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18309 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18310 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18311 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
18312 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
18313 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
18314 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18315 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
18316 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 18317 | |
c921be7d NC |
18318 | #undef ARM_VARIANT |
18319 | #define ARM_VARIANT & arm_ext_v6k | |
18320 | #undef THUMB_VARIANT | |
18321 | #define THUMB_VARIANT & arm_ext_v6k | |
18322 | ||
21d799b5 NC |
18323 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
18324 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
18325 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
18326 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 18327 | |
c921be7d NC |
18328 | #undef THUMB_VARIANT |
18329 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
18330 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
18331 | ldrexd, t_ldrexd), | |
18332 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
18333 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 18334 | |
c921be7d NC |
18335 | #undef THUMB_VARIANT |
18336 | #define THUMB_VARIANT & arm_ext_v6t2 | |
5be8be5d DG |
18337 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
18338 | rd_rn, rd_rn), | |
18339 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
18340 | rd_rn, rd_rn), | |
18341 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
877807f8 | 18342 | strex, t_strexbh), |
5be8be5d | 18343 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 18344 | strex, t_strexbh), |
21d799b5 | 18345 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 18346 | |
c921be7d | 18347 | #undef ARM_VARIANT |
f4c65163 MGD |
18348 | #define ARM_VARIANT & arm_ext_sec |
18349 | #undef THUMB_VARIANT | |
18350 | #define THUMB_VARIANT & arm_ext_sec | |
c921be7d | 18351 | |
21d799b5 | 18352 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 18353 | |
90ec0d68 MGD |
18354 | #undef ARM_VARIANT |
18355 | #define ARM_VARIANT & arm_ext_virt | |
18356 | #undef THUMB_VARIANT | |
18357 | #define THUMB_VARIANT & arm_ext_virt | |
18358 | ||
18359 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
18360 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
18361 | ||
c921be7d NC |
18362 | #undef ARM_VARIANT |
18363 | #define ARM_VARIANT & arm_ext_v6t2 | |
f4c65163 MGD |
18364 | #undef THUMB_VARIANT |
18365 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 18366 | |
21d799b5 NC |
18367 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
18368 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
18369 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
18370 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 18371 | |
21d799b5 NC |
18372 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
18373 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
18374 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
18375 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), | |
c19d1205 | 18376 | |
5be8be5d DG |
18377 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
18378 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
18379 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
18380 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 18381 | |
bf3eeda7 NS |
18382 | /* Thumb-only instructions. */ |
18383 | #undef ARM_VARIANT | |
18384 | #define ARM_VARIANT NULL | |
18385 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
18386 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
18387 | |
18388 | /* ARM does not really have an IT instruction, so always allow it. | |
18389 | The opcode is copied from Thumb in order to allow warnings in | |
18390 | -mimplicit-it=[never | arm] modes. */ | |
18391 | #undef ARM_VARIANT | |
18392 | #define ARM_VARIANT & arm_ext_v1 | |
18393 | ||
21d799b5 NC |
18394 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
18395 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
18396 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
18397 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
18398 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
18399 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
18400 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
18401 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
18402 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
18403 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
18404 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
18405 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
18406 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
18407 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
18408 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 18409 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
18410 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
18411 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 18412 | |
92e90b6e | 18413 | /* Thumb2 only instructions. */ |
c921be7d NC |
18414 | #undef ARM_VARIANT |
18415 | #define ARM_VARIANT NULL | |
92e90b6e | 18416 | |
21d799b5 NC |
18417 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
18418 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
18419 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
18420 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
18421 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
18422 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 18423 | |
eea54501 MGD |
18424 | /* Hardware division instructions. */ |
18425 | #undef ARM_VARIANT | |
18426 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
18427 | #undef THUMB_VARIANT |
18428 | #define THUMB_VARIANT & arm_ext_div | |
18429 | ||
eea54501 MGD |
18430 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
18431 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 18432 | |
7e806470 | 18433 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
18434 | #undef ARM_VARIANT |
18435 | #define ARM_VARIANT & arm_ext_barrier | |
18436 | #undef THUMB_VARIANT | |
18437 | #define THUMB_VARIANT & arm_ext_barrier | |
18438 | ||
52e7f43d RE |
18439 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier), |
18440 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier), | |
18441 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier), | |
7e806470 | 18442 | |
62b3e311 | 18443 | /* ARM V7 instructions. */ |
c921be7d NC |
18444 | #undef ARM_VARIANT |
18445 | #define ARM_VARIANT & arm_ext_v7 | |
18446 | #undef THUMB_VARIANT | |
18447 | #define THUMB_VARIANT & arm_ext_v7 | |
18448 | ||
21d799b5 NC |
18449 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
18450 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 18451 | |
60e5ef9f MGD |
18452 | #undef ARM_VARIANT |
18453 | #define ARM_VARIANT & arm_ext_mp | |
18454 | #undef THUMB_VARIANT | |
18455 | #define THUMB_VARIANT & arm_ext_mp | |
18456 | ||
18457 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
18458 | ||
53c4b28b MGD |
18459 | /* AArchv8 instructions. */ |
18460 | #undef ARM_VARIANT | |
18461 | #define ARM_VARIANT & arm_ext_v8 | |
18462 | #undef THUMB_VARIANT | |
18463 | #define THUMB_VARIANT & arm_ext_v8 | |
18464 | ||
18465 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), | |
8884b720 | 18466 | TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt), |
4b8c8c02 RE |
18467 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
18468 | TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb), | |
9eb6c0f1 | 18469 | ldrexd, t_ldrexd), |
4b8c8c02 RE |
18470 | TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn), |
18471 | TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
18472 | TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb), | |
18473 | stlex, t_stlex), | |
18474 | TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), | |
9eb6c0f1 | 18475 | strexd, t_strexd), |
4b8c8c02 RE |
18476 | TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb), |
18477 | stlex, t_stlex), | |
18478 | TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb), | |
18479 | stlex, t_stlex), | |
18480 | TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
18481 | TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
18482 | TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
18483 | TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
18484 | TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
18485 | TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
53c4b28b | 18486 | |
8884b720 | 18487 | /* ARMv8 T32 only. */ |
b79f7053 MGD |
18488 | #undef ARM_VARIANT |
18489 | #define ARM_VARIANT NULL | |
18490 | TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs), | |
18491 | TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs), | |
18492 | TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs), | |
18493 | ||
33399f07 MGD |
18494 | /* FP for ARMv8. */ |
18495 | #undef ARM_VARIANT | |
18496 | #define ARM_VARIANT & fpu_vfp_ext_armv8 | |
18497 | #undef THUMB_VARIANT | |
18498 | #define THUMB_VARIANT & fpu_vfp_ext_armv8 | |
18499 | ||
18500 | nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel), | |
18501 | nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel), | |
18502 | nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel), | |
18503 | nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel), | |
73924fbc MGD |
18504 | nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), |
18505 | nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), | |
7e8e6784 MGD |
18506 | nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta), |
18507 | nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn), | |
18508 | nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp), | |
18509 | nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm), | |
30bdf752 MGD |
18510 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
18511 | nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz), | |
18512 | nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx), | |
18513 | nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta), | |
18514 | nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn), | |
18515 | nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp), | |
18516 | nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm), | |
33399f07 | 18517 | |
91ff7894 MGD |
18518 | /* Crypto v1 extensions. */ |
18519 | #undef ARM_VARIANT | |
18520 | #define ARM_VARIANT & fpu_crypto_ext_armv8 | |
18521 | #undef THUMB_VARIANT | |
18522 | #define THUMB_VARIANT & fpu_crypto_ext_armv8 | |
18523 | ||
18524 | nUF(aese, _aes, 2, (RNQ, RNQ), aese), | |
18525 | nUF(aesd, _aes, 2, (RNQ, RNQ), aesd), | |
18526 | nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc), | |
18527 | nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc), | |
48adcd8e MGD |
18528 | nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c), |
18529 | nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p), | |
18530 | nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m), | |
18531 | nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0), | |
18532 | nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h), | |
18533 | nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2), | |
18534 | nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1), | |
3c9017d2 MGD |
18535 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
18536 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
18537 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 18538 | |
c921be7d NC |
18539 | #undef ARM_VARIANT |
18540 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
18541 | #undef THUMB_VARIANT |
18542 | #define THUMB_VARIANT NULL | |
c921be7d | 18543 | |
21d799b5 NC |
18544 | cCE("wfs", e200110, 1, (RR), rd), |
18545 | cCE("rfs", e300110, 1, (RR), rd), | |
18546 | cCE("wfc", e400110, 1, (RR), rd), | |
18547 | cCE("rfc", e500110, 1, (RR), rd), | |
18548 | ||
18549 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18550 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18551 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18552 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18553 | ||
18554 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18555 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18556 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18557 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
18558 | ||
18559 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
18560 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
18561 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
18562 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
18563 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
18564 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
18565 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
18566 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
18567 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
18568 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
18569 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
18570 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
18571 | ||
18572 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
18573 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
18574 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
18575 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
18576 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
18577 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
18578 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
18579 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
18580 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
18581 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
18582 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
18583 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
18584 | ||
18585 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
18586 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
18587 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
18588 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
18589 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
18590 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
18591 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
18592 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
18593 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
18594 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
18595 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
18596 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
18597 | ||
18598 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
18599 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
18600 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
18601 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
18602 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
18603 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
18604 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
18605 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
18606 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
18607 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
18608 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
18609 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
18610 | ||
18611 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
18612 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
18613 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
18614 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
18615 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
18616 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
18617 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
18618 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
18619 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
18620 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
18621 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
18622 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
18623 | ||
18624 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
18625 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
18626 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
18627 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
18628 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
18629 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
18630 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
18631 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
18632 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
18633 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
18634 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
18635 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
18636 | ||
18637 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
18638 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
18639 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
18640 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
18641 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
18642 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
18643 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
18644 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
18645 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
18646 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
18647 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
18648 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
18649 | ||
18650 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
18651 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
18652 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
18653 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
18654 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
18655 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
18656 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
18657 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
18658 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
18659 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
18660 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
18661 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
18662 | ||
18663 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
18664 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
18665 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
18666 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
18667 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
18668 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
18669 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
18670 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
18671 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
18672 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
18673 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
18674 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
18675 | ||
18676 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
18677 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
18678 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
18679 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
18680 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
18681 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
18682 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
18683 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
18684 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
18685 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
18686 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
18687 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
18688 | ||
18689 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
18690 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
18691 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
18692 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
18693 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
18694 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
18695 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
18696 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
18697 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
18698 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
18699 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
18700 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
18701 | ||
18702 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
18703 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
18704 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
18705 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
18706 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
18707 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
18708 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
18709 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
18710 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
18711 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
18712 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
18713 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
18714 | ||
18715 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
18716 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
18717 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
18718 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
18719 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
18720 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
18721 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
18722 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
18723 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
18724 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
18725 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
18726 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
18727 | ||
18728 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
18729 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
18730 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
18731 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
18732 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
18733 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
18734 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
18735 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
18736 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
18737 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
18738 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
18739 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
18740 | ||
18741 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
18742 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
18743 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
18744 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
18745 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
18746 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
18747 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
18748 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
18749 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
18750 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
18751 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
18752 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
18753 | ||
18754 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
18755 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
18756 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
18757 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
18758 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
18759 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
18760 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
18761 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
18762 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
18763 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
18764 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
18765 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
18766 | ||
18767 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18768 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18769 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18770 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18771 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18772 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18773 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18774 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18775 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18776 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18777 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18778 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18779 | ||
18780 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18781 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18782 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18783 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18784 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18785 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18786 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18787 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18788 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18789 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18790 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18791 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18792 | ||
18793 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18794 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18795 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18796 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18797 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18798 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18799 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18800 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18801 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18802 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18803 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18804 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18805 | ||
18806 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18807 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18808 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18809 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18810 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18811 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18812 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18813 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18814 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18815 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18816 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18817 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18818 | ||
18819 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18820 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18821 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18822 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18823 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18824 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18825 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18826 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18827 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18828 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18829 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18830 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18831 | ||
18832 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18833 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18834 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18835 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18836 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18837 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18838 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18839 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18840 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18841 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18842 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18843 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18844 | ||
18845 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18846 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18847 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18848 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18849 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18850 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18851 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18852 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18853 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18854 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18855 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18856 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18857 | ||
18858 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18859 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18860 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18861 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18862 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18863 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18864 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18865 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18866 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18867 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18868 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18869 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18870 | ||
18871 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18872 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18873 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18874 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18875 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18876 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18877 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18878 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18879 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18880 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18881 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18882 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18883 | ||
18884 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18885 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18886 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18887 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18888 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18889 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18890 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18891 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18892 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18893 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18894 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18895 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18896 | ||
18897 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18898 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18899 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18900 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18901 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18902 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18903 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18904 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18905 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18906 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18907 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18908 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18909 | ||
18910 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18911 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18912 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18913 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18914 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18915 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18916 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18917 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18918 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18919 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18920 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18921 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18922 | ||
18923 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18924 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18925 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18926 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18927 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18928 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18929 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18930 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18931 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18932 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18933 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18934 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
18935 | ||
18936 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
18937 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
18938 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
18939 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
18940 | ||
18941 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
18942 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
18943 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
18944 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
18945 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
18946 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
18947 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
18948 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
18949 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
18950 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
18951 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
18952 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 18953 | |
c19d1205 ZW |
18954 | /* The implementation of the FIX instruction is broken on some |
18955 | assemblers, in that it accepts a precision specifier as well as a | |
18956 | rounding specifier, despite the fact that this is meaningless. | |
18957 | To be more compatible, we accept it as well, though of course it | |
18958 | does not set any bits. */ | |
21d799b5 NC |
18959 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
18960 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
18961 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
18962 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
18963 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
18964 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
18965 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
18966 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
18967 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
18968 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
18969 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
18970 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
18971 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 18972 | |
c19d1205 | 18973 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
18974 | #undef ARM_VARIANT |
18975 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
18976 | ||
21d799b5 NC |
18977 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
18978 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
18979 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
18980 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
18981 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
18982 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 18983 | |
c921be7d NC |
18984 | #undef ARM_VARIANT |
18985 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
18986 | ||
c19d1205 | 18987 | /* Moves and type conversions. */ |
21d799b5 NC |
18988 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
18989 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
18990 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
18991 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
7465e07a NC |
18992 | cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs), |
18993 | cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr), | |
21d799b5 NC |
18994 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), |
18995 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
18996 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
18997 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
18998 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
18999 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
19000 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
19001 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
19002 | |
19003 | /* Memory operations. */ | |
21d799b5 NC |
19004 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
19005 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
19006 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
19007 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
19008 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19009 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19010 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19011 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19012 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
19013 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
19014 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
19015 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
19016 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19017 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19018 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19019 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19020 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
19021 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 19022 | |
c19d1205 | 19023 | /* Monadic operations. */ |
21d799b5 NC |
19024 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
19025 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
19026 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
19027 | |
19028 | /* Dyadic operations. */ | |
21d799b5 NC |
19029 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
19030 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19031 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19032 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19033 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19034 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19035 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19036 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19037 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 19038 | |
c19d1205 | 19039 | /* Comparisons. */ |
21d799b5 NC |
19040 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
19041 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
19042 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
19043 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 19044 | |
62f3b8c8 PB |
19045 | /* Double precision load/store are still present on single precision |
19046 | implementations. */ | |
19047 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
19048 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
19049 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
19050 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
19051 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
19052 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
19053 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
19054 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
19055 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
19056 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 19057 | |
c921be7d NC |
19058 | #undef ARM_VARIANT |
19059 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
19060 | ||
c19d1205 | 19061 | /* Moves and type conversions. */ |
21d799b5 NC |
19062 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
19063 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
19064 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19065 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
19066 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
19067 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
19068 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
19069 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
19070 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
19071 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19072 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19073 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19074 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 19075 | |
c19d1205 | 19076 | /* Monadic operations. */ |
21d799b5 NC |
19077 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
19078 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
19079 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
19080 | |
19081 | /* Dyadic operations. */ | |
21d799b5 NC |
19082 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
19083 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19084 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19085 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19086 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19087 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19088 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19089 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19090 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 19091 | |
c19d1205 | 19092 | /* Comparisons. */ |
21d799b5 NC |
19093 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
19094 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
19095 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
19096 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 19097 | |
c921be7d NC |
19098 | #undef ARM_VARIANT |
19099 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
19100 | ||
21d799b5 NC |
19101 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
19102 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
19103 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
19104 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 19105 | |
037e8744 JB |
19106 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
19107 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
19108 | #undef ARM_VARIANT |
19109 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
19110 | #undef THUMB_VARIANT | |
19111 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
19112 | ||
037e8744 JB |
19113 | /* These mnemonics are unique to VFP. */ |
19114 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
19115 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
19116 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
19117 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
19118 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
19119 | nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
19120 | nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
037e8744 JB |
19121 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
19122 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
19123 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
19124 | ||
19125 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
19126 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
19127 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
19128 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 19129 | |
21d799b5 NC |
19130 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
19131 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
19132 | |
19133 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
19134 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
19135 | ||
55881a11 MGD |
19136 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
19137 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19138 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19139 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19140 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19141 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
19142 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
19143 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 | 19144 | |
5f1af56b | 19145 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt), |
e3e535bc | 19146 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
c70a8987 MGD |
19147 | NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb), |
19148 | NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt), | |
f31fef98 | 19149 | |
037e8744 JB |
19150 | |
19151 | /* NOTE: All VMOV encoding is special-cased! */ | |
19152 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
19153 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
19154 | ||
c921be7d NC |
19155 | #undef THUMB_VARIANT |
19156 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
19157 | #undef ARM_VARIANT | |
19158 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
19159 | ||
5287ad62 JB |
19160 | /* Data processing with three registers of the same length. */ |
19161 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
19162 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
19163 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
19164 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
19165 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
19166 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
19167 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
19168 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
19169 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
19170 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
19171 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
19172 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
19173 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
19174 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
19175 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
19176 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
19177 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
19178 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
19179 | /* If not immediate, fall back to neon_dyadic_i64_su. |
19180 | shl_imm should accept I8 I16 I32 I64, | |
19181 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
19182 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
19183 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
19184 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
19185 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 19186 | /* Logic ops, types optional & ignored. */ |
4316f0d2 DG |
19187 | nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), |
19188 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
19189 | nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
19190 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
19191 | nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
19192 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
19193 | nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
19194 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
19195 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
19196 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
19197 | /* Bitfield ops, untyped. */ |
19198 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
19199 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
19200 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
19201 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
19202 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
19203 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
19204 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
21d799b5 NC |
19205 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
19206 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
19207 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
19208 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
19209 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
19210 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
19211 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
19212 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
19213 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
19214 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
19215 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
19216 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
19217 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
19218 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
19219 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
19220 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 19221 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
19222 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
19223 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 19224 | /* As above, D registers only. */ |
21d799b5 NC |
19225 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
19226 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 19227 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
19228 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
19229 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
19230 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 19231 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
19232 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
19233 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
19234 | /* vtst takes sizes 8, 16, 32. */ |
19235 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
19236 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
19237 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 19238 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 19239 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
19240 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
19241 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
19242 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
19243 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
19244 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
19245 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
19246 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
19247 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
19248 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
19249 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
19250 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
19251 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
19252 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
19253 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
19254 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
19255 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
19256 | ||
19257 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 19258 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
19259 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
19260 | ||
19261 | /* Data processing with two registers and a shift amount. */ | |
19262 | /* Right shifts, and variants with rounding. | |
19263 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
19264 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
19265 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
19266 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
19267 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
19268 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
19269 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
19270 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
19271 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
19272 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
19273 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
19274 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
19275 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
19276 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
19277 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
19278 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
19279 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
19280 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
19281 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
19282 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
19283 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
19284 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
19285 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
19286 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
19287 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
19288 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
19289 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
19290 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 19291 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 19292 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 19293 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 19294 | |
4316f0d2 DG |
19295 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn), |
19296 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), | |
5287ad62 JB |
19297 | |
19298 | /* Data processing, three registers of different lengths. */ | |
19299 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
19300 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
19301 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
19302 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
19303 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
19304 | /* If not scalar, fall back to neon_dyadic_long. | |
19305 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
19306 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
19307 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
19308 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
19309 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
19310 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
19311 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
19312 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
19313 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
19314 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
19315 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
19316 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
19317 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
19318 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
19319 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
19320 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
19321 | S16 S32 U16 U32. */ | |
21d799b5 | 19322 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
19323 | |
19324 | /* Extract. Size 8. */ | |
3b8d421e PB |
19325 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
19326 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
19327 | |
19328 | /* Two registers, miscellaneous. */ | |
19329 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
19330 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
19331 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
19332 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
19333 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
19334 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
19335 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
19336 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
19337 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
19338 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
19339 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
19340 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
19341 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 19342 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 19343 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 19344 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 19345 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 19346 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
19347 | /* VZIP / VUZP. Sizes 8 16 32. */ |
19348 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
19349 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
19350 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
19351 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
19352 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
19353 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
19354 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
19355 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
19356 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
19357 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
19358 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
19359 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
19360 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
19361 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
19362 | /* Reciprocal estimates. Types U32 F32. */ | |
19363 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
19364 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
19365 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
19366 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
19367 | /* VCLS. Types S8 S16 S32. */ | |
19368 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
19369 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
19370 | /* VCLZ. Types I8 I16 I32. */ | |
19371 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
19372 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
19373 | /* VCNT. Size 8. */ | |
19374 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
19375 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
19376 | /* Two address, untyped. */ | |
19377 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
19378 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
19379 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
19380 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
19381 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
19382 | |
19383 | /* Table lookup. Size 8. */ | |
19384 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
19385 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
19386 | ||
c921be7d NC |
19387 | #undef THUMB_VARIANT |
19388 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
19389 | #undef ARM_VARIANT | |
19390 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
19391 | ||
5287ad62 | 19392 | /* Neon element/structure load/store. */ |
21d799b5 NC |
19393 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
19394 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
19395 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
19396 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
19397 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
19398 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
19399 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
19400 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 19401 | |
c921be7d | 19402 | #undef THUMB_VARIANT |
62f3b8c8 PB |
19403 | #define THUMB_VARIANT &fpu_vfp_ext_v3xd |
19404 | #undef ARM_VARIANT | |
19405 | #define ARM_VARIANT &fpu_vfp_ext_v3xd | |
19406 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), | |
19407 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
19408 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
19409 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
19410 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
19411 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
19412 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
19413 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
19414 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
19415 | ||
19416 | #undef THUMB_VARIANT | |
c921be7d NC |
19417 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
19418 | #undef ARM_VARIANT | |
19419 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
19420 | ||
21d799b5 | 19421 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 19422 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 19423 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 19424 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 19425 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 19426 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 19427 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 19428 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 19429 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 19430 | |
62f3b8c8 PB |
19431 | #undef ARM_VARIANT |
19432 | #define ARM_VARIANT &fpu_vfp_ext_fma | |
19433 | #undef THUMB_VARIANT | |
19434 | #define THUMB_VARIANT &fpu_vfp_ext_fma | |
19435 | /* Mnemonics shared by Neon and VFP. These are included in the | |
19436 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
19437 | FMA instructions. */ | |
19438 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
19439 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
19440 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
19441 | the v form should always be used. */ | |
19442 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19443 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19444 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19445 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19446 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
19447 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
19448 | ||
5287ad62 | 19449 | #undef THUMB_VARIANT |
c921be7d NC |
19450 | #undef ARM_VARIANT |
19451 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
19452 | ||
21d799b5 NC |
19453 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
19454 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
19455 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
19456 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
19457 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
19458 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
19459 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
19460 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 19461 | |
c921be7d NC |
19462 | #undef ARM_VARIANT |
19463 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
19464 | ||
21d799b5 NC |
19465 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
19466 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
19467 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
19468 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
19469 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
19470 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
19471 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
19472 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
19473 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
19474 | cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
19475 | cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
19476 | cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
19477 | cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
19478 | cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
19479 | cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
19480 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
19481 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
19482 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
19483 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
19484 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
19485 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
19486 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
19487 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
19488 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
19489 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
19490 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
19491 | cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn), | |
19492 | cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn), | |
19493 | cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn), | |
19494 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), | |
19495 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
19496 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
19497 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
19498 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
19499 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
19500 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
19501 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
19502 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19503 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19504 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19505 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19506 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19507 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19508 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19509 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19510 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19511 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
19512 | cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19513 | cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19514 | cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19515 | cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19516 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19517 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19518 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19519 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19520 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19521 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19522 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19523 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19524 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19525 | cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19526 | cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19527 | cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19528 | cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19529 | cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19530 | cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19531 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
19532 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
19533 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
19534 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
19535 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19536 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19537 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19538 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19539 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19540 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19541 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19542 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19543 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19544 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19545 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19546 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19547 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19548 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19549 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19550 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19551 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19552 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19553 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
19554 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19555 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19556 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19557 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19558 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19559 | cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19560 | cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19561 | cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19562 | cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19563 | cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19564 | cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19565 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19566 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19567 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19568 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19569 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19570 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19571 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19572 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19573 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19574 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19575 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
19576 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19577 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19578 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19579 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19580 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19581 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19582 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19583 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19584 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19585 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19586 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19587 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19588 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19589 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19590 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19591 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19592 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
19593 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
19594 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
19595 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
19596 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
19597 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
19598 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19599 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19600 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19601 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19602 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19603 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19604 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19605 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19606 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19607 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
19608 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
19609 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
19610 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
19611 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
19612 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
19613 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19614 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19615 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19616 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
19617 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
19618 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
19619 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
19620 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
19621 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
19622 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19623 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19624 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19625 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19626 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 19627 | |
c921be7d NC |
19628 | #undef ARM_VARIANT |
19629 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
19630 | ||
21d799b5 NC |
19631 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
19632 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
19633 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
19634 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
19635 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
19636 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
19637 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19638 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19639 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19640 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19641 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19642 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19643 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19644 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19645 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19646 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19647 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19648 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19649 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19650 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19651 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
19652 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19653 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19654 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19655 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19656 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19657 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19658 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19659 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19660 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19661 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19662 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19663 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19664 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19665 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19666 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19667 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19668 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19669 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19670 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19671 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19672 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19673 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19674 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19675 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19676 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19677 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19678 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19679 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19680 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19681 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19682 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19683 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19684 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19685 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19686 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
19687 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 19688 | |
c921be7d NC |
19689 | #undef ARM_VARIANT |
19690 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
19691 | ||
21d799b5 NC |
19692 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
19693 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
19694 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
19695 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
19696 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
19697 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
19698 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
19699 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
19700 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
19701 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
19702 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
19703 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
19704 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
19705 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
19706 | cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd), | |
19707 | cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn), | |
19708 | cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd), | |
19709 | cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn), | |
19710 | cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn), | |
19711 | cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn), | |
19712 | cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn), | |
19713 | cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn), | |
19714 | cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn), | |
19715 | cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn), | |
19716 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), | |
19717 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
19718 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
19719 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
19720 | cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
19721 | cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd), | |
19722 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), | |
19723 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
19724 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
19725 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
19726 | cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn), | |
19727 | cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn), | |
19728 | cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn), | |
19729 | cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn), | |
19730 | cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn), | |
19731 | cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn), | |
19732 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), | |
19733 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
19734 | cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
19735 | cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
19736 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
19737 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
19738 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
19739 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
19740 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
19741 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
19742 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
19743 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
19744 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
19745 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
19746 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
19747 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
19748 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
19749 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
19750 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
19751 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
19752 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
19753 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
19754 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
19755 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
19756 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
19757 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
19758 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
19759 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
19760 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
19761 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
19762 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
19763 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
19764 | cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
19765 | cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
19766 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
19767 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
19768 | }; |
19769 | #undef ARM_VARIANT | |
19770 | #undef THUMB_VARIANT | |
19771 | #undef TCE | |
c19d1205 ZW |
19772 | #undef TUE |
19773 | #undef TUF | |
19774 | #undef TCC | |
8f06b2d8 | 19775 | #undef cCE |
e3cb604e PB |
19776 | #undef cCL |
19777 | #undef C3E | |
c19d1205 ZW |
19778 | #undef CE |
19779 | #undef CM | |
19780 | #undef UE | |
19781 | #undef UF | |
19782 | #undef UT | |
5287ad62 JB |
19783 | #undef NUF |
19784 | #undef nUF | |
19785 | #undef NCE | |
19786 | #undef nCE | |
c19d1205 ZW |
19787 | #undef OPS0 |
19788 | #undef OPS1 | |
19789 | #undef OPS2 | |
19790 | #undef OPS3 | |
19791 | #undef OPS4 | |
19792 | #undef OPS5 | |
19793 | #undef OPS6 | |
19794 | #undef do_0 | |
19795 | \f | |
19796 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 19797 | |
c19d1205 ZW |
19798 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
19799 | for use in the a.out file, and stores them in the array pointed to by buf. | |
19800 | This knows about the endian-ness of the target machine and does | |
19801 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
19802 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
19803 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 19804 | |
c19d1205 ZW |
19805 | void |
19806 | md_number_to_chars (char * buf, valueT val, int n) | |
19807 | { | |
19808 | if (target_big_endian) | |
19809 | number_to_chars_bigendian (buf, val, n); | |
19810 | else | |
19811 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
19812 | } |
19813 | ||
c19d1205 ZW |
19814 | static valueT |
19815 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 19816 | { |
c19d1205 ZW |
19817 | valueT result = 0; |
19818 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 19819 | |
c19d1205 | 19820 | if (target_big_endian) |
b99bd4ef | 19821 | { |
c19d1205 ZW |
19822 | while (n--) |
19823 | { | |
19824 | result <<= 8; | |
19825 | result |= (*where++ & 255); | |
19826 | } | |
b99bd4ef | 19827 | } |
c19d1205 | 19828 | else |
b99bd4ef | 19829 | { |
c19d1205 ZW |
19830 | while (n--) |
19831 | { | |
19832 | result <<= 8; | |
19833 | result |= (where[n] & 255); | |
19834 | } | |
bfae80f2 | 19835 | } |
b99bd4ef | 19836 | |
c19d1205 | 19837 | return result; |
bfae80f2 | 19838 | } |
b99bd4ef | 19839 | |
c19d1205 | 19840 | /* MD interface: Sections. */ |
b99bd4ef | 19841 | |
fa94de6b RM |
19842 | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
19843 | that an rs_machine_dependent frag may reach. */ | |
19844 | ||
19845 | unsigned int | |
19846 | arm_frag_max_var (fragS *fragp) | |
19847 | { | |
19848 | /* We only use rs_machine_dependent for variable-size Thumb instructions, | |
19849 | which are either THUMB_SIZE (2) or INSN_SIZE (4). | |
19850 | ||
19851 | Note that we generate relaxable instructions even for cases that don't | |
19852 | really need it, like an immediate that's a trivial constant. So we're | |
19853 | overestimating the instruction size for some of those cases. Rather | |
19854 | than putting more intelligence here, it would probably be better to | |
19855 | avoid generating a relaxation frag in the first place when it can be | |
19856 | determined up front that a short instruction will suffice. */ | |
19857 | ||
19858 | gas_assert (fragp->fr_type == rs_machine_dependent); | |
19859 | return INSN_SIZE; | |
19860 | } | |
19861 | ||
0110f2b8 PB |
19862 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
19863 | 2 bytes. */ | |
19864 | ||
c19d1205 | 19865 | int |
0110f2b8 | 19866 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
19867 | segT segtype ATTRIBUTE_UNUSED) |
19868 | { | |
0110f2b8 PB |
19869 | fragp->fr_var = 2; |
19870 | return 2; | |
19871 | } | |
19872 | ||
19873 | /* Convert a machine dependent frag. */ | |
19874 | ||
19875 | void | |
19876 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
19877 | { | |
19878 | unsigned long insn; | |
19879 | unsigned long old_op; | |
19880 | char *buf; | |
19881 | expressionS exp; | |
19882 | fixS *fixp; | |
19883 | int reloc_type; | |
19884 | int pc_rel; | |
19885 | int opcode; | |
19886 | ||
19887 | buf = fragp->fr_literal + fragp->fr_fix; | |
19888 | ||
19889 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
19890 | if (fragp->fr_symbol) |
19891 | { | |
0110f2b8 PB |
19892 | exp.X_op = O_symbol; |
19893 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
19894 | } |
19895 | else | |
19896 | { | |
0110f2b8 | 19897 | exp.X_op = O_constant; |
5f4273c7 | 19898 | } |
0110f2b8 PB |
19899 | exp.X_add_number = fragp->fr_offset; |
19900 | opcode = fragp->fr_subtype; | |
19901 | switch (opcode) | |
19902 | { | |
19903 | case T_MNEM_ldr_pc: | |
19904 | case T_MNEM_ldr_pc2: | |
19905 | case T_MNEM_ldr_sp: | |
19906 | case T_MNEM_str_sp: | |
19907 | case T_MNEM_ldr: | |
19908 | case T_MNEM_ldrb: | |
19909 | case T_MNEM_ldrh: | |
19910 | case T_MNEM_str: | |
19911 | case T_MNEM_strb: | |
19912 | case T_MNEM_strh: | |
19913 | if (fragp->fr_var == 4) | |
19914 | { | |
5f4273c7 | 19915 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
19916 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
19917 | { | |
19918 | insn |= (old_op & 0x700) << 4; | |
19919 | } | |
19920 | else | |
19921 | { | |
19922 | insn |= (old_op & 7) << 12; | |
19923 | insn |= (old_op & 0x38) << 13; | |
19924 | } | |
19925 | insn |= 0x00000c00; | |
19926 | put_thumb32_insn (buf, insn); | |
19927 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
19928 | } | |
19929 | else | |
19930 | { | |
19931 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
19932 | } | |
19933 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
19934 | break; | |
19935 | case T_MNEM_adr: | |
19936 | if (fragp->fr_var == 4) | |
19937 | { | |
19938 | insn = THUMB_OP32 (opcode); | |
19939 | insn |= (old_op & 0xf0) << 4; | |
19940 | put_thumb32_insn (buf, insn); | |
19941 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
19942 | } | |
19943 | else | |
19944 | { | |
19945 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
19946 | exp.X_add_number -= 4; | |
19947 | } | |
19948 | pc_rel = 1; | |
19949 | break; | |
19950 | case T_MNEM_mov: | |
19951 | case T_MNEM_movs: | |
19952 | case T_MNEM_cmp: | |
19953 | case T_MNEM_cmn: | |
19954 | if (fragp->fr_var == 4) | |
19955 | { | |
19956 | int r0off = (opcode == T_MNEM_mov | |
19957 | || opcode == T_MNEM_movs) ? 0 : 8; | |
19958 | insn = THUMB_OP32 (opcode); | |
19959 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
19960 | insn |= (old_op & 0x700) << r0off; | |
19961 | put_thumb32_insn (buf, insn); | |
19962 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
19963 | } | |
19964 | else | |
19965 | { | |
19966 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
19967 | } | |
19968 | pc_rel = 0; | |
19969 | break; | |
19970 | case T_MNEM_b: | |
19971 | if (fragp->fr_var == 4) | |
19972 | { | |
19973 | insn = THUMB_OP32(opcode); | |
19974 | put_thumb32_insn (buf, insn); | |
19975 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
19976 | } | |
19977 | else | |
19978 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
19979 | pc_rel = 1; | |
19980 | break; | |
19981 | case T_MNEM_bcond: | |
19982 | if (fragp->fr_var == 4) | |
19983 | { | |
19984 | insn = THUMB_OP32(opcode); | |
19985 | insn |= (old_op & 0xf00) << 14; | |
19986 | put_thumb32_insn (buf, insn); | |
19987 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
19988 | } | |
19989 | else | |
19990 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
19991 | pc_rel = 1; | |
19992 | break; | |
19993 | case T_MNEM_add_sp: | |
19994 | case T_MNEM_add_pc: | |
19995 | case T_MNEM_inc_sp: | |
19996 | case T_MNEM_dec_sp: | |
19997 | if (fragp->fr_var == 4) | |
19998 | { | |
19999 | /* ??? Choose between add and addw. */ | |
20000 | insn = THUMB_OP32 (opcode); | |
20001 | insn |= (old_op & 0xf0) << 4; | |
20002 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
20003 | if (opcode == T_MNEM_add_pc) |
20004 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
20005 | else | |
20006 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
20007 | } |
20008 | else | |
20009 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
20010 | pc_rel = 0; | |
20011 | break; | |
20012 | ||
20013 | case T_MNEM_addi: | |
20014 | case T_MNEM_addis: | |
20015 | case T_MNEM_subi: | |
20016 | case T_MNEM_subis: | |
20017 | if (fragp->fr_var == 4) | |
20018 | { | |
20019 | insn = THUMB_OP32 (opcode); | |
20020 | insn |= (old_op & 0xf0) << 4; | |
20021 | insn |= (old_op & 0xf) << 16; | |
20022 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
20023 | if (insn & (1 << 20)) |
20024 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
20025 | else | |
20026 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
20027 | } |
20028 | else | |
20029 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
20030 | pc_rel = 0; | |
20031 | break; | |
20032 | default: | |
5f4273c7 | 20033 | abort (); |
0110f2b8 PB |
20034 | } |
20035 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 20036 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
20037 | fixp->fx_file = fragp->fr_file; |
20038 | fixp->fx_line = fragp->fr_line; | |
20039 | fragp->fr_fix += fragp->fr_var; | |
20040 | } | |
20041 | ||
20042 | /* Return the size of a relaxable immediate operand instruction. | |
20043 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
20044 | static int | |
20045 | relax_immediate (fragS *fragp, int size, int shift) | |
20046 | { | |
20047 | offsetT offset; | |
20048 | offsetT mask; | |
20049 | offsetT low; | |
20050 | ||
20051 | /* ??? Should be able to do better than this. */ | |
20052 | if (fragp->fr_symbol) | |
20053 | return 4; | |
20054 | ||
20055 | low = (1 << shift) - 1; | |
20056 | mask = (1 << (shift + size)) - (1 << shift); | |
20057 | offset = fragp->fr_offset; | |
20058 | /* Force misaligned offsets to 32-bit variant. */ | |
20059 | if (offset & low) | |
5e77afaa | 20060 | return 4; |
0110f2b8 PB |
20061 | if (offset & ~mask) |
20062 | return 4; | |
20063 | return 2; | |
20064 | } | |
20065 | ||
5e77afaa PB |
20066 | /* Get the address of a symbol during relaxation. */ |
20067 | static addressT | |
5f4273c7 | 20068 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
20069 | { |
20070 | fragS *sym_frag; | |
20071 | addressT addr; | |
20072 | symbolS *sym; | |
20073 | ||
20074 | sym = fragp->fr_symbol; | |
20075 | sym_frag = symbol_get_frag (sym); | |
20076 | know (S_GET_SEGMENT (sym) != absolute_section | |
20077 | || sym_frag == &zero_address_frag); | |
20078 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
20079 | ||
20080 | /* If frag has yet to be reached on this pass, assume it will | |
20081 | move by STRETCH just as we did. If this is not so, it will | |
20082 | be because some frag between grows, and that will force | |
20083 | another pass. */ | |
20084 | ||
20085 | if (stretch != 0 | |
20086 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
20087 | { |
20088 | fragS *f; | |
20089 | ||
20090 | /* Adjust stretch for any alignment frag. Note that if have | |
20091 | been expanding the earlier code, the symbol may be | |
20092 | defined in what appears to be an earlier frag. FIXME: | |
20093 | This doesn't handle the fr_subtype field, which specifies | |
20094 | a maximum number of bytes to skip when doing an | |
20095 | alignment. */ | |
20096 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
20097 | { | |
20098 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
20099 | { | |
20100 | if (stretch < 0) | |
20101 | stretch = - ((- stretch) | |
20102 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
20103 | else | |
20104 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
20105 | if (stretch == 0) | |
20106 | break; | |
20107 | } | |
20108 | } | |
20109 | if (f != NULL) | |
20110 | addr += stretch; | |
20111 | } | |
5e77afaa PB |
20112 | |
20113 | return addr; | |
20114 | } | |
20115 | ||
0110f2b8 PB |
20116 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
20117 | load. */ | |
20118 | static int | |
5e77afaa | 20119 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
20120 | { |
20121 | addressT addr; | |
20122 | offsetT val; | |
20123 | ||
20124 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
20125 | if (fragp->fr_symbol == NULL |
20126 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
20127 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
20128 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
20129 | return 4; |
20130 | ||
5f4273c7 | 20131 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
20132 | addr = fragp->fr_address + fragp->fr_fix; |
20133 | addr = (addr + 4) & ~3; | |
5e77afaa | 20134 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 20135 | if (val & 3) |
5e77afaa | 20136 | return 4; |
0110f2b8 PB |
20137 | val -= addr; |
20138 | if (val < 0 || val > 1020) | |
20139 | return 4; | |
20140 | return 2; | |
20141 | } | |
20142 | ||
20143 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
20144 | static int | |
20145 | relax_addsub (fragS *fragp, asection *sec) | |
20146 | { | |
20147 | char *buf; | |
20148 | int op; | |
20149 | ||
20150 | buf = fragp->fr_literal + fragp->fr_fix; | |
20151 | op = bfd_get_16(sec->owner, buf); | |
20152 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
20153 | return relax_immediate (fragp, 8, 0); | |
20154 | else | |
20155 | return relax_immediate (fragp, 3, 0); | |
20156 | } | |
20157 | ||
20158 | ||
20159 | /* Return the size of a relaxable branch instruction. BITS is the | |
20160 | size of the offset field in the narrow instruction. */ | |
20161 | ||
20162 | static int | |
5e77afaa | 20163 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
20164 | { |
20165 | addressT addr; | |
20166 | offsetT val; | |
20167 | offsetT limit; | |
20168 | ||
20169 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 20170 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
20171 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
20172 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
20173 | return 4; |
20174 | ||
267bf995 RR |
20175 | #ifdef OBJ_ELF |
20176 | if (S_IS_DEFINED (fragp->fr_symbol) | |
20177 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
20178 | return 4; | |
0d9b4b55 NC |
20179 | |
20180 | /* PR 12532. Global symbols with default visibility might | |
20181 | be preempted, so do not relax relocations to them. */ | |
20182 | if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT) | |
20183 | && (! S_IS_LOCAL (fragp->fr_symbol))) | |
20184 | return 4; | |
267bf995 RR |
20185 | #endif |
20186 | ||
5f4273c7 | 20187 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
20188 | addr = fragp->fr_address + fragp->fr_fix + 4; |
20189 | val -= addr; | |
20190 | ||
20191 | /* Offset is a signed value *2 */ | |
20192 | limit = 1 << bits; | |
20193 | if (val >= limit || val < -limit) | |
20194 | return 4; | |
20195 | return 2; | |
20196 | } | |
20197 | ||
20198 | ||
20199 | /* Relax a machine dependent frag. This returns the amount by which | |
20200 | the current size of the frag should change. */ | |
20201 | ||
20202 | int | |
5e77afaa | 20203 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
20204 | { |
20205 | int oldsize; | |
20206 | int newsize; | |
20207 | ||
20208 | oldsize = fragp->fr_var; | |
20209 | switch (fragp->fr_subtype) | |
20210 | { | |
20211 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 20212 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
20213 | break; |
20214 | case T_MNEM_ldr_pc: | |
20215 | case T_MNEM_ldr_sp: | |
20216 | case T_MNEM_str_sp: | |
5f4273c7 | 20217 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
20218 | break; |
20219 | case T_MNEM_ldr: | |
20220 | case T_MNEM_str: | |
5f4273c7 | 20221 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
20222 | break; |
20223 | case T_MNEM_ldrh: | |
20224 | case T_MNEM_strh: | |
5f4273c7 | 20225 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
20226 | break; |
20227 | case T_MNEM_ldrb: | |
20228 | case T_MNEM_strb: | |
5f4273c7 | 20229 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
20230 | break; |
20231 | case T_MNEM_adr: | |
5f4273c7 | 20232 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
20233 | break; |
20234 | case T_MNEM_mov: | |
20235 | case T_MNEM_movs: | |
20236 | case T_MNEM_cmp: | |
20237 | case T_MNEM_cmn: | |
5f4273c7 | 20238 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
20239 | break; |
20240 | case T_MNEM_b: | |
5f4273c7 | 20241 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
20242 | break; |
20243 | case T_MNEM_bcond: | |
5f4273c7 | 20244 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
20245 | break; |
20246 | case T_MNEM_add_sp: | |
20247 | case T_MNEM_add_pc: | |
20248 | newsize = relax_immediate (fragp, 8, 2); | |
20249 | break; | |
20250 | case T_MNEM_inc_sp: | |
20251 | case T_MNEM_dec_sp: | |
20252 | newsize = relax_immediate (fragp, 7, 2); | |
20253 | break; | |
20254 | case T_MNEM_addi: | |
20255 | case T_MNEM_addis: | |
20256 | case T_MNEM_subi: | |
20257 | case T_MNEM_subis: | |
20258 | newsize = relax_addsub (fragp, sec); | |
20259 | break; | |
20260 | default: | |
5f4273c7 | 20261 | abort (); |
0110f2b8 | 20262 | } |
5e77afaa PB |
20263 | |
20264 | fragp->fr_var = newsize; | |
20265 | /* Freeze wide instructions that are at or before the same location as | |
20266 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
20267 | Don't freeze them unconditionally because targets may be artificially |
20268 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 20269 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 20270 | { |
0110f2b8 | 20271 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 20272 | frag_wane (fragp); |
0110f2b8 | 20273 | } |
5e77afaa | 20274 | |
0110f2b8 | 20275 | return newsize - oldsize; |
c19d1205 | 20276 | } |
b99bd4ef | 20277 | |
c19d1205 | 20278 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 20279 | |
c19d1205 ZW |
20280 | valueT |
20281 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
20282 | valueT size) | |
20283 | { | |
f0927246 NC |
20284 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
20285 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
20286 | { | |
20287 | /* For a.out, force the section size to be aligned. If we don't do | |
20288 | this, BFD will align it for us, but it will not write out the | |
20289 | final bytes of the section. This may be a bug in BFD, but it is | |
20290 | easier to fix it here since that is how the other a.out targets | |
20291 | work. */ | |
20292 | int align; | |
20293 | ||
20294 | align = bfd_get_section_alignment (stdoutput, segment); | |
20295 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
20296 | } | |
c19d1205 | 20297 | #endif |
f0927246 NC |
20298 | |
20299 | return size; | |
bfae80f2 | 20300 | } |
b99bd4ef | 20301 | |
c19d1205 ZW |
20302 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
20303 | of an rs_align_code fragment. */ | |
20304 | ||
20305 | void | |
20306 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 20307 | { |
e7495e45 NS |
20308 | static char const arm_noop[2][2][4] = |
20309 | { | |
20310 | { /* ARMv1 */ | |
20311 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
20312 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
20313 | }, | |
20314 | { /* ARMv6k */ | |
20315 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
20316 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
20317 | }, | |
20318 | }; | |
20319 | static char const thumb_noop[2][2][2] = | |
20320 | { | |
20321 | { /* Thumb-1 */ | |
20322 | {0xc0, 0x46}, /* LE */ | |
20323 | {0x46, 0xc0}, /* BE */ | |
20324 | }, | |
20325 | { /* Thumb-2 */ | |
20326 | {0x00, 0xbf}, /* LE */ | |
20327 | {0xbf, 0x00} /* BE */ | |
20328 | } | |
20329 | }; | |
20330 | static char const wide_thumb_noop[2][4] = | |
20331 | { /* Wide Thumb-2 */ | |
20332 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
20333 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
20334 | }; | |
c921be7d | 20335 | |
e7495e45 | 20336 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
20337 | char * p; |
20338 | const char * noop; | |
e7495e45 | 20339 | const char *narrow_noop = NULL; |
cd000bff DJ |
20340 | #ifdef OBJ_ELF |
20341 | enum mstate state; | |
20342 | #endif | |
bfae80f2 | 20343 | |
c19d1205 | 20344 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
20345 | return; |
20346 | ||
c19d1205 ZW |
20347 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
20348 | p = fragP->fr_literal + fragP->fr_fix; | |
20349 | fix = 0; | |
bfae80f2 | 20350 | |
c19d1205 ZW |
20351 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
20352 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 20353 | |
cd000bff | 20354 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 20355 | |
cd000bff | 20356 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 20357 | { |
e7495e45 NS |
20358 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
20359 | { | |
20360 | narrow_noop = thumb_noop[1][target_big_endian]; | |
20361 | noop = wide_thumb_noop[target_big_endian]; | |
20362 | } | |
c19d1205 | 20363 | else |
e7495e45 NS |
20364 | noop = thumb_noop[0][target_big_endian]; |
20365 | noop_size = 2; | |
cd000bff DJ |
20366 | #ifdef OBJ_ELF |
20367 | state = MAP_THUMB; | |
20368 | #endif | |
7ed4c4c5 NC |
20369 | } |
20370 | else | |
20371 | { | |
e7495e45 NS |
20372 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0] |
20373 | [target_big_endian]; | |
20374 | noop_size = 4; | |
cd000bff DJ |
20375 | #ifdef OBJ_ELF |
20376 | state = MAP_ARM; | |
20377 | #endif | |
7ed4c4c5 | 20378 | } |
c921be7d | 20379 | |
e7495e45 | 20380 | fragP->fr_var = noop_size; |
c921be7d | 20381 | |
c19d1205 | 20382 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 20383 | { |
c19d1205 | 20384 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
20385 | #ifdef OBJ_ELF |
20386 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
20387 | #endif | |
c19d1205 ZW |
20388 | memset (p, 0, fix); |
20389 | p += fix; | |
20390 | bytes -= fix; | |
a737bd4d | 20391 | } |
a737bd4d | 20392 | |
e7495e45 NS |
20393 | if (narrow_noop) |
20394 | { | |
20395 | if (bytes & noop_size) | |
20396 | { | |
20397 | /* Insert a narrow noop. */ | |
20398 | memcpy (p, narrow_noop, noop_size); | |
20399 | p += noop_size; | |
20400 | bytes -= noop_size; | |
20401 | fix += noop_size; | |
20402 | } | |
20403 | ||
20404 | /* Use wide noops for the remainder */ | |
20405 | noop_size = 4; | |
20406 | } | |
20407 | ||
c19d1205 | 20408 | while (bytes >= noop_size) |
a737bd4d | 20409 | { |
c19d1205 ZW |
20410 | memcpy (p, noop, noop_size); |
20411 | p += noop_size; | |
20412 | bytes -= noop_size; | |
20413 | fix += noop_size; | |
a737bd4d NC |
20414 | } |
20415 | ||
c19d1205 | 20416 | fragP->fr_fix += fix; |
a737bd4d NC |
20417 | } |
20418 | ||
c19d1205 ZW |
20419 | /* Called from md_do_align. Used to create an alignment |
20420 | frag in a code section. */ | |
20421 | ||
20422 | void | |
20423 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 20424 | { |
c19d1205 | 20425 | char * p; |
7ed4c4c5 | 20426 | |
c19d1205 | 20427 | /* We assume that there will never be a requirement |
6ec8e702 | 20428 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 20429 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
20430 | { |
20431 | char err_msg[128]; | |
20432 | ||
fa94de6b | 20433 | sprintf (err_msg, |
6ec8e702 NC |
20434 | _("alignments greater than %d bytes not supported in .text sections."), |
20435 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 20436 | as_fatal ("%s", err_msg); |
6ec8e702 | 20437 | } |
bfae80f2 | 20438 | |
c19d1205 ZW |
20439 | p = frag_var (rs_align_code, |
20440 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
20441 | 1, | |
20442 | (relax_substateT) max, | |
20443 | (symbolS *) NULL, | |
20444 | (offsetT) n, | |
20445 | (char *) NULL); | |
20446 | *p = 0; | |
20447 | } | |
bfae80f2 | 20448 | |
8dc2430f NC |
20449 | /* Perform target specific initialisation of a frag. |
20450 | Note - despite the name this initialisation is not done when the frag | |
20451 | is created, but only when its type is assigned. A frag can be created | |
20452 | and used a long time before its type is set, so beware of assuming that | |
20453 | this initialisationis performed first. */ | |
bfae80f2 | 20454 | |
cd000bff DJ |
20455 | #ifndef OBJ_ELF |
20456 | void | |
20457 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
20458 | { | |
20459 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 20460 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
20461 | } |
20462 | ||
20463 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 20464 | void |
cd000bff | 20465 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 20466 | { |
8dc2430f NC |
20467 | /* If the current ARM vs THUMB mode has not already |
20468 | been recorded into this frag then do so now. */ | |
cd000bff DJ |
20469 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
20470 | { | |
20471 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; | |
20472 | ||
20473 | /* Record a mapping symbol for alignment frags. We will delete this | |
20474 | later if the alignment ends up empty. */ | |
20475 | switch (fragP->fr_type) | |
20476 | { | |
20477 | case rs_align: | |
20478 | case rs_align_test: | |
20479 | case rs_fill: | |
20480 | mapping_state_2 (MAP_DATA, max_chars); | |
20481 | break; | |
20482 | case rs_align_code: | |
20483 | mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); | |
20484 | break; | |
20485 | default: | |
20486 | break; | |
20487 | } | |
20488 | } | |
bfae80f2 RE |
20489 | } |
20490 | ||
c19d1205 ZW |
20491 | /* When we change sections we need to issue a new mapping symbol. */ |
20492 | ||
20493 | void | |
20494 | arm_elf_change_section (void) | |
bfae80f2 | 20495 | { |
c19d1205 ZW |
20496 | /* Link an unlinked unwind index table section to the .text section. */ |
20497 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
20498 | && elf_linked_to_section (now_seg) == NULL) | |
20499 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
20500 | } |
20501 | ||
c19d1205 ZW |
20502 | int |
20503 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 20504 | { |
c19d1205 ZW |
20505 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
20506 | return SHT_ARM_EXIDX; | |
e45d0630 | 20507 | |
c19d1205 ZW |
20508 | return -1; |
20509 | } | |
20510 | \f | |
20511 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 20512 | |
c19d1205 | 20513 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 20514 | |
5f4273c7 | 20515 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 20516 | |
bfae80f2 | 20517 | static void |
c19d1205 | 20518 | flush_pending_unwind (void) |
bfae80f2 | 20519 | { |
c19d1205 | 20520 | offsetT offset; |
bfae80f2 | 20521 | |
c19d1205 ZW |
20522 | offset = unwind.pending_offset; |
20523 | unwind.pending_offset = 0; | |
20524 | if (offset != 0) | |
20525 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
20526 | } |
20527 | ||
c19d1205 ZW |
20528 | /* Add an opcode to this list for this function. Two-byte opcodes should |
20529 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
20530 | order. */ | |
20531 | ||
bfae80f2 | 20532 | static void |
c19d1205 | 20533 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 20534 | { |
c19d1205 ZW |
20535 | /* Add any deferred stack adjustment. */ |
20536 | if (unwind.pending_offset) | |
20537 | flush_pending_unwind (); | |
bfae80f2 | 20538 | |
c19d1205 | 20539 | unwind.sp_restored = 0; |
bfae80f2 | 20540 | |
c19d1205 | 20541 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 20542 | { |
c19d1205 ZW |
20543 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
20544 | if (unwind.opcodes) | |
21d799b5 NC |
20545 | unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes, |
20546 | unwind.opcode_alloc); | |
c19d1205 | 20547 | else |
21d799b5 | 20548 | unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc); |
bfae80f2 | 20549 | } |
c19d1205 | 20550 | while (length > 0) |
bfae80f2 | 20551 | { |
c19d1205 ZW |
20552 | length--; |
20553 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
20554 | op >>= 8; | |
20555 | unwind.opcode_count++; | |
bfae80f2 | 20556 | } |
bfae80f2 RE |
20557 | } |
20558 | ||
c19d1205 ZW |
20559 | /* Add unwind opcodes to adjust the stack pointer. */ |
20560 | ||
bfae80f2 | 20561 | static void |
c19d1205 | 20562 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 20563 | { |
c19d1205 | 20564 | valueT op; |
bfae80f2 | 20565 | |
c19d1205 | 20566 | if (offset > 0x200) |
bfae80f2 | 20567 | { |
c19d1205 ZW |
20568 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
20569 | char bytes[5]; | |
20570 | int n; | |
20571 | valueT o; | |
bfae80f2 | 20572 | |
c19d1205 ZW |
20573 | /* Long form: 0xb2, uleb128. */ |
20574 | /* This might not fit in a word so add the individual bytes, | |
20575 | remembering the list is built in reverse order. */ | |
20576 | o = (valueT) ((offset - 0x204) >> 2); | |
20577 | if (o == 0) | |
20578 | add_unwind_opcode (0, 1); | |
bfae80f2 | 20579 | |
c19d1205 ZW |
20580 | /* Calculate the uleb128 encoding of the offset. */ |
20581 | n = 0; | |
20582 | while (o) | |
20583 | { | |
20584 | bytes[n] = o & 0x7f; | |
20585 | o >>= 7; | |
20586 | if (o) | |
20587 | bytes[n] |= 0x80; | |
20588 | n++; | |
20589 | } | |
20590 | /* Add the insn. */ | |
20591 | for (; n; n--) | |
20592 | add_unwind_opcode (bytes[n - 1], 1); | |
20593 | add_unwind_opcode (0xb2, 1); | |
20594 | } | |
20595 | else if (offset > 0x100) | |
bfae80f2 | 20596 | { |
c19d1205 ZW |
20597 | /* Two short opcodes. */ |
20598 | add_unwind_opcode (0x3f, 1); | |
20599 | op = (offset - 0x104) >> 2; | |
20600 | add_unwind_opcode (op, 1); | |
bfae80f2 | 20601 | } |
c19d1205 ZW |
20602 | else if (offset > 0) |
20603 | { | |
20604 | /* Short opcode. */ | |
20605 | op = (offset - 4) >> 2; | |
20606 | add_unwind_opcode (op, 1); | |
20607 | } | |
20608 | else if (offset < 0) | |
bfae80f2 | 20609 | { |
c19d1205 ZW |
20610 | offset = -offset; |
20611 | while (offset > 0x100) | |
bfae80f2 | 20612 | { |
c19d1205 ZW |
20613 | add_unwind_opcode (0x7f, 1); |
20614 | offset -= 0x100; | |
bfae80f2 | 20615 | } |
c19d1205 ZW |
20616 | op = ((offset - 4) >> 2) | 0x40; |
20617 | add_unwind_opcode (op, 1); | |
bfae80f2 | 20618 | } |
bfae80f2 RE |
20619 | } |
20620 | ||
c19d1205 ZW |
20621 | /* Finish the list of unwind opcodes for this function. */ |
20622 | static void | |
20623 | finish_unwind_opcodes (void) | |
bfae80f2 | 20624 | { |
c19d1205 | 20625 | valueT op; |
bfae80f2 | 20626 | |
c19d1205 | 20627 | if (unwind.fp_used) |
bfae80f2 | 20628 | { |
708587a4 | 20629 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
20630 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
20631 | flush_pending_unwind (); | |
bfae80f2 | 20632 | |
c19d1205 ZW |
20633 | /* After restoring sp from the frame pointer. */ |
20634 | op = 0x90 | unwind.fp_reg; | |
20635 | add_unwind_opcode (op, 1); | |
20636 | } | |
20637 | else | |
20638 | flush_pending_unwind (); | |
bfae80f2 RE |
20639 | } |
20640 | ||
bfae80f2 | 20641 | |
c19d1205 ZW |
20642 | /* Start an exception table entry. If idx is nonzero this is an index table |
20643 | entry. */ | |
bfae80f2 RE |
20644 | |
20645 | static void | |
c19d1205 | 20646 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 20647 | { |
c19d1205 ZW |
20648 | const char * text_name; |
20649 | const char * prefix; | |
20650 | const char * prefix_once; | |
20651 | const char * group_name; | |
20652 | size_t prefix_len; | |
20653 | size_t text_len; | |
20654 | char * sec_name; | |
20655 | size_t sec_name_len; | |
20656 | int type; | |
20657 | int flags; | |
20658 | int linkonce; | |
bfae80f2 | 20659 | |
c19d1205 | 20660 | if (idx) |
bfae80f2 | 20661 | { |
c19d1205 ZW |
20662 | prefix = ELF_STRING_ARM_unwind; |
20663 | prefix_once = ELF_STRING_ARM_unwind_once; | |
20664 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 20665 | } |
c19d1205 | 20666 | else |
bfae80f2 | 20667 | { |
c19d1205 ZW |
20668 | prefix = ELF_STRING_ARM_unwind_info; |
20669 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
20670 | type = SHT_PROGBITS; | |
bfae80f2 RE |
20671 | } |
20672 | ||
c19d1205 ZW |
20673 | text_name = segment_name (text_seg); |
20674 | if (streq (text_name, ".text")) | |
20675 | text_name = ""; | |
20676 | ||
20677 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
20678 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 20679 | { |
c19d1205 ZW |
20680 | prefix = prefix_once; |
20681 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
20682 | } |
20683 | ||
c19d1205 ZW |
20684 | prefix_len = strlen (prefix); |
20685 | text_len = strlen (text_name); | |
20686 | sec_name_len = prefix_len + text_len; | |
21d799b5 | 20687 | sec_name = (char *) xmalloc (sec_name_len + 1); |
c19d1205 ZW |
20688 | memcpy (sec_name, prefix, prefix_len); |
20689 | memcpy (sec_name + prefix_len, text_name, text_len); | |
20690 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 20691 | |
c19d1205 ZW |
20692 | flags = SHF_ALLOC; |
20693 | linkonce = 0; | |
20694 | group_name = 0; | |
bfae80f2 | 20695 | |
c19d1205 ZW |
20696 | /* Handle COMDAT group. */ |
20697 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 20698 | { |
c19d1205 ZW |
20699 | group_name = elf_group_name (text_seg); |
20700 | if (group_name == NULL) | |
20701 | { | |
bd3ba5d1 | 20702 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
20703 | segment_name (text_seg)); |
20704 | ignore_rest_of_line (); | |
20705 | return; | |
20706 | } | |
20707 | flags |= SHF_GROUP; | |
20708 | linkonce = 1; | |
bfae80f2 RE |
20709 | } |
20710 | ||
c19d1205 | 20711 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 20712 | |
5f4273c7 | 20713 | /* Set the section link for index tables. */ |
c19d1205 ZW |
20714 | if (idx) |
20715 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
20716 | } |
20717 | ||
bfae80f2 | 20718 | |
c19d1205 ZW |
20719 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
20720 | personality routine data. Returns zero, or the index table value for | |
20721 | and inline entry. */ | |
20722 | ||
20723 | static valueT | |
20724 | create_unwind_entry (int have_data) | |
bfae80f2 | 20725 | { |
c19d1205 ZW |
20726 | int size; |
20727 | addressT where; | |
20728 | char *ptr; | |
20729 | /* The current word of data. */ | |
20730 | valueT data; | |
20731 | /* The number of bytes left in this word. */ | |
20732 | int n; | |
bfae80f2 | 20733 | |
c19d1205 | 20734 | finish_unwind_opcodes (); |
bfae80f2 | 20735 | |
c19d1205 ZW |
20736 | /* Remember the current text section. */ |
20737 | unwind.saved_seg = now_seg; | |
20738 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 20739 | |
c19d1205 | 20740 | start_unwind_section (now_seg, 0); |
bfae80f2 | 20741 | |
c19d1205 | 20742 | if (unwind.personality_routine == NULL) |
bfae80f2 | 20743 | { |
c19d1205 ZW |
20744 | if (unwind.personality_index == -2) |
20745 | { | |
20746 | if (have_data) | |
5f4273c7 | 20747 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
20748 | return 1; /* EXIDX_CANTUNWIND. */ |
20749 | } | |
bfae80f2 | 20750 | |
c19d1205 ZW |
20751 | /* Use a default personality routine if none is specified. */ |
20752 | if (unwind.personality_index == -1) | |
20753 | { | |
20754 | if (unwind.opcode_count > 3) | |
20755 | unwind.personality_index = 1; | |
20756 | else | |
20757 | unwind.personality_index = 0; | |
20758 | } | |
bfae80f2 | 20759 | |
c19d1205 ZW |
20760 | /* Space for the personality routine entry. */ |
20761 | if (unwind.personality_index == 0) | |
20762 | { | |
20763 | if (unwind.opcode_count > 3) | |
20764 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 20765 | |
c19d1205 ZW |
20766 | if (!have_data) |
20767 | { | |
20768 | /* All the data is inline in the index table. */ | |
20769 | data = 0x80; | |
20770 | n = 3; | |
20771 | while (unwind.opcode_count > 0) | |
20772 | { | |
20773 | unwind.opcode_count--; | |
20774 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
20775 | n--; | |
20776 | } | |
bfae80f2 | 20777 | |
c19d1205 ZW |
20778 | /* Pad with "finish" opcodes. */ |
20779 | while (n--) | |
20780 | data = (data << 8) | 0xb0; | |
bfae80f2 | 20781 | |
c19d1205 ZW |
20782 | return data; |
20783 | } | |
20784 | size = 0; | |
20785 | } | |
20786 | else | |
20787 | /* We get two opcodes "free" in the first word. */ | |
20788 | size = unwind.opcode_count - 2; | |
20789 | } | |
20790 | else | |
5011093d NC |
20791 | { |
20792 | gas_assert (unwind.personality_index == -1); | |
20793 | ||
20794 | /* An extra byte is required for the opcode count. */ | |
20795 | size = unwind.opcode_count + 1; | |
20796 | } | |
bfae80f2 | 20797 | |
c19d1205 ZW |
20798 | size = (size + 3) >> 2; |
20799 | if (size > 0xff) | |
20800 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 20801 | |
c19d1205 ZW |
20802 | frag_align (2, 0, 0); |
20803 | record_alignment (now_seg, 2); | |
20804 | unwind.table_entry = expr_build_dot (); | |
20805 | ||
20806 | /* Allocate the table entry. */ | |
20807 | ptr = frag_more ((size << 2) + 4); | |
74929e7b NC |
20808 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
20809 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 20810 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 20811 | |
c19d1205 | 20812 | switch (unwind.personality_index) |
bfae80f2 | 20813 | { |
c19d1205 ZW |
20814 | case -1: |
20815 | /* ??? Should this be a PLT generating relocation? */ | |
20816 | /* Custom personality routine. */ | |
20817 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
20818 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 20819 | |
c19d1205 ZW |
20820 | where += 4; |
20821 | ptr += 4; | |
bfae80f2 | 20822 | |
c19d1205 | 20823 | /* Set the first byte to the number of additional words. */ |
5011093d | 20824 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
20825 | n = 3; |
20826 | break; | |
bfae80f2 | 20827 | |
c19d1205 ZW |
20828 | /* ABI defined personality routines. */ |
20829 | case 0: | |
20830 | /* Three opcodes bytes are packed into the first word. */ | |
20831 | data = 0x80; | |
20832 | n = 3; | |
20833 | break; | |
bfae80f2 | 20834 | |
c19d1205 ZW |
20835 | case 1: |
20836 | case 2: | |
20837 | /* The size and first two opcode bytes go in the first word. */ | |
20838 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
20839 | n = 2; | |
20840 | break; | |
bfae80f2 | 20841 | |
c19d1205 ZW |
20842 | default: |
20843 | /* Should never happen. */ | |
20844 | abort (); | |
20845 | } | |
bfae80f2 | 20846 | |
c19d1205 ZW |
20847 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
20848 | time. */ | |
20849 | while (unwind.opcode_count > 0) | |
20850 | { | |
20851 | if (n == 0) | |
20852 | { | |
20853 | md_number_to_chars (ptr, data, 4); | |
20854 | ptr += 4; | |
20855 | n = 4; | |
20856 | data = 0; | |
20857 | } | |
20858 | unwind.opcode_count--; | |
20859 | n--; | |
20860 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
20861 | } | |
20862 | ||
20863 | /* Finish off the last word. */ | |
20864 | if (n < 4) | |
20865 | { | |
20866 | /* Pad with "finish" opcodes. */ | |
20867 | while (n--) | |
20868 | data = (data << 8) | 0xb0; | |
20869 | ||
20870 | md_number_to_chars (ptr, data, 4); | |
20871 | } | |
20872 | ||
20873 | if (!have_data) | |
20874 | { | |
20875 | /* Add an empty descriptor if there is no user-specified data. */ | |
20876 | ptr = frag_more (4); | |
20877 | md_number_to_chars (ptr, 0, 4); | |
20878 | } | |
20879 | ||
20880 | return 0; | |
bfae80f2 RE |
20881 | } |
20882 | ||
f0927246 NC |
20883 | |
20884 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
20885 | ||
20886 | void | |
20887 | tc_arm_frame_initial_instructions (void) | |
20888 | { | |
20889 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
20890 | } | |
20891 | #endif /* OBJ_ELF */ | |
20892 | ||
c19d1205 ZW |
20893 | /* Convert REGNAME to a DWARF-2 register number. */ |
20894 | ||
20895 | int | |
1df69f4f | 20896 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 20897 | { |
1df69f4f | 20898 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
20899 | |
20900 | if (reg == FAIL) | |
20901 | return -1; | |
20902 | ||
20903 | return reg; | |
bfae80f2 RE |
20904 | } |
20905 | ||
f0927246 | 20906 | #ifdef TE_PE |
c19d1205 | 20907 | void |
f0927246 | 20908 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 20909 | { |
91d6fa6a | 20910 | expressionS exp; |
bfae80f2 | 20911 | |
91d6fa6a NC |
20912 | exp.X_op = O_secrel; |
20913 | exp.X_add_symbol = symbol; | |
20914 | exp.X_add_number = 0; | |
20915 | emit_expr (&exp, size); | |
f0927246 NC |
20916 | } |
20917 | #endif | |
bfae80f2 | 20918 | |
c19d1205 | 20919 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 20920 | |
2fc8bdac ZW |
20921 | /* Return the address within the segment that a PC-relative fixup is |
20922 | relative to. For ARM, PC-relative fixups applied to instructions | |
20923 | are generally relative to the location of the fixup plus 8 bytes. | |
20924 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
20925 | require special handling. */ | |
bfae80f2 | 20926 | |
c19d1205 | 20927 | long |
2fc8bdac | 20928 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 20929 | { |
2fc8bdac ZW |
20930 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
20931 | ||
20932 | /* If this is pc-relative and we are going to emit a relocation | |
20933 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
20934 | will need. Otherwise we want to use the calculated base. |
20935 | For WinCE we skip the bias for externals as well, since this | |
20936 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 20937 | if (fixP->fx_pcrel |
2fc8bdac | 20938 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
20939 | || (arm_force_relocation (fixP) |
20940 | #ifdef TE_WINCE | |
20941 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20942 | #endif | |
20943 | ))) | |
2fc8bdac | 20944 | base = 0; |
bfae80f2 | 20945 | |
267bf995 | 20946 | |
c19d1205 | 20947 | switch (fixP->fx_r_type) |
bfae80f2 | 20948 | { |
2fc8bdac ZW |
20949 | /* PC relative addressing on the Thumb is slightly odd as the |
20950 | bottom two bits of the PC are forced to zero for the | |
20951 | calculation. This happens *after* application of the | |
20952 | pipeline offset. However, Thumb adrl already adjusts for | |
20953 | this, so we need not do it again. */ | |
c19d1205 | 20954 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 20955 | return base & ~3; |
c19d1205 ZW |
20956 | |
20957 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
20958 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 20959 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 20960 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 20961 | return (base + 4) & ~3; |
c19d1205 | 20962 | |
2fc8bdac ZW |
20963 | /* Thumb branches are simply offset by +4. */ |
20964 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
20965 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
20966 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
20967 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 20968 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 20969 | return base + 4; |
bfae80f2 | 20970 | |
267bf995 | 20971 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
20972 | if (fixP->fx_addsy |
20973 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 20974 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
20975 | && ARM_IS_FUNC (fixP->fx_addsy) |
20976 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20977 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
20978 | return base + 4; | |
20979 | ||
00adf2d4 JB |
20980 | /* BLX is like branches above, but forces the low two bits of PC to |
20981 | zero. */ | |
486499d0 CL |
20982 | case BFD_RELOC_THUMB_PCREL_BLX: |
20983 | if (fixP->fx_addsy | |
20984 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 20985 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
20986 | && THUMB_IS_FUNC (fixP->fx_addsy) |
20987 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20988 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
20989 | return (base + 4) & ~3; |
20990 | ||
2fc8bdac ZW |
20991 | /* ARM mode branches are offset by +8. However, the Windows CE |
20992 | loader expects the relocation not to take this into account. */ | |
267bf995 | 20993 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
20994 | if (fixP->fx_addsy |
20995 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 20996 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
20997 | && ARM_IS_FUNC (fixP->fx_addsy) |
20998 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20999 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 21000 | return base + 8; |
267bf995 | 21001 | |
486499d0 CL |
21002 | case BFD_RELOC_ARM_PCREL_CALL: |
21003 | if (fixP->fx_addsy | |
21004 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 21005 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
21006 | && THUMB_IS_FUNC (fixP->fx_addsy) |
21007 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
21008 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 21009 | return base + 8; |
267bf995 | 21010 | |
2fc8bdac | 21011 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 21012 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 21013 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 21014 | #ifdef TE_WINCE |
5f4273c7 | 21015 | /* When handling fixups immediately, because we have already |
53baae48 NC |
21016 | discovered the value of a symbol, or the address of the frag involved |
21017 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
21018 | see fixup_segment() in write.c | |
21019 | The S_IS_EXTERNAL test handles the case of global symbols. | |
21020 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
21021 | if (fixP->fx_pcrel | |
21022 | && fixP->fx_addsy != NULL | |
21023 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
21024 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
21025 | return base + 8; | |
2fc8bdac | 21026 | return base; |
c19d1205 | 21027 | #else |
2fc8bdac | 21028 | return base + 8; |
c19d1205 | 21029 | #endif |
2fc8bdac | 21030 | |
267bf995 | 21031 | |
2fc8bdac ZW |
21032 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
21033 | branches, the Windows CE loader *does* expect the relocation | |
21034 | to take this into account. */ | |
21035 | case BFD_RELOC_ARM_OFFSET_IMM: | |
21036 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
21037 | case BFD_RELOC_ARM_HWLITERAL: | |
21038 | case BFD_RELOC_ARM_LITERAL: | |
21039 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
21040 | return base + 8; | |
21041 | ||
21042 | ||
21043 | /* Other PC-relative relocations are un-offset. */ | |
21044 | default: | |
21045 | return base; | |
21046 | } | |
bfae80f2 RE |
21047 | } |
21048 | ||
c19d1205 ZW |
21049 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
21050 | Otherwise we have no need to default values of symbols. */ | |
21051 | ||
21052 | symbolS * | |
21053 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 21054 | { |
c19d1205 ZW |
21055 | #ifdef OBJ_ELF |
21056 | if (name[0] == '_' && name[1] == 'G' | |
21057 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
21058 | { | |
21059 | if (!GOT_symbol) | |
21060 | { | |
21061 | if (symbol_find (name)) | |
bd3ba5d1 | 21062 | as_bad (_("GOT already in the symbol table")); |
bfae80f2 | 21063 | |
c19d1205 ZW |
21064 | GOT_symbol = symbol_new (name, undefined_section, |
21065 | (valueT) 0, & zero_address_frag); | |
21066 | } | |
bfae80f2 | 21067 | |
c19d1205 | 21068 | return GOT_symbol; |
bfae80f2 | 21069 | } |
c19d1205 | 21070 | #endif |
bfae80f2 | 21071 | |
c921be7d | 21072 | return NULL; |
bfae80f2 RE |
21073 | } |
21074 | ||
55cf6793 | 21075 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
21076 | computed as two separate immediate values, added together. We |
21077 | already know that this value cannot be computed by just one ARM | |
21078 | instruction. */ | |
21079 | ||
21080 | static unsigned int | |
21081 | validate_immediate_twopart (unsigned int val, | |
21082 | unsigned int * highpart) | |
bfae80f2 | 21083 | { |
c19d1205 ZW |
21084 | unsigned int a; |
21085 | unsigned int i; | |
bfae80f2 | 21086 | |
c19d1205 ZW |
21087 | for (i = 0; i < 32; i += 2) |
21088 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
21089 | { | |
21090 | if (a & 0xff00) | |
21091 | { | |
21092 | if (a & ~ 0xffff) | |
21093 | continue; | |
21094 | * highpart = (a >> 8) | ((i + 24) << 7); | |
21095 | } | |
21096 | else if (a & 0xff0000) | |
21097 | { | |
21098 | if (a & 0xff000000) | |
21099 | continue; | |
21100 | * highpart = (a >> 16) | ((i + 16) << 7); | |
21101 | } | |
21102 | else | |
21103 | { | |
9c2799c2 | 21104 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
21105 | * highpart = (a >> 24) | ((i + 8) << 7); |
21106 | } | |
bfae80f2 | 21107 | |
c19d1205 ZW |
21108 | return (a & 0xff) | (i << 7); |
21109 | } | |
bfae80f2 | 21110 | |
c19d1205 | 21111 | return FAIL; |
bfae80f2 RE |
21112 | } |
21113 | ||
c19d1205 ZW |
21114 | static int |
21115 | validate_offset_imm (unsigned int val, int hwse) | |
21116 | { | |
21117 | if ((hwse && val > 255) || val > 4095) | |
21118 | return FAIL; | |
21119 | return val; | |
21120 | } | |
bfae80f2 | 21121 | |
55cf6793 | 21122 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
21123 | negative immediate constant by altering the instruction. A bit of |
21124 | a hack really. | |
21125 | MOV <-> MVN | |
21126 | AND <-> BIC | |
21127 | ADC <-> SBC | |
21128 | by inverting the second operand, and | |
21129 | ADD <-> SUB | |
21130 | CMP <-> CMN | |
21131 | by negating the second operand. */ | |
bfae80f2 | 21132 | |
c19d1205 ZW |
21133 | static int |
21134 | negate_data_op (unsigned long * instruction, | |
21135 | unsigned long value) | |
bfae80f2 | 21136 | { |
c19d1205 ZW |
21137 | int op, new_inst; |
21138 | unsigned long negated, inverted; | |
bfae80f2 | 21139 | |
c19d1205 ZW |
21140 | negated = encode_arm_immediate (-value); |
21141 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 21142 | |
c19d1205 ZW |
21143 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
21144 | switch (op) | |
bfae80f2 | 21145 | { |
c19d1205 ZW |
21146 | /* First negates. */ |
21147 | case OPCODE_SUB: /* ADD <-> SUB */ | |
21148 | new_inst = OPCODE_ADD; | |
21149 | value = negated; | |
21150 | break; | |
bfae80f2 | 21151 | |
c19d1205 ZW |
21152 | case OPCODE_ADD: |
21153 | new_inst = OPCODE_SUB; | |
21154 | value = negated; | |
21155 | break; | |
bfae80f2 | 21156 | |
c19d1205 ZW |
21157 | case OPCODE_CMP: /* CMP <-> CMN */ |
21158 | new_inst = OPCODE_CMN; | |
21159 | value = negated; | |
21160 | break; | |
bfae80f2 | 21161 | |
c19d1205 ZW |
21162 | case OPCODE_CMN: |
21163 | new_inst = OPCODE_CMP; | |
21164 | value = negated; | |
21165 | break; | |
bfae80f2 | 21166 | |
c19d1205 ZW |
21167 | /* Now Inverted ops. */ |
21168 | case OPCODE_MOV: /* MOV <-> MVN */ | |
21169 | new_inst = OPCODE_MVN; | |
21170 | value = inverted; | |
21171 | break; | |
bfae80f2 | 21172 | |
c19d1205 ZW |
21173 | case OPCODE_MVN: |
21174 | new_inst = OPCODE_MOV; | |
21175 | value = inverted; | |
21176 | break; | |
bfae80f2 | 21177 | |
c19d1205 ZW |
21178 | case OPCODE_AND: /* AND <-> BIC */ |
21179 | new_inst = OPCODE_BIC; | |
21180 | value = inverted; | |
21181 | break; | |
bfae80f2 | 21182 | |
c19d1205 ZW |
21183 | case OPCODE_BIC: |
21184 | new_inst = OPCODE_AND; | |
21185 | value = inverted; | |
21186 | break; | |
bfae80f2 | 21187 | |
c19d1205 ZW |
21188 | case OPCODE_ADC: /* ADC <-> SBC */ |
21189 | new_inst = OPCODE_SBC; | |
21190 | value = inverted; | |
21191 | break; | |
bfae80f2 | 21192 | |
c19d1205 ZW |
21193 | case OPCODE_SBC: |
21194 | new_inst = OPCODE_ADC; | |
21195 | value = inverted; | |
21196 | break; | |
bfae80f2 | 21197 | |
c19d1205 ZW |
21198 | /* We cannot do anything. */ |
21199 | default: | |
21200 | return FAIL; | |
b99bd4ef NC |
21201 | } |
21202 | ||
c19d1205 ZW |
21203 | if (value == (unsigned) FAIL) |
21204 | return FAIL; | |
21205 | ||
21206 | *instruction &= OPCODE_MASK; | |
21207 | *instruction |= new_inst << DATA_OP_SHIFT; | |
21208 | return value; | |
b99bd4ef NC |
21209 | } |
21210 | ||
ef8d22e6 PB |
21211 | /* Like negate_data_op, but for Thumb-2. */ |
21212 | ||
21213 | static unsigned int | |
16dd5e42 | 21214 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
21215 | { |
21216 | int op, new_inst; | |
21217 | int rd; | |
16dd5e42 | 21218 | unsigned int negated, inverted; |
ef8d22e6 PB |
21219 | |
21220 | negated = encode_thumb32_immediate (-value); | |
21221 | inverted = encode_thumb32_immediate (~value); | |
21222 | ||
21223 | rd = (*instruction >> 8) & 0xf; | |
21224 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
21225 | switch (op) | |
21226 | { | |
21227 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
21228 | case T2_OPCODE_SUB: | |
21229 | new_inst = T2_OPCODE_ADD; | |
21230 | value = negated; | |
21231 | break; | |
21232 | ||
21233 | case T2_OPCODE_ADD: | |
21234 | new_inst = T2_OPCODE_SUB; | |
21235 | value = negated; | |
21236 | break; | |
21237 | ||
21238 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
21239 | case T2_OPCODE_ORR: | |
21240 | new_inst = T2_OPCODE_ORN; | |
21241 | value = inverted; | |
21242 | break; | |
21243 | ||
21244 | case T2_OPCODE_ORN: | |
21245 | new_inst = T2_OPCODE_ORR; | |
21246 | value = inverted; | |
21247 | break; | |
21248 | ||
21249 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
21250 | case T2_OPCODE_AND: | |
21251 | new_inst = T2_OPCODE_BIC; | |
21252 | if (rd == 15) | |
21253 | value = FAIL; | |
21254 | else | |
21255 | value = inverted; | |
21256 | break; | |
21257 | ||
21258 | case T2_OPCODE_BIC: | |
21259 | new_inst = T2_OPCODE_AND; | |
21260 | value = inverted; | |
21261 | break; | |
21262 | ||
21263 | /* ADC <-> SBC */ | |
21264 | case T2_OPCODE_ADC: | |
21265 | new_inst = T2_OPCODE_SBC; | |
21266 | value = inverted; | |
21267 | break; | |
21268 | ||
21269 | case T2_OPCODE_SBC: | |
21270 | new_inst = T2_OPCODE_ADC; | |
21271 | value = inverted; | |
21272 | break; | |
21273 | ||
21274 | /* We cannot do anything. */ | |
21275 | default: | |
21276 | return FAIL; | |
21277 | } | |
21278 | ||
16dd5e42 | 21279 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
21280 | return FAIL; |
21281 | ||
21282 | *instruction &= T2_OPCODE_MASK; | |
21283 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
21284 | return value; | |
21285 | } | |
21286 | ||
8f06b2d8 PB |
21287 | /* Read a 32-bit thumb instruction from buf. */ |
21288 | static unsigned long | |
21289 | get_thumb32_insn (char * buf) | |
21290 | { | |
21291 | unsigned long insn; | |
21292 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
21293 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
21294 | ||
21295 | return insn; | |
21296 | } | |
21297 | ||
a8bc6c78 PB |
21298 | |
21299 | /* We usually want to set the low bit on the address of thumb function | |
21300 | symbols. In particular .word foo - . should have the low bit set. | |
21301 | Generic code tries to fold the difference of two symbols to | |
21302 | a constant. Prevent this and force a relocation when the first symbols | |
21303 | is a thumb function. */ | |
c921be7d NC |
21304 | |
21305 | bfd_boolean | |
a8bc6c78 PB |
21306 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
21307 | { | |
21308 | if (op == O_subtract | |
21309 | && l->X_op == O_symbol | |
21310 | && r->X_op == O_symbol | |
21311 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
21312 | { | |
21313 | l->X_op = O_subtract; | |
21314 | l->X_op_symbol = r->X_add_symbol; | |
21315 | l->X_add_number -= r->X_add_number; | |
c921be7d | 21316 | return TRUE; |
a8bc6c78 | 21317 | } |
c921be7d | 21318 | |
a8bc6c78 | 21319 | /* Process as normal. */ |
c921be7d | 21320 | return FALSE; |
a8bc6c78 PB |
21321 | } |
21322 | ||
4a42ebbc RR |
21323 | /* Encode Thumb2 unconditional branches and calls. The encoding |
21324 | for the 2 are identical for the immediate values. */ | |
21325 | ||
21326 | static void | |
21327 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
21328 | { | |
21329 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
21330 | offsetT newval; | |
21331 | offsetT newval2; | |
21332 | addressT S, I1, I2, lo, hi; | |
21333 | ||
21334 | S = (value >> 24) & 0x01; | |
21335 | I1 = (value >> 23) & 0x01; | |
21336 | I2 = (value >> 22) & 0x01; | |
21337 | hi = (value >> 12) & 0x3ff; | |
fa94de6b | 21338 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
21339 | newval = md_chars_to_number (buf, THUMB_SIZE); |
21340 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
21341 | newval |= (S << 10) | hi; | |
21342 | newval2 &= ~T2I1I2MASK; | |
21343 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
21344 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21345 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
21346 | } | |
21347 | ||
c19d1205 | 21348 | void |
55cf6793 | 21349 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
21350 | valueT * valP, |
21351 | segT seg) | |
21352 | { | |
21353 | offsetT value = * valP; | |
21354 | offsetT newval; | |
21355 | unsigned int newimm; | |
21356 | unsigned long temp; | |
21357 | int sign; | |
21358 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 21359 | |
9c2799c2 | 21360 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 21361 | |
c19d1205 | 21362 | /* Note whether this will delete the relocation. */ |
4962c51a | 21363 | |
c19d1205 ZW |
21364 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
21365 | fixP->fx_done = 1; | |
b99bd4ef | 21366 | |
adbaf948 | 21367 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 21368 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
21369 | for emit_reloc. */ |
21370 | value &= 0xffffffff; | |
21371 | value ^= 0x80000000; | |
5f4273c7 | 21372 | value -= 0x80000000; |
adbaf948 ZW |
21373 | |
21374 | *valP = value; | |
c19d1205 | 21375 | fixP->fx_addnumber = value; |
b99bd4ef | 21376 | |
adbaf948 ZW |
21377 | /* Same treatment for fixP->fx_offset. */ |
21378 | fixP->fx_offset &= 0xffffffff; | |
21379 | fixP->fx_offset ^= 0x80000000; | |
21380 | fixP->fx_offset -= 0x80000000; | |
21381 | ||
c19d1205 | 21382 | switch (fixP->fx_r_type) |
b99bd4ef | 21383 | { |
c19d1205 ZW |
21384 | case BFD_RELOC_NONE: |
21385 | /* This will need to go in the object file. */ | |
21386 | fixP->fx_done = 0; | |
21387 | break; | |
b99bd4ef | 21388 | |
c19d1205 ZW |
21389 | case BFD_RELOC_ARM_IMMEDIATE: |
21390 | /* We claim that this fixup has been processed here, | |
21391 | even if in fact we generate an error because we do | |
21392 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
21393 | fixP->fx_done = 1; | |
b99bd4ef | 21394 | |
77db8e2e | 21395 | if (fixP->fx_addsy) |
b99bd4ef | 21396 | { |
77db8e2e | 21397 | const char *msg = 0; |
b99bd4ef | 21398 | |
77db8e2e NC |
21399 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
21400 | msg = _("undefined symbol %s used as an immediate value"); | |
21401 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
21402 | msg = _("symbol %s is in a different section"); | |
21403 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
21404 | msg = _("symbol %s is weak and may be overridden later"); | |
21405 | ||
21406 | if (msg) | |
21407 | { | |
21408 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21409 | msg, S_GET_NAME (fixP->fx_addsy)); | |
21410 | break; | |
21411 | } | |
42e5fcbf AS |
21412 | } |
21413 | ||
c19d1205 ZW |
21414 | temp = md_chars_to_number (buf, INSN_SIZE); |
21415 | ||
5e73442d SL |
21416 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
21417 | if ((temp & 0xfff0000) == 0x28f0000 && value < 0) | |
21418 | newimm = negate_data_op (&temp, value); | |
21419 | else | |
21420 | { | |
21421 | newimm = encode_arm_immediate (value); | |
21422 | ||
21423 | /* If the instruction will fail, see if we can fix things up by | |
21424 | changing the opcode. */ | |
21425 | if (newimm == (unsigned int) FAIL) | |
21426 | newimm = negate_data_op (&temp, value); | |
21427 | } | |
21428 | ||
21429 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 21430 | { |
c19d1205 ZW |
21431 | as_bad_where (fixP->fx_file, fixP->fx_line, |
21432 | _("invalid constant (%lx) after fixup"), | |
21433 | (unsigned long) value); | |
21434 | break; | |
b99bd4ef | 21435 | } |
b99bd4ef | 21436 | |
c19d1205 ZW |
21437 | newimm |= (temp & 0xfffff000); |
21438 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
21439 | break; | |
b99bd4ef | 21440 | |
c19d1205 ZW |
21441 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
21442 | { | |
21443 | unsigned int highpart = 0; | |
21444 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 21445 | |
77db8e2e | 21446 | if (fixP->fx_addsy) |
42e5fcbf | 21447 | { |
77db8e2e | 21448 | const char *msg = 0; |
42e5fcbf | 21449 | |
77db8e2e NC |
21450 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
21451 | msg = _("undefined symbol %s used as an immediate value"); | |
21452 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
21453 | msg = _("symbol %s is in a different section"); | |
21454 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
21455 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 21456 | |
77db8e2e NC |
21457 | if (msg) |
21458 | { | |
21459 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21460 | msg, S_GET_NAME (fixP->fx_addsy)); | |
21461 | break; | |
21462 | } | |
21463 | } | |
fa94de6b | 21464 | |
c19d1205 ZW |
21465 | newimm = encode_arm_immediate (value); |
21466 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 21467 | |
c19d1205 ZW |
21468 | /* If the instruction will fail, see if we can fix things up by |
21469 | changing the opcode. */ | |
21470 | if (newimm == (unsigned int) FAIL | |
21471 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
21472 | { | |
21473 | /* No ? OK - try using two ADD instructions to generate | |
21474 | the value. */ | |
21475 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 21476 | |
c19d1205 ZW |
21477 | /* Yes - then make sure that the second instruction is |
21478 | also an add. */ | |
21479 | if (newimm != (unsigned int) FAIL) | |
21480 | newinsn = temp; | |
21481 | /* Still No ? Try using a negated value. */ | |
21482 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
21483 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
21484 | /* Otherwise - give up. */ | |
21485 | else | |
21486 | { | |
21487 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21488 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
21489 | (long) value); | |
21490 | break; | |
21491 | } | |
b99bd4ef | 21492 | |
c19d1205 ZW |
21493 | /* Replace the first operand in the 2nd instruction (which |
21494 | is the PC) with the destination register. We have | |
21495 | already added in the PC in the first instruction and we | |
21496 | do not want to do it again. */ | |
21497 | newinsn &= ~ 0xf0000; | |
21498 | newinsn |= ((newinsn & 0x0f000) << 4); | |
21499 | } | |
b99bd4ef | 21500 | |
c19d1205 ZW |
21501 | newimm |= (temp & 0xfffff000); |
21502 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 21503 | |
c19d1205 ZW |
21504 | highpart |= (newinsn & 0xfffff000); |
21505 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
21506 | } | |
21507 | break; | |
b99bd4ef | 21508 | |
c19d1205 | 21509 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
21510 | if (!fixP->fx_done && seg->use_rela_p) |
21511 | value = 0; | |
21512 | ||
c19d1205 | 21513 | case BFD_RELOC_ARM_LITERAL: |
26d97720 | 21514 | sign = value > 0; |
b99bd4ef | 21515 | |
c19d1205 ZW |
21516 | if (value < 0) |
21517 | value = - value; | |
b99bd4ef | 21518 | |
c19d1205 | 21519 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 21520 | { |
c19d1205 ZW |
21521 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
21522 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21523 | _("invalid literal constant: pool needs to be closer")); | |
21524 | else | |
21525 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21526 | _("bad immediate value for offset (%ld)"), | |
21527 | (long) value); | |
21528 | break; | |
f03698e6 RE |
21529 | } |
21530 | ||
c19d1205 | 21531 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
21532 | if (value == 0) |
21533 | newval &= 0xfffff000; | |
21534 | else | |
21535 | { | |
21536 | newval &= 0xff7ff000; | |
21537 | newval |= value | (sign ? INDEX_UP : 0); | |
21538 | } | |
c19d1205 ZW |
21539 | md_number_to_chars (buf, newval, INSN_SIZE); |
21540 | break; | |
b99bd4ef | 21541 | |
c19d1205 ZW |
21542 | case BFD_RELOC_ARM_OFFSET_IMM8: |
21543 | case BFD_RELOC_ARM_HWLITERAL: | |
26d97720 | 21544 | sign = value > 0; |
b99bd4ef | 21545 | |
c19d1205 ZW |
21546 | if (value < 0) |
21547 | value = - value; | |
b99bd4ef | 21548 | |
c19d1205 | 21549 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 21550 | { |
c19d1205 ZW |
21551 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
21552 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21553 | _("invalid literal constant: pool needs to be closer")); | |
21554 | else | |
427d0db6 RM |
21555 | as_bad_where (fixP->fx_file, fixP->fx_line, |
21556 | _("bad immediate value for 8-bit offset (%ld)"), | |
21557 | (long) value); | |
c19d1205 | 21558 | break; |
b99bd4ef NC |
21559 | } |
21560 | ||
c19d1205 | 21561 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
21562 | if (value == 0) |
21563 | newval &= 0xfffff0f0; | |
21564 | else | |
21565 | { | |
21566 | newval &= 0xff7ff0f0; | |
21567 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
21568 | } | |
c19d1205 ZW |
21569 | md_number_to_chars (buf, newval, INSN_SIZE); |
21570 | break; | |
b99bd4ef | 21571 | |
c19d1205 ZW |
21572 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
21573 | if (value < 0 || value > 1020 || value % 4 != 0) | |
21574 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21575 | _("bad immediate value for offset (%ld)"), (long) value); | |
21576 | value /= 4; | |
b99bd4ef | 21577 | |
c19d1205 | 21578 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
21579 | newval |= value; |
21580 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
21581 | break; | |
b99bd4ef | 21582 | |
c19d1205 ZW |
21583 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
21584 | /* This is a complicated relocation used for all varieties of Thumb32 | |
21585 | load/store instruction with immediate offset: | |
21586 | ||
21587 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
21588 | *4, optional writeback(W) | |
21589 | (doubleword load/store) | |
21590 | ||
21591 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
21592 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
21593 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
21594 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
21595 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
21596 | ||
21597 | Uppercase letters indicate bits that are already encoded at | |
21598 | this point. Lowercase letters are our problem. For the | |
21599 | second block of instructions, the secondary opcode nybble | |
21600 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
21601 | a PC-relative operation. */ | |
21602 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
21603 | newval <<= 16; | |
21604 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 21605 | |
c19d1205 | 21606 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 21607 | { |
c19d1205 ZW |
21608 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
21609 | if (value >= 0) | |
21610 | newval |= (1 << 23); | |
21611 | else | |
21612 | value = -value; | |
21613 | if (value % 4 != 0) | |
21614 | { | |
21615 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21616 | _("offset not a multiple of 4")); | |
21617 | break; | |
21618 | } | |
21619 | value /= 4; | |
216d22bc | 21620 | if (value > 0xff) |
c19d1205 ZW |
21621 | { |
21622 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21623 | _("offset out of range")); | |
21624 | break; | |
21625 | } | |
21626 | newval &= ~0xff; | |
b99bd4ef | 21627 | } |
c19d1205 | 21628 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 21629 | { |
c19d1205 ZW |
21630 | /* PC-relative, 12-bit offset. */ |
21631 | if (value >= 0) | |
21632 | newval |= (1 << 23); | |
21633 | else | |
21634 | value = -value; | |
216d22bc | 21635 | if (value > 0xfff) |
c19d1205 ZW |
21636 | { |
21637 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21638 | _("offset out of range")); | |
21639 | break; | |
21640 | } | |
21641 | newval &= ~0xfff; | |
b99bd4ef | 21642 | } |
c19d1205 | 21643 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 21644 | { |
c19d1205 ZW |
21645 | /* Writeback: 8-bit, +/- offset. */ |
21646 | if (value >= 0) | |
21647 | newval |= (1 << 9); | |
21648 | else | |
21649 | value = -value; | |
216d22bc | 21650 | if (value > 0xff) |
c19d1205 ZW |
21651 | { |
21652 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21653 | _("offset out of range")); | |
21654 | break; | |
21655 | } | |
21656 | newval &= ~0xff; | |
b99bd4ef | 21657 | } |
c19d1205 | 21658 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 21659 | { |
c19d1205 | 21660 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 21661 | if (value < 0 || value > 0xff) |
b99bd4ef | 21662 | { |
c19d1205 ZW |
21663 | as_bad_where (fixP->fx_file, fixP->fx_line, |
21664 | _("offset out of range")); | |
21665 | break; | |
b99bd4ef | 21666 | } |
c19d1205 ZW |
21667 | newval &= ~0xff; |
21668 | newval |= value; | |
b99bd4ef NC |
21669 | } |
21670 | else | |
b99bd4ef | 21671 | { |
c19d1205 ZW |
21672 | /* Positive 12-bit or negative 8-bit offset. */ |
21673 | int limit; | |
21674 | if (value >= 0) | |
b99bd4ef | 21675 | { |
c19d1205 ZW |
21676 | newval |= (1 << 23); |
21677 | limit = 0xfff; | |
21678 | } | |
21679 | else | |
21680 | { | |
21681 | value = -value; | |
21682 | limit = 0xff; | |
21683 | } | |
21684 | if (value > limit) | |
21685 | { | |
21686 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21687 | _("offset out of range")); | |
21688 | break; | |
b99bd4ef | 21689 | } |
c19d1205 | 21690 | newval &= ~limit; |
b99bd4ef | 21691 | } |
b99bd4ef | 21692 | |
c19d1205 ZW |
21693 | newval |= value; |
21694 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
21695 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
21696 | break; | |
404ff6b5 | 21697 | |
c19d1205 ZW |
21698 | case BFD_RELOC_ARM_SHIFT_IMM: |
21699 | newval = md_chars_to_number (buf, INSN_SIZE); | |
21700 | if (((unsigned long) value) > 32 | |
21701 | || (value == 32 | |
21702 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
21703 | { | |
21704 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21705 | _("shift expression is too large")); | |
21706 | break; | |
21707 | } | |
404ff6b5 | 21708 | |
c19d1205 ZW |
21709 | if (value == 0) |
21710 | /* Shifts of zero must be done as lsl. */ | |
21711 | newval &= ~0x60; | |
21712 | else if (value == 32) | |
21713 | value = 0; | |
21714 | newval &= 0xfffff07f; | |
21715 | newval |= (value & 0x1f) << 7; | |
21716 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21717 | break; | |
404ff6b5 | 21718 | |
c19d1205 | 21719 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 21720 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 21721 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 21722 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
21723 | /* We claim that this fixup has been processed here, |
21724 | even if in fact we generate an error because we do | |
21725 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
21726 | fixP->fx_done = 1; | |
404ff6b5 | 21727 | |
c19d1205 ZW |
21728 | if (fixP->fx_addsy |
21729 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
21730 | { | |
21731 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21732 | _("undefined symbol %s used as an immediate value"), | |
21733 | S_GET_NAME (fixP->fx_addsy)); | |
21734 | break; | |
21735 | } | |
404ff6b5 | 21736 | |
c19d1205 ZW |
21737 | newval = md_chars_to_number (buf, THUMB_SIZE); |
21738 | newval <<= 16; | |
21739 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 21740 | |
16805f35 PB |
21741 | newimm = FAIL; |
21742 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
21743 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
21744 | { |
21745 | newimm = encode_thumb32_immediate (value); | |
21746 | if (newimm == (unsigned int) FAIL) | |
21747 | newimm = thumb32_negate_data_op (&newval, value); | |
21748 | } | |
16805f35 PB |
21749 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
21750 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 21751 | { |
16805f35 PB |
21752 | /* Turn add/sum into addw/subw. */ |
21753 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
21754 | newval = (newval & 0xfeffffff) | 0x02000000; | |
40f246e3 NC |
21755 | /* No flat 12-bit imm encoding for addsw/subsw. */ |
21756 | if ((newval & 0x00100000) == 0) | |
e9f89963 | 21757 | { |
40f246e3 NC |
21758 | /* 12 bit immediate for addw/subw. */ |
21759 | if (value < 0) | |
21760 | { | |
21761 | value = -value; | |
21762 | newval ^= 0x00a00000; | |
21763 | } | |
21764 | if (value > 0xfff) | |
21765 | newimm = (unsigned int) FAIL; | |
21766 | else | |
21767 | newimm = value; | |
e9f89963 | 21768 | } |
92e90b6e | 21769 | } |
cc8a6dd0 | 21770 | |
c19d1205 | 21771 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 21772 | { |
c19d1205 ZW |
21773 | as_bad_where (fixP->fx_file, fixP->fx_line, |
21774 | _("invalid constant (%lx) after fixup"), | |
21775 | (unsigned long) value); | |
21776 | break; | |
3631a3c8 NC |
21777 | } |
21778 | ||
c19d1205 ZW |
21779 | newval |= (newimm & 0x800) << 15; |
21780 | newval |= (newimm & 0x700) << 4; | |
21781 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 21782 | |
c19d1205 ZW |
21783 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
21784 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
21785 | break; | |
a737bd4d | 21786 | |
3eb17e6b | 21787 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
21788 | if (((unsigned long) value) > 0xffff) |
21789 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 21790 | _("invalid smc expression")); |
2fc8bdac | 21791 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
21792 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
21793 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21794 | break; | |
a737bd4d | 21795 | |
90ec0d68 MGD |
21796 | case BFD_RELOC_ARM_HVC: |
21797 | if (((unsigned long) value) > 0xffff) | |
21798 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21799 | _("invalid hvc expression")); | |
21800 | newval = md_chars_to_number (buf, INSN_SIZE); | |
21801 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
21802 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21803 | break; | |
21804 | ||
c19d1205 | 21805 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 21806 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
21807 | { |
21808 | if (((unsigned long) value) > 0xff) | |
21809 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21810 | _("invalid swi expression")); | |
2fc8bdac | 21811 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
21812 | newval |= value; |
21813 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21814 | } | |
21815 | else | |
21816 | { | |
21817 | if (((unsigned long) value) > 0x00ffffff) | |
21818 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21819 | _("invalid swi expression")); | |
2fc8bdac | 21820 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
21821 | newval |= value; |
21822 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21823 | } | |
21824 | break; | |
a737bd4d | 21825 | |
c19d1205 ZW |
21826 | case BFD_RELOC_ARM_MULTI: |
21827 | if (((unsigned long) value) > 0xffff) | |
21828 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21829 | _("invalid expression in load/store multiple")); | |
21830 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
21831 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21832 | break; | |
a737bd4d | 21833 | |
c19d1205 | 21834 | #ifdef OBJ_ELF |
39b41c9c | 21835 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
21836 | |
21837 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
21838 | && fixP->fx_addsy | |
34e77a92 | 21839 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
21840 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
21841 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
21842 | /* Flip the bl to blx. This is a simple flip | |
21843 | bit here because we generate PCREL_CALL for | |
21844 | unconditional bls. */ | |
21845 | { | |
21846 | newval = md_chars_to_number (buf, INSN_SIZE); | |
21847 | newval = newval | 0x10000000; | |
21848 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21849 | temp = 1; | |
21850 | fixP->fx_done = 1; | |
21851 | } | |
39b41c9c PB |
21852 | else |
21853 | temp = 3; | |
21854 | goto arm_branch_common; | |
21855 | ||
21856 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
21857 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
21858 | && fixP->fx_addsy | |
34e77a92 | 21859 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
21860 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
21861 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
21862 | { | |
21863 | /* This would map to a bl<cond>, b<cond>, | |
21864 | b<always> to a Thumb function. We | |
21865 | need to force a relocation for this particular | |
21866 | case. */ | |
21867 | newval = md_chars_to_number (buf, INSN_SIZE); | |
21868 | fixP->fx_done = 0; | |
21869 | } | |
21870 | ||
2fc8bdac | 21871 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 21872 | #endif |
39b41c9c PB |
21873 | case BFD_RELOC_ARM_PCREL_BRANCH: |
21874 | temp = 3; | |
21875 | goto arm_branch_common; | |
a737bd4d | 21876 | |
39b41c9c | 21877 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 21878 | |
39b41c9c | 21879 | temp = 1; |
267bf995 RR |
21880 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
21881 | && fixP->fx_addsy | |
34e77a92 | 21882 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
21883 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
21884 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
21885 | { | |
21886 | /* Flip the blx to a bl and warn. */ | |
21887 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
21888 | newval = 0xeb000000; | |
21889 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
21890 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
21891 | name); | |
21892 | md_number_to_chars (buf, newval, INSN_SIZE); | |
21893 | temp = 3; | |
21894 | fixP->fx_done = 1; | |
21895 | } | |
21896 | ||
21897 | #ifdef OBJ_ELF | |
21898 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
21899 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; | |
21900 | #endif | |
21901 | ||
39b41c9c | 21902 | arm_branch_common: |
c19d1205 | 21903 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
21904 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
21905 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
21906 | also be be clear. */ | |
21907 | if (value & temp) | |
c19d1205 | 21908 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
21909 | _("misaligned branch destination")); |
21910 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
21911 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
08f10d51 | 21912 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 21913 | |
2fc8bdac | 21914 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 21915 | { |
2fc8bdac ZW |
21916 | newval = md_chars_to_number (buf, INSN_SIZE); |
21917 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
21918 | /* Set the H bit on BLX instructions. */ |
21919 | if (temp == 1) | |
21920 | { | |
21921 | if (value & 2) | |
21922 | newval |= 0x01000000; | |
21923 | else | |
21924 | newval &= ~0x01000000; | |
21925 | } | |
2fc8bdac | 21926 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 21927 | } |
c19d1205 | 21928 | break; |
a737bd4d | 21929 | |
25fe350b MS |
21930 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
21931 | /* CBZ can only branch forward. */ | |
a737bd4d | 21932 | |
738755b0 MS |
21933 | /* Attempts to use CBZ to branch to the next instruction |
21934 | (which, strictly speaking, are prohibited) will be turned into | |
21935 | no-ops. | |
21936 | ||
21937 | FIXME: It may be better to remove the instruction completely and | |
21938 | perform relaxation. */ | |
21939 | if (value == -2) | |
2fc8bdac ZW |
21940 | { |
21941 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 21942 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
21943 | md_number_to_chars (buf, newval, THUMB_SIZE); |
21944 | } | |
738755b0 MS |
21945 | else |
21946 | { | |
21947 | if (value & ~0x7e) | |
08f10d51 | 21948 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 MS |
21949 | |
21950 | if (fixP->fx_done || !seg->use_rela_p) | |
21951 | { | |
21952 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
21953 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
21954 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21955 | } | |
21956 | } | |
c19d1205 | 21957 | break; |
a737bd4d | 21958 | |
c19d1205 | 21959 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac | 21960 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
08f10d51 | 21961 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 21962 | |
2fc8bdac ZW |
21963 | if (fixP->fx_done || !seg->use_rela_p) |
21964 | { | |
21965 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
21966 | newval |= (value & 0x1ff) >> 1; | |
21967 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21968 | } | |
c19d1205 | 21969 | break; |
a737bd4d | 21970 | |
c19d1205 | 21971 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac | 21972 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
08f10d51 | 21973 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 21974 | |
2fc8bdac ZW |
21975 | if (fixP->fx_done || !seg->use_rela_p) |
21976 | { | |
21977 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
21978 | newval |= (value & 0xfff) >> 1; | |
21979 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21980 | } | |
c19d1205 | 21981 | break; |
a737bd4d | 21982 | |
c19d1205 | 21983 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
21984 | if (fixP->fx_addsy |
21985 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 21986 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
21987 | && ARM_IS_FUNC (fixP->fx_addsy) |
21988 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
21989 | { | |
21990 | /* Force a relocation for a branch 20 bits wide. */ | |
21991 | fixP->fx_done = 0; | |
21992 | } | |
08f10d51 | 21993 | if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff)) |
2fc8bdac ZW |
21994 | as_bad_where (fixP->fx_file, fixP->fx_line, |
21995 | _("conditional branch out of range")); | |
404ff6b5 | 21996 | |
2fc8bdac ZW |
21997 | if (fixP->fx_done || !seg->use_rela_p) |
21998 | { | |
21999 | offsetT newval2; | |
22000 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 22001 | |
2fc8bdac ZW |
22002 | S = (value & 0x00100000) >> 20; |
22003 | J2 = (value & 0x00080000) >> 19; | |
22004 | J1 = (value & 0x00040000) >> 18; | |
22005 | hi = (value & 0x0003f000) >> 12; | |
22006 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 22007 | |
2fc8bdac ZW |
22008 | newval = md_chars_to_number (buf, THUMB_SIZE); |
22009 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22010 | newval |= (S << 10) | hi; | |
22011 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
22012 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22013 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
22014 | } | |
c19d1205 | 22015 | break; |
6c43fab6 | 22016 | |
c19d1205 | 22017 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
22018 | /* If there is a blx from a thumb state function to |
22019 | another thumb function flip this to a bl and warn | |
22020 | about it. */ | |
22021 | ||
22022 | if (fixP->fx_addsy | |
34e77a92 | 22023 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22024 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
22025 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
22026 | { | |
22027 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
22028 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
22029 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
22030 | name); | |
22031 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22032 | newval = newval | 0x1000; | |
22033 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
22034 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
22035 | fixP->fx_done = 1; | |
22036 | } | |
22037 | ||
22038 | ||
22039 | goto thumb_bl_common; | |
22040 | ||
c19d1205 | 22041 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
22042 | /* A bl from Thumb state ISA to an internal ARM state function |
22043 | is converted to a blx. */ | |
22044 | if (fixP->fx_addsy | |
22045 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22046 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22047 | && ARM_IS_FUNC (fixP->fx_addsy) |
22048 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22049 | { | |
22050 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22051 | newval = newval & ~0x1000; | |
22052 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
22053 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
22054 | fixP->fx_done = 1; | |
22055 | } | |
22056 | ||
22057 | thumb_bl_common: | |
22058 | ||
2fc8bdac ZW |
22059 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
22060 | /* For a BLX instruction, make sure that the relocation is rounded up | |
22061 | to a word boundary. This follows the semantics of the instruction | |
22062 | which specifies that bit 1 of the target address will come from bit | |
22063 | 1 of the base address. */ | |
d406f3e4 JB |
22064 | value = (value + 3) & ~ 3; |
22065 | ||
22066 | #ifdef OBJ_ELF | |
22067 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 | |
22068 | && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
22069 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
22070 | #endif | |
404ff6b5 | 22071 | |
2b2f5df9 NC |
22072 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
22073 | { | |
22074 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))) | |
22075 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
22076 | else if ((value & ~0x1ffffff) | |
22077 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
22078 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22079 | _("Thumb2 branch out of range")); | |
22080 | } | |
4a42ebbc RR |
22081 | |
22082 | if (fixP->fx_done || !seg->use_rela_p) | |
22083 | encode_thumb2_b_bl_offset (buf, value); | |
22084 | ||
c19d1205 | 22085 | break; |
404ff6b5 | 22086 | |
c19d1205 | 22087 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
08f10d51 NC |
22088 | if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff)) |
22089 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
6c43fab6 | 22090 | |
2fc8bdac | 22091 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 22092 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 22093 | |
2fc8bdac | 22094 | break; |
a737bd4d | 22095 | |
2fc8bdac ZW |
22096 | case BFD_RELOC_8: |
22097 | if (fixP->fx_done || !seg->use_rela_p) | |
22098 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 22099 | break; |
a737bd4d | 22100 | |
c19d1205 | 22101 | case BFD_RELOC_16: |
2fc8bdac | 22102 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 22103 | md_number_to_chars (buf, value, 2); |
c19d1205 | 22104 | break; |
a737bd4d | 22105 | |
c19d1205 | 22106 | #ifdef OBJ_ELF |
0855e32b NS |
22107 | case BFD_RELOC_ARM_TLS_CALL: |
22108 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
22109 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
22110 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
22111 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
22112 | break; | |
22113 | ||
22114 | case BFD_RELOC_ARM_TLS_GOTDESC: | |
c19d1205 ZW |
22115 | case BFD_RELOC_ARM_TLS_GD32: |
22116 | case BFD_RELOC_ARM_TLS_LE32: | |
22117 | case BFD_RELOC_ARM_TLS_IE32: | |
22118 | case BFD_RELOC_ARM_TLS_LDM32: | |
22119 | case BFD_RELOC_ARM_TLS_LDO32: | |
22120 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
22121 | /* fall through */ | |
6c43fab6 | 22122 | |
c19d1205 ZW |
22123 | case BFD_RELOC_ARM_GOT32: |
22124 | case BFD_RELOC_ARM_GOTOFF: | |
2fc8bdac ZW |
22125 | if (fixP->fx_done || !seg->use_rela_p) |
22126 | md_number_to_chars (buf, 0, 4); | |
c19d1205 | 22127 | break; |
b43420e6 NC |
22128 | |
22129 | case BFD_RELOC_ARM_GOT_PREL: | |
22130 | if (fixP->fx_done || !seg->use_rela_p) | |
22131 | md_number_to_chars (buf, value, 4); | |
22132 | break; | |
22133 | ||
9a6f4e97 NS |
22134 | case BFD_RELOC_ARM_TARGET2: |
22135 | /* TARGET2 is not partial-inplace, so we need to write the | |
22136 | addend here for REL targets, because it won't be written out | |
22137 | during reloc processing later. */ | |
22138 | if (fixP->fx_done || !seg->use_rela_p) | |
22139 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
22140 | break; | |
c19d1205 | 22141 | #endif |
6c43fab6 | 22142 | |
c19d1205 ZW |
22143 | case BFD_RELOC_RVA: |
22144 | case BFD_RELOC_32: | |
22145 | case BFD_RELOC_ARM_TARGET1: | |
22146 | case BFD_RELOC_ARM_ROSEGREL32: | |
22147 | case BFD_RELOC_ARM_SBREL32: | |
22148 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
22149 | #ifdef TE_PE |
22150 | case BFD_RELOC_32_SECREL: | |
22151 | #endif | |
2fc8bdac | 22152 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
22153 | #ifdef TE_WINCE |
22154 | /* For WinCE we only do this for pcrel fixups. */ | |
22155 | if (fixP->fx_done || fixP->fx_pcrel) | |
22156 | #endif | |
22157 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 22158 | break; |
6c43fab6 | 22159 | |
c19d1205 ZW |
22160 | #ifdef OBJ_ELF |
22161 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 22162 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
22163 | { |
22164 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
22165 | if ((value ^ (value >> 1)) & 0x40000000) | |
22166 | { | |
22167 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22168 | _("rel31 relocation overflow")); | |
22169 | } | |
22170 | newval |= value & 0x7fffffff; | |
22171 | md_number_to_chars (buf, newval, 4); | |
22172 | } | |
22173 | break; | |
c19d1205 | 22174 | #endif |
a737bd4d | 22175 | |
c19d1205 | 22176 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 22177 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
22178 | if (value < -1023 || value > 1023 || (value & 3)) |
22179 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22180 | _("co-processor offset out of range")); | |
22181 | cp_off_common: | |
26d97720 | 22182 | sign = value > 0; |
c19d1205 ZW |
22183 | if (value < 0) |
22184 | value = -value; | |
8f06b2d8 PB |
22185 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
22186 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
22187 | newval = md_chars_to_number (buf, INSN_SIZE); | |
22188 | else | |
22189 | newval = get_thumb32_insn (buf); | |
26d97720 NS |
22190 | if (value == 0) |
22191 | newval &= 0xffffff00; | |
22192 | else | |
22193 | { | |
22194 | newval &= 0xff7fff00; | |
22195 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); | |
22196 | } | |
8f06b2d8 PB |
22197 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
22198 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
22199 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22200 | else | |
22201 | put_thumb32_insn (buf, newval); | |
c19d1205 | 22202 | break; |
a737bd4d | 22203 | |
c19d1205 | 22204 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 22205 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
22206 | if (value < -255 || value > 255) |
22207 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22208 | _("co-processor offset out of range")); | |
df7849c5 | 22209 | value *= 4; |
c19d1205 | 22210 | goto cp_off_common; |
6c43fab6 | 22211 | |
c19d1205 ZW |
22212 | case BFD_RELOC_ARM_THUMB_OFFSET: |
22213 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22214 | /* Exactly what ranges, and where the offset is inserted depends | |
22215 | on the type of instruction, we can establish this from the | |
22216 | top 4 bits. */ | |
22217 | switch (newval >> 12) | |
22218 | { | |
22219 | case 4: /* PC load. */ | |
22220 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
22221 | forced to zero for these loads; md_pcrel_from has already | |
22222 | compensated for this. */ | |
22223 | if (value & 3) | |
22224 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22225 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
22226 | (((unsigned long) fixP->fx_frag->fr_address |
22227 | + (unsigned long) fixP->fx_where) & ~3) | |
22228 | + (unsigned long) value); | |
a737bd4d | 22229 | |
c19d1205 ZW |
22230 | if (value & ~0x3fc) |
22231 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22232 | _("invalid offset, value too big (0x%08lX)"), | |
22233 | (long) value); | |
a737bd4d | 22234 | |
c19d1205 ZW |
22235 | newval |= value >> 2; |
22236 | break; | |
a737bd4d | 22237 | |
c19d1205 ZW |
22238 | case 9: /* SP load/store. */ |
22239 | if (value & ~0x3fc) | |
22240 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22241 | _("invalid offset, value too big (0x%08lX)"), | |
22242 | (long) value); | |
22243 | newval |= value >> 2; | |
22244 | break; | |
6c43fab6 | 22245 | |
c19d1205 ZW |
22246 | case 6: /* Word load/store. */ |
22247 | if (value & ~0x7c) | |
22248 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22249 | _("invalid offset, value too big (0x%08lX)"), | |
22250 | (long) value); | |
22251 | newval |= value << 4; /* 6 - 2. */ | |
22252 | break; | |
a737bd4d | 22253 | |
c19d1205 ZW |
22254 | case 7: /* Byte load/store. */ |
22255 | if (value & ~0x1f) | |
22256 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22257 | _("invalid offset, value too big (0x%08lX)"), | |
22258 | (long) value); | |
22259 | newval |= value << 6; | |
22260 | break; | |
a737bd4d | 22261 | |
c19d1205 ZW |
22262 | case 8: /* Halfword load/store. */ |
22263 | if (value & ~0x3e) | |
22264 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22265 | _("invalid offset, value too big (0x%08lX)"), | |
22266 | (long) value); | |
22267 | newval |= value << 5; /* 6 - 1. */ | |
22268 | break; | |
a737bd4d | 22269 | |
c19d1205 ZW |
22270 | default: |
22271 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22272 | "Unable to process relocation for thumb opcode: %lx", | |
22273 | (unsigned long) newval); | |
22274 | break; | |
22275 | } | |
22276 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22277 | break; | |
a737bd4d | 22278 | |
c19d1205 ZW |
22279 | case BFD_RELOC_ARM_THUMB_ADD: |
22280 | /* This is a complicated relocation, since we use it for all of | |
22281 | the following immediate relocations: | |
a737bd4d | 22282 | |
c19d1205 ZW |
22283 | 3bit ADD/SUB |
22284 | 8bit ADD/SUB | |
22285 | 9bit ADD/SUB SP word-aligned | |
22286 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 22287 | |
c19d1205 ZW |
22288 | The type of instruction being processed is encoded in the |
22289 | instruction field: | |
a737bd4d | 22290 | |
c19d1205 ZW |
22291 | 0x8000 SUB |
22292 | 0x00F0 Rd | |
22293 | 0x000F Rs | |
22294 | */ | |
22295 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22296 | { | |
22297 | int rd = (newval >> 4) & 0xf; | |
22298 | int rs = newval & 0xf; | |
22299 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 22300 | |
c19d1205 ZW |
22301 | /* Check for HI regs, only very restricted cases allowed: |
22302 | Adjusting SP, and using PC or SP to get an address. */ | |
22303 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
22304 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
22305 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22306 | _("invalid Hi register with immediate")); | |
a737bd4d | 22307 | |
c19d1205 ZW |
22308 | /* If value is negative, choose the opposite instruction. */ |
22309 | if (value < 0) | |
22310 | { | |
22311 | value = -value; | |
22312 | subtract = !subtract; | |
22313 | if (value < 0) | |
22314 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22315 | _("immediate value out of range")); | |
22316 | } | |
a737bd4d | 22317 | |
c19d1205 ZW |
22318 | if (rd == REG_SP) |
22319 | { | |
22320 | if (value & ~0x1fc) | |
22321 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22322 | _("invalid immediate for stack address calculation")); | |
22323 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
22324 | newval |= value >> 2; | |
22325 | } | |
22326 | else if (rs == REG_PC || rs == REG_SP) | |
22327 | { | |
22328 | if (subtract || value & ~0x3fc) | |
22329 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22330 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
22331 | (unsigned long) value); | |
22332 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
22333 | newval |= rd << 8; | |
22334 | newval |= value >> 2; | |
22335 | } | |
22336 | else if (rs == rd) | |
22337 | { | |
22338 | if (value & ~0xff) | |
22339 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22340 | _("immediate value out of range")); | |
22341 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
22342 | newval |= (rd << 8) | value; | |
22343 | } | |
22344 | else | |
22345 | { | |
22346 | if (value & ~0x7) | |
22347 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22348 | _("immediate value out of range")); | |
22349 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
22350 | newval |= rd | (rs << 3) | (value << 6); | |
22351 | } | |
22352 | } | |
22353 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22354 | break; | |
a737bd4d | 22355 | |
c19d1205 ZW |
22356 | case BFD_RELOC_ARM_THUMB_IMM: |
22357 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22358 | if (value < 0 || value > 255) | |
22359 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 22360 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
22361 | (long) value); |
22362 | newval |= value; | |
22363 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22364 | break; | |
a737bd4d | 22365 | |
c19d1205 ZW |
22366 | case BFD_RELOC_ARM_THUMB_SHIFT: |
22367 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
22368 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
22369 | temp = newval & 0xf800; | |
22370 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
22371 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22372 | _("invalid shift value: %ld"), (long) value); | |
22373 | /* Shifts of zero must be encoded as LSL. */ | |
22374 | if (value == 0) | |
22375 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
22376 | /* Shifts of 32 are encoded as zero. */ | |
22377 | else if (value == 32) | |
22378 | value = 0; | |
22379 | newval |= value << 6; | |
22380 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22381 | break; | |
a737bd4d | 22382 | |
c19d1205 ZW |
22383 | case BFD_RELOC_VTABLE_INHERIT: |
22384 | case BFD_RELOC_VTABLE_ENTRY: | |
22385 | fixP->fx_done = 0; | |
22386 | return; | |
6c43fab6 | 22387 | |
b6895b4f PB |
22388 | case BFD_RELOC_ARM_MOVW: |
22389 | case BFD_RELOC_ARM_MOVT: | |
22390 | case BFD_RELOC_ARM_THUMB_MOVW: | |
22391 | case BFD_RELOC_ARM_THUMB_MOVT: | |
22392 | if (fixP->fx_done || !seg->use_rela_p) | |
22393 | { | |
22394 | /* REL format relocations are limited to a 16-bit addend. */ | |
22395 | if (!fixP->fx_done) | |
22396 | { | |
39623e12 | 22397 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 22398 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 22399 | _("offset out of range")); |
b6895b4f PB |
22400 | } |
22401 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
22402 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
22403 | { | |
22404 | value >>= 16; | |
22405 | } | |
22406 | ||
22407 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
22408 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
22409 | { | |
22410 | newval = get_thumb32_insn (buf); | |
22411 | newval &= 0xfbf08f00; | |
22412 | newval |= (value & 0xf000) << 4; | |
22413 | newval |= (value & 0x0800) << 15; | |
22414 | newval |= (value & 0x0700) << 4; | |
22415 | newval |= (value & 0x00ff); | |
22416 | put_thumb32_insn (buf, newval); | |
22417 | } | |
22418 | else | |
22419 | { | |
22420 | newval = md_chars_to_number (buf, 4); | |
22421 | newval &= 0xfff0f000; | |
22422 | newval |= value & 0x0fff; | |
22423 | newval |= (value & 0xf000) << 4; | |
22424 | md_number_to_chars (buf, newval, 4); | |
22425 | } | |
22426 | } | |
22427 | return; | |
22428 | ||
4962c51a MS |
22429 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
22430 | case BFD_RELOC_ARM_ALU_PC_G0: | |
22431 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
22432 | case BFD_RELOC_ARM_ALU_PC_G1: | |
22433 | case BFD_RELOC_ARM_ALU_PC_G2: | |
22434 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
22435 | case BFD_RELOC_ARM_ALU_SB_G0: | |
22436 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
22437 | case BFD_RELOC_ARM_ALU_SB_G1: | |
22438 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 22439 | gas_assert (!fixP->fx_done); |
4962c51a MS |
22440 | if (!seg->use_rela_p) |
22441 | { | |
22442 | bfd_vma insn; | |
22443 | bfd_vma encoded_addend; | |
22444 | bfd_vma addend_abs = abs (value); | |
22445 | ||
22446 | /* Check that the absolute value of the addend can be | |
22447 | expressed as an 8-bit constant plus a rotation. */ | |
22448 | encoded_addend = encode_arm_immediate (addend_abs); | |
22449 | if (encoded_addend == (unsigned int) FAIL) | |
22450 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22451 | _("the offset 0x%08lX is not representable"), | |
495bde8e | 22452 | (unsigned long) addend_abs); |
4962c51a MS |
22453 | |
22454 | /* Extract the instruction. */ | |
22455 | insn = md_chars_to_number (buf, INSN_SIZE); | |
22456 | ||
22457 | /* If the addend is positive, use an ADD instruction. | |
22458 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
22459 | insn &= 0xff1fffff; | |
22460 | if (value < 0) | |
22461 | insn |= 1 << 22; | |
22462 | else | |
22463 | insn |= 1 << 23; | |
22464 | ||
22465 | /* Place the encoded addend into the first 12 bits of the | |
22466 | instruction. */ | |
22467 | insn &= 0xfffff000; | |
22468 | insn |= encoded_addend; | |
5f4273c7 NC |
22469 | |
22470 | /* Update the instruction. */ | |
4962c51a MS |
22471 | md_number_to_chars (buf, insn, INSN_SIZE); |
22472 | } | |
22473 | break; | |
22474 | ||
22475 | case BFD_RELOC_ARM_LDR_PC_G0: | |
22476 | case BFD_RELOC_ARM_LDR_PC_G1: | |
22477 | case BFD_RELOC_ARM_LDR_PC_G2: | |
22478 | case BFD_RELOC_ARM_LDR_SB_G0: | |
22479 | case BFD_RELOC_ARM_LDR_SB_G1: | |
22480 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 22481 | gas_assert (!fixP->fx_done); |
4962c51a MS |
22482 | if (!seg->use_rela_p) |
22483 | { | |
22484 | bfd_vma insn; | |
22485 | bfd_vma addend_abs = abs (value); | |
22486 | ||
22487 | /* Check that the absolute value of the addend can be | |
22488 | encoded in 12 bits. */ | |
22489 | if (addend_abs >= 0x1000) | |
22490 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22491 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
495bde8e | 22492 | (unsigned long) addend_abs); |
4962c51a MS |
22493 | |
22494 | /* Extract the instruction. */ | |
22495 | insn = md_chars_to_number (buf, INSN_SIZE); | |
22496 | ||
22497 | /* If the addend is negative, clear bit 23 of the instruction. | |
22498 | Otherwise set it. */ | |
22499 | if (value < 0) | |
22500 | insn &= ~(1 << 23); | |
22501 | else | |
22502 | insn |= 1 << 23; | |
22503 | ||
22504 | /* Place the absolute value of the addend into the first 12 bits | |
22505 | of the instruction. */ | |
22506 | insn &= 0xfffff000; | |
22507 | insn |= addend_abs; | |
5f4273c7 NC |
22508 | |
22509 | /* Update the instruction. */ | |
4962c51a MS |
22510 | md_number_to_chars (buf, insn, INSN_SIZE); |
22511 | } | |
22512 | break; | |
22513 | ||
22514 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
22515 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
22516 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
22517 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
22518 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
22519 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 22520 | gas_assert (!fixP->fx_done); |
4962c51a MS |
22521 | if (!seg->use_rela_p) |
22522 | { | |
22523 | bfd_vma insn; | |
22524 | bfd_vma addend_abs = abs (value); | |
22525 | ||
22526 | /* Check that the absolute value of the addend can be | |
22527 | encoded in 8 bits. */ | |
22528 | if (addend_abs >= 0x100) | |
22529 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22530 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
495bde8e | 22531 | (unsigned long) addend_abs); |
4962c51a MS |
22532 | |
22533 | /* Extract the instruction. */ | |
22534 | insn = md_chars_to_number (buf, INSN_SIZE); | |
22535 | ||
22536 | /* If the addend is negative, clear bit 23 of the instruction. | |
22537 | Otherwise set it. */ | |
22538 | if (value < 0) | |
22539 | insn &= ~(1 << 23); | |
22540 | else | |
22541 | insn |= 1 << 23; | |
22542 | ||
22543 | /* Place the first four bits of the absolute value of the addend | |
22544 | into the first 4 bits of the instruction, and the remaining | |
22545 | four into bits 8 .. 11. */ | |
22546 | insn &= 0xfffff0f0; | |
22547 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
5f4273c7 NC |
22548 | |
22549 | /* Update the instruction. */ | |
4962c51a MS |
22550 | md_number_to_chars (buf, insn, INSN_SIZE); |
22551 | } | |
22552 | break; | |
22553 | ||
22554 | case BFD_RELOC_ARM_LDC_PC_G0: | |
22555 | case BFD_RELOC_ARM_LDC_PC_G1: | |
22556 | case BFD_RELOC_ARM_LDC_PC_G2: | |
22557 | case BFD_RELOC_ARM_LDC_SB_G0: | |
22558 | case BFD_RELOC_ARM_LDC_SB_G1: | |
22559 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 22560 | gas_assert (!fixP->fx_done); |
4962c51a MS |
22561 | if (!seg->use_rela_p) |
22562 | { | |
22563 | bfd_vma insn; | |
22564 | bfd_vma addend_abs = abs (value); | |
22565 | ||
22566 | /* Check that the absolute value of the addend is a multiple of | |
22567 | four and, when divided by four, fits in 8 bits. */ | |
22568 | if (addend_abs & 0x3) | |
22569 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22570 | _("bad offset 0x%08lX (must be word-aligned)"), | |
495bde8e | 22571 | (unsigned long) addend_abs); |
4962c51a MS |
22572 | |
22573 | if ((addend_abs >> 2) > 0xff) | |
22574 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22575 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
495bde8e | 22576 | (unsigned long) addend_abs); |
4962c51a MS |
22577 | |
22578 | /* Extract the instruction. */ | |
22579 | insn = md_chars_to_number (buf, INSN_SIZE); | |
22580 | ||
22581 | /* If the addend is negative, clear bit 23 of the instruction. | |
22582 | Otherwise set it. */ | |
22583 | if (value < 0) | |
22584 | insn &= ~(1 << 23); | |
22585 | else | |
22586 | insn |= 1 << 23; | |
22587 | ||
22588 | /* Place the addend (divided by four) into the first eight | |
22589 | bits of the instruction. */ | |
22590 | insn &= 0xfffffff0; | |
22591 | insn |= addend_abs >> 2; | |
5f4273c7 NC |
22592 | |
22593 | /* Update the instruction. */ | |
4962c51a MS |
22594 | md_number_to_chars (buf, insn, INSN_SIZE); |
22595 | } | |
22596 | break; | |
22597 | ||
845b51d6 PB |
22598 | case BFD_RELOC_ARM_V4BX: |
22599 | /* This will need to go in the object file. */ | |
22600 | fixP->fx_done = 0; | |
22601 | break; | |
22602 | ||
c19d1205 ZW |
22603 | case BFD_RELOC_UNUSED: |
22604 | default: | |
22605 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22606 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
22607 | } | |
6c43fab6 RE |
22608 | } |
22609 | ||
c19d1205 ZW |
22610 | /* Translate internal representation of relocation info to BFD target |
22611 | format. */ | |
a737bd4d | 22612 | |
c19d1205 | 22613 | arelent * |
00a97672 | 22614 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 22615 | { |
c19d1205 ZW |
22616 | arelent * reloc; |
22617 | bfd_reloc_code_real_type code; | |
a737bd4d | 22618 | |
21d799b5 | 22619 | reloc = (arelent *) xmalloc (sizeof (arelent)); |
a737bd4d | 22620 | |
21d799b5 | 22621 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
c19d1205 ZW |
22622 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
22623 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 22624 | |
2fc8bdac | 22625 | if (fixp->fx_pcrel) |
00a97672 RS |
22626 | { |
22627 | if (section->use_rela_p) | |
22628 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
22629 | else | |
22630 | fixp->fx_offset = reloc->address; | |
22631 | } | |
c19d1205 | 22632 | reloc->addend = fixp->fx_offset; |
a737bd4d | 22633 | |
c19d1205 | 22634 | switch (fixp->fx_r_type) |
a737bd4d | 22635 | { |
c19d1205 ZW |
22636 | case BFD_RELOC_8: |
22637 | if (fixp->fx_pcrel) | |
22638 | { | |
22639 | code = BFD_RELOC_8_PCREL; | |
22640 | break; | |
22641 | } | |
a737bd4d | 22642 | |
c19d1205 ZW |
22643 | case BFD_RELOC_16: |
22644 | if (fixp->fx_pcrel) | |
22645 | { | |
22646 | code = BFD_RELOC_16_PCREL; | |
22647 | break; | |
22648 | } | |
6c43fab6 | 22649 | |
c19d1205 ZW |
22650 | case BFD_RELOC_32: |
22651 | if (fixp->fx_pcrel) | |
22652 | { | |
22653 | code = BFD_RELOC_32_PCREL; | |
22654 | break; | |
22655 | } | |
a737bd4d | 22656 | |
b6895b4f PB |
22657 | case BFD_RELOC_ARM_MOVW: |
22658 | if (fixp->fx_pcrel) | |
22659 | { | |
22660 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
22661 | break; | |
22662 | } | |
22663 | ||
22664 | case BFD_RELOC_ARM_MOVT: | |
22665 | if (fixp->fx_pcrel) | |
22666 | { | |
22667 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
22668 | break; | |
22669 | } | |
22670 | ||
22671 | case BFD_RELOC_ARM_THUMB_MOVW: | |
22672 | if (fixp->fx_pcrel) | |
22673 | { | |
22674 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
22675 | break; | |
22676 | } | |
22677 | ||
22678 | case BFD_RELOC_ARM_THUMB_MOVT: | |
22679 | if (fixp->fx_pcrel) | |
22680 | { | |
22681 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
22682 | break; | |
22683 | } | |
22684 | ||
c19d1205 ZW |
22685 | case BFD_RELOC_NONE: |
22686 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
22687 | case BFD_RELOC_ARM_PCREL_BLX: | |
22688 | case BFD_RELOC_RVA: | |
22689 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
22690 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
22691 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
22692 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
22693 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
22694 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
22695 | case BFD_RELOC_VTABLE_ENTRY: |
22696 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
22697 | #ifdef TE_PE |
22698 | case BFD_RELOC_32_SECREL: | |
22699 | #endif | |
c19d1205 ZW |
22700 | code = fixp->fx_r_type; |
22701 | break; | |
a737bd4d | 22702 | |
00adf2d4 JB |
22703 | case BFD_RELOC_THUMB_PCREL_BLX: |
22704 | #ifdef OBJ_ELF | |
22705 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
22706 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
22707 | else | |
22708 | #endif | |
22709 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
22710 | break; | |
22711 | ||
c19d1205 ZW |
22712 | case BFD_RELOC_ARM_LITERAL: |
22713 | case BFD_RELOC_ARM_HWLITERAL: | |
22714 | /* If this is called then the a literal has | |
22715 | been referenced across a section boundary. */ | |
22716 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
22717 | _("literal referenced across section boundary")); | |
22718 | return NULL; | |
a737bd4d | 22719 | |
c19d1205 | 22720 | #ifdef OBJ_ELF |
0855e32b NS |
22721 | case BFD_RELOC_ARM_TLS_CALL: |
22722 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
22723 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
22724 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
c19d1205 ZW |
22725 | case BFD_RELOC_ARM_GOT32: |
22726 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 22727 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
22728 | case BFD_RELOC_ARM_PLT32: |
22729 | case BFD_RELOC_ARM_TARGET1: | |
22730 | case BFD_RELOC_ARM_ROSEGREL32: | |
22731 | case BFD_RELOC_ARM_SBREL32: | |
22732 | case BFD_RELOC_ARM_PREL31: | |
22733 | case BFD_RELOC_ARM_TARGET2: | |
22734 | case BFD_RELOC_ARM_TLS_LE32: | |
22735 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
22736 | case BFD_RELOC_ARM_PCREL_CALL: |
22737 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
22738 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
22739 | case BFD_RELOC_ARM_ALU_PC_G0: | |
22740 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
22741 | case BFD_RELOC_ARM_ALU_PC_G1: | |
22742 | case BFD_RELOC_ARM_ALU_PC_G2: | |
22743 | case BFD_RELOC_ARM_LDR_PC_G0: | |
22744 | case BFD_RELOC_ARM_LDR_PC_G1: | |
22745 | case BFD_RELOC_ARM_LDR_PC_G2: | |
22746 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
22747 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
22748 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
22749 | case BFD_RELOC_ARM_LDC_PC_G0: | |
22750 | case BFD_RELOC_ARM_LDC_PC_G1: | |
22751 | case BFD_RELOC_ARM_LDC_PC_G2: | |
22752 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
22753 | case BFD_RELOC_ARM_ALU_SB_G0: | |
22754 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
22755 | case BFD_RELOC_ARM_ALU_SB_G1: | |
22756 | case BFD_RELOC_ARM_ALU_SB_G2: | |
22757 | case BFD_RELOC_ARM_LDR_SB_G0: | |
22758 | case BFD_RELOC_ARM_LDR_SB_G1: | |
22759 | case BFD_RELOC_ARM_LDR_SB_G2: | |
22760 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
22761 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
22762 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
22763 | case BFD_RELOC_ARM_LDC_SB_G0: | |
22764 | case BFD_RELOC_ARM_LDC_SB_G1: | |
22765 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 22766 | case BFD_RELOC_ARM_V4BX: |
c19d1205 ZW |
22767 | code = fixp->fx_r_type; |
22768 | break; | |
a737bd4d | 22769 | |
0855e32b | 22770 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
22771 | case BFD_RELOC_ARM_TLS_GD32: |
22772 | case BFD_RELOC_ARM_TLS_IE32: | |
22773 | case BFD_RELOC_ARM_TLS_LDM32: | |
22774 | /* BFD will include the symbol's address in the addend. | |
22775 | But we don't want that, so subtract it out again here. */ | |
22776 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
22777 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
22778 | code = fixp->fx_r_type; | |
22779 | break; | |
22780 | #endif | |
a737bd4d | 22781 | |
c19d1205 ZW |
22782 | case BFD_RELOC_ARM_IMMEDIATE: |
22783 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
22784 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
22785 | return NULL; | |
a737bd4d | 22786 | |
c19d1205 ZW |
22787 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
22788 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
22789 | _("ADRL used for a symbol not defined in the same file")); | |
22790 | return NULL; | |
a737bd4d | 22791 | |
c19d1205 | 22792 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
22793 | if (section->use_rela_p) |
22794 | { | |
22795 | code = fixp->fx_r_type; | |
22796 | break; | |
22797 | } | |
22798 | ||
c19d1205 ZW |
22799 | if (fixp->fx_addsy != NULL |
22800 | && !S_IS_DEFINED (fixp->fx_addsy) | |
22801 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 22802 | { |
c19d1205 ZW |
22803 | as_bad_where (fixp->fx_file, fixp->fx_line, |
22804 | _("undefined local label `%s'"), | |
22805 | S_GET_NAME (fixp->fx_addsy)); | |
22806 | return NULL; | |
a737bd4d NC |
22807 | } |
22808 | ||
c19d1205 ZW |
22809 | as_bad_where (fixp->fx_file, fixp->fx_line, |
22810 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
22811 | return NULL; | |
a737bd4d | 22812 | |
c19d1205 ZW |
22813 | default: |
22814 | { | |
22815 | char * type; | |
6c43fab6 | 22816 | |
c19d1205 ZW |
22817 | switch (fixp->fx_r_type) |
22818 | { | |
22819 | case BFD_RELOC_NONE: type = "NONE"; break; | |
22820 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
22821 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 22822 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
22823 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
22824 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
22825 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 22826 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 22827 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
22828 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
22829 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
22830 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
22831 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
22832 | default: type = _("<unknown>"); break; | |
22833 | } | |
22834 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
22835 | _("cannot represent %s relocation in this object file format"), | |
22836 | type); | |
22837 | return NULL; | |
22838 | } | |
a737bd4d | 22839 | } |
6c43fab6 | 22840 | |
c19d1205 ZW |
22841 | #ifdef OBJ_ELF |
22842 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
22843 | && GOT_symbol | |
22844 | && fixp->fx_addsy == GOT_symbol) | |
22845 | { | |
22846 | code = BFD_RELOC_ARM_GOTPC; | |
22847 | reloc->addend = fixp->fx_offset = reloc->address; | |
22848 | } | |
22849 | #endif | |
6c43fab6 | 22850 | |
c19d1205 | 22851 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 22852 | |
c19d1205 ZW |
22853 | if (reloc->howto == NULL) |
22854 | { | |
22855 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
22856 | _("cannot represent %s relocation in this object file format"), | |
22857 | bfd_get_reloc_code_name (code)); | |
22858 | return NULL; | |
22859 | } | |
6c43fab6 | 22860 | |
c19d1205 ZW |
22861 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
22862 | vtable entry to be used in the relocation's section offset. */ | |
22863 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
22864 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 22865 | |
c19d1205 | 22866 | return reloc; |
6c43fab6 RE |
22867 | } |
22868 | ||
c19d1205 | 22869 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 22870 | |
c19d1205 ZW |
22871 | void |
22872 | cons_fix_new_arm (fragS * frag, | |
22873 | int where, | |
22874 | int size, | |
22875 | expressionS * exp) | |
6c43fab6 | 22876 | { |
c19d1205 ZW |
22877 | bfd_reloc_code_real_type type; |
22878 | int pcrel = 0; | |
6c43fab6 | 22879 | |
c19d1205 ZW |
22880 | /* Pick a reloc. |
22881 | FIXME: @@ Should look at CPU word size. */ | |
22882 | switch (size) | |
22883 | { | |
22884 | case 1: | |
22885 | type = BFD_RELOC_8; | |
22886 | break; | |
22887 | case 2: | |
22888 | type = BFD_RELOC_16; | |
22889 | break; | |
22890 | case 4: | |
22891 | default: | |
22892 | type = BFD_RELOC_32; | |
22893 | break; | |
22894 | case 8: | |
22895 | type = BFD_RELOC_64; | |
22896 | break; | |
22897 | } | |
6c43fab6 | 22898 | |
f0927246 NC |
22899 | #ifdef TE_PE |
22900 | if (exp->X_op == O_secrel) | |
22901 | { | |
22902 | exp->X_op = O_symbol; | |
22903 | type = BFD_RELOC_32_SECREL; | |
22904 | } | |
22905 | #endif | |
22906 | ||
c19d1205 ZW |
22907 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
22908 | } | |
6c43fab6 | 22909 | |
4343666d | 22910 | #if defined (OBJ_COFF) |
c19d1205 ZW |
22911 | void |
22912 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 22913 | { |
c19d1205 ZW |
22914 | /* If the destination of the branch is a defined symbol which does not have |
22915 | the THUMB_FUNC attribute, then we must be calling a function which has | |
22916 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
22917 | function and change the branch to refer to that function instead. */ | |
22918 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
22919 | && fixP->fx_addsy != NULL | |
22920 | && S_IS_DEFINED (fixP->fx_addsy) | |
22921 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 22922 | { |
c19d1205 | 22923 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 22924 | } |
c19d1205 ZW |
22925 | } |
22926 | #endif | |
6c43fab6 | 22927 | |
267bf995 | 22928 | |
c19d1205 ZW |
22929 | int |
22930 | arm_force_relocation (struct fix * fixp) | |
22931 | { | |
22932 | #if defined (OBJ_COFF) && defined (TE_PE) | |
22933 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
22934 | return 1; | |
22935 | #endif | |
6c43fab6 | 22936 | |
267bf995 RR |
22937 | /* In case we have a call or a branch to a function in ARM ISA mode from |
22938 | a thumb function or vice-versa force the relocation. These relocations | |
22939 | are cleared off for some cores that might have blx and simple transformations | |
22940 | are possible. */ | |
22941 | ||
22942 | #ifdef OBJ_ELF | |
22943 | switch (fixp->fx_r_type) | |
22944 | { | |
22945 | case BFD_RELOC_ARM_PCREL_JUMP: | |
22946 | case BFD_RELOC_ARM_PCREL_CALL: | |
22947 | case BFD_RELOC_THUMB_PCREL_BLX: | |
22948 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
22949 | return 1; | |
22950 | break; | |
22951 | ||
22952 | case BFD_RELOC_ARM_PCREL_BLX: | |
22953 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
22954 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
22955 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
22956 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
22957 | return 1; | |
22958 | break; | |
22959 | ||
22960 | default: | |
22961 | break; | |
22962 | } | |
22963 | #endif | |
22964 | ||
b5884301 PB |
22965 | /* Resolve these relocations even if the symbol is extern or weak. |
22966 | Technically this is probably wrong due to symbol preemption. | |
22967 | In practice these relocations do not have enough range to be useful | |
22968 | at dynamic link time, and some code (e.g. in the Linux kernel) | |
22969 | expects these references to be resolved. */ | |
c19d1205 ZW |
22970 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
22971 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 22972 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 22973 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
22974 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
22975 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2 | |
22976 | || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET | |
16805f35 | 22977 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
22978 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
22979 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
22980 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM |
22981 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12 | |
22982 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM | |
22983 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2) | |
c19d1205 | 22984 | return 0; |
a737bd4d | 22985 | |
4962c51a MS |
22986 | /* Always leave these relocations for the linker. */ |
22987 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
22988 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
22989 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
22990 | return 1; | |
22991 | ||
f0291e4c PB |
22992 | /* Always generate relocations against function symbols. */ |
22993 | if (fixp->fx_r_type == BFD_RELOC_32 | |
22994 | && fixp->fx_addsy | |
22995 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
22996 | return 1; | |
22997 | ||
c19d1205 | 22998 | return generic_force_reloc (fixp); |
404ff6b5 AH |
22999 | } |
23000 | ||
0ffdc86c | 23001 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
23002 | /* Relocations against function names must be left unadjusted, |
23003 | so that the linker can use this information to generate interworking | |
23004 | stubs. The MIPS version of this function | |
c19d1205 ZW |
23005 | also prevents relocations that are mips-16 specific, but I do not |
23006 | know why it does this. | |
404ff6b5 | 23007 | |
c19d1205 ZW |
23008 | FIXME: |
23009 | There is one other problem that ought to be addressed here, but | |
23010 | which currently is not: Taking the address of a label (rather | |
23011 | than a function) and then later jumping to that address. Such | |
23012 | addresses also ought to have their bottom bit set (assuming that | |
23013 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 23014 | |
c19d1205 ZW |
23015 | bfd_boolean |
23016 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 23017 | { |
c19d1205 ZW |
23018 | if (fixP->fx_addsy == NULL) |
23019 | return 1; | |
404ff6b5 | 23020 | |
e28387c3 PB |
23021 | /* Preserve relocations against symbols with function type. */ |
23022 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 23023 | return FALSE; |
e28387c3 | 23024 | |
c19d1205 ZW |
23025 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
23026 | && fixP->fx_subsy == NULL) | |
c921be7d | 23027 | return FALSE; |
a737bd4d | 23028 | |
c19d1205 ZW |
23029 | /* We need the symbol name for the VTABLE entries. */ |
23030 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
23031 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 23032 | return FALSE; |
404ff6b5 | 23033 | |
c19d1205 ZW |
23034 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
23035 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
23036 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
23037 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
23038 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
23039 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
23040 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
23041 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
23042 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
0855e32b NS |
23043 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC |
23044 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL | |
23045 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL | |
23046 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ | |
23047 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
c19d1205 | 23048 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
c921be7d | 23049 | return FALSE; |
a737bd4d | 23050 | |
4962c51a MS |
23051 | /* Similarly for group relocations. */ |
23052 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
23053 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
23054 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 23055 | return FALSE; |
4962c51a | 23056 | |
79947c54 CD |
23057 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
23058 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
23059 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
23060 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
23061 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
23062 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
23063 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
23064 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
23065 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 23066 | return FALSE; |
79947c54 | 23067 | |
c921be7d | 23068 | return TRUE; |
a737bd4d | 23069 | } |
0ffdc86c NC |
23070 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
23071 | ||
23072 | #ifdef OBJ_ELF | |
404ff6b5 | 23073 | |
c19d1205 ZW |
23074 | const char * |
23075 | elf32_arm_target_format (void) | |
404ff6b5 | 23076 | { |
c19d1205 ZW |
23077 | #ifdef TE_SYMBIAN |
23078 | return (target_big_endian | |
23079 | ? "elf32-bigarm-symbian" | |
23080 | : "elf32-littlearm-symbian"); | |
23081 | #elif defined (TE_VXWORKS) | |
23082 | return (target_big_endian | |
23083 | ? "elf32-bigarm-vxworks" | |
23084 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
23085 | #elif defined (TE_NACL) |
23086 | return (target_big_endian | |
23087 | ? "elf32-bigarm-nacl" | |
23088 | : "elf32-littlearm-nacl"); | |
c19d1205 ZW |
23089 | #else |
23090 | if (target_big_endian) | |
23091 | return "elf32-bigarm"; | |
23092 | else | |
23093 | return "elf32-littlearm"; | |
23094 | #endif | |
404ff6b5 AH |
23095 | } |
23096 | ||
c19d1205 ZW |
23097 | void |
23098 | armelf_frob_symbol (symbolS * symp, | |
23099 | int * puntp) | |
404ff6b5 | 23100 | { |
c19d1205 ZW |
23101 | elf_frob_symbol (symp, puntp); |
23102 | } | |
23103 | #endif | |
404ff6b5 | 23104 | |
c19d1205 | 23105 | /* MD interface: Finalization. */ |
a737bd4d | 23106 | |
c19d1205 ZW |
23107 | void |
23108 | arm_cleanup (void) | |
23109 | { | |
23110 | literal_pool * pool; | |
a737bd4d | 23111 | |
e07e6e58 NC |
23112 | /* Ensure that all the IT blocks are properly closed. */ |
23113 | check_it_blocks_finished (); | |
23114 | ||
c19d1205 ZW |
23115 | for (pool = list_of_pools; pool; pool = pool->next) |
23116 | { | |
5f4273c7 | 23117 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
23118 | subseg_set (pool->section, pool->sub_section); |
23119 | #ifdef OBJ_ELF | |
23120 | arm_elf_change_section (); | |
23121 | #endif | |
23122 | s_ltorg (0); | |
23123 | } | |
404ff6b5 AH |
23124 | } |
23125 | ||
cd000bff DJ |
23126 | #ifdef OBJ_ELF |
23127 | /* Remove any excess mapping symbols generated for alignment frags in | |
23128 | SEC. We may have created a mapping symbol before a zero byte | |
23129 | alignment; remove it if there's a mapping symbol after the | |
23130 | alignment. */ | |
23131 | static void | |
23132 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
23133 | void *dummy ATTRIBUTE_UNUSED) | |
23134 | { | |
23135 | segment_info_type *seginfo = seg_info (sec); | |
23136 | fragS *fragp; | |
23137 | ||
23138 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
23139 | return; | |
23140 | ||
23141 | for (fragp = seginfo->frchainP->frch_root; | |
23142 | fragp != NULL; | |
23143 | fragp = fragp->fr_next) | |
23144 | { | |
23145 | symbolS *sym = fragp->tc_frag_data.last_map; | |
23146 | fragS *next = fragp->fr_next; | |
23147 | ||
23148 | /* Variable-sized frags have been converted to fixed size by | |
23149 | this point. But if this was variable-sized to start with, | |
23150 | there will be a fixed-size frag after it. So don't handle | |
23151 | next == NULL. */ | |
23152 | if (sym == NULL || next == NULL) | |
23153 | continue; | |
23154 | ||
23155 | if (S_GET_VALUE (sym) < next->fr_address) | |
23156 | /* Not at the end of this frag. */ | |
23157 | continue; | |
23158 | know (S_GET_VALUE (sym) == next->fr_address); | |
23159 | ||
23160 | do | |
23161 | { | |
23162 | if (next->tc_frag_data.first_map != NULL) | |
23163 | { | |
23164 | /* Next frag starts with a mapping symbol. Discard this | |
23165 | one. */ | |
23166 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
23167 | break; | |
23168 | } | |
23169 | ||
23170 | if (next->fr_next == NULL) | |
23171 | { | |
23172 | /* This mapping symbol is at the end of the section. Discard | |
23173 | it. */ | |
23174 | know (next->fr_fix == 0 && next->fr_var == 0); | |
23175 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
23176 | break; | |
23177 | } | |
23178 | ||
23179 | /* As long as we have empty frags without any mapping symbols, | |
23180 | keep looking. */ | |
23181 | /* If the next frag is non-empty and does not start with a | |
23182 | mapping symbol, then this mapping symbol is required. */ | |
23183 | if (next->fr_address != next->fr_next->fr_address) | |
23184 | break; | |
23185 | ||
23186 | next = next->fr_next; | |
23187 | } | |
23188 | while (next != NULL); | |
23189 | } | |
23190 | } | |
23191 | #endif | |
23192 | ||
c19d1205 ZW |
23193 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
23194 | ARM ones. */ | |
404ff6b5 | 23195 | |
c19d1205 ZW |
23196 | void |
23197 | arm_adjust_symtab (void) | |
404ff6b5 | 23198 | { |
c19d1205 ZW |
23199 | #ifdef OBJ_COFF |
23200 | symbolS * sym; | |
404ff6b5 | 23201 | |
c19d1205 ZW |
23202 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
23203 | { | |
23204 | if (ARM_IS_THUMB (sym)) | |
23205 | { | |
23206 | if (THUMB_IS_FUNC (sym)) | |
23207 | { | |
23208 | /* Mark the symbol as a Thumb function. */ | |
23209 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
23210 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
23211 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 23212 | |
c19d1205 ZW |
23213 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
23214 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
23215 | else | |
23216 | as_bad (_("%s: unexpected function type: %d"), | |
23217 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
23218 | } | |
23219 | else switch (S_GET_STORAGE_CLASS (sym)) | |
23220 | { | |
23221 | case C_EXT: | |
23222 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
23223 | break; | |
23224 | case C_STAT: | |
23225 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
23226 | break; | |
23227 | case C_LABEL: | |
23228 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
23229 | break; | |
23230 | default: | |
23231 | /* Do nothing. */ | |
23232 | break; | |
23233 | } | |
23234 | } | |
a737bd4d | 23235 | |
c19d1205 ZW |
23236 | if (ARM_IS_INTERWORK (sym)) |
23237 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 23238 | } |
c19d1205 ZW |
23239 | #endif |
23240 | #ifdef OBJ_ELF | |
23241 | symbolS * sym; | |
23242 | char bind; | |
404ff6b5 | 23243 | |
c19d1205 | 23244 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 23245 | { |
c19d1205 ZW |
23246 | if (ARM_IS_THUMB (sym)) |
23247 | { | |
23248 | elf_symbol_type * elf_sym; | |
404ff6b5 | 23249 | |
c19d1205 ZW |
23250 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
23251 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 23252 | |
b0796911 PB |
23253 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
23254 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
23255 | { |
23256 | /* If it's a .thumb_func, declare it as so, | |
23257 | otherwise tag label as .code 16. */ | |
23258 | if (THUMB_IS_FUNC (sym)) | |
35fc36a8 RS |
23259 | elf_sym->internal_elf_sym.st_target_internal |
23260 | = ST_BRANCH_TO_THUMB; | |
3ba67470 | 23261 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
23262 | elf_sym->internal_elf_sym.st_info = |
23263 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
23264 | } | |
23265 | } | |
23266 | } | |
cd000bff DJ |
23267 | |
23268 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
23269 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
23270 | /* Now do generic ELF adjustments. */ |
23271 | elf_adjust_symtab (); | |
c19d1205 | 23272 | #endif |
404ff6b5 AH |
23273 | } |
23274 | ||
c19d1205 | 23275 | /* MD interface: Initialization. */ |
404ff6b5 | 23276 | |
a737bd4d | 23277 | static void |
c19d1205 | 23278 | set_constant_flonums (void) |
a737bd4d | 23279 | { |
c19d1205 | 23280 | int i; |
404ff6b5 | 23281 | |
c19d1205 ZW |
23282 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
23283 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
23284 | abort (); | |
a737bd4d | 23285 | } |
404ff6b5 | 23286 | |
3e9e4fcf JB |
23287 | /* Auto-select Thumb mode if it's the only available instruction set for the |
23288 | given architecture. */ | |
23289 | ||
23290 | static void | |
23291 | autoselect_thumb_from_cpu_variant (void) | |
23292 | { | |
23293 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
23294 | opcode_select (16); | |
23295 | } | |
23296 | ||
c19d1205 ZW |
23297 | void |
23298 | md_begin (void) | |
a737bd4d | 23299 | { |
c19d1205 ZW |
23300 | unsigned mach; |
23301 | unsigned int i; | |
404ff6b5 | 23302 | |
c19d1205 ZW |
23303 | if ( (arm_ops_hsh = hash_new ()) == NULL |
23304 | || (arm_cond_hsh = hash_new ()) == NULL | |
23305 | || (arm_shift_hsh = hash_new ()) == NULL | |
23306 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 23307 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 23308 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
23309 | || (arm_reloc_hsh = hash_new ()) == NULL |
23310 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
23311 | as_fatal (_("virtual memory exhausted")); |
23312 | ||
23313 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 23314 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 23315 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 23316 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 23317 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 23318 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 23319 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 23320 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 23321 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 NC |
23322 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
23323 | (void *) (v7m_psrs + i)); | |
c19d1205 | 23324 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 23325 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
23326 | for (i = 0; |
23327 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
23328 | i++) | |
d3ce72d0 | 23329 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 23330 | (void *) (barrier_opt_names + i)); |
c19d1205 | 23331 | #ifdef OBJ_ELF |
3da1d841 NC |
23332 | for (i = 0; i < ARRAY_SIZE (reloc_names); i++) |
23333 | { | |
23334 | struct reloc_entry * entry = reloc_names + i; | |
23335 | ||
23336 | if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32) | |
23337 | /* This makes encode_branch() use the EABI versions of this relocation. */ | |
23338 | entry->reloc = BFD_RELOC_UNUSED; | |
23339 | ||
23340 | hash_insert (arm_reloc_hsh, entry->name, (void *) entry); | |
23341 | } | |
c19d1205 ZW |
23342 | #endif |
23343 | ||
23344 | set_constant_flonums (); | |
404ff6b5 | 23345 | |
c19d1205 ZW |
23346 | /* Set the cpu variant based on the command-line options. We prefer |
23347 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
23348 | -mfpu= over any other way of setting the floating point unit. | |
23349 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 23350 | if (legacy_cpu) |
404ff6b5 | 23351 | { |
e74cfd16 | 23352 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
23353 | as_bad (_("use of old and new-style options to set CPU type")); |
23354 | ||
23355 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 23356 | } |
e74cfd16 | 23357 | else if (!mcpu_cpu_opt) |
c19d1205 | 23358 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 23359 | |
e74cfd16 | 23360 | if (legacy_fpu) |
c19d1205 | 23361 | { |
e74cfd16 | 23362 | if (mfpu_opt) |
c19d1205 | 23363 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
23364 | |
23365 | mfpu_opt = legacy_fpu; | |
23366 | } | |
e74cfd16 | 23367 | else if (!mfpu_opt) |
03b1477f | 23368 | { |
45eb4c1b NS |
23369 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
23370 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
23371 | /* Some environments specify a default FPU. If they don't, infer it |
23372 | from the processor. */ | |
e74cfd16 | 23373 | if (mcpu_fpu_opt) |
03b1477f RE |
23374 | mfpu_opt = mcpu_fpu_opt; |
23375 | else | |
23376 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 23377 | #else |
e74cfd16 | 23378 | mfpu_opt = &fpu_default; |
39c2da32 | 23379 | #endif |
03b1477f RE |
23380 | } |
23381 | ||
e74cfd16 | 23382 | if (!mfpu_opt) |
03b1477f | 23383 | { |
493cb6ef | 23384 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 23385 | mfpu_opt = &fpu_default; |
493cb6ef | 23386 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 23387 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 23388 | else |
e74cfd16 | 23389 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
23390 | } |
23391 | ||
ee065d83 | 23392 | #ifdef CPU_DEFAULT |
e74cfd16 | 23393 | if (!mcpu_cpu_opt) |
ee065d83 | 23394 | { |
e74cfd16 PB |
23395 | mcpu_cpu_opt = &cpu_default; |
23396 | selected_cpu = cpu_default; | |
ee065d83 | 23397 | } |
e74cfd16 PB |
23398 | #else |
23399 | if (mcpu_cpu_opt) | |
23400 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 23401 | else |
e74cfd16 | 23402 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 23403 | #endif |
03b1477f | 23404 | |
e74cfd16 | 23405 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 23406 | |
3e9e4fcf JB |
23407 | autoselect_thumb_from_cpu_variant (); |
23408 | ||
e74cfd16 | 23409 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 23410 | |
f17c130b | 23411 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 23412 | { |
7cc69913 NC |
23413 | unsigned int flags = 0; |
23414 | ||
23415 | #if defined OBJ_ELF | |
23416 | flags = meabi_flags; | |
d507cf36 PB |
23417 | |
23418 | switch (meabi_flags) | |
33a392fb | 23419 | { |
d507cf36 | 23420 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 23421 | #endif |
d507cf36 PB |
23422 | /* Set the flags in the private structure. */ |
23423 | if (uses_apcs_26) flags |= F_APCS26; | |
23424 | if (support_interwork) flags |= F_INTERWORK; | |
23425 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 23426 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 23427 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
23428 | flags |= F_SOFT_FLOAT; |
23429 | ||
d507cf36 PB |
23430 | switch (mfloat_abi_opt) |
23431 | { | |
23432 | case ARM_FLOAT_ABI_SOFT: | |
23433 | case ARM_FLOAT_ABI_SOFTFP: | |
23434 | flags |= F_SOFT_FLOAT; | |
23435 | break; | |
33a392fb | 23436 | |
d507cf36 PB |
23437 | case ARM_FLOAT_ABI_HARD: |
23438 | if (flags & F_SOFT_FLOAT) | |
23439 | as_bad (_("hard-float conflicts with specified fpu")); | |
23440 | break; | |
23441 | } | |
03b1477f | 23442 | |
e74cfd16 PB |
23443 | /* Using pure-endian doubles (even if soft-float). */ |
23444 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 23445 | flags |= F_VFP_FLOAT; |
f17c130b | 23446 | |
fde78edd | 23447 | #if defined OBJ_ELF |
e74cfd16 | 23448 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 23449 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
23450 | break; |
23451 | ||
8cb51566 | 23452 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 23453 | case EF_ARM_EABI_VER5: |
c19d1205 | 23454 | /* No additional flags to set. */ |
d507cf36 PB |
23455 | break; |
23456 | ||
23457 | default: | |
23458 | abort (); | |
23459 | } | |
7cc69913 | 23460 | #endif |
b99bd4ef NC |
23461 | bfd_set_private_flags (stdoutput, flags); |
23462 | ||
23463 | /* We have run out flags in the COFF header to encode the | |
23464 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 23465 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
23466 | if (atpcs) |
23467 | { | |
23468 | asection * sec; | |
23469 | ||
23470 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
23471 | ||
23472 | if (sec != NULL) | |
23473 | { | |
23474 | bfd_set_section_flags | |
23475 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
23476 | bfd_set_section_size (stdoutput, sec, 0); | |
23477 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
23478 | } | |
23479 | } | |
7cc69913 | 23480 | } |
f17c130b | 23481 | #endif |
b99bd4ef NC |
23482 | |
23483 | /* Record the CPU type as well. */ | |
2d447fca JM |
23484 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
23485 | mach = bfd_mach_arm_iWMMXt2; | |
23486 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 23487 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 23488 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 23489 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 23490 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 23491 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 23492 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 23493 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 23494 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 23495 | { |
e74cfd16 | 23496 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
23497 | mach = bfd_mach_arm_5T; |
23498 | else | |
23499 | mach = bfd_mach_arm_5; | |
23500 | } | |
e74cfd16 | 23501 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 23502 | { |
e74cfd16 | 23503 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
23504 | mach = bfd_mach_arm_4T; |
23505 | else | |
23506 | mach = bfd_mach_arm_4; | |
23507 | } | |
e74cfd16 | 23508 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 23509 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
23510 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
23511 | mach = bfd_mach_arm_3; | |
23512 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
23513 | mach = bfd_mach_arm_2a; | |
23514 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
23515 | mach = bfd_mach_arm_2; | |
23516 | else | |
23517 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
23518 | |
23519 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
23520 | } | |
23521 | ||
c19d1205 | 23522 | /* Command line processing. */ |
b99bd4ef | 23523 | |
c19d1205 ZW |
23524 | /* md_parse_option |
23525 | Invocation line includes a switch not recognized by the base assembler. | |
23526 | See if it's a processor-specific option. | |
b99bd4ef | 23527 | |
c19d1205 ZW |
23528 | This routine is somewhat complicated by the need for backwards |
23529 | compatibility (since older releases of gcc can't be changed). | |
23530 | The new options try to make the interface as compatible as | |
23531 | possible with GCC. | |
b99bd4ef | 23532 | |
c19d1205 | 23533 | New options (supported) are: |
b99bd4ef | 23534 | |
c19d1205 ZW |
23535 | -mcpu=<cpu name> Assemble for selected processor |
23536 | -march=<architecture name> Assemble for selected architecture | |
23537 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
23538 | -EB/-mbig-endian Big-endian | |
23539 | -EL/-mlittle-endian Little-endian | |
23540 | -k Generate PIC code | |
23541 | -mthumb Start in Thumb mode | |
23542 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 23543 | |
278df34e | 23544 | -m[no-]warn-deprecated Warn about deprecated features |
267bf995 | 23545 | |
c19d1205 | 23546 | For now we will also provide support for: |
b99bd4ef | 23547 | |
c19d1205 ZW |
23548 | -mapcs-32 32-bit Program counter |
23549 | -mapcs-26 26-bit Program counter | |
23550 | -macps-float Floats passed in FP registers | |
23551 | -mapcs-reentrant Reentrant code | |
23552 | -matpcs | |
23553 | (sometime these will probably be replaced with -mapcs=<list of options> | |
23554 | and -matpcs=<list of options>) | |
b99bd4ef | 23555 | |
c19d1205 ZW |
23556 | The remaining options are only supported for back-wards compatibility. |
23557 | Cpu variants, the arm part is optional: | |
23558 | -m[arm]1 Currently not supported. | |
23559 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
23560 | -m[arm]3 Arm 3 processor | |
23561 | -m[arm]6[xx], Arm 6 processors | |
23562 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
23563 | -m[arm]8[10] Arm 8 processors | |
23564 | -m[arm]9[20][tdmi] Arm 9 processors | |
23565 | -mstrongarm[110[0]] StrongARM processors | |
23566 | -mxscale XScale processors | |
23567 | -m[arm]v[2345[t[e]]] Arm architectures | |
23568 | -mall All (except the ARM1) | |
23569 | FP variants: | |
23570 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
23571 | -mfpe-old (No float load/store multiples) | |
23572 | -mvfpxd VFP Single precision | |
23573 | -mvfp All VFP | |
23574 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 23575 | |
c19d1205 ZW |
23576 | The following CPU names are recognized: |
23577 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
23578 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
23579 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
23580 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
23581 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
23582 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
23583 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 23584 | |
c19d1205 | 23585 | */ |
b99bd4ef | 23586 | |
c19d1205 | 23587 | const char * md_shortopts = "m:k"; |
b99bd4ef | 23588 | |
c19d1205 ZW |
23589 | #ifdef ARM_BI_ENDIAN |
23590 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
23591 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 23592 | #else |
c19d1205 ZW |
23593 | #if TARGET_BYTES_BIG_ENDIAN |
23594 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 23595 | #else |
c19d1205 ZW |
23596 | #define OPTION_EL (OPTION_MD_BASE + 1) |
23597 | #endif | |
b99bd4ef | 23598 | #endif |
845b51d6 | 23599 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 23600 | |
c19d1205 | 23601 | struct option md_longopts[] = |
b99bd4ef | 23602 | { |
c19d1205 ZW |
23603 | #ifdef OPTION_EB |
23604 | {"EB", no_argument, NULL, OPTION_EB}, | |
23605 | #endif | |
23606 | #ifdef OPTION_EL | |
23607 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 23608 | #endif |
845b51d6 | 23609 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
23610 | {NULL, no_argument, NULL, 0} |
23611 | }; | |
b99bd4ef | 23612 | |
c19d1205 | 23613 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 23614 | |
c19d1205 | 23615 | struct arm_option_table |
b99bd4ef | 23616 | { |
c19d1205 ZW |
23617 | char *option; /* Option name to match. */ |
23618 | char *help; /* Help information. */ | |
23619 | int *var; /* Variable to change. */ | |
23620 | int value; /* What to change it to. */ | |
23621 | char *deprecated; /* If non-null, print this message. */ | |
23622 | }; | |
b99bd4ef | 23623 | |
c19d1205 ZW |
23624 | struct arm_option_table arm_opts[] = |
23625 | { | |
23626 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
23627 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
23628 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
23629 | &support_interwork, 1, NULL}, | |
23630 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
23631 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
23632 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
23633 | 1, NULL}, | |
23634 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
23635 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
23636 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
23637 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
23638 | NULL}, | |
b99bd4ef | 23639 | |
c19d1205 ZW |
23640 | /* These are recognized by the assembler, but have no affect on code. */ |
23641 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
23642 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
23643 | |
23644 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
23645 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
23646 | &warn_on_deprecated, 0, NULL}, | |
e74cfd16 PB |
23647 | {NULL, NULL, NULL, 0, NULL} |
23648 | }; | |
23649 | ||
23650 | struct arm_legacy_option_table | |
23651 | { | |
23652 | char *option; /* Option name to match. */ | |
23653 | const arm_feature_set **var; /* Variable to change. */ | |
23654 | const arm_feature_set value; /* What to change it to. */ | |
23655 | char *deprecated; /* If non-null, print this message. */ | |
23656 | }; | |
b99bd4ef | 23657 | |
e74cfd16 PB |
23658 | const struct arm_legacy_option_table arm_legacy_opts[] = |
23659 | { | |
c19d1205 ZW |
23660 | /* DON'T add any new processors to this list -- we want the whole list |
23661 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
23662 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
23663 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
23664 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
23665 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
23666 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
23667 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
23668 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
23669 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
23670 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
23671 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
23672 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
23673 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
23674 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
23675 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
23676 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
23677 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
23678 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
23679 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
23680 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
23681 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
23682 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
23683 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
23684 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
23685 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
23686 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
23687 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
23688 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
23689 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
23690 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
23691 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
23692 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
23693 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
23694 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
23695 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
23696 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
23697 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
23698 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
23699 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
23700 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
23701 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
23702 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
23703 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
23704 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
23705 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
23706 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
23707 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
23708 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
23709 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
23710 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
23711 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
23712 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
23713 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
23714 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
23715 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
23716 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
23717 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
23718 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
23719 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
23720 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
23721 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
23722 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
23723 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
23724 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
23725 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
23726 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
23727 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
23728 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
23729 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
23730 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
23731 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 23732 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 23733 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 23734 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 23735 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 23736 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
23737 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
23738 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
23739 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 23740 | |
c19d1205 | 23741 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
23742 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
23743 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
23744 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
23745 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
23746 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
23747 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
23748 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
23749 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
23750 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
23751 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
23752 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
23753 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
23754 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
23755 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
23756 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
23757 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
23758 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
23759 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 23760 | |
c19d1205 | 23761 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
23762 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
23763 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
23764 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
23765 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 23766 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 23767 | |
e74cfd16 | 23768 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 23769 | }; |
7ed4c4c5 | 23770 | |
c19d1205 | 23771 | struct arm_cpu_option_table |
7ed4c4c5 | 23772 | { |
c19d1205 | 23773 | char *name; |
f3bad469 | 23774 | size_t name_len; |
e74cfd16 | 23775 | const arm_feature_set value; |
c19d1205 ZW |
23776 | /* For some CPUs we assume an FPU unless the user explicitly sets |
23777 | -mfpu=... */ | |
e74cfd16 | 23778 | const arm_feature_set default_fpu; |
ee065d83 PB |
23779 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
23780 | case. */ | |
23781 | const char *canonical_name; | |
c19d1205 | 23782 | }; |
7ed4c4c5 | 23783 | |
c19d1205 ZW |
23784 | /* This list should, at a minimum, contain all the cpu names |
23785 | recognized by GCC. */ | |
f3bad469 | 23786 | #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN } |
e74cfd16 | 23787 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 23788 | { |
f3bad469 MGD |
23789 | ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL), |
23790 | ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL), | |
23791 | ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL), | |
23792 | ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL), | |
23793 | ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL), | |
23794 | ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23795 | ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23796 | ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23797 | ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23798 | ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23799 | ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23800 | ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
23801 | ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23802 | ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
23803 | ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23804 | ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
23805 | ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23806 | ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23807 | ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23808 | ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23809 | ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23810 | ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23811 | ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23812 | ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23813 | ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23814 | ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23815 | ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23816 | ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
23817 | ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23818 | ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23819 | ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23820 | ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23821 | ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23822 | ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23823 | ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23824 | ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23825 | ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23826 | ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23827 | ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23828 | ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"), | |
23829 | ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23830 | ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23831 | ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23832 | ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
23833 | ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
23834 | ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
c19d1205 ZW |
23835 | /* For V5 or later processors we default to using VFP; but the user |
23836 | should really set the FPU type explicitly. */ | |
f3bad469 MGD |
23837 | ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), |
23838 | ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23839 | ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"), | |
23840 | ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"), | |
23841 | ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL), | |
23842 | ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), | |
23843 | ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"), | |
23844 | ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23845 | ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), | |
23846 | ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"), | |
23847 | ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23848 | ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23849 | ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
23850 | ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
23851 | ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23852 | ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"), | |
23853 | ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
23854 | ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23855 | ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23856 | ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, | |
23857 | "ARM1026EJ-S"), | |
23858 | ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL), | |
23859 | ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23860 | ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23861 | ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23862 | ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23863 | ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
23864 | ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"), | |
23865 | ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL), | |
23866 | ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, | |
23867 | "ARM1136JF-S"), | |
23868 | ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL), | |
23869 | ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"), | |
23870 | ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"), | |
23871 | ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL), | |
23872 | ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL), | |
23873 | ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL), | |
23874 | ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL), | |
23875 | ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC, | |
23876 | FPU_NONE, "Cortex-A5"), | |
23877 | ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT, | |
23878 | FPU_ARCH_NEON_VFP_V4, | |
23879 | "Cortex-A7"), | |
23880 | ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC, | |
23881 | ARM_FEATURE (0, FPU_VFP_V3 | |
5287ad62 | 23882 | | FPU_NEON_EXT_V1), |
f3bad469 MGD |
23883 | "Cortex-A8"), |
23884 | ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC, | |
23885 | ARM_FEATURE (0, FPU_VFP_V3 | |
15290f0a | 23886 | | FPU_NEON_EXT_V1), |
f3bad469 MGD |
23887 | "Cortex-A9"), |
23888 | ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT, | |
23889 | FPU_ARCH_NEON_VFP_V4, | |
23890 | "Cortex-A15"), | |
23891 | ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"), | |
23892 | ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, | |
23893 | "Cortex-R4F"), | |
23894 | ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV, | |
23895 | FPU_NONE, "Cortex-R5"), | |
70a8bc5b | 23896 | ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV, |
23897 | FPU_ARCH_VFP_V3D16, | |
23898 | "Cortex-R7"), | |
f3bad469 MGD |
23899 | ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"), |
23900 | ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"), | |
23901 | ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"), | |
23902 | ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"), | |
ce32bd10 | 23903 | ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"), |
c19d1205 | 23904 | /* ??? XSCALE is really an architecture. */ |
f3bad469 | 23905 | ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL), |
c19d1205 | 23906 | /* ??? iwmmxt is not a processor. */ |
f3bad469 MGD |
23907 | ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL), |
23908 | ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL), | |
23909 | ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL), | |
c19d1205 | 23910 | /* Maverick */ |
f3bad469 | 23911 | ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), |
da4339ed NC |
23912 | FPU_ARCH_MAVERICK, "ARM920T"), |
23913 | /* Marvell processors. */ | |
4a81b02a | 23914 | ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE (ARM_AEXT_V7A | ARM_EXT_MP | ARM_EXT_SEC, 0), |
da4339ed NC |
23915 | FPU_ARCH_VFP_V3D16, NULL), |
23916 | ||
f3bad469 | 23917 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 23918 | }; |
f3bad469 | 23919 | #undef ARM_CPU_OPT |
7ed4c4c5 | 23920 | |
c19d1205 | 23921 | struct arm_arch_option_table |
7ed4c4c5 | 23922 | { |
c19d1205 | 23923 | char *name; |
f3bad469 | 23924 | size_t name_len; |
e74cfd16 PB |
23925 | const arm_feature_set value; |
23926 | const arm_feature_set default_fpu; | |
c19d1205 | 23927 | }; |
7ed4c4c5 | 23928 | |
c19d1205 ZW |
23929 | /* This list should, at a minimum, contain all the architecture names |
23930 | recognized by GCC. */ | |
f3bad469 | 23931 | #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF } |
e74cfd16 | 23932 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 23933 | { |
f3bad469 MGD |
23934 | ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA), |
23935 | ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA), | |
23936 | ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA), | |
23937 | ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
23938 | ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
23939 | ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA), | |
23940 | ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA), | |
23941 | ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA), | |
23942 | ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA), | |
23943 | ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA), | |
23944 | ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA), | |
23945 | ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP), | |
23946 | ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP), | |
23947 | ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP), | |
23948 | ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP), | |
23949 | ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP), | |
23950 | ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP), | |
23951 | ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP), | |
23952 | ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP), | |
23953 | ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP), | |
23954 | ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP), | |
23955 | ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP), | |
23956 | ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP), | |
23957 | ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP), | |
23958 | ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP), | |
23959 | ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP), | |
23960 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), | |
23961 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
23962 | ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP), | |
c450d570 PB |
23963 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
23964 | Accept the non-dashed form for compatibility with old toolchains. */ | |
f3bad469 MGD |
23965 | ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP), |
23966 | ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP), | |
23967 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), | |
23968 | ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP), | |
23969 | ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP), | |
23970 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), | |
23971 | ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP), | |
bca38921 | 23972 | ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP), |
f3bad469 MGD |
23973 | ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP), |
23974 | ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP), | |
23975 | ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP), | |
23976 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
c19d1205 | 23977 | }; |
f3bad469 | 23978 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 23979 | |
69133863 MGD |
23980 | /* ISA extensions in the co-processor and main instruction set space. */ |
23981 | struct arm_option_extension_value_table | |
c19d1205 ZW |
23982 | { |
23983 | char *name; | |
f3bad469 | 23984 | size_t name_len; |
e74cfd16 | 23985 | const arm_feature_set value; |
69133863 | 23986 | const arm_feature_set allowed_archs; |
c19d1205 | 23987 | }; |
7ed4c4c5 | 23988 | |
69133863 MGD |
23989 | /* The following table must be in alphabetical order with a NULL last entry. |
23990 | */ | |
f3bad469 | 23991 | #define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA } |
69133863 | 23992 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 23993 | { |
bca38921 MGD |
23994 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
23995 | ARM_FEATURE (ARM_EXT_V8, 0)), | |
23996 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, | |
23997 | ARM_FEATURE (ARM_EXT_V8, 0)), | |
f3bad469 MGD |
23998 | ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0), |
23999 | ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)), | |
24000 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY), | |
24001 | ARM_EXT_OPT ("iwmmxt2", | |
24002 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY), | |
24003 | ARM_EXT_OPT ("maverick", | |
24004 | ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY), | |
24005 | ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0), | |
24006 | ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)), | |
bca38921 MGD |
24007 | ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8, |
24008 | ARM_FEATURE (ARM_EXT_V8, 0)), | |
f3bad469 MGD |
24009 | ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0), |
24010 | ARM_FEATURE (ARM_EXT_V6M, 0)), | |
24011 | ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0), | |
24012 | ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)), | |
24013 | ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | |
24014 | | ARM_EXT_DIV, 0), | |
24015 | ARM_FEATURE (ARM_EXT_V7A, 0)), | |
24016 | ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY), | |
24017 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
69133863 | 24018 | }; |
f3bad469 | 24019 | #undef ARM_EXT_OPT |
69133863 MGD |
24020 | |
24021 | /* ISA floating-point and Advanced SIMD extensions. */ | |
24022 | struct arm_option_fpu_value_table | |
24023 | { | |
24024 | char *name; | |
24025 | const arm_feature_set value; | |
c19d1205 | 24026 | }; |
7ed4c4c5 | 24027 | |
c19d1205 ZW |
24028 | /* This list should, at a minimum, contain all the fpu names |
24029 | recognized by GCC. */ | |
69133863 | 24030 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
24031 | { |
24032 | {"softfpa", FPU_NONE}, | |
24033 | {"fpe", FPU_ARCH_FPE}, | |
24034 | {"fpe2", FPU_ARCH_FPE}, | |
24035 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
24036 | {"fpa", FPU_ARCH_FPA}, | |
24037 | {"fpa10", FPU_ARCH_FPA}, | |
24038 | {"fpa11", FPU_ARCH_FPA}, | |
24039 | {"arm7500fe", FPU_ARCH_FPA}, | |
24040 | {"softvfp", FPU_ARCH_VFP}, | |
24041 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
24042 | {"vfp", FPU_ARCH_VFP_V2}, | |
24043 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 24044 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
24045 | {"vfp10", FPU_ARCH_VFP_V2}, |
24046 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
24047 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
24048 | {"vfpv2", FPU_ARCH_VFP_V2}, |
24049 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 24050 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 24051 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
24052 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
24053 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
24054 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
24055 | {"arm1020t", FPU_ARCH_VFP_V1}, |
24056 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
24057 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
24058 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
24059 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 24060 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 24061 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
24062 | {"vfpv4", FPU_ARCH_VFP_V4}, |
24063 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 24064 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
62f3b8c8 | 24065 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
24066 | {"fp-armv8", FPU_ARCH_VFP_ARMV8}, |
24067 | {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8}, | |
24068 | {"crypto-neon-fp-armv8", | |
24069 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8}, | |
e74cfd16 PB |
24070 | {NULL, ARM_ARCH_NONE} |
24071 | }; | |
24072 | ||
24073 | struct arm_option_value_table | |
24074 | { | |
24075 | char *name; | |
24076 | long value; | |
c19d1205 | 24077 | }; |
7ed4c4c5 | 24078 | |
e74cfd16 | 24079 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
24080 | { |
24081 | {"hard", ARM_FLOAT_ABI_HARD}, | |
24082 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
24083 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 24084 | {NULL, 0} |
c19d1205 | 24085 | }; |
7ed4c4c5 | 24086 | |
c19d1205 | 24087 | #ifdef OBJ_ELF |
3a4a14e9 | 24088 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 24089 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
24090 | { |
24091 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
24092 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 24093 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 24094 | {NULL, 0} |
c19d1205 ZW |
24095 | }; |
24096 | #endif | |
7ed4c4c5 | 24097 | |
c19d1205 ZW |
24098 | struct arm_long_option_table |
24099 | { | |
24100 | char * option; /* Substring to match. */ | |
24101 | char * help; /* Help information. */ | |
24102 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
24103 | char * deprecated; /* If non-null, print this message. */ | |
24104 | }; | |
7ed4c4c5 | 24105 | |
c921be7d | 24106 | static bfd_boolean |
f3bad469 | 24107 | arm_parse_extension (char *str, const arm_feature_set **opt_p) |
7ed4c4c5 | 24108 | { |
21d799b5 NC |
24109 | arm_feature_set *ext_set = (arm_feature_set *) |
24110 | xmalloc (sizeof (arm_feature_set)); | |
e74cfd16 | 24111 | |
69133863 | 24112 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
24113 | extensions being added before being removed. We achieve this by having |
24114 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 24115 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 24116 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
24117 | -1 -> 1 -> 0. */ |
24118 | const struct arm_option_extension_value_table * opt = NULL; | |
24119 | int adding_value = -1; | |
24120 | ||
e74cfd16 PB |
24121 | /* Copy the feature set, so that we can modify it. */ |
24122 | *ext_set = **opt_p; | |
24123 | *opt_p = ext_set; | |
24124 | ||
c19d1205 | 24125 | while (str != NULL && *str != 0) |
7ed4c4c5 | 24126 | { |
f3bad469 MGD |
24127 | char *ext; |
24128 | size_t len; | |
7ed4c4c5 | 24129 | |
c19d1205 ZW |
24130 | if (*str != '+') |
24131 | { | |
24132 | as_bad (_("invalid architectural extension")); | |
c921be7d | 24133 | return FALSE; |
c19d1205 | 24134 | } |
7ed4c4c5 | 24135 | |
c19d1205 ZW |
24136 | str++; |
24137 | ext = strchr (str, '+'); | |
7ed4c4c5 | 24138 | |
c19d1205 | 24139 | if (ext != NULL) |
f3bad469 | 24140 | len = ext - str; |
c19d1205 | 24141 | else |
f3bad469 | 24142 | len = strlen (str); |
7ed4c4c5 | 24143 | |
f3bad469 | 24144 | if (len >= 2 && strncmp (str, "no", 2) == 0) |
69133863 MGD |
24145 | { |
24146 | if (adding_value != 0) | |
24147 | { | |
24148 | adding_value = 0; | |
24149 | opt = arm_extensions; | |
24150 | } | |
24151 | ||
f3bad469 | 24152 | len -= 2; |
69133863 MGD |
24153 | str += 2; |
24154 | } | |
f3bad469 | 24155 | else if (len > 0) |
69133863 MGD |
24156 | { |
24157 | if (adding_value == -1) | |
24158 | { | |
24159 | adding_value = 1; | |
24160 | opt = arm_extensions; | |
24161 | } | |
24162 | else if (adding_value != 1) | |
24163 | { | |
24164 | as_bad (_("must specify extensions to add before specifying " | |
24165 | "those to remove")); | |
24166 | return FALSE; | |
24167 | } | |
24168 | } | |
24169 | ||
f3bad469 | 24170 | if (len == 0) |
c19d1205 ZW |
24171 | { |
24172 | as_bad (_("missing architectural extension")); | |
c921be7d | 24173 | return FALSE; |
c19d1205 | 24174 | } |
7ed4c4c5 | 24175 | |
69133863 MGD |
24176 | gas_assert (adding_value != -1); |
24177 | gas_assert (opt != NULL); | |
24178 | ||
24179 | /* Scan over the options table trying to find an exact match. */ | |
24180 | for (; opt->name != NULL; opt++) | |
f3bad469 | 24181 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 24182 | { |
69133863 MGD |
24183 | /* Check we can apply the extension to this architecture. */ |
24184 | if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs)) | |
24185 | { | |
24186 | as_bad (_("extension does not apply to the base architecture")); | |
24187 | return FALSE; | |
24188 | } | |
24189 | ||
24190 | /* Add or remove the extension. */ | |
24191 | if (adding_value) | |
24192 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); | |
24193 | else | |
24194 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value); | |
24195 | ||
c19d1205 ZW |
24196 | break; |
24197 | } | |
7ed4c4c5 | 24198 | |
c19d1205 ZW |
24199 | if (opt->name == NULL) |
24200 | { | |
69133863 MGD |
24201 | /* Did we fail to find an extension because it wasn't specified in |
24202 | alphabetical order, or because it does not exist? */ | |
24203 | ||
24204 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
f3bad469 | 24205 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
24206 | break; |
24207 | ||
24208 | if (opt->name == NULL) | |
24209 | as_bad (_("unknown architectural extension `%s'"), str); | |
24210 | else | |
24211 | as_bad (_("architectural extensions must be specified in " | |
24212 | "alphabetical order")); | |
24213 | ||
c921be7d | 24214 | return FALSE; |
c19d1205 | 24215 | } |
69133863 MGD |
24216 | else |
24217 | { | |
24218 | /* We should skip the extension we've just matched the next time | |
24219 | round. */ | |
24220 | opt++; | |
24221 | } | |
7ed4c4c5 | 24222 | |
c19d1205 ZW |
24223 | str = ext; |
24224 | }; | |
7ed4c4c5 | 24225 | |
c921be7d | 24226 | return TRUE; |
c19d1205 | 24227 | } |
7ed4c4c5 | 24228 | |
c921be7d | 24229 | static bfd_boolean |
f3bad469 | 24230 | arm_parse_cpu (char *str) |
7ed4c4c5 | 24231 | { |
f3bad469 MGD |
24232 | const struct arm_cpu_option_table *opt; |
24233 | char *ext = strchr (str, '+'); | |
24234 | size_t len; | |
7ed4c4c5 | 24235 | |
c19d1205 | 24236 | if (ext != NULL) |
f3bad469 | 24237 | len = ext - str; |
7ed4c4c5 | 24238 | else |
f3bad469 | 24239 | len = strlen (str); |
7ed4c4c5 | 24240 | |
f3bad469 | 24241 | if (len == 0) |
7ed4c4c5 | 24242 | { |
c19d1205 | 24243 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 24244 | return FALSE; |
7ed4c4c5 NC |
24245 | } |
24246 | ||
c19d1205 | 24247 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 24248 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 24249 | { |
e74cfd16 PB |
24250 | mcpu_cpu_opt = &opt->value; |
24251 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 24252 | if (opt->canonical_name) |
5f4273c7 | 24253 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
24254 | else |
24255 | { | |
f3bad469 | 24256 | size_t i; |
c921be7d | 24257 | |
f3bad469 | 24258 | for (i = 0; i < len; i++) |
ee065d83 PB |
24259 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
24260 | selected_cpu_name[i] = 0; | |
24261 | } | |
7ed4c4c5 | 24262 | |
c19d1205 ZW |
24263 | if (ext != NULL) |
24264 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 24265 | |
c921be7d | 24266 | return TRUE; |
c19d1205 | 24267 | } |
7ed4c4c5 | 24268 | |
c19d1205 | 24269 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 24270 | return FALSE; |
7ed4c4c5 NC |
24271 | } |
24272 | ||
c921be7d | 24273 | static bfd_boolean |
f3bad469 | 24274 | arm_parse_arch (char *str) |
7ed4c4c5 | 24275 | { |
e74cfd16 | 24276 | const struct arm_arch_option_table *opt; |
c19d1205 | 24277 | char *ext = strchr (str, '+'); |
f3bad469 | 24278 | size_t len; |
7ed4c4c5 | 24279 | |
c19d1205 | 24280 | if (ext != NULL) |
f3bad469 | 24281 | len = ext - str; |
7ed4c4c5 | 24282 | else |
f3bad469 | 24283 | len = strlen (str); |
7ed4c4c5 | 24284 | |
f3bad469 | 24285 | if (len == 0) |
7ed4c4c5 | 24286 | { |
c19d1205 | 24287 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 24288 | return FALSE; |
7ed4c4c5 NC |
24289 | } |
24290 | ||
c19d1205 | 24291 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 24292 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 24293 | { |
e74cfd16 PB |
24294 | march_cpu_opt = &opt->value; |
24295 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 24296 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 24297 | |
c19d1205 ZW |
24298 | if (ext != NULL) |
24299 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 24300 | |
c921be7d | 24301 | return TRUE; |
c19d1205 ZW |
24302 | } |
24303 | ||
24304 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 24305 | return FALSE; |
7ed4c4c5 | 24306 | } |
eb043451 | 24307 | |
c921be7d | 24308 | static bfd_boolean |
c19d1205 ZW |
24309 | arm_parse_fpu (char * str) |
24310 | { | |
69133863 | 24311 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 24312 | |
c19d1205 ZW |
24313 | for (opt = arm_fpus; opt->name != NULL; opt++) |
24314 | if (streq (opt->name, str)) | |
24315 | { | |
e74cfd16 | 24316 | mfpu_opt = &opt->value; |
c921be7d | 24317 | return TRUE; |
c19d1205 | 24318 | } |
b99bd4ef | 24319 | |
c19d1205 | 24320 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 24321 | return FALSE; |
c19d1205 ZW |
24322 | } |
24323 | ||
c921be7d | 24324 | static bfd_boolean |
c19d1205 | 24325 | arm_parse_float_abi (char * str) |
b99bd4ef | 24326 | { |
e74cfd16 | 24327 | const struct arm_option_value_table * opt; |
b99bd4ef | 24328 | |
c19d1205 ZW |
24329 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
24330 | if (streq (opt->name, str)) | |
24331 | { | |
24332 | mfloat_abi_opt = opt->value; | |
c921be7d | 24333 | return TRUE; |
c19d1205 | 24334 | } |
cc8a6dd0 | 24335 | |
c19d1205 | 24336 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 24337 | return FALSE; |
c19d1205 | 24338 | } |
b99bd4ef | 24339 | |
c19d1205 | 24340 | #ifdef OBJ_ELF |
c921be7d | 24341 | static bfd_boolean |
c19d1205 ZW |
24342 | arm_parse_eabi (char * str) |
24343 | { | |
e74cfd16 | 24344 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 24345 | |
c19d1205 ZW |
24346 | for (opt = arm_eabis; opt->name != NULL; opt++) |
24347 | if (streq (opt->name, str)) | |
24348 | { | |
24349 | meabi_flags = opt->value; | |
c921be7d | 24350 | return TRUE; |
c19d1205 ZW |
24351 | } |
24352 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 24353 | return FALSE; |
c19d1205 ZW |
24354 | } |
24355 | #endif | |
cc8a6dd0 | 24356 | |
c921be7d | 24357 | static bfd_boolean |
e07e6e58 NC |
24358 | arm_parse_it_mode (char * str) |
24359 | { | |
c921be7d | 24360 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
24361 | |
24362 | if (streq ("arm", str)) | |
24363 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
24364 | else if (streq ("thumb", str)) | |
24365 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
24366 | else if (streq ("always", str)) | |
24367 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
24368 | else if (streq ("never", str)) | |
24369 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
24370 | else | |
24371 | { | |
24372 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
24373 | "arm, thumb, always, or never."), str); | |
c921be7d | 24374 | ret = FALSE; |
e07e6e58 NC |
24375 | } |
24376 | ||
24377 | return ret; | |
24378 | } | |
24379 | ||
c19d1205 ZW |
24380 | struct arm_long_option_table arm_long_opts[] = |
24381 | { | |
24382 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
24383 | arm_parse_cpu, NULL}, | |
24384 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
24385 | arm_parse_arch, NULL}, | |
24386 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
24387 | arm_parse_fpu, NULL}, | |
24388 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
24389 | arm_parse_float_abi, NULL}, | |
24390 | #ifdef OBJ_ELF | |
7fac0536 | 24391 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
24392 | arm_parse_eabi, NULL}, |
24393 | #endif | |
e07e6e58 NC |
24394 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
24395 | arm_parse_it_mode, NULL}, | |
c19d1205 ZW |
24396 | {NULL, NULL, 0, NULL} |
24397 | }; | |
cc8a6dd0 | 24398 | |
c19d1205 ZW |
24399 | int |
24400 | md_parse_option (int c, char * arg) | |
24401 | { | |
24402 | struct arm_option_table *opt; | |
e74cfd16 | 24403 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 24404 | struct arm_long_option_table *lopt; |
b99bd4ef | 24405 | |
c19d1205 | 24406 | switch (c) |
b99bd4ef | 24407 | { |
c19d1205 ZW |
24408 | #ifdef OPTION_EB |
24409 | case OPTION_EB: | |
24410 | target_big_endian = 1; | |
24411 | break; | |
24412 | #endif | |
cc8a6dd0 | 24413 | |
c19d1205 ZW |
24414 | #ifdef OPTION_EL |
24415 | case OPTION_EL: | |
24416 | target_big_endian = 0; | |
24417 | break; | |
24418 | #endif | |
b99bd4ef | 24419 | |
845b51d6 PB |
24420 | case OPTION_FIX_V4BX: |
24421 | fix_v4bx = TRUE; | |
24422 | break; | |
24423 | ||
c19d1205 ZW |
24424 | case 'a': |
24425 | /* Listing option. Just ignore these, we don't support additional | |
24426 | ones. */ | |
24427 | return 0; | |
b99bd4ef | 24428 | |
c19d1205 ZW |
24429 | default: |
24430 | for (opt = arm_opts; opt->option != NULL; opt++) | |
24431 | { | |
24432 | if (c == opt->option[0] | |
24433 | && ((arg == NULL && opt->option[1] == 0) | |
24434 | || streq (arg, opt->option + 1))) | |
24435 | { | |
c19d1205 | 24436 | /* If the option is deprecated, tell the user. */ |
278df34e | 24437 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
24438 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
24439 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 24440 | |
c19d1205 ZW |
24441 | if (opt->var != NULL) |
24442 | *opt->var = opt->value; | |
cc8a6dd0 | 24443 | |
c19d1205 ZW |
24444 | return 1; |
24445 | } | |
24446 | } | |
b99bd4ef | 24447 | |
e74cfd16 PB |
24448 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
24449 | { | |
24450 | if (c == fopt->option[0] | |
24451 | && ((arg == NULL && fopt->option[1] == 0) | |
24452 | || streq (arg, fopt->option + 1))) | |
24453 | { | |
e74cfd16 | 24454 | /* If the option is deprecated, tell the user. */ |
278df34e | 24455 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
24456 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
24457 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
24458 | |
24459 | if (fopt->var != NULL) | |
24460 | *fopt->var = &fopt->value; | |
24461 | ||
24462 | return 1; | |
24463 | } | |
24464 | } | |
24465 | ||
c19d1205 ZW |
24466 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
24467 | { | |
24468 | /* These options are expected to have an argument. */ | |
24469 | if (c == lopt->option[0] | |
24470 | && arg != NULL | |
24471 | && strncmp (arg, lopt->option + 1, | |
24472 | strlen (lopt->option + 1)) == 0) | |
24473 | { | |
c19d1205 | 24474 | /* If the option is deprecated, tell the user. */ |
278df34e | 24475 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
24476 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
24477 | _(lopt->deprecated)); | |
b99bd4ef | 24478 | |
c19d1205 ZW |
24479 | /* Call the sup-option parser. */ |
24480 | return lopt->func (arg + strlen (lopt->option) - 1); | |
24481 | } | |
24482 | } | |
a737bd4d | 24483 | |
c19d1205 ZW |
24484 | return 0; |
24485 | } | |
a394c00f | 24486 | |
c19d1205 ZW |
24487 | return 1; |
24488 | } | |
a394c00f | 24489 | |
c19d1205 ZW |
24490 | void |
24491 | md_show_usage (FILE * fp) | |
a394c00f | 24492 | { |
c19d1205 ZW |
24493 | struct arm_option_table *opt; |
24494 | struct arm_long_option_table *lopt; | |
a394c00f | 24495 | |
c19d1205 | 24496 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 24497 | |
c19d1205 ZW |
24498 | for (opt = arm_opts; opt->option != NULL; opt++) |
24499 | if (opt->help != NULL) | |
24500 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 24501 | |
c19d1205 ZW |
24502 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
24503 | if (lopt->help != NULL) | |
24504 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 24505 | |
c19d1205 ZW |
24506 | #ifdef OPTION_EB |
24507 | fprintf (fp, _("\ | |
24508 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
24509 | #endif |
24510 | ||
c19d1205 ZW |
24511 | #ifdef OPTION_EL |
24512 | fprintf (fp, _("\ | |
24513 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 24514 | #endif |
845b51d6 PB |
24515 | |
24516 | fprintf (fp, _("\ | |
24517 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 24518 | } |
ee065d83 PB |
24519 | |
24520 | ||
24521 | #ifdef OBJ_ELF | |
62b3e311 PB |
24522 | typedef struct |
24523 | { | |
24524 | int val; | |
24525 | arm_feature_set flags; | |
24526 | } cpu_arch_ver_table; | |
24527 | ||
24528 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
24529 | least features first. */ | |
24530 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
24531 | { | |
24532 | {1, ARM_ARCH_V4}, | |
24533 | {2, ARM_ARCH_V4T}, | |
24534 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 24535 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
24536 | {4, ARM_ARCH_V5TE}, |
24537 | {5, ARM_ARCH_V5TEJ}, | |
24538 | {6, ARM_ARCH_V6}, | |
7e806470 | 24539 | {9, ARM_ARCH_V6K}, |
f4c65163 | 24540 | {7, ARM_ARCH_V6Z}, |
91e22acd | 24541 | {11, ARM_ARCH_V6M}, |
b2a5fbdc | 24542 | {12, ARM_ARCH_V6SM}, |
7e806470 | 24543 | {8, ARM_ARCH_V6T2}, |
bca38921 | 24544 | {10, ARM_ARCH_V7A_IDIV_MP_SEC_VIRT}, |
62b3e311 PB |
24545 | {10, ARM_ARCH_V7R}, |
24546 | {10, ARM_ARCH_V7M}, | |
bca38921 | 24547 | {14, ARM_ARCH_V8A}, |
62b3e311 PB |
24548 | {0, ARM_ARCH_NONE} |
24549 | }; | |
24550 | ||
ee3c0378 AS |
24551 | /* Set an attribute if it has not already been set by the user. */ |
24552 | static void | |
24553 | aeabi_set_attribute_int (int tag, int value) | |
24554 | { | |
24555 | if (tag < 1 | |
24556 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
24557 | || !attributes_set_explicitly[tag]) | |
24558 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
24559 | } | |
24560 | ||
24561 | static void | |
24562 | aeabi_set_attribute_string (int tag, const char *value) | |
24563 | { | |
24564 | if (tag < 1 | |
24565 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
24566 | || !attributes_set_explicitly[tag]) | |
24567 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
24568 | } | |
24569 | ||
ee065d83 PB |
24570 | /* Set the public EABI object attributes. */ |
24571 | static void | |
24572 | aeabi_set_public_attributes (void) | |
24573 | { | |
24574 | int arch; | |
69239280 | 24575 | char profile; |
90ec0d68 | 24576 | int virt_sec = 0; |
bca38921 | 24577 | int fp16_optional = 0; |
e74cfd16 | 24578 | arm_feature_set flags; |
62b3e311 PB |
24579 | arm_feature_set tmp; |
24580 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
24581 | |
24582 | /* Choose the architecture based on the capabilities of the requested cpu | |
24583 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
24584 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
24585 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
24586 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
ddd7f988 RE |
24587 | |
24588 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) | |
24589 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
24590 | ||
24591 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) | |
24592 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
24593 | ||
24594 | /* Allow the user to override the reported architecture. */ | |
7a1d4c38 PB |
24595 | if (object_arch) |
24596 | { | |
24597 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
24598 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
24599 | } | |
24600 | ||
251665fc MGD |
24601 | /* We need to make sure that the attributes do not identify us as v6S-M |
24602 | when the only v6S-M feature in use is the Operating System Extensions. */ | |
24603 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os)) | |
24604 | if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only)) | |
24605 | ARM_CLEAR_FEATURE (flags, flags, arm_ext_os); | |
24606 | ||
62b3e311 PB |
24607 | tmp = flags; |
24608 | arch = 0; | |
24609 | for (p = cpu_arch_ver; p->val; p++) | |
24610 | { | |
24611 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
24612 | { | |
24613 | arch = p->val; | |
24614 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
24615 | } | |
24616 | } | |
ee065d83 | 24617 | |
9e3c6df6 PB |
24618 | /* The table lookup above finds the last architecture to contribute |
24619 | a new feature. Unfortunately, Tag13 is a subset of the union of | |
24620 | v6T2 and v7-M, so it is never seen as contributing a new feature. | |
24621 | We can not search for the last entry which is entirely used, | |
24622 | because if no CPU is specified we build up only those flags | |
24623 | actually used. Perhaps we should separate out the specified | |
24624 | and implicit cases. Avoid taking this path for -march=all by | |
24625 | checking for contradictory v7-A / v7-M features. */ | |
24626 | if (arch == 10 | |
24627 | && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a) | |
24628 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m) | |
24629 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp)) | |
24630 | arch = 13; | |
24631 | ||
ee065d83 PB |
24632 | /* Tag_CPU_name. */ |
24633 | if (selected_cpu_name[0]) | |
24634 | { | |
91d6fa6a | 24635 | char *q; |
ee065d83 | 24636 | |
91d6fa6a NC |
24637 | q = selected_cpu_name; |
24638 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
24639 | { |
24640 | int i; | |
5f4273c7 | 24641 | |
91d6fa6a NC |
24642 | q += 4; |
24643 | for (i = 0; q[i]; i++) | |
24644 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 24645 | } |
91d6fa6a | 24646 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 24647 | } |
62f3b8c8 | 24648 | |
ee065d83 | 24649 | /* Tag_CPU_arch. */ |
ee3c0378 | 24650 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 24651 | |
62b3e311 PB |
24652 | /* Tag_CPU_arch_profile. */ |
24653 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
69239280 | 24654 | profile = 'A'; |
62b3e311 | 24655 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
69239280 | 24656 | profile = 'R'; |
7e806470 | 24657 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
69239280 MGD |
24658 | profile = 'M'; |
24659 | else | |
24660 | profile = '\0'; | |
24661 | ||
24662 | if (profile != '\0') | |
24663 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 24664 | |
ee065d83 | 24665 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
24666 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
24667 | || arch == 0) | |
24668 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
62f3b8c8 | 24669 | |
ee065d83 | 24670 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
24671 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
24672 | || arch == 0) | |
24673 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, | |
24674 | ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1); | |
62f3b8c8 | 24675 | |
ee065d83 | 24676 | /* Tag_VFP_arch. */ |
bca38921 MGD |
24677 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8)) |
24678 | aeabi_set_attribute_int (Tag_VFP_arch, 7); | |
24679 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) | |
62f3b8c8 PB |
24680 | aeabi_set_attribute_int (Tag_VFP_arch, |
24681 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
24682 | ? 5 : 6); | |
24683 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
bca38921 MGD |
24684 | { |
24685 | fp16_optional = 1; | |
24686 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
24687 | } | |
ada65aa3 | 24688 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
24689 | { |
24690 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
24691 | fp16_optional = 1; | |
24692 | } | |
ee3c0378 AS |
24693 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) |
24694 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
24695 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
24696 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) | |
24697 | aeabi_set_attribute_int (Tag_VFP_arch, 1); | |
62f3b8c8 | 24698 | |
4547cb56 NC |
24699 | /* Tag_ABI_HardFP_use. */ |
24700 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
24701 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
24702 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
24703 | ||
ee065d83 | 24704 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
24705 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
24706 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
24707 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
24708 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 24709 | |
ee3c0378 | 24710 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
bca38921 MGD |
24711 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8)) |
24712 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3); | |
24713 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) | |
24714 | { | |
24715 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)) | |
24716 | { | |
24717 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2); | |
24718 | } | |
24719 | else | |
24720 | { | |
24721 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); | |
24722 | fp16_optional = 1; | |
24723 | } | |
24724 | } | |
fa94de6b | 24725 | |
ee3c0378 | 24726 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 24727 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 24728 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 24729 | |
69239280 MGD |
24730 | /* Tag_DIV_use. |
24731 | ||
24732 | We set Tag_DIV_use to two when integer divide instructions have been used | |
24733 | in ARM state, or when Thumb integer divide instructions have been used, | |
24734 | but we have no architecture profile set, nor have we any ARM instructions. | |
24735 | ||
bca38921 MGD |
24736 | For ARMv8 we set the tag to 0 as integer divide is implied by the base |
24737 | architecture. | |
24738 | ||
69239280 | 24739 | For new architectures we will have to check these tests. */ |
bca38921 MGD |
24740 | gas_assert (arch <= TAG_CPU_ARCH_V8); |
24741 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)) | |
24742 | aeabi_set_attribute_int (Tag_DIV_use, 0); | |
24743 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv) | |
24744 | || (profile == '\0' | |
24745 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_div) | |
24746 | && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))) | |
eea54501 | 24747 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
24748 | |
24749 | /* Tag_MP_extension_use. */ | |
24750 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
24751 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
24752 | |
24753 | /* Tag Virtualization_use. */ | |
24754 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
24755 | virt_sec |= 1; |
24756 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
24757 | virt_sec |= 2; | |
24758 | if (virt_sec != 0) | |
24759 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
ee065d83 PB |
24760 | } |
24761 | ||
104d59d1 | 24762 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
24763 | void |
24764 | arm_md_end (void) | |
24765 | { | |
ee065d83 PB |
24766 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
24767 | return; | |
24768 | ||
24769 | aeabi_set_public_attributes (); | |
ee065d83 | 24770 | } |
8463be01 | 24771 | #endif /* OBJ_ELF */ |
ee065d83 PB |
24772 | |
24773 | ||
24774 | /* Parse a .cpu directive. */ | |
24775 | ||
24776 | static void | |
24777 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
24778 | { | |
e74cfd16 | 24779 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
24780 | char *name; |
24781 | char saved_char; | |
24782 | ||
24783 | name = input_line_pointer; | |
5f4273c7 | 24784 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
24785 | input_line_pointer++; |
24786 | saved_char = *input_line_pointer; | |
24787 | *input_line_pointer = 0; | |
24788 | ||
24789 | /* Skip the first "all" entry. */ | |
24790 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
24791 | if (streq (opt->name, name)) | |
24792 | { | |
e74cfd16 PB |
24793 | mcpu_cpu_opt = &opt->value; |
24794 | selected_cpu = opt->value; | |
ee065d83 | 24795 | if (opt->canonical_name) |
5f4273c7 | 24796 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
24797 | else |
24798 | { | |
24799 | int i; | |
24800 | for (i = 0; opt->name[i]; i++) | |
24801 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 24802 | |
ee065d83 PB |
24803 | selected_cpu_name[i] = 0; |
24804 | } | |
e74cfd16 | 24805 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
24806 | *input_line_pointer = saved_char; |
24807 | demand_empty_rest_of_line (); | |
24808 | return; | |
24809 | } | |
24810 | as_bad (_("unknown cpu `%s'"), name); | |
24811 | *input_line_pointer = saved_char; | |
24812 | ignore_rest_of_line (); | |
24813 | } | |
24814 | ||
24815 | ||
24816 | /* Parse a .arch directive. */ | |
24817 | ||
24818 | static void | |
24819 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
24820 | { | |
e74cfd16 | 24821 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
24822 | char saved_char; |
24823 | char *name; | |
24824 | ||
24825 | name = input_line_pointer; | |
5f4273c7 | 24826 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
24827 | input_line_pointer++; |
24828 | saved_char = *input_line_pointer; | |
24829 | *input_line_pointer = 0; | |
24830 | ||
24831 | /* Skip the first "all" entry. */ | |
24832 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
24833 | if (streq (opt->name, name)) | |
24834 | { | |
e74cfd16 PB |
24835 | mcpu_cpu_opt = &opt->value; |
24836 | selected_cpu = opt->value; | |
5f4273c7 | 24837 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 24838 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
24839 | *input_line_pointer = saved_char; |
24840 | demand_empty_rest_of_line (); | |
24841 | return; | |
24842 | } | |
24843 | ||
24844 | as_bad (_("unknown architecture `%s'\n"), name); | |
24845 | *input_line_pointer = saved_char; | |
24846 | ignore_rest_of_line (); | |
24847 | } | |
24848 | ||
24849 | ||
7a1d4c38 PB |
24850 | /* Parse a .object_arch directive. */ |
24851 | ||
24852 | static void | |
24853 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
24854 | { | |
24855 | const struct arm_arch_option_table *opt; | |
24856 | char saved_char; | |
24857 | char *name; | |
24858 | ||
24859 | name = input_line_pointer; | |
5f4273c7 | 24860 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
24861 | input_line_pointer++; |
24862 | saved_char = *input_line_pointer; | |
24863 | *input_line_pointer = 0; | |
24864 | ||
24865 | /* Skip the first "all" entry. */ | |
24866 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
24867 | if (streq (opt->name, name)) | |
24868 | { | |
24869 | object_arch = &opt->value; | |
24870 | *input_line_pointer = saved_char; | |
24871 | demand_empty_rest_of_line (); | |
24872 | return; | |
24873 | } | |
24874 | ||
24875 | as_bad (_("unknown architecture `%s'\n"), name); | |
24876 | *input_line_pointer = saved_char; | |
24877 | ignore_rest_of_line (); | |
24878 | } | |
24879 | ||
69133863 MGD |
24880 | /* Parse a .arch_extension directive. */ |
24881 | ||
24882 | static void | |
24883 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
24884 | { | |
24885 | const struct arm_option_extension_value_table *opt; | |
24886 | char saved_char; | |
24887 | char *name; | |
24888 | int adding_value = 1; | |
24889 | ||
24890 | name = input_line_pointer; | |
24891 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
24892 | input_line_pointer++; | |
24893 | saved_char = *input_line_pointer; | |
24894 | *input_line_pointer = 0; | |
24895 | ||
24896 | if (strlen (name) >= 2 | |
24897 | && strncmp (name, "no", 2) == 0) | |
24898 | { | |
24899 | adding_value = 0; | |
24900 | name += 2; | |
24901 | } | |
24902 | ||
24903 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
24904 | if (streq (opt->name, name)) | |
24905 | { | |
24906 | if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs)) | |
24907 | { | |
24908 | as_bad (_("architectural extension `%s' is not allowed for the " | |
24909 | "current base architecture"), name); | |
24910 | break; | |
24911 | } | |
24912 | ||
24913 | if (adding_value) | |
24914 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value); | |
24915 | else | |
24916 | ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value); | |
24917 | ||
24918 | mcpu_cpu_opt = &selected_cpu; | |
24919 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
24920 | *input_line_pointer = saved_char; | |
24921 | demand_empty_rest_of_line (); | |
24922 | return; | |
24923 | } | |
24924 | ||
24925 | if (opt->name == NULL) | |
24926 | as_bad (_("unknown architecture `%s'\n"), name); | |
24927 | ||
24928 | *input_line_pointer = saved_char; | |
24929 | ignore_rest_of_line (); | |
24930 | } | |
24931 | ||
ee065d83 PB |
24932 | /* Parse a .fpu directive. */ |
24933 | ||
24934 | static void | |
24935 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
24936 | { | |
69133863 | 24937 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
24938 | char saved_char; |
24939 | char *name; | |
24940 | ||
24941 | name = input_line_pointer; | |
5f4273c7 | 24942 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
24943 | input_line_pointer++; |
24944 | saved_char = *input_line_pointer; | |
24945 | *input_line_pointer = 0; | |
5f4273c7 | 24946 | |
ee065d83 PB |
24947 | for (opt = arm_fpus; opt->name != NULL; opt++) |
24948 | if (streq (opt->name, name)) | |
24949 | { | |
e74cfd16 PB |
24950 | mfpu_opt = &opt->value; |
24951 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
24952 | *input_line_pointer = saved_char; |
24953 | demand_empty_rest_of_line (); | |
24954 | return; | |
24955 | } | |
24956 | ||
24957 | as_bad (_("unknown floating point format `%s'\n"), name); | |
24958 | *input_line_pointer = saved_char; | |
24959 | ignore_rest_of_line (); | |
24960 | } | |
ee065d83 | 24961 | |
794ba86a | 24962 | /* Copy symbol information. */ |
f31fef98 | 24963 | |
794ba86a DJ |
24964 | void |
24965 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
24966 | { | |
24967 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
24968 | } | |
e04befd0 | 24969 | |
f31fef98 | 24970 | #ifdef OBJ_ELF |
e04befd0 AS |
24971 | /* Given a symbolic attribute NAME, return the proper integer value. |
24972 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 24973 | |
e04befd0 AS |
24974 | int |
24975 | arm_convert_symbolic_attribute (const char *name) | |
24976 | { | |
f31fef98 NC |
24977 | static const struct |
24978 | { | |
24979 | const char * name; | |
24980 | const int tag; | |
24981 | } | |
24982 | attribute_table[] = | |
24983 | { | |
24984 | /* When you modify this table you should | |
24985 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 24986 | #define T(tag) {#tag, tag} |
f31fef98 NC |
24987 | T (Tag_CPU_raw_name), |
24988 | T (Tag_CPU_name), | |
24989 | T (Tag_CPU_arch), | |
24990 | T (Tag_CPU_arch_profile), | |
24991 | T (Tag_ARM_ISA_use), | |
24992 | T (Tag_THUMB_ISA_use), | |
75375b3e | 24993 | T (Tag_FP_arch), |
f31fef98 NC |
24994 | T (Tag_VFP_arch), |
24995 | T (Tag_WMMX_arch), | |
24996 | T (Tag_Advanced_SIMD_arch), | |
24997 | T (Tag_PCS_config), | |
24998 | T (Tag_ABI_PCS_R9_use), | |
24999 | T (Tag_ABI_PCS_RW_data), | |
25000 | T (Tag_ABI_PCS_RO_data), | |
25001 | T (Tag_ABI_PCS_GOT_use), | |
25002 | T (Tag_ABI_PCS_wchar_t), | |
25003 | T (Tag_ABI_FP_rounding), | |
25004 | T (Tag_ABI_FP_denormal), | |
25005 | T (Tag_ABI_FP_exceptions), | |
25006 | T (Tag_ABI_FP_user_exceptions), | |
25007 | T (Tag_ABI_FP_number_model), | |
75375b3e | 25008 | T (Tag_ABI_align_needed), |
f31fef98 | 25009 | T (Tag_ABI_align8_needed), |
75375b3e | 25010 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
25011 | T (Tag_ABI_align8_preserved), |
25012 | T (Tag_ABI_enum_size), | |
25013 | T (Tag_ABI_HardFP_use), | |
25014 | T (Tag_ABI_VFP_args), | |
25015 | T (Tag_ABI_WMMX_args), | |
25016 | T (Tag_ABI_optimization_goals), | |
25017 | T (Tag_ABI_FP_optimization_goals), | |
25018 | T (Tag_compatibility), | |
25019 | T (Tag_CPU_unaligned_access), | |
75375b3e | 25020 | T (Tag_FP_HP_extension), |
f31fef98 NC |
25021 | T (Tag_VFP_HP_extension), |
25022 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
25023 | T (Tag_MPextension_use), |
25024 | T (Tag_DIV_use), | |
f31fef98 NC |
25025 | T (Tag_nodefaults), |
25026 | T (Tag_also_compatible_with), | |
25027 | T (Tag_conformance), | |
25028 | T (Tag_T2EE_use), | |
25029 | T (Tag_Virtualization_use), | |
cd21e546 | 25030 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 25031 | #undef T |
f31fef98 | 25032 | }; |
e04befd0 AS |
25033 | unsigned int i; |
25034 | ||
25035 | if (name == NULL) | |
25036 | return -1; | |
25037 | ||
f31fef98 | 25038 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 25039 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
25040 | return attribute_table[i].tag; |
25041 | ||
25042 | return -1; | |
25043 | } | |
267bf995 RR |
25044 | |
25045 | ||
25046 | /* Apply sym value for relocations only in the case that | |
25047 | they are for local symbols and you have the respective | |
25048 | architectural feature for blx and simple switches. */ | |
25049 | int | |
25050 | arm_apply_sym_value (struct fix * fixP) | |
25051 | { | |
25052 | if (fixP->fx_addsy | |
25053 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
34e77a92 | 25054 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)) |
267bf995 RR |
25055 | { |
25056 | switch (fixP->fx_r_type) | |
25057 | { | |
25058 | case BFD_RELOC_ARM_PCREL_BLX: | |
25059 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
25060 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
25061 | return 1; | |
25062 | break; | |
25063 | ||
25064 | case BFD_RELOC_ARM_PCREL_CALL: | |
25065 | case BFD_RELOC_THUMB_PCREL_BLX: | |
25066 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
25067 | return 1; | |
25068 | break; | |
25069 | ||
25070 | default: | |
25071 | break; | |
25072 | } | |
25073 | ||
25074 | } | |
25075 | return 0; | |
25076 | } | |
f31fef98 | 25077 | #endif /* OBJ_ELF */ |