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 | ||
076d447c PB |
15375 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req) |
15376 | { | |
15377 | /* Implicit require narrow instructions on Thumb-1. This avoids | |
15378 | relaxation accidentally introducing Thumb-2 instructions. */ | |
7e806470 | 15379 | if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23 |
e07e6e58 NC |
15380 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
15381 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
076d447c PB |
15382 | inst.size_req = 2; |
15383 | } | |
15384 | ||
c19d1205 ZW |
15385 | mapping_state (MAP_THUMB); |
15386 | inst.instruction = opcode->tvalue; | |
15387 | ||
15388 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15389 | { |
15390 | /* Prepare the it_insn_type for those encodings that don't set | |
15391 | it. */ | |
15392 | it_fsm_pre_encode (); | |
c19d1205 | 15393 | |
e07e6e58 NC |
15394 | opcode->tencode (); |
15395 | ||
15396 | it_fsm_post_encode (); | |
15397 | } | |
e27ec89e | 15398 | |
0110f2b8 | 15399 | if (!(inst.error || inst.relax)) |
b99bd4ef | 15400 | { |
9c2799c2 | 15401 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
15402 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
15403 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 15404 | { |
c19d1205 | 15405 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
15406 | return; |
15407 | } | |
15408 | } | |
076d447c PB |
15409 | |
15410 | /* Something has gone badly wrong if we try to relax a fixed size | |
15411 | instruction. */ | |
9c2799c2 | 15412 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 15413 | |
e74cfd16 PB |
15414 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15415 | *opcode->tvariant); | |
ee065d83 | 15416 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
708587a4 | 15417 | set those bits when Thumb-2 32-bit instructions are seen. ie. |
7e806470 | 15418 | anything other than bl/blx and v6-M instructions. |
ee065d83 | 15419 | This is overly pessimistic for relaxable instructions. */ |
7e806470 PB |
15420 | if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) |
15421 | || inst.relax) | |
e07e6e58 NC |
15422 | && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) |
15423 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))) | |
e74cfd16 PB |
15424 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
15425 | arm_ext_v6t2); | |
c19d1205 | 15426 | } |
3e9e4fcf | 15427 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 15428 | { |
845b51d6 PB |
15429 | bfd_boolean is_bx; |
15430 | ||
15431 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
15432 | is_bx = (opcode->aencode == do_bx); | |
15433 | ||
c19d1205 | 15434 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
15435 | if (!(is_bx && fix_v4bx) |
15436 | && !(opcode->avariant && | |
15437 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 15438 | { |
c19d1205 ZW |
15439 | as_bad (_("selected processor does not support `%s'"), str); |
15440 | return; | |
b99bd4ef | 15441 | } |
c19d1205 | 15442 | if (inst.size_req) |
b99bd4ef | 15443 | { |
c19d1205 ZW |
15444 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
15445 | return; | |
b99bd4ef NC |
15446 | } |
15447 | ||
c19d1205 ZW |
15448 | mapping_state (MAP_ARM); |
15449 | inst.instruction = opcode->avalue; | |
15450 | if (opcode->tag == OT_unconditionalF) | |
15451 | inst.instruction |= 0xF << 28; | |
15452 | else | |
15453 | inst.instruction |= inst.cond << 28; | |
15454 | inst.size = INSN_SIZE; | |
15455 | if (!parse_operands (p, opcode->operands)) | |
e07e6e58 NC |
15456 | { |
15457 | it_fsm_pre_encode (); | |
15458 | opcode->aencode (); | |
15459 | it_fsm_post_encode (); | |
15460 | } | |
ee065d83 PB |
15461 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
15462 | on a hypothetical non-thumb v5 core. */ | |
845b51d6 | 15463 | if (is_bx) |
e74cfd16 | 15464 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 15465 | else |
e74cfd16 PB |
15466 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
15467 | *opcode->avariant); | |
b99bd4ef | 15468 | } |
3e9e4fcf JB |
15469 | else |
15470 | { | |
15471 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
15472 | "-- `%s'"), str); | |
15473 | return; | |
15474 | } | |
c19d1205 ZW |
15475 | output_inst (str); |
15476 | } | |
b99bd4ef | 15477 | |
e07e6e58 NC |
15478 | static void |
15479 | check_it_blocks_finished (void) | |
15480 | { | |
15481 | #ifdef OBJ_ELF | |
15482 | asection *sect; | |
15483 | ||
15484 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
15485 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
15486 | == MANUAL_IT_BLOCK) | |
15487 | { | |
15488 | as_warn (_("section '%s' finished with an open IT block."), | |
15489 | sect->name); | |
15490 | } | |
15491 | #else | |
15492 | if (now_it.state == MANUAL_IT_BLOCK) | |
15493 | as_warn (_("file finished with an open IT block.")); | |
15494 | #endif | |
15495 | } | |
15496 | ||
c19d1205 ZW |
15497 | /* Various frobbings of labels and their addresses. */ |
15498 | ||
15499 | void | |
15500 | arm_start_line_hook (void) | |
15501 | { | |
15502 | last_label_seen = NULL; | |
b99bd4ef NC |
15503 | } |
15504 | ||
c19d1205 ZW |
15505 | void |
15506 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 15507 | { |
c19d1205 | 15508 | last_label_seen = sym; |
b99bd4ef | 15509 | |
c19d1205 | 15510 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 15511 | |
c19d1205 ZW |
15512 | #if defined OBJ_COFF || defined OBJ_ELF |
15513 | ARM_SET_INTERWORK (sym, support_interwork); | |
15514 | #endif | |
b99bd4ef | 15515 | |
e07e6e58 NC |
15516 | force_automatic_it_block_close (); |
15517 | ||
5f4273c7 | 15518 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
15519 | as Thumb functions. This is because these labels, whilst |
15520 | they exist inside Thumb code, are not the entry points for | |
15521 | possible ARM->Thumb calls. Also, these labels can be used | |
15522 | as part of a computed goto or switch statement. eg gcc | |
15523 | can generate code that looks like this: | |
b99bd4ef | 15524 | |
c19d1205 ZW |
15525 | ldr r2, [pc, .Laaa] |
15526 | lsl r3, r3, #2 | |
15527 | ldr r2, [r3, r2] | |
15528 | mov pc, r2 | |
b99bd4ef | 15529 | |
c19d1205 ZW |
15530 | .Lbbb: .word .Lxxx |
15531 | .Lccc: .word .Lyyy | |
15532 | ..etc... | |
15533 | .Laaa: .word Lbbb | |
b99bd4ef | 15534 | |
c19d1205 ZW |
15535 | The first instruction loads the address of the jump table. |
15536 | The second instruction converts a table index into a byte offset. | |
15537 | The third instruction gets the jump address out of the table. | |
15538 | The fourth instruction performs the jump. | |
b99bd4ef | 15539 | |
c19d1205 ZW |
15540 | If the address stored at .Laaa is that of a symbol which has the |
15541 | Thumb_Func bit set, then the linker will arrange for this address | |
15542 | to have the bottom bit set, which in turn would mean that the | |
15543 | address computation performed by the third instruction would end | |
15544 | up with the bottom bit set. Since the ARM is capable of unaligned | |
15545 | word loads, the instruction would then load the incorrect address | |
15546 | out of the jump table, and chaos would ensue. */ | |
15547 | if (label_is_thumb_function_name | |
15548 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
15549 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 15550 | { |
c19d1205 ZW |
15551 | /* When the address of a Thumb function is taken the bottom |
15552 | bit of that address should be set. This will allow | |
15553 | interworking between Arm and Thumb functions to work | |
15554 | correctly. */ | |
b99bd4ef | 15555 | |
c19d1205 | 15556 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 15557 | |
c19d1205 | 15558 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 15559 | } |
07a53e5c | 15560 | |
07a53e5c | 15561 | dwarf2_emit_label (sym); |
b99bd4ef NC |
15562 | } |
15563 | ||
c921be7d | 15564 | bfd_boolean |
c19d1205 | 15565 | arm_data_in_code (void) |
b99bd4ef | 15566 | { |
c19d1205 | 15567 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 15568 | { |
c19d1205 ZW |
15569 | *input_line_pointer = '/'; |
15570 | input_line_pointer += 5; | |
15571 | *input_line_pointer = 0; | |
c921be7d | 15572 | return TRUE; |
b99bd4ef NC |
15573 | } |
15574 | ||
c921be7d | 15575 | return FALSE; |
b99bd4ef NC |
15576 | } |
15577 | ||
c19d1205 ZW |
15578 | char * |
15579 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 15580 | { |
c19d1205 | 15581 | int len; |
b99bd4ef | 15582 | |
c19d1205 ZW |
15583 | if (thumb_mode && (len = strlen (name)) > 5 |
15584 | && streq (name + len - 5, "/data")) | |
15585 | *(name + len - 5) = 0; | |
b99bd4ef | 15586 | |
c19d1205 | 15587 | return name; |
b99bd4ef | 15588 | } |
c19d1205 ZW |
15589 | \f |
15590 | /* Table of all register names defined by default. The user can | |
15591 | define additional names with .req. Note that all register names | |
15592 | should appear in both upper and lowercase variants. Some registers | |
15593 | also have mixed-case names. */ | |
b99bd4ef | 15594 | |
dcbf9037 | 15595 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 15596 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 15597 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
15598 | #define REGSET(p,t) \ |
15599 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
15600 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
15601 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
15602 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
15603 | #define REGSETH(p,t) \ |
15604 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
15605 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
15606 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
15607 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
15608 | #define REGSET2(p,t) \ | |
15609 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
15610 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
15611 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
15612 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
7ed4c4c5 | 15613 | |
c19d1205 | 15614 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 15615 | { |
c19d1205 ZW |
15616 | /* ARM integer registers. */ |
15617 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 15618 | |
c19d1205 ZW |
15619 | /* ATPCS synonyms. */ |
15620 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
15621 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
15622 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 15623 | |
c19d1205 ZW |
15624 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
15625 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
15626 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 15627 | |
c19d1205 ZW |
15628 | /* Well-known aliases. */ |
15629 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
15630 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
15631 | ||
15632 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
15633 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
15634 | ||
15635 | /* Coprocessor numbers. */ | |
15636 | REGSET(p, CP), REGSET(P, CP), | |
15637 | ||
15638 | /* Coprocessor register numbers. The "cr" variants are for backward | |
15639 | compatibility. */ | |
15640 | REGSET(c, CN), REGSET(C, CN), | |
15641 | REGSET(cr, CN), REGSET(CR, CN), | |
15642 | ||
15643 | /* FPA registers. */ | |
15644 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
15645 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
15646 | ||
15647 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
15648 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
15649 | ||
15650 | /* VFP SP registers. */ | |
5287ad62 JB |
15651 | REGSET(s,VFS), REGSET(S,VFS), |
15652 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
15653 | |
15654 | /* VFP DP Registers. */ | |
5287ad62 JB |
15655 | REGSET(d,VFD), REGSET(D,VFD), |
15656 | /* Extra Neon DP registers. */ | |
15657 | REGSETH(d,VFD), REGSETH(D,VFD), | |
15658 | ||
15659 | /* Neon QP registers. */ | |
15660 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
15661 | |
15662 | /* VFP control registers. */ | |
15663 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
15664 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
15665 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
15666 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
15667 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
15668 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
15669 | |
15670 | /* Maverick DSP coprocessor registers. */ | |
15671 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
15672 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
15673 | ||
15674 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
15675 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
15676 | REGDEF(dspsc,0,DSPSC), | |
15677 | ||
15678 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
15679 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
15680 | REGDEF(DSPSC,0,DSPSC), | |
15681 | ||
15682 | /* iWMMXt data registers - p0, c0-15. */ | |
15683 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
15684 | ||
15685 | /* iWMMXt control registers - p1, c0-3. */ | |
15686 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
15687 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
15688 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
15689 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
15690 | ||
15691 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
15692 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
15693 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
15694 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
15695 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
15696 | ||
15697 | /* XScale accumulator registers. */ | |
15698 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
15699 | }; | |
15700 | #undef REGDEF | |
15701 | #undef REGNUM | |
15702 | #undef REGSET | |
7ed4c4c5 | 15703 | |
c19d1205 ZW |
15704 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
15705 | within psr_required_here. */ | |
15706 | static const struct asm_psr psrs[] = | |
15707 | { | |
15708 | /* Backward compatibility notation. Note that "all" is no longer | |
15709 | truly all possible PSR bits. */ | |
15710 | {"all", PSR_c | PSR_f}, | |
15711 | {"flg", PSR_f}, | |
15712 | {"ctl", PSR_c}, | |
15713 | ||
15714 | /* Individual flags. */ | |
15715 | {"f", PSR_f}, | |
15716 | {"c", PSR_c}, | |
15717 | {"x", PSR_x}, | |
15718 | {"s", PSR_s}, | |
15719 | /* Combinations of flags. */ | |
15720 | {"fs", PSR_f | PSR_s}, | |
15721 | {"fx", PSR_f | PSR_x}, | |
15722 | {"fc", PSR_f | PSR_c}, | |
15723 | {"sf", PSR_s | PSR_f}, | |
15724 | {"sx", PSR_s | PSR_x}, | |
15725 | {"sc", PSR_s | PSR_c}, | |
15726 | {"xf", PSR_x | PSR_f}, | |
15727 | {"xs", PSR_x | PSR_s}, | |
15728 | {"xc", PSR_x | PSR_c}, | |
15729 | {"cf", PSR_c | PSR_f}, | |
15730 | {"cs", PSR_c | PSR_s}, | |
15731 | {"cx", PSR_c | PSR_x}, | |
15732 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
15733 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
15734 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
15735 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
15736 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
15737 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
15738 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
15739 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
15740 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
15741 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
15742 | {"scf", PSR_s | PSR_c | PSR_f}, | |
15743 | {"scx", PSR_s | PSR_c | PSR_x}, | |
15744 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
15745 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
15746 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
15747 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
15748 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
15749 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
15750 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
15751 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
15752 | {"csf", PSR_c | PSR_s | PSR_f}, | |
15753 | {"csx", PSR_c | PSR_s | PSR_x}, | |
15754 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
15755 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
15756 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
15757 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
15758 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
15759 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
15760 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
15761 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
15762 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
15763 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
15764 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
15765 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
15766 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
15767 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
15768 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
15769 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
15770 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
15771 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
15772 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
15773 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
15774 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
15775 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
15776 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
15777 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
15778 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
15779 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
15780 | }; | |
15781 | ||
62b3e311 PB |
15782 | /* Table of V7M psr names. */ |
15783 | static const struct asm_psr v7m_psrs[] = | |
15784 | { | |
2b744c99 PB |
15785 | {"apsr", 0 }, {"APSR", 0 }, |
15786 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
15787 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
15788 | {"psr", 3 }, {"PSR", 3 }, | |
15789 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
15790 | {"ipsr", 5 }, {"IPSR", 5 }, | |
15791 | {"epsr", 6 }, {"EPSR", 6 }, | |
15792 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
15793 | {"msp", 8 }, {"MSP", 8 }, | |
15794 | {"psp", 9 }, {"PSP", 9 }, | |
15795 | {"primask", 16}, {"PRIMASK", 16}, | |
15796 | {"basepri", 17}, {"BASEPRI", 17}, | |
15797 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, | |
15798 | {"faultmask", 19}, {"FAULTMASK", 19}, | |
15799 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
15800 | }; |
15801 | ||
c19d1205 ZW |
15802 | /* Table of all shift-in-operand names. */ |
15803 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 15804 | { |
c19d1205 ZW |
15805 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
15806 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
15807 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
15808 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
15809 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
15810 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
15811 | }; | |
b99bd4ef | 15812 | |
c19d1205 ZW |
15813 | /* Table of all explicit relocation names. */ |
15814 | #ifdef OBJ_ELF | |
15815 | static struct reloc_entry reloc_names[] = | |
15816 | { | |
15817 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
15818 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
15819 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
15820 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
15821 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
15822 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
15823 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
15824 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
15825 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
15826 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
15827 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
15828 | }; | |
15829 | #endif | |
b99bd4ef | 15830 | |
c19d1205 ZW |
15831 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
15832 | static const struct asm_cond conds[] = | |
15833 | { | |
15834 | {"eq", 0x0}, | |
15835 | {"ne", 0x1}, | |
15836 | {"cs", 0x2}, {"hs", 0x2}, | |
15837 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
15838 | {"mi", 0x4}, | |
15839 | {"pl", 0x5}, | |
15840 | {"vs", 0x6}, | |
15841 | {"vc", 0x7}, | |
15842 | {"hi", 0x8}, | |
15843 | {"ls", 0x9}, | |
15844 | {"ge", 0xa}, | |
15845 | {"lt", 0xb}, | |
15846 | {"gt", 0xc}, | |
15847 | {"le", 0xd}, | |
15848 | {"al", 0xe} | |
15849 | }; | |
bfae80f2 | 15850 | |
62b3e311 PB |
15851 | static struct asm_barrier_opt barrier_opt_names[] = |
15852 | { | |
15853 | { "sy", 0xf }, | |
15854 | { "un", 0x7 }, | |
15855 | { "st", 0xe }, | |
15856 | { "unst", 0x6 } | |
15857 | }; | |
15858 | ||
c19d1205 ZW |
15859 | /* Table of ARM-format instructions. */ |
15860 | ||
15861 | /* Macros for gluing together operand strings. N.B. In all cases | |
15862 | other than OPS0, the trailing OP_stop comes from default | |
15863 | zero-initialization of the unspecified elements of the array. */ | |
15864 | #define OPS0() { OP_stop, } | |
15865 | #define OPS1(a) { OP_##a, } | |
15866 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
15867 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
15868 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
15869 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
15870 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
15871 | ||
15872 | /* These macros abstract out the exact format of the mnemonic table and | |
15873 | save some repeated characters. */ | |
15874 | ||
15875 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
15876 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
15877 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 15878 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15879 | |
15880 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
15881 | a T_MNEM_xyz enumerator. */ | |
15882 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 15883 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 15884 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15885 | TxCE (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
c19d1205 ZW |
15886 | |
15887 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
15888 | infix after the third character. */ | |
15889 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
15890 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 15891 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e KH |
15892 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
15893 | { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ | |
15894 | THUMB_VARIANT, do_##ae, do_##te } | |
c19d1205 | 15895 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15896 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 15897 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15898 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 15899 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15900 | TxC3 (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
088fa78e | 15901 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 15902 | TxC3w (mnem, aop, T_MNEM_##top, nops, ops, ae, te) |
c19d1205 ZW |
15903 | |
15904 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
15905 | appear in the condition table. */ | |
15906 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
e07e6e58 | 15907 | { #m1 #m2 #m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \ |
1887dd22 | 15908 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15909 | |
15910 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
15911 | TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \ |
15912 | TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \ | |
15913 | TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \ | |
15914 | TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \ | |
15915 | TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \ | |
15916 | TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \ | |
15917 | TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \ | |
15918 | TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \ | |
15919 | TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \ | |
15920 | TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \ | |
15921 | TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \ | |
15922 | TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \ | |
15923 | TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \ | |
15924 | TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \ | |
15925 | TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \ | |
15926 | TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \ | |
15927 | TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \ | |
15928 | TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \ | |
15929 | TxCM_ (m1, al, m2, op, top, nops, ops, ae, te) | |
c19d1205 ZW |
15930 | |
15931 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
e07e6e58 NC |
15932 | TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te) |
15933 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
15934 | TxCM (m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
c19d1205 ZW |
15935 | |
15936 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
15937 | field is still 0xE. Many of the Thumb variants can be executed |
15938 | conditionally, so this is checked separately. */ | |
c19d1205 ZW |
15939 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
15940 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 15941 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15942 | |
15943 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
15944 | condition code field. */ | |
15945 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
15946 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 15947 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
15948 | |
15949 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
15950 | #define CE(mnem, op, nops, ops, ae) \ |
15951 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
15952 | ||
15953 | #define C3(mnem, op, nops, ops, ae) \ | |
15954 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
15955 | ||
e3cb604e PB |
15956 | /* Legacy mnemonics that always have conditional infix after the third |
15957 | character. */ | |
15958 | #define CL(mnem, op, nops, ops, ae) \ | |
15959 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
15960 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
15961 | ||
8f06b2d8 PB |
15962 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
15963 | #define cCE(mnem, op, nops, ops, ae) \ | |
15964 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
15965 | ||
e3cb604e PB |
15966 | /* Legacy coprocessor instructions where conditional infix and conditional |
15967 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
15968 | not just the potentially ambiguous ones. */ | |
15969 | #define cCL(mnem, op, nops, ops, ae) \ | |
15970 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
15971 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
15972 | ||
15973 | /* Coprocessor, takes either a suffix or a position-3 infix | |
15974 | (for an FPA corner case). */ | |
15975 | #define C3E(mnem, op, nops, ops, ae) \ | |
15976 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
15977 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 15978 | |
6a86118a NC |
15979 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
15980 | { #m1 #m2 #m3, OPS##nops ops, \ | |
e07e6e58 | 15981 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \ |
6a86118a NC |
15982 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
15983 | ||
15984 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
15985 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
15986 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
15987 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
15988 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
15989 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
15990 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
15991 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
15992 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
15993 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
15994 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
15995 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
15996 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
15997 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
15998 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
15999 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
16000 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
16001 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
16002 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
16003 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
16004 | |
16005 | #define UE(mnem, op, nops, ops, ae) \ | |
16006 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16007 | ||
16008 | #define UF(mnem, op, nops, ops, ae) \ | |
16009 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
16010 | ||
5287ad62 JB |
16011 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
16012 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
16013 | use the same encoding function for each. */ | |
16014 | #define NUF(mnem, op, nops, ops, enc) \ | |
16015 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
16016 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16017 | ||
16018 | /* Neon data processing, version which indirects through neon_enc_tab for | |
16019 | the various overloaded versions of opcodes. */ | |
16020 | #define nUF(mnem, op, nops, ops, enc) \ | |
16021 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \ | |
16022 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
16023 | ||
16024 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
16025 | version. */ | |
037e8744 JB |
16026 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
16027 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
16028 | THUMB_VARIANT, do_##enc, do_##enc } |
16029 | ||
037e8744 | 16030 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 16031 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
16032 | |
16033 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 16034 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 16035 | |
5287ad62 | 16036 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 JB |
16037 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
16038 | { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \ | |
5287ad62 JB |
16039 | ARM_VARIANT, 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 | |
c19d1205 ZW |
16047 | #define do_0 0 |
16048 | ||
16049 | /* Thumb-only, unconditional. */ | |
e07e6e58 | 16050 | #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te) |
c19d1205 | 16051 | |
c19d1205 | 16052 | static const struct asm_opcode insns[] = |
bfae80f2 | 16053 | { |
e74cfd16 PB |
16054 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
16055 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
16056 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
16057 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
16058 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
16059 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
16060 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
16061 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
4962c51a MS |
16062 | tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub), |
16063 | tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
c19d1205 ZW |
16064 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), |
16065 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16066 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
16067 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
16068 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
16069 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
16070 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
16071 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
16072 | ||
16073 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
16074 | for setting PSR flag bits. They are obsolete in V6 and do not | |
16075 | have Thumb equivalents. */ | |
16076 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
088fa78e | 16077 | tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16078 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 | 16079 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
088fa78e | 16080 | tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
e3cb604e | 16081 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 | 16082 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 16083 | tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16084 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
16085 | |
16086 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
16087 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
16088 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
16089 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
16090 | ||
4962c51a MS |
16091 | tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), |
16092 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16093 | tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
16094 | tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
c19d1205 | 16095 | |
f5208ef2 | 16096 | tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
16097 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16098 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
f5208ef2 | 16099 | tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
16100 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16101 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
16102 | ||
16103 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
c16d2bf0 | 16104 | TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi), |
0110f2b8 | 16105 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 16106 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 16107 | |
c19d1205 | 16108 | /* Pseudo ops. */ |
e9f89963 | 16109 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
16110 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
16111 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
16112 | |
16113 | /* Thumb-compatibility pseudo ops. */ | |
16114 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
16115 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
16116 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
16117 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
16118 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 16119 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
16120 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
16121 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
16122 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
16123 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
16124 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
16125 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
16126 | ||
16a4cf17 PB |
16127 | /* These may simplify to neg. */ |
16128 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16129 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16130 | ||
c921be7d NC |
16131 | #undef THUMB_VARIANT |
16132 | #define THUMB_VARIANT & arm_ext_v6 | |
16133 | ||
2fc8bdac | 16134 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
16135 | |
16136 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
16137 | #undef THUMB_VARIANT |
16138 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16139 | ||
c19d1205 | 16140 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
088fa78e | 16141 | TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
e3cb604e | 16142 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
16143 | |
16144 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
3e94bf1a | 16145 | TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 16146 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), |
3e94bf1a | 16147 | TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 16148 | |
9c3c69f2 PB |
16149 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16150 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 16151 | |
9c3c69f2 PB |
16152 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
16153 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
16154 | |
16155 | /* V1 instructions with no Thumb analogue at all. */ | |
16156 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
16157 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
16158 | ||
16159 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
16160 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
16161 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
16162 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
16163 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
16164 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
16165 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
16166 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
16167 | ||
c921be7d NC |
16168 | #undef ARM_VARIANT |
16169 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
16170 | #undef THUMB_VARIANT | |
16171 | #define THUMB_VARIANT & arm_ext_v4t | |
16172 | ||
c19d1205 ZW |
16173 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
16174 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
16175 | ||
c921be7d NC |
16176 | #undef THUMB_VARIANT |
16177 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16178 | ||
c19d1205 ZW |
16179 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
16180 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
16181 | ||
16182 | /* Generic coprocessor instructions. */ | |
16183 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
4962c51a MS |
16184 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
16185 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16186 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16187 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
16188 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), |
16189 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16190 | ||
c921be7d NC |
16191 | #undef ARM_VARIANT |
16192 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
16193 | ||
c19d1205 ZW |
16194 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
16195 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
16196 | ||
c921be7d NC |
16197 | #undef ARM_VARIANT |
16198 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
16199 | #undef THUMB_VARIANT | |
16200 | #define THUMB_VARIANT & arm_ext_msr | |
16201 | ||
037e8744 JB |
16202 | TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs), |
16203 | TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr), | |
c19d1205 | 16204 | |
c921be7d NC |
16205 | #undef ARM_VARIANT |
16206 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
16207 | #undef THUMB_VARIANT | |
16208 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16209 | ||
c19d1205 ZW |
16210 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
16211 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16212 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16213 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16214 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16215 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16216 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
16217 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
16218 | ||
c921be7d NC |
16219 | #undef ARM_VARIANT |
16220 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
16221 | #undef THUMB_VARIANT | |
16222 | #define THUMB_VARIANT & arm_ext_v4t | |
16223 | ||
4962c51a MS |
16224 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), |
16225 | tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16226 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16227 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16228 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
16229 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 16230 | |
c921be7d NC |
16231 | #undef ARM_VARIANT |
16232 | #define ARM_VARIANT & arm_ext_v4t_5 | |
16233 | ||
c19d1205 ZW |
16234 | /* ARM Architecture 4T. */ |
16235 | /* Note: bx (and blx) are required on V5, even if the processor does | |
16236 | not support Thumb. */ | |
16237 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
16238 | ||
c921be7d NC |
16239 | #undef ARM_VARIANT |
16240 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
16241 | #undef THUMB_VARIANT | |
16242 | #define THUMB_VARIANT & arm_ext_v5t | |
16243 | ||
c19d1205 ZW |
16244 | /* Note: blx has 2 variants; the .value coded here is for |
16245 | BLX(2). Only this variant has conditional execution. */ | |
16246 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
16247 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
16248 | ||
c921be7d NC |
16249 | #undef THUMB_VARIANT |
16250 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16251 | ||
c19d1205 | 16252 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
4962c51a MS |
16253 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), |
16254 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16255 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
16256 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
c19d1205 ZW |
16257 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
16258 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16259 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
16260 | ||
c921be7d NC |
16261 | #undef ARM_VARIANT |
16262 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ | |
16263 | ||
c19d1205 ZW |
16264 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
16265 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16266 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16267 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16268 | ||
16269 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16270 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
16271 | ||
16272 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16273 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16274 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16275 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
16276 | ||
16277 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16278 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16279 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16280 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16281 | ||
16282 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16283 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16284 | ||
087b80de JM |
16285 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), |
16286 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16287 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
16288 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd), | |
c19d1205 | 16289 | |
c921be7d NC |
16290 | #undef ARM_VARIANT |
16291 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ | |
16292 | ||
c19d1205 | 16293 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
79d49516 PB |
16294 | TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), |
16295 | TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 ZW |
16296 | |
16297 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16298 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
16299 | ||
c921be7d NC |
16300 | #undef ARM_VARIANT |
16301 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
16302 | ||
c19d1205 ZW |
16303 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
16304 | ||
c921be7d NC |
16305 | #undef ARM_VARIANT |
16306 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
16307 | #undef THUMB_VARIANT | |
16308 | #define THUMB_VARIANT & arm_ext_v6 | |
16309 | ||
c19d1205 ZW |
16310 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
16311 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
16312 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16313 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16314 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
16315 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16316 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16317 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16318 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16319 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
16320 | ||
c921be7d NC |
16321 | #undef THUMB_VARIANT |
16322 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16323 | ||
c19d1205 | 16324 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
91568d08 | 16325 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), |
c19d1205 ZW |
16326 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
16327 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 PB |
16328 | |
16329 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
16330 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
16331 | ||
16332 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
c921be7d NC |
16333 | #undef THUMB_VARIANT |
16334 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16335 | ||
dfa9f0d5 | 16336 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c19d1205 ZW |
16337 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
16338 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
16339 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16340 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16341 | TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16342 | /* Old name for QASX. */ | |
c19d1205 | 16343 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16344 | TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16345 | /* Old name for QSAX. */ | |
16346 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16347 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16348 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16349 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16350 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16351 | TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16352 | /* Old name for SASX. */ | |
c19d1205 ZW |
16353 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16354 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16355 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16356 | TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16357 | /* Old name for SHASX. */ | |
c19d1205 | 16358 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16359 | TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16360 | /* Old name for SHSAX. */ | |
16361 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16362 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16363 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16364 | TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16365 | /* Old name for SSAX. */ | |
16366 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16367 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16368 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16369 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16370 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16371 | TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16372 | /* Old name for UASX. */ | |
c19d1205 ZW |
16373 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16374 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
16375 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16376 | TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16377 | /* Old name for UHASX. */ | |
c19d1205 | 16378 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16379 | TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16380 | /* Old name for UHSAX. */ | |
16381 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16382 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16383 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16384 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16385 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e JM |
16386 | TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16387 | /* Old name for UQASX. */ | |
c19d1205 | 16388 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16389 | TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16390 | /* Old name for UQSAX. */ | |
16391 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 ZW |
16392 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16393 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
c19d1205 | 16394 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e JM |
16395 | TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
16396 | /* Old name for USAX. */ | |
c19d1205 | 16397 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 16398 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
16399 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), |
16400 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
16401 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
16402 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
16403 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
16404 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
16405 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
16406 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
16407 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16408 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16409 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16410 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
16411 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16412 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16413 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
16414 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 16415 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
16416 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
16417 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16418 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16419 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16420 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16421 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16422 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16423 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
16424 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16425 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16426 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16427 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
16428 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16429 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16430 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16431 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16432 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16433 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
b6702015 PB |
16434 | TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
16435 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), | |
16436 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), | |
16437 | TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs), | |
c19d1205 | 16438 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
c19d1205 ZW |
16439 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), |
16440 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
16441 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
c19d1205 ZW |
16442 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), |
16443 | ||
c921be7d NC |
16444 | #undef ARM_VARIANT |
16445 | #define ARM_VARIANT & arm_ext_v6k | |
16446 | #undef THUMB_VARIANT | |
16447 | #define THUMB_VARIANT & arm_ext_v6k | |
16448 | ||
c19d1205 ZW |
16449 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
16450 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
16451 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
16452 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
16453 | ||
c921be7d NC |
16454 | #undef THUMB_VARIANT |
16455 | #define THUMB_VARIANT & arm_ext_v6_notm | |
16456 | ||
ebdca51a PB |
16457 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), |
16458 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
16459 | ||
c921be7d NC |
16460 | #undef THUMB_VARIANT |
16461 | #define THUMB_VARIANT & arm_ext_v6t2 | |
16462 | ||
c19d1205 ZW |
16463 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
16464 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
c19d1205 ZW |
16465 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), |
16466 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
c19d1205 ZW |
16467 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
16468 | ||
c921be7d NC |
16469 | #undef ARM_VARIANT |
16470 | #define ARM_VARIANT & arm_ext_v6z | |
16471 | ||
3eb17e6b | 16472 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 16473 | |
c921be7d NC |
16474 | #undef ARM_VARIANT |
16475 | #define ARM_VARIANT & arm_ext_v6t2 | |
16476 | ||
c19d1205 ZW |
16477 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
16478 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
16479 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16480 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
16481 | ||
16482 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
b6895b4f PB |
16483 | TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), |
16484 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
401a54cf | 16485 | TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 ZW |
16486 | |
16487 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16488 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16489 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16490 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
16491 | ||
25fe350b MS |
16492 | UT(cbnz, b900, 2, (RR, EXP), t_cbz), |
16493 | UT(cbz, b100, 2, (RR, EXP), t_cbz), | |
c921be7d NC |
16494 | |
16495 | /* ARM does not really have an IT instruction, so always allow it. | |
16496 | The opcode is copied from Thumb in order to allow warnings in | |
16497 | -mimplicit-it=[never | arm] modes. */ | |
16498 | #undef ARM_VARIANT | |
16499 | #define ARM_VARIANT & arm_ext_v1 | |
16500 | ||
e07e6e58 NC |
16501 | TUE(it, bf08, bf08, 1, (COND), it, t_it), |
16502 | TUE(itt, bf0c, bf0c, 1, (COND), it, t_it), | |
16503 | TUE(ite, bf04, bf04, 1, (COND), it, t_it), | |
16504 | TUE(ittt, bf0e, bf0e, 1, (COND), it, t_it), | |
16505 | TUE(itet, bf06, bf06, 1, (COND), it, t_it), | |
16506 | TUE(itte, bf0a, bf0a, 1, (COND), it, t_it), | |
16507 | TUE(itee, bf02, bf02, 1, (COND), it, t_it), | |
16508 | TUE(itttt, bf0f, bf0f, 1, (COND), it, t_it), | |
16509 | TUE(itett, bf07, bf07, 1, (COND), it, t_it), | |
16510 | TUE(ittet, bf0b, bf0b, 1, (COND), it, t_it), | |
16511 | TUE(iteet, bf03, bf03, 1, (COND), it, t_it), | |
16512 | TUE(ittte, bf0d, bf0d, 1, (COND), it, t_it), | |
16513 | TUE(itete, bf05, bf05, 1, (COND), it, t_it), | |
16514 | TUE(ittee, bf09, bf09, 1, (COND), it, t_it), | |
16515 | TUE(iteee, bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 JM |
16516 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
16517 | TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), | |
16518 | TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 16519 | |
92e90b6e | 16520 | /* Thumb2 only instructions. */ |
c921be7d NC |
16521 | #undef ARM_VARIANT |
16522 | #define ARM_VARIANT NULL | |
92e90b6e PB |
16523 | |
16524 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
16525 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
1c444d06 JM |
16526 | TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), |
16527 | TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
92e90b6e PB |
16528 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), |
16529 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
16530 | ||
62b3e311 | 16531 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
c921be7d NC |
16532 | #undef THUMB_VARIANT |
16533 | #define THUMB_VARIANT & arm_ext_div | |
16534 | ||
62b3e311 PB |
16535 | TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), |
16536 | TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
16537 | ||
7e806470 | 16538 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
16539 | #undef ARM_VARIANT |
16540 | #define ARM_VARIANT & arm_ext_barrier | |
16541 | #undef THUMB_VARIANT | |
16542 | #define THUMB_VARIANT & arm_ext_barrier | |
16543 | ||
7e806470 PB |
16544 | TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), |
16545 | TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
16546 | TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
16547 | ||
62b3e311 | 16548 | /* ARM V7 instructions. */ |
c921be7d NC |
16549 | #undef ARM_VARIANT |
16550 | #define ARM_VARIANT & arm_ext_v7 | |
16551 | #undef THUMB_VARIANT | |
16552 | #define THUMB_VARIANT & arm_ext_v7 | |
16553 | ||
62b3e311 PB |
16554 | TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld), |
16555 | TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 16556 | |
c921be7d NC |
16557 | #undef ARM_VARIANT |
16558 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
16559 | ||
8f06b2d8 PB |
16560 | cCE(wfs, e200110, 1, (RR), rd), |
16561 | cCE(rfs, e300110, 1, (RR), rd), | |
16562 | cCE(wfc, e400110, 1, (RR), rd), | |
16563 | cCE(rfc, e500110, 1, (RR), rd), | |
16564 | ||
4962c51a MS |
16565 | cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr), |
16566 | cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16567 | cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16568 | cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e | 16569 | |
4962c51a MS |
16570 | cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr), |
16571 | cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16572 | cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
16573 | cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
e3cb604e PB |
16574 | |
16575 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
16576 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
16577 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
16578 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
16579 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
16580 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
16581 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
16582 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
16583 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
16584 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
16585 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
16586 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
16587 | ||
16588 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
16589 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
16590 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
16591 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
16592 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
16593 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
16594 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
16595 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
16596 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
16597 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
16598 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
16599 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
16600 | ||
16601 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
16602 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
16603 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
16604 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
16605 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
16606 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
16607 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
16608 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
16609 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
16610 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
16611 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
16612 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
16613 | ||
16614 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
16615 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
16616 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
16617 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
16618 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
16619 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
16620 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
16621 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
16622 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
16623 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
16624 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
16625 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
16626 | ||
16627 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
16628 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
16629 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
16630 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
16631 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
16632 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
16633 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
16634 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
16635 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
16636 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
16637 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
16638 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
16639 | ||
16640 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
16641 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
16642 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
16643 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
16644 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
16645 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
16646 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
16647 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
16648 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
16649 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
16650 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
16651 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
16652 | ||
16653 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
16654 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
16655 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
16656 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
16657 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
16658 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
16659 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
16660 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
16661 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
16662 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
16663 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
16664 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
16665 | ||
16666 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
16667 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
16668 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
16669 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
16670 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
16671 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
16672 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
16673 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
16674 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
16675 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
16676 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
16677 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
16678 | ||
16679 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
16680 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
16681 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
16682 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
16683 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
16684 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
16685 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
16686 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
16687 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
16688 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
16689 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
16690 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
16691 | ||
16692 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
16693 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
16694 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
16695 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
16696 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
16697 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
16698 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
16699 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
16700 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
16701 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
16702 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
16703 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
16704 | ||
16705 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
16706 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
16707 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
16708 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
16709 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
16710 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
16711 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
16712 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
16713 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
16714 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
16715 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
16716 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
16717 | ||
16718 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
16719 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
16720 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
16721 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
16722 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
16723 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
16724 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
16725 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
16726 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
16727 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
16728 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
16729 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
16730 | ||
16731 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
16732 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
16733 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
16734 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
16735 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
16736 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
16737 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
16738 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
16739 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
16740 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
16741 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
16742 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
16743 | ||
16744 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
16745 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
16746 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
16747 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
16748 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
16749 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
16750 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
16751 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
16752 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
16753 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
16754 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
16755 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
16756 | ||
16757 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
16758 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
16759 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
16760 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
16761 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
16762 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
16763 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
16764 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
16765 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
16766 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
16767 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
16768 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
16769 | ||
16770 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
16771 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
16772 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
16773 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
16774 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
16775 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
16776 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
16777 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
16778 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
16779 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
16780 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
16781 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
16782 | ||
16783 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16784 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16785 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16786 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16787 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16788 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16789 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16790 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16791 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16792 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16793 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16794 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16795 | ||
16796 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16797 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16798 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16799 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16800 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16801 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16802 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16803 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16804 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16805 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16806 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16807 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16808 | ||
16809 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16810 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16811 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16812 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16813 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16814 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16815 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16816 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16817 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16818 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16819 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16820 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16821 | ||
16822 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16823 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16824 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16825 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16826 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16827 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16828 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16829 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16830 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16831 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16832 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16833 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16834 | ||
16835 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16836 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16837 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16838 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16839 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16840 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16841 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16842 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16843 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16844 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16845 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16846 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16847 | ||
16848 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16849 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16850 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16851 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16852 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16853 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16854 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16855 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16856 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16857 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16858 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16859 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16860 | ||
16861 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16862 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16863 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16864 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16865 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16866 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16867 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16868 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16869 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16870 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16871 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16872 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16873 | ||
16874 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16875 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16876 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16877 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16878 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16879 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16880 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16881 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16882 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16883 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16884 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16885 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16886 | ||
16887 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16888 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16889 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16890 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16891 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16892 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16893 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16894 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16895 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16896 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16897 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16898 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16899 | ||
16900 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16901 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16902 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16903 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16904 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16905 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16906 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16907 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16908 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16909 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16910 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16911 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16912 | ||
16913 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16914 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16915 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16916 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16917 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16918 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16919 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16920 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16921 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16922 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16923 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16924 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16925 | ||
16926 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16927 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16928 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16929 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16930 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16931 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16932 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16933 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16934 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16935 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16936 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16937 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16938 | ||
16939 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16940 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16941 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16942 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16943 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16944 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16945 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16946 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16947 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16948 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16949 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
16950 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
16951 | |
16952 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 16953 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 16954 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
16955 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
16956 | ||
e3cb604e PB |
16957 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
16958 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
16959 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
16960 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
16961 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
16962 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
16963 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
16964 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
16965 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
16966 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
16967 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
16968 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 16969 | |
c19d1205 ZW |
16970 | /* The implementation of the FIX instruction is broken on some |
16971 | assemblers, in that it accepts a precision specifier as well as a | |
16972 | rounding specifier, despite the fact that this is meaningless. | |
16973 | To be more compatible, we accept it as well, though of course it | |
16974 | does not set any bits. */ | |
8f06b2d8 | 16975 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
16976 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
16977 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
16978 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
16979 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
16980 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
16981 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
16982 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
16983 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
16984 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
16985 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
16986 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
16987 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 16988 | |
c19d1205 | 16989 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
16990 | #undef ARM_VARIANT |
16991 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
16992 | ||
8f06b2d8 | 16993 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
16994 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
16995 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 16996 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
16997 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
16998 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 16999 | |
c921be7d NC |
17000 | #undef ARM_VARIANT |
17001 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
17002 | ||
c19d1205 | 17003 | /* Moves and type conversions. */ |
8f06b2d8 PB |
17004 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
17005 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
17006 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
17007 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
17008 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17009 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17010 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17011 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17012 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17013 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17014 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
17015 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
17016 | |
17017 | /* Memory operations. */ | |
4962c51a MS |
17018 | cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
17019 | cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
8f06b2d8 PB |
17020 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), |
17021 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17022 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17023 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17024 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17025 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17026 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17027 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17028 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17029 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
17030 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17031 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
17032 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17033 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
17034 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
17035 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 17036 | |
c19d1205 | 17037 | /* Monadic operations. */ |
8f06b2d8 PB |
17038 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
17039 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
17040 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
17041 | |
17042 | /* Dyadic operations. */ | |
8f06b2d8 PB |
17043 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
17044 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17045 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17046 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17047 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17048 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17049 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17050 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
17051 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 17052 | |
c19d1205 | 17053 | /* Comparisons. */ |
8f06b2d8 PB |
17054 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
17055 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
17056 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
17057 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 17058 | |
c921be7d NC |
17059 | #undef ARM_VARIANT |
17060 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
17061 | ||
c19d1205 | 17062 | /* Moves and type conversions. */ |
5287ad62 | 17063 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
8f06b2d8 PB |
17064 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
17065 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
5287ad62 JB |
17066 | cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd), |
17067 | cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
17068 | cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
17069 | cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
8f06b2d8 PB |
17070 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
17071 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
17072 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17073 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17074 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
17075 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
17076 | |
17077 | /* Memory operations. */ | |
4962c51a MS |
17078 | cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), |
17079 | cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
8f06b2d8 PB |
17080 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), |
17081 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17082 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17083 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17084 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17085 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
17086 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
17087 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 17088 | |
c19d1205 | 17089 | /* Monadic operations. */ |
5287ad62 JB |
17090 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
17091 | cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17092 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
17093 | |
17094 | /* Dyadic operations. */ | |
5287ad62 JB |
17095 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
17096 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17097 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17098 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17099 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17100 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17101 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17102 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
17103 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 17104 | |
c19d1205 | 17105 | /* Comparisons. */ |
5287ad62 JB |
17106 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
17107 | cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd), | |
17108 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
17109 | cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 17110 | |
c921be7d NC |
17111 | #undef ARM_VARIANT |
17112 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
17113 | ||
8f06b2d8 PB |
17114 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
17115 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
5287ad62 JB |
17116 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), |
17117 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
17118 | ||
037e8744 JB |
17119 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
17120 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
17121 | #undef ARM_VARIANT |
17122 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
17123 | #undef THUMB_VARIANT | |
17124 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
17125 | ||
037e8744 JB |
17126 | /* These mnemonics are unique to VFP. */ |
17127 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
17128 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
17129 | nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17130 | nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17131 | nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
17132 | nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17133 | nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp), | |
17134 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), | |
17135 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
17136 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
17137 | ||
17138 | /* Mnemonics shared by Neon and VFP. */ | |
17139 | nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), | |
17140 | nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17141 | nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
17142 | ||
17143 | nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
17144 | nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
17145 | ||
17146 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17147 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
17148 | ||
17149 | NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17150 | NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17151 | NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17152 | NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17153 | NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
17154 | NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
17155 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
17156 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 JB |
17157 | |
17158 | nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt), | |
8e79c3df CM |
17159 | nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb), |
17160 | nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt), | |
f31fef98 | 17161 | |
037e8744 JB |
17162 | |
17163 | /* NOTE: All VMOV encoding is special-cased! */ | |
17164 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
17165 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
17166 | ||
c921be7d NC |
17167 | #undef THUMB_VARIANT |
17168 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
17169 | #undef ARM_VARIANT | |
17170 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
17171 | ||
5287ad62 JB |
17172 | /* Data processing with three registers of the same length. */ |
17173 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
17174 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
17175 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
17176 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17177 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17178 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17179 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17180 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
17181 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
17182 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17183 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17184 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
17185 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
17186 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
17187 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
17188 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
17189 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
17190 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
17191 | /* If not immediate, fall back to neon_dyadic_i64_su. |
17192 | shl_imm should accept I8 I16 I32 I64, | |
17193 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17194 | nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), | |
17195 | nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
17196 | nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
17197 | nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
17198 | /* Logic ops, types optional & ignored. */ | |
17199 | nUF(vand, vand, 2, (RNDQ, NILO), neon_logic), | |
17200 | nUF(vandq, vand, 2, (RNQ, NILO), neon_logic), | |
17201 | nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic), | |
17202 | nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic), | |
17203 | nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic), | |
17204 | nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic), | |
17205 | nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic), | |
17206 | nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic), | |
17207 | nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
17208 | nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
17209 | /* Bitfield ops, untyped. */ | |
17210 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17211 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17212 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17213 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17214 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
17215 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
17216 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
17217 | nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17218 | nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17219 | nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17220 | nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17221 | nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
17222 | nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
17223 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall | |
17224 | back to neon_dyadic_if_su. */ | |
17225 | nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17226 | nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17227 | nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
17228 | nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
17229 | nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17230 | nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
17231 | nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
17232 | nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 17233 | /* Comparison. Type I8 I16 I32 F32. */ |
5287ad62 JB |
17234 | nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
17235 | nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
17236 | /* As above, D registers only. */ | |
17237 | nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
17238 | nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
17239 | /* Int and float variants, signedness unimportant. */ | |
5287ad62 | 17240 | nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
5287ad62 JB |
17241 | nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
17242 | nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
17243 | /* Add/sub take types I8 I16 I32 I64 F32. */ | |
5287ad62 | 17244 | nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
5287ad62 JB |
17245 | nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
17246 | /* vtst takes sizes 8, 16, 32. */ | |
17247 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
17248 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
17249 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
037e8744 | 17250 | nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 JB |
17251 | /* VQD{R}MULH takes S16 S32. */ |
17252 | nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17253 | nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17254 | nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
17255 | nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
17256 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17257 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
17258 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
17259 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
17260 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
17261 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
17262 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
17263 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
17264 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
17265 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17266 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
17267 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
17268 | ||
17269 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 17270 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
17271 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
17272 | ||
17273 | /* Data processing with two registers and a shift amount. */ | |
17274 | /* Right shifts, and variants with rounding. | |
17275 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17276 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17277 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17278 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
17279 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
17280 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17281 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17282 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
17283 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
17284 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
17285 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
17286 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
17287 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
17288 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
17289 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
17290 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
17291 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
17292 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
17293 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
17294 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17295 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
17296 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
17297 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17298 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
17299 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
17300 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17301 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
17302 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
17303 | nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll), | |
17304 | /* CVT with optional immediate for fixed-point variant. */ | |
037e8744 | 17305 | nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 17306 | |
5287ad62 JB |
17307 | nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn), |
17308 | nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn), | |
17309 | ||
17310 | /* Data processing, three registers of different lengths. */ | |
17311 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
17312 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
17313 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17314 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17315 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
17316 | /* If not scalar, fall back to neon_dyadic_long. | |
17317 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
17318 | nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
17319 | nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
17320 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ | |
17321 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17322 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
17323 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
17324 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17325 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17326 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17327 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
17328 | /* Saturating doubling multiplies. Types S16 S32. */ | |
17329 | nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17330 | nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17331 | nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
17332 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types | |
17333 | S16 S32 U16 U32. */ | |
17334 | nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), | |
17335 | ||
17336 | /* Extract. Size 8. */ | |
3b8d421e PB |
17337 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
17338 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
17339 | |
17340 | /* Two registers, miscellaneous. */ | |
17341 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
17342 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
17343 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
17344 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
17345 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
17346 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
17347 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
17348 | /* Vector replicate. Sizes 8 16 32. */ | |
17349 | nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup), | |
17350 | nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
17351 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ | |
17352 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
17353 | /* VMOVN. Types I16 I32 I64. */ | |
17354 | nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn), | |
17355 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ | |
17356 | nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn), | |
17357 | /* VQMOVUN. Types S16 S32 S64. */ | |
17358 | nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun), | |
17359 | /* VZIP / VUZP. Sizes 8 16 32. */ | |
17360 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17361 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
17362 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
17363 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
17364 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
17365 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17366 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17367 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
17368 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
17369 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
17370 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
17371 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
17372 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
17373 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
17374 | /* Reciprocal estimates. Types U32 F32. */ | |
17375 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
17376 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
17377 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
17378 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
17379 | /* VCLS. Types S8 S16 S32. */ | |
17380 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
17381 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
17382 | /* VCLZ. Types I8 I16 I32. */ | |
17383 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
17384 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
17385 | /* VCNT. Size 8. */ | |
17386 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
17387 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
17388 | /* Two address, untyped. */ | |
17389 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
17390 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
17391 | /* VTRN. Sizes 8 16 32. */ | |
17392 | nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn), | |
17393 | nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn), | |
17394 | ||
17395 | /* Table lookup. Size 8. */ | |
17396 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17397 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
17398 | ||
c921be7d NC |
17399 | #undef THUMB_VARIANT |
17400 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
17401 | #undef ARM_VARIANT | |
17402 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
17403 | ||
5287ad62 JB |
17404 | /* Neon element/structure load/store. */ |
17405 | nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17406 | nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17407 | nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17408 | nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17409 | nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17410 | nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17411 | nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17412 | nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
17413 | ||
c921be7d NC |
17414 | #undef THUMB_VARIANT |
17415 | #define THUMB_VARIANT & fpu_vfp_ext_v3 | |
17416 | #undef ARM_VARIANT | |
17417 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
17418 | ||
5287ad62 JB |
17419 | cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const), |
17420 | cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const), | |
17421 | cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17422 | cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17423 | cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17424 | cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17425 | cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17426 | cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17427 | cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17428 | cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17429 | cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17430 | cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17431 | cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17432 | cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
17433 | cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
17434 | cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), | |
17435 | cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
17436 | cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), | |
c19d1205 | 17437 | |
5287ad62 | 17438 | #undef THUMB_VARIANT |
c921be7d NC |
17439 | #undef ARM_VARIANT |
17440 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
17441 | ||
8f06b2d8 PB |
17442 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
17443 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17444 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17445 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17446 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17447 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
17448 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
17449 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 17450 | |
c921be7d NC |
17451 | #undef ARM_VARIANT |
17452 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
17453 | ||
8f06b2d8 PB |
17454 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
17455 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
17456 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
17457 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
17458 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
17459 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
17460 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
17461 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
17462 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
17463 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17464 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17465 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17466 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17467 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17468 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
17469 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17470 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
17471 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
41adaa5c | 17472 | cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd), |
8f06b2d8 PB |
17473 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), |
17474 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17475 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17476 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17477 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17478 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17479 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
17480 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
17481 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
17482 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
41adaa5c | 17483 | cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn), |
8f06b2d8 PB |
17484 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), |
17485 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
17486 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
17487 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
17488 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
17489 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
17490 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
17491 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17492 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17493 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17494 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17495 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17496 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17497 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17498 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17499 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17500 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
17501 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17502 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17503 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17504 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17505 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17506 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17507 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17508 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17509 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17510 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17511 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17512 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17513 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17514 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17515 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17516 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17517 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17518 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17519 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17520 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17521 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17522 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17523 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17524 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17525 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17526 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17527 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17528 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17529 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17530 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17531 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17532 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17533 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17534 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17535 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17536 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17537 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17538 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17539 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17540 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17541 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17542 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
17543 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17544 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17545 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17546 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17547 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17548 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17549 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17550 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17551 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17552 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17553 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 17554 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17555 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17556 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17557 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17558 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
17559 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
17560 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17561 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17562 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17563 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17564 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
2d447fca | 17565 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17566 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17567 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17568 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17569 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17570 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17571 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17572 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17573 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17574 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17575 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17576 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17577 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17578 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17579 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 | 17580 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
2d447fca | 17581 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
8f06b2d8 PB |
17582 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), |
17583 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17584 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
17585 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
17586 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
17587 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17588 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17589 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17590 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17591 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17592 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17593 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17594 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17595 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17596 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
17597 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
17598 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
17599 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
17600 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
17601 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
17602 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17603 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17604 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17605 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
17606 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
17607 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
17608 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
17609 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
17610 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
17611 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17612 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17613 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17614 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17615 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 17616 | |
c921be7d NC |
17617 | #undef ARM_VARIANT |
17618 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
17619 | ||
1103f72c NC |
17620 | cCE(torvscb, e12f190, 1, (RR), iwmmxt_tandorc), |
17621 | cCE(torvsch, e52f190, 1, (RR), iwmmxt_tandorc), | |
17622 | cCE(torvscw, e92f190, 1, (RR), iwmmxt_tandorc), | |
2d447fca JM |
17623 | cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn), |
17624 | cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn), | |
17625 | cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn), | |
17626 | cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17627 | cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17628 | cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17629 | cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17630 | cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17631 | cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17632 | cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17633 | cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17634 | cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17635 | cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17636 | cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17637 | cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17638 | cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17639 | cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17640 | cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
17641 | cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17642 | cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17643 | cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17644 | cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17645 | cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17646 | cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17647 | cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17648 | cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17649 | cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17650 | cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17651 | cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17652 | cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17653 | cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17654 | cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17655 | cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17656 | cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17657 | cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17658 | cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17659 | cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17660 | cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17661 | cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17662 | cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17663 | cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17664 | cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17665 | cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17666 | cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17667 | cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17668 | cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17669 | cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17670 | cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17671 | cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17672 | cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17673 | cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17674 | cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17675 | cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17676 | cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
17677 | ||
c921be7d NC |
17678 | #undef ARM_VARIANT |
17679 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
17680 | ||
4962c51a MS |
17681 | cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
17682 | cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17683 | cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17684 | cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
17685 | cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
17686 | cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
17687 | cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
17688 | cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
8f06b2d8 PB |
17689 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), |
17690 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
17691 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
17692 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
17693 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
17694 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
17695 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
17696 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
17697 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
17698 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
17699 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
17700 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
17701 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
17702 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
17703 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
17704 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
17705 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
17706 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
17707 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
17708 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
17709 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
17710 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
17711 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
17712 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
17713 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
17714 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
17715 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
17716 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
17717 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
17718 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
17719 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
17720 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
17721 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
17722 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
17723 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
17724 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
17725 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
17726 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
17727 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
17728 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
17729 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
17730 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
17731 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
17732 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
17733 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
17734 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
17735 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17736 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17737 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17738 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17739 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
17740 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
17741 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
17742 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
17743 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
17744 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
17745 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17746 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17747 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17748 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17749 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17750 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
17751 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17752 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
17753 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17754 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
17755 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
17756 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
17757 | }; |
17758 | #undef ARM_VARIANT | |
17759 | #undef THUMB_VARIANT | |
17760 | #undef TCE | |
17761 | #undef TCM | |
17762 | #undef TUE | |
17763 | #undef TUF | |
17764 | #undef TCC | |
8f06b2d8 | 17765 | #undef cCE |
e3cb604e PB |
17766 | #undef cCL |
17767 | #undef C3E | |
c19d1205 ZW |
17768 | #undef CE |
17769 | #undef CM | |
17770 | #undef UE | |
17771 | #undef UF | |
17772 | #undef UT | |
5287ad62 JB |
17773 | #undef NUF |
17774 | #undef nUF | |
17775 | #undef NCE | |
17776 | #undef nCE | |
c19d1205 ZW |
17777 | #undef OPS0 |
17778 | #undef OPS1 | |
17779 | #undef OPS2 | |
17780 | #undef OPS3 | |
17781 | #undef OPS4 | |
17782 | #undef OPS5 | |
17783 | #undef OPS6 | |
17784 | #undef do_0 | |
17785 | \f | |
17786 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 17787 | |
c19d1205 ZW |
17788 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
17789 | for use in the a.out file, and stores them in the array pointed to by buf. | |
17790 | This knows about the endian-ness of the target machine and does | |
17791 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
17792 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
17793 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 17794 | |
c19d1205 ZW |
17795 | void |
17796 | md_number_to_chars (char * buf, valueT val, int n) | |
17797 | { | |
17798 | if (target_big_endian) | |
17799 | number_to_chars_bigendian (buf, val, n); | |
17800 | else | |
17801 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
17802 | } |
17803 | ||
c19d1205 ZW |
17804 | static valueT |
17805 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 17806 | { |
c19d1205 ZW |
17807 | valueT result = 0; |
17808 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 17809 | |
c19d1205 | 17810 | if (target_big_endian) |
b99bd4ef | 17811 | { |
c19d1205 ZW |
17812 | while (n--) |
17813 | { | |
17814 | result <<= 8; | |
17815 | result |= (*where++ & 255); | |
17816 | } | |
b99bd4ef | 17817 | } |
c19d1205 | 17818 | else |
b99bd4ef | 17819 | { |
c19d1205 ZW |
17820 | while (n--) |
17821 | { | |
17822 | result <<= 8; | |
17823 | result |= (where[n] & 255); | |
17824 | } | |
bfae80f2 | 17825 | } |
b99bd4ef | 17826 | |
c19d1205 | 17827 | return result; |
bfae80f2 | 17828 | } |
b99bd4ef | 17829 | |
c19d1205 | 17830 | /* MD interface: Sections. */ |
b99bd4ef | 17831 | |
0110f2b8 PB |
17832 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
17833 | 2 bytes. */ | |
17834 | ||
c19d1205 | 17835 | int |
0110f2b8 | 17836 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
17837 | segT segtype ATTRIBUTE_UNUSED) |
17838 | { | |
0110f2b8 PB |
17839 | fragp->fr_var = 2; |
17840 | return 2; | |
17841 | } | |
17842 | ||
17843 | /* Convert a machine dependent frag. */ | |
17844 | ||
17845 | void | |
17846 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
17847 | { | |
17848 | unsigned long insn; | |
17849 | unsigned long old_op; | |
17850 | char *buf; | |
17851 | expressionS exp; | |
17852 | fixS *fixp; | |
17853 | int reloc_type; | |
17854 | int pc_rel; | |
17855 | int opcode; | |
17856 | ||
17857 | buf = fragp->fr_literal + fragp->fr_fix; | |
17858 | ||
17859 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
17860 | if (fragp->fr_symbol) |
17861 | { | |
0110f2b8 PB |
17862 | exp.X_op = O_symbol; |
17863 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
17864 | } |
17865 | else | |
17866 | { | |
0110f2b8 | 17867 | exp.X_op = O_constant; |
5f4273c7 | 17868 | } |
0110f2b8 PB |
17869 | exp.X_add_number = fragp->fr_offset; |
17870 | opcode = fragp->fr_subtype; | |
17871 | switch (opcode) | |
17872 | { | |
17873 | case T_MNEM_ldr_pc: | |
17874 | case T_MNEM_ldr_pc2: | |
17875 | case T_MNEM_ldr_sp: | |
17876 | case T_MNEM_str_sp: | |
17877 | case T_MNEM_ldr: | |
17878 | case T_MNEM_ldrb: | |
17879 | case T_MNEM_ldrh: | |
17880 | case T_MNEM_str: | |
17881 | case T_MNEM_strb: | |
17882 | case T_MNEM_strh: | |
17883 | if (fragp->fr_var == 4) | |
17884 | { | |
5f4273c7 | 17885 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
17886 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
17887 | { | |
17888 | insn |= (old_op & 0x700) << 4; | |
17889 | } | |
17890 | else | |
17891 | { | |
17892 | insn |= (old_op & 7) << 12; | |
17893 | insn |= (old_op & 0x38) << 13; | |
17894 | } | |
17895 | insn |= 0x00000c00; | |
17896 | put_thumb32_insn (buf, insn); | |
17897 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
17898 | } | |
17899 | else | |
17900 | { | |
17901 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
17902 | } | |
17903 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
17904 | break; | |
17905 | case T_MNEM_adr: | |
17906 | if (fragp->fr_var == 4) | |
17907 | { | |
17908 | insn = THUMB_OP32 (opcode); | |
17909 | insn |= (old_op & 0xf0) << 4; | |
17910 | put_thumb32_insn (buf, insn); | |
17911 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
17912 | } | |
17913 | else | |
17914 | { | |
17915 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
17916 | exp.X_add_number -= 4; | |
17917 | } | |
17918 | pc_rel = 1; | |
17919 | break; | |
17920 | case T_MNEM_mov: | |
17921 | case T_MNEM_movs: | |
17922 | case T_MNEM_cmp: | |
17923 | case T_MNEM_cmn: | |
17924 | if (fragp->fr_var == 4) | |
17925 | { | |
17926 | int r0off = (opcode == T_MNEM_mov | |
17927 | || opcode == T_MNEM_movs) ? 0 : 8; | |
17928 | insn = THUMB_OP32 (opcode); | |
17929 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
17930 | insn |= (old_op & 0x700) << r0off; | |
17931 | put_thumb32_insn (buf, insn); | |
17932 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
17933 | } | |
17934 | else | |
17935 | { | |
17936 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
17937 | } | |
17938 | pc_rel = 0; | |
17939 | break; | |
17940 | case T_MNEM_b: | |
17941 | if (fragp->fr_var == 4) | |
17942 | { | |
17943 | insn = THUMB_OP32(opcode); | |
17944 | put_thumb32_insn (buf, insn); | |
17945 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
17946 | } | |
17947 | else | |
17948 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
17949 | pc_rel = 1; | |
17950 | break; | |
17951 | case T_MNEM_bcond: | |
17952 | if (fragp->fr_var == 4) | |
17953 | { | |
17954 | insn = THUMB_OP32(opcode); | |
17955 | insn |= (old_op & 0xf00) << 14; | |
17956 | put_thumb32_insn (buf, insn); | |
17957 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
17958 | } | |
17959 | else | |
17960 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
17961 | pc_rel = 1; | |
17962 | break; | |
17963 | case T_MNEM_add_sp: | |
17964 | case T_MNEM_add_pc: | |
17965 | case T_MNEM_inc_sp: | |
17966 | case T_MNEM_dec_sp: | |
17967 | if (fragp->fr_var == 4) | |
17968 | { | |
17969 | /* ??? Choose between add and addw. */ | |
17970 | insn = THUMB_OP32 (opcode); | |
17971 | insn |= (old_op & 0xf0) << 4; | |
17972 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
17973 | if (opcode == T_MNEM_add_pc) |
17974 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
17975 | else | |
17976 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
17977 | } |
17978 | else | |
17979 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
17980 | pc_rel = 0; | |
17981 | break; | |
17982 | ||
17983 | case T_MNEM_addi: | |
17984 | case T_MNEM_addis: | |
17985 | case T_MNEM_subi: | |
17986 | case T_MNEM_subis: | |
17987 | if (fragp->fr_var == 4) | |
17988 | { | |
17989 | insn = THUMB_OP32 (opcode); | |
17990 | insn |= (old_op & 0xf0) << 4; | |
17991 | insn |= (old_op & 0xf) << 16; | |
17992 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
17993 | if (insn & (1 << 20)) |
17994 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
17995 | else | |
17996 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
17997 | } |
17998 | else | |
17999 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
18000 | pc_rel = 0; | |
18001 | break; | |
18002 | default: | |
5f4273c7 | 18003 | abort (); |
0110f2b8 PB |
18004 | } |
18005 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
18006 | reloc_type); | |
18007 | fixp->fx_file = fragp->fr_file; | |
18008 | fixp->fx_line = fragp->fr_line; | |
18009 | fragp->fr_fix += fragp->fr_var; | |
18010 | } | |
18011 | ||
18012 | /* Return the size of a relaxable immediate operand instruction. | |
18013 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
18014 | static int | |
18015 | relax_immediate (fragS *fragp, int size, int shift) | |
18016 | { | |
18017 | offsetT offset; | |
18018 | offsetT mask; | |
18019 | offsetT low; | |
18020 | ||
18021 | /* ??? Should be able to do better than this. */ | |
18022 | if (fragp->fr_symbol) | |
18023 | return 4; | |
18024 | ||
18025 | low = (1 << shift) - 1; | |
18026 | mask = (1 << (shift + size)) - (1 << shift); | |
18027 | offset = fragp->fr_offset; | |
18028 | /* Force misaligned offsets to 32-bit variant. */ | |
18029 | if (offset & low) | |
5e77afaa | 18030 | return 4; |
0110f2b8 PB |
18031 | if (offset & ~mask) |
18032 | return 4; | |
18033 | return 2; | |
18034 | } | |
18035 | ||
5e77afaa PB |
18036 | /* Get the address of a symbol during relaxation. */ |
18037 | static addressT | |
5f4273c7 | 18038 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
18039 | { |
18040 | fragS *sym_frag; | |
18041 | addressT addr; | |
18042 | symbolS *sym; | |
18043 | ||
18044 | sym = fragp->fr_symbol; | |
18045 | sym_frag = symbol_get_frag (sym); | |
18046 | know (S_GET_SEGMENT (sym) != absolute_section | |
18047 | || sym_frag == &zero_address_frag); | |
18048 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
18049 | ||
18050 | /* If frag has yet to be reached on this pass, assume it will | |
18051 | move by STRETCH just as we did. If this is not so, it will | |
18052 | be because some frag between grows, and that will force | |
18053 | another pass. */ | |
18054 | ||
18055 | if (stretch != 0 | |
18056 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
18057 | { |
18058 | fragS *f; | |
18059 | ||
18060 | /* Adjust stretch for any alignment frag. Note that if have | |
18061 | been expanding the earlier code, the symbol may be | |
18062 | defined in what appears to be an earlier frag. FIXME: | |
18063 | This doesn't handle the fr_subtype field, which specifies | |
18064 | a maximum number of bytes to skip when doing an | |
18065 | alignment. */ | |
18066 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
18067 | { | |
18068 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
18069 | { | |
18070 | if (stretch < 0) | |
18071 | stretch = - ((- stretch) | |
18072 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
18073 | else | |
18074 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
18075 | if (stretch == 0) | |
18076 | break; | |
18077 | } | |
18078 | } | |
18079 | if (f != NULL) | |
18080 | addr += stretch; | |
18081 | } | |
5e77afaa PB |
18082 | |
18083 | return addr; | |
18084 | } | |
18085 | ||
0110f2b8 PB |
18086 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
18087 | load. */ | |
18088 | static int | |
5e77afaa | 18089 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
18090 | { |
18091 | addressT addr; | |
18092 | offsetT val; | |
18093 | ||
18094 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18095 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18096 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18097 | return 4; | |
18098 | ||
5f4273c7 | 18099 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18100 | addr = fragp->fr_address + fragp->fr_fix; |
18101 | addr = (addr + 4) & ~3; | |
5e77afaa | 18102 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 18103 | if (val & 3) |
5e77afaa | 18104 | return 4; |
0110f2b8 PB |
18105 | val -= addr; |
18106 | if (val < 0 || val > 1020) | |
18107 | return 4; | |
18108 | return 2; | |
18109 | } | |
18110 | ||
18111 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
18112 | static int | |
18113 | relax_addsub (fragS *fragp, asection *sec) | |
18114 | { | |
18115 | char *buf; | |
18116 | int op; | |
18117 | ||
18118 | buf = fragp->fr_literal + fragp->fr_fix; | |
18119 | op = bfd_get_16(sec->owner, buf); | |
18120 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
18121 | return relax_immediate (fragp, 8, 0); | |
18122 | else | |
18123 | return relax_immediate (fragp, 3, 0); | |
18124 | } | |
18125 | ||
18126 | ||
18127 | /* Return the size of a relaxable branch instruction. BITS is the | |
18128 | size of the offset field in the narrow instruction. */ | |
18129 | ||
18130 | static int | |
5e77afaa | 18131 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
18132 | { |
18133 | addressT addr; | |
18134 | offsetT val; | |
18135 | offsetT limit; | |
18136 | ||
18137 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 18138 | if (!S_IS_DEFINED (fragp->fr_symbol) |
0110f2b8 PB |
18139 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) |
18140 | return 4; | |
18141 | ||
267bf995 RR |
18142 | #ifdef OBJ_ELF |
18143 | if (S_IS_DEFINED (fragp->fr_symbol) | |
18144 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
18145 | return 4; | |
18146 | #endif | |
18147 | ||
5f4273c7 | 18148 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
18149 | addr = fragp->fr_address + fragp->fr_fix + 4; |
18150 | val -= addr; | |
18151 | ||
18152 | /* Offset is a signed value *2 */ | |
18153 | limit = 1 << bits; | |
18154 | if (val >= limit || val < -limit) | |
18155 | return 4; | |
18156 | return 2; | |
18157 | } | |
18158 | ||
18159 | ||
18160 | /* Relax a machine dependent frag. This returns the amount by which | |
18161 | the current size of the frag should change. */ | |
18162 | ||
18163 | int | |
5e77afaa | 18164 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
18165 | { |
18166 | int oldsize; | |
18167 | int newsize; | |
18168 | ||
18169 | oldsize = fragp->fr_var; | |
18170 | switch (fragp->fr_subtype) | |
18171 | { | |
18172 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 18173 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18174 | break; |
18175 | case T_MNEM_ldr_pc: | |
18176 | case T_MNEM_ldr_sp: | |
18177 | case T_MNEM_str_sp: | |
5f4273c7 | 18178 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
18179 | break; |
18180 | case T_MNEM_ldr: | |
18181 | case T_MNEM_str: | |
5f4273c7 | 18182 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
18183 | break; |
18184 | case T_MNEM_ldrh: | |
18185 | case T_MNEM_strh: | |
5f4273c7 | 18186 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
18187 | break; |
18188 | case T_MNEM_ldrb: | |
18189 | case T_MNEM_strb: | |
5f4273c7 | 18190 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
18191 | break; |
18192 | case T_MNEM_adr: | |
5f4273c7 | 18193 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
18194 | break; |
18195 | case T_MNEM_mov: | |
18196 | case T_MNEM_movs: | |
18197 | case T_MNEM_cmp: | |
18198 | case T_MNEM_cmn: | |
5f4273c7 | 18199 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
18200 | break; |
18201 | case T_MNEM_b: | |
5f4273c7 | 18202 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
18203 | break; |
18204 | case T_MNEM_bcond: | |
5f4273c7 | 18205 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
18206 | break; |
18207 | case T_MNEM_add_sp: | |
18208 | case T_MNEM_add_pc: | |
18209 | newsize = relax_immediate (fragp, 8, 2); | |
18210 | break; | |
18211 | case T_MNEM_inc_sp: | |
18212 | case T_MNEM_dec_sp: | |
18213 | newsize = relax_immediate (fragp, 7, 2); | |
18214 | break; | |
18215 | case T_MNEM_addi: | |
18216 | case T_MNEM_addis: | |
18217 | case T_MNEM_subi: | |
18218 | case T_MNEM_subis: | |
18219 | newsize = relax_addsub (fragp, sec); | |
18220 | break; | |
18221 | default: | |
5f4273c7 | 18222 | abort (); |
0110f2b8 | 18223 | } |
5e77afaa PB |
18224 | |
18225 | fragp->fr_var = newsize; | |
18226 | /* Freeze wide instructions that are at or before the same location as | |
18227 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
18228 | Don't freeze them unconditionally because targets may be artificially |
18229 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 18230 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 18231 | { |
0110f2b8 | 18232 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 18233 | frag_wane (fragp); |
0110f2b8 | 18234 | } |
5e77afaa | 18235 | |
0110f2b8 | 18236 | return newsize - oldsize; |
c19d1205 | 18237 | } |
b99bd4ef | 18238 | |
c19d1205 | 18239 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 18240 | |
c19d1205 ZW |
18241 | valueT |
18242 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
18243 | valueT size) | |
18244 | { | |
f0927246 NC |
18245 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
18246 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
18247 | { | |
18248 | /* For a.out, force the section size to be aligned. If we don't do | |
18249 | this, BFD will align it for us, but it will not write out the | |
18250 | final bytes of the section. This may be a bug in BFD, but it is | |
18251 | easier to fix it here since that is how the other a.out targets | |
18252 | work. */ | |
18253 | int align; | |
18254 | ||
18255 | align = bfd_get_section_alignment (stdoutput, segment); | |
18256 | size = ((size + (1 << align) - 1) & ((valueT) -1 << align)); | |
18257 | } | |
c19d1205 | 18258 | #endif |
f0927246 NC |
18259 | |
18260 | return size; | |
bfae80f2 | 18261 | } |
b99bd4ef | 18262 | |
c19d1205 ZW |
18263 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
18264 | of an rs_align_code fragment. */ | |
18265 | ||
18266 | void | |
18267 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 18268 | { |
e7495e45 NS |
18269 | static char const arm_noop[2][2][4] = |
18270 | { | |
18271 | { /* ARMv1 */ | |
18272 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
18273 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
18274 | }, | |
18275 | { /* ARMv6k */ | |
18276 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
18277 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
18278 | }, | |
18279 | }; | |
18280 | static char const thumb_noop[2][2][2] = | |
18281 | { | |
18282 | { /* Thumb-1 */ | |
18283 | {0xc0, 0x46}, /* LE */ | |
18284 | {0x46, 0xc0}, /* BE */ | |
18285 | }, | |
18286 | { /* Thumb-2 */ | |
18287 | {0x00, 0xbf}, /* LE */ | |
18288 | {0xbf, 0x00} /* BE */ | |
18289 | } | |
18290 | }; | |
18291 | static char const wide_thumb_noop[2][4] = | |
18292 | { /* Wide Thumb-2 */ | |
18293 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
18294 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
18295 | }; | |
c921be7d | 18296 | |
e7495e45 | 18297 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
18298 | char * p; |
18299 | const char * noop; | |
e7495e45 | 18300 | const char *narrow_noop = NULL; |
bfae80f2 | 18301 | |
c19d1205 | 18302 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
18303 | return; |
18304 | ||
c19d1205 ZW |
18305 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
18306 | p = fragP->fr_literal + fragP->fr_fix; | |
18307 | fix = 0; | |
bfae80f2 | 18308 | |
c19d1205 ZW |
18309 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
18310 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 18311 | |
9c2799c2 | 18312 | gas_assert ((fragP->tc_frag_data & MODE_RECORDED) != 0); |
8dc2430f NC |
18313 | |
18314 | if (fragP->tc_frag_data & (~ MODE_RECORDED)) | |
a737bd4d | 18315 | { |
e7495e45 NS |
18316 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
18317 | { | |
18318 | narrow_noop = thumb_noop[1][target_big_endian]; | |
18319 | noop = wide_thumb_noop[target_big_endian]; | |
18320 | } | |
c19d1205 | 18321 | else |
e7495e45 NS |
18322 | noop = thumb_noop[0][target_big_endian]; |
18323 | noop_size = 2; | |
7ed4c4c5 NC |
18324 | } |
18325 | else | |
18326 | { | |
e7495e45 NS |
18327 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0] |
18328 | [target_big_endian]; | |
18329 | noop_size = 4; | |
7ed4c4c5 | 18330 | } |
c921be7d | 18331 | |
e7495e45 | 18332 | fragP->fr_var = noop_size; |
c921be7d | 18333 | |
c19d1205 | 18334 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 18335 | { |
c19d1205 ZW |
18336 | fix = bytes & (noop_size - 1); |
18337 | memset (p, 0, fix); | |
18338 | p += fix; | |
18339 | bytes -= fix; | |
a737bd4d | 18340 | } |
a737bd4d | 18341 | |
e7495e45 NS |
18342 | if (narrow_noop) |
18343 | { | |
18344 | if (bytes & noop_size) | |
18345 | { | |
18346 | /* Insert a narrow noop. */ | |
18347 | memcpy (p, narrow_noop, noop_size); | |
18348 | p += noop_size; | |
18349 | bytes -= noop_size; | |
18350 | fix += noop_size; | |
18351 | } | |
18352 | ||
18353 | /* Use wide noops for the remainder */ | |
18354 | noop_size = 4; | |
18355 | } | |
18356 | ||
c19d1205 | 18357 | while (bytes >= noop_size) |
a737bd4d | 18358 | { |
c19d1205 ZW |
18359 | memcpy (p, noop, noop_size); |
18360 | p += noop_size; | |
18361 | bytes -= noop_size; | |
18362 | fix += noop_size; | |
a737bd4d NC |
18363 | } |
18364 | ||
c19d1205 | 18365 | fragP->fr_fix += fix; |
a737bd4d NC |
18366 | } |
18367 | ||
c19d1205 ZW |
18368 | /* Called from md_do_align. Used to create an alignment |
18369 | frag in a code section. */ | |
18370 | ||
18371 | void | |
18372 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 18373 | { |
c19d1205 | 18374 | char * p; |
7ed4c4c5 | 18375 | |
c19d1205 ZW |
18376 | /* We assume that there will never be a requirement |
18377 | to support alignments greater than 32 bytes. */ | |
18378 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) | |
18379 | as_fatal (_("alignments greater than 32 bytes not supported in .text sections.")); | |
bfae80f2 | 18380 | |
c19d1205 ZW |
18381 | p = frag_var (rs_align_code, |
18382 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
18383 | 1, | |
18384 | (relax_substateT) max, | |
18385 | (symbolS *) NULL, | |
18386 | (offsetT) n, | |
18387 | (char *) NULL); | |
18388 | *p = 0; | |
18389 | } | |
bfae80f2 | 18390 | |
8dc2430f NC |
18391 | /* Perform target specific initialisation of a frag. |
18392 | Note - despite the name this initialisation is not done when the frag | |
18393 | is created, but only when its type is assigned. A frag can be created | |
18394 | and used a long time before its type is set, so beware of assuming that | |
18395 | this initialisationis performed first. */ | |
bfae80f2 | 18396 | |
c19d1205 ZW |
18397 | void |
18398 | arm_init_frag (fragS * fragP) | |
18399 | { | |
8dc2430f NC |
18400 | /* If the current ARM vs THUMB mode has not already |
18401 | been recorded into this frag then do so now. */ | |
18402 | if ((fragP->tc_frag_data & MODE_RECORDED) == 0) | |
18403 | fragP->tc_frag_data = thumb_mode | MODE_RECORDED; | |
bfae80f2 RE |
18404 | } |
18405 | ||
c19d1205 ZW |
18406 | #ifdef OBJ_ELF |
18407 | /* When we change sections we need to issue a new mapping symbol. */ | |
18408 | ||
18409 | void | |
18410 | arm_elf_change_section (void) | |
bfae80f2 | 18411 | { |
c19d1205 ZW |
18412 | flagword flags; |
18413 | segment_info_type *seginfo; | |
bfae80f2 | 18414 | |
c19d1205 ZW |
18415 | /* Link an unlinked unwind index table section to the .text section. */ |
18416 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
18417 | && elf_linked_to_section (now_seg) == NULL) | |
18418 | elf_linked_to_section (now_seg) = text_section; | |
18419 | ||
18420 | if (!SEG_NORMAL (now_seg)) | |
bfae80f2 RE |
18421 | return; |
18422 | ||
c19d1205 ZW |
18423 | flags = bfd_get_section_flags (stdoutput, now_seg); |
18424 | ||
18425 | /* We can ignore sections that only contain debug info. */ | |
18426 | if ((flags & SEC_ALLOC) == 0) | |
18427 | return; | |
bfae80f2 | 18428 | |
c19d1205 ZW |
18429 | seginfo = seg_info (now_seg); |
18430 | mapstate = seginfo->tc_segment_info_data.mapstate; | |
18431 | marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency; | |
bfae80f2 RE |
18432 | } |
18433 | ||
c19d1205 ZW |
18434 | int |
18435 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 18436 | { |
c19d1205 ZW |
18437 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
18438 | return SHT_ARM_EXIDX; | |
e45d0630 | 18439 | |
c19d1205 ZW |
18440 | return -1; |
18441 | } | |
18442 | \f | |
18443 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 18444 | |
c19d1205 | 18445 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 18446 | |
5f4273c7 | 18447 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 18448 | |
bfae80f2 | 18449 | static void |
c19d1205 | 18450 | flush_pending_unwind (void) |
bfae80f2 | 18451 | { |
c19d1205 | 18452 | offsetT offset; |
bfae80f2 | 18453 | |
c19d1205 ZW |
18454 | offset = unwind.pending_offset; |
18455 | unwind.pending_offset = 0; | |
18456 | if (offset != 0) | |
18457 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
18458 | } |
18459 | ||
c19d1205 ZW |
18460 | /* Add an opcode to this list for this function. Two-byte opcodes should |
18461 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
18462 | order. */ | |
18463 | ||
bfae80f2 | 18464 | static void |
c19d1205 | 18465 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 18466 | { |
c19d1205 ZW |
18467 | /* Add any deferred stack adjustment. */ |
18468 | if (unwind.pending_offset) | |
18469 | flush_pending_unwind (); | |
bfae80f2 | 18470 | |
c19d1205 | 18471 | unwind.sp_restored = 0; |
bfae80f2 | 18472 | |
c19d1205 | 18473 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 18474 | { |
c19d1205 ZW |
18475 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
18476 | if (unwind.opcodes) | |
18477 | unwind.opcodes = xrealloc (unwind.opcodes, | |
18478 | unwind.opcode_alloc); | |
18479 | else | |
18480 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 18481 | } |
c19d1205 | 18482 | while (length > 0) |
bfae80f2 | 18483 | { |
c19d1205 ZW |
18484 | length--; |
18485 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
18486 | op >>= 8; | |
18487 | unwind.opcode_count++; | |
bfae80f2 | 18488 | } |
bfae80f2 RE |
18489 | } |
18490 | ||
c19d1205 ZW |
18491 | /* Add unwind opcodes to adjust the stack pointer. */ |
18492 | ||
bfae80f2 | 18493 | static void |
c19d1205 | 18494 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 18495 | { |
c19d1205 | 18496 | valueT op; |
bfae80f2 | 18497 | |
c19d1205 | 18498 | if (offset > 0x200) |
bfae80f2 | 18499 | { |
c19d1205 ZW |
18500 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
18501 | char bytes[5]; | |
18502 | int n; | |
18503 | valueT o; | |
bfae80f2 | 18504 | |
c19d1205 ZW |
18505 | /* Long form: 0xb2, uleb128. */ |
18506 | /* This might not fit in a word so add the individual bytes, | |
18507 | remembering the list is built in reverse order. */ | |
18508 | o = (valueT) ((offset - 0x204) >> 2); | |
18509 | if (o == 0) | |
18510 | add_unwind_opcode (0, 1); | |
bfae80f2 | 18511 | |
c19d1205 ZW |
18512 | /* Calculate the uleb128 encoding of the offset. */ |
18513 | n = 0; | |
18514 | while (o) | |
18515 | { | |
18516 | bytes[n] = o & 0x7f; | |
18517 | o >>= 7; | |
18518 | if (o) | |
18519 | bytes[n] |= 0x80; | |
18520 | n++; | |
18521 | } | |
18522 | /* Add the insn. */ | |
18523 | for (; n; n--) | |
18524 | add_unwind_opcode (bytes[n - 1], 1); | |
18525 | add_unwind_opcode (0xb2, 1); | |
18526 | } | |
18527 | else if (offset > 0x100) | |
bfae80f2 | 18528 | { |
c19d1205 ZW |
18529 | /* Two short opcodes. */ |
18530 | add_unwind_opcode (0x3f, 1); | |
18531 | op = (offset - 0x104) >> 2; | |
18532 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18533 | } |
c19d1205 ZW |
18534 | else if (offset > 0) |
18535 | { | |
18536 | /* Short opcode. */ | |
18537 | op = (offset - 4) >> 2; | |
18538 | add_unwind_opcode (op, 1); | |
18539 | } | |
18540 | else if (offset < 0) | |
bfae80f2 | 18541 | { |
c19d1205 ZW |
18542 | offset = -offset; |
18543 | while (offset > 0x100) | |
bfae80f2 | 18544 | { |
c19d1205 ZW |
18545 | add_unwind_opcode (0x7f, 1); |
18546 | offset -= 0x100; | |
bfae80f2 | 18547 | } |
c19d1205 ZW |
18548 | op = ((offset - 4) >> 2) | 0x40; |
18549 | add_unwind_opcode (op, 1); | |
bfae80f2 | 18550 | } |
bfae80f2 RE |
18551 | } |
18552 | ||
c19d1205 ZW |
18553 | /* Finish the list of unwind opcodes for this function. */ |
18554 | static void | |
18555 | finish_unwind_opcodes (void) | |
bfae80f2 | 18556 | { |
c19d1205 | 18557 | valueT op; |
bfae80f2 | 18558 | |
c19d1205 | 18559 | if (unwind.fp_used) |
bfae80f2 | 18560 | { |
708587a4 | 18561 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
18562 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
18563 | flush_pending_unwind (); | |
bfae80f2 | 18564 | |
c19d1205 ZW |
18565 | /* After restoring sp from the frame pointer. */ |
18566 | op = 0x90 | unwind.fp_reg; | |
18567 | add_unwind_opcode (op, 1); | |
18568 | } | |
18569 | else | |
18570 | flush_pending_unwind (); | |
bfae80f2 RE |
18571 | } |
18572 | ||
bfae80f2 | 18573 | |
c19d1205 ZW |
18574 | /* Start an exception table entry. If idx is nonzero this is an index table |
18575 | entry. */ | |
bfae80f2 RE |
18576 | |
18577 | static void | |
c19d1205 | 18578 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 18579 | { |
c19d1205 ZW |
18580 | const char * text_name; |
18581 | const char * prefix; | |
18582 | const char * prefix_once; | |
18583 | const char * group_name; | |
18584 | size_t prefix_len; | |
18585 | size_t text_len; | |
18586 | char * sec_name; | |
18587 | size_t sec_name_len; | |
18588 | int type; | |
18589 | int flags; | |
18590 | int linkonce; | |
bfae80f2 | 18591 | |
c19d1205 | 18592 | if (idx) |
bfae80f2 | 18593 | { |
c19d1205 ZW |
18594 | prefix = ELF_STRING_ARM_unwind; |
18595 | prefix_once = ELF_STRING_ARM_unwind_once; | |
18596 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 18597 | } |
c19d1205 | 18598 | else |
bfae80f2 | 18599 | { |
c19d1205 ZW |
18600 | prefix = ELF_STRING_ARM_unwind_info; |
18601 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
18602 | type = SHT_PROGBITS; | |
bfae80f2 RE |
18603 | } |
18604 | ||
c19d1205 ZW |
18605 | text_name = segment_name (text_seg); |
18606 | if (streq (text_name, ".text")) | |
18607 | text_name = ""; | |
18608 | ||
18609 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
18610 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 18611 | { |
c19d1205 ZW |
18612 | prefix = prefix_once; |
18613 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
18614 | } |
18615 | ||
c19d1205 ZW |
18616 | prefix_len = strlen (prefix); |
18617 | text_len = strlen (text_name); | |
18618 | sec_name_len = prefix_len + text_len; | |
18619 | sec_name = xmalloc (sec_name_len + 1); | |
18620 | memcpy (sec_name, prefix, prefix_len); | |
18621 | memcpy (sec_name + prefix_len, text_name, text_len); | |
18622 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 18623 | |
c19d1205 ZW |
18624 | flags = SHF_ALLOC; |
18625 | linkonce = 0; | |
18626 | group_name = 0; | |
bfae80f2 | 18627 | |
c19d1205 ZW |
18628 | /* Handle COMDAT group. */ |
18629 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 18630 | { |
c19d1205 ZW |
18631 | group_name = elf_group_name (text_seg); |
18632 | if (group_name == NULL) | |
18633 | { | |
bd3ba5d1 | 18634 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
18635 | segment_name (text_seg)); |
18636 | ignore_rest_of_line (); | |
18637 | return; | |
18638 | } | |
18639 | flags |= SHF_GROUP; | |
18640 | linkonce = 1; | |
bfae80f2 RE |
18641 | } |
18642 | ||
c19d1205 | 18643 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 18644 | |
5f4273c7 | 18645 | /* Set the section link for index tables. */ |
c19d1205 ZW |
18646 | if (idx) |
18647 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
18648 | } |
18649 | ||
bfae80f2 | 18650 | |
c19d1205 ZW |
18651 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
18652 | personality routine data. Returns zero, or the index table value for | |
18653 | and inline entry. */ | |
18654 | ||
18655 | static valueT | |
18656 | create_unwind_entry (int have_data) | |
bfae80f2 | 18657 | { |
c19d1205 ZW |
18658 | int size; |
18659 | addressT where; | |
18660 | char *ptr; | |
18661 | /* The current word of data. */ | |
18662 | valueT data; | |
18663 | /* The number of bytes left in this word. */ | |
18664 | int n; | |
bfae80f2 | 18665 | |
c19d1205 | 18666 | finish_unwind_opcodes (); |
bfae80f2 | 18667 | |
c19d1205 ZW |
18668 | /* Remember the current text section. */ |
18669 | unwind.saved_seg = now_seg; | |
18670 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 18671 | |
c19d1205 | 18672 | start_unwind_section (now_seg, 0); |
bfae80f2 | 18673 | |
c19d1205 | 18674 | if (unwind.personality_routine == NULL) |
bfae80f2 | 18675 | { |
c19d1205 ZW |
18676 | if (unwind.personality_index == -2) |
18677 | { | |
18678 | if (have_data) | |
5f4273c7 | 18679 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
18680 | return 1; /* EXIDX_CANTUNWIND. */ |
18681 | } | |
bfae80f2 | 18682 | |
c19d1205 ZW |
18683 | /* Use a default personality routine if none is specified. */ |
18684 | if (unwind.personality_index == -1) | |
18685 | { | |
18686 | if (unwind.opcode_count > 3) | |
18687 | unwind.personality_index = 1; | |
18688 | else | |
18689 | unwind.personality_index = 0; | |
18690 | } | |
bfae80f2 | 18691 | |
c19d1205 ZW |
18692 | /* Space for the personality routine entry. */ |
18693 | if (unwind.personality_index == 0) | |
18694 | { | |
18695 | if (unwind.opcode_count > 3) | |
18696 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 18697 | |
c19d1205 ZW |
18698 | if (!have_data) |
18699 | { | |
18700 | /* All the data is inline in the index table. */ | |
18701 | data = 0x80; | |
18702 | n = 3; | |
18703 | while (unwind.opcode_count > 0) | |
18704 | { | |
18705 | unwind.opcode_count--; | |
18706 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18707 | n--; | |
18708 | } | |
bfae80f2 | 18709 | |
c19d1205 ZW |
18710 | /* Pad with "finish" opcodes. */ |
18711 | while (n--) | |
18712 | data = (data << 8) | 0xb0; | |
bfae80f2 | 18713 | |
c19d1205 ZW |
18714 | return data; |
18715 | } | |
18716 | size = 0; | |
18717 | } | |
18718 | else | |
18719 | /* We get two opcodes "free" in the first word. */ | |
18720 | size = unwind.opcode_count - 2; | |
18721 | } | |
18722 | else | |
18723 | /* An extra byte is required for the opcode count. */ | |
18724 | size = unwind.opcode_count + 1; | |
bfae80f2 | 18725 | |
c19d1205 ZW |
18726 | size = (size + 3) >> 2; |
18727 | if (size > 0xff) | |
18728 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 18729 | |
c19d1205 ZW |
18730 | frag_align (2, 0, 0); |
18731 | record_alignment (now_seg, 2); | |
18732 | unwind.table_entry = expr_build_dot (); | |
18733 | ||
18734 | /* Allocate the table entry. */ | |
18735 | ptr = frag_more ((size << 2) + 4); | |
18736 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 18737 | |
c19d1205 | 18738 | switch (unwind.personality_index) |
bfae80f2 | 18739 | { |
c19d1205 ZW |
18740 | case -1: |
18741 | /* ??? Should this be a PLT generating relocation? */ | |
18742 | /* Custom personality routine. */ | |
18743 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
18744 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 18745 | |
c19d1205 ZW |
18746 | where += 4; |
18747 | ptr += 4; | |
bfae80f2 | 18748 | |
c19d1205 ZW |
18749 | /* Set the first byte to the number of additional words. */ |
18750 | data = size - 1; | |
18751 | n = 3; | |
18752 | break; | |
bfae80f2 | 18753 | |
c19d1205 ZW |
18754 | /* ABI defined personality routines. */ |
18755 | case 0: | |
18756 | /* Three opcodes bytes are packed into the first word. */ | |
18757 | data = 0x80; | |
18758 | n = 3; | |
18759 | break; | |
bfae80f2 | 18760 | |
c19d1205 ZW |
18761 | case 1: |
18762 | case 2: | |
18763 | /* The size and first two opcode bytes go in the first word. */ | |
18764 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
18765 | n = 2; | |
18766 | break; | |
bfae80f2 | 18767 | |
c19d1205 ZW |
18768 | default: |
18769 | /* Should never happen. */ | |
18770 | abort (); | |
18771 | } | |
bfae80f2 | 18772 | |
c19d1205 ZW |
18773 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
18774 | time. */ | |
18775 | while (unwind.opcode_count > 0) | |
18776 | { | |
18777 | if (n == 0) | |
18778 | { | |
18779 | md_number_to_chars (ptr, data, 4); | |
18780 | ptr += 4; | |
18781 | n = 4; | |
18782 | data = 0; | |
18783 | } | |
18784 | unwind.opcode_count--; | |
18785 | n--; | |
18786 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
18787 | } | |
18788 | ||
18789 | /* Finish off the last word. */ | |
18790 | if (n < 4) | |
18791 | { | |
18792 | /* Pad with "finish" opcodes. */ | |
18793 | while (n--) | |
18794 | data = (data << 8) | 0xb0; | |
18795 | ||
18796 | md_number_to_chars (ptr, data, 4); | |
18797 | } | |
18798 | ||
18799 | if (!have_data) | |
18800 | { | |
18801 | /* Add an empty descriptor if there is no user-specified data. */ | |
18802 | ptr = frag_more (4); | |
18803 | md_number_to_chars (ptr, 0, 4); | |
18804 | } | |
18805 | ||
18806 | return 0; | |
bfae80f2 RE |
18807 | } |
18808 | ||
f0927246 NC |
18809 | |
18810 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
18811 | ||
18812 | void | |
18813 | tc_arm_frame_initial_instructions (void) | |
18814 | { | |
18815 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
18816 | } | |
18817 | #endif /* OBJ_ELF */ | |
18818 | ||
c19d1205 ZW |
18819 | /* Convert REGNAME to a DWARF-2 register number. */ |
18820 | ||
18821 | int | |
1df69f4f | 18822 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 18823 | { |
1df69f4f | 18824 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
c19d1205 ZW |
18825 | |
18826 | if (reg == FAIL) | |
18827 | return -1; | |
18828 | ||
18829 | return reg; | |
bfae80f2 RE |
18830 | } |
18831 | ||
f0927246 | 18832 | #ifdef TE_PE |
c19d1205 | 18833 | void |
f0927246 | 18834 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 18835 | { |
f0927246 | 18836 | expressionS expr; |
bfae80f2 | 18837 | |
f0927246 NC |
18838 | expr.X_op = O_secrel; |
18839 | expr.X_add_symbol = symbol; | |
18840 | expr.X_add_number = 0; | |
18841 | emit_expr (&expr, size); | |
18842 | } | |
18843 | #endif | |
bfae80f2 | 18844 | |
c19d1205 | 18845 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 18846 | |
2fc8bdac ZW |
18847 | /* Return the address within the segment that a PC-relative fixup is |
18848 | relative to. For ARM, PC-relative fixups applied to instructions | |
18849 | are generally relative to the location of the fixup plus 8 bytes. | |
18850 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
18851 | require special handling. */ | |
bfae80f2 | 18852 | |
c19d1205 | 18853 | long |
2fc8bdac | 18854 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 18855 | { |
2fc8bdac ZW |
18856 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
18857 | ||
18858 | /* If this is pc-relative and we are going to emit a relocation | |
18859 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
18860 | will need. Otherwise we want to use the calculated base. |
18861 | For WinCE we skip the bias for externals as well, since this | |
18862 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 18863 | if (fixP->fx_pcrel |
2fc8bdac | 18864 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
18865 | || (arm_force_relocation (fixP) |
18866 | #ifdef TE_WINCE | |
18867 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
18868 | #endif | |
18869 | ))) | |
2fc8bdac | 18870 | base = 0; |
bfae80f2 | 18871 | |
267bf995 | 18872 | |
c19d1205 | 18873 | switch (fixP->fx_r_type) |
bfae80f2 | 18874 | { |
2fc8bdac ZW |
18875 | /* PC relative addressing on the Thumb is slightly odd as the |
18876 | bottom two bits of the PC are forced to zero for the | |
18877 | calculation. This happens *after* application of the | |
18878 | pipeline offset. However, Thumb adrl already adjusts for | |
18879 | this, so we need not do it again. */ | |
c19d1205 | 18880 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 18881 | return base & ~3; |
c19d1205 ZW |
18882 | |
18883 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
18884 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 18885 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 18886 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 18887 | return (base + 4) & ~3; |
c19d1205 | 18888 | |
2fc8bdac ZW |
18889 | /* Thumb branches are simply offset by +4. */ |
18890 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
18891 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
18892 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
18893 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 18894 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 18895 | return base + 4; |
bfae80f2 | 18896 | |
267bf995 RR |
18897 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
18898 | if (fixP->fx_addsy | |
18899 | && ARM_IS_FUNC (fixP->fx_addsy) | |
18900 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18901 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
18902 | return base + 4; | |
18903 | ||
00adf2d4 JB |
18904 | /* BLX is like branches above, but forces the low two bits of PC to |
18905 | zero. */ | |
267bf995 RR |
18906 | case BFD_RELOC_THUMB_PCREL_BLX: |
18907 | if (fixP->fx_addsy | |
18908 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
18909 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18910 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
18911 | return (base + 4) & ~3; |
18912 | ||
2fc8bdac ZW |
18913 | /* ARM mode branches are offset by +8. However, the Windows CE |
18914 | loader expects the relocation not to take this into account. */ | |
267bf995 RR |
18915 | case BFD_RELOC_ARM_PCREL_BLX: |
18916 | if (fixP->fx_addsy | |
18917 | && ARM_IS_FUNC (fixP->fx_addsy) | |
18918 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18919 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
18920 | return base + 8; | |
18921 | ||
18922 | case BFD_RELOC_ARM_PCREL_CALL: | |
18923 | if (fixP->fx_addsy | |
18924 | && THUMB_IS_FUNC (fixP->fx_addsy) | |
18925 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
18926 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
18927 | return base + 8; | |
18928 | ||
2fc8bdac | 18929 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 18930 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 18931 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 18932 | #ifdef TE_WINCE |
5f4273c7 | 18933 | /* When handling fixups immediately, because we have already |
53baae48 NC |
18934 | discovered the value of a symbol, or the address of the frag involved |
18935 | we must account for the offset by +8, as the OS loader will never see the reloc. | |
18936 | see fixup_segment() in write.c | |
18937 | The S_IS_EXTERNAL test handles the case of global symbols. | |
18938 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
18939 | if (fixP->fx_pcrel | |
18940 | && fixP->fx_addsy != NULL | |
18941 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
18942 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
18943 | return base + 8; | |
2fc8bdac | 18944 | return base; |
c19d1205 | 18945 | #else |
2fc8bdac | 18946 | return base + 8; |
c19d1205 | 18947 | #endif |
2fc8bdac | 18948 | |
267bf995 | 18949 | |
2fc8bdac ZW |
18950 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
18951 | branches, the Windows CE loader *does* expect the relocation | |
18952 | to take this into account. */ | |
18953 | case BFD_RELOC_ARM_OFFSET_IMM: | |
18954 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
18955 | case BFD_RELOC_ARM_HWLITERAL: | |
18956 | case BFD_RELOC_ARM_LITERAL: | |
18957 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
18958 | return base + 8; | |
18959 | ||
18960 | ||
18961 | /* Other PC-relative relocations are un-offset. */ | |
18962 | default: | |
18963 | return base; | |
18964 | } | |
bfae80f2 RE |
18965 | } |
18966 | ||
c19d1205 ZW |
18967 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
18968 | Otherwise we have no need to default values of symbols. */ | |
18969 | ||
18970 | symbolS * | |
18971 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 18972 | { |
c19d1205 ZW |
18973 | #ifdef OBJ_ELF |
18974 | if (name[0] == '_' && name[1] == 'G' | |
18975 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
18976 | { | |
18977 | if (!GOT_symbol) | |
18978 | { | |
18979 | if (symbol_find (name)) | |
bd3ba5d1 | 18980 | as_bad (_("GOT already in the symbol table")); |
bfae80f2 | 18981 | |
c19d1205 ZW |
18982 | GOT_symbol = symbol_new (name, undefined_section, |
18983 | (valueT) 0, & zero_address_frag); | |
18984 | } | |
bfae80f2 | 18985 | |
c19d1205 | 18986 | return GOT_symbol; |
bfae80f2 | 18987 | } |
c19d1205 | 18988 | #endif |
bfae80f2 | 18989 | |
c921be7d | 18990 | return NULL; |
bfae80f2 RE |
18991 | } |
18992 | ||
55cf6793 | 18993 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
18994 | computed as two separate immediate values, added together. We |
18995 | already know that this value cannot be computed by just one ARM | |
18996 | instruction. */ | |
18997 | ||
18998 | static unsigned int | |
18999 | validate_immediate_twopart (unsigned int val, | |
19000 | unsigned int * highpart) | |
bfae80f2 | 19001 | { |
c19d1205 ZW |
19002 | unsigned int a; |
19003 | unsigned int i; | |
bfae80f2 | 19004 | |
c19d1205 ZW |
19005 | for (i = 0; i < 32; i += 2) |
19006 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
19007 | { | |
19008 | if (a & 0xff00) | |
19009 | { | |
19010 | if (a & ~ 0xffff) | |
19011 | continue; | |
19012 | * highpart = (a >> 8) | ((i + 24) << 7); | |
19013 | } | |
19014 | else if (a & 0xff0000) | |
19015 | { | |
19016 | if (a & 0xff000000) | |
19017 | continue; | |
19018 | * highpart = (a >> 16) | ((i + 16) << 7); | |
19019 | } | |
19020 | else | |
19021 | { | |
9c2799c2 | 19022 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
19023 | * highpart = (a >> 24) | ((i + 8) << 7); |
19024 | } | |
bfae80f2 | 19025 | |
c19d1205 ZW |
19026 | return (a & 0xff) | (i << 7); |
19027 | } | |
bfae80f2 | 19028 | |
c19d1205 | 19029 | return FAIL; |
bfae80f2 RE |
19030 | } |
19031 | ||
c19d1205 ZW |
19032 | static int |
19033 | validate_offset_imm (unsigned int val, int hwse) | |
19034 | { | |
19035 | if ((hwse && val > 255) || val > 4095) | |
19036 | return FAIL; | |
19037 | return val; | |
19038 | } | |
bfae80f2 | 19039 | |
55cf6793 | 19040 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
19041 | negative immediate constant by altering the instruction. A bit of |
19042 | a hack really. | |
19043 | MOV <-> MVN | |
19044 | AND <-> BIC | |
19045 | ADC <-> SBC | |
19046 | by inverting the second operand, and | |
19047 | ADD <-> SUB | |
19048 | CMP <-> CMN | |
19049 | by negating the second operand. */ | |
bfae80f2 | 19050 | |
c19d1205 ZW |
19051 | static int |
19052 | negate_data_op (unsigned long * instruction, | |
19053 | unsigned long value) | |
bfae80f2 | 19054 | { |
c19d1205 ZW |
19055 | int op, new_inst; |
19056 | unsigned long negated, inverted; | |
bfae80f2 | 19057 | |
c19d1205 ZW |
19058 | negated = encode_arm_immediate (-value); |
19059 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 19060 | |
c19d1205 ZW |
19061 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
19062 | switch (op) | |
bfae80f2 | 19063 | { |
c19d1205 ZW |
19064 | /* First negates. */ |
19065 | case OPCODE_SUB: /* ADD <-> SUB */ | |
19066 | new_inst = OPCODE_ADD; | |
19067 | value = negated; | |
19068 | break; | |
bfae80f2 | 19069 | |
c19d1205 ZW |
19070 | case OPCODE_ADD: |
19071 | new_inst = OPCODE_SUB; | |
19072 | value = negated; | |
19073 | break; | |
bfae80f2 | 19074 | |
c19d1205 ZW |
19075 | case OPCODE_CMP: /* CMP <-> CMN */ |
19076 | new_inst = OPCODE_CMN; | |
19077 | value = negated; | |
19078 | break; | |
bfae80f2 | 19079 | |
c19d1205 ZW |
19080 | case OPCODE_CMN: |
19081 | new_inst = OPCODE_CMP; | |
19082 | value = negated; | |
19083 | break; | |
bfae80f2 | 19084 | |
c19d1205 ZW |
19085 | /* Now Inverted ops. */ |
19086 | case OPCODE_MOV: /* MOV <-> MVN */ | |
19087 | new_inst = OPCODE_MVN; | |
19088 | value = inverted; | |
19089 | break; | |
bfae80f2 | 19090 | |
c19d1205 ZW |
19091 | case OPCODE_MVN: |
19092 | new_inst = OPCODE_MOV; | |
19093 | value = inverted; | |
19094 | break; | |
bfae80f2 | 19095 | |
c19d1205 ZW |
19096 | case OPCODE_AND: /* AND <-> BIC */ |
19097 | new_inst = OPCODE_BIC; | |
19098 | value = inverted; | |
19099 | break; | |
bfae80f2 | 19100 | |
c19d1205 ZW |
19101 | case OPCODE_BIC: |
19102 | new_inst = OPCODE_AND; | |
19103 | value = inverted; | |
19104 | break; | |
bfae80f2 | 19105 | |
c19d1205 ZW |
19106 | case OPCODE_ADC: /* ADC <-> SBC */ |
19107 | new_inst = OPCODE_SBC; | |
19108 | value = inverted; | |
19109 | break; | |
bfae80f2 | 19110 | |
c19d1205 ZW |
19111 | case OPCODE_SBC: |
19112 | new_inst = OPCODE_ADC; | |
19113 | value = inverted; | |
19114 | break; | |
bfae80f2 | 19115 | |
c19d1205 ZW |
19116 | /* We cannot do anything. */ |
19117 | default: | |
19118 | return FAIL; | |
b99bd4ef NC |
19119 | } |
19120 | ||
c19d1205 ZW |
19121 | if (value == (unsigned) FAIL) |
19122 | return FAIL; | |
19123 | ||
19124 | *instruction &= OPCODE_MASK; | |
19125 | *instruction |= new_inst << DATA_OP_SHIFT; | |
19126 | return value; | |
b99bd4ef NC |
19127 | } |
19128 | ||
ef8d22e6 PB |
19129 | /* Like negate_data_op, but for Thumb-2. */ |
19130 | ||
19131 | static unsigned int | |
16dd5e42 | 19132 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
19133 | { |
19134 | int op, new_inst; | |
19135 | int rd; | |
16dd5e42 | 19136 | unsigned int negated, inverted; |
ef8d22e6 PB |
19137 | |
19138 | negated = encode_thumb32_immediate (-value); | |
19139 | inverted = encode_thumb32_immediate (~value); | |
19140 | ||
19141 | rd = (*instruction >> 8) & 0xf; | |
19142 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
19143 | switch (op) | |
19144 | { | |
19145 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
19146 | case T2_OPCODE_SUB: | |
19147 | new_inst = T2_OPCODE_ADD; | |
19148 | value = negated; | |
19149 | break; | |
19150 | ||
19151 | case T2_OPCODE_ADD: | |
19152 | new_inst = T2_OPCODE_SUB; | |
19153 | value = negated; | |
19154 | break; | |
19155 | ||
19156 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
19157 | case T2_OPCODE_ORR: | |
19158 | new_inst = T2_OPCODE_ORN; | |
19159 | value = inverted; | |
19160 | break; | |
19161 | ||
19162 | case T2_OPCODE_ORN: | |
19163 | new_inst = T2_OPCODE_ORR; | |
19164 | value = inverted; | |
19165 | break; | |
19166 | ||
19167 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
19168 | case T2_OPCODE_AND: | |
19169 | new_inst = T2_OPCODE_BIC; | |
19170 | if (rd == 15) | |
19171 | value = FAIL; | |
19172 | else | |
19173 | value = inverted; | |
19174 | break; | |
19175 | ||
19176 | case T2_OPCODE_BIC: | |
19177 | new_inst = T2_OPCODE_AND; | |
19178 | value = inverted; | |
19179 | break; | |
19180 | ||
19181 | /* ADC <-> SBC */ | |
19182 | case T2_OPCODE_ADC: | |
19183 | new_inst = T2_OPCODE_SBC; | |
19184 | value = inverted; | |
19185 | break; | |
19186 | ||
19187 | case T2_OPCODE_SBC: | |
19188 | new_inst = T2_OPCODE_ADC; | |
19189 | value = inverted; | |
19190 | break; | |
19191 | ||
19192 | /* We cannot do anything. */ | |
19193 | default: | |
19194 | return FAIL; | |
19195 | } | |
19196 | ||
16dd5e42 | 19197 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
19198 | return FAIL; |
19199 | ||
19200 | *instruction &= T2_OPCODE_MASK; | |
19201 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
19202 | return value; | |
19203 | } | |
19204 | ||
8f06b2d8 PB |
19205 | /* Read a 32-bit thumb instruction from buf. */ |
19206 | static unsigned long | |
19207 | get_thumb32_insn (char * buf) | |
19208 | { | |
19209 | unsigned long insn; | |
19210 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
19211 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19212 | ||
19213 | return insn; | |
19214 | } | |
19215 | ||
a8bc6c78 PB |
19216 | |
19217 | /* We usually want to set the low bit on the address of thumb function | |
19218 | symbols. In particular .word foo - . should have the low bit set. | |
19219 | Generic code tries to fold the difference of two symbols to | |
19220 | a constant. Prevent this and force a relocation when the first symbols | |
19221 | is a thumb function. */ | |
c921be7d NC |
19222 | |
19223 | bfd_boolean | |
a8bc6c78 PB |
19224 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
19225 | { | |
19226 | if (op == O_subtract | |
19227 | && l->X_op == O_symbol | |
19228 | && r->X_op == O_symbol | |
19229 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
19230 | { | |
19231 | l->X_op = O_subtract; | |
19232 | l->X_op_symbol = r->X_add_symbol; | |
19233 | l->X_add_number -= r->X_add_number; | |
c921be7d | 19234 | return TRUE; |
a8bc6c78 | 19235 | } |
c921be7d | 19236 | |
a8bc6c78 | 19237 | /* Process as normal. */ |
c921be7d | 19238 | return FALSE; |
a8bc6c78 PB |
19239 | } |
19240 | ||
c19d1205 | 19241 | void |
55cf6793 | 19242 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
19243 | valueT * valP, |
19244 | segT seg) | |
19245 | { | |
19246 | offsetT value = * valP; | |
19247 | offsetT newval; | |
19248 | unsigned int newimm; | |
19249 | unsigned long temp; | |
19250 | int sign; | |
19251 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 19252 | |
9c2799c2 | 19253 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 19254 | |
c19d1205 | 19255 | /* Note whether this will delete the relocation. */ |
4962c51a | 19256 | |
c19d1205 ZW |
19257 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
19258 | fixP->fx_done = 1; | |
b99bd4ef | 19259 | |
adbaf948 | 19260 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 19261 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
19262 | for emit_reloc. */ |
19263 | value &= 0xffffffff; | |
19264 | value ^= 0x80000000; | |
5f4273c7 | 19265 | value -= 0x80000000; |
adbaf948 ZW |
19266 | |
19267 | *valP = value; | |
c19d1205 | 19268 | fixP->fx_addnumber = value; |
b99bd4ef | 19269 | |
adbaf948 ZW |
19270 | /* Same treatment for fixP->fx_offset. */ |
19271 | fixP->fx_offset &= 0xffffffff; | |
19272 | fixP->fx_offset ^= 0x80000000; | |
19273 | fixP->fx_offset -= 0x80000000; | |
19274 | ||
c19d1205 | 19275 | switch (fixP->fx_r_type) |
b99bd4ef | 19276 | { |
c19d1205 ZW |
19277 | case BFD_RELOC_NONE: |
19278 | /* This will need to go in the object file. */ | |
19279 | fixP->fx_done = 0; | |
19280 | break; | |
b99bd4ef | 19281 | |
c19d1205 ZW |
19282 | case BFD_RELOC_ARM_IMMEDIATE: |
19283 | /* We claim that this fixup has been processed here, | |
19284 | even if in fact we generate an error because we do | |
19285 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19286 | fixP->fx_done = 1; | |
b99bd4ef | 19287 | |
c19d1205 ZW |
19288 | if (fixP->fx_addsy |
19289 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 19290 | { |
c19d1205 ZW |
19291 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19292 | _("undefined symbol %s used as an immediate value"), | |
19293 | S_GET_NAME (fixP->fx_addsy)); | |
19294 | break; | |
b99bd4ef NC |
19295 | } |
19296 | ||
42e5fcbf AS |
19297 | if (fixP->fx_addsy |
19298 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19299 | { | |
19300 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19301 | _("symbol %s is in a different section"), | |
19302 | S_GET_NAME (fixP->fx_addsy)); | |
19303 | break; | |
19304 | } | |
19305 | ||
c19d1205 ZW |
19306 | newimm = encode_arm_immediate (value); |
19307 | temp = md_chars_to_number (buf, INSN_SIZE); | |
19308 | ||
19309 | /* If the instruction will fail, see if we can fix things up by | |
19310 | changing the opcode. */ | |
19311 | if (newimm == (unsigned int) FAIL | |
19312 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 19313 | { |
c19d1205 ZW |
19314 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19315 | _("invalid constant (%lx) after fixup"), | |
19316 | (unsigned long) value); | |
19317 | break; | |
b99bd4ef | 19318 | } |
b99bd4ef | 19319 | |
c19d1205 ZW |
19320 | newimm |= (temp & 0xfffff000); |
19321 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
19322 | break; | |
b99bd4ef | 19323 | |
c19d1205 ZW |
19324 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
19325 | { | |
19326 | unsigned int highpart = 0; | |
19327 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 19328 | |
42e5fcbf AS |
19329 | if (fixP->fx_addsy |
19330 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19331 | { | |
19332 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19333 | _("undefined symbol %s used as an immediate value"), | |
19334 | S_GET_NAME (fixP->fx_addsy)); | |
19335 | break; | |
19336 | } | |
19337 | ||
19338 | if (fixP->fx_addsy | |
19339 | && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
19340 | { | |
19341 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19342 | _("symbol %s is in a different section"), | |
19343 | S_GET_NAME (fixP->fx_addsy)); | |
19344 | break; | |
19345 | } | |
19346 | ||
c19d1205 ZW |
19347 | newimm = encode_arm_immediate (value); |
19348 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 19349 | |
c19d1205 ZW |
19350 | /* If the instruction will fail, see if we can fix things up by |
19351 | changing the opcode. */ | |
19352 | if (newimm == (unsigned int) FAIL | |
19353 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
19354 | { | |
19355 | /* No ? OK - try using two ADD instructions to generate | |
19356 | the value. */ | |
19357 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 19358 | |
c19d1205 ZW |
19359 | /* Yes - then make sure that the second instruction is |
19360 | also an add. */ | |
19361 | if (newimm != (unsigned int) FAIL) | |
19362 | newinsn = temp; | |
19363 | /* Still No ? Try using a negated value. */ | |
19364 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
19365 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
19366 | /* Otherwise - give up. */ | |
19367 | else | |
19368 | { | |
19369 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19370 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
19371 | (long) value); | |
19372 | break; | |
19373 | } | |
b99bd4ef | 19374 | |
c19d1205 ZW |
19375 | /* Replace the first operand in the 2nd instruction (which |
19376 | is the PC) with the destination register. We have | |
19377 | already added in the PC in the first instruction and we | |
19378 | do not want to do it again. */ | |
19379 | newinsn &= ~ 0xf0000; | |
19380 | newinsn |= ((newinsn & 0x0f000) << 4); | |
19381 | } | |
b99bd4ef | 19382 | |
c19d1205 ZW |
19383 | newimm |= (temp & 0xfffff000); |
19384 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 19385 | |
c19d1205 ZW |
19386 | highpart |= (newinsn & 0xfffff000); |
19387 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
19388 | } | |
19389 | break; | |
b99bd4ef | 19390 | |
c19d1205 | 19391 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
19392 | if (!fixP->fx_done && seg->use_rela_p) |
19393 | value = 0; | |
19394 | ||
c19d1205 ZW |
19395 | case BFD_RELOC_ARM_LITERAL: |
19396 | sign = value >= 0; | |
b99bd4ef | 19397 | |
c19d1205 ZW |
19398 | if (value < 0) |
19399 | value = - value; | |
b99bd4ef | 19400 | |
c19d1205 | 19401 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 19402 | { |
c19d1205 ZW |
19403 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
19404 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19405 | _("invalid literal constant: pool needs to be closer")); | |
19406 | else | |
19407 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19408 | _("bad immediate value for offset (%ld)"), | |
19409 | (long) value); | |
19410 | break; | |
f03698e6 RE |
19411 | } |
19412 | ||
c19d1205 ZW |
19413 | newval = md_chars_to_number (buf, INSN_SIZE); |
19414 | newval &= 0xff7ff000; | |
19415 | newval |= value | (sign ? INDEX_UP : 0); | |
19416 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19417 | break; | |
b99bd4ef | 19418 | |
c19d1205 ZW |
19419 | case BFD_RELOC_ARM_OFFSET_IMM8: |
19420 | case BFD_RELOC_ARM_HWLITERAL: | |
19421 | sign = value >= 0; | |
b99bd4ef | 19422 | |
c19d1205 ZW |
19423 | if (value < 0) |
19424 | value = - value; | |
b99bd4ef | 19425 | |
c19d1205 | 19426 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 19427 | { |
c19d1205 ZW |
19428 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
19429 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19430 | _("invalid literal constant: pool needs to be closer")); | |
19431 | else | |
f9d4405b | 19432 | as_bad (_("bad immediate value for 8-bit offset (%ld)"), |
c19d1205 ZW |
19433 | (long) value); |
19434 | break; | |
b99bd4ef NC |
19435 | } |
19436 | ||
c19d1205 ZW |
19437 | newval = md_chars_to_number (buf, INSN_SIZE); |
19438 | newval &= 0xff7ff0f0; | |
19439 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
19440 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19441 | break; | |
b99bd4ef | 19442 | |
c19d1205 ZW |
19443 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
19444 | if (value < 0 || value > 1020 || value % 4 != 0) | |
19445 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19446 | _("bad immediate value for offset (%ld)"), (long) value); | |
19447 | value /= 4; | |
b99bd4ef | 19448 | |
c19d1205 | 19449 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
19450 | newval |= value; |
19451 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
19452 | break; | |
b99bd4ef | 19453 | |
c19d1205 ZW |
19454 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
19455 | /* This is a complicated relocation used for all varieties of Thumb32 | |
19456 | load/store instruction with immediate offset: | |
19457 | ||
19458 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
19459 | *4, optional writeback(W) | |
19460 | (doubleword load/store) | |
19461 | ||
19462 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
19463 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
19464 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
19465 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
19466 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
19467 | ||
19468 | Uppercase letters indicate bits that are already encoded at | |
19469 | this point. Lowercase letters are our problem. For the | |
19470 | second block of instructions, the secondary opcode nybble | |
19471 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
19472 | a PC-relative operation. */ | |
19473 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19474 | newval <<= 16; | |
19475 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 19476 | |
c19d1205 | 19477 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 19478 | { |
c19d1205 ZW |
19479 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
19480 | if (value >= 0) | |
19481 | newval |= (1 << 23); | |
19482 | else | |
19483 | value = -value; | |
19484 | if (value % 4 != 0) | |
19485 | { | |
19486 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19487 | _("offset not a multiple of 4")); | |
19488 | break; | |
19489 | } | |
19490 | value /= 4; | |
216d22bc | 19491 | if (value > 0xff) |
c19d1205 ZW |
19492 | { |
19493 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19494 | _("offset out of range")); | |
19495 | break; | |
19496 | } | |
19497 | newval &= ~0xff; | |
b99bd4ef | 19498 | } |
c19d1205 | 19499 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 19500 | { |
c19d1205 ZW |
19501 | /* PC-relative, 12-bit offset. */ |
19502 | if (value >= 0) | |
19503 | newval |= (1 << 23); | |
19504 | else | |
19505 | value = -value; | |
216d22bc | 19506 | if (value > 0xfff) |
c19d1205 ZW |
19507 | { |
19508 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19509 | _("offset out of range")); | |
19510 | break; | |
19511 | } | |
19512 | newval &= ~0xfff; | |
b99bd4ef | 19513 | } |
c19d1205 | 19514 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 19515 | { |
c19d1205 ZW |
19516 | /* Writeback: 8-bit, +/- offset. */ |
19517 | if (value >= 0) | |
19518 | newval |= (1 << 9); | |
19519 | else | |
19520 | value = -value; | |
216d22bc | 19521 | if (value > 0xff) |
c19d1205 ZW |
19522 | { |
19523 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19524 | _("offset out of range")); | |
19525 | break; | |
19526 | } | |
19527 | newval &= ~0xff; | |
b99bd4ef | 19528 | } |
c19d1205 | 19529 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 19530 | { |
c19d1205 | 19531 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 19532 | if (value < 0 || value > 0xff) |
b99bd4ef | 19533 | { |
c19d1205 ZW |
19534 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19535 | _("offset out of range")); | |
19536 | break; | |
b99bd4ef | 19537 | } |
c19d1205 ZW |
19538 | newval &= ~0xff; |
19539 | newval |= value; | |
b99bd4ef NC |
19540 | } |
19541 | else | |
b99bd4ef | 19542 | { |
c19d1205 ZW |
19543 | /* Positive 12-bit or negative 8-bit offset. */ |
19544 | int limit; | |
19545 | if (value >= 0) | |
b99bd4ef | 19546 | { |
c19d1205 ZW |
19547 | newval |= (1 << 23); |
19548 | limit = 0xfff; | |
19549 | } | |
19550 | else | |
19551 | { | |
19552 | value = -value; | |
19553 | limit = 0xff; | |
19554 | } | |
19555 | if (value > limit) | |
19556 | { | |
19557 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19558 | _("offset out of range")); | |
19559 | break; | |
b99bd4ef | 19560 | } |
c19d1205 | 19561 | newval &= ~limit; |
b99bd4ef | 19562 | } |
b99bd4ef | 19563 | |
c19d1205 ZW |
19564 | newval |= value; |
19565 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
19566 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
19567 | break; | |
404ff6b5 | 19568 | |
c19d1205 ZW |
19569 | case BFD_RELOC_ARM_SHIFT_IMM: |
19570 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19571 | if (((unsigned long) value) > 32 | |
19572 | || (value == 32 | |
19573 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
19574 | { | |
19575 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19576 | _("shift expression is too large")); | |
19577 | break; | |
19578 | } | |
404ff6b5 | 19579 | |
c19d1205 ZW |
19580 | if (value == 0) |
19581 | /* Shifts of zero must be done as lsl. */ | |
19582 | newval &= ~0x60; | |
19583 | else if (value == 32) | |
19584 | value = 0; | |
19585 | newval &= 0xfffff07f; | |
19586 | newval |= (value & 0x1f) << 7; | |
19587 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19588 | break; | |
404ff6b5 | 19589 | |
c19d1205 | 19590 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 19591 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 19592 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 19593 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
19594 | /* We claim that this fixup has been processed here, |
19595 | even if in fact we generate an error because we do | |
19596 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
19597 | fixP->fx_done = 1; | |
404ff6b5 | 19598 | |
c19d1205 ZW |
19599 | if (fixP->fx_addsy |
19600 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
19601 | { | |
19602 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19603 | _("undefined symbol %s used as an immediate value"), | |
19604 | S_GET_NAME (fixP->fx_addsy)); | |
19605 | break; | |
19606 | } | |
404ff6b5 | 19607 | |
c19d1205 ZW |
19608 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19609 | newval <<= 16; | |
19610 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 19611 | |
16805f35 PB |
19612 | newimm = FAIL; |
19613 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
19614 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
19615 | { |
19616 | newimm = encode_thumb32_immediate (value); | |
19617 | if (newimm == (unsigned int) FAIL) | |
19618 | newimm = thumb32_negate_data_op (&newval, value); | |
19619 | } | |
16805f35 PB |
19620 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
19621 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 19622 | { |
16805f35 PB |
19623 | /* Turn add/sum into addw/subw. */ |
19624 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
19625 | newval = (newval & 0xfeffffff) | 0x02000000; | |
19626 | ||
e9f89963 PB |
19627 | /* 12 bit immediate for addw/subw. */ |
19628 | if (value < 0) | |
19629 | { | |
19630 | value = -value; | |
19631 | newval ^= 0x00a00000; | |
19632 | } | |
92e90b6e PB |
19633 | if (value > 0xfff) |
19634 | newimm = (unsigned int) FAIL; | |
19635 | else | |
19636 | newimm = value; | |
19637 | } | |
cc8a6dd0 | 19638 | |
c19d1205 | 19639 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 19640 | { |
c19d1205 ZW |
19641 | as_bad_where (fixP->fx_file, fixP->fx_line, |
19642 | _("invalid constant (%lx) after fixup"), | |
19643 | (unsigned long) value); | |
19644 | break; | |
3631a3c8 NC |
19645 | } |
19646 | ||
c19d1205 ZW |
19647 | newval |= (newimm & 0x800) << 15; |
19648 | newval |= (newimm & 0x700) << 4; | |
19649 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 19650 | |
c19d1205 ZW |
19651 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
19652 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
19653 | break; | |
a737bd4d | 19654 | |
3eb17e6b | 19655 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
19656 | if (((unsigned long) value) > 0xffff) |
19657 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 19658 | _("invalid smc expression")); |
2fc8bdac | 19659 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19660 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
19661 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19662 | break; | |
a737bd4d | 19663 | |
c19d1205 | 19664 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 19665 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
19666 | { |
19667 | if (((unsigned long) value) > 0xff) | |
19668 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19669 | _("invalid swi expression")); | |
2fc8bdac | 19670 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
19671 | newval |= value; |
19672 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19673 | } | |
19674 | else | |
19675 | { | |
19676 | if (((unsigned long) value) > 0x00ffffff) | |
19677 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19678 | _("invalid swi expression")); | |
2fc8bdac | 19679 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
19680 | newval |= value; |
19681 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19682 | } | |
19683 | break; | |
a737bd4d | 19684 | |
c19d1205 ZW |
19685 | case BFD_RELOC_ARM_MULTI: |
19686 | if (((unsigned long) value) > 0xffff) | |
19687 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19688 | _("invalid expression in load/store multiple")); | |
19689 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
19690 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19691 | break; | |
a737bd4d | 19692 | |
c19d1205 | 19693 | #ifdef OBJ_ELF |
39b41c9c | 19694 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
19695 | |
19696 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
19697 | && fixP->fx_addsy | |
19698 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19699 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19700 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19701 | /* Flip the bl to blx. This is a simple flip | |
19702 | bit here because we generate PCREL_CALL for | |
19703 | unconditional bls. */ | |
19704 | { | |
19705 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19706 | newval = newval | 0x10000000; | |
19707 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19708 | temp = 1; | |
19709 | fixP->fx_done = 1; | |
19710 | } | |
39b41c9c PB |
19711 | else |
19712 | temp = 3; | |
19713 | goto arm_branch_common; | |
19714 | ||
19715 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
19716 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19717 | && fixP->fx_addsy | |
19718 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19719 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19720 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19721 | { | |
19722 | /* This would map to a bl<cond>, b<cond>, | |
19723 | b<always> to a Thumb function. We | |
19724 | need to force a relocation for this particular | |
19725 | case. */ | |
19726 | newval = md_chars_to_number (buf, INSN_SIZE); | |
19727 | fixP->fx_done = 0; | |
19728 | } | |
19729 | ||
2fc8bdac | 19730 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 19731 | #endif |
39b41c9c PB |
19732 | case BFD_RELOC_ARM_PCREL_BRANCH: |
19733 | temp = 3; | |
19734 | goto arm_branch_common; | |
a737bd4d | 19735 | |
39b41c9c | 19736 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 19737 | |
39b41c9c | 19738 | temp = 1; |
267bf995 RR |
19739 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
19740 | && fixP->fx_addsy | |
19741 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19742 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19743 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
19744 | { | |
19745 | /* Flip the blx to a bl and warn. */ | |
19746 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
19747 | newval = 0xeb000000; | |
19748 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
19749 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
19750 | name); | |
19751 | md_number_to_chars (buf, newval, INSN_SIZE); | |
19752 | temp = 3; | |
19753 | fixP->fx_done = 1; | |
19754 | } | |
19755 | ||
19756 | #ifdef OBJ_ELF | |
19757 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
19758 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; | |
19759 | #endif | |
19760 | ||
39b41c9c | 19761 | arm_branch_common: |
c19d1205 | 19762 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
19763 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
19764 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
19765 | also be be clear. */ | |
19766 | if (value & temp) | |
c19d1205 | 19767 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
19768 | _("misaligned branch destination")); |
19769 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
19770 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
19771 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19772 | _("branch out of range")); | |
a737bd4d | 19773 | |
2fc8bdac | 19774 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19775 | { |
2fc8bdac ZW |
19776 | newval = md_chars_to_number (buf, INSN_SIZE); |
19777 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
19778 | /* Set the H bit on BLX instructions. */ |
19779 | if (temp == 1) | |
19780 | { | |
19781 | if (value & 2) | |
19782 | newval |= 0x01000000; | |
19783 | else | |
19784 | newval &= ~0x01000000; | |
19785 | } | |
2fc8bdac | 19786 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 19787 | } |
c19d1205 | 19788 | break; |
a737bd4d | 19789 | |
25fe350b MS |
19790 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
19791 | /* CBZ can only branch forward. */ | |
a737bd4d | 19792 | |
738755b0 MS |
19793 | /* Attempts to use CBZ to branch to the next instruction |
19794 | (which, strictly speaking, are prohibited) will be turned into | |
19795 | no-ops. | |
19796 | ||
19797 | FIXME: It may be better to remove the instruction completely and | |
19798 | perform relaxation. */ | |
19799 | if (value == -2) | |
2fc8bdac ZW |
19800 | { |
19801 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 19802 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
19803 | md_number_to_chars (buf, newval, THUMB_SIZE); |
19804 | } | |
738755b0 MS |
19805 | else |
19806 | { | |
19807 | if (value & ~0x7e) | |
19808 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19809 | _("branch out of range")); | |
19810 | ||
19811 | if (fixP->fx_done || !seg->use_rela_p) | |
19812 | { | |
19813 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19814 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
19815 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19816 | } | |
19817 | } | |
c19d1205 | 19818 | break; |
a737bd4d | 19819 | |
c19d1205 | 19820 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
19821 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
19822 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19823 | _("branch out of range")); | |
a737bd4d | 19824 | |
2fc8bdac ZW |
19825 | if (fixP->fx_done || !seg->use_rela_p) |
19826 | { | |
19827 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19828 | newval |= (value & 0x1ff) >> 1; | |
19829 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19830 | } | |
c19d1205 | 19831 | break; |
a737bd4d | 19832 | |
c19d1205 | 19833 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
19834 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
19835 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19836 | _("branch out of range")); | |
a737bd4d | 19837 | |
2fc8bdac ZW |
19838 | if (fixP->fx_done || !seg->use_rela_p) |
19839 | { | |
19840 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19841 | newval |= (value & 0xfff) >> 1; | |
19842 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19843 | } | |
c19d1205 | 19844 | break; |
a737bd4d | 19845 | |
c19d1205 | 19846 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
19847 | if (fixP->fx_addsy |
19848 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19849 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19850 | && S_IS_DEFINED (fixP->fx_addsy) | |
19851 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19852 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19853 | { | |
19854 | /* Force a relocation for a branch 20 bits wide. */ | |
19855 | fixP->fx_done = 0; | |
19856 | } | |
2fc8bdac ZW |
19857 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
19858 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19859 | _("conditional branch out of range")); | |
404ff6b5 | 19860 | |
2fc8bdac ZW |
19861 | if (fixP->fx_done || !seg->use_rela_p) |
19862 | { | |
19863 | offsetT newval2; | |
19864 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 19865 | |
2fc8bdac ZW |
19866 | S = (value & 0x00100000) >> 20; |
19867 | J2 = (value & 0x00080000) >> 19; | |
19868 | J1 = (value & 0x00040000) >> 18; | |
19869 | hi = (value & 0x0003f000) >> 12; | |
19870 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 19871 | |
2fc8bdac ZW |
19872 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19873 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19874 | newval |= (S << 10) | hi; | |
19875 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
19876 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19877 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
19878 | } | |
c19d1205 | 19879 | break; |
6c43fab6 | 19880 | |
c19d1205 | 19881 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
19882 | |
19883 | /* If there is a blx from a thumb state function to | |
19884 | another thumb function flip this to a bl and warn | |
19885 | about it. */ | |
19886 | ||
19887 | if (fixP->fx_addsy | |
19888 | && S_IS_DEFINED (fixP->fx_addsy) | |
19889 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19890 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19891 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
19892 | { | |
19893 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
19894 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
19895 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
19896 | name); | |
19897 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19898 | newval = newval | 0x1000; | |
19899 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
19900 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
19901 | fixP->fx_done = 1; | |
19902 | } | |
19903 | ||
19904 | ||
19905 | goto thumb_bl_common; | |
19906 | ||
c19d1205 | 19907 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
19908 | |
19909 | /* A bl from Thumb state ISA to an internal ARM state function | |
19910 | is converted to a blx. */ | |
19911 | if (fixP->fx_addsy | |
19912 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
19913 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
19914 | && S_IS_DEFINED (fixP->fx_addsy) | |
19915 | && ARM_IS_FUNC (fixP->fx_addsy) | |
19916 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
19917 | { | |
19918 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19919 | newval = newval & ~0x1000; | |
19920 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
19921 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
19922 | fixP->fx_done = 1; | |
19923 | } | |
19924 | ||
19925 | thumb_bl_common: | |
19926 | ||
19927 | #ifdef OBJ_ELF | |
19928 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 && | |
19929 | fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
19930 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
19931 | #endif | |
19932 | ||
2fc8bdac ZW |
19933 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
19934 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19935 | _("branch out of range")); | |
404ff6b5 | 19936 | |
2fc8bdac ZW |
19937 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
19938 | /* For a BLX instruction, make sure that the relocation is rounded up | |
19939 | to a word boundary. This follows the semantics of the instruction | |
19940 | which specifies that bit 1 of the target address will come from bit | |
19941 | 1 of the base address. */ | |
19942 | value = (value + 1) & ~ 1; | |
404ff6b5 | 19943 | |
2fc8bdac | 19944 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19945 | { |
2fc8bdac ZW |
19946 | offsetT newval2; |
19947 | ||
19948 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
19949 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19950 | newval |= (value & 0x7fffff) >> 12; | |
19951 | newval2 |= (value & 0xfff) >> 1; | |
19952 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19953 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 19954 | } |
c19d1205 | 19955 | break; |
404ff6b5 | 19956 | |
c19d1205 | 19957 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
19958 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
19959 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
19960 | _("branch out of range")); | |
6c43fab6 | 19961 | |
2fc8bdac ZW |
19962 | if (fixP->fx_done || !seg->use_rela_p) |
19963 | { | |
19964 | offsetT newval2; | |
19965 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 19966 | |
2fc8bdac ZW |
19967 | S = (value & 0x01000000) >> 24; |
19968 | I1 = (value & 0x00800000) >> 23; | |
19969 | I2 = (value & 0x00400000) >> 22; | |
19970 | hi = (value & 0x003ff000) >> 12; | |
19971 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 19972 | |
2fc8bdac ZW |
19973 | I1 = !(I1 ^ S); |
19974 | I2 = !(I2 ^ S); | |
a737bd4d | 19975 | |
2fc8bdac ZW |
19976 | newval = md_chars_to_number (buf, THUMB_SIZE); |
19977 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
19978 | newval |= (S << 10) | hi; | |
19979 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
19980 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
19981 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
19982 | } | |
19983 | break; | |
a737bd4d | 19984 | |
2fc8bdac ZW |
19985 | case BFD_RELOC_8: |
19986 | if (fixP->fx_done || !seg->use_rela_p) | |
19987 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 19988 | break; |
a737bd4d | 19989 | |
c19d1205 | 19990 | case BFD_RELOC_16: |
2fc8bdac | 19991 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 19992 | md_number_to_chars (buf, value, 2); |
c19d1205 | 19993 | break; |
a737bd4d | 19994 | |
c19d1205 ZW |
19995 | #ifdef OBJ_ELF |
19996 | case BFD_RELOC_ARM_TLS_GD32: | |
19997 | case BFD_RELOC_ARM_TLS_LE32: | |
19998 | case BFD_RELOC_ARM_TLS_IE32: | |
19999 | case BFD_RELOC_ARM_TLS_LDM32: | |
20000 | case BFD_RELOC_ARM_TLS_LDO32: | |
20001 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
20002 | /* fall through */ | |
6c43fab6 | 20003 | |
c19d1205 ZW |
20004 | case BFD_RELOC_ARM_GOT32: |
20005 | case BFD_RELOC_ARM_GOTOFF: | |
20006 | case BFD_RELOC_ARM_TARGET2: | |
2fc8bdac ZW |
20007 | if (fixP->fx_done || !seg->use_rela_p) |
20008 | md_number_to_chars (buf, 0, 4); | |
c19d1205 ZW |
20009 | break; |
20010 | #endif | |
6c43fab6 | 20011 | |
c19d1205 ZW |
20012 | case BFD_RELOC_RVA: |
20013 | case BFD_RELOC_32: | |
20014 | case BFD_RELOC_ARM_TARGET1: | |
20015 | case BFD_RELOC_ARM_ROSEGREL32: | |
20016 | case BFD_RELOC_ARM_SBREL32: | |
20017 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
20018 | #ifdef TE_PE |
20019 | case BFD_RELOC_32_SECREL: | |
20020 | #endif | |
2fc8bdac | 20021 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
20022 | #ifdef TE_WINCE |
20023 | /* For WinCE we only do this for pcrel fixups. */ | |
20024 | if (fixP->fx_done || fixP->fx_pcrel) | |
20025 | #endif | |
20026 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 20027 | break; |
6c43fab6 | 20028 | |
c19d1205 ZW |
20029 | #ifdef OBJ_ELF |
20030 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 20031 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
20032 | { |
20033 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
20034 | if ((value ^ (value >> 1)) & 0x40000000) | |
20035 | { | |
20036 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20037 | _("rel31 relocation overflow")); | |
20038 | } | |
20039 | newval |= value & 0x7fffffff; | |
20040 | md_number_to_chars (buf, newval, 4); | |
20041 | } | |
20042 | break; | |
c19d1205 | 20043 | #endif |
a737bd4d | 20044 | |
c19d1205 | 20045 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 20046 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
20047 | if (value < -1023 || value > 1023 || (value & 3)) |
20048 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20049 | _("co-processor offset out of range")); | |
20050 | cp_off_common: | |
20051 | sign = value >= 0; | |
20052 | if (value < 0) | |
20053 | value = -value; | |
8f06b2d8 PB |
20054 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20055 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20056 | newval = md_chars_to_number (buf, INSN_SIZE); | |
20057 | else | |
20058 | newval = get_thumb32_insn (buf); | |
20059 | newval &= 0xff7fff00; | |
c19d1205 | 20060 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
8f06b2d8 PB |
20061 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
20062 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
20063 | md_number_to_chars (buf, newval, INSN_SIZE); | |
20064 | else | |
20065 | put_thumb32_insn (buf, newval); | |
c19d1205 | 20066 | break; |
a737bd4d | 20067 | |
c19d1205 | 20068 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 20069 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
20070 | if (value < -255 || value > 255) |
20071 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20072 | _("co-processor offset out of range")); | |
df7849c5 | 20073 | value *= 4; |
c19d1205 | 20074 | goto cp_off_common; |
6c43fab6 | 20075 | |
c19d1205 ZW |
20076 | case BFD_RELOC_ARM_THUMB_OFFSET: |
20077 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20078 | /* Exactly what ranges, and where the offset is inserted depends | |
20079 | on the type of instruction, we can establish this from the | |
20080 | top 4 bits. */ | |
20081 | switch (newval >> 12) | |
20082 | { | |
20083 | case 4: /* PC load. */ | |
20084 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
20085 | forced to zero for these loads; md_pcrel_from has already | |
20086 | compensated for this. */ | |
20087 | if (value & 3) | |
20088 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20089 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
20090 | (((unsigned long) fixP->fx_frag->fr_address |
20091 | + (unsigned long) fixP->fx_where) & ~3) | |
20092 | + (unsigned long) value); | |
a737bd4d | 20093 | |
c19d1205 ZW |
20094 | if (value & ~0x3fc) |
20095 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20096 | _("invalid offset, value too big (0x%08lX)"), | |
20097 | (long) value); | |
a737bd4d | 20098 | |
c19d1205 ZW |
20099 | newval |= value >> 2; |
20100 | break; | |
a737bd4d | 20101 | |
c19d1205 ZW |
20102 | case 9: /* SP load/store. */ |
20103 | if (value & ~0x3fc) | |
20104 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20105 | _("invalid offset, value too big (0x%08lX)"), | |
20106 | (long) value); | |
20107 | newval |= value >> 2; | |
20108 | break; | |
6c43fab6 | 20109 | |
c19d1205 ZW |
20110 | case 6: /* Word load/store. */ |
20111 | if (value & ~0x7c) | |
20112 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20113 | _("invalid offset, value too big (0x%08lX)"), | |
20114 | (long) value); | |
20115 | newval |= value << 4; /* 6 - 2. */ | |
20116 | break; | |
a737bd4d | 20117 | |
c19d1205 ZW |
20118 | case 7: /* Byte load/store. */ |
20119 | if (value & ~0x1f) | |
20120 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20121 | _("invalid offset, value too big (0x%08lX)"), | |
20122 | (long) value); | |
20123 | newval |= value << 6; | |
20124 | break; | |
a737bd4d | 20125 | |
c19d1205 ZW |
20126 | case 8: /* Halfword load/store. */ |
20127 | if (value & ~0x3e) | |
20128 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20129 | _("invalid offset, value too big (0x%08lX)"), | |
20130 | (long) value); | |
20131 | newval |= value << 5; /* 6 - 1. */ | |
20132 | break; | |
a737bd4d | 20133 | |
c19d1205 ZW |
20134 | default: |
20135 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20136 | "Unable to process relocation for thumb opcode: %lx", | |
20137 | (unsigned long) newval); | |
20138 | break; | |
20139 | } | |
20140 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20141 | break; | |
a737bd4d | 20142 | |
c19d1205 ZW |
20143 | case BFD_RELOC_ARM_THUMB_ADD: |
20144 | /* This is a complicated relocation, since we use it for all of | |
20145 | the following immediate relocations: | |
a737bd4d | 20146 | |
c19d1205 ZW |
20147 | 3bit ADD/SUB |
20148 | 8bit ADD/SUB | |
20149 | 9bit ADD/SUB SP word-aligned | |
20150 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 20151 | |
c19d1205 ZW |
20152 | The type of instruction being processed is encoded in the |
20153 | instruction field: | |
a737bd4d | 20154 | |
c19d1205 ZW |
20155 | 0x8000 SUB |
20156 | 0x00F0 Rd | |
20157 | 0x000F Rs | |
20158 | */ | |
20159 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20160 | { | |
20161 | int rd = (newval >> 4) & 0xf; | |
20162 | int rs = newval & 0xf; | |
20163 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 20164 | |
c19d1205 ZW |
20165 | /* Check for HI regs, only very restricted cases allowed: |
20166 | Adjusting SP, and using PC or SP to get an address. */ | |
20167 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
20168 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
20169 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20170 | _("invalid Hi register with immediate")); | |
a737bd4d | 20171 | |
c19d1205 ZW |
20172 | /* If value is negative, choose the opposite instruction. */ |
20173 | if (value < 0) | |
20174 | { | |
20175 | value = -value; | |
20176 | subtract = !subtract; | |
20177 | if (value < 0) | |
20178 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20179 | _("immediate value out of range")); | |
20180 | } | |
a737bd4d | 20181 | |
c19d1205 ZW |
20182 | if (rd == REG_SP) |
20183 | { | |
20184 | if (value & ~0x1fc) | |
20185 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20186 | _("invalid immediate for stack address calculation")); | |
20187 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
20188 | newval |= value >> 2; | |
20189 | } | |
20190 | else if (rs == REG_PC || rs == REG_SP) | |
20191 | { | |
20192 | if (subtract || value & ~0x3fc) | |
20193 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20194 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
20195 | (unsigned long) value); | |
20196 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
20197 | newval |= rd << 8; | |
20198 | newval |= value >> 2; | |
20199 | } | |
20200 | else if (rs == rd) | |
20201 | { | |
20202 | if (value & ~0xff) | |
20203 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20204 | _("immediate value out of range")); | |
20205 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
20206 | newval |= (rd << 8) | value; | |
20207 | } | |
20208 | else | |
20209 | { | |
20210 | if (value & ~0x7) | |
20211 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20212 | _("immediate value out of range")); | |
20213 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
20214 | newval |= rd | (rs << 3) | (value << 6); | |
20215 | } | |
20216 | } | |
20217 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20218 | break; | |
a737bd4d | 20219 | |
c19d1205 ZW |
20220 | case BFD_RELOC_ARM_THUMB_IMM: |
20221 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
20222 | if (value < 0 || value > 255) | |
20223 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 20224 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
20225 | (long) value); |
20226 | newval |= value; | |
20227 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20228 | break; | |
a737bd4d | 20229 | |
c19d1205 ZW |
20230 | case BFD_RELOC_ARM_THUMB_SHIFT: |
20231 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
20232 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
20233 | temp = newval & 0xf800; | |
20234 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
20235 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20236 | _("invalid shift value: %ld"), (long) value); | |
20237 | /* Shifts of zero must be encoded as LSL. */ | |
20238 | if (value == 0) | |
20239 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
20240 | /* Shifts of 32 are encoded as zero. */ | |
20241 | else if (value == 32) | |
20242 | value = 0; | |
20243 | newval |= value << 6; | |
20244 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
20245 | break; | |
a737bd4d | 20246 | |
c19d1205 ZW |
20247 | case BFD_RELOC_VTABLE_INHERIT: |
20248 | case BFD_RELOC_VTABLE_ENTRY: | |
20249 | fixP->fx_done = 0; | |
20250 | return; | |
6c43fab6 | 20251 | |
b6895b4f PB |
20252 | case BFD_RELOC_ARM_MOVW: |
20253 | case BFD_RELOC_ARM_MOVT: | |
20254 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20255 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20256 | if (fixP->fx_done || !seg->use_rela_p) | |
20257 | { | |
20258 | /* REL format relocations are limited to a 16-bit addend. */ | |
20259 | if (!fixP->fx_done) | |
20260 | { | |
39623e12 | 20261 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 20262 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 20263 | _("offset out of range")); |
b6895b4f PB |
20264 | } |
20265 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
20266 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20267 | { | |
20268 | value >>= 16; | |
20269 | } | |
20270 | ||
20271 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
20272 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
20273 | { | |
20274 | newval = get_thumb32_insn (buf); | |
20275 | newval &= 0xfbf08f00; | |
20276 | newval |= (value & 0xf000) << 4; | |
20277 | newval |= (value & 0x0800) << 15; | |
20278 | newval |= (value & 0x0700) << 4; | |
20279 | newval |= (value & 0x00ff); | |
20280 | put_thumb32_insn (buf, newval); | |
20281 | } | |
20282 | else | |
20283 | { | |
20284 | newval = md_chars_to_number (buf, 4); | |
20285 | newval &= 0xfff0f000; | |
20286 | newval |= value & 0x0fff; | |
20287 | newval |= (value & 0xf000) << 4; | |
20288 | md_number_to_chars (buf, newval, 4); | |
20289 | } | |
20290 | } | |
20291 | return; | |
20292 | ||
4962c51a MS |
20293 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20294 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20295 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20296 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20297 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20298 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20299 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20300 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20301 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20302 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 20303 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20304 | if (!seg->use_rela_p) |
20305 | { | |
20306 | bfd_vma insn; | |
20307 | bfd_vma encoded_addend; | |
20308 | bfd_vma addend_abs = abs (value); | |
20309 | ||
20310 | /* Check that the absolute value of the addend can be | |
20311 | expressed as an 8-bit constant plus a rotation. */ | |
20312 | encoded_addend = encode_arm_immediate (addend_abs); | |
20313 | if (encoded_addend == (unsigned int) FAIL) | |
20314 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20315 | _("the offset 0x%08lX is not representable"), | |
495bde8e | 20316 | (unsigned long) addend_abs); |
4962c51a MS |
20317 | |
20318 | /* Extract the instruction. */ | |
20319 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20320 | ||
20321 | /* If the addend is positive, use an ADD instruction. | |
20322 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
20323 | insn &= 0xff1fffff; | |
20324 | if (value < 0) | |
20325 | insn |= 1 << 22; | |
20326 | else | |
20327 | insn |= 1 << 23; | |
20328 | ||
20329 | /* Place the encoded addend into the first 12 bits of the | |
20330 | instruction. */ | |
20331 | insn &= 0xfffff000; | |
20332 | insn |= encoded_addend; | |
5f4273c7 NC |
20333 | |
20334 | /* Update the instruction. */ | |
4962c51a MS |
20335 | md_number_to_chars (buf, insn, INSN_SIZE); |
20336 | } | |
20337 | break; | |
20338 | ||
20339 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20340 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20341 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20342 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20343 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20344 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 20345 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20346 | if (!seg->use_rela_p) |
20347 | { | |
20348 | bfd_vma insn; | |
20349 | bfd_vma addend_abs = abs (value); | |
20350 | ||
20351 | /* Check that the absolute value of the addend can be | |
20352 | encoded in 12 bits. */ | |
20353 | if (addend_abs >= 0x1000) | |
20354 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20355 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), | |
495bde8e | 20356 | (unsigned long) addend_abs); |
4962c51a MS |
20357 | |
20358 | /* Extract the instruction. */ | |
20359 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20360 | ||
20361 | /* If the addend is negative, clear bit 23 of the instruction. | |
20362 | Otherwise set it. */ | |
20363 | if (value < 0) | |
20364 | insn &= ~(1 << 23); | |
20365 | else | |
20366 | insn |= 1 << 23; | |
20367 | ||
20368 | /* Place the absolute value of the addend into the first 12 bits | |
20369 | of the instruction. */ | |
20370 | insn &= 0xfffff000; | |
20371 | insn |= addend_abs; | |
5f4273c7 NC |
20372 | |
20373 | /* Update the instruction. */ | |
4962c51a MS |
20374 | md_number_to_chars (buf, insn, INSN_SIZE); |
20375 | } | |
20376 | break; | |
20377 | ||
20378 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20379 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20380 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20381 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20382 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20383 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 20384 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20385 | if (!seg->use_rela_p) |
20386 | { | |
20387 | bfd_vma insn; | |
20388 | bfd_vma addend_abs = abs (value); | |
20389 | ||
20390 | /* Check that the absolute value of the addend can be | |
20391 | encoded in 8 bits. */ | |
20392 | if (addend_abs >= 0x100) | |
20393 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20394 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), | |
495bde8e | 20395 | (unsigned long) addend_abs); |
4962c51a MS |
20396 | |
20397 | /* Extract the instruction. */ | |
20398 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20399 | ||
20400 | /* If the addend is negative, clear bit 23 of the instruction. | |
20401 | Otherwise set it. */ | |
20402 | if (value < 0) | |
20403 | insn &= ~(1 << 23); | |
20404 | else | |
20405 | insn |= 1 << 23; | |
20406 | ||
20407 | /* Place the first four bits of the absolute value of the addend | |
20408 | into the first 4 bits of the instruction, and the remaining | |
20409 | four into bits 8 .. 11. */ | |
20410 | insn &= 0xfffff0f0; | |
20411 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
5f4273c7 NC |
20412 | |
20413 | /* Update the instruction. */ | |
4962c51a MS |
20414 | md_number_to_chars (buf, insn, INSN_SIZE); |
20415 | } | |
20416 | break; | |
20417 | ||
20418 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20419 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20420 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20421 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20422 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20423 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 20424 | gas_assert (!fixP->fx_done); |
4962c51a MS |
20425 | if (!seg->use_rela_p) |
20426 | { | |
20427 | bfd_vma insn; | |
20428 | bfd_vma addend_abs = abs (value); | |
20429 | ||
20430 | /* Check that the absolute value of the addend is a multiple of | |
20431 | four and, when divided by four, fits in 8 bits. */ | |
20432 | if (addend_abs & 0x3) | |
20433 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20434 | _("bad offset 0x%08lX (must be word-aligned)"), | |
495bde8e | 20435 | (unsigned long) addend_abs); |
4962c51a MS |
20436 | |
20437 | if ((addend_abs >> 2) > 0xff) | |
20438 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20439 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), | |
495bde8e | 20440 | (unsigned long) addend_abs); |
4962c51a MS |
20441 | |
20442 | /* Extract the instruction. */ | |
20443 | insn = md_chars_to_number (buf, INSN_SIZE); | |
20444 | ||
20445 | /* If the addend is negative, clear bit 23 of the instruction. | |
20446 | Otherwise set it. */ | |
20447 | if (value < 0) | |
20448 | insn &= ~(1 << 23); | |
20449 | else | |
20450 | insn |= 1 << 23; | |
20451 | ||
20452 | /* Place the addend (divided by four) into the first eight | |
20453 | bits of the instruction. */ | |
20454 | insn &= 0xfffffff0; | |
20455 | insn |= addend_abs >> 2; | |
5f4273c7 NC |
20456 | |
20457 | /* Update the instruction. */ | |
4962c51a MS |
20458 | md_number_to_chars (buf, insn, INSN_SIZE); |
20459 | } | |
20460 | break; | |
20461 | ||
845b51d6 PB |
20462 | case BFD_RELOC_ARM_V4BX: |
20463 | /* This will need to go in the object file. */ | |
20464 | fixP->fx_done = 0; | |
20465 | break; | |
20466 | ||
c19d1205 ZW |
20467 | case BFD_RELOC_UNUSED: |
20468 | default: | |
20469 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20470 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
20471 | } | |
6c43fab6 RE |
20472 | } |
20473 | ||
c19d1205 ZW |
20474 | /* Translate internal representation of relocation info to BFD target |
20475 | format. */ | |
a737bd4d | 20476 | |
c19d1205 | 20477 | arelent * |
00a97672 | 20478 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 20479 | { |
c19d1205 ZW |
20480 | arelent * reloc; |
20481 | bfd_reloc_code_real_type code; | |
a737bd4d | 20482 | |
c19d1205 | 20483 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 20484 | |
c19d1205 ZW |
20485 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
20486 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
20487 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 20488 | |
2fc8bdac | 20489 | if (fixp->fx_pcrel) |
00a97672 RS |
20490 | { |
20491 | if (section->use_rela_p) | |
20492 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
20493 | else | |
20494 | fixp->fx_offset = reloc->address; | |
20495 | } | |
c19d1205 | 20496 | reloc->addend = fixp->fx_offset; |
a737bd4d | 20497 | |
c19d1205 | 20498 | switch (fixp->fx_r_type) |
a737bd4d | 20499 | { |
c19d1205 ZW |
20500 | case BFD_RELOC_8: |
20501 | if (fixp->fx_pcrel) | |
20502 | { | |
20503 | code = BFD_RELOC_8_PCREL; | |
20504 | break; | |
20505 | } | |
a737bd4d | 20506 | |
c19d1205 ZW |
20507 | case BFD_RELOC_16: |
20508 | if (fixp->fx_pcrel) | |
20509 | { | |
20510 | code = BFD_RELOC_16_PCREL; | |
20511 | break; | |
20512 | } | |
6c43fab6 | 20513 | |
c19d1205 ZW |
20514 | case BFD_RELOC_32: |
20515 | if (fixp->fx_pcrel) | |
20516 | { | |
20517 | code = BFD_RELOC_32_PCREL; | |
20518 | break; | |
20519 | } | |
a737bd4d | 20520 | |
b6895b4f PB |
20521 | case BFD_RELOC_ARM_MOVW: |
20522 | if (fixp->fx_pcrel) | |
20523 | { | |
20524 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
20525 | break; | |
20526 | } | |
20527 | ||
20528 | case BFD_RELOC_ARM_MOVT: | |
20529 | if (fixp->fx_pcrel) | |
20530 | { | |
20531 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
20532 | break; | |
20533 | } | |
20534 | ||
20535 | case BFD_RELOC_ARM_THUMB_MOVW: | |
20536 | if (fixp->fx_pcrel) | |
20537 | { | |
20538 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
20539 | break; | |
20540 | } | |
20541 | ||
20542 | case BFD_RELOC_ARM_THUMB_MOVT: | |
20543 | if (fixp->fx_pcrel) | |
20544 | { | |
20545 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
20546 | break; | |
20547 | } | |
20548 | ||
c19d1205 ZW |
20549 | case BFD_RELOC_NONE: |
20550 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
20551 | case BFD_RELOC_ARM_PCREL_BLX: | |
20552 | case BFD_RELOC_RVA: | |
20553 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
20554 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
20555 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
20556 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20557 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20558 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
20559 | case BFD_RELOC_VTABLE_ENTRY: |
20560 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
20561 | #ifdef TE_PE |
20562 | case BFD_RELOC_32_SECREL: | |
20563 | #endif | |
c19d1205 ZW |
20564 | code = fixp->fx_r_type; |
20565 | break; | |
a737bd4d | 20566 | |
00adf2d4 JB |
20567 | case BFD_RELOC_THUMB_PCREL_BLX: |
20568 | #ifdef OBJ_ELF | |
20569 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
20570 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
20571 | else | |
20572 | #endif | |
20573 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
20574 | break; | |
20575 | ||
c19d1205 ZW |
20576 | case BFD_RELOC_ARM_LITERAL: |
20577 | case BFD_RELOC_ARM_HWLITERAL: | |
20578 | /* If this is called then the a literal has | |
20579 | been referenced across a section boundary. */ | |
20580 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20581 | _("literal referenced across section boundary")); | |
20582 | return NULL; | |
a737bd4d | 20583 | |
c19d1205 ZW |
20584 | #ifdef OBJ_ELF |
20585 | case BFD_RELOC_ARM_GOT32: | |
20586 | case BFD_RELOC_ARM_GOTOFF: | |
20587 | case BFD_RELOC_ARM_PLT32: | |
20588 | case BFD_RELOC_ARM_TARGET1: | |
20589 | case BFD_RELOC_ARM_ROSEGREL32: | |
20590 | case BFD_RELOC_ARM_SBREL32: | |
20591 | case BFD_RELOC_ARM_PREL31: | |
20592 | case BFD_RELOC_ARM_TARGET2: | |
20593 | case BFD_RELOC_ARM_TLS_LE32: | |
20594 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
20595 | case BFD_RELOC_ARM_PCREL_CALL: |
20596 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
20597 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
20598 | case BFD_RELOC_ARM_ALU_PC_G0: | |
20599 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
20600 | case BFD_RELOC_ARM_ALU_PC_G1: | |
20601 | case BFD_RELOC_ARM_ALU_PC_G2: | |
20602 | case BFD_RELOC_ARM_LDR_PC_G0: | |
20603 | case BFD_RELOC_ARM_LDR_PC_G1: | |
20604 | case BFD_RELOC_ARM_LDR_PC_G2: | |
20605 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
20606 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
20607 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
20608 | case BFD_RELOC_ARM_LDC_PC_G0: | |
20609 | case BFD_RELOC_ARM_LDC_PC_G1: | |
20610 | case BFD_RELOC_ARM_LDC_PC_G2: | |
20611 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
20612 | case BFD_RELOC_ARM_ALU_SB_G0: | |
20613 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
20614 | case BFD_RELOC_ARM_ALU_SB_G1: | |
20615 | case BFD_RELOC_ARM_ALU_SB_G2: | |
20616 | case BFD_RELOC_ARM_LDR_SB_G0: | |
20617 | case BFD_RELOC_ARM_LDR_SB_G1: | |
20618 | case BFD_RELOC_ARM_LDR_SB_G2: | |
20619 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
20620 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
20621 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
20622 | case BFD_RELOC_ARM_LDC_SB_G0: | |
20623 | case BFD_RELOC_ARM_LDC_SB_G1: | |
20624 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 20625 | case BFD_RELOC_ARM_V4BX: |
c19d1205 ZW |
20626 | code = fixp->fx_r_type; |
20627 | break; | |
a737bd4d | 20628 | |
c19d1205 ZW |
20629 | case BFD_RELOC_ARM_TLS_GD32: |
20630 | case BFD_RELOC_ARM_TLS_IE32: | |
20631 | case BFD_RELOC_ARM_TLS_LDM32: | |
20632 | /* BFD will include the symbol's address in the addend. | |
20633 | But we don't want that, so subtract it out again here. */ | |
20634 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
20635 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
20636 | code = fixp->fx_r_type; | |
20637 | break; | |
20638 | #endif | |
a737bd4d | 20639 | |
c19d1205 ZW |
20640 | case BFD_RELOC_ARM_IMMEDIATE: |
20641 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20642 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
20643 | return NULL; | |
a737bd4d | 20644 | |
c19d1205 ZW |
20645 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
20646 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20647 | _("ADRL used for a symbol not defined in the same file")); | |
20648 | return NULL; | |
a737bd4d | 20649 | |
c19d1205 | 20650 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
20651 | if (section->use_rela_p) |
20652 | { | |
20653 | code = fixp->fx_r_type; | |
20654 | break; | |
20655 | } | |
20656 | ||
c19d1205 ZW |
20657 | if (fixp->fx_addsy != NULL |
20658 | && !S_IS_DEFINED (fixp->fx_addsy) | |
20659 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 20660 | { |
c19d1205 ZW |
20661 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20662 | _("undefined local label `%s'"), | |
20663 | S_GET_NAME (fixp->fx_addsy)); | |
20664 | return NULL; | |
a737bd4d NC |
20665 | } |
20666 | ||
c19d1205 ZW |
20667 | as_bad_where (fixp->fx_file, fixp->fx_line, |
20668 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
20669 | return NULL; | |
a737bd4d | 20670 | |
c19d1205 ZW |
20671 | default: |
20672 | { | |
20673 | char * type; | |
6c43fab6 | 20674 | |
c19d1205 ZW |
20675 | switch (fixp->fx_r_type) |
20676 | { | |
20677 | case BFD_RELOC_NONE: type = "NONE"; break; | |
20678 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
20679 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 20680 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
20681 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
20682 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
20683 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 20684 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
20685 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
20686 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
20687 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
20688 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
20689 | default: type = _("<unknown>"); break; | |
20690 | } | |
20691 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20692 | _("cannot represent %s relocation in this object file format"), | |
20693 | type); | |
20694 | return NULL; | |
20695 | } | |
a737bd4d | 20696 | } |
6c43fab6 | 20697 | |
c19d1205 ZW |
20698 | #ifdef OBJ_ELF |
20699 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
20700 | && GOT_symbol | |
20701 | && fixp->fx_addsy == GOT_symbol) | |
20702 | { | |
20703 | code = BFD_RELOC_ARM_GOTPC; | |
20704 | reloc->addend = fixp->fx_offset = reloc->address; | |
20705 | } | |
20706 | #endif | |
6c43fab6 | 20707 | |
c19d1205 | 20708 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 20709 | |
c19d1205 ZW |
20710 | if (reloc->howto == NULL) |
20711 | { | |
20712 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
20713 | _("cannot represent %s relocation in this object file format"), | |
20714 | bfd_get_reloc_code_name (code)); | |
20715 | return NULL; | |
20716 | } | |
6c43fab6 | 20717 | |
c19d1205 ZW |
20718 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
20719 | vtable entry to be used in the relocation's section offset. */ | |
20720 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
20721 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 20722 | |
c19d1205 | 20723 | return reloc; |
6c43fab6 RE |
20724 | } |
20725 | ||
c19d1205 | 20726 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 20727 | |
c19d1205 ZW |
20728 | void |
20729 | cons_fix_new_arm (fragS * frag, | |
20730 | int where, | |
20731 | int size, | |
20732 | expressionS * exp) | |
6c43fab6 | 20733 | { |
c19d1205 ZW |
20734 | bfd_reloc_code_real_type type; |
20735 | int pcrel = 0; | |
6c43fab6 | 20736 | |
c19d1205 ZW |
20737 | /* Pick a reloc. |
20738 | FIXME: @@ Should look at CPU word size. */ | |
20739 | switch (size) | |
20740 | { | |
20741 | case 1: | |
20742 | type = BFD_RELOC_8; | |
20743 | break; | |
20744 | case 2: | |
20745 | type = BFD_RELOC_16; | |
20746 | break; | |
20747 | case 4: | |
20748 | default: | |
20749 | type = BFD_RELOC_32; | |
20750 | break; | |
20751 | case 8: | |
20752 | type = BFD_RELOC_64; | |
20753 | break; | |
20754 | } | |
6c43fab6 | 20755 | |
f0927246 NC |
20756 | #ifdef TE_PE |
20757 | if (exp->X_op == O_secrel) | |
20758 | { | |
20759 | exp->X_op = O_symbol; | |
20760 | type = BFD_RELOC_32_SECREL; | |
20761 | } | |
20762 | #endif | |
20763 | ||
c19d1205 ZW |
20764 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
20765 | } | |
6c43fab6 | 20766 | |
4343666d | 20767 | #if defined (OBJ_COFF) |
c19d1205 ZW |
20768 | void |
20769 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 20770 | { |
c19d1205 ZW |
20771 | /* If the destination of the branch is a defined symbol which does not have |
20772 | the THUMB_FUNC attribute, then we must be calling a function which has | |
20773 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
20774 | function and change the branch to refer to that function instead. */ | |
20775 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
20776 | && fixP->fx_addsy != NULL | |
20777 | && S_IS_DEFINED (fixP->fx_addsy) | |
20778 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 20779 | { |
c19d1205 | 20780 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 20781 | } |
c19d1205 ZW |
20782 | } |
20783 | #endif | |
6c43fab6 | 20784 | |
267bf995 | 20785 | |
c19d1205 ZW |
20786 | int |
20787 | arm_force_relocation (struct fix * fixp) | |
20788 | { | |
20789 | #if defined (OBJ_COFF) && defined (TE_PE) | |
20790 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
20791 | return 1; | |
20792 | #endif | |
6c43fab6 | 20793 | |
267bf995 RR |
20794 | /* In case we have a call or a branch to a function in ARM ISA mode from |
20795 | a thumb function or vice-versa force the relocation. These relocations | |
20796 | are cleared off for some cores that might have blx and simple transformations | |
20797 | are possible. */ | |
20798 | ||
20799 | #ifdef OBJ_ELF | |
20800 | switch (fixp->fx_r_type) | |
20801 | { | |
20802 | case BFD_RELOC_ARM_PCREL_JUMP: | |
20803 | case BFD_RELOC_ARM_PCREL_CALL: | |
20804 | case BFD_RELOC_THUMB_PCREL_BLX: | |
20805 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
20806 | return 1; | |
20807 | break; | |
20808 | ||
20809 | case BFD_RELOC_ARM_PCREL_BLX: | |
20810 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
20811 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
20812 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
20813 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
20814 | return 1; | |
20815 | break; | |
20816 | ||
20817 | default: | |
20818 | break; | |
20819 | } | |
20820 | #endif | |
20821 | ||
c19d1205 ZW |
20822 | /* Resolve these relocations even if the symbol is extern or weak. */ |
20823 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
20824 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 | 20825 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
16805f35 | 20826 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
20827 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
20828 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
20829 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 20830 | return 0; |
a737bd4d | 20831 | |
4962c51a MS |
20832 | /* Always leave these relocations for the linker. */ |
20833 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
20834 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
20835 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
20836 | return 1; | |
20837 | ||
f0291e4c PB |
20838 | /* Always generate relocations against function symbols. */ |
20839 | if (fixp->fx_r_type == BFD_RELOC_32 | |
20840 | && fixp->fx_addsy | |
20841 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
20842 | return 1; | |
20843 | ||
c19d1205 | 20844 | return generic_force_reloc (fixp); |
404ff6b5 AH |
20845 | } |
20846 | ||
0ffdc86c | 20847 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
20848 | /* Relocations against function names must be left unadjusted, |
20849 | so that the linker can use this information to generate interworking | |
20850 | stubs. The MIPS version of this function | |
c19d1205 ZW |
20851 | also prevents relocations that are mips-16 specific, but I do not |
20852 | know why it does this. | |
404ff6b5 | 20853 | |
c19d1205 ZW |
20854 | FIXME: |
20855 | There is one other problem that ought to be addressed here, but | |
20856 | which currently is not: Taking the address of a label (rather | |
20857 | than a function) and then later jumping to that address. Such | |
20858 | addresses also ought to have their bottom bit set (assuming that | |
20859 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 20860 | |
c19d1205 ZW |
20861 | bfd_boolean |
20862 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 20863 | { |
c19d1205 ZW |
20864 | if (fixP->fx_addsy == NULL) |
20865 | return 1; | |
404ff6b5 | 20866 | |
e28387c3 PB |
20867 | /* Preserve relocations against symbols with function type. */ |
20868 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 20869 | return FALSE; |
e28387c3 | 20870 | |
c19d1205 ZW |
20871 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
20872 | && fixP->fx_subsy == NULL) | |
c921be7d | 20873 | return FALSE; |
a737bd4d | 20874 | |
c19d1205 ZW |
20875 | /* We need the symbol name for the VTABLE entries. */ |
20876 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
20877 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 20878 | return FALSE; |
404ff6b5 | 20879 | |
c19d1205 ZW |
20880 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
20881 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
20882 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
20883 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
20884 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
20885 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
20886 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
20887 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
20888 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
20889 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
c921be7d | 20890 | return FALSE; |
a737bd4d | 20891 | |
4962c51a MS |
20892 | /* Similarly for group relocations. */ |
20893 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
20894 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
20895 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 20896 | return FALSE; |
4962c51a | 20897 | |
79947c54 CD |
20898 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
20899 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
20900 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
20901 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
20902 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
20903 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
20904 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
20905 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
20906 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 20907 | return FALSE; |
79947c54 | 20908 | |
c921be7d | 20909 | return TRUE; |
a737bd4d | 20910 | } |
0ffdc86c NC |
20911 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
20912 | ||
20913 | #ifdef OBJ_ELF | |
404ff6b5 | 20914 | |
c19d1205 ZW |
20915 | const char * |
20916 | elf32_arm_target_format (void) | |
404ff6b5 | 20917 | { |
c19d1205 ZW |
20918 | #ifdef TE_SYMBIAN |
20919 | return (target_big_endian | |
20920 | ? "elf32-bigarm-symbian" | |
20921 | : "elf32-littlearm-symbian"); | |
20922 | #elif defined (TE_VXWORKS) | |
20923 | return (target_big_endian | |
20924 | ? "elf32-bigarm-vxworks" | |
20925 | : "elf32-littlearm-vxworks"); | |
20926 | #else | |
20927 | if (target_big_endian) | |
20928 | return "elf32-bigarm"; | |
20929 | else | |
20930 | return "elf32-littlearm"; | |
20931 | #endif | |
404ff6b5 AH |
20932 | } |
20933 | ||
c19d1205 ZW |
20934 | void |
20935 | armelf_frob_symbol (symbolS * symp, | |
20936 | int * puntp) | |
404ff6b5 | 20937 | { |
c19d1205 ZW |
20938 | elf_frob_symbol (symp, puntp); |
20939 | } | |
20940 | #endif | |
404ff6b5 | 20941 | |
c19d1205 | 20942 | /* MD interface: Finalization. */ |
a737bd4d | 20943 | |
c19d1205 ZW |
20944 | void |
20945 | arm_cleanup (void) | |
20946 | { | |
20947 | literal_pool * pool; | |
a737bd4d | 20948 | |
e07e6e58 NC |
20949 | /* Ensure that all the IT blocks are properly closed. */ |
20950 | check_it_blocks_finished (); | |
20951 | ||
c19d1205 ZW |
20952 | for (pool = list_of_pools; pool; pool = pool->next) |
20953 | { | |
5f4273c7 | 20954 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
20955 | subseg_set (pool->section, pool->sub_section); |
20956 | #ifdef OBJ_ELF | |
20957 | arm_elf_change_section (); | |
20958 | #endif | |
20959 | s_ltorg (0); | |
20960 | } | |
404ff6b5 AH |
20961 | } |
20962 | ||
c19d1205 ZW |
20963 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
20964 | ARM ones. */ | |
404ff6b5 | 20965 | |
c19d1205 ZW |
20966 | void |
20967 | arm_adjust_symtab (void) | |
404ff6b5 | 20968 | { |
c19d1205 ZW |
20969 | #ifdef OBJ_COFF |
20970 | symbolS * sym; | |
404ff6b5 | 20971 | |
c19d1205 ZW |
20972 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
20973 | { | |
20974 | if (ARM_IS_THUMB (sym)) | |
20975 | { | |
20976 | if (THUMB_IS_FUNC (sym)) | |
20977 | { | |
20978 | /* Mark the symbol as a Thumb function. */ | |
20979 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
20980 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
20981 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 20982 | |
c19d1205 ZW |
20983 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
20984 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
20985 | else | |
20986 | as_bad (_("%s: unexpected function type: %d"), | |
20987 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
20988 | } | |
20989 | else switch (S_GET_STORAGE_CLASS (sym)) | |
20990 | { | |
20991 | case C_EXT: | |
20992 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
20993 | break; | |
20994 | case C_STAT: | |
20995 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
20996 | break; | |
20997 | case C_LABEL: | |
20998 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
20999 | break; | |
21000 | default: | |
21001 | /* Do nothing. */ | |
21002 | break; | |
21003 | } | |
21004 | } | |
a737bd4d | 21005 | |
c19d1205 ZW |
21006 | if (ARM_IS_INTERWORK (sym)) |
21007 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 21008 | } |
c19d1205 ZW |
21009 | #endif |
21010 | #ifdef OBJ_ELF | |
21011 | symbolS * sym; | |
21012 | char bind; | |
404ff6b5 | 21013 | |
c19d1205 | 21014 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 21015 | { |
c19d1205 ZW |
21016 | if (ARM_IS_THUMB (sym)) |
21017 | { | |
21018 | elf_symbol_type * elf_sym; | |
404ff6b5 | 21019 | |
c19d1205 ZW |
21020 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
21021 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 21022 | |
b0796911 PB |
21023 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
21024 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
21025 | { |
21026 | /* If it's a .thumb_func, declare it as so, | |
21027 | otherwise tag label as .code 16. */ | |
21028 | if (THUMB_IS_FUNC (sym)) | |
21029 | elf_sym->internal_elf_sym.st_info = | |
21030 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
3ba67470 | 21031 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
21032 | elf_sym->internal_elf_sym.st_info = |
21033 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
21034 | } | |
21035 | } | |
21036 | } | |
21037 | #endif | |
404ff6b5 AH |
21038 | } |
21039 | ||
c19d1205 | 21040 | /* MD interface: Initialization. */ |
404ff6b5 | 21041 | |
a737bd4d | 21042 | static void |
c19d1205 | 21043 | set_constant_flonums (void) |
a737bd4d | 21044 | { |
c19d1205 | 21045 | int i; |
404ff6b5 | 21046 | |
c19d1205 ZW |
21047 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
21048 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
21049 | abort (); | |
a737bd4d | 21050 | } |
404ff6b5 | 21051 | |
3e9e4fcf JB |
21052 | /* Auto-select Thumb mode if it's the only available instruction set for the |
21053 | given architecture. */ | |
21054 | ||
21055 | static void | |
21056 | autoselect_thumb_from_cpu_variant (void) | |
21057 | { | |
21058 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
21059 | opcode_select (16); | |
21060 | } | |
21061 | ||
c19d1205 ZW |
21062 | void |
21063 | md_begin (void) | |
a737bd4d | 21064 | { |
c19d1205 ZW |
21065 | unsigned mach; |
21066 | unsigned int i; | |
404ff6b5 | 21067 | |
c19d1205 ZW |
21068 | if ( (arm_ops_hsh = hash_new ()) == NULL |
21069 | || (arm_cond_hsh = hash_new ()) == NULL | |
21070 | || (arm_shift_hsh = hash_new ()) == NULL | |
21071 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 21072 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 21073 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
21074 | || (arm_reloc_hsh = hash_new ()) == NULL |
21075 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
21076 | as_fatal (_("virtual memory exhausted")); |
21077 | ||
21078 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
5a49b8ac | 21079 | hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i)); |
c19d1205 | 21080 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
5a49b8ac | 21081 | hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i)); |
c19d1205 | 21082 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 21083 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 21084 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
5a49b8ac | 21085 | hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i)); |
62b3e311 | 21086 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
5a49b8ac | 21087 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i)); |
c19d1205 | 21088 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 21089 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
21090 | for (i = 0; |
21091 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
21092 | i++) | |
21093 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template, | |
5a49b8ac | 21094 | (void *) (barrier_opt_names + i)); |
c19d1205 ZW |
21095 | #ifdef OBJ_ELF |
21096 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
5a49b8ac | 21097 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i)); |
c19d1205 ZW |
21098 | #endif |
21099 | ||
21100 | set_constant_flonums (); | |
404ff6b5 | 21101 | |
c19d1205 ZW |
21102 | /* Set the cpu variant based on the command-line options. We prefer |
21103 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
21104 | -mfpu= over any other way of setting the floating point unit. | |
21105 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 21106 | if (legacy_cpu) |
404ff6b5 | 21107 | { |
e74cfd16 | 21108 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
21109 | as_bad (_("use of old and new-style options to set CPU type")); |
21110 | ||
21111 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 21112 | } |
e74cfd16 | 21113 | else if (!mcpu_cpu_opt) |
c19d1205 | 21114 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 21115 | |
e74cfd16 | 21116 | if (legacy_fpu) |
c19d1205 | 21117 | { |
e74cfd16 | 21118 | if (mfpu_opt) |
c19d1205 | 21119 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
21120 | |
21121 | mfpu_opt = legacy_fpu; | |
21122 | } | |
e74cfd16 | 21123 | else if (!mfpu_opt) |
03b1477f | 21124 | { |
45eb4c1b NS |
21125 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
21126 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
21127 | /* Some environments specify a default FPU. If they don't, infer it |
21128 | from the processor. */ | |
e74cfd16 | 21129 | if (mcpu_fpu_opt) |
03b1477f RE |
21130 | mfpu_opt = mcpu_fpu_opt; |
21131 | else | |
21132 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 21133 | #else |
e74cfd16 | 21134 | mfpu_opt = &fpu_default; |
39c2da32 | 21135 | #endif |
03b1477f RE |
21136 | } |
21137 | ||
e74cfd16 | 21138 | if (!mfpu_opt) |
03b1477f | 21139 | { |
493cb6ef | 21140 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 21141 | mfpu_opt = &fpu_default; |
493cb6ef | 21142 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 21143 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 21144 | else |
e74cfd16 | 21145 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
21146 | } |
21147 | ||
ee065d83 | 21148 | #ifdef CPU_DEFAULT |
e74cfd16 | 21149 | if (!mcpu_cpu_opt) |
ee065d83 | 21150 | { |
e74cfd16 PB |
21151 | mcpu_cpu_opt = &cpu_default; |
21152 | selected_cpu = cpu_default; | |
ee065d83 | 21153 | } |
e74cfd16 PB |
21154 | #else |
21155 | if (mcpu_cpu_opt) | |
21156 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 21157 | else |
e74cfd16 | 21158 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 21159 | #endif |
03b1477f | 21160 | |
e74cfd16 | 21161 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 21162 | |
3e9e4fcf JB |
21163 | autoselect_thumb_from_cpu_variant (); |
21164 | ||
e74cfd16 | 21165 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 21166 | |
f17c130b | 21167 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 21168 | { |
7cc69913 NC |
21169 | unsigned int flags = 0; |
21170 | ||
21171 | #if defined OBJ_ELF | |
21172 | flags = meabi_flags; | |
d507cf36 PB |
21173 | |
21174 | switch (meabi_flags) | |
33a392fb | 21175 | { |
d507cf36 | 21176 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 21177 | #endif |
d507cf36 PB |
21178 | /* Set the flags in the private structure. */ |
21179 | if (uses_apcs_26) flags |= F_APCS26; | |
21180 | if (support_interwork) flags |= F_INTERWORK; | |
21181 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 21182 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 21183 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
21184 | flags |= F_SOFT_FLOAT; |
21185 | ||
d507cf36 PB |
21186 | switch (mfloat_abi_opt) |
21187 | { | |
21188 | case ARM_FLOAT_ABI_SOFT: | |
21189 | case ARM_FLOAT_ABI_SOFTFP: | |
21190 | flags |= F_SOFT_FLOAT; | |
21191 | break; | |
33a392fb | 21192 | |
d507cf36 PB |
21193 | case ARM_FLOAT_ABI_HARD: |
21194 | if (flags & F_SOFT_FLOAT) | |
21195 | as_bad (_("hard-float conflicts with specified fpu")); | |
21196 | break; | |
21197 | } | |
03b1477f | 21198 | |
e74cfd16 PB |
21199 | /* Using pure-endian doubles (even if soft-float). */ |
21200 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 21201 | flags |= F_VFP_FLOAT; |
f17c130b | 21202 | |
fde78edd | 21203 | #if defined OBJ_ELF |
e74cfd16 | 21204 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 21205 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
21206 | break; |
21207 | ||
8cb51566 | 21208 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 21209 | case EF_ARM_EABI_VER5: |
c19d1205 | 21210 | /* No additional flags to set. */ |
d507cf36 PB |
21211 | break; |
21212 | ||
21213 | default: | |
21214 | abort (); | |
21215 | } | |
7cc69913 | 21216 | #endif |
b99bd4ef NC |
21217 | bfd_set_private_flags (stdoutput, flags); |
21218 | ||
21219 | /* We have run out flags in the COFF header to encode the | |
21220 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 21221 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
21222 | if (atpcs) |
21223 | { | |
21224 | asection * sec; | |
21225 | ||
21226 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
21227 | ||
21228 | if (sec != NULL) | |
21229 | { | |
21230 | bfd_set_section_flags | |
21231 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
21232 | bfd_set_section_size (stdoutput, sec, 0); | |
21233 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
21234 | } | |
21235 | } | |
7cc69913 | 21236 | } |
f17c130b | 21237 | #endif |
b99bd4ef NC |
21238 | |
21239 | /* Record the CPU type as well. */ | |
2d447fca JM |
21240 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
21241 | mach = bfd_mach_arm_iWMMXt2; | |
21242 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 21243 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 21244 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 21245 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 21246 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 21247 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 21248 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 21249 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 21250 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 21251 | { |
e74cfd16 | 21252 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21253 | mach = bfd_mach_arm_5T; |
21254 | else | |
21255 | mach = bfd_mach_arm_5; | |
21256 | } | |
e74cfd16 | 21257 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 21258 | { |
e74cfd16 | 21259 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
21260 | mach = bfd_mach_arm_4T; |
21261 | else | |
21262 | mach = bfd_mach_arm_4; | |
21263 | } | |
e74cfd16 | 21264 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 21265 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
21266 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
21267 | mach = bfd_mach_arm_3; | |
21268 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
21269 | mach = bfd_mach_arm_2a; | |
21270 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
21271 | mach = bfd_mach_arm_2; | |
21272 | else | |
21273 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
21274 | |
21275 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
21276 | } | |
21277 | ||
c19d1205 | 21278 | /* Command line processing. */ |
b99bd4ef | 21279 | |
c19d1205 ZW |
21280 | /* md_parse_option |
21281 | Invocation line includes a switch not recognized by the base assembler. | |
21282 | See if it's a processor-specific option. | |
b99bd4ef | 21283 | |
c19d1205 ZW |
21284 | This routine is somewhat complicated by the need for backwards |
21285 | compatibility (since older releases of gcc can't be changed). | |
21286 | The new options try to make the interface as compatible as | |
21287 | possible with GCC. | |
b99bd4ef | 21288 | |
c19d1205 | 21289 | New options (supported) are: |
b99bd4ef | 21290 | |
c19d1205 ZW |
21291 | -mcpu=<cpu name> Assemble for selected processor |
21292 | -march=<architecture name> Assemble for selected architecture | |
21293 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
21294 | -EB/-mbig-endian Big-endian | |
21295 | -EL/-mlittle-endian Little-endian | |
21296 | -k Generate PIC code | |
21297 | -mthumb Start in Thumb mode | |
21298 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 21299 | |
278df34e | 21300 | -m[no-]warn-deprecated Warn about deprecated features |
267bf995 | 21301 | |
c19d1205 | 21302 | For now we will also provide support for: |
b99bd4ef | 21303 | |
c19d1205 ZW |
21304 | -mapcs-32 32-bit Program counter |
21305 | -mapcs-26 26-bit Program counter | |
21306 | -macps-float Floats passed in FP registers | |
21307 | -mapcs-reentrant Reentrant code | |
21308 | -matpcs | |
21309 | (sometime these will probably be replaced with -mapcs=<list of options> | |
21310 | and -matpcs=<list of options>) | |
b99bd4ef | 21311 | |
c19d1205 ZW |
21312 | The remaining options are only supported for back-wards compatibility. |
21313 | Cpu variants, the arm part is optional: | |
21314 | -m[arm]1 Currently not supported. | |
21315 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
21316 | -m[arm]3 Arm 3 processor | |
21317 | -m[arm]6[xx], Arm 6 processors | |
21318 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
21319 | -m[arm]8[10] Arm 8 processors | |
21320 | -m[arm]9[20][tdmi] Arm 9 processors | |
21321 | -mstrongarm[110[0]] StrongARM processors | |
21322 | -mxscale XScale processors | |
21323 | -m[arm]v[2345[t[e]]] Arm architectures | |
21324 | -mall All (except the ARM1) | |
21325 | FP variants: | |
21326 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
21327 | -mfpe-old (No float load/store multiples) | |
21328 | -mvfpxd VFP Single precision | |
21329 | -mvfp All VFP | |
21330 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 21331 | |
c19d1205 ZW |
21332 | The following CPU names are recognized: |
21333 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
21334 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
21335 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
21336 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
21337 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
21338 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
21339 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 21340 | |
c19d1205 | 21341 | */ |
b99bd4ef | 21342 | |
c19d1205 | 21343 | const char * md_shortopts = "m:k"; |
b99bd4ef | 21344 | |
c19d1205 ZW |
21345 | #ifdef ARM_BI_ENDIAN |
21346 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
21347 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 21348 | #else |
c19d1205 ZW |
21349 | #if TARGET_BYTES_BIG_ENDIAN |
21350 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 21351 | #else |
c19d1205 ZW |
21352 | #define OPTION_EL (OPTION_MD_BASE + 1) |
21353 | #endif | |
b99bd4ef | 21354 | #endif |
845b51d6 | 21355 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 21356 | |
c19d1205 | 21357 | struct option md_longopts[] = |
b99bd4ef | 21358 | { |
c19d1205 ZW |
21359 | #ifdef OPTION_EB |
21360 | {"EB", no_argument, NULL, OPTION_EB}, | |
21361 | #endif | |
21362 | #ifdef OPTION_EL | |
21363 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 21364 | #endif |
845b51d6 | 21365 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
21366 | {NULL, no_argument, NULL, 0} |
21367 | }; | |
b99bd4ef | 21368 | |
c19d1205 | 21369 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 21370 | |
c19d1205 | 21371 | struct arm_option_table |
b99bd4ef | 21372 | { |
c19d1205 ZW |
21373 | char *option; /* Option name to match. */ |
21374 | char *help; /* Help information. */ | |
21375 | int *var; /* Variable to change. */ | |
21376 | int value; /* What to change it to. */ | |
21377 | char *deprecated; /* If non-null, print this message. */ | |
21378 | }; | |
b99bd4ef | 21379 | |
c19d1205 ZW |
21380 | struct arm_option_table arm_opts[] = |
21381 | { | |
21382 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
21383 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
21384 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
21385 | &support_interwork, 1, NULL}, | |
21386 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
21387 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
21388 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
21389 | 1, NULL}, | |
21390 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
21391 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
21392 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
21393 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
21394 | NULL}, | |
b99bd4ef | 21395 | |
c19d1205 ZW |
21396 | /* These are recognized by the assembler, but have no affect on code. */ |
21397 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
21398 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
21399 | |
21400 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
21401 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
21402 | &warn_on_deprecated, 0, NULL}, | |
e74cfd16 PB |
21403 | {NULL, NULL, NULL, 0, NULL} |
21404 | }; | |
21405 | ||
21406 | struct arm_legacy_option_table | |
21407 | { | |
21408 | char *option; /* Option name to match. */ | |
21409 | const arm_feature_set **var; /* Variable to change. */ | |
21410 | const arm_feature_set value; /* What to change it to. */ | |
21411 | char *deprecated; /* If non-null, print this message. */ | |
21412 | }; | |
b99bd4ef | 21413 | |
e74cfd16 PB |
21414 | const struct arm_legacy_option_table arm_legacy_opts[] = |
21415 | { | |
c19d1205 ZW |
21416 | /* DON'T add any new processors to this list -- we want the whole list |
21417 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
21418 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
21419 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
21420 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21421 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
21422 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21423 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
21424 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21425 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
21426 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21427 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
21428 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21429 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
21430 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21431 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
21432 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21433 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
21434 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21435 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
21436 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21437 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
21438 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21439 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
21440 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21441 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
21442 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21443 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
21444 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21445 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
21446 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21447 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
21448 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21449 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
21450 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21451 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
21452 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21453 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
21454 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21455 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
21456 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21457 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
21458 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21459 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
21460 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21461 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
21462 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21463 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
21464 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21465 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21466 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21467 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
21468 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21469 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
21470 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21471 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
21472 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21473 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
21474 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21475 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
21476 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21477 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
21478 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21479 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
21480 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21481 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
21482 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21483 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
21484 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21485 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
21486 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
21487 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 21488 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 21489 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21490 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 21491 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 21492 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
21493 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
21494 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
21495 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 21496 | |
c19d1205 | 21497 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21498 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
21499 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
21500 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21501 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
21502 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21503 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
21504 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21505 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
21506 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21507 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
21508 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21509 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
21510 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21511 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
21512 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21513 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
21514 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
21515 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 21516 | |
c19d1205 | 21517 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
21518 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
21519 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
21520 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
21521 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 21522 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 21523 | |
e74cfd16 | 21524 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 21525 | }; |
7ed4c4c5 | 21526 | |
c19d1205 | 21527 | struct arm_cpu_option_table |
7ed4c4c5 | 21528 | { |
c19d1205 | 21529 | char *name; |
e74cfd16 | 21530 | const arm_feature_set value; |
c19d1205 ZW |
21531 | /* For some CPUs we assume an FPU unless the user explicitly sets |
21532 | -mfpu=... */ | |
e74cfd16 | 21533 | const arm_feature_set default_fpu; |
ee065d83 PB |
21534 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
21535 | case. */ | |
21536 | const char *canonical_name; | |
c19d1205 | 21537 | }; |
7ed4c4c5 | 21538 | |
c19d1205 ZW |
21539 | /* This list should, at a minimum, contain all the cpu names |
21540 | recognized by GCC. */ | |
e74cfd16 | 21541 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 21542 | { |
ee065d83 PB |
21543 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
21544 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
21545 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
21546 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21547 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
21548 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21549 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21550 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21551 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21552 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21553 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21554 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21555 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21556 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21557 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21558 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
21559 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21560 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21561 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21562 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21563 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21564 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21565 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21566 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21567 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21568 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21569 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21570 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
21571 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21572 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21573 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21574 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21575 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21576 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21577 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21578 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21579 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21580 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
21581 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21582 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
21583 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21584 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21585 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
21586 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
7fac0536 NC |
21587 | {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, |
21588 | {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
21589 | /* For V5 or later processors we default to using VFP; but the user |
21590 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
21591 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
21592 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21593 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21594 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
21595 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
21596 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21597 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
21598 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21599 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
21600 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
21601 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21602 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21603 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21604 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21605 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21606 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
21607 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
21608 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21609 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
21610 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
21611 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
7fac0536 NC |
21612 | {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL}, |
21613 | {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
ee065d83 PB |
21614 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, |
21615 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
21616 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
21617 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
21618 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
21619 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
21620 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
21621 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
21622 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
21623 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
e07e6e58 | 21624 | {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
5287ad62 | 21625 | | FPU_NEON_EXT_V1), |
15290f0a | 21626 | NULL}, |
e07e6e58 | 21627 | {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3 |
15290f0a | 21628 | | FPU_NEON_EXT_V1), |
5287ad62 | 21629 | NULL}, |
62b3e311 PB |
21630 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, |
21631 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, | |
7e806470 | 21632 | {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL}, |
5b19eaba | 21633 | {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL}, |
c19d1205 | 21634 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 21635 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21636 | /* ??? iwmmxt is not a processor. */ |
ee065d83 | 21637 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
2d447fca | 21638 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL}, |
ee065d83 | 21639 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 21640 | /* Maverick */ |
e07e6e58 | 21641 | {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
e74cfd16 | 21642 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} |
c19d1205 | 21643 | }; |
7ed4c4c5 | 21644 | |
c19d1205 | 21645 | struct arm_arch_option_table |
7ed4c4c5 | 21646 | { |
c19d1205 | 21647 | char *name; |
e74cfd16 PB |
21648 | const arm_feature_set value; |
21649 | const arm_feature_set default_fpu; | |
c19d1205 | 21650 | }; |
7ed4c4c5 | 21651 | |
c19d1205 ZW |
21652 | /* This list should, at a minimum, contain all the architecture names |
21653 | recognized by GCC. */ | |
e74cfd16 | 21654 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
21655 | { |
21656 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
21657 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
21658 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
21659 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21660 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
21661 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
21662 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
21663 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
21664 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
21665 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
21666 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
21667 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
21668 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
21669 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
21670 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
21671 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
21672 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
21673 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21674 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
21675 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
21676 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
21677 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
21678 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
21679 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
21680 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
21681 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
7e806470 | 21682 | {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP}, |
62b3e311 | 21683 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
c450d570 PB |
21684 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
21685 | Accept the non-dashed form for compatibility with old toolchains. */ | |
62b3e311 PB |
21686 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21687 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21688 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c450d570 PB |
21689 | {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP}, |
21690 | {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
21691 | {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
21692 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
21693 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
2d447fca | 21694 | {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP}, |
e74cfd16 | 21695 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 21696 | }; |
7ed4c4c5 | 21697 | |
c19d1205 | 21698 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 21699 | struct arm_option_cpu_value_table |
c19d1205 ZW |
21700 | { |
21701 | char *name; | |
e74cfd16 | 21702 | const arm_feature_set value; |
c19d1205 | 21703 | }; |
7ed4c4c5 | 21704 | |
e74cfd16 | 21705 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 21706 | { |
e74cfd16 PB |
21707 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
21708 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
21709 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
2d447fca | 21710 | {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)}, |
e74cfd16 | 21711 | {NULL, ARM_ARCH_NONE} |
c19d1205 | 21712 | }; |
7ed4c4c5 | 21713 | |
c19d1205 ZW |
21714 | /* This list should, at a minimum, contain all the fpu names |
21715 | recognized by GCC. */ | |
e74cfd16 | 21716 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
21717 | { |
21718 | {"softfpa", FPU_NONE}, | |
21719 | {"fpe", FPU_ARCH_FPE}, | |
21720 | {"fpe2", FPU_ARCH_FPE}, | |
21721 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
21722 | {"fpa", FPU_ARCH_FPA}, | |
21723 | {"fpa10", FPU_ARCH_FPA}, | |
21724 | {"fpa11", FPU_ARCH_FPA}, | |
21725 | {"arm7500fe", FPU_ARCH_FPA}, | |
21726 | {"softvfp", FPU_ARCH_VFP}, | |
21727 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
21728 | {"vfp", FPU_ARCH_VFP_V2}, | |
21729 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 21730 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
21731 | {"vfp10", FPU_ARCH_VFP_V2}, |
21732 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
21733 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
21734 | {"vfpv2", FPU_ARCH_VFP_V2}, |
21735 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
21736 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, | |
c19d1205 ZW |
21737 | {"arm1020t", FPU_ARCH_VFP_V1}, |
21738 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
21739 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
21740 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
21741 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 21742 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 21743 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
e74cfd16 PB |
21744 | {NULL, ARM_ARCH_NONE} |
21745 | }; | |
21746 | ||
21747 | struct arm_option_value_table | |
21748 | { | |
21749 | char *name; | |
21750 | long value; | |
c19d1205 | 21751 | }; |
7ed4c4c5 | 21752 | |
e74cfd16 | 21753 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
21754 | { |
21755 | {"hard", ARM_FLOAT_ABI_HARD}, | |
21756 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
21757 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 21758 | {NULL, 0} |
c19d1205 | 21759 | }; |
7ed4c4c5 | 21760 | |
c19d1205 | 21761 | #ifdef OBJ_ELF |
3a4a14e9 | 21762 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 21763 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
21764 | { |
21765 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
21766 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 21767 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 21768 | {NULL, 0} |
c19d1205 ZW |
21769 | }; |
21770 | #endif | |
7ed4c4c5 | 21771 | |
c19d1205 ZW |
21772 | struct arm_long_option_table |
21773 | { | |
21774 | char * option; /* Substring to match. */ | |
21775 | char * help; /* Help information. */ | |
21776 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
21777 | char * deprecated; /* If non-null, print this message. */ | |
21778 | }; | |
7ed4c4c5 | 21779 | |
c921be7d | 21780 | static bfd_boolean |
e74cfd16 | 21781 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 21782 | { |
e74cfd16 PB |
21783 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
21784 | ||
21785 | /* Copy the feature set, so that we can modify it. */ | |
21786 | *ext_set = **opt_p; | |
21787 | *opt_p = ext_set; | |
21788 | ||
c19d1205 | 21789 | while (str != NULL && *str != 0) |
7ed4c4c5 | 21790 | { |
e74cfd16 | 21791 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
21792 | char * ext; |
21793 | int optlen; | |
7ed4c4c5 | 21794 | |
c19d1205 ZW |
21795 | if (*str != '+') |
21796 | { | |
21797 | as_bad (_("invalid architectural extension")); | |
c921be7d | 21798 | return FALSE; |
c19d1205 | 21799 | } |
7ed4c4c5 | 21800 | |
c19d1205 ZW |
21801 | str++; |
21802 | ext = strchr (str, '+'); | |
7ed4c4c5 | 21803 | |
c19d1205 ZW |
21804 | if (ext != NULL) |
21805 | optlen = ext - str; | |
21806 | else | |
21807 | optlen = strlen (str); | |
7ed4c4c5 | 21808 | |
c19d1205 ZW |
21809 | if (optlen == 0) |
21810 | { | |
21811 | as_bad (_("missing architectural extension")); | |
c921be7d | 21812 | return FALSE; |
c19d1205 | 21813 | } |
7ed4c4c5 | 21814 | |
c19d1205 ZW |
21815 | for (opt = arm_extensions; opt->name != NULL; opt++) |
21816 | if (strncmp (opt->name, str, optlen) == 0) | |
21817 | { | |
e74cfd16 | 21818 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
21819 | break; |
21820 | } | |
7ed4c4c5 | 21821 | |
c19d1205 ZW |
21822 | if (opt->name == NULL) |
21823 | { | |
5f4273c7 | 21824 | as_bad (_("unknown architectural extension `%s'"), str); |
c921be7d | 21825 | return FALSE; |
c19d1205 | 21826 | } |
7ed4c4c5 | 21827 | |
c19d1205 ZW |
21828 | str = ext; |
21829 | }; | |
7ed4c4c5 | 21830 | |
c921be7d | 21831 | return TRUE; |
c19d1205 | 21832 | } |
7ed4c4c5 | 21833 | |
c921be7d | 21834 | static bfd_boolean |
c19d1205 | 21835 | arm_parse_cpu (char * str) |
7ed4c4c5 | 21836 | { |
e74cfd16 | 21837 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
21838 | char * ext = strchr (str, '+'); |
21839 | int optlen; | |
7ed4c4c5 | 21840 | |
c19d1205 ZW |
21841 | if (ext != NULL) |
21842 | optlen = ext - str; | |
7ed4c4c5 | 21843 | else |
c19d1205 | 21844 | optlen = strlen (str); |
7ed4c4c5 | 21845 | |
c19d1205 | 21846 | if (optlen == 0) |
7ed4c4c5 | 21847 | { |
c19d1205 | 21848 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 21849 | return FALSE; |
7ed4c4c5 NC |
21850 | } |
21851 | ||
c19d1205 ZW |
21852 | for (opt = arm_cpus; opt->name != NULL; opt++) |
21853 | if (strncmp (opt->name, str, optlen) == 0) | |
21854 | { | |
e74cfd16 PB |
21855 | mcpu_cpu_opt = &opt->value; |
21856 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 21857 | if (opt->canonical_name) |
5f4273c7 | 21858 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
21859 | else |
21860 | { | |
21861 | int i; | |
c921be7d | 21862 | |
ee065d83 PB |
21863 | for (i = 0; i < optlen; i++) |
21864 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
21865 | selected_cpu_name[i] = 0; | |
21866 | } | |
7ed4c4c5 | 21867 | |
c19d1205 ZW |
21868 | if (ext != NULL) |
21869 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 21870 | |
c921be7d | 21871 | return TRUE; |
c19d1205 | 21872 | } |
7ed4c4c5 | 21873 | |
c19d1205 | 21874 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 21875 | return FALSE; |
7ed4c4c5 NC |
21876 | } |
21877 | ||
c921be7d | 21878 | static bfd_boolean |
c19d1205 | 21879 | arm_parse_arch (char * str) |
7ed4c4c5 | 21880 | { |
e74cfd16 | 21881 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
21882 | char *ext = strchr (str, '+'); |
21883 | int optlen; | |
7ed4c4c5 | 21884 | |
c19d1205 ZW |
21885 | if (ext != NULL) |
21886 | optlen = ext - str; | |
7ed4c4c5 | 21887 | else |
c19d1205 | 21888 | optlen = strlen (str); |
7ed4c4c5 | 21889 | |
c19d1205 | 21890 | if (optlen == 0) |
7ed4c4c5 | 21891 | { |
c19d1205 | 21892 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 21893 | return FALSE; |
7ed4c4c5 NC |
21894 | } |
21895 | ||
c19d1205 ZW |
21896 | for (opt = arm_archs; opt->name != NULL; opt++) |
21897 | if (streq (opt->name, str)) | |
21898 | { | |
e74cfd16 PB |
21899 | march_cpu_opt = &opt->value; |
21900 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 21901 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 21902 | |
c19d1205 ZW |
21903 | if (ext != NULL) |
21904 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 21905 | |
c921be7d | 21906 | return TRUE; |
c19d1205 ZW |
21907 | } |
21908 | ||
21909 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 21910 | return FALSE; |
7ed4c4c5 | 21911 | } |
eb043451 | 21912 | |
c921be7d | 21913 | static bfd_boolean |
c19d1205 ZW |
21914 | arm_parse_fpu (char * str) |
21915 | { | |
e74cfd16 | 21916 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 21917 | |
c19d1205 ZW |
21918 | for (opt = arm_fpus; opt->name != NULL; opt++) |
21919 | if (streq (opt->name, str)) | |
21920 | { | |
e74cfd16 | 21921 | mfpu_opt = &opt->value; |
c921be7d | 21922 | return TRUE; |
c19d1205 | 21923 | } |
b99bd4ef | 21924 | |
c19d1205 | 21925 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 21926 | return FALSE; |
c19d1205 ZW |
21927 | } |
21928 | ||
c921be7d | 21929 | static bfd_boolean |
c19d1205 | 21930 | arm_parse_float_abi (char * str) |
b99bd4ef | 21931 | { |
e74cfd16 | 21932 | const struct arm_option_value_table * opt; |
b99bd4ef | 21933 | |
c19d1205 ZW |
21934 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
21935 | if (streq (opt->name, str)) | |
21936 | { | |
21937 | mfloat_abi_opt = opt->value; | |
c921be7d | 21938 | return TRUE; |
c19d1205 | 21939 | } |
cc8a6dd0 | 21940 | |
c19d1205 | 21941 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 21942 | return FALSE; |
c19d1205 | 21943 | } |
b99bd4ef | 21944 | |
c19d1205 | 21945 | #ifdef OBJ_ELF |
c921be7d | 21946 | static bfd_boolean |
c19d1205 ZW |
21947 | arm_parse_eabi (char * str) |
21948 | { | |
e74cfd16 | 21949 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 21950 | |
c19d1205 ZW |
21951 | for (opt = arm_eabis; opt->name != NULL; opt++) |
21952 | if (streq (opt->name, str)) | |
21953 | { | |
21954 | meabi_flags = opt->value; | |
c921be7d | 21955 | return TRUE; |
c19d1205 ZW |
21956 | } |
21957 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 21958 | return FALSE; |
c19d1205 ZW |
21959 | } |
21960 | #endif | |
cc8a6dd0 | 21961 | |
c921be7d | 21962 | static bfd_boolean |
e07e6e58 NC |
21963 | arm_parse_it_mode (char * str) |
21964 | { | |
c921be7d | 21965 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
21966 | |
21967 | if (streq ("arm", str)) | |
21968 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
21969 | else if (streq ("thumb", str)) | |
21970 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
21971 | else if (streq ("always", str)) | |
21972 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
21973 | else if (streq ("never", str)) | |
21974 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
21975 | else | |
21976 | { | |
21977 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
21978 | "arm, thumb, always, or never."), str); | |
c921be7d | 21979 | ret = FALSE; |
e07e6e58 NC |
21980 | } |
21981 | ||
21982 | return ret; | |
21983 | } | |
21984 | ||
c19d1205 ZW |
21985 | struct arm_long_option_table arm_long_opts[] = |
21986 | { | |
21987 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
21988 | arm_parse_cpu, NULL}, | |
21989 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
21990 | arm_parse_arch, NULL}, | |
21991 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
21992 | arm_parse_fpu, NULL}, | |
21993 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
21994 | arm_parse_float_abi, NULL}, | |
21995 | #ifdef OBJ_ELF | |
7fac0536 | 21996 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
21997 | arm_parse_eabi, NULL}, |
21998 | #endif | |
e07e6e58 NC |
21999 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
22000 | arm_parse_it_mode, NULL}, | |
c19d1205 ZW |
22001 | {NULL, NULL, 0, NULL} |
22002 | }; | |
cc8a6dd0 | 22003 | |
c19d1205 ZW |
22004 | int |
22005 | md_parse_option (int c, char * arg) | |
22006 | { | |
22007 | struct arm_option_table *opt; | |
e74cfd16 | 22008 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 22009 | struct arm_long_option_table *lopt; |
b99bd4ef | 22010 | |
c19d1205 | 22011 | switch (c) |
b99bd4ef | 22012 | { |
c19d1205 ZW |
22013 | #ifdef OPTION_EB |
22014 | case OPTION_EB: | |
22015 | target_big_endian = 1; | |
22016 | break; | |
22017 | #endif | |
cc8a6dd0 | 22018 | |
c19d1205 ZW |
22019 | #ifdef OPTION_EL |
22020 | case OPTION_EL: | |
22021 | target_big_endian = 0; | |
22022 | break; | |
22023 | #endif | |
b99bd4ef | 22024 | |
845b51d6 PB |
22025 | case OPTION_FIX_V4BX: |
22026 | fix_v4bx = TRUE; | |
22027 | break; | |
22028 | ||
c19d1205 ZW |
22029 | case 'a': |
22030 | /* Listing option. Just ignore these, we don't support additional | |
22031 | ones. */ | |
22032 | return 0; | |
b99bd4ef | 22033 | |
c19d1205 ZW |
22034 | default: |
22035 | for (opt = arm_opts; opt->option != NULL; opt++) | |
22036 | { | |
22037 | if (c == opt->option[0] | |
22038 | && ((arg == NULL && opt->option[1] == 0) | |
22039 | || streq (arg, opt->option + 1))) | |
22040 | { | |
c19d1205 | 22041 | /* If the option is deprecated, tell the user. */ |
278df34e | 22042 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
22043 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22044 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 22045 | |
c19d1205 ZW |
22046 | if (opt->var != NULL) |
22047 | *opt->var = opt->value; | |
cc8a6dd0 | 22048 | |
c19d1205 ZW |
22049 | return 1; |
22050 | } | |
22051 | } | |
b99bd4ef | 22052 | |
e74cfd16 PB |
22053 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
22054 | { | |
22055 | if (c == fopt->option[0] | |
22056 | && ((arg == NULL && fopt->option[1] == 0) | |
22057 | || streq (arg, fopt->option + 1))) | |
22058 | { | |
e74cfd16 | 22059 | /* If the option is deprecated, tell the user. */ |
278df34e | 22060 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
22061 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
22062 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
22063 | |
22064 | if (fopt->var != NULL) | |
22065 | *fopt->var = &fopt->value; | |
22066 | ||
22067 | return 1; | |
22068 | } | |
22069 | } | |
22070 | ||
c19d1205 ZW |
22071 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22072 | { | |
22073 | /* These options are expected to have an argument. */ | |
22074 | if (c == lopt->option[0] | |
22075 | && arg != NULL | |
22076 | && strncmp (arg, lopt->option + 1, | |
22077 | strlen (lopt->option + 1)) == 0) | |
22078 | { | |
c19d1205 | 22079 | /* If the option is deprecated, tell the user. */ |
278df34e | 22080 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
22081 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
22082 | _(lopt->deprecated)); | |
b99bd4ef | 22083 | |
c19d1205 ZW |
22084 | /* Call the sup-option parser. */ |
22085 | return lopt->func (arg + strlen (lopt->option) - 1); | |
22086 | } | |
22087 | } | |
a737bd4d | 22088 | |
c19d1205 ZW |
22089 | return 0; |
22090 | } | |
a394c00f | 22091 | |
c19d1205 ZW |
22092 | return 1; |
22093 | } | |
a394c00f | 22094 | |
c19d1205 ZW |
22095 | void |
22096 | md_show_usage (FILE * fp) | |
a394c00f | 22097 | { |
c19d1205 ZW |
22098 | struct arm_option_table *opt; |
22099 | struct arm_long_option_table *lopt; | |
a394c00f | 22100 | |
c19d1205 | 22101 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 22102 | |
c19d1205 ZW |
22103 | for (opt = arm_opts; opt->option != NULL; opt++) |
22104 | if (opt->help != NULL) | |
22105 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 22106 | |
c19d1205 ZW |
22107 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
22108 | if (lopt->help != NULL) | |
22109 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 22110 | |
c19d1205 ZW |
22111 | #ifdef OPTION_EB |
22112 | fprintf (fp, _("\ | |
22113 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
22114 | #endif |
22115 | ||
c19d1205 ZW |
22116 | #ifdef OPTION_EL |
22117 | fprintf (fp, _("\ | |
22118 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 22119 | #endif |
845b51d6 PB |
22120 | |
22121 | fprintf (fp, _("\ | |
22122 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 22123 | } |
ee065d83 PB |
22124 | |
22125 | ||
22126 | #ifdef OBJ_ELF | |
62b3e311 PB |
22127 | typedef struct |
22128 | { | |
22129 | int val; | |
22130 | arm_feature_set flags; | |
22131 | } cpu_arch_ver_table; | |
22132 | ||
22133 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
22134 | least features first. */ | |
22135 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
22136 | { | |
22137 | {1, ARM_ARCH_V4}, | |
22138 | {2, ARM_ARCH_V4T}, | |
22139 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 22140 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
22141 | {4, ARM_ARCH_V5TE}, |
22142 | {5, ARM_ARCH_V5TEJ}, | |
22143 | {6, ARM_ARCH_V6}, | |
22144 | {7, ARM_ARCH_V6Z}, | |
7e806470 | 22145 | {9, ARM_ARCH_V6K}, |
91e22acd | 22146 | {11, ARM_ARCH_V6M}, |
7e806470 | 22147 | {8, ARM_ARCH_V6T2}, |
62b3e311 PB |
22148 | {10, ARM_ARCH_V7A}, |
22149 | {10, ARM_ARCH_V7R}, | |
22150 | {10, ARM_ARCH_V7M}, | |
22151 | {0, ARM_ARCH_NONE} | |
22152 | }; | |
22153 | ||
ee3c0378 AS |
22154 | /* Set an attribute if it has not already been set by the user. */ |
22155 | static void | |
22156 | aeabi_set_attribute_int (int tag, int value) | |
22157 | { | |
22158 | if (tag < 1 | |
22159 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22160 | || !attributes_set_explicitly[tag]) | |
22161 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
22162 | } | |
22163 | ||
22164 | static void | |
22165 | aeabi_set_attribute_string (int tag, const char *value) | |
22166 | { | |
22167 | if (tag < 1 | |
22168 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
22169 | || !attributes_set_explicitly[tag]) | |
22170 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
22171 | } | |
22172 | ||
ee065d83 PB |
22173 | /* Set the public EABI object attributes. */ |
22174 | static void | |
22175 | aeabi_set_public_attributes (void) | |
22176 | { | |
22177 | int arch; | |
e74cfd16 | 22178 | arm_feature_set flags; |
62b3e311 PB |
22179 | arm_feature_set tmp; |
22180 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
22181 | |
22182 | /* Choose the architecture based on the capabilities of the requested cpu | |
22183 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
22184 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
22185 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
22186 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
7a1d4c38 PB |
22187 | /*Allow the user to override the reported architecture. */ |
22188 | if (object_arch) | |
22189 | { | |
22190 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
22191 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
22192 | } | |
22193 | ||
62b3e311 PB |
22194 | tmp = flags; |
22195 | arch = 0; | |
22196 | for (p = cpu_arch_ver; p->val; p++) | |
22197 | { | |
22198 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
22199 | { | |
22200 | arch = p->val; | |
22201 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
22202 | } | |
22203 | } | |
ee065d83 PB |
22204 | |
22205 | /* Tag_CPU_name. */ | |
22206 | if (selected_cpu_name[0]) | |
22207 | { | |
22208 | char *p; | |
22209 | ||
22210 | p = selected_cpu_name; | |
5f4273c7 | 22211 | if (strncmp (p, "armv", 4) == 0) |
ee065d83 PB |
22212 | { |
22213 | int i; | |
5f4273c7 | 22214 | |
ee065d83 PB |
22215 | p += 4; |
22216 | for (i = 0; p[i]; i++) | |
22217 | p[i] = TOUPPER (p[i]); | |
22218 | } | |
ee3c0378 | 22219 | aeabi_set_attribute_string (Tag_CPU_name, p); |
ee065d83 PB |
22220 | } |
22221 | /* Tag_CPU_arch. */ | |
ee3c0378 | 22222 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62b3e311 PB |
22223 | /* Tag_CPU_arch_profile. */ |
22224 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
ee3c0378 | 22225 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A'); |
62b3e311 | 22226 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
ee3c0378 | 22227 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R'); |
7e806470 | 22228 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
ee3c0378 | 22229 | aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M'); |
ee065d83 | 22230 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
22231 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
22232 | || arch == 0) | |
22233 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
ee065d83 | 22234 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
22235 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
22236 | || arch == 0) | |
22237 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, | |
22238 | ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1); | |
ee065d83 | 22239 | /* Tag_VFP_arch. */ |
ee3c0378 AS |
22240 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) |
22241 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
22242 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3)) | |
22243 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
22244 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) | |
22245 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
22246 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
22247 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) | |
22248 | aeabi_set_attribute_int (Tag_VFP_arch, 1); | |
ee065d83 | 22249 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
22250 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
22251 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
22252 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
22253 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
22254 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ | |
8e79c3df | 22255 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) |
ee3c0378 AS |
22256 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); |
22257 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ | |
8e79c3df | 22258 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16)) |
ee3c0378 | 22259 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
ee065d83 PB |
22260 | } |
22261 | ||
104d59d1 | 22262 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
22263 | void |
22264 | arm_md_end (void) | |
22265 | { | |
ee065d83 PB |
22266 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
22267 | return; | |
22268 | ||
22269 | aeabi_set_public_attributes (); | |
ee065d83 | 22270 | } |
8463be01 | 22271 | #endif /* OBJ_ELF */ |
ee065d83 PB |
22272 | |
22273 | ||
22274 | /* Parse a .cpu directive. */ | |
22275 | ||
22276 | static void | |
22277 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
22278 | { | |
e74cfd16 | 22279 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
22280 | char *name; |
22281 | char saved_char; | |
22282 | ||
22283 | name = input_line_pointer; | |
5f4273c7 | 22284 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22285 | input_line_pointer++; |
22286 | saved_char = *input_line_pointer; | |
22287 | *input_line_pointer = 0; | |
22288 | ||
22289 | /* Skip the first "all" entry. */ | |
22290 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
22291 | if (streq (opt->name, name)) | |
22292 | { | |
e74cfd16 PB |
22293 | mcpu_cpu_opt = &opt->value; |
22294 | selected_cpu = opt->value; | |
ee065d83 | 22295 | if (opt->canonical_name) |
5f4273c7 | 22296 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
22297 | else |
22298 | { | |
22299 | int i; | |
22300 | for (i = 0; opt->name[i]; i++) | |
22301 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
22302 | selected_cpu_name[i] = 0; | |
22303 | } | |
e74cfd16 | 22304 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22305 | *input_line_pointer = saved_char; |
22306 | demand_empty_rest_of_line (); | |
22307 | return; | |
22308 | } | |
22309 | as_bad (_("unknown cpu `%s'"), name); | |
22310 | *input_line_pointer = saved_char; | |
22311 | ignore_rest_of_line (); | |
22312 | } | |
22313 | ||
22314 | ||
22315 | /* Parse a .arch directive. */ | |
22316 | ||
22317 | static void | |
22318 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
22319 | { | |
e74cfd16 | 22320 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
22321 | char saved_char; |
22322 | char *name; | |
22323 | ||
22324 | name = input_line_pointer; | |
5f4273c7 | 22325 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22326 | input_line_pointer++; |
22327 | saved_char = *input_line_pointer; | |
22328 | *input_line_pointer = 0; | |
22329 | ||
22330 | /* Skip the first "all" entry. */ | |
22331 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22332 | if (streq (opt->name, name)) | |
22333 | { | |
e74cfd16 PB |
22334 | mcpu_cpu_opt = &opt->value; |
22335 | selected_cpu = opt->value; | |
5f4273c7 | 22336 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 22337 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
22338 | *input_line_pointer = saved_char; |
22339 | demand_empty_rest_of_line (); | |
22340 | return; | |
22341 | } | |
22342 | ||
22343 | as_bad (_("unknown architecture `%s'\n"), name); | |
22344 | *input_line_pointer = saved_char; | |
22345 | ignore_rest_of_line (); | |
22346 | } | |
22347 | ||
22348 | ||
7a1d4c38 PB |
22349 | /* Parse a .object_arch directive. */ |
22350 | ||
22351 | static void | |
22352 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
22353 | { | |
22354 | const struct arm_arch_option_table *opt; | |
22355 | char saved_char; | |
22356 | char *name; | |
22357 | ||
22358 | name = input_line_pointer; | |
5f4273c7 | 22359 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
22360 | input_line_pointer++; |
22361 | saved_char = *input_line_pointer; | |
22362 | *input_line_pointer = 0; | |
22363 | ||
22364 | /* Skip the first "all" entry. */ | |
22365 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
22366 | if (streq (opt->name, name)) | |
22367 | { | |
22368 | object_arch = &opt->value; | |
22369 | *input_line_pointer = saved_char; | |
22370 | demand_empty_rest_of_line (); | |
22371 | return; | |
22372 | } | |
22373 | ||
22374 | as_bad (_("unknown architecture `%s'\n"), name); | |
22375 | *input_line_pointer = saved_char; | |
22376 | ignore_rest_of_line (); | |
22377 | } | |
22378 | ||
ee065d83 PB |
22379 | /* Parse a .fpu directive. */ |
22380 | ||
22381 | static void | |
22382 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
22383 | { | |
e74cfd16 | 22384 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
22385 | char saved_char; |
22386 | char *name; | |
22387 | ||
22388 | name = input_line_pointer; | |
5f4273c7 | 22389 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
22390 | input_line_pointer++; |
22391 | saved_char = *input_line_pointer; | |
22392 | *input_line_pointer = 0; | |
5f4273c7 | 22393 | |
ee065d83 PB |
22394 | for (opt = arm_fpus; opt->name != NULL; opt++) |
22395 | if (streq (opt->name, name)) | |
22396 | { | |
e74cfd16 PB |
22397 | mfpu_opt = &opt->value; |
22398 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
22399 | *input_line_pointer = saved_char; |
22400 | demand_empty_rest_of_line (); | |
22401 | return; | |
22402 | } | |
22403 | ||
22404 | as_bad (_("unknown floating point format `%s'\n"), name); | |
22405 | *input_line_pointer = saved_char; | |
22406 | ignore_rest_of_line (); | |
22407 | } | |
ee065d83 | 22408 | |
794ba86a | 22409 | /* Copy symbol information. */ |
f31fef98 | 22410 | |
794ba86a DJ |
22411 | void |
22412 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
22413 | { | |
22414 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
22415 | } | |
e04befd0 | 22416 | |
f31fef98 | 22417 | #ifdef OBJ_ELF |
e04befd0 AS |
22418 | /* Given a symbolic attribute NAME, return the proper integer value. |
22419 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 22420 | |
e04befd0 AS |
22421 | int |
22422 | arm_convert_symbolic_attribute (const char *name) | |
22423 | { | |
f31fef98 NC |
22424 | static const struct |
22425 | { | |
22426 | const char * name; | |
22427 | const int tag; | |
22428 | } | |
22429 | attribute_table[] = | |
22430 | { | |
22431 | /* When you modify this table you should | |
22432 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 22433 | #define T(tag) {#tag, tag} |
f31fef98 NC |
22434 | T (Tag_CPU_raw_name), |
22435 | T (Tag_CPU_name), | |
22436 | T (Tag_CPU_arch), | |
22437 | T (Tag_CPU_arch_profile), | |
22438 | T (Tag_ARM_ISA_use), | |
22439 | T (Tag_THUMB_ISA_use), | |
22440 | T (Tag_VFP_arch), | |
22441 | T (Tag_WMMX_arch), | |
22442 | T (Tag_Advanced_SIMD_arch), | |
22443 | T (Tag_PCS_config), | |
22444 | T (Tag_ABI_PCS_R9_use), | |
22445 | T (Tag_ABI_PCS_RW_data), | |
22446 | T (Tag_ABI_PCS_RO_data), | |
22447 | T (Tag_ABI_PCS_GOT_use), | |
22448 | T (Tag_ABI_PCS_wchar_t), | |
22449 | T (Tag_ABI_FP_rounding), | |
22450 | T (Tag_ABI_FP_denormal), | |
22451 | T (Tag_ABI_FP_exceptions), | |
22452 | T (Tag_ABI_FP_user_exceptions), | |
22453 | T (Tag_ABI_FP_number_model), | |
22454 | T (Tag_ABI_align8_needed), | |
22455 | T (Tag_ABI_align8_preserved), | |
22456 | T (Tag_ABI_enum_size), | |
22457 | T (Tag_ABI_HardFP_use), | |
22458 | T (Tag_ABI_VFP_args), | |
22459 | T (Tag_ABI_WMMX_args), | |
22460 | T (Tag_ABI_optimization_goals), | |
22461 | T (Tag_ABI_FP_optimization_goals), | |
22462 | T (Tag_compatibility), | |
22463 | T (Tag_CPU_unaligned_access), | |
22464 | T (Tag_VFP_HP_extension), | |
22465 | T (Tag_ABI_FP_16bit_format), | |
22466 | T (Tag_nodefaults), | |
22467 | T (Tag_also_compatible_with), | |
22468 | T (Tag_conformance), | |
22469 | T (Tag_T2EE_use), | |
22470 | T (Tag_Virtualization_use), | |
22471 | T (Tag_MPextension_use) | |
e04befd0 | 22472 | #undef T |
f31fef98 | 22473 | }; |
e04befd0 AS |
22474 | unsigned int i; |
22475 | ||
22476 | if (name == NULL) | |
22477 | return -1; | |
22478 | ||
f31fef98 | 22479 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 22480 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
22481 | return attribute_table[i].tag; |
22482 | ||
22483 | return -1; | |
22484 | } | |
267bf995 RR |
22485 | |
22486 | ||
22487 | /* Apply sym value for relocations only in the case that | |
22488 | they are for local symbols and you have the respective | |
22489 | architectural feature for blx and simple switches. */ | |
22490 | int | |
22491 | arm_apply_sym_value (struct fix * fixP) | |
22492 | { | |
22493 | if (fixP->fx_addsy | |
22494 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
22495 | && !S_IS_EXTERNAL (fixP->fx_addsy)) | |
22496 | { | |
22497 | switch (fixP->fx_r_type) | |
22498 | { | |
22499 | case BFD_RELOC_ARM_PCREL_BLX: | |
22500 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
22501 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
22502 | return 1; | |
22503 | break; | |
22504 | ||
22505 | case BFD_RELOC_ARM_PCREL_CALL: | |
22506 | case BFD_RELOC_THUMB_PCREL_BLX: | |
22507 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
22508 | return 1; | |
22509 | break; | |
22510 | ||
22511 | default: | |
22512 | break; | |
22513 | } | |
22514 | ||
22515 | } | |
22516 | return 0; | |
22517 | } | |
f31fef98 | 22518 | #endif /* OBJ_ELF */ |