Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
f17c130b | 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
f31fef98 | 3 | 2004, 2005, 2006, 2007, 2008, 2009 |
b99bd4ef NC |
4 | Free Software Foundation, Inc. |
5 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) | |
6 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 7 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
8 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
9 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
10 | |
11 | This file is part of GAS, the GNU Assembler. | |
12 | ||
13 | GAS is free software; you can redistribute it and/or modify | |
14 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 15 | the Free Software Foundation; either version 3, or (at your option) |
b99bd4ef NC |
16 | any later version. |
17 | ||
18 | GAS is distributed in the hope that it will be useful, | |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c19d1205 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
21 | GNU General Public License for more details. |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
24 | along with GAS; see the file COPYING. If not, write to the Free | |
699d2810 NC |
25 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
26 | 02110-1301, USA. */ | |
b99bd4ef | 27 | |
42a68e18 | 28 | #include "as.h" |
5287ad62 | 29 | #include <limits.h> |
037e8744 | 30 | #include <stdarg.h> |
c19d1205 | 31 | #define NO_RELOC 0 |
3882b010 | 32 | #include "safe-ctype.h" |
b99bd4ef NC |
33 | #include "subsegs.h" |
34 | #include "obstack.h" | |
b99bd4ef | 35 | |
f263249b RE |
36 | #include "opcode/arm.h" |
37 | ||
b99bd4ef NC |
38 | #ifdef OBJ_ELF |
39 | #include "elf/arm.h" | |
a394c00f | 40 | #include "dw2gencfi.h" |
b99bd4ef NC |
41 | #endif |
42 | ||
f0927246 NC |
43 | #include "dwarf2dbg.h" |
44 | ||
7ed4c4c5 NC |
45 | #ifdef OBJ_ELF |
46 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
47 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
48 | ||
49 | /* This structure holds the unwinding state. */ | |
50 | ||
51 | static struct | |
52 | { | |
c19d1205 ZW |
53 | symbolS * proc_start; |
54 | symbolS * table_entry; | |
55 | symbolS * personality_routine; | |
56 | int personality_index; | |
7ed4c4c5 | 57 | /* The segment containing the function. */ |
c19d1205 ZW |
58 | segT saved_seg; |
59 | subsegT saved_subseg; | |
7ed4c4c5 NC |
60 | /* Opcodes generated from this function. */ |
61 | unsigned char * opcodes; | |
c19d1205 ZW |
62 | int opcode_count; |
63 | int opcode_alloc; | |
7ed4c4c5 | 64 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 65 | offsetT frame_size; |
7ed4c4c5 NC |
66 | /* We don't add stack adjustment opcodes immediately so that we can merge |
67 | multiple adjustments. We can also omit the final adjustment | |
68 | when using a frame pointer. */ | |
c19d1205 | 69 | offsetT pending_offset; |
7ed4c4c5 | 70 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
71 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
72 | offsetT fp_offset; | |
73 | int fp_reg; | |
7ed4c4c5 | 74 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 75 | unsigned fp_used:1; |
7ed4c4c5 | 76 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 77 | unsigned sp_restored:1; |
7ed4c4c5 NC |
78 | } unwind; |
79 | ||
8b1ad454 NC |
80 | #endif /* OBJ_ELF */ |
81 | ||
4962c51a MS |
82 | /* Results from operand parsing worker functions. */ |
83 | ||
84 | typedef enum | |
85 | { | |
86 | PARSE_OPERAND_SUCCESS, | |
87 | PARSE_OPERAND_FAIL, | |
88 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
89 | } parse_operand_result; | |
90 | ||
33a392fb PB |
91 | enum arm_float_abi |
92 | { | |
93 | ARM_FLOAT_ABI_HARD, | |
94 | ARM_FLOAT_ABI_SOFTFP, | |
95 | ARM_FLOAT_ABI_SOFT | |
96 | }; | |
97 | ||
c19d1205 | 98 | /* Types of processor to assemble for. */ |
b99bd4ef NC |
99 | #ifndef CPU_DEFAULT |
100 | #if defined __XSCALE__ | |
e74cfd16 | 101 | #define CPU_DEFAULT ARM_ARCH_XSCALE |
b99bd4ef NC |
102 | #else |
103 | #if defined __thumb__ | |
e74cfd16 | 104 | #define CPU_DEFAULT ARM_ARCH_V5T |
b99bd4ef NC |
105 | #endif |
106 | #endif | |
107 | #endif | |
108 | ||
109 | #ifndef FPU_DEFAULT | |
c820d418 MM |
110 | # ifdef TE_LINUX |
111 | # define FPU_DEFAULT FPU_ARCH_FPA | |
112 | # elif defined (TE_NetBSD) | |
113 | # ifdef OBJ_ELF | |
114 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
115 | # else | |
116 | /* Legacy a.out format. */ | |
117 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
118 | # endif | |
4e7fd91e PB |
119 | # elif defined (TE_VXWORKS) |
120 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
121 | # else |
122 | /* For backwards compatibility, default to FPA. */ | |
123 | # define FPU_DEFAULT FPU_ARCH_FPA | |
124 | # endif | |
125 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 126 | |
c19d1205 | 127 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 128 | |
e74cfd16 PB |
129 | static arm_feature_set cpu_variant; |
130 | static arm_feature_set arm_arch_used; | |
131 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 132 | |
b99bd4ef | 133 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
134 | static int uses_apcs_26 = FALSE; |
135 | static int atpcs = FALSE; | |
b34976b6 AM |
136 | static int support_interwork = FALSE; |
137 | static int uses_apcs_float = FALSE; | |
c19d1205 | 138 | static int pic_code = FALSE; |
845b51d6 | 139 | static int fix_v4bx = FALSE; |
278df34e NS |
140 | /* Warn on using deprecated features. */ |
141 | static int warn_on_deprecated = TRUE; | |
142 | ||
03b1477f RE |
143 | |
144 | /* Variables that we set while parsing command-line options. Once all | |
145 | options have been read we re-process these values to set the real | |
146 | assembly flags. */ | |
e74cfd16 PB |
147 | static const arm_feature_set *legacy_cpu = NULL; |
148 | static const arm_feature_set *legacy_fpu = NULL; | |
149 | ||
150 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
151 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
152 | static const arm_feature_set *march_cpu_opt = NULL; | |
153 | static const arm_feature_set *march_fpu_opt = NULL; | |
154 | static const arm_feature_set *mfpu_opt = NULL; | |
7a1d4c38 | 155 | static const arm_feature_set *object_arch = NULL; |
e74cfd16 PB |
156 | |
157 | /* Constants for known architecture features. */ | |
158 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
159 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
160 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
161 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
162 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
163 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
164 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
165 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
166 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
167 | ||
168 | #ifdef CPU_DEFAULT | |
169 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
170 | #endif | |
171 | ||
172 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
173 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
174 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
175 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
176 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
177 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
178 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
179 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
180 | static const arm_feature_set arm_ext_v4t_5 = | |
181 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
182 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
183 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
184 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
185 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
186 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
187 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
188 | static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0); | |
189 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); | |
62b3e311 | 190 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
7e806470 PB |
191 | static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0); |
192 | static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0); | |
62b3e311 PB |
193 | static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0); |
194 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0); | |
195 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0); | |
196 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0); | |
7e806470 PB |
197 | static const arm_feature_set arm_ext_m = |
198 | ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0); | |
e74cfd16 PB |
199 | |
200 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
201 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
202 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
203 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
204 | ||
2d447fca JM |
205 | static const arm_feature_set arm_cext_iwmmxt2 = |
206 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2); | |
e74cfd16 PB |
207 | static const arm_feature_set arm_cext_iwmmxt = |
208 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
209 | static const arm_feature_set arm_cext_xscale = | |
210 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
211 | static const arm_feature_set arm_cext_maverick = | |
212 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
213 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
214 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
215 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
216 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
217 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
218 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
5287ad62 | 219 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
b1cc4aeb PB |
220 | static const arm_feature_set fpu_vfp_ext_d32 = |
221 | ARM_FEATURE (0, FPU_VFP_EXT_D32); | |
5287ad62 JB |
222 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); |
223 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
224 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
8e79c3df | 225 | static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16); |
e74cfd16 | 226 | |
33a392fb | 227 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
228 | /* Record user cpu selection for object attributes. */ |
229 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
230 | /* Must be long enough to hold any of the names in arm_cpus. */ |
231 | static char selected_cpu_name[16]; | |
7cc69913 | 232 | #ifdef OBJ_ELF |
deeaaff8 DJ |
233 | # ifdef EABI_DEFAULT |
234 | static int meabi_flags = EABI_DEFAULT; | |
235 | # else | |
d507cf36 | 236 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 237 | # endif |
e1da3f5b | 238 | |
ee3c0378 AS |
239 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
240 | ||
e1da3f5b | 241 | bfd_boolean |
5f4273c7 | 242 | arm_is_eabi (void) |
e1da3f5b PB |
243 | { |
244 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
245 | } | |
7cc69913 | 246 | #endif |
b99bd4ef | 247 | |
b99bd4ef | 248 | #ifdef OBJ_ELF |
c19d1205 | 249 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
250 | symbolS * GOT_symbol; |
251 | #endif | |
252 | ||
b99bd4ef NC |
253 | /* 0: assemble for ARM, |
254 | 1: assemble for Thumb, | |
255 | 2: assemble for Thumb even though target CPU does not support thumb | |
256 | instructions. */ | |
257 | static int thumb_mode = 0; | |
8dc2430f NC |
258 | /* A value distinct from the possible values for thumb_mode that we |
259 | can use to record whether thumb_mode has been copied into the | |
260 | tc_frag_data field of a frag. */ | |
261 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 262 | |
e07e6e58 NC |
263 | /* Specifies the intrinsic IT insn behavior mode. */ |
264 | enum implicit_it_mode | |
265 | { | |
266 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
267 | IMPLICIT_IT_MODE_ARM = 0x01, | |
268 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
269 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
270 | }; | |
271 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
272 | ||
c19d1205 ZW |
273 | /* If unified_syntax is true, we are processing the new unified |
274 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
275 | ||
276 | - Immediate operands do not require a # prefix. | |
277 | - Conditional affixes always appear at the end of the | |
278 | instruction. (For backward compatibility, those instructions | |
279 | that formerly had them in the middle, continue to accept them | |
280 | there.) | |
281 | - The IT instruction may appear, and if it does is validated | |
282 | against subsequent conditional affixes. It does not generate | |
283 | machine code. | |
284 | ||
285 | Important differences from the old Thumb mode: | |
286 | ||
287 | - Immediate operands do not require a # prefix. | |
288 | - Most of the V6T2 instructions are only available in unified mode. | |
289 | - The .N and .W suffixes are recognized and honored (it is an error | |
290 | if they cannot be honored). | |
291 | - All instructions set the flags if and only if they have an 's' affix. | |
292 | - Conditional affixes may be used. They are validated against | |
293 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
294 | conditional affix except in the scope of an IT instruction. */ | |
295 | ||
296 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 297 | |
5287ad62 JB |
298 | enum neon_el_type |
299 | { | |
dcbf9037 | 300 | NT_invtype, |
5287ad62 JB |
301 | NT_untyped, |
302 | NT_integer, | |
303 | NT_float, | |
304 | NT_poly, | |
305 | NT_signed, | |
dcbf9037 | 306 | NT_unsigned |
5287ad62 JB |
307 | }; |
308 | ||
309 | struct neon_type_el | |
310 | { | |
311 | enum neon_el_type type; | |
312 | unsigned size; | |
313 | }; | |
314 | ||
315 | #define NEON_MAX_TYPE_ELS 4 | |
316 | ||
317 | struct neon_type | |
318 | { | |
319 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
320 | unsigned elems; | |
321 | }; | |
322 | ||
e07e6e58 NC |
323 | enum it_instruction_type |
324 | { | |
325 | OUTSIDE_IT_INSN, | |
326 | INSIDE_IT_INSN, | |
327 | INSIDE_IT_LAST_INSN, | |
328 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
329 | if inside, should be the last one. */ | |
330 | NEUTRAL_IT_INSN, /* This could be either inside or outside, | |
331 | i.e. BKPT and NOP. */ | |
332 | IT_INSN /* The IT insn has been parsed. */ | |
333 | }; | |
334 | ||
b99bd4ef NC |
335 | struct arm_it |
336 | { | |
c19d1205 | 337 | const char * error; |
b99bd4ef | 338 | unsigned long instruction; |
c19d1205 ZW |
339 | int size; |
340 | int size_req; | |
341 | int cond; | |
037e8744 JB |
342 | /* "uncond_value" is set to the value in place of the conditional field in |
343 | unconditional versions of the instruction, or -1 if nothing is | |
344 | appropriate. */ | |
345 | int uncond_value; | |
5287ad62 | 346 | struct neon_type vectype; |
0110f2b8 PB |
347 | /* Set to the opcode if the instruction needs relaxation. |
348 | Zero if the instruction is not relaxed. */ | |
349 | unsigned long relax; | |
b99bd4ef NC |
350 | struct |
351 | { | |
352 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
353 | expressionS exp; |
354 | int pc_rel; | |
b99bd4ef | 355 | } reloc; |
b99bd4ef | 356 | |
e07e6e58 NC |
357 | enum it_instruction_type it_insn_type; |
358 | ||
c19d1205 ZW |
359 | struct |
360 | { | |
361 | unsigned reg; | |
ca3f61f7 | 362 | signed int imm; |
dcbf9037 | 363 | struct neon_type_el vectype; |
ca3f61f7 NC |
364 | unsigned present : 1; /* Operand present. */ |
365 | unsigned isreg : 1; /* Operand was a register. */ | |
366 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
367 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
368 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 369 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
370 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
371 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
372 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 373 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 374 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 375 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
376 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
377 | unsigned writeback : 1; /* Operand has trailing ! */ | |
378 | unsigned preind : 1; /* Preindexed address. */ | |
379 | unsigned postind : 1; /* Postindexed address. */ | |
380 | unsigned negative : 1; /* Index register was negated. */ | |
381 | unsigned shifted : 1; /* Shift applied to operation. */ | |
382 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 383 | } operands[6]; |
b99bd4ef NC |
384 | }; |
385 | ||
c19d1205 | 386 | static struct arm_it inst; |
b99bd4ef NC |
387 | |
388 | #define NUM_FLOAT_VALS 8 | |
389 | ||
05d2d07e | 390 | const char * fp_const[] = |
b99bd4ef NC |
391 | { |
392 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
393 | }; | |
394 | ||
c19d1205 | 395 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
396 | #define MAX_LITTLENUMS 6 |
397 | ||
398 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
399 | ||
400 | #define FAIL (-1) | |
401 | #define SUCCESS (0) | |
402 | ||
403 | #define SUFF_S 1 | |
404 | #define SUFF_D 2 | |
405 | #define SUFF_E 3 | |
406 | #define SUFF_P 4 | |
407 | ||
c19d1205 ZW |
408 | #define CP_T_X 0x00008000 |
409 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 410 | |
c19d1205 ZW |
411 | #define CONDS_BIT 0x00100000 |
412 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
413 | |
414 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
415 | ||
416 | struct asm_cond | |
417 | { | |
c921be7d NC |
418 | const char * template; |
419 | unsigned long value; | |
b99bd4ef NC |
420 | }; |
421 | ||
c19d1205 | 422 | #define COND_ALWAYS 0xE |
b99bd4ef | 423 | |
b99bd4ef NC |
424 | struct asm_psr |
425 | { | |
c921be7d NC |
426 | const char * template; |
427 | unsigned long field; | |
b99bd4ef NC |
428 | }; |
429 | ||
62b3e311 PB |
430 | struct asm_barrier_opt |
431 | { | |
c921be7d NC |
432 | const char * template; |
433 | unsigned long value; | |
62b3e311 PB |
434 | }; |
435 | ||
2d2255b5 | 436 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
437 | #define SPSR_BIT (1 << 22) |
438 | ||
c19d1205 ZW |
439 | /* The individual PSR flag bits. */ |
440 | #define PSR_c (1 << 16) | |
441 | #define PSR_x (1 << 17) | |
442 | #define PSR_s (1 << 18) | |
443 | #define PSR_f (1 << 19) | |
b99bd4ef | 444 | |
c19d1205 | 445 | struct reloc_entry |
bfae80f2 | 446 | { |
c921be7d NC |
447 | char * name; |
448 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
449 | }; |
450 | ||
5287ad62 | 451 | enum vfp_reg_pos |
bfae80f2 | 452 | { |
5287ad62 JB |
453 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
454 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
455 | }; |
456 | ||
457 | enum vfp_ldstm_type | |
458 | { | |
459 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
460 | }; | |
461 | ||
dcbf9037 JB |
462 | /* Bits for DEFINED field in neon_typed_alias. */ |
463 | #define NTA_HASTYPE 1 | |
464 | #define NTA_HASINDEX 2 | |
465 | ||
466 | struct neon_typed_alias | |
467 | { | |
c921be7d NC |
468 | unsigned char defined; |
469 | unsigned char index; | |
470 | struct neon_type_el eltype; | |
dcbf9037 JB |
471 | }; |
472 | ||
c19d1205 ZW |
473 | /* ARM register categories. This includes coprocessor numbers and various |
474 | architecture extensions' registers. */ | |
475 | enum arm_reg_type | |
bfae80f2 | 476 | { |
c19d1205 ZW |
477 | REG_TYPE_RN, |
478 | REG_TYPE_CP, | |
479 | REG_TYPE_CN, | |
480 | REG_TYPE_FN, | |
481 | REG_TYPE_VFS, | |
482 | REG_TYPE_VFD, | |
5287ad62 | 483 | REG_TYPE_NQ, |
037e8744 | 484 | REG_TYPE_VFSD, |
5287ad62 | 485 | REG_TYPE_NDQ, |
037e8744 | 486 | REG_TYPE_NSDQ, |
c19d1205 ZW |
487 | REG_TYPE_VFC, |
488 | REG_TYPE_MVF, | |
489 | REG_TYPE_MVD, | |
490 | REG_TYPE_MVFX, | |
491 | REG_TYPE_MVDX, | |
492 | REG_TYPE_MVAX, | |
493 | REG_TYPE_DSPSC, | |
494 | REG_TYPE_MMXWR, | |
495 | REG_TYPE_MMXWC, | |
496 | REG_TYPE_MMXWCG, | |
497 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
498 | }; |
499 | ||
dcbf9037 JB |
500 | /* Structure for a hash table entry for a register. |
501 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
502 | information which states whether a vector type or index is specified (for a | |
503 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
504 | struct reg_entry |
505 | { | |
c921be7d NC |
506 | const char * name; |
507 | unsigned char number; | |
508 | unsigned char type; | |
509 | unsigned char builtin; | |
510 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
511 | }; |
512 | ||
c19d1205 | 513 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 514 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
515 | { |
516 | N_("ARM register expected"), | |
517 | N_("bad or missing co-processor number"), | |
518 | N_("co-processor register expected"), | |
519 | N_("FPA register expected"), | |
520 | N_("VFP single precision register expected"), | |
5287ad62 JB |
521 | N_("VFP/Neon double precision register expected"), |
522 | N_("Neon quad precision register expected"), | |
037e8744 | 523 | N_("VFP single or double precision register expected"), |
5287ad62 | 524 | N_("Neon double or quad precision register expected"), |
037e8744 | 525 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
526 | N_("VFP system register expected"), |
527 | N_("Maverick MVF register expected"), | |
528 | N_("Maverick MVD register expected"), | |
529 | N_("Maverick MVFX register expected"), | |
530 | N_("Maverick MVDX register expected"), | |
531 | N_("Maverick MVAX register expected"), | |
532 | N_("Maverick DSPSC register expected"), | |
533 | N_("iWMMXt data register expected"), | |
534 | N_("iWMMXt control register expected"), | |
535 | N_("iWMMXt scalar register expected"), | |
536 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
537 | }; |
538 | ||
c19d1205 ZW |
539 | /* Some well known registers that we refer to directly elsewhere. */ |
540 | #define REG_SP 13 | |
541 | #define REG_LR 14 | |
542 | #define REG_PC 15 | |
404ff6b5 | 543 | |
b99bd4ef NC |
544 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
545 | take 2: */ | |
c19d1205 | 546 | #define INSN_SIZE 4 |
b99bd4ef NC |
547 | |
548 | struct asm_opcode | |
549 | { | |
550 | /* Basic string to match. */ | |
c921be7d | 551 | const char * template; |
c19d1205 ZW |
552 | |
553 | /* Parameters to instruction. */ | |
554 | unsigned char operands[8]; | |
555 | ||
556 | /* Conditional tag - see opcode_lookup. */ | |
557 | unsigned int tag : 4; | |
b99bd4ef NC |
558 | |
559 | /* Basic instruction code. */ | |
c19d1205 | 560 | unsigned int avalue : 28; |
b99bd4ef | 561 | |
c19d1205 ZW |
562 | /* Thumb-format instruction code. */ |
563 | unsigned int tvalue; | |
b99bd4ef | 564 | |
90e4755a | 565 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
566 | const arm_feature_set * avariant; |
567 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
568 | |
569 | /* Function to call to encode instruction in ARM format. */ | |
570 | void (* aencode) (void); | |
b99bd4ef | 571 | |
c19d1205 ZW |
572 | /* Function to call to encode instruction in Thumb format. */ |
573 | void (* tencode) (void); | |
b99bd4ef NC |
574 | }; |
575 | ||
a737bd4d NC |
576 | /* Defines for various bits that we will want to toggle. */ |
577 | #define INST_IMMEDIATE 0x02000000 | |
578 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 579 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
580 | #define SHIFT_BY_REG 0x00000010 |
581 | #define PRE_INDEX 0x01000000 | |
582 | #define INDEX_UP 0x00800000 | |
583 | #define WRITE_BACK 0x00200000 | |
584 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 585 | #define CPSI_MMOD 0x00020000 |
90e4755a | 586 | |
a737bd4d NC |
587 | #define LITERAL_MASK 0xf000f000 |
588 | #define OPCODE_MASK 0xfe1fffff | |
589 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 590 | |
efd81785 PB |
591 | #define T2_SUBS_PC_LR 0xf3de8f00 |
592 | ||
a737bd4d | 593 | #define DATA_OP_SHIFT 21 |
90e4755a | 594 | |
ef8d22e6 PB |
595 | #define T2_OPCODE_MASK 0xfe1fffff |
596 | #define T2_DATA_OP_SHIFT 21 | |
597 | ||
a737bd4d NC |
598 | /* Codes to distinguish the arithmetic instructions. */ |
599 | #define OPCODE_AND 0 | |
600 | #define OPCODE_EOR 1 | |
601 | #define OPCODE_SUB 2 | |
602 | #define OPCODE_RSB 3 | |
603 | #define OPCODE_ADD 4 | |
604 | #define OPCODE_ADC 5 | |
605 | #define OPCODE_SBC 6 | |
606 | #define OPCODE_RSC 7 | |
607 | #define OPCODE_TST 8 | |
608 | #define OPCODE_TEQ 9 | |
609 | #define OPCODE_CMP 10 | |
610 | #define OPCODE_CMN 11 | |
611 | #define OPCODE_ORR 12 | |
612 | #define OPCODE_MOV 13 | |
613 | #define OPCODE_BIC 14 | |
614 | #define OPCODE_MVN 15 | |
90e4755a | 615 | |
ef8d22e6 PB |
616 | #define T2_OPCODE_AND 0 |
617 | #define T2_OPCODE_BIC 1 | |
618 | #define T2_OPCODE_ORR 2 | |
619 | #define T2_OPCODE_ORN 3 | |
620 | #define T2_OPCODE_EOR 4 | |
621 | #define T2_OPCODE_ADD 8 | |
622 | #define T2_OPCODE_ADC 10 | |
623 | #define T2_OPCODE_SBC 11 | |
624 | #define T2_OPCODE_SUB 13 | |
625 | #define T2_OPCODE_RSB 14 | |
626 | ||
a737bd4d NC |
627 | #define T_OPCODE_MUL 0x4340 |
628 | #define T_OPCODE_TST 0x4200 | |
629 | #define T_OPCODE_CMN 0x42c0 | |
630 | #define T_OPCODE_NEG 0x4240 | |
631 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 632 | |
a737bd4d NC |
633 | #define T_OPCODE_ADD_R3 0x1800 |
634 | #define T_OPCODE_SUB_R3 0x1a00 | |
635 | #define T_OPCODE_ADD_HI 0x4400 | |
636 | #define T_OPCODE_ADD_ST 0xb000 | |
637 | #define T_OPCODE_SUB_ST 0xb080 | |
638 | #define T_OPCODE_ADD_SP 0xa800 | |
639 | #define T_OPCODE_ADD_PC 0xa000 | |
640 | #define T_OPCODE_ADD_I8 0x3000 | |
641 | #define T_OPCODE_SUB_I8 0x3800 | |
642 | #define T_OPCODE_ADD_I3 0x1c00 | |
643 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 644 | |
a737bd4d NC |
645 | #define T_OPCODE_ASR_R 0x4100 |
646 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
647 | #define T_OPCODE_LSR_R 0x40c0 |
648 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
649 | #define T_OPCODE_ASR_I 0x1000 |
650 | #define T_OPCODE_LSL_I 0x0000 | |
651 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 652 | |
a737bd4d NC |
653 | #define T_OPCODE_MOV_I8 0x2000 |
654 | #define T_OPCODE_CMP_I8 0x2800 | |
655 | #define T_OPCODE_CMP_LR 0x4280 | |
656 | #define T_OPCODE_MOV_HR 0x4600 | |
657 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 658 | |
a737bd4d NC |
659 | #define T_OPCODE_LDR_PC 0x4800 |
660 | #define T_OPCODE_LDR_SP 0x9800 | |
661 | #define T_OPCODE_STR_SP 0x9000 | |
662 | #define T_OPCODE_LDR_IW 0x6800 | |
663 | #define T_OPCODE_STR_IW 0x6000 | |
664 | #define T_OPCODE_LDR_IH 0x8800 | |
665 | #define T_OPCODE_STR_IH 0x8000 | |
666 | #define T_OPCODE_LDR_IB 0x7800 | |
667 | #define T_OPCODE_STR_IB 0x7000 | |
668 | #define T_OPCODE_LDR_RW 0x5800 | |
669 | #define T_OPCODE_STR_RW 0x5000 | |
670 | #define T_OPCODE_LDR_RH 0x5a00 | |
671 | #define T_OPCODE_STR_RH 0x5200 | |
672 | #define T_OPCODE_LDR_RB 0x5c00 | |
673 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 674 | |
a737bd4d NC |
675 | #define T_OPCODE_PUSH 0xb400 |
676 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 677 | |
2fc8bdac | 678 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 679 | |
a737bd4d | 680 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 681 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 682 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 683 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
684 | |
685 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 686 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
687 | #define BAD_PC _("r15 not allowed here") |
688 | #define BAD_COND _("instruction cannot be conditional") | |
689 | #define BAD_OVERLAP _("registers may not be the same") | |
690 | #define BAD_HIREG _("lo register required") | |
691 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 692 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
693 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
694 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 695 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
696 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
697 | #define BAD_IT_COND _("incorrect condition in IT block") | |
698 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 699 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
c19d1205 | 700 | |
c921be7d NC |
701 | static struct hash_control * arm_ops_hsh; |
702 | static struct hash_control * arm_cond_hsh; | |
703 | static struct hash_control * arm_shift_hsh; | |
704 | static struct hash_control * arm_psr_hsh; | |
705 | static struct hash_control * arm_v7m_psr_hsh; | |
706 | static struct hash_control * arm_reg_hsh; | |
707 | static struct hash_control * arm_reloc_hsh; | |
708 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 709 | |
b99bd4ef NC |
710 | /* Stuff needed to resolve the label ambiguity |
711 | As: | |
712 | ... | |
713 | label: <insn> | |
714 | may differ from: | |
715 | ... | |
716 | label: | |
5f4273c7 | 717 | <insn> */ |
b99bd4ef NC |
718 | |
719 | symbolS * last_label_seen; | |
b34976b6 | 720 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 721 | |
3d0c9500 NC |
722 | /* Literal pool structure. Held on a per-section |
723 | and per-sub-section basis. */ | |
a737bd4d | 724 | |
c19d1205 | 725 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 726 | typedef struct literal_pool |
b99bd4ef | 727 | { |
c921be7d NC |
728 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
729 | unsigned int next_free_entry; | |
730 | unsigned int id; | |
731 | symbolS * symbol; | |
732 | segT section; | |
733 | subsegT sub_section; | |
734 | struct literal_pool * next; | |
3d0c9500 | 735 | } literal_pool; |
b99bd4ef | 736 | |
3d0c9500 NC |
737 | /* Pointer to a linked list of literal pools. */ |
738 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 739 | |
e07e6e58 NC |
740 | #ifdef OBJ_ELF |
741 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
742 | #else | |
743 | static struct current_it now_it; | |
744 | #endif | |
745 | ||
746 | static inline int | |
747 | now_it_compatible (int cond) | |
748 | { | |
749 | return (cond & ~1) == (now_it.cc & ~1); | |
750 | } | |
751 | ||
752 | static inline int | |
753 | conditional_insn (void) | |
754 | { | |
755 | return inst.cond != COND_ALWAYS; | |
756 | } | |
757 | ||
758 | static int in_it_block (void); | |
759 | ||
760 | static int handle_it_state (void); | |
761 | ||
762 | static void force_automatic_it_block_close (void); | |
763 | ||
c921be7d NC |
764 | static void it_fsm_post_encode (void); |
765 | ||
e07e6e58 NC |
766 | #define set_it_insn_type(type) \ |
767 | do \ | |
768 | { \ | |
769 | inst.it_insn_type = type; \ | |
770 | if (handle_it_state () == FAIL) \ | |
771 | return; \ | |
772 | } \ | |
773 | while (0) | |
774 | ||
c921be7d NC |
775 | #define set_it_insn_type_nonvoid(type, failret) \ |
776 | do \ | |
777 | { \ | |
778 | inst.it_insn_type = type; \ | |
779 | if (handle_it_state () == FAIL) \ | |
780 | return failret; \ | |
781 | } \ | |
782 | while(0) | |
783 | ||
e07e6e58 NC |
784 | #define set_it_insn_type_last() \ |
785 | do \ | |
786 | { \ | |
787 | if (inst.cond == COND_ALWAYS) \ | |
788 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ | |
789 | else \ | |
790 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ | |
791 | } \ | |
792 | while (0) | |
793 | ||
c19d1205 | 794 | /* Pure syntax. */ |
b99bd4ef | 795 | |
c19d1205 ZW |
796 | /* This array holds the chars that always start a comment. If the |
797 | pre-processor is disabled, these aren't very useful. */ | |
798 | const char comment_chars[] = "@"; | |
3d0c9500 | 799 | |
c19d1205 ZW |
800 | /* This array holds the chars that only start a comment at the beginning of |
801 | a line. If the line seems to have the form '# 123 filename' | |
802 | .line and .file directives will appear in the pre-processed output. */ | |
803 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
804 | first line of the input file. This is because the compiler outputs | |
805 | #NO_APP at the beginning of its output. */ | |
806 | /* Also note that comments like this one will always work. */ | |
807 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 808 | |
c19d1205 | 809 | const char line_separator_chars[] = ";"; |
b99bd4ef | 810 | |
c19d1205 ZW |
811 | /* Chars that can be used to separate mant |
812 | from exp in floating point numbers. */ | |
813 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 814 | |
c19d1205 ZW |
815 | /* Chars that mean this number is a floating point constant. */ |
816 | /* As in 0f12.456 */ | |
817 | /* or 0d1.2345e12 */ | |
b99bd4ef | 818 | |
c19d1205 | 819 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 820 | |
c19d1205 ZW |
821 | /* Prefix characters that indicate the start of an immediate |
822 | value. */ | |
823 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 824 | |
c19d1205 ZW |
825 | /* Separator character handling. */ |
826 | ||
827 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
828 | ||
829 | static inline int | |
830 | skip_past_char (char ** str, char c) | |
831 | { | |
832 | if (**str == c) | |
833 | { | |
834 | (*str)++; | |
835 | return SUCCESS; | |
3d0c9500 | 836 | } |
c19d1205 ZW |
837 | else |
838 | return FAIL; | |
839 | } | |
c921be7d | 840 | |
c19d1205 | 841 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 842 | |
c19d1205 ZW |
843 | /* Arithmetic expressions (possibly involving symbols). */ |
844 | ||
845 | /* Return TRUE if anything in the expression is a bignum. */ | |
846 | ||
847 | static int | |
848 | walk_no_bignums (symbolS * sp) | |
849 | { | |
850 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
851 | return 1; | |
852 | ||
853 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 854 | { |
c19d1205 ZW |
855 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
856 | || (symbol_get_value_expression (sp)->X_op_symbol | |
857 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
858 | } |
859 | ||
c19d1205 | 860 | return 0; |
3d0c9500 NC |
861 | } |
862 | ||
c19d1205 ZW |
863 | static int in_my_get_expression = 0; |
864 | ||
865 | /* Third argument to my_get_expression. */ | |
866 | #define GE_NO_PREFIX 0 | |
867 | #define GE_IMM_PREFIX 1 | |
868 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
869 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
870 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
871 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 872 | |
b99bd4ef | 873 | static int |
c19d1205 | 874 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 875 | { |
c19d1205 ZW |
876 | char * save_in; |
877 | segT seg; | |
b99bd4ef | 878 | |
c19d1205 ZW |
879 | /* In unified syntax, all prefixes are optional. */ |
880 | if (unified_syntax) | |
5287ad62 JB |
881 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
882 | : GE_OPT_PREFIX; | |
b99bd4ef | 883 | |
c19d1205 | 884 | switch (prefix_mode) |
b99bd4ef | 885 | { |
c19d1205 ZW |
886 | case GE_NO_PREFIX: break; |
887 | case GE_IMM_PREFIX: | |
888 | if (!is_immediate_prefix (**str)) | |
889 | { | |
890 | inst.error = _("immediate expression requires a # prefix"); | |
891 | return FAIL; | |
892 | } | |
893 | (*str)++; | |
894 | break; | |
895 | case GE_OPT_PREFIX: | |
5287ad62 | 896 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
897 | if (is_immediate_prefix (**str)) |
898 | (*str)++; | |
899 | break; | |
900 | default: abort (); | |
901 | } | |
b99bd4ef | 902 | |
c19d1205 | 903 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 904 | |
c19d1205 ZW |
905 | save_in = input_line_pointer; |
906 | input_line_pointer = *str; | |
907 | in_my_get_expression = 1; | |
908 | seg = expression (ep); | |
909 | in_my_get_expression = 0; | |
910 | ||
f86adc07 | 911 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 912 | { |
f86adc07 | 913 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
914 | *str = input_line_pointer; |
915 | input_line_pointer = save_in; | |
916 | if (inst.error == NULL) | |
f86adc07 NS |
917 | inst.error = (ep->X_op == O_absent |
918 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
919 | return 1; |
920 | } | |
b99bd4ef | 921 | |
c19d1205 ZW |
922 | #ifdef OBJ_AOUT |
923 | if (seg != absolute_section | |
924 | && seg != text_section | |
925 | && seg != data_section | |
926 | && seg != bss_section | |
927 | && seg != undefined_section) | |
928 | { | |
929 | inst.error = _("bad segment"); | |
930 | *str = input_line_pointer; | |
931 | input_line_pointer = save_in; | |
932 | return 1; | |
b99bd4ef | 933 | } |
c19d1205 | 934 | #endif |
b99bd4ef | 935 | |
c19d1205 ZW |
936 | /* Get rid of any bignums now, so that we don't generate an error for which |
937 | we can't establish a line number later on. Big numbers are never valid | |
938 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
939 | if (prefix_mode != GE_OPT_PREFIX_BIG |
940 | && (ep->X_op == O_big | |
941 | || (ep->X_add_symbol | |
942 | && (walk_no_bignums (ep->X_add_symbol) | |
943 | || (ep->X_op_symbol | |
944 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
945 | { |
946 | inst.error = _("invalid constant"); | |
947 | *str = input_line_pointer; | |
948 | input_line_pointer = save_in; | |
949 | return 1; | |
950 | } | |
b99bd4ef | 951 | |
c19d1205 ZW |
952 | *str = input_line_pointer; |
953 | input_line_pointer = save_in; | |
954 | return 0; | |
b99bd4ef NC |
955 | } |
956 | ||
c19d1205 ZW |
957 | /* Turn a string in input_line_pointer into a floating point constant |
958 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
959 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
960 | returned, or NULL on OK. | |
b99bd4ef | 961 | |
c19d1205 ZW |
962 | Note that fp constants aren't represent in the normal way on the ARM. |
963 | In big endian mode, things are as expected. However, in little endian | |
964 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
965 | within the words. For example, (double) 1.1 in big endian mode is | |
966 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
967 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 968 | |
c19d1205 | 969 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 970 | |
c19d1205 ZW |
971 | char * |
972 | md_atof (int type, char * litP, int * sizeP) | |
973 | { | |
974 | int prec; | |
975 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
976 | char *t; | |
977 | int i; | |
b99bd4ef | 978 | |
c19d1205 ZW |
979 | switch (type) |
980 | { | |
981 | case 'f': | |
982 | case 'F': | |
983 | case 's': | |
984 | case 'S': | |
985 | prec = 2; | |
986 | break; | |
b99bd4ef | 987 | |
c19d1205 ZW |
988 | case 'd': |
989 | case 'D': | |
990 | case 'r': | |
991 | case 'R': | |
992 | prec = 4; | |
993 | break; | |
b99bd4ef | 994 | |
c19d1205 ZW |
995 | case 'x': |
996 | case 'X': | |
499ac353 | 997 | prec = 5; |
c19d1205 | 998 | break; |
b99bd4ef | 999 | |
c19d1205 ZW |
1000 | case 'p': |
1001 | case 'P': | |
499ac353 | 1002 | prec = 5; |
c19d1205 | 1003 | break; |
a737bd4d | 1004 | |
c19d1205 ZW |
1005 | default: |
1006 | *sizeP = 0; | |
499ac353 | 1007 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1008 | } |
b99bd4ef | 1009 | |
c19d1205 ZW |
1010 | t = atof_ieee (input_line_pointer, type, words); |
1011 | if (t) | |
1012 | input_line_pointer = t; | |
499ac353 | 1013 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1014 | |
c19d1205 ZW |
1015 | if (target_big_endian) |
1016 | { | |
1017 | for (i = 0; i < prec; i++) | |
1018 | { | |
499ac353 NC |
1019 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1020 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1021 | } |
1022 | } | |
1023 | else | |
1024 | { | |
e74cfd16 | 1025 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1026 | for (i = prec - 1; i >= 0; i--) |
1027 | { | |
499ac353 NC |
1028 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1029 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1030 | } |
1031 | else | |
1032 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1033 | For an 8 byte float the order is 1 0 3 2. */ | |
1034 | for (i = 0; i < prec; i += 2) | |
1035 | { | |
499ac353 NC |
1036 | md_number_to_chars (litP, (valueT) words[i + 1], |
1037 | sizeof (LITTLENUM_TYPE)); | |
1038 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1039 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1040 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1041 | } |
1042 | } | |
b99bd4ef | 1043 | |
499ac353 | 1044 | return NULL; |
c19d1205 | 1045 | } |
b99bd4ef | 1046 | |
c19d1205 ZW |
1047 | /* We handle all bad expressions here, so that we can report the faulty |
1048 | instruction in the error message. */ | |
1049 | void | |
1050 | md_operand (expressionS * expr) | |
1051 | { | |
1052 | if (in_my_get_expression) | |
1053 | expr->X_op = O_illegal; | |
b99bd4ef NC |
1054 | } |
1055 | ||
c19d1205 | 1056 | /* Immediate values. */ |
b99bd4ef | 1057 | |
c19d1205 ZW |
1058 | /* Generic immediate-value read function for use in directives. |
1059 | Accepts anything that 'expression' can fold to a constant. | |
1060 | *val receives the number. */ | |
1061 | #ifdef OBJ_ELF | |
1062 | static int | |
1063 | immediate_for_directive (int *val) | |
b99bd4ef | 1064 | { |
c19d1205 ZW |
1065 | expressionS exp; |
1066 | exp.X_op = O_illegal; | |
b99bd4ef | 1067 | |
c19d1205 ZW |
1068 | if (is_immediate_prefix (*input_line_pointer)) |
1069 | { | |
1070 | input_line_pointer++; | |
1071 | expression (&exp); | |
1072 | } | |
b99bd4ef | 1073 | |
c19d1205 ZW |
1074 | if (exp.X_op != O_constant) |
1075 | { | |
1076 | as_bad (_("expected #constant")); | |
1077 | ignore_rest_of_line (); | |
1078 | return FAIL; | |
1079 | } | |
1080 | *val = exp.X_add_number; | |
1081 | return SUCCESS; | |
b99bd4ef | 1082 | } |
c19d1205 | 1083 | #endif |
b99bd4ef | 1084 | |
c19d1205 | 1085 | /* Register parsing. */ |
b99bd4ef | 1086 | |
c19d1205 ZW |
1087 | /* Generic register parser. CCP points to what should be the |
1088 | beginning of a register name. If it is indeed a valid register | |
1089 | name, advance CCP over it and return the reg_entry structure; | |
1090 | otherwise return NULL. Does not issue diagnostics. */ | |
1091 | ||
1092 | static struct reg_entry * | |
1093 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1094 | { |
c19d1205 ZW |
1095 | char *start = *ccp; |
1096 | char *p; | |
1097 | struct reg_entry *reg; | |
b99bd4ef | 1098 | |
c19d1205 ZW |
1099 | #ifdef REGISTER_PREFIX |
1100 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1101 | return NULL; |
c19d1205 ZW |
1102 | start++; |
1103 | #endif | |
1104 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1105 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1106 | start++; | |
1107 | #endif | |
b99bd4ef | 1108 | |
c19d1205 ZW |
1109 | p = start; |
1110 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1111 | return NULL; | |
b99bd4ef | 1112 | |
c19d1205 ZW |
1113 | do |
1114 | p++; | |
1115 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1116 | ||
1117 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1118 | ||
1119 | if (!reg) | |
1120 | return NULL; | |
1121 | ||
1122 | *ccp = p; | |
1123 | return reg; | |
b99bd4ef NC |
1124 | } |
1125 | ||
1126 | static int | |
dcbf9037 JB |
1127 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1128 | enum arm_reg_type type) | |
b99bd4ef | 1129 | { |
c19d1205 ZW |
1130 | /* Alternative syntaxes are accepted for a few register classes. */ |
1131 | switch (type) | |
1132 | { | |
1133 | case REG_TYPE_MVF: | |
1134 | case REG_TYPE_MVD: | |
1135 | case REG_TYPE_MVFX: | |
1136 | case REG_TYPE_MVDX: | |
1137 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1138 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1139 | return reg->number; |
1140 | break; | |
69b97547 | 1141 | |
c19d1205 ZW |
1142 | case REG_TYPE_CP: |
1143 | /* For backward compatibility, a bare number is valid here. */ | |
1144 | { | |
1145 | unsigned long processor = strtoul (start, ccp, 10); | |
1146 | if (*ccp != start && processor <= 15) | |
1147 | return processor; | |
1148 | } | |
6057a28f | 1149 | |
c19d1205 ZW |
1150 | case REG_TYPE_MMXWC: |
1151 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1152 | instructions that take WC registers. */ | |
79134647 | 1153 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1154 | return reg->number; |
6057a28f | 1155 | break; |
c19d1205 | 1156 | |
6057a28f | 1157 | default: |
c19d1205 | 1158 | break; |
6057a28f NC |
1159 | } |
1160 | ||
dcbf9037 JB |
1161 | return FAIL; |
1162 | } | |
1163 | ||
1164 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1165 | return value is the register number or FAIL. */ | |
1166 | ||
1167 | static int | |
1168 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1169 | { | |
1170 | char *start = *ccp; | |
1171 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1172 | int ret; | |
1173 | ||
1174 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1175 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1176 | return FAIL; | |
1177 | ||
1178 | if (reg && reg->type == type) | |
1179 | return reg->number; | |
1180 | ||
1181 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1182 | return ret; | |
1183 | ||
c19d1205 ZW |
1184 | *ccp = start; |
1185 | return FAIL; | |
1186 | } | |
69b97547 | 1187 | |
dcbf9037 JB |
1188 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1189 | character. Does no verification at this stage that the type fits the opcode | |
1190 | properly. E.g., | |
1191 | ||
1192 | .i32.i32.s16 | |
1193 | .s32.f32 | |
1194 | .u16 | |
1195 | ||
1196 | Can all be legally parsed by this function. | |
1197 | ||
1198 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1199 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1200 | type, FAIL if not. */ | |
1201 | ||
1202 | static int | |
1203 | parse_neon_type (struct neon_type *type, char **str) | |
1204 | { | |
1205 | char *ptr = *str; | |
1206 | ||
1207 | if (type) | |
1208 | type->elems = 0; | |
1209 | ||
1210 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1211 | { | |
1212 | enum neon_el_type thistype = NT_untyped; | |
1213 | unsigned thissize = -1u; | |
1214 | ||
1215 | if (*ptr != '.') | |
1216 | break; | |
1217 | ||
1218 | ptr++; | |
1219 | ||
1220 | /* Just a size without an explicit type. */ | |
1221 | if (ISDIGIT (*ptr)) | |
1222 | goto parsesize; | |
1223 | ||
1224 | switch (TOLOWER (*ptr)) | |
1225 | { | |
1226 | case 'i': thistype = NT_integer; break; | |
1227 | case 'f': thistype = NT_float; break; | |
1228 | case 'p': thistype = NT_poly; break; | |
1229 | case 's': thistype = NT_signed; break; | |
1230 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1231 | case 'd': |
1232 | thistype = NT_float; | |
1233 | thissize = 64; | |
1234 | ptr++; | |
1235 | goto done; | |
dcbf9037 JB |
1236 | default: |
1237 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1238 | return FAIL; | |
1239 | } | |
1240 | ||
1241 | ptr++; | |
1242 | ||
1243 | /* .f is an abbreviation for .f32. */ | |
1244 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1245 | thissize = 32; | |
1246 | else | |
1247 | { | |
1248 | parsesize: | |
1249 | thissize = strtoul (ptr, &ptr, 10); | |
1250 | ||
1251 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1252 | && thissize != 64) | |
1253 | { | |
1254 | as_bad (_("bad size %d in type specifier"), thissize); | |
1255 | return FAIL; | |
1256 | } | |
1257 | } | |
1258 | ||
037e8744 | 1259 | done: |
dcbf9037 JB |
1260 | if (type) |
1261 | { | |
1262 | type->el[type->elems].type = thistype; | |
1263 | type->el[type->elems].size = thissize; | |
1264 | type->elems++; | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | /* Empty/missing type is not a successful parse. */ | |
1269 | if (type->elems == 0) | |
1270 | return FAIL; | |
1271 | ||
1272 | *str = ptr; | |
1273 | ||
1274 | return SUCCESS; | |
1275 | } | |
1276 | ||
1277 | /* Errors may be set multiple times during parsing or bit encoding | |
1278 | (particularly in the Neon bits), but usually the earliest error which is set | |
1279 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1280 | errors by calling this function. */ | |
1281 | ||
1282 | static void | |
1283 | first_error (const char *err) | |
1284 | { | |
1285 | if (!inst.error) | |
1286 | inst.error = err; | |
1287 | } | |
1288 | ||
1289 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1290 | static int | |
1291 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1292 | { | |
1293 | char *str = *ccp; | |
1294 | struct neon_type optype; | |
1295 | ||
1296 | if (*str == '.') | |
1297 | { | |
1298 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1299 | { | |
1300 | if (optype.elems == 1) | |
1301 | *vectype = optype.el[0]; | |
1302 | else | |
1303 | { | |
1304 | first_error (_("only one type should be specified for operand")); | |
1305 | return FAIL; | |
1306 | } | |
1307 | } | |
1308 | else | |
1309 | { | |
1310 | first_error (_("vector type expected")); | |
1311 | return FAIL; | |
1312 | } | |
1313 | } | |
1314 | else | |
1315 | return FAIL; | |
5f4273c7 | 1316 | |
dcbf9037 | 1317 | *ccp = str; |
5f4273c7 | 1318 | |
dcbf9037 JB |
1319 | return SUCCESS; |
1320 | } | |
1321 | ||
1322 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1323 | a 4-bit integer. */ | |
1324 | ||
1325 | #define NEON_ALL_LANES 15 | |
1326 | #define NEON_INTERLEAVE_LANES 14 | |
1327 | ||
1328 | /* Parse either a register or a scalar, with an optional type. Return the | |
1329 | register number, and optionally fill in the actual type of the register | |
1330 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1331 | type/index information in *TYPEINFO. */ | |
1332 | ||
1333 | static int | |
1334 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1335 | enum arm_reg_type *rtype, | |
1336 | struct neon_typed_alias *typeinfo) | |
1337 | { | |
1338 | char *str = *ccp; | |
1339 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1340 | struct neon_typed_alias atype; | |
1341 | struct neon_type_el parsetype; | |
1342 | ||
1343 | atype.defined = 0; | |
1344 | atype.index = -1; | |
1345 | atype.eltype.type = NT_invtype; | |
1346 | atype.eltype.size = -1; | |
1347 | ||
1348 | /* Try alternate syntax for some types of register. Note these are mutually | |
1349 | exclusive with the Neon syntax extensions. */ | |
1350 | if (reg == NULL) | |
1351 | { | |
1352 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1353 | if (altreg != FAIL) | |
1354 | *ccp = str; | |
1355 | if (typeinfo) | |
1356 | *typeinfo = atype; | |
1357 | return altreg; | |
1358 | } | |
1359 | ||
037e8744 JB |
1360 | /* Undo polymorphism when a set of register types may be accepted. */ |
1361 | if ((type == REG_TYPE_NDQ | |
1362 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1363 | || (type == REG_TYPE_VFSD | |
1364 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1365 | || (type == REG_TYPE_NSDQ | |
1366 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
f512f76f NC |
1367 | || reg->type == REG_TYPE_NQ)) |
1368 | || (type == REG_TYPE_MMXWC | |
1369 | && (reg->type == REG_TYPE_MMXWCG))) | |
dcbf9037 JB |
1370 | type = reg->type; |
1371 | ||
1372 | if (type != reg->type) | |
1373 | return FAIL; | |
1374 | ||
1375 | if (reg->neon) | |
1376 | atype = *reg->neon; | |
5f4273c7 | 1377 | |
dcbf9037 JB |
1378 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1379 | { | |
1380 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1381 | { | |
1382 | first_error (_("can't redefine type for operand")); | |
1383 | return FAIL; | |
1384 | } | |
1385 | atype.defined |= NTA_HASTYPE; | |
1386 | atype.eltype = parsetype; | |
1387 | } | |
5f4273c7 | 1388 | |
dcbf9037 JB |
1389 | if (skip_past_char (&str, '[') == SUCCESS) |
1390 | { | |
1391 | if (type != REG_TYPE_VFD) | |
1392 | { | |
1393 | first_error (_("only D registers may be indexed")); | |
1394 | return FAIL; | |
1395 | } | |
5f4273c7 | 1396 | |
dcbf9037 JB |
1397 | if ((atype.defined & NTA_HASINDEX) != 0) |
1398 | { | |
1399 | first_error (_("can't change index for operand")); | |
1400 | return FAIL; | |
1401 | } | |
1402 | ||
1403 | atype.defined |= NTA_HASINDEX; | |
1404 | ||
1405 | if (skip_past_char (&str, ']') == SUCCESS) | |
1406 | atype.index = NEON_ALL_LANES; | |
1407 | else | |
1408 | { | |
1409 | expressionS exp; | |
1410 | ||
1411 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1412 | ||
1413 | if (exp.X_op != O_constant) | |
1414 | { | |
1415 | first_error (_("constant expression required")); | |
1416 | return FAIL; | |
1417 | } | |
1418 | ||
1419 | if (skip_past_char (&str, ']') == FAIL) | |
1420 | return FAIL; | |
1421 | ||
1422 | atype.index = exp.X_add_number; | |
1423 | } | |
1424 | } | |
5f4273c7 | 1425 | |
dcbf9037 JB |
1426 | if (typeinfo) |
1427 | *typeinfo = atype; | |
5f4273c7 | 1428 | |
dcbf9037 JB |
1429 | if (rtype) |
1430 | *rtype = type; | |
5f4273c7 | 1431 | |
dcbf9037 | 1432 | *ccp = str; |
5f4273c7 | 1433 | |
dcbf9037 JB |
1434 | return reg->number; |
1435 | } | |
1436 | ||
1437 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1438 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1439 | register (e.g. Neon double or quad reg when either has been requested). | |
1440 | - If this is a Neon vector type with additional type information, fill | |
1441 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1442 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1443 | |
1444 | static int | |
1445 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1446 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1447 | { | |
1448 | struct neon_typed_alias atype; | |
1449 | char *str = *ccp; | |
1450 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1451 | ||
1452 | if (reg == FAIL) | |
1453 | return FAIL; | |
1454 | ||
1455 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1456 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1457 | { | |
1458 | first_error (_("register operand expected, but got scalar")); | |
1459 | return FAIL; | |
1460 | } | |
1461 | ||
1462 | if (vectype) | |
1463 | *vectype = atype.eltype; | |
1464 | ||
1465 | *ccp = str; | |
1466 | ||
1467 | return reg; | |
1468 | } | |
1469 | ||
1470 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1471 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1472 | ||
5287ad62 JB |
1473 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1474 | have enough information to be able to do a good job bounds-checking. So, we | |
1475 | just do easy checks here, and do further checks later. */ | |
1476 | ||
1477 | static int | |
dcbf9037 | 1478 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1479 | { |
dcbf9037 | 1480 | int reg; |
5287ad62 | 1481 | char *str = *ccp; |
dcbf9037 | 1482 | struct neon_typed_alias atype; |
5f4273c7 | 1483 | |
dcbf9037 | 1484 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1485 | |
dcbf9037 | 1486 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1487 | return FAIL; |
5f4273c7 | 1488 | |
dcbf9037 | 1489 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1490 | { |
dcbf9037 | 1491 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1492 | return FAIL; |
1493 | } | |
dcbf9037 | 1494 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1495 | { |
dcbf9037 | 1496 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1497 | return FAIL; |
1498 | } | |
5f4273c7 | 1499 | |
dcbf9037 JB |
1500 | if (type) |
1501 | *type = atype.eltype; | |
5f4273c7 | 1502 | |
5287ad62 | 1503 | *ccp = str; |
5f4273c7 | 1504 | |
dcbf9037 | 1505 | return reg * 16 + atype.index; |
5287ad62 JB |
1506 | } |
1507 | ||
c19d1205 | 1508 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1509 | |
c19d1205 ZW |
1510 | static long |
1511 | parse_reg_list (char ** strp) | |
1512 | { | |
1513 | char * str = * strp; | |
1514 | long range = 0; | |
1515 | int another_range; | |
a737bd4d | 1516 | |
c19d1205 ZW |
1517 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1518 | do | |
6057a28f | 1519 | { |
c19d1205 | 1520 | another_range = 0; |
a737bd4d | 1521 | |
c19d1205 ZW |
1522 | if (*str == '{') |
1523 | { | |
1524 | int in_range = 0; | |
1525 | int cur_reg = -1; | |
a737bd4d | 1526 | |
c19d1205 ZW |
1527 | str++; |
1528 | do | |
1529 | { | |
1530 | int reg; | |
6057a28f | 1531 | |
dcbf9037 | 1532 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1533 | { |
dcbf9037 | 1534 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1535 | return FAIL; |
1536 | } | |
a737bd4d | 1537 | |
c19d1205 ZW |
1538 | if (in_range) |
1539 | { | |
1540 | int i; | |
a737bd4d | 1541 | |
c19d1205 ZW |
1542 | if (reg <= cur_reg) |
1543 | { | |
dcbf9037 | 1544 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1545 | return FAIL; |
1546 | } | |
40a18ebd | 1547 | |
c19d1205 ZW |
1548 | for (i = cur_reg + 1; i < reg; i++) |
1549 | { | |
1550 | if (range & (1 << i)) | |
1551 | as_tsktsk | |
1552 | (_("Warning: duplicated register (r%d) in register list"), | |
1553 | i); | |
1554 | else | |
1555 | range |= 1 << i; | |
1556 | } | |
1557 | in_range = 0; | |
1558 | } | |
a737bd4d | 1559 | |
c19d1205 ZW |
1560 | if (range & (1 << reg)) |
1561 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1562 | reg); | |
1563 | else if (reg <= cur_reg) | |
1564 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1565 | |
c19d1205 ZW |
1566 | range |= 1 << reg; |
1567 | cur_reg = reg; | |
1568 | } | |
1569 | while (skip_past_comma (&str) != FAIL | |
1570 | || (in_range = 1, *str++ == '-')); | |
1571 | str--; | |
a737bd4d | 1572 | |
c19d1205 ZW |
1573 | if (*str++ != '}') |
1574 | { | |
dcbf9037 | 1575 | first_error (_("missing `}'")); |
c19d1205 ZW |
1576 | return FAIL; |
1577 | } | |
1578 | } | |
1579 | else | |
1580 | { | |
1581 | expressionS expr; | |
40a18ebd | 1582 | |
c19d1205 ZW |
1583 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1584 | return FAIL; | |
40a18ebd | 1585 | |
c19d1205 ZW |
1586 | if (expr.X_op == O_constant) |
1587 | { | |
1588 | if (expr.X_add_number | |
1589 | != (expr.X_add_number & 0x0000ffff)) | |
1590 | { | |
1591 | inst.error = _("invalid register mask"); | |
1592 | return FAIL; | |
1593 | } | |
a737bd4d | 1594 | |
c19d1205 ZW |
1595 | if ((range & expr.X_add_number) != 0) |
1596 | { | |
1597 | int regno = range & expr.X_add_number; | |
a737bd4d | 1598 | |
c19d1205 ZW |
1599 | regno &= -regno; |
1600 | regno = (1 << regno) - 1; | |
1601 | as_tsktsk | |
1602 | (_("Warning: duplicated register (r%d) in register list"), | |
1603 | regno); | |
1604 | } | |
a737bd4d | 1605 | |
c19d1205 ZW |
1606 | range |= expr.X_add_number; |
1607 | } | |
1608 | else | |
1609 | { | |
1610 | if (inst.reloc.type != 0) | |
1611 | { | |
1612 | inst.error = _("expression too complex"); | |
1613 | return FAIL; | |
1614 | } | |
a737bd4d | 1615 | |
c19d1205 ZW |
1616 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1617 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1618 | inst.reloc.pc_rel = 0; | |
1619 | } | |
1620 | } | |
a737bd4d | 1621 | |
c19d1205 ZW |
1622 | if (*str == '|' || *str == '+') |
1623 | { | |
1624 | str++; | |
1625 | another_range = 1; | |
1626 | } | |
a737bd4d | 1627 | } |
c19d1205 | 1628 | while (another_range); |
a737bd4d | 1629 | |
c19d1205 ZW |
1630 | *strp = str; |
1631 | return range; | |
a737bd4d NC |
1632 | } |
1633 | ||
5287ad62 JB |
1634 | /* Types of registers in a list. */ |
1635 | ||
1636 | enum reg_list_els | |
1637 | { | |
1638 | REGLIST_VFP_S, | |
1639 | REGLIST_VFP_D, | |
1640 | REGLIST_NEON_D | |
1641 | }; | |
1642 | ||
c19d1205 ZW |
1643 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1644 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1645 | register. Parses registers of type ETYPE. |
1646 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1647 | - Q registers can be used to specify pairs of D registers | |
1648 | - { } can be omitted from around a singleton register list | |
1649 | FIXME: This is not implemented, as it would require backtracking in | |
1650 | some cases, e.g.: | |
1651 | vtbl.8 d3,d4,d5 | |
1652 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1653 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1654 | - 32 D registers may be used (also true for VFPv3). |
1655 | FIXME: Types are ignored in these register lists, which is probably a | |
1656 | bug. */ | |
6057a28f | 1657 | |
c19d1205 | 1658 | static int |
037e8744 | 1659 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1660 | { |
037e8744 | 1661 | char *str = *ccp; |
c19d1205 ZW |
1662 | int base_reg; |
1663 | int new_base; | |
5287ad62 JB |
1664 | enum arm_reg_type regtype = 0; |
1665 | int max_regs = 0; | |
c19d1205 ZW |
1666 | int count = 0; |
1667 | int warned = 0; | |
1668 | unsigned long mask = 0; | |
a737bd4d | 1669 | int i; |
6057a28f | 1670 | |
037e8744 | 1671 | if (*str != '{') |
5287ad62 JB |
1672 | { |
1673 | inst.error = _("expecting {"); | |
1674 | return FAIL; | |
1675 | } | |
6057a28f | 1676 | |
037e8744 | 1677 | str++; |
6057a28f | 1678 | |
5287ad62 | 1679 | switch (etype) |
c19d1205 | 1680 | { |
5287ad62 | 1681 | case REGLIST_VFP_S: |
c19d1205 ZW |
1682 | regtype = REG_TYPE_VFS; |
1683 | max_regs = 32; | |
5287ad62 | 1684 | break; |
5f4273c7 | 1685 | |
5287ad62 JB |
1686 | case REGLIST_VFP_D: |
1687 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1688 | break; |
5f4273c7 | 1689 | |
b7fc2769 JB |
1690 | case REGLIST_NEON_D: |
1691 | regtype = REG_TYPE_NDQ; | |
1692 | break; | |
1693 | } | |
1694 | ||
1695 | if (etype != REGLIST_VFP_S) | |
1696 | { | |
b1cc4aeb PB |
1697 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1698 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
5287ad62 JB |
1699 | { |
1700 | max_regs = 32; | |
1701 | if (thumb_mode) | |
1702 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 1703 | fpu_vfp_ext_d32); |
5287ad62 JB |
1704 | else |
1705 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 1706 | fpu_vfp_ext_d32); |
5287ad62 JB |
1707 | } |
1708 | else | |
1709 | max_regs = 16; | |
c19d1205 | 1710 | } |
6057a28f | 1711 | |
c19d1205 | 1712 | base_reg = max_regs; |
a737bd4d | 1713 | |
c19d1205 ZW |
1714 | do |
1715 | { | |
5287ad62 | 1716 | int setmask = 1, addregs = 1; |
dcbf9037 | 1717 | |
037e8744 | 1718 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1719 | |
c19d1205 | 1720 | if (new_base == FAIL) |
a737bd4d | 1721 | { |
dcbf9037 | 1722 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1723 | return FAIL; |
1724 | } | |
5f4273c7 | 1725 | |
b7fc2769 JB |
1726 | if (new_base >= max_regs) |
1727 | { | |
1728 | first_error (_("register out of range in list")); | |
1729 | return FAIL; | |
1730 | } | |
5f4273c7 | 1731 | |
5287ad62 JB |
1732 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1733 | if (regtype == REG_TYPE_NQ) | |
1734 | { | |
1735 | setmask = 3; | |
1736 | addregs = 2; | |
1737 | } | |
1738 | ||
c19d1205 ZW |
1739 | if (new_base < base_reg) |
1740 | base_reg = new_base; | |
a737bd4d | 1741 | |
5287ad62 | 1742 | if (mask & (setmask << new_base)) |
c19d1205 | 1743 | { |
dcbf9037 | 1744 | first_error (_("invalid register list")); |
c19d1205 | 1745 | return FAIL; |
a737bd4d | 1746 | } |
a737bd4d | 1747 | |
c19d1205 ZW |
1748 | if ((mask >> new_base) != 0 && ! warned) |
1749 | { | |
1750 | as_tsktsk (_("register list not in ascending order")); | |
1751 | warned = 1; | |
1752 | } | |
0bbf2aa4 | 1753 | |
5287ad62 JB |
1754 | mask |= setmask << new_base; |
1755 | count += addregs; | |
0bbf2aa4 | 1756 | |
037e8744 | 1757 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1758 | { |
1759 | int high_range; | |
0bbf2aa4 | 1760 | |
037e8744 | 1761 | str++; |
0bbf2aa4 | 1762 | |
037e8744 | 1763 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1764 | == FAIL) |
c19d1205 ZW |
1765 | { |
1766 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1767 | return FAIL; | |
1768 | } | |
0bbf2aa4 | 1769 | |
b7fc2769 JB |
1770 | if (high_range >= max_regs) |
1771 | { | |
1772 | first_error (_("register out of range in list")); | |
1773 | return FAIL; | |
1774 | } | |
1775 | ||
5287ad62 JB |
1776 | if (regtype == REG_TYPE_NQ) |
1777 | high_range = high_range + 1; | |
1778 | ||
c19d1205 ZW |
1779 | if (high_range <= new_base) |
1780 | { | |
1781 | inst.error = _("register range not in ascending order"); | |
1782 | return FAIL; | |
1783 | } | |
0bbf2aa4 | 1784 | |
5287ad62 | 1785 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1786 | { |
5287ad62 | 1787 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1788 | { |
c19d1205 ZW |
1789 | inst.error = _("invalid register list"); |
1790 | return FAIL; | |
0bbf2aa4 | 1791 | } |
c19d1205 | 1792 | |
5287ad62 JB |
1793 | mask |= setmask << new_base; |
1794 | count += addregs; | |
0bbf2aa4 | 1795 | } |
0bbf2aa4 | 1796 | } |
0bbf2aa4 | 1797 | } |
037e8744 | 1798 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1799 | |
037e8744 | 1800 | str++; |
0bbf2aa4 | 1801 | |
c19d1205 ZW |
1802 | /* Sanity check -- should have raised a parse error above. */ |
1803 | if (count == 0 || count > max_regs) | |
1804 | abort (); | |
1805 | ||
1806 | *pbase = base_reg; | |
1807 | ||
1808 | /* Final test -- the registers must be consecutive. */ | |
1809 | mask >>= base_reg; | |
1810 | for (i = 0; i < count; i++) | |
1811 | { | |
1812 | if ((mask & (1u << i)) == 0) | |
1813 | { | |
1814 | inst.error = _("non-contiguous register range"); | |
1815 | return FAIL; | |
1816 | } | |
1817 | } | |
1818 | ||
037e8744 JB |
1819 | *ccp = str; |
1820 | ||
c19d1205 | 1821 | return count; |
b99bd4ef NC |
1822 | } |
1823 | ||
dcbf9037 JB |
1824 | /* True if two alias types are the same. */ |
1825 | ||
c921be7d | 1826 | static bfd_boolean |
dcbf9037 JB |
1827 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1828 | { | |
1829 | if (!a && !b) | |
c921be7d | 1830 | return TRUE; |
5f4273c7 | 1831 | |
dcbf9037 | 1832 | if (!a || !b) |
c921be7d | 1833 | return FALSE; |
dcbf9037 JB |
1834 | |
1835 | if (a->defined != b->defined) | |
c921be7d | 1836 | return FALSE; |
5f4273c7 | 1837 | |
dcbf9037 JB |
1838 | if ((a->defined & NTA_HASTYPE) != 0 |
1839 | && (a->eltype.type != b->eltype.type | |
1840 | || a->eltype.size != b->eltype.size)) | |
c921be7d | 1841 | return FALSE; |
dcbf9037 JB |
1842 | |
1843 | if ((a->defined & NTA_HASINDEX) != 0 | |
1844 | && (a->index != b->index)) | |
c921be7d | 1845 | return FALSE; |
5f4273c7 | 1846 | |
c921be7d | 1847 | return TRUE; |
dcbf9037 JB |
1848 | } |
1849 | ||
5287ad62 JB |
1850 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1851 | The base register is put in *PBASE. | |
dcbf9037 | 1852 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1853 | the return value. |
1854 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1855 | Bits [6:5] encode the list length (minus one). |
1856 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1857 | |
5287ad62 | 1858 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1859 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1860 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1861 | ||
1862 | static int | |
dcbf9037 JB |
1863 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1864 | struct neon_type_el *eltype) | |
5287ad62 JB |
1865 | { |
1866 | char *ptr = *str; | |
1867 | int base_reg = -1; | |
1868 | int reg_incr = -1; | |
1869 | int count = 0; | |
1870 | int lane = -1; | |
1871 | int leading_brace = 0; | |
1872 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
1873 | int addregs = 1; | |
20203fb9 NC |
1874 | const char *const incr_error = _("register stride must be 1 or 2"); |
1875 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 1876 | struct neon_typed_alias firsttype; |
5f4273c7 | 1877 | |
5287ad62 JB |
1878 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1879 | leading_brace = 1; | |
5f4273c7 | 1880 | |
5287ad62 JB |
1881 | do |
1882 | { | |
dcbf9037 JB |
1883 | struct neon_typed_alias atype; |
1884 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1885 | ||
5287ad62 JB |
1886 | if (getreg == FAIL) |
1887 | { | |
dcbf9037 | 1888 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1889 | return FAIL; |
1890 | } | |
5f4273c7 | 1891 | |
5287ad62 JB |
1892 | if (base_reg == -1) |
1893 | { | |
1894 | base_reg = getreg; | |
1895 | if (rtype == REG_TYPE_NQ) | |
1896 | { | |
1897 | reg_incr = 1; | |
1898 | addregs = 2; | |
1899 | } | |
dcbf9037 | 1900 | firsttype = atype; |
5287ad62 JB |
1901 | } |
1902 | else if (reg_incr == -1) | |
1903 | { | |
1904 | reg_incr = getreg - base_reg; | |
1905 | if (reg_incr < 1 || reg_incr > 2) | |
1906 | { | |
dcbf9037 | 1907 | first_error (_(incr_error)); |
5287ad62 JB |
1908 | return FAIL; |
1909 | } | |
1910 | } | |
1911 | else if (getreg != base_reg + reg_incr * count) | |
1912 | { | |
dcbf9037 JB |
1913 | first_error (_(incr_error)); |
1914 | return FAIL; | |
1915 | } | |
1916 | ||
c921be7d | 1917 | if (! neon_alias_types_same (&atype, &firsttype)) |
dcbf9037 JB |
1918 | { |
1919 | first_error (_(type_error)); | |
5287ad62 JB |
1920 | return FAIL; |
1921 | } | |
5f4273c7 | 1922 | |
5287ad62 JB |
1923 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
1924 | modes. */ | |
1925 | if (ptr[0] == '-') | |
1926 | { | |
dcbf9037 | 1927 | struct neon_typed_alias htype; |
5287ad62 JB |
1928 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1929 | if (lane == -1) | |
1930 | lane = NEON_INTERLEAVE_LANES; | |
1931 | else if (lane != NEON_INTERLEAVE_LANES) | |
1932 | { | |
dcbf9037 | 1933 | first_error (_(type_error)); |
5287ad62 JB |
1934 | return FAIL; |
1935 | } | |
1936 | if (reg_incr == -1) | |
1937 | reg_incr = 1; | |
1938 | else if (reg_incr != 1) | |
1939 | { | |
dcbf9037 | 1940 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
1941 | return FAIL; |
1942 | } | |
1943 | ptr++; | |
dcbf9037 | 1944 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
1945 | if (hireg == FAIL) |
1946 | { | |
dcbf9037 JB |
1947 | first_error (_(reg_expected_msgs[rtype])); |
1948 | return FAIL; | |
1949 | } | |
c921be7d | 1950 | if (! neon_alias_types_same (&htype, &firsttype)) |
dcbf9037 JB |
1951 | { |
1952 | first_error (_(type_error)); | |
5287ad62 JB |
1953 | return FAIL; |
1954 | } | |
1955 | count += hireg + dregs - getreg; | |
1956 | continue; | |
1957 | } | |
5f4273c7 | 1958 | |
5287ad62 JB |
1959 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
1960 | if (rtype == REG_TYPE_NQ) | |
1961 | { | |
1962 | count += 2; | |
1963 | continue; | |
1964 | } | |
5f4273c7 | 1965 | |
dcbf9037 | 1966 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 1967 | { |
dcbf9037 JB |
1968 | if (lane == -1) |
1969 | lane = atype.index; | |
1970 | else if (lane != atype.index) | |
5287ad62 | 1971 | { |
dcbf9037 JB |
1972 | first_error (_(type_error)); |
1973 | return FAIL; | |
5287ad62 JB |
1974 | } |
1975 | } | |
1976 | else if (lane == -1) | |
1977 | lane = NEON_INTERLEAVE_LANES; | |
1978 | else if (lane != NEON_INTERLEAVE_LANES) | |
1979 | { | |
dcbf9037 | 1980 | first_error (_(type_error)); |
5287ad62 JB |
1981 | return FAIL; |
1982 | } | |
1983 | count++; | |
1984 | } | |
1985 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 1986 | |
5287ad62 JB |
1987 | /* No lane set by [x]. We must be interleaving structures. */ |
1988 | if (lane == -1) | |
1989 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 1990 | |
5287ad62 JB |
1991 | /* Sanity check. */ |
1992 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
1993 | || (count > 1 && reg_incr == -1)) | |
1994 | { | |
dcbf9037 | 1995 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
1996 | return FAIL; |
1997 | } | |
1998 | ||
1999 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2000 | { | |
dcbf9037 | 2001 | first_error (_("expected }")); |
5287ad62 JB |
2002 | return FAIL; |
2003 | } | |
5f4273c7 | 2004 | |
5287ad62 JB |
2005 | if (reg_incr == -1) |
2006 | reg_incr = 1; | |
2007 | ||
dcbf9037 JB |
2008 | if (eltype) |
2009 | *eltype = firsttype.eltype; | |
2010 | ||
5287ad62 JB |
2011 | *pbase = base_reg; |
2012 | *str = ptr; | |
5f4273c7 | 2013 | |
5287ad62 JB |
2014 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2015 | } | |
2016 | ||
c19d1205 ZW |
2017 | /* Parse an explicit relocation suffix on an expression. This is |
2018 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2019 | arm_reloc_hsh contains no entries, so this function can only | |
2020 | succeed if there is no () after the word. Returns -1 on error, | |
2021 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
2022 | static int | |
2023 | parse_reloc (char **str) | |
b99bd4ef | 2024 | { |
c19d1205 ZW |
2025 | struct reloc_entry *r; |
2026 | char *p, *q; | |
b99bd4ef | 2027 | |
c19d1205 ZW |
2028 | if (**str != '(') |
2029 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2030 | |
c19d1205 ZW |
2031 | p = *str + 1; |
2032 | q = p; | |
2033 | ||
2034 | while (*q && *q != ')' && *q != ',') | |
2035 | q++; | |
2036 | if (*q != ')') | |
2037 | return -1; | |
2038 | ||
2039 | if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
2040 | return -1; | |
2041 | ||
2042 | *str = q + 1; | |
2043 | return r->reloc; | |
b99bd4ef NC |
2044 | } |
2045 | ||
c19d1205 ZW |
2046 | /* Directives: register aliases. */ |
2047 | ||
dcbf9037 | 2048 | static struct reg_entry * |
c19d1205 | 2049 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 2050 | { |
c19d1205 ZW |
2051 | struct reg_entry *new; |
2052 | const char *name; | |
b99bd4ef | 2053 | |
c19d1205 ZW |
2054 | if ((new = hash_find (arm_reg_hsh, str)) != 0) |
2055 | { | |
2056 | if (new->builtin) | |
2057 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); | |
b99bd4ef | 2058 | |
c19d1205 ZW |
2059 | /* Only warn about a redefinition if it's not defined as the |
2060 | same register. */ | |
2061 | else if (new->number != number || new->type != type) | |
2062 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
69b97547 | 2063 | |
d929913e | 2064 | return NULL; |
c19d1205 | 2065 | } |
b99bd4ef | 2066 | |
c19d1205 ZW |
2067 | name = xstrdup (str); |
2068 | new = xmalloc (sizeof (struct reg_entry)); | |
b99bd4ef | 2069 | |
c19d1205 ZW |
2070 | new->name = name; |
2071 | new->number = number; | |
2072 | new->type = type; | |
2073 | new->builtin = FALSE; | |
dcbf9037 | 2074 | new->neon = NULL; |
b99bd4ef | 2075 | |
5a49b8ac | 2076 | if (hash_insert (arm_reg_hsh, name, (void *) new)) |
c19d1205 | 2077 | abort (); |
5f4273c7 | 2078 | |
dcbf9037 JB |
2079 | return new; |
2080 | } | |
2081 | ||
2082 | static void | |
2083 | insert_neon_reg_alias (char *str, int number, int type, | |
2084 | struct neon_typed_alias *atype) | |
2085 | { | |
2086 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2087 | |
dcbf9037 JB |
2088 | if (!reg) |
2089 | { | |
2090 | first_error (_("attempt to redefine typed alias")); | |
2091 | return; | |
2092 | } | |
5f4273c7 | 2093 | |
dcbf9037 JB |
2094 | if (atype) |
2095 | { | |
2096 | reg->neon = xmalloc (sizeof (struct neon_typed_alias)); | |
2097 | *reg->neon = *atype; | |
2098 | } | |
c19d1205 | 2099 | } |
b99bd4ef | 2100 | |
c19d1205 | 2101 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2102 | |
c19d1205 | 2103 | new_register_name .req existing_register_name |
b99bd4ef | 2104 | |
c19d1205 | 2105 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2106 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2107 | |
d929913e | 2108 | static bfd_boolean |
c19d1205 ZW |
2109 | create_register_alias (char * newname, char *p) |
2110 | { | |
2111 | struct reg_entry *old; | |
2112 | char *oldname, *nbuf; | |
2113 | size_t nlen; | |
b99bd4ef | 2114 | |
c19d1205 ZW |
2115 | /* The input scrubber ensures that whitespace after the mnemonic is |
2116 | collapsed to single spaces. */ | |
2117 | oldname = p; | |
2118 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2119 | return FALSE; |
b99bd4ef | 2120 | |
c19d1205 ZW |
2121 | oldname += 6; |
2122 | if (*oldname == '\0') | |
d929913e | 2123 | return FALSE; |
b99bd4ef | 2124 | |
c19d1205 ZW |
2125 | old = hash_find (arm_reg_hsh, oldname); |
2126 | if (!old) | |
b99bd4ef | 2127 | { |
c19d1205 | 2128 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2129 | return TRUE; |
b99bd4ef NC |
2130 | } |
2131 | ||
c19d1205 ZW |
2132 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2133 | the desired alias name, and p points to its end. If not, then | |
2134 | the desired alias name is in the global original_case_string. */ | |
2135 | #ifdef TC_CASE_SENSITIVE | |
2136 | nlen = p - newname; | |
2137 | #else | |
2138 | newname = original_case_string; | |
2139 | nlen = strlen (newname); | |
2140 | #endif | |
b99bd4ef | 2141 | |
c19d1205 ZW |
2142 | nbuf = alloca (nlen + 1); |
2143 | memcpy (nbuf, newname, nlen); | |
2144 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2145 | |
c19d1205 ZW |
2146 | /* Create aliases under the new name as stated; an all-lowercase |
2147 | version of the new name; and an all-uppercase version of the new | |
2148 | name. */ | |
d929913e NC |
2149 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2150 | { | |
2151 | for (p = nbuf; *p; p++) | |
2152 | *p = TOUPPER (*p); | |
c19d1205 | 2153 | |
d929913e NC |
2154 | if (strncmp (nbuf, newname, nlen)) |
2155 | { | |
2156 | /* If this attempt to create an additional alias fails, do not bother | |
2157 | trying to create the all-lower case alias. We will fail and issue | |
2158 | a second, duplicate error message. This situation arises when the | |
2159 | programmer does something like: | |
2160 | foo .req r0 | |
2161 | Foo .req r1 | |
2162 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2163 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2164 | first .req. */ |
2165 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
2166 | return TRUE; | |
2167 | } | |
c19d1205 | 2168 | |
d929913e NC |
2169 | for (p = nbuf; *p; p++) |
2170 | *p = TOLOWER (*p); | |
c19d1205 | 2171 | |
d929913e NC |
2172 | if (strncmp (nbuf, newname, nlen)) |
2173 | insert_reg_alias (nbuf, old->number, old->type); | |
2174 | } | |
c19d1205 | 2175 | |
d929913e | 2176 | return TRUE; |
b99bd4ef NC |
2177 | } |
2178 | ||
dcbf9037 JB |
2179 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2180 | X .dn d5.s32[1] | |
2181 | Y .qn 6.s16 | |
2182 | Z .dn d7 | |
2183 | T .dn Z[0] | |
2184 | These typed registers can be used instead of the types specified after the | |
2185 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2186 | specified directly, e.g.: | |
5f4273c7 | 2187 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2188 | |
c921be7d | 2189 | static bfd_boolean |
dcbf9037 JB |
2190 | create_neon_reg_alias (char *newname, char *p) |
2191 | { | |
2192 | enum arm_reg_type basetype; | |
2193 | struct reg_entry *basereg; | |
2194 | struct reg_entry mybasereg; | |
2195 | struct neon_type ntype; | |
2196 | struct neon_typed_alias typeinfo; | |
2197 | char *namebuf, *nameend; | |
2198 | int namelen; | |
5f4273c7 | 2199 | |
dcbf9037 JB |
2200 | typeinfo.defined = 0; |
2201 | typeinfo.eltype.type = NT_invtype; | |
2202 | typeinfo.eltype.size = -1; | |
2203 | typeinfo.index = -1; | |
5f4273c7 | 2204 | |
dcbf9037 | 2205 | nameend = p; |
5f4273c7 | 2206 | |
dcbf9037 JB |
2207 | if (strncmp (p, " .dn ", 5) == 0) |
2208 | basetype = REG_TYPE_VFD; | |
2209 | else if (strncmp (p, " .qn ", 5) == 0) | |
2210 | basetype = REG_TYPE_NQ; | |
2211 | else | |
c921be7d | 2212 | return FALSE; |
5f4273c7 | 2213 | |
dcbf9037 | 2214 | p += 5; |
5f4273c7 | 2215 | |
dcbf9037 | 2216 | if (*p == '\0') |
c921be7d | 2217 | return FALSE; |
5f4273c7 | 2218 | |
dcbf9037 JB |
2219 | basereg = arm_reg_parse_multi (&p); |
2220 | ||
2221 | if (basereg && basereg->type != basetype) | |
2222 | { | |
2223 | as_bad (_("bad type for register")); | |
c921be7d | 2224 | return FALSE; |
dcbf9037 JB |
2225 | } |
2226 | ||
2227 | if (basereg == NULL) | |
2228 | { | |
2229 | expressionS exp; | |
2230 | /* Try parsing as an integer. */ | |
2231 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2232 | if (exp.X_op != O_constant) | |
2233 | { | |
2234 | as_bad (_("expression must be constant")); | |
c921be7d | 2235 | return FALSE; |
dcbf9037 JB |
2236 | } |
2237 | basereg = &mybasereg; | |
2238 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2239 | : exp.X_add_number; | |
2240 | basereg->neon = 0; | |
2241 | } | |
2242 | ||
2243 | if (basereg->neon) | |
2244 | typeinfo = *basereg->neon; | |
2245 | ||
2246 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2247 | { | |
2248 | /* We got a type. */ | |
2249 | if (typeinfo.defined & NTA_HASTYPE) | |
2250 | { | |
2251 | as_bad (_("can't redefine the type of a register alias")); | |
c921be7d | 2252 | return FALSE; |
dcbf9037 | 2253 | } |
5f4273c7 | 2254 | |
dcbf9037 JB |
2255 | typeinfo.defined |= NTA_HASTYPE; |
2256 | if (ntype.elems != 1) | |
2257 | { | |
2258 | as_bad (_("you must specify a single type only")); | |
c921be7d | 2259 | return FALSE; |
dcbf9037 JB |
2260 | } |
2261 | typeinfo.eltype = ntype.el[0]; | |
2262 | } | |
5f4273c7 | 2263 | |
dcbf9037 JB |
2264 | if (skip_past_char (&p, '[') == SUCCESS) |
2265 | { | |
2266 | expressionS exp; | |
2267 | /* We got a scalar index. */ | |
5f4273c7 | 2268 | |
dcbf9037 JB |
2269 | if (typeinfo.defined & NTA_HASINDEX) |
2270 | { | |
2271 | as_bad (_("can't redefine the index of a scalar alias")); | |
c921be7d | 2272 | return FALSE; |
dcbf9037 | 2273 | } |
5f4273c7 | 2274 | |
dcbf9037 | 2275 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2276 | |
dcbf9037 JB |
2277 | if (exp.X_op != O_constant) |
2278 | { | |
2279 | as_bad (_("scalar index must be constant")); | |
c921be7d | 2280 | return FALSE; |
dcbf9037 | 2281 | } |
5f4273c7 | 2282 | |
dcbf9037 JB |
2283 | typeinfo.defined |= NTA_HASINDEX; |
2284 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2285 | |
dcbf9037 JB |
2286 | if (skip_past_char (&p, ']') == FAIL) |
2287 | { | |
2288 | as_bad (_("expecting ]")); | |
c921be7d | 2289 | return FALSE; |
dcbf9037 JB |
2290 | } |
2291 | } | |
2292 | ||
2293 | namelen = nameend - newname; | |
2294 | namebuf = alloca (namelen + 1); | |
2295 | strncpy (namebuf, newname, namelen); | |
2296 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2297 | |
dcbf9037 JB |
2298 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
2299 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2300 | |
dcbf9037 JB |
2301 | /* Insert name in all uppercase. */ |
2302 | for (p = namebuf; *p; p++) | |
2303 | *p = TOUPPER (*p); | |
5f4273c7 | 2304 | |
dcbf9037 JB |
2305 | if (strncmp (namebuf, newname, namelen)) |
2306 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2307 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2308 | |
dcbf9037 JB |
2309 | /* Insert name in all lowercase. */ |
2310 | for (p = namebuf; *p; p++) | |
2311 | *p = TOLOWER (*p); | |
5f4273c7 | 2312 | |
dcbf9037 JB |
2313 | if (strncmp (namebuf, newname, namelen)) |
2314 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2315 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2316 | |
c921be7d | 2317 | return TRUE; |
dcbf9037 JB |
2318 | } |
2319 | ||
c19d1205 ZW |
2320 | /* Should never be called, as .req goes between the alias and the |
2321 | register name, not at the beginning of the line. */ | |
c921be7d | 2322 | |
b99bd4ef | 2323 | static void |
c19d1205 | 2324 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2325 | { |
c19d1205 ZW |
2326 | as_bad (_("invalid syntax for .req directive")); |
2327 | } | |
b99bd4ef | 2328 | |
dcbf9037 JB |
2329 | static void |
2330 | s_dn (int a ATTRIBUTE_UNUSED) | |
2331 | { | |
2332 | as_bad (_("invalid syntax for .dn directive")); | |
2333 | } | |
2334 | ||
2335 | static void | |
2336 | s_qn (int a ATTRIBUTE_UNUSED) | |
2337 | { | |
2338 | as_bad (_("invalid syntax for .qn directive")); | |
2339 | } | |
2340 | ||
c19d1205 ZW |
2341 | /* The .unreq directive deletes an alias which was previously defined |
2342 | by .req. For example: | |
b99bd4ef | 2343 | |
c19d1205 ZW |
2344 | my_alias .req r11 |
2345 | .unreq my_alias */ | |
b99bd4ef NC |
2346 | |
2347 | static void | |
c19d1205 | 2348 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2349 | { |
c19d1205 ZW |
2350 | char * name; |
2351 | char saved_char; | |
b99bd4ef | 2352 | |
c19d1205 ZW |
2353 | name = input_line_pointer; |
2354 | ||
2355 | while (*input_line_pointer != 0 | |
2356 | && *input_line_pointer != ' ' | |
2357 | && *input_line_pointer != '\n') | |
2358 | ++input_line_pointer; | |
2359 | ||
2360 | saved_char = *input_line_pointer; | |
2361 | *input_line_pointer = 0; | |
2362 | ||
2363 | if (!*name) | |
2364 | as_bad (_("invalid syntax for .unreq directive")); | |
2365 | else | |
2366 | { | |
2367 | struct reg_entry *reg = hash_find (arm_reg_hsh, name); | |
2368 | ||
2369 | if (!reg) | |
2370 | as_bad (_("unknown register alias '%s'"), name); | |
2371 | else if (reg->builtin) | |
2372 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
2373 | name); | |
2374 | else | |
2375 | { | |
d929913e NC |
2376 | char * p; |
2377 | char * nbuf; | |
2378 | ||
db0bc284 | 2379 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2380 | free ((char *) reg->name); |
dcbf9037 JB |
2381 | if (reg->neon) |
2382 | free (reg->neon); | |
c19d1205 | 2383 | free (reg); |
d929913e NC |
2384 | |
2385 | /* Also locate the all upper case and all lower case versions. | |
2386 | Do not complain if we cannot find one or the other as it | |
2387 | was probably deleted above. */ | |
5f4273c7 | 2388 | |
d929913e NC |
2389 | nbuf = strdup (name); |
2390 | for (p = nbuf; *p; p++) | |
2391 | *p = TOUPPER (*p); | |
2392 | reg = hash_find (arm_reg_hsh, nbuf); | |
2393 | if (reg) | |
2394 | { | |
db0bc284 | 2395 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2396 | free ((char *) reg->name); |
2397 | if (reg->neon) | |
2398 | free (reg->neon); | |
2399 | free (reg); | |
2400 | } | |
2401 | ||
2402 | for (p = nbuf; *p; p++) | |
2403 | *p = TOLOWER (*p); | |
2404 | reg = hash_find (arm_reg_hsh, nbuf); | |
2405 | if (reg) | |
2406 | { | |
db0bc284 | 2407 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2408 | free ((char *) reg->name); |
2409 | if (reg->neon) | |
2410 | free (reg->neon); | |
2411 | free (reg); | |
2412 | } | |
2413 | ||
2414 | free (nbuf); | |
c19d1205 ZW |
2415 | } |
2416 | } | |
b99bd4ef | 2417 | |
c19d1205 | 2418 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2419 | demand_empty_rest_of_line (); |
2420 | } | |
2421 | ||
c19d1205 ZW |
2422 | /* Directives: Instruction set selection. */ |
2423 | ||
2424 | #ifdef OBJ_ELF | |
2425 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2426 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2427 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2428 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2429 | ||
cd000bff DJ |
2430 | /* Create a new mapping symbol for the transition to STATE. */ |
2431 | ||
2432 | static void | |
2433 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2434 | { |
a737bd4d | 2435 | symbolS * symbolP; |
c19d1205 ZW |
2436 | const char * symname; |
2437 | int type; | |
b99bd4ef | 2438 | |
c19d1205 | 2439 | switch (state) |
b99bd4ef | 2440 | { |
c19d1205 ZW |
2441 | case MAP_DATA: |
2442 | symname = "$d"; | |
2443 | type = BSF_NO_FLAGS; | |
2444 | break; | |
2445 | case MAP_ARM: | |
2446 | symname = "$a"; | |
2447 | type = BSF_NO_FLAGS; | |
2448 | break; | |
2449 | case MAP_THUMB: | |
2450 | symname = "$t"; | |
2451 | type = BSF_NO_FLAGS; | |
2452 | break; | |
c19d1205 ZW |
2453 | default: |
2454 | abort (); | |
2455 | } | |
2456 | ||
cd000bff | 2457 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2458 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2459 | ||
2460 | switch (state) | |
2461 | { | |
2462 | case MAP_ARM: | |
2463 | THUMB_SET_FUNC (symbolP, 0); | |
2464 | ARM_SET_THUMB (symbolP, 0); | |
2465 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2466 | break; | |
2467 | ||
2468 | case MAP_THUMB: | |
2469 | THUMB_SET_FUNC (symbolP, 1); | |
2470 | ARM_SET_THUMB (symbolP, 1); | |
2471 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2472 | break; | |
2473 | ||
2474 | case MAP_DATA: | |
2475 | default: | |
cd000bff DJ |
2476 | break; |
2477 | } | |
2478 | ||
2479 | /* Save the mapping symbols for future reference. Also check that | |
2480 | we do not place two mapping symbols at the same offset within a | |
2481 | frag. We'll handle overlap between frags in | |
2482 | check_mapping_symbols. */ | |
2483 | if (value == 0) | |
2484 | { | |
2485 | know (frag->tc_frag_data.first_map == NULL); | |
2486 | frag->tc_frag_data.first_map = symbolP; | |
2487 | } | |
2488 | if (frag->tc_frag_data.last_map != NULL) | |
2489 | know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP)); | |
2490 | frag->tc_frag_data.last_map = symbolP; | |
2491 | } | |
2492 | ||
2493 | /* We must sometimes convert a region marked as code to data during | |
2494 | code alignment, if an odd number of bytes have to be padded. The | |
2495 | code mapping symbol is pushed to an aligned address. */ | |
2496 | ||
2497 | static void | |
2498 | insert_data_mapping_symbol (enum mstate state, | |
2499 | valueT value, fragS *frag, offsetT bytes) | |
2500 | { | |
2501 | /* If there was already a mapping symbol, remove it. */ | |
2502 | if (frag->tc_frag_data.last_map != NULL | |
2503 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2504 | { | |
2505 | symbolS *symp = frag->tc_frag_data.last_map; | |
2506 | ||
2507 | if (value == 0) | |
2508 | { | |
2509 | know (frag->tc_frag_data.first_map == symp); | |
2510 | frag->tc_frag_data.first_map = NULL; | |
2511 | } | |
2512 | frag->tc_frag_data.last_map = NULL; | |
2513 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2514 | } |
cd000bff DJ |
2515 | |
2516 | make_mapping_symbol (MAP_DATA, value, frag); | |
2517 | make_mapping_symbol (state, value + bytes, frag); | |
2518 | } | |
2519 | ||
2520 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2521 | ||
2522 | /* Set the mapping state to STATE. Only call this when about to | |
2523 | emit some STATE bytes to the file. */ | |
2524 | ||
2525 | void | |
2526 | mapping_state (enum mstate state) | |
2527 | { | |
940b5ce0 DJ |
2528 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2529 | ||
cd000bff DJ |
2530 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
2531 | ||
2532 | if (mapstate == state) | |
2533 | /* The mapping symbol has already been emitted. | |
2534 | There is nothing else to do. */ | |
2535 | return; | |
2536 | else if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
2537 | /* This case will be evaluated later in the next else. */ | |
2538 | return; | |
2539 | else if (TRANSITION (MAP_UNDEFINED, MAP_ARM) | |
2540 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2541 | { | |
2542 | /* Only add the symbol if the offset is > 0: | |
2543 | if we're at the first frag, check it's size > 0; | |
2544 | if we're not at the first frag, then for sure | |
2545 | the offset is > 0. */ | |
2546 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2547 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2548 | ||
2549 | if (add_symbol) | |
2550 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2551 | } | |
2552 | ||
2553 | mapping_state_2 (state, 0); | |
2554 | #undef TRANSITION | |
2555 | } | |
2556 | ||
2557 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2558 | allocated. Put the mapping symbol that far back. */ | |
2559 | ||
2560 | static void | |
2561 | mapping_state_2 (enum mstate state, int max_chars) | |
2562 | { | |
940b5ce0 DJ |
2563 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2564 | ||
2565 | if (!SEG_NORMAL (now_seg)) | |
2566 | return; | |
2567 | ||
cd000bff DJ |
2568 | if (mapstate == state) |
2569 | /* The mapping symbol has already been emitted. | |
2570 | There is nothing else to do. */ | |
2571 | return; | |
2572 | ||
cd000bff DJ |
2573 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2574 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 ZW |
2575 | } |
2576 | #else | |
2577 | #define mapping_state(x) /* nothing */ | |
cd000bff | 2578 | #define mapping_state_2(x, y) /* nothing */ |
c19d1205 ZW |
2579 | #endif |
2580 | ||
2581 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2582 | ||
4343666d | 2583 | #ifdef OBJ_COFF |
c19d1205 ZW |
2584 | static symbolS * |
2585 | find_real_start (symbolS * symbolP) | |
2586 | { | |
2587 | char * real_start; | |
2588 | const char * name = S_GET_NAME (symbolP); | |
2589 | symbolS * new_target; | |
2590 | ||
2591 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2592 | #define STUB_NAME ".real_start_of" | |
2593 | ||
2594 | if (name == NULL) | |
2595 | abort (); | |
2596 | ||
37f6032b ZW |
2597 | /* The compiler may generate BL instructions to local labels because |
2598 | it needs to perform a branch to a far away location. These labels | |
2599 | do not have a corresponding ".real_start_of" label. We check | |
2600 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2601 | the ".real_start_of" convention for nonlocal branches. */ | |
2602 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2603 | return symbolP; |
2604 | ||
37f6032b | 2605 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2606 | new_target = symbol_find (real_start); |
2607 | ||
2608 | if (new_target == NULL) | |
2609 | { | |
bd3ba5d1 | 2610 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2611 | new_target = symbolP; |
2612 | } | |
2613 | ||
c19d1205 ZW |
2614 | return new_target; |
2615 | } | |
4343666d | 2616 | #endif |
c19d1205 ZW |
2617 | |
2618 | static void | |
2619 | opcode_select (int width) | |
2620 | { | |
2621 | switch (width) | |
2622 | { | |
2623 | case 16: | |
2624 | if (! thumb_mode) | |
2625 | { | |
e74cfd16 | 2626 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2627 | as_bad (_("selected processor does not support THUMB opcodes")); |
2628 | ||
2629 | thumb_mode = 1; | |
2630 | /* No need to force the alignment, since we will have been | |
2631 | coming from ARM mode, which is word-aligned. */ | |
2632 | record_alignment (now_seg, 1); | |
2633 | } | |
c19d1205 ZW |
2634 | break; |
2635 | ||
2636 | case 32: | |
2637 | if (thumb_mode) | |
2638 | { | |
e74cfd16 | 2639 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2640 | as_bad (_("selected processor does not support ARM opcodes")); |
2641 | ||
2642 | thumb_mode = 0; | |
2643 | ||
2644 | if (!need_pass_2) | |
2645 | frag_align (2, 0, 0); | |
2646 | ||
2647 | record_alignment (now_seg, 1); | |
2648 | } | |
c19d1205 ZW |
2649 | break; |
2650 | ||
2651 | default: | |
2652 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2653 | } | |
2654 | } | |
2655 | ||
2656 | static void | |
2657 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2658 | { | |
2659 | opcode_select (32); | |
2660 | demand_empty_rest_of_line (); | |
2661 | } | |
2662 | ||
2663 | static void | |
2664 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2665 | { | |
2666 | opcode_select (16); | |
2667 | demand_empty_rest_of_line (); | |
2668 | } | |
2669 | ||
2670 | static void | |
2671 | s_code (int unused ATTRIBUTE_UNUSED) | |
2672 | { | |
2673 | int temp; | |
2674 | ||
2675 | temp = get_absolute_expression (); | |
2676 | switch (temp) | |
2677 | { | |
2678 | case 16: | |
2679 | case 32: | |
2680 | opcode_select (temp); | |
2681 | break; | |
2682 | ||
2683 | default: | |
2684 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2685 | } | |
2686 | } | |
2687 | ||
2688 | static void | |
2689 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2690 | { | |
2691 | /* If we are not already in thumb mode go into it, EVEN if | |
2692 | the target processor does not support thumb instructions. | |
2693 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2694 | to compile interworking support functions even if the | |
2695 | target processor should not support interworking. */ | |
2696 | if (! thumb_mode) | |
2697 | { | |
2698 | thumb_mode = 2; | |
2699 | record_alignment (now_seg, 1); | |
2700 | } | |
2701 | ||
2702 | demand_empty_rest_of_line (); | |
2703 | } | |
2704 | ||
2705 | static void | |
2706 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2707 | { | |
2708 | s_thumb (0); | |
2709 | ||
2710 | /* The following label is the name/address of the start of a Thumb function. | |
2711 | We need to know this for the interworking support. */ | |
2712 | label_is_thumb_function_name = TRUE; | |
2713 | } | |
2714 | ||
2715 | /* Perform a .set directive, but also mark the alias as | |
2716 | being a thumb function. */ | |
2717 | ||
2718 | static void | |
2719 | s_thumb_set (int equiv) | |
2720 | { | |
2721 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2722 | We cannot just call that code as we need to get at the symbol that | |
2723 | is created. */ | |
2724 | char * name; | |
2725 | char delim; | |
2726 | char * end_name; | |
2727 | symbolS * symbolP; | |
2728 | ||
2729 | /* Especial apologies for the random logic: | |
2730 | This just grew, and could be parsed much more simply! | |
2731 | Dean - in haste. */ | |
2732 | name = input_line_pointer; | |
2733 | delim = get_symbol_end (); | |
2734 | end_name = input_line_pointer; | |
2735 | *end_name = delim; | |
2736 | ||
2737 | if (*input_line_pointer != ',') | |
2738 | { | |
2739 | *end_name = 0; | |
2740 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2741 | *end_name = delim; |
2742 | ignore_rest_of_line (); | |
2743 | return; | |
2744 | } | |
2745 | ||
2746 | input_line_pointer++; | |
2747 | *end_name = 0; | |
2748 | ||
2749 | if (name[0] == '.' && name[1] == '\0') | |
2750 | { | |
2751 | /* XXX - this should not happen to .thumb_set. */ | |
2752 | abort (); | |
2753 | } | |
2754 | ||
2755 | if ((symbolP = symbol_find (name)) == NULL | |
2756 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2757 | { | |
2758 | #ifndef NO_LISTING | |
2759 | /* When doing symbol listings, play games with dummy fragments living | |
2760 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2761 | for this symbol. */ |
b99bd4ef NC |
2762 | if (listing & LISTING_SYMBOLS) |
2763 | { | |
2764 | extern struct list_info_struct * listing_tail; | |
a737bd4d | 2765 | fragS * dummy_frag = xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2766 | |
2767 | memset (dummy_frag, 0, sizeof (fragS)); | |
2768 | dummy_frag->fr_type = rs_fill; | |
2769 | dummy_frag->line = listing_tail; | |
2770 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2771 | dummy_frag->fr_symbol = symbolP; | |
2772 | } | |
2773 | else | |
2774 | #endif | |
2775 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2776 | ||
2777 | #ifdef OBJ_COFF | |
2778 | /* "set" symbols are local unless otherwise specified. */ | |
2779 | SF_SET_LOCAL (symbolP); | |
2780 | #endif /* OBJ_COFF */ | |
2781 | } /* Make a new symbol. */ | |
2782 | ||
2783 | symbol_table_insert (symbolP); | |
2784 | ||
2785 | * end_name = delim; | |
2786 | ||
2787 | if (equiv | |
2788 | && S_IS_DEFINED (symbolP) | |
2789 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2790 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2791 | ||
2792 | pseudo_set (symbolP); | |
2793 | ||
2794 | demand_empty_rest_of_line (); | |
2795 | ||
c19d1205 | 2796 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2797 | |
2798 | THUMB_SET_FUNC (symbolP, 1); | |
2799 | ARM_SET_THUMB (symbolP, 1); | |
2800 | #if defined OBJ_ELF || defined OBJ_COFF | |
2801 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2802 | #endif | |
2803 | } | |
2804 | ||
c19d1205 | 2805 | /* Directives: Mode selection. */ |
b99bd4ef | 2806 | |
c19d1205 ZW |
2807 | /* .syntax [unified|divided] - choose the new unified syntax |
2808 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2809 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2810 | static void |
c19d1205 | 2811 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2812 | { |
c19d1205 ZW |
2813 | char *name, delim; |
2814 | ||
2815 | name = input_line_pointer; | |
2816 | delim = get_symbol_end (); | |
2817 | ||
2818 | if (!strcasecmp (name, "unified")) | |
2819 | unified_syntax = TRUE; | |
2820 | else if (!strcasecmp (name, "divided")) | |
2821 | unified_syntax = FALSE; | |
2822 | else | |
2823 | { | |
2824 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2825 | return; | |
2826 | } | |
2827 | *input_line_pointer = delim; | |
b99bd4ef NC |
2828 | demand_empty_rest_of_line (); |
2829 | } | |
2830 | ||
c19d1205 ZW |
2831 | /* Directives: sectioning and alignment. */ |
2832 | ||
2833 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2834 | ||
b99bd4ef | 2835 | static void |
c19d1205 | 2836 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2837 | { |
a737bd4d | 2838 | int temp; |
dce323d1 | 2839 | bfd_boolean fill_p; |
c19d1205 ZW |
2840 | long temp_fill; |
2841 | long max_alignment = 15; | |
b99bd4ef NC |
2842 | |
2843 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2844 | if (temp > max_alignment) |
2845 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2846 | else if (temp < 0) | |
b99bd4ef | 2847 | { |
c19d1205 ZW |
2848 | as_bad (_("alignment negative. 0 assumed.")); |
2849 | temp = 0; | |
2850 | } | |
b99bd4ef | 2851 | |
c19d1205 ZW |
2852 | if (*input_line_pointer == ',') |
2853 | { | |
2854 | input_line_pointer++; | |
2855 | temp_fill = get_absolute_expression (); | |
dce323d1 | 2856 | fill_p = TRUE; |
b99bd4ef | 2857 | } |
c19d1205 | 2858 | else |
dce323d1 PB |
2859 | { |
2860 | fill_p = FALSE; | |
2861 | temp_fill = 0; | |
2862 | } | |
b99bd4ef | 2863 | |
c19d1205 ZW |
2864 | if (!temp) |
2865 | temp = 2; | |
b99bd4ef | 2866 | |
c19d1205 ZW |
2867 | /* Only make a frag if we HAVE to. */ |
2868 | if (temp && !need_pass_2) | |
dce323d1 PB |
2869 | { |
2870 | if (!fill_p && subseg_text_p (now_seg)) | |
2871 | frag_align_code (temp, 0); | |
2872 | else | |
2873 | frag_align (temp, (int) temp_fill, 0); | |
2874 | } | |
c19d1205 ZW |
2875 | demand_empty_rest_of_line (); |
2876 | ||
2877 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2878 | } |
2879 | ||
c19d1205 ZW |
2880 | static void |
2881 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2882 | { |
c19d1205 ZW |
2883 | /* We don't support putting frags in the BSS segment, we fake it by |
2884 | marking in_bss, then looking at s_skip for clues. */ | |
2885 | subseg_set (bss_section, 0); | |
2886 | demand_empty_rest_of_line (); | |
cd000bff DJ |
2887 | |
2888 | #ifdef md_elf_section_change_hook | |
2889 | md_elf_section_change_hook (); | |
2890 | #endif | |
c19d1205 | 2891 | } |
b99bd4ef | 2892 | |
c19d1205 ZW |
2893 | static void |
2894 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2895 | { | |
2896 | /* Never make frag if expect extra pass. */ | |
2897 | if (!need_pass_2) | |
2898 | frag_align (1, 0, 0); | |
b99bd4ef | 2899 | |
c19d1205 | 2900 | record_alignment (now_seg, 1); |
b99bd4ef | 2901 | |
c19d1205 | 2902 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2903 | } |
2904 | ||
c19d1205 | 2905 | /* Directives: Literal pools. */ |
a737bd4d | 2906 | |
c19d1205 ZW |
2907 | static literal_pool * |
2908 | find_literal_pool (void) | |
a737bd4d | 2909 | { |
c19d1205 | 2910 | literal_pool * pool; |
a737bd4d | 2911 | |
c19d1205 | 2912 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 2913 | { |
c19d1205 ZW |
2914 | if (pool->section == now_seg |
2915 | && pool->sub_section == now_subseg) | |
2916 | break; | |
a737bd4d NC |
2917 | } |
2918 | ||
c19d1205 | 2919 | return pool; |
a737bd4d NC |
2920 | } |
2921 | ||
c19d1205 ZW |
2922 | static literal_pool * |
2923 | find_or_make_literal_pool (void) | |
a737bd4d | 2924 | { |
c19d1205 ZW |
2925 | /* Next literal pool ID number. */ |
2926 | static unsigned int latest_pool_num = 1; | |
2927 | literal_pool * pool; | |
a737bd4d | 2928 | |
c19d1205 | 2929 | pool = find_literal_pool (); |
a737bd4d | 2930 | |
c19d1205 | 2931 | if (pool == NULL) |
a737bd4d | 2932 | { |
c19d1205 ZW |
2933 | /* Create a new pool. */ |
2934 | pool = xmalloc (sizeof (* pool)); | |
2935 | if (! pool) | |
2936 | return NULL; | |
a737bd4d | 2937 | |
c19d1205 ZW |
2938 | pool->next_free_entry = 0; |
2939 | pool->section = now_seg; | |
2940 | pool->sub_section = now_subseg; | |
2941 | pool->next = list_of_pools; | |
2942 | pool->symbol = NULL; | |
2943 | ||
2944 | /* Add it to the list. */ | |
2945 | list_of_pools = pool; | |
a737bd4d | 2946 | } |
a737bd4d | 2947 | |
c19d1205 ZW |
2948 | /* New pools, and emptied pools, will have a NULL symbol. */ |
2949 | if (pool->symbol == NULL) | |
a737bd4d | 2950 | { |
c19d1205 ZW |
2951 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
2952 | (valueT) 0, &zero_address_frag); | |
2953 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
2954 | } |
2955 | ||
c19d1205 ZW |
2956 | /* Done. */ |
2957 | return pool; | |
a737bd4d NC |
2958 | } |
2959 | ||
c19d1205 | 2960 | /* Add the literal in the global 'inst' |
5f4273c7 | 2961 | structure to the relevant literal pool. */ |
b99bd4ef NC |
2962 | |
2963 | static int | |
c19d1205 | 2964 | add_to_lit_pool (void) |
b99bd4ef | 2965 | { |
c19d1205 ZW |
2966 | literal_pool * pool; |
2967 | unsigned int entry; | |
b99bd4ef | 2968 | |
c19d1205 ZW |
2969 | pool = find_or_make_literal_pool (); |
2970 | ||
2971 | /* Check if this literal value is already in the pool. */ | |
2972 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 2973 | { |
c19d1205 ZW |
2974 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
2975 | && (inst.reloc.exp.X_op == O_constant) | |
2976 | && (pool->literals[entry].X_add_number | |
2977 | == inst.reloc.exp.X_add_number) | |
2978 | && (pool->literals[entry].X_unsigned | |
2979 | == inst.reloc.exp.X_unsigned)) | |
2980 | break; | |
2981 | ||
2982 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
2983 | && (inst.reloc.exp.X_op == O_symbol) | |
2984 | && (pool->literals[entry].X_add_number | |
2985 | == inst.reloc.exp.X_add_number) | |
2986 | && (pool->literals[entry].X_add_symbol | |
2987 | == inst.reloc.exp.X_add_symbol) | |
2988 | && (pool->literals[entry].X_op_symbol | |
2989 | == inst.reloc.exp.X_op_symbol)) | |
2990 | break; | |
b99bd4ef NC |
2991 | } |
2992 | ||
c19d1205 ZW |
2993 | /* Do we need to create a new entry? */ |
2994 | if (entry == pool->next_free_entry) | |
2995 | { | |
2996 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
2997 | { | |
2998 | inst.error = _("literal pool overflow"); | |
2999 | return FAIL; | |
3000 | } | |
3001 | ||
3002 | pool->literals[entry] = inst.reloc.exp; | |
3003 | pool->next_free_entry += 1; | |
3004 | } | |
b99bd4ef | 3005 | |
c19d1205 ZW |
3006 | inst.reloc.exp.X_op = O_symbol; |
3007 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
3008 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3009 | |
c19d1205 | 3010 | return SUCCESS; |
b99bd4ef NC |
3011 | } |
3012 | ||
c19d1205 ZW |
3013 | /* Can't use symbol_new here, so have to create a symbol and then at |
3014 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 3015 | |
c19d1205 ZW |
3016 | static void |
3017 | symbol_locate (symbolS * symbolP, | |
3018 | const char * name, /* It is copied, the caller can modify. */ | |
3019 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3020 | valueT valu, /* Symbol value. */ | |
3021 | fragS * frag) /* Associated fragment. */ | |
3022 | { | |
3023 | unsigned int name_length; | |
3024 | char * preserved_copy_of_name; | |
e16bb312 | 3025 | |
c19d1205 ZW |
3026 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3027 | obstack_grow (¬es, name, name_length); | |
3028 | preserved_copy_of_name = obstack_finish (¬es); | |
e16bb312 | 3029 | |
c19d1205 ZW |
3030 | #ifdef tc_canonicalize_symbol_name |
3031 | preserved_copy_of_name = | |
3032 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3033 | #endif | |
b99bd4ef | 3034 | |
c19d1205 | 3035 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3036 | |
c19d1205 ZW |
3037 | S_SET_SEGMENT (symbolP, segment); |
3038 | S_SET_VALUE (symbolP, valu); | |
3039 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3040 | |
c19d1205 | 3041 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3042 | |
c19d1205 ZW |
3043 | /* Link to end of symbol chain. */ |
3044 | { | |
3045 | extern int symbol_table_frozen; | |
b99bd4ef | 3046 | |
c19d1205 ZW |
3047 | if (symbol_table_frozen) |
3048 | abort (); | |
3049 | } | |
b99bd4ef | 3050 | |
c19d1205 | 3051 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3052 | |
c19d1205 | 3053 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3054 | |
c19d1205 ZW |
3055 | #ifdef tc_symbol_new_hook |
3056 | tc_symbol_new_hook (symbolP); | |
3057 | #endif | |
3058 | ||
3059 | #ifdef DEBUG_SYMS | |
3060 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3061 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3062 | } |
3063 | ||
b99bd4ef | 3064 | |
c19d1205 ZW |
3065 | static void |
3066 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3067 | { |
c19d1205 ZW |
3068 | unsigned int entry; |
3069 | literal_pool * pool; | |
3070 | char sym_name[20]; | |
b99bd4ef | 3071 | |
c19d1205 ZW |
3072 | pool = find_literal_pool (); |
3073 | if (pool == NULL | |
3074 | || pool->symbol == NULL | |
3075 | || pool->next_free_entry == 0) | |
3076 | return; | |
b99bd4ef | 3077 | |
c19d1205 | 3078 | mapping_state (MAP_DATA); |
b99bd4ef | 3079 | |
c19d1205 ZW |
3080 | /* Align pool as you have word accesses. |
3081 | Only make a frag if we have to. */ | |
3082 | if (!need_pass_2) | |
3083 | frag_align (2, 0, 0); | |
b99bd4ef | 3084 | |
c19d1205 | 3085 | record_alignment (now_seg, 2); |
b99bd4ef | 3086 | |
c19d1205 | 3087 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3088 | |
c19d1205 ZW |
3089 | symbol_locate (pool->symbol, sym_name, now_seg, |
3090 | (valueT) frag_now_fix (), frag_now); | |
3091 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3092 | |
c19d1205 | 3093 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3094 | |
c19d1205 ZW |
3095 | #if defined OBJ_COFF || defined OBJ_ELF |
3096 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3097 | #endif | |
6c43fab6 | 3098 | |
c19d1205 ZW |
3099 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
3100 | /* First output the expression in the instruction to the pool. */ | |
3101 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 3102 | |
c19d1205 ZW |
3103 | /* Mark the pool as empty. */ |
3104 | pool->next_free_entry = 0; | |
3105 | pool->symbol = NULL; | |
b99bd4ef NC |
3106 | } |
3107 | ||
c19d1205 ZW |
3108 | #ifdef OBJ_ELF |
3109 | /* Forward declarations for functions below, in the MD interface | |
3110 | section. */ | |
3111 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3112 | static valueT create_unwind_entry (int); | |
3113 | static void start_unwind_section (const segT, int); | |
3114 | static void add_unwind_opcode (valueT, int); | |
3115 | static void flush_pending_unwind (void); | |
b99bd4ef | 3116 | |
c19d1205 | 3117 | /* Directives: Data. */ |
b99bd4ef | 3118 | |
c19d1205 ZW |
3119 | static void |
3120 | s_arm_elf_cons (int nbytes) | |
3121 | { | |
3122 | expressionS exp; | |
b99bd4ef | 3123 | |
c19d1205 ZW |
3124 | #ifdef md_flush_pending_output |
3125 | md_flush_pending_output (); | |
3126 | #endif | |
b99bd4ef | 3127 | |
c19d1205 | 3128 | if (is_it_end_of_statement ()) |
b99bd4ef | 3129 | { |
c19d1205 ZW |
3130 | demand_empty_rest_of_line (); |
3131 | return; | |
b99bd4ef NC |
3132 | } |
3133 | ||
c19d1205 ZW |
3134 | #ifdef md_cons_align |
3135 | md_cons_align (nbytes); | |
3136 | #endif | |
b99bd4ef | 3137 | |
c19d1205 ZW |
3138 | mapping_state (MAP_DATA); |
3139 | do | |
b99bd4ef | 3140 | { |
c19d1205 ZW |
3141 | int reloc; |
3142 | char *base = input_line_pointer; | |
b99bd4ef | 3143 | |
c19d1205 | 3144 | expression (& exp); |
b99bd4ef | 3145 | |
c19d1205 ZW |
3146 | if (exp.X_op != O_symbol) |
3147 | emit_expr (&exp, (unsigned int) nbytes); | |
3148 | else | |
3149 | { | |
3150 | char *before_reloc = input_line_pointer; | |
3151 | reloc = parse_reloc (&input_line_pointer); | |
3152 | if (reloc == -1) | |
3153 | { | |
3154 | as_bad (_("unrecognized relocation suffix")); | |
3155 | ignore_rest_of_line (); | |
3156 | return; | |
3157 | } | |
3158 | else if (reloc == BFD_RELOC_UNUSED) | |
3159 | emit_expr (&exp, (unsigned int) nbytes); | |
3160 | else | |
3161 | { | |
3162 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
3163 | int size = bfd_get_reloc_size (howto); | |
b99bd4ef | 3164 | |
2fc8bdac ZW |
3165 | if (reloc == BFD_RELOC_ARM_PLT32) |
3166 | { | |
3167 | as_bad (_("(plt) is only valid on branch targets")); | |
3168 | reloc = BFD_RELOC_UNUSED; | |
3169 | size = 0; | |
3170 | } | |
3171 | ||
c19d1205 | 3172 | if (size > nbytes) |
2fc8bdac | 3173 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3174 | howto->name, nbytes); |
3175 | else | |
3176 | { | |
3177 | /* We've parsed an expression stopping at O_symbol. | |
3178 | But there may be more expression left now that we | |
3179 | have parsed the relocation marker. Parse it again. | |
3180 | XXX Surely there is a cleaner way to do this. */ | |
3181 | char *p = input_line_pointer; | |
3182 | int offset; | |
3183 | char *save_buf = alloca (input_line_pointer - base); | |
3184 | memcpy (save_buf, base, input_line_pointer - base); | |
3185 | memmove (base + (input_line_pointer - before_reloc), | |
3186 | base, before_reloc - base); | |
3187 | ||
3188 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3189 | expression (&exp); | |
3190 | memcpy (base, save_buf, p - base); | |
3191 | ||
3192 | offset = nbytes - size; | |
3193 | p = frag_more ((int) nbytes); | |
3194 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
3195 | size, &exp, 0, reloc); | |
3196 | } | |
3197 | } | |
3198 | } | |
b99bd4ef | 3199 | } |
c19d1205 | 3200 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3201 | |
c19d1205 ZW |
3202 | /* Put terminator back into stream. */ |
3203 | input_line_pointer --; | |
3204 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3205 | } |
3206 | ||
c921be7d NC |
3207 | /* Emit an expression containing a 32-bit thumb instruction. |
3208 | Implementation based on put_thumb32_insn. */ | |
3209 | ||
3210 | static void | |
3211 | emit_thumb32_expr (expressionS * exp) | |
3212 | { | |
3213 | expressionS exp_high = *exp; | |
3214 | ||
3215 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3216 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3217 | exp->X_add_number &= 0xffff; | |
3218 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3219 | } | |
3220 | ||
3221 | /* Guess the instruction size based on the opcode. */ | |
3222 | ||
3223 | static int | |
3224 | thumb_insn_size (int opcode) | |
3225 | { | |
3226 | if ((unsigned int) opcode < 0xe800u) | |
3227 | return 2; | |
3228 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3229 | return 4; | |
3230 | else | |
3231 | return 0; | |
3232 | } | |
3233 | ||
3234 | static bfd_boolean | |
3235 | emit_insn (expressionS *exp, int nbytes) | |
3236 | { | |
3237 | int size = 0; | |
3238 | ||
3239 | if (exp->X_op == O_constant) | |
3240 | { | |
3241 | size = nbytes; | |
3242 | ||
3243 | if (size == 0) | |
3244 | size = thumb_insn_size (exp->X_add_number); | |
3245 | ||
3246 | if (size != 0) | |
3247 | { | |
3248 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3249 | { | |
3250 | as_bad (_(".inst.n operand too big. "\ | |
3251 | "Use .inst.w instead")); | |
3252 | size = 0; | |
3253 | } | |
3254 | else | |
3255 | { | |
3256 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3257 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3258 | else | |
3259 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3260 | ||
3261 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3262 | emit_thumb32_expr (exp); | |
3263 | else | |
3264 | emit_expr (exp, (unsigned int) size); | |
3265 | ||
3266 | it_fsm_post_encode (); | |
3267 | } | |
3268 | } | |
3269 | else | |
3270 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3271 | "Use .inst.n/.inst.w instead")); | |
3272 | } | |
3273 | else | |
3274 | as_bad (_("constant expression required")); | |
3275 | ||
3276 | return (size != 0); | |
3277 | } | |
3278 | ||
3279 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3280 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3281 | ||
3282 | static void | |
3283 | s_arm_elf_inst (int nbytes) | |
3284 | { | |
3285 | if (is_it_end_of_statement ()) | |
3286 | { | |
3287 | demand_empty_rest_of_line (); | |
3288 | return; | |
3289 | } | |
3290 | ||
3291 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3292 | but will ensure not to be in DATA state. */ | |
3293 | ||
3294 | if (thumb_mode) | |
3295 | mapping_state (MAP_THUMB); | |
3296 | else | |
3297 | { | |
3298 | if (nbytes != 0) | |
3299 | { | |
3300 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3301 | ignore_rest_of_line (); | |
3302 | return; | |
3303 | } | |
3304 | ||
3305 | nbytes = 4; | |
3306 | ||
3307 | mapping_state (MAP_ARM); | |
3308 | } | |
3309 | ||
3310 | do | |
3311 | { | |
3312 | expressionS exp; | |
3313 | ||
3314 | expression (& exp); | |
3315 | ||
3316 | if (! emit_insn (& exp, nbytes)) | |
3317 | { | |
3318 | ignore_rest_of_line (); | |
3319 | return; | |
3320 | } | |
3321 | } | |
3322 | while (*input_line_pointer++ == ','); | |
3323 | ||
3324 | /* Put terminator back into stream. */ | |
3325 | input_line_pointer --; | |
3326 | demand_empty_rest_of_line (); | |
3327 | } | |
b99bd4ef | 3328 | |
c19d1205 | 3329 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3330 | |
c19d1205 ZW |
3331 | static void |
3332 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3333 | { | |
3334 | expressionS exp; | |
3335 | char *p; | |
3336 | valueT highbit; | |
b99bd4ef | 3337 | |
c19d1205 ZW |
3338 | highbit = 0; |
3339 | if (*input_line_pointer == '1') | |
3340 | highbit = 0x80000000; | |
3341 | else if (*input_line_pointer != '0') | |
3342 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3343 | |
c19d1205 ZW |
3344 | input_line_pointer++; |
3345 | if (*input_line_pointer != ',') | |
3346 | as_bad (_("missing comma")); | |
3347 | input_line_pointer++; | |
b99bd4ef | 3348 | |
c19d1205 ZW |
3349 | #ifdef md_flush_pending_output |
3350 | md_flush_pending_output (); | |
3351 | #endif | |
b99bd4ef | 3352 | |
c19d1205 ZW |
3353 | #ifdef md_cons_align |
3354 | md_cons_align (4); | |
3355 | #endif | |
b99bd4ef | 3356 | |
c19d1205 | 3357 | mapping_state (MAP_DATA); |
b99bd4ef | 3358 | |
c19d1205 | 3359 | expression (&exp); |
b99bd4ef | 3360 | |
c19d1205 ZW |
3361 | p = frag_more (4); |
3362 | md_number_to_chars (p, highbit, 4); | |
3363 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3364 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3365 | |
c19d1205 | 3366 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3367 | } |
3368 | ||
c19d1205 | 3369 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3370 | |
c19d1205 | 3371 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3372 | |
c19d1205 ZW |
3373 | static void |
3374 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3375 | { | |
3376 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3377 | if (unwind.proc_start) |
3378 | { | |
c921be7d | 3379 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3380 | return; |
3381 | } | |
3382 | ||
c19d1205 ZW |
3383 | /* Mark the start of the function. */ |
3384 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3385 | |
c19d1205 ZW |
3386 | /* Reset the rest of the unwind info. */ |
3387 | unwind.opcode_count = 0; | |
3388 | unwind.table_entry = NULL; | |
3389 | unwind.personality_routine = NULL; | |
3390 | unwind.personality_index = -1; | |
3391 | unwind.frame_size = 0; | |
3392 | unwind.fp_offset = 0; | |
fdfde340 | 3393 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3394 | unwind.fp_used = 0; |
3395 | unwind.sp_restored = 0; | |
3396 | } | |
b99bd4ef | 3397 | |
b99bd4ef | 3398 | |
c19d1205 ZW |
3399 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3400 | for the function. */ | |
b99bd4ef | 3401 | |
c19d1205 ZW |
3402 | static void |
3403 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3404 | { | |
3405 | demand_empty_rest_of_line (); | |
921e5f0a | 3406 | if (!unwind.proc_start) |
c921be7d | 3407 | as_bad (MISSING_FNSTART); |
921e5f0a | 3408 | |
c19d1205 | 3409 | if (unwind.table_entry) |
6decc662 | 3410 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3411 | |
c19d1205 ZW |
3412 | create_unwind_entry (1); |
3413 | } | |
a737bd4d | 3414 | |
c19d1205 | 3415 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3416 | |
c19d1205 ZW |
3417 | static void |
3418 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3419 | { | |
3420 | long where; | |
3421 | char *ptr; | |
3422 | valueT val; | |
940b5ce0 | 3423 | unsigned int marked_pr_dependency; |
f02232aa | 3424 | |
c19d1205 | 3425 | demand_empty_rest_of_line (); |
f02232aa | 3426 | |
921e5f0a PB |
3427 | if (!unwind.proc_start) |
3428 | { | |
c921be7d | 3429 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3430 | return; |
3431 | } | |
3432 | ||
c19d1205 ZW |
3433 | /* Add eh table entry. */ |
3434 | if (unwind.table_entry == NULL) | |
3435 | val = create_unwind_entry (0); | |
3436 | else | |
3437 | val = 0; | |
f02232aa | 3438 | |
c19d1205 ZW |
3439 | /* Add index table entry. This is two words. */ |
3440 | start_unwind_section (unwind.saved_seg, 1); | |
3441 | frag_align (2, 0, 0); | |
3442 | record_alignment (now_seg, 2); | |
b99bd4ef | 3443 | |
c19d1205 ZW |
3444 | ptr = frag_more (8); |
3445 | where = frag_now_fix () - 8; | |
f02232aa | 3446 | |
c19d1205 ZW |
3447 | /* Self relative offset of the function start. */ |
3448 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3449 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3450 | |
c19d1205 ZW |
3451 | /* Indicate dependency on EHABI-defined personality routines to the |
3452 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3453 | marked_pr_dependency |
3454 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3455 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3456 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3457 | { | |
5f4273c7 NC |
3458 | static const char *const name[] = |
3459 | { | |
3460 | "__aeabi_unwind_cpp_pr0", | |
3461 | "__aeabi_unwind_cpp_pr1", | |
3462 | "__aeabi_unwind_cpp_pr2" | |
3463 | }; | |
c19d1205 ZW |
3464 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3465 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3466 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3467 | |= 1 << unwind.personality_index; |
c19d1205 | 3468 | } |
f02232aa | 3469 | |
c19d1205 ZW |
3470 | if (val) |
3471 | /* Inline exception table entry. */ | |
3472 | md_number_to_chars (ptr + 4, val, 4); | |
3473 | else | |
3474 | /* Self relative offset of the table entry. */ | |
3475 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3476 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3477 | |
c19d1205 ZW |
3478 | /* Restore the original section. */ |
3479 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3480 | |
3481 | unwind.proc_start = NULL; | |
c19d1205 | 3482 | } |
f02232aa | 3483 | |
f02232aa | 3484 | |
c19d1205 | 3485 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3486 | |
c19d1205 ZW |
3487 | static void |
3488 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3489 | { | |
3490 | demand_empty_rest_of_line (); | |
921e5f0a | 3491 | if (!unwind.proc_start) |
c921be7d | 3492 | as_bad (MISSING_FNSTART); |
921e5f0a | 3493 | |
c19d1205 ZW |
3494 | if (unwind.personality_routine || unwind.personality_index != -1) |
3495 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3496 | |
c19d1205 ZW |
3497 | unwind.personality_index = -2; |
3498 | } | |
b99bd4ef | 3499 | |
b99bd4ef | 3500 | |
c19d1205 | 3501 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3502 | |
c19d1205 ZW |
3503 | static void |
3504 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3505 | { | |
3506 | expressionS exp; | |
b99bd4ef | 3507 | |
921e5f0a | 3508 | if (!unwind.proc_start) |
c921be7d | 3509 | as_bad (MISSING_FNSTART); |
921e5f0a | 3510 | |
c19d1205 ZW |
3511 | if (unwind.personality_routine || unwind.personality_index != -1) |
3512 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3513 | |
c19d1205 | 3514 | expression (&exp); |
b99bd4ef | 3515 | |
c19d1205 ZW |
3516 | if (exp.X_op != O_constant |
3517 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3518 | { |
c19d1205 ZW |
3519 | as_bad (_("bad personality routine number")); |
3520 | ignore_rest_of_line (); | |
3521 | return; | |
b99bd4ef NC |
3522 | } |
3523 | ||
c19d1205 | 3524 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3525 | |
c19d1205 ZW |
3526 | demand_empty_rest_of_line (); |
3527 | } | |
e16bb312 | 3528 | |
e16bb312 | 3529 | |
c19d1205 | 3530 | /* Parse a personality directive. */ |
e16bb312 | 3531 | |
c19d1205 ZW |
3532 | static void |
3533 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3534 | { | |
3535 | char *name, *p, c; | |
a737bd4d | 3536 | |
921e5f0a | 3537 | if (!unwind.proc_start) |
c921be7d | 3538 | as_bad (MISSING_FNSTART); |
921e5f0a | 3539 | |
c19d1205 ZW |
3540 | if (unwind.personality_routine || unwind.personality_index != -1) |
3541 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3542 | |
c19d1205 ZW |
3543 | name = input_line_pointer; |
3544 | c = get_symbol_end (); | |
3545 | p = input_line_pointer; | |
3546 | unwind.personality_routine = symbol_find_or_make (name); | |
3547 | *p = c; | |
3548 | demand_empty_rest_of_line (); | |
3549 | } | |
e16bb312 | 3550 | |
e16bb312 | 3551 | |
c19d1205 | 3552 | /* Parse a directive saving core registers. */ |
e16bb312 | 3553 | |
c19d1205 ZW |
3554 | static void |
3555 | s_arm_unwind_save_core (void) | |
e16bb312 | 3556 | { |
c19d1205 ZW |
3557 | valueT op; |
3558 | long range; | |
3559 | int n; | |
e16bb312 | 3560 | |
c19d1205 ZW |
3561 | range = parse_reg_list (&input_line_pointer); |
3562 | if (range == FAIL) | |
e16bb312 | 3563 | { |
c19d1205 ZW |
3564 | as_bad (_("expected register list")); |
3565 | ignore_rest_of_line (); | |
3566 | return; | |
3567 | } | |
e16bb312 | 3568 | |
c19d1205 | 3569 | demand_empty_rest_of_line (); |
e16bb312 | 3570 | |
c19d1205 ZW |
3571 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3572 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3573 | ip because it is clobbered by calls. */ | |
3574 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3575 | && (range & 0x3000) == 0x1000) | |
3576 | { | |
3577 | unwind.opcode_count--; | |
3578 | unwind.sp_restored = 0; | |
3579 | range = (range | 0x2000) & ~0x1000; | |
3580 | unwind.pending_offset = 0; | |
3581 | } | |
e16bb312 | 3582 | |
01ae4198 DJ |
3583 | /* Pop r4-r15. */ |
3584 | if (range & 0xfff0) | |
c19d1205 | 3585 | { |
01ae4198 DJ |
3586 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3587 | registers starting with r4, plus maybe r14. */ | |
3588 | for (n = 0; n < 8; n++) | |
3589 | { | |
3590 | /* Break at the first non-saved register. */ | |
3591 | if ((range & (1 << (n + 4))) == 0) | |
3592 | break; | |
3593 | } | |
3594 | /* See if there are any other bits set. */ | |
3595 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3596 | { | |
3597 | /* Use the long form. */ | |
3598 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3599 | add_unwind_opcode (op, 2); | |
3600 | } | |
0dd132b6 | 3601 | else |
01ae4198 DJ |
3602 | { |
3603 | /* Use the short form. */ | |
3604 | if (range & 0x4000) | |
3605 | op = 0xa8; /* Pop r14. */ | |
3606 | else | |
3607 | op = 0xa0; /* Do not pop r14. */ | |
3608 | op |= (n - 1); | |
3609 | add_unwind_opcode (op, 1); | |
3610 | } | |
c19d1205 | 3611 | } |
0dd132b6 | 3612 | |
c19d1205 ZW |
3613 | /* Pop r0-r3. */ |
3614 | if (range & 0xf) | |
3615 | { | |
3616 | op = 0xb100 | (range & 0xf); | |
3617 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3618 | } |
3619 | ||
c19d1205 ZW |
3620 | /* Record the number of bytes pushed. */ |
3621 | for (n = 0; n < 16; n++) | |
3622 | { | |
3623 | if (range & (1 << n)) | |
3624 | unwind.frame_size += 4; | |
3625 | } | |
0dd132b6 NC |
3626 | } |
3627 | ||
c19d1205 ZW |
3628 | |
3629 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3630 | |
3631 | static void | |
c19d1205 | 3632 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3633 | { |
c19d1205 ZW |
3634 | expressionS exp; |
3635 | int num_regs; | |
3636 | valueT op; | |
b99bd4ef | 3637 | |
c19d1205 ZW |
3638 | /* Get Number of registers to transfer. */ |
3639 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3640 | expression (&exp); | |
3641 | else | |
3642 | exp.X_op = O_illegal; | |
b99bd4ef | 3643 | |
c19d1205 | 3644 | if (exp.X_op != O_constant) |
b99bd4ef | 3645 | { |
c19d1205 ZW |
3646 | as_bad (_("expected , <constant>")); |
3647 | ignore_rest_of_line (); | |
b99bd4ef NC |
3648 | return; |
3649 | } | |
3650 | ||
c19d1205 ZW |
3651 | num_regs = exp.X_add_number; |
3652 | ||
3653 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3654 | { |
c19d1205 ZW |
3655 | as_bad (_("number of registers must be in the range [1:4]")); |
3656 | ignore_rest_of_line (); | |
b99bd4ef NC |
3657 | return; |
3658 | } | |
3659 | ||
c19d1205 | 3660 | demand_empty_rest_of_line (); |
b99bd4ef | 3661 | |
c19d1205 ZW |
3662 | if (reg == 4) |
3663 | { | |
3664 | /* Short form. */ | |
3665 | op = 0xb4 | (num_regs - 1); | |
3666 | add_unwind_opcode (op, 1); | |
3667 | } | |
b99bd4ef NC |
3668 | else |
3669 | { | |
c19d1205 ZW |
3670 | /* Long form. */ |
3671 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3672 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3673 | } |
c19d1205 | 3674 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3675 | } |
3676 | ||
c19d1205 | 3677 | |
fa073d69 MS |
3678 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3679 | ||
3680 | static void | |
3681 | s_arm_unwind_save_vfp_armv6 (void) | |
3682 | { | |
3683 | int count; | |
3684 | unsigned int start; | |
3685 | valueT op; | |
3686 | int num_vfpv3_regs = 0; | |
3687 | int num_regs_below_16; | |
3688 | ||
3689 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3690 | if (count == FAIL) | |
3691 | { | |
3692 | as_bad (_("expected register list")); | |
3693 | ignore_rest_of_line (); | |
3694 | return; | |
3695 | } | |
3696 | ||
3697 | demand_empty_rest_of_line (); | |
3698 | ||
3699 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3700 | than FSTMX/FLDMX-style ones). */ | |
3701 | ||
3702 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3703 | if (start >= 16) | |
3704 | num_vfpv3_regs = count; | |
3705 | else if (start + count > 16) | |
3706 | num_vfpv3_regs = start + count - 16; | |
3707 | ||
3708 | if (num_vfpv3_regs > 0) | |
3709 | { | |
3710 | int start_offset = start > 16 ? start - 16 : 0; | |
3711 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3712 | add_unwind_opcode (op, 2); | |
3713 | } | |
3714 | ||
3715 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3716 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 3717 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
3718 | if (num_regs_below_16 > 0) |
3719 | { | |
3720 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3721 | add_unwind_opcode (op, 2); | |
3722 | } | |
3723 | ||
3724 | unwind.frame_size += count * 8; | |
3725 | } | |
3726 | ||
3727 | ||
3728 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3729 | |
3730 | static void | |
c19d1205 | 3731 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3732 | { |
c19d1205 | 3733 | int count; |
ca3f61f7 | 3734 | unsigned int reg; |
c19d1205 | 3735 | valueT op; |
b99bd4ef | 3736 | |
5287ad62 | 3737 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3738 | if (count == FAIL) |
b99bd4ef | 3739 | { |
c19d1205 ZW |
3740 | as_bad (_("expected register list")); |
3741 | ignore_rest_of_line (); | |
b99bd4ef NC |
3742 | return; |
3743 | } | |
3744 | ||
c19d1205 | 3745 | demand_empty_rest_of_line (); |
b99bd4ef | 3746 | |
c19d1205 | 3747 | if (reg == 8) |
b99bd4ef | 3748 | { |
c19d1205 ZW |
3749 | /* Short form. */ |
3750 | op = 0xb8 | (count - 1); | |
3751 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3752 | } |
c19d1205 | 3753 | else |
b99bd4ef | 3754 | { |
c19d1205 ZW |
3755 | /* Long form. */ |
3756 | op = 0xb300 | (reg << 4) | (count - 1); | |
3757 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3758 | } |
c19d1205 ZW |
3759 | unwind.frame_size += count * 8 + 4; |
3760 | } | |
b99bd4ef | 3761 | |
b99bd4ef | 3762 | |
c19d1205 ZW |
3763 | /* Parse a directive saving iWMMXt data registers. */ |
3764 | ||
3765 | static void | |
3766 | s_arm_unwind_save_mmxwr (void) | |
3767 | { | |
3768 | int reg; | |
3769 | int hi_reg; | |
3770 | int i; | |
3771 | unsigned mask = 0; | |
3772 | valueT op; | |
b99bd4ef | 3773 | |
c19d1205 ZW |
3774 | if (*input_line_pointer == '{') |
3775 | input_line_pointer++; | |
b99bd4ef | 3776 | |
c19d1205 | 3777 | do |
b99bd4ef | 3778 | { |
dcbf9037 | 3779 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3780 | |
c19d1205 | 3781 | if (reg == FAIL) |
b99bd4ef | 3782 | { |
9b7132d3 | 3783 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 3784 | goto error; |
b99bd4ef NC |
3785 | } |
3786 | ||
c19d1205 ZW |
3787 | if (mask >> reg) |
3788 | as_tsktsk (_("register list not in ascending order")); | |
3789 | mask |= 1 << reg; | |
b99bd4ef | 3790 | |
c19d1205 ZW |
3791 | if (*input_line_pointer == '-') |
3792 | { | |
3793 | input_line_pointer++; | |
dcbf9037 | 3794 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3795 | if (hi_reg == FAIL) |
3796 | { | |
9b7132d3 | 3797 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
3798 | goto error; |
3799 | } | |
3800 | else if (reg >= hi_reg) | |
3801 | { | |
3802 | as_bad (_("bad register range")); | |
3803 | goto error; | |
3804 | } | |
3805 | for (; reg < hi_reg; reg++) | |
3806 | mask |= 1 << reg; | |
3807 | } | |
3808 | } | |
3809 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3810 | |
c19d1205 ZW |
3811 | if (*input_line_pointer == '}') |
3812 | input_line_pointer++; | |
b99bd4ef | 3813 | |
c19d1205 | 3814 | demand_empty_rest_of_line (); |
b99bd4ef | 3815 | |
708587a4 | 3816 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3817 | the list. */ |
3818 | flush_pending_unwind (); | |
b99bd4ef | 3819 | |
c19d1205 | 3820 | for (i = 0; i < 16; i++) |
b99bd4ef | 3821 | { |
c19d1205 ZW |
3822 | if (mask & (1 << i)) |
3823 | unwind.frame_size += 8; | |
b99bd4ef NC |
3824 | } |
3825 | ||
c19d1205 ZW |
3826 | /* Attempt to combine with a previous opcode. We do this because gcc |
3827 | likes to output separate unwind directives for a single block of | |
3828 | registers. */ | |
3829 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3830 | { |
c19d1205 ZW |
3831 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3832 | if ((i & 0xf8) == 0xc0) | |
3833 | { | |
3834 | i &= 7; | |
3835 | /* Only merge if the blocks are contiguous. */ | |
3836 | if (i < 6) | |
3837 | { | |
3838 | if ((mask & 0xfe00) == (1 << 9)) | |
3839 | { | |
3840 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3841 | unwind.opcode_count--; | |
3842 | } | |
3843 | } | |
3844 | else if (i == 6 && unwind.opcode_count >= 2) | |
3845 | { | |
3846 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3847 | reg = i >> 4; | |
3848 | i &= 0xf; | |
b99bd4ef | 3849 | |
c19d1205 ZW |
3850 | op = 0xffff << (reg - 1); |
3851 | if (reg > 0 | |
87a1fd79 | 3852 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
3853 | { |
3854 | op = (1 << (reg + i + 1)) - 1; | |
3855 | op &= ~((1 << reg) - 1); | |
3856 | mask |= op; | |
3857 | unwind.opcode_count -= 2; | |
3858 | } | |
3859 | } | |
3860 | } | |
b99bd4ef NC |
3861 | } |
3862 | ||
c19d1205 ZW |
3863 | hi_reg = 15; |
3864 | /* We want to generate opcodes in the order the registers have been | |
3865 | saved, ie. descending order. */ | |
3866 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3867 | { |
c19d1205 ZW |
3868 | /* Save registers in blocks. */ |
3869 | if (reg < 0 | |
3870 | || !(mask & (1 << reg))) | |
3871 | { | |
3872 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 3873 | preceding block. */ |
c19d1205 ZW |
3874 | if (reg != hi_reg) |
3875 | { | |
3876 | if (reg == 9) | |
3877 | { | |
3878 | /* Short form. */ | |
3879 | op = 0xc0 | (hi_reg - 10); | |
3880 | add_unwind_opcode (op, 1); | |
3881 | } | |
3882 | else | |
3883 | { | |
3884 | /* Long form. */ | |
3885 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
3886 | add_unwind_opcode (op, 2); | |
3887 | } | |
3888 | } | |
3889 | hi_reg = reg - 1; | |
3890 | } | |
b99bd4ef NC |
3891 | } |
3892 | ||
c19d1205 ZW |
3893 | return; |
3894 | error: | |
3895 | ignore_rest_of_line (); | |
b99bd4ef NC |
3896 | } |
3897 | ||
3898 | static void | |
c19d1205 | 3899 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 3900 | { |
c19d1205 ZW |
3901 | int reg; |
3902 | int hi_reg; | |
3903 | unsigned mask = 0; | |
3904 | valueT op; | |
b99bd4ef | 3905 | |
c19d1205 ZW |
3906 | if (*input_line_pointer == '{') |
3907 | input_line_pointer++; | |
b99bd4ef | 3908 | |
c19d1205 | 3909 | do |
b99bd4ef | 3910 | { |
dcbf9037 | 3911 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 3912 | |
c19d1205 ZW |
3913 | if (reg == FAIL) |
3914 | { | |
9b7132d3 | 3915 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3916 | goto error; |
3917 | } | |
b99bd4ef | 3918 | |
c19d1205 ZW |
3919 | reg -= 8; |
3920 | if (mask >> reg) | |
3921 | as_tsktsk (_("register list not in ascending order")); | |
3922 | mask |= 1 << reg; | |
b99bd4ef | 3923 | |
c19d1205 ZW |
3924 | if (*input_line_pointer == '-') |
3925 | { | |
3926 | input_line_pointer++; | |
dcbf9037 | 3927 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
3928 | if (hi_reg == FAIL) |
3929 | { | |
9b7132d3 | 3930 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3931 | goto error; |
3932 | } | |
3933 | else if (reg >= hi_reg) | |
3934 | { | |
3935 | as_bad (_("bad register range")); | |
3936 | goto error; | |
3937 | } | |
3938 | for (; reg < hi_reg; reg++) | |
3939 | mask |= 1 << reg; | |
3940 | } | |
b99bd4ef | 3941 | } |
c19d1205 | 3942 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 3943 | |
c19d1205 ZW |
3944 | if (*input_line_pointer == '}') |
3945 | input_line_pointer++; | |
b99bd4ef | 3946 | |
c19d1205 ZW |
3947 | demand_empty_rest_of_line (); |
3948 | ||
708587a4 | 3949 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3950 | the list. */ |
3951 | flush_pending_unwind (); | |
b99bd4ef | 3952 | |
c19d1205 | 3953 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 3954 | { |
c19d1205 ZW |
3955 | if (mask & (1 << reg)) |
3956 | unwind.frame_size += 4; | |
b99bd4ef | 3957 | } |
c19d1205 ZW |
3958 | op = 0xc700 | mask; |
3959 | add_unwind_opcode (op, 2); | |
3960 | return; | |
3961 | error: | |
3962 | ignore_rest_of_line (); | |
b99bd4ef NC |
3963 | } |
3964 | ||
c19d1205 | 3965 | |
fa073d69 MS |
3966 | /* Parse an unwind_save directive. |
3967 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 3968 | |
b99bd4ef | 3969 | static void |
fa073d69 | 3970 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 3971 | { |
c19d1205 ZW |
3972 | char *peek; |
3973 | struct reg_entry *reg; | |
3974 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 3975 | |
921e5f0a | 3976 | if (!unwind.proc_start) |
c921be7d | 3977 | as_bad (MISSING_FNSTART); |
921e5f0a | 3978 | |
c19d1205 ZW |
3979 | /* Figure out what sort of save we have. */ |
3980 | peek = input_line_pointer; | |
b99bd4ef | 3981 | |
c19d1205 | 3982 | if (*peek == '{') |
b99bd4ef | 3983 | { |
c19d1205 ZW |
3984 | had_brace = TRUE; |
3985 | peek++; | |
b99bd4ef NC |
3986 | } |
3987 | ||
c19d1205 | 3988 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 3989 | |
c19d1205 | 3990 | if (!reg) |
b99bd4ef | 3991 | { |
c19d1205 ZW |
3992 | as_bad (_("register expected")); |
3993 | ignore_rest_of_line (); | |
b99bd4ef NC |
3994 | return; |
3995 | } | |
3996 | ||
c19d1205 | 3997 | switch (reg->type) |
b99bd4ef | 3998 | { |
c19d1205 ZW |
3999 | case REG_TYPE_FN: |
4000 | if (had_brace) | |
4001 | { | |
4002 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4003 | ignore_rest_of_line (); | |
4004 | return; | |
4005 | } | |
93ac2687 | 4006 | input_line_pointer = peek; |
c19d1205 | 4007 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4008 | return; |
c19d1205 ZW |
4009 | |
4010 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
4011 | case REG_TYPE_VFD: |
4012 | if (arch_v6) | |
4013 | s_arm_unwind_save_vfp_armv6 (); | |
4014 | else | |
4015 | s_arm_unwind_save_vfp (); | |
4016 | return; | |
c19d1205 ZW |
4017 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
4018 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
4019 | ||
4020 | default: | |
4021 | as_bad (_(".unwind_save does not support this kind of register")); | |
4022 | ignore_rest_of_line (); | |
b99bd4ef | 4023 | } |
c19d1205 | 4024 | } |
b99bd4ef | 4025 | |
b99bd4ef | 4026 | |
c19d1205 ZW |
4027 | /* Parse an unwind_movsp directive. */ |
4028 | ||
4029 | static void | |
4030 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4031 | { | |
4032 | int reg; | |
4033 | valueT op; | |
4fa3602b | 4034 | int offset; |
c19d1205 | 4035 | |
921e5f0a | 4036 | if (!unwind.proc_start) |
c921be7d | 4037 | as_bad (MISSING_FNSTART); |
921e5f0a | 4038 | |
dcbf9037 | 4039 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4040 | if (reg == FAIL) |
b99bd4ef | 4041 | { |
9b7132d3 | 4042 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4043 | ignore_rest_of_line (); |
b99bd4ef NC |
4044 | return; |
4045 | } | |
4fa3602b PB |
4046 | |
4047 | /* Optional constant. */ | |
4048 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4049 | { | |
4050 | if (immediate_for_directive (&offset) == FAIL) | |
4051 | return; | |
4052 | } | |
4053 | else | |
4054 | offset = 0; | |
4055 | ||
c19d1205 | 4056 | demand_empty_rest_of_line (); |
b99bd4ef | 4057 | |
c19d1205 | 4058 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4059 | { |
c19d1205 | 4060 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4061 | return; |
4062 | } | |
4063 | ||
c19d1205 ZW |
4064 | if (unwind.fp_reg != REG_SP) |
4065 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4066 | |
c19d1205 ZW |
4067 | /* Generate opcode to restore the value. */ |
4068 | op = 0x90 | reg; | |
4069 | add_unwind_opcode (op, 1); | |
4070 | ||
4071 | /* Record the information for later. */ | |
4072 | unwind.fp_reg = reg; | |
4fa3602b | 4073 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4074 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4075 | } |
4076 | ||
c19d1205 ZW |
4077 | /* Parse an unwind_pad directive. */ |
4078 | ||
b05fe5cf | 4079 | static void |
c19d1205 | 4080 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4081 | { |
c19d1205 | 4082 | int offset; |
b05fe5cf | 4083 | |
921e5f0a | 4084 | if (!unwind.proc_start) |
c921be7d | 4085 | as_bad (MISSING_FNSTART); |
921e5f0a | 4086 | |
c19d1205 ZW |
4087 | if (immediate_for_directive (&offset) == FAIL) |
4088 | return; | |
b99bd4ef | 4089 | |
c19d1205 ZW |
4090 | if (offset & 3) |
4091 | { | |
4092 | as_bad (_("stack increment must be multiple of 4")); | |
4093 | ignore_rest_of_line (); | |
4094 | return; | |
4095 | } | |
b99bd4ef | 4096 | |
c19d1205 ZW |
4097 | /* Don't generate any opcodes, just record the details for later. */ |
4098 | unwind.frame_size += offset; | |
4099 | unwind.pending_offset += offset; | |
4100 | ||
4101 | demand_empty_rest_of_line (); | |
4102 | } | |
4103 | ||
4104 | /* Parse an unwind_setfp directive. */ | |
4105 | ||
4106 | static void | |
4107 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4108 | { |
c19d1205 ZW |
4109 | int sp_reg; |
4110 | int fp_reg; | |
4111 | int offset; | |
4112 | ||
921e5f0a | 4113 | if (!unwind.proc_start) |
c921be7d | 4114 | as_bad (MISSING_FNSTART); |
921e5f0a | 4115 | |
dcbf9037 | 4116 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4117 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4118 | sp_reg = FAIL; | |
4119 | else | |
dcbf9037 | 4120 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4121 | |
c19d1205 ZW |
4122 | if (fp_reg == FAIL || sp_reg == FAIL) |
4123 | { | |
4124 | as_bad (_("expected <reg>, <reg>")); | |
4125 | ignore_rest_of_line (); | |
4126 | return; | |
4127 | } | |
b99bd4ef | 4128 | |
c19d1205 ZW |
4129 | /* Optional constant. */ |
4130 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4131 | { | |
4132 | if (immediate_for_directive (&offset) == FAIL) | |
4133 | return; | |
4134 | } | |
4135 | else | |
4136 | offset = 0; | |
a737bd4d | 4137 | |
c19d1205 | 4138 | demand_empty_rest_of_line (); |
a737bd4d | 4139 | |
fdfde340 | 4140 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4141 | { |
c19d1205 ZW |
4142 | as_bad (_("register must be either sp or set by a previous" |
4143 | "unwind_movsp directive")); | |
4144 | return; | |
a737bd4d NC |
4145 | } |
4146 | ||
c19d1205 ZW |
4147 | /* Don't generate any opcodes, just record the information for later. */ |
4148 | unwind.fp_reg = fp_reg; | |
4149 | unwind.fp_used = 1; | |
fdfde340 | 4150 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4151 | unwind.fp_offset = unwind.frame_size - offset; |
4152 | else | |
4153 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4154 | } |
4155 | ||
c19d1205 ZW |
4156 | /* Parse an unwind_raw directive. */ |
4157 | ||
4158 | static void | |
4159 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4160 | { |
c19d1205 | 4161 | expressionS exp; |
708587a4 | 4162 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4163 | unsigned char op[16]; |
4164 | int count; | |
a737bd4d | 4165 | |
921e5f0a | 4166 | if (!unwind.proc_start) |
c921be7d | 4167 | as_bad (MISSING_FNSTART); |
921e5f0a | 4168 | |
c19d1205 ZW |
4169 | expression (&exp); |
4170 | if (exp.X_op == O_constant | |
4171 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4172 | { |
c19d1205 ZW |
4173 | unwind.frame_size += exp.X_add_number; |
4174 | expression (&exp); | |
4175 | } | |
4176 | else | |
4177 | exp.X_op = O_illegal; | |
a737bd4d | 4178 | |
c19d1205 ZW |
4179 | if (exp.X_op != O_constant) |
4180 | { | |
4181 | as_bad (_("expected <offset>, <opcode>")); | |
4182 | ignore_rest_of_line (); | |
4183 | return; | |
4184 | } | |
a737bd4d | 4185 | |
c19d1205 | 4186 | count = 0; |
a737bd4d | 4187 | |
c19d1205 ZW |
4188 | /* Parse the opcode. */ |
4189 | for (;;) | |
4190 | { | |
4191 | if (count >= 16) | |
4192 | { | |
4193 | as_bad (_("unwind opcode too long")); | |
4194 | ignore_rest_of_line (); | |
a737bd4d | 4195 | } |
c19d1205 | 4196 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4197 | { |
c19d1205 ZW |
4198 | as_bad (_("invalid unwind opcode")); |
4199 | ignore_rest_of_line (); | |
4200 | return; | |
a737bd4d | 4201 | } |
c19d1205 | 4202 | op[count++] = exp.X_add_number; |
a737bd4d | 4203 | |
c19d1205 ZW |
4204 | /* Parse the next byte. */ |
4205 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4206 | break; | |
a737bd4d | 4207 | |
c19d1205 ZW |
4208 | expression (&exp); |
4209 | } | |
b99bd4ef | 4210 | |
c19d1205 ZW |
4211 | /* Add the opcode bytes in reverse order. */ |
4212 | while (count--) | |
4213 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4214 | |
c19d1205 | 4215 | demand_empty_rest_of_line (); |
b99bd4ef | 4216 | } |
ee065d83 PB |
4217 | |
4218 | ||
4219 | /* Parse a .eabi_attribute directive. */ | |
4220 | ||
4221 | static void | |
4222 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4223 | { | |
ee3c0378 AS |
4224 | int tag = s_vendor_attribute (OBJ_ATTR_PROC); |
4225 | ||
4226 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4227 | attributes_set_explicitly[tag] = 1; | |
ee065d83 | 4228 | } |
8463be01 | 4229 | #endif /* OBJ_ELF */ |
ee065d83 PB |
4230 | |
4231 | static void s_arm_arch (int); | |
7a1d4c38 | 4232 | static void s_arm_object_arch (int); |
ee065d83 PB |
4233 | static void s_arm_cpu (int); |
4234 | static void s_arm_fpu (int); | |
b99bd4ef | 4235 | |
f0927246 NC |
4236 | #ifdef TE_PE |
4237 | ||
4238 | static void | |
5f4273c7 | 4239 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4240 | { |
4241 | expressionS exp; | |
4242 | ||
4243 | do | |
4244 | { | |
4245 | expression (&exp); | |
4246 | if (exp.X_op == O_symbol) | |
4247 | exp.X_op = O_secrel; | |
4248 | ||
4249 | emit_expr (&exp, 4); | |
4250 | } | |
4251 | while (*input_line_pointer++ == ','); | |
4252 | ||
4253 | input_line_pointer--; | |
4254 | demand_empty_rest_of_line (); | |
4255 | } | |
4256 | #endif /* TE_PE */ | |
4257 | ||
c19d1205 ZW |
4258 | /* This table describes all the machine specific pseudo-ops the assembler |
4259 | has to support. The fields are: | |
4260 | pseudo-op name without dot | |
4261 | function to call to execute this pseudo-op | |
4262 | Integer arg to pass to the function. */ | |
b99bd4ef | 4263 | |
c19d1205 | 4264 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4265 | { |
c19d1205 ZW |
4266 | /* Never called because '.req' does not start a line. */ |
4267 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4268 | /* Following two are likewise never called. */ |
4269 | { "dn", s_dn, 0 }, | |
4270 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4271 | { "unreq", s_unreq, 0 }, |
4272 | { "bss", s_bss, 0 }, | |
4273 | { "align", s_align, 0 }, | |
4274 | { "arm", s_arm, 0 }, | |
4275 | { "thumb", s_thumb, 0 }, | |
4276 | { "code", s_code, 0 }, | |
4277 | { "force_thumb", s_force_thumb, 0 }, | |
4278 | { "thumb_func", s_thumb_func, 0 }, | |
4279 | { "thumb_set", s_thumb_set, 0 }, | |
4280 | { "even", s_even, 0 }, | |
4281 | { "ltorg", s_ltorg, 0 }, | |
4282 | { "pool", s_ltorg, 0 }, | |
4283 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4284 | { "cpu", s_arm_cpu, 0 }, |
4285 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4286 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4287 | { "fpu", s_arm_fpu, 0 }, |
c19d1205 | 4288 | #ifdef OBJ_ELF |
c921be7d NC |
4289 | { "word", s_arm_elf_cons, 4 }, |
4290 | { "long", s_arm_elf_cons, 4 }, | |
4291 | { "inst.n", s_arm_elf_inst, 2 }, | |
4292 | { "inst.w", s_arm_elf_inst, 4 }, | |
4293 | { "inst", s_arm_elf_inst, 0 }, | |
4294 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4295 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4296 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4297 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4298 | { "personality", s_arm_unwind_personality, 0 }, | |
4299 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4300 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4301 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4302 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4303 | { "movsp", s_arm_unwind_movsp, 0 }, |
4304 | { "pad", s_arm_unwind_pad, 0 }, | |
4305 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4306 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4307 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
4308 | #else |
4309 | { "word", cons, 4}, | |
f0927246 NC |
4310 | |
4311 | /* These are used for dwarf. */ | |
4312 | {"2byte", cons, 2}, | |
4313 | {"4byte", cons, 4}, | |
4314 | {"8byte", cons, 8}, | |
4315 | /* These are used for dwarf2. */ | |
4316 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4317 | { "loc", dwarf2_directive_loc, 0 }, | |
4318 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4319 | #endif |
4320 | { "extend", float_cons, 'x' }, | |
4321 | { "ldouble", float_cons, 'x' }, | |
4322 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4323 | #ifdef TE_PE |
4324 | {"secrel32", pe_directive_secrel, 0}, | |
4325 | #endif | |
c19d1205 ZW |
4326 | { 0, 0, 0 } |
4327 | }; | |
4328 | \f | |
4329 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4330 | |
c19d1205 ZW |
4331 | /* Generic immediate-value read function for use in insn parsing. |
4332 | STR points to the beginning of the immediate (the leading #); | |
4333 | VAL receives the value; if the value is outside [MIN, MAX] | |
4334 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4335 | optional. */ | |
b99bd4ef | 4336 | |
c19d1205 ZW |
4337 | static int |
4338 | parse_immediate (char **str, int *val, int min, int max, | |
4339 | bfd_boolean prefix_opt) | |
4340 | { | |
4341 | expressionS exp; | |
4342 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4343 | if (exp.X_op != O_constant) | |
b99bd4ef | 4344 | { |
c19d1205 ZW |
4345 | inst.error = _("constant expression required"); |
4346 | return FAIL; | |
4347 | } | |
b99bd4ef | 4348 | |
c19d1205 ZW |
4349 | if (exp.X_add_number < min || exp.X_add_number > max) |
4350 | { | |
4351 | inst.error = _("immediate value out of range"); | |
4352 | return FAIL; | |
4353 | } | |
b99bd4ef | 4354 | |
c19d1205 ZW |
4355 | *val = exp.X_add_number; |
4356 | return SUCCESS; | |
4357 | } | |
b99bd4ef | 4358 | |
5287ad62 | 4359 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4360 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4361 | instructions. Puts the result directly in inst.operands[i]. */ |
4362 | ||
4363 | static int | |
4364 | parse_big_immediate (char **str, int i) | |
4365 | { | |
4366 | expressionS exp; | |
4367 | char *ptr = *str; | |
4368 | ||
4369 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
4370 | ||
4371 | if (exp.X_op == O_constant) | |
036dc3f7 PB |
4372 | { |
4373 | inst.operands[i].imm = exp.X_add_number & 0xffffffff; | |
4374 | /* If we're on a 64-bit host, then a 64-bit number can be returned using | |
4375 | O_constant. We have to be careful not to break compilation for | |
4376 | 32-bit X_add_number, though. */ | |
4377 | if ((exp.X_add_number & ~0xffffffffl) != 0) | |
4378 | { | |
4379 | /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */ | |
4380 | inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff; | |
4381 | inst.operands[i].regisimm = 1; | |
4382 | } | |
4383 | } | |
5287ad62 JB |
4384 | else if (exp.X_op == O_big |
4385 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32 | |
4386 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64) | |
4387 | { | |
4388 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
4389 | /* Bignums have their least significant bits in | |
4390 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
4391 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4392 | gas_assert (parts != 0); |
5287ad62 JB |
4393 | inst.operands[i].imm = 0; |
4394 | for (j = 0; j < parts; j++, idx++) | |
4395 | inst.operands[i].imm |= generic_bignum[idx] | |
4396 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4397 | inst.operands[i].reg = 0; | |
4398 | for (j = 0; j < parts; j++, idx++) | |
4399 | inst.operands[i].reg |= generic_bignum[idx] | |
4400 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4401 | inst.operands[i].regisimm = 1; | |
4402 | } | |
4403 | else | |
4404 | return FAIL; | |
5f4273c7 | 4405 | |
5287ad62 JB |
4406 | *str = ptr; |
4407 | ||
4408 | return SUCCESS; | |
4409 | } | |
4410 | ||
c19d1205 ZW |
4411 | /* Returns the pseudo-register number of an FPA immediate constant, |
4412 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4413 | |
c19d1205 ZW |
4414 | static int |
4415 | parse_fpa_immediate (char ** str) | |
4416 | { | |
4417 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4418 | char * save_in; | |
4419 | expressionS exp; | |
4420 | int i; | |
4421 | int j; | |
b99bd4ef | 4422 | |
c19d1205 ZW |
4423 | /* First try and match exact strings, this is to guarantee |
4424 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4425 | |
c19d1205 ZW |
4426 | for (i = 0; fp_const[i]; i++) |
4427 | { | |
4428 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4429 | { |
c19d1205 | 4430 | char *start = *str; |
b99bd4ef | 4431 | |
c19d1205 ZW |
4432 | *str += strlen (fp_const[i]); |
4433 | if (is_end_of_line[(unsigned char) **str]) | |
4434 | return i + 8; | |
4435 | *str = start; | |
4436 | } | |
4437 | } | |
b99bd4ef | 4438 | |
c19d1205 ZW |
4439 | /* Just because we didn't get a match doesn't mean that the constant |
4440 | isn't valid, just that it is in a format that we don't | |
4441 | automatically recognize. Try parsing it with the standard | |
4442 | expression routines. */ | |
b99bd4ef | 4443 | |
c19d1205 | 4444 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4445 | |
c19d1205 ZW |
4446 | /* Look for a raw floating point number. */ |
4447 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4448 | && is_end_of_line[(unsigned char) *save_in]) | |
4449 | { | |
4450 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4451 | { | |
4452 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4453 | { |
c19d1205 ZW |
4454 | if (words[j] != fp_values[i][j]) |
4455 | break; | |
b99bd4ef NC |
4456 | } |
4457 | ||
c19d1205 | 4458 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4459 | { |
c19d1205 ZW |
4460 | *str = save_in; |
4461 | return i + 8; | |
b99bd4ef NC |
4462 | } |
4463 | } | |
4464 | } | |
b99bd4ef | 4465 | |
c19d1205 ZW |
4466 | /* Try and parse a more complex expression, this will probably fail |
4467 | unless the code uses a floating point prefix (eg "0f"). */ | |
4468 | save_in = input_line_pointer; | |
4469 | input_line_pointer = *str; | |
4470 | if (expression (&exp) == absolute_section | |
4471 | && exp.X_op == O_big | |
4472 | && exp.X_add_number < 0) | |
4473 | { | |
4474 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4475 | Ditto for 15. */ | |
4476 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4477 | { | |
4478 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4479 | { | |
4480 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4481 | { | |
4482 | if (words[j] != fp_values[i][j]) | |
4483 | break; | |
4484 | } | |
b99bd4ef | 4485 | |
c19d1205 ZW |
4486 | if (j == MAX_LITTLENUMS) |
4487 | { | |
4488 | *str = input_line_pointer; | |
4489 | input_line_pointer = save_in; | |
4490 | return i + 8; | |
4491 | } | |
4492 | } | |
4493 | } | |
b99bd4ef NC |
4494 | } |
4495 | ||
c19d1205 ZW |
4496 | *str = input_line_pointer; |
4497 | input_line_pointer = save_in; | |
4498 | inst.error = _("invalid FPA immediate expression"); | |
4499 | return FAIL; | |
b99bd4ef NC |
4500 | } |
4501 | ||
136da414 JB |
4502 | /* Returns 1 if a number has "quarter-precision" float format |
4503 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4504 | ||
4505 | static int | |
4506 | is_quarter_float (unsigned imm) | |
4507 | { | |
4508 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4509 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4510 | } | |
4511 | ||
4512 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4513 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4514 | The zero and minus-zero cases need special handling, since they can't be |
4515 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4516 | loaded as integer constants. */ | |
136da414 JB |
4517 | |
4518 | static unsigned | |
4519 | parse_qfloat_immediate (char **ccp, int *immed) | |
4520 | { | |
4521 | char *str = *ccp; | |
c96612cc | 4522 | char *fpnum; |
136da414 | 4523 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4524 | int found_fpchar = 0; |
5f4273c7 | 4525 | |
136da414 | 4526 | skip_past_char (&str, '#'); |
5f4273c7 | 4527 | |
c96612cc JB |
4528 | /* We must not accidentally parse an integer as a floating-point number. Make |
4529 | sure that the value we parse is not an integer by checking for special | |
4530 | characters '.' or 'e'. | |
4531 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4532 | information isn't in a very usable state at parse time. */ | |
4533 | fpnum = str; | |
4534 | skip_whitespace (fpnum); | |
4535 | ||
4536 | if (strncmp (fpnum, "0x", 2) == 0) | |
4537 | return FAIL; | |
4538 | else | |
4539 | { | |
4540 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
4541 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') | |
4542 | { | |
4543 | found_fpchar = 1; | |
4544 | break; | |
4545 | } | |
4546 | ||
4547 | if (!found_fpchar) | |
4548 | return FAIL; | |
4549 | } | |
5f4273c7 | 4550 | |
136da414 JB |
4551 | if ((str = atof_ieee (str, 's', words)) != NULL) |
4552 | { | |
4553 | unsigned fpword = 0; | |
4554 | int i; | |
5f4273c7 | 4555 | |
136da414 JB |
4556 | /* Our FP word must be 32 bits (single-precision FP). */ |
4557 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4558 | { | |
4559 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4560 | fpword |= words[i]; | |
4561 | } | |
5f4273c7 | 4562 | |
c96612cc | 4563 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
136da414 JB |
4564 | *immed = fpword; |
4565 | else | |
4566 | return FAIL; | |
4567 | ||
4568 | *ccp = str; | |
5f4273c7 | 4569 | |
136da414 JB |
4570 | return SUCCESS; |
4571 | } | |
5f4273c7 | 4572 | |
136da414 JB |
4573 | return FAIL; |
4574 | } | |
4575 | ||
c19d1205 ZW |
4576 | /* Shift operands. */ |
4577 | enum shift_kind | |
b99bd4ef | 4578 | { |
c19d1205 ZW |
4579 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4580 | }; | |
b99bd4ef | 4581 | |
c19d1205 ZW |
4582 | struct asm_shift_name |
4583 | { | |
4584 | const char *name; | |
4585 | enum shift_kind kind; | |
4586 | }; | |
b99bd4ef | 4587 | |
c19d1205 ZW |
4588 | /* Third argument to parse_shift. */ |
4589 | enum parse_shift_mode | |
4590 | { | |
4591 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4592 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4593 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4594 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4595 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4596 | }; | |
b99bd4ef | 4597 | |
c19d1205 ZW |
4598 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4599 | This has three forms: | |
b99bd4ef | 4600 | |
c19d1205 ZW |
4601 | (LSL|LSR|ASL|ASR|ROR) Rs |
4602 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4603 | RRX | |
b99bd4ef | 4604 | |
c19d1205 ZW |
4605 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4606 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4607 | |
c19d1205 ZW |
4608 | static int |
4609 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4610 | { |
c19d1205 ZW |
4611 | const struct asm_shift_name *shift_name; |
4612 | enum shift_kind shift; | |
4613 | char *s = *str; | |
4614 | char *p = s; | |
4615 | int reg; | |
b99bd4ef | 4616 | |
c19d1205 ZW |
4617 | for (p = *str; ISALPHA (*p); p++) |
4618 | ; | |
b99bd4ef | 4619 | |
c19d1205 | 4620 | if (p == *str) |
b99bd4ef | 4621 | { |
c19d1205 ZW |
4622 | inst.error = _("shift expression expected"); |
4623 | return FAIL; | |
b99bd4ef NC |
4624 | } |
4625 | ||
c19d1205 ZW |
4626 | shift_name = hash_find_n (arm_shift_hsh, *str, p - *str); |
4627 | ||
4628 | if (shift_name == NULL) | |
b99bd4ef | 4629 | { |
c19d1205 ZW |
4630 | inst.error = _("shift expression expected"); |
4631 | return FAIL; | |
b99bd4ef NC |
4632 | } |
4633 | ||
c19d1205 | 4634 | shift = shift_name->kind; |
b99bd4ef | 4635 | |
c19d1205 ZW |
4636 | switch (mode) |
4637 | { | |
4638 | case NO_SHIFT_RESTRICT: | |
4639 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4640 | |
c19d1205 ZW |
4641 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4642 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4643 | { | |
4644 | inst.error = _("'LSL' or 'ASR' required"); | |
4645 | return FAIL; | |
4646 | } | |
4647 | break; | |
b99bd4ef | 4648 | |
c19d1205 ZW |
4649 | case SHIFT_LSL_IMMEDIATE: |
4650 | if (shift != SHIFT_LSL) | |
4651 | { | |
4652 | inst.error = _("'LSL' required"); | |
4653 | return FAIL; | |
4654 | } | |
4655 | break; | |
b99bd4ef | 4656 | |
c19d1205 ZW |
4657 | case SHIFT_ASR_IMMEDIATE: |
4658 | if (shift != SHIFT_ASR) | |
4659 | { | |
4660 | inst.error = _("'ASR' required"); | |
4661 | return FAIL; | |
4662 | } | |
4663 | break; | |
b99bd4ef | 4664 | |
c19d1205 ZW |
4665 | default: abort (); |
4666 | } | |
b99bd4ef | 4667 | |
c19d1205 ZW |
4668 | if (shift != SHIFT_RRX) |
4669 | { | |
4670 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4671 | skip_whitespace (p); | |
b99bd4ef | 4672 | |
c19d1205 | 4673 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4674 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4675 | { |
4676 | inst.operands[i].imm = reg; | |
4677 | inst.operands[i].immisreg = 1; | |
4678 | } | |
4679 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4680 | return FAIL; | |
4681 | } | |
4682 | inst.operands[i].shift_kind = shift; | |
4683 | inst.operands[i].shifted = 1; | |
4684 | *str = p; | |
4685 | return SUCCESS; | |
b99bd4ef NC |
4686 | } |
4687 | ||
c19d1205 | 4688 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4689 | |
c19d1205 ZW |
4690 | #<immediate> |
4691 | #<immediate>, <rotate> | |
4692 | <Rm> | |
4693 | <Rm>, <shift> | |
b99bd4ef | 4694 | |
c19d1205 ZW |
4695 | where <shift> is defined by parse_shift above, and <rotate> is a |
4696 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4697 | is deferred to md_apply_fix. */ |
b99bd4ef | 4698 | |
c19d1205 ZW |
4699 | static int |
4700 | parse_shifter_operand (char **str, int i) | |
4701 | { | |
4702 | int value; | |
4703 | expressionS expr; | |
b99bd4ef | 4704 | |
dcbf9037 | 4705 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4706 | { |
4707 | inst.operands[i].reg = value; | |
4708 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4709 | |
c19d1205 ZW |
4710 | /* parse_shift will override this if appropriate */ |
4711 | inst.reloc.exp.X_op = O_constant; | |
4712 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4713 | |
c19d1205 ZW |
4714 | if (skip_past_comma (str) == FAIL) |
4715 | return SUCCESS; | |
b99bd4ef | 4716 | |
c19d1205 ZW |
4717 | /* Shift operation on register. */ |
4718 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4719 | } |
4720 | ||
c19d1205 ZW |
4721 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4722 | return FAIL; | |
b99bd4ef | 4723 | |
c19d1205 | 4724 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4725 | { |
c19d1205 ZW |
4726 | /* #x, y -- ie explicit rotation by Y. */ |
4727 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
4728 | return FAIL; | |
b99bd4ef | 4729 | |
c19d1205 ZW |
4730 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
4731 | { | |
4732 | inst.error = _("constant expression expected"); | |
4733 | return FAIL; | |
4734 | } | |
b99bd4ef | 4735 | |
c19d1205 ZW |
4736 | value = expr.X_add_number; |
4737 | if (value < 0 || value > 30 || value % 2 != 0) | |
4738 | { | |
4739 | inst.error = _("invalid rotation"); | |
4740 | return FAIL; | |
4741 | } | |
4742 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4743 | { | |
4744 | inst.error = _("invalid constant"); | |
4745 | return FAIL; | |
4746 | } | |
09d92015 | 4747 | |
55cf6793 | 4748 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
4749 | inst.reloc.exp.X_add_number |
4750 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
4751 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
4752 | } |
4753 | ||
c19d1205 ZW |
4754 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4755 | inst.reloc.pc_rel = 0; | |
4756 | return SUCCESS; | |
09d92015 MM |
4757 | } |
4758 | ||
4962c51a MS |
4759 | /* Group relocation information. Each entry in the table contains the |
4760 | textual name of the relocation as may appear in assembler source | |
4761 | and must end with a colon. | |
4762 | Along with this textual name are the relocation codes to be used if | |
4763 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4764 | an LDR, an LDRS, or an LDC. */ | |
4765 | ||
4766 | struct group_reloc_table_entry | |
4767 | { | |
4768 | const char *name; | |
4769 | int alu_code; | |
4770 | int ldr_code; | |
4771 | int ldrs_code; | |
4772 | int ldc_code; | |
4773 | }; | |
4774 | ||
4775 | typedef enum | |
4776 | { | |
4777 | /* Varieties of non-ALU group relocation. */ | |
4778 | ||
4779 | GROUP_LDR, | |
4780 | GROUP_LDRS, | |
4781 | GROUP_LDC | |
4782 | } group_reloc_type; | |
4783 | ||
4784 | static struct group_reloc_table_entry group_reloc_table[] = | |
4785 | { /* Program counter relative: */ | |
4786 | { "pc_g0_nc", | |
4787 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4788 | 0, /* LDR */ | |
4789 | 0, /* LDRS */ | |
4790 | 0 }, /* LDC */ | |
4791 | { "pc_g0", | |
4792 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4793 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4794 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4795 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4796 | { "pc_g1_nc", | |
4797 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4798 | 0, /* LDR */ | |
4799 | 0, /* LDRS */ | |
4800 | 0 }, /* LDC */ | |
4801 | { "pc_g1", | |
4802 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4803 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4804 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4805 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4806 | { "pc_g2", | |
4807 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4808 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4809 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4810 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4811 | /* Section base relative */ | |
4812 | { "sb_g0_nc", | |
4813 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4814 | 0, /* LDR */ | |
4815 | 0, /* LDRS */ | |
4816 | 0 }, /* LDC */ | |
4817 | { "sb_g0", | |
4818 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4819 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4820 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4821 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4822 | { "sb_g1_nc", | |
4823 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4824 | 0, /* LDR */ | |
4825 | 0, /* LDRS */ | |
4826 | 0 }, /* LDC */ | |
4827 | { "sb_g1", | |
4828 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4829 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4830 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4831 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4832 | { "sb_g2", | |
4833 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
4834 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
4835 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
4836 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
4837 | ||
4838 | /* Given the address of a pointer pointing to the textual name of a group | |
4839 | relocation as may appear in assembler source, attempt to find its details | |
4840 | in group_reloc_table. The pointer will be updated to the character after | |
4841 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
4842 | otherwise. On success, *entry will be updated to point at the relevant | |
4843 | group_reloc_table entry. */ | |
4844 | ||
4845 | static int | |
4846 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
4847 | { | |
4848 | unsigned int i; | |
4849 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
4850 | { | |
4851 | int length = strlen (group_reloc_table[i].name); | |
4852 | ||
5f4273c7 NC |
4853 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
4854 | && (*str)[length] == ':') | |
4962c51a MS |
4855 | { |
4856 | *out = &group_reloc_table[i]; | |
4857 | *str += (length + 1); | |
4858 | return SUCCESS; | |
4859 | } | |
4860 | } | |
4861 | ||
4862 | return FAIL; | |
4863 | } | |
4864 | ||
4865 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
4866 | (as for parse_shifter_operand) where group relocations are allowed: | |
4867 | ||
4868 | #<immediate> | |
4869 | #<immediate>, <rotate> | |
4870 | #:<group_reloc>:<expression> | |
4871 | <Rm> | |
4872 | <Rm>, <shift> | |
4873 | ||
4874 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
4875 | The hashes are optional. | |
4876 | ||
4877 | Everything else is as for parse_shifter_operand. */ | |
4878 | ||
4879 | static parse_operand_result | |
4880 | parse_shifter_operand_group_reloc (char **str, int i) | |
4881 | { | |
4882 | /* Determine if we have the sequence of characters #: or just : | |
4883 | coming next. If we do, then we check for a group relocation. | |
4884 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
4885 | ||
4886 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
4887 | || (*str)[0] == ':') | |
4888 | { | |
4889 | struct group_reloc_table_entry *entry; | |
4890 | ||
4891 | if ((*str)[0] == '#') | |
4892 | (*str) += 2; | |
4893 | else | |
4894 | (*str)++; | |
4895 | ||
4896 | /* Try to parse a group relocation. Anything else is an error. */ | |
4897 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
4898 | { | |
4899 | inst.error = _("unknown group relocation"); | |
4900 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4901 | } | |
4902 | ||
4903 | /* We now have the group relocation table entry corresponding to | |
4904 | the name in the assembler source. Next, we parse the expression. */ | |
4905 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
4906 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4907 | ||
4908 | /* Record the relocation type (always the ALU variant here). */ | |
4909 | inst.reloc.type = entry->alu_code; | |
9c2799c2 | 4910 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
4911 | |
4912 | return PARSE_OPERAND_SUCCESS; | |
4913 | } | |
4914 | else | |
4915 | return parse_shifter_operand (str, i) == SUCCESS | |
4916 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
4917 | ||
4918 | /* Never reached. */ | |
4919 | } | |
4920 | ||
c19d1205 ZW |
4921 | /* Parse all forms of an ARM address expression. Information is written |
4922 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 4923 | |
c19d1205 | 4924 | Preindexed addressing (.preind=1): |
09d92015 | 4925 | |
c19d1205 ZW |
4926 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
4927 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4928 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4929 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4930 | |
c19d1205 | 4931 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 4932 | |
c19d1205 | 4933 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 4934 | |
c19d1205 ZW |
4935 | [Rn], #offset .reg=Rn .reloc.exp=offset |
4936 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4937 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4938 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4939 | |
c19d1205 | 4940 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 4941 | |
c19d1205 | 4942 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 4943 | |
c19d1205 | 4944 | Other: |
09d92015 | 4945 | |
c19d1205 ZW |
4946 | [Rn]{!} shorthand for [Rn,#0]{!} |
4947 | =immediate .isreg=0 .reloc.exp=immediate | |
4948 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 4949 | |
c19d1205 ZW |
4950 | It is the caller's responsibility to check for addressing modes not |
4951 | supported by the instruction, and to set inst.reloc.type. */ | |
4952 | ||
4962c51a MS |
4953 | static parse_operand_result |
4954 | parse_address_main (char **str, int i, int group_relocations, | |
4955 | group_reloc_type group_type) | |
09d92015 | 4956 | { |
c19d1205 ZW |
4957 | char *p = *str; |
4958 | int reg; | |
09d92015 | 4959 | |
c19d1205 | 4960 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 4961 | { |
c19d1205 ZW |
4962 | if (skip_past_char (&p, '=') == FAIL) |
4963 | { | |
4964 | /* bare address - translate to PC-relative offset */ | |
4965 | inst.reloc.pc_rel = 1; | |
4966 | inst.operands[i].reg = REG_PC; | |
4967 | inst.operands[i].isreg = 1; | |
4968 | inst.operands[i].preind = 1; | |
4969 | } | |
4970 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 4971 | |
c19d1205 | 4972 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 4973 | return PARSE_OPERAND_FAIL; |
09d92015 | 4974 | |
c19d1205 | 4975 | *str = p; |
4962c51a | 4976 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
4977 | } |
4978 | ||
dcbf9037 | 4979 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 4980 | { |
c19d1205 | 4981 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 4982 | return PARSE_OPERAND_FAIL; |
09d92015 | 4983 | } |
c19d1205 ZW |
4984 | inst.operands[i].reg = reg; |
4985 | inst.operands[i].isreg = 1; | |
09d92015 | 4986 | |
c19d1205 | 4987 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4988 | { |
c19d1205 | 4989 | inst.operands[i].preind = 1; |
09d92015 | 4990 | |
c19d1205 ZW |
4991 | if (*p == '+') p++; |
4992 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
4993 | ||
dcbf9037 | 4994 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 4995 | { |
c19d1205 ZW |
4996 | inst.operands[i].imm = reg; |
4997 | inst.operands[i].immisreg = 1; | |
4998 | ||
4999 | if (skip_past_comma (&p) == SUCCESS) | |
5000 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5001 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5002 | } |
5287ad62 JB |
5003 | else if (skip_past_char (&p, ':') == SUCCESS) |
5004 | { | |
5005 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5006 | code before we get to see it here. This may be subject to | |
5007 | change. */ | |
5008 | expressionS exp; | |
5009 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5010 | if (exp.X_op != O_constant) | |
5011 | { | |
5012 | inst.error = _("alignment must be constant"); | |
4962c51a | 5013 | return PARSE_OPERAND_FAIL; |
5287ad62 JB |
5014 | } |
5015 | inst.operands[i].imm = exp.X_add_number << 8; | |
5016 | inst.operands[i].immisalign = 1; | |
5017 | /* Alignments are not pre-indexes. */ | |
5018 | inst.operands[i].preind = 0; | |
5019 | } | |
c19d1205 ZW |
5020 | else |
5021 | { | |
5022 | if (inst.operands[i].negative) | |
5023 | { | |
5024 | inst.operands[i].negative = 0; | |
5025 | p--; | |
5026 | } | |
4962c51a | 5027 | |
5f4273c7 NC |
5028 | if (group_relocations |
5029 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5030 | { |
5031 | struct group_reloc_table_entry *entry; | |
5032 | ||
5033 | /* Skip over the #: or : sequence. */ | |
5034 | if (*p == '#') | |
5035 | p += 2; | |
5036 | else | |
5037 | p++; | |
5038 | ||
5039 | /* Try to parse a group relocation. Anything else is an | |
5040 | error. */ | |
5041 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
5042 | { | |
5043 | inst.error = _("unknown group relocation"); | |
5044 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5045 | } | |
5046 | ||
5047 | /* We now have the group relocation table entry corresponding to | |
5048 | the name in the assembler source. Next, we parse the | |
5049 | expression. */ | |
5050 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5051 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5052 | ||
5053 | /* Record the relocation type. */ | |
5054 | switch (group_type) | |
5055 | { | |
5056 | case GROUP_LDR: | |
5057 | inst.reloc.type = entry->ldr_code; | |
5058 | break; | |
5059 | ||
5060 | case GROUP_LDRS: | |
5061 | inst.reloc.type = entry->ldrs_code; | |
5062 | break; | |
5063 | ||
5064 | case GROUP_LDC: | |
5065 | inst.reloc.type = entry->ldc_code; | |
5066 | break; | |
5067 | ||
5068 | default: | |
9c2799c2 | 5069 | gas_assert (0); |
4962c51a MS |
5070 | } |
5071 | ||
5072 | if (inst.reloc.type == 0) | |
5073 | { | |
5074 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5075 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5076 | } | |
5077 | } | |
5078 | else | |
5079 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5080 | return PARSE_OPERAND_FAIL; | |
09d92015 MM |
5081 | } |
5082 | } | |
5083 | ||
c19d1205 | 5084 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5085 | { |
c19d1205 | 5086 | inst.error = _("']' expected"); |
4962c51a | 5087 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5088 | } |
5089 | ||
c19d1205 ZW |
5090 | if (skip_past_char (&p, '!') == SUCCESS) |
5091 | inst.operands[i].writeback = 1; | |
09d92015 | 5092 | |
c19d1205 | 5093 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5094 | { |
c19d1205 ZW |
5095 | if (skip_past_char (&p, '{') == SUCCESS) |
5096 | { | |
5097 | /* [Rn], {expr} - unindexed, with option */ | |
5098 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5099 | 0, 255, TRUE) == FAIL) |
4962c51a | 5100 | return PARSE_OPERAND_FAIL; |
09d92015 | 5101 | |
c19d1205 ZW |
5102 | if (skip_past_char (&p, '}') == FAIL) |
5103 | { | |
5104 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5105 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5106 | } |
5107 | if (inst.operands[i].preind) | |
5108 | { | |
5109 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5110 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5111 | } |
5112 | *str = p; | |
4962c51a | 5113 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5114 | } |
c19d1205 ZW |
5115 | else |
5116 | { | |
5117 | inst.operands[i].postind = 1; | |
5118 | inst.operands[i].writeback = 1; | |
09d92015 | 5119 | |
c19d1205 ZW |
5120 | if (inst.operands[i].preind) |
5121 | { | |
5122 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5123 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5124 | } |
09d92015 | 5125 | |
c19d1205 ZW |
5126 | if (*p == '+') p++; |
5127 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5128 | |
dcbf9037 | 5129 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5130 | { |
5287ad62 JB |
5131 | /* We might be using the immediate for alignment already. If we |
5132 | are, OR the register number into the low-order bits. */ | |
5133 | if (inst.operands[i].immisalign) | |
5134 | inst.operands[i].imm |= reg; | |
5135 | else | |
5136 | inst.operands[i].imm = reg; | |
c19d1205 | 5137 | inst.operands[i].immisreg = 1; |
a737bd4d | 5138 | |
c19d1205 ZW |
5139 | if (skip_past_comma (&p) == SUCCESS) |
5140 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5141 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5142 | } |
5143 | else | |
5144 | { | |
5145 | if (inst.operands[i].negative) | |
5146 | { | |
5147 | inst.operands[i].negative = 0; | |
5148 | p--; | |
5149 | } | |
5150 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5151 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5152 | } |
5153 | } | |
a737bd4d NC |
5154 | } |
5155 | ||
c19d1205 ZW |
5156 | /* If at this point neither .preind nor .postind is set, we have a |
5157 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5158 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5159 | { | |
5160 | inst.operands[i].preind = 1; | |
5161 | inst.reloc.exp.X_op = O_constant; | |
5162 | inst.reloc.exp.X_add_number = 0; | |
5163 | } | |
5164 | *str = p; | |
4962c51a MS |
5165 | return PARSE_OPERAND_SUCCESS; |
5166 | } | |
5167 | ||
5168 | static int | |
5169 | parse_address (char **str, int i) | |
5170 | { | |
5171 | return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS | |
5172 | ? SUCCESS : FAIL; | |
5173 | } | |
5174 | ||
5175 | static parse_operand_result | |
5176 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5177 | { | |
5178 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5179 | } |
5180 | ||
b6895b4f PB |
5181 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5182 | static int | |
5183 | parse_half (char **str) | |
5184 | { | |
5185 | char * p; | |
5f4273c7 | 5186 | |
b6895b4f PB |
5187 | p = *str; |
5188 | skip_past_char (&p, '#'); | |
5f4273c7 | 5189 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5190 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5191 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5192 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5193 | ||
5194 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5195 | { | |
5196 | p += 9; | |
5f4273c7 | 5197 | skip_whitespace (p); |
b6895b4f PB |
5198 | } |
5199 | ||
5200 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5201 | return FAIL; | |
5202 | ||
5203 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5204 | { | |
5205 | if (inst.reloc.exp.X_op != O_constant) | |
5206 | { | |
5207 | inst.error = _("constant expression expected"); | |
5208 | return FAIL; | |
5209 | } | |
5210 | if (inst.reloc.exp.X_add_number < 0 | |
5211 | || inst.reloc.exp.X_add_number > 0xffff) | |
5212 | { | |
5213 | inst.error = _("immediate value out of range"); | |
5214 | return FAIL; | |
5215 | } | |
5216 | } | |
5217 | *str = p; | |
5218 | return SUCCESS; | |
5219 | } | |
5220 | ||
c19d1205 | 5221 | /* Miscellaneous. */ |
a737bd4d | 5222 | |
c19d1205 ZW |
5223 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5224 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5225 | static int | |
5226 | parse_psr (char **str) | |
09d92015 | 5227 | { |
c19d1205 ZW |
5228 | char *p; |
5229 | unsigned long psr_field; | |
62b3e311 PB |
5230 | const struct asm_psr *psr; |
5231 | char *start; | |
09d92015 | 5232 | |
c19d1205 ZW |
5233 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5234 | feature for ease of use and backwards compatibility. */ | |
5235 | p = *str; | |
62b3e311 | 5236 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 5237 | psr_field = SPSR_BIT; |
62b3e311 | 5238 | else if (strncasecmp (p, "CPSR", 4) == 0) |
c19d1205 ZW |
5239 | psr_field = 0; |
5240 | else | |
62b3e311 PB |
5241 | { |
5242 | start = p; | |
5243 | do | |
5244 | p++; | |
5245 | while (ISALNUM (*p) || *p == '_'); | |
5246 | ||
5247 | psr = hash_find_n (arm_v7m_psr_hsh, start, p - start); | |
5248 | if (!psr) | |
5249 | return FAIL; | |
09d92015 | 5250 | |
62b3e311 PB |
5251 | *str = p; |
5252 | return psr->field; | |
5253 | } | |
09d92015 | 5254 | |
62b3e311 | 5255 | p += 4; |
c19d1205 ZW |
5256 | if (*p == '_') |
5257 | { | |
5258 | /* A suffix follows. */ | |
c19d1205 ZW |
5259 | p++; |
5260 | start = p; | |
a737bd4d | 5261 | |
c19d1205 ZW |
5262 | do |
5263 | p++; | |
5264 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5265 | |
c19d1205 ZW |
5266 | psr = hash_find_n (arm_psr_hsh, start, p - start); |
5267 | if (!psr) | |
5268 | goto error; | |
a737bd4d | 5269 | |
c19d1205 | 5270 | psr_field |= psr->field; |
a737bd4d | 5271 | } |
c19d1205 | 5272 | else |
a737bd4d | 5273 | { |
c19d1205 ZW |
5274 | if (ISALNUM (*p)) |
5275 | goto error; /* Garbage after "[CS]PSR". */ | |
5276 | ||
5277 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5278 | } |
c19d1205 ZW |
5279 | *str = p; |
5280 | return psr_field; | |
a737bd4d | 5281 | |
c19d1205 ZW |
5282 | error: |
5283 | inst.error = _("flag for {c}psr instruction expected"); | |
5284 | return FAIL; | |
a737bd4d NC |
5285 | } |
5286 | ||
c19d1205 ZW |
5287 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5288 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5289 | |
c19d1205 ZW |
5290 | static int |
5291 | parse_cps_flags (char **str) | |
a737bd4d | 5292 | { |
c19d1205 ZW |
5293 | int val = 0; |
5294 | int saw_a_flag = 0; | |
5295 | char *s = *str; | |
a737bd4d | 5296 | |
c19d1205 ZW |
5297 | for (;;) |
5298 | switch (*s++) | |
5299 | { | |
5300 | case '\0': case ',': | |
5301 | goto done; | |
a737bd4d | 5302 | |
c19d1205 ZW |
5303 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5304 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5305 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5306 | |
c19d1205 ZW |
5307 | default: |
5308 | inst.error = _("unrecognized CPS flag"); | |
5309 | return FAIL; | |
5310 | } | |
a737bd4d | 5311 | |
c19d1205 ZW |
5312 | done: |
5313 | if (saw_a_flag == 0) | |
a737bd4d | 5314 | { |
c19d1205 ZW |
5315 | inst.error = _("missing CPS flags"); |
5316 | return FAIL; | |
a737bd4d | 5317 | } |
a737bd4d | 5318 | |
c19d1205 ZW |
5319 | *str = s - 1; |
5320 | return val; | |
a737bd4d NC |
5321 | } |
5322 | ||
c19d1205 ZW |
5323 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
5324 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
5325 | |
5326 | static int | |
c19d1205 | 5327 | parse_endian_specifier (char **str) |
a737bd4d | 5328 | { |
c19d1205 ZW |
5329 | int little_endian; |
5330 | char *s = *str; | |
a737bd4d | 5331 | |
c19d1205 ZW |
5332 | if (strncasecmp (s, "BE", 2)) |
5333 | little_endian = 0; | |
5334 | else if (strncasecmp (s, "LE", 2)) | |
5335 | little_endian = 1; | |
5336 | else | |
a737bd4d | 5337 | { |
c19d1205 | 5338 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5339 | return FAIL; |
5340 | } | |
5341 | ||
c19d1205 | 5342 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 5343 | { |
c19d1205 | 5344 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5345 | return FAIL; |
5346 | } | |
5347 | ||
c19d1205 ZW |
5348 | *str = s + 2; |
5349 | return little_endian; | |
5350 | } | |
a737bd4d | 5351 | |
c19d1205 ZW |
5352 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
5353 | value suitable for poking into the rotate field of an sxt or sxta | |
5354 | instruction, or FAIL on error. */ | |
5355 | ||
5356 | static int | |
5357 | parse_ror (char **str) | |
5358 | { | |
5359 | int rot; | |
5360 | char *s = *str; | |
5361 | ||
5362 | if (strncasecmp (s, "ROR", 3) == 0) | |
5363 | s += 3; | |
5364 | else | |
a737bd4d | 5365 | { |
c19d1205 | 5366 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
5367 | return FAIL; |
5368 | } | |
c19d1205 ZW |
5369 | |
5370 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
5371 | return FAIL; | |
5372 | ||
5373 | switch (rot) | |
a737bd4d | 5374 | { |
c19d1205 ZW |
5375 | case 0: *str = s; return 0x0; |
5376 | case 8: *str = s; return 0x1; | |
5377 | case 16: *str = s; return 0x2; | |
5378 | case 24: *str = s; return 0x3; | |
5379 | ||
5380 | default: | |
5381 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
5382 | return FAIL; |
5383 | } | |
c19d1205 | 5384 | } |
a737bd4d | 5385 | |
c19d1205 ZW |
5386 | /* Parse a conditional code (from conds[] below). The value returned is in the |
5387 | range 0 .. 14, or FAIL. */ | |
5388 | static int | |
5389 | parse_cond (char **str) | |
5390 | { | |
c462b453 | 5391 | char *q; |
c19d1205 | 5392 | const struct asm_cond *c; |
c462b453 PB |
5393 | int n; |
5394 | /* Condition codes are always 2 characters, so matching up to | |
5395 | 3 characters is sufficient. */ | |
5396 | char cond[3]; | |
a737bd4d | 5397 | |
c462b453 PB |
5398 | q = *str; |
5399 | n = 0; | |
5400 | while (ISALPHA (*q) && n < 3) | |
5401 | { | |
e07e6e58 | 5402 | cond[n] = TOLOWER (*q); |
c462b453 PB |
5403 | q++; |
5404 | n++; | |
5405 | } | |
a737bd4d | 5406 | |
c462b453 | 5407 | c = hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 5408 | if (!c) |
a737bd4d | 5409 | { |
c19d1205 | 5410 | inst.error = _("condition required"); |
a737bd4d NC |
5411 | return FAIL; |
5412 | } | |
5413 | ||
c19d1205 ZW |
5414 | *str = q; |
5415 | return c->value; | |
5416 | } | |
5417 | ||
62b3e311 PB |
5418 | /* Parse an option for a barrier instruction. Returns the encoding for the |
5419 | option, or FAIL. */ | |
5420 | static int | |
5421 | parse_barrier (char **str) | |
5422 | { | |
5423 | char *p, *q; | |
5424 | const struct asm_barrier_opt *o; | |
5425 | ||
5426 | p = q = *str; | |
5427 | while (ISALPHA (*q)) | |
5428 | q++; | |
5429 | ||
5430 | o = hash_find_n (arm_barrier_opt_hsh, p, q - p); | |
5431 | if (!o) | |
5432 | return FAIL; | |
5433 | ||
5434 | *str = q; | |
5435 | return o->value; | |
5436 | } | |
5437 | ||
92e90b6e PB |
5438 | /* Parse the operands of a table branch instruction. Similar to a memory |
5439 | operand. */ | |
5440 | static int | |
5441 | parse_tb (char **str) | |
5442 | { | |
5443 | char * p = *str; | |
5444 | int reg; | |
5445 | ||
5446 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5447 | { |
5448 | inst.error = _("'[' expected"); | |
5449 | return FAIL; | |
5450 | } | |
92e90b6e | 5451 | |
dcbf9037 | 5452 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5453 | { |
5454 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5455 | return FAIL; | |
5456 | } | |
5457 | inst.operands[0].reg = reg; | |
5458 | ||
5459 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5460 | { |
5461 | inst.error = _("',' expected"); | |
5462 | return FAIL; | |
5463 | } | |
5f4273c7 | 5464 | |
dcbf9037 | 5465 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5466 | { |
5467 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5468 | return FAIL; | |
5469 | } | |
5470 | inst.operands[0].imm = reg; | |
5471 | ||
5472 | if (skip_past_comma (&p) == SUCCESS) | |
5473 | { | |
5474 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5475 | return FAIL; | |
5476 | if (inst.reloc.exp.X_add_number != 1) | |
5477 | { | |
5478 | inst.error = _("invalid shift"); | |
5479 | return FAIL; | |
5480 | } | |
5481 | inst.operands[0].shifted = 1; | |
5482 | } | |
5483 | ||
5484 | if (skip_past_char (&p, ']') == FAIL) | |
5485 | { | |
5486 | inst.error = _("']' expected"); | |
5487 | return FAIL; | |
5488 | } | |
5489 | *str = p; | |
5490 | return SUCCESS; | |
5491 | } | |
5492 | ||
5287ad62 JB |
5493 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5494 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5495 | Up to four operands may be read; this function handles setting the |
5496 | ".present" field for each read operand itself. | |
5287ad62 JB |
5497 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5498 | else returns FAIL. */ | |
5499 | ||
5500 | static int | |
5501 | parse_neon_mov (char **str, int *which_operand) | |
5502 | { | |
5503 | int i = *which_operand, val; | |
5504 | enum arm_reg_type rtype; | |
5505 | char *ptr = *str; | |
dcbf9037 | 5506 | struct neon_type_el optype; |
5f4273c7 | 5507 | |
dcbf9037 | 5508 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5509 | { |
5510 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5511 | inst.operands[i].reg = val; | |
5512 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5513 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5514 | inst.operands[i++].present = 1; |
5515 | ||
5516 | if (skip_past_comma (&ptr) == FAIL) | |
5517 | goto wanted_comma; | |
5f4273c7 | 5518 | |
dcbf9037 | 5519 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 | 5520 | goto wanted_arm; |
5f4273c7 | 5521 | |
5287ad62 JB |
5522 | inst.operands[i].reg = val; |
5523 | inst.operands[i].isreg = 1; | |
5524 | inst.operands[i].present = 1; | |
5525 | } | |
037e8744 | 5526 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5527 | != FAIL) |
5287ad62 JB |
5528 | { |
5529 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5530 | if (skip_past_comma (&ptr) == FAIL) | |
5531 | goto wanted_comma; | |
5f4273c7 | 5532 | |
5287ad62 JB |
5533 | inst.operands[i].reg = val; |
5534 | inst.operands[i].isreg = 1; | |
5535 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5536 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5537 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5538 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5539 | inst.operands[i++].present = 1; |
5540 | ||
dcbf9037 | 5541 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5542 | { |
037e8744 JB |
5543 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5544 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5545 | inst.operands[i].reg = val; |
5546 | inst.operands[i].isreg = 1; | |
037e8744 | 5547 | inst.operands[i].present = 1; |
5287ad62 JB |
5548 | |
5549 | if (rtype == REG_TYPE_NQ) | |
5550 | { | |
dcbf9037 | 5551 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5552 | return FAIL; |
5553 | } | |
037e8744 JB |
5554 | else if (rtype != REG_TYPE_VFS) |
5555 | { | |
5556 | i++; | |
5557 | if (skip_past_comma (&ptr) == FAIL) | |
5558 | goto wanted_comma; | |
5559 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5560 | goto wanted_arm; | |
5561 | inst.operands[i].reg = val; | |
5562 | inst.operands[i].isreg = 1; | |
5563 | inst.operands[i].present = 1; | |
5564 | } | |
5287ad62 | 5565 | } |
037e8744 JB |
5566 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
5567 | &optype)) != FAIL) | |
5287ad62 JB |
5568 | { |
5569 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5570 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5571 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5572 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5573 | |
5574 | inst.operands[i].reg = val; | |
5575 | inst.operands[i].isreg = 1; | |
5576 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5577 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5578 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5579 | inst.operands[i].vectype = optype; |
5287ad62 | 5580 | inst.operands[i].present = 1; |
5f4273c7 | 5581 | |
037e8744 JB |
5582 | if (skip_past_comma (&ptr) == SUCCESS) |
5583 | { | |
5584 | /* Case 15. */ | |
5585 | i++; | |
5586 | ||
5587 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5588 | goto wanted_arm; | |
5589 | ||
5590 | inst.operands[i].reg = val; | |
5591 | inst.operands[i].isreg = 1; | |
5592 | inst.operands[i++].present = 1; | |
5f4273c7 | 5593 | |
037e8744 JB |
5594 | if (skip_past_comma (&ptr) == FAIL) |
5595 | goto wanted_comma; | |
5f4273c7 | 5596 | |
037e8744 JB |
5597 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5598 | goto wanted_arm; | |
5f4273c7 | 5599 | |
037e8744 JB |
5600 | inst.operands[i].reg = val; |
5601 | inst.operands[i].isreg = 1; | |
5602 | inst.operands[i++].present = 1; | |
5603 | } | |
5287ad62 | 5604 | } |
4641781c PB |
5605 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
5606 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> | |
5607 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
5608 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5609 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5610 | inst.operands[i].immisfloat = 1; | |
5611 | else if (parse_big_immediate (&ptr, i) == SUCCESS) | |
5612 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> | |
5613 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
5614 | ; | |
5287ad62 JB |
5615 | else |
5616 | { | |
dcbf9037 | 5617 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
5618 | return FAIL; |
5619 | } | |
5620 | } | |
dcbf9037 | 5621 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5622 | { |
5623 | /* Cases 6, 7. */ | |
5624 | inst.operands[i].reg = val; | |
5625 | inst.operands[i].isreg = 1; | |
5626 | inst.operands[i++].present = 1; | |
5f4273c7 | 5627 | |
5287ad62 JB |
5628 | if (skip_past_comma (&ptr) == FAIL) |
5629 | goto wanted_comma; | |
5f4273c7 | 5630 | |
dcbf9037 | 5631 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5632 | { |
5633 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
5634 | inst.operands[i].reg = val; | |
5635 | inst.operands[i].isscalar = 1; | |
5636 | inst.operands[i].present = 1; | |
dcbf9037 | 5637 | inst.operands[i].vectype = optype; |
5287ad62 | 5638 | } |
dcbf9037 | 5639 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5640 | { |
5641 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
5642 | inst.operands[i].reg = val; | |
5643 | inst.operands[i].isreg = 1; | |
5644 | inst.operands[i++].present = 1; | |
5f4273c7 | 5645 | |
5287ad62 JB |
5646 | if (skip_past_comma (&ptr) == FAIL) |
5647 | goto wanted_comma; | |
5f4273c7 | 5648 | |
037e8744 | 5649 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 5650 | == FAIL) |
5287ad62 | 5651 | { |
037e8744 | 5652 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
5653 | return FAIL; |
5654 | } | |
5655 | ||
5656 | inst.operands[i].reg = val; | |
5657 | inst.operands[i].isreg = 1; | |
037e8744 JB |
5658 | inst.operands[i].isvec = 1; |
5659 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 5660 | inst.operands[i].vectype = optype; |
5287ad62 | 5661 | inst.operands[i].present = 1; |
5f4273c7 | 5662 | |
037e8744 JB |
5663 | if (rtype == REG_TYPE_VFS) |
5664 | { | |
5665 | /* Case 14. */ | |
5666 | i++; | |
5667 | if (skip_past_comma (&ptr) == FAIL) | |
5668 | goto wanted_comma; | |
5669 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
5670 | &optype)) == FAIL) | |
5671 | { | |
5672 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
5673 | return FAIL; | |
5674 | } | |
5675 | inst.operands[i].reg = val; | |
5676 | inst.operands[i].isreg = 1; | |
5677 | inst.operands[i].isvec = 1; | |
5678 | inst.operands[i].issingle = 1; | |
5679 | inst.operands[i].vectype = optype; | |
5680 | inst.operands[i].present = 1; | |
5681 | } | |
5682 | } | |
5683 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
5684 | != FAIL) | |
5685 | { | |
5686 | /* Case 13. */ | |
5687 | inst.operands[i].reg = val; | |
5688 | inst.operands[i].isreg = 1; | |
5689 | inst.operands[i].isvec = 1; | |
5690 | inst.operands[i].issingle = 1; | |
5691 | inst.operands[i].vectype = optype; | |
5692 | inst.operands[i++].present = 1; | |
5287ad62 JB |
5693 | } |
5694 | } | |
5695 | else | |
5696 | { | |
dcbf9037 | 5697 | first_error (_("parse error")); |
5287ad62 JB |
5698 | return FAIL; |
5699 | } | |
5700 | ||
5701 | /* Successfully parsed the operands. Update args. */ | |
5702 | *which_operand = i; | |
5703 | *str = ptr; | |
5704 | return SUCCESS; | |
5705 | ||
5f4273c7 | 5706 | wanted_comma: |
dcbf9037 | 5707 | first_error (_("expected comma")); |
5287ad62 | 5708 | return FAIL; |
5f4273c7 NC |
5709 | |
5710 | wanted_arm: | |
dcbf9037 | 5711 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 5712 | return FAIL; |
5287ad62 JB |
5713 | } |
5714 | ||
c19d1205 ZW |
5715 | /* Matcher codes for parse_operands. */ |
5716 | enum operand_parse_code | |
5717 | { | |
5718 | OP_stop, /* end of line */ | |
5719 | ||
5720 | OP_RR, /* ARM register */ | |
5721 | OP_RRnpc, /* ARM register, not r15 */ | |
5722 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
5723 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
5724 | OP_RCP, /* Coprocessor number */ | |
5725 | OP_RCN, /* Coprocessor register */ | |
5726 | OP_RF, /* FPA register */ | |
5727 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
5728 | OP_RVD, /* VFP double precision register (0..15) */ |
5729 | OP_RND, /* Neon double precision register (0..31) */ | |
5730 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 5731 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 5732 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 5733 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 5734 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
5735 | OP_RVC, /* VFP control register */ |
5736 | OP_RMF, /* Maverick F register */ | |
5737 | OP_RMD, /* Maverick D register */ | |
5738 | OP_RMFX, /* Maverick FX register */ | |
5739 | OP_RMDX, /* Maverick DX register */ | |
5740 | OP_RMAX, /* Maverick AX register */ | |
5741 | OP_RMDS, /* Maverick DSPSC register */ | |
5742 | OP_RIWR, /* iWMMXt wR register */ | |
5743 | OP_RIWC, /* iWMMXt wC register */ | |
5744 | OP_RIWG, /* iWMMXt wCG register */ | |
5745 | OP_RXA, /* XScale accumulator register */ | |
5746 | ||
5747 | OP_REGLST, /* ARM register list */ | |
5748 | OP_VRSLST, /* VFP single-precision register list */ | |
5749 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 5750 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
5751 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
5752 | OP_NSTRLST, /* Neon element/structure list */ | |
5753 | ||
5754 | OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */ | |
5755 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ | |
037e8744 | 5756 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 5757 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 5758 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
5759 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
5760 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
5761 | OP_VMOV, /* Neon VMOV operands. */ | |
5762 | OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */ | |
5763 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ | |
2d447fca | 5764 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
5765 | |
5766 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
5767 | OP_I7, /* immediate value 0 .. 7 */ |
5768 | OP_I15, /* 0 .. 15 */ | |
5769 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 5770 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
5771 | OP_I31, /* 0 .. 31 */ |
5772 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
5773 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
5774 | OP_I32z, /* 0 .. 32 */ |
5775 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 5776 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
5777 | OP_I64, /* 1 .. 64 */ |
5778 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 5779 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
5780 | |
5781 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
5782 | OP_I7b, /* 0 .. 7 */ | |
5783 | OP_I15b, /* 0 .. 15 */ | |
5784 | OP_I31b, /* 0 .. 31 */ | |
5785 | ||
5786 | OP_SH, /* shifter operand */ | |
4962c51a | 5787 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 5788 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
5789 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
5790 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
5791 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
5792 | OP_EXP, /* arbitrary expression */ |
5793 | OP_EXPi, /* same, with optional immediate prefix */ | |
5794 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 5795 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
5796 | |
5797 | OP_CPSF, /* CPS flags */ | |
5798 | OP_ENDI, /* Endianness specifier */ | |
5799 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
5800 | OP_COND, /* conditional code */ | |
92e90b6e | 5801 | OP_TB, /* Table branch. */ |
c19d1205 | 5802 | |
037e8744 JB |
5803 | OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */ |
5804 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ | |
5805 | ||
c19d1205 ZW |
5806 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
5807 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
5808 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
5809 | OP_RF_IF, /* FPA register or immediate */ | |
5810 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 5811 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
5812 | |
5813 | /* Optional operands. */ | |
5814 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
5815 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 5816 | OP_oI32b, /* 1 .. 32 */ |
c19d1205 ZW |
5817 | OP_oIffffb, /* 0 .. 65535 */ |
5818 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
5819 | ||
5820 | OP_oRR, /* ARM register */ | |
5821 | OP_oRRnpc, /* ARM register, not the PC */ | |
b6702015 | 5822 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
5823 | OP_oRND, /* Optional Neon double precision register */ |
5824 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5825 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 5826 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
5827 | OP_oSHll, /* LSL immediate */ |
5828 | OP_oSHar, /* ASR immediate */ | |
5829 | OP_oSHllar, /* LSL or ASR immediate */ | |
5830 | OP_oROR, /* ROR 0/8/16/24 */ | |
62b3e311 | 5831 | OP_oBARRIER, /* Option argument for a barrier instruction. */ |
c19d1205 ZW |
5832 | |
5833 | OP_FIRST_OPTIONAL = OP_oI7b | |
5834 | }; | |
a737bd4d | 5835 | |
c19d1205 ZW |
5836 | /* Generic instruction operand parser. This does no encoding and no |
5837 | semantic validation; it merely squirrels values away in the inst | |
5838 | structure. Returns SUCCESS or FAIL depending on whether the | |
5839 | specified grammar matched. */ | |
5840 | static int | |
ca3f61f7 | 5841 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
5842 | { |
5843 | unsigned const char *upat = pattern; | |
5844 | char *backtrack_pos = 0; | |
5845 | const char *backtrack_error = 0; | |
5846 | int i, val, backtrack_index = 0; | |
5287ad62 | 5847 | enum arm_reg_type rtype; |
4962c51a | 5848 | parse_operand_result result; |
c19d1205 | 5849 | |
e07e6e58 NC |
5850 | #define po_char_or_fail(chr) \ |
5851 | do \ | |
5852 | { \ | |
5853 | if (skip_past_char (&str, chr) == FAIL) \ | |
5854 | goto bad_args; \ | |
5855 | } \ | |
5856 | while (0) | |
c19d1205 | 5857 | |
e07e6e58 NC |
5858 | #define po_reg_or_fail(regtype) \ |
5859 | do \ | |
dcbf9037 | 5860 | { \ |
e07e6e58 NC |
5861 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
5862 | & inst.operands[i].vectype); \ | |
5863 | if (val == FAIL) \ | |
5864 | { \ | |
5865 | first_error (_(reg_expected_msgs[regtype])); \ | |
5866 | goto failure; \ | |
5867 | } \ | |
5868 | inst.operands[i].reg = val; \ | |
5869 | inst.operands[i].isreg = 1; \ | |
5870 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5871 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5872 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5873 | || rtype == REG_TYPE_VFD \ | |
5874 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 5875 | } \ |
e07e6e58 NC |
5876 | while (0) |
5877 | ||
5878 | #define po_reg_or_goto(regtype, label) \ | |
5879 | do \ | |
5880 | { \ | |
5881 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
5882 | & inst.operands[i].vectype); \ | |
5883 | if (val == FAIL) \ | |
5884 | goto label; \ | |
dcbf9037 | 5885 | \ |
e07e6e58 NC |
5886 | inst.operands[i].reg = val; \ |
5887 | inst.operands[i].isreg = 1; \ | |
5888 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5889 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5890 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5891 | || rtype == REG_TYPE_VFD \ | |
5892 | || rtype == REG_TYPE_NQ); \ | |
5893 | } \ | |
5894 | while (0) | |
5895 | ||
5896 | #define po_imm_or_fail(min, max, popt) \ | |
5897 | do \ | |
5898 | { \ | |
5899 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
5900 | goto failure; \ | |
5901 | inst.operands[i].imm = val; \ | |
5902 | } \ | |
5903 | while (0) | |
5904 | ||
5905 | #define po_scalar_or_goto(elsz, label) \ | |
5906 | do \ | |
5907 | { \ | |
5908 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
5909 | if (val == FAIL) \ | |
5910 | goto label; \ | |
5911 | inst.operands[i].reg = val; \ | |
5912 | inst.operands[i].isscalar = 1; \ | |
5913 | } \ | |
5914 | while (0) | |
5915 | ||
5916 | #define po_misc_or_fail(expr) \ | |
5917 | do \ | |
5918 | { \ | |
5919 | if (expr) \ | |
5920 | goto failure; \ | |
5921 | } \ | |
5922 | while (0) | |
5923 | ||
5924 | #define po_misc_or_fail_no_backtrack(expr) \ | |
5925 | do \ | |
5926 | { \ | |
5927 | result = expr; \ | |
5928 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
5929 | backtrack_pos = 0; \ | |
5930 | if (result != PARSE_OPERAND_SUCCESS) \ | |
5931 | goto failure; \ | |
5932 | } \ | |
5933 | while (0) | |
4962c51a | 5934 | |
c19d1205 ZW |
5935 | skip_whitespace (str); |
5936 | ||
5937 | for (i = 0; upat[i] != OP_stop; i++) | |
5938 | { | |
5939 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
5940 | { | |
5941 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 5942 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
5943 | backtrack_pos = str; |
5944 | backtrack_error = inst.error; | |
5945 | backtrack_index = i; | |
5946 | } | |
5947 | ||
b6702015 | 5948 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
5949 | po_char_or_fail (','); |
5950 | ||
5951 | switch (upat[i]) | |
5952 | { | |
5953 | /* Registers */ | |
5954 | case OP_oRRnpc: | |
5955 | case OP_RRnpc: | |
5956 | case OP_oRR: | |
5957 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
5958 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
5959 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
5960 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
5961 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
5962 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
5963 | case OP_oRND: |
5964 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
cd2cf30b PB |
5965 | case OP_RVC: |
5966 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
5967 | break; | |
5968 | /* Also accept generic coprocessor regs for unknown registers. */ | |
5969 | coproc_reg: | |
5970 | po_reg_or_fail (REG_TYPE_CN); | |
5971 | break; | |
c19d1205 ZW |
5972 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
5973 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
5974 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
5975 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
5976 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
5977 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
5978 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
5979 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
5980 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
5981 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
5982 | case OP_oRNQ: |
5983 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
5984 | case OP_oRNDQ: | |
5985 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
5986 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
5987 | case OP_oRNSDQ: | |
5988 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
5989 | |
5990 | /* Neon scalar. Using an element size of 8 means that some invalid | |
5991 | scalars are accepted here, so deal with those in later code. */ | |
5992 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
5993 | ||
5994 | /* WARNING: We can expand to two operands here. This has the potential | |
5995 | to totally confuse the backtracking mechanism! It will be OK at | |
5996 | least as long as we don't try to use optional args as well, | |
5997 | though. */ | |
5998 | case OP_NILO: | |
5999 | { | |
6000 | po_reg_or_goto (REG_TYPE_NDQ, try_imm); | |
466bbf93 | 6001 | inst.operands[i].present = 1; |
5287ad62 JB |
6002 | i++; |
6003 | skip_past_comma (&str); | |
6004 | po_reg_or_goto (REG_TYPE_NDQ, one_reg_only); | |
6005 | break; | |
6006 | one_reg_only: | |
6007 | /* Optional register operand was omitted. Unfortunately, it's in | |
6008 | operands[i-1] and we need it to be in inst.operands[i]. Fix that | |
6009 | here (this is a bit grotty). */ | |
6010 | inst.operands[i] = inst.operands[i-1]; | |
6011 | inst.operands[i-1].present = 0; | |
6012 | break; | |
6013 | try_imm: | |
036dc3f7 PB |
6014 | /* There's a possibility of getting a 64-bit immediate here, so |
6015 | we need special handling. */ | |
6016 | if (parse_big_immediate (&str, i) == FAIL) | |
6017 | { | |
6018 | inst.error = _("immediate value is out of range"); | |
6019 | goto failure; | |
6020 | } | |
5287ad62 JB |
6021 | } |
6022 | break; | |
6023 | ||
6024 | case OP_RNDQ_I0: | |
6025 | { | |
6026 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6027 | break; | |
6028 | try_imm0: | |
6029 | po_imm_or_fail (0, 0, TRUE); | |
6030 | } | |
6031 | break; | |
6032 | ||
037e8744 JB |
6033 | case OP_RVSD_I0: |
6034 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6035 | break; | |
6036 | ||
5287ad62 JB |
6037 | case OP_RR_RNSC: |
6038 | { | |
6039 | po_scalar_or_goto (8, try_rr); | |
6040 | break; | |
6041 | try_rr: | |
6042 | po_reg_or_fail (REG_TYPE_RN); | |
6043 | } | |
6044 | break; | |
6045 | ||
037e8744 JB |
6046 | case OP_RNSDQ_RNSC: |
6047 | { | |
6048 | po_scalar_or_goto (8, try_nsdq); | |
6049 | break; | |
6050 | try_nsdq: | |
6051 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6052 | } | |
6053 | break; | |
6054 | ||
5287ad62 JB |
6055 | case OP_RNDQ_RNSC: |
6056 | { | |
6057 | po_scalar_or_goto (8, try_ndq); | |
6058 | break; | |
6059 | try_ndq: | |
6060 | po_reg_or_fail (REG_TYPE_NDQ); | |
6061 | } | |
6062 | break; | |
6063 | ||
6064 | case OP_RND_RNSC: | |
6065 | { | |
6066 | po_scalar_or_goto (8, try_vfd); | |
6067 | break; | |
6068 | try_vfd: | |
6069 | po_reg_or_fail (REG_TYPE_VFD); | |
6070 | } | |
6071 | break; | |
6072 | ||
6073 | case OP_VMOV: | |
6074 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6075 | not careful then bad things might happen. */ | |
6076 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6077 | break; | |
6078 | ||
6079 | case OP_RNDQ_IMVNb: | |
6080 | { | |
6081 | po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm); | |
6082 | break; | |
6083 | try_mvnimm: | |
6084 | /* There's a possibility of getting a 64-bit immediate here, so | |
6085 | we need special handling. */ | |
6086 | if (parse_big_immediate (&str, i) == FAIL) | |
6087 | { | |
6088 | inst.error = _("immediate value is out of range"); | |
6089 | goto failure; | |
6090 | } | |
6091 | } | |
6092 | break; | |
6093 | ||
6094 | case OP_RNDQ_I63b: | |
6095 | { | |
6096 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6097 | break; | |
6098 | try_shimm: | |
6099 | po_imm_or_fail (0, 63, TRUE); | |
6100 | } | |
6101 | break; | |
c19d1205 ZW |
6102 | |
6103 | case OP_RRnpcb: | |
6104 | po_char_or_fail ('['); | |
6105 | po_reg_or_fail (REG_TYPE_RN); | |
6106 | po_char_or_fail (']'); | |
6107 | break; | |
a737bd4d | 6108 | |
c19d1205 | 6109 | case OP_RRw: |
b6702015 | 6110 | case OP_oRRw: |
c19d1205 ZW |
6111 | po_reg_or_fail (REG_TYPE_RN); |
6112 | if (skip_past_char (&str, '!') == SUCCESS) | |
6113 | inst.operands[i].writeback = 1; | |
6114 | break; | |
6115 | ||
6116 | /* Immediates */ | |
6117 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6118 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6119 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 6120 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6121 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6122 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 6123 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6124 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
6125 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6126 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6127 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6128 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6129 | |
6130 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6131 | case OP_oI7b: | |
6132 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6133 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6134 | case OP_oI31b: | |
6135 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 6136 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
c19d1205 ZW |
6137 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6138 | ||
6139 | /* Immediate variants */ | |
6140 | case OP_oI255c: | |
6141 | po_char_or_fail ('{'); | |
6142 | po_imm_or_fail (0, 255, TRUE); | |
6143 | po_char_or_fail ('}'); | |
6144 | break; | |
6145 | ||
6146 | case OP_I31w: | |
6147 | /* The expression parser chokes on a trailing !, so we have | |
6148 | to find it first and zap it. */ | |
6149 | { | |
6150 | char *s = str; | |
6151 | while (*s && *s != ',') | |
6152 | s++; | |
6153 | if (s[-1] == '!') | |
6154 | { | |
6155 | s[-1] = '\0'; | |
6156 | inst.operands[i].writeback = 1; | |
6157 | } | |
6158 | po_imm_or_fail (0, 31, TRUE); | |
6159 | if (str == s - 1) | |
6160 | str = s; | |
6161 | } | |
6162 | break; | |
6163 | ||
6164 | /* Expressions */ | |
6165 | case OP_EXPi: EXPi: | |
6166 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6167 | GE_OPT_PREFIX)); | |
6168 | break; | |
6169 | ||
6170 | case OP_EXP: | |
6171 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6172 | GE_NO_PREFIX)); | |
6173 | break; | |
6174 | ||
6175 | case OP_EXPr: EXPr: | |
6176 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6177 | GE_NO_PREFIX)); | |
6178 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6179 | { |
c19d1205 ZW |
6180 | val = parse_reloc (&str); |
6181 | if (val == -1) | |
6182 | { | |
6183 | inst.error = _("unrecognized relocation suffix"); | |
6184 | goto failure; | |
6185 | } | |
6186 | else if (val != BFD_RELOC_UNUSED) | |
6187 | { | |
6188 | inst.operands[i].imm = val; | |
6189 | inst.operands[i].hasreloc = 1; | |
6190 | } | |
a737bd4d | 6191 | } |
c19d1205 | 6192 | break; |
a737bd4d | 6193 | |
b6895b4f PB |
6194 | /* Operand for MOVW or MOVT. */ |
6195 | case OP_HALF: | |
6196 | po_misc_or_fail (parse_half (&str)); | |
6197 | break; | |
6198 | ||
e07e6e58 | 6199 | /* Register or expression. */ |
c19d1205 ZW |
6200 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6201 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6202 | |
e07e6e58 | 6203 | /* Register or immediate. */ |
c19d1205 ZW |
6204 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6205 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6206 | |
c19d1205 ZW |
6207 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6208 | IF: | |
6209 | if (!is_immediate_prefix (*str)) | |
6210 | goto bad_args; | |
6211 | str++; | |
6212 | val = parse_fpa_immediate (&str); | |
6213 | if (val == FAIL) | |
6214 | goto failure; | |
6215 | /* FPA immediates are encoded as registers 8-15. | |
6216 | parse_fpa_immediate has already applied the offset. */ | |
6217 | inst.operands[i].reg = val; | |
6218 | inst.operands[i].isreg = 1; | |
6219 | break; | |
09d92015 | 6220 | |
2d447fca JM |
6221 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6222 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6223 | ||
e07e6e58 | 6224 | /* Two kinds of register. */ |
c19d1205 ZW |
6225 | case OP_RIWR_RIWC: |
6226 | { | |
6227 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6228 | if (!rege |
6229 | || (rege->type != REG_TYPE_MMXWR | |
6230 | && rege->type != REG_TYPE_MMXWC | |
6231 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6232 | { |
6233 | inst.error = _("iWMMXt data or control register expected"); | |
6234 | goto failure; | |
6235 | } | |
6236 | inst.operands[i].reg = rege->number; | |
6237 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6238 | } | |
6239 | break; | |
09d92015 | 6240 | |
41adaa5c JM |
6241 | case OP_RIWC_RIWG: |
6242 | { | |
6243 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6244 | if (!rege | |
6245 | || (rege->type != REG_TYPE_MMXWC | |
6246 | && rege->type != REG_TYPE_MMXWCG)) | |
6247 | { | |
6248 | inst.error = _("iWMMXt control register expected"); | |
6249 | goto failure; | |
6250 | } | |
6251 | inst.operands[i].reg = rege->number; | |
6252 | inst.operands[i].isreg = 1; | |
6253 | } | |
6254 | break; | |
6255 | ||
c19d1205 ZW |
6256 | /* Misc */ |
6257 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6258 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6259 | case OP_oROR: val = parse_ror (&str); break; | |
6260 | case OP_PSR: val = parse_psr (&str); break; | |
6261 | case OP_COND: val = parse_cond (&str); break; | |
62b3e311 | 6262 | case OP_oBARRIER:val = parse_barrier (&str); break; |
c19d1205 | 6263 | |
037e8744 JB |
6264 | case OP_RVC_PSR: |
6265 | po_reg_or_goto (REG_TYPE_VFC, try_psr); | |
6266 | inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */ | |
6267 | break; | |
6268 | try_psr: | |
6269 | val = parse_psr (&str); | |
6270 | break; | |
6271 | ||
6272 | case OP_APSR_RR: | |
6273 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
6274 | break; | |
6275 | try_apsr: | |
6276 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
6277 | instruction). */ | |
6278 | if (strncasecmp (str, "APSR_", 5) == 0) | |
6279 | { | |
6280 | unsigned found = 0; | |
6281 | str += 5; | |
6282 | while (found < 15) | |
6283 | switch (*str++) | |
6284 | { | |
6285 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
6286 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
6287 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
6288 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
6289 | default: found = 16; | |
6290 | } | |
6291 | if (found != 15) | |
6292 | goto failure; | |
6293 | inst.operands[i].isvec = 1; | |
6294 | } | |
6295 | else | |
6296 | goto failure; | |
6297 | break; | |
6298 | ||
92e90b6e PB |
6299 | case OP_TB: |
6300 | po_misc_or_fail (parse_tb (&str)); | |
6301 | break; | |
6302 | ||
e07e6e58 | 6303 | /* Register lists. */ |
c19d1205 ZW |
6304 | case OP_REGLST: |
6305 | val = parse_reg_list (&str); | |
6306 | if (*str == '^') | |
6307 | { | |
6308 | inst.operands[1].writeback = 1; | |
6309 | str++; | |
6310 | } | |
6311 | break; | |
09d92015 | 6312 | |
c19d1205 | 6313 | case OP_VRSLST: |
5287ad62 | 6314 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 6315 | break; |
09d92015 | 6316 | |
c19d1205 | 6317 | case OP_VRDLST: |
5287ad62 | 6318 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 6319 | break; |
a737bd4d | 6320 | |
037e8744 JB |
6321 | case OP_VRSDLST: |
6322 | /* Allow Q registers too. */ | |
6323 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6324 | REGLIST_NEON_D); | |
6325 | if (val == FAIL) | |
6326 | { | |
6327 | inst.error = NULL; | |
6328 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6329 | REGLIST_VFP_S); | |
6330 | inst.operands[i].issingle = 1; | |
6331 | } | |
6332 | break; | |
6333 | ||
5287ad62 JB |
6334 | case OP_NRDLST: |
6335 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6336 | REGLIST_NEON_D); | |
6337 | break; | |
6338 | ||
6339 | case OP_NSTRLST: | |
dcbf9037 JB |
6340 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
6341 | &inst.operands[i].vectype); | |
5287ad62 JB |
6342 | break; |
6343 | ||
c19d1205 ZW |
6344 | /* Addressing modes */ |
6345 | case OP_ADDR: | |
6346 | po_misc_or_fail (parse_address (&str, i)); | |
6347 | break; | |
09d92015 | 6348 | |
4962c51a MS |
6349 | case OP_ADDRGLDR: |
6350 | po_misc_or_fail_no_backtrack ( | |
6351 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
6352 | break; | |
6353 | ||
6354 | case OP_ADDRGLDRS: | |
6355 | po_misc_or_fail_no_backtrack ( | |
6356 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
6357 | break; | |
6358 | ||
6359 | case OP_ADDRGLDC: | |
6360 | po_misc_or_fail_no_backtrack ( | |
6361 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
6362 | break; | |
6363 | ||
c19d1205 ZW |
6364 | case OP_SH: |
6365 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
6366 | break; | |
09d92015 | 6367 | |
4962c51a MS |
6368 | case OP_SHG: |
6369 | po_misc_or_fail_no_backtrack ( | |
6370 | parse_shifter_operand_group_reloc (&str, i)); | |
6371 | break; | |
6372 | ||
c19d1205 ZW |
6373 | case OP_oSHll: |
6374 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
6375 | break; | |
09d92015 | 6376 | |
c19d1205 ZW |
6377 | case OP_oSHar: |
6378 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
6379 | break; | |
09d92015 | 6380 | |
c19d1205 ZW |
6381 | case OP_oSHllar: |
6382 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
6383 | break; | |
09d92015 | 6384 | |
c19d1205 | 6385 | default: |
bd3ba5d1 | 6386 | as_fatal (_("unhandled operand code %d"), upat[i]); |
c19d1205 | 6387 | } |
09d92015 | 6388 | |
c19d1205 ZW |
6389 | /* Various value-based sanity checks and shared operations. We |
6390 | do not signal immediate failures for the register constraints; | |
6391 | this allows a syntax error to take precedence. */ | |
6392 | switch (upat[i]) | |
6393 | { | |
6394 | case OP_oRRnpc: | |
6395 | case OP_RRnpc: | |
6396 | case OP_RRnpcb: | |
6397 | case OP_RRw: | |
b6702015 | 6398 | case OP_oRRw: |
c19d1205 ZW |
6399 | case OP_RRnpc_I0: |
6400 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
6401 | inst.error = BAD_PC; | |
6402 | break; | |
09d92015 | 6403 | |
c19d1205 ZW |
6404 | case OP_CPSF: |
6405 | case OP_ENDI: | |
6406 | case OP_oROR: | |
6407 | case OP_PSR: | |
037e8744 | 6408 | case OP_RVC_PSR: |
c19d1205 | 6409 | case OP_COND: |
62b3e311 | 6410 | case OP_oBARRIER: |
c19d1205 ZW |
6411 | case OP_REGLST: |
6412 | case OP_VRSLST: | |
6413 | case OP_VRDLST: | |
037e8744 | 6414 | case OP_VRSDLST: |
5287ad62 JB |
6415 | case OP_NRDLST: |
6416 | case OP_NSTRLST: | |
c19d1205 ZW |
6417 | if (val == FAIL) |
6418 | goto failure; | |
6419 | inst.operands[i].imm = val; | |
6420 | break; | |
a737bd4d | 6421 | |
c19d1205 ZW |
6422 | default: |
6423 | break; | |
6424 | } | |
09d92015 | 6425 | |
c19d1205 ZW |
6426 | /* If we get here, this operand was successfully parsed. */ |
6427 | inst.operands[i].present = 1; | |
6428 | continue; | |
09d92015 | 6429 | |
c19d1205 | 6430 | bad_args: |
09d92015 | 6431 | inst.error = BAD_ARGS; |
c19d1205 ZW |
6432 | |
6433 | failure: | |
6434 | if (!backtrack_pos) | |
d252fdde PB |
6435 | { |
6436 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 6437 | default here just in case. */ |
d252fdde PB |
6438 | if (!inst.error) |
6439 | inst.error = _("syntax error"); | |
6440 | return FAIL; | |
6441 | } | |
c19d1205 ZW |
6442 | |
6443 | /* Do not backtrack over a trailing optional argument that | |
6444 | absorbed some text. We will only fail again, with the | |
6445 | 'garbage following instruction' error message, which is | |
6446 | probably less helpful than the current one. */ | |
6447 | if (backtrack_index == i && backtrack_pos != str | |
6448 | && upat[i+1] == OP_stop) | |
d252fdde PB |
6449 | { |
6450 | if (!inst.error) | |
6451 | inst.error = _("syntax error"); | |
6452 | return FAIL; | |
6453 | } | |
c19d1205 ZW |
6454 | |
6455 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
6456 | str = backtrack_pos; | |
6457 | inst.error = backtrack_error; | |
6458 | inst.operands[backtrack_index].present = 0; | |
6459 | i = backtrack_index; | |
6460 | backtrack_pos = 0; | |
09d92015 | 6461 | } |
09d92015 | 6462 | |
c19d1205 ZW |
6463 | /* Check that we have parsed all the arguments. */ |
6464 | if (*str != '\0' && !inst.error) | |
6465 | inst.error = _("garbage following instruction"); | |
09d92015 | 6466 | |
c19d1205 | 6467 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
6468 | } |
6469 | ||
c19d1205 ZW |
6470 | #undef po_char_or_fail |
6471 | #undef po_reg_or_fail | |
6472 | #undef po_reg_or_goto | |
6473 | #undef po_imm_or_fail | |
5287ad62 | 6474 | #undef po_scalar_or_fail |
e07e6e58 | 6475 | |
c19d1205 | 6476 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
6477 | #define constraint(expr, err) \ |
6478 | do \ | |
c19d1205 | 6479 | { \ |
e07e6e58 NC |
6480 | if (expr) \ |
6481 | { \ | |
6482 | inst.error = err; \ | |
6483 | return; \ | |
6484 | } \ | |
c19d1205 | 6485 | } \ |
e07e6e58 | 6486 | while (0) |
c19d1205 | 6487 | |
fdfde340 JM |
6488 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
6489 | instructions are unpredictable if these registers are used. This | |
6490 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
6491 | #define reject_bad_reg(reg) \ | |
6492 | do \ | |
6493 | if (reg == REG_SP || reg == REG_PC) \ | |
6494 | { \ | |
6495 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
6496 | return; \ | |
6497 | } \ | |
6498 | while (0) | |
6499 | ||
94206790 MM |
6500 | /* If REG is R13 (the stack pointer), warn that its use is |
6501 | deprecated. */ | |
6502 | #define warn_deprecated_sp(reg) \ | |
6503 | do \ | |
6504 | if (warn_on_deprecated && reg == REG_SP) \ | |
6505 | as_warn (_("use of r13 is deprecated")); \ | |
6506 | while (0) | |
6507 | ||
c19d1205 ZW |
6508 | /* Functions for operand encoding. ARM, then Thumb. */ |
6509 | ||
6510 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
6511 | ||
6512 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
6513 | return the encoded form. Otherwise, return FAIL. */ | |
6514 | ||
6515 | static unsigned int | |
6516 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6517 | { |
c19d1205 ZW |
6518 | unsigned int a, i; |
6519 | ||
6520 | for (i = 0; i < 32; i += 2) | |
6521 | if ((a = rotate_left (val, i)) <= 0xff) | |
6522 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6523 | ||
6524 | return FAIL; | |
09d92015 MM |
6525 | } |
6526 | ||
c19d1205 ZW |
6527 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6528 | return the encoded form. Otherwise, return FAIL. */ | |
6529 | static unsigned int | |
6530 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6531 | { |
c19d1205 | 6532 | unsigned int a, i; |
09d92015 | 6533 | |
9c3c69f2 | 6534 | if (val <= 0xff) |
c19d1205 | 6535 | return val; |
a737bd4d | 6536 | |
9c3c69f2 | 6537 | for (i = 1; i <= 24; i++) |
09d92015 | 6538 | { |
9c3c69f2 PB |
6539 | a = val >> i; |
6540 | if ((val & ~(0xff << i)) == 0) | |
6541 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6542 | } |
a737bd4d | 6543 | |
c19d1205 ZW |
6544 | a = val & 0xff; |
6545 | if (val == ((a << 16) | a)) | |
6546 | return 0x100 | a; | |
6547 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6548 | return 0x300 | a; | |
09d92015 | 6549 | |
c19d1205 ZW |
6550 | a = val & 0xff00; |
6551 | if (val == ((a << 16) | a)) | |
6552 | return 0x200 | (a >> 8); | |
a737bd4d | 6553 | |
c19d1205 | 6554 | return FAIL; |
09d92015 | 6555 | } |
5287ad62 | 6556 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6557 | |
6558 | static void | |
5287ad62 JB |
6559 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6560 | { | |
6561 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6562 | && reg > 15) | |
6563 | { | |
b1cc4aeb | 6564 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
5287ad62 JB |
6565 | { |
6566 | if (thumb_mode) | |
6567 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 6568 | fpu_vfp_ext_d32); |
5287ad62 JB |
6569 | else |
6570 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 6571 | fpu_vfp_ext_d32); |
5287ad62 JB |
6572 | } |
6573 | else | |
6574 | { | |
dcbf9037 | 6575 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
6576 | return; |
6577 | } | |
6578 | } | |
6579 | ||
c19d1205 | 6580 | switch (pos) |
09d92015 | 6581 | { |
c19d1205 ZW |
6582 | case VFP_REG_Sd: |
6583 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
6584 | break; | |
6585 | ||
6586 | case VFP_REG_Sn: | |
6587 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
6588 | break; | |
6589 | ||
6590 | case VFP_REG_Sm: | |
6591 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
6592 | break; | |
6593 | ||
5287ad62 JB |
6594 | case VFP_REG_Dd: |
6595 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
6596 | break; | |
5f4273c7 | 6597 | |
5287ad62 JB |
6598 | case VFP_REG_Dn: |
6599 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
6600 | break; | |
5f4273c7 | 6601 | |
5287ad62 JB |
6602 | case VFP_REG_Dm: |
6603 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
6604 | break; | |
6605 | ||
c19d1205 ZW |
6606 | default: |
6607 | abort (); | |
09d92015 | 6608 | } |
09d92015 MM |
6609 | } |
6610 | ||
c19d1205 | 6611 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 6612 | if any, is handled by md_apply_fix. */ |
09d92015 | 6613 | static void |
c19d1205 | 6614 | encode_arm_shift (int i) |
09d92015 | 6615 | { |
c19d1205 ZW |
6616 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
6617 | inst.instruction |= SHIFT_ROR << 5; | |
6618 | else | |
09d92015 | 6619 | { |
c19d1205 ZW |
6620 | inst.instruction |= inst.operands[i].shift_kind << 5; |
6621 | if (inst.operands[i].immisreg) | |
6622 | { | |
6623 | inst.instruction |= SHIFT_BY_REG; | |
6624 | inst.instruction |= inst.operands[i].imm << 8; | |
6625 | } | |
6626 | else | |
6627 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 6628 | } |
c19d1205 | 6629 | } |
09d92015 | 6630 | |
c19d1205 ZW |
6631 | static void |
6632 | encode_arm_shifter_operand (int i) | |
6633 | { | |
6634 | if (inst.operands[i].isreg) | |
09d92015 | 6635 | { |
c19d1205 ZW |
6636 | inst.instruction |= inst.operands[i].reg; |
6637 | encode_arm_shift (i); | |
09d92015 | 6638 | } |
c19d1205 ZW |
6639 | else |
6640 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
6641 | } |
6642 | ||
c19d1205 | 6643 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 6644 | static void |
c19d1205 | 6645 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 6646 | { |
9c2799c2 | 6647 | gas_assert (inst.operands[i].isreg); |
c19d1205 | 6648 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6649 | |
c19d1205 | 6650 | if (inst.operands[i].preind) |
09d92015 | 6651 | { |
c19d1205 ZW |
6652 | if (is_t) |
6653 | { | |
6654 | inst.error = _("instruction does not accept preindexed addressing"); | |
6655 | return; | |
6656 | } | |
6657 | inst.instruction |= PRE_INDEX; | |
6658 | if (inst.operands[i].writeback) | |
6659 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6660 | |
c19d1205 ZW |
6661 | } |
6662 | else if (inst.operands[i].postind) | |
6663 | { | |
9c2799c2 | 6664 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
6665 | if (is_t) |
6666 | inst.instruction |= WRITE_BACK; | |
6667 | } | |
6668 | else /* unindexed - only for coprocessor */ | |
09d92015 | 6669 | { |
c19d1205 | 6670 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
6671 | return; |
6672 | } | |
6673 | ||
c19d1205 ZW |
6674 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
6675 | && (((inst.instruction & 0x000f0000) >> 16) | |
6676 | == ((inst.instruction & 0x0000f000) >> 12))) | |
6677 | as_warn ((inst.instruction & LOAD_BIT) | |
6678 | ? _("destination register same as write-back base") | |
6679 | : _("source register same as write-back base")); | |
09d92015 MM |
6680 | } |
6681 | ||
c19d1205 ZW |
6682 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6683 | ARM-format mode 2 load or store instruction. If is_t is true, | |
6684 | reject forms that cannot be used with a T instruction (i.e. not | |
6685 | post-indexed). */ | |
a737bd4d | 6686 | static void |
c19d1205 | 6687 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 6688 | { |
c19d1205 | 6689 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6690 | |
c19d1205 | 6691 | if (inst.operands[i].immisreg) |
09d92015 | 6692 | { |
c19d1205 ZW |
6693 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
6694 | inst.instruction |= inst.operands[i].imm; | |
6695 | if (!inst.operands[i].negative) | |
6696 | inst.instruction |= INDEX_UP; | |
6697 | if (inst.operands[i].shifted) | |
6698 | { | |
6699 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
6700 | inst.instruction |= SHIFT_ROR << 5; | |
6701 | else | |
6702 | { | |
6703 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
6704 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
6705 | } | |
6706 | } | |
09d92015 | 6707 | } |
c19d1205 | 6708 | else /* immediate offset in inst.reloc */ |
09d92015 | 6709 | { |
c19d1205 ZW |
6710 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6711 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 6712 | } |
09d92015 MM |
6713 | } |
6714 | ||
c19d1205 ZW |
6715 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6716 | ARM-format mode 3 load or store instruction. Reject forms that | |
6717 | cannot be used with such instructions. If is_t is true, reject | |
6718 | forms that cannot be used with a T instruction (i.e. not | |
6719 | post-indexed). */ | |
6720 | static void | |
6721 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 6722 | { |
c19d1205 | 6723 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 6724 | { |
c19d1205 ZW |
6725 | inst.error = _("instruction does not accept scaled register index"); |
6726 | return; | |
09d92015 | 6727 | } |
a737bd4d | 6728 | |
c19d1205 | 6729 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6730 | |
c19d1205 ZW |
6731 | if (inst.operands[i].immisreg) |
6732 | { | |
6733 | inst.instruction |= inst.operands[i].imm; | |
6734 | if (!inst.operands[i].negative) | |
6735 | inst.instruction |= INDEX_UP; | |
6736 | } | |
6737 | else /* immediate offset in inst.reloc */ | |
6738 | { | |
6739 | inst.instruction |= HWOFFSET_IMM; | |
6740 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6741 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 6742 | } |
a737bd4d NC |
6743 | } |
6744 | ||
c19d1205 ZW |
6745 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6746 | ARM-format instruction. Reject all forms which cannot be encoded | |
6747 | into a coprocessor load/store instruction. If wb_ok is false, | |
6748 | reject use of writeback; if unind_ok is false, reject use of | |
6749 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
6750 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
6751 | (in which case it is preserved). */ | |
09d92015 | 6752 | |
c19d1205 ZW |
6753 | static int |
6754 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 6755 | { |
c19d1205 | 6756 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6757 | |
9c2799c2 | 6758 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 6759 | |
c19d1205 | 6760 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 6761 | { |
9c2799c2 | 6762 | gas_assert (!inst.operands[i].writeback); |
c19d1205 ZW |
6763 | if (!unind_ok) |
6764 | { | |
6765 | inst.error = _("instruction does not support unindexed addressing"); | |
6766 | return FAIL; | |
6767 | } | |
6768 | inst.instruction |= inst.operands[i].imm; | |
6769 | inst.instruction |= INDEX_UP; | |
6770 | return SUCCESS; | |
09d92015 | 6771 | } |
a737bd4d | 6772 | |
c19d1205 ZW |
6773 | if (inst.operands[i].preind) |
6774 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 6775 | |
c19d1205 | 6776 | if (inst.operands[i].writeback) |
09d92015 | 6777 | { |
c19d1205 ZW |
6778 | if (inst.operands[i].reg == REG_PC) |
6779 | { | |
6780 | inst.error = _("pc may not be used with write-back"); | |
6781 | return FAIL; | |
6782 | } | |
6783 | if (!wb_ok) | |
6784 | { | |
6785 | inst.error = _("instruction does not support writeback"); | |
6786 | return FAIL; | |
6787 | } | |
6788 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6789 | } |
a737bd4d | 6790 | |
c19d1205 ZW |
6791 | if (reloc_override) |
6792 | inst.reloc.type = reloc_override; | |
4962c51a MS |
6793 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
6794 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
6795 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
6796 | { | |
6797 | if (thumb_mode) | |
6798 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
6799 | else | |
6800 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
6801 | } | |
6802 | ||
c19d1205 ZW |
6803 | return SUCCESS; |
6804 | } | |
a737bd4d | 6805 | |
c19d1205 ZW |
6806 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
6807 | Determine whether it can be performed with a move instruction; if | |
6808 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
6809 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
6810 | load and return FALSE. If this is not a valid thing to do in the | |
6811 | current context, set inst.error and return TRUE. | |
a737bd4d | 6812 | |
c19d1205 ZW |
6813 | inst.operands[i] describes the destination register. */ |
6814 | ||
c921be7d | 6815 | static bfd_boolean |
c19d1205 ZW |
6816 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) |
6817 | { | |
53365c0d PB |
6818 | unsigned long tbit; |
6819 | ||
6820 | if (thumb_p) | |
6821 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
6822 | else | |
6823 | tbit = LOAD_BIT; | |
6824 | ||
6825 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 6826 | { |
c19d1205 | 6827 | inst.error = _("invalid pseudo operation"); |
c921be7d | 6828 | return TRUE; |
09d92015 | 6829 | } |
c19d1205 | 6830 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
6831 | { |
6832 | inst.error = _("constant expression expected"); | |
c921be7d | 6833 | return TRUE; |
09d92015 | 6834 | } |
c19d1205 | 6835 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 6836 | { |
c19d1205 ZW |
6837 | if (thumb_p) |
6838 | { | |
53365c0d | 6839 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
6840 | { |
6841 | /* This can be done with a mov(1) instruction. */ | |
6842 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
6843 | inst.instruction |= inst.reloc.exp.X_add_number; | |
c921be7d | 6844 | return TRUE; |
c19d1205 ZW |
6845 | } |
6846 | } | |
6847 | else | |
6848 | { | |
6849 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
6850 | if (value != FAIL) | |
6851 | { | |
6852 | /* This can be done with a mov instruction. */ | |
6853 | inst.instruction &= LITERAL_MASK; | |
6854 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
6855 | inst.instruction |= value & 0xfff; | |
c921be7d | 6856 | return TRUE; |
c19d1205 | 6857 | } |
09d92015 | 6858 | |
c19d1205 ZW |
6859 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
6860 | if (value != FAIL) | |
6861 | { | |
6862 | /* This can be done with a mvn instruction. */ | |
6863 | inst.instruction &= LITERAL_MASK; | |
6864 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
6865 | inst.instruction |= value & 0xfff; | |
c921be7d | 6866 | return TRUE; |
c19d1205 ZW |
6867 | } |
6868 | } | |
09d92015 MM |
6869 | } |
6870 | ||
c19d1205 ZW |
6871 | if (add_to_lit_pool () == FAIL) |
6872 | { | |
6873 | inst.error = _("literal pool insertion failed"); | |
c921be7d | 6874 | return TRUE; |
c19d1205 ZW |
6875 | } |
6876 | inst.operands[1].reg = REG_PC; | |
6877 | inst.operands[1].isreg = 1; | |
6878 | inst.operands[1].preind = 1; | |
6879 | inst.reloc.pc_rel = 1; | |
6880 | inst.reloc.type = (thumb_p | |
6881 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
6882 | : (mode_3 | |
6883 | ? BFD_RELOC_ARM_HWLITERAL | |
6884 | : BFD_RELOC_ARM_LITERAL)); | |
c921be7d | 6885 | return FALSE; |
09d92015 MM |
6886 | } |
6887 | ||
5f4273c7 | 6888 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
6889 | First some generics; their names are taken from the conventional |
6890 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 6891 | |
a737bd4d | 6892 | static void |
c19d1205 | 6893 | do_noargs (void) |
09d92015 | 6894 | { |
c19d1205 | 6895 | } |
a737bd4d | 6896 | |
c19d1205 ZW |
6897 | static void |
6898 | do_rd (void) | |
6899 | { | |
6900 | inst.instruction |= inst.operands[0].reg << 12; | |
6901 | } | |
a737bd4d | 6902 | |
c19d1205 ZW |
6903 | static void |
6904 | do_rd_rm (void) | |
6905 | { | |
6906 | inst.instruction |= inst.operands[0].reg << 12; | |
6907 | inst.instruction |= inst.operands[1].reg; | |
6908 | } | |
09d92015 | 6909 | |
c19d1205 ZW |
6910 | static void |
6911 | do_rd_rn (void) | |
6912 | { | |
6913 | inst.instruction |= inst.operands[0].reg << 12; | |
6914 | inst.instruction |= inst.operands[1].reg << 16; | |
6915 | } | |
a737bd4d | 6916 | |
c19d1205 ZW |
6917 | static void |
6918 | do_rn_rd (void) | |
6919 | { | |
6920 | inst.instruction |= inst.operands[0].reg << 16; | |
6921 | inst.instruction |= inst.operands[1].reg << 12; | |
6922 | } | |
09d92015 | 6923 | |
c19d1205 ZW |
6924 | static void |
6925 | do_rd_rm_rn (void) | |
6926 | { | |
9a64e435 | 6927 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 6928 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 PB |
6929 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
6930 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
6931 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
6932 | inst.instruction |= inst.operands[0].reg << 12; |
6933 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 6934 | inst.instruction |= Rn << 16; |
c19d1205 | 6935 | } |
09d92015 | 6936 | |
c19d1205 ZW |
6937 | static void |
6938 | do_rd_rn_rm (void) | |
6939 | { | |
6940 | inst.instruction |= inst.operands[0].reg << 12; | |
6941 | inst.instruction |= inst.operands[1].reg << 16; | |
6942 | inst.instruction |= inst.operands[2].reg; | |
6943 | } | |
a737bd4d | 6944 | |
c19d1205 ZW |
6945 | static void |
6946 | do_rm_rd_rn (void) | |
6947 | { | |
6948 | inst.instruction |= inst.operands[0].reg; | |
6949 | inst.instruction |= inst.operands[1].reg << 12; | |
6950 | inst.instruction |= inst.operands[2].reg << 16; | |
6951 | } | |
09d92015 | 6952 | |
c19d1205 ZW |
6953 | static void |
6954 | do_imm0 (void) | |
6955 | { | |
6956 | inst.instruction |= inst.operands[0].imm; | |
6957 | } | |
09d92015 | 6958 | |
c19d1205 ZW |
6959 | static void |
6960 | do_rd_cpaddr (void) | |
6961 | { | |
6962 | inst.instruction |= inst.operands[0].reg << 12; | |
6963 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 6964 | } |
a737bd4d | 6965 | |
c19d1205 ZW |
6966 | /* ARM instructions, in alphabetical order by function name (except |
6967 | that wrapper functions appear immediately after the function they | |
6968 | wrap). */ | |
09d92015 | 6969 | |
c19d1205 ZW |
6970 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
6971 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
6972 | |
6973 | static void | |
c19d1205 | 6974 | do_adr (void) |
09d92015 | 6975 | { |
c19d1205 | 6976 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 6977 | |
c19d1205 ZW |
6978 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6979 | out to be negative. */ | |
6980 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 6981 | inst.reloc.pc_rel = 1; |
2fc8bdac | 6982 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 6983 | } |
b99bd4ef | 6984 | |
c19d1205 ZW |
6985 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
6986 | into a relative address of the form: | |
6987 | add rd, pc, #low(label-.-8)" | |
6988 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 6989 | |
c19d1205 ZW |
6990 | static void |
6991 | do_adrl (void) | |
6992 | { | |
6993 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 6994 | |
c19d1205 ZW |
6995 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6996 | out to be negative. */ | |
6997 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
6998 | inst.reloc.pc_rel = 1; |
6999 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 7000 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
7001 | } |
7002 | ||
b99bd4ef | 7003 | static void |
c19d1205 | 7004 | do_arit (void) |
b99bd4ef | 7005 | { |
c19d1205 ZW |
7006 | if (!inst.operands[1].present) |
7007 | inst.operands[1].reg = inst.operands[0].reg; | |
7008 | inst.instruction |= inst.operands[0].reg << 12; | |
7009 | inst.instruction |= inst.operands[1].reg << 16; | |
7010 | encode_arm_shifter_operand (2); | |
7011 | } | |
b99bd4ef | 7012 | |
62b3e311 PB |
7013 | static void |
7014 | do_barrier (void) | |
7015 | { | |
7016 | if (inst.operands[0].present) | |
7017 | { | |
7018 | constraint ((inst.instruction & 0xf0) != 0x40 | |
7019 | && inst.operands[0].imm != 0xf, | |
bd3ba5d1 | 7020 | _("bad barrier type")); |
62b3e311 PB |
7021 | inst.instruction |= inst.operands[0].imm; |
7022 | } | |
7023 | else | |
7024 | inst.instruction |= 0xf; | |
7025 | } | |
7026 | ||
c19d1205 ZW |
7027 | static void |
7028 | do_bfc (void) | |
7029 | { | |
7030 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
7031 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7032 | /* The instruction encoding stores the LSB and MSB, | |
7033 | not the LSB and width. */ | |
7034 | inst.instruction |= inst.operands[0].reg << 12; | |
7035 | inst.instruction |= inst.operands[1].imm << 7; | |
7036 | inst.instruction |= (msb - 1) << 16; | |
7037 | } | |
b99bd4ef | 7038 | |
c19d1205 ZW |
7039 | static void |
7040 | do_bfi (void) | |
7041 | { | |
7042 | unsigned int msb; | |
b99bd4ef | 7043 | |
c19d1205 ZW |
7044 | /* #0 in second position is alternative syntax for bfc, which is |
7045 | the same instruction but with REG_PC in the Rm field. */ | |
7046 | if (!inst.operands[1].isreg) | |
7047 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 7048 | |
c19d1205 ZW |
7049 | msb = inst.operands[2].imm + inst.operands[3].imm; |
7050 | constraint (msb > 32, _("bit-field extends past end of register")); | |
7051 | /* The instruction encoding stores the LSB and MSB, | |
7052 | not the LSB and width. */ | |
7053 | inst.instruction |= inst.operands[0].reg << 12; | |
7054 | inst.instruction |= inst.operands[1].reg; | |
7055 | inst.instruction |= inst.operands[2].imm << 7; | |
7056 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
7057 | } |
7058 | ||
b99bd4ef | 7059 | static void |
c19d1205 | 7060 | do_bfx (void) |
b99bd4ef | 7061 | { |
c19d1205 ZW |
7062 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
7063 | _("bit-field extends past end of register")); | |
7064 | inst.instruction |= inst.operands[0].reg << 12; | |
7065 | inst.instruction |= inst.operands[1].reg; | |
7066 | inst.instruction |= inst.operands[2].imm << 7; | |
7067 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
7068 | } | |
09d92015 | 7069 | |
c19d1205 ZW |
7070 | /* ARM V5 breakpoint instruction (argument parse) |
7071 | BKPT <16 bit unsigned immediate> | |
7072 | Instruction is not conditional. | |
7073 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
7074 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 7075 | |
c19d1205 ZW |
7076 | static void |
7077 | do_bkpt (void) | |
7078 | { | |
7079 | /* Top 12 of 16 bits to bits 19:8. */ | |
7080 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 7081 | |
c19d1205 ZW |
7082 | /* Bottom 4 of 16 bits to bits 3:0. */ |
7083 | inst.instruction |= inst.operands[0].imm & 0xf; | |
7084 | } | |
09d92015 | 7085 | |
c19d1205 ZW |
7086 | static void |
7087 | encode_branch (int default_reloc) | |
7088 | { | |
7089 | if (inst.operands[0].hasreloc) | |
7090 | { | |
7091 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
7092 | _("the only suffix valid here is '(plt)'")); | |
267bf995 | 7093 | inst.reloc.type = BFD_RELOC_ARM_PLT32; |
c19d1205 | 7094 | } |
b99bd4ef | 7095 | else |
c19d1205 ZW |
7096 | { |
7097 | inst.reloc.type = default_reloc; | |
c19d1205 | 7098 | } |
2fc8bdac | 7099 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
7100 | } |
7101 | ||
b99bd4ef | 7102 | static void |
c19d1205 | 7103 | do_branch (void) |
b99bd4ef | 7104 | { |
39b41c9c PB |
7105 | #ifdef OBJ_ELF |
7106 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7107 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7108 | else | |
7109 | #endif | |
7110 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
7111 | } | |
7112 | ||
7113 | static void | |
7114 | do_bl (void) | |
7115 | { | |
7116 | #ifdef OBJ_ELF | |
7117 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7118 | { | |
7119 | if (inst.cond == COND_ALWAYS) | |
7120 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
7121 | else | |
7122 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7123 | } | |
7124 | else | |
7125 | #endif | |
7126 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 7127 | } |
b99bd4ef | 7128 | |
c19d1205 ZW |
7129 | /* ARM V5 branch-link-exchange instruction (argument parse) |
7130 | BLX <target_addr> ie BLX(1) | |
7131 | BLX{<condition>} <Rm> ie BLX(2) | |
7132 | Unfortunately, there are two different opcodes for this mnemonic. | |
7133 | So, the insns[].value is not used, and the code here zaps values | |
7134 | into inst.instruction. | |
7135 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 7136 | |
c19d1205 ZW |
7137 | static void |
7138 | do_blx (void) | |
7139 | { | |
7140 | if (inst.operands[0].isreg) | |
b99bd4ef | 7141 | { |
c19d1205 ZW |
7142 | /* Arg is a register; the opcode provided by insns[] is correct. |
7143 | It is not illegal to do "blx pc", just useless. */ | |
7144 | if (inst.operands[0].reg == REG_PC) | |
7145 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 7146 | |
c19d1205 ZW |
7147 | inst.instruction |= inst.operands[0].reg; |
7148 | } | |
7149 | else | |
b99bd4ef | 7150 | { |
c19d1205 | 7151 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
7152 | conditionally, and the opcode must be adjusted. |
7153 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
7154 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 7155 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 7156 | inst.instruction = 0xfa000000; |
267bf995 | 7157 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 7158 | } |
c19d1205 ZW |
7159 | } |
7160 | ||
7161 | static void | |
7162 | do_bx (void) | |
7163 | { | |
845b51d6 PB |
7164 | bfd_boolean want_reloc; |
7165 | ||
c19d1205 ZW |
7166 | if (inst.operands[0].reg == REG_PC) |
7167 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 7168 | |
c19d1205 | 7169 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
7170 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
7171 | it is for ARMv4t or earlier. */ | |
7172 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
7173 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
7174 | want_reloc = TRUE; | |
7175 | ||
5ad34203 | 7176 | #ifdef OBJ_ELF |
845b51d6 | 7177 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 7178 | #endif |
584206db | 7179 | want_reloc = FALSE; |
845b51d6 PB |
7180 | |
7181 | if (want_reloc) | |
7182 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
7183 | } |
7184 | ||
c19d1205 ZW |
7185 | |
7186 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
7187 | |
7188 | static void | |
c19d1205 | 7189 | do_bxj (void) |
a737bd4d | 7190 | { |
c19d1205 ZW |
7191 | if (inst.operands[0].reg == REG_PC) |
7192 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
7193 | ||
7194 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
7195 | } |
7196 | ||
c19d1205 ZW |
7197 | /* Co-processor data operation: |
7198 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
7199 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
7200 | static void | |
7201 | do_cdp (void) | |
7202 | { | |
7203 | inst.instruction |= inst.operands[0].reg << 8; | |
7204 | inst.instruction |= inst.operands[1].imm << 20; | |
7205 | inst.instruction |= inst.operands[2].reg << 12; | |
7206 | inst.instruction |= inst.operands[3].reg << 16; | |
7207 | inst.instruction |= inst.operands[4].reg; | |
7208 | inst.instruction |= inst.operands[5].imm << 5; | |
7209 | } | |
a737bd4d NC |
7210 | |
7211 | static void | |
c19d1205 | 7212 | do_cmp (void) |
a737bd4d | 7213 | { |
c19d1205 ZW |
7214 | inst.instruction |= inst.operands[0].reg << 16; |
7215 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
7216 | } |
7217 | ||
c19d1205 ZW |
7218 | /* Transfer between coprocessor and ARM registers. |
7219 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
7220 | MRC2 | |
7221 | MCR{cond} | |
7222 | MCR2 | |
7223 | ||
7224 | No special properties. */ | |
09d92015 MM |
7225 | |
7226 | static void | |
c19d1205 | 7227 | do_co_reg (void) |
09d92015 | 7228 | { |
fdfde340 JM |
7229 | unsigned Rd; |
7230 | ||
7231 | Rd = inst.operands[2].reg; | |
7232 | if (thumb_mode) | |
7233 | { | |
7234 | if (inst.instruction == 0xee000010 | |
7235 | || inst.instruction == 0xfe000010) | |
7236 | /* MCR, MCR2 */ | |
7237 | reject_bad_reg (Rd); | |
7238 | else | |
7239 | /* MRC, MRC2 */ | |
7240 | constraint (Rd == REG_SP, BAD_SP); | |
7241 | } | |
7242 | else | |
7243 | { | |
7244 | /* MCR */ | |
7245 | if (inst.instruction == 0xe000010) | |
7246 | constraint (Rd == REG_PC, BAD_PC); | |
7247 | } | |
7248 | ||
7249 | ||
c19d1205 ZW |
7250 | inst.instruction |= inst.operands[0].reg << 8; |
7251 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 7252 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
7253 | inst.instruction |= inst.operands[3].reg << 16; |
7254 | inst.instruction |= inst.operands[4].reg; | |
7255 | inst.instruction |= inst.operands[5].imm << 5; | |
7256 | } | |
09d92015 | 7257 | |
c19d1205 ZW |
7258 | /* Transfer between coprocessor register and pair of ARM registers. |
7259 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
7260 | MCRR2 | |
7261 | MRRC{cond} | |
7262 | MRRC2 | |
b99bd4ef | 7263 | |
c19d1205 | 7264 | Two XScale instructions are special cases of these: |
09d92015 | 7265 | |
c19d1205 ZW |
7266 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
7267 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 7268 | |
5f4273c7 | 7269 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 7270 | |
c19d1205 ZW |
7271 | static void |
7272 | do_co_reg2c (void) | |
7273 | { | |
fdfde340 JM |
7274 | unsigned Rd, Rn; |
7275 | ||
7276 | Rd = inst.operands[2].reg; | |
7277 | Rn = inst.operands[3].reg; | |
7278 | ||
7279 | if (thumb_mode) | |
7280 | { | |
7281 | reject_bad_reg (Rd); | |
7282 | reject_bad_reg (Rn); | |
7283 | } | |
7284 | else | |
7285 | { | |
7286 | constraint (Rd == REG_PC, BAD_PC); | |
7287 | constraint (Rn == REG_PC, BAD_PC); | |
7288 | } | |
7289 | ||
c19d1205 ZW |
7290 | inst.instruction |= inst.operands[0].reg << 8; |
7291 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
7292 | inst.instruction |= Rd << 12; |
7293 | inst.instruction |= Rn << 16; | |
c19d1205 | 7294 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
7295 | } |
7296 | ||
c19d1205 ZW |
7297 | static void |
7298 | do_cpsi (void) | |
7299 | { | |
7300 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
7301 | if (inst.operands[1].present) |
7302 | { | |
7303 | inst.instruction |= CPSI_MMOD; | |
7304 | inst.instruction |= inst.operands[1].imm; | |
7305 | } | |
c19d1205 | 7306 | } |
b99bd4ef | 7307 | |
62b3e311 PB |
7308 | static void |
7309 | do_dbg (void) | |
7310 | { | |
7311 | inst.instruction |= inst.operands[0].imm; | |
7312 | } | |
7313 | ||
b99bd4ef | 7314 | static void |
c19d1205 | 7315 | do_it (void) |
b99bd4ef | 7316 | { |
c19d1205 | 7317 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
7318 | process it to do the validation as if in |
7319 | thumb mode, just in case the code gets | |
7320 | assembled for thumb using the unified syntax. */ | |
7321 | ||
c19d1205 | 7322 | inst.size = 0; |
e07e6e58 NC |
7323 | if (unified_syntax) |
7324 | { | |
7325 | set_it_insn_type (IT_INSN); | |
7326 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
7327 | now_it.cc = inst.operands[0].imm; | |
7328 | } | |
09d92015 | 7329 | } |
b99bd4ef | 7330 | |
09d92015 | 7331 | static void |
c19d1205 | 7332 | do_ldmstm (void) |
ea6ef066 | 7333 | { |
c19d1205 ZW |
7334 | int base_reg = inst.operands[0].reg; |
7335 | int range = inst.operands[1].imm; | |
ea6ef066 | 7336 | |
c19d1205 ZW |
7337 | inst.instruction |= base_reg << 16; |
7338 | inst.instruction |= range; | |
ea6ef066 | 7339 | |
c19d1205 ZW |
7340 | if (inst.operands[1].writeback) |
7341 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 7342 | |
c19d1205 | 7343 | if (inst.operands[0].writeback) |
ea6ef066 | 7344 | { |
c19d1205 ZW |
7345 | inst.instruction |= WRITE_BACK; |
7346 | /* Check for unpredictable uses of writeback. */ | |
7347 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 7348 | { |
c19d1205 ZW |
7349 | /* Not allowed in LDM type 2. */ |
7350 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
7351 | && ((range & (1 << REG_PC)) == 0)) | |
7352 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7353 | /* Only allowed if base reg not in list for other types. */ | |
7354 | else if (range & (1 << base_reg)) | |
7355 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
7356 | } | |
7357 | else /* STM. */ | |
7358 | { | |
7359 | /* Not allowed for type 2. */ | |
7360 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
7361 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7362 | /* Only allowed if base reg not in list, or first in list. */ | |
7363 | else if ((range & (1 << base_reg)) | |
7364 | && (range & ((1 << base_reg) - 1))) | |
7365 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 7366 | } |
ea6ef066 | 7367 | } |
a737bd4d NC |
7368 | } |
7369 | ||
c19d1205 ZW |
7370 | /* ARMv5TE load-consecutive (argument parse) |
7371 | Mode is like LDRH. | |
7372 | ||
7373 | LDRccD R, mode | |
7374 | STRccD R, mode. */ | |
7375 | ||
a737bd4d | 7376 | static void |
c19d1205 | 7377 | do_ldrd (void) |
a737bd4d | 7378 | { |
c19d1205 ZW |
7379 | constraint (inst.operands[0].reg % 2 != 0, |
7380 | _("first destination register must be even")); | |
7381 | constraint (inst.operands[1].present | |
7382 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7383 | _("can only load two consecutive registers")); | |
7384 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
7385 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 7386 | |
c19d1205 ZW |
7387 | if (!inst.operands[1].present) |
7388 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 7389 | |
c19d1205 | 7390 | if (inst.instruction & LOAD_BIT) |
a737bd4d | 7391 | { |
c19d1205 ZW |
7392 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
7393 | register and the first register written; we have to diagnose | |
7394 | overlap between the base and the second register written here. */ | |
ea6ef066 | 7395 | |
c19d1205 ZW |
7396 | if (inst.operands[2].reg == inst.operands[1].reg |
7397 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
7398 | as_warn (_("base register written back, and overlaps " | |
7399 | "second destination register")); | |
b05fe5cf | 7400 | |
c19d1205 ZW |
7401 | /* For an index-register load, the index register must not overlap the |
7402 | destination (even if not write-back). */ | |
7403 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
7404 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
7405 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 7406 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 7407 | } |
c19d1205 ZW |
7408 | |
7409 | inst.instruction |= inst.operands[0].reg << 12; | |
7410 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
7411 | } |
7412 | ||
7413 | static void | |
c19d1205 | 7414 | do_ldrex (void) |
b05fe5cf | 7415 | { |
c19d1205 ZW |
7416 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
7417 | || inst.operands[1].postind || inst.operands[1].writeback | |
7418 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
7419 | || inst.operands[1].negative |
7420 | /* This can arise if the programmer has written | |
7421 | strex rN, rM, foo | |
7422 | or if they have mistakenly used a register name as the last | |
7423 | operand, eg: | |
7424 | strex rN, rM, rX | |
7425 | It is very difficult to distinguish between these two cases | |
7426 | because "rX" might actually be a label. ie the register | |
7427 | name has been occluded by a symbol of the same name. So we | |
7428 | just generate a general 'bad addressing mode' type error | |
7429 | message and leave it up to the programmer to discover the | |
7430 | true cause and fix their mistake. */ | |
7431 | || (inst.operands[1].reg == REG_PC), | |
7432 | BAD_ADDR_MODE); | |
b05fe5cf | 7433 | |
c19d1205 ZW |
7434 | constraint (inst.reloc.exp.X_op != O_constant |
7435 | || inst.reloc.exp.X_add_number != 0, | |
7436 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 7437 | |
c19d1205 ZW |
7438 | inst.instruction |= inst.operands[0].reg << 12; |
7439 | inst.instruction |= inst.operands[1].reg << 16; | |
7440 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
7441 | } |
7442 | ||
7443 | static void | |
c19d1205 | 7444 | do_ldrexd (void) |
b05fe5cf | 7445 | { |
c19d1205 ZW |
7446 | constraint (inst.operands[0].reg % 2 != 0, |
7447 | _("even register required")); | |
7448 | constraint (inst.operands[1].present | |
7449 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7450 | _("can only load two consecutive registers")); | |
7451 | /* If op 1 were present and equal to PC, this function wouldn't | |
7452 | have been called in the first place. */ | |
7453 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 7454 | |
c19d1205 ZW |
7455 | inst.instruction |= inst.operands[0].reg << 12; |
7456 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
7457 | } |
7458 | ||
7459 | static void | |
c19d1205 | 7460 | do_ldst (void) |
b05fe5cf | 7461 | { |
c19d1205 ZW |
7462 | inst.instruction |= inst.operands[0].reg << 12; |
7463 | if (!inst.operands[1].isreg) | |
7464 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 7465 | return; |
c19d1205 | 7466 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7467 | } |
7468 | ||
7469 | static void | |
c19d1205 | 7470 | do_ldstt (void) |
b05fe5cf | 7471 | { |
c19d1205 ZW |
7472 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7473 | reject [Rn,...]. */ | |
7474 | if (inst.operands[1].preind) | |
b05fe5cf | 7475 | { |
bd3ba5d1 NC |
7476 | constraint (inst.reloc.exp.X_op != O_constant |
7477 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7478 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7479 | |
c19d1205 ZW |
7480 | inst.operands[1].preind = 0; |
7481 | inst.operands[1].postind = 1; | |
7482 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7483 | } |
c19d1205 ZW |
7484 | inst.instruction |= inst.operands[0].reg << 12; |
7485 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
7486 | } | |
b05fe5cf | 7487 | |
c19d1205 | 7488 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 7489 | |
c19d1205 ZW |
7490 | static void |
7491 | do_ldstv4 (void) | |
7492 | { | |
7493 | inst.instruction |= inst.operands[0].reg << 12; | |
7494 | if (!inst.operands[1].isreg) | |
7495 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 7496 | return; |
c19d1205 | 7497 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7498 | } |
7499 | ||
7500 | static void | |
c19d1205 | 7501 | do_ldsttv4 (void) |
b05fe5cf | 7502 | { |
c19d1205 ZW |
7503 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7504 | reject [Rn,...]. */ | |
7505 | if (inst.operands[1].preind) | |
b05fe5cf | 7506 | { |
bd3ba5d1 NC |
7507 | constraint (inst.reloc.exp.X_op != O_constant |
7508 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7509 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7510 | |
c19d1205 ZW |
7511 | inst.operands[1].preind = 0; |
7512 | inst.operands[1].postind = 1; | |
7513 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7514 | } |
c19d1205 ZW |
7515 | inst.instruction |= inst.operands[0].reg << 12; |
7516 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
7517 | } | |
b05fe5cf | 7518 | |
c19d1205 ZW |
7519 | /* Co-processor register load/store. |
7520 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
7521 | static void | |
7522 | do_lstc (void) | |
7523 | { | |
7524 | inst.instruction |= inst.operands[0].reg << 8; | |
7525 | inst.instruction |= inst.operands[1].reg << 12; | |
7526 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
7527 | } |
7528 | ||
b05fe5cf | 7529 | static void |
c19d1205 | 7530 | do_mlas (void) |
b05fe5cf | 7531 | { |
8fb9d7b9 | 7532 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 7533 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 7534 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 7535 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 7536 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 7537 | |
c19d1205 ZW |
7538 | inst.instruction |= inst.operands[0].reg << 16; |
7539 | inst.instruction |= inst.operands[1].reg; | |
7540 | inst.instruction |= inst.operands[2].reg << 8; | |
7541 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 7542 | } |
b05fe5cf | 7543 | |
c19d1205 ZW |
7544 | static void |
7545 | do_mov (void) | |
7546 | { | |
7547 | inst.instruction |= inst.operands[0].reg << 12; | |
7548 | encode_arm_shifter_operand (1); | |
7549 | } | |
b05fe5cf | 7550 | |
c19d1205 ZW |
7551 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
7552 | static void | |
7553 | do_mov16 (void) | |
7554 | { | |
b6895b4f PB |
7555 | bfd_vma imm; |
7556 | bfd_boolean top; | |
7557 | ||
7558 | top = (inst.instruction & 0x00400000) != 0; | |
7559 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
7560 | _(":lower16: not allowed this instruction")); | |
7561 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
7562 | _(":upper16: not allowed instruction")); | |
c19d1205 | 7563 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
7564 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
7565 | { | |
7566 | imm = inst.reloc.exp.X_add_number; | |
7567 | /* The value is in two pieces: 0:11, 16:19. */ | |
7568 | inst.instruction |= (imm & 0x00000fff); | |
7569 | inst.instruction |= (imm & 0x0000f000) << 4; | |
7570 | } | |
b05fe5cf | 7571 | } |
b99bd4ef | 7572 | |
037e8744 JB |
7573 | static void do_vfp_nsyn_opcode (const char *); |
7574 | ||
7575 | static int | |
7576 | do_vfp_nsyn_mrs (void) | |
7577 | { | |
7578 | if (inst.operands[0].isvec) | |
7579 | { | |
7580 | if (inst.operands[1].reg != 1) | |
7581 | first_error (_("operand 1 must be FPSCR")); | |
7582 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
7583 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
7584 | do_vfp_nsyn_opcode ("fmstat"); | |
7585 | } | |
7586 | else if (inst.operands[1].isvec) | |
7587 | do_vfp_nsyn_opcode ("fmrx"); | |
7588 | else | |
7589 | return FAIL; | |
5f4273c7 | 7590 | |
037e8744 JB |
7591 | return SUCCESS; |
7592 | } | |
7593 | ||
7594 | static int | |
7595 | do_vfp_nsyn_msr (void) | |
7596 | { | |
7597 | if (inst.operands[0].isvec) | |
7598 | do_vfp_nsyn_opcode ("fmxr"); | |
7599 | else | |
7600 | return FAIL; | |
7601 | ||
7602 | return SUCCESS; | |
7603 | } | |
7604 | ||
b99bd4ef | 7605 | static void |
c19d1205 | 7606 | do_mrs (void) |
b99bd4ef | 7607 | { |
037e8744 JB |
7608 | if (do_vfp_nsyn_mrs () == SUCCESS) |
7609 | return; | |
7610 | ||
c19d1205 ZW |
7611 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
7612 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7613 | != (PSR_c|PSR_f), | |
7614 | _("'CPSR' or 'SPSR' expected")); | |
7615 | inst.instruction |= inst.operands[0].reg << 12; | |
7616 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
7617 | } | |
b99bd4ef | 7618 | |
c19d1205 ZW |
7619 | /* Two possible forms: |
7620 | "{C|S}PSR_<field>, Rm", | |
7621 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 7622 | |
c19d1205 ZW |
7623 | static void |
7624 | do_msr (void) | |
7625 | { | |
037e8744 JB |
7626 | if (do_vfp_nsyn_msr () == SUCCESS) |
7627 | return; | |
7628 | ||
c19d1205 ZW |
7629 | inst.instruction |= inst.operands[0].imm; |
7630 | if (inst.operands[1].isreg) | |
7631 | inst.instruction |= inst.operands[1].reg; | |
7632 | else | |
b99bd4ef | 7633 | { |
c19d1205 ZW |
7634 | inst.instruction |= INST_IMMEDIATE; |
7635 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
7636 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 7637 | } |
b99bd4ef NC |
7638 | } |
7639 | ||
c19d1205 ZW |
7640 | static void |
7641 | do_mul (void) | |
a737bd4d | 7642 | { |
c19d1205 ZW |
7643 | if (!inst.operands[2].present) |
7644 | inst.operands[2].reg = inst.operands[0].reg; | |
7645 | inst.instruction |= inst.operands[0].reg << 16; | |
7646 | inst.instruction |= inst.operands[1].reg; | |
7647 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 7648 | |
8fb9d7b9 MS |
7649 | if (inst.operands[0].reg == inst.operands[1].reg |
7650 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
7651 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
7652 | } |
7653 | ||
c19d1205 ZW |
7654 | /* Long Multiply Parser |
7655 | UMULL RdLo, RdHi, Rm, Rs | |
7656 | SMULL RdLo, RdHi, Rm, Rs | |
7657 | UMLAL RdLo, RdHi, Rm, Rs | |
7658 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
7659 | |
7660 | static void | |
c19d1205 | 7661 | do_mull (void) |
b99bd4ef | 7662 | { |
c19d1205 ZW |
7663 | inst.instruction |= inst.operands[0].reg << 12; |
7664 | inst.instruction |= inst.operands[1].reg << 16; | |
7665 | inst.instruction |= inst.operands[2].reg; | |
7666 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 7667 | |
682b27ad PB |
7668 | /* rdhi and rdlo must be different. */ |
7669 | if (inst.operands[0].reg == inst.operands[1].reg) | |
7670 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7671 | ||
7672 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
7673 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 7674 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 7675 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
7676 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
7677 | } | |
b99bd4ef | 7678 | |
c19d1205 ZW |
7679 | static void |
7680 | do_nop (void) | |
7681 | { | |
e7495e45 NS |
7682 | if (inst.operands[0].present |
7683 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
7684 | { |
7685 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
7686 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
7687 | inst.instruction |= 0x0320f000; |
7688 | if (inst.operands[0].present) | |
7689 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 7690 | } |
b99bd4ef NC |
7691 | } |
7692 | ||
c19d1205 ZW |
7693 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
7694 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
7695 | Condition defaults to COND_ALWAYS. | |
7696 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
7697 | |
7698 | static void | |
c19d1205 | 7699 | do_pkhbt (void) |
b99bd4ef | 7700 | { |
c19d1205 ZW |
7701 | inst.instruction |= inst.operands[0].reg << 12; |
7702 | inst.instruction |= inst.operands[1].reg << 16; | |
7703 | inst.instruction |= inst.operands[2].reg; | |
7704 | if (inst.operands[3].present) | |
7705 | encode_arm_shift (3); | |
7706 | } | |
b99bd4ef | 7707 | |
c19d1205 | 7708 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 7709 | |
c19d1205 ZW |
7710 | static void |
7711 | do_pkhtb (void) | |
7712 | { | |
7713 | if (!inst.operands[3].present) | |
b99bd4ef | 7714 | { |
c19d1205 ZW |
7715 | /* If the shift specifier is omitted, turn the instruction |
7716 | into pkhbt rd, rm, rn. */ | |
7717 | inst.instruction &= 0xfff00010; | |
7718 | inst.instruction |= inst.operands[0].reg << 12; | |
7719 | inst.instruction |= inst.operands[1].reg; | |
7720 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7721 | } |
7722 | else | |
7723 | { | |
c19d1205 ZW |
7724 | inst.instruction |= inst.operands[0].reg << 12; |
7725 | inst.instruction |= inst.operands[1].reg << 16; | |
7726 | inst.instruction |= inst.operands[2].reg; | |
7727 | encode_arm_shift (3); | |
b99bd4ef NC |
7728 | } |
7729 | } | |
7730 | ||
c19d1205 ZW |
7731 | /* ARMv5TE: Preload-Cache |
7732 | ||
7733 | PLD <addr_mode> | |
7734 | ||
7735 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
7736 | |
7737 | static void | |
c19d1205 | 7738 | do_pld (void) |
b99bd4ef | 7739 | { |
c19d1205 ZW |
7740 | constraint (!inst.operands[0].isreg, |
7741 | _("'[' expected after PLD mnemonic")); | |
7742 | constraint (inst.operands[0].postind, | |
7743 | _("post-indexed expression used in preload instruction")); | |
7744 | constraint (inst.operands[0].writeback, | |
7745 | _("writeback used in preload instruction")); | |
7746 | constraint (!inst.operands[0].preind, | |
7747 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
7748 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
7749 | } | |
b99bd4ef | 7750 | |
62b3e311 PB |
7751 | /* ARMv7: PLI <addr_mode> */ |
7752 | static void | |
7753 | do_pli (void) | |
7754 | { | |
7755 | constraint (!inst.operands[0].isreg, | |
7756 | _("'[' expected after PLI mnemonic")); | |
7757 | constraint (inst.operands[0].postind, | |
7758 | _("post-indexed expression used in preload instruction")); | |
7759 | constraint (inst.operands[0].writeback, | |
7760 | _("writeback used in preload instruction")); | |
7761 | constraint (!inst.operands[0].preind, | |
7762 | _("unindexed addressing used in preload instruction")); | |
7763 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
7764 | inst.instruction &= ~PRE_INDEX; | |
7765 | } | |
7766 | ||
c19d1205 ZW |
7767 | static void |
7768 | do_push_pop (void) | |
7769 | { | |
7770 | inst.operands[1] = inst.operands[0]; | |
7771 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
7772 | inst.operands[0].isreg = 1; | |
7773 | inst.operands[0].writeback = 1; | |
7774 | inst.operands[0].reg = REG_SP; | |
7775 | do_ldmstm (); | |
7776 | } | |
b99bd4ef | 7777 | |
c19d1205 ZW |
7778 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
7779 | word at the specified address and the following word | |
7780 | respectively. | |
7781 | Unconditionally executed. | |
7782 | Error if Rn is R15. */ | |
b99bd4ef | 7783 | |
c19d1205 ZW |
7784 | static void |
7785 | do_rfe (void) | |
7786 | { | |
7787 | inst.instruction |= inst.operands[0].reg << 16; | |
7788 | if (inst.operands[0].writeback) | |
7789 | inst.instruction |= WRITE_BACK; | |
7790 | } | |
b99bd4ef | 7791 | |
c19d1205 | 7792 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 7793 | |
c19d1205 ZW |
7794 | static void |
7795 | do_ssat (void) | |
7796 | { | |
7797 | inst.instruction |= inst.operands[0].reg << 12; | |
7798 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
7799 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7800 | |
c19d1205 ZW |
7801 | if (inst.operands[3].present) |
7802 | encode_arm_shift (3); | |
b99bd4ef NC |
7803 | } |
7804 | ||
c19d1205 | 7805 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
7806 | |
7807 | static void | |
c19d1205 | 7808 | do_usat (void) |
b99bd4ef | 7809 | { |
c19d1205 ZW |
7810 | inst.instruction |= inst.operands[0].reg << 12; |
7811 | inst.instruction |= inst.operands[1].imm << 16; | |
7812 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7813 | |
c19d1205 ZW |
7814 | if (inst.operands[3].present) |
7815 | encode_arm_shift (3); | |
b99bd4ef NC |
7816 | } |
7817 | ||
c19d1205 | 7818 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
7819 | |
7820 | static void | |
c19d1205 | 7821 | do_ssat16 (void) |
09d92015 | 7822 | { |
c19d1205 ZW |
7823 | inst.instruction |= inst.operands[0].reg << 12; |
7824 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
7825 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
7826 | } |
7827 | ||
c19d1205 ZW |
7828 | static void |
7829 | do_usat16 (void) | |
a737bd4d | 7830 | { |
c19d1205 ZW |
7831 | inst.instruction |= inst.operands[0].reg << 12; |
7832 | inst.instruction |= inst.operands[1].imm << 16; | |
7833 | inst.instruction |= inst.operands[2].reg; | |
7834 | } | |
a737bd4d | 7835 | |
c19d1205 ZW |
7836 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
7837 | preserving the other bits. | |
a737bd4d | 7838 | |
c19d1205 ZW |
7839 | setend <endian_specifier>, where <endian_specifier> is either |
7840 | BE or LE. */ | |
a737bd4d | 7841 | |
c19d1205 ZW |
7842 | static void |
7843 | do_setend (void) | |
7844 | { | |
7845 | if (inst.operands[0].imm) | |
7846 | inst.instruction |= 0x200; | |
a737bd4d NC |
7847 | } |
7848 | ||
7849 | static void | |
c19d1205 | 7850 | do_shift (void) |
a737bd4d | 7851 | { |
c19d1205 ZW |
7852 | unsigned int Rm = (inst.operands[1].present |
7853 | ? inst.operands[1].reg | |
7854 | : inst.operands[0].reg); | |
a737bd4d | 7855 | |
c19d1205 ZW |
7856 | inst.instruction |= inst.operands[0].reg << 12; |
7857 | inst.instruction |= Rm; | |
7858 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 7859 | { |
c19d1205 ZW |
7860 | inst.instruction |= inst.operands[2].reg << 8; |
7861 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
7862 | } |
7863 | else | |
c19d1205 | 7864 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
7865 | } |
7866 | ||
09d92015 | 7867 | static void |
3eb17e6b | 7868 | do_smc (void) |
09d92015 | 7869 | { |
3eb17e6b | 7870 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 7871 | inst.reloc.pc_rel = 0; |
09d92015 MM |
7872 | } |
7873 | ||
09d92015 | 7874 | static void |
c19d1205 | 7875 | do_swi (void) |
09d92015 | 7876 | { |
c19d1205 ZW |
7877 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
7878 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
7879 | } |
7880 | ||
c19d1205 ZW |
7881 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
7882 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
7883 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
7884 | Error if any register is R15. */ | |
e16bb312 | 7885 | |
c19d1205 ZW |
7886 | static void |
7887 | do_smla (void) | |
e16bb312 | 7888 | { |
c19d1205 ZW |
7889 | inst.instruction |= inst.operands[0].reg << 16; |
7890 | inst.instruction |= inst.operands[1].reg; | |
7891 | inst.instruction |= inst.operands[2].reg << 8; | |
7892 | inst.instruction |= inst.operands[3].reg << 12; | |
7893 | } | |
a737bd4d | 7894 | |
c19d1205 ZW |
7895 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
7896 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
7897 | Error if any register is R15. | |
7898 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 7899 | |
c19d1205 ZW |
7900 | static void |
7901 | do_smlal (void) | |
7902 | { | |
7903 | inst.instruction |= inst.operands[0].reg << 12; | |
7904 | inst.instruction |= inst.operands[1].reg << 16; | |
7905 | inst.instruction |= inst.operands[2].reg; | |
7906 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 7907 | |
c19d1205 ZW |
7908 | if (inst.operands[0].reg == inst.operands[1].reg) |
7909 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7910 | } | |
a737bd4d | 7911 | |
c19d1205 ZW |
7912 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
7913 | SMULxy{cond} Rd,Rm,Rs | |
7914 | Error if any register is R15. */ | |
a737bd4d | 7915 | |
c19d1205 ZW |
7916 | static void |
7917 | do_smul (void) | |
7918 | { | |
7919 | inst.instruction |= inst.operands[0].reg << 16; | |
7920 | inst.instruction |= inst.operands[1].reg; | |
7921 | inst.instruction |= inst.operands[2].reg << 8; | |
7922 | } | |
a737bd4d | 7923 | |
b6702015 PB |
7924 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
7925 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 7926 | |
c19d1205 ZW |
7927 | static void |
7928 | do_srs (void) | |
7929 | { | |
b6702015 PB |
7930 | int reg; |
7931 | ||
7932 | if (inst.operands[0].present) | |
7933 | { | |
7934 | reg = inst.operands[0].reg; | |
fdfde340 | 7935 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
7936 | } |
7937 | else | |
fdfde340 | 7938 | reg = REG_SP; |
b6702015 PB |
7939 | |
7940 | inst.instruction |= reg << 16; | |
7941 | inst.instruction |= inst.operands[1].imm; | |
7942 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
7943 | inst.instruction |= WRITE_BACK; |
7944 | } | |
a737bd4d | 7945 | |
c19d1205 | 7946 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 7947 | |
c19d1205 ZW |
7948 | static void |
7949 | do_strex (void) | |
7950 | { | |
7951 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7952 | || inst.operands[2].postind || inst.operands[2].writeback | |
7953 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
7954 | || inst.operands[2].negative |
7955 | /* See comment in do_ldrex(). */ | |
7956 | || (inst.operands[2].reg == REG_PC), | |
7957 | BAD_ADDR_MODE); | |
a737bd4d | 7958 | |
c19d1205 ZW |
7959 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7960 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 7961 | |
c19d1205 ZW |
7962 | constraint (inst.reloc.exp.X_op != O_constant |
7963 | || inst.reloc.exp.X_add_number != 0, | |
7964 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 7965 | |
c19d1205 ZW |
7966 | inst.instruction |= inst.operands[0].reg << 12; |
7967 | inst.instruction |= inst.operands[1].reg; | |
7968 | inst.instruction |= inst.operands[2].reg << 16; | |
7969 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
7970 | } |
7971 | ||
7972 | static void | |
c19d1205 | 7973 | do_strexd (void) |
e16bb312 | 7974 | { |
c19d1205 ZW |
7975 | constraint (inst.operands[1].reg % 2 != 0, |
7976 | _("even register required")); | |
7977 | constraint (inst.operands[2].present | |
7978 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
7979 | _("can only store two consecutive registers")); | |
7980 | /* If op 2 were present and equal to PC, this function wouldn't | |
7981 | have been called in the first place. */ | |
7982 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 7983 | |
c19d1205 ZW |
7984 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7985 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
7986 | || inst.operands[0].reg == inst.operands[3].reg, | |
7987 | BAD_OVERLAP); | |
e16bb312 | 7988 | |
c19d1205 ZW |
7989 | inst.instruction |= inst.operands[0].reg << 12; |
7990 | inst.instruction |= inst.operands[1].reg; | |
7991 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
7992 | } |
7993 | ||
c19d1205 ZW |
7994 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
7995 | extends it to 32-bits, and adds the result to a value in another | |
7996 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
7997 | before extracting the 16-bit value. | |
7998 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
7999 | Condition defaults to COND_ALWAYS. | |
8000 | Error if any register uses R15. */ | |
8001 | ||
e16bb312 | 8002 | static void |
c19d1205 | 8003 | do_sxtah (void) |
e16bb312 | 8004 | { |
c19d1205 ZW |
8005 | inst.instruction |= inst.operands[0].reg << 12; |
8006 | inst.instruction |= inst.operands[1].reg << 16; | |
8007 | inst.instruction |= inst.operands[2].reg; | |
8008 | inst.instruction |= inst.operands[3].imm << 10; | |
8009 | } | |
e16bb312 | 8010 | |
c19d1205 | 8011 | /* ARM V6 SXTH. |
e16bb312 | 8012 | |
c19d1205 ZW |
8013 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
8014 | Condition defaults to COND_ALWAYS. | |
8015 | Error if any register uses R15. */ | |
e16bb312 NC |
8016 | |
8017 | static void | |
c19d1205 | 8018 | do_sxth (void) |
e16bb312 | 8019 | { |
c19d1205 ZW |
8020 | inst.instruction |= inst.operands[0].reg << 12; |
8021 | inst.instruction |= inst.operands[1].reg; | |
8022 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 8023 | } |
c19d1205 ZW |
8024 | \f |
8025 | /* VFP instructions. In a logical order: SP variant first, monad | |
8026 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
8027 | |
8028 | static void | |
c19d1205 | 8029 | do_vfp_sp_monadic (void) |
e16bb312 | 8030 | { |
5287ad62 JB |
8031 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8032 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8033 | } |
8034 | ||
8035 | static void | |
c19d1205 | 8036 | do_vfp_sp_dyadic (void) |
e16bb312 | 8037 | { |
5287ad62 JB |
8038 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8039 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
8040 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
8041 | } |
8042 | ||
8043 | static void | |
c19d1205 | 8044 | do_vfp_sp_compare_z (void) |
e16bb312 | 8045 | { |
5287ad62 | 8046 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
8047 | } |
8048 | ||
8049 | static void | |
c19d1205 | 8050 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 8051 | { |
5287ad62 JB |
8052 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
8053 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
8054 | } |
8055 | ||
8056 | static void | |
c19d1205 | 8057 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 8058 | { |
5287ad62 JB |
8059 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
8060 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
8061 | } |
8062 | ||
8063 | static void | |
c19d1205 | 8064 | do_vfp_reg_from_sp (void) |
e16bb312 | 8065 | { |
c19d1205 | 8066 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 8067 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
8068 | } |
8069 | ||
8070 | static void | |
c19d1205 | 8071 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 8072 | { |
c19d1205 ZW |
8073 | constraint (inst.operands[2].imm != 2, |
8074 | _("only two consecutive VFP SP registers allowed here")); | |
8075 | inst.instruction |= inst.operands[0].reg << 12; | |
8076 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 8077 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
8078 | } |
8079 | ||
8080 | static void | |
c19d1205 | 8081 | do_vfp_sp_from_reg (void) |
e16bb312 | 8082 | { |
5287ad62 | 8083 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 8084 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
8085 | } |
8086 | ||
8087 | static void | |
c19d1205 | 8088 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 8089 | { |
c19d1205 ZW |
8090 | constraint (inst.operands[0].imm != 2, |
8091 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 8092 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
8093 | inst.instruction |= inst.operands[1].reg << 12; |
8094 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
8095 | } |
8096 | ||
8097 | static void | |
c19d1205 | 8098 | do_vfp_sp_ldst (void) |
e16bb312 | 8099 | { |
5287ad62 | 8100 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 8101 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8102 | } |
8103 | ||
8104 | static void | |
c19d1205 | 8105 | do_vfp_dp_ldst (void) |
e16bb312 | 8106 | { |
5287ad62 | 8107 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 8108 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8109 | } |
8110 | ||
c19d1205 | 8111 | |
e16bb312 | 8112 | static void |
c19d1205 | 8113 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8114 | { |
c19d1205 ZW |
8115 | if (inst.operands[0].writeback) |
8116 | inst.instruction |= WRITE_BACK; | |
8117 | else | |
8118 | constraint (ldstm_type != VFP_LDSTMIA, | |
8119 | _("this addressing mode requires base-register writeback")); | |
8120 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 8121 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 8122 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
8123 | } |
8124 | ||
8125 | static void | |
c19d1205 | 8126 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8127 | { |
c19d1205 | 8128 | int count; |
e16bb312 | 8129 | |
c19d1205 ZW |
8130 | if (inst.operands[0].writeback) |
8131 | inst.instruction |= WRITE_BACK; | |
8132 | else | |
8133 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
8134 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 8135 | |
c19d1205 | 8136 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 8137 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 8138 | |
c19d1205 ZW |
8139 | count = inst.operands[1].imm << 1; |
8140 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
8141 | count += 1; | |
e16bb312 | 8142 | |
c19d1205 | 8143 | inst.instruction |= count; |
e16bb312 NC |
8144 | } |
8145 | ||
8146 | static void | |
c19d1205 | 8147 | do_vfp_sp_ldstmia (void) |
e16bb312 | 8148 | { |
c19d1205 | 8149 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8150 | } |
8151 | ||
8152 | static void | |
c19d1205 | 8153 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 8154 | { |
c19d1205 | 8155 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8156 | } |
8157 | ||
8158 | static void | |
c19d1205 | 8159 | do_vfp_dp_ldstmia (void) |
e16bb312 | 8160 | { |
c19d1205 | 8161 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8162 | } |
8163 | ||
8164 | static void | |
c19d1205 | 8165 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 8166 | { |
c19d1205 | 8167 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8168 | } |
8169 | ||
8170 | static void | |
c19d1205 | 8171 | do_vfp_xp_ldstmia (void) |
e16bb312 | 8172 | { |
c19d1205 ZW |
8173 | vfp_dp_ldstm (VFP_LDSTMIAX); |
8174 | } | |
e16bb312 | 8175 | |
c19d1205 ZW |
8176 | static void |
8177 | do_vfp_xp_ldstmdb (void) | |
8178 | { | |
8179 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 8180 | } |
5287ad62 JB |
8181 | |
8182 | static void | |
8183 | do_vfp_dp_rd_rm (void) | |
8184 | { | |
8185 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8186 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
8187 | } | |
8188 | ||
8189 | static void | |
8190 | do_vfp_dp_rn_rd (void) | |
8191 | { | |
8192 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
8193 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8194 | } | |
8195 | ||
8196 | static void | |
8197 | do_vfp_dp_rd_rn (void) | |
8198 | { | |
8199 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8200 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8201 | } | |
8202 | ||
8203 | static void | |
8204 | do_vfp_dp_rd_rn_rm (void) | |
8205 | { | |
8206 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8207 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8208 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
8209 | } | |
8210 | ||
8211 | static void | |
8212 | do_vfp_dp_rd (void) | |
8213 | { | |
8214 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8215 | } | |
8216 | ||
8217 | static void | |
8218 | do_vfp_dp_rm_rd_rn (void) | |
8219 | { | |
8220 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
8221 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8222 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
8223 | } | |
8224 | ||
8225 | /* VFPv3 instructions. */ | |
8226 | static void | |
8227 | do_vfp_sp_const (void) | |
8228 | { | |
8229 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
8230 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8231 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8232 | } |
8233 | ||
8234 | static void | |
8235 | do_vfp_dp_const (void) | |
8236 | { | |
8237 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
8238 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8239 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8240 | } |
8241 | ||
8242 | static void | |
8243 | vfp_conv (int srcsize) | |
8244 | { | |
8245 | unsigned immbits = srcsize - inst.operands[1].imm; | |
8246 | inst.instruction |= (immbits & 1) << 5; | |
8247 | inst.instruction |= (immbits >> 1); | |
8248 | } | |
8249 | ||
8250 | static void | |
8251 | do_vfp_sp_conv_16 (void) | |
8252 | { | |
8253 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8254 | vfp_conv (16); | |
8255 | } | |
8256 | ||
8257 | static void | |
8258 | do_vfp_dp_conv_16 (void) | |
8259 | { | |
8260 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8261 | vfp_conv (16); | |
8262 | } | |
8263 | ||
8264 | static void | |
8265 | do_vfp_sp_conv_32 (void) | |
8266 | { | |
8267 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8268 | vfp_conv (32); | |
8269 | } | |
8270 | ||
8271 | static void | |
8272 | do_vfp_dp_conv_32 (void) | |
8273 | { | |
8274 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8275 | vfp_conv (32); | |
8276 | } | |
c19d1205 ZW |
8277 | \f |
8278 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 8279 | |
c19d1205 ZW |
8280 | static void |
8281 | do_fpa_cmp (void) | |
8282 | { | |
8283 | inst.instruction |= inst.operands[0].reg << 16; | |
8284 | inst.instruction |= inst.operands[1].reg; | |
8285 | } | |
b99bd4ef NC |
8286 | |
8287 | static void | |
c19d1205 | 8288 | do_fpa_ldmstm (void) |
b99bd4ef | 8289 | { |
c19d1205 ZW |
8290 | inst.instruction |= inst.operands[0].reg << 12; |
8291 | switch (inst.operands[1].imm) | |
8292 | { | |
8293 | case 1: inst.instruction |= CP_T_X; break; | |
8294 | case 2: inst.instruction |= CP_T_Y; break; | |
8295 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
8296 | case 4: break; | |
8297 | default: abort (); | |
8298 | } | |
b99bd4ef | 8299 | |
c19d1205 ZW |
8300 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
8301 | { | |
8302 | /* The instruction specified "ea" or "fd", so we can only accept | |
8303 | [Rn]{!}. The instruction does not really support stacking or | |
8304 | unstacking, so we have to emulate these by setting appropriate | |
8305 | bits and offsets. */ | |
8306 | constraint (inst.reloc.exp.X_op != O_constant | |
8307 | || inst.reloc.exp.X_add_number != 0, | |
8308 | _("this instruction does not support indexing")); | |
b99bd4ef | 8309 | |
c19d1205 ZW |
8310 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
8311 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 8312 | |
c19d1205 ZW |
8313 | if (!(inst.instruction & INDEX_UP)) |
8314 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 8315 | |
c19d1205 ZW |
8316 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
8317 | { | |
8318 | inst.operands[2].preind = 0; | |
8319 | inst.operands[2].postind = 1; | |
8320 | } | |
8321 | } | |
b99bd4ef | 8322 | |
c19d1205 | 8323 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 8324 | } |
c19d1205 ZW |
8325 | \f |
8326 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 8327 | |
c19d1205 ZW |
8328 | static void |
8329 | do_iwmmxt_tandorc (void) | |
8330 | { | |
8331 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
8332 | } | |
b99bd4ef | 8333 | |
c19d1205 ZW |
8334 | static void |
8335 | do_iwmmxt_textrc (void) | |
8336 | { | |
8337 | inst.instruction |= inst.operands[0].reg << 12; | |
8338 | inst.instruction |= inst.operands[1].imm; | |
8339 | } | |
b99bd4ef NC |
8340 | |
8341 | static void | |
c19d1205 | 8342 | do_iwmmxt_textrm (void) |
b99bd4ef | 8343 | { |
c19d1205 ZW |
8344 | inst.instruction |= inst.operands[0].reg << 12; |
8345 | inst.instruction |= inst.operands[1].reg << 16; | |
8346 | inst.instruction |= inst.operands[2].imm; | |
8347 | } | |
b99bd4ef | 8348 | |
c19d1205 ZW |
8349 | static void |
8350 | do_iwmmxt_tinsr (void) | |
8351 | { | |
8352 | inst.instruction |= inst.operands[0].reg << 16; | |
8353 | inst.instruction |= inst.operands[1].reg << 12; | |
8354 | inst.instruction |= inst.operands[2].imm; | |
8355 | } | |
b99bd4ef | 8356 | |
c19d1205 ZW |
8357 | static void |
8358 | do_iwmmxt_tmia (void) | |
8359 | { | |
8360 | inst.instruction |= inst.operands[0].reg << 5; | |
8361 | inst.instruction |= inst.operands[1].reg; | |
8362 | inst.instruction |= inst.operands[2].reg << 12; | |
8363 | } | |
b99bd4ef | 8364 | |
c19d1205 ZW |
8365 | static void |
8366 | do_iwmmxt_waligni (void) | |
8367 | { | |
8368 | inst.instruction |= inst.operands[0].reg << 12; | |
8369 | inst.instruction |= inst.operands[1].reg << 16; | |
8370 | inst.instruction |= inst.operands[2].reg; | |
8371 | inst.instruction |= inst.operands[3].imm << 20; | |
8372 | } | |
b99bd4ef | 8373 | |
2d447fca JM |
8374 | static void |
8375 | do_iwmmxt_wmerge (void) | |
8376 | { | |
8377 | inst.instruction |= inst.operands[0].reg << 12; | |
8378 | inst.instruction |= inst.operands[1].reg << 16; | |
8379 | inst.instruction |= inst.operands[2].reg; | |
8380 | inst.instruction |= inst.operands[3].imm << 21; | |
8381 | } | |
8382 | ||
c19d1205 ZW |
8383 | static void |
8384 | do_iwmmxt_wmov (void) | |
8385 | { | |
8386 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
8387 | inst.instruction |= inst.operands[0].reg << 12; | |
8388 | inst.instruction |= inst.operands[1].reg << 16; | |
8389 | inst.instruction |= inst.operands[1].reg; | |
8390 | } | |
b99bd4ef | 8391 | |
c19d1205 ZW |
8392 | static void |
8393 | do_iwmmxt_wldstbh (void) | |
8394 | { | |
8f06b2d8 | 8395 | int reloc; |
c19d1205 | 8396 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
8397 | if (thumb_mode) |
8398 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
8399 | else | |
8400 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
8401 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
8402 | } |
8403 | ||
c19d1205 ZW |
8404 | static void |
8405 | do_iwmmxt_wldstw (void) | |
8406 | { | |
8407 | /* RIWR_RIWC clears .isreg for a control register. */ | |
8408 | if (!inst.operands[0].isreg) | |
8409 | { | |
8410 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
8411 | inst.instruction |= 0xf0000000; | |
8412 | } | |
b99bd4ef | 8413 | |
c19d1205 ZW |
8414 | inst.instruction |= inst.operands[0].reg << 12; |
8415 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
8416 | } | |
b99bd4ef NC |
8417 | |
8418 | static void | |
c19d1205 | 8419 | do_iwmmxt_wldstd (void) |
b99bd4ef | 8420 | { |
c19d1205 | 8421 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
8422 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
8423 | && inst.operands[1].immisreg) | |
8424 | { | |
8425 | inst.instruction &= ~0x1a000ff; | |
8426 | inst.instruction |= (0xf << 28); | |
8427 | if (inst.operands[1].preind) | |
8428 | inst.instruction |= PRE_INDEX; | |
8429 | if (!inst.operands[1].negative) | |
8430 | inst.instruction |= INDEX_UP; | |
8431 | if (inst.operands[1].writeback) | |
8432 | inst.instruction |= WRITE_BACK; | |
8433 | inst.instruction |= inst.operands[1].reg << 16; | |
8434 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
8435 | inst.instruction |= inst.operands[1].imm; | |
8436 | } | |
8437 | else | |
8438 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 8439 | } |
b99bd4ef | 8440 | |
c19d1205 ZW |
8441 | static void |
8442 | do_iwmmxt_wshufh (void) | |
8443 | { | |
8444 | inst.instruction |= inst.operands[0].reg << 12; | |
8445 | inst.instruction |= inst.operands[1].reg << 16; | |
8446 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
8447 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
8448 | } | |
b99bd4ef | 8449 | |
c19d1205 ZW |
8450 | static void |
8451 | do_iwmmxt_wzero (void) | |
8452 | { | |
8453 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
8454 | inst.instruction |= inst.operands[0].reg; | |
8455 | inst.instruction |= inst.operands[0].reg << 12; | |
8456 | inst.instruction |= inst.operands[0].reg << 16; | |
8457 | } | |
2d447fca JM |
8458 | |
8459 | static void | |
8460 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
8461 | { | |
8462 | if (inst.operands[2].isreg) | |
8463 | do_rd_rn_rm (); | |
8464 | else { | |
8465 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
8466 | _("immediate operand requires iWMMXt2")); | |
8467 | do_rd_rn (); | |
8468 | if (inst.operands[2].imm == 0) | |
8469 | { | |
8470 | switch ((inst.instruction >> 20) & 0xf) | |
8471 | { | |
8472 | case 4: | |
8473 | case 5: | |
8474 | case 6: | |
5f4273c7 | 8475 | case 7: |
2d447fca JM |
8476 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
8477 | inst.operands[2].imm = 16; | |
8478 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
8479 | break; | |
8480 | case 8: | |
8481 | case 9: | |
8482 | case 10: | |
8483 | case 11: | |
8484 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
8485 | inst.operands[2].imm = 32; | |
8486 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
8487 | break; | |
8488 | case 12: | |
8489 | case 13: | |
8490 | case 14: | |
8491 | case 15: | |
8492 | { | |
8493 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
8494 | unsigned long wrn; | |
8495 | wrn = (inst.instruction >> 16) & 0xf; | |
8496 | inst.instruction &= 0xff0fff0f; | |
8497 | inst.instruction |= wrn; | |
8498 | /* Bail out here; the instruction is now assembled. */ | |
8499 | return; | |
8500 | } | |
8501 | } | |
8502 | } | |
8503 | /* Map 32 -> 0, etc. */ | |
8504 | inst.operands[2].imm &= 0x1f; | |
8505 | inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); | |
8506 | } | |
8507 | } | |
c19d1205 ZW |
8508 | \f |
8509 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
8510 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 8511 | |
c19d1205 | 8512 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 8513 | |
c19d1205 ZW |
8514 | static void |
8515 | do_mav_triple (void) | |
8516 | { | |
8517 | inst.instruction |= inst.operands[0].reg << 16; | |
8518 | inst.instruction |= inst.operands[1].reg; | |
8519 | inst.instruction |= inst.operands[2].reg << 12; | |
8520 | } | |
b99bd4ef | 8521 | |
c19d1205 ZW |
8522 | /* Insns like "foo W,X,Y,Z". |
8523 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 8524 | |
c19d1205 ZW |
8525 | static void |
8526 | do_mav_quad (void) | |
8527 | { | |
8528 | inst.instruction |= inst.operands[0].reg << 5; | |
8529 | inst.instruction |= inst.operands[1].reg << 12; | |
8530 | inst.instruction |= inst.operands[2].reg << 16; | |
8531 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
8532 | } |
8533 | ||
c19d1205 ZW |
8534 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
8535 | static void | |
8536 | do_mav_dspsc (void) | |
a737bd4d | 8537 | { |
c19d1205 ZW |
8538 | inst.instruction |= inst.operands[1].reg << 12; |
8539 | } | |
a737bd4d | 8540 | |
c19d1205 ZW |
8541 | /* Maverick shift immediate instructions. |
8542 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
8543 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 8544 | |
c19d1205 ZW |
8545 | static void |
8546 | do_mav_shift (void) | |
8547 | { | |
8548 | int imm = inst.operands[2].imm; | |
a737bd4d | 8549 | |
c19d1205 ZW |
8550 | inst.instruction |= inst.operands[0].reg << 12; |
8551 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 8552 | |
c19d1205 ZW |
8553 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
8554 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
8555 | Bit 4 should be 0. */ | |
8556 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 8557 | |
c19d1205 ZW |
8558 | inst.instruction |= imm; |
8559 | } | |
8560 | \f | |
8561 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 8562 | |
c19d1205 ZW |
8563 | /* Xscale multiply-accumulate (argument parse) |
8564 | MIAcc acc0,Rm,Rs | |
8565 | MIAPHcc acc0,Rm,Rs | |
8566 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 8567 | |
c19d1205 ZW |
8568 | static void |
8569 | do_xsc_mia (void) | |
8570 | { | |
8571 | inst.instruction |= inst.operands[1].reg; | |
8572 | inst.instruction |= inst.operands[2].reg << 12; | |
8573 | } | |
a737bd4d | 8574 | |
c19d1205 | 8575 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 8576 | |
c19d1205 | 8577 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 8578 | |
c19d1205 ZW |
8579 | static void |
8580 | do_xsc_mar (void) | |
8581 | { | |
8582 | inst.instruction |= inst.operands[1].reg << 12; | |
8583 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8584 | } |
8585 | ||
c19d1205 | 8586 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 8587 | |
c19d1205 | 8588 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
8589 | |
8590 | static void | |
c19d1205 | 8591 | do_xsc_mra (void) |
b99bd4ef | 8592 | { |
c19d1205 ZW |
8593 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
8594 | inst.instruction |= inst.operands[0].reg << 12; | |
8595 | inst.instruction |= inst.operands[1].reg << 16; | |
8596 | } | |
8597 | \f | |
8598 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 8599 | |
c19d1205 ZW |
8600 | /* inst.operands[i] is a shifted-register operand; encode |
8601 | it into inst.instruction in the format used by Thumb32. */ | |
8602 | ||
8603 | static void | |
8604 | encode_thumb32_shifted_operand (int i) | |
8605 | { | |
8606 | unsigned int value = inst.reloc.exp.X_add_number; | |
8607 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 8608 | |
9c3c69f2 PB |
8609 | constraint (inst.operands[i].immisreg, |
8610 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
8611 | inst.instruction |= inst.operands[i].reg; |
8612 | if (shift == SHIFT_RRX) | |
8613 | inst.instruction |= SHIFT_ROR << 4; | |
8614 | else | |
b99bd4ef | 8615 | { |
c19d1205 ZW |
8616 | constraint (inst.reloc.exp.X_op != O_constant, |
8617 | _("expression too complex")); | |
8618 | ||
8619 | constraint (value > 32 | |
8620 | || (value == 32 && (shift == SHIFT_LSL | |
8621 | || shift == SHIFT_ROR)), | |
8622 | _("shift expression is too large")); | |
8623 | ||
8624 | if (value == 0) | |
8625 | shift = SHIFT_LSL; | |
8626 | else if (value == 32) | |
8627 | value = 0; | |
8628 | ||
8629 | inst.instruction |= shift << 4; | |
8630 | inst.instruction |= (value & 0x1c) << 10; | |
8631 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 8632 | } |
c19d1205 | 8633 | } |
b99bd4ef | 8634 | |
b99bd4ef | 8635 | |
c19d1205 ZW |
8636 | /* inst.operands[i] was set up by parse_address. Encode it into a |
8637 | Thumb32 format load or store instruction. Reject forms that cannot | |
8638 | be used with such instructions. If is_t is true, reject forms that | |
8639 | cannot be used with a T instruction; if is_d is true, reject forms | |
8640 | that cannot be used with a D instruction. */ | |
b99bd4ef | 8641 | |
c19d1205 ZW |
8642 | static void |
8643 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
8644 | { | |
8645 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
8646 | ||
8647 | constraint (!inst.operands[i].isreg, | |
53365c0d | 8648 | _("Instruction does not support =N addresses")); |
b99bd4ef | 8649 | |
c19d1205 ZW |
8650 | inst.instruction |= inst.operands[i].reg << 16; |
8651 | if (inst.operands[i].immisreg) | |
b99bd4ef | 8652 | { |
c19d1205 ZW |
8653 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
8654 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
8655 | constraint (inst.operands[i].negative, | |
8656 | _("Thumb does not support negative register indexing")); | |
8657 | constraint (inst.operands[i].postind, | |
8658 | _("Thumb does not support register post-indexing")); | |
8659 | constraint (inst.operands[i].writeback, | |
8660 | _("Thumb does not support register indexing with writeback")); | |
8661 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
8662 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 8663 | |
f40d1643 | 8664 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 8665 | if (inst.operands[i].shifted) |
b99bd4ef | 8666 | { |
c19d1205 ZW |
8667 | constraint (inst.reloc.exp.X_op != O_constant, |
8668 | _("expression too complex")); | |
9c3c69f2 PB |
8669 | constraint (inst.reloc.exp.X_add_number < 0 |
8670 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 8671 | _("shift out of range")); |
9c3c69f2 | 8672 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
8673 | } |
8674 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8675 | } | |
8676 | else if (inst.operands[i].preind) | |
8677 | { | |
8678 | constraint (is_pc && inst.operands[i].writeback, | |
8679 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 8680 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
8681 | _("cannot use writeback with this instruction")); |
8682 | ||
8683 | if (is_d) | |
8684 | { | |
8685 | inst.instruction |= 0x01000000; | |
8686 | if (inst.operands[i].writeback) | |
8687 | inst.instruction |= 0x00200000; | |
b99bd4ef | 8688 | } |
c19d1205 | 8689 | else |
b99bd4ef | 8690 | { |
c19d1205 ZW |
8691 | inst.instruction |= 0x00000c00; |
8692 | if (inst.operands[i].writeback) | |
8693 | inst.instruction |= 0x00000100; | |
b99bd4ef | 8694 | } |
c19d1205 | 8695 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 8696 | } |
c19d1205 | 8697 | else if (inst.operands[i].postind) |
b99bd4ef | 8698 | { |
9c2799c2 | 8699 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
8700 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
8701 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
8702 | ||
8703 | if (is_d) | |
8704 | inst.instruction |= 0x00200000; | |
8705 | else | |
8706 | inst.instruction |= 0x00000900; | |
8707 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
8708 | } | |
8709 | else /* unindexed - only for coprocessor */ | |
8710 | inst.error = _("instruction does not accept unindexed addressing"); | |
8711 | } | |
8712 | ||
8713 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
8714 | encodings (the latter only in post-V6T2 cores). The index is the | |
8715 | value used in the insns table below. When there is more than one | |
8716 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
8717 | holds variant (1). |
8718 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 ZW |
8719 | #define T16_32_TAB \ |
8720 | X(adc, 4140, eb400000), \ | |
8721 | X(adcs, 4140, eb500000), \ | |
8722 | X(add, 1c00, eb000000), \ | |
8723 | X(adds, 1c00, eb100000), \ | |
0110f2b8 PB |
8724 | X(addi, 0000, f1000000), \ |
8725 | X(addis, 0000, f1100000), \ | |
8726 | X(add_pc,000f, f20f0000), \ | |
8727 | X(add_sp,000d, f10d0000), \ | |
e9f89963 | 8728 | X(adr, 000f, f20f0000), \ |
c19d1205 ZW |
8729 | X(and, 4000, ea000000), \ |
8730 | X(ands, 4000, ea100000), \ | |
8731 | X(asr, 1000, fa40f000), \ | |
8732 | X(asrs, 1000, fa50f000), \ | |
0110f2b8 PB |
8733 | X(b, e000, f000b000), \ |
8734 | X(bcond, d000, f0008000), \ | |
c19d1205 ZW |
8735 | X(bic, 4380, ea200000), \ |
8736 | X(bics, 4380, ea300000), \ | |
8737 | X(cmn, 42c0, eb100f00), \ | |
8738 | X(cmp, 2800, ebb00f00), \ | |
8739 | X(cpsie, b660, f3af8400), \ | |
8740 | X(cpsid, b670, f3af8600), \ | |
8741 | X(cpy, 4600, ea4f0000), \ | |
155257ea | 8742 | X(dec_sp,80dd, f1ad0d00), \ |
c19d1205 ZW |
8743 | X(eor, 4040, ea800000), \ |
8744 | X(eors, 4040, ea900000), \ | |
0110f2b8 | 8745 | X(inc_sp,00dd, f10d0d00), \ |
c19d1205 ZW |
8746 | X(ldmia, c800, e8900000), \ |
8747 | X(ldr, 6800, f8500000), \ | |
8748 | X(ldrb, 7800, f8100000), \ | |
8749 | X(ldrh, 8800, f8300000), \ | |
8750 | X(ldrsb, 5600, f9100000), \ | |
8751 | X(ldrsh, 5e00, f9300000), \ | |
0110f2b8 PB |
8752 | X(ldr_pc,4800, f85f0000), \ |
8753 | X(ldr_pc2,4800, f85f0000), \ | |
8754 | X(ldr_sp,9800, f85d0000), \ | |
c19d1205 ZW |
8755 | X(lsl, 0000, fa00f000), \ |
8756 | X(lsls, 0000, fa10f000), \ | |
8757 | X(lsr, 0800, fa20f000), \ | |
8758 | X(lsrs, 0800, fa30f000), \ | |
8759 | X(mov, 2000, ea4f0000), \ | |
8760 | X(movs, 2000, ea5f0000), \ | |
8761 | X(mul, 4340, fb00f000), \ | |
8762 | X(muls, 4340, ffffffff), /* no 32b muls */ \ | |
8763 | X(mvn, 43c0, ea6f0000), \ | |
8764 | X(mvns, 43c0, ea7f0000), \ | |
8765 | X(neg, 4240, f1c00000), /* rsb #0 */ \ | |
8766 | X(negs, 4240, f1d00000), /* rsbs #0 */ \ | |
8767 | X(orr, 4300, ea400000), \ | |
8768 | X(orrs, 4300, ea500000), \ | |
e9f89963 PB |
8769 | X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \ |
8770 | X(push, b400, e92d0000), /* stmdb sp!,... */ \ | |
c19d1205 ZW |
8771 | X(rev, ba00, fa90f080), \ |
8772 | X(rev16, ba40, fa90f090), \ | |
8773 | X(revsh, bac0, fa90f0b0), \ | |
8774 | X(ror, 41c0, fa60f000), \ | |
8775 | X(rors, 41c0, fa70f000), \ | |
8776 | X(sbc, 4180, eb600000), \ | |
8777 | X(sbcs, 4180, eb700000), \ | |
8778 | X(stmia, c000, e8800000), \ | |
8779 | X(str, 6000, f8400000), \ | |
8780 | X(strb, 7000, f8000000), \ | |
8781 | X(strh, 8000, f8200000), \ | |
0110f2b8 | 8782 | X(str_sp,9000, f84d0000), \ |
c19d1205 ZW |
8783 | X(sub, 1e00, eba00000), \ |
8784 | X(subs, 1e00, ebb00000), \ | |
0110f2b8 PB |
8785 | X(subi, 8000, f1a00000), \ |
8786 | X(subis, 8000, f1b00000), \ | |
c19d1205 ZW |
8787 | X(sxtb, b240, fa4ff080), \ |
8788 | X(sxth, b200, fa0ff080), \ | |
8789 | X(tst, 4200, ea100f00), \ | |
8790 | X(uxtb, b2c0, fa5ff080), \ | |
8791 | X(uxth, b280, fa1ff080), \ | |
8792 | X(nop, bf00, f3af8000), \ | |
8793 | X(yield, bf10, f3af8001), \ | |
8794 | X(wfe, bf20, f3af8002), \ | |
8795 | X(wfi, bf30, f3af8003), \ | |
c921be7d | 8796 | X(sev, bf40, f3af8004), |
c19d1205 ZW |
8797 | |
8798 | /* To catch errors in encoding functions, the codes are all offset by | |
8799 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
8800 | as 16-bit instructions. */ | |
8801 | #define X(a,b,c) T_MNEM_##a | |
8802 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; | |
8803 | #undef X | |
8804 | ||
8805 | #define X(a,b,c) 0x##b | |
8806 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
8807 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
8808 | #undef X | |
8809 | ||
8810 | #define X(a,b,c) 0x##c | |
8811 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
8812 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
8813 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
8814 | #undef X |
8815 | #undef T16_32_TAB | |
8816 | ||
8817 | /* Thumb instruction encoders, in alphabetical order. */ | |
8818 | ||
92e90b6e | 8819 | /* ADDW or SUBW. */ |
c921be7d | 8820 | |
92e90b6e PB |
8821 | static void |
8822 | do_t_add_sub_w (void) | |
8823 | { | |
8824 | int Rd, Rn; | |
8825 | ||
8826 | Rd = inst.operands[0].reg; | |
8827 | Rn = inst.operands[1].reg; | |
8828 | ||
539d4391 NC |
8829 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
8830 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
8831 | if (Rn == REG_SP) | |
8832 | constraint (Rd == REG_PC, BAD_PC); | |
8833 | else | |
8834 | reject_bad_reg (Rd); | |
fdfde340 | 8835 | |
92e90b6e PB |
8836 | inst.instruction |= (Rn << 16) | (Rd << 8); |
8837 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8838 | } | |
8839 | ||
c19d1205 ZW |
8840 | /* Parse an add or subtract instruction. We get here with inst.instruction |
8841 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
8842 | ||
8843 | static void | |
8844 | do_t_add_sub (void) | |
8845 | { | |
8846 | int Rd, Rs, Rn; | |
8847 | ||
8848 | Rd = inst.operands[0].reg; | |
8849 | Rs = (inst.operands[1].present | |
8850 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8851 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8852 | ||
e07e6e58 NC |
8853 | if (Rd == REG_PC) |
8854 | set_it_insn_type_last (); | |
8855 | ||
c19d1205 ZW |
8856 | if (unified_syntax) |
8857 | { | |
0110f2b8 PB |
8858 | bfd_boolean flags; |
8859 | bfd_boolean narrow; | |
8860 | int opcode; | |
8861 | ||
8862 | flags = (inst.instruction == T_MNEM_adds | |
8863 | || inst.instruction == T_MNEM_subs); | |
8864 | if (flags) | |
e07e6e58 | 8865 | narrow = !in_it_block (); |
0110f2b8 | 8866 | else |
e07e6e58 | 8867 | narrow = in_it_block (); |
c19d1205 | 8868 | if (!inst.operands[2].isreg) |
b99bd4ef | 8869 | { |
16805f35 PB |
8870 | int add; |
8871 | ||
fdfde340 JM |
8872 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
8873 | ||
16805f35 PB |
8874 | add = (inst.instruction == T_MNEM_add |
8875 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
8876 | opcode = 0; |
8877 | if (inst.size_req != 4) | |
8878 | { | |
0110f2b8 PB |
8879 | /* Attempt to use a narrow opcode, with relaxation if |
8880 | appropriate. */ | |
8881 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
8882 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
8883 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
8884 | opcode = T_MNEM_add_sp; | |
8885 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
8886 | opcode = T_MNEM_add_pc; | |
8887 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
8888 | { | |
8889 | if (flags) | |
8890 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
8891 | else | |
8892 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
8893 | } | |
8894 | if (opcode) | |
8895 | { | |
8896 | inst.instruction = THUMB_OP16(opcode); | |
8897 | inst.instruction |= (Rd << 4) | Rs; | |
8898 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8899 | if (inst.size_req != 2) | |
8900 | inst.relax = opcode; | |
8901 | } | |
8902 | else | |
8903 | constraint (inst.size_req == 2, BAD_HIREG); | |
8904 | } | |
8905 | if (inst.size_req == 4 | |
8906 | || (inst.size_req != 2 && !opcode)) | |
8907 | { | |
efd81785 PB |
8908 | if (Rd == REG_PC) |
8909 | { | |
fdfde340 | 8910 | constraint (add, BAD_PC); |
efd81785 PB |
8911 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
8912 | _("only SUBS PC, LR, #const allowed")); | |
8913 | constraint (inst.reloc.exp.X_op != O_constant, | |
8914 | _("expression too complex")); | |
8915 | constraint (inst.reloc.exp.X_add_number < 0 | |
8916 | || inst.reloc.exp.X_add_number > 0xff, | |
8917 | _("immediate value out of range")); | |
8918 | inst.instruction = T2_SUBS_PC_LR | |
8919 | | inst.reloc.exp.X_add_number; | |
8920 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8921 | return; | |
8922 | } | |
8923 | else if (Rs == REG_PC) | |
16805f35 PB |
8924 | { |
8925 | /* Always use addw/subw. */ | |
8926 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
8927 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8928 | } | |
8929 | else | |
8930 | { | |
8931 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8932 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
8933 | | 0x10000000; | |
8934 | if (flags) | |
8935 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8936 | else | |
8937 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
8938 | } | |
dc4503c6 PB |
8939 | inst.instruction |= Rd << 8; |
8940 | inst.instruction |= Rs << 16; | |
0110f2b8 | 8941 | } |
b99bd4ef | 8942 | } |
c19d1205 ZW |
8943 | else |
8944 | { | |
8945 | Rn = inst.operands[2].reg; | |
8946 | /* See if we can do this with a 16-bit instruction. */ | |
8947 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
8948 | { | |
e27ec89e PB |
8949 | if (Rd > 7 || Rs > 7 || Rn > 7) |
8950 | narrow = FALSE; | |
8951 | ||
8952 | if (narrow) | |
c19d1205 | 8953 | { |
e27ec89e PB |
8954 | inst.instruction = ((inst.instruction == T_MNEM_adds |
8955 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
8956 | ? T_OPCODE_ADD_R3 |
8957 | : T_OPCODE_SUB_R3); | |
8958 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
8959 | return; | |
8960 | } | |
b99bd4ef | 8961 | |
7e806470 | 8962 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 8963 | { |
7e806470 PB |
8964 | /* Thumb-1 cores (except v6-M) require at least one high |
8965 | register in a narrow non flag setting add. */ | |
8966 | if (Rd > 7 || Rn > 7 | |
8967 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
8968 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 8969 | { |
7e806470 PB |
8970 | if (Rd == Rn) |
8971 | { | |
8972 | Rn = Rs; | |
8973 | Rs = Rd; | |
8974 | } | |
c19d1205 ZW |
8975 | inst.instruction = T_OPCODE_ADD_HI; |
8976 | inst.instruction |= (Rd & 8) << 4; | |
8977 | inst.instruction |= (Rd & 7); | |
8978 | inst.instruction |= Rn << 3; | |
8979 | return; | |
8980 | } | |
c19d1205 ZW |
8981 | } |
8982 | } | |
c921be7d | 8983 | |
fdfde340 JM |
8984 | constraint (Rd == REG_PC, BAD_PC); |
8985 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
8986 | constraint (Rs == REG_PC, BAD_PC); | |
8987 | reject_bad_reg (Rn); | |
8988 | ||
c19d1205 ZW |
8989 | /* If we get here, it can't be done in 16 bits. */ |
8990 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
8991 | _("shift must be constant")); | |
8992 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8993 | inst.instruction |= Rd << 8; | |
8994 | inst.instruction |= Rs << 16; | |
8995 | encode_thumb32_shifted_operand (2); | |
8996 | } | |
8997 | } | |
8998 | else | |
8999 | { | |
9000 | constraint (inst.instruction == T_MNEM_adds | |
9001 | || inst.instruction == T_MNEM_subs, | |
9002 | BAD_THUMB32); | |
b99bd4ef | 9003 | |
c19d1205 | 9004 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 9005 | { |
c19d1205 ZW |
9006 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
9007 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
9008 | BAD_HIREG); | |
9009 | ||
9010 | inst.instruction = (inst.instruction == T_MNEM_add | |
9011 | ? 0x0000 : 0x8000); | |
9012 | inst.instruction |= (Rd << 4) | Rs; | |
9013 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
9014 | return; |
9015 | } | |
9016 | ||
c19d1205 ZW |
9017 | Rn = inst.operands[2].reg; |
9018 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 9019 | |
c19d1205 ZW |
9020 | /* We now have Rd, Rs, and Rn set to registers. */ |
9021 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 9022 | { |
c19d1205 ZW |
9023 | /* Can't do this for SUB. */ |
9024 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
9025 | inst.instruction = T_OPCODE_ADD_HI; | |
9026 | inst.instruction |= (Rd & 8) << 4; | |
9027 | inst.instruction |= (Rd & 7); | |
9028 | if (Rs == Rd) | |
9029 | inst.instruction |= Rn << 3; | |
9030 | else if (Rn == Rd) | |
9031 | inst.instruction |= Rs << 3; | |
9032 | else | |
9033 | constraint (1, _("dest must overlap one source register")); | |
9034 | } | |
9035 | else | |
9036 | { | |
9037 | inst.instruction = (inst.instruction == T_MNEM_add | |
9038 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
9039 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 9040 | } |
b99bd4ef | 9041 | } |
b99bd4ef NC |
9042 | } |
9043 | ||
c19d1205 ZW |
9044 | static void |
9045 | do_t_adr (void) | |
9046 | { | |
fdfde340 JM |
9047 | unsigned Rd; |
9048 | ||
9049 | Rd = inst.operands[0].reg; | |
9050 | reject_bad_reg (Rd); | |
9051 | ||
9052 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
9053 | { |
9054 | /* Defer to section relaxation. */ | |
9055 | inst.relax = inst.instruction; | |
9056 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 9057 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
9058 | } |
9059 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 9060 | { |
0110f2b8 | 9061 | /* Generate a 32-bit opcode. */ |
e9f89963 | 9062 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 9063 | inst.instruction |= Rd << 8; |
e9f89963 PB |
9064 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
9065 | inst.reloc.pc_rel = 1; | |
9066 | } | |
9067 | else | |
9068 | { | |
0110f2b8 | 9069 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
9070 | inst.instruction = THUMB_OP16 (inst.instruction); |
9071 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
9072 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
9073 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 9074 | |
fdfde340 | 9075 | inst.instruction |= Rd << 4; |
e9f89963 | 9076 | } |
c19d1205 | 9077 | } |
b99bd4ef | 9078 | |
c19d1205 ZW |
9079 | /* Arithmetic instructions for which there is just one 16-bit |
9080 | instruction encoding, and it allows only two low registers. | |
9081 | For maximal compatibility with ARM syntax, we allow three register | |
9082 | operands even when Thumb-32 instructions are not available, as long | |
9083 | as the first two are identical. For instance, both "sbc r0,r1" and | |
9084 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 9085 | static void |
c19d1205 | 9086 | do_t_arit3 (void) |
b99bd4ef | 9087 | { |
c19d1205 | 9088 | int Rd, Rs, Rn; |
b99bd4ef | 9089 | |
c19d1205 ZW |
9090 | Rd = inst.operands[0].reg; |
9091 | Rs = (inst.operands[1].present | |
9092 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9093 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9094 | Rn = inst.operands[2].reg; | |
b99bd4ef | 9095 | |
fdfde340 JM |
9096 | reject_bad_reg (Rd); |
9097 | reject_bad_reg (Rs); | |
9098 | if (inst.operands[2].isreg) | |
9099 | reject_bad_reg (Rn); | |
9100 | ||
c19d1205 | 9101 | if (unified_syntax) |
b99bd4ef | 9102 | { |
c19d1205 ZW |
9103 | if (!inst.operands[2].isreg) |
9104 | { | |
9105 | /* For an immediate, we always generate a 32-bit opcode; | |
9106 | section relaxation will shrink it later if possible. */ | |
9107 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9108 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9109 | inst.instruction |= Rd << 8; | |
9110 | inst.instruction |= Rs << 16; | |
9111 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9112 | } | |
9113 | else | |
9114 | { | |
e27ec89e PB |
9115 | bfd_boolean narrow; |
9116 | ||
c19d1205 | 9117 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9118 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9119 | narrow = !in_it_block (); |
e27ec89e | 9120 | else |
e07e6e58 | 9121 | narrow = in_it_block (); |
e27ec89e PB |
9122 | |
9123 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9124 | narrow = FALSE; | |
9125 | if (inst.operands[2].shifted) | |
9126 | narrow = FALSE; | |
9127 | if (inst.size_req == 4) | |
9128 | narrow = FALSE; | |
9129 | ||
9130 | if (narrow | |
c19d1205 ZW |
9131 | && Rd == Rs) |
9132 | { | |
9133 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9134 | inst.instruction |= Rd; | |
9135 | inst.instruction |= Rn << 3; | |
9136 | return; | |
9137 | } | |
b99bd4ef | 9138 | |
c19d1205 ZW |
9139 | /* If we get here, it can't be done in 16 bits. */ |
9140 | constraint (inst.operands[2].shifted | |
9141 | && inst.operands[2].immisreg, | |
9142 | _("shift must be constant")); | |
9143 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9144 | inst.instruction |= Rd << 8; | |
9145 | inst.instruction |= Rs << 16; | |
9146 | encode_thumb32_shifted_operand (2); | |
9147 | } | |
a737bd4d | 9148 | } |
c19d1205 | 9149 | else |
b99bd4ef | 9150 | { |
c19d1205 ZW |
9151 | /* On its face this is a lie - the instruction does set the |
9152 | flags. However, the only supported mnemonic in this mode | |
9153 | says it doesn't. */ | |
9154 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9155 | |
c19d1205 ZW |
9156 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9157 | _("unshifted register required")); | |
9158 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9159 | constraint (Rd != Rs, | |
9160 | _("dest and source1 must be the same register")); | |
a737bd4d | 9161 | |
c19d1205 ZW |
9162 | inst.instruction = THUMB_OP16 (inst.instruction); |
9163 | inst.instruction |= Rd; | |
9164 | inst.instruction |= Rn << 3; | |
b99bd4ef | 9165 | } |
a737bd4d | 9166 | } |
b99bd4ef | 9167 | |
c19d1205 ZW |
9168 | /* Similarly, but for instructions where the arithmetic operation is |
9169 | commutative, so we can allow either of them to be different from | |
9170 | the destination operand in a 16-bit instruction. For instance, all | |
9171 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
9172 | accepted. */ | |
9173 | static void | |
9174 | do_t_arit3c (void) | |
a737bd4d | 9175 | { |
c19d1205 | 9176 | int Rd, Rs, Rn; |
b99bd4ef | 9177 | |
c19d1205 ZW |
9178 | Rd = inst.operands[0].reg; |
9179 | Rs = (inst.operands[1].present | |
9180 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9181 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9182 | Rn = inst.operands[2].reg; | |
c921be7d | 9183 | |
fdfde340 JM |
9184 | reject_bad_reg (Rd); |
9185 | reject_bad_reg (Rs); | |
9186 | if (inst.operands[2].isreg) | |
9187 | reject_bad_reg (Rn); | |
a737bd4d | 9188 | |
c19d1205 | 9189 | if (unified_syntax) |
a737bd4d | 9190 | { |
c19d1205 | 9191 | if (!inst.operands[2].isreg) |
b99bd4ef | 9192 | { |
c19d1205 ZW |
9193 | /* For an immediate, we always generate a 32-bit opcode; |
9194 | section relaxation will shrink it later if possible. */ | |
9195 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9196 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9197 | inst.instruction |= Rd << 8; | |
9198 | inst.instruction |= Rs << 16; | |
9199 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 9200 | } |
c19d1205 | 9201 | else |
a737bd4d | 9202 | { |
e27ec89e PB |
9203 | bfd_boolean narrow; |
9204 | ||
c19d1205 | 9205 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9206 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9207 | narrow = !in_it_block (); |
e27ec89e | 9208 | else |
e07e6e58 | 9209 | narrow = in_it_block (); |
e27ec89e PB |
9210 | |
9211 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9212 | narrow = FALSE; | |
9213 | if (inst.operands[2].shifted) | |
9214 | narrow = FALSE; | |
9215 | if (inst.size_req == 4) | |
9216 | narrow = FALSE; | |
9217 | ||
9218 | if (narrow) | |
a737bd4d | 9219 | { |
c19d1205 | 9220 | if (Rd == Rs) |
a737bd4d | 9221 | { |
c19d1205 ZW |
9222 | inst.instruction = THUMB_OP16 (inst.instruction); |
9223 | inst.instruction |= Rd; | |
9224 | inst.instruction |= Rn << 3; | |
9225 | return; | |
a737bd4d | 9226 | } |
c19d1205 | 9227 | if (Rd == Rn) |
a737bd4d | 9228 | { |
c19d1205 ZW |
9229 | inst.instruction = THUMB_OP16 (inst.instruction); |
9230 | inst.instruction |= Rd; | |
9231 | inst.instruction |= Rs << 3; | |
9232 | return; | |
a737bd4d NC |
9233 | } |
9234 | } | |
c19d1205 ZW |
9235 | |
9236 | /* If we get here, it can't be done in 16 bits. */ | |
9237 | constraint (inst.operands[2].shifted | |
9238 | && inst.operands[2].immisreg, | |
9239 | _("shift must be constant")); | |
9240 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9241 | inst.instruction |= Rd << 8; | |
9242 | inst.instruction |= Rs << 16; | |
9243 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 9244 | } |
b99bd4ef | 9245 | } |
c19d1205 ZW |
9246 | else |
9247 | { | |
9248 | /* On its face this is a lie - the instruction does set the | |
9249 | flags. However, the only supported mnemonic in this mode | |
9250 | says it doesn't. */ | |
9251 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9252 | |
c19d1205 ZW |
9253 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9254 | _("unshifted register required")); | |
9255 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9256 | ||
9257 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9258 | inst.instruction |= Rd; | |
9259 | ||
9260 | if (Rd == Rs) | |
9261 | inst.instruction |= Rn << 3; | |
9262 | else if (Rd == Rn) | |
9263 | inst.instruction |= Rs << 3; | |
9264 | else | |
9265 | constraint (1, _("dest must overlap one source register")); | |
9266 | } | |
a737bd4d NC |
9267 | } |
9268 | ||
62b3e311 PB |
9269 | static void |
9270 | do_t_barrier (void) | |
9271 | { | |
9272 | if (inst.operands[0].present) | |
9273 | { | |
9274 | constraint ((inst.instruction & 0xf0) != 0x40 | |
9275 | && inst.operands[0].imm != 0xf, | |
bd3ba5d1 | 9276 | _("bad barrier type")); |
62b3e311 PB |
9277 | inst.instruction |= inst.operands[0].imm; |
9278 | } | |
9279 | else | |
9280 | inst.instruction |= 0xf; | |
9281 | } | |
9282 | ||
c19d1205 ZW |
9283 | static void |
9284 | do_t_bfc (void) | |
a737bd4d | 9285 | { |
fdfde340 | 9286 | unsigned Rd; |
c19d1205 ZW |
9287 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
9288 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9289 | /* The instruction encoding stores the LSB and MSB, | |
9290 | not the LSB and width. */ | |
fdfde340 JM |
9291 | Rd = inst.operands[0].reg; |
9292 | reject_bad_reg (Rd); | |
9293 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
9294 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
9295 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
9296 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9297 | } |
9298 | ||
c19d1205 ZW |
9299 | static void |
9300 | do_t_bfi (void) | |
b99bd4ef | 9301 | { |
fdfde340 | 9302 | int Rd, Rn; |
c19d1205 | 9303 | unsigned int msb; |
b99bd4ef | 9304 | |
fdfde340 JM |
9305 | Rd = inst.operands[0].reg; |
9306 | reject_bad_reg (Rd); | |
9307 | ||
c19d1205 ZW |
9308 | /* #0 in second position is alternative syntax for bfc, which is |
9309 | the same instruction but with REG_PC in the Rm field. */ | |
9310 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
9311 | Rn = REG_PC; |
9312 | else | |
9313 | { | |
9314 | Rn = inst.operands[1].reg; | |
9315 | reject_bad_reg (Rn); | |
9316 | } | |
b99bd4ef | 9317 | |
c19d1205 ZW |
9318 | msb = inst.operands[2].imm + inst.operands[3].imm; |
9319 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9320 | /* The instruction encoding stores the LSB and MSB, | |
9321 | not the LSB and width. */ | |
fdfde340 JM |
9322 | inst.instruction |= Rd << 8; |
9323 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9324 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9325 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9326 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9327 | } |
9328 | ||
c19d1205 ZW |
9329 | static void |
9330 | do_t_bfx (void) | |
b99bd4ef | 9331 | { |
fdfde340 JM |
9332 | unsigned Rd, Rn; |
9333 | ||
9334 | Rd = inst.operands[0].reg; | |
9335 | Rn = inst.operands[1].reg; | |
9336 | ||
9337 | reject_bad_reg (Rd); | |
9338 | reject_bad_reg (Rn); | |
9339 | ||
c19d1205 ZW |
9340 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
9341 | _("bit-field extends past end of register")); | |
fdfde340 JM |
9342 | inst.instruction |= Rd << 8; |
9343 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9344 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9345 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9346 | inst.instruction |= inst.operands[3].imm - 1; | |
9347 | } | |
b99bd4ef | 9348 | |
c19d1205 ZW |
9349 | /* ARM V5 Thumb BLX (argument parse) |
9350 | BLX <target_addr> which is BLX(1) | |
9351 | BLX <Rm> which is BLX(2) | |
9352 | Unfortunately, there are two different opcodes for this mnemonic. | |
9353 | So, the insns[].value is not used, and the code here zaps values | |
9354 | into inst.instruction. | |
b99bd4ef | 9355 | |
c19d1205 ZW |
9356 | ??? How to take advantage of the additional two bits of displacement |
9357 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 9358 | |
c19d1205 ZW |
9359 | static void |
9360 | do_t_blx (void) | |
9361 | { | |
e07e6e58 NC |
9362 | set_it_insn_type_last (); |
9363 | ||
c19d1205 | 9364 | if (inst.operands[0].isreg) |
fdfde340 JM |
9365 | { |
9366 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
9367 | /* We have a register, so this is BLX(2). */ | |
9368 | inst.instruction |= inst.operands[0].reg << 3; | |
9369 | } | |
b99bd4ef NC |
9370 | else |
9371 | { | |
c19d1205 | 9372 | /* No register. This must be BLX(1). */ |
2fc8bdac | 9373 | inst.instruction = 0xf000e800; |
00adf2d4 | 9374 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; |
c19d1205 | 9375 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
9376 | } |
9377 | } | |
9378 | ||
c19d1205 ZW |
9379 | static void |
9380 | do_t_branch (void) | |
b99bd4ef | 9381 | { |
0110f2b8 | 9382 | int opcode; |
dfa9f0d5 PB |
9383 | int cond; |
9384 | ||
e07e6e58 NC |
9385 | cond = inst.cond; |
9386 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
9387 | ||
9388 | if (in_it_block ()) | |
dfa9f0d5 PB |
9389 | { |
9390 | /* Conditional branches inside IT blocks are encoded as unconditional | |
9391 | branches. */ | |
9392 | cond = COND_ALWAYS; | |
dfa9f0d5 PB |
9393 | } |
9394 | else | |
9395 | cond = inst.cond; | |
9396 | ||
9397 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
9398 | opcode = T_MNEM_bcond; |
9399 | else | |
9400 | opcode = inst.instruction; | |
9401 | ||
9402 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 9403 | { |
0110f2b8 | 9404 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 9405 | if (cond == COND_ALWAYS) |
0110f2b8 | 9406 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
9407 | else |
9408 | { | |
9c2799c2 | 9409 | gas_assert (cond != 0xF); |
dfa9f0d5 | 9410 | inst.instruction |= cond << 22; |
c19d1205 ZW |
9411 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
9412 | } | |
9413 | } | |
b99bd4ef NC |
9414 | else |
9415 | { | |
0110f2b8 | 9416 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 9417 | if (cond == COND_ALWAYS) |
c19d1205 ZW |
9418 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; |
9419 | else | |
b99bd4ef | 9420 | { |
dfa9f0d5 | 9421 | inst.instruction |= cond << 8; |
c19d1205 | 9422 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 9423 | } |
0110f2b8 PB |
9424 | /* Allow section relaxation. */ |
9425 | if (unified_syntax && inst.size_req != 2) | |
9426 | inst.relax = opcode; | |
b99bd4ef | 9427 | } |
c19d1205 ZW |
9428 | |
9429 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
9430 | } |
9431 | ||
9432 | static void | |
c19d1205 | 9433 | do_t_bkpt (void) |
b99bd4ef | 9434 | { |
dfa9f0d5 PB |
9435 | constraint (inst.cond != COND_ALWAYS, |
9436 | _("instruction is always unconditional")); | |
c19d1205 | 9437 | if (inst.operands[0].present) |
b99bd4ef | 9438 | { |
c19d1205 ZW |
9439 | constraint (inst.operands[0].imm > 255, |
9440 | _("immediate value out of range")); | |
9441 | inst.instruction |= inst.operands[0].imm; | |
e07e6e58 | 9442 | set_it_insn_type (NEUTRAL_IT_INSN); |
b99bd4ef | 9443 | } |
b99bd4ef NC |
9444 | } |
9445 | ||
9446 | static void | |
c19d1205 | 9447 | do_t_branch23 (void) |
b99bd4ef | 9448 | { |
e07e6e58 | 9449 | set_it_insn_type_last (); |
c19d1205 | 9450 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
9451 | inst.reloc.pc_rel = 1; |
9452 | ||
4343666d | 9453 | #if defined(OBJ_COFF) |
c19d1205 ZW |
9454 | /* If the destination of the branch is a defined symbol which does not have |
9455 | the THUMB_FUNC attribute, then we must be calling a function which has | |
9456 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
9457 | function and change the branch to refer to that function instead. */ | |
9458 | if ( inst.reloc.exp.X_op == O_symbol | |
9459 | && inst.reloc.exp.X_add_symbol != NULL | |
9460 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
9461 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
9462 | inst.reloc.exp.X_add_symbol = | |
9463 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 9464 | #endif |
90e4755a RE |
9465 | } |
9466 | ||
9467 | static void | |
c19d1205 | 9468 | do_t_bx (void) |
90e4755a | 9469 | { |
e07e6e58 | 9470 | set_it_insn_type_last (); |
c19d1205 ZW |
9471 | inst.instruction |= inst.operands[0].reg << 3; |
9472 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
9473 | should cause the alignment to be checked once it is known. This is | |
9474 | because BX PC only works if the instruction is word aligned. */ | |
9475 | } | |
90e4755a | 9476 | |
c19d1205 ZW |
9477 | static void |
9478 | do_t_bxj (void) | |
9479 | { | |
fdfde340 | 9480 | int Rm; |
90e4755a | 9481 | |
e07e6e58 | 9482 | set_it_insn_type_last (); |
fdfde340 JM |
9483 | Rm = inst.operands[0].reg; |
9484 | reject_bad_reg (Rm); | |
9485 | inst.instruction |= Rm << 16; | |
90e4755a RE |
9486 | } |
9487 | ||
9488 | static void | |
c19d1205 | 9489 | do_t_clz (void) |
90e4755a | 9490 | { |
fdfde340 JM |
9491 | unsigned Rd; |
9492 | unsigned Rm; | |
9493 | ||
9494 | Rd = inst.operands[0].reg; | |
9495 | Rm = inst.operands[1].reg; | |
9496 | ||
9497 | reject_bad_reg (Rd); | |
9498 | reject_bad_reg (Rm); | |
9499 | ||
9500 | inst.instruction |= Rd << 8; | |
9501 | inst.instruction |= Rm << 16; | |
9502 | inst.instruction |= Rm; | |
c19d1205 | 9503 | } |
90e4755a | 9504 | |
dfa9f0d5 PB |
9505 | static void |
9506 | do_t_cps (void) | |
9507 | { | |
e07e6e58 | 9508 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
9509 | inst.instruction |= inst.operands[0].imm; |
9510 | } | |
9511 | ||
c19d1205 ZW |
9512 | static void |
9513 | do_t_cpsi (void) | |
9514 | { | |
e07e6e58 | 9515 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 9516 | if (unified_syntax |
62b3e311 PB |
9517 | && (inst.operands[1].present || inst.size_req == 4) |
9518 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 9519 | { |
c19d1205 ZW |
9520 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
9521 | inst.instruction = 0xf3af8000; | |
9522 | inst.instruction |= imod << 9; | |
9523 | inst.instruction |= inst.operands[0].imm << 5; | |
9524 | if (inst.operands[1].present) | |
9525 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 9526 | } |
c19d1205 | 9527 | else |
90e4755a | 9528 | { |
62b3e311 PB |
9529 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
9530 | && (inst.operands[0].imm & 4), | |
9531 | _("selected processor does not support 'A' form " | |
9532 | "of this instruction")); | |
9533 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
9534 | _("Thumb does not support the 2-argument " |
9535 | "form of this instruction")); | |
9536 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 9537 | } |
90e4755a RE |
9538 | } |
9539 | ||
c19d1205 ZW |
9540 | /* THUMB CPY instruction (argument parse). */ |
9541 | ||
90e4755a | 9542 | static void |
c19d1205 | 9543 | do_t_cpy (void) |
90e4755a | 9544 | { |
c19d1205 | 9545 | if (inst.size_req == 4) |
90e4755a | 9546 | { |
c19d1205 ZW |
9547 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
9548 | inst.instruction |= inst.operands[0].reg << 8; | |
9549 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 9550 | } |
c19d1205 | 9551 | else |
90e4755a | 9552 | { |
c19d1205 ZW |
9553 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
9554 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9555 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 9556 | } |
90e4755a RE |
9557 | } |
9558 | ||
90e4755a | 9559 | static void |
25fe350b | 9560 | do_t_cbz (void) |
90e4755a | 9561 | { |
e07e6e58 | 9562 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
9563 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9564 | inst.instruction |= inst.operands[0].reg; | |
9565 | inst.reloc.pc_rel = 1; | |
9566 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
9567 | } | |
90e4755a | 9568 | |
62b3e311 PB |
9569 | static void |
9570 | do_t_dbg (void) | |
9571 | { | |
9572 | inst.instruction |= inst.operands[0].imm; | |
9573 | } | |
9574 | ||
9575 | static void | |
9576 | do_t_div (void) | |
9577 | { | |
fdfde340 JM |
9578 | unsigned Rd, Rn, Rm; |
9579 | ||
9580 | Rd = inst.operands[0].reg; | |
9581 | Rn = (inst.operands[1].present | |
9582 | ? inst.operands[1].reg : Rd); | |
9583 | Rm = inst.operands[2].reg; | |
9584 | ||
9585 | reject_bad_reg (Rd); | |
9586 | reject_bad_reg (Rn); | |
9587 | reject_bad_reg (Rm); | |
9588 | ||
9589 | inst.instruction |= Rd << 8; | |
9590 | inst.instruction |= Rn << 16; | |
9591 | inst.instruction |= Rm; | |
62b3e311 PB |
9592 | } |
9593 | ||
c19d1205 ZW |
9594 | static void |
9595 | do_t_hint (void) | |
9596 | { | |
9597 | if (unified_syntax && inst.size_req == 4) | |
9598 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9599 | else | |
9600 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9601 | } | |
90e4755a | 9602 | |
c19d1205 ZW |
9603 | static void |
9604 | do_t_it (void) | |
9605 | { | |
9606 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 9607 | |
e07e6e58 NC |
9608 | set_it_insn_type (IT_INSN); |
9609 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
9610 | now_it.cc = cond; | |
e27ec89e PB |
9611 | |
9612 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 9613 | if ((cond & 0x1) == 0x0) |
90e4755a | 9614 | { |
c19d1205 | 9615 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 9616 | |
c19d1205 ZW |
9617 | if ((mask & 0x7) == 0) |
9618 | /* no conversion needed */; | |
9619 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
9620 | mask ^= 0x8; |
9621 | else if ((mask & 0x1) == 0) | |
9622 | mask ^= 0xC; | |
c19d1205 | 9623 | else |
e27ec89e | 9624 | mask ^= 0xE; |
90e4755a | 9625 | |
e27ec89e PB |
9626 | inst.instruction &= 0xfff0; |
9627 | inst.instruction |= mask; | |
c19d1205 | 9628 | } |
90e4755a | 9629 | |
c19d1205 ZW |
9630 | inst.instruction |= cond << 4; |
9631 | } | |
90e4755a | 9632 | |
3c707909 PB |
9633 | /* Helper function used for both push/pop and ldm/stm. */ |
9634 | static void | |
9635 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
9636 | { | |
9637 | bfd_boolean load; | |
9638 | ||
9639 | load = (inst.instruction & (1 << 20)) != 0; | |
9640 | ||
9641 | if (mask & (1 << 13)) | |
9642 | inst.error = _("SP not allowed in register list"); | |
9643 | if (load) | |
9644 | { | |
e07e6e58 NC |
9645 | if (mask & (1 << 15)) |
9646 | { | |
9647 | if (mask & (1 << 14)) | |
9648 | inst.error = _("LR and PC should not both be in register list"); | |
9649 | else | |
9650 | set_it_insn_type_last (); | |
9651 | } | |
3c707909 PB |
9652 | |
9653 | if ((mask & (1 << base)) != 0 | |
9654 | && writeback) | |
9655 | as_warn (_("base register should not be in register list " | |
9656 | "when written back")); | |
9657 | } | |
9658 | else | |
9659 | { | |
9660 | if (mask & (1 << 15)) | |
9661 | inst.error = _("PC not allowed in register list"); | |
9662 | ||
9663 | if (mask & (1 << base)) | |
9664 | as_warn (_("value stored for r%d is UNPREDICTABLE"), base); | |
9665 | } | |
9666 | ||
9667 | if ((mask & (mask - 1)) == 0) | |
9668 | { | |
9669 | /* Single register transfers implemented as str/ldr. */ | |
9670 | if (writeback) | |
9671 | { | |
9672 | if (inst.instruction & (1 << 23)) | |
9673 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
9674 | else | |
9675 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
9676 | } | |
9677 | else | |
9678 | { | |
9679 | if (inst.instruction & (1 << 23)) | |
9680 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
9681 | else | |
9682 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
9683 | } | |
9684 | ||
9685 | inst.instruction |= 0xf8400000; | |
9686 | if (load) | |
9687 | inst.instruction |= 0x00100000; | |
9688 | ||
5f4273c7 | 9689 | mask = ffs (mask) - 1; |
3c707909 PB |
9690 | mask <<= 12; |
9691 | } | |
9692 | else if (writeback) | |
9693 | inst.instruction |= WRITE_BACK; | |
9694 | ||
9695 | inst.instruction |= mask; | |
9696 | inst.instruction |= base << 16; | |
9697 | } | |
9698 | ||
c19d1205 ZW |
9699 | static void |
9700 | do_t_ldmstm (void) | |
9701 | { | |
9702 | /* This really doesn't seem worth it. */ | |
9703 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9704 | _("expression too complex")); | |
9705 | constraint (inst.operands[1].writeback, | |
9706 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 9707 | |
c19d1205 ZW |
9708 | if (unified_syntax) |
9709 | { | |
3c707909 PB |
9710 | bfd_boolean narrow; |
9711 | unsigned mask; | |
9712 | ||
9713 | narrow = FALSE; | |
c19d1205 ZW |
9714 | /* See if we can use a 16-bit instruction. */ |
9715 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
9716 | && inst.size_req != 4 | |
3c707909 | 9717 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 9718 | { |
3c707909 | 9719 | mask = 1 << inst.operands[0].reg; |
90e4755a | 9720 | |
3c707909 PB |
9721 | if (inst.operands[0].reg <= 7 |
9722 | && (inst.instruction == T_MNEM_stmia | |
9723 | ? inst.operands[0].writeback | |
9724 | : (inst.operands[0].writeback | |
9725 | == !(inst.operands[1].imm & mask)))) | |
90e4755a | 9726 | { |
3c707909 PB |
9727 | if (inst.instruction == T_MNEM_stmia |
9728 | && (inst.operands[1].imm & mask) | |
9729 | && (inst.operands[1].imm & (mask - 1))) | |
c19d1205 ZW |
9730 | as_warn (_("value stored for r%d is UNPREDICTABLE"), |
9731 | inst.operands[0].reg); | |
3c707909 PB |
9732 | |
9733 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9734 | inst.instruction |= inst.operands[0].reg << 8; | |
9735 | inst.instruction |= inst.operands[1].imm; | |
9736 | narrow = TRUE; | |
90e4755a | 9737 | } |
3c707909 PB |
9738 | else if (inst.operands[0] .reg == REG_SP |
9739 | && inst.operands[0].writeback) | |
90e4755a | 9740 | { |
3c707909 PB |
9741 | inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia |
9742 | ? T_MNEM_push : T_MNEM_pop); | |
9743 | inst.instruction |= inst.operands[1].imm; | |
9744 | narrow = TRUE; | |
90e4755a | 9745 | } |
3c707909 PB |
9746 | } |
9747 | ||
9748 | if (!narrow) | |
9749 | { | |
c19d1205 ZW |
9750 | if (inst.instruction < 0xffff) |
9751 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 9752 | |
5f4273c7 NC |
9753 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
9754 | inst.operands[0].writeback); | |
90e4755a RE |
9755 | } |
9756 | } | |
c19d1205 | 9757 | else |
90e4755a | 9758 | { |
c19d1205 ZW |
9759 | constraint (inst.operands[0].reg > 7 |
9760 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
9761 | constraint (inst.instruction != T_MNEM_ldmia |
9762 | && inst.instruction != T_MNEM_stmia, | |
9763 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 9764 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 9765 | { |
c19d1205 ZW |
9766 | if (!inst.operands[0].writeback) |
9767 | as_warn (_("this instruction will write back the base register")); | |
9768 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9769 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
9770 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
9771 | inst.operands[0].reg); | |
f03698e6 | 9772 | } |
c19d1205 | 9773 | else |
90e4755a | 9774 | { |
c19d1205 ZW |
9775 | if (!inst.operands[0].writeback |
9776 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9777 | as_warn (_("this instruction will write back the base register")); | |
9778 | else if (inst.operands[0].writeback | |
9779 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9780 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
9781 | } |
9782 | ||
c19d1205 ZW |
9783 | inst.instruction = THUMB_OP16 (inst.instruction); |
9784 | inst.instruction |= inst.operands[0].reg << 8; | |
9785 | inst.instruction |= inst.operands[1].imm; | |
9786 | } | |
9787 | } | |
e28cd48c | 9788 | |
c19d1205 ZW |
9789 | static void |
9790 | do_t_ldrex (void) | |
9791 | { | |
9792 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
9793 | || inst.operands[1].postind || inst.operands[1].writeback | |
9794 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
9795 | || inst.operands[1].negative, | |
01cfc07f | 9796 | BAD_ADDR_MODE); |
e28cd48c | 9797 | |
c19d1205 ZW |
9798 | inst.instruction |= inst.operands[0].reg << 12; |
9799 | inst.instruction |= inst.operands[1].reg << 16; | |
9800 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
9801 | } | |
e28cd48c | 9802 | |
c19d1205 ZW |
9803 | static void |
9804 | do_t_ldrexd (void) | |
9805 | { | |
9806 | if (!inst.operands[1].present) | |
1cac9012 | 9807 | { |
c19d1205 ZW |
9808 | constraint (inst.operands[0].reg == REG_LR, |
9809 | _("r14 not allowed as first register " | |
9810 | "when second register is omitted")); | |
9811 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 9812 | } |
c19d1205 ZW |
9813 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
9814 | BAD_OVERLAP); | |
b99bd4ef | 9815 | |
c19d1205 ZW |
9816 | inst.instruction |= inst.operands[0].reg << 12; |
9817 | inst.instruction |= inst.operands[1].reg << 8; | |
9818 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9819 | } |
9820 | ||
9821 | static void | |
c19d1205 | 9822 | do_t_ldst (void) |
b99bd4ef | 9823 | { |
0110f2b8 PB |
9824 | unsigned long opcode; |
9825 | int Rn; | |
9826 | ||
e07e6e58 NC |
9827 | if (inst.operands[0].isreg |
9828 | && !inst.operands[0].preind | |
9829 | && inst.operands[0].reg == REG_PC) | |
9830 | set_it_insn_type_last (); | |
9831 | ||
0110f2b8 | 9832 | opcode = inst.instruction; |
c19d1205 | 9833 | if (unified_syntax) |
b99bd4ef | 9834 | { |
53365c0d PB |
9835 | if (!inst.operands[1].isreg) |
9836 | { | |
9837 | if (opcode <= 0xffff) | |
9838 | inst.instruction = THUMB_OP32 (opcode); | |
9839 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9840 | return; | |
9841 | } | |
0110f2b8 PB |
9842 | if (inst.operands[1].isreg |
9843 | && !inst.operands[1].writeback | |
c19d1205 ZW |
9844 | && !inst.operands[1].shifted && !inst.operands[1].postind |
9845 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
9846 | && opcode <= 0xffff |
9847 | && inst.size_req != 4) | |
c19d1205 | 9848 | { |
0110f2b8 PB |
9849 | /* Insn may have a 16-bit form. */ |
9850 | Rn = inst.operands[1].reg; | |
9851 | if (inst.operands[1].immisreg) | |
9852 | { | |
9853 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 9854 | /* [Rn, Rik] */ |
0110f2b8 PB |
9855 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
9856 | goto op16; | |
9857 | } | |
9858 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
9859 | && opcode != T_MNEM_ldrsb) | |
9860 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
9861 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
9862 | { | |
9863 | /* [Rn, #const] */ | |
9864 | if (Rn > 7) | |
9865 | { | |
9866 | if (Rn == REG_PC) | |
9867 | { | |
9868 | if (inst.reloc.pc_rel) | |
9869 | opcode = T_MNEM_ldr_pc2; | |
9870 | else | |
9871 | opcode = T_MNEM_ldr_pc; | |
9872 | } | |
9873 | else | |
9874 | { | |
9875 | if (opcode == T_MNEM_ldr) | |
9876 | opcode = T_MNEM_ldr_sp; | |
9877 | else | |
9878 | opcode = T_MNEM_str_sp; | |
9879 | } | |
9880 | inst.instruction = inst.operands[0].reg << 8; | |
9881 | } | |
9882 | else | |
9883 | { | |
9884 | inst.instruction = inst.operands[0].reg; | |
9885 | inst.instruction |= inst.operands[1].reg << 3; | |
9886 | } | |
9887 | inst.instruction |= THUMB_OP16 (opcode); | |
9888 | if (inst.size_req == 2) | |
9889 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9890 | else | |
9891 | inst.relax = opcode; | |
9892 | return; | |
9893 | } | |
c19d1205 | 9894 | } |
0110f2b8 PB |
9895 | /* Definitely a 32-bit variant. */ |
9896 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
9897 | inst.instruction |= inst.operands[0].reg << 12; |
9898 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
9899 | return; |
9900 | } | |
9901 | ||
c19d1205 ZW |
9902 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9903 | ||
9904 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 9905 | { |
c19d1205 ZW |
9906 | /* Only [Rn,Rm] is acceptable. */ |
9907 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
9908 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
9909 | || inst.operands[1].postind || inst.operands[1].shifted | |
9910 | || inst.operands[1].negative, | |
9911 | _("Thumb does not support this addressing mode")); | |
9912 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9913 | goto op16; | |
b99bd4ef | 9914 | } |
5f4273c7 | 9915 | |
c19d1205 ZW |
9916 | inst.instruction = THUMB_OP16 (inst.instruction); |
9917 | if (!inst.operands[1].isreg) | |
9918 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9919 | return; | |
b99bd4ef | 9920 | |
c19d1205 ZW |
9921 | constraint (!inst.operands[1].preind |
9922 | || inst.operands[1].shifted | |
9923 | || inst.operands[1].writeback, | |
9924 | _("Thumb does not support this addressing mode")); | |
9925 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 9926 | { |
c19d1205 ZW |
9927 | constraint (inst.instruction & 0x0600, |
9928 | _("byte or halfword not valid for base register")); | |
9929 | constraint (inst.operands[1].reg == REG_PC | |
9930 | && !(inst.instruction & THUMB_LOAD_BIT), | |
9931 | _("r15 based store not allowed")); | |
9932 | constraint (inst.operands[1].immisreg, | |
9933 | _("invalid base register for register offset")); | |
b99bd4ef | 9934 | |
c19d1205 ZW |
9935 | if (inst.operands[1].reg == REG_PC) |
9936 | inst.instruction = T_OPCODE_LDR_PC; | |
9937 | else if (inst.instruction & THUMB_LOAD_BIT) | |
9938 | inst.instruction = T_OPCODE_LDR_SP; | |
9939 | else | |
9940 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 9941 | |
c19d1205 ZW |
9942 | inst.instruction |= inst.operands[0].reg << 8; |
9943 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9944 | return; | |
9945 | } | |
90e4755a | 9946 | |
c19d1205 ZW |
9947 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
9948 | if (!inst.operands[1].immisreg) | |
9949 | { | |
9950 | /* Immediate offset. */ | |
9951 | inst.instruction |= inst.operands[0].reg; | |
9952 | inst.instruction |= inst.operands[1].reg << 3; | |
9953 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9954 | return; | |
9955 | } | |
90e4755a | 9956 | |
c19d1205 ZW |
9957 | /* Register offset. */ |
9958 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
9959 | constraint (inst.operands[1].negative, | |
9960 | _("Thumb does not support this addressing mode")); | |
90e4755a | 9961 | |
c19d1205 ZW |
9962 | op16: |
9963 | switch (inst.instruction) | |
9964 | { | |
9965 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
9966 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
9967 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
9968 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
9969 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
9970 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
9971 | case 0x5600 /* ldrsb */: | |
9972 | case 0x5e00 /* ldrsh */: break; | |
9973 | default: abort (); | |
9974 | } | |
90e4755a | 9975 | |
c19d1205 ZW |
9976 | inst.instruction |= inst.operands[0].reg; |
9977 | inst.instruction |= inst.operands[1].reg << 3; | |
9978 | inst.instruction |= inst.operands[1].imm << 6; | |
9979 | } | |
90e4755a | 9980 | |
c19d1205 ZW |
9981 | static void |
9982 | do_t_ldstd (void) | |
9983 | { | |
9984 | if (!inst.operands[1].present) | |
b99bd4ef | 9985 | { |
c19d1205 ZW |
9986 | inst.operands[1].reg = inst.operands[0].reg + 1; |
9987 | constraint (inst.operands[0].reg == REG_LR, | |
9988 | _("r14 not allowed here")); | |
b99bd4ef | 9989 | } |
c19d1205 ZW |
9990 | inst.instruction |= inst.operands[0].reg << 12; |
9991 | inst.instruction |= inst.operands[1].reg << 8; | |
9992 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
9993 | } |
9994 | ||
c19d1205 ZW |
9995 | static void |
9996 | do_t_ldstt (void) | |
9997 | { | |
9998 | inst.instruction |= inst.operands[0].reg << 12; | |
9999 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
10000 | } | |
a737bd4d | 10001 | |
b99bd4ef | 10002 | static void |
c19d1205 | 10003 | do_t_mla (void) |
b99bd4ef | 10004 | { |
fdfde340 | 10005 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 10006 | |
fdfde340 JM |
10007 | Rd = inst.operands[0].reg; |
10008 | Rn = inst.operands[1].reg; | |
10009 | Rm = inst.operands[2].reg; | |
10010 | Ra = inst.operands[3].reg; | |
10011 | ||
10012 | reject_bad_reg (Rd); | |
10013 | reject_bad_reg (Rn); | |
10014 | reject_bad_reg (Rm); | |
10015 | reject_bad_reg (Ra); | |
10016 | ||
10017 | inst.instruction |= Rd << 8; | |
10018 | inst.instruction |= Rn << 16; | |
10019 | inst.instruction |= Rm; | |
10020 | inst.instruction |= Ra << 12; | |
c19d1205 | 10021 | } |
b99bd4ef | 10022 | |
c19d1205 ZW |
10023 | static void |
10024 | do_t_mlal (void) | |
10025 | { | |
fdfde340 JM |
10026 | unsigned RdLo, RdHi, Rn, Rm; |
10027 | ||
10028 | RdLo = inst.operands[0].reg; | |
10029 | RdHi = inst.operands[1].reg; | |
10030 | Rn = inst.operands[2].reg; | |
10031 | Rm = inst.operands[3].reg; | |
10032 | ||
10033 | reject_bad_reg (RdLo); | |
10034 | reject_bad_reg (RdHi); | |
10035 | reject_bad_reg (Rn); | |
10036 | reject_bad_reg (Rm); | |
10037 | ||
10038 | inst.instruction |= RdLo << 12; | |
10039 | inst.instruction |= RdHi << 8; | |
10040 | inst.instruction |= Rn << 16; | |
10041 | inst.instruction |= Rm; | |
c19d1205 | 10042 | } |
b99bd4ef | 10043 | |
c19d1205 ZW |
10044 | static void |
10045 | do_t_mov_cmp (void) | |
10046 | { | |
fdfde340 JM |
10047 | unsigned Rn, Rm; |
10048 | ||
10049 | Rn = inst.operands[0].reg; | |
10050 | Rm = inst.operands[1].reg; | |
10051 | ||
e07e6e58 NC |
10052 | if (Rn == REG_PC) |
10053 | set_it_insn_type_last (); | |
10054 | ||
c19d1205 | 10055 | if (unified_syntax) |
b99bd4ef | 10056 | { |
c19d1205 ZW |
10057 | int r0off = (inst.instruction == T_MNEM_mov |
10058 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 10059 | unsigned long opcode; |
3d388997 PB |
10060 | bfd_boolean narrow; |
10061 | bfd_boolean low_regs; | |
10062 | ||
fdfde340 | 10063 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 10064 | opcode = inst.instruction; |
e07e6e58 | 10065 | if (in_it_block ()) |
0110f2b8 | 10066 | narrow = opcode != T_MNEM_movs; |
3d388997 | 10067 | else |
0110f2b8 | 10068 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
10069 | if (inst.size_req == 4 |
10070 | || inst.operands[1].shifted) | |
10071 | narrow = FALSE; | |
10072 | ||
efd81785 PB |
10073 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
10074 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
10075 | && !inst.operands[1].shifted | |
fdfde340 JM |
10076 | && Rn == REG_PC |
10077 | && Rm == REG_LR) | |
efd81785 PB |
10078 | { |
10079 | inst.instruction = T2_SUBS_PC_LR; | |
10080 | return; | |
10081 | } | |
10082 | ||
fdfde340 JM |
10083 | if (opcode == T_MNEM_cmp) |
10084 | { | |
10085 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
10086 | if (narrow) |
10087 | { | |
10088 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
10089 | but valid. */ | |
10090 | warn_deprecated_sp (Rm); | |
10091 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
10092 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
10093 | tools reject R15, so we do too. */ | |
10094 | constraint (Rm == REG_PC, BAD_PC); | |
10095 | } | |
10096 | else | |
10097 | reject_bad_reg (Rm); | |
fdfde340 JM |
10098 | } |
10099 | else if (opcode == T_MNEM_mov | |
10100 | || opcode == T_MNEM_movs) | |
10101 | { | |
10102 | if (inst.operands[1].isreg) | |
10103 | { | |
10104 | if (opcode == T_MNEM_movs) | |
10105 | { | |
10106 | reject_bad_reg (Rn); | |
10107 | reject_bad_reg (Rm); | |
10108 | } | |
10109 | else if ((Rn == REG_SP || Rn == REG_PC) | |
10110 | && (Rm == REG_SP || Rm == REG_PC)) | |
10111 | reject_bad_reg (Rm); | |
10112 | } | |
10113 | else | |
10114 | reject_bad_reg (Rn); | |
10115 | } | |
10116 | ||
c19d1205 ZW |
10117 | if (!inst.operands[1].isreg) |
10118 | { | |
0110f2b8 | 10119 | /* Immediate operand. */ |
e07e6e58 | 10120 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
10121 | narrow = 0; |
10122 | if (low_regs && narrow) | |
10123 | { | |
10124 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 10125 | inst.instruction |= Rn << 8; |
0110f2b8 PB |
10126 | if (inst.size_req == 2) |
10127 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
10128 | else | |
10129 | inst.relax = opcode; | |
10130 | } | |
10131 | else | |
10132 | { | |
10133 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10134 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10135 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
10136 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
10137 | } | |
c19d1205 | 10138 | } |
728ca7c9 PB |
10139 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
10140 | && (inst.instruction == T_MNEM_mov | |
10141 | || inst.instruction == T_MNEM_movs)) | |
10142 | { | |
10143 | /* Register shifts are encoded as separate shift instructions. */ | |
10144 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
10145 | ||
e07e6e58 | 10146 | if (in_it_block ()) |
728ca7c9 PB |
10147 | narrow = !flags; |
10148 | else | |
10149 | narrow = flags; | |
10150 | ||
10151 | if (inst.size_req == 4) | |
10152 | narrow = FALSE; | |
10153 | ||
10154 | if (!low_regs || inst.operands[1].imm > 7) | |
10155 | narrow = FALSE; | |
10156 | ||
fdfde340 | 10157 | if (Rn != Rm) |
728ca7c9 PB |
10158 | narrow = FALSE; |
10159 | ||
10160 | switch (inst.operands[1].shift_kind) | |
10161 | { | |
10162 | case SHIFT_LSL: | |
10163 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
10164 | break; | |
10165 | case SHIFT_ASR: | |
10166 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
10167 | break; | |
10168 | case SHIFT_LSR: | |
10169 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
10170 | break; | |
10171 | case SHIFT_ROR: | |
10172 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
10173 | break; | |
10174 | default: | |
5f4273c7 | 10175 | abort (); |
728ca7c9 PB |
10176 | } |
10177 | ||
10178 | inst.instruction = opcode; | |
10179 | if (narrow) | |
10180 | { | |
fdfde340 | 10181 | inst.instruction |= Rn; |
728ca7c9 PB |
10182 | inst.instruction |= inst.operands[1].imm << 3; |
10183 | } | |
10184 | else | |
10185 | { | |
10186 | if (flags) | |
10187 | inst.instruction |= CONDS_BIT; | |
10188 | ||
fdfde340 JM |
10189 | inst.instruction |= Rn << 8; |
10190 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
10191 | inst.instruction |= inst.operands[1].imm; |
10192 | } | |
10193 | } | |
3d388997 | 10194 | else if (!narrow) |
c19d1205 | 10195 | { |
728ca7c9 PB |
10196 | /* Some mov with immediate shift have narrow variants. |
10197 | Register shifts are handled above. */ | |
10198 | if (low_regs && inst.operands[1].shifted | |
10199 | && (inst.instruction == T_MNEM_mov | |
10200 | || inst.instruction == T_MNEM_movs)) | |
10201 | { | |
e07e6e58 | 10202 | if (in_it_block ()) |
728ca7c9 PB |
10203 | narrow = (inst.instruction == T_MNEM_mov); |
10204 | else | |
10205 | narrow = (inst.instruction == T_MNEM_movs); | |
10206 | } | |
10207 | ||
10208 | if (narrow) | |
10209 | { | |
10210 | switch (inst.operands[1].shift_kind) | |
10211 | { | |
10212 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10213 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
10214 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
10215 | default: narrow = FALSE; break; | |
10216 | } | |
10217 | } | |
10218 | ||
10219 | if (narrow) | |
10220 | { | |
fdfde340 JM |
10221 | inst.instruction |= Rn; |
10222 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
10223 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10224 | } | |
10225 | else | |
10226 | { | |
10227 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10228 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
10229 | encode_thumb32_shifted_operand (1); |
10230 | } | |
c19d1205 ZW |
10231 | } |
10232 | else | |
10233 | switch (inst.instruction) | |
10234 | { | |
10235 | case T_MNEM_mov: | |
10236 | inst.instruction = T_OPCODE_MOV_HR; | |
fdfde340 JM |
10237 | inst.instruction |= (Rn & 0x8) << 4; |
10238 | inst.instruction |= (Rn & 0x7); | |
10239 | inst.instruction |= Rm << 3; | |
c19d1205 | 10240 | break; |
b99bd4ef | 10241 | |
c19d1205 ZW |
10242 | case T_MNEM_movs: |
10243 | /* We know we have low registers at this point. | |
10244 | Generate ADD Rd, Rs, #0. */ | |
10245 | inst.instruction = T_OPCODE_ADD_I3; | |
fdfde340 JM |
10246 | inst.instruction |= Rn; |
10247 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10248 | break; |
10249 | ||
10250 | case T_MNEM_cmp: | |
3d388997 | 10251 | if (low_regs) |
c19d1205 ZW |
10252 | { |
10253 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
10254 | inst.instruction |= Rn; |
10255 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10256 | } |
10257 | else | |
10258 | { | |
10259 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
10260 | inst.instruction |= (Rn & 0x8) << 4; |
10261 | inst.instruction |= (Rn & 0x7); | |
10262 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10263 | } |
10264 | break; | |
10265 | } | |
b99bd4ef NC |
10266 | return; |
10267 | } | |
10268 | ||
c19d1205 | 10269 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
10270 | |
10271 | /* PR 10443: Do not silently ignore shifted operands. */ | |
10272 | constraint (inst.operands[1].shifted, | |
10273 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
10274 | ||
c19d1205 | 10275 | if (inst.operands[1].isreg) |
b99bd4ef | 10276 | { |
fdfde340 | 10277 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 10278 | { |
c19d1205 ZW |
10279 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
10280 | since a MOV instruction produces unpredictable results. */ | |
10281 | if (inst.instruction == T_OPCODE_MOV_I8) | |
10282 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 10283 | else |
c19d1205 | 10284 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 10285 | |
fdfde340 JM |
10286 | inst.instruction |= Rn; |
10287 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
10288 | } |
10289 | else | |
10290 | { | |
c19d1205 ZW |
10291 | if (inst.instruction == T_OPCODE_MOV_I8) |
10292 | inst.instruction = T_OPCODE_MOV_HR; | |
10293 | else | |
10294 | inst.instruction = T_OPCODE_CMP_HR; | |
10295 | do_t_cpy (); | |
b99bd4ef NC |
10296 | } |
10297 | } | |
c19d1205 | 10298 | else |
b99bd4ef | 10299 | { |
fdfde340 | 10300 | constraint (Rn > 7, |
c19d1205 | 10301 | _("only lo regs allowed with immediate")); |
fdfde340 | 10302 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
10303 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
10304 | } | |
10305 | } | |
b99bd4ef | 10306 | |
c19d1205 ZW |
10307 | static void |
10308 | do_t_mov16 (void) | |
10309 | { | |
fdfde340 | 10310 | unsigned Rd; |
b6895b4f PB |
10311 | bfd_vma imm; |
10312 | bfd_boolean top; | |
10313 | ||
10314 | top = (inst.instruction & 0x00800000) != 0; | |
10315 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
10316 | { | |
10317 | constraint (top, _(":lower16: not allowed this instruction")); | |
10318 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
10319 | } | |
10320 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
10321 | { | |
10322 | constraint (!top, _(":upper16: not allowed this instruction")); | |
10323 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
10324 | } | |
10325 | ||
fdfde340 JM |
10326 | Rd = inst.operands[0].reg; |
10327 | reject_bad_reg (Rd); | |
10328 | ||
10329 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
10330 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
10331 | { | |
10332 | imm = inst.reloc.exp.X_add_number; | |
10333 | inst.instruction |= (imm & 0xf000) << 4; | |
10334 | inst.instruction |= (imm & 0x0800) << 15; | |
10335 | inst.instruction |= (imm & 0x0700) << 4; | |
10336 | inst.instruction |= (imm & 0x00ff); | |
10337 | } | |
c19d1205 | 10338 | } |
b99bd4ef | 10339 | |
c19d1205 ZW |
10340 | static void |
10341 | do_t_mvn_tst (void) | |
10342 | { | |
fdfde340 | 10343 | unsigned Rn, Rm; |
c921be7d | 10344 | |
fdfde340 JM |
10345 | Rn = inst.operands[0].reg; |
10346 | Rm = inst.operands[1].reg; | |
10347 | ||
10348 | if (inst.instruction == T_MNEM_cmp | |
10349 | || inst.instruction == T_MNEM_cmn) | |
10350 | constraint (Rn == REG_PC, BAD_PC); | |
10351 | else | |
10352 | reject_bad_reg (Rn); | |
10353 | reject_bad_reg (Rm); | |
10354 | ||
c19d1205 ZW |
10355 | if (unified_syntax) |
10356 | { | |
10357 | int r0off = (inst.instruction == T_MNEM_mvn | |
10358 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
10359 | bfd_boolean narrow; |
10360 | ||
10361 | if (inst.size_req == 4 | |
10362 | || inst.instruction > 0xffff | |
10363 | || inst.operands[1].shifted | |
fdfde340 | 10364 | || Rn > 7 || Rm > 7) |
3d388997 PB |
10365 | narrow = FALSE; |
10366 | else if (inst.instruction == T_MNEM_cmn) | |
10367 | narrow = TRUE; | |
10368 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10369 | narrow = !in_it_block (); |
3d388997 | 10370 | else |
e07e6e58 | 10371 | narrow = in_it_block (); |
3d388997 | 10372 | |
c19d1205 | 10373 | if (!inst.operands[1].isreg) |
b99bd4ef | 10374 | { |
c19d1205 ZW |
10375 | /* For an immediate, we always generate a 32-bit opcode; |
10376 | section relaxation will shrink it later if possible. */ | |
10377 | if (inst.instruction < 0xffff) | |
10378 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10379 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10380 | inst.instruction |= Rn << r0off; |
c19d1205 | 10381 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 10382 | } |
c19d1205 | 10383 | else |
b99bd4ef | 10384 | { |
c19d1205 | 10385 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 10386 | if (narrow) |
b99bd4ef | 10387 | { |
c19d1205 | 10388 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10389 | inst.instruction |= Rn; |
10390 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10391 | } |
c19d1205 | 10392 | else |
b99bd4ef | 10393 | { |
c19d1205 ZW |
10394 | constraint (inst.operands[1].shifted |
10395 | && inst.operands[1].immisreg, | |
10396 | _("shift must be constant")); | |
10397 | if (inst.instruction < 0xffff) | |
10398 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10399 | inst.instruction |= Rn << r0off; |
c19d1205 | 10400 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 10401 | } |
b99bd4ef NC |
10402 | } |
10403 | } | |
10404 | else | |
10405 | { | |
c19d1205 ZW |
10406 | constraint (inst.instruction > 0xffff |
10407 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
10408 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
10409 | _("unshifted register required")); | |
fdfde340 | 10410 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10411 | BAD_HIREG); |
b99bd4ef | 10412 | |
c19d1205 | 10413 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10414 | inst.instruction |= Rn; |
10415 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10416 | } |
b99bd4ef NC |
10417 | } |
10418 | ||
b05fe5cf | 10419 | static void |
c19d1205 | 10420 | do_t_mrs (void) |
b05fe5cf | 10421 | { |
fdfde340 | 10422 | unsigned Rd; |
62b3e311 | 10423 | int flags; |
037e8744 JB |
10424 | |
10425 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
10426 | return; | |
10427 | ||
62b3e311 PB |
10428 | flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
10429 | if (flags == 0) | |
10430 | { | |
7e806470 | 10431 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10432 | _("selected processor does not support " |
10433 | "requested special purpose register")); | |
10434 | } | |
10435 | else | |
10436 | { | |
10437 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10438 | _("selected processor does not support " | |
44bf2362 | 10439 | "requested special purpose register")); |
62b3e311 PB |
10440 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
10441 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
10442 | _("'CPSR' or 'SPSR' expected")); | |
10443 | } | |
5f4273c7 | 10444 | |
fdfde340 JM |
10445 | Rd = inst.operands[0].reg; |
10446 | reject_bad_reg (Rd); | |
10447 | ||
10448 | inst.instruction |= Rd << 8; | |
62b3e311 PB |
10449 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10450 | inst.instruction |= inst.operands[1].imm & 0xff; | |
c19d1205 | 10451 | } |
b05fe5cf | 10452 | |
c19d1205 ZW |
10453 | static void |
10454 | do_t_msr (void) | |
10455 | { | |
62b3e311 | 10456 | int flags; |
fdfde340 | 10457 | unsigned Rn; |
62b3e311 | 10458 | |
037e8744 JB |
10459 | if (do_vfp_nsyn_msr () == SUCCESS) |
10460 | return; | |
10461 | ||
c19d1205 ZW |
10462 | constraint (!inst.operands[1].isreg, |
10463 | _("Thumb encoding does not support an immediate here")); | |
62b3e311 PB |
10464 | flags = inst.operands[0].imm; |
10465 | if (flags & ~0xff) | |
10466 | { | |
10467 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10468 | _("selected processor does not support " | |
10469 | "requested special purpose register")); | |
10470 | } | |
10471 | else | |
10472 | { | |
7e806470 | 10473 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10474 | _("selected processor does not support " |
10475 | "requested special purpose register")); | |
10476 | flags |= PSR_f; | |
10477 | } | |
c921be7d | 10478 | |
fdfde340 JM |
10479 | Rn = inst.operands[1].reg; |
10480 | reject_bad_reg (Rn); | |
10481 | ||
62b3e311 PB |
10482 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10483 | inst.instruction |= (flags & ~SPSR_BIT) >> 8; | |
10484 | inst.instruction |= (flags & 0xff); | |
fdfde340 | 10485 | inst.instruction |= Rn << 16; |
c19d1205 | 10486 | } |
b05fe5cf | 10487 | |
c19d1205 ZW |
10488 | static void |
10489 | do_t_mul (void) | |
10490 | { | |
17828f45 | 10491 | bfd_boolean narrow; |
fdfde340 | 10492 | unsigned Rd, Rn, Rm; |
17828f45 | 10493 | |
c19d1205 ZW |
10494 | if (!inst.operands[2].present) |
10495 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 10496 | |
fdfde340 JM |
10497 | Rd = inst.operands[0].reg; |
10498 | Rn = inst.operands[1].reg; | |
10499 | Rm = inst.operands[2].reg; | |
10500 | ||
17828f45 | 10501 | if (unified_syntax) |
b05fe5cf | 10502 | { |
17828f45 | 10503 | if (inst.size_req == 4 |
fdfde340 JM |
10504 | || (Rd != Rn |
10505 | && Rd != Rm) | |
10506 | || Rn > 7 | |
10507 | || Rm > 7) | |
17828f45 JM |
10508 | narrow = FALSE; |
10509 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 10510 | narrow = !in_it_block (); |
17828f45 | 10511 | else |
e07e6e58 | 10512 | narrow = in_it_block (); |
b05fe5cf | 10513 | } |
c19d1205 | 10514 | else |
b05fe5cf | 10515 | { |
17828f45 | 10516 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 10517 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10518 | BAD_HIREG); |
17828f45 JM |
10519 | narrow = TRUE; |
10520 | } | |
b05fe5cf | 10521 | |
17828f45 JM |
10522 | if (narrow) |
10523 | { | |
10524 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 10525 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 10526 | inst.instruction |= Rd; |
b05fe5cf | 10527 | |
fdfde340 JM |
10528 | if (Rd == Rn) |
10529 | inst.instruction |= Rm << 3; | |
10530 | else if (Rd == Rm) | |
10531 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
10532 | else |
10533 | constraint (1, _("dest must overlap one source register")); | |
10534 | } | |
17828f45 JM |
10535 | else |
10536 | { | |
e07e6e58 NC |
10537 | constraint (inst.instruction != T_MNEM_mul, |
10538 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
10539 | /* 32-bit MUL. */ |
10540 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10541 | inst.instruction |= Rd << 8; |
10542 | inst.instruction |= Rn << 16; | |
10543 | inst.instruction |= Rm << 0; | |
10544 | ||
10545 | reject_bad_reg (Rd); | |
10546 | reject_bad_reg (Rn); | |
10547 | reject_bad_reg (Rm); | |
17828f45 | 10548 | } |
c19d1205 | 10549 | } |
b05fe5cf | 10550 | |
c19d1205 ZW |
10551 | static void |
10552 | do_t_mull (void) | |
10553 | { | |
fdfde340 | 10554 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 10555 | |
fdfde340 JM |
10556 | RdLo = inst.operands[0].reg; |
10557 | RdHi = inst.operands[1].reg; | |
10558 | Rn = inst.operands[2].reg; | |
10559 | Rm = inst.operands[3].reg; | |
10560 | ||
10561 | reject_bad_reg (RdLo); | |
10562 | reject_bad_reg (RdHi); | |
10563 | reject_bad_reg (Rn); | |
10564 | reject_bad_reg (Rm); | |
10565 | ||
10566 | inst.instruction |= RdLo << 12; | |
10567 | inst.instruction |= RdHi << 8; | |
10568 | inst.instruction |= Rn << 16; | |
10569 | inst.instruction |= Rm; | |
10570 | ||
10571 | if (RdLo == RdHi) | |
c19d1205 ZW |
10572 | as_tsktsk (_("rdhi and rdlo must be different")); |
10573 | } | |
b05fe5cf | 10574 | |
c19d1205 ZW |
10575 | static void |
10576 | do_t_nop (void) | |
10577 | { | |
e07e6e58 NC |
10578 | set_it_insn_type (NEUTRAL_IT_INSN); |
10579 | ||
c19d1205 ZW |
10580 | if (unified_syntax) |
10581 | { | |
10582 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 10583 | { |
c19d1205 ZW |
10584 | inst.instruction = THUMB_OP32 (inst.instruction); |
10585 | inst.instruction |= inst.operands[0].imm; | |
10586 | } | |
10587 | else | |
10588 | { | |
bc2d1808 NC |
10589 | /* PR9722: Check for Thumb2 availability before |
10590 | generating a thumb2 nop instruction. */ | |
10591 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
10592 | { | |
10593 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10594 | inst.instruction |= inst.operands[0].imm << 4; | |
10595 | } | |
10596 | else | |
10597 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
10598 | } |
10599 | } | |
10600 | else | |
10601 | { | |
10602 | constraint (inst.operands[0].present, | |
10603 | _("Thumb does not support NOP with hints")); | |
10604 | inst.instruction = 0x46c0; | |
10605 | } | |
10606 | } | |
b05fe5cf | 10607 | |
c19d1205 ZW |
10608 | static void |
10609 | do_t_neg (void) | |
10610 | { | |
10611 | if (unified_syntax) | |
10612 | { | |
3d388997 PB |
10613 | bfd_boolean narrow; |
10614 | ||
10615 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10616 | narrow = !in_it_block (); |
3d388997 | 10617 | else |
e07e6e58 | 10618 | narrow = in_it_block (); |
3d388997 PB |
10619 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10620 | narrow = FALSE; | |
10621 | if (inst.size_req == 4) | |
10622 | narrow = FALSE; | |
10623 | ||
10624 | if (!narrow) | |
c19d1205 ZW |
10625 | { |
10626 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10627 | inst.instruction |= inst.operands[0].reg << 8; | |
10628 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
10629 | } |
10630 | else | |
10631 | { | |
c19d1205 ZW |
10632 | inst.instruction = THUMB_OP16 (inst.instruction); |
10633 | inst.instruction |= inst.operands[0].reg; | |
10634 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
10635 | } |
10636 | } | |
10637 | else | |
10638 | { | |
c19d1205 ZW |
10639 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
10640 | BAD_HIREG); | |
10641 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
10642 | ||
10643 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10644 | inst.instruction |= inst.operands[0].reg; | |
10645 | inst.instruction |= inst.operands[1].reg << 3; | |
10646 | } | |
10647 | } | |
10648 | ||
1c444d06 JM |
10649 | static void |
10650 | do_t_orn (void) | |
10651 | { | |
10652 | unsigned Rd, Rn; | |
10653 | ||
10654 | Rd = inst.operands[0].reg; | |
10655 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
10656 | ||
fdfde340 JM |
10657 | reject_bad_reg (Rd); |
10658 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
10659 | reject_bad_reg (Rn); | |
10660 | ||
1c444d06 JM |
10661 | inst.instruction |= Rd << 8; |
10662 | inst.instruction |= Rn << 16; | |
10663 | ||
10664 | if (!inst.operands[2].isreg) | |
10665 | { | |
10666 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10667 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10668 | } | |
10669 | else | |
10670 | { | |
10671 | unsigned Rm; | |
10672 | ||
10673 | Rm = inst.operands[2].reg; | |
fdfde340 | 10674 | reject_bad_reg (Rm); |
1c444d06 JM |
10675 | |
10676 | constraint (inst.operands[2].shifted | |
10677 | && inst.operands[2].immisreg, | |
10678 | _("shift must be constant")); | |
10679 | encode_thumb32_shifted_operand (2); | |
10680 | } | |
10681 | } | |
10682 | ||
c19d1205 ZW |
10683 | static void |
10684 | do_t_pkhbt (void) | |
10685 | { | |
fdfde340 JM |
10686 | unsigned Rd, Rn, Rm; |
10687 | ||
10688 | Rd = inst.operands[0].reg; | |
10689 | Rn = inst.operands[1].reg; | |
10690 | Rm = inst.operands[2].reg; | |
10691 | ||
10692 | reject_bad_reg (Rd); | |
10693 | reject_bad_reg (Rn); | |
10694 | reject_bad_reg (Rm); | |
10695 | ||
10696 | inst.instruction |= Rd << 8; | |
10697 | inst.instruction |= Rn << 16; | |
10698 | inst.instruction |= Rm; | |
c19d1205 ZW |
10699 | if (inst.operands[3].present) |
10700 | { | |
10701 | unsigned int val = inst.reloc.exp.X_add_number; | |
10702 | constraint (inst.reloc.exp.X_op != O_constant, | |
10703 | _("expression too complex")); | |
10704 | inst.instruction |= (val & 0x1c) << 10; | |
10705 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 10706 | } |
c19d1205 | 10707 | } |
b05fe5cf | 10708 | |
c19d1205 ZW |
10709 | static void |
10710 | do_t_pkhtb (void) | |
10711 | { | |
10712 | if (!inst.operands[3].present) | |
1ef52f49 NC |
10713 | { |
10714 | unsigned Rtmp; | |
10715 | ||
10716 | inst.instruction &= ~0x00000020; | |
10717 | ||
10718 | /* PR 10168. Swap the Rm and Rn registers. */ | |
10719 | Rtmp = inst.operands[1].reg; | |
10720 | inst.operands[1].reg = inst.operands[2].reg; | |
10721 | inst.operands[2].reg = Rtmp; | |
10722 | } | |
c19d1205 | 10723 | do_t_pkhbt (); |
b05fe5cf ZW |
10724 | } |
10725 | ||
c19d1205 ZW |
10726 | static void |
10727 | do_t_pld (void) | |
10728 | { | |
fdfde340 JM |
10729 | if (inst.operands[0].immisreg) |
10730 | reject_bad_reg (inst.operands[0].imm); | |
10731 | ||
c19d1205 ZW |
10732 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
10733 | } | |
b05fe5cf | 10734 | |
c19d1205 ZW |
10735 | static void |
10736 | do_t_push_pop (void) | |
b99bd4ef | 10737 | { |
e9f89963 | 10738 | unsigned mask; |
5f4273c7 | 10739 | |
c19d1205 ZW |
10740 | constraint (inst.operands[0].writeback, |
10741 | _("push/pop do not support {reglist}^")); | |
10742 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
10743 | _("expression too complex")); | |
b99bd4ef | 10744 | |
e9f89963 PB |
10745 | mask = inst.operands[0].imm; |
10746 | if ((mask & ~0xff) == 0) | |
3c707909 | 10747 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
c19d1205 | 10748 | else if ((inst.instruction == T_MNEM_push |
e9f89963 | 10749 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 10750 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 10751 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 10752 | { |
c19d1205 ZW |
10753 | inst.instruction = THUMB_OP16 (inst.instruction); |
10754 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 10755 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
10756 | } |
10757 | else if (unified_syntax) | |
10758 | { | |
3c707909 | 10759 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 10760 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
10761 | } |
10762 | else | |
10763 | { | |
10764 | inst.error = _("invalid register list to push/pop instruction"); | |
10765 | return; | |
10766 | } | |
c19d1205 | 10767 | } |
b99bd4ef | 10768 | |
c19d1205 ZW |
10769 | static void |
10770 | do_t_rbit (void) | |
10771 | { | |
fdfde340 JM |
10772 | unsigned Rd, Rm; |
10773 | ||
10774 | Rd = inst.operands[0].reg; | |
10775 | Rm = inst.operands[1].reg; | |
10776 | ||
10777 | reject_bad_reg (Rd); | |
10778 | reject_bad_reg (Rm); | |
10779 | ||
10780 | inst.instruction |= Rd << 8; | |
10781 | inst.instruction |= Rm << 16; | |
10782 | inst.instruction |= Rm; | |
c19d1205 | 10783 | } |
b99bd4ef | 10784 | |
c19d1205 ZW |
10785 | static void |
10786 | do_t_rev (void) | |
10787 | { | |
fdfde340 JM |
10788 | unsigned Rd, Rm; |
10789 | ||
10790 | Rd = inst.operands[0].reg; | |
10791 | Rm = inst.operands[1].reg; | |
10792 | ||
10793 | reject_bad_reg (Rd); | |
10794 | reject_bad_reg (Rm); | |
10795 | ||
10796 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
10797 | && inst.size_req != 4) |
10798 | { | |
10799 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
10800 | inst.instruction |= Rd; |
10801 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10802 | } |
10803 | else if (unified_syntax) | |
10804 | { | |
10805 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10806 | inst.instruction |= Rd << 8; |
10807 | inst.instruction |= Rm << 16; | |
10808 | inst.instruction |= Rm; | |
c19d1205 ZW |
10809 | } |
10810 | else | |
10811 | inst.error = BAD_HIREG; | |
10812 | } | |
b99bd4ef | 10813 | |
1c444d06 JM |
10814 | static void |
10815 | do_t_rrx (void) | |
10816 | { | |
10817 | unsigned Rd, Rm; | |
10818 | ||
10819 | Rd = inst.operands[0].reg; | |
10820 | Rm = inst.operands[1].reg; | |
10821 | ||
fdfde340 JM |
10822 | reject_bad_reg (Rd); |
10823 | reject_bad_reg (Rm); | |
c921be7d | 10824 | |
1c444d06 JM |
10825 | inst.instruction |= Rd << 8; |
10826 | inst.instruction |= Rm; | |
10827 | } | |
10828 | ||
c19d1205 ZW |
10829 | static void |
10830 | do_t_rsb (void) | |
10831 | { | |
fdfde340 | 10832 | unsigned Rd, Rs; |
b99bd4ef | 10833 | |
c19d1205 ZW |
10834 | Rd = inst.operands[0].reg; |
10835 | Rs = (inst.operands[1].present | |
10836 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10837 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 10838 | |
fdfde340 JM |
10839 | reject_bad_reg (Rd); |
10840 | reject_bad_reg (Rs); | |
10841 | if (inst.operands[2].isreg) | |
10842 | reject_bad_reg (inst.operands[2].reg); | |
10843 | ||
c19d1205 ZW |
10844 | inst.instruction |= Rd << 8; |
10845 | inst.instruction |= Rs << 16; | |
10846 | if (!inst.operands[2].isreg) | |
10847 | { | |
026d3abb PB |
10848 | bfd_boolean narrow; |
10849 | ||
10850 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 10851 | narrow = !in_it_block (); |
026d3abb | 10852 | else |
e07e6e58 | 10853 | narrow = in_it_block (); |
026d3abb PB |
10854 | |
10855 | if (Rd > 7 || Rs > 7) | |
10856 | narrow = FALSE; | |
10857 | ||
10858 | if (inst.size_req == 4 || !unified_syntax) | |
10859 | narrow = FALSE; | |
10860 | ||
10861 | if (inst.reloc.exp.X_op != O_constant | |
10862 | || inst.reloc.exp.X_add_number != 0) | |
10863 | narrow = FALSE; | |
10864 | ||
10865 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
10866 | relaxation, but it doesn't seem worth the hassle. */ | |
10867 | if (narrow) | |
10868 | { | |
10869 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10870 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
10871 | inst.instruction |= Rs << 3; | |
10872 | inst.instruction |= Rd; | |
10873 | } | |
10874 | else | |
10875 | { | |
10876 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10877 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10878 | } | |
c19d1205 ZW |
10879 | } |
10880 | else | |
10881 | encode_thumb32_shifted_operand (2); | |
10882 | } | |
b99bd4ef | 10883 | |
c19d1205 ZW |
10884 | static void |
10885 | do_t_setend (void) | |
10886 | { | |
e07e6e58 | 10887 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
10888 | if (inst.operands[0].imm) |
10889 | inst.instruction |= 0x8; | |
10890 | } | |
b99bd4ef | 10891 | |
c19d1205 ZW |
10892 | static void |
10893 | do_t_shift (void) | |
10894 | { | |
10895 | if (!inst.operands[1].present) | |
10896 | inst.operands[1].reg = inst.operands[0].reg; | |
10897 | ||
10898 | if (unified_syntax) | |
10899 | { | |
3d388997 PB |
10900 | bfd_boolean narrow; |
10901 | int shift_kind; | |
10902 | ||
10903 | switch (inst.instruction) | |
10904 | { | |
10905 | case T_MNEM_asr: | |
10906 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
10907 | case T_MNEM_lsl: | |
10908 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
10909 | case T_MNEM_lsr: | |
10910 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
10911 | case T_MNEM_ror: | |
10912 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
10913 | default: abort (); | |
10914 | } | |
10915 | ||
10916 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10917 | narrow = !in_it_block (); |
3d388997 | 10918 | else |
e07e6e58 | 10919 | narrow = in_it_block (); |
3d388997 PB |
10920 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10921 | narrow = FALSE; | |
10922 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
10923 | narrow = FALSE; | |
10924 | if (inst.operands[2].isreg | |
10925 | && (inst.operands[1].reg != inst.operands[0].reg | |
10926 | || inst.operands[2].reg > 7)) | |
10927 | narrow = FALSE; | |
10928 | if (inst.size_req == 4) | |
10929 | narrow = FALSE; | |
10930 | ||
fdfde340 JM |
10931 | reject_bad_reg (inst.operands[0].reg); |
10932 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 10933 | |
3d388997 | 10934 | if (!narrow) |
c19d1205 ZW |
10935 | { |
10936 | if (inst.operands[2].isreg) | |
b99bd4ef | 10937 | { |
fdfde340 | 10938 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
10939 | inst.instruction = THUMB_OP32 (inst.instruction); |
10940 | inst.instruction |= inst.operands[0].reg << 8; | |
10941 | inst.instruction |= inst.operands[1].reg << 16; | |
10942 | inst.instruction |= inst.operands[2].reg; | |
10943 | } | |
10944 | else | |
10945 | { | |
10946 | inst.operands[1].shifted = 1; | |
3d388997 | 10947 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
10948 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
10949 | ? T_MNEM_movs : T_MNEM_mov); | |
10950 | inst.instruction |= inst.operands[0].reg << 8; | |
10951 | encode_thumb32_shifted_operand (1); | |
10952 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
10953 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
10954 | } |
10955 | } | |
10956 | else | |
10957 | { | |
c19d1205 | 10958 | if (inst.operands[2].isreg) |
b99bd4ef | 10959 | { |
3d388997 | 10960 | switch (shift_kind) |
b99bd4ef | 10961 | { |
3d388997 PB |
10962 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
10963 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
10964 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
10965 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 10966 | default: abort (); |
b99bd4ef | 10967 | } |
5f4273c7 | 10968 | |
c19d1205 ZW |
10969 | inst.instruction |= inst.operands[0].reg; |
10970 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
10971 | } |
10972 | else | |
10973 | { | |
3d388997 | 10974 | switch (shift_kind) |
b99bd4ef | 10975 | { |
3d388997 PB |
10976 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
10977 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10978 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 10979 | default: abort (); |
b99bd4ef | 10980 | } |
c19d1205 ZW |
10981 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10982 | inst.instruction |= inst.operands[0].reg; | |
10983 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
10984 | } |
10985 | } | |
c19d1205 ZW |
10986 | } |
10987 | else | |
10988 | { | |
10989 | constraint (inst.operands[0].reg > 7 | |
10990 | || inst.operands[1].reg > 7, BAD_HIREG); | |
10991 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 10992 | |
c19d1205 ZW |
10993 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
10994 | { | |
10995 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
10996 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
10997 | _("source1 and dest must be same register")); | |
b99bd4ef | 10998 | |
c19d1205 ZW |
10999 | switch (inst.instruction) |
11000 | { | |
11001 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
11002 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
11003 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
11004 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
11005 | default: abort (); | |
11006 | } | |
5f4273c7 | 11007 | |
c19d1205 ZW |
11008 | inst.instruction |= inst.operands[0].reg; |
11009 | inst.instruction |= inst.operands[2].reg << 3; | |
11010 | } | |
11011 | else | |
b99bd4ef | 11012 | { |
c19d1205 ZW |
11013 | switch (inst.instruction) |
11014 | { | |
11015 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
11016 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
11017 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
11018 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
11019 | default: abort (); | |
11020 | } | |
11021 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
11022 | inst.instruction |= inst.operands[0].reg; | |
11023 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
11024 | } |
11025 | } | |
b99bd4ef NC |
11026 | } |
11027 | ||
11028 | static void | |
c19d1205 | 11029 | do_t_simd (void) |
b99bd4ef | 11030 | { |
fdfde340 JM |
11031 | unsigned Rd, Rn, Rm; |
11032 | ||
11033 | Rd = inst.operands[0].reg; | |
11034 | Rn = inst.operands[1].reg; | |
11035 | Rm = inst.operands[2].reg; | |
11036 | ||
11037 | reject_bad_reg (Rd); | |
11038 | reject_bad_reg (Rn); | |
11039 | reject_bad_reg (Rm); | |
11040 | ||
11041 | inst.instruction |= Rd << 8; | |
11042 | inst.instruction |= Rn << 16; | |
11043 | inst.instruction |= Rm; | |
c19d1205 | 11044 | } |
b99bd4ef | 11045 | |
c19d1205 | 11046 | static void |
3eb17e6b | 11047 | do_t_smc (void) |
c19d1205 ZW |
11048 | { |
11049 | unsigned int value = inst.reloc.exp.X_add_number; | |
11050 | constraint (inst.reloc.exp.X_op != O_constant, | |
11051 | _("expression too complex")); | |
11052 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11053 | inst.instruction |= (value & 0xf000) >> 12; | |
11054 | inst.instruction |= (value & 0x0ff0); | |
11055 | inst.instruction |= (value & 0x000f) << 16; | |
11056 | } | |
b99bd4ef | 11057 | |
c19d1205 | 11058 | static void |
3a21c15a | 11059 | do_t_ssat_usat (int bias) |
c19d1205 | 11060 | { |
fdfde340 JM |
11061 | unsigned Rd, Rn; |
11062 | ||
11063 | Rd = inst.operands[0].reg; | |
11064 | Rn = inst.operands[2].reg; | |
11065 | ||
11066 | reject_bad_reg (Rd); | |
11067 | reject_bad_reg (Rn); | |
11068 | ||
11069 | inst.instruction |= Rd << 8; | |
3a21c15a | 11070 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 11071 | inst.instruction |= Rn << 16; |
b99bd4ef | 11072 | |
c19d1205 | 11073 | if (inst.operands[3].present) |
b99bd4ef | 11074 | { |
3a21c15a NC |
11075 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
11076 | ||
11077 | inst.reloc.type = BFD_RELOC_UNUSED; | |
11078 | ||
c19d1205 ZW |
11079 | constraint (inst.reloc.exp.X_op != O_constant, |
11080 | _("expression too complex")); | |
b99bd4ef | 11081 | |
3a21c15a | 11082 | if (shift_amount != 0) |
6189168b | 11083 | { |
3a21c15a NC |
11084 | constraint (shift_amount > 31, |
11085 | _("shift expression is too large")); | |
11086 | ||
c19d1205 | 11087 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
11088 | inst.instruction |= 0x00200000; /* sh bit. */ |
11089 | ||
11090 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
11091 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
11092 | } |
11093 | } | |
b99bd4ef | 11094 | } |
c921be7d | 11095 | |
3a21c15a NC |
11096 | static void |
11097 | do_t_ssat (void) | |
11098 | { | |
11099 | do_t_ssat_usat (1); | |
11100 | } | |
b99bd4ef | 11101 | |
0dd132b6 | 11102 | static void |
c19d1205 | 11103 | do_t_ssat16 (void) |
0dd132b6 | 11104 | { |
fdfde340 JM |
11105 | unsigned Rd, Rn; |
11106 | ||
11107 | Rd = inst.operands[0].reg; | |
11108 | Rn = inst.operands[2].reg; | |
11109 | ||
11110 | reject_bad_reg (Rd); | |
11111 | reject_bad_reg (Rn); | |
11112 | ||
11113 | inst.instruction |= Rd << 8; | |
c19d1205 | 11114 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 11115 | inst.instruction |= Rn << 16; |
c19d1205 | 11116 | } |
0dd132b6 | 11117 | |
c19d1205 ZW |
11118 | static void |
11119 | do_t_strex (void) | |
11120 | { | |
11121 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
11122 | || inst.operands[2].postind || inst.operands[2].writeback | |
11123 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
11124 | || inst.operands[2].negative, | |
01cfc07f | 11125 | BAD_ADDR_MODE); |
0dd132b6 | 11126 | |
c19d1205 ZW |
11127 | inst.instruction |= inst.operands[0].reg << 8; |
11128 | inst.instruction |= inst.operands[1].reg << 12; | |
11129 | inst.instruction |= inst.operands[2].reg << 16; | |
11130 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
11131 | } |
11132 | ||
b99bd4ef | 11133 | static void |
c19d1205 | 11134 | do_t_strexd (void) |
b99bd4ef | 11135 | { |
c19d1205 ZW |
11136 | if (!inst.operands[2].present) |
11137 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 11138 | |
c19d1205 ZW |
11139 | constraint (inst.operands[0].reg == inst.operands[1].reg |
11140 | || inst.operands[0].reg == inst.operands[2].reg | |
11141 | || inst.operands[0].reg == inst.operands[3].reg | |
11142 | || inst.operands[1].reg == inst.operands[2].reg, | |
11143 | BAD_OVERLAP); | |
b99bd4ef | 11144 | |
c19d1205 ZW |
11145 | inst.instruction |= inst.operands[0].reg; |
11146 | inst.instruction |= inst.operands[1].reg << 12; | |
11147 | inst.instruction |= inst.operands[2].reg << 8; | |
11148 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
11149 | } |
11150 | ||
11151 | static void | |
c19d1205 | 11152 | do_t_sxtah (void) |
b99bd4ef | 11153 | { |
fdfde340 JM |
11154 | unsigned Rd, Rn, Rm; |
11155 | ||
11156 | Rd = inst.operands[0].reg; | |
11157 | Rn = inst.operands[1].reg; | |
11158 | Rm = inst.operands[2].reg; | |
11159 | ||
11160 | reject_bad_reg (Rd); | |
11161 | reject_bad_reg (Rn); | |
11162 | reject_bad_reg (Rm); | |
11163 | ||
11164 | inst.instruction |= Rd << 8; | |
11165 | inst.instruction |= Rn << 16; | |
11166 | inst.instruction |= Rm; | |
c19d1205 ZW |
11167 | inst.instruction |= inst.operands[3].imm << 4; |
11168 | } | |
b99bd4ef | 11169 | |
c19d1205 ZW |
11170 | static void |
11171 | do_t_sxth (void) | |
11172 | { | |
fdfde340 JM |
11173 | unsigned Rd, Rm; |
11174 | ||
11175 | Rd = inst.operands[0].reg; | |
11176 | Rm = inst.operands[1].reg; | |
11177 | ||
11178 | reject_bad_reg (Rd); | |
11179 | reject_bad_reg (Rm); | |
c921be7d NC |
11180 | |
11181 | if (inst.instruction <= 0xffff | |
11182 | && inst.size_req != 4 | |
fdfde340 | 11183 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 11184 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 11185 | { |
c19d1205 | 11186 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
11187 | inst.instruction |= Rd; |
11188 | inst.instruction |= Rm << 3; | |
b99bd4ef | 11189 | } |
c19d1205 | 11190 | else if (unified_syntax) |
b99bd4ef | 11191 | { |
c19d1205 ZW |
11192 | if (inst.instruction <= 0xffff) |
11193 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11194 | inst.instruction |= Rd << 8; |
11195 | inst.instruction |= Rm; | |
c19d1205 | 11196 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 11197 | } |
c19d1205 | 11198 | else |
b99bd4ef | 11199 | { |
c19d1205 ZW |
11200 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
11201 | _("Thumb encoding does not support rotation")); | |
11202 | constraint (1, BAD_HIREG); | |
b99bd4ef | 11203 | } |
c19d1205 | 11204 | } |
b99bd4ef | 11205 | |
c19d1205 ZW |
11206 | static void |
11207 | do_t_swi (void) | |
11208 | { | |
11209 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
11210 | } | |
b99bd4ef | 11211 | |
92e90b6e PB |
11212 | static void |
11213 | do_t_tb (void) | |
11214 | { | |
fdfde340 | 11215 | unsigned Rn, Rm; |
92e90b6e PB |
11216 | int half; |
11217 | ||
11218 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 11219 | set_it_insn_type_last (); |
dfa9f0d5 PB |
11220 | constraint (inst.operands[0].immisreg, |
11221 | _("instruction requires register index")); | |
fdfde340 JM |
11222 | |
11223 | Rn = inst.operands[0].reg; | |
11224 | Rm = inst.operands[0].imm; | |
c921be7d | 11225 | |
fdfde340 JM |
11226 | constraint (Rn == REG_SP, BAD_SP); |
11227 | reject_bad_reg (Rm); | |
11228 | ||
92e90b6e PB |
11229 | constraint (!half && inst.operands[0].shifted, |
11230 | _("instruction does not allow shifted index")); | |
fdfde340 | 11231 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
11232 | } |
11233 | ||
c19d1205 ZW |
11234 | static void |
11235 | do_t_usat (void) | |
11236 | { | |
3a21c15a | 11237 | do_t_ssat_usat (0); |
b99bd4ef NC |
11238 | } |
11239 | ||
11240 | static void | |
c19d1205 | 11241 | do_t_usat16 (void) |
b99bd4ef | 11242 | { |
fdfde340 JM |
11243 | unsigned Rd, Rn; |
11244 | ||
11245 | Rd = inst.operands[0].reg; | |
11246 | Rn = inst.operands[2].reg; | |
11247 | ||
11248 | reject_bad_reg (Rd); | |
11249 | reject_bad_reg (Rn); | |
11250 | ||
11251 | inst.instruction |= Rd << 8; | |
c19d1205 | 11252 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 11253 | inst.instruction |= Rn << 16; |
b99bd4ef | 11254 | } |
c19d1205 | 11255 | |
5287ad62 | 11256 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 11257 | |
5287ad62 | 11258 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 11259 | |
5287ad62 JB |
11260 | /* An "invalid" code for the following tables. */ |
11261 | #define N_INV -1u | |
11262 | ||
11263 | struct neon_tab_entry | |
b99bd4ef | 11264 | { |
5287ad62 JB |
11265 | unsigned integer; |
11266 | unsigned float_or_poly; | |
11267 | unsigned scalar_or_imm; | |
11268 | }; | |
5f4273c7 | 11269 | |
5287ad62 JB |
11270 | /* Map overloaded Neon opcodes to their respective encodings. */ |
11271 | #define NEON_ENC_TAB \ | |
11272 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
11273 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
11274 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
11275 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
11276 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
11277 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
11278 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
11279 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
11280 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
11281 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
11282 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
11283 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 11284 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
11285 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
11286 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
5287ad62 JB |
11287 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
11288 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
11289 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
11290 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
11291 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
11292 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
11293 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
11294 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
11295 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
11296 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
11297 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
11298 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
11299 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
11300 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
11301 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
11302 | X(veor, 0x1000110, N_INV, N_INV), \ | |
11303 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
11304 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
11305 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
11306 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
11307 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
11308 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
11309 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
11310 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
11311 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
11312 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
11313 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
11314 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
11315 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
11316 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
11317 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
11318 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
11319 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
11320 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
11321 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
11322 | X(vnmla, 0xe000a40, 0xe000b40, N_INV), \ | |
11323 | X(vnmls, 0xe100a40, 0xe100b40, N_INV), \ | |
11324 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ | |
11325 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
11326 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
11327 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV) | |
5287ad62 JB |
11328 | |
11329 | enum neon_opc | |
11330 | { | |
11331 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
11332 | NEON_ENC_TAB | |
11333 | #undef X | |
11334 | }; | |
b99bd4ef | 11335 | |
5287ad62 JB |
11336 | static const struct neon_tab_entry neon_enc_tab[] = |
11337 | { | |
11338 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
11339 | NEON_ENC_TAB | |
11340 | #undef X | |
11341 | }; | |
b99bd4ef | 11342 | |
5287ad62 JB |
11343 | #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer) |
11344 | #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11345 | #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11346 | #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11347 | #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11348 | #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11349 | #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11350 | #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11351 | #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
037e8744 JB |
11352 | #define NEON_ENC_SINGLE(X) \ |
11353 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) | |
11354 | #define NEON_ENC_DOUBLE(X) \ | |
11355 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) | |
5287ad62 | 11356 | |
037e8744 JB |
11357 | /* Define shapes for instruction operands. The following mnemonic characters |
11358 | are used in this table: | |
5287ad62 | 11359 | |
037e8744 | 11360 | F - VFP S<n> register |
5287ad62 JB |
11361 | D - Neon D<n> register |
11362 | Q - Neon Q<n> register | |
11363 | I - Immediate | |
11364 | S - Scalar | |
11365 | R - ARM register | |
11366 | L - D<n> register list | |
5f4273c7 | 11367 | |
037e8744 JB |
11368 | This table is used to generate various data: |
11369 | - enumerations of the form NS_DDR to be used as arguments to | |
11370 | neon_select_shape. | |
11371 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 11372 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 11373 | |
037e8744 JB |
11374 | #define NEON_SHAPE_DEF \ |
11375 | X(3, (D, D, D), DOUBLE), \ | |
11376 | X(3, (Q, Q, Q), QUAD), \ | |
11377 | X(3, (D, D, I), DOUBLE), \ | |
11378 | X(3, (Q, Q, I), QUAD), \ | |
11379 | X(3, (D, D, S), DOUBLE), \ | |
11380 | X(3, (Q, Q, S), QUAD), \ | |
11381 | X(2, (D, D), DOUBLE), \ | |
11382 | X(2, (Q, Q), QUAD), \ | |
11383 | X(2, (D, S), DOUBLE), \ | |
11384 | X(2, (Q, S), QUAD), \ | |
11385 | X(2, (D, R), DOUBLE), \ | |
11386 | X(2, (Q, R), QUAD), \ | |
11387 | X(2, (D, I), DOUBLE), \ | |
11388 | X(2, (Q, I), QUAD), \ | |
11389 | X(3, (D, L, D), DOUBLE), \ | |
11390 | X(2, (D, Q), MIXED), \ | |
11391 | X(2, (Q, D), MIXED), \ | |
11392 | X(3, (D, Q, I), MIXED), \ | |
11393 | X(3, (Q, D, I), MIXED), \ | |
11394 | X(3, (Q, D, D), MIXED), \ | |
11395 | X(3, (D, Q, Q), MIXED), \ | |
11396 | X(3, (Q, Q, D), MIXED), \ | |
11397 | X(3, (Q, D, S), MIXED), \ | |
11398 | X(3, (D, Q, S), MIXED), \ | |
11399 | X(4, (D, D, D, I), DOUBLE), \ | |
11400 | X(4, (Q, Q, Q, I), QUAD), \ | |
11401 | X(2, (F, F), SINGLE), \ | |
11402 | X(3, (F, F, F), SINGLE), \ | |
11403 | X(2, (F, I), SINGLE), \ | |
11404 | X(2, (F, D), MIXED), \ | |
11405 | X(2, (D, F), MIXED), \ | |
11406 | X(3, (F, F, I), MIXED), \ | |
11407 | X(4, (R, R, F, F), SINGLE), \ | |
11408 | X(4, (F, F, R, R), SINGLE), \ | |
11409 | X(3, (D, R, R), DOUBLE), \ | |
11410 | X(3, (R, R, D), DOUBLE), \ | |
11411 | X(2, (S, R), SINGLE), \ | |
11412 | X(2, (R, S), SINGLE), \ | |
11413 | X(2, (F, R), SINGLE), \ | |
11414 | X(2, (R, F), SINGLE) | |
11415 | ||
11416 | #define S2(A,B) NS_##A##B | |
11417 | #define S3(A,B,C) NS_##A##B##C | |
11418 | #define S4(A,B,C,D) NS_##A##B##C##D | |
11419 | ||
11420 | #define X(N, L, C) S##N L | |
11421 | ||
5287ad62 JB |
11422 | enum neon_shape |
11423 | { | |
037e8744 JB |
11424 | NEON_SHAPE_DEF, |
11425 | NS_NULL | |
5287ad62 | 11426 | }; |
b99bd4ef | 11427 | |
037e8744 JB |
11428 | #undef X |
11429 | #undef S2 | |
11430 | #undef S3 | |
11431 | #undef S4 | |
11432 | ||
11433 | enum neon_shape_class | |
11434 | { | |
11435 | SC_SINGLE, | |
11436 | SC_DOUBLE, | |
11437 | SC_QUAD, | |
11438 | SC_MIXED | |
11439 | }; | |
11440 | ||
11441 | #define X(N, L, C) SC_##C | |
11442 | ||
11443 | static enum neon_shape_class neon_shape_class[] = | |
11444 | { | |
11445 | NEON_SHAPE_DEF | |
11446 | }; | |
11447 | ||
11448 | #undef X | |
11449 | ||
11450 | enum neon_shape_el | |
11451 | { | |
11452 | SE_F, | |
11453 | SE_D, | |
11454 | SE_Q, | |
11455 | SE_I, | |
11456 | SE_S, | |
11457 | SE_R, | |
11458 | SE_L | |
11459 | }; | |
11460 | ||
11461 | /* Register widths of above. */ | |
11462 | static unsigned neon_shape_el_size[] = | |
11463 | { | |
11464 | 32, | |
11465 | 64, | |
11466 | 128, | |
11467 | 0, | |
11468 | 32, | |
11469 | 32, | |
11470 | 0 | |
11471 | }; | |
11472 | ||
11473 | struct neon_shape_info | |
11474 | { | |
11475 | unsigned els; | |
11476 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
11477 | }; | |
11478 | ||
11479 | #define S2(A,B) { SE_##A, SE_##B } | |
11480 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
11481 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
11482 | ||
11483 | #define X(N, L, C) { N, S##N L } | |
11484 | ||
11485 | static struct neon_shape_info neon_shape_tab[] = | |
11486 | { | |
11487 | NEON_SHAPE_DEF | |
11488 | }; | |
11489 | ||
11490 | #undef X | |
11491 | #undef S2 | |
11492 | #undef S3 | |
11493 | #undef S4 | |
11494 | ||
5287ad62 JB |
11495 | /* Bit masks used in type checking given instructions. |
11496 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
11497 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
11498 | set, various other bits can be set as well in order to modify the meaning of | |
11499 | the type constraint. */ | |
11500 | ||
11501 | enum neon_type_mask | |
11502 | { | |
8e79c3df CM |
11503 | N_S8 = 0x0000001, |
11504 | N_S16 = 0x0000002, | |
11505 | N_S32 = 0x0000004, | |
11506 | N_S64 = 0x0000008, | |
11507 | N_U8 = 0x0000010, | |
11508 | N_U16 = 0x0000020, | |
11509 | N_U32 = 0x0000040, | |
11510 | N_U64 = 0x0000080, | |
11511 | N_I8 = 0x0000100, | |
11512 | N_I16 = 0x0000200, | |
11513 | N_I32 = 0x0000400, | |
11514 | N_I64 = 0x0000800, | |
11515 | N_8 = 0x0001000, | |
11516 | N_16 = 0x0002000, | |
11517 | N_32 = 0x0004000, | |
11518 | N_64 = 0x0008000, | |
11519 | N_P8 = 0x0010000, | |
11520 | N_P16 = 0x0020000, | |
11521 | N_F16 = 0x0040000, | |
11522 | N_F32 = 0x0080000, | |
11523 | N_F64 = 0x0100000, | |
c921be7d NC |
11524 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
11525 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 11526 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
c921be7d NC |
11527 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
11528 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
11529 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
11530 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
11531 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
11532 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
11533 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 11534 | N_UTYP = 0, |
037e8744 | 11535 | N_MAX_NONSPECIAL = N_F64 |
5287ad62 JB |
11536 | }; |
11537 | ||
dcbf9037 JB |
11538 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
11539 | ||
5287ad62 JB |
11540 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
11541 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
11542 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
11543 | #define N_SUF_32 (N_SU_32 | N_F32) | |
11544 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
11545 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
11546 | ||
11547 | /* Pass this as the first type argument to neon_check_type to ignore types | |
11548 | altogether. */ | |
11549 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
11550 | ||
037e8744 JB |
11551 | /* Select a "shape" for the current instruction (describing register types or |
11552 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
11553 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
11554 | function of operand parsing, so this function doesn't need to be called. | |
11555 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
11556 | |
11557 | static enum neon_shape | |
037e8744 | 11558 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 11559 | { |
037e8744 JB |
11560 | va_list ap; |
11561 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
11562 | |
11563 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
11564 | many arguments we should have, so this makes the assumption that we have | |
11565 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
11566 | true in the future. */ | |
11567 | if (!inst.operands[1].present) | |
11568 | inst.operands[1] = inst.operands[0]; | |
11569 | ||
037e8744 | 11570 | va_start (ap, shape); |
5f4273c7 | 11571 | |
037e8744 JB |
11572 | for (; shape != NS_NULL; shape = va_arg (ap, int)) |
11573 | { | |
11574 | unsigned j; | |
11575 | int matches = 1; | |
11576 | ||
11577 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
11578 | { | |
11579 | if (!inst.operands[j].present) | |
11580 | { | |
11581 | matches = 0; | |
11582 | break; | |
11583 | } | |
11584 | ||
11585 | switch (neon_shape_tab[shape].el[j]) | |
11586 | { | |
11587 | case SE_F: | |
11588 | if (!(inst.operands[j].isreg | |
11589 | && inst.operands[j].isvec | |
11590 | && inst.operands[j].issingle | |
11591 | && !inst.operands[j].isquad)) | |
11592 | matches = 0; | |
11593 | break; | |
11594 | ||
11595 | case SE_D: | |
11596 | if (!(inst.operands[j].isreg | |
11597 | && inst.operands[j].isvec | |
11598 | && !inst.operands[j].isquad | |
11599 | && !inst.operands[j].issingle)) | |
11600 | matches = 0; | |
11601 | break; | |
11602 | ||
11603 | case SE_R: | |
11604 | if (!(inst.operands[j].isreg | |
11605 | && !inst.operands[j].isvec)) | |
11606 | matches = 0; | |
11607 | break; | |
11608 | ||
11609 | case SE_Q: | |
11610 | if (!(inst.operands[j].isreg | |
11611 | && inst.operands[j].isvec | |
11612 | && inst.operands[j].isquad | |
11613 | && !inst.operands[j].issingle)) | |
11614 | matches = 0; | |
11615 | break; | |
11616 | ||
11617 | case SE_I: | |
11618 | if (!(!inst.operands[j].isreg | |
11619 | && !inst.operands[j].isscalar)) | |
11620 | matches = 0; | |
11621 | break; | |
11622 | ||
11623 | case SE_S: | |
11624 | if (!(!inst.operands[j].isreg | |
11625 | && inst.operands[j].isscalar)) | |
11626 | matches = 0; | |
11627 | break; | |
11628 | ||
11629 | case SE_L: | |
11630 | break; | |
11631 | } | |
11632 | } | |
11633 | if (matches) | |
5287ad62 | 11634 | break; |
037e8744 | 11635 | } |
5f4273c7 | 11636 | |
037e8744 | 11637 | va_end (ap); |
5287ad62 | 11638 | |
037e8744 JB |
11639 | if (shape == NS_NULL && first_shape != NS_NULL) |
11640 | first_error (_("invalid instruction shape")); | |
5287ad62 | 11641 | |
037e8744 JB |
11642 | return shape; |
11643 | } | |
5287ad62 | 11644 | |
037e8744 JB |
11645 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
11646 | means the Q bit should be set). */ | |
11647 | ||
11648 | static int | |
11649 | neon_quad (enum neon_shape shape) | |
11650 | { | |
11651 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 11652 | } |
037e8744 | 11653 | |
5287ad62 JB |
11654 | static void |
11655 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
11656 | unsigned *g_size) | |
11657 | { | |
11658 | /* Allow modification to be made to types which are constrained to be | |
11659 | based on the key element, based on bits set alongside N_EQK. */ | |
11660 | if ((typebits & N_EQK) != 0) | |
11661 | { | |
11662 | if ((typebits & N_HLF) != 0) | |
11663 | *g_size /= 2; | |
11664 | else if ((typebits & N_DBL) != 0) | |
11665 | *g_size *= 2; | |
11666 | if ((typebits & N_SGN) != 0) | |
11667 | *g_type = NT_signed; | |
11668 | else if ((typebits & N_UNS) != 0) | |
11669 | *g_type = NT_unsigned; | |
11670 | else if ((typebits & N_INT) != 0) | |
11671 | *g_type = NT_integer; | |
11672 | else if ((typebits & N_FLT) != 0) | |
11673 | *g_type = NT_float; | |
dcbf9037 JB |
11674 | else if ((typebits & N_SIZ) != 0) |
11675 | *g_type = NT_untyped; | |
5287ad62 JB |
11676 | } |
11677 | } | |
5f4273c7 | 11678 | |
5287ad62 JB |
11679 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
11680 | operand type, i.e. the single type specified in a Neon instruction when it | |
11681 | is the only one given. */ | |
11682 | ||
11683 | static struct neon_type_el | |
11684 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
11685 | { | |
11686 | struct neon_type_el dest = *key; | |
5f4273c7 | 11687 | |
9c2799c2 | 11688 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 11689 | |
5287ad62 JB |
11690 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
11691 | ||
11692 | return dest; | |
11693 | } | |
11694 | ||
11695 | /* Convert Neon type and size into compact bitmask representation. */ | |
11696 | ||
11697 | static enum neon_type_mask | |
11698 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
11699 | { | |
11700 | switch (type) | |
11701 | { | |
11702 | case NT_untyped: | |
11703 | switch (size) | |
11704 | { | |
11705 | case 8: return N_8; | |
11706 | case 16: return N_16; | |
11707 | case 32: return N_32; | |
11708 | case 64: return N_64; | |
11709 | default: ; | |
11710 | } | |
11711 | break; | |
11712 | ||
11713 | case NT_integer: | |
11714 | switch (size) | |
11715 | { | |
11716 | case 8: return N_I8; | |
11717 | case 16: return N_I16; | |
11718 | case 32: return N_I32; | |
11719 | case 64: return N_I64; | |
11720 | default: ; | |
11721 | } | |
11722 | break; | |
11723 | ||
11724 | case NT_float: | |
037e8744 JB |
11725 | switch (size) |
11726 | { | |
8e79c3df | 11727 | case 16: return N_F16; |
037e8744 JB |
11728 | case 32: return N_F32; |
11729 | case 64: return N_F64; | |
11730 | default: ; | |
11731 | } | |
5287ad62 JB |
11732 | break; |
11733 | ||
11734 | case NT_poly: | |
11735 | switch (size) | |
11736 | { | |
11737 | case 8: return N_P8; | |
11738 | case 16: return N_P16; | |
11739 | default: ; | |
11740 | } | |
11741 | break; | |
11742 | ||
11743 | case NT_signed: | |
11744 | switch (size) | |
11745 | { | |
11746 | case 8: return N_S8; | |
11747 | case 16: return N_S16; | |
11748 | case 32: return N_S32; | |
11749 | case 64: return N_S64; | |
11750 | default: ; | |
11751 | } | |
11752 | break; | |
11753 | ||
11754 | case NT_unsigned: | |
11755 | switch (size) | |
11756 | { | |
11757 | case 8: return N_U8; | |
11758 | case 16: return N_U16; | |
11759 | case 32: return N_U32; | |
11760 | case 64: return N_U64; | |
11761 | default: ; | |
11762 | } | |
11763 | break; | |
11764 | ||
11765 | default: ; | |
11766 | } | |
5f4273c7 | 11767 | |
5287ad62 JB |
11768 | return N_UTYP; |
11769 | } | |
11770 | ||
11771 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
11772 | handles the case where a single bit is set in the mask. */ | |
11773 | ||
dcbf9037 | 11774 | static int |
5287ad62 JB |
11775 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
11776 | enum neon_type_mask mask) | |
11777 | { | |
dcbf9037 JB |
11778 | if ((mask & N_EQK) != 0) |
11779 | return FAIL; | |
11780 | ||
5287ad62 JB |
11781 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
11782 | *size = 8; | |
dcbf9037 | 11783 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0) |
5287ad62 | 11784 | *size = 16; |
dcbf9037 | 11785 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 11786 | *size = 32; |
037e8744 | 11787 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0) |
5287ad62 | 11788 | *size = 64; |
dcbf9037 JB |
11789 | else |
11790 | return FAIL; | |
11791 | ||
5287ad62 JB |
11792 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
11793 | *type = NT_signed; | |
dcbf9037 | 11794 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 11795 | *type = NT_unsigned; |
dcbf9037 | 11796 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 11797 | *type = NT_integer; |
dcbf9037 | 11798 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 11799 | *type = NT_untyped; |
dcbf9037 | 11800 | else if ((mask & (N_P8 | N_P16)) != 0) |
5287ad62 | 11801 | *type = NT_poly; |
037e8744 | 11802 | else if ((mask & (N_F32 | N_F64)) != 0) |
5287ad62 | 11803 | *type = NT_float; |
dcbf9037 JB |
11804 | else |
11805 | return FAIL; | |
5f4273c7 | 11806 | |
dcbf9037 | 11807 | return SUCCESS; |
5287ad62 JB |
11808 | } |
11809 | ||
11810 | /* Modify a bitmask of allowed types. This is only needed for type | |
11811 | relaxation. */ | |
11812 | ||
11813 | static unsigned | |
11814 | modify_types_allowed (unsigned allowed, unsigned mods) | |
11815 | { | |
11816 | unsigned size; | |
11817 | enum neon_el_type type; | |
11818 | unsigned destmask; | |
11819 | int i; | |
5f4273c7 | 11820 | |
5287ad62 | 11821 | destmask = 0; |
5f4273c7 | 11822 | |
5287ad62 JB |
11823 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
11824 | { | |
dcbf9037 JB |
11825 | if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS) |
11826 | { | |
11827 | neon_modify_type_size (mods, &type, &size); | |
11828 | destmask |= type_chk_of_el_type (type, size); | |
11829 | } | |
5287ad62 | 11830 | } |
5f4273c7 | 11831 | |
5287ad62 JB |
11832 | return destmask; |
11833 | } | |
11834 | ||
11835 | /* Check type and return type classification. | |
11836 | The manual states (paraphrase): If one datatype is given, it indicates the | |
11837 | type given in: | |
11838 | - the second operand, if there is one | |
11839 | - the operand, if there is no second operand | |
11840 | - the result, if there are no operands. | |
11841 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
11842 | which is set on a per-instruction basis, which is the one which matters when | |
11843 | only one data type is written. | |
11844 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 11845 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
11846 | |
11847 | static struct neon_type_el | |
11848 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
11849 | { | |
11850 | va_list ap; | |
11851 | unsigned i, pass, key_el = 0; | |
11852 | unsigned types[NEON_MAX_TYPE_ELS]; | |
11853 | enum neon_el_type k_type = NT_invtype; | |
11854 | unsigned k_size = -1u; | |
11855 | struct neon_type_el badtype = {NT_invtype, -1}; | |
11856 | unsigned key_allowed = 0; | |
11857 | ||
11858 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
11859 | Fill in the missing operand here, if it was omitted. */ | |
11860 | if (els > 1 && !inst.operands[1].present) | |
11861 | inst.operands[1] = inst.operands[0]; | |
11862 | ||
11863 | /* Suck up all the varargs. */ | |
11864 | va_start (ap, ns); | |
11865 | for (i = 0; i < els; i++) | |
11866 | { | |
11867 | unsigned thisarg = va_arg (ap, unsigned); | |
11868 | if (thisarg == N_IGNORE_TYPE) | |
11869 | { | |
11870 | va_end (ap); | |
11871 | return badtype; | |
11872 | } | |
11873 | types[i] = thisarg; | |
11874 | if ((thisarg & N_KEY) != 0) | |
11875 | key_el = i; | |
11876 | } | |
11877 | va_end (ap); | |
11878 | ||
dcbf9037 JB |
11879 | if (inst.vectype.elems > 0) |
11880 | for (i = 0; i < els; i++) | |
11881 | if (inst.operands[i].vectype.type != NT_invtype) | |
11882 | { | |
11883 | first_error (_("types specified in both the mnemonic and operands")); | |
11884 | return badtype; | |
11885 | } | |
11886 | ||
5287ad62 JB |
11887 | /* Duplicate inst.vectype elements here as necessary. |
11888 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
11889 | particularly when an insn takes one register and one non-register | |
11890 | operand. */ | |
11891 | if (inst.vectype.elems == 1 && els > 1) | |
11892 | { | |
11893 | unsigned j; | |
11894 | inst.vectype.elems = els; | |
11895 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
11896 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
11897 | if (j != key_el) |
11898 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
11899 | types[j]); | |
11900 | } | |
11901 | else if (inst.vectype.elems == 0 && els > 0) | |
11902 | { | |
11903 | unsigned j; | |
11904 | /* No types were given after the mnemonic, so look for types specified | |
11905 | after each operand. We allow some flexibility here; as long as the | |
11906 | "key" operand has a type, we can infer the others. */ | |
11907 | for (j = 0; j < els; j++) | |
11908 | if (inst.operands[j].vectype.type != NT_invtype) | |
11909 | inst.vectype.el[j] = inst.operands[j].vectype; | |
11910 | ||
11911 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 11912 | { |
dcbf9037 JB |
11913 | for (j = 0; j < els; j++) |
11914 | if (inst.operands[j].vectype.type == NT_invtype) | |
11915 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
11916 | types[j]); | |
11917 | } | |
11918 | else | |
11919 | { | |
11920 | first_error (_("operand types can't be inferred")); | |
11921 | return badtype; | |
5287ad62 JB |
11922 | } |
11923 | } | |
11924 | else if (inst.vectype.elems != els) | |
11925 | { | |
dcbf9037 | 11926 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
11927 | return badtype; |
11928 | } | |
11929 | ||
11930 | for (pass = 0; pass < 2; pass++) | |
11931 | { | |
11932 | for (i = 0; i < els; i++) | |
11933 | { | |
11934 | unsigned thisarg = types[i]; | |
11935 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
11936 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
11937 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
11938 | unsigned g_size = inst.vectype.el[i].size; | |
11939 | ||
11940 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
11941 | integer types if sign-specific variants are unavailable. */ | |
11942 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
11943 | && (types_allowed & N_SU_ALL) == 0) | |
11944 | g_type = NT_integer; | |
11945 | ||
11946 | /* If only untyped args are allowed, decay any more specific types to | |
11947 | them. Some instructions only care about signs for some element | |
11948 | sizes, so handle that properly. */ | |
11949 | if ((g_size == 8 && (types_allowed & N_8) != 0) | |
11950 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
11951 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
11952 | || (g_size == 64 && (types_allowed & N_64) != 0)) | |
11953 | g_type = NT_untyped; | |
11954 | ||
11955 | if (pass == 0) | |
11956 | { | |
11957 | if ((thisarg & N_KEY) != 0) | |
11958 | { | |
11959 | k_type = g_type; | |
11960 | k_size = g_size; | |
11961 | key_allowed = thisarg & ~N_KEY; | |
11962 | } | |
11963 | } | |
11964 | else | |
11965 | { | |
037e8744 JB |
11966 | if ((thisarg & N_VFP) != 0) |
11967 | { | |
11968 | enum neon_shape_el regshape = neon_shape_tab[ns].el[i]; | |
11969 | unsigned regwidth = neon_shape_el_size[regshape], match; | |
11970 | ||
11971 | /* In VFP mode, operands must match register widths. If we | |
11972 | have a key operand, use its width, else use the width of | |
11973 | the current operand. */ | |
11974 | if (k_size != -1u) | |
11975 | match = k_size; | |
11976 | else | |
11977 | match = g_size; | |
11978 | ||
11979 | if (regwidth != match) | |
11980 | { | |
11981 | first_error (_("operand size must match register width")); | |
11982 | return badtype; | |
11983 | } | |
11984 | } | |
5f4273c7 | 11985 | |
5287ad62 JB |
11986 | if ((thisarg & N_EQK) == 0) |
11987 | { | |
11988 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
11989 | ||
11990 | if ((given_type & types_allowed) == 0) | |
11991 | { | |
dcbf9037 | 11992 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
11993 | return badtype; |
11994 | } | |
11995 | } | |
11996 | else | |
11997 | { | |
11998 | enum neon_el_type mod_k_type = k_type; | |
11999 | unsigned mod_k_size = k_size; | |
12000 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
12001 | if (g_type != mod_k_type || g_size != mod_k_size) | |
12002 | { | |
dcbf9037 | 12003 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
12004 | return badtype; |
12005 | } | |
12006 | } | |
12007 | } | |
12008 | } | |
12009 | } | |
12010 | ||
12011 | return inst.vectype.el[key_el]; | |
12012 | } | |
12013 | ||
037e8744 | 12014 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 12015 | |
037e8744 JB |
12016 | /* Thumb VFP instructions have 0xE in the condition field. */ |
12017 | ||
12018 | static void | |
12019 | do_vfp_cond_or_thumb (void) | |
5287ad62 JB |
12020 | { |
12021 | if (thumb_mode) | |
037e8744 | 12022 | inst.instruction |= 0xe0000000; |
5287ad62 | 12023 | else |
037e8744 | 12024 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
12025 | } |
12026 | ||
037e8744 JB |
12027 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
12028 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
12029 | etc. It is assumed that operand parsing has already been done, and that the | |
12030 | operands are in the form expected by the given opcode (this isn't necessarily | |
12031 | the same as the form in which they were parsed, hence some massaging must | |
12032 | take place before this function is called). | |
12033 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 12034 | |
037e8744 JB |
12035 | static void |
12036 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 12037 | { |
037e8744 | 12038 | const struct asm_opcode *opcode; |
5f4273c7 | 12039 | |
037e8744 | 12040 | opcode = hash_find (arm_ops_hsh, opname); |
5287ad62 | 12041 | |
037e8744 JB |
12042 | if (!opcode) |
12043 | abort (); | |
5287ad62 | 12044 | |
037e8744 JB |
12045 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
12046 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
12047 | _(BAD_FPU)); | |
5287ad62 | 12048 | |
037e8744 JB |
12049 | if (thumb_mode) |
12050 | { | |
12051 | inst.instruction = opcode->tvalue; | |
12052 | opcode->tencode (); | |
12053 | } | |
12054 | else | |
12055 | { | |
12056 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
12057 | opcode->aencode (); | |
12058 | } | |
12059 | } | |
5287ad62 JB |
12060 | |
12061 | static void | |
037e8744 | 12062 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 12063 | { |
037e8744 JB |
12064 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
12065 | ||
12066 | if (rs == NS_FFF) | |
12067 | { | |
12068 | if (is_add) | |
12069 | do_vfp_nsyn_opcode ("fadds"); | |
12070 | else | |
12071 | do_vfp_nsyn_opcode ("fsubs"); | |
12072 | } | |
12073 | else | |
12074 | { | |
12075 | if (is_add) | |
12076 | do_vfp_nsyn_opcode ("faddd"); | |
12077 | else | |
12078 | do_vfp_nsyn_opcode ("fsubd"); | |
12079 | } | |
12080 | } | |
12081 | ||
12082 | /* Check operand types to see if this is a VFP instruction, and if so call | |
12083 | PFN (). */ | |
12084 | ||
12085 | static int | |
12086 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
12087 | { | |
12088 | enum neon_shape rs; | |
12089 | struct neon_type_el et; | |
12090 | ||
12091 | switch (args) | |
12092 | { | |
12093 | case 2: | |
12094 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12095 | et = neon_check_type (2, rs, | |
12096 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12097 | break; | |
5f4273c7 | 12098 | |
037e8744 JB |
12099 | case 3: |
12100 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12101 | et = neon_check_type (3, rs, | |
12102 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12103 | break; | |
12104 | ||
12105 | default: | |
12106 | abort (); | |
12107 | } | |
12108 | ||
12109 | if (et.type != NT_invtype) | |
12110 | { | |
12111 | pfn (rs); | |
12112 | return SUCCESS; | |
12113 | } | |
12114 | else | |
12115 | inst.error = NULL; | |
12116 | ||
12117 | return FAIL; | |
12118 | } | |
12119 | ||
12120 | static void | |
12121 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
12122 | { | |
12123 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 12124 | |
037e8744 JB |
12125 | if (rs == NS_FFF) |
12126 | { | |
12127 | if (is_mla) | |
12128 | do_vfp_nsyn_opcode ("fmacs"); | |
12129 | else | |
12130 | do_vfp_nsyn_opcode ("fmscs"); | |
12131 | } | |
12132 | else | |
12133 | { | |
12134 | if (is_mla) | |
12135 | do_vfp_nsyn_opcode ("fmacd"); | |
12136 | else | |
12137 | do_vfp_nsyn_opcode ("fmscd"); | |
12138 | } | |
12139 | } | |
12140 | ||
12141 | static void | |
12142 | do_vfp_nsyn_mul (enum neon_shape rs) | |
12143 | { | |
12144 | if (rs == NS_FFF) | |
12145 | do_vfp_nsyn_opcode ("fmuls"); | |
12146 | else | |
12147 | do_vfp_nsyn_opcode ("fmuld"); | |
12148 | } | |
12149 | ||
12150 | static void | |
12151 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
12152 | { | |
12153 | int is_neg = (inst.instruction & 0x80) != 0; | |
12154 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
12155 | ||
12156 | if (rs == NS_FF) | |
12157 | { | |
12158 | if (is_neg) | |
12159 | do_vfp_nsyn_opcode ("fnegs"); | |
12160 | else | |
12161 | do_vfp_nsyn_opcode ("fabss"); | |
12162 | } | |
12163 | else | |
12164 | { | |
12165 | if (is_neg) | |
12166 | do_vfp_nsyn_opcode ("fnegd"); | |
12167 | else | |
12168 | do_vfp_nsyn_opcode ("fabsd"); | |
12169 | } | |
12170 | } | |
12171 | ||
12172 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
12173 | insns belong to Neon, and are handled elsewhere. */ | |
12174 | ||
12175 | static void | |
12176 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
12177 | { | |
12178 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
12179 | if (is_ldm) | |
12180 | { | |
12181 | if (is_dbmode) | |
12182 | do_vfp_nsyn_opcode ("fldmdbs"); | |
12183 | else | |
12184 | do_vfp_nsyn_opcode ("fldmias"); | |
12185 | } | |
12186 | else | |
12187 | { | |
12188 | if (is_dbmode) | |
12189 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12190 | else | |
12191 | do_vfp_nsyn_opcode ("fstmias"); | |
12192 | } | |
12193 | } | |
12194 | ||
037e8744 JB |
12195 | static void |
12196 | do_vfp_nsyn_sqrt (void) | |
12197 | { | |
12198 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12199 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12200 | |
037e8744 JB |
12201 | if (rs == NS_FF) |
12202 | do_vfp_nsyn_opcode ("fsqrts"); | |
12203 | else | |
12204 | do_vfp_nsyn_opcode ("fsqrtd"); | |
12205 | } | |
12206 | ||
12207 | static void | |
12208 | do_vfp_nsyn_div (void) | |
12209 | { | |
12210 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12211 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12212 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12213 | |
037e8744 JB |
12214 | if (rs == NS_FFF) |
12215 | do_vfp_nsyn_opcode ("fdivs"); | |
12216 | else | |
12217 | do_vfp_nsyn_opcode ("fdivd"); | |
12218 | } | |
12219 | ||
12220 | static void | |
12221 | do_vfp_nsyn_nmul (void) | |
12222 | { | |
12223 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12224 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12225 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12226 | |
037e8744 JB |
12227 | if (rs == NS_FFF) |
12228 | { | |
12229 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12230 | do_vfp_sp_dyadic (); | |
12231 | } | |
12232 | else | |
12233 | { | |
12234 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12235 | do_vfp_dp_rd_rn_rm (); | |
12236 | } | |
12237 | do_vfp_cond_or_thumb (); | |
12238 | } | |
12239 | ||
12240 | static void | |
12241 | do_vfp_nsyn_cmp (void) | |
12242 | { | |
12243 | if (inst.operands[1].isreg) | |
12244 | { | |
12245 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12246 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12247 | |
037e8744 JB |
12248 | if (rs == NS_FF) |
12249 | { | |
12250 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12251 | do_vfp_sp_monadic (); | |
12252 | } | |
12253 | else | |
12254 | { | |
12255 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12256 | do_vfp_dp_rd_rm (); | |
12257 | } | |
12258 | } | |
12259 | else | |
12260 | { | |
12261 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
12262 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
12263 | ||
12264 | switch (inst.instruction & 0x0fffffff) | |
12265 | { | |
12266 | case N_MNEM_vcmp: | |
12267 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
12268 | break; | |
12269 | case N_MNEM_vcmpe: | |
12270 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
12271 | break; | |
12272 | default: | |
12273 | abort (); | |
12274 | } | |
5f4273c7 | 12275 | |
037e8744 JB |
12276 | if (rs == NS_FI) |
12277 | { | |
12278 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12279 | do_vfp_sp_compare_z (); | |
12280 | } | |
12281 | else | |
12282 | { | |
12283 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12284 | do_vfp_dp_rd (); | |
12285 | } | |
12286 | } | |
12287 | do_vfp_cond_or_thumb (); | |
12288 | } | |
12289 | ||
12290 | static void | |
12291 | nsyn_insert_sp (void) | |
12292 | { | |
12293 | inst.operands[1] = inst.operands[0]; | |
12294 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 12295 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
12296 | inst.operands[0].isreg = 1; |
12297 | inst.operands[0].writeback = 1; | |
12298 | inst.operands[0].present = 1; | |
12299 | } | |
12300 | ||
12301 | static void | |
12302 | do_vfp_nsyn_push (void) | |
12303 | { | |
12304 | nsyn_insert_sp (); | |
12305 | if (inst.operands[1].issingle) | |
12306 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12307 | else | |
12308 | do_vfp_nsyn_opcode ("fstmdbd"); | |
12309 | } | |
12310 | ||
12311 | static void | |
12312 | do_vfp_nsyn_pop (void) | |
12313 | { | |
12314 | nsyn_insert_sp (); | |
12315 | if (inst.operands[1].issingle) | |
22b5b651 | 12316 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 12317 | else |
22b5b651 | 12318 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
12319 | } |
12320 | ||
12321 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
12322 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
12323 | ||
12324 | static unsigned | |
12325 | neon_dp_fixup (unsigned i) | |
12326 | { | |
12327 | if (thumb_mode) | |
12328 | { | |
12329 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
12330 | if (i & (1 << 24)) | |
12331 | i |= 1 << 28; | |
5f4273c7 | 12332 | |
037e8744 | 12333 | i &= ~(1 << 24); |
5f4273c7 | 12334 | |
037e8744 JB |
12335 | i |= 0xef000000; |
12336 | } | |
12337 | else | |
12338 | i |= 0xf2000000; | |
5f4273c7 | 12339 | |
037e8744 JB |
12340 | return i; |
12341 | } | |
12342 | ||
12343 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
12344 | (0, 1, 2, 3). */ | |
12345 | ||
12346 | static unsigned | |
12347 | neon_logbits (unsigned x) | |
12348 | { | |
12349 | return ffs (x) - 4; | |
12350 | } | |
12351 | ||
12352 | #define LOW4(R) ((R) & 0xf) | |
12353 | #define HI1(R) (((R) >> 4) & 1) | |
12354 | ||
12355 | /* Encode insns with bit pattern: | |
12356 | ||
12357 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
12358 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 12359 | |
037e8744 JB |
12360 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
12361 | different meaning for some instruction. */ | |
12362 | ||
12363 | static void | |
12364 | neon_three_same (int isquad, int ubit, int size) | |
12365 | { | |
12366 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12367 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12368 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12369 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12370 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12371 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12372 | inst.instruction |= (isquad != 0) << 6; | |
12373 | inst.instruction |= (ubit != 0) << 24; | |
12374 | if (size != -1) | |
12375 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 12376 | |
037e8744 JB |
12377 | inst.instruction = neon_dp_fixup (inst.instruction); |
12378 | } | |
12379 | ||
12380 | /* Encode instructions of the form: | |
12381 | ||
12382 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
12383 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
12384 | |
12385 | Don't write size if SIZE == -1. */ | |
12386 | ||
12387 | static void | |
12388 | neon_two_same (int qbit, int ubit, int size) | |
12389 | { | |
12390 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12391 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12392 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12393 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12394 | inst.instruction |= (qbit != 0) << 6; | |
12395 | inst.instruction |= (ubit != 0) << 24; | |
12396 | ||
12397 | if (size != -1) | |
12398 | inst.instruction |= neon_logbits (size) << 18; | |
12399 | ||
12400 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12401 | } | |
12402 | ||
12403 | /* Neon instruction encoders, in approximate order of appearance. */ | |
12404 | ||
12405 | static void | |
12406 | do_neon_dyadic_i_su (void) | |
12407 | { | |
037e8744 | 12408 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12409 | struct neon_type_el et = neon_check_type (3, rs, |
12410 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 12411 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12412 | } |
12413 | ||
12414 | static void | |
12415 | do_neon_dyadic_i64_su (void) | |
12416 | { | |
037e8744 | 12417 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12418 | struct neon_type_el et = neon_check_type (3, rs, |
12419 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 12420 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12421 | } |
12422 | ||
12423 | static void | |
12424 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
12425 | unsigned immbits) | |
12426 | { | |
12427 | unsigned size = et.size >> 3; | |
12428 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12429 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12430 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12431 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12432 | inst.instruction |= (isquad != 0) << 6; | |
12433 | inst.instruction |= immbits << 16; | |
12434 | inst.instruction |= (size >> 3) << 7; | |
12435 | inst.instruction |= (size & 0x7) << 19; | |
12436 | if (write_ubit) | |
12437 | inst.instruction |= (uval != 0) << 24; | |
12438 | ||
12439 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12440 | } | |
12441 | ||
12442 | static void | |
12443 | do_neon_shl_imm (void) | |
12444 | { | |
12445 | if (!inst.operands[2].isreg) | |
12446 | { | |
037e8744 | 12447 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12448 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
12449 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 12450 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
12451 | } |
12452 | else | |
12453 | { | |
037e8744 | 12454 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12455 | struct neon_type_el et = neon_check_type (3, rs, |
12456 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12457 | unsigned int tmp; |
12458 | ||
12459 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
12460 | vshl.xx Dd, Dm, Dn | |
12461 | whereas other 3-register operations encoded by neon_three_same have | |
12462 | syntax like: | |
12463 | vadd.xx Dd, Dn, Dm | |
12464 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
12465 | here. */ | |
12466 | tmp = inst.operands[2].reg; | |
12467 | inst.operands[2].reg = inst.operands[1].reg; | |
12468 | inst.operands[1].reg = tmp; | |
5287ad62 | 12469 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
037e8744 | 12470 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12471 | } |
12472 | } | |
12473 | ||
12474 | static void | |
12475 | do_neon_qshl_imm (void) | |
12476 | { | |
12477 | if (!inst.operands[2].isreg) | |
12478 | { | |
037e8744 | 12479 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 12480 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
627907b7 | 12481 | |
5287ad62 | 12482 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
037e8744 | 12483 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
12484 | inst.operands[2].imm); |
12485 | } | |
12486 | else | |
12487 | { | |
037e8744 | 12488 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12489 | struct neon_type_el et = neon_check_type (3, rs, |
12490 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12491 | unsigned int tmp; |
12492 | ||
12493 | /* See note in do_neon_shl_imm. */ | |
12494 | tmp = inst.operands[2].reg; | |
12495 | inst.operands[2].reg = inst.operands[1].reg; | |
12496 | inst.operands[1].reg = tmp; | |
5287ad62 | 12497 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
037e8744 | 12498 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12499 | } |
12500 | } | |
12501 | ||
627907b7 JB |
12502 | static void |
12503 | do_neon_rshl (void) | |
12504 | { | |
12505 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
12506 | struct neon_type_el et = neon_check_type (3, rs, | |
12507 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
12508 | unsigned int tmp; | |
12509 | ||
12510 | tmp = inst.operands[2].reg; | |
12511 | inst.operands[2].reg = inst.operands[1].reg; | |
12512 | inst.operands[1].reg = tmp; | |
12513 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
12514 | } | |
12515 | ||
5287ad62 JB |
12516 | static int |
12517 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
12518 | { | |
036dc3f7 PB |
12519 | /* Handle .I8 pseudo-instructions. */ |
12520 | if (size == 8) | |
5287ad62 | 12521 | { |
5287ad62 JB |
12522 | /* Unfortunately, this will make everything apart from zero out-of-range. |
12523 | FIXME is this the intended semantics? There doesn't seem much point in | |
12524 | accepting .I8 if so. */ | |
12525 | immediate |= immediate << 8; | |
12526 | size = 16; | |
036dc3f7 PB |
12527 | } |
12528 | ||
12529 | if (size >= 32) | |
12530 | { | |
12531 | if (immediate == (immediate & 0x000000ff)) | |
12532 | { | |
12533 | *immbits = immediate; | |
12534 | return 0x1; | |
12535 | } | |
12536 | else if (immediate == (immediate & 0x0000ff00)) | |
12537 | { | |
12538 | *immbits = immediate >> 8; | |
12539 | return 0x3; | |
12540 | } | |
12541 | else if (immediate == (immediate & 0x00ff0000)) | |
12542 | { | |
12543 | *immbits = immediate >> 16; | |
12544 | return 0x5; | |
12545 | } | |
12546 | else if (immediate == (immediate & 0xff000000)) | |
12547 | { | |
12548 | *immbits = immediate >> 24; | |
12549 | return 0x7; | |
12550 | } | |
12551 | if ((immediate & 0xffff) != (immediate >> 16)) | |
12552 | goto bad_immediate; | |
12553 | immediate &= 0xffff; | |
5287ad62 JB |
12554 | } |
12555 | ||
12556 | if (immediate == (immediate & 0x000000ff)) | |
12557 | { | |
12558 | *immbits = immediate; | |
036dc3f7 | 12559 | return 0x9; |
5287ad62 JB |
12560 | } |
12561 | else if (immediate == (immediate & 0x0000ff00)) | |
12562 | { | |
12563 | *immbits = immediate >> 8; | |
036dc3f7 | 12564 | return 0xb; |
5287ad62 JB |
12565 | } |
12566 | ||
12567 | bad_immediate: | |
dcbf9037 | 12568 | first_error (_("immediate value out of range")); |
5287ad62 JB |
12569 | return FAIL; |
12570 | } | |
12571 | ||
12572 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
12573 | A, B, C, D. */ | |
12574 | ||
12575 | static int | |
12576 | neon_bits_same_in_bytes (unsigned imm) | |
12577 | { | |
12578 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
12579 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
12580 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
12581 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
12582 | } | |
12583 | ||
12584 | /* For immediate of above form, return 0bABCD. */ | |
12585 | ||
12586 | static unsigned | |
12587 | neon_squash_bits (unsigned imm) | |
12588 | { | |
12589 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
12590 | | ((imm & 0x01000000) >> 21); | |
12591 | } | |
12592 | ||
136da414 | 12593 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
12594 | |
12595 | static unsigned | |
12596 | neon_qfloat_bits (unsigned imm) | |
12597 | { | |
136da414 | 12598 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
12599 | } |
12600 | ||
12601 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
12602 | the instruction. *OP is passed as the initial value of the op field, and | |
12603 | may be set to a different value depending on the constant (i.e. | |
12604 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
5f4273c7 | 12605 | MVN). If the immediate looks like a repeated pattern then also |
036dc3f7 | 12606 | try smaller element sizes. */ |
5287ad62 JB |
12607 | |
12608 | static int | |
c96612cc JB |
12609 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, |
12610 | unsigned *immbits, int *op, int size, | |
12611 | enum neon_el_type type) | |
5287ad62 | 12612 | { |
c96612cc JB |
12613 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is |
12614 | float. */ | |
12615 | if (type == NT_float && !float_p) | |
12616 | return FAIL; | |
12617 | ||
136da414 JB |
12618 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
12619 | { | |
12620 | if (size != 32 || *op == 1) | |
12621 | return FAIL; | |
12622 | *immbits = neon_qfloat_bits (immlo); | |
12623 | return 0xf; | |
12624 | } | |
036dc3f7 PB |
12625 | |
12626 | if (size == 64) | |
5287ad62 | 12627 | { |
036dc3f7 PB |
12628 | if (neon_bits_same_in_bytes (immhi) |
12629 | && neon_bits_same_in_bytes (immlo)) | |
12630 | { | |
12631 | if (*op == 1) | |
12632 | return FAIL; | |
12633 | *immbits = (neon_squash_bits (immhi) << 4) | |
12634 | | neon_squash_bits (immlo); | |
12635 | *op = 1; | |
12636 | return 0xe; | |
12637 | } | |
12638 | ||
12639 | if (immhi != immlo) | |
12640 | return FAIL; | |
5287ad62 | 12641 | } |
036dc3f7 PB |
12642 | |
12643 | if (size >= 32) | |
5287ad62 | 12644 | { |
036dc3f7 PB |
12645 | if (immlo == (immlo & 0x000000ff)) |
12646 | { | |
12647 | *immbits = immlo; | |
12648 | return 0x0; | |
12649 | } | |
12650 | else if (immlo == (immlo & 0x0000ff00)) | |
12651 | { | |
12652 | *immbits = immlo >> 8; | |
12653 | return 0x2; | |
12654 | } | |
12655 | else if (immlo == (immlo & 0x00ff0000)) | |
12656 | { | |
12657 | *immbits = immlo >> 16; | |
12658 | return 0x4; | |
12659 | } | |
12660 | else if (immlo == (immlo & 0xff000000)) | |
12661 | { | |
12662 | *immbits = immlo >> 24; | |
12663 | return 0x6; | |
12664 | } | |
12665 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
12666 | { | |
12667 | *immbits = (immlo >> 8) & 0xff; | |
12668 | return 0xc; | |
12669 | } | |
12670 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
12671 | { | |
12672 | *immbits = (immlo >> 16) & 0xff; | |
12673 | return 0xd; | |
12674 | } | |
12675 | ||
12676 | if ((immlo & 0xffff) != (immlo >> 16)) | |
12677 | return FAIL; | |
12678 | immlo &= 0xffff; | |
5287ad62 | 12679 | } |
036dc3f7 PB |
12680 | |
12681 | if (size >= 16) | |
5287ad62 | 12682 | { |
036dc3f7 PB |
12683 | if (immlo == (immlo & 0x000000ff)) |
12684 | { | |
12685 | *immbits = immlo; | |
12686 | return 0x8; | |
12687 | } | |
12688 | else if (immlo == (immlo & 0x0000ff00)) | |
12689 | { | |
12690 | *immbits = immlo >> 8; | |
12691 | return 0xa; | |
12692 | } | |
12693 | ||
12694 | if ((immlo & 0xff) != (immlo >> 8)) | |
12695 | return FAIL; | |
12696 | immlo &= 0xff; | |
5287ad62 | 12697 | } |
036dc3f7 PB |
12698 | |
12699 | if (immlo == (immlo & 0x000000ff)) | |
5287ad62 | 12700 | { |
036dc3f7 PB |
12701 | /* Don't allow MVN with 8-bit immediate. */ |
12702 | if (*op == 1) | |
12703 | return FAIL; | |
12704 | *immbits = immlo; | |
12705 | return 0xe; | |
5287ad62 | 12706 | } |
5287ad62 JB |
12707 | |
12708 | return FAIL; | |
12709 | } | |
12710 | ||
12711 | /* Write immediate bits [7:0] to the following locations: | |
12712 | ||
12713 | |28/24|23 19|18 16|15 4|3 0| | |
12714 | | 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| | |
12715 | ||
12716 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
12717 | ||
12718 | static void | |
12719 | neon_write_immbits (unsigned immbits) | |
12720 | { | |
12721 | inst.instruction |= immbits & 0xf; | |
12722 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
12723 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
12724 | } | |
12725 | ||
12726 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
12727 | ||
12728 | static void | |
12729 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
12730 | { | |
12731 | unsigned immlo = xlo ? *xlo : 0; | |
12732 | unsigned immhi = xhi ? *xhi : 0; | |
12733 | ||
12734 | switch (size) | |
12735 | { | |
12736 | case 8: | |
12737 | immlo = (~immlo) & 0xff; | |
12738 | break; | |
12739 | ||
12740 | case 16: | |
12741 | immlo = (~immlo) & 0xffff; | |
12742 | break; | |
12743 | ||
12744 | case 64: | |
12745 | immhi = (~immhi) & 0xffffffff; | |
12746 | /* fall through. */ | |
12747 | ||
12748 | case 32: | |
12749 | immlo = (~immlo) & 0xffffffff; | |
12750 | break; | |
12751 | ||
12752 | default: | |
12753 | abort (); | |
12754 | } | |
12755 | ||
12756 | if (xlo) | |
12757 | *xlo = immlo; | |
12758 | ||
12759 | if (xhi) | |
12760 | *xhi = immhi; | |
12761 | } | |
12762 | ||
12763 | static void | |
12764 | do_neon_logic (void) | |
12765 | { | |
12766 | if (inst.operands[2].present && inst.operands[2].isreg) | |
12767 | { | |
037e8744 | 12768 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12769 | neon_check_type (3, rs, N_IGNORE_TYPE); |
12770 | /* U bit and size field were set as part of the bitmask. */ | |
12771 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12772 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12773 | } |
12774 | else | |
12775 | { | |
037e8744 JB |
12776 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
12777 | struct neon_type_el et = neon_check_type (2, rs, | |
12778 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 JB |
12779 | enum neon_opc opcode = inst.instruction & 0x0fffffff; |
12780 | unsigned immbits; | |
12781 | int cmode; | |
5f4273c7 | 12782 | |
5287ad62 JB |
12783 | if (et.type == NT_invtype) |
12784 | return; | |
5f4273c7 | 12785 | |
5287ad62 JB |
12786 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
12787 | ||
036dc3f7 PB |
12788 | immbits = inst.operands[1].imm; |
12789 | if (et.size == 64) | |
12790 | { | |
12791 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
12792 | pattern. */ | |
12793 | if (immbits != (inst.operands[1].regisimm ? | |
12794 | inst.operands[1].reg : 0)) | |
12795 | { | |
12796 | /* Set immbits to an invalid constant. */ | |
12797 | immbits = 0xdeadbeef; | |
12798 | } | |
12799 | } | |
12800 | ||
5287ad62 JB |
12801 | switch (opcode) |
12802 | { | |
12803 | case N_MNEM_vbic: | |
036dc3f7 | 12804 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 12805 | break; |
5f4273c7 | 12806 | |
5287ad62 | 12807 | case N_MNEM_vorr: |
036dc3f7 | 12808 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 12809 | break; |
5f4273c7 | 12810 | |
5287ad62 JB |
12811 | case N_MNEM_vand: |
12812 | /* Pseudo-instruction for VBIC. */ | |
5287ad62 JB |
12813 | neon_invert_size (&immbits, 0, et.size); |
12814 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
12815 | break; | |
5f4273c7 | 12816 | |
5287ad62 JB |
12817 | case N_MNEM_vorn: |
12818 | /* Pseudo-instruction for VORR. */ | |
5287ad62 JB |
12819 | neon_invert_size (&immbits, 0, et.size); |
12820 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
12821 | break; | |
5f4273c7 | 12822 | |
5287ad62 JB |
12823 | default: |
12824 | abort (); | |
12825 | } | |
12826 | ||
12827 | if (cmode == FAIL) | |
12828 | return; | |
12829 | ||
037e8744 | 12830 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12831 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
12832 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12833 | inst.instruction |= cmode << 8; | |
12834 | neon_write_immbits (immbits); | |
5f4273c7 | 12835 | |
5287ad62 JB |
12836 | inst.instruction = neon_dp_fixup (inst.instruction); |
12837 | } | |
12838 | } | |
12839 | ||
12840 | static void | |
12841 | do_neon_bitfield (void) | |
12842 | { | |
037e8744 | 12843 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 12844 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 12845 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12846 | } |
12847 | ||
12848 | static void | |
dcbf9037 JB |
12849 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
12850 | unsigned destbits) | |
5287ad62 | 12851 | { |
037e8744 | 12852 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
12853 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
12854 | types | N_KEY); | |
5287ad62 JB |
12855 | if (et.type == NT_float) |
12856 | { | |
12857 | inst.instruction = NEON_ENC_FLOAT (inst.instruction); | |
037e8744 | 12858 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12859 | } |
12860 | else | |
12861 | { | |
12862 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12863 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
12864 | } |
12865 | } | |
12866 | ||
12867 | static void | |
12868 | do_neon_dyadic_if_su (void) | |
12869 | { | |
dcbf9037 | 12870 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
12871 | } |
12872 | ||
12873 | static void | |
12874 | do_neon_dyadic_if_su_d (void) | |
12875 | { | |
12876 | /* This version only allow D registers, but that constraint is enforced during | |
12877 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 12878 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
12879 | } |
12880 | ||
5287ad62 JB |
12881 | static void |
12882 | do_neon_dyadic_if_i_d (void) | |
12883 | { | |
428e3f1f PB |
12884 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
12885 | affected if we specify unsigned args. */ | |
12886 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
12887 | } |
12888 | ||
037e8744 JB |
12889 | enum vfp_or_neon_is_neon_bits |
12890 | { | |
12891 | NEON_CHECK_CC = 1, | |
12892 | NEON_CHECK_ARCH = 2 | |
12893 | }; | |
12894 | ||
12895 | /* Call this function if an instruction which may have belonged to the VFP or | |
12896 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
12897 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
12898 | things: | |
12899 | ||
12900 | - Make sure the user hasn't attempted to make a Neon instruction | |
12901 | conditional. | |
12902 | - Alter the value in the condition code field if necessary. | |
12903 | - Make sure that the arch supports Neon instructions. | |
12904 | ||
12905 | Which of these operations take place depends on bits from enum | |
12906 | vfp_or_neon_is_neon_bits. | |
12907 | ||
12908 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
12909 | current instruction's condition is COND_ALWAYS, the condition field is | |
12910 | changed to inst.uncond_value. This is necessary because instructions shared | |
12911 | between VFP and Neon may be conditional for the VFP variants only, and the | |
12912 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
12913 | ||
12914 | static int | |
12915 | vfp_or_neon_is_neon (unsigned check) | |
12916 | { | |
12917 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
12918 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
12919 | { | |
12920 | if (inst.cond != COND_ALWAYS) | |
12921 | { | |
12922 | first_error (_(BAD_COND)); | |
12923 | return FAIL; | |
12924 | } | |
12925 | if (inst.uncond_value != -1) | |
12926 | inst.instruction |= inst.uncond_value << 28; | |
12927 | } | |
5f4273c7 | 12928 | |
037e8744 JB |
12929 | if ((check & NEON_CHECK_ARCH) |
12930 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
12931 | { | |
12932 | first_error (_(BAD_FPU)); | |
12933 | return FAIL; | |
12934 | } | |
5f4273c7 | 12935 | |
037e8744 JB |
12936 | return SUCCESS; |
12937 | } | |
12938 | ||
5287ad62 JB |
12939 | static void |
12940 | do_neon_addsub_if_i (void) | |
12941 | { | |
037e8744 JB |
12942 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
12943 | return; | |
12944 | ||
12945 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12946 | return; | |
12947 | ||
5287ad62 JB |
12948 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
12949 | affected if we specify unsigned args. */ | |
dcbf9037 | 12950 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
12951 | } |
12952 | ||
12953 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
12954 | result to be: | |
12955 | V<op> A,B (A is operand 0, B is operand 2) | |
12956 | to mean: | |
12957 | V<op> A,B,A | |
12958 | not: | |
12959 | V<op> A,B,B | |
12960 | so handle that case specially. */ | |
12961 | ||
12962 | static void | |
12963 | neon_exchange_operands (void) | |
12964 | { | |
12965 | void *scratch = alloca (sizeof (inst.operands[0])); | |
12966 | if (inst.operands[1].present) | |
12967 | { | |
12968 | /* Swap operands[1] and operands[2]. */ | |
12969 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
12970 | inst.operands[1] = inst.operands[2]; | |
12971 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
12972 | } | |
12973 | else | |
12974 | { | |
12975 | inst.operands[1] = inst.operands[2]; | |
12976 | inst.operands[2] = inst.operands[0]; | |
12977 | } | |
12978 | } | |
12979 | ||
12980 | static void | |
12981 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
12982 | { | |
12983 | if (inst.operands[2].isreg) | |
12984 | { | |
12985 | if (invert) | |
12986 | neon_exchange_operands (); | |
dcbf9037 | 12987 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
12988 | } |
12989 | else | |
12990 | { | |
037e8744 | 12991 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
12992 | struct neon_type_el et = neon_check_type (2, rs, |
12993 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 JB |
12994 | |
12995 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12996 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12997 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12998 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12999 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13000 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13001 | inst.instruction |= (et.type == NT_float) << 10; |
13002 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13003 | |
5287ad62 JB |
13004 | inst.instruction = neon_dp_fixup (inst.instruction); |
13005 | } | |
13006 | } | |
13007 | ||
13008 | static void | |
13009 | do_neon_cmp (void) | |
13010 | { | |
13011 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
13012 | } | |
13013 | ||
13014 | static void | |
13015 | do_neon_cmp_inv (void) | |
13016 | { | |
13017 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
13018 | } | |
13019 | ||
13020 | static void | |
13021 | do_neon_ceq (void) | |
13022 | { | |
13023 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
13024 | } | |
13025 | ||
13026 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
13027 | scalars, which are encoded in 5 bits, M : Rm. | |
13028 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
13029 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
13030 | index in M. */ | |
13031 | ||
13032 | static unsigned | |
13033 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
13034 | { | |
dcbf9037 JB |
13035 | unsigned regno = NEON_SCALAR_REG (scalar); |
13036 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
13037 | |
13038 | switch (elsize) | |
13039 | { | |
13040 | case 16: | |
13041 | if (regno > 7 || elno > 3) | |
13042 | goto bad_scalar; | |
13043 | return regno | (elno << 3); | |
5f4273c7 | 13044 | |
5287ad62 JB |
13045 | case 32: |
13046 | if (regno > 15 || elno > 1) | |
13047 | goto bad_scalar; | |
13048 | return regno | (elno << 4); | |
13049 | ||
13050 | default: | |
13051 | bad_scalar: | |
dcbf9037 | 13052 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
13053 | } |
13054 | ||
13055 | return 0; | |
13056 | } | |
13057 | ||
13058 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
13059 | ||
13060 | static void | |
13061 | neon_mul_mac (struct neon_type_el et, int ubit) | |
13062 | { | |
dcbf9037 JB |
13063 | unsigned scalar; |
13064 | ||
13065 | /* Give a more helpful error message if we have an invalid type. */ | |
13066 | if (et.type == NT_invtype) | |
13067 | return; | |
5f4273c7 | 13068 | |
dcbf9037 | 13069 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
13070 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13071 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13072 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13073 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13074 | inst.instruction |= LOW4 (scalar); | |
13075 | inst.instruction |= HI1 (scalar) << 5; | |
13076 | inst.instruction |= (et.type == NT_float) << 8; | |
13077 | inst.instruction |= neon_logbits (et.size) << 20; | |
13078 | inst.instruction |= (ubit != 0) << 24; | |
13079 | ||
13080 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13081 | } | |
13082 | ||
13083 | static void | |
13084 | do_neon_mac_maybe_scalar (void) | |
13085 | { | |
037e8744 JB |
13086 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
13087 | return; | |
13088 | ||
13089 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13090 | return; | |
13091 | ||
5287ad62 JB |
13092 | if (inst.operands[2].isscalar) |
13093 | { | |
037e8744 | 13094 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13095 | struct neon_type_el et = neon_check_type (3, rs, |
13096 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
13097 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 13098 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13099 | } |
13100 | else | |
428e3f1f PB |
13101 | { |
13102 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
13103 | affected if we specify unsigned args. */ | |
13104 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
13105 | } | |
5287ad62 JB |
13106 | } |
13107 | ||
13108 | static void | |
13109 | do_neon_tst (void) | |
13110 | { | |
037e8744 | 13111 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13112 | struct neon_type_el et = neon_check_type (3, rs, |
13113 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 13114 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13115 | } |
13116 | ||
13117 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
13118 | same types as the MAC equivalents. The polynomial type for this instruction | |
13119 | is encoded the same as the integer type. */ | |
13120 | ||
13121 | static void | |
13122 | do_neon_mul (void) | |
13123 | { | |
037e8744 JB |
13124 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
13125 | return; | |
13126 | ||
13127 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13128 | return; | |
13129 | ||
5287ad62 JB |
13130 | if (inst.operands[2].isscalar) |
13131 | do_neon_mac_maybe_scalar (); | |
13132 | else | |
dcbf9037 | 13133 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
13134 | } |
13135 | ||
13136 | static void | |
13137 | do_neon_qdmulh (void) | |
13138 | { | |
13139 | if (inst.operands[2].isscalar) | |
13140 | { | |
037e8744 | 13141 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13142 | struct neon_type_el et = neon_check_type (3, rs, |
13143 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
13144 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 13145 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13146 | } |
13147 | else | |
13148 | { | |
037e8744 | 13149 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13150 | struct neon_type_el et = neon_check_type (3, rs, |
13151 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
13152 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13153 | /* The U bit (rounding) comes from bit mask. */ | |
037e8744 | 13154 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13155 | } |
13156 | } | |
13157 | ||
13158 | static void | |
13159 | do_neon_fcmp_absolute (void) | |
13160 | { | |
037e8744 | 13161 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13162 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
13163 | /* Size field comes from bit mask. */ | |
037e8744 | 13164 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
13165 | } |
13166 | ||
13167 | static void | |
13168 | do_neon_fcmp_absolute_inv (void) | |
13169 | { | |
13170 | neon_exchange_operands (); | |
13171 | do_neon_fcmp_absolute (); | |
13172 | } | |
13173 | ||
13174 | static void | |
13175 | do_neon_step (void) | |
13176 | { | |
037e8744 | 13177 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 13178 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 13179 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13180 | } |
13181 | ||
13182 | static void | |
13183 | do_neon_abs_neg (void) | |
13184 | { | |
037e8744 JB |
13185 | enum neon_shape rs; |
13186 | struct neon_type_el et; | |
5f4273c7 | 13187 | |
037e8744 JB |
13188 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
13189 | return; | |
13190 | ||
13191 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13192 | return; | |
13193 | ||
13194 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
13195 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
5f4273c7 | 13196 | |
5287ad62 JB |
13197 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13198 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13199 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13200 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13201 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13202 | inst.instruction |= (et.type == NT_float) << 10; |
13203 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13204 | |
5287ad62 JB |
13205 | inst.instruction = neon_dp_fixup (inst.instruction); |
13206 | } | |
13207 | ||
13208 | static void | |
13209 | do_neon_sli (void) | |
13210 | { | |
037e8744 | 13211 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13212 | struct neon_type_el et = neon_check_type (2, rs, |
13213 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13214 | int imm = inst.operands[2].imm; | |
13215 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13216 | _("immediate out of range for insert")); | |
037e8744 | 13217 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13218 | } |
13219 | ||
13220 | static void | |
13221 | do_neon_sri (void) | |
13222 | { | |
037e8744 | 13223 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13224 | struct neon_type_el et = neon_check_type (2, rs, |
13225 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13226 | int imm = inst.operands[2].imm; | |
13227 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13228 | _("immediate out of range for insert")); | |
037e8744 | 13229 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
13230 | } |
13231 | ||
13232 | static void | |
13233 | do_neon_qshlu_imm (void) | |
13234 | { | |
037e8744 | 13235 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13236 | struct neon_type_el et = neon_check_type (2, rs, |
13237 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
13238 | int imm = inst.operands[2].imm; | |
13239 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13240 | _("immediate out of range for shift")); | |
13241 | /* Only encodes the 'U present' variant of the instruction. | |
13242 | In this case, signed types have OP (bit 8) set to 0. | |
13243 | Unsigned types have OP set to 1. */ | |
13244 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
13245 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 13246 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13247 | } |
13248 | ||
13249 | static void | |
13250 | do_neon_qmovn (void) | |
13251 | { | |
13252 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13253 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13254 | /* Saturating move where operands can be signed or unsigned, and the | |
13255 | destination has the same signedness. */ | |
13256 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13257 | if (et.type == NT_unsigned) | |
13258 | inst.instruction |= 0xc0; | |
13259 | else | |
13260 | inst.instruction |= 0x80; | |
13261 | neon_two_same (0, 1, et.size / 2); | |
13262 | } | |
13263 | ||
13264 | static void | |
13265 | do_neon_qmovun (void) | |
13266 | { | |
13267 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13268 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13269 | /* Saturating move with unsigned results. Operands must be signed. */ | |
13270 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13271 | neon_two_same (0, 1, et.size / 2); | |
13272 | } | |
13273 | ||
13274 | static void | |
13275 | do_neon_rshift_sat_narrow (void) | |
13276 | { | |
13277 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13278 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13279 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13280 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13281 | int imm = inst.operands[2].imm; | |
13282 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13283 | right. */ | |
13284 | et.size /= 2; | |
5f4273c7 | 13285 | |
5287ad62 JB |
13286 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
13287 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
13288 | if (imm == 0) | |
13289 | { | |
13290 | inst.operands[2].present = 0; | |
13291 | inst.instruction = N_MNEM_vqmovn; | |
13292 | do_neon_qmovn (); | |
13293 | return; | |
13294 | } | |
5f4273c7 | 13295 | |
5287ad62 JB |
13296 | constraint (imm < 1 || (unsigned)imm > et.size, |
13297 | _("immediate out of range")); | |
13298 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
13299 | } | |
13300 | ||
13301 | static void | |
13302 | do_neon_rshift_sat_narrow_u (void) | |
13303 | { | |
13304 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13305 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13306 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13307 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13308 | int imm = inst.operands[2].imm; | |
13309 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13310 | right. */ | |
13311 | et.size /= 2; | |
13312 | ||
13313 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
13314 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
13315 | if (imm == 0) | |
13316 | { | |
13317 | inst.operands[2].present = 0; | |
13318 | inst.instruction = N_MNEM_vqmovun; | |
13319 | do_neon_qmovun (); | |
13320 | return; | |
13321 | } | |
13322 | ||
13323 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13324 | _("immediate out of range")); | |
13325 | /* FIXME: The manual is kind of unclear about what value U should have in | |
13326 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
13327 | must be 1. */ | |
13328 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
13329 | } | |
13330 | ||
13331 | static void | |
13332 | do_neon_movn (void) | |
13333 | { | |
13334 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13335 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13336 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13337 | neon_two_same (0, 1, et.size / 2); | |
13338 | } | |
13339 | ||
13340 | static void | |
13341 | do_neon_rshift_narrow (void) | |
13342 | { | |
13343 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13344 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13345 | int imm = inst.operands[2].imm; | |
13346 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13347 | right. */ | |
13348 | et.size /= 2; | |
5f4273c7 | 13349 | |
5287ad62 JB |
13350 | /* If immediate is zero then we are a pseudo-instruction for |
13351 | VMOVN.I<size> <Dd>, <Qm> */ | |
13352 | if (imm == 0) | |
13353 | { | |
13354 | inst.operands[2].present = 0; | |
13355 | inst.instruction = N_MNEM_vmovn; | |
13356 | do_neon_movn (); | |
13357 | return; | |
13358 | } | |
5f4273c7 | 13359 | |
5287ad62 JB |
13360 | constraint (imm < 1 || (unsigned)imm > et.size, |
13361 | _("immediate out of range for narrowing operation")); | |
13362 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
13363 | } | |
13364 | ||
13365 | static void | |
13366 | do_neon_shll (void) | |
13367 | { | |
13368 | /* FIXME: Type checking when lengthening. */ | |
13369 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
13370 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
13371 | unsigned imm = inst.operands[2].imm; | |
13372 | ||
13373 | if (imm == et.size) | |
13374 | { | |
13375 | /* Maximum shift variant. */ | |
13376 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13377 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13378 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13379 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13380 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13381 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13382 | |
5287ad62 JB |
13383 | inst.instruction = neon_dp_fixup (inst.instruction); |
13384 | } | |
13385 | else | |
13386 | { | |
13387 | /* A more-specific type check for non-max versions. */ | |
13388 | et = neon_check_type (2, NS_QDI, | |
13389 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13390 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13391 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); | |
13392 | } | |
13393 | } | |
13394 | ||
037e8744 | 13395 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
13396 | the current instruction is. */ |
13397 | ||
13398 | static int | |
13399 | neon_cvt_flavour (enum neon_shape rs) | |
13400 | { | |
037e8744 JB |
13401 | #define CVT_VAR(C,X,Y) \ |
13402 | et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \ | |
13403 | if (et.type != NT_invtype) \ | |
13404 | { \ | |
13405 | inst.error = NULL; \ | |
13406 | return (C); \ | |
5287ad62 JB |
13407 | } |
13408 | struct neon_type_el et; | |
037e8744 JB |
13409 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
13410 | || rs == NS_FF) ? N_VFP : 0; | |
13411 | /* The instruction versions which take an immediate take one register | |
13412 | argument, which is extended to the width of the full register. Thus the | |
13413 | "source" and "destination" registers must have the same width. Hack that | |
13414 | here by making the size equal to the key (wider, in this case) operand. */ | |
13415 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 13416 | |
5287ad62 JB |
13417 | CVT_VAR (0, N_S32, N_F32); |
13418 | CVT_VAR (1, N_U32, N_F32); | |
13419 | CVT_VAR (2, N_F32, N_S32); | |
13420 | CVT_VAR (3, N_F32, N_U32); | |
8e79c3df CM |
13421 | /* Half-precision conversions. */ |
13422 | CVT_VAR (4, N_F32, N_F16); | |
13423 | CVT_VAR (5, N_F16, N_F32); | |
5f4273c7 | 13424 | |
037e8744 | 13425 | whole_reg = N_VFP; |
5f4273c7 | 13426 | |
037e8744 | 13427 | /* VFP instructions. */ |
8e79c3df CM |
13428 | CVT_VAR (6, N_F32, N_F64); |
13429 | CVT_VAR (7, N_F64, N_F32); | |
13430 | CVT_VAR (8, N_S32, N_F64 | key); | |
13431 | CVT_VAR (9, N_U32, N_F64 | key); | |
13432 | CVT_VAR (10, N_F64 | key, N_S32); | |
13433 | CVT_VAR (11, N_F64 | key, N_U32); | |
037e8744 | 13434 | /* VFP instructions with bitshift. */ |
8e79c3df CM |
13435 | CVT_VAR (12, N_F32 | key, N_S16); |
13436 | CVT_VAR (13, N_F32 | key, N_U16); | |
13437 | CVT_VAR (14, N_F64 | key, N_S16); | |
13438 | CVT_VAR (15, N_F64 | key, N_U16); | |
13439 | CVT_VAR (16, N_S16, N_F32 | key); | |
13440 | CVT_VAR (17, N_U16, N_F32 | key); | |
13441 | CVT_VAR (18, N_S16, N_F64 | key); | |
13442 | CVT_VAR (19, N_U16, N_F64 | key); | |
5f4273c7 | 13443 | |
5287ad62 JB |
13444 | return -1; |
13445 | #undef CVT_VAR | |
13446 | } | |
13447 | ||
037e8744 JB |
13448 | /* Neon-syntax VFP conversions. */ |
13449 | ||
5287ad62 | 13450 | static void |
037e8744 | 13451 | do_vfp_nsyn_cvt (enum neon_shape rs, int flavour) |
5287ad62 | 13452 | { |
037e8744 | 13453 | const char *opname = 0; |
5f4273c7 | 13454 | |
037e8744 | 13455 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) |
5287ad62 | 13456 | { |
037e8744 JB |
13457 | /* Conversions with immediate bitshift. */ |
13458 | const char *enc[] = | |
13459 | { | |
13460 | "ftosls", | |
13461 | "ftouls", | |
13462 | "fsltos", | |
13463 | "fultos", | |
13464 | NULL, | |
13465 | NULL, | |
8e79c3df CM |
13466 | NULL, |
13467 | NULL, | |
037e8744 JB |
13468 | "ftosld", |
13469 | "ftould", | |
13470 | "fsltod", | |
13471 | "fultod", | |
13472 | "fshtos", | |
13473 | "fuhtos", | |
13474 | "fshtod", | |
13475 | "fuhtod", | |
13476 | "ftoshs", | |
13477 | "ftouhs", | |
13478 | "ftoshd", | |
13479 | "ftouhd" | |
13480 | }; | |
13481 | ||
13482 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13483 | { | |
13484 | opname = enc[flavour]; | |
13485 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13486 | _("operands 0 and 1 must be the same register")); | |
13487 | inst.operands[1] = inst.operands[2]; | |
13488 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
13489 | } | |
5287ad62 JB |
13490 | } |
13491 | else | |
13492 | { | |
037e8744 JB |
13493 | /* Conversions without bitshift. */ |
13494 | const char *enc[] = | |
13495 | { | |
13496 | "ftosis", | |
13497 | "ftouis", | |
13498 | "fsitos", | |
13499 | "fuitos", | |
8e79c3df CM |
13500 | "NULL", |
13501 | "NULL", | |
037e8744 JB |
13502 | "fcvtsd", |
13503 | "fcvtds", | |
13504 | "ftosid", | |
13505 | "ftouid", | |
13506 | "fsitod", | |
13507 | "fuitod" | |
13508 | }; | |
13509 | ||
13510 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13511 | opname = enc[flavour]; | |
13512 | } | |
13513 | ||
13514 | if (opname) | |
13515 | do_vfp_nsyn_opcode (opname); | |
13516 | } | |
13517 | ||
13518 | static void | |
13519 | do_vfp_nsyn_cvtz (void) | |
13520 | { | |
13521 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
13522 | int flavour = neon_cvt_flavour (rs); | |
13523 | const char *enc[] = | |
13524 | { | |
13525 | "ftosizs", | |
13526 | "ftouizs", | |
13527 | NULL, | |
13528 | NULL, | |
13529 | NULL, | |
13530 | NULL, | |
8e79c3df CM |
13531 | NULL, |
13532 | NULL, | |
037e8744 JB |
13533 | "ftosizd", |
13534 | "ftouizd" | |
13535 | }; | |
13536 | ||
13537 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) | |
13538 | do_vfp_nsyn_opcode (enc[flavour]); | |
13539 | } | |
f31fef98 | 13540 | |
037e8744 JB |
13541 | static void |
13542 | do_neon_cvt (void) | |
13543 | { | |
13544 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
8e79c3df | 13545 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL); |
037e8744 JB |
13546 | int flavour = neon_cvt_flavour (rs); |
13547 | ||
13548 | /* VFP rather than Neon conversions. */ | |
8e79c3df | 13549 | if (flavour >= 6) |
037e8744 JB |
13550 | { |
13551 | do_vfp_nsyn_cvt (rs, flavour); | |
13552 | return; | |
13553 | } | |
13554 | ||
13555 | switch (rs) | |
13556 | { | |
13557 | case NS_DDI: | |
13558 | case NS_QQI: | |
13559 | { | |
35997600 NC |
13560 | unsigned immbits; |
13561 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
13562 | ||
037e8744 JB |
13563 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
13564 | return; | |
13565 | ||
13566 | /* Fixed-point conversion with #0 immediate is encoded as an | |
13567 | integer conversion. */ | |
13568 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
13569 | goto int_encode; | |
35997600 | 13570 | immbits = 32 - inst.operands[2].imm; |
037e8744 JB |
13571 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
13572 | if (flavour != -1) | |
13573 | inst.instruction |= enctab[flavour]; | |
13574 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13575 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13576 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13577 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13578 | inst.instruction |= neon_quad (rs) << 6; | |
13579 | inst.instruction |= 1 << 21; | |
13580 | inst.instruction |= immbits << 16; | |
13581 | ||
13582 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13583 | } | |
13584 | break; | |
13585 | ||
13586 | case NS_DD: | |
13587 | case NS_QQ: | |
13588 | int_encode: | |
13589 | { | |
13590 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
13591 | ||
13592 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13593 | ||
13594 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13595 | return; | |
13596 | ||
13597 | if (flavour != -1) | |
13598 | inst.instruction |= enctab[flavour]; | |
13599 | ||
13600 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13601 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13602 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13603 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13604 | inst.instruction |= neon_quad (rs) << 6; | |
13605 | inst.instruction |= 2 << 18; | |
13606 | ||
13607 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13608 | } | |
13609 | break; | |
13610 | ||
8e79c3df CM |
13611 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
13612 | case NS_QD: | |
13613 | case NS_DQ: | |
13614 | ||
13615 | if ((rs == NS_DQ) | |
13616 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
13617 | { | |
13618 | as_bad (_("operand size must match register width")); | |
13619 | break; | |
13620 | } | |
13621 | ||
13622 | if ((rs == NS_QD) | |
13623 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
13624 | { | |
13625 | as_bad (_("operand size must match register width")); | |
13626 | break; | |
13627 | } | |
13628 | ||
13629 | if (rs == NS_DQ) | |
13630 | inst.instruction = 0x3b60600; | |
13631 | else | |
13632 | inst.instruction = 0x3b60700; | |
13633 | ||
13634 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13635 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13636 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13637 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13638 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13639 | break; | |
13640 | ||
037e8744 JB |
13641 | default: |
13642 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
13643 | do_vfp_nsyn_cvt (rs, flavour); | |
5287ad62 | 13644 | } |
5287ad62 JB |
13645 | } |
13646 | ||
8e79c3df CM |
13647 | static void |
13648 | do_neon_cvtb (void) | |
13649 | { | |
13650 | inst.instruction = 0xeb20a40; | |
13651 | ||
13652 | /* The sizes are attached to the mnemonic. */ | |
13653 | if (inst.vectype.el[0].type != NT_invtype | |
13654 | && inst.vectype.el[0].size == 16) | |
13655 | inst.instruction |= 0x00010000; | |
13656 | ||
13657 | /* Programmer's syntax: the sizes are attached to the operands. */ | |
13658 | else if (inst.operands[0].vectype.type != NT_invtype | |
13659 | && inst.operands[0].vectype.size == 16) | |
13660 | inst.instruction |= 0x00010000; | |
13661 | ||
13662 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
13663 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
13664 | do_vfp_cond_or_thumb (); | |
13665 | } | |
13666 | ||
13667 | ||
13668 | static void | |
13669 | do_neon_cvtt (void) | |
13670 | { | |
13671 | do_neon_cvtb (); | |
13672 | inst.instruction |= 0x80; | |
13673 | } | |
13674 | ||
5287ad62 JB |
13675 | static void |
13676 | neon_move_immediate (void) | |
13677 | { | |
037e8744 JB |
13678 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
13679 | struct neon_type_el et = neon_check_type (2, rs, | |
13680 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 13681 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 13682 | int op, cmode, float_p; |
5287ad62 | 13683 | |
037e8744 JB |
13684 | constraint (et.type == NT_invtype, |
13685 | _("operand size must be specified for immediate VMOV")); | |
13686 | ||
5287ad62 JB |
13687 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
13688 | op = (inst.instruction & (1 << 5)) != 0; | |
13689 | ||
13690 | immlo = inst.operands[1].imm; | |
13691 | if (inst.operands[1].regisimm) | |
13692 | immhi = inst.operands[1].reg; | |
13693 | ||
13694 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
13695 | _("immediate has bits set outside the operand size")); | |
13696 | ||
c96612cc JB |
13697 | float_p = inst.operands[1].immisfloat; |
13698 | ||
13699 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
136da414 | 13700 | et.size, et.type)) == FAIL) |
5287ad62 JB |
13701 | { |
13702 | /* Invert relevant bits only. */ | |
13703 | neon_invert_size (&immlo, &immhi, et.size); | |
13704 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
13705 | with one or the other; those cases are caught by | |
13706 | neon_cmode_for_move_imm. */ | |
13707 | op = !op; | |
c96612cc JB |
13708 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
13709 | &op, et.size, et.type)) == FAIL) | |
5287ad62 | 13710 | { |
dcbf9037 | 13711 | first_error (_("immediate out of range")); |
5287ad62 JB |
13712 | return; |
13713 | } | |
13714 | } | |
13715 | ||
13716 | inst.instruction &= ~(1 << 5); | |
13717 | inst.instruction |= op << 5; | |
13718 | ||
13719 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13720 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 13721 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13722 | inst.instruction |= cmode << 8; |
13723 | ||
13724 | neon_write_immbits (immbits); | |
13725 | } | |
13726 | ||
13727 | static void | |
13728 | do_neon_mvn (void) | |
13729 | { | |
13730 | if (inst.operands[1].isreg) | |
13731 | { | |
037e8744 | 13732 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 13733 | |
5287ad62 JB |
13734 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
13735 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13736 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13737 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13738 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13739 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13740 | } |
13741 | else | |
13742 | { | |
13743 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13744 | neon_move_immediate (); | |
13745 | } | |
13746 | ||
13747 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13748 | } | |
13749 | ||
13750 | /* Encode instructions of form: | |
13751 | ||
13752 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 13753 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
13754 | |
13755 | static void | |
13756 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
13757 | { | |
13758 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13759 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13760 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13761 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13762 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13763 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
13764 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
13765 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 13766 | |
5287ad62 JB |
13767 | inst.instruction = neon_dp_fixup (inst.instruction); |
13768 | } | |
13769 | ||
13770 | static void | |
13771 | do_neon_dyadic_long (void) | |
13772 | { | |
13773 | /* FIXME: Type checking for lengthening op. */ | |
13774 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13775 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
13776 | neon_mixed_length (et, et.size); | |
13777 | } | |
13778 | ||
13779 | static void | |
13780 | do_neon_abal (void) | |
13781 | { | |
13782 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13783 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
13784 | neon_mixed_length (et, et.size); | |
13785 | } | |
13786 | ||
13787 | static void | |
13788 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
13789 | { | |
13790 | if (inst.operands[2].isscalar) | |
13791 | { | |
dcbf9037 JB |
13792 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
13793 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
5287ad62 JB |
13794 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
13795 | neon_mul_mac (et, et.type == NT_unsigned); | |
13796 | } | |
13797 | else | |
13798 | { | |
13799 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13800 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
13801 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13802 | neon_mixed_length (et, et.size); | |
13803 | } | |
13804 | } | |
13805 | ||
13806 | static void | |
13807 | do_neon_mac_maybe_scalar_long (void) | |
13808 | { | |
13809 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
13810 | } | |
13811 | ||
13812 | static void | |
13813 | do_neon_dyadic_wide (void) | |
13814 | { | |
13815 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
13816 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13817 | neon_mixed_length (et, et.size); | |
13818 | } | |
13819 | ||
13820 | static void | |
13821 | do_neon_dyadic_narrow (void) | |
13822 | { | |
13823 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13824 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
13825 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
13826 | so force the operand type to integer. */ | |
13827 | et.type = NT_integer; | |
5287ad62 JB |
13828 | neon_mixed_length (et, et.size / 2); |
13829 | } | |
13830 | ||
13831 | static void | |
13832 | do_neon_mul_sat_scalar_long (void) | |
13833 | { | |
13834 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
13835 | } | |
13836 | ||
13837 | static void | |
13838 | do_neon_vmull (void) | |
13839 | { | |
13840 | if (inst.operands[2].isscalar) | |
13841 | do_neon_mac_maybe_scalar_long (); | |
13842 | else | |
13843 | { | |
13844 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13845 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY); | |
13846 | if (et.type == NT_poly) | |
13847 | inst.instruction = NEON_ENC_POLY (inst.instruction); | |
13848 | else | |
13849 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13850 | /* For polynomial encoding, size field must be 0b00 and the U bit must be | |
13851 | zero. Should be OK as-is. */ | |
13852 | neon_mixed_length (et, et.size); | |
13853 | } | |
13854 | } | |
13855 | ||
13856 | static void | |
13857 | do_neon_ext (void) | |
13858 | { | |
037e8744 | 13859 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
13860 | struct neon_type_el et = neon_check_type (3, rs, |
13861 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13862 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
13863 | |
13864 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
13865 | _("shift out of range")); | |
5287ad62 JB |
13866 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13867 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13868 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13869 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13870 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13871 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 13872 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 13873 | inst.instruction |= imm << 8; |
5f4273c7 | 13874 | |
5287ad62 JB |
13875 | inst.instruction = neon_dp_fixup (inst.instruction); |
13876 | } | |
13877 | ||
13878 | static void | |
13879 | do_neon_rev (void) | |
13880 | { | |
037e8744 | 13881 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13882 | struct neon_type_el et = neon_check_type (2, rs, |
13883 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
13884 | unsigned op = (inst.instruction >> 7) & 3; | |
13885 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
13886 | extract it here to check the elements to be reversed are smaller. | |
13887 | Otherwise we'd get a reserved instruction. */ | |
13888 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 13889 | gas_assert (elsize != 0); |
5287ad62 JB |
13890 | constraint (et.size >= elsize, |
13891 | _("elements must be smaller than reversal region")); | |
037e8744 | 13892 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13893 | } |
13894 | ||
13895 | static void | |
13896 | do_neon_dup (void) | |
13897 | { | |
13898 | if (inst.operands[1].isscalar) | |
13899 | { | |
037e8744 | 13900 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
13901 | struct neon_type_el et = neon_check_type (2, rs, |
13902 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 13903 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 13904 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 13905 | int logsize = neon_logbits (et.size); |
dcbf9037 | 13906 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
13907 | |
13908 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
13909 | return; | |
13910 | ||
5287ad62 JB |
13911 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
13912 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13913 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13914 | inst.instruction |= LOW4 (dm); | |
13915 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 13916 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13917 | inst.instruction |= x << 17; |
13918 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 13919 | |
5287ad62 JB |
13920 | inst.instruction = neon_dp_fixup (inst.instruction); |
13921 | } | |
13922 | else | |
13923 | { | |
037e8744 JB |
13924 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
13925 | struct neon_type_el et = neon_check_type (2, rs, | |
13926 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 JB |
13927 | /* Duplicate ARM register to lanes of vector. */ |
13928 | inst.instruction = NEON_ENC_ARMREG (inst.instruction); | |
13929 | switch (et.size) | |
13930 | { | |
13931 | case 8: inst.instruction |= 0x400000; break; | |
13932 | case 16: inst.instruction |= 0x000020; break; | |
13933 | case 32: inst.instruction |= 0x000000; break; | |
13934 | default: break; | |
13935 | } | |
13936 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
13937 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
13938 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 13939 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
13940 | /* The encoding for this instruction is identical for the ARM and Thumb |
13941 | variants, except for the condition field. */ | |
037e8744 | 13942 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
13943 | } |
13944 | } | |
13945 | ||
13946 | /* VMOV has particularly many variations. It can be one of: | |
13947 | 0. VMOV<c><q> <Qd>, <Qm> | |
13948 | 1. VMOV<c><q> <Dd>, <Dm> | |
13949 | (Register operations, which are VORR with Rm = Rn.) | |
13950 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
13951 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
13952 | (Immediate loads.) | |
13953 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
13954 | (ARM register to scalar.) | |
13955 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
13956 | (Two ARM registers to vector.) | |
13957 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
13958 | (Scalar to ARM register.) | |
13959 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
13960 | (Vector to two ARM registers.) | |
037e8744 JB |
13961 | 8. VMOV.F32 <Sd>, <Sm> |
13962 | 9. VMOV.F64 <Dd>, <Dm> | |
13963 | (VFP register moves.) | |
13964 | 10. VMOV.F32 <Sd>, #imm | |
13965 | 11. VMOV.F64 <Dd>, #imm | |
13966 | (VFP float immediate load.) | |
13967 | 12. VMOV <Rd>, <Sm> | |
13968 | (VFP single to ARM reg.) | |
13969 | 13. VMOV <Sd>, <Rm> | |
13970 | (ARM reg to VFP single.) | |
13971 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
13972 | (Two ARM regs to two VFP singles.) | |
13973 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
13974 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 13975 | |
037e8744 JB |
13976 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
13977 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 13978 | |
5287ad62 | 13979 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 13980 | |
b7fc2769 JB |
13981 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
13982 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 13983 | |
5287ad62 | 13984 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 13985 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
13986 | |
13987 | static void | |
13988 | do_neon_mov (void) | |
13989 | { | |
037e8744 JB |
13990 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
13991 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
13992 | NS_NULL); | |
13993 | struct neon_type_el et; | |
13994 | const char *ldconst = 0; | |
5287ad62 | 13995 | |
037e8744 | 13996 | switch (rs) |
5287ad62 | 13997 | { |
037e8744 JB |
13998 | case NS_DD: /* case 1/9. */ |
13999 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
14000 | /* It is not an error here if no type is given. */ | |
14001 | inst.error = NULL; | |
14002 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 14003 | { |
037e8744 JB |
14004 | do_vfp_nsyn_opcode ("fcpyd"); |
14005 | break; | |
5287ad62 | 14006 | } |
037e8744 | 14007 | /* fall through. */ |
5287ad62 | 14008 | |
037e8744 JB |
14009 | case NS_QQ: /* case 0/1. */ |
14010 | { | |
14011 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14012 | return; | |
14013 | /* The architecture manual I have doesn't explicitly state which | |
14014 | value the U bit should have for register->register moves, but | |
14015 | the equivalent VORR instruction has U = 0, so do that. */ | |
14016 | inst.instruction = 0x0200110; | |
14017 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14018 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14019 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14020 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14021 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14022 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14023 | inst.instruction |= neon_quad (rs) << 6; | |
14024 | ||
14025 | inst.instruction = neon_dp_fixup (inst.instruction); | |
14026 | } | |
14027 | break; | |
5f4273c7 | 14028 | |
037e8744 JB |
14029 | case NS_DI: /* case 3/11. */ |
14030 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
14031 | inst.error = NULL; | |
14032 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 14033 | { |
037e8744 JB |
14034 | /* case 11 (fconstd). */ |
14035 | ldconst = "fconstd"; | |
14036 | goto encode_fconstd; | |
5287ad62 | 14037 | } |
037e8744 JB |
14038 | /* fall through. */ |
14039 | ||
14040 | case NS_QI: /* case 2/3. */ | |
14041 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14042 | return; | |
14043 | inst.instruction = 0x0800010; | |
14044 | neon_move_immediate (); | |
14045 | inst.instruction = neon_dp_fixup (inst.instruction); | |
5287ad62 | 14046 | break; |
5f4273c7 | 14047 | |
037e8744 JB |
14048 | case NS_SR: /* case 4. */ |
14049 | { | |
14050 | unsigned bcdebits = 0; | |
14051 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
14052 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
14053 | int logsize = neon_logbits (et.size); | |
14054 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
14055 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
14056 | ||
14057 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
14058 | _(BAD_FPU)); | |
14059 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14060 | && et.size != 32, _(BAD_FPU)); | |
14061 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14062 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14063 | ||
14064 | switch (et.size) | |
14065 | { | |
14066 | case 8: bcdebits = 0x8; break; | |
14067 | case 16: bcdebits = 0x1; break; | |
14068 | case 32: bcdebits = 0x0; break; | |
14069 | default: ; | |
14070 | } | |
14071 | ||
14072 | bcdebits |= x << logsize; | |
14073 | ||
14074 | inst.instruction = 0xe000b10; | |
14075 | do_vfp_cond_or_thumb (); | |
14076 | inst.instruction |= LOW4 (dn) << 16; | |
14077 | inst.instruction |= HI1 (dn) << 7; | |
14078 | inst.instruction |= inst.operands[1].reg << 12; | |
14079 | inst.instruction |= (bcdebits & 3) << 5; | |
14080 | inst.instruction |= (bcdebits >> 2) << 21; | |
14081 | } | |
14082 | break; | |
5f4273c7 | 14083 | |
037e8744 | 14084 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 14085 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 14086 | _(BAD_FPU)); |
b7fc2769 | 14087 | |
037e8744 JB |
14088 | inst.instruction = 0xc400b10; |
14089 | do_vfp_cond_or_thumb (); | |
14090 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
14091 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
14092 | inst.instruction |= inst.operands[1].reg << 12; | |
14093 | inst.instruction |= inst.operands[2].reg << 16; | |
14094 | break; | |
5f4273c7 | 14095 | |
037e8744 JB |
14096 | case NS_RS: /* case 6. */ |
14097 | { | |
14098 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
14099 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
14100 | unsigned logsize = neon_logbits (et.size); | |
14101 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
14102 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
14103 | unsigned abcdebits = 0; | |
14104 | ||
14105 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
14106 | _(BAD_FPU)); | |
14107 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14108 | && et.size != 32, _(BAD_FPU)); | |
14109 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14110 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14111 | ||
14112 | switch (et.size) | |
14113 | { | |
14114 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
14115 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
14116 | case 32: abcdebits = 0x00; break; | |
14117 | default: ; | |
14118 | } | |
14119 | ||
14120 | abcdebits |= x << logsize; | |
14121 | inst.instruction = 0xe100b10; | |
14122 | do_vfp_cond_or_thumb (); | |
14123 | inst.instruction |= LOW4 (dn) << 16; | |
14124 | inst.instruction |= HI1 (dn) << 7; | |
14125 | inst.instruction |= inst.operands[0].reg << 12; | |
14126 | inst.instruction |= (abcdebits & 3) << 5; | |
14127 | inst.instruction |= (abcdebits >> 2) << 21; | |
14128 | } | |
14129 | break; | |
5f4273c7 | 14130 | |
037e8744 JB |
14131 | case NS_RRD: /* case 7 (fmrrd). */ |
14132 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
14133 | _(BAD_FPU)); | |
14134 | ||
14135 | inst.instruction = 0xc500b10; | |
14136 | do_vfp_cond_or_thumb (); | |
14137 | inst.instruction |= inst.operands[0].reg << 12; | |
14138 | inst.instruction |= inst.operands[1].reg << 16; | |
14139 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14140 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14141 | break; | |
5f4273c7 | 14142 | |
037e8744 JB |
14143 | case NS_FF: /* case 8 (fcpys). */ |
14144 | do_vfp_nsyn_opcode ("fcpys"); | |
14145 | break; | |
5f4273c7 | 14146 | |
037e8744 JB |
14147 | case NS_FI: /* case 10 (fconsts). */ |
14148 | ldconst = "fconsts"; | |
14149 | encode_fconstd: | |
14150 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 14151 | { |
037e8744 JB |
14152 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
14153 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
14154 | } |
14155 | else | |
037e8744 JB |
14156 | first_error (_("immediate out of range")); |
14157 | break; | |
5f4273c7 | 14158 | |
037e8744 JB |
14159 | case NS_RF: /* case 12 (fmrs). */ |
14160 | do_vfp_nsyn_opcode ("fmrs"); | |
14161 | break; | |
5f4273c7 | 14162 | |
037e8744 JB |
14163 | case NS_FR: /* case 13 (fmsr). */ |
14164 | do_vfp_nsyn_opcode ("fmsr"); | |
14165 | break; | |
5f4273c7 | 14166 | |
037e8744 JB |
14167 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
14168 | (one of which is a list), but we have parsed four. Do some fiddling to | |
14169 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
14170 | expect. */ | |
14171 | case NS_RRFF: /* case 14 (fmrrs). */ | |
14172 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
14173 | _("VFP registers must be adjacent")); | |
14174 | inst.operands[2].imm = 2; | |
14175 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14176 | do_vfp_nsyn_opcode ("fmrrs"); | |
14177 | break; | |
5f4273c7 | 14178 | |
037e8744 JB |
14179 | case NS_FFRR: /* case 15 (fmsrr). */ |
14180 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
14181 | _("VFP registers must be adjacent")); | |
14182 | inst.operands[1] = inst.operands[2]; | |
14183 | inst.operands[2] = inst.operands[3]; | |
14184 | inst.operands[0].imm = 2; | |
14185 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14186 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 14187 | break; |
5f4273c7 | 14188 | |
5287ad62 JB |
14189 | default: |
14190 | abort (); | |
14191 | } | |
14192 | } | |
14193 | ||
14194 | static void | |
14195 | do_neon_rshift_round_imm (void) | |
14196 | { | |
037e8744 | 14197 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14198 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
14199 | int imm = inst.operands[2].imm; | |
14200 | ||
14201 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
14202 | if (imm == 0) | |
14203 | { | |
14204 | inst.operands[2].present = 0; | |
14205 | do_neon_mov (); | |
14206 | return; | |
14207 | } | |
14208 | ||
14209 | constraint (imm < 1 || (unsigned)imm > et.size, | |
14210 | _("immediate out of range for shift")); | |
037e8744 | 14211 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
14212 | et.size - imm); |
14213 | } | |
14214 | ||
14215 | static void | |
14216 | do_neon_movl (void) | |
14217 | { | |
14218 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
14219 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
14220 | unsigned sizebits = et.size >> 3; | |
14221 | inst.instruction |= sizebits << 19; | |
14222 | neon_two_same (0, et.type == NT_unsigned, -1); | |
14223 | } | |
14224 | ||
14225 | static void | |
14226 | do_neon_trn (void) | |
14227 | { | |
037e8744 | 14228 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14229 | struct neon_type_el et = neon_check_type (2, rs, |
14230 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14231 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 14232 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14233 | } |
14234 | ||
14235 | static void | |
14236 | do_neon_zip_uzp (void) | |
14237 | { | |
037e8744 | 14238 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14239 | struct neon_type_el et = neon_check_type (2, rs, |
14240 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14241 | if (rs == NS_DD && et.size == 32) | |
14242 | { | |
14243 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
14244 | inst.instruction = N_MNEM_vtrn; | |
14245 | do_neon_trn (); | |
14246 | return; | |
14247 | } | |
037e8744 | 14248 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14249 | } |
14250 | ||
14251 | static void | |
14252 | do_neon_sat_abs_neg (void) | |
14253 | { | |
037e8744 | 14254 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14255 | struct neon_type_el et = neon_check_type (2, rs, |
14256 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14257 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14258 | } |
14259 | ||
14260 | static void | |
14261 | do_neon_pair_long (void) | |
14262 | { | |
037e8744 | 14263 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14264 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
14265 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
14266 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 14267 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14268 | } |
14269 | ||
14270 | static void | |
14271 | do_neon_recip_est (void) | |
14272 | { | |
037e8744 | 14273 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14274 | struct neon_type_el et = neon_check_type (2, rs, |
14275 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
14276 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 14277 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14278 | } |
14279 | ||
14280 | static void | |
14281 | do_neon_cls (void) | |
14282 | { | |
037e8744 | 14283 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14284 | struct neon_type_el et = neon_check_type (2, rs, |
14285 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14286 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14287 | } |
14288 | ||
14289 | static void | |
14290 | do_neon_clz (void) | |
14291 | { | |
037e8744 | 14292 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14293 | struct neon_type_el et = neon_check_type (2, rs, |
14294 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 14295 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14296 | } |
14297 | ||
14298 | static void | |
14299 | do_neon_cnt (void) | |
14300 | { | |
037e8744 | 14301 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14302 | struct neon_type_el et = neon_check_type (2, rs, |
14303 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 14304 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14305 | } |
14306 | ||
14307 | static void | |
14308 | do_neon_swp (void) | |
14309 | { | |
037e8744 JB |
14310 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
14311 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
14312 | } |
14313 | ||
14314 | static void | |
14315 | do_neon_tbl_tbx (void) | |
14316 | { | |
14317 | unsigned listlenbits; | |
dcbf9037 | 14318 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 14319 | |
5287ad62 JB |
14320 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
14321 | { | |
dcbf9037 | 14322 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
14323 | return; |
14324 | } | |
5f4273c7 | 14325 | |
5287ad62 JB |
14326 | listlenbits = inst.operands[1].imm - 1; |
14327 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14328 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14329 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14330 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14331 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14332 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14333 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 14334 | |
5287ad62 JB |
14335 | inst.instruction = neon_dp_fixup (inst.instruction); |
14336 | } | |
14337 | ||
14338 | static void | |
14339 | do_neon_ldm_stm (void) | |
14340 | { | |
14341 | /* P, U and L bits are part of bitmask. */ | |
14342 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
14343 | unsigned offsetbits = inst.operands[1].imm * 2; | |
14344 | ||
037e8744 JB |
14345 | if (inst.operands[1].issingle) |
14346 | { | |
14347 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
14348 | return; | |
14349 | } | |
14350 | ||
5287ad62 JB |
14351 | constraint (is_dbmode && !inst.operands[0].writeback, |
14352 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
14353 | ||
14354 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14355 | _("register list must contain at least 1 and at most 16 " | |
14356 | "registers")); | |
14357 | ||
14358 | inst.instruction |= inst.operands[0].reg << 16; | |
14359 | inst.instruction |= inst.operands[0].writeback << 21; | |
14360 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
14361 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
14362 | ||
14363 | inst.instruction |= offsetbits; | |
5f4273c7 | 14364 | |
037e8744 | 14365 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
14366 | } |
14367 | ||
14368 | static void | |
14369 | do_neon_ldr_str (void) | |
14370 | { | |
5287ad62 | 14371 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 14372 | |
037e8744 JB |
14373 | if (inst.operands[0].issingle) |
14374 | { | |
cd2f129f JB |
14375 | if (is_ldr) |
14376 | do_vfp_nsyn_opcode ("flds"); | |
14377 | else | |
14378 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
14379 | } |
14380 | else | |
5287ad62 | 14381 | { |
cd2f129f JB |
14382 | if (is_ldr) |
14383 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 14384 | else |
cd2f129f | 14385 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 14386 | } |
5287ad62 JB |
14387 | } |
14388 | ||
14389 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
14390 | instructions. */ | |
14391 | ||
14392 | static void | |
14393 | do_neon_ld_st_interleave (void) | |
14394 | { | |
037e8744 | 14395 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
14396 | N_8 | N_16 | N_32 | N_64); |
14397 | unsigned alignbits = 0; | |
14398 | unsigned idx; | |
14399 | /* The bits in this table go: | |
14400 | 0: register stride of one (0) or two (1) | |
14401 | 1,2: register list length, minus one (1, 2, 3, 4). | |
14402 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
14403 | We use -1 for invalid entries. */ | |
14404 | const int typetable[] = | |
14405 | { | |
14406 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
14407 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
14408 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
14409 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
14410 | }; | |
14411 | int typebits; | |
14412 | ||
dcbf9037 JB |
14413 | if (et.type == NT_invtype) |
14414 | return; | |
14415 | ||
5287ad62 JB |
14416 | if (inst.operands[1].immisalign) |
14417 | switch (inst.operands[1].imm >> 8) | |
14418 | { | |
14419 | case 64: alignbits = 1; break; | |
14420 | case 128: | |
14421 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
14422 | goto bad_alignment; | |
14423 | alignbits = 2; | |
14424 | break; | |
14425 | case 256: | |
14426 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
14427 | goto bad_alignment; | |
14428 | alignbits = 3; | |
14429 | break; | |
14430 | default: | |
14431 | bad_alignment: | |
dcbf9037 | 14432 | first_error (_("bad alignment")); |
5287ad62 JB |
14433 | return; |
14434 | } | |
14435 | ||
14436 | inst.instruction |= alignbits << 4; | |
14437 | inst.instruction |= neon_logbits (et.size) << 6; | |
14438 | ||
14439 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
14440 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
14441 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
14442 | up the right value for "type" in a table based on this value and the given | |
14443 | list style, then stick it back. */ | |
14444 | idx = ((inst.operands[0].imm >> 4) & 7) | |
14445 | | (((inst.instruction >> 8) & 3) << 3); | |
14446 | ||
14447 | typebits = typetable[idx]; | |
5f4273c7 | 14448 | |
5287ad62 JB |
14449 | constraint (typebits == -1, _("bad list type for instruction")); |
14450 | ||
14451 | inst.instruction &= ~0xf00; | |
14452 | inst.instruction |= typebits << 8; | |
14453 | } | |
14454 | ||
14455 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
14456 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
14457 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
14458 | values, terminated with -1. */ | |
14459 | ||
14460 | static int | |
14461 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
14462 | { | |
14463 | va_list ap; | |
14464 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 14465 | |
5287ad62 JB |
14466 | if (!inst.operands[1].immisalign) |
14467 | { | |
14468 | *do_align = 0; | |
14469 | return SUCCESS; | |
14470 | } | |
5f4273c7 | 14471 | |
5287ad62 JB |
14472 | va_start (ap, do_align); |
14473 | ||
14474 | do | |
14475 | { | |
14476 | thissize = va_arg (ap, int); | |
14477 | if (thissize == -1) | |
14478 | break; | |
14479 | thisalign = va_arg (ap, int); | |
14480 | ||
14481 | if (size == thissize && align == thisalign) | |
14482 | result = SUCCESS; | |
14483 | } | |
14484 | while (result != SUCCESS); | |
14485 | ||
14486 | va_end (ap); | |
14487 | ||
14488 | if (result == SUCCESS) | |
14489 | *do_align = 1; | |
14490 | else | |
dcbf9037 | 14491 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 14492 | |
5287ad62 JB |
14493 | return result; |
14494 | } | |
14495 | ||
14496 | static void | |
14497 | do_neon_ld_st_lane (void) | |
14498 | { | |
037e8744 | 14499 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
14500 | int align_good, do_align = 0; |
14501 | int logsize = neon_logbits (et.size); | |
14502 | int align = inst.operands[1].imm >> 8; | |
14503 | int n = (inst.instruction >> 8) & 3; | |
14504 | int max_el = 64 / et.size; | |
5f4273c7 | 14505 | |
dcbf9037 JB |
14506 | if (et.type == NT_invtype) |
14507 | return; | |
5f4273c7 | 14508 | |
5287ad62 JB |
14509 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
14510 | _("bad list length")); | |
14511 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
14512 | _("scalar index out of range")); | |
14513 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
14514 | && et.size == 8, | |
14515 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 14516 | |
5287ad62 JB |
14517 | switch (n) |
14518 | { | |
14519 | case 0: /* VLD1 / VST1. */ | |
14520 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
14521 | 32, 32, -1); | |
14522 | if (align_good == FAIL) | |
14523 | return; | |
14524 | if (do_align) | |
14525 | { | |
14526 | unsigned alignbits = 0; | |
14527 | switch (et.size) | |
14528 | { | |
14529 | case 16: alignbits = 0x1; break; | |
14530 | case 32: alignbits = 0x3; break; | |
14531 | default: ; | |
14532 | } | |
14533 | inst.instruction |= alignbits << 4; | |
14534 | } | |
14535 | break; | |
14536 | ||
14537 | case 1: /* VLD2 / VST2. */ | |
14538 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
14539 | 32, 64, -1); | |
14540 | if (align_good == FAIL) | |
14541 | return; | |
14542 | if (do_align) | |
14543 | inst.instruction |= 1 << 4; | |
14544 | break; | |
14545 | ||
14546 | case 2: /* VLD3 / VST3. */ | |
14547 | constraint (inst.operands[1].immisalign, | |
14548 | _("can't use alignment with this instruction")); | |
14549 | break; | |
14550 | ||
14551 | case 3: /* VLD4 / VST4. */ | |
14552 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
14553 | 16, 64, 32, 64, 32, 128, -1); | |
14554 | if (align_good == FAIL) | |
14555 | return; | |
14556 | if (do_align) | |
14557 | { | |
14558 | unsigned alignbits = 0; | |
14559 | switch (et.size) | |
14560 | { | |
14561 | case 8: alignbits = 0x1; break; | |
14562 | case 16: alignbits = 0x1; break; | |
14563 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
14564 | default: ; | |
14565 | } | |
14566 | inst.instruction |= alignbits << 4; | |
14567 | } | |
14568 | break; | |
14569 | ||
14570 | default: ; | |
14571 | } | |
14572 | ||
14573 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
14574 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14575 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 14576 | |
5287ad62 JB |
14577 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
14578 | inst.instruction |= logsize << 10; | |
14579 | } | |
14580 | ||
14581 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
14582 | ||
14583 | static void | |
14584 | do_neon_ld_dup (void) | |
14585 | { | |
037e8744 | 14586 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
14587 | int align_good, do_align = 0; |
14588 | ||
dcbf9037 JB |
14589 | if (et.type == NT_invtype) |
14590 | return; | |
14591 | ||
5287ad62 JB |
14592 | switch ((inst.instruction >> 8) & 3) |
14593 | { | |
14594 | case 0: /* VLD1. */ | |
9c2799c2 | 14595 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 JB |
14596 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
14597 | &do_align, 16, 16, 32, 32, -1); | |
14598 | if (align_good == FAIL) | |
14599 | return; | |
14600 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
14601 | { | |
14602 | case 1: break; | |
14603 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 14604 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
14605 | } |
14606 | inst.instruction |= neon_logbits (et.size) << 6; | |
14607 | break; | |
14608 | ||
14609 | case 1: /* VLD2. */ | |
14610 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
14611 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
14612 | if (align_good == FAIL) | |
14613 | return; | |
14614 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
14615 | _("bad list length")); | |
14616 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14617 | inst.instruction |= 1 << 5; | |
14618 | inst.instruction |= neon_logbits (et.size) << 6; | |
14619 | break; | |
14620 | ||
14621 | case 2: /* VLD3. */ | |
14622 | constraint (inst.operands[1].immisalign, | |
14623 | _("can't use alignment with this instruction")); | |
14624 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
14625 | _("bad list length")); | |
14626 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14627 | inst.instruction |= 1 << 5; | |
14628 | inst.instruction |= neon_logbits (et.size) << 6; | |
14629 | break; | |
14630 | ||
14631 | case 3: /* VLD4. */ | |
14632 | { | |
14633 | int align = inst.operands[1].imm >> 8; | |
14634 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
14635 | 16, 64, 32, 64, 32, 128, -1); | |
14636 | if (align_good == FAIL) | |
14637 | return; | |
14638 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
14639 | _("bad list length")); | |
14640 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14641 | inst.instruction |= 1 << 5; | |
14642 | if (et.size == 32 && align == 128) | |
14643 | inst.instruction |= 0x3 << 6; | |
14644 | else | |
14645 | inst.instruction |= neon_logbits (et.size) << 6; | |
14646 | } | |
14647 | break; | |
14648 | ||
14649 | default: ; | |
14650 | } | |
14651 | ||
14652 | inst.instruction |= do_align << 4; | |
14653 | } | |
14654 | ||
14655 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
14656 | apart from bits [11:4]. */ | |
14657 | ||
14658 | static void | |
14659 | do_neon_ldx_stx (void) | |
14660 | { | |
14661 | switch (NEON_LANE (inst.operands[0].imm)) | |
14662 | { | |
14663 | case NEON_INTERLEAVE_LANES: | |
14664 | inst.instruction = NEON_ENC_INTERLV (inst.instruction); | |
14665 | do_neon_ld_st_interleave (); | |
14666 | break; | |
5f4273c7 | 14667 | |
5287ad62 JB |
14668 | case NEON_ALL_LANES: |
14669 | inst.instruction = NEON_ENC_DUP (inst.instruction); | |
14670 | do_neon_ld_dup (); | |
14671 | break; | |
5f4273c7 | 14672 | |
5287ad62 JB |
14673 | default: |
14674 | inst.instruction = NEON_ENC_LANE (inst.instruction); | |
14675 | do_neon_ld_st_lane (); | |
14676 | } | |
14677 | ||
14678 | /* L bit comes from bit mask. */ | |
14679 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14680 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14681 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 14682 | |
5287ad62 JB |
14683 | if (inst.operands[1].postind) |
14684 | { | |
14685 | int postreg = inst.operands[1].imm & 0xf; | |
14686 | constraint (!inst.operands[1].immisreg, | |
14687 | _("post-index must be a register")); | |
14688 | constraint (postreg == 0xd || postreg == 0xf, | |
14689 | _("bad register for post-index")); | |
14690 | inst.instruction |= postreg; | |
14691 | } | |
14692 | else if (inst.operands[1].writeback) | |
14693 | { | |
14694 | inst.instruction |= 0xd; | |
14695 | } | |
14696 | else | |
5f4273c7 NC |
14697 | inst.instruction |= 0xf; |
14698 | ||
5287ad62 JB |
14699 | if (thumb_mode) |
14700 | inst.instruction |= 0xf9000000; | |
14701 | else | |
14702 | inst.instruction |= 0xf4000000; | |
14703 | } | |
5287ad62 JB |
14704 | \f |
14705 | /* Overall per-instruction processing. */ | |
14706 | ||
14707 | /* We need to be able to fix up arbitrary expressions in some statements. | |
14708 | This is so that we can handle symbols that are an arbitrary distance from | |
14709 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
14710 | which returns part of an address in a form which will be valid for | |
14711 | a data instruction. We do this by pushing the expression into a symbol | |
14712 | in the expr_section, and creating a fix for that. */ | |
14713 | ||
14714 | static void | |
14715 | fix_new_arm (fragS * frag, | |
14716 | int where, | |
14717 | short int size, | |
14718 | expressionS * exp, | |
14719 | int pc_rel, | |
14720 | int reloc) | |
14721 | { | |
14722 | fixS * new_fix; | |
14723 | ||
14724 | switch (exp->X_op) | |
14725 | { | |
14726 | case O_constant: | |
14727 | case O_symbol: | |
14728 | case O_add: | |
14729 | case O_subtract: | |
14730 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
14731 | break; | |
14732 | ||
14733 | default: | |
14734 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
14735 | pc_rel, reloc); | |
14736 | break; | |
14737 | } | |
14738 | ||
14739 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
14740 | instruction. */ | |
14741 | new_fix->tc_fix_data = thumb_mode; | |
14742 | } | |
14743 | ||
14744 | /* Create a frg for an instruction requiring relaxation. */ | |
14745 | static void | |
14746 | output_relax_insn (void) | |
14747 | { | |
14748 | char * to; | |
14749 | symbolS *sym; | |
0110f2b8 PB |
14750 | int offset; |
14751 | ||
6e1cb1a6 PB |
14752 | /* The size of the instruction is unknown, so tie the debug info to the |
14753 | start of the instruction. */ | |
14754 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 14755 | |
0110f2b8 PB |
14756 | switch (inst.reloc.exp.X_op) |
14757 | { | |
14758 | case O_symbol: | |
14759 | sym = inst.reloc.exp.X_add_symbol; | |
14760 | offset = inst.reloc.exp.X_add_number; | |
14761 | break; | |
14762 | case O_constant: | |
14763 | sym = NULL; | |
14764 | offset = inst.reloc.exp.X_add_number; | |
14765 | break; | |
14766 | default: | |
14767 | sym = make_expr_symbol (&inst.reloc.exp); | |
14768 | offset = 0; | |
14769 | break; | |
14770 | } | |
14771 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
14772 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
14773 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
14774 | } |
14775 | ||
14776 | /* Write a 32-bit thumb instruction to buf. */ | |
14777 | static void | |
14778 | put_thumb32_insn (char * buf, unsigned long insn) | |
14779 | { | |
14780 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
14781 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
14782 | } | |
14783 | ||
b99bd4ef | 14784 | static void |
c19d1205 | 14785 | output_inst (const char * str) |
b99bd4ef | 14786 | { |
c19d1205 | 14787 | char * to = NULL; |
b99bd4ef | 14788 | |
c19d1205 | 14789 | if (inst.error) |
b99bd4ef | 14790 | { |
c19d1205 | 14791 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
14792 | return; |
14793 | } | |
5f4273c7 NC |
14794 | if (inst.relax) |
14795 | { | |
14796 | output_relax_insn (); | |
0110f2b8 | 14797 | return; |
5f4273c7 | 14798 | } |
c19d1205 ZW |
14799 | if (inst.size == 0) |
14800 | return; | |
b99bd4ef | 14801 | |
c19d1205 | 14802 | to = frag_more (inst.size); |
8dc2430f NC |
14803 | /* PR 9814: Record the thumb mode into the current frag so that we know |
14804 | what type of NOP padding to use, if necessary. We override any previous | |
14805 | setting so that if the mode has changed then the NOPS that we use will | |
14806 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 14807 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
14808 | |
14809 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 14810 | { |
9c2799c2 | 14811 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 14812 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 14813 | } |
c19d1205 | 14814 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 14815 | { |
9c2799c2 | 14816 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
14817 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
14818 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 14819 | } |
c19d1205 ZW |
14820 | else |
14821 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 14822 | |
c19d1205 ZW |
14823 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
14824 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
14825 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
14826 | inst.reloc.type); | |
b99bd4ef | 14827 | |
c19d1205 | 14828 | dwarf2_emit_insn (inst.size); |
c19d1205 | 14829 | } |
b99bd4ef | 14830 | |
e07e6e58 NC |
14831 | static char * |
14832 | output_it_inst (int cond, int mask, char * to) | |
14833 | { | |
14834 | unsigned long instruction = 0xbf00; | |
14835 | ||
14836 | mask &= 0xf; | |
14837 | instruction |= mask; | |
14838 | instruction |= cond << 4; | |
14839 | ||
14840 | if (to == NULL) | |
14841 | { | |
14842 | to = frag_more (2); | |
14843 | #ifdef OBJ_ELF | |
14844 | dwarf2_emit_insn (2); | |
14845 | #endif | |
14846 | } | |
14847 | ||
14848 | md_number_to_chars (to, instruction, 2); | |
14849 | ||
14850 | return to; | |
14851 | } | |
14852 | ||
c19d1205 ZW |
14853 | /* Tag values used in struct asm_opcode's tag field. */ |
14854 | enum opcode_tag | |
14855 | { | |
14856 | OT_unconditional, /* Instruction cannot be conditionalized. | |
14857 | The ARM condition field is still 0xE. */ | |
14858 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
14859 | and carries 0xF in its ARM condition field. */ | |
14860 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
14861 | OT_csuffixF, /* Some forms of the instruction take a conditional |
14862 | suffix, others place 0xF where the condition field | |
14863 | would be. */ | |
c19d1205 ZW |
14864 | OT_cinfix3, /* Instruction takes a conditional infix, |
14865 | beginning at character index 3. (In | |
14866 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
14867 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
14868 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
14869 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
14870 | character index 3, even in unified mode. Used for | |
14871 | legacy instructions where suffix and infix forms | |
14872 | may be ambiguous. */ | |
c19d1205 | 14873 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 14874 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
14875 | OT_odd_infix_unc, /* This is the unconditional variant of an |
14876 | instruction that takes a conditional infix | |
14877 | at an unusual position. In unified mode, | |
14878 | this variant will accept a suffix. */ | |
14879 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
14880 | are the conditional variants of instructions that | |
14881 | take conditional infixes in unusual positions. | |
14882 | The infix appears at character index | |
14883 | (tag - OT_odd_infix_0). These are not accepted | |
14884 | in unified mode. */ | |
14885 | }; | |
b99bd4ef | 14886 | |
c19d1205 ZW |
14887 | /* Subroutine of md_assemble, responsible for looking up the primary |
14888 | opcode from the mnemonic the user wrote. STR points to the | |
14889 | beginning of the mnemonic. | |
14890 | ||
14891 | This is not simply a hash table lookup, because of conditional | |
14892 | variants. Most instructions have conditional variants, which are | |
14893 | expressed with a _conditional affix_ to the mnemonic. If we were | |
14894 | to encode each conditional variant as a literal string in the opcode | |
14895 | table, it would have approximately 20,000 entries. | |
14896 | ||
14897 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
14898 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
14899 | instructions take the affix as an infix, notably the s-variants of | |
14900 | the arithmetic instructions. Of those instructions, all but six | |
14901 | have the infix appear after the third character of the mnemonic. | |
14902 | ||
14903 | Accordingly, the algorithm for looking up primary opcodes given | |
14904 | an identifier is: | |
14905 | ||
14906 | 1. Look up the identifier in the opcode table. | |
14907 | If we find a match, go to step U. | |
14908 | ||
14909 | 2. Look up the last two characters of the identifier in the | |
14910 | conditions table. If we find a match, look up the first N-2 | |
14911 | characters of the identifier in the opcode table. If we | |
14912 | find a match, go to step CE. | |
14913 | ||
14914 | 3. Look up the fourth and fifth characters of the identifier in | |
14915 | the conditions table. If we find a match, extract those | |
14916 | characters from the identifier, and look up the remaining | |
14917 | characters in the opcode table. If we find a match, go | |
14918 | to step CM. | |
14919 | ||
14920 | 4. Fail. | |
14921 | ||
14922 | U. Examine the tag field of the opcode structure, in case this is | |
14923 | one of the six instructions with its conditional infix in an | |
14924 | unusual place. If it is, the tag tells us where to find the | |
14925 | infix; look it up in the conditions table and set inst.cond | |
14926 | accordingly. Otherwise, this is an unconditional instruction. | |
14927 | Again set inst.cond accordingly. Return the opcode structure. | |
14928 | ||
14929 | CE. Examine the tag field to make sure this is an instruction that | |
14930 | should receive a conditional suffix. If it is not, fail. | |
14931 | Otherwise, set inst.cond from the suffix we already looked up, | |
14932 | and return the opcode structure. | |
14933 | ||
14934 | CM. Examine the tag field to make sure this is an instruction that | |
14935 | should receive a conditional infix after the third character. | |
14936 | If it is not, fail. Otherwise, undo the edits to the current | |
14937 | line of input and proceed as for case CE. */ | |
14938 | ||
14939 | static const struct asm_opcode * | |
14940 | opcode_lookup (char **str) | |
14941 | { | |
14942 | char *end, *base; | |
14943 | char *affix; | |
14944 | const struct asm_opcode *opcode; | |
14945 | const struct asm_cond *cond; | |
e3cb604e | 14946 | char save[2]; |
267d2029 | 14947 | bfd_boolean neon_supported; |
5f4273c7 | 14948 | |
267d2029 | 14949 | neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1); |
c19d1205 ZW |
14950 | |
14951 | /* Scan up to the end of the mnemonic, which must end in white space, | |
267d2029 | 14952 | '.' (in unified mode, or for Neon instructions), or end of string. */ |
c19d1205 | 14953 | for (base = end = *str; *end != '\0'; end++) |
267d2029 | 14954 | if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.')) |
c19d1205 | 14955 | break; |
b99bd4ef | 14956 | |
c19d1205 | 14957 | if (end == base) |
c921be7d | 14958 | return NULL; |
b99bd4ef | 14959 | |
5287ad62 | 14960 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 14961 | if (end[0] == '.') |
b99bd4ef | 14962 | { |
5287ad62 | 14963 | int offset = 2; |
5f4273c7 | 14964 | |
267d2029 JB |
14965 | /* The .w and .n suffixes are only valid if the unified syntax is in |
14966 | use. */ | |
14967 | if (unified_syntax && end[1] == 'w') | |
c19d1205 | 14968 | inst.size_req = 4; |
267d2029 | 14969 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
14970 | inst.size_req = 2; |
14971 | else | |
5287ad62 JB |
14972 | offset = 0; |
14973 | ||
14974 | inst.vectype.elems = 0; | |
14975 | ||
14976 | *str = end + offset; | |
b99bd4ef | 14977 | |
5f4273c7 | 14978 | if (end[offset] == '.') |
5287ad62 | 14979 | { |
267d2029 JB |
14980 | /* See if we have a Neon type suffix (possible in either unified or |
14981 | non-unified ARM syntax mode). */ | |
dcbf9037 | 14982 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
c921be7d | 14983 | return NULL; |
5287ad62 JB |
14984 | } |
14985 | else if (end[offset] != '\0' && end[offset] != ' ') | |
c921be7d | 14986 | return NULL; |
b99bd4ef | 14987 | } |
c19d1205 ZW |
14988 | else |
14989 | *str = end; | |
b99bd4ef | 14990 | |
c19d1205 ZW |
14991 | /* Look for unaffixed or special-case affixed mnemonic. */ |
14992 | opcode = hash_find_n (arm_ops_hsh, base, end - base); | |
14993 | if (opcode) | |
b99bd4ef | 14994 | { |
c19d1205 ZW |
14995 | /* step U */ |
14996 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 14997 | { |
c19d1205 ZW |
14998 | inst.cond = COND_ALWAYS; |
14999 | return opcode; | |
b99bd4ef | 15000 | } |
b99bd4ef | 15001 | |
278df34e | 15002 | if (warn_on_deprecated && unified_syntax) |
c19d1205 ZW |
15003 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
15004 | affix = base + (opcode->tag - OT_odd_infix_0); | |
15005 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
9c2799c2 | 15006 | gas_assert (cond); |
b99bd4ef | 15007 | |
c19d1205 ZW |
15008 | inst.cond = cond->value; |
15009 | return opcode; | |
15010 | } | |
b99bd4ef | 15011 | |
c19d1205 ZW |
15012 | /* Cannot have a conditional suffix on a mnemonic of less than two |
15013 | characters. */ | |
15014 | if (end - base < 3) | |
c921be7d | 15015 | return NULL; |
b99bd4ef | 15016 | |
c19d1205 ZW |
15017 | /* Look for suffixed mnemonic. */ |
15018 | affix = end - 2; | |
15019 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
15020 | opcode = hash_find_n (arm_ops_hsh, base, affix - base); | |
15021 | if (opcode && cond) | |
15022 | { | |
15023 | /* step CE */ | |
15024 | switch (opcode->tag) | |
15025 | { | |
e3cb604e PB |
15026 | case OT_cinfix3_legacy: |
15027 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
15028 | break; | |
15029 | ||
c19d1205 | 15030 | case OT_cinfix3: |
088fa78e | 15031 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
15032 | case OT_odd_infix_unc: |
15033 | if (!unified_syntax) | |
e3cb604e | 15034 | return 0; |
c19d1205 ZW |
15035 | /* else fall through */ |
15036 | ||
15037 | case OT_csuffix: | |
037e8744 | 15038 | case OT_csuffixF: |
c19d1205 ZW |
15039 | case OT_csuf_or_in3: |
15040 | inst.cond = cond->value; | |
15041 | return opcode; | |
15042 | ||
15043 | case OT_unconditional: | |
15044 | case OT_unconditionalF: | |
dfa9f0d5 | 15045 | if (thumb_mode) |
c921be7d | 15046 | inst.cond = cond->value; |
dfa9f0d5 PB |
15047 | else |
15048 | { | |
c921be7d | 15049 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
15050 | inst.error = BAD_COND; |
15051 | inst.cond = COND_ALWAYS; | |
15052 | } | |
c19d1205 | 15053 | return opcode; |
b99bd4ef | 15054 | |
c19d1205 | 15055 | default: |
c921be7d | 15056 | return NULL; |
c19d1205 ZW |
15057 | } |
15058 | } | |
b99bd4ef | 15059 | |
c19d1205 ZW |
15060 | /* Cannot have a usual-position infix on a mnemonic of less than |
15061 | six characters (five would be a suffix). */ | |
15062 | if (end - base < 6) | |
c921be7d | 15063 | return NULL; |
b99bd4ef | 15064 | |
c19d1205 ZW |
15065 | /* Look for infixed mnemonic in the usual position. */ |
15066 | affix = base + 3; | |
15067 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
e3cb604e | 15068 | if (!cond) |
c921be7d | 15069 | return NULL; |
e3cb604e PB |
15070 | |
15071 | memcpy (save, affix, 2); | |
15072 | memmove (affix, affix + 2, (end - affix) - 2); | |
15073 | opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2); | |
15074 | memmove (affix + 2, affix, (end - affix) - 2); | |
15075 | memcpy (affix, save, 2); | |
15076 | ||
088fa78e KH |
15077 | if (opcode |
15078 | && (opcode->tag == OT_cinfix3 | |
15079 | || opcode->tag == OT_cinfix3_deprecated | |
15080 | || opcode->tag == OT_csuf_or_in3 | |
15081 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 15082 | { |
c921be7d | 15083 | /* Step CM. */ |
278df34e | 15084 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
15085 | && (opcode->tag == OT_cinfix3 |
15086 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
15087 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
15088 | ||
15089 | inst.cond = cond->value; | |
15090 | return opcode; | |
b99bd4ef NC |
15091 | } |
15092 | ||
c921be7d | 15093 | return NULL; |
b99bd4ef NC |
15094 | } |
15095 | ||
e07e6e58 NC |
15096 | /* This function generates an initial IT instruction, leaving its block |
15097 | virtually open for the new instructions. Eventually, | |
15098 | the mask will be updated by now_it_add_mask () each time | |
15099 | a new instruction needs to be included in the IT block. | |
15100 | Finally, the block is closed with close_automatic_it_block (). | |
15101 | The block closure can be requested either from md_assemble (), | |
15102 | a tencode (), or due to a label hook. */ | |
15103 | ||
15104 | static void | |
15105 | new_automatic_it_block (int cond) | |
15106 | { | |
15107 | now_it.state = AUTOMATIC_IT_BLOCK; | |
15108 | now_it.mask = 0x18; | |
15109 | now_it.cc = cond; | |
15110 | now_it.block_length = 1; | |
cd000bff | 15111 | mapping_state (MAP_THUMB); |
e07e6e58 NC |
15112 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
15113 | } | |
15114 | ||
15115 | /* Close an automatic IT block. | |
15116 | See comments in new_automatic_it_block (). */ | |
15117 | ||
15118 | static void | |
15119 | close_automatic_it_block (void) | |
15120 | { | |
15121 | now_it.mask = 0x10; | |
15122 | now_it.block_length = 0; | |
15123 | } | |
15124 | ||
15125 | /* Update the mask of the current automatically-generated IT | |
15126 | instruction. See comments in new_automatic_it_block (). */ | |
15127 | ||
15128 | static void | |
15129 | now_it_add_mask (int cond) | |
15130 | { | |
15131 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
15132 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
15133 | | ((bitvalue) << (nbit))) | |
e07e6e58 | 15134 | const int resulting_bit = (cond & 1); |
c921be7d | 15135 | |
e07e6e58 NC |
15136 | now_it.mask &= 0xf; |
15137 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15138 | resulting_bit, | |
15139 | (5 - now_it.block_length)); | |
15140 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15141 | 1, | |
15142 | ((5 - now_it.block_length) - 1) ); | |
15143 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); | |
15144 | ||
15145 | #undef CLEAR_BIT | |
15146 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
15147 | } |
15148 | ||
15149 | /* The IT blocks handling machinery is accessed through the these functions: | |
15150 | it_fsm_pre_encode () from md_assemble () | |
15151 | set_it_insn_type () optional, from the tencode functions | |
15152 | set_it_insn_type_last () ditto | |
15153 | in_it_block () ditto | |
15154 | it_fsm_post_encode () from md_assemble () | |
15155 | force_automatic_it_block_close () from label habdling functions | |
15156 | ||
15157 | Rationale: | |
15158 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
15159 | initializing the IT insn type with a generic initial value depending | |
15160 | on the inst.condition. | |
15161 | 2) During the tencode function, two things may happen: | |
15162 | a) The tencode function overrides the IT insn type by | |
15163 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
15164 | b) The tencode function queries the IT block state by | |
15165 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
15166 | ||
15167 | Both set_it_insn_type and in_it_block run the internal FSM state | |
15168 | handling function (handle_it_state), because: a) setting the IT insn | |
15169 | type may incur in an invalid state (exiting the function), | |
15170 | and b) querying the state requires the FSM to be updated. | |
15171 | Specifically we want to avoid creating an IT block for conditional | |
15172 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
15173 | determine whether an IT block is required until the tencode () routine | |
15174 | has decided what type of instruction this actually it. | |
15175 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
15176 | set_it_insn_type has to be called first. | |
15177 | ||
15178 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
15179 | determines the insn IT type depending on the inst.cond code. | |
15180 | When a tencode () routine encodes an instruction that can be | |
15181 | either outside an IT block, or, in the case of being inside, has to be | |
15182 | the last one, set_it_insn_type_last () will determine the proper | |
15183 | IT instruction type based on the inst.cond code. Otherwise, | |
15184 | set_it_insn_type can be called for overriding that logic or | |
15185 | for covering other cases. | |
15186 | ||
15187 | Calling handle_it_state () may not transition the IT block state to | |
15188 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
15189 | still queried. Instead, if the FSM determines that the state should | |
15190 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
15191 | after the tencode () function: that's what it_fsm_post_encode () does. | |
15192 | ||
15193 | Since in_it_block () calls the state handling function to get an | |
15194 | updated state, an error may occur (due to invalid insns combination). | |
15195 | In that case, inst.error is set. | |
15196 | Therefore, inst.error has to be checked after the execution of | |
15197 | the tencode () routine. | |
15198 | ||
15199 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
15200 | any pending state change (if any) that didn't take place in | |
15201 | handle_it_state () as explained above. */ | |
15202 | ||
15203 | static void | |
15204 | it_fsm_pre_encode (void) | |
15205 | { | |
15206 | if (inst.cond != COND_ALWAYS) | |
15207 | inst.it_insn_type = INSIDE_IT_INSN; | |
15208 | else | |
15209 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
15210 | ||
15211 | now_it.state_handled = 0; | |
15212 | } | |
15213 | ||
15214 | /* IT state FSM handling function. */ | |
15215 | ||
15216 | static int | |
15217 | handle_it_state (void) | |
15218 | { | |
15219 | now_it.state_handled = 1; | |
15220 | ||
15221 | switch (now_it.state) | |
15222 | { | |
15223 | case OUTSIDE_IT_BLOCK: | |
15224 | switch (inst.it_insn_type) | |
15225 | { | |
15226 | case OUTSIDE_IT_INSN: | |
15227 | break; | |
15228 | ||
15229 | case INSIDE_IT_INSN: | |
15230 | case INSIDE_IT_LAST_INSN: | |
15231 | if (thumb_mode == 0) | |
15232 | { | |
c921be7d | 15233 | if (unified_syntax |
e07e6e58 NC |
15234 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
15235 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
15236 | " for Thumb.")); | |
15237 | } | |
15238 | else | |
15239 | { | |
15240 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
15241 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
15242 | { | |
15243 | /* Automatically generate the IT instruction. */ | |
15244 | new_automatic_it_block (inst.cond); | |
15245 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
15246 | close_automatic_it_block (); | |
15247 | } | |
15248 | else | |
15249 | { | |
15250 | inst.error = BAD_OUT_IT; | |
15251 | return FAIL; | |
15252 | } | |
15253 | } | |
15254 | break; | |
15255 | ||
15256 | case IF_INSIDE_IT_LAST_INSN: | |
15257 | case NEUTRAL_IT_INSN: | |
15258 | break; | |
15259 | ||
15260 | case IT_INSN: | |
15261 | now_it.state = MANUAL_IT_BLOCK; | |
15262 | now_it.block_length = 0; | |
15263 | break; | |
15264 | } | |
15265 | break; | |
15266 | ||
15267 | case AUTOMATIC_IT_BLOCK: | |
15268 | /* Three things may happen now: | |
15269 | a) We should increment current it block size; | |
15270 | b) We should close current it block (closing insn or 4 insns); | |
15271 | c) We should close current it block and start a new one (due | |
15272 | to incompatible conditions or | |
15273 | 4 insns-length block reached). */ | |
15274 | ||
15275 | switch (inst.it_insn_type) | |
15276 | { | |
15277 | case OUTSIDE_IT_INSN: | |
15278 | /* The closure of the block shall happen immediatelly, | |
15279 | so any in_it_block () call reports the block as closed. */ | |
15280 | force_automatic_it_block_close (); | |
15281 | break; | |
15282 | ||
15283 | case INSIDE_IT_INSN: | |
15284 | case INSIDE_IT_LAST_INSN: | |
15285 | case IF_INSIDE_IT_LAST_INSN: | |
15286 | now_it.block_length++; | |
15287 | ||
15288 | if (now_it.block_length > 4 | |
15289 | || !now_it_compatible (inst.cond)) | |
15290 | { | |
15291 | force_automatic_it_block_close (); | |
15292 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
15293 | new_automatic_it_block (inst.cond); | |
15294 | } | |
15295 | else | |
15296 | { | |
15297 | now_it_add_mask (inst.cond); | |
15298 | } | |
15299 | ||
15300 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
15301 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
15302 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
15303 | close_automatic_it_block (); | |
15304 | break; | |
15305 | ||
15306 | case NEUTRAL_IT_INSN: | |
15307 | now_it.block_length++; | |
15308 | ||
15309 | if (now_it.block_length > 4) | |
15310 | force_automatic_it_block_close (); | |
15311 | else | |
15312 | now_it_add_mask (now_it.cc & 1); | |
15313 | break; | |
15314 | ||
15315 | case IT_INSN: | |
15316 | close_automatic_it_block (); | |
15317 | now_it.state = MANUAL_IT_BLOCK; | |
15318 | break; | |
15319 | } | |
15320 | break; | |
15321 | ||
15322 | case MANUAL_IT_BLOCK: | |
15323 | { | |
15324 | /* Check conditional suffixes. */ | |
15325 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
15326 | int is_last; | |
15327 | now_it.mask <<= 1; | |
15328 | now_it.mask &= 0x1f; | |
15329 | is_last = (now_it.mask == 0x10); | |
15330 | ||
15331 | switch (inst.it_insn_type) | |
15332 | { | |
15333 | case OUTSIDE_IT_INSN: | |
15334 | inst.error = BAD_NOT_IT; | |
15335 | return FAIL; | |
15336 | ||
15337 | case INSIDE_IT_INSN: | |
15338 | if (cond != inst.cond) | |
15339 | { | |
15340 | inst.error = BAD_IT_COND; | |
15341 | return FAIL; | |
15342 | } | |
15343 | break; | |
15344 | ||
15345 | case INSIDE_IT_LAST_INSN: | |
15346 | case IF_INSIDE_IT_LAST_INSN: | |
15347 | if (cond != inst.cond) | |
15348 | { | |
15349 | inst.error = BAD_IT_COND; | |
15350 | return FAIL; | |
15351 | } | |
15352 | if (!is_last) | |
15353 | { | |
15354 | inst.error = BAD_BRANCH; | |
15355 | return FAIL; | |
15356 | } | |
15357 | break; | |
15358 | ||
15359 | case NEUTRAL_IT_INSN: | |
15360 | /* The BKPT instruction is unconditional even in an IT block. */ | |
15361 | break; | |
15362 | ||
15363 | case IT_INSN: | |
15364 | inst.error = BAD_IT_IT; | |
15365 | return FAIL; | |
15366 | } | |
15367 | } | |
15368 | break; | |
15369 | } | |
15370 | ||
15371 | return SUCCESS; | |
15372 | } | |
15373 | ||
15374 | static void | |
15375 | it_fsm_post_encode (void) | |
15376 | { | |
15377 | int is_last; | |
15378 | ||
15379 | if (!now_it.state_handled) | |
15380 | handle_it_state (); | |
15381 | ||
15382 | is_last = (now_it.mask == 0x10); | |
15383 | if (is_last) | |
15384 | { | |
15385 | now_it.state = OUTSIDE_IT_BLOCK; | |
15386 | now_it.mask = 0; | |
15387 | } | |
15388 | } | |
15389 | ||
15390 | static void | |
15391 | force_automatic_it_block_close (void) | |
15392 | { | |
15393 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
15394 | { | |
15395 | close_automatic_it_block (); | |
15396 | now_it.state = OUTSIDE_IT_BLOCK; | |
15397 | now_it.mask = 0; | |
15398 | } | |
15399 | } | |
15400 | ||
15401 | static int | |
15402 | in_it_block (void) | |
15403 | { | |
15404 | if (!now_it.state_handled) | |
15405 | handle_it_state (); | |
15406 | ||
15407 | return now_it.state != OUTSIDE_IT_BLOCK; | |
15408 | } | |
15409 | ||
c19d1205 ZW |
15410 | void |
15411 | md_assemble (char *str) | |
b99bd4ef | 15412 | { |
c19d1205 ZW |
15413 | char *p = str; |
15414 | const struct asm_opcode * opcode; | |
b99bd4ef | 15415 | |
c19d1205 ZW |
15416 | /* Align the previous label if needed. */ |
15417 | if (last_label_seen != NULL) | |
b99bd4ef | 15418 | { |
c19d1205 ZW |
15419 | symbol_set_frag (last_label_seen, frag_now); |
15420 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
15421 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
15422 | } |
15423 | ||
c19d1205 ZW |
15424 | memset (&inst, '\0', sizeof (inst)); |
15425 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 15426 | |
c19d1205 ZW |
15427 | opcode = opcode_lookup (&p); |
15428 | if (!opcode) | |
b99bd4ef | 15429 | { |
c19d1205 | 15430 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 15431 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d NC |
15432 | if (! create_register_alias (str, p) |
15433 | && ! create_neon_reg_alias (str, p)) | |
c19d1205 | 15434 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 15435 | |
b99bd4ef NC |
15436 | return; |
15437 | } | |
15438 | ||
278df34e | 15439 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
088fa78e KH |
15440 | as_warn (_("s suffix on comparison instruction is deprecated")); |
15441 | ||
037e8744 JB |
15442 | /* The value which unconditional instructions should have in place of the |
15443 | condition field. */ | |
15444 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
15445 | ||
c19d1205 | 15446 | if (thumb_mode) |
b99bd4ef | 15447 | { |
e74cfd16 | 15448 | arm_feature_set variant; |
8f06b2d8 PB |
15449 | |
15450 | variant = cpu_variant; | |
15451 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
15452 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
15453 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 15454 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
15455 | if (!opcode->tvariant |
15456 | || (thumb_mode == 1 | |
15457 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 15458 | { |
c19d1205 | 15459 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
15460 | return; |
15461 | } | |
c19d1205 ZW |
15462 | if (inst.cond != COND_ALWAYS && !unified_syntax |
15463 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 15464 | { |
c19d1205 | 15465 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
15466 | return; |
15467 | } | |
15468 | ||
752d5da4 | 15469 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)) |
076d447c | 15470 | { |
7e806470 | 15471 | if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23 |
752d5da4 NC |
15472 | && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr) |
15473 | || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier))) | |
15474 | { | |
15475 | /* Two things are addressed here. | |
15476 | 1) Implicit require narrow instructions on Thumb-1. | |
15477 | This avoids relaxation accidentally introducing Thumb-2 | |
15478 | instructions. | |
15479 | 2) Reject wide instructions in non Thumb-2 cores. */ | |
15480 | if (inst.size_req == 0) | |
15481 | inst.size_req = 2; | |
15482 | else if (inst.size_req == 4) | |
15483 | { | |
15484 | as_bad (_("selected processor does not support `%s'"), str); | |
15485 | return; | |
15486 | } | |
15487 | } | |
076d447c PB |
15488 | } |
15489 | ||
c19d1205 ZW |
15490 | inst.instruction = opcode->tvalue; |
15491 | ||
15492 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15493 | { |
15494 | /* Prepare the it_insn_type for those encodings that don't set | |
15495 | it. */ | |
15496 | it_fsm_pre_encode (); | |
c19d1205 | 15497 | |
e07e6e58 NC |
15498 | opcode->tencode (); |
15499 | ||
15500 | it_fsm_post_encode (); | |
15501 | } | |
e27ec89e | 15502 | |
0110f2b8 | 15503 | if (!(inst.error || inst.relax)) |
b99bd4ef | 15504 | { |
9c2799c2 | 15505 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
15506 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
15507 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 15508 | { |
c19d1205 | 15509 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
15510 | return; |
15511 | } | |
15512 | } | |
076d447c PB |
15513 | |
15514 | /* Something has gone badly wrong if we try to relax a fixed size | |
15515 | instruction. */ | |
9c2799c2 | 15516 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 15517 | |
e74cfd16 PB |
15518 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15519 | *opcode->tvariant); | |
ee065d83 | 15520 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 15521 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
7e806470 | 15522 | anything other than bl/blx and v6-M instructions. |
ee065d83 | 15523 | This is overly pessimistic for relaxable instructions. */ |
7e806470 PB |
15524 | if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) |
15525 | || inst.relax) | |
e07e6e58 NC |
15526 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
15527 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
e74cfd16 PB |
15528 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15529 | arm_ext_v6t2); | |
cd000bff DJ |
15530 | |
15531 | if (!inst.error) | |
c877a2f2 NC |
15532 | { |
15533 | mapping_state (MAP_THUMB); | |
15534 | } | |
c19d1205 | 15535 | } |
3e9e4fcf | 15536 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 15537 | { |
845b51d6 PB |
15538 | bfd_boolean is_bx; |
15539 | ||
15540 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
15541 | is_bx = (opcode->aencode == do_bx); | |
15542 | ||
c19d1205 | 15543 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
15544 | if (!(is_bx && fix_v4bx) |
15545 | && !(opcode->avariant && | |
15546 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 15547 | { |
c19d1205 ZW |
15548 | as_bad (_("selected processor does not support `%s'"), str); |
15549 | return; | |
b99bd4ef | 15550 | } |
c19d1205 | 15551 | if (inst.size_req) |
b99bd4ef | 15552 | { |
c19d1205 ZW |
15553 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
15554 | return; | |
b99bd4ef NC |
15555 | } |
15556 | ||
c19d1205 ZW |
15557 | inst.instruction = opcode->avalue; |
15558 | if (opcode->tag == OT_unconditionalF) | |
15559 | inst.instruction |= 0xF << 28; | |
15560 | else | |
15561 | inst.instruction |= inst.cond << 28; | |
15562 | inst.size = INSN_SIZE; | |
15563 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15564 | { |
15565 | it_fsm_pre_encode (); | |
15566 | opcode->aencode (); | |
15567 | it_fsm_post_encode (); | |
15568 | } | |
ee065d83 PB |
15569 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
15570 | on a hypothetical non-thumb v5 core. */ | |
845b51d6 | 15571 | if (is_bx) |
e74cfd16 | 15572 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 15573 | else |
e74cfd16 PB |
15574 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
15575 | *opcode->avariant); | |
cd000bff | 15576 | if (!inst.error) |
c877a2f2 NC |
15577 | { |
15578 | mapping_state (MAP_ARM); | |
15579 | } | |
b99bd4ef | 15580 | } |
3e9e4fcf JB |
15581 | else |
15582 | { | |
15583 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
15584 | "-- `%s'"), str); | |
15585 | return; | |
15586 | } | |
c19d1205 ZW |
15587 | output_inst (str); |
15588 | } | |
b99bd4ef | 15589 | |
e07e6e58 NC |
15590 | static void |
15591 | check_it_blocks_finished (void) | |
15592 | { | |
15593 | #ifdef OBJ_ELF | |
15594 | asection *sect; | |
15595 | ||
15596 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
15597 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
15598 | == MANUAL_IT_BLOCK) | |
15599 | { | |
15600 | as_warn (_("section '%s' finished with an open IT block."), | |
15601 | sect->name); | |
15602 | } | |
15603 | #else | |
15604 | if (now_it.state == MANUAL_IT_BLOCK) | |
15605 | as_warn (_("file finished with an open IT block.")); | |
15606 | #endif | |
15607 | } | |
15608 | ||
c19d1205 ZW |
15609 | /* Various frobbings of labels and their addresses. */ |
15610 | ||
15611 | void | |
15612 | arm_start_line_hook (void) | |
15613 | { | |
15614 | last_label_seen = NULL; | |
b99bd4ef NC |
15615 | } |
15616 | ||
c19d1205 ZW |
15617 | void |
15618 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 15619 | { |
c19d1205 | 15620 | last_label_seen = sym; |
b99bd4ef | 15621 | |
c19d1205 | 15622 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 15623 | |
c19d1205 ZW |
15624 | #if defined OBJ_COFF || defined OBJ_ELF |
15625 | ARM_SET_INTERWORK (sym, support_interwork); | |
15626 | #endif | |
b99bd4ef | 15627 | |
e07e6e58 NC |
15628 | force_automatic_it_block_close (); |
15629 | ||
5f4273c7 | 15630 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
15631 | as Thumb functions. This is because these labels, whilst |
15632 | they exist inside Thumb code, are not the entry points for | |
15633 | possible ARM->Thumb calls. Also, these labels can be used | |
15634 | as part of a computed goto or switch statement. eg gcc | |
15635 | can generate code that looks like this: | |
b99bd4ef | 15636 | |
c19d1205 ZW |
15637 | ldr r2, [pc, .Laaa] |
15638 | lsl r3, r3, #2 | |
15639 | ldr r2, [r3, r2] | |
15640 | mov pc, r2 | |
b99bd4ef | 15641 | |
c19d1205 ZW |
15642 | .Lbbb: .word .Lxxx |
15643 | .Lccc: .word .Lyyy | |
15644 | ..etc... | |
15645 | .Laaa: .word Lbbb | |
b99bd4ef | 15646 | |
c19d1205 ZW |
15647 | The first instruction loads the address of the jump table. |
15648 | The second instruction converts a table index into a byte offset. | |
15649 | The third instruction gets the jump address out of the table. | |
15650 | The fourth instruction performs the jump. | |
b99bd4ef | 15651 | |
c19d1205 ZW |
15652 | If the address stored at .Laaa is that of a symbol which has the |
15653 | Thumb_Func bit set, then the linker will arrange for this address | |
15654 | to have the bottom bit set, which in turn would mean that the | |
15655 | address computation performed by the third instruction would end | |
15656 | up with the bottom bit set. Since the ARM is capable of unaligned | |
15657 | word loads, the instruction would then load the incorrect address | |
15658 | out of the jump table, and chaos would ensue. */ | |
15659 | if (label_is_thumb_function_name | |
15660 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
15661 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 15662 | { |
c19d1205 ZW |
15663 | /* When the address of a Thumb function is taken the bottom |
15664 | bit of that address should be set. This will allow | |
15665 | interworking between Arm and Thumb functions to work | |
15666 | correctly. */ | |
b99bd4ef | 15667 | |
c19d1205 | 15668 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 15669 | |
c19d1205 | 15670 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 15671 | } |
07a53e5c | 15672 | |
07a53e5c | 15673 | dwarf2_emit_label (sym); |
b99bd4ef NC |
15674 | } |
15675 | ||
c921be7d | 15676 | bfd_boolean |
c19d1205 | 15677 | arm_data_in_code (void) |
b99bd4ef | 15678 | { |
c19d1205 | 15679 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 15680 | { |
c19d1205 ZW |
15681 | *input_line_pointer = '/'; |
15682 | input_line_pointer += 5; | |
15683 | *input_line_pointer = 0; | |
c921be7d | 15684 | return TRUE; |
b99bd4ef NC |
15685 | } |
15686 | ||
c921be7d | 15687 | return FALSE; |
b99bd4ef NC |
15688 | } |
15689 | ||
c19d1205 ZW |
15690 | char * |
15691 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 15692 | { |
c19d1205 | 15693 | int len; |
b99bd4ef | 15694 | |
c19d1205 ZW |
15695 | if (thumb_mode && (len = strlen (name)) > 5 |
15696 | && streq (name + len - 5, "/data")) | |
15697 | *(name + len - 5) = 0; | |
b99bd4ef | 15698 | |
c19d1205 | 15699 | return name; |
b99bd4ef | 15700 | } |
c19d1205 ZW |
15701 | \f |
15702 | /* Table of all register names defined by default. The user can | |
15703 | define additional names with .req. Note that all register names | |
15704 | should appear in both upper and lowercase variants. Some registers | |
15705 | also have mixed-case names. */ | |
b99bd4ef | 15706 | |
dcbf9037 | 15707 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 15708 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 15709 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
15710 | #define REGSET(p,t) \ |
15711 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
15712 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
15713 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
15714 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
15715 | #define REGSETH(p,t) \ |
15716 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
15717 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
15718 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
15719 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
15720 | #define REGSET2(p,t) \ | |
15721 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
15722 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
15723 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
15724 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
7ed4c4c5 | 15725 | |
c19d1205 | 15726 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 15727 | { |
c19d1205 ZW |
15728 | /* ARM integer registers. */ |
15729 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 15730 | |
c19d1205 ZW |
15731 | /* ATPCS synonyms. */ |
15732 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
15733 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
15734 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 15735 | |
c19d1205 ZW |
15736 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
15737 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
15738 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 15739 | |
c19d1205 ZW |
15740 | /* Well-known aliases. */ |
15741 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
15742 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
15743 | ||
15744 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
15745 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
15746 | ||
15747 | /* Coprocessor numbers. */ | |
15748 | REGSET(p, CP), REGSET(P, CP), | |
15749 | ||
15750 | /* Coprocessor register numbers. The "cr" variants are for backward | |
15751 | compatibility. */ | |
15752 | REGSET(c, CN), REGSET(C, CN), | |
15753 | REGSET(cr, CN), REGSET(CR, CN), | |
15754 | ||
15755 | /* FPA registers. */ | |
15756 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
15757 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
15758 | ||
15759 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
15760 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
15761 | ||
15762 | /* VFP SP registers. */ | |
5287ad62 JB |
15763 | REGSET(s,VFS), REGSET(S,VFS), |
15764 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
15765 | |
15766 | /* VFP DP Registers. */ | |
5287ad62 JB |
15767 | REGSET(d,VFD), REGSET(D,VFD), |
15768 | /* Extra Neon DP registers. */ | |
15769 | REGSETH(d,VFD), REGSETH(D,VFD), | |
15770 | ||
15771 | /* Neon QP registers. */ | |
15772 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
15773 | |
15774 | /* VFP control registers. */ | |
15775 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
15776 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
15777 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
15778 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
15779 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
15780 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
15781 | |
15782 | /* Maverick DSP coprocessor registers. */ | |
15783 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
15784 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
15785 | ||
15786 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
15787 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
15788 | REGDEF(dspsc,0,DSPSC), | |
15789 | ||
15790 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
15791 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
15792 | REGDEF(DSPSC,0,DSPSC), | |
15793 | ||
15794 | /* iWMMXt data registers - p0, c0-15. */ | |
15795 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
15796 | ||
15797 | /* iWMMXt control registers - p1, c0-3. */ | |
15798 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
15799 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
15800 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
15801 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
15802 | ||
15803 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
15804 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
15805 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
15806 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
15807 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
15808 | ||
15809 | /* XScale accumulator registers. */ | |
15810 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
15811 | }; | |
15812 | #undef REGDEF | |
15813 | #undef REGNUM | |
15814 | #undef REGSET | |
7ed4c4c5 | 15815 | |
c19d1205 ZW |
15816 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
15817 | within psr_required_here. */ | |
15818 | static const struct asm_psr psrs[] = | |
15819 | { | |
15820 | /* Backward compatibility notation. Note that "all" is no longer | |
15821 | truly all possible PSR bits. */ | |
15822 | {"all", PSR_c | PSR_f}, | |
15823 | {"flg", PSR_f}, | |
15824 | {"ctl", PSR_c}, | |
15825 | ||
15826 | /* Individual flags. */ | |
15827 | {"f", PSR_f}, | |
15828 | {"c", PSR_c}, | |
15829 | {"x", PSR_x}, | |
15830 | {"s", PSR_s}, | |
15831 | /* Combinations of flags. */ | |
15832 | {"fs", PSR_f | PSR_s}, | |
15833 | {"fx", PSR_f | PSR_x}, | |
15834 | {"fc", PSR_f | PSR_c}, | |
15835 | {"sf", PSR_s | PSR_f}, | |
15836 | {"sx", PSR_s | PSR_x}, | |
15837 | {"sc", PSR_s | PSR_c}, | |
15838 | {"xf", PSR_x | PSR_f}, | |
15839 | {"xs", PSR_x | PSR_s}, | |
15840 | {"xc", PSR_x | PSR_c}, | |
15841 | {"cf", PSR_c | PSR_f}, | |
15842 | {"cs", PSR_c | PSR_s}, | |
15843 | {"cx", PSR_c | PSR_x}, | |
15844 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
15845 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
15846 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
15847 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
15848 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
15849 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
15850 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
15851 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
15852 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
15853 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
15854 | {"scf", PSR_s | PSR_c | PSR_f}, | |
15855 | {"scx", PSR_s | PSR_c | PSR_x}, | |
15856 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
15857 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
15858 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
15859 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
15860 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
15861 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
15862 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
15863 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
15864 | {"csf", PSR_c | PSR_s | PSR_f}, | |
15865 | {"csx", PSR_c | PSR_s | PSR_x}, | |
15866 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
15867 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
15868 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
15869 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
15870 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
15871 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
15872 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
15873 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
15874 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
15875 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
15876 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
15877 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
15878 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
15879 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
15880 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
15881 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
15882 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
15883 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
15884 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
15885 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
15886 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
15887 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
15888 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
15889 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
15890 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
15891 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
15892 | }; | |
15893 | ||
62b3e311 PB |
15894 | /* Table of V7M psr names. */ |
15895 | static const struct asm_psr v7m_psrs[] = | |
15896 | { | |
2b744c99 PB |
15897 | {"apsr", 0 }, {"APSR", 0 }, |
15898 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
15899 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
15900 | {"psr", 3 }, {"PSR", 3 }, | |
15901 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
15902 | {"ipsr", 5 }, {"IPSR", 5 }, | |
15903 | {"epsr", 6 }, {"EPSR", 6 }, | |
15904 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
15905 | {"msp", 8 }, {"MSP", 8 }, | |
15906 | {"psp", 9 }, {"PSP", 9 }, | |
15907 | {"primask", 16}, {"PRIMASK", 16}, | |
15908 | {"basepri", 17}, {"BASEPRI", 17}, | |
15909 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, | |
15910 | {"faultmask", 19}, {"FAULTMASK", 19}, | |
15911 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
15912 | }; |
15913 | ||
c19d1205 ZW |
15914 | /* Table of all shift-in-operand names. */ |
15915 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 15916 | { |
c19d1205 ZW |
15917 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
15918 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
15919 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
15920 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
15921 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
15922 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
15923 | }; | |
b99bd4ef | 15924 | |
c19d1205 ZW |
15925 | /* Table of all explicit relocation names. */ |
15926 | #ifdef OBJ_ELF | |
15927 | static struct reloc_entry reloc_names[] = | |
15928 | { | |
15929 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
15930 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
15931 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
15932 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
15933 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
15934 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
15935 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
15936 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
15937 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
15938 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
15939 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
15940 | }; | |
15941 | #endif | |
b99bd4ef | 15942 | |
c19d1205 ZW |
15943 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
15944 | static const struct asm_cond conds[] = | |
15945 | { | |
15946 | {"eq", 0x0}, | |
15947 | {"ne", 0x1}, | |
15948 | {"cs", 0x2}, {"hs", 0x2}, | |
15949 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
15950 | {"mi", 0x4}, | |
15951 | {"pl", 0x5}, | |
15952 | {"vs", 0x6}, | |
15953 | {"vc", 0x7}, | |
15954 | {"hi", 0x8}, | |
15955 | {"ls", 0x9}, | |
15956 | {"ge", 0xa}, | |
15957 | {"lt", 0xb}, | |
15958 | {"gt", 0xc}, | |
15959 | {"le", 0xd}, | |
15960 | {"al", 0xe} | |
15961 | }; | |
bfae80f2 | 15962 | |
62b3e311 PB |
15963 | static struct asm_barrier_opt barrier_opt_names[] = |
15964 | { | |
15965 | { "sy", 0xf }, | |
15966 | { "un", 0x7 }, | |
15967 | { "st", 0xe }, | |
15968 | { "unst", 0x6 } | |
15969 | }; | |
15970 | ||
c19d1205 ZW |
15971 | /* Table of ARM-format instructions. */ |
15972 | ||
15973 | /* Macros for gluing together operand strings. N.B. In all cases | |
15974 | other than OPS0, the trailing OP_stop comes from default | |
15975 | zero-initialization of the unspecified elements of the array. */ | |
15976 | #define OPS0() { OP_stop, } | |
15977 | #define OPS1(a) { OP_##a, } | |
15978 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
15979 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
15980 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
15981 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
15982 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
15983 | ||
15984 | /* These macros abstract out the exact format of the mnemonic table and | |
15985 | save some repeated characters. */ | |
15986 | ||
15987 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
15988 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
15989 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 15990 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15991 | |
15992 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
15993 | a T_MNEM_xyz enumerator. */ | |
15994 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 15995 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 15996 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15997 | TxCE (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
c19d1205 ZW |
15998 | |
15999 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
16000 | infix after the third character. */ | |
16001 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
16002 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 16003 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e KH |
16004 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
16005 | { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ | |
16006 | THUMB_VARIANT, do_##ae, do_##te } | |
c19d1205 | 16007 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16008 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 16009 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16010 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 16011 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16012 | TxC3 (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
088fa78e | 16013 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 16014 | TxC3w (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
c19d1205 ZW |
16015 | |
16016 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
16017 | appear in the condition table. */ | |
16018 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
e07e6e58 | 16019 | { #m1 #m2 #m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \ |
1887dd22 | 16020 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16021 | |
16022 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
16023 | TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \ |
16024 | TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \ | |
16025 | TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \ | |
16026 | TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \ | |
16027 | TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \ | |
16028 | TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \ | |
16029 | TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \ | |
16030 | TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \ | |
16031 | TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \ | |
16032 | TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \ | |
16033 | TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \ | |
16034 | TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \ | |
16035 | TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \ | |
16036 | TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \ | |
16037 | TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \ | |
16038 | TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \ | |
16039 | TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \ | |
16040 | TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \ | |
16041 | TxCM_ (m1, al, m2, op, top, nops, ops, ae, te) | |
c19d1205 ZW |
16042 | |
16043 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
16044 | TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te) |
16045 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
16046 | TxCM (m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
c19d1205 ZW |
16047 | |
16048 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
16049 | field is still 0xE. Many of the Thumb variants can be executed |
16050 | conditionally, so this is checked separately. */ | |
c19d1205 ZW |
16051 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
16052 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 16053 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16054 | |
16055 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
16056 | condition code field. */ | |
16057 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
16058 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 16059 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
16060 | |
16061 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
16062 | #define CE(mnem, op, nops, ops, ae) \ |
16063 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
16064 | ||
16065 | #define C3(mnem, op, nops, ops, ae) \ | |
16066 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
16067 | ||
e3cb604e PB |
16068 | /* Legacy mnemonics that always have conditional infix after the third |
16069 | character. */ | |
16070 | #define CL(mnem, op, nops, ops, ae) \ | |
16071 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
16072 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
16073 | ||
8f06b2d8 PB |
16074 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
16075 | #define cCE(mnem, op, nops, ops, ae) \ | |
16076 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
16077 | ||
e3cb604e PB |
16078 | /* Legacy coprocessor instructions where conditional infix and conditional |
16079 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
16080 | not just the potentially ambiguous ones. */ | |
16081 | #define cCL(mnem, op, nops, ops, ae) \ | |
16082 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
16083 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
16084 | ||
16085 | /* Coprocessor, takes either a suffix or a position-3 infix | |
16086 | (for an FPA corner case). */ | |
16087 | #define C3E(mnem, op, nops, ops, ae) \ | |
16088 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
16089 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 16090 | |
6a86118a NC |
16091 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
16092 | { #m1 #m2 #m3, OPS##nops ops, \ | |
e07e6e58 | 16093 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \ |
6a86118a NC |
16094 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
16095 | ||
16096 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
16097 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
16098 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
16099 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
16100 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
16101 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
16102 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
16103 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
16104 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
16105 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
16106 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
16107 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
16108 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
16109 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
16110 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
16111 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
16112 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
16113 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
16114 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
16115 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
16116 | |
16117 | #define UE(mnem, op, nops, ops, ae) \ | |
16118 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16119 | ||
16120 | #define UF(mnem, op, nops, ops, ae) \ | |
16121 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16122 | ||
5287ad62 JB |
16123 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
16124 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
16125 | use the same encoding function for each. */ | |
16126 | #define NUF(mnem, op, nops, ops, enc) \ | |
16127 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
16128 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16129 | ||
16130 | /* Neon data processing, version which indirects through neon_enc_tab for | |
16131 | the various overloaded versions of opcodes. */ | |
16132 | #define nUF(mnem, op, nops, ops, enc) \ | |
16133 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \ | |
16134 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16135 | ||
16136 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
16137 | version. */ | |
037e8744 JB |
16138 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
16139 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
16140 | THUMB_VARIANT, do_##enc, do_##enc } |
16141 | ||
037e8744 | 16142 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16143 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16144 | |
16145 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16146 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16147 | |
5287ad62 | 16148 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 JB |
16149 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
16150 | { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \ | |
5287ad62 JB |
16151 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
16152 | ||
037e8744 | 16153 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16154 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16155 | |
16156 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16157 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16158 | |
c19d1205 ZW |
16159 | #define do_0 0 |
16160 | ||
16161 | /* Thumb-only, unconditional. */ | |
e07e6e58 | 16162 | #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te) |
c19d1205 | 16163 | |
c19d1205 | 16164 | static const struct asm_opcode insns[] = |
bfae80f2 | 16165 | { |
e74cfd16 PB |
16166 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
16167 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
16168 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
16169 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
16170 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
16171 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
16172 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
16173 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
4962c51a MS |
16174 | tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub), |
16175 | tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
c19d1205 ZW |
16176 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), |
16177 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16178 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
16179 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
16180 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
16181 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16182 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
16183 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
16184 | ||
16185 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
16186 | for setting PSR flag bits. They are obsolete in V6 and do not | |
16187 | have Thumb equivalents. */ | |
16188 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 16189 | tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16190 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 | 16191 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
088fa78e | 16192 | tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
e3cb604e | 16193 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 | 16194 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 16195 | tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16196 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
16197 | |
16198 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
16199 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
16200 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
16201 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
16202 | ||
4962c51a MS |
16203 | tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), |
16204 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16205 | tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16206 | tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
c19d1205 | 16207 | |
f5208ef2 | 16208 | tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
16209 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16210 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
f5208ef2 | 16211 | tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
16212 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16213 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16214 | ||
16215 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
c16d2bf0 | 16216 | TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi), |
0110f2b8 | 16217 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 16218 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 16219 | |
c19d1205 | 16220 | /* Pseudo ops. */ |
e9f89963 | 16221 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
16222 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
16223 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
16224 | |
16225 | /* Thumb-compatibility pseudo ops. */ | |
16226 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
16227 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
16228 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
16229 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
16230 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 16231 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
16232 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
16233 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
16234 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
16235 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
16236 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
16237 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
16238 | ||
16a4cf17 PB |
16239 | /* These may simplify to neg. */ |
16240 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16241 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16242 | ||
c921be7d NC |
16243 | #undef THUMB_VARIANT |
16244 | #define THUMB_VARIANT & arm_ext_v6 | |
16245 | ||
2fc8bdac | 16246 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
16247 | |
16248 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
16249 | #undef THUMB_VARIANT |
16250 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16251 | ||
c19d1205 | 16252 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 16253 | TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16254 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
16255 | |
16256 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
3e94bf1a | 16257 | TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 16258 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), |
3e94bf1a | 16259 | TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 16260 | |
9c3c69f2 PB |
16261 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16262 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 16263 | |
9c3c69f2 PB |
16264 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16265 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
16266 | |
16267 | /* V1 instructions with no Thumb analogue at all. */ | |
16268 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
16269 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
16270 | ||
16271 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
16272 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
16273 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
16274 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
16275 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
16276 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
16277 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
16278 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
16279 | ||
c921be7d NC |
16280 | #undef ARM_VARIANT |
16281 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
16282 | #undef THUMB_VARIANT | |
16283 | #define THUMB_VARIANT & arm_ext_v4t | |
16284 | ||
c19d1205 ZW |
16285 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
16286 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
16287 | ||
c921be7d NC |
16288 | #undef THUMB_VARIANT |
16289 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16290 | ||
c19d1205 ZW |
16291 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
16292 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
16293 | ||
16294 | /* Generic coprocessor instructions. */ | |
16295 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
4962c51a MS |
16296 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
16297 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16298 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16299 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
16300 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), |
16301 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16302 | ||
c921be7d NC |
16303 | #undef ARM_VARIANT |
16304 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
16305 | ||
c19d1205 ZW |
16306 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
16307 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
16308 | ||
c921be7d NC |
16309 | #undef ARM_VARIANT |
16310 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
16311 | #undef THUMB_VARIANT | |
16312 | #define THUMB_VARIANT & arm_ext_msr | |
16313 | ||
037e8744 JB |
16314 | TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
16315 | TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), | |
c19d1205 | 16316 | |
c921be7d NC |
16317 | #undef ARM_VARIANT |
16318 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
16319 | #undef THUMB_VARIANT | |
16320 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16321 | ||
c19d1205 ZW |
16322 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
16323 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16324 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16325 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16326 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16327 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16328 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16329 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16330 | ||
c921be7d NC |
16331 | #undef ARM_VARIANT |
16332 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
16333 | #undef THUMB_VARIANT | |
16334 | #define THUMB_VARIANT & arm_ext_v4t | |
16335 | ||
4962c51a MS |
16336 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), |
16337 | tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16338 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16339 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16340 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16341 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 16342 | |
c921be7d NC |
16343 | #undef ARM_VARIANT |
16344 | #define ARM_VARIANT & arm_ext_v4t_5 | |
16345 | ||
c19d1205 ZW |
16346 | /* ARM Architecture 4T. */ |
16347 | /* Note: bx (and blx) are required on V5, even if the processor does | |
16348 | not support Thumb. */ | |
16349 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
16350 | ||
c921be7d NC |
16351 | #undef ARM_VARIANT |
16352 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
16353 | #undef THUMB_VARIANT | |
16354 | #define THUMB_VARIANT & arm_ext_v5t | |
16355 | ||
c19d1205 ZW |
16356 | /* Note: blx has 2 variants; the .value coded here is for |
16357 | BLX(2). Only this variant has conditional execution. */ | |
16358 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
16359 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
16360 | ||
c921be7d NC |
16361 | #undef THUMB_VARIANT |
16362 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16363 | ||
c19d1205 | 16364 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
4962c51a MS |
16365 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
16366 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16367 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16368 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
16369 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
16370 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16371 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16372 | ||
c921be7d NC |
16373 | #undef ARM_VARIANT |
16374 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ | |
16375 | ||
c19d1205 ZW |
16376 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16377 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16378 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16379 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16380 | ||
16381 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16382 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16383 | ||
16384 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16385 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16386 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16387 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16388 | ||
16389 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16390 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16391 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16392 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16393 | ||
16394 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16395 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16396 | ||
087b80de JM |
16397 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), |
16398 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16399 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16400 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
c19d1205 | 16401 | |
c921be7d NC |
16402 | #undef ARM_VARIANT |
16403 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ | |
16404 | ||
c19d1205 | 16405 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
79d49516 PB |
16406 | TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), |
16407 | TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 ZW |
16408 | |
16409 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16410 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16411 | ||
c921be7d NC |
16412 | #undef ARM_VARIANT |
16413 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
16414 | ||
c19d1205 ZW |
16415 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
16416 | ||
c921be7d NC |
16417 | #undef ARM_VARIANT |
16418 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
16419 | #undef THUMB_VARIANT | |
16420 | #define THUMB_VARIANT & arm_ext_v6 | |
16421 | ||
c19d1205 ZW |
16422 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
16423 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
16424 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16425 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16426 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16427 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16428 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16429 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16430 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16431 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
16432 | ||
c921be7d NC |
16433 | #undef THUMB_VARIANT |
16434 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16435 | ||
c19d1205 | 16436 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
91568d08 | 16437 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), |
c19d1205 ZW |
16438 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
16439 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 PB |
16440 | |
16441 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
16442 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
16443 | ||
16444 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
c921be7d NC |
16445 | #undef THUMB_VARIANT |
16446 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16447 | ||
dfa9f0d5 | 16448 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c19d1205 ZW |
16449 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
16450 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
16451 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16452 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16453 | TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16454 | /* Old name for QASX. */ | |
c19d1205 | 16455 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16456 | TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16457 | /* Old name for QSAX. */ | |
16458 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16459 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16460 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16461 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16462 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16463 | TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16464 | /* Old name for SASX. */ | |
c19d1205 ZW |
16465 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16466 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16467 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16468 | TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16469 | /* Old name for SHASX. */ | |
c19d1205 | 16470 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16471 | TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16472 | /* Old name for SHSAX. */ | |
16473 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16474 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16475 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16476 | TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16477 | /* Old name for SSAX. */ | |
16478 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16479 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16480 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16481 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16482 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16483 | TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16484 | /* Old name for UASX. */ | |
c19d1205 ZW |
16485 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16486 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16487 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16488 | TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16489 | /* Old name for UHASX. */ | |
c19d1205 | 16490 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16491 | TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16492 | /* Old name for UHSAX. */ | |
16493 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16494 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16495 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16496 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16497 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16498 | TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16499 | /* Old name for UQASX. */ | |
c19d1205 | 16500 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16501 | TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16502 | /* Old name for UQSAX. */ | |
16503 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16504 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16505 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 | 16506 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16507 | TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16508 | /* Old name for USAX. */ | |
c19d1205 | 16509 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 16510 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
16511 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), |
16512 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
16513 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
16514 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
16515 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
16516 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
16517 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
16518 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
16519 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16520 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16521 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16522 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16523 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16524 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16525 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16526 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 16527 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
16528 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
16529 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16530 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16531 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16532 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16533 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16534 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16535 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16536 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16537 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16538 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16539 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16540 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16541 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16542 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16543 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16544 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16545 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
b6702015 PB |
16546 | TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
16547 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), | |
16548 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), | |
16549 | TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs), | |
c19d1205 | 16550 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
c19d1205 ZW |
16551 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), |
16552 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16553 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
c19d1205 ZW |
16554 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), |
16555 | ||
c921be7d NC |
16556 | #undef ARM_VARIANT |
16557 | #define ARM_VARIANT & arm_ext_v6k | |
16558 | #undef THUMB_VARIANT | |
16559 | #define THUMB_VARIANT & arm_ext_v6k | |
16560 | ||
c19d1205 ZW |
16561 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
16562 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
16563 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
16564 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
16565 | ||
c921be7d NC |
16566 | #undef THUMB_VARIANT |
16567 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16568 | ||
ebdca51a PB |
16569 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), |
16570 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
16571 | ||
c921be7d NC |
16572 | #undef THUMB_VARIANT |
16573 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16574 | ||
c19d1205 ZW |
16575 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
16576 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
c19d1205 ZW |
16577 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), |
16578 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
c19d1205 ZW |
16579 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
16580 | ||
c921be7d NC |
16581 | #undef ARM_VARIANT |
16582 | #define ARM_VARIANT & arm_ext_v6z | |
16583 | ||
3eb17e6b | 16584 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 16585 | |
c921be7d NC |
16586 | #undef ARM_VARIANT |
16587 | #define ARM_VARIANT & arm_ext_v6t2 | |
16588 | ||
c19d1205 ZW |
16589 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
16590 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
16591 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16592 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16593 | ||
16594 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
b6895b4f PB |
16595 | TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), |
16596 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
401a54cf | 16597 | TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 ZW |
16598 | |
16599 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16600 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16601 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16602 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16603 | ||
25fe350b MS |
16604 | UT(cbnz, b900, 2, (RR, EXP), t_cbz), |
16605 | UT(cbz, b100, 2, (RR, EXP), t_cbz), | |
c921be7d NC |
16606 | |
16607 | /* ARM does not really have an IT instruction, so always allow it. | |
16608 | The opcode is copied from Thumb in order to allow warnings in | |
16609 | -mimplicit-it=[never | arm] modes. */ | |
16610 | #undef ARM_VARIANT | |
16611 | #define ARM_VARIANT & arm_ext_v1 | |
16612 | ||
e07e6e58 NC |
16613 | TUE(it, bf08, bf08, 1, (COND), it, t_it), |
16614 | TUE(itt, bf0c, bf0c, 1, (COND), it, t_it), | |
16615 | TUE(ite, bf04, bf04, 1, (COND), it, t_it), | |
16616 | TUE(ittt, bf0e, bf0e, 1, (COND), it, t_it), | |
16617 | TUE(itet, bf06, bf06, 1, (COND), it, t_it), | |
16618 | TUE(itte, bf0a, bf0a, 1, (COND), it, t_it), | |
16619 | TUE(itee, bf02, bf02, 1, (COND), it, t_it), | |
16620 | TUE(itttt, bf0f, bf0f, 1, (COND), it, t_it), | |
16621 | TUE(itett, bf07, bf07, 1, (COND), it, t_it), | |
16622 | TUE(ittet, bf0b, bf0b, 1, (COND), it, t_it), | |
16623 | TUE(iteet, bf03, bf03, 1, (COND), it, t_it), | |
16624 | TUE(ittte, bf0d, bf0d, 1, (COND), it, t_it), | |
16625 | TUE(itete, bf05, bf05, 1, (COND), it, t_it), | |
16626 | TUE(ittee, bf09, bf09, 1, (COND), it, t_it), | |
16627 | TUE(iteee, bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 JM |
16628 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
16629 | TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), | |
16630 | TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 16631 | |
92e90b6e | 16632 | /* Thumb2 only instructions. */ |
c921be7d NC |
16633 | #undef ARM_VARIANT |
16634 | #define ARM_VARIANT NULL | |
92e90b6e PB |
16635 | |
16636 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
16637 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
1c444d06 JM |
16638 | TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), |
16639 | TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
92e90b6e PB |
16640 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), |
16641 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
16642 | ||
62b3e311 | 16643 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
c921be7d NC |
16644 | #undef THUMB_VARIANT |
16645 | #define THUMB_VARIANT & arm_ext_div | |
16646 | ||
62b3e311 PB |
16647 | TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), |
16648 | TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
16649 | ||
7e806470 | 16650 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
16651 | #undef ARM_VARIANT |
16652 | #define ARM_VARIANT & arm_ext_barrier | |
16653 | #undef THUMB_VARIANT | |
16654 | #define THUMB_VARIANT & arm_ext_barrier | |
16655 | ||
7e806470 PB |
16656 | TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), |
16657 | TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
16658 | TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
16659 | ||
62b3e311 | 16660 | /* ARM V7 instructions. */ |
c921be7d NC |
16661 | #undef ARM_VARIANT |
16662 | #define ARM_VARIANT & arm_ext_v7 | |
16663 | #undef THUMB_VARIANT | |
16664 | #define THUMB_VARIANT & arm_ext_v7 | |
16665 | ||
62b3e311 PB |
16666 | TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld), |
16667 | TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 16668 | |
c921be7d NC |
16669 | #undef ARM_VARIANT |
16670 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
16671 | ||
8f06b2d8 PB |
16672 | cCE(wfs, e200110, 1, (RR), rd), |
16673 | cCE(rfs, e300110, 1, (RR), rd), | |
16674 | cCE(wfc, e400110, 1, (RR), rd), | |
16675 | cCE(rfc, e500110, 1, (RR), rd), | |
16676 | ||
4962c51a MS |
16677 | cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr), |
16678 | cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16679 | cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16680 | cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e | 16681 | |
4962c51a MS |
16682 | cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr), |
16683 | cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16684 | cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16685 | cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e PB |
16686 | |
16687 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
16688 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
16689 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
16690 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
16691 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
16692 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
16693 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
16694 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
16695 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
16696 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
16697 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
16698 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
16699 | ||
16700 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
16701 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
16702 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
16703 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
16704 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
16705 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
16706 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
16707 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
16708 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
16709 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
16710 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
16711 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
16712 | ||
16713 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
16714 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
16715 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
16716 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
16717 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
16718 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
16719 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
16720 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
16721 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
16722 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
16723 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
16724 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
16725 | ||
16726 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
16727 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
16728 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
16729 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
16730 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
16731 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
16732 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
16733 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
16734 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
16735 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
16736 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
16737 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
16738 | ||
16739 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
16740 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
16741 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
16742 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
16743 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
16744 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
16745 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
16746 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
16747 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
16748 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
16749 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
16750 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
16751 | ||
16752 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
16753 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
16754 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
16755 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
16756 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
16757 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
16758 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
16759 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
16760 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
16761 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
16762 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
16763 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
16764 | ||
16765 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
16766 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
16767 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
16768 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
16769 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
16770 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
16771 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
16772 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
16773 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
16774 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
16775 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
16776 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
16777 | ||
16778 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
16779 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
16780 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
16781 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
16782 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
16783 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
16784 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
16785 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
16786 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
16787 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
16788 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
16789 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
16790 | ||
16791 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
16792 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
16793 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
16794 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
16795 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
16796 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
16797 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
16798 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
16799 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
16800 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
16801 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
16802 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
16803 | ||
16804 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
16805 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
16806 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
16807 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
16808 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
16809 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
16810 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
16811 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
16812 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
16813 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
16814 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
16815 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
16816 | ||
16817 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
16818 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
16819 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
16820 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
16821 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
16822 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
16823 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
16824 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
16825 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
16826 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
16827 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
16828 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
16829 | ||
16830 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
16831 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
16832 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
16833 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
16834 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
16835 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
16836 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
16837 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
16838 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
16839 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
16840 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
16841 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
16842 | ||
16843 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
16844 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
16845 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
16846 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
16847 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
16848 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
16849 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
16850 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
16851 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
16852 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
16853 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
16854 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
16855 | ||
16856 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
16857 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
16858 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
16859 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
16860 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
16861 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
16862 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
16863 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
16864 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
16865 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
16866 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
16867 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
16868 | ||
16869 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
16870 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
16871 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
16872 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
16873 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
16874 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
16875 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
16876 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
16877 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
16878 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
16879 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
16880 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
16881 | ||
16882 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
16883 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
16884 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
16885 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
16886 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
16887 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
16888 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
16889 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
16890 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
16891 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
16892 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
16893 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
16894 | ||
16895 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16896 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16897 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16898 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16899 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16900 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16901 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16902 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16903 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16904 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16905 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16906 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16907 | ||
16908 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16909 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16910 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16911 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16912 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16913 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16914 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16915 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16916 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16917 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16918 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16919 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16920 | ||
16921 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16922 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16923 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16924 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16925 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16926 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16927 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16928 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16929 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16930 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16931 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16932 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16933 | ||
16934 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16935 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16936 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16937 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16938 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16939 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16940 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16941 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16942 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16943 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16944 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16945 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16946 | ||
16947 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16948 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16949 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16950 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16951 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16952 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16953 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16954 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16955 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16956 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16957 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16958 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16959 | ||
16960 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16961 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16962 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16963 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16964 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16965 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16966 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16967 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16968 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16969 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16970 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16971 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16972 | ||
16973 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16974 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16975 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16976 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16977 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16978 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16979 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16980 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16981 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16982 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16983 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16984 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16985 | ||
16986 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16987 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16988 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16989 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16990 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16991 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16992 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16993 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16994 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16995 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16996 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16997 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16998 | ||
16999 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17000 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17001 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17002 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17003 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17004 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17005 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17006 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17007 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17008 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17009 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17010 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17011 | ||
17012 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17013 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17014 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17015 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17016 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17017 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17018 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17019 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17020 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17021 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17022 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17023 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17024 | ||
17025 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17026 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17027 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17028 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17029 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17030 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17031 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17032 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17033 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17034 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17035 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17036 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17037 | ||
17038 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17039 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17040 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17041 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17042 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17043 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17044 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17045 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17046 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17047 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17048 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17049 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17050 | ||
17051 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17052 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17053 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17054 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17055 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17056 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17057 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17058 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17059 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17060 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17061 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
17062 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
17063 | |
17064 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 17065 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 17066 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
17067 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
17068 | ||
e3cb604e PB |
17069 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
17070 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
17071 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
17072 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
17073 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
17074 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
17075 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
17076 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
17077 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
17078 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
17079 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
17080 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 17081 | |
c19d1205 ZW |
17082 | /* The implementation of the FIX instruction is broken on some |
17083 | assemblers, in that it accepts a precision specifier as well as a | |
17084 | rounding specifier, despite the fact that this is meaningless. | |
17085 | To be more compatible, we accept it as well, though of course it | |
17086 | does not set any bits. */ | |
8f06b2d8 | 17087 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
17088 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
17089 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
17090 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
17091 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
17092 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
17093 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
17094 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
17095 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
17096 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
17097 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
17098 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
17099 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 17100 | |
c19d1205 | 17101 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
17102 | #undef ARM_VARIANT |
17103 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
17104 | ||
8f06b2d8 | 17105 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
17106 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
17107 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 17108 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
17109 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
17110 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 17111 | |
c921be7d NC |
17112 | #undef ARM_VARIANT |
17113 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
17114 | ||
c19d1205 | 17115 | /* Moves and type conversions. */ |
8f06b2d8 PB |
17116 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
17117 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
17118 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
17119 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
17120 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17121 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17122 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17123 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17124 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17125 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17126 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
17127 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
17128 | |
17129 | /* Memory operations. */ | |
4962c51a MS |
17130 | cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
17131 | cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
8f06b2d8 PB |
17132 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), |
17133 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17134 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17135 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17136 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17137 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17138 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17139 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17140 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17141 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17142 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17143 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17144 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17145 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17146 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17147 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 17148 | |
c19d1205 | 17149 | /* Monadic operations. */ |
8f06b2d8 PB |
17150 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
17151 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17152 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
17153 | |
17154 | /* Dyadic operations. */ | |
8f06b2d8 PB |
17155 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
17156 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17157 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17158 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17159 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17160 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17161 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17162 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17163 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 17164 | |
c19d1205 | 17165 | /* Comparisons. */ |
8f06b2d8 PB |
17166 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
17167 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
17168 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17169 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 17170 | |
c921be7d NC |
17171 | #undef ARM_VARIANT |
17172 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
17173 | ||
c19d1205 | 17174 | /* Moves and type conversions. */ |
5287ad62 | 17175 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
8f06b2d8 PB |
17176 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
17177 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
5287ad62 JB |
17178 | cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd), |
17179 | cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17180 | cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17181 | cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
8f06b2d8 PB |
17182 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
17183 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17184 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17185 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17186 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17187 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
17188 | |
17189 | /* Memory operations. */ | |
4962c51a MS |
17190 | cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), |
17191 | cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
8f06b2d8 PB |
17192 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), |
17193 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17194 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17195 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17196 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17197 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17198 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17199 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 17200 | |
c19d1205 | 17201 | /* Monadic operations. */ |
5287ad62 JB |
17202 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
17203 | cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17204 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
17205 | |
17206 | /* Dyadic operations. */ | |
5287ad62 JB |
17207 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
17208 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17209 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17210 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17211 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17212 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17213 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17214 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17215 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 17216 | |
c19d1205 | 17217 | /* Comparisons. */ |
5287ad62 JB |
17218 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17219 | cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd), | |
17220 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17221 | cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 17222 | |
c921be7d NC |
17223 | #undef ARM_VARIANT |
17224 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
17225 | ||
8f06b2d8 PB |
17226 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
17227 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
5287ad62 JB |
17228 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), |
17229 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
17230 | ||
037e8744 JB |
17231 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
17232 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
17233 | #undef ARM_VARIANT |
17234 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
17235 | #undef THUMB_VARIANT | |
17236 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
17237 | ||
037e8744 JB |
17238 | /* These mnemonics are unique to VFP. */ |
17239 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
17240 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
17241 | nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17242 | nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17243 | nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17244 | nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17245 | nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17246 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), | |
17247 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
17248 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
17249 | ||
17250 | /* Mnemonics shared by Neon and VFP. */ | |
17251 | nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), | |
17252 | nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17253 | nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17254 | ||
17255 | nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
17256 | nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
17257 | ||
17258 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17259 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17260 | ||
17261 | NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17262 | NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17263 | NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17264 | NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17265 | NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17266 | NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
17267 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
17268 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 JB |
17269 | |
17270 | nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), | |
8e79c3df CM |
17271 | nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb), |
17272 | nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt), | |
f31fef98 | 17273 | |
037e8744 JB |
17274 | |
17275 | /* NOTE: All VMOV encoding is special-cased! */ | |
17276 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
17277 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
17278 | ||
c921be7d NC |
17279 | #undef THUMB_VARIANT |
17280 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
17281 | #undef ARM_VARIANT | |
17282 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
17283 | ||
5287ad62 JB |
17284 | /* Data processing with three registers of the same length. */ |
17285 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
17286 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
17287 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
17288 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17289 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17290 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17291 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17292 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17293 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17294 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17295 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17296 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
17297 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17298 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
17299 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
17300 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
17301 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
17302 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
17303 | /* If not immediate, fall back to neon_dyadic_i64_su. |
17304 | shl_imm should accept I8 I16 I32 I64, | |
17305 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17306 | nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), | |
17307 | nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
17308 | nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
17309 | nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
17310 | /* Logic ops, types optional & ignored. */ | |
17311 | nUF(vand, vand, 2, (RNDQ, NILO), neon_logic), | |
17312 | nUF(vandq, vand, 2, (RNQ, NILO), neon_logic), | |
17313 | nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic), | |
17314 | nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic), | |
17315 | nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic), | |
17316 | nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic), | |
17317 | nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic), | |
17318 | nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic), | |
17319 | nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
17320 | nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
17321 | /* Bitfield ops, untyped. */ | |
17322 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17323 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17324 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17325 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17326 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17327 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17328 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
17329 | nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17330 | nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17331 | nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17332 | nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17333 | nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17334 | nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17335 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall | |
17336 | back to neon_dyadic_if_su. */ | |
17337 | nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17338 | nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17339 | nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17340 | nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17341 | nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17342 | nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
17343 | nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17344 | nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 17345 | /* Comparison. Type I8 I16 I32 F32. */ |
5287ad62 JB |
17346 | nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
17347 | nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
17348 | /* As above, D registers only. */ | |
17349 | nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
17350 | nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
17351 | /* Int and float variants, signedness unimportant. */ | |
5287ad62 | 17352 | nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
5287ad62 JB |
17353 | nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
17354 | nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
17355 | /* Add/sub take types I8 I16 I32 I64 F32. */ | |
5287ad62 | 17356 | nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
5287ad62 JB |
17357 | nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
17358 | /* vtst takes sizes 8, 16, 32. */ | |
17359 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
17360 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
17361 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
037e8744 | 17362 | nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 JB |
17363 | /* VQD{R}MULH takes S16 S32. */ |
17364 | nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17365 | nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17366 | nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17367 | nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17368 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17369 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
17370 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17371 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
17372 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
17373 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
17374 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
17375 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
17376 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
17377 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17378 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
17379 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17380 | ||
17381 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 17382 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
17383 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
17384 | ||
17385 | /* Data processing with two registers and a shift amount. */ | |
17386 | /* Right shifts, and variants with rounding. | |
17387 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17388 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17389 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17390 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17391 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17392 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17393 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17394 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17395 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17396 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
17397 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
17398 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
17399 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
17400 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
17401 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17402 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
17403 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
17404 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
17405 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
17406 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17407 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17408 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
17409 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17410 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17411 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
17412 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17413 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17414 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
17415 | nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll), | |
17416 | /* CVT with optional immediate for fixed-point variant. */ | |
037e8744 | 17417 | nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 17418 | |
5287ad62 JB |
17419 | nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn), |
17420 | nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn), | |
17421 | ||
17422 | /* Data processing, three registers of different lengths. */ | |
17423 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
17424 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
17425 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17426 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17427 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17428 | /* If not scalar, fall back to neon_dyadic_long. | |
17429 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
17430 | nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
17431 | nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
17432 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ | |
17433 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17434 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17435 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
17436 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17437 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17438 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17439 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17440 | /* Saturating doubling multiplies. Types S16 S32. */ | |
17441 | nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17442 | nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17443 | nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17444 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types | |
17445 | S16 S32 U16 U32. */ | |
17446 | nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), | |
17447 | ||
17448 | /* Extract. Size 8. */ | |
3b8d421e PB |
17449 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
17450 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
17451 | |
17452 | /* Two registers, miscellaneous. */ | |
17453 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
17454 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
17455 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
17456 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
17457 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
17458 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
17459 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
17460 | /* Vector replicate. Sizes 8 16 32. */ | |
17461 | nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup), | |
17462 | nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
17463 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ | |
17464 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
17465 | /* VMOVN. Types I16 I32 I64. */ | |
17466 | nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn), | |
17467 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ | |
17468 | nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn), | |
17469 | /* VQMOVUN. Types S16 S32 S64. */ | |
17470 | nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun), | |
17471 | /* VZIP / VUZP. Sizes 8 16 32. */ | |
17472 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17473 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
17474 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17475 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
17476 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
17477 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17478 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17479 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17480 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17481 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
17482 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
17483 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
17484 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
17485 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
17486 | /* Reciprocal estimates. Types U32 F32. */ | |
17487 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
17488 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
17489 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
17490 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
17491 | /* VCLS. Types S8 S16 S32. */ | |
17492 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
17493 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
17494 | /* VCLZ. Types I8 I16 I32. */ | |
17495 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
17496 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
17497 | /* VCNT. Size 8. */ | |
17498 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
17499 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
17500 | /* Two address, untyped. */ | |
17501 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
17502 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
17503 | /* VTRN. Sizes 8 16 32. */ | |
17504 | nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn), | |
17505 | nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn), | |
17506 | ||
17507 | /* Table lookup. Size 8. */ | |
17508 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17509 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17510 | ||
c921be7d NC |
17511 | #undef THUMB_VARIANT |
17512 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
17513 | #undef ARM_VARIANT | |
17514 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
17515 | ||
5287ad62 JB |
17516 | /* Neon element/structure load/store. */ |
17517 | nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17518 | nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17519 | nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17520 | nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17521 | nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17522 | nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17523 | nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17524 | nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17525 | ||
c921be7d NC |
17526 | #undef THUMB_VARIANT |
17527 | #define THUMB_VARIANT & fpu_vfp_ext_v3 | |
17528 | #undef ARM_VARIANT | |
17529 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
17530 | ||
5287ad62 JB |
17531 | cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const), |
17532 | cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const), | |
17533 | cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17534 | cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17535 | cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17536 | cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17537 | cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17538 | cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17539 | cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17540 | cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17541 | cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17542 | cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17543 | cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17544 | cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17545 | cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17546 | cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17547 | cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17548 | cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
c19d1205 | 17549 | |
5287ad62 | 17550 | #undef THUMB_VARIANT |
c921be7d NC |
17551 | #undef ARM_VARIANT |
17552 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
17553 | ||
8f06b2d8 PB |
17554 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
17555 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17556 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17557 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17558 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17559 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17560 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
17561 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 17562 | |
c921be7d NC |
17563 | #undef ARM_VARIANT |
17564 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
17565 | ||
8f06b2d8 PB |
17566 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
17567 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
17568 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
17569 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
17570 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
17571 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
17572 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
17573 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
17574 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
17575 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17576 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17577 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17578 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17579 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17580 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17581 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17582 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17583 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
41adaa5c | 17584 | cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd), |
8f06b2d8 PB |
17585 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), |
17586 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17587 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17588 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17589 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17590 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17591 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17592 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
17593 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
17594 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
41adaa5c | 17595 | cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn), |
8f06b2d8 PB |
17596 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), |
17597 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
17598 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
17599 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
17600 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
17601 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
17602 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
17603 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17604 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17605 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17606 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17607 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17608 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17609 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17610 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17611 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17612 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
17613 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17614 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17615 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17616 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17617 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17618 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17619 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17620 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17621 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17622 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17623 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17624 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17625 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17626 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17627 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17628 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17629 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17630 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17631 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17632 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17633 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17634 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17635 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17636 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17637 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17638 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17639 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17640 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17641 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17642 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17643 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17644 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17645 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17646 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17647 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17648 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17649 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17650 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17651 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17652 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17653 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17654 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
17655 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17656 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17657 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17658 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17659 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17660 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17661 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17662 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17663 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17664 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17665 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 17666 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17667 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17668 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17669 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17670 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
17671 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
17672 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17673 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17674 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17675 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17676 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
2d447fca | 17677 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17678 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17679 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17680 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17681 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17682 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17683 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17684 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17685 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17686 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17687 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17688 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17689 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17690 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17691 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17692 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17693 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
17694 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
17695 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17696 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17697 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17698 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17699 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17700 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17701 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17702 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17703 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17704 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17705 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17706 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17707 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17708 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
17709 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
17710 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
17711 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
17712 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
17713 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
17714 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17715 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17716 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17717 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
17718 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
17719 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
17720 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
17721 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
17722 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
17723 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17724 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17725 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17726 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17727 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 17728 | |
c921be7d NC |
17729 | #undef ARM_VARIANT |
17730 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
17731 | ||
1103f72c NC |
17732 | cCE(torvscb, e12f190, 1, (RR), iwmmxt_tandorc), |
17733 | cCE(torvsch, e52f190, 1, (RR), iwmmxt_tandorc), | |
17734 | cCE(torvscw, e92f190, 1, (RR), iwmmxt_tandorc), | |
2d447fca JM |
17735 | cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn), |
17736 | cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn), | |
17737 | cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn), | |
17738 | cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17739 | cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17740 | cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17741 | cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17742 | cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17743 | cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17744 | cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17745 | cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17746 | cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17747 | cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17748 | cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17749 | cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17750 | cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17751 | cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17752 | cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
17753 | cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17754 | cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17755 | cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17756 | cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17757 | cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17758 | cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17759 | cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17760 | cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17761 | cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17762 | cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17763 | cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17764 | cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17765 | cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17766 | cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17767 | cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17768 | cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17769 | cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17770 | cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17771 | cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17772 | cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17773 | cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17774 | cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17775 | cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17776 | cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17777 | cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17778 | cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17779 | cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17780 | cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17781 | cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17782 | cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17783 | cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17784 | cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17785 | cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17786 | cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17787 | cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17788 | cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17789 | ||
c921be7d NC |
17790 | #undef ARM_VARIANT |
17791 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
17792 | ||
4962c51a MS |
17793 | cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
17794 | cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17795 | cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17796 | cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
17797 | cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
17798 | cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17799 | cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17800 | cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
8f06b2d8 PB |
17801 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), |
17802 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
17803 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
17804 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
17805 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
17806 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
17807 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
17808 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
17809 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
17810 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
17811 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
17812 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
17813 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
17814 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
17815 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
17816 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
17817 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
17818 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
17819 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
17820 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
17821 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
17822 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
17823 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
17824 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
17825 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
17826 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
17827 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
17828 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
17829 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
17830 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
17831 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
17832 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
17833 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
17834 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
17835 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
17836 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
17837 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
17838 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
17839 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
17840 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
17841 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
17842 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
17843 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
17844 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
17845 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
17846 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
17847 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17848 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17849 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17850 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17851 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17852 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17853 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
17854 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
17855 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
17856 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
17857 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17858 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17859 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17860 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17861 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17862 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17863 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17864 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17865 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17866 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17867 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
17868 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
17869 | }; |
17870 | #undef ARM_VARIANT | |
17871 | #undef THUMB_VARIANT | |
17872 | #undef TCE | |
17873 | #undef TCM | |
17874 | #undef TUE | |
17875 | #undef TUF | |
17876 | #undef TCC | |
8f06b2d8 | 17877 | #undef cCE |
e3cb604e PB |
17878 | #undef cCL |
17879 | #undef C3E | |
c19d1205 ZW |
17880 | #undef CE |
17881 | #undef CM | |
17882 | #undef UE | |
17883 | #undef UF | |
17884 | #undef UT | |
5287ad62 JB |
17885 | #undef NUF |
17886 | #undef nUF | |
17887 | #undef NCE | |
17888 | #undef nCE | |
c19d1205 ZW |
17889 | #undef OPS0 |
17890 | #undef OPS1 | |
17891 | #undef OPS2 | |
17892 | #undef OPS3 | |
17893 | #undef OPS4 | |
17894 | #undef OPS5 | |
17895 | #undef OPS6 | |
17896 | #undef do_0 | |
17897 | \f | |
17898 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 17899 | |
c19d1205 ZW |
17900 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
17901 | for use in the a.out file, and stores them in the array pointed to by buf. | |
17902 | This knows about the endian-ness of the target machine and does | |
17903 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
17904 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
17905 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 17906 | |
c19d1205 ZW |
17907 | void |
17908 | md_number_to_chars (char * buf, valueT val, int n) | |
17909 | { | |
17910 | if (target_big_endian) | |
17911 | number_to_chars_bigendian (buf, val, n); | |
17912 | else | |
17913 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
17914 | } |
17915 | ||
c19d1205 ZW |
17916 | static valueT |
17917 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 17918 | { |
c19d1205 ZW |
17919 | valueT result = 0; |
17920 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 17921 | |
c19d1205 | 17922 | if (target_big_endian) |
b99bd4ef | 17923 | { |
c19d1205 ZW |
17924 | while (n--) |
17925 | { | |
17926 | result <<= 8; | |
17927 | result |= (*where++ & 255); | |
17928 | } | |
b99bd4ef | 17929 | } |
c19d1205 | 17930 | else |
b99bd4ef | 17931 | { |
c19d1205 ZW |
17932 | while (n--) |
17933 | { | |
17934 | result <<= 8; | |
17935 | result |= (where[n] & 255); | |
17936 | } | |
bfae80f2 | 17937 | } |
b99bd4ef | 17938 | |
c19d1205 | 17939 | return result; |
bfae80f2 | 17940 | } |
b99bd4ef | 17941 | |
c19d1205 | 17942 | /* MD interface: Sections. */ |
b99bd4ef | 17943 | |
0110f2b8 PB |
17944 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
17945 | 2 bytes. */ | |
17946 | ||
c19d1205 | 17947 | int |
0110f2b8 | 17948 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
17949 | segT segtype ATTRIBUTE_UNUSED) |
17950 | { | |
0110f2b8 PB |
17951 | fragp->fr_var = 2; |
17952 | return 2; | |
17953 | } | |
17954 | ||
17955 | /* Convert a machine dependent frag. */ | |
17956 | ||
17957 | void | |
17958 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
17959 | { | |
17960 | unsigned long insn; | |
17961 | unsigned long old_op; | |
17962 | char *buf; | |
17963 | expressionS exp; | |
17964 | fixS *fixp; | |
17965 | int reloc_type; | |
17966 | int pc_rel; | |
17967 | int opcode; | |
17968 | ||
17969 | buf = fragp->fr_literal + fragp->fr_fix; | |
17970 | ||
17971 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
17972 | if (fragp->fr_symbol) |
17973 | { | |
0110f2b8 PB |
17974 | exp.X_op = O_symbol; |
17975 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
17976 | } |
17977 | else | |
17978 | { | |
0110f2b8 | 17979 | exp.X_op = O_constant; |
5f4273c7 | 17980 | } |
0110f2b8 PB |
17981 | exp.X_add_number = fragp->fr_offset; |
17982 | opcode = fragp->fr_subtype; | |
17983 | switch (opcode) | |
17984 | { | |
17985 | case T_MNEM_ldr_pc: | |
17986 | case T_MNEM_ldr_pc2: | |
17987 | case T_MNEM_ldr_sp: | |
17988 | case T_MNEM_str_sp: | |
17989 | case T_MNEM_ldr: | |
17990 | case T_MNEM_ldrb: | |
17991 | case T_MNEM_ldrh: | |
17992 | case T_MNEM_str: | |
17993 | case T_MNEM_strb: | |
17994 | case T_MNEM_strh: | |
17995 | if (fragp->fr_var == 4) | |
17996 | { | |
5f4273c7 | 17997 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
17998 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
17999 | { | |
18000 | insn |= (old_op & 0x700) << 4; | |
18001 | } | |
18002 | else | |
18003 | { | |
18004 | insn |= (old_op & 7) << 12; | |
18005 | insn |= (old_op & 0x38) << 13; | |
18006 | } | |
18007 | insn |= 0x00000c00; | |
18008 | put_thumb32_insn (buf, insn); | |
18009 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
18010 | } | |
18011 | else | |
18012 | { | |
18013 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
18014 | } | |
18015 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
18016 | break; | |
18017 | case T_MNEM_adr: | |
18018 | if (fragp->fr_var == 4) | |
18019 | { | |
18020 | insn = THUMB_OP32 (opcode); | |
18021 | insn |= (old_op & 0xf0) << 4; | |
18022 | put_thumb32_insn (buf, insn); | |
18023 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
18024 | } | |
18025 | else | |
18026 | { | |
18027 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18028 | exp.X_add_number -= 4; | |
18029 | } | |
18030 | pc_rel = 1; | |
18031 | break; | |
18032 | case T_MNEM_mov: | |
18033 | case T_MNEM_movs: | |
18034 | case T_MNEM_cmp: | |
18035 | case T_MNEM_cmn: | |
18036 | if (fragp->fr_var == 4) | |
18037 | { | |
18038 | int r0off = (opcode == T_MNEM_mov | |
18039 | || opcode == T_MNEM_movs) ? 0 : 8; | |
18040 | insn = THUMB_OP32 (opcode); | |
18041 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
18042 | insn |= (old_op & 0x700) << r0off; | |
18043 | put_thumb32_insn (buf, insn); | |
18044 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
18045 | } | |
18046 | else | |
18047 | { | |
18048 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
18049 | } | |
18050 | pc_rel = 0; | |
18051 | break; | |
18052 | case T_MNEM_b: | |
18053 | if (fragp->fr_var == 4) | |
18054 | { | |
18055 | insn = THUMB_OP32(opcode); | |
18056 | put_thumb32_insn (buf, insn); | |
18057 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
18058 | } | |
18059 | else | |
18060 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
18061 | pc_rel = 1; | |
18062 | break; | |
18063 | case T_MNEM_bcond: | |
18064 | if (fragp->fr_var == 4) | |
18065 | { | |
18066 | insn = THUMB_OP32(opcode); | |
18067 | insn |= (old_op & 0xf00) << 14; | |
18068 | put_thumb32_insn (buf, insn); | |
18069 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
18070 | } | |
18071 | else | |
18072 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
18073 | pc_rel = 1; | |
18074 | break; | |
18075 | case T_MNEM_add_sp: | |
18076 | case T_MNEM_add_pc: | |
18077 | case T_MNEM_inc_sp: | |
18078 | case T_MNEM_dec_sp: | |
18079 | if (fragp->fr_var == 4) | |
18080 | { | |
18081 | /* ??? Choose between add and addw. */ | |
18082 | insn = THUMB_OP32 (opcode); | |
18083 | insn |= (old_op & 0xf0) << 4; | |
18084 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18085 | if (opcode == T_MNEM_add_pc) |
18086 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
18087 | else | |
18088 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
18089 | } |
18090 | else | |
18091 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18092 | pc_rel = 0; | |
18093 | break; | |
18094 | ||
18095 | case T_MNEM_addi: | |
18096 | case T_MNEM_addis: | |
18097 | case T_MNEM_subi: | |
18098 | case T_MNEM_subis: | |
18099 | if (fragp->fr_var == 4) | |
18100 | { | |
18101 | insn = THUMB_OP32 (opcode); | |
18102 | insn |= (old_op & 0xf0) << 4; | |
18103 | insn |= (old_op & 0xf) << 16; | |
18104 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18105 | if (insn & (1 << 20)) |
18106 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
18107 | else | |
18108 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
18109 | } |
18110 | else | |
18111 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18112 | pc_rel = 0; | |
18113 | break; | |
18114 | default: | |
5f4273c7 | 18115 | abort (); |
0110f2b8 PB |
18116 | } |
18117 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
18118 | reloc_type); | |
18119 | fixp->fx_file = fragp->fr_file; | |
18120 | fixp->fx_line = fragp->fr_line; | |
18121 | fragp->fr_fix += fragp->fr_var; | |
18122 | } | |
18123 | ||
18124 | /* Return the size of a relaxable immediate operand instruction. | |
18125 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
18126 | static int | |
18127 | relax_immediate (fragS *fragp, int size, int shift) | |
18128 | { | |
18129 | offsetT offset; | |
18130 | offsetT mask; | |
18131 | offsetT low; | |
18132 | ||
18133 | /* ??? Should be able to do better than this. */ | |
18134 | if (fragp->fr_symbol) | |
18135 | return 4; | |
18136 | ||
18137 | low = (1 << shift) - 1; | |
18138 | mask = (1 << (shift + size)) - (1 << shift); | |
18139 | offset = fragp->fr_offset; | |
18140 | /* Force misaligned offsets to 32-bit variant. */ | |
18141 | if (offset & low) | |
5e77afaa | 18142 | return 4; |
0110f2b8 PB |
18143 | if (offset & ~mask) |
18144 | return 4; | |
18145 | return 2; | |
18146 | } | |
18147 | ||
5e77afaa PB |
18148 | /* Get the address of a symbol during relaxation. */ |
18149 | static addressT | |
5f4273c7 | 18150 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
18151 | { |
18152 | fragS *sym_frag; | |
18153 | addressT addr; | |
18154 | symbolS *sym; | |
18155 | ||
18156 | sym = fragp->fr_symbol; | |
18157 | sym_frag = symbol_get_frag (sym); | |
18158 | know (S_GET_SEGMENT (sym) != absolute_section | |
18159 | || sym_frag == &zero_address_frag); | |
18160 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
18161 | ||
18162 | /* If frag has yet to be reached on this pass, assume it will | |
18163 | move by STRETCH just as we did. If this is not so, it will | |
18164 | be because some frag between grows, and that will force | |
18165 | another pass. */ | |
18166 | ||
18167 | if (stretch != 0 | |
18168 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
18169 | { |
18170 | fragS *f; | |
18171 | ||
18172 | /* Adjust stretch for any alignment frag. Note that if have | |
18173 | been expanding the earlier code, the symbol may be | |
18174 | defined in what appears to be an earlier frag. FIXME: | |
18175 | This doesn't handle the fr_subtype field, which specifies | |
18176 | a maximum number of bytes to skip when doing an | |
18177 | alignment. */ | |
18178 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
18179 | { | |
18180 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
18181 | { | |
18182 | if (stretch < 0) | |
18183 | stretch = - ((- stretch) | |
18184 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
18185 | else | |
18186 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
18187 | if (stretch == 0) | |
18188 | break; | |
18189 | } | |
18190 | } | |
18191 | if (f != NULL) | |
18192 | addr += stretch; | |
18193 | } | |
5e77afaa PB |
18194 | |
18195 | return addr; | |
18196 | } | |
18197 | ||
0110f2b8 PB |
18198 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
18199 | load. */ | |
18200 | static int | |
5e77afaa | 18201 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
18202 | { |
18203 | addressT addr; | |
18204 | offsetT val; | |
18205 | ||
18206 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18207 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18208 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18209 | return 4; | |
18210 | ||
5f4273c7 | 18211 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18212 | addr = fragp->fr_address + fragp->fr_fix; |
18213 | addr = (addr + 4) & ~3; | |
5e77afaa | 18214 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 18215 | if (val & 3) |
5e77afaa | 18216 | return 4; |
0110f2b8 PB |
18217 | val -= addr; |
18218 | if (val < 0 || val > 1020) | |
18219 | return 4; | |
18220 | return 2; | |
18221 | } | |
18222 | ||
18223 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
18224 | static int | |
18225 | relax_addsub (fragS *fragp, asection *sec) | |
18226 | { | |
18227 | char *buf; | |
18228 | int op; | |
18229 | ||
18230 | buf = fragp->fr_literal + fragp->fr_fix; | |
18231 | op = bfd_get_16(sec->owner, buf); | |
18232 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
18233 | return relax_immediate (fragp, 8, 0); | |
18234 | else | |
18235 | return relax_immediate (fragp, 3, 0); | |
18236 | } | |
18237 | ||
18238 | ||
18239 | /* Return the size of a relaxable branch instruction. BITS is the | |
18240 | size of the offset field in the narrow instruction. */ | |
18241 | ||
18242 | static int | |
5e77afaa | 18243 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
18244 | { |
18245 | addressT addr; | |
18246 | offsetT val; | |
18247 | offsetT limit; | |
18248 | ||
18249 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18250 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18251 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18252 | return 4; | |
18253 | ||
267bf995 RR |
18254 | #ifdef OBJ_ELF |
18255 | if (S_IS_DEFINED (fragp->fr_symbol) | |
18256 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
18257 | return 4; | |
18258 | #endif | |
18259 | ||
5f4273c7 | 18260 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18261 | addr = fragp->fr_address + fragp->fr_fix + 4; |
18262 | val -= addr; | |
18263 | ||
18264 | /* Offset is a signed value *2 */ | |
18265 | limit = 1 << bits; | |
18266 | if (val >= limit || val < -limit) | |
18267 | return 4; | |
18268 | return 2; | |
18269 | } | |
18270 | ||
18271 | ||
18272 | /* Relax a machine dependent frag. This returns the amount by which | |
18273 | the current size of the frag should change. */ | |
18274 | ||
18275 | int | |
5e77afaa | 18276 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
18277 | { |
18278 | int oldsize; | |
18279 | int newsize; | |
18280 | ||
18281 | oldsize = fragp->fr_var; | |
18282 | switch (fragp->fr_subtype) | |
18283 | { | |
18284 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 18285 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18286 | break; |
18287 | case T_MNEM_ldr_pc: | |
18288 | case T_MNEM_ldr_sp: | |
18289 | case T_MNEM_str_sp: | |
5f4273c7 | 18290 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
18291 | break; |
18292 | case T_MNEM_ldr: | |
18293 | case T_MNEM_str: | |
5f4273c7 | 18294 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
18295 | break; |
18296 | case T_MNEM_ldrh: | |
18297 | case T_MNEM_strh: | |
5f4273c7 | 18298 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
18299 | break; |
18300 | case T_MNEM_ldrb: | |
18301 | case T_MNEM_strb: | |
5f4273c7 | 18302 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
18303 | break; |
18304 | case T_MNEM_adr: | |
5f4273c7 | 18305 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18306 | break; |
18307 | case T_MNEM_mov: | |
18308 | case T_MNEM_movs: | |
18309 | case T_MNEM_cmp: | |
18310 | case T_MNEM_cmn: | |
5f4273c7 | 18311 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
18312 | break; |
18313 | case T_MNEM_b: | |
5f4273c7 | 18314 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
18315 | break; |
18316 | case T_MNEM_bcond: | |
5f4273c7 | 18317 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
18318 | break; |
18319 | case T_MNEM_add_sp: | |
18320 | case T_MNEM_add_pc: | |
18321 | newsize = relax_immediate (fragp, 8, 2); | |
18322 | break; | |
18323 | case T_MNEM_inc_sp: | |
18324 | case T_MNEM_dec_sp: | |
18325 | newsize = relax_immediate (fragp, 7, 2); | |
18326 | break; | |
18327 | case T_MNEM_addi: | |
18328 | case T_MNEM_addis: | |
18329 | case T_MNEM_subi: | |
18330 | case T_MNEM_subis: | |
18331 | newsize = relax_addsub (fragp, sec); | |
18332 | break; | |
18333 | default: | |
5f4273c7 | 18334 | abort (); |
0110f2b8 | 18335 | } |
5e77afaa PB |
18336 | |
18337 | fragp->fr_var = newsize; | |
18338 | /* Freeze wide instructions that are at or before the same location as | |
18339 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
18340 | Don't freeze them unconditionally because targets may be artificially |
18341 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 18342 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 18343 | { |
0110f2b8 | 18344 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 18345 | frag_wane (fragp); |
0110f2b8 | 18346 | } |
5e77afaa | 18347 | |
0110f2b8 | 18348 | return newsize - oldsize; |
c19d1205 | 18349 | } |
b99bd4ef | 18350 | |
c19d1205 | 18351 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 18352 | |
c19d1205 ZW |
18353 | valueT |
18354 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
18355 | valueT size) | |
18356 | { | |
f0927246 NC |
18357 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
18358 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
18359 | { | |
18360 | /* For a.out, force the section size to be aligned. If we don't do | |
18361 | this, BFD will align it for us, but it will not write out the | |
18362 | final bytes of the section. This may be a bug in BFD, but it is | |
18363 | easier to fix it here since that is how the other a.out targets | |
18364 | work. */ | |
18365 | int align; | |
18366 | ||
18367 | align = bfd_get_section_alignment (stdoutput, segment); | |
18368 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
18369 | } | |
c19d1205 | 18370 | #endif |
f0927246 NC |
18371 | |
18372 | return size; | |
bfae80f2 | 18373 | } |
b99bd4ef | 18374 | |
c19d1205 ZW |
18375 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
18376 | of an rs_align_code fragment. */ | |
18377 | ||
18378 | void | |
18379 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 18380 | { |
e7495e45 NS |
18381 | static char const arm_noop[2][2][4] = |
18382 | { | |
18383 | { /* ARMv1 */ | |
18384 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
18385 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
18386 | }, | |
18387 | { /* ARMv6k */ | |
18388 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
18389 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
18390 | }, | |
18391 | }; | |
18392 | static char const thumb_noop[2][2][2] = | |
18393 | { | |
18394 | { /* Thumb-1 */ | |
18395 | {0xc0, 0x46}, /* LE */ | |
18396 | {0x46, 0xc0}, /* BE */ | |
18397 | }, | |
18398 | { /* Thumb-2 */ | |
18399 | {0x00, 0xbf}, /* LE */ | |
18400 | {0xbf, 0x00} /* BE */ | |
18401 | } | |
18402 | }; | |
18403 | static char const wide_thumb_noop[2][4] = | |
18404 | { /* Wide Thumb-2 */ | |
18405 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
18406 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
18407 | }; | |
c921be7d | 18408 | |
e7495e45 | 18409 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
18410 | char * p; |
18411 | const char * noop; | |
e7495e45 | 18412 | const char *narrow_noop = NULL; |
cd000bff DJ |
18413 | #ifdef OBJ_ELF |
18414 | enum mstate state; | |
18415 | #endif | |
bfae80f2 | 18416 | |
c19d1205 | 18417 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
18418 | return; |
18419 | ||
c19d1205 ZW |
18420 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
18421 | p = fragP->fr_literal + fragP->fr_fix; | |
18422 | fix = 0; | |
bfae80f2 | 18423 | |
c19d1205 ZW |
18424 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
18425 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 18426 | |
539d4391 | 18427 | #ifdef OBJ_ELF |
cd000bff | 18428 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
539d4391 | 18429 | #endif |
8dc2430f | 18430 | |
cd000bff | 18431 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 18432 | { |
e7495e45 NS |
18433 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
18434 | { | |
18435 | narrow_noop = thumb_noop[1][target_big_endian]; | |
18436 | noop = wide_thumb_noop[target_big_endian]; | |
18437 | } | |
c19d1205 | 18438 | else |
e7495e45 NS |
18439 | noop = thumb_noop[0][target_big_endian]; |
18440 | noop_size = 2; | |
cd000bff DJ |
18441 | #ifdef OBJ_ELF |
18442 | state = MAP_THUMB; | |
18443 | #endif | |
7ed4c4c5 NC |
18444 | } |
18445 | else | |
18446 | { | |
e7495e45 NS |
18447 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0] |
18448 | [target_big_endian]; | |
18449 | noop_size = 4; | |
cd000bff DJ |
18450 | #ifdef OBJ_ELF |
18451 | state = MAP_ARM; | |
18452 | #endif | |
7ed4c4c5 | 18453 | } |
c921be7d | 18454 | |
e7495e45 | 18455 | fragP->fr_var = noop_size; |
c921be7d | 18456 | |
c19d1205 | 18457 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 18458 | { |
c19d1205 | 18459 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
18460 | #ifdef OBJ_ELF |
18461 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
18462 | #endif | |
c19d1205 ZW |
18463 | memset (p, 0, fix); |
18464 | p += fix; | |
18465 | bytes -= fix; | |
a737bd4d | 18466 | } |
a737bd4d | 18467 | |
e7495e45 NS |
18468 | if (narrow_noop) |
18469 | { | |
18470 | if (bytes & noop_size) | |
18471 | { | |
18472 | /* Insert a narrow noop. */ | |
18473 | memcpy (p, narrow_noop, noop_size); | |
18474 | p += noop_size; | |
18475 | bytes -= noop_size; | |
18476 | fix += noop_size; | |
18477 | } | |
18478 | ||
18479 | /* Use wide noops for the remainder */ | |
18480 | noop_size = 4; | |
18481 | } | |
18482 | ||
c19d1205 | 18483 | while (bytes >= noop_size) |
a737bd4d | 18484 | { |
c19d1205 ZW |
18485 | memcpy (p, noop, noop_size); |
18486 | p += noop_size; | |
18487 | bytes -= noop_size; | |
18488 | fix += noop_size; | |
a737bd4d NC |
18489 | } |
18490 | ||
c19d1205 | 18491 | fragP->fr_fix += fix; |
a737bd4d NC |
18492 | } |
18493 | ||
c19d1205 ZW |
18494 | /* Called from md_do_align. Used to create an alignment |
18495 | frag in a code section. */ | |
18496 | ||
18497 | void | |
18498 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 18499 | { |
c19d1205 | 18500 | char * p; |
7ed4c4c5 | 18501 | |
c19d1205 | 18502 | /* We assume that there will never be a requirement |
6ec8e702 | 18503 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 18504 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
18505 | { |
18506 | char err_msg[128]; | |
18507 | ||
18508 | sprintf (err_msg, | |
18509 | _("alignments greater than %d bytes not supported in .text sections."), | |
18510 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 18511 | as_fatal ("%s", err_msg); |
6ec8e702 | 18512 | } |
bfae80f2 | 18513 | |
c19d1205 ZW |
18514 | p = frag_var (rs_align_code, |
18515 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
18516 | 1, | |
18517 | (relax_substateT) max, | |
18518 | (symbolS *) NULL, | |
18519 | (offsetT) n, | |
18520 | (char *) NULL); | |
18521 | *p = 0; | |
18522 | } | |
bfae80f2 | 18523 | |
8dc2430f NC |
18524 | /* Perform target specific initialisation of a frag. |
18525 | Note - despite the name this initialisation is not done when the frag | |
18526 | is created, but only when its type is assigned. A frag can be created | |
18527 | and used a long time before its type is set, so beware of assuming that | |
18528 | this initialisationis performed first. */ | |
bfae80f2 | 18529 | |
cd000bff DJ |
18530 | #ifndef OBJ_ELF |
18531 | void | |
18532 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
18533 | { | |
18534 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
18535 | fragP->tc_frag_data.thumb_mode = thumb_mode; | |
18536 | } | |
18537 | ||
18538 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 18539 | void |
cd000bff | 18540 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 18541 | { |
8dc2430f NC |
18542 | /* If the current ARM vs THUMB mode has not already |
18543 | been recorded into this frag then do so now. */ | |
cd000bff DJ |
18544 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
18545 | { | |
18546 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; | |
18547 | ||
18548 | /* Record a mapping symbol for alignment frags. We will delete this | |
18549 | later if the alignment ends up empty. */ | |
18550 | switch (fragP->fr_type) | |
18551 | { | |
18552 | case rs_align: | |
18553 | case rs_align_test: | |
18554 | case rs_fill: | |
18555 | mapping_state_2 (MAP_DATA, max_chars); | |
18556 | break; | |
18557 | case rs_align_code: | |
18558 | mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); | |
18559 | break; | |
18560 | default: | |
18561 | break; | |
18562 | } | |
18563 | } | |
bfae80f2 RE |
18564 | } |
18565 | ||
c19d1205 ZW |
18566 | /* When we change sections we need to issue a new mapping symbol. */ |
18567 | ||
18568 | void | |
18569 | arm_elf_change_section (void) | |
bfae80f2 | 18570 | { |
c19d1205 ZW |
18571 | /* Link an unlinked unwind index table section to the .text section. */ |
18572 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
18573 | && elf_linked_to_section (now_seg) == NULL) | |
18574 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
18575 | } |
18576 | ||
c19d1205 ZW |
18577 | int |
18578 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 18579 | { |
c19d1205 ZW |
18580 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
18581 | return SHT_ARM_EXIDX; | |
e45d0630 | 18582 | |
c19d1205 ZW |
18583 | return -1; |
18584 | } | |
18585 | \f | |
18586 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 18587 | |
c19d1205 | 18588 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 18589 | |
5f4273c7 | 18590 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 18591 | |
bfae80f2 | 18592 | static void |
c19d1205 | 18593 | flush_pending_unwind (void) |
bfae80f2 | 18594 | { |
c19d1205 | 18595 | offsetT offset; |
bfae80f2 | 18596 | |
c19d1205 ZW |
18597 | offset = unwind.pending_offset; |
18598 | unwind.pending_offset = 0; | |
18599 | if (offset != 0) | |
18600 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
18601 | } |
18602 | ||
c19d1205 ZW |
18603 | /* Add an opcode to this list for this function. Two-byte opcodes should |
18604 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
18605 | order. */ | |
18606 | ||
bfae80f2 | 18607 | static void |
c19d1205 | 18608 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 18609 | { |
c19d1205 ZW |
18610 | /* Add any deferred stack adjustment. */ |
18611 | if (unwind.pending_offset) | |
18612 | flush_pending_unwind (); | |
bfae80f2 | 18613 | |
c19d1205 | 18614 | unwind.sp_restored = 0; |
bfae80f2 | 18615 | |
c19d1205 | 18616 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 18617 | { |
c19d1205 ZW |
18618 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
18619 | if (unwind.opcodes) | |
18620 | unwind.opcodes = xrealloc (unwind.opcodes, | |
18621 | unwind.opcode_alloc); | |
18622 | else | |
18623 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 18624 | } |
c19d1205 | 18625 | while (length > 0) |
bfae80f2 | 18626 | { |
c19d1205 ZW |
18627 | length--; |
18628 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
18629 | op >>= 8; | |
18630 | unwind.opcode_count++; | |
bfae80f2 | 18631 | } |
bfae80f2 RE |
18632 | } |
18633 | ||
c19d1205 ZW |
18634 | /* Add unwind opcodes to adjust the stack pointer. */ |
18635 | ||
bfae80f2 | 18636 | static void |
c19d1205 | 18637 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 18638 | { |
c19d1205 | 18639 | valueT op; |
bfae80f2 | 18640 | |
c19d1205 | 18641 | if (offset > 0x200) |
bfae80f2 | 18642 | { |
c19d1205 ZW |
18643 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
18644 | char bytes[5]; | |
18645 | int n; | |
18646 | valueT o; | |
bfae80f2 | 18647 | |
c19d1205 ZW |
18648 | /* Long form: 0xb2, uleb128. */ |
18649 | /* This might not fit in a word so add the individual bytes, | |
18650 | remembering the list is built in reverse order. */ | |
18651 | o = (valueT) ((offset - 0x204) >> 2); | |
18652 | if (o == 0) | |
18653 | add_unwind_opcode (0, 1); | |
bfae80f2 | 18654 | |
c19d1205 ZW |
18655 | /* Calculate the uleb128 encoding of the offset. */ |
18656 | n = 0; | |
18657 | while (o) | |
18658 | { | |
18659 | bytes[n] = o & 0x7f; | |
18660 | o >>= 7; | |
18661 | if (o) | |
18662 | bytes[n] |= 0x80; | |
18663 | n++; | |
18664 | } | |
18665 | /* Add the insn. */ | |
18666 | for (; n; n--) | |
18667 | add_unwind_opcode (bytes[n - 1], 1); | |
18668 | add_unwind_opcode (0xb2, 1); | |
18669 | } | |
18670 | else if (offset > 0x100) | |
bfae80f2 | 18671 | { |
c19d1205 ZW |
18672 | /* Two short opcodes. */ |
18673 | add_unwind_opcode (0x3f, 1); | |
18674 | op = (offset - 0x104) >> 2; | |
18675 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18676 | } |
c19d1205 ZW |
18677 | else if (offset > 0) |
18678 | { | |
18679 | /* Short opcode. */ | |
18680 | op = (offset - 4) >> 2; | |
18681 | add_unwind_opcode (op, 1); | |
18682 | } | |
18683 | else if (offset < 0) | |
bfae80f2 | 18684 | { |
c19d1205 ZW |
18685 | offset = -offset; |
18686 | while (offset > 0x100) | |
bfae80f2 | 18687 | { |
c19d1205 ZW |
18688 | add_unwind_opcode (0x7f, 1); |
18689 | offset -= 0x100; | |
bfae80f2 | 18690 | } |
c19d1205 ZW |
18691 | op = ((offset - 4) >> 2) | 0x40; |
18692 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18693 | } |
bfae80f2 RE |
18694 | } |
18695 | ||
c19d1205 ZW |
18696 | /* Finish the list of unwind opcodes for this function. */ |
18697 | static void | |
18698 | finish_unwind_opcodes (void) | |
bfae80f2 | 18699 | { |
c19d1205 | 18700 | valueT op; |
bfae80f2 | 18701 | |
c19d1205 | 18702 | if (unwind.fp_used) |
bfae80f2 | 18703 | { |
708587a4 | 18704 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
18705 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
18706 | flush_pending_unwind (); | |
bfae80f2 | 18707 | |
c19d1205 ZW |
18708 | /* After restoring sp from the frame pointer. */ |
18709 | op = 0x90 | unwind.fp_reg; | |
18710 | add_unwind_opcode (op, 1); | |
18711 | } | |
18712 | else | |
18713 | flush_pending_unwind (); | |
bfae80f2 RE |
18714 | } |
18715 | ||
bfae80f2 | 18716 | |
c19d1205 ZW |
18717 | /* Start an exception table entry. If idx is nonzero this is an index table |
18718 | entry. */ | |
bfae80f2 RE |
18719 | |
18720 | static void | |
c19d1205 | 18721 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 18722 | { |
c19d1205 ZW |
18723 | const char * text_name; |
18724 | const char * prefix; | |
18725 | const char * prefix_once; | |
18726 | const char * group_name; | |
18727 | size_t prefix_len; | |
18728 | size_t text_len; | |
18729 | char * sec_name; | |
18730 | size_t sec_name_len; | |
18731 | int type; | |
18732 | int flags; | |
18733 | int linkonce; | |
bfae80f2 | 18734 | |
c19d1205 | 18735 | if (idx) |
bfae80f2 | 18736 | { |
c19d1205 ZW |
18737 | prefix = ELF_STRING_ARM_unwind; |
18738 | prefix_once = ELF_STRING_ARM_unwind_once; | |
18739 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 18740 | } |
c19d1205 | 18741 | else |
bfae80f2 | 18742 | { |
c19d1205 ZW |
18743 | prefix = ELF_STRING_ARM_unwind_info; |
18744 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
18745 | type = SHT_PROGBITS; | |
bfae80f2 RE |
18746 | } |
18747 | ||
c19d1205 ZW |
18748 | text_name = segment_name (text_seg); |
18749 | if (streq (text_name, ".text")) | |
18750 | text_name = ""; | |
18751 | ||
18752 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
18753 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 18754 | { |
c19d1205 ZW |
18755 | prefix = prefix_once; |
18756 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
18757 | } |
18758 | ||
c19d1205 ZW |
18759 | prefix_len = strlen (prefix); |
18760 | text_len = strlen (text_name); | |
18761 | sec_name_len = prefix_len + text_len; | |
18762 | sec_name = xmalloc (sec_name_len + 1); | |
18763 | memcpy (sec_name, prefix, prefix_len); | |
18764 | memcpy (sec_name + prefix_len, text_name, text_len); | |
18765 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 18766 | |
c19d1205 ZW |
18767 | flags = SHF_ALLOC; |
18768 | linkonce = 0; | |
18769 | group_name = 0; | |
bfae80f2 | 18770 | |
c19d1205 ZW |
18771 | /* Handle COMDAT group. */ |
18772 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 18773 | { |
c19d1205 ZW |
18774 | group_name = elf_group_name (text_seg); |
18775 | if (group_name == NULL) | |
18776 | { | |
bd3ba5d1 | 18777 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
18778 | segment_name (text_seg)); |
18779 | ignore_rest_of_line (); | |
18780 | return; | |
18781 | } | |
18782 | flags |= SHF_GROUP; | |
18783 | linkonce = 1; | |
bfae80f2 RE |
18784 | } |
18785 | ||
c19d1205 | 18786 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 18787 | |
5f4273c7 | 18788 | /* Set the section link for index tables. */ |
c19d1205 ZW |
18789 | if (idx) |
18790 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
18791 | } |
18792 | ||
bfae80f2 | 18793 | |
c19d1205 ZW |
18794 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
18795 | personality routine data. Returns zero, or the index table value for | |
18796 | and inline entry. */ | |
18797 | ||
18798 | static valueT | |
18799 | create_unwind_entry (int have_data) | |
bfae80f2 | 18800 | { |
c19d1205 ZW |
18801 | int size; |
18802 | addressT where; | |
18803 | char *ptr; | |
18804 | /* The current word of data. */ | |
18805 | valueT data; | |
18806 | /* The number of bytes left in this word. */ | |
18807 | int n; | |
bfae80f2 | 18808 | |
c19d1205 | 18809 | finish_unwind_opcodes (); |
bfae80f2 | 18810 | |
c19d1205 ZW |
18811 | /* Remember the current text section. */ |
18812 | unwind.saved_seg = now_seg; | |
18813 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 18814 | |
c19d1205 | 18815 | start_unwind_section (now_seg, 0); |
bfae80f2 | 18816 | |
c19d1205 | 18817 | if (unwind.personality_routine == NULL) |
bfae80f2 | 18818 | { |
c19d1205 ZW |
18819 | if (unwind.personality_index == -2) |
18820 | { | |
18821 | if (have_data) | |
5f4273c7 | 18822 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
18823 | return 1; /* EXIDX_CANTUNWIND. */ |
18824 | } | |
bfae80f2 | 18825 | |
c19d1205 ZW |
18826 | /* Use a default personality routine if none is specified. */ |
18827 | if (unwind.personality_index == -1) | |
18828 | { | |
18829 | if (unwind.opcode_count > 3) | |
18830 | unwind.personality_index = 1; | |
18831 | else | |
18832 | unwind.personality_index = 0; | |
18833 | } | |
bfae80f2 | 18834 | |
c19d1205 ZW |
18835 | /* Space for the personality routine entry. */ |
18836 | if (unwind.personality_index == 0) | |
18837 | { | |
18838 | if (unwind.opcode_count > 3) | |
18839 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 18840 | |
c19d1205 ZW |
18841 | if (!have_data) |
18842 | { | |
18843 | /* All the data is inline in the index table. */ | |
18844 | data = 0x80; | |
18845 | n = 3; | |
18846 | while (unwind.opcode_count > 0) | |
18847 | { | |
18848 | unwind.opcode_count--; | |
18849 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18850 | n--; | |
18851 | } | |
bfae80f2 | 18852 | |
c19d1205 ZW |
18853 | /* Pad with "finish" opcodes. */ |
18854 | while (n--) | |
18855 | data = (data << 8) | 0xb0; | |
bfae80f2 | 18856 | |
c19d1205 ZW |
18857 | return data; |
18858 | } | |
18859 | size = 0; | |
18860 | } | |
18861 | else | |
18862 | /* We get two opcodes "free" in the first word. */ | |
18863 | size = unwind.opcode_count - 2; | |
18864 | } | |
18865 | else | |
18866 | /* An extra byte is required for the opcode count. */ | |
18867 | size = unwind.opcode_count + 1; | |
bfae80f2 | 18868 | |
c19d1205 ZW |
18869 | size = (size + 3) >> 2; |
18870 | if (size > 0xff) | |
18871 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 18872 | |
c19d1205 ZW |
18873 | frag_align (2, 0, 0); |
18874 | record_alignment (now_seg, 2); | |
18875 | unwind.table_entry = expr_build_dot (); | |
18876 | ||
18877 | /* Allocate the table entry. */ | |
18878 | ptr = frag_more ((size << 2) + 4); | |
18879 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 18880 | |
c19d1205 | 18881 | switch (unwind.personality_index) |
bfae80f2 | 18882 | { |
c19d1205 ZW |
18883 | case -1: |
18884 | /* ??? Should this be a PLT generating relocation? */ | |
18885 | /* Custom personality routine. */ | |
18886 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
18887 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 18888 | |
c19d1205 ZW |
18889 | where += 4; |
18890 | ptr += 4; | |
bfae80f2 | 18891 | |
c19d1205 ZW |
18892 | /* Set the first byte to the number of additional words. */ |
18893 | data = size - 1; | |
18894 | n = 3; | |
18895 | break; | |
bfae80f2 | 18896 | |
c19d1205 ZW |
18897 | /* ABI defined personality routines. */ |
18898 | case 0: | |
18899 | /* Three opcodes bytes are packed into the first word. */ | |
18900 | data = 0x80; | |
18901 | n = 3; | |
18902 | break; | |
bfae80f2 | 18903 | |
c19d1205 ZW |
18904 | case 1: |
18905 | case 2: | |
18906 | /* The size and first two opcode bytes go in the first word. */ | |
18907 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
18908 | n = 2; | |
18909 | break; | |
bfae80f2 | 18910 | |
c19d1205 ZW |
18911 | default: |
18912 | /* Should never happen. */ | |
18913 | abort (); | |
18914 | } | |
bfae80f2 | 18915 | |
c19d1205 ZW |
18916 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
18917 | time. */ | |
18918 | while (unwind.opcode_count > 0) | |
18919 | { | |
18920 | if (n == 0) | |
18921 | { | |
18922 | md_number_to_chars (ptr, data, 4); | |
18923 | ptr += 4; | |
18924 | n = 4; | |
18925 | data = 0; | |
18926 | } | |
18927 | unwind.opcode_count--; | |
18928 | n--; | |
18929 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18930 | } | |
18931 | ||
18932 | /* Finish off the last word. */ | |
18933 | if (n < 4) | |
18934 | { | |
18935 | /* Pad with "finish" opcodes. */ | |
18936 | while (n--) | |
18937 | data = (data << 8) | 0xb0; | |
18938 | ||
18939 | md_number_to_chars (ptr, data, 4); | |
18940 | } | |
18941 | ||
18942 | if (!have_data) | |
18943 | { | |
18944 | /* Add an empty descriptor if there is no user-specified data. */ | |
18945 | ptr = frag_more (4); | |
18946 | md_number_to_chars (ptr, 0, 4); | |
18947 | } | |
18948 | ||
18949 | return 0; | |
bfae80f2 RE |
18950 | } |
18951 | ||
f0927246 NC |
18952 | |
18953 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
18954 | ||
18955 | void | |
18956 | tc_arm_frame_initial_instructions (void) | |
18957 | { | |
18958 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
18959 | } | |
18960 | #endif /* OBJ_ELF */ | |
18961 | ||
c19d1205 ZW |
18962 | /* Convert REGNAME to a DWARF-2 register number. */ |
18963 | ||
18964 | int | |
1df69f4f | 18965 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 18966 | { |
1df69f4f | 18967 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
18968 | |
18969 | if (reg == FAIL) | |
18970 | return -1; | |
18971 | ||
18972 | return reg; | |
bfae80f2 RE |
18973 | } |
18974 | ||
f0927246 | 18975 | #ifdef TE_PE |
c19d1205 | 18976 | void |
f0927246 | 18977 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 18978 | { |
f0927246 | 18979 | expressionS expr; |
bfae80f2 | 18980 | |
f0927246 NC |
18981 | expr.X_op = O_secrel; |
18982 | expr.X_add_symbol = symbol; | |
18983 | expr.X_add_number = 0; | |
18984 | emit_expr (&expr, size); | |
18985 | } | |
18986 | #endif | |
bfae80f2 | 18987 | |
c19d1205 | 18988 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 18989 | |
2fc8bdac ZW |
18990 | /* Return the address within the segment that a PC-relative fixup is |
18991 | relative to. For ARM, PC-relative fixups applied to instructions | |
18992 | are generally relative to the location of the fixup plus 8 bytes. | |
18993 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
18994 | require special handling. */ | |
bfae80f2 | 18995 | |
c19d1205 | 18996 | long |
2fc8bdac | 18997 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 18998 | { |
2fc8bdac ZW |
18999 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
19000 | ||
19001 | /* If this is pc-relative and we are going to emit a relocation | |
19002 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
19003 | will need. Otherwise we want to use the calculated base. |
19004 | For WinCE we skip the bias for externals as well, since this | |
19005 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 19006 | if (fixP->fx_pcrel |
2fc8bdac | 19007 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
19008 | || (arm_force_relocation (fixP) |
19009 | #ifdef TE_WINCE | |
19010 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19011 | #endif | |
19012 | ))) | |
2fc8bdac | 19013 | base = 0; |
bfae80f2 | 19014 | |
267bf995 | 19015 | |
c19d1205 | 19016 | switch (fixP->fx_r_type) |
bfae80f2 | 19017 | { |
2fc8bdac ZW |
19018 | /* PC relative addressing on the Thumb is slightly odd as the |
19019 | bottom two bits of the PC are forced to zero for the | |
19020 | calculation. This happens *after* application of the | |
19021 | pipeline offset. However, Thumb adrl already adjusts for | |
19022 | this, so we need not do it again. */ | |
c19d1205 | 19023 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 19024 | return base & ~3; |
c19d1205 ZW |
19025 | |
19026 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
19027 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 19028 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 19029 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 19030 | return (base + 4) & ~3; |
c19d1205 | 19031 | |
2fc8bdac ZW |
19032 | /* Thumb branches are simply offset by +4. */ |
19033 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
19034 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
19035 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
19036 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 19037 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 19038 | return base + 4; |
bfae80f2 | 19039 | |
267bf995 RR |
19040 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
19041 | if (fixP->fx_addsy | |
19042 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19043 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19044 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19045 | return base + 4; | |
19046 | ||
00adf2d4 JB |
19047 | /* BLX is like branches above, but forces the low two bits of PC to |
19048 | zero. */ | |
267bf995 RR |
19049 | case BFD_RELOC_THUMB_PCREL_BLX: |
19050 | if (fixP->fx_addsy | |
19051 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
19052 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19053 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
19054 | return (base + 4) & ~3; |
19055 | ||
2fc8bdac ZW |
19056 | /* ARM mode branches are offset by +8. However, the Windows CE |
19057 | loader expects the relocation not to take this into account. */ | |
267bf995 RR |
19058 | case BFD_RELOC_ARM_PCREL_BLX: |
19059 | if (fixP->fx_addsy | |
19060 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19061 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19062 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19063 | return base + 8; | |
19064 | ||
19065 | case BFD_RELOC_ARM_PCREL_CALL: | |
19066 | if (fixP->fx_addsy | |
19067 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
19068 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19069 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
19070 | return base + 8; | |
19071 | ||
2fc8bdac | 19072 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 19073 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 19074 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19075 | #ifdef TE_WINCE |
5f4273c7 | 19076 | /* When handling fixups immediately, because we have already |
53baae48 NC |
19077 | discovered the value of a symbol, or the address of the frag involved |
19078 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
19079 | see fixup_segment() in write.c | |
19080 | The S_IS_EXTERNAL test handles the case of global symbols. | |
19081 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
19082 | if (fixP->fx_pcrel | |
19083 | && fixP->fx_addsy != NULL | |
19084 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19085 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
19086 | return base + 8; | |
2fc8bdac | 19087 | return base; |
c19d1205 | 19088 | #else |
2fc8bdac | 19089 | return base + 8; |
c19d1205 | 19090 | #endif |
2fc8bdac | 19091 | |
267bf995 | 19092 | |
2fc8bdac ZW |
19093 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
19094 | branches, the Windows CE loader *does* expect the relocation | |
19095 | to take this into account. */ | |
19096 | case BFD_RELOC_ARM_OFFSET_IMM: | |
19097 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
19098 | case BFD_RELOC_ARM_HWLITERAL: | |
19099 | case BFD_RELOC_ARM_LITERAL: | |
19100 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
19101 | return base + 8; | |
19102 | ||
19103 | ||
19104 | /* Other PC-relative relocations are un-offset. */ | |
19105 | default: | |
19106 | return base; | |
19107 | } | |
bfae80f2 RE |
19108 | } |
19109 | ||
c19d1205 ZW |
19110 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
19111 | Otherwise we have no need to default values of symbols. */ | |
19112 | ||
19113 | symbolS * | |
19114 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 19115 | { |
c19d1205 ZW |
19116 | #ifdef OBJ_ELF |
19117 | if (name[0] == '_' && name[1] == 'G' | |
19118 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
19119 | { | |
19120 | if (!GOT_symbol) | |
19121 | { | |
19122 | if (symbol_find (name)) | |
bd3ba5d1 | 19123 | as_bad (_("GOT already in the symbol table")); |
bfae80f2 | 19124 | |
c19d1205 ZW |
19125 | GOT_symbol = symbol_new (name, undefined_section, |
19126 | (valueT) 0, & zero_address_frag); | |
19127 | } | |
bfae80f2 | 19128 | |
c19d1205 | 19129 | return GOT_symbol; |
bfae80f2 | 19130 | } |
c19d1205 | 19131 | #endif |
bfae80f2 | 19132 | |
c921be7d | 19133 | return NULL; |
bfae80f2 RE |
19134 | } |
19135 | ||
55cf6793 | 19136 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
19137 | computed as two separate immediate values, added together. We |
19138 | already know that this value cannot be computed by just one ARM | |
19139 | instruction. */ | |
19140 | ||
19141 | static unsigned int | |
19142 | validate_immediate_twopart (unsigned int val, | |
19143 | unsigned int * highpart) | |
bfae80f2 | 19144 | { |
c19d1205 ZW |
19145 | unsigned int a; |
19146 | unsigned int i; | |
bfae80f2 | 19147 | |
c19d1205 ZW |
19148 | for (i = 0; i < 32; i += 2) |
19149 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
19150 | { | |
19151 | if (a & 0xff00) | |
19152 | { | |
19153 | if (a & ~ 0xffff) | |
19154 | continue; | |
19155 | * highpart = (a >> 8) | ((i + 24) << 7); | |
19156 | } | |
19157 | else if (a & 0xff0000) | |
19158 | { | |
19159 | if (a & 0xff000000) | |
19160 | continue; | |
19161 | * highpart = (a >> 16) | ((i + 16) << 7); | |
19162 | } | |
19163 | else | |
19164 | { | |
9c2799c2 | 19165 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
19166 | * highpart = (a >> 24) | ((i + 8) << 7); |
19167 | } | |
bfae80f2 | 19168 | |
c19d1205 ZW |
19169 | return (a & 0xff) | (i << 7); |
19170 | } | |
bfae80f2 | 19171 | |
c19d1205 | 19172 | return FAIL; |
bfae80f2 RE |
19173 | } |
19174 | ||
c19d1205 ZW |
19175 | static int |
19176 | validate_offset_imm (unsigned int val, int hwse) | |
19177 | { | |
19178 | if ((hwse && val > 255) || val > 4095) | |
19179 | return FAIL; | |
19180 | return val; | |
19181 | } | |
bfae80f2 | 19182 | |
55cf6793 | 19183 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
19184 | negative immediate constant by altering the instruction. A bit of |
19185 | a hack really. | |
19186 | MOV <-> MVN | |
19187 | AND <-> BIC | |
19188 | ADC <-> SBC | |
19189 | by inverting the second operand, and | |
19190 | ADD <-> SUB | |
19191 | CMP <-> CMN | |
19192 | by negating the second operand. */ | |
bfae80f2 | 19193 | |
c19d1205 ZW |
19194 | static int |
19195 | negate_data_op (unsigned long * instruction, | |
19196 | unsigned long value) | |
bfae80f2 | 19197 | { |
c19d1205 ZW |
19198 | int op, new_inst; |
19199 | unsigned long negated, inverted; | |
bfae80f2 | 19200 | |
c19d1205 ZW |
19201 | negated = encode_arm_immediate (-value); |
19202 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 19203 | |
c19d1205 ZW |
19204 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
19205 | switch (op) | |
bfae80f2 | 19206 | { |
c19d1205 ZW |
19207 | /* First negates. */ |
19208 | case OPCODE_SUB: /* ADD <-> SUB */ | |
19209 | new_inst = OPCODE_ADD; | |
19210 | value = negated; | |
19211 | break; | |
bfae80f2 | 19212 | |
c19d1205 ZW |
19213 | case OPCODE_ADD: |
19214 | new_inst = OPCODE_SUB; | |
19215 | value = negated; | |
19216 | break; | |
bfae80f2 | 19217 | |
c19d1205 ZW |
19218 | case OPCODE_CMP: /* CMP <-> CMN */ |
19219 | new_inst = OPCODE_CMN; | |
19220 | value = negated; | |
19221 | break; | |
bfae80f2 | 19222 | |
c19d1205 ZW |
19223 | case OPCODE_CMN: |
19224 | new_inst = OPCODE_CMP; | |
19225 | value = negated; | |
19226 | break; | |
bfae80f2 | 19227 | |
c19d1205 ZW |
19228 | /* Now Inverted ops. */ |
19229 | case OPCODE_MOV: /* MOV <-> MVN */ | |
19230 | new_inst = OPCODE_MVN; | |
19231 | value = inverted; | |
19232 | break; | |
bfae80f2 | 19233 | |
c19d1205 ZW |
19234 | case OPCODE_MVN: |
19235 | new_inst = OPCODE_MOV; | |
19236 | value = inverted; | |
19237 | break; | |
bfae80f2 | 19238 | |
c19d1205 ZW |
19239 | case OPCODE_AND: /* AND <-> BIC */ |
19240 | new_inst = OPCODE_BIC; | |
19241 | value = inverted; | |
19242 | break; | |
bfae80f2 | 19243 | |
c19d1205 ZW |
19244 | case OPCODE_BIC: |
19245 | new_inst = OPCODE_AND; | |
19246 | value = inverted; | |
19247 | break; | |
bfae80f2 | 19248 | |
c19d1205 ZW |
19249 | case OPCODE_ADC: /* ADC <-> SBC */ |
19250 | new_inst = OPCODE_SBC; | |
19251 | value = inverted; | |
19252 | break; | |
bfae80f2 | 19253 | |
c19d1205 ZW |
19254 | case OPCODE_SBC: |
19255 | new_inst = OPCODE_ADC; | |
19256 | value = inverted; | |
19257 | break; | |
bfae80f2 | 19258 | |
c19d1205 ZW |
19259 | /* We cannot do anything. */ |
19260 | default: | |
19261 | return FAIL; | |
b99bd4ef NC |
19262 | } |
19263 | ||
c19d1205 ZW |
19264 | if (value == (unsigned) FAIL) |
19265 | return FAIL; | |
19266 | ||
19267 | *instruction &= OPCODE_MASK; | |
19268 | *instruction |= new_inst << DATA_OP_SHIFT; | |
19269 | return value; | |
b99bd4ef NC |
19270 | } |
19271 | ||
ef8d22e6 PB |
19272 | /* Like negate_data_op, but for Thumb-2. */ |
19273 | ||
19274 | static unsigned int | |
16dd5e42 | 19275 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
19276 | { |
19277 | int op, new_inst; | |
19278 | int rd; | |
16dd5e42 | 19279 | unsigned int negated, inverted; |
ef8d22e6 PB |
19280 | |
19281 | negated = encode_thumb32_immediate (-value); | |
19282 | inverted = encode_thumb32_immediate (~value); | |
19283 | ||
19284 | rd = (*instruction >> 8) & 0xf; | |
19285 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
19286 | switch (op) | |
19287 | { | |
19288 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
19289 | case T2_OPCODE_SUB: | |
19290 | new_inst = T2_OPCODE_ADD; | |
19291 | value = negated; | |
19292 | break; | |
19293 | ||
19294 | case T2_OPCODE_ADD: | |
19295 | new_inst = T2_OPCODE_SUB; | |
19296 | value = negated; | |
19297 | break; | |
19298 | ||
19299 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
19300 | case T2_OPCODE_ORR: | |
19301 | new_inst = T2_OPCODE_ORN; | |
19302 | value = inverted; | |
19303 | break; | |
19304 | ||
19305 | case T2_OPCODE_ORN: | |
19306 | new_inst = T2_OPCODE_ORR; | |
19307 | value = inverted; | |
19308 | break; | |
19309 | ||
19310 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
19311 | case T2_OPCODE_AND: | |
19312 | new_inst = T2_OPCODE_BIC; | |
19313 | if (rd == 15) | |
19314 | value = FAIL; | |
19315 | else | |
19316 | value = inverted; | |
19317 | break; | |
19318 | ||
19319 | case T2_OPCODE_BIC: | |
19320 | new_inst = T2_OPCODE_AND; | |
19321 | value = inverted; | |
19322 | break; | |
19323 | ||
19324 | /* ADC <-> SBC */ | |
19325 | case T2_OPCODE_ADC: | |
19326 | new_inst = T2_OPCODE_SBC; | |
19327 | value = inverted; | |
19328 | break; | |
19329 | ||
19330 | case T2_OPCODE_SBC: | |
19331 | new_inst = T2_OPCODE_ADC; | |
19332 | value = inverted; | |
19333 | break; | |
19334 | ||
19335 | /* We cannot do anything. */ | |
19336 | default: | |
19337 | return FAIL; | |
19338 | } | |
19339 | ||
16dd5e42 | 19340 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
19341 | return FAIL; |
19342 | ||
19343 | *instruction &= T2_OPCODE_MASK; | |
19344 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
19345 | return value; | |
19346 | } | |
19347 | ||
8f06b2d8 PB |
19348 | /* Read a 32-bit thumb instruction from buf. */ |
19349 | static unsigned long | |
19350 | get_thumb32_insn (char * buf) | |
19351 | { | |
19352 | unsigned long insn; | |
19353 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
19354 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19355 | ||
19356 | return insn; | |
19357 | } | |
19358 | ||
a8bc6c78 PB |
19359 | |
19360 | /* We usually want to set the low bit on the address of thumb function | |
19361 | symbols. In particular .word foo - . should have the low bit set. | |
19362 | Generic code tries to fold the difference of two symbols to | |
19363 | a constant. Prevent this and force a relocation when the first symbols | |
19364 | is a thumb function. */ | |
c921be7d NC |
19365 | |
19366 | bfd_boolean | |
a8bc6c78 PB |
19367 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
19368 | { | |
19369 | if (op == O_subtract | |
19370 | && l->X_op == O_symbol | |
19371 | && r->X_op == O_symbol | |
19372 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
19373 | { | |
19374 | l->X_op = O_subtract; | |
19375 | l->X_op_symbol = r->X_add_symbol; | |
19376 | l->X_add_number -= r->X_add_number; | |
c921be7d | 19377 | return TRUE; |
a8bc6c78 | 19378 | } |
c921be7d | 19379 | |
a8bc6c78 | 19380 | /* Process as normal. */ |
c921be7d | 19381 | return FALSE; |
a8bc6c78 PB |
19382 | } |
19383 | ||
c19d1205 | 19384 | void |
55cf6793 | 19385 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
19386 | valueT * valP, |
19387 | segT seg) | |
19388 | { | |
19389 | offsetT value = * valP; | |
19390 | offsetT newval; | |
19391 | unsigned int newimm; | |
19392 | unsigned long temp; | |
19393 | int sign; | |
19394 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 19395 | |
9c2799c2 | 19396 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 19397 | |
c19d1205 | 19398 | /* Note whether this will delete the relocation. */ |
4962c51a | 19399 | |
c19d1205 ZW |
19400 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
19401 | fixP->fx_done = 1; | |
b99bd4ef | 19402 | |
adbaf948 | 19403 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 19404 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
19405 | for emit_reloc. */ |
19406 | value &= 0xffffffff; | |
19407 | value ^= 0x80000000; | |
5f4273c7 | 19408 | value -= 0x80000000; |
adbaf948 ZW |
19409 | |
19410 | *valP = value; | |
c19d1205 | 19411 | fixP->fx_addnumber = value; |
b99bd4ef | 19412 | |
adbaf948 ZW |
19413 | /* Same treatment for fixP->fx_offset. */ |
19414 | fixP->fx_offset &= 0xffffffff; | |
19415 | fixP->fx_offset ^= 0x80000000; | |
19416 | fixP->fx_offset -= 0x80000000; | |
19417 | ||
c19d1205 | 19418 | switch (fixP->fx_r_type) |
b99bd4ef | 19419 | { |
c19d1205 ZW |
19420 | case BFD_RELOC_NONE: |
19421 | /* This will need to go in the object file. */ | |
19422 | fixP->fx_done = 0; | |
19423 | break; | |
b99bd4ef | 19424 | |
c19d1205 ZW |
19425 | case BFD_RELOC_ARM_IMMEDIATE: |
19426 | /* We claim that this fixup has been processed here, | |
19427 | even if in fact we generate an error because we do | |
19428 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19429 | fixP->fx_done = 1; | |
b99bd4ef | 19430 | |
c19d1205 ZW |
19431 | if (fixP->fx_addsy |
19432 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 19433 | { |
c19d1205 ZW |
19434 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19435 | _("undefined symbol %s used as an immediate value"), | |
19436 | S_GET_NAME (fixP->fx_addsy)); | |
19437 | break; | |
b99bd4ef NC |
19438 | } |
19439 | ||
42e5fcbf AS |
19440 | if (fixP->fx_addsy |
19441 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19442 | { | |
19443 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19444 | _("symbol %s is in a different section"), | |
19445 | S_GET_NAME (fixP->fx_addsy)); | |
19446 | break; | |
19447 | } | |
19448 | ||
c19d1205 ZW |
19449 | newimm = encode_arm_immediate (value); |
19450 | temp = md_chars_to_number (buf, INSN_SIZE); | |
19451 | ||
19452 | /* If the instruction will fail, see if we can fix things up by | |
19453 | changing the opcode. */ | |
19454 | if (newimm == (unsigned int) FAIL | |
19455 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 19456 | { |
c19d1205 ZW |
19457 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19458 | _("invalid constant (%lx) after fixup"), | |
19459 | (unsigned long) value); | |
19460 | break; | |
b99bd4ef | 19461 | } |
b99bd4ef | 19462 | |
c19d1205 ZW |
19463 | newimm |= (temp & 0xfffff000); |
19464 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
19465 | break; | |
b99bd4ef | 19466 | |
c19d1205 ZW |
19467 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
19468 | { | |
19469 | unsigned int highpart = 0; | |
19470 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 19471 | |
42e5fcbf AS |
19472 | if (fixP->fx_addsy |
19473 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19474 | { | |
19475 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19476 | _("undefined symbol %s used as an immediate value"), | |
19477 | S_GET_NAME (fixP->fx_addsy)); | |
19478 | break; | |
19479 | } | |
19480 | ||
19481 | if (fixP->fx_addsy | |
19482 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19483 | { | |
19484 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19485 | _("symbol %s is in a different section"), | |
19486 | S_GET_NAME (fixP->fx_addsy)); | |
19487 | break; | |
19488 | } | |
19489 | ||
c19d1205 ZW |
19490 | newimm = encode_arm_immediate (value); |
19491 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 19492 | |
c19d1205 ZW |
19493 | /* If the instruction will fail, see if we can fix things up by |
19494 | changing the opcode. */ | |
19495 | if (newimm == (unsigned int) FAIL | |
19496 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
19497 | { | |
19498 | /* No ? OK - try using two ADD instructions to generate | |
19499 | the value. */ | |
19500 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 19501 | |
c19d1205 ZW |
19502 | /* Yes - then make sure that the second instruction is |
19503 | also an add. */ | |
19504 | if (newimm != (unsigned int) FAIL) | |
19505 | newinsn = temp; | |
19506 | /* Still No ? Try using a negated value. */ | |
19507 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
19508 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
19509 | /* Otherwise - give up. */ | |
19510 | else | |
19511 | { | |
19512 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19513 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
19514 | (long) value); | |
19515 | break; | |
19516 | } | |
b99bd4ef | 19517 | |
c19d1205 ZW |
19518 | /* Replace the first operand in the 2nd instruction (which |
19519 | is the PC) with the destination register. We have | |
19520 | already added in the PC in the first instruction and we | |
19521 | do not want to do it again. */ | |
19522 | newinsn &= ~ 0xf0000; | |
19523 | newinsn |= ((newinsn & 0x0f000) << 4); | |
19524 | } | |
b99bd4ef | 19525 | |
c19d1205 ZW |
19526 | newimm |= (temp & 0xfffff000); |
19527 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 19528 | |
c19d1205 ZW |
19529 | highpart |= (newinsn & 0xfffff000); |
19530 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
19531 | } | |
19532 | break; | |
b99bd4ef | 19533 | |
c19d1205 | 19534 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
19535 | if (!fixP->fx_done && seg->use_rela_p) |
19536 | value = 0; | |
19537 | ||
c19d1205 ZW |
19538 | case BFD_RELOC_ARM_LITERAL: |
19539 | sign = value >= 0; | |
b99bd4ef | 19540 | |
c19d1205 ZW |
19541 | if (value < 0) |
19542 | value = - value; | |
b99bd4ef | 19543 | |
c19d1205 | 19544 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 19545 | { |
c19d1205 ZW |
19546 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
19547 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19548 | _("invalid literal constant: pool needs to be closer")); | |
19549 | else | |
19550 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19551 | _("bad immediate value for offset (%ld)"), | |
19552 | (long) value); | |
19553 | break; | |
f03698e6 RE |
19554 | } |
19555 | ||
c19d1205 ZW |
19556 | newval = md_chars_to_number (buf, INSN_SIZE); |
19557 | newval &= 0xff7ff000; | |
19558 | newval |= value | (sign ? INDEX_UP : 0); | |
19559 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19560 | break; | |
b99bd4ef | 19561 | |
c19d1205 ZW |
19562 | case BFD_RELOC_ARM_OFFSET_IMM8: |
19563 | case BFD_RELOC_ARM_HWLITERAL: | |
19564 | sign = value >= 0; | |
b99bd4ef | 19565 | |
c19d1205 ZW |
19566 | if (value < 0) |
19567 | value = - value; | |
b99bd4ef | 19568 | |
c19d1205 | 19569 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 19570 | { |
c19d1205 ZW |
19571 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
19572 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19573 | _("invalid literal constant: pool needs to be closer")); | |
19574 | else | |
f9d4405b | 19575 | as_bad (_("bad immediate value for 8-bit offset (%ld)"), |
c19d1205 ZW |
19576 | (long) value); |
19577 | break; | |
b99bd4ef NC |
19578 | } |
19579 | ||
c19d1205 ZW |
19580 | newval = md_chars_to_number (buf, INSN_SIZE); |
19581 | newval &= 0xff7ff0f0; | |
19582 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
19583 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19584 | break; | |
b99bd4ef | 19585 | |
c19d1205 ZW |
19586 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
19587 | if (value < 0 || value > 1020 || value % 4 != 0) | |
19588 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19589 | _("bad immediate value for offset (%ld)"), (long) value); | |
19590 | value /= 4; | |
b99bd4ef | 19591 | |
c19d1205 | 19592 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
19593 | newval |= value; |
19594 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
19595 | break; | |
b99bd4ef | 19596 | |
c19d1205 ZW |
19597 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
19598 | /* This is a complicated relocation used for all varieties of Thumb32 | |
19599 | load/store instruction with immediate offset: | |
19600 | ||
19601 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
19602 | *4, optional writeback(W) | |
19603 | (doubleword load/store) | |
19604 | ||
19605 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
19606 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
19607 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
19608 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
19609 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
19610 | ||
19611 | Uppercase letters indicate bits that are already encoded at | |
19612 | this point. Lowercase letters are our problem. For the | |
19613 | second block of instructions, the secondary opcode nybble | |
19614 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
19615 | a PC-relative operation. */ | |
19616 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19617 | newval <<= 16; | |
19618 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 19619 | |
c19d1205 | 19620 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 19621 | { |
c19d1205 ZW |
19622 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
19623 | if (value >= 0) | |
19624 | newval |= (1 << 23); | |
19625 | else | |
19626 | value = -value; | |
19627 | if (value % 4 != 0) | |
19628 | { | |
19629 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19630 | _("offset not a multiple of 4")); | |
19631 | break; | |
19632 | } | |
19633 | value /= 4; | |
216d22bc | 19634 | if (value > 0xff) |
c19d1205 ZW |
19635 | { |
19636 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19637 | _("offset out of range")); | |
19638 | break; | |
19639 | } | |
19640 | newval &= ~0xff; | |
b99bd4ef | 19641 | } |
c19d1205 | 19642 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 19643 | { |
c19d1205 ZW |
19644 | /* PC-relative, 12-bit offset. */ |
19645 | if (value >= 0) | |
19646 | newval |= (1 << 23); | |
19647 | else | |
19648 | value = -value; | |
216d22bc | 19649 | if (value > 0xfff) |
c19d1205 ZW |
19650 | { |
19651 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19652 | _("offset out of range")); | |
19653 | break; | |
19654 | } | |
19655 | newval &= ~0xfff; | |
b99bd4ef | 19656 | } |
c19d1205 | 19657 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 19658 | { |
c19d1205 ZW |
19659 | /* Writeback: 8-bit, +/- offset. */ |
19660 | if (value >= 0) | |
19661 | newval |= (1 << 9); | |
19662 | else | |
19663 | value = -value; | |
216d22bc | 19664 | if (value > 0xff) |
c19d1205 ZW |
19665 | { |
19666 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19667 | _("offset out of range")); | |
19668 | break; | |
19669 | } | |
19670 | newval &= ~0xff; | |
b99bd4ef | 19671 | } |
c19d1205 | 19672 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 19673 | { |
c19d1205 | 19674 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 19675 | if (value < 0 || value > 0xff) |
b99bd4ef | 19676 | { |
c19d1205 ZW |
19677 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19678 | _("offset out of range")); | |
19679 | break; | |
b99bd4ef | 19680 | } |
c19d1205 ZW |
19681 | newval &= ~0xff; |
19682 | newval |= value; | |
b99bd4ef NC |
19683 | } |
19684 | else | |
b99bd4ef | 19685 | { |
c19d1205 ZW |
19686 | /* Positive 12-bit or negative 8-bit offset. */ |
19687 | int limit; | |
19688 | if (value >= 0) | |
b99bd4ef | 19689 | { |
c19d1205 ZW |
19690 | newval |= (1 << 23); |
19691 | limit = 0xfff; | |
19692 | } | |
19693 | else | |
19694 | { | |
19695 | value = -value; | |
19696 | limit = 0xff; | |
19697 | } | |
19698 | if (value > limit) | |
19699 | { | |
19700 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19701 | _("offset out of range")); | |
19702 | break; | |
b99bd4ef | 19703 | } |
c19d1205 | 19704 | newval &= ~limit; |
b99bd4ef | 19705 | } |
b99bd4ef | 19706 | |
c19d1205 ZW |
19707 | newval |= value; |
19708 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
19709 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
19710 | break; | |
404ff6b5 | 19711 | |
c19d1205 ZW |
19712 | case BFD_RELOC_ARM_SHIFT_IMM: |
19713 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19714 | if (((unsigned long) value) > 32 | |
19715 | || (value == 32 | |
19716 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
19717 | { | |
19718 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19719 | _("shift expression is too large")); | |
19720 | break; | |
19721 | } | |
404ff6b5 | 19722 | |
c19d1205 ZW |
19723 | if (value == 0) |
19724 | /* Shifts of zero must be done as lsl. */ | |
19725 | newval &= ~0x60; | |
19726 | else if (value == 32) | |
19727 | value = 0; | |
19728 | newval &= 0xfffff07f; | |
19729 | newval |= (value & 0x1f) << 7; | |
19730 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19731 | break; | |
404ff6b5 | 19732 | |
c19d1205 | 19733 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 19734 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 19735 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 19736 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
19737 | /* We claim that this fixup has been processed here, |
19738 | even if in fact we generate an error because we do | |
19739 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19740 | fixP->fx_done = 1; | |
404ff6b5 | 19741 | |
c19d1205 ZW |
19742 | if (fixP->fx_addsy |
19743 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19744 | { | |
19745 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19746 | _("undefined symbol %s used as an immediate value"), | |
19747 | S_GET_NAME (fixP->fx_addsy)); | |
19748 | break; | |
19749 | } | |
404ff6b5 | 19750 | |
c19d1205 ZW |
19751 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19752 | newval <<= 16; | |
19753 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 19754 | |
16805f35 PB |
19755 | newimm = FAIL; |
19756 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
19757 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
19758 | { |
19759 | newimm = encode_thumb32_immediate (value); | |
19760 | if (newimm == (unsigned int) FAIL) | |
19761 | newimm = thumb32_negate_data_op (&newval, value); | |
19762 | } | |
16805f35 PB |
19763 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
19764 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 19765 | { |
16805f35 PB |
19766 | /* Turn add/sum into addw/subw. */ |
19767 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
19768 | newval = (newval & 0xfeffffff) | 0x02000000; | |
19769 | ||
e9f89963 PB |
19770 | /* 12 bit immediate for addw/subw. */ |
19771 | if (value < 0) | |
19772 | { | |
19773 | value = -value; | |
19774 | newval ^= 0x00a00000; | |
19775 | } | |
92e90b6e PB |
19776 | if (value > 0xfff) |
19777 | newimm = (unsigned int) FAIL; | |
19778 | else | |
19779 | newimm = value; | |
19780 | } | |
cc8a6dd0 | 19781 | |
c19d1205 | 19782 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 19783 | { |
c19d1205 ZW |
19784 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19785 | _("invalid constant (%lx) after fixup"), | |
19786 | (unsigned long) value); | |
19787 | break; | |
3631a3c8 NC |
19788 | } |
19789 | ||
c19d1205 ZW |
19790 | newval |= (newimm & 0x800) << 15; |
19791 | newval |= (newimm & 0x700) << 4; | |
19792 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 19793 | |
c19d1205 ZW |
19794 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
19795 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
19796 | break; | |
a737bd4d | 19797 | |
3eb17e6b | 19798 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
19799 | if (((unsigned long) value) > 0xffff) |
19800 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 19801 | _("invalid smc expression")); |
2fc8bdac | 19802 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19803 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
19804 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19805 | break; | |
a737bd4d | 19806 | |
c19d1205 | 19807 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 19808 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
19809 | { |
19810 | if (((unsigned long) value) > 0xff) | |
19811 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19812 | _("invalid swi expression")); | |
2fc8bdac | 19813 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
19814 | newval |= value; |
19815 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19816 | } | |
19817 | else | |
19818 | { | |
19819 | if (((unsigned long) value) > 0x00ffffff) | |
19820 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19821 | _("invalid swi expression")); | |
2fc8bdac | 19822 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19823 | newval |= value; |
19824 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19825 | } | |
19826 | break; | |
a737bd4d | 19827 | |
c19d1205 ZW |
19828 | case BFD_RELOC_ARM_MULTI: |
19829 | if (((unsigned long) value) > 0xffff) | |
19830 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19831 | _("invalid expression in load/store multiple")); | |
19832 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
19833 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19834 | break; | |
a737bd4d | 19835 | |
c19d1205 | 19836 | #ifdef OBJ_ELF |
39b41c9c | 19837 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
19838 | |
19839 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
19840 | && fixP->fx_addsy | |
19841 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19842 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19843 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19844 | /* Flip the bl to blx. This is a simple flip | |
19845 | bit here because we generate PCREL_CALL for | |
19846 | unconditional bls. */ | |
19847 | { | |
19848 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19849 | newval = newval | 0x10000000; | |
19850 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19851 | temp = 1; | |
19852 | fixP->fx_done = 1; | |
19853 | } | |
39b41c9c PB |
19854 | else |
19855 | temp = 3; | |
19856 | goto arm_branch_common; | |
19857 | ||
19858 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
19859 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19860 | && fixP->fx_addsy | |
19861 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19862 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19863 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19864 | { | |
19865 | /* This would map to a bl<cond>, b<cond>, | |
19866 | b<always> to a Thumb function. We | |
19867 | need to force a relocation for this particular | |
19868 | case. */ | |
19869 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19870 | fixP->fx_done = 0; | |
19871 | } | |
19872 | ||
2fc8bdac | 19873 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19874 | #endif |
39b41c9c PB |
19875 | case BFD_RELOC_ARM_PCREL_BRANCH: |
19876 | temp = 3; | |
19877 | goto arm_branch_common; | |
a737bd4d | 19878 | |
39b41c9c | 19879 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 19880 | |
39b41c9c | 19881 | temp = 1; |
267bf995 RR |
19882 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19883 | && fixP->fx_addsy | |
19884 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19885 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19886 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
19887 | { | |
19888 | /* Flip the blx to a bl and warn. */ | |
19889 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
19890 | newval = 0xeb000000; | |
19891 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
19892 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
19893 | name); | |
19894 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19895 | temp = 3; | |
19896 | fixP->fx_done = 1; | |
19897 | } | |
19898 | ||
19899 | #ifdef OBJ_ELF | |
19900 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
19901 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; | |
19902 | #endif | |
19903 | ||
39b41c9c | 19904 | arm_branch_common: |
c19d1205 | 19905 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
19906 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
19907 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
19908 | also be be clear. */ | |
19909 | if (value & temp) | |
c19d1205 | 19910 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
19911 | _("misaligned branch destination")); |
19912 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
19913 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
19914 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19915 | _("branch out of range")); | |
a737bd4d | 19916 | |
2fc8bdac | 19917 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19918 | { |
2fc8bdac ZW |
19919 | newval = md_chars_to_number (buf, INSN_SIZE); |
19920 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
19921 | /* Set the H bit on BLX instructions. */ |
19922 | if (temp == 1) | |
19923 | { | |
19924 | if (value & 2) | |
19925 | newval |= 0x01000000; | |
19926 | else | |
19927 | newval &= ~0x01000000; | |
19928 | } | |
2fc8bdac | 19929 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 19930 | } |
c19d1205 | 19931 | break; |
a737bd4d | 19932 | |
25fe350b MS |
19933 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
19934 | /* CBZ can only branch forward. */ | |
a737bd4d | 19935 | |
738755b0 MS |
19936 | /* Attempts to use CBZ to branch to the next instruction |
19937 | (which, strictly speaking, are prohibited) will be turned into | |
19938 | no-ops. | |
19939 | ||
19940 | FIXME: It may be better to remove the instruction completely and | |
19941 | perform relaxation. */ | |
19942 | if (value == -2) | |
2fc8bdac ZW |
19943 | { |
19944 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 19945 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
19946 | md_number_to_chars (buf, newval, THUMB_SIZE); |
19947 | } | |
738755b0 MS |
19948 | else |
19949 | { | |
19950 | if (value & ~0x7e) | |
19951 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19952 | _("branch out of range")); | |
19953 | ||
19954 | if (fixP->fx_done || !seg->use_rela_p) | |
19955 | { | |
19956 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19957 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
19958 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19959 | } | |
19960 | } | |
c19d1205 | 19961 | break; |
a737bd4d | 19962 | |
c19d1205 | 19963 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
19964 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
19965 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19966 | _("branch out of range")); | |
a737bd4d | 19967 | |
2fc8bdac ZW |
19968 | if (fixP->fx_done || !seg->use_rela_p) |
19969 | { | |
19970 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19971 | newval |= (value & 0x1ff) >> 1; | |
19972 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19973 | } | |
c19d1205 | 19974 | break; |
a737bd4d | 19975 | |
c19d1205 | 19976 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
19977 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
19978 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19979 | _("branch out of range")); | |
a737bd4d | 19980 | |
2fc8bdac ZW |
19981 | if (fixP->fx_done || !seg->use_rela_p) |
19982 | { | |
19983 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19984 | newval |= (value & 0xfff) >> 1; | |
19985 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19986 | } | |
c19d1205 | 19987 | break; |
a737bd4d | 19988 | |
c19d1205 | 19989 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
19990 | if (fixP->fx_addsy |
19991 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19992 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19993 | && S_IS_DEFINED (fixP->fx_addsy) | |
19994 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19995 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19996 | { | |
19997 | /* Force a relocation for a branch 20 bits wide. */ | |
19998 | fixP->fx_done = 0; | |
19999 | } | |
2fc8bdac ZW |
20000 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
20001 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20002 | _("conditional branch out of range")); | |
404ff6b5 | 20003 | |
2fc8bdac ZW |
20004 | if (fixP->fx_done || !seg->use_rela_p) |
20005 | { | |
20006 | offsetT newval2; | |
20007 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 20008 | |
2fc8bdac ZW |
20009 | S = (value & 0x00100000) >> 20; |
20010 | J2 = (value & 0x00080000) >> 19; | |
20011 | J1 = (value & 0x00040000) >> 18; | |
20012 | hi = (value & 0x0003f000) >> 12; | |
20013 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 20014 | |
2fc8bdac ZW |
20015 | newval = md_chars_to_number (buf, THUMB_SIZE); |
20016 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20017 | newval |= (S << 10) | hi; | |
20018 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
20019 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20020 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
20021 | } | |
c19d1205 | 20022 | break; |
6c43fab6 | 20023 | |
c19d1205 | 20024 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
20025 | |
20026 | /* If there is a blx from a thumb state function to | |
20027 | another thumb function flip this to a bl and warn | |
20028 | about it. */ | |
20029 | ||
20030 | if (fixP->fx_addsy | |
20031 | && S_IS_DEFINED (fixP->fx_addsy) | |
20032 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20033 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20034 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
20035 | { | |
20036 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
20037 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
20038 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
20039 | name); | |
20040 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20041 | newval = newval | 0x1000; | |
20042 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
20043 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20044 | fixP->fx_done = 1; | |
20045 | } | |
20046 | ||
20047 | ||
20048 | goto thumb_bl_common; | |
20049 | ||
c19d1205 | 20050 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
20051 | |
20052 | /* A bl from Thumb state ISA to an internal ARM state function | |
20053 | is converted to a blx. */ | |
20054 | if (fixP->fx_addsy | |
20055 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
20056 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
20057 | && S_IS_DEFINED (fixP->fx_addsy) | |
20058 | && ARM_IS_FUNC (fixP->fx_addsy) | |
20059 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
20060 | { | |
20061 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20062 | newval = newval & ~0x1000; | |
20063 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
20064 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
20065 | fixP->fx_done = 1; | |
20066 | } | |
20067 | ||
20068 | thumb_bl_common: | |
20069 | ||
20070 | #ifdef OBJ_ELF | |
20071 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 && | |
20072 | fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
20073 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20074 | #endif | |
20075 | ||
2fc8bdac ZW |
20076 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
20077 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20078 | _("branch out of range")); | |
404ff6b5 | 20079 | |
2fc8bdac ZW |
20080 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
20081 | /* For a BLX instruction, make sure that the relocation is rounded up | |
20082 | to a word boundary. This follows the semantics of the instruction | |
20083 | which specifies that bit 1 of the target address will come from bit | |
20084 | 1 of the base address. */ | |
20085 | value = (value + 1) & ~ 1; | |
404ff6b5 | 20086 | |
2fc8bdac | 20087 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20088 | { |
2fc8bdac ZW |
20089 | offsetT newval2; |
20090 | ||
20091 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20092 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20093 | newval |= (value & 0x7fffff) >> 12; | |
20094 | newval2 |= (value & 0xfff) >> 1; | |
20095 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20096 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 20097 | } |
c19d1205 | 20098 | break; |
404ff6b5 | 20099 | |
c19d1205 | 20100 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
20101 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
20102 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20103 | _("branch out of range")); | |
6c43fab6 | 20104 | |
2fc8bdac ZW |
20105 | if (fixP->fx_done || !seg->use_rela_p) |
20106 | { | |
20107 | offsetT newval2; | |
20108 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 20109 | |
2fc8bdac ZW |
20110 | S = (value & 0x01000000) >> 24; |
20111 | I1 = (value & 0x00800000) >> 23; | |
20112 | I2 = (value & 0x00400000) >> 22; | |
20113 | hi = (value & 0x003ff000) >> 12; | |
20114 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 20115 | |
2fc8bdac ZW |
20116 | I1 = !(I1 ^ S); |
20117 | I2 = !(I2 ^ S); | |
a737bd4d | 20118 | |
2fc8bdac ZW |
20119 | newval = md_chars_to_number (buf, THUMB_SIZE); |
20120 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
20121 | newval |= (S << 10) | hi; | |
20122 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
20123 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20124 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
20125 | } | |
20126 | break; | |
a737bd4d | 20127 | |
2fc8bdac ZW |
20128 | case BFD_RELOC_8: |
20129 | if (fixP->fx_done || !seg->use_rela_p) | |
20130 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 20131 | break; |
a737bd4d | 20132 | |
c19d1205 | 20133 | case BFD_RELOC_16: |
2fc8bdac | 20134 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20135 | md_number_to_chars (buf, value, 2); |
c19d1205 | 20136 | break; |
a737bd4d | 20137 | |
c19d1205 ZW |
20138 | #ifdef OBJ_ELF |
20139 | case BFD_RELOC_ARM_TLS_GD32: | |
20140 | case BFD_RELOC_ARM_TLS_LE32: | |
20141 | case BFD_RELOC_ARM_TLS_IE32: | |
20142 | case BFD_RELOC_ARM_TLS_LDM32: | |
20143 | case BFD_RELOC_ARM_TLS_LDO32: | |
20144 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
20145 | /* fall through */ | |
6c43fab6 | 20146 | |
c19d1205 ZW |
20147 | case BFD_RELOC_ARM_GOT32: |
20148 | case BFD_RELOC_ARM_GOTOFF: | |
2fc8bdac ZW |
20149 | if (fixP->fx_done || !seg->use_rela_p) |
20150 | md_number_to_chars (buf, 0, 4); | |
c19d1205 | 20151 | break; |
9a6f4e97 NS |
20152 | |
20153 | case BFD_RELOC_ARM_TARGET2: | |
20154 | /* TARGET2 is not partial-inplace, so we need to write the | |
20155 | addend here for REL targets, because it won't be written out | |
20156 | during reloc processing later. */ | |
20157 | if (fixP->fx_done || !seg->use_rela_p) | |
20158 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
20159 | break; | |
c19d1205 | 20160 | #endif |
6c43fab6 | 20161 | |
c19d1205 ZW |
20162 | case BFD_RELOC_RVA: |
20163 | case BFD_RELOC_32: | |
20164 | case BFD_RELOC_ARM_TARGET1: | |
20165 | case BFD_RELOC_ARM_ROSEGREL32: | |
20166 | case BFD_RELOC_ARM_SBREL32: | |
20167 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
20168 | #ifdef TE_PE |
20169 | case BFD_RELOC_32_SECREL: | |
20170 | #endif | |
2fc8bdac | 20171 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
20172 | #ifdef TE_WINCE |
20173 | /* For WinCE we only do this for pcrel fixups. */ | |
20174 | if (fixP->fx_done || fixP->fx_pcrel) | |
20175 | #endif | |
20176 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 20177 | break; |
6c43fab6 | 20178 | |
c19d1205 ZW |
20179 | #ifdef OBJ_ELF |
20180 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 20181 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
20182 | { |
20183 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
20184 | if ((value ^ (value >> 1)) & 0x40000000) | |
20185 | { | |
20186 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20187 | _("rel31 relocation overflow")); | |
20188 | } | |
20189 | newval |= value & 0x7fffffff; | |
20190 | md_number_to_chars (buf, newval, 4); | |
20191 | } | |
20192 | break; | |
c19d1205 | 20193 | #endif |
a737bd4d | 20194 | |
c19d1205 | 20195 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 20196 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
20197 | if (value < -1023 || value > 1023 || (value & 3)) |
20198 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20199 | _("co-processor offset out of range")); | |
20200 | cp_off_common: | |
20201 | sign = value >= 0; | |
20202 | if (value < 0) | |
20203 | value = -value; | |
8f06b2d8 PB |
20204 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20205 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20206 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20207 | else | |
20208 | newval = get_thumb32_insn (buf); | |
20209 | newval &= 0xff7fff00; | |
c19d1205 | 20210 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
8f06b2d8 PB |
20211 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20212 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20213 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20214 | else | |
20215 | put_thumb32_insn (buf, newval); | |
c19d1205 | 20216 | break; |
a737bd4d | 20217 | |
c19d1205 | 20218 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 20219 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
20220 | if (value < -255 || value > 255) |
20221 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20222 | _("co-processor offset out of range")); | |
df7849c5 | 20223 | value *= 4; |
c19d1205 | 20224 | goto cp_off_common; |
6c43fab6 | 20225 | |
c19d1205 ZW |
20226 | case BFD_RELOC_ARM_THUMB_OFFSET: |
20227 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20228 | /* Exactly what ranges, and where the offset is inserted depends | |
20229 | on the type of instruction, we can establish this from the | |
20230 | top 4 bits. */ | |
20231 | switch (newval >> 12) | |
20232 | { | |
20233 | case 4: /* PC load. */ | |
20234 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
20235 | forced to zero for these loads; md_pcrel_from has already | |
20236 | compensated for this. */ | |
20237 | if (value & 3) | |
20238 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20239 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
20240 | (((unsigned long) fixP->fx_frag->fr_address |
20241 | + (unsigned long) fixP->fx_where) & ~3) | |
20242 | + (unsigned long) value); | |
a737bd4d | 20243 | |
c19d1205 ZW |
20244 | if (value & ~0x3fc) |
20245 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20246 | _("invalid offset, value too big (0x%08lX)"), | |
20247 | (long) value); | |
a737bd4d | 20248 | |
c19d1205 ZW |
20249 | newval |= value >> 2; |
20250 | break; | |
a737bd4d | 20251 | |
c19d1205 ZW |
20252 | case 9: /* SP load/store. */ |
20253 | if (value & ~0x3fc) | |
20254 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20255 | _("invalid offset, value too big (0x%08lX)"), | |
20256 | (long) value); | |
20257 | newval |= value >> 2; | |
20258 | break; | |
6c43fab6 | 20259 | |
c19d1205 ZW |
20260 | case 6: /* Word load/store. */ |
20261 | if (value & ~0x7c) | |
20262 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20263 | _("invalid offset, value too big (0x%08lX)"), | |
20264 | (long) value); | |
20265 | newval |= value << 4; /* 6 - 2. */ | |
20266 | break; | |
a737bd4d | 20267 | |
c19d1205 ZW |
20268 | case 7: /* Byte load/store. */ |
20269 | if (value & ~0x1f) | |
20270 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20271 | _("invalid offset, value too big (0x%08lX)"), | |
20272 | (long) value); | |
20273 | newval |= value << 6; | |
20274 | break; | |
a737bd4d | 20275 | |
c19d1205 ZW |
20276 | case 8: /* Halfword load/store. */ |
20277 | if (value & ~0x3e) | |
20278 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20279 | _("invalid offset, value too big (0x%08lX)"), | |
20280 | (long) value); | |
20281 | newval |= value << 5; /* 6 - 1. */ | |
20282 | break; | |
a737bd4d | 20283 | |
c19d1205 ZW |
20284 | default: |
20285 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20286 | "Unable to process relocation for thumb opcode: %lx", | |
20287 | (unsigned long) newval); | |
20288 | break; | |
20289 | } | |
20290 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20291 | break; | |
a737bd4d | 20292 | |
c19d1205 ZW |
20293 | case BFD_RELOC_ARM_THUMB_ADD: |
20294 | /* This is a complicated relocation, since we use it for all of | |
20295 | the following immediate relocations: | |
a737bd4d | 20296 | |
c19d1205 ZW |
20297 | 3bit ADD/SUB |
20298 | 8bit ADD/SUB | |
20299 | 9bit ADD/SUB SP word-aligned | |
20300 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 20301 | |
c19d1205 ZW |
20302 | The type of instruction being processed is encoded in the |
20303 | instruction field: | |
a737bd4d | 20304 | |
c19d1205 ZW |
20305 | 0x8000 SUB |
20306 | 0x00F0 Rd | |
20307 | 0x000F Rs | |
20308 | */ | |
20309 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20310 | { | |
20311 | int rd = (newval >> 4) & 0xf; | |
20312 | int rs = newval & 0xf; | |
20313 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 20314 | |
c19d1205 ZW |
20315 | /* Check for HI regs, only very restricted cases allowed: |
20316 | Adjusting SP, and using PC or SP to get an address. */ | |
20317 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
20318 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
20319 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20320 | _("invalid Hi register with immediate")); | |
a737bd4d | 20321 | |
c19d1205 ZW |
20322 | /* If value is negative, choose the opposite instruction. */ |
20323 | if (value < 0) | |
20324 | { | |
20325 | value = -value; | |
20326 | subtract = !subtract; | |
20327 | if (value < 0) | |
20328 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20329 | _("immediate value out of range")); | |
20330 | } | |
a737bd4d | 20331 | |
c19d1205 ZW |
20332 | if (rd == REG_SP) |
20333 | { | |
20334 | if (value & ~0x1fc) | |
20335 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20336 | _("invalid immediate for stack address calculation")); | |
20337 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
20338 | newval |= value >> 2; | |
20339 | } | |
20340 | else if (rs == REG_PC || rs == REG_SP) | |
20341 | { | |
20342 | if (subtract || value & ~0x3fc) | |
20343 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20344 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
20345 | (unsigned long) value); | |
20346 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
20347 | newval |= rd << 8; | |
20348 | newval |= value >> 2; | |
20349 | } | |
20350 | else if (rs == rd) | |
20351 | { | |
20352 | if (value & ~0xff) | |
20353 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20354 | _("immediate value out of range")); | |
20355 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
20356 | newval |= (rd << 8) | value; | |
20357 | } | |
20358 | else | |
20359 | { | |
20360 | if (value & ~0x7) | |
20361 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20362 | _("immediate value out of range")); | |
20363 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
20364 | newval |= rd | (rs << 3) | (value << 6); | |
20365 | } | |
20366 | } | |
20367 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20368 | break; | |
a737bd4d | 20369 | |
c19d1205 ZW |
20370 | case BFD_RELOC_ARM_THUMB_IMM: |
20371 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20372 | if (value < 0 || value > 255) | |
20373 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 20374 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
20375 | (long) value); |
20376 | newval |= value; | |
20377 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20378 | break; | |
a737bd4d | 20379 | |
c19d1205 ZW |
20380 | case BFD_RELOC_ARM_THUMB_SHIFT: |
20381 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
20382 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
20383 | temp = newval & 0xf800; | |
20384 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
20385 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20386 | _("invalid shift value: %ld"), (long) value); | |
20387 | /* Shifts of zero must be encoded as LSL. */ | |
20388 | if (value == 0) | |
20389 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
20390 | /* Shifts of 32 are encoded as zero. */ | |
20391 | else if (value == 32) | |
20392 | value = 0; | |
20393 | newval |= value << 6; | |
20394 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20395 | break; | |
a737bd4d | 20396 | |
c19d1205 ZW |
20397 | case BFD_RELOC_VTABLE_INHERIT: |
20398 | case BFD_RELOC_VTABLE_ENTRY: | |
20399 | fixP->fx_done = 0; | |
20400 | return; | |
6c43fab6 | 20401 | |
b6895b4f PB |
20402 | case BFD_RELOC_ARM_MOVW: |
20403 | case BFD_RELOC_ARM_MOVT: | |
20404 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20405 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20406 | if (fixP->fx_done || !seg->use_rela_p) | |
20407 | { | |
20408 | /* REL format relocations are limited to a 16-bit addend. */ | |
20409 | if (!fixP->fx_done) | |
20410 | { | |
39623e12 | 20411 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 20412 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 20413 | _("offset out of range")); |
b6895b4f PB |
20414 | } |
20415 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
20416 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20417 | { | |
20418 | value >>= 16; | |
20419 | } | |
20420 | ||
20421 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
20422 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20423 | { | |
20424 | newval = get_thumb32_insn (buf); | |
20425 | newval &= 0xfbf08f00; | |
20426 | newval |= (value & 0xf000) << 4; | |
20427 | newval |= (value & 0x0800) << 15; | |
20428 | newval |= (value & 0x0700) << 4; | |
20429 | newval |= (value & 0x00ff); | |
20430 | put_thumb32_insn (buf, newval); | |
20431 | } | |
20432 | else | |
20433 | { | |
20434 | newval = md_chars_to_number (buf, 4); | |
20435 | newval &= 0xfff0f000; | |
20436 | newval |= value & 0x0fff; | |
20437 | newval |= (value & 0xf000) << 4; | |
20438 | md_number_to_chars (buf, newval, 4); | |
20439 | } | |
20440 | } | |
20441 | return; | |
20442 | ||
4962c51a MS |
20443 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20444 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20445 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20446 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20447 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20448 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20449 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20450 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20451 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20452 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 20453 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20454 | if (!seg->use_rela_p) |
20455 | { | |
20456 | bfd_vma insn; | |
20457 | bfd_vma encoded_addend; | |
20458 | bfd_vma addend_abs = abs (value); | |
20459 | ||
20460 | /* Check that the absolute value of the addend can be | |
20461 | expressed as an 8-bit constant plus a rotation. */ | |
20462 | encoded_addend = encode_arm_immediate (addend_abs); | |
20463 | if (encoded_addend == (unsigned int) FAIL) | |
20464 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20465 | _("the offset 0x%08lX is not representable"), | |
495bde8e | 20466 | (unsigned long) addend_abs); |
4962c51a MS |
20467 | |
20468 | /* Extract the instruction. */ | |
20469 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20470 | ||
20471 | /* If the addend is positive, use an ADD instruction. | |
20472 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
20473 | insn &= 0xff1fffff; | |
20474 | if (value < 0) | |
20475 | insn |= 1 << 22; | |
20476 | else | |
20477 | insn |= 1 << 23; | |
20478 | ||
20479 | /* Place the encoded addend into the first 12 bits of the | |
20480 | instruction. */ | |
20481 | insn &= 0xfffff000; | |
20482 | insn |= encoded_addend; | |
5f4273c7 NC |
20483 | |
20484 | /* Update the instruction. */ | |
4962c51a MS |
20485 | md_number_to_chars (buf, insn, INSN_SIZE); |
20486 | } | |
20487 | break; | |
20488 | ||
20489 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20490 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20491 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20492 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20493 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20494 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 20495 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20496 | if (!seg->use_rela_p) |
20497 | { | |
20498 | bfd_vma insn; | |
20499 | bfd_vma addend_abs = abs (value); | |
20500 | ||
20501 | /* Check that the absolute value of the addend can be | |
20502 | encoded in 12 bits. */ | |
20503 | if (addend_abs >= 0x1000) | |
20504 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20505 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
495bde8e | 20506 | (unsigned long) addend_abs); |
4962c51a MS |
20507 | |
20508 | /* Extract the instruction. */ | |
20509 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20510 | ||
20511 | /* If the addend is negative, clear bit 23 of the instruction. | |
20512 | Otherwise set it. */ | |
20513 | if (value < 0) | |
20514 | insn &= ~(1 << 23); | |
20515 | else | |
20516 | insn |= 1 << 23; | |
20517 | ||
20518 | /* Place the absolute value of the addend into the first 12 bits | |
20519 | of the instruction. */ | |
20520 | insn &= 0xfffff000; | |
20521 | insn |= addend_abs; | |
5f4273c7 NC |
20522 | |
20523 | /* Update the instruction. */ | |
4962c51a MS |
20524 | md_number_to_chars (buf, insn, INSN_SIZE); |
20525 | } | |
20526 | break; | |
20527 | ||
20528 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20529 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20530 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20531 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20532 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20533 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 20534 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20535 | if (!seg->use_rela_p) |
20536 | { | |
20537 | bfd_vma insn; | |
20538 | bfd_vma addend_abs = abs (value); | |
20539 | ||
20540 | /* Check that the absolute value of the addend can be | |
20541 | encoded in 8 bits. */ | |
20542 | if (addend_abs >= 0x100) | |
20543 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20544 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
495bde8e | 20545 | (unsigned long) addend_abs); |
4962c51a MS |
20546 | |
20547 | /* Extract the instruction. */ | |
20548 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20549 | ||
20550 | /* If the addend is negative, clear bit 23 of the instruction. | |
20551 | Otherwise set it. */ | |
20552 | if (value < 0) | |
20553 | insn &= ~(1 << 23); | |
20554 | else | |
20555 | insn |= 1 << 23; | |
20556 | ||
20557 | /* Place the first four bits of the absolute value of the addend | |
20558 | into the first 4 bits of the instruction, and the remaining | |
20559 | four into bits 8 .. 11. */ | |
20560 | insn &= 0xfffff0f0; | |
20561 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
5f4273c7 NC |
20562 | |
20563 | /* Update the instruction. */ | |
4962c51a MS |
20564 | md_number_to_chars (buf, insn, INSN_SIZE); |
20565 | } | |
20566 | break; | |
20567 | ||
20568 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20569 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20570 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20571 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20572 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20573 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 20574 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20575 | if (!seg->use_rela_p) |
20576 | { | |
20577 | bfd_vma insn; | |
20578 | bfd_vma addend_abs = abs (value); | |
20579 | ||
20580 | /* Check that the absolute value of the addend is a multiple of | |
20581 | four and, when divided by four, fits in 8 bits. */ | |
20582 | if (addend_abs & 0x3) | |
20583 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20584 | _("bad offset 0x%08lX (must be word-aligned)"), | |
495bde8e | 20585 | (unsigned long) addend_abs); |
4962c51a MS |
20586 | |
20587 | if ((addend_abs >> 2) > 0xff) | |
20588 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20589 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
495bde8e | 20590 | (unsigned long) addend_abs); |
4962c51a MS |
20591 | |
20592 | /* Extract the instruction. */ | |
20593 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20594 | ||
20595 | /* If the addend is negative, clear bit 23 of the instruction. | |
20596 | Otherwise set it. */ | |
20597 | if (value < 0) | |
20598 | insn &= ~(1 << 23); | |
20599 | else | |
20600 | insn |= 1 << 23; | |
20601 | ||
20602 | /* Place the addend (divided by four) into the first eight | |
20603 | bits of the instruction. */ | |
20604 | insn &= 0xfffffff0; | |
20605 | insn |= addend_abs >> 2; | |
5f4273c7 NC |
20606 | |
20607 | /* Update the instruction. */ | |
4962c51a MS |
20608 | md_number_to_chars (buf, insn, INSN_SIZE); |
20609 | } | |
20610 | break; | |
20611 | ||
845b51d6 PB |
20612 | case BFD_RELOC_ARM_V4BX: |
20613 | /* This will need to go in the object file. */ | |
20614 | fixP->fx_done = 0; | |
20615 | break; | |
20616 | ||
c19d1205 ZW |
20617 | case BFD_RELOC_UNUSED: |
20618 | default: | |
20619 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20620 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
20621 | } | |
6c43fab6 RE |
20622 | } |
20623 | ||
c19d1205 ZW |
20624 | /* Translate internal representation of relocation info to BFD target |
20625 | format. */ | |
a737bd4d | 20626 | |
c19d1205 | 20627 | arelent * |
00a97672 | 20628 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 20629 | { |
c19d1205 ZW |
20630 | arelent * reloc; |
20631 | bfd_reloc_code_real_type code; | |
a737bd4d | 20632 | |
c19d1205 | 20633 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 20634 | |
c19d1205 ZW |
20635 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
20636 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
20637 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 20638 | |
2fc8bdac | 20639 | if (fixp->fx_pcrel) |
00a97672 RS |
20640 | { |
20641 | if (section->use_rela_p) | |
20642 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
20643 | else | |
20644 | fixp->fx_offset = reloc->address; | |
20645 | } | |
c19d1205 | 20646 | reloc->addend = fixp->fx_offset; |
a737bd4d | 20647 | |
c19d1205 | 20648 | switch (fixp->fx_r_type) |
a737bd4d | 20649 | { |
c19d1205 ZW |
20650 | case BFD_RELOC_8: |
20651 | if (fixp->fx_pcrel) | |
20652 | { | |
20653 | code = BFD_RELOC_8_PCREL; | |
20654 | break; | |
20655 | } | |
a737bd4d | 20656 | |
c19d1205 ZW |
20657 | case BFD_RELOC_16: |
20658 | if (fixp->fx_pcrel) | |
20659 | { | |
20660 | code = BFD_RELOC_16_PCREL; | |
20661 | break; | |
20662 | } | |
6c43fab6 | 20663 | |
c19d1205 ZW |
20664 | case BFD_RELOC_32: |
20665 | if (fixp->fx_pcrel) | |
20666 | { | |
20667 | code = BFD_RELOC_32_PCREL; | |
20668 | break; | |
20669 | } | |
a737bd4d | 20670 | |
b6895b4f PB |
20671 | case BFD_RELOC_ARM_MOVW: |
20672 | if (fixp->fx_pcrel) | |
20673 | { | |
20674 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
20675 | break; | |
20676 | } | |
20677 | ||
20678 | case BFD_RELOC_ARM_MOVT: | |
20679 | if (fixp->fx_pcrel) | |
20680 | { | |
20681 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
20682 | break; | |
20683 | } | |
20684 | ||
20685 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20686 | if (fixp->fx_pcrel) | |
20687 | { | |
20688 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
20689 | break; | |
20690 | } | |
20691 | ||
20692 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20693 | if (fixp->fx_pcrel) | |
20694 | { | |
20695 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
20696 | break; | |
20697 | } | |
20698 | ||
c19d1205 ZW |
20699 | case BFD_RELOC_NONE: |
20700 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
20701 | case BFD_RELOC_ARM_PCREL_BLX: | |
20702 | case BFD_RELOC_RVA: | |
20703 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
20704 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
20705 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
20706 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20707 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20708 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
20709 | case BFD_RELOC_VTABLE_ENTRY: |
20710 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
20711 | #ifdef TE_PE |
20712 | case BFD_RELOC_32_SECREL: | |
20713 | #endif | |
c19d1205 ZW |
20714 | code = fixp->fx_r_type; |
20715 | break; | |
a737bd4d | 20716 | |
00adf2d4 JB |
20717 | case BFD_RELOC_THUMB_PCREL_BLX: |
20718 | #ifdef OBJ_ELF | |
20719 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
20720 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20721 | else | |
20722 | #endif | |
20723 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
20724 | break; | |
20725 | ||
c19d1205 ZW |
20726 | case BFD_RELOC_ARM_LITERAL: |
20727 | case BFD_RELOC_ARM_HWLITERAL: | |
20728 | /* If this is called then the a literal has | |
20729 | been referenced across a section boundary. */ | |
20730 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20731 | _("literal referenced across section boundary")); | |
20732 | return NULL; | |
a737bd4d | 20733 | |
c19d1205 ZW |
20734 | #ifdef OBJ_ELF |
20735 | case BFD_RELOC_ARM_GOT32: | |
20736 | case BFD_RELOC_ARM_GOTOFF: | |
20737 | case BFD_RELOC_ARM_PLT32: | |
20738 | case BFD_RELOC_ARM_TARGET1: | |
20739 | case BFD_RELOC_ARM_ROSEGREL32: | |
20740 | case BFD_RELOC_ARM_SBREL32: | |
20741 | case BFD_RELOC_ARM_PREL31: | |
20742 | case BFD_RELOC_ARM_TARGET2: | |
20743 | case BFD_RELOC_ARM_TLS_LE32: | |
20744 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
20745 | case BFD_RELOC_ARM_PCREL_CALL: |
20746 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
20747 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20748 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20749 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20750 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20751 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20752 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20753 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20754 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20755 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20756 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20757 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20758 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20759 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20760 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20761 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20762 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20763 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20764 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20765 | case BFD_RELOC_ARM_ALU_SB_G2: | |
20766 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20767 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20768 | case BFD_RELOC_ARM_LDR_SB_G2: | |
20769 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20770 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20771 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
20772 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20773 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20774 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 20775 | case BFD_RELOC_ARM_V4BX: |
c19d1205 ZW |
20776 | code = fixp->fx_r_type; |
20777 | break; | |
a737bd4d | 20778 | |
c19d1205 ZW |
20779 | case BFD_RELOC_ARM_TLS_GD32: |
20780 | case BFD_RELOC_ARM_TLS_IE32: | |
20781 | case BFD_RELOC_ARM_TLS_LDM32: | |
20782 | /* BFD will include the symbol's address in the addend. | |
20783 | But we don't want that, so subtract it out again here. */ | |
20784 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
20785 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
20786 | code = fixp->fx_r_type; | |
20787 | break; | |
20788 | #endif | |
a737bd4d | 20789 | |
c19d1205 ZW |
20790 | case BFD_RELOC_ARM_IMMEDIATE: |
20791 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20792 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
20793 | return NULL; | |
a737bd4d | 20794 | |
c19d1205 ZW |
20795 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
20796 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20797 | _("ADRL used for a symbol not defined in the same file")); | |
20798 | return NULL; | |
a737bd4d | 20799 | |
c19d1205 | 20800 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
20801 | if (section->use_rela_p) |
20802 | { | |
20803 | code = fixp->fx_r_type; | |
20804 | break; | |
20805 | } | |
20806 | ||
c19d1205 ZW |
20807 | if (fixp->fx_addsy != NULL |
20808 | && !S_IS_DEFINED (fixp->fx_addsy) | |
20809 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 20810 | { |
c19d1205 ZW |
20811 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20812 | _("undefined local label `%s'"), | |
20813 | S_GET_NAME (fixp->fx_addsy)); | |
20814 | return NULL; | |
a737bd4d NC |
20815 | } |
20816 | ||
c19d1205 ZW |
20817 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20818 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
20819 | return NULL; | |
a737bd4d | 20820 | |
c19d1205 ZW |
20821 | default: |
20822 | { | |
20823 | char * type; | |
6c43fab6 | 20824 | |
c19d1205 ZW |
20825 | switch (fixp->fx_r_type) |
20826 | { | |
20827 | case BFD_RELOC_NONE: type = "NONE"; break; | |
20828 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
20829 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 20830 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
20831 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
20832 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
20833 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 20834 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
20835 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
20836 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
20837 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
20838 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
20839 | default: type = _("<unknown>"); break; | |
20840 | } | |
20841 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20842 | _("cannot represent %s relocation in this object file format"), | |
20843 | type); | |
20844 | return NULL; | |
20845 | } | |
a737bd4d | 20846 | } |
6c43fab6 | 20847 | |
c19d1205 ZW |
20848 | #ifdef OBJ_ELF |
20849 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
20850 | && GOT_symbol | |
20851 | && fixp->fx_addsy == GOT_symbol) | |
20852 | { | |
20853 | code = BFD_RELOC_ARM_GOTPC; | |
20854 | reloc->addend = fixp->fx_offset = reloc->address; | |
20855 | } | |
20856 | #endif | |
6c43fab6 | 20857 | |
c19d1205 | 20858 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 20859 | |
c19d1205 ZW |
20860 | if (reloc->howto == NULL) |
20861 | { | |
20862 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20863 | _("cannot represent %s relocation in this object file format"), | |
20864 | bfd_get_reloc_code_name (code)); | |
20865 | return NULL; | |
20866 | } | |
6c43fab6 | 20867 | |
c19d1205 ZW |
20868 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
20869 | vtable entry to be used in the relocation's section offset. */ | |
20870 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
20871 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 20872 | |
c19d1205 | 20873 | return reloc; |
6c43fab6 RE |
20874 | } |
20875 | ||
c19d1205 | 20876 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 20877 | |
c19d1205 ZW |
20878 | void |
20879 | cons_fix_new_arm (fragS * frag, | |
20880 | int where, | |
20881 | int size, | |
20882 | expressionS * exp) | |
6c43fab6 | 20883 | { |
c19d1205 ZW |
20884 | bfd_reloc_code_real_type type; |
20885 | int pcrel = 0; | |
6c43fab6 | 20886 | |
c19d1205 ZW |
20887 | /* Pick a reloc. |
20888 | FIXME: @@ Should look at CPU word size. */ | |
20889 | switch (size) | |
20890 | { | |
20891 | case 1: | |
20892 | type = BFD_RELOC_8; | |
20893 | break; | |
20894 | case 2: | |
20895 | type = BFD_RELOC_16; | |
20896 | break; | |
20897 | case 4: | |
20898 | default: | |
20899 | type = BFD_RELOC_32; | |
20900 | break; | |
20901 | case 8: | |
20902 | type = BFD_RELOC_64; | |
20903 | break; | |
20904 | } | |
6c43fab6 | 20905 | |
f0927246 NC |
20906 | #ifdef TE_PE |
20907 | if (exp->X_op == O_secrel) | |
20908 | { | |
20909 | exp->X_op = O_symbol; | |
20910 | type = BFD_RELOC_32_SECREL; | |
20911 | } | |
20912 | #endif | |
20913 | ||
c19d1205 ZW |
20914 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
20915 | } | |
6c43fab6 | 20916 | |
4343666d | 20917 | #if defined (OBJ_COFF) |
c19d1205 ZW |
20918 | void |
20919 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 20920 | { |
c19d1205 ZW |
20921 | /* If the destination of the branch is a defined symbol which does not have |
20922 | the THUMB_FUNC attribute, then we must be calling a function which has | |
20923 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
20924 | function and change the branch to refer to that function instead. */ | |
20925 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
20926 | && fixP->fx_addsy != NULL | |
20927 | && S_IS_DEFINED (fixP->fx_addsy) | |
20928 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 20929 | { |
c19d1205 | 20930 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 20931 | } |
c19d1205 ZW |
20932 | } |
20933 | #endif | |
6c43fab6 | 20934 | |
267bf995 | 20935 | |
c19d1205 ZW |
20936 | int |
20937 | arm_force_relocation (struct fix * fixp) | |
20938 | { | |
20939 | #if defined (OBJ_COFF) && defined (TE_PE) | |
20940 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
20941 | return 1; | |
20942 | #endif | |
6c43fab6 | 20943 | |
267bf995 RR |
20944 | /* In case we have a call or a branch to a function in ARM ISA mode from |
20945 | a thumb function or vice-versa force the relocation. These relocations | |
20946 | are cleared off for some cores that might have blx and simple transformations | |
20947 | are possible. */ | |
20948 | ||
20949 | #ifdef OBJ_ELF | |
20950 | switch (fixp->fx_r_type) | |
20951 | { | |
20952 | case BFD_RELOC_ARM_PCREL_JUMP: | |
20953 | case BFD_RELOC_ARM_PCREL_CALL: | |
20954 | case BFD_RELOC_THUMB_PCREL_BLX: | |
20955 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
20956 | return 1; | |
20957 | break; | |
20958 | ||
20959 | case BFD_RELOC_ARM_PCREL_BLX: | |
20960 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
20961 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20962 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20963 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
20964 | return 1; | |
20965 | break; | |
20966 | ||
20967 | default: | |
20968 | break; | |
20969 | } | |
20970 | #endif | |
20971 | ||
c19d1205 ZW |
20972 | /* Resolve these relocations even if the symbol is extern or weak. */ |
20973 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
20974 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 | 20975 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
16805f35 | 20976 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
20977 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
20978 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
20979 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 20980 | return 0; |
a737bd4d | 20981 | |
4962c51a MS |
20982 | /* Always leave these relocations for the linker. */ |
20983 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
20984 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
20985 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
20986 | return 1; | |
20987 | ||
f0291e4c PB |
20988 | /* Always generate relocations against function symbols. */ |
20989 | if (fixp->fx_r_type == BFD_RELOC_32 | |
20990 | && fixp->fx_addsy | |
20991 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
20992 | return 1; | |
20993 | ||
c19d1205 | 20994 | return generic_force_reloc (fixp); |
404ff6b5 AH |
20995 | } |
20996 | ||
0ffdc86c | 20997 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
20998 | /* Relocations against function names must be left unadjusted, |
20999 | so that the linker can use this information to generate interworking | |
21000 | stubs. The MIPS version of this function | |
c19d1205 ZW |
21001 | also prevents relocations that are mips-16 specific, but I do not |
21002 | know why it does this. | |
404ff6b5 | 21003 | |
c19d1205 ZW |
21004 | FIXME: |
21005 | There is one other problem that ought to be addressed here, but | |
21006 | which currently is not: Taking the address of a label (rather | |
21007 | than a function) and then later jumping to that address. Such | |
21008 | addresses also ought to have their bottom bit set (assuming that | |
21009 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 21010 | |
c19d1205 ZW |
21011 | bfd_boolean |
21012 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 21013 | { |
c19d1205 ZW |
21014 | if (fixP->fx_addsy == NULL) |
21015 | return 1; | |
404ff6b5 | 21016 | |
e28387c3 PB |
21017 | /* Preserve relocations against symbols with function type. */ |
21018 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 21019 | return FALSE; |
e28387c3 | 21020 | |
c19d1205 ZW |
21021 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
21022 | && fixP->fx_subsy == NULL) | |
c921be7d | 21023 | return FALSE; |
a737bd4d | 21024 | |
c19d1205 ZW |
21025 | /* We need the symbol name for the VTABLE entries. */ |
21026 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
21027 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 21028 | return FALSE; |
404ff6b5 | 21029 | |
c19d1205 ZW |
21030 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
21031 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
21032 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
21033 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
21034 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
21035 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
21036 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
21037 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
21038 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
21039 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
c921be7d | 21040 | return FALSE; |
a737bd4d | 21041 | |
4962c51a MS |
21042 | /* Similarly for group relocations. */ |
21043 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
21044 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
21045 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 21046 | return FALSE; |
4962c51a | 21047 | |
79947c54 CD |
21048 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
21049 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
21050 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
21051 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
21052 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
21053 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
21054 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
21055 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
21056 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 21057 | return FALSE; |
79947c54 | 21058 | |
c921be7d | 21059 | return TRUE; |
a737bd4d | 21060 | } |
0ffdc86c NC |
21061 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
21062 | ||
21063 | #ifdef OBJ_ELF | |
404ff6b5 | 21064 | |
c19d1205 ZW |
21065 | const char * |
21066 | elf32_arm_target_format (void) | |
404ff6b5 | 21067 | { |
c19d1205 ZW |
21068 | #ifdef TE_SYMBIAN |
21069 | return (target_big_endian | |
21070 | ? "elf32-bigarm-symbian" | |
21071 | : "elf32-littlearm-symbian"); | |
21072 | #elif defined (TE_VXWORKS) | |
21073 | return (target_big_endian | |
21074 | ? "elf32-bigarm-vxworks" | |
21075 | : "elf32-littlearm-vxworks"); | |
21076 | #else | |
21077 | if (target_big_endian) | |
21078 | return "elf32-bigarm"; | |
21079 | else | |
21080 | return "elf32-littlearm"; | |
21081 | #endif | |
404ff6b5 AH |
21082 | } |
21083 | ||
c19d1205 ZW |
21084 | void |
21085 | armelf_frob_symbol (symbolS * symp, | |
21086 | int * puntp) | |
404ff6b5 | 21087 | { |
c19d1205 ZW |
21088 | elf_frob_symbol (symp, puntp); |
21089 | } | |
21090 | #endif | |
404ff6b5 | 21091 | |
c19d1205 | 21092 | /* MD interface: Finalization. */ |
a737bd4d | 21093 | |
c19d1205 ZW |
21094 | void |
21095 | arm_cleanup (void) | |
21096 | { | |
21097 | literal_pool * pool; | |
a737bd4d | 21098 | |
e07e6e58 NC |
21099 | /* Ensure that all the IT blocks are properly closed. */ |
21100 | check_it_blocks_finished (); | |
21101 | ||
c19d1205 ZW |
21102 | for (pool = list_of_pools; pool; pool = pool->next) |
21103 | { | |
5f4273c7 | 21104 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
21105 | subseg_set (pool->section, pool->sub_section); |
21106 | #ifdef OBJ_ELF | |
21107 | arm_elf_change_section (); | |
21108 | #endif | |
21109 | s_ltorg (0); | |
21110 | } | |
404ff6b5 AH |
21111 | } |
21112 | ||
cd000bff DJ |
21113 | #ifdef OBJ_ELF |
21114 | /* Remove any excess mapping symbols generated for alignment frags in | |
21115 | SEC. We may have created a mapping symbol before a zero byte | |
21116 | alignment; remove it if there's a mapping symbol after the | |
21117 | alignment. */ | |
21118 | static void | |
21119 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
21120 | void *dummy ATTRIBUTE_UNUSED) | |
21121 | { | |
21122 | segment_info_type *seginfo = seg_info (sec); | |
21123 | fragS *fragp; | |
21124 | ||
21125 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
21126 | return; | |
21127 | ||
21128 | for (fragp = seginfo->frchainP->frch_root; | |
21129 | fragp != NULL; | |
21130 | fragp = fragp->fr_next) | |
21131 | { | |
21132 | symbolS *sym = fragp->tc_frag_data.last_map; | |
21133 | fragS *next = fragp->fr_next; | |
21134 | ||
21135 | /* Variable-sized frags have been converted to fixed size by | |
21136 | this point. But if this was variable-sized to start with, | |
21137 | there will be a fixed-size frag after it. So don't handle | |
21138 | next == NULL. */ | |
21139 | if (sym == NULL || next == NULL) | |
21140 | continue; | |
21141 | ||
21142 | if (S_GET_VALUE (sym) < next->fr_address) | |
21143 | /* Not at the end of this frag. */ | |
21144 | continue; | |
21145 | know (S_GET_VALUE (sym) == next->fr_address); | |
21146 | ||
21147 | do | |
21148 | { | |
21149 | if (next->tc_frag_data.first_map != NULL) | |
21150 | { | |
21151 | /* Next frag starts with a mapping symbol. Discard this | |
21152 | one. */ | |
21153 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
21154 | break; | |
21155 | } | |
21156 | ||
21157 | if (next->fr_next == NULL) | |
21158 | { | |
21159 | /* This mapping symbol is at the end of the section. Discard | |
21160 | it. */ | |
21161 | know (next->fr_fix == 0 && next->fr_var == 0); | |
21162 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
21163 | break; | |
21164 | } | |
21165 | ||
21166 | /* As long as we have empty frags without any mapping symbols, | |
21167 | keep looking. */ | |
21168 | /* If the next frag is non-empty and does not start with a | |
21169 | mapping symbol, then this mapping symbol is required. */ | |
21170 | if (next->fr_address != next->fr_next->fr_address) | |
21171 | break; | |
21172 | ||
21173 | next = next->fr_next; | |
21174 | } | |
21175 | while (next != NULL); | |
21176 | } | |
21177 | } | |
21178 | #endif | |
21179 | ||
c19d1205 ZW |
21180 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
21181 | ARM ones. */ | |
404ff6b5 | 21182 | |
c19d1205 ZW |
21183 | void |
21184 | arm_adjust_symtab (void) | |
404ff6b5 | 21185 | { |
c19d1205 ZW |
21186 | #ifdef OBJ_COFF |
21187 | symbolS * sym; | |
404ff6b5 | 21188 | |
c19d1205 ZW |
21189 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
21190 | { | |
21191 | if (ARM_IS_THUMB (sym)) | |
21192 | { | |
21193 | if (THUMB_IS_FUNC (sym)) | |
21194 | { | |
21195 | /* Mark the symbol as a Thumb function. */ | |
21196 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
21197 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
21198 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 21199 | |
c19d1205 ZW |
21200 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
21201 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
21202 | else | |
21203 | as_bad (_("%s: unexpected function type: %d"), | |
21204 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
21205 | } | |
21206 | else switch (S_GET_STORAGE_CLASS (sym)) | |
21207 | { | |
21208 | case C_EXT: | |
21209 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
21210 | break; | |
21211 | case C_STAT: | |
21212 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
21213 | break; | |
21214 | case C_LABEL: | |
21215 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
21216 | break; | |
21217 | default: | |
21218 | /* Do nothing. */ | |
21219 | break; | |
21220 | } | |
21221 | } | |
a737bd4d | 21222 | |
c19d1205 ZW |
21223 | if (ARM_IS_INTERWORK (sym)) |
21224 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 21225 | } |
c19d1205 ZW |
21226 | #endif |
21227 | #ifdef OBJ_ELF | |
21228 | symbolS * sym; | |
21229 | char bind; | |
404ff6b5 | 21230 | |
c19d1205 | 21231 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 21232 | { |
c19d1205 ZW |
21233 | if (ARM_IS_THUMB (sym)) |
21234 | { | |
21235 | elf_symbol_type * elf_sym; | |
404ff6b5 | 21236 | |
c19d1205 ZW |
21237 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
21238 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 21239 | |
b0796911 PB |
21240 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
21241 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
21242 | { |
21243 | /* If it's a .thumb_func, declare it as so, | |
21244 | otherwise tag label as .code 16. */ | |
21245 | if (THUMB_IS_FUNC (sym)) | |
21246 | elf_sym->internal_elf_sym.st_info = | |
21247 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
3ba67470 | 21248 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
21249 | elf_sym->internal_elf_sym.st_info = |
21250 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
21251 | } | |
21252 | } | |
21253 | } | |
cd000bff DJ |
21254 | |
21255 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
21256 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
c19d1205 | 21257 | #endif |
404ff6b5 AH |
21258 | } |
21259 | ||
c19d1205 | 21260 | /* MD interface: Initialization. */ |
404ff6b5 | 21261 | |
a737bd4d | 21262 | static void |
c19d1205 | 21263 | set_constant_flonums (void) |
a737bd4d | 21264 | { |
c19d1205 | 21265 | int i; |
404ff6b5 | 21266 | |
c19d1205 ZW |
21267 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
21268 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
21269 | abort (); | |
a737bd4d | 21270 | } |
404ff6b5 | 21271 | |
3e9e4fcf JB |
21272 | /* Auto-select Thumb mode if it's the only available instruction set for the |
21273 | given architecture. */ | |
21274 | ||
21275 | static void | |
21276 | autoselect_thumb_from_cpu_variant (void) | |
21277 | { | |
21278 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
21279 | opcode_select (16); | |
21280 | } | |
21281 | ||
c19d1205 ZW |
21282 | void |
21283 | md_begin (void) | |
a737bd4d | 21284 | { |
c19d1205 ZW |
21285 | unsigned mach; |
21286 | unsigned int i; | |
404ff6b5 | 21287 | |
c19d1205 ZW |
21288 | if ( (arm_ops_hsh = hash_new ()) == NULL |
21289 | || (arm_cond_hsh = hash_new ()) == NULL | |
21290 | || (arm_shift_hsh = hash_new ()) == NULL | |
21291 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 21292 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 21293 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
21294 | || (arm_reloc_hsh = hash_new ()) == NULL |
21295 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
21296 | as_fatal (_("virtual memory exhausted")); |
21297 | ||
21298 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
5a49b8ac | 21299 | hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i)); |
c19d1205 | 21300 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
5a49b8ac | 21301 | hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i)); |
c19d1205 | 21302 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 21303 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 21304 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
5a49b8ac | 21305 | hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i)); |
62b3e311 | 21306 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
5a49b8ac | 21307 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i)); |
c19d1205 | 21308 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 21309 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
21310 | for (i = 0; |
21311 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
21312 | i++) | |
21313 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template, | |
5a49b8ac | 21314 | (void *) (barrier_opt_names + i)); |
c19d1205 ZW |
21315 | #ifdef OBJ_ELF |
21316 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
5a49b8ac | 21317 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i)); |
c19d1205 ZW |
21318 | #endif |
21319 | ||
21320 | set_constant_flonums (); | |
404ff6b5 | 21321 | |
c19d1205 ZW |
21322 | /* Set the cpu variant based on the command-line options. We prefer |
21323 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
21324 | -mfpu= over any other way of setting the floating point unit. | |
21325 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 21326 | if (legacy_cpu) |
404ff6b5 | 21327 | { |
e74cfd16 | 21328 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
21329 | as_bad (_("use of old and new-style options to set CPU type")); |
21330 | ||
21331 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 21332 | } |
e74cfd16 | 21333 | else if (!mcpu_cpu_opt) |
c19d1205 | 21334 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 21335 | |
e74cfd16 | 21336 | if (legacy_fpu) |
c19d1205 | 21337 | { |
e74cfd16 | 21338 | if (mfpu_opt) |
c19d1205 | 21339 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
21340 | |
21341 | mfpu_opt = legacy_fpu; | |
21342 | } | |
e74cfd16 | 21343 | else if (!mfpu_opt) |
03b1477f | 21344 | { |
45eb4c1b NS |
21345 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
21346 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
21347 | /* Some environments specify a default FPU. If they don't, infer it |
21348 | from the processor. */ | |
e74cfd16 | 21349 | if (mcpu_fpu_opt) |
03b1477f RE |
21350 | mfpu_opt = mcpu_fpu_opt; |
21351 | else | |
21352 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 21353 | #else |
e74cfd16 | 21354 | mfpu_opt = &fpu_default; |
39c2da32 | 21355 | #endif |
03b1477f RE |
21356 | } |
21357 | ||
e74cfd16 | 21358 | if (!mfpu_opt) |
03b1477f | 21359 | { |
493cb6ef | 21360 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 21361 | mfpu_opt = &fpu_default; |
493cb6ef | 21362 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 21363 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 21364 | else |
e74cfd16 | 21365 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
21366 | } |
21367 | ||
ee065d83 | 21368 | #ifdef CPU_DEFAULT |
e74cfd16 | 21369 | if (!mcpu_cpu_opt) |
ee065d83 | 21370 | { |
e74cfd16 PB |
21371 | mcpu_cpu_opt = &cpu_default; |
21372 | selected_cpu = cpu_default; | |
ee065d83 | 21373 | } |
e74cfd16 PB |
21374 | #else |
21375 | if (mcpu_cpu_opt) | |
21376 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 21377 | else |
e74cfd16 | 21378 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 21379 | #endif |
03b1477f | 21380 | |
e74cfd16 | 21381 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 21382 | |
3e9e4fcf JB |
21383 | autoselect_thumb_from_cpu_variant (); |
21384 | ||
e74cfd16 | 21385 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 21386 | |
f17c130b | 21387 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 21388 | { |
7cc69913 NC |
21389 | unsigned int flags = 0; |
21390 | ||
21391 | #if defined OBJ_ELF | |
21392 | flags = meabi_flags; | |
d507cf36 PB |
21393 | |
21394 | switch (meabi_flags) | |
33a392fb | 21395 | { |
d507cf36 | 21396 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 21397 | #endif |
d507cf36 PB |
21398 | /* Set the flags in the private structure. */ |
21399 | if (uses_apcs_26) flags |= F_APCS26; | |
21400 | if (support_interwork) flags |= F_INTERWORK; | |
21401 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 21402 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 21403 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
21404 | flags |= F_SOFT_FLOAT; |
21405 | ||
d507cf36 PB |
21406 | switch (mfloat_abi_opt) |
21407 | { | |
21408 | case ARM_FLOAT_ABI_SOFT: | |
21409 | case ARM_FLOAT_ABI_SOFTFP: | |
21410 | flags |= F_SOFT_FLOAT; | |
21411 | break; | |
33a392fb | 21412 | |
d507cf36 PB |
21413 | case ARM_FLOAT_ABI_HARD: |
21414 | if (flags & F_SOFT_FLOAT) | |
21415 | as_bad (_("hard-float conflicts with specified fpu")); | |
21416 | break; | |
21417 | } | |
03b1477f | 21418 | |
e74cfd16 PB |
21419 | /* Using pure-endian doubles (even if soft-float). */ |
21420 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 21421 | flags |= F_VFP_FLOAT; |
f17c130b | 21422 | |
fde78edd | 21423 | #if defined OBJ_ELF |
e74cfd16 | 21424 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 21425 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
21426 | break; |
21427 | ||
8cb51566 | 21428 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 21429 | case EF_ARM_EABI_VER5: |
c19d1205 | 21430 | /* No additional flags to set. */ |
d507cf36 PB |
21431 | break; |
21432 | ||
21433 | default: | |
21434 | abort (); | |
21435 | } | |
7cc69913 | 21436 | #endif |
b99bd4ef NC |
21437 | bfd_set_private_flags (stdoutput, flags); |
21438 | ||
21439 | /* We have run out flags in the COFF header to encode the | |
21440 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 21441 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
21442 | if (atpcs) |
21443 | { | |
21444 | asection * sec; | |
21445 | ||
21446 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
21447 | ||
21448 | if (sec != NULL) | |
21449 | { | |
21450 | bfd_set_section_flags | |
21451 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
21452 | bfd_set_section_size (stdoutput, sec, 0); | |
21453 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
21454 | } | |
21455 | } | |
7cc69913 | 21456 | } |
f17c130b | 21457 | #endif |
b99bd4ef NC |
21458 | |
21459 | /* Record the CPU type as well. */ | |
2d447fca JM |
21460 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
21461 | mach = bfd_mach_arm_iWMMXt2; | |
21462 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 21463 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 21464 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 21465 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 21466 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 21467 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 21468 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 21469 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 21470 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 21471 | { |
e74cfd16 | 21472 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21473 | mach = bfd_mach_arm_5T; |
21474 | else | |
21475 | mach = bfd_mach_arm_5; | |
21476 | } | |
e74cfd16 | 21477 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 21478 | { |
e74cfd16 | 21479 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21480 | mach = bfd_mach_arm_4T; |
21481 | else | |
21482 | mach = bfd_mach_arm_4; | |
21483 | } | |
e74cfd16 | 21484 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 21485 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
21486 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
21487 | mach = bfd_mach_arm_3; | |
21488 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
21489 | mach = bfd_mach_arm_2a; | |
21490 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
21491 | mach = bfd_mach_arm_2; | |
21492 | else | |
21493 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
21494 | |
21495 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
21496 | } | |
21497 | ||
c19d1205 | 21498 | /* Command line processing. */ |
b99bd4ef | 21499 | |
c19d1205 ZW |
21500 | /* md_parse_option |
21501 | Invocation line includes a switch not recognized by the base assembler. | |
21502 | See if it's a processor-specific option. | |
b99bd4ef | 21503 | |
c19d1205 ZW |
21504 | This routine is somewhat complicated by the need for backwards |
21505 | compatibility (since older releases of gcc can't be changed). | |
21506 | The new options try to make the interface as compatible as | |
21507 | possible with GCC. | |
b99bd4ef | 21508 | |
c19d1205 | 21509 | New options (supported) are: |
b99bd4ef | 21510 | |
c19d1205 ZW |
21511 | -mcpu=<cpu name> Assemble for selected processor |
21512 | -march=<architecture name> Assemble for selected architecture | |
21513 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
21514 | -EB/-mbig-endian Big-endian | |
21515 | -EL/-mlittle-endian Little-endian | |
21516 | -k Generate PIC code | |
21517 | -mthumb Start in Thumb mode | |
21518 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 21519 | |
278df34e | 21520 | -m[no-]warn-deprecated Warn about deprecated features |
267bf995 | 21521 | |
c19d1205 | 21522 | For now we will also provide support for: |
b99bd4ef | 21523 | |
c19d1205 ZW |
21524 | -mapcs-32 32-bit Program counter |
21525 | -mapcs-26 26-bit Program counter | |
21526 | -macps-float Floats passed in FP registers | |
21527 | -mapcs-reentrant Reentrant code | |
21528 | -matpcs | |
21529 | (sometime these will probably be replaced with -mapcs=<list of options> | |
21530 | and -matpcs=<list of options>) | |
b99bd4ef | 21531 | |
c19d1205 ZW |
21532 | The remaining options are only supported for back-wards compatibility. |
21533 | Cpu variants, the arm part is optional: | |
21534 | -m[arm]1 Currently not supported. | |
21535 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
21536 | -m[arm]3 Arm 3 processor | |
21537 | -m[arm]6[xx], Arm 6 processors | |
21538 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
21539 | -m[arm]8[10] Arm 8 processors | |
21540 | -m[arm]9[20][tdmi] Arm 9 processors | |
21541 | -mstrongarm[110[0]] StrongARM processors | |
21542 | -mxscale XScale processors | |
21543 | -m[arm]v[2345[t[e]]] Arm architectures | |
21544 | -mall All (except the ARM1) | |
21545 | FP variants: | |
21546 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
21547 | -mfpe-old (No float load/store multiples) | |
21548 | -mvfpxd VFP Single precision | |
21549 | -mvfp All VFP | |
21550 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 21551 | |
c19d1205 ZW |
21552 | The following CPU names are recognized: |
21553 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
21554 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
21555 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
21556 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
21557 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
21558 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
21559 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 21560 | |
c19d1205 | 21561 | */ |
b99bd4ef | 21562 | |
c19d1205 | 21563 | const char * md_shortopts = "m:k"; |
b99bd4ef | 21564 | |
c19d1205 ZW |
21565 | #ifdef ARM_BI_ENDIAN |
21566 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
21567 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 21568 | #else |
c19d1205 ZW |
21569 | #if TARGET_BYTES_BIG_ENDIAN |
21570 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 21571 | #else |
c19d1205 ZW |
21572 | #define OPTION_EL (OPTION_MD_BASE + 1) |
21573 | #endif | |
b99bd4ef | 21574 | #endif |
845b51d6 | 21575 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 21576 | |
c19d1205 | 21577 | struct option md_longopts[] = |
b99bd4ef | 21578 | { |
c19d1205 ZW |
21579 | #ifdef OPTION_EB |
21580 | {"EB", no_argument, NULL, OPTION_EB}, | |
21581 | #endif | |
21582 | #ifdef OPTION_EL | |
21583 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 21584 | #endif |
845b51d6 | 21585 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
21586 | {NULL, no_argument, NULL, 0} |
21587 | }; | |
b99bd4ef | 21588 | |
c19d1205 | 21589 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 21590 | |
c19d1205 | 21591 | struct arm_option_table |
b99bd4ef | 21592 | { |
c19d1205 ZW |
21593 | char *option; /* Option name to match. */ |
21594 | char *help; /* Help information. */ | |
21595 | int *var; /* Variable to change. */ | |
21596 | int value; /* What to change it to. */ | |
21597 | char *deprecated; /* If non-null, print this message. */ | |
21598 | }; | |
b99bd4ef | 21599 | |
c19d1205 ZW |
21600 | struct arm_option_table arm_opts[] = |
21601 | { | |
21602 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
21603 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
21604 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
21605 | &support_interwork, 1, NULL}, | |
21606 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
21607 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
21608 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
21609 | 1, NULL}, | |
21610 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
21611 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
21612 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
21613 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
21614 | NULL}, | |
b99bd4ef | 21615 | |
c19d1205 ZW |
21616 | /* These are recognized by the assembler, but have no affect on code. */ |
21617 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
21618 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
21619 | |
21620 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
21621 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
21622 | &warn_on_deprecated, 0, NULL}, | |
e74cfd16 PB |
21623 | {NULL, NULL, NULL, 0, NULL} |
21624 | }; | |
21625 | ||
21626 | struct arm_legacy_option_table | |
21627 | { | |
21628 | char *option; /* Option name to match. */ | |
21629 | const arm_feature_set **var; /* Variable to change. */ | |
21630 | const arm_feature_set value; /* What to change it to. */ | |
21631 | char *deprecated; /* If non-null, print this message. */ | |
21632 | }; | |
b99bd4ef | 21633 | |
e74cfd16 PB |
21634 | const struct arm_legacy_option_table arm_legacy_opts[] = |
21635 | { | |
c19d1205 ZW |
21636 | /* DON'T add any new processors to this list -- we want the whole list |
21637 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
21638 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
21639 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
21640 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21641 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21642 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21643 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21644 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21645 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21646 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21647 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21648 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21649 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21650 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21651 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21652 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21653 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21654 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21655 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21656 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21657 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21658 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21659 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21660 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21661 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21662 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21663 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21664 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21665 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21666 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21667 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21668 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21669 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21670 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21671 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21672 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21673 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21674 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21675 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21676 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21677 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21678 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21679 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21680 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21681 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21682 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21683 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21684 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21685 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21686 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21687 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21688 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21689 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21690 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21691 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21692 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21693 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21694 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21695 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21696 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21697 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21698 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21699 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21700 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21701 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21702 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21703 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21704 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21705 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21706 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
21707 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 21708 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 21709 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21710 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 21711 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21712 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
21713 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
21714 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
21715 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 21716 | |
c19d1205 | 21717 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21718 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
21719 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
21720 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21721 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21722 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21723 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21724 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21725 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21726 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21727 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21728 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21729 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21730 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21731 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21732 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21733 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21734 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
21735 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 21736 | |
c19d1205 | 21737 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21738 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
21739 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
21740 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
21741 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 21742 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 21743 | |
e74cfd16 | 21744 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 21745 | }; |
7ed4c4c5 | 21746 | |
c19d1205 | 21747 | struct arm_cpu_option_table |
7ed4c4c5 | 21748 | { |
c19d1205 | 21749 | char *name; |
e74cfd16 | 21750 | const arm_feature_set value; |
c19d1205 ZW |
21751 | /* For some CPUs we assume an FPU unless the user explicitly sets |
21752 | -mfpu=... */ | |
e74cfd16 | 21753 | const arm_feature_set default_fpu; |
ee065d83 PB |
21754 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
21755 | case. */ | |
21756 | const char *canonical_name; | |
c19d1205 | 21757 | }; |
7ed4c4c5 | 21758 | |
c19d1205 ZW |
21759 | /* This list should, at a minimum, contain all the cpu names |
21760 | recognized by GCC. */ | |
e74cfd16 | 21761 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 21762 | { |
ee065d83 PB |
21763 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
21764 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
21765 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
21766 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21767 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21768 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21769 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21770 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21771 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21772 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21773 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21774 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21775 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21776 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21777 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21778 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21779 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21780 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21781 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21782 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21783 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21784 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21785 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21786 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21787 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21788 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21789 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21790 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21791 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21792 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21793 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21794 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21795 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21796 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21797 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21798 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21799 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21800 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21801 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21802 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
21803 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21804 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21805 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21806 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
7fac0536 NC |
21807 | {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, |
21808 | {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
21809 | /* For V5 or later processors we default to using VFP; but the user |
21810 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
21811 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
21812 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21813 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21814 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21815 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
21816 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21817 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
21818 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21819 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21820 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
21821 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21822 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21823 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21824 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21825 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21826 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
21827 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21828 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21829 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21830 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
21831 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
7fac0536 NC |
21832 | {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL}, |
21833 | {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
ee065d83 PB |
21834 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, |
21835 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
21836 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
21837 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
21838 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
21839 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
21840 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
21841 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
21842 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
21843 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
e07e6e58 | 21844 | {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
5287ad62 | 21845 | | FPU_NEON_EXT_V1), |
15290f0a | 21846 | NULL}, |
e07e6e58 | 21847 | {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
15290f0a | 21848 | | FPU_NEON_EXT_V1), |
5287ad62 | 21849 | NULL}, |
62b3e311 PB |
21850 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, |
21851 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, | |
7e806470 | 21852 | {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL}, |
5b19eaba | 21853 | {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL}, |
c19d1205 | 21854 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 21855 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21856 | /* ??? iwmmxt is not a processor. */ |
ee065d83 | 21857 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
2d447fca | 21858 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL}, |
ee065d83 | 21859 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21860 | /* Maverick */ |
e07e6e58 | 21861 | {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
e74cfd16 | 21862 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} |
c19d1205 | 21863 | }; |
7ed4c4c5 | 21864 | |
c19d1205 | 21865 | struct arm_arch_option_table |
7ed4c4c5 | 21866 | { |
c19d1205 | 21867 | char *name; |
e74cfd16 PB |
21868 | const arm_feature_set value; |
21869 | const arm_feature_set default_fpu; | |
c19d1205 | 21870 | }; |
7ed4c4c5 | 21871 | |
c19d1205 ZW |
21872 | /* This list should, at a minimum, contain all the architecture names |
21873 | recognized by GCC. */ | |
e74cfd16 | 21874 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
21875 | { |
21876 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
21877 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
21878 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
21879 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21880 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21881 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
21882 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
21883 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
21884 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
21885 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
21886 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
21887 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
21888 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
21889 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
21890 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
21891 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
21892 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
21893 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21894 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21895 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
21896 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
21897 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
21898 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
21899 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
21900 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
21901 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
7e806470 | 21902 | {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP}, |
62b3e311 | 21903 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
c450d570 PB |
21904 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
21905 | Accept the non-dashed form for compatibility with old toolchains. */ | |
62b3e311 PB |
21906 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21907 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21908 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c450d570 PB |
21909 | {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21910 | {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21911 | {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
21912 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
21913 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
2d447fca | 21914 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP}, |
e74cfd16 | 21915 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 21916 | }; |
7ed4c4c5 | 21917 | |
c19d1205 | 21918 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 21919 | struct arm_option_cpu_value_table |
c19d1205 ZW |
21920 | { |
21921 | char *name; | |
e74cfd16 | 21922 | const arm_feature_set value; |
c19d1205 | 21923 | }; |
7ed4c4c5 | 21924 | |
e74cfd16 | 21925 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 21926 | { |
e74cfd16 PB |
21927 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
21928 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
21929 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
2d447fca | 21930 | {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)}, |
e74cfd16 | 21931 | {NULL, ARM_ARCH_NONE} |
c19d1205 | 21932 | }; |
7ed4c4c5 | 21933 | |
c19d1205 ZW |
21934 | /* This list should, at a minimum, contain all the fpu names |
21935 | recognized by GCC. */ | |
e74cfd16 | 21936 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
21937 | { |
21938 | {"softfpa", FPU_NONE}, | |
21939 | {"fpe", FPU_ARCH_FPE}, | |
21940 | {"fpe2", FPU_ARCH_FPE}, | |
21941 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
21942 | {"fpa", FPU_ARCH_FPA}, | |
21943 | {"fpa10", FPU_ARCH_FPA}, | |
21944 | {"fpa11", FPU_ARCH_FPA}, | |
21945 | {"arm7500fe", FPU_ARCH_FPA}, | |
21946 | {"softvfp", FPU_ARCH_VFP}, | |
21947 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
21948 | {"vfp", FPU_ARCH_VFP_V2}, | |
21949 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 21950 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
21951 | {"vfp10", FPU_ARCH_VFP_V2}, |
21952 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
21953 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
21954 | {"vfpv2", FPU_ARCH_VFP_V2}, |
21955 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
21956 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, | |
c19d1205 ZW |
21957 | {"arm1020t", FPU_ARCH_VFP_V1}, |
21958 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
21959 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
21960 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
21961 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 21962 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 21963 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
e74cfd16 PB |
21964 | {NULL, ARM_ARCH_NONE} |
21965 | }; | |
21966 | ||
21967 | struct arm_option_value_table | |
21968 | { | |
21969 | char *name; | |
21970 | long value; | |
c19d1205 | 21971 | }; |
7ed4c4c5 | 21972 | |
e74cfd16 | 21973 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
21974 | { |
21975 | {"hard", ARM_FLOAT_ABI_HARD}, | |
21976 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
21977 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 21978 | {NULL, 0} |
c19d1205 | 21979 | }; |
7ed4c4c5 | 21980 | |
c19d1205 | 21981 | #ifdef OBJ_ELF |
3a4a14e9 | 21982 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 21983 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
21984 | { |
21985 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
21986 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 21987 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 21988 | {NULL, 0} |
c19d1205 ZW |
21989 | }; |
21990 | #endif | |
7ed4c4c5 | 21991 | |
c19d1205 ZW |
21992 | struct arm_long_option_table |
21993 | { | |
21994 | char * option; /* Substring to match. */ | |
21995 | char * help; /* Help information. */ | |
21996 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
21997 | char * deprecated; /* If non-null, print this message. */ | |
21998 | }; | |
7ed4c4c5 | 21999 | |
c921be7d | 22000 | static bfd_boolean |
e74cfd16 | 22001 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 22002 | { |
e74cfd16 PB |
22003 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
22004 | ||
22005 | /* Copy the feature set, so that we can modify it. */ | |
22006 | *ext_set = **opt_p; | |
22007 | *opt_p = ext_set; | |
22008 | ||
c19d1205 | 22009 | while (str != NULL && *str != 0) |
7ed4c4c5 | 22010 | { |
e74cfd16 | 22011 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
22012 | char * ext; |
22013 | int optlen; | |
7ed4c4c5 | 22014 | |
c19d1205 ZW |
22015 | if (*str != '+') |
22016 | { | |
22017 | as_bad (_("invalid architectural extension")); | |
c921be7d | 22018 | return FALSE; |
c19d1205 | 22019 | } |
7ed4c4c5 | 22020 | |
c19d1205 ZW |
22021 | str++; |
22022 | ext = strchr (str, '+'); | |
7ed4c4c5 | 22023 | |
c19d1205 ZW |
22024 | if (ext != NULL) |
22025 | optlen = ext - str; | |
22026 | else | |
22027 | optlen = strlen (str); | |
7ed4c4c5 | 22028 | |
c19d1205 ZW |
22029 | if (optlen == 0) |
22030 | { | |
22031 | as_bad (_("missing architectural extension")); | |
c921be7d | 22032 | return FALSE; |
c19d1205 | 22033 | } |
7ed4c4c5 | 22034 | |
c19d1205 ZW |
22035 | for (opt = arm_extensions; opt->name != NULL; opt++) |
22036 | if (strncmp (opt->name, str, optlen) == 0) | |
22037 | { | |
e74cfd16 | 22038 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
22039 | break; |
22040 | } | |
7ed4c4c5 | 22041 | |
c19d1205 ZW |
22042 | if (opt->name == NULL) |
22043 | { | |
5f4273c7 | 22044 | as_bad (_("unknown architectural extension `%s'"), str); |
c921be7d | 22045 | return FALSE; |
c19d1205 | 22046 | } |
7ed4c4c5 | 22047 | |
c19d1205 ZW |
22048 | str = ext; |
22049 | }; | |
7ed4c4c5 | 22050 | |
c921be7d | 22051 | return TRUE; |
c19d1205 | 22052 | } |
7ed4c4c5 | 22053 | |
c921be7d | 22054 | static bfd_boolean |
c19d1205 | 22055 | arm_parse_cpu (char * str) |
7ed4c4c5 | 22056 | { |
e74cfd16 | 22057 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
22058 | char * ext = strchr (str, '+'); |
22059 | int optlen; | |
7ed4c4c5 | 22060 | |
c19d1205 ZW |
22061 | if (ext != NULL) |
22062 | optlen = ext - str; | |
7ed4c4c5 | 22063 | else |
c19d1205 | 22064 | optlen = strlen (str); |
7ed4c4c5 | 22065 | |
c19d1205 | 22066 | if (optlen == 0) |
7ed4c4c5 | 22067 | { |
c19d1205 | 22068 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 22069 | return FALSE; |
7ed4c4c5 NC |
22070 | } |
22071 | ||
c19d1205 ZW |
22072 | for (opt = arm_cpus; opt->name != NULL; opt++) |
22073 | if (strncmp (opt->name, str, optlen) == 0) | |
22074 | { | |
e74cfd16 PB |
22075 | mcpu_cpu_opt = &opt->value; |
22076 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 22077 | if (opt->canonical_name) |
5f4273c7 | 22078 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22079 | else |
22080 | { | |
22081 | int i; | |
c921be7d | 22082 | |
ee065d83 PB |
22083 | for (i = 0; i < optlen; i++) |
22084 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22085 | selected_cpu_name[i] = 0; | |
22086 | } | |
7ed4c4c5 | 22087 | |
c19d1205 ZW |
22088 | if (ext != NULL) |
22089 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 22090 | |
c921be7d | 22091 | return TRUE; |
c19d1205 | 22092 | } |
7ed4c4c5 | 22093 | |
c19d1205 | 22094 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 22095 | return FALSE; |
7ed4c4c5 NC |
22096 | } |
22097 | ||
c921be7d | 22098 | static bfd_boolean |
c19d1205 | 22099 | arm_parse_arch (char * str) |
7ed4c4c5 | 22100 | { |
e74cfd16 | 22101 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
22102 | char *ext = strchr (str, '+'); |
22103 | int optlen; | |
7ed4c4c5 | 22104 | |
c19d1205 ZW |
22105 | if (ext != NULL) |
22106 | optlen = ext - str; | |
7ed4c4c5 | 22107 | else |
c19d1205 | 22108 | optlen = strlen (str); |
7ed4c4c5 | 22109 | |
c19d1205 | 22110 | if (optlen == 0) |
7ed4c4c5 | 22111 | { |
c19d1205 | 22112 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 22113 | return FALSE; |
7ed4c4c5 NC |
22114 | } |
22115 | ||
c19d1205 ZW |
22116 | for (opt = arm_archs; opt->name != NULL; opt++) |
22117 | if (streq (opt->name, str)) | |
22118 | { | |
e74cfd16 PB |
22119 | march_cpu_opt = &opt->value; |
22120 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 22121 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 22122 | |
c19d1205 ZW |
22123 | if (ext != NULL) |
22124 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 22125 | |
c921be7d | 22126 | return TRUE; |
c19d1205 ZW |
22127 | } |
22128 | ||
22129 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 22130 | return FALSE; |
7ed4c4c5 | 22131 | } |
eb043451 | 22132 | |
c921be7d | 22133 | static bfd_boolean |
c19d1205 ZW |
22134 | arm_parse_fpu (char * str) |
22135 | { | |
e74cfd16 | 22136 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 22137 | |
c19d1205 ZW |
22138 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22139 | if (streq (opt->name, str)) | |
22140 | { | |
e74cfd16 | 22141 | mfpu_opt = &opt->value; |
c921be7d | 22142 | return TRUE; |
c19d1205 | 22143 | } |
b99bd4ef | 22144 | |
c19d1205 | 22145 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 22146 | return FALSE; |
c19d1205 ZW |
22147 | } |
22148 | ||
c921be7d | 22149 | static bfd_boolean |
c19d1205 | 22150 | arm_parse_float_abi (char * str) |
b99bd4ef | 22151 | { |
e74cfd16 | 22152 | const struct arm_option_value_table * opt; |
b99bd4ef | 22153 | |
c19d1205 ZW |
22154 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
22155 | if (streq (opt->name, str)) | |
22156 | { | |
22157 | mfloat_abi_opt = opt->value; | |
c921be7d | 22158 | return TRUE; |
c19d1205 | 22159 | } |
cc8a6dd0 | 22160 | |
c19d1205 | 22161 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 22162 | return FALSE; |
c19d1205 | 22163 | } |
b99bd4ef | 22164 | |
c19d1205 | 22165 | #ifdef OBJ_ELF |
c921be7d | 22166 | static bfd_boolean |
c19d1205 ZW |
22167 | arm_parse_eabi (char * str) |
22168 | { | |
e74cfd16 | 22169 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 22170 | |
c19d1205 ZW |
22171 | for (opt = arm_eabis; opt->name != NULL; opt++) |
22172 | if (streq (opt->name, str)) | |
22173 | { | |
22174 | meabi_flags = opt->value; | |
c921be7d | 22175 | return TRUE; |
c19d1205 ZW |
22176 | } |
22177 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 22178 | return FALSE; |
c19d1205 ZW |
22179 | } |
22180 | #endif | |
cc8a6dd0 | 22181 | |
c921be7d | 22182 | static bfd_boolean |
e07e6e58 NC |
22183 | arm_parse_it_mode (char * str) |
22184 | { | |
c921be7d | 22185 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
22186 | |
22187 | if (streq ("arm", str)) | |
22188 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
22189 | else if (streq ("thumb", str)) | |
22190 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
22191 | else if (streq ("always", str)) | |
22192 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
22193 | else if (streq ("never", str)) | |
22194 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
22195 | else | |
22196 | { | |
22197 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
22198 | "arm, thumb, always, or never."), str); | |
c921be7d | 22199 | ret = FALSE; |
e07e6e58 NC |
22200 | } |
22201 | ||
22202 | return ret; | |
22203 | } | |
22204 | ||
c19d1205 ZW |
22205 | struct arm_long_option_table arm_long_opts[] = |
22206 | { | |
22207 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
22208 | arm_parse_cpu, NULL}, | |
22209 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
22210 | arm_parse_arch, NULL}, | |
22211 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
22212 | arm_parse_fpu, NULL}, | |
22213 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
22214 | arm_parse_float_abi, NULL}, | |
22215 | #ifdef OBJ_ELF | |
7fac0536 | 22216 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
22217 | arm_parse_eabi, NULL}, |
22218 | #endif | |
e07e6e58 NC |
22219 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
22220 | arm_parse_it_mode, NULL}, | |
c19d1205 ZW |
22221 | {NULL, NULL, 0, NULL} |
22222 | }; | |
cc8a6dd0 | 22223 | |
c19d1205 ZW |
22224 | int |
22225 | md_parse_option (int c, char * arg) | |
22226 | { | |
22227 | struct arm_option_table *opt; | |
e74cfd16 | 22228 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 22229 | struct arm_long_option_table *lopt; |
b99bd4ef | 22230 | |
c19d1205 | 22231 | switch (c) |
b99bd4ef | 22232 | { |
c19d1205 ZW |
22233 | #ifdef OPTION_EB |
22234 | case OPTION_EB: | |
22235 | target_big_endian = 1; | |
22236 | break; | |
22237 | #endif | |
cc8a6dd0 | 22238 | |
c19d1205 ZW |
22239 | #ifdef OPTION_EL |
22240 | case OPTION_EL: | |
22241 | target_big_endian = 0; | |
22242 | break; | |
22243 | #endif | |
b99bd4ef | 22244 | |
845b51d6 PB |
22245 | case OPTION_FIX_V4BX: |
22246 | fix_v4bx = TRUE; | |
22247 | break; | |
22248 | ||
c19d1205 ZW |
22249 | case 'a': |
22250 | /* Listing option. Just ignore these, we don't support additional | |
22251 | ones. */ | |
22252 | return 0; | |
b99bd4ef | 22253 | |
c19d1205 ZW |
22254 | default: |
22255 | for (opt = arm_opts; opt->option != NULL; opt++) | |
22256 | { | |
22257 | if (c == opt->option[0] | |
22258 | && ((arg == NULL && opt->option[1] == 0) | |
22259 | || streq (arg, opt->option + 1))) | |
22260 | { | |
c19d1205 | 22261 | /* If the option is deprecated, tell the user. */ |
278df34e | 22262 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
22263 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22264 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 22265 | |
c19d1205 ZW |
22266 | if (opt->var != NULL) |
22267 | *opt->var = opt->value; | |
cc8a6dd0 | 22268 | |
c19d1205 ZW |
22269 | return 1; |
22270 | } | |
22271 | } | |
b99bd4ef | 22272 | |
e74cfd16 PB |
22273 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
22274 | { | |
22275 | if (c == fopt->option[0] | |
22276 | && ((arg == NULL && fopt->option[1] == 0) | |
22277 | || streq (arg, fopt->option + 1))) | |
22278 | { | |
e74cfd16 | 22279 | /* If the option is deprecated, tell the user. */ |
278df34e | 22280 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
22281 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22282 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
22283 | |
22284 | if (fopt->var != NULL) | |
22285 | *fopt->var = &fopt->value; | |
22286 | ||
22287 | return 1; | |
22288 | } | |
22289 | } | |
22290 | ||
c19d1205 ZW |
22291 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22292 | { | |
22293 | /* These options are expected to have an argument. */ | |
22294 | if (c == lopt->option[0] | |
22295 | && arg != NULL | |
22296 | && strncmp (arg, lopt->option + 1, | |
22297 | strlen (lopt->option + 1)) == 0) | |
22298 | { | |
c19d1205 | 22299 | /* If the option is deprecated, tell the user. */ |
278df34e | 22300 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
22301 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
22302 | _(lopt->deprecated)); | |
b99bd4ef | 22303 | |
c19d1205 ZW |
22304 | /* Call the sup-option parser. */ |
22305 | return lopt->func (arg + strlen (lopt->option) - 1); | |
22306 | } | |
22307 | } | |
a737bd4d | 22308 | |
c19d1205 ZW |
22309 | return 0; |
22310 | } | |
a394c00f | 22311 | |
c19d1205 ZW |
22312 | return 1; |
22313 | } | |
a394c00f | 22314 | |
c19d1205 ZW |
22315 | void |
22316 | md_show_usage (FILE * fp) | |
a394c00f | 22317 | { |
c19d1205 ZW |
22318 | struct arm_option_table *opt; |
22319 | struct arm_long_option_table *lopt; | |
a394c00f | 22320 | |
c19d1205 | 22321 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 22322 | |
c19d1205 ZW |
22323 | for (opt = arm_opts; opt->option != NULL; opt++) |
22324 | if (opt->help != NULL) | |
22325 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 22326 | |
c19d1205 ZW |
22327 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22328 | if (lopt->help != NULL) | |
22329 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 22330 | |
c19d1205 ZW |
22331 | #ifdef OPTION_EB |
22332 | fprintf (fp, _("\ | |
22333 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
22334 | #endif |
22335 | ||
c19d1205 ZW |
22336 | #ifdef OPTION_EL |
22337 | fprintf (fp, _("\ | |
22338 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 22339 | #endif |
845b51d6 PB |
22340 | |
22341 | fprintf (fp, _("\ | |
22342 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 22343 | } |
ee065d83 PB |
22344 | |
22345 | ||
22346 | #ifdef OBJ_ELF | |
62b3e311 PB |
22347 | typedef struct |
22348 | { | |
22349 | int val; | |
22350 | arm_feature_set flags; | |
22351 | } cpu_arch_ver_table; | |
22352 | ||
22353 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
22354 | least features first. */ | |
22355 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
22356 | { | |
22357 | {1, ARM_ARCH_V4}, | |
22358 | {2, ARM_ARCH_V4T}, | |
22359 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 22360 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
22361 | {4, ARM_ARCH_V5TE}, |
22362 | {5, ARM_ARCH_V5TEJ}, | |
22363 | {6, ARM_ARCH_V6}, | |
22364 | {7, ARM_ARCH_V6Z}, | |
7e806470 | 22365 | {9, ARM_ARCH_V6K}, |
91e22acd | 22366 | {11, ARM_ARCH_V6M}, |
7e806470 | 22367 | {8, ARM_ARCH_V6T2}, |
62b3e311 PB |
22368 | {10, ARM_ARCH_V7A}, |
22369 | {10, ARM_ARCH_V7R}, | |
22370 | {10, ARM_ARCH_V7M}, | |
22371 | {0, ARM_ARCH_NONE} | |
22372 | }; | |
22373 | ||
ee3c0378 AS |
22374 | /* Set an attribute if it has not already been set by the user. */ |
22375 | static void | |
22376 | aeabi_set_attribute_int (int tag, int value) | |
22377 | { | |
22378 | if (tag < 1 | |
22379 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22380 | || !attributes_set_explicitly[tag]) | |
22381 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
22382 | } | |
22383 | ||
22384 | static void | |
22385 | aeabi_set_attribute_string (int tag, const char *value) | |
22386 | { | |
22387 | if (tag < 1 | |
22388 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22389 | || !attributes_set_explicitly[tag]) | |
22390 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
22391 | } | |
22392 | ||
ee065d83 PB |
22393 | /* Set the public EABI object attributes. */ |
22394 | static void | |
22395 | aeabi_set_public_attributes (void) | |
22396 | { | |
22397 | int arch; | |
e74cfd16 | 22398 | arm_feature_set flags; |
62b3e311 PB |
22399 | arm_feature_set tmp; |
22400 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
22401 | |
22402 | /* Choose the architecture based on the capabilities of the requested cpu | |
22403 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
22404 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
22405 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
22406 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
7a1d4c38 PB |
22407 | /*Allow the user to override the reported architecture. */ |
22408 | if (object_arch) | |
22409 | { | |
22410 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
22411 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
22412 | } | |
22413 | ||
62b3e311 PB |
22414 | tmp = flags; |
22415 | arch = 0; | |
22416 | for (p = cpu_arch_ver; p->val; p++) | |
22417 | { | |
22418 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
22419 | { | |
22420 | arch = p->val; | |
22421 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
22422 | } | |
22423 | } | |
ee065d83 PB |
22424 | |
22425 | /* Tag_CPU_name. */ | |
22426 | if (selected_cpu_name[0]) | |
22427 | { | |
22428 | char *p; | |
22429 | ||
22430 | p = selected_cpu_name; | |
5f4273c7 | 22431 | if (strncmp (p, "armv", 4) == 0) |
ee065d83 PB |
22432 | { |
22433 | int i; | |
5f4273c7 | 22434 | |
ee065d83 PB |
22435 | p += 4; |
22436 | for (i = 0; p[i]; i++) | |
22437 | p[i] = TOUPPER (p[i]); | |
22438 | } | |
ee3c0378 | 22439 | aeabi_set_attribute_string (Tag_CPU_name, p); |
ee065d83 PB |
22440 | } |
22441 | /* Tag_CPU_arch. */ | |
ee3c0378 | 22442 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62b3e311 PB |
22443 | /* Tag_CPU_arch_profile. */ |
22444 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
ee3c0378 | 22445 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A'); |
62b3e311 | 22446 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
ee3c0378 | 22447 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R'); |
7e806470 | 22448 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
ee3c0378 | 22449 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M'); |
ee065d83 | 22450 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
22451 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
22452 | || arch == 0) | |
22453 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
ee065d83 | 22454 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
22455 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
22456 | || arch == 0) | |
22457 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, | |
22458 | ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1); | |
ee065d83 | 22459 | /* Tag_VFP_arch. */ |
ee3c0378 AS |
22460 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) |
22461 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
22462 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3)) | |
22463 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
22464 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) | |
22465 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
22466 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
22467 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) | |
22468 | aeabi_set_attribute_int (Tag_VFP_arch, 1); | |
ee065d83 | 22469 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
22470 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
22471 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
22472 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
22473 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
22474 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ | |
8e79c3df | 22475 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) |
ee3c0378 AS |
22476 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); |
22477 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ | |
8e79c3df | 22478 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16)) |
ee3c0378 | 22479 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
ee065d83 PB |
22480 | } |
22481 | ||
104d59d1 | 22482 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
22483 | void |
22484 | arm_md_end (void) | |
22485 | { | |
ee065d83 PB |
22486 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
22487 | return; | |
22488 | ||
22489 | aeabi_set_public_attributes (); | |
ee065d83 | 22490 | } |
8463be01 | 22491 | #endif /* OBJ_ELF */ |
ee065d83 PB |
22492 | |
22493 | ||
22494 | /* Parse a .cpu directive. */ | |
22495 | ||
22496 | static void | |
22497 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
22498 | { | |
e74cfd16 | 22499 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
22500 | char *name; |
22501 | char saved_char; | |
22502 | ||
22503 | name = input_line_pointer; | |
5f4273c7 | 22504 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22505 | input_line_pointer++; |
22506 | saved_char = *input_line_pointer; | |
22507 | *input_line_pointer = 0; | |
22508 | ||
22509 | /* Skip the first "all" entry. */ | |
22510 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
22511 | if (streq (opt->name, name)) | |
22512 | { | |
e74cfd16 PB |
22513 | mcpu_cpu_opt = &opt->value; |
22514 | selected_cpu = opt->value; | |
ee065d83 | 22515 | if (opt->canonical_name) |
5f4273c7 | 22516 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22517 | else |
22518 | { | |
22519 | int i; | |
22520 | for (i = 0; opt->name[i]; i++) | |
22521 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22522 | selected_cpu_name[i] = 0; | |
22523 | } | |
e74cfd16 | 22524 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22525 | *input_line_pointer = saved_char; |
22526 | demand_empty_rest_of_line (); | |
22527 | return; | |
22528 | } | |
22529 | as_bad (_("unknown cpu `%s'"), name); | |
22530 | *input_line_pointer = saved_char; | |
22531 | ignore_rest_of_line (); | |
22532 | } | |
22533 | ||
22534 | ||
22535 | /* Parse a .arch directive. */ | |
22536 | ||
22537 | static void | |
22538 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
22539 | { | |
e74cfd16 | 22540 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
22541 | char saved_char; |
22542 | char *name; | |
22543 | ||
22544 | name = input_line_pointer; | |
5f4273c7 | 22545 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22546 | input_line_pointer++; |
22547 | saved_char = *input_line_pointer; | |
22548 | *input_line_pointer = 0; | |
22549 | ||
22550 | /* Skip the first "all" entry. */ | |
22551 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22552 | if (streq (opt->name, name)) | |
22553 | { | |
e74cfd16 PB |
22554 | mcpu_cpu_opt = &opt->value; |
22555 | selected_cpu = opt->value; | |
5f4273c7 | 22556 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 22557 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22558 | *input_line_pointer = saved_char; |
22559 | demand_empty_rest_of_line (); | |
22560 | return; | |
22561 | } | |
22562 | ||
22563 | as_bad (_("unknown architecture `%s'\n"), name); | |
22564 | *input_line_pointer = saved_char; | |
22565 | ignore_rest_of_line (); | |
22566 | } | |
22567 | ||
22568 | ||
7a1d4c38 PB |
22569 | /* Parse a .object_arch directive. */ |
22570 | ||
22571 | static void | |
22572 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
22573 | { | |
22574 | const struct arm_arch_option_table *opt; | |
22575 | char saved_char; | |
22576 | char *name; | |
22577 | ||
22578 | name = input_line_pointer; | |
5f4273c7 | 22579 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
22580 | input_line_pointer++; |
22581 | saved_char = *input_line_pointer; | |
22582 | *input_line_pointer = 0; | |
22583 | ||
22584 | /* Skip the first "all" entry. */ | |
22585 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22586 | if (streq (opt->name, name)) | |
22587 | { | |
22588 | object_arch = &opt->value; | |
22589 | *input_line_pointer = saved_char; | |
22590 | demand_empty_rest_of_line (); | |
22591 | return; | |
22592 | } | |
22593 | ||
22594 | as_bad (_("unknown architecture `%s'\n"), name); | |
22595 | *input_line_pointer = saved_char; | |
22596 | ignore_rest_of_line (); | |
22597 | } | |
22598 | ||
ee065d83 PB |
22599 | /* Parse a .fpu directive. */ |
22600 | ||
22601 | static void | |
22602 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
22603 | { | |
e74cfd16 | 22604 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
22605 | char saved_char; |
22606 | char *name; | |
22607 | ||
22608 | name = input_line_pointer; | |
5f4273c7 | 22609 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22610 | input_line_pointer++; |
22611 | saved_char = *input_line_pointer; | |
22612 | *input_line_pointer = 0; | |
5f4273c7 | 22613 | |
ee065d83 PB |
22614 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22615 | if (streq (opt->name, name)) | |
22616 | { | |
e74cfd16 PB |
22617 | mfpu_opt = &opt->value; |
22618 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
22619 | *input_line_pointer = saved_char; |
22620 | demand_empty_rest_of_line (); | |
22621 | return; | |
22622 | } | |
22623 | ||
22624 | as_bad (_("unknown floating point format `%s'\n"), name); | |
22625 | *input_line_pointer = saved_char; | |
22626 | ignore_rest_of_line (); | |
22627 | } | |
ee065d83 | 22628 | |
794ba86a | 22629 | /* Copy symbol information. */ |
f31fef98 | 22630 | |
794ba86a DJ |
22631 | void |
22632 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
22633 | { | |
22634 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
22635 | } | |
e04befd0 | 22636 | |
f31fef98 | 22637 | #ifdef OBJ_ELF |
e04befd0 AS |
22638 | /* Given a symbolic attribute NAME, return the proper integer value. |
22639 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 22640 | |
e04befd0 AS |
22641 | int |
22642 | arm_convert_symbolic_attribute (const char *name) | |
22643 | { | |
f31fef98 NC |
22644 | static const struct |
22645 | { | |
22646 | const char * name; | |
22647 | const int tag; | |
22648 | } | |
22649 | attribute_table[] = | |
22650 | { | |
22651 | /* When you modify this table you should | |
22652 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 22653 | #define T(tag) {#tag, tag} |
f31fef98 NC |
22654 | T (Tag_CPU_raw_name), |
22655 | T (Tag_CPU_name), | |
22656 | T (Tag_CPU_arch), | |
22657 | T (Tag_CPU_arch_profile), | |
22658 | T (Tag_ARM_ISA_use), | |
22659 | T (Tag_THUMB_ISA_use), | |
22660 | T (Tag_VFP_arch), | |
22661 | T (Tag_WMMX_arch), | |
22662 | T (Tag_Advanced_SIMD_arch), | |
22663 | T (Tag_PCS_config), | |
22664 | T (Tag_ABI_PCS_R9_use), | |
22665 | T (Tag_ABI_PCS_RW_data), | |
22666 | T (Tag_ABI_PCS_RO_data), | |
22667 | T (Tag_ABI_PCS_GOT_use), | |
22668 | T (Tag_ABI_PCS_wchar_t), | |
22669 | T (Tag_ABI_FP_rounding), | |
22670 | T (Tag_ABI_FP_denormal), | |
22671 | T (Tag_ABI_FP_exceptions), | |
22672 | T (Tag_ABI_FP_user_exceptions), | |
22673 | T (Tag_ABI_FP_number_model), | |
22674 | T (Tag_ABI_align8_needed), | |
22675 | T (Tag_ABI_align8_preserved), | |
22676 | T (Tag_ABI_enum_size), | |
22677 | T (Tag_ABI_HardFP_use), | |
22678 | T (Tag_ABI_VFP_args), | |
22679 | T (Tag_ABI_WMMX_args), | |
22680 | T (Tag_ABI_optimization_goals), | |
22681 | T (Tag_ABI_FP_optimization_goals), | |
22682 | T (Tag_compatibility), | |
22683 | T (Tag_CPU_unaligned_access), | |
22684 | T (Tag_VFP_HP_extension), | |
22685 | T (Tag_ABI_FP_16bit_format), | |
22686 | T (Tag_nodefaults), | |
22687 | T (Tag_also_compatible_with), | |
22688 | T (Tag_conformance), | |
22689 | T (Tag_T2EE_use), | |
22690 | T (Tag_Virtualization_use), | |
22691 | T (Tag_MPextension_use) | |
e04befd0 | 22692 | #undef T |
f31fef98 | 22693 | }; |
e04befd0 AS |
22694 | unsigned int i; |
22695 | ||
22696 | if (name == NULL) | |
22697 | return -1; | |
22698 | ||
f31fef98 | 22699 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 22700 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
22701 | return attribute_table[i].tag; |
22702 | ||
22703 | return -1; | |
22704 | } | |
267bf995 RR |
22705 | |
22706 | ||
22707 | /* Apply sym value for relocations only in the case that | |
22708 | they are for local symbols and you have the respective | |
22709 | architectural feature for blx and simple switches. */ | |
22710 | int | |
22711 | arm_apply_sym_value (struct fix * fixP) | |
22712 | { | |
22713 | if (fixP->fx_addsy | |
22714 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
22715 | && !S_IS_EXTERNAL (fixP->fx_addsy)) | |
22716 | { | |
22717 | switch (fixP->fx_r_type) | |
22718 | { | |
22719 | case BFD_RELOC_ARM_PCREL_BLX: | |
22720 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
22721 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
22722 | return 1; | |
22723 | break; | |
22724 | ||
22725 | case BFD_RELOC_ARM_PCREL_CALL: | |
22726 | case BFD_RELOC_THUMB_PCREL_BLX: | |
22727 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
22728 | return 1; | |
22729 | break; | |
22730 | ||
22731 | default: | |
22732 | break; | |
22733 | } | |
22734 | ||
22735 | } | |
22736 | return 0; | |
22737 | } | |
f31fef98 | 22738 | #endif /* OBJ_ELF */ |