Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
f17c130b | 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
b43420e6 | 3 | 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
b99bd4ef NC |
4 | Free Software Foundation, Inc. |
5 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) | |
6 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 7 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
8 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
9 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
10 | |
11 | This file is part of GAS, the GNU Assembler. | |
12 | ||
13 | GAS is free software; you can redistribute it and/or modify | |
14 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 15 | the Free Software Foundation; either version 3, or (at your option) |
b99bd4ef NC |
16 | any later version. |
17 | ||
18 | GAS is distributed in the hope that it will be useful, | |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c19d1205 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
21 | GNU General Public License for more details. |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
24 | along with GAS; see the file COPYING. If not, write to the Free | |
699d2810 NC |
25 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
26 | 02110-1301, USA. */ | |
b99bd4ef | 27 | |
42a68e18 | 28 | #include "as.h" |
5287ad62 | 29 | #include <limits.h> |
037e8744 | 30 | #include <stdarg.h> |
c19d1205 | 31 | #define NO_RELOC 0 |
3882b010 | 32 | #include "safe-ctype.h" |
b99bd4ef NC |
33 | #include "subsegs.h" |
34 | #include "obstack.h" | |
b99bd4ef | 35 | |
f263249b RE |
36 | #include "opcode/arm.h" |
37 | ||
b99bd4ef NC |
38 | #ifdef OBJ_ELF |
39 | #include "elf/arm.h" | |
a394c00f | 40 | #include "dw2gencfi.h" |
b99bd4ef NC |
41 | #endif |
42 | ||
f0927246 NC |
43 | #include "dwarf2dbg.h" |
44 | ||
7ed4c4c5 NC |
45 | #ifdef OBJ_ELF |
46 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
47 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
48 | ||
49 | /* This structure holds the unwinding state. */ | |
50 | ||
51 | static struct | |
52 | { | |
c19d1205 ZW |
53 | symbolS * proc_start; |
54 | symbolS * table_entry; | |
55 | symbolS * personality_routine; | |
56 | int personality_index; | |
7ed4c4c5 | 57 | /* The segment containing the function. */ |
c19d1205 ZW |
58 | segT saved_seg; |
59 | subsegT saved_subseg; | |
7ed4c4c5 NC |
60 | /* Opcodes generated from this function. */ |
61 | unsigned char * opcodes; | |
c19d1205 ZW |
62 | int opcode_count; |
63 | int opcode_alloc; | |
7ed4c4c5 | 64 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 65 | offsetT frame_size; |
7ed4c4c5 NC |
66 | /* We don't add stack adjustment opcodes immediately so that we can merge |
67 | multiple adjustments. We can also omit the final adjustment | |
68 | when using a frame pointer. */ | |
c19d1205 | 69 | offsetT pending_offset; |
7ed4c4c5 | 70 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
71 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
72 | offsetT fp_offset; | |
73 | int fp_reg; | |
7ed4c4c5 | 74 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 75 | unsigned fp_used:1; |
7ed4c4c5 | 76 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 77 | unsigned sp_restored:1; |
7ed4c4c5 NC |
78 | } unwind; |
79 | ||
8b1ad454 NC |
80 | #endif /* OBJ_ELF */ |
81 | ||
4962c51a MS |
82 | /* Results from operand parsing worker functions. */ |
83 | ||
84 | typedef enum | |
85 | { | |
86 | PARSE_OPERAND_SUCCESS, | |
87 | PARSE_OPERAND_FAIL, | |
88 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
89 | } parse_operand_result; | |
90 | ||
33a392fb PB |
91 | enum arm_float_abi |
92 | { | |
93 | ARM_FLOAT_ABI_HARD, | |
94 | ARM_FLOAT_ABI_SOFTFP, | |
95 | ARM_FLOAT_ABI_SOFT | |
96 | }; | |
97 | ||
c19d1205 | 98 | /* Types of processor to assemble for. */ |
b99bd4ef | 99 | #ifndef CPU_DEFAULT |
8a59fff3 MGD |
100 | /* The code that was here used to select a default CPU depending on compiler |
101 | pre-defines which were only present when doing native builds, thus | |
102 | changing gas' default behaviour depending upon the build host. | |
103 | ||
104 | If you have a target that requires a default CPU option then the you | |
105 | should define CPU_DEFAULT here. */ | |
b99bd4ef NC |
106 | #endif |
107 | ||
108 | #ifndef FPU_DEFAULT | |
c820d418 MM |
109 | # ifdef TE_LINUX |
110 | # define FPU_DEFAULT FPU_ARCH_FPA | |
111 | # elif defined (TE_NetBSD) | |
112 | # ifdef OBJ_ELF | |
113 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
114 | # else | |
115 | /* Legacy a.out format. */ | |
116 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
117 | # endif | |
4e7fd91e PB |
118 | # elif defined (TE_VXWORKS) |
119 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
120 | # else |
121 | /* For backwards compatibility, default to FPA. */ | |
122 | # define FPU_DEFAULT FPU_ARCH_FPA | |
123 | # endif | |
124 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 125 | |
c19d1205 | 126 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 127 | |
e74cfd16 PB |
128 | static arm_feature_set cpu_variant; |
129 | static arm_feature_set arm_arch_used; | |
130 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 131 | |
b99bd4ef | 132 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
133 | static int uses_apcs_26 = FALSE; |
134 | static int atpcs = FALSE; | |
b34976b6 AM |
135 | static int support_interwork = FALSE; |
136 | static int uses_apcs_float = FALSE; | |
c19d1205 | 137 | static int pic_code = FALSE; |
845b51d6 | 138 | static int fix_v4bx = FALSE; |
278df34e NS |
139 | /* Warn on using deprecated features. */ |
140 | static int warn_on_deprecated = TRUE; | |
141 | ||
03b1477f RE |
142 | |
143 | /* Variables that we set while parsing command-line options. Once all | |
144 | options have been read we re-process these values to set the real | |
145 | assembly flags. */ | |
e74cfd16 PB |
146 | static const arm_feature_set *legacy_cpu = NULL; |
147 | static const arm_feature_set *legacy_fpu = NULL; | |
148 | ||
149 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
150 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
151 | static const arm_feature_set *march_cpu_opt = NULL; | |
152 | static const arm_feature_set *march_fpu_opt = NULL; | |
153 | static const arm_feature_set *mfpu_opt = NULL; | |
7a1d4c38 | 154 | static const arm_feature_set *object_arch = NULL; |
e74cfd16 PB |
155 | |
156 | /* Constants for known architecture features. */ | |
157 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
158 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
159 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
160 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
161 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
162 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
163 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
164 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
165 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
166 | ||
167 | #ifdef CPU_DEFAULT | |
168 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
169 | #endif | |
170 | ||
171 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
172 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
173 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
174 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
175 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
176 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
177 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
178 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
179 | static const arm_feature_set arm_ext_v4t_5 = | |
180 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
181 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
182 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
183 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
184 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
185 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
186 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
e74cfd16 | 187 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); |
b2a5fbdc | 188 | static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0); |
62b3e311 | 189 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
9e3c6df6 | 190 | static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0); |
7e806470 PB |
191 | static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0); |
192 | static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0); | |
62b3e311 PB |
193 | static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0); |
194 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0); | |
195 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0); | |
196 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0); | |
9e3c6df6 | 197 | static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0); |
7e806470 | 198 | static const arm_feature_set arm_ext_m = |
b2a5fbdc | 199 | ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0); |
60e5ef9f | 200 | static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0); |
f4c65163 | 201 | static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0); |
b2a5fbdc | 202 | static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0); |
eea54501 | 203 | static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0); |
90ec0d68 | 204 | static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0); |
e74cfd16 PB |
205 | |
206 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
207 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
208 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
209 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
251665fc | 210 | static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY; |
e74cfd16 | 211 | |
2d447fca JM |
212 | static const arm_feature_set arm_cext_iwmmxt2 = |
213 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2); | |
e74cfd16 PB |
214 | static const arm_feature_set arm_cext_iwmmxt = |
215 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
216 | static const arm_feature_set arm_cext_xscale = | |
217 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
218 | static const arm_feature_set arm_cext_maverick = | |
219 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
220 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
221 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
222 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
223 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
224 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
225 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
62f3b8c8 | 226 | static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD); |
5287ad62 | 227 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
b1cc4aeb PB |
228 | static const arm_feature_set fpu_vfp_ext_d32 = |
229 | ARM_FEATURE (0, FPU_VFP_EXT_D32); | |
5287ad62 JB |
230 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); |
231 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
232 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
62f3b8c8 PB |
233 | static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16); |
234 | static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA); | |
235 | static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA); | |
e74cfd16 | 236 | |
33a392fb | 237 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
238 | /* Record user cpu selection for object attributes. */ |
239 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
240 | /* Must be long enough to hold any of the names in arm_cpus. */ |
241 | static char selected_cpu_name[16]; | |
7cc69913 | 242 | #ifdef OBJ_ELF |
deeaaff8 DJ |
243 | # ifdef EABI_DEFAULT |
244 | static int meabi_flags = EABI_DEFAULT; | |
245 | # else | |
d507cf36 | 246 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 247 | # endif |
e1da3f5b | 248 | |
ee3c0378 AS |
249 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
250 | ||
e1da3f5b | 251 | bfd_boolean |
5f4273c7 | 252 | arm_is_eabi (void) |
e1da3f5b PB |
253 | { |
254 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
255 | } | |
7cc69913 | 256 | #endif |
b99bd4ef | 257 | |
b99bd4ef | 258 | #ifdef OBJ_ELF |
c19d1205 | 259 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
260 | symbolS * GOT_symbol; |
261 | #endif | |
262 | ||
b99bd4ef NC |
263 | /* 0: assemble for ARM, |
264 | 1: assemble for Thumb, | |
265 | 2: assemble for Thumb even though target CPU does not support thumb | |
266 | instructions. */ | |
267 | static int thumb_mode = 0; | |
8dc2430f NC |
268 | /* A value distinct from the possible values for thumb_mode that we |
269 | can use to record whether thumb_mode has been copied into the | |
270 | tc_frag_data field of a frag. */ | |
271 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 272 | |
e07e6e58 NC |
273 | /* Specifies the intrinsic IT insn behavior mode. */ |
274 | enum implicit_it_mode | |
275 | { | |
276 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
277 | IMPLICIT_IT_MODE_ARM = 0x01, | |
278 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
279 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
280 | }; | |
281 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
282 | ||
c19d1205 ZW |
283 | /* If unified_syntax is true, we are processing the new unified |
284 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
285 | ||
286 | - Immediate operands do not require a # prefix. | |
287 | - Conditional affixes always appear at the end of the | |
288 | instruction. (For backward compatibility, those instructions | |
289 | that formerly had them in the middle, continue to accept them | |
290 | there.) | |
291 | - The IT instruction may appear, and if it does is validated | |
292 | against subsequent conditional affixes. It does not generate | |
293 | machine code. | |
294 | ||
295 | Important differences from the old Thumb mode: | |
296 | ||
297 | - Immediate operands do not require a # prefix. | |
298 | - Most of the V6T2 instructions are only available in unified mode. | |
299 | - The .N and .W suffixes are recognized and honored (it is an error | |
300 | if they cannot be honored). | |
301 | - All instructions set the flags if and only if they have an 's' affix. | |
302 | - Conditional affixes may be used. They are validated against | |
303 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
304 | conditional affix except in the scope of an IT instruction. */ | |
305 | ||
306 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 307 | |
5287ad62 JB |
308 | enum neon_el_type |
309 | { | |
dcbf9037 | 310 | NT_invtype, |
5287ad62 JB |
311 | NT_untyped, |
312 | NT_integer, | |
313 | NT_float, | |
314 | NT_poly, | |
315 | NT_signed, | |
dcbf9037 | 316 | NT_unsigned |
5287ad62 JB |
317 | }; |
318 | ||
319 | struct neon_type_el | |
320 | { | |
321 | enum neon_el_type type; | |
322 | unsigned size; | |
323 | }; | |
324 | ||
325 | #define NEON_MAX_TYPE_ELS 4 | |
326 | ||
327 | struct neon_type | |
328 | { | |
329 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
330 | unsigned elems; | |
331 | }; | |
332 | ||
e07e6e58 NC |
333 | enum it_instruction_type |
334 | { | |
335 | OUTSIDE_IT_INSN, | |
336 | INSIDE_IT_INSN, | |
337 | INSIDE_IT_LAST_INSN, | |
338 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
339 | if inside, should be the last one. */ | |
340 | NEUTRAL_IT_INSN, /* This could be either inside or outside, | |
341 | i.e. BKPT and NOP. */ | |
342 | IT_INSN /* The IT insn has been parsed. */ | |
343 | }; | |
344 | ||
b99bd4ef NC |
345 | struct arm_it |
346 | { | |
c19d1205 | 347 | const char * error; |
b99bd4ef | 348 | unsigned long instruction; |
c19d1205 ZW |
349 | int size; |
350 | int size_req; | |
351 | int cond; | |
037e8744 JB |
352 | /* "uncond_value" is set to the value in place of the conditional field in |
353 | unconditional versions of the instruction, or -1 if nothing is | |
354 | appropriate. */ | |
355 | int uncond_value; | |
5287ad62 | 356 | struct neon_type vectype; |
88714cb8 DG |
357 | /* This does not indicate an actual NEON instruction, only that |
358 | the mnemonic accepts neon-style type suffixes. */ | |
359 | int is_neon; | |
0110f2b8 PB |
360 | /* Set to the opcode if the instruction needs relaxation. |
361 | Zero if the instruction is not relaxed. */ | |
362 | unsigned long relax; | |
b99bd4ef NC |
363 | struct |
364 | { | |
365 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
366 | expressionS exp; |
367 | int pc_rel; | |
b99bd4ef | 368 | } reloc; |
b99bd4ef | 369 | |
e07e6e58 NC |
370 | enum it_instruction_type it_insn_type; |
371 | ||
c19d1205 ZW |
372 | struct |
373 | { | |
374 | unsigned reg; | |
ca3f61f7 | 375 | signed int imm; |
dcbf9037 | 376 | struct neon_type_el vectype; |
ca3f61f7 NC |
377 | unsigned present : 1; /* Operand present. */ |
378 | unsigned isreg : 1; /* Operand was a register. */ | |
379 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
380 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
381 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 382 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
383 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
384 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
385 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 386 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 387 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 388 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
389 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
390 | unsigned writeback : 1; /* Operand has trailing ! */ | |
391 | unsigned preind : 1; /* Preindexed address. */ | |
392 | unsigned postind : 1; /* Postindexed address. */ | |
393 | unsigned negative : 1; /* Index register was negated. */ | |
394 | unsigned shifted : 1; /* Shift applied to operation. */ | |
395 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 396 | } operands[6]; |
b99bd4ef NC |
397 | }; |
398 | ||
c19d1205 | 399 | static struct arm_it inst; |
b99bd4ef NC |
400 | |
401 | #define NUM_FLOAT_VALS 8 | |
402 | ||
05d2d07e | 403 | const char * fp_const[] = |
b99bd4ef NC |
404 | { |
405 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
406 | }; | |
407 | ||
c19d1205 | 408 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
409 | #define MAX_LITTLENUMS 6 |
410 | ||
411 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
412 | ||
413 | #define FAIL (-1) | |
414 | #define SUCCESS (0) | |
415 | ||
416 | #define SUFF_S 1 | |
417 | #define SUFF_D 2 | |
418 | #define SUFF_E 3 | |
419 | #define SUFF_P 4 | |
420 | ||
c19d1205 ZW |
421 | #define CP_T_X 0x00008000 |
422 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 423 | |
c19d1205 ZW |
424 | #define CONDS_BIT 0x00100000 |
425 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
426 | |
427 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
428 | ||
429 | struct asm_cond | |
430 | { | |
d3ce72d0 | 431 | const char * template_name; |
c921be7d | 432 | unsigned long value; |
b99bd4ef NC |
433 | }; |
434 | ||
c19d1205 | 435 | #define COND_ALWAYS 0xE |
b99bd4ef | 436 | |
b99bd4ef NC |
437 | struct asm_psr |
438 | { | |
d3ce72d0 | 439 | const char * template_name; |
c921be7d | 440 | unsigned long field; |
b99bd4ef NC |
441 | }; |
442 | ||
62b3e311 PB |
443 | struct asm_barrier_opt |
444 | { | |
d3ce72d0 | 445 | const char * template_name; |
c921be7d | 446 | unsigned long value; |
62b3e311 PB |
447 | }; |
448 | ||
2d2255b5 | 449 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
450 | #define SPSR_BIT (1 << 22) |
451 | ||
c19d1205 ZW |
452 | /* The individual PSR flag bits. */ |
453 | #define PSR_c (1 << 16) | |
454 | #define PSR_x (1 << 17) | |
455 | #define PSR_s (1 << 18) | |
456 | #define PSR_f (1 << 19) | |
b99bd4ef | 457 | |
c19d1205 | 458 | struct reloc_entry |
bfae80f2 | 459 | { |
c921be7d NC |
460 | char * name; |
461 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
462 | }; |
463 | ||
5287ad62 | 464 | enum vfp_reg_pos |
bfae80f2 | 465 | { |
5287ad62 JB |
466 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
467 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
468 | }; |
469 | ||
470 | enum vfp_ldstm_type | |
471 | { | |
472 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
473 | }; | |
474 | ||
dcbf9037 JB |
475 | /* Bits for DEFINED field in neon_typed_alias. */ |
476 | #define NTA_HASTYPE 1 | |
477 | #define NTA_HASINDEX 2 | |
478 | ||
479 | struct neon_typed_alias | |
480 | { | |
c921be7d NC |
481 | unsigned char defined; |
482 | unsigned char index; | |
483 | struct neon_type_el eltype; | |
dcbf9037 JB |
484 | }; |
485 | ||
c19d1205 ZW |
486 | /* ARM register categories. This includes coprocessor numbers and various |
487 | architecture extensions' registers. */ | |
488 | enum arm_reg_type | |
bfae80f2 | 489 | { |
c19d1205 ZW |
490 | REG_TYPE_RN, |
491 | REG_TYPE_CP, | |
492 | REG_TYPE_CN, | |
493 | REG_TYPE_FN, | |
494 | REG_TYPE_VFS, | |
495 | REG_TYPE_VFD, | |
5287ad62 | 496 | REG_TYPE_NQ, |
037e8744 | 497 | REG_TYPE_VFSD, |
5287ad62 | 498 | REG_TYPE_NDQ, |
037e8744 | 499 | REG_TYPE_NSDQ, |
c19d1205 ZW |
500 | REG_TYPE_VFC, |
501 | REG_TYPE_MVF, | |
502 | REG_TYPE_MVD, | |
503 | REG_TYPE_MVFX, | |
504 | REG_TYPE_MVDX, | |
505 | REG_TYPE_MVAX, | |
506 | REG_TYPE_DSPSC, | |
507 | REG_TYPE_MMXWR, | |
508 | REG_TYPE_MMXWC, | |
509 | REG_TYPE_MMXWCG, | |
510 | REG_TYPE_XSCALE, | |
90ec0d68 | 511 | REG_TYPE_RNB |
bfae80f2 RE |
512 | }; |
513 | ||
dcbf9037 JB |
514 | /* Structure for a hash table entry for a register. |
515 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
516 | information which states whether a vector type or index is specified (for a | |
517 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
518 | struct reg_entry |
519 | { | |
c921be7d | 520 | const char * name; |
90ec0d68 | 521 | unsigned int number; |
c921be7d NC |
522 | unsigned char type; |
523 | unsigned char builtin; | |
524 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
525 | }; |
526 | ||
c19d1205 | 527 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 528 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
529 | { |
530 | N_("ARM register expected"), | |
531 | N_("bad or missing co-processor number"), | |
532 | N_("co-processor register expected"), | |
533 | N_("FPA register expected"), | |
534 | N_("VFP single precision register expected"), | |
5287ad62 JB |
535 | N_("VFP/Neon double precision register expected"), |
536 | N_("Neon quad precision register expected"), | |
037e8744 | 537 | N_("VFP single or double precision register expected"), |
5287ad62 | 538 | N_("Neon double or quad precision register expected"), |
037e8744 | 539 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
540 | N_("VFP system register expected"), |
541 | N_("Maverick MVF register expected"), | |
542 | N_("Maverick MVD register expected"), | |
543 | N_("Maverick MVFX register expected"), | |
544 | N_("Maverick MVDX register expected"), | |
545 | N_("Maverick MVAX register expected"), | |
546 | N_("Maverick DSPSC register expected"), | |
547 | N_("iWMMXt data register expected"), | |
548 | N_("iWMMXt control register expected"), | |
549 | N_("iWMMXt scalar register expected"), | |
550 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
551 | }; |
552 | ||
c19d1205 ZW |
553 | /* Some well known registers that we refer to directly elsewhere. */ |
554 | #define REG_SP 13 | |
555 | #define REG_LR 14 | |
556 | #define REG_PC 15 | |
404ff6b5 | 557 | |
b99bd4ef NC |
558 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
559 | take 2: */ | |
c19d1205 | 560 | #define INSN_SIZE 4 |
b99bd4ef NC |
561 | |
562 | struct asm_opcode | |
563 | { | |
564 | /* Basic string to match. */ | |
d3ce72d0 | 565 | const char * template_name; |
c19d1205 ZW |
566 | |
567 | /* Parameters to instruction. */ | |
5be8be5d | 568 | unsigned int operands[8]; |
c19d1205 ZW |
569 | |
570 | /* Conditional tag - see opcode_lookup. */ | |
571 | unsigned int tag : 4; | |
b99bd4ef NC |
572 | |
573 | /* Basic instruction code. */ | |
c19d1205 | 574 | unsigned int avalue : 28; |
b99bd4ef | 575 | |
c19d1205 ZW |
576 | /* Thumb-format instruction code. */ |
577 | unsigned int tvalue; | |
b99bd4ef | 578 | |
90e4755a | 579 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
580 | const arm_feature_set * avariant; |
581 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
582 | |
583 | /* Function to call to encode instruction in ARM format. */ | |
584 | void (* aencode) (void); | |
b99bd4ef | 585 | |
c19d1205 ZW |
586 | /* Function to call to encode instruction in Thumb format. */ |
587 | void (* tencode) (void); | |
b99bd4ef NC |
588 | }; |
589 | ||
a737bd4d NC |
590 | /* Defines for various bits that we will want to toggle. */ |
591 | #define INST_IMMEDIATE 0x02000000 | |
592 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 593 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
594 | #define SHIFT_BY_REG 0x00000010 |
595 | #define PRE_INDEX 0x01000000 | |
596 | #define INDEX_UP 0x00800000 | |
597 | #define WRITE_BACK 0x00200000 | |
598 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 599 | #define CPSI_MMOD 0x00020000 |
90e4755a | 600 | |
a737bd4d NC |
601 | #define LITERAL_MASK 0xf000f000 |
602 | #define OPCODE_MASK 0xfe1fffff | |
603 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 604 | |
efd81785 PB |
605 | #define T2_SUBS_PC_LR 0xf3de8f00 |
606 | ||
a737bd4d | 607 | #define DATA_OP_SHIFT 21 |
90e4755a | 608 | |
ef8d22e6 PB |
609 | #define T2_OPCODE_MASK 0xfe1fffff |
610 | #define T2_DATA_OP_SHIFT 21 | |
611 | ||
a737bd4d NC |
612 | /* Codes to distinguish the arithmetic instructions. */ |
613 | #define OPCODE_AND 0 | |
614 | #define OPCODE_EOR 1 | |
615 | #define OPCODE_SUB 2 | |
616 | #define OPCODE_RSB 3 | |
617 | #define OPCODE_ADD 4 | |
618 | #define OPCODE_ADC 5 | |
619 | #define OPCODE_SBC 6 | |
620 | #define OPCODE_RSC 7 | |
621 | #define OPCODE_TST 8 | |
622 | #define OPCODE_TEQ 9 | |
623 | #define OPCODE_CMP 10 | |
624 | #define OPCODE_CMN 11 | |
625 | #define OPCODE_ORR 12 | |
626 | #define OPCODE_MOV 13 | |
627 | #define OPCODE_BIC 14 | |
628 | #define OPCODE_MVN 15 | |
90e4755a | 629 | |
ef8d22e6 PB |
630 | #define T2_OPCODE_AND 0 |
631 | #define T2_OPCODE_BIC 1 | |
632 | #define T2_OPCODE_ORR 2 | |
633 | #define T2_OPCODE_ORN 3 | |
634 | #define T2_OPCODE_EOR 4 | |
635 | #define T2_OPCODE_ADD 8 | |
636 | #define T2_OPCODE_ADC 10 | |
637 | #define T2_OPCODE_SBC 11 | |
638 | #define T2_OPCODE_SUB 13 | |
639 | #define T2_OPCODE_RSB 14 | |
640 | ||
a737bd4d NC |
641 | #define T_OPCODE_MUL 0x4340 |
642 | #define T_OPCODE_TST 0x4200 | |
643 | #define T_OPCODE_CMN 0x42c0 | |
644 | #define T_OPCODE_NEG 0x4240 | |
645 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 646 | |
a737bd4d NC |
647 | #define T_OPCODE_ADD_R3 0x1800 |
648 | #define T_OPCODE_SUB_R3 0x1a00 | |
649 | #define T_OPCODE_ADD_HI 0x4400 | |
650 | #define T_OPCODE_ADD_ST 0xb000 | |
651 | #define T_OPCODE_SUB_ST 0xb080 | |
652 | #define T_OPCODE_ADD_SP 0xa800 | |
653 | #define T_OPCODE_ADD_PC 0xa000 | |
654 | #define T_OPCODE_ADD_I8 0x3000 | |
655 | #define T_OPCODE_SUB_I8 0x3800 | |
656 | #define T_OPCODE_ADD_I3 0x1c00 | |
657 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 658 | |
a737bd4d NC |
659 | #define T_OPCODE_ASR_R 0x4100 |
660 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
661 | #define T_OPCODE_LSR_R 0x40c0 |
662 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
663 | #define T_OPCODE_ASR_I 0x1000 |
664 | #define T_OPCODE_LSL_I 0x0000 | |
665 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 666 | |
a737bd4d NC |
667 | #define T_OPCODE_MOV_I8 0x2000 |
668 | #define T_OPCODE_CMP_I8 0x2800 | |
669 | #define T_OPCODE_CMP_LR 0x4280 | |
670 | #define T_OPCODE_MOV_HR 0x4600 | |
671 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 672 | |
a737bd4d NC |
673 | #define T_OPCODE_LDR_PC 0x4800 |
674 | #define T_OPCODE_LDR_SP 0x9800 | |
675 | #define T_OPCODE_STR_SP 0x9000 | |
676 | #define T_OPCODE_LDR_IW 0x6800 | |
677 | #define T_OPCODE_STR_IW 0x6000 | |
678 | #define T_OPCODE_LDR_IH 0x8800 | |
679 | #define T_OPCODE_STR_IH 0x8000 | |
680 | #define T_OPCODE_LDR_IB 0x7800 | |
681 | #define T_OPCODE_STR_IB 0x7000 | |
682 | #define T_OPCODE_LDR_RW 0x5800 | |
683 | #define T_OPCODE_STR_RW 0x5000 | |
684 | #define T_OPCODE_LDR_RH 0x5a00 | |
685 | #define T_OPCODE_STR_RH 0x5200 | |
686 | #define T_OPCODE_LDR_RB 0x5c00 | |
687 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 688 | |
a737bd4d NC |
689 | #define T_OPCODE_PUSH 0xb400 |
690 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 691 | |
2fc8bdac | 692 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 693 | |
a737bd4d | 694 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 695 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 696 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 697 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
698 | |
699 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 700 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
701 | #define BAD_PC _("r15 not allowed here") |
702 | #define BAD_COND _("instruction cannot be conditional") | |
703 | #define BAD_OVERLAP _("registers may not be the same") | |
704 | #define BAD_HIREG _("lo register required") | |
705 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 706 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
707 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
708 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 709 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
710 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
711 | #define BAD_IT_COND _("incorrect condition in IT block") | |
712 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 713 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
714 | #define BAD_PC_ADDRESSING \ |
715 | _("cannot use register index with PC-relative addressing") | |
716 | #define BAD_PC_WRITEBACK \ | |
717 | _("cannot use writeback with PC-relative addressing") | |
c19d1205 | 718 | |
c921be7d NC |
719 | static struct hash_control * arm_ops_hsh; |
720 | static struct hash_control * arm_cond_hsh; | |
721 | static struct hash_control * arm_shift_hsh; | |
722 | static struct hash_control * arm_psr_hsh; | |
723 | static struct hash_control * arm_v7m_psr_hsh; | |
724 | static struct hash_control * arm_reg_hsh; | |
725 | static struct hash_control * arm_reloc_hsh; | |
726 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 727 | |
b99bd4ef NC |
728 | /* Stuff needed to resolve the label ambiguity |
729 | As: | |
730 | ... | |
731 | label: <insn> | |
732 | may differ from: | |
733 | ... | |
734 | label: | |
5f4273c7 | 735 | <insn> */ |
b99bd4ef NC |
736 | |
737 | symbolS * last_label_seen; | |
b34976b6 | 738 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 739 | |
3d0c9500 NC |
740 | /* Literal pool structure. Held on a per-section |
741 | and per-sub-section basis. */ | |
a737bd4d | 742 | |
c19d1205 | 743 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 744 | typedef struct literal_pool |
b99bd4ef | 745 | { |
c921be7d NC |
746 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
747 | unsigned int next_free_entry; | |
748 | unsigned int id; | |
749 | symbolS * symbol; | |
750 | segT section; | |
751 | subsegT sub_section; | |
752 | struct literal_pool * next; | |
3d0c9500 | 753 | } literal_pool; |
b99bd4ef | 754 | |
3d0c9500 NC |
755 | /* Pointer to a linked list of literal pools. */ |
756 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 757 | |
e07e6e58 NC |
758 | #ifdef OBJ_ELF |
759 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
760 | #else | |
761 | static struct current_it now_it; | |
762 | #endif | |
763 | ||
764 | static inline int | |
765 | now_it_compatible (int cond) | |
766 | { | |
767 | return (cond & ~1) == (now_it.cc & ~1); | |
768 | } | |
769 | ||
770 | static inline int | |
771 | conditional_insn (void) | |
772 | { | |
773 | return inst.cond != COND_ALWAYS; | |
774 | } | |
775 | ||
776 | static int in_it_block (void); | |
777 | ||
778 | static int handle_it_state (void); | |
779 | ||
780 | static void force_automatic_it_block_close (void); | |
781 | ||
c921be7d NC |
782 | static void it_fsm_post_encode (void); |
783 | ||
e07e6e58 NC |
784 | #define set_it_insn_type(type) \ |
785 | do \ | |
786 | { \ | |
787 | inst.it_insn_type = type; \ | |
788 | if (handle_it_state () == FAIL) \ | |
789 | return; \ | |
790 | } \ | |
791 | while (0) | |
792 | ||
c921be7d NC |
793 | #define set_it_insn_type_nonvoid(type, failret) \ |
794 | do \ | |
795 | { \ | |
796 | inst.it_insn_type = type; \ | |
797 | if (handle_it_state () == FAIL) \ | |
798 | return failret; \ | |
799 | } \ | |
800 | while(0) | |
801 | ||
e07e6e58 NC |
802 | #define set_it_insn_type_last() \ |
803 | do \ | |
804 | { \ | |
805 | if (inst.cond == COND_ALWAYS) \ | |
806 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ | |
807 | else \ | |
808 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ | |
809 | } \ | |
810 | while (0) | |
811 | ||
c19d1205 | 812 | /* Pure syntax. */ |
b99bd4ef | 813 | |
c19d1205 ZW |
814 | /* This array holds the chars that always start a comment. If the |
815 | pre-processor is disabled, these aren't very useful. */ | |
816 | const char comment_chars[] = "@"; | |
3d0c9500 | 817 | |
c19d1205 ZW |
818 | /* This array holds the chars that only start a comment at the beginning of |
819 | a line. If the line seems to have the form '# 123 filename' | |
820 | .line and .file directives will appear in the pre-processed output. */ | |
821 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
822 | first line of the input file. This is because the compiler outputs | |
823 | #NO_APP at the beginning of its output. */ | |
824 | /* Also note that comments like this one will always work. */ | |
825 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 826 | |
c19d1205 | 827 | const char line_separator_chars[] = ";"; |
b99bd4ef | 828 | |
c19d1205 ZW |
829 | /* Chars that can be used to separate mant |
830 | from exp in floating point numbers. */ | |
831 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 832 | |
c19d1205 ZW |
833 | /* Chars that mean this number is a floating point constant. */ |
834 | /* As in 0f12.456 */ | |
835 | /* or 0d1.2345e12 */ | |
b99bd4ef | 836 | |
c19d1205 | 837 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 838 | |
c19d1205 ZW |
839 | /* Prefix characters that indicate the start of an immediate |
840 | value. */ | |
841 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 842 | |
c19d1205 ZW |
843 | /* Separator character handling. */ |
844 | ||
845 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
846 | ||
847 | static inline int | |
848 | skip_past_char (char ** str, char c) | |
849 | { | |
850 | if (**str == c) | |
851 | { | |
852 | (*str)++; | |
853 | return SUCCESS; | |
3d0c9500 | 854 | } |
c19d1205 ZW |
855 | else |
856 | return FAIL; | |
857 | } | |
c921be7d | 858 | |
c19d1205 | 859 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 860 | |
c19d1205 ZW |
861 | /* Arithmetic expressions (possibly involving symbols). */ |
862 | ||
863 | /* Return TRUE if anything in the expression is a bignum. */ | |
864 | ||
865 | static int | |
866 | walk_no_bignums (symbolS * sp) | |
867 | { | |
868 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
869 | return 1; | |
870 | ||
871 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 872 | { |
c19d1205 ZW |
873 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
874 | || (symbol_get_value_expression (sp)->X_op_symbol | |
875 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
876 | } |
877 | ||
c19d1205 | 878 | return 0; |
3d0c9500 NC |
879 | } |
880 | ||
c19d1205 ZW |
881 | static int in_my_get_expression = 0; |
882 | ||
883 | /* Third argument to my_get_expression. */ | |
884 | #define GE_NO_PREFIX 0 | |
885 | #define GE_IMM_PREFIX 1 | |
886 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
887 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
888 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
889 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 890 | |
b99bd4ef | 891 | static int |
c19d1205 | 892 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 893 | { |
c19d1205 ZW |
894 | char * save_in; |
895 | segT seg; | |
b99bd4ef | 896 | |
c19d1205 ZW |
897 | /* In unified syntax, all prefixes are optional. */ |
898 | if (unified_syntax) | |
5287ad62 JB |
899 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
900 | : GE_OPT_PREFIX; | |
b99bd4ef | 901 | |
c19d1205 | 902 | switch (prefix_mode) |
b99bd4ef | 903 | { |
c19d1205 ZW |
904 | case GE_NO_PREFIX: break; |
905 | case GE_IMM_PREFIX: | |
906 | if (!is_immediate_prefix (**str)) | |
907 | { | |
908 | inst.error = _("immediate expression requires a # prefix"); | |
909 | return FAIL; | |
910 | } | |
911 | (*str)++; | |
912 | break; | |
913 | case GE_OPT_PREFIX: | |
5287ad62 | 914 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
915 | if (is_immediate_prefix (**str)) |
916 | (*str)++; | |
917 | break; | |
918 | default: abort (); | |
919 | } | |
b99bd4ef | 920 | |
c19d1205 | 921 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 922 | |
c19d1205 ZW |
923 | save_in = input_line_pointer; |
924 | input_line_pointer = *str; | |
925 | in_my_get_expression = 1; | |
926 | seg = expression (ep); | |
927 | in_my_get_expression = 0; | |
928 | ||
f86adc07 | 929 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 930 | { |
f86adc07 | 931 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
932 | *str = input_line_pointer; |
933 | input_line_pointer = save_in; | |
934 | if (inst.error == NULL) | |
f86adc07 NS |
935 | inst.error = (ep->X_op == O_absent |
936 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
937 | return 1; |
938 | } | |
b99bd4ef | 939 | |
c19d1205 ZW |
940 | #ifdef OBJ_AOUT |
941 | if (seg != absolute_section | |
942 | && seg != text_section | |
943 | && seg != data_section | |
944 | && seg != bss_section | |
945 | && seg != undefined_section) | |
946 | { | |
947 | inst.error = _("bad segment"); | |
948 | *str = input_line_pointer; | |
949 | input_line_pointer = save_in; | |
950 | return 1; | |
b99bd4ef | 951 | } |
87975d2a AM |
952 | #else |
953 | (void) seg; | |
c19d1205 | 954 | #endif |
b99bd4ef | 955 | |
c19d1205 ZW |
956 | /* Get rid of any bignums now, so that we don't generate an error for which |
957 | we can't establish a line number later on. Big numbers are never valid | |
958 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
959 | if (prefix_mode != GE_OPT_PREFIX_BIG |
960 | && (ep->X_op == O_big | |
961 | || (ep->X_add_symbol | |
962 | && (walk_no_bignums (ep->X_add_symbol) | |
963 | || (ep->X_op_symbol | |
964 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
965 | { |
966 | inst.error = _("invalid constant"); | |
967 | *str = input_line_pointer; | |
968 | input_line_pointer = save_in; | |
969 | return 1; | |
970 | } | |
b99bd4ef | 971 | |
c19d1205 ZW |
972 | *str = input_line_pointer; |
973 | input_line_pointer = save_in; | |
974 | return 0; | |
b99bd4ef NC |
975 | } |
976 | ||
c19d1205 ZW |
977 | /* Turn a string in input_line_pointer into a floating point constant |
978 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
979 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
980 | returned, or NULL on OK. | |
b99bd4ef | 981 | |
c19d1205 ZW |
982 | Note that fp constants aren't represent in the normal way on the ARM. |
983 | In big endian mode, things are as expected. However, in little endian | |
984 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
985 | within the words. For example, (double) 1.1 in big endian mode is | |
986 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
987 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 988 | |
c19d1205 | 989 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 990 | |
c19d1205 ZW |
991 | char * |
992 | md_atof (int type, char * litP, int * sizeP) | |
993 | { | |
994 | int prec; | |
995 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
996 | char *t; | |
997 | int i; | |
b99bd4ef | 998 | |
c19d1205 ZW |
999 | switch (type) |
1000 | { | |
1001 | case 'f': | |
1002 | case 'F': | |
1003 | case 's': | |
1004 | case 'S': | |
1005 | prec = 2; | |
1006 | break; | |
b99bd4ef | 1007 | |
c19d1205 ZW |
1008 | case 'd': |
1009 | case 'D': | |
1010 | case 'r': | |
1011 | case 'R': | |
1012 | prec = 4; | |
1013 | break; | |
b99bd4ef | 1014 | |
c19d1205 ZW |
1015 | case 'x': |
1016 | case 'X': | |
499ac353 | 1017 | prec = 5; |
c19d1205 | 1018 | break; |
b99bd4ef | 1019 | |
c19d1205 ZW |
1020 | case 'p': |
1021 | case 'P': | |
499ac353 | 1022 | prec = 5; |
c19d1205 | 1023 | break; |
a737bd4d | 1024 | |
c19d1205 ZW |
1025 | default: |
1026 | *sizeP = 0; | |
499ac353 | 1027 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1028 | } |
b99bd4ef | 1029 | |
c19d1205 ZW |
1030 | t = atof_ieee (input_line_pointer, type, words); |
1031 | if (t) | |
1032 | input_line_pointer = t; | |
499ac353 | 1033 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1034 | |
c19d1205 ZW |
1035 | if (target_big_endian) |
1036 | { | |
1037 | for (i = 0; i < prec; i++) | |
1038 | { | |
499ac353 NC |
1039 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1040 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1041 | } |
1042 | } | |
1043 | else | |
1044 | { | |
e74cfd16 | 1045 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1046 | for (i = prec - 1; i >= 0; i--) |
1047 | { | |
499ac353 NC |
1048 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1049 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1050 | } |
1051 | else | |
1052 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1053 | For an 8 byte float the order is 1 0 3 2. */ | |
1054 | for (i = 0; i < prec; i += 2) | |
1055 | { | |
499ac353 NC |
1056 | md_number_to_chars (litP, (valueT) words[i + 1], |
1057 | sizeof (LITTLENUM_TYPE)); | |
1058 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1059 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1060 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1061 | } |
1062 | } | |
b99bd4ef | 1063 | |
499ac353 | 1064 | return NULL; |
c19d1205 | 1065 | } |
b99bd4ef | 1066 | |
c19d1205 ZW |
1067 | /* We handle all bad expressions here, so that we can report the faulty |
1068 | instruction in the error message. */ | |
1069 | void | |
91d6fa6a | 1070 | md_operand (expressionS * exp) |
c19d1205 ZW |
1071 | { |
1072 | if (in_my_get_expression) | |
91d6fa6a | 1073 | exp->X_op = O_illegal; |
b99bd4ef NC |
1074 | } |
1075 | ||
c19d1205 | 1076 | /* Immediate values. */ |
b99bd4ef | 1077 | |
c19d1205 ZW |
1078 | /* Generic immediate-value read function for use in directives. |
1079 | Accepts anything that 'expression' can fold to a constant. | |
1080 | *val receives the number. */ | |
1081 | #ifdef OBJ_ELF | |
1082 | static int | |
1083 | immediate_for_directive (int *val) | |
b99bd4ef | 1084 | { |
c19d1205 ZW |
1085 | expressionS exp; |
1086 | exp.X_op = O_illegal; | |
b99bd4ef | 1087 | |
c19d1205 ZW |
1088 | if (is_immediate_prefix (*input_line_pointer)) |
1089 | { | |
1090 | input_line_pointer++; | |
1091 | expression (&exp); | |
1092 | } | |
b99bd4ef | 1093 | |
c19d1205 ZW |
1094 | if (exp.X_op != O_constant) |
1095 | { | |
1096 | as_bad (_("expected #constant")); | |
1097 | ignore_rest_of_line (); | |
1098 | return FAIL; | |
1099 | } | |
1100 | *val = exp.X_add_number; | |
1101 | return SUCCESS; | |
b99bd4ef | 1102 | } |
c19d1205 | 1103 | #endif |
b99bd4ef | 1104 | |
c19d1205 | 1105 | /* Register parsing. */ |
b99bd4ef | 1106 | |
c19d1205 ZW |
1107 | /* Generic register parser. CCP points to what should be the |
1108 | beginning of a register name. If it is indeed a valid register | |
1109 | name, advance CCP over it and return the reg_entry structure; | |
1110 | otherwise return NULL. Does not issue diagnostics. */ | |
1111 | ||
1112 | static struct reg_entry * | |
1113 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1114 | { |
c19d1205 ZW |
1115 | char *start = *ccp; |
1116 | char *p; | |
1117 | struct reg_entry *reg; | |
b99bd4ef | 1118 | |
c19d1205 ZW |
1119 | #ifdef REGISTER_PREFIX |
1120 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1121 | return NULL; |
c19d1205 ZW |
1122 | start++; |
1123 | #endif | |
1124 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1125 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1126 | start++; | |
1127 | #endif | |
b99bd4ef | 1128 | |
c19d1205 ZW |
1129 | p = start; |
1130 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1131 | return NULL; | |
b99bd4ef | 1132 | |
c19d1205 ZW |
1133 | do |
1134 | p++; | |
1135 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1136 | ||
1137 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1138 | ||
1139 | if (!reg) | |
1140 | return NULL; | |
1141 | ||
1142 | *ccp = p; | |
1143 | return reg; | |
b99bd4ef NC |
1144 | } |
1145 | ||
1146 | static int | |
dcbf9037 JB |
1147 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1148 | enum arm_reg_type type) | |
b99bd4ef | 1149 | { |
c19d1205 ZW |
1150 | /* Alternative syntaxes are accepted for a few register classes. */ |
1151 | switch (type) | |
1152 | { | |
1153 | case REG_TYPE_MVF: | |
1154 | case REG_TYPE_MVD: | |
1155 | case REG_TYPE_MVFX: | |
1156 | case REG_TYPE_MVDX: | |
1157 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1158 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1159 | return reg->number; |
1160 | break; | |
69b97547 | 1161 | |
c19d1205 ZW |
1162 | case REG_TYPE_CP: |
1163 | /* For backward compatibility, a bare number is valid here. */ | |
1164 | { | |
1165 | unsigned long processor = strtoul (start, ccp, 10); | |
1166 | if (*ccp != start && processor <= 15) | |
1167 | return processor; | |
1168 | } | |
6057a28f | 1169 | |
c19d1205 ZW |
1170 | case REG_TYPE_MMXWC: |
1171 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1172 | instructions that take WC registers. */ | |
79134647 | 1173 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1174 | return reg->number; |
6057a28f | 1175 | break; |
c19d1205 | 1176 | |
6057a28f | 1177 | default: |
c19d1205 | 1178 | break; |
6057a28f NC |
1179 | } |
1180 | ||
dcbf9037 JB |
1181 | return FAIL; |
1182 | } | |
1183 | ||
1184 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1185 | return value is the register number or FAIL. */ | |
1186 | ||
1187 | static int | |
1188 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1189 | { | |
1190 | char *start = *ccp; | |
1191 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1192 | int ret; | |
1193 | ||
1194 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1195 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1196 | return FAIL; | |
1197 | ||
1198 | if (reg && reg->type == type) | |
1199 | return reg->number; | |
1200 | ||
1201 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1202 | return ret; | |
1203 | ||
c19d1205 ZW |
1204 | *ccp = start; |
1205 | return FAIL; | |
1206 | } | |
69b97547 | 1207 | |
dcbf9037 JB |
1208 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1209 | character. Does no verification at this stage that the type fits the opcode | |
1210 | properly. E.g., | |
1211 | ||
1212 | .i32.i32.s16 | |
1213 | .s32.f32 | |
1214 | .u16 | |
1215 | ||
1216 | Can all be legally parsed by this function. | |
1217 | ||
1218 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1219 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1220 | type, FAIL if not. */ | |
1221 | ||
1222 | static int | |
1223 | parse_neon_type (struct neon_type *type, char **str) | |
1224 | { | |
1225 | char *ptr = *str; | |
1226 | ||
1227 | if (type) | |
1228 | type->elems = 0; | |
1229 | ||
1230 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1231 | { | |
1232 | enum neon_el_type thistype = NT_untyped; | |
1233 | unsigned thissize = -1u; | |
1234 | ||
1235 | if (*ptr != '.') | |
1236 | break; | |
1237 | ||
1238 | ptr++; | |
1239 | ||
1240 | /* Just a size without an explicit type. */ | |
1241 | if (ISDIGIT (*ptr)) | |
1242 | goto parsesize; | |
1243 | ||
1244 | switch (TOLOWER (*ptr)) | |
1245 | { | |
1246 | case 'i': thistype = NT_integer; break; | |
1247 | case 'f': thistype = NT_float; break; | |
1248 | case 'p': thistype = NT_poly; break; | |
1249 | case 's': thistype = NT_signed; break; | |
1250 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1251 | case 'd': |
1252 | thistype = NT_float; | |
1253 | thissize = 64; | |
1254 | ptr++; | |
1255 | goto done; | |
dcbf9037 JB |
1256 | default: |
1257 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1258 | return FAIL; | |
1259 | } | |
1260 | ||
1261 | ptr++; | |
1262 | ||
1263 | /* .f is an abbreviation for .f32. */ | |
1264 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1265 | thissize = 32; | |
1266 | else | |
1267 | { | |
1268 | parsesize: | |
1269 | thissize = strtoul (ptr, &ptr, 10); | |
1270 | ||
1271 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1272 | && thissize != 64) | |
1273 | { | |
1274 | as_bad (_("bad size %d in type specifier"), thissize); | |
1275 | return FAIL; | |
1276 | } | |
1277 | } | |
1278 | ||
037e8744 | 1279 | done: |
dcbf9037 JB |
1280 | if (type) |
1281 | { | |
1282 | type->el[type->elems].type = thistype; | |
1283 | type->el[type->elems].size = thissize; | |
1284 | type->elems++; | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | /* Empty/missing type is not a successful parse. */ | |
1289 | if (type->elems == 0) | |
1290 | return FAIL; | |
1291 | ||
1292 | *str = ptr; | |
1293 | ||
1294 | return SUCCESS; | |
1295 | } | |
1296 | ||
1297 | /* Errors may be set multiple times during parsing or bit encoding | |
1298 | (particularly in the Neon bits), but usually the earliest error which is set | |
1299 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1300 | errors by calling this function. */ | |
1301 | ||
1302 | static void | |
1303 | first_error (const char *err) | |
1304 | { | |
1305 | if (!inst.error) | |
1306 | inst.error = err; | |
1307 | } | |
1308 | ||
1309 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1310 | static int | |
1311 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1312 | { | |
1313 | char *str = *ccp; | |
1314 | struct neon_type optype; | |
1315 | ||
1316 | if (*str == '.') | |
1317 | { | |
1318 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1319 | { | |
1320 | if (optype.elems == 1) | |
1321 | *vectype = optype.el[0]; | |
1322 | else | |
1323 | { | |
1324 | first_error (_("only one type should be specified for operand")); | |
1325 | return FAIL; | |
1326 | } | |
1327 | } | |
1328 | else | |
1329 | { | |
1330 | first_error (_("vector type expected")); | |
1331 | return FAIL; | |
1332 | } | |
1333 | } | |
1334 | else | |
1335 | return FAIL; | |
5f4273c7 | 1336 | |
dcbf9037 | 1337 | *ccp = str; |
5f4273c7 | 1338 | |
dcbf9037 JB |
1339 | return SUCCESS; |
1340 | } | |
1341 | ||
1342 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1343 | a 4-bit integer. */ | |
1344 | ||
1345 | #define NEON_ALL_LANES 15 | |
1346 | #define NEON_INTERLEAVE_LANES 14 | |
1347 | ||
1348 | /* Parse either a register or a scalar, with an optional type. Return the | |
1349 | register number, and optionally fill in the actual type of the register | |
1350 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1351 | type/index information in *TYPEINFO. */ | |
1352 | ||
1353 | static int | |
1354 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1355 | enum arm_reg_type *rtype, | |
1356 | struct neon_typed_alias *typeinfo) | |
1357 | { | |
1358 | char *str = *ccp; | |
1359 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1360 | struct neon_typed_alias atype; | |
1361 | struct neon_type_el parsetype; | |
1362 | ||
1363 | atype.defined = 0; | |
1364 | atype.index = -1; | |
1365 | atype.eltype.type = NT_invtype; | |
1366 | atype.eltype.size = -1; | |
1367 | ||
1368 | /* Try alternate syntax for some types of register. Note these are mutually | |
1369 | exclusive with the Neon syntax extensions. */ | |
1370 | if (reg == NULL) | |
1371 | { | |
1372 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1373 | if (altreg != FAIL) | |
1374 | *ccp = str; | |
1375 | if (typeinfo) | |
1376 | *typeinfo = atype; | |
1377 | return altreg; | |
1378 | } | |
1379 | ||
037e8744 JB |
1380 | /* Undo polymorphism when a set of register types may be accepted. */ |
1381 | if ((type == REG_TYPE_NDQ | |
1382 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1383 | || (type == REG_TYPE_VFSD | |
1384 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1385 | || (type == REG_TYPE_NSDQ | |
1386 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
f512f76f NC |
1387 | || reg->type == REG_TYPE_NQ)) |
1388 | || (type == REG_TYPE_MMXWC | |
1389 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1390 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1391 | |
1392 | if (type != reg->type) | |
1393 | return FAIL; | |
1394 | ||
1395 | if (reg->neon) | |
1396 | atype = *reg->neon; | |
5f4273c7 | 1397 | |
dcbf9037 JB |
1398 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1399 | { | |
1400 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1401 | { | |
1402 | first_error (_("can't redefine type for operand")); | |
1403 | return FAIL; | |
1404 | } | |
1405 | atype.defined |= NTA_HASTYPE; | |
1406 | atype.eltype = parsetype; | |
1407 | } | |
5f4273c7 | 1408 | |
dcbf9037 JB |
1409 | if (skip_past_char (&str, '[') == SUCCESS) |
1410 | { | |
1411 | if (type != REG_TYPE_VFD) | |
1412 | { | |
1413 | first_error (_("only D registers may be indexed")); | |
1414 | return FAIL; | |
1415 | } | |
5f4273c7 | 1416 | |
dcbf9037 JB |
1417 | if ((atype.defined & NTA_HASINDEX) != 0) |
1418 | { | |
1419 | first_error (_("can't change index for operand")); | |
1420 | return FAIL; | |
1421 | } | |
1422 | ||
1423 | atype.defined |= NTA_HASINDEX; | |
1424 | ||
1425 | if (skip_past_char (&str, ']') == SUCCESS) | |
1426 | atype.index = NEON_ALL_LANES; | |
1427 | else | |
1428 | { | |
1429 | expressionS exp; | |
1430 | ||
1431 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1432 | ||
1433 | if (exp.X_op != O_constant) | |
1434 | { | |
1435 | first_error (_("constant expression required")); | |
1436 | return FAIL; | |
1437 | } | |
1438 | ||
1439 | if (skip_past_char (&str, ']') == FAIL) | |
1440 | return FAIL; | |
1441 | ||
1442 | atype.index = exp.X_add_number; | |
1443 | } | |
1444 | } | |
5f4273c7 | 1445 | |
dcbf9037 JB |
1446 | if (typeinfo) |
1447 | *typeinfo = atype; | |
5f4273c7 | 1448 | |
dcbf9037 JB |
1449 | if (rtype) |
1450 | *rtype = type; | |
5f4273c7 | 1451 | |
dcbf9037 | 1452 | *ccp = str; |
5f4273c7 | 1453 | |
dcbf9037 JB |
1454 | return reg->number; |
1455 | } | |
1456 | ||
1457 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1458 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1459 | register (e.g. Neon double or quad reg when either has been requested). | |
1460 | - If this is a Neon vector type with additional type information, fill | |
1461 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1462 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1463 | |
1464 | static int | |
1465 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1466 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1467 | { | |
1468 | struct neon_typed_alias atype; | |
1469 | char *str = *ccp; | |
1470 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1471 | ||
1472 | if (reg == FAIL) | |
1473 | return FAIL; | |
1474 | ||
1475 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1476 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1477 | { | |
1478 | first_error (_("register operand expected, but got scalar")); | |
1479 | return FAIL; | |
1480 | } | |
1481 | ||
1482 | if (vectype) | |
1483 | *vectype = atype.eltype; | |
1484 | ||
1485 | *ccp = str; | |
1486 | ||
1487 | return reg; | |
1488 | } | |
1489 | ||
1490 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1491 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1492 | ||
5287ad62 JB |
1493 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1494 | have enough information to be able to do a good job bounds-checking. So, we | |
1495 | just do easy checks here, and do further checks later. */ | |
1496 | ||
1497 | static int | |
dcbf9037 | 1498 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1499 | { |
dcbf9037 | 1500 | int reg; |
5287ad62 | 1501 | char *str = *ccp; |
dcbf9037 | 1502 | struct neon_typed_alias atype; |
5f4273c7 | 1503 | |
dcbf9037 | 1504 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1505 | |
dcbf9037 | 1506 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1507 | return FAIL; |
5f4273c7 | 1508 | |
dcbf9037 | 1509 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1510 | { |
dcbf9037 | 1511 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1512 | return FAIL; |
1513 | } | |
dcbf9037 | 1514 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1515 | { |
dcbf9037 | 1516 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1517 | return FAIL; |
1518 | } | |
5f4273c7 | 1519 | |
dcbf9037 JB |
1520 | if (type) |
1521 | *type = atype.eltype; | |
5f4273c7 | 1522 | |
5287ad62 | 1523 | *ccp = str; |
5f4273c7 | 1524 | |
dcbf9037 | 1525 | return reg * 16 + atype.index; |
5287ad62 JB |
1526 | } |
1527 | ||
c19d1205 | 1528 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1529 | |
c19d1205 ZW |
1530 | static long |
1531 | parse_reg_list (char ** strp) | |
1532 | { | |
1533 | char * str = * strp; | |
1534 | long range = 0; | |
1535 | int another_range; | |
a737bd4d | 1536 | |
c19d1205 ZW |
1537 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1538 | do | |
6057a28f | 1539 | { |
c19d1205 | 1540 | another_range = 0; |
a737bd4d | 1541 | |
c19d1205 ZW |
1542 | if (*str == '{') |
1543 | { | |
1544 | int in_range = 0; | |
1545 | int cur_reg = -1; | |
a737bd4d | 1546 | |
c19d1205 ZW |
1547 | str++; |
1548 | do | |
1549 | { | |
1550 | int reg; | |
6057a28f | 1551 | |
dcbf9037 | 1552 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1553 | { |
dcbf9037 | 1554 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1555 | return FAIL; |
1556 | } | |
a737bd4d | 1557 | |
c19d1205 ZW |
1558 | if (in_range) |
1559 | { | |
1560 | int i; | |
a737bd4d | 1561 | |
c19d1205 ZW |
1562 | if (reg <= cur_reg) |
1563 | { | |
dcbf9037 | 1564 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1565 | return FAIL; |
1566 | } | |
40a18ebd | 1567 | |
c19d1205 ZW |
1568 | for (i = cur_reg + 1; i < reg; i++) |
1569 | { | |
1570 | if (range & (1 << i)) | |
1571 | as_tsktsk | |
1572 | (_("Warning: duplicated register (r%d) in register list"), | |
1573 | i); | |
1574 | else | |
1575 | range |= 1 << i; | |
1576 | } | |
1577 | in_range = 0; | |
1578 | } | |
a737bd4d | 1579 | |
c19d1205 ZW |
1580 | if (range & (1 << reg)) |
1581 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1582 | reg); | |
1583 | else if (reg <= cur_reg) | |
1584 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1585 | |
c19d1205 ZW |
1586 | range |= 1 << reg; |
1587 | cur_reg = reg; | |
1588 | } | |
1589 | while (skip_past_comma (&str) != FAIL | |
1590 | || (in_range = 1, *str++ == '-')); | |
1591 | str--; | |
a737bd4d | 1592 | |
c19d1205 ZW |
1593 | if (*str++ != '}') |
1594 | { | |
dcbf9037 | 1595 | first_error (_("missing `}'")); |
c19d1205 ZW |
1596 | return FAIL; |
1597 | } | |
1598 | } | |
1599 | else | |
1600 | { | |
91d6fa6a | 1601 | expressionS exp; |
40a18ebd | 1602 | |
91d6fa6a | 1603 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1604 | return FAIL; |
40a18ebd | 1605 | |
91d6fa6a | 1606 | if (exp.X_op == O_constant) |
c19d1205 | 1607 | { |
91d6fa6a NC |
1608 | if (exp.X_add_number |
1609 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1610 | { |
1611 | inst.error = _("invalid register mask"); | |
1612 | return FAIL; | |
1613 | } | |
a737bd4d | 1614 | |
91d6fa6a | 1615 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1616 | { |
91d6fa6a | 1617 | int regno = range & exp.X_add_number; |
a737bd4d | 1618 | |
c19d1205 ZW |
1619 | regno &= -regno; |
1620 | regno = (1 << regno) - 1; | |
1621 | as_tsktsk | |
1622 | (_("Warning: duplicated register (r%d) in register list"), | |
1623 | regno); | |
1624 | } | |
a737bd4d | 1625 | |
91d6fa6a | 1626 | range |= exp.X_add_number; |
c19d1205 ZW |
1627 | } |
1628 | else | |
1629 | { | |
1630 | if (inst.reloc.type != 0) | |
1631 | { | |
1632 | inst.error = _("expression too complex"); | |
1633 | return FAIL; | |
1634 | } | |
a737bd4d | 1635 | |
91d6fa6a | 1636 | memcpy (&inst.reloc.exp, &exp, sizeof (expressionS)); |
c19d1205 ZW |
1637 | inst.reloc.type = BFD_RELOC_ARM_MULTI; |
1638 | inst.reloc.pc_rel = 0; | |
1639 | } | |
1640 | } | |
a737bd4d | 1641 | |
c19d1205 ZW |
1642 | if (*str == '|' || *str == '+') |
1643 | { | |
1644 | str++; | |
1645 | another_range = 1; | |
1646 | } | |
a737bd4d | 1647 | } |
c19d1205 | 1648 | while (another_range); |
a737bd4d | 1649 | |
c19d1205 ZW |
1650 | *strp = str; |
1651 | return range; | |
a737bd4d NC |
1652 | } |
1653 | ||
5287ad62 JB |
1654 | /* Types of registers in a list. */ |
1655 | ||
1656 | enum reg_list_els | |
1657 | { | |
1658 | REGLIST_VFP_S, | |
1659 | REGLIST_VFP_D, | |
1660 | REGLIST_NEON_D | |
1661 | }; | |
1662 | ||
c19d1205 ZW |
1663 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1664 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1665 | register. Parses registers of type ETYPE. |
1666 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1667 | - Q registers can be used to specify pairs of D registers | |
1668 | - { } can be omitted from around a singleton register list | |
1669 | FIXME: This is not implemented, as it would require backtracking in | |
1670 | some cases, e.g.: | |
1671 | vtbl.8 d3,d4,d5 | |
1672 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1673 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1674 | - 32 D registers may be used (also true for VFPv3). |
1675 | FIXME: Types are ignored in these register lists, which is probably a | |
1676 | bug. */ | |
6057a28f | 1677 | |
c19d1205 | 1678 | static int |
037e8744 | 1679 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1680 | { |
037e8744 | 1681 | char *str = *ccp; |
c19d1205 ZW |
1682 | int base_reg; |
1683 | int new_base; | |
21d799b5 | 1684 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1685 | int max_regs = 0; |
c19d1205 ZW |
1686 | int count = 0; |
1687 | int warned = 0; | |
1688 | unsigned long mask = 0; | |
a737bd4d | 1689 | int i; |
6057a28f | 1690 | |
037e8744 | 1691 | if (*str != '{') |
5287ad62 JB |
1692 | { |
1693 | inst.error = _("expecting {"); | |
1694 | return FAIL; | |
1695 | } | |
6057a28f | 1696 | |
037e8744 | 1697 | str++; |
6057a28f | 1698 | |
5287ad62 | 1699 | switch (etype) |
c19d1205 | 1700 | { |
5287ad62 | 1701 | case REGLIST_VFP_S: |
c19d1205 ZW |
1702 | regtype = REG_TYPE_VFS; |
1703 | max_regs = 32; | |
5287ad62 | 1704 | break; |
5f4273c7 | 1705 | |
5287ad62 JB |
1706 | case REGLIST_VFP_D: |
1707 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1708 | break; |
5f4273c7 | 1709 | |
b7fc2769 JB |
1710 | case REGLIST_NEON_D: |
1711 | regtype = REG_TYPE_NDQ; | |
1712 | break; | |
1713 | } | |
1714 | ||
1715 | if (etype != REGLIST_VFP_S) | |
1716 | { | |
b1cc4aeb PB |
1717 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1718 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
5287ad62 JB |
1719 | { |
1720 | max_regs = 32; | |
1721 | if (thumb_mode) | |
1722 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 1723 | fpu_vfp_ext_d32); |
5287ad62 JB |
1724 | else |
1725 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 1726 | fpu_vfp_ext_d32); |
5287ad62 JB |
1727 | } |
1728 | else | |
1729 | max_regs = 16; | |
c19d1205 | 1730 | } |
6057a28f | 1731 | |
c19d1205 | 1732 | base_reg = max_regs; |
a737bd4d | 1733 | |
c19d1205 ZW |
1734 | do |
1735 | { | |
5287ad62 | 1736 | int setmask = 1, addregs = 1; |
dcbf9037 | 1737 | |
037e8744 | 1738 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1739 | |
c19d1205 | 1740 | if (new_base == FAIL) |
a737bd4d | 1741 | { |
dcbf9037 | 1742 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1743 | return FAIL; |
1744 | } | |
5f4273c7 | 1745 | |
b7fc2769 JB |
1746 | if (new_base >= max_regs) |
1747 | { | |
1748 | first_error (_("register out of range in list")); | |
1749 | return FAIL; | |
1750 | } | |
5f4273c7 | 1751 | |
5287ad62 JB |
1752 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1753 | if (regtype == REG_TYPE_NQ) | |
1754 | { | |
1755 | setmask = 3; | |
1756 | addregs = 2; | |
1757 | } | |
1758 | ||
c19d1205 ZW |
1759 | if (new_base < base_reg) |
1760 | base_reg = new_base; | |
a737bd4d | 1761 | |
5287ad62 | 1762 | if (mask & (setmask << new_base)) |
c19d1205 | 1763 | { |
dcbf9037 | 1764 | first_error (_("invalid register list")); |
c19d1205 | 1765 | return FAIL; |
a737bd4d | 1766 | } |
a737bd4d | 1767 | |
c19d1205 ZW |
1768 | if ((mask >> new_base) != 0 && ! warned) |
1769 | { | |
1770 | as_tsktsk (_("register list not in ascending order")); | |
1771 | warned = 1; | |
1772 | } | |
0bbf2aa4 | 1773 | |
5287ad62 JB |
1774 | mask |= setmask << new_base; |
1775 | count += addregs; | |
0bbf2aa4 | 1776 | |
037e8744 | 1777 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1778 | { |
1779 | int high_range; | |
0bbf2aa4 | 1780 | |
037e8744 | 1781 | str++; |
0bbf2aa4 | 1782 | |
037e8744 | 1783 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1784 | == FAIL) |
c19d1205 ZW |
1785 | { |
1786 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1787 | return FAIL; | |
1788 | } | |
0bbf2aa4 | 1789 | |
b7fc2769 JB |
1790 | if (high_range >= max_regs) |
1791 | { | |
1792 | first_error (_("register out of range in list")); | |
1793 | return FAIL; | |
1794 | } | |
1795 | ||
5287ad62 JB |
1796 | if (regtype == REG_TYPE_NQ) |
1797 | high_range = high_range + 1; | |
1798 | ||
c19d1205 ZW |
1799 | if (high_range <= new_base) |
1800 | { | |
1801 | inst.error = _("register range not in ascending order"); | |
1802 | return FAIL; | |
1803 | } | |
0bbf2aa4 | 1804 | |
5287ad62 | 1805 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1806 | { |
5287ad62 | 1807 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1808 | { |
c19d1205 ZW |
1809 | inst.error = _("invalid register list"); |
1810 | return FAIL; | |
0bbf2aa4 | 1811 | } |
c19d1205 | 1812 | |
5287ad62 JB |
1813 | mask |= setmask << new_base; |
1814 | count += addregs; | |
0bbf2aa4 | 1815 | } |
0bbf2aa4 | 1816 | } |
0bbf2aa4 | 1817 | } |
037e8744 | 1818 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1819 | |
037e8744 | 1820 | str++; |
0bbf2aa4 | 1821 | |
c19d1205 ZW |
1822 | /* Sanity check -- should have raised a parse error above. */ |
1823 | if (count == 0 || count > max_regs) | |
1824 | abort (); | |
1825 | ||
1826 | *pbase = base_reg; | |
1827 | ||
1828 | /* Final test -- the registers must be consecutive. */ | |
1829 | mask >>= base_reg; | |
1830 | for (i = 0; i < count; i++) | |
1831 | { | |
1832 | if ((mask & (1u << i)) == 0) | |
1833 | { | |
1834 | inst.error = _("non-contiguous register range"); | |
1835 | return FAIL; | |
1836 | } | |
1837 | } | |
1838 | ||
037e8744 JB |
1839 | *ccp = str; |
1840 | ||
c19d1205 | 1841 | return count; |
b99bd4ef NC |
1842 | } |
1843 | ||
dcbf9037 JB |
1844 | /* True if two alias types are the same. */ |
1845 | ||
c921be7d | 1846 | static bfd_boolean |
dcbf9037 JB |
1847 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1848 | { | |
1849 | if (!a && !b) | |
c921be7d | 1850 | return TRUE; |
5f4273c7 | 1851 | |
dcbf9037 | 1852 | if (!a || !b) |
c921be7d | 1853 | return FALSE; |
dcbf9037 JB |
1854 | |
1855 | if (a->defined != b->defined) | |
c921be7d | 1856 | return FALSE; |
5f4273c7 | 1857 | |
dcbf9037 JB |
1858 | if ((a->defined & NTA_HASTYPE) != 0 |
1859 | && (a->eltype.type != b->eltype.type | |
1860 | || a->eltype.size != b->eltype.size)) | |
c921be7d | 1861 | return FALSE; |
dcbf9037 JB |
1862 | |
1863 | if ((a->defined & NTA_HASINDEX) != 0 | |
1864 | && (a->index != b->index)) | |
c921be7d | 1865 | return FALSE; |
5f4273c7 | 1866 | |
c921be7d | 1867 | return TRUE; |
dcbf9037 JB |
1868 | } |
1869 | ||
5287ad62 JB |
1870 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1871 | The base register is put in *PBASE. | |
dcbf9037 | 1872 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1873 | the return value. |
1874 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1875 | Bits [6:5] encode the list length (minus one). |
1876 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1877 | |
5287ad62 | 1878 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1879 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1880 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1881 | ||
1882 | static int | |
dcbf9037 JB |
1883 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1884 | struct neon_type_el *eltype) | |
5287ad62 JB |
1885 | { |
1886 | char *ptr = *str; | |
1887 | int base_reg = -1; | |
1888 | int reg_incr = -1; | |
1889 | int count = 0; | |
1890 | int lane = -1; | |
1891 | int leading_brace = 0; | |
1892 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
20203fb9 NC |
1893 | const char *const incr_error = _("register stride must be 1 or 2"); |
1894 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 1895 | struct neon_typed_alias firsttype; |
5f4273c7 | 1896 | |
5287ad62 JB |
1897 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1898 | leading_brace = 1; | |
5f4273c7 | 1899 | |
5287ad62 JB |
1900 | do |
1901 | { | |
dcbf9037 JB |
1902 | struct neon_typed_alias atype; |
1903 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1904 | ||
5287ad62 JB |
1905 | if (getreg == FAIL) |
1906 | { | |
dcbf9037 | 1907 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1908 | return FAIL; |
1909 | } | |
5f4273c7 | 1910 | |
5287ad62 JB |
1911 | if (base_reg == -1) |
1912 | { | |
1913 | base_reg = getreg; | |
1914 | if (rtype == REG_TYPE_NQ) | |
1915 | { | |
1916 | reg_incr = 1; | |
5287ad62 | 1917 | } |
dcbf9037 | 1918 | firsttype = atype; |
5287ad62 JB |
1919 | } |
1920 | else if (reg_incr == -1) | |
1921 | { | |
1922 | reg_incr = getreg - base_reg; | |
1923 | if (reg_incr < 1 || reg_incr > 2) | |
1924 | { | |
dcbf9037 | 1925 | first_error (_(incr_error)); |
5287ad62 JB |
1926 | return FAIL; |
1927 | } | |
1928 | } | |
1929 | else if (getreg != base_reg + reg_incr * count) | |
1930 | { | |
dcbf9037 JB |
1931 | first_error (_(incr_error)); |
1932 | return FAIL; | |
1933 | } | |
1934 | ||
c921be7d | 1935 | if (! neon_alias_types_same (&atype, &firsttype)) |
dcbf9037 JB |
1936 | { |
1937 | first_error (_(type_error)); | |
5287ad62 JB |
1938 | return FAIL; |
1939 | } | |
5f4273c7 | 1940 | |
5287ad62 JB |
1941 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
1942 | modes. */ | |
1943 | if (ptr[0] == '-') | |
1944 | { | |
dcbf9037 | 1945 | struct neon_typed_alias htype; |
5287ad62 JB |
1946 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1947 | if (lane == -1) | |
1948 | lane = NEON_INTERLEAVE_LANES; | |
1949 | else if (lane != NEON_INTERLEAVE_LANES) | |
1950 | { | |
dcbf9037 | 1951 | first_error (_(type_error)); |
5287ad62 JB |
1952 | return FAIL; |
1953 | } | |
1954 | if (reg_incr == -1) | |
1955 | reg_incr = 1; | |
1956 | else if (reg_incr != 1) | |
1957 | { | |
dcbf9037 | 1958 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
1959 | return FAIL; |
1960 | } | |
1961 | ptr++; | |
dcbf9037 | 1962 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
1963 | if (hireg == FAIL) |
1964 | { | |
dcbf9037 JB |
1965 | first_error (_(reg_expected_msgs[rtype])); |
1966 | return FAIL; | |
1967 | } | |
c921be7d | 1968 | if (! neon_alias_types_same (&htype, &firsttype)) |
dcbf9037 JB |
1969 | { |
1970 | first_error (_(type_error)); | |
5287ad62 JB |
1971 | return FAIL; |
1972 | } | |
1973 | count += hireg + dregs - getreg; | |
1974 | continue; | |
1975 | } | |
5f4273c7 | 1976 | |
5287ad62 JB |
1977 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
1978 | if (rtype == REG_TYPE_NQ) | |
1979 | { | |
1980 | count += 2; | |
1981 | continue; | |
1982 | } | |
5f4273c7 | 1983 | |
dcbf9037 | 1984 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 1985 | { |
dcbf9037 JB |
1986 | if (lane == -1) |
1987 | lane = atype.index; | |
1988 | else if (lane != atype.index) | |
5287ad62 | 1989 | { |
dcbf9037 JB |
1990 | first_error (_(type_error)); |
1991 | return FAIL; | |
5287ad62 JB |
1992 | } |
1993 | } | |
1994 | else if (lane == -1) | |
1995 | lane = NEON_INTERLEAVE_LANES; | |
1996 | else if (lane != NEON_INTERLEAVE_LANES) | |
1997 | { | |
dcbf9037 | 1998 | first_error (_(type_error)); |
5287ad62 JB |
1999 | return FAIL; |
2000 | } | |
2001 | count++; | |
2002 | } | |
2003 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2004 | |
5287ad62 JB |
2005 | /* No lane set by [x]. We must be interleaving structures. */ |
2006 | if (lane == -1) | |
2007 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2008 | |
5287ad62 JB |
2009 | /* Sanity check. */ |
2010 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
2011 | || (count > 1 && reg_incr == -1)) | |
2012 | { | |
dcbf9037 | 2013 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2014 | return FAIL; |
2015 | } | |
2016 | ||
2017 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2018 | { | |
dcbf9037 | 2019 | first_error (_("expected }")); |
5287ad62 JB |
2020 | return FAIL; |
2021 | } | |
5f4273c7 | 2022 | |
5287ad62 JB |
2023 | if (reg_incr == -1) |
2024 | reg_incr = 1; | |
2025 | ||
dcbf9037 JB |
2026 | if (eltype) |
2027 | *eltype = firsttype.eltype; | |
2028 | ||
5287ad62 JB |
2029 | *pbase = base_reg; |
2030 | *str = ptr; | |
5f4273c7 | 2031 | |
5287ad62 JB |
2032 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2033 | } | |
2034 | ||
c19d1205 ZW |
2035 | /* Parse an explicit relocation suffix on an expression. This is |
2036 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2037 | arm_reloc_hsh contains no entries, so this function can only | |
2038 | succeed if there is no () after the word. Returns -1 on error, | |
2039 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
2040 | static int | |
2041 | parse_reloc (char **str) | |
b99bd4ef | 2042 | { |
c19d1205 ZW |
2043 | struct reloc_entry *r; |
2044 | char *p, *q; | |
b99bd4ef | 2045 | |
c19d1205 ZW |
2046 | if (**str != '(') |
2047 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2048 | |
c19d1205 ZW |
2049 | p = *str + 1; |
2050 | q = p; | |
2051 | ||
2052 | while (*q && *q != ')' && *q != ',') | |
2053 | q++; | |
2054 | if (*q != ')') | |
2055 | return -1; | |
2056 | ||
21d799b5 NC |
2057 | if ((r = (struct reloc_entry *) |
2058 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2059 | return -1; |
2060 | ||
2061 | *str = q + 1; | |
2062 | return r->reloc; | |
b99bd4ef NC |
2063 | } |
2064 | ||
c19d1205 ZW |
2065 | /* Directives: register aliases. */ |
2066 | ||
dcbf9037 | 2067 | static struct reg_entry * |
90ec0d68 | 2068 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2069 | { |
d3ce72d0 | 2070 | struct reg_entry *new_reg; |
c19d1205 | 2071 | const char *name; |
b99bd4ef | 2072 | |
d3ce72d0 | 2073 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2074 | { |
d3ce72d0 | 2075 | if (new_reg->builtin) |
c19d1205 | 2076 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2077 | |
c19d1205 ZW |
2078 | /* Only warn about a redefinition if it's not defined as the |
2079 | same register. */ | |
d3ce72d0 | 2080 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2081 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2082 | |
d929913e | 2083 | return NULL; |
c19d1205 | 2084 | } |
b99bd4ef | 2085 | |
c19d1205 | 2086 | name = xstrdup (str); |
d3ce72d0 | 2087 | new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry)); |
b99bd4ef | 2088 | |
d3ce72d0 NC |
2089 | new_reg->name = name; |
2090 | new_reg->number = number; | |
2091 | new_reg->type = type; | |
2092 | new_reg->builtin = FALSE; | |
2093 | new_reg->neon = NULL; | |
b99bd4ef | 2094 | |
d3ce72d0 | 2095 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2096 | abort (); |
5f4273c7 | 2097 | |
d3ce72d0 | 2098 | return new_reg; |
dcbf9037 JB |
2099 | } |
2100 | ||
2101 | static void | |
2102 | insert_neon_reg_alias (char *str, int number, int type, | |
2103 | struct neon_typed_alias *atype) | |
2104 | { | |
2105 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2106 | |
dcbf9037 JB |
2107 | if (!reg) |
2108 | { | |
2109 | first_error (_("attempt to redefine typed alias")); | |
2110 | return; | |
2111 | } | |
5f4273c7 | 2112 | |
dcbf9037 JB |
2113 | if (atype) |
2114 | { | |
21d799b5 NC |
2115 | reg->neon = (struct neon_typed_alias *) |
2116 | xmalloc (sizeof (struct neon_typed_alias)); | |
dcbf9037 JB |
2117 | *reg->neon = *atype; |
2118 | } | |
c19d1205 | 2119 | } |
b99bd4ef | 2120 | |
c19d1205 | 2121 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2122 | |
c19d1205 | 2123 | new_register_name .req existing_register_name |
b99bd4ef | 2124 | |
c19d1205 | 2125 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2126 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2127 | |
d929913e | 2128 | static bfd_boolean |
c19d1205 ZW |
2129 | create_register_alias (char * newname, char *p) |
2130 | { | |
2131 | struct reg_entry *old; | |
2132 | char *oldname, *nbuf; | |
2133 | size_t nlen; | |
b99bd4ef | 2134 | |
c19d1205 ZW |
2135 | /* The input scrubber ensures that whitespace after the mnemonic is |
2136 | collapsed to single spaces. */ | |
2137 | oldname = p; | |
2138 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2139 | return FALSE; |
b99bd4ef | 2140 | |
c19d1205 ZW |
2141 | oldname += 6; |
2142 | if (*oldname == '\0') | |
d929913e | 2143 | return FALSE; |
b99bd4ef | 2144 | |
21d799b5 | 2145 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2146 | if (!old) |
b99bd4ef | 2147 | { |
c19d1205 | 2148 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2149 | return TRUE; |
b99bd4ef NC |
2150 | } |
2151 | ||
c19d1205 ZW |
2152 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2153 | the desired alias name, and p points to its end. If not, then | |
2154 | the desired alias name is in the global original_case_string. */ | |
2155 | #ifdef TC_CASE_SENSITIVE | |
2156 | nlen = p - newname; | |
2157 | #else | |
2158 | newname = original_case_string; | |
2159 | nlen = strlen (newname); | |
2160 | #endif | |
b99bd4ef | 2161 | |
21d799b5 | 2162 | nbuf = (char *) alloca (nlen + 1); |
c19d1205 ZW |
2163 | memcpy (nbuf, newname, nlen); |
2164 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2165 | |
c19d1205 ZW |
2166 | /* Create aliases under the new name as stated; an all-lowercase |
2167 | version of the new name; and an all-uppercase version of the new | |
2168 | name. */ | |
d929913e NC |
2169 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2170 | { | |
2171 | for (p = nbuf; *p; p++) | |
2172 | *p = TOUPPER (*p); | |
c19d1205 | 2173 | |
d929913e NC |
2174 | if (strncmp (nbuf, newname, nlen)) |
2175 | { | |
2176 | /* If this attempt to create an additional alias fails, do not bother | |
2177 | trying to create the all-lower case alias. We will fail and issue | |
2178 | a second, duplicate error message. This situation arises when the | |
2179 | programmer does something like: | |
2180 | foo .req r0 | |
2181 | Foo .req r1 | |
2182 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2183 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2184 | first .req. */ |
2185 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
2186 | return TRUE; | |
2187 | } | |
c19d1205 | 2188 | |
d929913e NC |
2189 | for (p = nbuf; *p; p++) |
2190 | *p = TOLOWER (*p); | |
c19d1205 | 2191 | |
d929913e NC |
2192 | if (strncmp (nbuf, newname, nlen)) |
2193 | insert_reg_alias (nbuf, old->number, old->type); | |
2194 | } | |
c19d1205 | 2195 | |
d929913e | 2196 | return TRUE; |
b99bd4ef NC |
2197 | } |
2198 | ||
dcbf9037 JB |
2199 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2200 | X .dn d5.s32[1] | |
2201 | Y .qn 6.s16 | |
2202 | Z .dn d7 | |
2203 | T .dn Z[0] | |
2204 | These typed registers can be used instead of the types specified after the | |
2205 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2206 | specified directly, e.g.: | |
5f4273c7 | 2207 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2208 | |
c921be7d | 2209 | static bfd_boolean |
dcbf9037 JB |
2210 | create_neon_reg_alias (char *newname, char *p) |
2211 | { | |
2212 | enum arm_reg_type basetype; | |
2213 | struct reg_entry *basereg; | |
2214 | struct reg_entry mybasereg; | |
2215 | struct neon_type ntype; | |
2216 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2217 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2218 | int namelen; |
5f4273c7 | 2219 | |
dcbf9037 JB |
2220 | typeinfo.defined = 0; |
2221 | typeinfo.eltype.type = NT_invtype; | |
2222 | typeinfo.eltype.size = -1; | |
2223 | typeinfo.index = -1; | |
5f4273c7 | 2224 | |
dcbf9037 | 2225 | nameend = p; |
5f4273c7 | 2226 | |
dcbf9037 JB |
2227 | if (strncmp (p, " .dn ", 5) == 0) |
2228 | basetype = REG_TYPE_VFD; | |
2229 | else if (strncmp (p, " .qn ", 5) == 0) | |
2230 | basetype = REG_TYPE_NQ; | |
2231 | else | |
c921be7d | 2232 | return FALSE; |
5f4273c7 | 2233 | |
dcbf9037 | 2234 | p += 5; |
5f4273c7 | 2235 | |
dcbf9037 | 2236 | if (*p == '\0') |
c921be7d | 2237 | return FALSE; |
5f4273c7 | 2238 | |
dcbf9037 JB |
2239 | basereg = arm_reg_parse_multi (&p); |
2240 | ||
2241 | if (basereg && basereg->type != basetype) | |
2242 | { | |
2243 | as_bad (_("bad type for register")); | |
c921be7d | 2244 | return FALSE; |
dcbf9037 JB |
2245 | } |
2246 | ||
2247 | if (basereg == NULL) | |
2248 | { | |
2249 | expressionS exp; | |
2250 | /* Try parsing as an integer. */ | |
2251 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2252 | if (exp.X_op != O_constant) | |
2253 | { | |
2254 | as_bad (_("expression must be constant")); | |
c921be7d | 2255 | return FALSE; |
dcbf9037 JB |
2256 | } |
2257 | basereg = &mybasereg; | |
2258 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2259 | : exp.X_add_number; | |
2260 | basereg->neon = 0; | |
2261 | } | |
2262 | ||
2263 | if (basereg->neon) | |
2264 | typeinfo = *basereg->neon; | |
2265 | ||
2266 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2267 | { | |
2268 | /* We got a type. */ | |
2269 | if (typeinfo.defined & NTA_HASTYPE) | |
2270 | { | |
2271 | as_bad (_("can't redefine the type of a register alias")); | |
c921be7d | 2272 | return FALSE; |
dcbf9037 | 2273 | } |
5f4273c7 | 2274 | |
dcbf9037 JB |
2275 | typeinfo.defined |= NTA_HASTYPE; |
2276 | if (ntype.elems != 1) | |
2277 | { | |
2278 | as_bad (_("you must specify a single type only")); | |
c921be7d | 2279 | return FALSE; |
dcbf9037 JB |
2280 | } |
2281 | typeinfo.eltype = ntype.el[0]; | |
2282 | } | |
5f4273c7 | 2283 | |
dcbf9037 JB |
2284 | if (skip_past_char (&p, '[') == SUCCESS) |
2285 | { | |
2286 | expressionS exp; | |
2287 | /* We got a scalar index. */ | |
5f4273c7 | 2288 | |
dcbf9037 JB |
2289 | if (typeinfo.defined & NTA_HASINDEX) |
2290 | { | |
2291 | as_bad (_("can't redefine the index of a scalar alias")); | |
c921be7d | 2292 | return FALSE; |
dcbf9037 | 2293 | } |
5f4273c7 | 2294 | |
dcbf9037 | 2295 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2296 | |
dcbf9037 JB |
2297 | if (exp.X_op != O_constant) |
2298 | { | |
2299 | as_bad (_("scalar index must be constant")); | |
c921be7d | 2300 | return FALSE; |
dcbf9037 | 2301 | } |
5f4273c7 | 2302 | |
dcbf9037 JB |
2303 | typeinfo.defined |= NTA_HASINDEX; |
2304 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2305 | |
dcbf9037 JB |
2306 | if (skip_past_char (&p, ']') == FAIL) |
2307 | { | |
2308 | as_bad (_("expecting ]")); | |
c921be7d | 2309 | return FALSE; |
dcbf9037 JB |
2310 | } |
2311 | } | |
2312 | ||
15735687 NS |
2313 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2314 | the desired alias name, and p points to its end. If not, then | |
2315 | the desired alias name is in the global original_case_string. */ | |
2316 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2317 | namelen = nameend - newname; |
15735687 NS |
2318 | #else |
2319 | newname = original_case_string; | |
2320 | namelen = strlen (newname); | |
2321 | #endif | |
2322 | ||
21d799b5 | 2323 | namebuf = (char *) alloca (namelen + 1); |
dcbf9037 JB |
2324 | strncpy (namebuf, newname, namelen); |
2325 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2326 | |
dcbf9037 JB |
2327 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
2328 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2329 | |
dcbf9037 JB |
2330 | /* Insert name in all uppercase. */ |
2331 | for (p = namebuf; *p; p++) | |
2332 | *p = TOUPPER (*p); | |
5f4273c7 | 2333 | |
dcbf9037 JB |
2334 | if (strncmp (namebuf, newname, namelen)) |
2335 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2336 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2337 | |
dcbf9037 JB |
2338 | /* Insert name in all lowercase. */ |
2339 | for (p = namebuf; *p; p++) | |
2340 | *p = TOLOWER (*p); | |
5f4273c7 | 2341 | |
dcbf9037 JB |
2342 | if (strncmp (namebuf, newname, namelen)) |
2343 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2344 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2345 | |
c921be7d | 2346 | return TRUE; |
dcbf9037 JB |
2347 | } |
2348 | ||
c19d1205 ZW |
2349 | /* Should never be called, as .req goes between the alias and the |
2350 | register name, not at the beginning of the line. */ | |
c921be7d | 2351 | |
b99bd4ef | 2352 | static void |
c19d1205 | 2353 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2354 | { |
c19d1205 ZW |
2355 | as_bad (_("invalid syntax for .req directive")); |
2356 | } | |
b99bd4ef | 2357 | |
dcbf9037 JB |
2358 | static void |
2359 | s_dn (int a ATTRIBUTE_UNUSED) | |
2360 | { | |
2361 | as_bad (_("invalid syntax for .dn directive")); | |
2362 | } | |
2363 | ||
2364 | static void | |
2365 | s_qn (int a ATTRIBUTE_UNUSED) | |
2366 | { | |
2367 | as_bad (_("invalid syntax for .qn directive")); | |
2368 | } | |
2369 | ||
c19d1205 ZW |
2370 | /* The .unreq directive deletes an alias which was previously defined |
2371 | by .req. For example: | |
b99bd4ef | 2372 | |
c19d1205 ZW |
2373 | my_alias .req r11 |
2374 | .unreq my_alias */ | |
b99bd4ef NC |
2375 | |
2376 | static void | |
c19d1205 | 2377 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2378 | { |
c19d1205 ZW |
2379 | char * name; |
2380 | char saved_char; | |
b99bd4ef | 2381 | |
c19d1205 ZW |
2382 | name = input_line_pointer; |
2383 | ||
2384 | while (*input_line_pointer != 0 | |
2385 | && *input_line_pointer != ' ' | |
2386 | && *input_line_pointer != '\n') | |
2387 | ++input_line_pointer; | |
2388 | ||
2389 | saved_char = *input_line_pointer; | |
2390 | *input_line_pointer = 0; | |
2391 | ||
2392 | if (!*name) | |
2393 | as_bad (_("invalid syntax for .unreq directive")); | |
2394 | else | |
2395 | { | |
21d799b5 NC |
2396 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
2397 | name); | |
c19d1205 ZW |
2398 | |
2399 | if (!reg) | |
2400 | as_bad (_("unknown register alias '%s'"), name); | |
2401 | else if (reg->builtin) | |
2402 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
2403 | name); | |
2404 | else | |
2405 | { | |
d929913e NC |
2406 | char * p; |
2407 | char * nbuf; | |
2408 | ||
db0bc284 | 2409 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2410 | free ((char *) reg->name); |
dcbf9037 JB |
2411 | if (reg->neon) |
2412 | free (reg->neon); | |
c19d1205 | 2413 | free (reg); |
d929913e NC |
2414 | |
2415 | /* Also locate the all upper case and all lower case versions. | |
2416 | Do not complain if we cannot find one or the other as it | |
2417 | was probably deleted above. */ | |
5f4273c7 | 2418 | |
d929913e NC |
2419 | nbuf = strdup (name); |
2420 | for (p = nbuf; *p; p++) | |
2421 | *p = TOUPPER (*p); | |
21d799b5 | 2422 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2423 | if (reg) |
2424 | { | |
db0bc284 | 2425 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2426 | free ((char *) reg->name); |
2427 | if (reg->neon) | |
2428 | free (reg->neon); | |
2429 | free (reg); | |
2430 | } | |
2431 | ||
2432 | for (p = nbuf; *p; p++) | |
2433 | *p = TOLOWER (*p); | |
21d799b5 | 2434 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2435 | if (reg) |
2436 | { | |
db0bc284 | 2437 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2438 | free ((char *) reg->name); |
2439 | if (reg->neon) | |
2440 | free (reg->neon); | |
2441 | free (reg); | |
2442 | } | |
2443 | ||
2444 | free (nbuf); | |
c19d1205 ZW |
2445 | } |
2446 | } | |
b99bd4ef | 2447 | |
c19d1205 | 2448 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2449 | demand_empty_rest_of_line (); |
2450 | } | |
2451 | ||
c19d1205 ZW |
2452 | /* Directives: Instruction set selection. */ |
2453 | ||
2454 | #ifdef OBJ_ELF | |
2455 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2456 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2457 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2458 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2459 | ||
cd000bff DJ |
2460 | /* Create a new mapping symbol for the transition to STATE. */ |
2461 | ||
2462 | static void | |
2463 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2464 | { |
a737bd4d | 2465 | symbolS * symbolP; |
c19d1205 ZW |
2466 | const char * symname; |
2467 | int type; | |
b99bd4ef | 2468 | |
c19d1205 | 2469 | switch (state) |
b99bd4ef | 2470 | { |
c19d1205 ZW |
2471 | case MAP_DATA: |
2472 | symname = "$d"; | |
2473 | type = BSF_NO_FLAGS; | |
2474 | break; | |
2475 | case MAP_ARM: | |
2476 | symname = "$a"; | |
2477 | type = BSF_NO_FLAGS; | |
2478 | break; | |
2479 | case MAP_THUMB: | |
2480 | symname = "$t"; | |
2481 | type = BSF_NO_FLAGS; | |
2482 | break; | |
c19d1205 ZW |
2483 | default: |
2484 | abort (); | |
2485 | } | |
2486 | ||
cd000bff | 2487 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2488 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2489 | ||
2490 | switch (state) | |
2491 | { | |
2492 | case MAP_ARM: | |
2493 | THUMB_SET_FUNC (symbolP, 0); | |
2494 | ARM_SET_THUMB (symbolP, 0); | |
2495 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2496 | break; | |
2497 | ||
2498 | case MAP_THUMB: | |
2499 | THUMB_SET_FUNC (symbolP, 1); | |
2500 | ARM_SET_THUMB (symbolP, 1); | |
2501 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2502 | break; | |
2503 | ||
2504 | case MAP_DATA: | |
2505 | default: | |
cd000bff DJ |
2506 | break; |
2507 | } | |
2508 | ||
2509 | /* Save the mapping symbols for future reference. Also check that | |
2510 | we do not place two mapping symbols at the same offset within a | |
2511 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2512 | check_mapping_symbols. |
2513 | ||
2514 | If .fill or other data filling directive generates zero sized data, | |
2515 | the mapping symbol for the following code will have the same value | |
2516 | as the one generated for the data filling directive. In this case, | |
2517 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2518 | if (value == 0) |
2519 | { | |
2de7820f JZ |
2520 | if (frag->tc_frag_data.first_map != NULL) |
2521 | { | |
2522 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2523 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2524 | } | |
cd000bff DJ |
2525 | frag->tc_frag_data.first_map = symbolP; |
2526 | } | |
2527 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2528 | { |
2529 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2530 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2531 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2532 | } | |
cd000bff DJ |
2533 | frag->tc_frag_data.last_map = symbolP; |
2534 | } | |
2535 | ||
2536 | /* We must sometimes convert a region marked as code to data during | |
2537 | code alignment, if an odd number of bytes have to be padded. The | |
2538 | code mapping symbol is pushed to an aligned address. */ | |
2539 | ||
2540 | static void | |
2541 | insert_data_mapping_symbol (enum mstate state, | |
2542 | valueT value, fragS *frag, offsetT bytes) | |
2543 | { | |
2544 | /* If there was already a mapping symbol, remove it. */ | |
2545 | if (frag->tc_frag_data.last_map != NULL | |
2546 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2547 | { | |
2548 | symbolS *symp = frag->tc_frag_data.last_map; | |
2549 | ||
2550 | if (value == 0) | |
2551 | { | |
2552 | know (frag->tc_frag_data.first_map == symp); | |
2553 | frag->tc_frag_data.first_map = NULL; | |
2554 | } | |
2555 | frag->tc_frag_data.last_map = NULL; | |
2556 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2557 | } |
cd000bff DJ |
2558 | |
2559 | make_mapping_symbol (MAP_DATA, value, frag); | |
2560 | make_mapping_symbol (state, value + bytes, frag); | |
2561 | } | |
2562 | ||
2563 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2564 | ||
2565 | /* Set the mapping state to STATE. Only call this when about to | |
2566 | emit some STATE bytes to the file. */ | |
2567 | ||
2568 | void | |
2569 | mapping_state (enum mstate state) | |
2570 | { | |
940b5ce0 DJ |
2571 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2572 | ||
cd000bff DJ |
2573 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
2574 | ||
2575 | if (mapstate == state) | |
2576 | /* The mapping symbol has already been emitted. | |
2577 | There is nothing else to do. */ | |
2578 | return; | |
2579 | else if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
2580 | /* This case will be evaluated later in the next else. */ | |
2581 | return; | |
2582 | else if (TRANSITION (MAP_UNDEFINED, MAP_ARM) | |
2583 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2584 | { | |
2585 | /* Only add the symbol if the offset is > 0: | |
2586 | if we're at the first frag, check it's size > 0; | |
2587 | if we're not at the first frag, then for sure | |
2588 | the offset is > 0. */ | |
2589 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2590 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2591 | ||
2592 | if (add_symbol) | |
2593 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2594 | } | |
2595 | ||
2596 | mapping_state_2 (state, 0); | |
2597 | #undef TRANSITION | |
2598 | } | |
2599 | ||
2600 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2601 | allocated. Put the mapping symbol that far back. */ | |
2602 | ||
2603 | static void | |
2604 | mapping_state_2 (enum mstate state, int max_chars) | |
2605 | { | |
940b5ce0 DJ |
2606 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2607 | ||
2608 | if (!SEG_NORMAL (now_seg)) | |
2609 | return; | |
2610 | ||
cd000bff DJ |
2611 | if (mapstate == state) |
2612 | /* The mapping symbol has already been emitted. | |
2613 | There is nothing else to do. */ | |
2614 | return; | |
2615 | ||
cd000bff DJ |
2616 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2617 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 ZW |
2618 | } |
2619 | #else | |
d3106081 NS |
2620 | #define mapping_state(x) ((void)0) |
2621 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2622 | #endif |
2623 | ||
2624 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2625 | ||
4343666d | 2626 | #ifdef OBJ_COFF |
c19d1205 ZW |
2627 | static symbolS * |
2628 | find_real_start (symbolS * symbolP) | |
2629 | { | |
2630 | char * real_start; | |
2631 | const char * name = S_GET_NAME (symbolP); | |
2632 | symbolS * new_target; | |
2633 | ||
2634 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2635 | #define STUB_NAME ".real_start_of" | |
2636 | ||
2637 | if (name == NULL) | |
2638 | abort (); | |
2639 | ||
37f6032b ZW |
2640 | /* The compiler may generate BL instructions to local labels because |
2641 | it needs to perform a branch to a far away location. These labels | |
2642 | do not have a corresponding ".real_start_of" label. We check | |
2643 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2644 | the ".real_start_of" convention for nonlocal branches. */ | |
2645 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2646 | return symbolP; |
2647 | ||
37f6032b | 2648 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2649 | new_target = symbol_find (real_start); |
2650 | ||
2651 | if (new_target == NULL) | |
2652 | { | |
bd3ba5d1 | 2653 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2654 | new_target = symbolP; |
2655 | } | |
2656 | ||
c19d1205 ZW |
2657 | return new_target; |
2658 | } | |
4343666d | 2659 | #endif |
c19d1205 ZW |
2660 | |
2661 | static void | |
2662 | opcode_select (int width) | |
2663 | { | |
2664 | switch (width) | |
2665 | { | |
2666 | case 16: | |
2667 | if (! thumb_mode) | |
2668 | { | |
e74cfd16 | 2669 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2670 | as_bad (_("selected processor does not support THUMB opcodes")); |
2671 | ||
2672 | thumb_mode = 1; | |
2673 | /* No need to force the alignment, since we will have been | |
2674 | coming from ARM mode, which is word-aligned. */ | |
2675 | record_alignment (now_seg, 1); | |
2676 | } | |
c19d1205 ZW |
2677 | break; |
2678 | ||
2679 | case 32: | |
2680 | if (thumb_mode) | |
2681 | { | |
e74cfd16 | 2682 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2683 | as_bad (_("selected processor does not support ARM opcodes")); |
2684 | ||
2685 | thumb_mode = 0; | |
2686 | ||
2687 | if (!need_pass_2) | |
2688 | frag_align (2, 0, 0); | |
2689 | ||
2690 | record_alignment (now_seg, 1); | |
2691 | } | |
c19d1205 ZW |
2692 | break; |
2693 | ||
2694 | default: | |
2695 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2696 | } | |
2697 | } | |
2698 | ||
2699 | static void | |
2700 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2701 | { | |
2702 | opcode_select (32); | |
2703 | demand_empty_rest_of_line (); | |
2704 | } | |
2705 | ||
2706 | static void | |
2707 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2708 | { | |
2709 | opcode_select (16); | |
2710 | demand_empty_rest_of_line (); | |
2711 | } | |
2712 | ||
2713 | static void | |
2714 | s_code (int unused ATTRIBUTE_UNUSED) | |
2715 | { | |
2716 | int temp; | |
2717 | ||
2718 | temp = get_absolute_expression (); | |
2719 | switch (temp) | |
2720 | { | |
2721 | case 16: | |
2722 | case 32: | |
2723 | opcode_select (temp); | |
2724 | break; | |
2725 | ||
2726 | default: | |
2727 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2728 | } | |
2729 | } | |
2730 | ||
2731 | static void | |
2732 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2733 | { | |
2734 | /* If we are not already in thumb mode go into it, EVEN if | |
2735 | the target processor does not support thumb instructions. | |
2736 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2737 | to compile interworking support functions even if the | |
2738 | target processor should not support interworking. */ | |
2739 | if (! thumb_mode) | |
2740 | { | |
2741 | thumb_mode = 2; | |
2742 | record_alignment (now_seg, 1); | |
2743 | } | |
2744 | ||
2745 | demand_empty_rest_of_line (); | |
2746 | } | |
2747 | ||
2748 | static void | |
2749 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2750 | { | |
2751 | s_thumb (0); | |
2752 | ||
2753 | /* The following label is the name/address of the start of a Thumb function. | |
2754 | We need to know this for the interworking support. */ | |
2755 | label_is_thumb_function_name = TRUE; | |
2756 | } | |
2757 | ||
2758 | /* Perform a .set directive, but also mark the alias as | |
2759 | being a thumb function. */ | |
2760 | ||
2761 | static void | |
2762 | s_thumb_set (int equiv) | |
2763 | { | |
2764 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2765 | We cannot just call that code as we need to get at the symbol that | |
2766 | is created. */ | |
2767 | char * name; | |
2768 | char delim; | |
2769 | char * end_name; | |
2770 | symbolS * symbolP; | |
2771 | ||
2772 | /* Especial apologies for the random logic: | |
2773 | This just grew, and could be parsed much more simply! | |
2774 | Dean - in haste. */ | |
2775 | name = input_line_pointer; | |
2776 | delim = get_symbol_end (); | |
2777 | end_name = input_line_pointer; | |
2778 | *end_name = delim; | |
2779 | ||
2780 | if (*input_line_pointer != ',') | |
2781 | { | |
2782 | *end_name = 0; | |
2783 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2784 | *end_name = delim; |
2785 | ignore_rest_of_line (); | |
2786 | return; | |
2787 | } | |
2788 | ||
2789 | input_line_pointer++; | |
2790 | *end_name = 0; | |
2791 | ||
2792 | if (name[0] == '.' && name[1] == '\0') | |
2793 | { | |
2794 | /* XXX - this should not happen to .thumb_set. */ | |
2795 | abort (); | |
2796 | } | |
2797 | ||
2798 | if ((symbolP = symbol_find (name)) == NULL | |
2799 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2800 | { | |
2801 | #ifndef NO_LISTING | |
2802 | /* When doing symbol listings, play games with dummy fragments living | |
2803 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2804 | for this symbol. */ |
b99bd4ef NC |
2805 | if (listing & LISTING_SYMBOLS) |
2806 | { | |
2807 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 2808 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2809 | |
2810 | memset (dummy_frag, 0, sizeof (fragS)); | |
2811 | dummy_frag->fr_type = rs_fill; | |
2812 | dummy_frag->line = listing_tail; | |
2813 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2814 | dummy_frag->fr_symbol = symbolP; | |
2815 | } | |
2816 | else | |
2817 | #endif | |
2818 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2819 | ||
2820 | #ifdef OBJ_COFF | |
2821 | /* "set" symbols are local unless otherwise specified. */ | |
2822 | SF_SET_LOCAL (symbolP); | |
2823 | #endif /* OBJ_COFF */ | |
2824 | } /* Make a new symbol. */ | |
2825 | ||
2826 | symbol_table_insert (symbolP); | |
2827 | ||
2828 | * end_name = delim; | |
2829 | ||
2830 | if (equiv | |
2831 | && S_IS_DEFINED (symbolP) | |
2832 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2833 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2834 | ||
2835 | pseudo_set (symbolP); | |
2836 | ||
2837 | demand_empty_rest_of_line (); | |
2838 | ||
c19d1205 | 2839 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2840 | |
2841 | THUMB_SET_FUNC (symbolP, 1); | |
2842 | ARM_SET_THUMB (symbolP, 1); | |
2843 | #if defined OBJ_ELF || defined OBJ_COFF | |
2844 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2845 | #endif | |
2846 | } | |
2847 | ||
c19d1205 | 2848 | /* Directives: Mode selection. */ |
b99bd4ef | 2849 | |
c19d1205 ZW |
2850 | /* .syntax [unified|divided] - choose the new unified syntax |
2851 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2852 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2853 | static void |
c19d1205 | 2854 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2855 | { |
c19d1205 ZW |
2856 | char *name, delim; |
2857 | ||
2858 | name = input_line_pointer; | |
2859 | delim = get_symbol_end (); | |
2860 | ||
2861 | if (!strcasecmp (name, "unified")) | |
2862 | unified_syntax = TRUE; | |
2863 | else if (!strcasecmp (name, "divided")) | |
2864 | unified_syntax = FALSE; | |
2865 | else | |
2866 | { | |
2867 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2868 | return; | |
2869 | } | |
2870 | *input_line_pointer = delim; | |
b99bd4ef NC |
2871 | demand_empty_rest_of_line (); |
2872 | } | |
2873 | ||
c19d1205 ZW |
2874 | /* Directives: sectioning and alignment. */ |
2875 | ||
2876 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2877 | ||
b99bd4ef | 2878 | static void |
c19d1205 | 2879 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2880 | { |
a737bd4d | 2881 | int temp; |
dce323d1 | 2882 | bfd_boolean fill_p; |
c19d1205 ZW |
2883 | long temp_fill; |
2884 | long max_alignment = 15; | |
b99bd4ef NC |
2885 | |
2886 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2887 | if (temp > max_alignment) |
2888 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2889 | else if (temp < 0) | |
b99bd4ef | 2890 | { |
c19d1205 ZW |
2891 | as_bad (_("alignment negative. 0 assumed.")); |
2892 | temp = 0; | |
2893 | } | |
b99bd4ef | 2894 | |
c19d1205 ZW |
2895 | if (*input_line_pointer == ',') |
2896 | { | |
2897 | input_line_pointer++; | |
2898 | temp_fill = get_absolute_expression (); | |
dce323d1 | 2899 | fill_p = TRUE; |
b99bd4ef | 2900 | } |
c19d1205 | 2901 | else |
dce323d1 PB |
2902 | { |
2903 | fill_p = FALSE; | |
2904 | temp_fill = 0; | |
2905 | } | |
b99bd4ef | 2906 | |
c19d1205 ZW |
2907 | if (!temp) |
2908 | temp = 2; | |
b99bd4ef | 2909 | |
c19d1205 ZW |
2910 | /* Only make a frag if we HAVE to. */ |
2911 | if (temp && !need_pass_2) | |
dce323d1 PB |
2912 | { |
2913 | if (!fill_p && subseg_text_p (now_seg)) | |
2914 | frag_align_code (temp, 0); | |
2915 | else | |
2916 | frag_align (temp, (int) temp_fill, 0); | |
2917 | } | |
c19d1205 ZW |
2918 | demand_empty_rest_of_line (); |
2919 | ||
2920 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2921 | } |
2922 | ||
c19d1205 ZW |
2923 | static void |
2924 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2925 | { |
c19d1205 ZW |
2926 | /* We don't support putting frags in the BSS segment, we fake it by |
2927 | marking in_bss, then looking at s_skip for clues. */ | |
2928 | subseg_set (bss_section, 0); | |
2929 | demand_empty_rest_of_line (); | |
cd000bff DJ |
2930 | |
2931 | #ifdef md_elf_section_change_hook | |
2932 | md_elf_section_change_hook (); | |
2933 | #endif | |
c19d1205 | 2934 | } |
b99bd4ef | 2935 | |
c19d1205 ZW |
2936 | static void |
2937 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2938 | { | |
2939 | /* Never make frag if expect extra pass. */ | |
2940 | if (!need_pass_2) | |
2941 | frag_align (1, 0, 0); | |
b99bd4ef | 2942 | |
c19d1205 | 2943 | record_alignment (now_seg, 1); |
b99bd4ef | 2944 | |
c19d1205 | 2945 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2946 | } |
2947 | ||
c19d1205 | 2948 | /* Directives: Literal pools. */ |
a737bd4d | 2949 | |
c19d1205 ZW |
2950 | static literal_pool * |
2951 | find_literal_pool (void) | |
a737bd4d | 2952 | { |
c19d1205 | 2953 | literal_pool * pool; |
a737bd4d | 2954 | |
c19d1205 | 2955 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 2956 | { |
c19d1205 ZW |
2957 | if (pool->section == now_seg |
2958 | && pool->sub_section == now_subseg) | |
2959 | break; | |
a737bd4d NC |
2960 | } |
2961 | ||
c19d1205 | 2962 | return pool; |
a737bd4d NC |
2963 | } |
2964 | ||
c19d1205 ZW |
2965 | static literal_pool * |
2966 | find_or_make_literal_pool (void) | |
a737bd4d | 2967 | { |
c19d1205 ZW |
2968 | /* Next literal pool ID number. */ |
2969 | static unsigned int latest_pool_num = 1; | |
2970 | literal_pool * pool; | |
a737bd4d | 2971 | |
c19d1205 | 2972 | pool = find_literal_pool (); |
a737bd4d | 2973 | |
c19d1205 | 2974 | if (pool == NULL) |
a737bd4d | 2975 | { |
c19d1205 | 2976 | /* Create a new pool. */ |
21d799b5 | 2977 | pool = (literal_pool *) xmalloc (sizeof (* pool)); |
c19d1205 ZW |
2978 | if (! pool) |
2979 | return NULL; | |
a737bd4d | 2980 | |
c19d1205 ZW |
2981 | pool->next_free_entry = 0; |
2982 | pool->section = now_seg; | |
2983 | pool->sub_section = now_subseg; | |
2984 | pool->next = list_of_pools; | |
2985 | pool->symbol = NULL; | |
2986 | ||
2987 | /* Add it to the list. */ | |
2988 | list_of_pools = pool; | |
a737bd4d | 2989 | } |
a737bd4d | 2990 | |
c19d1205 ZW |
2991 | /* New pools, and emptied pools, will have a NULL symbol. */ |
2992 | if (pool->symbol == NULL) | |
a737bd4d | 2993 | { |
c19d1205 ZW |
2994 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
2995 | (valueT) 0, &zero_address_frag); | |
2996 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
2997 | } |
2998 | ||
c19d1205 ZW |
2999 | /* Done. */ |
3000 | return pool; | |
a737bd4d NC |
3001 | } |
3002 | ||
c19d1205 | 3003 | /* Add the literal in the global 'inst' |
5f4273c7 | 3004 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3005 | |
3006 | static int | |
c19d1205 | 3007 | add_to_lit_pool (void) |
b99bd4ef | 3008 | { |
c19d1205 ZW |
3009 | literal_pool * pool; |
3010 | unsigned int entry; | |
b99bd4ef | 3011 | |
c19d1205 ZW |
3012 | pool = find_or_make_literal_pool (); |
3013 | ||
3014 | /* Check if this literal value is already in the pool. */ | |
3015 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3016 | { |
c19d1205 ZW |
3017 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
3018 | && (inst.reloc.exp.X_op == O_constant) | |
3019 | && (pool->literals[entry].X_add_number | |
3020 | == inst.reloc.exp.X_add_number) | |
3021 | && (pool->literals[entry].X_unsigned | |
3022 | == inst.reloc.exp.X_unsigned)) | |
3023 | break; | |
3024 | ||
3025 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
3026 | && (inst.reloc.exp.X_op == O_symbol) | |
3027 | && (pool->literals[entry].X_add_number | |
3028 | == inst.reloc.exp.X_add_number) | |
3029 | && (pool->literals[entry].X_add_symbol | |
3030 | == inst.reloc.exp.X_add_symbol) | |
3031 | && (pool->literals[entry].X_op_symbol | |
3032 | == inst.reloc.exp.X_op_symbol)) | |
3033 | break; | |
b99bd4ef NC |
3034 | } |
3035 | ||
c19d1205 ZW |
3036 | /* Do we need to create a new entry? */ |
3037 | if (entry == pool->next_free_entry) | |
3038 | { | |
3039 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3040 | { | |
3041 | inst.error = _("literal pool overflow"); | |
3042 | return FAIL; | |
3043 | } | |
3044 | ||
3045 | pool->literals[entry] = inst.reloc.exp; | |
3046 | pool->next_free_entry += 1; | |
3047 | } | |
b99bd4ef | 3048 | |
c19d1205 ZW |
3049 | inst.reloc.exp.X_op = O_symbol; |
3050 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
3051 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3052 | |
c19d1205 | 3053 | return SUCCESS; |
b99bd4ef NC |
3054 | } |
3055 | ||
c19d1205 ZW |
3056 | /* Can't use symbol_new here, so have to create a symbol and then at |
3057 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 3058 | |
c19d1205 ZW |
3059 | static void |
3060 | symbol_locate (symbolS * symbolP, | |
3061 | const char * name, /* It is copied, the caller can modify. */ | |
3062 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3063 | valueT valu, /* Symbol value. */ | |
3064 | fragS * frag) /* Associated fragment. */ | |
3065 | { | |
3066 | unsigned int name_length; | |
3067 | char * preserved_copy_of_name; | |
e16bb312 | 3068 | |
c19d1205 ZW |
3069 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3070 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3071 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3072 | |
c19d1205 ZW |
3073 | #ifdef tc_canonicalize_symbol_name |
3074 | preserved_copy_of_name = | |
3075 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3076 | #endif | |
b99bd4ef | 3077 | |
c19d1205 | 3078 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3079 | |
c19d1205 ZW |
3080 | S_SET_SEGMENT (symbolP, segment); |
3081 | S_SET_VALUE (symbolP, valu); | |
3082 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3083 | |
c19d1205 | 3084 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3085 | |
c19d1205 ZW |
3086 | /* Link to end of symbol chain. */ |
3087 | { | |
3088 | extern int symbol_table_frozen; | |
b99bd4ef | 3089 | |
c19d1205 ZW |
3090 | if (symbol_table_frozen) |
3091 | abort (); | |
3092 | } | |
b99bd4ef | 3093 | |
c19d1205 | 3094 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3095 | |
c19d1205 | 3096 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3097 | |
c19d1205 ZW |
3098 | #ifdef tc_symbol_new_hook |
3099 | tc_symbol_new_hook (symbolP); | |
3100 | #endif | |
3101 | ||
3102 | #ifdef DEBUG_SYMS | |
3103 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3104 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3105 | } |
3106 | ||
b99bd4ef | 3107 | |
c19d1205 ZW |
3108 | static void |
3109 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3110 | { |
c19d1205 ZW |
3111 | unsigned int entry; |
3112 | literal_pool * pool; | |
3113 | char sym_name[20]; | |
b99bd4ef | 3114 | |
c19d1205 ZW |
3115 | pool = find_literal_pool (); |
3116 | if (pool == NULL | |
3117 | || pool->symbol == NULL | |
3118 | || pool->next_free_entry == 0) | |
3119 | return; | |
b99bd4ef | 3120 | |
c19d1205 | 3121 | mapping_state (MAP_DATA); |
b99bd4ef | 3122 | |
c19d1205 ZW |
3123 | /* Align pool as you have word accesses. |
3124 | Only make a frag if we have to. */ | |
3125 | if (!need_pass_2) | |
3126 | frag_align (2, 0, 0); | |
b99bd4ef | 3127 | |
c19d1205 | 3128 | record_alignment (now_seg, 2); |
b99bd4ef | 3129 | |
c19d1205 | 3130 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3131 | |
c19d1205 ZW |
3132 | symbol_locate (pool->symbol, sym_name, now_seg, |
3133 | (valueT) frag_now_fix (), frag_now); | |
3134 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3135 | |
c19d1205 | 3136 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3137 | |
c19d1205 ZW |
3138 | #if defined OBJ_COFF || defined OBJ_ELF |
3139 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3140 | #endif | |
6c43fab6 | 3141 | |
c19d1205 ZW |
3142 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
3143 | /* First output the expression in the instruction to the pool. */ | |
3144 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 3145 | |
c19d1205 ZW |
3146 | /* Mark the pool as empty. */ |
3147 | pool->next_free_entry = 0; | |
3148 | pool->symbol = NULL; | |
b99bd4ef NC |
3149 | } |
3150 | ||
c19d1205 ZW |
3151 | #ifdef OBJ_ELF |
3152 | /* Forward declarations for functions below, in the MD interface | |
3153 | section. */ | |
3154 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3155 | static valueT create_unwind_entry (int); | |
3156 | static void start_unwind_section (const segT, int); | |
3157 | static void add_unwind_opcode (valueT, int); | |
3158 | static void flush_pending_unwind (void); | |
b99bd4ef | 3159 | |
c19d1205 | 3160 | /* Directives: Data. */ |
b99bd4ef | 3161 | |
c19d1205 ZW |
3162 | static void |
3163 | s_arm_elf_cons (int nbytes) | |
3164 | { | |
3165 | expressionS exp; | |
b99bd4ef | 3166 | |
c19d1205 ZW |
3167 | #ifdef md_flush_pending_output |
3168 | md_flush_pending_output (); | |
3169 | #endif | |
b99bd4ef | 3170 | |
c19d1205 | 3171 | if (is_it_end_of_statement ()) |
b99bd4ef | 3172 | { |
c19d1205 ZW |
3173 | demand_empty_rest_of_line (); |
3174 | return; | |
b99bd4ef NC |
3175 | } |
3176 | ||
c19d1205 ZW |
3177 | #ifdef md_cons_align |
3178 | md_cons_align (nbytes); | |
3179 | #endif | |
b99bd4ef | 3180 | |
c19d1205 ZW |
3181 | mapping_state (MAP_DATA); |
3182 | do | |
b99bd4ef | 3183 | { |
c19d1205 ZW |
3184 | int reloc; |
3185 | char *base = input_line_pointer; | |
b99bd4ef | 3186 | |
c19d1205 | 3187 | expression (& exp); |
b99bd4ef | 3188 | |
c19d1205 ZW |
3189 | if (exp.X_op != O_symbol) |
3190 | emit_expr (&exp, (unsigned int) nbytes); | |
3191 | else | |
3192 | { | |
3193 | char *before_reloc = input_line_pointer; | |
3194 | reloc = parse_reloc (&input_line_pointer); | |
3195 | if (reloc == -1) | |
3196 | { | |
3197 | as_bad (_("unrecognized relocation suffix")); | |
3198 | ignore_rest_of_line (); | |
3199 | return; | |
3200 | } | |
3201 | else if (reloc == BFD_RELOC_UNUSED) | |
3202 | emit_expr (&exp, (unsigned int) nbytes); | |
3203 | else | |
3204 | { | |
21d799b5 NC |
3205 | reloc_howto_type *howto = (reloc_howto_type *) |
3206 | bfd_reloc_type_lookup (stdoutput, | |
3207 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3208 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3209 | |
2fc8bdac ZW |
3210 | if (reloc == BFD_RELOC_ARM_PLT32) |
3211 | { | |
3212 | as_bad (_("(plt) is only valid on branch targets")); | |
3213 | reloc = BFD_RELOC_UNUSED; | |
3214 | size = 0; | |
3215 | } | |
3216 | ||
c19d1205 | 3217 | if (size > nbytes) |
2fc8bdac | 3218 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3219 | howto->name, nbytes); |
3220 | else | |
3221 | { | |
3222 | /* We've parsed an expression stopping at O_symbol. | |
3223 | But there may be more expression left now that we | |
3224 | have parsed the relocation marker. Parse it again. | |
3225 | XXX Surely there is a cleaner way to do this. */ | |
3226 | char *p = input_line_pointer; | |
3227 | int offset; | |
21d799b5 | 3228 | char *save_buf = (char *) alloca (input_line_pointer - base); |
c19d1205 ZW |
3229 | memcpy (save_buf, base, input_line_pointer - base); |
3230 | memmove (base + (input_line_pointer - before_reloc), | |
3231 | base, before_reloc - base); | |
3232 | ||
3233 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3234 | expression (&exp); | |
3235 | memcpy (base, save_buf, p - base); | |
3236 | ||
3237 | offset = nbytes - size; | |
3238 | p = frag_more ((int) nbytes); | |
3239 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
21d799b5 | 3240 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
c19d1205 ZW |
3241 | } |
3242 | } | |
3243 | } | |
b99bd4ef | 3244 | } |
c19d1205 | 3245 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3246 | |
c19d1205 ZW |
3247 | /* Put terminator back into stream. */ |
3248 | input_line_pointer --; | |
3249 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3250 | } |
3251 | ||
c921be7d NC |
3252 | /* Emit an expression containing a 32-bit thumb instruction. |
3253 | Implementation based on put_thumb32_insn. */ | |
3254 | ||
3255 | static void | |
3256 | emit_thumb32_expr (expressionS * exp) | |
3257 | { | |
3258 | expressionS exp_high = *exp; | |
3259 | ||
3260 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3261 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3262 | exp->X_add_number &= 0xffff; | |
3263 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3264 | } | |
3265 | ||
3266 | /* Guess the instruction size based on the opcode. */ | |
3267 | ||
3268 | static int | |
3269 | thumb_insn_size (int opcode) | |
3270 | { | |
3271 | if ((unsigned int) opcode < 0xe800u) | |
3272 | return 2; | |
3273 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3274 | return 4; | |
3275 | else | |
3276 | return 0; | |
3277 | } | |
3278 | ||
3279 | static bfd_boolean | |
3280 | emit_insn (expressionS *exp, int nbytes) | |
3281 | { | |
3282 | int size = 0; | |
3283 | ||
3284 | if (exp->X_op == O_constant) | |
3285 | { | |
3286 | size = nbytes; | |
3287 | ||
3288 | if (size == 0) | |
3289 | size = thumb_insn_size (exp->X_add_number); | |
3290 | ||
3291 | if (size != 0) | |
3292 | { | |
3293 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3294 | { | |
3295 | as_bad (_(".inst.n operand too big. "\ | |
3296 | "Use .inst.w instead")); | |
3297 | size = 0; | |
3298 | } | |
3299 | else | |
3300 | { | |
3301 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3302 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3303 | else | |
3304 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3305 | ||
3306 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3307 | emit_thumb32_expr (exp); | |
3308 | else | |
3309 | emit_expr (exp, (unsigned int) size); | |
3310 | ||
3311 | it_fsm_post_encode (); | |
3312 | } | |
3313 | } | |
3314 | else | |
3315 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3316 | "Use .inst.n/.inst.w instead")); | |
3317 | } | |
3318 | else | |
3319 | as_bad (_("constant expression required")); | |
3320 | ||
3321 | return (size != 0); | |
3322 | } | |
3323 | ||
3324 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3325 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3326 | ||
3327 | static void | |
3328 | s_arm_elf_inst (int nbytes) | |
3329 | { | |
3330 | if (is_it_end_of_statement ()) | |
3331 | { | |
3332 | demand_empty_rest_of_line (); | |
3333 | return; | |
3334 | } | |
3335 | ||
3336 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3337 | but will ensure not to be in DATA state. */ | |
3338 | ||
3339 | if (thumb_mode) | |
3340 | mapping_state (MAP_THUMB); | |
3341 | else | |
3342 | { | |
3343 | if (nbytes != 0) | |
3344 | { | |
3345 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3346 | ignore_rest_of_line (); | |
3347 | return; | |
3348 | } | |
3349 | ||
3350 | nbytes = 4; | |
3351 | ||
3352 | mapping_state (MAP_ARM); | |
3353 | } | |
3354 | ||
3355 | do | |
3356 | { | |
3357 | expressionS exp; | |
3358 | ||
3359 | expression (& exp); | |
3360 | ||
3361 | if (! emit_insn (& exp, nbytes)) | |
3362 | { | |
3363 | ignore_rest_of_line (); | |
3364 | return; | |
3365 | } | |
3366 | } | |
3367 | while (*input_line_pointer++ == ','); | |
3368 | ||
3369 | /* Put terminator back into stream. */ | |
3370 | input_line_pointer --; | |
3371 | demand_empty_rest_of_line (); | |
3372 | } | |
b99bd4ef | 3373 | |
c19d1205 | 3374 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3375 | |
c19d1205 ZW |
3376 | static void |
3377 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3378 | { | |
3379 | expressionS exp; | |
3380 | char *p; | |
3381 | valueT highbit; | |
b99bd4ef | 3382 | |
c19d1205 ZW |
3383 | highbit = 0; |
3384 | if (*input_line_pointer == '1') | |
3385 | highbit = 0x80000000; | |
3386 | else if (*input_line_pointer != '0') | |
3387 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3388 | |
c19d1205 ZW |
3389 | input_line_pointer++; |
3390 | if (*input_line_pointer != ',') | |
3391 | as_bad (_("missing comma")); | |
3392 | input_line_pointer++; | |
b99bd4ef | 3393 | |
c19d1205 ZW |
3394 | #ifdef md_flush_pending_output |
3395 | md_flush_pending_output (); | |
3396 | #endif | |
b99bd4ef | 3397 | |
c19d1205 ZW |
3398 | #ifdef md_cons_align |
3399 | md_cons_align (4); | |
3400 | #endif | |
b99bd4ef | 3401 | |
c19d1205 | 3402 | mapping_state (MAP_DATA); |
b99bd4ef | 3403 | |
c19d1205 | 3404 | expression (&exp); |
b99bd4ef | 3405 | |
c19d1205 ZW |
3406 | p = frag_more (4); |
3407 | md_number_to_chars (p, highbit, 4); | |
3408 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3409 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3410 | |
c19d1205 | 3411 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3412 | } |
3413 | ||
c19d1205 | 3414 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3415 | |
c19d1205 | 3416 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3417 | |
c19d1205 ZW |
3418 | static void |
3419 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3420 | { | |
3421 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3422 | if (unwind.proc_start) |
3423 | { | |
c921be7d | 3424 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3425 | return; |
3426 | } | |
3427 | ||
c19d1205 ZW |
3428 | /* Mark the start of the function. */ |
3429 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3430 | |
c19d1205 ZW |
3431 | /* Reset the rest of the unwind info. */ |
3432 | unwind.opcode_count = 0; | |
3433 | unwind.table_entry = NULL; | |
3434 | unwind.personality_routine = NULL; | |
3435 | unwind.personality_index = -1; | |
3436 | unwind.frame_size = 0; | |
3437 | unwind.fp_offset = 0; | |
fdfde340 | 3438 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3439 | unwind.fp_used = 0; |
3440 | unwind.sp_restored = 0; | |
3441 | } | |
b99bd4ef | 3442 | |
b99bd4ef | 3443 | |
c19d1205 ZW |
3444 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3445 | for the function. */ | |
b99bd4ef | 3446 | |
c19d1205 ZW |
3447 | static void |
3448 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3449 | { | |
3450 | demand_empty_rest_of_line (); | |
921e5f0a | 3451 | if (!unwind.proc_start) |
c921be7d | 3452 | as_bad (MISSING_FNSTART); |
921e5f0a | 3453 | |
c19d1205 | 3454 | if (unwind.table_entry) |
6decc662 | 3455 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3456 | |
c19d1205 ZW |
3457 | create_unwind_entry (1); |
3458 | } | |
a737bd4d | 3459 | |
c19d1205 | 3460 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3461 | |
c19d1205 ZW |
3462 | static void |
3463 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3464 | { | |
3465 | long where; | |
3466 | char *ptr; | |
3467 | valueT val; | |
940b5ce0 | 3468 | unsigned int marked_pr_dependency; |
f02232aa | 3469 | |
c19d1205 | 3470 | demand_empty_rest_of_line (); |
f02232aa | 3471 | |
921e5f0a PB |
3472 | if (!unwind.proc_start) |
3473 | { | |
c921be7d | 3474 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3475 | return; |
3476 | } | |
3477 | ||
c19d1205 ZW |
3478 | /* Add eh table entry. */ |
3479 | if (unwind.table_entry == NULL) | |
3480 | val = create_unwind_entry (0); | |
3481 | else | |
3482 | val = 0; | |
f02232aa | 3483 | |
c19d1205 ZW |
3484 | /* Add index table entry. This is two words. */ |
3485 | start_unwind_section (unwind.saved_seg, 1); | |
3486 | frag_align (2, 0, 0); | |
3487 | record_alignment (now_seg, 2); | |
b99bd4ef | 3488 | |
c19d1205 ZW |
3489 | ptr = frag_more (8); |
3490 | where = frag_now_fix () - 8; | |
f02232aa | 3491 | |
c19d1205 ZW |
3492 | /* Self relative offset of the function start. */ |
3493 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3494 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3495 | |
c19d1205 ZW |
3496 | /* Indicate dependency on EHABI-defined personality routines to the |
3497 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3498 | marked_pr_dependency |
3499 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3500 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3501 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3502 | { | |
5f4273c7 NC |
3503 | static const char *const name[] = |
3504 | { | |
3505 | "__aeabi_unwind_cpp_pr0", | |
3506 | "__aeabi_unwind_cpp_pr1", | |
3507 | "__aeabi_unwind_cpp_pr2" | |
3508 | }; | |
c19d1205 ZW |
3509 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3510 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3511 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3512 | |= 1 << unwind.personality_index; |
c19d1205 | 3513 | } |
f02232aa | 3514 | |
c19d1205 ZW |
3515 | if (val) |
3516 | /* Inline exception table entry. */ | |
3517 | md_number_to_chars (ptr + 4, val, 4); | |
3518 | else | |
3519 | /* Self relative offset of the table entry. */ | |
3520 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3521 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3522 | |
c19d1205 ZW |
3523 | /* Restore the original section. */ |
3524 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3525 | |
3526 | unwind.proc_start = NULL; | |
c19d1205 | 3527 | } |
f02232aa | 3528 | |
f02232aa | 3529 | |
c19d1205 | 3530 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3531 | |
c19d1205 ZW |
3532 | static void |
3533 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3534 | { | |
3535 | demand_empty_rest_of_line (); | |
921e5f0a | 3536 | if (!unwind.proc_start) |
c921be7d | 3537 | as_bad (MISSING_FNSTART); |
921e5f0a | 3538 | |
c19d1205 ZW |
3539 | if (unwind.personality_routine || unwind.personality_index != -1) |
3540 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3541 | |
c19d1205 ZW |
3542 | unwind.personality_index = -2; |
3543 | } | |
b99bd4ef | 3544 | |
b99bd4ef | 3545 | |
c19d1205 | 3546 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3547 | |
c19d1205 ZW |
3548 | static void |
3549 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3550 | { | |
3551 | expressionS exp; | |
b99bd4ef | 3552 | |
921e5f0a | 3553 | if (!unwind.proc_start) |
c921be7d | 3554 | as_bad (MISSING_FNSTART); |
921e5f0a | 3555 | |
c19d1205 ZW |
3556 | if (unwind.personality_routine || unwind.personality_index != -1) |
3557 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3558 | |
c19d1205 | 3559 | expression (&exp); |
b99bd4ef | 3560 | |
c19d1205 ZW |
3561 | if (exp.X_op != O_constant |
3562 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3563 | { |
c19d1205 ZW |
3564 | as_bad (_("bad personality routine number")); |
3565 | ignore_rest_of_line (); | |
3566 | return; | |
b99bd4ef NC |
3567 | } |
3568 | ||
c19d1205 | 3569 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3570 | |
c19d1205 ZW |
3571 | demand_empty_rest_of_line (); |
3572 | } | |
e16bb312 | 3573 | |
e16bb312 | 3574 | |
c19d1205 | 3575 | /* Parse a personality directive. */ |
e16bb312 | 3576 | |
c19d1205 ZW |
3577 | static void |
3578 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3579 | { | |
3580 | char *name, *p, c; | |
a737bd4d | 3581 | |
921e5f0a | 3582 | if (!unwind.proc_start) |
c921be7d | 3583 | as_bad (MISSING_FNSTART); |
921e5f0a | 3584 | |
c19d1205 ZW |
3585 | if (unwind.personality_routine || unwind.personality_index != -1) |
3586 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3587 | |
c19d1205 ZW |
3588 | name = input_line_pointer; |
3589 | c = get_symbol_end (); | |
3590 | p = input_line_pointer; | |
3591 | unwind.personality_routine = symbol_find_or_make (name); | |
3592 | *p = c; | |
3593 | demand_empty_rest_of_line (); | |
3594 | } | |
e16bb312 | 3595 | |
e16bb312 | 3596 | |
c19d1205 | 3597 | /* Parse a directive saving core registers. */ |
e16bb312 | 3598 | |
c19d1205 ZW |
3599 | static void |
3600 | s_arm_unwind_save_core (void) | |
e16bb312 | 3601 | { |
c19d1205 ZW |
3602 | valueT op; |
3603 | long range; | |
3604 | int n; | |
e16bb312 | 3605 | |
c19d1205 ZW |
3606 | range = parse_reg_list (&input_line_pointer); |
3607 | if (range == FAIL) | |
e16bb312 | 3608 | { |
c19d1205 ZW |
3609 | as_bad (_("expected register list")); |
3610 | ignore_rest_of_line (); | |
3611 | return; | |
3612 | } | |
e16bb312 | 3613 | |
c19d1205 | 3614 | demand_empty_rest_of_line (); |
e16bb312 | 3615 | |
c19d1205 ZW |
3616 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3617 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3618 | ip because it is clobbered by calls. */ | |
3619 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3620 | && (range & 0x3000) == 0x1000) | |
3621 | { | |
3622 | unwind.opcode_count--; | |
3623 | unwind.sp_restored = 0; | |
3624 | range = (range | 0x2000) & ~0x1000; | |
3625 | unwind.pending_offset = 0; | |
3626 | } | |
e16bb312 | 3627 | |
01ae4198 DJ |
3628 | /* Pop r4-r15. */ |
3629 | if (range & 0xfff0) | |
c19d1205 | 3630 | { |
01ae4198 DJ |
3631 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3632 | registers starting with r4, plus maybe r14. */ | |
3633 | for (n = 0; n < 8; n++) | |
3634 | { | |
3635 | /* Break at the first non-saved register. */ | |
3636 | if ((range & (1 << (n + 4))) == 0) | |
3637 | break; | |
3638 | } | |
3639 | /* See if there are any other bits set. */ | |
3640 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3641 | { | |
3642 | /* Use the long form. */ | |
3643 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3644 | add_unwind_opcode (op, 2); | |
3645 | } | |
0dd132b6 | 3646 | else |
01ae4198 DJ |
3647 | { |
3648 | /* Use the short form. */ | |
3649 | if (range & 0x4000) | |
3650 | op = 0xa8; /* Pop r14. */ | |
3651 | else | |
3652 | op = 0xa0; /* Do not pop r14. */ | |
3653 | op |= (n - 1); | |
3654 | add_unwind_opcode (op, 1); | |
3655 | } | |
c19d1205 | 3656 | } |
0dd132b6 | 3657 | |
c19d1205 ZW |
3658 | /* Pop r0-r3. */ |
3659 | if (range & 0xf) | |
3660 | { | |
3661 | op = 0xb100 | (range & 0xf); | |
3662 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3663 | } |
3664 | ||
c19d1205 ZW |
3665 | /* Record the number of bytes pushed. */ |
3666 | for (n = 0; n < 16; n++) | |
3667 | { | |
3668 | if (range & (1 << n)) | |
3669 | unwind.frame_size += 4; | |
3670 | } | |
0dd132b6 NC |
3671 | } |
3672 | ||
c19d1205 ZW |
3673 | |
3674 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3675 | |
3676 | static void | |
c19d1205 | 3677 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3678 | { |
c19d1205 ZW |
3679 | expressionS exp; |
3680 | int num_regs; | |
3681 | valueT op; | |
b99bd4ef | 3682 | |
c19d1205 ZW |
3683 | /* Get Number of registers to transfer. */ |
3684 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3685 | expression (&exp); | |
3686 | else | |
3687 | exp.X_op = O_illegal; | |
b99bd4ef | 3688 | |
c19d1205 | 3689 | if (exp.X_op != O_constant) |
b99bd4ef | 3690 | { |
c19d1205 ZW |
3691 | as_bad (_("expected , <constant>")); |
3692 | ignore_rest_of_line (); | |
b99bd4ef NC |
3693 | return; |
3694 | } | |
3695 | ||
c19d1205 ZW |
3696 | num_regs = exp.X_add_number; |
3697 | ||
3698 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3699 | { |
c19d1205 ZW |
3700 | as_bad (_("number of registers must be in the range [1:4]")); |
3701 | ignore_rest_of_line (); | |
b99bd4ef NC |
3702 | return; |
3703 | } | |
3704 | ||
c19d1205 | 3705 | demand_empty_rest_of_line (); |
b99bd4ef | 3706 | |
c19d1205 ZW |
3707 | if (reg == 4) |
3708 | { | |
3709 | /* Short form. */ | |
3710 | op = 0xb4 | (num_regs - 1); | |
3711 | add_unwind_opcode (op, 1); | |
3712 | } | |
b99bd4ef NC |
3713 | else |
3714 | { | |
c19d1205 ZW |
3715 | /* Long form. */ |
3716 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3717 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3718 | } |
c19d1205 | 3719 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3720 | } |
3721 | ||
c19d1205 | 3722 | |
fa073d69 MS |
3723 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3724 | ||
3725 | static void | |
3726 | s_arm_unwind_save_vfp_armv6 (void) | |
3727 | { | |
3728 | int count; | |
3729 | unsigned int start; | |
3730 | valueT op; | |
3731 | int num_vfpv3_regs = 0; | |
3732 | int num_regs_below_16; | |
3733 | ||
3734 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3735 | if (count == FAIL) | |
3736 | { | |
3737 | as_bad (_("expected register list")); | |
3738 | ignore_rest_of_line (); | |
3739 | return; | |
3740 | } | |
3741 | ||
3742 | demand_empty_rest_of_line (); | |
3743 | ||
3744 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3745 | than FSTMX/FLDMX-style ones). */ | |
3746 | ||
3747 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3748 | if (start >= 16) | |
3749 | num_vfpv3_regs = count; | |
3750 | else if (start + count > 16) | |
3751 | num_vfpv3_regs = start + count - 16; | |
3752 | ||
3753 | if (num_vfpv3_regs > 0) | |
3754 | { | |
3755 | int start_offset = start > 16 ? start - 16 : 0; | |
3756 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3757 | add_unwind_opcode (op, 2); | |
3758 | } | |
3759 | ||
3760 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3761 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 3762 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
3763 | if (num_regs_below_16 > 0) |
3764 | { | |
3765 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3766 | add_unwind_opcode (op, 2); | |
3767 | } | |
3768 | ||
3769 | unwind.frame_size += count * 8; | |
3770 | } | |
3771 | ||
3772 | ||
3773 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3774 | |
3775 | static void | |
c19d1205 | 3776 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3777 | { |
c19d1205 | 3778 | int count; |
ca3f61f7 | 3779 | unsigned int reg; |
c19d1205 | 3780 | valueT op; |
b99bd4ef | 3781 | |
5287ad62 | 3782 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3783 | if (count == FAIL) |
b99bd4ef | 3784 | { |
c19d1205 ZW |
3785 | as_bad (_("expected register list")); |
3786 | ignore_rest_of_line (); | |
b99bd4ef NC |
3787 | return; |
3788 | } | |
3789 | ||
c19d1205 | 3790 | demand_empty_rest_of_line (); |
b99bd4ef | 3791 | |
c19d1205 | 3792 | if (reg == 8) |
b99bd4ef | 3793 | { |
c19d1205 ZW |
3794 | /* Short form. */ |
3795 | op = 0xb8 | (count - 1); | |
3796 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3797 | } |
c19d1205 | 3798 | else |
b99bd4ef | 3799 | { |
c19d1205 ZW |
3800 | /* Long form. */ |
3801 | op = 0xb300 | (reg << 4) | (count - 1); | |
3802 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3803 | } |
c19d1205 ZW |
3804 | unwind.frame_size += count * 8 + 4; |
3805 | } | |
b99bd4ef | 3806 | |
b99bd4ef | 3807 | |
c19d1205 ZW |
3808 | /* Parse a directive saving iWMMXt data registers. */ |
3809 | ||
3810 | static void | |
3811 | s_arm_unwind_save_mmxwr (void) | |
3812 | { | |
3813 | int reg; | |
3814 | int hi_reg; | |
3815 | int i; | |
3816 | unsigned mask = 0; | |
3817 | valueT op; | |
b99bd4ef | 3818 | |
c19d1205 ZW |
3819 | if (*input_line_pointer == '{') |
3820 | input_line_pointer++; | |
b99bd4ef | 3821 | |
c19d1205 | 3822 | do |
b99bd4ef | 3823 | { |
dcbf9037 | 3824 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3825 | |
c19d1205 | 3826 | if (reg == FAIL) |
b99bd4ef | 3827 | { |
9b7132d3 | 3828 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 3829 | goto error; |
b99bd4ef NC |
3830 | } |
3831 | ||
c19d1205 ZW |
3832 | if (mask >> reg) |
3833 | as_tsktsk (_("register list not in ascending order")); | |
3834 | mask |= 1 << reg; | |
b99bd4ef | 3835 | |
c19d1205 ZW |
3836 | if (*input_line_pointer == '-') |
3837 | { | |
3838 | input_line_pointer++; | |
dcbf9037 | 3839 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3840 | if (hi_reg == FAIL) |
3841 | { | |
9b7132d3 | 3842 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
3843 | goto error; |
3844 | } | |
3845 | else if (reg >= hi_reg) | |
3846 | { | |
3847 | as_bad (_("bad register range")); | |
3848 | goto error; | |
3849 | } | |
3850 | for (; reg < hi_reg; reg++) | |
3851 | mask |= 1 << reg; | |
3852 | } | |
3853 | } | |
3854 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3855 | |
c19d1205 ZW |
3856 | if (*input_line_pointer == '}') |
3857 | input_line_pointer++; | |
b99bd4ef | 3858 | |
c19d1205 | 3859 | demand_empty_rest_of_line (); |
b99bd4ef | 3860 | |
708587a4 | 3861 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3862 | the list. */ |
3863 | flush_pending_unwind (); | |
b99bd4ef | 3864 | |
c19d1205 | 3865 | for (i = 0; i < 16; i++) |
b99bd4ef | 3866 | { |
c19d1205 ZW |
3867 | if (mask & (1 << i)) |
3868 | unwind.frame_size += 8; | |
b99bd4ef NC |
3869 | } |
3870 | ||
c19d1205 ZW |
3871 | /* Attempt to combine with a previous opcode. We do this because gcc |
3872 | likes to output separate unwind directives for a single block of | |
3873 | registers. */ | |
3874 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3875 | { |
c19d1205 ZW |
3876 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3877 | if ((i & 0xf8) == 0xc0) | |
3878 | { | |
3879 | i &= 7; | |
3880 | /* Only merge if the blocks are contiguous. */ | |
3881 | if (i < 6) | |
3882 | { | |
3883 | if ((mask & 0xfe00) == (1 << 9)) | |
3884 | { | |
3885 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3886 | unwind.opcode_count--; | |
3887 | } | |
3888 | } | |
3889 | else if (i == 6 && unwind.opcode_count >= 2) | |
3890 | { | |
3891 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3892 | reg = i >> 4; | |
3893 | i &= 0xf; | |
b99bd4ef | 3894 | |
c19d1205 ZW |
3895 | op = 0xffff << (reg - 1); |
3896 | if (reg > 0 | |
87a1fd79 | 3897 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
3898 | { |
3899 | op = (1 << (reg + i + 1)) - 1; | |
3900 | op &= ~((1 << reg) - 1); | |
3901 | mask |= op; | |
3902 | unwind.opcode_count -= 2; | |
3903 | } | |
3904 | } | |
3905 | } | |
b99bd4ef NC |
3906 | } |
3907 | ||
c19d1205 ZW |
3908 | hi_reg = 15; |
3909 | /* We want to generate opcodes in the order the registers have been | |
3910 | saved, ie. descending order. */ | |
3911 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3912 | { |
c19d1205 ZW |
3913 | /* Save registers in blocks. */ |
3914 | if (reg < 0 | |
3915 | || !(mask & (1 << reg))) | |
3916 | { | |
3917 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 3918 | preceding block. */ |
c19d1205 ZW |
3919 | if (reg != hi_reg) |
3920 | { | |
3921 | if (reg == 9) | |
3922 | { | |
3923 | /* Short form. */ | |
3924 | op = 0xc0 | (hi_reg - 10); | |
3925 | add_unwind_opcode (op, 1); | |
3926 | } | |
3927 | else | |
3928 | { | |
3929 | /* Long form. */ | |
3930 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
3931 | add_unwind_opcode (op, 2); | |
3932 | } | |
3933 | } | |
3934 | hi_reg = reg - 1; | |
3935 | } | |
b99bd4ef NC |
3936 | } |
3937 | ||
c19d1205 ZW |
3938 | return; |
3939 | error: | |
3940 | ignore_rest_of_line (); | |
b99bd4ef NC |
3941 | } |
3942 | ||
3943 | static void | |
c19d1205 | 3944 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 3945 | { |
c19d1205 ZW |
3946 | int reg; |
3947 | int hi_reg; | |
3948 | unsigned mask = 0; | |
3949 | valueT op; | |
b99bd4ef | 3950 | |
c19d1205 ZW |
3951 | if (*input_line_pointer == '{') |
3952 | input_line_pointer++; | |
b99bd4ef | 3953 | |
c19d1205 | 3954 | do |
b99bd4ef | 3955 | { |
dcbf9037 | 3956 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 3957 | |
c19d1205 ZW |
3958 | if (reg == FAIL) |
3959 | { | |
9b7132d3 | 3960 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3961 | goto error; |
3962 | } | |
b99bd4ef | 3963 | |
c19d1205 ZW |
3964 | reg -= 8; |
3965 | if (mask >> reg) | |
3966 | as_tsktsk (_("register list not in ascending order")); | |
3967 | mask |= 1 << reg; | |
b99bd4ef | 3968 | |
c19d1205 ZW |
3969 | if (*input_line_pointer == '-') |
3970 | { | |
3971 | input_line_pointer++; | |
dcbf9037 | 3972 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
3973 | if (hi_reg == FAIL) |
3974 | { | |
9b7132d3 | 3975 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3976 | goto error; |
3977 | } | |
3978 | else if (reg >= hi_reg) | |
3979 | { | |
3980 | as_bad (_("bad register range")); | |
3981 | goto error; | |
3982 | } | |
3983 | for (; reg < hi_reg; reg++) | |
3984 | mask |= 1 << reg; | |
3985 | } | |
b99bd4ef | 3986 | } |
c19d1205 | 3987 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 3988 | |
c19d1205 ZW |
3989 | if (*input_line_pointer == '}') |
3990 | input_line_pointer++; | |
b99bd4ef | 3991 | |
c19d1205 ZW |
3992 | demand_empty_rest_of_line (); |
3993 | ||
708587a4 | 3994 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3995 | the list. */ |
3996 | flush_pending_unwind (); | |
b99bd4ef | 3997 | |
c19d1205 | 3998 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 3999 | { |
c19d1205 ZW |
4000 | if (mask & (1 << reg)) |
4001 | unwind.frame_size += 4; | |
b99bd4ef | 4002 | } |
c19d1205 ZW |
4003 | op = 0xc700 | mask; |
4004 | add_unwind_opcode (op, 2); | |
4005 | return; | |
4006 | error: | |
4007 | ignore_rest_of_line (); | |
b99bd4ef NC |
4008 | } |
4009 | ||
c19d1205 | 4010 | |
fa073d69 MS |
4011 | /* Parse an unwind_save directive. |
4012 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4013 | |
b99bd4ef | 4014 | static void |
fa073d69 | 4015 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4016 | { |
c19d1205 ZW |
4017 | char *peek; |
4018 | struct reg_entry *reg; | |
4019 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4020 | |
921e5f0a | 4021 | if (!unwind.proc_start) |
c921be7d | 4022 | as_bad (MISSING_FNSTART); |
921e5f0a | 4023 | |
c19d1205 ZW |
4024 | /* Figure out what sort of save we have. */ |
4025 | peek = input_line_pointer; | |
b99bd4ef | 4026 | |
c19d1205 | 4027 | if (*peek == '{') |
b99bd4ef | 4028 | { |
c19d1205 ZW |
4029 | had_brace = TRUE; |
4030 | peek++; | |
b99bd4ef NC |
4031 | } |
4032 | ||
c19d1205 | 4033 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4034 | |
c19d1205 | 4035 | if (!reg) |
b99bd4ef | 4036 | { |
c19d1205 ZW |
4037 | as_bad (_("register expected")); |
4038 | ignore_rest_of_line (); | |
b99bd4ef NC |
4039 | return; |
4040 | } | |
4041 | ||
c19d1205 | 4042 | switch (reg->type) |
b99bd4ef | 4043 | { |
c19d1205 ZW |
4044 | case REG_TYPE_FN: |
4045 | if (had_brace) | |
4046 | { | |
4047 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4048 | ignore_rest_of_line (); | |
4049 | return; | |
4050 | } | |
93ac2687 | 4051 | input_line_pointer = peek; |
c19d1205 | 4052 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4053 | return; |
c19d1205 ZW |
4054 | |
4055 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
4056 | case REG_TYPE_VFD: |
4057 | if (arch_v6) | |
4058 | s_arm_unwind_save_vfp_armv6 (); | |
4059 | else | |
4060 | s_arm_unwind_save_vfp (); | |
4061 | return; | |
c19d1205 ZW |
4062 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
4063 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
4064 | ||
4065 | default: | |
4066 | as_bad (_(".unwind_save does not support this kind of register")); | |
4067 | ignore_rest_of_line (); | |
b99bd4ef | 4068 | } |
c19d1205 | 4069 | } |
b99bd4ef | 4070 | |
b99bd4ef | 4071 | |
c19d1205 ZW |
4072 | /* Parse an unwind_movsp directive. */ |
4073 | ||
4074 | static void | |
4075 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4076 | { | |
4077 | int reg; | |
4078 | valueT op; | |
4fa3602b | 4079 | int offset; |
c19d1205 | 4080 | |
921e5f0a | 4081 | if (!unwind.proc_start) |
c921be7d | 4082 | as_bad (MISSING_FNSTART); |
921e5f0a | 4083 | |
dcbf9037 | 4084 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4085 | if (reg == FAIL) |
b99bd4ef | 4086 | { |
9b7132d3 | 4087 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4088 | ignore_rest_of_line (); |
b99bd4ef NC |
4089 | return; |
4090 | } | |
4fa3602b PB |
4091 | |
4092 | /* Optional constant. */ | |
4093 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4094 | { | |
4095 | if (immediate_for_directive (&offset) == FAIL) | |
4096 | return; | |
4097 | } | |
4098 | else | |
4099 | offset = 0; | |
4100 | ||
c19d1205 | 4101 | demand_empty_rest_of_line (); |
b99bd4ef | 4102 | |
c19d1205 | 4103 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4104 | { |
c19d1205 | 4105 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4106 | return; |
4107 | } | |
4108 | ||
c19d1205 ZW |
4109 | if (unwind.fp_reg != REG_SP) |
4110 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4111 | |
c19d1205 ZW |
4112 | /* Generate opcode to restore the value. */ |
4113 | op = 0x90 | reg; | |
4114 | add_unwind_opcode (op, 1); | |
4115 | ||
4116 | /* Record the information for later. */ | |
4117 | unwind.fp_reg = reg; | |
4fa3602b | 4118 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4119 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4120 | } |
4121 | ||
c19d1205 ZW |
4122 | /* Parse an unwind_pad directive. */ |
4123 | ||
b05fe5cf | 4124 | static void |
c19d1205 | 4125 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4126 | { |
c19d1205 | 4127 | int offset; |
b05fe5cf | 4128 | |
921e5f0a | 4129 | if (!unwind.proc_start) |
c921be7d | 4130 | as_bad (MISSING_FNSTART); |
921e5f0a | 4131 | |
c19d1205 ZW |
4132 | if (immediate_for_directive (&offset) == FAIL) |
4133 | return; | |
b99bd4ef | 4134 | |
c19d1205 ZW |
4135 | if (offset & 3) |
4136 | { | |
4137 | as_bad (_("stack increment must be multiple of 4")); | |
4138 | ignore_rest_of_line (); | |
4139 | return; | |
4140 | } | |
b99bd4ef | 4141 | |
c19d1205 ZW |
4142 | /* Don't generate any opcodes, just record the details for later. */ |
4143 | unwind.frame_size += offset; | |
4144 | unwind.pending_offset += offset; | |
4145 | ||
4146 | demand_empty_rest_of_line (); | |
4147 | } | |
4148 | ||
4149 | /* Parse an unwind_setfp directive. */ | |
4150 | ||
4151 | static void | |
4152 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4153 | { |
c19d1205 ZW |
4154 | int sp_reg; |
4155 | int fp_reg; | |
4156 | int offset; | |
4157 | ||
921e5f0a | 4158 | if (!unwind.proc_start) |
c921be7d | 4159 | as_bad (MISSING_FNSTART); |
921e5f0a | 4160 | |
dcbf9037 | 4161 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4162 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4163 | sp_reg = FAIL; | |
4164 | else | |
dcbf9037 | 4165 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4166 | |
c19d1205 ZW |
4167 | if (fp_reg == FAIL || sp_reg == FAIL) |
4168 | { | |
4169 | as_bad (_("expected <reg>, <reg>")); | |
4170 | ignore_rest_of_line (); | |
4171 | return; | |
4172 | } | |
b99bd4ef | 4173 | |
c19d1205 ZW |
4174 | /* Optional constant. */ |
4175 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4176 | { | |
4177 | if (immediate_for_directive (&offset) == FAIL) | |
4178 | return; | |
4179 | } | |
4180 | else | |
4181 | offset = 0; | |
a737bd4d | 4182 | |
c19d1205 | 4183 | demand_empty_rest_of_line (); |
a737bd4d | 4184 | |
fdfde340 | 4185 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4186 | { |
c19d1205 ZW |
4187 | as_bad (_("register must be either sp or set by a previous" |
4188 | "unwind_movsp directive")); | |
4189 | return; | |
a737bd4d NC |
4190 | } |
4191 | ||
c19d1205 ZW |
4192 | /* Don't generate any opcodes, just record the information for later. */ |
4193 | unwind.fp_reg = fp_reg; | |
4194 | unwind.fp_used = 1; | |
fdfde340 | 4195 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4196 | unwind.fp_offset = unwind.frame_size - offset; |
4197 | else | |
4198 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4199 | } |
4200 | ||
c19d1205 ZW |
4201 | /* Parse an unwind_raw directive. */ |
4202 | ||
4203 | static void | |
4204 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4205 | { |
c19d1205 | 4206 | expressionS exp; |
708587a4 | 4207 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4208 | unsigned char op[16]; |
4209 | int count; | |
a737bd4d | 4210 | |
921e5f0a | 4211 | if (!unwind.proc_start) |
c921be7d | 4212 | as_bad (MISSING_FNSTART); |
921e5f0a | 4213 | |
c19d1205 ZW |
4214 | expression (&exp); |
4215 | if (exp.X_op == O_constant | |
4216 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4217 | { |
c19d1205 ZW |
4218 | unwind.frame_size += exp.X_add_number; |
4219 | expression (&exp); | |
4220 | } | |
4221 | else | |
4222 | exp.X_op = O_illegal; | |
a737bd4d | 4223 | |
c19d1205 ZW |
4224 | if (exp.X_op != O_constant) |
4225 | { | |
4226 | as_bad (_("expected <offset>, <opcode>")); | |
4227 | ignore_rest_of_line (); | |
4228 | return; | |
4229 | } | |
a737bd4d | 4230 | |
c19d1205 | 4231 | count = 0; |
a737bd4d | 4232 | |
c19d1205 ZW |
4233 | /* Parse the opcode. */ |
4234 | for (;;) | |
4235 | { | |
4236 | if (count >= 16) | |
4237 | { | |
4238 | as_bad (_("unwind opcode too long")); | |
4239 | ignore_rest_of_line (); | |
a737bd4d | 4240 | } |
c19d1205 | 4241 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4242 | { |
c19d1205 ZW |
4243 | as_bad (_("invalid unwind opcode")); |
4244 | ignore_rest_of_line (); | |
4245 | return; | |
a737bd4d | 4246 | } |
c19d1205 | 4247 | op[count++] = exp.X_add_number; |
a737bd4d | 4248 | |
c19d1205 ZW |
4249 | /* Parse the next byte. */ |
4250 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4251 | break; | |
a737bd4d | 4252 | |
c19d1205 ZW |
4253 | expression (&exp); |
4254 | } | |
b99bd4ef | 4255 | |
c19d1205 ZW |
4256 | /* Add the opcode bytes in reverse order. */ |
4257 | while (count--) | |
4258 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4259 | |
c19d1205 | 4260 | demand_empty_rest_of_line (); |
b99bd4ef | 4261 | } |
ee065d83 PB |
4262 | |
4263 | ||
4264 | /* Parse a .eabi_attribute directive. */ | |
4265 | ||
4266 | static void | |
4267 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4268 | { | |
ee3c0378 AS |
4269 | int tag = s_vendor_attribute (OBJ_ATTR_PROC); |
4270 | ||
4271 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4272 | attributes_set_explicitly[tag] = 1; | |
ee065d83 | 4273 | } |
8463be01 | 4274 | #endif /* OBJ_ELF */ |
ee065d83 PB |
4275 | |
4276 | static void s_arm_arch (int); | |
7a1d4c38 | 4277 | static void s_arm_object_arch (int); |
ee065d83 PB |
4278 | static void s_arm_cpu (int); |
4279 | static void s_arm_fpu (int); | |
69133863 | 4280 | static void s_arm_arch_extension (int); |
b99bd4ef | 4281 | |
f0927246 NC |
4282 | #ifdef TE_PE |
4283 | ||
4284 | static void | |
5f4273c7 | 4285 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4286 | { |
4287 | expressionS exp; | |
4288 | ||
4289 | do | |
4290 | { | |
4291 | expression (&exp); | |
4292 | if (exp.X_op == O_symbol) | |
4293 | exp.X_op = O_secrel; | |
4294 | ||
4295 | emit_expr (&exp, 4); | |
4296 | } | |
4297 | while (*input_line_pointer++ == ','); | |
4298 | ||
4299 | input_line_pointer--; | |
4300 | demand_empty_rest_of_line (); | |
4301 | } | |
4302 | #endif /* TE_PE */ | |
4303 | ||
c19d1205 ZW |
4304 | /* This table describes all the machine specific pseudo-ops the assembler |
4305 | has to support. The fields are: | |
4306 | pseudo-op name without dot | |
4307 | function to call to execute this pseudo-op | |
4308 | Integer arg to pass to the function. */ | |
b99bd4ef | 4309 | |
c19d1205 | 4310 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4311 | { |
c19d1205 ZW |
4312 | /* Never called because '.req' does not start a line. */ |
4313 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4314 | /* Following two are likewise never called. */ |
4315 | { "dn", s_dn, 0 }, | |
4316 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4317 | { "unreq", s_unreq, 0 }, |
4318 | { "bss", s_bss, 0 }, | |
4319 | { "align", s_align, 0 }, | |
4320 | { "arm", s_arm, 0 }, | |
4321 | { "thumb", s_thumb, 0 }, | |
4322 | { "code", s_code, 0 }, | |
4323 | { "force_thumb", s_force_thumb, 0 }, | |
4324 | { "thumb_func", s_thumb_func, 0 }, | |
4325 | { "thumb_set", s_thumb_set, 0 }, | |
4326 | { "even", s_even, 0 }, | |
4327 | { "ltorg", s_ltorg, 0 }, | |
4328 | { "pool", s_ltorg, 0 }, | |
4329 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4330 | { "cpu", s_arm_cpu, 0 }, |
4331 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4332 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4333 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 4334 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 4335 | #ifdef OBJ_ELF |
c921be7d NC |
4336 | { "word", s_arm_elf_cons, 4 }, |
4337 | { "long", s_arm_elf_cons, 4 }, | |
4338 | { "inst.n", s_arm_elf_inst, 2 }, | |
4339 | { "inst.w", s_arm_elf_inst, 4 }, | |
4340 | { "inst", s_arm_elf_inst, 0 }, | |
4341 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4342 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4343 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4344 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4345 | { "personality", s_arm_unwind_personality, 0 }, | |
4346 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4347 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4348 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4349 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4350 | { "movsp", s_arm_unwind_movsp, 0 }, |
4351 | { "pad", s_arm_unwind_pad, 0 }, | |
4352 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4353 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4354 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
4355 | #else |
4356 | { "word", cons, 4}, | |
f0927246 NC |
4357 | |
4358 | /* These are used for dwarf. */ | |
4359 | {"2byte", cons, 2}, | |
4360 | {"4byte", cons, 4}, | |
4361 | {"8byte", cons, 8}, | |
4362 | /* These are used for dwarf2. */ | |
4363 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4364 | { "loc", dwarf2_directive_loc, 0 }, | |
4365 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4366 | #endif |
4367 | { "extend", float_cons, 'x' }, | |
4368 | { "ldouble", float_cons, 'x' }, | |
4369 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4370 | #ifdef TE_PE |
4371 | {"secrel32", pe_directive_secrel, 0}, | |
4372 | #endif | |
c19d1205 ZW |
4373 | { 0, 0, 0 } |
4374 | }; | |
4375 | \f | |
4376 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4377 | |
c19d1205 ZW |
4378 | /* Generic immediate-value read function for use in insn parsing. |
4379 | STR points to the beginning of the immediate (the leading #); | |
4380 | VAL receives the value; if the value is outside [MIN, MAX] | |
4381 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4382 | optional. */ | |
b99bd4ef | 4383 | |
c19d1205 ZW |
4384 | static int |
4385 | parse_immediate (char **str, int *val, int min, int max, | |
4386 | bfd_boolean prefix_opt) | |
4387 | { | |
4388 | expressionS exp; | |
4389 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4390 | if (exp.X_op != O_constant) | |
b99bd4ef | 4391 | { |
c19d1205 ZW |
4392 | inst.error = _("constant expression required"); |
4393 | return FAIL; | |
4394 | } | |
b99bd4ef | 4395 | |
c19d1205 ZW |
4396 | if (exp.X_add_number < min || exp.X_add_number > max) |
4397 | { | |
4398 | inst.error = _("immediate value out of range"); | |
4399 | return FAIL; | |
4400 | } | |
b99bd4ef | 4401 | |
c19d1205 ZW |
4402 | *val = exp.X_add_number; |
4403 | return SUCCESS; | |
4404 | } | |
b99bd4ef | 4405 | |
5287ad62 | 4406 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4407 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4408 | instructions. Puts the result directly in inst.operands[i]. */ |
4409 | ||
4410 | static int | |
4411 | parse_big_immediate (char **str, int i) | |
4412 | { | |
4413 | expressionS exp; | |
4414 | char *ptr = *str; | |
4415 | ||
4416 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
4417 | ||
4418 | if (exp.X_op == O_constant) | |
036dc3f7 PB |
4419 | { |
4420 | inst.operands[i].imm = exp.X_add_number & 0xffffffff; | |
4421 | /* If we're on a 64-bit host, then a 64-bit number can be returned using | |
4422 | O_constant. We have to be careful not to break compilation for | |
4423 | 32-bit X_add_number, though. */ | |
4424 | if ((exp.X_add_number & ~0xffffffffl) != 0) | |
4425 | { | |
4426 | /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */ | |
4427 | inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff; | |
4428 | inst.operands[i].regisimm = 1; | |
4429 | } | |
4430 | } | |
5287ad62 | 4431 | else if (exp.X_op == O_big |
95b75c01 | 4432 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32) |
5287ad62 JB |
4433 | { |
4434 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 4435 | |
5287ad62 JB |
4436 | /* Bignums have their least significant bits in |
4437 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
4438 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4439 | gas_assert (parts != 0); |
95b75c01 NC |
4440 | |
4441 | /* Make sure that the number is not too big. | |
4442 | PR 11972: Bignums can now be sign-extended to the | |
4443 | size of a .octa so check that the out of range bits | |
4444 | are all zero or all one. */ | |
4445 | if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64) | |
4446 | { | |
4447 | LITTLENUM_TYPE m = -1; | |
4448 | ||
4449 | if (generic_bignum[parts * 2] != 0 | |
4450 | && generic_bignum[parts * 2] != m) | |
4451 | return FAIL; | |
4452 | ||
4453 | for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++) | |
4454 | if (generic_bignum[j] != generic_bignum[j-1]) | |
4455 | return FAIL; | |
4456 | } | |
4457 | ||
5287ad62 JB |
4458 | inst.operands[i].imm = 0; |
4459 | for (j = 0; j < parts; j++, idx++) | |
4460 | inst.operands[i].imm |= generic_bignum[idx] | |
4461 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4462 | inst.operands[i].reg = 0; | |
4463 | for (j = 0; j < parts; j++, idx++) | |
4464 | inst.operands[i].reg |= generic_bignum[idx] | |
4465 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4466 | inst.operands[i].regisimm = 1; | |
4467 | } | |
4468 | else | |
4469 | return FAIL; | |
5f4273c7 | 4470 | |
5287ad62 JB |
4471 | *str = ptr; |
4472 | ||
4473 | return SUCCESS; | |
4474 | } | |
4475 | ||
c19d1205 ZW |
4476 | /* Returns the pseudo-register number of an FPA immediate constant, |
4477 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4478 | |
c19d1205 ZW |
4479 | static int |
4480 | parse_fpa_immediate (char ** str) | |
4481 | { | |
4482 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4483 | char * save_in; | |
4484 | expressionS exp; | |
4485 | int i; | |
4486 | int j; | |
b99bd4ef | 4487 | |
c19d1205 ZW |
4488 | /* First try and match exact strings, this is to guarantee |
4489 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4490 | |
c19d1205 ZW |
4491 | for (i = 0; fp_const[i]; i++) |
4492 | { | |
4493 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4494 | { |
c19d1205 | 4495 | char *start = *str; |
b99bd4ef | 4496 | |
c19d1205 ZW |
4497 | *str += strlen (fp_const[i]); |
4498 | if (is_end_of_line[(unsigned char) **str]) | |
4499 | return i + 8; | |
4500 | *str = start; | |
4501 | } | |
4502 | } | |
b99bd4ef | 4503 | |
c19d1205 ZW |
4504 | /* Just because we didn't get a match doesn't mean that the constant |
4505 | isn't valid, just that it is in a format that we don't | |
4506 | automatically recognize. Try parsing it with the standard | |
4507 | expression routines. */ | |
b99bd4ef | 4508 | |
c19d1205 | 4509 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4510 | |
c19d1205 ZW |
4511 | /* Look for a raw floating point number. */ |
4512 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4513 | && is_end_of_line[(unsigned char) *save_in]) | |
4514 | { | |
4515 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4516 | { | |
4517 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4518 | { |
c19d1205 ZW |
4519 | if (words[j] != fp_values[i][j]) |
4520 | break; | |
b99bd4ef NC |
4521 | } |
4522 | ||
c19d1205 | 4523 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4524 | { |
c19d1205 ZW |
4525 | *str = save_in; |
4526 | return i + 8; | |
b99bd4ef NC |
4527 | } |
4528 | } | |
4529 | } | |
b99bd4ef | 4530 | |
c19d1205 ZW |
4531 | /* Try and parse a more complex expression, this will probably fail |
4532 | unless the code uses a floating point prefix (eg "0f"). */ | |
4533 | save_in = input_line_pointer; | |
4534 | input_line_pointer = *str; | |
4535 | if (expression (&exp) == absolute_section | |
4536 | && exp.X_op == O_big | |
4537 | && exp.X_add_number < 0) | |
4538 | { | |
4539 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4540 | Ditto for 15. */ | |
4541 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4542 | { | |
4543 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4544 | { | |
4545 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4546 | { | |
4547 | if (words[j] != fp_values[i][j]) | |
4548 | break; | |
4549 | } | |
b99bd4ef | 4550 | |
c19d1205 ZW |
4551 | if (j == MAX_LITTLENUMS) |
4552 | { | |
4553 | *str = input_line_pointer; | |
4554 | input_line_pointer = save_in; | |
4555 | return i + 8; | |
4556 | } | |
4557 | } | |
4558 | } | |
b99bd4ef NC |
4559 | } |
4560 | ||
c19d1205 ZW |
4561 | *str = input_line_pointer; |
4562 | input_line_pointer = save_in; | |
4563 | inst.error = _("invalid FPA immediate expression"); | |
4564 | return FAIL; | |
b99bd4ef NC |
4565 | } |
4566 | ||
136da414 JB |
4567 | /* Returns 1 if a number has "quarter-precision" float format |
4568 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4569 | ||
4570 | static int | |
4571 | is_quarter_float (unsigned imm) | |
4572 | { | |
4573 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4574 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4575 | } | |
4576 | ||
4577 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4578 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4579 | The zero and minus-zero cases need special handling, since they can't be |
4580 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4581 | loaded as integer constants. */ | |
136da414 JB |
4582 | |
4583 | static unsigned | |
4584 | parse_qfloat_immediate (char **ccp, int *immed) | |
4585 | { | |
4586 | char *str = *ccp; | |
c96612cc | 4587 | char *fpnum; |
136da414 | 4588 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4589 | int found_fpchar = 0; |
5f4273c7 | 4590 | |
136da414 | 4591 | skip_past_char (&str, '#'); |
5f4273c7 | 4592 | |
c96612cc JB |
4593 | /* We must not accidentally parse an integer as a floating-point number. Make |
4594 | sure that the value we parse is not an integer by checking for special | |
4595 | characters '.' or 'e'. | |
4596 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4597 | information isn't in a very usable state at parse time. */ | |
4598 | fpnum = str; | |
4599 | skip_whitespace (fpnum); | |
4600 | ||
4601 | if (strncmp (fpnum, "0x", 2) == 0) | |
4602 | return FAIL; | |
4603 | else | |
4604 | { | |
4605 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
4606 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') | |
4607 | { | |
4608 | found_fpchar = 1; | |
4609 | break; | |
4610 | } | |
4611 | ||
4612 | if (!found_fpchar) | |
4613 | return FAIL; | |
4614 | } | |
5f4273c7 | 4615 | |
136da414 JB |
4616 | if ((str = atof_ieee (str, 's', words)) != NULL) |
4617 | { | |
4618 | unsigned fpword = 0; | |
4619 | int i; | |
5f4273c7 | 4620 | |
136da414 JB |
4621 | /* Our FP word must be 32 bits (single-precision FP). */ |
4622 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4623 | { | |
4624 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4625 | fpword |= words[i]; | |
4626 | } | |
5f4273c7 | 4627 | |
c96612cc | 4628 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
136da414 JB |
4629 | *immed = fpword; |
4630 | else | |
4631 | return FAIL; | |
4632 | ||
4633 | *ccp = str; | |
5f4273c7 | 4634 | |
136da414 JB |
4635 | return SUCCESS; |
4636 | } | |
5f4273c7 | 4637 | |
136da414 JB |
4638 | return FAIL; |
4639 | } | |
4640 | ||
c19d1205 ZW |
4641 | /* Shift operands. */ |
4642 | enum shift_kind | |
b99bd4ef | 4643 | { |
c19d1205 ZW |
4644 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4645 | }; | |
b99bd4ef | 4646 | |
c19d1205 ZW |
4647 | struct asm_shift_name |
4648 | { | |
4649 | const char *name; | |
4650 | enum shift_kind kind; | |
4651 | }; | |
b99bd4ef | 4652 | |
c19d1205 ZW |
4653 | /* Third argument to parse_shift. */ |
4654 | enum parse_shift_mode | |
4655 | { | |
4656 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4657 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4658 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4659 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4660 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4661 | }; | |
b99bd4ef | 4662 | |
c19d1205 ZW |
4663 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4664 | This has three forms: | |
b99bd4ef | 4665 | |
c19d1205 ZW |
4666 | (LSL|LSR|ASL|ASR|ROR) Rs |
4667 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4668 | RRX | |
b99bd4ef | 4669 | |
c19d1205 ZW |
4670 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4671 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4672 | |
c19d1205 ZW |
4673 | static int |
4674 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4675 | { |
c19d1205 ZW |
4676 | const struct asm_shift_name *shift_name; |
4677 | enum shift_kind shift; | |
4678 | char *s = *str; | |
4679 | char *p = s; | |
4680 | int reg; | |
b99bd4ef | 4681 | |
c19d1205 ZW |
4682 | for (p = *str; ISALPHA (*p); p++) |
4683 | ; | |
b99bd4ef | 4684 | |
c19d1205 | 4685 | if (p == *str) |
b99bd4ef | 4686 | { |
c19d1205 ZW |
4687 | inst.error = _("shift expression expected"); |
4688 | return FAIL; | |
b99bd4ef NC |
4689 | } |
4690 | ||
21d799b5 NC |
4691 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
4692 | p - *str); | |
c19d1205 ZW |
4693 | |
4694 | if (shift_name == NULL) | |
b99bd4ef | 4695 | { |
c19d1205 ZW |
4696 | inst.error = _("shift expression expected"); |
4697 | return FAIL; | |
b99bd4ef NC |
4698 | } |
4699 | ||
c19d1205 | 4700 | shift = shift_name->kind; |
b99bd4ef | 4701 | |
c19d1205 ZW |
4702 | switch (mode) |
4703 | { | |
4704 | case NO_SHIFT_RESTRICT: | |
4705 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4706 | |
c19d1205 ZW |
4707 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4708 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4709 | { | |
4710 | inst.error = _("'LSL' or 'ASR' required"); | |
4711 | return FAIL; | |
4712 | } | |
4713 | break; | |
b99bd4ef | 4714 | |
c19d1205 ZW |
4715 | case SHIFT_LSL_IMMEDIATE: |
4716 | if (shift != SHIFT_LSL) | |
4717 | { | |
4718 | inst.error = _("'LSL' required"); | |
4719 | return FAIL; | |
4720 | } | |
4721 | break; | |
b99bd4ef | 4722 | |
c19d1205 ZW |
4723 | case SHIFT_ASR_IMMEDIATE: |
4724 | if (shift != SHIFT_ASR) | |
4725 | { | |
4726 | inst.error = _("'ASR' required"); | |
4727 | return FAIL; | |
4728 | } | |
4729 | break; | |
b99bd4ef | 4730 | |
c19d1205 ZW |
4731 | default: abort (); |
4732 | } | |
b99bd4ef | 4733 | |
c19d1205 ZW |
4734 | if (shift != SHIFT_RRX) |
4735 | { | |
4736 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4737 | skip_whitespace (p); | |
b99bd4ef | 4738 | |
c19d1205 | 4739 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4740 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4741 | { |
4742 | inst.operands[i].imm = reg; | |
4743 | inst.operands[i].immisreg = 1; | |
4744 | } | |
4745 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4746 | return FAIL; | |
4747 | } | |
4748 | inst.operands[i].shift_kind = shift; | |
4749 | inst.operands[i].shifted = 1; | |
4750 | *str = p; | |
4751 | return SUCCESS; | |
b99bd4ef NC |
4752 | } |
4753 | ||
c19d1205 | 4754 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4755 | |
c19d1205 ZW |
4756 | #<immediate> |
4757 | #<immediate>, <rotate> | |
4758 | <Rm> | |
4759 | <Rm>, <shift> | |
b99bd4ef | 4760 | |
c19d1205 ZW |
4761 | where <shift> is defined by parse_shift above, and <rotate> is a |
4762 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4763 | is deferred to md_apply_fix. */ |
b99bd4ef | 4764 | |
c19d1205 ZW |
4765 | static int |
4766 | parse_shifter_operand (char **str, int i) | |
4767 | { | |
4768 | int value; | |
91d6fa6a | 4769 | expressionS exp; |
b99bd4ef | 4770 | |
dcbf9037 | 4771 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4772 | { |
4773 | inst.operands[i].reg = value; | |
4774 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4775 | |
c19d1205 ZW |
4776 | /* parse_shift will override this if appropriate */ |
4777 | inst.reloc.exp.X_op = O_constant; | |
4778 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4779 | |
c19d1205 ZW |
4780 | if (skip_past_comma (str) == FAIL) |
4781 | return SUCCESS; | |
b99bd4ef | 4782 | |
c19d1205 ZW |
4783 | /* Shift operation on register. */ |
4784 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4785 | } |
4786 | ||
c19d1205 ZW |
4787 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4788 | return FAIL; | |
b99bd4ef | 4789 | |
c19d1205 | 4790 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4791 | { |
c19d1205 | 4792 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 4793 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 4794 | return FAIL; |
b99bd4ef | 4795 | |
91d6fa6a | 4796 | if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
c19d1205 ZW |
4797 | { |
4798 | inst.error = _("constant expression expected"); | |
4799 | return FAIL; | |
4800 | } | |
b99bd4ef | 4801 | |
91d6fa6a | 4802 | value = exp.X_add_number; |
c19d1205 ZW |
4803 | if (value < 0 || value > 30 || value % 2 != 0) |
4804 | { | |
4805 | inst.error = _("invalid rotation"); | |
4806 | return FAIL; | |
4807 | } | |
4808 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4809 | { | |
4810 | inst.error = _("invalid constant"); | |
4811 | return FAIL; | |
4812 | } | |
09d92015 | 4813 | |
55cf6793 | 4814 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
4815 | inst.reloc.exp.X_add_number |
4816 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
4817 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
4818 | } |
4819 | ||
c19d1205 ZW |
4820 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4821 | inst.reloc.pc_rel = 0; | |
4822 | return SUCCESS; | |
09d92015 MM |
4823 | } |
4824 | ||
4962c51a MS |
4825 | /* Group relocation information. Each entry in the table contains the |
4826 | textual name of the relocation as may appear in assembler source | |
4827 | and must end with a colon. | |
4828 | Along with this textual name are the relocation codes to be used if | |
4829 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4830 | an LDR, an LDRS, or an LDC. */ | |
4831 | ||
4832 | struct group_reloc_table_entry | |
4833 | { | |
4834 | const char *name; | |
4835 | int alu_code; | |
4836 | int ldr_code; | |
4837 | int ldrs_code; | |
4838 | int ldc_code; | |
4839 | }; | |
4840 | ||
4841 | typedef enum | |
4842 | { | |
4843 | /* Varieties of non-ALU group relocation. */ | |
4844 | ||
4845 | GROUP_LDR, | |
4846 | GROUP_LDRS, | |
4847 | GROUP_LDC | |
4848 | } group_reloc_type; | |
4849 | ||
4850 | static struct group_reloc_table_entry group_reloc_table[] = | |
4851 | { /* Program counter relative: */ | |
4852 | { "pc_g0_nc", | |
4853 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4854 | 0, /* LDR */ | |
4855 | 0, /* LDRS */ | |
4856 | 0 }, /* LDC */ | |
4857 | { "pc_g0", | |
4858 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4859 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4860 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4861 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4862 | { "pc_g1_nc", | |
4863 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4864 | 0, /* LDR */ | |
4865 | 0, /* LDRS */ | |
4866 | 0 }, /* LDC */ | |
4867 | { "pc_g1", | |
4868 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4869 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4870 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4871 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4872 | { "pc_g2", | |
4873 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4874 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4875 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4876 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4877 | /* Section base relative */ | |
4878 | { "sb_g0_nc", | |
4879 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4880 | 0, /* LDR */ | |
4881 | 0, /* LDRS */ | |
4882 | 0 }, /* LDC */ | |
4883 | { "sb_g0", | |
4884 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4885 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4886 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4887 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4888 | { "sb_g1_nc", | |
4889 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4890 | 0, /* LDR */ | |
4891 | 0, /* LDRS */ | |
4892 | 0 }, /* LDC */ | |
4893 | { "sb_g1", | |
4894 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4895 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4896 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4897 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4898 | { "sb_g2", | |
4899 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
4900 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
4901 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
4902 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
4903 | ||
4904 | /* Given the address of a pointer pointing to the textual name of a group | |
4905 | relocation as may appear in assembler source, attempt to find its details | |
4906 | in group_reloc_table. The pointer will be updated to the character after | |
4907 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
4908 | otherwise. On success, *entry will be updated to point at the relevant | |
4909 | group_reloc_table entry. */ | |
4910 | ||
4911 | static int | |
4912 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
4913 | { | |
4914 | unsigned int i; | |
4915 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
4916 | { | |
4917 | int length = strlen (group_reloc_table[i].name); | |
4918 | ||
5f4273c7 NC |
4919 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
4920 | && (*str)[length] == ':') | |
4962c51a MS |
4921 | { |
4922 | *out = &group_reloc_table[i]; | |
4923 | *str += (length + 1); | |
4924 | return SUCCESS; | |
4925 | } | |
4926 | } | |
4927 | ||
4928 | return FAIL; | |
4929 | } | |
4930 | ||
4931 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
4932 | (as for parse_shifter_operand) where group relocations are allowed: | |
4933 | ||
4934 | #<immediate> | |
4935 | #<immediate>, <rotate> | |
4936 | #:<group_reloc>:<expression> | |
4937 | <Rm> | |
4938 | <Rm>, <shift> | |
4939 | ||
4940 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
4941 | The hashes are optional. | |
4942 | ||
4943 | Everything else is as for parse_shifter_operand. */ | |
4944 | ||
4945 | static parse_operand_result | |
4946 | parse_shifter_operand_group_reloc (char **str, int i) | |
4947 | { | |
4948 | /* Determine if we have the sequence of characters #: or just : | |
4949 | coming next. If we do, then we check for a group relocation. | |
4950 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
4951 | ||
4952 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
4953 | || (*str)[0] == ':') | |
4954 | { | |
4955 | struct group_reloc_table_entry *entry; | |
4956 | ||
4957 | if ((*str)[0] == '#') | |
4958 | (*str) += 2; | |
4959 | else | |
4960 | (*str)++; | |
4961 | ||
4962 | /* Try to parse a group relocation. Anything else is an error. */ | |
4963 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
4964 | { | |
4965 | inst.error = _("unknown group relocation"); | |
4966 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4967 | } | |
4968 | ||
4969 | /* We now have the group relocation table entry corresponding to | |
4970 | the name in the assembler source. Next, we parse the expression. */ | |
4971 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
4972 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4973 | ||
4974 | /* Record the relocation type (always the ALU variant here). */ | |
21d799b5 | 4975 | inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code; |
9c2799c2 | 4976 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
4977 | |
4978 | return PARSE_OPERAND_SUCCESS; | |
4979 | } | |
4980 | else | |
4981 | return parse_shifter_operand (str, i) == SUCCESS | |
4982 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
4983 | ||
4984 | /* Never reached. */ | |
4985 | } | |
4986 | ||
8e560766 MGD |
4987 | /* Parse a Neon alignment expression. Information is written to |
4988 | inst.operands[i]. We assume the initial ':' has been skipped. | |
4989 | ||
4990 | align .imm = align << 8, .immisalign=1, .preind=0 */ | |
4991 | static parse_operand_result | |
4992 | parse_neon_alignment (char **str, int i) | |
4993 | { | |
4994 | char *p = *str; | |
4995 | expressionS exp; | |
4996 | ||
4997 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
4998 | ||
4999 | if (exp.X_op != O_constant) | |
5000 | { | |
5001 | inst.error = _("alignment must be constant"); | |
5002 | return PARSE_OPERAND_FAIL; | |
5003 | } | |
5004 | ||
5005 | inst.operands[i].imm = exp.X_add_number << 8; | |
5006 | inst.operands[i].immisalign = 1; | |
5007 | /* Alignments are not pre-indexes. */ | |
5008 | inst.operands[i].preind = 0; | |
5009 | ||
5010 | *str = p; | |
5011 | return PARSE_OPERAND_SUCCESS; | |
5012 | } | |
5013 | ||
c19d1205 ZW |
5014 | /* Parse all forms of an ARM address expression. Information is written |
5015 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 5016 | |
c19d1205 | 5017 | Preindexed addressing (.preind=1): |
09d92015 | 5018 | |
c19d1205 ZW |
5019 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
5020 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5021 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5022 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5023 | |
c19d1205 | 5024 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5025 | |
c19d1205 | 5026 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5027 | |
c19d1205 ZW |
5028 | [Rn], #offset .reg=Rn .reloc.exp=offset |
5029 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5030 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5031 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5032 | |
c19d1205 | 5033 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5034 | |
c19d1205 | 5035 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5036 | |
c19d1205 | 5037 | Other: |
09d92015 | 5038 | |
c19d1205 ZW |
5039 | [Rn]{!} shorthand for [Rn,#0]{!} |
5040 | =immediate .isreg=0 .reloc.exp=immediate | |
5041 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 5042 | |
c19d1205 ZW |
5043 | It is the caller's responsibility to check for addressing modes not |
5044 | supported by the instruction, and to set inst.reloc.type. */ | |
5045 | ||
4962c51a MS |
5046 | static parse_operand_result |
5047 | parse_address_main (char **str, int i, int group_relocations, | |
5048 | group_reloc_type group_type) | |
09d92015 | 5049 | { |
c19d1205 ZW |
5050 | char *p = *str; |
5051 | int reg; | |
09d92015 | 5052 | |
c19d1205 | 5053 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5054 | { |
c19d1205 ZW |
5055 | if (skip_past_char (&p, '=') == FAIL) |
5056 | { | |
974da60d | 5057 | /* Bare address - translate to PC-relative offset. */ |
c19d1205 ZW |
5058 | inst.reloc.pc_rel = 1; |
5059 | inst.operands[i].reg = REG_PC; | |
5060 | inst.operands[i].isreg = 1; | |
5061 | inst.operands[i].preind = 1; | |
5062 | } | |
974da60d | 5063 | /* Otherwise a load-constant pseudo op, no special treatment needed here. */ |
09d92015 | 5064 | |
c19d1205 | 5065 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 5066 | return PARSE_OPERAND_FAIL; |
09d92015 | 5067 | |
c19d1205 | 5068 | *str = p; |
4962c51a | 5069 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5070 | } |
5071 | ||
dcbf9037 | 5072 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 5073 | { |
c19d1205 | 5074 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 5075 | return PARSE_OPERAND_FAIL; |
09d92015 | 5076 | } |
c19d1205 ZW |
5077 | inst.operands[i].reg = reg; |
5078 | inst.operands[i].isreg = 1; | |
09d92015 | 5079 | |
c19d1205 | 5080 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5081 | { |
c19d1205 | 5082 | inst.operands[i].preind = 1; |
09d92015 | 5083 | |
c19d1205 ZW |
5084 | if (*p == '+') p++; |
5085 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5086 | ||
dcbf9037 | 5087 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5088 | { |
c19d1205 ZW |
5089 | inst.operands[i].imm = reg; |
5090 | inst.operands[i].immisreg = 1; | |
5091 | ||
5092 | if (skip_past_comma (&p) == SUCCESS) | |
5093 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5094 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5095 | } |
5287ad62 | 5096 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5097 | { |
5098 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5099 | code before we get to see it here. This may be subject to | |
5100 | change. */ | |
5101 | parse_operand_result result = parse_neon_alignment (&p, i); | |
5102 | ||
5103 | if (result != PARSE_OPERAND_SUCCESS) | |
5104 | return result; | |
5105 | } | |
c19d1205 ZW |
5106 | else |
5107 | { | |
5108 | if (inst.operands[i].negative) | |
5109 | { | |
5110 | inst.operands[i].negative = 0; | |
5111 | p--; | |
5112 | } | |
4962c51a | 5113 | |
5f4273c7 NC |
5114 | if (group_relocations |
5115 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5116 | { |
5117 | struct group_reloc_table_entry *entry; | |
5118 | ||
5119 | /* Skip over the #: or : sequence. */ | |
5120 | if (*p == '#') | |
5121 | p += 2; | |
5122 | else | |
5123 | p++; | |
5124 | ||
5125 | /* Try to parse a group relocation. Anything else is an | |
5126 | error. */ | |
5127 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
5128 | { | |
5129 | inst.error = _("unknown group relocation"); | |
5130 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5131 | } | |
5132 | ||
5133 | /* We now have the group relocation table entry corresponding to | |
5134 | the name in the assembler source. Next, we parse the | |
5135 | expression. */ | |
5136 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5137 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5138 | ||
5139 | /* Record the relocation type. */ | |
5140 | switch (group_type) | |
5141 | { | |
5142 | case GROUP_LDR: | |
21d799b5 | 5143 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code; |
4962c51a MS |
5144 | break; |
5145 | ||
5146 | case GROUP_LDRS: | |
21d799b5 | 5147 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code; |
4962c51a MS |
5148 | break; |
5149 | ||
5150 | case GROUP_LDC: | |
21d799b5 | 5151 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code; |
4962c51a MS |
5152 | break; |
5153 | ||
5154 | default: | |
9c2799c2 | 5155 | gas_assert (0); |
4962c51a MS |
5156 | } |
5157 | ||
5158 | if (inst.reloc.type == 0) | |
5159 | { | |
5160 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5161 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5162 | } | |
5163 | } | |
5164 | else | |
5165 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5166 | return PARSE_OPERAND_FAIL; | |
09d92015 MM |
5167 | } |
5168 | } | |
8e560766 MGD |
5169 | else if (skip_past_char (&p, ':') == SUCCESS) |
5170 | { | |
5171 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
5172 | before we get to see it here. This may be subject to change. */ | |
5173 | parse_operand_result result = parse_neon_alignment (&p, i); | |
5174 | ||
5175 | if (result != PARSE_OPERAND_SUCCESS) | |
5176 | return result; | |
5177 | } | |
09d92015 | 5178 | |
c19d1205 | 5179 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5180 | { |
c19d1205 | 5181 | inst.error = _("']' expected"); |
4962c51a | 5182 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5183 | } |
5184 | ||
c19d1205 ZW |
5185 | if (skip_past_char (&p, '!') == SUCCESS) |
5186 | inst.operands[i].writeback = 1; | |
09d92015 | 5187 | |
c19d1205 | 5188 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5189 | { |
c19d1205 ZW |
5190 | if (skip_past_char (&p, '{') == SUCCESS) |
5191 | { | |
5192 | /* [Rn], {expr} - unindexed, with option */ | |
5193 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5194 | 0, 255, TRUE) == FAIL) |
4962c51a | 5195 | return PARSE_OPERAND_FAIL; |
09d92015 | 5196 | |
c19d1205 ZW |
5197 | if (skip_past_char (&p, '}') == FAIL) |
5198 | { | |
5199 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5200 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5201 | } |
5202 | if (inst.operands[i].preind) | |
5203 | { | |
5204 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5205 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5206 | } |
5207 | *str = p; | |
4962c51a | 5208 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5209 | } |
c19d1205 ZW |
5210 | else |
5211 | { | |
5212 | inst.operands[i].postind = 1; | |
5213 | inst.operands[i].writeback = 1; | |
09d92015 | 5214 | |
c19d1205 ZW |
5215 | if (inst.operands[i].preind) |
5216 | { | |
5217 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5218 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5219 | } |
09d92015 | 5220 | |
c19d1205 ZW |
5221 | if (*p == '+') p++; |
5222 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5223 | |
dcbf9037 | 5224 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5225 | { |
5287ad62 JB |
5226 | /* We might be using the immediate for alignment already. If we |
5227 | are, OR the register number into the low-order bits. */ | |
5228 | if (inst.operands[i].immisalign) | |
5229 | inst.operands[i].imm |= reg; | |
5230 | else | |
5231 | inst.operands[i].imm = reg; | |
c19d1205 | 5232 | inst.operands[i].immisreg = 1; |
a737bd4d | 5233 | |
c19d1205 ZW |
5234 | if (skip_past_comma (&p) == SUCCESS) |
5235 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5236 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5237 | } |
5238 | else | |
5239 | { | |
5240 | if (inst.operands[i].negative) | |
5241 | { | |
5242 | inst.operands[i].negative = 0; | |
5243 | p--; | |
5244 | } | |
5245 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5246 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5247 | } |
5248 | } | |
a737bd4d NC |
5249 | } |
5250 | ||
c19d1205 ZW |
5251 | /* If at this point neither .preind nor .postind is set, we have a |
5252 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5253 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5254 | { | |
5255 | inst.operands[i].preind = 1; | |
5256 | inst.reloc.exp.X_op = O_constant; | |
5257 | inst.reloc.exp.X_add_number = 0; | |
5258 | } | |
5259 | *str = p; | |
4962c51a MS |
5260 | return PARSE_OPERAND_SUCCESS; |
5261 | } | |
5262 | ||
5263 | static int | |
5264 | parse_address (char **str, int i) | |
5265 | { | |
21d799b5 | 5266 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
4962c51a MS |
5267 | ? SUCCESS : FAIL; |
5268 | } | |
5269 | ||
5270 | static parse_operand_result | |
5271 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5272 | { | |
5273 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5274 | } |
5275 | ||
b6895b4f PB |
5276 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5277 | static int | |
5278 | parse_half (char **str) | |
5279 | { | |
5280 | char * p; | |
5f4273c7 | 5281 | |
b6895b4f PB |
5282 | p = *str; |
5283 | skip_past_char (&p, '#'); | |
5f4273c7 | 5284 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5285 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5286 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5287 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5288 | ||
5289 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5290 | { | |
5291 | p += 9; | |
5f4273c7 | 5292 | skip_whitespace (p); |
b6895b4f PB |
5293 | } |
5294 | ||
5295 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5296 | return FAIL; | |
5297 | ||
5298 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5299 | { | |
5300 | if (inst.reloc.exp.X_op != O_constant) | |
5301 | { | |
5302 | inst.error = _("constant expression expected"); | |
5303 | return FAIL; | |
5304 | } | |
5305 | if (inst.reloc.exp.X_add_number < 0 | |
5306 | || inst.reloc.exp.X_add_number > 0xffff) | |
5307 | { | |
5308 | inst.error = _("immediate value out of range"); | |
5309 | return FAIL; | |
5310 | } | |
5311 | } | |
5312 | *str = p; | |
5313 | return SUCCESS; | |
5314 | } | |
5315 | ||
c19d1205 | 5316 | /* Miscellaneous. */ |
a737bd4d | 5317 | |
c19d1205 ZW |
5318 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5319 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5320 | static int | |
5321 | parse_psr (char **str) | |
09d92015 | 5322 | { |
c19d1205 ZW |
5323 | char *p; |
5324 | unsigned long psr_field; | |
62b3e311 PB |
5325 | const struct asm_psr *psr; |
5326 | char *start; | |
09d92015 | 5327 | |
c19d1205 ZW |
5328 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5329 | feature for ease of use and backwards compatibility. */ | |
5330 | p = *str; | |
62b3e311 | 5331 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 5332 | psr_field = SPSR_BIT; |
59b42a0d MGD |
5333 | else if (strncasecmp (p, "CPSR", 4) == 0 |
5334 | || (strncasecmp (p, "APSR", 4) == 0 | |
5335 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))) | |
c19d1205 ZW |
5336 | psr_field = 0; |
5337 | else | |
62b3e311 PB |
5338 | { |
5339 | start = p; | |
5340 | do | |
5341 | p++; | |
5342 | while (ISALNUM (*p) || *p == '_'); | |
5343 | ||
21d799b5 NC |
5344 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
5345 | p - start); | |
62b3e311 PB |
5346 | if (!psr) |
5347 | return FAIL; | |
09d92015 | 5348 | |
62b3e311 PB |
5349 | *str = p; |
5350 | return psr->field; | |
5351 | } | |
09d92015 | 5352 | |
62b3e311 | 5353 | p += 4; |
c19d1205 ZW |
5354 | if (*p == '_') |
5355 | { | |
5356 | /* A suffix follows. */ | |
c19d1205 ZW |
5357 | p++; |
5358 | start = p; | |
a737bd4d | 5359 | |
c19d1205 ZW |
5360 | do |
5361 | p++; | |
5362 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5363 | |
21d799b5 NC |
5364 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
5365 | p - start); | |
c19d1205 ZW |
5366 | if (!psr) |
5367 | goto error; | |
a737bd4d | 5368 | |
c19d1205 | 5369 | psr_field |= psr->field; |
a737bd4d | 5370 | } |
c19d1205 | 5371 | else |
a737bd4d | 5372 | { |
c19d1205 ZW |
5373 | if (ISALNUM (*p)) |
5374 | goto error; /* Garbage after "[CS]PSR". */ | |
5375 | ||
5376 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5377 | } |
c19d1205 ZW |
5378 | *str = p; |
5379 | return psr_field; | |
a737bd4d | 5380 | |
c19d1205 ZW |
5381 | error: |
5382 | inst.error = _("flag for {c}psr instruction expected"); | |
5383 | return FAIL; | |
a737bd4d NC |
5384 | } |
5385 | ||
c19d1205 ZW |
5386 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5387 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5388 | |
c19d1205 ZW |
5389 | static int |
5390 | parse_cps_flags (char **str) | |
a737bd4d | 5391 | { |
c19d1205 ZW |
5392 | int val = 0; |
5393 | int saw_a_flag = 0; | |
5394 | char *s = *str; | |
a737bd4d | 5395 | |
c19d1205 ZW |
5396 | for (;;) |
5397 | switch (*s++) | |
5398 | { | |
5399 | case '\0': case ',': | |
5400 | goto done; | |
a737bd4d | 5401 | |
c19d1205 ZW |
5402 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5403 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5404 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5405 | |
c19d1205 ZW |
5406 | default: |
5407 | inst.error = _("unrecognized CPS flag"); | |
5408 | return FAIL; | |
5409 | } | |
a737bd4d | 5410 | |
c19d1205 ZW |
5411 | done: |
5412 | if (saw_a_flag == 0) | |
a737bd4d | 5413 | { |
c19d1205 ZW |
5414 | inst.error = _("missing CPS flags"); |
5415 | return FAIL; | |
a737bd4d | 5416 | } |
a737bd4d | 5417 | |
c19d1205 ZW |
5418 | *str = s - 1; |
5419 | return val; | |
a737bd4d NC |
5420 | } |
5421 | ||
c19d1205 ZW |
5422 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
5423 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
5424 | |
5425 | static int | |
c19d1205 | 5426 | parse_endian_specifier (char **str) |
a737bd4d | 5427 | { |
c19d1205 ZW |
5428 | int little_endian; |
5429 | char *s = *str; | |
a737bd4d | 5430 | |
c19d1205 ZW |
5431 | if (strncasecmp (s, "BE", 2)) |
5432 | little_endian = 0; | |
5433 | else if (strncasecmp (s, "LE", 2)) | |
5434 | little_endian = 1; | |
5435 | else | |
a737bd4d | 5436 | { |
c19d1205 | 5437 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5438 | return FAIL; |
5439 | } | |
5440 | ||
c19d1205 | 5441 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 5442 | { |
c19d1205 | 5443 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5444 | return FAIL; |
5445 | } | |
5446 | ||
c19d1205 ZW |
5447 | *str = s + 2; |
5448 | return little_endian; | |
5449 | } | |
a737bd4d | 5450 | |
c19d1205 ZW |
5451 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
5452 | value suitable for poking into the rotate field of an sxt or sxta | |
5453 | instruction, or FAIL on error. */ | |
5454 | ||
5455 | static int | |
5456 | parse_ror (char **str) | |
5457 | { | |
5458 | int rot; | |
5459 | char *s = *str; | |
5460 | ||
5461 | if (strncasecmp (s, "ROR", 3) == 0) | |
5462 | s += 3; | |
5463 | else | |
a737bd4d | 5464 | { |
c19d1205 | 5465 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
5466 | return FAIL; |
5467 | } | |
c19d1205 ZW |
5468 | |
5469 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
5470 | return FAIL; | |
5471 | ||
5472 | switch (rot) | |
a737bd4d | 5473 | { |
c19d1205 ZW |
5474 | case 0: *str = s; return 0x0; |
5475 | case 8: *str = s; return 0x1; | |
5476 | case 16: *str = s; return 0x2; | |
5477 | case 24: *str = s; return 0x3; | |
5478 | ||
5479 | default: | |
5480 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
5481 | return FAIL; |
5482 | } | |
c19d1205 | 5483 | } |
a737bd4d | 5484 | |
c19d1205 ZW |
5485 | /* Parse a conditional code (from conds[] below). The value returned is in the |
5486 | range 0 .. 14, or FAIL. */ | |
5487 | static int | |
5488 | parse_cond (char **str) | |
5489 | { | |
c462b453 | 5490 | char *q; |
c19d1205 | 5491 | const struct asm_cond *c; |
c462b453 PB |
5492 | int n; |
5493 | /* Condition codes are always 2 characters, so matching up to | |
5494 | 3 characters is sufficient. */ | |
5495 | char cond[3]; | |
a737bd4d | 5496 | |
c462b453 PB |
5497 | q = *str; |
5498 | n = 0; | |
5499 | while (ISALPHA (*q) && n < 3) | |
5500 | { | |
e07e6e58 | 5501 | cond[n] = TOLOWER (*q); |
c462b453 PB |
5502 | q++; |
5503 | n++; | |
5504 | } | |
a737bd4d | 5505 | |
21d799b5 | 5506 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 5507 | if (!c) |
a737bd4d | 5508 | { |
c19d1205 | 5509 | inst.error = _("condition required"); |
a737bd4d NC |
5510 | return FAIL; |
5511 | } | |
5512 | ||
c19d1205 ZW |
5513 | *str = q; |
5514 | return c->value; | |
5515 | } | |
5516 | ||
62b3e311 PB |
5517 | /* Parse an option for a barrier instruction. Returns the encoding for the |
5518 | option, or FAIL. */ | |
5519 | static int | |
5520 | parse_barrier (char **str) | |
5521 | { | |
5522 | char *p, *q; | |
5523 | const struct asm_barrier_opt *o; | |
5524 | ||
5525 | p = q = *str; | |
5526 | while (ISALPHA (*q)) | |
5527 | q++; | |
5528 | ||
21d799b5 NC |
5529 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
5530 | q - p); | |
62b3e311 PB |
5531 | if (!o) |
5532 | return FAIL; | |
5533 | ||
5534 | *str = q; | |
5535 | return o->value; | |
5536 | } | |
5537 | ||
92e90b6e PB |
5538 | /* Parse the operands of a table branch instruction. Similar to a memory |
5539 | operand. */ | |
5540 | static int | |
5541 | parse_tb (char **str) | |
5542 | { | |
5543 | char * p = *str; | |
5544 | int reg; | |
5545 | ||
5546 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5547 | { |
5548 | inst.error = _("'[' expected"); | |
5549 | return FAIL; | |
5550 | } | |
92e90b6e | 5551 | |
dcbf9037 | 5552 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5553 | { |
5554 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5555 | return FAIL; | |
5556 | } | |
5557 | inst.operands[0].reg = reg; | |
5558 | ||
5559 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5560 | { |
5561 | inst.error = _("',' expected"); | |
5562 | return FAIL; | |
5563 | } | |
5f4273c7 | 5564 | |
dcbf9037 | 5565 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5566 | { |
5567 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5568 | return FAIL; | |
5569 | } | |
5570 | inst.operands[0].imm = reg; | |
5571 | ||
5572 | if (skip_past_comma (&p) == SUCCESS) | |
5573 | { | |
5574 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5575 | return FAIL; | |
5576 | if (inst.reloc.exp.X_add_number != 1) | |
5577 | { | |
5578 | inst.error = _("invalid shift"); | |
5579 | return FAIL; | |
5580 | } | |
5581 | inst.operands[0].shifted = 1; | |
5582 | } | |
5583 | ||
5584 | if (skip_past_char (&p, ']') == FAIL) | |
5585 | { | |
5586 | inst.error = _("']' expected"); | |
5587 | return FAIL; | |
5588 | } | |
5589 | *str = p; | |
5590 | return SUCCESS; | |
5591 | } | |
5592 | ||
5287ad62 JB |
5593 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5594 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5595 | Up to four operands may be read; this function handles setting the |
5596 | ".present" field for each read operand itself. | |
5287ad62 JB |
5597 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5598 | else returns FAIL. */ | |
5599 | ||
5600 | static int | |
5601 | parse_neon_mov (char **str, int *which_operand) | |
5602 | { | |
5603 | int i = *which_operand, val; | |
5604 | enum arm_reg_type rtype; | |
5605 | char *ptr = *str; | |
dcbf9037 | 5606 | struct neon_type_el optype; |
5f4273c7 | 5607 | |
dcbf9037 | 5608 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5609 | { |
5610 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5611 | inst.operands[i].reg = val; | |
5612 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5613 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5614 | inst.operands[i++].present = 1; |
5615 | ||
5616 | if (skip_past_comma (&ptr) == FAIL) | |
5617 | goto wanted_comma; | |
5f4273c7 | 5618 | |
dcbf9037 | 5619 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 | 5620 | goto wanted_arm; |
5f4273c7 | 5621 | |
5287ad62 JB |
5622 | inst.operands[i].reg = val; |
5623 | inst.operands[i].isreg = 1; | |
5624 | inst.operands[i].present = 1; | |
5625 | } | |
037e8744 | 5626 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5627 | != FAIL) |
5287ad62 JB |
5628 | { |
5629 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5630 | if (skip_past_comma (&ptr) == FAIL) | |
5631 | goto wanted_comma; | |
5f4273c7 | 5632 | |
5287ad62 JB |
5633 | inst.operands[i].reg = val; |
5634 | inst.operands[i].isreg = 1; | |
5635 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5636 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5637 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5638 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5639 | inst.operands[i++].present = 1; |
5640 | ||
dcbf9037 | 5641 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5642 | { |
037e8744 JB |
5643 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5644 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5645 | inst.operands[i].reg = val; |
5646 | inst.operands[i].isreg = 1; | |
037e8744 | 5647 | inst.operands[i].present = 1; |
5287ad62 JB |
5648 | |
5649 | if (rtype == REG_TYPE_NQ) | |
5650 | { | |
dcbf9037 | 5651 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5652 | return FAIL; |
5653 | } | |
037e8744 JB |
5654 | else if (rtype != REG_TYPE_VFS) |
5655 | { | |
5656 | i++; | |
5657 | if (skip_past_comma (&ptr) == FAIL) | |
5658 | goto wanted_comma; | |
5659 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5660 | goto wanted_arm; | |
5661 | inst.operands[i].reg = val; | |
5662 | inst.operands[i].isreg = 1; | |
5663 | inst.operands[i].present = 1; | |
5664 | } | |
5287ad62 | 5665 | } |
037e8744 JB |
5666 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
5667 | &optype)) != FAIL) | |
5287ad62 JB |
5668 | { |
5669 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5670 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5671 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5672 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5673 | |
5674 | inst.operands[i].reg = val; | |
5675 | inst.operands[i].isreg = 1; | |
5676 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5677 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5678 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5679 | inst.operands[i].vectype = optype; |
5287ad62 | 5680 | inst.operands[i].present = 1; |
5f4273c7 | 5681 | |
037e8744 JB |
5682 | if (skip_past_comma (&ptr) == SUCCESS) |
5683 | { | |
5684 | /* Case 15. */ | |
5685 | i++; | |
5686 | ||
5687 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5688 | goto wanted_arm; | |
5689 | ||
5690 | inst.operands[i].reg = val; | |
5691 | inst.operands[i].isreg = 1; | |
5692 | inst.operands[i++].present = 1; | |
5f4273c7 | 5693 | |
037e8744 JB |
5694 | if (skip_past_comma (&ptr) == FAIL) |
5695 | goto wanted_comma; | |
5f4273c7 | 5696 | |
037e8744 JB |
5697 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5698 | goto wanted_arm; | |
5f4273c7 | 5699 | |
037e8744 JB |
5700 | inst.operands[i].reg = val; |
5701 | inst.operands[i].isreg = 1; | |
5702 | inst.operands[i++].present = 1; | |
5703 | } | |
5287ad62 | 5704 | } |
4641781c PB |
5705 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
5706 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> | |
5707 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
5708 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5709 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5710 | inst.operands[i].immisfloat = 1; | |
5711 | else if (parse_big_immediate (&ptr, i) == SUCCESS) | |
5712 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> | |
5713 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
5714 | ; | |
5287ad62 JB |
5715 | else |
5716 | { | |
dcbf9037 | 5717 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
5718 | return FAIL; |
5719 | } | |
5720 | } | |
dcbf9037 | 5721 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5722 | { |
5723 | /* Cases 6, 7. */ | |
5724 | inst.operands[i].reg = val; | |
5725 | inst.operands[i].isreg = 1; | |
5726 | inst.operands[i++].present = 1; | |
5f4273c7 | 5727 | |
5287ad62 JB |
5728 | if (skip_past_comma (&ptr) == FAIL) |
5729 | goto wanted_comma; | |
5f4273c7 | 5730 | |
dcbf9037 | 5731 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5732 | { |
5733 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
5734 | inst.operands[i].reg = val; | |
5735 | inst.operands[i].isscalar = 1; | |
5736 | inst.operands[i].present = 1; | |
dcbf9037 | 5737 | inst.operands[i].vectype = optype; |
5287ad62 | 5738 | } |
dcbf9037 | 5739 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5740 | { |
5741 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
5742 | inst.operands[i].reg = val; | |
5743 | inst.operands[i].isreg = 1; | |
5744 | inst.operands[i++].present = 1; | |
5f4273c7 | 5745 | |
5287ad62 JB |
5746 | if (skip_past_comma (&ptr) == FAIL) |
5747 | goto wanted_comma; | |
5f4273c7 | 5748 | |
037e8744 | 5749 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 5750 | == FAIL) |
5287ad62 | 5751 | { |
037e8744 | 5752 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
5753 | return FAIL; |
5754 | } | |
5755 | ||
5756 | inst.operands[i].reg = val; | |
5757 | inst.operands[i].isreg = 1; | |
037e8744 JB |
5758 | inst.operands[i].isvec = 1; |
5759 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 5760 | inst.operands[i].vectype = optype; |
5287ad62 | 5761 | inst.operands[i].present = 1; |
5f4273c7 | 5762 | |
037e8744 JB |
5763 | if (rtype == REG_TYPE_VFS) |
5764 | { | |
5765 | /* Case 14. */ | |
5766 | i++; | |
5767 | if (skip_past_comma (&ptr) == FAIL) | |
5768 | goto wanted_comma; | |
5769 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
5770 | &optype)) == FAIL) | |
5771 | { | |
5772 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
5773 | return FAIL; | |
5774 | } | |
5775 | inst.operands[i].reg = val; | |
5776 | inst.operands[i].isreg = 1; | |
5777 | inst.operands[i].isvec = 1; | |
5778 | inst.operands[i].issingle = 1; | |
5779 | inst.operands[i].vectype = optype; | |
5780 | inst.operands[i].present = 1; | |
5781 | } | |
5782 | } | |
5783 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
5784 | != FAIL) | |
5785 | { | |
5786 | /* Case 13. */ | |
5787 | inst.operands[i].reg = val; | |
5788 | inst.operands[i].isreg = 1; | |
5789 | inst.operands[i].isvec = 1; | |
5790 | inst.operands[i].issingle = 1; | |
5791 | inst.operands[i].vectype = optype; | |
5792 | inst.operands[i++].present = 1; | |
5287ad62 JB |
5793 | } |
5794 | } | |
5795 | else | |
5796 | { | |
dcbf9037 | 5797 | first_error (_("parse error")); |
5287ad62 JB |
5798 | return FAIL; |
5799 | } | |
5800 | ||
5801 | /* Successfully parsed the operands. Update args. */ | |
5802 | *which_operand = i; | |
5803 | *str = ptr; | |
5804 | return SUCCESS; | |
5805 | ||
5f4273c7 | 5806 | wanted_comma: |
dcbf9037 | 5807 | first_error (_("expected comma")); |
5287ad62 | 5808 | return FAIL; |
5f4273c7 NC |
5809 | |
5810 | wanted_arm: | |
dcbf9037 | 5811 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 5812 | return FAIL; |
5287ad62 JB |
5813 | } |
5814 | ||
5be8be5d DG |
5815 | /* Use this macro when the operand constraints are different |
5816 | for ARM and THUMB (e.g. ldrd). */ | |
5817 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
5818 | ((arm_operand) | ((thumb_operand) << 16)) | |
5819 | ||
c19d1205 ZW |
5820 | /* Matcher codes for parse_operands. */ |
5821 | enum operand_parse_code | |
5822 | { | |
5823 | OP_stop, /* end of line */ | |
5824 | ||
5825 | OP_RR, /* ARM register */ | |
5826 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 5827 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 5828 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
55881a11 MGD |
5829 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
5830 | optional trailing ! */ | |
c19d1205 ZW |
5831 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
5832 | OP_RCP, /* Coprocessor number */ | |
5833 | OP_RCN, /* Coprocessor register */ | |
5834 | OP_RF, /* FPA register */ | |
5835 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
5836 | OP_RVD, /* VFP double precision register (0..15) */ |
5837 | OP_RND, /* Neon double precision register (0..31) */ | |
5838 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 5839 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 5840 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 5841 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 5842 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
5843 | OP_RVC, /* VFP control register */ |
5844 | OP_RMF, /* Maverick F register */ | |
5845 | OP_RMD, /* Maverick D register */ | |
5846 | OP_RMFX, /* Maverick FX register */ | |
5847 | OP_RMDX, /* Maverick DX register */ | |
5848 | OP_RMAX, /* Maverick AX register */ | |
5849 | OP_RMDS, /* Maverick DSPSC register */ | |
5850 | OP_RIWR, /* iWMMXt wR register */ | |
5851 | OP_RIWC, /* iWMMXt wC register */ | |
5852 | OP_RIWG, /* iWMMXt wCG register */ | |
5853 | OP_RXA, /* XScale accumulator register */ | |
5854 | ||
5855 | OP_REGLST, /* ARM register list */ | |
5856 | OP_VRSLST, /* VFP single-precision register list */ | |
5857 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 5858 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
5859 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
5860 | OP_NSTRLST, /* Neon element/structure list */ | |
5861 | ||
5287ad62 | 5862 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 5863 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 5864 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 5865 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
5866 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
5867 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
5868 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 5869 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
5287ad62 | 5870 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
2d447fca | 5871 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
5872 | |
5873 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
5874 | OP_I7, /* immediate value 0 .. 7 */ |
5875 | OP_I15, /* 0 .. 15 */ | |
5876 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 5877 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
5878 | OP_I31, /* 0 .. 31 */ |
5879 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
5880 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
5881 | OP_I32z, /* 0 .. 32 */ |
5882 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 5883 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
5884 | OP_I64, /* 1 .. 64 */ |
5885 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 5886 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
5887 | |
5888 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
5889 | OP_I7b, /* 0 .. 7 */ | |
5890 | OP_I15b, /* 0 .. 15 */ | |
5891 | OP_I31b, /* 0 .. 31 */ | |
5892 | ||
5893 | OP_SH, /* shifter operand */ | |
4962c51a | 5894 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 5895 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
5896 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
5897 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
5898 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
5899 | OP_EXP, /* arbitrary expression */ |
5900 | OP_EXPi, /* same, with optional immediate prefix */ | |
5901 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 5902 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
5903 | |
5904 | OP_CPSF, /* CPS flags */ | |
5905 | OP_ENDI, /* Endianness specifier */ | |
5906 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
5907 | OP_COND, /* conditional code */ | |
92e90b6e | 5908 | OP_TB, /* Table branch. */ |
c19d1205 | 5909 | |
037e8744 JB |
5910 | OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */ |
5911 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ | |
5912 | ||
c19d1205 ZW |
5913 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
5914 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
5915 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
5916 | OP_RF_IF, /* FPA register or immediate */ | |
5917 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 5918 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
5919 | |
5920 | /* Optional operands. */ | |
5921 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
5922 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 5923 | OP_oI32b, /* 1 .. 32 */ |
c19d1205 ZW |
5924 | OP_oIffffb, /* 0 .. 65535 */ |
5925 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
5926 | ||
5927 | OP_oRR, /* ARM register */ | |
5928 | OP_oRRnpc, /* ARM register, not the PC */ | |
5be8be5d | 5929 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 5930 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
5931 | OP_oRND, /* Optional Neon double precision register */ |
5932 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5933 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 5934 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
5935 | OP_oSHll, /* LSL immediate */ |
5936 | OP_oSHar, /* ASR immediate */ | |
5937 | OP_oSHllar, /* LSL or ASR immediate */ | |
5938 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 5939 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 5940 | |
5be8be5d DG |
5941 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
5942 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
5943 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
5944 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
5945 | ||
c19d1205 ZW |
5946 | OP_FIRST_OPTIONAL = OP_oI7b |
5947 | }; | |
a737bd4d | 5948 | |
c19d1205 ZW |
5949 | /* Generic instruction operand parser. This does no encoding and no |
5950 | semantic validation; it merely squirrels values away in the inst | |
5951 | structure. Returns SUCCESS or FAIL depending on whether the | |
5952 | specified grammar matched. */ | |
5953 | static int | |
5be8be5d | 5954 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 5955 | { |
5be8be5d | 5956 | unsigned const int *upat = pattern; |
c19d1205 ZW |
5957 | char *backtrack_pos = 0; |
5958 | const char *backtrack_error = 0; | |
5959 | int i, val, backtrack_index = 0; | |
5287ad62 | 5960 | enum arm_reg_type rtype; |
4962c51a | 5961 | parse_operand_result result; |
5be8be5d | 5962 | unsigned int op_parse_code; |
c19d1205 | 5963 | |
e07e6e58 NC |
5964 | #define po_char_or_fail(chr) \ |
5965 | do \ | |
5966 | { \ | |
5967 | if (skip_past_char (&str, chr) == FAIL) \ | |
5968 | goto bad_args; \ | |
5969 | } \ | |
5970 | while (0) | |
c19d1205 | 5971 | |
e07e6e58 NC |
5972 | #define po_reg_or_fail(regtype) \ |
5973 | do \ | |
dcbf9037 | 5974 | { \ |
e07e6e58 NC |
5975 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
5976 | & inst.operands[i].vectype); \ | |
5977 | if (val == FAIL) \ | |
5978 | { \ | |
5979 | first_error (_(reg_expected_msgs[regtype])); \ | |
5980 | goto failure; \ | |
5981 | } \ | |
5982 | inst.operands[i].reg = val; \ | |
5983 | inst.operands[i].isreg = 1; \ | |
5984 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5985 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5986 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5987 | || rtype == REG_TYPE_VFD \ | |
5988 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 5989 | } \ |
e07e6e58 NC |
5990 | while (0) |
5991 | ||
5992 | #define po_reg_or_goto(regtype, label) \ | |
5993 | do \ | |
5994 | { \ | |
5995 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
5996 | & inst.operands[i].vectype); \ | |
5997 | if (val == FAIL) \ | |
5998 | goto label; \ | |
dcbf9037 | 5999 | \ |
e07e6e58 NC |
6000 | inst.operands[i].reg = val; \ |
6001 | inst.operands[i].isreg = 1; \ | |
6002 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6003 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6004 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
6005 | || rtype == REG_TYPE_VFD \ | |
6006 | || rtype == REG_TYPE_NQ); \ | |
6007 | } \ | |
6008 | while (0) | |
6009 | ||
6010 | #define po_imm_or_fail(min, max, popt) \ | |
6011 | do \ | |
6012 | { \ | |
6013 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
6014 | goto failure; \ | |
6015 | inst.operands[i].imm = val; \ | |
6016 | } \ | |
6017 | while (0) | |
6018 | ||
6019 | #define po_scalar_or_goto(elsz, label) \ | |
6020 | do \ | |
6021 | { \ | |
6022 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
6023 | if (val == FAIL) \ | |
6024 | goto label; \ | |
6025 | inst.operands[i].reg = val; \ | |
6026 | inst.operands[i].isscalar = 1; \ | |
6027 | } \ | |
6028 | while (0) | |
6029 | ||
6030 | #define po_misc_or_fail(expr) \ | |
6031 | do \ | |
6032 | { \ | |
6033 | if (expr) \ | |
6034 | goto failure; \ | |
6035 | } \ | |
6036 | while (0) | |
6037 | ||
6038 | #define po_misc_or_fail_no_backtrack(expr) \ | |
6039 | do \ | |
6040 | { \ | |
6041 | result = expr; \ | |
6042 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
6043 | backtrack_pos = 0; \ | |
6044 | if (result != PARSE_OPERAND_SUCCESS) \ | |
6045 | goto failure; \ | |
6046 | } \ | |
6047 | while (0) | |
4962c51a | 6048 | |
52e7f43d RE |
6049 | #define po_barrier_or_imm(str) \ |
6050 | do \ | |
6051 | { \ | |
6052 | val = parse_barrier (&str); \ | |
6053 | if (val == FAIL) \ | |
6054 | { \ | |
6055 | if (ISALPHA (*str)) \ | |
6056 | goto failure; \ | |
6057 | else \ | |
6058 | goto immediate; \ | |
6059 | } \ | |
6060 | else \ | |
6061 | { \ | |
6062 | if ((inst.instruction & 0xf0) == 0x60 \ | |
6063 | && val != 0xf) \ | |
6064 | { \ | |
6065 | /* ISB can only take SY as an option. */ \ | |
6066 | inst.error = _("invalid barrier type"); \ | |
6067 | goto failure; \ | |
6068 | } \ | |
6069 | } \ | |
6070 | } \ | |
6071 | while (0) | |
6072 | ||
c19d1205 ZW |
6073 | skip_whitespace (str); |
6074 | ||
6075 | for (i = 0; upat[i] != OP_stop; i++) | |
6076 | { | |
5be8be5d DG |
6077 | op_parse_code = upat[i]; |
6078 | if (op_parse_code >= 1<<16) | |
6079 | op_parse_code = thumb ? (op_parse_code >> 16) | |
6080 | : (op_parse_code & ((1<<16)-1)); | |
6081 | ||
6082 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
6083 | { |
6084 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 6085 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
6086 | backtrack_pos = str; |
6087 | backtrack_error = inst.error; | |
6088 | backtrack_index = i; | |
6089 | } | |
6090 | ||
b6702015 | 6091 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
6092 | po_char_or_fail (','); |
6093 | ||
5be8be5d | 6094 | switch (op_parse_code) |
c19d1205 ZW |
6095 | { |
6096 | /* Registers */ | |
6097 | case OP_oRRnpc: | |
5be8be5d | 6098 | case OP_oRRnpcsp: |
c19d1205 | 6099 | case OP_RRnpc: |
5be8be5d | 6100 | case OP_RRnpcsp: |
c19d1205 ZW |
6101 | case OP_oRR: |
6102 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
6103 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
6104 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
6105 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
6106 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
6107 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
6108 | case OP_oRND: |
6109 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
cd2cf30b PB |
6110 | case OP_RVC: |
6111 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
6112 | break; | |
6113 | /* Also accept generic coprocessor regs for unknown registers. */ | |
6114 | coproc_reg: | |
6115 | po_reg_or_fail (REG_TYPE_CN); | |
6116 | break; | |
c19d1205 ZW |
6117 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
6118 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
6119 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
6120 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
6121 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
6122 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
6123 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
6124 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
6125 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
6126 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
6127 | case OP_oRNQ: |
6128 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
6129 | case OP_oRNDQ: | |
6130 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
6131 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
6132 | case OP_oRNSDQ: | |
6133 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
6134 | |
6135 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6136 | scalars are accepted here, so deal with those in later code. */ | |
6137 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6138 | ||
5287ad62 JB |
6139 | case OP_RNDQ_I0: |
6140 | { | |
6141 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6142 | break; | |
6143 | try_imm0: | |
6144 | po_imm_or_fail (0, 0, TRUE); | |
6145 | } | |
6146 | break; | |
6147 | ||
037e8744 JB |
6148 | case OP_RVSD_I0: |
6149 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6150 | break; | |
6151 | ||
5287ad62 JB |
6152 | case OP_RR_RNSC: |
6153 | { | |
6154 | po_scalar_or_goto (8, try_rr); | |
6155 | break; | |
6156 | try_rr: | |
6157 | po_reg_or_fail (REG_TYPE_RN); | |
6158 | } | |
6159 | break; | |
6160 | ||
037e8744 JB |
6161 | case OP_RNSDQ_RNSC: |
6162 | { | |
6163 | po_scalar_or_goto (8, try_nsdq); | |
6164 | break; | |
6165 | try_nsdq: | |
6166 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6167 | } | |
6168 | break; | |
6169 | ||
5287ad62 JB |
6170 | case OP_RNDQ_RNSC: |
6171 | { | |
6172 | po_scalar_or_goto (8, try_ndq); | |
6173 | break; | |
6174 | try_ndq: | |
6175 | po_reg_or_fail (REG_TYPE_NDQ); | |
6176 | } | |
6177 | break; | |
6178 | ||
6179 | case OP_RND_RNSC: | |
6180 | { | |
6181 | po_scalar_or_goto (8, try_vfd); | |
6182 | break; | |
6183 | try_vfd: | |
6184 | po_reg_or_fail (REG_TYPE_VFD); | |
6185 | } | |
6186 | break; | |
6187 | ||
6188 | case OP_VMOV: | |
6189 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6190 | not careful then bad things might happen. */ | |
6191 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6192 | break; | |
6193 | ||
4316f0d2 | 6194 | case OP_RNDQ_Ibig: |
5287ad62 | 6195 | { |
4316f0d2 | 6196 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); |
5287ad62 | 6197 | break; |
4316f0d2 | 6198 | try_immbig: |
5287ad62 JB |
6199 | /* There's a possibility of getting a 64-bit immediate here, so |
6200 | we need special handling. */ | |
6201 | if (parse_big_immediate (&str, i) == FAIL) | |
6202 | { | |
6203 | inst.error = _("immediate value is out of range"); | |
6204 | goto failure; | |
6205 | } | |
6206 | } | |
6207 | break; | |
6208 | ||
6209 | case OP_RNDQ_I63b: | |
6210 | { | |
6211 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6212 | break; | |
6213 | try_shimm: | |
6214 | po_imm_or_fail (0, 63, TRUE); | |
6215 | } | |
6216 | break; | |
c19d1205 ZW |
6217 | |
6218 | case OP_RRnpcb: | |
6219 | po_char_or_fail ('['); | |
6220 | po_reg_or_fail (REG_TYPE_RN); | |
6221 | po_char_or_fail (']'); | |
6222 | break; | |
a737bd4d | 6223 | |
55881a11 | 6224 | case OP_RRnpctw: |
c19d1205 | 6225 | case OP_RRw: |
b6702015 | 6226 | case OP_oRRw: |
c19d1205 ZW |
6227 | po_reg_or_fail (REG_TYPE_RN); |
6228 | if (skip_past_char (&str, '!') == SUCCESS) | |
6229 | inst.operands[i].writeback = 1; | |
6230 | break; | |
6231 | ||
6232 | /* Immediates */ | |
6233 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6234 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6235 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 6236 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6237 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6238 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 6239 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6240 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
6241 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6242 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6243 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6244 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6245 | |
6246 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6247 | case OP_oI7b: | |
6248 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6249 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6250 | case OP_oI31b: | |
6251 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 6252 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
c19d1205 ZW |
6253 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6254 | ||
6255 | /* Immediate variants */ | |
6256 | case OP_oI255c: | |
6257 | po_char_or_fail ('{'); | |
6258 | po_imm_or_fail (0, 255, TRUE); | |
6259 | po_char_or_fail ('}'); | |
6260 | break; | |
6261 | ||
6262 | case OP_I31w: | |
6263 | /* The expression parser chokes on a trailing !, so we have | |
6264 | to find it first and zap it. */ | |
6265 | { | |
6266 | char *s = str; | |
6267 | while (*s && *s != ',') | |
6268 | s++; | |
6269 | if (s[-1] == '!') | |
6270 | { | |
6271 | s[-1] = '\0'; | |
6272 | inst.operands[i].writeback = 1; | |
6273 | } | |
6274 | po_imm_or_fail (0, 31, TRUE); | |
6275 | if (str == s - 1) | |
6276 | str = s; | |
6277 | } | |
6278 | break; | |
6279 | ||
6280 | /* Expressions */ | |
6281 | case OP_EXPi: EXPi: | |
6282 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6283 | GE_OPT_PREFIX)); | |
6284 | break; | |
6285 | ||
6286 | case OP_EXP: | |
6287 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6288 | GE_NO_PREFIX)); | |
6289 | break; | |
6290 | ||
6291 | case OP_EXPr: EXPr: | |
6292 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6293 | GE_NO_PREFIX)); | |
6294 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6295 | { |
c19d1205 ZW |
6296 | val = parse_reloc (&str); |
6297 | if (val == -1) | |
6298 | { | |
6299 | inst.error = _("unrecognized relocation suffix"); | |
6300 | goto failure; | |
6301 | } | |
6302 | else if (val != BFD_RELOC_UNUSED) | |
6303 | { | |
6304 | inst.operands[i].imm = val; | |
6305 | inst.operands[i].hasreloc = 1; | |
6306 | } | |
a737bd4d | 6307 | } |
c19d1205 | 6308 | break; |
a737bd4d | 6309 | |
b6895b4f PB |
6310 | /* Operand for MOVW or MOVT. */ |
6311 | case OP_HALF: | |
6312 | po_misc_or_fail (parse_half (&str)); | |
6313 | break; | |
6314 | ||
e07e6e58 | 6315 | /* Register or expression. */ |
c19d1205 ZW |
6316 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6317 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6318 | |
e07e6e58 | 6319 | /* Register or immediate. */ |
c19d1205 ZW |
6320 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6321 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6322 | |
c19d1205 ZW |
6323 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6324 | IF: | |
6325 | if (!is_immediate_prefix (*str)) | |
6326 | goto bad_args; | |
6327 | str++; | |
6328 | val = parse_fpa_immediate (&str); | |
6329 | if (val == FAIL) | |
6330 | goto failure; | |
6331 | /* FPA immediates are encoded as registers 8-15. | |
6332 | parse_fpa_immediate has already applied the offset. */ | |
6333 | inst.operands[i].reg = val; | |
6334 | inst.operands[i].isreg = 1; | |
6335 | break; | |
09d92015 | 6336 | |
2d447fca JM |
6337 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6338 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6339 | ||
e07e6e58 | 6340 | /* Two kinds of register. */ |
c19d1205 ZW |
6341 | case OP_RIWR_RIWC: |
6342 | { | |
6343 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6344 | if (!rege |
6345 | || (rege->type != REG_TYPE_MMXWR | |
6346 | && rege->type != REG_TYPE_MMXWC | |
6347 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6348 | { |
6349 | inst.error = _("iWMMXt data or control register expected"); | |
6350 | goto failure; | |
6351 | } | |
6352 | inst.operands[i].reg = rege->number; | |
6353 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6354 | } | |
6355 | break; | |
09d92015 | 6356 | |
41adaa5c JM |
6357 | case OP_RIWC_RIWG: |
6358 | { | |
6359 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6360 | if (!rege | |
6361 | || (rege->type != REG_TYPE_MMXWC | |
6362 | && rege->type != REG_TYPE_MMXWCG)) | |
6363 | { | |
6364 | inst.error = _("iWMMXt control register expected"); | |
6365 | goto failure; | |
6366 | } | |
6367 | inst.operands[i].reg = rege->number; | |
6368 | inst.operands[i].isreg = 1; | |
6369 | } | |
6370 | break; | |
6371 | ||
c19d1205 ZW |
6372 | /* Misc */ |
6373 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6374 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6375 | case OP_oROR: val = parse_ror (&str); break; | |
6376 | case OP_PSR: val = parse_psr (&str); break; | |
6377 | case OP_COND: val = parse_cond (&str); break; | |
52e7f43d RE |
6378 | case OP_oBARRIER_I15: |
6379 | po_barrier_or_imm (str); break; | |
6380 | immediate: | |
6381 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
6382 | goto failure; | |
6383 | break; | |
c19d1205 | 6384 | |
037e8744 | 6385 | case OP_RVC_PSR: |
90ec0d68 | 6386 | po_reg_or_goto (REG_TYPE_VFC, try_banked_reg); |
037e8744 JB |
6387 | inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */ |
6388 | break; | |
90ec0d68 MGD |
6389 | try_banked_reg: |
6390 | po_reg_or_goto (REG_TYPE_RNB, try_psr); | |
6391 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
6392 | { | |
6393 | inst.error = _("Banked registers are not available with this " | |
6394 | "architecture."); | |
6395 | goto failure; | |
6396 | } | |
6397 | break; | |
037e8744 JB |
6398 | try_psr: |
6399 | val = parse_psr (&str); | |
6400 | break; | |
6401 | ||
6402 | case OP_APSR_RR: | |
6403 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
6404 | break; | |
6405 | try_apsr: | |
6406 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
6407 | instruction). */ | |
6408 | if (strncasecmp (str, "APSR_", 5) == 0) | |
6409 | { | |
6410 | unsigned found = 0; | |
6411 | str += 5; | |
6412 | while (found < 15) | |
6413 | switch (*str++) | |
6414 | { | |
6415 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
6416 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
6417 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
6418 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
6419 | default: found = 16; | |
6420 | } | |
6421 | if (found != 15) | |
6422 | goto failure; | |
6423 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
6424 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
6425 | inst.operands[i].reg = REG_PC; | |
037e8744 JB |
6426 | } |
6427 | else | |
6428 | goto failure; | |
6429 | break; | |
6430 | ||
92e90b6e PB |
6431 | case OP_TB: |
6432 | po_misc_or_fail (parse_tb (&str)); | |
6433 | break; | |
6434 | ||
e07e6e58 | 6435 | /* Register lists. */ |
c19d1205 ZW |
6436 | case OP_REGLST: |
6437 | val = parse_reg_list (&str); | |
6438 | if (*str == '^') | |
6439 | { | |
6440 | inst.operands[1].writeback = 1; | |
6441 | str++; | |
6442 | } | |
6443 | break; | |
09d92015 | 6444 | |
c19d1205 | 6445 | case OP_VRSLST: |
5287ad62 | 6446 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 6447 | break; |
09d92015 | 6448 | |
c19d1205 | 6449 | case OP_VRDLST: |
5287ad62 | 6450 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 6451 | break; |
a737bd4d | 6452 | |
037e8744 JB |
6453 | case OP_VRSDLST: |
6454 | /* Allow Q registers too. */ | |
6455 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6456 | REGLIST_NEON_D); | |
6457 | if (val == FAIL) | |
6458 | { | |
6459 | inst.error = NULL; | |
6460 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6461 | REGLIST_VFP_S); | |
6462 | inst.operands[i].issingle = 1; | |
6463 | } | |
6464 | break; | |
6465 | ||
5287ad62 JB |
6466 | case OP_NRDLST: |
6467 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6468 | REGLIST_NEON_D); | |
6469 | break; | |
6470 | ||
6471 | case OP_NSTRLST: | |
dcbf9037 JB |
6472 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
6473 | &inst.operands[i].vectype); | |
5287ad62 JB |
6474 | break; |
6475 | ||
c19d1205 ZW |
6476 | /* Addressing modes */ |
6477 | case OP_ADDR: | |
6478 | po_misc_or_fail (parse_address (&str, i)); | |
6479 | break; | |
09d92015 | 6480 | |
4962c51a MS |
6481 | case OP_ADDRGLDR: |
6482 | po_misc_or_fail_no_backtrack ( | |
6483 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
6484 | break; | |
6485 | ||
6486 | case OP_ADDRGLDRS: | |
6487 | po_misc_or_fail_no_backtrack ( | |
6488 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
6489 | break; | |
6490 | ||
6491 | case OP_ADDRGLDC: | |
6492 | po_misc_or_fail_no_backtrack ( | |
6493 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
6494 | break; | |
6495 | ||
c19d1205 ZW |
6496 | case OP_SH: |
6497 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
6498 | break; | |
09d92015 | 6499 | |
4962c51a MS |
6500 | case OP_SHG: |
6501 | po_misc_or_fail_no_backtrack ( | |
6502 | parse_shifter_operand_group_reloc (&str, i)); | |
6503 | break; | |
6504 | ||
c19d1205 ZW |
6505 | case OP_oSHll: |
6506 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
6507 | break; | |
09d92015 | 6508 | |
c19d1205 ZW |
6509 | case OP_oSHar: |
6510 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
6511 | break; | |
09d92015 | 6512 | |
c19d1205 ZW |
6513 | case OP_oSHllar: |
6514 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
6515 | break; | |
09d92015 | 6516 | |
c19d1205 | 6517 | default: |
5be8be5d | 6518 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 6519 | } |
09d92015 | 6520 | |
c19d1205 ZW |
6521 | /* Various value-based sanity checks and shared operations. We |
6522 | do not signal immediate failures for the register constraints; | |
6523 | this allows a syntax error to take precedence. */ | |
5be8be5d | 6524 | switch (op_parse_code) |
c19d1205 ZW |
6525 | { |
6526 | case OP_oRRnpc: | |
6527 | case OP_RRnpc: | |
6528 | case OP_RRnpcb: | |
6529 | case OP_RRw: | |
b6702015 | 6530 | case OP_oRRw: |
c19d1205 ZW |
6531 | case OP_RRnpc_I0: |
6532 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
6533 | inst.error = BAD_PC; | |
6534 | break; | |
09d92015 | 6535 | |
5be8be5d DG |
6536 | case OP_oRRnpcsp: |
6537 | case OP_RRnpcsp: | |
6538 | if (inst.operands[i].isreg) | |
6539 | { | |
6540 | if (inst.operands[i].reg == REG_PC) | |
6541 | inst.error = BAD_PC; | |
6542 | else if (inst.operands[i].reg == REG_SP) | |
6543 | inst.error = BAD_SP; | |
6544 | } | |
6545 | break; | |
6546 | ||
55881a11 MGD |
6547 | case OP_RRnpctw: |
6548 | if (inst.operands[i].isreg | |
6549 | && inst.operands[i].reg == REG_PC | |
6550 | && (inst.operands[i].writeback || thumb)) | |
6551 | inst.error = BAD_PC; | |
6552 | break; | |
6553 | ||
c19d1205 ZW |
6554 | case OP_CPSF: |
6555 | case OP_ENDI: | |
6556 | case OP_oROR: | |
6557 | case OP_PSR: | |
037e8744 | 6558 | case OP_RVC_PSR: |
c19d1205 | 6559 | case OP_COND: |
52e7f43d | 6560 | case OP_oBARRIER_I15: |
c19d1205 ZW |
6561 | case OP_REGLST: |
6562 | case OP_VRSLST: | |
6563 | case OP_VRDLST: | |
037e8744 | 6564 | case OP_VRSDLST: |
5287ad62 JB |
6565 | case OP_NRDLST: |
6566 | case OP_NSTRLST: | |
c19d1205 ZW |
6567 | if (val == FAIL) |
6568 | goto failure; | |
6569 | inst.operands[i].imm = val; | |
6570 | break; | |
a737bd4d | 6571 | |
c19d1205 ZW |
6572 | default: |
6573 | break; | |
6574 | } | |
09d92015 | 6575 | |
c19d1205 ZW |
6576 | /* If we get here, this operand was successfully parsed. */ |
6577 | inst.operands[i].present = 1; | |
6578 | continue; | |
09d92015 | 6579 | |
c19d1205 | 6580 | bad_args: |
09d92015 | 6581 | inst.error = BAD_ARGS; |
c19d1205 ZW |
6582 | |
6583 | failure: | |
6584 | if (!backtrack_pos) | |
d252fdde PB |
6585 | { |
6586 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 6587 | default here just in case. */ |
d252fdde PB |
6588 | if (!inst.error) |
6589 | inst.error = _("syntax error"); | |
6590 | return FAIL; | |
6591 | } | |
c19d1205 ZW |
6592 | |
6593 | /* Do not backtrack over a trailing optional argument that | |
6594 | absorbed some text. We will only fail again, with the | |
6595 | 'garbage following instruction' error message, which is | |
6596 | probably less helpful than the current one. */ | |
6597 | if (backtrack_index == i && backtrack_pos != str | |
6598 | && upat[i+1] == OP_stop) | |
d252fdde PB |
6599 | { |
6600 | if (!inst.error) | |
6601 | inst.error = _("syntax error"); | |
6602 | return FAIL; | |
6603 | } | |
c19d1205 ZW |
6604 | |
6605 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
6606 | str = backtrack_pos; | |
6607 | inst.error = backtrack_error; | |
6608 | inst.operands[backtrack_index].present = 0; | |
6609 | i = backtrack_index; | |
6610 | backtrack_pos = 0; | |
09d92015 | 6611 | } |
09d92015 | 6612 | |
c19d1205 ZW |
6613 | /* Check that we have parsed all the arguments. */ |
6614 | if (*str != '\0' && !inst.error) | |
6615 | inst.error = _("garbage following instruction"); | |
09d92015 | 6616 | |
c19d1205 | 6617 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
6618 | } |
6619 | ||
c19d1205 ZW |
6620 | #undef po_char_or_fail |
6621 | #undef po_reg_or_fail | |
6622 | #undef po_reg_or_goto | |
6623 | #undef po_imm_or_fail | |
5287ad62 | 6624 | #undef po_scalar_or_fail |
52e7f43d | 6625 | #undef po_barrier_or_imm |
e07e6e58 | 6626 | |
c19d1205 | 6627 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
6628 | #define constraint(expr, err) \ |
6629 | do \ | |
c19d1205 | 6630 | { \ |
e07e6e58 NC |
6631 | if (expr) \ |
6632 | { \ | |
6633 | inst.error = err; \ | |
6634 | return; \ | |
6635 | } \ | |
c19d1205 | 6636 | } \ |
e07e6e58 | 6637 | while (0) |
c19d1205 | 6638 | |
fdfde340 JM |
6639 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
6640 | instructions are unpredictable if these registers are used. This | |
6641 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
6642 | #define reject_bad_reg(reg) \ | |
6643 | do \ | |
6644 | if (reg == REG_SP || reg == REG_PC) \ | |
6645 | { \ | |
6646 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
6647 | return; \ | |
6648 | } \ | |
6649 | while (0) | |
6650 | ||
94206790 MM |
6651 | /* If REG is R13 (the stack pointer), warn that its use is |
6652 | deprecated. */ | |
6653 | #define warn_deprecated_sp(reg) \ | |
6654 | do \ | |
6655 | if (warn_on_deprecated && reg == REG_SP) \ | |
6656 | as_warn (_("use of r13 is deprecated")); \ | |
6657 | while (0) | |
6658 | ||
c19d1205 ZW |
6659 | /* Functions for operand encoding. ARM, then Thumb. */ |
6660 | ||
6661 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
6662 | ||
6663 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
6664 | return the encoded form. Otherwise, return FAIL. */ | |
6665 | ||
6666 | static unsigned int | |
6667 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6668 | { |
c19d1205 ZW |
6669 | unsigned int a, i; |
6670 | ||
6671 | for (i = 0; i < 32; i += 2) | |
6672 | if ((a = rotate_left (val, i)) <= 0xff) | |
6673 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6674 | ||
6675 | return FAIL; | |
09d92015 MM |
6676 | } |
6677 | ||
c19d1205 ZW |
6678 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6679 | return the encoded form. Otherwise, return FAIL. */ | |
6680 | static unsigned int | |
6681 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6682 | { |
c19d1205 | 6683 | unsigned int a, i; |
09d92015 | 6684 | |
9c3c69f2 | 6685 | if (val <= 0xff) |
c19d1205 | 6686 | return val; |
a737bd4d | 6687 | |
9c3c69f2 | 6688 | for (i = 1; i <= 24; i++) |
09d92015 | 6689 | { |
9c3c69f2 PB |
6690 | a = val >> i; |
6691 | if ((val & ~(0xff << i)) == 0) | |
6692 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6693 | } |
a737bd4d | 6694 | |
c19d1205 ZW |
6695 | a = val & 0xff; |
6696 | if (val == ((a << 16) | a)) | |
6697 | return 0x100 | a; | |
6698 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6699 | return 0x300 | a; | |
09d92015 | 6700 | |
c19d1205 ZW |
6701 | a = val & 0xff00; |
6702 | if (val == ((a << 16) | a)) | |
6703 | return 0x200 | (a >> 8); | |
a737bd4d | 6704 | |
c19d1205 | 6705 | return FAIL; |
09d92015 | 6706 | } |
5287ad62 | 6707 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6708 | |
6709 | static void | |
5287ad62 JB |
6710 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6711 | { | |
6712 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6713 | && reg > 15) | |
6714 | { | |
b1cc4aeb | 6715 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
5287ad62 JB |
6716 | { |
6717 | if (thumb_mode) | |
6718 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 6719 | fpu_vfp_ext_d32); |
5287ad62 JB |
6720 | else |
6721 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 6722 | fpu_vfp_ext_d32); |
5287ad62 JB |
6723 | } |
6724 | else | |
6725 | { | |
dcbf9037 | 6726 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
6727 | return; |
6728 | } | |
6729 | } | |
6730 | ||
c19d1205 | 6731 | switch (pos) |
09d92015 | 6732 | { |
c19d1205 ZW |
6733 | case VFP_REG_Sd: |
6734 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
6735 | break; | |
6736 | ||
6737 | case VFP_REG_Sn: | |
6738 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
6739 | break; | |
6740 | ||
6741 | case VFP_REG_Sm: | |
6742 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
6743 | break; | |
6744 | ||
5287ad62 JB |
6745 | case VFP_REG_Dd: |
6746 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
6747 | break; | |
5f4273c7 | 6748 | |
5287ad62 JB |
6749 | case VFP_REG_Dn: |
6750 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
6751 | break; | |
5f4273c7 | 6752 | |
5287ad62 JB |
6753 | case VFP_REG_Dm: |
6754 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
6755 | break; | |
6756 | ||
c19d1205 ZW |
6757 | default: |
6758 | abort (); | |
09d92015 | 6759 | } |
09d92015 MM |
6760 | } |
6761 | ||
c19d1205 | 6762 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 6763 | if any, is handled by md_apply_fix. */ |
09d92015 | 6764 | static void |
c19d1205 | 6765 | encode_arm_shift (int i) |
09d92015 | 6766 | { |
c19d1205 ZW |
6767 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
6768 | inst.instruction |= SHIFT_ROR << 5; | |
6769 | else | |
09d92015 | 6770 | { |
c19d1205 ZW |
6771 | inst.instruction |= inst.operands[i].shift_kind << 5; |
6772 | if (inst.operands[i].immisreg) | |
6773 | { | |
6774 | inst.instruction |= SHIFT_BY_REG; | |
6775 | inst.instruction |= inst.operands[i].imm << 8; | |
6776 | } | |
6777 | else | |
6778 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 6779 | } |
c19d1205 | 6780 | } |
09d92015 | 6781 | |
c19d1205 ZW |
6782 | static void |
6783 | encode_arm_shifter_operand (int i) | |
6784 | { | |
6785 | if (inst.operands[i].isreg) | |
09d92015 | 6786 | { |
c19d1205 ZW |
6787 | inst.instruction |= inst.operands[i].reg; |
6788 | encode_arm_shift (i); | |
09d92015 | 6789 | } |
c19d1205 ZW |
6790 | else |
6791 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
6792 | } |
6793 | ||
c19d1205 | 6794 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 6795 | static void |
c19d1205 | 6796 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 6797 | { |
9c2799c2 | 6798 | gas_assert (inst.operands[i].isreg); |
c19d1205 | 6799 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6800 | |
c19d1205 | 6801 | if (inst.operands[i].preind) |
09d92015 | 6802 | { |
c19d1205 ZW |
6803 | if (is_t) |
6804 | { | |
6805 | inst.error = _("instruction does not accept preindexed addressing"); | |
6806 | return; | |
6807 | } | |
6808 | inst.instruction |= PRE_INDEX; | |
6809 | if (inst.operands[i].writeback) | |
6810 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6811 | |
c19d1205 ZW |
6812 | } |
6813 | else if (inst.operands[i].postind) | |
6814 | { | |
9c2799c2 | 6815 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
6816 | if (is_t) |
6817 | inst.instruction |= WRITE_BACK; | |
6818 | } | |
6819 | else /* unindexed - only for coprocessor */ | |
09d92015 | 6820 | { |
c19d1205 | 6821 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
6822 | return; |
6823 | } | |
6824 | ||
c19d1205 ZW |
6825 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
6826 | && (((inst.instruction & 0x000f0000) >> 16) | |
6827 | == ((inst.instruction & 0x0000f000) >> 12))) | |
6828 | as_warn ((inst.instruction & LOAD_BIT) | |
6829 | ? _("destination register same as write-back base") | |
6830 | : _("source register same as write-back base")); | |
09d92015 MM |
6831 | } |
6832 | ||
c19d1205 ZW |
6833 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6834 | ARM-format mode 2 load or store instruction. If is_t is true, | |
6835 | reject forms that cannot be used with a T instruction (i.e. not | |
6836 | post-indexed). */ | |
a737bd4d | 6837 | static void |
c19d1205 | 6838 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 6839 | { |
5be8be5d DG |
6840 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
6841 | ||
c19d1205 | 6842 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6843 | |
c19d1205 | 6844 | if (inst.operands[i].immisreg) |
09d92015 | 6845 | { |
5be8be5d DG |
6846 | constraint ((inst.operands[i].imm == REG_PC |
6847 | || (is_pc && inst.operands[i].writeback)), | |
6848 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
6849 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
6850 | inst.instruction |= inst.operands[i].imm; | |
6851 | if (!inst.operands[i].negative) | |
6852 | inst.instruction |= INDEX_UP; | |
6853 | if (inst.operands[i].shifted) | |
6854 | { | |
6855 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
6856 | inst.instruction |= SHIFT_ROR << 5; | |
6857 | else | |
6858 | { | |
6859 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
6860 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
6861 | } | |
6862 | } | |
09d92015 | 6863 | } |
c19d1205 | 6864 | else /* immediate offset in inst.reloc */ |
09d92015 | 6865 | { |
5be8be5d DG |
6866 | if (is_pc && !inst.reloc.pc_rel) |
6867 | { | |
6868 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
6869 | |
6870 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
6871 | cannot use PC in addressing. | |
6872 | PC cannot be used in writeback addressing, either. */ | |
6873 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 6874 | BAD_PC_ADDRESSING); |
23a10334 | 6875 | |
dc5ec521 | 6876 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
6877 | if (warn_on_deprecated |
6878 | && !is_load | |
6879 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
6880 | as_warn (_("use of PC in this instruction is deprecated")); | |
5be8be5d DG |
6881 | } |
6882 | ||
c19d1205 ZW |
6883 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6884 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 6885 | } |
09d92015 MM |
6886 | } |
6887 | ||
c19d1205 ZW |
6888 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6889 | ARM-format mode 3 load or store instruction. Reject forms that | |
6890 | cannot be used with such instructions. If is_t is true, reject | |
6891 | forms that cannot be used with a T instruction (i.e. not | |
6892 | post-indexed). */ | |
6893 | static void | |
6894 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 6895 | { |
c19d1205 | 6896 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 6897 | { |
c19d1205 ZW |
6898 | inst.error = _("instruction does not accept scaled register index"); |
6899 | return; | |
09d92015 | 6900 | } |
a737bd4d | 6901 | |
c19d1205 | 6902 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6903 | |
c19d1205 ZW |
6904 | if (inst.operands[i].immisreg) |
6905 | { | |
5be8be5d DG |
6906 | constraint ((inst.operands[i].imm == REG_PC |
6907 | || inst.operands[i].reg == REG_PC), | |
6908 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
6909 | inst.instruction |= inst.operands[i].imm; |
6910 | if (!inst.operands[i].negative) | |
6911 | inst.instruction |= INDEX_UP; | |
6912 | } | |
6913 | else /* immediate offset in inst.reloc */ | |
6914 | { | |
5be8be5d DG |
6915 | constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel |
6916 | && inst.operands[i].writeback), | |
6917 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
6918 | inst.instruction |= HWOFFSET_IMM; |
6919 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6920 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 6921 | } |
a737bd4d NC |
6922 | } |
6923 | ||
c19d1205 ZW |
6924 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6925 | ARM-format instruction. Reject all forms which cannot be encoded | |
6926 | into a coprocessor load/store instruction. If wb_ok is false, | |
6927 | reject use of writeback; if unind_ok is false, reject use of | |
6928 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
6929 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
6930 | (in which case it is preserved). */ | |
09d92015 | 6931 | |
c19d1205 ZW |
6932 | static int |
6933 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 6934 | { |
c19d1205 | 6935 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6936 | |
9c2799c2 | 6937 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 6938 | |
c19d1205 | 6939 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 6940 | { |
9c2799c2 | 6941 | gas_assert (!inst.operands[i].writeback); |
c19d1205 ZW |
6942 | if (!unind_ok) |
6943 | { | |
6944 | inst.error = _("instruction does not support unindexed addressing"); | |
6945 | return FAIL; | |
6946 | } | |
6947 | inst.instruction |= inst.operands[i].imm; | |
6948 | inst.instruction |= INDEX_UP; | |
6949 | return SUCCESS; | |
09d92015 | 6950 | } |
a737bd4d | 6951 | |
c19d1205 ZW |
6952 | if (inst.operands[i].preind) |
6953 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 6954 | |
c19d1205 | 6955 | if (inst.operands[i].writeback) |
09d92015 | 6956 | { |
c19d1205 ZW |
6957 | if (inst.operands[i].reg == REG_PC) |
6958 | { | |
6959 | inst.error = _("pc may not be used with write-back"); | |
6960 | return FAIL; | |
6961 | } | |
6962 | if (!wb_ok) | |
6963 | { | |
6964 | inst.error = _("instruction does not support writeback"); | |
6965 | return FAIL; | |
6966 | } | |
6967 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6968 | } |
a737bd4d | 6969 | |
c19d1205 | 6970 | if (reloc_override) |
21d799b5 | 6971 | inst.reloc.type = (bfd_reloc_code_real_type) reloc_override; |
4962c51a MS |
6972 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
6973 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
6974 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
6975 | { | |
6976 | if (thumb_mode) | |
6977 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
6978 | else | |
6979 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
6980 | } | |
6981 | ||
c19d1205 ZW |
6982 | return SUCCESS; |
6983 | } | |
a737bd4d | 6984 | |
c19d1205 ZW |
6985 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
6986 | Determine whether it can be performed with a move instruction; if | |
6987 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
6988 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
6989 | load and return FALSE. If this is not a valid thing to do in the | |
6990 | current context, set inst.error and return TRUE. | |
a737bd4d | 6991 | |
c19d1205 ZW |
6992 | inst.operands[i] describes the destination register. */ |
6993 | ||
c921be7d | 6994 | static bfd_boolean |
c19d1205 ZW |
6995 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) |
6996 | { | |
53365c0d PB |
6997 | unsigned long tbit; |
6998 | ||
6999 | if (thumb_p) | |
7000 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
7001 | else | |
7002 | tbit = LOAD_BIT; | |
7003 | ||
7004 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 7005 | { |
c19d1205 | 7006 | inst.error = _("invalid pseudo operation"); |
c921be7d | 7007 | return TRUE; |
09d92015 | 7008 | } |
c19d1205 | 7009 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
7010 | { |
7011 | inst.error = _("constant expression expected"); | |
c921be7d | 7012 | return TRUE; |
09d92015 | 7013 | } |
c19d1205 | 7014 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 7015 | { |
c19d1205 ZW |
7016 | if (thumb_p) |
7017 | { | |
53365c0d | 7018 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
7019 | { |
7020 | /* This can be done with a mov(1) instruction. */ | |
7021 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
7022 | inst.instruction |= inst.reloc.exp.X_add_number; | |
c921be7d | 7023 | return TRUE; |
c19d1205 ZW |
7024 | } |
7025 | } | |
7026 | else | |
7027 | { | |
7028 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
7029 | if (value != FAIL) | |
7030 | { | |
7031 | /* This can be done with a mov instruction. */ | |
7032 | inst.instruction &= LITERAL_MASK; | |
7033 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
7034 | inst.instruction |= value & 0xfff; | |
c921be7d | 7035 | return TRUE; |
c19d1205 | 7036 | } |
09d92015 | 7037 | |
c19d1205 ZW |
7038 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
7039 | if (value != FAIL) | |
7040 | { | |
7041 | /* This can be done with a mvn instruction. */ | |
7042 | inst.instruction &= LITERAL_MASK; | |
7043 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
7044 | inst.instruction |= value & 0xfff; | |
c921be7d | 7045 | return TRUE; |
c19d1205 ZW |
7046 | } |
7047 | } | |
09d92015 MM |
7048 | } |
7049 | ||
c19d1205 ZW |
7050 | if (add_to_lit_pool () == FAIL) |
7051 | { | |
7052 | inst.error = _("literal pool insertion failed"); | |
c921be7d | 7053 | return TRUE; |
c19d1205 ZW |
7054 | } |
7055 | inst.operands[1].reg = REG_PC; | |
7056 | inst.operands[1].isreg = 1; | |
7057 | inst.operands[1].preind = 1; | |
7058 | inst.reloc.pc_rel = 1; | |
7059 | inst.reloc.type = (thumb_p | |
7060 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
7061 | : (mode_3 | |
7062 | ? BFD_RELOC_ARM_HWLITERAL | |
7063 | : BFD_RELOC_ARM_LITERAL)); | |
c921be7d | 7064 | return FALSE; |
09d92015 MM |
7065 | } |
7066 | ||
5f4273c7 | 7067 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
7068 | First some generics; their names are taken from the conventional |
7069 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 7070 | |
a737bd4d | 7071 | static void |
c19d1205 | 7072 | do_noargs (void) |
09d92015 | 7073 | { |
c19d1205 | 7074 | } |
a737bd4d | 7075 | |
c19d1205 ZW |
7076 | static void |
7077 | do_rd (void) | |
7078 | { | |
7079 | inst.instruction |= inst.operands[0].reg << 12; | |
7080 | } | |
a737bd4d | 7081 | |
c19d1205 ZW |
7082 | static void |
7083 | do_rd_rm (void) | |
7084 | { | |
7085 | inst.instruction |= inst.operands[0].reg << 12; | |
7086 | inst.instruction |= inst.operands[1].reg; | |
7087 | } | |
09d92015 | 7088 | |
c19d1205 ZW |
7089 | static void |
7090 | do_rd_rn (void) | |
7091 | { | |
7092 | inst.instruction |= inst.operands[0].reg << 12; | |
7093 | inst.instruction |= inst.operands[1].reg << 16; | |
7094 | } | |
a737bd4d | 7095 | |
c19d1205 ZW |
7096 | static void |
7097 | do_rn_rd (void) | |
7098 | { | |
7099 | inst.instruction |= inst.operands[0].reg << 16; | |
7100 | inst.instruction |= inst.operands[1].reg << 12; | |
7101 | } | |
09d92015 | 7102 | |
c19d1205 ZW |
7103 | static void |
7104 | do_rd_rm_rn (void) | |
7105 | { | |
9a64e435 | 7106 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 7107 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 7108 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
7109 | { |
7110 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
7111 | _("Rn must not overlap other operands")); | |
7112 | ||
7113 | /* SWP{b} is deprecated for ARMv6* and ARMv7. */ | |
7114 | if (warn_on_deprecated | |
7115 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
7116 | as_warn (_("swp{b} use is deprecated for this architecture")); | |
7117 | ||
7118 | } | |
c19d1205 ZW |
7119 | inst.instruction |= inst.operands[0].reg << 12; |
7120 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 7121 | inst.instruction |= Rn << 16; |
c19d1205 | 7122 | } |
09d92015 | 7123 | |
c19d1205 ZW |
7124 | static void |
7125 | do_rd_rn_rm (void) | |
7126 | { | |
7127 | inst.instruction |= inst.operands[0].reg << 12; | |
7128 | inst.instruction |= inst.operands[1].reg << 16; | |
7129 | inst.instruction |= inst.operands[2].reg; | |
7130 | } | |
a737bd4d | 7131 | |
c19d1205 ZW |
7132 | static void |
7133 | do_rm_rd_rn (void) | |
7134 | { | |
5be8be5d DG |
7135 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
7136 | constraint (((inst.reloc.exp.X_op != O_constant | |
7137 | && inst.reloc.exp.X_op != O_illegal) | |
7138 | || inst.reloc.exp.X_add_number != 0), | |
7139 | BAD_ADDR_MODE); | |
c19d1205 ZW |
7140 | inst.instruction |= inst.operands[0].reg; |
7141 | inst.instruction |= inst.operands[1].reg << 12; | |
7142 | inst.instruction |= inst.operands[2].reg << 16; | |
7143 | } | |
09d92015 | 7144 | |
c19d1205 ZW |
7145 | static void |
7146 | do_imm0 (void) | |
7147 | { | |
7148 | inst.instruction |= inst.operands[0].imm; | |
7149 | } | |
09d92015 | 7150 | |
c19d1205 ZW |
7151 | static void |
7152 | do_rd_cpaddr (void) | |
7153 | { | |
7154 | inst.instruction |= inst.operands[0].reg << 12; | |
7155 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 7156 | } |
a737bd4d | 7157 | |
c19d1205 ZW |
7158 | /* ARM instructions, in alphabetical order by function name (except |
7159 | that wrapper functions appear immediately after the function they | |
7160 | wrap). */ | |
09d92015 | 7161 | |
c19d1205 ZW |
7162 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
7163 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
7164 | |
7165 | static void | |
c19d1205 | 7166 | do_adr (void) |
09d92015 | 7167 | { |
c19d1205 | 7168 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 7169 | |
c19d1205 ZW |
7170 | /* Frag hacking will turn this into a sub instruction if the offset turns |
7171 | out to be negative. */ | |
7172 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 7173 | inst.reloc.pc_rel = 1; |
2fc8bdac | 7174 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 7175 | } |
b99bd4ef | 7176 | |
c19d1205 ZW |
7177 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
7178 | into a relative address of the form: | |
7179 | add rd, pc, #low(label-.-8)" | |
7180 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 7181 | |
c19d1205 ZW |
7182 | static void |
7183 | do_adrl (void) | |
7184 | { | |
7185 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 7186 | |
c19d1205 ZW |
7187 | /* Frag hacking will turn this into a sub instruction if the offset turns |
7188 | out to be negative. */ | |
7189 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
7190 | inst.reloc.pc_rel = 1; |
7191 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 7192 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
7193 | } |
7194 | ||
b99bd4ef | 7195 | static void |
c19d1205 | 7196 | do_arit (void) |
b99bd4ef | 7197 | { |
c19d1205 ZW |
7198 | if (!inst.operands[1].present) |
7199 | inst.operands[1].reg = inst.operands[0].reg; | |
7200 | inst.instruction |= inst.operands[0].reg << 12; | |
7201 | inst.instruction |= inst.operands[1].reg << 16; | |
7202 | encode_arm_shifter_operand (2); | |
7203 | } | |
b99bd4ef | 7204 | |
62b3e311 PB |
7205 | static void |
7206 | do_barrier (void) | |
7207 | { | |
7208 | if (inst.operands[0].present) | |
7209 | { | |
7210 | constraint ((inst.instruction & 0xf0) != 0x40 | |
52e7f43d RE |
7211 | && inst.operands[0].imm > 0xf |
7212 | && inst.operands[0].imm < 0x0, | |
bd3ba5d1 | 7213 | _("bad barrier type")); |
62b3e311 PB |
7214 | inst.instruction |= inst.operands[0].imm; |
7215 | } | |
7216 | else | |
7217 | inst.instruction |= 0xf; | |
7218 | } | |
7219 | ||
c19d1205 ZW |
7220 | static void |
7221 | do_bfc (void) | |
7222 | { | |
7223 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
7224 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7225 | /* The instruction encoding stores the LSB and MSB, | |
7226 | not the LSB and width. */ | |
7227 | inst.instruction |= inst.operands[0].reg << 12; | |
7228 | inst.instruction |= inst.operands[1].imm << 7; | |
7229 | inst.instruction |= (msb - 1) << 16; | |
7230 | } | |
b99bd4ef | 7231 | |
c19d1205 ZW |
7232 | static void |
7233 | do_bfi (void) | |
7234 | { | |
7235 | unsigned int msb; | |
b99bd4ef | 7236 | |
c19d1205 ZW |
7237 | /* #0 in second position is alternative syntax for bfc, which is |
7238 | the same instruction but with REG_PC in the Rm field. */ | |
7239 | if (!inst.operands[1].isreg) | |
7240 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 7241 | |
c19d1205 ZW |
7242 | msb = inst.operands[2].imm + inst.operands[3].imm; |
7243 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7244 | /* The instruction encoding stores the LSB and MSB, | |
7245 | not the LSB and width. */ | |
7246 | inst.instruction |= inst.operands[0].reg << 12; | |
7247 | inst.instruction |= inst.operands[1].reg; | |
7248 | inst.instruction |= inst.operands[2].imm << 7; | |
7249 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
7250 | } |
7251 | ||
b99bd4ef | 7252 | static void |
c19d1205 | 7253 | do_bfx (void) |
b99bd4ef | 7254 | { |
c19d1205 ZW |
7255 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
7256 | _("bit-field extends past end of register")); | |
7257 | inst.instruction |= inst.operands[0].reg << 12; | |
7258 | inst.instruction |= inst.operands[1].reg; | |
7259 | inst.instruction |= inst.operands[2].imm << 7; | |
7260 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
7261 | } | |
09d92015 | 7262 | |
c19d1205 ZW |
7263 | /* ARM V5 breakpoint instruction (argument parse) |
7264 | BKPT <16 bit unsigned immediate> | |
7265 | Instruction is not conditional. | |
7266 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
7267 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 7268 | |
c19d1205 ZW |
7269 | static void |
7270 | do_bkpt (void) | |
7271 | { | |
7272 | /* Top 12 of 16 bits to bits 19:8. */ | |
7273 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 7274 | |
c19d1205 ZW |
7275 | /* Bottom 4 of 16 bits to bits 3:0. */ |
7276 | inst.instruction |= inst.operands[0].imm & 0xf; | |
7277 | } | |
09d92015 | 7278 | |
c19d1205 ZW |
7279 | static void |
7280 | encode_branch (int default_reloc) | |
7281 | { | |
7282 | if (inst.operands[0].hasreloc) | |
7283 | { | |
7284 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
7285 | _("the only suffix valid here is '(plt)'")); | |
267bf995 | 7286 | inst.reloc.type = BFD_RELOC_ARM_PLT32; |
c19d1205 | 7287 | } |
b99bd4ef | 7288 | else |
9ae92b05 | 7289 | inst.reloc.type = (bfd_reloc_code_real_type) default_reloc; |
2fc8bdac | 7290 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
7291 | } |
7292 | ||
b99bd4ef | 7293 | static void |
c19d1205 | 7294 | do_branch (void) |
b99bd4ef | 7295 | { |
39b41c9c PB |
7296 | #ifdef OBJ_ELF |
7297 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7298 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7299 | else | |
7300 | #endif | |
7301 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
7302 | } | |
7303 | ||
7304 | static void | |
7305 | do_bl (void) | |
7306 | { | |
7307 | #ifdef OBJ_ELF | |
7308 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7309 | { | |
7310 | if (inst.cond == COND_ALWAYS) | |
7311 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
7312 | else | |
7313 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7314 | } | |
7315 | else | |
7316 | #endif | |
7317 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 7318 | } |
b99bd4ef | 7319 | |
c19d1205 ZW |
7320 | /* ARM V5 branch-link-exchange instruction (argument parse) |
7321 | BLX <target_addr> ie BLX(1) | |
7322 | BLX{<condition>} <Rm> ie BLX(2) | |
7323 | Unfortunately, there are two different opcodes for this mnemonic. | |
7324 | So, the insns[].value is not used, and the code here zaps values | |
7325 | into inst.instruction. | |
7326 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 7327 | |
c19d1205 ZW |
7328 | static void |
7329 | do_blx (void) | |
7330 | { | |
7331 | if (inst.operands[0].isreg) | |
b99bd4ef | 7332 | { |
c19d1205 ZW |
7333 | /* Arg is a register; the opcode provided by insns[] is correct. |
7334 | It is not illegal to do "blx pc", just useless. */ | |
7335 | if (inst.operands[0].reg == REG_PC) | |
7336 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 7337 | |
c19d1205 ZW |
7338 | inst.instruction |= inst.operands[0].reg; |
7339 | } | |
7340 | else | |
b99bd4ef | 7341 | { |
c19d1205 | 7342 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
7343 | conditionally, and the opcode must be adjusted. |
7344 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
7345 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 7346 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 7347 | inst.instruction = 0xfa000000; |
267bf995 | 7348 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 7349 | } |
c19d1205 ZW |
7350 | } |
7351 | ||
7352 | static void | |
7353 | do_bx (void) | |
7354 | { | |
845b51d6 PB |
7355 | bfd_boolean want_reloc; |
7356 | ||
c19d1205 ZW |
7357 | if (inst.operands[0].reg == REG_PC) |
7358 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 7359 | |
c19d1205 | 7360 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
7361 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
7362 | it is for ARMv4t or earlier. */ | |
7363 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
7364 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
7365 | want_reloc = TRUE; | |
7366 | ||
5ad34203 | 7367 | #ifdef OBJ_ELF |
845b51d6 | 7368 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 7369 | #endif |
584206db | 7370 | want_reloc = FALSE; |
845b51d6 PB |
7371 | |
7372 | if (want_reloc) | |
7373 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
7374 | } |
7375 | ||
c19d1205 ZW |
7376 | |
7377 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
7378 | |
7379 | static void | |
c19d1205 | 7380 | do_bxj (void) |
a737bd4d | 7381 | { |
c19d1205 ZW |
7382 | if (inst.operands[0].reg == REG_PC) |
7383 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
7384 | ||
7385 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
7386 | } |
7387 | ||
c19d1205 ZW |
7388 | /* Co-processor data operation: |
7389 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
7390 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
7391 | static void | |
7392 | do_cdp (void) | |
7393 | { | |
7394 | inst.instruction |= inst.operands[0].reg << 8; | |
7395 | inst.instruction |= inst.operands[1].imm << 20; | |
7396 | inst.instruction |= inst.operands[2].reg << 12; | |
7397 | inst.instruction |= inst.operands[3].reg << 16; | |
7398 | inst.instruction |= inst.operands[4].reg; | |
7399 | inst.instruction |= inst.operands[5].imm << 5; | |
7400 | } | |
a737bd4d NC |
7401 | |
7402 | static void | |
c19d1205 | 7403 | do_cmp (void) |
a737bd4d | 7404 | { |
c19d1205 ZW |
7405 | inst.instruction |= inst.operands[0].reg << 16; |
7406 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
7407 | } |
7408 | ||
c19d1205 ZW |
7409 | /* Transfer between coprocessor and ARM registers. |
7410 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
7411 | MRC2 | |
7412 | MCR{cond} | |
7413 | MCR2 | |
7414 | ||
7415 | No special properties. */ | |
09d92015 MM |
7416 | |
7417 | static void | |
c19d1205 | 7418 | do_co_reg (void) |
09d92015 | 7419 | { |
fdfde340 JM |
7420 | unsigned Rd; |
7421 | ||
7422 | Rd = inst.operands[2].reg; | |
7423 | if (thumb_mode) | |
7424 | { | |
7425 | if (inst.instruction == 0xee000010 | |
7426 | || inst.instruction == 0xfe000010) | |
7427 | /* MCR, MCR2 */ | |
7428 | reject_bad_reg (Rd); | |
7429 | else | |
7430 | /* MRC, MRC2 */ | |
7431 | constraint (Rd == REG_SP, BAD_SP); | |
7432 | } | |
7433 | else | |
7434 | { | |
7435 | /* MCR */ | |
7436 | if (inst.instruction == 0xe000010) | |
7437 | constraint (Rd == REG_PC, BAD_PC); | |
7438 | } | |
7439 | ||
7440 | ||
c19d1205 ZW |
7441 | inst.instruction |= inst.operands[0].reg << 8; |
7442 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 7443 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
7444 | inst.instruction |= inst.operands[3].reg << 16; |
7445 | inst.instruction |= inst.operands[4].reg; | |
7446 | inst.instruction |= inst.operands[5].imm << 5; | |
7447 | } | |
09d92015 | 7448 | |
c19d1205 ZW |
7449 | /* Transfer between coprocessor register and pair of ARM registers. |
7450 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
7451 | MCRR2 | |
7452 | MRRC{cond} | |
7453 | MRRC2 | |
b99bd4ef | 7454 | |
c19d1205 | 7455 | Two XScale instructions are special cases of these: |
09d92015 | 7456 | |
c19d1205 ZW |
7457 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
7458 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 7459 | |
5f4273c7 | 7460 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 7461 | |
c19d1205 ZW |
7462 | static void |
7463 | do_co_reg2c (void) | |
7464 | { | |
fdfde340 JM |
7465 | unsigned Rd, Rn; |
7466 | ||
7467 | Rd = inst.operands[2].reg; | |
7468 | Rn = inst.operands[3].reg; | |
7469 | ||
7470 | if (thumb_mode) | |
7471 | { | |
7472 | reject_bad_reg (Rd); | |
7473 | reject_bad_reg (Rn); | |
7474 | } | |
7475 | else | |
7476 | { | |
7477 | constraint (Rd == REG_PC, BAD_PC); | |
7478 | constraint (Rn == REG_PC, BAD_PC); | |
7479 | } | |
7480 | ||
c19d1205 ZW |
7481 | inst.instruction |= inst.operands[0].reg << 8; |
7482 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
7483 | inst.instruction |= Rd << 12; |
7484 | inst.instruction |= Rn << 16; | |
c19d1205 | 7485 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
7486 | } |
7487 | ||
c19d1205 ZW |
7488 | static void |
7489 | do_cpsi (void) | |
7490 | { | |
7491 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
7492 | if (inst.operands[1].present) |
7493 | { | |
7494 | inst.instruction |= CPSI_MMOD; | |
7495 | inst.instruction |= inst.operands[1].imm; | |
7496 | } | |
c19d1205 | 7497 | } |
b99bd4ef | 7498 | |
62b3e311 PB |
7499 | static void |
7500 | do_dbg (void) | |
7501 | { | |
7502 | inst.instruction |= inst.operands[0].imm; | |
7503 | } | |
7504 | ||
eea54501 MGD |
7505 | static void |
7506 | do_div (void) | |
7507 | { | |
7508 | unsigned Rd, Rn, Rm; | |
7509 | ||
7510 | Rd = inst.operands[0].reg; | |
7511 | Rn = (inst.operands[1].present | |
7512 | ? inst.operands[1].reg : Rd); | |
7513 | Rm = inst.operands[2].reg; | |
7514 | ||
7515 | constraint ((Rd == REG_PC), BAD_PC); | |
7516 | constraint ((Rn == REG_PC), BAD_PC); | |
7517 | constraint ((Rm == REG_PC), BAD_PC); | |
7518 | ||
7519 | inst.instruction |= Rd << 16; | |
7520 | inst.instruction |= Rn << 0; | |
7521 | inst.instruction |= Rm << 8; | |
7522 | } | |
7523 | ||
b99bd4ef | 7524 | static void |
c19d1205 | 7525 | do_it (void) |
b99bd4ef | 7526 | { |
c19d1205 | 7527 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
7528 | process it to do the validation as if in |
7529 | thumb mode, just in case the code gets | |
7530 | assembled for thumb using the unified syntax. */ | |
7531 | ||
c19d1205 | 7532 | inst.size = 0; |
e07e6e58 NC |
7533 | if (unified_syntax) |
7534 | { | |
7535 | set_it_insn_type (IT_INSN); | |
7536 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
7537 | now_it.cc = inst.operands[0].imm; | |
7538 | } | |
09d92015 | 7539 | } |
b99bd4ef | 7540 | |
09d92015 | 7541 | static void |
c19d1205 | 7542 | do_ldmstm (void) |
ea6ef066 | 7543 | { |
c19d1205 ZW |
7544 | int base_reg = inst.operands[0].reg; |
7545 | int range = inst.operands[1].imm; | |
ea6ef066 | 7546 | |
c19d1205 ZW |
7547 | inst.instruction |= base_reg << 16; |
7548 | inst.instruction |= range; | |
ea6ef066 | 7549 | |
c19d1205 ZW |
7550 | if (inst.operands[1].writeback) |
7551 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 7552 | |
c19d1205 | 7553 | if (inst.operands[0].writeback) |
ea6ef066 | 7554 | { |
c19d1205 ZW |
7555 | inst.instruction |= WRITE_BACK; |
7556 | /* Check for unpredictable uses of writeback. */ | |
7557 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 7558 | { |
c19d1205 ZW |
7559 | /* Not allowed in LDM type 2. */ |
7560 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
7561 | && ((range & (1 << REG_PC)) == 0)) | |
7562 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7563 | /* Only allowed if base reg not in list for other types. */ | |
7564 | else if (range & (1 << base_reg)) | |
7565 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
7566 | } | |
7567 | else /* STM. */ | |
7568 | { | |
7569 | /* Not allowed for type 2. */ | |
7570 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
7571 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7572 | /* Only allowed if base reg not in list, or first in list. */ | |
7573 | else if ((range & (1 << base_reg)) | |
7574 | && (range & ((1 << base_reg) - 1))) | |
7575 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 7576 | } |
ea6ef066 | 7577 | } |
a737bd4d NC |
7578 | } |
7579 | ||
c19d1205 ZW |
7580 | /* ARMv5TE load-consecutive (argument parse) |
7581 | Mode is like LDRH. | |
7582 | ||
7583 | LDRccD R, mode | |
7584 | STRccD R, mode. */ | |
7585 | ||
a737bd4d | 7586 | static void |
c19d1205 | 7587 | do_ldrd (void) |
a737bd4d | 7588 | { |
c19d1205 ZW |
7589 | constraint (inst.operands[0].reg % 2 != 0, |
7590 | _("first destination register must be even")); | |
7591 | constraint (inst.operands[1].present | |
7592 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7593 | _("can only load two consecutive registers")); | |
7594 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
7595 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 7596 | |
c19d1205 ZW |
7597 | if (!inst.operands[1].present) |
7598 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 7599 | |
c19d1205 | 7600 | if (inst.instruction & LOAD_BIT) |
a737bd4d | 7601 | { |
c19d1205 ZW |
7602 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
7603 | register and the first register written; we have to diagnose | |
7604 | overlap between the base and the second register written here. */ | |
ea6ef066 | 7605 | |
c19d1205 ZW |
7606 | if (inst.operands[2].reg == inst.operands[1].reg |
7607 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
7608 | as_warn (_("base register written back, and overlaps " | |
7609 | "second destination register")); | |
b05fe5cf | 7610 | |
c19d1205 ZW |
7611 | /* For an index-register load, the index register must not overlap the |
7612 | destination (even if not write-back). */ | |
7613 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
7614 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
7615 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 7616 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 7617 | } |
c19d1205 ZW |
7618 | |
7619 | inst.instruction |= inst.operands[0].reg << 12; | |
7620 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
7621 | } |
7622 | ||
7623 | static void | |
c19d1205 | 7624 | do_ldrex (void) |
b05fe5cf | 7625 | { |
c19d1205 ZW |
7626 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
7627 | || inst.operands[1].postind || inst.operands[1].writeback | |
7628 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
7629 | || inst.operands[1].negative |
7630 | /* This can arise if the programmer has written | |
7631 | strex rN, rM, foo | |
7632 | or if they have mistakenly used a register name as the last | |
7633 | operand, eg: | |
7634 | strex rN, rM, rX | |
7635 | It is very difficult to distinguish between these two cases | |
7636 | because "rX" might actually be a label. ie the register | |
7637 | name has been occluded by a symbol of the same name. So we | |
7638 | just generate a general 'bad addressing mode' type error | |
7639 | message and leave it up to the programmer to discover the | |
7640 | true cause and fix their mistake. */ | |
7641 | || (inst.operands[1].reg == REG_PC), | |
7642 | BAD_ADDR_MODE); | |
b05fe5cf | 7643 | |
c19d1205 ZW |
7644 | constraint (inst.reloc.exp.X_op != O_constant |
7645 | || inst.reloc.exp.X_add_number != 0, | |
7646 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 7647 | |
5be8be5d DG |
7648 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
7649 | ||
c19d1205 ZW |
7650 | inst.instruction |= inst.operands[0].reg << 12; |
7651 | inst.instruction |= inst.operands[1].reg << 16; | |
7652 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
7653 | } |
7654 | ||
7655 | static void | |
c19d1205 | 7656 | do_ldrexd (void) |
b05fe5cf | 7657 | { |
c19d1205 ZW |
7658 | constraint (inst.operands[0].reg % 2 != 0, |
7659 | _("even register required")); | |
7660 | constraint (inst.operands[1].present | |
7661 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7662 | _("can only load two consecutive registers")); | |
7663 | /* If op 1 were present and equal to PC, this function wouldn't | |
7664 | have been called in the first place. */ | |
7665 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 7666 | |
c19d1205 ZW |
7667 | inst.instruction |= inst.operands[0].reg << 12; |
7668 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
7669 | } |
7670 | ||
7671 | static void | |
c19d1205 | 7672 | do_ldst (void) |
b05fe5cf | 7673 | { |
c19d1205 ZW |
7674 | inst.instruction |= inst.operands[0].reg << 12; |
7675 | if (!inst.operands[1].isreg) | |
7676 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 7677 | return; |
c19d1205 | 7678 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7679 | } |
7680 | ||
7681 | static void | |
c19d1205 | 7682 | do_ldstt (void) |
b05fe5cf | 7683 | { |
c19d1205 ZW |
7684 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7685 | reject [Rn,...]. */ | |
7686 | if (inst.operands[1].preind) | |
b05fe5cf | 7687 | { |
bd3ba5d1 NC |
7688 | constraint (inst.reloc.exp.X_op != O_constant |
7689 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7690 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7691 | |
c19d1205 ZW |
7692 | inst.operands[1].preind = 0; |
7693 | inst.operands[1].postind = 1; | |
7694 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7695 | } |
c19d1205 ZW |
7696 | inst.instruction |= inst.operands[0].reg << 12; |
7697 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
7698 | } | |
b05fe5cf | 7699 | |
c19d1205 | 7700 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 7701 | |
c19d1205 ZW |
7702 | static void |
7703 | do_ldstv4 (void) | |
7704 | { | |
ff4a8d2b | 7705 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
7706 | inst.instruction |= inst.operands[0].reg << 12; |
7707 | if (!inst.operands[1].isreg) | |
7708 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 7709 | return; |
c19d1205 | 7710 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7711 | } |
7712 | ||
7713 | static void | |
c19d1205 | 7714 | do_ldsttv4 (void) |
b05fe5cf | 7715 | { |
c19d1205 ZW |
7716 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7717 | reject [Rn,...]. */ | |
7718 | if (inst.operands[1].preind) | |
b05fe5cf | 7719 | { |
bd3ba5d1 NC |
7720 | constraint (inst.reloc.exp.X_op != O_constant |
7721 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7722 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7723 | |
c19d1205 ZW |
7724 | inst.operands[1].preind = 0; |
7725 | inst.operands[1].postind = 1; | |
7726 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7727 | } |
c19d1205 ZW |
7728 | inst.instruction |= inst.operands[0].reg << 12; |
7729 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
7730 | } | |
b05fe5cf | 7731 | |
c19d1205 ZW |
7732 | /* Co-processor register load/store. |
7733 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
7734 | static void | |
7735 | do_lstc (void) | |
7736 | { | |
7737 | inst.instruction |= inst.operands[0].reg << 8; | |
7738 | inst.instruction |= inst.operands[1].reg << 12; | |
7739 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
7740 | } |
7741 | ||
b05fe5cf | 7742 | static void |
c19d1205 | 7743 | do_mlas (void) |
b05fe5cf | 7744 | { |
8fb9d7b9 | 7745 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 7746 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 7747 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 7748 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 7749 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 7750 | |
c19d1205 ZW |
7751 | inst.instruction |= inst.operands[0].reg << 16; |
7752 | inst.instruction |= inst.operands[1].reg; | |
7753 | inst.instruction |= inst.operands[2].reg << 8; | |
7754 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 7755 | } |
b05fe5cf | 7756 | |
c19d1205 ZW |
7757 | static void |
7758 | do_mov (void) | |
7759 | { | |
7760 | inst.instruction |= inst.operands[0].reg << 12; | |
7761 | encode_arm_shifter_operand (1); | |
7762 | } | |
b05fe5cf | 7763 | |
c19d1205 ZW |
7764 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
7765 | static void | |
7766 | do_mov16 (void) | |
7767 | { | |
b6895b4f PB |
7768 | bfd_vma imm; |
7769 | bfd_boolean top; | |
7770 | ||
7771 | top = (inst.instruction & 0x00400000) != 0; | |
7772 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
7773 | _(":lower16: not allowed this instruction")); | |
7774 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
7775 | _(":upper16: not allowed instruction")); | |
c19d1205 | 7776 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
7777 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
7778 | { | |
7779 | imm = inst.reloc.exp.X_add_number; | |
7780 | /* The value is in two pieces: 0:11, 16:19. */ | |
7781 | inst.instruction |= (imm & 0x00000fff); | |
7782 | inst.instruction |= (imm & 0x0000f000) << 4; | |
7783 | } | |
b05fe5cf | 7784 | } |
b99bd4ef | 7785 | |
037e8744 JB |
7786 | static void do_vfp_nsyn_opcode (const char *); |
7787 | ||
7788 | static int | |
7789 | do_vfp_nsyn_mrs (void) | |
7790 | { | |
7791 | if (inst.operands[0].isvec) | |
7792 | { | |
7793 | if (inst.operands[1].reg != 1) | |
7794 | first_error (_("operand 1 must be FPSCR")); | |
7795 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
7796 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
7797 | do_vfp_nsyn_opcode ("fmstat"); | |
7798 | } | |
7799 | else if (inst.operands[1].isvec) | |
7800 | do_vfp_nsyn_opcode ("fmrx"); | |
7801 | else | |
7802 | return FAIL; | |
5f4273c7 | 7803 | |
037e8744 JB |
7804 | return SUCCESS; |
7805 | } | |
7806 | ||
7807 | static int | |
7808 | do_vfp_nsyn_msr (void) | |
7809 | { | |
7810 | if (inst.operands[0].isvec) | |
7811 | do_vfp_nsyn_opcode ("fmxr"); | |
7812 | else | |
7813 | return FAIL; | |
7814 | ||
7815 | return SUCCESS; | |
7816 | } | |
7817 | ||
f7c21dc7 NC |
7818 | static void |
7819 | do_vmrs (void) | |
7820 | { | |
7821 | unsigned Rt = inst.operands[0].reg; | |
7822 | ||
7823 | if (thumb_mode && inst.operands[0].reg == REG_SP) | |
7824 | { | |
7825 | inst.error = BAD_SP; | |
7826 | return; | |
7827 | } | |
7828 | ||
7829 | /* APSR_ sets isvec. All other refs to PC are illegal. */ | |
7830 | if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC) | |
7831 | { | |
7832 | inst.error = BAD_PC; | |
7833 | return; | |
7834 | } | |
7835 | ||
7836 | if (inst.operands[1].reg != 1) | |
7837 | first_error (_("operand 1 must be FPSCR")); | |
7838 | ||
7839 | inst.instruction |= (Rt << 12); | |
7840 | } | |
7841 | ||
7842 | static void | |
7843 | do_vmsr (void) | |
7844 | { | |
7845 | unsigned Rt = inst.operands[1].reg; | |
7846 | ||
7847 | if (thumb_mode) | |
7848 | reject_bad_reg (Rt); | |
7849 | else if (Rt == REG_PC) | |
7850 | { | |
7851 | inst.error = BAD_PC; | |
7852 | return; | |
7853 | } | |
7854 | ||
7855 | if (inst.operands[0].reg != 1) | |
7856 | first_error (_("operand 0 must be FPSCR")); | |
7857 | ||
7858 | inst.instruction |= (Rt << 12); | |
7859 | } | |
7860 | ||
b99bd4ef | 7861 | static void |
c19d1205 | 7862 | do_mrs (void) |
b99bd4ef | 7863 | { |
90ec0d68 MGD |
7864 | unsigned br; |
7865 | ||
037e8744 JB |
7866 | if (do_vfp_nsyn_mrs () == SUCCESS) |
7867 | return; | |
7868 | ||
ff4a8d2b | 7869 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 7870 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
7871 | |
7872 | if (inst.operands[1].isreg) | |
7873 | { | |
7874 | br = inst.operands[1].reg; | |
7875 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000)) | |
7876 | as_bad (_("bad register for mrs")); | |
7877 | } | |
7878 | else | |
7879 | { | |
7880 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
7881 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7882 | != (PSR_c|PSR_f), | |
7883 | _("'CPSR' or 'SPSR' expected")); | |
7884 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); | |
7885 | } | |
7886 | ||
7887 | inst.instruction |= br; | |
c19d1205 | 7888 | } |
b99bd4ef | 7889 | |
c19d1205 ZW |
7890 | /* Two possible forms: |
7891 | "{C|S}PSR_<field>, Rm", | |
7892 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 7893 | |
c19d1205 ZW |
7894 | static void |
7895 | do_msr (void) | |
7896 | { | |
037e8744 JB |
7897 | if (do_vfp_nsyn_msr () == SUCCESS) |
7898 | return; | |
7899 | ||
c19d1205 ZW |
7900 | inst.instruction |= inst.operands[0].imm; |
7901 | if (inst.operands[1].isreg) | |
7902 | inst.instruction |= inst.operands[1].reg; | |
7903 | else | |
b99bd4ef | 7904 | { |
c19d1205 ZW |
7905 | inst.instruction |= INST_IMMEDIATE; |
7906 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
7907 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 7908 | } |
b99bd4ef NC |
7909 | } |
7910 | ||
c19d1205 ZW |
7911 | static void |
7912 | do_mul (void) | |
a737bd4d | 7913 | { |
ff4a8d2b NC |
7914 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
7915 | ||
c19d1205 ZW |
7916 | if (!inst.operands[2].present) |
7917 | inst.operands[2].reg = inst.operands[0].reg; | |
7918 | inst.instruction |= inst.operands[0].reg << 16; | |
7919 | inst.instruction |= inst.operands[1].reg; | |
7920 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 7921 | |
8fb9d7b9 MS |
7922 | if (inst.operands[0].reg == inst.operands[1].reg |
7923 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
7924 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
7925 | } |
7926 | ||
c19d1205 ZW |
7927 | /* Long Multiply Parser |
7928 | UMULL RdLo, RdHi, Rm, Rs | |
7929 | SMULL RdLo, RdHi, Rm, Rs | |
7930 | UMLAL RdLo, RdHi, Rm, Rs | |
7931 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
7932 | |
7933 | static void | |
c19d1205 | 7934 | do_mull (void) |
b99bd4ef | 7935 | { |
c19d1205 ZW |
7936 | inst.instruction |= inst.operands[0].reg << 12; |
7937 | inst.instruction |= inst.operands[1].reg << 16; | |
7938 | inst.instruction |= inst.operands[2].reg; | |
7939 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 7940 | |
682b27ad PB |
7941 | /* rdhi and rdlo must be different. */ |
7942 | if (inst.operands[0].reg == inst.operands[1].reg) | |
7943 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7944 | ||
7945 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
7946 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 7947 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 7948 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
7949 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
7950 | } | |
b99bd4ef | 7951 | |
c19d1205 ZW |
7952 | static void |
7953 | do_nop (void) | |
7954 | { | |
e7495e45 NS |
7955 | if (inst.operands[0].present |
7956 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
7957 | { |
7958 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
7959 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
7960 | inst.instruction |= 0x0320f000; |
7961 | if (inst.operands[0].present) | |
7962 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 7963 | } |
b99bd4ef NC |
7964 | } |
7965 | ||
c19d1205 ZW |
7966 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
7967 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
7968 | Condition defaults to COND_ALWAYS. | |
7969 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
7970 | |
7971 | static void | |
c19d1205 | 7972 | do_pkhbt (void) |
b99bd4ef | 7973 | { |
c19d1205 ZW |
7974 | inst.instruction |= inst.operands[0].reg << 12; |
7975 | inst.instruction |= inst.operands[1].reg << 16; | |
7976 | inst.instruction |= inst.operands[2].reg; | |
7977 | if (inst.operands[3].present) | |
7978 | encode_arm_shift (3); | |
7979 | } | |
b99bd4ef | 7980 | |
c19d1205 | 7981 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 7982 | |
c19d1205 ZW |
7983 | static void |
7984 | do_pkhtb (void) | |
7985 | { | |
7986 | if (!inst.operands[3].present) | |
b99bd4ef | 7987 | { |
c19d1205 ZW |
7988 | /* If the shift specifier is omitted, turn the instruction |
7989 | into pkhbt rd, rm, rn. */ | |
7990 | inst.instruction &= 0xfff00010; | |
7991 | inst.instruction |= inst.operands[0].reg << 12; | |
7992 | inst.instruction |= inst.operands[1].reg; | |
7993 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7994 | } |
7995 | else | |
7996 | { | |
c19d1205 ZW |
7997 | inst.instruction |= inst.operands[0].reg << 12; |
7998 | inst.instruction |= inst.operands[1].reg << 16; | |
7999 | inst.instruction |= inst.operands[2].reg; | |
8000 | encode_arm_shift (3); | |
b99bd4ef NC |
8001 | } |
8002 | } | |
8003 | ||
c19d1205 | 8004 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 8005 | MP Extensions: Preload for write |
c19d1205 | 8006 | |
60e5ef9f | 8007 | PLD(W) <addr_mode> |
c19d1205 ZW |
8008 | |
8009 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
8010 | |
8011 | static void | |
c19d1205 | 8012 | do_pld (void) |
b99bd4ef | 8013 | { |
c19d1205 ZW |
8014 | constraint (!inst.operands[0].isreg, |
8015 | _("'[' expected after PLD mnemonic")); | |
8016 | constraint (inst.operands[0].postind, | |
8017 | _("post-indexed expression used in preload instruction")); | |
8018 | constraint (inst.operands[0].writeback, | |
8019 | _("writeback used in preload instruction")); | |
8020 | constraint (!inst.operands[0].preind, | |
8021 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
8022 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
8023 | } | |
b99bd4ef | 8024 | |
62b3e311 PB |
8025 | /* ARMv7: PLI <addr_mode> */ |
8026 | static void | |
8027 | do_pli (void) | |
8028 | { | |
8029 | constraint (!inst.operands[0].isreg, | |
8030 | _("'[' expected after PLI mnemonic")); | |
8031 | constraint (inst.operands[0].postind, | |
8032 | _("post-indexed expression used in preload instruction")); | |
8033 | constraint (inst.operands[0].writeback, | |
8034 | _("writeback used in preload instruction")); | |
8035 | constraint (!inst.operands[0].preind, | |
8036 | _("unindexed addressing used in preload instruction")); | |
8037 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
8038 | inst.instruction &= ~PRE_INDEX; | |
8039 | } | |
8040 | ||
c19d1205 ZW |
8041 | static void |
8042 | do_push_pop (void) | |
8043 | { | |
8044 | inst.operands[1] = inst.operands[0]; | |
8045 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
8046 | inst.operands[0].isreg = 1; | |
8047 | inst.operands[0].writeback = 1; | |
8048 | inst.operands[0].reg = REG_SP; | |
8049 | do_ldmstm (); | |
8050 | } | |
b99bd4ef | 8051 | |
c19d1205 ZW |
8052 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
8053 | word at the specified address and the following word | |
8054 | respectively. | |
8055 | Unconditionally executed. | |
8056 | Error if Rn is R15. */ | |
b99bd4ef | 8057 | |
c19d1205 ZW |
8058 | static void |
8059 | do_rfe (void) | |
8060 | { | |
8061 | inst.instruction |= inst.operands[0].reg << 16; | |
8062 | if (inst.operands[0].writeback) | |
8063 | inst.instruction |= WRITE_BACK; | |
8064 | } | |
b99bd4ef | 8065 | |
c19d1205 | 8066 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 8067 | |
c19d1205 ZW |
8068 | static void |
8069 | do_ssat (void) | |
8070 | { | |
8071 | inst.instruction |= inst.operands[0].reg << 12; | |
8072 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
8073 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 8074 | |
c19d1205 ZW |
8075 | if (inst.operands[3].present) |
8076 | encode_arm_shift (3); | |
b99bd4ef NC |
8077 | } |
8078 | ||
c19d1205 | 8079 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
8080 | |
8081 | static void | |
c19d1205 | 8082 | do_usat (void) |
b99bd4ef | 8083 | { |
c19d1205 ZW |
8084 | inst.instruction |= inst.operands[0].reg << 12; |
8085 | inst.instruction |= inst.operands[1].imm << 16; | |
8086 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 8087 | |
c19d1205 ZW |
8088 | if (inst.operands[3].present) |
8089 | encode_arm_shift (3); | |
b99bd4ef NC |
8090 | } |
8091 | ||
c19d1205 | 8092 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
8093 | |
8094 | static void | |
c19d1205 | 8095 | do_ssat16 (void) |
09d92015 | 8096 | { |
c19d1205 ZW |
8097 | inst.instruction |= inst.operands[0].reg << 12; |
8098 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
8099 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
8100 | } |
8101 | ||
c19d1205 ZW |
8102 | static void |
8103 | do_usat16 (void) | |
a737bd4d | 8104 | { |
c19d1205 ZW |
8105 | inst.instruction |= inst.operands[0].reg << 12; |
8106 | inst.instruction |= inst.operands[1].imm << 16; | |
8107 | inst.instruction |= inst.operands[2].reg; | |
8108 | } | |
a737bd4d | 8109 | |
c19d1205 ZW |
8110 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
8111 | preserving the other bits. | |
a737bd4d | 8112 | |
c19d1205 ZW |
8113 | setend <endian_specifier>, where <endian_specifier> is either |
8114 | BE or LE. */ | |
a737bd4d | 8115 | |
c19d1205 ZW |
8116 | static void |
8117 | do_setend (void) | |
8118 | { | |
8119 | if (inst.operands[0].imm) | |
8120 | inst.instruction |= 0x200; | |
a737bd4d NC |
8121 | } |
8122 | ||
8123 | static void | |
c19d1205 | 8124 | do_shift (void) |
a737bd4d | 8125 | { |
c19d1205 ZW |
8126 | unsigned int Rm = (inst.operands[1].present |
8127 | ? inst.operands[1].reg | |
8128 | : inst.operands[0].reg); | |
a737bd4d | 8129 | |
c19d1205 ZW |
8130 | inst.instruction |= inst.operands[0].reg << 12; |
8131 | inst.instruction |= Rm; | |
8132 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 8133 | { |
c19d1205 ZW |
8134 | inst.instruction |= inst.operands[2].reg << 8; |
8135 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
8136 | } |
8137 | else | |
c19d1205 | 8138 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
8139 | } |
8140 | ||
09d92015 | 8141 | static void |
3eb17e6b | 8142 | do_smc (void) |
09d92015 | 8143 | { |
3eb17e6b | 8144 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 8145 | inst.reloc.pc_rel = 0; |
09d92015 MM |
8146 | } |
8147 | ||
90ec0d68 MGD |
8148 | static void |
8149 | do_hvc (void) | |
8150 | { | |
8151 | inst.reloc.type = BFD_RELOC_ARM_HVC; | |
8152 | inst.reloc.pc_rel = 0; | |
8153 | } | |
8154 | ||
09d92015 | 8155 | static void |
c19d1205 | 8156 | do_swi (void) |
09d92015 | 8157 | { |
c19d1205 ZW |
8158 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
8159 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
8160 | } |
8161 | ||
c19d1205 ZW |
8162 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
8163 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
8164 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
8165 | Error if any register is R15. */ | |
e16bb312 | 8166 | |
c19d1205 ZW |
8167 | static void |
8168 | do_smla (void) | |
e16bb312 | 8169 | { |
c19d1205 ZW |
8170 | inst.instruction |= inst.operands[0].reg << 16; |
8171 | inst.instruction |= inst.operands[1].reg; | |
8172 | inst.instruction |= inst.operands[2].reg << 8; | |
8173 | inst.instruction |= inst.operands[3].reg << 12; | |
8174 | } | |
a737bd4d | 8175 | |
c19d1205 ZW |
8176 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
8177 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
8178 | Error if any register is R15. | |
8179 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 8180 | |
c19d1205 ZW |
8181 | static void |
8182 | do_smlal (void) | |
8183 | { | |
8184 | inst.instruction |= inst.operands[0].reg << 12; | |
8185 | inst.instruction |= inst.operands[1].reg << 16; | |
8186 | inst.instruction |= inst.operands[2].reg; | |
8187 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 8188 | |
c19d1205 ZW |
8189 | if (inst.operands[0].reg == inst.operands[1].reg) |
8190 | as_tsktsk (_("rdhi and rdlo must be different")); | |
8191 | } | |
a737bd4d | 8192 | |
c19d1205 ZW |
8193 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
8194 | SMULxy{cond} Rd,Rm,Rs | |
8195 | Error if any register is R15. */ | |
a737bd4d | 8196 | |
c19d1205 ZW |
8197 | static void |
8198 | do_smul (void) | |
8199 | { | |
8200 | inst.instruction |= inst.operands[0].reg << 16; | |
8201 | inst.instruction |= inst.operands[1].reg; | |
8202 | inst.instruction |= inst.operands[2].reg << 8; | |
8203 | } | |
a737bd4d | 8204 | |
b6702015 PB |
8205 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
8206 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 8207 | |
c19d1205 ZW |
8208 | static void |
8209 | do_srs (void) | |
8210 | { | |
b6702015 PB |
8211 | int reg; |
8212 | ||
8213 | if (inst.operands[0].present) | |
8214 | { | |
8215 | reg = inst.operands[0].reg; | |
fdfde340 | 8216 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
8217 | } |
8218 | else | |
fdfde340 | 8219 | reg = REG_SP; |
b6702015 PB |
8220 | |
8221 | inst.instruction |= reg << 16; | |
8222 | inst.instruction |= inst.operands[1].imm; | |
8223 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
8224 | inst.instruction |= WRITE_BACK; |
8225 | } | |
a737bd4d | 8226 | |
c19d1205 | 8227 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 8228 | |
c19d1205 ZW |
8229 | static void |
8230 | do_strex (void) | |
8231 | { | |
8232 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
8233 | || inst.operands[2].postind || inst.operands[2].writeback | |
8234 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
8235 | || inst.operands[2].negative |
8236 | /* See comment in do_ldrex(). */ | |
8237 | || (inst.operands[2].reg == REG_PC), | |
8238 | BAD_ADDR_MODE); | |
a737bd4d | 8239 | |
c19d1205 ZW |
8240 | constraint (inst.operands[0].reg == inst.operands[1].reg |
8241 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 8242 | |
c19d1205 ZW |
8243 | constraint (inst.reloc.exp.X_op != O_constant |
8244 | || inst.reloc.exp.X_add_number != 0, | |
8245 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 8246 | |
c19d1205 ZW |
8247 | inst.instruction |= inst.operands[0].reg << 12; |
8248 | inst.instruction |= inst.operands[1].reg; | |
8249 | inst.instruction |= inst.operands[2].reg << 16; | |
8250 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
8251 | } |
8252 | ||
8253 | static void | |
c19d1205 | 8254 | do_strexd (void) |
e16bb312 | 8255 | { |
c19d1205 ZW |
8256 | constraint (inst.operands[1].reg % 2 != 0, |
8257 | _("even register required")); | |
8258 | constraint (inst.operands[2].present | |
8259 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
8260 | _("can only store two consecutive registers")); | |
8261 | /* If op 2 were present and equal to PC, this function wouldn't | |
8262 | have been called in the first place. */ | |
8263 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 8264 | |
c19d1205 ZW |
8265 | constraint (inst.operands[0].reg == inst.operands[1].reg |
8266 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
8267 | || inst.operands[0].reg == inst.operands[3].reg, | |
8268 | BAD_OVERLAP); | |
e16bb312 | 8269 | |
c19d1205 ZW |
8270 | inst.instruction |= inst.operands[0].reg << 12; |
8271 | inst.instruction |= inst.operands[1].reg; | |
8272 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
8273 | } |
8274 | ||
c19d1205 ZW |
8275 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
8276 | extends it to 32-bits, and adds the result to a value in another | |
8277 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
8278 | before extracting the 16-bit value. | |
8279 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
8280 | Condition defaults to COND_ALWAYS. | |
8281 | Error if any register uses R15. */ | |
8282 | ||
e16bb312 | 8283 | static void |
c19d1205 | 8284 | do_sxtah (void) |
e16bb312 | 8285 | { |
c19d1205 ZW |
8286 | inst.instruction |= inst.operands[0].reg << 12; |
8287 | inst.instruction |= inst.operands[1].reg << 16; | |
8288 | inst.instruction |= inst.operands[2].reg; | |
8289 | inst.instruction |= inst.operands[3].imm << 10; | |
8290 | } | |
e16bb312 | 8291 | |
c19d1205 | 8292 | /* ARM V6 SXTH. |
e16bb312 | 8293 | |
c19d1205 ZW |
8294 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
8295 | Condition defaults to COND_ALWAYS. | |
8296 | Error if any register uses R15. */ | |
e16bb312 NC |
8297 | |
8298 | static void | |
c19d1205 | 8299 | do_sxth (void) |
e16bb312 | 8300 | { |
c19d1205 ZW |
8301 | inst.instruction |= inst.operands[0].reg << 12; |
8302 | inst.instruction |= inst.operands[1].reg; | |
8303 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 8304 | } |
c19d1205 ZW |
8305 | \f |
8306 | /* VFP instructions. In a logical order: SP variant first, monad | |
8307 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
8308 | |
8309 | static void | |
c19d1205 | 8310 | do_vfp_sp_monadic (void) |
e16bb312 | 8311 | { |
5287ad62 JB |
8312 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8313 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8314 | } |
8315 | ||
8316 | static void | |
c19d1205 | 8317 | do_vfp_sp_dyadic (void) |
e16bb312 | 8318 | { |
5287ad62 JB |
8319 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8320 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
8321 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
8322 | } |
8323 | ||
8324 | static void | |
c19d1205 | 8325 | do_vfp_sp_compare_z (void) |
e16bb312 | 8326 | { |
5287ad62 | 8327 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
8328 | } |
8329 | ||
8330 | static void | |
c19d1205 | 8331 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 8332 | { |
5287ad62 JB |
8333 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
8334 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8335 | } |
8336 | ||
8337 | static void | |
c19d1205 | 8338 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 8339 | { |
5287ad62 JB |
8340 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8341 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
8342 | } |
8343 | ||
8344 | static void | |
c19d1205 | 8345 | do_vfp_reg_from_sp (void) |
e16bb312 | 8346 | { |
c19d1205 | 8347 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 8348 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
8349 | } |
8350 | ||
8351 | static void | |
c19d1205 | 8352 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 8353 | { |
c19d1205 ZW |
8354 | constraint (inst.operands[2].imm != 2, |
8355 | _("only two consecutive VFP SP registers allowed here")); | |
8356 | inst.instruction |= inst.operands[0].reg << 12; | |
8357 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 8358 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
8359 | } |
8360 | ||
8361 | static void | |
c19d1205 | 8362 | do_vfp_sp_from_reg (void) |
e16bb312 | 8363 | { |
5287ad62 | 8364 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 8365 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
8366 | } |
8367 | ||
8368 | static void | |
c19d1205 | 8369 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 8370 | { |
c19d1205 ZW |
8371 | constraint (inst.operands[0].imm != 2, |
8372 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 8373 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
8374 | inst.instruction |= inst.operands[1].reg << 12; |
8375 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
8376 | } |
8377 | ||
8378 | static void | |
c19d1205 | 8379 | do_vfp_sp_ldst (void) |
e16bb312 | 8380 | { |
5287ad62 | 8381 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 8382 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8383 | } |
8384 | ||
8385 | static void | |
c19d1205 | 8386 | do_vfp_dp_ldst (void) |
e16bb312 | 8387 | { |
5287ad62 | 8388 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 8389 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8390 | } |
8391 | ||
c19d1205 | 8392 | |
e16bb312 | 8393 | static void |
c19d1205 | 8394 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8395 | { |
c19d1205 ZW |
8396 | if (inst.operands[0].writeback) |
8397 | inst.instruction |= WRITE_BACK; | |
8398 | else | |
8399 | constraint (ldstm_type != VFP_LDSTMIA, | |
8400 | _("this addressing mode requires base-register writeback")); | |
8401 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 8402 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 8403 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
8404 | } |
8405 | ||
8406 | static void | |
c19d1205 | 8407 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8408 | { |
c19d1205 | 8409 | int count; |
e16bb312 | 8410 | |
c19d1205 ZW |
8411 | if (inst.operands[0].writeback) |
8412 | inst.instruction |= WRITE_BACK; | |
8413 | else | |
8414 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
8415 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 8416 | |
c19d1205 | 8417 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 8418 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 8419 | |
c19d1205 ZW |
8420 | count = inst.operands[1].imm << 1; |
8421 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
8422 | count += 1; | |
e16bb312 | 8423 | |
c19d1205 | 8424 | inst.instruction |= count; |
e16bb312 NC |
8425 | } |
8426 | ||
8427 | static void | |
c19d1205 | 8428 | do_vfp_sp_ldstmia (void) |
e16bb312 | 8429 | { |
c19d1205 | 8430 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8431 | } |
8432 | ||
8433 | static void | |
c19d1205 | 8434 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 8435 | { |
c19d1205 | 8436 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8437 | } |
8438 | ||
8439 | static void | |
c19d1205 | 8440 | do_vfp_dp_ldstmia (void) |
e16bb312 | 8441 | { |
c19d1205 | 8442 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8443 | } |
8444 | ||
8445 | static void | |
c19d1205 | 8446 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 8447 | { |
c19d1205 | 8448 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8449 | } |
8450 | ||
8451 | static void | |
c19d1205 | 8452 | do_vfp_xp_ldstmia (void) |
e16bb312 | 8453 | { |
c19d1205 ZW |
8454 | vfp_dp_ldstm (VFP_LDSTMIAX); |
8455 | } | |
e16bb312 | 8456 | |
c19d1205 ZW |
8457 | static void |
8458 | do_vfp_xp_ldstmdb (void) | |
8459 | { | |
8460 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 8461 | } |
5287ad62 JB |
8462 | |
8463 | static void | |
8464 | do_vfp_dp_rd_rm (void) | |
8465 | { | |
8466 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8467 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
8468 | } | |
8469 | ||
8470 | static void | |
8471 | do_vfp_dp_rn_rd (void) | |
8472 | { | |
8473 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
8474 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8475 | } | |
8476 | ||
8477 | static void | |
8478 | do_vfp_dp_rd_rn (void) | |
8479 | { | |
8480 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8481 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8482 | } | |
8483 | ||
8484 | static void | |
8485 | do_vfp_dp_rd_rn_rm (void) | |
8486 | { | |
8487 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8488 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8489 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
8490 | } | |
8491 | ||
8492 | static void | |
8493 | do_vfp_dp_rd (void) | |
8494 | { | |
8495 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8496 | } | |
8497 | ||
8498 | static void | |
8499 | do_vfp_dp_rm_rd_rn (void) | |
8500 | { | |
8501 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
8502 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8503 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
8504 | } | |
8505 | ||
8506 | /* VFPv3 instructions. */ | |
8507 | static void | |
8508 | do_vfp_sp_const (void) | |
8509 | { | |
8510 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
8511 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8512 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8513 | } |
8514 | ||
8515 | static void | |
8516 | do_vfp_dp_const (void) | |
8517 | { | |
8518 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
8519 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8520 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8521 | } |
8522 | ||
8523 | static void | |
8524 | vfp_conv (int srcsize) | |
8525 | { | |
8526 | unsigned immbits = srcsize - inst.operands[1].imm; | |
8527 | inst.instruction |= (immbits & 1) << 5; | |
8528 | inst.instruction |= (immbits >> 1); | |
8529 | } | |
8530 | ||
8531 | static void | |
8532 | do_vfp_sp_conv_16 (void) | |
8533 | { | |
8534 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8535 | vfp_conv (16); | |
8536 | } | |
8537 | ||
8538 | static void | |
8539 | do_vfp_dp_conv_16 (void) | |
8540 | { | |
8541 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8542 | vfp_conv (16); | |
8543 | } | |
8544 | ||
8545 | static void | |
8546 | do_vfp_sp_conv_32 (void) | |
8547 | { | |
8548 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8549 | vfp_conv (32); | |
8550 | } | |
8551 | ||
8552 | static void | |
8553 | do_vfp_dp_conv_32 (void) | |
8554 | { | |
8555 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8556 | vfp_conv (32); | |
8557 | } | |
c19d1205 ZW |
8558 | \f |
8559 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 8560 | |
c19d1205 ZW |
8561 | static void |
8562 | do_fpa_cmp (void) | |
8563 | { | |
8564 | inst.instruction |= inst.operands[0].reg << 16; | |
8565 | inst.instruction |= inst.operands[1].reg; | |
8566 | } | |
b99bd4ef NC |
8567 | |
8568 | static void | |
c19d1205 | 8569 | do_fpa_ldmstm (void) |
b99bd4ef | 8570 | { |
c19d1205 ZW |
8571 | inst.instruction |= inst.operands[0].reg << 12; |
8572 | switch (inst.operands[1].imm) | |
8573 | { | |
8574 | case 1: inst.instruction |= CP_T_X; break; | |
8575 | case 2: inst.instruction |= CP_T_Y; break; | |
8576 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
8577 | case 4: break; | |
8578 | default: abort (); | |
8579 | } | |
b99bd4ef | 8580 | |
c19d1205 ZW |
8581 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
8582 | { | |
8583 | /* The instruction specified "ea" or "fd", so we can only accept | |
8584 | [Rn]{!}. The instruction does not really support stacking or | |
8585 | unstacking, so we have to emulate these by setting appropriate | |
8586 | bits and offsets. */ | |
8587 | constraint (inst.reloc.exp.X_op != O_constant | |
8588 | || inst.reloc.exp.X_add_number != 0, | |
8589 | _("this instruction does not support indexing")); | |
b99bd4ef | 8590 | |
c19d1205 ZW |
8591 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
8592 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 8593 | |
c19d1205 ZW |
8594 | if (!(inst.instruction & INDEX_UP)) |
8595 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 8596 | |
c19d1205 ZW |
8597 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
8598 | { | |
8599 | inst.operands[2].preind = 0; | |
8600 | inst.operands[2].postind = 1; | |
8601 | } | |
8602 | } | |
b99bd4ef | 8603 | |
c19d1205 | 8604 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 8605 | } |
c19d1205 ZW |
8606 | \f |
8607 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 8608 | |
c19d1205 ZW |
8609 | static void |
8610 | do_iwmmxt_tandorc (void) | |
8611 | { | |
8612 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
8613 | } | |
b99bd4ef | 8614 | |
c19d1205 ZW |
8615 | static void |
8616 | do_iwmmxt_textrc (void) | |
8617 | { | |
8618 | inst.instruction |= inst.operands[0].reg << 12; | |
8619 | inst.instruction |= inst.operands[1].imm; | |
8620 | } | |
b99bd4ef NC |
8621 | |
8622 | static void | |
c19d1205 | 8623 | do_iwmmxt_textrm (void) |
b99bd4ef | 8624 | { |
c19d1205 ZW |
8625 | inst.instruction |= inst.operands[0].reg << 12; |
8626 | inst.instruction |= inst.operands[1].reg << 16; | |
8627 | inst.instruction |= inst.operands[2].imm; | |
8628 | } | |
b99bd4ef | 8629 | |
c19d1205 ZW |
8630 | static void |
8631 | do_iwmmxt_tinsr (void) | |
8632 | { | |
8633 | inst.instruction |= inst.operands[0].reg << 16; | |
8634 | inst.instruction |= inst.operands[1].reg << 12; | |
8635 | inst.instruction |= inst.operands[2].imm; | |
8636 | } | |
b99bd4ef | 8637 | |
c19d1205 ZW |
8638 | static void |
8639 | do_iwmmxt_tmia (void) | |
8640 | { | |
8641 | inst.instruction |= inst.operands[0].reg << 5; | |
8642 | inst.instruction |= inst.operands[1].reg; | |
8643 | inst.instruction |= inst.operands[2].reg << 12; | |
8644 | } | |
b99bd4ef | 8645 | |
c19d1205 ZW |
8646 | static void |
8647 | do_iwmmxt_waligni (void) | |
8648 | { | |
8649 | inst.instruction |= inst.operands[0].reg << 12; | |
8650 | inst.instruction |= inst.operands[1].reg << 16; | |
8651 | inst.instruction |= inst.operands[2].reg; | |
8652 | inst.instruction |= inst.operands[3].imm << 20; | |
8653 | } | |
b99bd4ef | 8654 | |
2d447fca JM |
8655 | static void |
8656 | do_iwmmxt_wmerge (void) | |
8657 | { | |
8658 | inst.instruction |= inst.operands[0].reg << 12; | |
8659 | inst.instruction |= inst.operands[1].reg << 16; | |
8660 | inst.instruction |= inst.operands[2].reg; | |
8661 | inst.instruction |= inst.operands[3].imm << 21; | |
8662 | } | |
8663 | ||
c19d1205 ZW |
8664 | static void |
8665 | do_iwmmxt_wmov (void) | |
8666 | { | |
8667 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
8668 | inst.instruction |= inst.operands[0].reg << 12; | |
8669 | inst.instruction |= inst.operands[1].reg << 16; | |
8670 | inst.instruction |= inst.operands[1].reg; | |
8671 | } | |
b99bd4ef | 8672 | |
c19d1205 ZW |
8673 | static void |
8674 | do_iwmmxt_wldstbh (void) | |
8675 | { | |
8f06b2d8 | 8676 | int reloc; |
c19d1205 | 8677 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
8678 | if (thumb_mode) |
8679 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
8680 | else | |
8681 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
8682 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
8683 | } |
8684 | ||
c19d1205 ZW |
8685 | static void |
8686 | do_iwmmxt_wldstw (void) | |
8687 | { | |
8688 | /* RIWR_RIWC clears .isreg for a control register. */ | |
8689 | if (!inst.operands[0].isreg) | |
8690 | { | |
8691 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
8692 | inst.instruction |= 0xf0000000; | |
8693 | } | |
b99bd4ef | 8694 | |
c19d1205 ZW |
8695 | inst.instruction |= inst.operands[0].reg << 12; |
8696 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
8697 | } | |
b99bd4ef NC |
8698 | |
8699 | static void | |
c19d1205 | 8700 | do_iwmmxt_wldstd (void) |
b99bd4ef | 8701 | { |
c19d1205 | 8702 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
8703 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
8704 | && inst.operands[1].immisreg) | |
8705 | { | |
8706 | inst.instruction &= ~0x1a000ff; | |
8707 | inst.instruction |= (0xf << 28); | |
8708 | if (inst.operands[1].preind) | |
8709 | inst.instruction |= PRE_INDEX; | |
8710 | if (!inst.operands[1].negative) | |
8711 | inst.instruction |= INDEX_UP; | |
8712 | if (inst.operands[1].writeback) | |
8713 | inst.instruction |= WRITE_BACK; | |
8714 | inst.instruction |= inst.operands[1].reg << 16; | |
8715 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
8716 | inst.instruction |= inst.operands[1].imm; | |
8717 | } | |
8718 | else | |
8719 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 8720 | } |
b99bd4ef | 8721 | |
c19d1205 ZW |
8722 | static void |
8723 | do_iwmmxt_wshufh (void) | |
8724 | { | |
8725 | inst.instruction |= inst.operands[0].reg << 12; | |
8726 | inst.instruction |= inst.operands[1].reg << 16; | |
8727 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
8728 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
8729 | } | |
b99bd4ef | 8730 | |
c19d1205 ZW |
8731 | static void |
8732 | do_iwmmxt_wzero (void) | |
8733 | { | |
8734 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
8735 | inst.instruction |= inst.operands[0].reg; | |
8736 | inst.instruction |= inst.operands[0].reg << 12; | |
8737 | inst.instruction |= inst.operands[0].reg << 16; | |
8738 | } | |
2d447fca JM |
8739 | |
8740 | static void | |
8741 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
8742 | { | |
8743 | if (inst.operands[2].isreg) | |
8744 | do_rd_rn_rm (); | |
8745 | else { | |
8746 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
8747 | _("immediate operand requires iWMMXt2")); | |
8748 | do_rd_rn (); | |
8749 | if (inst.operands[2].imm == 0) | |
8750 | { | |
8751 | switch ((inst.instruction >> 20) & 0xf) | |
8752 | { | |
8753 | case 4: | |
8754 | case 5: | |
8755 | case 6: | |
5f4273c7 | 8756 | case 7: |
2d447fca JM |
8757 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
8758 | inst.operands[2].imm = 16; | |
8759 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
8760 | break; | |
8761 | case 8: | |
8762 | case 9: | |
8763 | case 10: | |
8764 | case 11: | |
8765 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
8766 | inst.operands[2].imm = 32; | |
8767 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
8768 | break; | |
8769 | case 12: | |
8770 | case 13: | |
8771 | case 14: | |
8772 | case 15: | |
8773 | { | |
8774 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
8775 | unsigned long wrn; | |
8776 | wrn = (inst.instruction >> 16) & 0xf; | |
8777 | inst.instruction &= 0xff0fff0f; | |
8778 | inst.instruction |= wrn; | |
8779 | /* Bail out here; the instruction is now assembled. */ | |
8780 | return; | |
8781 | } | |
8782 | } | |
8783 | } | |
8784 | /* Map 32 -> 0, etc. */ | |
8785 | inst.operands[2].imm &= 0x1f; | |
8786 | inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); | |
8787 | } | |
8788 | } | |
c19d1205 ZW |
8789 | \f |
8790 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
8791 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 8792 | |
c19d1205 | 8793 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 8794 | |
c19d1205 ZW |
8795 | static void |
8796 | do_mav_triple (void) | |
8797 | { | |
8798 | inst.instruction |= inst.operands[0].reg << 16; | |
8799 | inst.instruction |= inst.operands[1].reg; | |
8800 | inst.instruction |= inst.operands[2].reg << 12; | |
8801 | } | |
b99bd4ef | 8802 | |
c19d1205 ZW |
8803 | /* Insns like "foo W,X,Y,Z". |
8804 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 8805 | |
c19d1205 ZW |
8806 | static void |
8807 | do_mav_quad (void) | |
8808 | { | |
8809 | inst.instruction |= inst.operands[0].reg << 5; | |
8810 | inst.instruction |= inst.operands[1].reg << 12; | |
8811 | inst.instruction |= inst.operands[2].reg << 16; | |
8812 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
8813 | } |
8814 | ||
c19d1205 ZW |
8815 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
8816 | static void | |
8817 | do_mav_dspsc (void) | |
a737bd4d | 8818 | { |
c19d1205 ZW |
8819 | inst.instruction |= inst.operands[1].reg << 12; |
8820 | } | |
a737bd4d | 8821 | |
c19d1205 ZW |
8822 | /* Maverick shift immediate instructions. |
8823 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
8824 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 8825 | |
c19d1205 ZW |
8826 | static void |
8827 | do_mav_shift (void) | |
8828 | { | |
8829 | int imm = inst.operands[2].imm; | |
a737bd4d | 8830 | |
c19d1205 ZW |
8831 | inst.instruction |= inst.operands[0].reg << 12; |
8832 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 8833 | |
c19d1205 ZW |
8834 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
8835 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
8836 | Bit 4 should be 0. */ | |
8837 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 8838 | |
c19d1205 ZW |
8839 | inst.instruction |= imm; |
8840 | } | |
8841 | \f | |
8842 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 8843 | |
c19d1205 ZW |
8844 | /* Xscale multiply-accumulate (argument parse) |
8845 | MIAcc acc0,Rm,Rs | |
8846 | MIAPHcc acc0,Rm,Rs | |
8847 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 8848 | |
c19d1205 ZW |
8849 | static void |
8850 | do_xsc_mia (void) | |
8851 | { | |
8852 | inst.instruction |= inst.operands[1].reg; | |
8853 | inst.instruction |= inst.operands[2].reg << 12; | |
8854 | } | |
a737bd4d | 8855 | |
c19d1205 | 8856 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 8857 | |
c19d1205 | 8858 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 8859 | |
c19d1205 ZW |
8860 | static void |
8861 | do_xsc_mar (void) | |
8862 | { | |
8863 | inst.instruction |= inst.operands[1].reg << 12; | |
8864 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8865 | } |
8866 | ||
c19d1205 | 8867 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 8868 | |
c19d1205 | 8869 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
8870 | |
8871 | static void | |
c19d1205 | 8872 | do_xsc_mra (void) |
b99bd4ef | 8873 | { |
c19d1205 ZW |
8874 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
8875 | inst.instruction |= inst.operands[0].reg << 12; | |
8876 | inst.instruction |= inst.operands[1].reg << 16; | |
8877 | } | |
8878 | \f | |
8879 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 8880 | |
c19d1205 ZW |
8881 | /* inst.operands[i] is a shifted-register operand; encode |
8882 | it into inst.instruction in the format used by Thumb32. */ | |
8883 | ||
8884 | static void | |
8885 | encode_thumb32_shifted_operand (int i) | |
8886 | { | |
8887 | unsigned int value = inst.reloc.exp.X_add_number; | |
8888 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 8889 | |
9c3c69f2 PB |
8890 | constraint (inst.operands[i].immisreg, |
8891 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
8892 | inst.instruction |= inst.operands[i].reg; |
8893 | if (shift == SHIFT_RRX) | |
8894 | inst.instruction |= SHIFT_ROR << 4; | |
8895 | else | |
b99bd4ef | 8896 | { |
c19d1205 ZW |
8897 | constraint (inst.reloc.exp.X_op != O_constant, |
8898 | _("expression too complex")); | |
8899 | ||
8900 | constraint (value > 32 | |
8901 | || (value == 32 && (shift == SHIFT_LSL | |
8902 | || shift == SHIFT_ROR)), | |
8903 | _("shift expression is too large")); | |
8904 | ||
8905 | if (value == 0) | |
8906 | shift = SHIFT_LSL; | |
8907 | else if (value == 32) | |
8908 | value = 0; | |
8909 | ||
8910 | inst.instruction |= shift << 4; | |
8911 | inst.instruction |= (value & 0x1c) << 10; | |
8912 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 8913 | } |
c19d1205 | 8914 | } |
b99bd4ef | 8915 | |
b99bd4ef | 8916 | |
c19d1205 ZW |
8917 | /* inst.operands[i] was set up by parse_address. Encode it into a |
8918 | Thumb32 format load or store instruction. Reject forms that cannot | |
8919 | be used with such instructions. If is_t is true, reject forms that | |
8920 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
8921 | that cannot be used with a D instruction. If it is a store insn, |
8922 | reject PC in Rn. */ | |
b99bd4ef | 8923 | |
c19d1205 ZW |
8924 | static void |
8925 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
8926 | { | |
5be8be5d | 8927 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
8928 | |
8929 | constraint (!inst.operands[i].isreg, | |
53365c0d | 8930 | _("Instruction does not support =N addresses")); |
b99bd4ef | 8931 | |
c19d1205 ZW |
8932 | inst.instruction |= inst.operands[i].reg << 16; |
8933 | if (inst.operands[i].immisreg) | |
b99bd4ef | 8934 | { |
5be8be5d | 8935 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
8936 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
8937 | constraint (inst.operands[i].negative, | |
8938 | _("Thumb does not support negative register indexing")); | |
8939 | constraint (inst.operands[i].postind, | |
8940 | _("Thumb does not support register post-indexing")); | |
8941 | constraint (inst.operands[i].writeback, | |
8942 | _("Thumb does not support register indexing with writeback")); | |
8943 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
8944 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 8945 | |
f40d1643 | 8946 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 8947 | if (inst.operands[i].shifted) |
b99bd4ef | 8948 | { |
c19d1205 ZW |
8949 | constraint (inst.reloc.exp.X_op != O_constant, |
8950 | _("expression too complex")); | |
9c3c69f2 PB |
8951 | constraint (inst.reloc.exp.X_add_number < 0 |
8952 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 8953 | _("shift out of range")); |
9c3c69f2 | 8954 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
8955 | } |
8956 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8957 | } | |
8958 | else if (inst.operands[i].preind) | |
8959 | { | |
5be8be5d | 8960 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 8961 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 8962 | _("cannot use writeback with this instruction")); |
5be8be5d DG |
8963 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0) |
8964 | && !inst.reloc.pc_rel, BAD_PC_ADDRESSING); | |
c19d1205 ZW |
8965 | |
8966 | if (is_d) | |
8967 | { | |
8968 | inst.instruction |= 0x01000000; | |
8969 | if (inst.operands[i].writeback) | |
8970 | inst.instruction |= 0x00200000; | |
b99bd4ef | 8971 | } |
c19d1205 | 8972 | else |
b99bd4ef | 8973 | { |
c19d1205 ZW |
8974 | inst.instruction |= 0x00000c00; |
8975 | if (inst.operands[i].writeback) | |
8976 | inst.instruction |= 0x00000100; | |
b99bd4ef | 8977 | } |
c19d1205 | 8978 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 8979 | } |
c19d1205 | 8980 | else if (inst.operands[i].postind) |
b99bd4ef | 8981 | { |
9c2799c2 | 8982 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
8983 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
8984 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
8985 | ||
8986 | if (is_d) | |
8987 | inst.instruction |= 0x00200000; | |
8988 | else | |
8989 | inst.instruction |= 0x00000900; | |
8990 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
8991 | } | |
8992 | else /* unindexed - only for coprocessor */ | |
8993 | inst.error = _("instruction does not accept unindexed addressing"); | |
8994 | } | |
8995 | ||
8996 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
8997 | encodings (the latter only in post-V6T2 cores). The index is the | |
8998 | value used in the insns table below. When there is more than one | |
8999 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
9000 | holds variant (1). |
9001 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 9002 | #define T16_32_TAB \ |
21d799b5 NC |
9003 | X(_adc, 4140, eb400000), \ |
9004 | X(_adcs, 4140, eb500000), \ | |
9005 | X(_add, 1c00, eb000000), \ | |
9006 | X(_adds, 1c00, eb100000), \ | |
9007 | X(_addi, 0000, f1000000), \ | |
9008 | X(_addis, 0000, f1100000), \ | |
9009 | X(_add_pc,000f, f20f0000), \ | |
9010 | X(_add_sp,000d, f10d0000), \ | |
9011 | X(_adr, 000f, f20f0000), \ | |
9012 | X(_and, 4000, ea000000), \ | |
9013 | X(_ands, 4000, ea100000), \ | |
9014 | X(_asr, 1000, fa40f000), \ | |
9015 | X(_asrs, 1000, fa50f000), \ | |
9016 | X(_b, e000, f000b000), \ | |
9017 | X(_bcond, d000, f0008000), \ | |
9018 | X(_bic, 4380, ea200000), \ | |
9019 | X(_bics, 4380, ea300000), \ | |
9020 | X(_cmn, 42c0, eb100f00), \ | |
9021 | X(_cmp, 2800, ebb00f00), \ | |
9022 | X(_cpsie, b660, f3af8400), \ | |
9023 | X(_cpsid, b670, f3af8600), \ | |
9024 | X(_cpy, 4600, ea4f0000), \ | |
9025 | X(_dec_sp,80dd, f1ad0d00), \ | |
9026 | X(_eor, 4040, ea800000), \ | |
9027 | X(_eors, 4040, ea900000), \ | |
9028 | X(_inc_sp,00dd, f10d0d00), \ | |
9029 | X(_ldmia, c800, e8900000), \ | |
9030 | X(_ldr, 6800, f8500000), \ | |
9031 | X(_ldrb, 7800, f8100000), \ | |
9032 | X(_ldrh, 8800, f8300000), \ | |
9033 | X(_ldrsb, 5600, f9100000), \ | |
9034 | X(_ldrsh, 5e00, f9300000), \ | |
9035 | X(_ldr_pc,4800, f85f0000), \ | |
9036 | X(_ldr_pc2,4800, f85f0000), \ | |
9037 | X(_ldr_sp,9800, f85d0000), \ | |
9038 | X(_lsl, 0000, fa00f000), \ | |
9039 | X(_lsls, 0000, fa10f000), \ | |
9040 | X(_lsr, 0800, fa20f000), \ | |
9041 | X(_lsrs, 0800, fa30f000), \ | |
9042 | X(_mov, 2000, ea4f0000), \ | |
9043 | X(_movs, 2000, ea5f0000), \ | |
9044 | X(_mul, 4340, fb00f000), \ | |
9045 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
9046 | X(_mvn, 43c0, ea6f0000), \ | |
9047 | X(_mvns, 43c0, ea7f0000), \ | |
9048 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
9049 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
9050 | X(_orr, 4300, ea400000), \ | |
9051 | X(_orrs, 4300, ea500000), \ | |
9052 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
9053 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
9054 | X(_rev, ba00, fa90f080), \ | |
9055 | X(_rev16, ba40, fa90f090), \ | |
9056 | X(_revsh, bac0, fa90f0b0), \ | |
9057 | X(_ror, 41c0, fa60f000), \ | |
9058 | X(_rors, 41c0, fa70f000), \ | |
9059 | X(_sbc, 4180, eb600000), \ | |
9060 | X(_sbcs, 4180, eb700000), \ | |
9061 | X(_stmia, c000, e8800000), \ | |
9062 | X(_str, 6000, f8400000), \ | |
9063 | X(_strb, 7000, f8000000), \ | |
9064 | X(_strh, 8000, f8200000), \ | |
9065 | X(_str_sp,9000, f84d0000), \ | |
9066 | X(_sub, 1e00, eba00000), \ | |
9067 | X(_subs, 1e00, ebb00000), \ | |
9068 | X(_subi, 8000, f1a00000), \ | |
9069 | X(_subis, 8000, f1b00000), \ | |
9070 | X(_sxtb, b240, fa4ff080), \ | |
9071 | X(_sxth, b200, fa0ff080), \ | |
9072 | X(_tst, 4200, ea100f00), \ | |
9073 | X(_uxtb, b2c0, fa5ff080), \ | |
9074 | X(_uxth, b280, fa1ff080), \ | |
9075 | X(_nop, bf00, f3af8000), \ | |
9076 | X(_yield, bf10, f3af8001), \ | |
9077 | X(_wfe, bf20, f3af8002), \ | |
9078 | X(_wfi, bf30, f3af8003), \ | |
9079 | X(_sev, bf40, f3af8004), | |
c19d1205 ZW |
9080 | |
9081 | /* To catch errors in encoding functions, the codes are all offset by | |
9082 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
9083 | as 16-bit instructions. */ | |
21d799b5 | 9084 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
9085 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
9086 | #undef X | |
9087 | ||
9088 | #define X(a,b,c) 0x##b | |
9089 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
9090 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
9091 | #undef X | |
9092 | ||
9093 | #define X(a,b,c) 0x##c | |
9094 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
9095 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
9096 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
9097 | #undef X |
9098 | #undef T16_32_TAB | |
9099 | ||
9100 | /* Thumb instruction encoders, in alphabetical order. */ | |
9101 | ||
92e90b6e | 9102 | /* ADDW or SUBW. */ |
c921be7d | 9103 | |
92e90b6e PB |
9104 | static void |
9105 | do_t_add_sub_w (void) | |
9106 | { | |
9107 | int Rd, Rn; | |
9108 | ||
9109 | Rd = inst.operands[0].reg; | |
9110 | Rn = inst.operands[1].reg; | |
9111 | ||
539d4391 NC |
9112 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
9113 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
9114 | if (Rn == REG_SP) | |
9115 | constraint (Rd == REG_PC, BAD_PC); | |
9116 | else | |
9117 | reject_bad_reg (Rd); | |
fdfde340 | 9118 | |
92e90b6e PB |
9119 | inst.instruction |= (Rn << 16) | (Rd << 8); |
9120 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
9121 | } | |
9122 | ||
c19d1205 ZW |
9123 | /* Parse an add or subtract instruction. We get here with inst.instruction |
9124 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
9125 | ||
9126 | static void | |
9127 | do_t_add_sub (void) | |
9128 | { | |
9129 | int Rd, Rs, Rn; | |
9130 | ||
9131 | Rd = inst.operands[0].reg; | |
9132 | Rs = (inst.operands[1].present | |
9133 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9134 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9135 | ||
e07e6e58 NC |
9136 | if (Rd == REG_PC) |
9137 | set_it_insn_type_last (); | |
9138 | ||
c19d1205 ZW |
9139 | if (unified_syntax) |
9140 | { | |
0110f2b8 PB |
9141 | bfd_boolean flags; |
9142 | bfd_boolean narrow; | |
9143 | int opcode; | |
9144 | ||
9145 | flags = (inst.instruction == T_MNEM_adds | |
9146 | || inst.instruction == T_MNEM_subs); | |
9147 | if (flags) | |
e07e6e58 | 9148 | narrow = !in_it_block (); |
0110f2b8 | 9149 | else |
e07e6e58 | 9150 | narrow = in_it_block (); |
c19d1205 | 9151 | if (!inst.operands[2].isreg) |
b99bd4ef | 9152 | { |
16805f35 PB |
9153 | int add; |
9154 | ||
fdfde340 JM |
9155 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
9156 | ||
16805f35 PB |
9157 | add = (inst.instruction == T_MNEM_add |
9158 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
9159 | opcode = 0; |
9160 | if (inst.size_req != 4) | |
9161 | { | |
0110f2b8 PB |
9162 | /* Attempt to use a narrow opcode, with relaxation if |
9163 | appropriate. */ | |
9164 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
9165 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
9166 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
9167 | opcode = T_MNEM_add_sp; | |
9168 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
9169 | opcode = T_MNEM_add_pc; | |
9170 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
9171 | { | |
9172 | if (flags) | |
9173 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
9174 | else | |
9175 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
9176 | } | |
9177 | if (opcode) | |
9178 | { | |
9179 | inst.instruction = THUMB_OP16(opcode); | |
9180 | inst.instruction |= (Rd << 4) | Rs; | |
9181 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
9182 | if (inst.size_req != 2) | |
9183 | inst.relax = opcode; | |
9184 | } | |
9185 | else | |
9186 | constraint (inst.size_req == 2, BAD_HIREG); | |
9187 | } | |
9188 | if (inst.size_req == 4 | |
9189 | || (inst.size_req != 2 && !opcode)) | |
9190 | { | |
efd81785 PB |
9191 | if (Rd == REG_PC) |
9192 | { | |
fdfde340 | 9193 | constraint (add, BAD_PC); |
efd81785 PB |
9194 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
9195 | _("only SUBS PC, LR, #const allowed")); | |
9196 | constraint (inst.reloc.exp.X_op != O_constant, | |
9197 | _("expression too complex")); | |
9198 | constraint (inst.reloc.exp.X_add_number < 0 | |
9199 | || inst.reloc.exp.X_add_number > 0xff, | |
9200 | _("immediate value out of range")); | |
9201 | inst.instruction = T2_SUBS_PC_LR | |
9202 | | inst.reloc.exp.X_add_number; | |
9203 | inst.reloc.type = BFD_RELOC_UNUSED; | |
9204 | return; | |
9205 | } | |
9206 | else if (Rs == REG_PC) | |
16805f35 PB |
9207 | { |
9208 | /* Always use addw/subw. */ | |
9209 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
9210 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
9211 | } | |
9212 | else | |
9213 | { | |
9214 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9215 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
9216 | | 0x10000000; | |
9217 | if (flags) | |
9218 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9219 | else | |
9220 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
9221 | } | |
dc4503c6 PB |
9222 | inst.instruction |= Rd << 8; |
9223 | inst.instruction |= Rs << 16; | |
0110f2b8 | 9224 | } |
b99bd4ef | 9225 | } |
c19d1205 ZW |
9226 | else |
9227 | { | |
9228 | Rn = inst.operands[2].reg; | |
9229 | /* See if we can do this with a 16-bit instruction. */ | |
9230 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
9231 | { | |
e27ec89e PB |
9232 | if (Rd > 7 || Rs > 7 || Rn > 7) |
9233 | narrow = FALSE; | |
9234 | ||
9235 | if (narrow) | |
c19d1205 | 9236 | { |
e27ec89e PB |
9237 | inst.instruction = ((inst.instruction == T_MNEM_adds |
9238 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
9239 | ? T_OPCODE_ADD_R3 |
9240 | : T_OPCODE_SUB_R3); | |
9241 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
9242 | return; | |
9243 | } | |
b99bd4ef | 9244 | |
7e806470 | 9245 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 9246 | { |
7e806470 PB |
9247 | /* Thumb-1 cores (except v6-M) require at least one high |
9248 | register in a narrow non flag setting add. */ | |
9249 | if (Rd > 7 || Rn > 7 | |
9250 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
9251 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 9252 | { |
7e806470 PB |
9253 | if (Rd == Rn) |
9254 | { | |
9255 | Rn = Rs; | |
9256 | Rs = Rd; | |
9257 | } | |
c19d1205 ZW |
9258 | inst.instruction = T_OPCODE_ADD_HI; |
9259 | inst.instruction |= (Rd & 8) << 4; | |
9260 | inst.instruction |= (Rd & 7); | |
9261 | inst.instruction |= Rn << 3; | |
9262 | return; | |
9263 | } | |
c19d1205 ZW |
9264 | } |
9265 | } | |
c921be7d | 9266 | |
fdfde340 JM |
9267 | constraint (Rd == REG_PC, BAD_PC); |
9268 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
9269 | constraint (Rs == REG_PC, BAD_PC); | |
9270 | reject_bad_reg (Rn); | |
9271 | ||
c19d1205 ZW |
9272 | /* If we get here, it can't be done in 16 bits. */ |
9273 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
9274 | _("shift must be constant")); | |
9275 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9276 | inst.instruction |= Rd << 8; | |
9277 | inst.instruction |= Rs << 16; | |
9278 | encode_thumb32_shifted_operand (2); | |
9279 | } | |
9280 | } | |
9281 | else | |
9282 | { | |
9283 | constraint (inst.instruction == T_MNEM_adds | |
9284 | || inst.instruction == T_MNEM_subs, | |
9285 | BAD_THUMB32); | |
b99bd4ef | 9286 | |
c19d1205 | 9287 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 9288 | { |
c19d1205 ZW |
9289 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
9290 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
9291 | BAD_HIREG); | |
9292 | ||
9293 | inst.instruction = (inst.instruction == T_MNEM_add | |
9294 | ? 0x0000 : 0x8000); | |
9295 | inst.instruction |= (Rd << 4) | Rs; | |
9296 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
9297 | return; |
9298 | } | |
9299 | ||
c19d1205 ZW |
9300 | Rn = inst.operands[2].reg; |
9301 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 9302 | |
c19d1205 ZW |
9303 | /* We now have Rd, Rs, and Rn set to registers. */ |
9304 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 9305 | { |
c19d1205 ZW |
9306 | /* Can't do this for SUB. */ |
9307 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
9308 | inst.instruction = T_OPCODE_ADD_HI; | |
9309 | inst.instruction |= (Rd & 8) << 4; | |
9310 | inst.instruction |= (Rd & 7); | |
9311 | if (Rs == Rd) | |
9312 | inst.instruction |= Rn << 3; | |
9313 | else if (Rn == Rd) | |
9314 | inst.instruction |= Rs << 3; | |
9315 | else | |
9316 | constraint (1, _("dest must overlap one source register")); | |
9317 | } | |
9318 | else | |
9319 | { | |
9320 | inst.instruction = (inst.instruction == T_MNEM_add | |
9321 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
9322 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 9323 | } |
b99bd4ef | 9324 | } |
b99bd4ef NC |
9325 | } |
9326 | ||
c19d1205 ZW |
9327 | static void |
9328 | do_t_adr (void) | |
9329 | { | |
fdfde340 JM |
9330 | unsigned Rd; |
9331 | ||
9332 | Rd = inst.operands[0].reg; | |
9333 | reject_bad_reg (Rd); | |
9334 | ||
9335 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
9336 | { |
9337 | /* Defer to section relaxation. */ | |
9338 | inst.relax = inst.instruction; | |
9339 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 9340 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
9341 | } |
9342 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 9343 | { |
0110f2b8 | 9344 | /* Generate a 32-bit opcode. */ |
e9f89963 | 9345 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 9346 | inst.instruction |= Rd << 8; |
e9f89963 PB |
9347 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
9348 | inst.reloc.pc_rel = 1; | |
9349 | } | |
9350 | else | |
9351 | { | |
0110f2b8 | 9352 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
9353 | inst.instruction = THUMB_OP16 (inst.instruction); |
9354 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
9355 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
9356 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 9357 | |
fdfde340 | 9358 | inst.instruction |= Rd << 4; |
e9f89963 | 9359 | } |
c19d1205 | 9360 | } |
b99bd4ef | 9361 | |
c19d1205 ZW |
9362 | /* Arithmetic instructions for which there is just one 16-bit |
9363 | instruction encoding, and it allows only two low registers. | |
9364 | For maximal compatibility with ARM syntax, we allow three register | |
9365 | operands even when Thumb-32 instructions are not available, as long | |
9366 | as the first two are identical. For instance, both "sbc r0,r1" and | |
9367 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 9368 | static void |
c19d1205 | 9369 | do_t_arit3 (void) |
b99bd4ef | 9370 | { |
c19d1205 | 9371 | int Rd, Rs, Rn; |
b99bd4ef | 9372 | |
c19d1205 ZW |
9373 | Rd = inst.operands[0].reg; |
9374 | Rs = (inst.operands[1].present | |
9375 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9376 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9377 | Rn = inst.operands[2].reg; | |
b99bd4ef | 9378 | |
fdfde340 JM |
9379 | reject_bad_reg (Rd); |
9380 | reject_bad_reg (Rs); | |
9381 | if (inst.operands[2].isreg) | |
9382 | reject_bad_reg (Rn); | |
9383 | ||
c19d1205 | 9384 | if (unified_syntax) |
b99bd4ef | 9385 | { |
c19d1205 ZW |
9386 | if (!inst.operands[2].isreg) |
9387 | { | |
9388 | /* For an immediate, we always generate a 32-bit opcode; | |
9389 | section relaxation will shrink it later if possible. */ | |
9390 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9391 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9392 | inst.instruction |= Rd << 8; | |
9393 | inst.instruction |= Rs << 16; | |
9394 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9395 | } | |
9396 | else | |
9397 | { | |
e27ec89e PB |
9398 | bfd_boolean narrow; |
9399 | ||
c19d1205 | 9400 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9401 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9402 | narrow = !in_it_block (); |
e27ec89e | 9403 | else |
e07e6e58 | 9404 | narrow = in_it_block (); |
e27ec89e PB |
9405 | |
9406 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9407 | narrow = FALSE; | |
9408 | if (inst.operands[2].shifted) | |
9409 | narrow = FALSE; | |
9410 | if (inst.size_req == 4) | |
9411 | narrow = FALSE; | |
9412 | ||
9413 | if (narrow | |
c19d1205 ZW |
9414 | && Rd == Rs) |
9415 | { | |
9416 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9417 | inst.instruction |= Rd; | |
9418 | inst.instruction |= Rn << 3; | |
9419 | return; | |
9420 | } | |
b99bd4ef | 9421 | |
c19d1205 ZW |
9422 | /* If we get here, it can't be done in 16 bits. */ |
9423 | constraint (inst.operands[2].shifted | |
9424 | && inst.operands[2].immisreg, | |
9425 | _("shift must be constant")); | |
9426 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9427 | inst.instruction |= Rd << 8; | |
9428 | inst.instruction |= Rs << 16; | |
9429 | encode_thumb32_shifted_operand (2); | |
9430 | } | |
a737bd4d | 9431 | } |
c19d1205 | 9432 | else |
b99bd4ef | 9433 | { |
c19d1205 ZW |
9434 | /* On its face this is a lie - the instruction does set the |
9435 | flags. However, the only supported mnemonic in this mode | |
9436 | says it doesn't. */ | |
9437 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9438 | |
c19d1205 ZW |
9439 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9440 | _("unshifted register required")); | |
9441 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9442 | constraint (Rd != Rs, | |
9443 | _("dest and source1 must be the same register")); | |
a737bd4d | 9444 | |
c19d1205 ZW |
9445 | inst.instruction = THUMB_OP16 (inst.instruction); |
9446 | inst.instruction |= Rd; | |
9447 | inst.instruction |= Rn << 3; | |
b99bd4ef | 9448 | } |
a737bd4d | 9449 | } |
b99bd4ef | 9450 | |
c19d1205 ZW |
9451 | /* Similarly, but for instructions where the arithmetic operation is |
9452 | commutative, so we can allow either of them to be different from | |
9453 | the destination operand in a 16-bit instruction. For instance, all | |
9454 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
9455 | accepted. */ | |
9456 | static void | |
9457 | do_t_arit3c (void) | |
a737bd4d | 9458 | { |
c19d1205 | 9459 | int Rd, Rs, Rn; |
b99bd4ef | 9460 | |
c19d1205 ZW |
9461 | Rd = inst.operands[0].reg; |
9462 | Rs = (inst.operands[1].present | |
9463 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9464 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9465 | Rn = inst.operands[2].reg; | |
c921be7d | 9466 | |
fdfde340 JM |
9467 | reject_bad_reg (Rd); |
9468 | reject_bad_reg (Rs); | |
9469 | if (inst.operands[2].isreg) | |
9470 | reject_bad_reg (Rn); | |
a737bd4d | 9471 | |
c19d1205 | 9472 | if (unified_syntax) |
a737bd4d | 9473 | { |
c19d1205 | 9474 | if (!inst.operands[2].isreg) |
b99bd4ef | 9475 | { |
c19d1205 ZW |
9476 | /* For an immediate, we always generate a 32-bit opcode; |
9477 | section relaxation will shrink it later if possible. */ | |
9478 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9479 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9480 | inst.instruction |= Rd << 8; | |
9481 | inst.instruction |= Rs << 16; | |
9482 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 9483 | } |
c19d1205 | 9484 | else |
a737bd4d | 9485 | { |
e27ec89e PB |
9486 | bfd_boolean narrow; |
9487 | ||
c19d1205 | 9488 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9489 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9490 | narrow = !in_it_block (); |
e27ec89e | 9491 | else |
e07e6e58 | 9492 | narrow = in_it_block (); |
e27ec89e PB |
9493 | |
9494 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9495 | narrow = FALSE; | |
9496 | if (inst.operands[2].shifted) | |
9497 | narrow = FALSE; | |
9498 | if (inst.size_req == 4) | |
9499 | narrow = FALSE; | |
9500 | ||
9501 | if (narrow) | |
a737bd4d | 9502 | { |
c19d1205 | 9503 | if (Rd == Rs) |
a737bd4d | 9504 | { |
c19d1205 ZW |
9505 | inst.instruction = THUMB_OP16 (inst.instruction); |
9506 | inst.instruction |= Rd; | |
9507 | inst.instruction |= Rn << 3; | |
9508 | return; | |
a737bd4d | 9509 | } |
c19d1205 | 9510 | if (Rd == Rn) |
a737bd4d | 9511 | { |
c19d1205 ZW |
9512 | inst.instruction = THUMB_OP16 (inst.instruction); |
9513 | inst.instruction |= Rd; | |
9514 | inst.instruction |= Rs << 3; | |
9515 | return; | |
a737bd4d NC |
9516 | } |
9517 | } | |
c19d1205 ZW |
9518 | |
9519 | /* If we get here, it can't be done in 16 bits. */ | |
9520 | constraint (inst.operands[2].shifted | |
9521 | && inst.operands[2].immisreg, | |
9522 | _("shift must be constant")); | |
9523 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9524 | inst.instruction |= Rd << 8; | |
9525 | inst.instruction |= Rs << 16; | |
9526 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 9527 | } |
b99bd4ef | 9528 | } |
c19d1205 ZW |
9529 | else |
9530 | { | |
9531 | /* On its face this is a lie - the instruction does set the | |
9532 | flags. However, the only supported mnemonic in this mode | |
9533 | says it doesn't. */ | |
9534 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9535 | |
c19d1205 ZW |
9536 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9537 | _("unshifted register required")); | |
9538 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9539 | ||
9540 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9541 | inst.instruction |= Rd; | |
9542 | ||
9543 | if (Rd == Rs) | |
9544 | inst.instruction |= Rn << 3; | |
9545 | else if (Rd == Rn) | |
9546 | inst.instruction |= Rs << 3; | |
9547 | else | |
9548 | constraint (1, _("dest must overlap one source register")); | |
9549 | } | |
a737bd4d NC |
9550 | } |
9551 | ||
62b3e311 PB |
9552 | static void |
9553 | do_t_barrier (void) | |
9554 | { | |
9555 | if (inst.operands[0].present) | |
9556 | { | |
9557 | constraint ((inst.instruction & 0xf0) != 0x40 | |
52e7f43d RE |
9558 | && inst.operands[0].imm > 0xf |
9559 | && inst.operands[0].imm < 0x0, | |
bd3ba5d1 | 9560 | _("bad barrier type")); |
62b3e311 PB |
9561 | inst.instruction |= inst.operands[0].imm; |
9562 | } | |
9563 | else | |
9564 | inst.instruction |= 0xf; | |
9565 | } | |
9566 | ||
c19d1205 ZW |
9567 | static void |
9568 | do_t_bfc (void) | |
a737bd4d | 9569 | { |
fdfde340 | 9570 | unsigned Rd; |
c19d1205 ZW |
9571 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
9572 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9573 | /* The instruction encoding stores the LSB and MSB, | |
9574 | not the LSB and width. */ | |
fdfde340 JM |
9575 | Rd = inst.operands[0].reg; |
9576 | reject_bad_reg (Rd); | |
9577 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
9578 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
9579 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
9580 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9581 | } |
9582 | ||
c19d1205 ZW |
9583 | static void |
9584 | do_t_bfi (void) | |
b99bd4ef | 9585 | { |
fdfde340 | 9586 | int Rd, Rn; |
c19d1205 | 9587 | unsigned int msb; |
b99bd4ef | 9588 | |
fdfde340 JM |
9589 | Rd = inst.operands[0].reg; |
9590 | reject_bad_reg (Rd); | |
9591 | ||
c19d1205 ZW |
9592 | /* #0 in second position is alternative syntax for bfc, which is |
9593 | the same instruction but with REG_PC in the Rm field. */ | |
9594 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
9595 | Rn = REG_PC; |
9596 | else | |
9597 | { | |
9598 | Rn = inst.operands[1].reg; | |
9599 | reject_bad_reg (Rn); | |
9600 | } | |
b99bd4ef | 9601 | |
c19d1205 ZW |
9602 | msb = inst.operands[2].imm + inst.operands[3].imm; |
9603 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9604 | /* The instruction encoding stores the LSB and MSB, | |
9605 | not the LSB and width. */ | |
fdfde340 JM |
9606 | inst.instruction |= Rd << 8; |
9607 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9608 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9609 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9610 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9611 | } |
9612 | ||
c19d1205 ZW |
9613 | static void |
9614 | do_t_bfx (void) | |
b99bd4ef | 9615 | { |
fdfde340 JM |
9616 | unsigned Rd, Rn; |
9617 | ||
9618 | Rd = inst.operands[0].reg; | |
9619 | Rn = inst.operands[1].reg; | |
9620 | ||
9621 | reject_bad_reg (Rd); | |
9622 | reject_bad_reg (Rn); | |
9623 | ||
c19d1205 ZW |
9624 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
9625 | _("bit-field extends past end of register")); | |
fdfde340 JM |
9626 | inst.instruction |= Rd << 8; |
9627 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9628 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9629 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9630 | inst.instruction |= inst.operands[3].imm - 1; | |
9631 | } | |
b99bd4ef | 9632 | |
c19d1205 ZW |
9633 | /* ARM V5 Thumb BLX (argument parse) |
9634 | BLX <target_addr> which is BLX(1) | |
9635 | BLX <Rm> which is BLX(2) | |
9636 | Unfortunately, there are two different opcodes for this mnemonic. | |
9637 | So, the insns[].value is not used, and the code here zaps values | |
9638 | into inst.instruction. | |
b99bd4ef | 9639 | |
c19d1205 ZW |
9640 | ??? How to take advantage of the additional two bits of displacement |
9641 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 9642 | |
c19d1205 ZW |
9643 | static void |
9644 | do_t_blx (void) | |
9645 | { | |
e07e6e58 NC |
9646 | set_it_insn_type_last (); |
9647 | ||
c19d1205 | 9648 | if (inst.operands[0].isreg) |
fdfde340 JM |
9649 | { |
9650 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
9651 | /* We have a register, so this is BLX(2). */ | |
9652 | inst.instruction |= inst.operands[0].reg << 3; | |
9653 | } | |
b99bd4ef NC |
9654 | else |
9655 | { | |
c19d1205 | 9656 | /* No register. This must be BLX(1). */ |
2fc8bdac | 9657 | inst.instruction = 0xf000e800; |
00adf2d4 | 9658 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; |
c19d1205 | 9659 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
9660 | } |
9661 | } | |
9662 | ||
c19d1205 ZW |
9663 | static void |
9664 | do_t_branch (void) | |
b99bd4ef | 9665 | { |
0110f2b8 | 9666 | int opcode; |
dfa9f0d5 | 9667 | int cond; |
9ae92b05 | 9668 | int reloc; |
dfa9f0d5 | 9669 | |
e07e6e58 NC |
9670 | cond = inst.cond; |
9671 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
9672 | ||
9673 | if (in_it_block ()) | |
dfa9f0d5 PB |
9674 | { |
9675 | /* Conditional branches inside IT blocks are encoded as unconditional | |
9676 | branches. */ | |
9677 | cond = COND_ALWAYS; | |
dfa9f0d5 PB |
9678 | } |
9679 | else | |
9680 | cond = inst.cond; | |
9681 | ||
9682 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
9683 | opcode = T_MNEM_bcond; |
9684 | else | |
9685 | opcode = inst.instruction; | |
9686 | ||
12d6b0b7 RS |
9687 | if (unified_syntax |
9688 | && (inst.size_req == 4 | |
9689 | || (inst.size_req != 2 && inst.operands[0].hasreloc))) | |
c19d1205 | 9690 | { |
0110f2b8 | 9691 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 9692 | if (cond == COND_ALWAYS) |
9ae92b05 | 9693 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
9694 | else |
9695 | { | |
9c2799c2 | 9696 | gas_assert (cond != 0xF); |
dfa9f0d5 | 9697 | inst.instruction |= cond << 22; |
9ae92b05 | 9698 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
9699 | } |
9700 | } | |
b99bd4ef NC |
9701 | else |
9702 | { | |
0110f2b8 | 9703 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 9704 | if (cond == COND_ALWAYS) |
9ae92b05 | 9705 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 9706 | else |
b99bd4ef | 9707 | { |
dfa9f0d5 | 9708 | inst.instruction |= cond << 8; |
9ae92b05 | 9709 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 9710 | } |
0110f2b8 PB |
9711 | /* Allow section relaxation. */ |
9712 | if (unified_syntax && inst.size_req != 2) | |
9713 | inst.relax = opcode; | |
b99bd4ef | 9714 | } |
9ae92b05 | 9715 | inst.reloc.type = reloc; |
c19d1205 | 9716 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
9717 | } |
9718 | ||
9719 | static void | |
c19d1205 | 9720 | do_t_bkpt (void) |
b99bd4ef | 9721 | { |
dfa9f0d5 PB |
9722 | constraint (inst.cond != COND_ALWAYS, |
9723 | _("instruction is always unconditional")); | |
c19d1205 | 9724 | if (inst.operands[0].present) |
b99bd4ef | 9725 | { |
c19d1205 ZW |
9726 | constraint (inst.operands[0].imm > 255, |
9727 | _("immediate value out of range")); | |
9728 | inst.instruction |= inst.operands[0].imm; | |
e07e6e58 | 9729 | set_it_insn_type (NEUTRAL_IT_INSN); |
b99bd4ef | 9730 | } |
b99bd4ef NC |
9731 | } |
9732 | ||
9733 | static void | |
c19d1205 | 9734 | do_t_branch23 (void) |
b99bd4ef | 9735 | { |
e07e6e58 | 9736 | set_it_insn_type_last (); |
c19d1205 | 9737 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
9738 | inst.reloc.pc_rel = 1; |
9739 | ||
4343666d | 9740 | #if defined(OBJ_COFF) |
c19d1205 ZW |
9741 | /* If the destination of the branch is a defined symbol which does not have |
9742 | the THUMB_FUNC attribute, then we must be calling a function which has | |
9743 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
9744 | function and change the branch to refer to that function instead. */ | |
9745 | if ( inst.reloc.exp.X_op == O_symbol | |
9746 | && inst.reloc.exp.X_add_symbol != NULL | |
9747 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
9748 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
9749 | inst.reloc.exp.X_add_symbol = | |
9750 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 9751 | #endif |
90e4755a RE |
9752 | } |
9753 | ||
9754 | static void | |
c19d1205 | 9755 | do_t_bx (void) |
90e4755a | 9756 | { |
e07e6e58 | 9757 | set_it_insn_type_last (); |
c19d1205 ZW |
9758 | inst.instruction |= inst.operands[0].reg << 3; |
9759 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
9760 | should cause the alignment to be checked once it is known. This is | |
9761 | because BX PC only works if the instruction is word aligned. */ | |
9762 | } | |
90e4755a | 9763 | |
c19d1205 ZW |
9764 | static void |
9765 | do_t_bxj (void) | |
9766 | { | |
fdfde340 | 9767 | int Rm; |
90e4755a | 9768 | |
e07e6e58 | 9769 | set_it_insn_type_last (); |
fdfde340 JM |
9770 | Rm = inst.operands[0].reg; |
9771 | reject_bad_reg (Rm); | |
9772 | inst.instruction |= Rm << 16; | |
90e4755a RE |
9773 | } |
9774 | ||
9775 | static void | |
c19d1205 | 9776 | do_t_clz (void) |
90e4755a | 9777 | { |
fdfde340 JM |
9778 | unsigned Rd; |
9779 | unsigned Rm; | |
9780 | ||
9781 | Rd = inst.operands[0].reg; | |
9782 | Rm = inst.operands[1].reg; | |
9783 | ||
9784 | reject_bad_reg (Rd); | |
9785 | reject_bad_reg (Rm); | |
9786 | ||
9787 | inst.instruction |= Rd << 8; | |
9788 | inst.instruction |= Rm << 16; | |
9789 | inst.instruction |= Rm; | |
c19d1205 | 9790 | } |
90e4755a | 9791 | |
dfa9f0d5 PB |
9792 | static void |
9793 | do_t_cps (void) | |
9794 | { | |
e07e6e58 | 9795 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
9796 | inst.instruction |= inst.operands[0].imm; |
9797 | } | |
9798 | ||
c19d1205 ZW |
9799 | static void |
9800 | do_t_cpsi (void) | |
9801 | { | |
e07e6e58 | 9802 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 9803 | if (unified_syntax |
62b3e311 PB |
9804 | && (inst.operands[1].present || inst.size_req == 4) |
9805 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 9806 | { |
c19d1205 ZW |
9807 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
9808 | inst.instruction = 0xf3af8000; | |
9809 | inst.instruction |= imod << 9; | |
9810 | inst.instruction |= inst.operands[0].imm << 5; | |
9811 | if (inst.operands[1].present) | |
9812 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 9813 | } |
c19d1205 | 9814 | else |
90e4755a | 9815 | { |
62b3e311 PB |
9816 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
9817 | && (inst.operands[0].imm & 4), | |
9818 | _("selected processor does not support 'A' form " | |
9819 | "of this instruction")); | |
9820 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
9821 | _("Thumb does not support the 2-argument " |
9822 | "form of this instruction")); | |
9823 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 9824 | } |
90e4755a RE |
9825 | } |
9826 | ||
c19d1205 ZW |
9827 | /* THUMB CPY instruction (argument parse). */ |
9828 | ||
90e4755a | 9829 | static void |
c19d1205 | 9830 | do_t_cpy (void) |
90e4755a | 9831 | { |
c19d1205 | 9832 | if (inst.size_req == 4) |
90e4755a | 9833 | { |
c19d1205 ZW |
9834 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
9835 | inst.instruction |= inst.operands[0].reg << 8; | |
9836 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 9837 | } |
c19d1205 | 9838 | else |
90e4755a | 9839 | { |
c19d1205 ZW |
9840 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
9841 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9842 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 9843 | } |
90e4755a RE |
9844 | } |
9845 | ||
90e4755a | 9846 | static void |
25fe350b | 9847 | do_t_cbz (void) |
90e4755a | 9848 | { |
e07e6e58 | 9849 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
9850 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9851 | inst.instruction |= inst.operands[0].reg; | |
9852 | inst.reloc.pc_rel = 1; | |
9853 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
9854 | } | |
90e4755a | 9855 | |
62b3e311 PB |
9856 | static void |
9857 | do_t_dbg (void) | |
9858 | { | |
9859 | inst.instruction |= inst.operands[0].imm; | |
9860 | } | |
9861 | ||
9862 | static void | |
9863 | do_t_div (void) | |
9864 | { | |
fdfde340 JM |
9865 | unsigned Rd, Rn, Rm; |
9866 | ||
9867 | Rd = inst.operands[0].reg; | |
9868 | Rn = (inst.operands[1].present | |
9869 | ? inst.operands[1].reg : Rd); | |
9870 | Rm = inst.operands[2].reg; | |
9871 | ||
9872 | reject_bad_reg (Rd); | |
9873 | reject_bad_reg (Rn); | |
9874 | reject_bad_reg (Rm); | |
9875 | ||
9876 | inst.instruction |= Rd << 8; | |
9877 | inst.instruction |= Rn << 16; | |
9878 | inst.instruction |= Rm; | |
62b3e311 PB |
9879 | } |
9880 | ||
c19d1205 ZW |
9881 | static void |
9882 | do_t_hint (void) | |
9883 | { | |
9884 | if (unified_syntax && inst.size_req == 4) | |
9885 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9886 | else | |
9887 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9888 | } | |
90e4755a | 9889 | |
c19d1205 ZW |
9890 | static void |
9891 | do_t_it (void) | |
9892 | { | |
9893 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 9894 | |
e07e6e58 NC |
9895 | set_it_insn_type (IT_INSN); |
9896 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
9897 | now_it.cc = cond; | |
e27ec89e PB |
9898 | |
9899 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 9900 | if ((cond & 0x1) == 0x0) |
90e4755a | 9901 | { |
c19d1205 | 9902 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 9903 | |
c19d1205 ZW |
9904 | if ((mask & 0x7) == 0) |
9905 | /* no conversion needed */; | |
9906 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
9907 | mask ^= 0x8; |
9908 | else if ((mask & 0x1) == 0) | |
9909 | mask ^= 0xC; | |
c19d1205 | 9910 | else |
e27ec89e | 9911 | mask ^= 0xE; |
90e4755a | 9912 | |
e27ec89e PB |
9913 | inst.instruction &= 0xfff0; |
9914 | inst.instruction |= mask; | |
c19d1205 | 9915 | } |
90e4755a | 9916 | |
c19d1205 ZW |
9917 | inst.instruction |= cond << 4; |
9918 | } | |
90e4755a | 9919 | |
3c707909 PB |
9920 | /* Helper function used for both push/pop and ldm/stm. */ |
9921 | static void | |
9922 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
9923 | { | |
9924 | bfd_boolean load; | |
9925 | ||
9926 | load = (inst.instruction & (1 << 20)) != 0; | |
9927 | ||
9928 | if (mask & (1 << 13)) | |
9929 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 NC |
9930 | |
9931 | if ((mask & (1 << base)) != 0 | |
9932 | && writeback) | |
9933 | inst.error = _("having the base register in the register list when " | |
9934 | "using write back is UNPREDICTABLE"); | |
9935 | ||
3c707909 PB |
9936 | if (load) |
9937 | { | |
e07e6e58 NC |
9938 | if (mask & (1 << 15)) |
9939 | { | |
9940 | if (mask & (1 << 14)) | |
9941 | inst.error = _("LR and PC should not both be in register list"); | |
9942 | else | |
9943 | set_it_insn_type_last (); | |
9944 | } | |
3c707909 PB |
9945 | } |
9946 | else | |
9947 | { | |
9948 | if (mask & (1 << 15)) | |
9949 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
9950 | } |
9951 | ||
9952 | if ((mask & (mask - 1)) == 0) | |
9953 | { | |
9954 | /* Single register transfers implemented as str/ldr. */ | |
9955 | if (writeback) | |
9956 | { | |
9957 | if (inst.instruction & (1 << 23)) | |
9958 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
9959 | else | |
9960 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
9961 | } | |
9962 | else | |
9963 | { | |
9964 | if (inst.instruction & (1 << 23)) | |
9965 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
9966 | else | |
9967 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
9968 | } | |
9969 | ||
9970 | inst.instruction |= 0xf8400000; | |
9971 | if (load) | |
9972 | inst.instruction |= 0x00100000; | |
9973 | ||
5f4273c7 | 9974 | mask = ffs (mask) - 1; |
3c707909 PB |
9975 | mask <<= 12; |
9976 | } | |
9977 | else if (writeback) | |
9978 | inst.instruction |= WRITE_BACK; | |
9979 | ||
9980 | inst.instruction |= mask; | |
9981 | inst.instruction |= base << 16; | |
9982 | } | |
9983 | ||
c19d1205 ZW |
9984 | static void |
9985 | do_t_ldmstm (void) | |
9986 | { | |
9987 | /* This really doesn't seem worth it. */ | |
9988 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9989 | _("expression too complex")); | |
9990 | constraint (inst.operands[1].writeback, | |
9991 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 9992 | |
c19d1205 ZW |
9993 | if (unified_syntax) |
9994 | { | |
3c707909 PB |
9995 | bfd_boolean narrow; |
9996 | unsigned mask; | |
9997 | ||
9998 | narrow = FALSE; | |
c19d1205 ZW |
9999 | /* See if we can use a 16-bit instruction. */ |
10000 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
10001 | && inst.size_req != 4 | |
3c707909 | 10002 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 10003 | { |
3c707909 | 10004 | mask = 1 << inst.operands[0].reg; |
90e4755a | 10005 | |
eab4f823 | 10006 | if (inst.operands[0].reg <= 7) |
90e4755a | 10007 | { |
3c707909 | 10008 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
10009 | ? inst.operands[0].writeback |
10010 | : (inst.operands[0].writeback | |
10011 | == !(inst.operands[1].imm & mask))) | |
10012 | { | |
10013 | if (inst.instruction == T_MNEM_stmia | |
10014 | && (inst.operands[1].imm & mask) | |
10015 | && (inst.operands[1].imm & (mask - 1))) | |
10016 | as_warn (_("value stored for r%d is UNKNOWN"), | |
10017 | inst.operands[0].reg); | |
3c707909 | 10018 | |
eab4f823 MGD |
10019 | inst.instruction = THUMB_OP16 (inst.instruction); |
10020 | inst.instruction |= inst.operands[0].reg << 8; | |
10021 | inst.instruction |= inst.operands[1].imm; | |
10022 | narrow = TRUE; | |
10023 | } | |
10024 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
10025 | { | |
10026 | /* This means 1 register in reg list one of 3 situations: | |
10027 | 1. Instruction is stmia, but without writeback. | |
10028 | 2. lmdia without writeback, but with Rn not in | |
10029 | reglist. | |
10030 | 3. ldmia with writeback, but with Rn in reglist. | |
10031 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
10032 | case 1 and 2 which can be converted into a 16-bit | |
10033 | str or ldr. The SP cases are handled below. */ | |
10034 | unsigned long opcode; | |
10035 | /* First, record an error for Case 3. */ | |
10036 | if (inst.operands[1].imm & mask | |
10037 | && inst.operands[0].writeback) | |
10038 | inst.error = | |
10039 | _("having the base register in the register list when " | |
10040 | "using write back is UNPREDICTABLE"); | |
10041 | ||
10042 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
10043 | : T_MNEM_ldr); | |
10044 | inst.instruction = THUMB_OP16 (opcode); | |
10045 | inst.instruction |= inst.operands[0].reg << 3; | |
10046 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
10047 | narrow = TRUE; | |
10048 | } | |
90e4755a | 10049 | } |
eab4f823 | 10050 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 10051 | { |
eab4f823 MGD |
10052 | if (inst.operands[0].writeback) |
10053 | { | |
10054 | inst.instruction = | |
10055 | THUMB_OP16 (inst.instruction == T_MNEM_stmia | |
10056 | ? T_MNEM_push : T_MNEM_pop); | |
10057 | inst.instruction |= inst.operands[1].imm; | |
10058 | narrow = TRUE; | |
10059 | } | |
10060 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
10061 | { | |
10062 | inst.instruction = | |
10063 | THUMB_OP16 (inst.instruction == T_MNEM_stmia | |
10064 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); | |
10065 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); | |
10066 | narrow = TRUE; | |
10067 | } | |
90e4755a | 10068 | } |
3c707909 PB |
10069 | } |
10070 | ||
10071 | if (!narrow) | |
10072 | { | |
c19d1205 ZW |
10073 | if (inst.instruction < 0xffff) |
10074 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 10075 | |
5f4273c7 NC |
10076 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
10077 | inst.operands[0].writeback); | |
90e4755a RE |
10078 | } |
10079 | } | |
c19d1205 | 10080 | else |
90e4755a | 10081 | { |
c19d1205 ZW |
10082 | constraint (inst.operands[0].reg > 7 |
10083 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
10084 | constraint (inst.instruction != T_MNEM_ldmia |
10085 | && inst.instruction != T_MNEM_stmia, | |
10086 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 10087 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 10088 | { |
c19d1205 ZW |
10089 | if (!inst.operands[0].writeback) |
10090 | as_warn (_("this instruction will write back the base register")); | |
10091 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
10092 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 10093 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 10094 | inst.operands[0].reg); |
f03698e6 | 10095 | } |
c19d1205 | 10096 | else |
90e4755a | 10097 | { |
c19d1205 ZW |
10098 | if (!inst.operands[0].writeback |
10099 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
10100 | as_warn (_("this instruction will write back the base register")); | |
10101 | else if (inst.operands[0].writeback | |
10102 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
10103 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
10104 | } |
10105 | ||
c19d1205 ZW |
10106 | inst.instruction = THUMB_OP16 (inst.instruction); |
10107 | inst.instruction |= inst.operands[0].reg << 8; | |
10108 | inst.instruction |= inst.operands[1].imm; | |
10109 | } | |
10110 | } | |
e28cd48c | 10111 | |
c19d1205 ZW |
10112 | static void |
10113 | do_t_ldrex (void) | |
10114 | { | |
10115 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
10116 | || inst.operands[1].postind || inst.operands[1].writeback | |
10117 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
10118 | || inst.operands[1].negative, | |
01cfc07f | 10119 | BAD_ADDR_MODE); |
e28cd48c | 10120 | |
5be8be5d DG |
10121 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
10122 | ||
c19d1205 ZW |
10123 | inst.instruction |= inst.operands[0].reg << 12; |
10124 | inst.instruction |= inst.operands[1].reg << 16; | |
10125 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
10126 | } | |
e28cd48c | 10127 | |
c19d1205 ZW |
10128 | static void |
10129 | do_t_ldrexd (void) | |
10130 | { | |
10131 | if (!inst.operands[1].present) | |
1cac9012 | 10132 | { |
c19d1205 ZW |
10133 | constraint (inst.operands[0].reg == REG_LR, |
10134 | _("r14 not allowed as first register " | |
10135 | "when second register is omitted")); | |
10136 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 10137 | } |
c19d1205 ZW |
10138 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
10139 | BAD_OVERLAP); | |
b99bd4ef | 10140 | |
c19d1205 ZW |
10141 | inst.instruction |= inst.operands[0].reg << 12; |
10142 | inst.instruction |= inst.operands[1].reg << 8; | |
10143 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10144 | } |
10145 | ||
10146 | static void | |
c19d1205 | 10147 | do_t_ldst (void) |
b99bd4ef | 10148 | { |
0110f2b8 PB |
10149 | unsigned long opcode; |
10150 | int Rn; | |
10151 | ||
e07e6e58 NC |
10152 | if (inst.operands[0].isreg |
10153 | && !inst.operands[0].preind | |
10154 | && inst.operands[0].reg == REG_PC) | |
10155 | set_it_insn_type_last (); | |
10156 | ||
0110f2b8 | 10157 | opcode = inst.instruction; |
c19d1205 | 10158 | if (unified_syntax) |
b99bd4ef | 10159 | { |
53365c0d PB |
10160 | if (!inst.operands[1].isreg) |
10161 | { | |
10162 | if (opcode <= 0xffff) | |
10163 | inst.instruction = THUMB_OP32 (opcode); | |
10164 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
10165 | return; | |
10166 | } | |
0110f2b8 PB |
10167 | if (inst.operands[1].isreg |
10168 | && !inst.operands[1].writeback | |
c19d1205 ZW |
10169 | && !inst.operands[1].shifted && !inst.operands[1].postind |
10170 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
10171 | && opcode <= 0xffff |
10172 | && inst.size_req != 4) | |
c19d1205 | 10173 | { |
0110f2b8 PB |
10174 | /* Insn may have a 16-bit form. */ |
10175 | Rn = inst.operands[1].reg; | |
10176 | if (inst.operands[1].immisreg) | |
10177 | { | |
10178 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 10179 | /* [Rn, Rik] */ |
0110f2b8 PB |
10180 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
10181 | goto op16; | |
5be8be5d DG |
10182 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
10183 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
10184 | } |
10185 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
10186 | && opcode != T_MNEM_ldrsb) | |
10187 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
10188 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
10189 | { | |
10190 | /* [Rn, #const] */ | |
10191 | if (Rn > 7) | |
10192 | { | |
10193 | if (Rn == REG_PC) | |
10194 | { | |
10195 | if (inst.reloc.pc_rel) | |
10196 | opcode = T_MNEM_ldr_pc2; | |
10197 | else | |
10198 | opcode = T_MNEM_ldr_pc; | |
10199 | } | |
10200 | else | |
10201 | { | |
10202 | if (opcode == T_MNEM_ldr) | |
10203 | opcode = T_MNEM_ldr_sp; | |
10204 | else | |
10205 | opcode = T_MNEM_str_sp; | |
10206 | } | |
10207 | inst.instruction = inst.operands[0].reg << 8; | |
10208 | } | |
10209 | else | |
10210 | { | |
10211 | inst.instruction = inst.operands[0].reg; | |
10212 | inst.instruction |= inst.operands[1].reg << 3; | |
10213 | } | |
10214 | inst.instruction |= THUMB_OP16 (opcode); | |
10215 | if (inst.size_req == 2) | |
10216 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10217 | else | |
10218 | inst.relax = opcode; | |
10219 | return; | |
10220 | } | |
c19d1205 | 10221 | } |
0110f2b8 | 10222 | /* Definitely a 32-bit variant. */ |
5be8be5d DG |
10223 | |
10224 | /* Do some validations regarding addressing modes. */ | |
10225 | if (inst.operands[1].immisreg && opcode != T_MNEM_ldr | |
10226 | && opcode != T_MNEM_str) | |
10227 | reject_bad_reg (inst.operands[1].imm); | |
10228 | ||
0110f2b8 | 10229 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
10230 | inst.instruction |= inst.operands[0].reg << 12; |
10231 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
10232 | return; |
10233 | } | |
10234 | ||
c19d1205 ZW |
10235 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
10236 | ||
10237 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 10238 | { |
c19d1205 ZW |
10239 | /* Only [Rn,Rm] is acceptable. */ |
10240 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
10241 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
10242 | || inst.operands[1].postind || inst.operands[1].shifted | |
10243 | || inst.operands[1].negative, | |
10244 | _("Thumb does not support this addressing mode")); | |
10245 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10246 | goto op16; | |
b99bd4ef | 10247 | } |
5f4273c7 | 10248 | |
c19d1205 ZW |
10249 | inst.instruction = THUMB_OP16 (inst.instruction); |
10250 | if (!inst.operands[1].isreg) | |
10251 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
10252 | return; | |
b99bd4ef | 10253 | |
c19d1205 ZW |
10254 | constraint (!inst.operands[1].preind |
10255 | || inst.operands[1].shifted | |
10256 | || inst.operands[1].writeback, | |
10257 | _("Thumb does not support this addressing mode")); | |
10258 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 10259 | { |
c19d1205 ZW |
10260 | constraint (inst.instruction & 0x0600, |
10261 | _("byte or halfword not valid for base register")); | |
10262 | constraint (inst.operands[1].reg == REG_PC | |
10263 | && !(inst.instruction & THUMB_LOAD_BIT), | |
10264 | _("r15 based store not allowed")); | |
10265 | constraint (inst.operands[1].immisreg, | |
10266 | _("invalid base register for register offset")); | |
b99bd4ef | 10267 | |
c19d1205 ZW |
10268 | if (inst.operands[1].reg == REG_PC) |
10269 | inst.instruction = T_OPCODE_LDR_PC; | |
10270 | else if (inst.instruction & THUMB_LOAD_BIT) | |
10271 | inst.instruction = T_OPCODE_LDR_SP; | |
10272 | else | |
10273 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 10274 | |
c19d1205 ZW |
10275 | inst.instruction |= inst.operands[0].reg << 8; |
10276 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10277 | return; | |
10278 | } | |
90e4755a | 10279 | |
c19d1205 ZW |
10280 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
10281 | if (!inst.operands[1].immisreg) | |
10282 | { | |
10283 | /* Immediate offset. */ | |
10284 | inst.instruction |= inst.operands[0].reg; | |
10285 | inst.instruction |= inst.operands[1].reg << 3; | |
10286 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10287 | return; | |
10288 | } | |
90e4755a | 10289 | |
c19d1205 ZW |
10290 | /* Register offset. */ |
10291 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
10292 | constraint (inst.operands[1].negative, | |
10293 | _("Thumb does not support this addressing mode")); | |
90e4755a | 10294 | |
c19d1205 ZW |
10295 | op16: |
10296 | switch (inst.instruction) | |
10297 | { | |
10298 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
10299 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
10300 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
10301 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
10302 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
10303 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
10304 | case 0x5600 /* ldrsb */: | |
10305 | case 0x5e00 /* ldrsh */: break; | |
10306 | default: abort (); | |
10307 | } | |
90e4755a | 10308 | |
c19d1205 ZW |
10309 | inst.instruction |= inst.operands[0].reg; |
10310 | inst.instruction |= inst.operands[1].reg << 3; | |
10311 | inst.instruction |= inst.operands[1].imm << 6; | |
10312 | } | |
90e4755a | 10313 | |
c19d1205 ZW |
10314 | static void |
10315 | do_t_ldstd (void) | |
10316 | { | |
10317 | if (!inst.operands[1].present) | |
b99bd4ef | 10318 | { |
c19d1205 ZW |
10319 | inst.operands[1].reg = inst.operands[0].reg + 1; |
10320 | constraint (inst.operands[0].reg == REG_LR, | |
10321 | _("r14 not allowed here")); | |
b99bd4ef | 10322 | } |
c19d1205 ZW |
10323 | inst.instruction |= inst.operands[0].reg << 12; |
10324 | inst.instruction |= inst.operands[1].reg << 8; | |
10325 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
10326 | } |
10327 | ||
c19d1205 ZW |
10328 | static void |
10329 | do_t_ldstt (void) | |
10330 | { | |
10331 | inst.instruction |= inst.operands[0].reg << 12; | |
10332 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
10333 | } | |
a737bd4d | 10334 | |
b99bd4ef | 10335 | static void |
c19d1205 | 10336 | do_t_mla (void) |
b99bd4ef | 10337 | { |
fdfde340 | 10338 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 10339 | |
fdfde340 JM |
10340 | Rd = inst.operands[0].reg; |
10341 | Rn = inst.operands[1].reg; | |
10342 | Rm = inst.operands[2].reg; | |
10343 | Ra = inst.operands[3].reg; | |
10344 | ||
10345 | reject_bad_reg (Rd); | |
10346 | reject_bad_reg (Rn); | |
10347 | reject_bad_reg (Rm); | |
10348 | reject_bad_reg (Ra); | |
10349 | ||
10350 | inst.instruction |= Rd << 8; | |
10351 | inst.instruction |= Rn << 16; | |
10352 | inst.instruction |= Rm; | |
10353 | inst.instruction |= Ra << 12; | |
c19d1205 | 10354 | } |
b99bd4ef | 10355 | |
c19d1205 ZW |
10356 | static void |
10357 | do_t_mlal (void) | |
10358 | { | |
fdfde340 JM |
10359 | unsigned RdLo, RdHi, Rn, Rm; |
10360 | ||
10361 | RdLo = inst.operands[0].reg; | |
10362 | RdHi = inst.operands[1].reg; | |
10363 | Rn = inst.operands[2].reg; | |
10364 | Rm = inst.operands[3].reg; | |
10365 | ||
10366 | reject_bad_reg (RdLo); | |
10367 | reject_bad_reg (RdHi); | |
10368 | reject_bad_reg (Rn); | |
10369 | reject_bad_reg (Rm); | |
10370 | ||
10371 | inst.instruction |= RdLo << 12; | |
10372 | inst.instruction |= RdHi << 8; | |
10373 | inst.instruction |= Rn << 16; | |
10374 | inst.instruction |= Rm; | |
c19d1205 | 10375 | } |
b99bd4ef | 10376 | |
c19d1205 ZW |
10377 | static void |
10378 | do_t_mov_cmp (void) | |
10379 | { | |
fdfde340 JM |
10380 | unsigned Rn, Rm; |
10381 | ||
10382 | Rn = inst.operands[0].reg; | |
10383 | Rm = inst.operands[1].reg; | |
10384 | ||
e07e6e58 NC |
10385 | if (Rn == REG_PC) |
10386 | set_it_insn_type_last (); | |
10387 | ||
c19d1205 | 10388 | if (unified_syntax) |
b99bd4ef | 10389 | { |
c19d1205 ZW |
10390 | int r0off = (inst.instruction == T_MNEM_mov |
10391 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 10392 | unsigned long opcode; |
3d388997 PB |
10393 | bfd_boolean narrow; |
10394 | bfd_boolean low_regs; | |
10395 | ||
fdfde340 | 10396 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 10397 | opcode = inst.instruction; |
e07e6e58 | 10398 | if (in_it_block ()) |
0110f2b8 | 10399 | narrow = opcode != T_MNEM_movs; |
3d388997 | 10400 | else |
0110f2b8 | 10401 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
10402 | if (inst.size_req == 4 |
10403 | || inst.operands[1].shifted) | |
10404 | narrow = FALSE; | |
10405 | ||
efd81785 PB |
10406 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
10407 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
10408 | && !inst.operands[1].shifted | |
fdfde340 JM |
10409 | && Rn == REG_PC |
10410 | && Rm == REG_LR) | |
efd81785 PB |
10411 | { |
10412 | inst.instruction = T2_SUBS_PC_LR; | |
10413 | return; | |
10414 | } | |
10415 | ||
fdfde340 JM |
10416 | if (opcode == T_MNEM_cmp) |
10417 | { | |
10418 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
10419 | if (narrow) |
10420 | { | |
10421 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
10422 | but valid. */ | |
10423 | warn_deprecated_sp (Rm); | |
10424 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
10425 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
10426 | tools reject R15, so we do too. */ | |
10427 | constraint (Rm == REG_PC, BAD_PC); | |
10428 | } | |
10429 | else | |
10430 | reject_bad_reg (Rm); | |
fdfde340 JM |
10431 | } |
10432 | else if (opcode == T_MNEM_mov | |
10433 | || opcode == T_MNEM_movs) | |
10434 | { | |
10435 | if (inst.operands[1].isreg) | |
10436 | { | |
10437 | if (opcode == T_MNEM_movs) | |
10438 | { | |
10439 | reject_bad_reg (Rn); | |
10440 | reject_bad_reg (Rm); | |
10441 | } | |
76fa04a4 MGD |
10442 | else if (narrow) |
10443 | { | |
10444 | /* This is mov.n. */ | |
10445 | if ((Rn == REG_SP || Rn == REG_PC) | |
10446 | && (Rm == REG_SP || Rm == REG_PC)) | |
10447 | { | |
10448 | as_warn (_("Use of r%u as a source register is " | |
10449 | "deprecated when r%u is the destination " | |
10450 | "register."), Rm, Rn); | |
10451 | } | |
10452 | } | |
10453 | else | |
10454 | { | |
10455 | /* This is mov.w. */ | |
10456 | constraint (Rn == REG_PC, BAD_PC); | |
10457 | constraint (Rm == REG_PC, BAD_PC); | |
10458 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
10459 | } | |
fdfde340 JM |
10460 | } |
10461 | else | |
10462 | reject_bad_reg (Rn); | |
10463 | } | |
10464 | ||
c19d1205 ZW |
10465 | if (!inst.operands[1].isreg) |
10466 | { | |
0110f2b8 | 10467 | /* Immediate operand. */ |
e07e6e58 | 10468 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
10469 | narrow = 0; |
10470 | if (low_regs && narrow) | |
10471 | { | |
10472 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 10473 | inst.instruction |= Rn << 8; |
0110f2b8 PB |
10474 | if (inst.size_req == 2) |
10475 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
10476 | else | |
10477 | inst.relax = opcode; | |
10478 | } | |
10479 | else | |
10480 | { | |
10481 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10482 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10483 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
10484 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
10485 | } | |
c19d1205 | 10486 | } |
728ca7c9 PB |
10487 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
10488 | && (inst.instruction == T_MNEM_mov | |
10489 | || inst.instruction == T_MNEM_movs)) | |
10490 | { | |
10491 | /* Register shifts are encoded as separate shift instructions. */ | |
10492 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
10493 | ||
e07e6e58 | 10494 | if (in_it_block ()) |
728ca7c9 PB |
10495 | narrow = !flags; |
10496 | else | |
10497 | narrow = flags; | |
10498 | ||
10499 | if (inst.size_req == 4) | |
10500 | narrow = FALSE; | |
10501 | ||
10502 | if (!low_regs || inst.operands[1].imm > 7) | |
10503 | narrow = FALSE; | |
10504 | ||
fdfde340 | 10505 | if (Rn != Rm) |
728ca7c9 PB |
10506 | narrow = FALSE; |
10507 | ||
10508 | switch (inst.operands[1].shift_kind) | |
10509 | { | |
10510 | case SHIFT_LSL: | |
10511 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
10512 | break; | |
10513 | case SHIFT_ASR: | |
10514 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
10515 | break; | |
10516 | case SHIFT_LSR: | |
10517 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
10518 | break; | |
10519 | case SHIFT_ROR: | |
10520 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
10521 | break; | |
10522 | default: | |
5f4273c7 | 10523 | abort (); |
728ca7c9 PB |
10524 | } |
10525 | ||
10526 | inst.instruction = opcode; | |
10527 | if (narrow) | |
10528 | { | |
fdfde340 | 10529 | inst.instruction |= Rn; |
728ca7c9 PB |
10530 | inst.instruction |= inst.operands[1].imm << 3; |
10531 | } | |
10532 | else | |
10533 | { | |
10534 | if (flags) | |
10535 | inst.instruction |= CONDS_BIT; | |
10536 | ||
fdfde340 JM |
10537 | inst.instruction |= Rn << 8; |
10538 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
10539 | inst.instruction |= inst.operands[1].imm; |
10540 | } | |
10541 | } | |
3d388997 | 10542 | else if (!narrow) |
c19d1205 | 10543 | { |
728ca7c9 PB |
10544 | /* Some mov with immediate shift have narrow variants. |
10545 | Register shifts are handled above. */ | |
10546 | if (low_regs && inst.operands[1].shifted | |
10547 | && (inst.instruction == T_MNEM_mov | |
10548 | || inst.instruction == T_MNEM_movs)) | |
10549 | { | |
e07e6e58 | 10550 | if (in_it_block ()) |
728ca7c9 PB |
10551 | narrow = (inst.instruction == T_MNEM_mov); |
10552 | else | |
10553 | narrow = (inst.instruction == T_MNEM_movs); | |
10554 | } | |
10555 | ||
10556 | if (narrow) | |
10557 | { | |
10558 | switch (inst.operands[1].shift_kind) | |
10559 | { | |
10560 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10561 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
10562 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
10563 | default: narrow = FALSE; break; | |
10564 | } | |
10565 | } | |
10566 | ||
10567 | if (narrow) | |
10568 | { | |
fdfde340 JM |
10569 | inst.instruction |= Rn; |
10570 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
10571 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10572 | } | |
10573 | else | |
10574 | { | |
10575 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10576 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
10577 | encode_thumb32_shifted_operand (1); |
10578 | } | |
c19d1205 ZW |
10579 | } |
10580 | else | |
10581 | switch (inst.instruction) | |
10582 | { | |
10583 | case T_MNEM_mov: | |
10584 | inst.instruction = T_OPCODE_MOV_HR; | |
fdfde340 JM |
10585 | inst.instruction |= (Rn & 0x8) << 4; |
10586 | inst.instruction |= (Rn & 0x7); | |
10587 | inst.instruction |= Rm << 3; | |
c19d1205 | 10588 | break; |
b99bd4ef | 10589 | |
c19d1205 ZW |
10590 | case T_MNEM_movs: |
10591 | /* We know we have low registers at this point. | |
941a8a52 MGD |
10592 | Generate LSLS Rd, Rs, #0. */ |
10593 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
10594 | inst.instruction |= Rn; |
10595 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10596 | break; |
10597 | ||
10598 | case T_MNEM_cmp: | |
3d388997 | 10599 | if (low_regs) |
c19d1205 ZW |
10600 | { |
10601 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
10602 | inst.instruction |= Rn; |
10603 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10604 | } |
10605 | else | |
10606 | { | |
10607 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
10608 | inst.instruction |= (Rn & 0x8) << 4; |
10609 | inst.instruction |= (Rn & 0x7); | |
10610 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10611 | } |
10612 | break; | |
10613 | } | |
b99bd4ef NC |
10614 | return; |
10615 | } | |
10616 | ||
c19d1205 | 10617 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
10618 | |
10619 | /* PR 10443: Do not silently ignore shifted operands. */ | |
10620 | constraint (inst.operands[1].shifted, | |
10621 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
10622 | ||
c19d1205 | 10623 | if (inst.operands[1].isreg) |
b99bd4ef | 10624 | { |
fdfde340 | 10625 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 10626 | { |
c19d1205 ZW |
10627 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
10628 | since a MOV instruction produces unpredictable results. */ | |
10629 | if (inst.instruction == T_OPCODE_MOV_I8) | |
10630 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 10631 | else |
c19d1205 | 10632 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 10633 | |
fdfde340 JM |
10634 | inst.instruction |= Rn; |
10635 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
10636 | } |
10637 | else | |
10638 | { | |
c19d1205 ZW |
10639 | if (inst.instruction == T_OPCODE_MOV_I8) |
10640 | inst.instruction = T_OPCODE_MOV_HR; | |
10641 | else | |
10642 | inst.instruction = T_OPCODE_CMP_HR; | |
10643 | do_t_cpy (); | |
b99bd4ef NC |
10644 | } |
10645 | } | |
c19d1205 | 10646 | else |
b99bd4ef | 10647 | { |
fdfde340 | 10648 | constraint (Rn > 7, |
c19d1205 | 10649 | _("only lo regs allowed with immediate")); |
fdfde340 | 10650 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
10651 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
10652 | } | |
10653 | } | |
b99bd4ef | 10654 | |
c19d1205 ZW |
10655 | static void |
10656 | do_t_mov16 (void) | |
10657 | { | |
fdfde340 | 10658 | unsigned Rd; |
b6895b4f PB |
10659 | bfd_vma imm; |
10660 | bfd_boolean top; | |
10661 | ||
10662 | top = (inst.instruction & 0x00800000) != 0; | |
10663 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
10664 | { | |
10665 | constraint (top, _(":lower16: not allowed this instruction")); | |
10666 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
10667 | } | |
10668 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
10669 | { | |
10670 | constraint (!top, _(":upper16: not allowed this instruction")); | |
10671 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
10672 | } | |
10673 | ||
fdfde340 JM |
10674 | Rd = inst.operands[0].reg; |
10675 | reject_bad_reg (Rd); | |
10676 | ||
10677 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
10678 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
10679 | { | |
10680 | imm = inst.reloc.exp.X_add_number; | |
10681 | inst.instruction |= (imm & 0xf000) << 4; | |
10682 | inst.instruction |= (imm & 0x0800) << 15; | |
10683 | inst.instruction |= (imm & 0x0700) << 4; | |
10684 | inst.instruction |= (imm & 0x00ff); | |
10685 | } | |
c19d1205 | 10686 | } |
b99bd4ef | 10687 | |
c19d1205 ZW |
10688 | static void |
10689 | do_t_mvn_tst (void) | |
10690 | { | |
fdfde340 | 10691 | unsigned Rn, Rm; |
c921be7d | 10692 | |
fdfde340 JM |
10693 | Rn = inst.operands[0].reg; |
10694 | Rm = inst.operands[1].reg; | |
10695 | ||
10696 | if (inst.instruction == T_MNEM_cmp | |
10697 | || inst.instruction == T_MNEM_cmn) | |
10698 | constraint (Rn == REG_PC, BAD_PC); | |
10699 | else | |
10700 | reject_bad_reg (Rn); | |
10701 | reject_bad_reg (Rm); | |
10702 | ||
c19d1205 ZW |
10703 | if (unified_syntax) |
10704 | { | |
10705 | int r0off = (inst.instruction == T_MNEM_mvn | |
10706 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
10707 | bfd_boolean narrow; |
10708 | ||
10709 | if (inst.size_req == 4 | |
10710 | || inst.instruction > 0xffff | |
10711 | || inst.operands[1].shifted | |
fdfde340 | 10712 | || Rn > 7 || Rm > 7) |
3d388997 PB |
10713 | narrow = FALSE; |
10714 | else if (inst.instruction == T_MNEM_cmn) | |
10715 | narrow = TRUE; | |
10716 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10717 | narrow = !in_it_block (); |
3d388997 | 10718 | else |
e07e6e58 | 10719 | narrow = in_it_block (); |
3d388997 | 10720 | |
c19d1205 | 10721 | if (!inst.operands[1].isreg) |
b99bd4ef | 10722 | { |
c19d1205 ZW |
10723 | /* For an immediate, we always generate a 32-bit opcode; |
10724 | section relaxation will shrink it later if possible. */ | |
10725 | if (inst.instruction < 0xffff) | |
10726 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10727 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10728 | inst.instruction |= Rn << r0off; |
c19d1205 | 10729 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 10730 | } |
c19d1205 | 10731 | else |
b99bd4ef | 10732 | { |
c19d1205 | 10733 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 10734 | if (narrow) |
b99bd4ef | 10735 | { |
c19d1205 | 10736 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10737 | inst.instruction |= Rn; |
10738 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10739 | } |
c19d1205 | 10740 | else |
b99bd4ef | 10741 | { |
c19d1205 ZW |
10742 | constraint (inst.operands[1].shifted |
10743 | && inst.operands[1].immisreg, | |
10744 | _("shift must be constant")); | |
10745 | if (inst.instruction < 0xffff) | |
10746 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10747 | inst.instruction |= Rn << r0off; |
c19d1205 | 10748 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 10749 | } |
b99bd4ef NC |
10750 | } |
10751 | } | |
10752 | else | |
10753 | { | |
c19d1205 ZW |
10754 | constraint (inst.instruction > 0xffff |
10755 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
10756 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
10757 | _("unshifted register required")); | |
fdfde340 | 10758 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10759 | BAD_HIREG); |
b99bd4ef | 10760 | |
c19d1205 | 10761 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10762 | inst.instruction |= Rn; |
10763 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10764 | } |
b99bd4ef NC |
10765 | } |
10766 | ||
b05fe5cf | 10767 | static void |
c19d1205 | 10768 | do_t_mrs (void) |
b05fe5cf | 10769 | { |
fdfde340 | 10770 | unsigned Rd; |
037e8744 JB |
10771 | |
10772 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
10773 | return; | |
10774 | ||
90ec0d68 MGD |
10775 | Rd = inst.operands[0].reg; |
10776 | reject_bad_reg (Rd); | |
10777 | inst.instruction |= Rd << 8; | |
10778 | ||
10779 | if (inst.operands[1].isreg) | |
62b3e311 | 10780 | { |
90ec0d68 MGD |
10781 | unsigned br = inst.operands[1].reg; |
10782 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
10783 | as_bad (_("bad register for mrs")); | |
10784 | ||
10785 | inst.instruction |= br & (0xf << 16); | |
10786 | inst.instruction |= (br & 0x300) >> 4; | |
10787 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
10788 | } |
10789 | else | |
10790 | { | |
90ec0d68 | 10791 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 10792 | |
90ec0d68 MGD |
10793 | if (flags == 0) |
10794 | { | |
10795 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), | |
10796 | _("selected processor does not support " | |
10797 | "requested special purpose register")); | |
10798 | } | |
10799 | else | |
10800 | { | |
10801 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10802 | _("selected processor does not support " | |
10803 | "requested special purpose register")); | |
10804 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
10805 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
10806 | _("'CPSR' or 'SPSR' expected")); | |
10807 | } | |
fdfde340 | 10808 | |
90ec0d68 MGD |
10809 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10810 | inst.instruction |= inst.operands[1].imm & 0xff; | |
10811 | inst.instruction |= 0xf0000; | |
10812 | } | |
c19d1205 | 10813 | } |
b05fe5cf | 10814 | |
c19d1205 ZW |
10815 | static void |
10816 | do_t_msr (void) | |
10817 | { | |
62b3e311 | 10818 | int flags; |
fdfde340 | 10819 | unsigned Rn; |
62b3e311 | 10820 | |
037e8744 JB |
10821 | if (do_vfp_nsyn_msr () == SUCCESS) |
10822 | return; | |
10823 | ||
c19d1205 ZW |
10824 | constraint (!inst.operands[1].isreg, |
10825 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
10826 | |
10827 | if (inst.operands[0].isreg) | |
10828 | flags = (int)(inst.operands[0].reg); | |
10829 | else | |
10830 | flags = inst.operands[0].imm; | |
10831 | ||
62b3e311 PB |
10832 | if (flags & ~0xff) |
10833 | { | |
10834 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10835 | _("selected processor does not support " | |
10836 | "requested special purpose register")); | |
10837 | } | |
10838 | else | |
10839 | { | |
7e806470 | 10840 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10841 | _("selected processor does not support " |
10842 | "requested special purpose register")); | |
10843 | flags |= PSR_f; | |
10844 | } | |
c921be7d | 10845 | |
fdfde340 JM |
10846 | Rn = inst.operands[1].reg; |
10847 | reject_bad_reg (Rn); | |
10848 | ||
62b3e311 | 10849 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
10850 | inst.instruction |= (flags & 0xf0000) >> 8; |
10851 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 10852 | inst.instruction |= (flags & 0xff); |
fdfde340 | 10853 | inst.instruction |= Rn << 16; |
c19d1205 | 10854 | } |
b05fe5cf | 10855 | |
c19d1205 ZW |
10856 | static void |
10857 | do_t_mul (void) | |
10858 | { | |
17828f45 | 10859 | bfd_boolean narrow; |
fdfde340 | 10860 | unsigned Rd, Rn, Rm; |
17828f45 | 10861 | |
c19d1205 ZW |
10862 | if (!inst.operands[2].present) |
10863 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 10864 | |
fdfde340 JM |
10865 | Rd = inst.operands[0].reg; |
10866 | Rn = inst.operands[1].reg; | |
10867 | Rm = inst.operands[2].reg; | |
10868 | ||
17828f45 | 10869 | if (unified_syntax) |
b05fe5cf | 10870 | { |
17828f45 | 10871 | if (inst.size_req == 4 |
fdfde340 JM |
10872 | || (Rd != Rn |
10873 | && Rd != Rm) | |
10874 | || Rn > 7 | |
10875 | || Rm > 7) | |
17828f45 JM |
10876 | narrow = FALSE; |
10877 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 10878 | narrow = !in_it_block (); |
17828f45 | 10879 | else |
e07e6e58 | 10880 | narrow = in_it_block (); |
b05fe5cf | 10881 | } |
c19d1205 | 10882 | else |
b05fe5cf | 10883 | { |
17828f45 | 10884 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 10885 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10886 | BAD_HIREG); |
17828f45 JM |
10887 | narrow = TRUE; |
10888 | } | |
b05fe5cf | 10889 | |
17828f45 JM |
10890 | if (narrow) |
10891 | { | |
10892 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 10893 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 10894 | inst.instruction |= Rd; |
b05fe5cf | 10895 | |
fdfde340 JM |
10896 | if (Rd == Rn) |
10897 | inst.instruction |= Rm << 3; | |
10898 | else if (Rd == Rm) | |
10899 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
10900 | else |
10901 | constraint (1, _("dest must overlap one source register")); | |
10902 | } | |
17828f45 JM |
10903 | else |
10904 | { | |
e07e6e58 NC |
10905 | constraint (inst.instruction != T_MNEM_mul, |
10906 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
10907 | /* 32-bit MUL. */ |
10908 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10909 | inst.instruction |= Rd << 8; |
10910 | inst.instruction |= Rn << 16; | |
10911 | inst.instruction |= Rm << 0; | |
10912 | ||
10913 | reject_bad_reg (Rd); | |
10914 | reject_bad_reg (Rn); | |
10915 | reject_bad_reg (Rm); | |
17828f45 | 10916 | } |
c19d1205 | 10917 | } |
b05fe5cf | 10918 | |
c19d1205 ZW |
10919 | static void |
10920 | do_t_mull (void) | |
10921 | { | |
fdfde340 | 10922 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 10923 | |
fdfde340 JM |
10924 | RdLo = inst.operands[0].reg; |
10925 | RdHi = inst.operands[1].reg; | |
10926 | Rn = inst.operands[2].reg; | |
10927 | Rm = inst.operands[3].reg; | |
10928 | ||
10929 | reject_bad_reg (RdLo); | |
10930 | reject_bad_reg (RdHi); | |
10931 | reject_bad_reg (Rn); | |
10932 | reject_bad_reg (Rm); | |
10933 | ||
10934 | inst.instruction |= RdLo << 12; | |
10935 | inst.instruction |= RdHi << 8; | |
10936 | inst.instruction |= Rn << 16; | |
10937 | inst.instruction |= Rm; | |
10938 | ||
10939 | if (RdLo == RdHi) | |
c19d1205 ZW |
10940 | as_tsktsk (_("rdhi and rdlo must be different")); |
10941 | } | |
b05fe5cf | 10942 | |
c19d1205 ZW |
10943 | static void |
10944 | do_t_nop (void) | |
10945 | { | |
e07e6e58 NC |
10946 | set_it_insn_type (NEUTRAL_IT_INSN); |
10947 | ||
c19d1205 ZW |
10948 | if (unified_syntax) |
10949 | { | |
10950 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 10951 | { |
c19d1205 ZW |
10952 | inst.instruction = THUMB_OP32 (inst.instruction); |
10953 | inst.instruction |= inst.operands[0].imm; | |
10954 | } | |
10955 | else | |
10956 | { | |
bc2d1808 NC |
10957 | /* PR9722: Check for Thumb2 availability before |
10958 | generating a thumb2 nop instruction. */ | |
afa62d5e | 10959 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
10960 | { |
10961 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10962 | inst.instruction |= inst.operands[0].imm << 4; | |
10963 | } | |
10964 | else | |
10965 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
10966 | } |
10967 | } | |
10968 | else | |
10969 | { | |
10970 | constraint (inst.operands[0].present, | |
10971 | _("Thumb does not support NOP with hints")); | |
10972 | inst.instruction = 0x46c0; | |
10973 | } | |
10974 | } | |
b05fe5cf | 10975 | |
c19d1205 ZW |
10976 | static void |
10977 | do_t_neg (void) | |
10978 | { | |
10979 | if (unified_syntax) | |
10980 | { | |
3d388997 PB |
10981 | bfd_boolean narrow; |
10982 | ||
10983 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10984 | narrow = !in_it_block (); |
3d388997 | 10985 | else |
e07e6e58 | 10986 | narrow = in_it_block (); |
3d388997 PB |
10987 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10988 | narrow = FALSE; | |
10989 | if (inst.size_req == 4) | |
10990 | narrow = FALSE; | |
10991 | ||
10992 | if (!narrow) | |
c19d1205 ZW |
10993 | { |
10994 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10995 | inst.instruction |= inst.operands[0].reg << 8; | |
10996 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
10997 | } |
10998 | else | |
10999 | { | |
c19d1205 ZW |
11000 | inst.instruction = THUMB_OP16 (inst.instruction); |
11001 | inst.instruction |= inst.operands[0].reg; | |
11002 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
11003 | } |
11004 | } | |
11005 | else | |
11006 | { | |
c19d1205 ZW |
11007 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
11008 | BAD_HIREG); | |
11009 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
11010 | ||
11011 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11012 | inst.instruction |= inst.operands[0].reg; | |
11013 | inst.instruction |= inst.operands[1].reg << 3; | |
11014 | } | |
11015 | } | |
11016 | ||
1c444d06 JM |
11017 | static void |
11018 | do_t_orn (void) | |
11019 | { | |
11020 | unsigned Rd, Rn; | |
11021 | ||
11022 | Rd = inst.operands[0].reg; | |
11023 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
11024 | ||
fdfde340 JM |
11025 | reject_bad_reg (Rd); |
11026 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
11027 | reject_bad_reg (Rn); | |
11028 | ||
1c444d06 JM |
11029 | inst.instruction |= Rd << 8; |
11030 | inst.instruction |= Rn << 16; | |
11031 | ||
11032 | if (!inst.operands[2].isreg) | |
11033 | { | |
11034 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11035 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
11036 | } | |
11037 | else | |
11038 | { | |
11039 | unsigned Rm; | |
11040 | ||
11041 | Rm = inst.operands[2].reg; | |
fdfde340 | 11042 | reject_bad_reg (Rm); |
1c444d06 JM |
11043 | |
11044 | constraint (inst.operands[2].shifted | |
11045 | && inst.operands[2].immisreg, | |
11046 | _("shift must be constant")); | |
11047 | encode_thumb32_shifted_operand (2); | |
11048 | } | |
11049 | } | |
11050 | ||
c19d1205 ZW |
11051 | static void |
11052 | do_t_pkhbt (void) | |
11053 | { | |
fdfde340 JM |
11054 | unsigned Rd, Rn, Rm; |
11055 | ||
11056 | Rd = inst.operands[0].reg; | |
11057 | Rn = inst.operands[1].reg; | |
11058 | Rm = inst.operands[2].reg; | |
11059 | ||
11060 | reject_bad_reg (Rd); | |
11061 | reject_bad_reg (Rn); | |
11062 | reject_bad_reg (Rm); | |
11063 | ||
11064 | inst.instruction |= Rd << 8; | |
11065 | inst.instruction |= Rn << 16; | |
11066 | inst.instruction |= Rm; | |
c19d1205 ZW |
11067 | if (inst.operands[3].present) |
11068 | { | |
11069 | unsigned int val = inst.reloc.exp.X_add_number; | |
11070 | constraint (inst.reloc.exp.X_op != O_constant, | |
11071 | _("expression too complex")); | |
11072 | inst.instruction |= (val & 0x1c) << 10; | |
11073 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 11074 | } |
c19d1205 | 11075 | } |
b05fe5cf | 11076 | |
c19d1205 ZW |
11077 | static void |
11078 | do_t_pkhtb (void) | |
11079 | { | |
11080 | if (!inst.operands[3].present) | |
1ef52f49 NC |
11081 | { |
11082 | unsigned Rtmp; | |
11083 | ||
11084 | inst.instruction &= ~0x00000020; | |
11085 | ||
11086 | /* PR 10168. Swap the Rm and Rn registers. */ | |
11087 | Rtmp = inst.operands[1].reg; | |
11088 | inst.operands[1].reg = inst.operands[2].reg; | |
11089 | inst.operands[2].reg = Rtmp; | |
11090 | } | |
c19d1205 | 11091 | do_t_pkhbt (); |
b05fe5cf ZW |
11092 | } |
11093 | ||
c19d1205 ZW |
11094 | static void |
11095 | do_t_pld (void) | |
11096 | { | |
fdfde340 JM |
11097 | if (inst.operands[0].immisreg) |
11098 | reject_bad_reg (inst.operands[0].imm); | |
11099 | ||
c19d1205 ZW |
11100 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
11101 | } | |
b05fe5cf | 11102 | |
c19d1205 ZW |
11103 | static void |
11104 | do_t_push_pop (void) | |
b99bd4ef | 11105 | { |
e9f89963 | 11106 | unsigned mask; |
5f4273c7 | 11107 | |
c19d1205 ZW |
11108 | constraint (inst.operands[0].writeback, |
11109 | _("push/pop do not support {reglist}^")); | |
11110 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
11111 | _("expression too complex")); | |
b99bd4ef | 11112 | |
e9f89963 PB |
11113 | mask = inst.operands[0].imm; |
11114 | if ((mask & ~0xff) == 0) | |
3c707909 | 11115 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
c19d1205 | 11116 | else if ((inst.instruction == T_MNEM_push |
e9f89963 | 11117 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 11118 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 11119 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 11120 | { |
c19d1205 ZW |
11121 | inst.instruction = THUMB_OP16 (inst.instruction); |
11122 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 11123 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
11124 | } |
11125 | else if (unified_syntax) | |
11126 | { | |
3c707909 | 11127 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 11128 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
11129 | } |
11130 | else | |
11131 | { | |
11132 | inst.error = _("invalid register list to push/pop instruction"); | |
11133 | return; | |
11134 | } | |
c19d1205 | 11135 | } |
b99bd4ef | 11136 | |
c19d1205 ZW |
11137 | static void |
11138 | do_t_rbit (void) | |
11139 | { | |
fdfde340 JM |
11140 | unsigned Rd, Rm; |
11141 | ||
11142 | Rd = inst.operands[0].reg; | |
11143 | Rm = inst.operands[1].reg; | |
11144 | ||
11145 | reject_bad_reg (Rd); | |
11146 | reject_bad_reg (Rm); | |
11147 | ||
11148 | inst.instruction |= Rd << 8; | |
11149 | inst.instruction |= Rm << 16; | |
11150 | inst.instruction |= Rm; | |
c19d1205 | 11151 | } |
b99bd4ef | 11152 | |
c19d1205 ZW |
11153 | static void |
11154 | do_t_rev (void) | |
11155 | { | |
fdfde340 JM |
11156 | unsigned Rd, Rm; |
11157 | ||
11158 | Rd = inst.operands[0].reg; | |
11159 | Rm = inst.operands[1].reg; | |
11160 | ||
11161 | reject_bad_reg (Rd); | |
11162 | reject_bad_reg (Rm); | |
11163 | ||
11164 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
11165 | && inst.size_req != 4) |
11166 | { | |
11167 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
11168 | inst.instruction |= Rd; |
11169 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11170 | } |
11171 | else if (unified_syntax) | |
11172 | { | |
11173 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11174 | inst.instruction |= Rd << 8; |
11175 | inst.instruction |= Rm << 16; | |
11176 | inst.instruction |= Rm; | |
c19d1205 ZW |
11177 | } |
11178 | else | |
11179 | inst.error = BAD_HIREG; | |
11180 | } | |
b99bd4ef | 11181 | |
1c444d06 JM |
11182 | static void |
11183 | do_t_rrx (void) | |
11184 | { | |
11185 | unsigned Rd, Rm; | |
11186 | ||
11187 | Rd = inst.operands[0].reg; | |
11188 | Rm = inst.operands[1].reg; | |
11189 | ||
fdfde340 JM |
11190 | reject_bad_reg (Rd); |
11191 | reject_bad_reg (Rm); | |
c921be7d | 11192 | |
1c444d06 JM |
11193 | inst.instruction |= Rd << 8; |
11194 | inst.instruction |= Rm; | |
11195 | } | |
11196 | ||
c19d1205 ZW |
11197 | static void |
11198 | do_t_rsb (void) | |
11199 | { | |
fdfde340 | 11200 | unsigned Rd, Rs; |
b99bd4ef | 11201 | |
c19d1205 ZW |
11202 | Rd = inst.operands[0].reg; |
11203 | Rs = (inst.operands[1].present | |
11204 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11205 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 11206 | |
fdfde340 JM |
11207 | reject_bad_reg (Rd); |
11208 | reject_bad_reg (Rs); | |
11209 | if (inst.operands[2].isreg) | |
11210 | reject_bad_reg (inst.operands[2].reg); | |
11211 | ||
c19d1205 ZW |
11212 | inst.instruction |= Rd << 8; |
11213 | inst.instruction |= Rs << 16; | |
11214 | if (!inst.operands[2].isreg) | |
11215 | { | |
026d3abb PB |
11216 | bfd_boolean narrow; |
11217 | ||
11218 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 11219 | narrow = !in_it_block (); |
026d3abb | 11220 | else |
e07e6e58 | 11221 | narrow = in_it_block (); |
026d3abb PB |
11222 | |
11223 | if (Rd > 7 || Rs > 7) | |
11224 | narrow = FALSE; | |
11225 | ||
11226 | if (inst.size_req == 4 || !unified_syntax) | |
11227 | narrow = FALSE; | |
11228 | ||
11229 | if (inst.reloc.exp.X_op != O_constant | |
11230 | || inst.reloc.exp.X_add_number != 0) | |
11231 | narrow = FALSE; | |
11232 | ||
11233 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
11234 | relaxation, but it doesn't seem worth the hassle. */ | |
11235 | if (narrow) | |
11236 | { | |
11237 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11238 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
11239 | inst.instruction |= Rs << 3; | |
11240 | inst.instruction |= Rd; | |
11241 | } | |
11242 | else | |
11243 | { | |
11244 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11245 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
11246 | } | |
c19d1205 ZW |
11247 | } |
11248 | else | |
11249 | encode_thumb32_shifted_operand (2); | |
11250 | } | |
b99bd4ef | 11251 | |
c19d1205 ZW |
11252 | static void |
11253 | do_t_setend (void) | |
11254 | { | |
e07e6e58 | 11255 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
11256 | if (inst.operands[0].imm) |
11257 | inst.instruction |= 0x8; | |
11258 | } | |
b99bd4ef | 11259 | |
c19d1205 ZW |
11260 | static void |
11261 | do_t_shift (void) | |
11262 | { | |
11263 | if (!inst.operands[1].present) | |
11264 | inst.operands[1].reg = inst.operands[0].reg; | |
11265 | ||
11266 | if (unified_syntax) | |
11267 | { | |
3d388997 PB |
11268 | bfd_boolean narrow; |
11269 | int shift_kind; | |
11270 | ||
11271 | switch (inst.instruction) | |
11272 | { | |
11273 | case T_MNEM_asr: | |
11274 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
11275 | case T_MNEM_lsl: | |
11276 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
11277 | case T_MNEM_lsr: | |
11278 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
11279 | case T_MNEM_ror: | |
11280 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
11281 | default: abort (); | |
11282 | } | |
11283 | ||
11284 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 11285 | narrow = !in_it_block (); |
3d388997 | 11286 | else |
e07e6e58 | 11287 | narrow = in_it_block (); |
3d388997 PB |
11288 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
11289 | narrow = FALSE; | |
11290 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
11291 | narrow = FALSE; | |
11292 | if (inst.operands[2].isreg | |
11293 | && (inst.operands[1].reg != inst.operands[0].reg | |
11294 | || inst.operands[2].reg > 7)) | |
11295 | narrow = FALSE; | |
11296 | if (inst.size_req == 4) | |
11297 | narrow = FALSE; | |
11298 | ||
fdfde340 JM |
11299 | reject_bad_reg (inst.operands[0].reg); |
11300 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 11301 | |
3d388997 | 11302 | if (!narrow) |
c19d1205 ZW |
11303 | { |
11304 | if (inst.operands[2].isreg) | |
b99bd4ef | 11305 | { |
fdfde340 | 11306 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
11307 | inst.instruction = THUMB_OP32 (inst.instruction); |
11308 | inst.instruction |= inst.operands[0].reg << 8; | |
11309 | inst.instruction |= inst.operands[1].reg << 16; | |
11310 | inst.instruction |= inst.operands[2].reg; | |
11311 | } | |
11312 | else | |
11313 | { | |
11314 | inst.operands[1].shifted = 1; | |
3d388997 | 11315 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
11316 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
11317 | ? T_MNEM_movs : T_MNEM_mov); | |
11318 | inst.instruction |= inst.operands[0].reg << 8; | |
11319 | encode_thumb32_shifted_operand (1); | |
11320 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
11321 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
11322 | } |
11323 | } | |
11324 | else | |
11325 | { | |
c19d1205 | 11326 | if (inst.operands[2].isreg) |
b99bd4ef | 11327 | { |
3d388997 | 11328 | switch (shift_kind) |
b99bd4ef | 11329 | { |
3d388997 PB |
11330 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
11331 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
11332 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
11333 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 11334 | default: abort (); |
b99bd4ef | 11335 | } |
5f4273c7 | 11336 | |
c19d1205 ZW |
11337 | inst.instruction |= inst.operands[0].reg; |
11338 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
11339 | } |
11340 | else | |
11341 | { | |
3d388997 | 11342 | switch (shift_kind) |
b99bd4ef | 11343 | { |
3d388997 PB |
11344 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
11345 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
11346 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 11347 | default: abort (); |
b99bd4ef | 11348 | } |
c19d1205 ZW |
11349 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
11350 | inst.instruction |= inst.operands[0].reg; | |
11351 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
11352 | } |
11353 | } | |
c19d1205 ZW |
11354 | } |
11355 | else | |
11356 | { | |
11357 | constraint (inst.operands[0].reg > 7 | |
11358 | || inst.operands[1].reg > 7, BAD_HIREG); | |
11359 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 11360 | |
c19d1205 ZW |
11361 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
11362 | { | |
11363 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
11364 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
11365 | _("source1 and dest must be same register")); | |
b99bd4ef | 11366 | |
c19d1205 ZW |
11367 | switch (inst.instruction) |
11368 | { | |
11369 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
11370 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
11371 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
11372 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
11373 | default: abort (); | |
11374 | } | |
5f4273c7 | 11375 | |
c19d1205 ZW |
11376 | inst.instruction |= inst.operands[0].reg; |
11377 | inst.instruction |= inst.operands[2].reg << 3; | |
11378 | } | |
11379 | else | |
b99bd4ef | 11380 | { |
c19d1205 ZW |
11381 | switch (inst.instruction) |
11382 | { | |
11383 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
11384 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
11385 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
11386 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
11387 | default: abort (); | |
11388 | } | |
11389 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
11390 | inst.instruction |= inst.operands[0].reg; | |
11391 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
11392 | } |
11393 | } | |
b99bd4ef NC |
11394 | } |
11395 | ||
11396 | static void | |
c19d1205 | 11397 | do_t_simd (void) |
b99bd4ef | 11398 | { |
fdfde340 JM |
11399 | unsigned Rd, Rn, Rm; |
11400 | ||
11401 | Rd = inst.operands[0].reg; | |
11402 | Rn = inst.operands[1].reg; | |
11403 | Rm = inst.operands[2].reg; | |
11404 | ||
11405 | reject_bad_reg (Rd); | |
11406 | reject_bad_reg (Rn); | |
11407 | reject_bad_reg (Rm); | |
11408 | ||
11409 | inst.instruction |= Rd << 8; | |
11410 | inst.instruction |= Rn << 16; | |
11411 | inst.instruction |= Rm; | |
c19d1205 | 11412 | } |
b99bd4ef | 11413 | |
03ee1b7f NC |
11414 | static void |
11415 | do_t_simd2 (void) | |
11416 | { | |
11417 | unsigned Rd, Rn, Rm; | |
11418 | ||
11419 | Rd = inst.operands[0].reg; | |
11420 | Rm = inst.operands[1].reg; | |
11421 | Rn = inst.operands[2].reg; | |
11422 | ||
11423 | reject_bad_reg (Rd); | |
11424 | reject_bad_reg (Rn); | |
11425 | reject_bad_reg (Rm); | |
11426 | ||
11427 | inst.instruction |= Rd << 8; | |
11428 | inst.instruction |= Rn << 16; | |
11429 | inst.instruction |= Rm; | |
11430 | } | |
11431 | ||
c19d1205 | 11432 | static void |
3eb17e6b | 11433 | do_t_smc (void) |
c19d1205 ZW |
11434 | { |
11435 | unsigned int value = inst.reloc.exp.X_add_number; | |
f4c65163 MGD |
11436 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
11437 | _("SMC is not permitted on this architecture")); | |
c19d1205 ZW |
11438 | constraint (inst.reloc.exp.X_op != O_constant, |
11439 | _("expression too complex")); | |
11440 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11441 | inst.instruction |= (value & 0xf000) >> 12; | |
11442 | inst.instruction |= (value & 0x0ff0); | |
11443 | inst.instruction |= (value & 0x000f) << 16; | |
11444 | } | |
b99bd4ef | 11445 | |
90ec0d68 MGD |
11446 | static void |
11447 | do_t_hvc (void) | |
11448 | { | |
11449 | unsigned int value = inst.reloc.exp.X_add_number; | |
11450 | ||
11451 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11452 | inst.instruction |= (value & 0x0fff); | |
11453 | inst.instruction |= (value & 0xf000) << 4; | |
11454 | } | |
11455 | ||
c19d1205 | 11456 | static void |
3a21c15a | 11457 | do_t_ssat_usat (int bias) |
c19d1205 | 11458 | { |
fdfde340 JM |
11459 | unsigned Rd, Rn; |
11460 | ||
11461 | Rd = inst.operands[0].reg; | |
11462 | Rn = inst.operands[2].reg; | |
11463 | ||
11464 | reject_bad_reg (Rd); | |
11465 | reject_bad_reg (Rn); | |
11466 | ||
11467 | inst.instruction |= Rd << 8; | |
3a21c15a | 11468 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 11469 | inst.instruction |= Rn << 16; |
b99bd4ef | 11470 | |
c19d1205 | 11471 | if (inst.operands[3].present) |
b99bd4ef | 11472 | { |
3a21c15a NC |
11473 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
11474 | ||
11475 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11476 | ||
c19d1205 ZW |
11477 | constraint (inst.reloc.exp.X_op != O_constant, |
11478 | _("expression too complex")); | |
b99bd4ef | 11479 | |
3a21c15a | 11480 | if (shift_amount != 0) |
6189168b | 11481 | { |
3a21c15a NC |
11482 | constraint (shift_amount > 31, |
11483 | _("shift expression is too large")); | |
11484 | ||
c19d1205 | 11485 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
11486 | inst.instruction |= 0x00200000; /* sh bit. */ |
11487 | ||
11488 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
11489 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
11490 | } |
11491 | } | |
b99bd4ef | 11492 | } |
c921be7d | 11493 | |
3a21c15a NC |
11494 | static void |
11495 | do_t_ssat (void) | |
11496 | { | |
11497 | do_t_ssat_usat (1); | |
11498 | } | |
b99bd4ef | 11499 | |
0dd132b6 | 11500 | static void |
c19d1205 | 11501 | do_t_ssat16 (void) |
0dd132b6 | 11502 | { |
fdfde340 JM |
11503 | unsigned Rd, Rn; |
11504 | ||
11505 | Rd = inst.operands[0].reg; | |
11506 | Rn = inst.operands[2].reg; | |
11507 | ||
11508 | reject_bad_reg (Rd); | |
11509 | reject_bad_reg (Rn); | |
11510 | ||
11511 | inst.instruction |= Rd << 8; | |
c19d1205 | 11512 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 11513 | inst.instruction |= Rn << 16; |
c19d1205 | 11514 | } |
0dd132b6 | 11515 | |
c19d1205 ZW |
11516 | static void |
11517 | do_t_strex (void) | |
11518 | { | |
11519 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
11520 | || inst.operands[2].postind || inst.operands[2].writeback | |
11521 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
11522 | || inst.operands[2].negative, | |
01cfc07f | 11523 | BAD_ADDR_MODE); |
0dd132b6 | 11524 | |
5be8be5d DG |
11525 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
11526 | ||
c19d1205 ZW |
11527 | inst.instruction |= inst.operands[0].reg << 8; |
11528 | inst.instruction |= inst.operands[1].reg << 12; | |
11529 | inst.instruction |= inst.operands[2].reg << 16; | |
11530 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
11531 | } |
11532 | ||
b99bd4ef | 11533 | static void |
c19d1205 | 11534 | do_t_strexd (void) |
b99bd4ef | 11535 | { |
c19d1205 ZW |
11536 | if (!inst.operands[2].present) |
11537 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 11538 | |
c19d1205 ZW |
11539 | constraint (inst.operands[0].reg == inst.operands[1].reg |
11540 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 11541 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 11542 | BAD_OVERLAP); |
b99bd4ef | 11543 | |
c19d1205 ZW |
11544 | inst.instruction |= inst.operands[0].reg; |
11545 | inst.instruction |= inst.operands[1].reg << 12; | |
11546 | inst.instruction |= inst.operands[2].reg << 8; | |
11547 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
11548 | } |
11549 | ||
11550 | static void | |
c19d1205 | 11551 | do_t_sxtah (void) |
b99bd4ef | 11552 | { |
fdfde340 JM |
11553 | unsigned Rd, Rn, Rm; |
11554 | ||
11555 | Rd = inst.operands[0].reg; | |
11556 | Rn = inst.operands[1].reg; | |
11557 | Rm = inst.operands[2].reg; | |
11558 | ||
11559 | reject_bad_reg (Rd); | |
11560 | reject_bad_reg (Rn); | |
11561 | reject_bad_reg (Rm); | |
11562 | ||
11563 | inst.instruction |= Rd << 8; | |
11564 | inst.instruction |= Rn << 16; | |
11565 | inst.instruction |= Rm; | |
c19d1205 ZW |
11566 | inst.instruction |= inst.operands[3].imm << 4; |
11567 | } | |
b99bd4ef | 11568 | |
c19d1205 ZW |
11569 | static void |
11570 | do_t_sxth (void) | |
11571 | { | |
fdfde340 JM |
11572 | unsigned Rd, Rm; |
11573 | ||
11574 | Rd = inst.operands[0].reg; | |
11575 | Rm = inst.operands[1].reg; | |
11576 | ||
11577 | reject_bad_reg (Rd); | |
11578 | reject_bad_reg (Rm); | |
c921be7d NC |
11579 | |
11580 | if (inst.instruction <= 0xffff | |
11581 | && inst.size_req != 4 | |
fdfde340 | 11582 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 11583 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 11584 | { |
c19d1205 | 11585 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
11586 | inst.instruction |= Rd; |
11587 | inst.instruction |= Rm << 3; | |
b99bd4ef | 11588 | } |
c19d1205 | 11589 | else if (unified_syntax) |
b99bd4ef | 11590 | { |
c19d1205 ZW |
11591 | if (inst.instruction <= 0xffff) |
11592 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11593 | inst.instruction |= Rd << 8; |
11594 | inst.instruction |= Rm; | |
c19d1205 | 11595 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 11596 | } |
c19d1205 | 11597 | else |
b99bd4ef | 11598 | { |
c19d1205 ZW |
11599 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
11600 | _("Thumb encoding does not support rotation")); | |
11601 | constraint (1, BAD_HIREG); | |
b99bd4ef | 11602 | } |
c19d1205 | 11603 | } |
b99bd4ef | 11604 | |
c19d1205 ZW |
11605 | static void |
11606 | do_t_swi (void) | |
11607 | { | |
b2a5fbdc MGD |
11608 | /* We have to do the following check manually as ARM_EXT_OS only applies |
11609 | to ARM_EXT_V6M. */ | |
11610 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m)) | |
11611 | { | |
11612 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)) | |
11613 | as_bad (_("SVC is not permitted on this architecture")); | |
11614 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os); | |
11615 | } | |
11616 | ||
c19d1205 ZW |
11617 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
11618 | } | |
b99bd4ef | 11619 | |
92e90b6e PB |
11620 | static void |
11621 | do_t_tb (void) | |
11622 | { | |
fdfde340 | 11623 | unsigned Rn, Rm; |
92e90b6e PB |
11624 | int half; |
11625 | ||
11626 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 11627 | set_it_insn_type_last (); |
dfa9f0d5 PB |
11628 | constraint (inst.operands[0].immisreg, |
11629 | _("instruction requires register index")); | |
fdfde340 JM |
11630 | |
11631 | Rn = inst.operands[0].reg; | |
11632 | Rm = inst.operands[0].imm; | |
c921be7d | 11633 | |
fdfde340 JM |
11634 | constraint (Rn == REG_SP, BAD_SP); |
11635 | reject_bad_reg (Rm); | |
11636 | ||
92e90b6e PB |
11637 | constraint (!half && inst.operands[0].shifted, |
11638 | _("instruction does not allow shifted index")); | |
fdfde340 | 11639 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
11640 | } |
11641 | ||
c19d1205 ZW |
11642 | static void |
11643 | do_t_usat (void) | |
11644 | { | |
3a21c15a | 11645 | do_t_ssat_usat (0); |
b99bd4ef NC |
11646 | } |
11647 | ||
11648 | static void | |
c19d1205 | 11649 | do_t_usat16 (void) |
b99bd4ef | 11650 | { |
fdfde340 JM |
11651 | unsigned Rd, Rn; |
11652 | ||
11653 | Rd = inst.operands[0].reg; | |
11654 | Rn = inst.operands[2].reg; | |
11655 | ||
11656 | reject_bad_reg (Rd); | |
11657 | reject_bad_reg (Rn); | |
11658 | ||
11659 | inst.instruction |= Rd << 8; | |
c19d1205 | 11660 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 11661 | inst.instruction |= Rn << 16; |
b99bd4ef | 11662 | } |
c19d1205 | 11663 | |
5287ad62 | 11664 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 11665 | |
5287ad62 | 11666 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 11667 | |
5287ad62 JB |
11668 | /* An "invalid" code for the following tables. */ |
11669 | #define N_INV -1u | |
11670 | ||
11671 | struct neon_tab_entry | |
b99bd4ef | 11672 | { |
5287ad62 JB |
11673 | unsigned integer; |
11674 | unsigned float_or_poly; | |
11675 | unsigned scalar_or_imm; | |
11676 | }; | |
5f4273c7 | 11677 | |
5287ad62 JB |
11678 | /* Map overloaded Neon opcodes to their respective encodings. */ |
11679 | #define NEON_ENC_TAB \ | |
11680 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
11681 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
11682 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
11683 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
11684 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
11685 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
11686 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
11687 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
11688 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
11689 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
11690 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
11691 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 11692 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
11693 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
11694 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
11695 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
11696 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
11697 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
11698 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
11699 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
11700 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
11701 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
11702 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
11703 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
11704 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
11705 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
11706 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
11707 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
11708 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
11709 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
11710 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
11711 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
11712 | X(veor, 0x1000110, N_INV, N_INV), \ | |
11713 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
11714 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
11715 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
11716 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
11717 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
11718 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
11719 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
11720 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
11721 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
11722 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
11723 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
11724 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
11725 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
11726 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
11727 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
11728 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
11729 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
11730 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
11731 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
11732 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
11733 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
11734 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
11735 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
11736 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
11737 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
11738 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
11739 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV) | |
5287ad62 JB |
11740 | |
11741 | enum neon_opc | |
11742 | { | |
11743 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
11744 | NEON_ENC_TAB | |
11745 | #undef X | |
11746 | }; | |
b99bd4ef | 11747 | |
5287ad62 JB |
11748 | static const struct neon_tab_entry neon_enc_tab[] = |
11749 | { | |
11750 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
11751 | NEON_ENC_TAB | |
11752 | #undef X | |
11753 | }; | |
b99bd4ef | 11754 | |
88714cb8 DG |
11755 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
11756 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11757 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11758 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11759 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11760 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11761 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11762 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11763 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11764 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11765 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 11766 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 11767 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 11768 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
5287ad62 | 11769 | |
88714cb8 DG |
11770 | #define NEON_ENCODE(type, inst) \ |
11771 | do \ | |
11772 | { \ | |
11773 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
11774 | inst.is_neon = 1; \ | |
11775 | } \ | |
11776 | while (0) | |
11777 | ||
11778 | #define check_neon_suffixes \ | |
11779 | do \ | |
11780 | { \ | |
11781 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
11782 | { \ | |
11783 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
11784 | return; \ | |
11785 | } \ | |
11786 | } \ | |
11787 | while (0) | |
11788 | ||
037e8744 JB |
11789 | /* Define shapes for instruction operands. The following mnemonic characters |
11790 | are used in this table: | |
5287ad62 | 11791 | |
037e8744 | 11792 | F - VFP S<n> register |
5287ad62 JB |
11793 | D - Neon D<n> register |
11794 | Q - Neon Q<n> register | |
11795 | I - Immediate | |
11796 | S - Scalar | |
11797 | R - ARM register | |
11798 | L - D<n> register list | |
5f4273c7 | 11799 | |
037e8744 JB |
11800 | This table is used to generate various data: |
11801 | - enumerations of the form NS_DDR to be used as arguments to | |
11802 | neon_select_shape. | |
11803 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 11804 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 11805 | |
037e8744 JB |
11806 | #define NEON_SHAPE_DEF \ |
11807 | X(3, (D, D, D), DOUBLE), \ | |
11808 | X(3, (Q, Q, Q), QUAD), \ | |
11809 | X(3, (D, D, I), DOUBLE), \ | |
11810 | X(3, (Q, Q, I), QUAD), \ | |
11811 | X(3, (D, D, S), DOUBLE), \ | |
11812 | X(3, (Q, Q, S), QUAD), \ | |
11813 | X(2, (D, D), DOUBLE), \ | |
11814 | X(2, (Q, Q), QUAD), \ | |
11815 | X(2, (D, S), DOUBLE), \ | |
11816 | X(2, (Q, S), QUAD), \ | |
11817 | X(2, (D, R), DOUBLE), \ | |
11818 | X(2, (Q, R), QUAD), \ | |
11819 | X(2, (D, I), DOUBLE), \ | |
11820 | X(2, (Q, I), QUAD), \ | |
11821 | X(3, (D, L, D), DOUBLE), \ | |
11822 | X(2, (D, Q), MIXED), \ | |
11823 | X(2, (Q, D), MIXED), \ | |
11824 | X(3, (D, Q, I), MIXED), \ | |
11825 | X(3, (Q, D, I), MIXED), \ | |
11826 | X(3, (Q, D, D), MIXED), \ | |
11827 | X(3, (D, Q, Q), MIXED), \ | |
11828 | X(3, (Q, Q, D), MIXED), \ | |
11829 | X(3, (Q, D, S), MIXED), \ | |
11830 | X(3, (D, Q, S), MIXED), \ | |
11831 | X(4, (D, D, D, I), DOUBLE), \ | |
11832 | X(4, (Q, Q, Q, I), QUAD), \ | |
11833 | X(2, (F, F), SINGLE), \ | |
11834 | X(3, (F, F, F), SINGLE), \ | |
11835 | X(2, (F, I), SINGLE), \ | |
11836 | X(2, (F, D), MIXED), \ | |
11837 | X(2, (D, F), MIXED), \ | |
11838 | X(3, (F, F, I), MIXED), \ | |
11839 | X(4, (R, R, F, F), SINGLE), \ | |
11840 | X(4, (F, F, R, R), SINGLE), \ | |
11841 | X(3, (D, R, R), DOUBLE), \ | |
11842 | X(3, (R, R, D), DOUBLE), \ | |
11843 | X(2, (S, R), SINGLE), \ | |
11844 | X(2, (R, S), SINGLE), \ | |
11845 | X(2, (F, R), SINGLE), \ | |
11846 | X(2, (R, F), SINGLE) | |
11847 | ||
11848 | #define S2(A,B) NS_##A##B | |
11849 | #define S3(A,B,C) NS_##A##B##C | |
11850 | #define S4(A,B,C,D) NS_##A##B##C##D | |
11851 | ||
11852 | #define X(N, L, C) S##N L | |
11853 | ||
5287ad62 JB |
11854 | enum neon_shape |
11855 | { | |
037e8744 JB |
11856 | NEON_SHAPE_DEF, |
11857 | NS_NULL | |
5287ad62 | 11858 | }; |
b99bd4ef | 11859 | |
037e8744 JB |
11860 | #undef X |
11861 | #undef S2 | |
11862 | #undef S3 | |
11863 | #undef S4 | |
11864 | ||
11865 | enum neon_shape_class | |
11866 | { | |
11867 | SC_SINGLE, | |
11868 | SC_DOUBLE, | |
11869 | SC_QUAD, | |
11870 | SC_MIXED | |
11871 | }; | |
11872 | ||
11873 | #define X(N, L, C) SC_##C | |
11874 | ||
11875 | static enum neon_shape_class neon_shape_class[] = | |
11876 | { | |
11877 | NEON_SHAPE_DEF | |
11878 | }; | |
11879 | ||
11880 | #undef X | |
11881 | ||
11882 | enum neon_shape_el | |
11883 | { | |
11884 | SE_F, | |
11885 | SE_D, | |
11886 | SE_Q, | |
11887 | SE_I, | |
11888 | SE_S, | |
11889 | SE_R, | |
11890 | SE_L | |
11891 | }; | |
11892 | ||
11893 | /* Register widths of above. */ | |
11894 | static unsigned neon_shape_el_size[] = | |
11895 | { | |
11896 | 32, | |
11897 | 64, | |
11898 | 128, | |
11899 | 0, | |
11900 | 32, | |
11901 | 32, | |
11902 | 0 | |
11903 | }; | |
11904 | ||
11905 | struct neon_shape_info | |
11906 | { | |
11907 | unsigned els; | |
11908 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
11909 | }; | |
11910 | ||
11911 | #define S2(A,B) { SE_##A, SE_##B } | |
11912 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
11913 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
11914 | ||
11915 | #define X(N, L, C) { N, S##N L } | |
11916 | ||
11917 | static struct neon_shape_info neon_shape_tab[] = | |
11918 | { | |
11919 | NEON_SHAPE_DEF | |
11920 | }; | |
11921 | ||
11922 | #undef X | |
11923 | #undef S2 | |
11924 | #undef S3 | |
11925 | #undef S4 | |
11926 | ||
5287ad62 JB |
11927 | /* Bit masks used in type checking given instructions. |
11928 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
11929 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
11930 | set, various other bits can be set as well in order to modify the meaning of | |
11931 | the type constraint. */ | |
11932 | ||
11933 | enum neon_type_mask | |
11934 | { | |
8e79c3df CM |
11935 | N_S8 = 0x0000001, |
11936 | N_S16 = 0x0000002, | |
11937 | N_S32 = 0x0000004, | |
11938 | N_S64 = 0x0000008, | |
11939 | N_U8 = 0x0000010, | |
11940 | N_U16 = 0x0000020, | |
11941 | N_U32 = 0x0000040, | |
11942 | N_U64 = 0x0000080, | |
11943 | N_I8 = 0x0000100, | |
11944 | N_I16 = 0x0000200, | |
11945 | N_I32 = 0x0000400, | |
11946 | N_I64 = 0x0000800, | |
11947 | N_8 = 0x0001000, | |
11948 | N_16 = 0x0002000, | |
11949 | N_32 = 0x0004000, | |
11950 | N_64 = 0x0008000, | |
11951 | N_P8 = 0x0010000, | |
11952 | N_P16 = 0x0020000, | |
11953 | N_F16 = 0x0040000, | |
11954 | N_F32 = 0x0080000, | |
11955 | N_F64 = 0x0100000, | |
c921be7d NC |
11956 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
11957 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 11958 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
c921be7d NC |
11959 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
11960 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
11961 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
11962 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
11963 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
11964 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
11965 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 11966 | N_UTYP = 0, |
037e8744 | 11967 | N_MAX_NONSPECIAL = N_F64 |
5287ad62 JB |
11968 | }; |
11969 | ||
dcbf9037 JB |
11970 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
11971 | ||
5287ad62 JB |
11972 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
11973 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
11974 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
11975 | #define N_SUF_32 (N_SU_32 | N_F32) | |
11976 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
11977 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
11978 | ||
11979 | /* Pass this as the first type argument to neon_check_type to ignore types | |
11980 | altogether. */ | |
11981 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
11982 | ||
037e8744 JB |
11983 | /* Select a "shape" for the current instruction (describing register types or |
11984 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
11985 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
11986 | function of operand parsing, so this function doesn't need to be called. | |
11987 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
11988 | |
11989 | static enum neon_shape | |
037e8744 | 11990 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 11991 | { |
037e8744 JB |
11992 | va_list ap; |
11993 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
11994 | |
11995 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
11996 | many arguments we should have, so this makes the assumption that we have | |
11997 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
11998 | true in the future. */ | |
11999 | if (!inst.operands[1].present) | |
12000 | inst.operands[1] = inst.operands[0]; | |
12001 | ||
037e8744 | 12002 | va_start (ap, shape); |
5f4273c7 | 12003 | |
21d799b5 | 12004 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
12005 | { |
12006 | unsigned j; | |
12007 | int matches = 1; | |
12008 | ||
12009 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
12010 | { | |
12011 | if (!inst.operands[j].present) | |
12012 | { | |
12013 | matches = 0; | |
12014 | break; | |
12015 | } | |
12016 | ||
12017 | switch (neon_shape_tab[shape].el[j]) | |
12018 | { | |
12019 | case SE_F: | |
12020 | if (!(inst.operands[j].isreg | |
12021 | && inst.operands[j].isvec | |
12022 | && inst.operands[j].issingle | |
12023 | && !inst.operands[j].isquad)) | |
12024 | matches = 0; | |
12025 | break; | |
12026 | ||
12027 | case SE_D: | |
12028 | if (!(inst.operands[j].isreg | |
12029 | && inst.operands[j].isvec | |
12030 | && !inst.operands[j].isquad | |
12031 | && !inst.operands[j].issingle)) | |
12032 | matches = 0; | |
12033 | break; | |
12034 | ||
12035 | case SE_R: | |
12036 | if (!(inst.operands[j].isreg | |
12037 | && !inst.operands[j].isvec)) | |
12038 | matches = 0; | |
12039 | break; | |
12040 | ||
12041 | case SE_Q: | |
12042 | if (!(inst.operands[j].isreg | |
12043 | && inst.operands[j].isvec | |
12044 | && inst.operands[j].isquad | |
12045 | && !inst.operands[j].issingle)) | |
12046 | matches = 0; | |
12047 | break; | |
12048 | ||
12049 | case SE_I: | |
12050 | if (!(!inst.operands[j].isreg | |
12051 | && !inst.operands[j].isscalar)) | |
12052 | matches = 0; | |
12053 | break; | |
12054 | ||
12055 | case SE_S: | |
12056 | if (!(!inst.operands[j].isreg | |
12057 | && inst.operands[j].isscalar)) | |
12058 | matches = 0; | |
12059 | break; | |
12060 | ||
12061 | case SE_L: | |
12062 | break; | |
12063 | } | |
3fde54a2 JZ |
12064 | if (!matches) |
12065 | break; | |
037e8744 JB |
12066 | } |
12067 | if (matches) | |
5287ad62 | 12068 | break; |
037e8744 | 12069 | } |
5f4273c7 | 12070 | |
037e8744 | 12071 | va_end (ap); |
5287ad62 | 12072 | |
037e8744 JB |
12073 | if (shape == NS_NULL && first_shape != NS_NULL) |
12074 | first_error (_("invalid instruction shape")); | |
5287ad62 | 12075 | |
037e8744 JB |
12076 | return shape; |
12077 | } | |
5287ad62 | 12078 | |
037e8744 JB |
12079 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
12080 | means the Q bit should be set). */ | |
12081 | ||
12082 | static int | |
12083 | neon_quad (enum neon_shape shape) | |
12084 | { | |
12085 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 12086 | } |
037e8744 | 12087 | |
5287ad62 JB |
12088 | static void |
12089 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
12090 | unsigned *g_size) | |
12091 | { | |
12092 | /* Allow modification to be made to types which are constrained to be | |
12093 | based on the key element, based on bits set alongside N_EQK. */ | |
12094 | if ((typebits & N_EQK) != 0) | |
12095 | { | |
12096 | if ((typebits & N_HLF) != 0) | |
12097 | *g_size /= 2; | |
12098 | else if ((typebits & N_DBL) != 0) | |
12099 | *g_size *= 2; | |
12100 | if ((typebits & N_SGN) != 0) | |
12101 | *g_type = NT_signed; | |
12102 | else if ((typebits & N_UNS) != 0) | |
12103 | *g_type = NT_unsigned; | |
12104 | else if ((typebits & N_INT) != 0) | |
12105 | *g_type = NT_integer; | |
12106 | else if ((typebits & N_FLT) != 0) | |
12107 | *g_type = NT_float; | |
dcbf9037 JB |
12108 | else if ((typebits & N_SIZ) != 0) |
12109 | *g_type = NT_untyped; | |
5287ad62 JB |
12110 | } |
12111 | } | |
5f4273c7 | 12112 | |
5287ad62 JB |
12113 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
12114 | operand type, i.e. the single type specified in a Neon instruction when it | |
12115 | is the only one given. */ | |
12116 | ||
12117 | static struct neon_type_el | |
12118 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
12119 | { | |
12120 | struct neon_type_el dest = *key; | |
5f4273c7 | 12121 | |
9c2799c2 | 12122 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 12123 | |
5287ad62 JB |
12124 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
12125 | ||
12126 | return dest; | |
12127 | } | |
12128 | ||
12129 | /* Convert Neon type and size into compact bitmask representation. */ | |
12130 | ||
12131 | static enum neon_type_mask | |
12132 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
12133 | { | |
12134 | switch (type) | |
12135 | { | |
12136 | case NT_untyped: | |
12137 | switch (size) | |
12138 | { | |
12139 | case 8: return N_8; | |
12140 | case 16: return N_16; | |
12141 | case 32: return N_32; | |
12142 | case 64: return N_64; | |
12143 | default: ; | |
12144 | } | |
12145 | break; | |
12146 | ||
12147 | case NT_integer: | |
12148 | switch (size) | |
12149 | { | |
12150 | case 8: return N_I8; | |
12151 | case 16: return N_I16; | |
12152 | case 32: return N_I32; | |
12153 | case 64: return N_I64; | |
12154 | default: ; | |
12155 | } | |
12156 | break; | |
12157 | ||
12158 | case NT_float: | |
037e8744 JB |
12159 | switch (size) |
12160 | { | |
8e79c3df | 12161 | case 16: return N_F16; |
037e8744 JB |
12162 | case 32: return N_F32; |
12163 | case 64: return N_F64; | |
12164 | default: ; | |
12165 | } | |
5287ad62 JB |
12166 | break; |
12167 | ||
12168 | case NT_poly: | |
12169 | switch (size) | |
12170 | { | |
12171 | case 8: return N_P8; | |
12172 | case 16: return N_P16; | |
12173 | default: ; | |
12174 | } | |
12175 | break; | |
12176 | ||
12177 | case NT_signed: | |
12178 | switch (size) | |
12179 | { | |
12180 | case 8: return N_S8; | |
12181 | case 16: return N_S16; | |
12182 | case 32: return N_S32; | |
12183 | case 64: return N_S64; | |
12184 | default: ; | |
12185 | } | |
12186 | break; | |
12187 | ||
12188 | case NT_unsigned: | |
12189 | switch (size) | |
12190 | { | |
12191 | case 8: return N_U8; | |
12192 | case 16: return N_U16; | |
12193 | case 32: return N_U32; | |
12194 | case 64: return N_U64; | |
12195 | default: ; | |
12196 | } | |
12197 | break; | |
12198 | ||
12199 | default: ; | |
12200 | } | |
5f4273c7 | 12201 | |
5287ad62 JB |
12202 | return N_UTYP; |
12203 | } | |
12204 | ||
12205 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
12206 | handles the case where a single bit is set in the mask. */ | |
12207 | ||
dcbf9037 | 12208 | static int |
5287ad62 JB |
12209 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
12210 | enum neon_type_mask mask) | |
12211 | { | |
dcbf9037 JB |
12212 | if ((mask & N_EQK) != 0) |
12213 | return FAIL; | |
12214 | ||
5287ad62 JB |
12215 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
12216 | *size = 8; | |
dcbf9037 | 12217 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0) |
5287ad62 | 12218 | *size = 16; |
dcbf9037 | 12219 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 12220 | *size = 32; |
037e8744 | 12221 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0) |
5287ad62 | 12222 | *size = 64; |
dcbf9037 JB |
12223 | else |
12224 | return FAIL; | |
12225 | ||
5287ad62 JB |
12226 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
12227 | *type = NT_signed; | |
dcbf9037 | 12228 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 12229 | *type = NT_unsigned; |
dcbf9037 | 12230 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 12231 | *type = NT_integer; |
dcbf9037 | 12232 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 12233 | *type = NT_untyped; |
dcbf9037 | 12234 | else if ((mask & (N_P8 | N_P16)) != 0) |
5287ad62 | 12235 | *type = NT_poly; |
037e8744 | 12236 | else if ((mask & (N_F32 | N_F64)) != 0) |
5287ad62 | 12237 | *type = NT_float; |
dcbf9037 JB |
12238 | else |
12239 | return FAIL; | |
5f4273c7 | 12240 | |
dcbf9037 | 12241 | return SUCCESS; |
5287ad62 JB |
12242 | } |
12243 | ||
12244 | /* Modify a bitmask of allowed types. This is only needed for type | |
12245 | relaxation. */ | |
12246 | ||
12247 | static unsigned | |
12248 | modify_types_allowed (unsigned allowed, unsigned mods) | |
12249 | { | |
12250 | unsigned size; | |
12251 | enum neon_el_type type; | |
12252 | unsigned destmask; | |
12253 | int i; | |
5f4273c7 | 12254 | |
5287ad62 | 12255 | destmask = 0; |
5f4273c7 | 12256 | |
5287ad62 JB |
12257 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
12258 | { | |
21d799b5 NC |
12259 | if (el_type_of_type_chk (&type, &size, |
12260 | (enum neon_type_mask) (allowed & i)) == SUCCESS) | |
dcbf9037 JB |
12261 | { |
12262 | neon_modify_type_size (mods, &type, &size); | |
12263 | destmask |= type_chk_of_el_type (type, size); | |
12264 | } | |
5287ad62 | 12265 | } |
5f4273c7 | 12266 | |
5287ad62 JB |
12267 | return destmask; |
12268 | } | |
12269 | ||
12270 | /* Check type and return type classification. | |
12271 | The manual states (paraphrase): If one datatype is given, it indicates the | |
12272 | type given in: | |
12273 | - the second operand, if there is one | |
12274 | - the operand, if there is no second operand | |
12275 | - the result, if there are no operands. | |
12276 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
12277 | which is set on a per-instruction basis, which is the one which matters when | |
12278 | only one data type is written. | |
12279 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 12280 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
12281 | |
12282 | static struct neon_type_el | |
12283 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
12284 | { | |
12285 | va_list ap; | |
12286 | unsigned i, pass, key_el = 0; | |
12287 | unsigned types[NEON_MAX_TYPE_ELS]; | |
12288 | enum neon_el_type k_type = NT_invtype; | |
12289 | unsigned k_size = -1u; | |
12290 | struct neon_type_el badtype = {NT_invtype, -1}; | |
12291 | unsigned key_allowed = 0; | |
12292 | ||
12293 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
12294 | Fill in the missing operand here, if it was omitted. */ | |
12295 | if (els > 1 && !inst.operands[1].present) | |
12296 | inst.operands[1] = inst.operands[0]; | |
12297 | ||
12298 | /* Suck up all the varargs. */ | |
12299 | va_start (ap, ns); | |
12300 | for (i = 0; i < els; i++) | |
12301 | { | |
12302 | unsigned thisarg = va_arg (ap, unsigned); | |
12303 | if (thisarg == N_IGNORE_TYPE) | |
12304 | { | |
12305 | va_end (ap); | |
12306 | return badtype; | |
12307 | } | |
12308 | types[i] = thisarg; | |
12309 | if ((thisarg & N_KEY) != 0) | |
12310 | key_el = i; | |
12311 | } | |
12312 | va_end (ap); | |
12313 | ||
dcbf9037 JB |
12314 | if (inst.vectype.elems > 0) |
12315 | for (i = 0; i < els; i++) | |
12316 | if (inst.operands[i].vectype.type != NT_invtype) | |
12317 | { | |
12318 | first_error (_("types specified in both the mnemonic and operands")); | |
12319 | return badtype; | |
12320 | } | |
12321 | ||
5287ad62 JB |
12322 | /* Duplicate inst.vectype elements here as necessary. |
12323 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
12324 | particularly when an insn takes one register and one non-register | |
12325 | operand. */ | |
12326 | if (inst.vectype.elems == 1 && els > 1) | |
12327 | { | |
12328 | unsigned j; | |
12329 | inst.vectype.elems = els; | |
12330 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
12331 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
12332 | if (j != key_el) |
12333 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
12334 | types[j]); | |
12335 | } | |
12336 | else if (inst.vectype.elems == 0 && els > 0) | |
12337 | { | |
12338 | unsigned j; | |
12339 | /* No types were given after the mnemonic, so look for types specified | |
12340 | after each operand. We allow some flexibility here; as long as the | |
12341 | "key" operand has a type, we can infer the others. */ | |
12342 | for (j = 0; j < els; j++) | |
12343 | if (inst.operands[j].vectype.type != NT_invtype) | |
12344 | inst.vectype.el[j] = inst.operands[j].vectype; | |
12345 | ||
12346 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 12347 | { |
dcbf9037 JB |
12348 | for (j = 0; j < els; j++) |
12349 | if (inst.operands[j].vectype.type == NT_invtype) | |
12350 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
12351 | types[j]); | |
12352 | } | |
12353 | else | |
12354 | { | |
12355 | first_error (_("operand types can't be inferred")); | |
12356 | return badtype; | |
5287ad62 JB |
12357 | } |
12358 | } | |
12359 | else if (inst.vectype.elems != els) | |
12360 | { | |
dcbf9037 | 12361 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
12362 | return badtype; |
12363 | } | |
12364 | ||
12365 | for (pass = 0; pass < 2; pass++) | |
12366 | { | |
12367 | for (i = 0; i < els; i++) | |
12368 | { | |
12369 | unsigned thisarg = types[i]; | |
12370 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
12371 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
12372 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
12373 | unsigned g_size = inst.vectype.el[i].size; | |
12374 | ||
12375 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
12376 | integer types if sign-specific variants are unavailable. */ | |
12377 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
12378 | && (types_allowed & N_SU_ALL) == 0) | |
12379 | g_type = NT_integer; | |
12380 | ||
12381 | /* If only untyped args are allowed, decay any more specific types to | |
12382 | them. Some instructions only care about signs for some element | |
12383 | sizes, so handle that properly. */ | |
12384 | if ((g_size == 8 && (types_allowed & N_8) != 0) | |
12385 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
12386 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
12387 | || (g_size == 64 && (types_allowed & N_64) != 0)) | |
12388 | g_type = NT_untyped; | |
12389 | ||
12390 | if (pass == 0) | |
12391 | { | |
12392 | if ((thisarg & N_KEY) != 0) | |
12393 | { | |
12394 | k_type = g_type; | |
12395 | k_size = g_size; | |
12396 | key_allowed = thisarg & ~N_KEY; | |
12397 | } | |
12398 | } | |
12399 | else | |
12400 | { | |
037e8744 JB |
12401 | if ((thisarg & N_VFP) != 0) |
12402 | { | |
99b253c5 NC |
12403 | enum neon_shape_el regshape; |
12404 | unsigned regwidth, match; | |
12405 | ||
12406 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
12407 | if (ns == NS_NULL) | |
12408 | { | |
12409 | first_error (_("invalid instruction shape")); | |
12410 | return badtype; | |
12411 | } | |
12412 | regshape = neon_shape_tab[ns].el[i]; | |
12413 | regwidth = neon_shape_el_size[regshape]; | |
037e8744 JB |
12414 | |
12415 | /* In VFP mode, operands must match register widths. If we | |
12416 | have a key operand, use its width, else use the width of | |
12417 | the current operand. */ | |
12418 | if (k_size != -1u) | |
12419 | match = k_size; | |
12420 | else | |
12421 | match = g_size; | |
12422 | ||
12423 | if (regwidth != match) | |
12424 | { | |
12425 | first_error (_("operand size must match register width")); | |
12426 | return badtype; | |
12427 | } | |
12428 | } | |
5f4273c7 | 12429 | |
5287ad62 JB |
12430 | if ((thisarg & N_EQK) == 0) |
12431 | { | |
12432 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
12433 | ||
12434 | if ((given_type & types_allowed) == 0) | |
12435 | { | |
dcbf9037 | 12436 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
12437 | return badtype; |
12438 | } | |
12439 | } | |
12440 | else | |
12441 | { | |
12442 | enum neon_el_type mod_k_type = k_type; | |
12443 | unsigned mod_k_size = k_size; | |
12444 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
12445 | if (g_type != mod_k_type || g_size != mod_k_size) | |
12446 | { | |
dcbf9037 | 12447 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
12448 | return badtype; |
12449 | } | |
12450 | } | |
12451 | } | |
12452 | } | |
12453 | } | |
12454 | ||
12455 | return inst.vectype.el[key_el]; | |
12456 | } | |
12457 | ||
037e8744 | 12458 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 12459 | |
037e8744 JB |
12460 | /* Thumb VFP instructions have 0xE in the condition field. */ |
12461 | ||
12462 | static void | |
12463 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 12464 | { |
88714cb8 DG |
12465 | inst.is_neon = 1; |
12466 | ||
5287ad62 | 12467 | if (thumb_mode) |
037e8744 | 12468 | inst.instruction |= 0xe0000000; |
5287ad62 | 12469 | else |
037e8744 | 12470 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
12471 | } |
12472 | ||
037e8744 JB |
12473 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
12474 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
12475 | etc. It is assumed that operand parsing has already been done, and that the | |
12476 | operands are in the form expected by the given opcode (this isn't necessarily | |
12477 | the same as the form in which they were parsed, hence some massaging must | |
12478 | take place before this function is called). | |
12479 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 12480 | |
037e8744 JB |
12481 | static void |
12482 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 12483 | { |
037e8744 | 12484 | const struct asm_opcode *opcode; |
5f4273c7 | 12485 | |
21d799b5 | 12486 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 12487 | |
037e8744 JB |
12488 | if (!opcode) |
12489 | abort (); | |
5287ad62 | 12490 | |
037e8744 JB |
12491 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
12492 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
12493 | _(BAD_FPU)); | |
5287ad62 | 12494 | |
88714cb8 DG |
12495 | inst.is_neon = 1; |
12496 | ||
037e8744 JB |
12497 | if (thumb_mode) |
12498 | { | |
12499 | inst.instruction = opcode->tvalue; | |
12500 | opcode->tencode (); | |
12501 | } | |
12502 | else | |
12503 | { | |
12504 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
12505 | opcode->aencode (); | |
12506 | } | |
12507 | } | |
5287ad62 JB |
12508 | |
12509 | static void | |
037e8744 | 12510 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 12511 | { |
037e8744 JB |
12512 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
12513 | ||
12514 | if (rs == NS_FFF) | |
12515 | { | |
12516 | if (is_add) | |
12517 | do_vfp_nsyn_opcode ("fadds"); | |
12518 | else | |
12519 | do_vfp_nsyn_opcode ("fsubs"); | |
12520 | } | |
12521 | else | |
12522 | { | |
12523 | if (is_add) | |
12524 | do_vfp_nsyn_opcode ("faddd"); | |
12525 | else | |
12526 | do_vfp_nsyn_opcode ("fsubd"); | |
12527 | } | |
12528 | } | |
12529 | ||
12530 | /* Check operand types to see if this is a VFP instruction, and if so call | |
12531 | PFN (). */ | |
12532 | ||
12533 | static int | |
12534 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
12535 | { | |
12536 | enum neon_shape rs; | |
12537 | struct neon_type_el et; | |
12538 | ||
12539 | switch (args) | |
12540 | { | |
12541 | case 2: | |
12542 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12543 | et = neon_check_type (2, rs, | |
12544 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12545 | break; | |
5f4273c7 | 12546 | |
037e8744 JB |
12547 | case 3: |
12548 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12549 | et = neon_check_type (3, rs, | |
12550 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12551 | break; | |
12552 | ||
12553 | default: | |
12554 | abort (); | |
12555 | } | |
12556 | ||
12557 | if (et.type != NT_invtype) | |
12558 | { | |
12559 | pfn (rs); | |
12560 | return SUCCESS; | |
12561 | } | |
037e8744 | 12562 | |
99b253c5 | 12563 | inst.error = NULL; |
037e8744 JB |
12564 | return FAIL; |
12565 | } | |
12566 | ||
12567 | static void | |
12568 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
12569 | { | |
12570 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 12571 | |
037e8744 JB |
12572 | if (rs == NS_FFF) |
12573 | { | |
12574 | if (is_mla) | |
12575 | do_vfp_nsyn_opcode ("fmacs"); | |
12576 | else | |
1ee69515 | 12577 | do_vfp_nsyn_opcode ("fnmacs"); |
037e8744 JB |
12578 | } |
12579 | else | |
12580 | { | |
12581 | if (is_mla) | |
12582 | do_vfp_nsyn_opcode ("fmacd"); | |
12583 | else | |
1ee69515 | 12584 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
12585 | } |
12586 | } | |
12587 | ||
62f3b8c8 PB |
12588 | static void |
12589 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
12590 | { | |
12591 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
12592 | ||
12593 | if (rs == NS_FFF) | |
12594 | { | |
12595 | if (is_fma) | |
12596 | do_vfp_nsyn_opcode ("ffmas"); | |
12597 | else | |
12598 | do_vfp_nsyn_opcode ("ffnmas"); | |
12599 | } | |
12600 | else | |
12601 | { | |
12602 | if (is_fma) | |
12603 | do_vfp_nsyn_opcode ("ffmad"); | |
12604 | else | |
12605 | do_vfp_nsyn_opcode ("ffnmad"); | |
12606 | } | |
12607 | } | |
12608 | ||
037e8744 JB |
12609 | static void |
12610 | do_vfp_nsyn_mul (enum neon_shape rs) | |
12611 | { | |
12612 | if (rs == NS_FFF) | |
12613 | do_vfp_nsyn_opcode ("fmuls"); | |
12614 | else | |
12615 | do_vfp_nsyn_opcode ("fmuld"); | |
12616 | } | |
12617 | ||
12618 | static void | |
12619 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
12620 | { | |
12621 | int is_neg = (inst.instruction & 0x80) != 0; | |
12622 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
12623 | ||
12624 | if (rs == NS_FF) | |
12625 | { | |
12626 | if (is_neg) | |
12627 | do_vfp_nsyn_opcode ("fnegs"); | |
12628 | else | |
12629 | do_vfp_nsyn_opcode ("fabss"); | |
12630 | } | |
12631 | else | |
12632 | { | |
12633 | if (is_neg) | |
12634 | do_vfp_nsyn_opcode ("fnegd"); | |
12635 | else | |
12636 | do_vfp_nsyn_opcode ("fabsd"); | |
12637 | } | |
12638 | } | |
12639 | ||
12640 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
12641 | insns belong to Neon, and are handled elsewhere. */ | |
12642 | ||
12643 | static void | |
12644 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
12645 | { | |
12646 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
12647 | if (is_ldm) | |
12648 | { | |
12649 | if (is_dbmode) | |
12650 | do_vfp_nsyn_opcode ("fldmdbs"); | |
12651 | else | |
12652 | do_vfp_nsyn_opcode ("fldmias"); | |
12653 | } | |
12654 | else | |
12655 | { | |
12656 | if (is_dbmode) | |
12657 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12658 | else | |
12659 | do_vfp_nsyn_opcode ("fstmias"); | |
12660 | } | |
12661 | } | |
12662 | ||
037e8744 JB |
12663 | static void |
12664 | do_vfp_nsyn_sqrt (void) | |
12665 | { | |
12666 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12667 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12668 | |
037e8744 JB |
12669 | if (rs == NS_FF) |
12670 | do_vfp_nsyn_opcode ("fsqrts"); | |
12671 | else | |
12672 | do_vfp_nsyn_opcode ("fsqrtd"); | |
12673 | } | |
12674 | ||
12675 | static void | |
12676 | do_vfp_nsyn_div (void) | |
12677 | { | |
12678 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12679 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12680 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12681 | |
037e8744 JB |
12682 | if (rs == NS_FFF) |
12683 | do_vfp_nsyn_opcode ("fdivs"); | |
12684 | else | |
12685 | do_vfp_nsyn_opcode ("fdivd"); | |
12686 | } | |
12687 | ||
12688 | static void | |
12689 | do_vfp_nsyn_nmul (void) | |
12690 | { | |
12691 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12692 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12693 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12694 | |
037e8744 JB |
12695 | if (rs == NS_FFF) |
12696 | { | |
88714cb8 | 12697 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
12698 | do_vfp_sp_dyadic (); |
12699 | } | |
12700 | else | |
12701 | { | |
88714cb8 | 12702 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
12703 | do_vfp_dp_rd_rn_rm (); |
12704 | } | |
12705 | do_vfp_cond_or_thumb (); | |
12706 | } | |
12707 | ||
12708 | static void | |
12709 | do_vfp_nsyn_cmp (void) | |
12710 | { | |
12711 | if (inst.operands[1].isreg) | |
12712 | { | |
12713 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12714 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12715 | |
037e8744 JB |
12716 | if (rs == NS_FF) |
12717 | { | |
88714cb8 | 12718 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
12719 | do_vfp_sp_monadic (); |
12720 | } | |
12721 | else | |
12722 | { | |
88714cb8 | 12723 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
12724 | do_vfp_dp_rd_rm (); |
12725 | } | |
12726 | } | |
12727 | else | |
12728 | { | |
12729 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
12730 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
12731 | ||
12732 | switch (inst.instruction & 0x0fffffff) | |
12733 | { | |
12734 | case N_MNEM_vcmp: | |
12735 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
12736 | break; | |
12737 | case N_MNEM_vcmpe: | |
12738 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
12739 | break; | |
12740 | default: | |
12741 | abort (); | |
12742 | } | |
5f4273c7 | 12743 | |
037e8744 JB |
12744 | if (rs == NS_FI) |
12745 | { | |
88714cb8 | 12746 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
12747 | do_vfp_sp_compare_z (); |
12748 | } | |
12749 | else | |
12750 | { | |
88714cb8 | 12751 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
12752 | do_vfp_dp_rd (); |
12753 | } | |
12754 | } | |
12755 | do_vfp_cond_or_thumb (); | |
12756 | } | |
12757 | ||
12758 | static void | |
12759 | nsyn_insert_sp (void) | |
12760 | { | |
12761 | inst.operands[1] = inst.operands[0]; | |
12762 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 12763 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
12764 | inst.operands[0].isreg = 1; |
12765 | inst.operands[0].writeback = 1; | |
12766 | inst.operands[0].present = 1; | |
12767 | } | |
12768 | ||
12769 | static void | |
12770 | do_vfp_nsyn_push (void) | |
12771 | { | |
12772 | nsyn_insert_sp (); | |
12773 | if (inst.operands[1].issingle) | |
12774 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12775 | else | |
12776 | do_vfp_nsyn_opcode ("fstmdbd"); | |
12777 | } | |
12778 | ||
12779 | static void | |
12780 | do_vfp_nsyn_pop (void) | |
12781 | { | |
12782 | nsyn_insert_sp (); | |
12783 | if (inst.operands[1].issingle) | |
22b5b651 | 12784 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 12785 | else |
22b5b651 | 12786 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
12787 | } |
12788 | ||
12789 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
12790 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
12791 | ||
88714cb8 DG |
12792 | static void |
12793 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 12794 | { |
88714cb8 DG |
12795 | unsigned int i = insn->instruction; |
12796 | insn->is_neon = 1; | |
12797 | ||
037e8744 JB |
12798 | if (thumb_mode) |
12799 | { | |
12800 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
12801 | if (i & (1 << 24)) | |
12802 | i |= 1 << 28; | |
5f4273c7 | 12803 | |
037e8744 | 12804 | i &= ~(1 << 24); |
5f4273c7 | 12805 | |
037e8744 JB |
12806 | i |= 0xef000000; |
12807 | } | |
12808 | else | |
12809 | i |= 0xf2000000; | |
5f4273c7 | 12810 | |
88714cb8 | 12811 | insn->instruction = i; |
037e8744 JB |
12812 | } |
12813 | ||
12814 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
12815 | (0, 1, 2, 3). */ | |
12816 | ||
12817 | static unsigned | |
12818 | neon_logbits (unsigned x) | |
12819 | { | |
12820 | return ffs (x) - 4; | |
12821 | } | |
12822 | ||
12823 | #define LOW4(R) ((R) & 0xf) | |
12824 | #define HI1(R) (((R) >> 4) & 1) | |
12825 | ||
12826 | /* Encode insns with bit pattern: | |
12827 | ||
12828 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
12829 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 12830 | |
037e8744 JB |
12831 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
12832 | different meaning for some instruction. */ | |
12833 | ||
12834 | static void | |
12835 | neon_three_same (int isquad, int ubit, int size) | |
12836 | { | |
12837 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12838 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12839 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12840 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12841 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12842 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12843 | inst.instruction |= (isquad != 0) << 6; | |
12844 | inst.instruction |= (ubit != 0) << 24; | |
12845 | if (size != -1) | |
12846 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 12847 | |
88714cb8 | 12848 | neon_dp_fixup (&inst); |
037e8744 JB |
12849 | } |
12850 | ||
12851 | /* Encode instructions of the form: | |
12852 | ||
12853 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
12854 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
12855 | |
12856 | Don't write size if SIZE == -1. */ | |
12857 | ||
12858 | static void | |
12859 | neon_two_same (int qbit, int ubit, int size) | |
12860 | { | |
12861 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12862 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12863 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12864 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12865 | inst.instruction |= (qbit != 0) << 6; | |
12866 | inst.instruction |= (ubit != 0) << 24; | |
12867 | ||
12868 | if (size != -1) | |
12869 | inst.instruction |= neon_logbits (size) << 18; | |
12870 | ||
88714cb8 | 12871 | neon_dp_fixup (&inst); |
5287ad62 JB |
12872 | } |
12873 | ||
12874 | /* Neon instruction encoders, in approximate order of appearance. */ | |
12875 | ||
12876 | static void | |
12877 | do_neon_dyadic_i_su (void) | |
12878 | { | |
037e8744 | 12879 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12880 | struct neon_type_el et = neon_check_type (3, rs, |
12881 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 12882 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12883 | } |
12884 | ||
12885 | static void | |
12886 | do_neon_dyadic_i64_su (void) | |
12887 | { | |
037e8744 | 12888 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12889 | struct neon_type_el et = neon_check_type (3, rs, |
12890 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 12891 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12892 | } |
12893 | ||
12894 | static void | |
12895 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
12896 | unsigned immbits) | |
12897 | { | |
12898 | unsigned size = et.size >> 3; | |
12899 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12900 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12901 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12902 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12903 | inst.instruction |= (isquad != 0) << 6; | |
12904 | inst.instruction |= immbits << 16; | |
12905 | inst.instruction |= (size >> 3) << 7; | |
12906 | inst.instruction |= (size & 0x7) << 19; | |
12907 | if (write_ubit) | |
12908 | inst.instruction |= (uval != 0) << 24; | |
12909 | ||
88714cb8 | 12910 | neon_dp_fixup (&inst); |
5287ad62 JB |
12911 | } |
12912 | ||
12913 | static void | |
12914 | do_neon_shl_imm (void) | |
12915 | { | |
12916 | if (!inst.operands[2].isreg) | |
12917 | { | |
037e8744 | 12918 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 12919 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
88714cb8 | 12920 | NEON_ENCODE (IMMED, inst); |
037e8744 | 12921 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
12922 | } |
12923 | else | |
12924 | { | |
037e8744 | 12925 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12926 | struct neon_type_el et = neon_check_type (3, rs, |
12927 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12928 | unsigned int tmp; |
12929 | ||
12930 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
12931 | vshl.xx Dd, Dm, Dn | |
12932 | whereas other 3-register operations encoded by neon_three_same have | |
12933 | syntax like: | |
12934 | vadd.xx Dd, Dn, Dm | |
12935 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
12936 | here. */ | |
12937 | tmp = inst.operands[2].reg; | |
12938 | inst.operands[2].reg = inst.operands[1].reg; | |
12939 | inst.operands[1].reg = tmp; | |
88714cb8 | 12940 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 12941 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12942 | } |
12943 | } | |
12944 | ||
12945 | static void | |
12946 | do_neon_qshl_imm (void) | |
12947 | { | |
12948 | if (!inst.operands[2].isreg) | |
12949 | { | |
037e8744 | 12950 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 12951 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
627907b7 | 12952 | |
88714cb8 | 12953 | NEON_ENCODE (IMMED, inst); |
037e8744 | 12954 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
12955 | inst.operands[2].imm); |
12956 | } | |
12957 | else | |
12958 | { | |
037e8744 | 12959 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12960 | struct neon_type_el et = neon_check_type (3, rs, |
12961 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12962 | unsigned int tmp; |
12963 | ||
12964 | /* See note in do_neon_shl_imm. */ | |
12965 | tmp = inst.operands[2].reg; | |
12966 | inst.operands[2].reg = inst.operands[1].reg; | |
12967 | inst.operands[1].reg = tmp; | |
88714cb8 | 12968 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 12969 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12970 | } |
12971 | } | |
12972 | ||
627907b7 JB |
12973 | static void |
12974 | do_neon_rshl (void) | |
12975 | { | |
12976 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
12977 | struct neon_type_el et = neon_check_type (3, rs, | |
12978 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
12979 | unsigned int tmp; | |
12980 | ||
12981 | tmp = inst.operands[2].reg; | |
12982 | inst.operands[2].reg = inst.operands[1].reg; | |
12983 | inst.operands[1].reg = tmp; | |
12984 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
12985 | } | |
12986 | ||
5287ad62 JB |
12987 | static int |
12988 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
12989 | { | |
036dc3f7 PB |
12990 | /* Handle .I8 pseudo-instructions. */ |
12991 | if (size == 8) | |
5287ad62 | 12992 | { |
5287ad62 JB |
12993 | /* Unfortunately, this will make everything apart from zero out-of-range. |
12994 | FIXME is this the intended semantics? There doesn't seem much point in | |
12995 | accepting .I8 if so. */ | |
12996 | immediate |= immediate << 8; | |
12997 | size = 16; | |
036dc3f7 PB |
12998 | } |
12999 | ||
13000 | if (size >= 32) | |
13001 | { | |
13002 | if (immediate == (immediate & 0x000000ff)) | |
13003 | { | |
13004 | *immbits = immediate; | |
13005 | return 0x1; | |
13006 | } | |
13007 | else if (immediate == (immediate & 0x0000ff00)) | |
13008 | { | |
13009 | *immbits = immediate >> 8; | |
13010 | return 0x3; | |
13011 | } | |
13012 | else if (immediate == (immediate & 0x00ff0000)) | |
13013 | { | |
13014 | *immbits = immediate >> 16; | |
13015 | return 0x5; | |
13016 | } | |
13017 | else if (immediate == (immediate & 0xff000000)) | |
13018 | { | |
13019 | *immbits = immediate >> 24; | |
13020 | return 0x7; | |
13021 | } | |
13022 | if ((immediate & 0xffff) != (immediate >> 16)) | |
13023 | goto bad_immediate; | |
13024 | immediate &= 0xffff; | |
5287ad62 JB |
13025 | } |
13026 | ||
13027 | if (immediate == (immediate & 0x000000ff)) | |
13028 | { | |
13029 | *immbits = immediate; | |
036dc3f7 | 13030 | return 0x9; |
5287ad62 JB |
13031 | } |
13032 | else if (immediate == (immediate & 0x0000ff00)) | |
13033 | { | |
13034 | *immbits = immediate >> 8; | |
036dc3f7 | 13035 | return 0xb; |
5287ad62 JB |
13036 | } |
13037 | ||
13038 | bad_immediate: | |
dcbf9037 | 13039 | first_error (_("immediate value out of range")); |
5287ad62 JB |
13040 | return FAIL; |
13041 | } | |
13042 | ||
13043 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
13044 | A, B, C, D. */ | |
13045 | ||
13046 | static int | |
13047 | neon_bits_same_in_bytes (unsigned imm) | |
13048 | { | |
13049 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
13050 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
13051 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
13052 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
13053 | } | |
13054 | ||
13055 | /* For immediate of above form, return 0bABCD. */ | |
13056 | ||
13057 | static unsigned | |
13058 | neon_squash_bits (unsigned imm) | |
13059 | { | |
13060 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
13061 | | ((imm & 0x01000000) >> 21); | |
13062 | } | |
13063 | ||
136da414 | 13064 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
13065 | |
13066 | static unsigned | |
13067 | neon_qfloat_bits (unsigned imm) | |
13068 | { | |
136da414 | 13069 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
13070 | } |
13071 | ||
13072 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
13073 | the instruction. *OP is passed as the initial value of the op field, and | |
13074 | may be set to a different value depending on the constant (i.e. | |
13075 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
5f4273c7 | 13076 | MVN). If the immediate looks like a repeated pattern then also |
036dc3f7 | 13077 | try smaller element sizes. */ |
5287ad62 JB |
13078 | |
13079 | static int | |
c96612cc JB |
13080 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, |
13081 | unsigned *immbits, int *op, int size, | |
13082 | enum neon_el_type type) | |
5287ad62 | 13083 | { |
c96612cc JB |
13084 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is |
13085 | float. */ | |
13086 | if (type == NT_float && !float_p) | |
13087 | return FAIL; | |
13088 | ||
136da414 JB |
13089 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
13090 | { | |
13091 | if (size != 32 || *op == 1) | |
13092 | return FAIL; | |
13093 | *immbits = neon_qfloat_bits (immlo); | |
13094 | return 0xf; | |
13095 | } | |
036dc3f7 PB |
13096 | |
13097 | if (size == 64) | |
5287ad62 | 13098 | { |
036dc3f7 PB |
13099 | if (neon_bits_same_in_bytes (immhi) |
13100 | && neon_bits_same_in_bytes (immlo)) | |
13101 | { | |
13102 | if (*op == 1) | |
13103 | return FAIL; | |
13104 | *immbits = (neon_squash_bits (immhi) << 4) | |
13105 | | neon_squash_bits (immlo); | |
13106 | *op = 1; | |
13107 | return 0xe; | |
13108 | } | |
13109 | ||
13110 | if (immhi != immlo) | |
13111 | return FAIL; | |
5287ad62 | 13112 | } |
036dc3f7 PB |
13113 | |
13114 | if (size >= 32) | |
5287ad62 | 13115 | { |
036dc3f7 PB |
13116 | if (immlo == (immlo & 0x000000ff)) |
13117 | { | |
13118 | *immbits = immlo; | |
13119 | return 0x0; | |
13120 | } | |
13121 | else if (immlo == (immlo & 0x0000ff00)) | |
13122 | { | |
13123 | *immbits = immlo >> 8; | |
13124 | return 0x2; | |
13125 | } | |
13126 | else if (immlo == (immlo & 0x00ff0000)) | |
13127 | { | |
13128 | *immbits = immlo >> 16; | |
13129 | return 0x4; | |
13130 | } | |
13131 | else if (immlo == (immlo & 0xff000000)) | |
13132 | { | |
13133 | *immbits = immlo >> 24; | |
13134 | return 0x6; | |
13135 | } | |
13136 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
13137 | { | |
13138 | *immbits = (immlo >> 8) & 0xff; | |
13139 | return 0xc; | |
13140 | } | |
13141 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
13142 | { | |
13143 | *immbits = (immlo >> 16) & 0xff; | |
13144 | return 0xd; | |
13145 | } | |
13146 | ||
13147 | if ((immlo & 0xffff) != (immlo >> 16)) | |
13148 | return FAIL; | |
13149 | immlo &= 0xffff; | |
5287ad62 | 13150 | } |
036dc3f7 PB |
13151 | |
13152 | if (size >= 16) | |
5287ad62 | 13153 | { |
036dc3f7 PB |
13154 | if (immlo == (immlo & 0x000000ff)) |
13155 | { | |
13156 | *immbits = immlo; | |
13157 | return 0x8; | |
13158 | } | |
13159 | else if (immlo == (immlo & 0x0000ff00)) | |
13160 | { | |
13161 | *immbits = immlo >> 8; | |
13162 | return 0xa; | |
13163 | } | |
13164 | ||
13165 | if ((immlo & 0xff) != (immlo >> 8)) | |
13166 | return FAIL; | |
13167 | immlo &= 0xff; | |
5287ad62 | 13168 | } |
036dc3f7 PB |
13169 | |
13170 | if (immlo == (immlo & 0x000000ff)) | |
5287ad62 | 13171 | { |
036dc3f7 PB |
13172 | /* Don't allow MVN with 8-bit immediate. */ |
13173 | if (*op == 1) | |
13174 | return FAIL; | |
13175 | *immbits = immlo; | |
13176 | return 0xe; | |
5287ad62 | 13177 | } |
5287ad62 JB |
13178 | |
13179 | return FAIL; | |
13180 | } | |
13181 | ||
13182 | /* Write immediate bits [7:0] to the following locations: | |
13183 | ||
13184 | |28/24|23 19|18 16|15 4|3 0| | |
13185 | | 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| | |
13186 | ||
13187 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
13188 | ||
13189 | static void | |
13190 | neon_write_immbits (unsigned immbits) | |
13191 | { | |
13192 | inst.instruction |= immbits & 0xf; | |
13193 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
13194 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
13195 | } | |
13196 | ||
13197 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
13198 | ||
13199 | static void | |
13200 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
13201 | { | |
13202 | unsigned immlo = xlo ? *xlo : 0; | |
13203 | unsigned immhi = xhi ? *xhi : 0; | |
13204 | ||
13205 | switch (size) | |
13206 | { | |
13207 | case 8: | |
13208 | immlo = (~immlo) & 0xff; | |
13209 | break; | |
13210 | ||
13211 | case 16: | |
13212 | immlo = (~immlo) & 0xffff; | |
13213 | break; | |
13214 | ||
13215 | case 64: | |
13216 | immhi = (~immhi) & 0xffffffff; | |
13217 | /* fall through. */ | |
13218 | ||
13219 | case 32: | |
13220 | immlo = (~immlo) & 0xffffffff; | |
13221 | break; | |
13222 | ||
13223 | default: | |
13224 | abort (); | |
13225 | } | |
13226 | ||
13227 | if (xlo) | |
13228 | *xlo = immlo; | |
13229 | ||
13230 | if (xhi) | |
13231 | *xhi = immhi; | |
13232 | } | |
13233 | ||
13234 | static void | |
13235 | do_neon_logic (void) | |
13236 | { | |
13237 | if (inst.operands[2].present && inst.operands[2].isreg) | |
13238 | { | |
037e8744 | 13239 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13240 | neon_check_type (3, rs, N_IGNORE_TYPE); |
13241 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 13242 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 13243 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13244 | } |
13245 | else | |
13246 | { | |
4316f0d2 DG |
13247 | const int three_ops_form = (inst.operands[2].present |
13248 | && !inst.operands[2].isreg); | |
13249 | const int immoperand = (three_ops_form ? 2 : 1); | |
13250 | enum neon_shape rs = (three_ops_form | |
13251 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
13252 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
037e8744 JB |
13253 | struct neon_type_el et = neon_check_type (2, rs, |
13254 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
21d799b5 | 13255 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
13256 | unsigned immbits; |
13257 | int cmode; | |
5f4273c7 | 13258 | |
5287ad62 JB |
13259 | if (et.type == NT_invtype) |
13260 | return; | |
5f4273c7 | 13261 | |
4316f0d2 DG |
13262 | if (three_ops_form) |
13263 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13264 | _("first and second operands shall be the same register")); | |
13265 | ||
88714cb8 | 13266 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 13267 | |
4316f0d2 | 13268 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
13269 | if (et.size == 64) |
13270 | { | |
13271 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
13272 | pattern. */ | |
4316f0d2 DG |
13273 | if (immbits != (inst.operands[immoperand].regisimm ? |
13274 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
13275 | { |
13276 | /* Set immbits to an invalid constant. */ | |
13277 | immbits = 0xdeadbeef; | |
13278 | } | |
13279 | } | |
13280 | ||
5287ad62 JB |
13281 | switch (opcode) |
13282 | { | |
13283 | case N_MNEM_vbic: | |
036dc3f7 | 13284 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 13285 | break; |
5f4273c7 | 13286 | |
5287ad62 | 13287 | case N_MNEM_vorr: |
036dc3f7 | 13288 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 13289 | break; |
5f4273c7 | 13290 | |
5287ad62 JB |
13291 | case N_MNEM_vand: |
13292 | /* Pseudo-instruction for VBIC. */ | |
5287ad62 JB |
13293 | neon_invert_size (&immbits, 0, et.size); |
13294 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
13295 | break; | |
5f4273c7 | 13296 | |
5287ad62 JB |
13297 | case N_MNEM_vorn: |
13298 | /* Pseudo-instruction for VORR. */ | |
5287ad62 JB |
13299 | neon_invert_size (&immbits, 0, et.size); |
13300 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
13301 | break; | |
5f4273c7 | 13302 | |
5287ad62 JB |
13303 | default: |
13304 | abort (); | |
13305 | } | |
13306 | ||
13307 | if (cmode == FAIL) | |
13308 | return; | |
13309 | ||
037e8744 | 13310 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13311 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13312 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13313 | inst.instruction |= cmode << 8; | |
13314 | neon_write_immbits (immbits); | |
5f4273c7 | 13315 | |
88714cb8 | 13316 | neon_dp_fixup (&inst); |
5287ad62 JB |
13317 | } |
13318 | } | |
13319 | ||
13320 | static void | |
13321 | do_neon_bitfield (void) | |
13322 | { | |
037e8744 | 13323 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 13324 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 13325 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13326 | } |
13327 | ||
13328 | static void | |
dcbf9037 JB |
13329 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
13330 | unsigned destbits) | |
5287ad62 | 13331 | { |
037e8744 | 13332 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
13333 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
13334 | types | N_KEY); | |
5287ad62 JB |
13335 | if (et.type == NT_float) |
13336 | { | |
88714cb8 | 13337 | NEON_ENCODE (FLOAT, inst); |
037e8744 | 13338 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13339 | } |
13340 | else | |
13341 | { | |
88714cb8 | 13342 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 13343 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
13344 | } |
13345 | } | |
13346 | ||
13347 | static void | |
13348 | do_neon_dyadic_if_su (void) | |
13349 | { | |
dcbf9037 | 13350 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
13351 | } |
13352 | ||
13353 | static void | |
13354 | do_neon_dyadic_if_su_d (void) | |
13355 | { | |
13356 | /* This version only allow D registers, but that constraint is enforced during | |
13357 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 13358 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
13359 | } |
13360 | ||
5287ad62 JB |
13361 | static void |
13362 | do_neon_dyadic_if_i_d (void) | |
13363 | { | |
428e3f1f PB |
13364 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
13365 | affected if we specify unsigned args. */ | |
13366 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
13367 | } |
13368 | ||
037e8744 JB |
13369 | enum vfp_or_neon_is_neon_bits |
13370 | { | |
13371 | NEON_CHECK_CC = 1, | |
13372 | NEON_CHECK_ARCH = 2 | |
13373 | }; | |
13374 | ||
13375 | /* Call this function if an instruction which may have belonged to the VFP or | |
13376 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
13377 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
13378 | things: | |
13379 | ||
13380 | - Make sure the user hasn't attempted to make a Neon instruction | |
13381 | conditional. | |
13382 | - Alter the value in the condition code field if necessary. | |
13383 | - Make sure that the arch supports Neon instructions. | |
13384 | ||
13385 | Which of these operations take place depends on bits from enum | |
13386 | vfp_or_neon_is_neon_bits. | |
13387 | ||
13388 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
13389 | current instruction's condition is COND_ALWAYS, the condition field is | |
13390 | changed to inst.uncond_value. This is necessary because instructions shared | |
13391 | between VFP and Neon may be conditional for the VFP variants only, and the | |
13392 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
13393 | ||
13394 | static int | |
13395 | vfp_or_neon_is_neon (unsigned check) | |
13396 | { | |
13397 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
13398 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
13399 | { | |
13400 | if (inst.cond != COND_ALWAYS) | |
13401 | { | |
13402 | first_error (_(BAD_COND)); | |
13403 | return FAIL; | |
13404 | } | |
13405 | if (inst.uncond_value != -1) | |
13406 | inst.instruction |= inst.uncond_value << 28; | |
13407 | } | |
5f4273c7 | 13408 | |
037e8744 JB |
13409 | if ((check & NEON_CHECK_ARCH) |
13410 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
13411 | { | |
13412 | first_error (_(BAD_FPU)); | |
13413 | return FAIL; | |
13414 | } | |
5f4273c7 | 13415 | |
037e8744 JB |
13416 | return SUCCESS; |
13417 | } | |
13418 | ||
5287ad62 JB |
13419 | static void |
13420 | do_neon_addsub_if_i (void) | |
13421 | { | |
037e8744 JB |
13422 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
13423 | return; | |
13424 | ||
13425 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13426 | return; | |
13427 | ||
5287ad62 JB |
13428 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
13429 | affected if we specify unsigned args. */ | |
dcbf9037 | 13430 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
13431 | } |
13432 | ||
13433 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
13434 | result to be: | |
13435 | V<op> A,B (A is operand 0, B is operand 2) | |
13436 | to mean: | |
13437 | V<op> A,B,A | |
13438 | not: | |
13439 | V<op> A,B,B | |
13440 | so handle that case specially. */ | |
13441 | ||
13442 | static void | |
13443 | neon_exchange_operands (void) | |
13444 | { | |
13445 | void *scratch = alloca (sizeof (inst.operands[0])); | |
13446 | if (inst.operands[1].present) | |
13447 | { | |
13448 | /* Swap operands[1] and operands[2]. */ | |
13449 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
13450 | inst.operands[1] = inst.operands[2]; | |
13451 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
13452 | } | |
13453 | else | |
13454 | { | |
13455 | inst.operands[1] = inst.operands[2]; | |
13456 | inst.operands[2] = inst.operands[0]; | |
13457 | } | |
13458 | } | |
13459 | ||
13460 | static void | |
13461 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
13462 | { | |
13463 | if (inst.operands[2].isreg) | |
13464 | { | |
13465 | if (invert) | |
13466 | neon_exchange_operands (); | |
dcbf9037 | 13467 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
13468 | } |
13469 | else | |
13470 | { | |
037e8744 | 13471 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
13472 | struct neon_type_el et = neon_check_type (2, rs, |
13473 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 | 13474 | |
88714cb8 | 13475 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
13476 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13477 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13478 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13479 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13480 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13481 | inst.instruction |= (et.type == NT_float) << 10; |
13482 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13483 | |
88714cb8 | 13484 | neon_dp_fixup (&inst); |
5287ad62 JB |
13485 | } |
13486 | } | |
13487 | ||
13488 | static void | |
13489 | do_neon_cmp (void) | |
13490 | { | |
13491 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
13492 | } | |
13493 | ||
13494 | static void | |
13495 | do_neon_cmp_inv (void) | |
13496 | { | |
13497 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
13498 | } | |
13499 | ||
13500 | static void | |
13501 | do_neon_ceq (void) | |
13502 | { | |
13503 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
13504 | } | |
13505 | ||
13506 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
13507 | scalars, which are encoded in 5 bits, M : Rm. | |
13508 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
13509 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
13510 | index in M. */ | |
13511 | ||
13512 | static unsigned | |
13513 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
13514 | { | |
dcbf9037 JB |
13515 | unsigned regno = NEON_SCALAR_REG (scalar); |
13516 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
13517 | |
13518 | switch (elsize) | |
13519 | { | |
13520 | case 16: | |
13521 | if (regno > 7 || elno > 3) | |
13522 | goto bad_scalar; | |
13523 | return regno | (elno << 3); | |
5f4273c7 | 13524 | |
5287ad62 JB |
13525 | case 32: |
13526 | if (regno > 15 || elno > 1) | |
13527 | goto bad_scalar; | |
13528 | return regno | (elno << 4); | |
13529 | ||
13530 | default: | |
13531 | bad_scalar: | |
dcbf9037 | 13532 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
13533 | } |
13534 | ||
13535 | return 0; | |
13536 | } | |
13537 | ||
13538 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
13539 | ||
13540 | static void | |
13541 | neon_mul_mac (struct neon_type_el et, int ubit) | |
13542 | { | |
dcbf9037 JB |
13543 | unsigned scalar; |
13544 | ||
13545 | /* Give a more helpful error message if we have an invalid type. */ | |
13546 | if (et.type == NT_invtype) | |
13547 | return; | |
5f4273c7 | 13548 | |
dcbf9037 | 13549 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
13550 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13551 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13552 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13553 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13554 | inst.instruction |= LOW4 (scalar); | |
13555 | inst.instruction |= HI1 (scalar) << 5; | |
13556 | inst.instruction |= (et.type == NT_float) << 8; | |
13557 | inst.instruction |= neon_logbits (et.size) << 20; | |
13558 | inst.instruction |= (ubit != 0) << 24; | |
13559 | ||
88714cb8 | 13560 | neon_dp_fixup (&inst); |
5287ad62 JB |
13561 | } |
13562 | ||
13563 | static void | |
13564 | do_neon_mac_maybe_scalar (void) | |
13565 | { | |
037e8744 JB |
13566 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
13567 | return; | |
13568 | ||
13569 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13570 | return; | |
13571 | ||
5287ad62 JB |
13572 | if (inst.operands[2].isscalar) |
13573 | { | |
037e8744 | 13574 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13575 | struct neon_type_el et = neon_check_type (3, rs, |
13576 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
88714cb8 | 13577 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 13578 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13579 | } |
13580 | else | |
428e3f1f PB |
13581 | { |
13582 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
13583 | affected if we specify unsigned args. */ | |
13584 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
13585 | } | |
5287ad62 JB |
13586 | } |
13587 | ||
62f3b8c8 PB |
13588 | static void |
13589 | do_neon_fmac (void) | |
13590 | { | |
13591 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
13592 | return; | |
13593 | ||
13594 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13595 | return; | |
13596 | ||
13597 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
13598 | } | |
13599 | ||
5287ad62 JB |
13600 | static void |
13601 | do_neon_tst (void) | |
13602 | { | |
037e8744 | 13603 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13604 | struct neon_type_el et = neon_check_type (3, rs, |
13605 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 13606 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13607 | } |
13608 | ||
13609 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
13610 | same types as the MAC equivalents. The polynomial type for this instruction | |
13611 | is encoded the same as the integer type. */ | |
13612 | ||
13613 | static void | |
13614 | do_neon_mul (void) | |
13615 | { | |
037e8744 JB |
13616 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
13617 | return; | |
13618 | ||
13619 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13620 | return; | |
13621 | ||
5287ad62 JB |
13622 | if (inst.operands[2].isscalar) |
13623 | do_neon_mac_maybe_scalar (); | |
13624 | else | |
dcbf9037 | 13625 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
13626 | } |
13627 | ||
13628 | static void | |
13629 | do_neon_qdmulh (void) | |
13630 | { | |
13631 | if (inst.operands[2].isscalar) | |
13632 | { | |
037e8744 | 13633 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13634 | struct neon_type_el et = neon_check_type (3, rs, |
13635 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
88714cb8 | 13636 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 13637 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13638 | } |
13639 | else | |
13640 | { | |
037e8744 | 13641 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13642 | struct neon_type_el et = neon_check_type (3, rs, |
13643 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
88714cb8 | 13644 | NEON_ENCODE (INTEGER, inst); |
5287ad62 | 13645 | /* The U bit (rounding) comes from bit mask. */ |
037e8744 | 13646 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13647 | } |
13648 | } | |
13649 | ||
13650 | static void | |
13651 | do_neon_fcmp_absolute (void) | |
13652 | { | |
037e8744 | 13653 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13654 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
13655 | /* Size field comes from bit mask. */ | |
037e8744 | 13656 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
13657 | } |
13658 | ||
13659 | static void | |
13660 | do_neon_fcmp_absolute_inv (void) | |
13661 | { | |
13662 | neon_exchange_operands (); | |
13663 | do_neon_fcmp_absolute (); | |
13664 | } | |
13665 | ||
13666 | static void | |
13667 | do_neon_step (void) | |
13668 | { | |
037e8744 | 13669 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 13670 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 13671 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13672 | } |
13673 | ||
13674 | static void | |
13675 | do_neon_abs_neg (void) | |
13676 | { | |
037e8744 JB |
13677 | enum neon_shape rs; |
13678 | struct neon_type_el et; | |
5f4273c7 | 13679 | |
037e8744 JB |
13680 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
13681 | return; | |
13682 | ||
13683 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13684 | return; | |
13685 | ||
13686 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
13687 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
5f4273c7 | 13688 | |
5287ad62 JB |
13689 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13690 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13691 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13692 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13693 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13694 | inst.instruction |= (et.type == NT_float) << 10; |
13695 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13696 | |
88714cb8 | 13697 | neon_dp_fixup (&inst); |
5287ad62 JB |
13698 | } |
13699 | ||
13700 | static void | |
13701 | do_neon_sli (void) | |
13702 | { | |
037e8744 | 13703 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13704 | struct neon_type_el et = neon_check_type (2, rs, |
13705 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13706 | int imm = inst.operands[2].imm; | |
13707 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13708 | _("immediate out of range for insert")); | |
037e8744 | 13709 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13710 | } |
13711 | ||
13712 | static void | |
13713 | do_neon_sri (void) | |
13714 | { | |
037e8744 | 13715 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13716 | struct neon_type_el et = neon_check_type (2, rs, |
13717 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13718 | int imm = inst.operands[2].imm; | |
13719 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13720 | _("immediate out of range for insert")); | |
037e8744 | 13721 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
13722 | } |
13723 | ||
13724 | static void | |
13725 | do_neon_qshlu_imm (void) | |
13726 | { | |
037e8744 | 13727 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13728 | struct neon_type_el et = neon_check_type (2, rs, |
13729 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
13730 | int imm = inst.operands[2].imm; | |
13731 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13732 | _("immediate out of range for shift")); | |
13733 | /* Only encodes the 'U present' variant of the instruction. | |
13734 | In this case, signed types have OP (bit 8) set to 0. | |
13735 | Unsigned types have OP set to 1. */ | |
13736 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
13737 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 13738 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13739 | } |
13740 | ||
13741 | static void | |
13742 | do_neon_qmovn (void) | |
13743 | { | |
13744 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13745 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13746 | /* Saturating move where operands can be signed or unsigned, and the | |
13747 | destination has the same signedness. */ | |
88714cb8 | 13748 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
13749 | if (et.type == NT_unsigned) |
13750 | inst.instruction |= 0xc0; | |
13751 | else | |
13752 | inst.instruction |= 0x80; | |
13753 | neon_two_same (0, 1, et.size / 2); | |
13754 | } | |
13755 | ||
13756 | static void | |
13757 | do_neon_qmovun (void) | |
13758 | { | |
13759 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13760 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13761 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 13762 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
13763 | neon_two_same (0, 1, et.size / 2); |
13764 | } | |
13765 | ||
13766 | static void | |
13767 | do_neon_rshift_sat_narrow (void) | |
13768 | { | |
13769 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13770 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13771 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13772 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13773 | int imm = inst.operands[2].imm; | |
13774 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13775 | right. */ | |
13776 | et.size /= 2; | |
5f4273c7 | 13777 | |
5287ad62 JB |
13778 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
13779 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
13780 | if (imm == 0) | |
13781 | { | |
13782 | inst.operands[2].present = 0; | |
13783 | inst.instruction = N_MNEM_vqmovn; | |
13784 | do_neon_qmovn (); | |
13785 | return; | |
13786 | } | |
5f4273c7 | 13787 | |
5287ad62 JB |
13788 | constraint (imm < 1 || (unsigned)imm > et.size, |
13789 | _("immediate out of range")); | |
13790 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
13791 | } | |
13792 | ||
13793 | static void | |
13794 | do_neon_rshift_sat_narrow_u (void) | |
13795 | { | |
13796 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13797 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13798 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13799 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13800 | int imm = inst.operands[2].imm; | |
13801 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13802 | right. */ | |
13803 | et.size /= 2; | |
13804 | ||
13805 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
13806 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
13807 | if (imm == 0) | |
13808 | { | |
13809 | inst.operands[2].present = 0; | |
13810 | inst.instruction = N_MNEM_vqmovun; | |
13811 | do_neon_qmovun (); | |
13812 | return; | |
13813 | } | |
13814 | ||
13815 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13816 | _("immediate out of range")); | |
13817 | /* FIXME: The manual is kind of unclear about what value U should have in | |
13818 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
13819 | must be 1. */ | |
13820 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
13821 | } | |
13822 | ||
13823 | static void | |
13824 | do_neon_movn (void) | |
13825 | { | |
13826 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13827 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 13828 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
13829 | neon_two_same (0, 1, et.size / 2); |
13830 | } | |
13831 | ||
13832 | static void | |
13833 | do_neon_rshift_narrow (void) | |
13834 | { | |
13835 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13836 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13837 | int imm = inst.operands[2].imm; | |
13838 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13839 | right. */ | |
13840 | et.size /= 2; | |
5f4273c7 | 13841 | |
5287ad62 JB |
13842 | /* If immediate is zero then we are a pseudo-instruction for |
13843 | VMOVN.I<size> <Dd>, <Qm> */ | |
13844 | if (imm == 0) | |
13845 | { | |
13846 | inst.operands[2].present = 0; | |
13847 | inst.instruction = N_MNEM_vmovn; | |
13848 | do_neon_movn (); | |
13849 | return; | |
13850 | } | |
5f4273c7 | 13851 | |
5287ad62 JB |
13852 | constraint (imm < 1 || (unsigned)imm > et.size, |
13853 | _("immediate out of range for narrowing operation")); | |
13854 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
13855 | } | |
13856 | ||
13857 | static void | |
13858 | do_neon_shll (void) | |
13859 | { | |
13860 | /* FIXME: Type checking when lengthening. */ | |
13861 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
13862 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
13863 | unsigned imm = inst.operands[2].imm; | |
13864 | ||
13865 | if (imm == et.size) | |
13866 | { | |
13867 | /* Maximum shift variant. */ | |
88714cb8 | 13868 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
13869 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13870 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13871 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13872 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13873 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13874 | |
88714cb8 | 13875 | neon_dp_fixup (&inst); |
5287ad62 JB |
13876 | } |
13877 | else | |
13878 | { | |
13879 | /* A more-specific type check for non-max versions. */ | |
13880 | et = neon_check_type (2, NS_QDI, | |
13881 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
88714cb8 | 13882 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
13883 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
13884 | } | |
13885 | } | |
13886 | ||
037e8744 | 13887 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
13888 | the current instruction is. */ |
13889 | ||
13890 | static int | |
13891 | neon_cvt_flavour (enum neon_shape rs) | |
13892 | { | |
037e8744 JB |
13893 | #define CVT_VAR(C,X,Y) \ |
13894 | et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \ | |
13895 | if (et.type != NT_invtype) \ | |
13896 | { \ | |
13897 | inst.error = NULL; \ | |
13898 | return (C); \ | |
5287ad62 JB |
13899 | } |
13900 | struct neon_type_el et; | |
037e8744 JB |
13901 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
13902 | || rs == NS_FF) ? N_VFP : 0; | |
13903 | /* The instruction versions which take an immediate take one register | |
13904 | argument, which is extended to the width of the full register. Thus the | |
13905 | "source" and "destination" registers must have the same width. Hack that | |
13906 | here by making the size equal to the key (wider, in this case) operand. */ | |
13907 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 13908 | |
5287ad62 JB |
13909 | CVT_VAR (0, N_S32, N_F32); |
13910 | CVT_VAR (1, N_U32, N_F32); | |
13911 | CVT_VAR (2, N_F32, N_S32); | |
13912 | CVT_VAR (3, N_F32, N_U32); | |
8e79c3df CM |
13913 | /* Half-precision conversions. */ |
13914 | CVT_VAR (4, N_F32, N_F16); | |
13915 | CVT_VAR (5, N_F16, N_F32); | |
5f4273c7 | 13916 | |
037e8744 | 13917 | whole_reg = N_VFP; |
5f4273c7 | 13918 | |
037e8744 | 13919 | /* VFP instructions. */ |
8e79c3df CM |
13920 | CVT_VAR (6, N_F32, N_F64); |
13921 | CVT_VAR (7, N_F64, N_F32); | |
13922 | CVT_VAR (8, N_S32, N_F64 | key); | |
13923 | CVT_VAR (9, N_U32, N_F64 | key); | |
13924 | CVT_VAR (10, N_F64 | key, N_S32); | |
13925 | CVT_VAR (11, N_F64 | key, N_U32); | |
037e8744 | 13926 | /* VFP instructions with bitshift. */ |
8e79c3df CM |
13927 | CVT_VAR (12, N_F32 | key, N_S16); |
13928 | CVT_VAR (13, N_F32 | key, N_U16); | |
13929 | CVT_VAR (14, N_F64 | key, N_S16); | |
13930 | CVT_VAR (15, N_F64 | key, N_U16); | |
13931 | CVT_VAR (16, N_S16, N_F32 | key); | |
13932 | CVT_VAR (17, N_U16, N_F32 | key); | |
13933 | CVT_VAR (18, N_S16, N_F64 | key); | |
13934 | CVT_VAR (19, N_U16, N_F64 | key); | |
5f4273c7 | 13935 | |
5287ad62 JB |
13936 | return -1; |
13937 | #undef CVT_VAR | |
13938 | } | |
13939 | ||
037e8744 JB |
13940 | /* Neon-syntax VFP conversions. */ |
13941 | ||
5287ad62 | 13942 | static void |
037e8744 | 13943 | do_vfp_nsyn_cvt (enum neon_shape rs, int flavour) |
5287ad62 | 13944 | { |
037e8744 | 13945 | const char *opname = 0; |
5f4273c7 | 13946 | |
037e8744 | 13947 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) |
5287ad62 | 13948 | { |
037e8744 JB |
13949 | /* Conversions with immediate bitshift. */ |
13950 | const char *enc[] = | |
13951 | { | |
13952 | "ftosls", | |
13953 | "ftouls", | |
13954 | "fsltos", | |
13955 | "fultos", | |
13956 | NULL, | |
13957 | NULL, | |
8e79c3df CM |
13958 | NULL, |
13959 | NULL, | |
037e8744 JB |
13960 | "ftosld", |
13961 | "ftould", | |
13962 | "fsltod", | |
13963 | "fultod", | |
13964 | "fshtos", | |
13965 | "fuhtos", | |
13966 | "fshtod", | |
13967 | "fuhtod", | |
13968 | "ftoshs", | |
13969 | "ftouhs", | |
13970 | "ftoshd", | |
13971 | "ftouhd" | |
13972 | }; | |
13973 | ||
13974 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13975 | { | |
13976 | opname = enc[flavour]; | |
13977 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13978 | _("operands 0 and 1 must be the same register")); | |
13979 | inst.operands[1] = inst.operands[2]; | |
13980 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
13981 | } | |
5287ad62 JB |
13982 | } |
13983 | else | |
13984 | { | |
037e8744 JB |
13985 | /* Conversions without bitshift. */ |
13986 | const char *enc[] = | |
13987 | { | |
13988 | "ftosis", | |
13989 | "ftouis", | |
13990 | "fsitos", | |
13991 | "fuitos", | |
8e79c3df CM |
13992 | "NULL", |
13993 | "NULL", | |
037e8744 JB |
13994 | "fcvtsd", |
13995 | "fcvtds", | |
13996 | "ftosid", | |
13997 | "ftouid", | |
13998 | "fsitod", | |
13999 | "fuitod" | |
14000 | }; | |
14001 | ||
14002 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
14003 | opname = enc[flavour]; | |
14004 | } | |
14005 | ||
14006 | if (opname) | |
14007 | do_vfp_nsyn_opcode (opname); | |
14008 | } | |
14009 | ||
14010 | static void | |
14011 | do_vfp_nsyn_cvtz (void) | |
14012 | { | |
14013 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
14014 | int flavour = neon_cvt_flavour (rs); | |
14015 | const char *enc[] = | |
14016 | { | |
14017 | "ftosizs", | |
14018 | "ftouizs", | |
14019 | NULL, | |
14020 | NULL, | |
14021 | NULL, | |
14022 | NULL, | |
8e79c3df CM |
14023 | NULL, |
14024 | NULL, | |
037e8744 JB |
14025 | "ftosizd", |
14026 | "ftouizd" | |
14027 | }; | |
14028 | ||
14029 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) | |
14030 | do_vfp_nsyn_opcode (enc[flavour]); | |
14031 | } | |
f31fef98 | 14032 | |
037e8744 | 14033 | static void |
e3e535bc | 14034 | do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED) |
037e8744 JB |
14035 | { |
14036 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
8e79c3df | 14037 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL); |
037e8744 JB |
14038 | int flavour = neon_cvt_flavour (rs); |
14039 | ||
e3e535bc NC |
14040 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
14041 | if (round_to_zero | |
14042 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) | |
14043 | && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9) | |
14044 | && (rs == NS_FD || rs == NS_FF)) | |
14045 | { | |
14046 | do_vfp_nsyn_cvtz (); | |
14047 | return; | |
14048 | } | |
14049 | ||
037e8744 | 14050 | /* VFP rather than Neon conversions. */ |
8e79c3df | 14051 | if (flavour >= 6) |
037e8744 JB |
14052 | { |
14053 | do_vfp_nsyn_cvt (rs, flavour); | |
14054 | return; | |
14055 | } | |
14056 | ||
14057 | switch (rs) | |
14058 | { | |
14059 | case NS_DDI: | |
14060 | case NS_QQI: | |
14061 | { | |
35997600 NC |
14062 | unsigned immbits; |
14063 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
14064 | ||
037e8744 JB |
14065 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
14066 | return; | |
14067 | ||
14068 | /* Fixed-point conversion with #0 immediate is encoded as an | |
14069 | integer conversion. */ | |
14070 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
14071 | goto int_encode; | |
35997600 | 14072 | immbits = 32 - inst.operands[2].imm; |
88714cb8 | 14073 | NEON_ENCODE (IMMED, inst); |
037e8744 JB |
14074 | if (flavour != -1) |
14075 | inst.instruction |= enctab[flavour]; | |
14076 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14077 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14078 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14079 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14080 | inst.instruction |= neon_quad (rs) << 6; | |
14081 | inst.instruction |= 1 << 21; | |
14082 | inst.instruction |= immbits << 16; | |
14083 | ||
88714cb8 | 14084 | neon_dp_fixup (&inst); |
037e8744 JB |
14085 | } |
14086 | break; | |
14087 | ||
14088 | case NS_DD: | |
14089 | case NS_QQ: | |
14090 | int_encode: | |
14091 | { | |
14092 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
14093 | ||
88714cb8 | 14094 | NEON_ENCODE (INTEGER, inst); |
037e8744 JB |
14095 | |
14096 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14097 | return; | |
14098 | ||
14099 | if (flavour != -1) | |
14100 | inst.instruction |= enctab[flavour]; | |
14101 | ||
14102 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14103 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14104 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14105 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14106 | inst.instruction |= neon_quad (rs) << 6; | |
14107 | inst.instruction |= 2 << 18; | |
14108 | ||
88714cb8 | 14109 | neon_dp_fixup (&inst); |
037e8744 JB |
14110 | } |
14111 | break; | |
14112 | ||
8e79c3df CM |
14113 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
14114 | case NS_QD: | |
14115 | case NS_DQ: | |
14116 | ||
14117 | if ((rs == NS_DQ) | |
14118 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
14119 | { | |
14120 | as_bad (_("operand size must match register width")); | |
14121 | break; | |
14122 | } | |
14123 | ||
14124 | if ((rs == NS_QD) | |
14125 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
14126 | { | |
14127 | as_bad (_("operand size must match register width")); | |
14128 | break; | |
14129 | } | |
14130 | ||
14131 | if (rs == NS_DQ) | |
14132 | inst.instruction = 0x3b60600; | |
14133 | else | |
14134 | inst.instruction = 0x3b60700; | |
14135 | ||
14136 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14137 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14138 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14139 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 14140 | neon_dp_fixup (&inst); |
8e79c3df CM |
14141 | break; |
14142 | ||
037e8744 JB |
14143 | default: |
14144 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
14145 | do_vfp_nsyn_cvt (rs, flavour); | |
5287ad62 | 14146 | } |
5287ad62 JB |
14147 | } |
14148 | ||
e3e535bc NC |
14149 | static void |
14150 | do_neon_cvtr (void) | |
14151 | { | |
14152 | do_neon_cvt_1 (FALSE); | |
14153 | } | |
14154 | ||
14155 | static void | |
14156 | do_neon_cvt (void) | |
14157 | { | |
14158 | do_neon_cvt_1 (TRUE); | |
14159 | } | |
14160 | ||
8e79c3df CM |
14161 | static void |
14162 | do_neon_cvtb (void) | |
14163 | { | |
14164 | inst.instruction = 0xeb20a40; | |
14165 | ||
14166 | /* The sizes are attached to the mnemonic. */ | |
14167 | if (inst.vectype.el[0].type != NT_invtype | |
14168 | && inst.vectype.el[0].size == 16) | |
14169 | inst.instruction |= 0x00010000; | |
14170 | ||
14171 | /* Programmer's syntax: the sizes are attached to the operands. */ | |
14172 | else if (inst.operands[0].vectype.type != NT_invtype | |
14173 | && inst.operands[0].vectype.size == 16) | |
14174 | inst.instruction |= 0x00010000; | |
14175 | ||
14176 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
14177 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
14178 | do_vfp_cond_or_thumb (); | |
14179 | } | |
14180 | ||
14181 | ||
14182 | static void | |
14183 | do_neon_cvtt (void) | |
14184 | { | |
14185 | do_neon_cvtb (); | |
14186 | inst.instruction |= 0x80; | |
14187 | } | |
14188 | ||
5287ad62 JB |
14189 | static void |
14190 | neon_move_immediate (void) | |
14191 | { | |
037e8744 JB |
14192 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
14193 | struct neon_type_el et = neon_check_type (2, rs, | |
14194 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 14195 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 14196 | int op, cmode, float_p; |
5287ad62 | 14197 | |
037e8744 JB |
14198 | constraint (et.type == NT_invtype, |
14199 | _("operand size must be specified for immediate VMOV")); | |
14200 | ||
5287ad62 JB |
14201 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
14202 | op = (inst.instruction & (1 << 5)) != 0; | |
14203 | ||
14204 | immlo = inst.operands[1].imm; | |
14205 | if (inst.operands[1].regisimm) | |
14206 | immhi = inst.operands[1].reg; | |
14207 | ||
14208 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
14209 | _("immediate has bits set outside the operand size")); | |
14210 | ||
c96612cc JB |
14211 | float_p = inst.operands[1].immisfloat; |
14212 | ||
14213 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
136da414 | 14214 | et.size, et.type)) == FAIL) |
5287ad62 JB |
14215 | { |
14216 | /* Invert relevant bits only. */ | |
14217 | neon_invert_size (&immlo, &immhi, et.size); | |
14218 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
14219 | with one or the other; those cases are caught by | |
14220 | neon_cmode_for_move_imm. */ | |
14221 | op = !op; | |
c96612cc JB |
14222 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
14223 | &op, et.size, et.type)) == FAIL) | |
5287ad62 | 14224 | { |
dcbf9037 | 14225 | first_error (_("immediate out of range")); |
5287ad62 JB |
14226 | return; |
14227 | } | |
14228 | } | |
14229 | ||
14230 | inst.instruction &= ~(1 << 5); | |
14231 | inst.instruction |= op << 5; | |
14232 | ||
14233 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14234 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 14235 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14236 | inst.instruction |= cmode << 8; |
14237 | ||
14238 | neon_write_immbits (immbits); | |
14239 | } | |
14240 | ||
14241 | static void | |
14242 | do_neon_mvn (void) | |
14243 | { | |
14244 | if (inst.operands[1].isreg) | |
14245 | { | |
037e8744 | 14246 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 14247 | |
88714cb8 | 14248 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14249 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14250 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14251 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14252 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 14253 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14254 | } |
14255 | else | |
14256 | { | |
88714cb8 | 14257 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
14258 | neon_move_immediate (); |
14259 | } | |
14260 | ||
88714cb8 | 14261 | neon_dp_fixup (&inst); |
5287ad62 JB |
14262 | } |
14263 | ||
14264 | /* Encode instructions of form: | |
14265 | ||
14266 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 14267 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
14268 | |
14269 | static void | |
14270 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
14271 | { | |
14272 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14273 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14274 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14275 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14276 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14277 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14278 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
14279 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 14280 | |
88714cb8 | 14281 | neon_dp_fixup (&inst); |
5287ad62 JB |
14282 | } |
14283 | ||
14284 | static void | |
14285 | do_neon_dyadic_long (void) | |
14286 | { | |
14287 | /* FIXME: Type checking for lengthening op. */ | |
14288 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
14289 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
14290 | neon_mixed_length (et, et.size); | |
14291 | } | |
14292 | ||
14293 | static void | |
14294 | do_neon_abal (void) | |
14295 | { | |
14296 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
14297 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
14298 | neon_mixed_length (et, et.size); | |
14299 | } | |
14300 | ||
14301 | static void | |
14302 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
14303 | { | |
14304 | if (inst.operands[2].isscalar) | |
14305 | { | |
dcbf9037 JB |
14306 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
14307 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
88714cb8 | 14308 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
14309 | neon_mul_mac (et, et.type == NT_unsigned); |
14310 | } | |
14311 | else | |
14312 | { | |
14313 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
14314 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
88714cb8 | 14315 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14316 | neon_mixed_length (et, et.size); |
14317 | } | |
14318 | } | |
14319 | ||
14320 | static void | |
14321 | do_neon_mac_maybe_scalar_long (void) | |
14322 | { | |
14323 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
14324 | } | |
14325 | ||
14326 | static void | |
14327 | do_neon_dyadic_wide (void) | |
14328 | { | |
14329 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
14330 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
14331 | neon_mixed_length (et, et.size); | |
14332 | } | |
14333 | ||
14334 | static void | |
14335 | do_neon_dyadic_narrow (void) | |
14336 | { | |
14337 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
14338 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
14339 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
14340 | so force the operand type to integer. */ | |
14341 | et.type = NT_integer; | |
5287ad62 JB |
14342 | neon_mixed_length (et, et.size / 2); |
14343 | } | |
14344 | ||
14345 | static void | |
14346 | do_neon_mul_sat_scalar_long (void) | |
14347 | { | |
14348 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
14349 | } | |
14350 | ||
14351 | static void | |
14352 | do_neon_vmull (void) | |
14353 | { | |
14354 | if (inst.operands[2].isscalar) | |
14355 | do_neon_mac_maybe_scalar_long (); | |
14356 | else | |
14357 | { | |
14358 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
14359 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY); | |
14360 | if (et.type == NT_poly) | |
88714cb8 | 14361 | NEON_ENCODE (POLY, inst); |
5287ad62 | 14362 | else |
88714cb8 | 14363 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14364 | /* For polynomial encoding, size field must be 0b00 and the U bit must be |
14365 | zero. Should be OK as-is. */ | |
14366 | neon_mixed_length (et, et.size); | |
14367 | } | |
14368 | } | |
14369 | ||
14370 | static void | |
14371 | do_neon_ext (void) | |
14372 | { | |
037e8744 | 14373 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
14374 | struct neon_type_el et = neon_check_type (3, rs, |
14375 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
14376 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
14377 | |
14378 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
14379 | _("shift out of range")); | |
5287ad62 JB |
14380 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14381 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14382 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14383 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14384 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14385 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 14386 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 14387 | inst.instruction |= imm << 8; |
5f4273c7 | 14388 | |
88714cb8 | 14389 | neon_dp_fixup (&inst); |
5287ad62 JB |
14390 | } |
14391 | ||
14392 | static void | |
14393 | do_neon_rev (void) | |
14394 | { | |
037e8744 | 14395 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14396 | struct neon_type_el et = neon_check_type (2, rs, |
14397 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14398 | unsigned op = (inst.instruction >> 7) & 3; | |
14399 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
14400 | extract it here to check the elements to be reversed are smaller. | |
14401 | Otherwise we'd get a reserved instruction. */ | |
14402 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 14403 | gas_assert (elsize != 0); |
5287ad62 JB |
14404 | constraint (et.size >= elsize, |
14405 | _("elements must be smaller than reversal region")); | |
037e8744 | 14406 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14407 | } |
14408 | ||
14409 | static void | |
14410 | do_neon_dup (void) | |
14411 | { | |
14412 | if (inst.operands[1].isscalar) | |
14413 | { | |
037e8744 | 14414 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
14415 | struct neon_type_el et = neon_check_type (2, rs, |
14416 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 14417 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 14418 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 14419 | int logsize = neon_logbits (et.size); |
dcbf9037 | 14420 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
14421 | |
14422 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
14423 | return; | |
14424 | ||
88714cb8 | 14425 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
14426 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14427 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14428 | inst.instruction |= LOW4 (dm); | |
14429 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 14430 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14431 | inst.instruction |= x << 17; |
14432 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 14433 | |
88714cb8 | 14434 | neon_dp_fixup (&inst); |
5287ad62 JB |
14435 | } |
14436 | else | |
14437 | { | |
037e8744 JB |
14438 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
14439 | struct neon_type_el et = neon_check_type (2, rs, | |
14440 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 | 14441 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 14442 | NEON_ENCODE (ARMREG, inst); |
5287ad62 JB |
14443 | switch (et.size) |
14444 | { | |
14445 | case 8: inst.instruction |= 0x400000; break; | |
14446 | case 16: inst.instruction |= 0x000020; break; | |
14447 | case 32: inst.instruction |= 0x000000; break; | |
14448 | default: break; | |
14449 | } | |
14450 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
14451 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
14452 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 14453 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
14454 | /* The encoding for this instruction is identical for the ARM and Thumb |
14455 | variants, except for the condition field. */ | |
037e8744 | 14456 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
14457 | } |
14458 | } | |
14459 | ||
14460 | /* VMOV has particularly many variations. It can be one of: | |
14461 | 0. VMOV<c><q> <Qd>, <Qm> | |
14462 | 1. VMOV<c><q> <Dd>, <Dm> | |
14463 | (Register operations, which are VORR with Rm = Rn.) | |
14464 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
14465 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
14466 | (Immediate loads.) | |
14467 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
14468 | (ARM register to scalar.) | |
14469 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
14470 | (Two ARM registers to vector.) | |
14471 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
14472 | (Scalar to ARM register.) | |
14473 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
14474 | (Vector to two ARM registers.) | |
037e8744 JB |
14475 | 8. VMOV.F32 <Sd>, <Sm> |
14476 | 9. VMOV.F64 <Dd>, <Dm> | |
14477 | (VFP register moves.) | |
14478 | 10. VMOV.F32 <Sd>, #imm | |
14479 | 11. VMOV.F64 <Dd>, #imm | |
14480 | (VFP float immediate load.) | |
14481 | 12. VMOV <Rd>, <Sm> | |
14482 | (VFP single to ARM reg.) | |
14483 | 13. VMOV <Sd>, <Rm> | |
14484 | (ARM reg to VFP single.) | |
14485 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
14486 | (Two ARM regs to two VFP singles.) | |
14487 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
14488 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 14489 | |
037e8744 JB |
14490 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
14491 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 14492 | |
5287ad62 | 14493 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 14494 | |
b7fc2769 JB |
14495 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
14496 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 14497 | |
5287ad62 | 14498 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 14499 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
14500 | |
14501 | static void | |
14502 | do_neon_mov (void) | |
14503 | { | |
037e8744 JB |
14504 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
14505 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
14506 | NS_NULL); | |
14507 | struct neon_type_el et; | |
14508 | const char *ldconst = 0; | |
5287ad62 | 14509 | |
037e8744 | 14510 | switch (rs) |
5287ad62 | 14511 | { |
037e8744 JB |
14512 | case NS_DD: /* case 1/9. */ |
14513 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
14514 | /* It is not an error here if no type is given. */ | |
14515 | inst.error = NULL; | |
14516 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 14517 | { |
037e8744 JB |
14518 | do_vfp_nsyn_opcode ("fcpyd"); |
14519 | break; | |
5287ad62 | 14520 | } |
037e8744 | 14521 | /* fall through. */ |
5287ad62 | 14522 | |
037e8744 JB |
14523 | case NS_QQ: /* case 0/1. */ |
14524 | { | |
14525 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14526 | return; | |
14527 | /* The architecture manual I have doesn't explicitly state which | |
14528 | value the U bit should have for register->register moves, but | |
14529 | the equivalent VORR instruction has U = 0, so do that. */ | |
14530 | inst.instruction = 0x0200110; | |
14531 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14532 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14533 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14534 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14535 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14536 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14537 | inst.instruction |= neon_quad (rs) << 6; | |
14538 | ||
88714cb8 | 14539 | neon_dp_fixup (&inst); |
037e8744 JB |
14540 | } |
14541 | break; | |
5f4273c7 | 14542 | |
037e8744 JB |
14543 | case NS_DI: /* case 3/11. */ |
14544 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
14545 | inst.error = NULL; | |
14546 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 14547 | { |
037e8744 JB |
14548 | /* case 11 (fconstd). */ |
14549 | ldconst = "fconstd"; | |
14550 | goto encode_fconstd; | |
5287ad62 | 14551 | } |
037e8744 JB |
14552 | /* fall through. */ |
14553 | ||
14554 | case NS_QI: /* case 2/3. */ | |
14555 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14556 | return; | |
14557 | inst.instruction = 0x0800010; | |
14558 | neon_move_immediate (); | |
88714cb8 | 14559 | neon_dp_fixup (&inst); |
5287ad62 | 14560 | break; |
5f4273c7 | 14561 | |
037e8744 JB |
14562 | case NS_SR: /* case 4. */ |
14563 | { | |
14564 | unsigned bcdebits = 0; | |
91d6fa6a | 14565 | int logsize; |
037e8744 JB |
14566 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); |
14567 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
14568 | ||
91d6fa6a NC |
14569 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
14570 | logsize = neon_logbits (et.size); | |
14571 | ||
037e8744 JB |
14572 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), |
14573 | _(BAD_FPU)); | |
14574 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14575 | && et.size != 32, _(BAD_FPU)); | |
14576 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14577 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14578 | ||
14579 | switch (et.size) | |
14580 | { | |
14581 | case 8: bcdebits = 0x8; break; | |
14582 | case 16: bcdebits = 0x1; break; | |
14583 | case 32: bcdebits = 0x0; break; | |
14584 | default: ; | |
14585 | } | |
14586 | ||
14587 | bcdebits |= x << logsize; | |
14588 | ||
14589 | inst.instruction = 0xe000b10; | |
14590 | do_vfp_cond_or_thumb (); | |
14591 | inst.instruction |= LOW4 (dn) << 16; | |
14592 | inst.instruction |= HI1 (dn) << 7; | |
14593 | inst.instruction |= inst.operands[1].reg << 12; | |
14594 | inst.instruction |= (bcdebits & 3) << 5; | |
14595 | inst.instruction |= (bcdebits >> 2) << 21; | |
14596 | } | |
14597 | break; | |
5f4273c7 | 14598 | |
037e8744 | 14599 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 14600 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 14601 | _(BAD_FPU)); |
b7fc2769 | 14602 | |
037e8744 JB |
14603 | inst.instruction = 0xc400b10; |
14604 | do_vfp_cond_or_thumb (); | |
14605 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
14606 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
14607 | inst.instruction |= inst.operands[1].reg << 12; | |
14608 | inst.instruction |= inst.operands[2].reg << 16; | |
14609 | break; | |
5f4273c7 | 14610 | |
037e8744 JB |
14611 | case NS_RS: /* case 6. */ |
14612 | { | |
91d6fa6a | 14613 | unsigned logsize; |
037e8744 JB |
14614 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); |
14615 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
14616 | unsigned abcdebits = 0; | |
14617 | ||
91d6fa6a NC |
14618 | et = neon_check_type (2, NS_NULL, |
14619 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
14620 | logsize = neon_logbits (et.size); | |
14621 | ||
037e8744 JB |
14622 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), |
14623 | _(BAD_FPU)); | |
14624 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14625 | && et.size != 32, _(BAD_FPU)); | |
14626 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14627 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14628 | ||
14629 | switch (et.size) | |
14630 | { | |
14631 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
14632 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
14633 | case 32: abcdebits = 0x00; break; | |
14634 | default: ; | |
14635 | } | |
14636 | ||
14637 | abcdebits |= x << logsize; | |
14638 | inst.instruction = 0xe100b10; | |
14639 | do_vfp_cond_or_thumb (); | |
14640 | inst.instruction |= LOW4 (dn) << 16; | |
14641 | inst.instruction |= HI1 (dn) << 7; | |
14642 | inst.instruction |= inst.operands[0].reg << 12; | |
14643 | inst.instruction |= (abcdebits & 3) << 5; | |
14644 | inst.instruction |= (abcdebits >> 2) << 21; | |
14645 | } | |
14646 | break; | |
5f4273c7 | 14647 | |
037e8744 JB |
14648 | case NS_RRD: /* case 7 (fmrrd). */ |
14649 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
14650 | _(BAD_FPU)); | |
14651 | ||
14652 | inst.instruction = 0xc500b10; | |
14653 | do_vfp_cond_or_thumb (); | |
14654 | inst.instruction |= inst.operands[0].reg << 12; | |
14655 | inst.instruction |= inst.operands[1].reg << 16; | |
14656 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14657 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14658 | break; | |
5f4273c7 | 14659 | |
037e8744 JB |
14660 | case NS_FF: /* case 8 (fcpys). */ |
14661 | do_vfp_nsyn_opcode ("fcpys"); | |
14662 | break; | |
5f4273c7 | 14663 | |
037e8744 JB |
14664 | case NS_FI: /* case 10 (fconsts). */ |
14665 | ldconst = "fconsts"; | |
14666 | encode_fconstd: | |
14667 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 14668 | { |
037e8744 JB |
14669 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
14670 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
14671 | } |
14672 | else | |
037e8744 JB |
14673 | first_error (_("immediate out of range")); |
14674 | break; | |
5f4273c7 | 14675 | |
037e8744 JB |
14676 | case NS_RF: /* case 12 (fmrs). */ |
14677 | do_vfp_nsyn_opcode ("fmrs"); | |
14678 | break; | |
5f4273c7 | 14679 | |
037e8744 JB |
14680 | case NS_FR: /* case 13 (fmsr). */ |
14681 | do_vfp_nsyn_opcode ("fmsr"); | |
14682 | break; | |
5f4273c7 | 14683 | |
037e8744 JB |
14684 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
14685 | (one of which is a list), but we have parsed four. Do some fiddling to | |
14686 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
14687 | expect. */ | |
14688 | case NS_RRFF: /* case 14 (fmrrs). */ | |
14689 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
14690 | _("VFP registers must be adjacent")); | |
14691 | inst.operands[2].imm = 2; | |
14692 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14693 | do_vfp_nsyn_opcode ("fmrrs"); | |
14694 | break; | |
5f4273c7 | 14695 | |
037e8744 JB |
14696 | case NS_FFRR: /* case 15 (fmsrr). */ |
14697 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
14698 | _("VFP registers must be adjacent")); | |
14699 | inst.operands[1] = inst.operands[2]; | |
14700 | inst.operands[2] = inst.operands[3]; | |
14701 | inst.operands[0].imm = 2; | |
14702 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14703 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 14704 | break; |
5f4273c7 | 14705 | |
5287ad62 JB |
14706 | default: |
14707 | abort (); | |
14708 | } | |
14709 | } | |
14710 | ||
14711 | static void | |
14712 | do_neon_rshift_round_imm (void) | |
14713 | { | |
037e8744 | 14714 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14715 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
14716 | int imm = inst.operands[2].imm; | |
14717 | ||
14718 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
14719 | if (imm == 0) | |
14720 | { | |
14721 | inst.operands[2].present = 0; | |
14722 | do_neon_mov (); | |
14723 | return; | |
14724 | } | |
14725 | ||
14726 | constraint (imm < 1 || (unsigned)imm > et.size, | |
14727 | _("immediate out of range for shift")); | |
037e8744 | 14728 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
14729 | et.size - imm); |
14730 | } | |
14731 | ||
14732 | static void | |
14733 | do_neon_movl (void) | |
14734 | { | |
14735 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
14736 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
14737 | unsigned sizebits = et.size >> 3; | |
14738 | inst.instruction |= sizebits << 19; | |
14739 | neon_two_same (0, et.type == NT_unsigned, -1); | |
14740 | } | |
14741 | ||
14742 | static void | |
14743 | do_neon_trn (void) | |
14744 | { | |
037e8744 | 14745 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14746 | struct neon_type_el et = neon_check_type (2, rs, |
14747 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 14748 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14749 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14750 | } |
14751 | ||
14752 | static void | |
14753 | do_neon_zip_uzp (void) | |
14754 | { | |
037e8744 | 14755 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14756 | struct neon_type_el et = neon_check_type (2, rs, |
14757 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14758 | if (rs == NS_DD && et.size == 32) | |
14759 | { | |
14760 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
14761 | inst.instruction = N_MNEM_vtrn; | |
14762 | do_neon_trn (); | |
14763 | return; | |
14764 | } | |
037e8744 | 14765 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14766 | } |
14767 | ||
14768 | static void | |
14769 | do_neon_sat_abs_neg (void) | |
14770 | { | |
037e8744 | 14771 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14772 | struct neon_type_el et = neon_check_type (2, rs, |
14773 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14774 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14775 | } |
14776 | ||
14777 | static void | |
14778 | do_neon_pair_long (void) | |
14779 | { | |
037e8744 | 14780 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14781 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
14782 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
14783 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 14784 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14785 | } |
14786 | ||
14787 | static void | |
14788 | do_neon_recip_est (void) | |
14789 | { | |
037e8744 | 14790 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14791 | struct neon_type_el et = neon_check_type (2, rs, |
14792 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
14793 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 14794 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14795 | } |
14796 | ||
14797 | static void | |
14798 | do_neon_cls (void) | |
14799 | { | |
037e8744 | 14800 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14801 | struct neon_type_el et = neon_check_type (2, rs, |
14802 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14803 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14804 | } |
14805 | ||
14806 | static void | |
14807 | do_neon_clz (void) | |
14808 | { | |
037e8744 | 14809 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14810 | struct neon_type_el et = neon_check_type (2, rs, |
14811 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 14812 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14813 | } |
14814 | ||
14815 | static void | |
14816 | do_neon_cnt (void) | |
14817 | { | |
037e8744 | 14818 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14819 | struct neon_type_el et = neon_check_type (2, rs, |
14820 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 14821 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14822 | } |
14823 | ||
14824 | static void | |
14825 | do_neon_swp (void) | |
14826 | { | |
037e8744 JB |
14827 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
14828 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
14829 | } |
14830 | ||
14831 | static void | |
14832 | do_neon_tbl_tbx (void) | |
14833 | { | |
14834 | unsigned listlenbits; | |
dcbf9037 | 14835 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 14836 | |
5287ad62 JB |
14837 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
14838 | { | |
dcbf9037 | 14839 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
14840 | return; |
14841 | } | |
5f4273c7 | 14842 | |
5287ad62 JB |
14843 | listlenbits = inst.operands[1].imm - 1; |
14844 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14845 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14846 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14847 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14848 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14849 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14850 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 14851 | |
88714cb8 | 14852 | neon_dp_fixup (&inst); |
5287ad62 JB |
14853 | } |
14854 | ||
14855 | static void | |
14856 | do_neon_ldm_stm (void) | |
14857 | { | |
14858 | /* P, U and L bits are part of bitmask. */ | |
14859 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
14860 | unsigned offsetbits = inst.operands[1].imm * 2; | |
14861 | ||
037e8744 JB |
14862 | if (inst.operands[1].issingle) |
14863 | { | |
14864 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
14865 | return; | |
14866 | } | |
14867 | ||
5287ad62 JB |
14868 | constraint (is_dbmode && !inst.operands[0].writeback, |
14869 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
14870 | ||
14871 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14872 | _("register list must contain at least 1 and at most 16 " | |
14873 | "registers")); | |
14874 | ||
14875 | inst.instruction |= inst.operands[0].reg << 16; | |
14876 | inst.instruction |= inst.operands[0].writeback << 21; | |
14877 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
14878 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
14879 | ||
14880 | inst.instruction |= offsetbits; | |
5f4273c7 | 14881 | |
037e8744 | 14882 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
14883 | } |
14884 | ||
14885 | static void | |
14886 | do_neon_ldr_str (void) | |
14887 | { | |
5287ad62 | 14888 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 14889 | |
6844b2c2 MGD |
14890 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
14891 | And is UNPREDICTABLE in thumb mode. */ | |
14892 | if (!is_ldr | |
14893 | && inst.operands[1].reg == REG_PC | |
14894 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
14895 | { | |
14896 | if (!thumb_mode && warn_on_deprecated) | |
14897 | as_warn (_("Use of PC here is deprecated")); | |
14898 | else | |
14899 | inst.error = _("Use of PC here is UNPREDICTABLE"); | |
14900 | } | |
14901 | ||
037e8744 JB |
14902 | if (inst.operands[0].issingle) |
14903 | { | |
cd2f129f JB |
14904 | if (is_ldr) |
14905 | do_vfp_nsyn_opcode ("flds"); | |
14906 | else | |
14907 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
14908 | } |
14909 | else | |
5287ad62 | 14910 | { |
cd2f129f JB |
14911 | if (is_ldr) |
14912 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 14913 | else |
cd2f129f | 14914 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 14915 | } |
5287ad62 JB |
14916 | } |
14917 | ||
14918 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
14919 | instructions. */ | |
14920 | ||
14921 | static void | |
14922 | do_neon_ld_st_interleave (void) | |
14923 | { | |
037e8744 | 14924 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
14925 | N_8 | N_16 | N_32 | N_64); |
14926 | unsigned alignbits = 0; | |
14927 | unsigned idx; | |
14928 | /* The bits in this table go: | |
14929 | 0: register stride of one (0) or two (1) | |
14930 | 1,2: register list length, minus one (1, 2, 3, 4). | |
14931 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
14932 | We use -1 for invalid entries. */ | |
14933 | const int typetable[] = | |
14934 | { | |
14935 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
14936 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
14937 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
14938 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
14939 | }; | |
14940 | int typebits; | |
14941 | ||
dcbf9037 JB |
14942 | if (et.type == NT_invtype) |
14943 | return; | |
14944 | ||
5287ad62 JB |
14945 | if (inst.operands[1].immisalign) |
14946 | switch (inst.operands[1].imm >> 8) | |
14947 | { | |
14948 | case 64: alignbits = 1; break; | |
14949 | case 128: | |
e23c0ad8 JZ |
14950 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
14951 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) | |
5287ad62 JB |
14952 | goto bad_alignment; |
14953 | alignbits = 2; | |
14954 | break; | |
14955 | case 256: | |
e23c0ad8 | 14956 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
5287ad62 JB |
14957 | goto bad_alignment; |
14958 | alignbits = 3; | |
14959 | break; | |
14960 | default: | |
14961 | bad_alignment: | |
dcbf9037 | 14962 | first_error (_("bad alignment")); |
5287ad62 JB |
14963 | return; |
14964 | } | |
14965 | ||
14966 | inst.instruction |= alignbits << 4; | |
14967 | inst.instruction |= neon_logbits (et.size) << 6; | |
14968 | ||
14969 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
14970 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
14971 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
14972 | up the right value for "type" in a table based on this value and the given | |
14973 | list style, then stick it back. */ | |
14974 | idx = ((inst.operands[0].imm >> 4) & 7) | |
14975 | | (((inst.instruction >> 8) & 3) << 3); | |
14976 | ||
14977 | typebits = typetable[idx]; | |
5f4273c7 | 14978 | |
5287ad62 JB |
14979 | constraint (typebits == -1, _("bad list type for instruction")); |
14980 | ||
14981 | inst.instruction &= ~0xf00; | |
14982 | inst.instruction |= typebits << 8; | |
14983 | } | |
14984 | ||
14985 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
14986 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
14987 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
14988 | values, terminated with -1. */ | |
14989 | ||
14990 | static int | |
14991 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
14992 | { | |
14993 | va_list ap; | |
14994 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 14995 | |
5287ad62 JB |
14996 | if (!inst.operands[1].immisalign) |
14997 | { | |
14998 | *do_align = 0; | |
14999 | return SUCCESS; | |
15000 | } | |
5f4273c7 | 15001 | |
5287ad62 JB |
15002 | va_start (ap, do_align); |
15003 | ||
15004 | do | |
15005 | { | |
15006 | thissize = va_arg (ap, int); | |
15007 | if (thissize == -1) | |
15008 | break; | |
15009 | thisalign = va_arg (ap, int); | |
15010 | ||
15011 | if (size == thissize && align == thisalign) | |
15012 | result = SUCCESS; | |
15013 | } | |
15014 | while (result != SUCCESS); | |
15015 | ||
15016 | va_end (ap); | |
15017 | ||
15018 | if (result == SUCCESS) | |
15019 | *do_align = 1; | |
15020 | else | |
dcbf9037 | 15021 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 15022 | |
5287ad62 JB |
15023 | return result; |
15024 | } | |
15025 | ||
15026 | static void | |
15027 | do_neon_ld_st_lane (void) | |
15028 | { | |
037e8744 | 15029 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
15030 | int align_good, do_align = 0; |
15031 | int logsize = neon_logbits (et.size); | |
15032 | int align = inst.operands[1].imm >> 8; | |
15033 | int n = (inst.instruction >> 8) & 3; | |
15034 | int max_el = 64 / et.size; | |
5f4273c7 | 15035 | |
dcbf9037 JB |
15036 | if (et.type == NT_invtype) |
15037 | return; | |
5f4273c7 | 15038 | |
5287ad62 JB |
15039 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
15040 | _("bad list length")); | |
15041 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
15042 | _("scalar index out of range")); | |
15043 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
15044 | && et.size == 8, | |
15045 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 15046 | |
5287ad62 JB |
15047 | switch (n) |
15048 | { | |
15049 | case 0: /* VLD1 / VST1. */ | |
15050 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
15051 | 32, 32, -1); | |
15052 | if (align_good == FAIL) | |
15053 | return; | |
15054 | if (do_align) | |
15055 | { | |
15056 | unsigned alignbits = 0; | |
15057 | switch (et.size) | |
15058 | { | |
15059 | case 16: alignbits = 0x1; break; | |
15060 | case 32: alignbits = 0x3; break; | |
15061 | default: ; | |
15062 | } | |
15063 | inst.instruction |= alignbits << 4; | |
15064 | } | |
15065 | break; | |
15066 | ||
15067 | case 1: /* VLD2 / VST2. */ | |
15068 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
15069 | 32, 64, -1); | |
15070 | if (align_good == FAIL) | |
15071 | return; | |
15072 | if (do_align) | |
15073 | inst.instruction |= 1 << 4; | |
15074 | break; | |
15075 | ||
15076 | case 2: /* VLD3 / VST3. */ | |
15077 | constraint (inst.operands[1].immisalign, | |
15078 | _("can't use alignment with this instruction")); | |
15079 | break; | |
15080 | ||
15081 | case 3: /* VLD4 / VST4. */ | |
15082 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
15083 | 16, 64, 32, 64, 32, 128, -1); | |
15084 | if (align_good == FAIL) | |
15085 | return; | |
15086 | if (do_align) | |
15087 | { | |
15088 | unsigned alignbits = 0; | |
15089 | switch (et.size) | |
15090 | { | |
15091 | case 8: alignbits = 0x1; break; | |
15092 | case 16: alignbits = 0x1; break; | |
15093 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
15094 | default: ; | |
15095 | } | |
15096 | inst.instruction |= alignbits << 4; | |
15097 | } | |
15098 | break; | |
15099 | ||
15100 | default: ; | |
15101 | } | |
15102 | ||
15103 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
15104 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15105 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 15106 | |
5287ad62 JB |
15107 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
15108 | inst.instruction |= logsize << 10; | |
15109 | } | |
15110 | ||
15111 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
15112 | ||
15113 | static void | |
15114 | do_neon_ld_dup (void) | |
15115 | { | |
037e8744 | 15116 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
15117 | int align_good, do_align = 0; |
15118 | ||
dcbf9037 JB |
15119 | if (et.type == NT_invtype) |
15120 | return; | |
15121 | ||
5287ad62 JB |
15122 | switch ((inst.instruction >> 8) & 3) |
15123 | { | |
15124 | case 0: /* VLD1. */ | |
9c2799c2 | 15125 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 JB |
15126 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
15127 | &do_align, 16, 16, 32, 32, -1); | |
15128 | if (align_good == FAIL) | |
15129 | return; | |
15130 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
15131 | { | |
15132 | case 1: break; | |
15133 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 15134 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
15135 | } |
15136 | inst.instruction |= neon_logbits (et.size) << 6; | |
15137 | break; | |
15138 | ||
15139 | case 1: /* VLD2. */ | |
15140 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
15141 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
15142 | if (align_good == FAIL) | |
15143 | return; | |
15144 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
15145 | _("bad list length")); | |
15146 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15147 | inst.instruction |= 1 << 5; | |
15148 | inst.instruction |= neon_logbits (et.size) << 6; | |
15149 | break; | |
15150 | ||
15151 | case 2: /* VLD3. */ | |
15152 | constraint (inst.operands[1].immisalign, | |
15153 | _("can't use alignment with this instruction")); | |
15154 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
15155 | _("bad list length")); | |
15156 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15157 | inst.instruction |= 1 << 5; | |
15158 | inst.instruction |= neon_logbits (et.size) << 6; | |
15159 | break; | |
15160 | ||
15161 | case 3: /* VLD4. */ | |
15162 | { | |
15163 | int align = inst.operands[1].imm >> 8; | |
15164 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
15165 | 16, 64, 32, 64, 32, 128, -1); | |
15166 | if (align_good == FAIL) | |
15167 | return; | |
15168 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
15169 | _("bad list length")); | |
15170 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
15171 | inst.instruction |= 1 << 5; | |
15172 | if (et.size == 32 && align == 128) | |
15173 | inst.instruction |= 0x3 << 6; | |
15174 | else | |
15175 | inst.instruction |= neon_logbits (et.size) << 6; | |
15176 | } | |
15177 | break; | |
15178 | ||
15179 | default: ; | |
15180 | } | |
15181 | ||
15182 | inst.instruction |= do_align << 4; | |
15183 | } | |
15184 | ||
15185 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
15186 | apart from bits [11:4]. */ | |
15187 | ||
15188 | static void | |
15189 | do_neon_ldx_stx (void) | |
15190 | { | |
b1a769ed DG |
15191 | if (inst.operands[1].isreg) |
15192 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
15193 | ||
5287ad62 JB |
15194 | switch (NEON_LANE (inst.operands[0].imm)) |
15195 | { | |
15196 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 15197 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
15198 | do_neon_ld_st_interleave (); |
15199 | break; | |
5f4273c7 | 15200 | |
5287ad62 | 15201 | case NEON_ALL_LANES: |
88714cb8 | 15202 | NEON_ENCODE (DUP, inst); |
5287ad62 JB |
15203 | do_neon_ld_dup (); |
15204 | break; | |
5f4273c7 | 15205 | |
5287ad62 | 15206 | default: |
88714cb8 | 15207 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
15208 | do_neon_ld_st_lane (); |
15209 | } | |
15210 | ||
15211 | /* L bit comes from bit mask. */ | |
15212 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15213 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15214 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 15215 | |
5287ad62 JB |
15216 | if (inst.operands[1].postind) |
15217 | { | |
15218 | int postreg = inst.operands[1].imm & 0xf; | |
15219 | constraint (!inst.operands[1].immisreg, | |
15220 | _("post-index must be a register")); | |
15221 | constraint (postreg == 0xd || postreg == 0xf, | |
15222 | _("bad register for post-index")); | |
15223 | inst.instruction |= postreg; | |
15224 | } | |
15225 | else if (inst.operands[1].writeback) | |
15226 | { | |
15227 | inst.instruction |= 0xd; | |
15228 | } | |
15229 | else | |
5f4273c7 NC |
15230 | inst.instruction |= 0xf; |
15231 | ||
5287ad62 JB |
15232 | if (thumb_mode) |
15233 | inst.instruction |= 0xf9000000; | |
15234 | else | |
15235 | inst.instruction |= 0xf4000000; | |
15236 | } | |
5287ad62 JB |
15237 | \f |
15238 | /* Overall per-instruction processing. */ | |
15239 | ||
15240 | /* We need to be able to fix up arbitrary expressions in some statements. | |
15241 | This is so that we can handle symbols that are an arbitrary distance from | |
15242 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
15243 | which returns part of an address in a form which will be valid for | |
15244 | a data instruction. We do this by pushing the expression into a symbol | |
15245 | in the expr_section, and creating a fix for that. */ | |
15246 | ||
15247 | static void | |
15248 | fix_new_arm (fragS * frag, | |
15249 | int where, | |
15250 | short int size, | |
15251 | expressionS * exp, | |
15252 | int pc_rel, | |
15253 | int reloc) | |
15254 | { | |
15255 | fixS * new_fix; | |
15256 | ||
15257 | switch (exp->X_op) | |
15258 | { | |
15259 | case O_constant: | |
15260 | case O_symbol: | |
15261 | case O_add: | |
15262 | case O_subtract: | |
21d799b5 NC |
15263 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
15264 | (enum bfd_reloc_code_real) reloc); | |
5287ad62 JB |
15265 | break; |
15266 | ||
15267 | default: | |
21d799b5 NC |
15268 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
15269 | pc_rel, (enum bfd_reloc_code_real) reloc); | |
5287ad62 JB |
15270 | break; |
15271 | } | |
15272 | ||
15273 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
15274 | instruction. */ | |
15275 | new_fix->tc_fix_data = thumb_mode; | |
15276 | } | |
15277 | ||
15278 | /* Create a frg for an instruction requiring relaxation. */ | |
15279 | static void | |
15280 | output_relax_insn (void) | |
15281 | { | |
15282 | char * to; | |
15283 | symbolS *sym; | |
0110f2b8 PB |
15284 | int offset; |
15285 | ||
6e1cb1a6 PB |
15286 | /* The size of the instruction is unknown, so tie the debug info to the |
15287 | start of the instruction. */ | |
15288 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 15289 | |
0110f2b8 PB |
15290 | switch (inst.reloc.exp.X_op) |
15291 | { | |
15292 | case O_symbol: | |
15293 | sym = inst.reloc.exp.X_add_symbol; | |
15294 | offset = inst.reloc.exp.X_add_number; | |
15295 | break; | |
15296 | case O_constant: | |
15297 | sym = NULL; | |
15298 | offset = inst.reloc.exp.X_add_number; | |
15299 | break; | |
15300 | default: | |
15301 | sym = make_expr_symbol (&inst.reloc.exp); | |
15302 | offset = 0; | |
15303 | break; | |
15304 | } | |
15305 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
15306 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
15307 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
15308 | } |
15309 | ||
15310 | /* Write a 32-bit thumb instruction to buf. */ | |
15311 | static void | |
15312 | put_thumb32_insn (char * buf, unsigned long insn) | |
15313 | { | |
15314 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
15315 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
15316 | } | |
15317 | ||
b99bd4ef | 15318 | static void |
c19d1205 | 15319 | output_inst (const char * str) |
b99bd4ef | 15320 | { |
c19d1205 | 15321 | char * to = NULL; |
b99bd4ef | 15322 | |
c19d1205 | 15323 | if (inst.error) |
b99bd4ef | 15324 | { |
c19d1205 | 15325 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
15326 | return; |
15327 | } | |
5f4273c7 NC |
15328 | if (inst.relax) |
15329 | { | |
15330 | output_relax_insn (); | |
0110f2b8 | 15331 | return; |
5f4273c7 | 15332 | } |
c19d1205 ZW |
15333 | if (inst.size == 0) |
15334 | return; | |
b99bd4ef | 15335 | |
c19d1205 | 15336 | to = frag_more (inst.size); |
8dc2430f NC |
15337 | /* PR 9814: Record the thumb mode into the current frag so that we know |
15338 | what type of NOP padding to use, if necessary. We override any previous | |
15339 | setting so that if the mode has changed then the NOPS that we use will | |
15340 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 15341 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
15342 | |
15343 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 15344 | { |
9c2799c2 | 15345 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 15346 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 15347 | } |
c19d1205 | 15348 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 15349 | { |
9c2799c2 | 15350 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
15351 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
15352 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 15353 | } |
c19d1205 ZW |
15354 | else |
15355 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 15356 | |
c19d1205 ZW |
15357 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
15358 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
15359 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
15360 | inst.reloc.type); | |
b99bd4ef | 15361 | |
c19d1205 | 15362 | dwarf2_emit_insn (inst.size); |
c19d1205 | 15363 | } |
b99bd4ef | 15364 | |
e07e6e58 NC |
15365 | static char * |
15366 | output_it_inst (int cond, int mask, char * to) | |
15367 | { | |
15368 | unsigned long instruction = 0xbf00; | |
15369 | ||
15370 | mask &= 0xf; | |
15371 | instruction |= mask; | |
15372 | instruction |= cond << 4; | |
15373 | ||
15374 | if (to == NULL) | |
15375 | { | |
15376 | to = frag_more (2); | |
15377 | #ifdef OBJ_ELF | |
15378 | dwarf2_emit_insn (2); | |
15379 | #endif | |
15380 | } | |
15381 | ||
15382 | md_number_to_chars (to, instruction, 2); | |
15383 | ||
15384 | return to; | |
15385 | } | |
15386 | ||
c19d1205 ZW |
15387 | /* Tag values used in struct asm_opcode's tag field. */ |
15388 | enum opcode_tag | |
15389 | { | |
15390 | OT_unconditional, /* Instruction cannot be conditionalized. | |
15391 | The ARM condition field is still 0xE. */ | |
15392 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
15393 | and carries 0xF in its ARM condition field. */ | |
15394 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
15395 | OT_csuffixF, /* Some forms of the instruction take a conditional |
15396 | suffix, others place 0xF where the condition field | |
15397 | would be. */ | |
c19d1205 ZW |
15398 | OT_cinfix3, /* Instruction takes a conditional infix, |
15399 | beginning at character index 3. (In | |
15400 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
15401 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
15402 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
15403 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
15404 | character index 3, even in unified mode. Used for | |
15405 | legacy instructions where suffix and infix forms | |
15406 | may be ambiguous. */ | |
c19d1205 | 15407 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 15408 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
15409 | OT_odd_infix_unc, /* This is the unconditional variant of an |
15410 | instruction that takes a conditional infix | |
15411 | at an unusual position. In unified mode, | |
15412 | this variant will accept a suffix. */ | |
15413 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
15414 | are the conditional variants of instructions that | |
15415 | take conditional infixes in unusual positions. | |
15416 | The infix appears at character index | |
15417 | (tag - OT_odd_infix_0). These are not accepted | |
15418 | in unified mode. */ | |
15419 | }; | |
b99bd4ef | 15420 | |
c19d1205 ZW |
15421 | /* Subroutine of md_assemble, responsible for looking up the primary |
15422 | opcode from the mnemonic the user wrote. STR points to the | |
15423 | beginning of the mnemonic. | |
15424 | ||
15425 | This is not simply a hash table lookup, because of conditional | |
15426 | variants. Most instructions have conditional variants, which are | |
15427 | expressed with a _conditional affix_ to the mnemonic. If we were | |
15428 | to encode each conditional variant as a literal string in the opcode | |
15429 | table, it would have approximately 20,000 entries. | |
15430 | ||
15431 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
15432 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
15433 | instructions take the affix as an infix, notably the s-variants of | |
15434 | the arithmetic instructions. Of those instructions, all but six | |
15435 | have the infix appear after the third character of the mnemonic. | |
15436 | ||
15437 | Accordingly, the algorithm for looking up primary opcodes given | |
15438 | an identifier is: | |
15439 | ||
15440 | 1. Look up the identifier in the opcode table. | |
15441 | If we find a match, go to step U. | |
15442 | ||
15443 | 2. Look up the last two characters of the identifier in the | |
15444 | conditions table. If we find a match, look up the first N-2 | |
15445 | characters of the identifier in the opcode table. If we | |
15446 | find a match, go to step CE. | |
15447 | ||
15448 | 3. Look up the fourth and fifth characters of the identifier in | |
15449 | the conditions table. If we find a match, extract those | |
15450 | characters from the identifier, and look up the remaining | |
15451 | characters in the opcode table. If we find a match, go | |
15452 | to step CM. | |
15453 | ||
15454 | 4. Fail. | |
15455 | ||
15456 | U. Examine the tag field of the opcode structure, in case this is | |
15457 | one of the six instructions with its conditional infix in an | |
15458 | unusual place. If it is, the tag tells us where to find the | |
15459 | infix; look it up in the conditions table and set inst.cond | |
15460 | accordingly. Otherwise, this is an unconditional instruction. | |
15461 | Again set inst.cond accordingly. Return the opcode structure. | |
15462 | ||
15463 | CE. Examine the tag field to make sure this is an instruction that | |
15464 | should receive a conditional suffix. If it is not, fail. | |
15465 | Otherwise, set inst.cond from the suffix we already looked up, | |
15466 | and return the opcode structure. | |
15467 | ||
15468 | CM. Examine the tag field to make sure this is an instruction that | |
15469 | should receive a conditional infix after the third character. | |
15470 | If it is not, fail. Otherwise, undo the edits to the current | |
15471 | line of input and proceed as for case CE. */ | |
15472 | ||
15473 | static const struct asm_opcode * | |
15474 | opcode_lookup (char **str) | |
15475 | { | |
15476 | char *end, *base; | |
15477 | char *affix; | |
15478 | const struct asm_opcode *opcode; | |
15479 | const struct asm_cond *cond; | |
e3cb604e | 15480 | char save[2]; |
c19d1205 ZW |
15481 | |
15482 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 15483 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 15484 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 15485 | if (*end == ' ' || *end == '.') |
c19d1205 | 15486 | break; |
b99bd4ef | 15487 | |
c19d1205 | 15488 | if (end == base) |
c921be7d | 15489 | return NULL; |
b99bd4ef | 15490 | |
5287ad62 | 15491 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 15492 | if (end[0] == '.') |
b99bd4ef | 15493 | { |
5287ad62 | 15494 | int offset = 2; |
5f4273c7 | 15495 | |
267d2029 JB |
15496 | /* The .w and .n suffixes are only valid if the unified syntax is in |
15497 | use. */ | |
15498 | if (unified_syntax && end[1] == 'w') | |
c19d1205 | 15499 | inst.size_req = 4; |
267d2029 | 15500 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
15501 | inst.size_req = 2; |
15502 | else | |
5287ad62 JB |
15503 | offset = 0; |
15504 | ||
15505 | inst.vectype.elems = 0; | |
15506 | ||
15507 | *str = end + offset; | |
b99bd4ef | 15508 | |
5f4273c7 | 15509 | if (end[offset] == '.') |
5287ad62 | 15510 | { |
267d2029 JB |
15511 | /* See if we have a Neon type suffix (possible in either unified or |
15512 | non-unified ARM syntax mode). */ | |
dcbf9037 | 15513 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
c921be7d | 15514 | return NULL; |
5287ad62 JB |
15515 | } |
15516 | else if (end[offset] != '\0' && end[offset] != ' ') | |
c921be7d | 15517 | return NULL; |
b99bd4ef | 15518 | } |
c19d1205 ZW |
15519 | else |
15520 | *str = end; | |
b99bd4ef | 15521 | |
c19d1205 | 15522 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 NC |
15523 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
15524 | end - base); | |
c19d1205 | 15525 | if (opcode) |
b99bd4ef | 15526 | { |
c19d1205 ZW |
15527 | /* step U */ |
15528 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 15529 | { |
c19d1205 ZW |
15530 | inst.cond = COND_ALWAYS; |
15531 | return opcode; | |
b99bd4ef | 15532 | } |
b99bd4ef | 15533 | |
278df34e | 15534 | if (warn_on_deprecated && unified_syntax) |
c19d1205 ZW |
15535 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
15536 | affix = base + (opcode->tag - OT_odd_infix_0); | |
21d799b5 | 15537 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 15538 | gas_assert (cond); |
b99bd4ef | 15539 | |
c19d1205 ZW |
15540 | inst.cond = cond->value; |
15541 | return opcode; | |
15542 | } | |
b99bd4ef | 15543 | |
c19d1205 ZW |
15544 | /* Cannot have a conditional suffix on a mnemonic of less than two |
15545 | characters. */ | |
15546 | if (end - base < 3) | |
c921be7d | 15547 | return NULL; |
b99bd4ef | 15548 | |
c19d1205 ZW |
15549 | /* Look for suffixed mnemonic. */ |
15550 | affix = end - 2; | |
21d799b5 NC |
15551 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
15552 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
15553 | affix - base); | |
c19d1205 ZW |
15554 | if (opcode && cond) |
15555 | { | |
15556 | /* step CE */ | |
15557 | switch (opcode->tag) | |
15558 | { | |
e3cb604e PB |
15559 | case OT_cinfix3_legacy: |
15560 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
15561 | break; | |
15562 | ||
c19d1205 | 15563 | case OT_cinfix3: |
088fa78e | 15564 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
15565 | case OT_odd_infix_unc: |
15566 | if (!unified_syntax) | |
e3cb604e | 15567 | return 0; |
c19d1205 ZW |
15568 | /* else fall through */ |
15569 | ||
15570 | case OT_csuffix: | |
037e8744 | 15571 | case OT_csuffixF: |
c19d1205 ZW |
15572 | case OT_csuf_or_in3: |
15573 | inst.cond = cond->value; | |
15574 | return opcode; | |
15575 | ||
15576 | case OT_unconditional: | |
15577 | case OT_unconditionalF: | |
dfa9f0d5 | 15578 | if (thumb_mode) |
c921be7d | 15579 | inst.cond = cond->value; |
dfa9f0d5 PB |
15580 | else |
15581 | { | |
c921be7d | 15582 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
15583 | inst.error = BAD_COND; |
15584 | inst.cond = COND_ALWAYS; | |
15585 | } | |
c19d1205 | 15586 | return opcode; |
b99bd4ef | 15587 | |
c19d1205 | 15588 | default: |
c921be7d | 15589 | return NULL; |
c19d1205 ZW |
15590 | } |
15591 | } | |
b99bd4ef | 15592 | |
c19d1205 ZW |
15593 | /* Cannot have a usual-position infix on a mnemonic of less than |
15594 | six characters (five would be a suffix). */ | |
15595 | if (end - base < 6) | |
c921be7d | 15596 | return NULL; |
b99bd4ef | 15597 | |
c19d1205 ZW |
15598 | /* Look for infixed mnemonic in the usual position. */ |
15599 | affix = base + 3; | |
21d799b5 | 15600 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 15601 | if (!cond) |
c921be7d | 15602 | return NULL; |
e3cb604e PB |
15603 | |
15604 | memcpy (save, affix, 2); | |
15605 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 NC |
15606 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
15607 | (end - base) - 2); | |
e3cb604e PB |
15608 | memmove (affix + 2, affix, (end - affix) - 2); |
15609 | memcpy (affix, save, 2); | |
15610 | ||
088fa78e KH |
15611 | if (opcode |
15612 | && (opcode->tag == OT_cinfix3 | |
15613 | || opcode->tag == OT_cinfix3_deprecated | |
15614 | || opcode->tag == OT_csuf_or_in3 | |
15615 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 15616 | { |
c921be7d | 15617 | /* Step CM. */ |
278df34e | 15618 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
15619 | && (opcode->tag == OT_cinfix3 |
15620 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
15621 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
15622 | ||
15623 | inst.cond = cond->value; | |
15624 | return opcode; | |
b99bd4ef NC |
15625 | } |
15626 | ||
c921be7d | 15627 | return NULL; |
b99bd4ef NC |
15628 | } |
15629 | ||
e07e6e58 NC |
15630 | /* This function generates an initial IT instruction, leaving its block |
15631 | virtually open for the new instructions. Eventually, | |
15632 | the mask will be updated by now_it_add_mask () each time | |
15633 | a new instruction needs to be included in the IT block. | |
15634 | Finally, the block is closed with close_automatic_it_block (). | |
15635 | The block closure can be requested either from md_assemble (), | |
15636 | a tencode (), or due to a label hook. */ | |
15637 | ||
15638 | static void | |
15639 | new_automatic_it_block (int cond) | |
15640 | { | |
15641 | now_it.state = AUTOMATIC_IT_BLOCK; | |
15642 | now_it.mask = 0x18; | |
15643 | now_it.cc = cond; | |
15644 | now_it.block_length = 1; | |
cd000bff | 15645 | mapping_state (MAP_THUMB); |
e07e6e58 NC |
15646 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
15647 | } | |
15648 | ||
15649 | /* Close an automatic IT block. | |
15650 | See comments in new_automatic_it_block (). */ | |
15651 | ||
15652 | static void | |
15653 | close_automatic_it_block (void) | |
15654 | { | |
15655 | now_it.mask = 0x10; | |
15656 | now_it.block_length = 0; | |
15657 | } | |
15658 | ||
15659 | /* Update the mask of the current automatically-generated IT | |
15660 | instruction. See comments in new_automatic_it_block (). */ | |
15661 | ||
15662 | static void | |
15663 | now_it_add_mask (int cond) | |
15664 | { | |
15665 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
15666 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
15667 | | ((bitvalue) << (nbit))) | |
e07e6e58 | 15668 | const int resulting_bit = (cond & 1); |
c921be7d | 15669 | |
e07e6e58 NC |
15670 | now_it.mask &= 0xf; |
15671 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15672 | resulting_bit, | |
15673 | (5 - now_it.block_length)); | |
15674 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15675 | 1, | |
15676 | ((5 - now_it.block_length) - 1) ); | |
15677 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); | |
15678 | ||
15679 | #undef CLEAR_BIT | |
15680 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
15681 | } |
15682 | ||
15683 | /* The IT blocks handling machinery is accessed through the these functions: | |
15684 | it_fsm_pre_encode () from md_assemble () | |
15685 | set_it_insn_type () optional, from the tencode functions | |
15686 | set_it_insn_type_last () ditto | |
15687 | in_it_block () ditto | |
15688 | it_fsm_post_encode () from md_assemble () | |
15689 | force_automatic_it_block_close () from label habdling functions | |
15690 | ||
15691 | Rationale: | |
15692 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
15693 | initializing the IT insn type with a generic initial value depending | |
15694 | on the inst.condition. | |
15695 | 2) During the tencode function, two things may happen: | |
15696 | a) The tencode function overrides the IT insn type by | |
15697 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
15698 | b) The tencode function queries the IT block state by | |
15699 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
15700 | ||
15701 | Both set_it_insn_type and in_it_block run the internal FSM state | |
15702 | handling function (handle_it_state), because: a) setting the IT insn | |
15703 | type may incur in an invalid state (exiting the function), | |
15704 | and b) querying the state requires the FSM to be updated. | |
15705 | Specifically we want to avoid creating an IT block for conditional | |
15706 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
15707 | determine whether an IT block is required until the tencode () routine | |
15708 | has decided what type of instruction this actually it. | |
15709 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
15710 | set_it_insn_type has to be called first. | |
15711 | ||
15712 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
15713 | determines the insn IT type depending on the inst.cond code. | |
15714 | When a tencode () routine encodes an instruction that can be | |
15715 | either outside an IT block, or, in the case of being inside, has to be | |
15716 | the last one, set_it_insn_type_last () will determine the proper | |
15717 | IT instruction type based on the inst.cond code. Otherwise, | |
15718 | set_it_insn_type can be called for overriding that logic or | |
15719 | for covering other cases. | |
15720 | ||
15721 | Calling handle_it_state () may not transition the IT block state to | |
15722 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
15723 | still queried. Instead, if the FSM determines that the state should | |
15724 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
15725 | after the tencode () function: that's what it_fsm_post_encode () does. | |
15726 | ||
15727 | Since in_it_block () calls the state handling function to get an | |
15728 | updated state, an error may occur (due to invalid insns combination). | |
15729 | In that case, inst.error is set. | |
15730 | Therefore, inst.error has to be checked after the execution of | |
15731 | the tencode () routine. | |
15732 | ||
15733 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
15734 | any pending state change (if any) that didn't take place in | |
15735 | handle_it_state () as explained above. */ | |
15736 | ||
15737 | static void | |
15738 | it_fsm_pre_encode (void) | |
15739 | { | |
15740 | if (inst.cond != COND_ALWAYS) | |
15741 | inst.it_insn_type = INSIDE_IT_INSN; | |
15742 | else | |
15743 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
15744 | ||
15745 | now_it.state_handled = 0; | |
15746 | } | |
15747 | ||
15748 | /* IT state FSM handling function. */ | |
15749 | ||
15750 | static int | |
15751 | handle_it_state (void) | |
15752 | { | |
15753 | now_it.state_handled = 1; | |
15754 | ||
15755 | switch (now_it.state) | |
15756 | { | |
15757 | case OUTSIDE_IT_BLOCK: | |
15758 | switch (inst.it_insn_type) | |
15759 | { | |
15760 | case OUTSIDE_IT_INSN: | |
15761 | break; | |
15762 | ||
15763 | case INSIDE_IT_INSN: | |
15764 | case INSIDE_IT_LAST_INSN: | |
15765 | if (thumb_mode == 0) | |
15766 | { | |
c921be7d | 15767 | if (unified_syntax |
e07e6e58 NC |
15768 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
15769 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
15770 | " for Thumb.")); | |
15771 | } | |
15772 | else | |
15773 | { | |
15774 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
15775 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
15776 | { | |
15777 | /* Automatically generate the IT instruction. */ | |
15778 | new_automatic_it_block (inst.cond); | |
15779 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
15780 | close_automatic_it_block (); | |
15781 | } | |
15782 | else | |
15783 | { | |
15784 | inst.error = BAD_OUT_IT; | |
15785 | return FAIL; | |
15786 | } | |
15787 | } | |
15788 | break; | |
15789 | ||
15790 | case IF_INSIDE_IT_LAST_INSN: | |
15791 | case NEUTRAL_IT_INSN: | |
15792 | break; | |
15793 | ||
15794 | case IT_INSN: | |
15795 | now_it.state = MANUAL_IT_BLOCK; | |
15796 | now_it.block_length = 0; | |
15797 | break; | |
15798 | } | |
15799 | break; | |
15800 | ||
15801 | case AUTOMATIC_IT_BLOCK: | |
15802 | /* Three things may happen now: | |
15803 | a) We should increment current it block size; | |
15804 | b) We should close current it block (closing insn or 4 insns); | |
15805 | c) We should close current it block and start a new one (due | |
15806 | to incompatible conditions or | |
15807 | 4 insns-length block reached). */ | |
15808 | ||
15809 | switch (inst.it_insn_type) | |
15810 | { | |
15811 | case OUTSIDE_IT_INSN: | |
15812 | /* The closure of the block shall happen immediatelly, | |
15813 | so any in_it_block () call reports the block as closed. */ | |
15814 | force_automatic_it_block_close (); | |
15815 | break; | |
15816 | ||
15817 | case INSIDE_IT_INSN: | |
15818 | case INSIDE_IT_LAST_INSN: | |
15819 | case IF_INSIDE_IT_LAST_INSN: | |
15820 | now_it.block_length++; | |
15821 | ||
15822 | if (now_it.block_length > 4 | |
15823 | || !now_it_compatible (inst.cond)) | |
15824 | { | |
15825 | force_automatic_it_block_close (); | |
15826 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
15827 | new_automatic_it_block (inst.cond); | |
15828 | } | |
15829 | else | |
15830 | { | |
15831 | now_it_add_mask (inst.cond); | |
15832 | } | |
15833 | ||
15834 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
15835 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
15836 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
15837 | close_automatic_it_block (); | |
15838 | break; | |
15839 | ||
15840 | case NEUTRAL_IT_INSN: | |
15841 | now_it.block_length++; | |
15842 | ||
15843 | if (now_it.block_length > 4) | |
15844 | force_automatic_it_block_close (); | |
15845 | else | |
15846 | now_it_add_mask (now_it.cc & 1); | |
15847 | break; | |
15848 | ||
15849 | case IT_INSN: | |
15850 | close_automatic_it_block (); | |
15851 | now_it.state = MANUAL_IT_BLOCK; | |
15852 | break; | |
15853 | } | |
15854 | break; | |
15855 | ||
15856 | case MANUAL_IT_BLOCK: | |
15857 | { | |
15858 | /* Check conditional suffixes. */ | |
15859 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
15860 | int is_last; | |
15861 | now_it.mask <<= 1; | |
15862 | now_it.mask &= 0x1f; | |
15863 | is_last = (now_it.mask == 0x10); | |
15864 | ||
15865 | switch (inst.it_insn_type) | |
15866 | { | |
15867 | case OUTSIDE_IT_INSN: | |
15868 | inst.error = BAD_NOT_IT; | |
15869 | return FAIL; | |
15870 | ||
15871 | case INSIDE_IT_INSN: | |
15872 | if (cond != inst.cond) | |
15873 | { | |
15874 | inst.error = BAD_IT_COND; | |
15875 | return FAIL; | |
15876 | } | |
15877 | break; | |
15878 | ||
15879 | case INSIDE_IT_LAST_INSN: | |
15880 | case IF_INSIDE_IT_LAST_INSN: | |
15881 | if (cond != inst.cond) | |
15882 | { | |
15883 | inst.error = BAD_IT_COND; | |
15884 | return FAIL; | |
15885 | } | |
15886 | if (!is_last) | |
15887 | { | |
15888 | inst.error = BAD_BRANCH; | |
15889 | return FAIL; | |
15890 | } | |
15891 | break; | |
15892 | ||
15893 | case NEUTRAL_IT_INSN: | |
15894 | /* The BKPT instruction is unconditional even in an IT block. */ | |
15895 | break; | |
15896 | ||
15897 | case IT_INSN: | |
15898 | inst.error = BAD_IT_IT; | |
15899 | return FAIL; | |
15900 | } | |
15901 | } | |
15902 | break; | |
15903 | } | |
15904 | ||
15905 | return SUCCESS; | |
15906 | } | |
15907 | ||
15908 | static void | |
15909 | it_fsm_post_encode (void) | |
15910 | { | |
15911 | int is_last; | |
15912 | ||
15913 | if (!now_it.state_handled) | |
15914 | handle_it_state (); | |
15915 | ||
15916 | is_last = (now_it.mask == 0x10); | |
15917 | if (is_last) | |
15918 | { | |
15919 | now_it.state = OUTSIDE_IT_BLOCK; | |
15920 | now_it.mask = 0; | |
15921 | } | |
15922 | } | |
15923 | ||
15924 | static void | |
15925 | force_automatic_it_block_close (void) | |
15926 | { | |
15927 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
15928 | { | |
15929 | close_automatic_it_block (); | |
15930 | now_it.state = OUTSIDE_IT_BLOCK; | |
15931 | now_it.mask = 0; | |
15932 | } | |
15933 | } | |
15934 | ||
15935 | static int | |
15936 | in_it_block (void) | |
15937 | { | |
15938 | if (!now_it.state_handled) | |
15939 | handle_it_state (); | |
15940 | ||
15941 | return now_it.state != OUTSIDE_IT_BLOCK; | |
15942 | } | |
15943 | ||
c19d1205 ZW |
15944 | void |
15945 | md_assemble (char *str) | |
b99bd4ef | 15946 | { |
c19d1205 ZW |
15947 | char *p = str; |
15948 | const struct asm_opcode * opcode; | |
b99bd4ef | 15949 | |
c19d1205 ZW |
15950 | /* Align the previous label if needed. */ |
15951 | if (last_label_seen != NULL) | |
b99bd4ef | 15952 | { |
c19d1205 ZW |
15953 | symbol_set_frag (last_label_seen, frag_now); |
15954 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
15955 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
15956 | } |
15957 | ||
c19d1205 ZW |
15958 | memset (&inst, '\0', sizeof (inst)); |
15959 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 15960 | |
c19d1205 ZW |
15961 | opcode = opcode_lookup (&p); |
15962 | if (!opcode) | |
b99bd4ef | 15963 | { |
c19d1205 | 15964 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 15965 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d NC |
15966 | if (! create_register_alias (str, p) |
15967 | && ! create_neon_reg_alias (str, p)) | |
c19d1205 | 15968 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 15969 | |
b99bd4ef NC |
15970 | return; |
15971 | } | |
15972 | ||
278df34e | 15973 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
088fa78e KH |
15974 | as_warn (_("s suffix on comparison instruction is deprecated")); |
15975 | ||
037e8744 JB |
15976 | /* The value which unconditional instructions should have in place of the |
15977 | condition field. */ | |
15978 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
15979 | ||
c19d1205 | 15980 | if (thumb_mode) |
b99bd4ef | 15981 | { |
e74cfd16 | 15982 | arm_feature_set variant; |
8f06b2d8 PB |
15983 | |
15984 | variant = cpu_variant; | |
15985 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
15986 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
15987 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 15988 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
15989 | if (!opcode->tvariant |
15990 | || (thumb_mode == 1 | |
15991 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 15992 | { |
bf3eeda7 | 15993 | as_bad (_("selected processor does not support Thumb mode `%s'"), str); |
b99bd4ef NC |
15994 | return; |
15995 | } | |
c19d1205 ZW |
15996 | if (inst.cond != COND_ALWAYS && !unified_syntax |
15997 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 15998 | { |
c19d1205 | 15999 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
16000 | return; |
16001 | } | |
16002 | ||
752d5da4 | 16003 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)) |
076d447c | 16004 | { |
7e806470 | 16005 | if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23 |
752d5da4 NC |
16006 | && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr) |
16007 | || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier))) | |
16008 | { | |
16009 | /* Two things are addressed here. | |
16010 | 1) Implicit require narrow instructions on Thumb-1. | |
16011 | This avoids relaxation accidentally introducing Thumb-2 | |
16012 | instructions. | |
16013 | 2) Reject wide instructions in non Thumb-2 cores. */ | |
16014 | if (inst.size_req == 0) | |
16015 | inst.size_req = 2; | |
16016 | else if (inst.size_req == 4) | |
16017 | { | |
bf3eeda7 | 16018 | as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str); |
752d5da4 NC |
16019 | return; |
16020 | } | |
16021 | } | |
076d447c PB |
16022 | } |
16023 | ||
c19d1205 ZW |
16024 | inst.instruction = opcode->tvalue; |
16025 | ||
5be8be5d | 16026 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
e07e6e58 NC |
16027 | { |
16028 | /* Prepare the it_insn_type for those encodings that don't set | |
16029 | it. */ | |
16030 | it_fsm_pre_encode (); | |
c19d1205 | 16031 | |
e07e6e58 NC |
16032 | opcode->tencode (); |
16033 | ||
16034 | it_fsm_post_encode (); | |
16035 | } | |
e27ec89e | 16036 | |
0110f2b8 | 16037 | if (!(inst.error || inst.relax)) |
b99bd4ef | 16038 | { |
9c2799c2 | 16039 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
16040 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
16041 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 16042 | { |
c19d1205 | 16043 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
16044 | return; |
16045 | } | |
16046 | } | |
076d447c PB |
16047 | |
16048 | /* Something has gone badly wrong if we try to relax a fixed size | |
16049 | instruction. */ | |
9c2799c2 | 16050 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 16051 | |
e74cfd16 PB |
16052 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
16053 | *opcode->tvariant); | |
ee065d83 | 16054 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 16055 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
7e806470 | 16056 | anything other than bl/blx and v6-M instructions. |
ee065d83 | 16057 | This is overly pessimistic for relaxable instructions. */ |
7e806470 PB |
16058 | if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) |
16059 | || inst.relax) | |
e07e6e58 NC |
16060 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
16061 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
e74cfd16 PB |
16062 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
16063 | arm_ext_v6t2); | |
cd000bff | 16064 | |
88714cb8 DG |
16065 | check_neon_suffixes; |
16066 | ||
cd000bff | 16067 | if (!inst.error) |
c877a2f2 NC |
16068 | { |
16069 | mapping_state (MAP_THUMB); | |
16070 | } | |
c19d1205 | 16071 | } |
3e9e4fcf | 16072 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 16073 | { |
845b51d6 PB |
16074 | bfd_boolean is_bx; |
16075 | ||
16076 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
16077 | is_bx = (opcode->aencode == do_bx); | |
16078 | ||
c19d1205 | 16079 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
16080 | if (!(is_bx && fix_v4bx) |
16081 | && !(opcode->avariant && | |
16082 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 16083 | { |
bf3eeda7 | 16084 | as_bad (_("selected processor does not support ARM mode `%s'"), str); |
c19d1205 | 16085 | return; |
b99bd4ef | 16086 | } |
c19d1205 | 16087 | if (inst.size_req) |
b99bd4ef | 16088 | { |
c19d1205 ZW |
16089 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
16090 | return; | |
b99bd4ef NC |
16091 | } |
16092 | ||
c19d1205 ZW |
16093 | inst.instruction = opcode->avalue; |
16094 | if (opcode->tag == OT_unconditionalF) | |
16095 | inst.instruction |= 0xF << 28; | |
16096 | else | |
16097 | inst.instruction |= inst.cond << 28; | |
16098 | inst.size = INSN_SIZE; | |
5be8be5d | 16099 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
e07e6e58 NC |
16100 | { |
16101 | it_fsm_pre_encode (); | |
16102 | opcode->aencode (); | |
16103 | it_fsm_post_encode (); | |
16104 | } | |
ee065d83 PB |
16105 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
16106 | on a hypothetical non-thumb v5 core. */ | |
845b51d6 | 16107 | if (is_bx) |
e74cfd16 | 16108 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 16109 | else |
e74cfd16 PB |
16110 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
16111 | *opcode->avariant); | |
88714cb8 DG |
16112 | |
16113 | check_neon_suffixes; | |
16114 | ||
cd000bff | 16115 | if (!inst.error) |
c877a2f2 NC |
16116 | { |
16117 | mapping_state (MAP_ARM); | |
16118 | } | |
b99bd4ef | 16119 | } |
3e9e4fcf JB |
16120 | else |
16121 | { | |
16122 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
16123 | "-- `%s'"), str); | |
16124 | return; | |
16125 | } | |
c19d1205 ZW |
16126 | output_inst (str); |
16127 | } | |
b99bd4ef | 16128 | |
e07e6e58 NC |
16129 | static void |
16130 | check_it_blocks_finished (void) | |
16131 | { | |
16132 | #ifdef OBJ_ELF | |
16133 | asection *sect; | |
16134 | ||
16135 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
16136 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
16137 | == MANUAL_IT_BLOCK) | |
16138 | { | |
16139 | as_warn (_("section '%s' finished with an open IT block."), | |
16140 | sect->name); | |
16141 | } | |
16142 | #else | |
16143 | if (now_it.state == MANUAL_IT_BLOCK) | |
16144 | as_warn (_("file finished with an open IT block.")); | |
16145 | #endif | |
16146 | } | |
16147 | ||
c19d1205 ZW |
16148 | /* Various frobbings of labels and their addresses. */ |
16149 | ||
16150 | void | |
16151 | arm_start_line_hook (void) | |
16152 | { | |
16153 | last_label_seen = NULL; | |
b99bd4ef NC |
16154 | } |
16155 | ||
c19d1205 ZW |
16156 | void |
16157 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 16158 | { |
c19d1205 | 16159 | last_label_seen = sym; |
b99bd4ef | 16160 | |
c19d1205 | 16161 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 16162 | |
c19d1205 ZW |
16163 | #if defined OBJ_COFF || defined OBJ_ELF |
16164 | ARM_SET_INTERWORK (sym, support_interwork); | |
16165 | #endif | |
b99bd4ef | 16166 | |
e07e6e58 NC |
16167 | force_automatic_it_block_close (); |
16168 | ||
5f4273c7 | 16169 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
16170 | as Thumb functions. This is because these labels, whilst |
16171 | they exist inside Thumb code, are not the entry points for | |
16172 | possible ARM->Thumb calls. Also, these labels can be used | |
16173 | as part of a computed goto or switch statement. eg gcc | |
16174 | can generate code that looks like this: | |
b99bd4ef | 16175 | |
c19d1205 ZW |
16176 | ldr r2, [pc, .Laaa] |
16177 | lsl r3, r3, #2 | |
16178 | ldr r2, [r3, r2] | |
16179 | mov pc, r2 | |
b99bd4ef | 16180 | |
c19d1205 ZW |
16181 | .Lbbb: .word .Lxxx |
16182 | .Lccc: .word .Lyyy | |
16183 | ..etc... | |
16184 | .Laaa: .word Lbbb | |
b99bd4ef | 16185 | |
c19d1205 ZW |
16186 | The first instruction loads the address of the jump table. |
16187 | The second instruction converts a table index into a byte offset. | |
16188 | The third instruction gets the jump address out of the table. | |
16189 | The fourth instruction performs the jump. | |
b99bd4ef | 16190 | |
c19d1205 ZW |
16191 | If the address stored at .Laaa is that of a symbol which has the |
16192 | Thumb_Func bit set, then the linker will arrange for this address | |
16193 | to have the bottom bit set, which in turn would mean that the | |
16194 | address computation performed by the third instruction would end | |
16195 | up with the bottom bit set. Since the ARM is capable of unaligned | |
16196 | word loads, the instruction would then load the incorrect address | |
16197 | out of the jump table, and chaos would ensue. */ | |
16198 | if (label_is_thumb_function_name | |
16199 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
16200 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 16201 | { |
c19d1205 ZW |
16202 | /* When the address of a Thumb function is taken the bottom |
16203 | bit of that address should be set. This will allow | |
16204 | interworking between Arm and Thumb functions to work | |
16205 | correctly. */ | |
b99bd4ef | 16206 | |
c19d1205 | 16207 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 16208 | |
c19d1205 | 16209 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 16210 | } |
07a53e5c | 16211 | |
07a53e5c | 16212 | dwarf2_emit_label (sym); |
b99bd4ef NC |
16213 | } |
16214 | ||
c921be7d | 16215 | bfd_boolean |
c19d1205 | 16216 | arm_data_in_code (void) |
b99bd4ef | 16217 | { |
c19d1205 | 16218 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 16219 | { |
c19d1205 ZW |
16220 | *input_line_pointer = '/'; |
16221 | input_line_pointer += 5; | |
16222 | *input_line_pointer = 0; | |
c921be7d | 16223 | return TRUE; |
b99bd4ef NC |
16224 | } |
16225 | ||
c921be7d | 16226 | return FALSE; |
b99bd4ef NC |
16227 | } |
16228 | ||
c19d1205 ZW |
16229 | char * |
16230 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 16231 | { |
c19d1205 | 16232 | int len; |
b99bd4ef | 16233 | |
c19d1205 ZW |
16234 | if (thumb_mode && (len = strlen (name)) > 5 |
16235 | && streq (name + len - 5, "/data")) | |
16236 | *(name + len - 5) = 0; | |
b99bd4ef | 16237 | |
c19d1205 | 16238 | return name; |
b99bd4ef | 16239 | } |
c19d1205 ZW |
16240 | \f |
16241 | /* Table of all register names defined by default. The user can | |
16242 | define additional names with .req. Note that all register names | |
16243 | should appear in both upper and lowercase variants. Some registers | |
16244 | also have mixed-case names. */ | |
b99bd4ef | 16245 | |
dcbf9037 | 16246 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 16247 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 16248 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
16249 | #define REGSET(p,t) \ |
16250 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
16251 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
16252 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
16253 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
16254 | #define REGSETH(p,t) \ |
16255 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
16256 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
16257 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
16258 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
16259 | #define REGSET2(p,t) \ | |
16260 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
16261 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
16262 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
16263 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
16264 | #define SPLRBANK(base,bank,t) \ |
16265 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
16266 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
16267 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
16268 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
16269 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
16270 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 16271 | |
c19d1205 | 16272 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 16273 | { |
c19d1205 ZW |
16274 | /* ARM integer registers. */ |
16275 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 16276 | |
c19d1205 ZW |
16277 | /* ATPCS synonyms. */ |
16278 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
16279 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
16280 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 16281 | |
c19d1205 ZW |
16282 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
16283 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
16284 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 16285 | |
c19d1205 ZW |
16286 | /* Well-known aliases. */ |
16287 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
16288 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
16289 | ||
16290 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
16291 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
16292 | ||
16293 | /* Coprocessor numbers. */ | |
16294 | REGSET(p, CP), REGSET(P, CP), | |
16295 | ||
16296 | /* Coprocessor register numbers. The "cr" variants are for backward | |
16297 | compatibility. */ | |
16298 | REGSET(c, CN), REGSET(C, CN), | |
16299 | REGSET(cr, CN), REGSET(CR, CN), | |
16300 | ||
90ec0d68 MGD |
16301 | /* ARM banked registers. */ |
16302 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
16303 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
16304 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
16305 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
16306 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
16307 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
16308 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
16309 | ||
16310 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
16311 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
16312 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
16313 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
16314 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
16315 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB), | |
16316 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), | |
16317 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
16318 | ||
16319 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
16320 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
16321 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
16322 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
16323 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
16324 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
16325 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
16326 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), | |
16327 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), | |
16328 | ||
c19d1205 ZW |
16329 | /* FPA registers. */ |
16330 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
16331 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
16332 | ||
16333 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
16334 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
16335 | ||
16336 | /* VFP SP registers. */ | |
5287ad62 JB |
16337 | REGSET(s,VFS), REGSET(S,VFS), |
16338 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
16339 | |
16340 | /* VFP DP Registers. */ | |
5287ad62 JB |
16341 | REGSET(d,VFD), REGSET(D,VFD), |
16342 | /* Extra Neon DP registers. */ | |
16343 | REGSETH(d,VFD), REGSETH(D,VFD), | |
16344 | ||
16345 | /* Neon QP registers. */ | |
16346 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
16347 | |
16348 | /* VFP control registers. */ | |
16349 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
16350 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
16351 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
16352 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
16353 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
16354 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
16355 | |
16356 | /* Maverick DSP coprocessor registers. */ | |
16357 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
16358 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
16359 | ||
16360 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
16361 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
16362 | REGDEF(dspsc,0,DSPSC), | |
16363 | ||
16364 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
16365 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
16366 | REGDEF(DSPSC,0,DSPSC), | |
16367 | ||
16368 | /* iWMMXt data registers - p0, c0-15. */ | |
16369 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
16370 | ||
16371 | /* iWMMXt control registers - p1, c0-3. */ | |
16372 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
16373 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
16374 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
16375 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
16376 | ||
16377 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
16378 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
16379 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
16380 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
16381 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
16382 | ||
16383 | /* XScale accumulator registers. */ | |
16384 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
16385 | }; | |
16386 | #undef REGDEF | |
16387 | #undef REGNUM | |
16388 | #undef REGSET | |
7ed4c4c5 | 16389 | |
c19d1205 ZW |
16390 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
16391 | within psr_required_here. */ | |
16392 | static const struct asm_psr psrs[] = | |
16393 | { | |
16394 | /* Backward compatibility notation. Note that "all" is no longer | |
16395 | truly all possible PSR bits. */ | |
16396 | {"all", PSR_c | PSR_f}, | |
16397 | {"flg", PSR_f}, | |
16398 | {"ctl", PSR_c}, | |
16399 | ||
16400 | /* Individual flags. */ | |
16401 | {"f", PSR_f}, | |
16402 | {"c", PSR_c}, | |
16403 | {"x", PSR_x}, | |
16404 | {"s", PSR_s}, | |
59b42a0d MGD |
16405 | {"g", PSR_s}, |
16406 | ||
c19d1205 ZW |
16407 | /* Combinations of flags. */ |
16408 | {"fs", PSR_f | PSR_s}, | |
16409 | {"fx", PSR_f | PSR_x}, | |
16410 | {"fc", PSR_f | PSR_c}, | |
16411 | {"sf", PSR_s | PSR_f}, | |
16412 | {"sx", PSR_s | PSR_x}, | |
16413 | {"sc", PSR_s | PSR_c}, | |
16414 | {"xf", PSR_x | PSR_f}, | |
16415 | {"xs", PSR_x | PSR_s}, | |
16416 | {"xc", PSR_x | PSR_c}, | |
16417 | {"cf", PSR_c | PSR_f}, | |
16418 | {"cs", PSR_c | PSR_s}, | |
16419 | {"cx", PSR_c | PSR_x}, | |
16420 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
16421 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
16422 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
16423 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
16424 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
16425 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
16426 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
16427 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
16428 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
16429 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
16430 | {"scf", PSR_s | PSR_c | PSR_f}, | |
16431 | {"scx", PSR_s | PSR_c | PSR_x}, | |
16432 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
16433 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
16434 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
16435 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
16436 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
16437 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
16438 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
16439 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
16440 | {"csf", PSR_c | PSR_s | PSR_f}, | |
16441 | {"csx", PSR_c | PSR_s | PSR_x}, | |
16442 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
16443 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
16444 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
16445 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
16446 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
16447 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
16448 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
16449 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
16450 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
16451 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
16452 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
16453 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
16454 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
16455 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
16456 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
16457 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
16458 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
16459 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
16460 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
16461 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
16462 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
16463 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
16464 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
16465 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
16466 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
16467 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
59b42a0d MGD |
16468 | |
16469 | /* APSR flags */ | |
16470 | {"nzcvq", PSR_f}, | |
16471 | {"nzcvqg", PSR_s | PSR_f} | |
c19d1205 ZW |
16472 | }; |
16473 | ||
62b3e311 PB |
16474 | /* Table of V7M psr names. */ |
16475 | static const struct asm_psr v7m_psrs[] = | |
16476 | { | |
2b744c99 PB |
16477 | {"apsr", 0 }, {"APSR", 0 }, |
16478 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
16479 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
16480 | {"psr", 3 }, {"PSR", 3 }, | |
16481 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
16482 | {"ipsr", 5 }, {"IPSR", 5 }, | |
16483 | {"epsr", 6 }, {"EPSR", 6 }, | |
16484 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
16485 | {"msp", 8 }, {"MSP", 8 }, | |
16486 | {"psp", 9 }, {"PSP", 9 }, | |
16487 | {"primask", 16}, {"PRIMASK", 16}, | |
16488 | {"basepri", 17}, {"BASEPRI", 17}, | |
16489 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, | |
16490 | {"faultmask", 19}, {"FAULTMASK", 19}, | |
16491 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
16492 | }; |
16493 | ||
c19d1205 ZW |
16494 | /* Table of all shift-in-operand names. */ |
16495 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 16496 | { |
c19d1205 ZW |
16497 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
16498 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
16499 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
16500 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
16501 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
16502 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
16503 | }; | |
b99bd4ef | 16504 | |
c19d1205 ZW |
16505 | /* Table of all explicit relocation names. */ |
16506 | #ifdef OBJ_ELF | |
16507 | static struct reloc_entry reloc_names[] = | |
16508 | { | |
16509 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
16510 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
16511 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
16512 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
16513 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
16514 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
16515 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
16516 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
16517 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
16518 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 NC |
16519 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
16520 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL} | |
c19d1205 ZW |
16521 | }; |
16522 | #endif | |
b99bd4ef | 16523 | |
c19d1205 ZW |
16524 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
16525 | static const struct asm_cond conds[] = | |
16526 | { | |
16527 | {"eq", 0x0}, | |
16528 | {"ne", 0x1}, | |
16529 | {"cs", 0x2}, {"hs", 0x2}, | |
16530 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
16531 | {"mi", 0x4}, | |
16532 | {"pl", 0x5}, | |
16533 | {"vs", 0x6}, | |
16534 | {"vc", 0x7}, | |
16535 | {"hi", 0x8}, | |
16536 | {"ls", 0x9}, | |
16537 | {"ge", 0xa}, | |
16538 | {"lt", 0xb}, | |
16539 | {"gt", 0xc}, | |
16540 | {"le", 0xd}, | |
16541 | {"al", 0xe} | |
16542 | }; | |
bfae80f2 | 16543 | |
62b3e311 PB |
16544 | static struct asm_barrier_opt barrier_opt_names[] = |
16545 | { | |
52e7f43d RE |
16546 | { "sy", 0xf }, { "SY", 0xf }, |
16547 | { "un", 0x7 }, { "UN", 0x7 }, | |
16548 | { "st", 0xe }, { "ST", 0xe }, | |
16549 | { "unst", 0x6 }, { "UNST", 0x6 }, | |
16550 | { "ish", 0xb }, { "ISH", 0xb }, | |
16551 | { "sh", 0xb }, { "SH", 0xb }, | |
16552 | { "ishst", 0xa }, { "ISHST", 0xa }, | |
16553 | { "shst", 0xa }, { "SHST", 0xa }, | |
16554 | { "nsh", 0x7 }, { "NSH", 0x7 }, | |
16555 | { "nshst", 0x6 }, { "NSHST", 0x6 }, | |
16556 | { "osh", 0x3 }, { "OSH", 0x3 }, | |
16557 | { "oshst", 0x2 }, { "OSHST", 0x2 } | |
62b3e311 PB |
16558 | }; |
16559 | ||
c19d1205 ZW |
16560 | /* Table of ARM-format instructions. */ |
16561 | ||
16562 | /* Macros for gluing together operand strings. N.B. In all cases | |
16563 | other than OPS0, the trailing OP_stop comes from default | |
16564 | zero-initialization of the unspecified elements of the array. */ | |
16565 | #define OPS0() { OP_stop, } | |
16566 | #define OPS1(a) { OP_##a, } | |
16567 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
16568 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
16569 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
16570 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
16571 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
16572 | ||
5be8be5d DG |
16573 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
16574 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
16575 | MIX_ARM_THUMB_OPERANDS macro. | |
16576 | In order to use these macros, prefix the number of operands with _ | |
16577 | e.g. _3. */ | |
16578 | #define OPS_1(a) { a, } | |
16579 | #define OPS_2(a,b) { a,b, } | |
16580 | #define OPS_3(a,b,c) { a,b,c, } | |
16581 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
16582 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
16583 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
16584 | ||
c19d1205 ZW |
16585 | /* These macros abstract out the exact format of the mnemonic table and |
16586 | save some repeated characters. */ | |
16587 | ||
16588 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
16589 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16590 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 16591 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16592 | |
16593 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
16594 | a T_MNEM_xyz enumerator. */ | |
16595 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 16596 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 16597 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 16598 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
16599 | |
16600 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
16601 | infix after the third character. */ | |
16602 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16603 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 16604 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 16605 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 16606 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 16607 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 16608 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16609 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 16610 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16611 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 16612 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 16613 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 16614 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 16615 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
16616 | |
16617 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
16618 | appear in the condition table. */ | |
16619 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16620 | { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ |
1887dd22 | 16621 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16622 | |
16623 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
16624 | TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \ |
16625 | TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \ | |
16626 | TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \ | |
16627 | TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \ | |
16628 | TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \ | |
16629 | TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \ | |
16630 | TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \ | |
16631 | TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \ | |
16632 | TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \ | |
16633 | TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \ | |
16634 | TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \ | |
16635 | TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \ | |
16636 | TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \ | |
16637 | TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \ | |
16638 | TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \ | |
16639 | TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \ | |
16640 | TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \ | |
16641 | TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \ | |
16642 | TxCM_ (m1, al, m2, op, top, nops, ops, ae, te) | |
c19d1205 ZW |
16643 | |
16644 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
16645 | TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te) |
16646 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
21d799b5 | 16647 | TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
16648 | |
16649 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
16650 | field is still 0xE. Many of the Thumb variants can be executed |
16651 | conditionally, so this is checked separately. */ | |
c19d1205 | 16652 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 16653 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 16654 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16655 | |
16656 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
16657 | condition code field. */ | |
16658 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 16659 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 16660 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16661 | |
16662 | /* ARM-only variants of all the above. */ | |
6a86118a | 16663 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 16664 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
16665 | |
16666 | #define C3(mnem, op, nops, ops, ae) \ | |
16667 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
16668 | ||
e3cb604e PB |
16669 | /* Legacy mnemonics that always have conditional infix after the third |
16670 | character. */ | |
16671 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16672 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
16673 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
16674 | ||
8f06b2d8 PB |
16675 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
16676 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16677 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 16678 | |
e3cb604e PB |
16679 | /* Legacy coprocessor instructions where conditional infix and conditional |
16680 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
16681 | not just the potentially ambiguous ones. */ | |
16682 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16683 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
16684 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
16685 | ||
16686 | /* Coprocessor, takes either a suffix or a position-3 infix | |
16687 | (for an FPA corner case). */ | |
16688 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 16689 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 16690 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 16691 | |
6a86118a | 16692 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
16693 | { m1 #m2 m3, OPS##nops ops, \ |
16694 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
16695 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
16696 | ||
16697 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
16698 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
16699 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
16700 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
16701 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
16702 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
16703 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
16704 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
16705 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
16706 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
16707 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
16708 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
16709 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
16710 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
16711 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
16712 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
16713 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
16714 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
16715 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
16716 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
16717 | |
16718 | #define UE(mnem, op, nops, ops, ae) \ | |
16719 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16720 | ||
16721 | #define UF(mnem, op, nops, ops, ae) \ | |
16722 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16723 | ||
5287ad62 JB |
16724 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
16725 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
16726 | use the same encoding function for each. */ | |
16727 | #define NUF(mnem, op, nops, ops, enc) \ | |
16728 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
16729 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16730 | ||
16731 | /* Neon data processing, version which indirects through neon_enc_tab for | |
16732 | the various overloaded versions of opcodes. */ | |
16733 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 16734 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
16735 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
16736 | ||
16737 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
16738 | version. */ | |
037e8744 JB |
16739 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
16740 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
16741 | THUMB_VARIANT, do_##enc, do_##enc } |
16742 | ||
037e8744 | 16743 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16744 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16745 | |
16746 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16747 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16748 | |
5287ad62 | 16749 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 16750 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 16751 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
16752 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
16753 | ||
037e8744 | 16754 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16755 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16756 | |
16757 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16758 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16759 | |
c19d1205 ZW |
16760 | #define do_0 0 |
16761 | ||
c19d1205 | 16762 | static const struct asm_opcode insns[] = |
bfae80f2 | 16763 | { |
e74cfd16 PB |
16764 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
16765 | #define THUMB_VARIANT &arm_ext_v4t | |
21d799b5 NC |
16766 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
16767 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
16768 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
16769 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
16770 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
16771 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
16772 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
16773 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
16774 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
16775 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16776 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
16777 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
16778 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
16779 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16780 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
16781 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
16782 | |
16783 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
16784 | for setting PSR flag bits. They are obsolete in V6 and do not | |
16785 | have Thumb equivalents. */ | |
21d799b5 NC |
16786 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
16787 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
16788 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
16789 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
16790 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
16791 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
16792 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
16793 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
16794 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
16795 | ||
16796 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
16797 | tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp), | |
16798 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), | |
16799 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
16800 | ||
16801 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
16802 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
16803 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
16804 | OP_RRnpc), | |
16805 | OP_ADDRGLDR),ldst, t_ldst), | |
16806 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
16807 | |
16808 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16809 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16810 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16811 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16812 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16813 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16814 | ||
16815 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
16816 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
16817 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), | |
16818 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 16819 | |
c19d1205 | 16820 | /* Pseudo ops. */ |
21d799b5 | 16821 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 16822 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 16823 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
c19d1205 ZW |
16824 | |
16825 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
16826 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
16827 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
16828 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
16829 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
16830 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
16831 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
16832 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
16833 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
16834 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
16835 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
16836 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
16837 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 16838 | |
16a4cf17 | 16839 | /* These may simplify to neg. */ |
21d799b5 NC |
16840 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
16841 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 16842 | |
c921be7d NC |
16843 | #undef THUMB_VARIANT |
16844 | #define THUMB_VARIANT & arm_ext_v6 | |
16845 | ||
21d799b5 | 16846 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
16847 | |
16848 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
16849 | #undef THUMB_VARIANT |
16850 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16851 | ||
21d799b5 NC |
16852 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
16853 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
16854 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 16855 | |
5be8be5d DG |
16856 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
16857 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
16858 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
16859 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 16860 | |
21d799b5 NC |
16861 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16862 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 16863 | |
21d799b5 NC |
16864 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16865 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
16866 | |
16867 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 16868 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
16869 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
16870 | ||
16871 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
16872 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
16873 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
16874 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
16875 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
16876 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
16877 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
16878 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
16879 | ||
c921be7d NC |
16880 | #undef ARM_VARIANT |
16881 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
16882 | #undef THUMB_VARIANT | |
16883 | #define THUMB_VARIANT & arm_ext_v4t | |
16884 | ||
21d799b5 NC |
16885 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
16886 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 16887 | |
c921be7d NC |
16888 | #undef THUMB_VARIANT |
16889 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16890 | ||
21d799b5 | 16891 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
16892 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
16893 | ||
16894 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
16895 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
16896 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16897 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16898 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16899 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16900 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 16901 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 16902 | |
c921be7d NC |
16903 | #undef ARM_VARIANT |
16904 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
16905 | ||
21d799b5 | 16906 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
16907 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
16908 | ||
c921be7d NC |
16909 | #undef ARM_VARIANT |
16910 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
16911 | #undef THUMB_VARIANT | |
16912 | #define THUMB_VARIANT & arm_ext_msr | |
16913 | ||
90ec0d68 | 16914 | TCE("mrs", 1000000, f3e08000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
21d799b5 | 16915 | TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), |
c19d1205 | 16916 | |
c921be7d NC |
16917 | #undef ARM_VARIANT |
16918 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
16919 | #undef THUMB_VARIANT | |
16920 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16921 | ||
21d799b5 NC |
16922 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
16923 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16924 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16925 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16926 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16927 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16928 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16929 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 16930 | |
c921be7d NC |
16931 | #undef ARM_VARIANT |
16932 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
16933 | #undef THUMB_VARIANT | |
16934 | #define THUMB_VARIANT & arm_ext_v4t | |
16935 | ||
5be8be5d DG |
16936 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
16937 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
16938 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
16939 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
16940 | tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
16941 | tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 16942 | |
c921be7d NC |
16943 | #undef ARM_VARIANT |
16944 | #define ARM_VARIANT & arm_ext_v4t_5 | |
16945 | ||
c19d1205 ZW |
16946 | /* ARM Architecture 4T. */ |
16947 | /* Note: bx (and blx) are required on V5, even if the processor does | |
16948 | not support Thumb. */ | |
21d799b5 | 16949 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 16950 | |
c921be7d NC |
16951 | #undef ARM_VARIANT |
16952 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
16953 | #undef THUMB_VARIANT | |
16954 | #define THUMB_VARIANT & arm_ext_v5t | |
16955 | ||
c19d1205 ZW |
16956 | /* Note: blx has 2 variants; the .value coded here is for |
16957 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
16958 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
16959 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 16960 | |
c921be7d NC |
16961 | #undef THUMB_VARIANT |
16962 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16963 | ||
21d799b5 NC |
16964 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
16965 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16966 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16967 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16968 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16969 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
16970 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16971 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 16972 | |
c921be7d NC |
16973 | #undef ARM_VARIANT |
16974 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ | |
9e3c6df6 PB |
16975 | #undef THUMB_VARIANT |
16976 | #define THUMB_VARIANT &arm_ext_v5exp | |
c921be7d | 16977 | |
21d799b5 NC |
16978 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16979 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16980 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16981 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 16982 | |
21d799b5 NC |
16983 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16984 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 16985 | |
21d799b5 NC |
16986 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
16987 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16988 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16989 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 16990 | |
21d799b5 NC |
16991 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
16992 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16993 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16994 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 16995 | |
21d799b5 NC |
16996 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
16997 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 16998 | |
03ee1b7f NC |
16999 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
17000 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
17001 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
17002 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 17003 | |
c921be7d NC |
17004 | #undef ARM_VARIANT |
17005 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ | |
9e3c6df6 PB |
17006 | #undef THUMB_VARIANT |
17007 | #define THUMB_VARIANT &arm_ext_v6t2 | |
c921be7d | 17008 | |
21d799b5 | 17009 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
17010 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
17011 | ldrd, t_ldstd), | |
17012 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
17013 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 17014 | |
21d799b5 NC |
17015 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
17016 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 17017 | |
c921be7d NC |
17018 | #undef ARM_VARIANT |
17019 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
17020 | ||
21d799b5 | 17021 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 17022 | |
c921be7d NC |
17023 | #undef ARM_VARIANT |
17024 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
17025 | #undef THUMB_VARIANT | |
17026 | #define THUMB_VARIANT & arm_ext_v6 | |
17027 | ||
21d799b5 NC |
17028 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
17029 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
17030 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
17031 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
17032 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
17033 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
17034 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
17035 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
17036 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
17037 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 17038 | |
c921be7d NC |
17039 | #undef THUMB_VARIANT |
17040 | #define THUMB_VARIANT & arm_ext_v6t2 | |
17041 | ||
5be8be5d DG |
17042 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
17043 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
17044 | strex, t_strex), | |
21d799b5 NC |
17045 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
17046 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 17047 | |
21d799b5 NC |
17048 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
17049 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 17050 | |
9e3c6df6 | 17051 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
17052 | #undef THUMB_VARIANT |
17053 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 PB |
17054 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
17055 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
17056 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
17057 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
17058 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
17059 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
17060 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
17061 | TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
17062 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
17063 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), | |
17064 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), | |
17065 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), | |
c921be7d | 17066 | |
9e3c6df6 PB |
17067 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
17068 | #undef THUMB_VARIANT | |
17069 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
17070 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
17071 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), | |
17072 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
17073 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17074 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17075 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17076 | /* Old name for QASX. */ |
21d799b5 NC |
17077 | TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17078 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17079 | /* Old name for QSAX. */ |
21d799b5 NC |
17080 | TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17081 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17082 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17083 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17084 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17085 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17086 | /* Old name for SASX. */ |
21d799b5 NC |
17087 | TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17088 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17089 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17090 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17091 | /* Old name for SHASX. */ |
21d799b5 NC |
17092 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17093 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17094 | /* Old name for SHSAX. */ |
21d799b5 NC |
17095 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17096 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17097 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17098 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17099 | /* Old name for SSAX. */ |
21d799b5 NC |
17100 | TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17101 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17102 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17103 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17104 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17105 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17106 | /* Old name for UASX. */ |
21d799b5 NC |
17107 | TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17108 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17109 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17110 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17111 | /* Old name for UHASX. */ |
21d799b5 NC |
17112 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17113 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17114 | /* Old name for UHSAX. */ |
21d799b5 NC |
17115 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17116 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17117 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17118 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17119 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17120 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17121 | /* Old name for UQASX. */ |
21d799b5 NC |
17122 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17123 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17124 | /* Old name for UQSAX. */ |
21d799b5 NC |
17125 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17126 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17127 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17128 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17129 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 17130 | /* Old name for USAX. */ |
21d799b5 NC |
17131 | TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
17132 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
21d799b5 NC |
17133 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
17134 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
17135 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
17136 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
17137 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
17138 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
17139 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
17140 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
17141 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
17142 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17143 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17144 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
17145 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
17146 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17147 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17148 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
17149 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
17150 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17151 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17152 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17153 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17154 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
17155 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
17156 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
17157 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
17158 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
17159 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
17160 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
17161 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
17162 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
17163 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
17164 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 17165 | |
c921be7d NC |
17166 | #undef ARM_VARIANT |
17167 | #define ARM_VARIANT & arm_ext_v6k | |
17168 | #undef THUMB_VARIANT | |
17169 | #define THUMB_VARIANT & arm_ext_v6k | |
17170 | ||
21d799b5 NC |
17171 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
17172 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
17173 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
17174 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 17175 | |
c921be7d NC |
17176 | #undef THUMB_VARIANT |
17177 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
17178 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
17179 | ldrexd, t_ldrexd), | |
17180 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
17181 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 17182 | |
c921be7d NC |
17183 | #undef THUMB_VARIANT |
17184 | #define THUMB_VARIANT & arm_ext_v6t2 | |
5be8be5d DG |
17185 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
17186 | rd_rn, rd_rn), | |
17187 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
17188 | rd_rn, rd_rn), | |
17189 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
17190 | strex, rm_rd_rn), | |
17191 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
17192 | strex, rm_rd_rn), | |
21d799b5 | 17193 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 17194 | |
c921be7d | 17195 | #undef ARM_VARIANT |
f4c65163 MGD |
17196 | #define ARM_VARIANT & arm_ext_sec |
17197 | #undef THUMB_VARIANT | |
17198 | #define THUMB_VARIANT & arm_ext_sec | |
c921be7d | 17199 | |
21d799b5 | 17200 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 17201 | |
90ec0d68 MGD |
17202 | #undef ARM_VARIANT |
17203 | #define ARM_VARIANT & arm_ext_virt | |
17204 | #undef THUMB_VARIANT | |
17205 | #define THUMB_VARIANT & arm_ext_virt | |
17206 | ||
17207 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
17208 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
17209 | ||
c921be7d NC |
17210 | #undef ARM_VARIANT |
17211 | #define ARM_VARIANT & arm_ext_v6t2 | |
f4c65163 MGD |
17212 | #undef THUMB_VARIANT |
17213 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 17214 | |
21d799b5 NC |
17215 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
17216 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
17217 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
17218 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 17219 | |
21d799b5 NC |
17220 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
17221 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
17222 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
17223 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), | |
c19d1205 | 17224 | |
5be8be5d DG |
17225 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
17226 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
17227 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
17228 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 17229 | |
bf3eeda7 NS |
17230 | /* Thumb-only instructions. */ |
17231 | #undef ARM_VARIANT | |
17232 | #define ARM_VARIANT NULL | |
17233 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
17234 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
17235 | |
17236 | /* ARM does not really have an IT instruction, so always allow it. | |
17237 | The opcode is copied from Thumb in order to allow warnings in | |
17238 | -mimplicit-it=[never | arm] modes. */ | |
17239 | #undef ARM_VARIANT | |
17240 | #define ARM_VARIANT & arm_ext_v1 | |
17241 | ||
21d799b5 NC |
17242 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
17243 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
17244 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
17245 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
17246 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
17247 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
17248 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
17249 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
17250 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
17251 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
17252 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
17253 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
17254 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
17255 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
17256 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 17257 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
17258 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
17259 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 17260 | |
92e90b6e | 17261 | /* Thumb2 only instructions. */ |
c921be7d NC |
17262 | #undef ARM_VARIANT |
17263 | #define ARM_VARIANT NULL | |
92e90b6e | 17264 | |
21d799b5 NC |
17265 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
17266 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
17267 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
17268 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
17269 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
17270 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 17271 | |
eea54501 MGD |
17272 | /* Hardware division instructions. */ |
17273 | #undef ARM_VARIANT | |
17274 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
17275 | #undef THUMB_VARIANT |
17276 | #define THUMB_VARIANT & arm_ext_div | |
17277 | ||
eea54501 MGD |
17278 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
17279 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 17280 | |
7e806470 | 17281 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
17282 | #undef ARM_VARIANT |
17283 | #define ARM_VARIANT & arm_ext_barrier | |
17284 | #undef THUMB_VARIANT | |
17285 | #define THUMB_VARIANT & arm_ext_barrier | |
17286 | ||
52e7f43d RE |
17287 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier), |
17288 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier), | |
17289 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier), | |
7e806470 | 17290 | |
62b3e311 | 17291 | /* ARM V7 instructions. */ |
c921be7d NC |
17292 | #undef ARM_VARIANT |
17293 | #define ARM_VARIANT & arm_ext_v7 | |
17294 | #undef THUMB_VARIANT | |
17295 | #define THUMB_VARIANT & arm_ext_v7 | |
17296 | ||
21d799b5 NC |
17297 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
17298 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 17299 | |
60e5ef9f MGD |
17300 | #undef ARM_VARIANT |
17301 | #define ARM_VARIANT & arm_ext_mp | |
17302 | #undef THUMB_VARIANT | |
17303 | #define THUMB_VARIANT & arm_ext_mp | |
17304 | ||
17305 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
17306 | ||
c921be7d NC |
17307 | #undef ARM_VARIANT |
17308 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
17309 | ||
21d799b5 NC |
17310 | cCE("wfs", e200110, 1, (RR), rd), |
17311 | cCE("rfs", e300110, 1, (RR), rd), | |
17312 | cCE("wfc", e400110, 1, (RR), rd), | |
17313 | cCE("rfc", e500110, 1, (RR), rd), | |
17314 | ||
17315 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17316 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17317 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17318 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17319 | ||
17320 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17321 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17322 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17323 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
17324 | ||
17325 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
17326 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
17327 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
17328 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
17329 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
17330 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
17331 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
17332 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
17333 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
17334 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
17335 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
17336 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
17337 | ||
17338 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
17339 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
17340 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
17341 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
17342 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
17343 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
17344 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
17345 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
17346 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
17347 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
17348 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
17349 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
17350 | ||
17351 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
17352 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
17353 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
17354 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
17355 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
17356 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
17357 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
17358 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
17359 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
17360 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
17361 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
17362 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
17363 | ||
17364 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
17365 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
17366 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
17367 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
17368 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
17369 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
17370 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
17371 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
17372 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
17373 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
17374 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
17375 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
17376 | ||
17377 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
17378 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
17379 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
17380 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
17381 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
17382 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
17383 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
17384 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
17385 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
17386 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
17387 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
17388 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
17389 | ||
17390 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
17391 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
17392 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
17393 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
17394 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
17395 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
17396 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
17397 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
17398 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
17399 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
17400 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
17401 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
17402 | ||
17403 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
17404 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
17405 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
17406 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
17407 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
17408 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
17409 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
17410 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
17411 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
17412 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
17413 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
17414 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
17415 | ||
17416 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
17417 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
17418 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
17419 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
17420 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
17421 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
17422 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
17423 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
17424 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
17425 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
17426 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
17427 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
17428 | ||
17429 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
17430 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
17431 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
17432 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
17433 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
17434 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
17435 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
17436 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
17437 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
17438 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
17439 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
17440 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
17441 | ||
17442 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
17443 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
17444 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
17445 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
17446 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
17447 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
17448 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
17449 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
17450 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
17451 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
17452 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
17453 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
17454 | ||
17455 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
17456 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
17457 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
17458 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
17459 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
17460 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
17461 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
17462 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
17463 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
17464 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
17465 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
17466 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
17467 | ||
17468 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
17469 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
17470 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
17471 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
17472 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
17473 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
17474 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
17475 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
17476 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
17477 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
17478 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
17479 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
17480 | ||
17481 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
17482 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
17483 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
17484 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
17485 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
17486 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
17487 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
17488 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
17489 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
17490 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
17491 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
17492 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
17493 | ||
17494 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
17495 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
17496 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
17497 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
17498 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
17499 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
17500 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
17501 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
17502 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
17503 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
17504 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
17505 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
17506 | ||
17507 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
17508 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
17509 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
17510 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
17511 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
17512 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
17513 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
17514 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
17515 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
17516 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
17517 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
17518 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
17519 | ||
17520 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
17521 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
17522 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
17523 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
17524 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
17525 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
17526 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
17527 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
17528 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
17529 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
17530 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
17531 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
17532 | ||
17533 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17534 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17535 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17536 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17537 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17538 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17539 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17540 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17541 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17542 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17543 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17544 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17545 | ||
17546 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17547 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17548 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17549 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17550 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17551 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17552 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17553 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17554 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17555 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17556 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17557 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17558 | ||
17559 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17560 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17561 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17562 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17563 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17564 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17565 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17566 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17567 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17568 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17569 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17570 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17571 | ||
17572 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17573 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17574 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17575 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17576 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17577 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17578 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17579 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17580 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17581 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17582 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17583 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17584 | ||
17585 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17586 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17587 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17588 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17589 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17590 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17591 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17592 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17593 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17594 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17595 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17596 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17597 | ||
17598 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17599 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17600 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17601 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17602 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17603 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17604 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17605 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17606 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17607 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17608 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17609 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17610 | ||
17611 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17612 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17613 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17614 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17615 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17616 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17617 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17618 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17619 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17620 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17621 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17622 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17623 | ||
17624 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17625 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17626 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17627 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17628 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17629 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17630 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17631 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17632 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17633 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17634 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17635 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17636 | ||
17637 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17638 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17639 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17640 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17641 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17642 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17643 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17644 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17645 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17646 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17647 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17648 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17649 | ||
17650 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17651 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17652 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17653 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17654 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17655 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17656 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17657 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17658 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17659 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17660 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17661 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17662 | ||
17663 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17664 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17665 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17666 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17667 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17668 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17669 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17670 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17671 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17672 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17673 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17674 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17675 | ||
17676 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17677 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17678 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17679 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17680 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17681 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17682 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17683 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17684 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17685 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17686 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17687 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17688 | ||
17689 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17690 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17691 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17692 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17693 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17694 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17695 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17696 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17697 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17698 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17699 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17700 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17701 | ||
17702 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
17703 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
17704 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
17705 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
17706 | ||
17707 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
17708 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
17709 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
17710 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
17711 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
17712 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
17713 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
17714 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
17715 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
17716 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
17717 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
17718 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 17719 | |
c19d1205 ZW |
17720 | /* The implementation of the FIX instruction is broken on some |
17721 | assemblers, in that it accepts a precision specifier as well as a | |
17722 | rounding specifier, despite the fact that this is meaningless. | |
17723 | To be more compatible, we accept it as well, though of course it | |
17724 | does not set any bits. */ | |
21d799b5 NC |
17725 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
17726 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
17727 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
17728 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
17729 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
17730 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
17731 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
17732 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
17733 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
17734 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
17735 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
17736 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
17737 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 17738 | |
c19d1205 | 17739 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
17740 | #undef ARM_VARIANT |
17741 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
17742 | ||
21d799b5 NC |
17743 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
17744 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17745 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17746 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17747 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
17748 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 17749 | |
c921be7d NC |
17750 | #undef ARM_VARIANT |
17751 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
17752 | ||
c19d1205 | 17753 | /* Moves and type conversions. */ |
21d799b5 NC |
17754 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
17755 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
17756 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
17757 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
f7c21dc7 NC |
17758 | cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs), |
17759 | cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr), | |
21d799b5 NC |
17760 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), |
17761 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17762 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17763 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17764 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17765 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17766 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
17767 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
17768 | |
17769 | /* Memory operations. */ | |
21d799b5 NC |
17770 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
17771 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
17772 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
17773 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
17774 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
17775 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
17776 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
17777 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
17778 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
17779 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
17780 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
17781 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
17782 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
17783 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
17784 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
17785 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
17786 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
17787 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 17788 | |
c19d1205 | 17789 | /* Monadic operations. */ |
21d799b5 NC |
17790 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
17791 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17792 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
17793 | |
17794 | /* Dyadic operations. */ | |
21d799b5 NC |
17795 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
17796 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17797 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17798 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17799 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17800 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17801 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17802 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17803 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 17804 | |
c19d1205 | 17805 | /* Comparisons. */ |
21d799b5 NC |
17806 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
17807 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
17808 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17809 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 17810 | |
62f3b8c8 PB |
17811 | /* Double precision load/store are still present on single precision |
17812 | implementations. */ | |
17813 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
17814 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
17815 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
17816 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
17817 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
17818 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
17819 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
17820 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
17821 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
17822 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 17823 | |
c921be7d NC |
17824 | #undef ARM_VARIANT |
17825 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
17826 | ||
c19d1205 | 17827 | /* Moves and type conversions. */ |
21d799b5 NC |
17828 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17829 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17830 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17831 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17832 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17833 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17834 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17835 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17836 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17837 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17838 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17839 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17840 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 17841 | |
c19d1205 | 17842 | /* Monadic operations. */ |
21d799b5 NC |
17843 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
17844 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17845 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
17846 | |
17847 | /* Dyadic operations. */ | |
21d799b5 NC |
17848 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
17849 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17850 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17851 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17852 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17853 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17854 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17855 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17856 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 17857 | |
c19d1205 | 17858 | /* Comparisons. */ |
21d799b5 NC |
17859 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17860 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
17861 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17862 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 17863 | |
c921be7d NC |
17864 | #undef ARM_VARIANT |
17865 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
17866 | ||
21d799b5 NC |
17867 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
17868 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
17869 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
17870 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 17871 | |
037e8744 JB |
17872 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
17873 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
17874 | #undef ARM_VARIANT |
17875 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
17876 | #undef THUMB_VARIANT | |
17877 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
17878 | ||
037e8744 JB |
17879 | /* These mnemonics are unique to VFP. */ |
17880 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
17881 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
17882 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
17883 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17884 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17885 | nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17886 | nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
037e8744 JB |
17887 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
17888 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
17889 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
17890 | ||
17891 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
17892 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
17893 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17894 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 17895 | |
21d799b5 NC |
17896 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
17897 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
17898 | |
17899 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17900 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17901 | ||
55881a11 MGD |
17902 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
17903 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
17904 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
17905 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
17906 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
17907 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
17908 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
17909 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 | 17910 | |
e3e535bc NC |
17911 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), |
17912 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), | |
21d799b5 NC |
17913 | nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb), |
17914 | nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt), | |
f31fef98 | 17915 | |
037e8744 JB |
17916 | |
17917 | /* NOTE: All VMOV encoding is special-cased! */ | |
17918 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
17919 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
17920 | ||
c921be7d NC |
17921 | #undef THUMB_VARIANT |
17922 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
17923 | #undef ARM_VARIANT | |
17924 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
17925 | ||
5287ad62 JB |
17926 | /* Data processing with three registers of the same length. */ |
17927 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
17928 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
17929 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
17930 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17931 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17932 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17933 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17934 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17935 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17936 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17937 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17938 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
17939 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17940 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
17941 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
17942 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
17943 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
17944 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
17945 | /* If not immediate, fall back to neon_dyadic_i64_su. |
17946 | shl_imm should accept I8 I16 I32 I64, | |
17947 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
17948 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
17949 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
17950 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
17951 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 17952 | /* Logic ops, types optional & ignored. */ |
4316f0d2 DG |
17953 | nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), |
17954 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
17955 | nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
17956 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
17957 | nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
17958 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
17959 | nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
17960 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
17961 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
17962 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
17963 | /* Bitfield ops, untyped. */ |
17964 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17965 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17966 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17967 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17968 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17969 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17970 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
21d799b5 NC |
17971 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
17972 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17973 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17974 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17975 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17976 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
17977 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
17978 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
17979 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
17980 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17981 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17982 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17983 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17984 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
17985 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17986 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 17987 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
17988 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
17989 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 17990 | /* As above, D registers only. */ |
21d799b5 NC |
17991 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
17992 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 17993 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
17994 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
17995 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
17996 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 17997 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
17998 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
17999 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
18000 | /* vtst takes sizes 8, 16, 32. */ |
18001 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
18002 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
18003 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 18004 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 18005 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
18006 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
18007 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
18008 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
18009 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
18010 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
18011 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
18012 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
18013 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
18014 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
18015 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
18016 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
18017 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
18018 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
18019 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
18020 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
18021 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
18022 | ||
18023 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 18024 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
18025 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
18026 | ||
18027 | /* Data processing with two registers and a shift amount. */ | |
18028 | /* Right shifts, and variants with rounding. | |
18029 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
18030 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
18031 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
18032 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
18033 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
18034 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
18035 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
18036 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
18037 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
18038 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
18039 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
18040 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
18041 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
18042 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
18043 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
18044 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
18045 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
18046 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
18047 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
18048 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
18049 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
18050 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
18051 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
18052 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
18053 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
18054 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
18055 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
18056 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 18057 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 18058 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 18059 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 18060 | |
4316f0d2 DG |
18061 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn), |
18062 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), | |
5287ad62 JB |
18063 | |
18064 | /* Data processing, three registers of different lengths. */ | |
18065 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
18066 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
18067 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
18068 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
18069 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
18070 | /* If not scalar, fall back to neon_dyadic_long. | |
18071 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
18072 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
18073 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
18074 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
18075 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
18076 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
18077 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
18078 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
18079 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
18080 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
18081 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
18082 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
18083 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
18084 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
18085 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
18086 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
18087 | S16 S32 U16 U32. */ | |
21d799b5 | 18088 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
18089 | |
18090 | /* Extract. Size 8. */ | |
3b8d421e PB |
18091 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
18092 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
18093 | |
18094 | /* Two registers, miscellaneous. */ | |
18095 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
18096 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
18097 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
18098 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
18099 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
18100 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
18101 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
18102 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
18103 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
18104 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
18105 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
18106 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
18107 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 18108 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 18109 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 18110 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 18111 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 18112 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
18113 | /* VZIP / VUZP. Sizes 8 16 32. */ |
18114 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
18115 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
18116 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
18117 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
18118 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
18119 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
18120 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
18121 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
18122 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
18123 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
18124 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
18125 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
18126 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
18127 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
18128 | /* Reciprocal estimates. Types U32 F32. */ | |
18129 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
18130 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
18131 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
18132 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
18133 | /* VCLS. Types S8 S16 S32. */ | |
18134 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
18135 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
18136 | /* VCLZ. Types I8 I16 I32. */ | |
18137 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
18138 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
18139 | /* VCNT. Size 8. */ | |
18140 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
18141 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
18142 | /* Two address, untyped. */ | |
18143 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
18144 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
18145 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
18146 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
18147 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
18148 | |
18149 | /* Table lookup. Size 8. */ | |
18150 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
18151 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
18152 | ||
c921be7d NC |
18153 | #undef THUMB_VARIANT |
18154 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
18155 | #undef ARM_VARIANT | |
18156 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
18157 | ||
5287ad62 | 18158 | /* Neon element/structure load/store. */ |
21d799b5 NC |
18159 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
18160 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
18161 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
18162 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
18163 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
18164 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
18165 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
18166 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 18167 | |
c921be7d | 18168 | #undef THUMB_VARIANT |
62f3b8c8 PB |
18169 | #define THUMB_VARIANT &fpu_vfp_ext_v3xd |
18170 | #undef ARM_VARIANT | |
18171 | #define ARM_VARIANT &fpu_vfp_ext_v3xd | |
18172 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), | |
18173 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
18174 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
18175 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
18176 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
18177 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
18178 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
18179 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
18180 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
18181 | ||
18182 | #undef THUMB_VARIANT | |
c921be7d NC |
18183 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
18184 | #undef ARM_VARIANT | |
18185 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
18186 | ||
21d799b5 | 18187 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 18188 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 18189 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 18190 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 18191 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 18192 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 18193 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 18194 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 18195 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 18196 | |
62f3b8c8 PB |
18197 | #undef ARM_VARIANT |
18198 | #define ARM_VARIANT &fpu_vfp_ext_fma | |
18199 | #undef THUMB_VARIANT | |
18200 | #define THUMB_VARIANT &fpu_vfp_ext_fma | |
18201 | /* Mnemonics shared by Neon and VFP. These are included in the | |
18202 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
18203 | FMA instructions. */ | |
18204 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
18205 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
18206 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
18207 | the v form should always be used. */ | |
18208 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
18209 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
18210 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
18211 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
18212 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
18213 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
18214 | ||
5287ad62 | 18215 | #undef THUMB_VARIANT |
c921be7d NC |
18216 | #undef ARM_VARIANT |
18217 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
18218 | ||
21d799b5 NC |
18219 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
18220 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
18221 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
18222 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
18223 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
18224 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
18225 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
18226 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 18227 | |
c921be7d NC |
18228 | #undef ARM_VARIANT |
18229 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
18230 | ||
21d799b5 NC |
18231 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
18232 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
18233 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
18234 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
18235 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
18236 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
18237 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
18238 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
18239 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
18240 | cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
18241 | cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
18242 | cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
18243 | cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
18244 | cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
18245 | cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
18246 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
18247 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
18248 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
18249 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
18250 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
18251 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
18252 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
18253 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
18254 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
18255 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
18256 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
18257 | cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn), | |
18258 | cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn), | |
18259 | cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn), | |
18260 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), | |
18261 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
18262 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
18263 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
18264 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
18265 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
18266 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
18267 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
18268 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18269 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18270 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18271 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18272 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18273 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18274 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18275 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18276 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18277 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
18278 | cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18279 | cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18280 | cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18281 | cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18282 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18283 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18284 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18285 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18286 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18287 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18288 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18289 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18290 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18291 | cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18292 | cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18293 | cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18294 | cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18295 | cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18296 | cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18297 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
18298 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
18299 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
18300 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
18301 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18302 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18303 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18304 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18305 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18306 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18307 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18308 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18309 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18310 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18311 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18312 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18313 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18314 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18315 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18316 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18317 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18318 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18319 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
18320 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18321 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18322 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18323 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18324 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18325 | cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18326 | cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18327 | cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18328 | cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18329 | cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18330 | cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18331 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18332 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18333 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18334 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18335 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18336 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18337 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18338 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18339 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18340 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18341 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
18342 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18343 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18344 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18345 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18346 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18347 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18348 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18349 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18350 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18351 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18352 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18353 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18354 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18355 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18356 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18357 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18358 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
18359 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
18360 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
18361 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
18362 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
18363 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
18364 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18365 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18366 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18367 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18368 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18369 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18370 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18371 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18372 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18373 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
18374 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
18375 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
18376 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
18377 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
18378 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
18379 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18380 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18381 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18382 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
18383 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
18384 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
18385 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
18386 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
18387 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
18388 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18389 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18390 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18391 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18392 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 18393 | |
c921be7d NC |
18394 | #undef ARM_VARIANT |
18395 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
18396 | ||
21d799b5 NC |
18397 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
18398 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
18399 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
18400 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
18401 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
18402 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
18403 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18404 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18405 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18406 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18407 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18408 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18409 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18410 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18411 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18412 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18413 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18414 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18415 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18416 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18417 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
18418 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18419 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18420 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18421 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18422 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18423 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18424 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18425 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18426 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18427 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18428 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18429 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18430 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18431 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18432 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18433 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18434 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18435 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18436 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18437 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18438 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18439 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18440 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18441 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18442 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18443 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18444 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18445 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18446 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18447 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18448 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18449 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18450 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18451 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18452 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
18453 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 18454 | |
c921be7d NC |
18455 | #undef ARM_VARIANT |
18456 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
18457 | ||
21d799b5 NC |
18458 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
18459 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
18460 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
18461 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
18462 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
18463 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
18464 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
18465 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
18466 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
18467 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
18468 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
18469 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
18470 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
18471 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
18472 | cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd), | |
18473 | cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn), | |
18474 | cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd), | |
18475 | cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn), | |
18476 | cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn), | |
18477 | cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn), | |
18478 | cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn), | |
18479 | cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn), | |
18480 | cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn), | |
18481 | cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn), | |
18482 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), | |
18483 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
18484 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
18485 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
18486 | cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
18487 | cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd), | |
18488 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), | |
18489 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
18490 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
18491 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
18492 | cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn), | |
18493 | cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn), | |
18494 | cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn), | |
18495 | cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn), | |
18496 | cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn), | |
18497 | cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn), | |
18498 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), | |
18499 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
18500 | cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
18501 | cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
18502 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
18503 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
18504 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
18505 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
18506 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
18507 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
18508 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
18509 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
18510 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
18511 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
18512 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
18513 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
18514 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
18515 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
18516 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
18517 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
18518 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
18519 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
18520 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
18521 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
18522 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
18523 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
18524 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
18525 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
18526 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
18527 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
18528 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
18529 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
18530 | cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
18531 | cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
18532 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
18533 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
18534 | }; |
18535 | #undef ARM_VARIANT | |
18536 | #undef THUMB_VARIANT | |
18537 | #undef TCE | |
18538 | #undef TCM | |
18539 | #undef TUE | |
18540 | #undef TUF | |
18541 | #undef TCC | |
8f06b2d8 | 18542 | #undef cCE |
e3cb604e PB |
18543 | #undef cCL |
18544 | #undef C3E | |
c19d1205 ZW |
18545 | #undef CE |
18546 | #undef CM | |
18547 | #undef UE | |
18548 | #undef UF | |
18549 | #undef UT | |
5287ad62 JB |
18550 | #undef NUF |
18551 | #undef nUF | |
18552 | #undef NCE | |
18553 | #undef nCE | |
c19d1205 ZW |
18554 | #undef OPS0 |
18555 | #undef OPS1 | |
18556 | #undef OPS2 | |
18557 | #undef OPS3 | |
18558 | #undef OPS4 | |
18559 | #undef OPS5 | |
18560 | #undef OPS6 | |
18561 | #undef do_0 | |
18562 | \f | |
18563 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 18564 | |
c19d1205 ZW |
18565 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
18566 | for use in the a.out file, and stores them in the array pointed to by buf. | |
18567 | This knows about the endian-ness of the target machine and does | |
18568 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
18569 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
18570 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 18571 | |
c19d1205 ZW |
18572 | void |
18573 | md_number_to_chars (char * buf, valueT val, int n) | |
18574 | { | |
18575 | if (target_big_endian) | |
18576 | number_to_chars_bigendian (buf, val, n); | |
18577 | else | |
18578 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
18579 | } |
18580 | ||
c19d1205 ZW |
18581 | static valueT |
18582 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 18583 | { |
c19d1205 ZW |
18584 | valueT result = 0; |
18585 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 18586 | |
c19d1205 | 18587 | if (target_big_endian) |
b99bd4ef | 18588 | { |
c19d1205 ZW |
18589 | while (n--) |
18590 | { | |
18591 | result <<= 8; | |
18592 | result |= (*where++ & 255); | |
18593 | } | |
b99bd4ef | 18594 | } |
c19d1205 | 18595 | else |
b99bd4ef | 18596 | { |
c19d1205 ZW |
18597 | while (n--) |
18598 | { | |
18599 | result <<= 8; | |
18600 | result |= (where[n] & 255); | |
18601 | } | |
bfae80f2 | 18602 | } |
b99bd4ef | 18603 | |
c19d1205 | 18604 | return result; |
bfae80f2 | 18605 | } |
b99bd4ef | 18606 | |
c19d1205 | 18607 | /* MD interface: Sections. */ |
b99bd4ef | 18608 | |
0110f2b8 PB |
18609 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
18610 | 2 bytes. */ | |
18611 | ||
c19d1205 | 18612 | int |
0110f2b8 | 18613 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
18614 | segT segtype ATTRIBUTE_UNUSED) |
18615 | { | |
0110f2b8 PB |
18616 | fragp->fr_var = 2; |
18617 | return 2; | |
18618 | } | |
18619 | ||
18620 | /* Convert a machine dependent frag. */ | |
18621 | ||
18622 | void | |
18623 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
18624 | { | |
18625 | unsigned long insn; | |
18626 | unsigned long old_op; | |
18627 | char *buf; | |
18628 | expressionS exp; | |
18629 | fixS *fixp; | |
18630 | int reloc_type; | |
18631 | int pc_rel; | |
18632 | int opcode; | |
18633 | ||
18634 | buf = fragp->fr_literal + fragp->fr_fix; | |
18635 | ||
18636 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
18637 | if (fragp->fr_symbol) |
18638 | { | |
0110f2b8 PB |
18639 | exp.X_op = O_symbol; |
18640 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
18641 | } |
18642 | else | |
18643 | { | |
0110f2b8 | 18644 | exp.X_op = O_constant; |
5f4273c7 | 18645 | } |
0110f2b8 PB |
18646 | exp.X_add_number = fragp->fr_offset; |
18647 | opcode = fragp->fr_subtype; | |
18648 | switch (opcode) | |
18649 | { | |
18650 | case T_MNEM_ldr_pc: | |
18651 | case T_MNEM_ldr_pc2: | |
18652 | case T_MNEM_ldr_sp: | |
18653 | case T_MNEM_str_sp: | |
18654 | case T_MNEM_ldr: | |
18655 | case T_MNEM_ldrb: | |
18656 | case T_MNEM_ldrh: | |
18657 | case T_MNEM_str: | |
18658 | case T_MNEM_strb: | |
18659 | case T_MNEM_strh: | |
18660 | if (fragp->fr_var == 4) | |
18661 | { | |
5f4273c7 | 18662 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
18663 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
18664 | { | |
18665 | insn |= (old_op & 0x700) << 4; | |
18666 | } | |
18667 | else | |
18668 | { | |
18669 | insn |= (old_op & 7) << 12; | |
18670 | insn |= (old_op & 0x38) << 13; | |
18671 | } | |
18672 | insn |= 0x00000c00; | |
18673 | put_thumb32_insn (buf, insn); | |
18674 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
18675 | } | |
18676 | else | |
18677 | { | |
18678 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
18679 | } | |
18680 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
18681 | break; | |
18682 | case T_MNEM_adr: | |
18683 | if (fragp->fr_var == 4) | |
18684 | { | |
18685 | insn = THUMB_OP32 (opcode); | |
18686 | insn |= (old_op & 0xf0) << 4; | |
18687 | put_thumb32_insn (buf, insn); | |
18688 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
18689 | } | |
18690 | else | |
18691 | { | |
18692 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18693 | exp.X_add_number -= 4; | |
18694 | } | |
18695 | pc_rel = 1; | |
18696 | break; | |
18697 | case T_MNEM_mov: | |
18698 | case T_MNEM_movs: | |
18699 | case T_MNEM_cmp: | |
18700 | case T_MNEM_cmn: | |
18701 | if (fragp->fr_var == 4) | |
18702 | { | |
18703 | int r0off = (opcode == T_MNEM_mov | |
18704 | || opcode == T_MNEM_movs) ? 0 : 8; | |
18705 | insn = THUMB_OP32 (opcode); | |
18706 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
18707 | insn |= (old_op & 0x700) << r0off; | |
18708 | put_thumb32_insn (buf, insn); | |
18709 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
18710 | } | |
18711 | else | |
18712 | { | |
18713 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
18714 | } | |
18715 | pc_rel = 0; | |
18716 | break; | |
18717 | case T_MNEM_b: | |
18718 | if (fragp->fr_var == 4) | |
18719 | { | |
18720 | insn = THUMB_OP32(opcode); | |
18721 | put_thumb32_insn (buf, insn); | |
18722 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
18723 | } | |
18724 | else | |
18725 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
18726 | pc_rel = 1; | |
18727 | break; | |
18728 | case T_MNEM_bcond: | |
18729 | if (fragp->fr_var == 4) | |
18730 | { | |
18731 | insn = THUMB_OP32(opcode); | |
18732 | insn |= (old_op & 0xf00) << 14; | |
18733 | put_thumb32_insn (buf, insn); | |
18734 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
18735 | } | |
18736 | else | |
18737 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
18738 | pc_rel = 1; | |
18739 | break; | |
18740 | case T_MNEM_add_sp: | |
18741 | case T_MNEM_add_pc: | |
18742 | case T_MNEM_inc_sp: | |
18743 | case T_MNEM_dec_sp: | |
18744 | if (fragp->fr_var == 4) | |
18745 | { | |
18746 | /* ??? Choose between add and addw. */ | |
18747 | insn = THUMB_OP32 (opcode); | |
18748 | insn |= (old_op & 0xf0) << 4; | |
18749 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18750 | if (opcode == T_MNEM_add_pc) |
18751 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
18752 | else | |
18753 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
18754 | } |
18755 | else | |
18756 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18757 | pc_rel = 0; | |
18758 | break; | |
18759 | ||
18760 | case T_MNEM_addi: | |
18761 | case T_MNEM_addis: | |
18762 | case T_MNEM_subi: | |
18763 | case T_MNEM_subis: | |
18764 | if (fragp->fr_var == 4) | |
18765 | { | |
18766 | insn = THUMB_OP32 (opcode); | |
18767 | insn |= (old_op & 0xf0) << 4; | |
18768 | insn |= (old_op & 0xf) << 16; | |
18769 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18770 | if (insn & (1 << 20)) |
18771 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
18772 | else | |
18773 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
18774 | } |
18775 | else | |
18776 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18777 | pc_rel = 0; | |
18778 | break; | |
18779 | default: | |
5f4273c7 | 18780 | abort (); |
0110f2b8 PB |
18781 | } |
18782 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 18783 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
18784 | fixp->fx_file = fragp->fr_file; |
18785 | fixp->fx_line = fragp->fr_line; | |
18786 | fragp->fr_fix += fragp->fr_var; | |
18787 | } | |
18788 | ||
18789 | /* Return the size of a relaxable immediate operand instruction. | |
18790 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
18791 | static int | |
18792 | relax_immediate (fragS *fragp, int size, int shift) | |
18793 | { | |
18794 | offsetT offset; | |
18795 | offsetT mask; | |
18796 | offsetT low; | |
18797 | ||
18798 | /* ??? Should be able to do better than this. */ | |
18799 | if (fragp->fr_symbol) | |
18800 | return 4; | |
18801 | ||
18802 | low = (1 << shift) - 1; | |
18803 | mask = (1 << (shift + size)) - (1 << shift); | |
18804 | offset = fragp->fr_offset; | |
18805 | /* Force misaligned offsets to 32-bit variant. */ | |
18806 | if (offset & low) | |
5e77afaa | 18807 | return 4; |
0110f2b8 PB |
18808 | if (offset & ~mask) |
18809 | return 4; | |
18810 | return 2; | |
18811 | } | |
18812 | ||
5e77afaa PB |
18813 | /* Get the address of a symbol during relaxation. */ |
18814 | static addressT | |
5f4273c7 | 18815 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
18816 | { |
18817 | fragS *sym_frag; | |
18818 | addressT addr; | |
18819 | symbolS *sym; | |
18820 | ||
18821 | sym = fragp->fr_symbol; | |
18822 | sym_frag = symbol_get_frag (sym); | |
18823 | know (S_GET_SEGMENT (sym) != absolute_section | |
18824 | || sym_frag == &zero_address_frag); | |
18825 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
18826 | ||
18827 | /* If frag has yet to be reached on this pass, assume it will | |
18828 | move by STRETCH just as we did. If this is not so, it will | |
18829 | be because some frag between grows, and that will force | |
18830 | another pass. */ | |
18831 | ||
18832 | if (stretch != 0 | |
18833 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
18834 | { |
18835 | fragS *f; | |
18836 | ||
18837 | /* Adjust stretch for any alignment frag. Note that if have | |
18838 | been expanding the earlier code, the symbol may be | |
18839 | defined in what appears to be an earlier frag. FIXME: | |
18840 | This doesn't handle the fr_subtype field, which specifies | |
18841 | a maximum number of bytes to skip when doing an | |
18842 | alignment. */ | |
18843 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
18844 | { | |
18845 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
18846 | { | |
18847 | if (stretch < 0) | |
18848 | stretch = - ((- stretch) | |
18849 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
18850 | else | |
18851 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
18852 | if (stretch == 0) | |
18853 | break; | |
18854 | } | |
18855 | } | |
18856 | if (f != NULL) | |
18857 | addr += stretch; | |
18858 | } | |
5e77afaa PB |
18859 | |
18860 | return addr; | |
18861 | } | |
18862 | ||
0110f2b8 PB |
18863 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
18864 | load. */ | |
18865 | static int | |
5e77afaa | 18866 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
18867 | { |
18868 | addressT addr; | |
18869 | offsetT val; | |
18870 | ||
18871 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
18872 | if (fragp->fr_symbol == NULL |
18873 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
18874 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
18875 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
18876 | return 4; |
18877 | ||
5f4273c7 | 18878 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18879 | addr = fragp->fr_address + fragp->fr_fix; |
18880 | addr = (addr + 4) & ~3; | |
5e77afaa | 18881 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 18882 | if (val & 3) |
5e77afaa | 18883 | return 4; |
0110f2b8 PB |
18884 | val -= addr; |
18885 | if (val < 0 || val > 1020) | |
18886 | return 4; | |
18887 | return 2; | |
18888 | } | |
18889 | ||
18890 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
18891 | static int | |
18892 | relax_addsub (fragS *fragp, asection *sec) | |
18893 | { | |
18894 | char *buf; | |
18895 | int op; | |
18896 | ||
18897 | buf = fragp->fr_literal + fragp->fr_fix; | |
18898 | op = bfd_get_16(sec->owner, buf); | |
18899 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
18900 | return relax_immediate (fragp, 8, 0); | |
18901 | else | |
18902 | return relax_immediate (fragp, 3, 0); | |
18903 | } | |
18904 | ||
18905 | ||
18906 | /* Return the size of a relaxable branch instruction. BITS is the | |
18907 | size of the offset field in the narrow instruction. */ | |
18908 | ||
18909 | static int | |
5e77afaa | 18910 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
18911 | { |
18912 | addressT addr; | |
18913 | offsetT val; | |
18914 | offsetT limit; | |
18915 | ||
18916 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18917 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
18918 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
18919 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
18920 | return 4; |
18921 | ||
267bf995 RR |
18922 | #ifdef OBJ_ELF |
18923 | if (S_IS_DEFINED (fragp->fr_symbol) | |
18924 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
18925 | return 4; | |
18926 | #endif | |
18927 | ||
5f4273c7 | 18928 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18929 | addr = fragp->fr_address + fragp->fr_fix + 4; |
18930 | val -= addr; | |
18931 | ||
18932 | /* Offset is a signed value *2 */ | |
18933 | limit = 1 << bits; | |
18934 | if (val >= limit || val < -limit) | |
18935 | return 4; | |
18936 | return 2; | |
18937 | } | |
18938 | ||
18939 | ||
18940 | /* Relax a machine dependent frag. This returns the amount by which | |
18941 | the current size of the frag should change. */ | |
18942 | ||
18943 | int | |
5e77afaa | 18944 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
18945 | { |
18946 | int oldsize; | |
18947 | int newsize; | |
18948 | ||
18949 | oldsize = fragp->fr_var; | |
18950 | switch (fragp->fr_subtype) | |
18951 | { | |
18952 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 18953 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18954 | break; |
18955 | case T_MNEM_ldr_pc: | |
18956 | case T_MNEM_ldr_sp: | |
18957 | case T_MNEM_str_sp: | |
5f4273c7 | 18958 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
18959 | break; |
18960 | case T_MNEM_ldr: | |
18961 | case T_MNEM_str: | |
5f4273c7 | 18962 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
18963 | break; |
18964 | case T_MNEM_ldrh: | |
18965 | case T_MNEM_strh: | |
5f4273c7 | 18966 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
18967 | break; |
18968 | case T_MNEM_ldrb: | |
18969 | case T_MNEM_strb: | |
5f4273c7 | 18970 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
18971 | break; |
18972 | case T_MNEM_adr: | |
5f4273c7 | 18973 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18974 | break; |
18975 | case T_MNEM_mov: | |
18976 | case T_MNEM_movs: | |
18977 | case T_MNEM_cmp: | |
18978 | case T_MNEM_cmn: | |
5f4273c7 | 18979 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
18980 | break; |
18981 | case T_MNEM_b: | |
5f4273c7 | 18982 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
18983 | break; |
18984 | case T_MNEM_bcond: | |
5f4273c7 | 18985 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
18986 | break; |
18987 | case T_MNEM_add_sp: | |
18988 | case T_MNEM_add_pc: | |
18989 | newsize = relax_immediate (fragp, 8, 2); | |
18990 | break; | |
18991 | case T_MNEM_inc_sp: | |
18992 | case T_MNEM_dec_sp: | |
18993 | newsize = relax_immediate (fragp, 7, 2); | |
18994 | break; | |
18995 | case T_MNEM_addi: | |
18996 | case T_MNEM_addis: | |
18997 | case T_MNEM_subi: | |
18998 | case T_MNEM_subis: | |
18999 | newsize = relax_addsub (fragp, sec); | |
19000 | break; | |
19001 | default: | |
5f4273c7 | 19002 | abort (); |
0110f2b8 | 19003 | } |
5e77afaa PB |
19004 | |
19005 | fragp->fr_var = newsize; | |
19006 | /* Freeze wide instructions that are at or before the same location as | |
19007 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
19008 | Don't freeze them unconditionally because targets may be artificially |
19009 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 19010 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 19011 | { |
0110f2b8 | 19012 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 19013 | frag_wane (fragp); |
0110f2b8 | 19014 | } |
5e77afaa | 19015 | |
0110f2b8 | 19016 | return newsize - oldsize; |
c19d1205 | 19017 | } |
b99bd4ef | 19018 | |
c19d1205 | 19019 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 19020 | |
c19d1205 ZW |
19021 | valueT |
19022 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
19023 | valueT size) | |
19024 | { | |
f0927246 NC |
19025 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
19026 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
19027 | { | |
19028 | /* For a.out, force the section size to be aligned. If we don't do | |
19029 | this, BFD will align it for us, but it will not write out the | |
19030 | final bytes of the section. This may be a bug in BFD, but it is | |
19031 | easier to fix it here since that is how the other a.out targets | |
19032 | work. */ | |
19033 | int align; | |
19034 | ||
19035 | align = bfd_get_section_alignment (stdoutput, segment); | |
19036 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
19037 | } | |
c19d1205 | 19038 | #endif |
f0927246 NC |
19039 | |
19040 | return size; | |
bfae80f2 | 19041 | } |
b99bd4ef | 19042 | |
c19d1205 ZW |
19043 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
19044 | of an rs_align_code fragment. */ | |
19045 | ||
19046 | void | |
19047 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 19048 | { |
e7495e45 NS |
19049 | static char const arm_noop[2][2][4] = |
19050 | { | |
19051 | { /* ARMv1 */ | |
19052 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
19053 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
19054 | }, | |
19055 | { /* ARMv6k */ | |
19056 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
19057 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
19058 | }, | |
19059 | }; | |
19060 | static char const thumb_noop[2][2][2] = | |
19061 | { | |
19062 | { /* Thumb-1 */ | |
19063 | {0xc0, 0x46}, /* LE */ | |
19064 | {0x46, 0xc0}, /* BE */ | |
19065 | }, | |
19066 | { /* Thumb-2 */ | |
19067 | {0x00, 0xbf}, /* LE */ | |
19068 | {0xbf, 0x00} /* BE */ | |
19069 | } | |
19070 | }; | |
19071 | static char const wide_thumb_noop[2][4] = | |
19072 | { /* Wide Thumb-2 */ | |
19073 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
19074 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
19075 | }; | |
c921be7d | 19076 | |
e7495e45 | 19077 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
19078 | char * p; |
19079 | const char * noop; | |
e7495e45 | 19080 | const char *narrow_noop = NULL; |
cd000bff DJ |
19081 | #ifdef OBJ_ELF |
19082 | enum mstate state; | |
19083 | #endif | |
bfae80f2 | 19084 | |
c19d1205 | 19085 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
19086 | return; |
19087 | ||
c19d1205 ZW |
19088 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
19089 | p = fragP->fr_literal + fragP->fr_fix; | |
19090 | fix = 0; | |
bfae80f2 | 19091 | |
c19d1205 ZW |
19092 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
19093 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 19094 | |
cd000bff | 19095 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 19096 | |
cd000bff | 19097 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 19098 | { |
e7495e45 NS |
19099 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
19100 | { | |
19101 | narrow_noop = thumb_noop[1][target_big_endian]; | |
19102 | noop = wide_thumb_noop[target_big_endian]; | |
19103 | } | |
c19d1205 | 19104 | else |
e7495e45 NS |
19105 | noop = thumb_noop[0][target_big_endian]; |
19106 | noop_size = 2; | |
cd000bff DJ |
19107 | #ifdef OBJ_ELF |
19108 | state = MAP_THUMB; | |
19109 | #endif | |
7ed4c4c5 NC |
19110 | } |
19111 | else | |
19112 | { | |
e7495e45 NS |
19113 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0] |
19114 | [target_big_endian]; | |
19115 | noop_size = 4; | |
cd000bff DJ |
19116 | #ifdef OBJ_ELF |
19117 | state = MAP_ARM; | |
19118 | #endif | |
7ed4c4c5 | 19119 | } |
c921be7d | 19120 | |
e7495e45 | 19121 | fragP->fr_var = noop_size; |
c921be7d | 19122 | |
c19d1205 | 19123 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 19124 | { |
c19d1205 | 19125 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
19126 | #ifdef OBJ_ELF |
19127 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
19128 | #endif | |
c19d1205 ZW |
19129 | memset (p, 0, fix); |
19130 | p += fix; | |
19131 | bytes -= fix; | |
a737bd4d | 19132 | } |
a737bd4d | 19133 | |
e7495e45 NS |
19134 | if (narrow_noop) |
19135 | { | |
19136 | if (bytes & noop_size) | |
19137 | { | |
19138 | /* Insert a narrow noop. */ | |
19139 | memcpy (p, narrow_noop, noop_size); | |
19140 | p += noop_size; | |
19141 | bytes -= noop_size; | |
19142 | fix += noop_size; | |
19143 | } | |
19144 | ||
19145 | /* Use wide noops for the remainder */ | |
19146 | noop_size = 4; | |
19147 | } | |
19148 | ||
c19d1205 | 19149 | while (bytes >= noop_size) |
a737bd4d | 19150 | { |
c19d1205 ZW |
19151 | memcpy (p, noop, noop_size); |
19152 | p += noop_size; | |
19153 | bytes -= noop_size; | |
19154 | fix += noop_size; | |
a737bd4d NC |
19155 | } |
19156 | ||
c19d1205 | 19157 | fragP->fr_fix += fix; |
a737bd4d NC |
19158 | } |
19159 | ||
c19d1205 ZW |
19160 | /* Called from md_do_align. Used to create an alignment |
19161 | frag in a code section. */ | |
19162 | ||
19163 | void | |
19164 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 19165 | { |
c19d1205 | 19166 | char * p; |
7ed4c4c5 | 19167 | |
c19d1205 | 19168 | /* We assume that there will never be a requirement |
6ec8e702 | 19169 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 19170 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
19171 | { |
19172 | char err_msg[128]; | |
19173 | ||
19174 | sprintf (err_msg, | |
19175 | _("alignments greater than %d bytes not supported in .text sections."), | |
19176 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 19177 | as_fatal ("%s", err_msg); |
6ec8e702 | 19178 | } |
bfae80f2 | 19179 | |
c19d1205 ZW |
19180 | p = frag_var (rs_align_code, |
19181 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
19182 | 1, | |
19183 | (relax_substateT) max, | |
19184 | (symbolS *) NULL, | |
19185 | (offsetT) n, | |
19186 | (char *) NULL); | |
19187 | *p = 0; | |
19188 | } | |
bfae80f2 | 19189 | |
8dc2430f NC |
19190 | /* Perform target specific initialisation of a frag. |
19191 | Note - despite the name this initialisation is not done when the frag | |
19192 | is created, but only when its type is assigned. A frag can be created | |
19193 | and used a long time before its type is set, so beware of assuming that | |
19194 | this initialisationis performed first. */ | |
bfae80f2 | 19195 | |
cd000bff DJ |
19196 | #ifndef OBJ_ELF |
19197 | void | |
19198 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
19199 | { | |
19200 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 19201 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
19202 | } |
19203 | ||
19204 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 19205 | void |
cd000bff | 19206 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 19207 | { |
8dc2430f NC |
19208 | /* If the current ARM vs THUMB mode has not already |
19209 | been recorded into this frag then do so now. */ | |
cd000bff DJ |
19210 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
19211 | { | |
19212 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; | |
19213 | ||
19214 | /* Record a mapping symbol for alignment frags. We will delete this | |
19215 | later if the alignment ends up empty. */ | |
19216 | switch (fragP->fr_type) | |
19217 | { | |
19218 | case rs_align: | |
19219 | case rs_align_test: | |
19220 | case rs_fill: | |
19221 | mapping_state_2 (MAP_DATA, max_chars); | |
19222 | break; | |
19223 | case rs_align_code: | |
19224 | mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); | |
19225 | break; | |
19226 | default: | |
19227 | break; | |
19228 | } | |
19229 | } | |
bfae80f2 RE |
19230 | } |
19231 | ||
c19d1205 ZW |
19232 | /* When we change sections we need to issue a new mapping symbol. */ |
19233 | ||
19234 | void | |
19235 | arm_elf_change_section (void) | |
bfae80f2 | 19236 | { |
c19d1205 ZW |
19237 | /* Link an unlinked unwind index table section to the .text section. */ |
19238 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
19239 | && elf_linked_to_section (now_seg) == NULL) | |
19240 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
19241 | } |
19242 | ||
c19d1205 ZW |
19243 | int |
19244 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 19245 | { |
c19d1205 ZW |
19246 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
19247 | return SHT_ARM_EXIDX; | |
e45d0630 | 19248 | |
c19d1205 ZW |
19249 | return -1; |
19250 | } | |
19251 | \f | |
19252 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 19253 | |
c19d1205 | 19254 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 19255 | |
5f4273c7 | 19256 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 19257 | |
bfae80f2 | 19258 | static void |
c19d1205 | 19259 | flush_pending_unwind (void) |
bfae80f2 | 19260 | { |
c19d1205 | 19261 | offsetT offset; |
bfae80f2 | 19262 | |
c19d1205 ZW |
19263 | offset = unwind.pending_offset; |
19264 | unwind.pending_offset = 0; | |
19265 | if (offset != 0) | |
19266 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
19267 | } |
19268 | ||
c19d1205 ZW |
19269 | /* Add an opcode to this list for this function. Two-byte opcodes should |
19270 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
19271 | order. */ | |
19272 | ||
bfae80f2 | 19273 | static void |
c19d1205 | 19274 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 19275 | { |
c19d1205 ZW |
19276 | /* Add any deferred stack adjustment. */ |
19277 | if (unwind.pending_offset) | |
19278 | flush_pending_unwind (); | |
bfae80f2 | 19279 | |
c19d1205 | 19280 | unwind.sp_restored = 0; |
bfae80f2 | 19281 | |
c19d1205 | 19282 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 19283 | { |
c19d1205 ZW |
19284 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
19285 | if (unwind.opcodes) | |
21d799b5 NC |
19286 | unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes, |
19287 | unwind.opcode_alloc); | |
c19d1205 | 19288 | else |
21d799b5 | 19289 | unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc); |
bfae80f2 | 19290 | } |
c19d1205 | 19291 | while (length > 0) |
bfae80f2 | 19292 | { |
c19d1205 ZW |
19293 | length--; |
19294 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
19295 | op >>= 8; | |
19296 | unwind.opcode_count++; | |
bfae80f2 | 19297 | } |
bfae80f2 RE |
19298 | } |
19299 | ||
c19d1205 ZW |
19300 | /* Add unwind opcodes to adjust the stack pointer. */ |
19301 | ||
bfae80f2 | 19302 | static void |
c19d1205 | 19303 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 19304 | { |
c19d1205 | 19305 | valueT op; |
bfae80f2 | 19306 | |
c19d1205 | 19307 | if (offset > 0x200) |
bfae80f2 | 19308 | { |
c19d1205 ZW |
19309 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
19310 | char bytes[5]; | |
19311 | int n; | |
19312 | valueT o; | |
bfae80f2 | 19313 | |
c19d1205 ZW |
19314 | /* Long form: 0xb2, uleb128. */ |
19315 | /* This might not fit in a word so add the individual bytes, | |
19316 | remembering the list is built in reverse order. */ | |
19317 | o = (valueT) ((offset - 0x204) >> 2); | |
19318 | if (o == 0) | |
19319 | add_unwind_opcode (0, 1); | |
bfae80f2 | 19320 | |
c19d1205 ZW |
19321 | /* Calculate the uleb128 encoding of the offset. */ |
19322 | n = 0; | |
19323 | while (o) | |
19324 | { | |
19325 | bytes[n] = o & 0x7f; | |
19326 | o >>= 7; | |
19327 | if (o) | |
19328 | bytes[n] |= 0x80; | |
19329 | n++; | |
19330 | } | |
19331 | /* Add the insn. */ | |
19332 | for (; n; n--) | |
19333 | add_unwind_opcode (bytes[n - 1], 1); | |
19334 | add_unwind_opcode (0xb2, 1); | |
19335 | } | |
19336 | else if (offset > 0x100) | |
bfae80f2 | 19337 | { |
c19d1205 ZW |
19338 | /* Two short opcodes. */ |
19339 | add_unwind_opcode (0x3f, 1); | |
19340 | op = (offset - 0x104) >> 2; | |
19341 | add_unwind_opcode (op, 1); | |
bfae80f2 | 19342 | } |
c19d1205 ZW |
19343 | else if (offset > 0) |
19344 | { | |
19345 | /* Short opcode. */ | |
19346 | op = (offset - 4) >> 2; | |
19347 | add_unwind_opcode (op, 1); | |
19348 | } | |
19349 | else if (offset < 0) | |
bfae80f2 | 19350 | { |
c19d1205 ZW |
19351 | offset = -offset; |
19352 | while (offset > 0x100) | |
bfae80f2 | 19353 | { |
c19d1205 ZW |
19354 | add_unwind_opcode (0x7f, 1); |
19355 | offset -= 0x100; | |
bfae80f2 | 19356 | } |
c19d1205 ZW |
19357 | op = ((offset - 4) >> 2) | 0x40; |
19358 | add_unwind_opcode (op, 1); | |
bfae80f2 | 19359 | } |
bfae80f2 RE |
19360 | } |
19361 | ||
c19d1205 ZW |
19362 | /* Finish the list of unwind opcodes for this function. */ |
19363 | static void | |
19364 | finish_unwind_opcodes (void) | |
bfae80f2 | 19365 | { |
c19d1205 | 19366 | valueT op; |
bfae80f2 | 19367 | |
c19d1205 | 19368 | if (unwind.fp_used) |
bfae80f2 | 19369 | { |
708587a4 | 19370 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
19371 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
19372 | flush_pending_unwind (); | |
bfae80f2 | 19373 | |
c19d1205 ZW |
19374 | /* After restoring sp from the frame pointer. */ |
19375 | op = 0x90 | unwind.fp_reg; | |
19376 | add_unwind_opcode (op, 1); | |
19377 | } | |
19378 | else | |
19379 | flush_pending_unwind (); | |
bfae80f2 RE |
19380 | } |
19381 | ||
bfae80f2 | 19382 | |
c19d1205 ZW |
19383 | /* Start an exception table entry. If idx is nonzero this is an index table |
19384 | entry. */ | |
bfae80f2 RE |
19385 | |
19386 | static void | |
c19d1205 | 19387 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 19388 | { |
c19d1205 ZW |
19389 | const char * text_name; |
19390 | const char * prefix; | |
19391 | const char * prefix_once; | |
19392 | const char * group_name; | |
19393 | size_t prefix_len; | |
19394 | size_t text_len; | |
19395 | char * sec_name; | |
19396 | size_t sec_name_len; | |
19397 | int type; | |
19398 | int flags; | |
19399 | int linkonce; | |
bfae80f2 | 19400 | |
c19d1205 | 19401 | if (idx) |
bfae80f2 | 19402 | { |
c19d1205 ZW |
19403 | prefix = ELF_STRING_ARM_unwind; |
19404 | prefix_once = ELF_STRING_ARM_unwind_once; | |
19405 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 19406 | } |
c19d1205 | 19407 | else |
bfae80f2 | 19408 | { |
c19d1205 ZW |
19409 | prefix = ELF_STRING_ARM_unwind_info; |
19410 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
19411 | type = SHT_PROGBITS; | |
bfae80f2 RE |
19412 | } |
19413 | ||
c19d1205 ZW |
19414 | text_name = segment_name (text_seg); |
19415 | if (streq (text_name, ".text")) | |
19416 | text_name = ""; | |
19417 | ||
19418 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
19419 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 19420 | { |
c19d1205 ZW |
19421 | prefix = prefix_once; |
19422 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
19423 | } |
19424 | ||
c19d1205 ZW |
19425 | prefix_len = strlen (prefix); |
19426 | text_len = strlen (text_name); | |
19427 | sec_name_len = prefix_len + text_len; | |
21d799b5 | 19428 | sec_name = (char *) xmalloc (sec_name_len + 1); |
c19d1205 ZW |
19429 | memcpy (sec_name, prefix, prefix_len); |
19430 | memcpy (sec_name + prefix_len, text_name, text_len); | |
19431 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 19432 | |
c19d1205 ZW |
19433 | flags = SHF_ALLOC; |
19434 | linkonce = 0; | |
19435 | group_name = 0; | |
bfae80f2 | 19436 | |
c19d1205 ZW |
19437 | /* Handle COMDAT group. */ |
19438 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 19439 | { |
c19d1205 ZW |
19440 | group_name = elf_group_name (text_seg); |
19441 | if (group_name == NULL) | |
19442 | { | |
bd3ba5d1 | 19443 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
19444 | segment_name (text_seg)); |
19445 | ignore_rest_of_line (); | |
19446 | return; | |
19447 | } | |
19448 | flags |= SHF_GROUP; | |
19449 | linkonce = 1; | |
bfae80f2 RE |
19450 | } |
19451 | ||
c19d1205 | 19452 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 19453 | |
5f4273c7 | 19454 | /* Set the section link for index tables. */ |
c19d1205 ZW |
19455 | if (idx) |
19456 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
19457 | } |
19458 | ||
bfae80f2 | 19459 | |
c19d1205 ZW |
19460 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
19461 | personality routine data. Returns zero, or the index table value for | |
19462 | and inline entry. */ | |
19463 | ||
19464 | static valueT | |
19465 | create_unwind_entry (int have_data) | |
bfae80f2 | 19466 | { |
c19d1205 ZW |
19467 | int size; |
19468 | addressT where; | |
19469 | char *ptr; | |
19470 | /* The current word of data. */ | |
19471 | valueT data; | |
19472 | /* The number of bytes left in this word. */ | |
19473 | int n; | |
bfae80f2 | 19474 | |
c19d1205 | 19475 | finish_unwind_opcodes (); |
bfae80f2 | 19476 | |
c19d1205 ZW |
19477 | /* Remember the current text section. */ |
19478 | unwind.saved_seg = now_seg; | |
19479 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 19480 | |
c19d1205 | 19481 | start_unwind_section (now_seg, 0); |
bfae80f2 | 19482 | |
c19d1205 | 19483 | if (unwind.personality_routine == NULL) |
bfae80f2 | 19484 | { |
c19d1205 ZW |
19485 | if (unwind.personality_index == -2) |
19486 | { | |
19487 | if (have_data) | |
5f4273c7 | 19488 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
19489 | return 1; /* EXIDX_CANTUNWIND. */ |
19490 | } | |
bfae80f2 | 19491 | |
c19d1205 ZW |
19492 | /* Use a default personality routine if none is specified. */ |
19493 | if (unwind.personality_index == -1) | |
19494 | { | |
19495 | if (unwind.opcode_count > 3) | |
19496 | unwind.personality_index = 1; | |
19497 | else | |
19498 | unwind.personality_index = 0; | |
19499 | } | |
bfae80f2 | 19500 | |
c19d1205 ZW |
19501 | /* Space for the personality routine entry. */ |
19502 | if (unwind.personality_index == 0) | |
19503 | { | |
19504 | if (unwind.opcode_count > 3) | |
19505 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 19506 | |
c19d1205 ZW |
19507 | if (!have_data) |
19508 | { | |
19509 | /* All the data is inline in the index table. */ | |
19510 | data = 0x80; | |
19511 | n = 3; | |
19512 | while (unwind.opcode_count > 0) | |
19513 | { | |
19514 | unwind.opcode_count--; | |
19515 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
19516 | n--; | |
19517 | } | |
bfae80f2 | 19518 | |
c19d1205 ZW |
19519 | /* Pad with "finish" opcodes. */ |
19520 | while (n--) | |
19521 | data = (data << 8) | 0xb0; | |
bfae80f2 | 19522 | |
c19d1205 ZW |
19523 | return data; |
19524 | } | |
19525 | size = 0; | |
19526 | } | |
19527 | else | |
19528 | /* We get two opcodes "free" in the first word. */ | |
19529 | size = unwind.opcode_count - 2; | |
19530 | } | |
19531 | else | |
19532 | /* An extra byte is required for the opcode count. */ | |
19533 | size = unwind.opcode_count + 1; | |
bfae80f2 | 19534 | |
c19d1205 ZW |
19535 | size = (size + 3) >> 2; |
19536 | if (size > 0xff) | |
19537 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 19538 | |
c19d1205 ZW |
19539 | frag_align (2, 0, 0); |
19540 | record_alignment (now_seg, 2); | |
19541 | unwind.table_entry = expr_build_dot (); | |
19542 | ||
19543 | /* Allocate the table entry. */ | |
19544 | ptr = frag_more ((size << 2) + 4); | |
19545 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 19546 | |
c19d1205 | 19547 | switch (unwind.personality_index) |
bfae80f2 | 19548 | { |
c19d1205 ZW |
19549 | case -1: |
19550 | /* ??? Should this be a PLT generating relocation? */ | |
19551 | /* Custom personality routine. */ | |
19552 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
19553 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 19554 | |
c19d1205 ZW |
19555 | where += 4; |
19556 | ptr += 4; | |
bfae80f2 | 19557 | |
c19d1205 ZW |
19558 | /* Set the first byte to the number of additional words. */ |
19559 | data = size - 1; | |
19560 | n = 3; | |
19561 | break; | |
bfae80f2 | 19562 | |
c19d1205 ZW |
19563 | /* ABI defined personality routines. */ |
19564 | case 0: | |
19565 | /* Three opcodes bytes are packed into the first word. */ | |
19566 | data = 0x80; | |
19567 | n = 3; | |
19568 | break; | |
bfae80f2 | 19569 | |
c19d1205 ZW |
19570 | case 1: |
19571 | case 2: | |
19572 | /* The size and first two opcode bytes go in the first word. */ | |
19573 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
19574 | n = 2; | |
19575 | break; | |
bfae80f2 | 19576 | |
c19d1205 ZW |
19577 | default: |
19578 | /* Should never happen. */ | |
19579 | abort (); | |
19580 | } | |
bfae80f2 | 19581 | |
c19d1205 ZW |
19582 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
19583 | time. */ | |
19584 | while (unwind.opcode_count > 0) | |
19585 | { | |
19586 | if (n == 0) | |
19587 | { | |
19588 | md_number_to_chars (ptr, data, 4); | |
19589 | ptr += 4; | |
19590 | n = 4; | |
19591 | data = 0; | |
19592 | } | |
19593 | unwind.opcode_count--; | |
19594 | n--; | |
19595 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
19596 | } | |
19597 | ||
19598 | /* Finish off the last word. */ | |
19599 | if (n < 4) | |
19600 | { | |
19601 | /* Pad with "finish" opcodes. */ | |
19602 | while (n--) | |
19603 | data = (data << 8) | 0xb0; | |
19604 | ||
19605 | md_number_to_chars (ptr, data, 4); | |
19606 | } | |
19607 | ||
19608 | if (!have_data) | |
19609 | { | |
19610 | /* Add an empty descriptor if there is no user-specified data. */ | |
19611 | ptr = frag_more (4); | |
19612 | md_number_to_chars (ptr, 0, 4); | |
19613 | } | |
19614 | ||
19615 | return 0; | |
bfae80f2 RE |
19616 | } |
19617 | ||
f0927246 NC |
19618 | |
19619 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
19620 | ||
19621 | void | |
19622 | tc_arm_frame_initial_instructions (void) | |
19623 | { | |
19624 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
19625 | } | |
19626 | #endif /* OBJ_ELF */ | |
19627 | ||
c19d1205 ZW |
19628 | /* Convert REGNAME to a DWARF-2 register number. */ |
19629 | ||
19630 | int | |
1df69f4f | 19631 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 19632 | { |
1df69f4f | 19633 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
19634 | |
19635 | if (reg == FAIL) | |
19636 | return -1; | |
19637 | ||
19638 | return reg; | |
bfae80f2 RE |
19639 | } |
19640 | ||
f0927246 | 19641 | #ifdef TE_PE |
c19d1205 | 19642 | void |
f0927246 | 19643 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 19644 | { |
91d6fa6a | 19645 | expressionS exp; |
bfae80f2 | 19646 | |
91d6fa6a NC |
19647 | exp.X_op = O_secrel; |
19648 | exp.X_add_symbol = symbol; | |
19649 | exp.X_add_number = 0; | |
19650 | emit_expr (&exp, size); | |
f0927246 NC |
19651 | } |
19652 | #endif | |
bfae80f2 | 19653 | |
c19d1205 | 19654 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 19655 | |
2fc8bdac ZW |
19656 | /* Return the address within the segment that a PC-relative fixup is |
19657 | relative to. For ARM, PC-relative fixups applied to instructions | |
19658 | are generally relative to the location of the fixup plus 8 bytes. | |
19659 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
19660 | require special handling. */ | |
bfae80f2 | 19661 | |
c19d1205 | 19662 | long |
2fc8bdac | 19663 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 19664 | { |
2fc8bdac ZW |
19665 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
19666 | ||
19667 | /* If this is pc-relative and we are going to emit a relocation | |
19668 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
19669 | will need. Otherwise we want to use the calculated base. |
19670 | For WinCE we skip the bias for externals as well, since this | |
19671 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 19672 | if (fixP->fx_pcrel |
2fc8bdac | 19673 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
19674 | || (arm_force_relocation (fixP) |
19675 | #ifdef TE_WINCE | |
19676 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19677 | #endif | |
19678 | ))) | |
2fc8bdac | 19679 | base = 0; |
bfae80f2 | 19680 | |
267bf995 | 19681 | |
c19d1205 | 19682 | switch (fixP->fx_r_type) |
bfae80f2 | 19683 | { |
2fc8bdac ZW |
19684 | /* PC relative addressing on the Thumb is slightly odd as the |
19685 | bottom two bits of the PC are forced to zero for the | |
19686 | calculation. This happens *after* application of the | |
19687 | pipeline offset. However, Thumb adrl already adjusts for | |
19688 | this, so we need not do it again. */ | |
c19d1205 | 19689 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 19690 | return base & ~3; |
c19d1205 ZW |
19691 | |
19692 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
19693 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 19694 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 19695 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 19696 | return (base + 4) & ~3; |
c19d1205 | 19697 | |
2fc8bdac ZW |
19698 | /* Thumb branches are simply offset by +4. */ |
19699 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
19700 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
19701 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
19702 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 19703 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 19704 | return base + 4; |
bfae80f2 | 19705 | |
267bf995 | 19706 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
19707 | if (fixP->fx_addsy |
19708 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19709 | && (!S_IS_EXTERNAL (fixP->fx_addsy)) | |
267bf995 RR |
19710 | && ARM_IS_FUNC (fixP->fx_addsy) |
19711 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19712 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19713 | return base + 4; | |
19714 | ||
00adf2d4 JB |
19715 | /* BLX is like branches above, but forces the low two bits of PC to |
19716 | zero. */ | |
486499d0 CL |
19717 | case BFD_RELOC_THUMB_PCREL_BLX: |
19718 | if (fixP->fx_addsy | |
19719 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19720 | && (!S_IS_EXTERNAL (fixP->fx_addsy)) | |
267bf995 RR |
19721 | && THUMB_IS_FUNC (fixP->fx_addsy) |
19722 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19723 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
19724 | return (base + 4) & ~3; |
19725 | ||
2fc8bdac ZW |
19726 | /* ARM mode branches are offset by +8. However, the Windows CE |
19727 | loader expects the relocation not to take this into account. */ | |
267bf995 | 19728 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
19729 | if (fixP->fx_addsy |
19730 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19731 | && (!S_IS_EXTERNAL (fixP->fx_addsy)) | |
267bf995 RR |
19732 | && ARM_IS_FUNC (fixP->fx_addsy) |
19733 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19734 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 19735 | return base + 8; |
267bf995 | 19736 | |
486499d0 CL |
19737 | case BFD_RELOC_ARM_PCREL_CALL: |
19738 | if (fixP->fx_addsy | |
19739 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19740 | && (!S_IS_EXTERNAL (fixP->fx_addsy)) | |
267bf995 RR |
19741 | && THUMB_IS_FUNC (fixP->fx_addsy) |
19742 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19743 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 19744 | return base + 8; |
267bf995 | 19745 | |
2fc8bdac | 19746 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 19747 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 19748 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19749 | #ifdef TE_WINCE |
5f4273c7 | 19750 | /* When handling fixups immediately, because we have already |
53baae48 NC |
19751 | discovered the value of a symbol, or the address of the frag involved |
19752 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
19753 | see fixup_segment() in write.c | |
19754 | The S_IS_EXTERNAL test handles the case of global symbols. | |
19755 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
19756 | if (fixP->fx_pcrel | |
19757 | && fixP->fx_addsy != NULL | |
19758 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19759 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
19760 | return base + 8; | |
2fc8bdac | 19761 | return base; |
c19d1205 | 19762 | #else |
2fc8bdac | 19763 | return base + 8; |
c19d1205 | 19764 | #endif |
2fc8bdac | 19765 | |
267bf995 | 19766 | |
2fc8bdac ZW |
19767 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
19768 | branches, the Windows CE loader *does* expect the relocation | |
19769 | to take this into account. */ | |
19770 | case BFD_RELOC_ARM_OFFSET_IMM: | |
19771 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
19772 | case BFD_RELOC_ARM_HWLITERAL: | |
19773 | case BFD_RELOC_ARM_LITERAL: | |
19774 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
19775 | return base + 8; | |
19776 | ||
19777 | ||
19778 | /* Other PC-relative relocations are un-offset. */ | |
19779 | default: | |
19780 | return base; | |
19781 | } | |
bfae80f2 RE |
19782 | } |
19783 | ||
c19d1205 ZW |
19784 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
19785 | Otherwise we have no need to default values of symbols. */ | |
19786 | ||
19787 | symbolS * | |
19788 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 19789 | { |
c19d1205 ZW |
19790 | #ifdef OBJ_ELF |
19791 | if (name[0] == '_' && name[1] == 'G' | |
19792 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
19793 | { | |
19794 | if (!GOT_symbol) | |
19795 | { | |
19796 | if (symbol_find (name)) | |
bd3ba5d1 | 19797 | as_bad (_("GOT already in the symbol table")); |
bfae80f2 | 19798 | |
c19d1205 ZW |
19799 | GOT_symbol = symbol_new (name, undefined_section, |
19800 | (valueT) 0, & zero_address_frag); | |
19801 | } | |
bfae80f2 | 19802 | |
c19d1205 | 19803 | return GOT_symbol; |
bfae80f2 | 19804 | } |
c19d1205 | 19805 | #endif |
bfae80f2 | 19806 | |
c921be7d | 19807 | return NULL; |
bfae80f2 RE |
19808 | } |
19809 | ||
55cf6793 | 19810 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
19811 | computed as two separate immediate values, added together. We |
19812 | already know that this value cannot be computed by just one ARM | |
19813 | instruction. */ | |
19814 | ||
19815 | static unsigned int | |
19816 | validate_immediate_twopart (unsigned int val, | |
19817 | unsigned int * highpart) | |
bfae80f2 | 19818 | { |
c19d1205 ZW |
19819 | unsigned int a; |
19820 | unsigned int i; | |
bfae80f2 | 19821 | |
c19d1205 ZW |
19822 | for (i = 0; i < 32; i += 2) |
19823 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
19824 | { | |
19825 | if (a & 0xff00) | |
19826 | { | |
19827 | if (a & ~ 0xffff) | |
19828 | continue; | |
19829 | * highpart = (a >> 8) | ((i + 24) << 7); | |
19830 | } | |
19831 | else if (a & 0xff0000) | |
19832 | { | |
19833 | if (a & 0xff000000) | |
19834 | continue; | |
19835 | * highpart = (a >> 16) | ((i + 16) << 7); | |
19836 | } | |
19837 | else | |
19838 | { | |
9c2799c2 | 19839 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
19840 | * highpart = (a >> 24) | ((i + 8) << 7); |
19841 | } | |
bfae80f2 | 19842 | |
c19d1205 ZW |
19843 | return (a & 0xff) | (i << 7); |
19844 | } | |
bfae80f2 | 19845 | |
c19d1205 | 19846 | return FAIL; |
bfae80f2 RE |
19847 | } |
19848 | ||
c19d1205 ZW |
19849 | static int |
19850 | validate_offset_imm (unsigned int val, int hwse) | |
19851 | { | |
19852 | if ((hwse && val > 255) || val > 4095) | |
19853 | return FAIL; | |
19854 | return val; | |
19855 | } | |
bfae80f2 | 19856 | |
55cf6793 | 19857 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
19858 | negative immediate constant by altering the instruction. A bit of |
19859 | a hack really. | |
19860 | MOV <-> MVN | |
19861 | AND <-> BIC | |
19862 | ADC <-> SBC | |
19863 | by inverting the second operand, and | |
19864 | ADD <-> SUB | |
19865 | CMP <-> CMN | |
19866 | by negating the second operand. */ | |
bfae80f2 | 19867 | |
c19d1205 ZW |
19868 | static int |
19869 | negate_data_op (unsigned long * instruction, | |
19870 | unsigned long value) | |
bfae80f2 | 19871 | { |
c19d1205 ZW |
19872 | int op, new_inst; |
19873 | unsigned long negated, inverted; | |
bfae80f2 | 19874 | |
c19d1205 ZW |
19875 | negated = encode_arm_immediate (-value); |
19876 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 19877 | |
c19d1205 ZW |
19878 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
19879 | switch (op) | |
bfae80f2 | 19880 | { |
c19d1205 ZW |
19881 | /* First negates. */ |
19882 | case OPCODE_SUB: /* ADD <-> SUB */ | |
19883 | new_inst = OPCODE_ADD; | |
19884 | value = negated; | |
19885 | break; | |
bfae80f2 | 19886 | |
c19d1205 ZW |
19887 | case OPCODE_ADD: |
19888 | new_inst = OPCODE_SUB; | |
19889 | value = negated; | |
19890 | break; | |
bfae80f2 | 19891 | |
c19d1205 ZW |
19892 | case OPCODE_CMP: /* CMP <-> CMN */ |
19893 | new_inst = OPCODE_CMN; | |
19894 | value = negated; | |
19895 | break; | |
bfae80f2 | 19896 | |
c19d1205 ZW |
19897 | case OPCODE_CMN: |
19898 | new_inst = OPCODE_CMP; | |
19899 | value = negated; | |
19900 | break; | |
bfae80f2 | 19901 | |
c19d1205 ZW |
19902 | /* Now Inverted ops. */ |
19903 | case OPCODE_MOV: /* MOV <-> MVN */ | |
19904 | new_inst = OPCODE_MVN; | |
19905 | value = inverted; | |
19906 | break; | |
bfae80f2 | 19907 | |
c19d1205 ZW |
19908 | case OPCODE_MVN: |
19909 | new_inst = OPCODE_MOV; | |
19910 | value = inverted; | |
19911 | break; | |
bfae80f2 | 19912 | |
c19d1205 ZW |
19913 | case OPCODE_AND: /* AND <-> BIC */ |
19914 | new_inst = OPCODE_BIC; | |
19915 | value = inverted; | |
19916 | break; | |
bfae80f2 | 19917 | |
c19d1205 ZW |
19918 | case OPCODE_BIC: |
19919 | new_inst = OPCODE_AND; | |
19920 | value = inverted; | |
19921 | break; | |
bfae80f2 | 19922 | |
c19d1205 ZW |
19923 | case OPCODE_ADC: /* ADC <-> SBC */ |
19924 | new_inst = OPCODE_SBC; | |
19925 | value = inverted; | |
19926 | break; | |
bfae80f2 | 19927 | |
c19d1205 ZW |
19928 | case OPCODE_SBC: |
19929 | new_inst = OPCODE_ADC; | |
19930 | value = inverted; | |
19931 | break; | |
bfae80f2 | 19932 | |
c19d1205 ZW |
19933 | /* We cannot do anything. */ |
19934 | default: | |
19935 | return FAIL; | |
b99bd4ef NC |
19936 | } |
19937 | ||
c19d1205 ZW |
19938 | if (value == (unsigned) FAIL) |
19939 | return FAIL; | |
19940 | ||
19941 | *instruction &= OPCODE_MASK; | |
19942 | *instruction |= new_inst << DATA_OP_SHIFT; | |
19943 | return value; | |
b99bd4ef NC |
19944 | } |
19945 | ||
ef8d22e6 PB |
19946 | /* Like negate_data_op, but for Thumb-2. */ |
19947 | ||
19948 | static unsigned int | |
16dd5e42 | 19949 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
19950 | { |
19951 | int op, new_inst; | |
19952 | int rd; | |
16dd5e42 | 19953 | unsigned int negated, inverted; |
ef8d22e6 PB |
19954 | |
19955 | negated = encode_thumb32_immediate (-value); | |
19956 | inverted = encode_thumb32_immediate (~value); | |
19957 | ||
19958 | rd = (*instruction >> 8) & 0xf; | |
19959 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
19960 | switch (op) | |
19961 | { | |
19962 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
19963 | case T2_OPCODE_SUB: | |
19964 | new_inst = T2_OPCODE_ADD; | |
19965 | value = negated; | |
19966 | break; | |
19967 | ||
19968 | case T2_OPCODE_ADD: | |
19969 | new_inst = T2_OPCODE_SUB; | |
19970 | value = negated; | |
19971 | break; | |
19972 | ||
19973 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
19974 | case T2_OPCODE_ORR: | |
19975 | new_inst = T2_OPCODE_ORN; | |
19976 | value = inverted; | |
19977 | break; | |
19978 | ||
19979 | case T2_OPCODE_ORN: | |
19980 | new_inst = T2_OPCODE_ORR; | |
19981 | value = inverted; | |
19982 | break; | |
19983 | ||
19984 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
19985 | case T2_OPCODE_AND: | |
19986 | new_inst = T2_OPCODE_BIC; | |
19987 | if (rd == 15) | |
19988 | value = FAIL; | |
19989 | else | |
19990 | value = inverted; | |
19991 | break; | |
19992 | ||
19993 | case T2_OPCODE_BIC: | |
19994 | new_inst = T2_OPCODE_AND; | |
19995 | value = inverted; | |
19996 | break; | |
19997 | ||
19998 | /* ADC <-> SBC */ | |
19999 | case T2_OPCODE_ADC: | |
20000 | new_inst = T2_OPCODE_SBC; | |
20001 | value = inverted; | |
20002 | break; | |
20003 | ||
20004 | case T2_OPCODE_SBC: | |
20005 | new_inst = T2_OPCODE_ADC; | |
20006 | value = inverted; | |
20007 | break; | |
20008 | ||
20009 | /* We cannot do anything. */ | |
20010 | default: | |
20011 | return FAIL; | |
20012 | } | |
20013 | ||
16dd5e42 | 20014 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
20015 | return FAIL; |
20016 | ||
20017 | *instruction &= T2_OPCODE_MASK; | |
20018 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
20019 | return value; | |
20020 | } | |
20021 | ||
8f06b2d8 PB |
20022 | /* Read a 32-bit thumb instruction from buf. */ |
20023 | static unsigned long | |
20024 | get_thumb32_insn (char * buf) | |
20025 | { | |
20026 | unsigned long insn; | |
20027 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
20028 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20029 | ||
20030 | return insn; | |
20031 | } | |
20032 | ||
a8bc6c78 PB |
20033 | |
20034 | /* We usually want to set the low bit on the address of thumb function | |
20035 | symbols. In particular .word foo - . should have the low bit set. | |
20036 | Generic code tries to fold the difference of two symbols to | |
20037 | a constant. Prevent this and force a relocation when the first symbols | |
20038 | is a thumb function. */ | |
c921be7d NC |
20039 | |
20040 | bfd_boolean | |
a8bc6c78 PB |
20041 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
20042 | { | |
20043 | if (op == O_subtract | |
20044 | && l->X_op == O_symbol | |
20045 | && r->X_op == O_symbol | |
20046 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
20047 | { | |
20048 | l->X_op = O_subtract; | |
20049 | l->X_op_symbol = r->X_add_symbol; | |
20050 | l->X_add_number -= r->X_add_number; | |
c921be7d | 20051 | return TRUE; |
a8bc6c78 | 20052 | } |
c921be7d | 20053 | |
a8bc6c78 | 20054 | /* Process as normal. */ |
c921be7d | 20055 | return FALSE; |
a8bc6c78 PB |
20056 | } |
20057 | ||
4a42ebbc RR |
20058 | /* Encode Thumb2 unconditional branches and calls. The encoding |
20059 | for the 2 are identical for the immediate values. */ | |
20060 | ||
20061 | static void | |
20062 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
20063 | { | |
20064 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
20065 | offsetT newval; | |
20066 | offsetT newval2; | |
20067 | addressT S, I1, I2, lo, hi; | |
20068 | ||
20069 | S = (value >> 24) & 0x01; | |
20070 | I1 = (value >> 23) & 0x01; | |
20071 | I2 = (value >> 22) & 0x01; | |
20072 | hi = (value >> 12) & 0x3ff; | |
20073 | lo = (value >> 1) & 0x7ff; | |
20074 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20075 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20076 | newval |= (S << 10) | hi; | |
20077 | newval2 &= ~T2I1I2MASK; | |
20078 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
20079 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20080 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
20081 | } | |
20082 | ||
c19d1205 | 20083 | void |
55cf6793 | 20084 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
20085 | valueT * valP, |
20086 | segT seg) | |
20087 | { | |
20088 | offsetT value = * valP; | |
20089 | offsetT newval; | |
20090 | unsigned int newimm; | |
20091 | unsigned long temp; | |
20092 | int sign; | |
20093 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 20094 | |
9c2799c2 | 20095 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 20096 | |
c19d1205 | 20097 | /* Note whether this will delete the relocation. */ |
4962c51a | 20098 | |
c19d1205 ZW |
20099 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
20100 | fixP->fx_done = 1; | |
b99bd4ef | 20101 | |
adbaf948 | 20102 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 20103 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
20104 | for emit_reloc. */ |
20105 | value &= 0xffffffff; | |
20106 | value ^= 0x80000000; | |
5f4273c7 | 20107 | value -= 0x80000000; |
adbaf948 ZW |
20108 | |
20109 | *valP = value; | |
c19d1205 | 20110 | fixP->fx_addnumber = value; |
b99bd4ef | 20111 | |
adbaf948 ZW |
20112 | /* Same treatment for fixP->fx_offset. */ |
20113 | fixP->fx_offset &= 0xffffffff; | |
20114 | fixP->fx_offset ^= 0x80000000; | |
20115 | fixP->fx_offset -= 0x80000000; | |
20116 | ||
c19d1205 | 20117 | switch (fixP->fx_r_type) |
b99bd4ef | 20118 | { |
c19d1205 ZW |
20119 | case BFD_RELOC_NONE: |
20120 | /* This will need to go in the object file. */ | |
20121 | fixP->fx_done = 0; | |
20122 | break; | |
b99bd4ef | 20123 | |
c19d1205 ZW |
20124 | case BFD_RELOC_ARM_IMMEDIATE: |
20125 | /* We claim that this fixup has been processed here, | |
20126 | even if in fact we generate an error because we do | |
20127 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
20128 | fixP->fx_done = 1; | |
b99bd4ef | 20129 | |
77db8e2e | 20130 | if (fixP->fx_addsy) |
b99bd4ef | 20131 | { |
77db8e2e | 20132 | const char *msg = 0; |
b99bd4ef | 20133 | |
77db8e2e NC |
20134 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
20135 | msg = _("undefined symbol %s used as an immediate value"); | |
20136 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
20137 | msg = _("symbol %s is in a different section"); | |
20138 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
20139 | msg = _("symbol %s is weak and may be overridden later"); | |
20140 | ||
20141 | if (msg) | |
20142 | { | |
20143 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20144 | msg, S_GET_NAME (fixP->fx_addsy)); | |
20145 | break; | |
20146 | } | |
42e5fcbf AS |
20147 | } |
20148 | ||
c19d1205 ZW |
20149 | newimm = encode_arm_immediate (value); |
20150 | temp = md_chars_to_number (buf, INSN_SIZE); | |
20151 | ||
20152 | /* If the instruction will fail, see if we can fix things up by | |
20153 | changing the opcode. */ | |
20154 | if (newimm == (unsigned int) FAIL | |
20155 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 20156 | { |
c19d1205 ZW |
20157 | as_bad_where (fixP->fx_file, fixP->fx_line, |
20158 | _("invalid constant (%lx) after fixup"), | |
20159 | (unsigned long) value); | |
20160 | break; | |
b99bd4ef | 20161 | } |
b99bd4ef | 20162 | |
c19d1205 ZW |
20163 | newimm |= (temp & 0xfffff000); |
20164 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
20165 | break; | |
b99bd4ef | 20166 | |
c19d1205 ZW |
20167 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
20168 | { | |
20169 | unsigned int highpart = 0; | |
20170 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 20171 | |
77db8e2e | 20172 | if (fixP->fx_addsy) |
42e5fcbf | 20173 | { |
77db8e2e | 20174 | const char *msg = 0; |
42e5fcbf | 20175 | |
77db8e2e NC |
20176 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
20177 | msg = _("undefined symbol %s used as an immediate value"); | |
20178 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
20179 | msg = _("symbol %s is in a different section"); | |
20180 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
20181 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 20182 | |
77db8e2e NC |
20183 | if (msg) |
20184 | { | |
20185 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20186 | msg, S_GET_NAME (fixP->fx_addsy)); | |
20187 | break; | |
20188 | } | |
20189 | } | |
20190 | ||
c19d1205 ZW |
20191 | newimm = encode_arm_immediate (value); |
20192 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 20193 | |
c19d1205 ZW |
20194 | /* If the instruction will fail, see if we can fix things up by |
20195 | changing the opcode. */ | |
20196 | if (newimm == (unsigned int) FAIL | |
20197 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
20198 | { | |
20199 | /* No ? OK - try using two ADD instructions to generate | |
20200 | the value. */ | |
20201 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 20202 | |
c19d1205 ZW |
20203 | /* Yes - then make sure that the second instruction is |
20204 | also an add. */ | |
20205 | if (newimm != (unsigned int) FAIL) | |
20206 | newinsn = temp; | |
20207 | /* Still No ? Try using a negated value. */ | |
20208 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
20209 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
20210 | /* Otherwise - give up. */ | |
20211 | else | |
20212 | { | |
20213 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20214 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
20215 | (long) value); | |
20216 | break; | |
20217 | } | |
b99bd4ef | 20218 | |
c19d1205 ZW |
20219 | /* Replace the first operand in the 2nd instruction (which |
20220 | is the PC) with the destination register. We have | |
20221 | already added in the PC in the first instruction and we | |
20222 | do not want to do it again. */ | |
20223 | newinsn &= ~ 0xf0000; | |
20224 | newinsn |= ((newinsn & 0x0f000) << 4); | |
20225 | } | |
b99bd4ef | 20226 | |
c19d1205 ZW |
20227 | newimm |= (temp & 0xfffff000); |
20228 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 20229 | |
c19d1205 ZW |
20230 | highpart |= (newinsn & 0xfffff000); |
20231 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
20232 | } | |
20233 | break; | |
b99bd4ef | 20234 | |
c19d1205 | 20235 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
20236 | if (!fixP->fx_done && seg->use_rela_p) |
20237 | value = 0; | |
20238 | ||
c19d1205 ZW |
20239 | case BFD_RELOC_ARM_LITERAL: |
20240 | sign = value >= 0; | |
b99bd4ef | 20241 | |
c19d1205 ZW |
20242 | if (value < 0) |
20243 | value = - value; | |
b99bd4ef | 20244 | |
c19d1205 | 20245 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 20246 | { |
c19d1205 ZW |
20247 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
20248 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20249 | _("invalid literal constant: pool needs to be closer")); | |
20250 | else | |
20251 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20252 | _("bad immediate value for offset (%ld)"), | |
20253 | (long) value); | |
20254 | break; | |
f03698e6 RE |
20255 | } |
20256 | ||
c19d1205 ZW |
20257 | newval = md_chars_to_number (buf, INSN_SIZE); |
20258 | newval &= 0xff7ff000; | |
20259 | newval |= value | (sign ? INDEX_UP : 0); | |
20260 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20261 | break; | |
b99bd4ef | 20262 | |
c19d1205 ZW |
20263 | case BFD_RELOC_ARM_OFFSET_IMM8: |
20264 | case BFD_RELOC_ARM_HWLITERAL: | |
20265 | sign = value >= 0; | |
b99bd4ef | 20266 | |
c19d1205 ZW |
20267 | if (value < 0) |
20268 | value = - value; | |
b99bd4ef | 20269 | |
c19d1205 | 20270 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 20271 | { |
c19d1205 ZW |
20272 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
20273 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20274 | _("invalid literal constant: pool needs to be closer")); | |
20275 | else | |
f9d4405b | 20276 | as_bad (_("bad immediate value for 8-bit offset (%ld)"), |
c19d1205 ZW |
20277 | (long) value); |
20278 | break; | |
b99bd4ef NC |
20279 | } |
20280 | ||
c19d1205 ZW |
20281 | newval = md_chars_to_number (buf, INSN_SIZE); |
20282 | newval &= 0xff7ff0f0; | |
20283 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
20284 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20285 | break; | |
b99bd4ef | 20286 | |
c19d1205 ZW |
20287 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
20288 | if (value < 0 || value > 1020 || value % 4 != 0) | |
20289 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20290 | _("bad immediate value for offset (%ld)"), (long) value); | |
20291 | value /= 4; | |
b99bd4ef | 20292 | |
c19d1205 | 20293 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
20294 | newval |= value; |
20295 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
20296 | break; | |
b99bd4ef | 20297 | |
c19d1205 ZW |
20298 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
20299 | /* This is a complicated relocation used for all varieties of Thumb32 | |
20300 | load/store instruction with immediate offset: | |
20301 | ||
20302 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
20303 | *4, optional writeback(W) | |
20304 | (doubleword load/store) | |
20305 | ||
20306 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
20307 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
20308 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
20309 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
20310 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
20311 | ||
20312 | Uppercase letters indicate bits that are already encoded at | |
20313 | this point. Lowercase letters are our problem. For the | |
20314 | second block of instructions, the secondary opcode nybble | |
20315 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
20316 | a PC-relative operation. */ | |
20317 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20318 | newval <<= 16; | |
20319 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 20320 | |
c19d1205 | 20321 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 20322 | { |
c19d1205 ZW |
20323 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
20324 | if (value >= 0) | |
20325 | newval |= (1 << 23); | |
20326 | else | |
20327 | value = -value; | |
20328 | if (value % 4 != 0) | |
20329 | { | |
20330 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20331 | _("offset not a multiple of 4")); | |
20332 | break; | |
20333 | } | |
20334 | value /= 4; | |
216d22bc | 20335 | if (value > 0xff) |
c19d1205 ZW |
20336 | { |
20337 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20338 | _("offset out of range")); | |
20339 | break; | |
20340 | } | |
20341 | newval &= ~0xff; | |
b99bd4ef | 20342 | } |
c19d1205 | 20343 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 20344 | { |
c19d1205 ZW |
20345 | /* PC-relative, 12-bit offset. */ |
20346 | if (value >= 0) | |
20347 | newval |= (1 << 23); | |
20348 | else | |
20349 | value = -value; | |
216d22bc | 20350 | if (value > 0xfff) |
c19d1205 ZW |
20351 | { |
20352 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20353 | _("offset out of range")); | |
20354 | break; | |
20355 | } | |
20356 | newval &= ~0xfff; | |
b99bd4ef | 20357 | } |
c19d1205 | 20358 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 20359 | { |
c19d1205 ZW |
20360 | /* Writeback: 8-bit, +/- offset. */ |
20361 | if (value >= 0) | |
20362 | newval |= (1 << 9); | |
20363 | else | |
20364 | value = -value; | |
216d22bc | 20365 | if (value > 0xff) |
c19d1205 ZW |
20366 | { |
20367 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20368 | _("offset out of range")); | |
20369 | break; | |
20370 | } | |
20371 | newval &= ~0xff; | |
b99bd4ef | 20372 | } |
c19d1205 | 20373 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 20374 | { |
c19d1205 | 20375 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 20376 | if (value < 0 || value > 0xff) |
b99bd4ef | 20377 | { |
c19d1205 ZW |
20378 | as_bad_where (fixP->fx_file, fixP->fx_line, |
20379 | _("offset out of range")); | |
20380 | break; | |
b99bd4ef | 20381 | } |
c19d1205 ZW |
20382 | newval &= ~0xff; |
20383 | newval |= value; | |
b99bd4ef NC |
20384 | } |
20385 | else | |
b99bd4ef | 20386 | { |
c19d1205 ZW |
20387 | /* Positive 12-bit or negative 8-bit offset. */ |
20388 | int limit; | |
20389 | if (value >= 0) | |
b99bd4ef | 20390 | { |
c19d1205 ZW |
20391 | newval |= (1 << 23); |
20392 | limit = 0xfff; | |
20393 | } | |
20394 | else | |
20395 | { | |
20396 | value = -value; | |
20397 | limit = 0xff; | |
20398 | } | |
20399 | if (value > limit) | |
20400 | { | |
20401 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20402 | _("offset out of range")); | |
20403 | break; | |
b99bd4ef | 20404 | } |
c19d1205 | 20405 | newval &= ~limit; |
b99bd4ef | 20406 | } |
b99bd4ef | 20407 | |
c19d1205 ZW |
20408 | newval |= value; |
20409 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
20410 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
20411 | break; | |
404ff6b5 | 20412 | |
c19d1205 ZW |
20413 | case BFD_RELOC_ARM_SHIFT_IMM: |
20414 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20415 | if (((unsigned long) value) > 32 | |
20416 | || (value == 32 | |
20417 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
20418 | { | |
20419 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20420 | _("shift expression is too large")); | |
20421 | break; | |
20422 | } | |
404ff6b5 | 20423 | |
c19d1205 ZW |
20424 | if (value == 0) |
20425 | /* Shifts of zero must be done as lsl. */ | |
20426 | newval &= ~0x60; | |
20427 | else if (value == 32) | |
20428 | value = 0; | |
20429 | newval &= 0xfffff07f; | |
20430 | newval |= (value & 0x1f) << 7; | |
20431 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20432 | break; | |
404ff6b5 | 20433 | |
c19d1205 | 20434 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 20435 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 20436 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 20437 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
20438 | /* We claim that this fixup has been processed here, |
20439 | even if in fact we generate an error because we do | |
20440 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
20441 | fixP->fx_done = 1; | |
404ff6b5 | 20442 | |
c19d1205 ZW |
20443 | if (fixP->fx_addsy |
20444 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
20445 | { | |
20446 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20447 | _("undefined symbol %s used as an immediate value"), | |
20448 | S_GET_NAME (fixP->fx_addsy)); | |
20449 | break; | |
20450 | } | |
404ff6b5 | 20451 | |
c19d1205 ZW |
20452 | newval = md_chars_to_number (buf, THUMB_SIZE); |
20453 | newval <<= 16; | |
20454 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 20455 | |
16805f35 PB |
20456 | newimm = FAIL; |
20457 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
20458 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
20459 | { |
20460 | newimm = encode_thumb32_immediate (value); | |
20461 | if (newimm == (unsigned int) FAIL) | |
20462 | newimm = thumb32_negate_data_op (&newval, value); | |
20463 | } | |
16805f35 PB |
20464 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
20465 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 20466 | { |
16805f35 PB |
20467 | /* Turn add/sum into addw/subw. */ |
20468 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
20469 | newval = (newval & 0xfeffffff) | 0x02000000; | |
40f246e3 NC |
20470 | /* No flat 12-bit imm encoding for addsw/subsw. */ |
20471 | if ((newval & 0x00100000) == 0) | |
e9f89963 | 20472 | { |
40f246e3 NC |
20473 | /* 12 bit immediate for addw/subw. */ |
20474 | if (value < 0) | |
20475 | { | |
20476 | value = -value; | |
20477 | newval ^= 0x00a00000; | |
20478 | } | |
20479 | if (value > 0xfff) | |
20480 | newimm = (unsigned int) FAIL; | |
20481 | else | |
20482 | newimm = value; | |
e9f89963 | 20483 | } |
92e90b6e | 20484 | } |
cc8a6dd0 | 20485 | |
c19d1205 | 20486 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 20487 | { |
c19d1205 ZW |
20488 | as_bad_where (fixP->fx_file, fixP->fx_line, |
20489 | _("invalid constant (%lx) after fixup"), | |
20490 | (unsigned long) value); | |
20491 | break; | |
3631a3c8 NC |
20492 | } |
20493 | ||
c19d1205 ZW |
20494 | newval |= (newimm & 0x800) << 15; |
20495 | newval |= (newimm & 0x700) << 4; | |
20496 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 20497 | |
c19d1205 ZW |
20498 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
20499 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
20500 | break; | |
a737bd4d | 20501 | |
3eb17e6b | 20502 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
20503 | if (((unsigned long) value) > 0xffff) |
20504 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 20505 | _("invalid smc expression")); |
2fc8bdac | 20506 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
20507 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
20508 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20509 | break; | |
a737bd4d | 20510 | |
90ec0d68 MGD |
20511 | case BFD_RELOC_ARM_HVC: |
20512 | if (((unsigned long) value) > 0xffff) | |
20513 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20514 | _("invalid hvc expression")); | |
20515 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20516 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
20517 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20518 | break; | |
20519 | ||
c19d1205 | 20520 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 20521 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
20522 | { |
20523 | if (((unsigned long) value) > 0xff) | |
20524 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20525 | _("invalid swi expression")); | |
2fc8bdac | 20526 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
20527 | newval |= value; |
20528 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20529 | } | |
20530 | else | |
20531 | { | |
20532 | if (((unsigned long) value) > 0x00ffffff) | |
20533 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20534 | _("invalid swi expression")); | |
2fc8bdac | 20535 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
20536 | newval |= value; |
20537 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20538 | } | |
20539 | break; | |
a737bd4d | 20540 | |
c19d1205 ZW |
20541 | case BFD_RELOC_ARM_MULTI: |
20542 | if (((unsigned long) value) > 0xffff) | |
20543 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20544 | _("invalid expression in load/store multiple")); | |
20545 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
20546 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20547 | break; | |
a737bd4d | 20548 | |
c19d1205 | 20549 | #ifdef OBJ_ELF |
39b41c9c | 20550 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
20551 | |
20552 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
20553 | && fixP->fx_addsy | |
20554 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20555 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20556 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
20557 | /* Flip the bl to blx. This is a simple flip | |
20558 | bit here because we generate PCREL_CALL for | |
20559 | unconditional bls. */ | |
20560 | { | |
20561 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20562 | newval = newval | 0x10000000; | |
20563 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20564 | temp = 1; | |
20565 | fixP->fx_done = 1; | |
20566 | } | |
39b41c9c PB |
20567 | else |
20568 | temp = 3; | |
20569 | goto arm_branch_common; | |
20570 | ||
20571 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
20572 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
20573 | && fixP->fx_addsy | |
20574 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20575 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20576 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
20577 | { | |
20578 | /* This would map to a bl<cond>, b<cond>, | |
20579 | b<always> to a Thumb function. We | |
20580 | need to force a relocation for this particular | |
20581 | case. */ | |
20582 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20583 | fixP->fx_done = 0; | |
20584 | } | |
20585 | ||
2fc8bdac | 20586 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 20587 | #endif |
39b41c9c PB |
20588 | case BFD_RELOC_ARM_PCREL_BRANCH: |
20589 | temp = 3; | |
20590 | goto arm_branch_common; | |
a737bd4d | 20591 | |
39b41c9c | 20592 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 20593 | |
39b41c9c | 20594 | temp = 1; |
267bf995 RR |
20595 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
20596 | && fixP->fx_addsy | |
20597 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20598 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20599 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
20600 | { | |
20601 | /* Flip the blx to a bl and warn. */ | |
20602 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
20603 | newval = 0xeb000000; | |
20604 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
20605 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
20606 | name); | |
20607 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20608 | temp = 3; | |
20609 | fixP->fx_done = 1; | |
20610 | } | |
20611 | ||
20612 | #ifdef OBJ_ELF | |
20613 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
20614 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; | |
20615 | #endif | |
20616 | ||
39b41c9c | 20617 | arm_branch_common: |
c19d1205 | 20618 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
20619 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
20620 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
20621 | also be be clear. */ | |
20622 | if (value & temp) | |
c19d1205 | 20623 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
20624 | _("misaligned branch destination")); |
20625 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
20626 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
20627 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20628 | _("branch out of range")); | |
a737bd4d | 20629 | |
2fc8bdac | 20630 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20631 | { |
2fc8bdac ZW |
20632 | newval = md_chars_to_number (buf, INSN_SIZE); |
20633 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
20634 | /* Set the H bit on BLX instructions. */ |
20635 | if (temp == 1) | |
20636 | { | |
20637 | if (value & 2) | |
20638 | newval |= 0x01000000; | |
20639 | else | |
20640 | newval &= ~0x01000000; | |
20641 | } | |
2fc8bdac | 20642 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 20643 | } |
c19d1205 | 20644 | break; |
a737bd4d | 20645 | |
25fe350b MS |
20646 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
20647 | /* CBZ can only branch forward. */ | |
a737bd4d | 20648 | |
738755b0 MS |
20649 | /* Attempts to use CBZ to branch to the next instruction |
20650 | (which, strictly speaking, are prohibited) will be turned into | |
20651 | no-ops. | |
20652 | ||
20653 | FIXME: It may be better to remove the instruction completely and | |
20654 | perform relaxation. */ | |
20655 | if (value == -2) | |
2fc8bdac ZW |
20656 | { |
20657 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 20658 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
20659 | md_number_to_chars (buf, newval, THUMB_SIZE); |
20660 | } | |
738755b0 MS |
20661 | else |
20662 | { | |
20663 | if (value & ~0x7e) | |
20664 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20665 | _("branch out of range")); | |
20666 | ||
20667 | if (fixP->fx_done || !seg->use_rela_p) | |
20668 | { | |
20669 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20670 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
20671 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20672 | } | |
20673 | } | |
c19d1205 | 20674 | break; |
a737bd4d | 20675 | |
c19d1205 | 20676 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
20677 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
20678 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20679 | _("branch out of range")); | |
a737bd4d | 20680 | |
2fc8bdac ZW |
20681 | if (fixP->fx_done || !seg->use_rela_p) |
20682 | { | |
20683 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20684 | newval |= (value & 0x1ff) >> 1; | |
20685 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20686 | } | |
c19d1205 | 20687 | break; |
a737bd4d | 20688 | |
c19d1205 | 20689 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
20690 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
20691 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20692 | _("branch out of range")); | |
a737bd4d | 20693 | |
2fc8bdac ZW |
20694 | if (fixP->fx_done || !seg->use_rela_p) |
20695 | { | |
20696 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20697 | newval |= (value & 0xfff) >> 1; | |
20698 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20699 | } | |
c19d1205 | 20700 | break; |
a737bd4d | 20701 | |
c19d1205 | 20702 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
20703 | if (fixP->fx_addsy |
20704 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20705 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20706 | && S_IS_DEFINED (fixP->fx_addsy) | |
20707 | && ARM_IS_FUNC (fixP->fx_addsy) | |
20708 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20709 | { | |
20710 | /* Force a relocation for a branch 20 bits wide. */ | |
20711 | fixP->fx_done = 0; | |
20712 | } | |
2fc8bdac ZW |
20713 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
20714 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20715 | _("conditional branch out of range")); | |
404ff6b5 | 20716 | |
2fc8bdac ZW |
20717 | if (fixP->fx_done || !seg->use_rela_p) |
20718 | { | |
20719 | offsetT newval2; | |
20720 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 20721 | |
2fc8bdac ZW |
20722 | S = (value & 0x00100000) >> 20; |
20723 | J2 = (value & 0x00080000) >> 19; | |
20724 | J1 = (value & 0x00040000) >> 18; | |
20725 | hi = (value & 0x0003f000) >> 12; | |
20726 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 20727 | |
2fc8bdac ZW |
20728 | newval = md_chars_to_number (buf, THUMB_SIZE); |
20729 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20730 | newval |= (S << 10) | hi; | |
20731 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
20732 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20733 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
20734 | } | |
c19d1205 | 20735 | break; |
6c43fab6 | 20736 | |
c19d1205 | 20737 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
20738 | |
20739 | /* If there is a blx from a thumb state function to | |
20740 | another thumb function flip this to a bl and warn | |
20741 | about it. */ | |
20742 | ||
20743 | if (fixP->fx_addsy | |
20744 | && S_IS_DEFINED (fixP->fx_addsy) | |
20745 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20746 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20747 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
20748 | { | |
20749 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
20750 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
20751 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
20752 | name); | |
20753 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20754 | newval = newval | 0x1000; | |
20755 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
20756 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20757 | fixP->fx_done = 1; | |
20758 | } | |
20759 | ||
20760 | ||
20761 | goto thumb_bl_common; | |
20762 | ||
c19d1205 | 20763 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
20764 | |
20765 | /* A bl from Thumb state ISA to an internal ARM state function | |
20766 | is converted to a blx. */ | |
20767 | if (fixP->fx_addsy | |
20768 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20769 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20770 | && S_IS_DEFINED (fixP->fx_addsy) | |
20771 | && ARM_IS_FUNC (fixP->fx_addsy) | |
20772 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20773 | { | |
20774 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20775 | newval = newval & ~0x1000; | |
20776 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
20777 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
20778 | fixP->fx_done = 1; | |
20779 | } | |
20780 | ||
20781 | thumb_bl_common: | |
20782 | ||
20783 | #ifdef OBJ_ELF | |
20784 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 && | |
20785 | fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
20786 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20787 | #endif | |
20788 | ||
2fc8bdac ZW |
20789 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
20790 | /* For a BLX instruction, make sure that the relocation is rounded up | |
20791 | to a word boundary. This follows the semantics of the instruction | |
20792 | which specifies that bit 1 of the target address will come from bit | |
20793 | 1 of the base address. */ | |
20794 | value = (value + 1) & ~ 1; | |
404ff6b5 | 20795 | |
2fc8bdac | 20796 | |
4a42ebbc RR |
20797 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
20798 | { | |
20799 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))) | |
20800 | { | |
20801 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20802 | _("branch out of range")); | |
20803 | } | |
20804 | else if ((value & ~0x1ffffff) | |
20805 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
20806 | { | |
20807 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20808 | _("Thumb2 branch out of range")); | |
20809 | } | |
c19d1205 | 20810 | } |
4a42ebbc RR |
20811 | |
20812 | if (fixP->fx_done || !seg->use_rela_p) | |
20813 | encode_thumb2_b_bl_offset (buf, value); | |
20814 | ||
c19d1205 | 20815 | break; |
404ff6b5 | 20816 | |
c19d1205 | 20817 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
20818 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
20819 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20820 | _("branch out of range")); | |
6c43fab6 | 20821 | |
2fc8bdac | 20822 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 20823 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 20824 | |
2fc8bdac | 20825 | break; |
a737bd4d | 20826 | |
2fc8bdac ZW |
20827 | case BFD_RELOC_8: |
20828 | if (fixP->fx_done || !seg->use_rela_p) | |
20829 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 20830 | break; |
a737bd4d | 20831 | |
c19d1205 | 20832 | case BFD_RELOC_16: |
2fc8bdac | 20833 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20834 | md_number_to_chars (buf, value, 2); |
c19d1205 | 20835 | break; |
a737bd4d | 20836 | |
c19d1205 ZW |
20837 | #ifdef OBJ_ELF |
20838 | case BFD_RELOC_ARM_TLS_GD32: | |
20839 | case BFD_RELOC_ARM_TLS_LE32: | |
20840 | case BFD_RELOC_ARM_TLS_IE32: | |
20841 | case BFD_RELOC_ARM_TLS_LDM32: | |
20842 | case BFD_RELOC_ARM_TLS_LDO32: | |
20843 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
20844 | /* fall through */ | |
6c43fab6 | 20845 | |
c19d1205 ZW |
20846 | case BFD_RELOC_ARM_GOT32: |
20847 | case BFD_RELOC_ARM_GOTOFF: | |
2fc8bdac ZW |
20848 | if (fixP->fx_done || !seg->use_rela_p) |
20849 | md_number_to_chars (buf, 0, 4); | |
c19d1205 | 20850 | break; |
b43420e6 NC |
20851 | |
20852 | case BFD_RELOC_ARM_GOT_PREL: | |
20853 | if (fixP->fx_done || !seg->use_rela_p) | |
20854 | md_number_to_chars (buf, value, 4); | |
20855 | break; | |
20856 | ||
9a6f4e97 NS |
20857 | case BFD_RELOC_ARM_TARGET2: |
20858 | /* TARGET2 is not partial-inplace, so we need to write the | |
20859 | addend here for REL targets, because it won't be written out | |
20860 | during reloc processing later. */ | |
20861 | if (fixP->fx_done || !seg->use_rela_p) | |
20862 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
20863 | break; | |
c19d1205 | 20864 | #endif |
6c43fab6 | 20865 | |
c19d1205 ZW |
20866 | case BFD_RELOC_RVA: |
20867 | case BFD_RELOC_32: | |
20868 | case BFD_RELOC_ARM_TARGET1: | |
20869 | case BFD_RELOC_ARM_ROSEGREL32: | |
20870 | case BFD_RELOC_ARM_SBREL32: | |
20871 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
20872 | #ifdef TE_PE |
20873 | case BFD_RELOC_32_SECREL: | |
20874 | #endif | |
2fc8bdac | 20875 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
20876 | #ifdef TE_WINCE |
20877 | /* For WinCE we only do this for pcrel fixups. */ | |
20878 | if (fixP->fx_done || fixP->fx_pcrel) | |
20879 | #endif | |
20880 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 20881 | break; |
6c43fab6 | 20882 | |
c19d1205 ZW |
20883 | #ifdef OBJ_ELF |
20884 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 20885 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
20886 | { |
20887 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
20888 | if ((value ^ (value >> 1)) & 0x40000000) | |
20889 | { | |
20890 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20891 | _("rel31 relocation overflow")); | |
20892 | } | |
20893 | newval |= value & 0x7fffffff; | |
20894 | md_number_to_chars (buf, newval, 4); | |
20895 | } | |
20896 | break; | |
c19d1205 | 20897 | #endif |
a737bd4d | 20898 | |
c19d1205 | 20899 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 20900 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
20901 | if (value < -1023 || value > 1023 || (value & 3)) |
20902 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20903 | _("co-processor offset out of range")); | |
20904 | cp_off_common: | |
20905 | sign = value >= 0; | |
20906 | if (value < 0) | |
20907 | value = -value; | |
8f06b2d8 PB |
20908 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20909 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20910 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20911 | else | |
20912 | newval = get_thumb32_insn (buf); | |
20913 | newval &= 0xff7fff00; | |
c19d1205 | 20914 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
8f06b2d8 PB |
20915 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20916 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20917 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20918 | else | |
20919 | put_thumb32_insn (buf, newval); | |
c19d1205 | 20920 | break; |
a737bd4d | 20921 | |
c19d1205 | 20922 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 20923 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
20924 | if (value < -255 || value > 255) |
20925 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20926 | _("co-processor offset out of range")); | |
df7849c5 | 20927 | value *= 4; |
c19d1205 | 20928 | goto cp_off_common; |
6c43fab6 | 20929 | |
c19d1205 ZW |
20930 | case BFD_RELOC_ARM_THUMB_OFFSET: |
20931 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20932 | /* Exactly what ranges, and where the offset is inserted depends | |
20933 | on the type of instruction, we can establish this from the | |
20934 | top 4 bits. */ | |
20935 | switch (newval >> 12) | |
20936 | { | |
20937 | case 4: /* PC load. */ | |
20938 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
20939 | forced to zero for these loads; md_pcrel_from has already | |
20940 | compensated for this. */ | |
20941 | if (value & 3) | |
20942 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20943 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
20944 | (((unsigned long) fixP->fx_frag->fr_address |
20945 | + (unsigned long) fixP->fx_where) & ~3) | |
20946 | + (unsigned long) value); | |
a737bd4d | 20947 | |
c19d1205 ZW |
20948 | if (value & ~0x3fc) |
20949 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20950 | _("invalid offset, value too big (0x%08lX)"), | |
20951 | (long) value); | |
a737bd4d | 20952 | |
c19d1205 ZW |
20953 | newval |= value >> 2; |
20954 | break; | |
a737bd4d | 20955 | |
c19d1205 ZW |
20956 | case 9: /* SP load/store. */ |
20957 | if (value & ~0x3fc) | |
20958 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20959 | _("invalid offset, value too big (0x%08lX)"), | |
20960 | (long) value); | |
20961 | newval |= value >> 2; | |
20962 | break; | |
6c43fab6 | 20963 | |
c19d1205 ZW |
20964 | case 6: /* Word load/store. */ |
20965 | if (value & ~0x7c) | |
20966 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20967 | _("invalid offset, value too big (0x%08lX)"), | |
20968 | (long) value); | |
20969 | newval |= value << 4; /* 6 - 2. */ | |
20970 | break; | |
a737bd4d | 20971 | |
c19d1205 ZW |
20972 | case 7: /* Byte load/store. */ |
20973 | if (value & ~0x1f) | |
20974 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20975 | _("invalid offset, value too big (0x%08lX)"), | |
20976 | (long) value); | |
20977 | newval |= value << 6; | |
20978 | break; | |
a737bd4d | 20979 | |
c19d1205 ZW |
20980 | case 8: /* Halfword load/store. */ |
20981 | if (value & ~0x3e) | |
20982 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20983 | _("invalid offset, value too big (0x%08lX)"), | |
20984 | (long) value); | |
20985 | newval |= value << 5; /* 6 - 1. */ | |
20986 | break; | |
a737bd4d | 20987 | |
c19d1205 ZW |
20988 | default: |
20989 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20990 | "Unable to process relocation for thumb opcode: %lx", | |
20991 | (unsigned long) newval); | |
20992 | break; | |
20993 | } | |
20994 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20995 | break; | |
a737bd4d | 20996 | |
c19d1205 ZW |
20997 | case BFD_RELOC_ARM_THUMB_ADD: |
20998 | /* This is a complicated relocation, since we use it for all of | |
20999 | the following immediate relocations: | |
a737bd4d | 21000 | |
c19d1205 ZW |
21001 | 3bit ADD/SUB |
21002 | 8bit ADD/SUB | |
21003 | 9bit ADD/SUB SP word-aligned | |
21004 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 21005 | |
c19d1205 ZW |
21006 | The type of instruction being processed is encoded in the |
21007 | instruction field: | |
a737bd4d | 21008 | |
c19d1205 ZW |
21009 | 0x8000 SUB |
21010 | 0x00F0 Rd | |
21011 | 0x000F Rs | |
21012 | */ | |
21013 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
21014 | { | |
21015 | int rd = (newval >> 4) & 0xf; | |
21016 | int rs = newval & 0xf; | |
21017 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 21018 | |
c19d1205 ZW |
21019 | /* Check for HI regs, only very restricted cases allowed: |
21020 | Adjusting SP, and using PC or SP to get an address. */ | |
21021 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
21022 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
21023 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21024 | _("invalid Hi register with immediate")); | |
a737bd4d | 21025 | |
c19d1205 ZW |
21026 | /* If value is negative, choose the opposite instruction. */ |
21027 | if (value < 0) | |
21028 | { | |
21029 | value = -value; | |
21030 | subtract = !subtract; | |
21031 | if (value < 0) | |
21032 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21033 | _("immediate value out of range")); | |
21034 | } | |
a737bd4d | 21035 | |
c19d1205 ZW |
21036 | if (rd == REG_SP) |
21037 | { | |
21038 | if (value & ~0x1fc) | |
21039 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21040 | _("invalid immediate for stack address calculation")); | |
21041 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
21042 | newval |= value >> 2; | |
21043 | } | |
21044 | else if (rs == REG_PC || rs == REG_SP) | |
21045 | { | |
21046 | if (subtract || value & ~0x3fc) | |
21047 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21048 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
21049 | (unsigned long) value); | |
21050 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
21051 | newval |= rd << 8; | |
21052 | newval |= value >> 2; | |
21053 | } | |
21054 | else if (rs == rd) | |
21055 | { | |
21056 | if (value & ~0xff) | |
21057 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21058 | _("immediate value out of range")); | |
21059 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
21060 | newval |= (rd << 8) | value; | |
21061 | } | |
21062 | else | |
21063 | { | |
21064 | if (value & ~0x7) | |
21065 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21066 | _("immediate value out of range")); | |
21067 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
21068 | newval |= rd | (rs << 3) | (value << 6); | |
21069 | } | |
21070 | } | |
21071 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21072 | break; | |
a737bd4d | 21073 | |
c19d1205 ZW |
21074 | case BFD_RELOC_ARM_THUMB_IMM: |
21075 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
21076 | if (value < 0 || value > 255) | |
21077 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 21078 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
21079 | (long) value); |
21080 | newval |= value; | |
21081 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21082 | break; | |
a737bd4d | 21083 | |
c19d1205 ZW |
21084 | case BFD_RELOC_ARM_THUMB_SHIFT: |
21085 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
21086 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
21087 | temp = newval & 0xf800; | |
21088 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
21089 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21090 | _("invalid shift value: %ld"), (long) value); | |
21091 | /* Shifts of zero must be encoded as LSL. */ | |
21092 | if (value == 0) | |
21093 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
21094 | /* Shifts of 32 are encoded as zero. */ | |
21095 | else if (value == 32) | |
21096 | value = 0; | |
21097 | newval |= value << 6; | |
21098 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
21099 | break; | |
a737bd4d | 21100 | |
c19d1205 ZW |
21101 | case BFD_RELOC_VTABLE_INHERIT: |
21102 | case BFD_RELOC_VTABLE_ENTRY: | |
21103 | fixP->fx_done = 0; | |
21104 | return; | |
6c43fab6 | 21105 | |
b6895b4f PB |
21106 | case BFD_RELOC_ARM_MOVW: |
21107 | case BFD_RELOC_ARM_MOVT: | |
21108 | case BFD_RELOC_ARM_THUMB_MOVW: | |
21109 | case BFD_RELOC_ARM_THUMB_MOVT: | |
21110 | if (fixP->fx_done || !seg->use_rela_p) | |
21111 | { | |
21112 | /* REL format relocations are limited to a 16-bit addend. */ | |
21113 | if (!fixP->fx_done) | |
21114 | { | |
39623e12 | 21115 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 21116 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 21117 | _("offset out of range")); |
b6895b4f PB |
21118 | } |
21119 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
21120 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
21121 | { | |
21122 | value >>= 16; | |
21123 | } | |
21124 | ||
21125 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
21126 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
21127 | { | |
21128 | newval = get_thumb32_insn (buf); | |
21129 | newval &= 0xfbf08f00; | |
21130 | newval |= (value & 0xf000) << 4; | |
21131 | newval |= (value & 0x0800) << 15; | |
21132 | newval |= (value & 0x0700) << 4; | |
21133 | newval |= (value & 0x00ff); | |
21134 | put_thumb32_insn (buf, newval); | |
21135 | } | |
21136 | else | |
21137 | { | |
21138 | newval = md_chars_to_number (buf, 4); | |
21139 | newval &= 0xfff0f000; | |
21140 | newval |= value & 0x0fff; | |
21141 | newval |= (value & 0xf000) << 4; | |
21142 | md_number_to_chars (buf, newval, 4); | |
21143 | } | |
21144 | } | |
21145 | return; | |
21146 | ||
4962c51a MS |
21147 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
21148 | case BFD_RELOC_ARM_ALU_PC_G0: | |
21149 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
21150 | case BFD_RELOC_ARM_ALU_PC_G1: | |
21151 | case BFD_RELOC_ARM_ALU_PC_G2: | |
21152 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
21153 | case BFD_RELOC_ARM_ALU_SB_G0: | |
21154 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
21155 | case BFD_RELOC_ARM_ALU_SB_G1: | |
21156 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 21157 | gas_assert (!fixP->fx_done); |
4962c51a MS |
21158 | if (!seg->use_rela_p) |
21159 | { | |
21160 | bfd_vma insn; | |
21161 | bfd_vma encoded_addend; | |
21162 | bfd_vma addend_abs = abs (value); | |
21163 | ||
21164 | /* Check that the absolute value of the addend can be | |
21165 | expressed as an 8-bit constant plus a rotation. */ | |
21166 | encoded_addend = encode_arm_immediate (addend_abs); | |
21167 | if (encoded_addend == (unsigned int) FAIL) | |
21168 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21169 | _("the offset 0x%08lX is not representable"), | |
495bde8e | 21170 | (unsigned long) addend_abs); |
4962c51a MS |
21171 | |
21172 | /* Extract the instruction. */ | |
21173 | insn = md_chars_to_number (buf, INSN_SIZE); | |
21174 | ||
21175 | /* If the addend is positive, use an ADD instruction. | |
21176 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
21177 | insn &= 0xff1fffff; | |
21178 | if (value < 0) | |
21179 | insn |= 1 << 22; | |
21180 | else | |
21181 | insn |= 1 << 23; | |
21182 | ||
21183 | /* Place the encoded addend into the first 12 bits of the | |
21184 | instruction. */ | |
21185 | insn &= 0xfffff000; | |
21186 | insn |= encoded_addend; | |
5f4273c7 NC |
21187 | |
21188 | /* Update the instruction. */ | |
4962c51a MS |
21189 | md_number_to_chars (buf, insn, INSN_SIZE); |
21190 | } | |
21191 | break; | |
21192 | ||
21193 | case BFD_RELOC_ARM_LDR_PC_G0: | |
21194 | case BFD_RELOC_ARM_LDR_PC_G1: | |
21195 | case BFD_RELOC_ARM_LDR_PC_G2: | |
21196 | case BFD_RELOC_ARM_LDR_SB_G0: | |
21197 | case BFD_RELOC_ARM_LDR_SB_G1: | |
21198 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 21199 | gas_assert (!fixP->fx_done); |
4962c51a MS |
21200 | if (!seg->use_rela_p) |
21201 | { | |
21202 | bfd_vma insn; | |
21203 | bfd_vma addend_abs = abs (value); | |
21204 | ||
21205 | /* Check that the absolute value of the addend can be | |
21206 | encoded in 12 bits. */ | |
21207 | if (addend_abs >= 0x1000) | |
21208 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21209 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
495bde8e | 21210 | (unsigned long) addend_abs); |
4962c51a MS |
21211 | |
21212 | /* Extract the instruction. */ | |
21213 | insn = md_chars_to_number (buf, INSN_SIZE); | |
21214 | ||
21215 | /* If the addend is negative, clear bit 23 of the instruction. | |
21216 | Otherwise set it. */ | |
21217 | if (value < 0) | |
21218 | insn &= ~(1 << 23); | |
21219 | else | |
21220 | insn |= 1 << 23; | |
21221 | ||
21222 | /* Place the absolute value of the addend into the first 12 bits | |
21223 | of the instruction. */ | |
21224 | insn &= 0xfffff000; | |
21225 | insn |= addend_abs; | |
5f4273c7 NC |
21226 | |
21227 | /* Update the instruction. */ | |
4962c51a MS |
21228 | md_number_to_chars (buf, insn, INSN_SIZE); |
21229 | } | |
21230 | break; | |
21231 | ||
21232 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
21233 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
21234 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
21235 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
21236 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
21237 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 21238 | gas_assert (!fixP->fx_done); |
4962c51a MS |
21239 | if (!seg->use_rela_p) |
21240 | { | |
21241 | bfd_vma insn; | |
21242 | bfd_vma addend_abs = abs (value); | |
21243 | ||
21244 | /* Check that the absolute value of the addend can be | |
21245 | encoded in 8 bits. */ | |
21246 | if (addend_abs >= 0x100) | |
21247 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21248 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
495bde8e | 21249 | (unsigned long) addend_abs); |
4962c51a MS |
21250 | |
21251 | /* Extract the instruction. */ | |
21252 | insn = md_chars_to_number (buf, INSN_SIZE); | |
21253 | ||
21254 | /* If the addend is negative, clear bit 23 of the instruction. | |
21255 | Otherwise set it. */ | |
21256 | if (value < 0) | |
21257 | insn &= ~(1 << 23); | |
21258 | else | |
21259 | insn |= 1 << 23; | |
21260 | ||
21261 | /* Place the first four bits of the absolute value of the addend | |
21262 | into the first 4 bits of the instruction, and the remaining | |
21263 | four into bits 8 .. 11. */ | |
21264 | insn &= 0xfffff0f0; | |
21265 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
5f4273c7 NC |
21266 | |
21267 | /* Update the instruction. */ | |
4962c51a MS |
21268 | md_number_to_chars (buf, insn, INSN_SIZE); |
21269 | } | |
21270 | break; | |
21271 | ||
21272 | case BFD_RELOC_ARM_LDC_PC_G0: | |
21273 | case BFD_RELOC_ARM_LDC_PC_G1: | |
21274 | case BFD_RELOC_ARM_LDC_PC_G2: | |
21275 | case BFD_RELOC_ARM_LDC_SB_G0: | |
21276 | case BFD_RELOC_ARM_LDC_SB_G1: | |
21277 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 21278 | gas_assert (!fixP->fx_done); |
4962c51a MS |
21279 | if (!seg->use_rela_p) |
21280 | { | |
21281 | bfd_vma insn; | |
21282 | bfd_vma addend_abs = abs (value); | |
21283 | ||
21284 | /* Check that the absolute value of the addend is a multiple of | |
21285 | four and, when divided by four, fits in 8 bits. */ | |
21286 | if (addend_abs & 0x3) | |
21287 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21288 | _("bad offset 0x%08lX (must be word-aligned)"), | |
495bde8e | 21289 | (unsigned long) addend_abs); |
4962c51a MS |
21290 | |
21291 | if ((addend_abs >> 2) > 0xff) | |
21292 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21293 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
495bde8e | 21294 | (unsigned long) addend_abs); |
4962c51a MS |
21295 | |
21296 | /* Extract the instruction. */ | |
21297 | insn = md_chars_to_number (buf, INSN_SIZE); | |
21298 | ||
21299 | /* If the addend is negative, clear bit 23 of the instruction. | |
21300 | Otherwise set it. */ | |
21301 | if (value < 0) | |
21302 | insn &= ~(1 << 23); | |
21303 | else | |
21304 | insn |= 1 << 23; | |
21305 | ||
21306 | /* Place the addend (divided by four) into the first eight | |
21307 | bits of the instruction. */ | |
21308 | insn &= 0xfffffff0; | |
21309 | insn |= addend_abs >> 2; | |
5f4273c7 NC |
21310 | |
21311 | /* Update the instruction. */ | |
4962c51a MS |
21312 | md_number_to_chars (buf, insn, INSN_SIZE); |
21313 | } | |
21314 | break; | |
21315 | ||
845b51d6 PB |
21316 | case BFD_RELOC_ARM_V4BX: |
21317 | /* This will need to go in the object file. */ | |
21318 | fixP->fx_done = 0; | |
21319 | break; | |
21320 | ||
c19d1205 ZW |
21321 | case BFD_RELOC_UNUSED: |
21322 | default: | |
21323 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
21324 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
21325 | } | |
6c43fab6 RE |
21326 | } |
21327 | ||
c19d1205 ZW |
21328 | /* Translate internal representation of relocation info to BFD target |
21329 | format. */ | |
a737bd4d | 21330 | |
c19d1205 | 21331 | arelent * |
00a97672 | 21332 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 21333 | { |
c19d1205 ZW |
21334 | arelent * reloc; |
21335 | bfd_reloc_code_real_type code; | |
a737bd4d | 21336 | |
21d799b5 | 21337 | reloc = (arelent *) xmalloc (sizeof (arelent)); |
a737bd4d | 21338 | |
21d799b5 | 21339 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
c19d1205 ZW |
21340 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
21341 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 21342 | |
2fc8bdac | 21343 | if (fixp->fx_pcrel) |
00a97672 RS |
21344 | { |
21345 | if (section->use_rela_p) | |
21346 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
21347 | else | |
21348 | fixp->fx_offset = reloc->address; | |
21349 | } | |
c19d1205 | 21350 | reloc->addend = fixp->fx_offset; |
a737bd4d | 21351 | |
c19d1205 | 21352 | switch (fixp->fx_r_type) |
a737bd4d | 21353 | { |
c19d1205 ZW |
21354 | case BFD_RELOC_8: |
21355 | if (fixp->fx_pcrel) | |
21356 | { | |
21357 | code = BFD_RELOC_8_PCREL; | |
21358 | break; | |
21359 | } | |
a737bd4d | 21360 | |
c19d1205 ZW |
21361 | case BFD_RELOC_16: |
21362 | if (fixp->fx_pcrel) | |
21363 | { | |
21364 | code = BFD_RELOC_16_PCREL; | |
21365 | break; | |
21366 | } | |
6c43fab6 | 21367 | |
c19d1205 ZW |
21368 | case BFD_RELOC_32: |
21369 | if (fixp->fx_pcrel) | |
21370 | { | |
21371 | code = BFD_RELOC_32_PCREL; | |
21372 | break; | |
21373 | } | |
a737bd4d | 21374 | |
b6895b4f PB |
21375 | case BFD_RELOC_ARM_MOVW: |
21376 | if (fixp->fx_pcrel) | |
21377 | { | |
21378 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
21379 | break; | |
21380 | } | |
21381 | ||
21382 | case BFD_RELOC_ARM_MOVT: | |
21383 | if (fixp->fx_pcrel) | |
21384 | { | |
21385 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
21386 | break; | |
21387 | } | |
21388 | ||
21389 | case BFD_RELOC_ARM_THUMB_MOVW: | |
21390 | if (fixp->fx_pcrel) | |
21391 | { | |
21392 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
21393 | break; | |
21394 | } | |
21395 | ||
21396 | case BFD_RELOC_ARM_THUMB_MOVT: | |
21397 | if (fixp->fx_pcrel) | |
21398 | { | |
21399 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
21400 | break; | |
21401 | } | |
21402 | ||
c19d1205 ZW |
21403 | case BFD_RELOC_NONE: |
21404 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
21405 | case BFD_RELOC_ARM_PCREL_BLX: | |
21406 | case BFD_RELOC_RVA: | |
21407 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
21408 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
21409 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
21410 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
21411 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
21412 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
21413 | case BFD_RELOC_VTABLE_ENTRY: |
21414 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
21415 | #ifdef TE_PE |
21416 | case BFD_RELOC_32_SECREL: | |
21417 | #endif | |
c19d1205 ZW |
21418 | code = fixp->fx_r_type; |
21419 | break; | |
a737bd4d | 21420 | |
00adf2d4 JB |
21421 | case BFD_RELOC_THUMB_PCREL_BLX: |
21422 | #ifdef OBJ_ELF | |
21423 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
21424 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
21425 | else | |
21426 | #endif | |
21427 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
21428 | break; | |
21429 | ||
c19d1205 ZW |
21430 | case BFD_RELOC_ARM_LITERAL: |
21431 | case BFD_RELOC_ARM_HWLITERAL: | |
21432 | /* If this is called then the a literal has | |
21433 | been referenced across a section boundary. */ | |
21434 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
21435 | _("literal referenced across section boundary")); | |
21436 | return NULL; | |
a737bd4d | 21437 | |
c19d1205 ZW |
21438 | #ifdef OBJ_ELF |
21439 | case BFD_RELOC_ARM_GOT32: | |
21440 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 21441 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
21442 | case BFD_RELOC_ARM_PLT32: |
21443 | case BFD_RELOC_ARM_TARGET1: | |
21444 | case BFD_RELOC_ARM_ROSEGREL32: | |
21445 | case BFD_RELOC_ARM_SBREL32: | |
21446 | case BFD_RELOC_ARM_PREL31: | |
21447 | case BFD_RELOC_ARM_TARGET2: | |
21448 | case BFD_RELOC_ARM_TLS_LE32: | |
21449 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
21450 | case BFD_RELOC_ARM_PCREL_CALL: |
21451 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
21452 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
21453 | case BFD_RELOC_ARM_ALU_PC_G0: | |
21454 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
21455 | case BFD_RELOC_ARM_ALU_PC_G1: | |
21456 | case BFD_RELOC_ARM_ALU_PC_G2: | |
21457 | case BFD_RELOC_ARM_LDR_PC_G0: | |
21458 | case BFD_RELOC_ARM_LDR_PC_G1: | |
21459 | case BFD_RELOC_ARM_LDR_PC_G2: | |
21460 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
21461 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
21462 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
21463 | case BFD_RELOC_ARM_LDC_PC_G0: | |
21464 | case BFD_RELOC_ARM_LDC_PC_G1: | |
21465 | case BFD_RELOC_ARM_LDC_PC_G2: | |
21466 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
21467 | case BFD_RELOC_ARM_ALU_SB_G0: | |
21468 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
21469 | case BFD_RELOC_ARM_ALU_SB_G1: | |
21470 | case BFD_RELOC_ARM_ALU_SB_G2: | |
21471 | case BFD_RELOC_ARM_LDR_SB_G0: | |
21472 | case BFD_RELOC_ARM_LDR_SB_G1: | |
21473 | case BFD_RELOC_ARM_LDR_SB_G2: | |
21474 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
21475 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
21476 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
21477 | case BFD_RELOC_ARM_LDC_SB_G0: | |
21478 | case BFD_RELOC_ARM_LDC_SB_G1: | |
21479 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 21480 | case BFD_RELOC_ARM_V4BX: |
c19d1205 ZW |
21481 | code = fixp->fx_r_type; |
21482 | break; | |
a737bd4d | 21483 | |
c19d1205 ZW |
21484 | case BFD_RELOC_ARM_TLS_GD32: |
21485 | case BFD_RELOC_ARM_TLS_IE32: | |
21486 | case BFD_RELOC_ARM_TLS_LDM32: | |
21487 | /* BFD will include the symbol's address in the addend. | |
21488 | But we don't want that, so subtract it out again here. */ | |
21489 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
21490 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
21491 | code = fixp->fx_r_type; | |
21492 | break; | |
21493 | #endif | |
a737bd4d | 21494 | |
c19d1205 ZW |
21495 | case BFD_RELOC_ARM_IMMEDIATE: |
21496 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
21497 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
21498 | return NULL; | |
a737bd4d | 21499 | |
c19d1205 ZW |
21500 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
21501 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
21502 | _("ADRL used for a symbol not defined in the same file")); | |
21503 | return NULL; | |
a737bd4d | 21504 | |
c19d1205 | 21505 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
21506 | if (section->use_rela_p) |
21507 | { | |
21508 | code = fixp->fx_r_type; | |
21509 | break; | |
21510 | } | |
21511 | ||
c19d1205 ZW |
21512 | if (fixp->fx_addsy != NULL |
21513 | && !S_IS_DEFINED (fixp->fx_addsy) | |
21514 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 21515 | { |
c19d1205 ZW |
21516 | as_bad_where (fixp->fx_file, fixp->fx_line, |
21517 | _("undefined local label `%s'"), | |
21518 | S_GET_NAME (fixp->fx_addsy)); | |
21519 | return NULL; | |
a737bd4d NC |
21520 | } |
21521 | ||
c19d1205 ZW |
21522 | as_bad_where (fixp->fx_file, fixp->fx_line, |
21523 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
21524 | return NULL; | |
a737bd4d | 21525 | |
c19d1205 ZW |
21526 | default: |
21527 | { | |
21528 | char * type; | |
6c43fab6 | 21529 | |
c19d1205 ZW |
21530 | switch (fixp->fx_r_type) |
21531 | { | |
21532 | case BFD_RELOC_NONE: type = "NONE"; break; | |
21533 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
21534 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 21535 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
21536 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
21537 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
21538 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 21539 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 21540 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
21541 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
21542 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
21543 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
21544 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
21545 | default: type = _("<unknown>"); break; | |
21546 | } | |
21547 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
21548 | _("cannot represent %s relocation in this object file format"), | |
21549 | type); | |
21550 | return NULL; | |
21551 | } | |
a737bd4d | 21552 | } |
6c43fab6 | 21553 | |
c19d1205 ZW |
21554 | #ifdef OBJ_ELF |
21555 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
21556 | && GOT_symbol | |
21557 | && fixp->fx_addsy == GOT_symbol) | |
21558 | { | |
21559 | code = BFD_RELOC_ARM_GOTPC; | |
21560 | reloc->addend = fixp->fx_offset = reloc->address; | |
21561 | } | |
21562 | #endif | |
6c43fab6 | 21563 | |
c19d1205 | 21564 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 21565 | |
c19d1205 ZW |
21566 | if (reloc->howto == NULL) |
21567 | { | |
21568 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
21569 | _("cannot represent %s relocation in this object file format"), | |
21570 | bfd_get_reloc_code_name (code)); | |
21571 | return NULL; | |
21572 | } | |
6c43fab6 | 21573 | |
c19d1205 ZW |
21574 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
21575 | vtable entry to be used in the relocation's section offset. */ | |
21576 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
21577 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 21578 | |
c19d1205 | 21579 | return reloc; |
6c43fab6 RE |
21580 | } |
21581 | ||
c19d1205 | 21582 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 21583 | |
c19d1205 ZW |
21584 | void |
21585 | cons_fix_new_arm (fragS * frag, | |
21586 | int where, | |
21587 | int size, | |
21588 | expressionS * exp) | |
6c43fab6 | 21589 | { |
c19d1205 ZW |
21590 | bfd_reloc_code_real_type type; |
21591 | int pcrel = 0; | |
6c43fab6 | 21592 | |
c19d1205 ZW |
21593 | /* Pick a reloc. |
21594 | FIXME: @@ Should look at CPU word size. */ | |
21595 | switch (size) | |
21596 | { | |
21597 | case 1: | |
21598 | type = BFD_RELOC_8; | |
21599 | break; | |
21600 | case 2: | |
21601 | type = BFD_RELOC_16; | |
21602 | break; | |
21603 | case 4: | |
21604 | default: | |
21605 | type = BFD_RELOC_32; | |
21606 | break; | |
21607 | case 8: | |
21608 | type = BFD_RELOC_64; | |
21609 | break; | |
21610 | } | |
6c43fab6 | 21611 | |
f0927246 NC |
21612 | #ifdef TE_PE |
21613 | if (exp->X_op == O_secrel) | |
21614 | { | |
21615 | exp->X_op = O_symbol; | |
21616 | type = BFD_RELOC_32_SECREL; | |
21617 | } | |
21618 | #endif | |
21619 | ||
c19d1205 ZW |
21620 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
21621 | } | |
6c43fab6 | 21622 | |
4343666d | 21623 | #if defined (OBJ_COFF) |
c19d1205 ZW |
21624 | void |
21625 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 21626 | { |
c19d1205 ZW |
21627 | /* If the destination of the branch is a defined symbol which does not have |
21628 | the THUMB_FUNC attribute, then we must be calling a function which has | |
21629 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
21630 | function and change the branch to refer to that function instead. */ | |
21631 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
21632 | && fixP->fx_addsy != NULL | |
21633 | && S_IS_DEFINED (fixP->fx_addsy) | |
21634 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 21635 | { |
c19d1205 | 21636 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 21637 | } |
c19d1205 ZW |
21638 | } |
21639 | #endif | |
6c43fab6 | 21640 | |
267bf995 | 21641 | |
c19d1205 ZW |
21642 | int |
21643 | arm_force_relocation (struct fix * fixp) | |
21644 | { | |
21645 | #if defined (OBJ_COFF) && defined (TE_PE) | |
21646 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
21647 | return 1; | |
21648 | #endif | |
6c43fab6 | 21649 | |
267bf995 RR |
21650 | /* In case we have a call or a branch to a function in ARM ISA mode from |
21651 | a thumb function or vice-versa force the relocation. These relocations | |
21652 | are cleared off for some cores that might have blx and simple transformations | |
21653 | are possible. */ | |
21654 | ||
21655 | #ifdef OBJ_ELF | |
21656 | switch (fixp->fx_r_type) | |
21657 | { | |
21658 | case BFD_RELOC_ARM_PCREL_JUMP: | |
21659 | case BFD_RELOC_ARM_PCREL_CALL: | |
21660 | case BFD_RELOC_THUMB_PCREL_BLX: | |
21661 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
21662 | return 1; | |
21663 | break; | |
21664 | ||
21665 | case BFD_RELOC_ARM_PCREL_BLX: | |
21666 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
21667 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
21668 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
21669 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
21670 | return 1; | |
21671 | break; | |
21672 | ||
21673 | default: | |
21674 | break; | |
21675 | } | |
21676 | #endif | |
21677 | ||
c19d1205 ZW |
21678 | /* Resolve these relocations even if the symbol is extern or weak. */ |
21679 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
21680 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 | 21681 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
16805f35 | 21682 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
21683 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
21684 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
21685 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 21686 | return 0; |
a737bd4d | 21687 | |
4962c51a MS |
21688 | /* Always leave these relocations for the linker. */ |
21689 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
21690 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
21691 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
21692 | return 1; | |
21693 | ||
f0291e4c PB |
21694 | /* Always generate relocations against function symbols. */ |
21695 | if (fixp->fx_r_type == BFD_RELOC_32 | |
21696 | && fixp->fx_addsy | |
21697 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
21698 | return 1; | |
21699 | ||
c19d1205 | 21700 | return generic_force_reloc (fixp); |
404ff6b5 AH |
21701 | } |
21702 | ||
0ffdc86c | 21703 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
21704 | /* Relocations against function names must be left unadjusted, |
21705 | so that the linker can use this information to generate interworking | |
21706 | stubs. The MIPS version of this function | |
c19d1205 ZW |
21707 | also prevents relocations that are mips-16 specific, but I do not |
21708 | know why it does this. | |
404ff6b5 | 21709 | |
c19d1205 ZW |
21710 | FIXME: |
21711 | There is one other problem that ought to be addressed here, but | |
21712 | which currently is not: Taking the address of a label (rather | |
21713 | than a function) and then later jumping to that address. Such | |
21714 | addresses also ought to have their bottom bit set (assuming that | |
21715 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 21716 | |
c19d1205 ZW |
21717 | bfd_boolean |
21718 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 21719 | { |
c19d1205 ZW |
21720 | if (fixP->fx_addsy == NULL) |
21721 | return 1; | |
404ff6b5 | 21722 | |
e28387c3 PB |
21723 | /* Preserve relocations against symbols with function type. */ |
21724 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 21725 | return FALSE; |
e28387c3 | 21726 | |
c19d1205 ZW |
21727 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
21728 | && fixP->fx_subsy == NULL) | |
c921be7d | 21729 | return FALSE; |
a737bd4d | 21730 | |
c19d1205 ZW |
21731 | /* We need the symbol name for the VTABLE entries. */ |
21732 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
21733 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 21734 | return FALSE; |
404ff6b5 | 21735 | |
c19d1205 ZW |
21736 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
21737 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
21738 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
21739 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
21740 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
21741 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
21742 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
21743 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
21744 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
21745 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
c921be7d | 21746 | return FALSE; |
a737bd4d | 21747 | |
4962c51a MS |
21748 | /* Similarly for group relocations. */ |
21749 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
21750 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
21751 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 21752 | return FALSE; |
4962c51a | 21753 | |
79947c54 CD |
21754 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
21755 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
21756 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
21757 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
21758 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
21759 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
21760 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
21761 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
21762 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 21763 | return FALSE; |
79947c54 | 21764 | |
c921be7d | 21765 | return TRUE; |
a737bd4d | 21766 | } |
0ffdc86c NC |
21767 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
21768 | ||
21769 | #ifdef OBJ_ELF | |
404ff6b5 | 21770 | |
c19d1205 ZW |
21771 | const char * |
21772 | elf32_arm_target_format (void) | |
404ff6b5 | 21773 | { |
c19d1205 ZW |
21774 | #ifdef TE_SYMBIAN |
21775 | return (target_big_endian | |
21776 | ? "elf32-bigarm-symbian" | |
21777 | : "elf32-littlearm-symbian"); | |
21778 | #elif defined (TE_VXWORKS) | |
21779 | return (target_big_endian | |
21780 | ? "elf32-bigarm-vxworks" | |
21781 | : "elf32-littlearm-vxworks"); | |
21782 | #else | |
21783 | if (target_big_endian) | |
21784 | return "elf32-bigarm"; | |
21785 | else | |
21786 | return "elf32-littlearm"; | |
21787 | #endif | |
404ff6b5 AH |
21788 | } |
21789 | ||
c19d1205 ZW |
21790 | void |
21791 | armelf_frob_symbol (symbolS * symp, | |
21792 | int * puntp) | |
404ff6b5 | 21793 | { |
c19d1205 ZW |
21794 | elf_frob_symbol (symp, puntp); |
21795 | } | |
21796 | #endif | |
404ff6b5 | 21797 | |
c19d1205 | 21798 | /* MD interface: Finalization. */ |
a737bd4d | 21799 | |
c19d1205 ZW |
21800 | void |
21801 | arm_cleanup (void) | |
21802 | { | |
21803 | literal_pool * pool; | |
a737bd4d | 21804 | |
e07e6e58 NC |
21805 | /* Ensure that all the IT blocks are properly closed. */ |
21806 | check_it_blocks_finished (); | |
21807 | ||
c19d1205 ZW |
21808 | for (pool = list_of_pools; pool; pool = pool->next) |
21809 | { | |
5f4273c7 | 21810 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
21811 | subseg_set (pool->section, pool->sub_section); |
21812 | #ifdef OBJ_ELF | |
21813 | arm_elf_change_section (); | |
21814 | #endif | |
21815 | s_ltorg (0); | |
21816 | } | |
404ff6b5 AH |
21817 | } |
21818 | ||
cd000bff DJ |
21819 | #ifdef OBJ_ELF |
21820 | /* Remove any excess mapping symbols generated for alignment frags in | |
21821 | SEC. We may have created a mapping symbol before a zero byte | |
21822 | alignment; remove it if there's a mapping symbol after the | |
21823 | alignment. */ | |
21824 | static void | |
21825 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
21826 | void *dummy ATTRIBUTE_UNUSED) | |
21827 | { | |
21828 | segment_info_type *seginfo = seg_info (sec); | |
21829 | fragS *fragp; | |
21830 | ||
21831 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
21832 | return; | |
21833 | ||
21834 | for (fragp = seginfo->frchainP->frch_root; | |
21835 | fragp != NULL; | |
21836 | fragp = fragp->fr_next) | |
21837 | { | |
21838 | symbolS *sym = fragp->tc_frag_data.last_map; | |
21839 | fragS *next = fragp->fr_next; | |
21840 | ||
21841 | /* Variable-sized frags have been converted to fixed size by | |
21842 | this point. But if this was variable-sized to start with, | |
21843 | there will be a fixed-size frag after it. So don't handle | |
21844 | next == NULL. */ | |
21845 | if (sym == NULL || next == NULL) | |
21846 | continue; | |
21847 | ||
21848 | if (S_GET_VALUE (sym) < next->fr_address) | |
21849 | /* Not at the end of this frag. */ | |
21850 | continue; | |
21851 | know (S_GET_VALUE (sym) == next->fr_address); | |
21852 | ||
21853 | do | |
21854 | { | |
21855 | if (next->tc_frag_data.first_map != NULL) | |
21856 | { | |
21857 | /* Next frag starts with a mapping symbol. Discard this | |
21858 | one. */ | |
21859 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
21860 | break; | |
21861 | } | |
21862 | ||
21863 | if (next->fr_next == NULL) | |
21864 | { | |
21865 | /* This mapping symbol is at the end of the section. Discard | |
21866 | it. */ | |
21867 | know (next->fr_fix == 0 && next->fr_var == 0); | |
21868 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
21869 | break; | |
21870 | } | |
21871 | ||
21872 | /* As long as we have empty frags without any mapping symbols, | |
21873 | keep looking. */ | |
21874 | /* If the next frag is non-empty and does not start with a | |
21875 | mapping symbol, then this mapping symbol is required. */ | |
21876 | if (next->fr_address != next->fr_next->fr_address) | |
21877 | break; | |
21878 | ||
21879 | next = next->fr_next; | |
21880 | } | |
21881 | while (next != NULL); | |
21882 | } | |
21883 | } | |
21884 | #endif | |
21885 | ||
c19d1205 ZW |
21886 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
21887 | ARM ones. */ | |
404ff6b5 | 21888 | |
c19d1205 ZW |
21889 | void |
21890 | arm_adjust_symtab (void) | |
404ff6b5 | 21891 | { |
c19d1205 ZW |
21892 | #ifdef OBJ_COFF |
21893 | symbolS * sym; | |
404ff6b5 | 21894 | |
c19d1205 ZW |
21895 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
21896 | { | |
21897 | if (ARM_IS_THUMB (sym)) | |
21898 | { | |
21899 | if (THUMB_IS_FUNC (sym)) | |
21900 | { | |
21901 | /* Mark the symbol as a Thumb function. */ | |
21902 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
21903 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
21904 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 21905 | |
c19d1205 ZW |
21906 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
21907 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
21908 | else | |
21909 | as_bad (_("%s: unexpected function type: %d"), | |
21910 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
21911 | } | |
21912 | else switch (S_GET_STORAGE_CLASS (sym)) | |
21913 | { | |
21914 | case C_EXT: | |
21915 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
21916 | break; | |
21917 | case C_STAT: | |
21918 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
21919 | break; | |
21920 | case C_LABEL: | |
21921 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
21922 | break; | |
21923 | default: | |
21924 | /* Do nothing. */ | |
21925 | break; | |
21926 | } | |
21927 | } | |
a737bd4d | 21928 | |
c19d1205 ZW |
21929 | if (ARM_IS_INTERWORK (sym)) |
21930 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 21931 | } |
c19d1205 ZW |
21932 | #endif |
21933 | #ifdef OBJ_ELF | |
21934 | symbolS * sym; | |
21935 | char bind; | |
404ff6b5 | 21936 | |
c19d1205 | 21937 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 21938 | { |
c19d1205 ZW |
21939 | if (ARM_IS_THUMB (sym)) |
21940 | { | |
21941 | elf_symbol_type * elf_sym; | |
404ff6b5 | 21942 | |
c19d1205 ZW |
21943 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
21944 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 21945 | |
b0796911 PB |
21946 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
21947 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
21948 | { |
21949 | /* If it's a .thumb_func, declare it as so, | |
21950 | otherwise tag label as .code 16. */ | |
21951 | if (THUMB_IS_FUNC (sym)) | |
21952 | elf_sym->internal_elf_sym.st_info = | |
21953 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
3ba67470 | 21954 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
21955 | elf_sym->internal_elf_sym.st_info = |
21956 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
21957 | } | |
21958 | } | |
21959 | } | |
cd000bff DJ |
21960 | |
21961 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
21962 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
21963 | /* Now do generic ELF adjustments. */ |
21964 | elf_adjust_symtab (); | |
c19d1205 | 21965 | #endif |
404ff6b5 AH |
21966 | } |
21967 | ||
c19d1205 | 21968 | /* MD interface: Initialization. */ |
404ff6b5 | 21969 | |
a737bd4d | 21970 | static void |
c19d1205 | 21971 | set_constant_flonums (void) |
a737bd4d | 21972 | { |
c19d1205 | 21973 | int i; |
404ff6b5 | 21974 | |
c19d1205 ZW |
21975 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
21976 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
21977 | abort (); | |
a737bd4d | 21978 | } |
404ff6b5 | 21979 | |
3e9e4fcf JB |
21980 | /* Auto-select Thumb mode if it's the only available instruction set for the |
21981 | given architecture. */ | |
21982 | ||
21983 | static void | |
21984 | autoselect_thumb_from_cpu_variant (void) | |
21985 | { | |
21986 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
21987 | opcode_select (16); | |
21988 | } | |
21989 | ||
c19d1205 ZW |
21990 | void |
21991 | md_begin (void) | |
a737bd4d | 21992 | { |
c19d1205 ZW |
21993 | unsigned mach; |
21994 | unsigned int i; | |
404ff6b5 | 21995 | |
c19d1205 ZW |
21996 | if ( (arm_ops_hsh = hash_new ()) == NULL |
21997 | || (arm_cond_hsh = hash_new ()) == NULL | |
21998 | || (arm_shift_hsh = hash_new ()) == NULL | |
21999 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 22000 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 22001 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
22002 | || (arm_reloc_hsh = hash_new ()) == NULL |
22003 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
22004 | as_fatal (_("virtual memory exhausted")); |
22005 | ||
22006 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 22007 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 22008 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 22009 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 22010 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 22011 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 22012 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 22013 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 22014 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 NC |
22015 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
22016 | (void *) (v7m_psrs + i)); | |
c19d1205 | 22017 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 22018 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
22019 | for (i = 0; |
22020 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
22021 | i++) | |
d3ce72d0 | 22022 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 22023 | (void *) (barrier_opt_names + i)); |
c19d1205 ZW |
22024 | #ifdef OBJ_ELF |
22025 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
5a49b8ac | 22026 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i)); |
c19d1205 ZW |
22027 | #endif |
22028 | ||
22029 | set_constant_flonums (); | |
404ff6b5 | 22030 | |
c19d1205 ZW |
22031 | /* Set the cpu variant based on the command-line options. We prefer |
22032 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
22033 | -mfpu= over any other way of setting the floating point unit. | |
22034 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 22035 | if (legacy_cpu) |
404ff6b5 | 22036 | { |
e74cfd16 | 22037 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
22038 | as_bad (_("use of old and new-style options to set CPU type")); |
22039 | ||
22040 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 22041 | } |
e74cfd16 | 22042 | else if (!mcpu_cpu_opt) |
c19d1205 | 22043 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 22044 | |
e74cfd16 | 22045 | if (legacy_fpu) |
c19d1205 | 22046 | { |
e74cfd16 | 22047 | if (mfpu_opt) |
c19d1205 | 22048 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
22049 | |
22050 | mfpu_opt = legacy_fpu; | |
22051 | } | |
e74cfd16 | 22052 | else if (!mfpu_opt) |
03b1477f | 22053 | { |
45eb4c1b NS |
22054 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
22055 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
22056 | /* Some environments specify a default FPU. If they don't, infer it |
22057 | from the processor. */ | |
e74cfd16 | 22058 | if (mcpu_fpu_opt) |
03b1477f RE |
22059 | mfpu_opt = mcpu_fpu_opt; |
22060 | else | |
22061 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 22062 | #else |
e74cfd16 | 22063 | mfpu_opt = &fpu_default; |
39c2da32 | 22064 | #endif |
03b1477f RE |
22065 | } |
22066 | ||
e74cfd16 | 22067 | if (!mfpu_opt) |
03b1477f | 22068 | { |
493cb6ef | 22069 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 22070 | mfpu_opt = &fpu_default; |
493cb6ef | 22071 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 22072 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 22073 | else |
e74cfd16 | 22074 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
22075 | } |
22076 | ||
ee065d83 | 22077 | #ifdef CPU_DEFAULT |
e74cfd16 | 22078 | if (!mcpu_cpu_opt) |
ee065d83 | 22079 | { |
e74cfd16 PB |
22080 | mcpu_cpu_opt = &cpu_default; |
22081 | selected_cpu = cpu_default; | |
ee065d83 | 22082 | } |
e74cfd16 PB |
22083 | #else |
22084 | if (mcpu_cpu_opt) | |
22085 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 22086 | else |
e74cfd16 | 22087 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 22088 | #endif |
03b1477f | 22089 | |
e74cfd16 | 22090 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 22091 | |
3e9e4fcf JB |
22092 | autoselect_thumb_from_cpu_variant (); |
22093 | ||
e74cfd16 | 22094 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 22095 | |
f17c130b | 22096 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 22097 | { |
7cc69913 NC |
22098 | unsigned int flags = 0; |
22099 | ||
22100 | #if defined OBJ_ELF | |
22101 | flags = meabi_flags; | |
d507cf36 PB |
22102 | |
22103 | switch (meabi_flags) | |
33a392fb | 22104 | { |
d507cf36 | 22105 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 22106 | #endif |
d507cf36 PB |
22107 | /* Set the flags in the private structure. */ |
22108 | if (uses_apcs_26) flags |= F_APCS26; | |
22109 | if (support_interwork) flags |= F_INTERWORK; | |
22110 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 22111 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 22112 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
22113 | flags |= F_SOFT_FLOAT; |
22114 | ||
d507cf36 PB |
22115 | switch (mfloat_abi_opt) |
22116 | { | |
22117 | case ARM_FLOAT_ABI_SOFT: | |
22118 | case ARM_FLOAT_ABI_SOFTFP: | |
22119 | flags |= F_SOFT_FLOAT; | |
22120 | break; | |
33a392fb | 22121 | |
d507cf36 PB |
22122 | case ARM_FLOAT_ABI_HARD: |
22123 | if (flags & F_SOFT_FLOAT) | |
22124 | as_bad (_("hard-float conflicts with specified fpu")); | |
22125 | break; | |
22126 | } | |
03b1477f | 22127 | |
e74cfd16 PB |
22128 | /* Using pure-endian doubles (even if soft-float). */ |
22129 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 22130 | flags |= F_VFP_FLOAT; |
f17c130b | 22131 | |
fde78edd | 22132 | #if defined OBJ_ELF |
e74cfd16 | 22133 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 22134 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
22135 | break; |
22136 | ||
8cb51566 | 22137 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 22138 | case EF_ARM_EABI_VER5: |
c19d1205 | 22139 | /* No additional flags to set. */ |
d507cf36 PB |
22140 | break; |
22141 | ||
22142 | default: | |
22143 | abort (); | |
22144 | } | |
7cc69913 | 22145 | #endif |
b99bd4ef NC |
22146 | bfd_set_private_flags (stdoutput, flags); |
22147 | ||
22148 | /* We have run out flags in the COFF header to encode the | |
22149 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 22150 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
22151 | if (atpcs) |
22152 | { | |
22153 | asection * sec; | |
22154 | ||
22155 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
22156 | ||
22157 | if (sec != NULL) | |
22158 | { | |
22159 | bfd_set_section_flags | |
22160 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
22161 | bfd_set_section_size (stdoutput, sec, 0); | |
22162 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
22163 | } | |
22164 | } | |
7cc69913 | 22165 | } |
f17c130b | 22166 | #endif |
b99bd4ef NC |
22167 | |
22168 | /* Record the CPU type as well. */ | |
2d447fca JM |
22169 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
22170 | mach = bfd_mach_arm_iWMMXt2; | |
22171 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 22172 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 22173 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 22174 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 22175 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 22176 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 22177 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 22178 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 22179 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 22180 | { |
e74cfd16 | 22181 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
22182 | mach = bfd_mach_arm_5T; |
22183 | else | |
22184 | mach = bfd_mach_arm_5; | |
22185 | } | |
e74cfd16 | 22186 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 22187 | { |
e74cfd16 | 22188 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
22189 | mach = bfd_mach_arm_4T; |
22190 | else | |
22191 | mach = bfd_mach_arm_4; | |
22192 | } | |
e74cfd16 | 22193 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 22194 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
22195 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
22196 | mach = bfd_mach_arm_3; | |
22197 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
22198 | mach = bfd_mach_arm_2a; | |
22199 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
22200 | mach = bfd_mach_arm_2; | |
22201 | else | |
22202 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
22203 | |
22204 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
22205 | } | |
22206 | ||
c19d1205 | 22207 | /* Command line processing. */ |
b99bd4ef | 22208 | |
c19d1205 ZW |
22209 | /* md_parse_option |
22210 | Invocation line includes a switch not recognized by the base assembler. | |
22211 | See if it's a processor-specific option. | |
b99bd4ef | 22212 | |
c19d1205 ZW |
22213 | This routine is somewhat complicated by the need for backwards |
22214 | compatibility (since older releases of gcc can't be changed). | |
22215 | The new options try to make the interface as compatible as | |
22216 | possible with GCC. | |
b99bd4ef | 22217 | |
c19d1205 | 22218 | New options (supported) are: |
b99bd4ef | 22219 | |
c19d1205 ZW |
22220 | -mcpu=<cpu name> Assemble for selected processor |
22221 | -march=<architecture name> Assemble for selected architecture | |
22222 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
22223 | -EB/-mbig-endian Big-endian | |
22224 | -EL/-mlittle-endian Little-endian | |
22225 | -k Generate PIC code | |
22226 | -mthumb Start in Thumb mode | |
22227 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 22228 | |
278df34e | 22229 | -m[no-]warn-deprecated Warn about deprecated features |
267bf995 | 22230 | |
c19d1205 | 22231 | For now we will also provide support for: |
b99bd4ef | 22232 | |
c19d1205 ZW |
22233 | -mapcs-32 32-bit Program counter |
22234 | -mapcs-26 26-bit Program counter | |
22235 | -macps-float Floats passed in FP registers | |
22236 | -mapcs-reentrant Reentrant code | |
22237 | -matpcs | |
22238 | (sometime these will probably be replaced with -mapcs=<list of options> | |
22239 | and -matpcs=<list of options>) | |
b99bd4ef | 22240 | |
c19d1205 ZW |
22241 | The remaining options are only supported for back-wards compatibility. |
22242 | Cpu variants, the arm part is optional: | |
22243 | -m[arm]1 Currently not supported. | |
22244 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
22245 | -m[arm]3 Arm 3 processor | |
22246 | -m[arm]6[xx], Arm 6 processors | |
22247 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
22248 | -m[arm]8[10] Arm 8 processors | |
22249 | -m[arm]9[20][tdmi] Arm 9 processors | |
22250 | -mstrongarm[110[0]] StrongARM processors | |
22251 | -mxscale XScale processors | |
22252 | -m[arm]v[2345[t[e]]] Arm architectures | |
22253 | -mall All (except the ARM1) | |
22254 | FP variants: | |
22255 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
22256 | -mfpe-old (No float load/store multiples) | |
22257 | -mvfpxd VFP Single precision | |
22258 | -mvfp All VFP | |
22259 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 22260 | |
c19d1205 ZW |
22261 | The following CPU names are recognized: |
22262 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
22263 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
22264 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
22265 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
22266 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
22267 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
22268 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 22269 | |
c19d1205 | 22270 | */ |
b99bd4ef | 22271 | |
c19d1205 | 22272 | const char * md_shortopts = "m:k"; |
b99bd4ef | 22273 | |
c19d1205 ZW |
22274 | #ifdef ARM_BI_ENDIAN |
22275 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
22276 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 22277 | #else |
c19d1205 ZW |
22278 | #if TARGET_BYTES_BIG_ENDIAN |
22279 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 22280 | #else |
c19d1205 ZW |
22281 | #define OPTION_EL (OPTION_MD_BASE + 1) |
22282 | #endif | |
b99bd4ef | 22283 | #endif |
845b51d6 | 22284 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 22285 | |
c19d1205 | 22286 | struct option md_longopts[] = |
b99bd4ef | 22287 | { |
c19d1205 ZW |
22288 | #ifdef OPTION_EB |
22289 | {"EB", no_argument, NULL, OPTION_EB}, | |
22290 | #endif | |
22291 | #ifdef OPTION_EL | |
22292 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 22293 | #endif |
845b51d6 | 22294 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
22295 | {NULL, no_argument, NULL, 0} |
22296 | }; | |
b99bd4ef | 22297 | |
c19d1205 | 22298 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 22299 | |
c19d1205 | 22300 | struct arm_option_table |
b99bd4ef | 22301 | { |
c19d1205 ZW |
22302 | char *option; /* Option name to match. */ |
22303 | char *help; /* Help information. */ | |
22304 | int *var; /* Variable to change. */ | |
22305 | int value; /* What to change it to. */ | |
22306 | char *deprecated; /* If non-null, print this message. */ | |
22307 | }; | |
b99bd4ef | 22308 | |
c19d1205 ZW |
22309 | struct arm_option_table arm_opts[] = |
22310 | { | |
22311 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
22312 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
22313 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
22314 | &support_interwork, 1, NULL}, | |
22315 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
22316 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
22317 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
22318 | 1, NULL}, | |
22319 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
22320 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
22321 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
22322 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
22323 | NULL}, | |
b99bd4ef | 22324 | |
c19d1205 ZW |
22325 | /* These are recognized by the assembler, but have no affect on code. */ |
22326 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
22327 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
22328 | |
22329 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
22330 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
22331 | &warn_on_deprecated, 0, NULL}, | |
e74cfd16 PB |
22332 | {NULL, NULL, NULL, 0, NULL} |
22333 | }; | |
22334 | ||
22335 | struct arm_legacy_option_table | |
22336 | { | |
22337 | char *option; /* Option name to match. */ | |
22338 | const arm_feature_set **var; /* Variable to change. */ | |
22339 | const arm_feature_set value; /* What to change it to. */ | |
22340 | char *deprecated; /* If non-null, print this message. */ | |
22341 | }; | |
b99bd4ef | 22342 | |
e74cfd16 PB |
22343 | const struct arm_legacy_option_table arm_legacy_opts[] = |
22344 | { | |
c19d1205 ZW |
22345 | /* DON'T add any new processors to this list -- we want the whole list |
22346 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
22347 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
22348 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
22349 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
22350 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
22351 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
22352 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
22353 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
22354 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
22355 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
22356 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
22357 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
22358 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
22359 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
22360 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
22361 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
22362 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
22363 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
22364 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
22365 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
22366 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
22367 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
22368 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
22369 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
22370 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
22371 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
22372 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
22373 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
22374 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
22375 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
22376 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
22377 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
22378 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
22379 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
22380 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
22381 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
22382 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
22383 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
22384 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
22385 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
22386 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
22387 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
22388 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
22389 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
22390 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
22391 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
22392 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
22393 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
22394 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
22395 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
22396 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
22397 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
22398 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
22399 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
22400 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
22401 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
22402 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
22403 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
22404 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
22405 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
22406 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
22407 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
22408 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
22409 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
22410 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
22411 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
22412 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
22413 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
22414 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
22415 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
22416 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 22417 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 22418 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 22419 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 22420 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 22421 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
22422 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
22423 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
22424 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 22425 | |
c19d1205 | 22426 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
22427 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
22428 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
22429 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
22430 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
22431 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
22432 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
22433 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
22434 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
22435 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
22436 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
22437 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
22438 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
22439 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
22440 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
22441 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
22442 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
22443 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
22444 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 22445 | |
c19d1205 | 22446 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
22447 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
22448 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
22449 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
22450 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 22451 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 22452 | |
e74cfd16 | 22453 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 22454 | }; |
7ed4c4c5 | 22455 | |
c19d1205 | 22456 | struct arm_cpu_option_table |
7ed4c4c5 | 22457 | { |
c19d1205 | 22458 | char *name; |
e74cfd16 | 22459 | const arm_feature_set value; |
c19d1205 ZW |
22460 | /* For some CPUs we assume an FPU unless the user explicitly sets |
22461 | -mfpu=... */ | |
e74cfd16 | 22462 | const arm_feature_set default_fpu; |
ee065d83 PB |
22463 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
22464 | case. */ | |
22465 | const char *canonical_name; | |
c19d1205 | 22466 | }; |
7ed4c4c5 | 22467 | |
c19d1205 ZW |
22468 | /* This list should, at a minimum, contain all the cpu names |
22469 | recognized by GCC. */ | |
e74cfd16 | 22470 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 22471 | { |
ee065d83 PB |
22472 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
22473 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
22474 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
22475 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
22476 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
22477 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22478 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22479 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22480 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22481 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22482 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22483 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
22484 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22485 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
22486 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22487 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
22488 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22489 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22490 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22491 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22492 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22493 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22494 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22495 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22496 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22497 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22498 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22499 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
22500 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22501 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22502 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22503 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22504 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22505 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22506 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22507 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22508 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22509 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
22510 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22511 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
22512 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22513 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22514 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
22515 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
7fac0536 NC |
22516 | {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, |
22517 | {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
22518 | /* For V5 or later processors we default to using VFP; but the user |
22519 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
22520 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
22521 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22522 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
22523 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
22524 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
22525 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
22526 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
22527 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22528 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
22529 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
22530 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22531 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22532 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
22533 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
22534 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22535 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
22536 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
22537 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22538 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
22539 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
22540 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
7fac0536 NC |
22541 | {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL}, |
22542 | {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
ee065d83 PB |
22543 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, |
22544 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
22545 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
22546 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
4ff9b924 MGD |
22547 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"}, |
22548 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"}, | |
ee065d83 PB |
22549 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, |
22550 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
22551 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
22552 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
f4c65163 MGD |
22553 | {"cortex-a5", ARM_ARCH_V7A_MP_SEC, |
22554 | FPU_NONE, "Cortex-A5"}, | |
22555 | {"cortex-a8", ARM_ARCH_V7A_SEC, | |
22556 | ARM_FEATURE (0, FPU_VFP_V3 | |
5287ad62 | 22557 | | FPU_NEON_EXT_V1), |
4ff9b924 | 22558 | "Cortex-A8"}, |
f4c65163 MGD |
22559 | {"cortex-a9", ARM_ARCH_V7A_MP_SEC, |
22560 | ARM_FEATURE (0, FPU_VFP_V3 | |
15290f0a | 22561 | | FPU_NEON_EXT_V1), |
4ff9b924 | 22562 | "Cortex-A9"}, |
90ec0d68 | 22563 | {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT, |
eea54501 | 22564 | FPU_ARCH_NEON_VFP_V4, |
dbb1f804 | 22565 | "Cortex-A15"}, |
4ff9b924 MGD |
22566 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"}, |
22567 | {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, | |
22568 | "Cortex-R4F"}, | |
22569 | {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"}, | |
22570 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"}, | |
b2a5fbdc MGD |
22571 | {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"}, |
22572 | {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"}, | |
c19d1205 | 22573 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 22574 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 22575 | /* ??? iwmmxt is not a processor. */ |
ee065d83 | 22576 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
2d447fca | 22577 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL}, |
ee065d83 | 22578 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 22579 | /* Maverick */ |
e07e6e58 | 22580 | {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
e74cfd16 | 22581 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} |
c19d1205 | 22582 | }; |
7ed4c4c5 | 22583 | |
c19d1205 | 22584 | struct arm_arch_option_table |
7ed4c4c5 | 22585 | { |
c19d1205 | 22586 | char *name; |
e74cfd16 PB |
22587 | const arm_feature_set value; |
22588 | const arm_feature_set default_fpu; | |
c19d1205 | 22589 | }; |
7ed4c4c5 | 22590 | |
c19d1205 ZW |
22591 | /* This list should, at a minimum, contain all the architecture names |
22592 | recognized by GCC. */ | |
e74cfd16 | 22593 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
22594 | { |
22595 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
22596 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
22597 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
22598 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
22599 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
22600 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
22601 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
22602 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
22603 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
22604 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
22605 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
22606 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
22607 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
22608 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
22609 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
22610 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
22611 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
22612 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
22613 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
22614 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
22615 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
22616 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
22617 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
22618 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
22619 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
22620 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
7e806470 | 22621 | {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP}, |
b2a5fbdc | 22622 | {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP}, |
62b3e311 | 22623 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
c450d570 PB |
22624 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
22625 | Accept the non-dashed form for compatibility with old toolchains. */ | |
62b3e311 PB |
22626 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
22627 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
22628 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c450d570 PB |
22629 | {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
22630 | {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
22631 | {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
9e3c6df6 | 22632 | {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP}, |
c19d1205 ZW |
22633 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
22634 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
2d447fca | 22635 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP}, |
e74cfd16 | 22636 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 22637 | }; |
7ed4c4c5 | 22638 | |
69133863 MGD |
22639 | /* ISA extensions in the co-processor and main instruction set space. */ |
22640 | struct arm_option_extension_value_table | |
c19d1205 ZW |
22641 | { |
22642 | char *name; | |
e74cfd16 | 22643 | const arm_feature_set value; |
69133863 | 22644 | const arm_feature_set allowed_archs; |
c19d1205 | 22645 | }; |
7ed4c4c5 | 22646 | |
69133863 MGD |
22647 | /* The following table must be in alphabetical order with a NULL last entry. |
22648 | */ | |
22649 | static const struct arm_option_extension_value_table arm_extensions[] = | |
c19d1205 | 22650 | { |
eea54501 MGD |
22651 | {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0), |
22652 | ARM_FEATURE (ARM_EXT_V7A, 0)}, | |
69133863 MGD |
22653 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY}, |
22654 | {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY}, | |
22655 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY}, | |
60e5ef9f MGD |
22656 | {"mp", ARM_FEATURE (ARM_EXT_MP, 0), |
22657 | ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)}, | |
b2a5fbdc MGD |
22658 | {"os", ARM_FEATURE (ARM_EXT_OS, 0), |
22659 | ARM_FEATURE (ARM_EXT_V6M, 0)}, | |
f4c65163 MGD |
22660 | {"sec", ARM_FEATURE (ARM_EXT_SEC, 0), |
22661 | ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)}, | |
90ec0d68 MGD |
22662 | {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0), |
22663 | ARM_FEATURE (ARM_EXT_V7A, 0)}, | |
69133863 | 22664 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY}, |
60e5ef9f | 22665 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
69133863 MGD |
22666 | }; |
22667 | ||
22668 | /* ISA floating-point and Advanced SIMD extensions. */ | |
22669 | struct arm_option_fpu_value_table | |
22670 | { | |
22671 | char *name; | |
22672 | const arm_feature_set value; | |
c19d1205 | 22673 | }; |
7ed4c4c5 | 22674 | |
c19d1205 ZW |
22675 | /* This list should, at a minimum, contain all the fpu names |
22676 | recognized by GCC. */ | |
69133863 | 22677 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
22678 | { |
22679 | {"softfpa", FPU_NONE}, | |
22680 | {"fpe", FPU_ARCH_FPE}, | |
22681 | {"fpe2", FPU_ARCH_FPE}, | |
22682 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
22683 | {"fpa", FPU_ARCH_FPA}, | |
22684 | {"fpa10", FPU_ARCH_FPA}, | |
22685 | {"fpa11", FPU_ARCH_FPA}, | |
22686 | {"arm7500fe", FPU_ARCH_FPA}, | |
22687 | {"softvfp", FPU_ARCH_VFP}, | |
22688 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
22689 | {"vfp", FPU_ARCH_VFP_V2}, | |
22690 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 22691 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
22692 | {"vfp10", FPU_ARCH_VFP_V2}, |
22693 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
22694 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
22695 | {"vfpv2", FPU_ARCH_VFP_V2}, |
22696 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 22697 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 22698 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
22699 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
22700 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
22701 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
22702 | {"arm1020t", FPU_ARCH_VFP_V1}, |
22703 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
22704 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
22705 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
22706 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 22707 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 22708 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
22709 | {"vfpv4", FPU_ARCH_VFP_V4}, |
22710 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 22711 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
62f3b8c8 | 22712 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
e74cfd16 PB |
22713 | {NULL, ARM_ARCH_NONE} |
22714 | }; | |
22715 | ||
22716 | struct arm_option_value_table | |
22717 | { | |
22718 | char *name; | |
22719 | long value; | |
c19d1205 | 22720 | }; |
7ed4c4c5 | 22721 | |
e74cfd16 | 22722 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
22723 | { |
22724 | {"hard", ARM_FLOAT_ABI_HARD}, | |
22725 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
22726 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 22727 | {NULL, 0} |
c19d1205 | 22728 | }; |
7ed4c4c5 | 22729 | |
c19d1205 | 22730 | #ifdef OBJ_ELF |
3a4a14e9 | 22731 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 22732 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
22733 | { |
22734 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
22735 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 22736 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 22737 | {NULL, 0} |
c19d1205 ZW |
22738 | }; |
22739 | #endif | |
7ed4c4c5 | 22740 | |
c19d1205 ZW |
22741 | struct arm_long_option_table |
22742 | { | |
22743 | char * option; /* Substring to match. */ | |
22744 | char * help; /* Help information. */ | |
22745 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
22746 | char * deprecated; /* If non-null, print this message. */ | |
22747 | }; | |
7ed4c4c5 | 22748 | |
c921be7d | 22749 | static bfd_boolean |
e74cfd16 | 22750 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 22751 | { |
21d799b5 NC |
22752 | arm_feature_set *ext_set = (arm_feature_set *) |
22753 | xmalloc (sizeof (arm_feature_set)); | |
e74cfd16 | 22754 | |
69133863 MGD |
22755 | /* We insist on extensions being specified in alphabetical order, and with |
22756 | extensions being added before being removed. We achieve this by having | |
22757 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
22758 | ADDING_VALUE variable to indicate whether we are adding an extension (1) | |
22759 | or removing it (0) and only allowing it to change in the order | |
22760 | -1 -> 1 -> 0. */ | |
22761 | const struct arm_option_extension_value_table * opt = NULL; | |
22762 | int adding_value = -1; | |
22763 | ||
e74cfd16 PB |
22764 | /* Copy the feature set, so that we can modify it. */ |
22765 | *ext_set = **opt_p; | |
22766 | *opt_p = ext_set; | |
22767 | ||
c19d1205 | 22768 | while (str != NULL && *str != 0) |
7ed4c4c5 | 22769 | { |
c19d1205 | 22770 | char * ext; |
69133863 | 22771 | size_t optlen; |
7ed4c4c5 | 22772 | |
c19d1205 ZW |
22773 | if (*str != '+') |
22774 | { | |
22775 | as_bad (_("invalid architectural extension")); | |
c921be7d | 22776 | return FALSE; |
c19d1205 | 22777 | } |
7ed4c4c5 | 22778 | |
c19d1205 ZW |
22779 | str++; |
22780 | ext = strchr (str, '+'); | |
7ed4c4c5 | 22781 | |
c19d1205 ZW |
22782 | if (ext != NULL) |
22783 | optlen = ext - str; | |
22784 | else | |
22785 | optlen = strlen (str); | |
7ed4c4c5 | 22786 | |
69133863 MGD |
22787 | if (optlen >= 2 |
22788 | && strncmp (str, "no", 2) == 0) | |
22789 | { | |
22790 | if (adding_value != 0) | |
22791 | { | |
22792 | adding_value = 0; | |
22793 | opt = arm_extensions; | |
22794 | } | |
22795 | ||
22796 | optlen -= 2; | |
22797 | str += 2; | |
22798 | } | |
22799 | else if (optlen > 0) | |
22800 | { | |
22801 | if (adding_value == -1) | |
22802 | { | |
22803 | adding_value = 1; | |
22804 | opt = arm_extensions; | |
22805 | } | |
22806 | else if (adding_value != 1) | |
22807 | { | |
22808 | as_bad (_("must specify extensions to add before specifying " | |
22809 | "those to remove")); | |
22810 | return FALSE; | |
22811 | } | |
22812 | } | |
22813 | ||
c19d1205 ZW |
22814 | if (optlen == 0) |
22815 | { | |
22816 | as_bad (_("missing architectural extension")); | |
c921be7d | 22817 | return FALSE; |
c19d1205 | 22818 | } |
7ed4c4c5 | 22819 | |
69133863 MGD |
22820 | gas_assert (adding_value != -1); |
22821 | gas_assert (opt != NULL); | |
22822 | ||
22823 | /* Scan over the options table trying to find an exact match. */ | |
22824 | for (; opt->name != NULL; opt++) | |
22825 | if (strncmp (opt->name, str, optlen) == 0 | |
22826 | && strlen (opt->name) == optlen) | |
c19d1205 | 22827 | { |
69133863 MGD |
22828 | /* Check we can apply the extension to this architecture. */ |
22829 | if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs)) | |
22830 | { | |
22831 | as_bad (_("extension does not apply to the base architecture")); | |
22832 | return FALSE; | |
22833 | } | |
22834 | ||
22835 | /* Add or remove the extension. */ | |
22836 | if (adding_value) | |
22837 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); | |
22838 | else | |
22839 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value); | |
22840 | ||
c19d1205 ZW |
22841 | break; |
22842 | } | |
7ed4c4c5 | 22843 | |
c19d1205 ZW |
22844 | if (opt->name == NULL) |
22845 | { | |
69133863 MGD |
22846 | /* Did we fail to find an extension because it wasn't specified in |
22847 | alphabetical order, or because it does not exist? */ | |
22848 | ||
22849 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
22850 | if (strncmp (opt->name, str, optlen) == 0) | |
22851 | break; | |
22852 | ||
22853 | if (opt->name == NULL) | |
22854 | as_bad (_("unknown architectural extension `%s'"), str); | |
22855 | else | |
22856 | as_bad (_("architectural extensions must be specified in " | |
22857 | "alphabetical order")); | |
22858 | ||
c921be7d | 22859 | return FALSE; |
c19d1205 | 22860 | } |
69133863 MGD |
22861 | else |
22862 | { | |
22863 | /* We should skip the extension we've just matched the next time | |
22864 | round. */ | |
22865 | opt++; | |
22866 | } | |
7ed4c4c5 | 22867 | |
c19d1205 ZW |
22868 | str = ext; |
22869 | }; | |
7ed4c4c5 | 22870 | |
c921be7d | 22871 | return TRUE; |
c19d1205 | 22872 | } |
7ed4c4c5 | 22873 | |
c921be7d | 22874 | static bfd_boolean |
c19d1205 | 22875 | arm_parse_cpu (char * str) |
7ed4c4c5 | 22876 | { |
e74cfd16 | 22877 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
22878 | char * ext = strchr (str, '+'); |
22879 | int optlen; | |
7ed4c4c5 | 22880 | |
c19d1205 ZW |
22881 | if (ext != NULL) |
22882 | optlen = ext - str; | |
7ed4c4c5 | 22883 | else |
c19d1205 | 22884 | optlen = strlen (str); |
7ed4c4c5 | 22885 | |
c19d1205 | 22886 | if (optlen == 0) |
7ed4c4c5 | 22887 | { |
c19d1205 | 22888 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 22889 | return FALSE; |
7ed4c4c5 NC |
22890 | } |
22891 | ||
c19d1205 ZW |
22892 | for (opt = arm_cpus; opt->name != NULL; opt++) |
22893 | if (strncmp (opt->name, str, optlen) == 0) | |
22894 | { | |
e74cfd16 PB |
22895 | mcpu_cpu_opt = &opt->value; |
22896 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 22897 | if (opt->canonical_name) |
5f4273c7 | 22898 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22899 | else |
22900 | { | |
22901 | int i; | |
c921be7d | 22902 | |
ee065d83 PB |
22903 | for (i = 0; i < optlen; i++) |
22904 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22905 | selected_cpu_name[i] = 0; | |
22906 | } | |
7ed4c4c5 | 22907 | |
c19d1205 ZW |
22908 | if (ext != NULL) |
22909 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 22910 | |
c921be7d | 22911 | return TRUE; |
c19d1205 | 22912 | } |
7ed4c4c5 | 22913 | |
c19d1205 | 22914 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 22915 | return FALSE; |
7ed4c4c5 NC |
22916 | } |
22917 | ||
c921be7d | 22918 | static bfd_boolean |
c19d1205 | 22919 | arm_parse_arch (char * str) |
7ed4c4c5 | 22920 | { |
e74cfd16 | 22921 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
22922 | char *ext = strchr (str, '+'); |
22923 | int optlen; | |
7ed4c4c5 | 22924 | |
c19d1205 ZW |
22925 | if (ext != NULL) |
22926 | optlen = ext - str; | |
7ed4c4c5 | 22927 | else |
c19d1205 | 22928 | optlen = strlen (str); |
7ed4c4c5 | 22929 | |
c19d1205 | 22930 | if (optlen == 0) |
7ed4c4c5 | 22931 | { |
c19d1205 | 22932 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 22933 | return FALSE; |
7ed4c4c5 NC |
22934 | } |
22935 | ||
c19d1205 | 22936 | for (opt = arm_archs; opt->name != NULL; opt++) |
69133863 | 22937 | if (strncmp (opt->name, str, optlen) == 0) |
c19d1205 | 22938 | { |
e74cfd16 PB |
22939 | march_cpu_opt = &opt->value; |
22940 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 22941 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 22942 | |
c19d1205 ZW |
22943 | if (ext != NULL) |
22944 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 22945 | |
c921be7d | 22946 | return TRUE; |
c19d1205 ZW |
22947 | } |
22948 | ||
22949 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 22950 | return FALSE; |
7ed4c4c5 | 22951 | } |
eb043451 | 22952 | |
c921be7d | 22953 | static bfd_boolean |
c19d1205 ZW |
22954 | arm_parse_fpu (char * str) |
22955 | { | |
69133863 | 22956 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 22957 | |
c19d1205 ZW |
22958 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22959 | if (streq (opt->name, str)) | |
22960 | { | |
e74cfd16 | 22961 | mfpu_opt = &opt->value; |
c921be7d | 22962 | return TRUE; |
c19d1205 | 22963 | } |
b99bd4ef | 22964 | |
c19d1205 | 22965 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 22966 | return FALSE; |
c19d1205 ZW |
22967 | } |
22968 | ||
c921be7d | 22969 | static bfd_boolean |
c19d1205 | 22970 | arm_parse_float_abi (char * str) |
b99bd4ef | 22971 | { |
e74cfd16 | 22972 | const struct arm_option_value_table * opt; |
b99bd4ef | 22973 | |
c19d1205 ZW |
22974 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
22975 | if (streq (opt->name, str)) | |
22976 | { | |
22977 | mfloat_abi_opt = opt->value; | |
c921be7d | 22978 | return TRUE; |
c19d1205 | 22979 | } |
cc8a6dd0 | 22980 | |
c19d1205 | 22981 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 22982 | return FALSE; |
c19d1205 | 22983 | } |
b99bd4ef | 22984 | |
c19d1205 | 22985 | #ifdef OBJ_ELF |
c921be7d | 22986 | static bfd_boolean |
c19d1205 ZW |
22987 | arm_parse_eabi (char * str) |
22988 | { | |
e74cfd16 | 22989 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 22990 | |
c19d1205 ZW |
22991 | for (opt = arm_eabis; opt->name != NULL; opt++) |
22992 | if (streq (opt->name, str)) | |
22993 | { | |
22994 | meabi_flags = opt->value; | |
c921be7d | 22995 | return TRUE; |
c19d1205 ZW |
22996 | } |
22997 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 22998 | return FALSE; |
c19d1205 ZW |
22999 | } |
23000 | #endif | |
cc8a6dd0 | 23001 | |
c921be7d | 23002 | static bfd_boolean |
e07e6e58 NC |
23003 | arm_parse_it_mode (char * str) |
23004 | { | |
c921be7d | 23005 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
23006 | |
23007 | if (streq ("arm", str)) | |
23008 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
23009 | else if (streq ("thumb", str)) | |
23010 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
23011 | else if (streq ("always", str)) | |
23012 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
23013 | else if (streq ("never", str)) | |
23014 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
23015 | else | |
23016 | { | |
23017 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
23018 | "arm, thumb, always, or never."), str); | |
c921be7d | 23019 | ret = FALSE; |
e07e6e58 NC |
23020 | } |
23021 | ||
23022 | return ret; | |
23023 | } | |
23024 | ||
c19d1205 ZW |
23025 | struct arm_long_option_table arm_long_opts[] = |
23026 | { | |
23027 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
23028 | arm_parse_cpu, NULL}, | |
23029 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
23030 | arm_parse_arch, NULL}, | |
23031 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
23032 | arm_parse_fpu, NULL}, | |
23033 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
23034 | arm_parse_float_abi, NULL}, | |
23035 | #ifdef OBJ_ELF | |
7fac0536 | 23036 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
23037 | arm_parse_eabi, NULL}, |
23038 | #endif | |
e07e6e58 NC |
23039 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
23040 | arm_parse_it_mode, NULL}, | |
c19d1205 ZW |
23041 | {NULL, NULL, 0, NULL} |
23042 | }; | |
cc8a6dd0 | 23043 | |
c19d1205 ZW |
23044 | int |
23045 | md_parse_option (int c, char * arg) | |
23046 | { | |
23047 | struct arm_option_table *opt; | |
e74cfd16 | 23048 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 23049 | struct arm_long_option_table *lopt; |
b99bd4ef | 23050 | |
c19d1205 | 23051 | switch (c) |
b99bd4ef | 23052 | { |
c19d1205 ZW |
23053 | #ifdef OPTION_EB |
23054 | case OPTION_EB: | |
23055 | target_big_endian = 1; | |
23056 | break; | |
23057 | #endif | |
cc8a6dd0 | 23058 | |
c19d1205 ZW |
23059 | #ifdef OPTION_EL |
23060 | case OPTION_EL: | |
23061 | target_big_endian = 0; | |
23062 | break; | |
23063 | #endif | |
b99bd4ef | 23064 | |
845b51d6 PB |
23065 | case OPTION_FIX_V4BX: |
23066 | fix_v4bx = TRUE; | |
23067 | break; | |
23068 | ||
c19d1205 ZW |
23069 | case 'a': |
23070 | /* Listing option. Just ignore these, we don't support additional | |
23071 | ones. */ | |
23072 | return 0; | |
b99bd4ef | 23073 | |
c19d1205 ZW |
23074 | default: |
23075 | for (opt = arm_opts; opt->option != NULL; opt++) | |
23076 | { | |
23077 | if (c == opt->option[0] | |
23078 | && ((arg == NULL && opt->option[1] == 0) | |
23079 | || streq (arg, opt->option + 1))) | |
23080 | { | |
c19d1205 | 23081 | /* If the option is deprecated, tell the user. */ |
278df34e | 23082 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
23083 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
23084 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 23085 | |
c19d1205 ZW |
23086 | if (opt->var != NULL) |
23087 | *opt->var = opt->value; | |
cc8a6dd0 | 23088 | |
c19d1205 ZW |
23089 | return 1; |
23090 | } | |
23091 | } | |
b99bd4ef | 23092 | |
e74cfd16 PB |
23093 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
23094 | { | |
23095 | if (c == fopt->option[0] | |
23096 | && ((arg == NULL && fopt->option[1] == 0) | |
23097 | || streq (arg, fopt->option + 1))) | |
23098 | { | |
e74cfd16 | 23099 | /* If the option is deprecated, tell the user. */ |
278df34e | 23100 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
23101 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
23102 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
23103 | |
23104 | if (fopt->var != NULL) | |
23105 | *fopt->var = &fopt->value; | |
23106 | ||
23107 | return 1; | |
23108 | } | |
23109 | } | |
23110 | ||
c19d1205 ZW |
23111 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
23112 | { | |
23113 | /* These options are expected to have an argument. */ | |
23114 | if (c == lopt->option[0] | |
23115 | && arg != NULL | |
23116 | && strncmp (arg, lopt->option + 1, | |
23117 | strlen (lopt->option + 1)) == 0) | |
23118 | { | |
c19d1205 | 23119 | /* If the option is deprecated, tell the user. */ |
278df34e | 23120 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
23121 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
23122 | _(lopt->deprecated)); | |
b99bd4ef | 23123 | |
c19d1205 ZW |
23124 | /* Call the sup-option parser. */ |
23125 | return lopt->func (arg + strlen (lopt->option) - 1); | |
23126 | } | |
23127 | } | |
a737bd4d | 23128 | |
c19d1205 ZW |
23129 | return 0; |
23130 | } | |
a394c00f | 23131 | |
c19d1205 ZW |
23132 | return 1; |
23133 | } | |
a394c00f | 23134 | |
c19d1205 ZW |
23135 | void |
23136 | md_show_usage (FILE * fp) | |
a394c00f | 23137 | { |
c19d1205 ZW |
23138 | struct arm_option_table *opt; |
23139 | struct arm_long_option_table *lopt; | |
a394c00f | 23140 | |
c19d1205 | 23141 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 23142 | |
c19d1205 ZW |
23143 | for (opt = arm_opts; opt->option != NULL; opt++) |
23144 | if (opt->help != NULL) | |
23145 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 23146 | |
c19d1205 ZW |
23147 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
23148 | if (lopt->help != NULL) | |
23149 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 23150 | |
c19d1205 ZW |
23151 | #ifdef OPTION_EB |
23152 | fprintf (fp, _("\ | |
23153 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
23154 | #endif |
23155 | ||
c19d1205 ZW |
23156 | #ifdef OPTION_EL |
23157 | fprintf (fp, _("\ | |
23158 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 23159 | #endif |
845b51d6 PB |
23160 | |
23161 | fprintf (fp, _("\ | |
23162 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 23163 | } |
ee065d83 PB |
23164 | |
23165 | ||
23166 | #ifdef OBJ_ELF | |
62b3e311 PB |
23167 | typedef struct |
23168 | { | |
23169 | int val; | |
23170 | arm_feature_set flags; | |
23171 | } cpu_arch_ver_table; | |
23172 | ||
23173 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
23174 | least features first. */ | |
23175 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
23176 | { | |
23177 | {1, ARM_ARCH_V4}, | |
23178 | {2, ARM_ARCH_V4T}, | |
23179 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 23180 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
23181 | {4, ARM_ARCH_V5TE}, |
23182 | {5, ARM_ARCH_V5TEJ}, | |
23183 | {6, ARM_ARCH_V6}, | |
7e806470 | 23184 | {9, ARM_ARCH_V6K}, |
f4c65163 | 23185 | {7, ARM_ARCH_V6Z}, |
91e22acd | 23186 | {11, ARM_ARCH_V6M}, |
b2a5fbdc | 23187 | {12, ARM_ARCH_V6SM}, |
7e806470 | 23188 | {8, ARM_ARCH_V6T2}, |
62b3e311 PB |
23189 | {10, ARM_ARCH_V7A}, |
23190 | {10, ARM_ARCH_V7R}, | |
23191 | {10, ARM_ARCH_V7M}, | |
23192 | {0, ARM_ARCH_NONE} | |
23193 | }; | |
23194 | ||
ee3c0378 AS |
23195 | /* Set an attribute if it has not already been set by the user. */ |
23196 | static void | |
23197 | aeabi_set_attribute_int (int tag, int value) | |
23198 | { | |
23199 | if (tag < 1 | |
23200 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
23201 | || !attributes_set_explicitly[tag]) | |
23202 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
23203 | } | |
23204 | ||
23205 | static void | |
23206 | aeabi_set_attribute_string (int tag, const char *value) | |
23207 | { | |
23208 | if (tag < 1 | |
23209 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
23210 | || !attributes_set_explicitly[tag]) | |
23211 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
23212 | } | |
23213 | ||
ee065d83 PB |
23214 | /* Set the public EABI object attributes. */ |
23215 | static void | |
23216 | aeabi_set_public_attributes (void) | |
23217 | { | |
23218 | int arch; | |
90ec0d68 | 23219 | int virt_sec = 0; |
e74cfd16 | 23220 | arm_feature_set flags; |
62b3e311 PB |
23221 | arm_feature_set tmp; |
23222 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
23223 | |
23224 | /* Choose the architecture based on the capabilities of the requested cpu | |
23225 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
23226 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
23227 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
23228 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
7a1d4c38 PB |
23229 | /*Allow the user to override the reported architecture. */ |
23230 | if (object_arch) | |
23231 | { | |
23232 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
23233 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
23234 | } | |
23235 | ||
251665fc MGD |
23236 | /* We need to make sure that the attributes do not identify us as v6S-M |
23237 | when the only v6S-M feature in use is the Operating System Extensions. */ | |
23238 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os)) | |
23239 | if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only)) | |
23240 | ARM_CLEAR_FEATURE (flags, flags, arm_ext_os); | |
23241 | ||
62b3e311 PB |
23242 | tmp = flags; |
23243 | arch = 0; | |
23244 | for (p = cpu_arch_ver; p->val; p++) | |
23245 | { | |
23246 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
23247 | { | |
23248 | arch = p->val; | |
23249 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
23250 | } | |
23251 | } | |
ee065d83 | 23252 | |
9e3c6df6 PB |
23253 | /* The table lookup above finds the last architecture to contribute |
23254 | a new feature. Unfortunately, Tag13 is a subset of the union of | |
23255 | v6T2 and v7-M, so it is never seen as contributing a new feature. | |
23256 | We can not search for the last entry which is entirely used, | |
23257 | because if no CPU is specified we build up only those flags | |
23258 | actually used. Perhaps we should separate out the specified | |
23259 | and implicit cases. Avoid taking this path for -march=all by | |
23260 | checking for contradictory v7-A / v7-M features. */ | |
23261 | if (arch == 10 | |
23262 | && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a) | |
23263 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m) | |
23264 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp)) | |
23265 | arch = 13; | |
23266 | ||
ee065d83 PB |
23267 | /* Tag_CPU_name. */ |
23268 | if (selected_cpu_name[0]) | |
23269 | { | |
91d6fa6a | 23270 | char *q; |
ee065d83 | 23271 | |
91d6fa6a NC |
23272 | q = selected_cpu_name; |
23273 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
23274 | { |
23275 | int i; | |
5f4273c7 | 23276 | |
91d6fa6a NC |
23277 | q += 4; |
23278 | for (i = 0; q[i]; i++) | |
23279 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 23280 | } |
91d6fa6a | 23281 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 23282 | } |
62f3b8c8 | 23283 | |
ee065d83 | 23284 | /* Tag_CPU_arch. */ |
ee3c0378 | 23285 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 23286 | |
62b3e311 PB |
23287 | /* Tag_CPU_arch_profile. */ |
23288 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
ee3c0378 | 23289 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A'); |
62b3e311 | 23290 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
ee3c0378 | 23291 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R'); |
7e806470 | 23292 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
ee3c0378 | 23293 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M'); |
62f3b8c8 | 23294 | |
ee065d83 | 23295 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
23296 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
23297 | || arch == 0) | |
23298 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
62f3b8c8 | 23299 | |
ee065d83 | 23300 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
23301 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
23302 | || arch == 0) | |
23303 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, | |
23304 | ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1); | |
62f3b8c8 | 23305 | |
ee065d83 | 23306 | /* Tag_VFP_arch. */ |
62f3b8c8 PB |
23307 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
23308 | aeabi_set_attribute_int (Tag_VFP_arch, | |
23309 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
23310 | ? 5 : 6); | |
23311 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
ee3c0378 | 23312 | aeabi_set_attribute_int (Tag_VFP_arch, 3); |
ada65aa3 | 23313 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
ee3c0378 AS |
23314 | aeabi_set_attribute_int (Tag_VFP_arch, 4); |
23315 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) | |
23316 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
23317 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
23318 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) | |
23319 | aeabi_set_attribute_int (Tag_VFP_arch, 1); | |
62f3b8c8 | 23320 | |
4547cb56 NC |
23321 | /* Tag_ABI_HardFP_use. */ |
23322 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
23323 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
23324 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
23325 | ||
ee065d83 | 23326 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
23327 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
23328 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
23329 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
23330 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 23331 | |
ee3c0378 | 23332 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
8e79c3df | 23333 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) |
62f3b8c8 PB |
23334 | aeabi_set_attribute_int |
23335 | (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma) | |
23336 | ? 2 : 1)); | |
23337 | ||
ee3c0378 | 23338 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
62f3b8c8 | 23339 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16)) |
ee3c0378 | 23340 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 NC |
23341 | |
23342 | /* Tag_DIV_use. */ | |
eea54501 MGD |
23343 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)) |
23344 | aeabi_set_attribute_int (Tag_DIV_use, 2); | |
23345 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div)) | |
4547cb56 | 23346 | aeabi_set_attribute_int (Tag_DIV_use, 0); |
4547cb56 NC |
23347 | else |
23348 | aeabi_set_attribute_int (Tag_DIV_use, 1); | |
60e5ef9f MGD |
23349 | |
23350 | /* Tag_MP_extension_use. */ | |
23351 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
23352 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
23353 | |
23354 | /* Tag Virtualization_use. */ | |
23355 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
23356 | virt_sec |= 1; |
23357 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
23358 | virt_sec |= 2; | |
23359 | if (virt_sec != 0) | |
23360 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
ee065d83 PB |
23361 | } |
23362 | ||
104d59d1 | 23363 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
23364 | void |
23365 | arm_md_end (void) | |
23366 | { | |
ee065d83 PB |
23367 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
23368 | return; | |
23369 | ||
23370 | aeabi_set_public_attributes (); | |
ee065d83 | 23371 | } |
8463be01 | 23372 | #endif /* OBJ_ELF */ |
ee065d83 PB |
23373 | |
23374 | ||
23375 | /* Parse a .cpu directive. */ | |
23376 | ||
23377 | static void | |
23378 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
23379 | { | |
e74cfd16 | 23380 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
23381 | char *name; |
23382 | char saved_char; | |
23383 | ||
23384 | name = input_line_pointer; | |
5f4273c7 | 23385 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
23386 | input_line_pointer++; |
23387 | saved_char = *input_line_pointer; | |
23388 | *input_line_pointer = 0; | |
23389 | ||
23390 | /* Skip the first "all" entry. */ | |
23391 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
23392 | if (streq (opt->name, name)) | |
23393 | { | |
e74cfd16 PB |
23394 | mcpu_cpu_opt = &opt->value; |
23395 | selected_cpu = opt->value; | |
ee065d83 | 23396 | if (opt->canonical_name) |
5f4273c7 | 23397 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
23398 | else |
23399 | { | |
23400 | int i; | |
23401 | for (i = 0; opt->name[i]; i++) | |
23402 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
23403 | selected_cpu_name[i] = 0; | |
23404 | } | |
e74cfd16 | 23405 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
23406 | *input_line_pointer = saved_char; |
23407 | demand_empty_rest_of_line (); | |
23408 | return; | |
23409 | } | |
23410 | as_bad (_("unknown cpu `%s'"), name); | |
23411 | *input_line_pointer = saved_char; | |
23412 | ignore_rest_of_line (); | |
23413 | } | |
23414 | ||
23415 | ||
23416 | /* Parse a .arch directive. */ | |
23417 | ||
23418 | static void | |
23419 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
23420 | { | |
e74cfd16 | 23421 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
23422 | char saved_char; |
23423 | char *name; | |
23424 | ||
23425 | name = input_line_pointer; | |
5f4273c7 | 23426 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
23427 | input_line_pointer++; |
23428 | saved_char = *input_line_pointer; | |
23429 | *input_line_pointer = 0; | |
23430 | ||
23431 | /* Skip the first "all" entry. */ | |
23432 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
23433 | if (streq (opt->name, name)) | |
23434 | { | |
e74cfd16 PB |
23435 | mcpu_cpu_opt = &opt->value; |
23436 | selected_cpu = opt->value; | |
5f4273c7 | 23437 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 23438 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
23439 | *input_line_pointer = saved_char; |
23440 | demand_empty_rest_of_line (); | |
23441 | return; | |
23442 | } | |
23443 | ||
23444 | as_bad (_("unknown architecture `%s'\n"), name); | |
23445 | *input_line_pointer = saved_char; | |
23446 | ignore_rest_of_line (); | |
23447 | } | |
23448 | ||
23449 | ||
7a1d4c38 PB |
23450 | /* Parse a .object_arch directive. */ |
23451 | ||
23452 | static void | |
23453 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
23454 | { | |
23455 | const struct arm_arch_option_table *opt; | |
23456 | char saved_char; | |
23457 | char *name; | |
23458 | ||
23459 | name = input_line_pointer; | |
5f4273c7 | 23460 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
23461 | input_line_pointer++; |
23462 | saved_char = *input_line_pointer; | |
23463 | *input_line_pointer = 0; | |
23464 | ||
23465 | /* Skip the first "all" entry. */ | |
23466 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
23467 | if (streq (opt->name, name)) | |
23468 | { | |
23469 | object_arch = &opt->value; | |
23470 | *input_line_pointer = saved_char; | |
23471 | demand_empty_rest_of_line (); | |
23472 | return; | |
23473 | } | |
23474 | ||
23475 | as_bad (_("unknown architecture `%s'\n"), name); | |
23476 | *input_line_pointer = saved_char; | |
23477 | ignore_rest_of_line (); | |
23478 | } | |
23479 | ||
69133863 MGD |
23480 | /* Parse a .arch_extension directive. */ |
23481 | ||
23482 | static void | |
23483 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
23484 | { | |
23485 | const struct arm_option_extension_value_table *opt; | |
23486 | char saved_char; | |
23487 | char *name; | |
23488 | int adding_value = 1; | |
23489 | ||
23490 | name = input_line_pointer; | |
23491 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
23492 | input_line_pointer++; | |
23493 | saved_char = *input_line_pointer; | |
23494 | *input_line_pointer = 0; | |
23495 | ||
23496 | if (strlen (name) >= 2 | |
23497 | && strncmp (name, "no", 2) == 0) | |
23498 | { | |
23499 | adding_value = 0; | |
23500 | name += 2; | |
23501 | } | |
23502 | ||
23503 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
23504 | if (streq (opt->name, name)) | |
23505 | { | |
23506 | if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs)) | |
23507 | { | |
23508 | as_bad (_("architectural extension `%s' is not allowed for the " | |
23509 | "current base architecture"), name); | |
23510 | break; | |
23511 | } | |
23512 | ||
23513 | if (adding_value) | |
23514 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value); | |
23515 | else | |
23516 | ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value); | |
23517 | ||
23518 | mcpu_cpu_opt = &selected_cpu; | |
23519 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
23520 | *input_line_pointer = saved_char; | |
23521 | demand_empty_rest_of_line (); | |
23522 | return; | |
23523 | } | |
23524 | ||
23525 | if (opt->name == NULL) | |
23526 | as_bad (_("unknown architecture `%s'\n"), name); | |
23527 | ||
23528 | *input_line_pointer = saved_char; | |
23529 | ignore_rest_of_line (); | |
23530 | } | |
23531 | ||
ee065d83 PB |
23532 | /* Parse a .fpu directive. */ |
23533 | ||
23534 | static void | |
23535 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
23536 | { | |
69133863 | 23537 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
23538 | char saved_char; |
23539 | char *name; | |
23540 | ||
23541 | name = input_line_pointer; | |
5f4273c7 | 23542 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
23543 | input_line_pointer++; |
23544 | saved_char = *input_line_pointer; | |
23545 | *input_line_pointer = 0; | |
5f4273c7 | 23546 | |
ee065d83 PB |
23547 | for (opt = arm_fpus; opt->name != NULL; opt++) |
23548 | if (streq (opt->name, name)) | |
23549 | { | |
e74cfd16 PB |
23550 | mfpu_opt = &opt->value; |
23551 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
23552 | *input_line_pointer = saved_char; |
23553 | demand_empty_rest_of_line (); | |
23554 | return; | |
23555 | } | |
23556 | ||
23557 | as_bad (_("unknown floating point format `%s'\n"), name); | |
23558 | *input_line_pointer = saved_char; | |
23559 | ignore_rest_of_line (); | |
23560 | } | |
ee065d83 | 23561 | |
794ba86a | 23562 | /* Copy symbol information. */ |
f31fef98 | 23563 | |
794ba86a DJ |
23564 | void |
23565 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
23566 | { | |
23567 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
23568 | } | |
e04befd0 | 23569 | |
f31fef98 | 23570 | #ifdef OBJ_ELF |
e04befd0 AS |
23571 | /* Given a symbolic attribute NAME, return the proper integer value. |
23572 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 23573 | |
e04befd0 AS |
23574 | int |
23575 | arm_convert_symbolic_attribute (const char *name) | |
23576 | { | |
f31fef98 NC |
23577 | static const struct |
23578 | { | |
23579 | const char * name; | |
23580 | const int tag; | |
23581 | } | |
23582 | attribute_table[] = | |
23583 | { | |
23584 | /* When you modify this table you should | |
23585 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 23586 | #define T(tag) {#tag, tag} |
f31fef98 NC |
23587 | T (Tag_CPU_raw_name), |
23588 | T (Tag_CPU_name), | |
23589 | T (Tag_CPU_arch), | |
23590 | T (Tag_CPU_arch_profile), | |
23591 | T (Tag_ARM_ISA_use), | |
23592 | T (Tag_THUMB_ISA_use), | |
75375b3e | 23593 | T (Tag_FP_arch), |
f31fef98 NC |
23594 | T (Tag_VFP_arch), |
23595 | T (Tag_WMMX_arch), | |
23596 | T (Tag_Advanced_SIMD_arch), | |
23597 | T (Tag_PCS_config), | |
23598 | T (Tag_ABI_PCS_R9_use), | |
23599 | T (Tag_ABI_PCS_RW_data), | |
23600 | T (Tag_ABI_PCS_RO_data), | |
23601 | T (Tag_ABI_PCS_GOT_use), | |
23602 | T (Tag_ABI_PCS_wchar_t), | |
23603 | T (Tag_ABI_FP_rounding), | |
23604 | T (Tag_ABI_FP_denormal), | |
23605 | T (Tag_ABI_FP_exceptions), | |
23606 | T (Tag_ABI_FP_user_exceptions), | |
23607 | T (Tag_ABI_FP_number_model), | |
75375b3e | 23608 | T (Tag_ABI_align_needed), |
f31fef98 | 23609 | T (Tag_ABI_align8_needed), |
75375b3e | 23610 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
23611 | T (Tag_ABI_align8_preserved), |
23612 | T (Tag_ABI_enum_size), | |
23613 | T (Tag_ABI_HardFP_use), | |
23614 | T (Tag_ABI_VFP_args), | |
23615 | T (Tag_ABI_WMMX_args), | |
23616 | T (Tag_ABI_optimization_goals), | |
23617 | T (Tag_ABI_FP_optimization_goals), | |
23618 | T (Tag_compatibility), | |
23619 | T (Tag_CPU_unaligned_access), | |
75375b3e | 23620 | T (Tag_FP_HP_extension), |
f31fef98 NC |
23621 | T (Tag_VFP_HP_extension), |
23622 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
23623 | T (Tag_MPextension_use), |
23624 | T (Tag_DIV_use), | |
f31fef98 NC |
23625 | T (Tag_nodefaults), |
23626 | T (Tag_also_compatible_with), | |
23627 | T (Tag_conformance), | |
23628 | T (Tag_T2EE_use), | |
23629 | T (Tag_Virtualization_use), | |
cd21e546 | 23630 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 23631 | #undef T |
f31fef98 | 23632 | }; |
e04befd0 AS |
23633 | unsigned int i; |
23634 | ||
23635 | if (name == NULL) | |
23636 | return -1; | |
23637 | ||
f31fef98 | 23638 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 23639 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
23640 | return attribute_table[i].tag; |
23641 | ||
23642 | return -1; | |
23643 | } | |
267bf995 RR |
23644 | |
23645 | ||
23646 | /* Apply sym value for relocations only in the case that | |
23647 | they are for local symbols and you have the respective | |
23648 | architectural feature for blx and simple switches. */ | |
23649 | int | |
23650 | arm_apply_sym_value (struct fix * fixP) | |
23651 | { | |
23652 | if (fixP->fx_addsy | |
23653 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
23654 | && !S_IS_EXTERNAL (fixP->fx_addsy)) | |
23655 | { | |
23656 | switch (fixP->fx_r_type) | |
23657 | { | |
23658 | case BFD_RELOC_ARM_PCREL_BLX: | |
23659 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
23660 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
23661 | return 1; | |
23662 | break; | |
23663 | ||
23664 | case BFD_RELOC_ARM_PCREL_CALL: | |
23665 | case BFD_RELOC_THUMB_PCREL_BLX: | |
23666 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
23667 | return 1; | |
23668 | break; | |
23669 | ||
23670 | default: | |
23671 | break; | |
23672 | } | |
23673 | ||
23674 | } | |
23675 | return 0; | |
23676 | } | |
f31fef98 | 23677 | #endif /* OBJ_ELF */ |