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 | /* Bit N indicates that an R_ARM_NONE relocation has been output for |
81 | __aeabi_unwind_cpp_prN already if set. This enables dependencies to be | |
82 | emitted only once per section, to save unnecessary bloat. */ | |
83 | static unsigned int marked_pr_dependency = 0; | |
84 | ||
85 | #endif /* OBJ_ELF */ | |
86 | ||
4962c51a MS |
87 | /* Results from operand parsing worker functions. */ |
88 | ||
89 | typedef enum | |
90 | { | |
91 | PARSE_OPERAND_SUCCESS, | |
92 | PARSE_OPERAND_FAIL, | |
93 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
94 | } parse_operand_result; | |
95 | ||
33a392fb PB |
96 | enum arm_float_abi |
97 | { | |
98 | ARM_FLOAT_ABI_HARD, | |
99 | ARM_FLOAT_ABI_SOFTFP, | |
100 | ARM_FLOAT_ABI_SOFT | |
101 | }; | |
102 | ||
c19d1205 | 103 | /* Types of processor to assemble for. */ |
b99bd4ef NC |
104 | #ifndef CPU_DEFAULT |
105 | #if defined __XSCALE__ | |
e74cfd16 | 106 | #define CPU_DEFAULT ARM_ARCH_XSCALE |
b99bd4ef NC |
107 | #else |
108 | #if defined __thumb__ | |
e74cfd16 | 109 | #define CPU_DEFAULT ARM_ARCH_V5T |
b99bd4ef NC |
110 | #endif |
111 | #endif | |
112 | #endif | |
113 | ||
114 | #ifndef FPU_DEFAULT | |
c820d418 MM |
115 | # ifdef TE_LINUX |
116 | # define FPU_DEFAULT FPU_ARCH_FPA | |
117 | # elif defined (TE_NetBSD) | |
118 | # ifdef OBJ_ELF | |
119 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
120 | # else | |
121 | /* Legacy a.out format. */ | |
122 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
123 | # endif | |
4e7fd91e PB |
124 | # elif defined (TE_VXWORKS) |
125 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
126 | # else |
127 | /* For backwards compatibility, default to FPA. */ | |
128 | # define FPU_DEFAULT FPU_ARCH_FPA | |
129 | # endif | |
130 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 131 | |
c19d1205 | 132 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 133 | |
e74cfd16 PB |
134 | static arm_feature_set cpu_variant; |
135 | static arm_feature_set arm_arch_used; | |
136 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 137 | |
b99bd4ef | 138 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
139 | static int uses_apcs_26 = FALSE; |
140 | static int atpcs = FALSE; | |
b34976b6 AM |
141 | static int support_interwork = FALSE; |
142 | static int uses_apcs_float = FALSE; | |
c19d1205 | 143 | static int pic_code = FALSE; |
845b51d6 | 144 | static int fix_v4bx = FALSE; |
278df34e NS |
145 | /* Warn on using deprecated features. */ |
146 | static int warn_on_deprecated = TRUE; | |
147 | ||
03b1477f RE |
148 | |
149 | /* Variables that we set while parsing command-line options. Once all | |
150 | options have been read we re-process these values to set the real | |
151 | assembly flags. */ | |
e74cfd16 PB |
152 | static const arm_feature_set *legacy_cpu = NULL; |
153 | static const arm_feature_set *legacy_fpu = NULL; | |
154 | ||
155 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
156 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
157 | static const arm_feature_set *march_cpu_opt = NULL; | |
158 | static const arm_feature_set *march_fpu_opt = NULL; | |
159 | static const arm_feature_set *mfpu_opt = NULL; | |
7a1d4c38 | 160 | static const arm_feature_set *object_arch = NULL; |
e74cfd16 PB |
161 | |
162 | /* Constants for known architecture features. */ | |
163 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
164 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
165 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
166 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
167 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
168 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
169 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
170 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
171 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
172 | ||
173 | #ifdef CPU_DEFAULT | |
174 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
175 | #endif | |
176 | ||
177 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
178 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
179 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
180 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
181 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
182 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
183 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
184 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
185 | static const arm_feature_set arm_ext_v4t_5 = | |
186 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
187 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
188 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
189 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
190 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
191 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
192 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
193 | static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0); | |
194 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); | |
62b3e311 | 195 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
7e806470 PB |
196 | static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0); |
197 | static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0); | |
62b3e311 PB |
198 | static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0); |
199 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0); | |
200 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0); | |
201 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0); | |
7e806470 PB |
202 | static const arm_feature_set arm_ext_m = |
203 | ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0); | |
e74cfd16 PB |
204 | |
205 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
206 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
207 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
208 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
209 | ||
2d447fca JM |
210 | static const arm_feature_set arm_cext_iwmmxt2 = |
211 | ARM_FEATURE (0, ARM_CEXT_IWMMXT2); | |
e74cfd16 PB |
212 | static const arm_feature_set arm_cext_iwmmxt = |
213 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
214 | static const arm_feature_set arm_cext_xscale = | |
215 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
216 | static const arm_feature_set arm_cext_maverick = | |
217 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
218 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
219 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
220 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
221 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
222 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
223 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
5287ad62 | 224 | static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3); |
b1cc4aeb PB |
225 | static const arm_feature_set fpu_vfp_ext_d32 = |
226 | ARM_FEATURE (0, FPU_VFP_EXT_D32); | |
5287ad62 JB |
227 | static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1); |
228 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = | |
229 | ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); | |
8e79c3df | 230 | static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16); |
e74cfd16 | 231 | |
33a392fb | 232 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
233 | /* Record user cpu selection for object attributes. */ |
234 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
235 | /* Must be long enough to hold any of the names in arm_cpus. */ |
236 | static char selected_cpu_name[16]; | |
7cc69913 | 237 | #ifdef OBJ_ELF |
deeaaff8 DJ |
238 | # ifdef EABI_DEFAULT |
239 | static int meabi_flags = EABI_DEFAULT; | |
240 | # else | |
d507cf36 | 241 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 242 | # endif |
e1da3f5b | 243 | |
ee3c0378 AS |
244 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
245 | ||
e1da3f5b | 246 | bfd_boolean |
5f4273c7 | 247 | arm_is_eabi (void) |
e1da3f5b PB |
248 | { |
249 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
250 | } | |
7cc69913 | 251 | #endif |
b99bd4ef | 252 | |
b99bd4ef | 253 | #ifdef OBJ_ELF |
c19d1205 | 254 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
255 | symbolS * GOT_symbol; |
256 | #endif | |
257 | ||
b99bd4ef NC |
258 | /* 0: assemble for ARM, |
259 | 1: assemble for Thumb, | |
260 | 2: assemble for Thumb even though target CPU does not support thumb | |
261 | instructions. */ | |
262 | static int thumb_mode = 0; | |
8dc2430f NC |
263 | /* A value distinct from the possible values for thumb_mode that we |
264 | can use to record whether thumb_mode has been copied into the | |
265 | tc_frag_data field of a frag. */ | |
266 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 267 | |
e07e6e58 NC |
268 | /* Specifies the intrinsic IT insn behavior mode. */ |
269 | enum implicit_it_mode | |
270 | { | |
271 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
272 | IMPLICIT_IT_MODE_ARM = 0x01, | |
273 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
274 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
275 | }; | |
276 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
277 | ||
c19d1205 ZW |
278 | /* If unified_syntax is true, we are processing the new unified |
279 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
280 | ||
281 | - Immediate operands do not require a # prefix. | |
282 | - Conditional affixes always appear at the end of the | |
283 | instruction. (For backward compatibility, those instructions | |
284 | that formerly had them in the middle, continue to accept them | |
285 | there.) | |
286 | - The IT instruction may appear, and if it does is validated | |
287 | against subsequent conditional affixes. It does not generate | |
288 | machine code. | |
289 | ||
290 | Important differences from the old Thumb mode: | |
291 | ||
292 | - Immediate operands do not require a # prefix. | |
293 | - Most of the V6T2 instructions are only available in unified mode. | |
294 | - The .N and .W suffixes are recognized and honored (it is an error | |
295 | if they cannot be honored). | |
296 | - All instructions set the flags if and only if they have an 's' affix. | |
297 | - Conditional affixes may be used. They are validated against | |
298 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
299 | conditional affix except in the scope of an IT instruction. */ | |
300 | ||
301 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 302 | |
5287ad62 JB |
303 | enum neon_el_type |
304 | { | |
dcbf9037 | 305 | NT_invtype, |
5287ad62 JB |
306 | NT_untyped, |
307 | NT_integer, | |
308 | NT_float, | |
309 | NT_poly, | |
310 | NT_signed, | |
dcbf9037 | 311 | NT_unsigned |
5287ad62 JB |
312 | }; |
313 | ||
314 | struct neon_type_el | |
315 | { | |
316 | enum neon_el_type type; | |
317 | unsigned size; | |
318 | }; | |
319 | ||
320 | #define NEON_MAX_TYPE_ELS 4 | |
321 | ||
322 | struct neon_type | |
323 | { | |
324 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
325 | unsigned elems; | |
326 | }; | |
327 | ||
e07e6e58 NC |
328 | enum it_instruction_type |
329 | { | |
330 | OUTSIDE_IT_INSN, | |
331 | INSIDE_IT_INSN, | |
332 | INSIDE_IT_LAST_INSN, | |
333 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
334 | if inside, should be the last one. */ | |
335 | NEUTRAL_IT_INSN, /* This could be either inside or outside, | |
336 | i.e. BKPT and NOP. */ | |
337 | IT_INSN /* The IT insn has been parsed. */ | |
338 | }; | |
339 | ||
b99bd4ef NC |
340 | struct arm_it |
341 | { | |
c19d1205 | 342 | const char * error; |
b99bd4ef | 343 | unsigned long instruction; |
c19d1205 ZW |
344 | int size; |
345 | int size_req; | |
346 | int cond; | |
037e8744 JB |
347 | /* "uncond_value" is set to the value in place of the conditional field in |
348 | unconditional versions of the instruction, or -1 if nothing is | |
349 | appropriate. */ | |
350 | int uncond_value; | |
5287ad62 | 351 | struct neon_type vectype; |
0110f2b8 PB |
352 | /* Set to the opcode if the instruction needs relaxation. |
353 | Zero if the instruction is not relaxed. */ | |
354 | unsigned long relax; | |
b99bd4ef NC |
355 | struct |
356 | { | |
357 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
358 | expressionS exp; |
359 | int pc_rel; | |
b99bd4ef | 360 | } reloc; |
b99bd4ef | 361 | |
e07e6e58 NC |
362 | enum it_instruction_type it_insn_type; |
363 | ||
c19d1205 ZW |
364 | struct |
365 | { | |
366 | unsigned reg; | |
ca3f61f7 | 367 | signed int imm; |
dcbf9037 | 368 | struct neon_type_el vectype; |
ca3f61f7 NC |
369 | unsigned present : 1; /* Operand present. */ |
370 | unsigned isreg : 1; /* Operand was a register. */ | |
371 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
372 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
373 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 374 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
375 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
376 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
377 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 378 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 379 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 380 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
381 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
382 | unsigned writeback : 1; /* Operand has trailing ! */ | |
383 | unsigned preind : 1; /* Preindexed address. */ | |
384 | unsigned postind : 1; /* Postindexed address. */ | |
385 | unsigned negative : 1; /* Index register was negated. */ | |
386 | unsigned shifted : 1; /* Shift applied to operation. */ | |
387 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 388 | } operands[6]; |
b99bd4ef NC |
389 | }; |
390 | ||
c19d1205 | 391 | static struct arm_it inst; |
b99bd4ef NC |
392 | |
393 | #define NUM_FLOAT_VALS 8 | |
394 | ||
05d2d07e | 395 | const char * fp_const[] = |
b99bd4ef NC |
396 | { |
397 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
398 | }; | |
399 | ||
c19d1205 | 400 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
401 | #define MAX_LITTLENUMS 6 |
402 | ||
403 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
404 | ||
405 | #define FAIL (-1) | |
406 | #define SUCCESS (0) | |
407 | ||
408 | #define SUFF_S 1 | |
409 | #define SUFF_D 2 | |
410 | #define SUFF_E 3 | |
411 | #define SUFF_P 4 | |
412 | ||
c19d1205 ZW |
413 | #define CP_T_X 0x00008000 |
414 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 415 | |
c19d1205 ZW |
416 | #define CONDS_BIT 0x00100000 |
417 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
418 | |
419 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
420 | ||
421 | struct asm_cond | |
422 | { | |
c921be7d NC |
423 | const char * template; |
424 | unsigned long value; | |
b99bd4ef NC |
425 | }; |
426 | ||
c19d1205 | 427 | #define COND_ALWAYS 0xE |
b99bd4ef | 428 | |
b99bd4ef NC |
429 | struct asm_psr |
430 | { | |
c921be7d NC |
431 | const char * template; |
432 | unsigned long field; | |
b99bd4ef NC |
433 | }; |
434 | ||
62b3e311 PB |
435 | struct asm_barrier_opt |
436 | { | |
c921be7d NC |
437 | const char * template; |
438 | unsigned long value; | |
62b3e311 PB |
439 | }; |
440 | ||
2d2255b5 | 441 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
442 | #define SPSR_BIT (1 << 22) |
443 | ||
c19d1205 ZW |
444 | /* The individual PSR flag bits. */ |
445 | #define PSR_c (1 << 16) | |
446 | #define PSR_x (1 << 17) | |
447 | #define PSR_s (1 << 18) | |
448 | #define PSR_f (1 << 19) | |
b99bd4ef | 449 | |
c19d1205 | 450 | struct reloc_entry |
bfae80f2 | 451 | { |
c921be7d NC |
452 | char * name; |
453 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
454 | }; |
455 | ||
5287ad62 | 456 | enum vfp_reg_pos |
bfae80f2 | 457 | { |
5287ad62 JB |
458 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
459 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
460 | }; |
461 | ||
462 | enum vfp_ldstm_type | |
463 | { | |
464 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
465 | }; | |
466 | ||
dcbf9037 JB |
467 | /* Bits for DEFINED field in neon_typed_alias. */ |
468 | #define NTA_HASTYPE 1 | |
469 | #define NTA_HASINDEX 2 | |
470 | ||
471 | struct neon_typed_alias | |
472 | { | |
c921be7d NC |
473 | unsigned char defined; |
474 | unsigned char index; | |
475 | struct neon_type_el eltype; | |
dcbf9037 JB |
476 | }; |
477 | ||
c19d1205 ZW |
478 | /* ARM register categories. This includes coprocessor numbers and various |
479 | architecture extensions' registers. */ | |
480 | enum arm_reg_type | |
bfae80f2 | 481 | { |
c19d1205 ZW |
482 | REG_TYPE_RN, |
483 | REG_TYPE_CP, | |
484 | REG_TYPE_CN, | |
485 | REG_TYPE_FN, | |
486 | REG_TYPE_VFS, | |
487 | REG_TYPE_VFD, | |
5287ad62 | 488 | REG_TYPE_NQ, |
037e8744 | 489 | REG_TYPE_VFSD, |
5287ad62 | 490 | REG_TYPE_NDQ, |
037e8744 | 491 | REG_TYPE_NSDQ, |
c19d1205 ZW |
492 | REG_TYPE_VFC, |
493 | REG_TYPE_MVF, | |
494 | REG_TYPE_MVD, | |
495 | REG_TYPE_MVFX, | |
496 | REG_TYPE_MVDX, | |
497 | REG_TYPE_MVAX, | |
498 | REG_TYPE_DSPSC, | |
499 | REG_TYPE_MMXWR, | |
500 | REG_TYPE_MMXWC, | |
501 | REG_TYPE_MMXWCG, | |
502 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
503 | }; |
504 | ||
dcbf9037 JB |
505 | /* Structure for a hash table entry for a register. |
506 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
507 | information which states whether a vector type or index is specified (for a | |
508 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
509 | struct reg_entry |
510 | { | |
c921be7d NC |
511 | const char * name; |
512 | unsigned char number; | |
513 | unsigned char type; | |
514 | unsigned char builtin; | |
515 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
516 | }; |
517 | ||
c19d1205 | 518 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 519 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
520 | { |
521 | N_("ARM register expected"), | |
522 | N_("bad or missing co-processor number"), | |
523 | N_("co-processor register expected"), | |
524 | N_("FPA register expected"), | |
525 | N_("VFP single precision register expected"), | |
5287ad62 JB |
526 | N_("VFP/Neon double precision register expected"), |
527 | N_("Neon quad precision register expected"), | |
037e8744 | 528 | N_("VFP single or double precision register expected"), |
5287ad62 | 529 | N_("Neon double or quad precision register expected"), |
037e8744 | 530 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
531 | N_("VFP system register expected"), |
532 | N_("Maverick MVF register expected"), | |
533 | N_("Maverick MVD register expected"), | |
534 | N_("Maverick MVFX register expected"), | |
535 | N_("Maverick MVDX register expected"), | |
536 | N_("Maverick MVAX register expected"), | |
537 | N_("Maverick DSPSC register expected"), | |
538 | N_("iWMMXt data register expected"), | |
539 | N_("iWMMXt control register expected"), | |
540 | N_("iWMMXt scalar register expected"), | |
541 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
542 | }; |
543 | ||
c19d1205 ZW |
544 | /* Some well known registers that we refer to directly elsewhere. */ |
545 | #define REG_SP 13 | |
546 | #define REG_LR 14 | |
547 | #define REG_PC 15 | |
404ff6b5 | 548 | |
b99bd4ef NC |
549 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
550 | take 2: */ | |
c19d1205 | 551 | #define INSN_SIZE 4 |
b99bd4ef NC |
552 | |
553 | struct asm_opcode | |
554 | { | |
555 | /* Basic string to match. */ | |
c921be7d | 556 | const char * template; |
c19d1205 ZW |
557 | |
558 | /* Parameters to instruction. */ | |
559 | unsigned char operands[8]; | |
560 | ||
561 | /* Conditional tag - see opcode_lookup. */ | |
562 | unsigned int tag : 4; | |
b99bd4ef NC |
563 | |
564 | /* Basic instruction code. */ | |
c19d1205 | 565 | unsigned int avalue : 28; |
b99bd4ef | 566 | |
c19d1205 ZW |
567 | /* Thumb-format instruction code. */ |
568 | unsigned int tvalue; | |
b99bd4ef | 569 | |
90e4755a | 570 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
571 | const arm_feature_set * avariant; |
572 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
573 | |
574 | /* Function to call to encode instruction in ARM format. */ | |
575 | void (* aencode) (void); | |
b99bd4ef | 576 | |
c19d1205 ZW |
577 | /* Function to call to encode instruction in Thumb format. */ |
578 | void (* tencode) (void); | |
b99bd4ef NC |
579 | }; |
580 | ||
a737bd4d NC |
581 | /* Defines for various bits that we will want to toggle. */ |
582 | #define INST_IMMEDIATE 0x02000000 | |
583 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 584 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
585 | #define SHIFT_BY_REG 0x00000010 |
586 | #define PRE_INDEX 0x01000000 | |
587 | #define INDEX_UP 0x00800000 | |
588 | #define WRITE_BACK 0x00200000 | |
589 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 590 | #define CPSI_MMOD 0x00020000 |
90e4755a | 591 | |
a737bd4d NC |
592 | #define LITERAL_MASK 0xf000f000 |
593 | #define OPCODE_MASK 0xfe1fffff | |
594 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 595 | |
efd81785 PB |
596 | #define T2_SUBS_PC_LR 0xf3de8f00 |
597 | ||
a737bd4d | 598 | #define DATA_OP_SHIFT 21 |
90e4755a | 599 | |
ef8d22e6 PB |
600 | #define T2_OPCODE_MASK 0xfe1fffff |
601 | #define T2_DATA_OP_SHIFT 21 | |
602 | ||
a737bd4d NC |
603 | /* Codes to distinguish the arithmetic instructions. */ |
604 | #define OPCODE_AND 0 | |
605 | #define OPCODE_EOR 1 | |
606 | #define OPCODE_SUB 2 | |
607 | #define OPCODE_RSB 3 | |
608 | #define OPCODE_ADD 4 | |
609 | #define OPCODE_ADC 5 | |
610 | #define OPCODE_SBC 6 | |
611 | #define OPCODE_RSC 7 | |
612 | #define OPCODE_TST 8 | |
613 | #define OPCODE_TEQ 9 | |
614 | #define OPCODE_CMP 10 | |
615 | #define OPCODE_CMN 11 | |
616 | #define OPCODE_ORR 12 | |
617 | #define OPCODE_MOV 13 | |
618 | #define OPCODE_BIC 14 | |
619 | #define OPCODE_MVN 15 | |
90e4755a | 620 | |
ef8d22e6 PB |
621 | #define T2_OPCODE_AND 0 |
622 | #define T2_OPCODE_BIC 1 | |
623 | #define T2_OPCODE_ORR 2 | |
624 | #define T2_OPCODE_ORN 3 | |
625 | #define T2_OPCODE_EOR 4 | |
626 | #define T2_OPCODE_ADD 8 | |
627 | #define T2_OPCODE_ADC 10 | |
628 | #define T2_OPCODE_SBC 11 | |
629 | #define T2_OPCODE_SUB 13 | |
630 | #define T2_OPCODE_RSB 14 | |
631 | ||
a737bd4d NC |
632 | #define T_OPCODE_MUL 0x4340 |
633 | #define T_OPCODE_TST 0x4200 | |
634 | #define T_OPCODE_CMN 0x42c0 | |
635 | #define T_OPCODE_NEG 0x4240 | |
636 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 637 | |
a737bd4d NC |
638 | #define T_OPCODE_ADD_R3 0x1800 |
639 | #define T_OPCODE_SUB_R3 0x1a00 | |
640 | #define T_OPCODE_ADD_HI 0x4400 | |
641 | #define T_OPCODE_ADD_ST 0xb000 | |
642 | #define T_OPCODE_SUB_ST 0xb080 | |
643 | #define T_OPCODE_ADD_SP 0xa800 | |
644 | #define T_OPCODE_ADD_PC 0xa000 | |
645 | #define T_OPCODE_ADD_I8 0x3000 | |
646 | #define T_OPCODE_SUB_I8 0x3800 | |
647 | #define T_OPCODE_ADD_I3 0x1c00 | |
648 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 649 | |
a737bd4d NC |
650 | #define T_OPCODE_ASR_R 0x4100 |
651 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
652 | #define T_OPCODE_LSR_R 0x40c0 |
653 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
654 | #define T_OPCODE_ASR_I 0x1000 |
655 | #define T_OPCODE_LSL_I 0x0000 | |
656 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 657 | |
a737bd4d NC |
658 | #define T_OPCODE_MOV_I8 0x2000 |
659 | #define T_OPCODE_CMP_I8 0x2800 | |
660 | #define T_OPCODE_CMP_LR 0x4280 | |
661 | #define T_OPCODE_MOV_HR 0x4600 | |
662 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 663 | |
a737bd4d NC |
664 | #define T_OPCODE_LDR_PC 0x4800 |
665 | #define T_OPCODE_LDR_SP 0x9800 | |
666 | #define T_OPCODE_STR_SP 0x9000 | |
667 | #define T_OPCODE_LDR_IW 0x6800 | |
668 | #define T_OPCODE_STR_IW 0x6000 | |
669 | #define T_OPCODE_LDR_IH 0x8800 | |
670 | #define T_OPCODE_STR_IH 0x8000 | |
671 | #define T_OPCODE_LDR_IB 0x7800 | |
672 | #define T_OPCODE_STR_IB 0x7000 | |
673 | #define T_OPCODE_LDR_RW 0x5800 | |
674 | #define T_OPCODE_STR_RW 0x5000 | |
675 | #define T_OPCODE_LDR_RH 0x5a00 | |
676 | #define T_OPCODE_STR_RH 0x5200 | |
677 | #define T_OPCODE_LDR_RB 0x5c00 | |
678 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 679 | |
a737bd4d NC |
680 | #define T_OPCODE_PUSH 0xb400 |
681 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 682 | |
2fc8bdac | 683 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 684 | |
a737bd4d | 685 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 686 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 687 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 688 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
689 | |
690 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 691 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
692 | #define BAD_PC _("r15 not allowed here") |
693 | #define BAD_COND _("instruction cannot be conditional") | |
694 | #define BAD_OVERLAP _("registers may not be the same") | |
695 | #define BAD_HIREG _("lo register required") | |
696 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 697 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
698 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
699 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 700 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
701 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
702 | #define BAD_IT_COND _("incorrect condition in IT block") | |
703 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 704 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
c19d1205 | 705 | |
c921be7d NC |
706 | static struct hash_control * arm_ops_hsh; |
707 | static struct hash_control * arm_cond_hsh; | |
708 | static struct hash_control * arm_shift_hsh; | |
709 | static struct hash_control * arm_psr_hsh; | |
710 | static struct hash_control * arm_v7m_psr_hsh; | |
711 | static struct hash_control * arm_reg_hsh; | |
712 | static struct hash_control * arm_reloc_hsh; | |
713 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 714 | |
b99bd4ef NC |
715 | /* Stuff needed to resolve the label ambiguity |
716 | As: | |
717 | ... | |
718 | label: <insn> | |
719 | may differ from: | |
720 | ... | |
721 | label: | |
5f4273c7 | 722 | <insn> */ |
b99bd4ef NC |
723 | |
724 | symbolS * last_label_seen; | |
b34976b6 | 725 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 726 | |
3d0c9500 NC |
727 | /* Literal pool structure. Held on a per-section |
728 | and per-sub-section basis. */ | |
a737bd4d | 729 | |
c19d1205 | 730 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 731 | typedef struct literal_pool |
b99bd4ef | 732 | { |
c921be7d NC |
733 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
734 | unsigned int next_free_entry; | |
735 | unsigned int id; | |
736 | symbolS * symbol; | |
737 | segT section; | |
738 | subsegT sub_section; | |
739 | struct literal_pool * next; | |
3d0c9500 | 740 | } literal_pool; |
b99bd4ef | 741 | |
3d0c9500 NC |
742 | /* Pointer to a linked list of literal pools. */ |
743 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 744 | |
e07e6e58 NC |
745 | #ifdef OBJ_ELF |
746 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
747 | #else | |
748 | static struct current_it now_it; | |
749 | #endif | |
750 | ||
751 | static inline int | |
752 | now_it_compatible (int cond) | |
753 | { | |
754 | return (cond & ~1) == (now_it.cc & ~1); | |
755 | } | |
756 | ||
757 | static inline int | |
758 | conditional_insn (void) | |
759 | { | |
760 | return inst.cond != COND_ALWAYS; | |
761 | } | |
762 | ||
763 | static int in_it_block (void); | |
764 | ||
765 | static int handle_it_state (void); | |
766 | ||
767 | static void force_automatic_it_block_close (void); | |
768 | ||
c921be7d NC |
769 | static void it_fsm_post_encode (void); |
770 | ||
e07e6e58 NC |
771 | #define set_it_insn_type(type) \ |
772 | do \ | |
773 | { \ | |
774 | inst.it_insn_type = type; \ | |
775 | if (handle_it_state () == FAIL) \ | |
776 | return; \ | |
777 | } \ | |
778 | while (0) | |
779 | ||
c921be7d NC |
780 | #define set_it_insn_type_nonvoid(type, failret) \ |
781 | do \ | |
782 | { \ | |
783 | inst.it_insn_type = type; \ | |
784 | if (handle_it_state () == FAIL) \ | |
785 | return failret; \ | |
786 | } \ | |
787 | while(0) | |
788 | ||
e07e6e58 NC |
789 | #define set_it_insn_type_last() \ |
790 | do \ | |
791 | { \ | |
792 | if (inst.cond == COND_ALWAYS) \ | |
793 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ | |
794 | else \ | |
795 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ | |
796 | } \ | |
797 | while (0) | |
798 | ||
c19d1205 | 799 | /* Pure syntax. */ |
b99bd4ef | 800 | |
c19d1205 ZW |
801 | /* This array holds the chars that always start a comment. If the |
802 | pre-processor is disabled, these aren't very useful. */ | |
803 | const char comment_chars[] = "@"; | |
3d0c9500 | 804 | |
c19d1205 ZW |
805 | /* This array holds the chars that only start a comment at the beginning of |
806 | a line. If the line seems to have the form '# 123 filename' | |
807 | .line and .file directives will appear in the pre-processed output. */ | |
808 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
809 | first line of the input file. This is because the compiler outputs | |
810 | #NO_APP at the beginning of its output. */ | |
811 | /* Also note that comments like this one will always work. */ | |
812 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 813 | |
c19d1205 | 814 | const char line_separator_chars[] = ";"; |
b99bd4ef | 815 | |
c19d1205 ZW |
816 | /* Chars that can be used to separate mant |
817 | from exp in floating point numbers. */ | |
818 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 819 | |
c19d1205 ZW |
820 | /* Chars that mean this number is a floating point constant. */ |
821 | /* As in 0f12.456 */ | |
822 | /* or 0d1.2345e12 */ | |
b99bd4ef | 823 | |
c19d1205 | 824 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 825 | |
c19d1205 ZW |
826 | /* Prefix characters that indicate the start of an immediate |
827 | value. */ | |
828 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 829 | |
c19d1205 ZW |
830 | /* Separator character handling. */ |
831 | ||
832 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
833 | ||
834 | static inline int | |
835 | skip_past_char (char ** str, char c) | |
836 | { | |
837 | if (**str == c) | |
838 | { | |
839 | (*str)++; | |
840 | return SUCCESS; | |
3d0c9500 | 841 | } |
c19d1205 ZW |
842 | else |
843 | return FAIL; | |
844 | } | |
c921be7d | 845 | |
c19d1205 | 846 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 847 | |
c19d1205 ZW |
848 | /* Arithmetic expressions (possibly involving symbols). */ |
849 | ||
850 | /* Return TRUE if anything in the expression is a bignum. */ | |
851 | ||
852 | static int | |
853 | walk_no_bignums (symbolS * sp) | |
854 | { | |
855 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
856 | return 1; | |
857 | ||
858 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 859 | { |
c19d1205 ZW |
860 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
861 | || (symbol_get_value_expression (sp)->X_op_symbol | |
862 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
863 | } |
864 | ||
c19d1205 | 865 | return 0; |
3d0c9500 NC |
866 | } |
867 | ||
c19d1205 ZW |
868 | static int in_my_get_expression = 0; |
869 | ||
870 | /* Third argument to my_get_expression. */ | |
871 | #define GE_NO_PREFIX 0 | |
872 | #define GE_IMM_PREFIX 1 | |
873 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
874 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
875 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
876 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 877 | |
b99bd4ef | 878 | static int |
c19d1205 | 879 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 880 | { |
c19d1205 ZW |
881 | char * save_in; |
882 | segT seg; | |
b99bd4ef | 883 | |
c19d1205 ZW |
884 | /* In unified syntax, all prefixes are optional. */ |
885 | if (unified_syntax) | |
5287ad62 JB |
886 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
887 | : GE_OPT_PREFIX; | |
b99bd4ef | 888 | |
c19d1205 | 889 | switch (prefix_mode) |
b99bd4ef | 890 | { |
c19d1205 ZW |
891 | case GE_NO_PREFIX: break; |
892 | case GE_IMM_PREFIX: | |
893 | if (!is_immediate_prefix (**str)) | |
894 | { | |
895 | inst.error = _("immediate expression requires a # prefix"); | |
896 | return FAIL; | |
897 | } | |
898 | (*str)++; | |
899 | break; | |
900 | case GE_OPT_PREFIX: | |
5287ad62 | 901 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
902 | if (is_immediate_prefix (**str)) |
903 | (*str)++; | |
904 | break; | |
905 | default: abort (); | |
906 | } | |
b99bd4ef | 907 | |
c19d1205 | 908 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 909 | |
c19d1205 ZW |
910 | save_in = input_line_pointer; |
911 | input_line_pointer = *str; | |
912 | in_my_get_expression = 1; | |
913 | seg = expression (ep); | |
914 | in_my_get_expression = 0; | |
915 | ||
916 | if (ep->X_op == O_illegal) | |
b99bd4ef | 917 | { |
c19d1205 ZW |
918 | /* We found a bad expression in md_operand(). */ |
919 | *str = input_line_pointer; | |
920 | input_line_pointer = save_in; | |
921 | if (inst.error == NULL) | |
922 | inst.error = _("bad expression"); | |
923 | return 1; | |
924 | } | |
b99bd4ef | 925 | |
c19d1205 ZW |
926 | #ifdef OBJ_AOUT |
927 | if (seg != absolute_section | |
928 | && seg != text_section | |
929 | && seg != data_section | |
930 | && seg != bss_section | |
931 | && seg != undefined_section) | |
932 | { | |
933 | inst.error = _("bad segment"); | |
934 | *str = input_line_pointer; | |
935 | input_line_pointer = save_in; | |
936 | return 1; | |
b99bd4ef | 937 | } |
c19d1205 | 938 | #endif |
b99bd4ef | 939 | |
c19d1205 ZW |
940 | /* Get rid of any bignums now, so that we don't generate an error for which |
941 | we can't establish a line number later on. Big numbers are never valid | |
942 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
943 | if (prefix_mode != GE_OPT_PREFIX_BIG |
944 | && (ep->X_op == O_big | |
945 | || (ep->X_add_symbol | |
946 | && (walk_no_bignums (ep->X_add_symbol) | |
947 | || (ep->X_op_symbol | |
948 | && walk_no_bignums (ep->X_op_symbol)))))) | |
c19d1205 ZW |
949 | { |
950 | inst.error = _("invalid constant"); | |
951 | *str = input_line_pointer; | |
952 | input_line_pointer = save_in; | |
953 | return 1; | |
954 | } | |
b99bd4ef | 955 | |
c19d1205 ZW |
956 | *str = input_line_pointer; |
957 | input_line_pointer = save_in; | |
958 | return 0; | |
b99bd4ef NC |
959 | } |
960 | ||
c19d1205 ZW |
961 | /* Turn a string in input_line_pointer into a floating point constant |
962 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
963 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
964 | returned, or NULL on OK. | |
b99bd4ef | 965 | |
c19d1205 ZW |
966 | Note that fp constants aren't represent in the normal way on the ARM. |
967 | In big endian mode, things are as expected. However, in little endian | |
968 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
969 | within the words. For example, (double) 1.1 in big endian mode is | |
970 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
971 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 972 | |
c19d1205 | 973 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 974 | |
c19d1205 ZW |
975 | char * |
976 | md_atof (int type, char * litP, int * sizeP) | |
977 | { | |
978 | int prec; | |
979 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
980 | char *t; | |
981 | int i; | |
b99bd4ef | 982 | |
c19d1205 ZW |
983 | switch (type) |
984 | { | |
985 | case 'f': | |
986 | case 'F': | |
987 | case 's': | |
988 | case 'S': | |
989 | prec = 2; | |
990 | break; | |
b99bd4ef | 991 | |
c19d1205 ZW |
992 | case 'd': |
993 | case 'D': | |
994 | case 'r': | |
995 | case 'R': | |
996 | prec = 4; | |
997 | break; | |
b99bd4ef | 998 | |
c19d1205 ZW |
999 | case 'x': |
1000 | case 'X': | |
499ac353 | 1001 | prec = 5; |
c19d1205 | 1002 | break; |
b99bd4ef | 1003 | |
c19d1205 ZW |
1004 | case 'p': |
1005 | case 'P': | |
499ac353 | 1006 | prec = 5; |
c19d1205 | 1007 | break; |
a737bd4d | 1008 | |
c19d1205 ZW |
1009 | default: |
1010 | *sizeP = 0; | |
499ac353 | 1011 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1012 | } |
b99bd4ef | 1013 | |
c19d1205 ZW |
1014 | t = atof_ieee (input_line_pointer, type, words); |
1015 | if (t) | |
1016 | input_line_pointer = t; | |
499ac353 | 1017 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1018 | |
c19d1205 ZW |
1019 | if (target_big_endian) |
1020 | { | |
1021 | for (i = 0; i < prec; i++) | |
1022 | { | |
499ac353 NC |
1023 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1024 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1025 | } |
1026 | } | |
1027 | else | |
1028 | { | |
e74cfd16 | 1029 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1030 | for (i = prec - 1; i >= 0; i--) |
1031 | { | |
499ac353 NC |
1032 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1033 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1034 | } |
1035 | else | |
1036 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1037 | For an 8 byte float the order is 1 0 3 2. */ | |
1038 | for (i = 0; i < prec; i += 2) | |
1039 | { | |
499ac353 NC |
1040 | md_number_to_chars (litP, (valueT) words[i + 1], |
1041 | sizeof (LITTLENUM_TYPE)); | |
1042 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1043 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1044 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1045 | } |
1046 | } | |
b99bd4ef | 1047 | |
499ac353 | 1048 | return NULL; |
c19d1205 | 1049 | } |
b99bd4ef | 1050 | |
c19d1205 ZW |
1051 | /* We handle all bad expressions here, so that we can report the faulty |
1052 | instruction in the error message. */ | |
1053 | void | |
1054 | md_operand (expressionS * expr) | |
1055 | { | |
1056 | if (in_my_get_expression) | |
1057 | expr->X_op = O_illegal; | |
b99bd4ef NC |
1058 | } |
1059 | ||
c19d1205 | 1060 | /* Immediate values. */ |
b99bd4ef | 1061 | |
c19d1205 ZW |
1062 | /* Generic immediate-value read function for use in directives. |
1063 | Accepts anything that 'expression' can fold to a constant. | |
1064 | *val receives the number. */ | |
1065 | #ifdef OBJ_ELF | |
1066 | static int | |
1067 | immediate_for_directive (int *val) | |
b99bd4ef | 1068 | { |
c19d1205 ZW |
1069 | expressionS exp; |
1070 | exp.X_op = O_illegal; | |
b99bd4ef | 1071 | |
c19d1205 ZW |
1072 | if (is_immediate_prefix (*input_line_pointer)) |
1073 | { | |
1074 | input_line_pointer++; | |
1075 | expression (&exp); | |
1076 | } | |
b99bd4ef | 1077 | |
c19d1205 ZW |
1078 | if (exp.X_op != O_constant) |
1079 | { | |
1080 | as_bad (_("expected #constant")); | |
1081 | ignore_rest_of_line (); | |
1082 | return FAIL; | |
1083 | } | |
1084 | *val = exp.X_add_number; | |
1085 | return SUCCESS; | |
b99bd4ef | 1086 | } |
c19d1205 | 1087 | #endif |
b99bd4ef | 1088 | |
c19d1205 | 1089 | /* Register parsing. */ |
b99bd4ef | 1090 | |
c19d1205 ZW |
1091 | /* Generic register parser. CCP points to what should be the |
1092 | beginning of a register name. If it is indeed a valid register | |
1093 | name, advance CCP over it and return the reg_entry structure; | |
1094 | otherwise return NULL. Does not issue diagnostics. */ | |
1095 | ||
1096 | static struct reg_entry * | |
1097 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1098 | { |
c19d1205 ZW |
1099 | char *start = *ccp; |
1100 | char *p; | |
1101 | struct reg_entry *reg; | |
b99bd4ef | 1102 | |
c19d1205 ZW |
1103 | #ifdef REGISTER_PREFIX |
1104 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1105 | return NULL; |
c19d1205 ZW |
1106 | start++; |
1107 | #endif | |
1108 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1109 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1110 | start++; | |
1111 | #endif | |
b99bd4ef | 1112 | |
c19d1205 ZW |
1113 | p = start; |
1114 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1115 | return NULL; | |
b99bd4ef | 1116 | |
c19d1205 ZW |
1117 | do |
1118 | p++; | |
1119 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1120 | ||
1121 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1122 | ||
1123 | if (!reg) | |
1124 | return NULL; | |
1125 | ||
1126 | *ccp = p; | |
1127 | return reg; | |
b99bd4ef NC |
1128 | } |
1129 | ||
1130 | static int | |
dcbf9037 JB |
1131 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
1132 | enum arm_reg_type type) | |
b99bd4ef | 1133 | { |
c19d1205 ZW |
1134 | /* Alternative syntaxes are accepted for a few register classes. */ |
1135 | switch (type) | |
1136 | { | |
1137 | case REG_TYPE_MVF: | |
1138 | case REG_TYPE_MVD: | |
1139 | case REG_TYPE_MVFX: | |
1140 | case REG_TYPE_MVDX: | |
1141 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1142 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1143 | return reg->number; |
1144 | break; | |
69b97547 | 1145 | |
c19d1205 ZW |
1146 | case REG_TYPE_CP: |
1147 | /* For backward compatibility, a bare number is valid here. */ | |
1148 | { | |
1149 | unsigned long processor = strtoul (start, ccp, 10); | |
1150 | if (*ccp != start && processor <= 15) | |
1151 | return processor; | |
1152 | } | |
6057a28f | 1153 | |
c19d1205 ZW |
1154 | case REG_TYPE_MMXWC: |
1155 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1156 | instructions that take WC registers. */ | |
79134647 | 1157 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1158 | return reg->number; |
6057a28f | 1159 | break; |
c19d1205 | 1160 | |
6057a28f | 1161 | default: |
c19d1205 | 1162 | break; |
6057a28f NC |
1163 | } |
1164 | ||
dcbf9037 JB |
1165 | return FAIL; |
1166 | } | |
1167 | ||
1168 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1169 | return value is the register number or FAIL. */ | |
1170 | ||
1171 | static int | |
1172 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1173 | { | |
1174 | char *start = *ccp; | |
1175 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1176 | int ret; | |
1177 | ||
1178 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1179 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1180 | return FAIL; | |
1181 | ||
1182 | if (reg && reg->type == type) | |
1183 | return reg->number; | |
1184 | ||
1185 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1186 | return ret; | |
1187 | ||
c19d1205 ZW |
1188 | *ccp = start; |
1189 | return FAIL; | |
1190 | } | |
69b97547 | 1191 | |
dcbf9037 JB |
1192 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1193 | character. Does no verification at this stage that the type fits the opcode | |
1194 | properly. E.g., | |
1195 | ||
1196 | .i32.i32.s16 | |
1197 | .s32.f32 | |
1198 | .u16 | |
1199 | ||
1200 | Can all be legally parsed by this function. | |
1201 | ||
1202 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1203 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1204 | type, FAIL if not. */ | |
1205 | ||
1206 | static int | |
1207 | parse_neon_type (struct neon_type *type, char **str) | |
1208 | { | |
1209 | char *ptr = *str; | |
1210 | ||
1211 | if (type) | |
1212 | type->elems = 0; | |
1213 | ||
1214 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1215 | { | |
1216 | enum neon_el_type thistype = NT_untyped; | |
1217 | unsigned thissize = -1u; | |
1218 | ||
1219 | if (*ptr != '.') | |
1220 | break; | |
1221 | ||
1222 | ptr++; | |
1223 | ||
1224 | /* Just a size without an explicit type. */ | |
1225 | if (ISDIGIT (*ptr)) | |
1226 | goto parsesize; | |
1227 | ||
1228 | switch (TOLOWER (*ptr)) | |
1229 | { | |
1230 | case 'i': thistype = NT_integer; break; | |
1231 | case 'f': thistype = NT_float; break; | |
1232 | case 'p': thistype = NT_poly; break; | |
1233 | case 's': thistype = NT_signed; break; | |
1234 | case 'u': thistype = NT_unsigned; break; | |
037e8744 JB |
1235 | case 'd': |
1236 | thistype = NT_float; | |
1237 | thissize = 64; | |
1238 | ptr++; | |
1239 | goto done; | |
dcbf9037 JB |
1240 | default: |
1241 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1242 | return FAIL; | |
1243 | } | |
1244 | ||
1245 | ptr++; | |
1246 | ||
1247 | /* .f is an abbreviation for .f32. */ | |
1248 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1249 | thissize = 32; | |
1250 | else | |
1251 | { | |
1252 | parsesize: | |
1253 | thissize = strtoul (ptr, &ptr, 10); | |
1254 | ||
1255 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
1256 | && thissize != 64) | |
1257 | { | |
1258 | as_bad (_("bad size %d in type specifier"), thissize); | |
1259 | return FAIL; | |
1260 | } | |
1261 | } | |
1262 | ||
037e8744 | 1263 | done: |
dcbf9037 JB |
1264 | if (type) |
1265 | { | |
1266 | type->el[type->elems].type = thistype; | |
1267 | type->el[type->elems].size = thissize; | |
1268 | type->elems++; | |
1269 | } | |
1270 | } | |
1271 | ||
1272 | /* Empty/missing type is not a successful parse. */ | |
1273 | if (type->elems == 0) | |
1274 | return FAIL; | |
1275 | ||
1276 | *str = ptr; | |
1277 | ||
1278 | return SUCCESS; | |
1279 | } | |
1280 | ||
1281 | /* Errors may be set multiple times during parsing or bit encoding | |
1282 | (particularly in the Neon bits), but usually the earliest error which is set | |
1283 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1284 | errors by calling this function. */ | |
1285 | ||
1286 | static void | |
1287 | first_error (const char *err) | |
1288 | { | |
1289 | if (!inst.error) | |
1290 | inst.error = err; | |
1291 | } | |
1292 | ||
1293 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1294 | static int | |
1295 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1296 | { | |
1297 | char *str = *ccp; | |
1298 | struct neon_type optype; | |
1299 | ||
1300 | if (*str == '.') | |
1301 | { | |
1302 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
1303 | { | |
1304 | if (optype.elems == 1) | |
1305 | *vectype = optype.el[0]; | |
1306 | else | |
1307 | { | |
1308 | first_error (_("only one type should be specified for operand")); | |
1309 | return FAIL; | |
1310 | } | |
1311 | } | |
1312 | else | |
1313 | { | |
1314 | first_error (_("vector type expected")); | |
1315 | return FAIL; | |
1316 | } | |
1317 | } | |
1318 | else | |
1319 | return FAIL; | |
5f4273c7 | 1320 | |
dcbf9037 | 1321 | *ccp = str; |
5f4273c7 | 1322 | |
dcbf9037 JB |
1323 | return SUCCESS; |
1324 | } | |
1325 | ||
1326 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1327 | a 4-bit integer. */ | |
1328 | ||
1329 | #define NEON_ALL_LANES 15 | |
1330 | #define NEON_INTERLEAVE_LANES 14 | |
1331 | ||
1332 | /* Parse either a register or a scalar, with an optional type. Return the | |
1333 | register number, and optionally fill in the actual type of the register | |
1334 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1335 | type/index information in *TYPEINFO. */ | |
1336 | ||
1337 | static int | |
1338 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
1339 | enum arm_reg_type *rtype, | |
1340 | struct neon_typed_alias *typeinfo) | |
1341 | { | |
1342 | char *str = *ccp; | |
1343 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1344 | struct neon_typed_alias atype; | |
1345 | struct neon_type_el parsetype; | |
1346 | ||
1347 | atype.defined = 0; | |
1348 | atype.index = -1; | |
1349 | atype.eltype.type = NT_invtype; | |
1350 | atype.eltype.size = -1; | |
1351 | ||
1352 | /* Try alternate syntax for some types of register. Note these are mutually | |
1353 | exclusive with the Neon syntax extensions. */ | |
1354 | if (reg == NULL) | |
1355 | { | |
1356 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1357 | if (altreg != FAIL) | |
1358 | *ccp = str; | |
1359 | if (typeinfo) | |
1360 | *typeinfo = atype; | |
1361 | return altreg; | |
1362 | } | |
1363 | ||
037e8744 JB |
1364 | /* Undo polymorphism when a set of register types may be accepted. */ |
1365 | if ((type == REG_TYPE_NDQ | |
1366 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1367 | || (type == REG_TYPE_VFSD | |
1368 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
1369 | || (type == REG_TYPE_NSDQ | |
1370 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD | |
f512f76f NC |
1371 | || reg->type == REG_TYPE_NQ)) |
1372 | || (type == REG_TYPE_MMXWC | |
1373 | && (reg->type == REG_TYPE_MMXWCG))) | |
dcbf9037 JB |
1374 | type = reg->type; |
1375 | ||
1376 | if (type != reg->type) | |
1377 | return FAIL; | |
1378 | ||
1379 | if (reg->neon) | |
1380 | atype = *reg->neon; | |
5f4273c7 | 1381 | |
dcbf9037 JB |
1382 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1383 | { | |
1384 | if ((atype.defined & NTA_HASTYPE) != 0) | |
1385 | { | |
1386 | first_error (_("can't redefine type for operand")); | |
1387 | return FAIL; | |
1388 | } | |
1389 | atype.defined |= NTA_HASTYPE; | |
1390 | atype.eltype = parsetype; | |
1391 | } | |
5f4273c7 | 1392 | |
dcbf9037 JB |
1393 | if (skip_past_char (&str, '[') == SUCCESS) |
1394 | { | |
1395 | if (type != REG_TYPE_VFD) | |
1396 | { | |
1397 | first_error (_("only D registers may be indexed")); | |
1398 | return FAIL; | |
1399 | } | |
5f4273c7 | 1400 | |
dcbf9037 JB |
1401 | if ((atype.defined & NTA_HASINDEX) != 0) |
1402 | { | |
1403 | first_error (_("can't change index for operand")); | |
1404 | return FAIL; | |
1405 | } | |
1406 | ||
1407 | atype.defined |= NTA_HASINDEX; | |
1408 | ||
1409 | if (skip_past_char (&str, ']') == SUCCESS) | |
1410 | atype.index = NEON_ALL_LANES; | |
1411 | else | |
1412 | { | |
1413 | expressionS exp; | |
1414 | ||
1415 | my_get_expression (&exp, &str, GE_NO_PREFIX); | |
1416 | ||
1417 | if (exp.X_op != O_constant) | |
1418 | { | |
1419 | first_error (_("constant expression required")); | |
1420 | return FAIL; | |
1421 | } | |
1422 | ||
1423 | if (skip_past_char (&str, ']') == FAIL) | |
1424 | return FAIL; | |
1425 | ||
1426 | atype.index = exp.X_add_number; | |
1427 | } | |
1428 | } | |
5f4273c7 | 1429 | |
dcbf9037 JB |
1430 | if (typeinfo) |
1431 | *typeinfo = atype; | |
5f4273c7 | 1432 | |
dcbf9037 JB |
1433 | if (rtype) |
1434 | *rtype = type; | |
5f4273c7 | 1435 | |
dcbf9037 | 1436 | *ccp = str; |
5f4273c7 | 1437 | |
dcbf9037 JB |
1438 | return reg->number; |
1439 | } | |
1440 | ||
1441 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1442 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1443 | register (e.g. Neon double or quad reg when either has been requested). | |
1444 | - If this is a Neon vector type with additional type information, fill | |
1445 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1446 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1447 | |
1448 | static int | |
1449 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
1450 | enum arm_reg_type *rtype, struct neon_type_el *vectype) | |
1451 | { | |
1452 | struct neon_typed_alias atype; | |
1453 | char *str = *ccp; | |
1454 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1455 | ||
1456 | if (reg == FAIL) | |
1457 | return FAIL; | |
1458 | ||
1459 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1460 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1461 | { | |
1462 | first_error (_("register operand expected, but got scalar")); | |
1463 | return FAIL; | |
1464 | } | |
1465 | ||
1466 | if (vectype) | |
1467 | *vectype = atype.eltype; | |
1468 | ||
1469 | *ccp = str; | |
1470 | ||
1471 | return reg; | |
1472 | } | |
1473 | ||
1474 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1475 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1476 | ||
5287ad62 JB |
1477 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1478 | have enough information to be able to do a good job bounds-checking. So, we | |
1479 | just do easy checks here, and do further checks later. */ | |
1480 | ||
1481 | static int | |
dcbf9037 | 1482 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1483 | { |
dcbf9037 | 1484 | int reg; |
5287ad62 | 1485 | char *str = *ccp; |
dcbf9037 | 1486 | struct neon_typed_alias atype; |
5f4273c7 | 1487 | |
dcbf9037 | 1488 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1489 | |
dcbf9037 | 1490 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1491 | return FAIL; |
5f4273c7 | 1492 | |
dcbf9037 | 1493 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1494 | { |
dcbf9037 | 1495 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1496 | return FAIL; |
1497 | } | |
dcbf9037 | 1498 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1499 | { |
dcbf9037 | 1500 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1501 | return FAIL; |
1502 | } | |
5f4273c7 | 1503 | |
dcbf9037 JB |
1504 | if (type) |
1505 | *type = atype.eltype; | |
5f4273c7 | 1506 | |
5287ad62 | 1507 | *ccp = str; |
5f4273c7 | 1508 | |
dcbf9037 | 1509 | return reg * 16 + atype.index; |
5287ad62 JB |
1510 | } |
1511 | ||
c19d1205 | 1512 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1513 | |
c19d1205 ZW |
1514 | static long |
1515 | parse_reg_list (char ** strp) | |
1516 | { | |
1517 | char * str = * strp; | |
1518 | long range = 0; | |
1519 | int another_range; | |
a737bd4d | 1520 | |
c19d1205 ZW |
1521 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1522 | do | |
6057a28f | 1523 | { |
c19d1205 | 1524 | another_range = 0; |
a737bd4d | 1525 | |
c19d1205 ZW |
1526 | if (*str == '{') |
1527 | { | |
1528 | int in_range = 0; | |
1529 | int cur_reg = -1; | |
a737bd4d | 1530 | |
c19d1205 ZW |
1531 | str++; |
1532 | do | |
1533 | { | |
1534 | int reg; | |
6057a28f | 1535 | |
dcbf9037 | 1536 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1537 | { |
dcbf9037 | 1538 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1539 | return FAIL; |
1540 | } | |
a737bd4d | 1541 | |
c19d1205 ZW |
1542 | if (in_range) |
1543 | { | |
1544 | int i; | |
a737bd4d | 1545 | |
c19d1205 ZW |
1546 | if (reg <= cur_reg) |
1547 | { | |
dcbf9037 | 1548 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1549 | return FAIL; |
1550 | } | |
40a18ebd | 1551 | |
c19d1205 ZW |
1552 | for (i = cur_reg + 1; i < reg; i++) |
1553 | { | |
1554 | if (range & (1 << i)) | |
1555 | as_tsktsk | |
1556 | (_("Warning: duplicated register (r%d) in register list"), | |
1557 | i); | |
1558 | else | |
1559 | range |= 1 << i; | |
1560 | } | |
1561 | in_range = 0; | |
1562 | } | |
a737bd4d | 1563 | |
c19d1205 ZW |
1564 | if (range & (1 << reg)) |
1565 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1566 | reg); | |
1567 | else if (reg <= cur_reg) | |
1568 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1569 | |
c19d1205 ZW |
1570 | range |= 1 << reg; |
1571 | cur_reg = reg; | |
1572 | } | |
1573 | while (skip_past_comma (&str) != FAIL | |
1574 | || (in_range = 1, *str++ == '-')); | |
1575 | str--; | |
a737bd4d | 1576 | |
c19d1205 ZW |
1577 | if (*str++ != '}') |
1578 | { | |
dcbf9037 | 1579 | first_error (_("missing `}'")); |
c19d1205 ZW |
1580 | return FAIL; |
1581 | } | |
1582 | } | |
1583 | else | |
1584 | { | |
1585 | expressionS expr; | |
40a18ebd | 1586 | |
c19d1205 ZW |
1587 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1588 | return FAIL; | |
40a18ebd | 1589 | |
c19d1205 ZW |
1590 | if (expr.X_op == O_constant) |
1591 | { | |
1592 | if (expr.X_add_number | |
1593 | != (expr.X_add_number & 0x0000ffff)) | |
1594 | { | |
1595 | inst.error = _("invalid register mask"); | |
1596 | return FAIL; | |
1597 | } | |
a737bd4d | 1598 | |
c19d1205 ZW |
1599 | if ((range & expr.X_add_number) != 0) |
1600 | { | |
1601 | int regno = range & expr.X_add_number; | |
a737bd4d | 1602 | |
c19d1205 ZW |
1603 | regno &= -regno; |
1604 | regno = (1 << regno) - 1; | |
1605 | as_tsktsk | |
1606 | (_("Warning: duplicated register (r%d) in register list"), | |
1607 | regno); | |
1608 | } | |
a737bd4d | 1609 | |
c19d1205 ZW |
1610 | range |= expr.X_add_number; |
1611 | } | |
1612 | else | |
1613 | { | |
1614 | if (inst.reloc.type != 0) | |
1615 | { | |
1616 | inst.error = _("expression too complex"); | |
1617 | return FAIL; | |
1618 | } | |
a737bd4d | 1619 | |
c19d1205 ZW |
1620 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1621 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1622 | inst.reloc.pc_rel = 0; | |
1623 | } | |
1624 | } | |
a737bd4d | 1625 | |
c19d1205 ZW |
1626 | if (*str == '|' || *str == '+') |
1627 | { | |
1628 | str++; | |
1629 | another_range = 1; | |
1630 | } | |
a737bd4d | 1631 | } |
c19d1205 | 1632 | while (another_range); |
a737bd4d | 1633 | |
c19d1205 ZW |
1634 | *strp = str; |
1635 | return range; | |
a737bd4d NC |
1636 | } |
1637 | ||
5287ad62 JB |
1638 | /* Types of registers in a list. */ |
1639 | ||
1640 | enum reg_list_els | |
1641 | { | |
1642 | REGLIST_VFP_S, | |
1643 | REGLIST_VFP_D, | |
1644 | REGLIST_NEON_D | |
1645 | }; | |
1646 | ||
c19d1205 ZW |
1647 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1648 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1649 | register. Parses registers of type ETYPE. |
1650 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1651 | - Q registers can be used to specify pairs of D registers | |
1652 | - { } can be omitted from around a singleton register list | |
1653 | FIXME: This is not implemented, as it would require backtracking in | |
1654 | some cases, e.g.: | |
1655 | vtbl.8 d3,d4,d5 | |
1656 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1657 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1658 | - 32 D registers may be used (also true for VFPv3). |
1659 | FIXME: Types are ignored in these register lists, which is probably a | |
1660 | bug. */ | |
6057a28f | 1661 | |
c19d1205 | 1662 | static int |
037e8744 | 1663 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1664 | { |
037e8744 | 1665 | char *str = *ccp; |
c19d1205 ZW |
1666 | int base_reg; |
1667 | int new_base; | |
5287ad62 JB |
1668 | enum arm_reg_type regtype = 0; |
1669 | int max_regs = 0; | |
c19d1205 ZW |
1670 | int count = 0; |
1671 | int warned = 0; | |
1672 | unsigned long mask = 0; | |
a737bd4d | 1673 | int i; |
6057a28f | 1674 | |
037e8744 | 1675 | if (*str != '{') |
5287ad62 JB |
1676 | { |
1677 | inst.error = _("expecting {"); | |
1678 | return FAIL; | |
1679 | } | |
6057a28f | 1680 | |
037e8744 | 1681 | str++; |
6057a28f | 1682 | |
5287ad62 | 1683 | switch (etype) |
c19d1205 | 1684 | { |
5287ad62 | 1685 | case REGLIST_VFP_S: |
c19d1205 ZW |
1686 | regtype = REG_TYPE_VFS; |
1687 | max_regs = 32; | |
5287ad62 | 1688 | break; |
5f4273c7 | 1689 | |
5287ad62 JB |
1690 | case REGLIST_VFP_D: |
1691 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1692 | break; |
5f4273c7 | 1693 | |
b7fc2769 JB |
1694 | case REGLIST_NEON_D: |
1695 | regtype = REG_TYPE_NDQ; | |
1696 | break; | |
1697 | } | |
1698 | ||
1699 | if (etype != REGLIST_VFP_S) | |
1700 | { | |
b1cc4aeb PB |
1701 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1702 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
5287ad62 JB |
1703 | { |
1704 | max_regs = 32; | |
1705 | if (thumb_mode) | |
1706 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 1707 | fpu_vfp_ext_d32); |
5287ad62 JB |
1708 | else |
1709 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 1710 | fpu_vfp_ext_d32); |
5287ad62 JB |
1711 | } |
1712 | else | |
1713 | max_regs = 16; | |
c19d1205 | 1714 | } |
6057a28f | 1715 | |
c19d1205 | 1716 | base_reg = max_regs; |
a737bd4d | 1717 | |
c19d1205 ZW |
1718 | do |
1719 | { | |
5287ad62 | 1720 | int setmask = 1, addregs = 1; |
dcbf9037 | 1721 | |
037e8744 | 1722 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1723 | |
c19d1205 | 1724 | if (new_base == FAIL) |
a737bd4d | 1725 | { |
dcbf9037 | 1726 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1727 | return FAIL; |
1728 | } | |
5f4273c7 | 1729 | |
b7fc2769 JB |
1730 | if (new_base >= max_regs) |
1731 | { | |
1732 | first_error (_("register out of range in list")); | |
1733 | return FAIL; | |
1734 | } | |
5f4273c7 | 1735 | |
5287ad62 JB |
1736 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1737 | if (regtype == REG_TYPE_NQ) | |
1738 | { | |
1739 | setmask = 3; | |
1740 | addregs = 2; | |
1741 | } | |
1742 | ||
c19d1205 ZW |
1743 | if (new_base < base_reg) |
1744 | base_reg = new_base; | |
a737bd4d | 1745 | |
5287ad62 | 1746 | if (mask & (setmask << new_base)) |
c19d1205 | 1747 | { |
dcbf9037 | 1748 | first_error (_("invalid register list")); |
c19d1205 | 1749 | return FAIL; |
a737bd4d | 1750 | } |
a737bd4d | 1751 | |
c19d1205 ZW |
1752 | if ((mask >> new_base) != 0 && ! warned) |
1753 | { | |
1754 | as_tsktsk (_("register list not in ascending order")); | |
1755 | warned = 1; | |
1756 | } | |
0bbf2aa4 | 1757 | |
5287ad62 JB |
1758 | mask |= setmask << new_base; |
1759 | count += addregs; | |
0bbf2aa4 | 1760 | |
037e8744 | 1761 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1762 | { |
1763 | int high_range; | |
0bbf2aa4 | 1764 | |
037e8744 | 1765 | str++; |
0bbf2aa4 | 1766 | |
037e8744 | 1767 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
dcbf9037 | 1768 | == FAIL) |
c19d1205 ZW |
1769 | { |
1770 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1771 | return FAIL; | |
1772 | } | |
0bbf2aa4 | 1773 | |
b7fc2769 JB |
1774 | if (high_range >= max_regs) |
1775 | { | |
1776 | first_error (_("register out of range in list")); | |
1777 | return FAIL; | |
1778 | } | |
1779 | ||
5287ad62 JB |
1780 | if (regtype == REG_TYPE_NQ) |
1781 | high_range = high_range + 1; | |
1782 | ||
c19d1205 ZW |
1783 | if (high_range <= new_base) |
1784 | { | |
1785 | inst.error = _("register range not in ascending order"); | |
1786 | return FAIL; | |
1787 | } | |
0bbf2aa4 | 1788 | |
5287ad62 | 1789 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1790 | { |
5287ad62 | 1791 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1792 | { |
c19d1205 ZW |
1793 | inst.error = _("invalid register list"); |
1794 | return FAIL; | |
0bbf2aa4 | 1795 | } |
c19d1205 | 1796 | |
5287ad62 JB |
1797 | mask |= setmask << new_base; |
1798 | count += addregs; | |
0bbf2aa4 | 1799 | } |
0bbf2aa4 | 1800 | } |
0bbf2aa4 | 1801 | } |
037e8744 | 1802 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1803 | |
037e8744 | 1804 | str++; |
0bbf2aa4 | 1805 | |
c19d1205 ZW |
1806 | /* Sanity check -- should have raised a parse error above. */ |
1807 | if (count == 0 || count > max_regs) | |
1808 | abort (); | |
1809 | ||
1810 | *pbase = base_reg; | |
1811 | ||
1812 | /* Final test -- the registers must be consecutive. */ | |
1813 | mask >>= base_reg; | |
1814 | for (i = 0; i < count; i++) | |
1815 | { | |
1816 | if ((mask & (1u << i)) == 0) | |
1817 | { | |
1818 | inst.error = _("non-contiguous register range"); | |
1819 | return FAIL; | |
1820 | } | |
1821 | } | |
1822 | ||
037e8744 JB |
1823 | *ccp = str; |
1824 | ||
c19d1205 | 1825 | return count; |
b99bd4ef NC |
1826 | } |
1827 | ||
dcbf9037 JB |
1828 | /* True if two alias types are the same. */ |
1829 | ||
c921be7d | 1830 | static bfd_boolean |
dcbf9037 JB |
1831 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1832 | { | |
1833 | if (!a && !b) | |
c921be7d | 1834 | return TRUE; |
5f4273c7 | 1835 | |
dcbf9037 | 1836 | if (!a || !b) |
c921be7d | 1837 | return FALSE; |
dcbf9037 JB |
1838 | |
1839 | if (a->defined != b->defined) | |
c921be7d | 1840 | return FALSE; |
5f4273c7 | 1841 | |
dcbf9037 JB |
1842 | if ((a->defined & NTA_HASTYPE) != 0 |
1843 | && (a->eltype.type != b->eltype.type | |
1844 | || a->eltype.size != b->eltype.size)) | |
c921be7d | 1845 | return FALSE; |
dcbf9037 JB |
1846 | |
1847 | if ((a->defined & NTA_HASINDEX) != 0 | |
1848 | && (a->index != b->index)) | |
c921be7d | 1849 | return FALSE; |
5f4273c7 | 1850 | |
c921be7d | 1851 | return TRUE; |
dcbf9037 JB |
1852 | } |
1853 | ||
5287ad62 JB |
1854 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1855 | The base register is put in *PBASE. | |
dcbf9037 | 1856 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1857 | the return value. |
1858 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1859 | Bits [6:5] encode the list length (minus one). |
1860 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1861 | |
5287ad62 | 1862 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1863 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1864 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1865 | ||
1866 | static int | |
dcbf9037 JB |
1867 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
1868 | struct neon_type_el *eltype) | |
5287ad62 JB |
1869 | { |
1870 | char *ptr = *str; | |
1871 | int base_reg = -1; | |
1872 | int reg_incr = -1; | |
1873 | int count = 0; | |
1874 | int lane = -1; | |
1875 | int leading_brace = 0; | |
1876 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
1877 | int addregs = 1; | |
1878 | const char *const incr_error = "register stride must be 1 or 2"; | |
1879 | const char *const type_error = "mismatched element/structure types in list"; | |
dcbf9037 | 1880 | struct neon_typed_alias firsttype; |
5f4273c7 | 1881 | |
5287ad62 JB |
1882 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1883 | leading_brace = 1; | |
5f4273c7 | 1884 | |
5287ad62 JB |
1885 | do |
1886 | { | |
dcbf9037 JB |
1887 | struct neon_typed_alias atype; |
1888 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1889 | ||
5287ad62 JB |
1890 | if (getreg == FAIL) |
1891 | { | |
dcbf9037 | 1892 | first_error (_(reg_expected_msgs[rtype])); |
5287ad62 JB |
1893 | return FAIL; |
1894 | } | |
5f4273c7 | 1895 | |
5287ad62 JB |
1896 | if (base_reg == -1) |
1897 | { | |
1898 | base_reg = getreg; | |
1899 | if (rtype == REG_TYPE_NQ) | |
1900 | { | |
1901 | reg_incr = 1; | |
1902 | addregs = 2; | |
1903 | } | |
dcbf9037 | 1904 | firsttype = atype; |
5287ad62 JB |
1905 | } |
1906 | else if (reg_incr == -1) | |
1907 | { | |
1908 | reg_incr = getreg - base_reg; | |
1909 | if (reg_incr < 1 || reg_incr > 2) | |
1910 | { | |
dcbf9037 | 1911 | first_error (_(incr_error)); |
5287ad62 JB |
1912 | return FAIL; |
1913 | } | |
1914 | } | |
1915 | else if (getreg != base_reg + reg_incr * count) | |
1916 | { | |
dcbf9037 JB |
1917 | first_error (_(incr_error)); |
1918 | return FAIL; | |
1919 | } | |
1920 | ||
c921be7d | 1921 | if (! neon_alias_types_same (&atype, &firsttype)) |
dcbf9037 JB |
1922 | { |
1923 | first_error (_(type_error)); | |
5287ad62 JB |
1924 | return FAIL; |
1925 | } | |
5f4273c7 | 1926 | |
5287ad62 JB |
1927 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
1928 | modes. */ | |
1929 | if (ptr[0] == '-') | |
1930 | { | |
dcbf9037 | 1931 | struct neon_typed_alias htype; |
5287ad62 JB |
1932 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; |
1933 | if (lane == -1) | |
1934 | lane = NEON_INTERLEAVE_LANES; | |
1935 | else if (lane != NEON_INTERLEAVE_LANES) | |
1936 | { | |
dcbf9037 | 1937 | first_error (_(type_error)); |
5287ad62 JB |
1938 | return FAIL; |
1939 | } | |
1940 | if (reg_incr == -1) | |
1941 | reg_incr = 1; | |
1942 | else if (reg_incr != 1) | |
1943 | { | |
dcbf9037 | 1944 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); |
5287ad62 JB |
1945 | return FAIL; |
1946 | } | |
1947 | ptr++; | |
dcbf9037 | 1948 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); |
5287ad62 JB |
1949 | if (hireg == FAIL) |
1950 | { | |
dcbf9037 JB |
1951 | first_error (_(reg_expected_msgs[rtype])); |
1952 | return FAIL; | |
1953 | } | |
c921be7d | 1954 | if (! neon_alias_types_same (&htype, &firsttype)) |
dcbf9037 JB |
1955 | { |
1956 | first_error (_(type_error)); | |
5287ad62 JB |
1957 | return FAIL; |
1958 | } | |
1959 | count += hireg + dregs - getreg; | |
1960 | continue; | |
1961 | } | |
5f4273c7 | 1962 | |
5287ad62 JB |
1963 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
1964 | if (rtype == REG_TYPE_NQ) | |
1965 | { | |
1966 | count += 2; | |
1967 | continue; | |
1968 | } | |
5f4273c7 | 1969 | |
dcbf9037 | 1970 | if ((atype.defined & NTA_HASINDEX) != 0) |
5287ad62 | 1971 | { |
dcbf9037 JB |
1972 | if (lane == -1) |
1973 | lane = atype.index; | |
1974 | else if (lane != atype.index) | |
5287ad62 | 1975 | { |
dcbf9037 JB |
1976 | first_error (_(type_error)); |
1977 | return FAIL; | |
5287ad62 JB |
1978 | } |
1979 | } | |
1980 | else if (lane == -1) | |
1981 | lane = NEON_INTERLEAVE_LANES; | |
1982 | else if (lane != NEON_INTERLEAVE_LANES) | |
1983 | { | |
dcbf9037 | 1984 | first_error (_(type_error)); |
5287ad62 JB |
1985 | return FAIL; |
1986 | } | |
1987 | count++; | |
1988 | } | |
1989 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 1990 | |
5287ad62 JB |
1991 | /* No lane set by [x]. We must be interleaving structures. */ |
1992 | if (lane == -1) | |
1993 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 1994 | |
5287ad62 JB |
1995 | /* Sanity check. */ |
1996 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
1997 | || (count > 1 && reg_incr == -1)) | |
1998 | { | |
dcbf9037 | 1999 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2000 | return FAIL; |
2001 | } | |
2002 | ||
2003 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2004 | { | |
dcbf9037 | 2005 | first_error (_("expected }")); |
5287ad62 JB |
2006 | return FAIL; |
2007 | } | |
5f4273c7 | 2008 | |
5287ad62 JB |
2009 | if (reg_incr == -1) |
2010 | reg_incr = 1; | |
2011 | ||
dcbf9037 JB |
2012 | if (eltype) |
2013 | *eltype = firsttype.eltype; | |
2014 | ||
5287ad62 JB |
2015 | *pbase = base_reg; |
2016 | *str = ptr; | |
5f4273c7 | 2017 | |
5287ad62 JB |
2018 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2019 | } | |
2020 | ||
c19d1205 ZW |
2021 | /* Parse an explicit relocation suffix on an expression. This is |
2022 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2023 | arm_reloc_hsh contains no entries, so this function can only | |
2024 | succeed if there is no () after the word. Returns -1 on error, | |
2025 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
2026 | static int | |
2027 | parse_reloc (char **str) | |
b99bd4ef | 2028 | { |
c19d1205 ZW |
2029 | struct reloc_entry *r; |
2030 | char *p, *q; | |
b99bd4ef | 2031 | |
c19d1205 ZW |
2032 | if (**str != '(') |
2033 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2034 | |
c19d1205 ZW |
2035 | p = *str + 1; |
2036 | q = p; | |
2037 | ||
2038 | while (*q && *q != ')' && *q != ',') | |
2039 | q++; | |
2040 | if (*q != ')') | |
2041 | return -1; | |
2042 | ||
2043 | if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
2044 | return -1; | |
2045 | ||
2046 | *str = q + 1; | |
2047 | return r->reloc; | |
b99bd4ef NC |
2048 | } |
2049 | ||
c19d1205 ZW |
2050 | /* Directives: register aliases. */ |
2051 | ||
dcbf9037 | 2052 | static struct reg_entry * |
c19d1205 | 2053 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 2054 | { |
c19d1205 ZW |
2055 | struct reg_entry *new; |
2056 | const char *name; | |
b99bd4ef | 2057 | |
c19d1205 ZW |
2058 | if ((new = hash_find (arm_reg_hsh, str)) != 0) |
2059 | { | |
2060 | if (new->builtin) | |
2061 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); | |
b99bd4ef | 2062 | |
c19d1205 ZW |
2063 | /* Only warn about a redefinition if it's not defined as the |
2064 | same register. */ | |
2065 | else if (new->number != number || new->type != type) | |
2066 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
69b97547 | 2067 | |
d929913e | 2068 | return NULL; |
c19d1205 | 2069 | } |
b99bd4ef | 2070 | |
c19d1205 ZW |
2071 | name = xstrdup (str); |
2072 | new = xmalloc (sizeof (struct reg_entry)); | |
b99bd4ef | 2073 | |
c19d1205 ZW |
2074 | new->name = name; |
2075 | new->number = number; | |
2076 | new->type = type; | |
2077 | new->builtin = FALSE; | |
dcbf9037 | 2078 | new->neon = NULL; |
b99bd4ef | 2079 | |
5a49b8ac | 2080 | if (hash_insert (arm_reg_hsh, name, (void *) new)) |
c19d1205 | 2081 | abort (); |
5f4273c7 | 2082 | |
dcbf9037 JB |
2083 | return new; |
2084 | } | |
2085 | ||
2086 | static void | |
2087 | insert_neon_reg_alias (char *str, int number, int type, | |
2088 | struct neon_typed_alias *atype) | |
2089 | { | |
2090 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2091 | |
dcbf9037 JB |
2092 | if (!reg) |
2093 | { | |
2094 | first_error (_("attempt to redefine typed alias")); | |
2095 | return; | |
2096 | } | |
5f4273c7 | 2097 | |
dcbf9037 JB |
2098 | if (atype) |
2099 | { | |
2100 | reg->neon = xmalloc (sizeof (struct neon_typed_alias)); | |
2101 | *reg->neon = *atype; | |
2102 | } | |
c19d1205 | 2103 | } |
b99bd4ef | 2104 | |
c19d1205 | 2105 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2106 | |
c19d1205 | 2107 | new_register_name .req existing_register_name |
b99bd4ef | 2108 | |
c19d1205 | 2109 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2110 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2111 | |
d929913e | 2112 | static bfd_boolean |
c19d1205 ZW |
2113 | create_register_alias (char * newname, char *p) |
2114 | { | |
2115 | struct reg_entry *old; | |
2116 | char *oldname, *nbuf; | |
2117 | size_t nlen; | |
b99bd4ef | 2118 | |
c19d1205 ZW |
2119 | /* The input scrubber ensures that whitespace after the mnemonic is |
2120 | collapsed to single spaces. */ | |
2121 | oldname = p; | |
2122 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2123 | return FALSE; |
b99bd4ef | 2124 | |
c19d1205 ZW |
2125 | oldname += 6; |
2126 | if (*oldname == '\0') | |
d929913e | 2127 | return FALSE; |
b99bd4ef | 2128 | |
c19d1205 ZW |
2129 | old = hash_find (arm_reg_hsh, oldname); |
2130 | if (!old) | |
b99bd4ef | 2131 | { |
c19d1205 | 2132 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2133 | return TRUE; |
b99bd4ef NC |
2134 | } |
2135 | ||
c19d1205 ZW |
2136 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2137 | the desired alias name, and p points to its end. If not, then | |
2138 | the desired alias name is in the global original_case_string. */ | |
2139 | #ifdef TC_CASE_SENSITIVE | |
2140 | nlen = p - newname; | |
2141 | #else | |
2142 | newname = original_case_string; | |
2143 | nlen = strlen (newname); | |
2144 | #endif | |
b99bd4ef | 2145 | |
c19d1205 ZW |
2146 | nbuf = alloca (nlen + 1); |
2147 | memcpy (nbuf, newname, nlen); | |
2148 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2149 | |
c19d1205 ZW |
2150 | /* Create aliases under the new name as stated; an all-lowercase |
2151 | version of the new name; and an all-uppercase version of the new | |
2152 | name. */ | |
d929913e NC |
2153 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2154 | { | |
2155 | for (p = nbuf; *p; p++) | |
2156 | *p = TOUPPER (*p); | |
c19d1205 | 2157 | |
d929913e NC |
2158 | if (strncmp (nbuf, newname, nlen)) |
2159 | { | |
2160 | /* If this attempt to create an additional alias fails, do not bother | |
2161 | trying to create the all-lower case alias. We will fail and issue | |
2162 | a second, duplicate error message. This situation arises when the | |
2163 | programmer does something like: | |
2164 | foo .req r0 | |
2165 | Foo .req r1 | |
2166 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2167 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2168 | first .req. */ |
2169 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
2170 | return TRUE; | |
2171 | } | |
c19d1205 | 2172 | |
d929913e NC |
2173 | for (p = nbuf; *p; p++) |
2174 | *p = TOLOWER (*p); | |
c19d1205 | 2175 | |
d929913e NC |
2176 | if (strncmp (nbuf, newname, nlen)) |
2177 | insert_reg_alias (nbuf, old->number, old->type); | |
2178 | } | |
c19d1205 | 2179 | |
d929913e | 2180 | return TRUE; |
b99bd4ef NC |
2181 | } |
2182 | ||
dcbf9037 JB |
2183 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2184 | X .dn d5.s32[1] | |
2185 | Y .qn 6.s16 | |
2186 | Z .dn d7 | |
2187 | T .dn Z[0] | |
2188 | These typed registers can be used instead of the types specified after the | |
2189 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2190 | specified directly, e.g.: | |
5f4273c7 | 2191 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2192 | |
c921be7d | 2193 | static bfd_boolean |
dcbf9037 JB |
2194 | create_neon_reg_alias (char *newname, char *p) |
2195 | { | |
2196 | enum arm_reg_type basetype; | |
2197 | struct reg_entry *basereg; | |
2198 | struct reg_entry mybasereg; | |
2199 | struct neon_type ntype; | |
2200 | struct neon_typed_alias typeinfo; | |
2201 | char *namebuf, *nameend; | |
2202 | int namelen; | |
5f4273c7 | 2203 | |
dcbf9037 JB |
2204 | typeinfo.defined = 0; |
2205 | typeinfo.eltype.type = NT_invtype; | |
2206 | typeinfo.eltype.size = -1; | |
2207 | typeinfo.index = -1; | |
5f4273c7 | 2208 | |
dcbf9037 | 2209 | nameend = p; |
5f4273c7 | 2210 | |
dcbf9037 JB |
2211 | if (strncmp (p, " .dn ", 5) == 0) |
2212 | basetype = REG_TYPE_VFD; | |
2213 | else if (strncmp (p, " .qn ", 5) == 0) | |
2214 | basetype = REG_TYPE_NQ; | |
2215 | else | |
c921be7d | 2216 | return FALSE; |
5f4273c7 | 2217 | |
dcbf9037 | 2218 | p += 5; |
5f4273c7 | 2219 | |
dcbf9037 | 2220 | if (*p == '\0') |
c921be7d | 2221 | return FALSE; |
5f4273c7 | 2222 | |
dcbf9037 JB |
2223 | basereg = arm_reg_parse_multi (&p); |
2224 | ||
2225 | if (basereg && basereg->type != basetype) | |
2226 | { | |
2227 | as_bad (_("bad type for register")); | |
c921be7d | 2228 | return FALSE; |
dcbf9037 JB |
2229 | } |
2230 | ||
2231 | if (basereg == NULL) | |
2232 | { | |
2233 | expressionS exp; | |
2234 | /* Try parsing as an integer. */ | |
2235 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2236 | if (exp.X_op != O_constant) | |
2237 | { | |
2238 | as_bad (_("expression must be constant")); | |
c921be7d | 2239 | return FALSE; |
dcbf9037 JB |
2240 | } |
2241 | basereg = &mybasereg; | |
2242 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
2243 | : exp.X_add_number; | |
2244 | basereg->neon = 0; | |
2245 | } | |
2246 | ||
2247 | if (basereg->neon) | |
2248 | typeinfo = *basereg->neon; | |
2249 | ||
2250 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2251 | { | |
2252 | /* We got a type. */ | |
2253 | if (typeinfo.defined & NTA_HASTYPE) | |
2254 | { | |
2255 | as_bad (_("can't redefine the type of a register alias")); | |
c921be7d | 2256 | return FALSE; |
dcbf9037 | 2257 | } |
5f4273c7 | 2258 | |
dcbf9037 JB |
2259 | typeinfo.defined |= NTA_HASTYPE; |
2260 | if (ntype.elems != 1) | |
2261 | { | |
2262 | as_bad (_("you must specify a single type only")); | |
c921be7d | 2263 | return FALSE; |
dcbf9037 JB |
2264 | } |
2265 | typeinfo.eltype = ntype.el[0]; | |
2266 | } | |
5f4273c7 | 2267 | |
dcbf9037 JB |
2268 | if (skip_past_char (&p, '[') == SUCCESS) |
2269 | { | |
2270 | expressionS exp; | |
2271 | /* We got a scalar index. */ | |
5f4273c7 | 2272 | |
dcbf9037 JB |
2273 | if (typeinfo.defined & NTA_HASINDEX) |
2274 | { | |
2275 | as_bad (_("can't redefine the index of a scalar alias")); | |
c921be7d | 2276 | return FALSE; |
dcbf9037 | 2277 | } |
5f4273c7 | 2278 | |
dcbf9037 | 2279 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2280 | |
dcbf9037 JB |
2281 | if (exp.X_op != O_constant) |
2282 | { | |
2283 | as_bad (_("scalar index must be constant")); | |
c921be7d | 2284 | return FALSE; |
dcbf9037 | 2285 | } |
5f4273c7 | 2286 | |
dcbf9037 JB |
2287 | typeinfo.defined |= NTA_HASINDEX; |
2288 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2289 | |
dcbf9037 JB |
2290 | if (skip_past_char (&p, ']') == FAIL) |
2291 | { | |
2292 | as_bad (_("expecting ]")); | |
c921be7d | 2293 | return FALSE; |
dcbf9037 JB |
2294 | } |
2295 | } | |
2296 | ||
2297 | namelen = nameend - newname; | |
2298 | namebuf = alloca (namelen + 1); | |
2299 | strncpy (namebuf, newname, namelen); | |
2300 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2301 | |
dcbf9037 JB |
2302 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
2303 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2304 | |
dcbf9037 JB |
2305 | /* Insert name in all uppercase. */ |
2306 | for (p = namebuf; *p; p++) | |
2307 | *p = TOUPPER (*p); | |
5f4273c7 | 2308 | |
dcbf9037 JB |
2309 | if (strncmp (namebuf, newname, namelen)) |
2310 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2311 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2312 | |
dcbf9037 JB |
2313 | /* Insert name in all lowercase. */ |
2314 | for (p = namebuf; *p; p++) | |
2315 | *p = TOLOWER (*p); | |
5f4273c7 | 2316 | |
dcbf9037 JB |
2317 | if (strncmp (namebuf, newname, namelen)) |
2318 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
2319 | typeinfo.defined != 0 ? &typeinfo : NULL); | |
5f4273c7 | 2320 | |
c921be7d | 2321 | return TRUE; |
dcbf9037 JB |
2322 | } |
2323 | ||
c19d1205 ZW |
2324 | /* Should never be called, as .req goes between the alias and the |
2325 | register name, not at the beginning of the line. */ | |
c921be7d | 2326 | |
b99bd4ef | 2327 | static void |
c19d1205 | 2328 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2329 | { |
c19d1205 ZW |
2330 | as_bad (_("invalid syntax for .req directive")); |
2331 | } | |
b99bd4ef | 2332 | |
dcbf9037 JB |
2333 | static void |
2334 | s_dn (int a ATTRIBUTE_UNUSED) | |
2335 | { | |
2336 | as_bad (_("invalid syntax for .dn directive")); | |
2337 | } | |
2338 | ||
2339 | static void | |
2340 | s_qn (int a ATTRIBUTE_UNUSED) | |
2341 | { | |
2342 | as_bad (_("invalid syntax for .qn directive")); | |
2343 | } | |
2344 | ||
c19d1205 ZW |
2345 | /* The .unreq directive deletes an alias which was previously defined |
2346 | by .req. For example: | |
b99bd4ef | 2347 | |
c19d1205 ZW |
2348 | my_alias .req r11 |
2349 | .unreq my_alias */ | |
b99bd4ef NC |
2350 | |
2351 | static void | |
c19d1205 | 2352 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2353 | { |
c19d1205 ZW |
2354 | char * name; |
2355 | char saved_char; | |
b99bd4ef | 2356 | |
c19d1205 ZW |
2357 | name = input_line_pointer; |
2358 | ||
2359 | while (*input_line_pointer != 0 | |
2360 | && *input_line_pointer != ' ' | |
2361 | && *input_line_pointer != '\n') | |
2362 | ++input_line_pointer; | |
2363 | ||
2364 | saved_char = *input_line_pointer; | |
2365 | *input_line_pointer = 0; | |
2366 | ||
2367 | if (!*name) | |
2368 | as_bad (_("invalid syntax for .unreq directive")); | |
2369 | else | |
2370 | { | |
2371 | struct reg_entry *reg = hash_find (arm_reg_hsh, name); | |
2372 | ||
2373 | if (!reg) | |
2374 | as_bad (_("unknown register alias '%s'"), name); | |
2375 | else if (reg->builtin) | |
2376 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
2377 | name); | |
2378 | else | |
2379 | { | |
d929913e NC |
2380 | char * p; |
2381 | char * nbuf; | |
2382 | ||
db0bc284 | 2383 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2384 | free ((char *) reg->name); |
dcbf9037 JB |
2385 | if (reg->neon) |
2386 | free (reg->neon); | |
c19d1205 | 2387 | free (reg); |
d929913e NC |
2388 | |
2389 | /* Also locate the all upper case and all lower case versions. | |
2390 | Do not complain if we cannot find one or the other as it | |
2391 | was probably deleted above. */ | |
5f4273c7 | 2392 | |
d929913e NC |
2393 | nbuf = strdup (name); |
2394 | for (p = nbuf; *p; p++) | |
2395 | *p = TOUPPER (*p); | |
2396 | reg = hash_find (arm_reg_hsh, nbuf); | |
2397 | if (reg) | |
2398 | { | |
db0bc284 | 2399 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2400 | free ((char *) reg->name); |
2401 | if (reg->neon) | |
2402 | free (reg->neon); | |
2403 | free (reg); | |
2404 | } | |
2405 | ||
2406 | for (p = nbuf; *p; p++) | |
2407 | *p = TOLOWER (*p); | |
2408 | reg = hash_find (arm_reg_hsh, nbuf); | |
2409 | if (reg) | |
2410 | { | |
db0bc284 | 2411 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2412 | free ((char *) reg->name); |
2413 | if (reg->neon) | |
2414 | free (reg->neon); | |
2415 | free (reg); | |
2416 | } | |
2417 | ||
2418 | free (nbuf); | |
c19d1205 ZW |
2419 | } |
2420 | } | |
b99bd4ef | 2421 | |
c19d1205 | 2422 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2423 | demand_empty_rest_of_line (); |
2424 | } | |
2425 | ||
c19d1205 ZW |
2426 | /* Directives: Instruction set selection. */ |
2427 | ||
2428 | #ifdef OBJ_ELF | |
2429 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2430 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2431 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2432 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2433 | ||
2434 | static enum mstate mapstate = MAP_UNDEFINED; | |
b99bd4ef | 2435 | |
e821645d | 2436 | void |
c19d1205 | 2437 | mapping_state (enum mstate state) |
b99bd4ef | 2438 | { |
a737bd4d | 2439 | symbolS * symbolP; |
c19d1205 ZW |
2440 | const char * symname; |
2441 | int type; | |
b99bd4ef | 2442 | |
c19d1205 ZW |
2443 | if (mapstate == state) |
2444 | /* The mapping symbol has already been emitted. | |
2445 | There is nothing else to do. */ | |
2446 | return; | |
b99bd4ef | 2447 | |
c19d1205 | 2448 | mapstate = state; |
b99bd4ef | 2449 | |
c19d1205 | 2450 | switch (state) |
b99bd4ef | 2451 | { |
c19d1205 ZW |
2452 | case MAP_DATA: |
2453 | symname = "$d"; | |
2454 | type = BSF_NO_FLAGS; | |
2455 | break; | |
2456 | case MAP_ARM: | |
2457 | symname = "$a"; | |
2458 | type = BSF_NO_FLAGS; | |
2459 | break; | |
2460 | case MAP_THUMB: | |
2461 | symname = "$t"; | |
2462 | type = BSF_NO_FLAGS; | |
2463 | break; | |
2464 | case MAP_UNDEFINED: | |
2465 | return; | |
2466 | default: | |
2467 | abort (); | |
2468 | } | |
2469 | ||
2470 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; | |
2471 | ||
2472 | symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now); | |
2473 | symbol_table_insert (symbolP); | |
2474 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; | |
2475 | ||
2476 | switch (state) | |
2477 | { | |
2478 | case MAP_ARM: | |
2479 | THUMB_SET_FUNC (symbolP, 0); | |
2480 | ARM_SET_THUMB (symbolP, 0); | |
2481 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2482 | break; | |
2483 | ||
2484 | case MAP_THUMB: | |
2485 | THUMB_SET_FUNC (symbolP, 1); | |
2486 | ARM_SET_THUMB (symbolP, 1); | |
2487 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2488 | break; | |
2489 | ||
2490 | case MAP_DATA: | |
2491 | default: | |
2492 | return; | |
2493 | } | |
2494 | } | |
2495 | #else | |
2496 | #define mapping_state(x) /* nothing */ | |
2497 | #endif | |
2498 | ||
2499 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2500 | ||
4343666d | 2501 | #ifdef OBJ_COFF |
c19d1205 ZW |
2502 | static symbolS * |
2503 | find_real_start (symbolS * symbolP) | |
2504 | { | |
2505 | char * real_start; | |
2506 | const char * name = S_GET_NAME (symbolP); | |
2507 | symbolS * new_target; | |
2508 | ||
2509 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2510 | #define STUB_NAME ".real_start_of" | |
2511 | ||
2512 | if (name == NULL) | |
2513 | abort (); | |
2514 | ||
37f6032b ZW |
2515 | /* The compiler may generate BL instructions to local labels because |
2516 | it needs to perform a branch to a far away location. These labels | |
2517 | do not have a corresponding ".real_start_of" label. We check | |
2518 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2519 | the ".real_start_of" convention for nonlocal branches. */ | |
2520 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2521 | return symbolP; |
2522 | ||
37f6032b | 2523 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2524 | new_target = symbol_find (real_start); |
2525 | ||
2526 | if (new_target == NULL) | |
2527 | { | |
bd3ba5d1 | 2528 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2529 | new_target = symbolP; |
2530 | } | |
2531 | ||
c19d1205 ZW |
2532 | return new_target; |
2533 | } | |
4343666d | 2534 | #endif |
c19d1205 ZW |
2535 | |
2536 | static void | |
2537 | opcode_select (int width) | |
2538 | { | |
2539 | switch (width) | |
2540 | { | |
2541 | case 16: | |
2542 | if (! thumb_mode) | |
2543 | { | |
e74cfd16 | 2544 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2545 | as_bad (_("selected processor does not support THUMB opcodes")); |
2546 | ||
2547 | thumb_mode = 1; | |
2548 | /* No need to force the alignment, since we will have been | |
2549 | coming from ARM mode, which is word-aligned. */ | |
2550 | record_alignment (now_seg, 1); | |
2551 | } | |
2552 | mapping_state (MAP_THUMB); | |
2553 | break; | |
2554 | ||
2555 | case 32: | |
2556 | if (thumb_mode) | |
2557 | { | |
e74cfd16 | 2558 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2559 | as_bad (_("selected processor does not support ARM opcodes")); |
2560 | ||
2561 | thumb_mode = 0; | |
2562 | ||
2563 | if (!need_pass_2) | |
2564 | frag_align (2, 0, 0); | |
2565 | ||
2566 | record_alignment (now_seg, 1); | |
2567 | } | |
2568 | mapping_state (MAP_ARM); | |
2569 | break; | |
2570 | ||
2571 | default: | |
2572 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2573 | } | |
2574 | } | |
2575 | ||
2576 | static void | |
2577 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2578 | { | |
2579 | opcode_select (32); | |
2580 | demand_empty_rest_of_line (); | |
2581 | } | |
2582 | ||
2583 | static void | |
2584 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2585 | { | |
2586 | opcode_select (16); | |
2587 | demand_empty_rest_of_line (); | |
2588 | } | |
2589 | ||
2590 | static void | |
2591 | s_code (int unused ATTRIBUTE_UNUSED) | |
2592 | { | |
2593 | int temp; | |
2594 | ||
2595 | temp = get_absolute_expression (); | |
2596 | switch (temp) | |
2597 | { | |
2598 | case 16: | |
2599 | case 32: | |
2600 | opcode_select (temp); | |
2601 | break; | |
2602 | ||
2603 | default: | |
2604 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2605 | } | |
2606 | } | |
2607 | ||
2608 | static void | |
2609 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2610 | { | |
2611 | /* If we are not already in thumb mode go into it, EVEN if | |
2612 | the target processor does not support thumb instructions. | |
2613 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2614 | to compile interworking support functions even if the | |
2615 | target processor should not support interworking. */ | |
2616 | if (! thumb_mode) | |
2617 | { | |
2618 | thumb_mode = 2; | |
2619 | record_alignment (now_seg, 1); | |
2620 | } | |
2621 | ||
2622 | demand_empty_rest_of_line (); | |
2623 | } | |
2624 | ||
2625 | static void | |
2626 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2627 | { | |
2628 | s_thumb (0); | |
2629 | ||
2630 | /* The following label is the name/address of the start of a Thumb function. | |
2631 | We need to know this for the interworking support. */ | |
2632 | label_is_thumb_function_name = TRUE; | |
2633 | } | |
2634 | ||
2635 | /* Perform a .set directive, but also mark the alias as | |
2636 | being a thumb function. */ | |
2637 | ||
2638 | static void | |
2639 | s_thumb_set (int equiv) | |
2640 | { | |
2641 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2642 | We cannot just call that code as we need to get at the symbol that | |
2643 | is created. */ | |
2644 | char * name; | |
2645 | char delim; | |
2646 | char * end_name; | |
2647 | symbolS * symbolP; | |
2648 | ||
2649 | /* Especial apologies for the random logic: | |
2650 | This just grew, and could be parsed much more simply! | |
2651 | Dean - in haste. */ | |
2652 | name = input_line_pointer; | |
2653 | delim = get_symbol_end (); | |
2654 | end_name = input_line_pointer; | |
2655 | *end_name = delim; | |
2656 | ||
2657 | if (*input_line_pointer != ',') | |
2658 | { | |
2659 | *end_name = 0; | |
2660 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2661 | *end_name = delim; |
2662 | ignore_rest_of_line (); | |
2663 | return; | |
2664 | } | |
2665 | ||
2666 | input_line_pointer++; | |
2667 | *end_name = 0; | |
2668 | ||
2669 | if (name[0] == '.' && name[1] == '\0') | |
2670 | { | |
2671 | /* XXX - this should not happen to .thumb_set. */ | |
2672 | abort (); | |
2673 | } | |
2674 | ||
2675 | if ((symbolP = symbol_find (name)) == NULL | |
2676 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2677 | { | |
2678 | #ifndef NO_LISTING | |
2679 | /* When doing symbol listings, play games with dummy fragments living | |
2680 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2681 | for this symbol. */ |
b99bd4ef NC |
2682 | if (listing & LISTING_SYMBOLS) |
2683 | { | |
2684 | extern struct list_info_struct * listing_tail; | |
a737bd4d | 2685 | fragS * dummy_frag = xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2686 | |
2687 | memset (dummy_frag, 0, sizeof (fragS)); | |
2688 | dummy_frag->fr_type = rs_fill; | |
2689 | dummy_frag->line = listing_tail; | |
2690 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2691 | dummy_frag->fr_symbol = symbolP; | |
2692 | } | |
2693 | else | |
2694 | #endif | |
2695 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2696 | ||
2697 | #ifdef OBJ_COFF | |
2698 | /* "set" symbols are local unless otherwise specified. */ | |
2699 | SF_SET_LOCAL (symbolP); | |
2700 | #endif /* OBJ_COFF */ | |
2701 | } /* Make a new symbol. */ | |
2702 | ||
2703 | symbol_table_insert (symbolP); | |
2704 | ||
2705 | * end_name = delim; | |
2706 | ||
2707 | if (equiv | |
2708 | && S_IS_DEFINED (symbolP) | |
2709 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2710 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2711 | ||
2712 | pseudo_set (symbolP); | |
2713 | ||
2714 | demand_empty_rest_of_line (); | |
2715 | ||
c19d1205 | 2716 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2717 | |
2718 | THUMB_SET_FUNC (symbolP, 1); | |
2719 | ARM_SET_THUMB (symbolP, 1); | |
2720 | #if defined OBJ_ELF || defined OBJ_COFF | |
2721 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2722 | #endif | |
2723 | } | |
2724 | ||
c19d1205 | 2725 | /* Directives: Mode selection. */ |
b99bd4ef | 2726 | |
c19d1205 ZW |
2727 | /* .syntax [unified|divided] - choose the new unified syntax |
2728 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2729 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2730 | static void |
c19d1205 | 2731 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2732 | { |
c19d1205 ZW |
2733 | char *name, delim; |
2734 | ||
2735 | name = input_line_pointer; | |
2736 | delim = get_symbol_end (); | |
2737 | ||
2738 | if (!strcasecmp (name, "unified")) | |
2739 | unified_syntax = TRUE; | |
2740 | else if (!strcasecmp (name, "divided")) | |
2741 | unified_syntax = FALSE; | |
2742 | else | |
2743 | { | |
2744 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2745 | return; | |
2746 | } | |
2747 | *input_line_pointer = delim; | |
b99bd4ef NC |
2748 | demand_empty_rest_of_line (); |
2749 | } | |
2750 | ||
c19d1205 ZW |
2751 | /* Directives: sectioning and alignment. */ |
2752 | ||
2753 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
2754 | ||
b99bd4ef | 2755 | static void |
c19d1205 | 2756 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2757 | { |
a737bd4d | 2758 | int temp; |
dce323d1 | 2759 | bfd_boolean fill_p; |
c19d1205 ZW |
2760 | long temp_fill; |
2761 | long max_alignment = 15; | |
b99bd4ef NC |
2762 | |
2763 | temp = get_absolute_expression (); | |
c19d1205 ZW |
2764 | if (temp > max_alignment) |
2765 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
2766 | else if (temp < 0) | |
b99bd4ef | 2767 | { |
c19d1205 ZW |
2768 | as_bad (_("alignment negative. 0 assumed.")); |
2769 | temp = 0; | |
2770 | } | |
b99bd4ef | 2771 | |
c19d1205 ZW |
2772 | if (*input_line_pointer == ',') |
2773 | { | |
2774 | input_line_pointer++; | |
2775 | temp_fill = get_absolute_expression (); | |
dce323d1 | 2776 | fill_p = TRUE; |
b99bd4ef | 2777 | } |
c19d1205 | 2778 | else |
dce323d1 PB |
2779 | { |
2780 | fill_p = FALSE; | |
2781 | temp_fill = 0; | |
2782 | } | |
b99bd4ef | 2783 | |
c19d1205 ZW |
2784 | if (!temp) |
2785 | temp = 2; | |
b99bd4ef | 2786 | |
c19d1205 ZW |
2787 | /* Only make a frag if we HAVE to. */ |
2788 | if (temp && !need_pass_2) | |
dce323d1 PB |
2789 | { |
2790 | if (!fill_p && subseg_text_p (now_seg)) | |
2791 | frag_align_code (temp, 0); | |
2792 | else | |
2793 | frag_align (temp, (int) temp_fill, 0); | |
2794 | } | |
c19d1205 ZW |
2795 | demand_empty_rest_of_line (); |
2796 | ||
2797 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
2798 | } |
2799 | ||
c19d1205 ZW |
2800 | static void |
2801 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2802 | { |
c19d1205 ZW |
2803 | /* We don't support putting frags in the BSS segment, we fake it by |
2804 | marking in_bss, then looking at s_skip for clues. */ | |
2805 | subseg_set (bss_section, 0); | |
2806 | demand_empty_rest_of_line (); | |
2807 | mapping_state (MAP_DATA); | |
2808 | } | |
b99bd4ef | 2809 | |
c19d1205 ZW |
2810 | static void |
2811 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2812 | { | |
2813 | /* Never make frag if expect extra pass. */ | |
2814 | if (!need_pass_2) | |
2815 | frag_align (1, 0, 0); | |
b99bd4ef | 2816 | |
c19d1205 | 2817 | record_alignment (now_seg, 1); |
b99bd4ef | 2818 | |
c19d1205 | 2819 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2820 | } |
2821 | ||
c19d1205 | 2822 | /* Directives: Literal pools. */ |
a737bd4d | 2823 | |
c19d1205 ZW |
2824 | static literal_pool * |
2825 | find_literal_pool (void) | |
a737bd4d | 2826 | { |
c19d1205 | 2827 | literal_pool * pool; |
a737bd4d | 2828 | |
c19d1205 | 2829 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 2830 | { |
c19d1205 ZW |
2831 | if (pool->section == now_seg |
2832 | && pool->sub_section == now_subseg) | |
2833 | break; | |
a737bd4d NC |
2834 | } |
2835 | ||
c19d1205 | 2836 | return pool; |
a737bd4d NC |
2837 | } |
2838 | ||
c19d1205 ZW |
2839 | static literal_pool * |
2840 | find_or_make_literal_pool (void) | |
a737bd4d | 2841 | { |
c19d1205 ZW |
2842 | /* Next literal pool ID number. */ |
2843 | static unsigned int latest_pool_num = 1; | |
2844 | literal_pool * pool; | |
a737bd4d | 2845 | |
c19d1205 | 2846 | pool = find_literal_pool (); |
a737bd4d | 2847 | |
c19d1205 | 2848 | if (pool == NULL) |
a737bd4d | 2849 | { |
c19d1205 ZW |
2850 | /* Create a new pool. */ |
2851 | pool = xmalloc (sizeof (* pool)); | |
2852 | if (! pool) | |
2853 | return NULL; | |
a737bd4d | 2854 | |
c19d1205 ZW |
2855 | pool->next_free_entry = 0; |
2856 | pool->section = now_seg; | |
2857 | pool->sub_section = now_subseg; | |
2858 | pool->next = list_of_pools; | |
2859 | pool->symbol = NULL; | |
2860 | ||
2861 | /* Add it to the list. */ | |
2862 | list_of_pools = pool; | |
a737bd4d | 2863 | } |
a737bd4d | 2864 | |
c19d1205 ZW |
2865 | /* New pools, and emptied pools, will have a NULL symbol. */ |
2866 | if (pool->symbol == NULL) | |
a737bd4d | 2867 | { |
c19d1205 ZW |
2868 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
2869 | (valueT) 0, &zero_address_frag); | |
2870 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
2871 | } |
2872 | ||
c19d1205 ZW |
2873 | /* Done. */ |
2874 | return pool; | |
a737bd4d NC |
2875 | } |
2876 | ||
c19d1205 | 2877 | /* Add the literal in the global 'inst' |
5f4273c7 | 2878 | structure to the relevant literal pool. */ |
b99bd4ef NC |
2879 | |
2880 | static int | |
c19d1205 | 2881 | add_to_lit_pool (void) |
b99bd4ef | 2882 | { |
c19d1205 ZW |
2883 | literal_pool * pool; |
2884 | unsigned int entry; | |
b99bd4ef | 2885 | |
c19d1205 ZW |
2886 | pool = find_or_make_literal_pool (); |
2887 | ||
2888 | /* Check if this literal value is already in the pool. */ | |
2889 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 2890 | { |
c19d1205 ZW |
2891 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
2892 | && (inst.reloc.exp.X_op == O_constant) | |
2893 | && (pool->literals[entry].X_add_number | |
2894 | == inst.reloc.exp.X_add_number) | |
2895 | && (pool->literals[entry].X_unsigned | |
2896 | == inst.reloc.exp.X_unsigned)) | |
2897 | break; | |
2898 | ||
2899 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
2900 | && (inst.reloc.exp.X_op == O_symbol) | |
2901 | && (pool->literals[entry].X_add_number | |
2902 | == inst.reloc.exp.X_add_number) | |
2903 | && (pool->literals[entry].X_add_symbol | |
2904 | == inst.reloc.exp.X_add_symbol) | |
2905 | && (pool->literals[entry].X_op_symbol | |
2906 | == inst.reloc.exp.X_op_symbol)) | |
2907 | break; | |
b99bd4ef NC |
2908 | } |
2909 | ||
c19d1205 ZW |
2910 | /* Do we need to create a new entry? */ |
2911 | if (entry == pool->next_free_entry) | |
2912 | { | |
2913 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
2914 | { | |
2915 | inst.error = _("literal pool overflow"); | |
2916 | return FAIL; | |
2917 | } | |
2918 | ||
2919 | pool->literals[entry] = inst.reloc.exp; | |
2920 | pool->next_free_entry += 1; | |
2921 | } | |
b99bd4ef | 2922 | |
c19d1205 ZW |
2923 | inst.reloc.exp.X_op = O_symbol; |
2924 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
2925 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 2926 | |
c19d1205 | 2927 | return SUCCESS; |
b99bd4ef NC |
2928 | } |
2929 | ||
c19d1205 ZW |
2930 | /* Can't use symbol_new here, so have to create a symbol and then at |
2931 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 2932 | |
c19d1205 ZW |
2933 | static void |
2934 | symbol_locate (symbolS * symbolP, | |
2935 | const char * name, /* It is copied, the caller can modify. */ | |
2936 | segT segment, /* Segment identifier (SEG_<something>). */ | |
2937 | valueT valu, /* Symbol value. */ | |
2938 | fragS * frag) /* Associated fragment. */ | |
2939 | { | |
2940 | unsigned int name_length; | |
2941 | char * preserved_copy_of_name; | |
e16bb312 | 2942 | |
c19d1205 ZW |
2943 | name_length = strlen (name) + 1; /* +1 for \0. */ |
2944 | obstack_grow (¬es, name, name_length); | |
2945 | preserved_copy_of_name = obstack_finish (¬es); | |
e16bb312 | 2946 | |
c19d1205 ZW |
2947 | #ifdef tc_canonicalize_symbol_name |
2948 | preserved_copy_of_name = | |
2949 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
2950 | #endif | |
b99bd4ef | 2951 | |
c19d1205 | 2952 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 2953 | |
c19d1205 ZW |
2954 | S_SET_SEGMENT (symbolP, segment); |
2955 | S_SET_VALUE (symbolP, valu); | |
2956 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 2957 | |
c19d1205 | 2958 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 2959 | |
c19d1205 ZW |
2960 | /* Link to end of symbol chain. */ |
2961 | { | |
2962 | extern int symbol_table_frozen; | |
b99bd4ef | 2963 | |
c19d1205 ZW |
2964 | if (symbol_table_frozen) |
2965 | abort (); | |
2966 | } | |
b99bd4ef | 2967 | |
c19d1205 | 2968 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 2969 | |
c19d1205 | 2970 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 2971 | |
c19d1205 ZW |
2972 | #ifdef tc_symbol_new_hook |
2973 | tc_symbol_new_hook (symbolP); | |
2974 | #endif | |
2975 | ||
2976 | #ifdef DEBUG_SYMS | |
2977 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
2978 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
2979 | } |
2980 | ||
b99bd4ef | 2981 | |
c19d1205 ZW |
2982 | static void |
2983 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 2984 | { |
c19d1205 ZW |
2985 | unsigned int entry; |
2986 | literal_pool * pool; | |
2987 | char sym_name[20]; | |
b99bd4ef | 2988 | |
c19d1205 ZW |
2989 | pool = find_literal_pool (); |
2990 | if (pool == NULL | |
2991 | || pool->symbol == NULL | |
2992 | || pool->next_free_entry == 0) | |
2993 | return; | |
b99bd4ef | 2994 | |
c19d1205 | 2995 | mapping_state (MAP_DATA); |
b99bd4ef | 2996 | |
c19d1205 ZW |
2997 | /* Align pool as you have word accesses. |
2998 | Only make a frag if we have to. */ | |
2999 | if (!need_pass_2) | |
3000 | frag_align (2, 0, 0); | |
b99bd4ef | 3001 | |
c19d1205 | 3002 | record_alignment (now_seg, 2); |
b99bd4ef | 3003 | |
c19d1205 | 3004 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3005 | |
c19d1205 ZW |
3006 | symbol_locate (pool->symbol, sym_name, now_seg, |
3007 | (valueT) frag_now_fix (), frag_now); | |
3008 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3009 | |
c19d1205 | 3010 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3011 | |
c19d1205 ZW |
3012 | #if defined OBJ_COFF || defined OBJ_ELF |
3013 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3014 | #endif | |
6c43fab6 | 3015 | |
c19d1205 ZW |
3016 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
3017 | /* First output the expression in the instruction to the pool. */ | |
3018 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 3019 | |
c19d1205 ZW |
3020 | /* Mark the pool as empty. */ |
3021 | pool->next_free_entry = 0; | |
3022 | pool->symbol = NULL; | |
b99bd4ef NC |
3023 | } |
3024 | ||
c19d1205 ZW |
3025 | #ifdef OBJ_ELF |
3026 | /* Forward declarations for functions below, in the MD interface | |
3027 | section. */ | |
3028 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3029 | static valueT create_unwind_entry (int); | |
3030 | static void start_unwind_section (const segT, int); | |
3031 | static void add_unwind_opcode (valueT, int); | |
3032 | static void flush_pending_unwind (void); | |
b99bd4ef | 3033 | |
c19d1205 | 3034 | /* Directives: Data. */ |
b99bd4ef | 3035 | |
c19d1205 ZW |
3036 | static void |
3037 | s_arm_elf_cons (int nbytes) | |
3038 | { | |
3039 | expressionS exp; | |
b99bd4ef | 3040 | |
c19d1205 ZW |
3041 | #ifdef md_flush_pending_output |
3042 | md_flush_pending_output (); | |
3043 | #endif | |
b99bd4ef | 3044 | |
c19d1205 | 3045 | if (is_it_end_of_statement ()) |
b99bd4ef | 3046 | { |
c19d1205 ZW |
3047 | demand_empty_rest_of_line (); |
3048 | return; | |
b99bd4ef NC |
3049 | } |
3050 | ||
c19d1205 ZW |
3051 | #ifdef md_cons_align |
3052 | md_cons_align (nbytes); | |
3053 | #endif | |
b99bd4ef | 3054 | |
c19d1205 ZW |
3055 | mapping_state (MAP_DATA); |
3056 | do | |
b99bd4ef | 3057 | { |
c19d1205 ZW |
3058 | int reloc; |
3059 | char *base = input_line_pointer; | |
b99bd4ef | 3060 | |
c19d1205 | 3061 | expression (& exp); |
b99bd4ef | 3062 | |
c19d1205 ZW |
3063 | if (exp.X_op != O_symbol) |
3064 | emit_expr (&exp, (unsigned int) nbytes); | |
3065 | else | |
3066 | { | |
3067 | char *before_reloc = input_line_pointer; | |
3068 | reloc = parse_reloc (&input_line_pointer); | |
3069 | if (reloc == -1) | |
3070 | { | |
3071 | as_bad (_("unrecognized relocation suffix")); | |
3072 | ignore_rest_of_line (); | |
3073 | return; | |
3074 | } | |
3075 | else if (reloc == BFD_RELOC_UNUSED) | |
3076 | emit_expr (&exp, (unsigned int) nbytes); | |
3077 | else | |
3078 | { | |
3079 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
3080 | int size = bfd_get_reloc_size (howto); | |
b99bd4ef | 3081 | |
2fc8bdac ZW |
3082 | if (reloc == BFD_RELOC_ARM_PLT32) |
3083 | { | |
3084 | as_bad (_("(plt) is only valid on branch targets")); | |
3085 | reloc = BFD_RELOC_UNUSED; | |
3086 | size = 0; | |
3087 | } | |
3088 | ||
c19d1205 | 3089 | if (size > nbytes) |
2fc8bdac | 3090 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3091 | howto->name, nbytes); |
3092 | else | |
3093 | { | |
3094 | /* We've parsed an expression stopping at O_symbol. | |
3095 | But there may be more expression left now that we | |
3096 | have parsed the relocation marker. Parse it again. | |
3097 | XXX Surely there is a cleaner way to do this. */ | |
3098 | char *p = input_line_pointer; | |
3099 | int offset; | |
3100 | char *save_buf = alloca (input_line_pointer - base); | |
3101 | memcpy (save_buf, base, input_line_pointer - base); | |
3102 | memmove (base + (input_line_pointer - before_reloc), | |
3103 | base, before_reloc - base); | |
3104 | ||
3105 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3106 | expression (&exp); | |
3107 | memcpy (base, save_buf, p - base); | |
3108 | ||
3109 | offset = nbytes - size; | |
3110 | p = frag_more ((int) nbytes); | |
3111 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
3112 | size, &exp, 0, reloc); | |
3113 | } | |
3114 | } | |
3115 | } | |
b99bd4ef | 3116 | } |
c19d1205 | 3117 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3118 | |
c19d1205 ZW |
3119 | /* Put terminator back into stream. */ |
3120 | input_line_pointer --; | |
3121 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3122 | } |
3123 | ||
c921be7d NC |
3124 | /* Emit an expression containing a 32-bit thumb instruction. |
3125 | Implementation based on put_thumb32_insn. */ | |
3126 | ||
3127 | static void | |
3128 | emit_thumb32_expr (expressionS * exp) | |
3129 | { | |
3130 | expressionS exp_high = *exp; | |
3131 | ||
3132 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3133 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3134 | exp->X_add_number &= 0xffff; | |
3135 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3136 | } | |
3137 | ||
3138 | /* Guess the instruction size based on the opcode. */ | |
3139 | ||
3140 | static int | |
3141 | thumb_insn_size (int opcode) | |
3142 | { | |
3143 | if ((unsigned int) opcode < 0xe800u) | |
3144 | return 2; | |
3145 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3146 | return 4; | |
3147 | else | |
3148 | return 0; | |
3149 | } | |
3150 | ||
3151 | static bfd_boolean | |
3152 | emit_insn (expressionS *exp, int nbytes) | |
3153 | { | |
3154 | int size = 0; | |
3155 | ||
3156 | if (exp->X_op == O_constant) | |
3157 | { | |
3158 | size = nbytes; | |
3159 | ||
3160 | if (size == 0) | |
3161 | size = thumb_insn_size (exp->X_add_number); | |
3162 | ||
3163 | if (size != 0) | |
3164 | { | |
3165 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3166 | { | |
3167 | as_bad (_(".inst.n operand too big. "\ | |
3168 | "Use .inst.w instead")); | |
3169 | size = 0; | |
3170 | } | |
3171 | else | |
3172 | { | |
3173 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3174 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3175 | else | |
3176 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3177 | ||
3178 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3179 | emit_thumb32_expr (exp); | |
3180 | else | |
3181 | emit_expr (exp, (unsigned int) size); | |
3182 | ||
3183 | it_fsm_post_encode (); | |
3184 | } | |
3185 | } | |
3186 | else | |
3187 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3188 | "Use .inst.n/.inst.w instead")); | |
3189 | } | |
3190 | else | |
3191 | as_bad (_("constant expression required")); | |
3192 | ||
3193 | return (size != 0); | |
3194 | } | |
3195 | ||
3196 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3197 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3198 | ||
3199 | static void | |
3200 | s_arm_elf_inst (int nbytes) | |
3201 | { | |
3202 | if (is_it_end_of_statement ()) | |
3203 | { | |
3204 | demand_empty_rest_of_line (); | |
3205 | return; | |
3206 | } | |
3207 | ||
3208 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3209 | but will ensure not to be in DATA state. */ | |
3210 | ||
3211 | if (thumb_mode) | |
3212 | mapping_state (MAP_THUMB); | |
3213 | else | |
3214 | { | |
3215 | if (nbytes != 0) | |
3216 | { | |
3217 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3218 | ignore_rest_of_line (); | |
3219 | return; | |
3220 | } | |
3221 | ||
3222 | nbytes = 4; | |
3223 | ||
3224 | mapping_state (MAP_ARM); | |
3225 | } | |
3226 | ||
3227 | do | |
3228 | { | |
3229 | expressionS exp; | |
3230 | ||
3231 | expression (& exp); | |
3232 | ||
3233 | if (! emit_insn (& exp, nbytes)) | |
3234 | { | |
3235 | ignore_rest_of_line (); | |
3236 | return; | |
3237 | } | |
3238 | } | |
3239 | while (*input_line_pointer++ == ','); | |
3240 | ||
3241 | /* Put terminator back into stream. */ | |
3242 | input_line_pointer --; | |
3243 | demand_empty_rest_of_line (); | |
3244 | } | |
b99bd4ef | 3245 | |
c19d1205 | 3246 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3247 | |
c19d1205 ZW |
3248 | static void |
3249 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3250 | { | |
3251 | expressionS exp; | |
3252 | char *p; | |
3253 | valueT highbit; | |
b99bd4ef | 3254 | |
c19d1205 ZW |
3255 | highbit = 0; |
3256 | if (*input_line_pointer == '1') | |
3257 | highbit = 0x80000000; | |
3258 | else if (*input_line_pointer != '0') | |
3259 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3260 | |
c19d1205 ZW |
3261 | input_line_pointer++; |
3262 | if (*input_line_pointer != ',') | |
3263 | as_bad (_("missing comma")); | |
3264 | input_line_pointer++; | |
b99bd4ef | 3265 | |
c19d1205 ZW |
3266 | #ifdef md_flush_pending_output |
3267 | md_flush_pending_output (); | |
3268 | #endif | |
b99bd4ef | 3269 | |
c19d1205 ZW |
3270 | #ifdef md_cons_align |
3271 | md_cons_align (4); | |
3272 | #endif | |
b99bd4ef | 3273 | |
c19d1205 | 3274 | mapping_state (MAP_DATA); |
b99bd4ef | 3275 | |
c19d1205 | 3276 | expression (&exp); |
b99bd4ef | 3277 | |
c19d1205 ZW |
3278 | p = frag_more (4); |
3279 | md_number_to_chars (p, highbit, 4); | |
3280 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3281 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3282 | |
c19d1205 | 3283 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3284 | } |
3285 | ||
c19d1205 | 3286 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3287 | |
c19d1205 | 3288 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3289 | |
c19d1205 ZW |
3290 | static void |
3291 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3292 | { | |
3293 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3294 | if (unwind.proc_start) |
3295 | { | |
c921be7d | 3296 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3297 | return; |
3298 | } | |
3299 | ||
c19d1205 ZW |
3300 | /* Mark the start of the function. */ |
3301 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3302 | |
c19d1205 ZW |
3303 | /* Reset the rest of the unwind info. */ |
3304 | unwind.opcode_count = 0; | |
3305 | unwind.table_entry = NULL; | |
3306 | unwind.personality_routine = NULL; | |
3307 | unwind.personality_index = -1; | |
3308 | unwind.frame_size = 0; | |
3309 | unwind.fp_offset = 0; | |
fdfde340 | 3310 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3311 | unwind.fp_used = 0; |
3312 | unwind.sp_restored = 0; | |
3313 | } | |
b99bd4ef | 3314 | |
b99bd4ef | 3315 | |
c19d1205 ZW |
3316 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3317 | for the function. */ | |
b99bd4ef | 3318 | |
c19d1205 ZW |
3319 | static void |
3320 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3321 | { | |
3322 | demand_empty_rest_of_line (); | |
921e5f0a | 3323 | if (!unwind.proc_start) |
c921be7d | 3324 | as_bad (MISSING_FNSTART); |
921e5f0a | 3325 | |
c19d1205 | 3326 | if (unwind.table_entry) |
6decc662 | 3327 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3328 | |
c19d1205 ZW |
3329 | create_unwind_entry (1); |
3330 | } | |
a737bd4d | 3331 | |
c19d1205 | 3332 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3333 | |
c19d1205 ZW |
3334 | static void |
3335 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3336 | { | |
3337 | long where; | |
3338 | char *ptr; | |
3339 | valueT val; | |
f02232aa | 3340 | |
c19d1205 | 3341 | demand_empty_rest_of_line (); |
f02232aa | 3342 | |
921e5f0a PB |
3343 | if (!unwind.proc_start) |
3344 | { | |
c921be7d | 3345 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3346 | return; |
3347 | } | |
3348 | ||
c19d1205 ZW |
3349 | /* Add eh table entry. */ |
3350 | if (unwind.table_entry == NULL) | |
3351 | val = create_unwind_entry (0); | |
3352 | else | |
3353 | val = 0; | |
f02232aa | 3354 | |
c19d1205 ZW |
3355 | /* Add index table entry. This is two words. */ |
3356 | start_unwind_section (unwind.saved_seg, 1); | |
3357 | frag_align (2, 0, 0); | |
3358 | record_alignment (now_seg, 2); | |
b99bd4ef | 3359 | |
c19d1205 ZW |
3360 | ptr = frag_more (8); |
3361 | where = frag_now_fix () - 8; | |
f02232aa | 3362 | |
c19d1205 ZW |
3363 | /* Self relative offset of the function start. */ |
3364 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3365 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3366 | |
c19d1205 ZW |
3367 | /* Indicate dependency on EHABI-defined personality routines to the |
3368 | linker, if it hasn't been done already. */ | |
3369 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 | |
3370 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3371 | { | |
5f4273c7 NC |
3372 | static const char *const name[] = |
3373 | { | |
3374 | "__aeabi_unwind_cpp_pr0", | |
3375 | "__aeabi_unwind_cpp_pr1", | |
3376 | "__aeabi_unwind_cpp_pr2" | |
3377 | }; | |
c19d1205 ZW |
3378 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3379 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
3380 | marked_pr_dependency |= 1 << unwind.personality_index; | |
3381 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency | |
3382 | = marked_pr_dependency; | |
3383 | } | |
f02232aa | 3384 | |
c19d1205 ZW |
3385 | if (val) |
3386 | /* Inline exception table entry. */ | |
3387 | md_number_to_chars (ptr + 4, val, 4); | |
3388 | else | |
3389 | /* Self relative offset of the table entry. */ | |
3390 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3391 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3392 | |
c19d1205 ZW |
3393 | /* Restore the original section. */ |
3394 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3395 | |
3396 | unwind.proc_start = NULL; | |
c19d1205 | 3397 | } |
f02232aa | 3398 | |
f02232aa | 3399 | |
c19d1205 | 3400 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3401 | |
c19d1205 ZW |
3402 | static void |
3403 | s_arm_unwind_cantunwind (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 ZW |
3409 | if (unwind.personality_routine || unwind.personality_index != -1) |
3410 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3411 | |
c19d1205 ZW |
3412 | unwind.personality_index = -2; |
3413 | } | |
b99bd4ef | 3414 | |
b99bd4ef | 3415 | |
c19d1205 | 3416 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3417 | |
c19d1205 ZW |
3418 | static void |
3419 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3420 | { | |
3421 | expressionS exp; | |
b99bd4ef | 3422 | |
921e5f0a | 3423 | if (!unwind.proc_start) |
c921be7d | 3424 | as_bad (MISSING_FNSTART); |
921e5f0a | 3425 | |
c19d1205 ZW |
3426 | if (unwind.personality_routine || unwind.personality_index != -1) |
3427 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3428 | |
c19d1205 | 3429 | expression (&exp); |
b99bd4ef | 3430 | |
c19d1205 ZW |
3431 | if (exp.X_op != O_constant |
3432 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3433 | { |
c19d1205 ZW |
3434 | as_bad (_("bad personality routine number")); |
3435 | ignore_rest_of_line (); | |
3436 | return; | |
b99bd4ef NC |
3437 | } |
3438 | ||
c19d1205 | 3439 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3440 | |
c19d1205 ZW |
3441 | demand_empty_rest_of_line (); |
3442 | } | |
e16bb312 | 3443 | |
e16bb312 | 3444 | |
c19d1205 | 3445 | /* Parse a personality directive. */ |
e16bb312 | 3446 | |
c19d1205 ZW |
3447 | static void |
3448 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3449 | { | |
3450 | char *name, *p, c; | |
a737bd4d | 3451 | |
921e5f0a | 3452 | if (!unwind.proc_start) |
c921be7d | 3453 | as_bad (MISSING_FNSTART); |
921e5f0a | 3454 | |
c19d1205 ZW |
3455 | if (unwind.personality_routine || unwind.personality_index != -1) |
3456 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3457 | |
c19d1205 ZW |
3458 | name = input_line_pointer; |
3459 | c = get_symbol_end (); | |
3460 | p = input_line_pointer; | |
3461 | unwind.personality_routine = symbol_find_or_make (name); | |
3462 | *p = c; | |
3463 | demand_empty_rest_of_line (); | |
3464 | } | |
e16bb312 | 3465 | |
e16bb312 | 3466 | |
c19d1205 | 3467 | /* Parse a directive saving core registers. */ |
e16bb312 | 3468 | |
c19d1205 ZW |
3469 | static void |
3470 | s_arm_unwind_save_core (void) | |
e16bb312 | 3471 | { |
c19d1205 ZW |
3472 | valueT op; |
3473 | long range; | |
3474 | int n; | |
e16bb312 | 3475 | |
c19d1205 ZW |
3476 | range = parse_reg_list (&input_line_pointer); |
3477 | if (range == FAIL) | |
e16bb312 | 3478 | { |
c19d1205 ZW |
3479 | as_bad (_("expected register list")); |
3480 | ignore_rest_of_line (); | |
3481 | return; | |
3482 | } | |
e16bb312 | 3483 | |
c19d1205 | 3484 | demand_empty_rest_of_line (); |
e16bb312 | 3485 | |
c19d1205 ZW |
3486 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3487 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3488 | ip because it is clobbered by calls. */ | |
3489 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3490 | && (range & 0x3000) == 0x1000) | |
3491 | { | |
3492 | unwind.opcode_count--; | |
3493 | unwind.sp_restored = 0; | |
3494 | range = (range | 0x2000) & ~0x1000; | |
3495 | unwind.pending_offset = 0; | |
3496 | } | |
e16bb312 | 3497 | |
01ae4198 DJ |
3498 | /* Pop r4-r15. */ |
3499 | if (range & 0xfff0) | |
c19d1205 | 3500 | { |
01ae4198 DJ |
3501 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3502 | registers starting with r4, plus maybe r14. */ | |
3503 | for (n = 0; n < 8; n++) | |
3504 | { | |
3505 | /* Break at the first non-saved register. */ | |
3506 | if ((range & (1 << (n + 4))) == 0) | |
3507 | break; | |
3508 | } | |
3509 | /* See if there are any other bits set. */ | |
3510 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3511 | { | |
3512 | /* Use the long form. */ | |
3513 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3514 | add_unwind_opcode (op, 2); | |
3515 | } | |
0dd132b6 | 3516 | else |
01ae4198 DJ |
3517 | { |
3518 | /* Use the short form. */ | |
3519 | if (range & 0x4000) | |
3520 | op = 0xa8; /* Pop r14. */ | |
3521 | else | |
3522 | op = 0xa0; /* Do not pop r14. */ | |
3523 | op |= (n - 1); | |
3524 | add_unwind_opcode (op, 1); | |
3525 | } | |
c19d1205 | 3526 | } |
0dd132b6 | 3527 | |
c19d1205 ZW |
3528 | /* Pop r0-r3. */ |
3529 | if (range & 0xf) | |
3530 | { | |
3531 | op = 0xb100 | (range & 0xf); | |
3532 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3533 | } |
3534 | ||
c19d1205 ZW |
3535 | /* Record the number of bytes pushed. */ |
3536 | for (n = 0; n < 16; n++) | |
3537 | { | |
3538 | if (range & (1 << n)) | |
3539 | unwind.frame_size += 4; | |
3540 | } | |
0dd132b6 NC |
3541 | } |
3542 | ||
c19d1205 ZW |
3543 | |
3544 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3545 | |
3546 | static void | |
c19d1205 | 3547 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3548 | { |
c19d1205 ZW |
3549 | expressionS exp; |
3550 | int num_regs; | |
3551 | valueT op; | |
b99bd4ef | 3552 | |
c19d1205 ZW |
3553 | /* Get Number of registers to transfer. */ |
3554 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3555 | expression (&exp); | |
3556 | else | |
3557 | exp.X_op = O_illegal; | |
b99bd4ef | 3558 | |
c19d1205 | 3559 | if (exp.X_op != O_constant) |
b99bd4ef | 3560 | { |
c19d1205 ZW |
3561 | as_bad (_("expected , <constant>")); |
3562 | ignore_rest_of_line (); | |
b99bd4ef NC |
3563 | return; |
3564 | } | |
3565 | ||
c19d1205 ZW |
3566 | num_regs = exp.X_add_number; |
3567 | ||
3568 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 3569 | { |
c19d1205 ZW |
3570 | as_bad (_("number of registers must be in the range [1:4]")); |
3571 | ignore_rest_of_line (); | |
b99bd4ef NC |
3572 | return; |
3573 | } | |
3574 | ||
c19d1205 | 3575 | demand_empty_rest_of_line (); |
b99bd4ef | 3576 | |
c19d1205 ZW |
3577 | if (reg == 4) |
3578 | { | |
3579 | /* Short form. */ | |
3580 | op = 0xb4 | (num_regs - 1); | |
3581 | add_unwind_opcode (op, 1); | |
3582 | } | |
b99bd4ef NC |
3583 | else |
3584 | { | |
c19d1205 ZW |
3585 | /* Long form. */ |
3586 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
3587 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3588 | } |
c19d1205 | 3589 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
3590 | } |
3591 | ||
c19d1205 | 3592 | |
fa073d69 MS |
3593 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
3594 | ||
3595 | static void | |
3596 | s_arm_unwind_save_vfp_armv6 (void) | |
3597 | { | |
3598 | int count; | |
3599 | unsigned int start; | |
3600 | valueT op; | |
3601 | int num_vfpv3_regs = 0; | |
3602 | int num_regs_below_16; | |
3603 | ||
3604 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
3605 | if (count == FAIL) | |
3606 | { | |
3607 | as_bad (_("expected register list")); | |
3608 | ignore_rest_of_line (); | |
3609 | return; | |
3610 | } | |
3611 | ||
3612 | demand_empty_rest_of_line (); | |
3613 | ||
3614 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
3615 | than FSTMX/FLDMX-style ones). */ | |
3616 | ||
3617 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
3618 | if (start >= 16) | |
3619 | num_vfpv3_regs = count; | |
3620 | else if (start + count > 16) | |
3621 | num_vfpv3_regs = start + count - 16; | |
3622 | ||
3623 | if (num_vfpv3_regs > 0) | |
3624 | { | |
3625 | int start_offset = start > 16 ? start - 16 : 0; | |
3626 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
3627 | add_unwind_opcode (op, 2); | |
3628 | } | |
3629 | ||
3630 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
3631 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 3632 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
3633 | if (num_regs_below_16 > 0) |
3634 | { | |
3635 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
3636 | add_unwind_opcode (op, 2); | |
3637 | } | |
3638 | ||
3639 | unwind.frame_size += count * 8; | |
3640 | } | |
3641 | ||
3642 | ||
3643 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
3644 | |
3645 | static void | |
c19d1205 | 3646 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 3647 | { |
c19d1205 | 3648 | int count; |
ca3f61f7 | 3649 | unsigned int reg; |
c19d1205 | 3650 | valueT op; |
b99bd4ef | 3651 | |
5287ad62 | 3652 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 3653 | if (count == FAIL) |
b99bd4ef | 3654 | { |
c19d1205 ZW |
3655 | as_bad (_("expected register list")); |
3656 | ignore_rest_of_line (); | |
b99bd4ef NC |
3657 | return; |
3658 | } | |
3659 | ||
c19d1205 | 3660 | demand_empty_rest_of_line (); |
b99bd4ef | 3661 | |
c19d1205 | 3662 | if (reg == 8) |
b99bd4ef | 3663 | { |
c19d1205 ZW |
3664 | /* Short form. */ |
3665 | op = 0xb8 | (count - 1); | |
3666 | add_unwind_opcode (op, 1); | |
b99bd4ef | 3667 | } |
c19d1205 | 3668 | else |
b99bd4ef | 3669 | { |
c19d1205 ZW |
3670 | /* Long form. */ |
3671 | op = 0xb300 | (reg << 4) | (count - 1); | |
3672 | add_unwind_opcode (op, 2); | |
b99bd4ef | 3673 | } |
c19d1205 ZW |
3674 | unwind.frame_size += count * 8 + 4; |
3675 | } | |
b99bd4ef | 3676 | |
b99bd4ef | 3677 | |
c19d1205 ZW |
3678 | /* Parse a directive saving iWMMXt data registers. */ |
3679 | ||
3680 | static void | |
3681 | s_arm_unwind_save_mmxwr (void) | |
3682 | { | |
3683 | int reg; | |
3684 | int hi_reg; | |
3685 | int i; | |
3686 | unsigned mask = 0; | |
3687 | valueT op; | |
b99bd4ef | 3688 | |
c19d1205 ZW |
3689 | if (*input_line_pointer == '{') |
3690 | input_line_pointer++; | |
b99bd4ef | 3691 | |
c19d1205 | 3692 | do |
b99bd4ef | 3693 | { |
dcbf9037 | 3694 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 3695 | |
c19d1205 | 3696 | if (reg == FAIL) |
b99bd4ef | 3697 | { |
9b7132d3 | 3698 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 3699 | goto error; |
b99bd4ef NC |
3700 | } |
3701 | ||
c19d1205 ZW |
3702 | if (mask >> reg) |
3703 | as_tsktsk (_("register list not in ascending order")); | |
3704 | mask |= 1 << reg; | |
b99bd4ef | 3705 | |
c19d1205 ZW |
3706 | if (*input_line_pointer == '-') |
3707 | { | |
3708 | input_line_pointer++; | |
dcbf9037 | 3709 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
3710 | if (hi_reg == FAIL) |
3711 | { | |
9b7132d3 | 3712 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
3713 | goto error; |
3714 | } | |
3715 | else if (reg >= hi_reg) | |
3716 | { | |
3717 | as_bad (_("bad register range")); | |
3718 | goto error; | |
3719 | } | |
3720 | for (; reg < hi_reg; reg++) | |
3721 | mask |= 1 << reg; | |
3722 | } | |
3723 | } | |
3724 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 3725 | |
c19d1205 ZW |
3726 | if (*input_line_pointer == '}') |
3727 | input_line_pointer++; | |
b99bd4ef | 3728 | |
c19d1205 | 3729 | demand_empty_rest_of_line (); |
b99bd4ef | 3730 | |
708587a4 | 3731 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3732 | the list. */ |
3733 | flush_pending_unwind (); | |
b99bd4ef | 3734 | |
c19d1205 | 3735 | for (i = 0; i < 16; i++) |
b99bd4ef | 3736 | { |
c19d1205 ZW |
3737 | if (mask & (1 << i)) |
3738 | unwind.frame_size += 8; | |
b99bd4ef NC |
3739 | } |
3740 | ||
c19d1205 ZW |
3741 | /* Attempt to combine with a previous opcode. We do this because gcc |
3742 | likes to output separate unwind directives for a single block of | |
3743 | registers. */ | |
3744 | if (unwind.opcode_count > 0) | |
b99bd4ef | 3745 | { |
c19d1205 ZW |
3746 | i = unwind.opcodes[unwind.opcode_count - 1]; |
3747 | if ((i & 0xf8) == 0xc0) | |
3748 | { | |
3749 | i &= 7; | |
3750 | /* Only merge if the blocks are contiguous. */ | |
3751 | if (i < 6) | |
3752 | { | |
3753 | if ((mask & 0xfe00) == (1 << 9)) | |
3754 | { | |
3755 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
3756 | unwind.opcode_count--; | |
3757 | } | |
3758 | } | |
3759 | else if (i == 6 && unwind.opcode_count >= 2) | |
3760 | { | |
3761 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
3762 | reg = i >> 4; | |
3763 | i &= 0xf; | |
b99bd4ef | 3764 | |
c19d1205 ZW |
3765 | op = 0xffff << (reg - 1); |
3766 | if (reg > 0 | |
87a1fd79 | 3767 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
3768 | { |
3769 | op = (1 << (reg + i + 1)) - 1; | |
3770 | op &= ~((1 << reg) - 1); | |
3771 | mask |= op; | |
3772 | unwind.opcode_count -= 2; | |
3773 | } | |
3774 | } | |
3775 | } | |
b99bd4ef NC |
3776 | } |
3777 | ||
c19d1205 ZW |
3778 | hi_reg = 15; |
3779 | /* We want to generate opcodes in the order the registers have been | |
3780 | saved, ie. descending order. */ | |
3781 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 3782 | { |
c19d1205 ZW |
3783 | /* Save registers in blocks. */ |
3784 | if (reg < 0 | |
3785 | || !(mask & (1 << reg))) | |
3786 | { | |
3787 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 3788 | preceding block. */ |
c19d1205 ZW |
3789 | if (reg != hi_reg) |
3790 | { | |
3791 | if (reg == 9) | |
3792 | { | |
3793 | /* Short form. */ | |
3794 | op = 0xc0 | (hi_reg - 10); | |
3795 | add_unwind_opcode (op, 1); | |
3796 | } | |
3797 | else | |
3798 | { | |
3799 | /* Long form. */ | |
3800 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
3801 | add_unwind_opcode (op, 2); | |
3802 | } | |
3803 | } | |
3804 | hi_reg = reg - 1; | |
3805 | } | |
b99bd4ef NC |
3806 | } |
3807 | ||
c19d1205 ZW |
3808 | return; |
3809 | error: | |
3810 | ignore_rest_of_line (); | |
b99bd4ef NC |
3811 | } |
3812 | ||
3813 | static void | |
c19d1205 | 3814 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 3815 | { |
c19d1205 ZW |
3816 | int reg; |
3817 | int hi_reg; | |
3818 | unsigned mask = 0; | |
3819 | valueT op; | |
b99bd4ef | 3820 | |
c19d1205 ZW |
3821 | if (*input_line_pointer == '{') |
3822 | input_line_pointer++; | |
b99bd4ef | 3823 | |
c19d1205 | 3824 | do |
b99bd4ef | 3825 | { |
dcbf9037 | 3826 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 3827 | |
c19d1205 ZW |
3828 | if (reg == FAIL) |
3829 | { | |
9b7132d3 | 3830 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3831 | goto error; |
3832 | } | |
b99bd4ef | 3833 | |
c19d1205 ZW |
3834 | reg -= 8; |
3835 | if (mask >> reg) | |
3836 | as_tsktsk (_("register list not in ascending order")); | |
3837 | mask |= 1 << reg; | |
b99bd4ef | 3838 | |
c19d1205 ZW |
3839 | if (*input_line_pointer == '-') |
3840 | { | |
3841 | input_line_pointer++; | |
dcbf9037 | 3842 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
3843 | if (hi_reg == FAIL) |
3844 | { | |
9b7132d3 | 3845 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
3846 | goto error; |
3847 | } | |
3848 | else if (reg >= hi_reg) | |
3849 | { | |
3850 | as_bad (_("bad register range")); | |
3851 | goto error; | |
3852 | } | |
3853 | for (; reg < hi_reg; reg++) | |
3854 | mask |= 1 << reg; | |
3855 | } | |
b99bd4ef | 3856 | } |
c19d1205 | 3857 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 3858 | |
c19d1205 ZW |
3859 | if (*input_line_pointer == '}') |
3860 | input_line_pointer++; | |
b99bd4ef | 3861 | |
c19d1205 ZW |
3862 | demand_empty_rest_of_line (); |
3863 | ||
708587a4 | 3864 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
3865 | the list. */ |
3866 | flush_pending_unwind (); | |
b99bd4ef | 3867 | |
c19d1205 | 3868 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 3869 | { |
c19d1205 ZW |
3870 | if (mask & (1 << reg)) |
3871 | unwind.frame_size += 4; | |
b99bd4ef | 3872 | } |
c19d1205 ZW |
3873 | op = 0xc700 | mask; |
3874 | add_unwind_opcode (op, 2); | |
3875 | return; | |
3876 | error: | |
3877 | ignore_rest_of_line (); | |
b99bd4ef NC |
3878 | } |
3879 | ||
c19d1205 | 3880 | |
fa073d69 MS |
3881 | /* Parse an unwind_save directive. |
3882 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 3883 | |
b99bd4ef | 3884 | static void |
fa073d69 | 3885 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 3886 | { |
c19d1205 ZW |
3887 | char *peek; |
3888 | struct reg_entry *reg; | |
3889 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 3890 | |
921e5f0a | 3891 | if (!unwind.proc_start) |
c921be7d | 3892 | as_bad (MISSING_FNSTART); |
921e5f0a | 3893 | |
c19d1205 ZW |
3894 | /* Figure out what sort of save we have. */ |
3895 | peek = input_line_pointer; | |
b99bd4ef | 3896 | |
c19d1205 | 3897 | if (*peek == '{') |
b99bd4ef | 3898 | { |
c19d1205 ZW |
3899 | had_brace = TRUE; |
3900 | peek++; | |
b99bd4ef NC |
3901 | } |
3902 | ||
c19d1205 | 3903 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 3904 | |
c19d1205 | 3905 | if (!reg) |
b99bd4ef | 3906 | { |
c19d1205 ZW |
3907 | as_bad (_("register expected")); |
3908 | ignore_rest_of_line (); | |
b99bd4ef NC |
3909 | return; |
3910 | } | |
3911 | ||
c19d1205 | 3912 | switch (reg->type) |
b99bd4ef | 3913 | { |
c19d1205 ZW |
3914 | case REG_TYPE_FN: |
3915 | if (had_brace) | |
3916 | { | |
3917 | as_bad (_("FPA .unwind_save does not take a register list")); | |
3918 | ignore_rest_of_line (); | |
3919 | return; | |
3920 | } | |
93ac2687 | 3921 | input_line_pointer = peek; |
c19d1205 | 3922 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 3923 | return; |
c19d1205 ZW |
3924 | |
3925 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
fa073d69 MS |
3926 | case REG_TYPE_VFD: |
3927 | if (arch_v6) | |
3928 | s_arm_unwind_save_vfp_armv6 (); | |
3929 | else | |
3930 | s_arm_unwind_save_vfp (); | |
3931 | return; | |
c19d1205 ZW |
3932 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; |
3933 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
3934 | ||
3935 | default: | |
3936 | as_bad (_(".unwind_save does not support this kind of register")); | |
3937 | ignore_rest_of_line (); | |
b99bd4ef | 3938 | } |
c19d1205 | 3939 | } |
b99bd4ef | 3940 | |
b99bd4ef | 3941 | |
c19d1205 ZW |
3942 | /* Parse an unwind_movsp directive. */ |
3943 | ||
3944 | static void | |
3945 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
3946 | { | |
3947 | int reg; | |
3948 | valueT op; | |
4fa3602b | 3949 | int offset; |
c19d1205 | 3950 | |
921e5f0a | 3951 | if (!unwind.proc_start) |
c921be7d | 3952 | as_bad (MISSING_FNSTART); |
921e5f0a | 3953 | |
dcbf9037 | 3954 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 3955 | if (reg == FAIL) |
b99bd4ef | 3956 | { |
9b7132d3 | 3957 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 3958 | ignore_rest_of_line (); |
b99bd4ef NC |
3959 | return; |
3960 | } | |
4fa3602b PB |
3961 | |
3962 | /* Optional constant. */ | |
3963 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3964 | { | |
3965 | if (immediate_for_directive (&offset) == FAIL) | |
3966 | return; | |
3967 | } | |
3968 | else | |
3969 | offset = 0; | |
3970 | ||
c19d1205 | 3971 | demand_empty_rest_of_line (); |
b99bd4ef | 3972 | |
c19d1205 | 3973 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 3974 | { |
c19d1205 | 3975 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
3976 | return; |
3977 | } | |
3978 | ||
c19d1205 ZW |
3979 | if (unwind.fp_reg != REG_SP) |
3980 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 3981 | |
c19d1205 ZW |
3982 | /* Generate opcode to restore the value. */ |
3983 | op = 0x90 | reg; | |
3984 | add_unwind_opcode (op, 1); | |
3985 | ||
3986 | /* Record the information for later. */ | |
3987 | unwind.fp_reg = reg; | |
4fa3602b | 3988 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 3989 | unwind.sp_restored = 1; |
b05fe5cf ZW |
3990 | } |
3991 | ||
c19d1205 ZW |
3992 | /* Parse an unwind_pad directive. */ |
3993 | ||
b05fe5cf | 3994 | static void |
c19d1205 | 3995 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 3996 | { |
c19d1205 | 3997 | int offset; |
b05fe5cf | 3998 | |
921e5f0a | 3999 | if (!unwind.proc_start) |
c921be7d | 4000 | as_bad (MISSING_FNSTART); |
921e5f0a | 4001 | |
c19d1205 ZW |
4002 | if (immediate_for_directive (&offset) == FAIL) |
4003 | return; | |
b99bd4ef | 4004 | |
c19d1205 ZW |
4005 | if (offset & 3) |
4006 | { | |
4007 | as_bad (_("stack increment must be multiple of 4")); | |
4008 | ignore_rest_of_line (); | |
4009 | return; | |
4010 | } | |
b99bd4ef | 4011 | |
c19d1205 ZW |
4012 | /* Don't generate any opcodes, just record the details for later. */ |
4013 | unwind.frame_size += offset; | |
4014 | unwind.pending_offset += offset; | |
4015 | ||
4016 | demand_empty_rest_of_line (); | |
4017 | } | |
4018 | ||
4019 | /* Parse an unwind_setfp directive. */ | |
4020 | ||
4021 | static void | |
4022 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4023 | { |
c19d1205 ZW |
4024 | int sp_reg; |
4025 | int fp_reg; | |
4026 | int offset; | |
4027 | ||
921e5f0a | 4028 | if (!unwind.proc_start) |
c921be7d | 4029 | as_bad (MISSING_FNSTART); |
921e5f0a | 4030 | |
dcbf9037 | 4031 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4032 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4033 | sp_reg = FAIL; | |
4034 | else | |
dcbf9037 | 4035 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4036 | |
c19d1205 ZW |
4037 | if (fp_reg == FAIL || sp_reg == FAIL) |
4038 | { | |
4039 | as_bad (_("expected <reg>, <reg>")); | |
4040 | ignore_rest_of_line (); | |
4041 | return; | |
4042 | } | |
b99bd4ef | 4043 | |
c19d1205 ZW |
4044 | /* Optional constant. */ |
4045 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4046 | { | |
4047 | if (immediate_for_directive (&offset) == FAIL) | |
4048 | return; | |
4049 | } | |
4050 | else | |
4051 | offset = 0; | |
a737bd4d | 4052 | |
c19d1205 | 4053 | demand_empty_rest_of_line (); |
a737bd4d | 4054 | |
fdfde340 | 4055 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4056 | { |
c19d1205 ZW |
4057 | as_bad (_("register must be either sp or set by a previous" |
4058 | "unwind_movsp directive")); | |
4059 | return; | |
a737bd4d NC |
4060 | } |
4061 | ||
c19d1205 ZW |
4062 | /* Don't generate any opcodes, just record the information for later. */ |
4063 | unwind.fp_reg = fp_reg; | |
4064 | unwind.fp_used = 1; | |
fdfde340 | 4065 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4066 | unwind.fp_offset = unwind.frame_size - offset; |
4067 | else | |
4068 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4069 | } |
4070 | ||
c19d1205 ZW |
4071 | /* Parse an unwind_raw directive. */ |
4072 | ||
4073 | static void | |
4074 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4075 | { |
c19d1205 | 4076 | expressionS exp; |
708587a4 | 4077 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4078 | unsigned char op[16]; |
4079 | int count; | |
a737bd4d | 4080 | |
921e5f0a | 4081 | if (!unwind.proc_start) |
c921be7d | 4082 | as_bad (MISSING_FNSTART); |
921e5f0a | 4083 | |
c19d1205 ZW |
4084 | expression (&exp); |
4085 | if (exp.X_op == O_constant | |
4086 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4087 | { |
c19d1205 ZW |
4088 | unwind.frame_size += exp.X_add_number; |
4089 | expression (&exp); | |
4090 | } | |
4091 | else | |
4092 | exp.X_op = O_illegal; | |
a737bd4d | 4093 | |
c19d1205 ZW |
4094 | if (exp.X_op != O_constant) |
4095 | { | |
4096 | as_bad (_("expected <offset>, <opcode>")); | |
4097 | ignore_rest_of_line (); | |
4098 | return; | |
4099 | } | |
a737bd4d | 4100 | |
c19d1205 | 4101 | count = 0; |
a737bd4d | 4102 | |
c19d1205 ZW |
4103 | /* Parse the opcode. */ |
4104 | for (;;) | |
4105 | { | |
4106 | if (count >= 16) | |
4107 | { | |
4108 | as_bad (_("unwind opcode too long")); | |
4109 | ignore_rest_of_line (); | |
a737bd4d | 4110 | } |
c19d1205 | 4111 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4112 | { |
c19d1205 ZW |
4113 | as_bad (_("invalid unwind opcode")); |
4114 | ignore_rest_of_line (); | |
4115 | return; | |
a737bd4d | 4116 | } |
c19d1205 | 4117 | op[count++] = exp.X_add_number; |
a737bd4d | 4118 | |
c19d1205 ZW |
4119 | /* Parse the next byte. */ |
4120 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4121 | break; | |
a737bd4d | 4122 | |
c19d1205 ZW |
4123 | expression (&exp); |
4124 | } | |
b99bd4ef | 4125 | |
c19d1205 ZW |
4126 | /* Add the opcode bytes in reverse order. */ |
4127 | while (count--) | |
4128 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4129 | |
c19d1205 | 4130 | demand_empty_rest_of_line (); |
b99bd4ef | 4131 | } |
ee065d83 PB |
4132 | |
4133 | ||
4134 | /* Parse a .eabi_attribute directive. */ | |
4135 | ||
4136 | static void | |
4137 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4138 | { | |
ee3c0378 AS |
4139 | int tag = s_vendor_attribute (OBJ_ATTR_PROC); |
4140 | ||
4141 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4142 | attributes_set_explicitly[tag] = 1; | |
ee065d83 | 4143 | } |
8463be01 | 4144 | #endif /* OBJ_ELF */ |
ee065d83 PB |
4145 | |
4146 | static void s_arm_arch (int); | |
7a1d4c38 | 4147 | static void s_arm_object_arch (int); |
ee065d83 PB |
4148 | static void s_arm_cpu (int); |
4149 | static void s_arm_fpu (int); | |
b99bd4ef | 4150 | |
f0927246 NC |
4151 | #ifdef TE_PE |
4152 | ||
4153 | static void | |
5f4273c7 | 4154 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4155 | { |
4156 | expressionS exp; | |
4157 | ||
4158 | do | |
4159 | { | |
4160 | expression (&exp); | |
4161 | if (exp.X_op == O_symbol) | |
4162 | exp.X_op = O_secrel; | |
4163 | ||
4164 | emit_expr (&exp, 4); | |
4165 | } | |
4166 | while (*input_line_pointer++ == ','); | |
4167 | ||
4168 | input_line_pointer--; | |
4169 | demand_empty_rest_of_line (); | |
4170 | } | |
4171 | #endif /* TE_PE */ | |
4172 | ||
c19d1205 ZW |
4173 | /* This table describes all the machine specific pseudo-ops the assembler |
4174 | has to support. The fields are: | |
4175 | pseudo-op name without dot | |
4176 | function to call to execute this pseudo-op | |
4177 | Integer arg to pass to the function. */ | |
b99bd4ef | 4178 | |
c19d1205 | 4179 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4180 | { |
c19d1205 ZW |
4181 | /* Never called because '.req' does not start a line. */ |
4182 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4183 | /* Following two are likewise never called. */ |
4184 | { "dn", s_dn, 0 }, | |
4185 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4186 | { "unreq", s_unreq, 0 }, |
4187 | { "bss", s_bss, 0 }, | |
4188 | { "align", s_align, 0 }, | |
4189 | { "arm", s_arm, 0 }, | |
4190 | { "thumb", s_thumb, 0 }, | |
4191 | { "code", s_code, 0 }, | |
4192 | { "force_thumb", s_force_thumb, 0 }, | |
4193 | { "thumb_func", s_thumb_func, 0 }, | |
4194 | { "thumb_set", s_thumb_set, 0 }, | |
4195 | { "even", s_even, 0 }, | |
4196 | { "ltorg", s_ltorg, 0 }, | |
4197 | { "pool", s_ltorg, 0 }, | |
4198 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4199 | { "cpu", s_arm_cpu, 0 }, |
4200 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4201 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4202 | { "fpu", s_arm_fpu, 0 }, |
c19d1205 | 4203 | #ifdef OBJ_ELF |
c921be7d NC |
4204 | { "word", s_arm_elf_cons, 4 }, |
4205 | { "long", s_arm_elf_cons, 4 }, | |
4206 | { "inst.n", s_arm_elf_inst, 2 }, | |
4207 | { "inst.w", s_arm_elf_inst, 4 }, | |
4208 | { "inst", s_arm_elf_inst, 0 }, | |
4209 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4210 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4211 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4212 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4213 | { "personality", s_arm_unwind_personality, 0 }, | |
4214 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4215 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4216 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4217 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4218 | { "movsp", s_arm_unwind_movsp, 0 }, |
4219 | { "pad", s_arm_unwind_pad, 0 }, | |
4220 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4221 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4222 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
4223 | #else |
4224 | { "word", cons, 4}, | |
f0927246 NC |
4225 | |
4226 | /* These are used for dwarf. */ | |
4227 | {"2byte", cons, 2}, | |
4228 | {"4byte", cons, 4}, | |
4229 | {"8byte", cons, 8}, | |
4230 | /* These are used for dwarf2. */ | |
4231 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4232 | { "loc", dwarf2_directive_loc, 0 }, | |
4233 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4234 | #endif |
4235 | { "extend", float_cons, 'x' }, | |
4236 | { "ldouble", float_cons, 'x' }, | |
4237 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4238 | #ifdef TE_PE |
4239 | {"secrel32", pe_directive_secrel, 0}, | |
4240 | #endif | |
c19d1205 ZW |
4241 | { 0, 0, 0 } |
4242 | }; | |
4243 | \f | |
4244 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4245 | |
c19d1205 ZW |
4246 | /* Generic immediate-value read function for use in insn parsing. |
4247 | STR points to the beginning of the immediate (the leading #); | |
4248 | VAL receives the value; if the value is outside [MIN, MAX] | |
4249 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4250 | optional. */ | |
b99bd4ef | 4251 | |
c19d1205 ZW |
4252 | static int |
4253 | parse_immediate (char **str, int *val, int min, int max, | |
4254 | bfd_boolean prefix_opt) | |
4255 | { | |
4256 | expressionS exp; | |
4257 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4258 | if (exp.X_op != O_constant) | |
b99bd4ef | 4259 | { |
c19d1205 ZW |
4260 | inst.error = _("constant expression required"); |
4261 | return FAIL; | |
4262 | } | |
b99bd4ef | 4263 | |
c19d1205 ZW |
4264 | if (exp.X_add_number < min || exp.X_add_number > max) |
4265 | { | |
4266 | inst.error = _("immediate value out of range"); | |
4267 | return FAIL; | |
4268 | } | |
b99bd4ef | 4269 | |
c19d1205 ZW |
4270 | *val = exp.X_add_number; |
4271 | return SUCCESS; | |
4272 | } | |
b99bd4ef | 4273 | |
5287ad62 | 4274 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4275 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4276 | instructions. Puts the result directly in inst.operands[i]. */ |
4277 | ||
4278 | static int | |
4279 | parse_big_immediate (char **str, int i) | |
4280 | { | |
4281 | expressionS exp; | |
4282 | char *ptr = *str; | |
4283 | ||
4284 | my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG); | |
4285 | ||
4286 | if (exp.X_op == O_constant) | |
036dc3f7 PB |
4287 | { |
4288 | inst.operands[i].imm = exp.X_add_number & 0xffffffff; | |
4289 | /* If we're on a 64-bit host, then a 64-bit number can be returned using | |
4290 | O_constant. We have to be careful not to break compilation for | |
4291 | 32-bit X_add_number, though. */ | |
4292 | if ((exp.X_add_number & ~0xffffffffl) != 0) | |
4293 | { | |
4294 | /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */ | |
4295 | inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff; | |
4296 | inst.operands[i].regisimm = 1; | |
4297 | } | |
4298 | } | |
5287ad62 JB |
4299 | else if (exp.X_op == O_big |
4300 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32 | |
4301 | && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64) | |
4302 | { | |
4303 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
4304 | /* Bignums have their least significant bits in | |
4305 | generic_bignum[0]. Make sure we put 32 bits in imm and | |
4306 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4307 | gas_assert (parts != 0); |
5287ad62 JB |
4308 | inst.operands[i].imm = 0; |
4309 | for (j = 0; j < parts; j++, idx++) | |
4310 | inst.operands[i].imm |= generic_bignum[idx] | |
4311 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4312 | inst.operands[i].reg = 0; | |
4313 | for (j = 0; j < parts; j++, idx++) | |
4314 | inst.operands[i].reg |= generic_bignum[idx] | |
4315 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
4316 | inst.operands[i].regisimm = 1; | |
4317 | } | |
4318 | else | |
4319 | return FAIL; | |
5f4273c7 | 4320 | |
5287ad62 JB |
4321 | *str = ptr; |
4322 | ||
4323 | return SUCCESS; | |
4324 | } | |
4325 | ||
c19d1205 ZW |
4326 | /* Returns the pseudo-register number of an FPA immediate constant, |
4327 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4328 | |
c19d1205 ZW |
4329 | static int |
4330 | parse_fpa_immediate (char ** str) | |
4331 | { | |
4332 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4333 | char * save_in; | |
4334 | expressionS exp; | |
4335 | int i; | |
4336 | int j; | |
b99bd4ef | 4337 | |
c19d1205 ZW |
4338 | /* First try and match exact strings, this is to guarantee |
4339 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4340 | |
c19d1205 ZW |
4341 | for (i = 0; fp_const[i]; i++) |
4342 | { | |
4343 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4344 | { |
c19d1205 | 4345 | char *start = *str; |
b99bd4ef | 4346 | |
c19d1205 ZW |
4347 | *str += strlen (fp_const[i]); |
4348 | if (is_end_of_line[(unsigned char) **str]) | |
4349 | return i + 8; | |
4350 | *str = start; | |
4351 | } | |
4352 | } | |
b99bd4ef | 4353 | |
c19d1205 ZW |
4354 | /* Just because we didn't get a match doesn't mean that the constant |
4355 | isn't valid, just that it is in a format that we don't | |
4356 | automatically recognize. Try parsing it with the standard | |
4357 | expression routines. */ | |
b99bd4ef | 4358 | |
c19d1205 | 4359 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4360 | |
c19d1205 ZW |
4361 | /* Look for a raw floating point number. */ |
4362 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4363 | && is_end_of_line[(unsigned char) *save_in]) | |
4364 | { | |
4365 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4366 | { | |
4367 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4368 | { |
c19d1205 ZW |
4369 | if (words[j] != fp_values[i][j]) |
4370 | break; | |
b99bd4ef NC |
4371 | } |
4372 | ||
c19d1205 | 4373 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4374 | { |
c19d1205 ZW |
4375 | *str = save_in; |
4376 | return i + 8; | |
b99bd4ef NC |
4377 | } |
4378 | } | |
4379 | } | |
b99bd4ef | 4380 | |
c19d1205 ZW |
4381 | /* Try and parse a more complex expression, this will probably fail |
4382 | unless the code uses a floating point prefix (eg "0f"). */ | |
4383 | save_in = input_line_pointer; | |
4384 | input_line_pointer = *str; | |
4385 | if (expression (&exp) == absolute_section | |
4386 | && exp.X_op == O_big | |
4387 | && exp.X_add_number < 0) | |
4388 | { | |
4389 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4390 | Ditto for 15. */ | |
4391 | if (gen_to_words (words, 5, (long) 15) == 0) | |
4392 | { | |
4393 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4394 | { | |
4395 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4396 | { | |
4397 | if (words[j] != fp_values[i][j]) | |
4398 | break; | |
4399 | } | |
b99bd4ef | 4400 | |
c19d1205 ZW |
4401 | if (j == MAX_LITTLENUMS) |
4402 | { | |
4403 | *str = input_line_pointer; | |
4404 | input_line_pointer = save_in; | |
4405 | return i + 8; | |
4406 | } | |
4407 | } | |
4408 | } | |
b99bd4ef NC |
4409 | } |
4410 | ||
c19d1205 ZW |
4411 | *str = input_line_pointer; |
4412 | input_line_pointer = save_in; | |
4413 | inst.error = _("invalid FPA immediate expression"); | |
4414 | return FAIL; | |
b99bd4ef NC |
4415 | } |
4416 | ||
136da414 JB |
4417 | /* Returns 1 if a number has "quarter-precision" float format |
4418 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4419 | ||
4420 | static int | |
4421 | is_quarter_float (unsigned imm) | |
4422 | { | |
4423 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4424 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4425 | } | |
4426 | ||
4427 | /* Parse an 8-bit "quarter-precision" floating point number of the form: | |
4428 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4429 | The zero and minus-zero cases need special handling, since they can't be |
4430 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4431 | loaded as integer constants. */ | |
136da414 JB |
4432 | |
4433 | static unsigned | |
4434 | parse_qfloat_immediate (char **ccp, int *immed) | |
4435 | { | |
4436 | char *str = *ccp; | |
c96612cc | 4437 | char *fpnum; |
136da414 | 4438 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4439 | int found_fpchar = 0; |
5f4273c7 | 4440 | |
136da414 | 4441 | skip_past_char (&str, '#'); |
5f4273c7 | 4442 | |
c96612cc JB |
4443 | /* We must not accidentally parse an integer as a floating-point number. Make |
4444 | sure that the value we parse is not an integer by checking for special | |
4445 | characters '.' or 'e'. | |
4446 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4447 | information isn't in a very usable state at parse time. */ | |
4448 | fpnum = str; | |
4449 | skip_whitespace (fpnum); | |
4450 | ||
4451 | if (strncmp (fpnum, "0x", 2) == 0) | |
4452 | return FAIL; | |
4453 | else | |
4454 | { | |
4455 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
4456 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') | |
4457 | { | |
4458 | found_fpchar = 1; | |
4459 | break; | |
4460 | } | |
4461 | ||
4462 | if (!found_fpchar) | |
4463 | return FAIL; | |
4464 | } | |
5f4273c7 | 4465 | |
136da414 JB |
4466 | if ((str = atof_ieee (str, 's', words)) != NULL) |
4467 | { | |
4468 | unsigned fpword = 0; | |
4469 | int i; | |
5f4273c7 | 4470 | |
136da414 JB |
4471 | /* Our FP word must be 32 bits (single-precision FP). */ |
4472 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
4473 | { | |
4474 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
4475 | fpword |= words[i]; | |
4476 | } | |
5f4273c7 | 4477 | |
c96612cc | 4478 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
136da414 JB |
4479 | *immed = fpword; |
4480 | else | |
4481 | return FAIL; | |
4482 | ||
4483 | *ccp = str; | |
5f4273c7 | 4484 | |
136da414 JB |
4485 | return SUCCESS; |
4486 | } | |
5f4273c7 | 4487 | |
136da414 JB |
4488 | return FAIL; |
4489 | } | |
4490 | ||
c19d1205 ZW |
4491 | /* Shift operands. */ |
4492 | enum shift_kind | |
b99bd4ef | 4493 | { |
c19d1205 ZW |
4494 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
4495 | }; | |
b99bd4ef | 4496 | |
c19d1205 ZW |
4497 | struct asm_shift_name |
4498 | { | |
4499 | const char *name; | |
4500 | enum shift_kind kind; | |
4501 | }; | |
b99bd4ef | 4502 | |
c19d1205 ZW |
4503 | /* Third argument to parse_shift. */ |
4504 | enum parse_shift_mode | |
4505 | { | |
4506 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
4507 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
4508 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
4509 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
4510 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
4511 | }; | |
b99bd4ef | 4512 | |
c19d1205 ZW |
4513 | /* Parse a <shift> specifier on an ARM data processing instruction. |
4514 | This has three forms: | |
b99bd4ef | 4515 | |
c19d1205 ZW |
4516 | (LSL|LSR|ASL|ASR|ROR) Rs |
4517 | (LSL|LSR|ASL|ASR|ROR) #imm | |
4518 | RRX | |
b99bd4ef | 4519 | |
c19d1205 ZW |
4520 | Note that ASL is assimilated to LSL in the instruction encoding, and |
4521 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 4522 | |
c19d1205 ZW |
4523 | static int |
4524 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 4525 | { |
c19d1205 ZW |
4526 | const struct asm_shift_name *shift_name; |
4527 | enum shift_kind shift; | |
4528 | char *s = *str; | |
4529 | char *p = s; | |
4530 | int reg; | |
b99bd4ef | 4531 | |
c19d1205 ZW |
4532 | for (p = *str; ISALPHA (*p); p++) |
4533 | ; | |
b99bd4ef | 4534 | |
c19d1205 | 4535 | if (p == *str) |
b99bd4ef | 4536 | { |
c19d1205 ZW |
4537 | inst.error = _("shift expression expected"); |
4538 | return FAIL; | |
b99bd4ef NC |
4539 | } |
4540 | ||
c19d1205 ZW |
4541 | shift_name = hash_find_n (arm_shift_hsh, *str, p - *str); |
4542 | ||
4543 | if (shift_name == NULL) | |
b99bd4ef | 4544 | { |
c19d1205 ZW |
4545 | inst.error = _("shift expression expected"); |
4546 | return FAIL; | |
b99bd4ef NC |
4547 | } |
4548 | ||
c19d1205 | 4549 | shift = shift_name->kind; |
b99bd4ef | 4550 | |
c19d1205 ZW |
4551 | switch (mode) |
4552 | { | |
4553 | case NO_SHIFT_RESTRICT: | |
4554 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 4555 | |
c19d1205 ZW |
4556 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
4557 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
4558 | { | |
4559 | inst.error = _("'LSL' or 'ASR' required"); | |
4560 | return FAIL; | |
4561 | } | |
4562 | break; | |
b99bd4ef | 4563 | |
c19d1205 ZW |
4564 | case SHIFT_LSL_IMMEDIATE: |
4565 | if (shift != SHIFT_LSL) | |
4566 | { | |
4567 | inst.error = _("'LSL' required"); | |
4568 | return FAIL; | |
4569 | } | |
4570 | break; | |
b99bd4ef | 4571 | |
c19d1205 ZW |
4572 | case SHIFT_ASR_IMMEDIATE: |
4573 | if (shift != SHIFT_ASR) | |
4574 | { | |
4575 | inst.error = _("'ASR' required"); | |
4576 | return FAIL; | |
4577 | } | |
4578 | break; | |
b99bd4ef | 4579 | |
c19d1205 ZW |
4580 | default: abort (); |
4581 | } | |
b99bd4ef | 4582 | |
c19d1205 ZW |
4583 | if (shift != SHIFT_RRX) |
4584 | { | |
4585 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
4586 | skip_whitespace (p); | |
b99bd4ef | 4587 | |
c19d1205 | 4588 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 4589 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4590 | { |
4591 | inst.operands[i].imm = reg; | |
4592 | inst.operands[i].immisreg = 1; | |
4593 | } | |
4594 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4595 | return FAIL; | |
4596 | } | |
4597 | inst.operands[i].shift_kind = shift; | |
4598 | inst.operands[i].shifted = 1; | |
4599 | *str = p; | |
4600 | return SUCCESS; | |
b99bd4ef NC |
4601 | } |
4602 | ||
c19d1205 | 4603 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 4604 | |
c19d1205 ZW |
4605 | #<immediate> |
4606 | #<immediate>, <rotate> | |
4607 | <Rm> | |
4608 | <Rm>, <shift> | |
b99bd4ef | 4609 | |
c19d1205 ZW |
4610 | where <shift> is defined by parse_shift above, and <rotate> is a |
4611 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 4612 | is deferred to md_apply_fix. */ |
b99bd4ef | 4613 | |
c19d1205 ZW |
4614 | static int |
4615 | parse_shifter_operand (char **str, int i) | |
4616 | { | |
4617 | int value; | |
4618 | expressionS expr; | |
b99bd4ef | 4619 | |
dcbf9037 | 4620 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
4621 | { |
4622 | inst.operands[i].reg = value; | |
4623 | inst.operands[i].isreg = 1; | |
b99bd4ef | 4624 | |
c19d1205 ZW |
4625 | /* parse_shift will override this if appropriate */ |
4626 | inst.reloc.exp.X_op = O_constant; | |
4627 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 4628 | |
c19d1205 ZW |
4629 | if (skip_past_comma (str) == FAIL) |
4630 | return SUCCESS; | |
b99bd4ef | 4631 | |
c19d1205 ZW |
4632 | /* Shift operation on register. */ |
4633 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
4634 | } |
4635 | ||
c19d1205 ZW |
4636 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
4637 | return FAIL; | |
b99bd4ef | 4638 | |
c19d1205 | 4639 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 4640 | { |
c19d1205 ZW |
4641 | /* #x, y -- ie explicit rotation by Y. */ |
4642 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
4643 | return FAIL; | |
b99bd4ef | 4644 | |
c19d1205 ZW |
4645 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
4646 | { | |
4647 | inst.error = _("constant expression expected"); | |
4648 | return FAIL; | |
4649 | } | |
b99bd4ef | 4650 | |
c19d1205 ZW |
4651 | value = expr.X_add_number; |
4652 | if (value < 0 || value > 30 || value % 2 != 0) | |
4653 | { | |
4654 | inst.error = _("invalid rotation"); | |
4655 | return FAIL; | |
4656 | } | |
4657 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
4658 | { | |
4659 | inst.error = _("invalid constant"); | |
4660 | return FAIL; | |
4661 | } | |
09d92015 | 4662 | |
55cf6793 | 4663 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
4664 | inst.reloc.exp.X_add_number |
4665 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
4666 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
4667 | } |
4668 | ||
c19d1205 ZW |
4669 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
4670 | inst.reloc.pc_rel = 0; | |
4671 | return SUCCESS; | |
09d92015 MM |
4672 | } |
4673 | ||
4962c51a MS |
4674 | /* Group relocation information. Each entry in the table contains the |
4675 | textual name of the relocation as may appear in assembler source | |
4676 | and must end with a colon. | |
4677 | Along with this textual name are the relocation codes to be used if | |
4678 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
4679 | an LDR, an LDRS, or an LDC. */ | |
4680 | ||
4681 | struct group_reloc_table_entry | |
4682 | { | |
4683 | const char *name; | |
4684 | int alu_code; | |
4685 | int ldr_code; | |
4686 | int ldrs_code; | |
4687 | int ldc_code; | |
4688 | }; | |
4689 | ||
4690 | typedef enum | |
4691 | { | |
4692 | /* Varieties of non-ALU group relocation. */ | |
4693 | ||
4694 | GROUP_LDR, | |
4695 | GROUP_LDRS, | |
4696 | GROUP_LDC | |
4697 | } group_reloc_type; | |
4698 | ||
4699 | static struct group_reloc_table_entry group_reloc_table[] = | |
4700 | { /* Program counter relative: */ | |
4701 | { "pc_g0_nc", | |
4702 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
4703 | 0, /* LDR */ | |
4704 | 0, /* LDRS */ | |
4705 | 0 }, /* LDC */ | |
4706 | { "pc_g0", | |
4707 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
4708 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
4709 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
4710 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
4711 | { "pc_g1_nc", | |
4712 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
4713 | 0, /* LDR */ | |
4714 | 0, /* LDRS */ | |
4715 | 0 }, /* LDC */ | |
4716 | { "pc_g1", | |
4717 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
4718 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
4719 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
4720 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
4721 | { "pc_g2", | |
4722 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
4723 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
4724 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
4725 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
4726 | /* Section base relative */ | |
4727 | { "sb_g0_nc", | |
4728 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
4729 | 0, /* LDR */ | |
4730 | 0, /* LDRS */ | |
4731 | 0 }, /* LDC */ | |
4732 | { "sb_g0", | |
4733 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
4734 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
4735 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
4736 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
4737 | { "sb_g1_nc", | |
4738 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
4739 | 0, /* LDR */ | |
4740 | 0, /* LDRS */ | |
4741 | 0 }, /* LDC */ | |
4742 | { "sb_g1", | |
4743 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
4744 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
4745 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
4746 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
4747 | { "sb_g2", | |
4748 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
4749 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
4750 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
4751 | BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */ | |
4752 | ||
4753 | /* Given the address of a pointer pointing to the textual name of a group | |
4754 | relocation as may appear in assembler source, attempt to find its details | |
4755 | in group_reloc_table. The pointer will be updated to the character after | |
4756 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
4757 | otherwise. On success, *entry will be updated to point at the relevant | |
4758 | group_reloc_table entry. */ | |
4759 | ||
4760 | static int | |
4761 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
4762 | { | |
4763 | unsigned int i; | |
4764 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
4765 | { | |
4766 | int length = strlen (group_reloc_table[i].name); | |
4767 | ||
5f4273c7 NC |
4768 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
4769 | && (*str)[length] == ':') | |
4962c51a MS |
4770 | { |
4771 | *out = &group_reloc_table[i]; | |
4772 | *str += (length + 1); | |
4773 | return SUCCESS; | |
4774 | } | |
4775 | } | |
4776 | ||
4777 | return FAIL; | |
4778 | } | |
4779 | ||
4780 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
4781 | (as for parse_shifter_operand) where group relocations are allowed: | |
4782 | ||
4783 | #<immediate> | |
4784 | #<immediate>, <rotate> | |
4785 | #:<group_reloc>:<expression> | |
4786 | <Rm> | |
4787 | <Rm>, <shift> | |
4788 | ||
4789 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
4790 | The hashes are optional. | |
4791 | ||
4792 | Everything else is as for parse_shifter_operand. */ | |
4793 | ||
4794 | static parse_operand_result | |
4795 | parse_shifter_operand_group_reloc (char **str, int i) | |
4796 | { | |
4797 | /* Determine if we have the sequence of characters #: or just : | |
4798 | coming next. If we do, then we check for a group relocation. | |
4799 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
4800 | ||
4801 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
4802 | || (*str)[0] == ':') | |
4803 | { | |
4804 | struct group_reloc_table_entry *entry; | |
4805 | ||
4806 | if ((*str)[0] == '#') | |
4807 | (*str) += 2; | |
4808 | else | |
4809 | (*str)++; | |
4810 | ||
4811 | /* Try to parse a group relocation. Anything else is an error. */ | |
4812 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
4813 | { | |
4814 | inst.error = _("unknown group relocation"); | |
4815 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4816 | } | |
4817 | ||
4818 | /* We now have the group relocation table entry corresponding to | |
4819 | the name in the assembler source. Next, we parse the expression. */ | |
4820 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) | |
4821 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4822 | ||
4823 | /* Record the relocation type (always the ALU variant here). */ | |
4824 | inst.reloc.type = entry->alu_code; | |
9c2799c2 | 4825 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
4826 | |
4827 | return PARSE_OPERAND_SUCCESS; | |
4828 | } | |
4829 | else | |
4830 | return parse_shifter_operand (str, i) == SUCCESS | |
4831 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; | |
4832 | ||
4833 | /* Never reached. */ | |
4834 | } | |
4835 | ||
c19d1205 ZW |
4836 | /* Parse all forms of an ARM address expression. Information is written |
4837 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 4838 | |
c19d1205 | 4839 | Preindexed addressing (.preind=1): |
09d92015 | 4840 | |
c19d1205 ZW |
4841 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
4842 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4843 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4844 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4845 | |
c19d1205 | 4846 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 4847 | |
c19d1205 | 4848 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 4849 | |
c19d1205 ZW |
4850 | [Rn], #offset .reg=Rn .reloc.exp=offset |
4851 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4852 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
4853 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 4854 | |
c19d1205 | 4855 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 4856 | |
c19d1205 | 4857 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 4858 | |
c19d1205 | 4859 | Other: |
09d92015 | 4860 | |
c19d1205 ZW |
4861 | [Rn]{!} shorthand for [Rn,#0]{!} |
4862 | =immediate .isreg=0 .reloc.exp=immediate | |
4863 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 4864 | |
c19d1205 ZW |
4865 | It is the caller's responsibility to check for addressing modes not |
4866 | supported by the instruction, and to set inst.reloc.type. */ | |
4867 | ||
4962c51a MS |
4868 | static parse_operand_result |
4869 | parse_address_main (char **str, int i, int group_relocations, | |
4870 | group_reloc_type group_type) | |
09d92015 | 4871 | { |
c19d1205 ZW |
4872 | char *p = *str; |
4873 | int reg; | |
09d92015 | 4874 | |
c19d1205 | 4875 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 4876 | { |
c19d1205 ZW |
4877 | if (skip_past_char (&p, '=') == FAIL) |
4878 | { | |
4879 | /* bare address - translate to PC-relative offset */ | |
4880 | inst.reloc.pc_rel = 1; | |
4881 | inst.operands[i].reg = REG_PC; | |
4882 | inst.operands[i].isreg = 1; | |
4883 | inst.operands[i].preind = 1; | |
4884 | } | |
4885 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 4886 | |
c19d1205 | 4887 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
4962c51a | 4888 | return PARSE_OPERAND_FAIL; |
09d92015 | 4889 | |
c19d1205 | 4890 | *str = p; |
4962c51a | 4891 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
4892 | } |
4893 | ||
dcbf9037 | 4894 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 4895 | { |
c19d1205 | 4896 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 4897 | return PARSE_OPERAND_FAIL; |
09d92015 | 4898 | } |
c19d1205 ZW |
4899 | inst.operands[i].reg = reg; |
4900 | inst.operands[i].isreg = 1; | |
09d92015 | 4901 | |
c19d1205 | 4902 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 4903 | { |
c19d1205 | 4904 | inst.operands[i].preind = 1; |
09d92015 | 4905 | |
c19d1205 ZW |
4906 | if (*p == '+') p++; |
4907 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
4908 | ||
dcbf9037 | 4909 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 4910 | { |
c19d1205 ZW |
4911 | inst.operands[i].imm = reg; |
4912 | inst.operands[i].immisreg = 1; | |
4913 | ||
4914 | if (skip_past_comma (&p) == SUCCESS) | |
4915 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 4916 | return PARSE_OPERAND_FAIL; |
c19d1205 | 4917 | } |
5287ad62 JB |
4918 | else if (skip_past_char (&p, ':') == SUCCESS) |
4919 | { | |
4920 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
4921 | code before we get to see it here. This may be subject to | |
4922 | change. */ | |
4923 | expressionS exp; | |
4924 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
4925 | if (exp.X_op != O_constant) | |
4926 | { | |
4927 | inst.error = _("alignment must be constant"); | |
4962c51a | 4928 | return PARSE_OPERAND_FAIL; |
5287ad62 JB |
4929 | } |
4930 | inst.operands[i].imm = exp.X_add_number << 8; | |
4931 | inst.operands[i].immisalign = 1; | |
4932 | /* Alignments are not pre-indexes. */ | |
4933 | inst.operands[i].preind = 0; | |
4934 | } | |
c19d1205 ZW |
4935 | else |
4936 | { | |
4937 | if (inst.operands[i].negative) | |
4938 | { | |
4939 | inst.operands[i].negative = 0; | |
4940 | p--; | |
4941 | } | |
4962c51a | 4942 | |
5f4273c7 NC |
4943 | if (group_relocations |
4944 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
4945 | { |
4946 | struct group_reloc_table_entry *entry; | |
4947 | ||
4948 | /* Skip over the #: or : sequence. */ | |
4949 | if (*p == '#') | |
4950 | p += 2; | |
4951 | else | |
4952 | p++; | |
4953 | ||
4954 | /* Try to parse a group relocation. Anything else is an | |
4955 | error. */ | |
4956 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) | |
4957 | { | |
4958 | inst.error = _("unknown group relocation"); | |
4959 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4960 | } | |
4961 | ||
4962 | /* We now have the group relocation table entry corresponding to | |
4963 | the name in the assembler source. Next, we parse the | |
4964 | expression. */ | |
4965 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
4966 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4967 | ||
4968 | /* Record the relocation type. */ | |
4969 | switch (group_type) | |
4970 | { | |
4971 | case GROUP_LDR: | |
4972 | inst.reloc.type = entry->ldr_code; | |
4973 | break; | |
4974 | ||
4975 | case GROUP_LDRS: | |
4976 | inst.reloc.type = entry->ldrs_code; | |
4977 | break; | |
4978 | ||
4979 | case GROUP_LDC: | |
4980 | inst.reloc.type = entry->ldc_code; | |
4981 | break; | |
4982 | ||
4983 | default: | |
9c2799c2 | 4984 | gas_assert (0); |
4962c51a MS |
4985 | } |
4986 | ||
4987 | if (inst.reloc.type == 0) | |
4988 | { | |
4989 | inst.error = _("this group relocation is not allowed on this instruction"); | |
4990 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
4991 | } | |
4992 | } | |
4993 | else | |
4994 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4995 | return PARSE_OPERAND_FAIL; | |
09d92015 MM |
4996 | } |
4997 | } | |
4998 | ||
c19d1205 | 4999 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5000 | { |
c19d1205 | 5001 | inst.error = _("']' expected"); |
4962c51a | 5002 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5003 | } |
5004 | ||
c19d1205 ZW |
5005 | if (skip_past_char (&p, '!') == SUCCESS) |
5006 | inst.operands[i].writeback = 1; | |
09d92015 | 5007 | |
c19d1205 | 5008 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5009 | { |
c19d1205 ZW |
5010 | if (skip_past_char (&p, '{') == SUCCESS) |
5011 | { | |
5012 | /* [Rn], {expr} - unindexed, with option */ | |
5013 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5014 | 0, 255, TRUE) == FAIL) |
4962c51a | 5015 | return PARSE_OPERAND_FAIL; |
09d92015 | 5016 | |
c19d1205 ZW |
5017 | if (skip_past_char (&p, '}') == FAIL) |
5018 | { | |
5019 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5020 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5021 | } |
5022 | if (inst.operands[i].preind) | |
5023 | { | |
5024 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5025 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5026 | } |
5027 | *str = p; | |
4962c51a | 5028 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5029 | } |
c19d1205 ZW |
5030 | else |
5031 | { | |
5032 | inst.operands[i].postind = 1; | |
5033 | inst.operands[i].writeback = 1; | |
09d92015 | 5034 | |
c19d1205 ZW |
5035 | if (inst.operands[i].preind) |
5036 | { | |
5037 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5038 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5039 | } |
09d92015 | 5040 | |
c19d1205 ZW |
5041 | if (*p == '+') p++; |
5042 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5043 | |
dcbf9037 | 5044 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5045 | { |
5287ad62 JB |
5046 | /* We might be using the immediate for alignment already. If we |
5047 | are, OR the register number into the low-order bits. */ | |
5048 | if (inst.operands[i].immisalign) | |
5049 | inst.operands[i].imm |= reg; | |
5050 | else | |
5051 | inst.operands[i].imm = reg; | |
c19d1205 | 5052 | inst.operands[i].immisreg = 1; |
a737bd4d | 5053 | |
c19d1205 ZW |
5054 | if (skip_past_comma (&p) == SUCCESS) |
5055 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5056 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5057 | } |
5058 | else | |
5059 | { | |
5060 | if (inst.operands[i].negative) | |
5061 | { | |
5062 | inst.operands[i].negative = 0; | |
5063 | p--; | |
5064 | } | |
5065 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5066 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5067 | } |
5068 | } | |
a737bd4d NC |
5069 | } |
5070 | ||
c19d1205 ZW |
5071 | /* If at this point neither .preind nor .postind is set, we have a |
5072 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5073 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5074 | { | |
5075 | inst.operands[i].preind = 1; | |
5076 | inst.reloc.exp.X_op = O_constant; | |
5077 | inst.reloc.exp.X_add_number = 0; | |
5078 | } | |
5079 | *str = p; | |
4962c51a MS |
5080 | return PARSE_OPERAND_SUCCESS; |
5081 | } | |
5082 | ||
5083 | static int | |
5084 | parse_address (char **str, int i) | |
5085 | { | |
5086 | return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS | |
5087 | ? SUCCESS : FAIL; | |
5088 | } | |
5089 | ||
5090 | static parse_operand_result | |
5091 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5092 | { | |
5093 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5094 | } |
5095 | ||
b6895b4f PB |
5096 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5097 | static int | |
5098 | parse_half (char **str) | |
5099 | { | |
5100 | char * p; | |
5f4273c7 | 5101 | |
b6895b4f PB |
5102 | p = *str; |
5103 | skip_past_char (&p, '#'); | |
5f4273c7 | 5104 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5105 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5106 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5107 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5108 | ||
5109 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5110 | { | |
5111 | p += 9; | |
5f4273c7 | 5112 | skip_whitespace (p); |
b6895b4f PB |
5113 | } |
5114 | ||
5115 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5116 | return FAIL; | |
5117 | ||
5118 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5119 | { | |
5120 | if (inst.reloc.exp.X_op != O_constant) | |
5121 | { | |
5122 | inst.error = _("constant expression expected"); | |
5123 | return FAIL; | |
5124 | } | |
5125 | if (inst.reloc.exp.X_add_number < 0 | |
5126 | || inst.reloc.exp.X_add_number > 0xffff) | |
5127 | { | |
5128 | inst.error = _("immediate value out of range"); | |
5129 | return FAIL; | |
5130 | } | |
5131 | } | |
5132 | *str = p; | |
5133 | return SUCCESS; | |
5134 | } | |
5135 | ||
c19d1205 | 5136 | /* Miscellaneous. */ |
a737bd4d | 5137 | |
c19d1205 ZW |
5138 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5139 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5140 | static int | |
5141 | parse_psr (char **str) | |
09d92015 | 5142 | { |
c19d1205 ZW |
5143 | char *p; |
5144 | unsigned long psr_field; | |
62b3e311 PB |
5145 | const struct asm_psr *psr; |
5146 | char *start; | |
09d92015 | 5147 | |
c19d1205 ZW |
5148 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5149 | feature for ease of use and backwards compatibility. */ | |
5150 | p = *str; | |
62b3e311 | 5151 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 5152 | psr_field = SPSR_BIT; |
62b3e311 | 5153 | else if (strncasecmp (p, "CPSR", 4) == 0) |
c19d1205 ZW |
5154 | psr_field = 0; |
5155 | else | |
62b3e311 PB |
5156 | { |
5157 | start = p; | |
5158 | do | |
5159 | p++; | |
5160 | while (ISALNUM (*p) || *p == '_'); | |
5161 | ||
5162 | psr = hash_find_n (arm_v7m_psr_hsh, start, p - start); | |
5163 | if (!psr) | |
5164 | return FAIL; | |
09d92015 | 5165 | |
62b3e311 PB |
5166 | *str = p; |
5167 | return psr->field; | |
5168 | } | |
09d92015 | 5169 | |
62b3e311 | 5170 | p += 4; |
c19d1205 ZW |
5171 | if (*p == '_') |
5172 | { | |
5173 | /* A suffix follows. */ | |
c19d1205 ZW |
5174 | p++; |
5175 | start = p; | |
a737bd4d | 5176 | |
c19d1205 ZW |
5177 | do |
5178 | p++; | |
5179 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5180 | |
c19d1205 ZW |
5181 | psr = hash_find_n (arm_psr_hsh, start, p - start); |
5182 | if (!psr) | |
5183 | goto error; | |
a737bd4d | 5184 | |
c19d1205 | 5185 | psr_field |= psr->field; |
a737bd4d | 5186 | } |
c19d1205 | 5187 | else |
a737bd4d | 5188 | { |
c19d1205 ZW |
5189 | if (ISALNUM (*p)) |
5190 | goto error; /* Garbage after "[CS]PSR". */ | |
5191 | ||
5192 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5193 | } |
c19d1205 ZW |
5194 | *str = p; |
5195 | return psr_field; | |
a737bd4d | 5196 | |
c19d1205 ZW |
5197 | error: |
5198 | inst.error = _("flag for {c}psr instruction expected"); | |
5199 | return FAIL; | |
a737bd4d NC |
5200 | } |
5201 | ||
c19d1205 ZW |
5202 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5203 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5204 | |
c19d1205 ZW |
5205 | static int |
5206 | parse_cps_flags (char **str) | |
a737bd4d | 5207 | { |
c19d1205 ZW |
5208 | int val = 0; |
5209 | int saw_a_flag = 0; | |
5210 | char *s = *str; | |
a737bd4d | 5211 | |
c19d1205 ZW |
5212 | for (;;) |
5213 | switch (*s++) | |
5214 | { | |
5215 | case '\0': case ',': | |
5216 | goto done; | |
a737bd4d | 5217 | |
c19d1205 ZW |
5218 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5219 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5220 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5221 | |
c19d1205 ZW |
5222 | default: |
5223 | inst.error = _("unrecognized CPS flag"); | |
5224 | return FAIL; | |
5225 | } | |
a737bd4d | 5226 | |
c19d1205 ZW |
5227 | done: |
5228 | if (saw_a_flag == 0) | |
a737bd4d | 5229 | { |
c19d1205 ZW |
5230 | inst.error = _("missing CPS flags"); |
5231 | return FAIL; | |
a737bd4d | 5232 | } |
a737bd4d | 5233 | |
c19d1205 ZW |
5234 | *str = s - 1; |
5235 | return val; | |
a737bd4d NC |
5236 | } |
5237 | ||
c19d1205 ZW |
5238 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
5239 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
5240 | |
5241 | static int | |
c19d1205 | 5242 | parse_endian_specifier (char **str) |
a737bd4d | 5243 | { |
c19d1205 ZW |
5244 | int little_endian; |
5245 | char *s = *str; | |
a737bd4d | 5246 | |
c19d1205 ZW |
5247 | if (strncasecmp (s, "BE", 2)) |
5248 | little_endian = 0; | |
5249 | else if (strncasecmp (s, "LE", 2)) | |
5250 | little_endian = 1; | |
5251 | else | |
a737bd4d | 5252 | { |
c19d1205 | 5253 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5254 | return FAIL; |
5255 | } | |
5256 | ||
c19d1205 | 5257 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 5258 | { |
c19d1205 | 5259 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
5260 | return FAIL; |
5261 | } | |
5262 | ||
c19d1205 ZW |
5263 | *str = s + 2; |
5264 | return little_endian; | |
5265 | } | |
a737bd4d | 5266 | |
c19d1205 ZW |
5267 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
5268 | value suitable for poking into the rotate field of an sxt or sxta | |
5269 | instruction, or FAIL on error. */ | |
5270 | ||
5271 | static int | |
5272 | parse_ror (char **str) | |
5273 | { | |
5274 | int rot; | |
5275 | char *s = *str; | |
5276 | ||
5277 | if (strncasecmp (s, "ROR", 3) == 0) | |
5278 | s += 3; | |
5279 | else | |
a737bd4d | 5280 | { |
c19d1205 | 5281 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
5282 | return FAIL; |
5283 | } | |
c19d1205 ZW |
5284 | |
5285 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
5286 | return FAIL; | |
5287 | ||
5288 | switch (rot) | |
a737bd4d | 5289 | { |
c19d1205 ZW |
5290 | case 0: *str = s; return 0x0; |
5291 | case 8: *str = s; return 0x1; | |
5292 | case 16: *str = s; return 0x2; | |
5293 | case 24: *str = s; return 0x3; | |
5294 | ||
5295 | default: | |
5296 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
5297 | return FAIL; |
5298 | } | |
c19d1205 | 5299 | } |
a737bd4d | 5300 | |
c19d1205 ZW |
5301 | /* Parse a conditional code (from conds[] below). The value returned is in the |
5302 | range 0 .. 14, or FAIL. */ | |
5303 | static int | |
5304 | parse_cond (char **str) | |
5305 | { | |
c462b453 | 5306 | char *q; |
c19d1205 | 5307 | const struct asm_cond *c; |
c462b453 PB |
5308 | int n; |
5309 | /* Condition codes are always 2 characters, so matching up to | |
5310 | 3 characters is sufficient. */ | |
5311 | char cond[3]; | |
a737bd4d | 5312 | |
c462b453 PB |
5313 | q = *str; |
5314 | n = 0; | |
5315 | while (ISALPHA (*q) && n < 3) | |
5316 | { | |
e07e6e58 | 5317 | cond[n] = TOLOWER (*q); |
c462b453 PB |
5318 | q++; |
5319 | n++; | |
5320 | } | |
a737bd4d | 5321 | |
c462b453 | 5322 | c = hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 5323 | if (!c) |
a737bd4d | 5324 | { |
c19d1205 | 5325 | inst.error = _("condition required"); |
a737bd4d NC |
5326 | return FAIL; |
5327 | } | |
5328 | ||
c19d1205 ZW |
5329 | *str = q; |
5330 | return c->value; | |
5331 | } | |
5332 | ||
62b3e311 PB |
5333 | /* Parse an option for a barrier instruction. Returns the encoding for the |
5334 | option, or FAIL. */ | |
5335 | static int | |
5336 | parse_barrier (char **str) | |
5337 | { | |
5338 | char *p, *q; | |
5339 | const struct asm_barrier_opt *o; | |
5340 | ||
5341 | p = q = *str; | |
5342 | while (ISALPHA (*q)) | |
5343 | q++; | |
5344 | ||
5345 | o = hash_find_n (arm_barrier_opt_hsh, p, q - p); | |
5346 | if (!o) | |
5347 | return FAIL; | |
5348 | ||
5349 | *str = q; | |
5350 | return o->value; | |
5351 | } | |
5352 | ||
92e90b6e PB |
5353 | /* Parse the operands of a table branch instruction. Similar to a memory |
5354 | operand. */ | |
5355 | static int | |
5356 | parse_tb (char **str) | |
5357 | { | |
5358 | char * p = *str; | |
5359 | int reg; | |
5360 | ||
5361 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
5362 | { |
5363 | inst.error = _("'[' expected"); | |
5364 | return FAIL; | |
5365 | } | |
92e90b6e | 5366 | |
dcbf9037 | 5367 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5368 | { |
5369 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5370 | return FAIL; | |
5371 | } | |
5372 | inst.operands[0].reg = reg; | |
5373 | ||
5374 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
5375 | { |
5376 | inst.error = _("',' expected"); | |
5377 | return FAIL; | |
5378 | } | |
5f4273c7 | 5379 | |
dcbf9037 | 5380 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
5381 | { |
5382 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
5383 | return FAIL; | |
5384 | } | |
5385 | inst.operands[0].imm = reg; | |
5386 | ||
5387 | if (skip_past_comma (&p) == SUCCESS) | |
5388 | { | |
5389 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
5390 | return FAIL; | |
5391 | if (inst.reloc.exp.X_add_number != 1) | |
5392 | { | |
5393 | inst.error = _("invalid shift"); | |
5394 | return FAIL; | |
5395 | } | |
5396 | inst.operands[0].shifted = 1; | |
5397 | } | |
5398 | ||
5399 | if (skip_past_char (&p, ']') == FAIL) | |
5400 | { | |
5401 | inst.error = _("']' expected"); | |
5402 | return FAIL; | |
5403 | } | |
5404 | *str = p; | |
5405 | return SUCCESS; | |
5406 | } | |
5407 | ||
5287ad62 JB |
5408 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
5409 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
5410 | Up to four operands may be read; this function handles setting the |
5411 | ".present" field for each read operand itself. | |
5287ad62 JB |
5412 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
5413 | else returns FAIL. */ | |
5414 | ||
5415 | static int | |
5416 | parse_neon_mov (char **str, int *which_operand) | |
5417 | { | |
5418 | int i = *which_operand, val; | |
5419 | enum arm_reg_type rtype; | |
5420 | char *ptr = *str; | |
dcbf9037 | 5421 | struct neon_type_el optype; |
5f4273c7 | 5422 | |
dcbf9037 | 5423 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5424 | { |
5425 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
5426 | inst.operands[i].reg = val; | |
5427 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 5428 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5429 | inst.operands[i++].present = 1; |
5430 | ||
5431 | if (skip_past_comma (&ptr) == FAIL) | |
5432 | goto wanted_comma; | |
5f4273c7 | 5433 | |
dcbf9037 | 5434 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5287ad62 | 5435 | goto wanted_arm; |
5f4273c7 | 5436 | |
5287ad62 JB |
5437 | inst.operands[i].reg = val; |
5438 | inst.operands[i].isreg = 1; | |
5439 | inst.operands[i].present = 1; | |
5440 | } | |
037e8744 | 5441 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
dcbf9037 | 5442 | != FAIL) |
5287ad62 JB |
5443 | { |
5444 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
5445 | if (skip_past_comma (&ptr) == FAIL) | |
5446 | goto wanted_comma; | |
5f4273c7 | 5447 | |
5287ad62 JB |
5448 | inst.operands[i].reg = val; |
5449 | inst.operands[i].isreg = 1; | |
5450 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5451 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5452 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5453 | inst.operands[i].vectype = optype; |
5287ad62 JB |
5454 | inst.operands[i++].present = 1; |
5455 | ||
dcbf9037 | 5456 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 5457 | { |
037e8744 JB |
5458 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. |
5459 | Case 13: VMOV <Sd>, <Rm> */ | |
5287ad62 JB |
5460 | inst.operands[i].reg = val; |
5461 | inst.operands[i].isreg = 1; | |
037e8744 | 5462 | inst.operands[i].present = 1; |
5287ad62 JB |
5463 | |
5464 | if (rtype == REG_TYPE_NQ) | |
5465 | { | |
dcbf9037 | 5466 | first_error (_("can't use Neon quad register here")); |
5287ad62 JB |
5467 | return FAIL; |
5468 | } | |
037e8744 JB |
5469 | else if (rtype != REG_TYPE_VFS) |
5470 | { | |
5471 | i++; | |
5472 | if (skip_past_comma (&ptr) == FAIL) | |
5473 | goto wanted_comma; | |
5474 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5475 | goto wanted_arm; | |
5476 | inst.operands[i].reg = val; | |
5477 | inst.operands[i].isreg = 1; | |
5478 | inst.operands[i].present = 1; | |
5479 | } | |
5287ad62 | 5480 | } |
037e8744 JB |
5481 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
5482 | &optype)) != FAIL) | |
5287ad62 JB |
5483 | { |
5484 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
037e8744 JB |
5485 | Case 1: VMOV<c><q> <Dd>, <Dm> |
5486 | Case 8: VMOV.F32 <Sd>, <Sm> | |
5487 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
5287ad62 JB |
5488 | |
5489 | inst.operands[i].reg = val; | |
5490 | inst.operands[i].isreg = 1; | |
5491 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
5492 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
5493 | inst.operands[i].isvec = 1; | |
dcbf9037 | 5494 | inst.operands[i].vectype = optype; |
5287ad62 | 5495 | inst.operands[i].present = 1; |
5f4273c7 | 5496 | |
037e8744 JB |
5497 | if (skip_past_comma (&ptr) == SUCCESS) |
5498 | { | |
5499 | /* Case 15. */ | |
5500 | i++; | |
5501 | ||
5502 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
5503 | goto wanted_arm; | |
5504 | ||
5505 | inst.operands[i].reg = val; | |
5506 | inst.operands[i].isreg = 1; | |
5507 | inst.operands[i++].present = 1; | |
5f4273c7 | 5508 | |
037e8744 JB |
5509 | if (skip_past_comma (&ptr) == FAIL) |
5510 | goto wanted_comma; | |
5f4273c7 | 5511 | |
037e8744 JB |
5512 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
5513 | goto wanted_arm; | |
5f4273c7 | 5514 | |
037e8744 JB |
5515 | inst.operands[i].reg = val; |
5516 | inst.operands[i].isreg = 1; | |
5517 | inst.operands[i++].present = 1; | |
5518 | } | |
5287ad62 | 5519 | } |
4641781c PB |
5520 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
5521 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> | |
5522 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
5523 | Case 10: VMOV.F32 <Sd>, #<imm> | |
5524 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
5525 | inst.operands[i].immisfloat = 1; | |
5526 | else if (parse_big_immediate (&ptr, i) == SUCCESS) | |
5527 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> | |
5528 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
5529 | ; | |
5287ad62 JB |
5530 | else |
5531 | { | |
dcbf9037 | 5532 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); |
5287ad62 JB |
5533 | return FAIL; |
5534 | } | |
5535 | } | |
dcbf9037 | 5536 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5537 | { |
5538 | /* Cases 6, 7. */ | |
5539 | inst.operands[i].reg = val; | |
5540 | inst.operands[i].isreg = 1; | |
5541 | inst.operands[i++].present = 1; | |
5f4273c7 | 5542 | |
5287ad62 JB |
5543 | if (skip_past_comma (&ptr) == FAIL) |
5544 | goto wanted_comma; | |
5f4273c7 | 5545 | |
dcbf9037 | 5546 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
5547 | { |
5548 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
5549 | inst.operands[i].reg = val; | |
5550 | inst.operands[i].isscalar = 1; | |
5551 | inst.operands[i].present = 1; | |
dcbf9037 | 5552 | inst.operands[i].vectype = optype; |
5287ad62 | 5553 | } |
dcbf9037 | 5554 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
5555 | { |
5556 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
5557 | inst.operands[i].reg = val; | |
5558 | inst.operands[i].isreg = 1; | |
5559 | inst.operands[i++].present = 1; | |
5f4273c7 | 5560 | |
5287ad62 JB |
5561 | if (skip_past_comma (&ptr) == FAIL) |
5562 | goto wanted_comma; | |
5f4273c7 | 5563 | |
037e8744 | 5564 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) |
dcbf9037 | 5565 | == FAIL) |
5287ad62 | 5566 | { |
037e8744 | 5567 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); |
5287ad62 JB |
5568 | return FAIL; |
5569 | } | |
5570 | ||
5571 | inst.operands[i].reg = val; | |
5572 | inst.operands[i].isreg = 1; | |
037e8744 JB |
5573 | inst.operands[i].isvec = 1; |
5574 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
dcbf9037 | 5575 | inst.operands[i].vectype = optype; |
5287ad62 | 5576 | inst.operands[i].present = 1; |
5f4273c7 | 5577 | |
037e8744 JB |
5578 | if (rtype == REG_TYPE_VFS) |
5579 | { | |
5580 | /* Case 14. */ | |
5581 | i++; | |
5582 | if (skip_past_comma (&ptr) == FAIL) | |
5583 | goto wanted_comma; | |
5584 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
5585 | &optype)) == FAIL) | |
5586 | { | |
5587 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
5588 | return FAIL; | |
5589 | } | |
5590 | inst.operands[i].reg = val; | |
5591 | inst.operands[i].isreg = 1; | |
5592 | inst.operands[i].isvec = 1; | |
5593 | inst.operands[i].issingle = 1; | |
5594 | inst.operands[i].vectype = optype; | |
5595 | inst.operands[i].present = 1; | |
5596 | } | |
5597 | } | |
5598 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) | |
5599 | != FAIL) | |
5600 | { | |
5601 | /* Case 13. */ | |
5602 | inst.operands[i].reg = val; | |
5603 | inst.operands[i].isreg = 1; | |
5604 | inst.operands[i].isvec = 1; | |
5605 | inst.operands[i].issingle = 1; | |
5606 | inst.operands[i].vectype = optype; | |
5607 | inst.operands[i++].present = 1; | |
5287ad62 JB |
5608 | } |
5609 | } | |
5610 | else | |
5611 | { | |
dcbf9037 | 5612 | first_error (_("parse error")); |
5287ad62 JB |
5613 | return FAIL; |
5614 | } | |
5615 | ||
5616 | /* Successfully parsed the operands. Update args. */ | |
5617 | *which_operand = i; | |
5618 | *str = ptr; | |
5619 | return SUCCESS; | |
5620 | ||
5f4273c7 | 5621 | wanted_comma: |
dcbf9037 | 5622 | first_error (_("expected comma")); |
5287ad62 | 5623 | return FAIL; |
5f4273c7 NC |
5624 | |
5625 | wanted_arm: | |
dcbf9037 | 5626 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 5627 | return FAIL; |
5287ad62 JB |
5628 | } |
5629 | ||
c19d1205 ZW |
5630 | /* Matcher codes for parse_operands. */ |
5631 | enum operand_parse_code | |
5632 | { | |
5633 | OP_stop, /* end of line */ | |
5634 | ||
5635 | OP_RR, /* ARM register */ | |
5636 | OP_RRnpc, /* ARM register, not r15 */ | |
5637 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
5638 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
5639 | OP_RCP, /* Coprocessor number */ | |
5640 | OP_RCN, /* Coprocessor register */ | |
5641 | OP_RF, /* FPA register */ | |
5642 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
5643 | OP_RVD, /* VFP double precision register (0..15) */ |
5644 | OP_RND, /* Neon double precision register (0..31) */ | |
5645 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 5646 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 5647 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 5648 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 5649 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
5650 | OP_RVC, /* VFP control register */ |
5651 | OP_RMF, /* Maverick F register */ | |
5652 | OP_RMD, /* Maverick D register */ | |
5653 | OP_RMFX, /* Maverick FX register */ | |
5654 | OP_RMDX, /* Maverick DX register */ | |
5655 | OP_RMAX, /* Maverick AX register */ | |
5656 | OP_RMDS, /* Maverick DSPSC register */ | |
5657 | OP_RIWR, /* iWMMXt wR register */ | |
5658 | OP_RIWC, /* iWMMXt wC register */ | |
5659 | OP_RIWG, /* iWMMXt wCG register */ | |
5660 | OP_RXA, /* XScale accumulator register */ | |
5661 | ||
5662 | OP_REGLST, /* ARM register list */ | |
5663 | OP_VRSLST, /* VFP single-precision register list */ | |
5664 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 5665 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
5666 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
5667 | OP_NSTRLST, /* Neon element/structure list */ | |
5668 | ||
5669 | OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */ | |
5670 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ | |
037e8744 | 5671 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
5287ad62 | 5672 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 5673 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
5674 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
5675 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
5676 | OP_VMOV, /* Neon VMOV operands. */ | |
5677 | OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */ | |
5678 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ | |
2d447fca | 5679 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
5680 | |
5681 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
5682 | OP_I7, /* immediate value 0 .. 7 */ |
5683 | OP_I15, /* 0 .. 15 */ | |
5684 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 5685 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
5686 | OP_I31, /* 0 .. 31 */ |
5687 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
5688 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
5689 | OP_I32z, /* 0 .. 32 */ |
5690 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 5691 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
5692 | OP_I64, /* 1 .. 64 */ |
5693 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 5694 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
5695 | |
5696 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
5697 | OP_I7b, /* 0 .. 7 */ | |
5698 | OP_I15b, /* 0 .. 15 */ | |
5699 | OP_I31b, /* 0 .. 31 */ | |
5700 | ||
5701 | OP_SH, /* shifter operand */ | |
4962c51a | 5702 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 5703 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
5704 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
5705 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
5706 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
5707 | OP_EXP, /* arbitrary expression */ |
5708 | OP_EXPi, /* same, with optional immediate prefix */ | |
5709 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 5710 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
5711 | |
5712 | OP_CPSF, /* CPS flags */ | |
5713 | OP_ENDI, /* Endianness specifier */ | |
5714 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
5715 | OP_COND, /* conditional code */ | |
92e90b6e | 5716 | OP_TB, /* Table branch. */ |
c19d1205 | 5717 | |
037e8744 JB |
5718 | OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */ |
5719 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ | |
5720 | ||
c19d1205 ZW |
5721 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
5722 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
5723 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
5724 | OP_RF_IF, /* FPA register or immediate */ | |
5725 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 5726 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
5727 | |
5728 | /* Optional operands. */ | |
5729 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
5730 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 5731 | OP_oI32b, /* 1 .. 32 */ |
c19d1205 ZW |
5732 | OP_oIffffb, /* 0 .. 65535 */ |
5733 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
5734 | ||
5735 | OP_oRR, /* ARM register */ | |
5736 | OP_oRRnpc, /* ARM register, not the PC */ | |
b6702015 | 5737 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
5738 | OP_oRND, /* Optional Neon double precision register */ |
5739 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5740 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 5741 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
5742 | OP_oSHll, /* LSL immediate */ |
5743 | OP_oSHar, /* ASR immediate */ | |
5744 | OP_oSHllar, /* LSL or ASR immediate */ | |
5745 | OP_oROR, /* ROR 0/8/16/24 */ | |
62b3e311 | 5746 | OP_oBARRIER, /* Option argument for a barrier instruction. */ |
c19d1205 ZW |
5747 | |
5748 | OP_FIRST_OPTIONAL = OP_oI7b | |
5749 | }; | |
a737bd4d | 5750 | |
c19d1205 ZW |
5751 | /* Generic instruction operand parser. This does no encoding and no |
5752 | semantic validation; it merely squirrels values away in the inst | |
5753 | structure. Returns SUCCESS or FAIL depending on whether the | |
5754 | specified grammar matched. */ | |
5755 | static int | |
ca3f61f7 | 5756 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
5757 | { |
5758 | unsigned const char *upat = pattern; | |
5759 | char *backtrack_pos = 0; | |
5760 | const char *backtrack_error = 0; | |
5761 | int i, val, backtrack_index = 0; | |
5287ad62 | 5762 | enum arm_reg_type rtype; |
4962c51a | 5763 | parse_operand_result result; |
c19d1205 | 5764 | |
e07e6e58 NC |
5765 | #define po_char_or_fail(chr) \ |
5766 | do \ | |
5767 | { \ | |
5768 | if (skip_past_char (&str, chr) == FAIL) \ | |
5769 | goto bad_args; \ | |
5770 | } \ | |
5771 | while (0) | |
c19d1205 | 5772 | |
e07e6e58 NC |
5773 | #define po_reg_or_fail(regtype) \ |
5774 | do \ | |
dcbf9037 | 5775 | { \ |
e07e6e58 NC |
5776 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
5777 | & inst.operands[i].vectype); \ | |
5778 | if (val == FAIL) \ | |
5779 | { \ | |
5780 | first_error (_(reg_expected_msgs[regtype])); \ | |
5781 | goto failure; \ | |
5782 | } \ | |
5783 | inst.operands[i].reg = val; \ | |
5784 | inst.operands[i].isreg = 1; \ | |
5785 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5786 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5787 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5788 | || rtype == REG_TYPE_VFD \ | |
5789 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 5790 | } \ |
e07e6e58 NC |
5791 | while (0) |
5792 | ||
5793 | #define po_reg_or_goto(regtype, label) \ | |
5794 | do \ | |
5795 | { \ | |
5796 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
5797 | & inst.operands[i].vectype); \ | |
5798 | if (val == FAIL) \ | |
5799 | goto label; \ | |
dcbf9037 | 5800 | \ |
e07e6e58 NC |
5801 | inst.operands[i].reg = val; \ |
5802 | inst.operands[i].isreg = 1; \ | |
5803 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
5804 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
5805 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
5806 | || rtype == REG_TYPE_VFD \ | |
5807 | || rtype == REG_TYPE_NQ); \ | |
5808 | } \ | |
5809 | while (0) | |
5810 | ||
5811 | #define po_imm_or_fail(min, max, popt) \ | |
5812 | do \ | |
5813 | { \ | |
5814 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
5815 | goto failure; \ | |
5816 | inst.operands[i].imm = val; \ | |
5817 | } \ | |
5818 | while (0) | |
5819 | ||
5820 | #define po_scalar_or_goto(elsz, label) \ | |
5821 | do \ | |
5822 | { \ | |
5823 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
5824 | if (val == FAIL) \ | |
5825 | goto label; \ | |
5826 | inst.operands[i].reg = val; \ | |
5827 | inst.operands[i].isscalar = 1; \ | |
5828 | } \ | |
5829 | while (0) | |
5830 | ||
5831 | #define po_misc_or_fail(expr) \ | |
5832 | do \ | |
5833 | { \ | |
5834 | if (expr) \ | |
5835 | goto failure; \ | |
5836 | } \ | |
5837 | while (0) | |
5838 | ||
5839 | #define po_misc_or_fail_no_backtrack(expr) \ | |
5840 | do \ | |
5841 | { \ | |
5842 | result = expr; \ | |
5843 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
5844 | backtrack_pos = 0; \ | |
5845 | if (result != PARSE_OPERAND_SUCCESS) \ | |
5846 | goto failure; \ | |
5847 | } \ | |
5848 | while (0) | |
4962c51a | 5849 | |
c19d1205 ZW |
5850 | skip_whitespace (str); |
5851 | ||
5852 | for (i = 0; upat[i] != OP_stop; i++) | |
5853 | { | |
5854 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
5855 | { | |
5856 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 5857 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
5858 | backtrack_pos = str; |
5859 | backtrack_error = inst.error; | |
5860 | backtrack_index = i; | |
5861 | } | |
5862 | ||
b6702015 | 5863 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
5864 | po_char_or_fail (','); |
5865 | ||
5866 | switch (upat[i]) | |
5867 | { | |
5868 | /* Registers */ | |
5869 | case OP_oRRnpc: | |
5870 | case OP_RRnpc: | |
5871 | case OP_oRR: | |
5872 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
5873 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
5874 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
5875 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
5876 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
5877 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
5287ad62 JB |
5878 | case OP_oRND: |
5879 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; | |
cd2cf30b PB |
5880 | case OP_RVC: |
5881 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
5882 | break; | |
5883 | /* Also accept generic coprocessor regs for unknown registers. */ | |
5884 | coproc_reg: | |
5885 | po_reg_or_fail (REG_TYPE_CN); | |
5886 | break; | |
c19d1205 ZW |
5887 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
5888 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
5889 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
5890 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
5891 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
5892 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
5893 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
5894 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
5895 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
5896 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
5287ad62 JB |
5897 | case OP_oRNQ: |
5898 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; | |
5899 | case OP_oRNDQ: | |
5900 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; | |
037e8744 JB |
5901 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
5902 | case OP_oRNSDQ: | |
5903 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5287ad62 JB |
5904 | |
5905 | /* Neon scalar. Using an element size of 8 means that some invalid | |
5906 | scalars are accepted here, so deal with those in later code. */ | |
5907 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
5908 | ||
5909 | /* WARNING: We can expand to two operands here. This has the potential | |
5910 | to totally confuse the backtracking mechanism! It will be OK at | |
5911 | least as long as we don't try to use optional args as well, | |
5912 | though. */ | |
5913 | case OP_NILO: | |
5914 | { | |
5915 | po_reg_or_goto (REG_TYPE_NDQ, try_imm); | |
466bbf93 | 5916 | inst.operands[i].present = 1; |
5287ad62 JB |
5917 | i++; |
5918 | skip_past_comma (&str); | |
5919 | po_reg_or_goto (REG_TYPE_NDQ, one_reg_only); | |
5920 | break; | |
5921 | one_reg_only: | |
5922 | /* Optional register operand was omitted. Unfortunately, it's in | |
5923 | operands[i-1] and we need it to be in inst.operands[i]. Fix that | |
5924 | here (this is a bit grotty). */ | |
5925 | inst.operands[i] = inst.operands[i-1]; | |
5926 | inst.operands[i-1].present = 0; | |
5927 | break; | |
5928 | try_imm: | |
036dc3f7 PB |
5929 | /* There's a possibility of getting a 64-bit immediate here, so |
5930 | we need special handling. */ | |
5931 | if (parse_big_immediate (&str, i) == FAIL) | |
5932 | { | |
5933 | inst.error = _("immediate value is out of range"); | |
5934 | goto failure; | |
5935 | } | |
5287ad62 JB |
5936 | } |
5937 | break; | |
5938 | ||
5939 | case OP_RNDQ_I0: | |
5940 | { | |
5941 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
5942 | break; | |
5943 | try_imm0: | |
5944 | po_imm_or_fail (0, 0, TRUE); | |
5945 | } | |
5946 | break; | |
5947 | ||
037e8744 JB |
5948 | case OP_RVSD_I0: |
5949 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
5950 | break; | |
5951 | ||
5287ad62 JB |
5952 | case OP_RR_RNSC: |
5953 | { | |
5954 | po_scalar_or_goto (8, try_rr); | |
5955 | break; | |
5956 | try_rr: | |
5957 | po_reg_or_fail (REG_TYPE_RN); | |
5958 | } | |
5959 | break; | |
5960 | ||
037e8744 JB |
5961 | case OP_RNSDQ_RNSC: |
5962 | { | |
5963 | po_scalar_or_goto (8, try_nsdq); | |
5964 | break; | |
5965 | try_nsdq: | |
5966 | po_reg_or_fail (REG_TYPE_NSDQ); | |
5967 | } | |
5968 | break; | |
5969 | ||
5287ad62 JB |
5970 | case OP_RNDQ_RNSC: |
5971 | { | |
5972 | po_scalar_or_goto (8, try_ndq); | |
5973 | break; | |
5974 | try_ndq: | |
5975 | po_reg_or_fail (REG_TYPE_NDQ); | |
5976 | } | |
5977 | break; | |
5978 | ||
5979 | case OP_RND_RNSC: | |
5980 | { | |
5981 | po_scalar_or_goto (8, try_vfd); | |
5982 | break; | |
5983 | try_vfd: | |
5984 | po_reg_or_fail (REG_TYPE_VFD); | |
5985 | } | |
5986 | break; | |
5987 | ||
5988 | case OP_VMOV: | |
5989 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
5990 | not careful then bad things might happen. */ | |
5991 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
5992 | break; | |
5993 | ||
5994 | case OP_RNDQ_IMVNb: | |
5995 | { | |
5996 | po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm); | |
5997 | break; | |
5998 | try_mvnimm: | |
5999 | /* There's a possibility of getting a 64-bit immediate here, so | |
6000 | we need special handling. */ | |
6001 | if (parse_big_immediate (&str, i) == FAIL) | |
6002 | { | |
6003 | inst.error = _("immediate value is out of range"); | |
6004 | goto failure; | |
6005 | } | |
6006 | } | |
6007 | break; | |
6008 | ||
6009 | case OP_RNDQ_I63b: | |
6010 | { | |
6011 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6012 | break; | |
6013 | try_shimm: | |
6014 | po_imm_or_fail (0, 63, TRUE); | |
6015 | } | |
6016 | break; | |
c19d1205 ZW |
6017 | |
6018 | case OP_RRnpcb: | |
6019 | po_char_or_fail ('['); | |
6020 | po_reg_or_fail (REG_TYPE_RN); | |
6021 | po_char_or_fail (']'); | |
6022 | break; | |
a737bd4d | 6023 | |
c19d1205 | 6024 | case OP_RRw: |
b6702015 | 6025 | case OP_oRRw: |
c19d1205 ZW |
6026 | po_reg_or_fail (REG_TYPE_RN); |
6027 | if (skip_past_char (&str, '!') == SUCCESS) | |
6028 | inst.operands[i].writeback = 1; | |
6029 | break; | |
6030 | ||
6031 | /* Immediates */ | |
6032 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6033 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6034 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
5287ad62 | 6035 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6036 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6037 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
5287ad62 | 6038 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6039 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
5287ad62 JB |
6040 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6041 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6042 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6043 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6044 | |
6045 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6046 | case OP_oI7b: | |
6047 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6048 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6049 | case OP_oI31b: | |
6050 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
5287ad62 | 6051 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
c19d1205 ZW |
6052 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6053 | ||
6054 | /* Immediate variants */ | |
6055 | case OP_oI255c: | |
6056 | po_char_or_fail ('{'); | |
6057 | po_imm_or_fail (0, 255, TRUE); | |
6058 | po_char_or_fail ('}'); | |
6059 | break; | |
6060 | ||
6061 | case OP_I31w: | |
6062 | /* The expression parser chokes on a trailing !, so we have | |
6063 | to find it first and zap it. */ | |
6064 | { | |
6065 | char *s = str; | |
6066 | while (*s && *s != ',') | |
6067 | s++; | |
6068 | if (s[-1] == '!') | |
6069 | { | |
6070 | s[-1] = '\0'; | |
6071 | inst.operands[i].writeback = 1; | |
6072 | } | |
6073 | po_imm_or_fail (0, 31, TRUE); | |
6074 | if (str == s - 1) | |
6075 | str = s; | |
6076 | } | |
6077 | break; | |
6078 | ||
6079 | /* Expressions */ | |
6080 | case OP_EXPi: EXPi: | |
6081 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6082 | GE_OPT_PREFIX)); | |
6083 | break; | |
6084 | ||
6085 | case OP_EXP: | |
6086 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6087 | GE_NO_PREFIX)); | |
6088 | break; | |
6089 | ||
6090 | case OP_EXPr: EXPr: | |
6091 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6092 | GE_NO_PREFIX)); | |
6093 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6094 | { |
c19d1205 ZW |
6095 | val = parse_reloc (&str); |
6096 | if (val == -1) | |
6097 | { | |
6098 | inst.error = _("unrecognized relocation suffix"); | |
6099 | goto failure; | |
6100 | } | |
6101 | else if (val != BFD_RELOC_UNUSED) | |
6102 | { | |
6103 | inst.operands[i].imm = val; | |
6104 | inst.operands[i].hasreloc = 1; | |
6105 | } | |
a737bd4d | 6106 | } |
c19d1205 | 6107 | break; |
a737bd4d | 6108 | |
b6895b4f PB |
6109 | /* Operand for MOVW or MOVT. */ |
6110 | case OP_HALF: | |
6111 | po_misc_or_fail (parse_half (&str)); | |
6112 | break; | |
6113 | ||
e07e6e58 | 6114 | /* Register or expression. */ |
c19d1205 ZW |
6115 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6116 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6117 | |
e07e6e58 | 6118 | /* Register or immediate. */ |
c19d1205 ZW |
6119 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6120 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6121 | |
c19d1205 ZW |
6122 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6123 | IF: | |
6124 | if (!is_immediate_prefix (*str)) | |
6125 | goto bad_args; | |
6126 | str++; | |
6127 | val = parse_fpa_immediate (&str); | |
6128 | if (val == FAIL) | |
6129 | goto failure; | |
6130 | /* FPA immediates are encoded as registers 8-15. | |
6131 | parse_fpa_immediate has already applied the offset. */ | |
6132 | inst.operands[i].reg = val; | |
6133 | inst.operands[i].isreg = 1; | |
6134 | break; | |
09d92015 | 6135 | |
2d447fca JM |
6136 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6137 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6138 | ||
e07e6e58 | 6139 | /* Two kinds of register. */ |
c19d1205 ZW |
6140 | case OP_RIWR_RIWC: |
6141 | { | |
6142 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6143 | if (!rege |
6144 | || (rege->type != REG_TYPE_MMXWR | |
6145 | && rege->type != REG_TYPE_MMXWC | |
6146 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6147 | { |
6148 | inst.error = _("iWMMXt data or control register expected"); | |
6149 | goto failure; | |
6150 | } | |
6151 | inst.operands[i].reg = rege->number; | |
6152 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6153 | } | |
6154 | break; | |
09d92015 | 6155 | |
41adaa5c JM |
6156 | case OP_RIWC_RIWG: |
6157 | { | |
6158 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6159 | if (!rege | |
6160 | || (rege->type != REG_TYPE_MMXWC | |
6161 | && rege->type != REG_TYPE_MMXWCG)) | |
6162 | { | |
6163 | inst.error = _("iWMMXt control register expected"); | |
6164 | goto failure; | |
6165 | } | |
6166 | inst.operands[i].reg = rege->number; | |
6167 | inst.operands[i].isreg = 1; | |
6168 | } | |
6169 | break; | |
6170 | ||
c19d1205 ZW |
6171 | /* Misc */ |
6172 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6173 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6174 | case OP_oROR: val = parse_ror (&str); break; | |
6175 | case OP_PSR: val = parse_psr (&str); break; | |
6176 | case OP_COND: val = parse_cond (&str); break; | |
62b3e311 | 6177 | case OP_oBARRIER:val = parse_barrier (&str); break; |
c19d1205 | 6178 | |
037e8744 JB |
6179 | case OP_RVC_PSR: |
6180 | po_reg_or_goto (REG_TYPE_VFC, try_psr); | |
6181 | inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */ | |
6182 | break; | |
6183 | try_psr: | |
6184 | val = parse_psr (&str); | |
6185 | break; | |
6186 | ||
6187 | case OP_APSR_RR: | |
6188 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
6189 | break; | |
6190 | try_apsr: | |
6191 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
6192 | instruction). */ | |
6193 | if (strncasecmp (str, "APSR_", 5) == 0) | |
6194 | { | |
6195 | unsigned found = 0; | |
6196 | str += 5; | |
6197 | while (found < 15) | |
6198 | switch (*str++) | |
6199 | { | |
6200 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
6201 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
6202 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
6203 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
6204 | default: found = 16; | |
6205 | } | |
6206 | if (found != 15) | |
6207 | goto failure; | |
6208 | inst.operands[i].isvec = 1; | |
6209 | } | |
6210 | else | |
6211 | goto failure; | |
6212 | break; | |
6213 | ||
92e90b6e PB |
6214 | case OP_TB: |
6215 | po_misc_or_fail (parse_tb (&str)); | |
6216 | break; | |
6217 | ||
e07e6e58 | 6218 | /* Register lists. */ |
c19d1205 ZW |
6219 | case OP_REGLST: |
6220 | val = parse_reg_list (&str); | |
6221 | if (*str == '^') | |
6222 | { | |
6223 | inst.operands[1].writeback = 1; | |
6224 | str++; | |
6225 | } | |
6226 | break; | |
09d92015 | 6227 | |
c19d1205 | 6228 | case OP_VRSLST: |
5287ad62 | 6229 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 6230 | break; |
09d92015 | 6231 | |
c19d1205 | 6232 | case OP_VRDLST: |
5287ad62 | 6233 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 6234 | break; |
a737bd4d | 6235 | |
037e8744 JB |
6236 | case OP_VRSDLST: |
6237 | /* Allow Q registers too. */ | |
6238 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6239 | REGLIST_NEON_D); | |
6240 | if (val == FAIL) | |
6241 | { | |
6242 | inst.error = NULL; | |
6243 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6244 | REGLIST_VFP_S); | |
6245 | inst.operands[i].issingle = 1; | |
6246 | } | |
6247 | break; | |
6248 | ||
5287ad62 JB |
6249 | case OP_NRDLST: |
6250 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
6251 | REGLIST_NEON_D); | |
6252 | break; | |
6253 | ||
6254 | case OP_NSTRLST: | |
dcbf9037 JB |
6255 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
6256 | &inst.operands[i].vectype); | |
5287ad62 JB |
6257 | break; |
6258 | ||
c19d1205 ZW |
6259 | /* Addressing modes */ |
6260 | case OP_ADDR: | |
6261 | po_misc_or_fail (parse_address (&str, i)); | |
6262 | break; | |
09d92015 | 6263 | |
4962c51a MS |
6264 | case OP_ADDRGLDR: |
6265 | po_misc_or_fail_no_backtrack ( | |
6266 | parse_address_group_reloc (&str, i, GROUP_LDR)); | |
6267 | break; | |
6268 | ||
6269 | case OP_ADDRGLDRS: | |
6270 | po_misc_or_fail_no_backtrack ( | |
6271 | parse_address_group_reloc (&str, i, GROUP_LDRS)); | |
6272 | break; | |
6273 | ||
6274 | case OP_ADDRGLDC: | |
6275 | po_misc_or_fail_no_backtrack ( | |
6276 | parse_address_group_reloc (&str, i, GROUP_LDC)); | |
6277 | break; | |
6278 | ||
c19d1205 ZW |
6279 | case OP_SH: |
6280 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
6281 | break; | |
09d92015 | 6282 | |
4962c51a MS |
6283 | case OP_SHG: |
6284 | po_misc_or_fail_no_backtrack ( | |
6285 | parse_shifter_operand_group_reloc (&str, i)); | |
6286 | break; | |
6287 | ||
c19d1205 ZW |
6288 | case OP_oSHll: |
6289 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
6290 | break; | |
09d92015 | 6291 | |
c19d1205 ZW |
6292 | case OP_oSHar: |
6293 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
6294 | break; | |
09d92015 | 6295 | |
c19d1205 ZW |
6296 | case OP_oSHllar: |
6297 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
6298 | break; | |
09d92015 | 6299 | |
c19d1205 | 6300 | default: |
bd3ba5d1 | 6301 | as_fatal (_("unhandled operand code %d"), upat[i]); |
c19d1205 | 6302 | } |
09d92015 | 6303 | |
c19d1205 ZW |
6304 | /* Various value-based sanity checks and shared operations. We |
6305 | do not signal immediate failures for the register constraints; | |
6306 | this allows a syntax error to take precedence. */ | |
6307 | switch (upat[i]) | |
6308 | { | |
6309 | case OP_oRRnpc: | |
6310 | case OP_RRnpc: | |
6311 | case OP_RRnpcb: | |
6312 | case OP_RRw: | |
b6702015 | 6313 | case OP_oRRw: |
c19d1205 ZW |
6314 | case OP_RRnpc_I0: |
6315 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
6316 | inst.error = BAD_PC; | |
6317 | break; | |
09d92015 | 6318 | |
c19d1205 ZW |
6319 | case OP_CPSF: |
6320 | case OP_ENDI: | |
6321 | case OP_oROR: | |
6322 | case OP_PSR: | |
037e8744 | 6323 | case OP_RVC_PSR: |
c19d1205 | 6324 | case OP_COND: |
62b3e311 | 6325 | case OP_oBARRIER: |
c19d1205 ZW |
6326 | case OP_REGLST: |
6327 | case OP_VRSLST: | |
6328 | case OP_VRDLST: | |
037e8744 | 6329 | case OP_VRSDLST: |
5287ad62 JB |
6330 | case OP_NRDLST: |
6331 | case OP_NSTRLST: | |
c19d1205 ZW |
6332 | if (val == FAIL) |
6333 | goto failure; | |
6334 | inst.operands[i].imm = val; | |
6335 | break; | |
a737bd4d | 6336 | |
c19d1205 ZW |
6337 | default: |
6338 | break; | |
6339 | } | |
09d92015 | 6340 | |
c19d1205 ZW |
6341 | /* If we get here, this operand was successfully parsed. */ |
6342 | inst.operands[i].present = 1; | |
6343 | continue; | |
09d92015 | 6344 | |
c19d1205 | 6345 | bad_args: |
09d92015 | 6346 | inst.error = BAD_ARGS; |
c19d1205 ZW |
6347 | |
6348 | failure: | |
6349 | if (!backtrack_pos) | |
d252fdde PB |
6350 | { |
6351 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 6352 | default here just in case. */ |
d252fdde PB |
6353 | if (!inst.error) |
6354 | inst.error = _("syntax error"); | |
6355 | return FAIL; | |
6356 | } | |
c19d1205 ZW |
6357 | |
6358 | /* Do not backtrack over a trailing optional argument that | |
6359 | absorbed some text. We will only fail again, with the | |
6360 | 'garbage following instruction' error message, which is | |
6361 | probably less helpful than the current one. */ | |
6362 | if (backtrack_index == i && backtrack_pos != str | |
6363 | && upat[i+1] == OP_stop) | |
d252fdde PB |
6364 | { |
6365 | if (!inst.error) | |
6366 | inst.error = _("syntax error"); | |
6367 | return FAIL; | |
6368 | } | |
c19d1205 ZW |
6369 | |
6370 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
6371 | str = backtrack_pos; | |
6372 | inst.error = backtrack_error; | |
6373 | inst.operands[backtrack_index].present = 0; | |
6374 | i = backtrack_index; | |
6375 | backtrack_pos = 0; | |
09d92015 | 6376 | } |
09d92015 | 6377 | |
c19d1205 ZW |
6378 | /* Check that we have parsed all the arguments. */ |
6379 | if (*str != '\0' && !inst.error) | |
6380 | inst.error = _("garbage following instruction"); | |
09d92015 | 6381 | |
c19d1205 | 6382 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
6383 | } |
6384 | ||
c19d1205 ZW |
6385 | #undef po_char_or_fail |
6386 | #undef po_reg_or_fail | |
6387 | #undef po_reg_or_goto | |
6388 | #undef po_imm_or_fail | |
5287ad62 | 6389 | #undef po_scalar_or_fail |
e07e6e58 | 6390 | |
c19d1205 | 6391 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
6392 | #define constraint(expr, err) \ |
6393 | do \ | |
c19d1205 | 6394 | { \ |
e07e6e58 NC |
6395 | if (expr) \ |
6396 | { \ | |
6397 | inst.error = err; \ | |
6398 | return; \ | |
6399 | } \ | |
c19d1205 | 6400 | } \ |
e07e6e58 | 6401 | while (0) |
c19d1205 | 6402 | |
fdfde340 JM |
6403 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
6404 | instructions are unpredictable if these registers are used. This | |
6405 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
6406 | #define reject_bad_reg(reg) \ | |
6407 | do \ | |
6408 | if (reg == REG_SP || reg == REG_PC) \ | |
6409 | { \ | |
6410 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
6411 | return; \ | |
6412 | } \ | |
6413 | while (0) | |
6414 | ||
94206790 MM |
6415 | /* If REG is R13 (the stack pointer), warn that its use is |
6416 | deprecated. */ | |
6417 | #define warn_deprecated_sp(reg) \ | |
6418 | do \ | |
6419 | if (warn_on_deprecated && reg == REG_SP) \ | |
6420 | as_warn (_("use of r13 is deprecated")); \ | |
6421 | while (0) | |
6422 | ||
c19d1205 ZW |
6423 | /* Functions for operand encoding. ARM, then Thumb. */ |
6424 | ||
6425 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
6426 | ||
6427 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
6428 | return the encoded form. Otherwise, return FAIL. */ | |
6429 | ||
6430 | static unsigned int | |
6431 | encode_arm_immediate (unsigned int val) | |
09d92015 | 6432 | { |
c19d1205 ZW |
6433 | unsigned int a, i; |
6434 | ||
6435 | for (i = 0; i < 32; i += 2) | |
6436 | if ((a = rotate_left (val, i)) <= 0xff) | |
6437 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
6438 | ||
6439 | return FAIL; | |
09d92015 MM |
6440 | } |
6441 | ||
c19d1205 ZW |
6442 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
6443 | return the encoded form. Otherwise, return FAIL. */ | |
6444 | static unsigned int | |
6445 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 6446 | { |
c19d1205 | 6447 | unsigned int a, i; |
09d92015 | 6448 | |
9c3c69f2 | 6449 | if (val <= 0xff) |
c19d1205 | 6450 | return val; |
a737bd4d | 6451 | |
9c3c69f2 | 6452 | for (i = 1; i <= 24; i++) |
09d92015 | 6453 | { |
9c3c69f2 PB |
6454 | a = val >> i; |
6455 | if ((val & ~(0xff << i)) == 0) | |
6456 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 6457 | } |
a737bd4d | 6458 | |
c19d1205 ZW |
6459 | a = val & 0xff; |
6460 | if (val == ((a << 16) | a)) | |
6461 | return 0x100 | a; | |
6462 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
6463 | return 0x300 | a; | |
09d92015 | 6464 | |
c19d1205 ZW |
6465 | a = val & 0xff00; |
6466 | if (val == ((a << 16) | a)) | |
6467 | return 0x200 | (a >> 8); | |
a737bd4d | 6468 | |
c19d1205 | 6469 | return FAIL; |
09d92015 | 6470 | } |
5287ad62 | 6471 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
6472 | |
6473 | static void | |
5287ad62 JB |
6474 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
6475 | { | |
6476 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
6477 | && reg > 15) | |
6478 | { | |
b1cc4aeb | 6479 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
5287ad62 JB |
6480 | { |
6481 | if (thumb_mode) | |
6482 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
b1cc4aeb | 6483 | fpu_vfp_ext_d32); |
5287ad62 JB |
6484 | else |
6485 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
b1cc4aeb | 6486 | fpu_vfp_ext_d32); |
5287ad62 JB |
6487 | } |
6488 | else | |
6489 | { | |
dcbf9037 | 6490 | first_error (_("D register out of range for selected VFP version")); |
5287ad62 JB |
6491 | return; |
6492 | } | |
6493 | } | |
6494 | ||
c19d1205 | 6495 | switch (pos) |
09d92015 | 6496 | { |
c19d1205 ZW |
6497 | case VFP_REG_Sd: |
6498 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
6499 | break; | |
6500 | ||
6501 | case VFP_REG_Sn: | |
6502 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
6503 | break; | |
6504 | ||
6505 | case VFP_REG_Sm: | |
6506 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
6507 | break; | |
6508 | ||
5287ad62 JB |
6509 | case VFP_REG_Dd: |
6510 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
6511 | break; | |
5f4273c7 | 6512 | |
5287ad62 JB |
6513 | case VFP_REG_Dn: |
6514 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
6515 | break; | |
5f4273c7 | 6516 | |
5287ad62 JB |
6517 | case VFP_REG_Dm: |
6518 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
6519 | break; | |
6520 | ||
c19d1205 ZW |
6521 | default: |
6522 | abort (); | |
09d92015 | 6523 | } |
09d92015 MM |
6524 | } |
6525 | ||
c19d1205 | 6526 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 6527 | if any, is handled by md_apply_fix. */ |
09d92015 | 6528 | static void |
c19d1205 | 6529 | encode_arm_shift (int i) |
09d92015 | 6530 | { |
c19d1205 ZW |
6531 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
6532 | inst.instruction |= SHIFT_ROR << 5; | |
6533 | else | |
09d92015 | 6534 | { |
c19d1205 ZW |
6535 | inst.instruction |= inst.operands[i].shift_kind << 5; |
6536 | if (inst.operands[i].immisreg) | |
6537 | { | |
6538 | inst.instruction |= SHIFT_BY_REG; | |
6539 | inst.instruction |= inst.operands[i].imm << 8; | |
6540 | } | |
6541 | else | |
6542 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 6543 | } |
c19d1205 | 6544 | } |
09d92015 | 6545 | |
c19d1205 ZW |
6546 | static void |
6547 | encode_arm_shifter_operand (int i) | |
6548 | { | |
6549 | if (inst.operands[i].isreg) | |
09d92015 | 6550 | { |
c19d1205 ZW |
6551 | inst.instruction |= inst.operands[i].reg; |
6552 | encode_arm_shift (i); | |
09d92015 | 6553 | } |
c19d1205 ZW |
6554 | else |
6555 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
6556 | } |
6557 | ||
c19d1205 | 6558 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 6559 | static void |
c19d1205 | 6560 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 6561 | { |
9c2799c2 | 6562 | gas_assert (inst.operands[i].isreg); |
c19d1205 | 6563 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6564 | |
c19d1205 | 6565 | if (inst.operands[i].preind) |
09d92015 | 6566 | { |
c19d1205 ZW |
6567 | if (is_t) |
6568 | { | |
6569 | inst.error = _("instruction does not accept preindexed addressing"); | |
6570 | return; | |
6571 | } | |
6572 | inst.instruction |= PRE_INDEX; | |
6573 | if (inst.operands[i].writeback) | |
6574 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6575 | |
c19d1205 ZW |
6576 | } |
6577 | else if (inst.operands[i].postind) | |
6578 | { | |
9c2799c2 | 6579 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
6580 | if (is_t) |
6581 | inst.instruction |= WRITE_BACK; | |
6582 | } | |
6583 | else /* unindexed - only for coprocessor */ | |
09d92015 | 6584 | { |
c19d1205 | 6585 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
6586 | return; |
6587 | } | |
6588 | ||
c19d1205 ZW |
6589 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
6590 | && (((inst.instruction & 0x000f0000) >> 16) | |
6591 | == ((inst.instruction & 0x0000f000) >> 12))) | |
6592 | as_warn ((inst.instruction & LOAD_BIT) | |
6593 | ? _("destination register same as write-back base") | |
6594 | : _("source register same as write-back base")); | |
09d92015 MM |
6595 | } |
6596 | ||
c19d1205 ZW |
6597 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6598 | ARM-format mode 2 load or store instruction. If is_t is true, | |
6599 | reject forms that cannot be used with a T instruction (i.e. not | |
6600 | post-indexed). */ | |
a737bd4d | 6601 | static void |
c19d1205 | 6602 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 6603 | { |
c19d1205 | 6604 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6605 | |
c19d1205 | 6606 | if (inst.operands[i].immisreg) |
09d92015 | 6607 | { |
c19d1205 ZW |
6608 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
6609 | inst.instruction |= inst.operands[i].imm; | |
6610 | if (!inst.operands[i].negative) | |
6611 | inst.instruction |= INDEX_UP; | |
6612 | if (inst.operands[i].shifted) | |
6613 | { | |
6614 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
6615 | inst.instruction |= SHIFT_ROR << 5; | |
6616 | else | |
6617 | { | |
6618 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
6619 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
6620 | } | |
6621 | } | |
09d92015 | 6622 | } |
c19d1205 | 6623 | else /* immediate offset in inst.reloc */ |
09d92015 | 6624 | { |
c19d1205 ZW |
6625 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6626 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 6627 | } |
09d92015 MM |
6628 | } |
6629 | ||
c19d1205 ZW |
6630 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6631 | ARM-format mode 3 load or store instruction. Reject forms that | |
6632 | cannot be used with such instructions. If is_t is true, reject | |
6633 | forms that cannot be used with a T instruction (i.e. not | |
6634 | post-indexed). */ | |
6635 | static void | |
6636 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 6637 | { |
c19d1205 | 6638 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 6639 | { |
c19d1205 ZW |
6640 | inst.error = _("instruction does not accept scaled register index"); |
6641 | return; | |
09d92015 | 6642 | } |
a737bd4d | 6643 | |
c19d1205 | 6644 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 6645 | |
c19d1205 ZW |
6646 | if (inst.operands[i].immisreg) |
6647 | { | |
6648 | inst.instruction |= inst.operands[i].imm; | |
6649 | if (!inst.operands[i].negative) | |
6650 | inst.instruction |= INDEX_UP; | |
6651 | } | |
6652 | else /* immediate offset in inst.reloc */ | |
6653 | { | |
6654 | inst.instruction |= HWOFFSET_IMM; | |
6655 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6656 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 6657 | } |
a737bd4d NC |
6658 | } |
6659 | ||
c19d1205 ZW |
6660 | /* inst.operands[i] was set up by parse_address. Encode it into an |
6661 | ARM-format instruction. Reject all forms which cannot be encoded | |
6662 | into a coprocessor load/store instruction. If wb_ok is false, | |
6663 | reject use of writeback; if unind_ok is false, reject use of | |
6664 | unindexed addressing. If reloc_override is not 0, use it instead | |
4962c51a MS |
6665 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one |
6666 | (in which case it is preserved). */ | |
09d92015 | 6667 | |
c19d1205 ZW |
6668 | static int |
6669 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 6670 | { |
c19d1205 | 6671 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 6672 | |
9c2799c2 | 6673 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 6674 | |
c19d1205 | 6675 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 6676 | { |
9c2799c2 | 6677 | gas_assert (!inst.operands[i].writeback); |
c19d1205 ZW |
6678 | if (!unind_ok) |
6679 | { | |
6680 | inst.error = _("instruction does not support unindexed addressing"); | |
6681 | return FAIL; | |
6682 | } | |
6683 | inst.instruction |= inst.operands[i].imm; | |
6684 | inst.instruction |= INDEX_UP; | |
6685 | return SUCCESS; | |
09d92015 | 6686 | } |
a737bd4d | 6687 | |
c19d1205 ZW |
6688 | if (inst.operands[i].preind) |
6689 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 6690 | |
c19d1205 | 6691 | if (inst.operands[i].writeback) |
09d92015 | 6692 | { |
c19d1205 ZW |
6693 | if (inst.operands[i].reg == REG_PC) |
6694 | { | |
6695 | inst.error = _("pc may not be used with write-back"); | |
6696 | return FAIL; | |
6697 | } | |
6698 | if (!wb_ok) | |
6699 | { | |
6700 | inst.error = _("instruction does not support writeback"); | |
6701 | return FAIL; | |
6702 | } | |
6703 | inst.instruction |= WRITE_BACK; | |
09d92015 | 6704 | } |
a737bd4d | 6705 | |
c19d1205 ZW |
6706 | if (reloc_override) |
6707 | inst.reloc.type = reloc_override; | |
4962c51a MS |
6708 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC |
6709 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
6710 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
6711 | { | |
6712 | if (thumb_mode) | |
6713 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
6714 | else | |
6715 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
6716 | } | |
6717 | ||
c19d1205 ZW |
6718 | return SUCCESS; |
6719 | } | |
a737bd4d | 6720 | |
c19d1205 ZW |
6721 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
6722 | Determine whether it can be performed with a move instruction; if | |
6723 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
6724 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
6725 | load and return FALSE. If this is not a valid thing to do in the | |
6726 | current context, set inst.error and return TRUE. | |
a737bd4d | 6727 | |
c19d1205 ZW |
6728 | inst.operands[i] describes the destination register. */ |
6729 | ||
c921be7d | 6730 | static bfd_boolean |
c19d1205 ZW |
6731 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) |
6732 | { | |
53365c0d PB |
6733 | unsigned long tbit; |
6734 | ||
6735 | if (thumb_p) | |
6736 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
6737 | else | |
6738 | tbit = LOAD_BIT; | |
6739 | ||
6740 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 6741 | { |
c19d1205 | 6742 | inst.error = _("invalid pseudo operation"); |
c921be7d | 6743 | return TRUE; |
09d92015 | 6744 | } |
c19d1205 | 6745 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
6746 | { |
6747 | inst.error = _("constant expression expected"); | |
c921be7d | 6748 | return TRUE; |
09d92015 | 6749 | } |
c19d1205 | 6750 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 6751 | { |
c19d1205 ZW |
6752 | if (thumb_p) |
6753 | { | |
53365c0d | 6754 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
6755 | { |
6756 | /* This can be done with a mov(1) instruction. */ | |
6757 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
6758 | inst.instruction |= inst.reloc.exp.X_add_number; | |
c921be7d | 6759 | return TRUE; |
c19d1205 ZW |
6760 | } |
6761 | } | |
6762 | else | |
6763 | { | |
6764 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
6765 | if (value != FAIL) | |
6766 | { | |
6767 | /* This can be done with a mov instruction. */ | |
6768 | inst.instruction &= LITERAL_MASK; | |
6769 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
6770 | inst.instruction |= value & 0xfff; | |
c921be7d | 6771 | return TRUE; |
c19d1205 | 6772 | } |
09d92015 | 6773 | |
c19d1205 ZW |
6774 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
6775 | if (value != FAIL) | |
6776 | { | |
6777 | /* This can be done with a mvn instruction. */ | |
6778 | inst.instruction &= LITERAL_MASK; | |
6779 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
6780 | inst.instruction |= value & 0xfff; | |
c921be7d | 6781 | return TRUE; |
c19d1205 ZW |
6782 | } |
6783 | } | |
09d92015 MM |
6784 | } |
6785 | ||
c19d1205 ZW |
6786 | if (add_to_lit_pool () == FAIL) |
6787 | { | |
6788 | inst.error = _("literal pool insertion failed"); | |
c921be7d | 6789 | return TRUE; |
c19d1205 ZW |
6790 | } |
6791 | inst.operands[1].reg = REG_PC; | |
6792 | inst.operands[1].isreg = 1; | |
6793 | inst.operands[1].preind = 1; | |
6794 | inst.reloc.pc_rel = 1; | |
6795 | inst.reloc.type = (thumb_p | |
6796 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
6797 | : (mode_3 | |
6798 | ? BFD_RELOC_ARM_HWLITERAL | |
6799 | : BFD_RELOC_ARM_LITERAL)); | |
c921be7d | 6800 | return FALSE; |
09d92015 MM |
6801 | } |
6802 | ||
5f4273c7 | 6803 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
6804 | First some generics; their names are taken from the conventional |
6805 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 6806 | |
a737bd4d | 6807 | static void |
c19d1205 | 6808 | do_noargs (void) |
09d92015 | 6809 | { |
c19d1205 | 6810 | } |
a737bd4d | 6811 | |
c19d1205 ZW |
6812 | static void |
6813 | do_rd (void) | |
6814 | { | |
6815 | inst.instruction |= inst.operands[0].reg << 12; | |
6816 | } | |
a737bd4d | 6817 | |
c19d1205 ZW |
6818 | static void |
6819 | do_rd_rm (void) | |
6820 | { | |
6821 | inst.instruction |= inst.operands[0].reg << 12; | |
6822 | inst.instruction |= inst.operands[1].reg; | |
6823 | } | |
09d92015 | 6824 | |
c19d1205 ZW |
6825 | static void |
6826 | do_rd_rn (void) | |
6827 | { | |
6828 | inst.instruction |= inst.operands[0].reg << 12; | |
6829 | inst.instruction |= inst.operands[1].reg << 16; | |
6830 | } | |
a737bd4d | 6831 | |
c19d1205 ZW |
6832 | static void |
6833 | do_rn_rd (void) | |
6834 | { | |
6835 | inst.instruction |= inst.operands[0].reg << 16; | |
6836 | inst.instruction |= inst.operands[1].reg << 12; | |
6837 | } | |
09d92015 | 6838 | |
c19d1205 ZW |
6839 | static void |
6840 | do_rd_rm_rn (void) | |
6841 | { | |
9a64e435 | 6842 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 6843 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 PB |
6844 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
6845 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
6846 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
6847 | inst.instruction |= inst.operands[0].reg << 12; |
6848 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 6849 | inst.instruction |= Rn << 16; |
c19d1205 | 6850 | } |
09d92015 | 6851 | |
c19d1205 ZW |
6852 | static void |
6853 | do_rd_rn_rm (void) | |
6854 | { | |
6855 | inst.instruction |= inst.operands[0].reg << 12; | |
6856 | inst.instruction |= inst.operands[1].reg << 16; | |
6857 | inst.instruction |= inst.operands[2].reg; | |
6858 | } | |
a737bd4d | 6859 | |
c19d1205 ZW |
6860 | static void |
6861 | do_rm_rd_rn (void) | |
6862 | { | |
6863 | inst.instruction |= inst.operands[0].reg; | |
6864 | inst.instruction |= inst.operands[1].reg << 12; | |
6865 | inst.instruction |= inst.operands[2].reg << 16; | |
6866 | } | |
09d92015 | 6867 | |
c19d1205 ZW |
6868 | static void |
6869 | do_imm0 (void) | |
6870 | { | |
6871 | inst.instruction |= inst.operands[0].imm; | |
6872 | } | |
09d92015 | 6873 | |
c19d1205 ZW |
6874 | static void |
6875 | do_rd_cpaddr (void) | |
6876 | { | |
6877 | inst.instruction |= inst.operands[0].reg << 12; | |
6878 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 6879 | } |
a737bd4d | 6880 | |
c19d1205 ZW |
6881 | /* ARM instructions, in alphabetical order by function name (except |
6882 | that wrapper functions appear immediately after the function they | |
6883 | wrap). */ | |
09d92015 | 6884 | |
c19d1205 ZW |
6885 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
6886 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
6887 | |
6888 | static void | |
c19d1205 | 6889 | do_adr (void) |
09d92015 | 6890 | { |
c19d1205 | 6891 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 6892 | |
c19d1205 ZW |
6893 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6894 | out to be negative. */ | |
6895 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 6896 | inst.reloc.pc_rel = 1; |
2fc8bdac | 6897 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 6898 | } |
b99bd4ef | 6899 | |
c19d1205 ZW |
6900 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
6901 | into a relative address of the form: | |
6902 | add rd, pc, #low(label-.-8)" | |
6903 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 6904 | |
c19d1205 ZW |
6905 | static void |
6906 | do_adrl (void) | |
6907 | { | |
6908 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 6909 | |
c19d1205 ZW |
6910 | /* Frag hacking will turn this into a sub instruction if the offset turns |
6911 | out to be negative. */ | |
6912 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
6913 | inst.reloc.pc_rel = 1; |
6914 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 6915 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
6916 | } |
6917 | ||
b99bd4ef | 6918 | static void |
c19d1205 | 6919 | do_arit (void) |
b99bd4ef | 6920 | { |
c19d1205 ZW |
6921 | if (!inst.operands[1].present) |
6922 | inst.operands[1].reg = inst.operands[0].reg; | |
6923 | inst.instruction |= inst.operands[0].reg << 12; | |
6924 | inst.instruction |= inst.operands[1].reg << 16; | |
6925 | encode_arm_shifter_operand (2); | |
6926 | } | |
b99bd4ef | 6927 | |
62b3e311 PB |
6928 | static void |
6929 | do_barrier (void) | |
6930 | { | |
6931 | if (inst.operands[0].present) | |
6932 | { | |
6933 | constraint ((inst.instruction & 0xf0) != 0x40 | |
6934 | && inst.operands[0].imm != 0xf, | |
bd3ba5d1 | 6935 | _("bad barrier type")); |
62b3e311 PB |
6936 | inst.instruction |= inst.operands[0].imm; |
6937 | } | |
6938 | else | |
6939 | inst.instruction |= 0xf; | |
6940 | } | |
6941 | ||
c19d1205 ZW |
6942 | static void |
6943 | do_bfc (void) | |
6944 | { | |
6945 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
6946 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6947 | /* The instruction encoding stores the LSB and MSB, | |
6948 | not the LSB and width. */ | |
6949 | inst.instruction |= inst.operands[0].reg << 12; | |
6950 | inst.instruction |= inst.operands[1].imm << 7; | |
6951 | inst.instruction |= (msb - 1) << 16; | |
6952 | } | |
b99bd4ef | 6953 | |
c19d1205 ZW |
6954 | static void |
6955 | do_bfi (void) | |
6956 | { | |
6957 | unsigned int msb; | |
b99bd4ef | 6958 | |
c19d1205 ZW |
6959 | /* #0 in second position is alternative syntax for bfc, which is |
6960 | the same instruction but with REG_PC in the Rm field. */ | |
6961 | if (!inst.operands[1].isreg) | |
6962 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 6963 | |
c19d1205 ZW |
6964 | msb = inst.operands[2].imm + inst.operands[3].imm; |
6965 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6966 | /* The instruction encoding stores the LSB and MSB, | |
6967 | not the LSB and width. */ | |
6968 | inst.instruction |= inst.operands[0].reg << 12; | |
6969 | inst.instruction |= inst.operands[1].reg; | |
6970 | inst.instruction |= inst.operands[2].imm << 7; | |
6971 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
6972 | } |
6973 | ||
b99bd4ef | 6974 | static void |
c19d1205 | 6975 | do_bfx (void) |
b99bd4ef | 6976 | { |
c19d1205 ZW |
6977 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
6978 | _("bit-field extends past end of register")); | |
6979 | inst.instruction |= inst.operands[0].reg << 12; | |
6980 | inst.instruction |= inst.operands[1].reg; | |
6981 | inst.instruction |= inst.operands[2].imm << 7; | |
6982 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
6983 | } | |
09d92015 | 6984 | |
c19d1205 ZW |
6985 | /* ARM V5 breakpoint instruction (argument parse) |
6986 | BKPT <16 bit unsigned immediate> | |
6987 | Instruction is not conditional. | |
6988 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
6989 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 6990 | |
c19d1205 ZW |
6991 | static void |
6992 | do_bkpt (void) | |
6993 | { | |
6994 | /* Top 12 of 16 bits to bits 19:8. */ | |
6995 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 6996 | |
c19d1205 ZW |
6997 | /* Bottom 4 of 16 bits to bits 3:0. */ |
6998 | inst.instruction |= inst.operands[0].imm & 0xf; | |
6999 | } | |
09d92015 | 7000 | |
c19d1205 ZW |
7001 | static void |
7002 | encode_branch (int default_reloc) | |
7003 | { | |
7004 | if (inst.operands[0].hasreloc) | |
7005 | { | |
7006 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
7007 | _("the only suffix valid here is '(plt)'")); | |
267bf995 | 7008 | inst.reloc.type = BFD_RELOC_ARM_PLT32; |
c19d1205 | 7009 | } |
b99bd4ef | 7010 | else |
c19d1205 ZW |
7011 | { |
7012 | inst.reloc.type = default_reloc; | |
c19d1205 | 7013 | } |
2fc8bdac | 7014 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
7015 | } |
7016 | ||
b99bd4ef | 7017 | static void |
c19d1205 | 7018 | do_branch (void) |
b99bd4ef | 7019 | { |
39b41c9c PB |
7020 | #ifdef OBJ_ELF |
7021 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7022 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7023 | else | |
7024 | #endif | |
7025 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
7026 | } | |
7027 | ||
7028 | static void | |
7029 | do_bl (void) | |
7030 | { | |
7031 | #ifdef OBJ_ELF | |
7032 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
7033 | { | |
7034 | if (inst.cond == COND_ALWAYS) | |
7035 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
7036 | else | |
7037 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
7038 | } | |
7039 | else | |
7040 | #endif | |
7041 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 7042 | } |
b99bd4ef | 7043 | |
c19d1205 ZW |
7044 | /* ARM V5 branch-link-exchange instruction (argument parse) |
7045 | BLX <target_addr> ie BLX(1) | |
7046 | BLX{<condition>} <Rm> ie BLX(2) | |
7047 | Unfortunately, there are two different opcodes for this mnemonic. | |
7048 | So, the insns[].value is not used, and the code here zaps values | |
7049 | into inst.instruction. | |
7050 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 7051 | |
c19d1205 ZW |
7052 | static void |
7053 | do_blx (void) | |
7054 | { | |
7055 | if (inst.operands[0].isreg) | |
b99bd4ef | 7056 | { |
c19d1205 ZW |
7057 | /* Arg is a register; the opcode provided by insns[] is correct. |
7058 | It is not illegal to do "blx pc", just useless. */ | |
7059 | if (inst.operands[0].reg == REG_PC) | |
7060 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 7061 | |
c19d1205 ZW |
7062 | inst.instruction |= inst.operands[0].reg; |
7063 | } | |
7064 | else | |
b99bd4ef | 7065 | { |
c19d1205 | 7066 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
7067 | conditionally, and the opcode must be adjusted. |
7068 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
7069 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 7070 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 7071 | inst.instruction = 0xfa000000; |
267bf995 | 7072 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 7073 | } |
c19d1205 ZW |
7074 | } |
7075 | ||
7076 | static void | |
7077 | do_bx (void) | |
7078 | { | |
845b51d6 PB |
7079 | bfd_boolean want_reloc; |
7080 | ||
c19d1205 ZW |
7081 | if (inst.operands[0].reg == REG_PC) |
7082 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 7083 | |
c19d1205 | 7084 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
7085 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
7086 | it is for ARMv4t or earlier. */ | |
7087 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
7088 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
7089 | want_reloc = TRUE; | |
7090 | ||
5ad34203 | 7091 | #ifdef OBJ_ELF |
845b51d6 | 7092 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 7093 | #endif |
584206db | 7094 | want_reloc = FALSE; |
845b51d6 PB |
7095 | |
7096 | if (want_reloc) | |
7097 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
7098 | } |
7099 | ||
c19d1205 ZW |
7100 | |
7101 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
7102 | |
7103 | static void | |
c19d1205 | 7104 | do_bxj (void) |
a737bd4d | 7105 | { |
c19d1205 ZW |
7106 | if (inst.operands[0].reg == REG_PC) |
7107 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
7108 | ||
7109 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
7110 | } |
7111 | ||
c19d1205 ZW |
7112 | /* Co-processor data operation: |
7113 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
7114 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
7115 | static void | |
7116 | do_cdp (void) | |
7117 | { | |
7118 | inst.instruction |= inst.operands[0].reg << 8; | |
7119 | inst.instruction |= inst.operands[1].imm << 20; | |
7120 | inst.instruction |= inst.operands[2].reg << 12; | |
7121 | inst.instruction |= inst.operands[3].reg << 16; | |
7122 | inst.instruction |= inst.operands[4].reg; | |
7123 | inst.instruction |= inst.operands[5].imm << 5; | |
7124 | } | |
a737bd4d NC |
7125 | |
7126 | static void | |
c19d1205 | 7127 | do_cmp (void) |
a737bd4d | 7128 | { |
c19d1205 ZW |
7129 | inst.instruction |= inst.operands[0].reg << 16; |
7130 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
7131 | } |
7132 | ||
c19d1205 ZW |
7133 | /* Transfer between coprocessor and ARM registers. |
7134 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
7135 | MRC2 | |
7136 | MCR{cond} | |
7137 | MCR2 | |
7138 | ||
7139 | No special properties. */ | |
09d92015 MM |
7140 | |
7141 | static void | |
c19d1205 | 7142 | do_co_reg (void) |
09d92015 | 7143 | { |
fdfde340 JM |
7144 | unsigned Rd; |
7145 | ||
7146 | Rd = inst.operands[2].reg; | |
7147 | if (thumb_mode) | |
7148 | { | |
7149 | if (inst.instruction == 0xee000010 | |
7150 | || inst.instruction == 0xfe000010) | |
7151 | /* MCR, MCR2 */ | |
7152 | reject_bad_reg (Rd); | |
7153 | else | |
7154 | /* MRC, MRC2 */ | |
7155 | constraint (Rd == REG_SP, BAD_SP); | |
7156 | } | |
7157 | else | |
7158 | { | |
7159 | /* MCR */ | |
7160 | if (inst.instruction == 0xe000010) | |
7161 | constraint (Rd == REG_PC, BAD_PC); | |
7162 | } | |
7163 | ||
7164 | ||
c19d1205 ZW |
7165 | inst.instruction |= inst.operands[0].reg << 8; |
7166 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 7167 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
7168 | inst.instruction |= inst.operands[3].reg << 16; |
7169 | inst.instruction |= inst.operands[4].reg; | |
7170 | inst.instruction |= inst.operands[5].imm << 5; | |
7171 | } | |
09d92015 | 7172 | |
c19d1205 ZW |
7173 | /* Transfer between coprocessor register and pair of ARM registers. |
7174 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
7175 | MCRR2 | |
7176 | MRRC{cond} | |
7177 | MRRC2 | |
b99bd4ef | 7178 | |
c19d1205 | 7179 | Two XScale instructions are special cases of these: |
09d92015 | 7180 | |
c19d1205 ZW |
7181 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
7182 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 7183 | |
5f4273c7 | 7184 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 7185 | |
c19d1205 ZW |
7186 | static void |
7187 | do_co_reg2c (void) | |
7188 | { | |
fdfde340 JM |
7189 | unsigned Rd, Rn; |
7190 | ||
7191 | Rd = inst.operands[2].reg; | |
7192 | Rn = inst.operands[3].reg; | |
7193 | ||
7194 | if (thumb_mode) | |
7195 | { | |
7196 | reject_bad_reg (Rd); | |
7197 | reject_bad_reg (Rn); | |
7198 | } | |
7199 | else | |
7200 | { | |
7201 | constraint (Rd == REG_PC, BAD_PC); | |
7202 | constraint (Rn == REG_PC, BAD_PC); | |
7203 | } | |
7204 | ||
c19d1205 ZW |
7205 | inst.instruction |= inst.operands[0].reg << 8; |
7206 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
7207 | inst.instruction |= Rd << 12; |
7208 | inst.instruction |= Rn << 16; | |
c19d1205 | 7209 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
7210 | } |
7211 | ||
c19d1205 ZW |
7212 | static void |
7213 | do_cpsi (void) | |
7214 | { | |
7215 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
7216 | if (inst.operands[1].present) |
7217 | { | |
7218 | inst.instruction |= CPSI_MMOD; | |
7219 | inst.instruction |= inst.operands[1].imm; | |
7220 | } | |
c19d1205 | 7221 | } |
b99bd4ef | 7222 | |
62b3e311 PB |
7223 | static void |
7224 | do_dbg (void) | |
7225 | { | |
7226 | inst.instruction |= inst.operands[0].imm; | |
7227 | } | |
7228 | ||
b99bd4ef | 7229 | static void |
c19d1205 | 7230 | do_it (void) |
b99bd4ef | 7231 | { |
c19d1205 | 7232 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
7233 | process it to do the validation as if in |
7234 | thumb mode, just in case the code gets | |
7235 | assembled for thumb using the unified syntax. */ | |
7236 | ||
c19d1205 | 7237 | inst.size = 0; |
e07e6e58 NC |
7238 | if (unified_syntax) |
7239 | { | |
7240 | set_it_insn_type (IT_INSN); | |
7241 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
7242 | now_it.cc = inst.operands[0].imm; | |
7243 | } | |
09d92015 | 7244 | } |
b99bd4ef | 7245 | |
09d92015 | 7246 | static void |
c19d1205 | 7247 | do_ldmstm (void) |
ea6ef066 | 7248 | { |
c19d1205 ZW |
7249 | int base_reg = inst.operands[0].reg; |
7250 | int range = inst.operands[1].imm; | |
ea6ef066 | 7251 | |
c19d1205 ZW |
7252 | inst.instruction |= base_reg << 16; |
7253 | inst.instruction |= range; | |
ea6ef066 | 7254 | |
c19d1205 ZW |
7255 | if (inst.operands[1].writeback) |
7256 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 7257 | |
c19d1205 | 7258 | if (inst.operands[0].writeback) |
ea6ef066 | 7259 | { |
c19d1205 ZW |
7260 | inst.instruction |= WRITE_BACK; |
7261 | /* Check for unpredictable uses of writeback. */ | |
7262 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 7263 | { |
c19d1205 ZW |
7264 | /* Not allowed in LDM type 2. */ |
7265 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
7266 | && ((range & (1 << REG_PC)) == 0)) | |
7267 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7268 | /* Only allowed if base reg not in list for other types. */ | |
7269 | else if (range & (1 << base_reg)) | |
7270 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
7271 | } | |
7272 | else /* STM. */ | |
7273 | { | |
7274 | /* Not allowed for type 2. */ | |
7275 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
7276 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
7277 | /* Only allowed if base reg not in list, or first in list. */ | |
7278 | else if ((range & (1 << base_reg)) | |
7279 | && (range & ((1 << base_reg) - 1))) | |
7280 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 7281 | } |
ea6ef066 | 7282 | } |
a737bd4d NC |
7283 | } |
7284 | ||
c19d1205 ZW |
7285 | /* ARMv5TE load-consecutive (argument parse) |
7286 | Mode is like LDRH. | |
7287 | ||
7288 | LDRccD R, mode | |
7289 | STRccD R, mode. */ | |
7290 | ||
a737bd4d | 7291 | static void |
c19d1205 | 7292 | do_ldrd (void) |
a737bd4d | 7293 | { |
c19d1205 ZW |
7294 | constraint (inst.operands[0].reg % 2 != 0, |
7295 | _("first destination register must be even")); | |
7296 | constraint (inst.operands[1].present | |
7297 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7298 | _("can only load two consecutive registers")); | |
7299 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
7300 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 7301 | |
c19d1205 ZW |
7302 | if (!inst.operands[1].present) |
7303 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 7304 | |
c19d1205 | 7305 | if (inst.instruction & LOAD_BIT) |
a737bd4d | 7306 | { |
c19d1205 ZW |
7307 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
7308 | register and the first register written; we have to diagnose | |
7309 | overlap between the base and the second register written here. */ | |
ea6ef066 | 7310 | |
c19d1205 ZW |
7311 | if (inst.operands[2].reg == inst.operands[1].reg |
7312 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
7313 | as_warn (_("base register written back, and overlaps " | |
7314 | "second destination register")); | |
b05fe5cf | 7315 | |
c19d1205 ZW |
7316 | /* For an index-register load, the index register must not overlap the |
7317 | destination (even if not write-back). */ | |
7318 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
7319 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
7320 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 7321 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 7322 | } |
c19d1205 ZW |
7323 | |
7324 | inst.instruction |= inst.operands[0].reg << 12; | |
7325 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
7326 | } |
7327 | ||
7328 | static void | |
c19d1205 | 7329 | do_ldrex (void) |
b05fe5cf | 7330 | { |
c19d1205 ZW |
7331 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
7332 | || inst.operands[1].postind || inst.operands[1].writeback | |
7333 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
7334 | || inst.operands[1].negative |
7335 | /* This can arise if the programmer has written | |
7336 | strex rN, rM, foo | |
7337 | or if they have mistakenly used a register name as the last | |
7338 | operand, eg: | |
7339 | strex rN, rM, rX | |
7340 | It is very difficult to distinguish between these two cases | |
7341 | because "rX" might actually be a label. ie the register | |
7342 | name has been occluded by a symbol of the same name. So we | |
7343 | just generate a general 'bad addressing mode' type error | |
7344 | message and leave it up to the programmer to discover the | |
7345 | true cause and fix their mistake. */ | |
7346 | || (inst.operands[1].reg == REG_PC), | |
7347 | BAD_ADDR_MODE); | |
b05fe5cf | 7348 | |
c19d1205 ZW |
7349 | constraint (inst.reloc.exp.X_op != O_constant |
7350 | || inst.reloc.exp.X_add_number != 0, | |
7351 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 7352 | |
c19d1205 ZW |
7353 | inst.instruction |= inst.operands[0].reg << 12; |
7354 | inst.instruction |= inst.operands[1].reg << 16; | |
7355 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
7356 | } |
7357 | ||
7358 | static void | |
c19d1205 | 7359 | do_ldrexd (void) |
b05fe5cf | 7360 | { |
c19d1205 ZW |
7361 | constraint (inst.operands[0].reg % 2 != 0, |
7362 | _("even register required")); | |
7363 | constraint (inst.operands[1].present | |
7364 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
7365 | _("can only load two consecutive registers")); | |
7366 | /* If op 1 were present and equal to PC, this function wouldn't | |
7367 | have been called in the first place. */ | |
7368 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 7369 | |
c19d1205 ZW |
7370 | inst.instruction |= inst.operands[0].reg << 12; |
7371 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
7372 | } |
7373 | ||
7374 | static void | |
c19d1205 | 7375 | do_ldst (void) |
b05fe5cf | 7376 | { |
c19d1205 ZW |
7377 | inst.instruction |= inst.operands[0].reg << 12; |
7378 | if (!inst.operands[1].isreg) | |
7379 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 7380 | return; |
c19d1205 | 7381 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7382 | } |
7383 | ||
7384 | static void | |
c19d1205 | 7385 | do_ldstt (void) |
b05fe5cf | 7386 | { |
c19d1205 ZW |
7387 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7388 | reject [Rn,...]. */ | |
7389 | if (inst.operands[1].preind) | |
b05fe5cf | 7390 | { |
bd3ba5d1 NC |
7391 | constraint (inst.reloc.exp.X_op != O_constant |
7392 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7393 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7394 | |
c19d1205 ZW |
7395 | inst.operands[1].preind = 0; |
7396 | inst.operands[1].postind = 1; | |
7397 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7398 | } |
c19d1205 ZW |
7399 | inst.instruction |= inst.operands[0].reg << 12; |
7400 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
7401 | } | |
b05fe5cf | 7402 | |
c19d1205 | 7403 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 7404 | |
c19d1205 ZW |
7405 | static void |
7406 | do_ldstv4 (void) | |
7407 | { | |
7408 | inst.instruction |= inst.operands[0].reg << 12; | |
7409 | if (!inst.operands[1].isreg) | |
7410 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 7411 | return; |
c19d1205 | 7412 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
7413 | } |
7414 | ||
7415 | static void | |
c19d1205 | 7416 | do_ldsttv4 (void) |
b05fe5cf | 7417 | { |
c19d1205 ZW |
7418 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
7419 | reject [Rn,...]. */ | |
7420 | if (inst.operands[1].preind) | |
b05fe5cf | 7421 | { |
bd3ba5d1 NC |
7422 | constraint (inst.reloc.exp.X_op != O_constant |
7423 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 7424 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 7425 | |
c19d1205 ZW |
7426 | inst.operands[1].preind = 0; |
7427 | inst.operands[1].postind = 1; | |
7428 | inst.operands[1].writeback = 1; | |
b05fe5cf | 7429 | } |
c19d1205 ZW |
7430 | inst.instruction |= inst.operands[0].reg << 12; |
7431 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
7432 | } | |
b05fe5cf | 7433 | |
c19d1205 ZW |
7434 | /* Co-processor register load/store. |
7435 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
7436 | static void | |
7437 | do_lstc (void) | |
7438 | { | |
7439 | inst.instruction |= inst.operands[0].reg << 8; | |
7440 | inst.instruction |= inst.operands[1].reg << 12; | |
7441 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
7442 | } |
7443 | ||
b05fe5cf | 7444 | static void |
c19d1205 | 7445 | do_mlas (void) |
b05fe5cf | 7446 | { |
8fb9d7b9 | 7447 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 7448 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 7449 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 7450 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 7451 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 7452 | |
c19d1205 ZW |
7453 | inst.instruction |= inst.operands[0].reg << 16; |
7454 | inst.instruction |= inst.operands[1].reg; | |
7455 | inst.instruction |= inst.operands[2].reg << 8; | |
7456 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 7457 | } |
b05fe5cf | 7458 | |
c19d1205 ZW |
7459 | static void |
7460 | do_mov (void) | |
7461 | { | |
7462 | inst.instruction |= inst.operands[0].reg << 12; | |
7463 | encode_arm_shifter_operand (1); | |
7464 | } | |
b05fe5cf | 7465 | |
c19d1205 ZW |
7466 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
7467 | static void | |
7468 | do_mov16 (void) | |
7469 | { | |
b6895b4f PB |
7470 | bfd_vma imm; |
7471 | bfd_boolean top; | |
7472 | ||
7473 | top = (inst.instruction & 0x00400000) != 0; | |
7474 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
7475 | _(":lower16: not allowed this instruction")); | |
7476 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
7477 | _(":upper16: not allowed instruction")); | |
c19d1205 | 7478 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
7479 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
7480 | { | |
7481 | imm = inst.reloc.exp.X_add_number; | |
7482 | /* The value is in two pieces: 0:11, 16:19. */ | |
7483 | inst.instruction |= (imm & 0x00000fff); | |
7484 | inst.instruction |= (imm & 0x0000f000) << 4; | |
7485 | } | |
b05fe5cf | 7486 | } |
b99bd4ef | 7487 | |
037e8744 JB |
7488 | static void do_vfp_nsyn_opcode (const char *); |
7489 | ||
7490 | static int | |
7491 | do_vfp_nsyn_mrs (void) | |
7492 | { | |
7493 | if (inst.operands[0].isvec) | |
7494 | { | |
7495 | if (inst.operands[1].reg != 1) | |
7496 | first_error (_("operand 1 must be FPSCR")); | |
7497 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
7498 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
7499 | do_vfp_nsyn_opcode ("fmstat"); | |
7500 | } | |
7501 | else if (inst.operands[1].isvec) | |
7502 | do_vfp_nsyn_opcode ("fmrx"); | |
7503 | else | |
7504 | return FAIL; | |
5f4273c7 | 7505 | |
037e8744 JB |
7506 | return SUCCESS; |
7507 | } | |
7508 | ||
7509 | static int | |
7510 | do_vfp_nsyn_msr (void) | |
7511 | { | |
7512 | if (inst.operands[0].isvec) | |
7513 | do_vfp_nsyn_opcode ("fmxr"); | |
7514 | else | |
7515 | return FAIL; | |
7516 | ||
7517 | return SUCCESS; | |
7518 | } | |
7519 | ||
b99bd4ef | 7520 | static void |
c19d1205 | 7521 | do_mrs (void) |
b99bd4ef | 7522 | { |
037e8744 JB |
7523 | if (do_vfp_nsyn_mrs () == SUCCESS) |
7524 | return; | |
7525 | ||
c19d1205 ZW |
7526 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
7527 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7528 | != (PSR_c|PSR_f), | |
7529 | _("'CPSR' or 'SPSR' expected")); | |
7530 | inst.instruction |= inst.operands[0].reg << 12; | |
7531 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
7532 | } | |
b99bd4ef | 7533 | |
c19d1205 ZW |
7534 | /* Two possible forms: |
7535 | "{C|S}PSR_<field>, Rm", | |
7536 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 7537 | |
c19d1205 ZW |
7538 | static void |
7539 | do_msr (void) | |
7540 | { | |
037e8744 JB |
7541 | if (do_vfp_nsyn_msr () == SUCCESS) |
7542 | return; | |
7543 | ||
c19d1205 ZW |
7544 | inst.instruction |= inst.operands[0].imm; |
7545 | if (inst.operands[1].isreg) | |
7546 | inst.instruction |= inst.operands[1].reg; | |
7547 | else | |
b99bd4ef | 7548 | { |
c19d1205 ZW |
7549 | inst.instruction |= INST_IMMEDIATE; |
7550 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
7551 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 7552 | } |
b99bd4ef NC |
7553 | } |
7554 | ||
c19d1205 ZW |
7555 | static void |
7556 | do_mul (void) | |
a737bd4d | 7557 | { |
c19d1205 ZW |
7558 | if (!inst.operands[2].present) |
7559 | inst.operands[2].reg = inst.operands[0].reg; | |
7560 | inst.instruction |= inst.operands[0].reg << 16; | |
7561 | inst.instruction |= inst.operands[1].reg; | |
7562 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 7563 | |
8fb9d7b9 MS |
7564 | if (inst.operands[0].reg == inst.operands[1].reg |
7565 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
7566 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
7567 | } |
7568 | ||
c19d1205 ZW |
7569 | /* Long Multiply Parser |
7570 | UMULL RdLo, RdHi, Rm, Rs | |
7571 | SMULL RdLo, RdHi, Rm, Rs | |
7572 | UMLAL RdLo, RdHi, Rm, Rs | |
7573 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
7574 | |
7575 | static void | |
c19d1205 | 7576 | do_mull (void) |
b99bd4ef | 7577 | { |
c19d1205 ZW |
7578 | inst.instruction |= inst.operands[0].reg << 12; |
7579 | inst.instruction |= inst.operands[1].reg << 16; | |
7580 | inst.instruction |= inst.operands[2].reg; | |
7581 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 7582 | |
682b27ad PB |
7583 | /* rdhi and rdlo must be different. */ |
7584 | if (inst.operands[0].reg == inst.operands[1].reg) | |
7585 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7586 | ||
7587 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
7588 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 7589 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 7590 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
7591 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
7592 | } | |
b99bd4ef | 7593 | |
c19d1205 ZW |
7594 | static void |
7595 | do_nop (void) | |
7596 | { | |
e7495e45 NS |
7597 | if (inst.operands[0].present |
7598 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
7599 | { |
7600 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
7601 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
7602 | inst.instruction |= 0x0320f000; |
7603 | if (inst.operands[0].present) | |
7604 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 7605 | } |
b99bd4ef NC |
7606 | } |
7607 | ||
c19d1205 ZW |
7608 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
7609 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
7610 | Condition defaults to COND_ALWAYS. | |
7611 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
7612 | |
7613 | static void | |
c19d1205 | 7614 | do_pkhbt (void) |
b99bd4ef | 7615 | { |
c19d1205 ZW |
7616 | inst.instruction |= inst.operands[0].reg << 12; |
7617 | inst.instruction |= inst.operands[1].reg << 16; | |
7618 | inst.instruction |= inst.operands[2].reg; | |
7619 | if (inst.operands[3].present) | |
7620 | encode_arm_shift (3); | |
7621 | } | |
b99bd4ef | 7622 | |
c19d1205 | 7623 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 7624 | |
c19d1205 ZW |
7625 | static void |
7626 | do_pkhtb (void) | |
7627 | { | |
7628 | if (!inst.operands[3].present) | |
b99bd4ef | 7629 | { |
c19d1205 ZW |
7630 | /* If the shift specifier is omitted, turn the instruction |
7631 | into pkhbt rd, rm, rn. */ | |
7632 | inst.instruction &= 0xfff00010; | |
7633 | inst.instruction |= inst.operands[0].reg << 12; | |
7634 | inst.instruction |= inst.operands[1].reg; | |
7635 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
7636 | } |
7637 | else | |
7638 | { | |
c19d1205 ZW |
7639 | inst.instruction |= inst.operands[0].reg << 12; |
7640 | inst.instruction |= inst.operands[1].reg << 16; | |
7641 | inst.instruction |= inst.operands[2].reg; | |
7642 | encode_arm_shift (3); | |
b99bd4ef NC |
7643 | } |
7644 | } | |
7645 | ||
c19d1205 ZW |
7646 | /* ARMv5TE: Preload-Cache |
7647 | ||
7648 | PLD <addr_mode> | |
7649 | ||
7650 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
7651 | |
7652 | static void | |
c19d1205 | 7653 | do_pld (void) |
b99bd4ef | 7654 | { |
c19d1205 ZW |
7655 | constraint (!inst.operands[0].isreg, |
7656 | _("'[' expected after PLD mnemonic")); | |
7657 | constraint (inst.operands[0].postind, | |
7658 | _("post-indexed expression used in preload instruction")); | |
7659 | constraint (inst.operands[0].writeback, | |
7660 | _("writeback used in preload instruction")); | |
7661 | constraint (!inst.operands[0].preind, | |
7662 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
7663 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
7664 | } | |
b99bd4ef | 7665 | |
62b3e311 PB |
7666 | /* ARMv7: PLI <addr_mode> */ |
7667 | static void | |
7668 | do_pli (void) | |
7669 | { | |
7670 | constraint (!inst.operands[0].isreg, | |
7671 | _("'[' expected after PLI mnemonic")); | |
7672 | constraint (inst.operands[0].postind, | |
7673 | _("post-indexed expression used in preload instruction")); | |
7674 | constraint (inst.operands[0].writeback, | |
7675 | _("writeback used in preload instruction")); | |
7676 | constraint (!inst.operands[0].preind, | |
7677 | _("unindexed addressing used in preload instruction")); | |
7678 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
7679 | inst.instruction &= ~PRE_INDEX; | |
7680 | } | |
7681 | ||
c19d1205 ZW |
7682 | static void |
7683 | do_push_pop (void) | |
7684 | { | |
7685 | inst.operands[1] = inst.operands[0]; | |
7686 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
7687 | inst.operands[0].isreg = 1; | |
7688 | inst.operands[0].writeback = 1; | |
7689 | inst.operands[0].reg = REG_SP; | |
7690 | do_ldmstm (); | |
7691 | } | |
b99bd4ef | 7692 | |
c19d1205 ZW |
7693 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
7694 | word at the specified address and the following word | |
7695 | respectively. | |
7696 | Unconditionally executed. | |
7697 | Error if Rn is R15. */ | |
b99bd4ef | 7698 | |
c19d1205 ZW |
7699 | static void |
7700 | do_rfe (void) | |
7701 | { | |
7702 | inst.instruction |= inst.operands[0].reg << 16; | |
7703 | if (inst.operands[0].writeback) | |
7704 | inst.instruction |= WRITE_BACK; | |
7705 | } | |
b99bd4ef | 7706 | |
c19d1205 | 7707 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 7708 | |
c19d1205 ZW |
7709 | static void |
7710 | do_ssat (void) | |
7711 | { | |
7712 | inst.instruction |= inst.operands[0].reg << 12; | |
7713 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
7714 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7715 | |
c19d1205 ZW |
7716 | if (inst.operands[3].present) |
7717 | encode_arm_shift (3); | |
b99bd4ef NC |
7718 | } |
7719 | ||
c19d1205 | 7720 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
7721 | |
7722 | static void | |
c19d1205 | 7723 | do_usat (void) |
b99bd4ef | 7724 | { |
c19d1205 ZW |
7725 | inst.instruction |= inst.operands[0].reg << 12; |
7726 | inst.instruction |= inst.operands[1].imm << 16; | |
7727 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 7728 | |
c19d1205 ZW |
7729 | if (inst.operands[3].present) |
7730 | encode_arm_shift (3); | |
b99bd4ef NC |
7731 | } |
7732 | ||
c19d1205 | 7733 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
7734 | |
7735 | static void | |
c19d1205 | 7736 | do_ssat16 (void) |
09d92015 | 7737 | { |
c19d1205 ZW |
7738 | inst.instruction |= inst.operands[0].reg << 12; |
7739 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
7740 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
7741 | } |
7742 | ||
c19d1205 ZW |
7743 | static void |
7744 | do_usat16 (void) | |
a737bd4d | 7745 | { |
c19d1205 ZW |
7746 | inst.instruction |= inst.operands[0].reg << 12; |
7747 | inst.instruction |= inst.operands[1].imm << 16; | |
7748 | inst.instruction |= inst.operands[2].reg; | |
7749 | } | |
a737bd4d | 7750 | |
c19d1205 ZW |
7751 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
7752 | preserving the other bits. | |
a737bd4d | 7753 | |
c19d1205 ZW |
7754 | setend <endian_specifier>, where <endian_specifier> is either |
7755 | BE or LE. */ | |
a737bd4d | 7756 | |
c19d1205 ZW |
7757 | static void |
7758 | do_setend (void) | |
7759 | { | |
7760 | if (inst.operands[0].imm) | |
7761 | inst.instruction |= 0x200; | |
a737bd4d NC |
7762 | } |
7763 | ||
7764 | static void | |
c19d1205 | 7765 | do_shift (void) |
a737bd4d | 7766 | { |
c19d1205 ZW |
7767 | unsigned int Rm = (inst.operands[1].present |
7768 | ? inst.operands[1].reg | |
7769 | : inst.operands[0].reg); | |
a737bd4d | 7770 | |
c19d1205 ZW |
7771 | inst.instruction |= inst.operands[0].reg << 12; |
7772 | inst.instruction |= Rm; | |
7773 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 7774 | { |
c19d1205 ZW |
7775 | inst.instruction |= inst.operands[2].reg << 8; |
7776 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
7777 | } |
7778 | else | |
c19d1205 | 7779 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
7780 | } |
7781 | ||
09d92015 | 7782 | static void |
3eb17e6b | 7783 | do_smc (void) |
09d92015 | 7784 | { |
3eb17e6b | 7785 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 7786 | inst.reloc.pc_rel = 0; |
09d92015 MM |
7787 | } |
7788 | ||
09d92015 | 7789 | static void |
c19d1205 | 7790 | do_swi (void) |
09d92015 | 7791 | { |
c19d1205 ZW |
7792 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
7793 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
7794 | } |
7795 | ||
c19d1205 ZW |
7796 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
7797 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
7798 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
7799 | Error if any register is R15. */ | |
e16bb312 | 7800 | |
c19d1205 ZW |
7801 | static void |
7802 | do_smla (void) | |
e16bb312 | 7803 | { |
c19d1205 ZW |
7804 | inst.instruction |= inst.operands[0].reg << 16; |
7805 | inst.instruction |= inst.operands[1].reg; | |
7806 | inst.instruction |= inst.operands[2].reg << 8; | |
7807 | inst.instruction |= inst.operands[3].reg << 12; | |
7808 | } | |
a737bd4d | 7809 | |
c19d1205 ZW |
7810 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
7811 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
7812 | Error if any register is R15. | |
7813 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 7814 | |
c19d1205 ZW |
7815 | static void |
7816 | do_smlal (void) | |
7817 | { | |
7818 | inst.instruction |= inst.operands[0].reg << 12; | |
7819 | inst.instruction |= inst.operands[1].reg << 16; | |
7820 | inst.instruction |= inst.operands[2].reg; | |
7821 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 7822 | |
c19d1205 ZW |
7823 | if (inst.operands[0].reg == inst.operands[1].reg) |
7824 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7825 | } | |
a737bd4d | 7826 | |
c19d1205 ZW |
7827 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
7828 | SMULxy{cond} Rd,Rm,Rs | |
7829 | Error if any register is R15. */ | |
a737bd4d | 7830 | |
c19d1205 ZW |
7831 | static void |
7832 | do_smul (void) | |
7833 | { | |
7834 | inst.instruction |= inst.operands[0].reg << 16; | |
7835 | inst.instruction |= inst.operands[1].reg; | |
7836 | inst.instruction |= inst.operands[2].reg << 8; | |
7837 | } | |
a737bd4d | 7838 | |
b6702015 PB |
7839 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
7840 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 7841 | |
c19d1205 ZW |
7842 | static void |
7843 | do_srs (void) | |
7844 | { | |
b6702015 PB |
7845 | int reg; |
7846 | ||
7847 | if (inst.operands[0].present) | |
7848 | { | |
7849 | reg = inst.operands[0].reg; | |
fdfde340 | 7850 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
7851 | } |
7852 | else | |
fdfde340 | 7853 | reg = REG_SP; |
b6702015 PB |
7854 | |
7855 | inst.instruction |= reg << 16; | |
7856 | inst.instruction |= inst.operands[1].imm; | |
7857 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
7858 | inst.instruction |= WRITE_BACK; |
7859 | } | |
a737bd4d | 7860 | |
c19d1205 | 7861 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 7862 | |
c19d1205 ZW |
7863 | static void |
7864 | do_strex (void) | |
7865 | { | |
7866 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7867 | || inst.operands[2].postind || inst.operands[2].writeback | |
7868 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
7869 | || inst.operands[2].negative |
7870 | /* See comment in do_ldrex(). */ | |
7871 | || (inst.operands[2].reg == REG_PC), | |
7872 | BAD_ADDR_MODE); | |
a737bd4d | 7873 | |
c19d1205 ZW |
7874 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7875 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 7876 | |
c19d1205 ZW |
7877 | constraint (inst.reloc.exp.X_op != O_constant |
7878 | || inst.reloc.exp.X_add_number != 0, | |
7879 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 7880 | |
c19d1205 ZW |
7881 | inst.instruction |= inst.operands[0].reg << 12; |
7882 | inst.instruction |= inst.operands[1].reg; | |
7883 | inst.instruction |= inst.operands[2].reg << 16; | |
7884 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
7885 | } |
7886 | ||
7887 | static void | |
c19d1205 | 7888 | do_strexd (void) |
e16bb312 | 7889 | { |
c19d1205 ZW |
7890 | constraint (inst.operands[1].reg % 2 != 0, |
7891 | _("even register required")); | |
7892 | constraint (inst.operands[2].present | |
7893 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
7894 | _("can only store two consecutive registers")); | |
7895 | /* If op 2 were present and equal to PC, this function wouldn't | |
7896 | have been called in the first place. */ | |
7897 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 7898 | |
c19d1205 ZW |
7899 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7900 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
7901 | || inst.operands[0].reg == inst.operands[3].reg, | |
7902 | BAD_OVERLAP); | |
e16bb312 | 7903 | |
c19d1205 ZW |
7904 | inst.instruction |= inst.operands[0].reg << 12; |
7905 | inst.instruction |= inst.operands[1].reg; | |
7906 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
7907 | } |
7908 | ||
c19d1205 ZW |
7909 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
7910 | extends it to 32-bits, and adds the result to a value in another | |
7911 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
7912 | before extracting the 16-bit value. | |
7913 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
7914 | Condition defaults to COND_ALWAYS. | |
7915 | Error if any register uses R15. */ | |
7916 | ||
e16bb312 | 7917 | static void |
c19d1205 | 7918 | do_sxtah (void) |
e16bb312 | 7919 | { |
c19d1205 ZW |
7920 | inst.instruction |= inst.operands[0].reg << 12; |
7921 | inst.instruction |= inst.operands[1].reg << 16; | |
7922 | inst.instruction |= inst.operands[2].reg; | |
7923 | inst.instruction |= inst.operands[3].imm << 10; | |
7924 | } | |
e16bb312 | 7925 | |
c19d1205 | 7926 | /* ARM V6 SXTH. |
e16bb312 | 7927 | |
c19d1205 ZW |
7928 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
7929 | Condition defaults to COND_ALWAYS. | |
7930 | Error if any register uses R15. */ | |
e16bb312 NC |
7931 | |
7932 | static void | |
c19d1205 | 7933 | do_sxth (void) |
e16bb312 | 7934 | { |
c19d1205 ZW |
7935 | inst.instruction |= inst.operands[0].reg << 12; |
7936 | inst.instruction |= inst.operands[1].reg; | |
7937 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 7938 | } |
c19d1205 ZW |
7939 | \f |
7940 | /* VFP instructions. In a logical order: SP variant first, monad | |
7941 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
7942 | |
7943 | static void | |
c19d1205 | 7944 | do_vfp_sp_monadic (void) |
e16bb312 | 7945 | { |
5287ad62 JB |
7946 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7947 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
7948 | } |
7949 | ||
7950 | static void | |
c19d1205 | 7951 | do_vfp_sp_dyadic (void) |
e16bb312 | 7952 | { |
5287ad62 JB |
7953 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7954 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
7955 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
7956 | } |
7957 | ||
7958 | static void | |
c19d1205 | 7959 | do_vfp_sp_compare_z (void) |
e16bb312 | 7960 | { |
5287ad62 | 7961 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
7962 | } |
7963 | ||
7964 | static void | |
c19d1205 | 7965 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 7966 | { |
5287ad62 JB |
7967 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
7968 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
7969 | } |
7970 | ||
7971 | static void | |
c19d1205 | 7972 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 7973 | { |
5287ad62 JB |
7974 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
7975 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
7976 | } |
7977 | ||
7978 | static void | |
c19d1205 | 7979 | do_vfp_reg_from_sp (void) |
e16bb312 | 7980 | { |
c19d1205 | 7981 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 7982 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
7983 | } |
7984 | ||
7985 | static void | |
c19d1205 | 7986 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 7987 | { |
c19d1205 ZW |
7988 | constraint (inst.operands[2].imm != 2, |
7989 | _("only two consecutive VFP SP registers allowed here")); | |
7990 | inst.instruction |= inst.operands[0].reg << 12; | |
7991 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 7992 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
7993 | } |
7994 | ||
7995 | static void | |
c19d1205 | 7996 | do_vfp_sp_from_reg (void) |
e16bb312 | 7997 | { |
5287ad62 | 7998 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 7999 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
8000 | } |
8001 | ||
8002 | static void | |
c19d1205 | 8003 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 8004 | { |
c19d1205 ZW |
8005 | constraint (inst.operands[0].imm != 2, |
8006 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 8007 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
8008 | inst.instruction |= inst.operands[1].reg << 12; |
8009 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
8010 | } |
8011 | ||
8012 | static void | |
c19d1205 | 8013 | do_vfp_sp_ldst (void) |
e16bb312 | 8014 | { |
5287ad62 | 8015 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 8016 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8017 | } |
8018 | ||
8019 | static void | |
c19d1205 | 8020 | do_vfp_dp_ldst (void) |
e16bb312 | 8021 | { |
5287ad62 | 8022 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 8023 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
8024 | } |
8025 | ||
c19d1205 | 8026 | |
e16bb312 | 8027 | static void |
c19d1205 | 8028 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8029 | { |
c19d1205 ZW |
8030 | if (inst.operands[0].writeback) |
8031 | inst.instruction |= WRITE_BACK; | |
8032 | else | |
8033 | constraint (ldstm_type != VFP_LDSTMIA, | |
8034 | _("this addressing mode requires base-register writeback")); | |
8035 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 8036 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 8037 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
8038 | } |
8039 | ||
8040 | static void | |
c19d1205 | 8041 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 8042 | { |
c19d1205 | 8043 | int count; |
e16bb312 | 8044 | |
c19d1205 ZW |
8045 | if (inst.operands[0].writeback) |
8046 | inst.instruction |= WRITE_BACK; | |
8047 | else | |
8048 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
8049 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 8050 | |
c19d1205 | 8051 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 8052 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 8053 | |
c19d1205 ZW |
8054 | count = inst.operands[1].imm << 1; |
8055 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
8056 | count += 1; | |
e16bb312 | 8057 | |
c19d1205 | 8058 | inst.instruction |= count; |
e16bb312 NC |
8059 | } |
8060 | ||
8061 | static void | |
c19d1205 | 8062 | do_vfp_sp_ldstmia (void) |
e16bb312 | 8063 | { |
c19d1205 | 8064 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8065 | } |
8066 | ||
8067 | static void | |
c19d1205 | 8068 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 8069 | { |
c19d1205 | 8070 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8071 | } |
8072 | ||
8073 | static void | |
c19d1205 | 8074 | do_vfp_dp_ldstmia (void) |
e16bb312 | 8075 | { |
c19d1205 | 8076 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
8077 | } |
8078 | ||
8079 | static void | |
c19d1205 | 8080 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 8081 | { |
c19d1205 | 8082 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
8083 | } |
8084 | ||
8085 | static void | |
c19d1205 | 8086 | do_vfp_xp_ldstmia (void) |
e16bb312 | 8087 | { |
c19d1205 ZW |
8088 | vfp_dp_ldstm (VFP_LDSTMIAX); |
8089 | } | |
e16bb312 | 8090 | |
c19d1205 ZW |
8091 | static void |
8092 | do_vfp_xp_ldstmdb (void) | |
8093 | { | |
8094 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 8095 | } |
5287ad62 JB |
8096 | |
8097 | static void | |
8098 | do_vfp_dp_rd_rm (void) | |
8099 | { | |
8100 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8101 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
8102 | } | |
8103 | ||
8104 | static void | |
8105 | do_vfp_dp_rn_rd (void) | |
8106 | { | |
8107 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
8108 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8109 | } | |
8110 | ||
8111 | static void | |
8112 | do_vfp_dp_rd_rn (void) | |
8113 | { | |
8114 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8115 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8116 | } | |
8117 | ||
8118 | static void | |
8119 | do_vfp_dp_rd_rn_rm (void) | |
8120 | { | |
8121 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8122 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
8123 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
8124 | } | |
8125 | ||
8126 | static void | |
8127 | do_vfp_dp_rd (void) | |
8128 | { | |
8129 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8130 | } | |
8131 | ||
8132 | static void | |
8133 | do_vfp_dp_rm_rd_rn (void) | |
8134 | { | |
8135 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
8136 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
8137 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
8138 | } | |
8139 | ||
8140 | /* VFPv3 instructions. */ | |
8141 | static void | |
8142 | do_vfp_sp_const (void) | |
8143 | { | |
8144 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
8145 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8146 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8147 | } |
8148 | ||
8149 | static void | |
8150 | do_vfp_dp_const (void) | |
8151 | { | |
8152 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
8153 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
8154 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
8155 | } |
8156 | ||
8157 | static void | |
8158 | vfp_conv (int srcsize) | |
8159 | { | |
8160 | unsigned immbits = srcsize - inst.operands[1].imm; | |
8161 | inst.instruction |= (immbits & 1) << 5; | |
8162 | inst.instruction |= (immbits >> 1); | |
8163 | } | |
8164 | ||
8165 | static void | |
8166 | do_vfp_sp_conv_16 (void) | |
8167 | { | |
8168 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8169 | vfp_conv (16); | |
8170 | } | |
8171 | ||
8172 | static void | |
8173 | do_vfp_dp_conv_16 (void) | |
8174 | { | |
8175 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8176 | vfp_conv (16); | |
8177 | } | |
8178 | ||
8179 | static void | |
8180 | do_vfp_sp_conv_32 (void) | |
8181 | { | |
8182 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
8183 | vfp_conv (32); | |
8184 | } | |
8185 | ||
8186 | static void | |
8187 | do_vfp_dp_conv_32 (void) | |
8188 | { | |
8189 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
8190 | vfp_conv (32); | |
8191 | } | |
c19d1205 ZW |
8192 | \f |
8193 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 8194 | |
c19d1205 ZW |
8195 | static void |
8196 | do_fpa_cmp (void) | |
8197 | { | |
8198 | inst.instruction |= inst.operands[0].reg << 16; | |
8199 | inst.instruction |= inst.operands[1].reg; | |
8200 | } | |
b99bd4ef NC |
8201 | |
8202 | static void | |
c19d1205 | 8203 | do_fpa_ldmstm (void) |
b99bd4ef | 8204 | { |
c19d1205 ZW |
8205 | inst.instruction |= inst.operands[0].reg << 12; |
8206 | switch (inst.operands[1].imm) | |
8207 | { | |
8208 | case 1: inst.instruction |= CP_T_X; break; | |
8209 | case 2: inst.instruction |= CP_T_Y; break; | |
8210 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
8211 | case 4: break; | |
8212 | default: abort (); | |
8213 | } | |
b99bd4ef | 8214 | |
c19d1205 ZW |
8215 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
8216 | { | |
8217 | /* The instruction specified "ea" or "fd", so we can only accept | |
8218 | [Rn]{!}. The instruction does not really support stacking or | |
8219 | unstacking, so we have to emulate these by setting appropriate | |
8220 | bits and offsets. */ | |
8221 | constraint (inst.reloc.exp.X_op != O_constant | |
8222 | || inst.reloc.exp.X_add_number != 0, | |
8223 | _("this instruction does not support indexing")); | |
b99bd4ef | 8224 | |
c19d1205 ZW |
8225 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
8226 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 8227 | |
c19d1205 ZW |
8228 | if (!(inst.instruction & INDEX_UP)) |
8229 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 8230 | |
c19d1205 ZW |
8231 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
8232 | { | |
8233 | inst.operands[2].preind = 0; | |
8234 | inst.operands[2].postind = 1; | |
8235 | } | |
8236 | } | |
b99bd4ef | 8237 | |
c19d1205 | 8238 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 8239 | } |
c19d1205 ZW |
8240 | \f |
8241 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 8242 | |
c19d1205 ZW |
8243 | static void |
8244 | do_iwmmxt_tandorc (void) | |
8245 | { | |
8246 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
8247 | } | |
b99bd4ef | 8248 | |
c19d1205 ZW |
8249 | static void |
8250 | do_iwmmxt_textrc (void) | |
8251 | { | |
8252 | inst.instruction |= inst.operands[0].reg << 12; | |
8253 | inst.instruction |= inst.operands[1].imm; | |
8254 | } | |
b99bd4ef NC |
8255 | |
8256 | static void | |
c19d1205 | 8257 | do_iwmmxt_textrm (void) |
b99bd4ef | 8258 | { |
c19d1205 ZW |
8259 | inst.instruction |= inst.operands[0].reg << 12; |
8260 | inst.instruction |= inst.operands[1].reg << 16; | |
8261 | inst.instruction |= inst.operands[2].imm; | |
8262 | } | |
b99bd4ef | 8263 | |
c19d1205 ZW |
8264 | static void |
8265 | do_iwmmxt_tinsr (void) | |
8266 | { | |
8267 | inst.instruction |= inst.operands[0].reg << 16; | |
8268 | inst.instruction |= inst.operands[1].reg << 12; | |
8269 | inst.instruction |= inst.operands[2].imm; | |
8270 | } | |
b99bd4ef | 8271 | |
c19d1205 ZW |
8272 | static void |
8273 | do_iwmmxt_tmia (void) | |
8274 | { | |
8275 | inst.instruction |= inst.operands[0].reg << 5; | |
8276 | inst.instruction |= inst.operands[1].reg; | |
8277 | inst.instruction |= inst.operands[2].reg << 12; | |
8278 | } | |
b99bd4ef | 8279 | |
c19d1205 ZW |
8280 | static void |
8281 | do_iwmmxt_waligni (void) | |
8282 | { | |
8283 | inst.instruction |= inst.operands[0].reg << 12; | |
8284 | inst.instruction |= inst.operands[1].reg << 16; | |
8285 | inst.instruction |= inst.operands[2].reg; | |
8286 | inst.instruction |= inst.operands[3].imm << 20; | |
8287 | } | |
b99bd4ef | 8288 | |
2d447fca JM |
8289 | static void |
8290 | do_iwmmxt_wmerge (void) | |
8291 | { | |
8292 | inst.instruction |= inst.operands[0].reg << 12; | |
8293 | inst.instruction |= inst.operands[1].reg << 16; | |
8294 | inst.instruction |= inst.operands[2].reg; | |
8295 | inst.instruction |= inst.operands[3].imm << 21; | |
8296 | } | |
8297 | ||
c19d1205 ZW |
8298 | static void |
8299 | do_iwmmxt_wmov (void) | |
8300 | { | |
8301 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
8302 | inst.instruction |= inst.operands[0].reg << 12; | |
8303 | inst.instruction |= inst.operands[1].reg << 16; | |
8304 | inst.instruction |= inst.operands[1].reg; | |
8305 | } | |
b99bd4ef | 8306 | |
c19d1205 ZW |
8307 | static void |
8308 | do_iwmmxt_wldstbh (void) | |
8309 | { | |
8f06b2d8 | 8310 | int reloc; |
c19d1205 | 8311 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
8312 | if (thumb_mode) |
8313 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
8314 | else | |
8315 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
8316 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
8317 | } |
8318 | ||
c19d1205 ZW |
8319 | static void |
8320 | do_iwmmxt_wldstw (void) | |
8321 | { | |
8322 | /* RIWR_RIWC clears .isreg for a control register. */ | |
8323 | if (!inst.operands[0].isreg) | |
8324 | { | |
8325 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
8326 | inst.instruction |= 0xf0000000; | |
8327 | } | |
b99bd4ef | 8328 | |
c19d1205 ZW |
8329 | inst.instruction |= inst.operands[0].reg << 12; |
8330 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
8331 | } | |
b99bd4ef NC |
8332 | |
8333 | static void | |
c19d1205 | 8334 | do_iwmmxt_wldstd (void) |
b99bd4ef | 8335 | { |
c19d1205 | 8336 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
8337 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
8338 | && inst.operands[1].immisreg) | |
8339 | { | |
8340 | inst.instruction &= ~0x1a000ff; | |
8341 | inst.instruction |= (0xf << 28); | |
8342 | if (inst.operands[1].preind) | |
8343 | inst.instruction |= PRE_INDEX; | |
8344 | if (!inst.operands[1].negative) | |
8345 | inst.instruction |= INDEX_UP; | |
8346 | if (inst.operands[1].writeback) | |
8347 | inst.instruction |= WRITE_BACK; | |
8348 | inst.instruction |= inst.operands[1].reg << 16; | |
8349 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
8350 | inst.instruction |= inst.operands[1].imm; | |
8351 | } | |
8352 | else | |
8353 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 8354 | } |
b99bd4ef | 8355 | |
c19d1205 ZW |
8356 | static void |
8357 | do_iwmmxt_wshufh (void) | |
8358 | { | |
8359 | inst.instruction |= inst.operands[0].reg << 12; | |
8360 | inst.instruction |= inst.operands[1].reg << 16; | |
8361 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
8362 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
8363 | } | |
b99bd4ef | 8364 | |
c19d1205 ZW |
8365 | static void |
8366 | do_iwmmxt_wzero (void) | |
8367 | { | |
8368 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
8369 | inst.instruction |= inst.operands[0].reg; | |
8370 | inst.instruction |= inst.operands[0].reg << 12; | |
8371 | inst.instruction |= inst.operands[0].reg << 16; | |
8372 | } | |
2d447fca JM |
8373 | |
8374 | static void | |
8375 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
8376 | { | |
8377 | if (inst.operands[2].isreg) | |
8378 | do_rd_rn_rm (); | |
8379 | else { | |
8380 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
8381 | _("immediate operand requires iWMMXt2")); | |
8382 | do_rd_rn (); | |
8383 | if (inst.operands[2].imm == 0) | |
8384 | { | |
8385 | switch ((inst.instruction >> 20) & 0xf) | |
8386 | { | |
8387 | case 4: | |
8388 | case 5: | |
8389 | case 6: | |
5f4273c7 | 8390 | case 7: |
2d447fca JM |
8391 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
8392 | inst.operands[2].imm = 16; | |
8393 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
8394 | break; | |
8395 | case 8: | |
8396 | case 9: | |
8397 | case 10: | |
8398 | case 11: | |
8399 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
8400 | inst.operands[2].imm = 32; | |
8401 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
8402 | break; | |
8403 | case 12: | |
8404 | case 13: | |
8405 | case 14: | |
8406 | case 15: | |
8407 | { | |
8408 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
8409 | unsigned long wrn; | |
8410 | wrn = (inst.instruction >> 16) & 0xf; | |
8411 | inst.instruction &= 0xff0fff0f; | |
8412 | inst.instruction |= wrn; | |
8413 | /* Bail out here; the instruction is now assembled. */ | |
8414 | return; | |
8415 | } | |
8416 | } | |
8417 | } | |
8418 | /* Map 32 -> 0, etc. */ | |
8419 | inst.operands[2].imm &= 0x1f; | |
8420 | inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); | |
8421 | } | |
8422 | } | |
c19d1205 ZW |
8423 | \f |
8424 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
8425 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 8426 | |
c19d1205 | 8427 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 8428 | |
c19d1205 ZW |
8429 | static void |
8430 | do_mav_triple (void) | |
8431 | { | |
8432 | inst.instruction |= inst.operands[0].reg << 16; | |
8433 | inst.instruction |= inst.operands[1].reg; | |
8434 | inst.instruction |= inst.operands[2].reg << 12; | |
8435 | } | |
b99bd4ef | 8436 | |
c19d1205 ZW |
8437 | /* Insns like "foo W,X,Y,Z". |
8438 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 8439 | |
c19d1205 ZW |
8440 | static void |
8441 | do_mav_quad (void) | |
8442 | { | |
8443 | inst.instruction |= inst.operands[0].reg << 5; | |
8444 | inst.instruction |= inst.operands[1].reg << 12; | |
8445 | inst.instruction |= inst.operands[2].reg << 16; | |
8446 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
8447 | } |
8448 | ||
c19d1205 ZW |
8449 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
8450 | static void | |
8451 | do_mav_dspsc (void) | |
a737bd4d | 8452 | { |
c19d1205 ZW |
8453 | inst.instruction |= inst.operands[1].reg << 12; |
8454 | } | |
a737bd4d | 8455 | |
c19d1205 ZW |
8456 | /* Maverick shift immediate instructions. |
8457 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
8458 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 8459 | |
c19d1205 ZW |
8460 | static void |
8461 | do_mav_shift (void) | |
8462 | { | |
8463 | int imm = inst.operands[2].imm; | |
a737bd4d | 8464 | |
c19d1205 ZW |
8465 | inst.instruction |= inst.operands[0].reg << 12; |
8466 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 8467 | |
c19d1205 ZW |
8468 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
8469 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
8470 | Bit 4 should be 0. */ | |
8471 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 8472 | |
c19d1205 ZW |
8473 | inst.instruction |= imm; |
8474 | } | |
8475 | \f | |
8476 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 8477 | |
c19d1205 ZW |
8478 | /* Xscale multiply-accumulate (argument parse) |
8479 | MIAcc acc0,Rm,Rs | |
8480 | MIAPHcc acc0,Rm,Rs | |
8481 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 8482 | |
c19d1205 ZW |
8483 | static void |
8484 | do_xsc_mia (void) | |
8485 | { | |
8486 | inst.instruction |= inst.operands[1].reg; | |
8487 | inst.instruction |= inst.operands[2].reg << 12; | |
8488 | } | |
a737bd4d | 8489 | |
c19d1205 | 8490 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 8491 | |
c19d1205 | 8492 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 8493 | |
c19d1205 ZW |
8494 | static void |
8495 | do_xsc_mar (void) | |
8496 | { | |
8497 | inst.instruction |= inst.operands[1].reg << 12; | |
8498 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
8499 | } |
8500 | ||
c19d1205 | 8501 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 8502 | |
c19d1205 | 8503 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
8504 | |
8505 | static void | |
c19d1205 | 8506 | do_xsc_mra (void) |
b99bd4ef | 8507 | { |
c19d1205 ZW |
8508 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
8509 | inst.instruction |= inst.operands[0].reg << 12; | |
8510 | inst.instruction |= inst.operands[1].reg << 16; | |
8511 | } | |
8512 | \f | |
8513 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 8514 | |
c19d1205 ZW |
8515 | /* inst.operands[i] is a shifted-register operand; encode |
8516 | it into inst.instruction in the format used by Thumb32. */ | |
8517 | ||
8518 | static void | |
8519 | encode_thumb32_shifted_operand (int i) | |
8520 | { | |
8521 | unsigned int value = inst.reloc.exp.X_add_number; | |
8522 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 8523 | |
9c3c69f2 PB |
8524 | constraint (inst.operands[i].immisreg, |
8525 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
8526 | inst.instruction |= inst.operands[i].reg; |
8527 | if (shift == SHIFT_RRX) | |
8528 | inst.instruction |= SHIFT_ROR << 4; | |
8529 | else | |
b99bd4ef | 8530 | { |
c19d1205 ZW |
8531 | constraint (inst.reloc.exp.X_op != O_constant, |
8532 | _("expression too complex")); | |
8533 | ||
8534 | constraint (value > 32 | |
8535 | || (value == 32 && (shift == SHIFT_LSL | |
8536 | || shift == SHIFT_ROR)), | |
8537 | _("shift expression is too large")); | |
8538 | ||
8539 | if (value == 0) | |
8540 | shift = SHIFT_LSL; | |
8541 | else if (value == 32) | |
8542 | value = 0; | |
8543 | ||
8544 | inst.instruction |= shift << 4; | |
8545 | inst.instruction |= (value & 0x1c) << 10; | |
8546 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 8547 | } |
c19d1205 | 8548 | } |
b99bd4ef | 8549 | |
b99bd4ef | 8550 | |
c19d1205 ZW |
8551 | /* inst.operands[i] was set up by parse_address. Encode it into a |
8552 | Thumb32 format load or store instruction. Reject forms that cannot | |
8553 | be used with such instructions. If is_t is true, reject forms that | |
8554 | cannot be used with a T instruction; if is_d is true, reject forms | |
8555 | that cannot be used with a D instruction. */ | |
b99bd4ef | 8556 | |
c19d1205 ZW |
8557 | static void |
8558 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
8559 | { | |
8560 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
8561 | ||
8562 | constraint (!inst.operands[i].isreg, | |
53365c0d | 8563 | _("Instruction does not support =N addresses")); |
b99bd4ef | 8564 | |
c19d1205 ZW |
8565 | inst.instruction |= inst.operands[i].reg << 16; |
8566 | if (inst.operands[i].immisreg) | |
b99bd4ef | 8567 | { |
c19d1205 ZW |
8568 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
8569 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
8570 | constraint (inst.operands[i].negative, | |
8571 | _("Thumb does not support negative register indexing")); | |
8572 | constraint (inst.operands[i].postind, | |
8573 | _("Thumb does not support register post-indexing")); | |
8574 | constraint (inst.operands[i].writeback, | |
8575 | _("Thumb does not support register indexing with writeback")); | |
8576 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
8577 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 8578 | |
f40d1643 | 8579 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 8580 | if (inst.operands[i].shifted) |
b99bd4ef | 8581 | { |
c19d1205 ZW |
8582 | constraint (inst.reloc.exp.X_op != O_constant, |
8583 | _("expression too complex")); | |
9c3c69f2 PB |
8584 | constraint (inst.reloc.exp.X_add_number < 0 |
8585 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 8586 | _("shift out of range")); |
9c3c69f2 | 8587 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
8588 | } |
8589 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8590 | } | |
8591 | else if (inst.operands[i].preind) | |
8592 | { | |
8593 | constraint (is_pc && inst.operands[i].writeback, | |
8594 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 8595 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
8596 | _("cannot use writeback with this instruction")); |
8597 | ||
8598 | if (is_d) | |
8599 | { | |
8600 | inst.instruction |= 0x01000000; | |
8601 | if (inst.operands[i].writeback) | |
8602 | inst.instruction |= 0x00200000; | |
b99bd4ef | 8603 | } |
c19d1205 | 8604 | else |
b99bd4ef | 8605 | { |
c19d1205 ZW |
8606 | inst.instruction |= 0x00000c00; |
8607 | if (inst.operands[i].writeback) | |
8608 | inst.instruction |= 0x00000100; | |
b99bd4ef | 8609 | } |
c19d1205 | 8610 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 8611 | } |
c19d1205 | 8612 | else if (inst.operands[i].postind) |
b99bd4ef | 8613 | { |
9c2799c2 | 8614 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
8615 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
8616 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
8617 | ||
8618 | if (is_d) | |
8619 | inst.instruction |= 0x00200000; | |
8620 | else | |
8621 | inst.instruction |= 0x00000900; | |
8622 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
8623 | } | |
8624 | else /* unindexed - only for coprocessor */ | |
8625 | inst.error = _("instruction does not accept unindexed addressing"); | |
8626 | } | |
8627 | ||
8628 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
8629 | encodings (the latter only in post-V6T2 cores). The index is the | |
8630 | value used in the insns table below. When there is more than one | |
8631 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
8632 | holds variant (1). |
8633 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 ZW |
8634 | #define T16_32_TAB \ |
8635 | X(adc, 4140, eb400000), \ | |
8636 | X(adcs, 4140, eb500000), \ | |
8637 | X(add, 1c00, eb000000), \ | |
8638 | X(adds, 1c00, eb100000), \ | |
0110f2b8 PB |
8639 | X(addi, 0000, f1000000), \ |
8640 | X(addis, 0000, f1100000), \ | |
8641 | X(add_pc,000f, f20f0000), \ | |
8642 | X(add_sp,000d, f10d0000), \ | |
e9f89963 | 8643 | X(adr, 000f, f20f0000), \ |
c19d1205 ZW |
8644 | X(and, 4000, ea000000), \ |
8645 | X(ands, 4000, ea100000), \ | |
8646 | X(asr, 1000, fa40f000), \ | |
8647 | X(asrs, 1000, fa50f000), \ | |
0110f2b8 PB |
8648 | X(b, e000, f000b000), \ |
8649 | X(bcond, d000, f0008000), \ | |
c19d1205 ZW |
8650 | X(bic, 4380, ea200000), \ |
8651 | X(bics, 4380, ea300000), \ | |
8652 | X(cmn, 42c0, eb100f00), \ | |
8653 | X(cmp, 2800, ebb00f00), \ | |
8654 | X(cpsie, b660, f3af8400), \ | |
8655 | X(cpsid, b670, f3af8600), \ | |
8656 | X(cpy, 4600, ea4f0000), \ | |
155257ea | 8657 | X(dec_sp,80dd, f1ad0d00), \ |
c19d1205 ZW |
8658 | X(eor, 4040, ea800000), \ |
8659 | X(eors, 4040, ea900000), \ | |
0110f2b8 | 8660 | X(inc_sp,00dd, f10d0d00), \ |
c19d1205 ZW |
8661 | X(ldmia, c800, e8900000), \ |
8662 | X(ldr, 6800, f8500000), \ | |
8663 | X(ldrb, 7800, f8100000), \ | |
8664 | X(ldrh, 8800, f8300000), \ | |
8665 | X(ldrsb, 5600, f9100000), \ | |
8666 | X(ldrsh, 5e00, f9300000), \ | |
0110f2b8 PB |
8667 | X(ldr_pc,4800, f85f0000), \ |
8668 | X(ldr_pc2,4800, f85f0000), \ | |
8669 | X(ldr_sp,9800, f85d0000), \ | |
c19d1205 ZW |
8670 | X(lsl, 0000, fa00f000), \ |
8671 | X(lsls, 0000, fa10f000), \ | |
8672 | X(lsr, 0800, fa20f000), \ | |
8673 | X(lsrs, 0800, fa30f000), \ | |
8674 | X(mov, 2000, ea4f0000), \ | |
8675 | X(movs, 2000, ea5f0000), \ | |
8676 | X(mul, 4340, fb00f000), \ | |
8677 | X(muls, 4340, ffffffff), /* no 32b muls */ \ | |
8678 | X(mvn, 43c0, ea6f0000), \ | |
8679 | X(mvns, 43c0, ea7f0000), \ | |
8680 | X(neg, 4240, f1c00000), /* rsb #0 */ \ | |
8681 | X(negs, 4240, f1d00000), /* rsbs #0 */ \ | |
8682 | X(orr, 4300, ea400000), \ | |
8683 | X(orrs, 4300, ea500000), \ | |
e9f89963 PB |
8684 | X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \ |
8685 | X(push, b400, e92d0000), /* stmdb sp!,... */ \ | |
c19d1205 ZW |
8686 | X(rev, ba00, fa90f080), \ |
8687 | X(rev16, ba40, fa90f090), \ | |
8688 | X(revsh, bac0, fa90f0b0), \ | |
8689 | X(ror, 41c0, fa60f000), \ | |
8690 | X(rors, 41c0, fa70f000), \ | |
8691 | X(sbc, 4180, eb600000), \ | |
8692 | X(sbcs, 4180, eb700000), \ | |
8693 | X(stmia, c000, e8800000), \ | |
8694 | X(str, 6000, f8400000), \ | |
8695 | X(strb, 7000, f8000000), \ | |
8696 | X(strh, 8000, f8200000), \ | |
0110f2b8 | 8697 | X(str_sp,9000, f84d0000), \ |
c19d1205 ZW |
8698 | X(sub, 1e00, eba00000), \ |
8699 | X(subs, 1e00, ebb00000), \ | |
0110f2b8 PB |
8700 | X(subi, 8000, f1a00000), \ |
8701 | X(subis, 8000, f1b00000), \ | |
c19d1205 ZW |
8702 | X(sxtb, b240, fa4ff080), \ |
8703 | X(sxth, b200, fa0ff080), \ | |
8704 | X(tst, 4200, ea100f00), \ | |
8705 | X(uxtb, b2c0, fa5ff080), \ | |
8706 | X(uxth, b280, fa1ff080), \ | |
8707 | X(nop, bf00, f3af8000), \ | |
8708 | X(yield, bf10, f3af8001), \ | |
8709 | X(wfe, bf20, f3af8002), \ | |
8710 | X(wfi, bf30, f3af8003), \ | |
c921be7d | 8711 | X(sev, bf40, f3af8004), |
c19d1205 ZW |
8712 | |
8713 | /* To catch errors in encoding functions, the codes are all offset by | |
8714 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
8715 | as 16-bit instructions. */ | |
8716 | #define X(a,b,c) T_MNEM_##a | |
8717 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; | |
8718 | #undef X | |
8719 | ||
8720 | #define X(a,b,c) 0x##b | |
8721 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
8722 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
8723 | #undef X | |
8724 | ||
8725 | #define X(a,b,c) 0x##c | |
8726 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
8727 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
8728 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
8729 | #undef X |
8730 | #undef T16_32_TAB | |
8731 | ||
8732 | /* Thumb instruction encoders, in alphabetical order. */ | |
8733 | ||
92e90b6e | 8734 | /* ADDW or SUBW. */ |
c921be7d | 8735 | |
92e90b6e PB |
8736 | static void |
8737 | do_t_add_sub_w (void) | |
8738 | { | |
8739 | int Rd, Rn; | |
8740 | ||
8741 | Rd = inst.operands[0].reg; | |
8742 | Rn = inst.operands[1].reg; | |
8743 | ||
fdfde340 JM |
8744 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the |
8745 | SP-{plus,minute}-immediate form of the instruction. */ | |
8746 | reject_bad_reg (Rd); | |
8747 | ||
92e90b6e PB |
8748 | inst.instruction |= (Rn << 16) | (Rd << 8); |
8749 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8750 | } | |
8751 | ||
c19d1205 ZW |
8752 | /* Parse an add or subtract instruction. We get here with inst.instruction |
8753 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
8754 | ||
8755 | static void | |
8756 | do_t_add_sub (void) | |
8757 | { | |
8758 | int Rd, Rs, Rn; | |
8759 | ||
8760 | Rd = inst.operands[0].reg; | |
8761 | Rs = (inst.operands[1].present | |
8762 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
8763 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
8764 | ||
e07e6e58 NC |
8765 | if (Rd == REG_PC) |
8766 | set_it_insn_type_last (); | |
8767 | ||
c19d1205 ZW |
8768 | if (unified_syntax) |
8769 | { | |
0110f2b8 PB |
8770 | bfd_boolean flags; |
8771 | bfd_boolean narrow; | |
8772 | int opcode; | |
8773 | ||
8774 | flags = (inst.instruction == T_MNEM_adds | |
8775 | || inst.instruction == T_MNEM_subs); | |
8776 | if (flags) | |
e07e6e58 | 8777 | narrow = !in_it_block (); |
0110f2b8 | 8778 | else |
e07e6e58 | 8779 | narrow = in_it_block (); |
c19d1205 | 8780 | if (!inst.operands[2].isreg) |
b99bd4ef | 8781 | { |
16805f35 PB |
8782 | int add; |
8783 | ||
fdfde340 JM |
8784 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
8785 | ||
16805f35 PB |
8786 | add = (inst.instruction == T_MNEM_add |
8787 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
8788 | opcode = 0; |
8789 | if (inst.size_req != 4) | |
8790 | { | |
0110f2b8 PB |
8791 | /* Attempt to use a narrow opcode, with relaxation if |
8792 | appropriate. */ | |
8793 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
8794 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
8795 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
8796 | opcode = T_MNEM_add_sp; | |
8797 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
8798 | opcode = T_MNEM_add_pc; | |
8799 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
8800 | { | |
8801 | if (flags) | |
8802 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
8803 | else | |
8804 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
8805 | } | |
8806 | if (opcode) | |
8807 | { | |
8808 | inst.instruction = THUMB_OP16(opcode); | |
8809 | inst.instruction |= (Rd << 4) | Rs; | |
8810 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8811 | if (inst.size_req != 2) | |
8812 | inst.relax = opcode; | |
8813 | } | |
8814 | else | |
8815 | constraint (inst.size_req == 2, BAD_HIREG); | |
8816 | } | |
8817 | if (inst.size_req == 4 | |
8818 | || (inst.size_req != 2 && !opcode)) | |
8819 | { | |
efd81785 PB |
8820 | if (Rd == REG_PC) |
8821 | { | |
fdfde340 | 8822 | constraint (add, BAD_PC); |
efd81785 PB |
8823 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
8824 | _("only SUBS PC, LR, #const allowed")); | |
8825 | constraint (inst.reloc.exp.X_op != O_constant, | |
8826 | _("expression too complex")); | |
8827 | constraint (inst.reloc.exp.X_add_number < 0 | |
8828 | || inst.reloc.exp.X_add_number > 0xff, | |
8829 | _("immediate value out of range")); | |
8830 | inst.instruction = T2_SUBS_PC_LR | |
8831 | | inst.reloc.exp.X_add_number; | |
8832 | inst.reloc.type = BFD_RELOC_UNUSED; | |
8833 | return; | |
8834 | } | |
8835 | else if (Rs == REG_PC) | |
16805f35 PB |
8836 | { |
8837 | /* Always use addw/subw. */ | |
8838 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
8839 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
8840 | } | |
8841 | else | |
8842 | { | |
8843 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8844 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
8845 | | 0x10000000; | |
8846 | if (flags) | |
8847 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
8848 | else | |
8849 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
8850 | } | |
dc4503c6 PB |
8851 | inst.instruction |= Rd << 8; |
8852 | inst.instruction |= Rs << 16; | |
0110f2b8 | 8853 | } |
b99bd4ef | 8854 | } |
c19d1205 ZW |
8855 | else |
8856 | { | |
8857 | Rn = inst.operands[2].reg; | |
8858 | /* See if we can do this with a 16-bit instruction. */ | |
8859 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
8860 | { | |
e27ec89e PB |
8861 | if (Rd > 7 || Rs > 7 || Rn > 7) |
8862 | narrow = FALSE; | |
8863 | ||
8864 | if (narrow) | |
c19d1205 | 8865 | { |
e27ec89e PB |
8866 | inst.instruction = ((inst.instruction == T_MNEM_adds |
8867 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
8868 | ? T_OPCODE_ADD_R3 |
8869 | : T_OPCODE_SUB_R3); | |
8870 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
8871 | return; | |
8872 | } | |
b99bd4ef | 8873 | |
7e806470 | 8874 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 8875 | { |
7e806470 PB |
8876 | /* Thumb-1 cores (except v6-M) require at least one high |
8877 | register in a narrow non flag setting add. */ | |
8878 | if (Rd > 7 || Rn > 7 | |
8879 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
8880 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 8881 | { |
7e806470 PB |
8882 | if (Rd == Rn) |
8883 | { | |
8884 | Rn = Rs; | |
8885 | Rs = Rd; | |
8886 | } | |
c19d1205 ZW |
8887 | inst.instruction = T_OPCODE_ADD_HI; |
8888 | inst.instruction |= (Rd & 8) << 4; | |
8889 | inst.instruction |= (Rd & 7); | |
8890 | inst.instruction |= Rn << 3; | |
8891 | return; | |
8892 | } | |
c19d1205 ZW |
8893 | } |
8894 | } | |
c921be7d | 8895 | |
fdfde340 JM |
8896 | constraint (Rd == REG_PC, BAD_PC); |
8897 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
8898 | constraint (Rs == REG_PC, BAD_PC); | |
8899 | reject_bad_reg (Rn); | |
8900 | ||
c19d1205 ZW |
8901 | /* If we get here, it can't be done in 16 bits. */ |
8902 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
8903 | _("shift must be constant")); | |
8904 | inst.instruction = THUMB_OP32 (inst.instruction); | |
8905 | inst.instruction |= Rd << 8; | |
8906 | inst.instruction |= Rs << 16; | |
8907 | encode_thumb32_shifted_operand (2); | |
8908 | } | |
8909 | } | |
8910 | else | |
8911 | { | |
8912 | constraint (inst.instruction == T_MNEM_adds | |
8913 | || inst.instruction == T_MNEM_subs, | |
8914 | BAD_THUMB32); | |
b99bd4ef | 8915 | |
c19d1205 | 8916 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 8917 | { |
c19d1205 ZW |
8918 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
8919 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
8920 | BAD_HIREG); | |
8921 | ||
8922 | inst.instruction = (inst.instruction == T_MNEM_add | |
8923 | ? 0x0000 : 0x8000); | |
8924 | inst.instruction |= (Rd << 4) | Rs; | |
8925 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
8926 | return; |
8927 | } | |
8928 | ||
c19d1205 ZW |
8929 | Rn = inst.operands[2].reg; |
8930 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 8931 | |
c19d1205 ZW |
8932 | /* We now have Rd, Rs, and Rn set to registers. */ |
8933 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 8934 | { |
c19d1205 ZW |
8935 | /* Can't do this for SUB. */ |
8936 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
8937 | inst.instruction = T_OPCODE_ADD_HI; | |
8938 | inst.instruction |= (Rd & 8) << 4; | |
8939 | inst.instruction |= (Rd & 7); | |
8940 | if (Rs == Rd) | |
8941 | inst.instruction |= Rn << 3; | |
8942 | else if (Rn == Rd) | |
8943 | inst.instruction |= Rs << 3; | |
8944 | else | |
8945 | constraint (1, _("dest must overlap one source register")); | |
8946 | } | |
8947 | else | |
8948 | { | |
8949 | inst.instruction = (inst.instruction == T_MNEM_add | |
8950 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
8951 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 8952 | } |
b99bd4ef | 8953 | } |
b99bd4ef NC |
8954 | } |
8955 | ||
c19d1205 ZW |
8956 | static void |
8957 | do_t_adr (void) | |
8958 | { | |
fdfde340 JM |
8959 | unsigned Rd; |
8960 | ||
8961 | Rd = inst.operands[0].reg; | |
8962 | reject_bad_reg (Rd); | |
8963 | ||
8964 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
8965 | { |
8966 | /* Defer to section relaxation. */ | |
8967 | inst.relax = inst.instruction; | |
8968 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 8969 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
8970 | } |
8971 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 8972 | { |
0110f2b8 | 8973 | /* Generate a 32-bit opcode. */ |
e9f89963 | 8974 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 8975 | inst.instruction |= Rd << 8; |
e9f89963 PB |
8976 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
8977 | inst.reloc.pc_rel = 1; | |
8978 | } | |
8979 | else | |
8980 | { | |
0110f2b8 | 8981 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
8982 | inst.instruction = THUMB_OP16 (inst.instruction); |
8983 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
8984 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
8985 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 8986 | |
fdfde340 | 8987 | inst.instruction |= Rd << 4; |
e9f89963 | 8988 | } |
c19d1205 | 8989 | } |
b99bd4ef | 8990 | |
c19d1205 ZW |
8991 | /* Arithmetic instructions for which there is just one 16-bit |
8992 | instruction encoding, and it allows only two low registers. | |
8993 | For maximal compatibility with ARM syntax, we allow three register | |
8994 | operands even when Thumb-32 instructions are not available, as long | |
8995 | as the first two are identical. For instance, both "sbc r0,r1" and | |
8996 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 8997 | static void |
c19d1205 | 8998 | do_t_arit3 (void) |
b99bd4ef | 8999 | { |
c19d1205 | 9000 | int Rd, Rs, Rn; |
b99bd4ef | 9001 | |
c19d1205 ZW |
9002 | Rd = inst.operands[0].reg; |
9003 | Rs = (inst.operands[1].present | |
9004 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
9005 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
9006 | Rn = inst.operands[2].reg; | |
b99bd4ef | 9007 | |
fdfde340 JM |
9008 | reject_bad_reg (Rd); |
9009 | reject_bad_reg (Rs); | |
9010 | if (inst.operands[2].isreg) | |
9011 | reject_bad_reg (Rn); | |
9012 | ||
c19d1205 | 9013 | if (unified_syntax) |
b99bd4ef | 9014 | { |
c19d1205 ZW |
9015 | if (!inst.operands[2].isreg) |
9016 | { | |
9017 | /* For an immediate, we always generate a 32-bit opcode; | |
9018 | section relaxation will shrink it later if possible. */ | |
9019 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9020 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
9021 | inst.instruction |= Rd << 8; | |
9022 | inst.instruction |= Rs << 16; | |
9023 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
9024 | } | |
9025 | else | |
9026 | { | |
e27ec89e PB |
9027 | bfd_boolean narrow; |
9028 | ||
c19d1205 | 9029 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 9030 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 9031 | narrow = !in_it_block (); |
e27ec89e | 9032 | else |
e07e6e58 | 9033 | narrow = in_it_block (); |
e27ec89e PB |
9034 | |
9035 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
9036 | narrow = FALSE; | |
9037 | if (inst.operands[2].shifted) | |
9038 | narrow = FALSE; | |
9039 | if (inst.size_req == 4) | |
9040 | narrow = FALSE; | |
9041 | ||
9042 | if (narrow | |
c19d1205 ZW |
9043 | && Rd == Rs) |
9044 | { | |
9045 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9046 | inst.instruction |= Rd; | |
9047 | inst.instruction |= Rn << 3; | |
9048 | return; | |
9049 | } | |
b99bd4ef | 9050 | |
c19d1205 ZW |
9051 | /* If we get here, it can't be done in 16 bits. */ |
9052 | constraint (inst.operands[2].shifted | |
9053 | && inst.operands[2].immisreg, | |
9054 | _("shift must be constant")); | |
9055 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9056 | inst.instruction |= Rd << 8; | |
9057 | inst.instruction |= Rs << 16; | |
9058 | encode_thumb32_shifted_operand (2); | |
9059 | } | |
a737bd4d | 9060 | } |
c19d1205 | 9061 | else |
b99bd4ef | 9062 | { |
c19d1205 ZW |
9063 | /* On its face this is a lie - the instruction does set the |
9064 | flags. However, the only supported mnemonic in this mode | |
9065 | says it doesn't. */ | |
9066 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9067 | |
c19d1205 ZW |
9068 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9069 | _("unshifted register required")); | |
9070 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9071 | constraint (Rd != Rs, | |
9072 | _("dest and source1 must be the same register")); | |
a737bd4d | 9073 | |
c19d1205 ZW |
9074 | inst.instruction = THUMB_OP16 (inst.instruction); |
9075 | inst.instruction |= Rd; | |
9076 | inst.instruction |= Rn << 3; | |
b99bd4ef | 9077 | } |
a737bd4d | 9078 | } |
b99bd4ef | 9079 | |
c19d1205 ZW |
9080 | /* Similarly, but for instructions where the arithmetic operation is |
9081 | commutative, so we can allow either of them to be different from | |
9082 | the destination operand in a 16-bit instruction. For instance, all | |
9083 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
9084 | accepted. */ | |
9085 | static void | |
9086 | do_t_arit3c (void) | |
a737bd4d | 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; | |
c921be7d | 9095 | |
fdfde340 JM |
9096 | reject_bad_reg (Rd); |
9097 | reject_bad_reg (Rs); | |
9098 | if (inst.operands[2].isreg) | |
9099 | reject_bad_reg (Rn); | |
a737bd4d | 9100 | |
c19d1205 | 9101 | if (unified_syntax) |
a737bd4d | 9102 | { |
c19d1205 | 9103 | if (!inst.operands[2].isreg) |
b99bd4ef | 9104 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 9112 | } |
c19d1205 | 9113 | else |
a737bd4d | 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) | |
a737bd4d | 9131 | { |
c19d1205 | 9132 | if (Rd == Rs) |
a737bd4d | 9133 | { |
c19d1205 ZW |
9134 | inst.instruction = THUMB_OP16 (inst.instruction); |
9135 | inst.instruction |= Rd; | |
9136 | inst.instruction |= Rn << 3; | |
9137 | return; | |
a737bd4d | 9138 | } |
c19d1205 | 9139 | if (Rd == Rn) |
a737bd4d | 9140 | { |
c19d1205 ZW |
9141 | inst.instruction = THUMB_OP16 (inst.instruction); |
9142 | inst.instruction |= Rd; | |
9143 | inst.instruction |= Rs << 3; | |
9144 | return; | |
a737bd4d NC |
9145 | } |
9146 | } | |
c19d1205 ZW |
9147 | |
9148 | /* If we get here, it can't be done in 16 bits. */ | |
9149 | constraint (inst.operands[2].shifted | |
9150 | && inst.operands[2].immisreg, | |
9151 | _("shift must be constant")); | |
9152 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9153 | inst.instruction |= Rd << 8; | |
9154 | inst.instruction |= Rs << 16; | |
9155 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 9156 | } |
b99bd4ef | 9157 | } |
c19d1205 ZW |
9158 | else |
9159 | { | |
9160 | /* On its face this is a lie - the instruction does set the | |
9161 | flags. However, the only supported mnemonic in this mode | |
9162 | says it doesn't. */ | |
9163 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 9164 | |
c19d1205 ZW |
9165 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
9166 | _("unshifted register required")); | |
9167 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
9168 | ||
9169 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9170 | inst.instruction |= Rd; | |
9171 | ||
9172 | if (Rd == Rs) | |
9173 | inst.instruction |= Rn << 3; | |
9174 | else if (Rd == Rn) | |
9175 | inst.instruction |= Rs << 3; | |
9176 | else | |
9177 | constraint (1, _("dest must overlap one source register")); | |
9178 | } | |
a737bd4d NC |
9179 | } |
9180 | ||
62b3e311 PB |
9181 | static void |
9182 | do_t_barrier (void) | |
9183 | { | |
9184 | if (inst.operands[0].present) | |
9185 | { | |
9186 | constraint ((inst.instruction & 0xf0) != 0x40 | |
9187 | && inst.operands[0].imm != 0xf, | |
bd3ba5d1 | 9188 | _("bad barrier type")); |
62b3e311 PB |
9189 | inst.instruction |= inst.operands[0].imm; |
9190 | } | |
9191 | else | |
9192 | inst.instruction |= 0xf; | |
9193 | } | |
9194 | ||
c19d1205 ZW |
9195 | static void |
9196 | do_t_bfc (void) | |
a737bd4d | 9197 | { |
fdfde340 | 9198 | unsigned Rd; |
c19d1205 ZW |
9199 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
9200 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9201 | /* The instruction encoding stores the LSB and MSB, | |
9202 | not the LSB and width. */ | |
fdfde340 JM |
9203 | Rd = inst.operands[0].reg; |
9204 | reject_bad_reg (Rd); | |
9205 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
9206 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
9207 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
9208 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9209 | } |
9210 | ||
c19d1205 ZW |
9211 | static void |
9212 | do_t_bfi (void) | |
b99bd4ef | 9213 | { |
fdfde340 | 9214 | int Rd, Rn; |
c19d1205 | 9215 | unsigned int msb; |
b99bd4ef | 9216 | |
fdfde340 JM |
9217 | Rd = inst.operands[0].reg; |
9218 | reject_bad_reg (Rd); | |
9219 | ||
c19d1205 ZW |
9220 | /* #0 in second position is alternative syntax for bfc, which is |
9221 | the same instruction but with REG_PC in the Rm field. */ | |
9222 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
9223 | Rn = REG_PC; |
9224 | else | |
9225 | { | |
9226 | Rn = inst.operands[1].reg; | |
9227 | reject_bad_reg (Rn); | |
9228 | } | |
b99bd4ef | 9229 | |
c19d1205 ZW |
9230 | msb = inst.operands[2].imm + inst.operands[3].imm; |
9231 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9232 | /* The instruction encoding stores the LSB and MSB, | |
9233 | not the LSB and width. */ | |
fdfde340 JM |
9234 | inst.instruction |= Rd << 8; |
9235 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9236 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9237 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9238 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
9239 | } |
9240 | ||
c19d1205 ZW |
9241 | static void |
9242 | do_t_bfx (void) | |
b99bd4ef | 9243 | { |
fdfde340 JM |
9244 | unsigned Rd, Rn; |
9245 | ||
9246 | Rd = inst.operands[0].reg; | |
9247 | Rn = inst.operands[1].reg; | |
9248 | ||
9249 | reject_bad_reg (Rd); | |
9250 | reject_bad_reg (Rn); | |
9251 | ||
c19d1205 ZW |
9252 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
9253 | _("bit-field extends past end of register")); | |
fdfde340 JM |
9254 | inst.instruction |= Rd << 8; |
9255 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
9256 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
9257 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
9258 | inst.instruction |= inst.operands[3].imm - 1; | |
9259 | } | |
b99bd4ef | 9260 | |
c19d1205 ZW |
9261 | /* ARM V5 Thumb BLX (argument parse) |
9262 | BLX <target_addr> which is BLX(1) | |
9263 | BLX <Rm> which is BLX(2) | |
9264 | Unfortunately, there are two different opcodes for this mnemonic. | |
9265 | So, the insns[].value is not used, and the code here zaps values | |
9266 | into inst.instruction. | |
b99bd4ef | 9267 | |
c19d1205 ZW |
9268 | ??? How to take advantage of the additional two bits of displacement |
9269 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 9270 | |
c19d1205 ZW |
9271 | static void |
9272 | do_t_blx (void) | |
9273 | { | |
e07e6e58 NC |
9274 | set_it_insn_type_last (); |
9275 | ||
c19d1205 | 9276 | if (inst.operands[0].isreg) |
fdfde340 JM |
9277 | { |
9278 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
9279 | /* We have a register, so this is BLX(2). */ | |
9280 | inst.instruction |= inst.operands[0].reg << 3; | |
9281 | } | |
b99bd4ef NC |
9282 | else |
9283 | { | |
c19d1205 | 9284 | /* No register. This must be BLX(1). */ |
2fc8bdac | 9285 | inst.instruction = 0xf000e800; |
00adf2d4 | 9286 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; |
c19d1205 | 9287 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
9288 | } |
9289 | } | |
9290 | ||
c19d1205 ZW |
9291 | static void |
9292 | do_t_branch (void) | |
b99bd4ef | 9293 | { |
0110f2b8 | 9294 | int opcode; |
dfa9f0d5 PB |
9295 | int cond; |
9296 | ||
e07e6e58 NC |
9297 | cond = inst.cond; |
9298 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
9299 | ||
9300 | if (in_it_block ()) | |
dfa9f0d5 PB |
9301 | { |
9302 | /* Conditional branches inside IT blocks are encoded as unconditional | |
9303 | branches. */ | |
9304 | cond = COND_ALWAYS; | |
dfa9f0d5 PB |
9305 | } |
9306 | else | |
9307 | cond = inst.cond; | |
9308 | ||
9309 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
9310 | opcode = T_MNEM_bcond; |
9311 | else | |
9312 | opcode = inst.instruction; | |
9313 | ||
9314 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 9315 | { |
0110f2b8 | 9316 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 9317 | if (cond == COND_ALWAYS) |
0110f2b8 | 9318 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
9319 | else |
9320 | { | |
9c2799c2 | 9321 | gas_assert (cond != 0xF); |
dfa9f0d5 | 9322 | inst.instruction |= cond << 22; |
c19d1205 ZW |
9323 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
9324 | } | |
9325 | } | |
b99bd4ef NC |
9326 | else |
9327 | { | |
0110f2b8 | 9328 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 9329 | if (cond == COND_ALWAYS) |
c19d1205 ZW |
9330 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; |
9331 | else | |
b99bd4ef | 9332 | { |
dfa9f0d5 | 9333 | inst.instruction |= cond << 8; |
c19d1205 | 9334 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 9335 | } |
0110f2b8 PB |
9336 | /* Allow section relaxation. */ |
9337 | if (unified_syntax && inst.size_req != 2) | |
9338 | inst.relax = opcode; | |
b99bd4ef | 9339 | } |
c19d1205 ZW |
9340 | |
9341 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
9342 | } |
9343 | ||
9344 | static void | |
c19d1205 | 9345 | do_t_bkpt (void) |
b99bd4ef | 9346 | { |
dfa9f0d5 PB |
9347 | constraint (inst.cond != COND_ALWAYS, |
9348 | _("instruction is always unconditional")); | |
c19d1205 | 9349 | if (inst.operands[0].present) |
b99bd4ef | 9350 | { |
c19d1205 ZW |
9351 | constraint (inst.operands[0].imm > 255, |
9352 | _("immediate value out of range")); | |
9353 | inst.instruction |= inst.operands[0].imm; | |
e07e6e58 | 9354 | set_it_insn_type (NEUTRAL_IT_INSN); |
b99bd4ef | 9355 | } |
b99bd4ef NC |
9356 | } |
9357 | ||
9358 | static void | |
c19d1205 | 9359 | do_t_branch23 (void) |
b99bd4ef | 9360 | { |
e07e6e58 | 9361 | set_it_insn_type_last (); |
c19d1205 | 9362 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
9363 | inst.reloc.pc_rel = 1; |
9364 | ||
4343666d | 9365 | #if defined(OBJ_COFF) |
c19d1205 ZW |
9366 | /* If the destination of the branch is a defined symbol which does not have |
9367 | the THUMB_FUNC attribute, then we must be calling a function which has | |
9368 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
9369 | function and change the branch to refer to that function instead. */ | |
9370 | if ( inst.reloc.exp.X_op == O_symbol | |
9371 | && inst.reloc.exp.X_add_symbol != NULL | |
9372 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
9373 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
9374 | inst.reloc.exp.X_add_symbol = | |
9375 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 9376 | #endif |
90e4755a RE |
9377 | } |
9378 | ||
9379 | static void | |
c19d1205 | 9380 | do_t_bx (void) |
90e4755a | 9381 | { |
e07e6e58 | 9382 | set_it_insn_type_last (); |
c19d1205 ZW |
9383 | inst.instruction |= inst.operands[0].reg << 3; |
9384 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
9385 | should cause the alignment to be checked once it is known. This is | |
9386 | because BX PC only works if the instruction is word aligned. */ | |
9387 | } | |
90e4755a | 9388 | |
c19d1205 ZW |
9389 | static void |
9390 | do_t_bxj (void) | |
9391 | { | |
fdfde340 | 9392 | int Rm; |
90e4755a | 9393 | |
e07e6e58 | 9394 | set_it_insn_type_last (); |
fdfde340 JM |
9395 | Rm = inst.operands[0].reg; |
9396 | reject_bad_reg (Rm); | |
9397 | inst.instruction |= Rm << 16; | |
90e4755a RE |
9398 | } |
9399 | ||
9400 | static void | |
c19d1205 | 9401 | do_t_clz (void) |
90e4755a | 9402 | { |
fdfde340 JM |
9403 | unsigned Rd; |
9404 | unsigned Rm; | |
9405 | ||
9406 | Rd = inst.operands[0].reg; | |
9407 | Rm = inst.operands[1].reg; | |
9408 | ||
9409 | reject_bad_reg (Rd); | |
9410 | reject_bad_reg (Rm); | |
9411 | ||
9412 | inst.instruction |= Rd << 8; | |
9413 | inst.instruction |= Rm << 16; | |
9414 | inst.instruction |= Rm; | |
c19d1205 | 9415 | } |
90e4755a | 9416 | |
dfa9f0d5 PB |
9417 | static void |
9418 | do_t_cps (void) | |
9419 | { | |
e07e6e58 | 9420 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
9421 | inst.instruction |= inst.operands[0].imm; |
9422 | } | |
9423 | ||
c19d1205 ZW |
9424 | static void |
9425 | do_t_cpsi (void) | |
9426 | { | |
e07e6e58 | 9427 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 9428 | if (unified_syntax |
62b3e311 PB |
9429 | && (inst.operands[1].present || inst.size_req == 4) |
9430 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 9431 | { |
c19d1205 ZW |
9432 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
9433 | inst.instruction = 0xf3af8000; | |
9434 | inst.instruction |= imod << 9; | |
9435 | inst.instruction |= inst.operands[0].imm << 5; | |
9436 | if (inst.operands[1].present) | |
9437 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 9438 | } |
c19d1205 | 9439 | else |
90e4755a | 9440 | { |
62b3e311 PB |
9441 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
9442 | && (inst.operands[0].imm & 4), | |
9443 | _("selected processor does not support 'A' form " | |
9444 | "of this instruction")); | |
9445 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
9446 | _("Thumb does not support the 2-argument " |
9447 | "form of this instruction")); | |
9448 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 9449 | } |
90e4755a RE |
9450 | } |
9451 | ||
c19d1205 ZW |
9452 | /* THUMB CPY instruction (argument parse). */ |
9453 | ||
90e4755a | 9454 | static void |
c19d1205 | 9455 | do_t_cpy (void) |
90e4755a | 9456 | { |
c19d1205 | 9457 | if (inst.size_req == 4) |
90e4755a | 9458 | { |
c19d1205 ZW |
9459 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
9460 | inst.instruction |= inst.operands[0].reg << 8; | |
9461 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 9462 | } |
c19d1205 | 9463 | else |
90e4755a | 9464 | { |
c19d1205 ZW |
9465 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
9466 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
9467 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 9468 | } |
90e4755a RE |
9469 | } |
9470 | ||
90e4755a | 9471 | static void |
25fe350b | 9472 | do_t_cbz (void) |
90e4755a | 9473 | { |
e07e6e58 | 9474 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
9475 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9476 | inst.instruction |= inst.operands[0].reg; | |
9477 | inst.reloc.pc_rel = 1; | |
9478 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
9479 | } | |
90e4755a | 9480 | |
62b3e311 PB |
9481 | static void |
9482 | do_t_dbg (void) | |
9483 | { | |
9484 | inst.instruction |= inst.operands[0].imm; | |
9485 | } | |
9486 | ||
9487 | static void | |
9488 | do_t_div (void) | |
9489 | { | |
fdfde340 JM |
9490 | unsigned Rd, Rn, Rm; |
9491 | ||
9492 | Rd = inst.operands[0].reg; | |
9493 | Rn = (inst.operands[1].present | |
9494 | ? inst.operands[1].reg : Rd); | |
9495 | Rm = inst.operands[2].reg; | |
9496 | ||
9497 | reject_bad_reg (Rd); | |
9498 | reject_bad_reg (Rn); | |
9499 | reject_bad_reg (Rm); | |
9500 | ||
9501 | inst.instruction |= Rd << 8; | |
9502 | inst.instruction |= Rn << 16; | |
9503 | inst.instruction |= Rm; | |
62b3e311 PB |
9504 | } |
9505 | ||
c19d1205 ZW |
9506 | static void |
9507 | do_t_hint (void) | |
9508 | { | |
9509 | if (unified_syntax && inst.size_req == 4) | |
9510 | inst.instruction = THUMB_OP32 (inst.instruction); | |
9511 | else | |
9512 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9513 | } | |
90e4755a | 9514 | |
c19d1205 ZW |
9515 | static void |
9516 | do_t_it (void) | |
9517 | { | |
9518 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 9519 | |
e07e6e58 NC |
9520 | set_it_insn_type (IT_INSN); |
9521 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
9522 | now_it.cc = cond; | |
e27ec89e PB |
9523 | |
9524 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 9525 | if ((cond & 0x1) == 0x0) |
90e4755a | 9526 | { |
c19d1205 | 9527 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 9528 | |
c19d1205 ZW |
9529 | if ((mask & 0x7) == 0) |
9530 | /* no conversion needed */; | |
9531 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
9532 | mask ^= 0x8; |
9533 | else if ((mask & 0x1) == 0) | |
9534 | mask ^= 0xC; | |
c19d1205 | 9535 | else |
e27ec89e | 9536 | mask ^= 0xE; |
90e4755a | 9537 | |
e27ec89e PB |
9538 | inst.instruction &= 0xfff0; |
9539 | inst.instruction |= mask; | |
c19d1205 | 9540 | } |
90e4755a | 9541 | |
c19d1205 ZW |
9542 | inst.instruction |= cond << 4; |
9543 | } | |
90e4755a | 9544 | |
3c707909 PB |
9545 | /* Helper function used for both push/pop and ldm/stm. */ |
9546 | static void | |
9547 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
9548 | { | |
9549 | bfd_boolean load; | |
9550 | ||
9551 | load = (inst.instruction & (1 << 20)) != 0; | |
9552 | ||
9553 | if (mask & (1 << 13)) | |
9554 | inst.error = _("SP not allowed in register list"); | |
9555 | if (load) | |
9556 | { | |
e07e6e58 NC |
9557 | if (mask & (1 << 15)) |
9558 | { | |
9559 | if (mask & (1 << 14)) | |
9560 | inst.error = _("LR and PC should not both be in register list"); | |
9561 | else | |
9562 | set_it_insn_type_last (); | |
9563 | } | |
3c707909 PB |
9564 | |
9565 | if ((mask & (1 << base)) != 0 | |
9566 | && writeback) | |
9567 | as_warn (_("base register should not be in register list " | |
9568 | "when written back")); | |
9569 | } | |
9570 | else | |
9571 | { | |
9572 | if (mask & (1 << 15)) | |
9573 | inst.error = _("PC not allowed in register list"); | |
9574 | ||
9575 | if (mask & (1 << base)) | |
9576 | as_warn (_("value stored for r%d is UNPREDICTABLE"), base); | |
9577 | } | |
9578 | ||
9579 | if ((mask & (mask - 1)) == 0) | |
9580 | { | |
9581 | /* Single register transfers implemented as str/ldr. */ | |
9582 | if (writeback) | |
9583 | { | |
9584 | if (inst.instruction & (1 << 23)) | |
9585 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
9586 | else | |
9587 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
9588 | } | |
9589 | else | |
9590 | { | |
9591 | if (inst.instruction & (1 << 23)) | |
9592 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
9593 | else | |
9594 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
9595 | } | |
9596 | ||
9597 | inst.instruction |= 0xf8400000; | |
9598 | if (load) | |
9599 | inst.instruction |= 0x00100000; | |
9600 | ||
5f4273c7 | 9601 | mask = ffs (mask) - 1; |
3c707909 PB |
9602 | mask <<= 12; |
9603 | } | |
9604 | else if (writeback) | |
9605 | inst.instruction |= WRITE_BACK; | |
9606 | ||
9607 | inst.instruction |= mask; | |
9608 | inst.instruction |= base << 16; | |
9609 | } | |
9610 | ||
c19d1205 ZW |
9611 | static void |
9612 | do_t_ldmstm (void) | |
9613 | { | |
9614 | /* This really doesn't seem worth it. */ | |
9615 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
9616 | _("expression too complex")); | |
9617 | constraint (inst.operands[1].writeback, | |
9618 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 9619 | |
c19d1205 ZW |
9620 | if (unified_syntax) |
9621 | { | |
3c707909 PB |
9622 | bfd_boolean narrow; |
9623 | unsigned mask; | |
9624 | ||
9625 | narrow = FALSE; | |
c19d1205 ZW |
9626 | /* See if we can use a 16-bit instruction. */ |
9627 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
9628 | && inst.size_req != 4 | |
3c707909 | 9629 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 9630 | { |
3c707909 | 9631 | mask = 1 << inst.operands[0].reg; |
90e4755a | 9632 | |
3c707909 PB |
9633 | if (inst.operands[0].reg <= 7 |
9634 | && (inst.instruction == T_MNEM_stmia | |
9635 | ? inst.operands[0].writeback | |
9636 | : (inst.operands[0].writeback | |
9637 | == !(inst.operands[1].imm & mask)))) | |
90e4755a | 9638 | { |
3c707909 PB |
9639 | if (inst.instruction == T_MNEM_stmia |
9640 | && (inst.operands[1].imm & mask) | |
9641 | && (inst.operands[1].imm & (mask - 1))) | |
c19d1205 ZW |
9642 | as_warn (_("value stored for r%d is UNPREDICTABLE"), |
9643 | inst.operands[0].reg); | |
3c707909 PB |
9644 | |
9645 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9646 | inst.instruction |= inst.operands[0].reg << 8; | |
9647 | inst.instruction |= inst.operands[1].imm; | |
9648 | narrow = TRUE; | |
90e4755a | 9649 | } |
3c707909 PB |
9650 | else if (inst.operands[0] .reg == REG_SP |
9651 | && inst.operands[0].writeback) | |
90e4755a | 9652 | { |
3c707909 PB |
9653 | inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia |
9654 | ? T_MNEM_push : T_MNEM_pop); | |
9655 | inst.instruction |= inst.operands[1].imm; | |
9656 | narrow = TRUE; | |
90e4755a | 9657 | } |
3c707909 PB |
9658 | } |
9659 | ||
9660 | if (!narrow) | |
9661 | { | |
c19d1205 ZW |
9662 | if (inst.instruction < 0xffff) |
9663 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 9664 | |
5f4273c7 NC |
9665 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
9666 | inst.operands[0].writeback); | |
90e4755a RE |
9667 | } |
9668 | } | |
c19d1205 | 9669 | else |
90e4755a | 9670 | { |
c19d1205 ZW |
9671 | constraint (inst.operands[0].reg > 7 |
9672 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
9673 | constraint (inst.instruction != T_MNEM_ldmia |
9674 | && inst.instruction != T_MNEM_stmia, | |
9675 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 9676 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 9677 | { |
c19d1205 ZW |
9678 | if (!inst.operands[0].writeback) |
9679 | as_warn (_("this instruction will write back the base register")); | |
9680 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
9681 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
9682 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
9683 | inst.operands[0].reg); | |
f03698e6 | 9684 | } |
c19d1205 | 9685 | else |
90e4755a | 9686 | { |
c19d1205 ZW |
9687 | if (!inst.operands[0].writeback |
9688 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9689 | as_warn (_("this instruction will write back the base register")); | |
9690 | else if (inst.operands[0].writeback | |
9691 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
9692 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
9693 | } |
9694 | ||
c19d1205 ZW |
9695 | inst.instruction = THUMB_OP16 (inst.instruction); |
9696 | inst.instruction |= inst.operands[0].reg << 8; | |
9697 | inst.instruction |= inst.operands[1].imm; | |
9698 | } | |
9699 | } | |
e28cd48c | 9700 | |
c19d1205 ZW |
9701 | static void |
9702 | do_t_ldrex (void) | |
9703 | { | |
9704 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
9705 | || inst.operands[1].postind || inst.operands[1].writeback | |
9706 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
9707 | || inst.operands[1].negative, | |
01cfc07f | 9708 | BAD_ADDR_MODE); |
e28cd48c | 9709 | |
c19d1205 ZW |
9710 | inst.instruction |= inst.operands[0].reg << 12; |
9711 | inst.instruction |= inst.operands[1].reg << 16; | |
9712 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
9713 | } | |
e28cd48c | 9714 | |
c19d1205 ZW |
9715 | static void |
9716 | do_t_ldrexd (void) | |
9717 | { | |
9718 | if (!inst.operands[1].present) | |
1cac9012 | 9719 | { |
c19d1205 ZW |
9720 | constraint (inst.operands[0].reg == REG_LR, |
9721 | _("r14 not allowed as first register " | |
9722 | "when second register is omitted")); | |
9723 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 9724 | } |
c19d1205 ZW |
9725 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
9726 | BAD_OVERLAP); | |
b99bd4ef | 9727 | |
c19d1205 ZW |
9728 | inst.instruction |= inst.operands[0].reg << 12; |
9729 | inst.instruction |= inst.operands[1].reg << 8; | |
9730 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9731 | } |
9732 | ||
9733 | static void | |
c19d1205 | 9734 | do_t_ldst (void) |
b99bd4ef | 9735 | { |
0110f2b8 PB |
9736 | unsigned long opcode; |
9737 | int Rn; | |
9738 | ||
e07e6e58 NC |
9739 | if (inst.operands[0].isreg |
9740 | && !inst.operands[0].preind | |
9741 | && inst.operands[0].reg == REG_PC) | |
9742 | set_it_insn_type_last (); | |
9743 | ||
0110f2b8 | 9744 | opcode = inst.instruction; |
c19d1205 | 9745 | if (unified_syntax) |
b99bd4ef | 9746 | { |
53365c0d PB |
9747 | if (!inst.operands[1].isreg) |
9748 | { | |
9749 | if (opcode <= 0xffff) | |
9750 | inst.instruction = THUMB_OP32 (opcode); | |
9751 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9752 | return; | |
9753 | } | |
0110f2b8 PB |
9754 | if (inst.operands[1].isreg |
9755 | && !inst.operands[1].writeback | |
c19d1205 ZW |
9756 | && !inst.operands[1].shifted && !inst.operands[1].postind |
9757 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
9758 | && opcode <= 0xffff |
9759 | && inst.size_req != 4) | |
c19d1205 | 9760 | { |
0110f2b8 PB |
9761 | /* Insn may have a 16-bit form. */ |
9762 | Rn = inst.operands[1].reg; | |
9763 | if (inst.operands[1].immisreg) | |
9764 | { | |
9765 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 9766 | /* [Rn, Rik] */ |
0110f2b8 PB |
9767 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
9768 | goto op16; | |
9769 | } | |
9770 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
9771 | && opcode != T_MNEM_ldrsb) | |
9772 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
9773 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
9774 | { | |
9775 | /* [Rn, #const] */ | |
9776 | if (Rn > 7) | |
9777 | { | |
9778 | if (Rn == REG_PC) | |
9779 | { | |
9780 | if (inst.reloc.pc_rel) | |
9781 | opcode = T_MNEM_ldr_pc2; | |
9782 | else | |
9783 | opcode = T_MNEM_ldr_pc; | |
9784 | } | |
9785 | else | |
9786 | { | |
9787 | if (opcode == T_MNEM_ldr) | |
9788 | opcode = T_MNEM_ldr_sp; | |
9789 | else | |
9790 | opcode = T_MNEM_str_sp; | |
9791 | } | |
9792 | inst.instruction = inst.operands[0].reg << 8; | |
9793 | } | |
9794 | else | |
9795 | { | |
9796 | inst.instruction = inst.operands[0].reg; | |
9797 | inst.instruction |= inst.operands[1].reg << 3; | |
9798 | } | |
9799 | inst.instruction |= THUMB_OP16 (opcode); | |
9800 | if (inst.size_req == 2) | |
9801 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9802 | else | |
9803 | inst.relax = opcode; | |
9804 | return; | |
9805 | } | |
c19d1205 | 9806 | } |
0110f2b8 PB |
9807 | /* Definitely a 32-bit variant. */ |
9808 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
9809 | inst.instruction |= inst.operands[0].reg << 12; |
9810 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
9811 | return; |
9812 | } | |
9813 | ||
c19d1205 ZW |
9814 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
9815 | ||
9816 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 9817 | { |
c19d1205 ZW |
9818 | /* Only [Rn,Rm] is acceptable. */ |
9819 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
9820 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
9821 | || inst.operands[1].postind || inst.operands[1].shifted | |
9822 | || inst.operands[1].negative, | |
9823 | _("Thumb does not support this addressing mode")); | |
9824 | inst.instruction = THUMB_OP16 (inst.instruction); | |
9825 | goto op16; | |
b99bd4ef | 9826 | } |
5f4273c7 | 9827 | |
c19d1205 ZW |
9828 | inst.instruction = THUMB_OP16 (inst.instruction); |
9829 | if (!inst.operands[1].isreg) | |
9830 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
9831 | return; | |
b99bd4ef | 9832 | |
c19d1205 ZW |
9833 | constraint (!inst.operands[1].preind |
9834 | || inst.operands[1].shifted | |
9835 | || inst.operands[1].writeback, | |
9836 | _("Thumb does not support this addressing mode")); | |
9837 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 9838 | { |
c19d1205 ZW |
9839 | constraint (inst.instruction & 0x0600, |
9840 | _("byte or halfword not valid for base register")); | |
9841 | constraint (inst.operands[1].reg == REG_PC | |
9842 | && !(inst.instruction & THUMB_LOAD_BIT), | |
9843 | _("r15 based store not allowed")); | |
9844 | constraint (inst.operands[1].immisreg, | |
9845 | _("invalid base register for register offset")); | |
b99bd4ef | 9846 | |
c19d1205 ZW |
9847 | if (inst.operands[1].reg == REG_PC) |
9848 | inst.instruction = T_OPCODE_LDR_PC; | |
9849 | else if (inst.instruction & THUMB_LOAD_BIT) | |
9850 | inst.instruction = T_OPCODE_LDR_SP; | |
9851 | else | |
9852 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 9853 | |
c19d1205 ZW |
9854 | inst.instruction |= inst.operands[0].reg << 8; |
9855 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9856 | return; | |
9857 | } | |
90e4755a | 9858 | |
c19d1205 ZW |
9859 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
9860 | if (!inst.operands[1].immisreg) | |
9861 | { | |
9862 | /* Immediate offset. */ | |
9863 | inst.instruction |= inst.operands[0].reg; | |
9864 | inst.instruction |= inst.operands[1].reg << 3; | |
9865 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
9866 | return; | |
9867 | } | |
90e4755a | 9868 | |
c19d1205 ZW |
9869 | /* Register offset. */ |
9870 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
9871 | constraint (inst.operands[1].negative, | |
9872 | _("Thumb does not support this addressing mode")); | |
90e4755a | 9873 | |
c19d1205 ZW |
9874 | op16: |
9875 | switch (inst.instruction) | |
9876 | { | |
9877 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
9878 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
9879 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
9880 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
9881 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
9882 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
9883 | case 0x5600 /* ldrsb */: | |
9884 | case 0x5e00 /* ldrsh */: break; | |
9885 | default: abort (); | |
9886 | } | |
90e4755a | 9887 | |
c19d1205 ZW |
9888 | inst.instruction |= inst.operands[0].reg; |
9889 | inst.instruction |= inst.operands[1].reg << 3; | |
9890 | inst.instruction |= inst.operands[1].imm << 6; | |
9891 | } | |
90e4755a | 9892 | |
c19d1205 ZW |
9893 | static void |
9894 | do_t_ldstd (void) | |
9895 | { | |
9896 | if (!inst.operands[1].present) | |
b99bd4ef | 9897 | { |
c19d1205 ZW |
9898 | inst.operands[1].reg = inst.operands[0].reg + 1; |
9899 | constraint (inst.operands[0].reg == REG_LR, | |
9900 | _("r14 not allowed here")); | |
b99bd4ef | 9901 | } |
c19d1205 ZW |
9902 | inst.instruction |= inst.operands[0].reg << 12; |
9903 | inst.instruction |= inst.operands[1].reg << 8; | |
9904 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
9905 | } |
9906 | ||
c19d1205 ZW |
9907 | static void |
9908 | do_t_ldstt (void) | |
9909 | { | |
9910 | inst.instruction |= inst.operands[0].reg << 12; | |
9911 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
9912 | } | |
a737bd4d | 9913 | |
b99bd4ef | 9914 | static void |
c19d1205 | 9915 | do_t_mla (void) |
b99bd4ef | 9916 | { |
fdfde340 | 9917 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 9918 | |
fdfde340 JM |
9919 | Rd = inst.operands[0].reg; |
9920 | Rn = inst.operands[1].reg; | |
9921 | Rm = inst.operands[2].reg; | |
9922 | Ra = inst.operands[3].reg; | |
9923 | ||
9924 | reject_bad_reg (Rd); | |
9925 | reject_bad_reg (Rn); | |
9926 | reject_bad_reg (Rm); | |
9927 | reject_bad_reg (Ra); | |
9928 | ||
9929 | inst.instruction |= Rd << 8; | |
9930 | inst.instruction |= Rn << 16; | |
9931 | inst.instruction |= Rm; | |
9932 | inst.instruction |= Ra << 12; | |
c19d1205 | 9933 | } |
b99bd4ef | 9934 | |
c19d1205 ZW |
9935 | static void |
9936 | do_t_mlal (void) | |
9937 | { | |
fdfde340 JM |
9938 | unsigned RdLo, RdHi, Rn, Rm; |
9939 | ||
9940 | RdLo = inst.operands[0].reg; | |
9941 | RdHi = inst.operands[1].reg; | |
9942 | Rn = inst.operands[2].reg; | |
9943 | Rm = inst.operands[3].reg; | |
9944 | ||
9945 | reject_bad_reg (RdLo); | |
9946 | reject_bad_reg (RdHi); | |
9947 | reject_bad_reg (Rn); | |
9948 | reject_bad_reg (Rm); | |
9949 | ||
9950 | inst.instruction |= RdLo << 12; | |
9951 | inst.instruction |= RdHi << 8; | |
9952 | inst.instruction |= Rn << 16; | |
9953 | inst.instruction |= Rm; | |
c19d1205 | 9954 | } |
b99bd4ef | 9955 | |
c19d1205 ZW |
9956 | static void |
9957 | do_t_mov_cmp (void) | |
9958 | { | |
fdfde340 JM |
9959 | unsigned Rn, Rm; |
9960 | ||
9961 | Rn = inst.operands[0].reg; | |
9962 | Rm = inst.operands[1].reg; | |
9963 | ||
e07e6e58 NC |
9964 | if (Rn == REG_PC) |
9965 | set_it_insn_type_last (); | |
9966 | ||
c19d1205 | 9967 | if (unified_syntax) |
b99bd4ef | 9968 | { |
c19d1205 ZW |
9969 | int r0off = (inst.instruction == T_MNEM_mov |
9970 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 9971 | unsigned long opcode; |
3d388997 PB |
9972 | bfd_boolean narrow; |
9973 | bfd_boolean low_regs; | |
9974 | ||
fdfde340 | 9975 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 9976 | opcode = inst.instruction; |
e07e6e58 | 9977 | if (in_it_block ()) |
0110f2b8 | 9978 | narrow = opcode != T_MNEM_movs; |
3d388997 | 9979 | else |
0110f2b8 | 9980 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
9981 | if (inst.size_req == 4 |
9982 | || inst.operands[1].shifted) | |
9983 | narrow = FALSE; | |
9984 | ||
efd81785 PB |
9985 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
9986 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
9987 | && !inst.operands[1].shifted | |
fdfde340 JM |
9988 | && Rn == REG_PC |
9989 | && Rm == REG_LR) | |
efd81785 PB |
9990 | { |
9991 | inst.instruction = T2_SUBS_PC_LR; | |
9992 | return; | |
9993 | } | |
9994 | ||
fdfde340 JM |
9995 | if (opcode == T_MNEM_cmp) |
9996 | { | |
9997 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
9998 | if (narrow) |
9999 | { | |
10000 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
10001 | but valid. */ | |
10002 | warn_deprecated_sp (Rm); | |
10003 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
10004 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
10005 | tools reject R15, so we do too. */ | |
10006 | constraint (Rm == REG_PC, BAD_PC); | |
10007 | } | |
10008 | else | |
10009 | reject_bad_reg (Rm); | |
fdfde340 JM |
10010 | } |
10011 | else if (opcode == T_MNEM_mov | |
10012 | || opcode == T_MNEM_movs) | |
10013 | { | |
10014 | if (inst.operands[1].isreg) | |
10015 | { | |
10016 | if (opcode == T_MNEM_movs) | |
10017 | { | |
10018 | reject_bad_reg (Rn); | |
10019 | reject_bad_reg (Rm); | |
10020 | } | |
10021 | else if ((Rn == REG_SP || Rn == REG_PC) | |
10022 | && (Rm == REG_SP || Rm == REG_PC)) | |
10023 | reject_bad_reg (Rm); | |
10024 | } | |
10025 | else | |
10026 | reject_bad_reg (Rn); | |
10027 | } | |
10028 | ||
c19d1205 ZW |
10029 | if (!inst.operands[1].isreg) |
10030 | { | |
0110f2b8 | 10031 | /* Immediate operand. */ |
e07e6e58 | 10032 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
10033 | narrow = 0; |
10034 | if (low_regs && narrow) | |
10035 | { | |
10036 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 10037 | inst.instruction |= Rn << 8; |
0110f2b8 PB |
10038 | if (inst.size_req == 2) |
10039 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
10040 | else | |
10041 | inst.relax = opcode; | |
10042 | } | |
10043 | else | |
10044 | { | |
10045 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10046 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10047 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
10048 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
10049 | } | |
c19d1205 | 10050 | } |
728ca7c9 PB |
10051 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
10052 | && (inst.instruction == T_MNEM_mov | |
10053 | || inst.instruction == T_MNEM_movs)) | |
10054 | { | |
10055 | /* Register shifts are encoded as separate shift instructions. */ | |
10056 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
10057 | ||
e07e6e58 | 10058 | if (in_it_block ()) |
728ca7c9 PB |
10059 | narrow = !flags; |
10060 | else | |
10061 | narrow = flags; | |
10062 | ||
10063 | if (inst.size_req == 4) | |
10064 | narrow = FALSE; | |
10065 | ||
10066 | if (!low_regs || inst.operands[1].imm > 7) | |
10067 | narrow = FALSE; | |
10068 | ||
fdfde340 | 10069 | if (Rn != Rm) |
728ca7c9 PB |
10070 | narrow = FALSE; |
10071 | ||
10072 | switch (inst.operands[1].shift_kind) | |
10073 | { | |
10074 | case SHIFT_LSL: | |
10075 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
10076 | break; | |
10077 | case SHIFT_ASR: | |
10078 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
10079 | break; | |
10080 | case SHIFT_LSR: | |
10081 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
10082 | break; | |
10083 | case SHIFT_ROR: | |
10084 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
10085 | break; | |
10086 | default: | |
5f4273c7 | 10087 | abort (); |
728ca7c9 PB |
10088 | } |
10089 | ||
10090 | inst.instruction = opcode; | |
10091 | if (narrow) | |
10092 | { | |
fdfde340 | 10093 | inst.instruction |= Rn; |
728ca7c9 PB |
10094 | inst.instruction |= inst.operands[1].imm << 3; |
10095 | } | |
10096 | else | |
10097 | { | |
10098 | if (flags) | |
10099 | inst.instruction |= CONDS_BIT; | |
10100 | ||
fdfde340 JM |
10101 | inst.instruction |= Rn << 8; |
10102 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
10103 | inst.instruction |= inst.operands[1].imm; |
10104 | } | |
10105 | } | |
3d388997 | 10106 | else if (!narrow) |
c19d1205 | 10107 | { |
728ca7c9 PB |
10108 | /* Some mov with immediate shift have narrow variants. |
10109 | Register shifts are handled above. */ | |
10110 | if (low_regs && inst.operands[1].shifted | |
10111 | && (inst.instruction == T_MNEM_mov | |
10112 | || inst.instruction == T_MNEM_movs)) | |
10113 | { | |
e07e6e58 | 10114 | if (in_it_block ()) |
728ca7c9 PB |
10115 | narrow = (inst.instruction == T_MNEM_mov); |
10116 | else | |
10117 | narrow = (inst.instruction == T_MNEM_movs); | |
10118 | } | |
10119 | ||
10120 | if (narrow) | |
10121 | { | |
10122 | switch (inst.operands[1].shift_kind) | |
10123 | { | |
10124 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10125 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
10126 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
10127 | default: narrow = FALSE; break; | |
10128 | } | |
10129 | } | |
10130 | ||
10131 | if (narrow) | |
10132 | { | |
fdfde340 JM |
10133 | inst.instruction |= Rn; |
10134 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
10135 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10136 | } | |
10137 | else | |
10138 | { | |
10139 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10140 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
10141 | encode_thumb32_shifted_operand (1); |
10142 | } | |
c19d1205 ZW |
10143 | } |
10144 | else | |
10145 | switch (inst.instruction) | |
10146 | { | |
10147 | case T_MNEM_mov: | |
10148 | inst.instruction = T_OPCODE_MOV_HR; | |
fdfde340 JM |
10149 | inst.instruction |= (Rn & 0x8) << 4; |
10150 | inst.instruction |= (Rn & 0x7); | |
10151 | inst.instruction |= Rm << 3; | |
c19d1205 | 10152 | break; |
b99bd4ef | 10153 | |
c19d1205 ZW |
10154 | case T_MNEM_movs: |
10155 | /* We know we have low registers at this point. | |
10156 | Generate ADD Rd, Rs, #0. */ | |
10157 | inst.instruction = T_OPCODE_ADD_I3; | |
fdfde340 JM |
10158 | inst.instruction |= Rn; |
10159 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10160 | break; |
10161 | ||
10162 | case T_MNEM_cmp: | |
3d388997 | 10163 | if (low_regs) |
c19d1205 ZW |
10164 | { |
10165 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
10166 | inst.instruction |= Rn; |
10167 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10168 | } |
10169 | else | |
10170 | { | |
10171 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
10172 | inst.instruction |= (Rn & 0x8) << 4; |
10173 | inst.instruction |= (Rn & 0x7); | |
10174 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10175 | } |
10176 | break; | |
10177 | } | |
b99bd4ef NC |
10178 | return; |
10179 | } | |
10180 | ||
c19d1205 ZW |
10181 | inst.instruction = THUMB_OP16 (inst.instruction); |
10182 | if (inst.operands[1].isreg) | |
b99bd4ef | 10183 | { |
fdfde340 | 10184 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 10185 | { |
c19d1205 ZW |
10186 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
10187 | since a MOV instruction produces unpredictable results. */ | |
10188 | if (inst.instruction == T_OPCODE_MOV_I8) | |
10189 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 10190 | else |
c19d1205 | 10191 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 10192 | |
fdfde340 JM |
10193 | inst.instruction |= Rn; |
10194 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
10195 | } |
10196 | else | |
10197 | { | |
c19d1205 ZW |
10198 | if (inst.instruction == T_OPCODE_MOV_I8) |
10199 | inst.instruction = T_OPCODE_MOV_HR; | |
10200 | else | |
10201 | inst.instruction = T_OPCODE_CMP_HR; | |
10202 | do_t_cpy (); | |
b99bd4ef NC |
10203 | } |
10204 | } | |
c19d1205 | 10205 | else |
b99bd4ef | 10206 | { |
fdfde340 | 10207 | constraint (Rn > 7, |
c19d1205 | 10208 | _("only lo regs allowed with immediate")); |
fdfde340 | 10209 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
10210 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
10211 | } | |
10212 | } | |
b99bd4ef | 10213 | |
c19d1205 ZW |
10214 | static void |
10215 | do_t_mov16 (void) | |
10216 | { | |
fdfde340 | 10217 | unsigned Rd; |
b6895b4f PB |
10218 | bfd_vma imm; |
10219 | bfd_boolean top; | |
10220 | ||
10221 | top = (inst.instruction & 0x00800000) != 0; | |
10222 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
10223 | { | |
10224 | constraint (top, _(":lower16: not allowed this instruction")); | |
10225 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
10226 | } | |
10227 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
10228 | { | |
10229 | constraint (!top, _(":upper16: not allowed this instruction")); | |
10230 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
10231 | } | |
10232 | ||
fdfde340 JM |
10233 | Rd = inst.operands[0].reg; |
10234 | reject_bad_reg (Rd); | |
10235 | ||
10236 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
10237 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
10238 | { | |
10239 | imm = inst.reloc.exp.X_add_number; | |
10240 | inst.instruction |= (imm & 0xf000) << 4; | |
10241 | inst.instruction |= (imm & 0x0800) << 15; | |
10242 | inst.instruction |= (imm & 0x0700) << 4; | |
10243 | inst.instruction |= (imm & 0x00ff); | |
10244 | } | |
c19d1205 | 10245 | } |
b99bd4ef | 10246 | |
c19d1205 ZW |
10247 | static void |
10248 | do_t_mvn_tst (void) | |
10249 | { | |
fdfde340 | 10250 | unsigned Rn, Rm; |
c921be7d | 10251 | |
fdfde340 JM |
10252 | Rn = inst.operands[0].reg; |
10253 | Rm = inst.operands[1].reg; | |
10254 | ||
10255 | if (inst.instruction == T_MNEM_cmp | |
10256 | || inst.instruction == T_MNEM_cmn) | |
10257 | constraint (Rn == REG_PC, BAD_PC); | |
10258 | else | |
10259 | reject_bad_reg (Rn); | |
10260 | reject_bad_reg (Rm); | |
10261 | ||
c19d1205 ZW |
10262 | if (unified_syntax) |
10263 | { | |
10264 | int r0off = (inst.instruction == T_MNEM_mvn | |
10265 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
10266 | bfd_boolean narrow; |
10267 | ||
10268 | if (inst.size_req == 4 | |
10269 | || inst.instruction > 0xffff | |
10270 | || inst.operands[1].shifted | |
fdfde340 | 10271 | || Rn > 7 || Rm > 7) |
3d388997 PB |
10272 | narrow = FALSE; |
10273 | else if (inst.instruction == T_MNEM_cmn) | |
10274 | narrow = TRUE; | |
10275 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10276 | narrow = !in_it_block (); |
3d388997 | 10277 | else |
e07e6e58 | 10278 | narrow = in_it_block (); |
3d388997 | 10279 | |
c19d1205 | 10280 | if (!inst.operands[1].isreg) |
b99bd4ef | 10281 | { |
c19d1205 ZW |
10282 | /* For an immediate, we always generate a 32-bit opcode; |
10283 | section relaxation will shrink it later if possible. */ | |
10284 | if (inst.instruction < 0xffff) | |
10285 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10286 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 10287 | inst.instruction |= Rn << r0off; |
c19d1205 | 10288 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 10289 | } |
c19d1205 | 10290 | else |
b99bd4ef | 10291 | { |
c19d1205 | 10292 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 10293 | if (narrow) |
b99bd4ef | 10294 | { |
c19d1205 | 10295 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10296 | inst.instruction |= Rn; |
10297 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10298 | } |
c19d1205 | 10299 | else |
b99bd4ef | 10300 | { |
c19d1205 ZW |
10301 | constraint (inst.operands[1].shifted |
10302 | && inst.operands[1].immisreg, | |
10303 | _("shift must be constant")); | |
10304 | if (inst.instruction < 0xffff) | |
10305 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 10306 | inst.instruction |= Rn << r0off; |
c19d1205 | 10307 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 10308 | } |
b99bd4ef NC |
10309 | } |
10310 | } | |
10311 | else | |
10312 | { | |
c19d1205 ZW |
10313 | constraint (inst.instruction > 0xffff |
10314 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
10315 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
10316 | _("unshifted register required")); | |
fdfde340 | 10317 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10318 | BAD_HIREG); |
b99bd4ef | 10319 | |
c19d1205 | 10320 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
10321 | inst.instruction |= Rn; |
10322 | inst.instruction |= Rm << 3; | |
b99bd4ef | 10323 | } |
b99bd4ef NC |
10324 | } |
10325 | ||
b05fe5cf | 10326 | static void |
c19d1205 | 10327 | do_t_mrs (void) |
b05fe5cf | 10328 | { |
fdfde340 | 10329 | unsigned Rd; |
62b3e311 | 10330 | int flags; |
037e8744 JB |
10331 | |
10332 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
10333 | return; | |
10334 | ||
62b3e311 PB |
10335 | flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
10336 | if (flags == 0) | |
10337 | { | |
7e806470 | 10338 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10339 | _("selected processor does not support " |
10340 | "requested special purpose register")); | |
10341 | } | |
10342 | else | |
10343 | { | |
10344 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10345 | _("selected processor does not support " | |
44bf2362 | 10346 | "requested special purpose register")); |
62b3e311 PB |
10347 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
10348 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
10349 | _("'CPSR' or 'SPSR' expected")); | |
10350 | } | |
5f4273c7 | 10351 | |
fdfde340 JM |
10352 | Rd = inst.operands[0].reg; |
10353 | reject_bad_reg (Rd); | |
10354 | ||
10355 | inst.instruction |= Rd << 8; | |
62b3e311 PB |
10356 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10357 | inst.instruction |= inst.operands[1].imm & 0xff; | |
c19d1205 | 10358 | } |
b05fe5cf | 10359 | |
c19d1205 ZW |
10360 | static void |
10361 | do_t_msr (void) | |
10362 | { | |
62b3e311 | 10363 | int flags; |
fdfde340 | 10364 | unsigned Rn; |
62b3e311 | 10365 | |
037e8744 JB |
10366 | if (do_vfp_nsyn_msr () == SUCCESS) |
10367 | return; | |
10368 | ||
c19d1205 ZW |
10369 | constraint (!inst.operands[1].isreg, |
10370 | _("Thumb encoding does not support an immediate here")); | |
62b3e311 PB |
10371 | flags = inst.operands[0].imm; |
10372 | if (flags & ~0xff) | |
10373 | { | |
10374 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
10375 | _("selected processor does not support " | |
10376 | "requested special purpose register")); | |
10377 | } | |
10378 | else | |
10379 | { | |
7e806470 | 10380 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m), |
62b3e311 PB |
10381 | _("selected processor does not support " |
10382 | "requested special purpose register")); | |
10383 | flags |= PSR_f; | |
10384 | } | |
c921be7d | 10385 | |
fdfde340 JM |
10386 | Rn = inst.operands[1].reg; |
10387 | reject_bad_reg (Rn); | |
10388 | ||
62b3e311 PB |
10389 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
10390 | inst.instruction |= (flags & ~SPSR_BIT) >> 8; | |
10391 | inst.instruction |= (flags & 0xff); | |
fdfde340 | 10392 | inst.instruction |= Rn << 16; |
c19d1205 | 10393 | } |
b05fe5cf | 10394 | |
c19d1205 ZW |
10395 | static void |
10396 | do_t_mul (void) | |
10397 | { | |
17828f45 | 10398 | bfd_boolean narrow; |
fdfde340 | 10399 | unsigned Rd, Rn, Rm; |
17828f45 | 10400 | |
c19d1205 ZW |
10401 | if (!inst.operands[2].present) |
10402 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 10403 | |
fdfde340 JM |
10404 | Rd = inst.operands[0].reg; |
10405 | Rn = inst.operands[1].reg; | |
10406 | Rm = inst.operands[2].reg; | |
10407 | ||
17828f45 | 10408 | if (unified_syntax) |
b05fe5cf | 10409 | { |
17828f45 | 10410 | if (inst.size_req == 4 |
fdfde340 JM |
10411 | || (Rd != Rn |
10412 | && Rd != Rm) | |
10413 | || Rn > 7 | |
10414 | || Rm > 7) | |
17828f45 JM |
10415 | narrow = FALSE; |
10416 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 10417 | narrow = !in_it_block (); |
17828f45 | 10418 | else |
e07e6e58 | 10419 | narrow = in_it_block (); |
b05fe5cf | 10420 | } |
c19d1205 | 10421 | else |
b05fe5cf | 10422 | { |
17828f45 | 10423 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 10424 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 10425 | BAD_HIREG); |
17828f45 JM |
10426 | narrow = TRUE; |
10427 | } | |
b05fe5cf | 10428 | |
17828f45 JM |
10429 | if (narrow) |
10430 | { | |
10431 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 10432 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 10433 | inst.instruction |= Rd; |
b05fe5cf | 10434 | |
fdfde340 JM |
10435 | if (Rd == Rn) |
10436 | inst.instruction |= Rm << 3; | |
10437 | else if (Rd == Rm) | |
10438 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
10439 | else |
10440 | constraint (1, _("dest must overlap one source register")); | |
10441 | } | |
17828f45 JM |
10442 | else |
10443 | { | |
e07e6e58 NC |
10444 | constraint (inst.instruction != T_MNEM_mul, |
10445 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
10446 | /* 32-bit MUL. */ |
10447 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10448 | inst.instruction |= Rd << 8; |
10449 | inst.instruction |= Rn << 16; | |
10450 | inst.instruction |= Rm << 0; | |
10451 | ||
10452 | reject_bad_reg (Rd); | |
10453 | reject_bad_reg (Rn); | |
10454 | reject_bad_reg (Rm); | |
17828f45 | 10455 | } |
c19d1205 | 10456 | } |
b05fe5cf | 10457 | |
c19d1205 ZW |
10458 | static void |
10459 | do_t_mull (void) | |
10460 | { | |
fdfde340 | 10461 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 10462 | |
fdfde340 JM |
10463 | RdLo = inst.operands[0].reg; |
10464 | RdHi = inst.operands[1].reg; | |
10465 | Rn = inst.operands[2].reg; | |
10466 | Rm = inst.operands[3].reg; | |
10467 | ||
10468 | reject_bad_reg (RdLo); | |
10469 | reject_bad_reg (RdHi); | |
10470 | reject_bad_reg (Rn); | |
10471 | reject_bad_reg (Rm); | |
10472 | ||
10473 | inst.instruction |= RdLo << 12; | |
10474 | inst.instruction |= RdHi << 8; | |
10475 | inst.instruction |= Rn << 16; | |
10476 | inst.instruction |= Rm; | |
10477 | ||
10478 | if (RdLo == RdHi) | |
c19d1205 ZW |
10479 | as_tsktsk (_("rdhi and rdlo must be different")); |
10480 | } | |
b05fe5cf | 10481 | |
c19d1205 ZW |
10482 | static void |
10483 | do_t_nop (void) | |
10484 | { | |
e07e6e58 NC |
10485 | set_it_insn_type (NEUTRAL_IT_INSN); |
10486 | ||
c19d1205 ZW |
10487 | if (unified_syntax) |
10488 | { | |
10489 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 10490 | { |
c19d1205 ZW |
10491 | inst.instruction = THUMB_OP32 (inst.instruction); |
10492 | inst.instruction |= inst.operands[0].imm; | |
10493 | } | |
10494 | else | |
10495 | { | |
bc2d1808 NC |
10496 | /* PR9722: Check for Thumb2 availability before |
10497 | generating a thumb2 nop instruction. */ | |
10498 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
10499 | { | |
10500 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10501 | inst.instruction |= inst.operands[0].imm << 4; | |
10502 | } | |
10503 | else | |
10504 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
10505 | } |
10506 | } | |
10507 | else | |
10508 | { | |
10509 | constraint (inst.operands[0].present, | |
10510 | _("Thumb does not support NOP with hints")); | |
10511 | inst.instruction = 0x46c0; | |
10512 | } | |
10513 | } | |
b05fe5cf | 10514 | |
c19d1205 ZW |
10515 | static void |
10516 | do_t_neg (void) | |
10517 | { | |
10518 | if (unified_syntax) | |
10519 | { | |
3d388997 PB |
10520 | bfd_boolean narrow; |
10521 | ||
10522 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10523 | narrow = !in_it_block (); |
3d388997 | 10524 | else |
e07e6e58 | 10525 | narrow = in_it_block (); |
3d388997 PB |
10526 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10527 | narrow = FALSE; | |
10528 | if (inst.size_req == 4) | |
10529 | narrow = FALSE; | |
10530 | ||
10531 | if (!narrow) | |
c19d1205 ZW |
10532 | { |
10533 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10534 | inst.instruction |= inst.operands[0].reg << 8; | |
10535 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
10536 | } |
10537 | else | |
10538 | { | |
c19d1205 ZW |
10539 | inst.instruction = THUMB_OP16 (inst.instruction); |
10540 | inst.instruction |= inst.operands[0].reg; | |
10541 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
10542 | } |
10543 | } | |
10544 | else | |
10545 | { | |
c19d1205 ZW |
10546 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
10547 | BAD_HIREG); | |
10548 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
10549 | ||
10550 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10551 | inst.instruction |= inst.operands[0].reg; | |
10552 | inst.instruction |= inst.operands[1].reg << 3; | |
10553 | } | |
10554 | } | |
10555 | ||
1c444d06 JM |
10556 | static void |
10557 | do_t_orn (void) | |
10558 | { | |
10559 | unsigned Rd, Rn; | |
10560 | ||
10561 | Rd = inst.operands[0].reg; | |
10562 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
10563 | ||
fdfde340 JM |
10564 | reject_bad_reg (Rd); |
10565 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
10566 | reject_bad_reg (Rn); | |
10567 | ||
1c444d06 JM |
10568 | inst.instruction |= Rd << 8; |
10569 | inst.instruction |= Rn << 16; | |
10570 | ||
10571 | if (!inst.operands[2].isreg) | |
10572 | { | |
10573 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10574 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10575 | } | |
10576 | else | |
10577 | { | |
10578 | unsigned Rm; | |
10579 | ||
10580 | Rm = inst.operands[2].reg; | |
fdfde340 | 10581 | reject_bad_reg (Rm); |
1c444d06 JM |
10582 | |
10583 | constraint (inst.operands[2].shifted | |
10584 | && inst.operands[2].immisreg, | |
10585 | _("shift must be constant")); | |
10586 | encode_thumb32_shifted_operand (2); | |
10587 | } | |
10588 | } | |
10589 | ||
c19d1205 ZW |
10590 | static void |
10591 | do_t_pkhbt (void) | |
10592 | { | |
fdfde340 JM |
10593 | unsigned Rd, Rn, Rm; |
10594 | ||
10595 | Rd = inst.operands[0].reg; | |
10596 | Rn = inst.operands[1].reg; | |
10597 | Rm = inst.operands[2].reg; | |
10598 | ||
10599 | reject_bad_reg (Rd); | |
10600 | reject_bad_reg (Rn); | |
10601 | reject_bad_reg (Rm); | |
10602 | ||
10603 | inst.instruction |= Rd << 8; | |
10604 | inst.instruction |= Rn << 16; | |
10605 | inst.instruction |= Rm; | |
c19d1205 ZW |
10606 | if (inst.operands[3].present) |
10607 | { | |
10608 | unsigned int val = inst.reloc.exp.X_add_number; | |
10609 | constraint (inst.reloc.exp.X_op != O_constant, | |
10610 | _("expression too complex")); | |
10611 | inst.instruction |= (val & 0x1c) << 10; | |
10612 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 10613 | } |
c19d1205 | 10614 | } |
b05fe5cf | 10615 | |
c19d1205 ZW |
10616 | static void |
10617 | do_t_pkhtb (void) | |
10618 | { | |
10619 | if (!inst.operands[3].present) | |
1ef52f49 NC |
10620 | { |
10621 | unsigned Rtmp; | |
10622 | ||
10623 | inst.instruction &= ~0x00000020; | |
10624 | ||
10625 | /* PR 10168. Swap the Rm and Rn registers. */ | |
10626 | Rtmp = inst.operands[1].reg; | |
10627 | inst.operands[1].reg = inst.operands[2].reg; | |
10628 | inst.operands[2].reg = Rtmp; | |
10629 | } | |
c19d1205 | 10630 | do_t_pkhbt (); |
b05fe5cf ZW |
10631 | } |
10632 | ||
c19d1205 ZW |
10633 | static void |
10634 | do_t_pld (void) | |
10635 | { | |
fdfde340 JM |
10636 | if (inst.operands[0].immisreg) |
10637 | reject_bad_reg (inst.operands[0].imm); | |
10638 | ||
c19d1205 ZW |
10639 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
10640 | } | |
b05fe5cf | 10641 | |
c19d1205 ZW |
10642 | static void |
10643 | do_t_push_pop (void) | |
b99bd4ef | 10644 | { |
e9f89963 | 10645 | unsigned mask; |
5f4273c7 | 10646 | |
c19d1205 ZW |
10647 | constraint (inst.operands[0].writeback, |
10648 | _("push/pop do not support {reglist}^")); | |
10649 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
10650 | _("expression too complex")); | |
b99bd4ef | 10651 | |
e9f89963 PB |
10652 | mask = inst.operands[0].imm; |
10653 | if ((mask & ~0xff) == 0) | |
3c707909 | 10654 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
c19d1205 | 10655 | else if ((inst.instruction == T_MNEM_push |
e9f89963 | 10656 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 10657 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 10658 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 10659 | { |
c19d1205 ZW |
10660 | inst.instruction = THUMB_OP16 (inst.instruction); |
10661 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 10662 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
10663 | } |
10664 | else if (unified_syntax) | |
10665 | { | |
3c707909 | 10666 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 10667 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
10668 | } |
10669 | else | |
10670 | { | |
10671 | inst.error = _("invalid register list to push/pop instruction"); | |
10672 | return; | |
10673 | } | |
c19d1205 | 10674 | } |
b99bd4ef | 10675 | |
c19d1205 ZW |
10676 | static void |
10677 | do_t_rbit (void) | |
10678 | { | |
fdfde340 JM |
10679 | unsigned Rd, Rm; |
10680 | ||
10681 | Rd = inst.operands[0].reg; | |
10682 | Rm = inst.operands[1].reg; | |
10683 | ||
10684 | reject_bad_reg (Rd); | |
10685 | reject_bad_reg (Rm); | |
10686 | ||
10687 | inst.instruction |= Rd << 8; | |
10688 | inst.instruction |= Rm << 16; | |
10689 | inst.instruction |= Rm; | |
c19d1205 | 10690 | } |
b99bd4ef | 10691 | |
c19d1205 ZW |
10692 | static void |
10693 | do_t_rev (void) | |
10694 | { | |
fdfde340 JM |
10695 | unsigned Rd, Rm; |
10696 | ||
10697 | Rd = inst.operands[0].reg; | |
10698 | Rm = inst.operands[1].reg; | |
10699 | ||
10700 | reject_bad_reg (Rd); | |
10701 | reject_bad_reg (Rm); | |
10702 | ||
10703 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
10704 | && inst.size_req != 4) |
10705 | { | |
10706 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
10707 | inst.instruction |= Rd; |
10708 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
10709 | } |
10710 | else if (unified_syntax) | |
10711 | { | |
10712 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
10713 | inst.instruction |= Rd << 8; |
10714 | inst.instruction |= Rm << 16; | |
10715 | inst.instruction |= Rm; | |
c19d1205 ZW |
10716 | } |
10717 | else | |
10718 | inst.error = BAD_HIREG; | |
10719 | } | |
b99bd4ef | 10720 | |
1c444d06 JM |
10721 | static void |
10722 | do_t_rrx (void) | |
10723 | { | |
10724 | unsigned Rd, Rm; | |
10725 | ||
10726 | Rd = inst.operands[0].reg; | |
10727 | Rm = inst.operands[1].reg; | |
10728 | ||
fdfde340 JM |
10729 | reject_bad_reg (Rd); |
10730 | reject_bad_reg (Rm); | |
c921be7d | 10731 | |
1c444d06 JM |
10732 | inst.instruction |= Rd << 8; |
10733 | inst.instruction |= Rm; | |
10734 | } | |
10735 | ||
c19d1205 ZW |
10736 | static void |
10737 | do_t_rsb (void) | |
10738 | { | |
fdfde340 | 10739 | unsigned Rd, Rs; |
b99bd4ef | 10740 | |
c19d1205 ZW |
10741 | Rd = inst.operands[0].reg; |
10742 | Rs = (inst.operands[1].present | |
10743 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10744 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 10745 | |
fdfde340 JM |
10746 | reject_bad_reg (Rd); |
10747 | reject_bad_reg (Rs); | |
10748 | if (inst.operands[2].isreg) | |
10749 | reject_bad_reg (inst.operands[2].reg); | |
10750 | ||
c19d1205 ZW |
10751 | inst.instruction |= Rd << 8; |
10752 | inst.instruction |= Rs << 16; | |
10753 | if (!inst.operands[2].isreg) | |
10754 | { | |
026d3abb PB |
10755 | bfd_boolean narrow; |
10756 | ||
10757 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 10758 | narrow = !in_it_block (); |
026d3abb | 10759 | else |
e07e6e58 | 10760 | narrow = in_it_block (); |
026d3abb PB |
10761 | |
10762 | if (Rd > 7 || Rs > 7) | |
10763 | narrow = FALSE; | |
10764 | ||
10765 | if (inst.size_req == 4 || !unified_syntax) | |
10766 | narrow = FALSE; | |
10767 | ||
10768 | if (inst.reloc.exp.X_op != O_constant | |
10769 | || inst.reloc.exp.X_add_number != 0) | |
10770 | narrow = FALSE; | |
10771 | ||
10772 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
10773 | relaxation, but it doesn't seem worth the hassle. */ | |
10774 | if (narrow) | |
10775 | { | |
10776 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10777 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
10778 | inst.instruction |= Rs << 3; | |
10779 | inst.instruction |= Rd; | |
10780 | } | |
10781 | else | |
10782 | { | |
10783 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10784 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10785 | } | |
c19d1205 ZW |
10786 | } |
10787 | else | |
10788 | encode_thumb32_shifted_operand (2); | |
10789 | } | |
b99bd4ef | 10790 | |
c19d1205 ZW |
10791 | static void |
10792 | do_t_setend (void) | |
10793 | { | |
e07e6e58 | 10794 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
10795 | if (inst.operands[0].imm) |
10796 | inst.instruction |= 0x8; | |
10797 | } | |
b99bd4ef | 10798 | |
c19d1205 ZW |
10799 | static void |
10800 | do_t_shift (void) | |
10801 | { | |
10802 | if (!inst.operands[1].present) | |
10803 | inst.operands[1].reg = inst.operands[0].reg; | |
10804 | ||
10805 | if (unified_syntax) | |
10806 | { | |
3d388997 PB |
10807 | bfd_boolean narrow; |
10808 | int shift_kind; | |
10809 | ||
10810 | switch (inst.instruction) | |
10811 | { | |
10812 | case T_MNEM_asr: | |
10813 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
10814 | case T_MNEM_lsl: | |
10815 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
10816 | case T_MNEM_lsr: | |
10817 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
10818 | case T_MNEM_ror: | |
10819 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
10820 | default: abort (); | |
10821 | } | |
10822 | ||
10823 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 10824 | narrow = !in_it_block (); |
3d388997 | 10825 | else |
e07e6e58 | 10826 | narrow = in_it_block (); |
3d388997 PB |
10827 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
10828 | narrow = FALSE; | |
10829 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
10830 | narrow = FALSE; | |
10831 | if (inst.operands[2].isreg | |
10832 | && (inst.operands[1].reg != inst.operands[0].reg | |
10833 | || inst.operands[2].reg > 7)) | |
10834 | narrow = FALSE; | |
10835 | if (inst.size_req == 4) | |
10836 | narrow = FALSE; | |
10837 | ||
fdfde340 JM |
10838 | reject_bad_reg (inst.operands[0].reg); |
10839 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 10840 | |
3d388997 | 10841 | if (!narrow) |
c19d1205 ZW |
10842 | { |
10843 | if (inst.operands[2].isreg) | |
b99bd4ef | 10844 | { |
fdfde340 | 10845 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
10846 | inst.instruction = THUMB_OP32 (inst.instruction); |
10847 | inst.instruction |= inst.operands[0].reg << 8; | |
10848 | inst.instruction |= inst.operands[1].reg << 16; | |
10849 | inst.instruction |= inst.operands[2].reg; | |
10850 | } | |
10851 | else | |
10852 | { | |
10853 | inst.operands[1].shifted = 1; | |
3d388997 | 10854 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
10855 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
10856 | ? T_MNEM_movs : T_MNEM_mov); | |
10857 | inst.instruction |= inst.operands[0].reg << 8; | |
10858 | encode_thumb32_shifted_operand (1); | |
10859 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
10860 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
10861 | } |
10862 | } | |
10863 | else | |
10864 | { | |
c19d1205 | 10865 | if (inst.operands[2].isreg) |
b99bd4ef | 10866 | { |
3d388997 | 10867 | switch (shift_kind) |
b99bd4ef | 10868 | { |
3d388997 PB |
10869 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
10870 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
10871 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
10872 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 10873 | default: abort (); |
b99bd4ef | 10874 | } |
5f4273c7 | 10875 | |
c19d1205 ZW |
10876 | inst.instruction |= inst.operands[0].reg; |
10877 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
10878 | } |
10879 | else | |
10880 | { | |
3d388997 | 10881 | switch (shift_kind) |
b99bd4ef | 10882 | { |
3d388997 PB |
10883 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
10884 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
10885 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 10886 | default: abort (); |
b99bd4ef | 10887 | } |
c19d1205 ZW |
10888 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
10889 | inst.instruction |= inst.operands[0].reg; | |
10890 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
10891 | } |
10892 | } | |
c19d1205 ZW |
10893 | } |
10894 | else | |
10895 | { | |
10896 | constraint (inst.operands[0].reg > 7 | |
10897 | || inst.operands[1].reg > 7, BAD_HIREG); | |
10898 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 10899 | |
c19d1205 ZW |
10900 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
10901 | { | |
10902 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
10903 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
10904 | _("source1 and dest must be same register")); | |
b99bd4ef | 10905 | |
c19d1205 ZW |
10906 | switch (inst.instruction) |
10907 | { | |
10908 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
10909 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
10910 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
10911 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
10912 | default: abort (); | |
10913 | } | |
5f4273c7 | 10914 | |
c19d1205 ZW |
10915 | inst.instruction |= inst.operands[0].reg; |
10916 | inst.instruction |= inst.operands[2].reg << 3; | |
10917 | } | |
10918 | else | |
b99bd4ef | 10919 | { |
c19d1205 ZW |
10920 | switch (inst.instruction) |
10921 | { | |
10922 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
10923 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
10924 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
10925 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
10926 | default: abort (); | |
10927 | } | |
10928 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
10929 | inst.instruction |= inst.operands[0].reg; | |
10930 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
10931 | } |
10932 | } | |
b99bd4ef NC |
10933 | } |
10934 | ||
10935 | static void | |
c19d1205 | 10936 | do_t_simd (void) |
b99bd4ef | 10937 | { |
fdfde340 JM |
10938 | unsigned Rd, Rn, Rm; |
10939 | ||
10940 | Rd = inst.operands[0].reg; | |
10941 | Rn = inst.operands[1].reg; | |
10942 | Rm = inst.operands[2].reg; | |
10943 | ||
10944 | reject_bad_reg (Rd); | |
10945 | reject_bad_reg (Rn); | |
10946 | reject_bad_reg (Rm); | |
10947 | ||
10948 | inst.instruction |= Rd << 8; | |
10949 | inst.instruction |= Rn << 16; | |
10950 | inst.instruction |= Rm; | |
c19d1205 | 10951 | } |
b99bd4ef | 10952 | |
c19d1205 | 10953 | static void |
3eb17e6b | 10954 | do_t_smc (void) |
c19d1205 ZW |
10955 | { |
10956 | unsigned int value = inst.reloc.exp.X_add_number; | |
10957 | constraint (inst.reloc.exp.X_op != O_constant, | |
10958 | _("expression too complex")); | |
10959 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10960 | inst.instruction |= (value & 0xf000) >> 12; | |
10961 | inst.instruction |= (value & 0x0ff0); | |
10962 | inst.instruction |= (value & 0x000f) << 16; | |
10963 | } | |
b99bd4ef | 10964 | |
c19d1205 | 10965 | static void |
3a21c15a | 10966 | do_t_ssat_usat (int bias) |
c19d1205 | 10967 | { |
fdfde340 JM |
10968 | unsigned Rd, Rn; |
10969 | ||
10970 | Rd = inst.operands[0].reg; | |
10971 | Rn = inst.operands[2].reg; | |
10972 | ||
10973 | reject_bad_reg (Rd); | |
10974 | reject_bad_reg (Rn); | |
10975 | ||
10976 | inst.instruction |= Rd << 8; | |
3a21c15a | 10977 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 10978 | inst.instruction |= Rn << 16; |
b99bd4ef | 10979 | |
c19d1205 | 10980 | if (inst.operands[3].present) |
b99bd4ef | 10981 | { |
3a21c15a NC |
10982 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
10983 | ||
10984 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10985 | ||
c19d1205 ZW |
10986 | constraint (inst.reloc.exp.X_op != O_constant, |
10987 | _("expression too complex")); | |
b99bd4ef | 10988 | |
3a21c15a | 10989 | if (shift_amount != 0) |
6189168b | 10990 | { |
3a21c15a NC |
10991 | constraint (shift_amount > 31, |
10992 | _("shift expression is too large")); | |
10993 | ||
c19d1205 | 10994 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
10995 | inst.instruction |= 0x00200000; /* sh bit. */ |
10996 | ||
10997 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
10998 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
10999 | } |
11000 | } | |
b99bd4ef | 11001 | } |
c921be7d | 11002 | |
3a21c15a NC |
11003 | static void |
11004 | do_t_ssat (void) | |
11005 | { | |
11006 | do_t_ssat_usat (1); | |
11007 | } | |
b99bd4ef | 11008 | |
0dd132b6 | 11009 | static void |
c19d1205 | 11010 | do_t_ssat16 (void) |
0dd132b6 | 11011 | { |
fdfde340 JM |
11012 | unsigned Rd, Rn; |
11013 | ||
11014 | Rd = inst.operands[0].reg; | |
11015 | Rn = inst.operands[2].reg; | |
11016 | ||
11017 | reject_bad_reg (Rd); | |
11018 | reject_bad_reg (Rn); | |
11019 | ||
11020 | inst.instruction |= Rd << 8; | |
c19d1205 | 11021 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 11022 | inst.instruction |= Rn << 16; |
c19d1205 | 11023 | } |
0dd132b6 | 11024 | |
c19d1205 ZW |
11025 | static void |
11026 | do_t_strex (void) | |
11027 | { | |
11028 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
11029 | || inst.operands[2].postind || inst.operands[2].writeback | |
11030 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
11031 | || inst.operands[2].negative, | |
01cfc07f | 11032 | BAD_ADDR_MODE); |
0dd132b6 | 11033 | |
c19d1205 ZW |
11034 | inst.instruction |= inst.operands[0].reg << 8; |
11035 | inst.instruction |= inst.operands[1].reg << 12; | |
11036 | inst.instruction |= inst.operands[2].reg << 16; | |
11037 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
11038 | } |
11039 | ||
b99bd4ef | 11040 | static void |
c19d1205 | 11041 | do_t_strexd (void) |
b99bd4ef | 11042 | { |
c19d1205 ZW |
11043 | if (!inst.operands[2].present) |
11044 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 11045 | |
c19d1205 ZW |
11046 | constraint (inst.operands[0].reg == inst.operands[1].reg |
11047 | || inst.operands[0].reg == inst.operands[2].reg | |
11048 | || inst.operands[0].reg == inst.operands[3].reg | |
11049 | || inst.operands[1].reg == inst.operands[2].reg, | |
11050 | BAD_OVERLAP); | |
b99bd4ef | 11051 | |
c19d1205 ZW |
11052 | inst.instruction |= inst.operands[0].reg; |
11053 | inst.instruction |= inst.operands[1].reg << 12; | |
11054 | inst.instruction |= inst.operands[2].reg << 8; | |
11055 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
11056 | } |
11057 | ||
11058 | static void | |
c19d1205 | 11059 | do_t_sxtah (void) |
b99bd4ef | 11060 | { |
fdfde340 JM |
11061 | unsigned Rd, Rn, Rm; |
11062 | ||
11063 | Rd = inst.operands[0].reg; | |
11064 | Rn = inst.operands[1].reg; | |
11065 | Rm = inst.operands[2].reg; | |
11066 | ||
11067 | reject_bad_reg (Rd); | |
11068 | reject_bad_reg (Rn); | |
11069 | reject_bad_reg (Rm); | |
11070 | ||
11071 | inst.instruction |= Rd << 8; | |
11072 | inst.instruction |= Rn << 16; | |
11073 | inst.instruction |= Rm; | |
c19d1205 ZW |
11074 | inst.instruction |= inst.operands[3].imm << 4; |
11075 | } | |
b99bd4ef | 11076 | |
c19d1205 ZW |
11077 | static void |
11078 | do_t_sxth (void) | |
11079 | { | |
fdfde340 JM |
11080 | unsigned Rd, Rm; |
11081 | ||
11082 | Rd = inst.operands[0].reg; | |
11083 | Rm = inst.operands[1].reg; | |
11084 | ||
11085 | reject_bad_reg (Rd); | |
11086 | reject_bad_reg (Rm); | |
c921be7d NC |
11087 | |
11088 | if (inst.instruction <= 0xffff | |
11089 | && inst.size_req != 4 | |
fdfde340 | 11090 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 11091 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 11092 | { |
c19d1205 | 11093 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
11094 | inst.instruction |= Rd; |
11095 | inst.instruction |= Rm << 3; | |
b99bd4ef | 11096 | } |
c19d1205 | 11097 | else if (unified_syntax) |
b99bd4ef | 11098 | { |
c19d1205 ZW |
11099 | if (inst.instruction <= 0xffff) |
11100 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
11101 | inst.instruction |= Rd << 8; |
11102 | inst.instruction |= Rm; | |
c19d1205 | 11103 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 11104 | } |
c19d1205 | 11105 | else |
b99bd4ef | 11106 | { |
c19d1205 ZW |
11107 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
11108 | _("Thumb encoding does not support rotation")); | |
11109 | constraint (1, BAD_HIREG); | |
b99bd4ef | 11110 | } |
c19d1205 | 11111 | } |
b99bd4ef | 11112 | |
c19d1205 ZW |
11113 | static void |
11114 | do_t_swi (void) | |
11115 | { | |
11116 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
11117 | } | |
b99bd4ef | 11118 | |
92e90b6e PB |
11119 | static void |
11120 | do_t_tb (void) | |
11121 | { | |
fdfde340 | 11122 | unsigned Rn, Rm; |
92e90b6e PB |
11123 | int half; |
11124 | ||
11125 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 11126 | set_it_insn_type_last (); |
dfa9f0d5 PB |
11127 | constraint (inst.operands[0].immisreg, |
11128 | _("instruction requires register index")); | |
fdfde340 JM |
11129 | |
11130 | Rn = inst.operands[0].reg; | |
11131 | Rm = inst.operands[0].imm; | |
c921be7d | 11132 | |
fdfde340 JM |
11133 | constraint (Rn == REG_SP, BAD_SP); |
11134 | reject_bad_reg (Rm); | |
11135 | ||
92e90b6e PB |
11136 | constraint (!half && inst.operands[0].shifted, |
11137 | _("instruction does not allow shifted index")); | |
fdfde340 | 11138 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
11139 | } |
11140 | ||
c19d1205 ZW |
11141 | static void |
11142 | do_t_usat (void) | |
11143 | { | |
3a21c15a | 11144 | do_t_ssat_usat (0); |
b99bd4ef NC |
11145 | } |
11146 | ||
11147 | static void | |
c19d1205 | 11148 | do_t_usat16 (void) |
b99bd4ef | 11149 | { |
fdfde340 JM |
11150 | unsigned Rd, Rn; |
11151 | ||
11152 | Rd = inst.operands[0].reg; | |
11153 | Rn = inst.operands[2].reg; | |
11154 | ||
11155 | reject_bad_reg (Rd); | |
11156 | reject_bad_reg (Rn); | |
11157 | ||
11158 | inst.instruction |= Rd << 8; | |
c19d1205 | 11159 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 11160 | inst.instruction |= Rn << 16; |
b99bd4ef | 11161 | } |
c19d1205 | 11162 | |
5287ad62 | 11163 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 11164 | |
5287ad62 | 11165 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 11166 | |
5287ad62 JB |
11167 | /* An "invalid" code for the following tables. */ |
11168 | #define N_INV -1u | |
11169 | ||
11170 | struct neon_tab_entry | |
b99bd4ef | 11171 | { |
5287ad62 JB |
11172 | unsigned integer; |
11173 | unsigned float_or_poly; | |
11174 | unsigned scalar_or_imm; | |
11175 | }; | |
5f4273c7 | 11176 | |
5287ad62 JB |
11177 | /* Map overloaded Neon opcodes to their respective encodings. */ |
11178 | #define NEON_ENC_TAB \ | |
11179 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
11180 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
11181 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
11182 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
11183 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
11184 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
11185 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
11186 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
11187 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
11188 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
11189 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
11190 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 11191 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
11192 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
11193 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
5287ad62 JB |
11194 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
11195 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
11196 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
11197 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
11198 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
11199 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
11200 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
11201 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
11202 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
11203 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
11204 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
11205 | X(vshl, 0x0000400, N_INV, 0x0800510), \ | |
11206 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
11207 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
11208 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
11209 | X(veor, 0x1000110, N_INV, N_INV), \ | |
11210 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
11211 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
11212 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
11213 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
11214 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
11215 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
11216 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
11217 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
11218 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
11219 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
11220 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
11221 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
11222 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
11223 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
11224 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
11225 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
11226 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
11227 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
11228 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
11229 | X(vnmla, 0xe000a40, 0xe000b40, N_INV), \ | |
11230 | X(vnmls, 0xe100a40, 0xe100b40, N_INV), \ | |
11231 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ | |
11232 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
11233 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
11234 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV) | |
5287ad62 JB |
11235 | |
11236 | enum neon_opc | |
11237 | { | |
11238 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
11239 | NEON_ENC_TAB | |
11240 | #undef X | |
11241 | }; | |
b99bd4ef | 11242 | |
5287ad62 JB |
11243 | static const struct neon_tab_entry neon_enc_tab[] = |
11244 | { | |
11245 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
11246 | NEON_ENC_TAB | |
11247 | #undef X | |
11248 | }; | |
b99bd4ef | 11249 | |
5287ad62 JB |
11250 | #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer) |
11251 | #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11252 | #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11253 | #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11254 | #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11255 | #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
11256 | #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
11257 | #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
11258 | #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
037e8744 JB |
11259 | #define NEON_ENC_SINGLE(X) \ |
11260 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) | |
11261 | #define NEON_ENC_DOUBLE(X) \ | |
11262 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) | |
5287ad62 | 11263 | |
037e8744 JB |
11264 | /* Define shapes for instruction operands. The following mnemonic characters |
11265 | are used in this table: | |
5287ad62 | 11266 | |
037e8744 | 11267 | F - VFP S<n> register |
5287ad62 JB |
11268 | D - Neon D<n> register |
11269 | Q - Neon Q<n> register | |
11270 | I - Immediate | |
11271 | S - Scalar | |
11272 | R - ARM register | |
11273 | L - D<n> register list | |
5f4273c7 | 11274 | |
037e8744 JB |
11275 | This table is used to generate various data: |
11276 | - enumerations of the form NS_DDR to be used as arguments to | |
11277 | neon_select_shape. | |
11278 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 11279 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 11280 | |
037e8744 JB |
11281 | #define NEON_SHAPE_DEF \ |
11282 | X(3, (D, D, D), DOUBLE), \ | |
11283 | X(3, (Q, Q, Q), QUAD), \ | |
11284 | X(3, (D, D, I), DOUBLE), \ | |
11285 | X(3, (Q, Q, I), QUAD), \ | |
11286 | X(3, (D, D, S), DOUBLE), \ | |
11287 | X(3, (Q, Q, S), QUAD), \ | |
11288 | X(2, (D, D), DOUBLE), \ | |
11289 | X(2, (Q, Q), QUAD), \ | |
11290 | X(2, (D, S), DOUBLE), \ | |
11291 | X(2, (Q, S), QUAD), \ | |
11292 | X(2, (D, R), DOUBLE), \ | |
11293 | X(2, (Q, R), QUAD), \ | |
11294 | X(2, (D, I), DOUBLE), \ | |
11295 | X(2, (Q, I), QUAD), \ | |
11296 | X(3, (D, L, D), DOUBLE), \ | |
11297 | X(2, (D, Q), MIXED), \ | |
11298 | X(2, (Q, D), MIXED), \ | |
11299 | X(3, (D, Q, I), MIXED), \ | |
11300 | X(3, (Q, D, I), MIXED), \ | |
11301 | X(3, (Q, D, D), MIXED), \ | |
11302 | X(3, (D, Q, Q), MIXED), \ | |
11303 | X(3, (Q, Q, D), MIXED), \ | |
11304 | X(3, (Q, D, S), MIXED), \ | |
11305 | X(3, (D, Q, S), MIXED), \ | |
11306 | X(4, (D, D, D, I), DOUBLE), \ | |
11307 | X(4, (Q, Q, Q, I), QUAD), \ | |
11308 | X(2, (F, F), SINGLE), \ | |
11309 | X(3, (F, F, F), SINGLE), \ | |
11310 | X(2, (F, I), SINGLE), \ | |
11311 | X(2, (F, D), MIXED), \ | |
11312 | X(2, (D, F), MIXED), \ | |
11313 | X(3, (F, F, I), MIXED), \ | |
11314 | X(4, (R, R, F, F), SINGLE), \ | |
11315 | X(4, (F, F, R, R), SINGLE), \ | |
11316 | X(3, (D, R, R), DOUBLE), \ | |
11317 | X(3, (R, R, D), DOUBLE), \ | |
11318 | X(2, (S, R), SINGLE), \ | |
11319 | X(2, (R, S), SINGLE), \ | |
11320 | X(2, (F, R), SINGLE), \ | |
11321 | X(2, (R, F), SINGLE) | |
11322 | ||
11323 | #define S2(A,B) NS_##A##B | |
11324 | #define S3(A,B,C) NS_##A##B##C | |
11325 | #define S4(A,B,C,D) NS_##A##B##C##D | |
11326 | ||
11327 | #define X(N, L, C) S##N L | |
11328 | ||
5287ad62 JB |
11329 | enum neon_shape |
11330 | { | |
037e8744 JB |
11331 | NEON_SHAPE_DEF, |
11332 | NS_NULL | |
5287ad62 | 11333 | }; |
b99bd4ef | 11334 | |
037e8744 JB |
11335 | #undef X |
11336 | #undef S2 | |
11337 | #undef S3 | |
11338 | #undef S4 | |
11339 | ||
11340 | enum neon_shape_class | |
11341 | { | |
11342 | SC_SINGLE, | |
11343 | SC_DOUBLE, | |
11344 | SC_QUAD, | |
11345 | SC_MIXED | |
11346 | }; | |
11347 | ||
11348 | #define X(N, L, C) SC_##C | |
11349 | ||
11350 | static enum neon_shape_class neon_shape_class[] = | |
11351 | { | |
11352 | NEON_SHAPE_DEF | |
11353 | }; | |
11354 | ||
11355 | #undef X | |
11356 | ||
11357 | enum neon_shape_el | |
11358 | { | |
11359 | SE_F, | |
11360 | SE_D, | |
11361 | SE_Q, | |
11362 | SE_I, | |
11363 | SE_S, | |
11364 | SE_R, | |
11365 | SE_L | |
11366 | }; | |
11367 | ||
11368 | /* Register widths of above. */ | |
11369 | static unsigned neon_shape_el_size[] = | |
11370 | { | |
11371 | 32, | |
11372 | 64, | |
11373 | 128, | |
11374 | 0, | |
11375 | 32, | |
11376 | 32, | |
11377 | 0 | |
11378 | }; | |
11379 | ||
11380 | struct neon_shape_info | |
11381 | { | |
11382 | unsigned els; | |
11383 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
11384 | }; | |
11385 | ||
11386 | #define S2(A,B) { SE_##A, SE_##B } | |
11387 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
11388 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
11389 | ||
11390 | #define X(N, L, C) { N, S##N L } | |
11391 | ||
11392 | static struct neon_shape_info neon_shape_tab[] = | |
11393 | { | |
11394 | NEON_SHAPE_DEF | |
11395 | }; | |
11396 | ||
11397 | #undef X | |
11398 | #undef S2 | |
11399 | #undef S3 | |
11400 | #undef S4 | |
11401 | ||
5287ad62 JB |
11402 | /* Bit masks used in type checking given instructions. |
11403 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
11404 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
11405 | set, various other bits can be set as well in order to modify the meaning of | |
11406 | the type constraint. */ | |
11407 | ||
11408 | enum neon_type_mask | |
11409 | { | |
8e79c3df CM |
11410 | N_S8 = 0x0000001, |
11411 | N_S16 = 0x0000002, | |
11412 | N_S32 = 0x0000004, | |
11413 | N_S64 = 0x0000008, | |
11414 | N_U8 = 0x0000010, | |
11415 | N_U16 = 0x0000020, | |
11416 | N_U32 = 0x0000040, | |
11417 | N_U64 = 0x0000080, | |
11418 | N_I8 = 0x0000100, | |
11419 | N_I16 = 0x0000200, | |
11420 | N_I32 = 0x0000400, | |
11421 | N_I64 = 0x0000800, | |
11422 | N_8 = 0x0001000, | |
11423 | N_16 = 0x0002000, | |
11424 | N_32 = 0x0004000, | |
11425 | N_64 = 0x0008000, | |
11426 | N_P8 = 0x0010000, | |
11427 | N_P16 = 0x0020000, | |
11428 | N_F16 = 0x0040000, | |
11429 | N_F32 = 0x0080000, | |
11430 | N_F64 = 0x0100000, | |
c921be7d NC |
11431 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
11432 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 11433 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
c921be7d NC |
11434 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
11435 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
11436 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
11437 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
11438 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
11439 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
11440 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 11441 | N_UTYP = 0, |
037e8744 | 11442 | N_MAX_NONSPECIAL = N_F64 |
5287ad62 JB |
11443 | }; |
11444 | ||
dcbf9037 JB |
11445 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
11446 | ||
5287ad62 JB |
11447 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
11448 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
11449 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
11450 | #define N_SUF_32 (N_SU_32 | N_F32) | |
11451 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
11452 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
11453 | ||
11454 | /* Pass this as the first type argument to neon_check_type to ignore types | |
11455 | altogether. */ | |
11456 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
11457 | ||
037e8744 JB |
11458 | /* Select a "shape" for the current instruction (describing register types or |
11459 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
11460 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
11461 | function of operand parsing, so this function doesn't need to be called. | |
11462 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
11463 | |
11464 | static enum neon_shape | |
037e8744 | 11465 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 11466 | { |
037e8744 JB |
11467 | va_list ap; |
11468 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
11469 | |
11470 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
11471 | many arguments we should have, so this makes the assumption that we have | |
11472 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
11473 | true in the future. */ | |
11474 | if (!inst.operands[1].present) | |
11475 | inst.operands[1] = inst.operands[0]; | |
11476 | ||
037e8744 | 11477 | va_start (ap, shape); |
5f4273c7 | 11478 | |
037e8744 JB |
11479 | for (; shape != NS_NULL; shape = va_arg (ap, int)) |
11480 | { | |
11481 | unsigned j; | |
11482 | int matches = 1; | |
11483 | ||
11484 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
11485 | { | |
11486 | if (!inst.operands[j].present) | |
11487 | { | |
11488 | matches = 0; | |
11489 | break; | |
11490 | } | |
11491 | ||
11492 | switch (neon_shape_tab[shape].el[j]) | |
11493 | { | |
11494 | case SE_F: | |
11495 | if (!(inst.operands[j].isreg | |
11496 | && inst.operands[j].isvec | |
11497 | && inst.operands[j].issingle | |
11498 | && !inst.operands[j].isquad)) | |
11499 | matches = 0; | |
11500 | break; | |
11501 | ||
11502 | case SE_D: | |
11503 | if (!(inst.operands[j].isreg | |
11504 | && inst.operands[j].isvec | |
11505 | && !inst.operands[j].isquad | |
11506 | && !inst.operands[j].issingle)) | |
11507 | matches = 0; | |
11508 | break; | |
11509 | ||
11510 | case SE_R: | |
11511 | if (!(inst.operands[j].isreg | |
11512 | && !inst.operands[j].isvec)) | |
11513 | matches = 0; | |
11514 | break; | |
11515 | ||
11516 | case SE_Q: | |
11517 | if (!(inst.operands[j].isreg | |
11518 | && inst.operands[j].isvec | |
11519 | && inst.operands[j].isquad | |
11520 | && !inst.operands[j].issingle)) | |
11521 | matches = 0; | |
11522 | break; | |
11523 | ||
11524 | case SE_I: | |
11525 | if (!(!inst.operands[j].isreg | |
11526 | && !inst.operands[j].isscalar)) | |
11527 | matches = 0; | |
11528 | break; | |
11529 | ||
11530 | case SE_S: | |
11531 | if (!(!inst.operands[j].isreg | |
11532 | && inst.operands[j].isscalar)) | |
11533 | matches = 0; | |
11534 | break; | |
11535 | ||
11536 | case SE_L: | |
11537 | break; | |
11538 | } | |
11539 | } | |
11540 | if (matches) | |
5287ad62 | 11541 | break; |
037e8744 | 11542 | } |
5f4273c7 | 11543 | |
037e8744 | 11544 | va_end (ap); |
5287ad62 | 11545 | |
037e8744 JB |
11546 | if (shape == NS_NULL && first_shape != NS_NULL) |
11547 | first_error (_("invalid instruction shape")); | |
5287ad62 | 11548 | |
037e8744 JB |
11549 | return shape; |
11550 | } | |
5287ad62 | 11551 | |
037e8744 JB |
11552 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
11553 | means the Q bit should be set). */ | |
11554 | ||
11555 | static int | |
11556 | neon_quad (enum neon_shape shape) | |
11557 | { | |
11558 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 11559 | } |
037e8744 | 11560 | |
5287ad62 JB |
11561 | static void |
11562 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
11563 | unsigned *g_size) | |
11564 | { | |
11565 | /* Allow modification to be made to types which are constrained to be | |
11566 | based on the key element, based on bits set alongside N_EQK. */ | |
11567 | if ((typebits & N_EQK) != 0) | |
11568 | { | |
11569 | if ((typebits & N_HLF) != 0) | |
11570 | *g_size /= 2; | |
11571 | else if ((typebits & N_DBL) != 0) | |
11572 | *g_size *= 2; | |
11573 | if ((typebits & N_SGN) != 0) | |
11574 | *g_type = NT_signed; | |
11575 | else if ((typebits & N_UNS) != 0) | |
11576 | *g_type = NT_unsigned; | |
11577 | else if ((typebits & N_INT) != 0) | |
11578 | *g_type = NT_integer; | |
11579 | else if ((typebits & N_FLT) != 0) | |
11580 | *g_type = NT_float; | |
dcbf9037 JB |
11581 | else if ((typebits & N_SIZ) != 0) |
11582 | *g_type = NT_untyped; | |
5287ad62 JB |
11583 | } |
11584 | } | |
5f4273c7 | 11585 | |
5287ad62 JB |
11586 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
11587 | operand type, i.e. the single type specified in a Neon instruction when it | |
11588 | is the only one given. */ | |
11589 | ||
11590 | static struct neon_type_el | |
11591 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
11592 | { | |
11593 | struct neon_type_el dest = *key; | |
5f4273c7 | 11594 | |
9c2799c2 | 11595 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 11596 | |
5287ad62 JB |
11597 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
11598 | ||
11599 | return dest; | |
11600 | } | |
11601 | ||
11602 | /* Convert Neon type and size into compact bitmask representation. */ | |
11603 | ||
11604 | static enum neon_type_mask | |
11605 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
11606 | { | |
11607 | switch (type) | |
11608 | { | |
11609 | case NT_untyped: | |
11610 | switch (size) | |
11611 | { | |
11612 | case 8: return N_8; | |
11613 | case 16: return N_16; | |
11614 | case 32: return N_32; | |
11615 | case 64: return N_64; | |
11616 | default: ; | |
11617 | } | |
11618 | break; | |
11619 | ||
11620 | case NT_integer: | |
11621 | switch (size) | |
11622 | { | |
11623 | case 8: return N_I8; | |
11624 | case 16: return N_I16; | |
11625 | case 32: return N_I32; | |
11626 | case 64: return N_I64; | |
11627 | default: ; | |
11628 | } | |
11629 | break; | |
11630 | ||
11631 | case NT_float: | |
037e8744 JB |
11632 | switch (size) |
11633 | { | |
8e79c3df | 11634 | case 16: return N_F16; |
037e8744 JB |
11635 | case 32: return N_F32; |
11636 | case 64: return N_F64; | |
11637 | default: ; | |
11638 | } | |
5287ad62 JB |
11639 | break; |
11640 | ||
11641 | case NT_poly: | |
11642 | switch (size) | |
11643 | { | |
11644 | case 8: return N_P8; | |
11645 | case 16: return N_P16; | |
11646 | default: ; | |
11647 | } | |
11648 | break; | |
11649 | ||
11650 | case NT_signed: | |
11651 | switch (size) | |
11652 | { | |
11653 | case 8: return N_S8; | |
11654 | case 16: return N_S16; | |
11655 | case 32: return N_S32; | |
11656 | case 64: return N_S64; | |
11657 | default: ; | |
11658 | } | |
11659 | break; | |
11660 | ||
11661 | case NT_unsigned: | |
11662 | switch (size) | |
11663 | { | |
11664 | case 8: return N_U8; | |
11665 | case 16: return N_U16; | |
11666 | case 32: return N_U32; | |
11667 | case 64: return N_U64; | |
11668 | default: ; | |
11669 | } | |
11670 | break; | |
11671 | ||
11672 | default: ; | |
11673 | } | |
5f4273c7 | 11674 | |
5287ad62 JB |
11675 | return N_UTYP; |
11676 | } | |
11677 | ||
11678 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
11679 | handles the case where a single bit is set in the mask. */ | |
11680 | ||
dcbf9037 | 11681 | static int |
5287ad62 JB |
11682 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
11683 | enum neon_type_mask mask) | |
11684 | { | |
dcbf9037 JB |
11685 | if ((mask & N_EQK) != 0) |
11686 | return FAIL; | |
11687 | ||
5287ad62 JB |
11688 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
11689 | *size = 8; | |
dcbf9037 | 11690 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0) |
5287ad62 | 11691 | *size = 16; |
dcbf9037 | 11692 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 11693 | *size = 32; |
037e8744 | 11694 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0) |
5287ad62 | 11695 | *size = 64; |
dcbf9037 JB |
11696 | else |
11697 | return FAIL; | |
11698 | ||
5287ad62 JB |
11699 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
11700 | *type = NT_signed; | |
dcbf9037 | 11701 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 11702 | *type = NT_unsigned; |
dcbf9037 | 11703 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 11704 | *type = NT_integer; |
dcbf9037 | 11705 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 11706 | *type = NT_untyped; |
dcbf9037 | 11707 | else if ((mask & (N_P8 | N_P16)) != 0) |
5287ad62 | 11708 | *type = NT_poly; |
037e8744 | 11709 | else if ((mask & (N_F32 | N_F64)) != 0) |
5287ad62 | 11710 | *type = NT_float; |
dcbf9037 JB |
11711 | else |
11712 | return FAIL; | |
5f4273c7 | 11713 | |
dcbf9037 | 11714 | return SUCCESS; |
5287ad62 JB |
11715 | } |
11716 | ||
11717 | /* Modify a bitmask of allowed types. This is only needed for type | |
11718 | relaxation. */ | |
11719 | ||
11720 | static unsigned | |
11721 | modify_types_allowed (unsigned allowed, unsigned mods) | |
11722 | { | |
11723 | unsigned size; | |
11724 | enum neon_el_type type; | |
11725 | unsigned destmask; | |
11726 | int i; | |
5f4273c7 | 11727 | |
5287ad62 | 11728 | destmask = 0; |
5f4273c7 | 11729 | |
5287ad62 JB |
11730 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
11731 | { | |
dcbf9037 JB |
11732 | if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS) |
11733 | { | |
11734 | neon_modify_type_size (mods, &type, &size); | |
11735 | destmask |= type_chk_of_el_type (type, size); | |
11736 | } | |
5287ad62 | 11737 | } |
5f4273c7 | 11738 | |
5287ad62 JB |
11739 | return destmask; |
11740 | } | |
11741 | ||
11742 | /* Check type and return type classification. | |
11743 | The manual states (paraphrase): If one datatype is given, it indicates the | |
11744 | type given in: | |
11745 | - the second operand, if there is one | |
11746 | - the operand, if there is no second operand | |
11747 | - the result, if there are no operands. | |
11748 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
11749 | which is set on a per-instruction basis, which is the one which matters when | |
11750 | only one data type is written. | |
11751 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 11752 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
11753 | |
11754 | static struct neon_type_el | |
11755 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
11756 | { | |
11757 | va_list ap; | |
11758 | unsigned i, pass, key_el = 0; | |
11759 | unsigned types[NEON_MAX_TYPE_ELS]; | |
11760 | enum neon_el_type k_type = NT_invtype; | |
11761 | unsigned k_size = -1u; | |
11762 | struct neon_type_el badtype = {NT_invtype, -1}; | |
11763 | unsigned key_allowed = 0; | |
11764 | ||
11765 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
11766 | Fill in the missing operand here, if it was omitted. */ | |
11767 | if (els > 1 && !inst.operands[1].present) | |
11768 | inst.operands[1] = inst.operands[0]; | |
11769 | ||
11770 | /* Suck up all the varargs. */ | |
11771 | va_start (ap, ns); | |
11772 | for (i = 0; i < els; i++) | |
11773 | { | |
11774 | unsigned thisarg = va_arg (ap, unsigned); | |
11775 | if (thisarg == N_IGNORE_TYPE) | |
11776 | { | |
11777 | va_end (ap); | |
11778 | return badtype; | |
11779 | } | |
11780 | types[i] = thisarg; | |
11781 | if ((thisarg & N_KEY) != 0) | |
11782 | key_el = i; | |
11783 | } | |
11784 | va_end (ap); | |
11785 | ||
dcbf9037 JB |
11786 | if (inst.vectype.elems > 0) |
11787 | for (i = 0; i < els; i++) | |
11788 | if (inst.operands[i].vectype.type != NT_invtype) | |
11789 | { | |
11790 | first_error (_("types specified in both the mnemonic and operands")); | |
11791 | return badtype; | |
11792 | } | |
11793 | ||
5287ad62 JB |
11794 | /* Duplicate inst.vectype elements here as necessary. |
11795 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
11796 | particularly when an insn takes one register and one non-register | |
11797 | operand. */ | |
11798 | if (inst.vectype.elems == 1 && els > 1) | |
11799 | { | |
11800 | unsigned j; | |
11801 | inst.vectype.elems = els; | |
11802 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
11803 | for (j = 0; j < els; j++) | |
dcbf9037 JB |
11804 | if (j != key_el) |
11805 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
11806 | types[j]); | |
11807 | } | |
11808 | else if (inst.vectype.elems == 0 && els > 0) | |
11809 | { | |
11810 | unsigned j; | |
11811 | /* No types were given after the mnemonic, so look for types specified | |
11812 | after each operand. We allow some flexibility here; as long as the | |
11813 | "key" operand has a type, we can infer the others. */ | |
11814 | for (j = 0; j < els; j++) | |
11815 | if (inst.operands[j].vectype.type != NT_invtype) | |
11816 | inst.vectype.el[j] = inst.operands[j].vectype; | |
11817 | ||
11818 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
5287ad62 | 11819 | { |
dcbf9037 JB |
11820 | for (j = 0; j < els; j++) |
11821 | if (inst.operands[j].vectype.type == NT_invtype) | |
11822 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
11823 | types[j]); | |
11824 | } | |
11825 | else | |
11826 | { | |
11827 | first_error (_("operand types can't be inferred")); | |
11828 | return badtype; | |
5287ad62 JB |
11829 | } |
11830 | } | |
11831 | else if (inst.vectype.elems != els) | |
11832 | { | |
dcbf9037 | 11833 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
11834 | return badtype; |
11835 | } | |
11836 | ||
11837 | for (pass = 0; pass < 2; pass++) | |
11838 | { | |
11839 | for (i = 0; i < els; i++) | |
11840 | { | |
11841 | unsigned thisarg = types[i]; | |
11842 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
11843 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
11844 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
11845 | unsigned g_size = inst.vectype.el[i].size; | |
11846 | ||
11847 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
11848 | integer types if sign-specific variants are unavailable. */ | |
11849 | if ((g_type == NT_signed || g_type == NT_unsigned) | |
11850 | && (types_allowed & N_SU_ALL) == 0) | |
11851 | g_type = NT_integer; | |
11852 | ||
11853 | /* If only untyped args are allowed, decay any more specific types to | |
11854 | them. Some instructions only care about signs for some element | |
11855 | sizes, so handle that properly. */ | |
11856 | if ((g_size == 8 && (types_allowed & N_8) != 0) | |
11857 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
11858 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
11859 | || (g_size == 64 && (types_allowed & N_64) != 0)) | |
11860 | g_type = NT_untyped; | |
11861 | ||
11862 | if (pass == 0) | |
11863 | { | |
11864 | if ((thisarg & N_KEY) != 0) | |
11865 | { | |
11866 | k_type = g_type; | |
11867 | k_size = g_size; | |
11868 | key_allowed = thisarg & ~N_KEY; | |
11869 | } | |
11870 | } | |
11871 | else | |
11872 | { | |
037e8744 JB |
11873 | if ((thisarg & N_VFP) != 0) |
11874 | { | |
11875 | enum neon_shape_el regshape = neon_shape_tab[ns].el[i]; | |
11876 | unsigned regwidth = neon_shape_el_size[regshape], match; | |
11877 | ||
11878 | /* In VFP mode, operands must match register widths. If we | |
11879 | have a key operand, use its width, else use the width of | |
11880 | the current operand. */ | |
11881 | if (k_size != -1u) | |
11882 | match = k_size; | |
11883 | else | |
11884 | match = g_size; | |
11885 | ||
11886 | if (regwidth != match) | |
11887 | { | |
11888 | first_error (_("operand size must match register width")); | |
11889 | return badtype; | |
11890 | } | |
11891 | } | |
5f4273c7 | 11892 | |
5287ad62 JB |
11893 | if ((thisarg & N_EQK) == 0) |
11894 | { | |
11895 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
11896 | ||
11897 | if ((given_type & types_allowed) == 0) | |
11898 | { | |
dcbf9037 | 11899 | first_error (_("bad type in Neon instruction")); |
5287ad62 JB |
11900 | return badtype; |
11901 | } | |
11902 | } | |
11903 | else | |
11904 | { | |
11905 | enum neon_el_type mod_k_type = k_type; | |
11906 | unsigned mod_k_size = k_size; | |
11907 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
11908 | if (g_type != mod_k_type || g_size != mod_k_size) | |
11909 | { | |
dcbf9037 | 11910 | first_error (_("inconsistent types in Neon instruction")); |
5287ad62 JB |
11911 | return badtype; |
11912 | } | |
11913 | } | |
11914 | } | |
11915 | } | |
11916 | } | |
11917 | ||
11918 | return inst.vectype.el[key_el]; | |
11919 | } | |
11920 | ||
037e8744 | 11921 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 11922 | |
037e8744 JB |
11923 | /* Thumb VFP instructions have 0xE in the condition field. */ |
11924 | ||
11925 | static void | |
11926 | do_vfp_cond_or_thumb (void) | |
5287ad62 JB |
11927 | { |
11928 | if (thumb_mode) | |
037e8744 | 11929 | inst.instruction |= 0xe0000000; |
5287ad62 | 11930 | else |
037e8744 | 11931 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
11932 | } |
11933 | ||
037e8744 JB |
11934 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
11935 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
11936 | etc. It is assumed that operand parsing has already been done, and that the | |
11937 | operands are in the form expected by the given opcode (this isn't necessarily | |
11938 | the same as the form in which they were parsed, hence some massaging must | |
11939 | take place before this function is called). | |
11940 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 11941 | |
037e8744 JB |
11942 | static void |
11943 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 11944 | { |
037e8744 | 11945 | const struct asm_opcode *opcode; |
5f4273c7 | 11946 | |
037e8744 | 11947 | opcode = hash_find (arm_ops_hsh, opname); |
5287ad62 | 11948 | |
037e8744 JB |
11949 | if (!opcode) |
11950 | abort (); | |
5287ad62 | 11951 | |
037e8744 JB |
11952 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
11953 | thumb_mode ? *opcode->tvariant : *opcode->avariant), | |
11954 | _(BAD_FPU)); | |
5287ad62 | 11955 | |
037e8744 JB |
11956 | if (thumb_mode) |
11957 | { | |
11958 | inst.instruction = opcode->tvalue; | |
11959 | opcode->tencode (); | |
11960 | } | |
11961 | else | |
11962 | { | |
11963 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
11964 | opcode->aencode (); | |
11965 | } | |
11966 | } | |
5287ad62 JB |
11967 | |
11968 | static void | |
037e8744 | 11969 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 11970 | { |
037e8744 JB |
11971 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
11972 | ||
11973 | if (rs == NS_FFF) | |
11974 | { | |
11975 | if (is_add) | |
11976 | do_vfp_nsyn_opcode ("fadds"); | |
11977 | else | |
11978 | do_vfp_nsyn_opcode ("fsubs"); | |
11979 | } | |
11980 | else | |
11981 | { | |
11982 | if (is_add) | |
11983 | do_vfp_nsyn_opcode ("faddd"); | |
11984 | else | |
11985 | do_vfp_nsyn_opcode ("fsubd"); | |
11986 | } | |
11987 | } | |
11988 | ||
11989 | /* Check operand types to see if this is a VFP instruction, and if so call | |
11990 | PFN (). */ | |
11991 | ||
11992 | static int | |
11993 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
11994 | { | |
11995 | enum neon_shape rs; | |
11996 | struct neon_type_el et; | |
11997 | ||
11998 | switch (args) | |
11999 | { | |
12000 | case 2: | |
12001 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12002 | et = neon_check_type (2, rs, | |
12003 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12004 | break; | |
5f4273c7 | 12005 | |
037e8744 JB |
12006 | case 3: |
12007 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12008 | et = neon_check_type (3, rs, | |
12009 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
12010 | break; | |
12011 | ||
12012 | default: | |
12013 | abort (); | |
12014 | } | |
12015 | ||
12016 | if (et.type != NT_invtype) | |
12017 | { | |
12018 | pfn (rs); | |
12019 | return SUCCESS; | |
12020 | } | |
12021 | else | |
12022 | inst.error = NULL; | |
12023 | ||
12024 | return FAIL; | |
12025 | } | |
12026 | ||
12027 | static void | |
12028 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
12029 | { | |
12030 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 12031 | |
037e8744 JB |
12032 | if (rs == NS_FFF) |
12033 | { | |
12034 | if (is_mla) | |
12035 | do_vfp_nsyn_opcode ("fmacs"); | |
12036 | else | |
12037 | do_vfp_nsyn_opcode ("fmscs"); | |
12038 | } | |
12039 | else | |
12040 | { | |
12041 | if (is_mla) | |
12042 | do_vfp_nsyn_opcode ("fmacd"); | |
12043 | else | |
12044 | do_vfp_nsyn_opcode ("fmscd"); | |
12045 | } | |
12046 | } | |
12047 | ||
12048 | static void | |
12049 | do_vfp_nsyn_mul (enum neon_shape rs) | |
12050 | { | |
12051 | if (rs == NS_FFF) | |
12052 | do_vfp_nsyn_opcode ("fmuls"); | |
12053 | else | |
12054 | do_vfp_nsyn_opcode ("fmuld"); | |
12055 | } | |
12056 | ||
12057 | static void | |
12058 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
12059 | { | |
12060 | int is_neg = (inst.instruction & 0x80) != 0; | |
12061 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
12062 | ||
12063 | if (rs == NS_FF) | |
12064 | { | |
12065 | if (is_neg) | |
12066 | do_vfp_nsyn_opcode ("fnegs"); | |
12067 | else | |
12068 | do_vfp_nsyn_opcode ("fabss"); | |
12069 | } | |
12070 | else | |
12071 | { | |
12072 | if (is_neg) | |
12073 | do_vfp_nsyn_opcode ("fnegd"); | |
12074 | else | |
12075 | do_vfp_nsyn_opcode ("fabsd"); | |
12076 | } | |
12077 | } | |
12078 | ||
12079 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
12080 | insns belong to Neon, and are handled elsewhere. */ | |
12081 | ||
12082 | static void | |
12083 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
12084 | { | |
12085 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
12086 | if (is_ldm) | |
12087 | { | |
12088 | if (is_dbmode) | |
12089 | do_vfp_nsyn_opcode ("fldmdbs"); | |
12090 | else | |
12091 | do_vfp_nsyn_opcode ("fldmias"); | |
12092 | } | |
12093 | else | |
12094 | { | |
12095 | if (is_dbmode) | |
12096 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12097 | else | |
12098 | do_vfp_nsyn_opcode ("fstmias"); | |
12099 | } | |
12100 | } | |
12101 | ||
037e8744 JB |
12102 | static void |
12103 | do_vfp_nsyn_sqrt (void) | |
12104 | { | |
12105 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12106 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12107 | |
037e8744 JB |
12108 | if (rs == NS_FF) |
12109 | do_vfp_nsyn_opcode ("fsqrts"); | |
12110 | else | |
12111 | do_vfp_nsyn_opcode ("fsqrtd"); | |
12112 | } | |
12113 | ||
12114 | static void | |
12115 | do_vfp_nsyn_div (void) | |
12116 | { | |
12117 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12118 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12119 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12120 | |
037e8744 JB |
12121 | if (rs == NS_FFF) |
12122 | do_vfp_nsyn_opcode ("fdivs"); | |
12123 | else | |
12124 | do_vfp_nsyn_opcode ("fdivd"); | |
12125 | } | |
12126 | ||
12127 | static void | |
12128 | do_vfp_nsyn_nmul (void) | |
12129 | { | |
12130 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
12131 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
12132 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12133 | |
037e8744 JB |
12134 | if (rs == NS_FFF) |
12135 | { | |
12136 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12137 | do_vfp_sp_dyadic (); | |
12138 | } | |
12139 | else | |
12140 | { | |
12141 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12142 | do_vfp_dp_rd_rn_rm (); | |
12143 | } | |
12144 | do_vfp_cond_or_thumb (); | |
12145 | } | |
12146 | ||
12147 | static void | |
12148 | do_vfp_nsyn_cmp (void) | |
12149 | { | |
12150 | if (inst.operands[1].isreg) | |
12151 | { | |
12152 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
12153 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 12154 | |
037e8744 JB |
12155 | if (rs == NS_FF) |
12156 | { | |
12157 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12158 | do_vfp_sp_monadic (); | |
12159 | } | |
12160 | else | |
12161 | { | |
12162 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12163 | do_vfp_dp_rd_rm (); | |
12164 | } | |
12165 | } | |
12166 | else | |
12167 | { | |
12168 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
12169 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
12170 | ||
12171 | switch (inst.instruction & 0x0fffffff) | |
12172 | { | |
12173 | case N_MNEM_vcmp: | |
12174 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
12175 | break; | |
12176 | case N_MNEM_vcmpe: | |
12177 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
12178 | break; | |
12179 | default: | |
12180 | abort (); | |
12181 | } | |
5f4273c7 | 12182 | |
037e8744 JB |
12183 | if (rs == NS_FI) |
12184 | { | |
12185 | inst.instruction = NEON_ENC_SINGLE (inst.instruction); | |
12186 | do_vfp_sp_compare_z (); | |
12187 | } | |
12188 | else | |
12189 | { | |
12190 | inst.instruction = NEON_ENC_DOUBLE (inst.instruction); | |
12191 | do_vfp_dp_rd (); | |
12192 | } | |
12193 | } | |
12194 | do_vfp_cond_or_thumb (); | |
12195 | } | |
12196 | ||
12197 | static void | |
12198 | nsyn_insert_sp (void) | |
12199 | { | |
12200 | inst.operands[1] = inst.operands[0]; | |
12201 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 12202 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
12203 | inst.operands[0].isreg = 1; |
12204 | inst.operands[0].writeback = 1; | |
12205 | inst.operands[0].present = 1; | |
12206 | } | |
12207 | ||
12208 | static void | |
12209 | do_vfp_nsyn_push (void) | |
12210 | { | |
12211 | nsyn_insert_sp (); | |
12212 | if (inst.operands[1].issingle) | |
12213 | do_vfp_nsyn_opcode ("fstmdbs"); | |
12214 | else | |
12215 | do_vfp_nsyn_opcode ("fstmdbd"); | |
12216 | } | |
12217 | ||
12218 | static void | |
12219 | do_vfp_nsyn_pop (void) | |
12220 | { | |
12221 | nsyn_insert_sp (); | |
12222 | if (inst.operands[1].issingle) | |
22b5b651 | 12223 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 12224 | else |
22b5b651 | 12225 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
12226 | } |
12227 | ||
12228 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
12229 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
12230 | ||
12231 | static unsigned | |
12232 | neon_dp_fixup (unsigned i) | |
12233 | { | |
12234 | if (thumb_mode) | |
12235 | { | |
12236 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
12237 | if (i & (1 << 24)) | |
12238 | i |= 1 << 28; | |
5f4273c7 | 12239 | |
037e8744 | 12240 | i &= ~(1 << 24); |
5f4273c7 | 12241 | |
037e8744 JB |
12242 | i |= 0xef000000; |
12243 | } | |
12244 | else | |
12245 | i |= 0xf2000000; | |
5f4273c7 | 12246 | |
037e8744 JB |
12247 | return i; |
12248 | } | |
12249 | ||
12250 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
12251 | (0, 1, 2, 3). */ | |
12252 | ||
12253 | static unsigned | |
12254 | neon_logbits (unsigned x) | |
12255 | { | |
12256 | return ffs (x) - 4; | |
12257 | } | |
12258 | ||
12259 | #define LOW4(R) ((R) & 0xf) | |
12260 | #define HI1(R) (((R) >> 4) & 1) | |
12261 | ||
12262 | /* Encode insns with bit pattern: | |
12263 | ||
12264 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
12265 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 12266 | |
037e8744 JB |
12267 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
12268 | different meaning for some instruction. */ | |
12269 | ||
12270 | static void | |
12271 | neon_three_same (int isquad, int ubit, int size) | |
12272 | { | |
12273 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12274 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12275 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12276 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12277 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
12278 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
12279 | inst.instruction |= (isquad != 0) << 6; | |
12280 | inst.instruction |= (ubit != 0) << 24; | |
12281 | if (size != -1) | |
12282 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 12283 | |
037e8744 JB |
12284 | inst.instruction = neon_dp_fixup (inst.instruction); |
12285 | } | |
12286 | ||
12287 | /* Encode instructions of the form: | |
12288 | ||
12289 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
12290 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
12291 | |
12292 | Don't write size if SIZE == -1. */ | |
12293 | ||
12294 | static void | |
12295 | neon_two_same (int qbit, int ubit, int size) | |
12296 | { | |
12297 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12298 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12299 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12300 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12301 | inst.instruction |= (qbit != 0) << 6; | |
12302 | inst.instruction |= (ubit != 0) << 24; | |
12303 | ||
12304 | if (size != -1) | |
12305 | inst.instruction |= neon_logbits (size) << 18; | |
12306 | ||
12307 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12308 | } | |
12309 | ||
12310 | /* Neon instruction encoders, in approximate order of appearance. */ | |
12311 | ||
12312 | static void | |
12313 | do_neon_dyadic_i_su (void) | |
12314 | { | |
037e8744 | 12315 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12316 | struct neon_type_el et = neon_check_type (3, rs, |
12317 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 12318 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12319 | } |
12320 | ||
12321 | static void | |
12322 | do_neon_dyadic_i64_su (void) | |
12323 | { | |
037e8744 | 12324 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12325 | struct neon_type_el et = neon_check_type (3, rs, |
12326 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 12327 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12328 | } |
12329 | ||
12330 | static void | |
12331 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
12332 | unsigned immbits) | |
12333 | { | |
12334 | unsigned size = et.size >> 3; | |
12335 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12336 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12337 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12338 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
12339 | inst.instruction |= (isquad != 0) << 6; | |
12340 | inst.instruction |= immbits << 16; | |
12341 | inst.instruction |= (size >> 3) << 7; | |
12342 | inst.instruction |= (size & 0x7) << 19; | |
12343 | if (write_ubit) | |
12344 | inst.instruction |= (uval != 0) << 24; | |
12345 | ||
12346 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12347 | } | |
12348 | ||
12349 | static void | |
12350 | do_neon_shl_imm (void) | |
12351 | { | |
12352 | if (!inst.operands[2].isreg) | |
12353 | { | |
037e8744 | 12354 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
12355 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
12356 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
037e8744 | 12357 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm); |
5287ad62 JB |
12358 | } |
12359 | else | |
12360 | { | |
037e8744 | 12361 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12362 | struct neon_type_el et = neon_check_type (3, rs, |
12363 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12364 | unsigned int tmp; |
12365 | ||
12366 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
12367 | vshl.xx Dd, Dm, Dn | |
12368 | whereas other 3-register operations encoded by neon_three_same have | |
12369 | syntax like: | |
12370 | vadd.xx Dd, Dn, Dm | |
12371 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
12372 | here. */ | |
12373 | tmp = inst.operands[2].reg; | |
12374 | inst.operands[2].reg = inst.operands[1].reg; | |
12375 | inst.operands[1].reg = tmp; | |
5287ad62 | 12376 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
037e8744 | 12377 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12378 | } |
12379 | } | |
12380 | ||
12381 | static void | |
12382 | do_neon_qshl_imm (void) | |
12383 | { | |
12384 | if (!inst.operands[2].isreg) | |
12385 | { | |
037e8744 | 12386 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 12387 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
627907b7 | 12388 | |
5287ad62 | 12389 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
037e8744 | 12390 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
12391 | inst.operands[2].imm); |
12392 | } | |
12393 | else | |
12394 | { | |
037e8744 | 12395 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12396 | struct neon_type_el et = neon_check_type (3, rs, |
12397 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
627907b7 JB |
12398 | unsigned int tmp; |
12399 | ||
12400 | /* See note in do_neon_shl_imm. */ | |
12401 | tmp = inst.operands[2].reg; | |
12402 | inst.operands[2].reg = inst.operands[1].reg; | |
12403 | inst.operands[1].reg = tmp; | |
5287ad62 | 12404 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
037e8744 | 12405 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
12406 | } |
12407 | } | |
12408 | ||
627907b7 JB |
12409 | static void |
12410 | do_neon_rshl (void) | |
12411 | { | |
12412 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
12413 | struct neon_type_el et = neon_check_type (3, rs, | |
12414 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
12415 | unsigned int tmp; | |
12416 | ||
12417 | tmp = inst.operands[2].reg; | |
12418 | inst.operands[2].reg = inst.operands[1].reg; | |
12419 | inst.operands[1].reg = tmp; | |
12420 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
12421 | } | |
12422 | ||
5287ad62 JB |
12423 | static int |
12424 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
12425 | { | |
036dc3f7 PB |
12426 | /* Handle .I8 pseudo-instructions. */ |
12427 | if (size == 8) | |
5287ad62 | 12428 | { |
5287ad62 JB |
12429 | /* Unfortunately, this will make everything apart from zero out-of-range. |
12430 | FIXME is this the intended semantics? There doesn't seem much point in | |
12431 | accepting .I8 if so. */ | |
12432 | immediate |= immediate << 8; | |
12433 | size = 16; | |
036dc3f7 PB |
12434 | } |
12435 | ||
12436 | if (size >= 32) | |
12437 | { | |
12438 | if (immediate == (immediate & 0x000000ff)) | |
12439 | { | |
12440 | *immbits = immediate; | |
12441 | return 0x1; | |
12442 | } | |
12443 | else if (immediate == (immediate & 0x0000ff00)) | |
12444 | { | |
12445 | *immbits = immediate >> 8; | |
12446 | return 0x3; | |
12447 | } | |
12448 | else if (immediate == (immediate & 0x00ff0000)) | |
12449 | { | |
12450 | *immbits = immediate >> 16; | |
12451 | return 0x5; | |
12452 | } | |
12453 | else if (immediate == (immediate & 0xff000000)) | |
12454 | { | |
12455 | *immbits = immediate >> 24; | |
12456 | return 0x7; | |
12457 | } | |
12458 | if ((immediate & 0xffff) != (immediate >> 16)) | |
12459 | goto bad_immediate; | |
12460 | immediate &= 0xffff; | |
5287ad62 JB |
12461 | } |
12462 | ||
12463 | if (immediate == (immediate & 0x000000ff)) | |
12464 | { | |
12465 | *immbits = immediate; | |
036dc3f7 | 12466 | return 0x9; |
5287ad62 JB |
12467 | } |
12468 | else if (immediate == (immediate & 0x0000ff00)) | |
12469 | { | |
12470 | *immbits = immediate >> 8; | |
036dc3f7 | 12471 | return 0xb; |
5287ad62 JB |
12472 | } |
12473 | ||
12474 | bad_immediate: | |
dcbf9037 | 12475 | first_error (_("immediate value out of range")); |
5287ad62 JB |
12476 | return FAIL; |
12477 | } | |
12478 | ||
12479 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
12480 | A, B, C, D. */ | |
12481 | ||
12482 | static int | |
12483 | neon_bits_same_in_bytes (unsigned imm) | |
12484 | { | |
12485 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) | |
12486 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
12487 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
12488 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
12489 | } | |
12490 | ||
12491 | /* For immediate of above form, return 0bABCD. */ | |
12492 | ||
12493 | static unsigned | |
12494 | neon_squash_bits (unsigned imm) | |
12495 | { | |
12496 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
12497 | | ((imm & 0x01000000) >> 21); | |
12498 | } | |
12499 | ||
136da414 | 12500 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ |
5287ad62 JB |
12501 | |
12502 | static unsigned | |
12503 | neon_qfloat_bits (unsigned imm) | |
12504 | { | |
136da414 | 12505 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); |
5287ad62 JB |
12506 | } |
12507 | ||
12508 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
12509 | the instruction. *OP is passed as the initial value of the op field, and | |
12510 | may be set to a different value depending on the constant (i.e. | |
12511 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
5f4273c7 | 12512 | MVN). If the immediate looks like a repeated pattern then also |
036dc3f7 | 12513 | try smaller element sizes. */ |
5287ad62 JB |
12514 | |
12515 | static int | |
c96612cc JB |
12516 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, |
12517 | unsigned *immbits, int *op, int size, | |
12518 | enum neon_el_type type) | |
5287ad62 | 12519 | { |
c96612cc JB |
12520 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is |
12521 | float. */ | |
12522 | if (type == NT_float && !float_p) | |
12523 | return FAIL; | |
12524 | ||
136da414 JB |
12525 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) |
12526 | { | |
12527 | if (size != 32 || *op == 1) | |
12528 | return FAIL; | |
12529 | *immbits = neon_qfloat_bits (immlo); | |
12530 | return 0xf; | |
12531 | } | |
036dc3f7 PB |
12532 | |
12533 | if (size == 64) | |
5287ad62 | 12534 | { |
036dc3f7 PB |
12535 | if (neon_bits_same_in_bytes (immhi) |
12536 | && neon_bits_same_in_bytes (immlo)) | |
12537 | { | |
12538 | if (*op == 1) | |
12539 | return FAIL; | |
12540 | *immbits = (neon_squash_bits (immhi) << 4) | |
12541 | | neon_squash_bits (immlo); | |
12542 | *op = 1; | |
12543 | return 0xe; | |
12544 | } | |
12545 | ||
12546 | if (immhi != immlo) | |
12547 | return FAIL; | |
5287ad62 | 12548 | } |
036dc3f7 PB |
12549 | |
12550 | if (size >= 32) | |
5287ad62 | 12551 | { |
036dc3f7 PB |
12552 | if (immlo == (immlo & 0x000000ff)) |
12553 | { | |
12554 | *immbits = immlo; | |
12555 | return 0x0; | |
12556 | } | |
12557 | else if (immlo == (immlo & 0x0000ff00)) | |
12558 | { | |
12559 | *immbits = immlo >> 8; | |
12560 | return 0x2; | |
12561 | } | |
12562 | else if (immlo == (immlo & 0x00ff0000)) | |
12563 | { | |
12564 | *immbits = immlo >> 16; | |
12565 | return 0x4; | |
12566 | } | |
12567 | else if (immlo == (immlo & 0xff000000)) | |
12568 | { | |
12569 | *immbits = immlo >> 24; | |
12570 | return 0x6; | |
12571 | } | |
12572 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
12573 | { | |
12574 | *immbits = (immlo >> 8) & 0xff; | |
12575 | return 0xc; | |
12576 | } | |
12577 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
12578 | { | |
12579 | *immbits = (immlo >> 16) & 0xff; | |
12580 | return 0xd; | |
12581 | } | |
12582 | ||
12583 | if ((immlo & 0xffff) != (immlo >> 16)) | |
12584 | return FAIL; | |
12585 | immlo &= 0xffff; | |
5287ad62 | 12586 | } |
036dc3f7 PB |
12587 | |
12588 | if (size >= 16) | |
5287ad62 | 12589 | { |
036dc3f7 PB |
12590 | if (immlo == (immlo & 0x000000ff)) |
12591 | { | |
12592 | *immbits = immlo; | |
12593 | return 0x8; | |
12594 | } | |
12595 | else if (immlo == (immlo & 0x0000ff00)) | |
12596 | { | |
12597 | *immbits = immlo >> 8; | |
12598 | return 0xa; | |
12599 | } | |
12600 | ||
12601 | if ((immlo & 0xff) != (immlo >> 8)) | |
12602 | return FAIL; | |
12603 | immlo &= 0xff; | |
5287ad62 | 12604 | } |
036dc3f7 PB |
12605 | |
12606 | if (immlo == (immlo & 0x000000ff)) | |
5287ad62 | 12607 | { |
036dc3f7 PB |
12608 | /* Don't allow MVN with 8-bit immediate. */ |
12609 | if (*op == 1) | |
12610 | return FAIL; | |
12611 | *immbits = immlo; | |
12612 | return 0xe; | |
5287ad62 | 12613 | } |
5287ad62 JB |
12614 | |
12615 | return FAIL; | |
12616 | } | |
12617 | ||
12618 | /* Write immediate bits [7:0] to the following locations: | |
12619 | ||
12620 | |28/24|23 19|18 16|15 4|3 0| | |
12621 | | 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| | |
12622 | ||
12623 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
12624 | ||
12625 | static void | |
12626 | neon_write_immbits (unsigned immbits) | |
12627 | { | |
12628 | inst.instruction |= immbits & 0xf; | |
12629 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
12630 | inst.instruction |= ((immbits >> 7) & 0x1) << 24; | |
12631 | } | |
12632 | ||
12633 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
12634 | ||
12635 | static void | |
12636 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
12637 | { | |
12638 | unsigned immlo = xlo ? *xlo : 0; | |
12639 | unsigned immhi = xhi ? *xhi : 0; | |
12640 | ||
12641 | switch (size) | |
12642 | { | |
12643 | case 8: | |
12644 | immlo = (~immlo) & 0xff; | |
12645 | break; | |
12646 | ||
12647 | case 16: | |
12648 | immlo = (~immlo) & 0xffff; | |
12649 | break; | |
12650 | ||
12651 | case 64: | |
12652 | immhi = (~immhi) & 0xffffffff; | |
12653 | /* fall through. */ | |
12654 | ||
12655 | case 32: | |
12656 | immlo = (~immlo) & 0xffffffff; | |
12657 | break; | |
12658 | ||
12659 | default: | |
12660 | abort (); | |
12661 | } | |
12662 | ||
12663 | if (xlo) | |
12664 | *xlo = immlo; | |
12665 | ||
12666 | if (xhi) | |
12667 | *xhi = immhi; | |
12668 | } | |
12669 | ||
12670 | static void | |
12671 | do_neon_logic (void) | |
12672 | { | |
12673 | if (inst.operands[2].present && inst.operands[2].isreg) | |
12674 | { | |
037e8744 | 12675 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
12676 | neon_check_type (3, rs, N_IGNORE_TYPE); |
12677 | /* U bit and size field were set as part of the bitmask. */ | |
12678 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12679 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12680 | } |
12681 | else | |
12682 | { | |
037e8744 JB |
12683 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
12684 | struct neon_type_el et = neon_check_type (2, rs, | |
12685 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 JB |
12686 | enum neon_opc opcode = inst.instruction & 0x0fffffff; |
12687 | unsigned immbits; | |
12688 | int cmode; | |
5f4273c7 | 12689 | |
5287ad62 JB |
12690 | if (et.type == NT_invtype) |
12691 | return; | |
5f4273c7 | 12692 | |
5287ad62 JB |
12693 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
12694 | ||
036dc3f7 PB |
12695 | immbits = inst.operands[1].imm; |
12696 | if (et.size == 64) | |
12697 | { | |
12698 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
12699 | pattern. */ | |
12700 | if (immbits != (inst.operands[1].regisimm ? | |
12701 | inst.operands[1].reg : 0)) | |
12702 | { | |
12703 | /* Set immbits to an invalid constant. */ | |
12704 | immbits = 0xdeadbeef; | |
12705 | } | |
12706 | } | |
12707 | ||
5287ad62 JB |
12708 | switch (opcode) |
12709 | { | |
12710 | case N_MNEM_vbic: | |
036dc3f7 | 12711 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 12712 | break; |
5f4273c7 | 12713 | |
5287ad62 | 12714 | case N_MNEM_vorr: |
036dc3f7 | 12715 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); |
5287ad62 | 12716 | break; |
5f4273c7 | 12717 | |
5287ad62 JB |
12718 | case N_MNEM_vand: |
12719 | /* Pseudo-instruction for VBIC. */ | |
5287ad62 JB |
12720 | neon_invert_size (&immbits, 0, et.size); |
12721 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
12722 | break; | |
5f4273c7 | 12723 | |
5287ad62 JB |
12724 | case N_MNEM_vorn: |
12725 | /* Pseudo-instruction for VORR. */ | |
5287ad62 JB |
12726 | neon_invert_size (&immbits, 0, et.size); |
12727 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
12728 | break; | |
5f4273c7 | 12729 | |
5287ad62 JB |
12730 | default: |
12731 | abort (); | |
12732 | } | |
12733 | ||
12734 | if (cmode == FAIL) | |
12735 | return; | |
12736 | ||
037e8744 | 12737 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12738 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
12739 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12740 | inst.instruction |= cmode << 8; | |
12741 | neon_write_immbits (immbits); | |
5f4273c7 | 12742 | |
5287ad62 JB |
12743 | inst.instruction = neon_dp_fixup (inst.instruction); |
12744 | } | |
12745 | } | |
12746 | ||
12747 | static void | |
12748 | do_neon_bitfield (void) | |
12749 | { | |
037e8744 | 12750 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 12751 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 12752 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12753 | } |
12754 | ||
12755 | static void | |
dcbf9037 JB |
12756 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
12757 | unsigned destbits) | |
5287ad62 | 12758 | { |
037e8744 | 12759 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 JB |
12760 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
12761 | types | N_KEY); | |
5287ad62 JB |
12762 | if (et.type == NT_float) |
12763 | { | |
12764 | inst.instruction = NEON_ENC_FLOAT (inst.instruction); | |
037e8744 | 12765 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
12766 | } |
12767 | else | |
12768 | { | |
12769 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 12770 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
12771 | } |
12772 | } | |
12773 | ||
12774 | static void | |
12775 | do_neon_dyadic_if_su (void) | |
12776 | { | |
dcbf9037 | 12777 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
12778 | } |
12779 | ||
12780 | static void | |
12781 | do_neon_dyadic_if_su_d (void) | |
12782 | { | |
12783 | /* This version only allow D registers, but that constraint is enforced during | |
12784 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 12785 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
12786 | } |
12787 | ||
5287ad62 JB |
12788 | static void |
12789 | do_neon_dyadic_if_i_d (void) | |
12790 | { | |
428e3f1f PB |
12791 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
12792 | affected if we specify unsigned args. */ | |
12793 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
12794 | } |
12795 | ||
037e8744 JB |
12796 | enum vfp_or_neon_is_neon_bits |
12797 | { | |
12798 | NEON_CHECK_CC = 1, | |
12799 | NEON_CHECK_ARCH = 2 | |
12800 | }; | |
12801 | ||
12802 | /* Call this function if an instruction which may have belonged to the VFP or | |
12803 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
12804 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
12805 | things: | |
12806 | ||
12807 | - Make sure the user hasn't attempted to make a Neon instruction | |
12808 | conditional. | |
12809 | - Alter the value in the condition code field if necessary. | |
12810 | - Make sure that the arch supports Neon instructions. | |
12811 | ||
12812 | Which of these operations take place depends on bits from enum | |
12813 | vfp_or_neon_is_neon_bits. | |
12814 | ||
12815 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
12816 | current instruction's condition is COND_ALWAYS, the condition field is | |
12817 | changed to inst.uncond_value. This is necessary because instructions shared | |
12818 | between VFP and Neon may be conditional for the VFP variants only, and the | |
12819 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
12820 | ||
12821 | static int | |
12822 | vfp_or_neon_is_neon (unsigned check) | |
12823 | { | |
12824 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
12825 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
12826 | { | |
12827 | if (inst.cond != COND_ALWAYS) | |
12828 | { | |
12829 | first_error (_(BAD_COND)); | |
12830 | return FAIL; | |
12831 | } | |
12832 | if (inst.uncond_value != -1) | |
12833 | inst.instruction |= inst.uncond_value << 28; | |
12834 | } | |
5f4273c7 | 12835 | |
037e8744 JB |
12836 | if ((check & NEON_CHECK_ARCH) |
12837 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
12838 | { | |
12839 | first_error (_(BAD_FPU)); | |
12840 | return FAIL; | |
12841 | } | |
5f4273c7 | 12842 | |
037e8744 JB |
12843 | return SUCCESS; |
12844 | } | |
12845 | ||
5287ad62 JB |
12846 | static void |
12847 | do_neon_addsub_if_i (void) | |
12848 | { | |
037e8744 JB |
12849 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
12850 | return; | |
12851 | ||
12852 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12853 | return; | |
12854 | ||
5287ad62 JB |
12855 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
12856 | affected if we specify unsigned args. */ | |
dcbf9037 | 12857 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
12858 | } |
12859 | ||
12860 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
12861 | result to be: | |
12862 | V<op> A,B (A is operand 0, B is operand 2) | |
12863 | to mean: | |
12864 | V<op> A,B,A | |
12865 | not: | |
12866 | V<op> A,B,B | |
12867 | so handle that case specially. */ | |
12868 | ||
12869 | static void | |
12870 | neon_exchange_operands (void) | |
12871 | { | |
12872 | void *scratch = alloca (sizeof (inst.operands[0])); | |
12873 | if (inst.operands[1].present) | |
12874 | { | |
12875 | /* Swap operands[1] and operands[2]. */ | |
12876 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
12877 | inst.operands[1] = inst.operands[2]; | |
12878 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
12879 | } | |
12880 | else | |
12881 | { | |
12882 | inst.operands[1] = inst.operands[2]; | |
12883 | inst.operands[2] = inst.operands[0]; | |
12884 | } | |
12885 | } | |
12886 | ||
12887 | static void | |
12888 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
12889 | { | |
12890 | if (inst.operands[2].isreg) | |
12891 | { | |
12892 | if (invert) | |
12893 | neon_exchange_operands (); | |
dcbf9037 | 12894 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
12895 | } |
12896 | else | |
12897 | { | |
037e8744 | 12898 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 JB |
12899 | struct neon_type_el et = neon_check_type (2, rs, |
12900 | N_EQK | N_SIZ, immtypes | N_KEY); | |
5287ad62 JB |
12901 | |
12902 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
12903 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
12904 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12905 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
12906 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 12907 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
12908 | inst.instruction |= (et.type == NT_float) << 10; |
12909 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 12910 | |
5287ad62 JB |
12911 | inst.instruction = neon_dp_fixup (inst.instruction); |
12912 | } | |
12913 | } | |
12914 | ||
12915 | static void | |
12916 | do_neon_cmp (void) | |
12917 | { | |
12918 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
12919 | } | |
12920 | ||
12921 | static void | |
12922 | do_neon_cmp_inv (void) | |
12923 | { | |
12924 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
12925 | } | |
12926 | ||
12927 | static void | |
12928 | do_neon_ceq (void) | |
12929 | { | |
12930 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
12931 | } | |
12932 | ||
12933 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
12934 | scalars, which are encoded in 5 bits, M : Rm. | |
12935 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
12936 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
12937 | index in M. */ | |
12938 | ||
12939 | static unsigned | |
12940 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
12941 | { | |
dcbf9037 JB |
12942 | unsigned regno = NEON_SCALAR_REG (scalar); |
12943 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
12944 | |
12945 | switch (elsize) | |
12946 | { | |
12947 | case 16: | |
12948 | if (regno > 7 || elno > 3) | |
12949 | goto bad_scalar; | |
12950 | return regno | (elno << 3); | |
5f4273c7 | 12951 | |
5287ad62 JB |
12952 | case 32: |
12953 | if (regno > 15 || elno > 1) | |
12954 | goto bad_scalar; | |
12955 | return regno | (elno << 4); | |
12956 | ||
12957 | default: | |
12958 | bad_scalar: | |
dcbf9037 | 12959 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
12960 | } |
12961 | ||
12962 | return 0; | |
12963 | } | |
12964 | ||
12965 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
12966 | ||
12967 | static void | |
12968 | neon_mul_mac (struct neon_type_el et, int ubit) | |
12969 | { | |
dcbf9037 JB |
12970 | unsigned scalar; |
12971 | ||
12972 | /* Give a more helpful error message if we have an invalid type. */ | |
12973 | if (et.type == NT_invtype) | |
12974 | return; | |
5f4273c7 | 12975 | |
dcbf9037 | 12976 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
12977 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
12978 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
12979 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
12980 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
12981 | inst.instruction |= LOW4 (scalar); | |
12982 | inst.instruction |= HI1 (scalar) << 5; | |
12983 | inst.instruction |= (et.type == NT_float) << 8; | |
12984 | inst.instruction |= neon_logbits (et.size) << 20; | |
12985 | inst.instruction |= (ubit != 0) << 24; | |
12986 | ||
12987 | inst.instruction = neon_dp_fixup (inst.instruction); | |
12988 | } | |
12989 | ||
12990 | static void | |
12991 | do_neon_mac_maybe_scalar (void) | |
12992 | { | |
037e8744 JB |
12993 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
12994 | return; | |
12995 | ||
12996 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
12997 | return; | |
12998 | ||
5287ad62 JB |
12999 | if (inst.operands[2].isscalar) |
13000 | { | |
037e8744 | 13001 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13002 | struct neon_type_el et = neon_check_type (3, rs, |
13003 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); | |
13004 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 13005 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13006 | } |
13007 | else | |
428e3f1f PB |
13008 | { |
13009 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
13010 | affected if we specify unsigned args. */ | |
13011 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
13012 | } | |
5287ad62 JB |
13013 | } |
13014 | ||
13015 | static void | |
13016 | do_neon_tst (void) | |
13017 | { | |
037e8744 | 13018 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13019 | struct neon_type_el et = neon_check_type (3, rs, |
13020 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 13021 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13022 | } |
13023 | ||
13024 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
13025 | same types as the MAC equivalents. The polynomial type for this instruction | |
13026 | is encoded the same as the integer type. */ | |
13027 | ||
13028 | static void | |
13029 | do_neon_mul (void) | |
13030 | { | |
037e8744 JB |
13031 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
13032 | return; | |
13033 | ||
13034 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13035 | return; | |
13036 | ||
5287ad62 JB |
13037 | if (inst.operands[2].isscalar) |
13038 | do_neon_mac_maybe_scalar (); | |
13039 | else | |
dcbf9037 | 13040 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
13041 | } |
13042 | ||
13043 | static void | |
13044 | do_neon_qdmulh (void) | |
13045 | { | |
13046 | if (inst.operands[2].isscalar) | |
13047 | { | |
037e8744 | 13048 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 JB |
13049 | struct neon_type_el et = neon_check_type (3, rs, |
13050 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
13051 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); | |
037e8744 | 13052 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
13053 | } |
13054 | else | |
13055 | { | |
037e8744 | 13056 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13057 | struct neon_type_el et = neon_check_type (3, rs, |
13058 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
13059 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13060 | /* The U bit (rounding) comes from bit mask. */ | |
037e8744 | 13061 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
13062 | } |
13063 | } | |
13064 | ||
13065 | static void | |
13066 | do_neon_fcmp_absolute (void) | |
13067 | { | |
037e8744 | 13068 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
13069 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
13070 | /* Size field comes from bit mask. */ | |
037e8744 | 13071 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
13072 | } |
13073 | ||
13074 | static void | |
13075 | do_neon_fcmp_absolute_inv (void) | |
13076 | { | |
13077 | neon_exchange_operands (); | |
13078 | do_neon_fcmp_absolute (); | |
13079 | } | |
13080 | ||
13081 | static void | |
13082 | do_neon_step (void) | |
13083 | { | |
037e8744 | 13084 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 13085 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 13086 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
13087 | } |
13088 | ||
13089 | static void | |
13090 | do_neon_abs_neg (void) | |
13091 | { | |
037e8744 JB |
13092 | enum neon_shape rs; |
13093 | struct neon_type_el et; | |
5f4273c7 | 13094 | |
037e8744 JB |
13095 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
13096 | return; | |
13097 | ||
13098 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13099 | return; | |
13100 | ||
13101 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
13102 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
5f4273c7 | 13103 | |
5287ad62 JB |
13104 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13105 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13106 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13107 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13108 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13109 | inst.instruction |= (et.type == NT_float) << 10; |
13110 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13111 | |
5287ad62 JB |
13112 | inst.instruction = neon_dp_fixup (inst.instruction); |
13113 | } | |
13114 | ||
13115 | static void | |
13116 | do_neon_sli (void) | |
13117 | { | |
037e8744 | 13118 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13119 | struct neon_type_el et = neon_check_type (2, rs, |
13120 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13121 | int imm = inst.operands[2].imm; | |
13122 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13123 | _("immediate out of range for insert")); | |
037e8744 | 13124 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13125 | } |
13126 | ||
13127 | static void | |
13128 | do_neon_sri (void) | |
13129 | { | |
037e8744 | 13130 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13131 | struct neon_type_el et = neon_check_type (2, rs, |
13132 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13133 | int imm = inst.operands[2].imm; | |
13134 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13135 | _("immediate out of range for insert")); | |
037e8744 | 13136 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
13137 | } |
13138 | ||
13139 | static void | |
13140 | do_neon_qshlu_imm (void) | |
13141 | { | |
037e8744 | 13142 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
13143 | struct neon_type_el et = neon_check_type (2, rs, |
13144 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
13145 | int imm = inst.operands[2].imm; | |
13146 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
13147 | _("immediate out of range for shift")); | |
13148 | /* Only encodes the 'U present' variant of the instruction. | |
13149 | In this case, signed types have OP (bit 8) set to 0. | |
13150 | Unsigned types have OP set to 1. */ | |
13151 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
13152 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 13153 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
13154 | } |
13155 | ||
13156 | static void | |
13157 | do_neon_qmovn (void) | |
13158 | { | |
13159 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13160 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13161 | /* Saturating move where operands can be signed or unsigned, and the | |
13162 | destination has the same signedness. */ | |
13163 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13164 | if (et.type == NT_unsigned) | |
13165 | inst.instruction |= 0xc0; | |
13166 | else | |
13167 | inst.instruction |= 0x80; | |
13168 | neon_two_same (0, 1, et.size / 2); | |
13169 | } | |
13170 | ||
13171 | static void | |
13172 | do_neon_qmovun (void) | |
13173 | { | |
13174 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13175 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13176 | /* Saturating move with unsigned results. Operands must be signed. */ | |
13177 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13178 | neon_two_same (0, 1, et.size / 2); | |
13179 | } | |
13180 | ||
13181 | static void | |
13182 | do_neon_rshift_sat_narrow (void) | |
13183 | { | |
13184 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13185 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13186 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13187 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
13188 | int imm = inst.operands[2].imm; | |
13189 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13190 | right. */ | |
13191 | et.size /= 2; | |
5f4273c7 | 13192 | |
5287ad62 JB |
13193 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
13194 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
13195 | if (imm == 0) | |
13196 | { | |
13197 | inst.operands[2].present = 0; | |
13198 | inst.instruction = N_MNEM_vqmovn; | |
13199 | do_neon_qmovn (); | |
13200 | return; | |
13201 | } | |
5f4273c7 | 13202 | |
5287ad62 JB |
13203 | constraint (imm < 1 || (unsigned)imm > et.size, |
13204 | _("immediate out of range")); | |
13205 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); | |
13206 | } | |
13207 | ||
13208 | static void | |
13209 | do_neon_rshift_sat_narrow_u (void) | |
13210 | { | |
13211 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
13212 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
13213 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13214 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
13215 | int imm = inst.operands[2].imm; | |
13216 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13217 | right. */ | |
13218 | et.size /= 2; | |
13219 | ||
13220 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
13221 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
13222 | if (imm == 0) | |
13223 | { | |
13224 | inst.operands[2].present = 0; | |
13225 | inst.instruction = N_MNEM_vqmovun; | |
13226 | do_neon_qmovun (); | |
13227 | return; | |
13228 | } | |
13229 | ||
13230 | constraint (imm < 1 || (unsigned)imm > et.size, | |
13231 | _("immediate out of range")); | |
13232 | /* FIXME: The manual is kind of unclear about what value U should have in | |
13233 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
13234 | must be 1. */ | |
13235 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
13236 | } | |
13237 | ||
13238 | static void | |
13239 | do_neon_movn (void) | |
13240 | { | |
13241 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
13242 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13243 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13244 | neon_two_same (0, 1, et.size / 2); | |
13245 | } | |
13246 | ||
13247 | static void | |
13248 | do_neon_rshift_narrow (void) | |
13249 | { | |
13250 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
13251 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
13252 | int imm = inst.operands[2].imm; | |
13253 | /* This gets the bounds check, size encoding and immediate bits calculation | |
13254 | right. */ | |
13255 | et.size /= 2; | |
5f4273c7 | 13256 | |
5287ad62 JB |
13257 | /* If immediate is zero then we are a pseudo-instruction for |
13258 | VMOVN.I<size> <Dd>, <Qm> */ | |
13259 | if (imm == 0) | |
13260 | { | |
13261 | inst.operands[2].present = 0; | |
13262 | inst.instruction = N_MNEM_vmovn; | |
13263 | do_neon_movn (); | |
13264 | return; | |
13265 | } | |
5f4273c7 | 13266 | |
5287ad62 JB |
13267 | constraint (imm < 1 || (unsigned)imm > et.size, |
13268 | _("immediate out of range for narrowing operation")); | |
13269 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); | |
13270 | } | |
13271 | ||
13272 | static void | |
13273 | do_neon_shll (void) | |
13274 | { | |
13275 | /* FIXME: Type checking when lengthening. */ | |
13276 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
13277 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
13278 | unsigned imm = inst.operands[2].imm; | |
13279 | ||
13280 | if (imm == et.size) | |
13281 | { | |
13282 | /* Maximum shift variant. */ | |
13283 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13284 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13285 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13286 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13287 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13288 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 13289 | |
5287ad62 JB |
13290 | inst.instruction = neon_dp_fixup (inst.instruction); |
13291 | } | |
13292 | else | |
13293 | { | |
13294 | /* A more-specific type check for non-max versions. */ | |
13295 | et = neon_check_type (2, NS_QDI, | |
13296 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13297 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13298 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); | |
13299 | } | |
13300 | } | |
13301 | ||
037e8744 | 13302 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
13303 | the current instruction is. */ |
13304 | ||
13305 | static int | |
13306 | neon_cvt_flavour (enum neon_shape rs) | |
13307 | { | |
037e8744 JB |
13308 | #define CVT_VAR(C,X,Y) \ |
13309 | et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \ | |
13310 | if (et.type != NT_invtype) \ | |
13311 | { \ | |
13312 | inst.error = NULL; \ | |
13313 | return (C); \ | |
5287ad62 JB |
13314 | } |
13315 | struct neon_type_el et; | |
037e8744 JB |
13316 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
13317 | || rs == NS_FF) ? N_VFP : 0; | |
13318 | /* The instruction versions which take an immediate take one register | |
13319 | argument, which is extended to the width of the full register. Thus the | |
13320 | "source" and "destination" registers must have the same width. Hack that | |
13321 | here by making the size equal to the key (wider, in this case) operand. */ | |
13322 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 13323 | |
5287ad62 JB |
13324 | CVT_VAR (0, N_S32, N_F32); |
13325 | CVT_VAR (1, N_U32, N_F32); | |
13326 | CVT_VAR (2, N_F32, N_S32); | |
13327 | CVT_VAR (3, N_F32, N_U32); | |
8e79c3df CM |
13328 | /* Half-precision conversions. */ |
13329 | CVT_VAR (4, N_F32, N_F16); | |
13330 | CVT_VAR (5, N_F16, N_F32); | |
5f4273c7 | 13331 | |
037e8744 | 13332 | whole_reg = N_VFP; |
5f4273c7 | 13333 | |
037e8744 | 13334 | /* VFP instructions. */ |
8e79c3df CM |
13335 | CVT_VAR (6, N_F32, N_F64); |
13336 | CVT_VAR (7, N_F64, N_F32); | |
13337 | CVT_VAR (8, N_S32, N_F64 | key); | |
13338 | CVT_VAR (9, N_U32, N_F64 | key); | |
13339 | CVT_VAR (10, N_F64 | key, N_S32); | |
13340 | CVT_VAR (11, N_F64 | key, N_U32); | |
037e8744 | 13341 | /* VFP instructions with bitshift. */ |
8e79c3df CM |
13342 | CVT_VAR (12, N_F32 | key, N_S16); |
13343 | CVT_VAR (13, N_F32 | key, N_U16); | |
13344 | CVT_VAR (14, N_F64 | key, N_S16); | |
13345 | CVT_VAR (15, N_F64 | key, N_U16); | |
13346 | CVT_VAR (16, N_S16, N_F32 | key); | |
13347 | CVT_VAR (17, N_U16, N_F32 | key); | |
13348 | CVT_VAR (18, N_S16, N_F64 | key); | |
13349 | CVT_VAR (19, N_U16, N_F64 | key); | |
5f4273c7 | 13350 | |
5287ad62 JB |
13351 | return -1; |
13352 | #undef CVT_VAR | |
13353 | } | |
13354 | ||
037e8744 JB |
13355 | /* Neon-syntax VFP conversions. */ |
13356 | ||
5287ad62 | 13357 | static void |
037e8744 | 13358 | do_vfp_nsyn_cvt (enum neon_shape rs, int flavour) |
5287ad62 | 13359 | { |
037e8744 | 13360 | const char *opname = 0; |
5f4273c7 | 13361 | |
037e8744 | 13362 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) |
5287ad62 | 13363 | { |
037e8744 JB |
13364 | /* Conversions with immediate bitshift. */ |
13365 | const char *enc[] = | |
13366 | { | |
13367 | "ftosls", | |
13368 | "ftouls", | |
13369 | "fsltos", | |
13370 | "fultos", | |
13371 | NULL, | |
13372 | NULL, | |
8e79c3df CM |
13373 | NULL, |
13374 | NULL, | |
037e8744 JB |
13375 | "ftosld", |
13376 | "ftould", | |
13377 | "fsltod", | |
13378 | "fultod", | |
13379 | "fshtos", | |
13380 | "fuhtos", | |
13381 | "fshtod", | |
13382 | "fuhtod", | |
13383 | "ftoshs", | |
13384 | "ftouhs", | |
13385 | "ftoshd", | |
13386 | "ftouhd" | |
13387 | }; | |
13388 | ||
13389 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13390 | { | |
13391 | opname = enc[flavour]; | |
13392 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13393 | _("operands 0 and 1 must be the same register")); | |
13394 | inst.operands[1] = inst.operands[2]; | |
13395 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
13396 | } | |
5287ad62 JB |
13397 | } |
13398 | else | |
13399 | { | |
037e8744 JB |
13400 | /* Conversions without bitshift. */ |
13401 | const char *enc[] = | |
13402 | { | |
13403 | "ftosis", | |
13404 | "ftouis", | |
13405 | "fsitos", | |
13406 | "fuitos", | |
8e79c3df CM |
13407 | "NULL", |
13408 | "NULL", | |
037e8744 JB |
13409 | "fcvtsd", |
13410 | "fcvtds", | |
13411 | "ftosid", | |
13412 | "ftouid", | |
13413 | "fsitod", | |
13414 | "fuitod" | |
13415 | }; | |
13416 | ||
13417 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc)) | |
13418 | opname = enc[flavour]; | |
13419 | } | |
13420 | ||
13421 | if (opname) | |
13422 | do_vfp_nsyn_opcode (opname); | |
13423 | } | |
13424 | ||
13425 | static void | |
13426 | do_vfp_nsyn_cvtz (void) | |
13427 | { | |
13428 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
13429 | int flavour = neon_cvt_flavour (rs); | |
13430 | const char *enc[] = | |
13431 | { | |
13432 | "ftosizs", | |
13433 | "ftouizs", | |
13434 | NULL, | |
13435 | NULL, | |
13436 | NULL, | |
13437 | NULL, | |
8e79c3df CM |
13438 | NULL, |
13439 | NULL, | |
037e8744 JB |
13440 | "ftosizd", |
13441 | "ftouizd" | |
13442 | }; | |
13443 | ||
13444 | if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) | |
13445 | do_vfp_nsyn_opcode (enc[flavour]); | |
13446 | } | |
f31fef98 | 13447 | |
037e8744 JB |
13448 | static void |
13449 | do_neon_cvt (void) | |
13450 | { | |
13451 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
8e79c3df | 13452 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL); |
037e8744 JB |
13453 | int flavour = neon_cvt_flavour (rs); |
13454 | ||
13455 | /* VFP rather than Neon conversions. */ | |
8e79c3df | 13456 | if (flavour >= 6) |
037e8744 JB |
13457 | { |
13458 | do_vfp_nsyn_cvt (rs, flavour); | |
13459 | return; | |
13460 | } | |
13461 | ||
13462 | switch (rs) | |
13463 | { | |
13464 | case NS_DDI: | |
13465 | case NS_QQI: | |
13466 | { | |
35997600 NC |
13467 | unsigned immbits; |
13468 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
13469 | ||
037e8744 JB |
13470 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
13471 | return; | |
13472 | ||
13473 | /* Fixed-point conversion with #0 immediate is encoded as an | |
13474 | integer conversion. */ | |
13475 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
13476 | goto int_encode; | |
35997600 | 13477 | immbits = 32 - inst.operands[2].imm; |
037e8744 JB |
13478 | inst.instruction = NEON_ENC_IMMED (inst.instruction); |
13479 | if (flavour != -1) | |
13480 | inst.instruction |= enctab[flavour]; | |
13481 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13482 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13483 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13484 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13485 | inst.instruction |= neon_quad (rs) << 6; | |
13486 | inst.instruction |= 1 << 21; | |
13487 | inst.instruction |= immbits << 16; | |
13488 | ||
13489 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13490 | } | |
13491 | break; | |
13492 | ||
13493 | case NS_DD: | |
13494 | case NS_QQ: | |
13495 | int_encode: | |
13496 | { | |
13497 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
13498 | ||
13499 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13500 | ||
13501 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13502 | return; | |
13503 | ||
13504 | if (flavour != -1) | |
13505 | inst.instruction |= enctab[flavour]; | |
13506 | ||
13507 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13508 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13509 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13510 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13511 | inst.instruction |= neon_quad (rs) << 6; | |
13512 | inst.instruction |= 2 << 18; | |
13513 | ||
13514 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13515 | } | |
13516 | break; | |
13517 | ||
8e79c3df CM |
13518 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
13519 | case NS_QD: | |
13520 | case NS_DQ: | |
13521 | ||
13522 | if ((rs == NS_DQ) | |
13523 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
13524 | { | |
13525 | as_bad (_("operand size must match register width")); | |
13526 | break; | |
13527 | } | |
13528 | ||
13529 | if ((rs == NS_QD) | |
13530 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
13531 | { | |
13532 | as_bad (_("operand size must match register width")); | |
13533 | break; | |
13534 | } | |
13535 | ||
13536 | if (rs == NS_DQ) | |
13537 | inst.instruction = 0x3b60600; | |
13538 | else | |
13539 | inst.instruction = 0x3b60700; | |
13540 | ||
13541 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13542 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13543 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13544 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13545 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13546 | break; | |
13547 | ||
037e8744 JB |
13548 | default: |
13549 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
13550 | do_vfp_nsyn_cvt (rs, flavour); | |
5287ad62 | 13551 | } |
5287ad62 JB |
13552 | } |
13553 | ||
8e79c3df CM |
13554 | static void |
13555 | do_neon_cvtb (void) | |
13556 | { | |
13557 | inst.instruction = 0xeb20a40; | |
13558 | ||
13559 | /* The sizes are attached to the mnemonic. */ | |
13560 | if (inst.vectype.el[0].type != NT_invtype | |
13561 | && inst.vectype.el[0].size == 16) | |
13562 | inst.instruction |= 0x00010000; | |
13563 | ||
13564 | /* Programmer's syntax: the sizes are attached to the operands. */ | |
13565 | else if (inst.operands[0].vectype.type != NT_invtype | |
13566 | && inst.operands[0].vectype.size == 16) | |
13567 | inst.instruction |= 0x00010000; | |
13568 | ||
13569 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
13570 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
13571 | do_vfp_cond_or_thumb (); | |
13572 | } | |
13573 | ||
13574 | ||
13575 | static void | |
13576 | do_neon_cvtt (void) | |
13577 | { | |
13578 | do_neon_cvtb (); | |
13579 | inst.instruction |= 0x80; | |
13580 | } | |
13581 | ||
5287ad62 JB |
13582 | static void |
13583 | neon_move_immediate (void) | |
13584 | { | |
037e8744 JB |
13585 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
13586 | struct neon_type_el et = neon_check_type (2, rs, | |
13587 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 13588 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 13589 | int op, cmode, float_p; |
5287ad62 | 13590 | |
037e8744 JB |
13591 | constraint (et.type == NT_invtype, |
13592 | _("operand size must be specified for immediate VMOV")); | |
13593 | ||
5287ad62 JB |
13594 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
13595 | op = (inst.instruction & (1 << 5)) != 0; | |
13596 | ||
13597 | immlo = inst.operands[1].imm; | |
13598 | if (inst.operands[1].regisimm) | |
13599 | immhi = inst.operands[1].reg; | |
13600 | ||
13601 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
13602 | _("immediate has bits set outside the operand size")); | |
13603 | ||
c96612cc JB |
13604 | float_p = inst.operands[1].immisfloat; |
13605 | ||
13606 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
136da414 | 13607 | et.size, et.type)) == FAIL) |
5287ad62 JB |
13608 | { |
13609 | /* Invert relevant bits only. */ | |
13610 | neon_invert_size (&immlo, &immhi, et.size); | |
13611 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
13612 | with one or the other; those cases are caught by | |
13613 | neon_cmode_for_move_imm. */ | |
13614 | op = !op; | |
c96612cc JB |
13615 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
13616 | &op, et.size, et.type)) == FAIL) | |
5287ad62 | 13617 | { |
dcbf9037 | 13618 | first_error (_("immediate out of range")); |
5287ad62 JB |
13619 | return; |
13620 | } | |
13621 | } | |
13622 | ||
13623 | inst.instruction &= ~(1 << 5); | |
13624 | inst.instruction |= op << 5; | |
13625 | ||
13626 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13627 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 13628 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13629 | inst.instruction |= cmode << 8; |
13630 | ||
13631 | neon_write_immbits (immbits); | |
13632 | } | |
13633 | ||
13634 | static void | |
13635 | do_neon_mvn (void) | |
13636 | { | |
13637 | if (inst.operands[1].isreg) | |
13638 | { | |
037e8744 | 13639 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 13640 | |
5287ad62 JB |
13641 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); |
13642 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13643 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13644 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13645 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 13646 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13647 | } |
13648 | else | |
13649 | { | |
13650 | inst.instruction = NEON_ENC_IMMED (inst.instruction); | |
13651 | neon_move_immediate (); | |
13652 | } | |
13653 | ||
13654 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13655 | } | |
13656 | ||
13657 | /* Encode instructions of form: | |
13658 | ||
13659 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 13660 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
13661 | |
13662 | static void | |
13663 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
13664 | { | |
13665 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13666 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13667 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13668 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13669 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13670 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
13671 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
13672 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 13673 | |
5287ad62 JB |
13674 | inst.instruction = neon_dp_fixup (inst.instruction); |
13675 | } | |
13676 | ||
13677 | static void | |
13678 | do_neon_dyadic_long (void) | |
13679 | { | |
13680 | /* FIXME: Type checking for lengthening op. */ | |
13681 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13682 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
13683 | neon_mixed_length (et, et.size); | |
13684 | } | |
13685 | ||
13686 | static void | |
13687 | do_neon_abal (void) | |
13688 | { | |
13689 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13690 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
13691 | neon_mixed_length (et, et.size); | |
13692 | } | |
13693 | ||
13694 | static void | |
13695 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
13696 | { | |
13697 | if (inst.operands[2].isscalar) | |
13698 | { | |
dcbf9037 JB |
13699 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
13700 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); | |
5287ad62 JB |
13701 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
13702 | neon_mul_mac (et, et.type == NT_unsigned); | |
13703 | } | |
13704 | else | |
13705 | { | |
13706 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13707 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); | |
13708 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13709 | neon_mixed_length (et, et.size); | |
13710 | } | |
13711 | } | |
13712 | ||
13713 | static void | |
13714 | do_neon_mac_maybe_scalar_long (void) | |
13715 | { | |
13716 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
13717 | } | |
13718 | ||
13719 | static void | |
13720 | do_neon_dyadic_wide (void) | |
13721 | { | |
13722 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
13723 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
13724 | neon_mixed_length (et, et.size); | |
13725 | } | |
13726 | ||
13727 | static void | |
13728 | do_neon_dyadic_narrow (void) | |
13729 | { | |
13730 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13731 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
13732 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
13733 | so force the operand type to integer. */ | |
13734 | et.type = NT_integer; | |
5287ad62 JB |
13735 | neon_mixed_length (et, et.size / 2); |
13736 | } | |
13737 | ||
13738 | static void | |
13739 | do_neon_mul_sat_scalar_long (void) | |
13740 | { | |
13741 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
13742 | } | |
13743 | ||
13744 | static void | |
13745 | do_neon_vmull (void) | |
13746 | { | |
13747 | if (inst.operands[2].isscalar) | |
13748 | do_neon_mac_maybe_scalar_long (); | |
13749 | else | |
13750 | { | |
13751 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
13752 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY); | |
13753 | if (et.type == NT_poly) | |
13754 | inst.instruction = NEON_ENC_POLY (inst.instruction); | |
13755 | else | |
13756 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
13757 | /* For polynomial encoding, size field must be 0b00 and the U bit must be | |
13758 | zero. Should be OK as-is. */ | |
13759 | neon_mixed_length (et, et.size); | |
13760 | } | |
13761 | } | |
13762 | ||
13763 | static void | |
13764 | do_neon_ext (void) | |
13765 | { | |
037e8744 | 13766 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
13767 | struct neon_type_el et = neon_check_type (3, rs, |
13768 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
13769 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
13770 | |
13771 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
13772 | _("shift out of range")); | |
5287ad62 JB |
13773 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
13774 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13775 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13776 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13777 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
13778 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 13779 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 13780 | inst.instruction |= imm << 8; |
5f4273c7 | 13781 | |
5287ad62 JB |
13782 | inst.instruction = neon_dp_fixup (inst.instruction); |
13783 | } | |
13784 | ||
13785 | static void | |
13786 | do_neon_rev (void) | |
13787 | { | |
037e8744 | 13788 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
13789 | struct neon_type_el et = neon_check_type (2, rs, |
13790 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
13791 | unsigned op = (inst.instruction >> 7) & 3; | |
13792 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
13793 | extract it here to check the elements to be reversed are smaller. | |
13794 | Otherwise we'd get a reserved instruction. */ | |
13795 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 13796 | gas_assert (elsize != 0); |
5287ad62 JB |
13797 | constraint (et.size >= elsize, |
13798 | _("elements must be smaller than reversal region")); | |
037e8744 | 13799 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
13800 | } |
13801 | ||
13802 | static void | |
13803 | do_neon_dup (void) | |
13804 | { | |
13805 | if (inst.operands[1].isscalar) | |
13806 | { | |
037e8744 | 13807 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 JB |
13808 | struct neon_type_el et = neon_check_type (2, rs, |
13809 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
5287ad62 | 13810 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 13811 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 13812 | int logsize = neon_logbits (et.size); |
dcbf9037 | 13813 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
13814 | |
13815 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
13816 | return; | |
13817 | ||
5287ad62 JB |
13818 | inst.instruction = NEON_ENC_SCALAR (inst.instruction); |
13819 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13820 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13821 | inst.instruction |= LOW4 (dm); | |
13822 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 13823 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
13824 | inst.instruction |= x << 17; |
13825 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 13826 | |
5287ad62 JB |
13827 | inst.instruction = neon_dp_fixup (inst.instruction); |
13828 | } | |
13829 | else | |
13830 | { | |
037e8744 JB |
13831 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
13832 | struct neon_type_el et = neon_check_type (2, rs, | |
13833 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
5287ad62 JB |
13834 | /* Duplicate ARM register to lanes of vector. */ |
13835 | inst.instruction = NEON_ENC_ARMREG (inst.instruction); | |
13836 | switch (et.size) | |
13837 | { | |
13838 | case 8: inst.instruction |= 0x400000; break; | |
13839 | case 16: inst.instruction |= 0x000020; break; | |
13840 | case 32: inst.instruction |= 0x000000; break; | |
13841 | default: break; | |
13842 | } | |
13843 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
13844 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
13845 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 13846 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 JB |
13847 | /* The encoding for this instruction is identical for the ARM and Thumb |
13848 | variants, except for the condition field. */ | |
037e8744 | 13849 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
13850 | } |
13851 | } | |
13852 | ||
13853 | /* VMOV has particularly many variations. It can be one of: | |
13854 | 0. VMOV<c><q> <Qd>, <Qm> | |
13855 | 1. VMOV<c><q> <Dd>, <Dm> | |
13856 | (Register operations, which are VORR with Rm = Rn.) | |
13857 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
13858 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
13859 | (Immediate loads.) | |
13860 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
13861 | (ARM register to scalar.) | |
13862 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
13863 | (Two ARM registers to vector.) | |
13864 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
13865 | (Scalar to ARM register.) | |
13866 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
13867 | (Vector to two ARM registers.) | |
037e8744 JB |
13868 | 8. VMOV.F32 <Sd>, <Sm> |
13869 | 9. VMOV.F64 <Dd>, <Dm> | |
13870 | (VFP register moves.) | |
13871 | 10. VMOV.F32 <Sd>, #imm | |
13872 | 11. VMOV.F64 <Dd>, #imm | |
13873 | (VFP float immediate load.) | |
13874 | 12. VMOV <Rd>, <Sm> | |
13875 | (VFP single to ARM reg.) | |
13876 | 13. VMOV <Sd>, <Rm> | |
13877 | (ARM reg to VFP single.) | |
13878 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
13879 | (Two ARM regs to two VFP singles.) | |
13880 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
13881 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 13882 | |
037e8744 JB |
13883 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
13884 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 13885 | |
5287ad62 | 13886 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 13887 | |
b7fc2769 JB |
13888 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
13889 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 13890 | |
5287ad62 | 13891 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 13892 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
13893 | |
13894 | static void | |
13895 | do_neon_mov (void) | |
13896 | { | |
037e8744 JB |
13897 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
13898 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
13899 | NS_NULL); | |
13900 | struct neon_type_el et; | |
13901 | const char *ldconst = 0; | |
5287ad62 | 13902 | |
037e8744 | 13903 | switch (rs) |
5287ad62 | 13904 | { |
037e8744 JB |
13905 | case NS_DD: /* case 1/9. */ |
13906 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
13907 | /* It is not an error here if no type is given. */ | |
13908 | inst.error = NULL; | |
13909 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 13910 | { |
037e8744 JB |
13911 | do_vfp_nsyn_opcode ("fcpyd"); |
13912 | break; | |
5287ad62 | 13913 | } |
037e8744 | 13914 | /* fall through. */ |
5287ad62 | 13915 | |
037e8744 JB |
13916 | case NS_QQ: /* case 0/1. */ |
13917 | { | |
13918 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13919 | return; | |
13920 | /* The architecture manual I have doesn't explicitly state which | |
13921 | value the U bit should have for register->register moves, but | |
13922 | the equivalent VORR instruction has U = 0, so do that. */ | |
13923 | inst.instruction = 0x0200110; | |
13924 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
13925 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
13926 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
13927 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
13928 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
13929 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
13930 | inst.instruction |= neon_quad (rs) << 6; | |
13931 | ||
13932 | inst.instruction = neon_dp_fixup (inst.instruction); | |
13933 | } | |
13934 | break; | |
5f4273c7 | 13935 | |
037e8744 JB |
13936 | case NS_DI: /* case 3/11. */ |
13937 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
13938 | inst.error = NULL; | |
13939 | if (et.type == NT_float && et.size == 64) | |
5287ad62 | 13940 | { |
037e8744 JB |
13941 | /* case 11 (fconstd). */ |
13942 | ldconst = "fconstd"; | |
13943 | goto encode_fconstd; | |
5287ad62 | 13944 | } |
037e8744 JB |
13945 | /* fall through. */ |
13946 | ||
13947 | case NS_QI: /* case 2/3. */ | |
13948 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
13949 | return; | |
13950 | inst.instruction = 0x0800010; | |
13951 | neon_move_immediate (); | |
13952 | inst.instruction = neon_dp_fixup (inst.instruction); | |
5287ad62 | 13953 | break; |
5f4273c7 | 13954 | |
037e8744 JB |
13955 | case NS_SR: /* case 4. */ |
13956 | { | |
13957 | unsigned bcdebits = 0; | |
13958 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
13959 | N_8 | N_16 | N_32 | N_KEY, N_EQK); | |
13960 | int logsize = neon_logbits (et.size); | |
13961 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
13962 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
13963 | ||
13964 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
13965 | _(BAD_FPU)); | |
13966 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
13967 | && et.size != 32, _(BAD_FPU)); | |
13968 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
13969 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
13970 | ||
13971 | switch (et.size) | |
13972 | { | |
13973 | case 8: bcdebits = 0x8; break; | |
13974 | case 16: bcdebits = 0x1; break; | |
13975 | case 32: bcdebits = 0x0; break; | |
13976 | default: ; | |
13977 | } | |
13978 | ||
13979 | bcdebits |= x << logsize; | |
13980 | ||
13981 | inst.instruction = 0xe000b10; | |
13982 | do_vfp_cond_or_thumb (); | |
13983 | inst.instruction |= LOW4 (dn) << 16; | |
13984 | inst.instruction |= HI1 (dn) << 7; | |
13985 | inst.instruction |= inst.operands[1].reg << 12; | |
13986 | inst.instruction |= (bcdebits & 3) << 5; | |
13987 | inst.instruction |= (bcdebits >> 2) << 21; | |
13988 | } | |
13989 | break; | |
5f4273c7 | 13990 | |
037e8744 | 13991 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 13992 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
037e8744 | 13993 | _(BAD_FPU)); |
b7fc2769 | 13994 | |
037e8744 JB |
13995 | inst.instruction = 0xc400b10; |
13996 | do_vfp_cond_or_thumb (); | |
13997 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
13998 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
13999 | inst.instruction |= inst.operands[1].reg << 12; | |
14000 | inst.instruction |= inst.operands[2].reg << 16; | |
14001 | break; | |
5f4273c7 | 14002 | |
037e8744 JB |
14003 | case NS_RS: /* case 6. */ |
14004 | { | |
14005 | struct neon_type_el et = neon_check_type (2, NS_NULL, | |
14006 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
14007 | unsigned logsize = neon_logbits (et.size); | |
14008 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
14009 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
14010 | unsigned abcdebits = 0; | |
14011 | ||
14012 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
14013 | _(BAD_FPU)); | |
14014 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
14015 | && et.size != 32, _(BAD_FPU)); | |
14016 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
14017 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
14018 | ||
14019 | switch (et.size) | |
14020 | { | |
14021 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
14022 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
14023 | case 32: abcdebits = 0x00; break; | |
14024 | default: ; | |
14025 | } | |
14026 | ||
14027 | abcdebits |= x << logsize; | |
14028 | inst.instruction = 0xe100b10; | |
14029 | do_vfp_cond_or_thumb (); | |
14030 | inst.instruction |= LOW4 (dn) << 16; | |
14031 | inst.instruction |= HI1 (dn) << 7; | |
14032 | inst.instruction |= inst.operands[0].reg << 12; | |
14033 | inst.instruction |= (abcdebits & 3) << 5; | |
14034 | inst.instruction |= (abcdebits >> 2) << 21; | |
14035 | } | |
14036 | break; | |
5f4273c7 | 14037 | |
037e8744 JB |
14038 | case NS_RRD: /* case 7 (fmrrd). */ |
14039 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
14040 | _(BAD_FPU)); | |
14041 | ||
14042 | inst.instruction = 0xc500b10; | |
14043 | do_vfp_cond_or_thumb (); | |
14044 | inst.instruction |= inst.operands[0].reg << 12; | |
14045 | inst.instruction |= inst.operands[1].reg << 16; | |
14046 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14047 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14048 | break; | |
5f4273c7 | 14049 | |
037e8744 JB |
14050 | case NS_FF: /* case 8 (fcpys). */ |
14051 | do_vfp_nsyn_opcode ("fcpys"); | |
14052 | break; | |
5f4273c7 | 14053 | |
037e8744 JB |
14054 | case NS_FI: /* case 10 (fconsts). */ |
14055 | ldconst = "fconsts"; | |
14056 | encode_fconstd: | |
14057 | if (is_quarter_float (inst.operands[1].imm)) | |
5287ad62 | 14058 | { |
037e8744 JB |
14059 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); |
14060 | do_vfp_nsyn_opcode (ldconst); | |
5287ad62 JB |
14061 | } |
14062 | else | |
037e8744 JB |
14063 | first_error (_("immediate out of range")); |
14064 | break; | |
5f4273c7 | 14065 | |
037e8744 JB |
14066 | case NS_RF: /* case 12 (fmrs). */ |
14067 | do_vfp_nsyn_opcode ("fmrs"); | |
14068 | break; | |
5f4273c7 | 14069 | |
037e8744 JB |
14070 | case NS_FR: /* case 13 (fmsr). */ |
14071 | do_vfp_nsyn_opcode ("fmsr"); | |
14072 | break; | |
5f4273c7 | 14073 | |
037e8744 JB |
14074 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
14075 | (one of which is a list), but we have parsed four. Do some fiddling to | |
14076 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
14077 | expect. */ | |
14078 | case NS_RRFF: /* case 14 (fmrrs). */ | |
14079 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
14080 | _("VFP registers must be adjacent")); | |
14081 | inst.operands[2].imm = 2; | |
14082 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14083 | do_vfp_nsyn_opcode ("fmrrs"); | |
14084 | break; | |
5f4273c7 | 14085 | |
037e8744 JB |
14086 | case NS_FFRR: /* case 15 (fmsrr). */ |
14087 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
14088 | _("VFP registers must be adjacent")); | |
14089 | inst.operands[1] = inst.operands[2]; | |
14090 | inst.operands[2] = inst.operands[3]; | |
14091 | inst.operands[0].imm = 2; | |
14092 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
14093 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 14094 | break; |
5f4273c7 | 14095 | |
5287ad62 JB |
14096 | default: |
14097 | abort (); | |
14098 | } | |
14099 | } | |
14100 | ||
14101 | static void | |
14102 | do_neon_rshift_round_imm (void) | |
14103 | { | |
037e8744 | 14104 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14105 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
14106 | int imm = inst.operands[2].imm; | |
14107 | ||
14108 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
14109 | if (imm == 0) | |
14110 | { | |
14111 | inst.operands[2].present = 0; | |
14112 | do_neon_mov (); | |
14113 | return; | |
14114 | } | |
14115 | ||
14116 | constraint (imm < 1 || (unsigned)imm > et.size, | |
14117 | _("immediate out of range for shift")); | |
037e8744 | 14118 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
5287ad62 JB |
14119 | et.size - imm); |
14120 | } | |
14121 | ||
14122 | static void | |
14123 | do_neon_movl (void) | |
14124 | { | |
14125 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
14126 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
14127 | unsigned sizebits = et.size >> 3; | |
14128 | inst.instruction |= sizebits << 19; | |
14129 | neon_two_same (0, et.type == NT_unsigned, -1); | |
14130 | } | |
14131 | ||
14132 | static void | |
14133 | do_neon_trn (void) | |
14134 | { | |
037e8744 | 14135 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14136 | struct neon_type_el et = neon_check_type (2, rs, |
14137 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14138 | inst.instruction = NEON_ENC_INTEGER (inst.instruction); | |
037e8744 | 14139 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14140 | } |
14141 | ||
14142 | static void | |
14143 | do_neon_zip_uzp (void) | |
14144 | { | |
037e8744 | 14145 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14146 | struct neon_type_el et = neon_check_type (2, rs, |
14147 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
14148 | if (rs == NS_DD && et.size == 32) | |
14149 | { | |
14150 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
14151 | inst.instruction = N_MNEM_vtrn; | |
14152 | do_neon_trn (); | |
14153 | return; | |
14154 | } | |
037e8744 | 14155 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14156 | } |
14157 | ||
14158 | static void | |
14159 | do_neon_sat_abs_neg (void) | |
14160 | { | |
037e8744 | 14161 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14162 | struct neon_type_el et = neon_check_type (2, rs, |
14163 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14164 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14165 | } |
14166 | ||
14167 | static void | |
14168 | do_neon_pair_long (void) | |
14169 | { | |
037e8744 | 14170 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14171 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
14172 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
14173 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 14174 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14175 | } |
14176 | ||
14177 | static void | |
14178 | do_neon_recip_est (void) | |
14179 | { | |
037e8744 | 14180 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14181 | struct neon_type_el et = neon_check_type (2, rs, |
14182 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
14183 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 14184 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14185 | } |
14186 | ||
14187 | static void | |
14188 | do_neon_cls (void) | |
14189 | { | |
037e8744 | 14190 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14191 | struct neon_type_el et = neon_check_type (2, rs, |
14192 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 14193 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14194 | } |
14195 | ||
14196 | static void | |
14197 | do_neon_clz (void) | |
14198 | { | |
037e8744 | 14199 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14200 | struct neon_type_el et = neon_check_type (2, rs, |
14201 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 14202 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14203 | } |
14204 | ||
14205 | static void | |
14206 | do_neon_cnt (void) | |
14207 | { | |
037e8744 | 14208 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
14209 | struct neon_type_el et = neon_check_type (2, rs, |
14210 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 14211 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
14212 | } |
14213 | ||
14214 | static void | |
14215 | do_neon_swp (void) | |
14216 | { | |
037e8744 JB |
14217 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
14218 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
14219 | } |
14220 | ||
14221 | static void | |
14222 | do_neon_tbl_tbx (void) | |
14223 | { | |
14224 | unsigned listlenbits; | |
dcbf9037 | 14225 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 14226 | |
5287ad62 JB |
14227 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
14228 | { | |
dcbf9037 | 14229 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
14230 | return; |
14231 | } | |
5f4273c7 | 14232 | |
5287ad62 JB |
14233 | listlenbits = inst.operands[1].imm - 1; |
14234 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14235 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14236 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14237 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14238 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14239 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14240 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 14241 | |
5287ad62 JB |
14242 | inst.instruction = neon_dp_fixup (inst.instruction); |
14243 | } | |
14244 | ||
14245 | static void | |
14246 | do_neon_ldm_stm (void) | |
14247 | { | |
14248 | /* P, U and L bits are part of bitmask. */ | |
14249 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
14250 | unsigned offsetbits = inst.operands[1].imm * 2; | |
14251 | ||
037e8744 JB |
14252 | if (inst.operands[1].issingle) |
14253 | { | |
14254 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
14255 | return; | |
14256 | } | |
14257 | ||
5287ad62 JB |
14258 | constraint (is_dbmode && !inst.operands[0].writeback, |
14259 | _("writeback (!) must be used for VLDMDB and VSTMDB")); | |
14260 | ||
14261 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14262 | _("register list must contain at least 1 and at most 16 " | |
14263 | "registers")); | |
14264 | ||
14265 | inst.instruction |= inst.operands[0].reg << 16; | |
14266 | inst.instruction |= inst.operands[0].writeback << 21; | |
14267 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
14268 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
14269 | ||
14270 | inst.instruction |= offsetbits; | |
5f4273c7 | 14271 | |
037e8744 | 14272 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
14273 | } |
14274 | ||
14275 | static void | |
14276 | do_neon_ldr_str (void) | |
14277 | { | |
5287ad62 | 14278 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 14279 | |
037e8744 JB |
14280 | if (inst.operands[0].issingle) |
14281 | { | |
cd2f129f JB |
14282 | if (is_ldr) |
14283 | do_vfp_nsyn_opcode ("flds"); | |
14284 | else | |
14285 | do_vfp_nsyn_opcode ("fsts"); | |
5287ad62 JB |
14286 | } |
14287 | else | |
5287ad62 | 14288 | { |
cd2f129f JB |
14289 | if (is_ldr) |
14290 | do_vfp_nsyn_opcode ("fldd"); | |
5287ad62 | 14291 | else |
cd2f129f | 14292 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 14293 | } |
5287ad62 JB |
14294 | } |
14295 | ||
14296 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
14297 | instructions. */ | |
14298 | ||
14299 | static void | |
14300 | do_neon_ld_st_interleave (void) | |
14301 | { | |
037e8744 | 14302 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
5287ad62 JB |
14303 | N_8 | N_16 | N_32 | N_64); |
14304 | unsigned alignbits = 0; | |
14305 | unsigned idx; | |
14306 | /* The bits in this table go: | |
14307 | 0: register stride of one (0) or two (1) | |
14308 | 1,2: register list length, minus one (1, 2, 3, 4). | |
14309 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
14310 | We use -1 for invalid entries. */ | |
14311 | const int typetable[] = | |
14312 | { | |
14313 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
14314 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
14315 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
14316 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
14317 | }; | |
14318 | int typebits; | |
14319 | ||
dcbf9037 JB |
14320 | if (et.type == NT_invtype) |
14321 | return; | |
14322 | ||
5287ad62 JB |
14323 | if (inst.operands[1].immisalign) |
14324 | switch (inst.operands[1].imm >> 8) | |
14325 | { | |
14326 | case 64: alignbits = 1; break; | |
14327 | case 128: | |
14328 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
14329 | goto bad_alignment; | |
14330 | alignbits = 2; | |
14331 | break; | |
14332 | case 256: | |
14333 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3) | |
14334 | goto bad_alignment; | |
14335 | alignbits = 3; | |
14336 | break; | |
14337 | default: | |
14338 | bad_alignment: | |
dcbf9037 | 14339 | first_error (_("bad alignment")); |
5287ad62 JB |
14340 | return; |
14341 | } | |
14342 | ||
14343 | inst.instruction |= alignbits << 4; | |
14344 | inst.instruction |= neon_logbits (et.size) << 6; | |
14345 | ||
14346 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
14347 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
14348 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
14349 | up the right value for "type" in a table based on this value and the given | |
14350 | list style, then stick it back. */ | |
14351 | idx = ((inst.operands[0].imm >> 4) & 7) | |
14352 | | (((inst.instruction >> 8) & 3) << 3); | |
14353 | ||
14354 | typebits = typetable[idx]; | |
5f4273c7 | 14355 | |
5287ad62 JB |
14356 | constraint (typebits == -1, _("bad list type for instruction")); |
14357 | ||
14358 | inst.instruction &= ~0xf00; | |
14359 | inst.instruction |= typebits << 8; | |
14360 | } | |
14361 | ||
14362 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
14363 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
14364 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
14365 | values, terminated with -1. */ | |
14366 | ||
14367 | static int | |
14368 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
14369 | { | |
14370 | va_list ap; | |
14371 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 14372 | |
5287ad62 JB |
14373 | if (!inst.operands[1].immisalign) |
14374 | { | |
14375 | *do_align = 0; | |
14376 | return SUCCESS; | |
14377 | } | |
5f4273c7 | 14378 | |
5287ad62 JB |
14379 | va_start (ap, do_align); |
14380 | ||
14381 | do | |
14382 | { | |
14383 | thissize = va_arg (ap, int); | |
14384 | if (thissize == -1) | |
14385 | break; | |
14386 | thisalign = va_arg (ap, int); | |
14387 | ||
14388 | if (size == thissize && align == thisalign) | |
14389 | result = SUCCESS; | |
14390 | } | |
14391 | while (result != SUCCESS); | |
14392 | ||
14393 | va_end (ap); | |
14394 | ||
14395 | if (result == SUCCESS) | |
14396 | *do_align = 1; | |
14397 | else | |
dcbf9037 | 14398 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 14399 | |
5287ad62 JB |
14400 | return result; |
14401 | } | |
14402 | ||
14403 | static void | |
14404 | do_neon_ld_st_lane (void) | |
14405 | { | |
037e8744 | 14406 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
14407 | int align_good, do_align = 0; |
14408 | int logsize = neon_logbits (et.size); | |
14409 | int align = inst.operands[1].imm >> 8; | |
14410 | int n = (inst.instruction >> 8) & 3; | |
14411 | int max_el = 64 / et.size; | |
5f4273c7 | 14412 | |
dcbf9037 JB |
14413 | if (et.type == NT_invtype) |
14414 | return; | |
5f4273c7 | 14415 | |
5287ad62 JB |
14416 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
14417 | _("bad list length")); | |
14418 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, | |
14419 | _("scalar index out of range")); | |
14420 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 | |
14421 | && et.size == 8, | |
14422 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 14423 | |
5287ad62 JB |
14424 | switch (n) |
14425 | { | |
14426 | case 0: /* VLD1 / VST1. */ | |
14427 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
14428 | 32, 32, -1); | |
14429 | if (align_good == FAIL) | |
14430 | return; | |
14431 | if (do_align) | |
14432 | { | |
14433 | unsigned alignbits = 0; | |
14434 | switch (et.size) | |
14435 | { | |
14436 | case 16: alignbits = 0x1; break; | |
14437 | case 32: alignbits = 0x3; break; | |
14438 | default: ; | |
14439 | } | |
14440 | inst.instruction |= alignbits << 4; | |
14441 | } | |
14442 | break; | |
14443 | ||
14444 | case 1: /* VLD2 / VST2. */ | |
14445 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
14446 | 32, 64, -1); | |
14447 | if (align_good == FAIL) | |
14448 | return; | |
14449 | if (do_align) | |
14450 | inst.instruction |= 1 << 4; | |
14451 | break; | |
14452 | ||
14453 | case 2: /* VLD3 / VST3. */ | |
14454 | constraint (inst.operands[1].immisalign, | |
14455 | _("can't use alignment with this instruction")); | |
14456 | break; | |
14457 | ||
14458 | case 3: /* VLD4 / VST4. */ | |
14459 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
14460 | 16, 64, 32, 64, 32, 128, -1); | |
14461 | if (align_good == FAIL) | |
14462 | return; | |
14463 | if (do_align) | |
14464 | { | |
14465 | unsigned alignbits = 0; | |
14466 | switch (et.size) | |
14467 | { | |
14468 | case 8: alignbits = 0x1; break; | |
14469 | case 16: alignbits = 0x1; break; | |
14470 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
14471 | default: ; | |
14472 | } | |
14473 | inst.instruction |= alignbits << 4; | |
14474 | } | |
14475 | break; | |
14476 | ||
14477 | default: ; | |
14478 | } | |
14479 | ||
14480 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
14481 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14482 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 14483 | |
5287ad62 JB |
14484 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
14485 | inst.instruction |= logsize << 10; | |
14486 | } | |
14487 | ||
14488 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
14489 | ||
14490 | static void | |
14491 | do_neon_ld_dup (void) | |
14492 | { | |
037e8744 | 14493 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
14494 | int align_good, do_align = 0; |
14495 | ||
dcbf9037 JB |
14496 | if (et.type == NT_invtype) |
14497 | return; | |
14498 | ||
5287ad62 JB |
14499 | switch ((inst.instruction >> 8) & 3) |
14500 | { | |
14501 | case 0: /* VLD1. */ | |
9c2799c2 | 14502 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 JB |
14503 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
14504 | &do_align, 16, 16, 32, 32, -1); | |
14505 | if (align_good == FAIL) | |
14506 | return; | |
14507 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) | |
14508 | { | |
14509 | case 1: break; | |
14510 | case 2: inst.instruction |= 1 << 5; break; | |
dcbf9037 | 14511 | default: first_error (_("bad list length")); return; |
5287ad62 JB |
14512 | } |
14513 | inst.instruction |= neon_logbits (et.size) << 6; | |
14514 | break; | |
14515 | ||
14516 | case 1: /* VLD2. */ | |
14517 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
14518 | &do_align, 8, 16, 16, 32, 32, 64, -1); | |
14519 | if (align_good == FAIL) | |
14520 | return; | |
14521 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, | |
14522 | _("bad list length")); | |
14523 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14524 | inst.instruction |= 1 << 5; | |
14525 | inst.instruction |= neon_logbits (et.size) << 6; | |
14526 | break; | |
14527 | ||
14528 | case 2: /* VLD3. */ | |
14529 | constraint (inst.operands[1].immisalign, | |
14530 | _("can't use alignment with this instruction")); | |
14531 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, | |
14532 | _("bad list length")); | |
14533 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14534 | inst.instruction |= 1 << 5; | |
14535 | inst.instruction |= neon_logbits (et.size) << 6; | |
14536 | break; | |
14537 | ||
14538 | case 3: /* VLD4. */ | |
14539 | { | |
14540 | int align = inst.operands[1].imm >> 8; | |
14541 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
14542 | 16, 64, 32, 64, 32, 128, -1); | |
14543 | if (align_good == FAIL) | |
14544 | return; | |
14545 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
14546 | _("bad list length")); | |
14547 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
14548 | inst.instruction |= 1 << 5; | |
14549 | if (et.size == 32 && align == 128) | |
14550 | inst.instruction |= 0x3 << 6; | |
14551 | else | |
14552 | inst.instruction |= neon_logbits (et.size) << 6; | |
14553 | } | |
14554 | break; | |
14555 | ||
14556 | default: ; | |
14557 | } | |
14558 | ||
14559 | inst.instruction |= do_align << 4; | |
14560 | } | |
14561 | ||
14562 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
14563 | apart from bits [11:4]. */ | |
14564 | ||
14565 | static void | |
14566 | do_neon_ldx_stx (void) | |
14567 | { | |
14568 | switch (NEON_LANE (inst.operands[0].imm)) | |
14569 | { | |
14570 | case NEON_INTERLEAVE_LANES: | |
14571 | inst.instruction = NEON_ENC_INTERLV (inst.instruction); | |
14572 | do_neon_ld_st_interleave (); | |
14573 | break; | |
5f4273c7 | 14574 | |
5287ad62 JB |
14575 | case NEON_ALL_LANES: |
14576 | inst.instruction = NEON_ENC_DUP (inst.instruction); | |
14577 | do_neon_ld_dup (); | |
14578 | break; | |
5f4273c7 | 14579 | |
5287ad62 JB |
14580 | default: |
14581 | inst.instruction = NEON_ENC_LANE (inst.instruction); | |
14582 | do_neon_ld_st_lane (); | |
14583 | } | |
14584 | ||
14585 | /* L bit comes from bit mask. */ | |
14586 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14587 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14588 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 14589 | |
5287ad62 JB |
14590 | if (inst.operands[1].postind) |
14591 | { | |
14592 | int postreg = inst.operands[1].imm & 0xf; | |
14593 | constraint (!inst.operands[1].immisreg, | |
14594 | _("post-index must be a register")); | |
14595 | constraint (postreg == 0xd || postreg == 0xf, | |
14596 | _("bad register for post-index")); | |
14597 | inst.instruction |= postreg; | |
14598 | } | |
14599 | else if (inst.operands[1].writeback) | |
14600 | { | |
14601 | inst.instruction |= 0xd; | |
14602 | } | |
14603 | else | |
5f4273c7 NC |
14604 | inst.instruction |= 0xf; |
14605 | ||
5287ad62 JB |
14606 | if (thumb_mode) |
14607 | inst.instruction |= 0xf9000000; | |
14608 | else | |
14609 | inst.instruction |= 0xf4000000; | |
14610 | } | |
5287ad62 JB |
14611 | \f |
14612 | /* Overall per-instruction processing. */ | |
14613 | ||
14614 | /* We need to be able to fix up arbitrary expressions in some statements. | |
14615 | This is so that we can handle symbols that are an arbitrary distance from | |
14616 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
14617 | which returns part of an address in a form which will be valid for | |
14618 | a data instruction. We do this by pushing the expression into a symbol | |
14619 | in the expr_section, and creating a fix for that. */ | |
14620 | ||
14621 | static void | |
14622 | fix_new_arm (fragS * frag, | |
14623 | int where, | |
14624 | short int size, | |
14625 | expressionS * exp, | |
14626 | int pc_rel, | |
14627 | int reloc) | |
14628 | { | |
14629 | fixS * new_fix; | |
14630 | ||
14631 | switch (exp->X_op) | |
14632 | { | |
14633 | case O_constant: | |
14634 | case O_symbol: | |
14635 | case O_add: | |
14636 | case O_subtract: | |
14637 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
14638 | break; | |
14639 | ||
14640 | default: | |
14641 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
14642 | pc_rel, reloc); | |
14643 | break; | |
14644 | } | |
14645 | ||
14646 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
14647 | instruction. */ | |
14648 | new_fix->tc_fix_data = thumb_mode; | |
14649 | } | |
14650 | ||
14651 | /* Create a frg for an instruction requiring relaxation. */ | |
14652 | static void | |
14653 | output_relax_insn (void) | |
14654 | { | |
14655 | char * to; | |
14656 | symbolS *sym; | |
0110f2b8 PB |
14657 | int offset; |
14658 | ||
6e1cb1a6 PB |
14659 | /* The size of the instruction is unknown, so tie the debug info to the |
14660 | start of the instruction. */ | |
14661 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 14662 | |
0110f2b8 PB |
14663 | switch (inst.reloc.exp.X_op) |
14664 | { | |
14665 | case O_symbol: | |
14666 | sym = inst.reloc.exp.X_add_symbol; | |
14667 | offset = inst.reloc.exp.X_add_number; | |
14668 | break; | |
14669 | case O_constant: | |
14670 | sym = NULL; | |
14671 | offset = inst.reloc.exp.X_add_number; | |
14672 | break; | |
14673 | default: | |
14674 | sym = make_expr_symbol (&inst.reloc.exp); | |
14675 | offset = 0; | |
14676 | break; | |
14677 | } | |
14678 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
14679 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
14680 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
14681 | } |
14682 | ||
14683 | /* Write a 32-bit thumb instruction to buf. */ | |
14684 | static void | |
14685 | put_thumb32_insn (char * buf, unsigned long insn) | |
14686 | { | |
14687 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
14688 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
14689 | } | |
14690 | ||
b99bd4ef | 14691 | static void |
c19d1205 | 14692 | output_inst (const char * str) |
b99bd4ef | 14693 | { |
c19d1205 | 14694 | char * to = NULL; |
b99bd4ef | 14695 | |
c19d1205 | 14696 | if (inst.error) |
b99bd4ef | 14697 | { |
c19d1205 | 14698 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
14699 | return; |
14700 | } | |
5f4273c7 NC |
14701 | if (inst.relax) |
14702 | { | |
14703 | output_relax_insn (); | |
0110f2b8 | 14704 | return; |
5f4273c7 | 14705 | } |
c19d1205 ZW |
14706 | if (inst.size == 0) |
14707 | return; | |
b99bd4ef | 14708 | |
c19d1205 | 14709 | to = frag_more (inst.size); |
8dc2430f NC |
14710 | /* PR 9814: Record the thumb mode into the current frag so that we know |
14711 | what type of NOP padding to use, if necessary. We override any previous | |
14712 | setting so that if the mode has changed then the NOPS that we use will | |
14713 | match the encoding of the last instruction in the frag. */ | |
14714 | frag_now->tc_frag_data = thumb_mode | MODE_RECORDED; | |
c19d1205 ZW |
14715 | |
14716 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 14717 | { |
9c2799c2 | 14718 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 14719 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 14720 | } |
c19d1205 | 14721 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 14722 | { |
9c2799c2 | 14723 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
14724 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
14725 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 14726 | } |
c19d1205 ZW |
14727 | else |
14728 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 14729 | |
c19d1205 ZW |
14730 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
14731 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
14732 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
14733 | inst.reloc.type); | |
b99bd4ef | 14734 | |
c19d1205 | 14735 | dwarf2_emit_insn (inst.size); |
c19d1205 | 14736 | } |
b99bd4ef | 14737 | |
e07e6e58 NC |
14738 | static char * |
14739 | output_it_inst (int cond, int mask, char * to) | |
14740 | { | |
14741 | unsigned long instruction = 0xbf00; | |
14742 | ||
14743 | mask &= 0xf; | |
14744 | instruction |= mask; | |
14745 | instruction |= cond << 4; | |
14746 | ||
14747 | if (to == NULL) | |
14748 | { | |
14749 | to = frag_more (2); | |
14750 | #ifdef OBJ_ELF | |
14751 | dwarf2_emit_insn (2); | |
14752 | #endif | |
14753 | } | |
14754 | ||
14755 | md_number_to_chars (to, instruction, 2); | |
14756 | ||
14757 | return to; | |
14758 | } | |
14759 | ||
c19d1205 ZW |
14760 | /* Tag values used in struct asm_opcode's tag field. */ |
14761 | enum opcode_tag | |
14762 | { | |
14763 | OT_unconditional, /* Instruction cannot be conditionalized. | |
14764 | The ARM condition field is still 0xE. */ | |
14765 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
14766 | and carries 0xF in its ARM condition field. */ | |
14767 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 JB |
14768 | OT_csuffixF, /* Some forms of the instruction take a conditional |
14769 | suffix, others place 0xF where the condition field | |
14770 | would be. */ | |
c19d1205 ZW |
14771 | OT_cinfix3, /* Instruction takes a conditional infix, |
14772 | beginning at character index 3. (In | |
14773 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
14774 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
14775 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
14776 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
14777 | character index 3, even in unified mode. Used for | |
14778 | legacy instructions where suffix and infix forms | |
14779 | may be ambiguous. */ | |
c19d1205 | 14780 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 14781 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
14782 | OT_odd_infix_unc, /* This is the unconditional variant of an |
14783 | instruction that takes a conditional infix | |
14784 | at an unusual position. In unified mode, | |
14785 | this variant will accept a suffix. */ | |
14786 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
14787 | are the conditional variants of instructions that | |
14788 | take conditional infixes in unusual positions. | |
14789 | The infix appears at character index | |
14790 | (tag - OT_odd_infix_0). These are not accepted | |
14791 | in unified mode. */ | |
14792 | }; | |
b99bd4ef | 14793 | |
c19d1205 ZW |
14794 | /* Subroutine of md_assemble, responsible for looking up the primary |
14795 | opcode from the mnemonic the user wrote. STR points to the | |
14796 | beginning of the mnemonic. | |
14797 | ||
14798 | This is not simply a hash table lookup, because of conditional | |
14799 | variants. Most instructions have conditional variants, which are | |
14800 | expressed with a _conditional affix_ to the mnemonic. If we were | |
14801 | to encode each conditional variant as a literal string in the opcode | |
14802 | table, it would have approximately 20,000 entries. | |
14803 | ||
14804 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
14805 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
14806 | instructions take the affix as an infix, notably the s-variants of | |
14807 | the arithmetic instructions. Of those instructions, all but six | |
14808 | have the infix appear after the third character of the mnemonic. | |
14809 | ||
14810 | Accordingly, the algorithm for looking up primary opcodes given | |
14811 | an identifier is: | |
14812 | ||
14813 | 1. Look up the identifier in the opcode table. | |
14814 | If we find a match, go to step U. | |
14815 | ||
14816 | 2. Look up the last two characters of the identifier in the | |
14817 | conditions table. If we find a match, look up the first N-2 | |
14818 | characters of the identifier in the opcode table. If we | |
14819 | find a match, go to step CE. | |
14820 | ||
14821 | 3. Look up the fourth and fifth characters of the identifier in | |
14822 | the conditions table. If we find a match, extract those | |
14823 | characters from the identifier, and look up the remaining | |
14824 | characters in the opcode table. If we find a match, go | |
14825 | to step CM. | |
14826 | ||
14827 | 4. Fail. | |
14828 | ||
14829 | U. Examine the tag field of the opcode structure, in case this is | |
14830 | one of the six instructions with its conditional infix in an | |
14831 | unusual place. If it is, the tag tells us where to find the | |
14832 | infix; look it up in the conditions table and set inst.cond | |
14833 | accordingly. Otherwise, this is an unconditional instruction. | |
14834 | Again set inst.cond accordingly. Return the opcode structure. | |
14835 | ||
14836 | CE. Examine the tag field to make sure this is an instruction that | |
14837 | should receive a conditional suffix. If it is not, fail. | |
14838 | Otherwise, set inst.cond from the suffix we already looked up, | |
14839 | and return the opcode structure. | |
14840 | ||
14841 | CM. Examine the tag field to make sure this is an instruction that | |
14842 | should receive a conditional infix after the third character. | |
14843 | If it is not, fail. Otherwise, undo the edits to the current | |
14844 | line of input and proceed as for case CE. */ | |
14845 | ||
14846 | static const struct asm_opcode * | |
14847 | opcode_lookup (char **str) | |
14848 | { | |
14849 | char *end, *base; | |
14850 | char *affix; | |
14851 | const struct asm_opcode *opcode; | |
14852 | const struct asm_cond *cond; | |
e3cb604e | 14853 | char save[2]; |
267d2029 | 14854 | bfd_boolean neon_supported; |
5f4273c7 | 14855 | |
267d2029 | 14856 | neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1); |
c19d1205 ZW |
14857 | |
14858 | /* Scan up to the end of the mnemonic, which must end in white space, | |
267d2029 | 14859 | '.' (in unified mode, or for Neon instructions), or end of string. */ |
c19d1205 | 14860 | for (base = end = *str; *end != '\0'; end++) |
267d2029 | 14861 | if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.')) |
c19d1205 | 14862 | break; |
b99bd4ef | 14863 | |
c19d1205 | 14864 | if (end == base) |
c921be7d | 14865 | return NULL; |
b99bd4ef | 14866 | |
5287ad62 | 14867 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 14868 | if (end[0] == '.') |
b99bd4ef | 14869 | { |
5287ad62 | 14870 | int offset = 2; |
5f4273c7 | 14871 | |
267d2029 JB |
14872 | /* The .w and .n suffixes are only valid if the unified syntax is in |
14873 | use. */ | |
14874 | if (unified_syntax && end[1] == 'w') | |
c19d1205 | 14875 | inst.size_req = 4; |
267d2029 | 14876 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
14877 | inst.size_req = 2; |
14878 | else | |
5287ad62 JB |
14879 | offset = 0; |
14880 | ||
14881 | inst.vectype.elems = 0; | |
14882 | ||
14883 | *str = end + offset; | |
b99bd4ef | 14884 | |
5f4273c7 | 14885 | if (end[offset] == '.') |
5287ad62 | 14886 | { |
267d2029 JB |
14887 | /* See if we have a Neon type suffix (possible in either unified or |
14888 | non-unified ARM syntax mode). */ | |
dcbf9037 | 14889 | if (parse_neon_type (&inst.vectype, str) == FAIL) |
c921be7d | 14890 | return NULL; |
5287ad62 JB |
14891 | } |
14892 | else if (end[offset] != '\0' && end[offset] != ' ') | |
c921be7d | 14893 | return NULL; |
b99bd4ef | 14894 | } |
c19d1205 ZW |
14895 | else |
14896 | *str = end; | |
b99bd4ef | 14897 | |
c19d1205 ZW |
14898 | /* Look for unaffixed or special-case affixed mnemonic. */ |
14899 | opcode = hash_find_n (arm_ops_hsh, base, end - base); | |
14900 | if (opcode) | |
b99bd4ef | 14901 | { |
c19d1205 ZW |
14902 | /* step U */ |
14903 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 14904 | { |
c19d1205 ZW |
14905 | inst.cond = COND_ALWAYS; |
14906 | return opcode; | |
b99bd4ef | 14907 | } |
b99bd4ef | 14908 | |
278df34e | 14909 | if (warn_on_deprecated && unified_syntax) |
c19d1205 ZW |
14910 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
14911 | affix = base + (opcode->tag - OT_odd_infix_0); | |
14912 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
9c2799c2 | 14913 | gas_assert (cond); |
b99bd4ef | 14914 | |
c19d1205 ZW |
14915 | inst.cond = cond->value; |
14916 | return opcode; | |
14917 | } | |
b99bd4ef | 14918 | |
c19d1205 ZW |
14919 | /* Cannot have a conditional suffix on a mnemonic of less than two |
14920 | characters. */ | |
14921 | if (end - base < 3) | |
c921be7d | 14922 | return NULL; |
b99bd4ef | 14923 | |
c19d1205 ZW |
14924 | /* Look for suffixed mnemonic. */ |
14925 | affix = end - 2; | |
14926 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
14927 | opcode = hash_find_n (arm_ops_hsh, base, affix - base); | |
14928 | if (opcode && cond) | |
14929 | { | |
14930 | /* step CE */ | |
14931 | switch (opcode->tag) | |
14932 | { | |
e3cb604e PB |
14933 | case OT_cinfix3_legacy: |
14934 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
14935 | break; | |
14936 | ||
c19d1205 | 14937 | case OT_cinfix3: |
088fa78e | 14938 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
14939 | case OT_odd_infix_unc: |
14940 | if (!unified_syntax) | |
e3cb604e | 14941 | return 0; |
c19d1205 ZW |
14942 | /* else fall through */ |
14943 | ||
14944 | case OT_csuffix: | |
037e8744 | 14945 | case OT_csuffixF: |
c19d1205 ZW |
14946 | case OT_csuf_or_in3: |
14947 | inst.cond = cond->value; | |
14948 | return opcode; | |
14949 | ||
14950 | case OT_unconditional: | |
14951 | case OT_unconditionalF: | |
dfa9f0d5 | 14952 | if (thumb_mode) |
c921be7d | 14953 | inst.cond = cond->value; |
dfa9f0d5 PB |
14954 | else |
14955 | { | |
c921be7d | 14956 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
14957 | inst.error = BAD_COND; |
14958 | inst.cond = COND_ALWAYS; | |
14959 | } | |
c19d1205 | 14960 | return opcode; |
b99bd4ef | 14961 | |
c19d1205 | 14962 | default: |
c921be7d | 14963 | return NULL; |
c19d1205 ZW |
14964 | } |
14965 | } | |
b99bd4ef | 14966 | |
c19d1205 ZW |
14967 | /* Cannot have a usual-position infix on a mnemonic of less than |
14968 | six characters (five would be a suffix). */ | |
14969 | if (end - base < 6) | |
c921be7d | 14970 | return NULL; |
b99bd4ef | 14971 | |
c19d1205 ZW |
14972 | /* Look for infixed mnemonic in the usual position. */ |
14973 | affix = base + 3; | |
14974 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
e3cb604e | 14975 | if (!cond) |
c921be7d | 14976 | return NULL; |
e3cb604e PB |
14977 | |
14978 | memcpy (save, affix, 2); | |
14979 | memmove (affix, affix + 2, (end - affix) - 2); | |
14980 | opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2); | |
14981 | memmove (affix + 2, affix, (end - affix) - 2); | |
14982 | memcpy (affix, save, 2); | |
14983 | ||
088fa78e KH |
14984 | if (opcode |
14985 | && (opcode->tag == OT_cinfix3 | |
14986 | || opcode->tag == OT_cinfix3_deprecated | |
14987 | || opcode->tag == OT_csuf_or_in3 | |
14988 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 14989 | { |
c921be7d | 14990 | /* Step CM. */ |
278df34e | 14991 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
14992 | && (opcode->tag == OT_cinfix3 |
14993 | || opcode->tag == OT_cinfix3_deprecated)) | |
c19d1205 ZW |
14994 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
14995 | ||
14996 | inst.cond = cond->value; | |
14997 | return opcode; | |
b99bd4ef NC |
14998 | } |
14999 | ||
c921be7d | 15000 | return NULL; |
b99bd4ef NC |
15001 | } |
15002 | ||
e07e6e58 NC |
15003 | /* This function generates an initial IT instruction, leaving its block |
15004 | virtually open for the new instructions. Eventually, | |
15005 | the mask will be updated by now_it_add_mask () each time | |
15006 | a new instruction needs to be included in the IT block. | |
15007 | Finally, the block is closed with close_automatic_it_block (). | |
15008 | The block closure can be requested either from md_assemble (), | |
15009 | a tencode (), or due to a label hook. */ | |
15010 | ||
15011 | static void | |
15012 | new_automatic_it_block (int cond) | |
15013 | { | |
15014 | now_it.state = AUTOMATIC_IT_BLOCK; | |
15015 | now_it.mask = 0x18; | |
15016 | now_it.cc = cond; | |
15017 | now_it.block_length = 1; | |
15018 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); | |
15019 | } | |
15020 | ||
15021 | /* Close an automatic IT block. | |
15022 | See comments in new_automatic_it_block (). */ | |
15023 | ||
15024 | static void | |
15025 | close_automatic_it_block (void) | |
15026 | { | |
15027 | now_it.mask = 0x10; | |
15028 | now_it.block_length = 0; | |
15029 | } | |
15030 | ||
15031 | /* Update the mask of the current automatically-generated IT | |
15032 | instruction. See comments in new_automatic_it_block (). */ | |
15033 | ||
15034 | static void | |
15035 | now_it_add_mask (int cond) | |
15036 | { | |
15037 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
15038 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
15039 | | ((bitvalue) << (nbit))) | |
e07e6e58 | 15040 | const int resulting_bit = (cond & 1); |
c921be7d | 15041 | |
e07e6e58 NC |
15042 | now_it.mask &= 0xf; |
15043 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15044 | resulting_bit, | |
15045 | (5 - now_it.block_length)); | |
15046 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
15047 | 1, | |
15048 | ((5 - now_it.block_length) - 1) ); | |
15049 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); | |
15050 | ||
15051 | #undef CLEAR_BIT | |
15052 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
15053 | } |
15054 | ||
15055 | /* The IT blocks handling machinery is accessed through the these functions: | |
15056 | it_fsm_pre_encode () from md_assemble () | |
15057 | set_it_insn_type () optional, from the tencode functions | |
15058 | set_it_insn_type_last () ditto | |
15059 | in_it_block () ditto | |
15060 | it_fsm_post_encode () from md_assemble () | |
15061 | force_automatic_it_block_close () from label habdling functions | |
15062 | ||
15063 | Rationale: | |
15064 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
15065 | initializing the IT insn type with a generic initial value depending | |
15066 | on the inst.condition. | |
15067 | 2) During the tencode function, two things may happen: | |
15068 | a) The tencode function overrides the IT insn type by | |
15069 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
15070 | b) The tencode function queries the IT block state by | |
15071 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
15072 | ||
15073 | Both set_it_insn_type and in_it_block run the internal FSM state | |
15074 | handling function (handle_it_state), because: a) setting the IT insn | |
15075 | type may incur in an invalid state (exiting the function), | |
15076 | and b) querying the state requires the FSM to be updated. | |
15077 | Specifically we want to avoid creating an IT block for conditional | |
15078 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
15079 | determine whether an IT block is required until the tencode () routine | |
15080 | has decided what type of instruction this actually it. | |
15081 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
15082 | set_it_insn_type has to be called first. | |
15083 | ||
15084 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
15085 | determines the insn IT type depending on the inst.cond code. | |
15086 | When a tencode () routine encodes an instruction that can be | |
15087 | either outside an IT block, or, in the case of being inside, has to be | |
15088 | the last one, set_it_insn_type_last () will determine the proper | |
15089 | IT instruction type based on the inst.cond code. Otherwise, | |
15090 | set_it_insn_type can be called for overriding that logic or | |
15091 | for covering other cases. | |
15092 | ||
15093 | Calling handle_it_state () may not transition the IT block state to | |
15094 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
15095 | still queried. Instead, if the FSM determines that the state should | |
15096 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
15097 | after the tencode () function: that's what it_fsm_post_encode () does. | |
15098 | ||
15099 | Since in_it_block () calls the state handling function to get an | |
15100 | updated state, an error may occur (due to invalid insns combination). | |
15101 | In that case, inst.error is set. | |
15102 | Therefore, inst.error has to be checked after the execution of | |
15103 | the tencode () routine. | |
15104 | ||
15105 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
15106 | any pending state change (if any) that didn't take place in | |
15107 | handle_it_state () as explained above. */ | |
15108 | ||
15109 | static void | |
15110 | it_fsm_pre_encode (void) | |
15111 | { | |
15112 | if (inst.cond != COND_ALWAYS) | |
15113 | inst.it_insn_type = INSIDE_IT_INSN; | |
15114 | else | |
15115 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
15116 | ||
15117 | now_it.state_handled = 0; | |
15118 | } | |
15119 | ||
15120 | /* IT state FSM handling function. */ | |
15121 | ||
15122 | static int | |
15123 | handle_it_state (void) | |
15124 | { | |
15125 | now_it.state_handled = 1; | |
15126 | ||
15127 | switch (now_it.state) | |
15128 | { | |
15129 | case OUTSIDE_IT_BLOCK: | |
15130 | switch (inst.it_insn_type) | |
15131 | { | |
15132 | case OUTSIDE_IT_INSN: | |
15133 | break; | |
15134 | ||
15135 | case INSIDE_IT_INSN: | |
15136 | case INSIDE_IT_LAST_INSN: | |
15137 | if (thumb_mode == 0) | |
15138 | { | |
c921be7d | 15139 | if (unified_syntax |
e07e6e58 NC |
15140 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
15141 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
15142 | " for Thumb.")); | |
15143 | } | |
15144 | else | |
15145 | { | |
15146 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
15147 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)) | |
15148 | { | |
15149 | /* Automatically generate the IT instruction. */ | |
15150 | new_automatic_it_block (inst.cond); | |
15151 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
15152 | close_automatic_it_block (); | |
15153 | } | |
15154 | else | |
15155 | { | |
15156 | inst.error = BAD_OUT_IT; | |
15157 | return FAIL; | |
15158 | } | |
15159 | } | |
15160 | break; | |
15161 | ||
15162 | case IF_INSIDE_IT_LAST_INSN: | |
15163 | case NEUTRAL_IT_INSN: | |
15164 | break; | |
15165 | ||
15166 | case IT_INSN: | |
15167 | now_it.state = MANUAL_IT_BLOCK; | |
15168 | now_it.block_length = 0; | |
15169 | break; | |
15170 | } | |
15171 | break; | |
15172 | ||
15173 | case AUTOMATIC_IT_BLOCK: | |
15174 | /* Three things may happen now: | |
15175 | a) We should increment current it block size; | |
15176 | b) We should close current it block (closing insn or 4 insns); | |
15177 | c) We should close current it block and start a new one (due | |
15178 | to incompatible conditions or | |
15179 | 4 insns-length block reached). */ | |
15180 | ||
15181 | switch (inst.it_insn_type) | |
15182 | { | |
15183 | case OUTSIDE_IT_INSN: | |
15184 | /* The closure of the block shall happen immediatelly, | |
15185 | so any in_it_block () call reports the block as closed. */ | |
15186 | force_automatic_it_block_close (); | |
15187 | break; | |
15188 | ||
15189 | case INSIDE_IT_INSN: | |
15190 | case INSIDE_IT_LAST_INSN: | |
15191 | case IF_INSIDE_IT_LAST_INSN: | |
15192 | now_it.block_length++; | |
15193 | ||
15194 | if (now_it.block_length > 4 | |
15195 | || !now_it_compatible (inst.cond)) | |
15196 | { | |
15197 | force_automatic_it_block_close (); | |
15198 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
15199 | new_automatic_it_block (inst.cond); | |
15200 | } | |
15201 | else | |
15202 | { | |
15203 | now_it_add_mask (inst.cond); | |
15204 | } | |
15205 | ||
15206 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
15207 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
15208 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
15209 | close_automatic_it_block (); | |
15210 | break; | |
15211 | ||
15212 | case NEUTRAL_IT_INSN: | |
15213 | now_it.block_length++; | |
15214 | ||
15215 | if (now_it.block_length > 4) | |
15216 | force_automatic_it_block_close (); | |
15217 | else | |
15218 | now_it_add_mask (now_it.cc & 1); | |
15219 | break; | |
15220 | ||
15221 | case IT_INSN: | |
15222 | close_automatic_it_block (); | |
15223 | now_it.state = MANUAL_IT_BLOCK; | |
15224 | break; | |
15225 | } | |
15226 | break; | |
15227 | ||
15228 | case MANUAL_IT_BLOCK: | |
15229 | { | |
15230 | /* Check conditional suffixes. */ | |
15231 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
15232 | int is_last; | |
15233 | now_it.mask <<= 1; | |
15234 | now_it.mask &= 0x1f; | |
15235 | is_last = (now_it.mask == 0x10); | |
15236 | ||
15237 | switch (inst.it_insn_type) | |
15238 | { | |
15239 | case OUTSIDE_IT_INSN: | |
15240 | inst.error = BAD_NOT_IT; | |
15241 | return FAIL; | |
15242 | ||
15243 | case INSIDE_IT_INSN: | |
15244 | if (cond != inst.cond) | |
15245 | { | |
15246 | inst.error = BAD_IT_COND; | |
15247 | return FAIL; | |
15248 | } | |
15249 | break; | |
15250 | ||
15251 | case INSIDE_IT_LAST_INSN: | |
15252 | case IF_INSIDE_IT_LAST_INSN: | |
15253 | if (cond != inst.cond) | |
15254 | { | |
15255 | inst.error = BAD_IT_COND; | |
15256 | return FAIL; | |
15257 | } | |
15258 | if (!is_last) | |
15259 | { | |
15260 | inst.error = BAD_BRANCH; | |
15261 | return FAIL; | |
15262 | } | |
15263 | break; | |
15264 | ||
15265 | case NEUTRAL_IT_INSN: | |
15266 | /* The BKPT instruction is unconditional even in an IT block. */ | |
15267 | break; | |
15268 | ||
15269 | case IT_INSN: | |
15270 | inst.error = BAD_IT_IT; | |
15271 | return FAIL; | |
15272 | } | |
15273 | } | |
15274 | break; | |
15275 | } | |
15276 | ||
15277 | return SUCCESS; | |
15278 | } | |
15279 | ||
15280 | static void | |
15281 | it_fsm_post_encode (void) | |
15282 | { | |
15283 | int is_last; | |
15284 | ||
15285 | if (!now_it.state_handled) | |
15286 | handle_it_state (); | |
15287 | ||
15288 | is_last = (now_it.mask == 0x10); | |
15289 | if (is_last) | |
15290 | { | |
15291 | now_it.state = OUTSIDE_IT_BLOCK; | |
15292 | now_it.mask = 0; | |
15293 | } | |
15294 | } | |
15295 | ||
15296 | static void | |
15297 | force_automatic_it_block_close (void) | |
15298 | { | |
15299 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
15300 | { | |
15301 | close_automatic_it_block (); | |
15302 | now_it.state = OUTSIDE_IT_BLOCK; | |
15303 | now_it.mask = 0; | |
15304 | } | |
15305 | } | |
15306 | ||
15307 | static int | |
15308 | in_it_block (void) | |
15309 | { | |
15310 | if (!now_it.state_handled) | |
15311 | handle_it_state (); | |
15312 | ||
15313 | return now_it.state != OUTSIDE_IT_BLOCK; | |
15314 | } | |
15315 | ||
c19d1205 ZW |
15316 | void |
15317 | md_assemble (char *str) | |
b99bd4ef | 15318 | { |
c19d1205 ZW |
15319 | char *p = str; |
15320 | const struct asm_opcode * opcode; | |
b99bd4ef | 15321 | |
c19d1205 ZW |
15322 | /* Align the previous label if needed. */ |
15323 | if (last_label_seen != NULL) | |
b99bd4ef | 15324 | { |
c19d1205 ZW |
15325 | symbol_set_frag (last_label_seen, frag_now); |
15326 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
15327 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
15328 | } |
15329 | ||
c19d1205 ZW |
15330 | memset (&inst, '\0', sizeof (inst)); |
15331 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 15332 | |
c19d1205 ZW |
15333 | opcode = opcode_lookup (&p); |
15334 | if (!opcode) | |
b99bd4ef | 15335 | { |
c19d1205 | 15336 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 15337 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d NC |
15338 | if (! create_register_alias (str, p) |
15339 | && ! create_neon_reg_alias (str, p)) | |
c19d1205 | 15340 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 15341 | |
b99bd4ef NC |
15342 | return; |
15343 | } | |
15344 | ||
278df34e | 15345 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
088fa78e KH |
15346 | as_warn (_("s suffix on comparison instruction is deprecated")); |
15347 | ||
037e8744 JB |
15348 | /* The value which unconditional instructions should have in place of the |
15349 | condition field. */ | |
15350 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
15351 | ||
c19d1205 | 15352 | if (thumb_mode) |
b99bd4ef | 15353 | { |
e74cfd16 | 15354 | arm_feature_set variant; |
8f06b2d8 PB |
15355 | |
15356 | variant = cpu_variant; | |
15357 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
15358 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
15359 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 15360 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
15361 | if (!opcode->tvariant |
15362 | || (thumb_mode == 1 | |
15363 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 15364 | { |
c19d1205 | 15365 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
15366 | return; |
15367 | } | |
c19d1205 ZW |
15368 | if (inst.cond != COND_ALWAYS && !unified_syntax |
15369 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 15370 | { |
c19d1205 | 15371 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
15372 | return; |
15373 | } | |
15374 | ||
752d5da4 | 15375 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)) |
076d447c | 15376 | { |
7e806470 | 15377 | if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23 |
752d5da4 NC |
15378 | && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr) |
15379 | || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier))) | |
15380 | { | |
15381 | /* Two things are addressed here. | |
15382 | 1) Implicit require narrow instructions on Thumb-1. | |
15383 | This avoids relaxation accidentally introducing Thumb-2 | |
15384 | instructions. | |
15385 | 2) Reject wide instructions in non Thumb-2 cores. */ | |
15386 | if (inst.size_req == 0) | |
15387 | inst.size_req = 2; | |
15388 | else if (inst.size_req == 4) | |
15389 | { | |
15390 | as_bad (_("selected processor does not support `%s'"), str); | |
15391 | return; | |
15392 | } | |
15393 | } | |
076d447c PB |
15394 | } |
15395 | ||
c19d1205 ZW |
15396 | mapping_state (MAP_THUMB); |
15397 | inst.instruction = opcode->tvalue; | |
15398 | ||
15399 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15400 | { |
15401 | /* Prepare the it_insn_type for those encodings that don't set | |
15402 | it. */ | |
15403 | it_fsm_pre_encode (); | |
c19d1205 | 15404 | |
e07e6e58 NC |
15405 | opcode->tencode (); |
15406 | ||
15407 | it_fsm_post_encode (); | |
15408 | } | |
e27ec89e | 15409 | |
0110f2b8 | 15410 | if (!(inst.error || inst.relax)) |
b99bd4ef | 15411 | { |
9c2799c2 | 15412 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
15413 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
15414 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 15415 | { |
c19d1205 | 15416 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
15417 | return; |
15418 | } | |
15419 | } | |
076d447c PB |
15420 | |
15421 | /* Something has gone badly wrong if we try to relax a fixed size | |
15422 | instruction. */ | |
9c2799c2 | 15423 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 15424 | |
e74cfd16 PB |
15425 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15426 | *opcode->tvariant); | |
ee065d83 | 15427 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 15428 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
7e806470 | 15429 | anything other than bl/blx and v6-M instructions. |
ee065d83 | 15430 | This is overly pessimistic for relaxable instructions. */ |
7e806470 PB |
15431 | if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) |
15432 | || inst.relax) | |
e07e6e58 NC |
15433 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
15434 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
e74cfd16 PB |
15435 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15436 | arm_ext_v6t2); | |
c19d1205 | 15437 | } |
3e9e4fcf | 15438 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 15439 | { |
845b51d6 PB |
15440 | bfd_boolean is_bx; |
15441 | ||
15442 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
15443 | is_bx = (opcode->aencode == do_bx); | |
15444 | ||
c19d1205 | 15445 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
15446 | if (!(is_bx && fix_v4bx) |
15447 | && !(opcode->avariant && | |
15448 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 15449 | { |
c19d1205 ZW |
15450 | as_bad (_("selected processor does not support `%s'"), str); |
15451 | return; | |
b99bd4ef | 15452 | } |
c19d1205 | 15453 | if (inst.size_req) |
b99bd4ef | 15454 | { |
c19d1205 ZW |
15455 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
15456 | return; | |
b99bd4ef NC |
15457 | } |
15458 | ||
c19d1205 ZW |
15459 | mapping_state (MAP_ARM); |
15460 | inst.instruction = opcode->avalue; | |
15461 | if (opcode->tag == OT_unconditionalF) | |
15462 | inst.instruction |= 0xF << 28; | |
15463 | else | |
15464 | inst.instruction |= inst.cond << 28; | |
15465 | inst.size = INSN_SIZE; | |
15466 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15467 | { |
15468 | it_fsm_pre_encode (); | |
15469 | opcode->aencode (); | |
15470 | it_fsm_post_encode (); | |
15471 | } | |
ee065d83 PB |
15472 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
15473 | on a hypothetical non-thumb v5 core. */ | |
845b51d6 | 15474 | if (is_bx) |
e74cfd16 | 15475 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 15476 | else |
e74cfd16 PB |
15477 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
15478 | *opcode->avariant); | |
b99bd4ef | 15479 | } |
3e9e4fcf JB |
15480 | else |
15481 | { | |
15482 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
15483 | "-- `%s'"), str); | |
15484 | return; | |
15485 | } | |
c19d1205 ZW |
15486 | output_inst (str); |
15487 | } | |
b99bd4ef | 15488 | |
e07e6e58 NC |
15489 | static void |
15490 | check_it_blocks_finished (void) | |
15491 | { | |
15492 | #ifdef OBJ_ELF | |
15493 | asection *sect; | |
15494 | ||
15495 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
15496 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
15497 | == MANUAL_IT_BLOCK) | |
15498 | { | |
15499 | as_warn (_("section '%s' finished with an open IT block."), | |
15500 | sect->name); | |
15501 | } | |
15502 | #else | |
15503 | if (now_it.state == MANUAL_IT_BLOCK) | |
15504 | as_warn (_("file finished with an open IT block.")); | |
15505 | #endif | |
15506 | } | |
15507 | ||
c19d1205 ZW |
15508 | /* Various frobbings of labels and their addresses. */ |
15509 | ||
15510 | void | |
15511 | arm_start_line_hook (void) | |
15512 | { | |
15513 | last_label_seen = NULL; | |
b99bd4ef NC |
15514 | } |
15515 | ||
c19d1205 ZW |
15516 | void |
15517 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 15518 | { |
c19d1205 | 15519 | last_label_seen = sym; |
b99bd4ef | 15520 | |
c19d1205 | 15521 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 15522 | |
c19d1205 ZW |
15523 | #if defined OBJ_COFF || defined OBJ_ELF |
15524 | ARM_SET_INTERWORK (sym, support_interwork); | |
15525 | #endif | |
b99bd4ef | 15526 | |
e07e6e58 NC |
15527 | force_automatic_it_block_close (); |
15528 | ||
5f4273c7 | 15529 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
15530 | as Thumb functions. This is because these labels, whilst |
15531 | they exist inside Thumb code, are not the entry points for | |
15532 | possible ARM->Thumb calls. Also, these labels can be used | |
15533 | as part of a computed goto or switch statement. eg gcc | |
15534 | can generate code that looks like this: | |
b99bd4ef | 15535 | |
c19d1205 ZW |
15536 | ldr r2, [pc, .Laaa] |
15537 | lsl r3, r3, #2 | |
15538 | ldr r2, [r3, r2] | |
15539 | mov pc, r2 | |
b99bd4ef | 15540 | |
c19d1205 ZW |
15541 | .Lbbb: .word .Lxxx |
15542 | .Lccc: .word .Lyyy | |
15543 | ..etc... | |
15544 | .Laaa: .word Lbbb | |
b99bd4ef | 15545 | |
c19d1205 ZW |
15546 | The first instruction loads the address of the jump table. |
15547 | The second instruction converts a table index into a byte offset. | |
15548 | The third instruction gets the jump address out of the table. | |
15549 | The fourth instruction performs the jump. | |
b99bd4ef | 15550 | |
c19d1205 ZW |
15551 | If the address stored at .Laaa is that of a symbol which has the |
15552 | Thumb_Func bit set, then the linker will arrange for this address | |
15553 | to have the bottom bit set, which in turn would mean that the | |
15554 | address computation performed by the third instruction would end | |
15555 | up with the bottom bit set. Since the ARM is capable of unaligned | |
15556 | word loads, the instruction would then load the incorrect address | |
15557 | out of the jump table, and chaos would ensue. */ | |
15558 | if (label_is_thumb_function_name | |
15559 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
15560 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 15561 | { |
c19d1205 ZW |
15562 | /* When the address of a Thumb function is taken the bottom |
15563 | bit of that address should be set. This will allow | |
15564 | interworking between Arm and Thumb functions to work | |
15565 | correctly. */ | |
b99bd4ef | 15566 | |
c19d1205 | 15567 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 15568 | |
c19d1205 | 15569 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 15570 | } |
07a53e5c | 15571 | |
07a53e5c | 15572 | dwarf2_emit_label (sym); |
b99bd4ef NC |
15573 | } |
15574 | ||
c921be7d | 15575 | bfd_boolean |
c19d1205 | 15576 | arm_data_in_code (void) |
b99bd4ef | 15577 | { |
c19d1205 | 15578 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 15579 | { |
c19d1205 ZW |
15580 | *input_line_pointer = '/'; |
15581 | input_line_pointer += 5; | |
15582 | *input_line_pointer = 0; | |
c921be7d | 15583 | return TRUE; |
b99bd4ef NC |
15584 | } |
15585 | ||
c921be7d | 15586 | return FALSE; |
b99bd4ef NC |
15587 | } |
15588 | ||
c19d1205 ZW |
15589 | char * |
15590 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 15591 | { |
c19d1205 | 15592 | int len; |
b99bd4ef | 15593 | |
c19d1205 ZW |
15594 | if (thumb_mode && (len = strlen (name)) > 5 |
15595 | && streq (name + len - 5, "/data")) | |
15596 | *(name + len - 5) = 0; | |
b99bd4ef | 15597 | |
c19d1205 | 15598 | return name; |
b99bd4ef | 15599 | } |
c19d1205 ZW |
15600 | \f |
15601 | /* Table of all register names defined by default. The user can | |
15602 | define additional names with .req. Note that all register names | |
15603 | should appear in both upper and lowercase variants. Some registers | |
15604 | also have mixed-case names. */ | |
b99bd4ef | 15605 | |
dcbf9037 | 15606 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 15607 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 15608 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
15609 | #define REGSET(p,t) \ |
15610 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
15611 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
15612 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
15613 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
15614 | #define REGSETH(p,t) \ |
15615 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
15616 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
15617 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
15618 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
15619 | #define REGSET2(p,t) \ | |
15620 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
15621 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
15622 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
15623 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
7ed4c4c5 | 15624 | |
c19d1205 | 15625 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 15626 | { |
c19d1205 ZW |
15627 | /* ARM integer registers. */ |
15628 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 15629 | |
c19d1205 ZW |
15630 | /* ATPCS synonyms. */ |
15631 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
15632 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
15633 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 15634 | |
c19d1205 ZW |
15635 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
15636 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
15637 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 15638 | |
c19d1205 ZW |
15639 | /* Well-known aliases. */ |
15640 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
15641 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
15642 | ||
15643 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
15644 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
15645 | ||
15646 | /* Coprocessor numbers. */ | |
15647 | REGSET(p, CP), REGSET(P, CP), | |
15648 | ||
15649 | /* Coprocessor register numbers. The "cr" variants are for backward | |
15650 | compatibility. */ | |
15651 | REGSET(c, CN), REGSET(C, CN), | |
15652 | REGSET(cr, CN), REGSET(CR, CN), | |
15653 | ||
15654 | /* FPA registers. */ | |
15655 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
15656 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
15657 | ||
15658 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
15659 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
15660 | ||
15661 | /* VFP SP registers. */ | |
5287ad62 JB |
15662 | REGSET(s,VFS), REGSET(S,VFS), |
15663 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
15664 | |
15665 | /* VFP DP Registers. */ | |
5287ad62 JB |
15666 | REGSET(d,VFD), REGSET(D,VFD), |
15667 | /* Extra Neon DP registers. */ | |
15668 | REGSETH(d,VFD), REGSETH(D,VFD), | |
15669 | ||
15670 | /* Neon QP registers. */ | |
15671 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
15672 | |
15673 | /* VFP control registers. */ | |
15674 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
15675 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
15676 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
15677 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
15678 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
15679 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
15680 | |
15681 | /* Maverick DSP coprocessor registers. */ | |
15682 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
15683 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
15684 | ||
15685 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
15686 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
15687 | REGDEF(dspsc,0,DSPSC), | |
15688 | ||
15689 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
15690 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
15691 | REGDEF(DSPSC,0,DSPSC), | |
15692 | ||
15693 | /* iWMMXt data registers - p0, c0-15. */ | |
15694 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
15695 | ||
15696 | /* iWMMXt control registers - p1, c0-3. */ | |
15697 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
15698 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
15699 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
15700 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
15701 | ||
15702 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
15703 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
15704 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
15705 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
15706 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
15707 | ||
15708 | /* XScale accumulator registers. */ | |
15709 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
15710 | }; | |
15711 | #undef REGDEF | |
15712 | #undef REGNUM | |
15713 | #undef REGSET | |
7ed4c4c5 | 15714 | |
c19d1205 ZW |
15715 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
15716 | within psr_required_here. */ | |
15717 | static const struct asm_psr psrs[] = | |
15718 | { | |
15719 | /* Backward compatibility notation. Note that "all" is no longer | |
15720 | truly all possible PSR bits. */ | |
15721 | {"all", PSR_c | PSR_f}, | |
15722 | {"flg", PSR_f}, | |
15723 | {"ctl", PSR_c}, | |
15724 | ||
15725 | /* Individual flags. */ | |
15726 | {"f", PSR_f}, | |
15727 | {"c", PSR_c}, | |
15728 | {"x", PSR_x}, | |
15729 | {"s", PSR_s}, | |
15730 | /* Combinations of flags. */ | |
15731 | {"fs", PSR_f | PSR_s}, | |
15732 | {"fx", PSR_f | PSR_x}, | |
15733 | {"fc", PSR_f | PSR_c}, | |
15734 | {"sf", PSR_s | PSR_f}, | |
15735 | {"sx", PSR_s | PSR_x}, | |
15736 | {"sc", PSR_s | PSR_c}, | |
15737 | {"xf", PSR_x | PSR_f}, | |
15738 | {"xs", PSR_x | PSR_s}, | |
15739 | {"xc", PSR_x | PSR_c}, | |
15740 | {"cf", PSR_c | PSR_f}, | |
15741 | {"cs", PSR_c | PSR_s}, | |
15742 | {"cx", PSR_c | PSR_x}, | |
15743 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
15744 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
15745 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
15746 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
15747 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
15748 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
15749 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
15750 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
15751 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
15752 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
15753 | {"scf", PSR_s | PSR_c | PSR_f}, | |
15754 | {"scx", PSR_s | PSR_c | PSR_x}, | |
15755 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
15756 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
15757 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
15758 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
15759 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
15760 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
15761 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
15762 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
15763 | {"csf", PSR_c | PSR_s | PSR_f}, | |
15764 | {"csx", PSR_c | PSR_s | PSR_x}, | |
15765 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
15766 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
15767 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
15768 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
15769 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
15770 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
15771 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
15772 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
15773 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
15774 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
15775 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
15776 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
15777 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
15778 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
15779 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
15780 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
15781 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
15782 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
15783 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
15784 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
15785 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
15786 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
15787 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
15788 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
15789 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
15790 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
15791 | }; | |
15792 | ||
62b3e311 PB |
15793 | /* Table of V7M psr names. */ |
15794 | static const struct asm_psr v7m_psrs[] = | |
15795 | { | |
2b744c99 PB |
15796 | {"apsr", 0 }, {"APSR", 0 }, |
15797 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
15798 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
15799 | {"psr", 3 }, {"PSR", 3 }, | |
15800 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
15801 | {"ipsr", 5 }, {"IPSR", 5 }, | |
15802 | {"epsr", 6 }, {"EPSR", 6 }, | |
15803 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
15804 | {"msp", 8 }, {"MSP", 8 }, | |
15805 | {"psp", 9 }, {"PSP", 9 }, | |
15806 | {"primask", 16}, {"PRIMASK", 16}, | |
15807 | {"basepri", 17}, {"BASEPRI", 17}, | |
15808 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, | |
15809 | {"faultmask", 19}, {"FAULTMASK", 19}, | |
15810 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
15811 | }; |
15812 | ||
c19d1205 ZW |
15813 | /* Table of all shift-in-operand names. */ |
15814 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 15815 | { |
c19d1205 ZW |
15816 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
15817 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
15818 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
15819 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
15820 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
15821 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
15822 | }; | |
b99bd4ef | 15823 | |
c19d1205 ZW |
15824 | /* Table of all explicit relocation names. */ |
15825 | #ifdef OBJ_ELF | |
15826 | static struct reloc_entry reloc_names[] = | |
15827 | { | |
15828 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
15829 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
15830 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
15831 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
15832 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
15833 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
15834 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
15835 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
15836 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
15837 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
15838 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
15839 | }; | |
15840 | #endif | |
b99bd4ef | 15841 | |
c19d1205 ZW |
15842 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
15843 | static const struct asm_cond conds[] = | |
15844 | { | |
15845 | {"eq", 0x0}, | |
15846 | {"ne", 0x1}, | |
15847 | {"cs", 0x2}, {"hs", 0x2}, | |
15848 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
15849 | {"mi", 0x4}, | |
15850 | {"pl", 0x5}, | |
15851 | {"vs", 0x6}, | |
15852 | {"vc", 0x7}, | |
15853 | {"hi", 0x8}, | |
15854 | {"ls", 0x9}, | |
15855 | {"ge", 0xa}, | |
15856 | {"lt", 0xb}, | |
15857 | {"gt", 0xc}, | |
15858 | {"le", 0xd}, | |
15859 | {"al", 0xe} | |
15860 | }; | |
bfae80f2 | 15861 | |
62b3e311 PB |
15862 | static struct asm_barrier_opt barrier_opt_names[] = |
15863 | { | |
15864 | { "sy", 0xf }, | |
15865 | { "un", 0x7 }, | |
15866 | { "st", 0xe }, | |
15867 | { "unst", 0x6 } | |
15868 | }; | |
15869 | ||
c19d1205 ZW |
15870 | /* Table of ARM-format instructions. */ |
15871 | ||
15872 | /* Macros for gluing together operand strings. N.B. In all cases | |
15873 | other than OPS0, the trailing OP_stop comes from default | |
15874 | zero-initialization of the unspecified elements of the array. */ | |
15875 | #define OPS0() { OP_stop, } | |
15876 | #define OPS1(a) { OP_##a, } | |
15877 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
15878 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
15879 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
15880 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
15881 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
15882 | ||
15883 | /* These macros abstract out the exact format of the mnemonic table and | |
15884 | save some repeated characters. */ | |
15885 | ||
15886 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
15887 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
15888 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 15889 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15890 | |
15891 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
15892 | a T_MNEM_xyz enumerator. */ | |
15893 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 15894 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 15895 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15896 | TxCE (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
c19d1205 ZW |
15897 | |
15898 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
15899 | infix after the third character. */ | |
15900 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
15901 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 15902 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e KH |
15903 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
15904 | { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ | |
15905 | THUMB_VARIANT, do_##ae, do_##te } | |
c19d1205 | 15906 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15907 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 15908 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15909 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 15910 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15911 | TxC3 (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
088fa78e | 15912 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15913 | TxC3w (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
c19d1205 ZW |
15914 | |
15915 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
15916 | appear in the condition table. */ | |
15917 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
e07e6e58 | 15918 | { #m1 #m2 #m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \ |
1887dd22 | 15919 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15920 | |
15921 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
15922 | TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \ |
15923 | TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \ | |
15924 | TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \ | |
15925 | TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \ | |
15926 | TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \ | |
15927 | TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \ | |
15928 | TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \ | |
15929 | TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \ | |
15930 | TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \ | |
15931 | TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \ | |
15932 | TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \ | |
15933 | TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \ | |
15934 | TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \ | |
15935 | TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \ | |
15936 | TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \ | |
15937 | TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \ | |
15938 | TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \ | |
15939 | TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \ | |
15940 | TxCM_ (m1, al, m2, op, top, nops, ops, ae, te) | |
c19d1205 ZW |
15941 | |
15942 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
15943 | TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te) |
15944 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
15945 | TxCM (m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
c19d1205 ZW |
15946 | |
15947 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
15948 | field is still 0xE. Many of the Thumb variants can be executed |
15949 | conditionally, so this is checked separately. */ | |
c19d1205 ZW |
15950 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
15951 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 15952 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15953 | |
15954 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
15955 | condition code field. */ | |
15956 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
15957 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 15958 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15959 | |
15960 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
15961 | #define CE(mnem, op, nops, ops, ae) \ |
15962 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
15963 | ||
15964 | #define C3(mnem, op, nops, ops, ae) \ | |
15965 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
15966 | ||
e3cb604e PB |
15967 | /* Legacy mnemonics that always have conditional infix after the third |
15968 | character. */ | |
15969 | #define CL(mnem, op, nops, ops, ae) \ | |
15970 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
15971 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
15972 | ||
8f06b2d8 PB |
15973 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
15974 | #define cCE(mnem, op, nops, ops, ae) \ | |
15975 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
15976 | ||
e3cb604e PB |
15977 | /* Legacy coprocessor instructions where conditional infix and conditional |
15978 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
15979 | not just the potentially ambiguous ones. */ | |
15980 | #define cCL(mnem, op, nops, ops, ae) \ | |
15981 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
15982 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
15983 | ||
15984 | /* Coprocessor, takes either a suffix or a position-3 infix | |
15985 | (for an FPA corner case). */ | |
15986 | #define C3E(mnem, op, nops, ops, ae) \ | |
15987 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
15988 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 15989 | |
6a86118a NC |
15990 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
15991 | { #m1 #m2 #m3, OPS##nops ops, \ | |
e07e6e58 | 15992 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \ |
6a86118a NC |
15993 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
15994 | ||
15995 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
15996 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
15997 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
15998 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
15999 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
16000 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
16001 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
16002 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
16003 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
16004 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
16005 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
16006 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
16007 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
16008 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
16009 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
16010 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
16011 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
16012 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
16013 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
16014 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
16015 | |
16016 | #define UE(mnem, op, nops, ops, ae) \ | |
16017 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16018 | ||
16019 | #define UF(mnem, op, nops, ops, ae) \ | |
16020 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16021 | ||
5287ad62 JB |
16022 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
16023 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
16024 | use the same encoding function for each. */ | |
16025 | #define NUF(mnem, op, nops, ops, enc) \ | |
16026 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
16027 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16028 | ||
16029 | /* Neon data processing, version which indirects through neon_enc_tab for | |
16030 | the various overloaded versions of opcodes. */ | |
16031 | #define nUF(mnem, op, nops, ops, enc) \ | |
16032 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \ | |
16033 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16034 | ||
16035 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
16036 | version. */ | |
037e8744 JB |
16037 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
16038 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
16039 | THUMB_VARIANT, do_##enc, do_##enc } |
16040 | ||
037e8744 | 16041 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16042 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16043 | |
16044 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16045 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16046 | |
5287ad62 | 16047 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 JB |
16048 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
16049 | { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \ | |
5287ad62 JB |
16050 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
16051 | ||
037e8744 | 16052 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16053 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16054 | |
16055 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16056 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16057 | |
c19d1205 ZW |
16058 | #define do_0 0 |
16059 | ||
16060 | /* Thumb-only, unconditional. */ | |
e07e6e58 | 16061 | #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te) |
c19d1205 | 16062 | |
c19d1205 | 16063 | static const struct asm_opcode insns[] = |
bfae80f2 | 16064 | { |
e74cfd16 PB |
16065 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
16066 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
16067 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
16068 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
16069 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
16070 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
16071 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
16072 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
4962c51a MS |
16073 | tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub), |
16074 | tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
c19d1205 ZW |
16075 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), |
16076 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16077 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
16078 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
16079 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
16080 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16081 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
16082 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
16083 | ||
16084 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
16085 | for setting PSR flag bits. They are obsolete in V6 and do not | |
16086 | have Thumb equivalents. */ | |
16087 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 16088 | tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16089 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 | 16090 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
088fa78e | 16091 | tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
e3cb604e | 16092 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 | 16093 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 16094 | tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16095 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
16096 | |
16097 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
16098 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
16099 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
16100 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
16101 | ||
4962c51a MS |
16102 | tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), |
16103 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16104 | tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16105 | tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
c19d1205 | 16106 | |
f5208ef2 | 16107 | tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
16108 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16109 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
f5208ef2 | 16110 | tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
16111 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16112 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16113 | ||
16114 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
c16d2bf0 | 16115 | TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi), |
0110f2b8 | 16116 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 16117 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 16118 | |
c19d1205 | 16119 | /* Pseudo ops. */ |
e9f89963 | 16120 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
16121 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
16122 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
16123 | |
16124 | /* Thumb-compatibility pseudo ops. */ | |
16125 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
16126 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
16127 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
16128 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
16129 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 16130 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
16131 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
16132 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
16133 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
16134 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
16135 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
16136 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
16137 | ||
16a4cf17 PB |
16138 | /* These may simplify to neg. */ |
16139 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16140 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16141 | ||
c921be7d NC |
16142 | #undef THUMB_VARIANT |
16143 | #define THUMB_VARIANT & arm_ext_v6 | |
16144 | ||
2fc8bdac | 16145 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
16146 | |
16147 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
16148 | #undef THUMB_VARIANT |
16149 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16150 | ||
c19d1205 | 16151 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 16152 | TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16153 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
16154 | |
16155 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
3e94bf1a | 16156 | TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 16157 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), |
3e94bf1a | 16158 | TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 16159 | |
9c3c69f2 PB |
16160 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16161 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 16162 | |
9c3c69f2 PB |
16163 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16164 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
16165 | |
16166 | /* V1 instructions with no Thumb analogue at all. */ | |
16167 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
16168 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
16169 | ||
16170 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
16171 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
16172 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
16173 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
16174 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
16175 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
16176 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
16177 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
16178 | ||
c921be7d NC |
16179 | #undef ARM_VARIANT |
16180 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
16181 | #undef THUMB_VARIANT | |
16182 | #define THUMB_VARIANT & arm_ext_v4t | |
16183 | ||
c19d1205 ZW |
16184 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
16185 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
16186 | ||
c921be7d NC |
16187 | #undef THUMB_VARIANT |
16188 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16189 | ||
c19d1205 ZW |
16190 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
16191 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
16192 | ||
16193 | /* Generic coprocessor instructions. */ | |
16194 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
4962c51a MS |
16195 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
16196 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16197 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16198 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
16199 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), |
16200 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16201 | ||
c921be7d NC |
16202 | #undef ARM_VARIANT |
16203 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
16204 | ||
c19d1205 ZW |
16205 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
16206 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
16207 | ||
c921be7d NC |
16208 | #undef ARM_VARIANT |
16209 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
16210 | #undef THUMB_VARIANT | |
16211 | #define THUMB_VARIANT & arm_ext_msr | |
16212 | ||
037e8744 JB |
16213 | TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
16214 | TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), | |
c19d1205 | 16215 | |
c921be7d NC |
16216 | #undef ARM_VARIANT |
16217 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
16218 | #undef THUMB_VARIANT | |
16219 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16220 | ||
c19d1205 ZW |
16221 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
16222 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16223 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16224 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16225 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16226 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16227 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16228 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16229 | ||
c921be7d NC |
16230 | #undef ARM_VARIANT |
16231 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
16232 | #undef THUMB_VARIANT | |
16233 | #define THUMB_VARIANT & arm_ext_v4t | |
16234 | ||
4962c51a MS |
16235 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), |
16236 | tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16237 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16238 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16239 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16240 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 16241 | |
c921be7d NC |
16242 | #undef ARM_VARIANT |
16243 | #define ARM_VARIANT & arm_ext_v4t_5 | |
16244 | ||
c19d1205 ZW |
16245 | /* ARM Architecture 4T. */ |
16246 | /* Note: bx (and blx) are required on V5, even if the processor does | |
16247 | not support Thumb. */ | |
16248 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
16249 | ||
c921be7d NC |
16250 | #undef ARM_VARIANT |
16251 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
16252 | #undef THUMB_VARIANT | |
16253 | #define THUMB_VARIANT & arm_ext_v5t | |
16254 | ||
c19d1205 ZW |
16255 | /* Note: blx has 2 variants; the .value coded here is for |
16256 | BLX(2). Only this variant has conditional execution. */ | |
16257 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
16258 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
16259 | ||
c921be7d NC |
16260 | #undef THUMB_VARIANT |
16261 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16262 | ||
c19d1205 | 16263 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
4962c51a MS |
16264 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
16265 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16266 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16267 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
16268 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
16269 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16270 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16271 | ||
c921be7d NC |
16272 | #undef ARM_VARIANT |
16273 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ | |
16274 | ||
c19d1205 ZW |
16275 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16276 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16277 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16278 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16279 | ||
16280 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16281 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16282 | ||
16283 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16284 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16285 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16286 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16287 | ||
16288 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16289 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16290 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16291 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16292 | ||
16293 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16294 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16295 | ||
087b80de JM |
16296 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), |
16297 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16298 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16299 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
c19d1205 | 16300 | |
c921be7d NC |
16301 | #undef ARM_VARIANT |
16302 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ | |
16303 | ||
c19d1205 | 16304 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
79d49516 PB |
16305 | TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), |
16306 | TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 ZW |
16307 | |
16308 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16309 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16310 | ||
c921be7d NC |
16311 | #undef ARM_VARIANT |
16312 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
16313 | ||
c19d1205 ZW |
16314 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
16315 | ||
c921be7d NC |
16316 | #undef ARM_VARIANT |
16317 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
16318 | #undef THUMB_VARIANT | |
16319 | #define THUMB_VARIANT & arm_ext_v6 | |
16320 | ||
c19d1205 ZW |
16321 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
16322 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
16323 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16324 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16325 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16326 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16327 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16328 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16329 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16330 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
16331 | ||
c921be7d NC |
16332 | #undef THUMB_VARIANT |
16333 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16334 | ||
c19d1205 | 16335 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
91568d08 | 16336 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), |
c19d1205 ZW |
16337 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
16338 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 PB |
16339 | |
16340 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
16341 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
16342 | ||
16343 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
c921be7d NC |
16344 | #undef THUMB_VARIANT |
16345 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16346 | ||
dfa9f0d5 | 16347 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c19d1205 ZW |
16348 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
16349 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
16350 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16351 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16352 | TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16353 | /* Old name for QASX. */ | |
c19d1205 | 16354 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16355 | TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16356 | /* Old name for QSAX. */ | |
16357 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16358 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16359 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16360 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16361 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16362 | TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16363 | /* Old name for SASX. */ | |
c19d1205 ZW |
16364 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16365 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16366 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16367 | TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16368 | /* Old name for SHASX. */ | |
c19d1205 | 16369 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16370 | TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16371 | /* Old name for SHSAX. */ | |
16372 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16373 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16374 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16375 | TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16376 | /* Old name for SSAX. */ | |
16377 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16378 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16379 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16380 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16381 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16382 | TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16383 | /* Old name for UASX. */ | |
c19d1205 ZW |
16384 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16385 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16386 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16387 | TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16388 | /* Old name for UHASX. */ | |
c19d1205 | 16389 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16390 | TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16391 | /* Old name for UHSAX. */ | |
16392 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16393 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16394 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16395 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16396 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16397 | TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16398 | /* Old name for UQASX. */ | |
c19d1205 | 16399 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16400 | TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16401 | /* Old name for UQSAX. */ | |
16402 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16403 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16404 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 | 16405 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16406 | TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16407 | /* Old name for USAX. */ | |
c19d1205 | 16408 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 16409 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
16410 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), |
16411 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
16412 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
16413 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
16414 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
16415 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
16416 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
16417 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
16418 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16419 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16420 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16421 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16422 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16423 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16424 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16425 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 16426 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
16427 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
16428 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16429 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16430 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16431 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16432 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16433 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16434 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16435 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16436 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16437 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16438 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16439 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16440 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16441 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16442 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16443 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16444 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
b6702015 PB |
16445 | TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
16446 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), | |
16447 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), | |
16448 | TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs), | |
c19d1205 | 16449 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
c19d1205 ZW |
16450 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), |
16451 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16452 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
c19d1205 ZW |
16453 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), |
16454 | ||
c921be7d NC |
16455 | #undef ARM_VARIANT |
16456 | #define ARM_VARIANT & arm_ext_v6k | |
16457 | #undef THUMB_VARIANT | |
16458 | #define THUMB_VARIANT & arm_ext_v6k | |
16459 | ||
c19d1205 ZW |
16460 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
16461 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
16462 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
16463 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
16464 | ||
c921be7d NC |
16465 | #undef THUMB_VARIANT |
16466 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16467 | ||
ebdca51a PB |
16468 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), |
16469 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
16470 | ||
c921be7d NC |
16471 | #undef THUMB_VARIANT |
16472 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16473 | ||
c19d1205 ZW |
16474 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
16475 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
c19d1205 ZW |
16476 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), |
16477 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
c19d1205 ZW |
16478 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
16479 | ||
c921be7d NC |
16480 | #undef ARM_VARIANT |
16481 | #define ARM_VARIANT & arm_ext_v6z | |
16482 | ||
3eb17e6b | 16483 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 16484 | |
c921be7d NC |
16485 | #undef ARM_VARIANT |
16486 | #define ARM_VARIANT & arm_ext_v6t2 | |
16487 | ||
c19d1205 ZW |
16488 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
16489 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
16490 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16491 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16492 | ||
16493 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
b6895b4f PB |
16494 | TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), |
16495 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
401a54cf | 16496 | TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 ZW |
16497 | |
16498 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16499 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16500 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16501 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16502 | ||
25fe350b MS |
16503 | UT(cbnz, b900, 2, (RR, EXP), t_cbz), |
16504 | UT(cbz, b100, 2, (RR, EXP), t_cbz), | |
c921be7d NC |
16505 | |
16506 | /* ARM does not really have an IT instruction, so always allow it. | |
16507 | The opcode is copied from Thumb in order to allow warnings in | |
16508 | -mimplicit-it=[never | arm] modes. */ | |
16509 | #undef ARM_VARIANT | |
16510 | #define ARM_VARIANT & arm_ext_v1 | |
16511 | ||
e07e6e58 NC |
16512 | TUE(it, bf08, bf08, 1, (COND), it, t_it), |
16513 | TUE(itt, bf0c, bf0c, 1, (COND), it, t_it), | |
16514 | TUE(ite, bf04, bf04, 1, (COND), it, t_it), | |
16515 | TUE(ittt, bf0e, bf0e, 1, (COND), it, t_it), | |
16516 | TUE(itet, bf06, bf06, 1, (COND), it, t_it), | |
16517 | TUE(itte, bf0a, bf0a, 1, (COND), it, t_it), | |
16518 | TUE(itee, bf02, bf02, 1, (COND), it, t_it), | |
16519 | TUE(itttt, bf0f, bf0f, 1, (COND), it, t_it), | |
16520 | TUE(itett, bf07, bf07, 1, (COND), it, t_it), | |
16521 | TUE(ittet, bf0b, bf0b, 1, (COND), it, t_it), | |
16522 | TUE(iteet, bf03, bf03, 1, (COND), it, t_it), | |
16523 | TUE(ittte, bf0d, bf0d, 1, (COND), it, t_it), | |
16524 | TUE(itete, bf05, bf05, 1, (COND), it, t_it), | |
16525 | TUE(ittee, bf09, bf09, 1, (COND), it, t_it), | |
16526 | TUE(iteee, bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 JM |
16527 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
16528 | TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), | |
16529 | TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 16530 | |
92e90b6e | 16531 | /* Thumb2 only instructions. */ |
c921be7d NC |
16532 | #undef ARM_VARIANT |
16533 | #define ARM_VARIANT NULL | |
92e90b6e PB |
16534 | |
16535 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
16536 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
1c444d06 JM |
16537 | TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), |
16538 | TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
92e90b6e PB |
16539 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), |
16540 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
16541 | ||
62b3e311 | 16542 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
c921be7d NC |
16543 | #undef THUMB_VARIANT |
16544 | #define THUMB_VARIANT & arm_ext_div | |
16545 | ||
62b3e311 PB |
16546 | TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), |
16547 | TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
16548 | ||
7e806470 | 16549 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
16550 | #undef ARM_VARIANT |
16551 | #define ARM_VARIANT & arm_ext_barrier | |
16552 | #undef THUMB_VARIANT | |
16553 | #define THUMB_VARIANT & arm_ext_barrier | |
16554 | ||
7e806470 PB |
16555 | TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), |
16556 | TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
16557 | TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
16558 | ||
62b3e311 | 16559 | /* ARM V7 instructions. */ |
c921be7d NC |
16560 | #undef ARM_VARIANT |
16561 | #define ARM_VARIANT & arm_ext_v7 | |
16562 | #undef THUMB_VARIANT | |
16563 | #define THUMB_VARIANT & arm_ext_v7 | |
16564 | ||
62b3e311 PB |
16565 | TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld), |
16566 | TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 16567 | |
c921be7d NC |
16568 | #undef ARM_VARIANT |
16569 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
16570 | ||
8f06b2d8 PB |
16571 | cCE(wfs, e200110, 1, (RR), rd), |
16572 | cCE(rfs, e300110, 1, (RR), rd), | |
16573 | cCE(wfc, e400110, 1, (RR), rd), | |
16574 | cCE(rfc, e500110, 1, (RR), rd), | |
16575 | ||
4962c51a MS |
16576 | cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr), |
16577 | cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16578 | cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16579 | cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e | 16580 | |
4962c51a MS |
16581 | cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr), |
16582 | cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16583 | cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16584 | cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e PB |
16585 | |
16586 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
16587 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
16588 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
16589 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
16590 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
16591 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
16592 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
16593 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
16594 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
16595 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
16596 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
16597 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
16598 | ||
16599 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
16600 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
16601 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
16602 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
16603 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
16604 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
16605 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
16606 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
16607 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
16608 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
16609 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
16610 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
16611 | ||
16612 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
16613 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
16614 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
16615 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
16616 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
16617 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
16618 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
16619 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
16620 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
16621 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
16622 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
16623 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
16624 | ||
16625 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
16626 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
16627 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
16628 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
16629 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
16630 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
16631 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
16632 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
16633 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
16634 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
16635 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
16636 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
16637 | ||
16638 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
16639 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
16640 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
16641 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
16642 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
16643 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
16644 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
16645 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
16646 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
16647 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
16648 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
16649 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
16650 | ||
16651 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
16652 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
16653 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
16654 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
16655 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
16656 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
16657 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
16658 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
16659 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
16660 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
16661 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
16662 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
16663 | ||
16664 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
16665 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
16666 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
16667 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
16668 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
16669 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
16670 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
16671 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
16672 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
16673 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
16674 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
16675 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
16676 | ||
16677 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
16678 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
16679 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
16680 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
16681 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
16682 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
16683 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
16684 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
16685 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
16686 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
16687 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
16688 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
16689 | ||
16690 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
16691 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
16692 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
16693 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
16694 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
16695 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
16696 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
16697 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
16698 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
16699 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
16700 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
16701 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
16702 | ||
16703 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
16704 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
16705 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
16706 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
16707 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
16708 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
16709 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
16710 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
16711 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
16712 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
16713 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
16714 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
16715 | ||
16716 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
16717 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
16718 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
16719 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
16720 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
16721 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
16722 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
16723 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
16724 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
16725 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
16726 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
16727 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
16728 | ||
16729 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
16730 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
16731 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
16732 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
16733 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
16734 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
16735 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
16736 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
16737 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
16738 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
16739 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
16740 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
16741 | ||
16742 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
16743 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
16744 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
16745 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
16746 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
16747 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
16748 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
16749 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
16750 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
16751 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
16752 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
16753 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
16754 | ||
16755 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
16756 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
16757 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
16758 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
16759 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
16760 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
16761 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
16762 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
16763 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
16764 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
16765 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
16766 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
16767 | ||
16768 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
16769 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
16770 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
16771 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
16772 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
16773 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
16774 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
16775 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
16776 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
16777 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
16778 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
16779 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
16780 | ||
16781 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
16782 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
16783 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
16784 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
16785 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
16786 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
16787 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
16788 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
16789 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
16790 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
16791 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
16792 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
16793 | ||
16794 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16795 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16796 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16797 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16798 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16799 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16800 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16801 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16802 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16803 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16804 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16805 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16806 | ||
16807 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16808 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16809 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16810 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16811 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16812 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16813 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16814 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16815 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16816 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16817 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16818 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16819 | ||
16820 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16821 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16822 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16823 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16824 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16825 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16826 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16827 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16828 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16829 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16830 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16831 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16832 | ||
16833 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16834 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16835 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16836 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16837 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16838 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16839 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16840 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16841 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16842 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16843 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16844 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16845 | ||
16846 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16847 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16848 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16849 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16850 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16851 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16852 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16853 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16854 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16855 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16856 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16857 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16858 | ||
16859 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16860 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16861 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16862 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16863 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16864 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16865 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16866 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16867 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16868 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16869 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16870 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16871 | ||
16872 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16873 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16874 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16875 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16876 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16877 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16878 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16879 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16880 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16881 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16882 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16883 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16884 | ||
16885 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16886 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16887 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16888 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16889 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16890 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16891 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16892 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16893 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16894 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16895 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16896 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16897 | ||
16898 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16899 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16900 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16901 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16902 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16903 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16904 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16905 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16906 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16907 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16908 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16909 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16910 | ||
16911 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16912 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16913 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16914 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16915 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16916 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16917 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16918 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16919 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16920 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16921 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16922 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16923 | ||
16924 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16925 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16926 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16927 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16928 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16929 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16930 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16931 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16932 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16933 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16934 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16935 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16936 | ||
16937 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16938 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16939 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16940 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16941 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16942 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16943 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16944 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16945 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16946 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16947 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16948 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16949 | ||
16950 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16951 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16952 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16953 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16954 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16955 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16956 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16957 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16958 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16959 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16960 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16961 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
16962 | |
16963 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 16964 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 16965 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
16966 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
16967 | ||
e3cb604e PB |
16968 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
16969 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
16970 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
16971 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
16972 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
16973 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
16974 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
16975 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
16976 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
16977 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
16978 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
16979 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 16980 | |
c19d1205 ZW |
16981 | /* The implementation of the FIX instruction is broken on some |
16982 | assemblers, in that it accepts a precision specifier as well as a | |
16983 | rounding specifier, despite the fact that this is meaningless. | |
16984 | To be more compatible, we accept it as well, though of course it | |
16985 | does not set any bits. */ | |
8f06b2d8 | 16986 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
16987 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
16988 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
16989 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
16990 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
16991 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
16992 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
16993 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
16994 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
16995 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
16996 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
16997 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
16998 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 16999 | |
c19d1205 | 17000 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
17001 | #undef ARM_VARIANT |
17002 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
17003 | ||
8f06b2d8 | 17004 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
17005 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
17006 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 17007 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
17008 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
17009 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 17010 | |
c921be7d NC |
17011 | #undef ARM_VARIANT |
17012 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
17013 | ||
c19d1205 | 17014 | /* Moves and type conversions. */ |
8f06b2d8 PB |
17015 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
17016 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
17017 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
17018 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
17019 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17020 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17021 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17022 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17023 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17024 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17025 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
17026 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
17027 | |
17028 | /* Memory operations. */ | |
4962c51a MS |
17029 | cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
17030 | cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
8f06b2d8 PB |
17031 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), |
17032 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17033 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17034 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17035 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17036 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17037 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17038 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17039 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17040 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17041 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17042 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17043 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17044 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17045 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17046 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 17047 | |
c19d1205 | 17048 | /* Monadic operations. */ |
8f06b2d8 PB |
17049 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
17050 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17051 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
17052 | |
17053 | /* Dyadic operations. */ | |
8f06b2d8 PB |
17054 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
17055 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17056 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17057 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17058 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17059 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17060 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17061 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17062 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 17063 | |
c19d1205 | 17064 | /* Comparisons. */ |
8f06b2d8 PB |
17065 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
17066 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
17067 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17068 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 17069 | |
c921be7d NC |
17070 | #undef ARM_VARIANT |
17071 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
17072 | ||
c19d1205 | 17073 | /* Moves and type conversions. */ |
5287ad62 | 17074 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
8f06b2d8 PB |
17075 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
17076 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
5287ad62 JB |
17077 | cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd), |
17078 | cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17079 | cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17080 | cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
8f06b2d8 PB |
17081 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
17082 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17083 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17084 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17085 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17086 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
17087 | |
17088 | /* Memory operations. */ | |
4962c51a MS |
17089 | cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), |
17090 | cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
8f06b2d8 PB |
17091 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), |
17092 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17093 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17094 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17095 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17096 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17097 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17098 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 17099 | |
c19d1205 | 17100 | /* Monadic operations. */ |
5287ad62 JB |
17101 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
17102 | cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17103 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
17104 | |
17105 | /* Dyadic operations. */ | |
5287ad62 JB |
17106 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
17107 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17108 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17109 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17110 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17111 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17112 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17113 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17114 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 17115 | |
c19d1205 | 17116 | /* Comparisons. */ |
5287ad62 JB |
17117 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17118 | cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd), | |
17119 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17120 | cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 17121 | |
c921be7d NC |
17122 | #undef ARM_VARIANT |
17123 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
17124 | ||
8f06b2d8 PB |
17125 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
17126 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
5287ad62 JB |
17127 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), |
17128 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
17129 | ||
037e8744 JB |
17130 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
17131 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
17132 | #undef ARM_VARIANT |
17133 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
17134 | #undef THUMB_VARIANT | |
17135 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
17136 | ||
037e8744 JB |
17137 | /* These mnemonics are unique to VFP. */ |
17138 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
17139 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
17140 | nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17141 | nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17142 | nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17143 | nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17144 | nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17145 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), | |
17146 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
17147 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
17148 | ||
17149 | /* Mnemonics shared by Neon and VFP. */ | |
17150 | nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), | |
17151 | nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17152 | nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17153 | ||
17154 | nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
17155 | nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
17156 | ||
17157 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17158 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17159 | ||
17160 | NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17161 | NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17162 | NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17163 | NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17164 | NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17165 | NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
17166 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
17167 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 JB |
17168 | |
17169 | nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), | |
8e79c3df CM |
17170 | nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb), |
17171 | nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt), | |
f31fef98 | 17172 | |
037e8744 JB |
17173 | |
17174 | /* NOTE: All VMOV encoding is special-cased! */ | |
17175 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
17176 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
17177 | ||
c921be7d NC |
17178 | #undef THUMB_VARIANT |
17179 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
17180 | #undef ARM_VARIANT | |
17181 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
17182 | ||
5287ad62 JB |
17183 | /* Data processing with three registers of the same length. */ |
17184 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
17185 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
17186 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
17187 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17188 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17189 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17190 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17191 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17192 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17193 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17194 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17195 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
17196 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17197 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
17198 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
17199 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
17200 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
17201 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
17202 | /* If not immediate, fall back to neon_dyadic_i64_su. |
17203 | shl_imm should accept I8 I16 I32 I64, | |
17204 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17205 | nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), | |
17206 | nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
17207 | nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
17208 | nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
17209 | /* Logic ops, types optional & ignored. */ | |
17210 | nUF(vand, vand, 2, (RNDQ, NILO), neon_logic), | |
17211 | nUF(vandq, vand, 2, (RNQ, NILO), neon_logic), | |
17212 | nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic), | |
17213 | nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic), | |
17214 | nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic), | |
17215 | nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic), | |
17216 | nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic), | |
17217 | nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic), | |
17218 | nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
17219 | nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
17220 | /* Bitfield ops, untyped. */ | |
17221 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17222 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17223 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17224 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17225 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17226 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17227 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
17228 | nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17229 | nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17230 | nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17231 | nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17232 | nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17233 | nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17234 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall | |
17235 | back to neon_dyadic_if_su. */ | |
17236 | nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17237 | nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17238 | nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17239 | nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17240 | nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17241 | nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
17242 | nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17243 | nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 17244 | /* Comparison. Type I8 I16 I32 F32. */ |
5287ad62 JB |
17245 | nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
17246 | nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
17247 | /* As above, D registers only. */ | |
17248 | nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
17249 | nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
17250 | /* Int and float variants, signedness unimportant. */ | |
5287ad62 | 17251 | nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
5287ad62 JB |
17252 | nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
17253 | nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
17254 | /* Add/sub take types I8 I16 I32 I64 F32. */ | |
5287ad62 | 17255 | nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
5287ad62 JB |
17256 | nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
17257 | /* vtst takes sizes 8, 16, 32. */ | |
17258 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
17259 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
17260 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
037e8744 | 17261 | nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 JB |
17262 | /* VQD{R}MULH takes S16 S32. */ |
17263 | nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17264 | nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17265 | nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17266 | nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17267 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17268 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
17269 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17270 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
17271 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
17272 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
17273 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
17274 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
17275 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
17276 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17277 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
17278 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17279 | ||
17280 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 17281 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
17282 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
17283 | ||
17284 | /* Data processing with two registers and a shift amount. */ | |
17285 | /* Right shifts, and variants with rounding. | |
17286 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17287 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17288 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17289 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17290 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17291 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17292 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17293 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17294 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17295 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
17296 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
17297 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
17298 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
17299 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
17300 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17301 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
17302 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
17303 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
17304 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
17305 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17306 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17307 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
17308 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17309 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17310 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
17311 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17312 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17313 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
17314 | nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll), | |
17315 | /* CVT with optional immediate for fixed-point variant. */ | |
037e8744 | 17316 | nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 17317 | |
5287ad62 JB |
17318 | nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn), |
17319 | nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn), | |
17320 | ||
17321 | /* Data processing, three registers of different lengths. */ | |
17322 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
17323 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
17324 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17325 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17326 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17327 | /* If not scalar, fall back to neon_dyadic_long. | |
17328 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
17329 | nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
17330 | nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
17331 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ | |
17332 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17333 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17334 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
17335 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17336 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17337 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17338 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17339 | /* Saturating doubling multiplies. Types S16 S32. */ | |
17340 | nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17341 | nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17342 | nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17343 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types | |
17344 | S16 S32 U16 U32. */ | |
17345 | nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), | |
17346 | ||
17347 | /* Extract. Size 8. */ | |
3b8d421e PB |
17348 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
17349 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
17350 | |
17351 | /* Two registers, miscellaneous. */ | |
17352 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
17353 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
17354 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
17355 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
17356 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
17357 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
17358 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
17359 | /* Vector replicate. Sizes 8 16 32. */ | |
17360 | nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup), | |
17361 | nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
17362 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ | |
17363 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
17364 | /* VMOVN. Types I16 I32 I64. */ | |
17365 | nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn), | |
17366 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ | |
17367 | nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn), | |
17368 | /* VQMOVUN. Types S16 S32 S64. */ | |
17369 | nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun), | |
17370 | /* VZIP / VUZP. Sizes 8 16 32. */ | |
17371 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17372 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
17373 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17374 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
17375 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
17376 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17377 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17378 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17379 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17380 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
17381 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
17382 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
17383 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
17384 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
17385 | /* Reciprocal estimates. Types U32 F32. */ | |
17386 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
17387 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
17388 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
17389 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
17390 | /* VCLS. Types S8 S16 S32. */ | |
17391 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
17392 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
17393 | /* VCLZ. Types I8 I16 I32. */ | |
17394 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
17395 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
17396 | /* VCNT. Size 8. */ | |
17397 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
17398 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
17399 | /* Two address, untyped. */ | |
17400 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
17401 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
17402 | /* VTRN. Sizes 8 16 32. */ | |
17403 | nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn), | |
17404 | nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn), | |
17405 | ||
17406 | /* Table lookup. Size 8. */ | |
17407 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17408 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17409 | ||
c921be7d NC |
17410 | #undef THUMB_VARIANT |
17411 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
17412 | #undef ARM_VARIANT | |
17413 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
17414 | ||
5287ad62 JB |
17415 | /* Neon element/structure load/store. */ |
17416 | nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17417 | nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17418 | nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17419 | nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17420 | nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17421 | nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17422 | nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17423 | nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17424 | ||
c921be7d NC |
17425 | #undef THUMB_VARIANT |
17426 | #define THUMB_VARIANT & fpu_vfp_ext_v3 | |
17427 | #undef ARM_VARIANT | |
17428 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
17429 | ||
5287ad62 JB |
17430 | cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const), |
17431 | cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const), | |
17432 | cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17433 | cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17434 | cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17435 | cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17436 | cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17437 | cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17438 | cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17439 | cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17440 | cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17441 | cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17442 | cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17443 | cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17444 | cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17445 | cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17446 | cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17447 | cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
c19d1205 | 17448 | |
5287ad62 | 17449 | #undef THUMB_VARIANT |
c921be7d NC |
17450 | #undef ARM_VARIANT |
17451 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
17452 | ||
8f06b2d8 PB |
17453 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
17454 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17455 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17456 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17457 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17458 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17459 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
17460 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 17461 | |
c921be7d NC |
17462 | #undef ARM_VARIANT |
17463 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
17464 | ||
8f06b2d8 PB |
17465 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
17466 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
17467 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
17468 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
17469 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
17470 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
17471 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
17472 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
17473 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
17474 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17475 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17476 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17477 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17478 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17479 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17480 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17481 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17482 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
41adaa5c | 17483 | cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd), |
8f06b2d8 PB |
17484 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), |
17485 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17486 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17487 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17488 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17489 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17490 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17491 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
17492 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
17493 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
41adaa5c | 17494 | cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn), |
8f06b2d8 PB |
17495 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), |
17496 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
17497 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
17498 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
17499 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
17500 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
17501 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
17502 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17503 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17504 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17505 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17506 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17507 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17508 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17509 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17510 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17511 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
17512 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17513 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17514 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17515 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17516 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17517 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17518 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17519 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17520 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17521 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17522 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17523 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17524 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17525 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17526 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17527 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17528 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17529 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17530 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17531 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17532 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17533 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17534 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17535 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17536 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17537 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17538 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17539 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17540 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17541 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17542 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17543 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17544 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17545 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17546 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17547 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17548 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17549 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17550 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17551 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17552 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17553 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
17554 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17555 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17556 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17557 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17558 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17559 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17560 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17561 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17562 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17563 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17564 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 17565 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17566 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17567 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17568 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17569 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
17570 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
17571 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17572 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17573 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17574 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17575 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
2d447fca | 17576 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17577 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17578 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17579 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17580 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17581 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17582 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17583 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17584 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17585 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17586 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17587 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17588 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17589 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17590 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17591 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17592 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
17593 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
17594 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17595 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17596 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17597 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17598 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17599 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17600 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17601 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17602 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17603 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17604 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17605 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17606 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17607 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
17608 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
17609 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
17610 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
17611 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
17612 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
17613 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17614 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17615 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17616 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
17617 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
17618 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
17619 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
17620 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
17621 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
17622 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17623 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17624 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17625 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17626 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 17627 | |
c921be7d NC |
17628 | #undef ARM_VARIANT |
17629 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
17630 | ||
1103f72c NC |
17631 | cCE(torvscb, e12f190, 1, (RR), iwmmxt_tandorc), |
17632 | cCE(torvsch, e52f190, 1, (RR), iwmmxt_tandorc), | |
17633 | cCE(torvscw, e92f190, 1, (RR), iwmmxt_tandorc), | |
2d447fca JM |
17634 | cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn), |
17635 | cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn), | |
17636 | cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn), | |
17637 | cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17638 | cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17639 | cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17640 | cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17641 | cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17642 | cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17643 | cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17644 | cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17645 | cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17646 | cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17647 | cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17648 | cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17649 | cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17650 | cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17651 | cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
17652 | cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17653 | cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17654 | cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17655 | cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17656 | cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17657 | cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17658 | cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17659 | cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17660 | cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17661 | cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17662 | cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17663 | cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17664 | cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17665 | cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17666 | cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17667 | cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17668 | cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17669 | cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17670 | cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17671 | cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17672 | cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17673 | cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17674 | cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17675 | cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17676 | cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17677 | cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17678 | cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17679 | cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17680 | cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17681 | cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17682 | cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17683 | cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17684 | cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17685 | cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17686 | cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17687 | cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17688 | ||
c921be7d NC |
17689 | #undef ARM_VARIANT |
17690 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
17691 | ||
4962c51a MS |
17692 | cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
17693 | cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17694 | cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17695 | cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
17696 | cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
17697 | cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17698 | cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17699 | cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
8f06b2d8 PB |
17700 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), |
17701 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
17702 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
17703 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
17704 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
17705 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
17706 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
17707 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
17708 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
17709 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
17710 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
17711 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
17712 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
17713 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
17714 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
17715 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
17716 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
17717 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
17718 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
17719 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
17720 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
17721 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
17722 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
17723 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
17724 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
17725 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
17726 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
17727 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
17728 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
17729 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
17730 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
17731 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
17732 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
17733 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
17734 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
17735 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
17736 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
17737 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
17738 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
17739 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
17740 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
17741 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
17742 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
17743 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
17744 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
17745 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
17746 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17747 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17748 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17749 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17750 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17751 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17752 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
17753 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
17754 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
17755 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
17756 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17757 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17758 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17759 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17760 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17761 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17762 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17763 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17764 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17765 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17766 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
17767 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
17768 | }; |
17769 | #undef ARM_VARIANT | |
17770 | #undef THUMB_VARIANT | |
17771 | #undef TCE | |
17772 | #undef TCM | |
17773 | #undef TUE | |
17774 | #undef TUF | |
17775 | #undef TCC | |
8f06b2d8 | 17776 | #undef cCE |
e3cb604e PB |
17777 | #undef cCL |
17778 | #undef C3E | |
c19d1205 ZW |
17779 | #undef CE |
17780 | #undef CM | |
17781 | #undef UE | |
17782 | #undef UF | |
17783 | #undef UT | |
5287ad62 JB |
17784 | #undef NUF |
17785 | #undef nUF | |
17786 | #undef NCE | |
17787 | #undef nCE | |
c19d1205 ZW |
17788 | #undef OPS0 |
17789 | #undef OPS1 | |
17790 | #undef OPS2 | |
17791 | #undef OPS3 | |
17792 | #undef OPS4 | |
17793 | #undef OPS5 | |
17794 | #undef OPS6 | |
17795 | #undef do_0 | |
17796 | \f | |
17797 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 17798 | |
c19d1205 ZW |
17799 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
17800 | for use in the a.out file, and stores them in the array pointed to by buf. | |
17801 | This knows about the endian-ness of the target machine and does | |
17802 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
17803 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
17804 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 17805 | |
c19d1205 ZW |
17806 | void |
17807 | md_number_to_chars (char * buf, valueT val, int n) | |
17808 | { | |
17809 | if (target_big_endian) | |
17810 | number_to_chars_bigendian (buf, val, n); | |
17811 | else | |
17812 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
17813 | } |
17814 | ||
c19d1205 ZW |
17815 | static valueT |
17816 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 17817 | { |
c19d1205 ZW |
17818 | valueT result = 0; |
17819 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 17820 | |
c19d1205 | 17821 | if (target_big_endian) |
b99bd4ef | 17822 | { |
c19d1205 ZW |
17823 | while (n--) |
17824 | { | |
17825 | result <<= 8; | |
17826 | result |= (*where++ & 255); | |
17827 | } | |
b99bd4ef | 17828 | } |
c19d1205 | 17829 | else |
b99bd4ef | 17830 | { |
c19d1205 ZW |
17831 | while (n--) |
17832 | { | |
17833 | result <<= 8; | |
17834 | result |= (where[n] & 255); | |
17835 | } | |
bfae80f2 | 17836 | } |
b99bd4ef | 17837 | |
c19d1205 | 17838 | return result; |
bfae80f2 | 17839 | } |
b99bd4ef | 17840 | |
c19d1205 | 17841 | /* MD interface: Sections. */ |
b99bd4ef | 17842 | |
0110f2b8 PB |
17843 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
17844 | 2 bytes. */ | |
17845 | ||
c19d1205 | 17846 | int |
0110f2b8 | 17847 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
17848 | segT segtype ATTRIBUTE_UNUSED) |
17849 | { | |
0110f2b8 PB |
17850 | fragp->fr_var = 2; |
17851 | return 2; | |
17852 | } | |
17853 | ||
17854 | /* Convert a machine dependent frag. */ | |
17855 | ||
17856 | void | |
17857 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
17858 | { | |
17859 | unsigned long insn; | |
17860 | unsigned long old_op; | |
17861 | char *buf; | |
17862 | expressionS exp; | |
17863 | fixS *fixp; | |
17864 | int reloc_type; | |
17865 | int pc_rel; | |
17866 | int opcode; | |
17867 | ||
17868 | buf = fragp->fr_literal + fragp->fr_fix; | |
17869 | ||
17870 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
17871 | if (fragp->fr_symbol) |
17872 | { | |
0110f2b8 PB |
17873 | exp.X_op = O_symbol; |
17874 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
17875 | } |
17876 | else | |
17877 | { | |
0110f2b8 | 17878 | exp.X_op = O_constant; |
5f4273c7 | 17879 | } |
0110f2b8 PB |
17880 | exp.X_add_number = fragp->fr_offset; |
17881 | opcode = fragp->fr_subtype; | |
17882 | switch (opcode) | |
17883 | { | |
17884 | case T_MNEM_ldr_pc: | |
17885 | case T_MNEM_ldr_pc2: | |
17886 | case T_MNEM_ldr_sp: | |
17887 | case T_MNEM_str_sp: | |
17888 | case T_MNEM_ldr: | |
17889 | case T_MNEM_ldrb: | |
17890 | case T_MNEM_ldrh: | |
17891 | case T_MNEM_str: | |
17892 | case T_MNEM_strb: | |
17893 | case T_MNEM_strh: | |
17894 | if (fragp->fr_var == 4) | |
17895 | { | |
5f4273c7 | 17896 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
17897 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
17898 | { | |
17899 | insn |= (old_op & 0x700) << 4; | |
17900 | } | |
17901 | else | |
17902 | { | |
17903 | insn |= (old_op & 7) << 12; | |
17904 | insn |= (old_op & 0x38) << 13; | |
17905 | } | |
17906 | insn |= 0x00000c00; | |
17907 | put_thumb32_insn (buf, insn); | |
17908 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
17909 | } | |
17910 | else | |
17911 | { | |
17912 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
17913 | } | |
17914 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
17915 | break; | |
17916 | case T_MNEM_adr: | |
17917 | if (fragp->fr_var == 4) | |
17918 | { | |
17919 | insn = THUMB_OP32 (opcode); | |
17920 | insn |= (old_op & 0xf0) << 4; | |
17921 | put_thumb32_insn (buf, insn); | |
17922 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
17923 | } | |
17924 | else | |
17925 | { | |
17926 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
17927 | exp.X_add_number -= 4; | |
17928 | } | |
17929 | pc_rel = 1; | |
17930 | break; | |
17931 | case T_MNEM_mov: | |
17932 | case T_MNEM_movs: | |
17933 | case T_MNEM_cmp: | |
17934 | case T_MNEM_cmn: | |
17935 | if (fragp->fr_var == 4) | |
17936 | { | |
17937 | int r0off = (opcode == T_MNEM_mov | |
17938 | || opcode == T_MNEM_movs) ? 0 : 8; | |
17939 | insn = THUMB_OP32 (opcode); | |
17940 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
17941 | insn |= (old_op & 0x700) << r0off; | |
17942 | put_thumb32_insn (buf, insn); | |
17943 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
17944 | } | |
17945 | else | |
17946 | { | |
17947 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
17948 | } | |
17949 | pc_rel = 0; | |
17950 | break; | |
17951 | case T_MNEM_b: | |
17952 | if (fragp->fr_var == 4) | |
17953 | { | |
17954 | insn = THUMB_OP32(opcode); | |
17955 | put_thumb32_insn (buf, insn); | |
17956 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
17957 | } | |
17958 | else | |
17959 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
17960 | pc_rel = 1; | |
17961 | break; | |
17962 | case T_MNEM_bcond: | |
17963 | if (fragp->fr_var == 4) | |
17964 | { | |
17965 | insn = THUMB_OP32(opcode); | |
17966 | insn |= (old_op & 0xf00) << 14; | |
17967 | put_thumb32_insn (buf, insn); | |
17968 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
17969 | } | |
17970 | else | |
17971 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
17972 | pc_rel = 1; | |
17973 | break; | |
17974 | case T_MNEM_add_sp: | |
17975 | case T_MNEM_add_pc: | |
17976 | case T_MNEM_inc_sp: | |
17977 | case T_MNEM_dec_sp: | |
17978 | if (fragp->fr_var == 4) | |
17979 | { | |
17980 | /* ??? Choose between add and addw. */ | |
17981 | insn = THUMB_OP32 (opcode); | |
17982 | insn |= (old_op & 0xf0) << 4; | |
17983 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
17984 | if (opcode == T_MNEM_add_pc) |
17985 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
17986 | else | |
17987 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
17988 | } |
17989 | else | |
17990 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
17991 | pc_rel = 0; | |
17992 | break; | |
17993 | ||
17994 | case T_MNEM_addi: | |
17995 | case T_MNEM_addis: | |
17996 | case T_MNEM_subi: | |
17997 | case T_MNEM_subis: | |
17998 | if (fragp->fr_var == 4) | |
17999 | { | |
18000 | insn = THUMB_OP32 (opcode); | |
18001 | insn |= (old_op & 0xf0) << 4; | |
18002 | insn |= (old_op & 0xf) << 16; | |
18003 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
18004 | if (insn & (1 << 20)) |
18005 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
18006 | else | |
18007 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
18008 | } |
18009 | else | |
18010 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18011 | pc_rel = 0; | |
18012 | break; | |
18013 | default: | |
5f4273c7 | 18014 | abort (); |
0110f2b8 PB |
18015 | } |
18016 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
18017 | reloc_type); | |
18018 | fixp->fx_file = fragp->fr_file; | |
18019 | fixp->fx_line = fragp->fr_line; | |
18020 | fragp->fr_fix += fragp->fr_var; | |
18021 | } | |
18022 | ||
18023 | /* Return the size of a relaxable immediate operand instruction. | |
18024 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
18025 | static int | |
18026 | relax_immediate (fragS *fragp, int size, int shift) | |
18027 | { | |
18028 | offsetT offset; | |
18029 | offsetT mask; | |
18030 | offsetT low; | |
18031 | ||
18032 | /* ??? Should be able to do better than this. */ | |
18033 | if (fragp->fr_symbol) | |
18034 | return 4; | |
18035 | ||
18036 | low = (1 << shift) - 1; | |
18037 | mask = (1 << (shift + size)) - (1 << shift); | |
18038 | offset = fragp->fr_offset; | |
18039 | /* Force misaligned offsets to 32-bit variant. */ | |
18040 | if (offset & low) | |
5e77afaa | 18041 | return 4; |
0110f2b8 PB |
18042 | if (offset & ~mask) |
18043 | return 4; | |
18044 | return 2; | |
18045 | } | |
18046 | ||
5e77afaa PB |
18047 | /* Get the address of a symbol during relaxation. */ |
18048 | static addressT | |
5f4273c7 | 18049 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
18050 | { |
18051 | fragS *sym_frag; | |
18052 | addressT addr; | |
18053 | symbolS *sym; | |
18054 | ||
18055 | sym = fragp->fr_symbol; | |
18056 | sym_frag = symbol_get_frag (sym); | |
18057 | know (S_GET_SEGMENT (sym) != absolute_section | |
18058 | || sym_frag == &zero_address_frag); | |
18059 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
18060 | ||
18061 | /* If frag has yet to be reached on this pass, assume it will | |
18062 | move by STRETCH just as we did. If this is not so, it will | |
18063 | be because some frag between grows, and that will force | |
18064 | another pass. */ | |
18065 | ||
18066 | if (stretch != 0 | |
18067 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
18068 | { |
18069 | fragS *f; | |
18070 | ||
18071 | /* Adjust stretch for any alignment frag. Note that if have | |
18072 | been expanding the earlier code, the symbol may be | |
18073 | defined in what appears to be an earlier frag. FIXME: | |
18074 | This doesn't handle the fr_subtype field, which specifies | |
18075 | a maximum number of bytes to skip when doing an | |
18076 | alignment. */ | |
18077 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
18078 | { | |
18079 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
18080 | { | |
18081 | if (stretch < 0) | |
18082 | stretch = - ((- stretch) | |
18083 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
18084 | else | |
18085 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
18086 | if (stretch == 0) | |
18087 | break; | |
18088 | } | |
18089 | } | |
18090 | if (f != NULL) | |
18091 | addr += stretch; | |
18092 | } | |
5e77afaa PB |
18093 | |
18094 | return addr; | |
18095 | } | |
18096 | ||
0110f2b8 PB |
18097 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
18098 | load. */ | |
18099 | static int | |
5e77afaa | 18100 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
18101 | { |
18102 | addressT addr; | |
18103 | offsetT val; | |
18104 | ||
18105 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18106 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18107 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18108 | return 4; | |
18109 | ||
5f4273c7 | 18110 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18111 | addr = fragp->fr_address + fragp->fr_fix; |
18112 | addr = (addr + 4) & ~3; | |
5e77afaa | 18113 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 18114 | if (val & 3) |
5e77afaa | 18115 | return 4; |
0110f2b8 PB |
18116 | val -= addr; |
18117 | if (val < 0 || val > 1020) | |
18118 | return 4; | |
18119 | return 2; | |
18120 | } | |
18121 | ||
18122 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
18123 | static int | |
18124 | relax_addsub (fragS *fragp, asection *sec) | |
18125 | { | |
18126 | char *buf; | |
18127 | int op; | |
18128 | ||
18129 | buf = fragp->fr_literal + fragp->fr_fix; | |
18130 | op = bfd_get_16(sec->owner, buf); | |
18131 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
18132 | return relax_immediate (fragp, 8, 0); | |
18133 | else | |
18134 | return relax_immediate (fragp, 3, 0); | |
18135 | } | |
18136 | ||
18137 | ||
18138 | /* Return the size of a relaxable branch instruction. BITS is the | |
18139 | size of the offset field in the narrow instruction. */ | |
18140 | ||
18141 | static int | |
5e77afaa | 18142 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
18143 | { |
18144 | addressT addr; | |
18145 | offsetT val; | |
18146 | offsetT limit; | |
18147 | ||
18148 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18149 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18150 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18151 | return 4; | |
18152 | ||
267bf995 RR |
18153 | #ifdef OBJ_ELF |
18154 | if (S_IS_DEFINED (fragp->fr_symbol) | |
18155 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
18156 | return 4; | |
18157 | #endif | |
18158 | ||
5f4273c7 | 18159 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18160 | addr = fragp->fr_address + fragp->fr_fix + 4; |
18161 | val -= addr; | |
18162 | ||
18163 | /* Offset is a signed value *2 */ | |
18164 | limit = 1 << bits; | |
18165 | if (val >= limit || val < -limit) | |
18166 | return 4; | |
18167 | return 2; | |
18168 | } | |
18169 | ||
18170 | ||
18171 | /* Relax a machine dependent frag. This returns the amount by which | |
18172 | the current size of the frag should change. */ | |
18173 | ||
18174 | int | |
5e77afaa | 18175 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
18176 | { |
18177 | int oldsize; | |
18178 | int newsize; | |
18179 | ||
18180 | oldsize = fragp->fr_var; | |
18181 | switch (fragp->fr_subtype) | |
18182 | { | |
18183 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 18184 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18185 | break; |
18186 | case T_MNEM_ldr_pc: | |
18187 | case T_MNEM_ldr_sp: | |
18188 | case T_MNEM_str_sp: | |
5f4273c7 | 18189 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
18190 | break; |
18191 | case T_MNEM_ldr: | |
18192 | case T_MNEM_str: | |
5f4273c7 | 18193 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
18194 | break; |
18195 | case T_MNEM_ldrh: | |
18196 | case T_MNEM_strh: | |
5f4273c7 | 18197 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
18198 | break; |
18199 | case T_MNEM_ldrb: | |
18200 | case T_MNEM_strb: | |
5f4273c7 | 18201 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
18202 | break; |
18203 | case T_MNEM_adr: | |
5f4273c7 | 18204 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18205 | break; |
18206 | case T_MNEM_mov: | |
18207 | case T_MNEM_movs: | |
18208 | case T_MNEM_cmp: | |
18209 | case T_MNEM_cmn: | |
5f4273c7 | 18210 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
18211 | break; |
18212 | case T_MNEM_b: | |
5f4273c7 | 18213 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
18214 | break; |
18215 | case T_MNEM_bcond: | |
5f4273c7 | 18216 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
18217 | break; |
18218 | case T_MNEM_add_sp: | |
18219 | case T_MNEM_add_pc: | |
18220 | newsize = relax_immediate (fragp, 8, 2); | |
18221 | break; | |
18222 | case T_MNEM_inc_sp: | |
18223 | case T_MNEM_dec_sp: | |
18224 | newsize = relax_immediate (fragp, 7, 2); | |
18225 | break; | |
18226 | case T_MNEM_addi: | |
18227 | case T_MNEM_addis: | |
18228 | case T_MNEM_subi: | |
18229 | case T_MNEM_subis: | |
18230 | newsize = relax_addsub (fragp, sec); | |
18231 | break; | |
18232 | default: | |
5f4273c7 | 18233 | abort (); |
0110f2b8 | 18234 | } |
5e77afaa PB |
18235 | |
18236 | fragp->fr_var = newsize; | |
18237 | /* Freeze wide instructions that are at or before the same location as | |
18238 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
18239 | Don't freeze them unconditionally because targets may be artificially |
18240 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 18241 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 18242 | { |
0110f2b8 | 18243 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 18244 | frag_wane (fragp); |
0110f2b8 | 18245 | } |
5e77afaa | 18246 | |
0110f2b8 | 18247 | return newsize - oldsize; |
c19d1205 | 18248 | } |
b99bd4ef | 18249 | |
c19d1205 | 18250 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 18251 | |
c19d1205 ZW |
18252 | valueT |
18253 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
18254 | valueT size) | |
18255 | { | |
f0927246 NC |
18256 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
18257 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
18258 | { | |
18259 | /* For a.out, force the section size to be aligned. If we don't do | |
18260 | this, BFD will align it for us, but it will not write out the | |
18261 | final bytes of the section. This may be a bug in BFD, but it is | |
18262 | easier to fix it here since that is how the other a.out targets | |
18263 | work. */ | |
18264 | int align; | |
18265 | ||
18266 | align = bfd_get_section_alignment (stdoutput, segment); | |
18267 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
18268 | } | |
c19d1205 | 18269 | #endif |
f0927246 NC |
18270 | |
18271 | return size; | |
bfae80f2 | 18272 | } |
b99bd4ef | 18273 | |
c19d1205 ZW |
18274 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
18275 | of an rs_align_code fragment. */ | |
18276 | ||
18277 | void | |
18278 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 18279 | { |
e7495e45 NS |
18280 | static char const arm_noop[2][2][4] = |
18281 | { | |
18282 | { /* ARMv1 */ | |
18283 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
18284 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
18285 | }, | |
18286 | { /* ARMv6k */ | |
18287 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
18288 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
18289 | }, | |
18290 | }; | |
18291 | static char const thumb_noop[2][2][2] = | |
18292 | { | |
18293 | { /* Thumb-1 */ | |
18294 | {0xc0, 0x46}, /* LE */ | |
18295 | {0x46, 0xc0}, /* BE */ | |
18296 | }, | |
18297 | { /* Thumb-2 */ | |
18298 | {0x00, 0xbf}, /* LE */ | |
18299 | {0xbf, 0x00} /* BE */ | |
18300 | } | |
18301 | }; | |
18302 | static char const wide_thumb_noop[2][4] = | |
18303 | { /* Wide Thumb-2 */ | |
18304 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
18305 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
18306 | }; | |
c921be7d | 18307 | |
e7495e45 | 18308 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
18309 | char * p; |
18310 | const char * noop; | |
e7495e45 | 18311 | const char *narrow_noop = NULL; |
bfae80f2 | 18312 | |
c19d1205 | 18313 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
18314 | return; |
18315 | ||
c19d1205 ZW |
18316 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
18317 | p = fragP->fr_literal + fragP->fr_fix; | |
18318 | fix = 0; | |
bfae80f2 | 18319 | |
c19d1205 ZW |
18320 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
18321 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 18322 | |
9c2799c2 | 18323 | gas_assert ((fragP->tc_frag_data & MODE_RECORDED) != 0); |
8dc2430f NC |
18324 | |
18325 | if (fragP->tc_frag_data & (~ MODE_RECORDED)) | |
a737bd4d | 18326 | { |
e7495e45 NS |
18327 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
18328 | { | |
18329 | narrow_noop = thumb_noop[1][target_big_endian]; | |
18330 | noop = wide_thumb_noop[target_big_endian]; | |
18331 | } | |
c19d1205 | 18332 | else |
e7495e45 NS |
18333 | noop = thumb_noop[0][target_big_endian]; |
18334 | noop_size = 2; | |
7ed4c4c5 NC |
18335 | } |
18336 | else | |
18337 | { | |
e7495e45 NS |
18338 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0] |
18339 | [target_big_endian]; | |
18340 | noop_size = 4; | |
7ed4c4c5 | 18341 | } |
c921be7d | 18342 | |
e7495e45 | 18343 | fragP->fr_var = noop_size; |
c921be7d | 18344 | |
c19d1205 | 18345 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 18346 | { |
c19d1205 ZW |
18347 | fix = bytes & (noop_size - 1); |
18348 | memset (p, 0, fix); | |
18349 | p += fix; | |
18350 | bytes -= fix; | |
a737bd4d | 18351 | } |
a737bd4d | 18352 | |
e7495e45 NS |
18353 | if (narrow_noop) |
18354 | { | |
18355 | if (bytes & noop_size) | |
18356 | { | |
18357 | /* Insert a narrow noop. */ | |
18358 | memcpy (p, narrow_noop, noop_size); | |
18359 | p += noop_size; | |
18360 | bytes -= noop_size; | |
18361 | fix += noop_size; | |
18362 | } | |
18363 | ||
18364 | /* Use wide noops for the remainder */ | |
18365 | noop_size = 4; | |
18366 | } | |
18367 | ||
c19d1205 | 18368 | while (bytes >= noop_size) |
a737bd4d | 18369 | { |
c19d1205 ZW |
18370 | memcpy (p, noop, noop_size); |
18371 | p += noop_size; | |
18372 | bytes -= noop_size; | |
18373 | fix += noop_size; | |
a737bd4d NC |
18374 | } |
18375 | ||
c19d1205 | 18376 | fragP->fr_fix += fix; |
a737bd4d NC |
18377 | } |
18378 | ||
c19d1205 ZW |
18379 | /* Called from md_do_align. Used to create an alignment |
18380 | frag in a code section. */ | |
18381 | ||
18382 | void | |
18383 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 18384 | { |
c19d1205 | 18385 | char * p; |
7ed4c4c5 | 18386 | |
c19d1205 ZW |
18387 | /* We assume that there will never be a requirement |
18388 | to support alignments greater than 32 bytes. */ | |
18389 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) | |
18390 | as_fatal (_("alignments greater than 32 bytes not supported in .text sections.")); | |
bfae80f2 | 18391 | |
c19d1205 ZW |
18392 | p = frag_var (rs_align_code, |
18393 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
18394 | 1, | |
18395 | (relax_substateT) max, | |
18396 | (symbolS *) NULL, | |
18397 | (offsetT) n, | |
18398 | (char *) NULL); | |
18399 | *p = 0; | |
18400 | } | |
bfae80f2 | 18401 | |
8dc2430f NC |
18402 | /* Perform target specific initialisation of a frag. |
18403 | Note - despite the name this initialisation is not done when the frag | |
18404 | is created, but only when its type is assigned. A frag can be created | |
18405 | and used a long time before its type is set, so beware of assuming that | |
18406 | this initialisationis performed first. */ | |
bfae80f2 | 18407 | |
c19d1205 ZW |
18408 | void |
18409 | arm_init_frag (fragS * fragP) | |
18410 | { | |
8dc2430f NC |
18411 | /* If the current ARM vs THUMB mode has not already |
18412 | been recorded into this frag then do so now. */ | |
18413 | if ((fragP->tc_frag_data & MODE_RECORDED) == 0) | |
18414 | fragP->tc_frag_data = thumb_mode | MODE_RECORDED; | |
bfae80f2 RE |
18415 | } |
18416 | ||
c19d1205 ZW |
18417 | #ifdef OBJ_ELF |
18418 | /* When we change sections we need to issue a new mapping symbol. */ | |
18419 | ||
18420 | void | |
18421 | arm_elf_change_section (void) | |
bfae80f2 | 18422 | { |
c19d1205 ZW |
18423 | flagword flags; |
18424 | segment_info_type *seginfo; | |
bfae80f2 | 18425 | |
c19d1205 ZW |
18426 | /* Link an unlinked unwind index table section to the .text section. */ |
18427 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
18428 | && elf_linked_to_section (now_seg) == NULL) | |
18429 | elf_linked_to_section (now_seg) = text_section; | |
18430 | ||
18431 | if (!SEG_NORMAL (now_seg)) | |
bfae80f2 RE |
18432 | return; |
18433 | ||
c19d1205 ZW |
18434 | flags = bfd_get_section_flags (stdoutput, now_seg); |
18435 | ||
18436 | /* We can ignore sections that only contain debug info. */ | |
18437 | if ((flags & SEC_ALLOC) == 0) | |
18438 | return; | |
bfae80f2 | 18439 | |
c19d1205 ZW |
18440 | seginfo = seg_info (now_seg); |
18441 | mapstate = seginfo->tc_segment_info_data.mapstate; | |
18442 | marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency; | |
bfae80f2 RE |
18443 | } |
18444 | ||
c19d1205 ZW |
18445 | int |
18446 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 18447 | { |
c19d1205 ZW |
18448 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
18449 | return SHT_ARM_EXIDX; | |
e45d0630 | 18450 | |
c19d1205 ZW |
18451 | return -1; |
18452 | } | |
18453 | \f | |
18454 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 18455 | |
c19d1205 | 18456 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 18457 | |
5f4273c7 | 18458 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 18459 | |
bfae80f2 | 18460 | static void |
c19d1205 | 18461 | flush_pending_unwind (void) |
bfae80f2 | 18462 | { |
c19d1205 | 18463 | offsetT offset; |
bfae80f2 | 18464 | |
c19d1205 ZW |
18465 | offset = unwind.pending_offset; |
18466 | unwind.pending_offset = 0; | |
18467 | if (offset != 0) | |
18468 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
18469 | } |
18470 | ||
c19d1205 ZW |
18471 | /* Add an opcode to this list for this function. Two-byte opcodes should |
18472 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
18473 | order. */ | |
18474 | ||
bfae80f2 | 18475 | static void |
c19d1205 | 18476 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 18477 | { |
c19d1205 ZW |
18478 | /* Add any deferred stack adjustment. */ |
18479 | if (unwind.pending_offset) | |
18480 | flush_pending_unwind (); | |
bfae80f2 | 18481 | |
c19d1205 | 18482 | unwind.sp_restored = 0; |
bfae80f2 | 18483 | |
c19d1205 | 18484 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 18485 | { |
c19d1205 ZW |
18486 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
18487 | if (unwind.opcodes) | |
18488 | unwind.opcodes = xrealloc (unwind.opcodes, | |
18489 | unwind.opcode_alloc); | |
18490 | else | |
18491 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 18492 | } |
c19d1205 | 18493 | while (length > 0) |
bfae80f2 | 18494 | { |
c19d1205 ZW |
18495 | length--; |
18496 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
18497 | op >>= 8; | |
18498 | unwind.opcode_count++; | |
bfae80f2 | 18499 | } |
bfae80f2 RE |
18500 | } |
18501 | ||
c19d1205 ZW |
18502 | /* Add unwind opcodes to adjust the stack pointer. */ |
18503 | ||
bfae80f2 | 18504 | static void |
c19d1205 | 18505 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 18506 | { |
c19d1205 | 18507 | valueT op; |
bfae80f2 | 18508 | |
c19d1205 | 18509 | if (offset > 0x200) |
bfae80f2 | 18510 | { |
c19d1205 ZW |
18511 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
18512 | char bytes[5]; | |
18513 | int n; | |
18514 | valueT o; | |
bfae80f2 | 18515 | |
c19d1205 ZW |
18516 | /* Long form: 0xb2, uleb128. */ |
18517 | /* This might not fit in a word so add the individual bytes, | |
18518 | remembering the list is built in reverse order. */ | |
18519 | o = (valueT) ((offset - 0x204) >> 2); | |
18520 | if (o == 0) | |
18521 | add_unwind_opcode (0, 1); | |
bfae80f2 | 18522 | |
c19d1205 ZW |
18523 | /* Calculate the uleb128 encoding of the offset. */ |
18524 | n = 0; | |
18525 | while (o) | |
18526 | { | |
18527 | bytes[n] = o & 0x7f; | |
18528 | o >>= 7; | |
18529 | if (o) | |
18530 | bytes[n] |= 0x80; | |
18531 | n++; | |
18532 | } | |
18533 | /* Add the insn. */ | |
18534 | for (; n; n--) | |
18535 | add_unwind_opcode (bytes[n - 1], 1); | |
18536 | add_unwind_opcode (0xb2, 1); | |
18537 | } | |
18538 | else if (offset > 0x100) | |
bfae80f2 | 18539 | { |
c19d1205 ZW |
18540 | /* Two short opcodes. */ |
18541 | add_unwind_opcode (0x3f, 1); | |
18542 | op = (offset - 0x104) >> 2; | |
18543 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18544 | } |
c19d1205 ZW |
18545 | else if (offset > 0) |
18546 | { | |
18547 | /* Short opcode. */ | |
18548 | op = (offset - 4) >> 2; | |
18549 | add_unwind_opcode (op, 1); | |
18550 | } | |
18551 | else if (offset < 0) | |
bfae80f2 | 18552 | { |
c19d1205 ZW |
18553 | offset = -offset; |
18554 | while (offset > 0x100) | |
bfae80f2 | 18555 | { |
c19d1205 ZW |
18556 | add_unwind_opcode (0x7f, 1); |
18557 | offset -= 0x100; | |
bfae80f2 | 18558 | } |
c19d1205 ZW |
18559 | op = ((offset - 4) >> 2) | 0x40; |
18560 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18561 | } |
bfae80f2 RE |
18562 | } |
18563 | ||
c19d1205 ZW |
18564 | /* Finish the list of unwind opcodes for this function. */ |
18565 | static void | |
18566 | finish_unwind_opcodes (void) | |
bfae80f2 | 18567 | { |
c19d1205 | 18568 | valueT op; |
bfae80f2 | 18569 | |
c19d1205 | 18570 | if (unwind.fp_used) |
bfae80f2 | 18571 | { |
708587a4 | 18572 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
18573 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
18574 | flush_pending_unwind (); | |
bfae80f2 | 18575 | |
c19d1205 ZW |
18576 | /* After restoring sp from the frame pointer. */ |
18577 | op = 0x90 | unwind.fp_reg; | |
18578 | add_unwind_opcode (op, 1); | |
18579 | } | |
18580 | else | |
18581 | flush_pending_unwind (); | |
bfae80f2 RE |
18582 | } |
18583 | ||
bfae80f2 | 18584 | |
c19d1205 ZW |
18585 | /* Start an exception table entry. If idx is nonzero this is an index table |
18586 | entry. */ | |
bfae80f2 RE |
18587 | |
18588 | static void | |
c19d1205 | 18589 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 18590 | { |
c19d1205 ZW |
18591 | const char * text_name; |
18592 | const char * prefix; | |
18593 | const char * prefix_once; | |
18594 | const char * group_name; | |
18595 | size_t prefix_len; | |
18596 | size_t text_len; | |
18597 | char * sec_name; | |
18598 | size_t sec_name_len; | |
18599 | int type; | |
18600 | int flags; | |
18601 | int linkonce; | |
bfae80f2 | 18602 | |
c19d1205 | 18603 | if (idx) |
bfae80f2 | 18604 | { |
c19d1205 ZW |
18605 | prefix = ELF_STRING_ARM_unwind; |
18606 | prefix_once = ELF_STRING_ARM_unwind_once; | |
18607 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 18608 | } |
c19d1205 | 18609 | else |
bfae80f2 | 18610 | { |
c19d1205 ZW |
18611 | prefix = ELF_STRING_ARM_unwind_info; |
18612 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
18613 | type = SHT_PROGBITS; | |
bfae80f2 RE |
18614 | } |
18615 | ||
c19d1205 ZW |
18616 | text_name = segment_name (text_seg); |
18617 | if (streq (text_name, ".text")) | |
18618 | text_name = ""; | |
18619 | ||
18620 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
18621 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 18622 | { |
c19d1205 ZW |
18623 | prefix = prefix_once; |
18624 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
18625 | } |
18626 | ||
c19d1205 ZW |
18627 | prefix_len = strlen (prefix); |
18628 | text_len = strlen (text_name); | |
18629 | sec_name_len = prefix_len + text_len; | |
18630 | sec_name = xmalloc (sec_name_len + 1); | |
18631 | memcpy (sec_name, prefix, prefix_len); | |
18632 | memcpy (sec_name + prefix_len, text_name, text_len); | |
18633 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 18634 | |
c19d1205 ZW |
18635 | flags = SHF_ALLOC; |
18636 | linkonce = 0; | |
18637 | group_name = 0; | |
bfae80f2 | 18638 | |
c19d1205 ZW |
18639 | /* Handle COMDAT group. */ |
18640 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 18641 | { |
c19d1205 ZW |
18642 | group_name = elf_group_name (text_seg); |
18643 | if (group_name == NULL) | |
18644 | { | |
bd3ba5d1 | 18645 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
18646 | segment_name (text_seg)); |
18647 | ignore_rest_of_line (); | |
18648 | return; | |
18649 | } | |
18650 | flags |= SHF_GROUP; | |
18651 | linkonce = 1; | |
bfae80f2 RE |
18652 | } |
18653 | ||
c19d1205 | 18654 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 18655 | |
5f4273c7 | 18656 | /* Set the section link for index tables. */ |
c19d1205 ZW |
18657 | if (idx) |
18658 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
18659 | } |
18660 | ||
bfae80f2 | 18661 | |
c19d1205 ZW |
18662 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
18663 | personality routine data. Returns zero, or the index table value for | |
18664 | and inline entry. */ | |
18665 | ||
18666 | static valueT | |
18667 | create_unwind_entry (int have_data) | |
bfae80f2 | 18668 | { |
c19d1205 ZW |
18669 | int size; |
18670 | addressT where; | |
18671 | char *ptr; | |
18672 | /* The current word of data. */ | |
18673 | valueT data; | |
18674 | /* The number of bytes left in this word. */ | |
18675 | int n; | |
bfae80f2 | 18676 | |
c19d1205 | 18677 | finish_unwind_opcodes (); |
bfae80f2 | 18678 | |
c19d1205 ZW |
18679 | /* Remember the current text section. */ |
18680 | unwind.saved_seg = now_seg; | |
18681 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 18682 | |
c19d1205 | 18683 | start_unwind_section (now_seg, 0); |
bfae80f2 | 18684 | |
c19d1205 | 18685 | if (unwind.personality_routine == NULL) |
bfae80f2 | 18686 | { |
c19d1205 ZW |
18687 | if (unwind.personality_index == -2) |
18688 | { | |
18689 | if (have_data) | |
5f4273c7 | 18690 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
18691 | return 1; /* EXIDX_CANTUNWIND. */ |
18692 | } | |
bfae80f2 | 18693 | |
c19d1205 ZW |
18694 | /* Use a default personality routine if none is specified. */ |
18695 | if (unwind.personality_index == -1) | |
18696 | { | |
18697 | if (unwind.opcode_count > 3) | |
18698 | unwind.personality_index = 1; | |
18699 | else | |
18700 | unwind.personality_index = 0; | |
18701 | } | |
bfae80f2 | 18702 | |
c19d1205 ZW |
18703 | /* Space for the personality routine entry. */ |
18704 | if (unwind.personality_index == 0) | |
18705 | { | |
18706 | if (unwind.opcode_count > 3) | |
18707 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 18708 | |
c19d1205 ZW |
18709 | if (!have_data) |
18710 | { | |
18711 | /* All the data is inline in the index table. */ | |
18712 | data = 0x80; | |
18713 | n = 3; | |
18714 | while (unwind.opcode_count > 0) | |
18715 | { | |
18716 | unwind.opcode_count--; | |
18717 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18718 | n--; | |
18719 | } | |
bfae80f2 | 18720 | |
c19d1205 ZW |
18721 | /* Pad with "finish" opcodes. */ |
18722 | while (n--) | |
18723 | data = (data << 8) | 0xb0; | |
bfae80f2 | 18724 | |
c19d1205 ZW |
18725 | return data; |
18726 | } | |
18727 | size = 0; | |
18728 | } | |
18729 | else | |
18730 | /* We get two opcodes "free" in the first word. */ | |
18731 | size = unwind.opcode_count - 2; | |
18732 | } | |
18733 | else | |
18734 | /* An extra byte is required for the opcode count. */ | |
18735 | size = unwind.opcode_count + 1; | |
bfae80f2 | 18736 | |
c19d1205 ZW |
18737 | size = (size + 3) >> 2; |
18738 | if (size > 0xff) | |
18739 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 18740 | |
c19d1205 ZW |
18741 | frag_align (2, 0, 0); |
18742 | record_alignment (now_seg, 2); | |
18743 | unwind.table_entry = expr_build_dot (); | |
18744 | ||
18745 | /* Allocate the table entry. */ | |
18746 | ptr = frag_more ((size << 2) + 4); | |
18747 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 18748 | |
c19d1205 | 18749 | switch (unwind.personality_index) |
bfae80f2 | 18750 | { |
c19d1205 ZW |
18751 | case -1: |
18752 | /* ??? Should this be a PLT generating relocation? */ | |
18753 | /* Custom personality routine. */ | |
18754 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
18755 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 18756 | |
c19d1205 ZW |
18757 | where += 4; |
18758 | ptr += 4; | |
bfae80f2 | 18759 | |
c19d1205 ZW |
18760 | /* Set the first byte to the number of additional words. */ |
18761 | data = size - 1; | |
18762 | n = 3; | |
18763 | break; | |
bfae80f2 | 18764 | |
c19d1205 ZW |
18765 | /* ABI defined personality routines. */ |
18766 | case 0: | |
18767 | /* Three opcodes bytes are packed into the first word. */ | |
18768 | data = 0x80; | |
18769 | n = 3; | |
18770 | break; | |
bfae80f2 | 18771 | |
c19d1205 ZW |
18772 | case 1: |
18773 | case 2: | |
18774 | /* The size and first two opcode bytes go in the first word. */ | |
18775 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
18776 | n = 2; | |
18777 | break; | |
bfae80f2 | 18778 | |
c19d1205 ZW |
18779 | default: |
18780 | /* Should never happen. */ | |
18781 | abort (); | |
18782 | } | |
bfae80f2 | 18783 | |
c19d1205 ZW |
18784 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
18785 | time. */ | |
18786 | while (unwind.opcode_count > 0) | |
18787 | { | |
18788 | if (n == 0) | |
18789 | { | |
18790 | md_number_to_chars (ptr, data, 4); | |
18791 | ptr += 4; | |
18792 | n = 4; | |
18793 | data = 0; | |
18794 | } | |
18795 | unwind.opcode_count--; | |
18796 | n--; | |
18797 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18798 | } | |
18799 | ||
18800 | /* Finish off the last word. */ | |
18801 | if (n < 4) | |
18802 | { | |
18803 | /* Pad with "finish" opcodes. */ | |
18804 | while (n--) | |
18805 | data = (data << 8) | 0xb0; | |
18806 | ||
18807 | md_number_to_chars (ptr, data, 4); | |
18808 | } | |
18809 | ||
18810 | if (!have_data) | |
18811 | { | |
18812 | /* Add an empty descriptor if there is no user-specified data. */ | |
18813 | ptr = frag_more (4); | |
18814 | md_number_to_chars (ptr, 0, 4); | |
18815 | } | |
18816 | ||
18817 | return 0; | |
bfae80f2 RE |
18818 | } |
18819 | ||
f0927246 NC |
18820 | |
18821 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
18822 | ||
18823 | void | |
18824 | tc_arm_frame_initial_instructions (void) | |
18825 | { | |
18826 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
18827 | } | |
18828 | #endif /* OBJ_ELF */ | |
18829 | ||
c19d1205 ZW |
18830 | /* Convert REGNAME to a DWARF-2 register number. */ |
18831 | ||
18832 | int | |
1df69f4f | 18833 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 18834 | { |
1df69f4f | 18835 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
18836 | |
18837 | if (reg == FAIL) | |
18838 | return -1; | |
18839 | ||
18840 | return reg; | |
bfae80f2 RE |
18841 | } |
18842 | ||
f0927246 | 18843 | #ifdef TE_PE |
c19d1205 | 18844 | void |
f0927246 | 18845 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 18846 | { |
f0927246 | 18847 | expressionS expr; |
bfae80f2 | 18848 | |
f0927246 NC |
18849 | expr.X_op = O_secrel; |
18850 | expr.X_add_symbol = symbol; | |
18851 | expr.X_add_number = 0; | |
18852 | emit_expr (&expr, size); | |
18853 | } | |
18854 | #endif | |
bfae80f2 | 18855 | |
c19d1205 | 18856 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 18857 | |
2fc8bdac ZW |
18858 | /* Return the address within the segment that a PC-relative fixup is |
18859 | relative to. For ARM, PC-relative fixups applied to instructions | |
18860 | are generally relative to the location of the fixup plus 8 bytes. | |
18861 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
18862 | require special handling. */ | |
bfae80f2 | 18863 | |
c19d1205 | 18864 | long |
2fc8bdac | 18865 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 18866 | { |
2fc8bdac ZW |
18867 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
18868 | ||
18869 | /* If this is pc-relative and we are going to emit a relocation | |
18870 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
18871 | will need. Otherwise we want to use the calculated base. |
18872 | For WinCE we skip the bias for externals as well, since this | |
18873 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 18874 | if (fixP->fx_pcrel |
2fc8bdac | 18875 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
18876 | || (arm_force_relocation (fixP) |
18877 | #ifdef TE_WINCE | |
18878 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
18879 | #endif | |
18880 | ))) | |
2fc8bdac | 18881 | base = 0; |
bfae80f2 | 18882 | |
267bf995 | 18883 | |
c19d1205 | 18884 | switch (fixP->fx_r_type) |
bfae80f2 | 18885 | { |
2fc8bdac ZW |
18886 | /* PC relative addressing on the Thumb is slightly odd as the |
18887 | bottom two bits of the PC are forced to zero for the | |
18888 | calculation. This happens *after* application of the | |
18889 | pipeline offset. However, Thumb adrl already adjusts for | |
18890 | this, so we need not do it again. */ | |
c19d1205 | 18891 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 18892 | return base & ~3; |
c19d1205 ZW |
18893 | |
18894 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
18895 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 18896 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 18897 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 18898 | return (base + 4) & ~3; |
c19d1205 | 18899 | |
2fc8bdac ZW |
18900 | /* Thumb branches are simply offset by +4. */ |
18901 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
18902 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
18903 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
18904 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 18905 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 18906 | return base + 4; |
bfae80f2 | 18907 | |
267bf995 RR |
18908 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
18909 | if (fixP->fx_addsy | |
18910 | && ARM_IS_FUNC (fixP->fx_addsy) | |
18911 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18912 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
18913 | return base + 4; | |
18914 | ||
00adf2d4 JB |
18915 | /* BLX is like branches above, but forces the low two bits of PC to |
18916 | zero. */ | |
267bf995 RR |
18917 | case BFD_RELOC_THUMB_PCREL_BLX: |
18918 | if (fixP->fx_addsy | |
18919 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
18920 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18921 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
18922 | return (base + 4) & ~3; |
18923 | ||
2fc8bdac ZW |
18924 | /* ARM mode branches are offset by +8. However, the Windows CE |
18925 | loader expects the relocation not to take this into account. */ | |
267bf995 RR |
18926 | case BFD_RELOC_ARM_PCREL_BLX: |
18927 | if (fixP->fx_addsy | |
18928 | && ARM_IS_FUNC (fixP->fx_addsy) | |
18929 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18930 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
18931 | return base + 8; | |
18932 | ||
18933 | case BFD_RELOC_ARM_PCREL_CALL: | |
18934 | if (fixP->fx_addsy | |
18935 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
18936 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18937 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
18938 | return base + 8; | |
18939 | ||
2fc8bdac | 18940 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 18941 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 18942 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 18943 | #ifdef TE_WINCE |
5f4273c7 | 18944 | /* When handling fixups immediately, because we have already |
53baae48 NC |
18945 | discovered the value of a symbol, or the address of the frag involved |
18946 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
18947 | see fixup_segment() in write.c | |
18948 | The S_IS_EXTERNAL test handles the case of global symbols. | |
18949 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
18950 | if (fixP->fx_pcrel | |
18951 | && fixP->fx_addsy != NULL | |
18952 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
18953 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
18954 | return base + 8; | |
2fc8bdac | 18955 | return base; |
c19d1205 | 18956 | #else |
2fc8bdac | 18957 | return base + 8; |
c19d1205 | 18958 | #endif |
2fc8bdac | 18959 | |
267bf995 | 18960 | |
2fc8bdac ZW |
18961 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
18962 | branches, the Windows CE loader *does* expect the relocation | |
18963 | to take this into account. */ | |
18964 | case BFD_RELOC_ARM_OFFSET_IMM: | |
18965 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
18966 | case BFD_RELOC_ARM_HWLITERAL: | |
18967 | case BFD_RELOC_ARM_LITERAL: | |
18968 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
18969 | return base + 8; | |
18970 | ||
18971 | ||
18972 | /* Other PC-relative relocations are un-offset. */ | |
18973 | default: | |
18974 | return base; | |
18975 | } | |
bfae80f2 RE |
18976 | } |
18977 | ||
c19d1205 ZW |
18978 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
18979 | Otherwise we have no need to default values of symbols. */ | |
18980 | ||
18981 | symbolS * | |
18982 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 18983 | { |
c19d1205 ZW |
18984 | #ifdef OBJ_ELF |
18985 | if (name[0] == '_' && name[1] == 'G' | |
18986 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
18987 | { | |
18988 | if (!GOT_symbol) | |
18989 | { | |
18990 | if (symbol_find (name)) | |
bd3ba5d1 | 18991 | as_bad (_("GOT already in the symbol table")); |
bfae80f2 | 18992 | |
c19d1205 ZW |
18993 | GOT_symbol = symbol_new (name, undefined_section, |
18994 | (valueT) 0, & zero_address_frag); | |
18995 | } | |
bfae80f2 | 18996 | |
c19d1205 | 18997 | return GOT_symbol; |
bfae80f2 | 18998 | } |
c19d1205 | 18999 | #endif |
bfae80f2 | 19000 | |
c921be7d | 19001 | return NULL; |
bfae80f2 RE |
19002 | } |
19003 | ||
55cf6793 | 19004 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
19005 | computed as two separate immediate values, added together. We |
19006 | already know that this value cannot be computed by just one ARM | |
19007 | instruction. */ | |
19008 | ||
19009 | static unsigned int | |
19010 | validate_immediate_twopart (unsigned int val, | |
19011 | unsigned int * highpart) | |
bfae80f2 | 19012 | { |
c19d1205 ZW |
19013 | unsigned int a; |
19014 | unsigned int i; | |
bfae80f2 | 19015 | |
c19d1205 ZW |
19016 | for (i = 0; i < 32; i += 2) |
19017 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
19018 | { | |
19019 | if (a & 0xff00) | |
19020 | { | |
19021 | if (a & ~ 0xffff) | |
19022 | continue; | |
19023 | * highpart = (a >> 8) | ((i + 24) << 7); | |
19024 | } | |
19025 | else if (a & 0xff0000) | |
19026 | { | |
19027 | if (a & 0xff000000) | |
19028 | continue; | |
19029 | * highpart = (a >> 16) | ((i + 16) << 7); | |
19030 | } | |
19031 | else | |
19032 | { | |
9c2799c2 | 19033 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
19034 | * highpart = (a >> 24) | ((i + 8) << 7); |
19035 | } | |
bfae80f2 | 19036 | |
c19d1205 ZW |
19037 | return (a & 0xff) | (i << 7); |
19038 | } | |
bfae80f2 | 19039 | |
c19d1205 | 19040 | return FAIL; |
bfae80f2 RE |
19041 | } |
19042 | ||
c19d1205 ZW |
19043 | static int |
19044 | validate_offset_imm (unsigned int val, int hwse) | |
19045 | { | |
19046 | if ((hwse && val > 255) || val > 4095) | |
19047 | return FAIL; | |
19048 | return val; | |
19049 | } | |
bfae80f2 | 19050 | |
55cf6793 | 19051 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
19052 | negative immediate constant by altering the instruction. A bit of |
19053 | a hack really. | |
19054 | MOV <-> MVN | |
19055 | AND <-> BIC | |
19056 | ADC <-> SBC | |
19057 | by inverting the second operand, and | |
19058 | ADD <-> SUB | |
19059 | CMP <-> CMN | |
19060 | by negating the second operand. */ | |
bfae80f2 | 19061 | |
c19d1205 ZW |
19062 | static int |
19063 | negate_data_op (unsigned long * instruction, | |
19064 | unsigned long value) | |
bfae80f2 | 19065 | { |
c19d1205 ZW |
19066 | int op, new_inst; |
19067 | unsigned long negated, inverted; | |
bfae80f2 | 19068 | |
c19d1205 ZW |
19069 | negated = encode_arm_immediate (-value); |
19070 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 19071 | |
c19d1205 ZW |
19072 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
19073 | switch (op) | |
bfae80f2 | 19074 | { |
c19d1205 ZW |
19075 | /* First negates. */ |
19076 | case OPCODE_SUB: /* ADD <-> SUB */ | |
19077 | new_inst = OPCODE_ADD; | |
19078 | value = negated; | |
19079 | break; | |
bfae80f2 | 19080 | |
c19d1205 ZW |
19081 | case OPCODE_ADD: |
19082 | new_inst = OPCODE_SUB; | |
19083 | value = negated; | |
19084 | break; | |
bfae80f2 | 19085 | |
c19d1205 ZW |
19086 | case OPCODE_CMP: /* CMP <-> CMN */ |
19087 | new_inst = OPCODE_CMN; | |
19088 | value = negated; | |
19089 | break; | |
bfae80f2 | 19090 | |
c19d1205 ZW |
19091 | case OPCODE_CMN: |
19092 | new_inst = OPCODE_CMP; | |
19093 | value = negated; | |
19094 | break; | |
bfae80f2 | 19095 | |
c19d1205 ZW |
19096 | /* Now Inverted ops. */ |
19097 | case OPCODE_MOV: /* MOV <-> MVN */ | |
19098 | new_inst = OPCODE_MVN; | |
19099 | value = inverted; | |
19100 | break; | |
bfae80f2 | 19101 | |
c19d1205 ZW |
19102 | case OPCODE_MVN: |
19103 | new_inst = OPCODE_MOV; | |
19104 | value = inverted; | |
19105 | break; | |
bfae80f2 | 19106 | |
c19d1205 ZW |
19107 | case OPCODE_AND: /* AND <-> BIC */ |
19108 | new_inst = OPCODE_BIC; | |
19109 | value = inverted; | |
19110 | break; | |
bfae80f2 | 19111 | |
c19d1205 ZW |
19112 | case OPCODE_BIC: |
19113 | new_inst = OPCODE_AND; | |
19114 | value = inverted; | |
19115 | break; | |
bfae80f2 | 19116 | |
c19d1205 ZW |
19117 | case OPCODE_ADC: /* ADC <-> SBC */ |
19118 | new_inst = OPCODE_SBC; | |
19119 | value = inverted; | |
19120 | break; | |
bfae80f2 | 19121 | |
c19d1205 ZW |
19122 | case OPCODE_SBC: |
19123 | new_inst = OPCODE_ADC; | |
19124 | value = inverted; | |
19125 | break; | |
bfae80f2 | 19126 | |
c19d1205 ZW |
19127 | /* We cannot do anything. */ |
19128 | default: | |
19129 | return FAIL; | |
b99bd4ef NC |
19130 | } |
19131 | ||
c19d1205 ZW |
19132 | if (value == (unsigned) FAIL) |
19133 | return FAIL; | |
19134 | ||
19135 | *instruction &= OPCODE_MASK; | |
19136 | *instruction |= new_inst << DATA_OP_SHIFT; | |
19137 | return value; | |
b99bd4ef NC |
19138 | } |
19139 | ||
ef8d22e6 PB |
19140 | /* Like negate_data_op, but for Thumb-2. */ |
19141 | ||
19142 | static unsigned int | |
16dd5e42 | 19143 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
19144 | { |
19145 | int op, new_inst; | |
19146 | int rd; | |
16dd5e42 | 19147 | unsigned int negated, inverted; |
ef8d22e6 PB |
19148 | |
19149 | negated = encode_thumb32_immediate (-value); | |
19150 | inverted = encode_thumb32_immediate (~value); | |
19151 | ||
19152 | rd = (*instruction >> 8) & 0xf; | |
19153 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
19154 | switch (op) | |
19155 | { | |
19156 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
19157 | case T2_OPCODE_SUB: | |
19158 | new_inst = T2_OPCODE_ADD; | |
19159 | value = negated; | |
19160 | break; | |
19161 | ||
19162 | case T2_OPCODE_ADD: | |
19163 | new_inst = T2_OPCODE_SUB; | |
19164 | value = negated; | |
19165 | break; | |
19166 | ||
19167 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
19168 | case T2_OPCODE_ORR: | |
19169 | new_inst = T2_OPCODE_ORN; | |
19170 | value = inverted; | |
19171 | break; | |
19172 | ||
19173 | case T2_OPCODE_ORN: | |
19174 | new_inst = T2_OPCODE_ORR; | |
19175 | value = inverted; | |
19176 | break; | |
19177 | ||
19178 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
19179 | case T2_OPCODE_AND: | |
19180 | new_inst = T2_OPCODE_BIC; | |
19181 | if (rd == 15) | |
19182 | value = FAIL; | |
19183 | else | |
19184 | value = inverted; | |
19185 | break; | |
19186 | ||
19187 | case T2_OPCODE_BIC: | |
19188 | new_inst = T2_OPCODE_AND; | |
19189 | value = inverted; | |
19190 | break; | |
19191 | ||
19192 | /* ADC <-> SBC */ | |
19193 | case T2_OPCODE_ADC: | |
19194 | new_inst = T2_OPCODE_SBC; | |
19195 | value = inverted; | |
19196 | break; | |
19197 | ||
19198 | case T2_OPCODE_SBC: | |
19199 | new_inst = T2_OPCODE_ADC; | |
19200 | value = inverted; | |
19201 | break; | |
19202 | ||
19203 | /* We cannot do anything. */ | |
19204 | default: | |
19205 | return FAIL; | |
19206 | } | |
19207 | ||
16dd5e42 | 19208 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
19209 | return FAIL; |
19210 | ||
19211 | *instruction &= T2_OPCODE_MASK; | |
19212 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
19213 | return value; | |
19214 | } | |
19215 | ||
8f06b2d8 PB |
19216 | /* Read a 32-bit thumb instruction from buf. */ |
19217 | static unsigned long | |
19218 | get_thumb32_insn (char * buf) | |
19219 | { | |
19220 | unsigned long insn; | |
19221 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
19222 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19223 | ||
19224 | return insn; | |
19225 | } | |
19226 | ||
a8bc6c78 PB |
19227 | |
19228 | /* We usually want to set the low bit on the address of thumb function | |
19229 | symbols. In particular .word foo - . should have the low bit set. | |
19230 | Generic code tries to fold the difference of two symbols to | |
19231 | a constant. Prevent this and force a relocation when the first symbols | |
19232 | is a thumb function. */ | |
c921be7d NC |
19233 | |
19234 | bfd_boolean | |
a8bc6c78 PB |
19235 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
19236 | { | |
19237 | if (op == O_subtract | |
19238 | && l->X_op == O_symbol | |
19239 | && r->X_op == O_symbol | |
19240 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
19241 | { | |
19242 | l->X_op = O_subtract; | |
19243 | l->X_op_symbol = r->X_add_symbol; | |
19244 | l->X_add_number -= r->X_add_number; | |
c921be7d | 19245 | return TRUE; |
a8bc6c78 | 19246 | } |
c921be7d | 19247 | |
a8bc6c78 | 19248 | /* Process as normal. */ |
c921be7d | 19249 | return FALSE; |
a8bc6c78 PB |
19250 | } |
19251 | ||
c19d1205 | 19252 | void |
55cf6793 | 19253 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
19254 | valueT * valP, |
19255 | segT seg) | |
19256 | { | |
19257 | offsetT value = * valP; | |
19258 | offsetT newval; | |
19259 | unsigned int newimm; | |
19260 | unsigned long temp; | |
19261 | int sign; | |
19262 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 19263 | |
9c2799c2 | 19264 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 19265 | |
c19d1205 | 19266 | /* Note whether this will delete the relocation. */ |
4962c51a | 19267 | |
c19d1205 ZW |
19268 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
19269 | fixP->fx_done = 1; | |
b99bd4ef | 19270 | |
adbaf948 | 19271 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 19272 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
19273 | for emit_reloc. */ |
19274 | value &= 0xffffffff; | |
19275 | value ^= 0x80000000; | |
5f4273c7 | 19276 | value -= 0x80000000; |
adbaf948 ZW |
19277 | |
19278 | *valP = value; | |
c19d1205 | 19279 | fixP->fx_addnumber = value; |
b99bd4ef | 19280 | |
adbaf948 ZW |
19281 | /* Same treatment for fixP->fx_offset. */ |
19282 | fixP->fx_offset &= 0xffffffff; | |
19283 | fixP->fx_offset ^= 0x80000000; | |
19284 | fixP->fx_offset -= 0x80000000; | |
19285 | ||
c19d1205 | 19286 | switch (fixP->fx_r_type) |
b99bd4ef | 19287 | { |
c19d1205 ZW |
19288 | case BFD_RELOC_NONE: |
19289 | /* This will need to go in the object file. */ | |
19290 | fixP->fx_done = 0; | |
19291 | break; | |
b99bd4ef | 19292 | |
c19d1205 ZW |
19293 | case BFD_RELOC_ARM_IMMEDIATE: |
19294 | /* We claim that this fixup has been processed here, | |
19295 | even if in fact we generate an error because we do | |
19296 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19297 | fixP->fx_done = 1; | |
b99bd4ef | 19298 | |
c19d1205 ZW |
19299 | if (fixP->fx_addsy |
19300 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 19301 | { |
c19d1205 ZW |
19302 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19303 | _("undefined symbol %s used as an immediate value"), | |
19304 | S_GET_NAME (fixP->fx_addsy)); | |
19305 | break; | |
b99bd4ef NC |
19306 | } |
19307 | ||
42e5fcbf AS |
19308 | if (fixP->fx_addsy |
19309 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19310 | { | |
19311 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19312 | _("symbol %s is in a different section"), | |
19313 | S_GET_NAME (fixP->fx_addsy)); | |
19314 | break; | |
19315 | } | |
19316 | ||
c19d1205 ZW |
19317 | newimm = encode_arm_immediate (value); |
19318 | temp = md_chars_to_number (buf, INSN_SIZE); | |
19319 | ||
19320 | /* If the instruction will fail, see if we can fix things up by | |
19321 | changing the opcode. */ | |
19322 | if (newimm == (unsigned int) FAIL | |
19323 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 19324 | { |
c19d1205 ZW |
19325 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19326 | _("invalid constant (%lx) after fixup"), | |
19327 | (unsigned long) value); | |
19328 | break; | |
b99bd4ef | 19329 | } |
b99bd4ef | 19330 | |
c19d1205 ZW |
19331 | newimm |= (temp & 0xfffff000); |
19332 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
19333 | break; | |
b99bd4ef | 19334 | |
c19d1205 ZW |
19335 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
19336 | { | |
19337 | unsigned int highpart = 0; | |
19338 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 19339 | |
42e5fcbf AS |
19340 | if (fixP->fx_addsy |
19341 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19342 | { | |
19343 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19344 | _("undefined symbol %s used as an immediate value"), | |
19345 | S_GET_NAME (fixP->fx_addsy)); | |
19346 | break; | |
19347 | } | |
19348 | ||
19349 | if (fixP->fx_addsy | |
19350 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19351 | { | |
19352 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19353 | _("symbol %s is in a different section"), | |
19354 | S_GET_NAME (fixP->fx_addsy)); | |
19355 | break; | |
19356 | } | |
19357 | ||
c19d1205 ZW |
19358 | newimm = encode_arm_immediate (value); |
19359 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 19360 | |
c19d1205 ZW |
19361 | /* If the instruction will fail, see if we can fix things up by |
19362 | changing the opcode. */ | |
19363 | if (newimm == (unsigned int) FAIL | |
19364 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
19365 | { | |
19366 | /* No ? OK - try using two ADD instructions to generate | |
19367 | the value. */ | |
19368 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 19369 | |
c19d1205 ZW |
19370 | /* Yes - then make sure that the second instruction is |
19371 | also an add. */ | |
19372 | if (newimm != (unsigned int) FAIL) | |
19373 | newinsn = temp; | |
19374 | /* Still No ? Try using a negated value. */ | |
19375 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
19376 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
19377 | /* Otherwise - give up. */ | |
19378 | else | |
19379 | { | |
19380 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19381 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
19382 | (long) value); | |
19383 | break; | |
19384 | } | |
b99bd4ef | 19385 | |
c19d1205 ZW |
19386 | /* Replace the first operand in the 2nd instruction (which |
19387 | is the PC) with the destination register. We have | |
19388 | already added in the PC in the first instruction and we | |
19389 | do not want to do it again. */ | |
19390 | newinsn &= ~ 0xf0000; | |
19391 | newinsn |= ((newinsn & 0x0f000) << 4); | |
19392 | } | |
b99bd4ef | 19393 | |
c19d1205 ZW |
19394 | newimm |= (temp & 0xfffff000); |
19395 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 19396 | |
c19d1205 ZW |
19397 | highpart |= (newinsn & 0xfffff000); |
19398 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
19399 | } | |
19400 | break; | |
b99bd4ef | 19401 | |
c19d1205 | 19402 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
19403 | if (!fixP->fx_done && seg->use_rela_p) |
19404 | value = 0; | |
19405 | ||
c19d1205 ZW |
19406 | case BFD_RELOC_ARM_LITERAL: |
19407 | sign = value >= 0; | |
b99bd4ef | 19408 | |
c19d1205 ZW |
19409 | if (value < 0) |
19410 | value = - value; | |
b99bd4ef | 19411 | |
c19d1205 | 19412 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 19413 | { |
c19d1205 ZW |
19414 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
19415 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19416 | _("invalid literal constant: pool needs to be closer")); | |
19417 | else | |
19418 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19419 | _("bad immediate value for offset (%ld)"), | |
19420 | (long) value); | |
19421 | break; | |
f03698e6 RE |
19422 | } |
19423 | ||
c19d1205 ZW |
19424 | newval = md_chars_to_number (buf, INSN_SIZE); |
19425 | newval &= 0xff7ff000; | |
19426 | newval |= value | (sign ? INDEX_UP : 0); | |
19427 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19428 | break; | |
b99bd4ef | 19429 | |
c19d1205 ZW |
19430 | case BFD_RELOC_ARM_OFFSET_IMM8: |
19431 | case BFD_RELOC_ARM_HWLITERAL: | |
19432 | sign = value >= 0; | |
b99bd4ef | 19433 | |
c19d1205 ZW |
19434 | if (value < 0) |
19435 | value = - value; | |
b99bd4ef | 19436 | |
c19d1205 | 19437 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 19438 | { |
c19d1205 ZW |
19439 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
19440 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19441 | _("invalid literal constant: pool needs to be closer")); | |
19442 | else | |
f9d4405b | 19443 | as_bad (_("bad immediate value for 8-bit offset (%ld)"), |
c19d1205 ZW |
19444 | (long) value); |
19445 | break; | |
b99bd4ef NC |
19446 | } |
19447 | ||
c19d1205 ZW |
19448 | newval = md_chars_to_number (buf, INSN_SIZE); |
19449 | newval &= 0xff7ff0f0; | |
19450 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
19451 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19452 | break; | |
b99bd4ef | 19453 | |
c19d1205 ZW |
19454 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
19455 | if (value < 0 || value > 1020 || value % 4 != 0) | |
19456 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19457 | _("bad immediate value for offset (%ld)"), (long) value); | |
19458 | value /= 4; | |
b99bd4ef | 19459 | |
c19d1205 | 19460 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
19461 | newval |= value; |
19462 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
19463 | break; | |
b99bd4ef | 19464 | |
c19d1205 ZW |
19465 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
19466 | /* This is a complicated relocation used for all varieties of Thumb32 | |
19467 | load/store instruction with immediate offset: | |
19468 | ||
19469 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
19470 | *4, optional writeback(W) | |
19471 | (doubleword load/store) | |
19472 | ||
19473 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
19474 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
19475 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
19476 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
19477 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
19478 | ||
19479 | Uppercase letters indicate bits that are already encoded at | |
19480 | this point. Lowercase letters are our problem. For the | |
19481 | second block of instructions, the secondary opcode nybble | |
19482 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
19483 | a PC-relative operation. */ | |
19484 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19485 | newval <<= 16; | |
19486 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 19487 | |
c19d1205 | 19488 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 19489 | { |
c19d1205 ZW |
19490 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
19491 | if (value >= 0) | |
19492 | newval |= (1 << 23); | |
19493 | else | |
19494 | value = -value; | |
19495 | if (value % 4 != 0) | |
19496 | { | |
19497 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19498 | _("offset not a multiple of 4")); | |
19499 | break; | |
19500 | } | |
19501 | value /= 4; | |
216d22bc | 19502 | if (value > 0xff) |
c19d1205 ZW |
19503 | { |
19504 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19505 | _("offset out of range")); | |
19506 | break; | |
19507 | } | |
19508 | newval &= ~0xff; | |
b99bd4ef | 19509 | } |
c19d1205 | 19510 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 19511 | { |
c19d1205 ZW |
19512 | /* PC-relative, 12-bit offset. */ |
19513 | if (value >= 0) | |
19514 | newval |= (1 << 23); | |
19515 | else | |
19516 | value = -value; | |
216d22bc | 19517 | if (value > 0xfff) |
c19d1205 ZW |
19518 | { |
19519 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19520 | _("offset out of range")); | |
19521 | break; | |
19522 | } | |
19523 | newval &= ~0xfff; | |
b99bd4ef | 19524 | } |
c19d1205 | 19525 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 19526 | { |
c19d1205 ZW |
19527 | /* Writeback: 8-bit, +/- offset. */ |
19528 | if (value >= 0) | |
19529 | newval |= (1 << 9); | |
19530 | else | |
19531 | value = -value; | |
216d22bc | 19532 | if (value > 0xff) |
c19d1205 ZW |
19533 | { |
19534 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19535 | _("offset out of range")); | |
19536 | break; | |
19537 | } | |
19538 | newval &= ~0xff; | |
b99bd4ef | 19539 | } |
c19d1205 | 19540 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 19541 | { |
c19d1205 | 19542 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 19543 | if (value < 0 || value > 0xff) |
b99bd4ef | 19544 | { |
c19d1205 ZW |
19545 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19546 | _("offset out of range")); | |
19547 | break; | |
b99bd4ef | 19548 | } |
c19d1205 ZW |
19549 | newval &= ~0xff; |
19550 | newval |= value; | |
b99bd4ef NC |
19551 | } |
19552 | else | |
b99bd4ef | 19553 | { |
c19d1205 ZW |
19554 | /* Positive 12-bit or negative 8-bit offset. */ |
19555 | int limit; | |
19556 | if (value >= 0) | |
b99bd4ef | 19557 | { |
c19d1205 ZW |
19558 | newval |= (1 << 23); |
19559 | limit = 0xfff; | |
19560 | } | |
19561 | else | |
19562 | { | |
19563 | value = -value; | |
19564 | limit = 0xff; | |
19565 | } | |
19566 | if (value > limit) | |
19567 | { | |
19568 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19569 | _("offset out of range")); | |
19570 | break; | |
b99bd4ef | 19571 | } |
c19d1205 | 19572 | newval &= ~limit; |
b99bd4ef | 19573 | } |
b99bd4ef | 19574 | |
c19d1205 ZW |
19575 | newval |= value; |
19576 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
19577 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
19578 | break; | |
404ff6b5 | 19579 | |
c19d1205 ZW |
19580 | case BFD_RELOC_ARM_SHIFT_IMM: |
19581 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19582 | if (((unsigned long) value) > 32 | |
19583 | || (value == 32 | |
19584 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
19585 | { | |
19586 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19587 | _("shift expression is too large")); | |
19588 | break; | |
19589 | } | |
404ff6b5 | 19590 | |
c19d1205 ZW |
19591 | if (value == 0) |
19592 | /* Shifts of zero must be done as lsl. */ | |
19593 | newval &= ~0x60; | |
19594 | else if (value == 32) | |
19595 | value = 0; | |
19596 | newval &= 0xfffff07f; | |
19597 | newval |= (value & 0x1f) << 7; | |
19598 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19599 | break; | |
404ff6b5 | 19600 | |
c19d1205 | 19601 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 19602 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 19603 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 19604 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
19605 | /* We claim that this fixup has been processed here, |
19606 | even if in fact we generate an error because we do | |
19607 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19608 | fixP->fx_done = 1; | |
404ff6b5 | 19609 | |
c19d1205 ZW |
19610 | if (fixP->fx_addsy |
19611 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19612 | { | |
19613 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19614 | _("undefined symbol %s used as an immediate value"), | |
19615 | S_GET_NAME (fixP->fx_addsy)); | |
19616 | break; | |
19617 | } | |
404ff6b5 | 19618 | |
c19d1205 ZW |
19619 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19620 | newval <<= 16; | |
19621 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 19622 | |
16805f35 PB |
19623 | newimm = FAIL; |
19624 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
19625 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
19626 | { |
19627 | newimm = encode_thumb32_immediate (value); | |
19628 | if (newimm == (unsigned int) FAIL) | |
19629 | newimm = thumb32_negate_data_op (&newval, value); | |
19630 | } | |
16805f35 PB |
19631 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
19632 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 19633 | { |
16805f35 PB |
19634 | /* Turn add/sum into addw/subw. */ |
19635 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
19636 | newval = (newval & 0xfeffffff) | 0x02000000; | |
19637 | ||
e9f89963 PB |
19638 | /* 12 bit immediate for addw/subw. */ |
19639 | if (value < 0) | |
19640 | { | |
19641 | value = -value; | |
19642 | newval ^= 0x00a00000; | |
19643 | } | |
92e90b6e PB |
19644 | if (value > 0xfff) |
19645 | newimm = (unsigned int) FAIL; | |
19646 | else | |
19647 | newimm = value; | |
19648 | } | |
cc8a6dd0 | 19649 | |
c19d1205 | 19650 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 19651 | { |
c19d1205 ZW |
19652 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19653 | _("invalid constant (%lx) after fixup"), | |
19654 | (unsigned long) value); | |
19655 | break; | |
3631a3c8 NC |
19656 | } |
19657 | ||
c19d1205 ZW |
19658 | newval |= (newimm & 0x800) << 15; |
19659 | newval |= (newimm & 0x700) << 4; | |
19660 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 19661 | |
c19d1205 ZW |
19662 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
19663 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
19664 | break; | |
a737bd4d | 19665 | |
3eb17e6b | 19666 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
19667 | if (((unsigned long) value) > 0xffff) |
19668 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 19669 | _("invalid smc expression")); |
2fc8bdac | 19670 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19671 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
19672 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19673 | break; | |
a737bd4d | 19674 | |
c19d1205 | 19675 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 19676 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
19677 | { |
19678 | if (((unsigned long) value) > 0xff) | |
19679 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19680 | _("invalid swi expression")); | |
2fc8bdac | 19681 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
19682 | newval |= value; |
19683 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19684 | } | |
19685 | else | |
19686 | { | |
19687 | if (((unsigned long) value) > 0x00ffffff) | |
19688 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19689 | _("invalid swi expression")); | |
2fc8bdac | 19690 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19691 | newval |= value; |
19692 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19693 | } | |
19694 | break; | |
a737bd4d | 19695 | |
c19d1205 ZW |
19696 | case BFD_RELOC_ARM_MULTI: |
19697 | if (((unsigned long) value) > 0xffff) | |
19698 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19699 | _("invalid expression in load/store multiple")); | |
19700 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
19701 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19702 | break; | |
a737bd4d | 19703 | |
c19d1205 | 19704 | #ifdef OBJ_ELF |
39b41c9c | 19705 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
19706 | |
19707 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
19708 | && fixP->fx_addsy | |
19709 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19710 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19711 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19712 | /* Flip the bl to blx. This is a simple flip | |
19713 | bit here because we generate PCREL_CALL for | |
19714 | unconditional bls. */ | |
19715 | { | |
19716 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19717 | newval = newval | 0x10000000; | |
19718 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19719 | temp = 1; | |
19720 | fixP->fx_done = 1; | |
19721 | } | |
39b41c9c PB |
19722 | else |
19723 | temp = 3; | |
19724 | goto arm_branch_common; | |
19725 | ||
19726 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
19727 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19728 | && fixP->fx_addsy | |
19729 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19730 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19731 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19732 | { | |
19733 | /* This would map to a bl<cond>, b<cond>, | |
19734 | b<always> to a Thumb function. We | |
19735 | need to force a relocation for this particular | |
19736 | case. */ | |
19737 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19738 | fixP->fx_done = 0; | |
19739 | } | |
19740 | ||
2fc8bdac | 19741 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19742 | #endif |
39b41c9c PB |
19743 | case BFD_RELOC_ARM_PCREL_BRANCH: |
19744 | temp = 3; | |
19745 | goto arm_branch_common; | |
a737bd4d | 19746 | |
39b41c9c | 19747 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 19748 | |
39b41c9c | 19749 | temp = 1; |
267bf995 RR |
19750 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19751 | && fixP->fx_addsy | |
19752 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19753 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19754 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
19755 | { | |
19756 | /* Flip the blx to a bl and warn. */ | |
19757 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
19758 | newval = 0xeb000000; | |
19759 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
19760 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
19761 | name); | |
19762 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19763 | temp = 3; | |
19764 | fixP->fx_done = 1; | |
19765 | } | |
19766 | ||
19767 | #ifdef OBJ_ELF | |
19768 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
19769 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; | |
19770 | #endif | |
19771 | ||
39b41c9c | 19772 | arm_branch_common: |
c19d1205 | 19773 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
19774 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
19775 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
19776 | also be be clear. */ | |
19777 | if (value & temp) | |
c19d1205 | 19778 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
19779 | _("misaligned branch destination")); |
19780 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
19781 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
19782 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19783 | _("branch out of range")); | |
a737bd4d | 19784 | |
2fc8bdac | 19785 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19786 | { |
2fc8bdac ZW |
19787 | newval = md_chars_to_number (buf, INSN_SIZE); |
19788 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
19789 | /* Set the H bit on BLX instructions. */ |
19790 | if (temp == 1) | |
19791 | { | |
19792 | if (value & 2) | |
19793 | newval |= 0x01000000; | |
19794 | else | |
19795 | newval &= ~0x01000000; | |
19796 | } | |
2fc8bdac | 19797 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 19798 | } |
c19d1205 | 19799 | break; |
a737bd4d | 19800 | |
25fe350b MS |
19801 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
19802 | /* CBZ can only branch forward. */ | |
a737bd4d | 19803 | |
738755b0 MS |
19804 | /* Attempts to use CBZ to branch to the next instruction |
19805 | (which, strictly speaking, are prohibited) will be turned into | |
19806 | no-ops. | |
19807 | ||
19808 | FIXME: It may be better to remove the instruction completely and | |
19809 | perform relaxation. */ | |
19810 | if (value == -2) | |
2fc8bdac ZW |
19811 | { |
19812 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 19813 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
19814 | md_number_to_chars (buf, newval, THUMB_SIZE); |
19815 | } | |
738755b0 MS |
19816 | else |
19817 | { | |
19818 | if (value & ~0x7e) | |
19819 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19820 | _("branch out of range")); | |
19821 | ||
19822 | if (fixP->fx_done || !seg->use_rela_p) | |
19823 | { | |
19824 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19825 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
19826 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19827 | } | |
19828 | } | |
c19d1205 | 19829 | break; |
a737bd4d | 19830 | |
c19d1205 | 19831 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
19832 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
19833 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19834 | _("branch out of range")); | |
a737bd4d | 19835 | |
2fc8bdac ZW |
19836 | if (fixP->fx_done || !seg->use_rela_p) |
19837 | { | |
19838 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19839 | newval |= (value & 0x1ff) >> 1; | |
19840 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19841 | } | |
c19d1205 | 19842 | break; |
a737bd4d | 19843 | |
c19d1205 | 19844 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
19845 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
19846 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19847 | _("branch out of range")); | |
a737bd4d | 19848 | |
2fc8bdac ZW |
19849 | if (fixP->fx_done || !seg->use_rela_p) |
19850 | { | |
19851 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19852 | newval |= (value & 0xfff) >> 1; | |
19853 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19854 | } | |
c19d1205 | 19855 | break; |
a737bd4d | 19856 | |
c19d1205 | 19857 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
19858 | if (fixP->fx_addsy |
19859 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19860 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19861 | && S_IS_DEFINED (fixP->fx_addsy) | |
19862 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19863 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19864 | { | |
19865 | /* Force a relocation for a branch 20 bits wide. */ | |
19866 | fixP->fx_done = 0; | |
19867 | } | |
2fc8bdac ZW |
19868 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
19869 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19870 | _("conditional branch out of range")); | |
404ff6b5 | 19871 | |
2fc8bdac ZW |
19872 | if (fixP->fx_done || !seg->use_rela_p) |
19873 | { | |
19874 | offsetT newval2; | |
19875 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 19876 | |
2fc8bdac ZW |
19877 | S = (value & 0x00100000) >> 20; |
19878 | J2 = (value & 0x00080000) >> 19; | |
19879 | J1 = (value & 0x00040000) >> 18; | |
19880 | hi = (value & 0x0003f000) >> 12; | |
19881 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 19882 | |
2fc8bdac ZW |
19883 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19884 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19885 | newval |= (S << 10) | hi; | |
19886 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
19887 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19888 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
19889 | } | |
c19d1205 | 19890 | break; |
6c43fab6 | 19891 | |
c19d1205 | 19892 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
19893 | |
19894 | /* If there is a blx from a thumb state function to | |
19895 | another thumb function flip this to a bl and warn | |
19896 | about it. */ | |
19897 | ||
19898 | if (fixP->fx_addsy | |
19899 | && S_IS_DEFINED (fixP->fx_addsy) | |
19900 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19901 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19902 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19903 | { | |
19904 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
19905 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
19906 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
19907 | name); | |
19908 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19909 | newval = newval | 0x1000; | |
19910 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
19911 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
19912 | fixP->fx_done = 1; | |
19913 | } | |
19914 | ||
19915 | ||
19916 | goto thumb_bl_common; | |
19917 | ||
c19d1205 | 19918 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
19919 | |
19920 | /* A bl from Thumb state ISA to an internal ARM state function | |
19921 | is converted to a blx. */ | |
19922 | if (fixP->fx_addsy | |
19923 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19924 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19925 | && S_IS_DEFINED (fixP->fx_addsy) | |
19926 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19927 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19928 | { | |
19929 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19930 | newval = newval & ~0x1000; | |
19931 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
19932 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
19933 | fixP->fx_done = 1; | |
19934 | } | |
19935 | ||
19936 | thumb_bl_common: | |
19937 | ||
19938 | #ifdef OBJ_ELF | |
19939 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 && | |
19940 | fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
19941 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
19942 | #endif | |
19943 | ||
2fc8bdac ZW |
19944 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
19945 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19946 | _("branch out of range")); | |
404ff6b5 | 19947 | |
2fc8bdac ZW |
19948 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
19949 | /* For a BLX instruction, make sure that the relocation is rounded up | |
19950 | to a word boundary. This follows the semantics of the instruction | |
19951 | which specifies that bit 1 of the target address will come from bit | |
19952 | 1 of the base address. */ | |
19953 | value = (value + 1) & ~ 1; | |
404ff6b5 | 19954 | |
2fc8bdac | 19955 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19956 | { |
2fc8bdac ZW |
19957 | offsetT newval2; |
19958 | ||
19959 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19960 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19961 | newval |= (value & 0x7fffff) >> 12; | |
19962 | newval2 |= (value & 0xfff) >> 1; | |
19963 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19964 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 19965 | } |
c19d1205 | 19966 | break; |
404ff6b5 | 19967 | |
c19d1205 | 19968 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
19969 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
19970 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19971 | _("branch out of range")); | |
6c43fab6 | 19972 | |
2fc8bdac ZW |
19973 | if (fixP->fx_done || !seg->use_rela_p) |
19974 | { | |
19975 | offsetT newval2; | |
19976 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 19977 | |
2fc8bdac ZW |
19978 | S = (value & 0x01000000) >> 24; |
19979 | I1 = (value & 0x00800000) >> 23; | |
19980 | I2 = (value & 0x00400000) >> 22; | |
19981 | hi = (value & 0x003ff000) >> 12; | |
19982 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 19983 | |
2fc8bdac ZW |
19984 | I1 = !(I1 ^ S); |
19985 | I2 = !(I2 ^ S); | |
a737bd4d | 19986 | |
2fc8bdac ZW |
19987 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19988 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19989 | newval |= (S << 10) | hi; | |
19990 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
19991 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19992 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
19993 | } | |
19994 | break; | |
a737bd4d | 19995 | |
2fc8bdac ZW |
19996 | case BFD_RELOC_8: |
19997 | if (fixP->fx_done || !seg->use_rela_p) | |
19998 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 19999 | break; |
a737bd4d | 20000 | |
c19d1205 | 20001 | case BFD_RELOC_16: |
2fc8bdac | 20002 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 20003 | md_number_to_chars (buf, value, 2); |
c19d1205 | 20004 | break; |
a737bd4d | 20005 | |
c19d1205 ZW |
20006 | #ifdef OBJ_ELF |
20007 | case BFD_RELOC_ARM_TLS_GD32: | |
20008 | case BFD_RELOC_ARM_TLS_LE32: | |
20009 | case BFD_RELOC_ARM_TLS_IE32: | |
20010 | case BFD_RELOC_ARM_TLS_LDM32: | |
20011 | case BFD_RELOC_ARM_TLS_LDO32: | |
20012 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
20013 | /* fall through */ | |
6c43fab6 | 20014 | |
c19d1205 ZW |
20015 | case BFD_RELOC_ARM_GOT32: |
20016 | case BFD_RELOC_ARM_GOTOFF: | |
2fc8bdac ZW |
20017 | if (fixP->fx_done || !seg->use_rela_p) |
20018 | md_number_to_chars (buf, 0, 4); | |
c19d1205 | 20019 | break; |
9a6f4e97 NS |
20020 | |
20021 | case BFD_RELOC_ARM_TARGET2: | |
20022 | /* TARGET2 is not partial-inplace, so we need to write the | |
20023 | addend here for REL targets, because it won't be written out | |
20024 | during reloc processing later. */ | |
20025 | if (fixP->fx_done || !seg->use_rela_p) | |
20026 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
20027 | break; | |
c19d1205 | 20028 | #endif |
6c43fab6 | 20029 | |
c19d1205 ZW |
20030 | case BFD_RELOC_RVA: |
20031 | case BFD_RELOC_32: | |
20032 | case BFD_RELOC_ARM_TARGET1: | |
20033 | case BFD_RELOC_ARM_ROSEGREL32: | |
20034 | case BFD_RELOC_ARM_SBREL32: | |
20035 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
20036 | #ifdef TE_PE |
20037 | case BFD_RELOC_32_SECREL: | |
20038 | #endif | |
2fc8bdac | 20039 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
20040 | #ifdef TE_WINCE |
20041 | /* For WinCE we only do this for pcrel fixups. */ | |
20042 | if (fixP->fx_done || fixP->fx_pcrel) | |
20043 | #endif | |
20044 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 20045 | break; |
6c43fab6 | 20046 | |
c19d1205 ZW |
20047 | #ifdef OBJ_ELF |
20048 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 20049 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
20050 | { |
20051 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
20052 | if ((value ^ (value >> 1)) & 0x40000000) | |
20053 | { | |
20054 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20055 | _("rel31 relocation overflow")); | |
20056 | } | |
20057 | newval |= value & 0x7fffffff; | |
20058 | md_number_to_chars (buf, newval, 4); | |
20059 | } | |
20060 | break; | |
c19d1205 | 20061 | #endif |
a737bd4d | 20062 | |
c19d1205 | 20063 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 20064 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
20065 | if (value < -1023 || value > 1023 || (value & 3)) |
20066 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20067 | _("co-processor offset out of range")); | |
20068 | cp_off_common: | |
20069 | sign = value >= 0; | |
20070 | if (value < 0) | |
20071 | value = -value; | |
8f06b2d8 PB |
20072 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20073 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20074 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20075 | else | |
20076 | newval = get_thumb32_insn (buf); | |
20077 | newval &= 0xff7fff00; | |
c19d1205 | 20078 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
8f06b2d8 PB |
20079 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20080 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20081 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20082 | else | |
20083 | put_thumb32_insn (buf, newval); | |
c19d1205 | 20084 | break; |
a737bd4d | 20085 | |
c19d1205 | 20086 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 20087 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
20088 | if (value < -255 || value > 255) |
20089 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20090 | _("co-processor offset out of range")); | |
df7849c5 | 20091 | value *= 4; |
c19d1205 | 20092 | goto cp_off_common; |
6c43fab6 | 20093 | |
c19d1205 ZW |
20094 | case BFD_RELOC_ARM_THUMB_OFFSET: |
20095 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20096 | /* Exactly what ranges, and where the offset is inserted depends | |
20097 | on the type of instruction, we can establish this from the | |
20098 | top 4 bits. */ | |
20099 | switch (newval >> 12) | |
20100 | { | |
20101 | case 4: /* PC load. */ | |
20102 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
20103 | forced to zero for these loads; md_pcrel_from has already | |
20104 | compensated for this. */ | |
20105 | if (value & 3) | |
20106 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20107 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
20108 | (((unsigned long) fixP->fx_frag->fr_address |
20109 | + (unsigned long) fixP->fx_where) & ~3) | |
20110 | + (unsigned long) value); | |
a737bd4d | 20111 | |
c19d1205 ZW |
20112 | if (value & ~0x3fc) |
20113 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20114 | _("invalid offset, value too big (0x%08lX)"), | |
20115 | (long) value); | |
a737bd4d | 20116 | |
c19d1205 ZW |
20117 | newval |= value >> 2; |
20118 | break; | |
a737bd4d | 20119 | |
c19d1205 ZW |
20120 | case 9: /* SP load/store. */ |
20121 | if (value & ~0x3fc) | |
20122 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20123 | _("invalid offset, value too big (0x%08lX)"), | |
20124 | (long) value); | |
20125 | newval |= value >> 2; | |
20126 | break; | |
6c43fab6 | 20127 | |
c19d1205 ZW |
20128 | case 6: /* Word load/store. */ |
20129 | if (value & ~0x7c) | |
20130 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20131 | _("invalid offset, value too big (0x%08lX)"), | |
20132 | (long) value); | |
20133 | newval |= value << 4; /* 6 - 2. */ | |
20134 | break; | |
a737bd4d | 20135 | |
c19d1205 ZW |
20136 | case 7: /* Byte load/store. */ |
20137 | if (value & ~0x1f) | |
20138 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20139 | _("invalid offset, value too big (0x%08lX)"), | |
20140 | (long) value); | |
20141 | newval |= value << 6; | |
20142 | break; | |
a737bd4d | 20143 | |
c19d1205 ZW |
20144 | case 8: /* Halfword load/store. */ |
20145 | if (value & ~0x3e) | |
20146 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20147 | _("invalid offset, value too big (0x%08lX)"), | |
20148 | (long) value); | |
20149 | newval |= value << 5; /* 6 - 1. */ | |
20150 | break; | |
a737bd4d | 20151 | |
c19d1205 ZW |
20152 | default: |
20153 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20154 | "Unable to process relocation for thumb opcode: %lx", | |
20155 | (unsigned long) newval); | |
20156 | break; | |
20157 | } | |
20158 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20159 | break; | |
a737bd4d | 20160 | |
c19d1205 ZW |
20161 | case BFD_RELOC_ARM_THUMB_ADD: |
20162 | /* This is a complicated relocation, since we use it for all of | |
20163 | the following immediate relocations: | |
a737bd4d | 20164 | |
c19d1205 ZW |
20165 | 3bit ADD/SUB |
20166 | 8bit ADD/SUB | |
20167 | 9bit ADD/SUB SP word-aligned | |
20168 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 20169 | |
c19d1205 ZW |
20170 | The type of instruction being processed is encoded in the |
20171 | instruction field: | |
a737bd4d | 20172 | |
c19d1205 ZW |
20173 | 0x8000 SUB |
20174 | 0x00F0 Rd | |
20175 | 0x000F Rs | |
20176 | */ | |
20177 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20178 | { | |
20179 | int rd = (newval >> 4) & 0xf; | |
20180 | int rs = newval & 0xf; | |
20181 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 20182 | |
c19d1205 ZW |
20183 | /* Check for HI regs, only very restricted cases allowed: |
20184 | Adjusting SP, and using PC or SP to get an address. */ | |
20185 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
20186 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
20187 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20188 | _("invalid Hi register with immediate")); | |
a737bd4d | 20189 | |
c19d1205 ZW |
20190 | /* If value is negative, choose the opposite instruction. */ |
20191 | if (value < 0) | |
20192 | { | |
20193 | value = -value; | |
20194 | subtract = !subtract; | |
20195 | if (value < 0) | |
20196 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20197 | _("immediate value out of range")); | |
20198 | } | |
a737bd4d | 20199 | |
c19d1205 ZW |
20200 | if (rd == REG_SP) |
20201 | { | |
20202 | if (value & ~0x1fc) | |
20203 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20204 | _("invalid immediate for stack address calculation")); | |
20205 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
20206 | newval |= value >> 2; | |
20207 | } | |
20208 | else if (rs == REG_PC || rs == REG_SP) | |
20209 | { | |
20210 | if (subtract || value & ~0x3fc) | |
20211 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20212 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
20213 | (unsigned long) value); | |
20214 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
20215 | newval |= rd << 8; | |
20216 | newval |= value >> 2; | |
20217 | } | |
20218 | else if (rs == rd) | |
20219 | { | |
20220 | if (value & ~0xff) | |
20221 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20222 | _("immediate value out of range")); | |
20223 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
20224 | newval |= (rd << 8) | value; | |
20225 | } | |
20226 | else | |
20227 | { | |
20228 | if (value & ~0x7) | |
20229 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20230 | _("immediate value out of range")); | |
20231 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
20232 | newval |= rd | (rs << 3) | (value << 6); | |
20233 | } | |
20234 | } | |
20235 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20236 | break; | |
a737bd4d | 20237 | |
c19d1205 ZW |
20238 | case BFD_RELOC_ARM_THUMB_IMM: |
20239 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20240 | if (value < 0 || value > 255) | |
20241 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 20242 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
20243 | (long) value); |
20244 | newval |= value; | |
20245 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20246 | break; | |
a737bd4d | 20247 | |
c19d1205 ZW |
20248 | case BFD_RELOC_ARM_THUMB_SHIFT: |
20249 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
20250 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
20251 | temp = newval & 0xf800; | |
20252 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
20253 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20254 | _("invalid shift value: %ld"), (long) value); | |
20255 | /* Shifts of zero must be encoded as LSL. */ | |
20256 | if (value == 0) | |
20257 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
20258 | /* Shifts of 32 are encoded as zero. */ | |
20259 | else if (value == 32) | |
20260 | value = 0; | |
20261 | newval |= value << 6; | |
20262 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20263 | break; | |
a737bd4d | 20264 | |
c19d1205 ZW |
20265 | case BFD_RELOC_VTABLE_INHERIT: |
20266 | case BFD_RELOC_VTABLE_ENTRY: | |
20267 | fixP->fx_done = 0; | |
20268 | return; | |
6c43fab6 | 20269 | |
b6895b4f PB |
20270 | case BFD_RELOC_ARM_MOVW: |
20271 | case BFD_RELOC_ARM_MOVT: | |
20272 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20273 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20274 | if (fixP->fx_done || !seg->use_rela_p) | |
20275 | { | |
20276 | /* REL format relocations are limited to a 16-bit addend. */ | |
20277 | if (!fixP->fx_done) | |
20278 | { | |
39623e12 | 20279 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 20280 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 20281 | _("offset out of range")); |
b6895b4f PB |
20282 | } |
20283 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
20284 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20285 | { | |
20286 | value >>= 16; | |
20287 | } | |
20288 | ||
20289 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
20290 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20291 | { | |
20292 | newval = get_thumb32_insn (buf); | |
20293 | newval &= 0xfbf08f00; | |
20294 | newval |= (value & 0xf000) << 4; | |
20295 | newval |= (value & 0x0800) << 15; | |
20296 | newval |= (value & 0x0700) << 4; | |
20297 | newval |= (value & 0x00ff); | |
20298 | put_thumb32_insn (buf, newval); | |
20299 | } | |
20300 | else | |
20301 | { | |
20302 | newval = md_chars_to_number (buf, 4); | |
20303 | newval &= 0xfff0f000; | |
20304 | newval |= value & 0x0fff; | |
20305 | newval |= (value & 0xf000) << 4; | |
20306 | md_number_to_chars (buf, newval, 4); | |
20307 | } | |
20308 | } | |
20309 | return; | |
20310 | ||
4962c51a MS |
20311 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20312 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20313 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20314 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20315 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20316 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20317 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20318 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20319 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20320 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 20321 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20322 | if (!seg->use_rela_p) |
20323 | { | |
20324 | bfd_vma insn; | |
20325 | bfd_vma encoded_addend; | |
20326 | bfd_vma addend_abs = abs (value); | |
20327 | ||
20328 | /* Check that the absolute value of the addend can be | |
20329 | expressed as an 8-bit constant plus a rotation. */ | |
20330 | encoded_addend = encode_arm_immediate (addend_abs); | |
20331 | if (encoded_addend == (unsigned int) FAIL) | |
20332 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20333 | _("the offset 0x%08lX is not representable"), | |
495bde8e | 20334 | (unsigned long) addend_abs); |
4962c51a MS |
20335 | |
20336 | /* Extract the instruction. */ | |
20337 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20338 | ||
20339 | /* If the addend is positive, use an ADD instruction. | |
20340 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
20341 | insn &= 0xff1fffff; | |
20342 | if (value < 0) | |
20343 | insn |= 1 << 22; | |
20344 | else | |
20345 | insn |= 1 << 23; | |
20346 | ||
20347 | /* Place the encoded addend into the first 12 bits of the | |
20348 | instruction. */ | |
20349 | insn &= 0xfffff000; | |
20350 | insn |= encoded_addend; | |
5f4273c7 NC |
20351 | |
20352 | /* Update the instruction. */ | |
4962c51a MS |
20353 | md_number_to_chars (buf, insn, INSN_SIZE); |
20354 | } | |
20355 | break; | |
20356 | ||
20357 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20358 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20359 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20360 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20361 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20362 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 20363 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20364 | if (!seg->use_rela_p) |
20365 | { | |
20366 | bfd_vma insn; | |
20367 | bfd_vma addend_abs = abs (value); | |
20368 | ||
20369 | /* Check that the absolute value of the addend can be | |
20370 | encoded in 12 bits. */ | |
20371 | if (addend_abs >= 0x1000) | |
20372 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20373 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
495bde8e | 20374 | (unsigned long) addend_abs); |
4962c51a MS |
20375 | |
20376 | /* Extract the instruction. */ | |
20377 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20378 | ||
20379 | /* If the addend is negative, clear bit 23 of the instruction. | |
20380 | Otherwise set it. */ | |
20381 | if (value < 0) | |
20382 | insn &= ~(1 << 23); | |
20383 | else | |
20384 | insn |= 1 << 23; | |
20385 | ||
20386 | /* Place the absolute value of the addend into the first 12 bits | |
20387 | of the instruction. */ | |
20388 | insn &= 0xfffff000; | |
20389 | insn |= addend_abs; | |
5f4273c7 NC |
20390 | |
20391 | /* Update the instruction. */ | |
4962c51a MS |
20392 | md_number_to_chars (buf, insn, INSN_SIZE); |
20393 | } | |
20394 | break; | |
20395 | ||
20396 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20397 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20398 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20399 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20400 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20401 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 20402 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20403 | if (!seg->use_rela_p) |
20404 | { | |
20405 | bfd_vma insn; | |
20406 | bfd_vma addend_abs = abs (value); | |
20407 | ||
20408 | /* Check that the absolute value of the addend can be | |
20409 | encoded in 8 bits. */ | |
20410 | if (addend_abs >= 0x100) | |
20411 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20412 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
495bde8e | 20413 | (unsigned long) addend_abs); |
4962c51a MS |
20414 | |
20415 | /* Extract the instruction. */ | |
20416 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20417 | ||
20418 | /* If the addend is negative, clear bit 23 of the instruction. | |
20419 | Otherwise set it. */ | |
20420 | if (value < 0) | |
20421 | insn &= ~(1 << 23); | |
20422 | else | |
20423 | insn |= 1 << 23; | |
20424 | ||
20425 | /* Place the first four bits of the absolute value of the addend | |
20426 | into the first 4 bits of the instruction, and the remaining | |
20427 | four into bits 8 .. 11. */ | |
20428 | insn &= 0xfffff0f0; | |
20429 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
5f4273c7 NC |
20430 | |
20431 | /* Update the instruction. */ | |
4962c51a MS |
20432 | md_number_to_chars (buf, insn, INSN_SIZE); |
20433 | } | |
20434 | break; | |
20435 | ||
20436 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20437 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20438 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20439 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20440 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20441 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 20442 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20443 | if (!seg->use_rela_p) |
20444 | { | |
20445 | bfd_vma insn; | |
20446 | bfd_vma addend_abs = abs (value); | |
20447 | ||
20448 | /* Check that the absolute value of the addend is a multiple of | |
20449 | four and, when divided by four, fits in 8 bits. */ | |
20450 | if (addend_abs & 0x3) | |
20451 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20452 | _("bad offset 0x%08lX (must be word-aligned)"), | |
495bde8e | 20453 | (unsigned long) addend_abs); |
4962c51a MS |
20454 | |
20455 | if ((addend_abs >> 2) > 0xff) | |
20456 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20457 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
495bde8e | 20458 | (unsigned long) addend_abs); |
4962c51a MS |
20459 | |
20460 | /* Extract the instruction. */ | |
20461 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20462 | ||
20463 | /* If the addend is negative, clear bit 23 of the instruction. | |
20464 | Otherwise set it. */ | |
20465 | if (value < 0) | |
20466 | insn &= ~(1 << 23); | |
20467 | else | |
20468 | insn |= 1 << 23; | |
20469 | ||
20470 | /* Place the addend (divided by four) into the first eight | |
20471 | bits of the instruction. */ | |
20472 | insn &= 0xfffffff0; | |
20473 | insn |= addend_abs >> 2; | |
5f4273c7 NC |
20474 | |
20475 | /* Update the instruction. */ | |
4962c51a MS |
20476 | md_number_to_chars (buf, insn, INSN_SIZE); |
20477 | } | |
20478 | break; | |
20479 | ||
845b51d6 PB |
20480 | case BFD_RELOC_ARM_V4BX: |
20481 | /* This will need to go in the object file. */ | |
20482 | fixP->fx_done = 0; | |
20483 | break; | |
20484 | ||
c19d1205 ZW |
20485 | case BFD_RELOC_UNUSED: |
20486 | default: | |
20487 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20488 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
20489 | } | |
6c43fab6 RE |
20490 | } |
20491 | ||
c19d1205 ZW |
20492 | /* Translate internal representation of relocation info to BFD target |
20493 | format. */ | |
a737bd4d | 20494 | |
c19d1205 | 20495 | arelent * |
00a97672 | 20496 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 20497 | { |
c19d1205 ZW |
20498 | arelent * reloc; |
20499 | bfd_reloc_code_real_type code; | |
a737bd4d | 20500 | |
c19d1205 | 20501 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 20502 | |
c19d1205 ZW |
20503 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
20504 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
20505 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 20506 | |
2fc8bdac | 20507 | if (fixp->fx_pcrel) |
00a97672 RS |
20508 | { |
20509 | if (section->use_rela_p) | |
20510 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
20511 | else | |
20512 | fixp->fx_offset = reloc->address; | |
20513 | } | |
c19d1205 | 20514 | reloc->addend = fixp->fx_offset; |
a737bd4d | 20515 | |
c19d1205 | 20516 | switch (fixp->fx_r_type) |
a737bd4d | 20517 | { |
c19d1205 ZW |
20518 | case BFD_RELOC_8: |
20519 | if (fixp->fx_pcrel) | |
20520 | { | |
20521 | code = BFD_RELOC_8_PCREL; | |
20522 | break; | |
20523 | } | |
a737bd4d | 20524 | |
c19d1205 ZW |
20525 | case BFD_RELOC_16: |
20526 | if (fixp->fx_pcrel) | |
20527 | { | |
20528 | code = BFD_RELOC_16_PCREL; | |
20529 | break; | |
20530 | } | |
6c43fab6 | 20531 | |
c19d1205 ZW |
20532 | case BFD_RELOC_32: |
20533 | if (fixp->fx_pcrel) | |
20534 | { | |
20535 | code = BFD_RELOC_32_PCREL; | |
20536 | break; | |
20537 | } | |
a737bd4d | 20538 | |
b6895b4f PB |
20539 | case BFD_RELOC_ARM_MOVW: |
20540 | if (fixp->fx_pcrel) | |
20541 | { | |
20542 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
20543 | break; | |
20544 | } | |
20545 | ||
20546 | case BFD_RELOC_ARM_MOVT: | |
20547 | if (fixp->fx_pcrel) | |
20548 | { | |
20549 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
20550 | break; | |
20551 | } | |
20552 | ||
20553 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20554 | if (fixp->fx_pcrel) | |
20555 | { | |
20556 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
20557 | break; | |
20558 | } | |
20559 | ||
20560 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20561 | if (fixp->fx_pcrel) | |
20562 | { | |
20563 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
20564 | break; | |
20565 | } | |
20566 | ||
c19d1205 ZW |
20567 | case BFD_RELOC_NONE: |
20568 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
20569 | case BFD_RELOC_ARM_PCREL_BLX: | |
20570 | case BFD_RELOC_RVA: | |
20571 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
20572 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
20573 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
20574 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20575 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20576 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
20577 | case BFD_RELOC_VTABLE_ENTRY: |
20578 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
20579 | #ifdef TE_PE |
20580 | case BFD_RELOC_32_SECREL: | |
20581 | #endif | |
c19d1205 ZW |
20582 | code = fixp->fx_r_type; |
20583 | break; | |
a737bd4d | 20584 | |
00adf2d4 JB |
20585 | case BFD_RELOC_THUMB_PCREL_BLX: |
20586 | #ifdef OBJ_ELF | |
20587 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
20588 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20589 | else | |
20590 | #endif | |
20591 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
20592 | break; | |
20593 | ||
c19d1205 ZW |
20594 | case BFD_RELOC_ARM_LITERAL: |
20595 | case BFD_RELOC_ARM_HWLITERAL: | |
20596 | /* If this is called then the a literal has | |
20597 | been referenced across a section boundary. */ | |
20598 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20599 | _("literal referenced across section boundary")); | |
20600 | return NULL; | |
a737bd4d | 20601 | |
c19d1205 ZW |
20602 | #ifdef OBJ_ELF |
20603 | case BFD_RELOC_ARM_GOT32: | |
20604 | case BFD_RELOC_ARM_GOTOFF: | |
20605 | case BFD_RELOC_ARM_PLT32: | |
20606 | case BFD_RELOC_ARM_TARGET1: | |
20607 | case BFD_RELOC_ARM_ROSEGREL32: | |
20608 | case BFD_RELOC_ARM_SBREL32: | |
20609 | case BFD_RELOC_ARM_PREL31: | |
20610 | case BFD_RELOC_ARM_TARGET2: | |
20611 | case BFD_RELOC_ARM_TLS_LE32: | |
20612 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
20613 | case BFD_RELOC_ARM_PCREL_CALL: |
20614 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
20615 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20616 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20617 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20618 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20619 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20620 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20621 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20622 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20623 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20624 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20625 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20626 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20627 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20628 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20629 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20630 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20631 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20632 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20633 | case BFD_RELOC_ARM_ALU_SB_G2: | |
20634 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20635 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20636 | case BFD_RELOC_ARM_LDR_SB_G2: | |
20637 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20638 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20639 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
20640 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20641 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20642 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 20643 | case BFD_RELOC_ARM_V4BX: |
c19d1205 ZW |
20644 | code = fixp->fx_r_type; |
20645 | break; | |
a737bd4d | 20646 | |
c19d1205 ZW |
20647 | case BFD_RELOC_ARM_TLS_GD32: |
20648 | case BFD_RELOC_ARM_TLS_IE32: | |
20649 | case BFD_RELOC_ARM_TLS_LDM32: | |
20650 | /* BFD will include the symbol's address in the addend. | |
20651 | But we don't want that, so subtract it out again here. */ | |
20652 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
20653 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
20654 | code = fixp->fx_r_type; | |
20655 | break; | |
20656 | #endif | |
a737bd4d | 20657 | |
c19d1205 ZW |
20658 | case BFD_RELOC_ARM_IMMEDIATE: |
20659 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20660 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
20661 | return NULL; | |
a737bd4d | 20662 | |
c19d1205 ZW |
20663 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
20664 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20665 | _("ADRL used for a symbol not defined in the same file")); | |
20666 | return NULL; | |
a737bd4d | 20667 | |
c19d1205 | 20668 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
20669 | if (section->use_rela_p) |
20670 | { | |
20671 | code = fixp->fx_r_type; | |
20672 | break; | |
20673 | } | |
20674 | ||
c19d1205 ZW |
20675 | if (fixp->fx_addsy != NULL |
20676 | && !S_IS_DEFINED (fixp->fx_addsy) | |
20677 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 20678 | { |
c19d1205 ZW |
20679 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20680 | _("undefined local label `%s'"), | |
20681 | S_GET_NAME (fixp->fx_addsy)); | |
20682 | return NULL; | |
a737bd4d NC |
20683 | } |
20684 | ||
c19d1205 ZW |
20685 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20686 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
20687 | return NULL; | |
a737bd4d | 20688 | |
c19d1205 ZW |
20689 | default: |
20690 | { | |
20691 | char * type; | |
6c43fab6 | 20692 | |
c19d1205 ZW |
20693 | switch (fixp->fx_r_type) |
20694 | { | |
20695 | case BFD_RELOC_NONE: type = "NONE"; break; | |
20696 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
20697 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 20698 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
20699 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
20700 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
20701 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 20702 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
20703 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
20704 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
20705 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
20706 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
20707 | default: type = _("<unknown>"); break; | |
20708 | } | |
20709 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20710 | _("cannot represent %s relocation in this object file format"), | |
20711 | type); | |
20712 | return NULL; | |
20713 | } | |
a737bd4d | 20714 | } |
6c43fab6 | 20715 | |
c19d1205 ZW |
20716 | #ifdef OBJ_ELF |
20717 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
20718 | && GOT_symbol | |
20719 | && fixp->fx_addsy == GOT_symbol) | |
20720 | { | |
20721 | code = BFD_RELOC_ARM_GOTPC; | |
20722 | reloc->addend = fixp->fx_offset = reloc->address; | |
20723 | } | |
20724 | #endif | |
6c43fab6 | 20725 | |
c19d1205 | 20726 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 20727 | |
c19d1205 ZW |
20728 | if (reloc->howto == NULL) |
20729 | { | |
20730 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20731 | _("cannot represent %s relocation in this object file format"), | |
20732 | bfd_get_reloc_code_name (code)); | |
20733 | return NULL; | |
20734 | } | |
6c43fab6 | 20735 | |
c19d1205 ZW |
20736 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
20737 | vtable entry to be used in the relocation's section offset. */ | |
20738 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
20739 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 20740 | |
c19d1205 | 20741 | return reloc; |
6c43fab6 RE |
20742 | } |
20743 | ||
c19d1205 | 20744 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 20745 | |
c19d1205 ZW |
20746 | void |
20747 | cons_fix_new_arm (fragS * frag, | |
20748 | int where, | |
20749 | int size, | |
20750 | expressionS * exp) | |
6c43fab6 | 20751 | { |
c19d1205 ZW |
20752 | bfd_reloc_code_real_type type; |
20753 | int pcrel = 0; | |
6c43fab6 | 20754 | |
c19d1205 ZW |
20755 | /* Pick a reloc. |
20756 | FIXME: @@ Should look at CPU word size. */ | |
20757 | switch (size) | |
20758 | { | |
20759 | case 1: | |
20760 | type = BFD_RELOC_8; | |
20761 | break; | |
20762 | case 2: | |
20763 | type = BFD_RELOC_16; | |
20764 | break; | |
20765 | case 4: | |
20766 | default: | |
20767 | type = BFD_RELOC_32; | |
20768 | break; | |
20769 | case 8: | |
20770 | type = BFD_RELOC_64; | |
20771 | break; | |
20772 | } | |
6c43fab6 | 20773 | |
f0927246 NC |
20774 | #ifdef TE_PE |
20775 | if (exp->X_op == O_secrel) | |
20776 | { | |
20777 | exp->X_op = O_symbol; | |
20778 | type = BFD_RELOC_32_SECREL; | |
20779 | } | |
20780 | #endif | |
20781 | ||
c19d1205 ZW |
20782 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
20783 | } | |
6c43fab6 | 20784 | |
4343666d | 20785 | #if defined (OBJ_COFF) |
c19d1205 ZW |
20786 | void |
20787 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 20788 | { |
c19d1205 ZW |
20789 | /* If the destination of the branch is a defined symbol which does not have |
20790 | the THUMB_FUNC attribute, then we must be calling a function which has | |
20791 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
20792 | function and change the branch to refer to that function instead. */ | |
20793 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
20794 | && fixP->fx_addsy != NULL | |
20795 | && S_IS_DEFINED (fixP->fx_addsy) | |
20796 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 20797 | { |
c19d1205 | 20798 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 20799 | } |
c19d1205 ZW |
20800 | } |
20801 | #endif | |
6c43fab6 | 20802 | |
267bf995 | 20803 | |
c19d1205 ZW |
20804 | int |
20805 | arm_force_relocation (struct fix * fixp) | |
20806 | { | |
20807 | #if defined (OBJ_COFF) && defined (TE_PE) | |
20808 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
20809 | return 1; | |
20810 | #endif | |
6c43fab6 | 20811 | |
267bf995 RR |
20812 | /* In case we have a call or a branch to a function in ARM ISA mode from |
20813 | a thumb function or vice-versa force the relocation. These relocations | |
20814 | are cleared off for some cores that might have blx and simple transformations | |
20815 | are possible. */ | |
20816 | ||
20817 | #ifdef OBJ_ELF | |
20818 | switch (fixp->fx_r_type) | |
20819 | { | |
20820 | case BFD_RELOC_ARM_PCREL_JUMP: | |
20821 | case BFD_RELOC_ARM_PCREL_CALL: | |
20822 | case BFD_RELOC_THUMB_PCREL_BLX: | |
20823 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
20824 | return 1; | |
20825 | break; | |
20826 | ||
20827 | case BFD_RELOC_ARM_PCREL_BLX: | |
20828 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
20829 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20830 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20831 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
20832 | return 1; | |
20833 | break; | |
20834 | ||
20835 | default: | |
20836 | break; | |
20837 | } | |
20838 | #endif | |
20839 | ||
c19d1205 ZW |
20840 | /* Resolve these relocations even if the symbol is extern or weak. */ |
20841 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
20842 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 | 20843 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
16805f35 | 20844 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
20845 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
20846 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
20847 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 20848 | return 0; |
a737bd4d | 20849 | |
4962c51a MS |
20850 | /* Always leave these relocations for the linker. */ |
20851 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
20852 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
20853 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
20854 | return 1; | |
20855 | ||
f0291e4c PB |
20856 | /* Always generate relocations against function symbols. */ |
20857 | if (fixp->fx_r_type == BFD_RELOC_32 | |
20858 | && fixp->fx_addsy | |
20859 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
20860 | return 1; | |
20861 | ||
c19d1205 | 20862 | return generic_force_reloc (fixp); |
404ff6b5 AH |
20863 | } |
20864 | ||
0ffdc86c | 20865 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
20866 | /* Relocations against function names must be left unadjusted, |
20867 | so that the linker can use this information to generate interworking | |
20868 | stubs. The MIPS version of this function | |
c19d1205 ZW |
20869 | also prevents relocations that are mips-16 specific, but I do not |
20870 | know why it does this. | |
404ff6b5 | 20871 | |
c19d1205 ZW |
20872 | FIXME: |
20873 | There is one other problem that ought to be addressed here, but | |
20874 | which currently is not: Taking the address of a label (rather | |
20875 | than a function) and then later jumping to that address. Such | |
20876 | addresses also ought to have their bottom bit set (assuming that | |
20877 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 20878 | |
c19d1205 ZW |
20879 | bfd_boolean |
20880 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 20881 | { |
c19d1205 ZW |
20882 | if (fixP->fx_addsy == NULL) |
20883 | return 1; | |
404ff6b5 | 20884 | |
e28387c3 PB |
20885 | /* Preserve relocations against symbols with function type. */ |
20886 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 20887 | return FALSE; |
e28387c3 | 20888 | |
c19d1205 ZW |
20889 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
20890 | && fixP->fx_subsy == NULL) | |
c921be7d | 20891 | return FALSE; |
a737bd4d | 20892 | |
c19d1205 ZW |
20893 | /* We need the symbol name for the VTABLE entries. */ |
20894 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
20895 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 20896 | return FALSE; |
404ff6b5 | 20897 | |
c19d1205 ZW |
20898 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
20899 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
20900 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
20901 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
20902 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
20903 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
20904 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
20905 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
20906 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
20907 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
c921be7d | 20908 | return FALSE; |
a737bd4d | 20909 | |
4962c51a MS |
20910 | /* Similarly for group relocations. */ |
20911 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
20912 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
20913 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 20914 | return FALSE; |
4962c51a | 20915 | |
79947c54 CD |
20916 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
20917 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
20918 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
20919 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
20920 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
20921 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
20922 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
20923 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
20924 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 20925 | return FALSE; |
79947c54 | 20926 | |
c921be7d | 20927 | return TRUE; |
a737bd4d | 20928 | } |
0ffdc86c NC |
20929 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
20930 | ||
20931 | #ifdef OBJ_ELF | |
404ff6b5 | 20932 | |
c19d1205 ZW |
20933 | const char * |
20934 | elf32_arm_target_format (void) | |
404ff6b5 | 20935 | { |
c19d1205 ZW |
20936 | #ifdef TE_SYMBIAN |
20937 | return (target_big_endian | |
20938 | ? "elf32-bigarm-symbian" | |
20939 | : "elf32-littlearm-symbian"); | |
20940 | #elif defined (TE_VXWORKS) | |
20941 | return (target_big_endian | |
20942 | ? "elf32-bigarm-vxworks" | |
20943 | : "elf32-littlearm-vxworks"); | |
20944 | #else | |
20945 | if (target_big_endian) | |
20946 | return "elf32-bigarm"; | |
20947 | else | |
20948 | return "elf32-littlearm"; | |
20949 | #endif | |
404ff6b5 AH |
20950 | } |
20951 | ||
c19d1205 ZW |
20952 | void |
20953 | armelf_frob_symbol (symbolS * symp, | |
20954 | int * puntp) | |
404ff6b5 | 20955 | { |
c19d1205 ZW |
20956 | elf_frob_symbol (symp, puntp); |
20957 | } | |
20958 | #endif | |
404ff6b5 | 20959 | |
c19d1205 | 20960 | /* MD interface: Finalization. */ |
a737bd4d | 20961 | |
c19d1205 ZW |
20962 | void |
20963 | arm_cleanup (void) | |
20964 | { | |
20965 | literal_pool * pool; | |
a737bd4d | 20966 | |
e07e6e58 NC |
20967 | /* Ensure that all the IT blocks are properly closed. */ |
20968 | check_it_blocks_finished (); | |
20969 | ||
c19d1205 ZW |
20970 | for (pool = list_of_pools; pool; pool = pool->next) |
20971 | { | |
5f4273c7 | 20972 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
20973 | subseg_set (pool->section, pool->sub_section); |
20974 | #ifdef OBJ_ELF | |
20975 | arm_elf_change_section (); | |
20976 | #endif | |
20977 | s_ltorg (0); | |
20978 | } | |
404ff6b5 AH |
20979 | } |
20980 | ||
c19d1205 ZW |
20981 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
20982 | ARM ones. */ | |
404ff6b5 | 20983 | |
c19d1205 ZW |
20984 | void |
20985 | arm_adjust_symtab (void) | |
404ff6b5 | 20986 | { |
c19d1205 ZW |
20987 | #ifdef OBJ_COFF |
20988 | symbolS * sym; | |
404ff6b5 | 20989 | |
c19d1205 ZW |
20990 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
20991 | { | |
20992 | if (ARM_IS_THUMB (sym)) | |
20993 | { | |
20994 | if (THUMB_IS_FUNC (sym)) | |
20995 | { | |
20996 | /* Mark the symbol as a Thumb function. */ | |
20997 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
20998 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
20999 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 21000 | |
c19d1205 ZW |
21001 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
21002 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
21003 | else | |
21004 | as_bad (_("%s: unexpected function type: %d"), | |
21005 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
21006 | } | |
21007 | else switch (S_GET_STORAGE_CLASS (sym)) | |
21008 | { | |
21009 | case C_EXT: | |
21010 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
21011 | break; | |
21012 | case C_STAT: | |
21013 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
21014 | break; | |
21015 | case C_LABEL: | |
21016 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
21017 | break; | |
21018 | default: | |
21019 | /* Do nothing. */ | |
21020 | break; | |
21021 | } | |
21022 | } | |
a737bd4d | 21023 | |
c19d1205 ZW |
21024 | if (ARM_IS_INTERWORK (sym)) |
21025 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 21026 | } |
c19d1205 ZW |
21027 | #endif |
21028 | #ifdef OBJ_ELF | |
21029 | symbolS * sym; | |
21030 | char bind; | |
404ff6b5 | 21031 | |
c19d1205 | 21032 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 21033 | { |
c19d1205 ZW |
21034 | if (ARM_IS_THUMB (sym)) |
21035 | { | |
21036 | elf_symbol_type * elf_sym; | |
404ff6b5 | 21037 | |
c19d1205 ZW |
21038 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
21039 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 21040 | |
b0796911 PB |
21041 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
21042 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
21043 | { |
21044 | /* If it's a .thumb_func, declare it as so, | |
21045 | otherwise tag label as .code 16. */ | |
21046 | if (THUMB_IS_FUNC (sym)) | |
21047 | elf_sym->internal_elf_sym.st_info = | |
21048 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
3ba67470 | 21049 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
21050 | elf_sym->internal_elf_sym.st_info = |
21051 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
21052 | } | |
21053 | } | |
21054 | } | |
21055 | #endif | |
404ff6b5 AH |
21056 | } |
21057 | ||
c19d1205 | 21058 | /* MD interface: Initialization. */ |
404ff6b5 | 21059 | |
a737bd4d | 21060 | static void |
c19d1205 | 21061 | set_constant_flonums (void) |
a737bd4d | 21062 | { |
c19d1205 | 21063 | int i; |
404ff6b5 | 21064 | |
c19d1205 ZW |
21065 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
21066 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
21067 | abort (); | |
a737bd4d | 21068 | } |
404ff6b5 | 21069 | |
3e9e4fcf JB |
21070 | /* Auto-select Thumb mode if it's the only available instruction set for the |
21071 | given architecture. */ | |
21072 | ||
21073 | static void | |
21074 | autoselect_thumb_from_cpu_variant (void) | |
21075 | { | |
21076 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
21077 | opcode_select (16); | |
21078 | } | |
21079 | ||
c19d1205 ZW |
21080 | void |
21081 | md_begin (void) | |
a737bd4d | 21082 | { |
c19d1205 ZW |
21083 | unsigned mach; |
21084 | unsigned int i; | |
404ff6b5 | 21085 | |
c19d1205 ZW |
21086 | if ( (arm_ops_hsh = hash_new ()) == NULL |
21087 | || (arm_cond_hsh = hash_new ()) == NULL | |
21088 | || (arm_shift_hsh = hash_new ()) == NULL | |
21089 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 21090 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 21091 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
21092 | || (arm_reloc_hsh = hash_new ()) == NULL |
21093 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
21094 | as_fatal (_("virtual memory exhausted")); |
21095 | ||
21096 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
5a49b8ac | 21097 | hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i)); |
c19d1205 | 21098 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
5a49b8ac | 21099 | hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i)); |
c19d1205 | 21100 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 21101 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 21102 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
5a49b8ac | 21103 | hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i)); |
62b3e311 | 21104 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
5a49b8ac | 21105 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i)); |
c19d1205 | 21106 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 21107 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
21108 | for (i = 0; |
21109 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
21110 | i++) | |
21111 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template, | |
5a49b8ac | 21112 | (void *) (barrier_opt_names + i)); |
c19d1205 ZW |
21113 | #ifdef OBJ_ELF |
21114 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
5a49b8ac | 21115 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i)); |
c19d1205 ZW |
21116 | #endif |
21117 | ||
21118 | set_constant_flonums (); | |
404ff6b5 | 21119 | |
c19d1205 ZW |
21120 | /* Set the cpu variant based on the command-line options. We prefer |
21121 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
21122 | -mfpu= over any other way of setting the floating point unit. | |
21123 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 21124 | if (legacy_cpu) |
404ff6b5 | 21125 | { |
e74cfd16 | 21126 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
21127 | as_bad (_("use of old and new-style options to set CPU type")); |
21128 | ||
21129 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 21130 | } |
e74cfd16 | 21131 | else if (!mcpu_cpu_opt) |
c19d1205 | 21132 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 21133 | |
e74cfd16 | 21134 | if (legacy_fpu) |
c19d1205 | 21135 | { |
e74cfd16 | 21136 | if (mfpu_opt) |
c19d1205 | 21137 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
21138 | |
21139 | mfpu_opt = legacy_fpu; | |
21140 | } | |
e74cfd16 | 21141 | else if (!mfpu_opt) |
03b1477f | 21142 | { |
45eb4c1b NS |
21143 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
21144 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
21145 | /* Some environments specify a default FPU. If they don't, infer it |
21146 | from the processor. */ | |
e74cfd16 | 21147 | if (mcpu_fpu_opt) |
03b1477f RE |
21148 | mfpu_opt = mcpu_fpu_opt; |
21149 | else | |
21150 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 21151 | #else |
e74cfd16 | 21152 | mfpu_opt = &fpu_default; |
39c2da32 | 21153 | #endif |
03b1477f RE |
21154 | } |
21155 | ||
e74cfd16 | 21156 | if (!mfpu_opt) |
03b1477f | 21157 | { |
493cb6ef | 21158 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 21159 | mfpu_opt = &fpu_default; |
493cb6ef | 21160 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 21161 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 21162 | else |
e74cfd16 | 21163 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
21164 | } |
21165 | ||
ee065d83 | 21166 | #ifdef CPU_DEFAULT |
e74cfd16 | 21167 | if (!mcpu_cpu_opt) |
ee065d83 | 21168 | { |
e74cfd16 PB |
21169 | mcpu_cpu_opt = &cpu_default; |
21170 | selected_cpu = cpu_default; | |
ee065d83 | 21171 | } |
e74cfd16 PB |
21172 | #else |
21173 | if (mcpu_cpu_opt) | |
21174 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 21175 | else |
e74cfd16 | 21176 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 21177 | #endif |
03b1477f | 21178 | |
e74cfd16 | 21179 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 21180 | |
3e9e4fcf JB |
21181 | autoselect_thumb_from_cpu_variant (); |
21182 | ||
e74cfd16 | 21183 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 21184 | |
f17c130b | 21185 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 21186 | { |
7cc69913 NC |
21187 | unsigned int flags = 0; |
21188 | ||
21189 | #if defined OBJ_ELF | |
21190 | flags = meabi_flags; | |
d507cf36 PB |
21191 | |
21192 | switch (meabi_flags) | |
33a392fb | 21193 | { |
d507cf36 | 21194 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 21195 | #endif |
d507cf36 PB |
21196 | /* Set the flags in the private structure. */ |
21197 | if (uses_apcs_26) flags |= F_APCS26; | |
21198 | if (support_interwork) flags |= F_INTERWORK; | |
21199 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 21200 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 21201 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
21202 | flags |= F_SOFT_FLOAT; |
21203 | ||
d507cf36 PB |
21204 | switch (mfloat_abi_opt) |
21205 | { | |
21206 | case ARM_FLOAT_ABI_SOFT: | |
21207 | case ARM_FLOAT_ABI_SOFTFP: | |
21208 | flags |= F_SOFT_FLOAT; | |
21209 | break; | |
33a392fb | 21210 | |
d507cf36 PB |
21211 | case ARM_FLOAT_ABI_HARD: |
21212 | if (flags & F_SOFT_FLOAT) | |
21213 | as_bad (_("hard-float conflicts with specified fpu")); | |
21214 | break; | |
21215 | } | |
03b1477f | 21216 | |
e74cfd16 PB |
21217 | /* Using pure-endian doubles (even if soft-float). */ |
21218 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 21219 | flags |= F_VFP_FLOAT; |
f17c130b | 21220 | |
fde78edd | 21221 | #if defined OBJ_ELF |
e74cfd16 | 21222 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 21223 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
21224 | break; |
21225 | ||
8cb51566 | 21226 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 21227 | case EF_ARM_EABI_VER5: |
c19d1205 | 21228 | /* No additional flags to set. */ |
d507cf36 PB |
21229 | break; |
21230 | ||
21231 | default: | |
21232 | abort (); | |
21233 | } | |
7cc69913 | 21234 | #endif |
b99bd4ef NC |
21235 | bfd_set_private_flags (stdoutput, flags); |
21236 | ||
21237 | /* We have run out flags in the COFF header to encode the | |
21238 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 21239 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
21240 | if (atpcs) |
21241 | { | |
21242 | asection * sec; | |
21243 | ||
21244 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
21245 | ||
21246 | if (sec != NULL) | |
21247 | { | |
21248 | bfd_set_section_flags | |
21249 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
21250 | bfd_set_section_size (stdoutput, sec, 0); | |
21251 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
21252 | } | |
21253 | } | |
7cc69913 | 21254 | } |
f17c130b | 21255 | #endif |
b99bd4ef NC |
21256 | |
21257 | /* Record the CPU type as well. */ | |
2d447fca JM |
21258 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
21259 | mach = bfd_mach_arm_iWMMXt2; | |
21260 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 21261 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 21262 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 21263 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 21264 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 21265 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 21266 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 21267 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 21268 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 21269 | { |
e74cfd16 | 21270 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21271 | mach = bfd_mach_arm_5T; |
21272 | else | |
21273 | mach = bfd_mach_arm_5; | |
21274 | } | |
e74cfd16 | 21275 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 21276 | { |
e74cfd16 | 21277 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21278 | mach = bfd_mach_arm_4T; |
21279 | else | |
21280 | mach = bfd_mach_arm_4; | |
21281 | } | |
e74cfd16 | 21282 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 21283 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
21284 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
21285 | mach = bfd_mach_arm_3; | |
21286 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
21287 | mach = bfd_mach_arm_2a; | |
21288 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
21289 | mach = bfd_mach_arm_2; | |
21290 | else | |
21291 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
21292 | |
21293 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
21294 | } | |
21295 | ||
c19d1205 | 21296 | /* Command line processing. */ |
b99bd4ef | 21297 | |
c19d1205 ZW |
21298 | /* md_parse_option |
21299 | Invocation line includes a switch not recognized by the base assembler. | |
21300 | See if it's a processor-specific option. | |
b99bd4ef | 21301 | |
c19d1205 ZW |
21302 | This routine is somewhat complicated by the need for backwards |
21303 | compatibility (since older releases of gcc can't be changed). | |
21304 | The new options try to make the interface as compatible as | |
21305 | possible with GCC. | |
b99bd4ef | 21306 | |
c19d1205 | 21307 | New options (supported) are: |
b99bd4ef | 21308 | |
c19d1205 ZW |
21309 | -mcpu=<cpu name> Assemble for selected processor |
21310 | -march=<architecture name> Assemble for selected architecture | |
21311 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
21312 | -EB/-mbig-endian Big-endian | |
21313 | -EL/-mlittle-endian Little-endian | |
21314 | -k Generate PIC code | |
21315 | -mthumb Start in Thumb mode | |
21316 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 21317 | |
278df34e | 21318 | -m[no-]warn-deprecated Warn about deprecated features |
267bf995 | 21319 | |
c19d1205 | 21320 | For now we will also provide support for: |
b99bd4ef | 21321 | |
c19d1205 ZW |
21322 | -mapcs-32 32-bit Program counter |
21323 | -mapcs-26 26-bit Program counter | |
21324 | -macps-float Floats passed in FP registers | |
21325 | -mapcs-reentrant Reentrant code | |
21326 | -matpcs | |
21327 | (sometime these will probably be replaced with -mapcs=<list of options> | |
21328 | and -matpcs=<list of options>) | |
b99bd4ef | 21329 | |
c19d1205 ZW |
21330 | The remaining options are only supported for back-wards compatibility. |
21331 | Cpu variants, the arm part is optional: | |
21332 | -m[arm]1 Currently not supported. | |
21333 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
21334 | -m[arm]3 Arm 3 processor | |
21335 | -m[arm]6[xx], Arm 6 processors | |
21336 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
21337 | -m[arm]8[10] Arm 8 processors | |
21338 | -m[arm]9[20][tdmi] Arm 9 processors | |
21339 | -mstrongarm[110[0]] StrongARM processors | |
21340 | -mxscale XScale processors | |
21341 | -m[arm]v[2345[t[e]]] Arm architectures | |
21342 | -mall All (except the ARM1) | |
21343 | FP variants: | |
21344 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
21345 | -mfpe-old (No float load/store multiples) | |
21346 | -mvfpxd VFP Single precision | |
21347 | -mvfp All VFP | |
21348 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 21349 | |
c19d1205 ZW |
21350 | The following CPU names are recognized: |
21351 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
21352 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
21353 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
21354 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
21355 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
21356 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
21357 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 21358 | |
c19d1205 | 21359 | */ |
b99bd4ef | 21360 | |
c19d1205 | 21361 | const char * md_shortopts = "m:k"; |
b99bd4ef | 21362 | |
c19d1205 ZW |
21363 | #ifdef ARM_BI_ENDIAN |
21364 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
21365 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 21366 | #else |
c19d1205 ZW |
21367 | #if TARGET_BYTES_BIG_ENDIAN |
21368 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 21369 | #else |
c19d1205 ZW |
21370 | #define OPTION_EL (OPTION_MD_BASE + 1) |
21371 | #endif | |
b99bd4ef | 21372 | #endif |
845b51d6 | 21373 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 21374 | |
c19d1205 | 21375 | struct option md_longopts[] = |
b99bd4ef | 21376 | { |
c19d1205 ZW |
21377 | #ifdef OPTION_EB |
21378 | {"EB", no_argument, NULL, OPTION_EB}, | |
21379 | #endif | |
21380 | #ifdef OPTION_EL | |
21381 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 21382 | #endif |
845b51d6 | 21383 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
21384 | {NULL, no_argument, NULL, 0} |
21385 | }; | |
b99bd4ef | 21386 | |
c19d1205 | 21387 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 21388 | |
c19d1205 | 21389 | struct arm_option_table |
b99bd4ef | 21390 | { |
c19d1205 ZW |
21391 | char *option; /* Option name to match. */ |
21392 | char *help; /* Help information. */ | |
21393 | int *var; /* Variable to change. */ | |
21394 | int value; /* What to change it to. */ | |
21395 | char *deprecated; /* If non-null, print this message. */ | |
21396 | }; | |
b99bd4ef | 21397 | |
c19d1205 ZW |
21398 | struct arm_option_table arm_opts[] = |
21399 | { | |
21400 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
21401 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
21402 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
21403 | &support_interwork, 1, NULL}, | |
21404 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
21405 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
21406 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
21407 | 1, NULL}, | |
21408 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
21409 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
21410 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
21411 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
21412 | NULL}, | |
b99bd4ef | 21413 | |
c19d1205 ZW |
21414 | /* These are recognized by the assembler, but have no affect on code. */ |
21415 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
21416 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
21417 | |
21418 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
21419 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
21420 | &warn_on_deprecated, 0, NULL}, | |
e74cfd16 PB |
21421 | {NULL, NULL, NULL, 0, NULL} |
21422 | }; | |
21423 | ||
21424 | struct arm_legacy_option_table | |
21425 | { | |
21426 | char *option; /* Option name to match. */ | |
21427 | const arm_feature_set **var; /* Variable to change. */ | |
21428 | const arm_feature_set value; /* What to change it to. */ | |
21429 | char *deprecated; /* If non-null, print this message. */ | |
21430 | }; | |
b99bd4ef | 21431 | |
e74cfd16 PB |
21432 | const struct arm_legacy_option_table arm_legacy_opts[] = |
21433 | { | |
c19d1205 ZW |
21434 | /* DON'T add any new processors to this list -- we want the whole list |
21435 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
21436 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
21437 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
21438 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21439 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21440 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21441 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21442 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21443 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21444 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21445 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21446 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21447 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21448 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21449 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21450 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21451 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21452 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21453 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21454 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21455 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21456 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21457 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21458 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21459 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21460 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21461 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21462 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21463 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21464 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21465 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21466 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21467 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21468 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21469 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21470 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21471 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21472 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21473 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21474 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21475 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21476 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21477 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21478 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21479 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21480 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21481 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21482 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21483 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21484 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21485 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21486 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21487 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21488 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21489 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21490 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21491 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21492 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21493 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21494 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21495 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21496 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21497 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21498 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21499 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21500 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21501 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21502 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21503 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21504 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
21505 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 21506 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 21507 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21508 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 21509 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21510 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
21511 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
21512 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
21513 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 21514 | |
c19d1205 | 21515 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21516 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
21517 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
21518 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21519 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21520 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21521 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21522 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21523 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21524 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21525 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21526 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21527 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21528 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21529 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21530 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21531 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21532 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
21533 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 21534 | |
c19d1205 | 21535 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21536 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
21537 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
21538 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
21539 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 21540 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 21541 | |
e74cfd16 | 21542 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 21543 | }; |
7ed4c4c5 | 21544 | |
c19d1205 | 21545 | struct arm_cpu_option_table |
7ed4c4c5 | 21546 | { |
c19d1205 | 21547 | char *name; |
e74cfd16 | 21548 | const arm_feature_set value; |
c19d1205 ZW |
21549 | /* For some CPUs we assume an FPU unless the user explicitly sets |
21550 | -mfpu=... */ | |
e74cfd16 | 21551 | const arm_feature_set default_fpu; |
ee065d83 PB |
21552 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
21553 | case. */ | |
21554 | const char *canonical_name; | |
c19d1205 | 21555 | }; |
7ed4c4c5 | 21556 | |
c19d1205 ZW |
21557 | /* This list should, at a minimum, contain all the cpu names |
21558 | recognized by GCC. */ | |
e74cfd16 | 21559 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 21560 | { |
ee065d83 PB |
21561 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
21562 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
21563 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
21564 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21565 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21566 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21567 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21568 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21569 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21570 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21571 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21572 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21573 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21574 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21575 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21576 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21577 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21578 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21579 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21580 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21581 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21582 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21583 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21584 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21585 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21586 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21587 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21588 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21589 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21590 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21591 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21592 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21593 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21594 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21595 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21596 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21597 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21598 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21599 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21600 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
21601 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21602 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21603 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21604 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
7fac0536 NC |
21605 | {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, |
21606 | {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
21607 | /* For V5 or later processors we default to using VFP; but the user |
21608 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
21609 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
21610 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21611 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21612 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21613 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
21614 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21615 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
21616 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21617 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21618 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
21619 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21620 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21621 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21622 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21623 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21624 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
21625 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21626 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21627 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21628 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
21629 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
7fac0536 NC |
21630 | {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL}, |
21631 | {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
ee065d83 PB |
21632 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, |
21633 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
21634 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
21635 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
21636 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
21637 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
21638 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
21639 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
21640 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
21641 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
e07e6e58 | 21642 | {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
5287ad62 | 21643 | | FPU_NEON_EXT_V1), |
15290f0a | 21644 | NULL}, |
e07e6e58 | 21645 | {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
15290f0a | 21646 | | FPU_NEON_EXT_V1), |
5287ad62 | 21647 | NULL}, |
62b3e311 PB |
21648 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, |
21649 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, | |
7e806470 | 21650 | {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL}, |
5b19eaba | 21651 | {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL}, |
c19d1205 | 21652 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 21653 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21654 | /* ??? iwmmxt is not a processor. */ |
ee065d83 | 21655 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
2d447fca | 21656 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL}, |
ee065d83 | 21657 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21658 | /* Maverick */ |
e07e6e58 | 21659 | {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
e74cfd16 | 21660 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} |
c19d1205 | 21661 | }; |
7ed4c4c5 | 21662 | |
c19d1205 | 21663 | struct arm_arch_option_table |
7ed4c4c5 | 21664 | { |
c19d1205 | 21665 | char *name; |
e74cfd16 PB |
21666 | const arm_feature_set value; |
21667 | const arm_feature_set default_fpu; | |
c19d1205 | 21668 | }; |
7ed4c4c5 | 21669 | |
c19d1205 ZW |
21670 | /* This list should, at a minimum, contain all the architecture names |
21671 | recognized by GCC. */ | |
e74cfd16 | 21672 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
21673 | { |
21674 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
21675 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
21676 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
21677 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21678 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21679 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
21680 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
21681 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
21682 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
21683 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
21684 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
21685 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
21686 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
21687 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
21688 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
21689 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
21690 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
21691 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21692 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21693 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
21694 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
21695 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
21696 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
21697 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
21698 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
21699 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
7e806470 | 21700 | {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP}, |
62b3e311 | 21701 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
c450d570 PB |
21702 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
21703 | Accept the non-dashed form for compatibility with old toolchains. */ | |
62b3e311 PB |
21704 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21705 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21706 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c450d570 PB |
21707 | {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21708 | {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21709 | {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
21710 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
21711 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
2d447fca | 21712 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP}, |
e74cfd16 | 21713 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 21714 | }; |
7ed4c4c5 | 21715 | |
c19d1205 | 21716 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 21717 | struct arm_option_cpu_value_table |
c19d1205 ZW |
21718 | { |
21719 | char *name; | |
e74cfd16 | 21720 | const arm_feature_set value; |
c19d1205 | 21721 | }; |
7ed4c4c5 | 21722 | |
e74cfd16 | 21723 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 21724 | { |
e74cfd16 PB |
21725 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
21726 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
21727 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
2d447fca | 21728 | {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)}, |
e74cfd16 | 21729 | {NULL, ARM_ARCH_NONE} |
c19d1205 | 21730 | }; |
7ed4c4c5 | 21731 | |
c19d1205 ZW |
21732 | /* This list should, at a minimum, contain all the fpu names |
21733 | recognized by GCC. */ | |
e74cfd16 | 21734 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
21735 | { |
21736 | {"softfpa", FPU_NONE}, | |
21737 | {"fpe", FPU_ARCH_FPE}, | |
21738 | {"fpe2", FPU_ARCH_FPE}, | |
21739 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
21740 | {"fpa", FPU_ARCH_FPA}, | |
21741 | {"fpa10", FPU_ARCH_FPA}, | |
21742 | {"fpa11", FPU_ARCH_FPA}, | |
21743 | {"arm7500fe", FPU_ARCH_FPA}, | |
21744 | {"softvfp", FPU_ARCH_VFP}, | |
21745 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
21746 | {"vfp", FPU_ARCH_VFP_V2}, | |
21747 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 21748 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
21749 | {"vfp10", FPU_ARCH_VFP_V2}, |
21750 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
21751 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
21752 | {"vfpv2", FPU_ARCH_VFP_V2}, |
21753 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
21754 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, | |
c19d1205 ZW |
21755 | {"arm1020t", FPU_ARCH_VFP_V1}, |
21756 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
21757 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
21758 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
21759 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 21760 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 21761 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
e74cfd16 PB |
21762 | {NULL, ARM_ARCH_NONE} |
21763 | }; | |
21764 | ||
21765 | struct arm_option_value_table | |
21766 | { | |
21767 | char *name; | |
21768 | long value; | |
c19d1205 | 21769 | }; |
7ed4c4c5 | 21770 | |
e74cfd16 | 21771 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
21772 | { |
21773 | {"hard", ARM_FLOAT_ABI_HARD}, | |
21774 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
21775 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 21776 | {NULL, 0} |
c19d1205 | 21777 | }; |
7ed4c4c5 | 21778 | |
c19d1205 | 21779 | #ifdef OBJ_ELF |
3a4a14e9 | 21780 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 21781 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
21782 | { |
21783 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
21784 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 21785 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 21786 | {NULL, 0} |
c19d1205 ZW |
21787 | }; |
21788 | #endif | |
7ed4c4c5 | 21789 | |
c19d1205 ZW |
21790 | struct arm_long_option_table |
21791 | { | |
21792 | char * option; /* Substring to match. */ | |
21793 | char * help; /* Help information. */ | |
21794 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
21795 | char * deprecated; /* If non-null, print this message. */ | |
21796 | }; | |
7ed4c4c5 | 21797 | |
c921be7d | 21798 | static bfd_boolean |
e74cfd16 | 21799 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 21800 | { |
e74cfd16 PB |
21801 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
21802 | ||
21803 | /* Copy the feature set, so that we can modify it. */ | |
21804 | *ext_set = **opt_p; | |
21805 | *opt_p = ext_set; | |
21806 | ||
c19d1205 | 21807 | while (str != NULL && *str != 0) |
7ed4c4c5 | 21808 | { |
e74cfd16 | 21809 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
21810 | char * ext; |
21811 | int optlen; | |
7ed4c4c5 | 21812 | |
c19d1205 ZW |
21813 | if (*str != '+') |
21814 | { | |
21815 | as_bad (_("invalid architectural extension")); | |
c921be7d | 21816 | return FALSE; |
c19d1205 | 21817 | } |
7ed4c4c5 | 21818 | |
c19d1205 ZW |
21819 | str++; |
21820 | ext = strchr (str, '+'); | |
7ed4c4c5 | 21821 | |
c19d1205 ZW |
21822 | if (ext != NULL) |
21823 | optlen = ext - str; | |
21824 | else | |
21825 | optlen = strlen (str); | |
7ed4c4c5 | 21826 | |
c19d1205 ZW |
21827 | if (optlen == 0) |
21828 | { | |
21829 | as_bad (_("missing architectural extension")); | |
c921be7d | 21830 | return FALSE; |
c19d1205 | 21831 | } |
7ed4c4c5 | 21832 | |
c19d1205 ZW |
21833 | for (opt = arm_extensions; opt->name != NULL; opt++) |
21834 | if (strncmp (opt->name, str, optlen) == 0) | |
21835 | { | |
e74cfd16 | 21836 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
21837 | break; |
21838 | } | |
7ed4c4c5 | 21839 | |
c19d1205 ZW |
21840 | if (opt->name == NULL) |
21841 | { | |
5f4273c7 | 21842 | as_bad (_("unknown architectural extension `%s'"), str); |
c921be7d | 21843 | return FALSE; |
c19d1205 | 21844 | } |
7ed4c4c5 | 21845 | |
c19d1205 ZW |
21846 | str = ext; |
21847 | }; | |
7ed4c4c5 | 21848 | |
c921be7d | 21849 | return TRUE; |
c19d1205 | 21850 | } |
7ed4c4c5 | 21851 | |
c921be7d | 21852 | static bfd_boolean |
c19d1205 | 21853 | arm_parse_cpu (char * str) |
7ed4c4c5 | 21854 | { |
e74cfd16 | 21855 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
21856 | char * ext = strchr (str, '+'); |
21857 | int optlen; | |
7ed4c4c5 | 21858 | |
c19d1205 ZW |
21859 | if (ext != NULL) |
21860 | optlen = ext - str; | |
7ed4c4c5 | 21861 | else |
c19d1205 | 21862 | optlen = strlen (str); |
7ed4c4c5 | 21863 | |
c19d1205 | 21864 | if (optlen == 0) |
7ed4c4c5 | 21865 | { |
c19d1205 | 21866 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 21867 | return FALSE; |
7ed4c4c5 NC |
21868 | } |
21869 | ||
c19d1205 ZW |
21870 | for (opt = arm_cpus; opt->name != NULL; opt++) |
21871 | if (strncmp (opt->name, str, optlen) == 0) | |
21872 | { | |
e74cfd16 PB |
21873 | mcpu_cpu_opt = &opt->value; |
21874 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 21875 | if (opt->canonical_name) |
5f4273c7 | 21876 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
21877 | else |
21878 | { | |
21879 | int i; | |
c921be7d | 21880 | |
ee065d83 PB |
21881 | for (i = 0; i < optlen; i++) |
21882 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
21883 | selected_cpu_name[i] = 0; | |
21884 | } | |
7ed4c4c5 | 21885 | |
c19d1205 ZW |
21886 | if (ext != NULL) |
21887 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 21888 | |
c921be7d | 21889 | return TRUE; |
c19d1205 | 21890 | } |
7ed4c4c5 | 21891 | |
c19d1205 | 21892 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 21893 | return FALSE; |
7ed4c4c5 NC |
21894 | } |
21895 | ||
c921be7d | 21896 | static bfd_boolean |
c19d1205 | 21897 | arm_parse_arch (char * str) |
7ed4c4c5 | 21898 | { |
e74cfd16 | 21899 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
21900 | char *ext = strchr (str, '+'); |
21901 | int optlen; | |
7ed4c4c5 | 21902 | |
c19d1205 ZW |
21903 | if (ext != NULL) |
21904 | optlen = ext - str; | |
7ed4c4c5 | 21905 | else |
c19d1205 | 21906 | optlen = strlen (str); |
7ed4c4c5 | 21907 | |
c19d1205 | 21908 | if (optlen == 0) |
7ed4c4c5 | 21909 | { |
c19d1205 | 21910 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 21911 | return FALSE; |
7ed4c4c5 NC |
21912 | } |
21913 | ||
c19d1205 ZW |
21914 | for (opt = arm_archs; opt->name != NULL; opt++) |
21915 | if (streq (opt->name, str)) | |
21916 | { | |
e74cfd16 PB |
21917 | march_cpu_opt = &opt->value; |
21918 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 21919 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 21920 | |
c19d1205 ZW |
21921 | if (ext != NULL) |
21922 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 21923 | |
c921be7d | 21924 | return TRUE; |
c19d1205 ZW |
21925 | } |
21926 | ||
21927 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 21928 | return FALSE; |
7ed4c4c5 | 21929 | } |
eb043451 | 21930 | |
c921be7d | 21931 | static bfd_boolean |
c19d1205 ZW |
21932 | arm_parse_fpu (char * str) |
21933 | { | |
e74cfd16 | 21934 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 21935 | |
c19d1205 ZW |
21936 | for (opt = arm_fpus; opt->name != NULL; opt++) |
21937 | if (streq (opt->name, str)) | |
21938 | { | |
e74cfd16 | 21939 | mfpu_opt = &opt->value; |
c921be7d | 21940 | return TRUE; |
c19d1205 | 21941 | } |
b99bd4ef | 21942 | |
c19d1205 | 21943 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 21944 | return FALSE; |
c19d1205 ZW |
21945 | } |
21946 | ||
c921be7d | 21947 | static bfd_boolean |
c19d1205 | 21948 | arm_parse_float_abi (char * str) |
b99bd4ef | 21949 | { |
e74cfd16 | 21950 | const struct arm_option_value_table * opt; |
b99bd4ef | 21951 | |
c19d1205 ZW |
21952 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
21953 | if (streq (opt->name, str)) | |
21954 | { | |
21955 | mfloat_abi_opt = opt->value; | |
c921be7d | 21956 | return TRUE; |
c19d1205 | 21957 | } |
cc8a6dd0 | 21958 | |
c19d1205 | 21959 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 21960 | return FALSE; |
c19d1205 | 21961 | } |
b99bd4ef | 21962 | |
c19d1205 | 21963 | #ifdef OBJ_ELF |
c921be7d | 21964 | static bfd_boolean |
c19d1205 ZW |
21965 | arm_parse_eabi (char * str) |
21966 | { | |
e74cfd16 | 21967 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 21968 | |
c19d1205 ZW |
21969 | for (opt = arm_eabis; opt->name != NULL; opt++) |
21970 | if (streq (opt->name, str)) | |
21971 | { | |
21972 | meabi_flags = opt->value; | |
c921be7d | 21973 | return TRUE; |
c19d1205 ZW |
21974 | } |
21975 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 21976 | return FALSE; |
c19d1205 ZW |
21977 | } |
21978 | #endif | |
cc8a6dd0 | 21979 | |
c921be7d | 21980 | static bfd_boolean |
e07e6e58 NC |
21981 | arm_parse_it_mode (char * str) |
21982 | { | |
c921be7d | 21983 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
21984 | |
21985 | if (streq ("arm", str)) | |
21986 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
21987 | else if (streq ("thumb", str)) | |
21988 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
21989 | else if (streq ("always", str)) | |
21990 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
21991 | else if (streq ("never", str)) | |
21992 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
21993 | else | |
21994 | { | |
21995 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
21996 | "arm, thumb, always, or never."), str); | |
c921be7d | 21997 | ret = FALSE; |
e07e6e58 NC |
21998 | } |
21999 | ||
22000 | return ret; | |
22001 | } | |
22002 | ||
c19d1205 ZW |
22003 | struct arm_long_option_table arm_long_opts[] = |
22004 | { | |
22005 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
22006 | arm_parse_cpu, NULL}, | |
22007 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
22008 | arm_parse_arch, NULL}, | |
22009 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
22010 | arm_parse_fpu, NULL}, | |
22011 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
22012 | arm_parse_float_abi, NULL}, | |
22013 | #ifdef OBJ_ELF | |
7fac0536 | 22014 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
22015 | arm_parse_eabi, NULL}, |
22016 | #endif | |
e07e6e58 NC |
22017 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
22018 | arm_parse_it_mode, NULL}, | |
c19d1205 ZW |
22019 | {NULL, NULL, 0, NULL} |
22020 | }; | |
cc8a6dd0 | 22021 | |
c19d1205 ZW |
22022 | int |
22023 | md_parse_option (int c, char * arg) | |
22024 | { | |
22025 | struct arm_option_table *opt; | |
e74cfd16 | 22026 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 22027 | struct arm_long_option_table *lopt; |
b99bd4ef | 22028 | |
c19d1205 | 22029 | switch (c) |
b99bd4ef | 22030 | { |
c19d1205 ZW |
22031 | #ifdef OPTION_EB |
22032 | case OPTION_EB: | |
22033 | target_big_endian = 1; | |
22034 | break; | |
22035 | #endif | |
cc8a6dd0 | 22036 | |
c19d1205 ZW |
22037 | #ifdef OPTION_EL |
22038 | case OPTION_EL: | |
22039 | target_big_endian = 0; | |
22040 | break; | |
22041 | #endif | |
b99bd4ef | 22042 | |
845b51d6 PB |
22043 | case OPTION_FIX_V4BX: |
22044 | fix_v4bx = TRUE; | |
22045 | break; | |
22046 | ||
c19d1205 ZW |
22047 | case 'a': |
22048 | /* Listing option. Just ignore these, we don't support additional | |
22049 | ones. */ | |
22050 | return 0; | |
b99bd4ef | 22051 | |
c19d1205 ZW |
22052 | default: |
22053 | for (opt = arm_opts; opt->option != NULL; opt++) | |
22054 | { | |
22055 | if (c == opt->option[0] | |
22056 | && ((arg == NULL && opt->option[1] == 0) | |
22057 | || streq (arg, opt->option + 1))) | |
22058 | { | |
c19d1205 | 22059 | /* If the option is deprecated, tell the user. */ |
278df34e | 22060 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
22061 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22062 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 22063 | |
c19d1205 ZW |
22064 | if (opt->var != NULL) |
22065 | *opt->var = opt->value; | |
cc8a6dd0 | 22066 | |
c19d1205 ZW |
22067 | return 1; |
22068 | } | |
22069 | } | |
b99bd4ef | 22070 | |
e74cfd16 PB |
22071 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
22072 | { | |
22073 | if (c == fopt->option[0] | |
22074 | && ((arg == NULL && fopt->option[1] == 0) | |
22075 | || streq (arg, fopt->option + 1))) | |
22076 | { | |
e74cfd16 | 22077 | /* If the option is deprecated, tell the user. */ |
278df34e | 22078 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
22079 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22080 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
22081 | |
22082 | if (fopt->var != NULL) | |
22083 | *fopt->var = &fopt->value; | |
22084 | ||
22085 | return 1; | |
22086 | } | |
22087 | } | |
22088 | ||
c19d1205 ZW |
22089 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22090 | { | |
22091 | /* These options are expected to have an argument. */ | |
22092 | if (c == lopt->option[0] | |
22093 | && arg != NULL | |
22094 | && strncmp (arg, lopt->option + 1, | |
22095 | strlen (lopt->option + 1)) == 0) | |
22096 | { | |
c19d1205 | 22097 | /* If the option is deprecated, tell the user. */ |
278df34e | 22098 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
22099 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
22100 | _(lopt->deprecated)); | |
b99bd4ef | 22101 | |
c19d1205 ZW |
22102 | /* Call the sup-option parser. */ |
22103 | return lopt->func (arg + strlen (lopt->option) - 1); | |
22104 | } | |
22105 | } | |
a737bd4d | 22106 | |
c19d1205 ZW |
22107 | return 0; |
22108 | } | |
a394c00f | 22109 | |
c19d1205 ZW |
22110 | return 1; |
22111 | } | |
a394c00f | 22112 | |
c19d1205 ZW |
22113 | void |
22114 | md_show_usage (FILE * fp) | |
a394c00f | 22115 | { |
c19d1205 ZW |
22116 | struct arm_option_table *opt; |
22117 | struct arm_long_option_table *lopt; | |
a394c00f | 22118 | |
c19d1205 | 22119 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 22120 | |
c19d1205 ZW |
22121 | for (opt = arm_opts; opt->option != NULL; opt++) |
22122 | if (opt->help != NULL) | |
22123 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 22124 | |
c19d1205 ZW |
22125 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22126 | if (lopt->help != NULL) | |
22127 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 22128 | |
c19d1205 ZW |
22129 | #ifdef OPTION_EB |
22130 | fprintf (fp, _("\ | |
22131 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
22132 | #endif |
22133 | ||
c19d1205 ZW |
22134 | #ifdef OPTION_EL |
22135 | fprintf (fp, _("\ | |
22136 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 22137 | #endif |
845b51d6 PB |
22138 | |
22139 | fprintf (fp, _("\ | |
22140 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 22141 | } |
ee065d83 PB |
22142 | |
22143 | ||
22144 | #ifdef OBJ_ELF | |
62b3e311 PB |
22145 | typedef struct |
22146 | { | |
22147 | int val; | |
22148 | arm_feature_set flags; | |
22149 | } cpu_arch_ver_table; | |
22150 | ||
22151 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
22152 | least features first. */ | |
22153 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
22154 | { | |
22155 | {1, ARM_ARCH_V4}, | |
22156 | {2, ARM_ARCH_V4T}, | |
22157 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 22158 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
22159 | {4, ARM_ARCH_V5TE}, |
22160 | {5, ARM_ARCH_V5TEJ}, | |
22161 | {6, ARM_ARCH_V6}, | |
22162 | {7, ARM_ARCH_V6Z}, | |
7e806470 | 22163 | {9, ARM_ARCH_V6K}, |
91e22acd | 22164 | {11, ARM_ARCH_V6M}, |
7e806470 | 22165 | {8, ARM_ARCH_V6T2}, |
62b3e311 PB |
22166 | {10, ARM_ARCH_V7A}, |
22167 | {10, ARM_ARCH_V7R}, | |
22168 | {10, ARM_ARCH_V7M}, | |
22169 | {0, ARM_ARCH_NONE} | |
22170 | }; | |
22171 | ||
ee3c0378 AS |
22172 | /* Set an attribute if it has not already been set by the user. */ |
22173 | static void | |
22174 | aeabi_set_attribute_int (int tag, int value) | |
22175 | { | |
22176 | if (tag < 1 | |
22177 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22178 | || !attributes_set_explicitly[tag]) | |
22179 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
22180 | } | |
22181 | ||
22182 | static void | |
22183 | aeabi_set_attribute_string (int tag, const char *value) | |
22184 | { | |
22185 | if (tag < 1 | |
22186 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22187 | || !attributes_set_explicitly[tag]) | |
22188 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
22189 | } | |
22190 | ||
ee065d83 PB |
22191 | /* Set the public EABI object attributes. */ |
22192 | static void | |
22193 | aeabi_set_public_attributes (void) | |
22194 | { | |
22195 | int arch; | |
e74cfd16 | 22196 | arm_feature_set flags; |
62b3e311 PB |
22197 | arm_feature_set tmp; |
22198 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
22199 | |
22200 | /* Choose the architecture based on the capabilities of the requested cpu | |
22201 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
22202 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
22203 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
22204 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
7a1d4c38 PB |
22205 | /*Allow the user to override the reported architecture. */ |
22206 | if (object_arch) | |
22207 | { | |
22208 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
22209 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
22210 | } | |
22211 | ||
62b3e311 PB |
22212 | tmp = flags; |
22213 | arch = 0; | |
22214 | for (p = cpu_arch_ver; p->val; p++) | |
22215 | { | |
22216 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
22217 | { | |
22218 | arch = p->val; | |
22219 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
22220 | } | |
22221 | } | |
ee065d83 PB |
22222 | |
22223 | /* Tag_CPU_name. */ | |
22224 | if (selected_cpu_name[0]) | |
22225 | { | |
22226 | char *p; | |
22227 | ||
22228 | p = selected_cpu_name; | |
5f4273c7 | 22229 | if (strncmp (p, "armv", 4) == 0) |
ee065d83 PB |
22230 | { |
22231 | int i; | |
5f4273c7 | 22232 | |
ee065d83 PB |
22233 | p += 4; |
22234 | for (i = 0; p[i]; i++) | |
22235 | p[i] = TOUPPER (p[i]); | |
22236 | } | |
ee3c0378 | 22237 | aeabi_set_attribute_string (Tag_CPU_name, p); |
ee065d83 PB |
22238 | } |
22239 | /* Tag_CPU_arch. */ | |
ee3c0378 | 22240 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62b3e311 PB |
22241 | /* Tag_CPU_arch_profile. */ |
22242 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
ee3c0378 | 22243 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A'); |
62b3e311 | 22244 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
ee3c0378 | 22245 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R'); |
7e806470 | 22246 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
ee3c0378 | 22247 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M'); |
ee065d83 | 22248 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
22249 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
22250 | || arch == 0) | |
22251 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
ee065d83 | 22252 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
22253 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
22254 | || arch == 0) | |
22255 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, | |
22256 | ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1); | |
ee065d83 | 22257 | /* Tag_VFP_arch. */ |
ee3c0378 AS |
22258 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) |
22259 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
22260 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3)) | |
22261 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
22262 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) | |
22263 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
22264 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
22265 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) | |
22266 | aeabi_set_attribute_int (Tag_VFP_arch, 1); | |
ee065d83 | 22267 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
22268 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
22269 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
22270 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
22271 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
22272 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ | |
8e79c3df | 22273 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) |
ee3c0378 AS |
22274 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); |
22275 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ | |
8e79c3df | 22276 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16)) |
ee3c0378 | 22277 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
ee065d83 PB |
22278 | } |
22279 | ||
104d59d1 | 22280 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
22281 | void |
22282 | arm_md_end (void) | |
22283 | { | |
ee065d83 PB |
22284 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
22285 | return; | |
22286 | ||
22287 | aeabi_set_public_attributes (); | |
ee065d83 | 22288 | } |
8463be01 | 22289 | #endif /* OBJ_ELF */ |
ee065d83 PB |
22290 | |
22291 | ||
22292 | /* Parse a .cpu directive. */ | |
22293 | ||
22294 | static void | |
22295 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
22296 | { | |
e74cfd16 | 22297 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
22298 | char *name; |
22299 | char saved_char; | |
22300 | ||
22301 | name = input_line_pointer; | |
5f4273c7 | 22302 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22303 | input_line_pointer++; |
22304 | saved_char = *input_line_pointer; | |
22305 | *input_line_pointer = 0; | |
22306 | ||
22307 | /* Skip the first "all" entry. */ | |
22308 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
22309 | if (streq (opt->name, name)) | |
22310 | { | |
e74cfd16 PB |
22311 | mcpu_cpu_opt = &opt->value; |
22312 | selected_cpu = opt->value; | |
ee065d83 | 22313 | if (opt->canonical_name) |
5f4273c7 | 22314 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22315 | else |
22316 | { | |
22317 | int i; | |
22318 | for (i = 0; opt->name[i]; i++) | |
22319 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22320 | selected_cpu_name[i] = 0; | |
22321 | } | |
e74cfd16 | 22322 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22323 | *input_line_pointer = saved_char; |
22324 | demand_empty_rest_of_line (); | |
22325 | return; | |
22326 | } | |
22327 | as_bad (_("unknown cpu `%s'"), name); | |
22328 | *input_line_pointer = saved_char; | |
22329 | ignore_rest_of_line (); | |
22330 | } | |
22331 | ||
22332 | ||
22333 | /* Parse a .arch directive. */ | |
22334 | ||
22335 | static void | |
22336 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
22337 | { | |
e74cfd16 | 22338 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
22339 | char saved_char; |
22340 | char *name; | |
22341 | ||
22342 | name = input_line_pointer; | |
5f4273c7 | 22343 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22344 | input_line_pointer++; |
22345 | saved_char = *input_line_pointer; | |
22346 | *input_line_pointer = 0; | |
22347 | ||
22348 | /* Skip the first "all" entry. */ | |
22349 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22350 | if (streq (opt->name, name)) | |
22351 | { | |
e74cfd16 PB |
22352 | mcpu_cpu_opt = &opt->value; |
22353 | selected_cpu = opt->value; | |
5f4273c7 | 22354 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 22355 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22356 | *input_line_pointer = saved_char; |
22357 | demand_empty_rest_of_line (); | |
22358 | return; | |
22359 | } | |
22360 | ||
22361 | as_bad (_("unknown architecture `%s'\n"), name); | |
22362 | *input_line_pointer = saved_char; | |
22363 | ignore_rest_of_line (); | |
22364 | } | |
22365 | ||
22366 | ||
7a1d4c38 PB |
22367 | /* Parse a .object_arch directive. */ |
22368 | ||
22369 | static void | |
22370 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
22371 | { | |
22372 | const struct arm_arch_option_table *opt; | |
22373 | char saved_char; | |
22374 | char *name; | |
22375 | ||
22376 | name = input_line_pointer; | |
5f4273c7 | 22377 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
22378 | input_line_pointer++; |
22379 | saved_char = *input_line_pointer; | |
22380 | *input_line_pointer = 0; | |
22381 | ||
22382 | /* Skip the first "all" entry. */ | |
22383 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22384 | if (streq (opt->name, name)) | |
22385 | { | |
22386 | object_arch = &opt->value; | |
22387 | *input_line_pointer = saved_char; | |
22388 | demand_empty_rest_of_line (); | |
22389 | return; | |
22390 | } | |
22391 | ||
22392 | as_bad (_("unknown architecture `%s'\n"), name); | |
22393 | *input_line_pointer = saved_char; | |
22394 | ignore_rest_of_line (); | |
22395 | } | |
22396 | ||
ee065d83 PB |
22397 | /* Parse a .fpu directive. */ |
22398 | ||
22399 | static void | |
22400 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
22401 | { | |
e74cfd16 | 22402 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
22403 | char saved_char; |
22404 | char *name; | |
22405 | ||
22406 | name = input_line_pointer; | |
5f4273c7 | 22407 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22408 | input_line_pointer++; |
22409 | saved_char = *input_line_pointer; | |
22410 | *input_line_pointer = 0; | |
5f4273c7 | 22411 | |
ee065d83 PB |
22412 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22413 | if (streq (opt->name, name)) | |
22414 | { | |
e74cfd16 PB |
22415 | mfpu_opt = &opt->value; |
22416 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
22417 | *input_line_pointer = saved_char; |
22418 | demand_empty_rest_of_line (); | |
22419 | return; | |
22420 | } | |
22421 | ||
22422 | as_bad (_("unknown floating point format `%s'\n"), name); | |
22423 | *input_line_pointer = saved_char; | |
22424 | ignore_rest_of_line (); | |
22425 | } | |
ee065d83 | 22426 | |
794ba86a | 22427 | /* Copy symbol information. */ |
f31fef98 | 22428 | |
794ba86a DJ |
22429 | void |
22430 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
22431 | { | |
22432 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
22433 | } | |
e04befd0 | 22434 | |
f31fef98 | 22435 | #ifdef OBJ_ELF |
e04befd0 AS |
22436 | /* Given a symbolic attribute NAME, return the proper integer value. |
22437 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 22438 | |
e04befd0 AS |
22439 | int |
22440 | arm_convert_symbolic_attribute (const char *name) | |
22441 | { | |
f31fef98 NC |
22442 | static const struct |
22443 | { | |
22444 | const char * name; | |
22445 | const int tag; | |
22446 | } | |
22447 | attribute_table[] = | |
22448 | { | |
22449 | /* When you modify this table you should | |
22450 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 22451 | #define T(tag) {#tag, tag} |
f31fef98 NC |
22452 | T (Tag_CPU_raw_name), |
22453 | T (Tag_CPU_name), | |
22454 | T (Tag_CPU_arch), | |
22455 | T (Tag_CPU_arch_profile), | |
22456 | T (Tag_ARM_ISA_use), | |
22457 | T (Tag_THUMB_ISA_use), | |
22458 | T (Tag_VFP_arch), | |
22459 | T (Tag_WMMX_arch), | |
22460 | T (Tag_Advanced_SIMD_arch), | |
22461 | T (Tag_PCS_config), | |
22462 | T (Tag_ABI_PCS_R9_use), | |
22463 | T (Tag_ABI_PCS_RW_data), | |
22464 | T (Tag_ABI_PCS_RO_data), | |
22465 | T (Tag_ABI_PCS_GOT_use), | |
22466 | T (Tag_ABI_PCS_wchar_t), | |
22467 | T (Tag_ABI_FP_rounding), | |
22468 | T (Tag_ABI_FP_denormal), | |
22469 | T (Tag_ABI_FP_exceptions), | |
22470 | T (Tag_ABI_FP_user_exceptions), | |
22471 | T (Tag_ABI_FP_number_model), | |
22472 | T (Tag_ABI_align8_needed), | |
22473 | T (Tag_ABI_align8_preserved), | |
22474 | T (Tag_ABI_enum_size), | |
22475 | T (Tag_ABI_HardFP_use), | |
22476 | T (Tag_ABI_VFP_args), | |
22477 | T (Tag_ABI_WMMX_args), | |
22478 | T (Tag_ABI_optimization_goals), | |
22479 | T (Tag_ABI_FP_optimization_goals), | |
22480 | T (Tag_compatibility), | |
22481 | T (Tag_CPU_unaligned_access), | |
22482 | T (Tag_VFP_HP_extension), | |
22483 | T (Tag_ABI_FP_16bit_format), | |
22484 | T (Tag_nodefaults), | |
22485 | T (Tag_also_compatible_with), | |
22486 | T (Tag_conformance), | |
22487 | T (Tag_T2EE_use), | |
22488 | T (Tag_Virtualization_use), | |
22489 | T (Tag_MPextension_use) | |
e04befd0 | 22490 | #undef T |
f31fef98 | 22491 | }; |
e04befd0 AS |
22492 | unsigned int i; |
22493 | ||
22494 | if (name == NULL) | |
22495 | return -1; | |
22496 | ||
f31fef98 | 22497 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 22498 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
22499 | return attribute_table[i].tag; |
22500 | ||
22501 | return -1; | |
22502 | } | |
267bf995 RR |
22503 | |
22504 | ||
22505 | /* Apply sym value for relocations only in the case that | |
22506 | they are for local symbols and you have the respective | |
22507 | architectural feature for blx and simple switches. */ | |
22508 | int | |
22509 | arm_apply_sym_value (struct fix * fixP) | |
22510 | { | |
22511 | if (fixP->fx_addsy | |
22512 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
22513 | && !S_IS_EXTERNAL (fixP->fx_addsy)) | |
22514 | { | |
22515 | switch (fixP->fx_r_type) | |
22516 | { | |
22517 | case BFD_RELOC_ARM_PCREL_BLX: | |
22518 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
22519 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
22520 | return 1; | |
22521 | break; | |
22522 | ||
22523 | case BFD_RELOC_ARM_PCREL_CALL: | |
22524 | case BFD_RELOC_THUMB_PCREL_BLX: | |
22525 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
22526 | return 1; | |
22527 | break; | |
22528 | ||
22529 | default: | |
22530 | break; | |
22531 | } | |
22532 | ||
22533 | } | |
22534 | return 0; | |
22535 | } | |
f31fef98 | 22536 | #endif /* OBJ_ELF */ |