ld: Move the .note.build-id section to near the start of the memory map.
[binutils-gdb.git] / gas / config / tc-arm.c
blob540ab4873843a49214d85642b59520ef7a7dd971
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2024 Free Software Foundation, Inc.
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
9 This file is part of GAS, the GNU Assembler.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
14 any later version.
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
26 #include "as.h"
27 #include <limits.h>
28 #include <stdarg.h>
29 #define NO_RELOC 0
30 #include "safe-ctype.h"
31 #include "subsegs.h"
32 #include "obstack.h"
33 #include "libiberty.h"
34 #include "opcode/arm.h"
35 #include "cpu-arm.h"
37 #ifdef OBJ_ELF
38 #include "elf/arm.h"
39 #include "dw2gencfi.h"
40 #endif
42 #include "dwarf2dbg.h"
44 #ifdef OBJ_ELF
45 /* Must be at least the size of the largest unwind opcode (currently two). */
46 #define ARM_OPCODE_CHUNK_SIZE 8
48 /* This structure holds the unwinding state. */
50 static struct
52 symbolS * proc_start;
53 symbolS * table_entry;
54 symbolS * personality_routine;
55 int personality_index;
56 /* The segment containing the function. */
57 segT saved_seg;
58 subsegT saved_subseg;
59 /* Opcodes generated from this function. */
60 unsigned char * opcodes;
61 int opcode_count;
62 int opcode_alloc;
63 /* The number of bytes pushed to the stack. */
64 offsetT frame_size;
65 /* We don't add stack adjustment opcodes immediately so that we can merge
66 multiple adjustments. We can also omit the final adjustment
67 when using a frame pointer. */
68 offsetT pending_offset;
69 /* These two fields are set by both unwind_movsp and unwind_setfp. They
70 hold the reg+offset to use when restoring sp from a frame pointer. */
71 offsetT fp_offset;
72 int fp_reg;
73 /* Nonzero if an unwind_setfp directive has been seen. */
74 unsigned fp_used:1;
75 /* Nonzero if the last opcode restores sp from fp_reg. */
76 unsigned sp_restored:1;
77 } unwind;
79 /* Whether --fdpic was given. */
80 static int arm_fdpic;
82 #endif /* OBJ_ELF */
84 /* Results from operand parsing worker functions. */
86 typedef enum
88 PARSE_OPERAND_SUCCESS,
89 PARSE_OPERAND_FAIL,
90 PARSE_OPERAND_FAIL_NO_BACKTRACK
91 } parse_operand_result;
93 enum arm_float_abi
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
100 /* Types of processor to assemble for. */
101 #ifndef CPU_DEFAULT
102 /* The code that was here used to select a default CPU depending on compiler
103 pre-defines which were only present when doing native builds, thus
104 changing gas' default behaviour depending upon the build host.
106 If you have a target that requires a default CPU option then the you
107 should define CPU_DEFAULT here. */
108 #endif
110 /* Perform range checks on positive and negative overflows by checking if the
111 VALUE given fits within the range of an BITS sized immediate. */
112 static bool out_of_range_p (offsetT value, offsetT bits)
114 gas_assert (bits < (offsetT)(sizeof (value) * 8));
115 return (value & ~((1 << bits)-1))
116 && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
119 #ifndef FPU_DEFAULT
120 # ifdef TE_LINUX
121 # define FPU_DEFAULT FPU_NONE
122 # elif defined (TE_NetBSD)
123 # ifdef OBJ_ELF
124 # define FPU_DEFAULT FPU_ARCH_SOFTVFP /* Soft-float, but VFP order. */
125 # else
126 /* Legacy a.out format. */
127 # define FPU_DEFAULT FPU_NONE /* Soft-float, no FPU. */
128 # endif
129 # elif defined (TE_VXWORKS)
130 # define FPU_DEFAULT FPU_ARCH_SOFTVFP /* Soft-float, VFP order. */
131 # else
132 /* For backwards compatibility, default to no-fpu so that we don't
133 get silent code changes of FP literal data. */
134 # define FPU_DEFAULT FPU_NONE
135 # endif
136 #endif /* ifndef FPU_DEFAULT */
138 #define streq(a, b) (strcmp (a, b) == 0)
140 /* Current set of feature bits available (CPU+FPU). Different from
141 selected_cpu + selected_fpu in case of autodetection since the CPU
142 feature bits are then all set. */
143 static arm_feature_set cpu_variant;
144 /* Feature bits used in each execution state. Used to set build attribute
145 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
146 static arm_feature_set arm_arch_used;
147 static arm_feature_set thumb_arch_used;
149 /* Flags stored in private area of BFD structure. */
150 static int uses_apcs_26 = false;
151 static int atpcs = false;
152 static int support_interwork = false;
153 static int uses_apcs_float = false;
154 static int pic_code = false;
155 static int fix_v4bx = false;
156 /* Warn on using deprecated features. */
157 static int warn_on_deprecated = true;
158 static int warn_on_restrict_it = false;
160 /* Understand CodeComposer Studio assembly syntax. */
161 bool codecomposer_syntax = false;
163 /* Variables that we set while parsing command-line options. Once all
164 options have been read we re-process these values to set the real
165 assembly flags. */
167 /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
168 instead of -mcpu=arm1). */
169 static const arm_feature_set *legacy_cpu = NULL;
170 static const arm_feature_set *legacy_fpu = NULL;
172 /* CPU, extension and FPU feature bits selected by -mcpu. */
173 static const arm_feature_set *mcpu_cpu_opt = NULL;
174 static arm_feature_set *mcpu_ext_opt = NULL;
175 static const arm_feature_set *mcpu_fpu_opt = NULL;
177 /* CPU, extension and FPU feature bits selected by -march. */
178 static const arm_feature_set *march_cpu_opt = NULL;
179 static arm_feature_set *march_ext_opt = NULL;
180 static const arm_feature_set *march_fpu_opt = NULL;
182 /* Feature bits selected by -mfpu. */
183 static const arm_feature_set *mfpu_opt = NULL;
185 /* Constants for known architecture features. */
186 static const arm_feature_set fpu_default = FPU_DEFAULT;
187 static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
188 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
189 static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
190 static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
191 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
192 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
194 #ifdef CPU_DEFAULT
195 static const arm_feature_set cpu_default = CPU_DEFAULT;
196 #endif
198 static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
199 static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
200 static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
201 static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
202 static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
203 static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
204 static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
205 static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
206 static const arm_feature_set arm_ext_v4t_5 =
207 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
208 static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
209 static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
210 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
211 static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
212 static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
213 static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
214 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
215 /* Only for compatability of hint instructions. */
216 static const arm_feature_set arm_ext_v6k_v6t2 =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
218 static const arm_feature_set arm_ext_v6_notm =
219 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
220 static const arm_feature_set arm_ext_v6_dsp =
221 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
222 static const arm_feature_set arm_ext_barrier =
223 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
224 static const arm_feature_set arm_ext_msr =
225 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
226 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
227 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
228 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
229 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
230 static const arm_feature_set arm_ext_v8r = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8R);
231 #ifdef OBJ_ELF
232 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
233 #endif
234 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
235 static const arm_feature_set arm_ext_m =
236 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
237 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
238 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
239 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
240 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
241 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
242 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
243 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
244 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
245 static const arm_feature_set arm_ext_v8m_main =
246 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
247 static const arm_feature_set arm_ext_v8_1m_main =
248 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
249 /* Instructions in ARMv8-M only found in M profile architectures. */
250 static const arm_feature_set arm_ext_v8m_m_only =
251 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
252 static const arm_feature_set arm_ext_v6t2_v8m =
253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
254 /* Instructions shared between ARMv8-A and ARMv8-M. */
255 static const arm_feature_set arm_ext_atomics =
256 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
257 #ifdef OBJ_ELF
258 /* DSP instructions Tag_DSP_extension refers to. */
259 static const arm_feature_set arm_ext_dsp =
260 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
261 #endif
262 static const arm_feature_set arm_ext_ras =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
264 /* FP16 instructions. */
265 static const arm_feature_set arm_ext_fp16 =
266 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
267 static const arm_feature_set arm_ext_fp16_fml =
268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
269 static const arm_feature_set arm_ext_v8_2 =
270 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
271 static const arm_feature_set arm_ext_v8_3 =
272 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
273 static const arm_feature_set arm_ext_sb =
274 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
275 static const arm_feature_set arm_ext_predres =
276 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
277 static const arm_feature_set arm_ext_bf16 =
278 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
279 static const arm_feature_set arm_ext_i8mm =
280 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
281 static const arm_feature_set arm_ext_crc =
282 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
283 static const arm_feature_set arm_ext_cde =
284 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
285 static const arm_feature_set arm_ext_cde0 =
286 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
287 static const arm_feature_set arm_ext_cde1 =
288 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
289 static const arm_feature_set arm_ext_cde2 =
290 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
291 static const arm_feature_set arm_ext_cde3 =
292 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
293 static const arm_feature_set arm_ext_cde4 =
294 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
295 static const arm_feature_set arm_ext_cde5 =
296 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
297 static const arm_feature_set arm_ext_cde6 =
298 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
299 static const arm_feature_set arm_ext_cde7 =
300 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
302 static const arm_feature_set arm_arch_any = ARM_ANY;
303 static const arm_feature_set fpu_any = FPU_ANY;
304 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
305 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
306 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
308 static const arm_feature_set arm_cext_iwmmxt2 =
309 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
310 static const arm_feature_set arm_cext_iwmmxt =
311 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
312 static const arm_feature_set arm_cext_xscale =
313 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
314 static const arm_feature_set fpu_vfp_ext_v1xd =
315 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
316 static const arm_feature_set fpu_vfp_ext_v1 =
317 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
318 static const arm_feature_set fpu_vfp_ext_v2 =
319 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
320 static const arm_feature_set fpu_vfp_ext_v3xd =
321 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
322 static const arm_feature_set fpu_vfp_ext_v3 =
323 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
324 static const arm_feature_set fpu_vfp_ext_d32 =
325 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
326 static const arm_feature_set fpu_neon_ext_v1 =
327 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
328 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
329 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
330 static const arm_feature_set mve_ext =
331 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
332 static const arm_feature_set mve_fp_ext =
333 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
334 /* Note: This has more than one bit set, which means using it with
335 mark_feature_used (which returns if *any* of the bits are set in the current
336 cpu variant) can give surprising results. */
337 static const arm_feature_set armv8m_fp =
338 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
339 #ifdef OBJ_ELF
340 static const arm_feature_set fpu_vfp_fp16 =
341 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
342 static const arm_feature_set fpu_neon_ext_fma =
343 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
344 #endif
345 static const arm_feature_set fpu_vfp_ext_fma =
346 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
347 static const arm_feature_set fpu_vfp_ext_armv8 =
348 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
349 static const arm_feature_set fpu_vfp_ext_armv8xd =
350 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
351 static const arm_feature_set fpu_neon_ext_armv8 =
352 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
353 static const arm_feature_set fpu_crypto_ext_armv8 =
354 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
355 static const arm_feature_set fpu_neon_ext_v8_1 =
356 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
357 static const arm_feature_set fpu_neon_ext_dotprod =
358 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
359 static const arm_feature_set pacbti_ext =
360 ARM_FEATURE_CORE_HIGH_HIGH (ARM_EXT3_PACBTI);
362 static int mfloat_abi_opt = -1;
363 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
364 directive. */
365 static arm_feature_set selected_arch = ARM_ARCH_NONE;
366 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
367 directive. */
368 static arm_feature_set selected_ext = ARM_ARCH_NONE;
369 /* Feature bits selected by the last -mcpu/-march or by the combination of the
370 last .cpu/.arch directive .arch_extension directives since that
371 directive. */
372 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
373 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
374 static arm_feature_set selected_fpu = FPU_NONE;
375 /* Feature bits selected by the last .object_arch directive. */
376 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
377 /* Must be long enough to hold any of the names in arm_cpus. */
378 static const struct arm_ext_table * selected_ctx_ext_table = NULL;
379 static char selected_cpu_name[20];
381 extern FLONUM_TYPE generic_floating_point_number;
383 /* Return if no cpu was selected on command-line. */
384 static bool
385 no_cpu_selected (void)
387 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
390 #ifdef OBJ_ELF
391 # ifdef EABI_DEFAULT
392 static int meabi_flags = EABI_DEFAULT;
393 # else
394 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
395 # endif
397 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
399 bool
400 arm_is_eabi (void)
402 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
404 #endif
406 #ifdef OBJ_ELF
407 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
408 symbolS * GOT_symbol;
409 #endif
411 /* 0: assemble for ARM,
412 1: assemble for Thumb,
413 2: assemble for Thumb even though target CPU does not support thumb
414 instructions. */
415 static int thumb_mode = 0;
416 /* A value distinct from the possible values for thumb_mode that we
417 can use to record whether thumb_mode has been copied into the
418 tc_frag_data field of a frag. */
419 #define MODE_RECORDED (1 << 4)
421 /* Specifies the intrinsic IT insn behavior mode. */
422 enum implicit_it_mode
424 IMPLICIT_IT_MODE_NEVER = 0x00,
425 IMPLICIT_IT_MODE_ARM = 0x01,
426 IMPLICIT_IT_MODE_THUMB = 0x02,
427 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
429 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
431 /* If unified_syntax is true, we are processing the new unified
432 ARM/Thumb syntax. Important differences from the old ARM mode:
434 - Immediate operands do not require a # prefix.
435 - Conditional affixes always appear at the end of the
436 instruction. (For backward compatibility, those instructions
437 that formerly had them in the middle, continue to accept them
438 there.)
439 - The IT instruction may appear, and if it does is validated
440 against subsequent conditional affixes. It does not generate
441 machine code.
443 Important differences from the old Thumb mode:
445 - Immediate operands do not require a # prefix.
446 - Most of the V6T2 instructions are only available in unified mode.
447 - The .N and .W suffixes are recognized and honored (it is an error
448 if they cannot be honored).
449 - All instructions set the flags if and only if they have an 's' affix.
450 - Conditional affixes may be used. They are validated against
451 preceding IT instructions. Unlike ARM mode, you cannot use a
452 conditional affix except in the scope of an IT instruction. */
454 static bool unified_syntax = false;
456 /* An immediate operand can start with #, and ld*, st*, pld operands
457 can contain [ and ]. We need to tell APP not to elide whitespace
458 before a [, which can appear as the first operand for pld.
459 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
460 const char arm_symbol_chars[] = "#[]{}";
462 enum neon_el_type
464 NT_invtype,
465 NT_untyped,
466 NT_integer,
467 NT_float,
468 NT_poly,
469 NT_signed,
470 NT_bfloat,
471 NT_unsigned
474 struct neon_type_el
476 enum neon_el_type type;
477 unsigned size;
480 #define NEON_MAX_TYPE_ELS 5
482 struct neon_type
484 struct neon_type_el el[NEON_MAX_TYPE_ELS];
485 unsigned elems;
488 enum pred_instruction_type
490 OUTSIDE_PRED_INSN,
491 INSIDE_VPT_INSN,
492 INSIDE_IT_INSN,
493 INSIDE_IT_LAST_INSN,
494 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
495 if inside, should be the last one. */
496 NEUTRAL_IT_INSN, /* This could be either inside or outside,
497 i.e. BKPT and NOP. */
498 IT_INSN, /* The IT insn has been parsed. */
499 VPT_INSN, /* The VPT/VPST insn has been parsed. */
500 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
501 a predication code. */
502 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
505 /* The maximum number of operands we need. */
506 #define ARM_IT_MAX_OPERANDS 6
507 #define ARM_IT_MAX_RELOCS 3
509 struct arm_it
511 const char * error;
512 unsigned long instruction;
513 unsigned int size;
514 unsigned int size_req;
515 unsigned int cond;
516 /* "uncond_value" is set to the value in place of the conditional field in
517 unconditional versions of the instruction, or -1u if nothing is
518 appropriate. */
519 unsigned int uncond_value;
520 struct neon_type vectype;
521 /* This does not indicate an actual NEON instruction, only that
522 the mnemonic accepts neon-style type suffixes. */
523 int is_neon;
524 /* Set to the opcode if the instruction needs relaxation.
525 Zero if the instruction is not relaxed. */
526 unsigned long relax;
527 struct
529 bfd_reloc_code_real_type type;
530 expressionS exp;
531 int pc_rel;
532 } relocs[ARM_IT_MAX_RELOCS];
534 enum pred_instruction_type pred_insn_type;
536 struct
538 unsigned reg;
539 signed int imm;
540 struct neon_type_el vectype;
541 unsigned present : 1; /* Operand present. */
542 unsigned isreg : 1; /* Operand was a register. */
543 unsigned immisreg : 2; /* .imm field is a second register.
544 0: imm, 1: gpr, 2: MVE Q-register. */
545 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
546 0) not scalar,
547 1) Neon scalar,
548 2) MVE scalar. */
549 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
550 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
551 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
552 instructions. This allows us to disambiguate ARM <-> vector insns. */
553 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
554 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
555 unsigned isquad : 1; /* Operand is SIMD quad register. */
556 unsigned issingle : 1; /* Operand is VFP single-precision register. */
557 unsigned iszr : 1; /* Operand is ZR register. */
558 unsigned hasreloc : 1; /* Operand has relocation suffix. */
559 unsigned writeback : 1; /* Operand has trailing ! */
560 unsigned preind : 1; /* Preindexed address. */
561 unsigned postind : 1; /* Postindexed address. */
562 unsigned negative : 1; /* Index register was negated. */
563 unsigned shifted : 1; /* Shift applied to operation. */
564 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
565 } operands[ARM_IT_MAX_OPERANDS];
568 static struct arm_it inst;
570 #define NUM_FLOAT_VALS 8
572 const char * fp_const[] =
574 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
577 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
579 #define FAIL (-1)
580 #define SUCCESS (0)
582 #define SUFF_S 1
583 #define SUFF_D 2
584 #define SUFF_E 3
585 #define SUFF_P 4
587 #define CP_T_X 0x00008000
588 #define CP_T_Y 0x00400000
590 #define CONDS_BIT 0x00100000
591 #define LOAD_BIT 0x00100000
593 #define DOUBLE_LOAD_FLAG 0x00000001
595 struct asm_cond
597 const char * template_name;
598 unsigned long value;
601 #define COND_ALWAYS 0xE
603 struct asm_psr
605 const char * template_name;
606 unsigned long field;
609 struct asm_barrier_opt
611 const char * template_name;
612 unsigned long value;
613 const arm_feature_set arch;
616 /* The bit that distinguishes CPSR and SPSR. */
617 #define SPSR_BIT (1 << 22)
619 /* The individual PSR flag bits. */
620 #define PSR_c (1 << 16)
621 #define PSR_x (1 << 17)
622 #define PSR_s (1 << 18)
623 #define PSR_f (1 << 19)
625 struct reloc_entry
627 const char * name;
628 bfd_reloc_code_real_type reloc;
631 enum vfp_reg_pos
633 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
634 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
637 enum vfp_ldstm_type
639 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
642 /* Bits for DEFINED field in neon_typed_alias. */
643 #define NTA_HASTYPE 1
644 #define NTA_HASINDEX 2
646 struct neon_typed_alias
648 unsigned char defined;
649 unsigned char index;
650 struct neon_type_el eltype;
653 /* ARM register categories. This includes coprocessor numbers and various
654 architecture extensions' registers. Each entry should have an error message
655 in reg_expected_msgs below. */
656 enum arm_reg_type
658 REG_TYPE_RN,
659 REG_TYPE_CP,
660 REG_TYPE_CN,
661 REG_TYPE_FN,
662 REG_TYPE_VFS,
663 REG_TYPE_VFD,
664 REG_TYPE_NQ,
665 REG_TYPE_VFSD,
666 REG_TYPE_NDQ,
667 REG_TYPE_NSD,
668 REG_TYPE_NSDQ,
669 REG_TYPE_VFC,
670 REG_TYPE_MVF,
671 REG_TYPE_MVD,
672 REG_TYPE_MVFX,
673 REG_TYPE_MVDX,
674 REG_TYPE_MVAX,
675 REG_TYPE_MQ,
676 REG_TYPE_DSPSC,
677 REG_TYPE_MMXWR,
678 REG_TYPE_MMXWC,
679 REG_TYPE_MMXWCG,
680 REG_TYPE_XSCALE,
681 REG_TYPE_RNB,
682 REG_TYPE_ZR,
683 REG_TYPE_PSEUDO
686 /* Structure for a hash table entry for a register.
687 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
688 information which states whether a vector type or index is specified (for a
689 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
690 struct reg_entry
692 const char * name;
693 unsigned int number;
694 unsigned char type;
695 unsigned char builtin;
696 struct neon_typed_alias * neon;
699 /* Diagnostics used when we don't get a register of the expected type. */
700 const char * const reg_expected_msgs[] =
702 [REG_TYPE_RN] = N_("ARM register expected"),
703 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
704 [REG_TYPE_CN] = N_("co-processor register expected"),
705 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
706 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
707 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
708 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
709 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
710 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
711 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
712 " expected"),
713 [REG_TYPE_VFC] = N_("VFP system register expected"),
714 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
715 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
716 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
717 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
718 [REG_TYPE_MQ] = N_("MVE vector register expected"),
719 [REG_TYPE_RNB] = "",
720 [REG_TYPE_ZR] = N_("ZR register expected"),
721 [REG_TYPE_PSEUDO] = N_("Pseudo register expected"),
724 /* Some well known registers that we refer to directly elsewhere. */
725 #define REG_R12 12
726 #define REG_SP 13
727 #define REG_LR 14
728 #define REG_PC 15
729 #define REG_RA_AUTH_CODE 143
731 /* ARM instructions take 4bytes in the object file, Thumb instructions
732 take 2: */
733 #define INSN_SIZE 4
735 struct asm_opcode
737 /* Basic string to match. */
738 const char * template_name;
740 /* Parameters to instruction. */
741 unsigned int operands[8];
743 /* Conditional tag - see opcode_lookup. */
744 unsigned int tag : 4;
746 /* Basic instruction code. */
747 unsigned int avalue;
749 /* Thumb-format instruction code. */
750 unsigned int tvalue;
752 /* Which architecture variant provides this instruction. */
753 const arm_feature_set * avariant;
754 const arm_feature_set * tvariant;
756 /* Function to call to encode instruction in ARM format. */
757 void (* aencode) (void);
759 /* Function to call to encode instruction in Thumb format. */
760 void (* tencode) (void);
762 /* Indicates whether this instruction may be vector predicated. */
763 unsigned int mayBeVecPred : 1;
766 /* Defines for various bits that we will want to toggle. */
767 #define INST_IMMEDIATE 0x02000000
768 #define OFFSET_REG 0x02000000
769 #define HWOFFSET_IMM 0x00400000
770 #define SHIFT_BY_REG 0x00000010
771 #define PRE_INDEX 0x01000000
772 #define INDEX_UP 0x00800000
773 #define WRITE_BACK 0x00200000
774 #define LDM_TYPE_2_OR_3 0x00400000
775 #define CPSI_MMOD 0x00020000
777 #define LITERAL_MASK 0xf000f000
778 #define OPCODE_MASK 0xfe1fffff
779 #define V4_STR_BIT 0x00000020
780 #define VLDR_VMOV_SAME 0x0040f000
782 #define T2_SUBS_PC_LR 0xf3de8f00
784 #define DATA_OP_SHIFT 21
785 #define SBIT_SHIFT 20
787 #define T2_OPCODE_MASK 0xfe1fffff
788 #define T2_DATA_OP_SHIFT 21
789 #define T2_SBIT_SHIFT 20
791 #define A_COND_MASK 0xf0000000
792 #define A_PUSH_POP_OP_MASK 0x0fff0000
794 /* Opcodes for pushing/poping registers to/from the stack. */
795 #define A1_OPCODE_PUSH 0x092d0000
796 #define A2_OPCODE_PUSH 0x052d0004
797 #define A2_OPCODE_POP 0x049d0004
799 /* Codes to distinguish the arithmetic instructions. */
800 #define OPCODE_AND 0
801 #define OPCODE_EOR 1
802 #define OPCODE_SUB 2
803 #define OPCODE_RSB 3
804 #define OPCODE_ADD 4
805 #define OPCODE_ADC 5
806 #define OPCODE_SBC 6
807 #define OPCODE_RSC 7
808 #define OPCODE_TST 8
809 #define OPCODE_TEQ 9
810 #define OPCODE_CMP 10
811 #define OPCODE_CMN 11
812 #define OPCODE_ORR 12
813 #define OPCODE_MOV 13
814 #define OPCODE_BIC 14
815 #define OPCODE_MVN 15
817 #define T2_OPCODE_AND 0
818 #define T2_OPCODE_BIC 1
819 #define T2_OPCODE_ORR 2
820 #define T2_OPCODE_ORN 3
821 #define T2_OPCODE_EOR 4
822 #define T2_OPCODE_ADD 8
823 #define T2_OPCODE_ADC 10
824 #define T2_OPCODE_SBC 11
825 #define T2_OPCODE_SUB 13
826 #define T2_OPCODE_RSB 14
828 #define T_OPCODE_MUL 0x4340
829 #define T_OPCODE_TST 0x4200
830 #define T_OPCODE_CMN 0x42c0
831 #define T_OPCODE_NEG 0x4240
832 #define T_OPCODE_MVN 0x43c0
834 #define T_OPCODE_ADD_R3 0x1800
835 #define T_OPCODE_SUB_R3 0x1a00
836 #define T_OPCODE_ADD_HI 0x4400
837 #define T_OPCODE_ADD_ST 0xb000
838 #define T_OPCODE_SUB_ST 0xb080
839 #define T_OPCODE_ADD_SP 0xa800
840 #define T_OPCODE_ADD_PC 0xa000
841 #define T_OPCODE_ADD_I8 0x3000
842 #define T_OPCODE_SUB_I8 0x3800
843 #define T_OPCODE_ADD_I3 0x1c00
844 #define T_OPCODE_SUB_I3 0x1e00
846 #define T_OPCODE_ASR_R 0x4100
847 #define T_OPCODE_LSL_R 0x4080
848 #define T_OPCODE_LSR_R 0x40c0
849 #define T_OPCODE_ROR_R 0x41c0
850 #define T_OPCODE_ASR_I 0x1000
851 #define T_OPCODE_LSL_I 0x0000
852 #define T_OPCODE_LSR_I 0x0800
854 #define T_OPCODE_MOV_I8 0x2000
855 #define T_OPCODE_CMP_I8 0x2800
856 #define T_OPCODE_CMP_LR 0x4280
857 #define T_OPCODE_MOV_HR 0x4600
858 #define T_OPCODE_CMP_HR 0x4500
860 #define T_OPCODE_LDR_PC 0x4800
861 #define T_OPCODE_LDR_SP 0x9800
862 #define T_OPCODE_STR_SP 0x9000
863 #define T_OPCODE_LDR_IW 0x6800
864 #define T_OPCODE_STR_IW 0x6000
865 #define T_OPCODE_LDR_IH 0x8800
866 #define T_OPCODE_STR_IH 0x8000
867 #define T_OPCODE_LDR_IB 0x7800
868 #define T_OPCODE_STR_IB 0x7000
869 #define T_OPCODE_LDR_RW 0x5800
870 #define T_OPCODE_STR_RW 0x5000
871 #define T_OPCODE_LDR_RH 0x5a00
872 #define T_OPCODE_STR_RH 0x5200
873 #define T_OPCODE_LDR_RB 0x5c00
874 #define T_OPCODE_STR_RB 0x5400
876 #define T_OPCODE_PUSH 0xb400
877 #define T_OPCODE_POP 0xbc00
879 #define T_OPCODE_BRANCH 0xe000
881 #define THUMB_SIZE 2 /* Size of thumb instruction. */
882 #define THUMB_PP_PC_LR 0x0100
883 #define THUMB_LOAD_BIT 0x0800
884 #define THUMB2_LOAD_BIT 0x00100000
886 #define BAD_SYNTAX _("syntax error")
887 #define BAD_ARGS _("bad arguments to instruction")
888 #define BAD_SP _("r13 not allowed here")
889 #define BAD_PC _("r15 not allowed here")
890 #define BAD_ODD _("Odd register not allowed here")
891 #define BAD_EVEN _("Even register not allowed here")
892 #define BAD_COND _("instruction cannot be conditional")
893 #define BAD_OVERLAP _("registers may not be the same")
894 #define BAD_HIREG _("lo register required")
895 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
896 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
897 #define BAD_BRANCH _("branch must be last instruction in IT block")
898 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
899 #define BAD_NO_VPT _("instruction not allowed in VPT block")
900 #define BAD_NOT_IT _("instruction not allowed in IT block")
901 #define BAD_NOT_VPT _("instruction missing MVE vector predication code")
902 #define BAD_FPU _("selected FPU does not support instruction")
903 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
904 #define BAD_OUT_VPT \
905 _("vector predicated instruction should be in VPT/VPST block")
906 #define BAD_IT_COND _("incorrect condition in IT block")
907 #define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
908 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
909 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
910 #define BAD_PC_ADDRESSING \
911 _("cannot use register index with PC-relative addressing")
912 #define BAD_PC_WRITEBACK \
913 _("cannot use writeback with PC-relative addressing")
914 #define BAD_RANGE _("branch out of range")
915 #define BAD_FP16 _("selected processor does not support fp16 instruction")
916 #define BAD_BF16 _("selected processor does not support bf16 instruction")
917 #define BAD_CDE _("selected processor does not support cde instruction")
918 #define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
919 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
920 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
921 #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
922 "block")
923 #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
924 "block")
925 #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
926 " operand")
927 #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
928 " operand")
929 #define BAD_SIMD_TYPE _("bad type in SIMD instruction")
930 #define BAD_MVE_AUTO \
931 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
932 " use a valid -march or -mcpu option.")
933 #define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
934 "and source operands makes instruction UNPREDICTABLE")
935 #define BAD_EL_TYPE _("bad element type for instruction")
936 #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
937 #define BAD_PACBTI _("selected processor does not support PACBTI extention")
939 static htab_t arm_ops_hsh;
940 static htab_t arm_cond_hsh;
941 static htab_t arm_vcond_hsh;
942 static htab_t arm_shift_hsh;
943 static htab_t arm_psr_hsh;
944 static htab_t arm_v7m_psr_hsh;
945 static htab_t arm_reg_hsh;
946 static htab_t arm_reloc_hsh;
947 static htab_t arm_barrier_opt_hsh;
949 /* Stuff needed to resolve the label ambiguity
952 label: <insn>
953 may differ from:
955 label:
956 <insn> */
958 symbolS * last_label_seen;
959 static int label_is_thumb_function_name = false;
961 /* Literal pool structure. Held on a per-section
962 and per-sub-section basis. */
964 #define MAX_LITERAL_POOL_SIZE 1024
965 typedef struct literal_pool
967 expressionS literals [MAX_LITERAL_POOL_SIZE];
968 unsigned int next_free_entry;
969 unsigned int id;
970 symbolS * symbol;
971 segT section;
972 subsegT sub_section;
973 #ifdef OBJ_ELF
974 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
975 #endif
976 struct literal_pool * next;
977 unsigned int alignment;
978 } literal_pool;
980 /* Pointer to a linked list of literal pools. */
981 literal_pool * list_of_pools = NULL;
983 typedef enum asmfunc_states
985 OUTSIDE_ASMFUNC,
986 WAITING_ASMFUNC_NAME,
987 WAITING_ENDASMFUNC
988 } asmfunc_states;
990 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
992 #ifdef OBJ_ELF
993 # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
994 #else
995 static struct current_pred now_pred;
996 #endif
998 static inline int
999 now_pred_compatible (int cond)
1001 return (cond & ~1) == (now_pred.cc & ~1);
1004 static inline int
1005 conditional_insn (void)
1007 return inst.cond != COND_ALWAYS;
1010 static int in_pred_block (void);
1012 static int handle_pred_state (void);
1014 static void force_automatic_it_block_close (void);
1016 static void it_fsm_post_encode (void);
1018 #define set_pred_insn_type(type) \
1019 do \
1021 inst.pred_insn_type = type; \
1022 if (handle_pred_state () == FAIL) \
1023 return; \
1025 while (0)
1027 #define set_pred_insn_type_nonvoid(type, failret) \
1028 do \
1030 inst.pred_insn_type = type; \
1031 if (handle_pred_state () == FAIL) \
1032 return failret; \
1034 while(0)
1036 #define set_pred_insn_type_last() \
1037 do \
1039 if (inst.cond == COND_ALWAYS) \
1040 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
1041 else \
1042 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
1044 while (0)
1046 /* Toggle value[pos]. */
1047 #define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1049 /* Pure syntax. */
1051 /* This array holds the chars that always start a comment. If the
1052 pre-processor is disabled, these aren't very useful. */
1053 char arm_comment_chars[] = "@";
1055 /* This array holds the chars that only start a comment at the beginning of
1056 a line. If the line seems to have the form '# 123 filename'
1057 .line and .file directives will appear in the pre-processed output. */
1058 /* Note that input_file.c hand checks for '#' at the beginning of the
1059 first line of the input file. This is because the compiler outputs
1060 #NO_APP at the beginning of its output. */
1061 /* Also note that comments like this one will always work. */
1062 const char line_comment_chars[] = "#";
1064 char arm_line_separator_chars[] = ";";
1066 /* Chars that can be used to separate mant
1067 from exp in floating point numbers. */
1068 const char EXP_CHARS[] = "eE";
1070 /* Chars that mean this number is a floating point constant. */
1071 /* As in 0f12.456 */
1072 /* or 0d1.2345e12 */
1074 const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
1076 /* Prefix characters that indicate the start of an immediate
1077 value. */
1078 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1080 /* Separator character handling. */
1082 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1084 enum fp_16bit_format
1086 ARM_FP16_FORMAT_IEEE = 0x1,
1087 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1088 ARM_FP16_FORMAT_DEFAULT = 0x3
1091 static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1094 static inline int
1095 skip_past_char (char ** str, char c)
1097 /* PR gas/14987: Allow for whitespace before the expected character. */
1098 skip_whitespace (*str);
1100 if (**str == c)
1102 (*str)++;
1103 return SUCCESS;
1105 else
1106 return FAIL;
1109 #define skip_past_comma(str) skip_past_char (str, ',')
1111 /* Arithmetic expressions (possibly involving symbols). */
1113 /* Return TRUE if anything in the expression is a bignum. */
1115 static bool
1116 walk_no_bignums (symbolS * sp)
1118 if (symbol_get_value_expression (sp)->X_op == O_big)
1119 return true;
1121 if (symbol_get_value_expression (sp)->X_add_symbol)
1123 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1124 || (symbol_get_value_expression (sp)->X_op_symbol
1125 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1128 return false;
1131 static bool in_my_get_expression = false;
1133 /* Third argument to my_get_expression. */
1134 #define GE_NO_PREFIX 0
1135 #define GE_IMM_PREFIX 1
1136 #define GE_OPT_PREFIX 2
1137 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1138 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1139 #define GE_OPT_PREFIX_BIG 3
1141 static int
1142 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1144 char * save_in;
1146 /* In unified syntax, all prefixes are optional. */
1147 if (unified_syntax)
1148 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1149 : GE_OPT_PREFIX;
1151 switch (prefix_mode)
1153 case GE_NO_PREFIX: break;
1154 case GE_IMM_PREFIX:
1155 if (!is_immediate_prefix (**str))
1157 inst.error = _("immediate expression requires a # prefix");
1158 return FAIL;
1160 (*str)++;
1161 break;
1162 case GE_OPT_PREFIX:
1163 case GE_OPT_PREFIX_BIG:
1164 if (is_immediate_prefix (**str))
1165 (*str)++;
1166 break;
1167 default:
1168 abort ();
1171 memset (ep, 0, sizeof (expressionS));
1173 save_in = input_line_pointer;
1174 input_line_pointer = *str;
1175 in_my_get_expression = true;
1176 expression (ep);
1177 in_my_get_expression = false;
1179 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1181 /* We found a bad or missing expression in md_operand(). */
1182 *str = input_line_pointer;
1183 input_line_pointer = save_in;
1184 if (inst.error == NULL)
1185 inst.error = (ep->X_op == O_absent
1186 ? _("missing expression") :_("bad expression"));
1187 return 1;
1190 /* Get rid of any bignums now, so that we don't generate an error for which
1191 we can't establish a line number later on. Big numbers are never valid
1192 in instructions, which is where this routine is always called. */
1193 if (prefix_mode != GE_OPT_PREFIX_BIG
1194 && (ep->X_op == O_big
1195 || (ep->X_add_symbol
1196 && (walk_no_bignums (ep->X_add_symbol)
1197 || (ep->X_op_symbol
1198 && walk_no_bignums (ep->X_op_symbol))))))
1200 inst.error = _("invalid constant");
1201 *str = input_line_pointer;
1202 input_line_pointer = save_in;
1203 return 1;
1206 *str = input_line_pointer;
1207 input_line_pointer = save_in;
1208 return SUCCESS;
1211 /* Turn a string in input_line_pointer into a floating point constant
1212 of type TYPE, and store the appropriate bytes in *LITP. The number
1213 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1214 returned, or NULL on OK.
1216 Note that fp constants aren't represent in the normal way on the ARM.
1217 In big endian mode, things are as expected. However, in little endian
1218 mode fp constants are big-endian word-wise, and little-endian byte-wise
1219 within the words. For example, (double) 1.1 in big endian mode is
1220 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1221 the byte sequence 99 99 f1 3f 9a 99 99 99.
1223 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1225 const char *
1226 md_atof (int type, char * litP, int * sizeP)
1228 int prec;
1229 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1230 char *t;
1231 int i;
1233 switch (type)
1235 case 'H':
1236 case 'h':
1237 /* bfloat16, despite not being part of the IEEE specification, can also
1238 be handled by atof_ieee(). */
1239 case 'b':
1240 prec = 1;
1241 break;
1243 case 'f':
1244 case 'F':
1245 case 's':
1246 case 'S':
1247 prec = 2;
1248 break;
1250 case 'd':
1251 case 'D':
1252 case 'r':
1253 case 'R':
1254 prec = 4;
1255 break;
1257 case 'x':
1258 case 'X':
1259 prec = 5;
1260 break;
1262 case 'p':
1263 case 'P':
1264 prec = 5;
1265 break;
1267 default:
1268 *sizeP = 0;
1269 return _("Unrecognized or unsupported floating point constant");
1272 t = atof_ieee (input_line_pointer, type, words);
1273 if (t)
1274 input_line_pointer = t;
1275 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1277 if (target_big_endian || prec == 1)
1278 for (i = 0; i < prec; i++)
1280 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1281 litP += sizeof (LITTLENUM_TYPE);
1283 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1284 for (i = prec - 1; i >= 0; i--)
1286 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1287 litP += sizeof (LITTLENUM_TYPE);
1289 else
1290 /* For a 4 byte float the order of elements in `words' is 1 0.
1291 For an 8 byte float the order is 1 0 3 2. */
1292 for (i = 0; i < prec; i += 2)
1294 md_number_to_chars (litP, (valueT) words[i + 1],
1295 sizeof (LITTLENUM_TYPE));
1296 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1297 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1298 litP += 2 * sizeof (LITTLENUM_TYPE);
1301 return NULL;
1304 /* We handle all bad expressions here, so that we can report the faulty
1305 instruction in the error message. */
1307 void
1308 md_operand (expressionS * exp)
1310 if (in_my_get_expression)
1311 exp->X_op = O_illegal;
1314 /* Immediate values. */
1316 #ifdef OBJ_ELF
1317 /* Generic immediate-value read function for use in directives.
1318 Accepts anything that 'expression' can fold to a constant.
1319 *val receives the number. */
1321 static int
1322 immediate_for_directive (int *val)
1324 expressionS exp;
1325 exp.X_op = O_illegal;
1327 if (is_immediate_prefix (*input_line_pointer))
1329 input_line_pointer++;
1330 expression (&exp);
1333 if (exp.X_op != O_constant)
1335 as_bad (_("expected #constant"));
1336 ignore_rest_of_line ();
1337 return FAIL;
1339 *val = exp.X_add_number;
1340 return SUCCESS;
1342 #endif
1344 /* Register parsing. */
1346 /* Generic register parser. CCP points to what should be the
1347 beginning of a register name. If it is indeed a valid register
1348 name, advance CCP over it and return the reg_entry structure;
1349 otherwise return NULL. Does not issue diagnostics. */
1351 static struct reg_entry *
1352 arm_reg_parse_multi (char **ccp)
1354 char *start = *ccp;
1355 char *p;
1356 struct reg_entry *reg;
1358 skip_whitespace (start);
1360 #ifdef REGISTER_PREFIX
1361 if (*start != REGISTER_PREFIX)
1362 return NULL;
1363 start++;
1364 #endif
1365 #ifdef OPTIONAL_REGISTER_PREFIX
1366 if (*start == OPTIONAL_REGISTER_PREFIX)
1367 start++;
1368 #endif
1370 p = start;
1371 if (!ISALPHA (*p) || !is_name_beginner (*p))
1372 return NULL;
1375 p++;
1376 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1378 reg = (struct reg_entry *) str_hash_find_n (arm_reg_hsh, start, p - start);
1380 if (!reg)
1381 return NULL;
1383 *ccp = p;
1384 return reg;
1387 static int
1388 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1389 enum arm_reg_type type)
1391 /* Alternative syntaxes are accepted for a few register classes. */
1392 switch (type)
1394 case REG_TYPE_MVF:
1395 case REG_TYPE_MVD:
1396 case REG_TYPE_MVFX:
1397 case REG_TYPE_MVDX:
1398 /* Generic coprocessor register names are allowed for these. */
1399 if (reg && reg->type == REG_TYPE_CN)
1400 return reg->number;
1401 break;
1403 case REG_TYPE_CP:
1404 /* For backward compatibility, a bare number is valid here. */
1406 unsigned long processor = strtoul (start, ccp, 10);
1407 if (*ccp != start && processor <= 15)
1408 return processor;
1410 /* Fall through. */
1412 case REG_TYPE_MMXWC:
1413 /* WC includes WCG. ??? I'm not sure this is true for all
1414 instructions that take WC registers. */
1415 if (reg && reg->type == REG_TYPE_MMXWCG)
1416 return reg->number;
1417 break;
1419 default:
1420 break;
1423 return FAIL;
1426 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1427 return value is the register number or FAIL. */
1429 static int
1430 arm_reg_parse (char **ccp, enum arm_reg_type type)
1432 char *start = *ccp;
1433 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1434 int ret;
1436 /* Do not allow a scalar (reg+index) to parse as a register. */
1437 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1438 return FAIL;
1440 if (reg && reg->type == type)
1441 return reg->number;
1443 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1444 return ret;
1446 *ccp = start;
1447 return FAIL;
1450 /* Parse a Neon type specifier. *STR should point at the leading '.'
1451 character. Does no verification at this stage that the type fits the opcode
1452 properly. E.g.,
1454 .i32.i32.s16
1455 .s32.f32
1456 .u16
1458 Can all be legally parsed by this function.
1460 Fills in neon_type struct pointer with parsed information, and updates STR
1461 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1462 type, FAIL if not. */
1464 static int
1465 parse_neon_type (struct neon_type *type, char **str)
1467 char *ptr = *str;
1469 if (type)
1470 type->elems = 0;
1472 while (type->elems < NEON_MAX_TYPE_ELS)
1474 enum neon_el_type thistype = NT_untyped;
1475 unsigned thissize = -1u;
1477 if (*ptr != '.')
1478 break;
1480 ptr++;
1482 /* Just a size without an explicit type. */
1483 if (ISDIGIT (*ptr))
1484 goto parsesize;
1486 switch (TOLOWER (*ptr))
1488 case 'i': thistype = NT_integer; break;
1489 case 'f': thistype = NT_float; break;
1490 case 'p': thistype = NT_poly; break;
1491 case 's': thistype = NT_signed; break;
1492 case 'u': thistype = NT_unsigned; break;
1493 case 'd':
1494 thistype = NT_float;
1495 thissize = 64;
1496 ptr++;
1497 goto done;
1498 case 'b':
1499 thistype = NT_bfloat;
1500 switch (TOLOWER (*(++ptr)))
1502 case 'f':
1503 ptr += 1;
1504 thissize = strtoul (ptr, &ptr, 10);
1505 if (thissize != 16)
1507 as_bad (_("bad size %d in type specifier"), thissize);
1508 return FAIL;
1510 goto done;
1511 case '0': case '1': case '2': case '3': case '4':
1512 case '5': case '6': case '7': case '8': case '9':
1513 case ' ': case '.':
1514 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1515 return FAIL;
1516 default:
1517 break;
1519 break;
1520 default:
1521 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1522 return FAIL;
1525 ptr++;
1527 /* .f is an abbreviation for .f32. */
1528 if (thistype == NT_float && !ISDIGIT (*ptr))
1529 thissize = 32;
1530 else
1532 parsesize:
1533 thissize = strtoul (ptr, &ptr, 10);
1535 if (thissize != 8 && thissize != 16 && thissize != 32
1536 && thissize != 64)
1538 as_bad (_("bad size %d in type specifier"), thissize);
1539 return FAIL;
1543 done:
1544 if (type)
1546 type->el[type->elems].type = thistype;
1547 type->el[type->elems].size = thissize;
1548 type->elems++;
1552 /* Empty/missing type is not a successful parse. */
1553 if (type->elems == 0)
1554 return FAIL;
1556 *str = ptr;
1558 return SUCCESS;
1561 /* Errors may be set multiple times during parsing or bit encoding
1562 (particularly in the Neon bits), but usually the earliest error which is set
1563 will be the most meaningful. Avoid overwriting it with later (cascading)
1564 errors by calling this function. */
1566 static void
1567 first_error (const char *err)
1569 if (!inst.error)
1570 inst.error = err;
1573 /* Parse a single type, e.g. ".s32", leading period included. */
1574 static int
1575 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1577 char *str = *ccp;
1578 struct neon_type optype;
1580 if (*str == '.')
1582 if (parse_neon_type (&optype, &str) == SUCCESS)
1584 if (optype.elems == 1)
1585 *vectype = optype.el[0];
1586 else
1588 first_error (_("only one type should be specified for operand"));
1589 return FAIL;
1592 else
1594 first_error (_("vector type expected"));
1595 return FAIL;
1598 else
1599 return FAIL;
1601 *ccp = str;
1603 return SUCCESS;
1606 /* Special meanings for indices (which have a range of 0-7), which will fit into
1607 a 4-bit integer. */
1609 #define NEON_ALL_LANES 15
1610 #define NEON_INTERLEAVE_LANES 14
1612 /* Record a use of the given feature. */
1613 static void
1614 record_feature_use (const arm_feature_set *feature)
1616 if (thumb_mode)
1617 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1618 else
1619 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1622 /* If the given feature available in the selected CPU, mark it as used.
1623 Returns TRUE iff feature is available. */
1624 static bool
1625 mark_feature_used (const arm_feature_set *feature)
1628 /* Do not support the use of MVE only instructions when in auto-detection or
1629 -march=all. */
1630 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1631 && ARM_CPU_IS_ANY (cpu_variant))
1633 first_error (BAD_MVE_AUTO);
1634 return false;
1636 /* Ensure the option is valid on the current architecture. */
1637 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1638 return false;
1640 /* Add the appropriate architecture feature for the barrier option used.
1642 record_feature_use (feature);
1644 return true;
1647 /* Parse either a register or a scalar, with an optional type. Return the
1648 register number, and optionally fill in the actual type of the register
1649 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1650 type/index information in *TYPEINFO. */
1652 static int
1653 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1654 enum arm_reg_type *rtype,
1655 struct neon_typed_alias *typeinfo)
1657 char *str = *ccp;
1658 struct reg_entry *reg = arm_reg_parse_multi (&str);
1659 struct neon_typed_alias atype;
1660 struct neon_type_el parsetype;
1662 atype.defined = 0;
1663 atype.index = -1;
1664 atype.eltype.type = NT_invtype;
1665 atype.eltype.size = -1;
1667 /* Try alternate syntax for some types of register. Note these are mutually
1668 exclusive with the Neon syntax extensions. */
1669 if (reg == NULL)
1671 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1672 if (altreg != FAIL)
1673 *ccp = str;
1674 if (typeinfo)
1675 *typeinfo = atype;
1676 return altreg;
1679 /* Undo polymorphism when a set of register types may be accepted. */
1680 if ((type == REG_TYPE_NDQ
1681 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1682 || (type == REG_TYPE_VFSD
1683 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1684 || (type == REG_TYPE_NSDQ
1685 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1686 || reg->type == REG_TYPE_NQ))
1687 || (type == REG_TYPE_NSD
1688 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1689 || (type == REG_TYPE_MMXWC
1690 && (reg->type == REG_TYPE_MMXWCG)))
1691 type = (enum arm_reg_type) reg->type;
1693 if (type == REG_TYPE_MQ)
1695 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1696 return FAIL;
1698 if (!reg || reg->type != REG_TYPE_NQ)
1699 return FAIL;
1701 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1703 first_error (_("expected MVE register [q0..q7]"));
1704 return FAIL;
1706 type = REG_TYPE_NQ;
1708 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1709 && (type == REG_TYPE_NQ))
1710 return FAIL;
1713 if (type != reg->type)
1714 return FAIL;
1716 if (reg->neon)
1717 atype = *reg->neon;
1719 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1721 if ((atype.defined & NTA_HASTYPE) != 0)
1723 first_error (_("can't redefine type for operand"));
1724 return FAIL;
1726 atype.defined |= NTA_HASTYPE;
1727 atype.eltype = parsetype;
1730 if (skip_past_char (&str, '[') == SUCCESS)
1732 if (type != REG_TYPE_VFD
1733 && !(type == REG_TYPE_VFS
1734 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1735 && !(type == REG_TYPE_NQ
1736 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
1738 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1739 first_error (_("only D and Q registers may be indexed"));
1740 else
1741 first_error (_("only D registers may be indexed"));
1742 return FAIL;
1745 if ((atype.defined & NTA_HASINDEX) != 0)
1747 first_error (_("can't change index for operand"));
1748 return FAIL;
1751 atype.defined |= NTA_HASINDEX;
1753 if (skip_past_char (&str, ']') == SUCCESS)
1754 atype.index = NEON_ALL_LANES;
1755 else
1757 expressionS exp;
1759 my_get_expression (&exp, &str, GE_NO_PREFIX);
1761 if (exp.X_op != O_constant)
1763 first_error (_("constant expression required"));
1764 return FAIL;
1767 if (skip_past_char (&str, ']') == FAIL)
1768 return FAIL;
1770 atype.index = exp.X_add_number;
1774 if (typeinfo)
1775 *typeinfo = atype;
1777 if (rtype)
1778 *rtype = type;
1780 *ccp = str;
1782 return reg->number;
1785 /* Like arm_reg_parse, but also allow the following extra features:
1786 - If RTYPE is non-zero, return the (possibly restricted) type of the
1787 register (e.g. Neon double or quad reg when either has been requested).
1788 - If this is a Neon vector type with additional type information, fill
1789 in the struct pointed to by VECTYPE (if non-NULL).
1790 This function will fault on encountering a scalar. */
1792 static int
1793 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1794 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1796 struct neon_typed_alias atype;
1797 char *str = *ccp;
1798 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1800 if (reg == FAIL)
1801 return FAIL;
1803 /* Do not allow regname(... to parse as a register. */
1804 if (*str == '(')
1805 return FAIL;
1807 /* Do not allow a scalar (reg+index) to parse as a register. */
1808 if ((atype.defined & NTA_HASINDEX) != 0)
1810 first_error (_("register operand expected, but got scalar"));
1811 return FAIL;
1814 if (vectype)
1815 *vectype = atype.eltype;
1817 *ccp = str;
1819 return reg;
1822 #define NEON_SCALAR_REG(X) ((X) >> 4)
1823 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1825 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1826 have enough information to be able to do a good job bounds-checking. So, we
1827 just do easy checks here, and do further checks later. */
1829 static int
1830 parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1831 arm_reg_type reg_type)
1833 int reg;
1834 char *str = *ccp;
1835 struct neon_typed_alias atype;
1836 unsigned reg_size;
1838 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1840 switch (reg_type)
1842 case REG_TYPE_VFS:
1843 reg_size = 32;
1844 break;
1845 case REG_TYPE_VFD:
1846 reg_size = 64;
1847 break;
1848 case REG_TYPE_MQ:
1849 reg_size = 128;
1850 break;
1851 default:
1852 gas_assert (0);
1853 return FAIL;
1856 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1857 return FAIL;
1859 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
1861 first_error (_("scalar must have an index"));
1862 return FAIL;
1864 else if (atype.index >= reg_size / elsize)
1866 first_error (_("scalar index out of range"));
1867 return FAIL;
1870 if (type)
1871 *type = atype.eltype;
1873 *ccp = str;
1875 return reg * 16 + atype.index;
1878 /* Types of registers in a list. */
1880 enum reg_list_els
1882 REGLIST_RN,
1883 REGLIST_PSEUDO,
1884 REGLIST_CLRM,
1885 REGLIST_VFP_S,
1886 REGLIST_VFP_S_VPR,
1887 REGLIST_VFP_D,
1888 REGLIST_VFP_D_VPR,
1889 REGLIST_NEON_D
1892 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1894 static long
1895 parse_reg_list (char ** strp, enum reg_list_els etype)
1897 char *str = *strp;
1898 long range = 0;
1899 int another_range;
1901 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM
1902 || etype == REGLIST_PSEUDO);
1904 /* We come back here if we get ranges concatenated by '+' or '|'. */
1907 skip_whitespace (str);
1909 another_range = 0;
1911 if (*str == '{')
1913 int in_range = 0;
1914 int cur_reg = -1;
1916 str++;
1919 int reg;
1920 const char apsr_str[] = "apsr";
1921 int apsr_str_len = strlen (apsr_str);
1922 enum arm_reg_type rt;
1924 if (etype == REGLIST_RN || etype == REGLIST_CLRM)
1925 rt = REG_TYPE_RN;
1926 else
1927 rt = REG_TYPE_PSEUDO;
1929 reg = arm_reg_parse (&str, rt);
1931 if (etype == REGLIST_CLRM)
1933 if (reg == REG_SP || reg == REG_PC)
1934 reg = FAIL;
1935 else if (reg == FAIL
1936 && !strncasecmp (str, apsr_str, apsr_str_len)
1937 && !ISALPHA (*(str + apsr_str_len)))
1939 reg = 15;
1940 str += apsr_str_len;
1943 if (reg == FAIL)
1945 first_error (_("r0-r12, lr or APSR expected"));
1946 return FAIL;
1949 else if (etype == REGLIST_PSEUDO)
1951 if (reg == FAIL)
1953 first_error (_(reg_expected_msgs[REG_TYPE_PSEUDO]));
1954 return FAIL;
1957 else /* etype == REGLIST_RN. */
1959 if (reg == FAIL)
1961 first_error (_(reg_expected_msgs[REGLIST_RN]));
1962 return FAIL;
1966 if (in_range)
1968 int i;
1970 if (reg <= cur_reg)
1972 first_error (_("bad range in register list"));
1973 return FAIL;
1976 for (i = cur_reg + 1; i < reg; i++)
1978 if (range & (1 << i))
1979 as_tsktsk
1980 (_("Warning: duplicated register (r%d) in register list"),
1982 else
1983 range |= 1 << i;
1985 in_range = 0;
1988 if (range & (1 << reg))
1989 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1990 reg);
1991 else if (reg <= cur_reg)
1992 as_tsktsk (_("Warning: register range not in ascending order"));
1994 range |= 1 << reg;
1995 cur_reg = reg;
1997 while (skip_past_comma (&str) != FAIL
1998 || (in_range = 1, *str++ == '-'));
1999 str--;
2001 if (skip_past_char (&str, '}') == FAIL)
2003 first_error (_("missing `}'"));
2004 return FAIL;
2007 else if (etype == REGLIST_RN)
2009 expressionS exp;
2011 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
2012 return FAIL;
2014 if (exp.X_op == O_constant)
2016 if (exp.X_add_number
2017 != (exp.X_add_number & 0x0000ffff))
2019 inst.error = _("invalid register mask");
2020 return FAIL;
2023 if ((range & exp.X_add_number) != 0)
2025 int regno = range & exp.X_add_number;
2027 regno &= -regno;
2028 regno = (1 << regno) - 1;
2029 as_tsktsk
2030 (_("Warning: duplicated register (r%d) in register list"),
2031 regno);
2034 range |= exp.X_add_number;
2036 else
2038 if (inst.relocs[0].type != 0)
2040 inst.error = _("expression too complex");
2041 return FAIL;
2044 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2045 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2046 inst.relocs[0].pc_rel = 0;
2050 if (*str == '|' || *str == '+')
2052 str++;
2053 another_range = 1;
2056 while (another_range);
2058 *strp = str;
2059 return range;
2062 /* Parse a VFP register list. If the string is invalid return FAIL.
2063 Otherwise return the number of registers, and set PBASE to the first
2064 register. Parses registers of type ETYPE.
2065 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2066 - Q registers can be used to specify pairs of D registers
2067 - { } can be omitted from around a singleton register list
2068 FIXME: This is not implemented, as it would require backtracking in
2069 some cases, e.g.:
2070 vtbl.8 d3,d4,d5
2071 This could be done (the meaning isn't really ambiguous), but doesn't
2072 fit in well with the current parsing framework.
2073 - 32 D registers may be used (also true for VFPv3).
2074 FIXME: Types are ignored in these register lists, which is probably a
2075 bug. */
2077 static int
2078 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2079 bool *partial_match)
2081 char *str = *ccp;
2082 int base_reg;
2083 int new_base;
2084 enum arm_reg_type regtype = (enum arm_reg_type) 0;
2085 int max_regs = 0;
2086 int count = 0;
2087 int warned = 0;
2088 unsigned long mask = 0;
2089 int i;
2090 bool vpr_seen = false;
2091 bool expect_vpr =
2092 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
2094 if (skip_past_char (&str, '{') == FAIL)
2096 inst.error = _("expecting {");
2097 return FAIL;
2100 switch (etype)
2102 case REGLIST_VFP_S:
2103 case REGLIST_VFP_S_VPR:
2104 regtype = REG_TYPE_VFS;
2105 max_regs = 32;
2106 break;
2108 case REGLIST_VFP_D:
2109 case REGLIST_VFP_D_VPR:
2110 regtype = REG_TYPE_VFD;
2111 break;
2113 case REGLIST_NEON_D:
2114 regtype = REG_TYPE_NDQ;
2115 break;
2117 default:
2118 gas_assert (0);
2121 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
2123 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2124 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
2126 max_regs = 32;
2127 if (thumb_mode)
2128 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2129 fpu_vfp_ext_d32);
2130 else
2131 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2132 fpu_vfp_ext_d32);
2134 else
2135 max_regs = 16;
2138 base_reg = max_regs;
2139 *partial_match = false;
2143 unsigned int setmask = 1, addregs = 1;
2144 const char vpr_str[] = "vpr";
2145 size_t vpr_str_len = strlen (vpr_str);
2147 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
2149 if (expect_vpr)
2151 if (new_base == FAIL
2152 && !strncasecmp (str, vpr_str, vpr_str_len)
2153 && !ISALPHA (*(str + vpr_str_len))
2154 && !vpr_seen)
2156 vpr_seen = true;
2157 str += vpr_str_len;
2158 if (count == 0)
2159 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2161 else if (vpr_seen)
2163 first_error (_("VPR expected last"));
2164 return FAIL;
2166 else if (new_base == FAIL)
2168 if (regtype == REG_TYPE_VFS)
2169 first_error (_("VFP single precision register or VPR "
2170 "expected"));
2171 else /* regtype == REG_TYPE_VFD. */
2172 first_error (_("VFP/Neon double precision register or VPR "
2173 "expected"));
2174 return FAIL;
2177 else if (new_base == FAIL)
2179 first_error (_(reg_expected_msgs[regtype]));
2180 return FAIL;
2183 *partial_match = true;
2184 if (vpr_seen)
2185 continue;
2187 if (new_base >= max_regs)
2189 first_error (_("register out of range in list"));
2190 return FAIL;
2193 /* Note: a value of 2 * n is returned for the register Q<n>. */
2194 if (regtype == REG_TYPE_NQ)
2196 setmask = 3;
2197 addregs = 2;
2200 if (new_base < base_reg)
2201 base_reg = new_base;
2203 if (mask & (setmask << new_base))
2205 first_error (_("invalid register list"));
2206 return FAIL;
2209 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
2211 as_tsktsk (_("register list not in ascending order"));
2212 warned = 1;
2215 mask |= setmask << new_base;
2216 count += addregs;
2218 if (*str == '-') /* We have the start of a range expression */
2220 int high_range;
2222 str++;
2224 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
2225 == FAIL)
2227 inst.error = gettext (reg_expected_msgs[regtype]);
2228 return FAIL;
2231 if (high_range >= max_regs)
2233 first_error (_("register out of range in list"));
2234 return FAIL;
2237 if (regtype == REG_TYPE_NQ)
2238 high_range = high_range + 1;
2240 if (high_range <= new_base)
2242 inst.error = _("register range not in ascending order");
2243 return FAIL;
2246 for (new_base += addregs; new_base <= high_range; new_base += addregs)
2248 if (mask & (setmask << new_base))
2250 inst.error = _("invalid register list");
2251 return FAIL;
2254 mask |= setmask << new_base;
2255 count += addregs;
2259 while (skip_past_comma (&str) != FAIL);
2261 str++;
2263 /* Sanity check -- should have raised a parse error above. */
2264 if ((!vpr_seen && count == 0) || count > max_regs)
2265 abort ();
2267 *pbase = base_reg;
2269 if (expect_vpr && !vpr_seen)
2271 first_error (_("VPR expected last"));
2272 return FAIL;
2275 /* Final test -- the registers must be consecutive. */
2276 mask >>= base_reg;
2277 for (i = 0; i < count; i++)
2279 if ((mask & (1u << i)) == 0)
2281 inst.error = _("non-contiguous register range");
2282 return FAIL;
2286 *ccp = str;
2288 return count;
2291 /* True if two alias types are the same. */
2293 static bool
2294 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2296 if (!a && !b)
2297 return true;
2299 if (!a || !b)
2300 return false;
2302 if (a->defined != b->defined)
2303 return false;
2305 if ((a->defined & NTA_HASTYPE) != 0
2306 && (a->eltype.type != b->eltype.type
2307 || a->eltype.size != b->eltype.size))
2308 return false;
2310 if ((a->defined & NTA_HASINDEX) != 0
2311 && (a->index != b->index))
2312 return false;
2314 return true;
2317 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2318 The base register is put in *PBASE.
2319 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2320 the return value.
2321 The register stride (minus one) is put in bit 4 of the return value.
2322 Bits [6:5] encode the list length (minus one).
2323 The type of the list elements is put in *ELTYPE, if non-NULL. */
2325 #define NEON_LANE(X) ((X) & 0xf)
2326 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2327 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2329 static int
2330 parse_neon_el_struct_list (char **str, unsigned *pbase,
2331 int mve,
2332 struct neon_type_el *eltype)
2334 char *ptr = *str;
2335 int base_reg = -1;
2336 int reg_incr = -1;
2337 int count = 0;
2338 int lane = -1;
2339 int leading_brace = 0;
2340 enum arm_reg_type rtype = REG_TYPE_NDQ;
2341 const char *const incr_error = mve ? _("register stride must be 1") :
2342 _("register stride must be 1 or 2");
2343 const char *const type_error = _("mismatched element/structure types in list");
2344 struct neon_typed_alias firsttype;
2345 firsttype.defined = 0;
2346 firsttype.eltype.type = NT_invtype;
2347 firsttype.eltype.size = -1;
2348 firsttype.index = -1;
2350 if (skip_past_char (&ptr, '{') == SUCCESS)
2351 leading_brace = 1;
2355 struct neon_typed_alias atype;
2356 if (mve)
2357 rtype = REG_TYPE_MQ;
2358 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2360 if (getreg == FAIL)
2362 first_error (_(reg_expected_msgs[rtype]));
2363 return FAIL;
2366 if (base_reg == -1)
2368 base_reg = getreg;
2369 if (rtype == REG_TYPE_NQ)
2371 reg_incr = 1;
2373 firsttype = atype;
2375 else if (reg_incr == -1)
2377 reg_incr = getreg - base_reg;
2378 if (reg_incr < 1 || reg_incr > 2)
2380 first_error (_(incr_error));
2381 return FAIL;
2384 else if (getreg != base_reg + reg_incr * count)
2386 first_error (_(incr_error));
2387 return FAIL;
2390 if (! neon_alias_types_same (&atype, &firsttype))
2392 first_error (_(type_error));
2393 return FAIL;
2396 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2397 modes. */
2398 if (ptr[0] == '-')
2400 struct neon_typed_alias htype;
2401 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2402 if (lane == -1)
2403 lane = NEON_INTERLEAVE_LANES;
2404 else if (lane != NEON_INTERLEAVE_LANES)
2406 first_error (_(type_error));
2407 return FAIL;
2409 if (reg_incr == -1)
2410 reg_incr = 1;
2411 else if (reg_incr != 1)
2413 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2414 return FAIL;
2416 ptr++;
2417 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2418 if (hireg == FAIL)
2420 first_error (_(reg_expected_msgs[rtype]));
2421 return FAIL;
2423 if (! neon_alias_types_same (&htype, &firsttype))
2425 first_error (_(type_error));
2426 return FAIL;
2428 count += hireg + dregs - getreg;
2429 continue;
2432 /* If we're using Q registers, we can't use [] or [n] syntax. */
2433 if (rtype == REG_TYPE_NQ)
2435 count += 2;
2436 continue;
2439 if ((atype.defined & NTA_HASINDEX) != 0)
2441 if (lane == -1)
2442 lane = atype.index;
2443 else if (lane != atype.index)
2445 first_error (_(type_error));
2446 return FAIL;
2449 else if (lane == -1)
2450 lane = NEON_INTERLEAVE_LANES;
2451 else if (lane != NEON_INTERLEAVE_LANES)
2453 first_error (_(type_error));
2454 return FAIL;
2456 count++;
2458 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2460 /* No lane set by [x]. We must be interleaving structures. */
2461 if (lane == -1)
2462 lane = NEON_INTERLEAVE_LANES;
2464 /* Sanity check. */
2465 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
2466 || (count > 1 && reg_incr == -1))
2468 first_error (_("error parsing element/structure list"));
2469 return FAIL;
2472 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2474 first_error (_("expected }"));
2475 return FAIL;
2478 if (reg_incr == -1)
2479 reg_incr = 1;
2481 if (eltype)
2482 *eltype = firsttype.eltype;
2484 *pbase = base_reg;
2485 *str = ptr;
2487 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2490 /* Parse an explicit relocation suffix on an expression. This is
2491 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2492 arm_reloc_hsh contains no entries, so this function can only
2493 succeed if there is no () after the word. Returns -1 on error,
2494 BFD_RELOC_UNUSED if there wasn't any suffix. */
2496 static int
2497 parse_reloc (char **str)
2499 struct reloc_entry *r;
2500 char *p, *q;
2502 if (**str != '(')
2503 return BFD_RELOC_UNUSED;
2505 p = *str + 1;
2506 q = p;
2508 while (*q && *q != ')' && *q != ',')
2509 q++;
2510 if (*q != ')')
2511 return -1;
2513 if ((r = (struct reloc_entry *)
2514 str_hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2515 return -1;
2517 *str = q + 1;
2518 return r->reloc;
2521 /* Directives: register aliases. */
2523 static struct reg_entry *
2524 insert_reg_alias (char *str, unsigned number, int type)
2526 struct reg_entry *new_reg;
2527 const char *name;
2529 if ((new_reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, str)) != 0)
2531 if (new_reg->builtin)
2532 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2534 /* Only warn about a redefinition if it's not defined as the
2535 same register. */
2536 else if (new_reg->number != number || new_reg->type != type)
2537 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2539 return NULL;
2542 name = xstrdup (str);
2543 new_reg = XNEW (struct reg_entry);
2545 new_reg->name = name;
2546 new_reg->number = number;
2547 new_reg->type = type;
2548 new_reg->builtin = false;
2549 new_reg->neon = NULL;
2551 str_hash_insert (arm_reg_hsh, name, new_reg, 0);
2553 return new_reg;
2556 static void
2557 insert_neon_reg_alias (char *str, int number, int type,
2558 struct neon_typed_alias *atype)
2560 struct reg_entry *reg = insert_reg_alias (str, number, type);
2562 if (!reg)
2564 first_error (_("attempt to redefine typed alias"));
2565 return;
2568 if (atype)
2570 reg->neon = XNEW (struct neon_typed_alias);
2571 *reg->neon = *atype;
2575 /* Look for the .req directive. This is of the form:
2577 new_register_name .req existing_register_name
2579 If we find one, or if it looks sufficiently like one that we want to
2580 handle any error here, return TRUE. Otherwise return FALSE. */
2582 static bool
2583 create_register_alias (char * newname, char *p)
2585 struct reg_entry *old;
2586 char *oldname, *nbuf;
2587 size_t nlen;
2589 /* The input scrubber ensures that whitespace after the mnemonic is
2590 collapsed to single spaces. */
2591 oldname = p;
2592 if (!startswith (oldname, " .req "))
2593 return false;
2595 oldname += 6;
2596 if (*oldname == '\0')
2597 return false;
2599 old = (struct reg_entry *) str_hash_find (arm_reg_hsh, oldname);
2600 if (!old)
2602 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2603 return true;
2606 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2607 the desired alias name, and p points to its end. If not, then
2608 the desired alias name is in the global original_case_string. */
2609 #ifdef TC_CASE_SENSITIVE
2610 nlen = p - newname;
2611 #else
2612 newname = original_case_string;
2613 nlen = strlen (newname);
2614 #endif
2616 nbuf = xmemdup0 (newname, nlen);
2618 /* Create aliases under the new name as stated; an all-lowercase
2619 version of the new name; and an all-uppercase version of the new
2620 name. */
2621 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2623 for (p = nbuf; *p; p++)
2624 *p = TOUPPER (*p);
2626 if (strncmp (nbuf, newname, nlen))
2628 /* If this attempt to create an additional alias fails, do not bother
2629 trying to create the all-lower case alias. We will fail and issue
2630 a second, duplicate error message. This situation arises when the
2631 programmer does something like:
2632 foo .req r0
2633 Foo .req r1
2634 The second .req creates the "Foo" alias but then fails to create
2635 the artificial FOO alias because it has already been created by the
2636 first .req. */
2637 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2639 free (nbuf);
2640 return true;
2644 for (p = nbuf; *p; p++)
2645 *p = TOLOWER (*p);
2647 if (strncmp (nbuf, newname, nlen))
2648 insert_reg_alias (nbuf, old->number, old->type);
2651 free (nbuf);
2652 return true;
2655 /* Create a Neon typed/indexed register alias using directives, e.g.:
2656 X .dn d5.s32[1]
2657 Y .qn 6.s16
2658 Z .dn d7
2659 T .dn Z[0]
2660 These typed registers can be used instead of the types specified after the
2661 Neon mnemonic, so long as all operands given have types. Types can also be
2662 specified directly, e.g.:
2663 vadd d0.s32, d1.s32, d2.s32 */
2665 static bool
2666 create_neon_reg_alias (char *newname, char *p)
2668 enum arm_reg_type basetype;
2669 struct reg_entry *basereg;
2670 struct reg_entry mybasereg;
2671 struct neon_type ntype;
2672 struct neon_typed_alias typeinfo;
2673 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2674 int namelen;
2676 typeinfo.defined = 0;
2677 typeinfo.eltype.type = NT_invtype;
2678 typeinfo.eltype.size = -1;
2679 typeinfo.index = -1;
2681 nameend = p;
2683 if (startswith (p, " .dn "))
2684 basetype = REG_TYPE_VFD;
2685 else if (startswith (p, " .qn "))
2686 basetype = REG_TYPE_NQ;
2687 else
2688 return false;
2690 p += 5;
2692 if (*p == '\0')
2693 return false;
2695 basereg = arm_reg_parse_multi (&p);
2697 if (basereg && basereg->type != basetype)
2699 as_bad (_("bad type for register"));
2700 return false;
2703 if (basereg == NULL)
2705 expressionS exp;
2706 /* Try parsing as an integer. */
2707 my_get_expression (&exp, &p, GE_NO_PREFIX);
2708 if (exp.X_op != O_constant)
2710 as_bad (_("expression must be constant"));
2711 return false;
2713 basereg = &mybasereg;
2714 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2715 : exp.X_add_number;
2716 basereg->neon = 0;
2719 if (basereg->neon)
2720 typeinfo = *basereg->neon;
2722 if (parse_neon_type (&ntype, &p) == SUCCESS)
2724 /* We got a type. */
2725 if (typeinfo.defined & NTA_HASTYPE)
2727 as_bad (_("can't redefine the type of a register alias"));
2728 return false;
2731 typeinfo.defined |= NTA_HASTYPE;
2732 if (ntype.elems != 1)
2734 as_bad (_("you must specify a single type only"));
2735 return false;
2737 typeinfo.eltype = ntype.el[0];
2740 if (skip_past_char (&p, '[') == SUCCESS)
2742 expressionS exp;
2743 /* We got a scalar index. */
2745 if (typeinfo.defined & NTA_HASINDEX)
2747 as_bad (_("can't redefine the index of a scalar alias"));
2748 return false;
2751 my_get_expression (&exp, &p, GE_NO_PREFIX);
2753 if (exp.X_op != O_constant)
2755 as_bad (_("scalar index must be constant"));
2756 return false;
2759 typeinfo.defined |= NTA_HASINDEX;
2760 typeinfo.index = exp.X_add_number;
2762 if (skip_past_char (&p, ']') == FAIL)
2764 as_bad (_("expecting ]"));
2765 return false;
2769 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2770 the desired alias name, and p points to its end. If not, then
2771 the desired alias name is in the global original_case_string. */
2772 #ifdef TC_CASE_SENSITIVE
2773 namelen = nameend - newname;
2774 #else
2775 newname = original_case_string;
2776 namelen = strlen (newname);
2777 #endif
2779 namebuf = xmemdup0 (newname, namelen);
2781 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2782 typeinfo.defined != 0 ? &typeinfo : NULL);
2784 /* Insert name in all uppercase. */
2785 for (p = namebuf; *p; p++)
2786 *p = TOUPPER (*p);
2788 if (strncmp (namebuf, newname, namelen))
2789 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2790 typeinfo.defined != 0 ? &typeinfo : NULL);
2792 /* Insert name in all lowercase. */
2793 for (p = namebuf; *p; p++)
2794 *p = TOLOWER (*p);
2796 if (strncmp (namebuf, newname, namelen))
2797 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2798 typeinfo.defined != 0 ? &typeinfo : NULL);
2800 free (namebuf);
2801 return true;
2804 /* Should never be called, as .req goes between the alias and the
2805 register name, not at the beginning of the line. */
2807 static void
2808 s_req (int a ATTRIBUTE_UNUSED)
2810 as_bad (_("invalid syntax for .req directive"));
2813 static void
2814 s_dn (int a ATTRIBUTE_UNUSED)
2816 as_bad (_("invalid syntax for .dn directive"));
2819 static void
2820 s_qn (int a ATTRIBUTE_UNUSED)
2822 as_bad (_("invalid syntax for .qn directive"));
2825 /* The .unreq directive deletes an alias which was previously defined
2826 by .req. For example:
2828 my_alias .req r11
2829 .unreq my_alias */
2831 static void
2832 s_unreq (int a ATTRIBUTE_UNUSED)
2834 char * name;
2835 char saved_char;
2837 name = input_line_pointer;
2838 input_line_pointer = find_end_of_line (input_line_pointer, flag_m68k_mri);
2839 saved_char = *input_line_pointer;
2840 *input_line_pointer = 0;
2842 if (!*name)
2843 as_bad (_("invalid syntax for .unreq directive"));
2844 else
2846 struct reg_entry *reg
2847 = (struct reg_entry *) str_hash_find (arm_reg_hsh, name);
2849 if (!reg)
2850 as_bad (_("unknown register alias '%s'"), name);
2851 else if (reg->builtin)
2852 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2853 name);
2854 else
2856 char * p;
2857 char * nbuf;
2859 str_hash_delete (arm_reg_hsh, name);
2860 free ((char *) reg->name);
2861 free (reg->neon);
2862 free (reg);
2864 /* Also locate the all upper case and all lower case versions.
2865 Do not complain if we cannot find one or the other as it
2866 was probably deleted above. */
2868 nbuf = strdup (name);
2869 for (p = nbuf; *p; p++)
2870 *p = TOUPPER (*p);
2871 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
2872 if (reg)
2874 str_hash_delete (arm_reg_hsh, nbuf);
2875 free ((char *) reg->name);
2876 free (reg->neon);
2877 free (reg);
2880 for (p = nbuf; *p; p++)
2881 *p = TOLOWER (*p);
2882 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
2883 if (reg)
2885 str_hash_delete (arm_reg_hsh, nbuf);
2886 free ((char *) reg->name);
2887 free (reg->neon);
2888 free (reg);
2891 free (nbuf);
2895 *input_line_pointer = saved_char;
2896 demand_empty_rest_of_line ();
2899 /* Directives: Instruction set selection. */
2901 #ifdef OBJ_ELF
2902 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2903 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2904 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2905 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2907 /* Create a new mapping symbol for the transition to STATE. */
2909 static void
2910 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2912 symbolS * symbolP;
2913 const char * symname;
2914 int type;
2916 switch (state)
2918 case MAP_DATA:
2919 symname = "$d";
2920 type = BSF_NO_FLAGS;
2921 break;
2922 case MAP_ARM:
2923 symname = "$a";
2924 type = BSF_NO_FLAGS;
2925 break;
2926 case MAP_THUMB:
2927 symname = "$t";
2928 type = BSF_NO_FLAGS;
2929 break;
2930 default:
2931 abort ();
2934 symbolP = symbol_new (symname, now_seg, frag, value);
2935 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2937 switch (state)
2939 case MAP_ARM:
2940 THUMB_SET_FUNC (symbolP, 0);
2941 ARM_SET_THUMB (symbolP, 0);
2942 ARM_SET_INTERWORK (symbolP, support_interwork);
2943 break;
2945 case MAP_THUMB:
2946 THUMB_SET_FUNC (symbolP, 1);
2947 ARM_SET_THUMB (symbolP, 1);
2948 ARM_SET_INTERWORK (symbolP, support_interwork);
2949 break;
2951 case MAP_DATA:
2952 default:
2953 break;
2956 /* Save the mapping symbols for future reference. Also check that
2957 we do not place two mapping symbols at the same offset within a
2958 frag. We'll handle overlap between frags in
2959 check_mapping_symbols.
2961 If .fill or other data filling directive generates zero sized data,
2962 the mapping symbol for the following code will have the same value
2963 as the one generated for the data filling directive. In this case,
2964 we replace the old symbol with the new one at the same address. */
2965 if (value == 0)
2967 if (frag->tc_frag_data.first_map != NULL)
2969 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2970 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2972 frag->tc_frag_data.first_map = symbolP;
2974 if (frag->tc_frag_data.last_map != NULL)
2976 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2977 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2978 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2980 frag->tc_frag_data.last_map = symbolP;
2983 /* We must sometimes convert a region marked as code to data during
2984 code alignment, if an odd number of bytes have to be padded. The
2985 code mapping symbol is pushed to an aligned address. */
2987 static void
2988 insert_data_mapping_symbol (enum mstate state,
2989 valueT value, fragS *frag, offsetT bytes)
2991 /* If there was already a mapping symbol, remove it. */
2992 if (frag->tc_frag_data.last_map != NULL
2993 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2995 symbolS *symp = frag->tc_frag_data.last_map;
2997 if (value == 0)
2999 know (frag->tc_frag_data.first_map == symp);
3000 frag->tc_frag_data.first_map = NULL;
3002 frag->tc_frag_data.last_map = NULL;
3003 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
3006 make_mapping_symbol (MAP_DATA, value, frag);
3007 make_mapping_symbol (state, value + bytes, frag);
3010 static void mapping_state_2 (enum mstate state, int max_chars);
3012 /* Set the mapping state to STATE. Only call this when about to
3013 emit some STATE bytes to the file. */
3015 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
3016 void
3017 mapping_state (enum mstate state)
3019 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3021 if (mapstate == state)
3022 /* The mapping symbol has already been emitted.
3023 There is nothing else to do. */
3024 return;
3026 if (state == MAP_ARM || state == MAP_THUMB)
3027 /* PR gas/12931
3028 All ARM instructions require 4-byte alignment.
3029 (Almost) all Thumb instructions require 2-byte alignment.
3031 When emitting instructions into any section, mark the section
3032 appropriately.
3034 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3035 but themselves require 2-byte alignment; this applies to some
3036 PC- relative forms. However, these cases will involve implicit
3037 literal pool generation or an explicit .align >=2, both of
3038 which will cause the section to me marked with sufficient
3039 alignment. Thus, we don't handle those cases here. */
3040 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3042 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
3043 /* This case will be evaluated later. */
3044 return;
3046 mapping_state_2 (state, 0);
3049 /* Same as mapping_state, but MAX_CHARS bytes have already been
3050 allocated. Put the mapping symbol that far back. */
3052 static void
3053 mapping_state_2 (enum mstate state, int max_chars)
3055 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3057 if (!SEG_NORMAL (now_seg))
3058 return;
3060 if (mapstate == state)
3061 /* The mapping symbol has already been emitted.
3062 There is nothing else to do. */
3063 return;
3065 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3066 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3068 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3069 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3071 if (add_symbol)
3072 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3075 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3076 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
3078 #undef TRANSITION
3079 #else
3080 #define mapping_state(x) ((void)0)
3081 #define mapping_state_2(x, y) ((void)0)
3082 #endif
3084 /* Find the real, Thumb encoded start of a Thumb function. */
3086 #ifdef OBJ_COFF
3087 static symbolS *
3088 find_real_start (symbolS * symbolP)
3090 char * real_start;
3091 const char * name = S_GET_NAME (symbolP);
3092 symbolS * new_target;
3094 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3095 #define STUB_NAME ".real_start_of"
3097 if (name == NULL)
3098 abort ();
3100 /* The compiler may generate BL instructions to local labels because
3101 it needs to perform a branch to a far away location. These labels
3102 do not have a corresponding ".real_start_of" label. We check
3103 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3104 the ".real_start_of" convention for nonlocal branches. */
3105 if (S_IS_LOCAL (symbolP) || name[0] == '.')
3106 return symbolP;
3108 real_start = concat (STUB_NAME, name, NULL);
3109 new_target = symbol_find (real_start);
3110 free (real_start);
3112 if (new_target == NULL)
3114 as_warn (_("Failed to find real start of function: %s\n"), name);
3115 new_target = symbolP;
3118 return new_target;
3120 #endif
3122 static void
3123 opcode_select (int width)
3125 switch (width)
3127 case 16:
3128 if (! thumb_mode)
3130 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
3131 as_bad (_("selected processor does not support THUMB opcodes"));
3133 thumb_mode = 1;
3134 /* No need to force the alignment, since we will have been
3135 coming from ARM mode, which is word-aligned. */
3136 record_alignment (now_seg, 1);
3138 break;
3140 case 32:
3141 if (thumb_mode)
3143 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
3144 as_bad (_("selected processor does not support ARM opcodes"));
3146 thumb_mode = 0;
3148 if (!need_pass_2)
3149 frag_align (2, 0, 0);
3151 record_alignment (now_seg, 1);
3153 break;
3155 default:
3156 as_bad (_("invalid instruction size selected (%d)"), width);
3160 static void
3161 s_arm (int ignore ATTRIBUTE_UNUSED)
3163 opcode_select (32);
3164 demand_empty_rest_of_line ();
3167 static void
3168 s_thumb (int ignore ATTRIBUTE_UNUSED)
3170 opcode_select (16);
3171 demand_empty_rest_of_line ();
3174 static void
3175 s_code (int unused ATTRIBUTE_UNUSED)
3177 int temp;
3179 temp = get_absolute_expression ();
3180 switch (temp)
3182 case 16:
3183 case 32:
3184 opcode_select (temp);
3185 break;
3187 default:
3188 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3190 demand_empty_rest_of_line ();
3193 static void
3194 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3196 /* If we are not already in thumb mode go into it, EVEN if
3197 the target processor does not support thumb instructions.
3198 This is used by gcc/config/arm/lib1funcs.asm for example
3199 to compile interworking support functions even if the
3200 target processor should not support interworking. */
3201 if (! thumb_mode)
3203 thumb_mode = 2;
3204 record_alignment (now_seg, 1);
3207 demand_empty_rest_of_line ();
3210 static void
3211 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3213 s_thumb (0); /* Will check for end-of-line. */
3215 /* The following label is the name/address of the start of a Thumb function.
3216 We need to know this for the interworking support. */
3217 label_is_thumb_function_name = true;
3220 /* Perform a .set directive, but also mark the alias as
3221 being a thumb function. */
3223 static void
3224 s_thumb_set (int equiv)
3226 /* XXX the following is a duplicate of the code for s_set() in read.c
3227 We cannot just call that code as we need to get at the symbol that
3228 is created. */
3229 char * name;
3230 char delim;
3231 char * end_name;
3232 symbolS * symbolP;
3234 /* Especial apologies for the random logic:
3235 This just grew, and could be parsed much more simply!
3236 Dean - in haste. */
3237 delim = get_symbol_name (& name);
3238 end_name = input_line_pointer;
3239 (void) restore_line_pointer (delim);
3241 if (*input_line_pointer != ',')
3243 *end_name = 0;
3244 as_bad (_("expected comma after name \"%s\""), name);
3245 *end_name = delim;
3246 ignore_rest_of_line ();
3247 return;
3250 input_line_pointer++;
3251 *end_name = 0;
3253 if (name[0] == '.' && name[1] == '\0')
3255 /* XXX - this should not happen to .thumb_set. */
3256 abort ();
3259 if ((symbolP = symbol_find (name)) == NULL
3260 && (symbolP = md_undefined_symbol (name)) == NULL)
3262 #ifndef NO_LISTING
3263 /* When doing symbol listings, play games with dummy fragments living
3264 outside the normal fragment chain to record the file and line info
3265 for this symbol. */
3266 if (listing & LISTING_SYMBOLS)
3268 extern struct list_info_struct * listing_tail;
3269 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
3271 memset (dummy_frag, 0, sizeof (fragS));
3272 dummy_frag->fr_type = rs_fill;
3273 dummy_frag->line = listing_tail;
3274 symbolP = symbol_new (name, undefined_section, dummy_frag, 0);
3275 dummy_frag->fr_symbol = symbolP;
3277 else
3278 #endif
3279 symbolP = symbol_new (name, undefined_section, &zero_address_frag, 0);
3281 #ifdef OBJ_COFF
3282 /* "set" symbols are local unless otherwise specified. */
3283 SF_SET_LOCAL (symbolP);
3284 #endif /* OBJ_COFF */
3285 } /* Make a new symbol. */
3287 symbol_table_insert (symbolP);
3289 * end_name = delim;
3291 if (equiv
3292 && S_IS_DEFINED (symbolP)
3293 && S_GET_SEGMENT (symbolP) != reg_section)
3294 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3296 pseudo_set (symbolP);
3298 demand_empty_rest_of_line ();
3300 /* XXX Now we come to the Thumb specific bit of code. */
3302 THUMB_SET_FUNC (symbolP, 1);
3303 ARM_SET_THUMB (symbolP, 1);
3304 #if defined OBJ_ELF || defined OBJ_COFF
3305 ARM_SET_INTERWORK (symbolP, support_interwork);
3306 #endif
3309 /* Directives: Mode selection. */
3311 /* .syntax [unified|divided] - choose the new unified syntax
3312 (same for Arm and Thumb encoding, modulo slight differences in what
3313 can be represented) or the old divergent syntax for each mode. */
3314 static void
3315 s_syntax (int unused ATTRIBUTE_UNUSED)
3317 char *name, delim;
3319 delim = get_symbol_name (& name);
3321 if (!strcasecmp (name, "unified"))
3322 unified_syntax = true;
3323 else if (!strcasecmp (name, "divided"))
3324 unified_syntax = false;
3325 else
3327 as_bad (_("unrecognized syntax mode \"%s\""), name);
3328 return;
3330 (void) restore_line_pointer (delim);
3331 demand_empty_rest_of_line ();
3334 /* Directives: alignment. */
3336 static void
3337 s_even (int ignore ATTRIBUTE_UNUSED)
3339 /* Never make frag if expect extra pass. */
3340 if (!need_pass_2)
3341 frag_align (1, 0, 0);
3343 record_alignment (now_seg, 1);
3345 demand_empty_rest_of_line ();
3348 /* Directives: CodeComposer Studio. */
3350 /* .ref (for CodeComposer Studio syntax only). */
3351 static void
3352 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3354 if (codecomposer_syntax)
3355 ignore_rest_of_line ();
3356 else
3357 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3360 /* If name is not NULL, then it is used for marking the beginning of a
3361 function, whereas if it is NULL then it means the function end. */
3362 static void
3363 asmfunc_debug (const char * name)
3365 static const char * last_name = NULL;
3367 if (name != NULL)
3369 gas_assert (last_name == NULL);
3370 last_name = name;
3372 if (debug_type == DEBUG_STABS)
3373 stabs_generate_asm_func (name, name);
3375 else
3377 gas_assert (last_name != NULL);
3379 if (debug_type == DEBUG_STABS)
3380 stabs_generate_asm_endfunc (last_name, last_name);
3382 last_name = NULL;
3386 static void
3387 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3389 if (codecomposer_syntax)
3391 switch (asmfunc_state)
3393 case OUTSIDE_ASMFUNC:
3394 asmfunc_state = WAITING_ASMFUNC_NAME;
3395 break;
3397 case WAITING_ASMFUNC_NAME:
3398 as_bad (_(".asmfunc repeated."));
3399 break;
3401 case WAITING_ENDASMFUNC:
3402 as_bad (_(".asmfunc without function."));
3403 break;
3405 demand_empty_rest_of_line ();
3407 else
3408 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3411 static void
3412 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3414 if (codecomposer_syntax)
3416 switch (asmfunc_state)
3418 case OUTSIDE_ASMFUNC:
3419 as_bad (_(".endasmfunc without a .asmfunc."));
3420 break;
3422 case WAITING_ASMFUNC_NAME:
3423 as_bad (_(".endasmfunc without function."));
3424 break;
3426 case WAITING_ENDASMFUNC:
3427 asmfunc_state = OUTSIDE_ASMFUNC;
3428 asmfunc_debug (NULL);
3429 break;
3431 demand_empty_rest_of_line ();
3433 else
3434 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3437 static void
3438 s_ccs_def (int name)
3440 if (codecomposer_syntax)
3441 s_globl (name);
3442 else
3443 as_bad (_(".def pseudo-op only available with -mccs flag."));
3446 /* Directives: Literal pools. */
3448 static literal_pool *
3449 find_literal_pool (void)
3451 literal_pool * pool;
3453 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3455 if (pool->section == now_seg
3456 && pool->sub_section == now_subseg)
3457 break;
3460 return pool;
3463 static literal_pool *
3464 find_or_make_literal_pool (void)
3466 /* Next literal pool ID number. */
3467 static unsigned int latest_pool_num = 1;
3468 literal_pool * pool;
3470 pool = find_literal_pool ();
3472 if (pool == NULL)
3474 /* Create a new pool. */
3475 pool = XNEW (literal_pool);
3476 if (! pool)
3477 return NULL;
3479 pool->next_free_entry = 0;
3480 pool->section = now_seg;
3481 pool->sub_section = now_subseg;
3482 pool->next = list_of_pools;
3483 pool->symbol = NULL;
3484 pool->alignment = 2;
3486 /* Add it to the list. */
3487 list_of_pools = pool;
3490 /* New pools, and emptied pools, will have a NULL symbol. */
3491 if (pool->symbol == NULL)
3493 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3494 &zero_address_frag, 0);
3495 pool->id = latest_pool_num ++;
3498 /* Done. */
3499 return pool;
3502 /* Add the literal in the global 'inst'
3503 structure to the relevant literal pool. */
3505 static int
3506 add_to_lit_pool (unsigned int nbytes)
3508 #define PADDING_SLOT 0x1
3509 #define LIT_ENTRY_SIZE_MASK 0xFF
3510 literal_pool * pool;
3511 unsigned int entry, pool_size = 0;
3512 bool padding_slot_p = false;
3513 unsigned imm1 = 0;
3514 unsigned imm2 = 0;
3516 if (nbytes == 8)
3518 imm1 = inst.operands[1].imm;
3519 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3520 : inst.relocs[0].exp.X_unsigned ? 0
3521 : (int64_t) inst.operands[1].imm >> 32);
3522 if (target_big_endian)
3524 imm1 = imm2;
3525 imm2 = inst.operands[1].imm;
3529 pool = find_or_make_literal_pool ();
3531 /* Check if this literal value is already in the pool. */
3532 for (entry = 0; entry < pool->next_free_entry; entry ++)
3534 if (nbytes == 4)
3536 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3537 && (inst.relocs[0].exp.X_op == O_constant)
3538 && (pool->literals[entry].X_add_number
3539 == inst.relocs[0].exp.X_add_number)
3540 && (pool->literals[entry].X_md == nbytes)
3541 && (pool->literals[entry].X_unsigned
3542 == inst.relocs[0].exp.X_unsigned))
3543 break;
3545 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3546 && (inst.relocs[0].exp.X_op == O_symbol)
3547 && (pool->literals[entry].X_add_number
3548 == inst.relocs[0].exp.X_add_number)
3549 && (pool->literals[entry].X_add_symbol
3550 == inst.relocs[0].exp.X_add_symbol)
3551 && (pool->literals[entry].X_op_symbol
3552 == inst.relocs[0].exp.X_op_symbol)
3553 && (pool->literals[entry].X_md == nbytes))
3554 break;
3556 else if ((nbytes == 8)
3557 && !(pool_size & 0x7)
3558 && ((entry + 1) != pool->next_free_entry)
3559 && (pool->literals[entry].X_op == O_constant)
3560 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3561 && (pool->literals[entry].X_unsigned
3562 == inst.relocs[0].exp.X_unsigned)
3563 && (pool->literals[entry + 1].X_op == O_constant)
3564 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3565 && (pool->literals[entry + 1].X_unsigned
3566 == inst.relocs[0].exp.X_unsigned))
3567 break;
3569 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3570 if (padding_slot_p && (nbytes == 4))
3571 break;
3573 pool_size += 4;
3576 /* Do we need to create a new entry? */
3577 if (entry == pool->next_free_entry)
3579 if (entry >= MAX_LITERAL_POOL_SIZE)
3581 inst.error = _("literal pool overflow");
3582 return FAIL;
3585 if (nbytes == 8)
3587 /* For 8-byte entries, we align to an 8-byte boundary,
3588 and split it into two 4-byte entries, because on 32-bit
3589 host, 8-byte constants are treated as big num, thus
3590 saved in "generic_bignum" which will be overwritten
3591 by later assignments.
3593 We also need to make sure there is enough space for
3594 the split.
3596 We also check to make sure the literal operand is a
3597 constant number. */
3598 if (!(inst.relocs[0].exp.X_op == O_constant
3599 || inst.relocs[0].exp.X_op == O_big))
3601 inst.error = _("invalid type for literal pool");
3602 return FAIL;
3604 else if (pool_size & 0x7)
3606 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3608 inst.error = _("literal pool overflow");
3609 return FAIL;
3612 pool->literals[entry] = inst.relocs[0].exp;
3613 pool->literals[entry].X_op = O_constant;
3614 pool->literals[entry].X_add_number = 0;
3615 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3616 pool->next_free_entry += 1;
3617 pool_size += 4;
3619 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3621 inst.error = _("literal pool overflow");
3622 return FAIL;
3625 pool->literals[entry] = inst.relocs[0].exp;
3626 pool->literals[entry].X_op = O_constant;
3627 pool->literals[entry].X_add_number = imm1;
3628 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3629 pool->literals[entry++].X_md = 4;
3630 pool->literals[entry] = inst.relocs[0].exp;
3631 pool->literals[entry].X_op = O_constant;
3632 pool->literals[entry].X_add_number = imm2;
3633 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3634 pool->literals[entry].X_md = 4;
3635 pool->alignment = 3;
3636 pool->next_free_entry += 1;
3638 else
3640 pool->literals[entry] = inst.relocs[0].exp;
3641 pool->literals[entry].X_md = 4;
3644 #ifdef OBJ_ELF
3645 /* PR ld/12974: Record the location of the first source line to reference
3646 this entry in the literal pool. If it turns out during linking that the
3647 symbol does not exist we will be able to give an accurate line number for
3648 the (first use of the) missing reference. */
3649 if (debug_type == DEBUG_DWARF2)
3650 dwarf2_where (pool->locs + entry);
3651 #endif
3652 pool->next_free_entry += 1;
3654 else if (padding_slot_p)
3656 pool->literals[entry] = inst.relocs[0].exp;
3657 pool->literals[entry].X_md = nbytes;
3660 inst.relocs[0].exp.X_op = O_symbol;
3661 inst.relocs[0].exp.X_add_number = pool_size;
3662 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3664 return SUCCESS;
3667 bool
3668 tc_start_label_without_colon (void)
3670 bool ret = true;
3672 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3674 const char *label = input_line_pointer;
3676 while (!is_end_of_line[(int) label[-1]])
3677 --label;
3679 if (*label == '.')
3681 as_bad (_("Invalid label '%s'"), label);
3682 ret = false;
3685 asmfunc_debug (label);
3687 asmfunc_state = WAITING_ENDASMFUNC;
3690 return ret;
3693 /* Can't use symbol_new here, so have to create a symbol and then at
3694 a later date assign it a value. That's what these functions do. */
3696 static void
3697 symbol_locate (symbolS * symbolP,
3698 const char * name, /* It is copied, the caller can modify. */
3699 segT segment, /* Segment identifier (SEG_<something>). */
3700 valueT valu, /* Symbol value. */
3701 fragS * frag) /* Associated fragment. */
3703 size_t name_length;
3704 char * preserved_copy_of_name;
3706 name_length = strlen (name) + 1; /* +1 for \0. */
3707 obstack_grow (&notes, name, name_length);
3708 preserved_copy_of_name = (char *) obstack_finish (&notes);
3710 #ifdef tc_canonicalize_symbol_name
3711 preserved_copy_of_name =
3712 tc_canonicalize_symbol_name (preserved_copy_of_name);
3713 #endif
3715 S_SET_NAME (symbolP, preserved_copy_of_name);
3717 S_SET_SEGMENT (symbolP, segment);
3718 S_SET_VALUE (symbolP, valu);
3719 symbol_clear_list_pointers (symbolP);
3721 symbol_set_frag (symbolP, frag);
3723 /* Link to end of symbol chain. */
3725 extern int symbol_table_frozen;
3727 if (symbol_table_frozen)
3728 abort ();
3731 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3733 obj_symbol_new_hook (symbolP);
3735 #ifdef tc_symbol_new_hook
3736 tc_symbol_new_hook (symbolP);
3737 #endif
3739 #ifdef DEBUG_SYMS
3740 verify_symbol_chain (symbol_rootP, symbol_lastP);
3741 #endif /* DEBUG_SYMS */
3744 static void
3745 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3747 unsigned int entry;
3748 literal_pool * pool;
3749 char sym_name[20];
3751 demand_empty_rest_of_line ();
3752 pool = find_literal_pool ();
3753 if (pool == NULL
3754 || pool->symbol == NULL
3755 || pool->next_free_entry == 0)
3756 return;
3758 /* Align pool as you have word accesses.
3759 Only make a frag if we have to. */
3760 if (!need_pass_2)
3761 frag_align (pool->alignment, 0, 0);
3763 record_alignment (now_seg, 2);
3765 #ifdef OBJ_ELF
3766 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3767 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3768 #endif
3769 sprintf (sym_name, "$$lit_\002%x", pool->id);
3771 symbol_locate (pool->symbol, sym_name, now_seg,
3772 (valueT) frag_now_fix (), frag_now);
3773 symbol_table_insert (pool->symbol);
3775 ARM_SET_THUMB (pool->symbol, thumb_mode);
3777 #if defined OBJ_COFF || defined OBJ_ELF
3778 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3779 #endif
3781 for (entry = 0; entry < pool->next_free_entry; entry ++)
3783 #ifdef OBJ_ELF
3784 if (debug_type == DEBUG_DWARF2)
3785 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3786 #endif
3787 /* First output the expression in the instruction to the pool. */
3788 emit_expr (&(pool->literals[entry]),
3789 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3792 /* Mark the pool as empty. */
3793 pool->next_free_entry = 0;
3794 pool->symbol = NULL;
3797 #ifdef OBJ_ELF
3798 /* Forward declarations for functions below, in the MD interface
3799 section. */
3800 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3801 static valueT create_unwind_entry (int);
3802 static void start_unwind_section (const segT, int);
3803 static void add_unwind_opcode (valueT, int);
3804 static void flush_pending_unwind (void);
3806 /* Directives: Data. */
3808 static void
3809 s_arm_elf_cons (int nbytes)
3811 expressionS exp;
3813 #ifdef md_flush_pending_output
3814 md_flush_pending_output ();
3815 #endif
3817 if (is_it_end_of_statement ())
3819 demand_empty_rest_of_line ();
3820 return;
3823 #ifdef md_cons_align
3824 md_cons_align (nbytes);
3825 #endif
3827 mapping_state (MAP_DATA);
3830 int reloc;
3831 char *base = input_line_pointer;
3833 expression (& exp);
3835 if (exp.X_op != O_symbol)
3836 emit_expr (&exp, (unsigned int) nbytes);
3837 else
3839 char *before_reloc = input_line_pointer;
3840 reloc = parse_reloc (&input_line_pointer);
3841 if (reloc == -1)
3843 as_bad (_("unrecognized relocation suffix"));
3844 ignore_rest_of_line ();
3845 return;
3847 else if (reloc == BFD_RELOC_UNUSED)
3848 emit_expr (&exp, (unsigned int) nbytes);
3849 else
3851 reloc_howto_type *howto = (reloc_howto_type *)
3852 bfd_reloc_type_lookup (stdoutput,
3853 (bfd_reloc_code_real_type) reloc);
3854 int size = bfd_get_reloc_size (howto);
3856 if (reloc == BFD_RELOC_ARM_PLT32)
3858 as_bad (_("(plt) is only valid on branch targets"));
3859 reloc = BFD_RELOC_UNUSED;
3860 size = 0;
3863 if (size > nbytes)
3864 as_bad (ngettext ("%s relocations do not fit in %d byte",
3865 "%s relocations do not fit in %d bytes",
3866 nbytes),
3867 howto->name, nbytes);
3868 else
3870 /* We've parsed an expression stopping at O_symbol.
3871 But there may be more expression left now that we
3872 have parsed the relocation marker. Parse it again.
3873 XXX Surely there is a cleaner way to do this. */
3874 char *p = input_line_pointer;
3875 int offset;
3876 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3878 memcpy (save_buf, base, input_line_pointer - base);
3879 memmove (base + (input_line_pointer - before_reloc),
3880 base, before_reloc - base);
3882 input_line_pointer = base + (input_line_pointer-before_reloc);
3883 expression (&exp);
3884 memcpy (base, save_buf, p - base);
3886 offset = nbytes - size;
3887 p = frag_more (nbytes);
3888 memset (p, 0, nbytes);
3889 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3890 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3891 free (save_buf);
3896 while (*input_line_pointer++ == ',');
3898 /* Put terminator back into stream. */
3899 input_line_pointer --;
3900 demand_empty_rest_of_line ();
3903 /* Emit an expression containing a 32-bit thumb instruction.
3904 Implementation based on put_thumb32_insn. */
3906 static void
3907 emit_thumb32_expr (expressionS * exp)
3909 expressionS exp_high = *exp;
3911 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3912 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3913 exp->X_add_number &= 0xffff;
3914 emit_expr (exp, (unsigned int) THUMB_SIZE);
3917 /* Guess the instruction size based on the opcode. */
3919 static int
3920 thumb_insn_size (int opcode)
3922 if ((unsigned int) opcode < 0xe800u)
3923 return 2;
3924 else if ((unsigned int) opcode >= 0xe8000000u)
3925 return 4;
3926 else
3927 return 0;
3930 static bool
3931 emit_insn (expressionS *exp, int nbytes)
3933 int size = 0;
3935 if (exp->X_op == O_constant)
3937 size = nbytes;
3939 if (size == 0)
3940 size = thumb_insn_size (exp->X_add_number);
3942 if (size != 0)
3944 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3946 as_bad (_(".inst.n operand too big. "\
3947 "Use .inst.w instead"));
3948 size = 0;
3950 else
3952 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3953 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
3954 else
3955 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3957 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3958 emit_thumb32_expr (exp);
3959 else
3960 emit_expr (exp, (unsigned int) size);
3962 it_fsm_post_encode ();
3965 else
3966 as_bad (_("cannot determine Thumb instruction size. " \
3967 "Use .inst.n/.inst.w instead"));
3969 else
3970 as_bad (_("constant expression required"));
3972 return (size != 0);
3975 /* Like s_arm_elf_cons but do not use md_cons_align and
3976 set the mapping state to MAP_ARM/MAP_THUMB. */
3978 static void
3979 s_arm_elf_inst (int nbytes)
3981 if (is_it_end_of_statement ())
3983 demand_empty_rest_of_line ();
3984 return;
3987 /* Calling mapping_state () here will not change ARM/THUMB,
3988 but will ensure not to be in DATA state. */
3990 if (thumb_mode)
3991 mapping_state (MAP_THUMB);
3992 else
3994 if (nbytes != 0)
3996 as_bad (_("width suffixes are invalid in ARM mode"));
3997 ignore_rest_of_line ();
3998 return;
4001 nbytes = 4;
4003 mapping_state (MAP_ARM);
4006 dwarf2_emit_insn (0);
4010 expressionS exp;
4012 expression (& exp);
4014 if (! emit_insn (& exp, nbytes))
4016 ignore_rest_of_line ();
4017 return;
4020 while (*input_line_pointer++ == ',');
4022 /* Put terminator back into stream. */
4023 input_line_pointer --;
4024 demand_empty_rest_of_line ();
4027 /* Parse a .rel31 directive. */
4029 static void
4030 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4032 expressionS exp;
4033 char *p;
4034 valueT highbit;
4036 highbit = 0;
4037 if (*input_line_pointer == '1')
4038 highbit = 0x80000000;
4039 else if (*input_line_pointer != '0')
4040 as_bad (_("expected 0 or 1"));
4042 input_line_pointer++;
4043 if (*input_line_pointer != ',')
4044 as_bad (_("missing comma"));
4045 input_line_pointer++;
4047 #ifdef md_flush_pending_output
4048 md_flush_pending_output ();
4049 #endif
4051 #ifdef md_cons_align
4052 md_cons_align (4);
4053 #endif
4055 mapping_state (MAP_DATA);
4057 expression (&exp);
4059 p = frag_more (4);
4060 md_number_to_chars (p, highbit, 4);
4061 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4062 BFD_RELOC_ARM_PREL31);
4064 demand_empty_rest_of_line ();
4067 /* Directives: AEABI stack-unwind tables. */
4069 /* Parse an unwind_fnstart directive. Simply records the current location. */
4071 static void
4072 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4074 demand_empty_rest_of_line ();
4075 if (unwind.proc_start)
4077 as_bad (_("duplicate .fnstart directive"));
4078 return;
4081 /* Mark the start of the function. */
4082 unwind.proc_start = expr_build_dot ();
4084 /* Reset the rest of the unwind info. */
4085 unwind.opcode_count = 0;
4086 unwind.table_entry = NULL;
4087 unwind.personality_routine = NULL;
4088 unwind.personality_index = -1;
4089 unwind.frame_size = 0;
4090 unwind.fp_offset = 0;
4091 unwind.fp_reg = REG_SP;
4092 unwind.fp_used = 0;
4093 unwind.sp_restored = 0;
4096 /* Parse a handlerdata directive. Creates the exception handling table entry
4097 for the function. */
4099 static void
4100 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4102 demand_empty_rest_of_line ();
4103 if (!unwind.proc_start)
4104 as_bad (MISSING_FNSTART);
4106 if (unwind.table_entry)
4107 as_bad (_("duplicate .handlerdata directive"));
4109 create_unwind_entry (1);
4112 /* Parse an unwind_fnend directive. Generates the index table entry. */
4114 static void
4115 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4117 long where;
4118 char *ptr;
4119 valueT val;
4120 unsigned int marked_pr_dependency;
4122 demand_empty_rest_of_line ();
4124 if (!unwind.proc_start)
4126 as_bad (_(".fnend directive without .fnstart"));
4127 return;
4130 /* Add eh table entry. */
4131 if (unwind.table_entry == NULL)
4132 val = create_unwind_entry (0);
4133 else
4134 val = 0;
4136 /* Add index table entry. This is two words. */
4137 start_unwind_section (unwind.saved_seg, 1);
4138 frag_align (2, 0, 0);
4139 record_alignment (now_seg, 2);
4141 ptr = frag_more (8);
4142 memset (ptr, 0, 8);
4143 where = frag_now_fix () - 8;
4145 /* Self relative offset of the function start. */
4146 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4147 BFD_RELOC_ARM_PREL31);
4149 /* Indicate dependency on EHABI-defined personality routines to the
4150 linker, if it hasn't been done already. */
4151 marked_pr_dependency
4152 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
4153 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4154 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4156 static const char *const name[] =
4158 "__aeabi_unwind_cpp_pr0",
4159 "__aeabi_unwind_cpp_pr1",
4160 "__aeabi_unwind_cpp_pr2"
4162 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4163 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
4164 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
4165 |= 1 << unwind.personality_index;
4168 if (val)
4169 /* Inline exception table entry. */
4170 md_number_to_chars (ptr + 4, val, 4);
4171 else
4172 /* Self relative offset of the table entry. */
4173 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4174 BFD_RELOC_ARM_PREL31);
4176 /* Restore the original section. */
4177 subseg_set (unwind.saved_seg, unwind.saved_subseg);
4179 unwind.proc_start = NULL;
4183 /* Parse an unwind_cantunwind directive. */
4185 static void
4186 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4188 demand_empty_rest_of_line ();
4189 if (!unwind.proc_start)
4190 as_bad (MISSING_FNSTART);
4192 if (unwind.personality_routine || unwind.personality_index != -1)
4193 as_bad (_("personality routine specified for cantunwind frame"));
4195 unwind.personality_index = -2;
4199 /* Parse a personalityindex directive. */
4201 static void
4202 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4204 expressionS exp;
4206 if (!unwind.proc_start)
4207 as_bad (MISSING_FNSTART);
4209 if (unwind.personality_routine || unwind.personality_index != -1)
4210 as_bad (_("duplicate .personalityindex directive"));
4212 expression (&exp);
4214 if (exp.X_op != O_constant
4215 || exp.X_add_number < 0 || exp.X_add_number > 15)
4217 as_bad (_("bad personality routine number"));
4218 ignore_rest_of_line ();
4219 return;
4222 unwind.personality_index = exp.X_add_number;
4224 demand_empty_rest_of_line ();
4228 /* Parse a personality directive. */
4230 static void
4231 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4233 char *name, *p, c;
4235 if (!unwind.proc_start)
4236 as_bad (MISSING_FNSTART);
4238 if (unwind.personality_routine || unwind.personality_index != -1)
4239 as_bad (_("duplicate .personality directive"));
4241 c = get_symbol_name (& name);
4242 p = input_line_pointer;
4243 if (c == '"')
4244 ++ input_line_pointer;
4245 unwind.personality_routine = symbol_find_or_make (name);
4246 *p = c;
4247 demand_empty_rest_of_line ();
4250 /* Parse a directive saving pseudo registers. */
4252 static void
4253 s_arm_unwind_save_pseudo (int regno)
4255 valueT op;
4257 switch (regno)
4259 case REG_RA_AUTH_CODE:
4260 /* Opcode for restoring RA_AUTH_CODE. */
4261 op = 0xb4;
4262 add_unwind_opcode (op, 1);
4263 break;
4264 default:
4265 as_bad (_("Unknown register no. encountered: %d\n"), regno);
4270 /* Parse a directive saving core registers. */
4272 static void
4273 s_arm_unwind_save_core (long range)
4275 valueT op;
4276 int n;
4278 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4279 into .unwind_save {..., sp...}. We aren't bothered about the value of
4280 ip because it is clobbered by calls. */
4281 if (unwind.sp_restored && unwind.fp_reg == 12
4282 && (range & 0x3000) == 0x1000)
4284 unwind.opcode_count--;
4285 unwind.sp_restored = 0;
4286 range = (range | 0x2000) & ~0x1000;
4287 unwind.pending_offset = 0;
4290 /* Pop r4-r15. */
4291 if (range & 0xfff0)
4293 /* See if we can use the short opcodes. These pop a block of up to 8
4294 registers starting with r4, plus maybe r14. */
4295 for (n = 0; n < 8; n++)
4297 /* Break at the first non-saved register. */
4298 if ((range & (1 << (n + 4))) == 0)
4299 break;
4301 /* See if there are any other bits set. */
4302 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4304 /* Use the long form. */
4305 op = 0x8000 | ((range >> 4) & 0xfff);
4306 add_unwind_opcode (op, 2);
4308 else
4310 /* Use the short form. */
4311 if (range & 0x4000)
4312 op = 0xa8; /* Pop r14. */
4313 else
4314 op = 0xa0; /* Do not pop r14. */
4315 op |= (n - 1);
4316 add_unwind_opcode (op, 1);
4320 /* Pop r0-r3. */
4321 if (range & 0xf)
4323 op = 0xb100 | (range & 0xf);
4324 add_unwind_opcode (op, 2);
4327 /* Record the number of bytes pushed. */
4328 for (n = 0; n < 16; n++)
4330 if (range & (1 << n))
4331 unwind.frame_size += 4;
4335 /* Implement correct handling of .save lists enabling the split into
4336 sublists where necessary, while preserving correct sublist ordering. */
4338 static void
4339 parse_dot_save (char **str_p, int prev_reg)
4341 long core_regs = 0;
4342 int reg;
4343 int in_range = 0;
4345 if (**str_p == ',')
4346 *str_p += 1;
4347 if (**str_p == '}')
4349 *str_p += 1;
4350 return;
4353 while ((reg = arm_reg_parse (str_p, REG_TYPE_RN)) != FAIL)
4355 if (!in_range)
4357 if (core_regs & (1 << reg))
4358 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
4359 reg);
4360 else if (reg <= prev_reg)
4361 as_tsktsk (_("Warning: register list not in ascending order"));
4363 core_regs |= (1 << reg);
4364 prev_reg = reg;
4365 if (skip_past_char(str_p, '-') != FAIL)
4366 in_range = 1;
4367 else if (skip_past_comma(str_p) == FAIL)
4368 first_error (_("bad register list"));
4370 else
4372 int i;
4373 if (reg <= prev_reg)
4374 first_error (_("bad range in register list"));
4375 for (i = prev_reg + 1; i <= reg; i++)
4377 if (core_regs & (1 << i))
4378 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
4380 else
4381 core_regs |= 1 << i;
4383 in_range = 0;
4386 if (core_regs)
4388 /* Higher register numbers go in higher memory addresses. When splitting a list,
4389 right-most sublist should therefore be .saved first. Use recursion for this. */
4390 parse_dot_save (str_p, reg);
4391 /* We're back from recursion, so emit .save insn for sublist. */
4392 s_arm_unwind_save_core (core_regs);
4393 return;
4395 /* Handle pseudo-regs, under assumption these are emitted singly. */
4396 else if ((reg = arm_reg_parse (str_p, REG_TYPE_PSEUDO)) != FAIL)
4398 /* recurse for remainder of input. Note: No assumption is made regarding which
4399 register in core register set holds pseudo-register. It's not considered in
4400 ordering check beyond ensuring it's not sandwiched between 2 consecutive
4401 registers. */
4402 parse_dot_save (str_p, prev_reg + 1);
4403 s_arm_unwind_save_pseudo (reg);
4404 return;
4406 else
4407 as_bad (BAD_SYNTAX);
4410 /* Parse a directive saving VFP registers for ARMv6 and above. */
4412 static void
4413 s_arm_unwind_save_vfp_armv6 (void)
4415 int count;
4416 unsigned int start;
4417 valueT op;
4418 int num_vfpv3_regs = 0;
4419 int num_regs_below_16;
4420 bool partial_match;
4422 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4423 &partial_match);
4424 if (count == FAIL)
4426 as_bad (_("expected register list"));
4427 ignore_rest_of_line ();
4428 return;
4431 demand_empty_rest_of_line ();
4433 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4434 than FSTMX/FLDMX-style ones). */
4436 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4437 if (start >= 16)
4438 num_vfpv3_regs = count;
4439 else if (start + count > 16)
4440 num_vfpv3_regs = start + count - 16;
4442 if (num_vfpv3_regs > 0)
4444 int start_offset = start > 16 ? start - 16 : 0;
4445 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4446 add_unwind_opcode (op, 2);
4449 /* Generate opcode for registers numbered in the range 0 .. 15. */
4450 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4451 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4452 if (num_regs_below_16 > 0)
4454 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4455 add_unwind_opcode (op, 2);
4458 unwind.frame_size += count * 8;
4462 /* Parse a directive saving VFP registers for pre-ARMv6. */
4464 static void
4465 s_arm_unwind_save_vfp (void)
4467 int count;
4468 unsigned int reg;
4469 valueT op;
4470 bool partial_match;
4472 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4473 &partial_match);
4474 if (count == FAIL)
4476 as_bad (_("expected register list"));
4477 ignore_rest_of_line ();
4478 return;
4481 demand_empty_rest_of_line ();
4483 if (reg == 8)
4485 /* Short form. */
4486 op = 0xb8 | (count - 1);
4487 add_unwind_opcode (op, 1);
4489 else
4491 /* Long form. */
4492 op = 0xb300 | (reg << 4) | (count - 1);
4493 add_unwind_opcode (op, 2);
4495 unwind.frame_size += count * 8 + 4;
4499 /* Parse a directive saving iWMMXt data registers. */
4501 static void
4502 s_arm_unwind_save_mmxwr (void)
4504 int reg;
4505 int hi_reg;
4506 int i;
4507 unsigned mask = 0;
4508 valueT op;
4510 if (*input_line_pointer == '{')
4511 input_line_pointer++;
4515 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4517 if (reg == FAIL)
4519 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4520 goto error;
4523 if (mask >> reg)
4524 as_tsktsk (_("register list not in ascending order"));
4525 mask |= 1 << reg;
4527 if (*input_line_pointer == '-')
4529 input_line_pointer++;
4530 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4531 if (hi_reg == FAIL)
4533 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4534 goto error;
4536 else if (reg >= hi_reg)
4538 as_bad (_("bad register range"));
4539 goto error;
4541 for (; reg < hi_reg; reg++)
4542 mask |= 1 << reg;
4545 while (skip_past_comma (&input_line_pointer) != FAIL);
4547 skip_past_char (&input_line_pointer, '}');
4549 demand_empty_rest_of_line ();
4551 /* Generate any deferred opcodes because we're going to be looking at
4552 the list. */
4553 flush_pending_unwind ();
4555 for (i = 0; i < 16; i++)
4557 if (mask & (1 << i))
4558 unwind.frame_size += 8;
4561 /* Attempt to combine with a previous opcode. We do this because gcc
4562 likes to output separate unwind directives for a single block of
4563 registers. */
4564 if (unwind.opcode_count > 0)
4566 i = unwind.opcodes[unwind.opcode_count - 1];
4567 if ((i & 0xf8) == 0xc0)
4569 i &= 7;
4570 /* Only merge if the blocks are contiguous. */
4571 if (i < 6)
4573 if ((mask & 0xfe00) == (1 << 9))
4575 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4576 unwind.opcode_count--;
4579 else if (i == 6 && unwind.opcode_count >= 2)
4581 i = unwind.opcodes[unwind.opcode_count - 2];
4582 reg = i >> 4;
4583 i &= 0xf;
4585 op = 0xffff << (reg - 1);
4586 if (reg > 0
4587 && ((mask & op) == (1u << (reg - 1))))
4589 op = (1 << (reg + i + 1)) - 1;
4590 op &= ~((1 << reg) - 1);
4591 mask |= op;
4592 unwind.opcode_count -= 2;
4598 hi_reg = 15;
4599 /* We want to generate opcodes in the order the registers have been
4600 saved, ie. descending order. */
4601 for (reg = 15; reg >= -1; reg--)
4603 /* Save registers in blocks. */
4604 if (reg < 0
4605 || !(mask & (1 << reg)))
4607 /* We found an unsaved reg. Generate opcodes to save the
4608 preceding block. */
4609 if (reg != hi_reg)
4611 if (reg == 9)
4613 /* Short form. */
4614 op = 0xc0 | (hi_reg - 10);
4615 add_unwind_opcode (op, 1);
4617 else
4619 /* Long form. */
4620 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4621 add_unwind_opcode (op, 2);
4624 hi_reg = reg - 1;
4628 return;
4629 error:
4630 ignore_rest_of_line ();
4633 static void
4634 s_arm_unwind_save_mmxwcg (void)
4636 int reg;
4637 int hi_reg;
4638 unsigned mask = 0;
4639 valueT op;
4641 if (*input_line_pointer == '{')
4642 input_line_pointer++;
4644 skip_whitespace (input_line_pointer);
4648 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4650 if (reg == FAIL)
4652 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4653 goto error;
4656 reg -= 8;
4657 if (mask >> reg)
4658 as_tsktsk (_("register list not in ascending order"));
4659 mask |= 1 << reg;
4661 if (*input_line_pointer == '-')
4663 input_line_pointer++;
4664 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4665 if (hi_reg == FAIL)
4667 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4668 goto error;
4670 else if (reg >= hi_reg)
4672 as_bad (_("bad register range"));
4673 goto error;
4675 for (; reg < hi_reg; reg++)
4676 mask |= 1 << reg;
4679 while (skip_past_comma (&input_line_pointer) != FAIL);
4681 skip_past_char (&input_line_pointer, '}');
4683 demand_empty_rest_of_line ();
4685 /* Generate any deferred opcodes because we're going to be looking at
4686 the list. */
4687 flush_pending_unwind ();
4689 for (reg = 0; reg < 16; reg++)
4691 if (mask & (1 << reg))
4692 unwind.frame_size += 4;
4694 op = 0xc700 | mask;
4695 add_unwind_opcode (op, 2);
4696 return;
4697 error:
4698 ignore_rest_of_line ();
4701 /* Parse an unwind_save directive.
4702 If the argument is non-zero, this is a .vsave directive. */
4704 static void
4705 s_arm_unwind_save (int arch_v6)
4707 char *peek;
4708 struct reg_entry *reg;
4709 bool had_brace = false;
4711 if (!unwind.proc_start)
4712 as_bad (MISSING_FNSTART);
4714 /* Figure out what sort of save we have. */
4715 peek = input_line_pointer;
4717 if (*peek == '{')
4719 had_brace = true;
4720 peek++;
4723 reg = arm_reg_parse_multi (&peek);
4725 if (!reg)
4727 as_bad (_("register expected"));
4728 ignore_rest_of_line ();
4729 return;
4732 switch (reg->type)
4734 case REG_TYPE_PSEUDO:
4735 case REG_TYPE_RN:
4737 if (had_brace)
4738 input_line_pointer++;
4739 parse_dot_save (&input_line_pointer, -1);
4740 demand_empty_rest_of_line ();
4741 return;
4744 case REG_TYPE_VFD:
4745 if (arch_v6)
4746 s_arm_unwind_save_vfp_armv6 ();
4747 else
4748 s_arm_unwind_save_vfp ();
4749 return;
4751 case REG_TYPE_MMXWR:
4752 s_arm_unwind_save_mmxwr ();
4753 return;
4755 case REG_TYPE_MMXWCG:
4756 s_arm_unwind_save_mmxwcg ();
4757 return;
4759 default:
4760 as_bad (_(".unwind_save does not support this kind of register"));
4761 ignore_rest_of_line ();
4766 /* Parse an unwind_movsp directive. */
4768 static void
4769 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4771 int reg;
4772 valueT op;
4773 int offset;
4775 if (!unwind.proc_start)
4776 as_bad (MISSING_FNSTART);
4778 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4779 if (reg == FAIL)
4781 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4782 ignore_rest_of_line ();
4783 return;
4786 /* Optional constant. */
4787 if (skip_past_comma (&input_line_pointer) != FAIL)
4789 if (immediate_for_directive (&offset) == FAIL)
4790 return;
4792 else
4793 offset = 0;
4795 demand_empty_rest_of_line ();
4797 if (reg == REG_SP || reg == REG_PC)
4799 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4800 return;
4803 if (unwind.fp_reg != REG_SP)
4804 as_bad (_("unexpected .unwind_movsp directive"));
4806 /* Generate opcode to restore the value. */
4807 op = 0x90 | reg;
4808 add_unwind_opcode (op, 1);
4810 /* Record the information for later. */
4811 unwind.fp_reg = reg;
4812 unwind.fp_offset = unwind.frame_size - offset;
4813 unwind.sp_restored = 1;
4816 /* Parse an unwind_pad directive. */
4818 static void
4819 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4821 int offset;
4823 if (!unwind.proc_start)
4824 as_bad (MISSING_FNSTART);
4826 if (immediate_for_directive (&offset) == FAIL)
4827 return;
4829 if (offset & 3)
4831 as_bad (_("stack increment must be multiple of 4"));
4832 ignore_rest_of_line ();
4833 return;
4836 /* Don't generate any opcodes, just record the details for later. */
4837 unwind.frame_size += offset;
4838 unwind.pending_offset += offset;
4840 demand_empty_rest_of_line ();
4843 /* Parse an unwind_pacspval directive. */
4845 static void
4846 s_arm_unwind_pacspval (int ignored ATTRIBUTE_UNUSED)
4848 valueT op;
4850 if (!unwind.proc_start)
4851 as_bad (MISSING_FNSTART);
4853 demand_empty_rest_of_line ();
4855 op = 0xb5;
4856 add_unwind_opcode (op, 1);
4859 /* Parse an unwind_setfp directive. */
4861 static void
4862 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4864 int sp_reg;
4865 int fp_reg;
4866 int offset;
4868 if (!unwind.proc_start)
4869 as_bad (MISSING_FNSTART);
4871 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4872 if (skip_past_comma (&input_line_pointer) == FAIL)
4873 sp_reg = FAIL;
4874 else
4875 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4877 if (fp_reg == FAIL || sp_reg == FAIL)
4879 as_bad (_("expected <reg>, <reg>"));
4880 ignore_rest_of_line ();
4881 return;
4884 /* Optional constant. */
4885 if (skip_past_comma (&input_line_pointer) != FAIL)
4887 if (immediate_for_directive (&offset) == FAIL)
4888 return;
4890 else
4891 offset = 0;
4893 demand_empty_rest_of_line ();
4895 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4897 as_bad (_("register must be either sp or set by a previous"
4898 "unwind_movsp directive"));
4899 return;
4902 /* Don't generate any opcodes, just record the information for later. */
4903 unwind.fp_reg = fp_reg;
4904 unwind.fp_used = 1;
4905 if (sp_reg == REG_SP)
4906 unwind.fp_offset = unwind.frame_size - offset;
4907 else
4908 unwind.fp_offset -= offset;
4911 /* Parse an unwind_raw directive. */
4913 static void
4914 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4916 expressionS exp;
4917 /* This is an arbitrary limit. */
4918 unsigned char op[16];
4919 int count;
4921 if (!unwind.proc_start)
4922 as_bad (MISSING_FNSTART);
4924 expression (&exp);
4925 if (exp.X_op == O_constant
4926 && skip_past_comma (&input_line_pointer) != FAIL)
4928 unwind.frame_size += exp.X_add_number;
4929 expression (&exp);
4931 else
4932 exp.X_op = O_illegal;
4934 if (exp.X_op != O_constant)
4936 as_bad (_("expected <offset>, <opcode>"));
4937 ignore_rest_of_line ();
4938 return;
4941 count = 0;
4943 /* Parse the opcode. */
4944 for (;;)
4946 if (count >= 16)
4948 as_bad (_("unwind opcode too long"));
4949 ignore_rest_of_line ();
4951 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4953 as_bad (_("invalid unwind opcode"));
4954 ignore_rest_of_line ();
4955 return;
4957 op[count++] = exp.X_add_number;
4959 /* Parse the next byte. */
4960 if (skip_past_comma (&input_line_pointer) == FAIL)
4961 break;
4963 expression (&exp);
4966 /* Add the opcode bytes in reverse order. */
4967 while (count--)
4968 add_unwind_opcode (op[count], 1);
4970 demand_empty_rest_of_line ();
4974 /* Parse a .eabi_attribute directive. */
4976 static void
4977 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4979 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4981 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4982 attributes_set_explicitly[tag] = 1;
4985 /* Emit a tls fix for the symbol. */
4987 static void
4988 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4990 char *p;
4991 expressionS exp;
4992 #ifdef md_flush_pending_output
4993 md_flush_pending_output ();
4994 #endif
4996 #ifdef md_cons_align
4997 md_cons_align (4);
4998 #endif
5000 /* Since we're just labelling the code, there's no need to define a
5001 mapping symbol. */
5002 expression (&exp);
5003 p = obstack_next_free (&frchain_now->frch_obstack);
5004 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5005 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5006 : BFD_RELOC_ARM_TLS_DESCSEQ);
5008 #endif /* OBJ_ELF */
5010 static void s_arm_arch (int);
5011 static void s_arm_object_arch (int);
5012 static void s_arm_cpu (int);
5013 static void s_arm_fpu (int);
5014 static void s_arm_arch_extension (int);
5016 #ifdef TE_PE
5018 static void
5019 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
5021 expressionS exp;
5025 expression (&exp);
5026 if (exp.X_op == O_symbol)
5027 exp.X_op = O_secrel;
5029 emit_expr (&exp, 4);
5031 while (*input_line_pointer++ == ',');
5033 input_line_pointer--;
5034 demand_empty_rest_of_line ();
5036 #endif /* TE_PE */
5039 arm_is_largest_exponent_ok (int precision)
5041 /* precision == 1 ensures that this will only return
5042 true for 16 bit floats. */
5043 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5046 static void
5047 set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5049 char saved_char;
5050 char* name;
5051 enum fp_16bit_format new_format;
5053 new_format = ARM_FP16_FORMAT_DEFAULT;
5055 name = input_line_pointer;
5056 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5057 input_line_pointer++;
5059 saved_char = *input_line_pointer;
5060 *input_line_pointer = 0;
5062 if (strcasecmp (name, "ieee") == 0)
5063 new_format = ARM_FP16_FORMAT_IEEE;
5064 else if (strcasecmp (name, "alternative") == 0)
5065 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5066 else
5068 as_bad (_("unrecognised float16 format \"%s\""), name);
5069 goto cleanup;
5072 /* Only set fp16_format if it is still the default (aka not already
5073 been set yet). */
5074 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5075 fp16_format = new_format;
5076 else
5078 if (new_format != fp16_format)
5079 as_warn (_("float16 format cannot be set more than once, ignoring."));
5082 cleanup:
5083 *input_line_pointer = saved_char;
5084 ignore_rest_of_line ();
5087 static void s_arm_float_cons (int float_type)
5089 /* We still parse the directive on error, so that any syntactic issues
5090 are picked up. */
5091 if (ARM_FEATURE_ZERO (selected_fpu))
5092 as_bad (_("the floating-point format has not been set (or has been disabled)"));
5093 float_cons (float_type);
5095 /* This table describes all the machine specific pseudo-ops the assembler
5096 has to support. The fields are:
5097 pseudo-op name without dot
5098 function to call to execute this pseudo-op
5099 Integer arg to pass to the function. */
5101 const pseudo_typeS md_pseudo_table[] =
5103 /* Never called because '.req' does not start a line. */
5104 { "req", s_req, 0 },
5105 /* Following two are likewise never called. */
5106 { "dn", s_dn, 0 },
5107 { "qn", s_qn, 0 },
5108 { "unreq", s_unreq, 0 },
5109 { "align", s_align_ptwo, 2 },
5110 { "arm", s_arm, 0 },
5111 { "thumb", s_thumb, 0 },
5112 { "code", s_code, 0 },
5113 { "force_thumb", s_force_thumb, 0 },
5114 { "thumb_func", s_thumb_func, 0 },
5115 { "thumb_set", s_thumb_set, 0 },
5116 { "even", s_even, 0 },
5117 { "ltorg", s_ltorg, 0 },
5118 { "pool", s_ltorg, 0 },
5119 { "syntax", s_syntax, 0 },
5120 { "cpu", s_arm_cpu, 0 },
5121 { "arch", s_arm_arch, 0 },
5122 { "object_arch", s_arm_object_arch, 0 },
5123 { "fpu", s_arm_fpu, 0 },
5124 { "arch_extension", s_arm_arch_extension, 0 },
5125 #ifdef OBJ_ELF
5126 { "word", s_arm_elf_cons, 4 },
5127 { "long", s_arm_elf_cons, 4 },
5128 { "inst.n", s_arm_elf_inst, 2 },
5129 { "inst.w", s_arm_elf_inst, 4 },
5130 { "inst", s_arm_elf_inst, 0 },
5131 { "rel31", s_arm_rel31, 0 },
5132 { "fnstart", s_arm_unwind_fnstart, 0 },
5133 { "fnend", s_arm_unwind_fnend, 0 },
5134 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5135 { "personality", s_arm_unwind_personality, 0 },
5136 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5137 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5138 { "save", s_arm_unwind_save, 0 },
5139 { "vsave", s_arm_unwind_save, 1 },
5140 { "movsp", s_arm_unwind_movsp, 0 },
5141 { "pad", s_arm_unwind_pad, 0 },
5142 { "pacspval", s_arm_unwind_pacspval, 0 },
5143 { "setfp", s_arm_unwind_setfp, 0 },
5144 { "unwind_raw", s_arm_unwind_raw, 0 },
5145 { "eabi_attribute", s_arm_eabi_attribute, 0 },
5146 { "tlsdescseq", s_arm_tls_descseq, 0 },
5147 #else
5148 { "word", cons, 4},
5150 /* These are used for dwarf. */
5151 {"2byte", cons, 2},
5152 {"4byte", cons, 4},
5153 {"8byte", cons, 8},
5154 /* These are used for dwarf2. */
5155 { "file", dwarf2_directive_file, 0 },
5156 { "loc", dwarf2_directive_loc, 0 },
5157 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
5158 #endif
5159 /* Override the default float_cons handling so that we can validate
5160 the FPU setting. */
5161 { "float", s_arm_float_cons, 'f' },
5162 { "single", s_arm_float_cons, 'f' },
5163 { "double", s_arm_float_cons, 'd' },
5164 { "dc.s", s_arm_float_cons, 'f' },
5165 { "dc.d", s_arm_float_cons, 'd' },
5166 { "extend", s_arm_float_cons, 'x' },
5167 { "ldouble", s_arm_float_cons, 'x' },
5168 { "packed", s_arm_float_cons, 'p' },
5169 { "bfloat16", s_arm_float_cons, 'b' },
5170 #ifdef TE_PE
5171 {"secrel32", pe_directive_secrel, 0},
5172 #endif
5174 /* These are for compatibility with CodeComposer Studio. */
5175 {"ref", s_ccs_ref, 0},
5176 {"def", s_ccs_def, 0},
5177 {"asmfunc", s_ccs_asmfunc, 0},
5178 {"endasmfunc", s_ccs_endasmfunc, 0},
5180 {"float16", s_arm_float_cons, 'h' },
5181 {"float16_format", set_fp16_format, 0 },
5183 { 0, 0, 0 }
5186 /* Parser functions used exclusively in instruction operands. */
5188 /* Generic immediate-value read function for use in insn parsing.
5189 STR points to the beginning of the immediate (the leading #);
5190 VAL receives the value; if the value is outside [MIN, MAX]
5191 issue an error. PREFIX_OPT is true if the immediate prefix is
5192 optional. */
5194 static int
5195 parse_immediate (char **str, int *val, int min, int max,
5196 bool prefix_opt)
5198 expressionS exp;
5200 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5201 if (exp.X_op != O_constant)
5203 inst.error = _("constant expression required");
5204 return FAIL;
5207 if (exp.X_add_number < min || exp.X_add_number > max)
5209 inst.error = _("immediate value out of range");
5210 return FAIL;
5213 *val = exp.X_add_number;
5214 return SUCCESS;
5217 /* Less-generic immediate-value read function with the possibility of loading a
5218 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5219 instructions. Puts the result directly in inst.operands[i]. */
5221 static int
5222 parse_big_immediate (char **str, int i, expressionS *in_exp,
5223 bool allow_symbol_p)
5225 expressionS exp;
5226 expressionS *exp_p = in_exp ? in_exp : &exp;
5227 char *ptr = *str;
5229 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5231 if (exp_p->X_op == O_constant)
5233 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
5234 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5235 O_constant. We have to be careful not to break compilation for
5236 32-bit X_add_number, though. */
5237 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
5239 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5240 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5241 & 0xffffffff);
5242 inst.operands[i].regisimm = 1;
5245 else if (exp_p->X_op == O_big
5246 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5248 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
5250 /* Bignums have their least significant bits in
5251 generic_bignum[0]. Make sure we put 32 bits in imm and
5252 32 bits in reg, in a (hopefully) portable way. */
5253 gas_assert (parts != 0);
5255 /* Make sure that the number is not too big.
5256 PR 11972: Bignums can now be sign-extended to the
5257 size of a .octa so check that the out of range bits
5258 are all zero or all one. */
5259 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
5261 LITTLENUM_TYPE m = -1;
5263 if (generic_bignum[parts * 2] != 0
5264 && generic_bignum[parts * 2] != m)
5265 return FAIL;
5267 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
5268 if (generic_bignum[j] != generic_bignum[j-1])
5269 return FAIL;
5272 inst.operands[i].imm = 0;
5273 for (j = 0; j < parts; j++, idx++)
5274 inst.operands[i].imm |= ((unsigned) generic_bignum[idx]
5275 << (LITTLENUM_NUMBER_OF_BITS * j));
5276 inst.operands[i].reg = 0;
5277 for (j = 0; j < parts; j++, idx++)
5278 inst.operands[i].reg |= ((unsigned) generic_bignum[idx]
5279 << (LITTLENUM_NUMBER_OF_BITS * j));
5280 inst.operands[i].regisimm = 1;
5282 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5283 return FAIL;
5285 *str = ptr;
5287 return SUCCESS;
5290 /* Returns 1 if a number has "quarter-precision" float format
5291 0baBbbbbbc defgh000 00000000 00000000. */
5293 static int
5294 is_quarter_float (unsigned imm)
5296 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5297 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5301 /* Detect the presence of a floating point or integer zero constant,
5302 i.e. #0.0 or #0. */
5304 static bool
5305 parse_ifimm_zero (char **in)
5307 int error_code;
5309 if (!is_immediate_prefix (**in))
5311 /* In unified syntax, all prefixes are optional. */
5312 if (!unified_syntax)
5313 return false;
5315 else
5316 ++*in;
5318 /* Accept #0x0 as a synonym for #0. */
5319 if (startswith (*in, "0x"))
5321 int val;
5322 if (parse_immediate (in, &val, 0, 0, true) == FAIL)
5323 return false;
5324 return true;
5327 error_code = atof_generic (in, ".", EXP_CHARS,
5328 &generic_floating_point_number);
5330 if (!error_code
5331 && generic_floating_point_number.sign == '+'
5332 && (generic_floating_point_number.low
5333 > generic_floating_point_number.leader))
5334 return true;
5336 return false;
5339 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5340 0baBbbbbbc defgh000 00000000 00000000.
5341 The zero and minus-zero cases need special handling, since they can't be
5342 encoded in the "quarter-precision" float format, but can nonetheless be
5343 loaded as integer constants. */
5345 static unsigned
5346 parse_qfloat_immediate (char **ccp, int *immed)
5348 char *str = *ccp;
5349 char *fpnum;
5350 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5351 int found_fpchar = 0;
5353 skip_past_char (&str, '#');
5355 /* We must not accidentally parse an integer as a floating-point number. Make
5356 sure that the value we parse is not an integer by checking for special
5357 characters '.' or 'e'.
5358 FIXME: This is a horrible hack, but doing better is tricky because type
5359 information isn't in a very usable state at parse time. */
5360 fpnum = str;
5361 skip_whitespace (fpnum);
5363 if (startswith (fpnum, "0x"))
5364 return FAIL;
5365 else
5367 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5368 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5370 found_fpchar = 1;
5371 break;
5374 if (!found_fpchar)
5375 return FAIL;
5378 if ((str = atof_ieee (str, 's', words)) != NULL)
5380 unsigned fpword = 0;
5381 int i;
5383 /* Our FP word must be 32 bits (single-precision FP). */
5384 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5386 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5387 fpword |= words[i];
5390 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5391 *immed = fpword;
5392 else
5393 return FAIL;
5395 *ccp = str;
5397 return SUCCESS;
5400 return FAIL;
5403 /* Shift operands. */
5404 enum shift_kind
5406 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
5409 struct asm_shift_name
5411 const char *name;
5412 enum shift_kind kind;
5415 /* Third argument to parse_shift. */
5416 enum parse_shift_mode
5418 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5419 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5420 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5421 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5422 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5423 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
5426 /* Parse a <shift> specifier on an ARM data processing instruction.
5427 This has three forms:
5429 (LSL|LSR|ASL|ASR|ROR) Rs
5430 (LSL|LSR|ASL|ASR|ROR) #imm
5433 Note that ASL is assimilated to LSL in the instruction encoding, and
5434 RRX to ROR #0 (which cannot be written as such). */
5436 static int
5437 parse_shift (char **str, int i, enum parse_shift_mode mode)
5439 const struct asm_shift_name *shift_name;
5440 enum shift_kind shift;
5441 char *s = *str;
5442 char *p = s;
5443 int reg;
5445 for (p = *str; ISALPHA (*p); p++)
5448 if (p == *str)
5450 inst.error = _("shift expression expected");
5451 return FAIL;
5454 shift_name
5455 = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str,
5456 p - *str);
5458 if (shift_name == NULL)
5460 inst.error = _("shift expression expected");
5461 return FAIL;
5464 shift = shift_name->kind;
5466 switch (mode)
5468 case NO_SHIFT_RESTRICT:
5469 case SHIFT_IMMEDIATE:
5470 if (shift == SHIFT_UXTW)
5472 inst.error = _("'UXTW' not allowed here");
5473 return FAIL;
5475 break;
5477 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5478 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5480 inst.error = _("'LSL' or 'ASR' required");
5481 return FAIL;
5483 break;
5485 case SHIFT_LSL_IMMEDIATE:
5486 if (shift != SHIFT_LSL)
5488 inst.error = _("'LSL' required");
5489 return FAIL;
5491 break;
5493 case SHIFT_ASR_IMMEDIATE:
5494 if (shift != SHIFT_ASR)
5496 inst.error = _("'ASR' required");
5497 return FAIL;
5499 break;
5500 case SHIFT_UXTW_IMMEDIATE:
5501 if (shift != SHIFT_UXTW)
5503 inst.error = _("'UXTW' required");
5504 return FAIL;
5506 break;
5508 default: abort ();
5511 if (shift != SHIFT_RRX)
5513 /* Whitespace can appear here if the next thing is a bare digit. */
5514 skip_whitespace (p);
5516 if (mode == NO_SHIFT_RESTRICT
5517 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5519 inst.operands[i].imm = reg;
5520 inst.operands[i].immisreg = 1;
5522 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5523 return FAIL;
5525 inst.operands[i].shift_kind = shift;
5526 inst.operands[i].shifted = 1;
5527 *str = p;
5528 return SUCCESS;
5531 /* Parse a <shifter_operand> for an ARM data processing instruction:
5533 #<immediate>
5534 #<immediate>, <rotate>
5535 <Rm>
5536 <Rm>, <shift>
5538 where <shift> is defined by parse_shift above, and <rotate> is a
5539 multiple of 2 between 0 and 30. Validation of immediate operands
5540 is deferred to md_apply_fix. */
5542 static int
5543 parse_shifter_operand (char **str, int i)
5545 int value;
5546 expressionS exp;
5548 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5550 inst.operands[i].reg = value;
5551 inst.operands[i].isreg = 1;
5553 /* parse_shift will override this if appropriate */
5554 inst.relocs[0].exp.X_op = O_constant;
5555 inst.relocs[0].exp.X_add_number = 0;
5557 if (skip_past_comma (str) == FAIL)
5558 return SUCCESS;
5560 /* Shift operation on register. */
5561 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5564 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5565 return FAIL;
5567 if (skip_past_comma (str) == SUCCESS)
5569 /* #x, y -- ie explicit rotation by Y. */
5570 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5571 return FAIL;
5573 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5575 inst.error = _("constant expression expected");
5576 return FAIL;
5579 value = exp.X_add_number;
5580 if (value < 0 || value > 30 || value % 2 != 0)
5582 inst.error = _("invalid rotation");
5583 return FAIL;
5585 if (inst.relocs[0].exp.X_add_number < 0
5586 || inst.relocs[0].exp.X_add_number > 255)
5588 inst.error = _("invalid constant");
5589 return FAIL;
5592 /* Encode as specified. */
5593 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5594 return SUCCESS;
5597 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5598 inst.relocs[0].pc_rel = 0;
5599 return SUCCESS;
5602 /* Group relocation information. Each entry in the table contains the
5603 textual name of the relocation as may appear in assembler source
5604 and must end with a colon.
5605 Along with this textual name are the relocation codes to be used if
5606 the corresponding instruction is an ALU instruction (ADD or SUB only),
5607 an LDR, an LDRS, or an LDC. */
5609 struct group_reloc_table_entry
5611 const char *name;
5612 int alu_code;
5613 int ldr_code;
5614 int ldrs_code;
5615 int ldc_code;
5618 typedef enum
5620 /* Varieties of non-ALU group relocation. */
5622 GROUP_LDR,
5623 GROUP_LDRS,
5624 GROUP_LDC,
5625 GROUP_MVE
5626 } group_reloc_type;
5628 static struct group_reloc_table_entry group_reloc_table[] =
5629 { /* Program counter relative: */
5630 { "pc_g0_nc",
5631 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5632 0, /* LDR */
5633 0, /* LDRS */
5634 0 }, /* LDC */
5635 { "pc_g0",
5636 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5637 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5638 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5639 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5640 { "pc_g1_nc",
5641 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5642 0, /* LDR */
5643 0, /* LDRS */
5644 0 }, /* LDC */
5645 { "pc_g1",
5646 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5647 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5648 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5649 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5650 { "pc_g2",
5651 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5652 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5653 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5654 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5655 /* Section base relative */
5656 { "sb_g0_nc",
5657 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5658 0, /* LDR */
5659 0, /* LDRS */
5660 0 }, /* LDC */
5661 { "sb_g0",
5662 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5663 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5664 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5665 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5666 { "sb_g1_nc",
5667 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5668 0, /* LDR */
5669 0, /* LDRS */
5670 0 }, /* LDC */
5671 { "sb_g1",
5672 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5673 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5674 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5675 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5676 { "sb_g2",
5677 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5678 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5679 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5680 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5681 /* Absolute thumb alu relocations. */
5682 { "lower0_7",
5683 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5684 0, /* LDR. */
5685 0, /* LDRS. */
5686 0 }, /* LDC. */
5687 { "lower8_15",
5688 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5689 0, /* LDR. */
5690 0, /* LDRS. */
5691 0 }, /* LDC. */
5692 { "upper0_7",
5693 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5694 0, /* LDR. */
5695 0, /* LDRS. */
5696 0 }, /* LDC. */
5697 { "upper8_15",
5698 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5699 0, /* LDR. */
5700 0, /* LDRS. */
5701 0 } }; /* LDC. */
5703 /* Given the address of a pointer pointing to the textual name of a group
5704 relocation as may appear in assembler source, attempt to find its details
5705 in group_reloc_table. The pointer will be updated to the character after
5706 the trailing colon. On failure, FAIL will be returned; SUCCESS
5707 otherwise. On success, *entry will be updated to point at the relevant
5708 group_reloc_table entry. */
5710 static int
5711 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5713 unsigned int i;
5714 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5716 int length = strlen (group_reloc_table[i].name);
5718 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5719 && (*str)[length] == ':')
5721 *out = &group_reloc_table[i];
5722 *str += (length + 1);
5723 return SUCCESS;
5727 return FAIL;
5730 /* Parse a <shifter_operand> for an ARM data processing instruction
5731 (as for parse_shifter_operand) where group relocations are allowed:
5733 #<immediate>
5734 #<immediate>, <rotate>
5735 #:<group_reloc>:<expression>
5736 <Rm>
5737 <Rm>, <shift>
5739 where <group_reloc> is one of the strings defined in group_reloc_table.
5740 The hashes are optional.
5742 Everything else is as for parse_shifter_operand. */
5744 static parse_operand_result
5745 parse_shifter_operand_group_reloc (char **str, int i)
5747 /* Determine if we have the sequence of characters #: or just :
5748 coming next. If we do, then we check for a group relocation.
5749 If we don't, punt the whole lot to parse_shifter_operand. */
5751 if (((*str)[0] == '#' && (*str)[1] == ':')
5752 || (*str)[0] == ':')
5754 struct group_reloc_table_entry *entry;
5756 if ((*str)[0] == '#')
5757 (*str) += 2;
5758 else
5759 (*str)++;
5761 /* Try to parse a group relocation. Anything else is an error. */
5762 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5764 inst.error = _("unknown group relocation");
5765 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5768 /* We now have the group relocation table entry corresponding to
5769 the name in the assembler source. Next, we parse the expression. */
5770 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5771 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5773 /* Record the relocation type (always the ALU variant here). */
5774 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5775 gas_assert (inst.relocs[0].type != 0);
5777 return PARSE_OPERAND_SUCCESS;
5779 else
5780 return parse_shifter_operand (str, i) == SUCCESS
5781 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5783 /* Never reached. */
5786 /* Parse a Neon alignment expression. Information is written to
5787 inst.operands[i]. We assume the initial ':' has been skipped.
5789 align .imm = align << 8, .immisalign=1, .preind=0 */
5790 static parse_operand_result
5791 parse_neon_alignment (char **str, int i)
5793 char *p = *str;
5794 expressionS exp;
5796 my_get_expression (&exp, &p, GE_NO_PREFIX);
5798 if (exp.X_op != O_constant)
5800 inst.error = _("alignment must be constant");
5801 return PARSE_OPERAND_FAIL;
5804 inst.operands[i].imm = exp.X_add_number << 8;
5805 inst.operands[i].immisalign = 1;
5806 /* Alignments are not pre-indexes. */
5807 inst.operands[i].preind = 0;
5809 *str = p;
5810 return PARSE_OPERAND_SUCCESS;
5813 /* Parse all forms of an ARM address expression. Information is written
5814 to inst.operands[i] and/or inst.relocs[0].
5816 Preindexed addressing (.preind=1):
5818 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5819 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5820 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5821 .shift_kind=shift .relocs[0].exp=shift_imm
5823 These three may have a trailing ! which causes .writeback to be set also.
5825 Postindexed addressing (.postind=1, .writeback=1):
5827 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5828 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5829 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5830 .shift_kind=shift .relocs[0].exp=shift_imm
5832 Unindexed addressing (.preind=0, .postind=0):
5834 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5836 Other:
5838 [Rn]{!} shorthand for [Rn,#0]{!}
5839 =immediate .isreg=0 .relocs[0].exp=immediate
5840 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5842 It is the caller's responsibility to check for addressing modes not
5843 supported by the instruction, and to set inst.relocs[0].type. */
5845 static parse_operand_result
5846 parse_address_main (char **str, int i, int group_relocations,
5847 group_reloc_type group_type)
5849 char *p = *str;
5850 int reg;
5852 if (skip_past_char (&p, '[') == FAIL)
5854 if (group_type == GROUP_MVE
5855 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5857 /* [r0-r15] expected as argument but receiving r0-r15 without
5858 [] brackets. */
5859 inst.error = BAD_SYNTAX;
5860 return PARSE_OPERAND_FAIL;
5862 else if (skip_past_char (&p, '=') == FAIL)
5864 /* Bare address - translate to PC-relative offset. */
5865 inst.relocs[0].pc_rel = 1;
5866 inst.operands[i].reg = REG_PC;
5867 inst.operands[i].isreg = 1;
5868 inst.operands[i].preind = 1;
5870 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5871 return PARSE_OPERAND_FAIL;
5873 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5874 /*allow_symbol_p=*/true))
5875 return PARSE_OPERAND_FAIL;
5877 *str = p;
5878 return PARSE_OPERAND_SUCCESS;
5881 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5882 skip_whitespace (p);
5884 if (group_type == GROUP_MVE)
5886 enum arm_reg_type rtype = REG_TYPE_MQ;
5887 struct neon_type_el et;
5888 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5890 inst.operands[i].isquad = 1;
5892 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5894 inst.error = BAD_ADDR_MODE;
5895 return PARSE_OPERAND_FAIL;
5898 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5900 if (group_type == GROUP_MVE)
5901 inst.error = BAD_ADDR_MODE;
5902 else
5903 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5904 return PARSE_OPERAND_FAIL;
5906 inst.operands[i].reg = reg;
5907 inst.operands[i].isreg = 1;
5909 if (skip_past_comma (&p) == SUCCESS)
5911 inst.operands[i].preind = 1;
5913 if (*p == '+') p++;
5914 else if (*p == '-') p++, inst.operands[i].negative = 1;
5916 enum arm_reg_type rtype = REG_TYPE_MQ;
5917 struct neon_type_el et;
5918 if (group_type == GROUP_MVE
5919 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5921 inst.operands[i].immisreg = 2;
5922 inst.operands[i].imm = reg;
5924 if (skip_past_comma (&p) == SUCCESS)
5926 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
5928 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
5929 inst.relocs[0].exp.X_add_number = 0;
5931 else
5932 return PARSE_OPERAND_FAIL;
5935 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5937 inst.operands[i].imm = reg;
5938 inst.operands[i].immisreg = 1;
5940 if (skip_past_comma (&p) == SUCCESS)
5941 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5942 return PARSE_OPERAND_FAIL;
5944 else if (skip_past_char (&p, ':') == SUCCESS)
5946 /* FIXME: '@' should be used here, but it's filtered out by generic
5947 code before we get to see it here. This may be subject to
5948 change. */
5949 parse_operand_result result = parse_neon_alignment (&p, i);
5951 if (result != PARSE_OPERAND_SUCCESS)
5952 return result;
5954 else
5956 if (inst.operands[i].negative)
5958 inst.operands[i].negative = 0;
5959 p--;
5962 if (group_relocations
5963 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5965 struct group_reloc_table_entry *entry;
5967 /* Skip over the #: or : sequence. */
5968 if (*p == '#')
5969 p += 2;
5970 else
5971 p++;
5973 /* Try to parse a group relocation. Anything else is an
5974 error. */
5975 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5977 inst.error = _("unknown group relocation");
5978 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5981 /* We now have the group relocation table entry corresponding to
5982 the name in the assembler source. Next, we parse the
5983 expression. */
5984 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
5985 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5987 /* Record the relocation type. */
5988 switch (group_type)
5990 case GROUP_LDR:
5991 inst.relocs[0].type
5992 = (bfd_reloc_code_real_type) entry->ldr_code;
5993 break;
5995 case GROUP_LDRS:
5996 inst.relocs[0].type
5997 = (bfd_reloc_code_real_type) entry->ldrs_code;
5998 break;
6000 case GROUP_LDC:
6001 inst.relocs[0].type
6002 = (bfd_reloc_code_real_type) entry->ldc_code;
6003 break;
6005 default:
6006 gas_assert (0);
6009 if (inst.relocs[0].type == 0)
6011 inst.error = _("this group relocation is not allowed on this instruction");
6012 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6015 else
6017 char *q = p;
6019 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6020 return PARSE_OPERAND_FAIL;
6021 /* If the offset is 0, find out if it's a +0 or -0. */
6022 if (inst.relocs[0].exp.X_op == O_constant
6023 && inst.relocs[0].exp.X_add_number == 0)
6025 skip_whitespace (q);
6026 if (*q == '#')
6028 q++;
6029 skip_whitespace (q);
6031 if (*q == '-')
6032 inst.operands[i].negative = 1;
6037 else if (skip_past_char (&p, ':') == SUCCESS)
6039 /* FIXME: '@' should be used here, but it's filtered out by generic code
6040 before we get to see it here. This may be subject to change. */
6041 parse_operand_result result = parse_neon_alignment (&p, i);
6043 if (result != PARSE_OPERAND_SUCCESS)
6044 return result;
6047 if (skip_past_char (&p, ']') == FAIL)
6049 inst.error = _("']' expected");
6050 return PARSE_OPERAND_FAIL;
6053 if (skip_past_char (&p, '!') == SUCCESS)
6054 inst.operands[i].writeback = 1;
6056 else if (skip_past_comma (&p) == SUCCESS)
6058 if (skip_past_char (&p, '{') == SUCCESS)
6060 /* [Rn], {expr} - unindexed, with option */
6061 if (parse_immediate (&p, &inst.operands[i].imm,
6062 0, 255, true) == FAIL)
6063 return PARSE_OPERAND_FAIL;
6065 if (skip_past_char (&p, '}') == FAIL)
6067 inst.error = _("'}' expected at end of 'option' field");
6068 return PARSE_OPERAND_FAIL;
6070 if (inst.operands[i].preind)
6072 inst.error = _("cannot combine index with option");
6073 return PARSE_OPERAND_FAIL;
6075 *str = p;
6076 return PARSE_OPERAND_SUCCESS;
6078 else
6080 inst.operands[i].postind = 1;
6081 inst.operands[i].writeback = 1;
6083 if (inst.operands[i].preind)
6085 inst.error = _("cannot combine pre- and post-indexing");
6086 return PARSE_OPERAND_FAIL;
6089 if (*p == '+') p++;
6090 else if (*p == '-') p++, inst.operands[i].negative = 1;
6092 enum arm_reg_type rtype = REG_TYPE_MQ;
6093 struct neon_type_el et;
6094 if (group_type == GROUP_MVE
6095 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6097 inst.operands[i].immisreg = 2;
6098 inst.operands[i].imm = reg;
6100 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6102 /* We might be using the immediate for alignment already. If we
6103 are, OR the register number into the low-order bits. */
6104 if (inst.operands[i].immisalign)
6105 inst.operands[i].imm |= reg;
6106 else
6107 inst.operands[i].imm = reg;
6108 inst.operands[i].immisreg = 1;
6110 if (skip_past_comma (&p) == SUCCESS)
6111 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6112 return PARSE_OPERAND_FAIL;
6114 else
6116 char *q = p;
6118 if (inst.operands[i].negative)
6120 inst.operands[i].negative = 0;
6121 p--;
6123 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6124 return PARSE_OPERAND_FAIL;
6125 /* If the offset is 0, find out if it's a +0 or -0. */
6126 if (inst.relocs[0].exp.X_op == O_constant
6127 && inst.relocs[0].exp.X_add_number == 0)
6129 skip_whitespace (q);
6130 if (*q == '#')
6132 q++;
6133 skip_whitespace (q);
6135 if (*q == '-')
6136 inst.operands[i].negative = 1;
6142 /* If at this point neither .preind nor .postind is set, we have a
6143 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6144 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6146 inst.operands[i].preind = 1;
6147 inst.relocs[0].exp.X_op = O_constant;
6148 inst.relocs[0].exp.X_add_number = 0;
6150 *str = p;
6151 return PARSE_OPERAND_SUCCESS;
6154 static int
6155 parse_address (char **str, int i)
6157 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
6158 ? SUCCESS : FAIL;
6161 static parse_operand_result
6162 parse_address_group_reloc (char **str, int i, group_reloc_type type)
6164 return parse_address_main (str, i, 1, type);
6167 /* Parse an operand for a MOVW or MOVT instruction. */
6168 static int
6169 parse_half (char **str)
6171 char * p;
6173 p = *str;
6174 skip_past_char (&p, '#');
6175 if (strncasecmp (p, ":lower16:", 9) == 0)
6176 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
6177 else if (strncasecmp (p, ":upper16:", 9) == 0)
6178 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
6180 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
6182 p += 9;
6183 skip_whitespace (p);
6186 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6187 return FAIL;
6189 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
6191 if (inst.relocs[0].exp.X_op != O_constant)
6193 inst.error = _("constant expression expected");
6194 return FAIL;
6196 if (inst.relocs[0].exp.X_add_number < 0
6197 || inst.relocs[0].exp.X_add_number > 0xffff)
6199 inst.error = _("immediate value out of range");
6200 return FAIL;
6203 *str = p;
6204 return SUCCESS;
6207 /* Miscellaneous. */
6209 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6210 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6211 static int
6212 parse_psr (char **str, bool lhs)
6214 char *p;
6215 unsigned long psr_field;
6216 const struct asm_psr *psr;
6217 char *start;
6218 bool is_apsr = false;
6219 bool m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
6221 /* PR gas/12698: If the user has specified -march=all then m_profile will
6222 be TRUE, but we want to ignore it in this case as we are building for any
6223 CPU type, including non-m variants. */
6224 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
6225 m_profile = false;
6227 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6228 feature for ease of use and backwards compatibility. */
6229 p = *str;
6230 if (strncasecmp (p, "SPSR", 4) == 0)
6232 if (m_profile)
6233 goto unsupported_psr;
6235 psr_field = SPSR_BIT;
6237 else if (strncasecmp (p, "CPSR", 4) == 0)
6239 if (m_profile)
6240 goto unsupported_psr;
6242 psr_field = 0;
6244 else if (strncasecmp (p, "APSR", 4) == 0)
6246 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6247 and ARMv7-R architecture CPUs. */
6248 is_apsr = true;
6249 psr_field = 0;
6251 else if (m_profile)
6253 start = p;
6255 p++;
6256 while (ISALNUM (*p) || *p == '_');
6258 if (strncasecmp (start, "iapsr", 5) == 0
6259 || strncasecmp (start, "eapsr", 5) == 0
6260 || strncasecmp (start, "xpsr", 4) == 0
6261 || strncasecmp (start, "psr", 3) == 0)
6262 p = start + strcspn (start, "rR") + 1;
6264 psr = (const struct asm_psr *) str_hash_find_n (arm_v7m_psr_hsh, start,
6265 p - start);
6267 if (!psr)
6268 return FAIL;
6270 /* If APSR is being written, a bitfield may be specified. Note that
6271 APSR itself is handled above. */
6272 if (psr->field <= 3)
6274 psr_field = psr->field;
6275 is_apsr = true;
6276 goto check_suffix;
6279 *str = p;
6280 /* M-profile MSR instructions have the mask field set to "10", except
6281 *PSR variants which modify APSR, which may use a different mask (and
6282 have been handled already). Do that by setting the PSR_f field
6283 here. */
6284 return psr->field | (lhs ? PSR_f : 0);
6286 else
6287 goto unsupported_psr;
6289 p += 4;
6290 check_suffix:
6291 if (*p == '_')
6293 /* A suffix follows. */
6294 p++;
6295 start = p;
6298 p++;
6299 while (ISALNUM (*p) || *p == '_');
6301 if (is_apsr)
6303 /* APSR uses a notation for bits, rather than fields. */
6304 unsigned int nzcvq_bits = 0;
6305 unsigned int g_bit = 0;
6306 char *bit;
6308 for (bit = start; bit != p; bit++)
6310 switch (TOLOWER (*bit))
6312 case 'n':
6313 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6314 break;
6316 case 'z':
6317 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6318 break;
6320 case 'c':
6321 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6322 break;
6324 case 'v':
6325 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6326 break;
6328 case 'q':
6329 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6330 break;
6332 case 'g':
6333 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6334 break;
6336 default:
6337 inst.error = _("unexpected bit specified after APSR");
6338 return FAIL;
6342 if (nzcvq_bits == 0x1f)
6343 psr_field |= PSR_f;
6345 if (g_bit == 0x1)
6347 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
6349 inst.error = _("selected processor does not "
6350 "support DSP extension");
6351 return FAIL;
6354 psr_field |= PSR_s;
6357 if ((nzcvq_bits & 0x20) != 0
6358 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6359 || (g_bit & 0x2) != 0)
6361 inst.error = _("bad bitmask specified after APSR");
6362 return FAIL;
6365 else
6367 psr = (const struct asm_psr *) str_hash_find_n (arm_psr_hsh, start,
6368 p - start);
6369 if (!psr)
6370 goto error;
6372 psr_field |= psr->field;
6375 else
6377 if (ISALNUM (*p))
6378 goto error; /* Garbage after "[CS]PSR". */
6380 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6381 is deprecated, but allow it anyway. */
6382 if (is_apsr && lhs)
6384 psr_field |= PSR_f;
6385 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6386 "deprecated"));
6388 else if (!m_profile)
6389 /* These bits are never right for M-profile devices: don't set them
6390 (only code paths which read/write APSR reach here). */
6391 psr_field |= (PSR_c | PSR_f);
6393 *str = p;
6394 return psr_field;
6396 unsupported_psr:
6397 inst.error = _("selected processor does not support requested special "
6398 "purpose register");
6399 return FAIL;
6401 error:
6402 inst.error = _("flag for {c}psr instruction expected");
6403 return FAIL;
6406 static int
6407 parse_sys_vldr_vstr (char **str)
6409 unsigned i;
6410 int val = FAIL;
6411 struct {
6412 const char *name;
6413 int regl;
6414 int regh;
6415 } sysregs[] = {
6416 {"FPSCR", 0x1, 0x0},
6417 {"FPSCR_nzcvqc", 0x2, 0x0},
6418 {"VPR", 0x4, 0x1},
6419 {"P0", 0x5, 0x1},
6420 {"FPCXTNS", 0x6, 0x1},
6421 {"FPCXT_NS", 0x6, 0x1},
6422 {"fpcxtns", 0x6, 0x1},
6423 {"fpcxt_ns", 0x6, 0x1},
6424 {"FPCXTS", 0x7, 0x1},
6425 {"FPCXT_S", 0x7, 0x1},
6426 {"fpcxts", 0x7, 0x1},
6427 {"fpcxt_s", 0x7, 0x1}
6429 char *op_end = strchr (*str, ',');
6430 size_t op_strlen = op_end - *str;
6432 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6434 if (!strncmp (*str, sysregs[i].name, op_strlen))
6436 val = sysregs[i].regl | (sysregs[i].regh << 3);
6437 *str = op_end;
6438 break;
6442 return val;
6445 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6446 value suitable for splatting into the AIF field of the instruction. */
6448 static int
6449 parse_cps_flags (char **str)
6451 int val = 0;
6452 int saw_a_flag = 0;
6453 char *s = *str;
6455 for (;;)
6456 switch (*s++)
6458 case '\0': case ',':
6459 goto done;
6461 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6462 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6463 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6465 default:
6466 inst.error = _("unrecognized CPS flag");
6467 return FAIL;
6470 done:
6471 if (saw_a_flag == 0)
6473 inst.error = _("missing CPS flags");
6474 return FAIL;
6477 *str = s - 1;
6478 return val;
6481 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6482 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6484 static int
6485 parse_endian_specifier (char **str)
6487 int little_endian;
6488 char *s = *str;
6490 if (strncasecmp (s, "BE", 2))
6491 little_endian = 0;
6492 else if (strncasecmp (s, "LE", 2))
6493 little_endian = 1;
6494 else
6496 inst.error = _("valid endian specifiers are be or le");
6497 return FAIL;
6500 if (ISALNUM (s[2]) || s[2] == '_')
6502 inst.error = _("valid endian specifiers are be or le");
6503 return FAIL;
6506 *str = s + 2;
6507 return little_endian;
6510 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6511 value suitable for poking into the rotate field of an sxt or sxta
6512 instruction, or FAIL on error. */
6514 static int
6515 parse_ror (char **str)
6517 int rot;
6518 char *s = *str;
6520 if (strncasecmp (s, "ROR", 3) == 0)
6521 s += 3;
6522 else
6524 inst.error = _("missing rotation field after comma");
6525 return FAIL;
6528 if (parse_immediate (&s, &rot, 0, 24, false) == FAIL)
6529 return FAIL;
6531 switch (rot)
6533 case 0: *str = s; return 0x0;
6534 case 8: *str = s; return 0x1;
6535 case 16: *str = s; return 0x2;
6536 case 24: *str = s; return 0x3;
6538 default:
6539 inst.error = _("rotation can only be 0, 8, 16, or 24");
6540 return FAIL;
6544 /* Parse a conditional code (from conds[] below). The value returned is in the
6545 range 0 .. 14, or FAIL. */
6546 static int
6547 parse_cond (char **str)
6549 char *q;
6550 const struct asm_cond *c;
6551 int n;
6552 /* Condition codes are always 2 characters, so matching up to
6553 3 characters is sufficient. */
6554 char cond[3];
6556 q = *str;
6557 n = 0;
6558 while (ISALPHA (*q) && n < 3)
6560 cond[n] = TOLOWER (*q);
6561 q++;
6562 n++;
6565 c = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, cond, n);
6566 if (!c)
6568 inst.error = _("condition required");
6569 return FAIL;
6572 *str = q;
6573 return c->value;
6576 /* Parse an option for a barrier instruction. Returns the encoding for the
6577 option, or FAIL. */
6578 static int
6579 parse_barrier (char **str)
6581 char *p, *q;
6582 const struct asm_barrier_opt *o;
6584 p = q = *str;
6585 while (ISALPHA (*q))
6586 q++;
6588 o = (const struct asm_barrier_opt *) str_hash_find_n (arm_barrier_opt_hsh, p,
6589 q - p);
6590 if (!o)
6591 return FAIL;
6593 if (!mark_feature_used (&o->arch))
6594 return FAIL;
6596 *str = q;
6597 return o->value;
6600 /* Parse the operands of a table branch instruction. Similar to a memory
6601 operand. */
6602 static int
6603 parse_tb (char **str)
6605 char * p = *str;
6606 int reg;
6608 if (skip_past_char (&p, '[') == FAIL)
6610 inst.error = _("'[' expected");
6611 return FAIL;
6614 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6616 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6617 return FAIL;
6619 inst.operands[0].reg = reg;
6621 if (skip_past_comma (&p) == FAIL)
6623 inst.error = _("',' expected");
6624 return FAIL;
6627 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6629 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6630 return FAIL;
6632 inst.operands[0].imm = reg;
6634 if (skip_past_comma (&p) == SUCCESS)
6636 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6637 return FAIL;
6638 if (inst.relocs[0].exp.X_add_number != 1)
6640 inst.error = _("invalid shift");
6641 return FAIL;
6643 inst.operands[0].shifted = 1;
6646 if (skip_past_char (&p, ']') == FAIL)
6648 inst.error = _("']' expected");
6649 return FAIL;
6651 *str = p;
6652 return SUCCESS;
6655 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6656 information on the types the operands can take and how they are encoded.
6657 Up to four operands may be read; this function handles setting the
6658 ".present" field for each read operand itself.
6659 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6660 else returns FAIL. */
6662 static int
6663 parse_neon_mov (char **str, int *which_operand)
6665 int i = *which_operand, val;
6666 enum arm_reg_type rtype;
6667 char *ptr = *str;
6668 struct neon_type_el optype;
6670 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6672 /* Cases 17 or 19. */
6673 inst.operands[i].reg = val;
6674 inst.operands[i].isvec = 1;
6675 inst.operands[i].isscalar = 2;
6676 inst.operands[i].vectype = optype;
6677 inst.operands[i++].present = 1;
6679 if (skip_past_comma (&ptr) == FAIL)
6680 goto wanted_comma;
6682 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6684 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6685 inst.operands[i].reg = val;
6686 inst.operands[i].isreg = 1;
6687 inst.operands[i].present = 1;
6689 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6691 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6692 inst.operands[i].reg = val;
6693 inst.operands[i].isvec = 1;
6694 inst.operands[i].isscalar = 2;
6695 inst.operands[i].vectype = optype;
6696 inst.operands[i++].present = 1;
6698 if (skip_past_comma (&ptr) == FAIL)
6699 goto wanted_comma;
6701 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6702 goto wanted_arm;
6704 inst.operands[i].reg = val;
6705 inst.operands[i].isreg = 1;
6706 inst.operands[i++].present = 1;
6708 if (skip_past_comma (&ptr) == FAIL)
6709 goto wanted_comma;
6711 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6712 goto wanted_arm;
6714 inst.operands[i].reg = val;
6715 inst.operands[i].isreg = 1;
6716 inst.operands[i].present = 1;
6718 else
6720 first_error (_("expected ARM or MVE vector register"));
6721 return FAIL;
6724 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6726 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6727 inst.operands[i].reg = val;
6728 inst.operands[i].isscalar = 1;
6729 inst.operands[i].vectype = optype;
6730 inst.operands[i++].present = 1;
6732 if (skip_past_comma (&ptr) == FAIL)
6733 goto wanted_comma;
6735 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6736 goto wanted_arm;
6738 inst.operands[i].reg = val;
6739 inst.operands[i].isreg = 1;
6740 inst.operands[i].present = 1;
6742 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6743 != FAIL)
6744 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6745 != FAIL))
6747 /* Cases 0, 1, 2, 3, 5 (D only). */
6748 if (skip_past_comma (&ptr) == FAIL)
6749 goto wanted_comma;
6751 inst.operands[i].reg = val;
6752 inst.operands[i].isreg = 1;
6753 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6754 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6755 inst.operands[i].isvec = 1;
6756 inst.operands[i].vectype = optype;
6757 inst.operands[i++].present = 1;
6759 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6761 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6762 Case 13: VMOV <Sd>, <Rm> */
6763 inst.operands[i].reg = val;
6764 inst.operands[i].isreg = 1;
6765 inst.operands[i].present = 1;
6767 if (rtype == REG_TYPE_NQ)
6769 first_error (_("can't use Neon quad register here"));
6770 return FAIL;
6772 else if (rtype != REG_TYPE_VFS)
6774 i++;
6775 if (skip_past_comma (&ptr) == FAIL)
6776 goto wanted_comma;
6777 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6778 goto wanted_arm;
6779 inst.operands[i].reg = val;
6780 inst.operands[i].isreg = 1;
6781 inst.operands[i].present = 1;
6784 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6785 &optype)) != FAIL)
6786 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6787 &optype)) != FAIL))
6789 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6790 Case 1: VMOV<c><q> <Dd>, <Dm>
6791 Case 8: VMOV.F32 <Sd>, <Sm>
6792 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6794 inst.operands[i].reg = val;
6795 inst.operands[i].isreg = 1;
6796 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6797 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6798 inst.operands[i].isvec = 1;
6799 inst.operands[i].vectype = optype;
6800 inst.operands[i].present = 1;
6802 if (skip_past_comma (&ptr) == SUCCESS)
6804 /* Case 15. */
6805 i++;
6807 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6808 goto wanted_arm;
6810 inst.operands[i].reg = val;
6811 inst.operands[i].isreg = 1;
6812 inst.operands[i++].present = 1;
6814 if (skip_past_comma (&ptr) == FAIL)
6815 goto wanted_comma;
6817 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6818 goto wanted_arm;
6820 inst.operands[i].reg = val;
6821 inst.operands[i].isreg = 1;
6822 inst.operands[i].present = 1;
6825 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6826 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6827 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6828 Case 10: VMOV.F32 <Sd>, #<imm>
6829 Case 11: VMOV.F64 <Dd>, #<imm> */
6830 inst.operands[i].immisfloat = 1;
6831 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/false)
6832 == SUCCESS)
6833 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6834 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6836 else
6838 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6839 return FAIL;
6842 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6844 /* Cases 6, 7, 16, 18. */
6845 inst.operands[i].reg = val;
6846 inst.operands[i].isreg = 1;
6847 inst.operands[i++].present = 1;
6849 if (skip_past_comma (&ptr) == FAIL)
6850 goto wanted_comma;
6852 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6854 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6855 inst.operands[i].reg = val;
6856 inst.operands[i].isscalar = 2;
6857 inst.operands[i].present = 1;
6858 inst.operands[i].vectype = optype;
6860 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6862 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6863 inst.operands[i].reg = val;
6864 inst.operands[i].isscalar = 1;
6865 inst.operands[i].present = 1;
6866 inst.operands[i].vectype = optype;
6868 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6870 inst.operands[i].reg = val;
6871 inst.operands[i].isreg = 1;
6872 inst.operands[i++].present = 1;
6874 if (skip_past_comma (&ptr) == FAIL)
6875 goto wanted_comma;
6877 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6878 != FAIL)
6880 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6882 inst.operands[i].reg = val;
6883 inst.operands[i].isreg = 1;
6884 inst.operands[i].isvec = 1;
6885 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6886 inst.operands[i].vectype = optype;
6887 inst.operands[i].present = 1;
6889 if (rtype == REG_TYPE_VFS)
6891 /* Case 14. */
6892 i++;
6893 if (skip_past_comma (&ptr) == FAIL)
6894 goto wanted_comma;
6895 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6896 &optype)) == FAIL)
6898 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6899 return FAIL;
6901 inst.operands[i].reg = val;
6902 inst.operands[i].isreg = 1;
6903 inst.operands[i].isvec = 1;
6904 inst.operands[i].issingle = 1;
6905 inst.operands[i].vectype = optype;
6906 inst.operands[i].present = 1;
6909 else
6911 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6912 != FAIL)
6914 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6915 inst.operands[i].reg = val;
6916 inst.operands[i].isvec = 1;
6917 inst.operands[i].isscalar = 2;
6918 inst.operands[i].vectype = optype;
6919 inst.operands[i++].present = 1;
6921 if (skip_past_comma (&ptr) == FAIL)
6922 goto wanted_comma;
6924 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6925 == FAIL)
6927 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6928 return FAIL;
6930 inst.operands[i].reg = val;
6931 inst.operands[i].isvec = 1;
6932 inst.operands[i].isscalar = 2;
6933 inst.operands[i].vectype = optype;
6934 inst.operands[i].present = 1;
6936 else
6938 first_error (_("VFP single, double or MVE vector register"
6939 " expected"));
6940 return FAIL;
6944 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6945 != FAIL)
6947 /* Case 13. */
6948 inst.operands[i].reg = val;
6949 inst.operands[i].isreg = 1;
6950 inst.operands[i].isvec = 1;
6951 inst.operands[i].issingle = 1;
6952 inst.operands[i].vectype = optype;
6953 inst.operands[i].present = 1;
6956 else
6958 first_error (_("parse error"));
6959 return FAIL;
6962 /* Successfully parsed the operands. Update args. */
6963 *which_operand = i;
6964 *str = ptr;
6965 return SUCCESS;
6967 wanted_comma:
6968 first_error (_("expected comma"));
6969 return FAIL;
6971 wanted_arm:
6972 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6973 return FAIL;
6976 /* Use this macro when the operand constraints are different
6977 for ARM and THUMB (e.g. ldrd). */
6978 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6979 ((arm_operand) | ((thumb_operand) << 16))
6981 /* Matcher codes for parse_operands. */
6982 enum operand_parse_code
6984 OP_stop, /* end of line */
6986 OP_RR, /* ARM register */
6987 OP_RRnpc, /* ARM register, not r15 */
6988 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6989 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6990 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6991 optional trailing ! */
6992 OP_RRw, /* ARM register, not r15, optional trailing ! */
6993 OP_RCP, /* Coprocessor number */
6994 OP_RCN, /* Coprocessor register */
6995 OP_RVS, /* VFP single precision register */
6996 OP_RVD, /* VFP double precision register (0..15) */
6997 OP_RND, /* Neon double precision register (0..31) */
6998 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
6999 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7001 OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register.
7003 OP_RNQ, /* Neon quad precision register */
7004 OP_RNQMQ, /* Neon quad or MVE vector register. */
7005 OP_RVSD, /* VFP single or double precision register */
7006 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
7007 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
7008 OP_RNSD, /* Neon single or double precision register */
7009 OP_RNDQ, /* Neon double or quad precision register */
7010 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7011 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
7012 OP_RNSDQ, /* Neon single, double or quad precision register */
7013 OP_RNSC, /* Neon scalar D[X] */
7014 OP_RVC, /* VFP control register */
7015 OP_RIWR, /* iWMMXt wR register */
7016 OP_RIWC, /* iWMMXt wC register */
7017 OP_RIWG, /* iWMMXt wCG register */
7018 OP_RXA, /* XScale accumulator register */
7020 OP_RNSDMQ, /* Neon single, double or MVE vector register */
7021 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7023 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7024 GPR (no SP/SP) */
7025 OP_RMQ, /* MVE vector register. */
7026 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
7027 OP_RMQRR, /* MVE vector or ARM register. */
7029 /* New operands for Armv8.1-M Mainline. */
7030 OP_LR, /* ARM LR register */
7031 OP_SP, /* ARM SP register */
7032 OP_R12,
7033 OP_RRe, /* ARM register, only even numbered. */
7034 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
7035 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
7036 OP_RR_ZR, /* ARM register or ZR but no PC */
7038 OP_REGLST, /* ARM register list */
7039 OP_CLRMLST, /* CLRM register list */
7040 OP_VRSLST, /* VFP single-precision register list */
7041 OP_VRDLST, /* VFP double-precision register list */
7042 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
7043 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7044 OP_NSTRLST, /* Neon element/structure list */
7045 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
7046 OP_MSTRLST2, /* MVE vector list with two elements. */
7047 OP_MSTRLST4, /* MVE vector list with four elements. */
7049 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
7050 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
7051 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
7052 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7053 zero. */
7054 OP_RR_RNSC, /* ARM reg or Neon scalar. */
7055 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
7056 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
7057 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7059 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7060 scalar, or ARM register. */
7061 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
7062 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7063 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7064 register. */
7065 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
7066 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7067 OP_VMOV, /* Neon VMOV operands. */
7068 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
7069 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7070 OP_RNDQMQ_Ibig,
7071 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
7072 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7073 ARM register. */
7074 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
7075 OP_VLDR, /* VLDR operand. */
7077 OP_I0, /* immediate zero */
7078 OP_I7, /* immediate value 0 .. 7 */
7079 OP_I15, /* 0 .. 15 */
7080 OP_I16, /* 1 .. 16 */
7081 OP_I16z, /* 0 .. 16 */
7082 OP_I31, /* 0 .. 31 */
7083 OP_I31w, /* 0 .. 31, optional trailing ! */
7084 OP_I32, /* 1 .. 32 */
7085 OP_I32z, /* 0 .. 32 */
7086 OP_I48_I64, /* 48 or 64 */
7087 OP_I63, /* 0 .. 63 */
7088 OP_I63s, /* -64 .. 63 */
7089 OP_I64, /* 1 .. 64 */
7090 OP_I64z, /* 0 .. 64 */
7091 OP_I127, /* 0 .. 127 */
7092 OP_I255, /* 0 .. 255 */
7093 OP_I511, /* 0 .. 511 */
7094 OP_I4095, /* 0 .. 4095 */
7095 OP_I8191, /* 0 .. 8191 */
7096 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7097 OP_I7b, /* 0 .. 7 */
7098 OP_I15b, /* 0 .. 15 */
7099 OP_I31b, /* 0 .. 31 */
7101 OP_SH, /* shifter operand */
7102 OP_SHG, /* shifter operand with possible group relocation */
7103 OP_ADDR, /* Memory address expression (any mode) */
7104 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
7105 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7106 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7107 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
7108 OP_EXP, /* arbitrary expression */
7109 OP_EXPi, /* same, with optional immediate prefix */
7110 OP_EXPr, /* same, with optional relocation suffix */
7111 OP_EXPs, /* same, with optional non-first operand relocation suffix */
7112 OP_HALF, /* 0 .. 65535 or low/high reloc. */
7113 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7114 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
7116 OP_CPSF, /* CPS flags */
7117 OP_ENDI, /* Endianness specifier */
7118 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7119 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
7120 OP_COND, /* conditional code */
7121 OP_TB, /* Table branch. */
7123 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7125 OP_RRnpc_I0, /* ARM register or literal 0 */
7126 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
7127 OP_RR_EXi, /* ARM register or expression with imm prefix */
7128 OP_RIWR_RIWC, /* iWMMXt R or C reg */
7129 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
7131 /* Optional operands. */
7132 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7133 OP_oI31b, /* 0 .. 31 */
7134 OP_oI32b, /* 1 .. 32 */
7135 OP_oI32z, /* 0 .. 32 */
7136 OP_oIffffb, /* 0 .. 65535 */
7137 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7139 OP_oRR, /* ARM register */
7140 OP_oLR, /* ARM LR register */
7141 OP_oRRnpc, /* ARM register, not the PC */
7142 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
7143 OP_oRRw, /* ARM register, not r15, optional trailing ! */
7144 OP_oRND, /* Optional Neon double precision register */
7145 OP_oRNQ, /* Optional Neon quad precision register */
7146 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
7147 OP_oRNDQ, /* Optional Neon double or quad precision register */
7148 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
7149 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7150 register. */
7151 OP_oRNSDMQ, /* Optional single, double register or MVE vector
7152 register. */
7153 OP_oSHll, /* LSL immediate */
7154 OP_oSHar, /* ASR immediate */
7155 OP_oSHllar, /* LSL or ASR immediate */
7156 OP_oROR, /* ROR 0/8/16/24 */
7157 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
7159 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7161 /* Some pre-defined mixed (ARM/THUMB) operands. */
7162 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7163 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7164 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7166 OP_FIRST_OPTIONAL = OP_oI7b
7169 /* Generic instruction operand parser. This does no encoding and no
7170 semantic validation; it merely squirrels values away in the inst
7171 structure. Returns SUCCESS or FAIL depending on whether the
7172 specified grammar matched. */
7173 static int
7174 parse_operands (char *str, const unsigned int *pattern, bool thumb)
7176 unsigned const int *upat = pattern;
7177 char *backtrack_pos = 0;
7178 const char *backtrack_error = 0;
7179 int i, val = 0, backtrack_index = 0;
7180 enum arm_reg_type rtype;
7181 parse_operand_result result;
7182 unsigned int op_parse_code;
7183 bool partial_match;
7185 #define po_char_or_fail(chr) \
7186 do \
7188 if (skip_past_char (&str, chr) == FAIL) \
7189 goto bad_args; \
7191 while (0)
7193 #define po_reg_or_fail(regtype) \
7194 do \
7196 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7197 & inst.operands[i].vectype); \
7198 if (val == FAIL) \
7200 first_error (_(reg_expected_msgs[regtype])); \
7201 goto failure; \
7203 inst.operands[i].reg = val; \
7204 inst.operands[i].isreg = 1; \
7205 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7206 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7207 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7208 || rtype == REG_TYPE_VFD \
7209 || rtype == REG_TYPE_NQ); \
7210 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7212 while (0)
7214 #define po_reg_or_goto(regtype, label) \
7215 do \
7217 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7218 & inst.operands[i].vectype); \
7219 if (val == FAIL) \
7220 goto label; \
7222 inst.operands[i].reg = val; \
7223 inst.operands[i].isreg = 1; \
7224 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7225 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7226 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7227 || rtype == REG_TYPE_VFD \
7228 || rtype == REG_TYPE_NQ); \
7229 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7231 while (0)
7233 #define po_imm_or_fail(min, max, popt) \
7234 do \
7236 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7237 goto failure; \
7238 inst.operands[i].imm = val; \
7240 while (0)
7242 #define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7243 do \
7245 expressionS exp; \
7246 my_get_expression (&exp, &str, popt); \
7247 if (exp.X_op != O_constant) \
7249 inst.error = _("constant expression required"); \
7250 goto failure; \
7252 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7254 inst.error = _("immediate value 48 or 64 expected"); \
7255 goto failure; \
7257 inst.operands[i].imm = exp.X_add_number; \
7259 while (0)
7261 #define po_scalar_or_goto(elsz, label, reg_type) \
7262 do \
7264 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7265 reg_type); \
7266 if (val == FAIL) \
7267 goto label; \
7268 inst.operands[i].reg = val; \
7269 inst.operands[i].isscalar = 1; \
7271 while (0)
7273 #define po_misc_or_fail(expr) \
7274 do \
7276 if (expr) \
7277 goto failure; \
7279 while (0)
7281 #define po_misc_or_fail_no_backtrack(expr) \
7282 do \
7284 result = expr; \
7285 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7286 backtrack_pos = 0; \
7287 if (result != PARSE_OPERAND_SUCCESS) \
7288 goto failure; \
7290 while (0)
7292 #define po_barrier_or_imm(str) \
7293 do \
7295 val = parse_barrier (&str); \
7296 if (val == FAIL && ! ISALPHA (*str)) \
7297 goto immediate; \
7298 if (val == FAIL \
7299 /* ISB can only take SY as an option. */ \
7300 || ((inst.instruction & 0xf0) == 0x60 \
7301 && val != 0xf)) \
7303 inst.error = _("invalid barrier type"); \
7304 backtrack_pos = 0; \
7305 goto failure; \
7308 while (0)
7310 skip_whitespace (str);
7312 for (i = 0; upat[i] != OP_stop; i++)
7314 op_parse_code = upat[i];
7315 if (op_parse_code >= 1<<16)
7316 op_parse_code = thumb ? (op_parse_code >> 16)
7317 : (op_parse_code & ((1<<16)-1));
7319 if (op_parse_code >= OP_FIRST_OPTIONAL)
7321 /* Remember where we are in case we need to backtrack. */
7322 backtrack_pos = str;
7323 backtrack_error = inst.error;
7324 backtrack_index = i;
7327 if (i > 0 && (i > 1 || inst.operands[0].present))
7328 po_char_or_fail (',');
7330 switch (op_parse_code)
7332 /* Registers */
7333 case OP_oRRnpc:
7334 case OP_oRRnpcsp:
7335 case OP_RRnpc:
7336 case OP_RRnpcsp:
7337 case OP_oRR:
7338 case OP_RRe:
7339 case OP_RRo:
7340 case OP_LR:
7341 case OP_oLR:
7342 case OP_SP:
7343 case OP_R12:
7344 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7345 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7346 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7347 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7348 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
7349 case OP_oRND:
7350 case OP_RNSDMQR:
7351 po_reg_or_goto (REG_TYPE_VFS, try_rndmqr);
7352 break;
7353 try_rndmqr:
7354 case OP_RNDMQR:
7355 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7356 break;
7357 try_rndmq:
7358 case OP_RNDMQ:
7359 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7360 break;
7361 try_rnd:
7362 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
7363 case OP_RVC:
7364 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7365 break;
7366 /* Also accept generic coprocessor regs for unknown registers. */
7367 coproc_reg:
7368 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7369 break;
7370 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7371 existing register with a value of 0, this seems like the
7372 best way to parse P0. */
7373 vpr_po:
7374 if (strncasecmp (str, "P0", 2) == 0)
7376 str += 2;
7377 inst.operands[i].isreg = 1;
7378 inst.operands[i].reg = 13;
7380 else
7381 goto failure;
7382 break;
7383 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7384 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7385 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7386 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
7387 case OP_oRNQ:
7388 case OP_RNQMQ:
7389 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7390 break;
7391 try_nq:
7392 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
7393 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7394 case OP_RNDQMQR:
7395 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7396 break;
7397 try_rndqmq:
7398 case OP_oRNDQMQ:
7399 case OP_RNDQMQ:
7400 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7401 break;
7402 try_rndq:
7403 case OP_oRNDQ:
7404 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
7405 case OP_RVSDMQ:
7406 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7407 break;
7408 try_rvsd:
7409 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7410 case OP_RVSD_COND:
7411 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7412 break;
7413 case OP_oRNSDMQ:
7414 case OP_RNSDMQ:
7415 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7416 break;
7417 try_mq2:
7418 po_reg_or_fail (REG_TYPE_MQ);
7419 break;
7420 case OP_oRNSDQ:
7421 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
7422 case OP_RNSDQMQR:
7423 po_reg_or_goto (REG_TYPE_RN, try_mq);
7424 break;
7425 try_mq:
7426 case OP_oRNSDQMQ:
7427 case OP_RNSDQMQ:
7428 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7429 break;
7430 try_nsdq2:
7431 po_reg_or_fail (REG_TYPE_NSDQ);
7432 inst.error = 0;
7433 break;
7434 case OP_RMQRR:
7435 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7436 break;
7437 try_rmq:
7438 case OP_RMQ:
7439 po_reg_or_fail (REG_TYPE_MQ);
7440 break;
7441 /* Neon scalar. Using an element size of 8 means that some invalid
7442 scalars are accepted here, so deal with those in later code. */
7443 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
7445 case OP_RNDQ_I0:
7447 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7448 break;
7449 try_imm0:
7450 po_imm_or_fail (0, 0, true);
7452 break;
7454 case OP_RVSD_I0:
7455 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7456 break;
7458 case OP_RSVDMQ_FI0:
7459 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7460 break;
7461 try_rsvd_fi0:
7462 case OP_RSVD_FI0:
7464 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7465 break;
7466 try_ifimm0:
7467 if (parse_ifimm_zero (&str))
7468 inst.operands[i].imm = 0;
7469 else
7471 inst.error
7472 = _("only floating point zero is allowed as immediate value");
7473 goto failure;
7476 break;
7478 case OP_RR_RNSC:
7480 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
7481 break;
7482 try_rr:
7483 po_reg_or_fail (REG_TYPE_RN);
7485 break;
7487 case OP_RNSDQ_RNSC_MQ_RR:
7488 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7489 break;
7490 try_rnsdq_rnsc_mq:
7491 case OP_RNSDQ_RNSC_MQ:
7492 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7493 break;
7494 try_rnsdq_rnsc:
7495 case OP_RNSDQ_RNSC:
7497 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7498 inst.error = 0;
7499 break;
7500 try_nsdq:
7501 po_reg_or_fail (REG_TYPE_NSDQ);
7502 inst.error = 0;
7504 break;
7506 case OP_RNSD_RNSC:
7508 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
7509 break;
7510 try_s_scalar:
7511 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
7512 break;
7513 try_nsd:
7514 po_reg_or_fail (REG_TYPE_NSD);
7516 break;
7518 case OP_RNDQMQ_RNSC_RR:
7519 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7520 break;
7521 try_rndq_rnsc_rr:
7522 case OP_RNDQ_RNSC_RR:
7523 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7524 break;
7525 case OP_RNDQMQ_RNSC:
7526 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7527 break;
7528 try_rndq_rnsc:
7529 case OP_RNDQ_RNSC:
7531 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
7532 break;
7533 try_ndq:
7534 po_reg_or_fail (REG_TYPE_NDQ);
7536 break;
7538 case OP_RND_RNSC:
7540 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
7541 break;
7542 try_vfd:
7543 po_reg_or_fail (REG_TYPE_VFD);
7545 break;
7547 case OP_VMOV:
7548 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7549 not careful then bad things might happen. */
7550 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7551 break;
7553 case OP_RNDQMQ_Ibig:
7554 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7555 break;
7556 try_rndq_ibig:
7557 case OP_RNDQ_Ibig:
7559 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7560 break;
7561 try_immbig:
7562 /* There's a possibility of getting a 64-bit immediate here, so
7563 we need special handling. */
7564 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/false)
7565 == FAIL)
7567 inst.error = _("immediate value is out of range");
7568 goto failure;
7571 break;
7573 case OP_RNDQMQ_I63b_RR:
7574 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7575 break;
7576 try_rndq_i63b_rr:
7577 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7578 break;
7579 try_rndq_i63b:
7580 case OP_RNDQ_I63b:
7582 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7583 break;
7584 try_shimm:
7585 po_imm_or_fail (0, 63, true);
7587 break;
7589 case OP_RRnpcb:
7590 po_char_or_fail ('[');
7591 po_reg_or_fail (REG_TYPE_RN);
7592 po_char_or_fail (']');
7593 break;
7595 case OP_RRnpctw:
7596 case OP_RRw:
7597 case OP_oRRw:
7598 po_reg_or_fail (REG_TYPE_RN);
7599 if (skip_past_char (&str, '!') == SUCCESS)
7600 inst.operands[i].writeback = 1;
7601 break;
7603 /* Immediates */
7604 case OP_I7: po_imm_or_fail ( 0, 7, false); break;
7605 case OP_I15: po_imm_or_fail ( 0, 15, false); break;
7606 case OP_I16: po_imm_or_fail ( 1, 16, false); break;
7607 case OP_I16z: po_imm_or_fail ( 0, 16, false); break;
7608 case OP_I31: po_imm_or_fail ( 0, 31, false); break;
7609 case OP_I32: po_imm_or_fail ( 1, 32, false); break;
7610 case OP_I32z: po_imm_or_fail ( 0, 32, false); break;
7611 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, false); break;
7612 case OP_I63s: po_imm_or_fail (-64, 63, false); break;
7613 case OP_I63: po_imm_or_fail ( 0, 63, false); break;
7614 case OP_I64: po_imm_or_fail ( 1, 64, false); break;
7615 case OP_I64z: po_imm_or_fail ( 0, 64, false); break;
7616 case OP_I127: po_imm_or_fail ( 0, 127, false); break;
7617 case OP_I255: po_imm_or_fail ( 0, 255, false); break;
7618 case OP_I511: po_imm_or_fail ( 0, 511, false); break;
7619 case OP_I4095: po_imm_or_fail ( 0, 4095, false); break;
7620 case OP_I8191: po_imm_or_fail ( 0, 8191, false); break;
7621 case OP_I4b: po_imm_or_fail ( 1, 4, true); break;
7622 case OP_oI7b:
7623 case OP_I7b: po_imm_or_fail ( 0, 7, true); break;
7624 case OP_I15b: po_imm_or_fail ( 0, 15, true); break;
7625 case OP_oI31b:
7626 case OP_I31b: po_imm_or_fail ( 0, 31, true); break;
7627 case OP_oI32b: po_imm_or_fail ( 1, 32, true); break;
7628 case OP_oI32z: po_imm_or_fail ( 0, 32, true); break;
7629 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, true); break;
7631 /* Immediate variants */
7632 case OP_oI255c:
7633 po_char_or_fail ('{');
7634 po_imm_or_fail (0, 255, true);
7635 po_char_or_fail ('}');
7636 break;
7638 case OP_I31w:
7639 /* The expression parser chokes on a trailing !, so we have
7640 to find it first and zap it. */
7642 char *s = str;
7643 while (*s && *s != ',')
7644 s++;
7645 if (s[-1] == '!')
7647 s[-1] = '\0';
7648 inst.operands[i].writeback = 1;
7650 po_imm_or_fail (0, 31, true);
7651 if (str == s - 1)
7652 str = s;
7654 break;
7656 /* Expressions */
7657 case OP_EXPi: EXPi:
7658 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7659 GE_OPT_PREFIX));
7660 break;
7662 case OP_EXP:
7663 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7664 GE_NO_PREFIX));
7665 break;
7667 case OP_EXPr: EXPr:
7668 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7669 GE_NO_PREFIX));
7670 if (inst.relocs[0].exp.X_op == O_symbol)
7672 val = parse_reloc (&str);
7673 if (val == -1)
7675 inst.error = _("unrecognized relocation suffix");
7676 goto failure;
7678 else if (val != BFD_RELOC_UNUSED)
7680 inst.operands[i].imm = val;
7681 inst.operands[i].hasreloc = 1;
7684 break;
7686 case OP_EXPs:
7687 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7688 GE_NO_PREFIX));
7689 if (inst.relocs[i].exp.X_op == O_symbol)
7691 inst.operands[i].hasreloc = 1;
7693 else if (inst.relocs[i].exp.X_op == O_constant)
7695 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7696 inst.operands[i].hasreloc = 0;
7698 break;
7700 /* Operand for MOVW or MOVT. */
7701 case OP_HALF:
7702 po_misc_or_fail (parse_half (&str));
7703 break;
7705 /* Register or expression. */
7706 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7707 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7709 /* Register or immediate. */
7710 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7711 I0: po_imm_or_fail (0, 0, false); break;
7713 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7714 I32: po_imm_or_fail (1, 32, false); break;
7716 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7717 I32z: po_imm_or_fail (0, 32, false); break;
7719 /* Two kinds of register. */
7720 case OP_RIWR_RIWC:
7722 struct reg_entry *rege = arm_reg_parse_multi (&str);
7723 if (!rege
7724 || (rege->type != REG_TYPE_MMXWR
7725 && rege->type != REG_TYPE_MMXWC
7726 && rege->type != REG_TYPE_MMXWCG))
7728 inst.error = _("iWMMXt data or control register expected");
7729 goto failure;
7731 inst.operands[i].reg = rege->number;
7732 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7734 break;
7736 case OP_RIWC_RIWG:
7738 struct reg_entry *rege = arm_reg_parse_multi (&str);
7739 if (!rege
7740 || (rege->type != REG_TYPE_MMXWC
7741 && rege->type != REG_TYPE_MMXWCG))
7743 inst.error = _("iWMMXt control register expected");
7744 goto failure;
7746 inst.operands[i].reg = rege->number;
7747 inst.operands[i].isreg = 1;
7749 break;
7751 /* Misc */
7752 case OP_CPSF: val = parse_cps_flags (&str); break;
7753 case OP_ENDI: val = parse_endian_specifier (&str); break;
7754 case OP_oROR: val = parse_ror (&str); break;
7755 try_cond:
7756 case OP_COND: val = parse_cond (&str); break;
7757 case OP_oBARRIER_I15:
7758 po_barrier_or_imm (str); break;
7759 immediate:
7760 if (parse_immediate (&str, &val, 0, 15, true) == FAIL)
7761 goto failure;
7762 break;
7764 case OP_wPSR:
7765 case OP_rPSR:
7766 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7767 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7769 inst.error = _("Banked registers are not available with this "
7770 "architecture.");
7771 goto failure;
7773 break;
7774 try_psr:
7775 val = parse_psr (&str, op_parse_code == OP_wPSR);
7776 break;
7778 case OP_VLDR:
7779 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7780 break;
7781 try_sysreg:
7782 val = parse_sys_vldr_vstr (&str);
7783 break;
7785 case OP_APSR_RR:
7786 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7787 break;
7788 try_apsr:
7789 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7790 instruction). */
7791 if (strncasecmp (str, "APSR_", 5) == 0)
7793 unsigned found = 0;
7794 str += 5;
7795 while (found < 15)
7796 switch (*str++)
7798 case 'c': found = (found & 1) ? 16 : found | 1; break;
7799 case 'n': found = (found & 2) ? 16 : found | 2; break;
7800 case 'z': found = (found & 4) ? 16 : found | 4; break;
7801 case 'v': found = (found & 8) ? 16 : found | 8; break;
7802 default: found = 16;
7804 if (found != 15)
7805 goto failure;
7806 inst.operands[i].isvec = 1;
7807 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7808 inst.operands[i].reg = REG_PC;
7810 else
7811 goto failure;
7812 break;
7814 case OP_TB:
7815 po_misc_or_fail (parse_tb (&str));
7816 break;
7818 /* Register lists. */
7819 case OP_REGLST:
7820 val = parse_reg_list (&str, REGLIST_RN);
7821 if (*str == '^')
7823 inst.operands[i].writeback = 1;
7824 str++;
7826 break;
7828 case OP_CLRMLST:
7829 val = parse_reg_list (&str, REGLIST_CLRM);
7830 break;
7832 case OP_VRSLST:
7833 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7834 &partial_match);
7835 break;
7837 case OP_VRDLST:
7838 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7839 &partial_match);
7840 break;
7842 case OP_VRSDLST:
7843 /* Allow Q registers too. */
7844 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7845 REGLIST_NEON_D, &partial_match);
7846 if (val == FAIL)
7848 inst.error = NULL;
7849 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7850 REGLIST_VFP_S, &partial_match);
7851 inst.operands[i].issingle = 1;
7853 break;
7855 case OP_VRSDVLST:
7856 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7857 REGLIST_VFP_D_VPR, &partial_match);
7858 if (val == FAIL && !partial_match)
7860 inst.error = NULL;
7861 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7862 REGLIST_VFP_S_VPR, &partial_match);
7863 inst.operands[i].issingle = 1;
7865 break;
7867 case OP_NRDLST:
7868 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7869 REGLIST_NEON_D, &partial_match);
7870 break;
7872 case OP_MSTRLST4:
7873 case OP_MSTRLST2:
7874 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7875 1, &inst.operands[i].vectype);
7876 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7877 goto failure;
7878 break;
7879 case OP_NSTRLST:
7880 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7881 0, &inst.operands[i].vectype);
7882 break;
7884 /* Addressing modes */
7885 case OP_ADDRMVE:
7886 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7887 break;
7889 case OP_ADDR:
7890 po_misc_or_fail (parse_address (&str, i));
7891 break;
7893 case OP_ADDRGLDR:
7894 po_misc_or_fail_no_backtrack (
7895 parse_address_group_reloc (&str, i, GROUP_LDR));
7896 break;
7898 case OP_ADDRGLDRS:
7899 po_misc_or_fail_no_backtrack (
7900 parse_address_group_reloc (&str, i, GROUP_LDRS));
7901 break;
7903 case OP_ADDRGLDC:
7904 po_misc_or_fail_no_backtrack (
7905 parse_address_group_reloc (&str, i, GROUP_LDC));
7906 break;
7908 case OP_SH:
7909 po_misc_or_fail (parse_shifter_operand (&str, i));
7910 break;
7912 case OP_SHG:
7913 po_misc_or_fail_no_backtrack (
7914 parse_shifter_operand_group_reloc (&str, i));
7915 break;
7917 case OP_oSHll:
7918 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7919 break;
7921 case OP_oSHar:
7922 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7923 break;
7925 case OP_oSHllar:
7926 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7927 break;
7929 case OP_RMQRZ:
7930 case OP_oRMQRZ:
7931 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
7932 break;
7934 case OP_RR_ZR:
7935 try_rr_zr:
7936 po_reg_or_goto (REG_TYPE_RN, ZR);
7937 break;
7939 po_reg_or_fail (REG_TYPE_ZR);
7940 break;
7942 default:
7943 as_fatal (_("unhandled operand code %d"), op_parse_code);
7946 /* Various value-based sanity checks and shared operations. We
7947 do not signal immediate failures for the register constraints;
7948 this allows a syntax error to take precedence. */
7949 switch (op_parse_code)
7951 case OP_oRRnpc:
7952 case OP_RRnpc:
7953 case OP_RRnpcb:
7954 case OP_RRw:
7955 case OP_oRRw:
7956 case OP_RRnpc_I0:
7957 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7958 inst.error = BAD_PC;
7959 break;
7961 case OP_oRRnpcsp:
7962 case OP_RRnpcsp:
7963 case OP_RRnpcsp_I32:
7964 if (inst.operands[i].isreg)
7966 if (inst.operands[i].reg == REG_PC)
7967 inst.error = BAD_PC;
7968 else if (inst.operands[i].reg == REG_SP
7969 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7970 relaxed since ARMv8-A. */
7971 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7973 gas_assert (thumb);
7974 inst.error = BAD_SP;
7977 break;
7979 case OP_RRnpctw:
7980 if (inst.operands[i].isreg
7981 && inst.operands[i].reg == REG_PC
7982 && (inst.operands[i].writeback || thumb))
7983 inst.error = BAD_PC;
7984 break;
7986 case OP_RVSD_COND:
7987 case OP_VLDR:
7988 if (inst.operands[i].isreg)
7989 break;
7990 /* fall through. */
7992 case OP_CPSF:
7993 case OP_ENDI:
7994 case OP_oROR:
7995 case OP_wPSR:
7996 case OP_rPSR:
7997 case OP_COND:
7998 case OP_oBARRIER_I15:
7999 case OP_REGLST:
8000 case OP_CLRMLST:
8001 case OP_VRSLST:
8002 case OP_VRDLST:
8003 case OP_VRSDLST:
8004 case OP_VRSDVLST:
8005 case OP_NRDLST:
8006 case OP_NSTRLST:
8007 case OP_MSTRLST2:
8008 case OP_MSTRLST4:
8009 if (val == FAIL)
8010 goto failure;
8011 inst.operands[i].imm = val;
8012 break;
8014 case OP_LR:
8015 case OP_oLR:
8016 if (inst.operands[i].reg != REG_LR)
8017 inst.error = _("operand must be LR register");
8018 break;
8020 case OP_SP:
8021 if (inst.operands[i].reg != REG_SP)
8022 inst.error = _("operand must be SP register");
8023 break;
8025 case OP_R12:
8026 if (inst.operands[i].reg != REG_R12)
8027 inst.error = _("operand must be r12");
8028 break;
8030 case OP_RMQRZ:
8031 case OP_oRMQRZ:
8032 case OP_RR_ZR:
8033 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8034 inst.error = BAD_PC;
8035 break;
8037 case OP_RRe:
8038 if (inst.operands[i].isreg
8039 && (inst.operands[i].reg & 0x00000001) != 0)
8040 inst.error = BAD_ODD;
8041 break;
8043 case OP_RRo:
8044 if (inst.operands[i].isreg)
8046 if ((inst.operands[i].reg & 0x00000001) != 1)
8047 inst.error = BAD_EVEN;
8048 else if (inst.operands[i].reg == REG_SP)
8049 as_tsktsk (MVE_BAD_SP);
8050 else if (inst.operands[i].reg == REG_PC)
8051 inst.error = BAD_PC;
8053 break;
8055 default:
8056 break;
8059 /* If we get here, this operand was successfully parsed. */
8060 inst.operands[i].present = 1;
8061 continue;
8063 bad_args:
8064 inst.error = BAD_ARGS;
8066 failure:
8067 if (!backtrack_pos)
8069 /* The parse routine should already have set inst.error, but set a
8070 default here just in case. */
8071 if (!inst.error)
8072 inst.error = BAD_SYNTAX;
8073 return FAIL;
8076 /* Do not backtrack over a trailing optional argument that
8077 absorbed some text. We will only fail again, with the
8078 'garbage following instruction' error message, which is
8079 probably less helpful than the current one. */
8080 if (backtrack_index == i && backtrack_pos != str
8081 && upat[i+1] == OP_stop)
8083 if (!inst.error)
8084 inst.error = BAD_SYNTAX;
8085 return FAIL;
8088 /* Try again, skipping the optional argument at backtrack_pos. */
8089 str = backtrack_pos;
8090 inst.error = backtrack_error;
8091 inst.operands[backtrack_index].present = 0;
8092 i = backtrack_index;
8093 backtrack_pos = 0;
8096 /* Check that we have parsed all the arguments. */
8097 if (*str != '\0' && !inst.error)
8098 inst.error = _("garbage following instruction");
8100 return inst.error ? FAIL : SUCCESS;
8103 #undef po_char_or_fail
8104 #undef po_reg_or_fail
8105 #undef po_reg_or_goto
8106 #undef po_imm_or_fail
8107 #undef po_scalar_or_fail
8108 #undef po_barrier_or_imm
8110 /* Shorthand macro for instruction encoding functions issuing errors. */
8111 #define constraint(expr, err) \
8112 do \
8114 if (expr) \
8116 inst.error = err; \
8117 return; \
8120 while (0)
8122 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8123 instructions are unpredictable if these registers are used. This
8124 is the BadReg predicate in ARM's Thumb-2 documentation.
8126 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8127 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8128 #define reject_bad_reg(reg) \
8129 do \
8130 if (reg == REG_PC) \
8132 inst.error = BAD_PC; \
8133 return; \
8135 else if (reg == REG_SP \
8136 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8138 inst.error = BAD_SP; \
8139 return; \
8141 while (0)
8143 /* If REG is R13 (the stack pointer), warn that its use is
8144 deprecated. */
8145 #define warn_deprecated_sp(reg) \
8146 do \
8147 if (warn_on_deprecated && reg == REG_SP) \
8148 as_tsktsk (_("use of r13 is deprecated")); \
8149 while (0)
8151 /* Functions for operand encoding. ARM, then Thumb. */
8153 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
8155 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8157 The only binary encoding difference is the Coprocessor number. Coprocessor
8158 9 is used for half-precision calculations or conversions. The format of the
8159 instruction is the same as the equivalent Coprocessor 10 instruction that
8160 exists for Single-Precision operation. */
8162 static void
8163 do_scalar_fp16_v82_encode (void)
8165 if (inst.cond < COND_ALWAYS)
8166 as_warn (_("scalar fp16 instruction cannot be conditional,"
8167 " the behaviour is UNPREDICTABLE"));
8168 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8169 _(BAD_FP16));
8171 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8172 mark_feature_used (&arm_ext_fp16);
8175 /* If VAL can be encoded in the immediate field of an ARM instruction,
8176 return the encoded form. Otherwise, return FAIL. */
8178 static unsigned int
8179 encode_arm_immediate (unsigned int val)
8181 unsigned int a, i;
8183 if (val <= 0xff)
8184 return val;
8186 for (i = 2; i < 32; i += 2)
8187 if ((a = rotate_left (val, i)) <= 0xff)
8188 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8190 return FAIL;
8193 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8194 return the encoded form. Otherwise, return FAIL. */
8195 static unsigned int
8196 encode_thumb32_immediate (unsigned int val)
8198 unsigned int a, i;
8200 if (val <= 0xff)
8201 return val;
8203 for (i = 1; i <= 24; i++)
8205 a = val >> i;
8206 if ((val & ~(0xffU << i)) == 0)
8207 return ((val >> i) & 0x7f) | ((32 - i) << 7);
8210 a = val & 0xff;
8211 if (val == ((a << 16) | a))
8212 return 0x100 | a;
8213 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8214 return 0x300 | a;
8216 a = val & 0xff00;
8217 if (val == ((a << 16) | a))
8218 return 0x200 | (a >> 8);
8220 return FAIL;
8222 /* Encode a VFP SP or DP register number into inst.instruction. */
8224 static void
8225 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8227 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8228 && reg > 15)
8230 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
8232 if (thumb_mode)
8233 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8234 fpu_vfp_ext_d32);
8235 else
8236 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8237 fpu_vfp_ext_d32);
8239 else
8241 first_error (_("D register out of range for selected VFP version"));
8242 return;
8246 switch (pos)
8248 case VFP_REG_Sd:
8249 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8250 break;
8252 case VFP_REG_Sn:
8253 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8254 break;
8256 case VFP_REG_Sm:
8257 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8258 break;
8260 case VFP_REG_Dd:
8261 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8262 break;
8264 case VFP_REG_Dn:
8265 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8266 break;
8268 case VFP_REG_Dm:
8269 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8270 break;
8272 default:
8273 abort ();
8277 /* Encode a <shift> in an ARM-format instruction. The immediate,
8278 if any, is handled by md_apply_fix. */
8279 static void
8280 encode_arm_shift (int i)
8282 /* register-shifted register. */
8283 if (inst.operands[i].immisreg)
8285 int op_index;
8286 for (op_index = 0; op_index <= i; ++op_index)
8288 /* Check the operand only when it's presented. In pre-UAL syntax,
8289 if the destination register is the same as the first operand, two
8290 register form of the instruction can be used. */
8291 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8292 && inst.operands[op_index].reg == REG_PC)
8293 as_warn (UNPRED_REG ("r15"));
8296 if (inst.operands[i].imm == REG_PC)
8297 as_warn (UNPRED_REG ("r15"));
8300 if (inst.operands[i].shift_kind == SHIFT_RRX)
8301 inst.instruction |= SHIFT_ROR << 5;
8302 else
8304 inst.instruction |= inst.operands[i].shift_kind << 5;
8305 if (inst.operands[i].immisreg)
8307 inst.instruction |= SHIFT_BY_REG;
8308 inst.instruction |= inst.operands[i].imm << 8;
8310 else
8311 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8315 static void
8316 encode_arm_shifter_operand (int i)
8318 if (inst.operands[i].isreg)
8320 inst.instruction |= inst.operands[i].reg;
8321 encode_arm_shift (i);
8323 else
8325 inst.instruction |= INST_IMMEDIATE;
8326 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
8327 inst.instruction |= inst.operands[i].imm;
8331 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
8332 static void
8333 encode_arm_addr_mode_common (int i, bool is_t)
8335 /* PR 14260:
8336 Generate an error if the operand is not a register. */
8337 constraint (!inst.operands[i].isreg,
8338 _("Instruction does not support =N addresses"));
8340 inst.instruction |= inst.operands[i].reg << 16;
8342 if (inst.operands[i].preind)
8344 if (is_t)
8346 inst.error = _("instruction does not accept preindexed addressing");
8347 return;
8349 inst.instruction |= PRE_INDEX;
8350 if (inst.operands[i].writeback)
8351 inst.instruction |= WRITE_BACK;
8354 else if (inst.operands[i].postind)
8356 gas_assert (inst.operands[i].writeback);
8357 if (is_t)
8358 inst.instruction |= WRITE_BACK;
8360 else /* unindexed - only for coprocessor */
8362 inst.error = _("instruction does not accept unindexed addressing");
8363 return;
8366 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8367 && (((inst.instruction & 0x000f0000) >> 16)
8368 == ((inst.instruction & 0x0000f000) >> 12)))
8369 as_warn ((inst.instruction & LOAD_BIT)
8370 ? _("destination register same as write-back base")
8371 : _("source register same as write-back base"));
8374 /* inst.operands[i] was set up by parse_address. Encode it into an
8375 ARM-format mode 2 load or store instruction. If is_t is true,
8376 reject forms that cannot be used with a T instruction (i.e. not
8377 post-indexed). */
8378 static void
8379 encode_arm_addr_mode_2 (int i, bool is_t)
8381 const bool is_pc = (inst.operands[i].reg == REG_PC);
8383 encode_arm_addr_mode_common (i, is_t);
8385 if (inst.operands[i].immisreg)
8387 constraint ((inst.operands[i].imm == REG_PC
8388 || (is_pc && inst.operands[i].writeback)),
8389 BAD_PC_ADDRESSING);
8390 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8391 inst.instruction |= inst.operands[i].imm;
8392 if (!inst.operands[i].negative)
8393 inst.instruction |= INDEX_UP;
8394 if (inst.operands[i].shifted)
8396 if (inst.operands[i].shift_kind == SHIFT_RRX)
8397 inst.instruction |= SHIFT_ROR << 5;
8398 else
8400 inst.instruction |= inst.operands[i].shift_kind << 5;
8401 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8405 else /* immediate offset in inst.relocs[0] */
8407 if (is_pc && !inst.relocs[0].pc_rel)
8409 const bool is_load = ((inst.instruction & LOAD_BIT) != 0);
8411 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8412 cannot use PC in addressing.
8413 PC cannot be used in writeback addressing, either. */
8414 constraint ((is_t || inst.operands[i].writeback),
8415 BAD_PC_ADDRESSING);
8417 /* Use of PC in str is deprecated for ARMv7. */
8418 if (warn_on_deprecated
8419 && !is_load
8420 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
8421 as_tsktsk (_("use of PC in this instruction is deprecated"));
8424 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8426 /* Prefer + for zero encoded value. */
8427 if (!inst.operands[i].negative)
8428 inst.instruction |= INDEX_UP;
8429 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
8434 /* inst.operands[i] was set up by parse_address. Encode it into an
8435 ARM-format mode 3 load or store instruction. Reject forms that
8436 cannot be used with such instructions. If is_t is true, reject
8437 forms that cannot be used with a T instruction (i.e. not
8438 post-indexed). */
8439 static void
8440 encode_arm_addr_mode_3 (int i, bool is_t)
8442 if (inst.operands[i].immisreg && inst.operands[i].shifted)
8444 inst.error = _("instruction does not accept scaled register index");
8445 return;
8448 encode_arm_addr_mode_common (i, is_t);
8450 if (inst.operands[i].immisreg)
8452 constraint ((inst.operands[i].imm == REG_PC
8453 || (is_t && inst.operands[i].reg == REG_PC)),
8454 BAD_PC_ADDRESSING);
8455 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8456 BAD_PC_WRITEBACK);
8457 inst.instruction |= inst.operands[i].imm;
8458 if (!inst.operands[i].negative)
8459 inst.instruction |= INDEX_UP;
8461 else /* immediate offset in inst.relocs[0] */
8463 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
8464 && inst.operands[i].writeback),
8465 BAD_PC_WRITEBACK);
8466 inst.instruction |= HWOFFSET_IMM;
8467 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8469 /* Prefer + for zero encoded value. */
8470 if (!inst.operands[i].negative)
8471 inst.instruction |= INDEX_UP;
8473 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
8478 /* Write immediate bits [7:0] to the following locations:
8480 |28/24|23 19|18 16|15 4|3 0|
8481 | 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|
8483 This function is used by VMOV/VMVN/VORR/VBIC. */
8485 static void
8486 neon_write_immbits (unsigned immbits)
8488 inst.instruction |= immbits & 0xf;
8489 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8490 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8493 /* Invert low-order SIZE bits of XHI:XLO. */
8495 static void
8496 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8498 unsigned immlo = xlo ? *xlo : 0;
8499 unsigned immhi = xhi ? *xhi : 0;
8501 switch (size)
8503 case 8:
8504 immlo = (~immlo) & 0xff;
8505 break;
8507 case 16:
8508 immlo = (~immlo) & 0xffff;
8509 break;
8511 case 64:
8512 immhi = (~immhi) & 0xffffffff;
8513 /* fall through. */
8515 case 32:
8516 immlo = (~immlo) & 0xffffffff;
8517 break;
8519 default:
8520 abort ();
8523 if (xlo)
8524 *xlo = immlo;
8526 if (xhi)
8527 *xhi = immhi;
8530 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8531 A, B, C, D. */
8533 static int
8534 neon_bits_same_in_bytes (unsigned imm)
8536 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8537 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8538 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8539 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8542 /* For immediate of above form, return 0bABCD. */
8544 static unsigned
8545 neon_squash_bits (unsigned imm)
8547 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8548 | ((imm & 0x01000000) >> 21);
8551 /* Compress quarter-float representation to 0b...000 abcdefgh. */
8553 static unsigned
8554 neon_qfloat_bits (unsigned imm)
8556 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8559 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8560 the instruction. *OP is passed as the initial value of the op field, and
8561 may be set to a different value depending on the constant (i.e.
8562 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8563 MVN). If the immediate looks like a repeated pattern then also
8564 try smaller element sizes. */
8566 static int
8567 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8568 unsigned *immbits, int *op, int size,
8569 enum neon_el_type type)
8571 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8572 float. */
8573 if (type == NT_float && !float_p)
8574 return FAIL;
8576 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
8578 if (size != 32 || *op == 1)
8579 return FAIL;
8580 *immbits = neon_qfloat_bits (immlo);
8581 return 0xf;
8584 if (size == 64)
8586 if (neon_bits_same_in_bytes (immhi)
8587 && neon_bits_same_in_bytes (immlo))
8589 if (*op == 1)
8590 return FAIL;
8591 *immbits = (neon_squash_bits (immhi) << 4)
8592 | neon_squash_bits (immlo);
8593 *op = 1;
8594 return 0xe;
8597 if (immhi != immlo)
8598 return FAIL;
8601 if (size >= 32)
8603 if (immlo == (immlo & 0x000000ff))
8605 *immbits = immlo;
8606 return 0x0;
8608 else if (immlo == (immlo & 0x0000ff00))
8610 *immbits = immlo >> 8;
8611 return 0x2;
8613 else if (immlo == (immlo & 0x00ff0000))
8615 *immbits = immlo >> 16;
8616 return 0x4;
8618 else if (immlo == (immlo & 0xff000000))
8620 *immbits = immlo >> 24;
8621 return 0x6;
8623 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8625 *immbits = (immlo >> 8) & 0xff;
8626 return 0xc;
8628 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8630 *immbits = (immlo >> 16) & 0xff;
8631 return 0xd;
8634 if ((immlo & 0xffff) != (immlo >> 16))
8635 return FAIL;
8636 immlo &= 0xffff;
8639 if (size >= 16)
8641 if (immlo == (immlo & 0x000000ff))
8643 *immbits = immlo;
8644 return 0x8;
8646 else if (immlo == (immlo & 0x0000ff00))
8648 *immbits = immlo >> 8;
8649 return 0xa;
8652 if ((immlo & 0xff) != (immlo >> 8))
8653 return FAIL;
8654 immlo &= 0xff;
8657 if (immlo == (immlo & 0x000000ff))
8659 /* Don't allow MVN with 8-bit immediate. */
8660 if (*op == 1)
8661 return FAIL;
8662 *immbits = immlo;
8663 return 0xe;
8666 return FAIL;
8669 /* Returns TRUE if double precision value V may be cast
8670 to single precision without loss of accuracy. */
8672 static bool
8673 is_double_a_single (uint64_t v)
8675 int exp = (v >> 52) & 0x7FF;
8676 uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
8678 return ((exp == 0 || exp == 0x7FF
8679 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8680 && (mantissa & 0x1FFFFFFFL) == 0);
8683 /* Returns a double precision value casted to single precision
8684 (ignoring the least significant bits in exponent and mantissa). */
8686 static int
8687 double_to_single (uint64_t v)
8689 unsigned int sign = (v >> 63) & 1;
8690 int exp = (v >> 52) & 0x7FF;
8691 uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
8693 if (exp == 0x7FF)
8694 exp = 0xFF;
8695 else
8697 exp = exp - 1023 + 127;
8698 if (exp >= 0xFF)
8700 /* Infinity. */
8701 exp = 0x7F;
8702 mantissa = 0;
8704 else if (exp < 0)
8706 /* No denormalized numbers. */
8707 exp = 0;
8708 mantissa = 0;
8711 mantissa >>= 29;
8712 return (sign << 31) | (exp << 23) | mantissa;
8715 enum lit_type
8717 CONST_THUMB,
8718 CONST_ARM,
8719 CONST_VEC
8722 static void do_vfp_nsyn_opcode (const char *);
8724 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
8725 Determine whether it can be performed with a move instruction; if
8726 it can, convert inst.instruction to that move instruction and
8727 return true; if it can't, convert inst.instruction to a literal-pool
8728 load and return FALSE. If this is not a valid thing to do in the
8729 current context, set inst.error and return TRUE.
8731 inst.operands[i] describes the destination register. */
8733 static bool
8734 move_or_literal_pool (int i, enum lit_type t, bool mode_3)
8736 unsigned long tbit;
8737 bool thumb_p = (t == CONST_THUMB);
8738 bool arm_p = (t == CONST_ARM);
8740 if (thumb_p)
8741 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8742 else
8743 tbit = LOAD_BIT;
8745 if ((inst.instruction & tbit) == 0)
8747 inst.error = _("invalid pseudo operation");
8748 return true;
8751 if (inst.relocs[0].exp.X_op != O_constant
8752 && inst.relocs[0].exp.X_op != O_symbol
8753 && inst.relocs[0].exp.X_op != O_big)
8755 inst.error = _("constant expression expected");
8756 return true;
8759 if (inst.relocs[0].exp.X_op == O_constant
8760 || inst.relocs[0].exp.X_op == O_big)
8762 uint64_t v;
8763 if (inst.relocs[0].exp.X_op == O_big)
8765 LITTLENUM_TYPE *l;
8767 if (inst.relocs[0].exp.X_add_number <= 0) /* FP value. */
8769 /* FIXME: The code that was here previously could not
8770 work. Firstly, it tried to convert a floating point
8771 number into an extended precision format, but only
8772 provided a buffer of 5 littlenums, which was too
8773 small. Secondly, it then didn't deal with the value
8774 converted correctly, just reading out the first 4
8775 littlenum fields and assuming that could be used
8776 directly.
8778 I think the code was intended to handle expressions
8779 such as:
8781 LDR r0, =1.0
8782 VLDR d0, =55.3
8784 but the parsers currently don't permit floating-point
8785 literal values to be written this way, so this code
8786 is probably unreachable. To be safe, we simply
8787 return an error here. */
8789 inst.error = _("constant expression not supported");
8790 return true;
8792 else
8793 l = generic_bignum;
8795 v = l[3] & LITTLENUM_MASK;
8796 v <<= LITTLENUM_NUMBER_OF_BITS;
8797 v |= l[2] & LITTLENUM_MASK;
8798 v <<= LITTLENUM_NUMBER_OF_BITS;
8799 v |= l[1] & LITTLENUM_MASK;
8800 v <<= LITTLENUM_NUMBER_OF_BITS;
8801 v |= l[0] & LITTLENUM_MASK;
8803 else
8804 v = inst.relocs[0].exp.X_add_number;
8806 if (!inst.operands[i].issingle)
8808 if (thumb_p)
8810 /* LDR should not use lead in a flag-setting instruction being
8811 chosen so we do not check whether movs can be used. */
8813 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8814 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8815 && inst.operands[i].reg != 13
8816 && inst.operands[i].reg != 15)
8818 /* Check if on thumb2 it can be done with a mov.w, mvn or
8819 movw instruction. */
8820 unsigned int newimm;
8821 bool isNegated = false;
8823 newimm = encode_thumb32_immediate (v);
8824 if (newimm == (unsigned int) FAIL)
8826 newimm = encode_thumb32_immediate (~v);
8827 isNegated = true;
8830 /* The number can be loaded with a mov.w or mvn
8831 instruction. */
8832 if (newimm != (unsigned int) FAIL
8833 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8835 inst.instruction = (0xf04f0000 /* MOV.W. */
8836 | (inst.operands[i].reg << 8));
8837 /* Change to MOVN. */
8838 inst.instruction |= (isNegated ? 0x200000 : 0);
8839 inst.instruction |= (newimm & 0x800) << 15;
8840 inst.instruction |= (newimm & 0x700) << 4;
8841 inst.instruction |= (newimm & 0x0ff);
8842 return true;
8844 /* The number can be loaded with a movw instruction. */
8845 else if ((v & ~0xFFFF) == 0
8846 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8848 int imm = v & 0xFFFF;
8850 inst.instruction = 0xf2400000; /* MOVW. */
8851 inst.instruction |= (inst.operands[i].reg << 8);
8852 inst.instruction |= (imm & 0xf000) << 4;
8853 inst.instruction |= (imm & 0x0800) << 15;
8854 inst.instruction |= (imm & 0x0700) << 4;
8855 inst.instruction |= (imm & 0x00ff);
8856 /* In case this replacement is being done on Armv8-M
8857 Baseline we need to make sure to disable the
8858 instruction size check, as otherwise GAS will reject
8859 the use of this T32 instruction. */
8860 inst.size_req = 0;
8861 return true;
8865 else if (arm_p)
8867 int value = encode_arm_immediate (v);
8869 if (value != FAIL)
8871 /* This can be done with a mov instruction. */
8872 inst.instruction &= LITERAL_MASK;
8873 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8874 inst.instruction |= value & 0xfff;
8875 return true;
8878 value = encode_arm_immediate (~ v);
8879 if (value != FAIL)
8881 /* This can be done with a mvn instruction. */
8882 inst.instruction &= LITERAL_MASK;
8883 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8884 inst.instruction |= value & 0xfff;
8885 return true;
8888 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8890 int op = 0;
8891 unsigned immbits = 0;
8892 unsigned immlo = inst.operands[1].imm;
8893 unsigned immhi = inst.operands[1].regisimm
8894 ? inst.operands[1].reg
8895 : inst.relocs[0].exp.X_unsigned
8897 : (int64_t) (int) immlo >> 32;
8898 int cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits,
8899 &op, 64, NT_invtype);
8901 if (cmode == FAIL)
8903 neon_invert_size (&immlo, &immhi, 64);
8904 op = !op;
8905 cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits,
8906 &op, 64, NT_invtype);
8909 if (cmode != FAIL)
8911 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8912 | (1 << 23)
8913 | (cmode << 8)
8914 | (op << 5)
8915 | (1 << 4);
8917 /* Fill other bits in vmov encoding for both thumb and arm. */
8918 if (thumb_mode)
8919 inst.instruction |= (0x7U << 29) | (0xF << 24);
8920 else
8921 inst.instruction |= (0xFU << 28) | (0x1 << 25);
8922 neon_write_immbits (immbits);
8923 return true;
8928 if (t == CONST_VEC)
8930 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8931 if (inst.operands[i].issingle
8932 && is_quarter_float (inst.operands[1].imm)
8933 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8935 inst.operands[1].imm =
8936 neon_qfloat_bits (v);
8937 do_vfp_nsyn_opcode ("fconsts");
8938 return true;
8941 /* If our host does not support a 64-bit type then we cannot perform
8942 the following optimization. This mean that there will be a
8943 discrepancy between the output produced by an assembler built for
8944 a 32-bit-only host and the output produced from a 64-bit host, but
8945 this cannot be helped. */
8946 else if (!inst.operands[1].issingle
8947 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8949 if (is_double_a_single (v)
8950 && is_quarter_float (double_to_single (v)))
8952 inst.operands[1].imm =
8953 neon_qfloat_bits (double_to_single (v));
8954 do_vfp_nsyn_opcode ("fconstd");
8955 return true;
8961 if (add_to_lit_pool ((!inst.operands[i].isvec
8962 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8963 return true;
8965 inst.operands[1].reg = REG_PC;
8966 inst.operands[1].isreg = 1;
8967 inst.operands[1].preind = 1;
8968 inst.relocs[0].pc_rel = 1;
8969 inst.relocs[0].type = (thumb_p
8970 ? BFD_RELOC_ARM_THUMB_OFFSET
8971 : (mode_3
8972 ? BFD_RELOC_ARM_HWLITERAL
8973 : BFD_RELOC_ARM_LITERAL));
8974 return false;
8977 /* inst.operands[i] was set up by parse_address. Encode it into an
8978 ARM-format instruction. Reject all forms which cannot be encoded
8979 into a coprocessor load/store instruction. If wb_ok is false,
8980 reject use of writeback; if unind_ok is false, reject use of
8981 unindexed addressing. If reloc_override is not 0, use it instead
8982 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8983 (in which case it is preserved). */
8985 static int
8986 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8988 if (!inst.operands[i].isreg)
8990 /* PR 18256 */
8991 if (! inst.operands[0].isvec)
8993 inst.error = _("invalid co-processor operand");
8994 return FAIL;
8996 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/false))
8997 return SUCCESS;
9000 inst.instruction |= inst.operands[i].reg << 16;
9002 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9004 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9006 gas_assert (!inst.operands[i].writeback);
9007 if (!unind_ok)
9009 inst.error = _("instruction does not support unindexed addressing");
9010 return FAIL;
9012 inst.instruction |= inst.operands[i].imm;
9013 inst.instruction |= INDEX_UP;
9014 return SUCCESS;
9017 if (inst.operands[i].preind)
9018 inst.instruction |= PRE_INDEX;
9020 if (inst.operands[i].writeback)
9022 if (inst.operands[i].reg == REG_PC)
9024 inst.error = _("pc may not be used with write-back");
9025 return FAIL;
9027 if (!wb_ok)
9029 inst.error = _("instruction does not support writeback");
9030 return FAIL;
9032 inst.instruction |= WRITE_BACK;
9035 if (reloc_override)
9036 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9037 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9038 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9039 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
9041 if (thumb_mode)
9042 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
9043 else
9044 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
9047 /* Prefer + for zero encoded value. */
9048 if (!inst.operands[i].negative)
9049 inst.instruction |= INDEX_UP;
9051 return SUCCESS;
9054 /* Functions for instruction encoding, sorted by sub-architecture.
9055 First some generics; their names are taken from the conventional
9056 bit positions for register arguments in ARM format instructions. */
9058 static void
9059 do_noargs (void)
9063 static void
9064 do_rd (void)
9066 inst.instruction |= inst.operands[0].reg << 12;
9069 static void
9070 do_rn (void)
9072 inst.instruction |= inst.operands[0].reg << 16;
9075 static void
9076 do_rd_rm (void)
9078 inst.instruction |= inst.operands[0].reg << 12;
9079 inst.instruction |= inst.operands[1].reg;
9082 static void
9083 do_rm_rn (void)
9085 inst.instruction |= inst.operands[0].reg;
9086 inst.instruction |= inst.operands[1].reg << 16;
9089 static void
9090 do_rd_rn (void)
9092 inst.instruction |= inst.operands[0].reg << 12;
9093 inst.instruction |= inst.operands[1].reg << 16;
9096 static void
9097 do_rn_rd (void)
9099 inst.instruction |= inst.operands[0].reg << 16;
9100 inst.instruction |= inst.operands[1].reg << 12;
9103 static void
9104 do_tt (void)
9106 inst.instruction |= inst.operands[0].reg << 8;
9107 inst.instruction |= inst.operands[1].reg << 16;
9110 static bool
9111 check_obsolete (const arm_feature_set *feature, const char *msg)
9113 if (ARM_CPU_IS_ANY (cpu_variant))
9115 as_tsktsk ("%s", msg);
9116 return true;
9118 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9120 as_bad ("%s", msg);
9121 return true;
9124 return false;
9127 static void
9128 do_rd_rm_rn (void)
9130 unsigned Rn = inst.operands[2].reg;
9131 /* Enforce restrictions on SWP instruction. */
9132 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
9134 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9135 _("Rn must not overlap other operands"));
9137 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9139 if (!check_obsolete (&arm_ext_v8,
9140 _("swp{b} use is obsoleted for ARMv8 and later"))
9141 && warn_on_deprecated
9142 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
9143 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
9146 inst.instruction |= inst.operands[0].reg << 12;
9147 inst.instruction |= inst.operands[1].reg;
9148 inst.instruction |= Rn << 16;
9151 static void
9152 do_rd_rn_rm (void)
9154 inst.instruction |= inst.operands[0].reg << 12;
9155 inst.instruction |= inst.operands[1].reg << 16;
9156 inst.instruction |= inst.operands[2].reg;
9159 static void
9160 do_rm_rd_rn (void)
9162 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
9163 constraint (((inst.relocs[0].exp.X_op != O_constant
9164 && inst.relocs[0].exp.X_op != O_illegal)
9165 || inst.relocs[0].exp.X_add_number != 0),
9166 BAD_ADDR_MODE);
9167 inst.instruction |= inst.operands[0].reg;
9168 inst.instruction |= inst.operands[1].reg << 12;
9169 inst.instruction |= inst.operands[2].reg << 16;
9172 static void
9173 do_imm0 (void)
9175 inst.instruction |= inst.operands[0].imm;
9178 /* ARM instructions, in alphabetical order by function name (except
9179 that wrapper functions appear immediately after the function they
9180 wrap). */
9182 /* This is a pseudo-op of the form "adr rd, label" to be converted
9183 into a relative address of the form "add rd, pc, #label-.-8". */
9185 static void
9186 do_adr (void)
9188 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9190 /* Frag hacking will turn this into a sub instruction if the offset turns
9191 out to be negative. */
9192 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9193 inst.relocs[0].pc_rel = 1;
9194 inst.relocs[0].exp.X_add_number -= 8;
9196 if (support_interwork
9197 && inst.relocs[0].exp.X_op == O_symbol
9198 && inst.relocs[0].exp.X_add_symbol != NULL
9199 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9200 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9201 inst.relocs[0].exp.X_add_number |= 1;
9204 /* This is a pseudo-op of the form "adrl rd, label" to be converted
9205 into a relative address of the form:
9206 add rd, pc, #low(label-.-8)"
9207 add rd, rd, #high(label-.-8)" */
9209 static void
9210 do_adrl (void)
9212 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9214 /* Frag hacking will turn this into a sub instruction if the offset turns
9215 out to be negative. */
9216 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9217 inst.relocs[0].pc_rel = 1;
9218 inst.size = INSN_SIZE * 2;
9219 inst.relocs[0].exp.X_add_number -= 8;
9221 if (support_interwork
9222 && inst.relocs[0].exp.X_op == O_symbol
9223 && inst.relocs[0].exp.X_add_symbol != NULL
9224 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9225 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9226 inst.relocs[0].exp.X_add_number |= 1;
9229 static void
9230 do_arit (void)
9232 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9233 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9234 THUMB1_RELOC_ONLY);
9235 if (!inst.operands[1].present)
9236 inst.operands[1].reg = inst.operands[0].reg;
9237 inst.instruction |= inst.operands[0].reg << 12;
9238 inst.instruction |= inst.operands[1].reg << 16;
9239 encode_arm_shifter_operand (2);
9242 static void
9243 do_barrier (void)
9245 if (inst.operands[0].present)
9246 inst.instruction |= inst.operands[0].imm;
9247 else
9248 inst.instruction |= 0xf;
9251 static void
9252 do_bfc (void)
9254 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9255 constraint (msb > 32, _("bit-field extends past end of register"));
9256 /* The instruction encoding stores the LSB and MSB,
9257 not the LSB and width. */
9258 inst.instruction |= inst.operands[0].reg << 12;
9259 inst.instruction |= inst.operands[1].imm << 7;
9260 inst.instruction |= (msb - 1) << 16;
9263 static void
9264 do_bfi (void)
9266 unsigned int msb;
9268 /* #0 in second position is alternative syntax for bfc, which is
9269 the same instruction but with REG_PC in the Rm field. */
9270 if (!inst.operands[1].isreg)
9271 inst.operands[1].reg = REG_PC;
9273 msb = inst.operands[2].imm + inst.operands[3].imm;
9274 constraint (msb > 32, _("bit-field extends past end of register"));
9275 /* The instruction encoding stores the LSB and MSB,
9276 not the LSB and width. */
9277 inst.instruction |= inst.operands[0].reg << 12;
9278 inst.instruction |= inst.operands[1].reg;
9279 inst.instruction |= inst.operands[2].imm << 7;
9280 inst.instruction |= (msb - 1) << 16;
9283 static void
9284 do_bfx (void)
9286 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9287 _("bit-field extends past end of register"));
9288 inst.instruction |= inst.operands[0].reg << 12;
9289 inst.instruction |= inst.operands[1].reg;
9290 inst.instruction |= inst.operands[2].imm << 7;
9291 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9294 /* ARM V5 breakpoint instruction (argument parse)
9295 BKPT <16 bit unsigned immediate>
9296 Instruction is not conditional.
9297 The bit pattern given in insns[] has the COND_ALWAYS condition,
9298 and it is an error if the caller tried to override that. */
9300 static void
9301 do_bkpt (void)
9303 /* Top 12 of 16 bits to bits 19:8. */
9304 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
9306 /* Bottom 4 of 16 bits to bits 3:0. */
9307 inst.instruction |= inst.operands[0].imm & 0xf;
9310 static void
9311 encode_branch (int default_reloc)
9313 if (inst.operands[0].hasreloc)
9315 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9316 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9317 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
9318 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
9319 ? BFD_RELOC_ARM_PLT32
9320 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
9322 else
9323 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9324 inst.relocs[0].pc_rel = 1;
9327 static void
9328 do_branch (void)
9330 #ifdef OBJ_ELF
9331 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9332 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9333 else
9334 #endif
9335 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9338 static void
9339 do_bl (void)
9341 #ifdef OBJ_ELF
9342 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9344 if (inst.cond == COND_ALWAYS)
9345 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9346 else
9347 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9349 else
9350 #endif
9351 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9354 /* ARM V5 branch-link-exchange instruction (argument parse)
9355 BLX <target_addr> ie BLX(1)
9356 BLX{<condition>} <Rm> ie BLX(2)
9357 Unfortunately, there are two different opcodes for this mnemonic.
9358 So, the insns[].value is not used, and the code here zaps values
9359 into inst.instruction.
9360 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
9362 static void
9363 do_blx (void)
9365 if (inst.operands[0].isreg)
9367 /* Arg is a register; the opcode provided by insns[] is correct.
9368 It is not illegal to do "blx pc", just useless. */
9369 if (inst.operands[0].reg == REG_PC)
9370 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
9372 inst.instruction |= inst.operands[0].reg;
9374 else
9376 /* Arg is an address; this instruction cannot be executed
9377 conditionally, and the opcode must be adjusted.
9378 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9379 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
9380 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9381 inst.instruction = 0xfa000000;
9382 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
9386 static void
9387 do_bx (void)
9389 bool want_reloc;
9391 if (inst.operands[0].reg == REG_PC)
9392 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
9394 inst.instruction |= inst.operands[0].reg;
9395 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9396 it is for ARMv4t or earlier. */
9397 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
9398 if (!ARM_FEATURE_ZERO (selected_object_arch)
9399 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
9400 want_reloc = true;
9402 #ifdef OBJ_ELF
9403 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
9404 #endif
9405 want_reloc = false;
9407 if (want_reloc)
9408 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
9412 /* ARM v5TEJ. Jump to Jazelle code. */
9414 static void
9415 do_bxj (void)
9417 if (inst.operands[0].reg == REG_PC)
9418 as_tsktsk (_("use of r15 in bxj is not really useful"));
9420 inst.instruction |= inst.operands[0].reg;
9423 /* Co-processor data operation:
9424 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9425 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9426 static void
9427 do_cdp (void)
9429 inst.instruction |= inst.operands[0].reg << 8;
9430 inst.instruction |= inst.operands[1].imm << 20;
9431 inst.instruction |= inst.operands[2].reg << 12;
9432 inst.instruction |= inst.operands[3].reg << 16;
9433 inst.instruction |= inst.operands[4].reg;
9434 inst.instruction |= inst.operands[5].imm << 5;
9437 static void
9438 do_cmp (void)
9440 inst.instruction |= inst.operands[0].reg << 16;
9441 encode_arm_shifter_operand (1);
9444 /* Transfer between coprocessor and ARM registers.
9445 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9446 MRC2
9447 MCR{cond}
9448 MCR2
9450 No special properties. */
9452 struct deprecated_coproc_regs_s
9454 unsigned cp;
9455 int opc1;
9456 unsigned crn;
9457 unsigned crm;
9458 int opc2;
9459 arm_feature_set deprecated;
9460 arm_feature_set obsoleted;
9461 const char *dep_msg;
9462 const char *obs_msg;
9465 #define DEPR_ACCESS_V8 \
9466 N_("This coprocessor register access is deprecated in ARMv8")
9468 /* Table of all deprecated coprocessor registers. */
9469 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9471 {15, 0, 7, 10, 5, /* CP15DMB. */
9472 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9473 DEPR_ACCESS_V8, NULL},
9474 {15, 0, 7, 10, 4, /* CP15DSB. */
9475 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9476 DEPR_ACCESS_V8, NULL},
9477 {15, 0, 7, 5, 4, /* CP15ISB. */
9478 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9479 DEPR_ACCESS_V8, NULL},
9480 {14, 6, 1, 0, 0, /* TEEHBR. */
9481 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9482 DEPR_ACCESS_V8, NULL},
9483 {14, 6, 0, 0, 0, /* TEECR. */
9484 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9485 DEPR_ACCESS_V8, NULL},
9488 #undef DEPR_ACCESS_V8
9490 static const size_t deprecated_coproc_reg_count =
9491 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9493 static void
9494 do_co_reg (void)
9496 unsigned Rd;
9497 size_t i;
9499 Rd = inst.operands[2].reg;
9500 if (thumb_mode)
9502 if (inst.instruction == 0xee000010
9503 || inst.instruction == 0xfe000010)
9504 /* MCR, MCR2 */
9505 reject_bad_reg (Rd);
9506 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9507 /* MRC, MRC2 */
9508 constraint (Rd == REG_SP, BAD_SP);
9510 else
9512 /* MCR */
9513 if (inst.instruction == 0xe000010)
9514 constraint (Rd == REG_PC, BAD_PC);
9517 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9519 const struct deprecated_coproc_regs_s *r =
9520 deprecated_coproc_regs + i;
9522 if (inst.operands[0].reg == r->cp
9523 && inst.operands[1].imm == r->opc1
9524 && inst.operands[3].reg == r->crn
9525 && inst.operands[4].reg == r->crm
9526 && inst.operands[5].imm == r->opc2)
9528 if (! ARM_CPU_IS_ANY (cpu_variant)
9529 && warn_on_deprecated
9530 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
9531 as_tsktsk ("%s", r->dep_msg);
9535 inst.instruction |= inst.operands[0].reg << 8;
9536 inst.instruction |= inst.operands[1].imm << 21;
9537 inst.instruction |= Rd << 12;
9538 inst.instruction |= inst.operands[3].reg << 16;
9539 inst.instruction |= inst.operands[4].reg;
9540 inst.instruction |= inst.operands[5].imm << 5;
9543 /* Transfer between coprocessor register and pair of ARM registers.
9544 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9545 MCRR2
9546 MRRC{cond}
9547 MRRC2
9549 Two XScale instructions are special cases of these:
9551 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9552 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
9554 Result unpredictable if Rd or Rn is R15. */
9556 static void
9557 do_co_reg2c (void)
9559 unsigned Rd, Rn;
9561 Rd = inst.operands[2].reg;
9562 Rn = inst.operands[3].reg;
9564 if (thumb_mode)
9566 reject_bad_reg (Rd);
9567 reject_bad_reg (Rn);
9569 else
9571 constraint (Rd == REG_PC, BAD_PC);
9572 constraint (Rn == REG_PC, BAD_PC);
9575 /* Only check the MRRC{2} variants. */
9576 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9578 /* If Rd == Rn, error that the operation is
9579 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9580 constraint (Rd == Rn, BAD_OVERLAP);
9583 inst.instruction |= inst.operands[0].reg << 8;
9584 inst.instruction |= inst.operands[1].imm << 4;
9585 inst.instruction |= Rd << 12;
9586 inst.instruction |= Rn << 16;
9587 inst.instruction |= inst.operands[4].reg;
9590 static void
9591 do_cpsi (void)
9593 inst.instruction |= inst.operands[0].imm << 6;
9594 if (inst.operands[1].present)
9596 inst.instruction |= CPSI_MMOD;
9597 inst.instruction |= inst.operands[1].imm;
9601 static void
9602 do_dbg (void)
9604 inst.instruction |= inst.operands[0].imm;
9607 static void
9608 do_div (void)
9610 unsigned Rd, Rn, Rm;
9612 Rd = inst.operands[0].reg;
9613 Rn = (inst.operands[1].present
9614 ? inst.operands[1].reg : Rd);
9615 Rm = inst.operands[2].reg;
9617 constraint ((Rd == REG_PC), BAD_PC);
9618 constraint ((Rn == REG_PC), BAD_PC);
9619 constraint ((Rm == REG_PC), BAD_PC);
9621 inst.instruction |= Rd << 16;
9622 inst.instruction |= Rn << 0;
9623 inst.instruction |= Rm << 8;
9626 static void
9627 do_it (void)
9629 /* There is no IT instruction in ARM mode. We
9630 process it to do the validation as if in
9631 thumb mode, just in case the code gets
9632 assembled for thumb using the unified syntax. */
9634 inst.size = 0;
9635 if (unified_syntax)
9637 set_pred_insn_type (IT_INSN);
9638 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9639 now_pred.cc = inst.operands[0].imm;
9643 /* If there is only one register in the register list,
9644 then return its register number. Otherwise return -1. */
9645 static int
9646 only_one_reg_in_list (int range)
9648 int i = ffs (range) - 1;
9649 return (i > 15 || range != (1 << i)) ? -1 : i;
9652 static void
9653 encode_ldmstm(int from_push_pop_mnem)
9655 int base_reg = inst.operands[0].reg;
9656 int range = inst.operands[1].imm;
9657 int one_reg;
9659 inst.instruction |= base_reg << 16;
9660 inst.instruction |= range;
9662 if (inst.operands[1].writeback)
9663 inst.instruction |= LDM_TYPE_2_OR_3;
9665 if (inst.operands[0].writeback)
9667 inst.instruction |= WRITE_BACK;
9668 /* Check for unpredictable uses of writeback. */
9669 if (inst.instruction & LOAD_BIT)
9671 /* Not allowed in LDM type 2. */
9672 if ((inst.instruction & LDM_TYPE_2_OR_3)
9673 && ((range & (1 << REG_PC)) == 0))
9674 as_warn (_("writeback of base register is UNPREDICTABLE"));
9675 /* Only allowed if base reg not in list for other types. */
9676 else if (range & (1 << base_reg))
9677 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9679 else /* STM. */
9681 /* Not allowed for type 2. */
9682 if (inst.instruction & LDM_TYPE_2_OR_3)
9683 as_warn (_("writeback of base register is UNPREDICTABLE"));
9684 /* Only allowed if base reg not in list, or first in list. */
9685 else if ((range & (1 << base_reg))
9686 && (range & ((1 << base_reg) - 1)))
9687 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
9691 /* If PUSH/POP has only one register, then use the A2 encoding. */
9692 one_reg = only_one_reg_in_list (range);
9693 if (from_push_pop_mnem && one_reg >= 0)
9695 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9697 if (is_push && one_reg == 13 /* SP */)
9698 /* PR 22483: The A2 encoding cannot be used when
9699 pushing the stack pointer as this is UNPREDICTABLE. */
9700 return;
9702 inst.instruction &= A_COND_MASK;
9703 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9704 inst.instruction |= one_reg << 12;
9708 static void
9709 do_ldmstm (void)
9711 encode_ldmstm (/*from_push_pop_mnem=*/false);
9714 /* ARMv5TE load-consecutive (argument parse)
9715 Mode is like LDRH.
9717 LDRccD R, mode
9718 STRccD R, mode. */
9720 static void
9721 do_ldrd (void)
9723 constraint (inst.operands[0].reg % 2 != 0,
9724 _("first transfer register must be even"));
9725 constraint (inst.operands[1].present
9726 && inst.operands[1].reg != inst.operands[0].reg + 1,
9727 _("can only transfer two consecutive registers"));
9728 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9729 constraint (!inst.operands[2].isreg, _("'[' expected"));
9731 if (!inst.operands[1].present)
9732 inst.operands[1].reg = inst.operands[0].reg + 1;
9734 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9735 register and the first register written; we have to diagnose
9736 overlap between the base and the second register written here. */
9738 if (inst.operands[2].reg == inst.operands[1].reg
9739 && (inst.operands[2].writeback || inst.operands[2].postind))
9740 as_warn (_("base register written back, and overlaps "
9741 "second transfer register"));
9743 if (!(inst.instruction & V4_STR_BIT))
9745 /* For an index-register load, the index register must not overlap the
9746 destination (even if not write-back). */
9747 if (inst.operands[2].immisreg
9748 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9749 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9750 as_warn (_("index register overlaps transfer register"));
9752 inst.instruction |= inst.operands[0].reg << 12;
9753 encode_arm_addr_mode_3 (2, /*is_t=*/false);
9756 static void
9757 do_ldrex (void)
9759 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9760 || inst.operands[1].postind || inst.operands[1].writeback
9761 || inst.operands[1].immisreg || inst.operands[1].shifted
9762 || inst.operands[1].negative
9763 /* This can arise if the programmer has written
9764 strex rN, rM, foo
9765 or if they have mistakenly used a register name as the last
9766 operand, eg:
9767 strex rN, rM, rX
9768 It is very difficult to distinguish between these two cases
9769 because "rX" might actually be a label. ie the register
9770 name has been occluded by a symbol of the same name. So we
9771 just generate a general 'bad addressing mode' type error
9772 message and leave it up to the programmer to discover the
9773 true cause and fix their mistake. */
9774 || (inst.operands[1].reg == REG_PC),
9775 BAD_ADDR_MODE);
9777 constraint (inst.relocs[0].exp.X_op != O_constant
9778 || inst.relocs[0].exp.X_add_number != 0,
9779 _("offset must be zero in ARM encoding"));
9781 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9783 inst.instruction |= inst.operands[0].reg << 12;
9784 inst.instruction |= inst.operands[1].reg << 16;
9785 inst.relocs[0].type = BFD_RELOC_UNUSED;
9788 static void
9789 do_ldrexd (void)
9791 constraint (inst.operands[0].reg % 2 != 0,
9792 _("even register required"));
9793 constraint (inst.operands[1].present
9794 && inst.operands[1].reg != inst.operands[0].reg + 1,
9795 _("can only load two consecutive registers"));
9796 /* If op 1 were present and equal to PC, this function wouldn't
9797 have been called in the first place. */
9798 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9800 inst.instruction |= inst.operands[0].reg << 12;
9801 inst.instruction |= inst.operands[2].reg << 16;
9804 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9805 which is not a multiple of four is UNPREDICTABLE. */
9806 static void
9807 check_ldr_r15_aligned (void)
9809 constraint (!(inst.operands[1].immisreg)
9810 && (inst.operands[0].reg == REG_PC
9811 && inst.operands[1].reg == REG_PC
9812 && (inst.relocs[0].exp.X_add_number & 0x3)),
9813 _("ldr to register 15 must be 4-byte aligned"));
9816 static void
9817 do_ldst (void)
9819 inst.instruction |= inst.operands[0].reg << 12;
9820 if (!inst.operands[1].isreg)
9821 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/false))
9822 return;
9823 encode_arm_addr_mode_2 (1, /*is_t=*/false);
9824 check_ldr_r15_aligned ();
9827 static void
9828 do_ldstt (void)
9830 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9831 reject [Rn,...]. */
9832 if (inst.operands[1].preind)
9834 constraint (inst.relocs[0].exp.X_op != O_constant
9835 || inst.relocs[0].exp.X_add_number != 0,
9836 _("this instruction requires a post-indexed address"));
9838 inst.operands[1].preind = 0;
9839 inst.operands[1].postind = 1;
9840 inst.operands[1].writeback = 1;
9842 inst.instruction |= inst.operands[0].reg << 12;
9843 encode_arm_addr_mode_2 (1, /*is_t=*/true);
9846 /* Halfword and signed-byte load/store operations. */
9848 static void
9849 do_ldstv4 (void)
9851 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9852 inst.instruction |= inst.operands[0].reg << 12;
9853 if (!inst.operands[1].isreg)
9854 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/true))
9855 return;
9856 encode_arm_addr_mode_3 (1, /*is_t=*/false);
9859 static void
9860 do_ldsttv4 (void)
9862 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9863 reject [Rn,...]. */
9864 if (inst.operands[1].preind)
9866 constraint (inst.relocs[0].exp.X_op != O_constant
9867 || inst.relocs[0].exp.X_add_number != 0,
9868 _("this instruction requires a post-indexed address"));
9870 inst.operands[1].preind = 0;
9871 inst.operands[1].postind = 1;
9872 inst.operands[1].writeback = 1;
9874 inst.instruction |= inst.operands[0].reg << 12;
9875 encode_arm_addr_mode_3 (1, /*is_t=*/true);
9878 /* Co-processor register load/store.
9879 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9880 static void
9881 do_lstc (void)
9883 inst.instruction |= inst.operands[0].reg << 8;
9884 inst.instruction |= inst.operands[1].reg << 12;
9885 encode_arm_cp_address (2, true, true, 0);
9888 static void
9889 do_mlas (void)
9891 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9892 if (inst.operands[0].reg == inst.operands[1].reg
9893 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9894 && !(inst.instruction & 0x00400000))
9895 as_tsktsk (_("Rd and Rm should be different in mla"));
9897 inst.instruction |= inst.operands[0].reg << 16;
9898 inst.instruction |= inst.operands[1].reg;
9899 inst.instruction |= inst.operands[2].reg << 8;
9900 inst.instruction |= inst.operands[3].reg << 12;
9903 static void
9904 do_mov (void)
9906 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9907 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9908 THUMB1_RELOC_ONLY);
9909 inst.instruction |= inst.operands[0].reg << 12;
9910 encode_arm_shifter_operand (1);
9913 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9914 static void
9915 do_mov16 (void)
9917 bfd_vma imm;
9918 bool top;
9920 top = (inst.instruction & 0x00400000) != 0;
9921 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
9922 _(":lower16: not allowed in this instruction"));
9923 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
9924 _(":upper16: not allowed in this instruction"));
9925 inst.instruction |= inst.operands[0].reg << 12;
9926 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
9928 imm = inst.relocs[0].exp.X_add_number;
9929 /* The value is in two pieces: 0:11, 16:19. */
9930 inst.instruction |= (imm & 0x00000fff);
9931 inst.instruction |= (imm & 0x0000f000) << 4;
9935 static int
9936 do_vfp_nsyn_mrs (void)
9938 if (inst.operands[0].isvec)
9940 if (inst.operands[1].reg != 1)
9941 first_error (_("operand 1 must be FPSCR"));
9942 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9943 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9944 do_vfp_nsyn_opcode ("fmstat");
9946 else if (inst.operands[1].isvec)
9947 do_vfp_nsyn_opcode ("fmrx");
9948 else
9949 return FAIL;
9951 return SUCCESS;
9954 static int
9955 do_vfp_nsyn_msr (void)
9957 if (inst.operands[0].isvec)
9958 do_vfp_nsyn_opcode ("fmxr");
9959 else
9960 return FAIL;
9962 return SUCCESS;
9965 static void
9966 do_vmrs (void)
9968 unsigned Rt = inst.operands[0].reg;
9970 if (thumb_mode && Rt == REG_SP)
9972 inst.error = BAD_SP;
9973 return;
9976 switch (inst.operands[1].reg)
9978 /* MVFR2 is only valid for Armv8-A. */
9979 case 5:
9980 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9981 _(BAD_FPU));
9982 break;
9984 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
9985 case 1: /* fpscr. */
9986 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9987 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9988 _(BAD_FPU));
9989 break;
9991 case 14: /* fpcxt_ns, fpcxtns, FPCXT_NS, FPCXTNS. */
9992 case 15: /* fpcxt_s, fpcxts, FPCXT_S, FPCXTS. */
9993 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
9994 _("selected processor does not support instruction"));
9995 break;
9997 case 2: /* fpscr_nzcvqc. */
9998 case 12: /* vpr. */
9999 case 13: /* p0. */
10000 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10001 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10002 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10003 _("selected processor does not support instruction"));
10004 if (inst.operands[0].reg != 2
10005 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10006 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10007 break;
10009 default:
10010 break;
10013 /* APSR_ sets isvec. All other refs to PC are illegal. */
10014 if (!inst.operands[0].isvec && Rt == REG_PC)
10016 inst.error = BAD_PC;
10017 return;
10020 /* If we get through parsing the register name, we just insert the number
10021 generated into the instruction without further validation. */
10022 inst.instruction |= (inst.operands[1].reg << 16);
10023 inst.instruction |= (Rt << 12);
10026 static void
10027 do_vmsr (void)
10029 unsigned Rt = inst.operands[1].reg;
10031 if (thumb_mode)
10032 reject_bad_reg (Rt);
10033 else if (Rt == REG_PC)
10035 inst.error = BAD_PC;
10036 return;
10039 switch (inst.operands[0].reg)
10041 /* MVFR2 is only valid for Armv8-A. */
10042 case 5:
10043 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10044 _(BAD_FPU));
10045 break;
10047 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10048 case 1: /* fpcr. */
10049 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10050 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10051 _(BAD_FPU));
10052 break;
10054 case 14: /* fpcxt_ns. */
10055 case 15: /* fpcxt_s. */
10056 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10057 _("selected processor does not support instruction"));
10058 break;
10060 case 2: /* fpscr_nzcvqc. */
10061 case 12: /* vpr. */
10062 case 13: /* p0. */
10063 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10064 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10065 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10066 _("selected processor does not support instruction"));
10067 if (inst.operands[0].reg != 2
10068 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10069 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10070 break;
10072 default:
10073 break;
10076 /* If we get through parsing the register name, we just insert the number
10077 generated into the instruction without further validation. */
10078 inst.instruction |= (inst.operands[0].reg << 16);
10079 inst.instruction |= (Rt << 12);
10082 static void
10083 do_mrs (void)
10085 unsigned br;
10087 if (do_vfp_nsyn_mrs () == SUCCESS)
10088 return;
10090 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10091 inst.instruction |= inst.operands[0].reg << 12;
10093 if (inst.operands[1].isreg)
10095 br = inst.operands[1].reg;
10096 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
10097 as_bad (_("bad register for mrs"));
10099 else
10101 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10102 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10103 != (PSR_c|PSR_f),
10104 _("'APSR', 'CPSR' or 'SPSR' expected"));
10105 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10108 inst.instruction |= br;
10111 /* Two possible forms:
10112 "{C|S}PSR_<field>, Rm",
10113 "{C|S}PSR_f, #expression". */
10115 static void
10116 do_msr (void)
10118 if (do_vfp_nsyn_msr () == SUCCESS)
10119 return;
10121 inst.instruction |= inst.operands[0].imm;
10122 if (inst.operands[1].isreg)
10123 inst.instruction |= inst.operands[1].reg;
10124 else
10126 inst.instruction |= INST_IMMEDIATE;
10127 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10128 inst.relocs[0].pc_rel = 0;
10132 static void
10133 do_mul (void)
10135 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10137 if (!inst.operands[2].present)
10138 inst.operands[2].reg = inst.operands[0].reg;
10139 inst.instruction |= inst.operands[0].reg << 16;
10140 inst.instruction |= inst.operands[1].reg;
10141 inst.instruction |= inst.operands[2].reg << 8;
10143 if (inst.operands[0].reg == inst.operands[1].reg
10144 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10145 as_tsktsk (_("Rd and Rm should be different in mul"));
10148 /* Long Multiply Parser
10149 UMULL RdLo, RdHi, Rm, Rs
10150 SMULL RdLo, RdHi, Rm, Rs
10151 UMLAL RdLo, RdHi, Rm, Rs
10152 SMLAL RdLo, RdHi, Rm, Rs. */
10154 static void
10155 do_mull (void)
10157 inst.instruction |= inst.operands[0].reg << 12;
10158 inst.instruction |= inst.operands[1].reg << 16;
10159 inst.instruction |= inst.operands[2].reg;
10160 inst.instruction |= inst.operands[3].reg << 8;
10162 /* rdhi and rdlo must be different. */
10163 if (inst.operands[0].reg == inst.operands[1].reg)
10164 as_tsktsk (_("rdhi and rdlo must be different"));
10166 /* rdhi, rdlo and rm must all be different before armv6. */
10167 if ((inst.operands[0].reg == inst.operands[2].reg
10168 || inst.operands[1].reg == inst.operands[2].reg)
10169 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10170 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10173 static void
10174 do_nop (void)
10176 if (inst.operands[0].present
10177 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
10179 /* Architectural NOP hints are CPSR sets with no bits selected. */
10180 inst.instruction &= 0xf0000000;
10181 inst.instruction |= 0x0320f000;
10182 if (inst.operands[0].present)
10183 inst.instruction |= inst.operands[0].imm;
10187 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10188 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10189 Condition defaults to COND_ALWAYS.
10190 Error if Rd, Rn or Rm are R15. */
10192 static void
10193 do_pkhbt (void)
10195 inst.instruction |= inst.operands[0].reg << 12;
10196 inst.instruction |= inst.operands[1].reg << 16;
10197 inst.instruction |= inst.operands[2].reg;
10198 if (inst.operands[3].present)
10199 encode_arm_shift (3);
10202 /* ARM V6 PKHTB (Argument Parse). */
10204 static void
10205 do_pkhtb (void)
10207 if (!inst.operands[3].present)
10209 /* If the shift specifier is omitted, turn the instruction
10210 into pkhbt rd, rm, rn. */
10211 inst.instruction &= 0xfff00010;
10212 inst.instruction |= inst.operands[0].reg << 12;
10213 inst.instruction |= inst.operands[1].reg;
10214 inst.instruction |= inst.operands[2].reg << 16;
10216 else
10218 inst.instruction |= inst.operands[0].reg << 12;
10219 inst.instruction |= inst.operands[1].reg << 16;
10220 inst.instruction |= inst.operands[2].reg;
10221 encode_arm_shift (3);
10225 /* ARMv5TE: Preload-Cache
10226 MP Extensions: Preload for write
10228 PLD(W) <addr_mode>
10230 Syntactically, like LDR with B=1, W=0, L=1. */
10232 static void
10233 do_pld (void)
10235 constraint (!inst.operands[0].isreg,
10236 _("'[' expected after PLD mnemonic"));
10237 constraint (inst.operands[0].postind,
10238 _("post-indexed expression used in preload instruction"));
10239 constraint (inst.operands[0].writeback,
10240 _("writeback used in preload instruction"));
10241 constraint (!inst.operands[0].preind,
10242 _("unindexed addressing used in preload instruction"));
10243 encode_arm_addr_mode_2 (0, /*is_t=*/false);
10246 /* ARMv7: PLI <addr_mode> */
10247 static void
10248 do_pli (void)
10250 constraint (!inst.operands[0].isreg,
10251 _("'[' expected after PLI mnemonic"));
10252 constraint (inst.operands[0].postind,
10253 _("post-indexed expression used in preload instruction"));
10254 constraint (inst.operands[0].writeback,
10255 _("writeback used in preload instruction"));
10256 constraint (!inst.operands[0].preind,
10257 _("unindexed addressing used in preload instruction"));
10258 encode_arm_addr_mode_2 (0, /*is_t=*/false);
10259 inst.instruction &= ~PRE_INDEX;
10262 static void
10263 do_push_pop (void)
10265 constraint (inst.operands[0].writeback,
10266 _("push/pop do not support {reglist}^"));
10267 inst.operands[1] = inst.operands[0];
10268 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10269 inst.operands[0].isreg = 1;
10270 inst.operands[0].writeback = 1;
10271 inst.operands[0].reg = REG_SP;
10272 encode_ldmstm (/*from_push_pop_mnem=*/true);
10275 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10276 word at the specified address and the following word
10277 respectively.
10278 Unconditionally executed.
10279 Error if Rn is R15. */
10281 static void
10282 do_rfe (void)
10284 inst.instruction |= inst.operands[0].reg << 16;
10285 if (inst.operands[0].writeback)
10286 inst.instruction |= WRITE_BACK;
10289 /* ARM V6 ssat (argument parse). */
10291 static void
10292 do_ssat (void)
10294 inst.instruction |= inst.operands[0].reg << 12;
10295 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10296 inst.instruction |= inst.operands[2].reg;
10298 if (inst.operands[3].present)
10299 encode_arm_shift (3);
10302 /* ARM V6 usat (argument parse). */
10304 static void
10305 do_usat (void)
10307 inst.instruction |= inst.operands[0].reg << 12;
10308 inst.instruction |= inst.operands[1].imm << 16;
10309 inst.instruction |= inst.operands[2].reg;
10311 if (inst.operands[3].present)
10312 encode_arm_shift (3);
10315 /* ARM V6 ssat16 (argument parse). */
10317 static void
10318 do_ssat16 (void)
10320 inst.instruction |= inst.operands[0].reg << 12;
10321 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10322 inst.instruction |= inst.operands[2].reg;
10325 static void
10326 do_usat16 (void)
10328 inst.instruction |= inst.operands[0].reg << 12;
10329 inst.instruction |= inst.operands[1].imm << 16;
10330 inst.instruction |= inst.operands[2].reg;
10333 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10334 preserving the other bits.
10336 setend <endian_specifier>, where <endian_specifier> is either
10337 BE or LE. */
10339 static void
10340 do_setend (void)
10342 if (warn_on_deprecated
10343 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10344 as_tsktsk (_("setend use is deprecated for ARMv8"));
10346 if (inst.operands[0].imm)
10347 inst.instruction |= 0x200;
10350 static void
10351 do_shift (void)
10353 unsigned int Rm = (inst.operands[1].present
10354 ? inst.operands[1].reg
10355 : inst.operands[0].reg);
10357 inst.instruction |= inst.operands[0].reg << 12;
10358 inst.instruction |= Rm;
10359 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
10361 inst.instruction |= inst.operands[2].reg << 8;
10362 inst.instruction |= SHIFT_BY_REG;
10363 /* PR 12854: Error on extraneous shifts. */
10364 constraint (inst.operands[2].shifted,
10365 _("extraneous shift as part of operand to shift insn"));
10367 else
10368 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
10371 static void
10372 do_smc (void)
10374 unsigned int value = inst.relocs[0].exp.X_add_number;
10375 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10377 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10378 inst.relocs[0].pc_rel = 0;
10381 static void
10382 do_hvc (void)
10384 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10385 inst.relocs[0].pc_rel = 0;
10388 static void
10389 do_swi (void)
10391 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10392 inst.relocs[0].pc_rel = 0;
10395 static void
10396 do_setpan (void)
10398 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10399 _("selected processor does not support SETPAN instruction"));
10401 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10404 static void
10405 do_t_setpan (void)
10407 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10408 _("selected processor does not support SETPAN instruction"));
10410 inst.instruction |= (inst.operands[0].imm << 3);
10413 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10414 SMLAxy{cond} Rd,Rm,Rs,Rn
10415 SMLAWy{cond} Rd,Rm,Rs,Rn
10416 Error if any register is R15. */
10418 static void
10419 do_smla (void)
10421 inst.instruction |= inst.operands[0].reg << 16;
10422 inst.instruction |= inst.operands[1].reg;
10423 inst.instruction |= inst.operands[2].reg << 8;
10424 inst.instruction |= inst.operands[3].reg << 12;
10427 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10428 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10429 Error if any register is R15.
10430 Warning if Rdlo == Rdhi. */
10432 static void
10433 do_smlal (void)
10435 inst.instruction |= inst.operands[0].reg << 12;
10436 inst.instruction |= inst.operands[1].reg << 16;
10437 inst.instruction |= inst.operands[2].reg;
10438 inst.instruction |= inst.operands[3].reg << 8;
10440 if (inst.operands[0].reg == inst.operands[1].reg)
10441 as_tsktsk (_("rdhi and rdlo must be different"));
10444 /* ARM V5E (El Segundo) signed-multiply (argument parse)
10445 SMULxy{cond} Rd,Rm,Rs
10446 Error if any register is R15. */
10448 static void
10449 do_smul (void)
10451 inst.instruction |= inst.operands[0].reg << 16;
10452 inst.instruction |= inst.operands[1].reg;
10453 inst.instruction |= inst.operands[2].reg << 8;
10456 /* ARM V6 srs (argument parse). The variable fields in the encoding are
10457 the same for both ARM and Thumb-2. */
10459 static void
10460 do_srs (void)
10462 int reg;
10464 if (inst.operands[0].present)
10466 reg = inst.operands[0].reg;
10467 constraint (reg != REG_SP, _("SRS base register must be r13"));
10469 else
10470 reg = REG_SP;
10472 inst.instruction |= reg << 16;
10473 inst.instruction |= inst.operands[1].imm;
10474 if (inst.operands[0].writeback || inst.operands[1].writeback)
10475 inst.instruction |= WRITE_BACK;
10478 /* ARM V6 strex (argument parse). */
10480 static void
10481 do_strex (void)
10483 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10484 || inst.operands[2].postind || inst.operands[2].writeback
10485 || inst.operands[2].immisreg || inst.operands[2].shifted
10486 || inst.operands[2].negative
10487 /* See comment in do_ldrex(). */
10488 || (inst.operands[2].reg == REG_PC),
10489 BAD_ADDR_MODE);
10491 constraint (inst.operands[0].reg == inst.operands[1].reg
10492 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10494 constraint (inst.relocs[0].exp.X_op != O_constant
10495 || inst.relocs[0].exp.X_add_number != 0,
10496 _("offset must be zero in ARM encoding"));
10498 inst.instruction |= inst.operands[0].reg << 12;
10499 inst.instruction |= inst.operands[1].reg;
10500 inst.instruction |= inst.operands[2].reg << 16;
10501 inst.relocs[0].type = BFD_RELOC_UNUSED;
10504 static void
10505 do_t_strexbh (void)
10507 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10508 || inst.operands[2].postind || inst.operands[2].writeback
10509 || inst.operands[2].immisreg || inst.operands[2].shifted
10510 || inst.operands[2].negative,
10511 BAD_ADDR_MODE);
10513 constraint (inst.operands[0].reg == inst.operands[1].reg
10514 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10516 do_rm_rd_rn ();
10519 static void
10520 do_strexd (void)
10522 constraint (inst.operands[1].reg % 2 != 0,
10523 _("even register required"));
10524 constraint (inst.operands[2].present
10525 && inst.operands[2].reg != inst.operands[1].reg + 1,
10526 _("can only store two consecutive registers"));
10527 /* If op 2 were present and equal to PC, this function wouldn't
10528 have been called in the first place. */
10529 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
10531 constraint (inst.operands[0].reg == inst.operands[1].reg
10532 || inst.operands[0].reg == inst.operands[1].reg + 1
10533 || inst.operands[0].reg == inst.operands[3].reg,
10534 BAD_OVERLAP);
10536 inst.instruction |= inst.operands[0].reg << 12;
10537 inst.instruction |= inst.operands[1].reg;
10538 inst.instruction |= inst.operands[3].reg << 16;
10541 /* ARM V8 STRL. */
10542 static void
10543 do_stlex (void)
10545 constraint (inst.operands[0].reg == inst.operands[1].reg
10546 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10548 do_rd_rm_rn ();
10551 static void
10552 do_t_stlex (void)
10554 constraint (inst.operands[0].reg == inst.operands[1].reg
10555 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10557 do_rm_rd_rn ();
10560 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10561 extends it to 32-bits, and adds the result to a value in another
10562 register. You can specify a rotation by 0, 8, 16, or 24 bits
10563 before extracting the 16-bit value.
10564 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10565 Condition defaults to COND_ALWAYS.
10566 Error if any register uses R15. */
10568 static void
10569 do_sxtah (void)
10571 inst.instruction |= inst.operands[0].reg << 12;
10572 inst.instruction |= inst.operands[1].reg << 16;
10573 inst.instruction |= inst.operands[2].reg;
10574 inst.instruction |= inst.operands[3].imm << 10;
10577 /* ARM V6 SXTH.
10579 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10580 Condition defaults to COND_ALWAYS.
10581 Error if any register uses R15. */
10583 static void
10584 do_sxth (void)
10586 inst.instruction |= inst.operands[0].reg << 12;
10587 inst.instruction |= inst.operands[1].reg;
10588 inst.instruction |= inst.operands[2].imm << 10;
10591 /* VFP instructions. In a logical order: SP variant first, monad
10592 before dyad, arithmetic then move then load/store. */
10594 static void
10595 do_vfp_sp_monadic (void)
10597 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10598 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10599 _(BAD_FPU));
10601 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10602 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10605 static void
10606 do_vfp_sp_dyadic (void)
10608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10610 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10613 static void
10614 do_vfp_sp_compare_z (void)
10616 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10619 static void
10620 do_vfp_dp_sp_cvt (void)
10622 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10623 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10626 static void
10627 do_vfp_sp_dp_cvt (void)
10629 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10630 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10633 static void
10634 do_vfp_reg_from_sp (void)
10636 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10637 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10638 _(BAD_FPU));
10640 inst.instruction |= inst.operands[0].reg << 12;
10641 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10644 static void
10645 do_vfp_reg2_from_sp2 (void)
10647 constraint (inst.operands[2].imm != 2,
10648 _("only two consecutive VFP SP registers allowed here"));
10649 inst.instruction |= inst.operands[0].reg << 12;
10650 inst.instruction |= inst.operands[1].reg << 16;
10651 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10654 static void
10655 do_vfp_sp_from_reg (void)
10657 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10658 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10659 _(BAD_FPU));
10661 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
10662 inst.instruction |= inst.operands[1].reg << 12;
10665 static void
10666 do_vfp_sp2_from_reg2 (void)
10668 constraint (inst.operands[0].imm != 2,
10669 _("only two consecutive VFP SP registers allowed here"));
10670 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
10671 inst.instruction |= inst.operands[1].reg << 12;
10672 inst.instruction |= inst.operands[2].reg << 16;
10675 static void
10676 do_vfp_sp_ldst (void)
10678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10679 encode_arm_cp_address (1, false, true, 0);
10682 static void
10683 do_vfp_dp_ldst (void)
10685 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10686 encode_arm_cp_address (1, false, true, 0);
10690 static void
10691 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
10693 if (inst.operands[0].writeback)
10694 inst.instruction |= WRITE_BACK;
10695 else
10696 constraint (ldstm_type != VFP_LDSTMIA,
10697 _("this addressing mode requires base-register writeback"));
10698 inst.instruction |= inst.operands[0].reg << 16;
10699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
10700 inst.instruction |= inst.operands[1].imm;
10703 static void
10704 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
10706 int count;
10708 if (inst.operands[0].writeback)
10709 inst.instruction |= WRITE_BACK;
10710 else
10711 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10712 _("this addressing mode requires base-register writeback"));
10714 inst.instruction |= inst.operands[0].reg << 16;
10715 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10717 count = inst.operands[1].imm << 1;
10718 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10719 count += 1;
10721 inst.instruction |= count;
10724 static void
10725 do_vfp_sp_ldstmia (void)
10727 vfp_sp_ldstm (VFP_LDSTMIA);
10730 static void
10731 do_vfp_sp_ldstmdb (void)
10733 vfp_sp_ldstm (VFP_LDSTMDB);
10736 static void
10737 do_vfp_dp_ldstmia (void)
10739 vfp_dp_ldstm (VFP_LDSTMIA);
10742 static void
10743 do_vfp_dp_ldstmdb (void)
10745 vfp_dp_ldstm (VFP_LDSTMDB);
10748 static void
10749 do_vfp_xp_ldstmia (void)
10751 vfp_dp_ldstm (VFP_LDSTMIAX);
10754 static void
10755 do_vfp_xp_ldstmdb (void)
10757 vfp_dp_ldstm (VFP_LDSTMDBX);
10760 static void
10761 do_vfp_dp_rd_rm (void)
10763 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10764 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10765 _(BAD_FPU));
10767 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10768 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10771 static void
10772 do_vfp_dp_rn_rd (void)
10774 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10775 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10778 static void
10779 do_vfp_dp_rd_rn (void)
10781 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10782 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10785 static void
10786 do_vfp_dp_rd_rn_rm (void)
10788 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10789 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10790 _(BAD_FPU));
10792 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10793 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10794 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10797 static void
10798 do_vfp_dp_rd (void)
10800 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10803 static void
10804 do_vfp_dp_rm_rd_rn (void)
10806 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10807 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10808 _(BAD_FPU));
10810 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10811 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10812 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10815 /* VFPv3 instructions. */
10816 static void
10817 do_vfp_sp_const (void)
10819 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10820 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10821 inst.instruction |= (inst.operands[1].imm & 0x0f);
10824 static void
10825 do_vfp_dp_const (void)
10827 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10828 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10829 inst.instruction |= (inst.operands[1].imm & 0x0f);
10832 static void
10833 vfp_conv (int srcsize)
10835 int immbits = srcsize - inst.operands[1].imm;
10837 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10839 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10840 i.e. immbits must be in range 0 - 16. */
10841 inst.error = _("immediate value out of range, expected range [0, 16]");
10842 return;
10844 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10846 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10847 i.e. immbits must be in range 0 - 31. */
10848 inst.error = _("immediate value out of range, expected range [1, 32]");
10849 return;
10852 inst.instruction |= (immbits & 1) << 5;
10853 inst.instruction |= (immbits >> 1);
10856 static void
10857 do_vfp_sp_conv_16 (void)
10859 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10860 vfp_conv (16);
10863 static void
10864 do_vfp_dp_conv_16 (void)
10866 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10867 vfp_conv (16);
10870 static void
10871 do_vfp_sp_conv_32 (void)
10873 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10874 vfp_conv (32);
10877 static void
10878 do_vfp_dp_conv_32 (void)
10880 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10881 vfp_conv (32);
10884 /* iWMMXt instructions: strictly in alphabetical order. */
10886 static void
10887 do_iwmmxt_tandorc (void)
10889 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10892 static void
10893 do_iwmmxt_textrc (void)
10895 inst.instruction |= inst.operands[0].reg << 12;
10896 inst.instruction |= inst.operands[1].imm;
10899 static void
10900 do_iwmmxt_textrm (void)
10902 inst.instruction |= inst.operands[0].reg << 12;
10903 inst.instruction |= inst.operands[1].reg << 16;
10904 inst.instruction |= inst.operands[2].imm;
10907 static void
10908 do_iwmmxt_tinsr (void)
10910 inst.instruction |= inst.operands[0].reg << 16;
10911 inst.instruction |= inst.operands[1].reg << 12;
10912 inst.instruction |= inst.operands[2].imm;
10915 static void
10916 do_iwmmxt_tmia (void)
10918 inst.instruction |= inst.operands[0].reg << 5;
10919 inst.instruction |= inst.operands[1].reg;
10920 inst.instruction |= inst.operands[2].reg << 12;
10923 static void
10924 do_iwmmxt_waligni (void)
10926 inst.instruction |= inst.operands[0].reg << 12;
10927 inst.instruction |= inst.operands[1].reg << 16;
10928 inst.instruction |= inst.operands[2].reg;
10929 inst.instruction |= inst.operands[3].imm << 20;
10932 static void
10933 do_iwmmxt_wmerge (void)
10935 inst.instruction |= inst.operands[0].reg << 12;
10936 inst.instruction |= inst.operands[1].reg << 16;
10937 inst.instruction |= inst.operands[2].reg;
10938 inst.instruction |= inst.operands[3].imm << 21;
10941 static void
10942 do_iwmmxt_wmov (void)
10944 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10945 inst.instruction |= inst.operands[0].reg << 12;
10946 inst.instruction |= inst.operands[1].reg << 16;
10947 inst.instruction |= inst.operands[1].reg;
10950 static void
10951 do_iwmmxt_wldstbh (void)
10953 int reloc;
10954 inst.instruction |= inst.operands[0].reg << 12;
10955 if (thumb_mode)
10956 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10957 else
10958 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10959 encode_arm_cp_address (1, true, false, reloc);
10962 static void
10963 do_iwmmxt_wldstw (void)
10965 /* RIWR_RIWC clears .isreg for a control register. */
10966 if (!inst.operands[0].isreg)
10968 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10969 inst.instruction |= 0xf0000000;
10972 inst.instruction |= inst.operands[0].reg << 12;
10973 encode_arm_cp_address (1, true, true, 0);
10976 static void
10977 do_iwmmxt_wldstd (void)
10979 inst.instruction |= inst.operands[0].reg << 12;
10980 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10981 && inst.operands[1].immisreg)
10983 inst.instruction &= ~0x1a000ff;
10984 inst.instruction |= (0xfU << 28);
10985 if (inst.operands[1].preind)
10986 inst.instruction |= PRE_INDEX;
10987 if (!inst.operands[1].negative)
10988 inst.instruction |= INDEX_UP;
10989 if (inst.operands[1].writeback)
10990 inst.instruction |= WRITE_BACK;
10991 inst.instruction |= inst.operands[1].reg << 16;
10992 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
10993 inst.instruction |= inst.operands[1].imm;
10995 else
10996 encode_arm_cp_address (1, true, false, 0);
10999 static void
11000 do_iwmmxt_wshufh (void)
11002 inst.instruction |= inst.operands[0].reg << 12;
11003 inst.instruction |= inst.operands[1].reg << 16;
11004 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11005 inst.instruction |= (inst.operands[2].imm & 0x0f);
11008 static void
11009 do_iwmmxt_wzero (void)
11011 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11012 inst.instruction |= inst.operands[0].reg;
11013 inst.instruction |= inst.operands[0].reg << 12;
11014 inst.instruction |= inst.operands[0].reg << 16;
11017 static void
11018 do_iwmmxt_wrwrwr_or_imm5 (void)
11020 if (inst.operands[2].isreg)
11021 do_rd_rn_rm ();
11022 else {
11023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11024 _("immediate operand requires iWMMXt2"));
11025 do_rd_rn ();
11026 if (inst.operands[2].imm == 0)
11028 switch ((inst.instruction >> 20) & 0xf)
11030 case 4:
11031 case 5:
11032 case 6:
11033 case 7:
11034 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11035 inst.operands[2].imm = 16;
11036 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11037 break;
11038 case 8:
11039 case 9:
11040 case 10:
11041 case 11:
11042 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11043 inst.operands[2].imm = 32;
11044 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11045 break;
11046 case 12:
11047 case 13:
11048 case 14:
11049 case 15:
11051 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11052 unsigned long wrn;
11053 wrn = (inst.instruction >> 16) & 0xf;
11054 inst.instruction &= 0xff0fff0f;
11055 inst.instruction |= wrn;
11056 /* Bail out here; the instruction is now assembled. */
11057 return;
11061 /* Map 32 -> 0, etc. */
11062 inst.operands[2].imm &= 0x1f;
11063 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
11068 /* XScale instructions. Also sorted arithmetic before move. */
11070 /* Xscale multiply-accumulate (argument parse)
11071 MIAcc acc0,Rm,Rs
11072 MIAPHcc acc0,Rm,Rs
11073 MIAxycc acc0,Rm,Rs. */
11075 static void
11076 do_xsc_mia (void)
11078 inst.instruction |= inst.operands[1].reg;
11079 inst.instruction |= inst.operands[2].reg << 12;
11082 /* Xscale move-accumulator-register (argument parse)
11084 MARcc acc0,RdLo,RdHi. */
11086 static void
11087 do_xsc_mar (void)
11089 inst.instruction |= inst.operands[1].reg << 12;
11090 inst.instruction |= inst.operands[2].reg << 16;
11093 /* Xscale move-register-accumulator (argument parse)
11095 MRAcc RdLo,RdHi,acc0. */
11097 static void
11098 do_xsc_mra (void)
11100 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11101 inst.instruction |= inst.operands[0].reg << 12;
11102 inst.instruction |= inst.operands[1].reg << 16;
11105 /* Encoding functions relevant only to Thumb. */
11107 /* inst.operands[i] is a shifted-register operand; encode
11108 it into inst.instruction in the format used by Thumb32. */
11110 static void
11111 encode_thumb32_shifted_operand (int i)
11113 unsigned int value = inst.relocs[0].exp.X_add_number;
11114 unsigned int shift = inst.operands[i].shift_kind;
11116 constraint (inst.operands[i].immisreg,
11117 _("shift by register not allowed in thumb mode"));
11118 inst.instruction |= inst.operands[i].reg;
11119 if (shift == SHIFT_RRX)
11120 inst.instruction |= SHIFT_ROR << 4;
11121 else
11123 constraint (inst.relocs[0].exp.X_op != O_constant,
11124 _("expression too complex"));
11126 constraint (value > 32
11127 || (value == 32 && (shift == SHIFT_LSL
11128 || shift == SHIFT_ROR)),
11129 _("shift expression is too large"));
11131 if (value == 0)
11132 shift = SHIFT_LSL;
11133 else if (value == 32)
11134 value = 0;
11136 inst.instruction |= shift << 4;
11137 inst.instruction |= (value & 0x1c) << 10;
11138 inst.instruction |= (value & 0x03) << 6;
11143 /* inst.operands[i] was set up by parse_address. Encode it into a
11144 Thumb32 format load or store instruction. Reject forms that cannot
11145 be used with such instructions. If is_t is true, reject forms that
11146 cannot be used with a T instruction; if is_d is true, reject forms
11147 that cannot be used with a D instruction. If it is a store insn,
11148 reject PC in Rn. */
11150 static void
11151 encode_thumb32_addr_mode (int i, bool is_t, bool is_d)
11153 const bool is_pc = (inst.operands[i].reg == REG_PC);
11155 constraint (!inst.operands[i].isreg,
11156 _("Instruction does not support =N addresses"));
11158 inst.instruction |= inst.operands[i].reg << 16;
11159 if (inst.operands[i].immisreg)
11161 constraint (is_pc, BAD_PC_ADDRESSING);
11162 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11163 constraint (inst.operands[i].negative,
11164 _("Thumb does not support negative register indexing"));
11165 constraint (inst.operands[i].postind,
11166 _("Thumb does not support register post-indexing"));
11167 constraint (inst.operands[i].writeback,
11168 _("Thumb does not support register indexing with writeback"));
11169 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11170 _("Thumb supports only LSL in shifted register indexing"));
11172 inst.instruction |= inst.operands[i].imm;
11173 if (inst.operands[i].shifted)
11175 constraint (inst.relocs[0].exp.X_op != O_constant,
11176 _("expression too complex"));
11177 constraint (inst.relocs[0].exp.X_add_number < 0
11178 || inst.relocs[0].exp.X_add_number > 3,
11179 _("shift out of range"));
11180 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11182 inst.relocs[0].type = BFD_RELOC_UNUSED;
11184 else if (inst.operands[i].preind)
11186 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
11187 constraint (is_t && inst.operands[i].writeback,
11188 _("cannot use writeback with this instruction"));
11189 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11190 BAD_PC_ADDRESSING);
11192 if (is_d)
11194 inst.instruction |= 0x01000000;
11195 if (inst.operands[i].writeback)
11196 inst.instruction |= 0x00200000;
11198 else
11200 inst.instruction |= 0x00000c00;
11201 if (inst.operands[i].writeback)
11202 inst.instruction |= 0x00000100;
11204 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11206 else if (inst.operands[i].postind)
11208 gas_assert (inst.operands[i].writeback);
11209 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11210 constraint (is_t, _("cannot use post-indexing with this instruction"));
11212 if (is_d)
11213 inst.instruction |= 0x00200000;
11214 else
11215 inst.instruction |= 0x00000900;
11216 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11218 else /* unindexed - only for coprocessor */
11219 inst.error = _("instruction does not accept unindexed addressing");
11222 /* Table of Thumb instructions which exist in 16- and/or 32-bit
11223 encodings (the latter only in post-V6T2 cores). The index is the
11224 value used in the insns table below. When there is more than one
11225 possible 16-bit encoding for the instruction, this table always
11226 holds variant (1).
11227 Also contains several pseudo-instructions used during relaxation. */
11228 #define T16_32_TAB \
11229 X(_adc, 4140, eb400000), \
11230 X(_adcs, 4140, eb500000), \
11231 X(_add, 1c00, eb000000), \
11232 X(_adds, 1c00, eb100000), \
11233 X(_addi, 0000, f1000000), \
11234 X(_addis, 0000, f1100000), \
11235 X(_add_pc,000f, f20f0000), \
11236 X(_add_sp,000d, f10d0000), \
11237 X(_adr, 000f, f20f0000), \
11238 X(_and, 4000, ea000000), \
11239 X(_ands, 4000, ea100000), \
11240 X(_asr, 1000, fa40f000), \
11241 X(_asrs, 1000, fa50f000), \
11242 X(_aut, 0000, f3af802d), \
11243 X(_autg, 0000, fb500f00), \
11244 X(_b, e000, f000b000), \
11245 X(_bcond, d000, f0008000), \
11246 X(_bf, 0000, f040e001), \
11247 X(_bfcsel,0000, f000e001), \
11248 X(_bfx, 0000, f060e001), \
11249 X(_bfl, 0000, f000c001), \
11250 X(_bflx, 0000, f070e001), \
11251 X(_bic, 4380, ea200000), \
11252 X(_bics, 4380, ea300000), \
11253 X(_bxaut, 0000, fb500f10), \
11254 X(_cinc, 0000, ea509000), \
11255 X(_cinv, 0000, ea50a000), \
11256 X(_cmn, 42c0, eb100f00), \
11257 X(_cmp, 2800, ebb00f00), \
11258 X(_cneg, 0000, ea50b000), \
11259 X(_cpsie, b660, f3af8400), \
11260 X(_cpsid, b670, f3af8600), \
11261 X(_cpy, 4600, ea4f0000), \
11262 X(_csel, 0000, ea508000), \
11263 X(_cset, 0000, ea5f900f), \
11264 X(_csetm, 0000, ea5fa00f), \
11265 X(_csinc, 0000, ea509000), \
11266 X(_csinv, 0000, ea50a000), \
11267 X(_csneg, 0000, ea50b000), \
11268 X(_dec_sp,80dd, f1ad0d00), \
11269 X(_dls, 0000, f040e001), \
11270 X(_dlstp, 0000, f000e001), \
11271 X(_eor, 4040, ea800000), \
11272 X(_eors, 4040, ea900000), \
11273 X(_inc_sp,00dd, f10d0d00), \
11274 X(_lctp, 0000, f00fe001), \
11275 X(_ldmia, c800, e8900000), \
11276 X(_ldr, 6800, f8500000), \
11277 X(_ldrb, 7800, f8100000), \
11278 X(_ldrh, 8800, f8300000), \
11279 X(_ldrsb, 5600, f9100000), \
11280 X(_ldrsh, 5e00, f9300000), \
11281 X(_ldr_pc,4800, f85f0000), \
11282 X(_ldr_pc2,4800, f85f0000), \
11283 X(_ldr_sp,9800, f85d0000), \
11284 X(_le, 0000, f00fc001), \
11285 X(_letp, 0000, f01fc001), \
11286 X(_lsl, 0000, fa00f000), \
11287 X(_lsls, 0000, fa10f000), \
11288 X(_lsr, 0800, fa20f000), \
11289 X(_lsrs, 0800, fa30f000), \
11290 X(_mov, 2000, ea4f0000), \
11291 X(_movs, 2000, ea5f0000), \
11292 X(_mul, 4340, fb00f000), \
11293 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11294 X(_mvn, 43c0, ea6f0000), \
11295 X(_mvns, 43c0, ea7f0000), \
11296 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11297 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11298 X(_orr, 4300, ea400000), \
11299 X(_orrs, 4300, ea500000), \
11300 X(_pac, 0000, f3af801d), \
11301 X(_pacbti, 0000, f3af800d), \
11302 X(_pacg, 0000, fb60f000), \
11303 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11304 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11305 X(_rev, ba00, fa90f080), \
11306 X(_rev16, ba40, fa90f090), \
11307 X(_revsh, bac0, fa90f0b0), \
11308 X(_ror, 41c0, fa60f000), \
11309 X(_rors, 41c0, fa70f000), \
11310 X(_sbc, 4180, eb600000), \
11311 X(_sbcs, 4180, eb700000), \
11312 X(_stmia, c000, e8800000), \
11313 X(_str, 6000, f8400000), \
11314 X(_strb, 7000, f8000000), \
11315 X(_strh, 8000, f8200000), \
11316 X(_str_sp,9000, f84d0000), \
11317 X(_sub, 1e00, eba00000), \
11318 X(_subs, 1e00, ebb00000), \
11319 X(_subi, 8000, f1a00000), \
11320 X(_subis, 8000, f1b00000), \
11321 X(_sxtb, b240, fa4ff080), \
11322 X(_sxth, b200, fa0ff080), \
11323 X(_tst, 4200, ea100f00), \
11324 X(_uxtb, b2c0, fa5ff080), \
11325 X(_uxth, b280, fa1ff080), \
11326 X(_nop, bf00, f3af8000), \
11327 X(_yield, bf10, f3af8001), \
11328 X(_wfe, bf20, f3af8002), \
11329 X(_wfi, bf30, f3af8003), \
11330 X(_wls, 0000, f040c001), \
11331 X(_wlstp, 0000, f000c001), \
11332 X(_sev, bf40, f3af8004), \
11333 X(_sevl, bf50, f3af8005), \
11334 X(_udf, de00, f7f0a000)
11336 /* To catch errors in encoding functions, the codes are all offset by
11337 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11338 as 16-bit instructions. */
11339 #define X(a,b,c) T_MNEM##a
11340 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11341 #undef X
11343 #define X(a,b,c) 0x##b
11344 static const unsigned short thumb_op16[] = { T16_32_TAB };
11345 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11346 #undef X
11348 #define X(a,b,c) 0x##c
11349 static const unsigned int thumb_op32[] = { T16_32_TAB };
11350 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11351 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
11352 #undef X
11353 #undef T16_32_TAB
11355 /* Thumb instruction encoders, in alphabetical order. */
11357 /* ADDW or SUBW. */
11359 static void
11360 do_t_add_sub_w (void)
11362 int Rd, Rn;
11364 Rd = inst.operands[0].reg;
11365 Rn = inst.operands[1].reg;
11367 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11368 is the SP-{plus,minus}-immediate form of the instruction. */
11369 if (Rn == REG_SP)
11370 constraint (Rd == REG_PC, BAD_PC);
11371 else
11372 reject_bad_reg (Rd);
11374 inst.instruction |= (Rn << 16) | (Rd << 8);
11375 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11378 /* Parse an add or subtract instruction. We get here with inst.instruction
11379 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
11381 static void
11382 do_t_add_sub (void)
11384 int Rd, Rs, Rn;
11386 Rd = inst.operands[0].reg;
11387 Rs = (inst.operands[1].present
11388 ? inst.operands[1].reg /* Rd, Rs, foo */
11389 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11391 if (Rd == REG_PC)
11392 set_pred_insn_type_last ();
11394 if (unified_syntax)
11396 bool flags;
11397 bool narrow;
11398 int opcode;
11400 flags = (inst.instruction == T_MNEM_adds
11401 || inst.instruction == T_MNEM_subs);
11402 if (flags)
11403 narrow = !in_pred_block ();
11404 else
11405 narrow = in_pred_block ();
11406 if (!inst.operands[2].isreg)
11408 int add;
11410 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11411 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11413 add = (inst.instruction == T_MNEM_add
11414 || inst.instruction == T_MNEM_adds);
11415 opcode = 0;
11416 if (inst.size_req != 4)
11418 /* Attempt to use a narrow opcode, with relaxation if
11419 appropriate. */
11420 if (Rd == REG_SP && Rs == REG_SP && !flags)
11421 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11422 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11423 opcode = T_MNEM_add_sp;
11424 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11425 opcode = T_MNEM_add_pc;
11426 else if (Rd <= 7 && Rs <= 7 && narrow)
11428 if (flags)
11429 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11430 else
11431 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11433 if (opcode)
11435 inst.instruction = THUMB_OP16(opcode);
11436 inst.instruction |= (Rd << 4) | Rs;
11437 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11438 || (inst.relocs[0].type
11439 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
11441 if (inst.size_req == 2)
11442 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11443 else
11444 inst.relax = opcode;
11447 else
11448 constraint (inst.size_req == 2, _("cannot honor width suffix"));
11450 if (inst.size_req == 4
11451 || (inst.size_req != 2 && !opcode))
11453 constraint ((inst.relocs[0].type
11454 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11455 && (inst.relocs[0].type
11456 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
11457 THUMB1_RELOC_ONLY);
11458 if (Rd == REG_PC)
11460 constraint (add, BAD_PC);
11461 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11462 _("only SUBS PC, LR, #const allowed"));
11463 constraint (inst.relocs[0].exp.X_op != O_constant,
11464 _("expression too complex"));
11465 constraint (inst.relocs[0].exp.X_add_number < 0
11466 || inst.relocs[0].exp.X_add_number > 0xff,
11467 _("immediate value out of range"));
11468 inst.instruction = T2_SUBS_PC_LR
11469 | inst.relocs[0].exp.X_add_number;
11470 inst.relocs[0].type = BFD_RELOC_UNUSED;
11471 return;
11473 else if (Rs == REG_PC)
11475 /* Always use addw/subw. */
11476 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
11477 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11479 else
11481 inst.instruction = THUMB_OP32 (inst.instruction);
11482 inst.instruction = (inst.instruction & 0xe1ffffff)
11483 | 0x10000000;
11484 if (flags)
11485 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11486 else
11487 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
11489 inst.instruction |= Rd << 8;
11490 inst.instruction |= Rs << 16;
11493 else
11495 unsigned int value = inst.relocs[0].exp.X_add_number;
11496 unsigned int shift = inst.operands[2].shift_kind;
11498 Rn = inst.operands[2].reg;
11499 /* See if we can do this with a 16-bit instruction. */
11500 if (!inst.operands[2].shifted && inst.size_req != 4)
11502 if (Rd > 7 || Rs > 7 || Rn > 7)
11503 narrow = false;
11505 if (narrow)
11507 inst.instruction = ((inst.instruction == T_MNEM_adds
11508 || inst.instruction == T_MNEM_add)
11509 ? T_OPCODE_ADD_R3
11510 : T_OPCODE_SUB_R3);
11511 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11512 return;
11515 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
11517 /* Thumb-1 cores (except v6-M) require at least one high
11518 register in a narrow non flag setting add. */
11519 if (Rd > 7 || Rn > 7
11520 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11521 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
11523 if (Rd == Rn)
11525 Rn = Rs;
11526 Rs = Rd;
11528 inst.instruction = T_OPCODE_ADD_HI;
11529 inst.instruction |= (Rd & 8) << 4;
11530 inst.instruction |= (Rd & 7);
11531 inst.instruction |= Rn << 3;
11532 return;
11537 constraint (Rd == REG_PC, BAD_PC);
11538 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11539 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11540 constraint (Rs == REG_PC, BAD_PC);
11541 reject_bad_reg (Rn);
11543 /* If we get here, it can't be done in 16 bits. */
11544 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11545 _("shift must be constant"));
11546 inst.instruction = THUMB_OP32 (inst.instruction);
11547 inst.instruction |= Rd << 8;
11548 inst.instruction |= Rs << 16;
11549 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11550 _("shift value over 3 not allowed in thumb mode"));
11551 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11552 _("only LSL shift allowed in thumb mode"));
11553 encode_thumb32_shifted_operand (2);
11556 else
11558 constraint (inst.instruction == T_MNEM_adds
11559 || inst.instruction == T_MNEM_subs,
11560 BAD_THUMB32);
11562 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
11564 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11565 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11566 BAD_HIREG);
11568 inst.instruction = (inst.instruction == T_MNEM_add
11569 ? 0x0000 : 0x8000);
11570 inst.instruction |= (Rd << 4) | Rs;
11571 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11572 return;
11575 Rn = inst.operands[2].reg;
11576 constraint (inst.operands[2].shifted, _("unshifted register required"));
11578 /* We now have Rd, Rs, and Rn set to registers. */
11579 if (Rd > 7 || Rs > 7 || Rn > 7)
11581 /* Can't do this for SUB. */
11582 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11583 inst.instruction = T_OPCODE_ADD_HI;
11584 inst.instruction |= (Rd & 8) << 4;
11585 inst.instruction |= (Rd & 7);
11586 if (Rs == Rd)
11587 inst.instruction |= Rn << 3;
11588 else if (Rn == Rd)
11589 inst.instruction |= Rs << 3;
11590 else
11591 constraint (1, _("dest must overlap one source register"));
11593 else
11595 inst.instruction = (inst.instruction == T_MNEM_add
11596 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11597 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11602 static void
11603 do_t_adr (void)
11605 unsigned Rd;
11607 Rd = inst.operands[0].reg;
11608 reject_bad_reg (Rd);
11610 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
11612 /* Defer to section relaxation. */
11613 inst.relax = inst.instruction;
11614 inst.instruction = THUMB_OP16 (inst.instruction);
11615 inst.instruction |= Rd << 4;
11617 else if (unified_syntax && inst.size_req != 2)
11619 /* Generate a 32-bit opcode. */
11620 inst.instruction = THUMB_OP32 (inst.instruction);
11621 inst.instruction |= Rd << 8;
11622 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11623 inst.relocs[0].pc_rel = 1;
11625 else
11627 /* Generate a 16-bit opcode. */
11628 inst.instruction = THUMB_OP16 (inst.instruction);
11629 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11630 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11631 inst.relocs[0].pc_rel = 1;
11632 inst.instruction |= Rd << 4;
11635 if (inst.relocs[0].exp.X_op == O_symbol
11636 && inst.relocs[0].exp.X_add_symbol != NULL
11637 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11638 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11639 inst.relocs[0].exp.X_add_number += 1;
11642 /* Arithmetic instructions for which there is just one 16-bit
11643 instruction encoding, and it allows only two low registers.
11644 For maximal compatibility with ARM syntax, we allow three register
11645 operands even when Thumb-32 instructions are not available, as long
11646 as the first two are identical. For instance, both "sbc r0,r1" and
11647 "sbc r0,r0,r1" are allowed. */
11648 static void
11649 do_t_arit3 (void)
11651 int Rd, Rs, Rn;
11653 Rd = inst.operands[0].reg;
11654 Rs = (inst.operands[1].present
11655 ? inst.operands[1].reg /* Rd, Rs, foo */
11656 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11657 Rn = inst.operands[2].reg;
11659 reject_bad_reg (Rd);
11660 reject_bad_reg (Rs);
11661 if (inst.operands[2].isreg)
11662 reject_bad_reg (Rn);
11664 if (unified_syntax)
11666 if (!inst.operands[2].isreg)
11668 /* For an immediate, we always generate a 32-bit opcode;
11669 section relaxation will shrink it later if possible. */
11670 inst.instruction = THUMB_OP32 (inst.instruction);
11671 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11672 inst.instruction |= Rd << 8;
11673 inst.instruction |= Rs << 16;
11674 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11676 else
11678 bool narrow;
11680 /* See if we can do this with a 16-bit instruction. */
11681 if (THUMB_SETS_FLAGS (inst.instruction))
11682 narrow = !in_pred_block ();
11683 else
11684 narrow = in_pred_block ();
11686 if (Rd > 7 || Rn > 7 || Rs > 7)
11687 narrow = false;
11688 if (inst.operands[2].shifted)
11689 narrow = false;
11690 if (inst.size_req == 4)
11691 narrow = false;
11693 if (narrow
11694 && Rd == Rs)
11696 inst.instruction = THUMB_OP16 (inst.instruction);
11697 inst.instruction |= Rd;
11698 inst.instruction |= Rn << 3;
11699 return;
11702 /* If we get here, it can't be done in 16 bits. */
11703 constraint (inst.operands[2].shifted
11704 && inst.operands[2].immisreg,
11705 _("shift must be constant"));
11706 inst.instruction = THUMB_OP32 (inst.instruction);
11707 inst.instruction |= Rd << 8;
11708 inst.instruction |= Rs << 16;
11709 encode_thumb32_shifted_operand (2);
11712 else
11714 /* On its face this is a lie - the instruction does set the
11715 flags. However, the only supported mnemonic in this mode
11716 says it doesn't. */
11717 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11719 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11720 _("unshifted register required"));
11721 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11722 constraint (Rd != Rs,
11723 _("dest and source1 must be the same register"));
11725 inst.instruction = THUMB_OP16 (inst.instruction);
11726 inst.instruction |= Rd;
11727 inst.instruction |= Rn << 3;
11731 /* Similarly, but for instructions where the arithmetic operation is
11732 commutative, so we can allow either of them to be different from
11733 the destination operand in a 16-bit instruction. For instance, all
11734 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11735 accepted. */
11736 static void
11737 do_t_arit3c (void)
11739 int Rd, Rs, Rn;
11741 Rd = inst.operands[0].reg;
11742 Rs = (inst.operands[1].present
11743 ? inst.operands[1].reg /* Rd, Rs, foo */
11744 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11745 Rn = inst.operands[2].reg;
11747 reject_bad_reg (Rd);
11748 reject_bad_reg (Rs);
11749 if (inst.operands[2].isreg)
11750 reject_bad_reg (Rn);
11752 if (unified_syntax)
11754 if (!inst.operands[2].isreg)
11756 /* For an immediate, we always generate a 32-bit opcode;
11757 section relaxation will shrink it later if possible. */
11758 inst.instruction = THUMB_OP32 (inst.instruction);
11759 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11760 inst.instruction |= Rd << 8;
11761 inst.instruction |= Rs << 16;
11762 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11764 else
11766 bool narrow;
11768 /* See if we can do this with a 16-bit instruction. */
11769 if (THUMB_SETS_FLAGS (inst.instruction))
11770 narrow = !in_pred_block ();
11771 else
11772 narrow = in_pred_block ();
11774 if (Rd > 7 || Rn > 7 || Rs > 7)
11775 narrow = false;
11776 if (inst.operands[2].shifted)
11777 narrow = false;
11778 if (inst.size_req == 4)
11779 narrow = false;
11781 if (narrow)
11783 if (Rd == Rs)
11785 inst.instruction = THUMB_OP16 (inst.instruction);
11786 inst.instruction |= Rd;
11787 inst.instruction |= Rn << 3;
11788 return;
11790 if (Rd == Rn)
11792 inst.instruction = THUMB_OP16 (inst.instruction);
11793 inst.instruction |= Rd;
11794 inst.instruction |= Rs << 3;
11795 return;
11799 /* If we get here, it can't be done in 16 bits. */
11800 constraint (inst.operands[2].shifted
11801 && inst.operands[2].immisreg,
11802 _("shift must be constant"));
11803 inst.instruction = THUMB_OP32 (inst.instruction);
11804 inst.instruction |= Rd << 8;
11805 inst.instruction |= Rs << 16;
11806 encode_thumb32_shifted_operand (2);
11809 else
11811 /* On its face this is a lie - the instruction does set the
11812 flags. However, the only supported mnemonic in this mode
11813 says it doesn't. */
11814 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11816 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11817 _("unshifted register required"));
11818 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11820 inst.instruction = THUMB_OP16 (inst.instruction);
11821 inst.instruction |= Rd;
11823 if (Rd == Rs)
11824 inst.instruction |= Rn << 3;
11825 else if (Rd == Rn)
11826 inst.instruction |= Rs << 3;
11827 else
11828 constraint (1, _("dest must overlap one source register"));
11832 static void
11833 do_t_bfc (void)
11835 unsigned Rd;
11836 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11837 constraint (msb > 32, _("bit-field extends past end of register"));
11838 /* The instruction encoding stores the LSB and MSB,
11839 not the LSB and width. */
11840 Rd = inst.operands[0].reg;
11841 reject_bad_reg (Rd);
11842 inst.instruction |= Rd << 8;
11843 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11844 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11845 inst.instruction |= msb - 1;
11848 static void
11849 do_t_bfi (void)
11851 int Rd, Rn;
11852 unsigned int msb;
11854 Rd = inst.operands[0].reg;
11855 reject_bad_reg (Rd);
11857 /* #0 in second position is alternative syntax for bfc, which is
11858 the same instruction but with REG_PC in the Rm field. */
11859 if (!inst.operands[1].isreg)
11860 Rn = REG_PC;
11861 else
11863 Rn = inst.operands[1].reg;
11864 reject_bad_reg (Rn);
11867 msb = inst.operands[2].imm + inst.operands[3].imm;
11868 constraint (msb > 32, _("bit-field extends past end of register"));
11869 /* The instruction encoding stores the LSB and MSB,
11870 not the LSB and width. */
11871 inst.instruction |= Rd << 8;
11872 inst.instruction |= Rn << 16;
11873 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11874 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11875 inst.instruction |= msb - 1;
11878 static void
11879 do_t_bfx (void)
11881 unsigned Rd, Rn;
11883 Rd = inst.operands[0].reg;
11884 Rn = inst.operands[1].reg;
11886 reject_bad_reg (Rd);
11887 reject_bad_reg (Rn);
11889 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11890 _("bit-field extends past end of register"));
11891 inst.instruction |= Rd << 8;
11892 inst.instruction |= Rn << 16;
11893 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11894 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11895 inst.instruction |= inst.operands[3].imm - 1;
11898 /* ARM V5 Thumb BLX (argument parse)
11899 BLX <target_addr> which is BLX(1)
11900 BLX <Rm> which is BLX(2)
11901 Unfortunately, there are two different opcodes for this mnemonic.
11902 So, the insns[].value is not used, and the code here zaps values
11903 into inst.instruction.
11905 ??? How to take advantage of the additional two bits of displacement
11906 available in Thumb32 mode? Need new relocation? */
11908 static void
11909 do_t_blx (void)
11911 set_pred_insn_type_last ();
11913 if (inst.operands[0].isreg)
11915 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11916 /* We have a register, so this is BLX(2). */
11917 inst.instruction |= inst.operands[0].reg << 3;
11919 else
11921 /* No register. This must be BLX(1). */
11922 inst.instruction = 0xf000e800;
11923 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
11927 static void
11928 do_t_branch (void)
11930 int opcode;
11931 int cond;
11932 bfd_reloc_code_real_type reloc;
11934 cond = inst.cond;
11935 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
11937 if (in_pred_block ())
11939 /* Conditional branches inside IT blocks are encoded as unconditional
11940 branches. */
11941 cond = COND_ALWAYS;
11943 else
11944 cond = inst.cond;
11946 if (cond != COND_ALWAYS)
11947 opcode = T_MNEM_bcond;
11948 else
11949 opcode = inst.instruction;
11951 if (unified_syntax
11952 && (inst.size_req == 4
11953 || (inst.size_req != 2
11954 && (inst.operands[0].hasreloc
11955 || inst.relocs[0].exp.X_op == O_constant))))
11957 inst.instruction = THUMB_OP32(opcode);
11958 if (cond == COND_ALWAYS)
11959 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
11960 else
11962 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11963 _("selected architecture does not support "
11964 "wide conditional branch instruction"));
11966 gas_assert (cond != 0xF);
11967 inst.instruction |= cond << 22;
11968 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
11971 else
11973 inst.instruction = THUMB_OP16(opcode);
11974 if (cond == COND_ALWAYS)
11975 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
11976 else
11978 inst.instruction |= cond << 8;
11979 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
11981 /* Allow section relaxation. */
11982 if (unified_syntax && inst.size_req != 2)
11983 inst.relax = opcode;
11985 inst.relocs[0].type = reloc;
11986 inst.relocs[0].pc_rel = 1;
11989 /* Actually do the work for Thumb state bkpt and hlt. The only difference
11990 between the two is the maximum immediate allowed - which is passed in
11991 RANGE. */
11992 static void
11993 do_t_bkpt_hlt1 (int range)
11995 constraint (inst.cond != COND_ALWAYS,
11996 _("instruction is always unconditional"));
11997 if (inst.operands[0].present)
11999 constraint (inst.operands[0].imm > range,
12000 _("immediate value out of range"));
12001 inst.instruction |= inst.operands[0].imm;
12004 set_pred_insn_type (NEUTRAL_IT_INSN);
12007 static void
12008 do_t_hlt (void)
12010 do_t_bkpt_hlt1 (63);
12013 static void
12014 do_t_bkpt (void)
12016 do_t_bkpt_hlt1 (255);
12019 static void
12020 do_t_branch23 (void)
12022 set_pred_insn_type_last ();
12023 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
12025 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12026 this file. We used to simply ignore the PLT reloc type here --
12027 the branch encoding is now needed to deal with TLSCALL relocs.
12028 So if we see a PLT reloc now, put it back to how it used to be to
12029 keep the preexisting behaviour. */
12030 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12031 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
12033 #if defined(OBJ_COFF)
12034 /* If the destination of the branch is a defined symbol which does not have
12035 the THUMB_FUNC attribute, then we must be calling a function which has
12036 the (interfacearm) attribute. We look for the Thumb entry point to that
12037 function and change the branch to refer to that function instead. */
12038 if ( inst.relocs[0].exp.X_op == O_symbol
12039 && inst.relocs[0].exp.X_add_symbol != NULL
12040 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12041 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12042 inst.relocs[0].exp.X_add_symbol
12043 = find_real_start (inst.relocs[0].exp.X_add_symbol);
12044 #endif
12047 static void
12048 do_t_bx (void)
12050 set_pred_insn_type_last ();
12051 inst.instruction |= inst.operands[0].reg << 3;
12052 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12053 should cause the alignment to be checked once it is known. This is
12054 because BX PC only works if the instruction is word aligned. */
12057 static void
12058 do_t_bxj (void)
12060 int Rm;
12062 set_pred_insn_type_last ();
12063 Rm = inst.operands[0].reg;
12064 reject_bad_reg (Rm);
12065 inst.instruction |= Rm << 16;
12068 static void
12069 do_t_clz (void)
12071 unsigned Rd;
12072 unsigned Rm;
12074 Rd = inst.operands[0].reg;
12075 Rm = inst.operands[1].reg;
12077 reject_bad_reg (Rd);
12078 reject_bad_reg (Rm);
12080 inst.instruction |= Rd << 8;
12081 inst.instruction |= Rm << 16;
12082 inst.instruction |= Rm;
12085 /* For the Armv8.1-M conditional instructions. */
12086 static void
12087 do_t_cond (void)
12089 unsigned Rd, Rn, Rm;
12090 signed int cond;
12092 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12094 Rd = inst.operands[0].reg;
12095 switch (inst.instruction)
12097 case T_MNEM_csinc:
12098 case T_MNEM_csinv:
12099 case T_MNEM_csneg:
12100 case T_MNEM_csel:
12101 Rn = inst.operands[1].reg;
12102 Rm = inst.operands[2].reg;
12103 cond = inst.operands[3].imm;
12104 constraint (Rn == REG_SP, BAD_SP);
12105 constraint (Rm == REG_SP, BAD_SP);
12106 break;
12108 case T_MNEM_cinc:
12109 case T_MNEM_cinv:
12110 case T_MNEM_cneg:
12111 Rn = inst.operands[1].reg;
12112 cond = inst.operands[2].imm;
12113 /* Invert the last bit to invert the cond. */
12114 cond = TOGGLE_BIT (cond, 0);
12115 constraint (Rn == REG_SP, BAD_SP);
12116 Rm = Rn;
12117 break;
12119 case T_MNEM_csetm:
12120 case T_MNEM_cset:
12121 cond = inst.operands[1].imm;
12122 /* Invert the last bit to invert the cond. */
12123 cond = TOGGLE_BIT (cond, 0);
12124 Rn = REG_PC;
12125 Rm = REG_PC;
12126 break;
12128 default: abort ();
12131 set_pred_insn_type (OUTSIDE_PRED_INSN);
12132 inst.instruction = THUMB_OP32 (inst.instruction);
12133 inst.instruction |= Rd << 8;
12134 inst.instruction |= Rn << 16;
12135 inst.instruction |= Rm;
12136 inst.instruction |= cond << 4;
12139 static void
12140 do_t_csdb (void)
12142 set_pred_insn_type (OUTSIDE_PRED_INSN);
12145 static void
12146 do_t_cps (void)
12148 set_pred_insn_type (OUTSIDE_PRED_INSN);
12149 inst.instruction |= inst.operands[0].imm;
12152 static void
12153 do_t_cpsi (void)
12155 set_pred_insn_type (OUTSIDE_PRED_INSN);
12156 if (unified_syntax
12157 && (inst.operands[1].present || inst.size_req == 4)
12158 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
12160 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12161 inst.instruction = 0xf3af8000;
12162 inst.instruction |= imod << 9;
12163 inst.instruction |= inst.operands[0].imm << 5;
12164 if (inst.operands[1].present)
12165 inst.instruction |= 0x100 | inst.operands[1].imm;
12167 else
12169 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12170 && (inst.operands[0].imm & 4),
12171 _("selected processor does not support 'A' form "
12172 "of this instruction"));
12173 constraint (inst.operands[1].present || inst.size_req == 4,
12174 _("Thumb does not support the 2-argument "
12175 "form of this instruction"));
12176 inst.instruction |= inst.operands[0].imm;
12180 /* THUMB CPY instruction (argument parse). */
12182 static void
12183 do_t_cpy (void)
12185 if (inst.size_req == 4)
12187 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12188 inst.instruction |= inst.operands[0].reg << 8;
12189 inst.instruction |= inst.operands[1].reg;
12191 else
12193 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12194 inst.instruction |= (inst.operands[0].reg & 0x7);
12195 inst.instruction |= inst.operands[1].reg << 3;
12199 static void
12200 do_t_cbz (void)
12202 set_pred_insn_type (OUTSIDE_PRED_INSN);
12203 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12204 inst.instruction |= inst.operands[0].reg;
12205 inst.relocs[0].pc_rel = 1;
12206 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
12209 static void
12210 do_t_dbg (void)
12212 inst.instruction |= inst.operands[0].imm;
12215 static void
12216 do_t_div (void)
12218 unsigned Rd, Rn, Rm;
12220 Rd = inst.operands[0].reg;
12221 Rn = (inst.operands[1].present
12222 ? inst.operands[1].reg : Rd);
12223 Rm = inst.operands[2].reg;
12225 reject_bad_reg (Rd);
12226 reject_bad_reg (Rn);
12227 reject_bad_reg (Rm);
12229 inst.instruction |= Rd << 8;
12230 inst.instruction |= Rn << 16;
12231 inst.instruction |= Rm;
12234 static void
12235 do_t_hint (void)
12237 if (unified_syntax && inst.size_req == 4)
12238 inst.instruction = THUMB_OP32 (inst.instruction);
12239 else
12240 inst.instruction = THUMB_OP16 (inst.instruction);
12243 static void
12244 do_t_it (void)
12246 unsigned int cond = inst.operands[0].imm;
12248 set_pred_insn_type (IT_INSN);
12249 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12250 now_pred.cc = cond;
12251 now_pred.warn_deprecated = false;
12252 now_pred.type = SCALAR_PRED;
12254 /* If the condition is a negative condition, invert the mask. */
12255 if ((cond & 0x1) == 0x0)
12257 unsigned int mask = inst.instruction & 0x000f;
12259 if ((mask & 0x7) == 0)
12261 /* No conversion needed. */
12262 now_pred.block_length = 1;
12264 else if ((mask & 0x3) == 0)
12266 mask ^= 0x8;
12267 now_pred.block_length = 2;
12269 else if ((mask & 0x1) == 0)
12271 mask ^= 0xC;
12272 now_pred.block_length = 3;
12274 else
12276 mask ^= 0xE;
12277 now_pred.block_length = 4;
12280 inst.instruction &= 0xfff0;
12281 inst.instruction |= mask;
12284 inst.instruction |= cond << 4;
12287 /* Helper function used for both push/pop and ldm/stm. */
12288 static void
12289 encode_thumb2_multi (bool do_io, int base, unsigned mask,
12290 bool writeback)
12292 bool load, store;
12294 gas_assert (base != -1 || !do_io);
12295 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12296 store = do_io && !load;
12298 if (mask & (1 << 13))
12299 inst.error = _("SP not allowed in register list");
12301 if (do_io && (mask & (1 << base)) != 0
12302 && writeback)
12303 inst.error = _("having the base register in the register list when "
12304 "using write back is UNPREDICTABLE");
12306 if (load)
12308 if (mask & (1 << 15))
12310 if (mask & (1 << 14))
12311 inst.error = _("LR and PC should not both be in register list");
12312 else
12313 set_pred_insn_type_last ();
12316 else if (store)
12318 if (mask & (1 << 15))
12319 inst.error = _("PC not allowed in register list");
12322 if (do_io && ((mask & (mask - 1)) == 0))
12324 /* Single register transfers implemented as str/ldr. */
12325 if (writeback)
12327 if (inst.instruction & (1 << 23))
12328 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12329 else
12330 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12332 else
12334 if (inst.instruction & (1 << 23))
12335 inst.instruction = 0x00800000; /* ia -> [base] */
12336 else
12337 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12340 inst.instruction |= 0xf8400000;
12341 if (load)
12342 inst.instruction |= 0x00100000;
12344 mask = ffs (mask) - 1;
12345 mask <<= 12;
12347 else if (writeback)
12348 inst.instruction |= WRITE_BACK;
12350 inst.instruction |= mask;
12351 if (do_io)
12352 inst.instruction |= base << 16;
12355 static void
12356 do_t_ldmstm (void)
12358 /* This really doesn't seem worth it. */
12359 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12360 _("expression too complex"));
12361 constraint (inst.operands[1].writeback,
12362 _("Thumb load/store multiple does not support {reglist}^"));
12364 if (unified_syntax)
12366 bool narrow;
12367 unsigned mask;
12369 narrow = false;
12370 /* See if we can use a 16-bit instruction. */
12371 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12372 && inst.size_req != 4
12373 && !(inst.operands[1].imm & ~0xff))
12375 mask = 1 << inst.operands[0].reg;
12377 if (inst.operands[0].reg <= 7)
12379 if (inst.instruction == T_MNEM_stmia
12380 ? inst.operands[0].writeback
12381 : (inst.operands[0].writeback
12382 == !(inst.operands[1].imm & mask)))
12384 if (inst.instruction == T_MNEM_stmia
12385 && (inst.operands[1].imm & mask)
12386 && (inst.operands[1].imm & (mask - 1)))
12387 as_warn (_("value stored for r%d is UNKNOWN"),
12388 inst.operands[0].reg);
12390 inst.instruction = THUMB_OP16 (inst.instruction);
12391 inst.instruction |= inst.operands[0].reg << 8;
12392 inst.instruction |= inst.operands[1].imm;
12393 narrow = true;
12395 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12397 /* This means 1 register in reg list one of 3 situations:
12398 1. Instruction is stmia, but without writeback.
12399 2. lmdia without writeback, but with Rn not in
12400 reglist.
12401 3. ldmia with writeback, but with Rn in reglist.
12402 Case 3 is UNPREDICTABLE behaviour, so we handle
12403 case 1 and 2 which can be converted into a 16-bit
12404 str or ldr. The SP cases are handled below. */
12405 unsigned long opcode;
12406 /* First, record an error for Case 3. */
12407 if (inst.operands[1].imm & mask
12408 && inst.operands[0].writeback)
12409 inst.error =
12410 _("having the base register in the register list when "
12411 "using write back is UNPREDICTABLE");
12413 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
12414 : T_MNEM_ldr);
12415 inst.instruction = THUMB_OP16 (opcode);
12416 inst.instruction |= inst.operands[0].reg << 3;
12417 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12418 narrow = true;
12421 else if (inst.operands[0] .reg == REG_SP)
12423 if (inst.operands[0].writeback)
12425 inst.instruction =
12426 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12427 ? T_MNEM_push : T_MNEM_pop);
12428 inst.instruction |= inst.operands[1].imm;
12429 narrow = true;
12431 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12433 inst.instruction =
12434 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12435 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
12436 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
12437 narrow = true;
12442 if (!narrow)
12444 if (inst.instruction < 0xffff)
12445 inst.instruction = THUMB_OP32 (inst.instruction);
12447 encode_thumb2_multi (true /* do_io */, inst.operands[0].reg,
12448 inst.operands[1].imm,
12449 inst.operands[0].writeback);
12452 else
12454 constraint (inst.operands[0].reg > 7
12455 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
12456 constraint (inst.instruction != T_MNEM_ldmia
12457 && inst.instruction != T_MNEM_stmia,
12458 _("Thumb-2 instruction only valid in unified syntax"));
12459 if (inst.instruction == T_MNEM_stmia)
12461 if (!inst.operands[0].writeback)
12462 as_warn (_("this instruction will write back the base register"));
12463 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12464 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
12465 as_warn (_("value stored for r%d is UNKNOWN"),
12466 inst.operands[0].reg);
12468 else
12470 if (!inst.operands[0].writeback
12471 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12472 as_warn (_("this instruction will write back the base register"));
12473 else if (inst.operands[0].writeback
12474 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12475 as_warn (_("this instruction will not write back the base register"));
12478 inst.instruction = THUMB_OP16 (inst.instruction);
12479 inst.instruction |= inst.operands[0].reg << 8;
12480 inst.instruction |= inst.operands[1].imm;
12484 static void
12485 do_t_ldrex (void)
12487 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12488 || inst.operands[1].postind || inst.operands[1].writeback
12489 || inst.operands[1].immisreg || inst.operands[1].shifted
12490 || inst.operands[1].negative,
12491 BAD_ADDR_MODE);
12493 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12495 inst.instruction |= inst.operands[0].reg << 12;
12496 inst.instruction |= inst.operands[1].reg << 16;
12497 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
12500 static void
12501 do_t_ldrexd (void)
12503 if (!inst.operands[1].present)
12505 constraint (inst.operands[0].reg == REG_LR,
12506 _("r14 not allowed as first register "
12507 "when second register is omitted"));
12508 inst.operands[1].reg = inst.operands[0].reg + 1;
12510 constraint (inst.operands[0].reg == inst.operands[1].reg,
12511 BAD_OVERLAP);
12513 inst.instruction |= inst.operands[0].reg << 12;
12514 inst.instruction |= inst.operands[1].reg << 8;
12515 inst.instruction |= inst.operands[2].reg << 16;
12518 static void
12519 do_t_ldst (void)
12521 unsigned long opcode;
12522 int Rn;
12524 if (inst.operands[0].isreg
12525 && !inst.operands[0].preind
12526 && inst.operands[0].reg == REG_PC)
12527 set_pred_insn_type_last ();
12529 opcode = inst.instruction;
12530 if (unified_syntax)
12532 if (!inst.operands[1].isreg)
12534 if (opcode <= 0xffff)
12535 inst.instruction = THUMB_OP32 (opcode);
12536 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/false))
12537 return;
12539 if (inst.operands[1].isreg
12540 && !inst.operands[1].writeback
12541 && !inst.operands[1].shifted && !inst.operands[1].postind
12542 && !inst.operands[1].negative && inst.operands[0].reg <= 7
12543 && opcode <= 0xffff
12544 && inst.size_req != 4)
12546 /* Insn may have a 16-bit form. */
12547 Rn = inst.operands[1].reg;
12548 if (inst.operands[1].immisreg)
12550 inst.instruction = THUMB_OP16 (opcode);
12551 /* [Rn, Rik] */
12552 if (Rn <= 7 && inst.operands[1].imm <= 7)
12553 goto op16;
12554 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12555 reject_bad_reg (inst.operands[1].imm);
12557 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12558 && opcode != T_MNEM_ldrsb)
12559 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12560 || (Rn == REG_SP && opcode == T_MNEM_str))
12562 /* [Rn, #const] */
12563 if (Rn > 7)
12565 if (Rn == REG_PC)
12567 if (inst.relocs[0].pc_rel)
12568 opcode = T_MNEM_ldr_pc2;
12569 else
12570 opcode = T_MNEM_ldr_pc;
12572 else
12574 if (opcode == T_MNEM_ldr)
12575 opcode = T_MNEM_ldr_sp;
12576 else
12577 opcode = T_MNEM_str_sp;
12579 inst.instruction = inst.operands[0].reg << 8;
12581 else
12583 inst.instruction = inst.operands[0].reg;
12584 inst.instruction |= inst.operands[1].reg << 3;
12586 inst.instruction |= THUMB_OP16 (opcode);
12587 if (inst.size_req == 2)
12588 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12589 else
12590 inst.relax = opcode;
12591 return;
12594 /* Definitely a 32-bit variant. */
12596 /* Warning for Erratum 752419. */
12597 if (opcode == T_MNEM_ldr
12598 && inst.operands[0].reg == REG_SP
12599 && inst.operands[1].writeback == 1
12600 && !inst.operands[1].immisreg)
12602 if (no_cpu_selected ()
12603 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
12604 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12605 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
12606 as_warn (_("This instruction may be unpredictable "
12607 "if executed on M-profile cores "
12608 "with interrupts enabled."));
12611 /* Do some validations regarding addressing modes. */
12612 if (inst.operands[1].immisreg)
12613 reject_bad_reg (inst.operands[1].imm);
12615 constraint (inst.operands[1].writeback == 1
12616 && inst.operands[0].reg == inst.operands[1].reg,
12617 BAD_OVERLAP);
12619 inst.instruction = THUMB_OP32 (opcode);
12620 inst.instruction |= inst.operands[0].reg << 12;
12621 encode_thumb32_addr_mode (1, /*is_t=*/false, /*is_d=*/false);
12622 check_ldr_r15_aligned ();
12623 return;
12626 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12628 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
12630 /* Only [Rn,Rm] is acceptable. */
12631 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12632 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12633 || inst.operands[1].postind || inst.operands[1].shifted
12634 || inst.operands[1].negative,
12635 _("Thumb does not support this addressing mode"));
12636 inst.instruction = THUMB_OP16 (inst.instruction);
12637 goto op16;
12640 inst.instruction = THUMB_OP16 (inst.instruction);
12641 if (!inst.operands[1].isreg)
12642 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/false))
12643 return;
12645 constraint (!inst.operands[1].preind
12646 || inst.operands[1].shifted
12647 || inst.operands[1].writeback,
12648 _("Thumb does not support this addressing mode"));
12649 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
12651 constraint (inst.instruction & 0x0600,
12652 _("byte or halfword not valid for base register"));
12653 constraint (inst.operands[1].reg == REG_PC
12654 && !(inst.instruction & THUMB_LOAD_BIT),
12655 _("r15 based store not allowed"));
12656 constraint (inst.operands[1].immisreg,
12657 _("invalid base register for register offset"));
12659 if (inst.operands[1].reg == REG_PC)
12660 inst.instruction = T_OPCODE_LDR_PC;
12661 else if (inst.instruction & THUMB_LOAD_BIT)
12662 inst.instruction = T_OPCODE_LDR_SP;
12663 else
12664 inst.instruction = T_OPCODE_STR_SP;
12666 inst.instruction |= inst.operands[0].reg << 8;
12667 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12668 return;
12671 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12672 if (!inst.operands[1].immisreg)
12674 /* Immediate offset. */
12675 inst.instruction |= inst.operands[0].reg;
12676 inst.instruction |= inst.operands[1].reg << 3;
12677 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12678 return;
12681 /* Register offset. */
12682 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12683 constraint (inst.operands[1].negative,
12684 _("Thumb does not support this addressing mode"));
12686 op16:
12687 switch (inst.instruction)
12689 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12690 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12691 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12692 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12693 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12694 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12695 case 0x5600 /* ldrsb */:
12696 case 0x5e00 /* ldrsh */: break;
12697 default: abort ();
12700 inst.instruction |= inst.operands[0].reg;
12701 inst.instruction |= inst.operands[1].reg << 3;
12702 inst.instruction |= inst.operands[1].imm << 6;
12705 static void
12706 do_t_ldstd (void)
12708 if (!inst.operands[1].present)
12710 inst.operands[1].reg = inst.operands[0].reg + 1;
12711 constraint (inst.operands[0].reg == REG_LR,
12712 _("r14 not allowed here"));
12713 constraint (inst.operands[0].reg == REG_R12,
12714 _("r12 not allowed here"));
12717 if (inst.operands[2].writeback
12718 && (inst.operands[0].reg == inst.operands[2].reg
12719 || inst.operands[1].reg == inst.operands[2].reg))
12720 as_warn (_("base register written back, and overlaps "
12721 "one of transfer registers"));
12723 inst.instruction |= inst.operands[0].reg << 12;
12724 inst.instruction |= inst.operands[1].reg << 8;
12725 encode_thumb32_addr_mode (2, /*is_t=*/false, /*is_d=*/true);
12728 static void
12729 do_t_ldstt (void)
12731 inst.instruction |= inst.operands[0].reg << 12;
12732 encode_thumb32_addr_mode (1, /*is_t=*/true, /*is_d=*/false);
12735 static void
12736 do_t_mla (void)
12738 unsigned Rd, Rn, Rm, Ra;
12740 Rd = inst.operands[0].reg;
12741 Rn = inst.operands[1].reg;
12742 Rm = inst.operands[2].reg;
12743 Ra = inst.operands[3].reg;
12745 reject_bad_reg (Rd);
12746 reject_bad_reg (Rn);
12747 reject_bad_reg (Rm);
12748 reject_bad_reg (Ra);
12750 inst.instruction |= Rd << 8;
12751 inst.instruction |= Rn << 16;
12752 inst.instruction |= Rm;
12753 inst.instruction |= Ra << 12;
12756 static void
12757 do_t_mlal (void)
12759 unsigned RdLo, RdHi, Rn, Rm;
12761 RdLo = inst.operands[0].reg;
12762 RdHi = inst.operands[1].reg;
12763 Rn = inst.operands[2].reg;
12764 Rm = inst.operands[3].reg;
12766 reject_bad_reg (RdLo);
12767 reject_bad_reg (RdHi);
12768 reject_bad_reg (Rn);
12769 reject_bad_reg (Rm);
12771 inst.instruction |= RdLo << 12;
12772 inst.instruction |= RdHi << 8;
12773 inst.instruction |= Rn << 16;
12774 inst.instruction |= Rm;
12777 static void
12778 do_t_mov_cmp (void)
12780 unsigned Rn, Rm;
12782 Rn = inst.operands[0].reg;
12783 Rm = inst.operands[1].reg;
12785 if (Rn == REG_PC)
12786 set_pred_insn_type_last ();
12788 if (unified_syntax)
12790 int r0off = (inst.instruction == T_MNEM_mov
12791 || inst.instruction == T_MNEM_movs) ? 8 : 16;
12792 unsigned long opcode;
12793 bool narrow;
12794 bool low_regs;
12796 low_regs = (Rn <= 7 && Rm <= 7);
12797 opcode = inst.instruction;
12798 if (in_pred_block ())
12799 narrow = opcode != T_MNEM_movs;
12800 else
12801 narrow = opcode != T_MNEM_movs || low_regs;
12802 if (inst.size_req == 4
12803 || inst.operands[1].shifted)
12804 narrow = false;
12806 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12807 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12808 && !inst.operands[1].shifted
12809 && Rn == REG_PC
12810 && Rm == REG_LR)
12812 inst.instruction = T2_SUBS_PC_LR;
12813 return;
12816 if (opcode == T_MNEM_cmp)
12818 constraint (Rn == REG_PC, BAD_PC);
12819 if (narrow)
12821 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12822 but valid. */
12823 warn_deprecated_sp (Rm);
12824 /* R15 was documented as a valid choice for Rm in ARMv6,
12825 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12826 tools reject R15, so we do too. */
12827 constraint (Rm == REG_PC, BAD_PC);
12829 else
12830 reject_bad_reg (Rm);
12832 else if (opcode == T_MNEM_mov
12833 || opcode == T_MNEM_movs)
12835 if (inst.operands[1].isreg)
12837 if (opcode == T_MNEM_movs)
12839 reject_bad_reg (Rn);
12840 reject_bad_reg (Rm);
12842 else if (narrow)
12844 /* This is mov.n. */
12845 if ((Rn == REG_SP || Rn == REG_PC)
12846 && (Rm == REG_SP || Rm == REG_PC))
12848 as_tsktsk (_("Use of r%u as a source register is "
12849 "deprecated when r%u is the destination "
12850 "register."), Rm, Rn);
12853 else
12855 /* This is mov.w. */
12856 constraint (Rn == REG_PC, BAD_PC);
12857 constraint (Rm == REG_PC, BAD_PC);
12858 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12859 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
12862 else
12863 reject_bad_reg (Rn);
12866 if (!inst.operands[1].isreg)
12868 /* Immediate operand. */
12869 if (!in_pred_block () && opcode == T_MNEM_mov)
12870 narrow = 0;
12871 if (low_regs && narrow)
12873 inst.instruction = THUMB_OP16 (opcode);
12874 inst.instruction |= Rn << 8;
12875 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12876 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
12878 if (inst.size_req == 2)
12879 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
12880 else
12881 inst.relax = opcode;
12884 else
12886 constraint ((inst.relocs[0].type
12887 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12888 && (inst.relocs[0].type
12889 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
12890 THUMB1_RELOC_ONLY);
12892 inst.instruction = THUMB_OP32 (inst.instruction);
12893 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12894 inst.instruction |= Rn << r0off;
12895 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12898 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12899 && (inst.instruction == T_MNEM_mov
12900 || inst.instruction == T_MNEM_movs))
12902 /* Register shifts are encoded as separate shift instructions. */
12903 bool flags = (inst.instruction == T_MNEM_movs);
12905 if (in_pred_block ())
12906 narrow = !flags;
12907 else
12908 narrow = flags;
12910 if (inst.size_req == 4)
12911 narrow = false;
12913 if (!low_regs || inst.operands[1].imm > 7)
12914 narrow = false;
12916 if (Rn != Rm)
12917 narrow = false;
12919 switch (inst.operands[1].shift_kind)
12921 case SHIFT_LSL:
12922 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12923 break;
12924 case SHIFT_ASR:
12925 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12926 break;
12927 case SHIFT_LSR:
12928 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12929 break;
12930 case SHIFT_ROR:
12931 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12932 break;
12933 default:
12934 abort ();
12937 inst.instruction = opcode;
12938 if (narrow)
12940 inst.instruction |= Rn;
12941 inst.instruction |= inst.operands[1].imm << 3;
12943 else
12945 if (flags)
12946 inst.instruction |= CONDS_BIT;
12948 inst.instruction |= Rn << 8;
12949 inst.instruction |= Rm << 16;
12950 inst.instruction |= inst.operands[1].imm;
12953 else if (!narrow)
12955 /* Some mov with immediate shift have narrow variants.
12956 Register shifts are handled above. */
12957 if (low_regs && inst.operands[1].shifted
12958 && (inst.instruction == T_MNEM_mov
12959 || inst.instruction == T_MNEM_movs))
12961 if (in_pred_block ())
12962 narrow = (inst.instruction == T_MNEM_mov);
12963 else
12964 narrow = (inst.instruction == T_MNEM_movs);
12967 if (narrow)
12969 switch (inst.operands[1].shift_kind)
12971 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12972 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12973 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12974 default: narrow = false; break;
12978 if (narrow)
12980 inst.instruction |= Rn;
12981 inst.instruction |= Rm << 3;
12982 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
12984 else
12986 inst.instruction = THUMB_OP32 (inst.instruction);
12987 inst.instruction |= Rn << r0off;
12988 encode_thumb32_shifted_operand (1);
12991 else
12992 switch (inst.instruction)
12994 case T_MNEM_mov:
12995 /* In v4t or v5t a move of two lowregs produces unpredictable
12996 results. Don't allow this. */
12997 if (low_regs)
12999 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13000 "MOV Rd, Rs with two low registers is not "
13001 "permitted on this architecture");
13002 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13003 arm_ext_v6);
13006 inst.instruction = T_OPCODE_MOV_HR;
13007 inst.instruction |= (Rn & 0x8) << 4;
13008 inst.instruction |= (Rn & 0x7);
13009 inst.instruction |= Rm << 3;
13010 break;
13012 case T_MNEM_movs:
13013 /* We know we have low registers at this point.
13014 Generate LSLS Rd, Rs, #0. */
13015 inst.instruction = T_OPCODE_LSL_I;
13016 inst.instruction |= Rn;
13017 inst.instruction |= Rm << 3;
13018 break;
13020 case T_MNEM_cmp:
13021 if (low_regs)
13023 inst.instruction = T_OPCODE_CMP_LR;
13024 inst.instruction |= Rn;
13025 inst.instruction |= Rm << 3;
13027 else
13029 inst.instruction = T_OPCODE_CMP_HR;
13030 inst.instruction |= (Rn & 0x8) << 4;
13031 inst.instruction |= (Rn & 0x7);
13032 inst.instruction |= Rm << 3;
13034 break;
13036 return;
13039 inst.instruction = THUMB_OP16 (inst.instruction);
13041 /* PR 10443: Do not silently ignore shifted operands. */
13042 constraint (inst.operands[1].shifted,
13043 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13045 if (inst.operands[1].isreg)
13047 if (Rn < 8 && Rm < 8)
13049 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13050 since a MOV instruction produces unpredictable results. */
13051 if (inst.instruction == T_OPCODE_MOV_I8)
13052 inst.instruction = T_OPCODE_ADD_I3;
13053 else
13054 inst.instruction = T_OPCODE_CMP_LR;
13056 inst.instruction |= Rn;
13057 inst.instruction |= Rm << 3;
13059 else
13061 if (inst.instruction == T_OPCODE_MOV_I8)
13062 inst.instruction = T_OPCODE_MOV_HR;
13063 else
13064 inst.instruction = T_OPCODE_CMP_HR;
13065 do_t_cpy ();
13068 else
13070 constraint (Rn > 7,
13071 _("only lo regs allowed with immediate"));
13072 inst.instruction |= Rn << 8;
13073 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13077 static void
13078 do_t_mov16 (void)
13080 unsigned Rd;
13081 bfd_vma imm;
13082 bool top;
13084 top = (inst.instruction & 0x00800000) != 0;
13085 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
13087 constraint (top, _(":lower16: not allowed in this instruction"));
13088 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
13090 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
13092 constraint (!top, _(":upper16: not allowed in this instruction"));
13093 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
13096 Rd = inst.operands[0].reg;
13097 reject_bad_reg (Rd);
13099 inst.instruction |= Rd << 8;
13100 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
13102 imm = inst.relocs[0].exp.X_add_number;
13103 inst.instruction |= (imm & 0xf000) << 4;
13104 inst.instruction |= (imm & 0x0800) << 15;
13105 inst.instruction |= (imm & 0x0700) << 4;
13106 inst.instruction |= (imm & 0x00ff);
13110 static void
13111 do_t_mvn_tst (void)
13113 unsigned Rn, Rm;
13115 Rn = inst.operands[0].reg;
13116 Rm = inst.operands[1].reg;
13118 if (inst.instruction == T_MNEM_cmp
13119 || inst.instruction == T_MNEM_cmn)
13120 constraint (Rn == REG_PC, BAD_PC);
13121 else
13122 reject_bad_reg (Rn);
13123 reject_bad_reg (Rm);
13125 if (unified_syntax)
13127 int r0off = (inst.instruction == T_MNEM_mvn
13128 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
13129 bool narrow;
13131 if (inst.size_req == 4
13132 || inst.instruction > 0xffff
13133 || inst.operands[1].shifted
13134 || Rn > 7 || Rm > 7)
13135 narrow = false;
13136 else if (inst.instruction == T_MNEM_cmn
13137 || inst.instruction == T_MNEM_tst)
13138 narrow = true;
13139 else if (THUMB_SETS_FLAGS (inst.instruction))
13140 narrow = !in_pred_block ();
13141 else
13142 narrow = in_pred_block ();
13144 if (!inst.operands[1].isreg)
13146 /* For an immediate, we always generate a 32-bit opcode;
13147 section relaxation will shrink it later if possible. */
13148 if (inst.instruction < 0xffff)
13149 inst.instruction = THUMB_OP32 (inst.instruction);
13150 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13151 inst.instruction |= Rn << r0off;
13152 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13154 else
13156 /* See if we can do this with a 16-bit instruction. */
13157 if (narrow)
13159 inst.instruction = THUMB_OP16 (inst.instruction);
13160 inst.instruction |= Rn;
13161 inst.instruction |= Rm << 3;
13163 else
13165 constraint (inst.operands[1].shifted
13166 && inst.operands[1].immisreg,
13167 _("shift must be constant"));
13168 if (inst.instruction < 0xffff)
13169 inst.instruction = THUMB_OP32 (inst.instruction);
13170 inst.instruction |= Rn << r0off;
13171 encode_thumb32_shifted_operand (1);
13175 else
13177 constraint (inst.instruction > 0xffff
13178 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13179 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13180 _("unshifted register required"));
13181 constraint (Rn > 7 || Rm > 7,
13182 BAD_HIREG);
13184 inst.instruction = THUMB_OP16 (inst.instruction);
13185 inst.instruction |= Rn;
13186 inst.instruction |= Rm << 3;
13190 static void
13191 do_t_mrs (void)
13193 unsigned Rd;
13195 if (do_vfp_nsyn_mrs () == SUCCESS)
13196 return;
13198 Rd = inst.operands[0].reg;
13199 reject_bad_reg (Rd);
13200 inst.instruction |= Rd << 8;
13202 if (inst.operands[1].isreg)
13204 unsigned br = inst.operands[1].reg;
13205 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13206 as_bad (_("bad register for mrs"));
13208 inst.instruction |= br & (0xf << 16);
13209 inst.instruction |= (br & 0x300) >> 4;
13210 inst.instruction |= (br & SPSR_BIT) >> 2;
13212 else
13214 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13216 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13218 /* PR gas/12698: The constraint is only applied for m_profile.
13219 If the user has specified -march=all, we want to ignore it as
13220 we are building for any CPU type, including non-m variants. */
13221 bool m_profile =
13222 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13223 constraint ((flags != 0) && m_profile, _("selected processor does "
13224 "not support requested special purpose register"));
13226 else
13227 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13228 devices). */
13229 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13230 _("'APSR', 'CPSR' or 'SPSR' expected"));
13232 inst.instruction |= (flags & SPSR_BIT) >> 2;
13233 inst.instruction |= inst.operands[1].imm & 0xff;
13234 inst.instruction |= 0xf0000;
13238 static void
13239 do_t_msr (void)
13241 int flags;
13242 unsigned Rn;
13244 if (do_vfp_nsyn_msr () == SUCCESS)
13245 return;
13247 constraint (!inst.operands[1].isreg,
13248 _("Thumb encoding does not support an immediate here"));
13250 if (inst.operands[0].isreg)
13251 flags = (int)(inst.operands[0].reg);
13252 else
13253 flags = inst.operands[0].imm;
13255 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13257 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13259 /* PR gas/12698: The constraint is only applied for m_profile.
13260 If the user has specified -march=all, we want to ignore it as
13261 we are building for any CPU type, including non-m variants. */
13262 bool m_profile =
13263 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13264 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13265 && (bits & ~(PSR_s | PSR_f)) != 0)
13266 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13267 && bits != PSR_f)) && m_profile,
13268 _("selected processor does not support requested special "
13269 "purpose register"));
13271 else
13272 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13273 "requested special purpose register"));
13275 Rn = inst.operands[1].reg;
13276 reject_bad_reg (Rn);
13278 inst.instruction |= (flags & SPSR_BIT) >> 2;
13279 inst.instruction |= (flags & 0xf0000) >> 8;
13280 inst.instruction |= (flags & 0x300) >> 4;
13281 inst.instruction |= (flags & 0xff);
13282 inst.instruction |= Rn << 16;
13285 static void
13286 do_t_mul (void)
13288 bool narrow;
13289 unsigned Rd, Rn, Rm;
13291 if (!inst.operands[2].present)
13292 inst.operands[2].reg = inst.operands[0].reg;
13294 Rd = inst.operands[0].reg;
13295 Rn = inst.operands[1].reg;
13296 Rm = inst.operands[2].reg;
13298 if (unified_syntax)
13300 if (inst.size_req == 4
13301 || (Rd != Rn
13302 && Rd != Rm)
13303 || Rn > 7
13304 || Rm > 7)
13305 narrow = false;
13306 else if (inst.instruction == T_MNEM_muls)
13307 narrow = !in_pred_block ();
13308 else
13309 narrow = in_pred_block ();
13311 else
13313 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
13314 constraint (Rn > 7 || Rm > 7,
13315 BAD_HIREG);
13316 narrow = true;
13319 if (narrow)
13321 /* 16-bit MULS/Conditional MUL. */
13322 inst.instruction = THUMB_OP16 (inst.instruction);
13323 inst.instruction |= Rd;
13325 if (Rd == Rn)
13326 inst.instruction |= Rm << 3;
13327 else if (Rd == Rm)
13328 inst.instruction |= Rn << 3;
13329 else
13330 constraint (1, _("dest must overlap one source register"));
13332 else
13334 constraint (inst.instruction != T_MNEM_mul,
13335 _("Thumb-2 MUL must not set flags"));
13336 /* 32-bit MUL. */
13337 inst.instruction = THUMB_OP32 (inst.instruction);
13338 inst.instruction |= Rd << 8;
13339 inst.instruction |= Rn << 16;
13340 inst.instruction |= Rm << 0;
13342 reject_bad_reg (Rd);
13343 reject_bad_reg (Rn);
13344 reject_bad_reg (Rm);
13348 static void
13349 do_t_mull (void)
13351 unsigned RdLo, RdHi, Rn, Rm;
13353 RdLo = inst.operands[0].reg;
13354 RdHi = inst.operands[1].reg;
13355 Rn = inst.operands[2].reg;
13356 Rm = inst.operands[3].reg;
13358 reject_bad_reg (RdLo);
13359 reject_bad_reg (RdHi);
13360 reject_bad_reg (Rn);
13361 reject_bad_reg (Rm);
13363 inst.instruction |= RdLo << 12;
13364 inst.instruction |= RdHi << 8;
13365 inst.instruction |= Rn << 16;
13366 inst.instruction |= Rm;
13368 if (RdLo == RdHi)
13369 as_tsktsk (_("rdhi and rdlo must be different"));
13372 static void
13373 do_t_nop (void)
13375 set_pred_insn_type (NEUTRAL_IT_INSN);
13377 if (unified_syntax)
13379 if (inst.size_req == 4 || inst.operands[0].imm > 15)
13381 inst.instruction = THUMB_OP32 (inst.instruction);
13382 inst.instruction |= inst.operands[0].imm;
13384 else
13386 /* PR9722: Check for Thumb2 availability before
13387 generating a thumb2 nop instruction. */
13388 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
13390 inst.instruction = THUMB_OP16 (inst.instruction);
13391 inst.instruction |= inst.operands[0].imm << 4;
13393 else
13394 inst.instruction = 0x46c0;
13397 else
13399 constraint (inst.operands[0].present,
13400 _("Thumb does not support NOP with hints"));
13401 inst.instruction = 0x46c0;
13405 static void
13406 do_t_neg (void)
13408 if (unified_syntax)
13410 bool narrow;
13412 if (THUMB_SETS_FLAGS (inst.instruction))
13413 narrow = !in_pred_block ();
13414 else
13415 narrow = in_pred_block ();
13416 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13417 narrow = false;
13418 if (inst.size_req == 4)
13419 narrow = false;
13421 if (!narrow)
13423 inst.instruction = THUMB_OP32 (inst.instruction);
13424 inst.instruction |= inst.operands[0].reg << 8;
13425 inst.instruction |= inst.operands[1].reg << 16;
13427 else
13429 inst.instruction = THUMB_OP16 (inst.instruction);
13430 inst.instruction |= inst.operands[0].reg;
13431 inst.instruction |= inst.operands[1].reg << 3;
13434 else
13436 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13437 BAD_HIREG);
13438 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13440 inst.instruction = THUMB_OP16 (inst.instruction);
13441 inst.instruction |= inst.operands[0].reg;
13442 inst.instruction |= inst.operands[1].reg << 3;
13446 static void
13447 do_t_orn (void)
13449 unsigned Rd, Rn;
13451 Rd = inst.operands[0].reg;
13452 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13454 reject_bad_reg (Rd);
13455 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13456 reject_bad_reg (Rn);
13458 inst.instruction |= Rd << 8;
13459 inst.instruction |= Rn << 16;
13461 if (!inst.operands[2].isreg)
13463 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13464 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13466 else
13468 unsigned Rm;
13470 Rm = inst.operands[2].reg;
13471 reject_bad_reg (Rm);
13473 constraint (inst.operands[2].shifted
13474 && inst.operands[2].immisreg,
13475 _("shift must be constant"));
13476 encode_thumb32_shifted_operand (2);
13480 static void
13481 do_t_pkhbt (void)
13483 unsigned Rd, Rn, Rm;
13485 Rd = inst.operands[0].reg;
13486 Rn = inst.operands[1].reg;
13487 Rm = inst.operands[2].reg;
13489 reject_bad_reg (Rd);
13490 reject_bad_reg (Rn);
13491 reject_bad_reg (Rm);
13493 inst.instruction |= Rd << 8;
13494 inst.instruction |= Rn << 16;
13495 inst.instruction |= Rm;
13496 if (inst.operands[3].present)
13498 unsigned int val = inst.relocs[0].exp.X_add_number;
13499 constraint (inst.relocs[0].exp.X_op != O_constant,
13500 _("expression too complex"));
13501 inst.instruction |= (val & 0x1c) << 10;
13502 inst.instruction |= (val & 0x03) << 6;
13506 static void
13507 do_t_pkhtb (void)
13509 if (!inst.operands[3].present)
13511 unsigned Rtmp;
13513 inst.instruction &= ~0x00000020;
13515 /* PR 10168. Swap the Rm and Rn registers. */
13516 Rtmp = inst.operands[1].reg;
13517 inst.operands[1].reg = inst.operands[2].reg;
13518 inst.operands[2].reg = Rtmp;
13520 do_t_pkhbt ();
13523 static void
13524 do_t_pld (void)
13526 if (inst.operands[0].immisreg)
13527 reject_bad_reg (inst.operands[0].imm);
13529 encode_thumb32_addr_mode (0, /*is_t=*/false, /*is_d=*/false);
13532 static void
13533 do_t_push_pop (void)
13535 unsigned mask;
13537 constraint (inst.operands[0].writeback,
13538 _("push/pop do not support {reglist}^"));
13539 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
13540 _("expression too complex"));
13542 mask = inst.operands[0].imm;
13543 if (inst.size_req != 4 && (mask & ~0xff) == 0)
13544 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
13545 else if (inst.size_req != 4
13546 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
13547 ? REG_LR : REG_PC)))
13549 inst.instruction = THUMB_OP16 (inst.instruction);
13550 inst.instruction |= THUMB_PP_PC_LR;
13551 inst.instruction |= mask & 0xff;
13553 else if (unified_syntax)
13555 inst.instruction = THUMB_OP32 (inst.instruction);
13556 encode_thumb2_multi (true /* do_io */, 13, mask, true);
13558 else
13560 inst.error = _("invalid register list to push/pop instruction");
13561 return;
13565 static void
13566 do_t_clrm (void)
13568 if (unified_syntax)
13569 encode_thumb2_multi (false /* do_io */, -1, inst.operands[0].imm, false);
13570 else
13572 inst.error = _("invalid register list to push/pop instruction");
13573 return;
13577 static void
13578 do_t_vscclrm (void)
13580 if (inst.operands[0].issingle)
13582 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13583 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13584 inst.instruction |= inst.operands[0].imm;
13586 else
13588 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13589 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13590 inst.instruction |= 1 << 8;
13591 inst.instruction |= inst.operands[0].imm << 1;
13595 static void
13596 do_t_rbit (void)
13598 unsigned Rd, Rm;
13600 Rd = inst.operands[0].reg;
13601 Rm = inst.operands[1].reg;
13603 reject_bad_reg (Rd);
13604 reject_bad_reg (Rm);
13606 inst.instruction |= Rd << 8;
13607 inst.instruction |= Rm << 16;
13608 inst.instruction |= Rm;
13611 static void
13612 do_t_rev (void)
13614 unsigned Rd, Rm;
13616 Rd = inst.operands[0].reg;
13617 Rm = inst.operands[1].reg;
13619 reject_bad_reg (Rd);
13620 reject_bad_reg (Rm);
13622 if (Rd <= 7 && Rm <= 7
13623 && inst.size_req != 4)
13625 inst.instruction = THUMB_OP16 (inst.instruction);
13626 inst.instruction |= Rd;
13627 inst.instruction |= Rm << 3;
13629 else if (unified_syntax)
13631 inst.instruction = THUMB_OP32 (inst.instruction);
13632 inst.instruction |= Rd << 8;
13633 inst.instruction |= Rm << 16;
13634 inst.instruction |= Rm;
13636 else
13637 inst.error = BAD_HIREG;
13640 static void
13641 do_t_rrx (void)
13643 unsigned Rd, Rm;
13645 Rd = inst.operands[0].reg;
13646 Rm = inst.operands[1].reg;
13648 reject_bad_reg (Rd);
13649 reject_bad_reg (Rm);
13651 inst.instruction |= Rd << 8;
13652 inst.instruction |= Rm;
13655 static void
13656 do_t_rsb (void)
13658 unsigned Rd, Rs;
13660 Rd = inst.operands[0].reg;
13661 Rs = (inst.operands[1].present
13662 ? inst.operands[1].reg /* Rd, Rs, foo */
13663 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
13665 reject_bad_reg (Rd);
13666 reject_bad_reg (Rs);
13667 if (inst.operands[2].isreg)
13668 reject_bad_reg (inst.operands[2].reg);
13670 inst.instruction |= Rd << 8;
13671 inst.instruction |= Rs << 16;
13672 if (!inst.operands[2].isreg)
13674 bool narrow;
13676 if ((inst.instruction & 0x00100000) != 0)
13677 narrow = !in_pred_block ();
13678 else
13679 narrow = in_pred_block ();
13681 if (Rd > 7 || Rs > 7)
13682 narrow = false;
13684 if (inst.size_req == 4 || !unified_syntax)
13685 narrow = false;
13687 if (inst.relocs[0].exp.X_op != O_constant
13688 || inst.relocs[0].exp.X_add_number != 0)
13689 narrow = false;
13691 /* Turn rsb #0 into 16-bit neg. We should probably do this via
13692 relaxation, but it doesn't seem worth the hassle. */
13693 if (narrow)
13695 inst.relocs[0].type = BFD_RELOC_UNUSED;
13696 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13697 inst.instruction |= Rs << 3;
13698 inst.instruction |= Rd;
13700 else
13702 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13703 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13706 else
13707 encode_thumb32_shifted_operand (2);
13710 static void
13711 do_t_setend (void)
13713 if (warn_on_deprecated
13714 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13715 as_tsktsk (_("setend use is deprecated for ARMv8"));
13717 set_pred_insn_type (OUTSIDE_PRED_INSN);
13718 if (inst.operands[0].imm)
13719 inst.instruction |= 0x8;
13722 static void
13723 do_t_shift (void)
13725 if (!inst.operands[1].present)
13726 inst.operands[1].reg = inst.operands[0].reg;
13728 if (unified_syntax)
13730 bool narrow;
13731 int shift_kind;
13733 switch (inst.instruction)
13735 case T_MNEM_asr:
13736 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13737 case T_MNEM_lsl:
13738 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13739 case T_MNEM_lsr:
13740 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13741 case T_MNEM_ror:
13742 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13743 default: abort ();
13746 if (THUMB_SETS_FLAGS (inst.instruction))
13747 narrow = !in_pred_block ();
13748 else
13749 narrow = in_pred_block ();
13750 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13751 narrow = false;
13752 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13753 narrow = false;
13754 if (inst.operands[2].isreg
13755 && (inst.operands[1].reg != inst.operands[0].reg
13756 || inst.operands[2].reg > 7))
13757 narrow = false;
13758 if (inst.size_req == 4)
13759 narrow = false;
13761 reject_bad_reg (inst.operands[0].reg);
13762 reject_bad_reg (inst.operands[1].reg);
13764 if (!narrow)
13766 if (inst.operands[2].isreg)
13768 reject_bad_reg (inst.operands[2].reg);
13769 inst.instruction = THUMB_OP32 (inst.instruction);
13770 inst.instruction |= inst.operands[0].reg << 8;
13771 inst.instruction |= inst.operands[1].reg << 16;
13772 inst.instruction |= inst.operands[2].reg;
13774 /* PR 12854: Error on extraneous shifts. */
13775 constraint (inst.operands[2].shifted,
13776 _("extraneous shift as part of operand to shift insn"));
13778 else
13780 inst.operands[1].shifted = 1;
13781 inst.operands[1].shift_kind = shift_kind;
13782 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13783 ? T_MNEM_movs : T_MNEM_mov);
13784 inst.instruction |= inst.operands[0].reg << 8;
13785 encode_thumb32_shifted_operand (1);
13786 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
13787 inst.relocs[0].type = BFD_RELOC_UNUSED;
13790 else
13792 if (inst.operands[2].isreg)
13794 switch (shift_kind)
13796 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13797 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13798 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13799 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
13800 default: abort ();
13803 inst.instruction |= inst.operands[0].reg;
13804 inst.instruction |= inst.operands[2].reg << 3;
13806 /* PR 12854: Error on extraneous shifts. */
13807 constraint (inst.operands[2].shifted,
13808 _("extraneous shift as part of operand to shift insn"));
13810 else
13812 switch (shift_kind)
13814 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13815 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13816 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13817 default: abort ();
13819 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13820 inst.instruction |= inst.operands[0].reg;
13821 inst.instruction |= inst.operands[1].reg << 3;
13825 else
13827 constraint (inst.operands[0].reg > 7
13828 || inst.operands[1].reg > 7, BAD_HIREG);
13829 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13831 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13833 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13834 constraint (inst.operands[0].reg != inst.operands[1].reg,
13835 _("source1 and dest must be same register"));
13837 switch (inst.instruction)
13839 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13840 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13841 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13842 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13843 default: abort ();
13846 inst.instruction |= inst.operands[0].reg;
13847 inst.instruction |= inst.operands[2].reg << 3;
13849 /* PR 12854: Error on extraneous shifts. */
13850 constraint (inst.operands[2].shifted,
13851 _("extraneous shift as part of operand to shift insn"));
13853 else
13855 switch (inst.instruction)
13857 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13858 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13859 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13860 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13861 default: abort ();
13863 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13864 inst.instruction |= inst.operands[0].reg;
13865 inst.instruction |= inst.operands[1].reg << 3;
13870 static void
13871 do_t_simd (void)
13873 unsigned Rd, Rn, Rm;
13875 Rd = inst.operands[0].reg;
13876 Rn = inst.operands[1].reg;
13877 Rm = inst.operands[2].reg;
13879 reject_bad_reg (Rd);
13880 reject_bad_reg (Rn);
13881 reject_bad_reg (Rm);
13883 inst.instruction |= Rd << 8;
13884 inst.instruction |= Rn << 16;
13885 inst.instruction |= Rm;
13888 static void
13889 do_t_simd2 (void)
13891 unsigned Rd, Rn, Rm;
13893 Rd = inst.operands[0].reg;
13894 Rm = inst.operands[1].reg;
13895 Rn = inst.operands[2].reg;
13897 reject_bad_reg (Rd);
13898 reject_bad_reg (Rn);
13899 reject_bad_reg (Rm);
13901 inst.instruction |= Rd << 8;
13902 inst.instruction |= Rn << 16;
13903 inst.instruction |= Rm;
13906 static void
13907 do_t_smc (void)
13909 unsigned int value = inst.relocs[0].exp.X_add_number;
13910 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13911 _("SMC is not permitted on this architecture"));
13912 constraint (inst.relocs[0].exp.X_op != O_constant,
13913 _("expression too complex"));
13914 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
13916 inst.relocs[0].type = BFD_RELOC_UNUSED;
13917 inst.instruction |= (value & 0x000f) << 16;
13919 /* PR gas/15623: SMC instructions must be last in an IT block. */
13920 set_pred_insn_type_last ();
13923 static void
13924 do_t_hvc (void)
13926 unsigned int value = inst.relocs[0].exp.X_add_number;
13928 inst.relocs[0].type = BFD_RELOC_UNUSED;
13929 inst.instruction |= (value & 0x0fff);
13930 inst.instruction |= (value & 0xf000) << 4;
13933 static void
13934 do_t_ssat_usat (int bias)
13936 unsigned Rd, Rn;
13938 Rd = inst.operands[0].reg;
13939 Rn = inst.operands[2].reg;
13941 reject_bad_reg (Rd);
13942 reject_bad_reg (Rn);
13944 inst.instruction |= Rd << 8;
13945 inst.instruction |= inst.operands[1].imm - bias;
13946 inst.instruction |= Rn << 16;
13948 if (inst.operands[3].present)
13950 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
13952 inst.relocs[0].type = BFD_RELOC_UNUSED;
13954 constraint (inst.relocs[0].exp.X_op != O_constant,
13955 _("expression too complex"));
13957 if (shift_amount != 0)
13959 constraint (shift_amount > 31,
13960 _("shift expression is too large"));
13962 if (inst.operands[3].shift_kind == SHIFT_ASR)
13963 inst.instruction |= 0x00200000; /* sh bit. */
13965 inst.instruction |= (shift_amount & 0x1c) << 10;
13966 inst.instruction |= (shift_amount & 0x03) << 6;
13971 static void
13972 do_t_ssat (void)
13974 do_t_ssat_usat (1);
13977 static void
13978 do_t_ssat16 (void)
13980 unsigned Rd, Rn;
13982 Rd = inst.operands[0].reg;
13983 Rn = inst.operands[2].reg;
13985 reject_bad_reg (Rd);
13986 reject_bad_reg (Rn);
13988 inst.instruction |= Rd << 8;
13989 inst.instruction |= inst.operands[1].imm - 1;
13990 inst.instruction |= Rn << 16;
13993 static void
13994 do_t_strex (void)
13996 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13997 || inst.operands[2].postind || inst.operands[2].writeback
13998 || inst.operands[2].immisreg || inst.operands[2].shifted
13999 || inst.operands[2].negative,
14000 BAD_ADDR_MODE);
14002 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14004 inst.instruction |= inst.operands[0].reg << 8;
14005 inst.instruction |= inst.operands[1].reg << 12;
14006 inst.instruction |= inst.operands[2].reg << 16;
14007 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
14010 static void
14011 do_t_strexd (void)
14013 if (!inst.operands[2].present)
14014 inst.operands[2].reg = inst.operands[1].reg + 1;
14016 constraint (inst.operands[0].reg == inst.operands[1].reg
14017 || inst.operands[0].reg == inst.operands[2].reg
14018 || inst.operands[0].reg == inst.operands[3].reg,
14019 BAD_OVERLAP);
14021 inst.instruction |= inst.operands[0].reg;
14022 inst.instruction |= inst.operands[1].reg << 12;
14023 inst.instruction |= inst.operands[2].reg << 8;
14024 inst.instruction |= inst.operands[3].reg << 16;
14027 static void
14028 do_t_sxtah (void)
14030 unsigned Rd, Rn, Rm;
14032 Rd = inst.operands[0].reg;
14033 Rn = inst.operands[1].reg;
14034 Rm = inst.operands[2].reg;
14036 reject_bad_reg (Rd);
14037 reject_bad_reg (Rn);
14038 reject_bad_reg (Rm);
14040 inst.instruction |= Rd << 8;
14041 inst.instruction |= Rn << 16;
14042 inst.instruction |= Rm;
14043 inst.instruction |= inst.operands[3].imm << 4;
14046 static void
14047 do_t_sxth (void)
14049 unsigned Rd, Rm;
14051 Rd = inst.operands[0].reg;
14052 Rm = inst.operands[1].reg;
14054 reject_bad_reg (Rd);
14055 reject_bad_reg (Rm);
14057 if (inst.instruction <= 0xffff
14058 && inst.size_req != 4
14059 && Rd <= 7 && Rm <= 7
14060 && (!inst.operands[2].present || inst.operands[2].imm == 0))
14062 inst.instruction = THUMB_OP16 (inst.instruction);
14063 inst.instruction |= Rd;
14064 inst.instruction |= Rm << 3;
14066 else if (unified_syntax)
14068 if (inst.instruction <= 0xffff)
14069 inst.instruction = THUMB_OP32 (inst.instruction);
14070 inst.instruction |= Rd << 8;
14071 inst.instruction |= Rm;
14072 inst.instruction |= inst.operands[2].imm << 4;
14074 else
14076 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14077 _("Thumb encoding does not support rotation"));
14078 constraint (1, BAD_HIREG);
14082 static void
14083 do_t_swi (void)
14085 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
14088 static void
14089 do_t_tb (void)
14091 unsigned Rn, Rm;
14092 int half;
14094 half = (inst.instruction & 0x10) != 0;
14095 set_pred_insn_type_last ();
14096 constraint (inst.operands[0].immisreg,
14097 _("instruction requires register index"));
14099 Rn = inst.operands[0].reg;
14100 Rm = inst.operands[0].imm;
14102 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14103 constraint (Rn == REG_SP, BAD_SP);
14104 reject_bad_reg (Rm);
14106 constraint (!half && inst.operands[0].shifted,
14107 _("instruction does not allow shifted index"));
14108 inst.instruction |= (Rn << 16) | Rm;
14111 static void
14112 do_t_udf (void)
14114 if (!inst.operands[0].present)
14115 inst.operands[0].imm = 0;
14117 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14119 constraint (inst.size_req == 2,
14120 _("immediate value out of range"));
14121 inst.instruction = THUMB_OP32 (inst.instruction);
14122 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14123 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14125 else
14127 inst.instruction = THUMB_OP16 (inst.instruction);
14128 inst.instruction |= inst.operands[0].imm;
14131 set_pred_insn_type (NEUTRAL_IT_INSN);
14135 static void
14136 do_t_usat (void)
14138 do_t_ssat_usat (0);
14141 static void
14142 do_t_usat16 (void)
14144 unsigned Rd, Rn;
14146 Rd = inst.operands[0].reg;
14147 Rn = inst.operands[2].reg;
14149 reject_bad_reg (Rd);
14150 reject_bad_reg (Rn);
14152 inst.instruction |= Rd << 8;
14153 inst.instruction |= inst.operands[1].imm;
14154 inst.instruction |= Rn << 16;
14157 /* Checking the range of the branch offset (VAL) with NBITS bits
14158 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14159 static int
14160 v8_1_branch_value_check (int val, int nbits, int is_signed)
14162 gas_assert (nbits > 0 && nbits <= 32);
14163 if (is_signed)
14165 int cmp = (1 << (nbits - 1));
14166 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14167 return FAIL;
14169 else
14171 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14172 return FAIL;
14174 return SUCCESS;
14177 /* For branches in Armv8.1-M Mainline. */
14178 static void
14179 do_t_branch_future (void)
14181 unsigned long insn = inst.instruction;
14183 inst.instruction = THUMB_OP32 (inst.instruction);
14184 if (inst.operands[0].hasreloc == 0)
14186 if (v8_1_branch_value_check (inst.operands[0].imm, 5, false) == FAIL)
14187 as_bad (BAD_BRANCH_OFF);
14189 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14191 else
14193 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14194 inst.relocs[0].pc_rel = 1;
14197 switch (insn)
14199 case T_MNEM_bf:
14200 if (inst.operands[1].hasreloc == 0)
14202 int val = inst.operands[1].imm;
14203 if (v8_1_branch_value_check (inst.operands[1].imm, 17, true) == FAIL)
14204 as_bad (BAD_BRANCH_OFF);
14206 int immA = (val & 0x0001f000) >> 12;
14207 int immB = (val & 0x00000ffc) >> 2;
14208 int immC = (val & 0x00000002) >> 1;
14209 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14211 else
14213 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14214 inst.relocs[1].pc_rel = 1;
14216 break;
14218 case T_MNEM_bfl:
14219 if (inst.operands[1].hasreloc == 0)
14221 int val = inst.operands[1].imm;
14222 if (v8_1_branch_value_check (inst.operands[1].imm, 19, true) == FAIL)
14223 as_bad (BAD_BRANCH_OFF);
14225 int immA = (val & 0x0007f000) >> 12;
14226 int immB = (val & 0x00000ffc) >> 2;
14227 int immC = (val & 0x00000002) >> 1;
14228 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14230 else
14232 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14233 inst.relocs[1].pc_rel = 1;
14235 break;
14237 case T_MNEM_bfcsel:
14238 /* Operand 1. */
14239 if (inst.operands[1].hasreloc == 0)
14241 int val = inst.operands[1].imm;
14242 int immA = (val & 0x00001000) >> 12;
14243 int immB = (val & 0x00000ffc) >> 2;
14244 int immC = (val & 0x00000002) >> 1;
14245 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14247 else
14249 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14250 inst.relocs[1].pc_rel = 1;
14253 /* Operand 2. */
14254 if (inst.operands[2].hasreloc == 0)
14256 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14257 int val2 = inst.operands[2].imm;
14258 int val0 = inst.operands[0].imm & 0x1f;
14259 int diff = val2 - val0;
14260 if (diff == 4)
14261 inst.instruction |= 1 << 17; /* T bit. */
14262 else if (diff != 2)
14263 as_bad (_("out of range label-relative fixup value"));
14265 else
14267 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14268 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14269 inst.relocs[2].pc_rel = 1;
14272 /* Operand 3. */
14273 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14274 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14275 break;
14277 case T_MNEM_bfx:
14278 case T_MNEM_bflx:
14279 inst.instruction |= inst.operands[1].reg << 16;
14280 break;
14282 default: abort ();
14286 /* Helper function for do_t_loloop to handle relocations. */
14287 static void
14288 v8_1_loop_reloc (int is_le)
14290 if (inst.relocs[0].exp.X_op == O_constant)
14292 int value = inst.relocs[0].exp.X_add_number;
14293 value = (is_le) ? -value : value;
14295 if (v8_1_branch_value_check (value, 12, false) == FAIL)
14296 as_bad (BAD_BRANCH_OFF);
14298 int imml, immh;
14300 immh = (value & 0x00000ffc) >> 2;
14301 imml = (value & 0x00000002) >> 1;
14303 inst.instruction |= (imml << 11) | (immh << 1);
14305 else
14307 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14308 inst.relocs[0].pc_rel = 1;
14312 /* For shifts with four operands in MVE. */
14313 static void
14314 do_mve_scalar_shift1 (void)
14316 unsigned int value = inst.operands[2].imm;
14318 inst.instruction |= inst.operands[0].reg << 16;
14319 inst.instruction |= inst.operands[1].reg << 8;
14321 /* Setting the bit for saturation. */
14322 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14324 /* Assuming Rm is already checked not to be 11x1. */
14325 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14326 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14327 inst.instruction |= inst.operands[3].reg << 12;
14330 /* For shifts in MVE. */
14331 static void
14332 do_mve_scalar_shift (void)
14334 if (!inst.operands[2].present)
14336 inst.operands[2] = inst.operands[1];
14337 inst.operands[1].reg = 0xf;
14340 inst.instruction |= inst.operands[0].reg << 16;
14341 inst.instruction |= inst.operands[1].reg << 8;
14343 if (inst.operands[2].isreg)
14345 /* Assuming Rm is already checked not to be 11x1. */
14346 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14347 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14348 inst.instruction |= inst.operands[2].reg << 12;
14350 else
14352 /* Assuming imm is already checked as [1,32]. */
14353 unsigned int value = inst.operands[2].imm;
14354 inst.instruction |= (value & 0x1c) << 10;
14355 inst.instruction |= (value & 0x03) << 6;
14356 /* Change last 4 bits from 0xd to 0xf. */
14357 inst.instruction |= 0x2;
14361 /* MVE instruction encoder helpers. */
14362 #define M_MNEM_vabav 0xee800f01
14363 #define M_MNEM_vmladav 0xeef00e00
14364 #define M_MNEM_vmladava 0xeef00e20
14365 #define M_MNEM_vmladavx 0xeef01e00
14366 #define M_MNEM_vmladavax 0xeef01e20
14367 #define M_MNEM_vmlsdav 0xeef00e01
14368 #define M_MNEM_vmlsdava 0xeef00e21
14369 #define M_MNEM_vmlsdavx 0xeef01e01
14370 #define M_MNEM_vmlsdavax 0xeef01e21
14371 #define M_MNEM_vmullt 0xee011e00
14372 #define M_MNEM_vmullb 0xee010e00
14373 #define M_MNEM_vctp 0xf000e801
14374 #define M_MNEM_vst20 0xfc801e00
14375 #define M_MNEM_vst21 0xfc801e20
14376 #define M_MNEM_vst40 0xfc801e01
14377 #define M_MNEM_vst41 0xfc801e21
14378 #define M_MNEM_vst42 0xfc801e41
14379 #define M_MNEM_vst43 0xfc801e61
14380 #define M_MNEM_vld20 0xfc901e00
14381 #define M_MNEM_vld21 0xfc901e20
14382 #define M_MNEM_vld40 0xfc901e01
14383 #define M_MNEM_vld41 0xfc901e21
14384 #define M_MNEM_vld42 0xfc901e41
14385 #define M_MNEM_vld43 0xfc901e61
14386 #define M_MNEM_vstrb 0xec000e00
14387 #define M_MNEM_vstrh 0xec000e10
14388 #define M_MNEM_vstrw 0xec000e40
14389 #define M_MNEM_vstrd 0xec000e50
14390 #define M_MNEM_vldrb 0xec100e00
14391 #define M_MNEM_vldrh 0xec100e10
14392 #define M_MNEM_vldrw 0xec100e40
14393 #define M_MNEM_vldrd 0xec100e50
14394 #define M_MNEM_vmovlt 0xeea01f40
14395 #define M_MNEM_vmovlb 0xeea00f40
14396 #define M_MNEM_vmovnt 0xfe311e81
14397 #define M_MNEM_vmovnb 0xfe310e81
14398 #define M_MNEM_vadc 0xee300f00
14399 #define M_MNEM_vadci 0xee301f00
14400 #define M_MNEM_vbrsr 0xfe011e60
14401 #define M_MNEM_vaddlv 0xee890f00
14402 #define M_MNEM_vaddlva 0xee890f20
14403 #define M_MNEM_vaddv 0xeef10f00
14404 #define M_MNEM_vaddva 0xeef10f20
14405 #define M_MNEM_vddup 0xee011f6e
14406 #define M_MNEM_vdwdup 0xee011f60
14407 #define M_MNEM_vidup 0xee010f6e
14408 #define M_MNEM_viwdup 0xee010f60
14409 #define M_MNEM_vmaxv 0xeee20f00
14410 #define M_MNEM_vmaxav 0xeee00f00
14411 #define M_MNEM_vminv 0xeee20f80
14412 #define M_MNEM_vminav 0xeee00f80
14413 #define M_MNEM_vmlaldav 0xee800e00
14414 #define M_MNEM_vmlaldava 0xee800e20
14415 #define M_MNEM_vmlaldavx 0xee801e00
14416 #define M_MNEM_vmlaldavax 0xee801e20
14417 #define M_MNEM_vmlsldav 0xee800e01
14418 #define M_MNEM_vmlsldava 0xee800e21
14419 #define M_MNEM_vmlsldavx 0xee801e01
14420 #define M_MNEM_vmlsldavax 0xee801e21
14421 #define M_MNEM_vrmlaldavhx 0xee801f00
14422 #define M_MNEM_vrmlaldavhax 0xee801f20
14423 #define M_MNEM_vrmlsldavh 0xfe800e01
14424 #define M_MNEM_vrmlsldavha 0xfe800e21
14425 #define M_MNEM_vrmlsldavhx 0xfe801e01
14426 #define M_MNEM_vrmlsldavhax 0xfe801e21
14427 #define M_MNEM_vqmovnt 0xee331e01
14428 #define M_MNEM_vqmovnb 0xee330e01
14429 #define M_MNEM_vqmovunt 0xee311e81
14430 #define M_MNEM_vqmovunb 0xee310e81
14431 #define M_MNEM_vshrnt 0xee801fc1
14432 #define M_MNEM_vshrnb 0xee800fc1
14433 #define M_MNEM_vrshrnt 0xfe801fc1
14434 #define M_MNEM_vqshrnt 0xee801f40
14435 #define M_MNEM_vqshrnb 0xee800f40
14436 #define M_MNEM_vqshrunt 0xee801fc0
14437 #define M_MNEM_vqshrunb 0xee800fc0
14438 #define M_MNEM_vrshrnb 0xfe800fc1
14439 #define M_MNEM_vqrshrnt 0xee801f41
14440 #define M_MNEM_vqrshrnb 0xee800f41
14441 #define M_MNEM_vqrshrunt 0xfe801fc0
14442 #define M_MNEM_vqrshrunb 0xfe800fc0
14444 /* Bfloat16 instruction encoder helpers. */
14445 #define B_MNEM_vfmat 0xfc300850
14446 #define B_MNEM_vfmab 0xfc300810
14448 /* Neon instruction encoder helpers. */
14450 /* Encodings for the different types for various Neon opcodes. */
14452 /* An "invalid" code for the following tables. */
14453 #define N_INV -1u
14455 struct neon_tab_entry
14457 unsigned integer;
14458 unsigned float_or_poly;
14459 unsigned scalar_or_imm;
14462 /* Map overloaded Neon opcodes to their respective encodings. */
14463 #define NEON_ENC_TAB \
14464 X(vabd, 0x0000700, 0x1200d00, N_INV), \
14465 X(vabdl, 0x0800700, N_INV, N_INV), \
14466 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14467 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14468 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14469 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14470 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14471 X(vadd, 0x0000800, 0x0000d00, N_INV), \
14472 X(vaddl, 0x0800000, N_INV, N_INV), \
14473 X(vsub, 0x1000800, 0x0200d00, N_INV), \
14474 X(vsubl, 0x0800200, N_INV, N_INV), \
14475 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14476 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14477 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14478 /* Register variants of the following two instructions are encoded as
14479 vcge / vcgt with the operands reversed. */ \
14480 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14481 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
14482 X(vfma, N_INV, 0x0000c10, N_INV), \
14483 X(vfms, N_INV, 0x0200c10, N_INV), \
14484 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14485 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14486 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14487 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14488 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14489 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14490 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14491 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14492 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14493 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14494 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
14495 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14496 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
14497 X(vshl, 0x0000400, N_INV, 0x0800510), \
14498 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14499 X(vand, 0x0000110, N_INV, 0x0800030), \
14500 X(vbic, 0x0100110, N_INV, 0x0800030), \
14501 X(veor, 0x1000110, N_INV, N_INV), \
14502 X(vorn, 0x0300110, N_INV, 0x0800010), \
14503 X(vorr, 0x0200110, N_INV, 0x0800010), \
14504 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14505 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14506 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14507 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14508 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14509 X(vst1, 0x0000000, 0x0800000, N_INV), \
14510 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14511 X(vst2, 0x0000100, 0x0800100, N_INV), \
14512 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14513 X(vst3, 0x0000200, 0x0800200, N_INV), \
14514 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14515 X(vst4, 0x0000300, 0x0800300, N_INV), \
14516 X(vmovn, 0x1b20200, N_INV, N_INV), \
14517 X(vtrn, 0x1b20080, N_INV, N_INV), \
14518 X(vqmovn, 0x1b20200, N_INV, N_INV), \
14519 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14520 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
14521 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14522 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
14523 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14524 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
14525 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14526 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14527 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
14528 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14529 X(vseleq, 0xe000a00, N_INV, N_INV), \
14530 X(vselvs, 0xe100a00, N_INV, N_INV), \
14531 X(vselge, 0xe200a00, N_INV, N_INV), \
14532 X(vselgt, 0xe300a00, N_INV, N_INV), \
14533 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
14534 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
14535 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14536 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
14537 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
14538 X(aes, 0x3b00300, N_INV, N_INV), \
14539 X(sha3op, 0x2000c00, N_INV, N_INV), \
14540 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14541 X(sha2op, 0x3ba0380, N_INV, N_INV)
14543 enum neon_opc
14545 #define X(OPC,I,F,S) N_MNEM_##OPC
14546 NEON_ENC_TAB
14547 #undef X
14550 static const struct neon_tab_entry neon_enc_tab[] =
14552 #define X(OPC,I,F,S) { (I), (F), (S) }
14553 NEON_ENC_TAB
14554 #undef X
14557 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
14558 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14559 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14560 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14561 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14562 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14563 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14564 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14565 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14566 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14567 #define NEON_ENC_SINGLE_(X) \
14568 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
14569 #define NEON_ENC_DOUBLE_(X) \
14570 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
14571 #define NEON_ENC_FPV8_(X) \
14572 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
14574 #define NEON_ENCODE(type, inst) \
14575 do \
14577 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14578 inst.is_neon = 1; \
14580 while (0)
14582 #define check_neon_suffixes \
14583 do \
14585 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14587 as_bad (_("invalid neon suffix for non neon instruction")); \
14588 return; \
14591 while (0)
14593 /* Define shapes for instruction operands. The following mnemonic characters
14594 are used in this table:
14596 F - VFP S<n> register
14597 D - Neon D<n> register
14598 Q - Neon Q<n> register
14599 I - Immediate
14600 S - Scalar
14601 R - ARM register
14602 L - D<n> register list
14604 This table is used to generate various data:
14605 - enumerations of the form NS_DDR to be used as arguments to
14606 neon_select_shape.
14607 - a table classifying shapes into single, double, quad, mixed.
14608 - a table used to drive neon_select_shape. */
14610 #define NEON_SHAPE_DEF \
14611 X(4, (R, R, Q, Q), QUAD), \
14612 X(4, (Q, R, R, I), QUAD), \
14613 X(4, (R, R, S, S), QUAD), \
14614 X(4, (S, S, R, R), QUAD), \
14615 X(3, (Q, R, I), QUAD), \
14616 X(3, (I, Q, Q), QUAD), \
14617 X(3, (I, Q, R), QUAD), \
14618 X(3, (R, Q, Q), QUAD), \
14619 X(3, (D, D, D), DOUBLE), \
14620 X(3, (Q, Q, Q), QUAD), \
14621 X(3, (D, D, I), DOUBLE), \
14622 X(3, (Q, Q, I), QUAD), \
14623 X(3, (D, D, S), DOUBLE), \
14624 X(3, (Q, Q, S), QUAD), \
14625 X(3, (Q, Q, R), QUAD), \
14626 X(3, (R, R, Q), QUAD), \
14627 X(2, (R, Q), QUAD), \
14628 X(2, (D, D), DOUBLE), \
14629 X(2, (Q, Q), QUAD), \
14630 X(2, (D, S), DOUBLE), \
14631 X(2, (Q, S), QUAD), \
14632 X(2, (D, R), DOUBLE), \
14633 X(2, (Q, R), QUAD), \
14634 X(2, (D, I), DOUBLE), \
14635 X(2, (Q, I), QUAD), \
14636 X(3, (P, F, I), SINGLE), \
14637 X(3, (P, D, I), DOUBLE), \
14638 X(3, (P, Q, I), QUAD), \
14639 X(4, (P, F, F, I), SINGLE), \
14640 X(4, (P, D, D, I), DOUBLE), \
14641 X(4, (P, Q, Q, I), QUAD), \
14642 X(5, (P, F, F, F, I), SINGLE), \
14643 X(5, (P, D, D, D, I), DOUBLE), \
14644 X(5, (P, Q, Q, Q, I), QUAD), \
14645 X(3, (D, L, D), DOUBLE), \
14646 X(2, (D, Q), MIXED), \
14647 X(2, (Q, D), MIXED), \
14648 X(3, (D, Q, I), MIXED), \
14649 X(3, (Q, D, I), MIXED), \
14650 X(3, (Q, D, D), MIXED), \
14651 X(3, (D, Q, Q), MIXED), \
14652 X(3, (Q, Q, D), MIXED), \
14653 X(3, (Q, D, S), MIXED), \
14654 X(3, (D, Q, S), MIXED), \
14655 X(4, (D, D, D, I), DOUBLE), \
14656 X(4, (Q, Q, Q, I), QUAD), \
14657 X(4, (D, D, S, I), DOUBLE), \
14658 X(4, (Q, Q, S, I), QUAD), \
14659 X(2, (F, F), SINGLE), \
14660 X(3, (F, F, F), SINGLE), \
14661 X(2, (F, I), SINGLE), \
14662 X(2, (F, D), MIXED), \
14663 X(2, (D, F), MIXED), \
14664 X(3, (F, F, I), MIXED), \
14665 X(4, (R, R, F, F), SINGLE), \
14666 X(4, (F, F, R, R), SINGLE), \
14667 X(3, (D, R, R), DOUBLE), \
14668 X(3, (R, R, D), DOUBLE), \
14669 X(2, (S, R), SINGLE), \
14670 X(2, (R, S), SINGLE), \
14671 X(2, (F, R), SINGLE), \
14672 X(2, (R, F), SINGLE), \
14673 /* Used for MVE tail predicated loop instructions. */\
14674 X(2, (R, R), QUAD), \
14675 /* Half float shape supported so far. */\
14676 X (2, (H, D), MIXED), \
14677 X (2, (D, H), MIXED), \
14678 X (2, (H, F), MIXED), \
14679 X (2, (F, H), MIXED), \
14680 X (2, (H, H), HALF), \
14681 X (2, (H, R), HALF), \
14682 X (2, (R, H), HALF), \
14683 X (2, (H, I), HALF), \
14684 X (3, (H, H, H), HALF), \
14685 X (3, (H, F, I), MIXED), \
14686 X (3, (F, H, I), MIXED), \
14687 X (3, (D, H, H), MIXED), \
14688 X (3, (D, H, S), MIXED)
14690 #define S2(A,B) NS_##A##B
14691 #define S3(A,B,C) NS_##A##B##C
14692 #define S4(A,B,C,D) NS_##A##B##C##D
14693 #define S5(A,B,C,D,E) NS_##A##B##C##D##E
14695 #define X(N, L, C) S##N L
14697 enum neon_shape
14699 NEON_SHAPE_DEF,
14700 NS_NULL
14703 #undef X
14704 #undef S2
14705 #undef S3
14706 #undef S4
14707 #undef S5
14709 enum neon_shape_class
14711 SC_HALF,
14712 SC_SINGLE,
14713 SC_DOUBLE,
14714 SC_QUAD,
14715 SC_MIXED
14718 #define X(N, L, C) SC_##C
14720 static enum neon_shape_class neon_shape_class[] =
14722 NEON_SHAPE_DEF
14725 #undef X
14727 enum neon_shape_el
14729 SE_H,
14730 SE_F,
14731 SE_D,
14732 SE_Q,
14733 SE_I,
14734 SE_S,
14735 SE_R,
14736 SE_L,
14737 SE_P
14740 /* Register widths of above. */
14741 static unsigned neon_shape_el_size[] =
14746 128,
14754 struct neon_shape_info
14756 unsigned els;
14757 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14760 #define S2(A,B) { SE_##A, SE_##B }
14761 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14762 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14763 #define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
14765 #define X(N, L, C) { N, S##N L }
14767 static struct neon_shape_info neon_shape_tab[] =
14769 NEON_SHAPE_DEF
14772 #undef X
14773 #undef S2
14774 #undef S3
14775 #undef S4
14776 #undef S5
14778 /* Bit masks used in type checking given instructions.
14779 'N_EQK' means the type must be the same as (or based on in some way) the key
14780 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14781 set, various other bits can be set as well in order to modify the meaning of
14782 the type constraint. */
14784 enum neon_type_mask
14786 N_S8 = 0x0000001,
14787 N_S16 = 0x0000002,
14788 N_S32 = 0x0000004,
14789 N_S64 = 0x0000008,
14790 N_U8 = 0x0000010,
14791 N_U16 = 0x0000020,
14792 N_U32 = 0x0000040,
14793 N_U64 = 0x0000080,
14794 N_I8 = 0x0000100,
14795 N_I16 = 0x0000200,
14796 N_I32 = 0x0000400,
14797 N_I64 = 0x0000800,
14798 N_8 = 0x0001000,
14799 N_16 = 0x0002000,
14800 N_32 = 0x0004000,
14801 N_64 = 0x0008000,
14802 N_P8 = 0x0010000,
14803 N_P16 = 0x0020000,
14804 N_F16 = 0x0040000,
14805 N_F32 = 0x0080000,
14806 N_F64 = 0x0100000,
14807 N_P64 = 0x0200000,
14808 N_BF16 = 0x0400000,
14809 N_KEY = 0x1000000, /* Key element (main type specifier). */
14810 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
14811 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
14812 N_UNT = 0x8000000, /* Must be explicitly untyped. */
14813 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14814 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14815 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14816 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14817 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14818 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14819 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
14820 N_UTYP = 0,
14821 N_MAX_NONSPECIAL = N_P64
14824 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14826 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14827 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14828 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
14829 #define N_S_32 (N_S8 | N_S16 | N_S32)
14830 #define N_F_16_32 (N_F16 | N_F32)
14831 #define N_SUF_32 (N_SU_32 | N_F_16_32)
14832 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
14833 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
14834 #define N_F_ALL (N_F16 | N_F32 | N_F64)
14835 #define N_I_MVE (N_I8 | N_I16 | N_I32)
14836 #define N_F_MVE (N_F16 | N_F32)
14837 #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14839 /* Pass this as the first type argument to neon_check_type to ignore types
14840 altogether. */
14841 #define N_IGNORE_TYPE (N_KEY | N_EQK)
14843 /* Select a "shape" for the current instruction (describing register types or
14844 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14845 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14846 function of operand parsing, so this function doesn't need to be called.
14847 Shapes should be listed in order of decreasing length. */
14849 static enum neon_shape
14850 neon_select_shape (enum neon_shape shape, ...)
14852 va_list ap;
14853 enum neon_shape first_shape = shape;
14855 /* Fix missing optional operands. FIXME: we don't know at this point how
14856 many arguments we should have, so this makes the assumption that we have
14857 > 1. This is true of all current Neon opcodes, I think, but may not be
14858 true in the future. */
14859 if (!inst.operands[1].present)
14860 inst.operands[1] = inst.operands[0];
14862 va_start (ap, shape);
14864 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
14866 unsigned j;
14867 int matches = 1;
14869 for (j = 0; j < neon_shape_tab[shape].els; j++)
14871 if (!inst.operands[j].present)
14873 matches = 0;
14874 break;
14877 switch (neon_shape_tab[shape].el[j])
14879 /* If a .f16, .16, .u16, .s16 type specifier is given over
14880 a VFP single precision register operand, it's essentially
14881 means only half of the register is used.
14883 If the type specifier is given after the mnemonics, the
14884 information is stored in inst.vectype. If the type specifier
14885 is given after register operand, the information is stored
14886 in inst.operands[].vectype.
14888 When there is only one type specifier, and all the register
14889 operands are the same type of hardware register, the type
14890 specifier applies to all register operands.
14892 If no type specifier is given, the shape is inferred from
14893 operand information.
14895 for example:
14896 vadd.f16 s0, s1, s2: NS_HHH
14897 vabs.f16 s0, s1: NS_HH
14898 vmov.f16 s0, r1: NS_HR
14899 vmov.f16 r0, s1: NS_RH
14900 vcvt.f16 r0, s1: NS_RH
14901 vcvt.f16.s32 s2, s2, #29: NS_HFI
14902 vcvt.f16.s32 s2, s2: NS_HF
14904 case SE_H:
14905 if (!(inst.operands[j].isreg
14906 && inst.operands[j].isvec
14907 && inst.operands[j].issingle
14908 && !inst.operands[j].isquad
14909 && ((inst.vectype.elems == 1
14910 && inst.vectype.el[0].size == 16)
14911 || (inst.vectype.elems > 1
14912 && inst.vectype.el[j].size == 16)
14913 || (inst.vectype.elems == 0
14914 && inst.operands[j].vectype.type != NT_invtype
14915 && inst.operands[j].vectype.size == 16))))
14916 matches = 0;
14917 break;
14919 case SE_F:
14920 if (!(inst.operands[j].isreg
14921 && inst.operands[j].isvec
14922 && inst.operands[j].issingle
14923 && !inst.operands[j].isquad
14924 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
14925 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
14926 || (inst.vectype.elems == 0
14927 && (inst.operands[j].vectype.size == 32
14928 || inst.operands[j].vectype.type == NT_invtype)))))
14929 matches = 0;
14930 break;
14932 case SE_D:
14933 if (!(inst.operands[j].isreg
14934 && inst.operands[j].isvec
14935 && !inst.operands[j].isquad
14936 && !inst.operands[j].issingle))
14937 matches = 0;
14938 break;
14940 case SE_R:
14941 if (!(inst.operands[j].isreg
14942 && !inst.operands[j].isvec))
14943 matches = 0;
14944 break;
14946 case SE_Q:
14947 if (!(inst.operands[j].isreg
14948 && inst.operands[j].isvec
14949 && inst.operands[j].isquad
14950 && !inst.operands[j].issingle))
14951 matches = 0;
14952 break;
14954 case SE_I:
14955 if (!(!inst.operands[j].isreg
14956 && !inst.operands[j].isscalar))
14957 matches = 0;
14958 break;
14960 case SE_S:
14961 if (!(!inst.operands[j].isreg
14962 && inst.operands[j].isscalar))
14963 matches = 0;
14964 break;
14966 case SE_P:
14967 case SE_L:
14968 break;
14970 if (!matches)
14971 break;
14973 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
14974 /* We've matched all the entries in the shape table, and we don't
14975 have any left over operands which have not been matched. */
14976 break;
14979 va_end (ap);
14981 if (shape == NS_NULL && first_shape != NS_NULL)
14982 first_error (_("invalid instruction shape"));
14984 return shape;
14987 /* True if SHAPE is predominantly a quadword operation (most of the time, this
14988 means the Q bit should be set). */
14990 static int
14991 neon_quad (enum neon_shape shape)
14993 return neon_shape_class[shape] == SC_QUAD;
14996 static void
14997 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
14998 unsigned *g_size)
15000 /* Allow modification to be made to types which are constrained to be
15001 based on the key element, based on bits set alongside N_EQK. */
15002 if ((typebits & N_EQK) != 0)
15004 if ((typebits & N_HLF) != 0)
15005 *g_size /= 2;
15006 else if ((typebits & N_DBL) != 0)
15007 *g_size *= 2;
15008 if ((typebits & N_SGN) != 0)
15009 *g_type = NT_signed;
15010 else if ((typebits & N_UNS) != 0)
15011 *g_type = NT_unsigned;
15012 else if ((typebits & N_INT) != 0)
15013 *g_type = NT_integer;
15014 else if ((typebits & N_FLT) != 0)
15015 *g_type = NT_float;
15016 else if ((typebits & N_SIZ) != 0)
15017 *g_type = NT_untyped;
15021 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15022 operand type, i.e. the single type specified in a Neon instruction when it
15023 is the only one given. */
15025 static struct neon_type_el
15026 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15028 struct neon_type_el dest = *key;
15030 gas_assert ((thisarg & N_EQK) != 0);
15032 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15034 return dest;
15037 /* Convert Neon type and size into compact bitmask representation. */
15039 static enum neon_type_mask
15040 type_chk_of_el_type (enum neon_el_type type, unsigned size)
15042 switch (type)
15044 case NT_untyped:
15045 switch (size)
15047 case 8: return N_8;
15048 case 16: return N_16;
15049 case 32: return N_32;
15050 case 64: return N_64;
15051 default: ;
15053 break;
15055 case NT_integer:
15056 switch (size)
15058 case 8: return N_I8;
15059 case 16: return N_I16;
15060 case 32: return N_I32;
15061 case 64: return N_I64;
15062 default: ;
15064 break;
15066 case NT_float:
15067 switch (size)
15069 case 16: return N_F16;
15070 case 32: return N_F32;
15071 case 64: return N_F64;
15072 default: ;
15074 break;
15076 case NT_poly:
15077 switch (size)
15079 case 8: return N_P8;
15080 case 16: return N_P16;
15081 case 64: return N_P64;
15082 default: ;
15084 break;
15086 case NT_signed:
15087 switch (size)
15089 case 8: return N_S8;
15090 case 16: return N_S16;
15091 case 32: return N_S32;
15092 case 64: return N_S64;
15093 default: ;
15095 break;
15097 case NT_unsigned:
15098 switch (size)
15100 case 8: return N_U8;
15101 case 16: return N_U16;
15102 case 32: return N_U32;
15103 case 64: return N_U64;
15104 default: ;
15106 break;
15108 case NT_bfloat:
15109 if (size == 16) return N_BF16;
15110 break;
15112 default: ;
15115 return N_UTYP;
15118 /* Convert compact Neon bitmask type representation to a type and size. Only
15119 handles the case where a single bit is set in the mask. */
15121 static int
15122 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
15123 enum neon_type_mask mask)
15125 if ((mask & N_EQK) != 0)
15126 return FAIL;
15128 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15129 *size = 8;
15130 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15131 != 0)
15132 *size = 16;
15133 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
15134 *size = 32;
15135 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
15136 *size = 64;
15137 else
15138 return FAIL;
15140 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15141 *type = NT_signed;
15142 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
15143 *type = NT_unsigned;
15144 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
15145 *type = NT_integer;
15146 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
15147 *type = NT_untyped;
15148 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
15149 *type = NT_poly;
15150 else if ((mask & (N_F_ALL)) != 0)
15151 *type = NT_float;
15152 else if ((mask & (N_BF16)) != 0)
15153 *type = NT_bfloat;
15154 else
15155 return FAIL;
15157 return SUCCESS;
15160 /* Modify a bitmask of allowed types. This is only needed for type
15161 relaxation. */
15163 static unsigned
15164 modify_types_allowed (unsigned allowed, unsigned mods)
15166 unsigned size;
15167 enum neon_el_type type;
15168 unsigned destmask;
15169 int i;
15171 destmask = 0;
15173 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15175 if (el_type_of_type_chk (&type, &size,
15176 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15178 neon_modify_type_size (mods, &type, &size);
15179 destmask |= type_chk_of_el_type (type, size);
15183 return destmask;
15186 /* Check type and return type classification.
15187 The manual states (paraphrase): If one datatype is given, it indicates the
15188 type given in:
15189 - the second operand, if there is one
15190 - the operand, if there is no second operand
15191 - the result, if there are no operands.
15192 This isn't quite good enough though, so we use a concept of a "key" datatype
15193 which is set on a per-instruction basis, which is the one which matters when
15194 only one data type is written.
15195 Note: this function has side-effects (e.g. filling in missing operands). All
15196 Neon instructions should call it before performing bit encoding. */
15198 static struct neon_type_el
15199 neon_check_type (unsigned els, enum neon_shape ns, ...)
15201 va_list ap;
15202 unsigned i, pass, key_el = 0;
15203 unsigned types[NEON_MAX_TYPE_ELS];
15204 enum neon_el_type k_type = NT_invtype;
15205 unsigned k_size = -1u;
15206 struct neon_type_el badtype = {NT_invtype, -1};
15207 unsigned key_allowed = 0;
15209 /* Optional registers in Neon instructions are always (not) in operand 1.
15210 Fill in the missing operand here, if it was omitted. */
15211 if (els > 1 && !inst.operands[1].present)
15212 inst.operands[1] = inst.operands[0];
15214 /* Suck up all the varargs. */
15215 va_start (ap, ns);
15216 for (i = 0; i < els; i++)
15218 unsigned thisarg = va_arg (ap, unsigned);
15219 if (thisarg == N_IGNORE_TYPE)
15221 va_end (ap);
15222 return badtype;
15224 types[i] = thisarg;
15225 if ((thisarg & N_KEY) != 0)
15226 key_el = i;
15228 va_end (ap);
15230 if (inst.vectype.elems > 0)
15231 for (i = 0; i < els; i++)
15232 if (inst.operands[i].vectype.type != NT_invtype)
15234 first_error (_("types specified in both the mnemonic and operands"));
15235 return badtype;
15238 /* Duplicate inst.vectype elements here as necessary.
15239 FIXME: No idea if this is exactly the same as the ARM assembler,
15240 particularly when an insn takes one register and one non-register
15241 operand. */
15242 if (inst.vectype.elems == 1 && els > 1)
15244 unsigned j;
15245 inst.vectype.elems = els;
15246 inst.vectype.el[key_el] = inst.vectype.el[0];
15247 for (j = 0; j < els; j++)
15248 if (j != key_el)
15249 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15250 types[j]);
15252 else if (inst.vectype.elems == 0 && els > 0)
15254 unsigned j;
15255 /* No types were given after the mnemonic, so look for types specified
15256 after each operand. We allow some flexibility here; as long as the
15257 "key" operand has a type, we can infer the others. */
15258 for (j = 0; j < els; j++)
15259 if (inst.operands[j].vectype.type != NT_invtype)
15260 inst.vectype.el[j] = inst.operands[j].vectype;
15262 if (inst.operands[key_el].vectype.type != NT_invtype)
15264 for (j = 0; j < els; j++)
15265 if (inst.operands[j].vectype.type == NT_invtype)
15266 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15267 types[j]);
15269 else
15271 first_error (_("operand types can't be inferred"));
15272 return badtype;
15275 else if (inst.vectype.elems != els)
15277 first_error (_("type specifier has the wrong number of parts"));
15278 return badtype;
15281 for (pass = 0; pass < 2; pass++)
15283 for (i = 0; i < els; i++)
15285 unsigned thisarg = types[i];
15286 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15287 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15288 enum neon_el_type g_type = inst.vectype.el[i].type;
15289 unsigned g_size = inst.vectype.el[i].size;
15291 /* Decay more-specific signed & unsigned types to sign-insensitive
15292 integer types if sign-specific variants are unavailable. */
15293 if ((g_type == NT_signed || g_type == NT_unsigned)
15294 && (types_allowed & N_SU_ALL) == 0)
15295 g_type = NT_integer;
15297 /* If only untyped args are allowed, decay any more specific types to
15298 them. Some instructions only care about signs for some element
15299 sizes, so handle that properly. */
15300 if (((types_allowed & N_UNT) == 0)
15301 && ((g_size == 8 && (types_allowed & N_8) != 0)
15302 || (g_size == 16 && (types_allowed & N_16) != 0)
15303 || (g_size == 32 && (types_allowed & N_32) != 0)
15304 || (g_size == 64 && (types_allowed & N_64) != 0)))
15305 g_type = NT_untyped;
15307 if (pass == 0)
15309 if ((thisarg & N_KEY) != 0)
15311 k_type = g_type;
15312 k_size = g_size;
15313 key_allowed = thisarg & ~N_KEY;
15315 /* Check architecture constraint on FP16 extension. */
15316 if (k_size == 16
15317 && k_type == NT_float
15318 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15320 inst.error = _(BAD_FP16);
15321 return badtype;
15325 else
15327 if ((thisarg & N_VFP) != 0)
15329 enum neon_shape_el regshape;
15330 unsigned regwidth, match;
15332 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15333 if (ns == NS_NULL)
15335 first_error (_("invalid instruction shape"));
15336 return badtype;
15338 regshape = neon_shape_tab[ns].el[i];
15339 regwidth = neon_shape_el_size[regshape];
15341 /* In VFP mode, operands must match register widths. If we
15342 have a key operand, use its width, else use the width of
15343 the current operand. */
15344 if (k_size != -1u)
15345 match = k_size;
15346 else
15347 match = g_size;
15349 /* FP16 will use a single precision register. */
15350 if (regwidth == 32 && match == 16)
15352 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15353 match = regwidth;
15354 else
15356 inst.error = _(BAD_FP16);
15357 return badtype;
15361 if (regwidth != match)
15363 first_error (_("operand size must match register width"));
15364 return badtype;
15368 if ((thisarg & N_EQK) == 0)
15370 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15372 if ((given_type & types_allowed) == 0)
15374 first_error (BAD_SIMD_TYPE);
15375 return badtype;
15378 else
15380 enum neon_el_type mod_k_type = k_type;
15381 unsigned mod_k_size = k_size;
15382 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15383 if (g_type != mod_k_type || g_size != mod_k_size)
15385 first_error (_("inconsistent types in Neon instruction"));
15386 return badtype;
15393 return inst.vectype.el[key_el];
15396 /* Neon-style VFP instruction forwarding. */
15398 /* Thumb VFP instructions have 0xE in the condition field. */
15400 static void
15401 do_vfp_cond_or_thumb (void)
15403 inst.is_neon = 1;
15405 if (thumb_mode)
15406 inst.instruction |= 0xe0000000;
15407 else
15408 inst.instruction |= inst.cond << 28;
15411 /* Look up and encode a simple mnemonic, for use as a helper function for the
15412 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15413 etc. It is assumed that operand parsing has already been done, and that the
15414 operands are in the form expected by the given opcode (this isn't necessarily
15415 the same as the form in which they were parsed, hence some massaging must
15416 take place before this function is called).
15417 Checks current arch version against that in the looked-up opcode. */
15419 static void
15420 do_vfp_nsyn_opcode (const char *opname)
15422 const struct asm_opcode *opcode;
15424 opcode = (const struct asm_opcode *) str_hash_find (arm_ops_hsh, opname);
15426 if (!opcode)
15427 abort ();
15429 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
15430 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15431 _(BAD_FPU));
15433 inst.is_neon = 1;
15435 if (thumb_mode)
15437 inst.instruction = opcode->tvalue;
15438 opcode->tencode ();
15440 else
15442 inst.instruction = (inst.cond << 28) | opcode->avalue;
15443 opcode->aencode ();
15447 static void
15448 do_vfp_nsyn_add_sub (enum neon_shape rs)
15450 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15452 if (rs == NS_FFF || rs == NS_HHH)
15454 if (is_add)
15455 do_vfp_nsyn_opcode ("fadds");
15456 else
15457 do_vfp_nsyn_opcode ("fsubs");
15459 /* ARMv8.2 fp16 instruction. */
15460 if (rs == NS_HHH)
15461 do_scalar_fp16_v82_encode ();
15463 else
15465 if (is_add)
15466 do_vfp_nsyn_opcode ("faddd");
15467 else
15468 do_vfp_nsyn_opcode ("fsubd");
15472 /* Check operand types to see if this is a VFP instruction, and if so call
15473 PFN (). */
15475 static int
15476 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15478 enum neon_shape rs;
15479 struct neon_type_el et;
15481 switch (args)
15483 case 2:
15484 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15485 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15486 break;
15488 case 3:
15489 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15490 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15491 N_F_ALL | N_KEY | N_VFP);
15492 break;
15494 default:
15495 abort ();
15498 if (et.type != NT_invtype)
15500 pfn (rs);
15501 return SUCCESS;
15504 inst.error = NULL;
15505 return FAIL;
15508 static void
15509 do_vfp_nsyn_mla_mls (enum neon_shape rs)
15511 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
15513 if (rs == NS_FFF || rs == NS_HHH)
15515 if (is_mla)
15516 do_vfp_nsyn_opcode ("fmacs");
15517 else
15518 do_vfp_nsyn_opcode ("fnmacs");
15520 /* ARMv8.2 fp16 instruction. */
15521 if (rs == NS_HHH)
15522 do_scalar_fp16_v82_encode ();
15524 else
15526 if (is_mla)
15527 do_vfp_nsyn_opcode ("fmacd");
15528 else
15529 do_vfp_nsyn_opcode ("fnmacd");
15533 static void
15534 do_vfp_nsyn_fma_fms (enum neon_shape rs)
15536 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15538 if (rs == NS_FFF || rs == NS_HHH)
15540 if (is_fma)
15541 do_vfp_nsyn_opcode ("ffmas");
15542 else
15543 do_vfp_nsyn_opcode ("ffnmas");
15545 /* ARMv8.2 fp16 instruction. */
15546 if (rs == NS_HHH)
15547 do_scalar_fp16_v82_encode ();
15549 else
15551 if (is_fma)
15552 do_vfp_nsyn_opcode ("ffmad");
15553 else
15554 do_vfp_nsyn_opcode ("ffnmad");
15558 static void
15559 do_vfp_nsyn_mul (enum neon_shape rs)
15561 if (rs == NS_FFF || rs == NS_HHH)
15563 do_vfp_nsyn_opcode ("fmuls");
15565 /* ARMv8.2 fp16 instruction. */
15566 if (rs == NS_HHH)
15567 do_scalar_fp16_v82_encode ();
15569 else
15570 do_vfp_nsyn_opcode ("fmuld");
15573 static void
15574 do_vfp_nsyn_abs_neg (enum neon_shape rs)
15576 int is_neg = (inst.instruction & 0x80) != 0;
15577 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
15579 if (rs == NS_FF || rs == NS_HH)
15581 if (is_neg)
15582 do_vfp_nsyn_opcode ("fnegs");
15583 else
15584 do_vfp_nsyn_opcode ("fabss");
15586 /* ARMv8.2 fp16 instruction. */
15587 if (rs == NS_HH)
15588 do_scalar_fp16_v82_encode ();
15590 else
15592 if (is_neg)
15593 do_vfp_nsyn_opcode ("fnegd");
15594 else
15595 do_vfp_nsyn_opcode ("fabsd");
15599 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15600 insns belong to Neon, and are handled elsewhere. */
15602 static void
15603 do_vfp_nsyn_ldm_stm (int is_dbmode)
15605 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15606 if (is_ldm)
15608 if (is_dbmode)
15609 do_vfp_nsyn_opcode ("fldmdbs");
15610 else
15611 do_vfp_nsyn_opcode ("fldmias");
15613 else
15615 if (is_dbmode)
15616 do_vfp_nsyn_opcode ("fstmdbs");
15617 else
15618 do_vfp_nsyn_opcode ("fstmias");
15622 static void
15623 do_vfp_nsyn_sqrt (void)
15625 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15626 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15628 if (rs == NS_FF || rs == NS_HH)
15630 do_vfp_nsyn_opcode ("fsqrts");
15632 /* ARMv8.2 fp16 instruction. */
15633 if (rs == NS_HH)
15634 do_scalar_fp16_v82_encode ();
15636 else
15637 do_vfp_nsyn_opcode ("fsqrtd");
15640 static void
15641 do_vfp_nsyn_div (void)
15643 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15644 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15645 N_F_ALL | N_KEY | N_VFP);
15647 if (rs == NS_FFF || rs == NS_HHH)
15649 do_vfp_nsyn_opcode ("fdivs");
15651 /* ARMv8.2 fp16 instruction. */
15652 if (rs == NS_HHH)
15653 do_scalar_fp16_v82_encode ();
15655 else
15656 do_vfp_nsyn_opcode ("fdivd");
15659 static void
15660 do_vfp_nsyn_nmul (void)
15662 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15663 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15664 N_F_ALL | N_KEY | N_VFP);
15666 if (rs == NS_FFF || rs == NS_HHH)
15668 NEON_ENCODE (SINGLE, inst);
15669 do_vfp_sp_dyadic ();
15671 /* ARMv8.2 fp16 instruction. */
15672 if (rs == NS_HHH)
15673 do_scalar_fp16_v82_encode ();
15675 else
15677 NEON_ENCODE (DOUBLE, inst);
15678 do_vfp_dp_rd_rn_rm ();
15680 do_vfp_cond_or_thumb ();
15684 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15685 (0, 1, 2, 3). */
15687 static unsigned
15688 neon_logbits (unsigned x)
15690 return ffs (x) - 4;
15693 #define LOW4(R) ((R) & 0xf)
15694 #define HI1(R) (((R) >> 4) & 1)
15695 #define LOW1(R) ((R) & 0x1)
15696 #define HI4(R) (((R) >> 1) & 0xf)
15698 static unsigned
15699 mve_get_vcmp_vpt_cond (struct neon_type_el et)
15701 switch (et.type)
15703 default:
15704 first_error (BAD_EL_TYPE);
15705 return 0;
15706 case NT_float:
15707 switch (inst.operands[0].imm)
15709 default:
15710 first_error (_("invalid condition"));
15711 return 0;
15712 case 0x0:
15713 /* eq. */
15714 return 0;
15715 case 0x1:
15716 /* ne. */
15717 return 1;
15718 case 0xa:
15719 /* ge/ */
15720 return 4;
15721 case 0xb:
15722 /* lt. */
15723 return 5;
15724 case 0xc:
15725 /* gt. */
15726 return 6;
15727 case 0xd:
15728 /* le. */
15729 return 7;
15731 case NT_integer:
15732 /* only accept eq and ne. */
15733 if (inst.operands[0].imm > 1)
15735 first_error (_("invalid condition"));
15736 return 0;
15738 return inst.operands[0].imm;
15739 case NT_unsigned:
15740 if (inst.operands[0].imm == 0x2)
15741 return 2;
15742 else if (inst.operands[0].imm == 0x8)
15743 return 3;
15744 else
15746 first_error (_("invalid condition"));
15747 return 0;
15749 case NT_signed:
15750 switch (inst.operands[0].imm)
15752 default:
15753 first_error (_("invalid condition"));
15754 return 0;
15755 case 0xa:
15756 /* ge. */
15757 return 4;
15758 case 0xb:
15759 /* lt. */
15760 return 5;
15761 case 0xc:
15762 /* gt. */
15763 return 6;
15764 case 0xd:
15765 /* le. */
15766 return 7;
15769 /* Should be unreachable. */
15770 abort ();
15773 /* For VCTP (create vector tail predicate) in MVE. */
15774 static void
15775 do_mve_vctp (void)
15777 int dt = 0;
15778 unsigned size = 0x0;
15780 if (inst.cond > COND_ALWAYS)
15781 inst.pred_insn_type = INSIDE_VPT_INSN;
15782 else
15783 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15785 /* This is a typical MVE instruction which has no type but have size 8, 16,
15786 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15787 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15788 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15789 dt = inst.vectype.el[0].size;
15791 /* Setting this does not indicate an actual NEON instruction, but only
15792 indicates that the mnemonic accepts neon-style type suffixes. */
15793 inst.is_neon = 1;
15795 switch (dt)
15797 case 8:
15798 break;
15799 case 16:
15800 size = 0x1; break;
15801 case 32:
15802 size = 0x2; break;
15803 case 64:
15804 size = 0x3; break;
15805 default:
15806 first_error (_("Type is not allowed for this instruction"));
15808 inst.instruction |= size << 20;
15809 inst.instruction |= inst.operands[0].reg << 16;
15812 static void
15813 do_mve_vpt (void)
15815 /* We are dealing with a vector predicated block. */
15816 if (inst.operands[0].present)
15818 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15819 struct neon_type_el et
15820 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15821 N_EQK);
15823 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15825 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15827 if (et.type == NT_invtype)
15828 return;
15830 if (et.type == NT_float)
15832 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15833 BAD_FPU);
15834 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
15835 inst.instruction |= (et.size == 16) << 28;
15836 inst.instruction |= 0x3 << 20;
15838 else
15840 constraint (et.size != 8 && et.size != 16 && et.size != 32,
15841 BAD_EL_TYPE);
15842 inst.instruction |= 1 << 28;
15843 inst.instruction |= neon_logbits (et.size) << 20;
15846 if (inst.operands[2].isquad)
15848 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15849 inst.instruction |= LOW4 (inst.operands[2].reg);
15850 inst.instruction |= (fcond & 0x2) >> 1;
15852 else
15854 if (inst.operands[2].reg == REG_SP)
15855 as_tsktsk (MVE_BAD_SP);
15856 inst.instruction |= 1 << 6;
15857 inst.instruction |= (fcond & 0x2) << 4;
15858 inst.instruction |= inst.operands[2].reg;
15860 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15861 inst.instruction |= (fcond & 0x4) << 10;
15862 inst.instruction |= (fcond & 0x1) << 7;
15865 set_pred_insn_type (VPT_INSN);
15866 now_pred.cc = 0;
15867 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
15868 | ((inst.instruction & 0xe000) >> 13);
15869 now_pred.warn_deprecated = false;
15870 now_pred.type = VECTOR_PRED;
15871 inst.is_neon = 1;
15874 static void
15875 do_mve_vcmp (void)
15877 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
15878 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
15879 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
15880 if (!inst.operands[2].present)
15881 first_error (_("MVE vector or ARM register expected"));
15882 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15884 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
15885 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
15886 && inst.operands[1].isquad)
15888 inst.instruction = N_MNEM_vcmp;
15889 inst.cond = 0x10;
15892 if (inst.cond > COND_ALWAYS)
15893 inst.pred_insn_type = INSIDE_VPT_INSN;
15894 else
15895 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15897 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15898 struct neon_type_el et
15899 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15900 N_EQK);
15902 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
15903 && !inst.operands[2].iszr, BAD_PC);
15905 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15907 inst.instruction = 0xee010f00;
15908 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15909 inst.instruction |= (fcond & 0x4) << 10;
15910 inst.instruction |= (fcond & 0x1) << 7;
15911 if (et.type == NT_float)
15913 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15914 BAD_FPU);
15915 inst.instruction |= (et.size == 16) << 28;
15916 inst.instruction |= 0x3 << 20;
15918 else
15920 inst.instruction |= 1 << 28;
15921 inst.instruction |= neon_logbits (et.size) << 20;
15923 if (inst.operands[2].isquad)
15925 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15926 inst.instruction |= (fcond & 0x2) >> 1;
15927 inst.instruction |= LOW4 (inst.operands[2].reg);
15929 else
15931 if (inst.operands[2].reg == REG_SP)
15932 as_tsktsk (MVE_BAD_SP);
15933 inst.instruction |= 1 << 6;
15934 inst.instruction |= (fcond & 0x2) << 4;
15935 inst.instruction |= inst.operands[2].reg;
15938 inst.is_neon = 1;
15939 return;
15942 static void
15943 do_mve_vmaxa_vmina (void)
15945 if (inst.cond > COND_ALWAYS)
15946 inst.pred_insn_type = INSIDE_VPT_INSN;
15947 else
15948 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15950 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
15951 struct neon_type_el et
15952 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
15954 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15955 inst.instruction |= neon_logbits (et.size) << 18;
15956 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15957 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15958 inst.instruction |= LOW4 (inst.operands[1].reg);
15959 inst.is_neon = 1;
15962 static void
15963 do_mve_vfmas (void)
15965 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
15966 struct neon_type_el et
15967 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
15969 if (inst.cond > COND_ALWAYS)
15970 inst.pred_insn_type = INSIDE_VPT_INSN;
15971 else
15972 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15974 if (inst.operands[2].reg == REG_SP)
15975 as_tsktsk (MVE_BAD_SP);
15976 else if (inst.operands[2].reg == REG_PC)
15977 as_tsktsk (MVE_BAD_PC);
15979 inst.instruction |= (et.size == 16) << 28;
15980 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15981 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15982 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15983 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15984 inst.instruction |= inst.operands[2].reg;
15985 inst.is_neon = 1;
15988 static void
15989 do_mve_viddup (void)
15991 if (inst.cond > COND_ALWAYS)
15992 inst.pred_insn_type = INSIDE_VPT_INSN;
15993 else
15994 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15996 unsigned imm = inst.relocs[0].exp.X_add_number;
15997 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
15998 _("immediate must be either 1, 2, 4 or 8"));
16000 enum neon_shape rs;
16001 struct neon_type_el et;
16002 unsigned Rm;
16003 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16005 rs = neon_select_shape (NS_QRI, NS_NULL);
16006 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16007 Rm = 7;
16009 else
16011 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16012 if (inst.operands[2].reg == REG_SP)
16013 as_tsktsk (MVE_BAD_SP);
16014 else if (inst.operands[2].reg == REG_PC)
16015 first_error (BAD_PC);
16017 rs = neon_select_shape (NS_QRRI, NS_NULL);
16018 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16019 Rm = inst.operands[2].reg >> 1;
16021 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16022 inst.instruction |= neon_logbits (et.size) << 20;
16023 inst.instruction |= inst.operands[1].reg << 16;
16024 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16025 inst.instruction |= (imm > 2) << 7;
16026 inst.instruction |= Rm << 1;
16027 inst.instruction |= (imm == 2 || imm == 8);
16028 inst.is_neon = 1;
16031 static void
16032 do_mve_vmlas (void)
16034 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16035 struct neon_type_el et
16036 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16038 if (inst.operands[2].reg == REG_PC)
16039 as_tsktsk (MVE_BAD_PC);
16040 else if (inst.operands[2].reg == REG_SP)
16041 as_tsktsk (MVE_BAD_SP);
16043 if (inst.cond > COND_ALWAYS)
16044 inst.pred_insn_type = INSIDE_VPT_INSN;
16045 else
16046 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16048 inst.instruction |= (et.type == NT_unsigned) << 28;
16049 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16050 inst.instruction |= neon_logbits (et.size) << 20;
16051 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16052 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16053 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16054 inst.instruction |= inst.operands[2].reg;
16055 inst.is_neon = 1;
16058 static void
16059 do_mve_vshll (void)
16061 struct neon_type_el et
16062 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16064 if (inst.cond > COND_ALWAYS)
16065 inst.pred_insn_type = INSIDE_VPT_INSN;
16066 else
16067 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16069 int imm = inst.operands[2].imm;
16070 constraint (imm < 1 || (unsigned)imm > et.size,
16071 _("immediate value out of range"));
16073 if ((unsigned)imm == et.size)
16075 inst.instruction |= neon_logbits (et.size) << 18;
16076 inst.instruction |= 0x110001;
16078 else
16080 inst.instruction |= (et.size + imm) << 16;
16081 inst.instruction |= 0x800140;
16084 inst.instruction |= (et.type == NT_unsigned) << 28;
16085 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16086 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16087 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16088 inst.instruction |= LOW4 (inst.operands[1].reg);
16089 inst.is_neon = 1;
16092 static void
16093 do_mve_vshlc (void)
16095 if (inst.cond > COND_ALWAYS)
16096 inst.pred_insn_type = INSIDE_VPT_INSN;
16097 else
16098 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16100 if (inst.operands[1].reg == REG_PC)
16101 as_tsktsk (MVE_BAD_PC);
16102 else if (inst.operands[1].reg == REG_SP)
16103 as_tsktsk (MVE_BAD_SP);
16105 int imm = inst.operands[2].imm;
16106 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16108 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16109 inst.instruction |= (imm & 0x1f) << 16;
16110 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16111 inst.instruction |= inst.operands[1].reg;
16112 inst.is_neon = 1;
16115 static void
16116 do_mve_vshrn (void)
16118 unsigned types;
16119 switch (inst.instruction)
16121 case M_MNEM_vshrnt:
16122 case M_MNEM_vshrnb:
16123 case M_MNEM_vrshrnt:
16124 case M_MNEM_vrshrnb:
16125 types = N_I16 | N_I32;
16126 break;
16127 case M_MNEM_vqshrnt:
16128 case M_MNEM_vqshrnb:
16129 case M_MNEM_vqrshrnt:
16130 case M_MNEM_vqrshrnb:
16131 types = N_U16 | N_U32 | N_S16 | N_S32;
16132 break;
16133 case M_MNEM_vqshrunt:
16134 case M_MNEM_vqshrunb:
16135 case M_MNEM_vqrshrunt:
16136 case M_MNEM_vqrshrunb:
16137 types = N_S16 | N_S32;
16138 break;
16139 default:
16140 abort ();
16143 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16145 if (inst.cond > COND_ALWAYS)
16146 inst.pred_insn_type = INSIDE_VPT_INSN;
16147 else
16148 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16150 unsigned Qd = inst.operands[0].reg;
16151 unsigned Qm = inst.operands[1].reg;
16152 unsigned imm = inst.operands[2].imm;
16153 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16154 et.size == 16
16155 ? _("immediate operand expected in the range [1,8]")
16156 : _("immediate operand expected in the range [1,16]"));
16158 inst.instruction |= (et.type == NT_unsigned) << 28;
16159 inst.instruction |= HI1 (Qd) << 22;
16160 inst.instruction |= (et.size - imm) << 16;
16161 inst.instruction |= LOW4 (Qd) << 12;
16162 inst.instruction |= HI1 (Qm) << 5;
16163 inst.instruction |= LOW4 (Qm);
16164 inst.is_neon = 1;
16167 static void
16168 do_mve_vqmovn (void)
16170 struct neon_type_el et;
16171 if (inst.instruction == M_MNEM_vqmovnt
16172 || inst.instruction == M_MNEM_vqmovnb)
16173 et = neon_check_type (2, NS_QQ, N_EQK,
16174 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16175 else
16176 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16178 if (inst.cond > COND_ALWAYS)
16179 inst.pred_insn_type = INSIDE_VPT_INSN;
16180 else
16181 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16183 inst.instruction |= (et.type == NT_unsigned) << 28;
16184 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16185 inst.instruction |= (et.size == 32) << 18;
16186 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16187 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16188 inst.instruction |= LOW4 (inst.operands[1].reg);
16189 inst.is_neon = 1;
16192 static void
16193 do_mve_vpsel (void)
16195 neon_select_shape (NS_QQQ, NS_NULL);
16197 if (inst.cond > COND_ALWAYS)
16198 inst.pred_insn_type = INSIDE_VPT_INSN;
16199 else
16200 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16202 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16203 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16204 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16205 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16206 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16207 inst.instruction |= LOW4 (inst.operands[2].reg);
16208 inst.is_neon = 1;
16211 static void
16212 do_mve_vpnot (void)
16214 if (inst.cond > COND_ALWAYS)
16215 inst.pred_insn_type = INSIDE_VPT_INSN;
16216 else
16217 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16220 static void
16221 do_mve_vmaxnma_vminnma (void)
16223 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16224 struct neon_type_el et
16225 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16227 if (inst.cond > COND_ALWAYS)
16228 inst.pred_insn_type = INSIDE_VPT_INSN;
16229 else
16230 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16232 inst.instruction |= (et.size == 16) << 28;
16233 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16234 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16235 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16236 inst.instruction |= LOW4 (inst.operands[1].reg);
16237 inst.is_neon = 1;
16240 static void
16241 do_mve_vcmul (void)
16243 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16244 struct neon_type_el et
16245 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16247 if (inst.cond > COND_ALWAYS)
16248 inst.pred_insn_type = INSIDE_VPT_INSN;
16249 else
16250 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16252 unsigned rot = inst.relocs[0].exp.X_add_number;
16253 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16254 _("immediate out of range"));
16256 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16257 || inst.operands[0].reg == inst.operands[2].reg))
16258 as_tsktsk (BAD_MVE_SRCDEST);
16260 inst.instruction |= (et.size == 32) << 28;
16261 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16262 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16263 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16264 inst.instruction |= (rot > 90) << 12;
16265 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16266 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16267 inst.instruction |= LOW4 (inst.operands[2].reg);
16268 inst.instruction |= (rot == 90 || rot == 270);
16269 inst.is_neon = 1;
16272 /* To handle the Low Overhead Loop instructions
16273 in Armv8.1-M Mainline and MVE. */
16274 static void
16275 do_t_loloop (void)
16277 unsigned long insn = inst.instruction;
16279 inst.instruction = THUMB_OP32 (inst.instruction);
16281 if (insn == T_MNEM_lctp)
16282 return;
16284 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16286 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16288 struct neon_type_el et
16289 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16290 inst.instruction |= neon_logbits (et.size) << 20;
16291 inst.is_neon = 1;
16294 switch (insn)
16296 case T_MNEM_letp:
16297 constraint (!inst.operands[0].present,
16298 _("expected LR"));
16299 /* fall through. */
16300 case T_MNEM_le:
16301 /* le <label>. */
16302 if (!inst.operands[0].present)
16303 inst.instruction |= 1 << 21;
16305 v8_1_loop_reloc (true);
16306 break;
16308 case T_MNEM_wls:
16309 case T_MNEM_wlstp:
16310 v8_1_loop_reloc (false);
16311 /* fall through. */
16312 case T_MNEM_dlstp:
16313 case T_MNEM_dls:
16314 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16316 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16317 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16318 else if (inst.operands[1].reg == REG_PC)
16319 as_tsktsk (MVE_BAD_PC);
16320 if (inst.operands[1].reg == REG_SP)
16321 as_tsktsk (MVE_BAD_SP);
16323 inst.instruction |= (inst.operands[1].reg << 16);
16324 break;
16326 default:
16327 abort ();
16332 static void
16333 do_vfp_nsyn_cmp (void)
16335 enum neon_shape rs;
16336 if (!inst.operands[0].isreg)
16338 do_mve_vcmp ();
16339 return;
16341 else
16343 constraint (inst.operands[2].present, BAD_SYNTAX);
16344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16345 BAD_FPU);
16348 if (inst.operands[1].isreg)
16350 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16351 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
16353 if (rs == NS_FF || rs == NS_HH)
16355 NEON_ENCODE (SINGLE, inst);
16356 do_vfp_sp_monadic ();
16358 else
16360 NEON_ENCODE (DOUBLE, inst);
16361 do_vfp_dp_rd_rm ();
16364 else
16366 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16367 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
16369 switch (inst.instruction & 0x0fffffff)
16371 case N_MNEM_vcmp:
16372 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16373 break;
16374 case N_MNEM_vcmpe:
16375 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16376 break;
16377 default:
16378 abort ();
16381 if (rs == NS_FI || rs == NS_HI)
16383 NEON_ENCODE (SINGLE, inst);
16384 do_vfp_sp_compare_z ();
16386 else
16388 NEON_ENCODE (DOUBLE, inst);
16389 do_vfp_dp_rd ();
16392 do_vfp_cond_or_thumb ();
16394 /* ARMv8.2 fp16 instruction. */
16395 if (rs == NS_HI || rs == NS_HH)
16396 do_scalar_fp16_v82_encode ();
16399 static void
16400 nsyn_insert_sp (void)
16402 inst.operands[1] = inst.operands[0];
16403 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
16404 inst.operands[0].reg = REG_SP;
16405 inst.operands[0].isreg = 1;
16406 inst.operands[0].writeback = 1;
16407 inst.operands[0].present = 1;
16410 /* Fix up Neon data-processing instructions, ORing in the correct bits for
16411 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16413 static void
16414 neon_dp_fixup (struct arm_it* insn)
16416 unsigned int i = insn->instruction;
16417 insn->is_neon = 1;
16419 if (thumb_mode)
16421 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16422 if (i & (1 << 24))
16423 i |= 1 << 28;
16425 i &= ~(1 << 24);
16427 i |= 0xef000000;
16429 else
16430 i |= 0xf2000000;
16432 insn->instruction = i;
16435 static void
16436 mve_encode_qqr (int size, int U, int fp)
16438 if (inst.operands[2].reg == REG_SP)
16439 as_tsktsk (MVE_BAD_SP);
16440 else if (inst.operands[2].reg == REG_PC)
16441 as_tsktsk (MVE_BAD_PC);
16443 if (fp)
16445 /* vadd. */
16446 if (((unsigned)inst.instruction) == 0xd00)
16447 inst.instruction = 0xee300f40;
16448 /* vsub. */
16449 else if (((unsigned)inst.instruction) == 0x200d00)
16450 inst.instruction = 0xee301f40;
16451 /* vmul. */
16452 else if (((unsigned)inst.instruction) == 0x1000d10)
16453 inst.instruction = 0xee310e60;
16455 /* Setting size which is 1 for F16 and 0 for F32. */
16456 inst.instruction |= (size == 16) << 28;
16458 else
16460 /* vadd. */
16461 if (((unsigned)inst.instruction) == 0x800)
16462 inst.instruction = 0xee010f40;
16463 /* vsub. */
16464 else if (((unsigned)inst.instruction) == 0x1000800)
16465 inst.instruction = 0xee011f40;
16466 /* vhadd. */
16467 else if (((unsigned)inst.instruction) == 0)
16468 inst.instruction = 0xee000f40;
16469 /* vhsub. */
16470 else if (((unsigned)inst.instruction) == 0x200)
16471 inst.instruction = 0xee001f40;
16472 /* vmla. */
16473 else if (((unsigned)inst.instruction) == 0x900)
16474 inst.instruction = 0xee010e40;
16475 /* vmul. */
16476 else if (((unsigned)inst.instruction) == 0x910)
16477 inst.instruction = 0xee011e60;
16478 /* vqadd. */
16479 else if (((unsigned)inst.instruction) == 0x10)
16480 inst.instruction = 0xee000f60;
16481 /* vqsub. */
16482 else if (((unsigned)inst.instruction) == 0x210)
16483 inst.instruction = 0xee001f60;
16484 /* vqrdmlah. */
16485 else if (((unsigned)inst.instruction) == 0x3000b10)
16486 inst.instruction = 0xee000e40;
16487 /* vqdmulh. */
16488 else if (((unsigned)inst.instruction) == 0x0000b00)
16489 inst.instruction = 0xee010e60;
16490 /* vqrdmulh. */
16491 else if (((unsigned)inst.instruction) == 0x1000b00)
16492 inst.instruction = 0xfe010e60;
16494 /* Set U-bit. */
16495 inst.instruction |= U << 28;
16497 /* Setting bits for size. */
16498 inst.instruction |= neon_logbits (size) << 20;
16500 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16501 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16502 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16503 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16504 inst.instruction |= inst.operands[2].reg;
16505 inst.is_neon = 1;
16508 static void
16509 mve_encode_rqq (unsigned bit28, unsigned size)
16511 inst.instruction |= bit28 << 28;
16512 inst.instruction |= neon_logbits (size) << 20;
16513 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16514 inst.instruction |= inst.operands[0].reg << 12;
16515 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16516 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16517 inst.instruction |= LOW4 (inst.operands[2].reg);
16518 inst.is_neon = 1;
16521 static void
16522 mve_encode_qqq (int ubit, int size)
16525 inst.instruction |= (ubit != 0) << 28;
16526 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16527 inst.instruction |= neon_logbits (size) << 20;
16528 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16530 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16531 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16532 inst.instruction |= LOW4 (inst.operands[2].reg);
16534 inst.is_neon = 1;
16537 static void
16538 mve_encode_rq (unsigned bit28, unsigned size)
16540 inst.instruction |= bit28 << 28;
16541 inst.instruction |= neon_logbits (size) << 18;
16542 inst.instruction |= inst.operands[0].reg << 12;
16543 inst.instruction |= LOW4 (inst.operands[1].reg);
16544 inst.is_neon = 1;
16547 static void
16548 mve_encode_rrqq (unsigned U, unsigned size)
16550 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16552 inst.instruction |= U << 28;
16553 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16554 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16555 inst.instruction |= (size == 32) << 16;
16556 inst.instruction |= inst.operands[0].reg << 12;
16557 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16558 inst.instruction |= inst.operands[3].reg;
16559 inst.is_neon = 1;
16562 /* Helper function for neon_three_same handling the operands. */
16563 static void
16564 neon_three_args (int isquad)
16566 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16567 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16568 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16569 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16570 inst.instruction |= LOW4 (inst.operands[2].reg);
16571 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16572 inst.instruction |= (isquad != 0) << 6;
16573 inst.is_neon = 1;
16576 /* Encode insns with bit pattern:
16578 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16579 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
16581 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16582 different meaning for some instruction. */
16584 static void
16585 neon_three_same (int isquad, int ubit, int size)
16587 neon_three_args (isquad);
16588 inst.instruction |= (ubit != 0) << 24;
16589 if (size != -1)
16590 inst.instruction |= neon_logbits (size) << 20;
16592 neon_dp_fixup (&inst);
16595 /* Encode instructions of the form:
16597 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16598 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
16600 Don't write size if SIZE == -1. */
16602 static void
16603 neon_two_same (int qbit, int ubit, int size)
16605 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16606 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16607 inst.instruction |= LOW4 (inst.operands[1].reg);
16608 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16609 inst.instruction |= (qbit != 0) << 6;
16610 inst.instruction |= (ubit != 0) << 24;
16612 if (size != -1)
16613 inst.instruction |= neon_logbits (size) << 18;
16615 neon_dp_fixup (&inst);
16618 enum vfp_or_neon_is_neon_bits
16620 NEON_CHECK_CC = 1,
16621 NEON_CHECK_ARCH = 2,
16622 NEON_CHECK_ARCH8 = 4
16625 /* Call this function if an instruction which may have belonged to the VFP or
16626 Neon instruction sets, but turned out to be a Neon instruction (due to the
16627 operand types involved, etc.). We have to check and/or fix-up a couple of
16628 things:
16630 - Make sure the user hasn't attempted to make a Neon instruction
16631 conditional.
16632 - Alter the value in the condition code field if necessary.
16633 - Make sure that the arch supports Neon instructions.
16635 Which of these operations take place depends on bits from enum
16636 vfp_or_neon_is_neon_bits.
16638 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16639 current instruction's condition is COND_ALWAYS, the condition field is
16640 changed to inst.uncond_value. This is necessary because instructions shared
16641 between VFP and Neon may be conditional for the VFP variants only, and the
16642 unconditional Neon version must have, e.g., 0xF in the condition field. */
16644 static int
16645 vfp_or_neon_is_neon (unsigned check)
16647 /* Conditions are always legal in Thumb mode (IT blocks). */
16648 if (!thumb_mode && (check & NEON_CHECK_CC))
16650 if (inst.cond != COND_ALWAYS)
16652 first_error (_(BAD_COND));
16653 return FAIL;
16655 if (inst.uncond_value != -1u)
16656 inst.instruction |= inst.uncond_value << 28;
16660 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16661 || ((check & NEON_CHECK_ARCH8)
16662 && !mark_feature_used (&fpu_neon_ext_armv8)))
16664 first_error (_(BAD_FPU));
16665 return FAIL;
16668 return SUCCESS;
16672 /* Return TRUE if the SIMD instruction is available for the current
16673 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16674 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16675 vfp_or_neon_is_neon for the NEON specific checks. */
16677 static bool
16678 check_simd_pred_availability (int fp, unsigned check)
16680 if (inst.cond > COND_ALWAYS)
16682 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16684 inst.error = BAD_FPU;
16685 return false;
16687 inst.pred_insn_type = INSIDE_VPT_INSN;
16689 else if (inst.cond < COND_ALWAYS)
16691 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16692 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16693 else if (vfp_or_neon_is_neon (check) == FAIL)
16694 return false;
16696 else
16698 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16699 && vfp_or_neon_is_neon (check) == FAIL)
16700 return false;
16702 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16703 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16705 return true;
16708 /* Neon instruction encoders, in approximate order of appearance. */
16710 static void
16711 do_neon_dyadic_i_su (void)
16713 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
16714 return;
16716 enum neon_shape rs;
16717 struct neon_type_el et;
16718 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16719 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16720 else
16721 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16723 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16726 if (rs != NS_QQR)
16727 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16728 else
16729 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16732 static void
16733 do_neon_dyadic_i64_su (void)
16735 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
16736 return;
16737 enum neon_shape rs;
16738 struct neon_type_el et;
16739 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16741 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16742 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16744 else
16746 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16747 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16749 if (rs == NS_QQR)
16750 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16751 else
16752 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16755 static void
16756 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
16757 unsigned immbits)
16759 unsigned size = et.size >> 3;
16760 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16761 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16762 inst.instruction |= LOW4 (inst.operands[1].reg);
16763 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16764 inst.instruction |= (isquad != 0) << 6;
16765 inst.instruction |= immbits << 16;
16766 inst.instruction |= (size >> 3) << 7;
16767 inst.instruction |= (size & 0x7) << 19;
16768 if (write_ubit)
16769 inst.instruction |= (uval != 0) << 24;
16771 neon_dp_fixup (&inst);
16774 static void
16775 do_neon_shl (void)
16777 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
16778 return;
16780 if (!inst.operands[2].isreg)
16782 enum neon_shape rs;
16783 struct neon_type_el et;
16784 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16786 rs = neon_select_shape (NS_QQI, NS_NULL);
16787 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16789 else
16791 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16792 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16794 int imm = inst.operands[2].imm;
16796 constraint (imm < 0 || (unsigned)imm >= et.size,
16797 _("immediate out of range for shift"));
16798 NEON_ENCODE (IMMED, inst);
16799 neon_imm_shift (false, 0, neon_quad (rs), et, imm);
16801 else
16803 enum neon_shape rs;
16804 struct neon_type_el et;
16805 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16807 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16808 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16810 else
16812 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16813 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16817 if (rs == NS_QQR)
16819 constraint (inst.operands[0].reg != inst.operands[1].reg,
16820 _("invalid instruction shape"));
16821 if (inst.operands[2].reg == REG_SP)
16822 as_tsktsk (MVE_BAD_SP);
16823 else if (inst.operands[2].reg == REG_PC)
16824 as_tsktsk (MVE_BAD_PC);
16826 inst.instruction = 0xee311e60;
16827 inst.instruction |= (et.type == NT_unsigned) << 28;
16828 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16829 inst.instruction |= neon_logbits (et.size) << 18;
16830 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16831 inst.instruction |= inst.operands[2].reg;
16832 inst.is_neon = 1;
16834 else
16836 unsigned int tmp;
16838 /* VSHL/VQSHL 3-register variants have syntax such as:
16839 vshl.xx Dd, Dm, Dn
16840 whereas other 3-register operations encoded by neon_three_same have
16841 syntax like:
16842 vadd.xx Dd, Dn, Dm
16843 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
16844 operands[2].reg here. */
16845 tmp = inst.operands[2].reg;
16846 inst.operands[2].reg = inst.operands[1].reg;
16847 inst.operands[1].reg = tmp;
16848 NEON_ENCODE (INTEGER, inst);
16849 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16854 static void
16855 do_neon_qshl (void)
16857 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
16858 return;
16860 if (!inst.operands[2].isreg)
16862 enum neon_shape rs;
16863 struct neon_type_el et;
16864 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16866 rs = neon_select_shape (NS_QQI, NS_NULL);
16867 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
16869 else
16871 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16872 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16874 int imm = inst.operands[2].imm;
16876 constraint (imm < 0 || (unsigned)imm >= et.size,
16877 _("immediate out of range for shift"));
16878 NEON_ENCODE (IMMED, inst);
16879 neon_imm_shift (true, et.type == NT_unsigned, neon_quad (rs), et, imm);
16881 else
16883 enum neon_shape rs;
16884 struct neon_type_el et;
16886 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16888 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16889 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16891 else
16893 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16894 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16897 if (rs == NS_QQR)
16899 constraint (inst.operands[0].reg != inst.operands[1].reg,
16900 _("invalid instruction shape"));
16901 if (inst.operands[2].reg == REG_SP)
16902 as_tsktsk (MVE_BAD_SP);
16903 else if (inst.operands[2].reg == REG_PC)
16904 as_tsktsk (MVE_BAD_PC);
16906 inst.instruction = 0xee311ee0;
16907 inst.instruction |= (et.type == NT_unsigned) << 28;
16908 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16909 inst.instruction |= neon_logbits (et.size) << 18;
16910 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16911 inst.instruction |= inst.operands[2].reg;
16912 inst.is_neon = 1;
16914 else
16916 unsigned int tmp;
16918 /* See note in do_neon_shl. */
16919 tmp = inst.operands[2].reg;
16920 inst.operands[2].reg = inst.operands[1].reg;
16921 inst.operands[1].reg = tmp;
16922 NEON_ENCODE (INTEGER, inst);
16923 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16928 static void
16929 do_neon_rshl (void)
16931 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
16932 return;
16934 enum neon_shape rs;
16935 struct neon_type_el et;
16936 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16938 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16939 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16941 else
16943 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16944 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16947 unsigned int tmp;
16949 if (rs == NS_QQR)
16951 if (inst.operands[2].reg == REG_PC)
16952 as_tsktsk (MVE_BAD_PC);
16953 else if (inst.operands[2].reg == REG_SP)
16954 as_tsktsk (MVE_BAD_SP);
16956 constraint (inst.operands[0].reg != inst.operands[1].reg,
16957 _("invalid instruction shape"));
16959 if (inst.instruction == 0x0000510)
16960 /* We are dealing with vqrshl. */
16961 inst.instruction = 0xee331ee0;
16962 else
16963 /* We are dealing with vrshl. */
16964 inst.instruction = 0xee331e60;
16966 inst.instruction |= (et.type == NT_unsigned) << 28;
16967 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16968 inst.instruction |= neon_logbits (et.size) << 18;
16969 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16970 inst.instruction |= inst.operands[2].reg;
16971 inst.is_neon = 1;
16973 else
16975 tmp = inst.operands[2].reg;
16976 inst.operands[2].reg = inst.operands[1].reg;
16977 inst.operands[1].reg = tmp;
16978 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16982 static int
16983 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
16985 /* Handle .I8 pseudo-instructions. */
16986 if (size == 8)
16988 /* Unfortunately, this will make everything apart from zero out-of-range.
16989 FIXME is this the intended semantics? There doesn't seem much point in
16990 accepting .I8 if so. */
16991 immediate |= immediate << 8;
16992 size = 16;
16995 if (size >= 32)
16997 if (immediate == (immediate & 0x000000ff))
16999 *immbits = immediate;
17000 return 0x1;
17002 else if (immediate == (immediate & 0x0000ff00))
17004 *immbits = immediate >> 8;
17005 return 0x3;
17007 else if (immediate == (immediate & 0x00ff0000))
17009 *immbits = immediate >> 16;
17010 return 0x5;
17012 else if (immediate == (immediate & 0xff000000))
17014 *immbits = immediate >> 24;
17015 return 0x7;
17017 if ((immediate & 0xffff) != (immediate >> 16))
17018 goto bad_immediate;
17019 immediate &= 0xffff;
17022 if (immediate == (immediate & 0x000000ff))
17024 *immbits = immediate;
17025 return 0x9;
17027 else if (immediate == (immediate & 0x0000ff00))
17029 *immbits = immediate >> 8;
17030 return 0xb;
17033 bad_immediate:
17034 first_error (_("immediate value out of range"));
17035 return FAIL;
17038 static void
17039 do_neon_logic (void)
17041 if (inst.operands[2].present && inst.operands[2].isreg)
17043 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17044 if (rs == NS_QQQ
17045 && !check_simd_pred_availability (false,
17046 NEON_CHECK_ARCH | NEON_CHECK_CC))
17047 return;
17048 else if (rs != NS_QQQ
17049 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17050 first_error (BAD_FPU);
17052 neon_check_type (3, rs, N_IGNORE_TYPE);
17053 /* U bit and size field were set as part of the bitmask. */
17054 NEON_ENCODE (INTEGER, inst);
17055 neon_three_same (neon_quad (rs), 0, -1);
17057 else
17059 const int three_ops_form = (inst.operands[2].present
17060 && !inst.operands[2].isreg);
17061 const int immoperand = (three_ops_form ? 2 : 1);
17062 enum neon_shape rs = (three_ops_form
17063 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17064 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
17065 /* Because neon_select_shape makes the second operand a copy of the first
17066 if the second operand is not present. */
17067 if (rs == NS_QQI
17068 && !check_simd_pred_availability (false,
17069 NEON_CHECK_ARCH | NEON_CHECK_CC))
17070 return;
17071 else if (rs != NS_QQI
17072 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17073 first_error (BAD_FPU);
17075 struct neon_type_el et;
17076 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17077 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17078 else
17079 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17080 | N_KEY, N_EQK);
17082 if (et.type == NT_invtype)
17083 return;
17084 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
17085 unsigned immbits;
17086 int cmode;
17089 if (three_ops_form)
17090 constraint (inst.operands[0].reg != inst.operands[1].reg,
17091 _("first and second operands shall be the same register"));
17093 NEON_ENCODE (IMMED, inst);
17095 immbits = inst.operands[immoperand].imm;
17096 if (et.size == 64)
17098 /* .i64 is a pseudo-op, so the immediate must be a repeating
17099 pattern. */
17100 if (immbits != (inst.operands[immoperand].regisimm ?
17101 inst.operands[immoperand].reg : 0))
17103 /* Set immbits to an invalid constant. */
17104 immbits = 0xdeadbeef;
17108 switch (opcode)
17110 case N_MNEM_vbic:
17111 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17112 break;
17114 case N_MNEM_vorr:
17115 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17116 break;
17118 case N_MNEM_vand:
17119 /* Pseudo-instruction for VBIC. */
17120 neon_invert_size (&immbits, 0, et.size);
17121 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17122 break;
17124 case N_MNEM_vorn:
17125 /* Pseudo-instruction for VORR. */
17126 neon_invert_size (&immbits, 0, et.size);
17127 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17128 break;
17130 default:
17131 abort ();
17134 if (cmode == FAIL)
17135 return;
17137 inst.instruction |= neon_quad (rs) << 6;
17138 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17139 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17140 inst.instruction |= cmode << 8;
17141 neon_write_immbits (immbits);
17143 neon_dp_fixup (&inst);
17147 static void
17148 do_neon_bitfield (void)
17150 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17151 neon_check_type (3, rs, N_IGNORE_TYPE);
17152 neon_three_same (neon_quad (rs), 0, -1);
17155 static void
17156 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
17157 unsigned destbits)
17159 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17160 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
17161 types | N_KEY);
17162 if (et.type == NT_float)
17164 NEON_ENCODE (FLOAT, inst);
17165 if (rs == NS_QQR)
17166 mve_encode_qqr (et.size, 0, 1);
17167 else
17168 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
17170 else
17172 NEON_ENCODE (INTEGER, inst);
17173 if (rs == NS_QQR)
17174 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
17175 else
17176 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
17181 static void
17182 do_neon_dyadic_if_su_d (void)
17184 /* This version only allow D registers, but that constraint is enforced during
17185 operand parsing so we don't need to do anything extra here. */
17186 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17189 static void
17190 do_neon_dyadic_if_i_d (void)
17192 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17193 affected if we specify unsigned args. */
17194 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17197 static void
17198 do_mve_vstr_vldr_QI (int size, int elsize, int load)
17200 constraint (size < 32, BAD_ADDR_MODE);
17201 constraint (size != elsize, BAD_EL_TYPE);
17202 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17203 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17204 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17205 _("destination register and offset register may not be the"
17206 " same"));
17208 int imm = inst.relocs[0].exp.X_add_number;
17209 int add = 1;
17210 if (imm < 0)
17212 add = 0;
17213 imm = -imm;
17215 constraint ((imm % (size / 8) != 0)
17216 || imm > (0x7f << neon_logbits (size)),
17217 (size == 32) ? _("immediate must be a multiple of 4 in the"
17218 " range of +/-[0,508]")
17219 : _("immediate must be a multiple of 8 in the"
17220 " range of +/-[0,1016]"));
17221 inst.instruction |= 0x11 << 24;
17222 inst.instruction |= add << 23;
17223 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17224 inst.instruction |= inst.operands[1].writeback << 21;
17225 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17226 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17227 inst.instruction |= 1 << 12;
17228 inst.instruction |= (size == 64) << 8;
17229 inst.instruction &= 0xffffff00;
17230 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17231 inst.instruction |= imm >> neon_logbits (size);
17234 static void
17235 do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17237 unsigned os = inst.operands[1].imm >> 5;
17238 unsigned type = inst.vectype.el[0].type;
17239 constraint (os != 0 && size == 8,
17240 _("can not shift offsets when accessing less than half-word"));
17241 constraint (os && os != neon_logbits (size),
17242 _("shift immediate must be 1, 2 or 3 for half-word, word"
17243 " or double-word accesses respectively"));
17244 if (inst.operands[1].reg == REG_PC)
17245 as_tsktsk (MVE_BAD_PC);
17247 switch (size)
17249 case 8:
17250 constraint (elsize >= 64, BAD_EL_TYPE);
17251 break;
17252 case 16:
17253 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17254 break;
17255 case 32:
17256 case 64:
17257 constraint (elsize != size, BAD_EL_TYPE);
17258 break;
17259 default:
17260 break;
17262 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17263 BAD_ADDR_MODE);
17264 if (load)
17266 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17267 _("destination register and offset register may not be"
17268 " the same"));
17269 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17270 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
17271 BAD_EL_TYPE);
17272 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
17274 else
17276 constraint (type != NT_untyped, BAD_EL_TYPE);
17279 inst.instruction |= 1 << 23;
17280 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17281 inst.instruction |= inst.operands[1].reg << 16;
17282 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17283 inst.instruction |= neon_logbits (elsize) << 7;
17284 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17285 inst.instruction |= LOW4 (inst.operands[1].imm);
17286 inst.instruction |= !!os;
17289 static void
17290 do_mve_vstr_vldr_RI (int size, int elsize, int load)
17292 enum neon_el_type type = inst.vectype.el[0].type;
17294 constraint (size >= 64, BAD_ADDR_MODE);
17295 switch (size)
17297 case 16:
17298 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17299 break;
17300 case 32:
17301 constraint (elsize != size, BAD_EL_TYPE);
17302 break;
17303 default:
17304 break;
17306 if (load)
17308 constraint (elsize != size && type != NT_unsigned
17309 && type != NT_signed, BAD_EL_TYPE);
17311 else
17313 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17316 int imm = inst.relocs[0].exp.X_add_number;
17317 int add = 1;
17318 if (imm < 0)
17320 add = 0;
17321 imm = -imm;
17324 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17326 switch (size)
17328 case 8:
17329 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17330 break;
17331 case 16:
17332 constraint (1, _("immediate must be a multiple of 2 in the"
17333 " range of +/-[0,254]"));
17334 break;
17335 case 32:
17336 constraint (1, _("immediate must be a multiple of 4 in the"
17337 " range of +/-[0,508]"));
17338 break;
17342 if (size != elsize)
17344 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17345 constraint (inst.operands[0].reg > 14,
17346 _("MVE vector register in the range [Q0..Q7] expected"));
17347 inst.instruction |= (load && type == NT_unsigned) << 28;
17348 inst.instruction |= (size == 16) << 19;
17349 inst.instruction |= neon_logbits (elsize) << 7;
17351 else
17353 if (inst.operands[1].reg == REG_PC)
17354 as_tsktsk (MVE_BAD_PC);
17355 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17356 as_tsktsk (MVE_BAD_SP);
17357 inst.instruction |= 1 << 12;
17358 inst.instruction |= neon_logbits (size) << 7;
17360 inst.instruction |= inst.operands[1].preind << 24;
17361 inst.instruction |= add << 23;
17362 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17363 inst.instruction |= inst.operands[1].writeback << 21;
17364 inst.instruction |= inst.operands[1].reg << 16;
17365 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17366 inst.instruction &= 0xffffff80;
17367 inst.instruction |= imm >> neon_logbits (size);
17371 static void
17372 do_mve_vstr_vldr (void)
17374 unsigned size;
17375 int load = 0;
17377 if (inst.cond > COND_ALWAYS)
17378 inst.pred_insn_type = INSIDE_VPT_INSN;
17379 else
17380 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17382 switch (inst.instruction)
17384 default:
17385 gas_assert (0);
17386 break;
17387 case M_MNEM_vldrb:
17388 load = 1;
17389 /* fall through. */
17390 case M_MNEM_vstrb:
17391 size = 8;
17392 break;
17393 case M_MNEM_vldrh:
17394 load = 1;
17395 /* fall through. */
17396 case M_MNEM_vstrh:
17397 size = 16;
17398 break;
17399 case M_MNEM_vldrw:
17400 load = 1;
17401 /* fall through. */
17402 case M_MNEM_vstrw:
17403 size = 32;
17404 break;
17405 case M_MNEM_vldrd:
17406 load = 1;
17407 /* fall through. */
17408 case M_MNEM_vstrd:
17409 size = 64;
17410 break;
17412 unsigned elsize = inst.vectype.el[0].size;
17414 if (inst.operands[1].isquad)
17416 /* We are dealing with [Q, imm]{!} cases. */
17417 do_mve_vstr_vldr_QI (size, elsize, load);
17419 else
17421 if (inst.operands[1].immisreg == 2)
17423 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17424 do_mve_vstr_vldr_RQ (size, elsize, load);
17426 else if (!inst.operands[1].immisreg)
17428 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17429 do_mve_vstr_vldr_RI (size, elsize, load);
17431 else
17432 constraint (1, BAD_ADDR_MODE);
17435 inst.is_neon = 1;
17438 static void
17439 do_mve_vst_vld (void)
17441 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17442 return;
17444 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17445 || inst.relocs[0].exp.X_add_number != 0
17446 || inst.operands[1].immisreg != 0,
17447 BAD_ADDR_MODE);
17448 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17449 if (inst.operands[1].reg == REG_PC)
17450 as_tsktsk (MVE_BAD_PC);
17451 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17452 as_tsktsk (MVE_BAD_SP);
17455 /* These instructions are one of the "exceptions" mentioned in
17456 handle_pred_state. They are MVE instructions that are not VPT compatible
17457 and do not accept a VPT code, thus appending such a code is a syntax
17458 error. */
17459 if (inst.cond > COND_ALWAYS)
17460 first_error (BAD_SYNTAX);
17461 /* If we append a scalar condition code we can set this to
17462 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17463 else if (inst.cond < COND_ALWAYS)
17464 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17465 else
17466 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17468 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17469 inst.instruction |= inst.operands[1].writeback << 21;
17470 inst.instruction |= inst.operands[1].reg << 16;
17471 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17472 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17473 inst.is_neon = 1;
17476 static void
17477 do_mve_vaddlv (void)
17479 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17480 struct neon_type_el et
17481 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17483 if (et.type == NT_invtype)
17484 first_error (BAD_EL_TYPE);
17486 if (inst.cond > COND_ALWAYS)
17487 inst.pred_insn_type = INSIDE_VPT_INSN;
17488 else
17489 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17491 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17493 inst.instruction |= (et.type == NT_unsigned) << 28;
17494 inst.instruction |= inst.operands[1].reg << 19;
17495 inst.instruction |= inst.operands[0].reg << 12;
17496 inst.instruction |= inst.operands[2].reg;
17497 inst.is_neon = 1;
17500 static void
17501 do_neon_dyadic_if_su (void)
17503 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17504 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17505 N_SUF_32 | N_KEY);
17507 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17508 || inst.instruction == ((unsigned) N_MNEM_vmin))
17509 && et.type == NT_float
17510 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17512 if (!check_simd_pred_availability (et.type == NT_float,
17513 NEON_CHECK_ARCH | NEON_CHECK_CC))
17514 return;
17516 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17519 static void
17520 do_neon_addsub_if_i (void)
17522 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17523 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
17524 return;
17526 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17527 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17528 N_EQK, N_IF_32 | N_I64 | N_KEY);
17530 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17531 /* If we are parsing Q registers and the element types match MVE, which NEON
17532 also supports, then we must check whether this is an instruction that can
17533 be used by both MVE/NEON. This distinction can be made based on whether
17534 they are predicated or not. */
17535 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17537 if (!check_simd_pred_availability (et.type == NT_float,
17538 NEON_CHECK_ARCH | NEON_CHECK_CC))
17539 return;
17541 else
17543 /* If they are either in a D register or are using an unsupported. */
17544 if (rs != NS_QQR
17545 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17546 return;
17549 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17550 affected if we specify unsigned args. */
17551 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
17554 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17555 result to be:
17556 V<op> A,B (A is operand 0, B is operand 2)
17557 to mean:
17558 V<op> A,B,A
17559 not:
17560 V<op> A,B,B
17561 so handle that case specially. */
17563 static void
17564 neon_exchange_operands (void)
17566 if (inst.operands[1].present)
17568 void *scratch = xmalloc (sizeof (inst.operands[0]));
17570 /* Swap operands[1] and operands[2]. */
17571 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17572 inst.operands[1] = inst.operands[2];
17573 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
17574 free (scratch);
17576 else
17578 inst.operands[1] = inst.operands[2];
17579 inst.operands[2] = inst.operands[0];
17583 static void
17584 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17586 if (inst.operands[2].isreg)
17588 if (invert)
17589 neon_exchange_operands ();
17590 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
17592 else
17594 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17595 struct neon_type_el et = neon_check_type (2, rs,
17596 N_EQK | N_SIZ, immtypes | N_KEY);
17598 NEON_ENCODE (IMMED, inst);
17599 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17600 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17601 inst.instruction |= LOW4 (inst.operands[1].reg);
17602 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17603 inst.instruction |= neon_quad (rs) << 6;
17604 inst.instruction |= (et.type == NT_float) << 10;
17605 inst.instruction |= neon_logbits (et.size) << 18;
17607 neon_dp_fixup (&inst);
17611 static void
17612 do_neon_cmp (void)
17614 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, false);
17617 static void
17618 do_neon_cmp_inv (void)
17620 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, true);
17623 static void
17624 do_neon_ceq (void)
17626 neon_compare (N_IF_32, N_IF_32, false);
17629 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
17630 scalars, which are encoded in 5 bits, M : Rm.
17631 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17632 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
17633 index in M.
17635 Dot Product instructions are similar to multiply instructions except elsize
17636 should always be 32.
17638 This function translates SCALAR, which is GAS's internal encoding of indexed
17639 scalar register, to raw encoding. There is also register and index range
17640 check based on ELSIZE. */
17642 static unsigned
17643 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17645 unsigned regno = NEON_SCALAR_REG (scalar);
17646 unsigned elno = NEON_SCALAR_INDEX (scalar);
17648 switch (elsize)
17650 case 16:
17651 if (regno > 7 || elno > 3)
17652 goto bad_scalar;
17653 return regno | (elno << 3);
17655 case 32:
17656 if (regno > 15 || elno > 1)
17657 goto bad_scalar;
17658 return regno | (elno << 4);
17660 default:
17661 bad_scalar:
17662 first_error (_("scalar out of range for multiply instruction"));
17665 return 0;
17668 /* Encode multiply / multiply-accumulate scalar instructions. */
17670 static void
17671 neon_mul_mac (struct neon_type_el et, int ubit)
17673 unsigned scalar;
17675 /* Give a more helpful error message if we have an invalid type. */
17676 if (et.type == NT_invtype)
17677 return;
17679 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
17680 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17681 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17682 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17683 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17684 inst.instruction |= LOW4 (scalar);
17685 inst.instruction |= HI1 (scalar) << 5;
17686 inst.instruction |= (et.type == NT_float) << 8;
17687 inst.instruction |= neon_logbits (et.size) << 20;
17688 inst.instruction |= (ubit != 0) << 24;
17690 neon_dp_fixup (&inst);
17693 static void
17694 do_neon_mac_maybe_scalar (void)
17696 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17697 return;
17699 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
17700 return;
17702 if (inst.operands[2].isscalar)
17704 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17705 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17706 struct neon_type_el et = neon_check_type (3, rs,
17707 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
17708 NEON_ENCODE (SCALAR, inst);
17709 neon_mul_mac (et, neon_quad (rs));
17711 else if (!inst.operands[2].isvec)
17713 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17715 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17716 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_I_MVE | N_KEY);
17718 neon_dyadic_misc (NT_untyped, N_SU_MVE | N_I_MVE, 0);
17720 else
17722 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17723 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17724 affected if we specify unsigned args. */
17725 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17729 static void
17730 do_bfloat_vfma (void)
17732 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17733 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17734 enum neon_shape rs;
17735 int t_bit = 0;
17737 if (inst.instruction != B_MNEM_vfmab)
17739 t_bit = 1;
17740 inst.instruction = B_MNEM_vfmat;
17743 if (inst.operands[2].isscalar)
17745 rs = neon_select_shape (NS_QQS, NS_NULL);
17746 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17748 inst.instruction |= (1 << 25);
17749 int idx = inst.operands[2].reg & 0xf;
17750 constraint (!(idx < 4), _("index must be in the range 0 to 3"));
17751 inst.operands[2].reg >>= 4;
17752 constraint (!(inst.operands[2].reg < 8),
17753 _("indexed register must be less than 8"));
17754 neon_three_args (t_bit);
17755 inst.instruction |= ((idx & 1) << 3);
17756 inst.instruction |= ((idx & 2) << 4);
17758 else
17760 rs = neon_select_shape (NS_QQQ, NS_NULL);
17761 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17762 neon_three_args (t_bit);
17767 static void
17768 do_neon_fmac (void)
17770 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17771 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
17772 return;
17774 if (!check_simd_pred_availability (true, NEON_CHECK_CC | NEON_CHECK_ARCH))
17775 return;
17777 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17779 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17780 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17781 N_EQK);
17783 if (rs == NS_QQR)
17786 if (inst.operands[2].reg == REG_SP)
17787 as_tsktsk (MVE_BAD_SP);
17788 else if (inst.operands[2].reg == REG_PC)
17789 as_tsktsk (MVE_BAD_PC);
17791 inst.instruction = 0xee310e40;
17792 inst.instruction |= (et.size == 16) << 28;
17793 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17794 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17795 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17796 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17797 inst.instruction |= inst.operands[2].reg;
17798 inst.is_neon = 1;
17799 return;
17802 else
17804 constraint (!inst.operands[2].isvec, BAD_FPU);
17807 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17810 static void
17811 do_mve_vfma (void)
17813 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
17814 inst.cond == COND_ALWAYS)
17816 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17817 inst.instruction = N_MNEM_vfma;
17818 inst.pred_insn_type = INSIDE_VPT_INSN;
17819 inst.cond = 0xf;
17820 return do_neon_fmac();
17822 else
17824 do_bfloat_vfma();
17828 static void
17829 do_neon_tst (void)
17831 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17832 struct neon_type_el et = neon_check_type (3, rs,
17833 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
17834 neon_three_same (neon_quad (rs), 0, et.size);
17837 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
17838 same types as the MAC equivalents. The polynomial type for this instruction
17839 is encoded the same as the integer type. */
17841 static void
17842 do_neon_mul (void)
17844 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
17845 return;
17847 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
17848 return;
17850 if (inst.operands[2].isscalar)
17852 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17853 do_neon_mac_maybe_scalar ();
17855 else
17857 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17859 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17860 struct neon_type_el et
17861 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
17862 if (et.type == NT_float)
17863 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
17864 BAD_FPU);
17866 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
17868 else
17870 constraint (!inst.operands[2].isvec, BAD_FPU);
17871 neon_dyadic_misc (NT_poly,
17872 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
17877 static void
17878 do_neon_qdmulh (void)
17880 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
17881 return;
17883 if (inst.operands[2].isscalar)
17885 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17886 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17887 struct neon_type_el et = neon_check_type (3, rs,
17888 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17889 NEON_ENCODE (SCALAR, inst);
17890 neon_mul_mac (et, neon_quad (rs));
17892 else
17894 enum neon_shape rs;
17895 struct neon_type_el et;
17896 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17898 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17899 et = neon_check_type (3, rs,
17900 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17902 else
17904 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17905 et = neon_check_type (3, rs,
17906 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17909 NEON_ENCODE (INTEGER, inst);
17910 if (rs == NS_QQR)
17911 mve_encode_qqr (et.size, 0, 0);
17912 else
17913 /* The U bit (rounding) comes from bit mask. */
17914 neon_three_same (neon_quad (rs), 0, et.size);
17918 static void
17919 do_mve_vaddv (void)
17921 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
17922 struct neon_type_el et
17923 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17925 if (et.type == NT_invtype)
17926 first_error (BAD_EL_TYPE);
17928 if (inst.cond > COND_ALWAYS)
17929 inst.pred_insn_type = INSIDE_VPT_INSN;
17930 else
17931 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17933 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17935 mve_encode_rq (et.type == NT_unsigned, et.size);
17938 static void
17939 do_mve_vhcadd (void)
17941 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
17942 struct neon_type_el et
17943 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17945 if (inst.cond > COND_ALWAYS)
17946 inst.pred_insn_type = INSIDE_VPT_INSN;
17947 else
17948 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17950 unsigned rot = inst.relocs[0].exp.X_add_number;
17951 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17953 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
17954 as_tsktsk (_("Warning: 32-bit element size and same first and third "
17955 "operand makes instruction UNPREDICTABLE"));
17957 mve_encode_qqq (0, et.size);
17958 inst.instruction |= (rot == 270) << 12;
17959 inst.is_neon = 1;
17962 static void
17963 do_mve_vqdmull (void)
17965 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17966 struct neon_type_el et
17967 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17969 if (et.size == 32
17970 && (inst.operands[0].reg == inst.operands[1].reg
17971 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
17972 as_tsktsk (BAD_MVE_SRCDEST);
17974 if (inst.cond > COND_ALWAYS)
17975 inst.pred_insn_type = INSIDE_VPT_INSN;
17976 else
17977 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17979 if (rs == NS_QQQ)
17981 mve_encode_qqq (et.size == 32, 64);
17982 inst.instruction |= 1;
17984 else
17986 mve_encode_qqr (64, et.size == 32, 0);
17987 inst.instruction |= 0x3 << 5;
17991 static void
17992 do_mve_vadc (void)
17994 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17995 struct neon_type_el et
17996 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
17998 if (et.type == NT_invtype)
17999 first_error (BAD_EL_TYPE);
18001 if (inst.cond > COND_ALWAYS)
18002 inst.pred_insn_type = INSIDE_VPT_INSN;
18003 else
18004 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18006 mve_encode_qqq (0, 64);
18009 static void
18010 do_mve_vbrsr (void)
18012 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18013 struct neon_type_el et
18014 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18016 if (inst.cond > COND_ALWAYS)
18017 inst.pred_insn_type = INSIDE_VPT_INSN;
18018 else
18019 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18021 mve_encode_qqr (et.size, 0, 0);
18024 static void
18025 do_mve_vsbc (void)
18027 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18029 if (inst.cond > COND_ALWAYS)
18030 inst.pred_insn_type = INSIDE_VPT_INSN;
18031 else
18032 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18034 mve_encode_qqq (1, 64);
18037 static void
18038 do_mve_vmulh (void)
18040 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18041 struct neon_type_el et
18042 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18044 if (inst.cond > COND_ALWAYS)
18045 inst.pred_insn_type = INSIDE_VPT_INSN;
18046 else
18047 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18049 mve_encode_qqq (et.type == NT_unsigned, et.size);
18052 static void
18053 do_mve_vqdmlah (void)
18055 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18056 struct neon_type_el et
18057 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18059 if (inst.cond > COND_ALWAYS)
18060 inst.pred_insn_type = INSIDE_VPT_INSN;
18061 else
18062 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18064 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18067 static void
18068 do_mve_vqdmladh (void)
18070 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18071 struct neon_type_el et
18072 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18074 if (inst.cond > COND_ALWAYS)
18075 inst.pred_insn_type = INSIDE_VPT_INSN;
18076 else
18077 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18079 mve_encode_qqq (0, et.size);
18083 static void
18084 do_mve_vmull (void)
18087 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18088 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18089 if (inst.cond == COND_ALWAYS
18090 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18093 if (rs == NS_QQQ)
18095 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18096 goto neon_vmul;
18098 else
18099 goto neon_vmul;
18102 constraint (rs != NS_QQQ, BAD_FPU);
18103 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18104 N_SU_32 | N_P8 | N_P16 | N_KEY);
18106 /* We are dealing with MVE's vmullt. */
18107 if (et.size == 32
18108 && (inst.operands[0].reg == inst.operands[1].reg
18109 || inst.operands[0].reg == inst.operands[2].reg))
18110 as_tsktsk (BAD_MVE_SRCDEST);
18112 if (inst.cond > COND_ALWAYS)
18113 inst.pred_insn_type = INSIDE_VPT_INSN;
18114 else
18115 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18117 if (et.type == NT_poly)
18118 mve_encode_qqq (neon_logbits (et.size), 64);
18119 else
18120 mve_encode_qqq (et.type == NT_unsigned, et.size);
18122 return;
18124 neon_vmul:
18125 inst.instruction = N_MNEM_vmul;
18126 inst.cond = 0xb;
18127 if (thumb_mode)
18128 inst.pred_insn_type = INSIDE_IT_INSN;
18129 do_neon_mul ();
18132 static void
18133 do_mve_vabav (void)
18135 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18137 if (rs == NS_NULL)
18138 return;
18140 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18141 return;
18143 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18144 | N_S16 | N_S32 | N_U8 | N_U16
18145 | N_U32);
18147 if (inst.cond > COND_ALWAYS)
18148 inst.pred_insn_type = INSIDE_VPT_INSN;
18149 else
18150 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18152 mve_encode_rqq (et.type == NT_unsigned, et.size);
18155 static void
18156 do_mve_vmladav (void)
18158 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18159 struct neon_type_el et = neon_check_type (3, rs,
18160 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18162 if (et.type == NT_unsigned
18163 && (inst.instruction == M_MNEM_vmladavx
18164 || inst.instruction == M_MNEM_vmladavax
18165 || inst.instruction == M_MNEM_vmlsdav
18166 || inst.instruction == M_MNEM_vmlsdava
18167 || inst.instruction == M_MNEM_vmlsdavx
18168 || inst.instruction == M_MNEM_vmlsdavax))
18169 first_error (BAD_SIMD_TYPE);
18171 constraint (inst.operands[2].reg > 14,
18172 _("MVE vector register in the range [Q0..Q7] expected"));
18174 if (inst.cond > COND_ALWAYS)
18175 inst.pred_insn_type = INSIDE_VPT_INSN;
18176 else
18177 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18179 if (inst.instruction == M_MNEM_vmlsdav
18180 || inst.instruction == M_MNEM_vmlsdava
18181 || inst.instruction == M_MNEM_vmlsdavx
18182 || inst.instruction == M_MNEM_vmlsdavax)
18183 inst.instruction |= (et.size == 8) << 28;
18184 else
18185 inst.instruction |= (et.size == 8) << 8;
18187 mve_encode_rqq (et.type == NT_unsigned, 64);
18188 inst.instruction |= (et.size == 32) << 16;
18191 static void
18192 do_mve_vmlaldav (void)
18194 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18195 struct neon_type_el et
18196 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18197 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18199 if (et.type == NT_unsigned
18200 && (inst.instruction == M_MNEM_vmlsldav
18201 || inst.instruction == M_MNEM_vmlsldava
18202 || inst.instruction == M_MNEM_vmlsldavx
18203 || inst.instruction == M_MNEM_vmlsldavax))
18204 first_error (BAD_SIMD_TYPE);
18206 if (inst.cond > COND_ALWAYS)
18207 inst.pred_insn_type = INSIDE_VPT_INSN;
18208 else
18209 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18211 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18214 static void
18215 do_mve_vrmlaldavh (void)
18217 struct neon_type_el et;
18218 if (inst.instruction == M_MNEM_vrmlsldavh
18219 || inst.instruction == M_MNEM_vrmlsldavha
18220 || inst.instruction == M_MNEM_vrmlsldavhx
18221 || inst.instruction == M_MNEM_vrmlsldavhax)
18223 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18224 if (inst.operands[1].reg == REG_SP)
18225 as_tsktsk (MVE_BAD_SP);
18227 else
18229 if (inst.instruction == M_MNEM_vrmlaldavhx
18230 || inst.instruction == M_MNEM_vrmlaldavhax)
18231 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18232 else
18233 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18234 N_U32 | N_S32 | N_KEY);
18235 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18236 with vmax/min instructions, making the use of SP in assembly really
18237 nonsensical, so instead of issuing a warning like we do for other uses
18238 of SP for the odd register operand we error out. */
18239 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18242 /* Make sure we still check the second operand is an odd one and that PC is
18243 disallowed. This because we are parsing for any GPR operand, to be able
18244 to distinguish between giving a warning or an error for SP as described
18245 above. */
18246 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18247 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18249 if (inst.cond > COND_ALWAYS)
18250 inst.pred_insn_type = INSIDE_VPT_INSN;
18251 else
18252 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18254 mve_encode_rrqq (et.type == NT_unsigned, 0);
18258 static void
18259 do_mve_vmaxnmv (void)
18261 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18262 struct neon_type_el et
18263 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18265 if (inst.cond > COND_ALWAYS)
18266 inst.pred_insn_type = INSIDE_VPT_INSN;
18267 else
18268 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18270 if (inst.operands[0].reg == REG_SP)
18271 as_tsktsk (MVE_BAD_SP);
18272 else if (inst.operands[0].reg == REG_PC)
18273 as_tsktsk (MVE_BAD_PC);
18275 mve_encode_rq (et.size == 16, 64);
18278 static void
18279 do_mve_vmaxv (void)
18281 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18282 struct neon_type_el et;
18284 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18285 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18286 else
18287 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18289 if (inst.cond > COND_ALWAYS)
18290 inst.pred_insn_type = INSIDE_VPT_INSN;
18291 else
18292 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18294 if (inst.operands[0].reg == REG_SP)
18295 as_tsktsk (MVE_BAD_SP);
18296 else if (inst.operands[0].reg == REG_PC)
18297 as_tsktsk (MVE_BAD_PC);
18299 mve_encode_rq (et.type == NT_unsigned, et.size);
18303 static void
18304 do_neon_qrdmlah (void)
18306 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18307 return;
18308 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18310 /* Check we're on the correct architecture. */
18311 if (!mark_feature_used (&fpu_neon_ext_armv8))
18312 inst.error
18313 = _("instruction form not available on this architecture.");
18314 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18316 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18317 record_feature_use (&fpu_neon_ext_v8_1);
18319 if (inst.operands[2].isscalar)
18321 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18322 struct neon_type_el et = neon_check_type (3, rs,
18323 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18324 NEON_ENCODE (SCALAR, inst);
18325 neon_mul_mac (et, neon_quad (rs));
18327 else
18329 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18330 struct neon_type_el et = neon_check_type (3, rs,
18331 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18332 NEON_ENCODE (INTEGER, inst);
18333 /* The U bit (rounding) comes from bit mask. */
18334 neon_three_same (neon_quad (rs), 0, et.size);
18337 else
18339 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18340 struct neon_type_el et
18341 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18343 NEON_ENCODE (INTEGER, inst);
18344 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18348 static void
18349 do_neon_fcmp_absolute (void)
18351 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18352 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18353 N_F_16_32 | N_KEY);
18354 /* Size field comes from bit mask. */
18355 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
18358 static void
18359 do_neon_fcmp_absolute_inv (void)
18361 neon_exchange_operands ();
18362 do_neon_fcmp_absolute ();
18365 static void
18366 do_neon_step (void)
18368 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18369 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18370 N_F_16_32 | N_KEY);
18371 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
18374 static void
18375 do_neon_abs_neg (void)
18377 enum neon_shape rs;
18378 struct neon_type_el et;
18380 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18381 return;
18383 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
18384 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
18386 if (!check_simd_pred_availability (et.type == NT_float,
18387 NEON_CHECK_ARCH | NEON_CHECK_CC))
18388 return;
18390 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18391 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18392 inst.instruction |= LOW4 (inst.operands[1].reg);
18393 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18394 inst.instruction |= neon_quad (rs) << 6;
18395 inst.instruction |= (et.type == NT_float) << 10;
18396 inst.instruction |= neon_logbits (et.size) << 18;
18398 neon_dp_fixup (&inst);
18401 static void
18402 do_neon_sli (void)
18404 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18405 return;
18407 enum neon_shape rs;
18408 struct neon_type_el et;
18409 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18411 rs = neon_select_shape (NS_QQI, NS_NULL);
18412 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18414 else
18416 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18417 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18421 int imm = inst.operands[2].imm;
18422 constraint (imm < 0 || (unsigned)imm >= et.size,
18423 _("immediate out of range for insert"));
18424 neon_imm_shift (false, 0, neon_quad (rs), et, imm);
18427 static void
18428 do_neon_sri (void)
18430 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18431 return;
18433 enum neon_shape rs;
18434 struct neon_type_el et;
18435 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18437 rs = neon_select_shape (NS_QQI, NS_NULL);
18438 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18440 else
18442 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18443 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18446 int imm = inst.operands[2].imm;
18447 constraint (imm < 1 || (unsigned)imm > et.size,
18448 _("immediate out of range for insert"));
18449 neon_imm_shift (false, 0, neon_quad (rs), et, et.size - imm);
18452 static void
18453 do_neon_qshlu_imm (void)
18455 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18456 return;
18458 enum neon_shape rs;
18459 struct neon_type_el et;
18460 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18462 rs = neon_select_shape (NS_QQI, NS_NULL);
18463 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18465 else
18467 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18468 et = neon_check_type (2, rs, N_EQK | N_UNS,
18469 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18472 int imm = inst.operands[2].imm;
18473 constraint (imm < 0 || (unsigned)imm >= et.size,
18474 _("immediate out of range for shift"));
18475 /* Only encodes the 'U present' variant of the instruction.
18476 In this case, signed types have OP (bit 8) set to 0.
18477 Unsigned types have OP set to 1. */
18478 inst.instruction |= (et.type == NT_unsigned) << 8;
18479 /* The rest of the bits are the same as other immediate shifts. */
18480 neon_imm_shift (false, 0, neon_quad (rs), et, imm);
18483 static void
18484 do_neon_qmovn (void)
18486 struct neon_type_el et = neon_check_type (2, NS_DQ,
18487 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18488 /* Saturating move where operands can be signed or unsigned, and the
18489 destination has the same signedness. */
18490 NEON_ENCODE (INTEGER, inst);
18491 if (et.type == NT_unsigned)
18492 inst.instruction |= 0xc0;
18493 else
18494 inst.instruction |= 0x80;
18495 neon_two_same (0, 1, et.size / 2);
18498 static void
18499 do_neon_qmovun (void)
18501 struct neon_type_el et = neon_check_type (2, NS_DQ,
18502 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18503 /* Saturating move with unsigned results. Operands must be signed. */
18504 NEON_ENCODE (INTEGER, inst);
18505 neon_two_same (0, 1, et.size / 2);
18508 static void
18509 do_neon_rshift_sat_narrow (void)
18511 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18512 or unsigned. If operands are unsigned, results must also be unsigned. */
18513 struct neon_type_el et = neon_check_type (2, NS_DQI,
18514 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18515 int imm = inst.operands[2].imm;
18516 /* This gets the bounds check, size encoding and immediate bits calculation
18517 right. */
18518 et.size /= 2;
18520 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18521 VQMOVN.I<size> <Dd>, <Qm>. */
18522 if (imm == 0)
18524 inst.operands[2].present = 0;
18525 inst.instruction = N_MNEM_vqmovn;
18526 do_neon_qmovn ();
18527 return;
18530 constraint (imm < 1 || (unsigned)imm > et.size,
18531 _("immediate out of range"));
18532 neon_imm_shift (true, et.type == NT_unsigned, 0, et, et.size - imm);
18535 static void
18536 do_neon_rshift_sat_narrow_u (void)
18538 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18539 or unsigned. If operands are unsigned, results must also be unsigned. */
18540 struct neon_type_el et = neon_check_type (2, NS_DQI,
18541 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18542 int imm = inst.operands[2].imm;
18543 /* This gets the bounds check, size encoding and immediate bits calculation
18544 right. */
18545 et.size /= 2;
18547 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18548 VQMOVUN.I<size> <Dd>, <Qm>. */
18549 if (imm == 0)
18551 inst.operands[2].present = 0;
18552 inst.instruction = N_MNEM_vqmovun;
18553 do_neon_qmovun ();
18554 return;
18557 constraint (imm < 1 || (unsigned)imm > et.size,
18558 _("immediate out of range"));
18559 /* FIXME: The manual is kind of unclear about what value U should have in
18560 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18561 must be 1. */
18562 neon_imm_shift (true, 1, 0, et, et.size - imm);
18565 static void
18566 do_neon_movn (void)
18568 struct neon_type_el et = neon_check_type (2, NS_DQ,
18569 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18570 NEON_ENCODE (INTEGER, inst);
18571 neon_two_same (0, 1, et.size / 2);
18574 static void
18575 do_neon_rshift_narrow (void)
18577 struct neon_type_el et = neon_check_type (2, NS_DQI,
18578 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18579 int imm = inst.operands[2].imm;
18580 /* This gets the bounds check, size encoding and immediate bits calculation
18581 right. */
18582 et.size /= 2;
18584 /* If immediate is zero then we are a pseudo-instruction for
18585 VMOVN.I<size> <Dd>, <Qm> */
18586 if (imm == 0)
18588 inst.operands[2].present = 0;
18589 inst.instruction = N_MNEM_vmovn;
18590 do_neon_movn ();
18591 return;
18594 constraint (imm < 1 || (unsigned)imm > et.size,
18595 _("immediate out of range for narrowing operation"));
18596 neon_imm_shift (false, 0, 0, et, et.size - imm);
18599 static void
18600 do_neon_shll (void)
18602 /* FIXME: Type checking when lengthening. */
18603 struct neon_type_el et = neon_check_type (2, NS_QDI,
18604 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18605 unsigned imm = inst.operands[2].imm;
18607 if (imm == et.size)
18609 /* Maximum shift variant. */
18610 NEON_ENCODE (INTEGER, inst);
18611 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18612 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18613 inst.instruction |= LOW4 (inst.operands[1].reg);
18614 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18615 inst.instruction |= neon_logbits (et.size) << 18;
18617 neon_dp_fixup (&inst);
18619 else
18621 /* A more-specific type check for non-max versions. */
18622 et = neon_check_type (2, NS_QDI,
18623 N_EQK | N_DBL, N_SU_32 | N_KEY);
18624 NEON_ENCODE (IMMED, inst);
18625 neon_imm_shift (true, et.type == NT_unsigned, 0, et, imm);
18629 /* Check the various types for the VCVT instruction, and return which version
18630 the current instruction is. */
18632 #define CVT_FLAVOUR_VAR \
18633 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18634 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18635 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18636 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18637 /* Half-precision conversions. */ \
18638 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18639 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18640 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18641 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
18642 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18643 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
18644 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18645 Compared with single/double precision variants, only the co-processor \
18646 field is different, so the encoding flow is reused here. */ \
18647 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18648 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18649 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18650 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
18651 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
18652 /* VFP instructions. */ \
18653 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18654 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18655 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18656 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18657 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18658 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18659 /* VFP instructions with bitshift. */ \
18660 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18661 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18662 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18663 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18664 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18665 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18666 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18667 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18669 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18670 neon_cvt_flavour_##C,
18672 /* The different types of conversions we can do. */
18673 enum neon_cvt_flavour
18675 CVT_FLAVOUR_VAR
18676 neon_cvt_flavour_invalid,
18677 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18680 #undef CVT_VAR
18682 static enum neon_cvt_flavour
18683 get_neon_cvt_flavour (enum neon_shape rs)
18685 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18686 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18687 if (et.type != NT_invtype) \
18689 inst.error = NULL; \
18690 return (neon_cvt_flavour_##C); \
18693 struct neon_type_el et;
18694 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
18695 || rs == NS_FF) ? N_VFP : 0;
18696 /* The instruction versions which take an immediate take one register
18697 argument, which is extended to the width of the full register. Thus the
18698 "source" and "destination" registers must have the same width. Hack that
18699 here by making the size equal to the key (wider, in this case) operand. */
18700 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
18702 CVT_FLAVOUR_VAR;
18704 return neon_cvt_flavour_invalid;
18705 #undef CVT_VAR
18708 enum neon_cvt_mode
18710 neon_cvt_mode_a,
18711 neon_cvt_mode_n,
18712 neon_cvt_mode_p,
18713 neon_cvt_mode_m,
18714 neon_cvt_mode_z,
18715 neon_cvt_mode_x,
18716 neon_cvt_mode_r
18719 /* Neon-syntax VFP conversions. */
18721 static void
18722 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
18724 const char *opname = 0;
18726 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18727 || rs == NS_FHI || rs == NS_HFI)
18729 /* Conversions with immediate bitshift. */
18730 const char *enc[] =
18732 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18733 CVT_FLAVOUR_VAR
18734 NULL
18735 #undef CVT_VAR
18738 if (flavour < (int) ARRAY_SIZE (enc))
18740 opname = enc[flavour];
18741 constraint (inst.operands[0].reg != inst.operands[1].reg,
18742 _("operands 0 and 1 must be the same register"));
18743 inst.operands[1] = inst.operands[2];
18744 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18747 else
18749 /* Conversions without bitshift. */
18750 const char *enc[] =
18752 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18753 CVT_FLAVOUR_VAR
18754 NULL
18755 #undef CVT_VAR
18758 if (flavour < (int) ARRAY_SIZE (enc))
18759 opname = enc[flavour];
18762 if (opname)
18763 do_vfp_nsyn_opcode (opname);
18765 /* ARMv8.2 fp16 VCVT instruction. */
18766 if (flavour == neon_cvt_flavour_s32_f16
18767 || flavour == neon_cvt_flavour_u32_f16
18768 || flavour == neon_cvt_flavour_f16_u32
18769 || flavour == neon_cvt_flavour_f16_s32)
18770 do_scalar_fp16_v82_encode ();
18773 static void
18774 do_vfp_nsyn_cvtz (void)
18776 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
18777 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18778 const char *enc[] =
18780 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18781 CVT_FLAVOUR_VAR
18782 NULL
18783 #undef CVT_VAR
18786 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
18787 do_vfp_nsyn_opcode (enc[flavour]);
18790 static void
18791 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
18792 enum neon_cvt_mode mode)
18794 int sz, op;
18795 int rm;
18797 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18798 D register operands. */
18799 if (flavour == neon_cvt_flavour_s32_f64
18800 || flavour == neon_cvt_flavour_u32_f64)
18801 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18802 _(BAD_FPU));
18804 if (flavour == neon_cvt_flavour_s32_f16
18805 || flavour == neon_cvt_flavour_u32_f16)
18806 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18807 _(BAD_FP16));
18809 set_pred_insn_type (OUTSIDE_PRED_INSN);
18811 switch (flavour)
18813 case neon_cvt_flavour_s32_f64:
18814 sz = 1;
18815 op = 1;
18816 break;
18817 case neon_cvt_flavour_s32_f32:
18818 sz = 0;
18819 op = 1;
18820 break;
18821 case neon_cvt_flavour_s32_f16:
18822 sz = 0;
18823 op = 1;
18824 break;
18825 case neon_cvt_flavour_u32_f64:
18826 sz = 1;
18827 op = 0;
18828 break;
18829 case neon_cvt_flavour_u32_f32:
18830 sz = 0;
18831 op = 0;
18832 break;
18833 case neon_cvt_flavour_u32_f16:
18834 sz = 0;
18835 op = 0;
18836 break;
18837 default:
18838 first_error (_("invalid instruction shape"));
18839 return;
18842 switch (mode)
18844 case neon_cvt_mode_a: rm = 0; break;
18845 case neon_cvt_mode_n: rm = 1; break;
18846 case neon_cvt_mode_p: rm = 2; break;
18847 case neon_cvt_mode_m: rm = 3; break;
18848 default: first_error (_("invalid rounding mode")); return;
18851 NEON_ENCODE (FPV8, inst);
18852 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
18853 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
18854 inst.instruction |= sz << 8;
18856 /* ARMv8.2 fp16 VCVT instruction. */
18857 if (flavour == neon_cvt_flavour_s32_f16
18858 ||flavour == neon_cvt_flavour_u32_f16)
18859 do_scalar_fp16_v82_encode ();
18860 inst.instruction |= op << 7;
18861 inst.instruction |= rm << 16;
18862 inst.instruction |= 0xf0000000;
18863 inst.is_neon = true;
18866 static void
18867 do_neon_cvt_1 (enum neon_cvt_mode mode)
18869 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
18870 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
18871 NS_FH, NS_HF, NS_FHI, NS_HFI,
18872 NS_NULL);
18873 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18875 if (flavour == neon_cvt_flavour_invalid)
18876 return;
18878 /* PR11109: Handle round-to-zero for VCVT conversions. */
18879 if (mode == neon_cvt_mode_z
18880 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
18881 && (flavour == neon_cvt_flavour_s16_f16
18882 || flavour == neon_cvt_flavour_u16_f16
18883 || flavour == neon_cvt_flavour_s32_f32
18884 || flavour == neon_cvt_flavour_u32_f32
18885 || flavour == neon_cvt_flavour_s32_f64
18886 || flavour == neon_cvt_flavour_u32_f64)
18887 && (rs == NS_FD || rs == NS_FF))
18889 do_vfp_nsyn_cvtz ();
18890 return;
18893 /* ARMv8.2 fp16 VCVT conversions. */
18894 if (mode == neon_cvt_mode_z
18895 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
18896 && (flavour == neon_cvt_flavour_s32_f16
18897 || flavour == neon_cvt_flavour_u32_f16)
18898 && (rs == NS_FH))
18900 do_vfp_nsyn_cvtz ();
18901 do_scalar_fp16_v82_encode ();
18902 return;
18905 /* VFP rather than Neon conversions. */
18906 if (flavour >= neon_cvt_flavour_first_fp)
18908 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
18909 do_vfp_nsyn_cvt (rs, flavour);
18910 else
18911 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
18913 return;
18916 switch (rs)
18918 case NS_QQI:
18919 if (mode == neon_cvt_mode_z
18920 && (flavour == neon_cvt_flavour_f16_s16
18921 || flavour == neon_cvt_flavour_f16_u16
18922 || flavour == neon_cvt_flavour_s16_f16
18923 || flavour == neon_cvt_flavour_u16_f16
18924 || flavour == neon_cvt_flavour_f32_u32
18925 || flavour == neon_cvt_flavour_f32_s32
18926 || flavour == neon_cvt_flavour_s32_f32
18927 || flavour == neon_cvt_flavour_u32_f32))
18929 if (!check_simd_pred_availability (true,
18930 NEON_CHECK_CC | NEON_CHECK_ARCH))
18931 return;
18933 /* fall through. */
18934 case NS_DDI:
18936 unsigned immbits;
18937 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
18938 0x0000100, 0x1000100, 0x0, 0x1000000};
18940 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18941 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18942 return;
18944 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18946 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
18947 _("immediate value out of range"));
18948 switch (flavour)
18950 case neon_cvt_flavour_f16_s16:
18951 case neon_cvt_flavour_f16_u16:
18952 case neon_cvt_flavour_s16_f16:
18953 case neon_cvt_flavour_u16_f16:
18954 constraint (inst.operands[2].imm > 16,
18955 _("immediate value out of range"));
18956 break;
18957 case neon_cvt_flavour_f32_u32:
18958 case neon_cvt_flavour_f32_s32:
18959 case neon_cvt_flavour_s32_f32:
18960 case neon_cvt_flavour_u32_f32:
18961 constraint (inst.operands[2].imm > 32,
18962 _("immediate value out of range"));
18963 break;
18964 default:
18965 inst.error = BAD_FPU;
18966 return;
18970 /* Fixed-point conversion with #0 immediate is encoded as an
18971 integer conversion. */
18972 if (inst.operands[2].present && inst.operands[2].imm == 0)
18973 goto int_encode;
18974 NEON_ENCODE (IMMED, inst);
18975 if (flavour != neon_cvt_flavour_invalid)
18976 inst.instruction |= enctab[flavour];
18977 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18978 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18979 inst.instruction |= LOW4 (inst.operands[1].reg);
18980 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18981 inst.instruction |= neon_quad (rs) << 6;
18982 inst.instruction |= 1 << 21;
18983 if (flavour < neon_cvt_flavour_s16_f16)
18985 inst.instruction |= 1 << 21;
18986 immbits = 32 - inst.operands[2].imm;
18987 inst.instruction |= immbits << 16;
18989 else
18991 inst.instruction |= 3 << 20;
18992 immbits = 16 - inst.operands[2].imm;
18993 inst.instruction |= immbits << 16;
18994 inst.instruction &= ~(1 << 9);
18997 neon_dp_fixup (&inst);
18999 break;
19001 case NS_QQ:
19002 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19003 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19004 && (flavour == neon_cvt_flavour_s16_f16
19005 || flavour == neon_cvt_flavour_u16_f16
19006 || flavour == neon_cvt_flavour_s32_f32
19007 || flavour == neon_cvt_flavour_u32_f32))
19009 if (!check_simd_pred_availability (true,
19010 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19011 return;
19013 else if (mode == neon_cvt_mode_z
19014 && (flavour == neon_cvt_flavour_f16_s16
19015 || flavour == neon_cvt_flavour_f16_u16
19016 || flavour == neon_cvt_flavour_s16_f16
19017 || flavour == neon_cvt_flavour_u16_f16
19018 || flavour == neon_cvt_flavour_f32_u32
19019 || flavour == neon_cvt_flavour_f32_s32
19020 || flavour == neon_cvt_flavour_s32_f32
19021 || flavour == neon_cvt_flavour_u32_f32))
19023 if (!check_simd_pred_availability (true,
19024 NEON_CHECK_CC | NEON_CHECK_ARCH))
19025 return;
19027 /* fall through. */
19028 case NS_DD:
19029 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19032 NEON_ENCODE (FLOAT, inst);
19033 if (!check_simd_pred_availability (true,
19034 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19035 return;
19037 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19038 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19039 inst.instruction |= LOW4 (inst.operands[1].reg);
19040 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19041 inst.instruction |= neon_quad (rs) << 6;
19042 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19043 || flavour == neon_cvt_flavour_u32_f32) << 7;
19044 inst.instruction |= mode << 8;
19045 if (flavour == neon_cvt_flavour_u16_f16
19046 || flavour == neon_cvt_flavour_s16_f16)
19047 /* Mask off the original size bits and reencode them. */
19048 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19050 if (thumb_mode)
19051 inst.instruction |= 0xfc000000;
19052 else
19053 inst.instruction |= 0xf0000000;
19055 else
19057 int_encode:
19059 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19060 0x100, 0x180, 0x0, 0x080};
19062 NEON_ENCODE (INTEGER, inst);
19064 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19066 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19067 return;
19070 if (flavour != neon_cvt_flavour_invalid)
19071 inst.instruction |= enctab[flavour];
19073 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19074 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19075 inst.instruction |= LOW4 (inst.operands[1].reg);
19076 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19077 inst.instruction |= neon_quad (rs) << 6;
19078 if (flavour >= neon_cvt_flavour_s16_f16
19079 && flavour <= neon_cvt_flavour_f16_u16)
19080 /* Half precision. */
19081 inst.instruction |= 1 << 18;
19082 else
19083 inst.instruction |= 2 << 18;
19085 neon_dp_fixup (&inst);
19088 break;
19090 /* Half-precision conversions for Advanced SIMD -- neon. */
19091 case NS_QD:
19092 case NS_DQ:
19093 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19094 return;
19096 if ((rs == NS_DQ)
19097 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19099 as_bad (_("operand size must match register width"));
19100 break;
19103 if ((rs == NS_QD)
19104 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19106 as_bad (_("operand size must match register width"));
19107 break;
19110 if (rs == NS_DQ)
19112 if (flavour == neon_cvt_flavour_bf16_f32)
19114 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19115 return;
19116 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19117 /* VCVT.bf16.f32. */
19118 inst.instruction = 0x11b60640;
19120 else
19121 /* VCVT.f16.f32. */
19122 inst.instruction = 0x3b60600;
19124 else
19125 /* VCVT.f32.f16. */
19126 inst.instruction = 0x3b60700;
19128 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19129 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19130 inst.instruction |= LOW4 (inst.operands[1].reg);
19131 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19132 neon_dp_fixup (&inst);
19133 break;
19135 default:
19136 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
19137 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19138 do_vfp_nsyn_cvt (rs, flavour);
19139 else
19140 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19144 static void
19145 do_neon_cvtr (void)
19147 do_neon_cvt_1 (neon_cvt_mode_x);
19150 static void
19151 do_neon_cvt (void)
19153 do_neon_cvt_1 (neon_cvt_mode_z);
19156 static void
19157 do_neon_cvta (void)
19159 do_neon_cvt_1 (neon_cvt_mode_a);
19162 static void
19163 do_neon_cvtn (void)
19165 do_neon_cvt_1 (neon_cvt_mode_n);
19168 static void
19169 do_neon_cvtp (void)
19171 do_neon_cvt_1 (neon_cvt_mode_p);
19174 static void
19175 do_neon_cvtm (void)
19177 do_neon_cvt_1 (neon_cvt_mode_m);
19180 static void
19181 do_neon_cvttb_2 (bool t, bool to, bool is_double)
19183 if (is_double)
19184 mark_feature_used (&fpu_vfp_ext_armv8);
19186 encode_arm_vfp_reg (inst.operands[0].reg,
19187 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19188 encode_arm_vfp_reg (inst.operands[1].reg,
19189 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19190 inst.instruction |= to ? 0x10000 : 0;
19191 inst.instruction |= t ? 0x80 : 0;
19192 inst.instruction |= is_double ? 0x100 : 0;
19193 do_vfp_cond_or_thumb ();
19196 static void
19197 do_neon_cvttb_1 (bool t)
19199 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
19200 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
19202 if (rs == NS_NULL)
19203 return;
19204 else if (rs == NS_QQ || rs == NS_QQI)
19206 int single_to_half = 0;
19207 if (!check_simd_pred_availability (true, NEON_CHECK_ARCH))
19208 return;
19210 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19212 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19213 && (flavour == neon_cvt_flavour_u16_f16
19214 || flavour == neon_cvt_flavour_s16_f16
19215 || flavour == neon_cvt_flavour_f16_s16
19216 || flavour == neon_cvt_flavour_f16_u16
19217 || flavour == neon_cvt_flavour_u32_f32
19218 || flavour == neon_cvt_flavour_s32_f32
19219 || flavour == neon_cvt_flavour_f32_s32
19220 || flavour == neon_cvt_flavour_f32_u32))
19222 inst.cond = 0xf;
19223 inst.instruction = N_MNEM_vcvt;
19224 set_pred_insn_type (INSIDE_VPT_INSN);
19225 do_neon_cvt_1 (neon_cvt_mode_z);
19226 return;
19228 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19229 single_to_half = 1;
19230 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19232 first_error (BAD_FPU);
19233 return;
19236 unsigned op0 = inst.operands[0].reg;
19237 unsigned op1 = inst.operands[1].reg;
19238 /* NS_QQ so both registers are quads but inst.operands has their
19239 D-register values, so halve before encoding. */
19240 if (rs == NS_QQ)
19242 op0 >>= 1;
19243 op1 >>= 1;
19245 inst.instruction = 0xee3f0e01;
19246 inst.instruction |= single_to_half << 28;
19247 inst.instruction |= HI1 (op0) << 22;
19248 inst.instruction |= LOW4 (op0) << 13;
19249 inst.instruction |= t << 12;
19250 inst.instruction |= HI1 (op1) << 5;
19251 inst.instruction |= LOW4 (op1) << 1;
19252 inst.is_neon = 1;
19254 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19256 inst.error = NULL;
19257 do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/false);
19259 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19261 inst.error = NULL;
19262 do_neon_cvttb_2 (t, /*to=*/false, /*is_double=*/false);
19264 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19266 /* The VCVTB and VCVTT instructions with D-register operands
19267 don't work for SP only targets. */
19268 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19269 _(BAD_FPU));
19271 inst.error = NULL;
19272 do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/true);
19274 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19276 /* The VCVTB and VCVTT instructions with D-register operands
19277 don't work for SP only targets. */
19278 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19279 _(BAD_FPU));
19281 inst.error = NULL;
19282 do_neon_cvttb_2 (t, /*to=*/false, /*is_double=*/true);
19284 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19286 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19287 inst.error = NULL;
19288 inst.instruction |= (1 << 8);
19289 inst.instruction &= ~(1 << 9);
19290 do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/false);
19292 else
19293 return;
19296 static void
19297 do_neon_cvtb (void)
19299 do_neon_cvttb_1 (false);
19303 static void
19304 do_neon_cvtt (void)
19306 do_neon_cvttb_1 (true);
19309 static void
19310 neon_move_immediate (void)
19312 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19313 struct neon_type_el et = neon_check_type (2, rs,
19314 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
19315 unsigned immlo, immhi = 0, immbits;
19316 int op, cmode, float_p;
19318 constraint (et.type == NT_invtype,
19319 _("operand size must be specified for immediate VMOV"));
19321 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19322 op = (inst.instruction & (1 << 5)) != 0;
19324 immlo = inst.operands[1].imm;
19325 if (inst.operands[1].regisimm)
19326 immhi = inst.operands[1].reg;
19328 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
19329 _("immediate has bits set outside the operand size"));
19331 float_p = inst.operands[1].immisfloat;
19333 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
19334 et.size, et.type)) == FAIL)
19336 /* Invert relevant bits only. */
19337 neon_invert_size (&immlo, &immhi, et.size);
19338 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
19339 with one or the other; those cases are caught by
19340 neon_cmode_for_move_imm. */
19341 op = !op;
19342 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19343 &op, et.size, et.type)) == FAIL)
19345 first_error (_("immediate out of range"));
19346 return;
19350 inst.instruction &= ~(1 << 5);
19351 inst.instruction |= op << 5;
19353 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19354 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19355 inst.instruction |= neon_quad (rs) << 6;
19356 inst.instruction |= cmode << 8;
19358 neon_write_immbits (immbits);
19361 static void
19362 do_neon_mvn (void)
19364 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
19365 return;
19367 if (inst.operands[1].isreg)
19369 enum neon_shape rs;
19370 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19371 rs = neon_select_shape (NS_QQ, NS_NULL);
19372 else
19373 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19375 if (rs == NS_NULL)
19376 return;
19378 NEON_ENCODE (INTEGER, inst);
19379 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19380 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19381 inst.instruction |= LOW4 (inst.operands[1].reg);
19382 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19383 inst.instruction |= neon_quad (rs) << 6;
19385 else
19387 NEON_ENCODE (IMMED, inst);
19388 neon_move_immediate ();
19391 neon_dp_fixup (&inst);
19393 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19395 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19399 /* Encode instructions of form:
19401 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
19402 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
19404 static void
19405 neon_mixed_length (struct neon_type_el et, unsigned size)
19407 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19408 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19409 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19410 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19411 inst.instruction |= LOW4 (inst.operands[2].reg);
19412 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19413 inst.instruction |= (et.type == NT_unsigned) << 24;
19414 inst.instruction |= neon_logbits (size) << 20;
19416 neon_dp_fixup (&inst);
19419 static void
19420 do_neon_dyadic_long (void)
19422 enum neon_shape rs = neon_select_shape (NS_QDD, NS_HHH, NS_FFF, NS_DDD, NS_NULL);
19423 if (rs == NS_QDD)
19425 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19426 return;
19428 NEON_ENCODE (INTEGER, inst);
19429 /* FIXME: Type checking for lengthening op. */
19430 struct neon_type_el et = neon_check_type (3, NS_QDD,
19431 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19432 neon_mixed_length (et, et.size);
19434 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19435 && (inst.cond == 0xf || inst.cond == 0x10))
19437 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19438 in an IT block with le/lt conditions. */
19440 if (inst.cond == 0xf)
19441 inst.cond = 0xb;
19442 else if (inst.cond == 0x10)
19443 inst.cond = 0xd;
19445 inst.pred_insn_type = INSIDE_IT_INSN;
19447 if (inst.instruction == N_MNEM_vaddl)
19449 inst.instruction = N_MNEM_vadd;
19450 do_neon_addsub_if_i ();
19452 else if (inst.instruction == N_MNEM_vsubl)
19454 inst.instruction = N_MNEM_vsub;
19455 do_neon_addsub_if_i ();
19457 else if (inst.instruction == N_MNEM_vabdl)
19459 inst.instruction = N_MNEM_vabd;
19460 do_neon_dyadic_if_su ();
19463 else
19464 first_error (BAD_FPU);
19467 static void
19468 do_neon_abal (void)
19470 struct neon_type_el et = neon_check_type (3, NS_QDD,
19471 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19472 neon_mixed_length (et, et.size);
19475 static void
19476 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19478 if (inst.operands[2].isscalar)
19480 struct neon_type_el et = neon_check_type (3, NS_QDS,
19481 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
19482 NEON_ENCODE (SCALAR, inst);
19483 neon_mul_mac (et, et.type == NT_unsigned);
19485 else
19487 struct neon_type_el et = neon_check_type (3, NS_QDD,
19488 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
19489 NEON_ENCODE (INTEGER, inst);
19490 neon_mixed_length (et, et.size);
19494 static void
19495 do_neon_mac_maybe_scalar_long (void)
19497 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19500 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19501 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19503 static unsigned
19504 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19506 unsigned regno = NEON_SCALAR_REG (scalar);
19507 unsigned elno = NEON_SCALAR_INDEX (scalar);
19509 if (quad_p)
19511 if (regno > 7 || elno > 3)
19512 goto bad_scalar;
19514 return ((regno & 0x7)
19515 | ((elno & 0x1) << 3)
19516 | (((elno >> 1) & 0x1) << 5));
19518 else
19520 if (regno > 15 || elno > 1)
19521 goto bad_scalar;
19523 return (((regno & 0x1) << 5)
19524 | ((regno >> 1) & 0x7)
19525 | ((elno & 0x1) << 3));
19528 bad_scalar:
19529 first_error (_("scalar out of range for multiply instruction"));
19530 return 0;
19533 static void
19534 do_neon_fmac_maybe_scalar_long (int subtype)
19536 enum neon_shape rs;
19537 int high8;
19538 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19539 field (bits[21:20]) has different meaning. For scalar index variant, it's
19540 used to differentiate add and subtract, otherwise it's with fixed value
19541 0x2. */
19542 int size = -1;
19544 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19545 be a scalar index register. */
19546 if (inst.operands[2].isscalar)
19548 high8 = 0xfe000000;
19549 if (subtype)
19550 size = 16;
19551 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19553 else
19555 high8 = 0xfc000000;
19556 size = 32;
19557 if (subtype)
19558 inst.instruction |= (0x1 << 23);
19559 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19563 if (inst.cond != COND_ALWAYS)
19564 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19565 "behaviour is UNPREDICTABLE"));
19567 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19568 _(BAD_FP16));
19570 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19571 _(BAD_FPU));
19573 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19574 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19575 so we simply pass -1 as size. */
19576 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19577 neon_three_same (quad_p, 0, size);
19579 /* Undo neon_dp_fixup. Redo the high eight bits. */
19580 inst.instruction &= 0x00ffffff;
19581 inst.instruction |= high8;
19583 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19584 whether the instruction is in Q form and whether Vm is a scalar indexed
19585 operand. */
19586 if (inst.operands[2].isscalar)
19588 unsigned rm
19589 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19590 inst.instruction &= 0xffffffd0;
19591 inst.instruction |= rm;
19593 if (!quad_p)
19595 /* Redo Rn as well. */
19596 inst.instruction &= 0xfff0ff7f;
19597 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19598 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19601 else if (!quad_p)
19603 /* Redo Rn and Rm. */
19604 inst.instruction &= 0xfff0ff50;
19605 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19606 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19607 inst.instruction |= HI4 (inst.operands[2].reg);
19608 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19612 static void
19613 do_neon_vfmal (void)
19615 return do_neon_fmac_maybe_scalar_long (0);
19618 static void
19619 do_neon_vfmsl (void)
19621 return do_neon_fmac_maybe_scalar_long (1);
19624 static void
19625 do_neon_dyadic_wide (void)
19627 struct neon_type_el et = neon_check_type (3, NS_QQD,
19628 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19629 neon_mixed_length (et, et.size);
19632 static void
19633 do_neon_dyadic_narrow (void)
19635 struct neon_type_el et = neon_check_type (3, NS_QDD,
19636 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
19637 /* Operand sign is unimportant, and the U bit is part of the opcode,
19638 so force the operand type to integer. */
19639 et.type = NT_integer;
19640 neon_mixed_length (et, et.size / 2);
19643 static void
19644 do_neon_mul_sat_scalar_long (void)
19646 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19649 static void
19650 do_neon_vmull (void)
19652 if (inst.operands[2].isscalar)
19653 do_neon_mac_maybe_scalar_long ();
19654 else
19656 struct neon_type_el et = neon_check_type (3, NS_QDD,
19657 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
19659 if (et.type == NT_poly)
19660 NEON_ENCODE (POLY, inst);
19661 else
19662 NEON_ENCODE (INTEGER, inst);
19664 /* For polynomial encoding the U bit must be zero, and the size must
19665 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19666 obviously, as 0b10). */
19667 if (et.size == 64)
19669 /* Check we're on the correct architecture. */
19670 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19671 inst.error =
19672 _("Instruction form not available on this architecture.");
19674 et.size = 32;
19677 neon_mixed_length (et, et.size);
19681 static void
19682 do_neon_ext (void)
19684 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
19685 struct neon_type_el et = neon_check_type (3, rs,
19686 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19687 unsigned imm = (inst.operands[3].imm * et.size) / 8;
19689 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19690 _("shift out of range"));
19691 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19692 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19693 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19694 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19695 inst.instruction |= LOW4 (inst.operands[2].reg);
19696 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19697 inst.instruction |= neon_quad (rs) << 6;
19698 inst.instruction |= imm << 8;
19700 neon_dp_fixup (&inst);
19703 static void
19704 do_neon_rev (void)
19706 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
19707 return;
19709 enum neon_shape rs;
19710 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19711 rs = neon_select_shape (NS_QQ, NS_NULL);
19712 else
19713 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19715 struct neon_type_el et = neon_check_type (2, rs,
19716 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19718 unsigned op = (inst.instruction >> 7) & 3;
19719 /* N (width of reversed regions) is encoded as part of the bitmask. We
19720 extract it here to check the elements to be reversed are smaller.
19721 Otherwise we'd get a reserved instruction. */
19722 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
19724 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19725 && inst.operands[0].reg == inst.operands[1].reg)
19726 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19727 " operands makes instruction UNPREDICTABLE"));
19729 gas_assert (elsize != 0);
19730 constraint (et.size >= elsize,
19731 _("elements must be smaller than reversal region"));
19732 neon_two_same (neon_quad (rs), 1, et.size);
19735 static void
19736 do_neon_dup (void)
19738 if (inst.operands[1].isscalar)
19740 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19741 BAD_FPU);
19742 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
19743 struct neon_type_el et = neon_check_type (2, rs,
19744 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19745 unsigned sizebits = et.size >> 3;
19746 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
19747 int logsize = neon_logbits (et.size);
19748 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
19750 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
19751 return;
19753 NEON_ENCODE (SCALAR, inst);
19754 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19756 inst.instruction |= LOW4 (dm);
19757 inst.instruction |= HI1 (dm) << 5;
19758 inst.instruction |= neon_quad (rs) << 6;
19759 inst.instruction |= x << 17;
19760 inst.instruction |= sizebits << 16;
19762 neon_dp_fixup (&inst);
19764 else
19766 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19767 struct neon_type_el et = neon_check_type (2, rs,
19768 N_8 | N_16 | N_32 | N_KEY, N_EQK);
19769 if (rs == NS_QR)
19771 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH))
19772 return;
19774 else
19775 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19776 BAD_FPU);
19778 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19780 if (inst.operands[1].reg == REG_SP)
19781 as_tsktsk (MVE_BAD_SP);
19782 else if (inst.operands[1].reg == REG_PC)
19783 as_tsktsk (MVE_BAD_PC);
19786 /* Duplicate ARM register to lanes of vector. */
19787 NEON_ENCODE (ARMREG, inst);
19788 switch (et.size)
19790 case 8: inst.instruction |= 0x400000; break;
19791 case 16: inst.instruction |= 0x000020; break;
19792 case 32: inst.instruction |= 0x000000; break;
19793 default: break;
19795 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19796 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19797 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
19798 inst.instruction |= neon_quad (rs) << 21;
19799 /* The encoding for this instruction is identical for the ARM and Thumb
19800 variants, except for the condition field. */
19801 do_vfp_cond_or_thumb ();
19805 static void
19806 do_mve_mov (int toQ)
19808 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19809 return;
19810 if (inst.cond > COND_ALWAYS)
19811 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19813 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19814 if (toQ)
19816 Q0 = 0;
19817 Q1 = 1;
19818 Rt = 2;
19819 Rt2 = 3;
19822 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
19823 _("Index one must be [2,3] and index two must be two less than"
19824 " index one."));
19825 constraint (!toQ && inst.operands[Rt].reg == inst.operands[Rt2].reg,
19826 _("Destination registers may not be the same"));
19827 constraint (inst.operands[Rt].reg == REG_SP
19828 || inst.operands[Rt2].reg == REG_SP,
19829 BAD_SP);
19830 constraint (inst.operands[Rt].reg == REG_PC
19831 || inst.operands[Rt2].reg == REG_PC,
19832 BAD_PC);
19834 inst.instruction = 0xec000f00;
19835 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
19836 inst.instruction |= !!toQ << 20;
19837 inst.instruction |= inst.operands[Rt2].reg << 16;
19838 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
19839 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
19840 inst.instruction |= inst.operands[Rt].reg;
19843 static void
19844 do_mve_movn (void)
19846 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19847 return;
19849 if (inst.cond > COND_ALWAYS)
19850 inst.pred_insn_type = INSIDE_VPT_INSN;
19851 else
19852 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
19854 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
19855 | N_KEY);
19857 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19858 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
19859 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19860 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19861 inst.instruction |= LOW4 (inst.operands[1].reg);
19862 inst.is_neon = 1;
19866 /* VMOV has particularly many variations. It can be one of:
19867 0. VMOV<c><q> <Qd>, <Qm>
19868 1. VMOV<c><q> <Dd>, <Dm>
19869 (Register operations, which are VORR with Rm = Rn.)
19870 2. VMOV<c><q>.<dt> <Qd>, #<imm>
19871 3. VMOV<c><q>.<dt> <Dd>, #<imm>
19872 (Immediate loads.)
19873 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
19874 (ARM register to scalar.)
19875 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
19876 (Two ARM registers to vector.)
19877 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
19878 (Scalar to ARM register.)
19879 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
19880 (Vector to two ARM registers.)
19881 8. VMOV.F32 <Sd>, <Sm>
19882 9. VMOV.F64 <Dd>, <Dm>
19883 (VFP register moves.)
19884 10. VMOV.F32 <Sd>, #imm
19885 11. VMOV.F64 <Dd>, #imm
19886 (VFP float immediate load.)
19887 12. VMOV <Rd>, <Sm>
19888 (VFP single to ARM reg.)
19889 13. VMOV <Sd>, <Rm>
19890 (ARM reg to VFP single.)
19891 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
19892 (Two ARM regs to two VFP singles.)
19893 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
19894 (Two VFP singles to two ARM regs.)
19895 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
19896 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
19897 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
19898 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
19900 These cases can be disambiguated using neon_select_shape, except cases 1/9
19901 and 3/11 which depend on the operand type too.
19903 All the encoded bits are hardcoded by this function.
19905 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
19906 Cases 5, 7 may be used with VFPv2 and above.
19908 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
19909 can specify a type where it doesn't make sense to, and is ignored). */
19911 static void
19912 do_neon_mov (void)
19914 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
19915 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
19916 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
19917 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
19918 NS_NULL);
19919 struct neon_type_el et;
19920 const char *ldconst = 0;
19922 switch (rs)
19924 case NS_DD: /* case 1/9. */
19925 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19926 /* It is not an error here if no type is given. */
19927 inst.error = NULL;
19929 /* In MVE we interpret the following instructions as same, so ignoring
19930 the following type (float) and size (64) checks.
19931 a: VMOV<c><q> <Dd>, <Dm>
19932 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
19933 if ((et.type == NT_float && et.size == 64)
19934 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
19936 do_vfp_nsyn_opcode ("fcpyd");
19937 break;
19939 /* fall through. */
19941 case NS_QQ: /* case 0/1. */
19943 if (!check_simd_pred_availability (false,
19944 NEON_CHECK_CC | NEON_CHECK_ARCH))
19945 return;
19946 /* The architecture manual I have doesn't explicitly state which
19947 value the U bit should have for register->register moves, but
19948 the equivalent VORR instruction has U = 0, so do that. */
19949 inst.instruction = 0x0200110;
19950 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19951 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19952 inst.instruction |= LOW4 (inst.operands[1].reg);
19953 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19954 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19955 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19956 inst.instruction |= neon_quad (rs) << 6;
19958 neon_dp_fixup (&inst);
19960 break;
19962 case NS_DI: /* case 3/11. */
19963 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19964 inst.error = NULL;
19965 if (et.type == NT_float && et.size == 64)
19967 /* case 11 (fconstd). */
19968 ldconst = "fconstd";
19969 goto encode_fconstd;
19971 /* fall through. */
19973 case NS_QI: /* case 2/3. */
19974 if (!check_simd_pred_availability (false,
19975 NEON_CHECK_CC | NEON_CHECK_ARCH))
19976 return;
19977 inst.instruction = 0x0800010;
19978 neon_move_immediate ();
19979 neon_dp_fixup (&inst);
19980 break;
19982 case NS_SR: /* case 4. */
19984 unsigned bcdebits = 0;
19985 int logsize;
19986 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
19987 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
19989 /* .<size> is optional here, defaulting to .32. */
19990 if (inst.vectype.elems == 0
19991 && inst.operands[0].vectype.type == NT_invtype
19992 && inst.operands[1].vectype.type == NT_invtype)
19994 inst.vectype.el[0].type = NT_untyped;
19995 inst.vectype.el[0].size = 32;
19996 inst.vectype.elems = 1;
19999 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20000 logsize = neon_logbits (et.size);
20002 if (et.size != 32)
20004 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20005 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20006 return;
20008 else
20010 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20011 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20012 _(BAD_FPU));
20015 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20017 if (inst.operands[1].reg == REG_SP)
20018 as_tsktsk (MVE_BAD_SP);
20019 else if (inst.operands[1].reg == REG_PC)
20020 as_tsktsk (MVE_BAD_PC);
20022 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20024 constraint (et.type == NT_invtype, _("bad type for scalar"));
20025 constraint (x >= size / et.size, _("scalar index out of range"));
20028 switch (et.size)
20030 case 8: bcdebits = 0x8; break;
20031 case 16: bcdebits = 0x1; break;
20032 case 32: bcdebits = 0x0; break;
20033 default: ;
20036 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20038 inst.instruction = 0xe000b10;
20039 do_vfp_cond_or_thumb ();
20040 inst.instruction |= LOW4 (dn) << 16;
20041 inst.instruction |= HI1 (dn) << 7;
20042 inst.instruction |= inst.operands[1].reg << 12;
20043 inst.instruction |= (bcdebits & 3) << 5;
20044 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20045 inst.instruction |= (x >> (3-logsize)) << 16;
20047 break;
20049 case NS_DRR: /* case 5 (fmdrr). */
20050 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20051 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20052 _(BAD_FPU));
20054 inst.instruction = 0xc400b10;
20055 do_vfp_cond_or_thumb ();
20056 inst.instruction |= LOW4 (inst.operands[0].reg);
20057 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20058 inst.instruction |= inst.operands[1].reg << 12;
20059 inst.instruction |= inst.operands[2].reg << 16;
20060 break;
20062 case NS_RS: /* case 6. */
20064 unsigned logsize;
20065 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20066 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20067 unsigned abcdebits = 0;
20069 /* .<dt> is optional here, defaulting to .32. */
20070 if (inst.vectype.elems == 0
20071 && inst.operands[0].vectype.type == NT_invtype
20072 && inst.operands[1].vectype.type == NT_invtype)
20074 inst.vectype.el[0].type = NT_untyped;
20075 inst.vectype.el[0].size = 32;
20076 inst.vectype.elems = 1;
20079 et = neon_check_type (2, NS_NULL,
20080 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
20081 logsize = neon_logbits (et.size);
20083 if (et.size != 32)
20085 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20086 && vfp_or_neon_is_neon (NEON_CHECK_CC
20087 | NEON_CHECK_ARCH) == FAIL)
20088 return;
20090 else
20092 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20093 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20094 _(BAD_FPU));
20097 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20099 if (inst.operands[0].reg == REG_SP)
20100 as_tsktsk (MVE_BAD_SP);
20101 else if (inst.operands[0].reg == REG_PC)
20102 as_tsktsk (MVE_BAD_PC);
20105 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20107 constraint (et.type == NT_invtype, _("bad type for scalar"));
20108 constraint (x >= size / et.size, _("scalar index out of range"));
20110 switch (et.size)
20112 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20113 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20114 case 32: abcdebits = 0x00; break;
20115 default: ;
20118 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20119 inst.instruction = 0xe100b10;
20120 do_vfp_cond_or_thumb ();
20121 inst.instruction |= LOW4 (dn) << 16;
20122 inst.instruction |= HI1 (dn) << 7;
20123 inst.instruction |= inst.operands[0].reg << 12;
20124 inst.instruction |= (abcdebits & 3) << 5;
20125 inst.instruction |= (abcdebits >> 2) << 21;
20126 inst.instruction |= (x >> (3-logsize)) << 16;
20128 break;
20130 case NS_RRD: /* case 7 (fmrrd). */
20131 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20132 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20133 _(BAD_FPU));
20135 inst.instruction = 0xc500b10;
20136 do_vfp_cond_or_thumb ();
20137 inst.instruction |= inst.operands[0].reg << 12;
20138 inst.instruction |= inst.operands[1].reg << 16;
20139 inst.instruction |= LOW4 (inst.operands[2].reg);
20140 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20141 break;
20143 case NS_FF: /* case 8 (fcpys). */
20144 do_vfp_nsyn_opcode ("fcpys");
20145 break;
20147 case NS_HI:
20148 case NS_FI: /* case 10 (fconsts). */
20149 ldconst = "fconsts";
20150 encode_fconstd:
20151 if (!inst.operands[1].immisfloat)
20153 unsigned new_imm;
20154 /* Immediate has to fit in 8 bits so float is enough. */
20155 float imm = (float) inst.operands[1].imm;
20156 memcpy (&new_imm, &imm, sizeof (float));
20157 /* But the assembly may have been written to provide an integer
20158 bit pattern that equates to a float, so check that the
20159 conversion has worked. */
20160 if (is_quarter_float (new_imm))
20162 if (is_quarter_float (inst.operands[1].imm))
20163 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20165 inst.operands[1].imm = new_imm;
20166 inst.operands[1].immisfloat = 1;
20170 if (is_quarter_float (inst.operands[1].imm))
20172 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20173 do_vfp_nsyn_opcode (ldconst);
20175 /* ARMv8.2 fp16 vmov.f16 instruction. */
20176 if (rs == NS_HI)
20177 do_scalar_fp16_v82_encode ();
20179 else
20180 first_error (_("immediate out of range"));
20181 break;
20183 case NS_RH:
20184 case NS_RF: /* case 12 (fmrs). */
20185 do_vfp_nsyn_opcode ("fmrs");
20186 /* ARMv8.2 fp16 vmov.f16 instruction. */
20187 if (rs == NS_RH)
20188 do_scalar_fp16_v82_encode ();
20189 break;
20191 case NS_HR:
20192 case NS_FR: /* case 13 (fmsr). */
20193 do_vfp_nsyn_opcode ("fmsr");
20194 /* ARMv8.2 fp16 vmov.f16 instruction. */
20195 if (rs == NS_HR)
20196 do_scalar_fp16_v82_encode ();
20197 break;
20199 case NS_RRSS:
20200 do_mve_mov (0);
20201 break;
20202 case NS_SSRR:
20203 do_mve_mov (1);
20204 break;
20206 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20207 (one of which is a list), but we have parsed four. Do some fiddling to
20208 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20209 expect. */
20210 case NS_RRFF: /* case 14 (fmrrs). */
20211 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20212 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20213 _(BAD_FPU));
20214 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
20215 _("VFP registers must be adjacent"));
20216 inst.operands[2].imm = 2;
20217 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20218 do_vfp_nsyn_opcode ("fmrrs");
20219 break;
20221 case NS_FFRR: /* case 15 (fmsrr). */
20222 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20223 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20224 _(BAD_FPU));
20225 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
20226 _("VFP registers must be adjacent"));
20227 inst.operands[1] = inst.operands[2];
20228 inst.operands[2] = inst.operands[3];
20229 inst.operands[0].imm = 2;
20230 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20231 do_vfp_nsyn_opcode ("fmsrr");
20232 break;
20234 case NS_NULL:
20235 /* neon_select_shape has determined that the instruction
20236 shape is wrong and has already set the error message. */
20237 break;
20239 default:
20240 abort ();
20244 static void
20245 do_mve_movl (void)
20247 if (!(inst.operands[0].present && inst.operands[0].isquad
20248 && inst.operands[1].present && inst.operands[1].isquad
20249 && !inst.operands[2].present))
20251 inst.instruction = 0;
20252 inst.cond = 0xb;
20253 if (thumb_mode)
20254 set_pred_insn_type (INSIDE_IT_INSN);
20255 do_neon_mov ();
20256 return;
20259 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20260 return;
20262 if (inst.cond != COND_ALWAYS)
20263 inst.pred_insn_type = INSIDE_VPT_INSN;
20265 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20266 | N_S16 | N_U16 | N_KEY);
20268 inst.instruction |= (et.type == NT_unsigned) << 28;
20269 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20270 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20271 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20272 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20273 inst.instruction |= LOW4 (inst.operands[1].reg);
20274 inst.is_neon = 1;
20277 static void
20278 do_neon_rshift_round_imm (void)
20280 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
20281 return;
20283 enum neon_shape rs;
20284 struct neon_type_el et;
20286 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20288 rs = neon_select_shape (NS_QQI, NS_NULL);
20289 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20291 else
20293 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20294 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20296 int imm = inst.operands[2].imm;
20298 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20299 if (imm == 0)
20301 inst.operands[2].present = 0;
20302 do_neon_mov ();
20303 return;
20306 constraint (imm < 1 || (unsigned)imm > et.size,
20307 _("immediate out of range for shift"));
20308 neon_imm_shift (true, et.type == NT_unsigned, neon_quad (rs), et,
20309 et.size - imm);
20312 static void
20313 do_neon_movhf (void)
20315 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20316 constraint (rs != NS_HH, _("invalid suffix"));
20318 if (inst.cond != COND_ALWAYS)
20320 if (thumb_mode)
20322 as_warn (_("scalar fp16 instruction cannot be conditional,"
20323 " the behaviour is UNPREDICTABLE"));
20325 else
20327 inst.error = BAD_COND;
20328 return;
20332 do_vfp_sp_monadic ();
20334 inst.is_neon = 1;
20335 inst.instruction |= 0xf0000000;
20338 static void
20339 do_neon_movl (void)
20341 struct neon_type_el et = neon_check_type (2, NS_QD,
20342 N_EQK | N_DBL, N_SU_32 | N_KEY);
20343 unsigned sizebits = et.size >> 3;
20344 inst.instruction |= sizebits << 19;
20345 neon_two_same (0, et.type == NT_unsigned, -1);
20348 static void
20349 do_neon_trn (void)
20351 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20352 struct neon_type_el et = neon_check_type (2, rs,
20353 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20354 NEON_ENCODE (INTEGER, inst);
20355 neon_two_same (neon_quad (rs), 1, et.size);
20358 static void
20359 do_neon_zip_uzp (void)
20361 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20362 struct neon_type_el et = neon_check_type (2, rs,
20363 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20364 if (rs == NS_DD && et.size == 32)
20366 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20367 inst.instruction = N_MNEM_vtrn;
20368 do_neon_trn ();
20369 return;
20371 neon_two_same (neon_quad (rs), 1, et.size);
20374 static void
20375 do_neon_sat_abs_neg (void)
20377 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
20378 return;
20380 enum neon_shape rs;
20381 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20382 rs = neon_select_shape (NS_QQ, NS_NULL);
20383 else
20384 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20385 struct neon_type_el et = neon_check_type (2, rs,
20386 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20387 neon_two_same (neon_quad (rs), 1, et.size);
20390 static void
20391 do_neon_pair_long (void)
20393 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20394 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20395 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20396 inst.instruction |= (et.type == NT_unsigned) << 7;
20397 neon_two_same (neon_quad (rs), 1, et.size);
20400 static void
20401 do_neon_recip_est (void)
20403 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20404 struct neon_type_el et = neon_check_type (2, rs,
20405 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
20406 inst.instruction |= (et.type == NT_float) << 8;
20407 neon_two_same (neon_quad (rs), 1, et.size);
20410 static void
20411 do_neon_cls (void)
20413 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
20414 return;
20416 enum neon_shape rs;
20417 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20418 rs = neon_select_shape (NS_QQ, NS_NULL);
20419 else
20420 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20422 struct neon_type_el et = neon_check_type (2, rs,
20423 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20424 neon_two_same (neon_quad (rs), 1, et.size);
20427 static void
20428 do_neon_clz (void)
20430 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
20431 return;
20433 enum neon_shape rs;
20434 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20435 rs = neon_select_shape (NS_QQ, NS_NULL);
20436 else
20437 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20439 struct neon_type_el et = neon_check_type (2, rs,
20440 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
20441 neon_two_same (neon_quad (rs), 1, et.size);
20444 static void
20445 do_neon_cnt (void)
20447 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20448 struct neon_type_el et = neon_check_type (2, rs,
20449 N_EQK | N_INT, N_8 | N_KEY);
20450 neon_two_same (neon_quad (rs), 1, et.size);
20453 static void
20454 do_neon_swp (void)
20456 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20457 if (rs == NS_NULL)
20458 return;
20459 neon_two_same (neon_quad (rs), 1, -1);
20462 static void
20463 do_neon_tbl_tbx (void)
20465 unsigned listlenbits;
20466 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
20468 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20470 first_error (_("bad list length for table lookup"));
20471 return;
20474 listlenbits = inst.operands[1].imm - 1;
20475 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20476 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20477 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20478 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20479 inst.instruction |= LOW4 (inst.operands[2].reg);
20480 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20481 inst.instruction |= listlenbits << 8;
20483 neon_dp_fixup (&inst);
20486 static void
20487 do_neon_ldm_stm (void)
20489 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20490 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20491 _(BAD_FPU));
20492 /* P, U and L bits are part of bitmask. */
20493 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20494 unsigned offsetbits = inst.operands[1].imm * 2;
20496 if (inst.operands[1].issingle)
20498 do_vfp_nsyn_ldm_stm (is_dbmode);
20499 return;
20502 constraint (is_dbmode && !inst.operands[0].writeback,
20503 _("writeback (!) must be used for VLDMDB and VSTMDB"));
20505 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20506 _("register list must contain at least 1 and at most 16 "
20507 "registers"));
20509 inst.instruction |= inst.operands[0].reg << 16;
20510 inst.instruction |= inst.operands[0].writeback << 21;
20511 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20512 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20514 inst.instruction |= offsetbits;
20516 do_vfp_cond_or_thumb ();
20519 static void
20520 do_vfp_nsyn_push_pop_check (void)
20522 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd), _(BAD_FPU));
20524 if (inst.operands[1].issingle)
20526 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 32,
20527 _("register list must contain at least 1 and at most 32 registers"));
20529 else
20531 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20532 _("register list must contain at least 1 and at most 16 registers"));
20536 static void
20537 do_vfp_nsyn_pop (void)
20539 nsyn_insert_sp ();
20541 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20542 return do_vfp_nsyn_opcode ("vldm");
20544 do_vfp_nsyn_push_pop_check ();
20546 if (inst.operands[1].issingle)
20547 do_vfp_nsyn_opcode ("fldmias");
20548 else
20549 do_vfp_nsyn_opcode ("fldmiad");
20552 static void
20553 do_vfp_nsyn_push (void)
20555 nsyn_insert_sp ();
20557 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20558 return do_vfp_nsyn_opcode ("vstmdb");
20560 do_vfp_nsyn_push_pop_check ();
20562 if (inst.operands[1].issingle)
20563 do_vfp_nsyn_opcode ("fstmdbs");
20564 else
20565 do_vfp_nsyn_opcode ("fstmdbd");
20568 static void
20569 do_neon_ldr_str (void)
20571 int is_ldr = (inst.instruction & (1 << 20)) != 0;
20573 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20574 And is UNPREDICTABLE in thumb mode. */
20575 if (!is_ldr
20576 && inst.operands[1].reg == REG_PC
20577 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
20579 if (thumb_mode)
20580 inst.error = _("Use of PC here is UNPREDICTABLE");
20581 else if (warn_on_deprecated)
20582 as_tsktsk (_("Use of PC here is deprecated"));
20585 if (inst.operands[0].issingle)
20587 if (is_ldr)
20588 do_vfp_nsyn_opcode ("flds");
20589 else
20590 do_vfp_nsyn_opcode ("fsts");
20592 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20593 if (inst.vectype.el[0].size == 16)
20594 do_scalar_fp16_v82_encode ();
20596 else
20598 if (is_ldr)
20599 do_vfp_nsyn_opcode ("fldd");
20600 else
20601 do_vfp_nsyn_opcode ("fstd");
20605 static void
20606 do_t_vldr_vstr_sysreg (void)
20608 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20609 bool is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20611 /* Use of PC is UNPREDICTABLE. */
20612 if (inst.operands[1].reg == REG_PC)
20613 inst.error = _("Use of PC here is UNPREDICTABLE");
20615 if (inst.operands[1].immisreg)
20616 inst.error = _("instruction does not accept register index");
20618 if (!inst.operands[1].isreg)
20619 inst.error = _("instruction does not accept PC-relative addressing");
20621 if (abs (inst.operands[1].imm) >= (1 << 7))
20622 inst.error = _("immediate value out of range");
20624 inst.instruction = 0xec000f80;
20625 if (is_vldr)
20626 inst.instruction |= 1 << sysreg_vldr_bitno;
20627 encode_arm_cp_address (1, true, false, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20628 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20629 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20632 static void
20633 do_vldr_vstr (void)
20635 bool sysreg_op = !inst.operands[0].isreg;
20637 /* VLDR/VSTR (System Register). */
20638 if (sysreg_op)
20640 if (!mark_feature_used (&arm_ext_v8_1m_main))
20641 as_bad (_("Instruction not permitted on this architecture"));
20643 do_t_vldr_vstr_sysreg ();
20645 /* VLDR/VSTR. */
20646 else
20648 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20649 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20650 as_bad (_("Instruction not permitted on this architecture"));
20651 do_neon_ldr_str ();
20655 /* "interleave" version also handles non-interleaving register VLD1/VST1
20656 instructions. */
20658 static void
20659 do_neon_ld_st_interleave (void)
20661 struct neon_type_el et = neon_check_type (1, NS_NULL,
20662 N_8 | N_16 | N_32 | N_64);
20663 unsigned alignbits = 0;
20664 unsigned idx;
20665 /* The bits in this table go:
20666 0: register stride of one (0) or two (1)
20667 1,2: register list length, minus one (1, 2, 3, 4).
20668 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20669 We use -1 for invalid entries. */
20670 const int typetable[] =
20672 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20673 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20674 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20675 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20677 int typebits;
20679 if (et.type == NT_invtype)
20680 return;
20682 if (inst.operands[1].immisalign)
20683 switch (inst.operands[1].imm >> 8)
20685 case 64: alignbits = 1; break;
20686 case 128:
20687 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
20688 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20689 goto bad_alignment;
20690 alignbits = 2;
20691 break;
20692 case 256:
20693 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20694 goto bad_alignment;
20695 alignbits = 3;
20696 break;
20697 default:
20698 bad_alignment:
20699 first_error (_("bad alignment"));
20700 return;
20703 inst.instruction |= alignbits << 4;
20704 inst.instruction |= neon_logbits (et.size) << 6;
20706 /* Bits [4:6] of the immediate in a list specifier encode register stride
20707 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20708 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20709 up the right value for "type" in a table based on this value and the given
20710 list style, then stick it back. */
20711 idx = ((inst.operands[0].imm >> 4) & 7)
20712 | (((inst.instruction >> 8) & 3) << 3);
20714 typebits = typetable[idx];
20716 constraint (typebits == -1, _("bad list type for instruction"));
20717 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
20718 BAD_EL_TYPE);
20720 inst.instruction &= ~0xf00;
20721 inst.instruction |= typebits << 8;
20724 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20725 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20726 otherwise. The variable arguments are a list of pairs of legal (size, align)
20727 values, terminated with -1. */
20729 static int
20730 neon_alignment_bit (int size, int align, int *do_alignment, ...)
20732 va_list ap;
20733 int result = FAIL, thissize, thisalign;
20735 if (!inst.operands[1].immisalign)
20737 *do_alignment = 0;
20738 return SUCCESS;
20741 va_start (ap, do_alignment);
20745 thissize = va_arg (ap, int);
20746 if (thissize == -1)
20747 break;
20748 thisalign = va_arg (ap, int);
20750 if (size == thissize && align == thisalign)
20751 result = SUCCESS;
20753 while (result != SUCCESS);
20755 va_end (ap);
20757 if (result == SUCCESS)
20758 *do_alignment = 1;
20759 else
20760 first_error (_("unsupported alignment for instruction"));
20762 return result;
20765 static void
20766 do_neon_ld_st_lane (void)
20768 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20769 int align_good, do_alignment = 0;
20770 int logsize = neon_logbits (et.size);
20771 int align = inst.operands[1].imm >> 8;
20772 int n = (inst.instruction >> 8) & 3;
20773 int max_el = 64 / et.size;
20775 if (et.type == NT_invtype)
20776 return;
20778 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
20779 _("bad list length"));
20780 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
20781 _("scalar index out of range"));
20782 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
20783 && et.size == 8,
20784 _("stride of 2 unavailable when element size is 8"));
20786 switch (n)
20788 case 0: /* VLD1 / VST1. */
20789 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
20790 32, 32, -1);
20791 if (align_good == FAIL)
20792 return;
20793 if (do_alignment)
20795 unsigned alignbits = 0;
20796 switch (et.size)
20798 case 16: alignbits = 0x1; break;
20799 case 32: alignbits = 0x3; break;
20800 default: ;
20802 inst.instruction |= alignbits << 4;
20804 break;
20806 case 1: /* VLD2 / VST2. */
20807 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20808 16, 32, 32, 64, -1);
20809 if (align_good == FAIL)
20810 return;
20811 if (do_alignment)
20812 inst.instruction |= 1 << 4;
20813 break;
20815 case 2: /* VLD3 / VST3. */
20816 constraint (inst.operands[1].immisalign,
20817 _("can't use alignment with this instruction"));
20818 break;
20820 case 3: /* VLD4 / VST4. */
20821 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
20822 16, 64, 32, 64, 32, 128, -1);
20823 if (align_good == FAIL)
20824 return;
20825 if (do_alignment)
20827 unsigned alignbits = 0;
20828 switch (et.size)
20830 case 8: alignbits = 0x1; break;
20831 case 16: alignbits = 0x1; break;
20832 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
20833 default: ;
20835 inst.instruction |= alignbits << 4;
20837 break;
20839 default: ;
20842 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
20843 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20844 inst.instruction |= 1 << (4 + logsize);
20846 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
20847 inst.instruction |= logsize << 10;
20850 /* Encode single n-element structure to all lanes VLD<n> instructions. */
20852 static void
20853 do_neon_ld_dup (void)
20855 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20856 int align_good, do_alignment = 0;
20858 if (et.type == NT_invtype)
20859 return;
20861 switch ((inst.instruction >> 8) & 3)
20863 case 0: /* VLD1. */
20864 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
20865 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
20866 &do_alignment, 16, 16, 32, 32, -1);
20867 if (align_good == FAIL)
20868 return;
20869 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
20871 case 1: break;
20872 case 2: inst.instruction |= 1 << 5; break;
20873 default: first_error (_("bad list length")); return;
20875 inst.instruction |= neon_logbits (et.size) << 6;
20876 break;
20878 case 1: /* VLD2. */
20879 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
20880 &do_alignment, 8, 16, 16, 32, 32, 64,
20881 -1);
20882 if (align_good == FAIL)
20883 return;
20884 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
20885 _("bad list length"));
20886 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20887 inst.instruction |= 1 << 5;
20888 inst.instruction |= neon_logbits (et.size) << 6;
20889 break;
20891 case 2: /* VLD3. */
20892 constraint (inst.operands[1].immisalign,
20893 _("can't use alignment with this instruction"));
20894 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
20895 _("bad list length"));
20896 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20897 inst.instruction |= 1 << 5;
20898 inst.instruction |= neon_logbits (et.size) << 6;
20899 break;
20901 case 3: /* VLD4. */
20903 int align = inst.operands[1].imm >> 8;
20904 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
20905 16, 64, 32, 64, 32, 128, -1);
20906 if (align_good == FAIL)
20907 return;
20908 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
20909 _("bad list length"));
20910 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20911 inst.instruction |= 1 << 5;
20912 if (et.size == 32 && align == 128)
20913 inst.instruction |= 0x3 << 6;
20914 else
20915 inst.instruction |= neon_logbits (et.size) << 6;
20917 break;
20919 default: ;
20922 inst.instruction |= do_alignment << 4;
20925 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
20926 apart from bits [11:4]. */
20928 static void
20929 do_neon_ldx_stx (void)
20931 if (inst.operands[1].isreg)
20932 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
20934 switch (NEON_LANE (inst.operands[0].imm))
20936 case NEON_INTERLEAVE_LANES:
20937 NEON_ENCODE (INTERLV, inst);
20938 do_neon_ld_st_interleave ();
20939 break;
20941 case NEON_ALL_LANES:
20942 NEON_ENCODE (DUP, inst);
20943 if (inst.instruction == N_INV)
20945 first_error ("only loads support such operands");
20946 break;
20948 do_neon_ld_dup ();
20949 break;
20951 default:
20952 NEON_ENCODE (LANE, inst);
20953 do_neon_ld_st_lane ();
20956 /* L bit comes from bit mask. */
20957 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20958 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20959 inst.instruction |= inst.operands[1].reg << 16;
20961 if (inst.operands[1].postind)
20963 int postreg = inst.operands[1].imm & 0xf;
20964 constraint (!inst.operands[1].immisreg,
20965 _("post-index must be a register"));
20966 constraint (postreg == 0xd || postreg == 0xf,
20967 _("bad register for post-index"));
20968 inst.instruction |= postreg;
20970 else
20972 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
20973 constraint (inst.relocs[0].exp.X_op != O_constant
20974 || inst.relocs[0].exp.X_add_number != 0,
20975 BAD_ADDR_MODE);
20977 if (inst.operands[1].writeback)
20979 inst.instruction |= 0xd;
20981 else
20982 inst.instruction |= 0xf;
20985 if (thumb_mode)
20986 inst.instruction |= 0xf9000000;
20987 else
20988 inst.instruction |= 0xf4000000;
20991 /* FP v8. */
20992 static void
20993 do_vfp_nsyn_fpv8 (enum neon_shape rs)
20995 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20996 D register operands. */
20997 if (neon_shape_class[rs] == SC_DOUBLE)
20998 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20999 _(BAD_FPU));
21001 NEON_ENCODE (FPV8, inst);
21003 if (rs == NS_FFF || rs == NS_HHH)
21005 do_vfp_sp_dyadic ();
21007 /* ARMv8.2 fp16 instruction. */
21008 if (rs == NS_HHH)
21009 do_scalar_fp16_v82_encode ();
21011 else
21012 do_vfp_dp_rd_rn_rm ();
21014 if (rs == NS_DDD)
21015 inst.instruction |= 0x100;
21017 inst.instruction |= 0xf0000000;
21020 static void
21021 do_vsel (void)
21023 set_pred_insn_type (OUTSIDE_PRED_INSN);
21025 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21026 first_error (_("invalid instruction shape"));
21029 static void
21030 do_vmaxnm (void)
21032 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21033 set_pred_insn_type (OUTSIDE_PRED_INSN);
21035 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21036 return;
21038 if (!check_simd_pred_availability (true, NEON_CHECK_CC | NEON_CHECK_ARCH8))
21039 return;
21041 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
21044 static void
21045 do_vrint_1 (enum neon_cvt_mode mode)
21047 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
21048 struct neon_type_el et;
21050 if (rs == NS_NULL)
21051 return;
21053 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21054 D register operands. */
21055 if (neon_shape_class[rs] == SC_DOUBLE)
21056 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21057 _(BAD_FPU));
21059 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21060 | N_VFP);
21061 if (et.type != NT_invtype)
21063 /* VFP encodings. */
21064 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21065 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
21066 set_pred_insn_type (OUTSIDE_PRED_INSN);
21068 NEON_ENCODE (FPV8, inst);
21069 if (rs == NS_FF || rs == NS_HH)
21070 do_vfp_sp_monadic ();
21071 else
21072 do_vfp_dp_rd_rm ();
21074 switch (mode)
21076 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21077 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21078 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21079 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21080 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21081 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21082 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21083 default: abort ();
21086 inst.instruction |= (rs == NS_DD) << 8;
21087 do_vfp_cond_or_thumb ();
21089 /* ARMv8.2 fp16 vrint instruction. */
21090 if (rs == NS_HH)
21091 do_scalar_fp16_v82_encode ();
21093 else
21095 /* Neon encodings (or something broken...). */
21096 inst.error = NULL;
21097 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
21099 if (et.type == NT_invtype)
21100 return;
21102 if (!check_simd_pred_availability (true,
21103 NEON_CHECK_CC | NEON_CHECK_ARCH8))
21104 return;
21106 NEON_ENCODE (FLOAT, inst);
21108 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21109 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21110 inst.instruction |= LOW4 (inst.operands[1].reg);
21111 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21112 inst.instruction |= neon_quad (rs) << 6;
21113 /* Mask off the original size bits and reencode them. */
21114 inst.instruction = ((inst.instruction & 0xfff3ffff)
21115 | neon_logbits (et.size) << 18);
21117 switch (mode)
21119 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21120 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21121 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21122 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21123 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21124 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21125 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21126 default: abort ();
21129 if (thumb_mode)
21130 inst.instruction |= 0xfc000000;
21131 else
21132 inst.instruction |= 0xf0000000;
21136 static void
21137 do_vrintx (void)
21139 do_vrint_1 (neon_cvt_mode_x);
21142 static void
21143 do_vrintz (void)
21145 do_vrint_1 (neon_cvt_mode_z);
21148 static void
21149 do_vrintr (void)
21151 do_vrint_1 (neon_cvt_mode_r);
21154 static void
21155 do_vrinta (void)
21157 do_vrint_1 (neon_cvt_mode_a);
21160 static void
21161 do_vrintn (void)
21163 do_vrint_1 (neon_cvt_mode_n);
21166 static void
21167 do_vrintp (void)
21169 do_vrint_1 (neon_cvt_mode_p);
21172 static void
21173 do_vrintm (void)
21175 do_vrint_1 (neon_cvt_mode_m);
21178 static unsigned
21179 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21181 unsigned regno = NEON_SCALAR_REG (opnd);
21182 unsigned elno = NEON_SCALAR_INDEX (opnd);
21184 if (elsize == 16 && elno < 2 && regno < 16)
21185 return regno | (elno << 4);
21186 else if (elsize == 32 && elno == 0)
21187 return regno;
21189 first_error (_("scalar out of range"));
21190 return 0;
21193 static void
21194 do_vcmla (void)
21196 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21197 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21198 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21199 constraint (inst.relocs[0].exp.X_op != O_constant,
21200 _("expression too complex"));
21201 unsigned rot = inst.relocs[0].exp.X_add_number;
21202 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21203 _("immediate out of range"));
21204 rot /= 90;
21206 if (!check_simd_pred_availability (true,
21207 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21208 return;
21210 if (inst.operands[2].isscalar)
21212 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21213 first_error (_("invalid instruction shape"));
21214 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21215 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21216 N_KEY | N_F16 | N_F32).size;
21217 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21218 inst.is_neon = 1;
21219 inst.instruction = 0xfe000800;
21220 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21221 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21222 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21223 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21224 inst.instruction |= LOW4 (m);
21225 inst.instruction |= HI1 (m) << 5;
21226 inst.instruction |= neon_quad (rs) << 6;
21227 inst.instruction |= rot << 20;
21228 inst.instruction |= (size == 32) << 23;
21230 else
21232 enum neon_shape rs;
21233 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21234 rs = neon_select_shape (NS_QQQI, NS_NULL);
21235 else
21236 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21238 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21239 N_KEY | N_F16 | N_F32).size;
21240 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21241 && (inst.operands[0].reg == inst.operands[1].reg
21242 || inst.operands[0].reg == inst.operands[2].reg))
21243 as_tsktsk (BAD_MVE_SRCDEST);
21245 neon_three_same (neon_quad (rs), 0, -1);
21246 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21247 inst.instruction |= 0xfc200800;
21248 inst.instruction |= rot << 23;
21249 inst.instruction |= (size == 32) << 20;
21253 static void
21254 do_vcadd (void)
21256 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21257 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21258 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21259 constraint (inst.relocs[0].exp.X_op != O_constant,
21260 _("expression too complex"));
21262 unsigned rot = inst.relocs[0].exp.X_add_number;
21263 constraint (rot != 90 && rot != 270, _("immediate out of range"));
21264 enum neon_shape rs;
21265 struct neon_type_el et;
21266 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21268 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21269 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21271 else
21273 rs = neon_select_shape (NS_QQQI, NS_NULL);
21274 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21275 | N_I16 | N_I32);
21276 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21277 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21278 "operand makes instruction UNPREDICTABLE"));
21281 if (et.type == NT_invtype)
21282 return;
21284 if (!check_simd_pred_availability (et.type == NT_float,
21285 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21286 return;
21288 if (et.type == NT_float)
21290 neon_three_same (neon_quad (rs), 0, -1);
21291 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21292 inst.instruction |= 0xfc800800;
21293 inst.instruction |= (rot == 270) << 24;
21294 inst.instruction |= (et.size == 32) << 20;
21296 else
21298 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21299 inst.instruction = 0xfe000f00;
21300 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21301 inst.instruction |= neon_logbits (et.size) << 20;
21302 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21303 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21304 inst.instruction |= (rot == 270) << 12;
21305 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21306 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21307 inst.instruction |= LOW4 (inst.operands[2].reg);
21308 inst.is_neon = 1;
21312 /* Dot Product instructions encoding support. */
21314 static void
21315 do_neon_dotproduct (int unsigned_p)
21317 enum neon_shape rs;
21318 unsigned scalar_oprd2 = 0;
21319 int high8;
21321 if (inst.cond != COND_ALWAYS)
21322 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21323 "is UNPREDICTABLE"));
21325 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21326 _(BAD_FPU));
21328 /* Dot Product instructions are in three-same D/Q register format or the third
21329 operand can be a scalar index register. */
21330 if (inst.operands[2].isscalar)
21332 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21333 high8 = 0xfe000000;
21334 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21336 else
21338 high8 = 0xfc000000;
21339 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21342 if (unsigned_p)
21343 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21344 else
21345 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21347 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21348 Product instruction, so we pass 0 as the "ubit" parameter. And the
21349 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21350 neon_three_same (neon_quad (rs), 0, 32);
21352 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21353 different NEON three-same encoding. */
21354 inst.instruction &= 0x00ffffff;
21355 inst.instruction |= high8;
21356 /* Encode 'U' bit which indicates signedness. */
21357 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21358 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21359 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21360 the instruction encoding. */
21361 if (inst.operands[2].isscalar)
21363 inst.instruction &= 0xffffffd0;
21364 inst.instruction |= LOW4 (scalar_oprd2);
21365 inst.instruction |= HI1 (scalar_oprd2) << 5;
21369 /* Dot Product instructions for signed integer. */
21371 static void
21372 do_neon_dotproduct_s (void)
21374 return do_neon_dotproduct (0);
21377 /* Dot Product instructions for unsigned integer. */
21379 static void
21380 do_neon_dotproduct_u (void)
21382 return do_neon_dotproduct (1);
21385 static void
21386 do_vusdot (void)
21388 enum neon_shape rs;
21389 set_pred_insn_type (OUTSIDE_PRED_INSN);
21390 if (inst.operands[2].isscalar)
21392 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21393 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21395 inst.instruction |= (1 << 25);
21396 int idx = inst.operands[2].reg & 0xf;
21397 constraint ((idx != 1 && idx != 0), _("index must be 0 or 1"));
21398 inst.operands[2].reg >>= 4;
21399 constraint (!(inst.operands[2].reg < 16),
21400 _("indexed register must be less than 16"));
21401 neon_three_args (rs == NS_QQS);
21402 inst.instruction |= (idx << 5);
21404 else
21406 inst.instruction |= (1 << 21);
21407 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21408 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21409 neon_three_args (rs == NS_QQQ);
21413 static void
21414 do_vsudot (void)
21416 enum neon_shape rs;
21417 set_pred_insn_type (OUTSIDE_PRED_INSN);
21418 if (inst.operands[2].isscalar)
21420 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21421 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21423 inst.instruction |= (1 << 25);
21424 int idx = inst.operands[2].reg & 0xf;
21425 constraint ((idx != 1 && idx != 0), _("index must be 0 or 1"));
21426 inst.operands[2].reg >>= 4;
21427 constraint (!(inst.operands[2].reg < 16),
21428 _("indexed register must be less than 16"));
21429 neon_three_args (rs == NS_QQS);
21430 inst.instruction |= (idx << 5);
21434 static void
21435 do_vsmmla (void)
21437 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21438 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21440 set_pred_insn_type (OUTSIDE_PRED_INSN);
21442 neon_three_args (1);
21446 static void
21447 do_vummla (void)
21449 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21450 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21452 set_pred_insn_type (OUTSIDE_PRED_INSN);
21454 neon_three_args (1);
21458 static void
21459 check_cde_operand (size_t idx, int is_dual)
21461 unsigned Rx = inst.operands[idx].reg;
21462 bool isvec = inst.operands[idx].isvec;
21463 if (is_dual == 0 && thumb_mode)
21464 constraint (
21465 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21466 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21467 else
21468 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21469 _("Register must be an even register between r0-r10."));
21472 static bool
21473 cde_coproc_enabled (unsigned coproc)
21475 switch (coproc)
21477 case 0: return mark_feature_used (&arm_ext_cde0);
21478 case 1: return mark_feature_used (&arm_ext_cde1);
21479 case 2: return mark_feature_used (&arm_ext_cde2);
21480 case 3: return mark_feature_used (&arm_ext_cde3);
21481 case 4: return mark_feature_used (&arm_ext_cde4);
21482 case 5: return mark_feature_used (&arm_ext_cde5);
21483 case 6: return mark_feature_used (&arm_ext_cde6);
21484 case 7: return mark_feature_used (&arm_ext_cde7);
21485 default: return false;
21489 #define cde_coproc_pos 8
21490 static void
21491 cde_handle_coproc (void)
21493 unsigned coproc = inst.operands[0].reg;
21494 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21495 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21496 inst.instruction |= coproc << cde_coproc_pos;
21498 #undef cde_coproc_pos
21500 static void
21501 cxn_handle_predication (bool is_accum)
21503 if (is_accum && conditional_insn ())
21504 set_pred_insn_type (INSIDE_IT_INSN);
21505 else if (conditional_insn ())
21506 /* conditional_insn essentially checks for a suffix, not whether the
21507 instruction is inside an IT block or not.
21508 The non-accumulator versions should not have suffixes. */
21509 inst.error = BAD_SYNTAX;
21510 else
21511 set_pred_insn_type (OUTSIDE_PRED_INSN);
21514 static void
21515 do_custom_instruction_1 (int is_dual, bool is_accum)
21518 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21520 unsigned imm, Rd;
21522 Rd = inst.operands[1].reg;
21523 check_cde_operand (1, is_dual);
21525 if (is_dual == 1)
21527 constraint (inst.operands[2].reg != Rd + 1,
21528 _("cx1d requires consecutive destination registers."));
21529 imm = inst.operands[3].imm;
21531 else if (is_dual == 0)
21532 imm = inst.operands[2].imm;
21533 else
21534 abort ();
21536 inst.instruction |= Rd << 12;
21537 inst.instruction |= (imm & 0x1F80) << 9;
21538 inst.instruction |= (imm & 0x0040) << 1;
21539 inst.instruction |= (imm & 0x003f);
21541 cde_handle_coproc ();
21542 cxn_handle_predication (is_accum);
21545 static void
21546 do_custom_instruction_2 (int is_dual, bool is_accum)
21549 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21551 unsigned imm, Rd, Rn;
21553 Rd = inst.operands[1].reg;
21555 if (is_dual == 1)
21557 constraint (inst.operands[2].reg != Rd + 1,
21558 _("cx2d requires consecutive destination registers."));
21559 imm = inst.operands[4].imm;
21560 Rn = inst.operands[3].reg;
21562 else if (is_dual == 0)
21564 imm = inst.operands[3].imm;
21565 Rn = inst.operands[2].reg;
21567 else
21568 abort ();
21570 check_cde_operand (2 + is_dual, /* is_dual = */0);
21571 check_cde_operand (1, is_dual);
21573 inst.instruction |= Rd << 12;
21574 inst.instruction |= Rn << 16;
21576 inst.instruction |= (imm & 0x0380) << 13;
21577 inst.instruction |= (imm & 0x0040) << 1;
21578 inst.instruction |= (imm & 0x003f);
21580 cde_handle_coproc ();
21581 cxn_handle_predication (is_accum);
21584 static void
21585 do_custom_instruction_3 (int is_dual, bool is_accum)
21588 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21590 unsigned imm, Rd, Rn, Rm;
21592 Rd = inst.operands[1].reg;
21594 if (is_dual == 1)
21596 constraint (inst.operands[2].reg != Rd + 1,
21597 _("cx3d requires consecutive destination registers."));
21598 imm = inst.operands[5].imm;
21599 Rn = inst.operands[3].reg;
21600 Rm = inst.operands[4].reg;
21602 else if (is_dual == 0)
21604 imm = inst.operands[4].imm;
21605 Rn = inst.operands[2].reg;
21606 Rm = inst.operands[3].reg;
21608 else
21609 abort ();
21611 check_cde_operand (1, is_dual);
21612 check_cde_operand (2 + is_dual, /* is_dual = */0);
21613 check_cde_operand (3 + is_dual, /* is_dual = */0);
21615 inst.instruction |= Rd;
21616 inst.instruction |= Rn << 16;
21617 inst.instruction |= Rm << 12;
21619 inst.instruction |= (imm & 0x0038) << 17;
21620 inst.instruction |= (imm & 0x0004) << 5;
21621 inst.instruction |= (imm & 0x0003) << 4;
21623 cde_handle_coproc ();
21624 cxn_handle_predication (is_accum);
21627 static void
21628 do_cx1 (void)
21630 return do_custom_instruction_1 (0, 0);
21633 static void
21634 do_cx1a (void)
21636 return do_custom_instruction_1 (0, 1);
21639 static void
21640 do_cx1d (void)
21642 return do_custom_instruction_1 (1, 0);
21645 static void
21646 do_cx1da (void)
21648 return do_custom_instruction_1 (1, 1);
21651 static void
21652 do_cx2 (void)
21654 return do_custom_instruction_2 (0, 0);
21657 static void
21658 do_cx2a (void)
21660 return do_custom_instruction_2 (0, 1);
21663 static void
21664 do_cx2d (void)
21666 return do_custom_instruction_2 (1, 0);
21669 static void
21670 do_cx2da (void)
21672 return do_custom_instruction_2 (1, 1);
21675 static void
21676 do_cx3 (void)
21678 return do_custom_instruction_3 (0, 0);
21681 static void
21682 do_cx3a (void)
21684 return do_custom_instruction_3 (0, 1);
21687 static void
21688 do_cx3d (void)
21690 return do_custom_instruction_3 (1, 0);
21693 static void
21694 do_cx3da (void)
21696 return do_custom_instruction_3 (1, 1);
21699 static void
21700 vcx_assign_vec_d (unsigned regnum)
21702 inst.instruction |= HI4 (regnum) << 12;
21703 inst.instruction |= LOW1 (regnum) << 22;
21706 static void
21707 vcx_assign_vec_m (unsigned regnum)
21709 inst.instruction |= HI4 (regnum);
21710 inst.instruction |= LOW1 (regnum) << 5;
21713 static void
21714 vcx_assign_vec_n (unsigned regnum)
21716 inst.instruction |= HI4 (regnum) << 16;
21717 inst.instruction |= LOW1 (regnum) << 7;
21720 enum vcx_reg_type {
21721 q_reg,
21722 d_reg,
21723 s_reg
21726 static enum vcx_reg_type
21727 vcx_get_reg_type (enum neon_shape ns)
21729 gas_assert (ns == NS_PQI
21730 || ns == NS_PDI
21731 || ns == NS_PFI
21732 || ns == NS_PQQI
21733 || ns == NS_PDDI
21734 || ns == NS_PFFI
21735 || ns == NS_PQQQI
21736 || ns == NS_PDDDI
21737 || ns == NS_PFFFI);
21738 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21739 return q_reg;
21740 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21741 return d_reg;
21742 return s_reg;
21745 #define vcx_size_pos 24
21746 #define vcx_vec_pos 6
21747 static unsigned
21748 vcx_handle_shape (enum vcx_reg_type reg_type)
21750 unsigned mult = 2;
21751 if (reg_type == q_reg)
21752 inst.instruction |= 1 << vcx_vec_pos;
21753 else if (reg_type == d_reg)
21754 inst.instruction |= 1 << vcx_size_pos;
21755 else
21756 mult = 1;
21757 /* NOTE:
21758 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21759 bits (or equivalent for N and M registers).
21760 Similarly the D registers are encoded as N in D:Vd bits.
21761 While the S registers are encoded as N in the Vd:D bits.
21763 Taking into account the maximum values of these registers we can see a
21764 nicer pattern for calculation:
21765 Q -> 7, D -> 15, S -> 31
21767 If we say that everything is encoded in the Vd:D bits, then we can say
21768 that Q is encoded as 4*N, and D is encoded as 2*N.
21769 This way the bits will end up the same, and calculation is simpler.
21770 (calculation is now:
21771 1. Multiply by a number determined by the register letter.
21772 2. Encode resulting number in Vd:D bits.)
21774 This is made a little more complicated by automatic handling of 'Q'
21775 registers elsewhere, which means the register number is already 2*N where
21776 N is the number the user wrote after the register letter.
21778 return mult;
21780 #undef vcx_vec_pos
21781 #undef vcx_size_pos
21783 static void
21784 vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21786 if (reg_type == q_reg)
21788 gas_assert (R % 2 == 0);
21789 constraint (R >= 16, _("'q' register must be in range 0-7"));
21791 else if (reg_type == d_reg)
21792 constraint (R >= 16, _("'d' register must be in range 0-15"));
21793 else
21794 constraint (R >= 32, _("'s' register must be in range 0-31"));
21797 static void (*vcx_assign_vec[3]) (unsigned) = {
21798 vcx_assign_vec_d,
21799 vcx_assign_vec_m,
21800 vcx_assign_vec_n
21803 static void
21804 vcx_handle_register_arguments (unsigned num_registers,
21805 enum vcx_reg_type reg_type)
21807 unsigned R, i;
21808 unsigned reg_mult = vcx_handle_shape (reg_type);
21809 for (i = 0; i < num_registers; i++)
21811 R = inst.operands[i+1].reg;
21812 vcx_ensure_register_in_range (R, reg_type);
21813 if (num_registers == 3 && i > 0)
21815 if (i == 2)
21816 vcx_assign_vec[1] (R * reg_mult);
21817 else
21818 vcx_assign_vec[2] (R * reg_mult);
21819 continue;
21821 vcx_assign_vec[i](R * reg_mult);
21825 static void
21826 vcx_handle_insn_block (enum vcx_reg_type reg_type)
21828 if (reg_type == q_reg)
21829 if (inst.cond > COND_ALWAYS)
21830 inst.pred_insn_type = INSIDE_VPT_INSN;
21831 else
21832 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
21833 else if (inst.cond == COND_ALWAYS)
21834 inst.pred_insn_type = OUTSIDE_PRED_INSN;
21835 else
21836 inst.error = BAD_NOT_IT;
21839 static void
21840 vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
21842 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21843 cde_handle_coproc ();
21844 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
21845 vcx_handle_register_arguments (num_args, reg_type);
21846 vcx_handle_insn_block (reg_type);
21847 if (reg_type == q_reg)
21848 constraint (!mark_feature_used (&mve_ext),
21849 _("vcx instructions with Q registers require MVE"));
21850 else
21851 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
21852 && mark_feature_used (&armv8m_fp))
21853 && !mark_feature_used (&mve_ext),
21854 _("vcx instructions with S or D registers require either MVE"
21855 " or Armv8-M floating point extension."));
21858 static void
21859 do_vcx1 (void)
21861 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
21862 vcx_handle_common_checks (1, rs);
21864 unsigned imm = inst.operands[2].imm;
21865 inst.instruction |= (imm & 0x03f);
21866 inst.instruction |= (imm & 0x040) << 1;
21867 inst.instruction |= (imm & 0x780) << 9;
21868 if (rs != NS_PQI)
21869 constraint (imm >= 2048,
21870 _("vcx1 with S or D registers takes immediate within 0-2047"));
21871 inst.instruction |= (imm & 0x800) << 13;
21874 static void
21875 do_vcx2 (void)
21877 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
21878 vcx_handle_common_checks (2, rs);
21880 unsigned imm = inst.operands[3].imm;
21881 inst.instruction |= (imm & 0x01) << 4;
21882 inst.instruction |= (imm & 0x02) << 6;
21883 inst.instruction |= (imm & 0x3c) << 14;
21884 if (rs != NS_PQQI)
21885 constraint (imm >= 64,
21886 _("vcx2 with S or D registers takes immediate within 0-63"));
21887 inst.instruction |= (imm & 0x40) << 18;
21890 static void
21891 do_vcx3 (void)
21893 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
21894 vcx_handle_common_checks (3, rs);
21896 unsigned imm = inst.operands[4].imm;
21897 inst.instruction |= (imm & 0x1) << 4;
21898 inst.instruction |= (imm & 0x6) << 19;
21899 if (rs != NS_PQQQI)
21900 constraint (imm >= 8,
21901 _("vcx2 with S or D registers takes immediate within 0-7"));
21902 inst.instruction |= (imm & 0x8) << 21;
21905 /* Crypto v1 instructions. */
21906 static void
21907 do_crypto_2op_1 (unsigned elttype, int op)
21909 set_pred_insn_type (OUTSIDE_PRED_INSN);
21911 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
21912 == NT_invtype)
21913 return;
21915 inst.error = NULL;
21917 NEON_ENCODE (INTEGER, inst);
21918 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21919 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21920 inst.instruction |= LOW4 (inst.operands[1].reg);
21921 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21922 if (op != -1)
21923 inst.instruction |= op << 6;
21925 if (thumb_mode)
21926 inst.instruction |= 0xfc000000;
21927 else
21928 inst.instruction |= 0xf0000000;
21931 static void
21932 do_crypto_3op_1 (int u, int op)
21934 set_pred_insn_type (OUTSIDE_PRED_INSN);
21936 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
21937 N_32 | N_UNT | N_KEY).type == NT_invtype)
21938 return;
21940 inst.error = NULL;
21942 NEON_ENCODE (INTEGER, inst);
21943 neon_three_same (1, u, 8 << op);
21946 static void
21947 do_aese (void)
21949 do_crypto_2op_1 (N_8, 0);
21952 static void
21953 do_aesd (void)
21955 do_crypto_2op_1 (N_8, 1);
21958 static void
21959 do_aesmc (void)
21961 do_crypto_2op_1 (N_8, 2);
21964 static void
21965 do_aesimc (void)
21967 do_crypto_2op_1 (N_8, 3);
21970 static void
21971 do_sha1c (void)
21973 do_crypto_3op_1 (0, 0);
21976 static void
21977 do_sha1p (void)
21979 do_crypto_3op_1 (0, 1);
21982 static void
21983 do_sha1m (void)
21985 do_crypto_3op_1 (0, 2);
21988 static void
21989 do_sha1su0 (void)
21991 do_crypto_3op_1 (0, 3);
21994 static void
21995 do_sha256h (void)
21997 do_crypto_3op_1 (1, 0);
22000 static void
22001 do_sha256h2 (void)
22003 do_crypto_3op_1 (1, 1);
22006 static void
22007 do_sha256su1 (void)
22009 do_crypto_3op_1 (1, 2);
22012 static void
22013 do_sha1h (void)
22015 do_crypto_2op_1 (N_32, -1);
22018 static void
22019 do_sha1su1 (void)
22021 do_crypto_2op_1 (N_32, 0);
22024 static void
22025 do_sha256su0 (void)
22027 do_crypto_2op_1 (N_32, 1);
22030 static void
22031 do_crc32_1 (unsigned int poly, unsigned int sz)
22033 unsigned int Rd = inst.operands[0].reg;
22034 unsigned int Rn = inst.operands[1].reg;
22035 unsigned int Rm = inst.operands[2].reg;
22037 set_pred_insn_type (OUTSIDE_PRED_INSN);
22038 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22039 inst.instruction |= LOW4 (Rn) << 16;
22040 inst.instruction |= LOW4 (Rm);
22041 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22042 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22044 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22045 as_warn (UNPRED_REG ("r15"));
22048 static void
22049 do_crc32b (void)
22051 do_crc32_1 (0, 0);
22054 static void
22055 do_crc32h (void)
22057 do_crc32_1 (0, 1);
22060 static void
22061 do_crc32w (void)
22063 do_crc32_1 (0, 2);
22066 static void
22067 do_crc32cb (void)
22069 do_crc32_1 (1, 0);
22072 static void
22073 do_crc32ch (void)
22075 do_crc32_1 (1, 1);
22078 static void
22079 do_crc32cw (void)
22081 do_crc32_1 (1, 2);
22084 static void
22085 do_vjcvt (void)
22087 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22088 _(BAD_FPU));
22089 neon_check_type (2, NS_FD, N_S32, N_F64);
22090 do_vfp_sp_dp_cvt ();
22091 do_vfp_cond_or_thumb ();
22094 static void
22095 do_vdot (void)
22097 enum neon_shape rs;
22098 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22099 set_pred_insn_type (OUTSIDE_PRED_INSN);
22100 if (inst.operands[2].isscalar)
22102 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22103 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22105 inst.instruction |= (1 << 25);
22106 int idx = inst.operands[2].reg & 0xf;
22107 constraint ((idx != 1 && idx != 0), _("index must be 0 or 1"));
22108 inst.operands[2].reg >>= 4;
22109 constraint (!(inst.operands[2].reg < 16),
22110 _("indexed register must be less than 16"));
22111 neon_three_args (rs == NS_QQS);
22112 inst.instruction |= (idx << 5);
22114 else
22116 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22117 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22118 neon_three_args (rs == NS_QQQ);
22122 static void
22123 do_vmmla (void)
22125 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22126 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22128 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22129 set_pred_insn_type (OUTSIDE_PRED_INSN);
22131 neon_three_args (1);
22134 static void
22135 do_t_pacbti (void)
22137 inst.instruction = THUMB_OP32 (inst.instruction);
22140 static void
22141 do_t_pacbti_nonop (void)
22143 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, pacbti_ext),
22144 _(BAD_PACBTI));
22146 inst.instruction = THUMB_OP32 (inst.instruction);
22147 inst.instruction |= inst.operands[0].reg << 12;
22148 inst.instruction |= inst.operands[1].reg << 16;
22149 inst.instruction |= inst.operands[2].reg;
22152 static void
22153 do_t_pacbti_pacg (void)
22155 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, pacbti_ext),
22156 _(BAD_PACBTI));
22158 inst.instruction = THUMB_OP32 (inst.instruction);
22159 inst.instruction |= inst.operands[0].reg << 8;
22160 inst.instruction |= inst.operands[1].reg << 16;
22161 inst.instruction |= inst.operands[2].reg;
22165 /* Overall per-instruction processing. */
22167 /* We need to be able to fix up arbitrary expressions in some statements.
22168 This is so that we can handle symbols that are an arbitrary distance from
22169 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22170 which returns part of an address in a form which will be valid for
22171 a data instruction. We do this by pushing the expression into a symbol
22172 in the expr_section, and creating a fix for that. */
22174 static void
22175 fix_new_arm (fragS * frag,
22176 int where,
22177 short int size,
22178 expressionS * exp,
22179 int pc_rel,
22180 int reloc)
22182 fixS * new_fix;
22184 switch (exp->X_op)
22186 case O_constant:
22187 if (pc_rel)
22189 /* Create an absolute valued symbol, so we have something to
22190 refer to in the object file. Unfortunately for us, gas's
22191 generic expression parsing will already have folded out
22192 any use of .set foo/.type foo %function that may have
22193 been used to set type information of the target location,
22194 that's being specified symbolically. We have to presume
22195 the user knows what they are doing. */
22196 char name[16 + 8];
22197 symbolS *symbol;
22199 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22201 symbol = symbol_find_or_make (name);
22202 S_SET_SEGMENT (symbol, absolute_section);
22203 symbol_set_frag (symbol, &zero_address_frag);
22204 S_SET_VALUE (symbol, exp->X_add_number);
22205 exp->X_op = O_symbol;
22206 exp->X_add_symbol = symbol;
22207 exp->X_add_number = 0;
22209 /* FALLTHROUGH */
22210 case O_symbol:
22211 case O_add:
22212 case O_subtract:
22213 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
22214 (enum bfd_reloc_code_real) reloc);
22215 break;
22217 default:
22218 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
22219 pc_rel, (enum bfd_reloc_code_real) reloc);
22220 break;
22223 /* Mark whether the fix is to a THUMB instruction, or an ARM
22224 instruction. */
22225 new_fix->tc_fix_data = thumb_mode;
22228 /* Create a frg for an instruction requiring relaxation. */
22229 static void
22230 output_relax_insn (void)
22232 char * to;
22233 symbolS *sym;
22234 int offset;
22236 /* The size of the instruction is unknown, so tie the debug info to the
22237 start of the instruction. */
22238 dwarf2_emit_insn (0);
22240 switch (inst.relocs[0].exp.X_op)
22242 case O_symbol:
22243 sym = inst.relocs[0].exp.X_add_symbol;
22244 offset = inst.relocs[0].exp.X_add_number;
22245 break;
22246 case O_constant:
22247 sym = NULL;
22248 offset = inst.relocs[0].exp.X_add_number;
22249 break;
22250 default:
22251 sym = make_expr_symbol (&inst.relocs[0].exp);
22252 offset = 0;
22253 break;
22255 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22256 inst.relax, sym, offset, NULL/*offset, opcode*/);
22257 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
22260 /* Write a 32-bit thumb instruction to buf. */
22261 static void
22262 put_thumb32_insn (char * buf, unsigned long insn)
22264 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22265 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22268 static void
22269 output_inst (const char * str)
22271 char * to = NULL;
22273 if (inst.error)
22275 as_bad ("%s -- `%s'", inst.error, str);
22276 return;
22278 if (inst.relax)
22280 output_relax_insn ();
22281 return;
22283 if (inst.size == 0)
22284 return;
22286 to = frag_more (inst.size);
22287 /* PR 9814: Record the thumb mode into the current frag so that we know
22288 what type of NOP padding to use, if necessary. We override any previous
22289 setting so that if the mode has changed then the NOPS that we use will
22290 match the encoding of the last instruction in the frag. */
22291 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22293 if (thumb_mode && (inst.size > THUMB_SIZE))
22295 gas_assert (inst.size == (2 * THUMB_SIZE));
22296 put_thumb32_insn (to, inst.instruction);
22298 else if (inst.size > INSN_SIZE)
22300 gas_assert (inst.size == (2 * INSN_SIZE));
22301 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22302 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
22304 else
22305 md_number_to_chars (to, inst.instruction, inst.size);
22307 int r;
22308 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22310 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22311 fix_new_arm (frag_now, to - frag_now->fr_literal,
22312 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22313 inst.relocs[r].type);
22316 dwarf2_emit_insn (inst.size);
22319 static char *
22320 output_it_inst (int cond, int mask, char * to)
22322 unsigned long instruction = 0xbf00;
22324 mask &= 0xf;
22325 instruction |= mask;
22326 instruction |= cond << 4;
22328 if (to == NULL)
22330 to = frag_more (2);
22331 #ifdef OBJ_ELF
22332 dwarf2_emit_insn (2);
22333 #endif
22336 md_number_to_chars (to, instruction, 2);
22338 return to;
22341 /* Tag values used in struct asm_opcode's tag field. */
22342 enum opcode_tag
22344 OT_unconditional, /* Instruction cannot be conditionalized.
22345 The ARM condition field is still 0xE. */
22346 OT_unconditionalF, /* Instruction cannot be conditionalized
22347 and carries 0xF in its ARM condition field. */
22348 OT_csuffix, /* Instruction takes a conditional suffix. */
22349 OT_csuffixF, /* Some forms of the instruction take a scalar
22350 conditional suffix, others place 0xF where the
22351 condition field would be, others take a vector
22352 conditional suffix. */
22353 OT_cinfix3, /* Instruction takes a conditional infix,
22354 beginning at character index 3. (In
22355 unified mode, it becomes a suffix.) */
22356 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22357 tsts, cmps, cmns, and teqs. */
22358 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22359 character index 3, even in unified mode. Used for
22360 legacy instructions where suffix and infix forms
22361 may be ambiguous. */
22362 OT_csuf_or_in3, /* Instruction takes either a conditional
22363 suffix or an infix at character index 3. */
22364 OT_odd_infix_unc, /* This is the unconditional variant of an
22365 instruction that takes a conditional infix
22366 at an unusual position. In unified mode,
22367 this variant will accept a suffix. */
22368 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22369 are the conditional variants of instructions that
22370 take conditional infixes in unusual positions.
22371 The infix appears at character index
22372 (tag - OT_odd_infix_0). These are not accepted
22373 in unified mode. */
22376 /* Subroutine of md_assemble, responsible for looking up the primary
22377 opcode from the mnemonic the user wrote. STR points to the
22378 beginning of the mnemonic.
22380 This is not simply a hash table lookup, because of conditional
22381 variants. Most instructions have conditional variants, which are
22382 expressed with a _conditional affix_ to the mnemonic. If we were
22383 to encode each conditional variant as a literal string in the opcode
22384 table, it would have approximately 20,000 entries.
22386 Most mnemonics take this affix as a suffix, and in unified syntax,
22387 'most' is upgraded to 'all'. However, in the divided syntax, some
22388 instructions take the affix as an infix, notably the s-variants of
22389 the arithmetic instructions. Of those instructions, all but six
22390 have the infix appear after the third character of the mnemonic.
22392 Accordingly, the algorithm for looking up primary opcodes given
22393 an identifier is:
22395 1. Look up the identifier in the opcode table.
22396 If we find a match, go to step U.
22398 2. Look up the last two characters of the identifier in the
22399 conditions table. If we find a match, look up the first N-2
22400 characters of the identifier in the opcode table. If we
22401 find a match, go to step CE.
22403 3. Look up the fourth and fifth characters of the identifier in
22404 the conditions table. If we find a match, extract those
22405 characters from the identifier, and look up the remaining
22406 characters in the opcode table. If we find a match, go
22407 to step CM.
22409 4. Fail.
22411 U. Examine the tag field of the opcode structure, in case this is
22412 one of the six instructions with its conditional infix in an
22413 unusual place. If it is, the tag tells us where to find the
22414 infix; look it up in the conditions table and set inst.cond
22415 accordingly. Otherwise, this is an unconditional instruction.
22416 Again set inst.cond accordingly. Return the opcode structure.
22418 CE. Examine the tag field to make sure this is an instruction that
22419 should receive a conditional suffix. If it is not, fail.
22420 Otherwise, set inst.cond from the suffix we already looked up,
22421 and return the opcode structure.
22423 CM. Examine the tag field to make sure this is an instruction that
22424 should receive a conditional infix after the third character.
22425 If it is not, fail. Otherwise, undo the edits to the current
22426 line of input and proceed as for case CE. */
22428 static const struct asm_opcode *
22429 opcode_lookup (char **str)
22431 char *end, *base;
22432 char *affix;
22433 const struct asm_opcode *opcode;
22434 const struct asm_cond *cond;
22435 char save[2];
22437 /* Scan up to the end of the mnemonic, which must end in white space,
22438 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
22439 for (base = end = *str; *end != '\0'; end++)
22440 if (*end == ' ' || *end == '.')
22441 break;
22443 if (end == base)
22444 return NULL;
22446 /* Handle a possible width suffix and/or Neon type suffix. */
22447 if (end[0] == '.')
22449 int offset = 2;
22451 /* The .w and .n suffixes are only valid if the unified syntax is in
22452 use. */
22453 if (unified_syntax && end[1] == 'w')
22454 inst.size_req = 4;
22455 else if (unified_syntax && end[1] == 'n')
22456 inst.size_req = 2;
22457 else
22458 offset = 0;
22460 inst.vectype.elems = 0;
22462 *str = end + offset;
22464 if (end[offset] == '.')
22466 /* See if we have a Neon type suffix (possible in either unified or
22467 non-unified ARM syntax mode). */
22468 if (parse_neon_type (&inst.vectype, str) == FAIL)
22469 return NULL;
22471 else if (end[offset] != '\0' && end[offset] != ' ')
22472 return NULL;
22474 else
22475 *str = end;
22477 /* Look for unaffixed or special-case affixed mnemonic. */
22478 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22479 end - base);
22480 cond = NULL;
22481 if (opcode)
22483 /* step U */
22484 if (opcode->tag < OT_odd_infix_0)
22486 inst.cond = COND_ALWAYS;
22487 return opcode;
22490 if (warn_on_deprecated && unified_syntax)
22491 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22492 affix = base + (opcode->tag - OT_odd_infix_0);
22493 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22494 gas_assert (cond);
22496 inst.cond = cond->value;
22497 return opcode;
22499 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22501 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22503 if (end - base < 2)
22504 return NULL;
22505 affix = end - 1;
22506 cond = (const struct asm_cond *) str_hash_find_n (arm_vcond_hsh, affix, 1);
22507 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22508 affix - base);
22510 /* A known edge case is a conflict between an 'e' as a suffix for an
22511 Else of a VPT predication block and an 'ne' suffix for an IT block.
22512 If we detect that edge case here and we are not in a VPT VECTOR_PRED
22513 block, reset opcode and cond, so that the 'ne' case can be detected
22514 in the next section for 2-character conditional suffixes.
22515 An example where this is a problem is between the MVE 'vcvtn' and the
22516 non-MVE 'vcvt' instructions. */
22517 if (cond && opcode
22518 && cond->template_name[0] == 'e'
22519 && opcode->template_name[affix - base - 1] == 'n'
22520 && now_pred.type != VECTOR_PRED)
22522 opcode = NULL;
22523 cond = NULL;
22526 /* If this opcode can not be vector predicated then don't accept it with a
22527 vector predication code. */
22528 if (opcode && !opcode->mayBeVecPred)
22529 opcode = NULL;
22531 if (!opcode || !cond)
22533 /* Cannot have a conditional suffix on a mnemonic of less than two
22534 characters. */
22535 if (end - base < 3)
22536 return NULL;
22538 /* Look for suffixed mnemonic. */
22539 affix = end - 2;
22540 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22541 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22542 affix - base);
22545 if (opcode && cond)
22547 /* step CE */
22548 switch (opcode->tag)
22550 case OT_cinfix3_legacy:
22551 /* Ignore conditional suffixes matched on infix only mnemonics. */
22552 break;
22554 case OT_cinfix3:
22555 case OT_cinfix3_deprecated:
22556 case OT_odd_infix_unc:
22557 if (!unified_syntax)
22558 return NULL;
22559 /* Fall through. */
22561 case OT_csuffix:
22562 case OT_csuffixF:
22563 case OT_csuf_or_in3:
22564 inst.cond = cond->value;
22565 return opcode;
22567 case OT_unconditional:
22568 case OT_unconditionalF:
22569 if (thumb_mode)
22570 inst.cond = cond->value;
22571 else
22573 /* Delayed diagnostic. */
22574 inst.error = BAD_COND;
22575 inst.cond = COND_ALWAYS;
22577 return opcode;
22579 default:
22580 return NULL;
22584 /* Cannot have a usual-position infix on a mnemonic of less than
22585 six characters (five would be a suffix). */
22586 if (end - base < 6)
22587 return NULL;
22589 /* Look for infixed mnemonic in the usual position. */
22590 affix = base + 3;
22591 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22592 if (!cond)
22593 return NULL;
22595 memcpy (save, affix, 2);
22596 memmove (affix, affix + 2, (end - affix) - 2);
22597 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22598 (end - base) - 2);
22599 memmove (affix + 2, affix, (end - affix) - 2);
22600 memcpy (affix, save, 2);
22602 if (opcode
22603 && (opcode->tag == OT_cinfix3
22604 || opcode->tag == OT_cinfix3_deprecated
22605 || opcode->tag == OT_csuf_or_in3
22606 || opcode->tag == OT_cinfix3_legacy))
22608 /* Step CM. */
22609 if (warn_on_deprecated && unified_syntax
22610 && (opcode->tag == OT_cinfix3
22611 || opcode->tag == OT_cinfix3_deprecated))
22612 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22614 inst.cond = cond->value;
22615 return opcode;
22618 return NULL;
22621 /* This function generates an initial IT instruction, leaving its block
22622 virtually open for the new instructions. Eventually,
22623 the mask will be updated by now_pred_add_mask () each time
22624 a new instruction needs to be included in the IT block.
22625 Finally, the block is closed with close_automatic_it_block ().
22626 The block closure can be requested either from md_assemble (),
22627 a tencode (), or due to a label hook. */
22629 static void
22630 new_automatic_it_block (int cond)
22632 now_pred.state = AUTOMATIC_PRED_BLOCK;
22633 now_pred.mask = 0x18;
22634 now_pred.cc = cond;
22635 now_pred.block_length = 1;
22636 mapping_state (MAP_THUMB);
22637 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22638 now_pred.warn_deprecated = false;
22639 now_pred.insn_cond = true;
22642 /* Close an automatic IT block.
22643 See comments in new_automatic_it_block (). */
22645 static void
22646 close_automatic_it_block (void)
22648 now_pred.mask = 0x10;
22649 now_pred.block_length = 0;
22652 /* Update the mask of the current automatically-generated IT
22653 instruction. See comments in new_automatic_it_block (). */
22655 static void
22656 now_pred_add_mask (int cond)
22658 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22659 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
22660 | ((bitvalue) << (nbit)))
22661 const int resulting_bit = (cond & 1);
22663 now_pred.mask &= 0xf;
22664 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22665 resulting_bit,
22666 (5 - now_pred.block_length));
22667 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22669 ((5 - now_pred.block_length) - 1));
22670 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
22672 #undef CLEAR_BIT
22673 #undef SET_BIT_VALUE
22676 /* The IT blocks handling machinery is accessed through the these functions:
22677 it_fsm_pre_encode () from md_assemble ()
22678 set_pred_insn_type () optional, from the tencode functions
22679 set_pred_insn_type_last () ditto
22680 in_pred_block () ditto
22681 it_fsm_post_encode () from md_assemble ()
22682 force_automatic_it_block_close () from label handling functions
22684 Rationale:
22685 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
22686 initializing the IT insn type with a generic initial value depending
22687 on the inst.condition.
22688 2) During the tencode function, two things may happen:
22689 a) The tencode function overrides the IT insn type by
22690 calling either set_pred_insn_type (type) or
22691 set_pred_insn_type_last ().
22692 b) The tencode function queries the IT block state by
22693 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
22695 Both set_pred_insn_type and in_pred_block run the internal FSM state
22696 handling function (handle_pred_state), because: a) setting the IT insn
22697 type may incur in an invalid state (exiting the function),
22698 and b) querying the state requires the FSM to be updated.
22699 Specifically we want to avoid creating an IT block for conditional
22700 branches, so it_fsm_pre_encode is actually a guess and we can't
22701 determine whether an IT block is required until the tencode () routine
22702 has decided what type of instruction this actually it.
22703 Because of this, if set_pred_insn_type and in_pred_block have to be
22704 used, set_pred_insn_type has to be called first.
22706 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22707 that determines the insn IT type depending on the inst.cond code.
22708 When a tencode () routine encodes an instruction that can be
22709 either outside an IT block, or, in the case of being inside, has to be
22710 the last one, set_pred_insn_type_last () will determine the proper
22711 IT instruction type based on the inst.cond code. Otherwise,
22712 set_pred_insn_type can be called for overriding that logic or
22713 for covering other cases.
22715 Calling handle_pred_state () may not transition the IT block state to
22716 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
22717 still queried. Instead, if the FSM determines that the state should
22718 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
22719 after the tencode () function: that's what it_fsm_post_encode () does.
22721 Since in_pred_block () calls the state handling function to get an
22722 updated state, an error may occur (due to invalid insns combination).
22723 In that case, inst.error is set.
22724 Therefore, inst.error has to be checked after the execution of
22725 the tencode () routine.
22727 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
22728 any pending state change (if any) that didn't take place in
22729 handle_pred_state () as explained above. */
22731 static void
22732 it_fsm_pre_encode (void)
22734 if (inst.cond != COND_ALWAYS)
22735 inst.pred_insn_type = INSIDE_IT_INSN;
22736 else
22737 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22739 now_pred.state_handled = 0;
22742 /* IT state FSM handling function. */
22743 /* MVE instructions and non-MVE instructions are handled differently because of
22744 the introduction of VPT blocks.
22745 Specifications say that any non-MVE instruction inside a VPT block is
22746 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22747 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
22748 few exceptions we have MVE_UNPREDICABLE_INSN.
22749 The error messages provided depending on the different combinations possible
22750 are described in the cases below:
22751 For 'most' MVE instructions:
22752 1) In an IT block, with an IT code: syntax error
22753 2) In an IT block, with a VPT code: error: must be in a VPT block
22754 3) In an IT block, with no code: warning: UNPREDICTABLE
22755 4) In a VPT block, with an IT code: syntax error
22756 5) In a VPT block, with a VPT code: OK!
22757 6) In a VPT block, with no code: error: missing code
22758 7) Outside a pred block, with an IT code: error: syntax error
22759 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22760 9) Outside a pred block, with no code: OK!
22761 For non-MVE instructions:
22762 10) In an IT block, with an IT code: OK!
22763 11) In an IT block, with a VPT code: syntax error
22764 12) In an IT block, with no code: error: missing code
22765 13) In a VPT block, with an IT code: error: should be in an IT block
22766 14) In a VPT block, with a VPT code: syntax error
22767 15) In a VPT block, with no code: UNPREDICTABLE
22768 16) Outside a pred block, with an IT code: error: should be in an IT block
22769 17) Outside a pred block, with a VPT code: syntax error
22770 18) Outside a pred block, with no code: OK!
22774 static int
22775 handle_pred_state (void)
22777 now_pred.state_handled = 1;
22778 now_pred.insn_cond = false;
22780 switch (now_pred.state)
22782 case OUTSIDE_PRED_BLOCK:
22783 switch (inst.pred_insn_type)
22785 case MVE_UNPREDICABLE_INSN:
22786 case MVE_OUTSIDE_PRED_INSN:
22787 if (inst.cond < COND_ALWAYS)
22789 /* Case 7: Outside a pred block, with an IT code: error: syntax
22790 error. */
22791 inst.error = BAD_SYNTAX;
22792 return FAIL;
22794 /* Case 9: Outside a pred block, with no code: OK! */
22795 break;
22796 case OUTSIDE_PRED_INSN:
22797 if (inst.cond > COND_ALWAYS)
22799 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22801 inst.error = BAD_SYNTAX;
22802 return FAIL;
22804 /* Case 18: Outside a pred block, with no code: OK! */
22805 break;
22807 case INSIDE_VPT_INSN:
22808 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22809 a VPT block. */
22810 inst.error = BAD_OUT_VPT;
22811 return FAIL;
22813 case INSIDE_IT_INSN:
22814 case INSIDE_IT_LAST_INSN:
22815 if (inst.cond < COND_ALWAYS)
22817 /* Case 16: Outside a pred block, with an IT code: error: should
22818 be in an IT block. */
22819 if (thumb_mode == 0)
22821 if (unified_syntax
22822 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22823 as_tsktsk (_("Warning: conditional outside an IT block"\
22824 " for Thumb."));
22826 else
22828 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22829 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22831 /* Automatically generate the IT instruction. */
22832 new_automatic_it_block (inst.cond);
22833 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22834 close_automatic_it_block ();
22836 else
22838 inst.error = BAD_OUT_IT;
22839 return FAIL;
22842 break;
22844 else if (inst.cond > COND_ALWAYS)
22846 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22848 inst.error = BAD_SYNTAX;
22849 return FAIL;
22851 else
22852 gas_assert (0);
22853 case IF_INSIDE_IT_LAST_INSN:
22854 case NEUTRAL_IT_INSN:
22855 break;
22857 case VPT_INSN:
22858 if (inst.cond != COND_ALWAYS)
22859 first_error (BAD_SYNTAX);
22860 now_pred.state = MANUAL_PRED_BLOCK;
22861 now_pred.block_length = 0;
22862 now_pred.type = VECTOR_PRED;
22863 now_pred.cc = 0;
22864 break;
22865 case IT_INSN:
22866 now_pred.state = MANUAL_PRED_BLOCK;
22867 now_pred.block_length = 0;
22868 now_pred.type = SCALAR_PRED;
22869 break;
22871 break;
22873 case AUTOMATIC_PRED_BLOCK:
22874 /* Three things may happen now:
22875 a) We should increment current it block size;
22876 b) We should close current it block (closing insn or 4 insns);
22877 c) We should close current it block and start a new one (due
22878 to incompatible conditions or
22879 4 insns-length block reached). */
22881 switch (inst.pred_insn_type)
22883 case INSIDE_VPT_INSN:
22884 case VPT_INSN:
22885 case MVE_UNPREDICABLE_INSN:
22886 case MVE_OUTSIDE_PRED_INSN:
22887 gas_assert (0);
22888 case OUTSIDE_PRED_INSN:
22889 /* The closure of the block shall happen immediately,
22890 so any in_pred_block () call reports the block as closed. */
22891 force_automatic_it_block_close ();
22892 break;
22894 case INSIDE_IT_INSN:
22895 case INSIDE_IT_LAST_INSN:
22896 case IF_INSIDE_IT_LAST_INSN:
22897 now_pred.block_length++;
22899 if (now_pred.block_length > 4
22900 || !now_pred_compatible (inst.cond))
22902 force_automatic_it_block_close ();
22903 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
22904 new_automatic_it_block (inst.cond);
22906 else
22908 now_pred.insn_cond = true;
22909 now_pred_add_mask (inst.cond);
22912 if (now_pred.state == AUTOMATIC_PRED_BLOCK
22913 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
22914 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
22915 close_automatic_it_block ();
22916 break;
22918 /* Fallthrough. */
22919 case NEUTRAL_IT_INSN:
22920 now_pred.block_length++;
22921 now_pred.insn_cond = true;
22923 if (now_pred.block_length > 4)
22924 force_automatic_it_block_close ();
22925 else
22926 now_pred_add_mask (now_pred.cc & 1);
22927 break;
22929 case IT_INSN:
22930 close_automatic_it_block ();
22931 now_pred.state = MANUAL_PRED_BLOCK;
22932 break;
22934 break;
22936 case MANUAL_PRED_BLOCK:
22938 unsigned int cond;
22939 int is_last;
22940 if (now_pred.type == SCALAR_PRED)
22942 /* Check conditional suffixes. */
22943 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
22944 now_pred.mask <<= 1;
22945 now_pred.mask &= 0x1f;
22946 is_last = (now_pred.mask == 0x10);
22948 else
22950 now_pred.cc ^= (now_pred.mask >> 4);
22951 cond = now_pred.cc + 0xf;
22952 now_pred.mask <<= 1;
22953 now_pred.mask &= 0x1f;
22954 is_last = now_pred.mask == 0x10;
22956 now_pred.insn_cond = true;
22958 switch (inst.pred_insn_type)
22960 case OUTSIDE_PRED_INSN:
22961 if (now_pred.type == SCALAR_PRED)
22963 if (inst.cond == COND_ALWAYS)
22965 /* Case 12: In an IT block, with no code: error: missing
22966 code. */
22967 inst.error = BAD_NOT_IT;
22968 return FAIL;
22970 else if (inst.cond > COND_ALWAYS)
22972 /* Case 11: In an IT block, with a VPT code: syntax error.
22974 inst.error = BAD_SYNTAX;
22975 return FAIL;
22977 else if (thumb_mode)
22979 /* This is for some special cases where a non-MVE
22980 instruction is not allowed in an IT block, such as cbz,
22981 but are put into one with a condition code.
22982 You could argue this should be a syntax error, but we
22983 gave the 'not allowed in IT block' diagnostic in the
22984 past so we will keep doing so. */
22985 inst.error = BAD_NOT_IT;
22986 return FAIL;
22988 break;
22990 else
22992 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
22993 as_tsktsk (MVE_NOT_VPT);
22994 return SUCCESS;
22996 case MVE_OUTSIDE_PRED_INSN:
22997 if (now_pred.type == SCALAR_PRED)
22999 if (inst.cond == COND_ALWAYS)
23001 /* Case 3: In an IT block, with no code: warning:
23002 UNPREDICTABLE. */
23003 as_tsktsk (MVE_NOT_IT);
23004 return SUCCESS;
23006 else if (inst.cond < COND_ALWAYS)
23008 /* Case 1: In an IT block, with an IT code: syntax error.
23010 inst.error = BAD_SYNTAX;
23011 return FAIL;
23013 else
23014 gas_assert (0);
23016 else
23018 if (inst.cond < COND_ALWAYS)
23020 /* Case 4: In a VPT block, with an IT code: syntax error.
23022 inst.error = BAD_SYNTAX;
23023 return FAIL;
23025 else if (inst.cond == COND_ALWAYS)
23027 /* Case 6: In a VPT block, with no code: error: missing
23028 code. */
23029 inst.error = BAD_NOT_VPT;
23030 return FAIL;
23032 else
23034 gas_assert (0);
23037 case MVE_UNPREDICABLE_INSN:
23038 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23039 return SUCCESS;
23040 case INSIDE_IT_INSN:
23041 if (inst.cond > COND_ALWAYS)
23043 /* Case 11: In an IT block, with a VPT code: syntax error. */
23044 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23045 inst.error = BAD_SYNTAX;
23046 return FAIL;
23048 else if (now_pred.type == SCALAR_PRED)
23050 /* Case 10: In an IT block, with an IT code: OK! */
23051 if (cond != inst.cond)
23053 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23054 BAD_VPT_COND;
23055 return FAIL;
23058 else
23060 /* Case 13: In a VPT block, with an IT code: error: should be
23061 in an IT block. */
23062 inst.error = BAD_OUT_IT;
23063 return FAIL;
23065 break;
23067 case INSIDE_VPT_INSN:
23068 if (now_pred.type == SCALAR_PRED)
23070 /* Case 2: In an IT block, with a VPT code: error: must be in a
23071 VPT block. */
23072 inst.error = BAD_OUT_VPT;
23073 return FAIL;
23075 /* Case 5: In a VPT block, with a VPT code: OK! */
23076 else if (cond != inst.cond)
23078 inst.error = BAD_VPT_COND;
23079 return FAIL;
23081 break;
23082 case INSIDE_IT_LAST_INSN:
23083 case IF_INSIDE_IT_LAST_INSN:
23084 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23086 /* Case 4: In a VPT block, with an IT code: syntax error. */
23087 /* Case 11: In an IT block, with a VPT code: syntax error. */
23088 inst.error = BAD_SYNTAX;
23089 return FAIL;
23091 else if (cond != inst.cond)
23093 inst.error = BAD_IT_COND;
23094 return FAIL;
23096 if (!is_last)
23098 inst.error = BAD_BRANCH;
23099 return FAIL;
23101 break;
23103 case NEUTRAL_IT_INSN:
23104 /* The BKPT instruction is unconditional even in a IT or VPT
23105 block. */
23106 break;
23108 case IT_INSN:
23109 if (now_pred.type == SCALAR_PRED)
23111 inst.error = BAD_IT_IT;
23112 return FAIL;
23114 /* fall through. */
23115 case VPT_INSN:
23116 if (inst.cond == COND_ALWAYS)
23118 /* Executing a VPT/VPST instruction inside an IT block or a
23119 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23121 if (now_pred.type == SCALAR_PRED)
23122 as_tsktsk (MVE_NOT_IT);
23123 else
23124 as_tsktsk (MVE_NOT_VPT);
23125 return SUCCESS;
23127 else
23129 /* VPT/VPST do not accept condition codes. */
23130 inst.error = BAD_SYNTAX;
23131 return FAIL;
23135 break;
23138 return SUCCESS;
23141 struct depr_insn_mask
23143 unsigned long pattern;
23144 unsigned long mask;
23145 const char* description;
23148 /* List of 16-bit instruction patterns deprecated in an IT block in
23149 ARMv8. */
23150 static const struct depr_insn_mask depr_it_insns[] = {
23151 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23152 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23153 { 0xa000, 0xb800, N_("ADR") },
23154 { 0x4800, 0xf800, N_("Literal loads") },
23155 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23156 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
23157 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23158 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23159 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
23160 { 0, 0, NULL }
23163 static void
23164 it_fsm_post_encode (void)
23166 int is_last;
23168 if (!now_pred.state_handled)
23169 handle_pred_state ();
23171 if (now_pred.insn_cond
23172 && warn_on_restrict_it
23173 && !now_pred.warn_deprecated
23174 && warn_on_deprecated
23175 && (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23176 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8r))
23177 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
23179 if (inst.instruction >= 0x10000)
23181 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
23182 "performance deprecated in ARMv8-A and ARMv8-R"));
23183 now_pred.warn_deprecated = true;
23185 else
23187 const struct depr_insn_mask *p = depr_it_insns;
23189 while (p->mask != 0)
23191 if ((inst.instruction & p->mask) == p->pattern)
23193 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23194 "instructions of the following class are "
23195 "performance deprecated in ARMv8-A and "
23196 "ARMv8-R: %s"), p->description);
23197 now_pred.warn_deprecated = true;
23198 break;
23201 ++p;
23205 if (now_pred.block_length > 1)
23207 as_tsktsk (_("IT blocks containing more than one conditional "
23208 "instruction are performance deprecated in ARMv8-A and "
23209 "ARMv8-R"));
23210 now_pred.warn_deprecated = true;
23214 is_last = (now_pred.mask == 0x10);
23215 if (is_last)
23217 now_pred.state = OUTSIDE_PRED_BLOCK;
23218 now_pred.mask = 0;
23222 static void
23223 force_automatic_it_block_close (void)
23225 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
23227 close_automatic_it_block ();
23228 now_pred.state = OUTSIDE_PRED_BLOCK;
23229 now_pred.mask = 0;
23233 static int
23234 in_pred_block (void)
23236 if (!now_pred.state_handled)
23237 handle_pred_state ();
23239 return now_pred.state != OUTSIDE_PRED_BLOCK;
23242 /* Whether OPCODE only has T32 encoding. Since this function is only used by
23243 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23244 here, hence the "known" in the function name. */
23246 static bool
23247 known_t32_only_insn (const struct asm_opcode *opcode)
23249 /* Original Thumb-1 wide instruction. */
23250 if (opcode->tencode == do_t_blx
23251 || opcode->tencode == do_t_branch23
23252 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23253 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23254 return true;
23256 /* Wide-only instruction added to ARMv8-M Baseline. */
23257 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
23258 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23259 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23260 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23261 return true;
23263 return false;
23266 /* Whether wide instruction variant can be used if available for a valid OPCODE
23267 in ARCH. */
23269 static bool
23270 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23272 if (known_t32_only_insn (opcode))
23273 return true;
23275 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23276 of variant T3 of B.W is checked in do_t_branch. */
23277 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23278 && opcode->tencode == do_t_branch)
23279 return true;
23281 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23282 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23283 && opcode->tencode == do_t_mov_cmp
23284 /* Make sure CMP instruction is not affected. */
23285 && opcode->aencode == do_mov)
23286 return true;
23288 /* Wide instruction variants of all instructions with narrow *and* wide
23289 variants become available with ARMv6t2. Other opcodes are either
23290 narrow-only or wide-only and are thus available if OPCODE is valid. */
23291 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23292 return true;
23294 /* OPCODE with narrow only instruction variant or wide variant not
23295 available. */
23296 return false;
23299 void
23300 md_assemble (char *str)
23302 char *p = str;
23303 const struct asm_opcode * opcode;
23305 /* Align the previous label if needed. */
23306 if (last_label_seen != NULL)
23308 symbol_set_frag (last_label_seen, frag_now);
23309 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23310 S_SET_SEGMENT (last_label_seen, now_seg);
23313 memset (&inst, '\0', sizeof (inst));
23314 int r;
23315 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23316 inst.relocs[r].type = BFD_RELOC_UNUSED;
23318 opcode = opcode_lookup (&p);
23319 if (!opcode)
23321 /* It wasn't an instruction, but it might be a register alias of
23322 the form alias .req reg, or a Neon .dn/.qn directive. */
23323 if (! create_register_alias (str, p)
23324 && ! create_neon_reg_alias (str, p))
23325 as_bad (_("bad instruction `%s'"), str);
23327 return;
23330 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
23331 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
23333 /* The value which unconditional instructions should have in place of the
23334 condition field. */
23335 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1u;
23337 if (thumb_mode)
23339 arm_feature_set variant;
23341 variant = cpu_variant;
23342 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
23343 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23344 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
23345 /* Check that this instruction is supported for this CPU. */
23346 if (!opcode->tvariant
23347 || (thumb_mode == 1
23348 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
23350 if (opcode->tencode == do_t_swi)
23351 as_bad (_("SVC is not permitted on this architecture"));
23352 else
23353 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
23354 return;
23356 if (inst.cond != COND_ALWAYS && !unified_syntax
23357 && opcode->tencode != do_t_branch)
23359 as_bad (_("Thumb does not support conditional execution"));
23360 return;
23363 /* Two things are addressed here:
23364 1) Implicit require narrow instructions on Thumb-1.
23365 This avoids relaxation accidentally introducing Thumb-2
23366 instructions.
23367 2) Reject wide instructions in non Thumb-2 cores.
23369 Only instructions with narrow and wide variants need to be handled
23370 but selecting all non wide-only instructions is easier. */
23371 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
23372 && !t32_insn_ok (variant, opcode))
23374 if (inst.size_req == 0)
23375 inst.size_req = 2;
23376 else if (inst.size_req == 4)
23378 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23379 as_bad (_("selected processor does not support 32bit wide "
23380 "variant of instruction `%s'"), str);
23381 else
23382 as_bad (_("selected processor does not support `%s' in "
23383 "Thumb-2 mode"), str);
23384 return;
23388 inst.instruction = opcode->tvalue;
23390 if (!parse_operands (p, opcode->operands, /*thumb=*/true))
23392 /* Prepare the pred_insn_type for those encodings that don't set
23393 it. */
23394 it_fsm_pre_encode ();
23396 opcode->tencode ();
23398 it_fsm_post_encode ();
23401 if (!(inst.error || inst.relax))
23403 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
23404 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23405 if (inst.size_req && inst.size_req != inst.size)
23407 as_bad (_("cannot honor width suffix -- `%s'"), str);
23408 return;
23412 /* Something has gone badly wrong if we try to relax a fixed size
23413 instruction. */
23414 gas_assert (inst.size_req == 0 || !inst.relax);
23416 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23417 *opcode->tvariant);
23418 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
23419 set those bits when Thumb-2 32-bit instructions are seen. The impact
23420 of relaxable instructions will be considered later after we finish all
23421 relaxation. */
23422 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23423 variant = arm_arch_none;
23424 else
23425 variant = cpu_variant;
23426 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
23427 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23428 arm_ext_v6t2);
23430 check_neon_suffixes;
23432 if (!inst.error)
23434 mapping_state (MAP_THUMB);
23437 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23439 bool is_bx;
23441 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23442 is_bx = (opcode->aencode == do_bx);
23444 /* Check that this instruction is supported for this CPU. */
23445 if (!(is_bx && fix_v4bx)
23446 && !(opcode->avariant &&
23447 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
23449 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
23450 return;
23452 if (inst.size_req)
23454 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23455 return;
23458 inst.instruction = opcode->avalue;
23459 if (opcode->tag == OT_unconditionalF)
23460 inst.instruction |= 0xFU << 28;
23461 else
23462 inst.instruction |= inst.cond << 28;
23463 inst.size = INSN_SIZE;
23464 if (!parse_operands (p, opcode->operands, /*thumb=*/false))
23466 it_fsm_pre_encode ();
23467 opcode->aencode ();
23468 it_fsm_post_encode ();
23470 /* Arm mode bx is marked as both v4T and v5 because it's still required
23471 on a hypothetical non-thumb v5 core. */
23472 if (is_bx)
23473 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
23474 else
23475 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23476 *opcode->avariant);
23478 check_neon_suffixes;
23480 if (!inst.error)
23482 mapping_state (MAP_ARM);
23485 else
23487 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23488 "-- `%s'"), str);
23489 return;
23491 output_inst (str);
23494 static void
23495 check_pred_blocks_finished (void)
23497 #ifdef OBJ_ELF
23498 asection *sect;
23500 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
23501 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23502 == MANUAL_PRED_BLOCK)
23504 if (now_pred.type == SCALAR_PRED)
23505 as_warn (_("section '%s' finished with an open IT block."),
23506 sect->name);
23507 else
23508 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23509 sect->name);
23511 #else
23512 if (now_pred.state == MANUAL_PRED_BLOCK)
23514 if (now_pred.type == SCALAR_PRED)
23515 as_warn (_("file finished with an open IT block."));
23516 else
23517 as_warn (_("file finished with an open VPT/VPST block."));
23519 #endif
23522 /* Various frobbings of labels and their addresses. */
23524 void
23525 arm_start_line_hook (void)
23527 last_label_seen = NULL;
23530 void
23531 arm_frob_label (symbolS * sym)
23533 last_label_seen = sym;
23535 ARM_SET_THUMB (sym, thumb_mode);
23537 #if defined OBJ_COFF || defined OBJ_ELF
23538 ARM_SET_INTERWORK (sym, support_interwork);
23539 #endif
23541 force_automatic_it_block_close ();
23543 /* Note - do not allow local symbols (.Lxxx) to be labelled
23544 as Thumb functions. This is because these labels, whilst
23545 they exist inside Thumb code, are not the entry points for
23546 possible ARM->Thumb calls. Also, these labels can be used
23547 as part of a computed goto or switch statement. eg gcc
23548 can generate code that looks like this:
23550 ldr r2, [pc, .Laaa]
23551 lsl r3, r3, #2
23552 ldr r2, [r3, r2]
23553 mov pc, r2
23555 .Lbbb: .word .Lxxx
23556 .Lccc: .word .Lyyy
23557 ..etc...
23558 .Laaa: .word Lbbb
23560 The first instruction loads the address of the jump table.
23561 The second instruction converts a table index into a byte offset.
23562 The third instruction gets the jump address out of the table.
23563 The fourth instruction performs the jump.
23565 If the address stored at .Laaa is that of a symbol which has the
23566 Thumb_Func bit set, then the linker will arrange for this address
23567 to have the bottom bit set, which in turn would mean that the
23568 address computation performed by the third instruction would end
23569 up with the bottom bit set. Since the ARM is capable of unaligned
23570 word loads, the instruction would then load the incorrect address
23571 out of the jump table, and chaos would ensue. */
23572 if (label_is_thumb_function_name
23573 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
23574 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
23576 /* When the address of a Thumb function is taken the bottom
23577 bit of that address should be set. This will allow
23578 interworking between Arm and Thumb functions to work
23579 correctly. */
23581 THUMB_SET_FUNC (sym, 1);
23583 label_is_thumb_function_name = false;
23586 dwarf2_emit_label (sym);
23589 bool
23590 arm_data_in_code (void)
23592 if (thumb_mode && startswith (input_line_pointer + 1, "data:"))
23594 *input_line_pointer = '/';
23595 input_line_pointer += 5;
23596 *input_line_pointer = 0;
23597 return true;
23600 return false;
23603 char *
23604 arm_canonicalize_symbol_name (char * name)
23606 int len;
23608 if (thumb_mode && (len = strlen (name)) > 5
23609 && streq (name + len - 5, "/data"))
23610 *(name + len - 5) = 0;
23612 return name;
23615 /* Table of all register names defined by default. The user can
23616 define additional names with .req. Note that all register names
23617 should appear in both upper and lowercase variants. Some registers
23618 also have mixed-case names. */
23620 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, true, 0 }
23621 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
23622 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
23623 #define REGSET(p,t) \
23624 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23625 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23626 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23627 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
23628 #define REGSETH(p,t) \
23629 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23630 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23631 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23632 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23633 #define REGSET2(p,t) \
23634 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23635 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23636 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23637 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
23638 #define SPLRBANK(base,bank,t) \
23639 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23640 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23641 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23642 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23643 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23644 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
23646 static const struct reg_entry reg_names[] =
23648 /* ARM integer registers. */
23649 REGSET(r, RN), REGSET(R, RN),
23651 /* ATPCS synonyms. */
23652 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23653 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23654 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
23656 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23657 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23658 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
23660 /* Well-known aliases. */
23661 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23662 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23664 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23665 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23667 /* Defining the new Zero register from ARMv8.1-M. */
23668 REGDEF(zr,15,ZR),
23669 REGDEF(ZR,15,ZR),
23671 /* Coprocessor numbers. */
23672 REGSET(p, CP), REGSET(P, CP),
23674 /* Coprocessor register numbers. The "cr" variants are for backward
23675 compatibility. */
23676 REGSET(c, CN), REGSET(C, CN),
23677 REGSET(cr, CN), REGSET(CR, CN),
23679 /* ARM banked registers. */
23680 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23681 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23682 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23683 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23684 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23685 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23686 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23688 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23689 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23690 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23691 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23692 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
23693 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
23694 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23695 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23697 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23698 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23699 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23700 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23701 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23702 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23703 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
23704 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
23705 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23707 /* VFP SP registers. */
23708 REGSET(s,VFS), REGSET(S,VFS),
23709 REGSETH(s,VFS), REGSETH(S,VFS),
23711 /* VFP DP Registers. */
23712 REGSET(d,VFD), REGSET(D,VFD),
23713 /* Extra Neon DP registers. */
23714 REGSETH(d,VFD), REGSETH(D,VFD),
23716 /* Neon QP registers. */
23717 REGSET2(q,NQ), REGSET2(Q,NQ),
23719 /* VFP control registers. */
23720 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23721 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
23722 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23723 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23724 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23725 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
23726 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
23727 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23728 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23729 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23730 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
23731 REGDEF(fpcxtns,14,VFC), REGDEF(FPCXTNS,14,VFC),
23732 REGDEF(fpcxts,15,VFC), REGDEF(FPCXTS,15,VFC),
23734 /* iWMMXt data registers - p0, c0-15. */
23735 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23737 /* iWMMXt control registers - p1, c0-3. */
23738 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23739 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23740 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23741 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23743 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23744 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23745 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23746 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23747 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23749 /* XScale accumulator registers. */
23750 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23752 /* DWARF ABI defines RA_AUTH_CODE to 143. */
23753 REGDEF(ra_auth_code,143,PSEUDO),
23755 #undef REGDEF
23756 #undef REGNUM
23757 #undef REGSET
23759 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23760 within psr_required_here. */
23761 static const struct asm_psr psrs[] =
23763 /* Backward compatibility notation. Note that "all" is no longer
23764 truly all possible PSR bits. */
23765 {"all", PSR_c | PSR_f},
23766 {"flg", PSR_f},
23767 {"ctl", PSR_c},
23769 /* Individual flags. */
23770 {"f", PSR_f},
23771 {"c", PSR_c},
23772 {"x", PSR_x},
23773 {"s", PSR_s},
23775 /* Combinations of flags. */
23776 {"fs", PSR_f | PSR_s},
23777 {"fx", PSR_f | PSR_x},
23778 {"fc", PSR_f | PSR_c},
23779 {"sf", PSR_s | PSR_f},
23780 {"sx", PSR_s | PSR_x},
23781 {"sc", PSR_s | PSR_c},
23782 {"xf", PSR_x | PSR_f},
23783 {"xs", PSR_x | PSR_s},
23784 {"xc", PSR_x | PSR_c},
23785 {"cf", PSR_c | PSR_f},
23786 {"cs", PSR_c | PSR_s},
23787 {"cx", PSR_c | PSR_x},
23788 {"fsx", PSR_f | PSR_s | PSR_x},
23789 {"fsc", PSR_f | PSR_s | PSR_c},
23790 {"fxs", PSR_f | PSR_x | PSR_s},
23791 {"fxc", PSR_f | PSR_x | PSR_c},
23792 {"fcs", PSR_f | PSR_c | PSR_s},
23793 {"fcx", PSR_f | PSR_c | PSR_x},
23794 {"sfx", PSR_s | PSR_f | PSR_x},
23795 {"sfc", PSR_s | PSR_f | PSR_c},
23796 {"sxf", PSR_s | PSR_x | PSR_f},
23797 {"sxc", PSR_s | PSR_x | PSR_c},
23798 {"scf", PSR_s | PSR_c | PSR_f},
23799 {"scx", PSR_s | PSR_c | PSR_x},
23800 {"xfs", PSR_x | PSR_f | PSR_s},
23801 {"xfc", PSR_x | PSR_f | PSR_c},
23802 {"xsf", PSR_x | PSR_s | PSR_f},
23803 {"xsc", PSR_x | PSR_s | PSR_c},
23804 {"xcf", PSR_x | PSR_c | PSR_f},
23805 {"xcs", PSR_x | PSR_c | PSR_s},
23806 {"cfs", PSR_c | PSR_f | PSR_s},
23807 {"cfx", PSR_c | PSR_f | PSR_x},
23808 {"csf", PSR_c | PSR_s | PSR_f},
23809 {"csx", PSR_c | PSR_s | PSR_x},
23810 {"cxf", PSR_c | PSR_x | PSR_f},
23811 {"cxs", PSR_c | PSR_x | PSR_s},
23812 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23813 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23814 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23815 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23816 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23817 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23818 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23819 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23820 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23821 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23822 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23823 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23824 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23825 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23826 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23827 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23828 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23829 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23830 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23831 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23832 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23833 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23834 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23835 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23838 /* Table of V7M psr names. */
23839 static const struct asm_psr v7m_psrs[] =
23841 {"apsr", 0x0 }, {"APSR", 0x0 },
23842 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23843 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23844 {"psr", 0x3 }, {"PSR", 0x3 },
23845 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23846 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23847 {"epsr", 0x6 }, {"EPSR", 0x6 },
23848 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23849 {"msp", 0x8 }, {"MSP", 0x8 },
23850 {"psp", 0x9 }, {"PSP", 0x9 },
23851 {"msplim", 0xa }, {"MSPLIM", 0xa },
23852 {"psplim", 0xb }, {"PSPLIM", 0xb },
23853 {"primask", 0x10}, {"PRIMASK", 0x10},
23854 {"basepri", 0x11}, {"BASEPRI", 0x11},
23855 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
23856 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
23857 {"control", 0x14}, {"CONTROL", 0x14},
23858 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
23859 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
23860 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
23861 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
23862 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
23863 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
23864 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
23865 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
23866 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
23869 /* Table of all shift-in-operand names. */
23870 static const struct asm_shift_name shift_names [] =
23872 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
23873 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
23874 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
23875 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
23876 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
23877 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
23878 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
23881 /* Table of all explicit relocation names. */
23882 #ifdef OBJ_ELF
23883 static struct reloc_entry reloc_names[] =
23885 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
23886 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
23887 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
23888 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
23889 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
23890 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
23891 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
23892 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
23893 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
23894 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
23895 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
23896 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
23897 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
23898 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
23899 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
23900 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
23901 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
23902 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
23903 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
23904 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
23905 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23906 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23907 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
23908 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
23909 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
23910 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
23911 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
23913 #endif
23915 /* Table of all conditional affixes. */
23916 static const struct asm_cond conds[] =
23918 {"eq", 0x0},
23919 {"ne", 0x1},
23920 {"cs", 0x2}, {"hs", 0x2},
23921 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
23922 {"mi", 0x4},
23923 {"pl", 0x5},
23924 {"vs", 0x6},
23925 {"vc", 0x7},
23926 {"hi", 0x8},
23927 {"ls", 0x9},
23928 {"ge", 0xa},
23929 {"lt", 0xb},
23930 {"gt", 0xc},
23931 {"le", 0xd},
23932 {"al", 0xe}
23934 static const struct asm_cond vconds[] =
23936 {"t", 0xf},
23937 {"e", 0x10}
23940 #define UL_BARRIER(L,U,CODE,FEAT) \
23941 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
23942 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
23944 static struct asm_barrier_opt barrier_opt_names[] =
23946 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
23947 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
23948 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
23949 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
23950 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
23951 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
23952 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
23953 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
23954 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
23955 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
23956 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
23957 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
23958 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
23959 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
23960 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
23961 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
23964 #undef UL_BARRIER
23966 /* Table of ARM-format instructions. */
23968 /* Macros for gluing together operand strings. N.B. In all cases
23969 other than OPS0, the trailing OP_stop comes from default
23970 zero-initialization of the unspecified elements of the array. */
23971 #define OPS0() { OP_stop, }
23972 #define OPS1(a) { OP_##a, }
23973 #define OPS2(a,b) { OP_##a,OP_##b, }
23974 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
23975 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
23976 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
23977 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
23979 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
23980 This is useful when mixing operands for ARM and THUMB, i.e. using the
23981 MIX_ARM_THUMB_OPERANDS macro.
23982 In order to use these macros, prefix the number of operands with _
23983 e.g. _3. */
23984 #define OPS_1(a) { a, }
23985 #define OPS_2(a,b) { a,b, }
23986 #define OPS_3(a,b,c) { a,b,c, }
23987 #define OPS_4(a,b,c,d) { a,b,c,d, }
23988 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
23989 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
23991 /* These macros abstract out the exact format of the mnemonic table and
23992 save some repeated characters. */
23994 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
23995 #define TxCE(mnem, op, top, nops, ops, ae, te) \
23996 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
23997 THUMB_VARIANT, do_##ae, do_##te, 0 }
23999 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24000 a T_MNEM_xyz enumerator. */
24001 #define TCE(mnem, aop, top, nops, ops, ae, te) \
24002 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
24003 #define tCE(mnem, aop, top, nops, ops, ae, te) \
24004 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24006 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24007 infix after the third character. */
24008 #define TxC3(mnem, op, top, nops, ops, ae, te) \
24009 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
24010 THUMB_VARIANT, do_##ae, do_##te, 0 }
24011 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
24012 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
24013 THUMB_VARIANT, do_##ae, do_##te, 0 }
24014 #define TC3(mnem, aop, top, nops, ops, ae, te) \
24015 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
24016 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
24017 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
24018 #define tC3(mnem, aop, top, nops, ops, ae, te) \
24019 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24020 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
24021 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24023 /* Mnemonic that cannot be conditionalized. The ARM condition-code
24024 field is still 0xE. Many of the Thumb variants can be executed
24025 conditionally, so this is checked separately. */
24026 #define TUE(mnem, op, top, nops, ops, ae, te) \
24027 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24028 THUMB_VARIANT, do_##ae, do_##te, 0 }
24030 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24031 Used by mnemonics that have very minimal differences in the encoding for
24032 ARM and Thumb variants and can be handled in a common function. */
24033 #define TUEc(mnem, op, top, nops, ops, en) \
24034 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24035 THUMB_VARIANT, do_##en, do_##en, 0 }
24037 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24038 condition code field. */
24039 #define TUF(mnem, op, top, nops, ops, ae, te) \
24040 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
24041 THUMB_VARIANT, do_##ae, do_##te, 0 }
24043 /* ARM-only variants of all the above. */
24044 #define CE(mnem, op, nops, ops, ae) \
24045 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24047 #define C3(mnem, op, nops, ops, ae) \
24048 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24050 /* Thumb-only variants of TCE and TUE. */
24051 #define ToC(mnem, top, nops, ops, te) \
24052 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24053 do_##te, 0 }
24055 #define ToU(mnem, top, nops, ops, te) \
24056 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
24057 NULL, do_##te, 0 }
24059 /* T_MNEM_xyz enumerator variants of ToC. */
24060 #define toC(mnem, top, nops, ops, te) \
24061 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
24062 do_##te, 0 }
24064 /* T_MNEM_xyz enumerator variants of ToU. */
24065 #define toU(mnem, top, nops, ops, te) \
24066 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
24067 NULL, do_##te, 0 }
24069 /* Legacy mnemonics that always have conditional infix after the third
24070 character. */
24071 #define CL(mnem, op, nops, ops, ae) \
24072 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24073 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24075 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24076 #define cCE(mnem, op, nops, ops, ae) \
24077 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24079 /* mov instructions that are shared between coprocessor and MVE. */
24080 #define mcCE(mnem, op, nops, ops, ae) \
24081 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24083 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
24084 { m1 #m2 m3, OPS##nops ops, \
24085 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
24086 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24088 #define CM(m1, m2, op, nops, ops, ae) \
24089 xCM_ (m1, , m2, op, nops, ops, ae), \
24090 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24091 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24092 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24093 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24094 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24095 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24096 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24097 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24098 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24099 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24100 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24101 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24102 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24103 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24104 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24105 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24106 xCM_ (m1, le, m2, op, nops, ops, ae), \
24107 xCM_ (m1, al, m2, op, nops, ops, ae)
24109 #define UE(mnem, op, nops, ops, ae) \
24110 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24112 #define UF(mnem, op, nops, ops, ae) \
24113 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24115 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
24116 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24117 use the same encoding function for each. */
24118 #define NUF(mnem, op, nops, ops, enc) \
24119 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24120 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24122 /* Neon data processing, version which indirects through neon_enc_tab for
24123 the various overloaded versions of opcodes. */
24124 #define nUF(mnem, op, nops, ops, enc) \
24125 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24126 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24128 /* Neon insn with conditional suffix for the ARM version, non-overloaded
24129 version. */
24130 #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24131 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
24132 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24134 #define NCE(mnem, op, nops, ops, enc) \
24135 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24137 #define NCEF(mnem, op, nops, ops, enc) \
24138 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24140 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
24141 #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24142 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
24143 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24145 #define nCE(mnem, op, nops, ops, enc) \
24146 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24148 #define nCEF(mnem, op, nops, ops, enc) \
24149 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24151 /* */
24152 #define mCEF(mnem, op, nops, ops, enc) \
24153 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
24154 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24157 /* nCEF but for MVE predicated instructions. */
24158 #define mnCEF(mnem, op, nops, ops, enc) \
24159 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24161 /* nCE but for MVE predicated instructions. */
24162 #define mnCE(mnem, op, nops, ops, enc) \
24163 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24165 /* NUF but for potentially MVE predicated instructions. */
24166 #define MNUF(mnem, op, nops, ops, enc) \
24167 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24168 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24170 /* nUF but for potentially MVE predicated instructions. */
24171 #define mnUF(mnem, op, nops, ops, enc) \
24172 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24173 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24175 /* ToC but for potentially MVE predicated instructions. */
24176 #define mToC(mnem, top, nops, ops, te) \
24177 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24178 do_##te, 1 }
24180 /* NCE but for MVE predicated instructions. */
24181 #define MNCE(mnem, op, nops, ops, enc) \
24182 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24184 /* NCEF but for MVE predicated instructions. */
24185 #define MNCEF(mnem, op, nops, ops, enc) \
24186 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24187 #define do_0 0
24189 static const struct asm_opcode insns[] =
24191 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24192 #define THUMB_VARIANT & arm_ext_v4t
24193 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24194 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24195 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24196 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24197 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24198 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24199 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24200 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24201 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24202 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24203 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24204 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24205 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24206 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24207 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24208 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
24210 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24211 for setting PSR flag bits. They are obsolete in V6 and do not
24212 have Thumb equivalents. */
24213 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24214 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24215 CL("tstp", 110f000, 2, (RR, SH), cmp),
24216 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24217 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24218 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24219 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24220 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24221 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24223 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
24224 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
24225 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24226 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24228 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
24229 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24230 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24231 OP_RRnpc),
24232 OP_ADDRGLDR),ldst, t_ldst),
24233 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24235 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24236 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24237 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24238 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24239 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24240 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24242 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24243 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
24245 /* Pseudo ops. */
24246 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
24247 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
24248 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
24249 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
24251 /* Thumb-compatibility pseudo ops. */
24252 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24253 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24254 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24255 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24256 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24257 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24258 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24259 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24260 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24261 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24262 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24263 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
24265 /* These may simplify to neg. */
24266 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24267 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
24269 #undef THUMB_VARIANT
24270 #define THUMB_VARIANT & arm_ext_os
24272 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24273 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24275 #undef THUMB_VARIANT
24276 #define THUMB_VARIANT & arm_ext_v6
24278 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
24280 /* V1 instructions with no Thumb analogue prior to V6T2. */
24281 #undef THUMB_VARIANT
24282 #define THUMB_VARIANT & arm_ext_v6t2
24284 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24285 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24286 CL("teqp", 130f000, 2, (RR, SH), cmp),
24288 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24289 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24290 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24291 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24293 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24294 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24296 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24297 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24299 /* V1 instructions with no Thumb analogue at all. */
24300 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
24301 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24303 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24304 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24305 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24306 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24307 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24308 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24309 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24310 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24312 #undef ARM_VARIANT
24313 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24314 #undef THUMB_VARIANT
24315 #define THUMB_VARIANT & arm_ext_v4t
24317 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24318 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24320 #undef THUMB_VARIANT
24321 #define THUMB_VARIANT & arm_ext_v6t2
24323 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24324 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24326 /* Generic coprocessor instructions. */
24327 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24328 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24329 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24330 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24331 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24332 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24333 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
24335 #undef ARM_VARIANT
24336 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24338 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24339 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24341 #undef ARM_VARIANT
24342 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24343 #undef THUMB_VARIANT
24344 #define THUMB_VARIANT & arm_ext_msr
24346 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24347 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
24349 #undef ARM_VARIANT
24350 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24351 #undef THUMB_VARIANT
24352 #define THUMB_VARIANT & arm_ext_v6t2
24354 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24355 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24356 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24357 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24358 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24359 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24360 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24361 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24363 #undef ARM_VARIANT
24364 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24365 #undef THUMB_VARIANT
24366 #define THUMB_VARIANT & arm_ext_v4t
24368 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24369 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24370 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24371 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24372 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24373 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24375 #undef ARM_VARIANT
24376 #define ARM_VARIANT & arm_ext_v4t_5
24378 /* ARM Architecture 4T. */
24379 /* Note: bx (and blx) are required on V5, even if the processor does
24380 not support Thumb. */
24381 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
24383 #undef ARM_VARIANT
24384 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24385 #undef THUMB_VARIANT
24386 #define THUMB_VARIANT & arm_ext_v5t
24388 /* Note: blx has 2 variants; the .value coded here is for
24389 BLX(2). Only this variant has conditional execution. */
24390 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24391 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
24393 #undef THUMB_VARIANT
24394 #define THUMB_VARIANT & arm_ext_v6t2
24396 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24397 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24398 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24399 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24400 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24401 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24402 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24403 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24405 #undef ARM_VARIANT
24406 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24407 #undef THUMB_VARIANT
24408 #define THUMB_VARIANT & arm_ext_v5exp
24410 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24411 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24412 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24413 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24415 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24416 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24418 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24419 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24420 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24421 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24423 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24424 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24425 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24426 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24428 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24429 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24431 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24432 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24433 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24434 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24436 #undef ARM_VARIANT
24437 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24438 #undef THUMB_VARIANT
24439 #define THUMB_VARIANT & arm_ext_v6t2
24441 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
24442 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24443 ldrd, t_ldstd),
24444 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24445 ADDRGLDRS), ldrd, t_ldstd),
24447 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24448 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24450 #undef ARM_VARIANT
24451 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24453 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
24455 #undef ARM_VARIANT
24456 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24457 #undef THUMB_VARIANT
24458 #define THUMB_VARIANT & arm_ext_v6
24460 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24461 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24462 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24463 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24464 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24465 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24466 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24467 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24468 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24469 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
24471 #undef THUMB_VARIANT
24472 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24474 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24475 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24476 strex, t_strex),
24477 #undef THUMB_VARIANT
24478 #define THUMB_VARIANT & arm_ext_v6t2
24480 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24481 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24483 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24484 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
24486 /* ARM V6 not included in V7M. */
24487 #undef THUMB_VARIANT
24488 #define THUMB_VARIANT & arm_ext_v6_notm
24489 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24490 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24491 UF(rfeib, 9900a00, 1, (RRw), rfe),
24492 UF(rfeda, 8100a00, 1, (RRw), rfe),
24493 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24494 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24495 UF(rfefa, 8100a00, 1, (RRw), rfe),
24496 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24497 UF(rfeed, 9900a00, 1, (RRw), rfe),
24498 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24499 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24500 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24501 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
24502 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
24503 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
24504 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
24505 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24506 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24507 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
24509 /* ARM V6 not included in V7M (eg. integer SIMD). */
24510 #undef THUMB_VARIANT
24511 #define THUMB_VARIANT & arm_ext_v6_dsp
24512 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24513 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24514 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24515 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24516 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24517 /* Old name for QASX. */
24518 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24519 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24520 /* Old name for QSAX. */
24521 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24522 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24523 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24524 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24525 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24526 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24527 /* Old name for SASX. */
24528 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24529 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24530 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24531 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24532 /* Old name for SHASX. */
24533 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24534 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24535 /* Old name for SHSAX. */
24536 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24537 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24538 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24539 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24540 /* Old name for SSAX. */
24541 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24542 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24543 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24544 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24545 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24546 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24547 /* Old name for UASX. */
24548 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24549 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24550 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24551 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24552 /* Old name for UHASX. */
24553 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24554 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24555 /* Old name for UHSAX. */
24556 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24557 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24558 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24559 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24560 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24561 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24562 /* Old name for UQASX. */
24563 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24564 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24565 /* Old name for UQSAX. */
24566 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24567 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24568 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24569 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24570 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24571 /* Old name for USAX. */
24572 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24573 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24574 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24575 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24576 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24577 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24578 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24579 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24580 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24581 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24582 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24583 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24584 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24585 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24586 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24587 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24588 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24589 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24590 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24591 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24592 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24593 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24594 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24595 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24596 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24597 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24598 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24599 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24600 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24601 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24602 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24603 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24604 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24605 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
24607 #undef ARM_VARIANT
24608 #define ARM_VARIANT & arm_ext_v6k_v6t2
24609 #undef THUMB_VARIANT
24610 #define THUMB_VARIANT & arm_ext_v6k_v6t2
24612 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24613 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24614 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24615 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
24617 #undef THUMB_VARIANT
24618 #define THUMB_VARIANT & arm_ext_v6_notm
24619 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24620 ldrexd, t_ldrexd),
24621 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24622 RRnpcb), strexd, t_strexd),
24624 #undef THUMB_VARIANT
24625 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24626 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24627 rd_rn, rd_rn),
24628 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24629 rd_rn, rd_rn),
24630 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24631 strex, t_strexbh),
24632 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24633 strex, t_strexbh),
24634 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
24636 #undef ARM_VARIANT
24637 #define ARM_VARIANT & arm_ext_sec
24638 #undef THUMB_VARIANT
24639 #define THUMB_VARIANT & arm_ext_sec
24641 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
24643 #undef ARM_VARIANT
24644 #define ARM_VARIANT & arm_ext_virt
24645 #undef THUMB_VARIANT
24646 #define THUMB_VARIANT & arm_ext_virt
24648 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24649 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24651 #undef ARM_VARIANT
24652 #define ARM_VARIANT & arm_ext_pan
24653 #undef THUMB_VARIANT
24654 #define THUMB_VARIANT & arm_ext_pan
24656 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24658 #undef ARM_VARIANT
24659 #define ARM_VARIANT & arm_ext_v6t2
24660 #undef THUMB_VARIANT
24661 #define THUMB_VARIANT & arm_ext_v6t2
24663 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24664 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24665 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24666 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24668 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24669 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
24671 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24672 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24673 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24674 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24676 #undef ARM_VARIANT
24677 #define ARM_VARIANT & arm_ext_v3
24678 #undef THUMB_VARIANT
24679 #define THUMB_VARIANT & arm_ext_v6t2
24681 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
24682 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24683 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
24685 #undef ARM_VARIANT
24686 #define ARM_VARIANT & arm_ext_v6t2
24687 #undef THUMB_VARIANT
24688 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24689 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24690 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24692 /* Thumb-only instructions. */
24693 #undef ARM_VARIANT
24694 #define ARM_VARIANT NULL
24695 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24696 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
24698 /* ARM does not really have an IT instruction, so always allow it.
24699 The opcode is copied from Thumb in order to allow warnings in
24700 -mimplicit-it=[never | arm] modes. */
24701 #undef ARM_VARIANT
24702 #define ARM_VARIANT & arm_ext_v1
24703 #undef THUMB_VARIANT
24704 #define THUMB_VARIANT & arm_ext_v6t2
24706 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24707 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24708 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24709 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24710 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24711 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24712 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24713 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24714 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24715 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24716 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24717 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24718 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24719 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24720 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
24721 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
24722 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24723 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
24725 /* Thumb2 only instructions. */
24726 #undef ARM_VARIANT
24727 #define ARM_VARIANT NULL
24729 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24730 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24731 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24732 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24733 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24734 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
24736 /* Hardware division instructions. */
24737 #undef ARM_VARIANT
24738 #define ARM_VARIANT & arm_ext_adiv
24739 #undef THUMB_VARIANT
24740 #define THUMB_VARIANT & arm_ext_div
24742 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24743 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
24745 /* ARM V6M/V7 instructions. */
24746 #undef ARM_VARIANT
24747 #define ARM_VARIANT & arm_ext_barrier
24748 #undef THUMB_VARIANT
24749 #define THUMB_VARIANT & arm_ext_barrier
24751 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24752 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24753 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
24755 /* ARM V7 instructions. */
24756 #undef ARM_VARIANT
24757 #define ARM_VARIANT & arm_ext_v7
24758 #undef THUMB_VARIANT
24759 #define THUMB_VARIANT & arm_ext_v7
24761 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24762 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
24764 #undef ARM_VARIANT
24765 #define ARM_VARIANT & arm_ext_mp
24766 #undef THUMB_VARIANT
24767 #define THUMB_VARIANT & arm_ext_mp
24769 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24771 /* AArchv8 instructions. */
24772 #undef ARM_VARIANT
24773 #define ARM_VARIANT & arm_ext_v8
24775 /* Instructions shared between armv8-a and armv8-m. */
24776 #undef THUMB_VARIANT
24777 #define THUMB_VARIANT & arm_ext_atomics
24779 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24780 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24781 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24782 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24783 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24784 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24785 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24786 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24787 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24788 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24789 stlex, t_stlex),
24790 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24791 stlex, t_stlex),
24792 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24793 stlex, t_stlex),
24794 #undef THUMB_VARIANT
24795 #define THUMB_VARIANT & arm_ext_v8
24797 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
24798 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24799 ldrexd, t_ldrexd),
24800 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24801 strexd, t_strexd),
24802 #undef THUMB_VARIANT
24803 #define THUMB_VARIANT & arm_ext_v8r
24804 #undef ARM_VARIANT
24805 #define ARM_VARIANT & arm_ext_v8r
24807 /* ARMv8-R instructions. */
24808 TUF("dfb", 57ff04c, f3bf8f4c, 0, (), noargs, noargs),
24810 /* Defined in V8 but is in undefined encoding space for earlier
24811 architectures. However earlier architectures are required to treat
24812 this instuction as a semihosting trap as well. Hence while not explicitly
24813 defined as such, it is in fact correct to define the instruction for all
24814 architectures. */
24815 #undef THUMB_VARIANT
24816 #define THUMB_VARIANT & arm_ext_v1
24817 #undef ARM_VARIANT
24818 #define ARM_VARIANT & arm_ext_v1
24819 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24821 /* ARMv8 T32 only. */
24822 #undef ARM_VARIANT
24823 #define ARM_VARIANT NULL
24824 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24825 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24826 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24828 /* FP for ARMv8. */
24829 #undef ARM_VARIANT
24830 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
24831 #undef THUMB_VARIANT
24832 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
24834 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24835 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24836 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24837 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
24838 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
24839 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24840 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24841 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24842 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24843 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24844 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
24846 /* Crypto v1 extensions. */
24847 #undef ARM_VARIANT
24848 #define ARM_VARIANT & fpu_crypto_ext_armv8
24849 #undef THUMB_VARIANT
24850 #define THUMB_VARIANT & fpu_crypto_ext_armv8
24852 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
24853 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
24854 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
24855 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
24856 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
24857 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
24858 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
24859 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
24860 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
24861 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
24862 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
24863 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
24864 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
24865 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
24867 #undef ARM_VARIANT
24868 #define ARM_VARIANT & arm_ext_crc
24869 #undef THUMB_VARIANT
24870 #define THUMB_VARIANT & arm_ext_crc
24871 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
24872 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
24873 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
24874 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
24875 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
24876 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
24878 /* ARMv8.2 RAS extension. */
24879 #undef ARM_VARIANT
24880 #define ARM_VARIANT & arm_ext_ras
24881 #undef THUMB_VARIANT
24882 #define THUMB_VARIANT & arm_ext_ras
24883 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
24885 #undef ARM_VARIANT
24886 #define ARM_VARIANT & arm_ext_v8_3
24887 #undef THUMB_VARIANT
24888 #define THUMB_VARIANT & arm_ext_v8_3
24889 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
24891 #undef ARM_VARIANT
24892 #define ARM_VARIANT & fpu_neon_ext_dotprod
24893 #undef THUMB_VARIANT
24894 #define THUMB_VARIANT & fpu_neon_ext_dotprod
24895 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
24896 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
24898 #undef ARM_VARIANT
24899 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
24900 #undef THUMB_VARIANT
24901 #define THUMB_VARIANT & arm_ext_v6t2
24902 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
24903 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
24904 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
24905 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
24906 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
24907 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
24909 /* Memory operations. */
24910 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24911 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24912 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24913 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24914 #undef THUMB_VARIANT
24916 /* Moves and type conversions. */
24917 cCE("fmstat", ef1fa10, 0, (), noargs),
24918 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
24919 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
24920 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
24921 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24922 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
24923 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24924 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
24925 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
24927 /* Memory operations. */
24928 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24929 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24930 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24931 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24932 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24933 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24934 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24935 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24936 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24937 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24938 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24939 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24941 /* Monadic operations. */
24942 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
24943 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
24944 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
24946 /* Dyadic operations. */
24947 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24948 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24949 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24950 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24951 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24952 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24953 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24954 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24955 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24957 /* Comparisons. */
24958 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
24959 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
24960 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
24961 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
24963 /* Double precision load/store are still present on single precision
24964 implementations. */
24965 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24966 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24967 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24968 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24969 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24970 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24971 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24972 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24974 #undef ARM_VARIANT
24975 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
24977 /* Moves and type conversions. */
24978 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24979 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24980 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
24981 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
24982 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
24983 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
24984 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24985 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
24986 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24987 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24988 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24989 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24991 /* Monadic operations. */
24992 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24993 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24994 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24996 /* Dyadic operations. */
24997 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24998 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24999 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25000 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25001 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25002 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25003 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25004 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25005 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25007 /* Comparisons. */
25008 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25009 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25010 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25011 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
25013 /* Instructions which may belong to either the Neon or VFP instruction sets.
25014 Individual encoder functions perform additional architecture checks. */
25015 #undef ARM_VARIANT
25016 #define ARM_VARIANT & fpu_vfp_ext_v1xd
25017 #undef THUMB_VARIANT
25018 #define THUMB_VARIANT & arm_ext_v6t2
25020 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25021 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25022 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25023 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25024 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25025 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25027 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25028 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25030 #undef THUMB_VARIANT
25031 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
25033 /* These mnemonics are unique to VFP. */
25034 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25035 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
25036 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25037 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25038 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25039 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25041 /* Mnemonics shared by Neon and VFP. */
25042 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
25044 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
25045 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
25046 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25047 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
25050 /* NOTE: All VMOV encoding is special-cased! */
25051 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25053 #undef THUMB_VARIANT
25054 /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25055 by different feature bits. Since we are setting the Thumb guard, we can
25056 require Thumb-1 which makes it a nop guard and set the right feature bit in
25057 do_vldr_vstr (). */
25058 #define THUMB_VARIANT & arm_ext_v4t
25059 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25060 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25062 #undef ARM_VARIANT
25063 #define ARM_VARIANT & arm_ext_fp16
25064 #undef THUMB_VARIANT
25065 #define THUMB_VARIANT & arm_ext_fp16
25066 /* New instructions added from v8.2, allowing the extraction and insertion of
25067 the upper 16 bits of a 32-bit vector register. */
25068 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25069 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25071 /* New backported fma/fms instructions optional in v8.2. */
25072 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25073 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
25075 #undef THUMB_VARIANT
25076 #define THUMB_VARIANT & fpu_neon_ext_v1
25077 #undef ARM_VARIANT
25078 #define ARM_VARIANT & fpu_neon_ext_v1
25080 /* Data processing with three registers of the same length. */
25081 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25082 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25083 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
25084 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25085 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25086 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25087 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
25088 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25089 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25090 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25091 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25092 /* If not immediate, fall back to neon_dyadic_i64_su.
25093 shl should accept I8 I16 I32 I64,
25094 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25095 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25096 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
25097 /* Logic ops, types optional & ignored. */
25098 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25099 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25100 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25101 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25102 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
25103 /* Bitfield ops, untyped. */
25104 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25105 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25106 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25107 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25108 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25109 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25110 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
25111 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25112 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25113 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25114 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25115 back to neon_dyadic_if_su. */
25116 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25117 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25118 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25119 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25120 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25121 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25122 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25123 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25124 /* Comparison. Type I8 I16 I32 F32. */
25125 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25126 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
25127 /* As above, D registers only. */
25128 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25129 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25130 /* Int and float variants, signedness unimportant. */
25131 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25132 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25133 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
25134 /* Add/sub take types I8 I16 I32 I64 F32. */
25135 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25136 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25137 /* vtst takes sizes 8, 16, 32. */
25138 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25139 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25140 /* VMUL takes I8 I16 I32 F32 P8. */
25141 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
25142 /* VQD{R}MULH takes S16 S32. */
25143 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25144 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25145 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25146 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25147 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25148 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25149 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25150 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25151 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25152 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25153 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25154 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25155 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25156 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25157 /* ARM v8.1 extension. */
25158 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25159 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25160 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25162 /* Two address, int/float. Types S8 S16 S32 F32. */
25163 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
25164 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25166 /* Data processing with two registers and a shift amount. */
25167 /* Right shifts, and variants with rounding.
25168 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
25169 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25170 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25171 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25172 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25173 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25174 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25175 /* Shift and insert. Sizes accepted 8 16 32 64. */
25176 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
25177 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25178 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
25179 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25180 /* Right shift immediate, saturating & narrowing, with rounding variants.
25181 Types accepted S16 S32 S64 U16 U32 U64. */
25182 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25183 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25184 /* As above, unsigned. Types accepted S16 S32 S64. */
25185 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25186 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25187 /* Right shift narrowing. Types accepted I16 I32 I64. */
25188 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25189 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25190 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
25191 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
25192 /* CVT with optional immediate for fixed-point variant. */
25193 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
25195 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
25197 /* Data processing, three registers of different lengths. */
25198 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25199 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
25200 /* If not scalar, fall back to neon_dyadic_long.
25201 Vector types as above, scalar types S16 S32 U16 U32. */
25202 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25203 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25204 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25205 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25206 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25207 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25208 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25209 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25210 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25211 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25212 /* Saturating doubling multiplies. Types S16 S32. */
25213 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25214 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25215 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25216 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25217 S16 S32 U16 U32. */
25218 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
25220 /* Extract. Size 8. */
25221 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25222 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
25224 /* Two registers, miscellaneous. */
25225 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
25226 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
25227 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
25228 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25229 /* Vector replicate. Sizes 8 16 32. */
25230 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
25231 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25232 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25233 /* VMOVN. Types I16 I32 I64. */
25234 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
25235 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
25236 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
25237 /* VQMOVUN. Types S16 S32 S64. */
25238 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
25239 /* VZIP / VUZP. Sizes 8 16 32. */
25240 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25241 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25242 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25243 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25244 /* VQABS / VQNEG. Types S8 S16 S32. */
25245 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
25246 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25247 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25248 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25249 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25250 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25251 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
25252 /* Reciprocal estimates. Types U32 F16 F32. */
25253 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25254 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25255 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25256 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25257 /* VCLS. Types S8 S16 S32. */
25258 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25259 /* VCLZ. Types I8 I16 I32. */
25260 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25261 /* VCNT. Size 8. */
25262 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25263 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25264 /* Two address, untyped. */
25265 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25266 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25267 /* VTRN. Sizes 8 16 32. */
25268 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25269 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
25271 /* Table lookup. Size 8. */
25272 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25273 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25275 #undef THUMB_VARIANT
25276 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25277 #undef ARM_VARIANT
25278 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25280 /* Neon element/structure load/store. */
25281 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25282 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25283 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25284 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25285 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25286 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25287 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25288 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25290 #undef THUMB_VARIANT
25291 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
25292 #undef ARM_VARIANT
25293 #define ARM_VARIANT & fpu_vfp_ext_v3xd
25294 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25295 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25296 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25297 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25298 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25299 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25300 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25301 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25302 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25304 #undef THUMB_VARIANT
25305 #define THUMB_VARIANT & fpu_vfp_ext_v3
25306 #undef ARM_VARIANT
25307 #define ARM_VARIANT & fpu_vfp_ext_v3
25309 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
25310 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25311 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25312 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25313 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25314 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25315 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25316 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25317 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25319 #undef ARM_VARIANT
25320 #define ARM_VARIANT & fpu_vfp_ext_fma
25321 #undef THUMB_VARIANT
25322 #define THUMB_VARIANT & fpu_vfp_ext_fma
25323 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
25324 VFP FMA variant; NEON and VFP FMA always includes the NEON
25325 FMA instructions. */
25326 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
25327 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
25328 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25330 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25331 the v form should always be used. */
25332 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25333 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25334 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25335 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25336 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25337 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25339 #undef THUMB_VARIANT
25340 #undef ARM_VARIANT
25341 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25343 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25344 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25345 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25346 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25347 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25348 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25349 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25350 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
25352 #undef ARM_VARIANT
25353 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25355 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25356 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25357 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25358 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25359 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25360 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25361 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25362 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25363 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
25364 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25365 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25366 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25367 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25368 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25369 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25370 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25371 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25372 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25373 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25374 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25375 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25376 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25377 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25378 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25379 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25380 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25381 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25382 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25383 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
25384 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25385 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25386 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25387 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25388 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25389 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25390 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25391 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25392 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25393 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25394 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25395 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25396 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25397 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25398 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25399 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25400 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25401 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
25402 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25403 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25404 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25405 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25406 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25407 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25408 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25409 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25410 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25411 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25412 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25413 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25414 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25415 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25416 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25417 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25418 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25419 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25420 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25421 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25422 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25423 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25424 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25425 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25426 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25427 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25428 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25429 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25430 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25431 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25432 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25433 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25434 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25435 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25436 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25437 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25438 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25439 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25440 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25441 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25442 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25443 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
25444 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25445 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25446 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25447 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25448 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25449 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25450 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25451 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25452 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25453 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25454 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25455 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25456 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25457 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25458 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25459 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25460 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25461 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25462 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25463 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25464 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25465 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
25466 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25467 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25468 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25469 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25470 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25471 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25472 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25473 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25474 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25475 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25476 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25477 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25478 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25479 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25480 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25481 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25482 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25483 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25484 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25485 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25486 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25487 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25488 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25489 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25490 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25491 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25492 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25493 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25494 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25495 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25496 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25497 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
25498 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
25499 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
25500 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
25501 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
25502 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
25503 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25504 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25505 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25506 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
25507 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
25508 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
25509 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
25510 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
25511 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
25512 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25513 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25514 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25515 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25516 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
25518 #undef ARM_VARIANT
25519 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
25521 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
25522 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
25523 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
25524 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
25525 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
25526 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
25527 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25528 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25529 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25530 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25531 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25532 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25533 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25534 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25535 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25536 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25537 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25538 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25539 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25540 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25541 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
25542 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25543 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25544 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25545 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25546 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25547 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25548 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25549 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25550 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25551 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25552 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25553 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25554 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25555 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25556 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25557 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25558 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25559 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25560 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25561 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25562 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25563 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25564 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25565 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25566 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25567 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25568 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25569 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25570 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25571 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25572 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25573 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25574 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25575 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25576 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25577 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25579 /* ARMv8.5-A instructions. */
25580 #undef ARM_VARIANT
25581 #define ARM_VARIANT & arm_ext_sb
25582 #undef THUMB_VARIANT
25583 #define THUMB_VARIANT & arm_ext_sb
25584 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
25586 #undef ARM_VARIANT
25587 #define ARM_VARIANT & arm_ext_predres
25588 #undef THUMB_VARIANT
25589 #define THUMB_VARIANT & arm_ext_predres
25590 CE("cfprctx", e070f93, 1, (RRnpc), rd),
25591 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
25592 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
25594 /* ARMv8-M instructions. */
25595 #undef ARM_VARIANT
25596 #define ARM_VARIANT NULL
25597 #undef THUMB_VARIANT
25598 #define THUMB_VARIANT & arm_ext_v8m
25599 ToU("sg", e97fe97f, 0, (), noargs),
25600 ToC("blxns", 4784, 1, (RRnpc), t_blx),
25601 ToC("bxns", 4704, 1, (RRnpc), t_bx),
25602 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
25603 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
25604 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
25605 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
25607 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
25608 instructions behave as nop if no VFP is present. */
25609 #undef THUMB_VARIANT
25610 #define THUMB_VARIANT & arm_ext_v8m_main
25611 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
25612 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
25614 /* Armv8.1-M Mainline instructions. */
25615 #undef THUMB_VARIANT
25616 #define THUMB_VARIANT & arm_ext_v8_1m_main
25617 toU("aut", _aut, 3, (R12, LR, SP), t_pacbti),
25618 toU("autg", _autg, 3, (RR, RR, RR), t_pacbti_nonop),
25619 ToU("bti", f3af800f, 0, (), noargs),
25620 toU("bxaut", _bxaut, 3, (RR, RR, RR), t_pacbti_nonop),
25621 toU("pac", _pac, 3, (R12, LR, SP), t_pacbti),
25622 toU("pacbti", _pacbti, 3, (R12, LR, SP), t_pacbti),
25623 toU("pacg", _pacg, 3, (RR, RR, RR), t_pacbti_pacg),
25624 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25625 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25626 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25627 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25628 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
25629 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
25630 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25631 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25632 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25634 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
25635 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
25636 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
25637 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
25638 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
25640 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
25641 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
25642 toU("le", _le, 2, (oLR, EXP), t_loloop),
25644 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
25645 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
25647 #undef THUMB_VARIANT
25648 #define THUMB_VARIANT & mve_ext
25649 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25650 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25651 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25652 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
25653 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
25654 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
25655 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25656 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
25657 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
25658 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25659 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25660 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
25661 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
25662 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
25663 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
25665 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25666 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25667 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25668 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25669 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25670 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25671 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25672 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25673 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25674 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25675 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25676 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25677 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25678 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25679 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25681 ToC("vpst", fe710f4d, 0, (), mve_vpt),
25682 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
25683 ToC("vpste", fe718f4d, 0, (), mve_vpt),
25684 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
25685 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
25686 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
25687 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
25688 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
25689 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
25690 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
25691 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
25692 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
25693 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
25694 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
25695 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
25697 /* MVE and MVE FP only. */
25698 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
25699 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
25700 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
25701 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
25702 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
25703 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
25704 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
25705 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
25706 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25707 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25708 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25709 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25710 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25711 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25712 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25713 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25714 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25715 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25717 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25718 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25719 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25720 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25721 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25722 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25723 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25724 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25725 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25726 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25727 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25728 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25729 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25730 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25731 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25732 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25733 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25734 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25735 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25736 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25738 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
25739 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
25740 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
25741 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
25742 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
25743 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
25744 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
25745 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
25746 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
25747 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
25748 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
25749 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
25750 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
25751 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
25752 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
25753 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
25754 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
25756 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25757 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25758 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25759 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25760 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25761 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25762 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25763 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25764 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25765 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25766 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25767 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25768 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25769 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25770 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25771 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25772 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25773 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25774 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25775 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25777 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
25778 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
25779 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
25780 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
25781 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
25783 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25784 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25785 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25786 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25787 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25788 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25789 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25790 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25791 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25792 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25793 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25794 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
25795 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
25796 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
25797 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
25798 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
25799 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
25801 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25802 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25803 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25804 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25805 mCEF(vqshrnt, _vqshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25806 mCEF(vqshrnb, _vqshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25807 mCEF(vqshrunt, _vqshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25808 mCEF(vqshrunb, _vqshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25809 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25810 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25811 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25812 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25814 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
25815 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
25816 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
25818 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
25819 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
25820 toU("letp", _letp, 2, (LR, EXP), t_loloop),
25821 toU("lctp", _lctp, 0, (), t_loloop),
25823 #undef THUMB_VARIANT
25824 #define THUMB_VARIANT & mve_fp_ext
25825 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
25826 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
25827 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
25828 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
25829 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
25830 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
25831 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
25832 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
25834 #undef ARM_VARIANT
25835 #define ARM_VARIANT & fpu_vfp_ext_v1
25836 #undef THUMB_VARIANT
25837 #define THUMB_VARIANT & arm_ext_v6t2
25839 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25841 #undef ARM_VARIANT
25842 #define ARM_VARIANT & fpu_vfp_ext_v1xd
25844 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
25845 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
25846 MNCE(vmov, 0, 1, (VMOV), neon_mov),
25847 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
25848 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
25849 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
25851 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
25852 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
25853 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
25855 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25856 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25858 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
25859 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
25861 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25862 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25864 #undef ARM_VARIANT
25865 #define ARM_VARIANT & fpu_vfp_ext_v2
25867 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
25868 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
25869 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
25870 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
25872 #undef ARM_VARIANT
25873 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
25874 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
25875 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
25876 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
25877 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
25878 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
25879 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
25881 #undef ARM_VARIANT
25882 #define ARM_VARIANT & fpu_neon_ext_v1
25883 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25884 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
25885 mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
25886 mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
25887 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25888 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25889 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25890 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25891 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
25892 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
25893 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
25894 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
25895 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
25896 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
25897 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
25898 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25899 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25900 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
25901 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
25902 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
25903 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
25904 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
25905 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
25906 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
25907 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
25908 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
25909 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
25910 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25911 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25912 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
25913 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
25914 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
25915 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
25916 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
25917 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
25918 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
25919 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
25921 #undef ARM_VARIANT
25922 #define ARM_VARIANT & arm_ext_v8_3
25923 #undef THUMB_VARIANT
25924 #define THUMB_VARIANT & arm_ext_v6t2_v8m
25925 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
25926 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
25928 #undef ARM_VARIANT
25929 #define ARM_VARIANT &arm_ext_bf16
25930 #undef THUMB_VARIANT
25931 #define THUMB_VARIANT &arm_ext_bf16
25932 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
25933 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
25934 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
25936 #undef ARM_VARIANT
25937 #define ARM_VARIANT &arm_ext_i8mm
25938 #undef THUMB_VARIANT
25939 #define THUMB_VARIANT &arm_ext_i8mm
25940 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
25941 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
25942 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
25943 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
25944 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
25946 #undef ARM_VARIANT
25947 #undef THUMB_VARIANT
25948 #define THUMB_VARIANT &arm_ext_cde
25949 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
25950 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
25951 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
25952 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
25954 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
25955 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
25956 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
25957 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
25959 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
25960 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
25961 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
25962 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
25964 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
25965 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
25967 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
25968 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
25970 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
25971 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
25974 #undef ARM_VARIANT
25975 #undef THUMB_VARIANT
25976 #undef TCE
25977 #undef TUE
25978 #undef TUF
25979 #undef TCC
25980 #undef cCE
25981 #undef C3
25982 #undef CE
25983 #undef CM
25984 #undef CL
25985 #undef UE
25986 #undef UF
25987 #undef UT
25988 #undef NUF
25989 #undef nUF
25990 #undef NCE
25991 #undef nCE
25992 #undef OPS0
25993 #undef OPS1
25994 #undef OPS2
25995 #undef OPS3
25996 #undef OPS4
25997 #undef OPS5
25998 #undef OPS6
25999 #undef do_0
26000 #undef ToC
26001 #undef toC
26002 #undef ToU
26003 #undef toU
26005 /* MD interface: bits in the object file. */
26007 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26008 for use in the a.out file, and stores them in the array pointed to by buf.
26009 This knows about the endian-ness of the target machine and does
26010 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26011 2 (short) and 4 (long) Floating numbers are put out as a series of
26012 LITTLENUMS (shorts, here at least). */
26014 void
26015 md_number_to_chars (char * buf, valueT val, int n)
26017 if (target_big_endian)
26018 number_to_chars_bigendian (buf, val, n);
26019 else
26020 number_to_chars_littleendian (buf, val, n);
26023 static valueT
26024 md_chars_to_number (char * buf, int n)
26026 valueT result = 0;
26027 unsigned char * where = (unsigned char *) buf;
26029 if (target_big_endian)
26031 while (n--)
26033 result <<= 8;
26034 result |= (*where++ & 255);
26037 else
26039 while (n--)
26041 result <<= 8;
26042 result |= (where[n] & 255);
26046 return result;
26049 /* MD interface: Sections. */
26051 /* Calculate the maximum variable size (i.e., excluding fr_fix)
26052 that an rs_machine_dependent frag may reach. */
26054 unsigned int
26055 arm_frag_max_var (fragS *fragp)
26057 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26058 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26060 Note that we generate relaxable instructions even for cases that don't
26061 really need it, like an immediate that's a trivial constant. So we're
26062 overestimating the instruction size for some of those cases. Rather
26063 than putting more intelligence here, it would probably be better to
26064 avoid generating a relaxation frag in the first place when it can be
26065 determined up front that a short instruction will suffice. */
26067 gas_assert (fragp->fr_type == rs_machine_dependent);
26068 return INSN_SIZE;
26071 /* Estimate the size of a frag before relaxing. Assume everything fits in
26072 2 bytes. */
26075 md_estimate_size_before_relax (fragS * fragp,
26076 segT segtype ATTRIBUTE_UNUSED)
26078 fragp->fr_var = 2;
26079 return 2;
26082 /* Convert a machine dependent frag. */
26084 void
26085 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26087 unsigned long insn;
26088 unsigned long old_op;
26089 char *buf;
26090 expressionS exp;
26091 fixS *fixp;
26092 int reloc_type;
26093 int pc_rel;
26094 int opcode;
26096 buf = fragp->fr_literal + fragp->fr_fix;
26098 old_op = bfd_get_16(abfd, buf);
26099 if (fragp->fr_symbol)
26101 exp.X_op = O_symbol;
26102 exp.X_add_symbol = fragp->fr_symbol;
26104 else
26106 exp.X_op = O_constant;
26108 exp.X_add_number = fragp->fr_offset;
26109 opcode = fragp->fr_subtype;
26110 switch (opcode)
26112 case T_MNEM_ldr_pc:
26113 case T_MNEM_ldr_pc2:
26114 case T_MNEM_ldr_sp:
26115 case T_MNEM_str_sp:
26116 case T_MNEM_ldr:
26117 case T_MNEM_ldrb:
26118 case T_MNEM_ldrh:
26119 case T_MNEM_str:
26120 case T_MNEM_strb:
26121 case T_MNEM_strh:
26122 if (fragp->fr_var == 4)
26124 insn = THUMB_OP32 (opcode);
26125 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26127 insn |= (old_op & 0x700) << 4;
26129 else
26131 insn |= (old_op & 7) << 12;
26132 insn |= (old_op & 0x38) << 13;
26134 insn |= 0x00000c00;
26135 put_thumb32_insn (buf, insn);
26136 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26138 else
26140 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26142 pc_rel = (opcode == T_MNEM_ldr_pc2);
26143 break;
26144 case T_MNEM_adr:
26145 /* Thumb bits should be set in the frag handling so we process them
26146 after all symbols have been seen. PR gas/25235. */
26147 if (exp.X_op == O_symbol
26148 && exp.X_add_symbol != NULL
26149 && S_IS_DEFINED (exp.X_add_symbol)
26150 && THUMB_IS_FUNC (exp.X_add_symbol))
26151 exp.X_add_number |= 1;
26153 if (fragp->fr_var == 4)
26155 insn = THUMB_OP32 (opcode);
26156 insn |= (old_op & 0xf0) << 4;
26157 put_thumb32_insn (buf, insn);
26158 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26160 else
26162 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26163 exp.X_add_number -= 4;
26165 pc_rel = 1;
26166 break;
26167 case T_MNEM_mov:
26168 case T_MNEM_movs:
26169 case T_MNEM_cmp:
26170 case T_MNEM_cmn:
26171 if (fragp->fr_var == 4)
26173 int r0off = (opcode == T_MNEM_mov
26174 || opcode == T_MNEM_movs) ? 0 : 8;
26175 insn = THUMB_OP32 (opcode);
26176 insn = (insn & 0xe1ffffff) | 0x10000000;
26177 insn |= (old_op & 0x700) << r0off;
26178 put_thumb32_insn (buf, insn);
26179 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26181 else
26183 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26185 pc_rel = 0;
26186 break;
26187 case T_MNEM_b:
26188 if (fragp->fr_var == 4)
26190 insn = THUMB_OP32(opcode);
26191 put_thumb32_insn (buf, insn);
26192 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26194 else
26195 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26196 pc_rel = 1;
26197 break;
26198 case T_MNEM_bcond:
26199 if (fragp->fr_var == 4)
26201 insn = THUMB_OP32(opcode);
26202 insn |= (old_op & 0xf00) << 14;
26203 put_thumb32_insn (buf, insn);
26204 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26206 else
26207 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26208 pc_rel = 1;
26209 break;
26210 case T_MNEM_add_sp:
26211 case T_MNEM_add_pc:
26212 case T_MNEM_inc_sp:
26213 case T_MNEM_dec_sp:
26214 if (fragp->fr_var == 4)
26216 /* ??? Choose between add and addw. */
26217 insn = THUMB_OP32 (opcode);
26218 insn |= (old_op & 0xf0) << 4;
26219 put_thumb32_insn (buf, insn);
26220 if (opcode == T_MNEM_add_pc)
26221 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26222 else
26223 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26225 else
26226 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26227 pc_rel = 0;
26228 break;
26230 case T_MNEM_addi:
26231 case T_MNEM_addis:
26232 case T_MNEM_subi:
26233 case T_MNEM_subis:
26234 if (fragp->fr_var == 4)
26236 insn = THUMB_OP32 (opcode);
26237 insn |= (old_op & 0xf0) << 4;
26238 insn |= (old_op & 0xf) << 16;
26239 put_thumb32_insn (buf, insn);
26240 if (insn & (1 << 20))
26241 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26242 else
26243 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26245 else
26246 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26247 pc_rel = 0;
26248 break;
26249 default:
26250 abort ();
26252 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
26253 (enum bfd_reloc_code_real) reloc_type);
26254 fixp->fx_file = fragp->fr_file;
26255 fixp->fx_line = fragp->fr_line;
26256 fragp->fr_fix += fragp->fr_var;
26258 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26259 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26260 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26261 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
26264 /* Return the size of a relaxable immediate operand instruction.
26265 SHIFT and SIZE specify the form of the allowable immediate. */
26266 static int
26267 relax_immediate (fragS *fragp, int size, int shift)
26269 offsetT offset;
26270 offsetT mask;
26271 offsetT low;
26273 /* ??? Should be able to do better than this. */
26274 if (fragp->fr_symbol)
26275 return 4;
26277 low = (1 << shift) - 1;
26278 mask = (1 << (shift + size)) - (1 << shift);
26279 offset = fragp->fr_offset;
26280 /* Force misaligned offsets to 32-bit variant. */
26281 if (offset & low)
26282 return 4;
26283 if (offset & ~mask)
26284 return 4;
26285 return 2;
26288 /* Get the address of a symbol during relaxation. */
26289 static addressT
26290 relaxed_symbol_addr (fragS *fragp, long stretch)
26292 fragS *sym_frag;
26293 addressT addr;
26294 symbolS *sym;
26296 sym = fragp->fr_symbol;
26297 sym_frag = symbol_get_frag (sym);
26298 know (S_GET_SEGMENT (sym) != absolute_section
26299 || sym_frag == &zero_address_frag);
26300 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26302 /* If frag has yet to be reached on this pass, assume it will
26303 move by STRETCH just as we did. If this is not so, it will
26304 be because some frag between grows, and that will force
26305 another pass. */
26307 if (stretch != 0
26308 && sym_frag->relax_marker != fragp->relax_marker)
26310 fragS *f;
26312 /* Adjust stretch for any alignment frag. Note that if have
26313 been expanding the earlier code, the symbol may be
26314 defined in what appears to be an earlier frag. FIXME:
26315 This doesn't handle the fr_subtype field, which specifies
26316 a maximum number of bytes to skip when doing an
26317 alignment. */
26318 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26320 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26322 if (stretch < 0)
26323 stretch = - ((- stretch)
26324 & ~ ((1 << (int) f->fr_offset) - 1));
26325 else
26326 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26327 if (stretch == 0)
26328 break;
26331 if (f != NULL)
26332 addr += stretch;
26335 return addr;
26338 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
26339 load. */
26340 static int
26341 relax_adr (fragS *fragp, asection *sec, long stretch)
26343 addressT addr;
26344 offsetT val;
26346 /* Assume worst case for symbols not known to be in the same section. */
26347 if (fragp->fr_symbol == NULL
26348 || !S_IS_DEFINED (fragp->fr_symbol)
26349 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26350 || S_IS_WEAK (fragp->fr_symbol)
26351 || THUMB_IS_FUNC (fragp->fr_symbol))
26352 return 4;
26354 val = relaxed_symbol_addr (fragp, stretch);
26355 addr = fragp->fr_address + fragp->fr_fix;
26356 addr = (addr + 4) & ~3;
26357 /* Force misaligned targets to 32-bit variant. */
26358 if (val & 3)
26359 return 4;
26360 val -= addr;
26361 if (val < 0 || val > 1020)
26362 return 4;
26363 return 2;
26366 /* Return the size of a relaxable add/sub immediate instruction. */
26367 static int
26368 relax_addsub (fragS *fragp, asection *sec)
26370 char *buf;
26371 int op;
26373 buf = fragp->fr_literal + fragp->fr_fix;
26374 op = bfd_get_16(sec->owner, buf);
26375 if ((op & 0xf) == ((op >> 4) & 0xf))
26376 return relax_immediate (fragp, 8, 0);
26377 else
26378 return relax_immediate (fragp, 3, 0);
26381 /* Return TRUE iff the definition of symbol S could be pre-empted
26382 (overridden) at link or load time. */
26383 static bool
26384 symbol_preemptible (symbolS *s)
26386 /* Weak symbols can always be pre-empted. */
26387 if (S_IS_WEAK (s))
26388 return true;
26390 /* Non-global symbols cannot be pre-empted. */
26391 if (! S_IS_EXTERNAL (s))
26392 return false;
26394 #ifdef OBJ_ELF
26395 /* In ELF, a global symbol can be marked protected, or private. In that
26396 case it can't be pre-empted (other definitions in the same link unit
26397 would violate the ODR). */
26398 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
26399 return false;
26400 #endif
26402 /* Other global symbols might be pre-empted. */
26403 return true;
26406 /* Return the size of a relaxable branch instruction. BITS is the
26407 size of the offset field in the narrow instruction. */
26409 static int
26410 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
26412 addressT addr;
26413 offsetT val;
26414 offsetT limit;
26416 /* Assume worst case for symbols not known to be in the same section. */
26417 if (!S_IS_DEFINED (fragp->fr_symbol)
26418 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26419 || S_IS_WEAK (fragp->fr_symbol))
26420 return 4;
26422 #ifdef OBJ_ELF
26423 /* A branch to a function in ARM state will require interworking. */
26424 if (S_IS_DEFINED (fragp->fr_symbol)
26425 && ARM_IS_FUNC (fragp->fr_symbol))
26426 return 4;
26427 #endif
26429 if (symbol_preemptible (fragp->fr_symbol))
26430 return 4;
26432 val = relaxed_symbol_addr (fragp, stretch);
26433 addr = fragp->fr_address + fragp->fr_fix + 4;
26434 val -= addr;
26436 /* Offset is a signed value *2 */
26437 limit = 1 << bits;
26438 if (val >= limit || val < -limit)
26439 return 4;
26440 return 2;
26444 /* Relax a machine dependent frag. This returns the amount by which
26445 the current size of the frag should change. */
26448 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
26450 int oldsize;
26451 int newsize;
26453 oldsize = fragp->fr_var;
26454 switch (fragp->fr_subtype)
26456 case T_MNEM_ldr_pc2:
26457 newsize = relax_adr (fragp, sec, stretch);
26458 break;
26459 case T_MNEM_ldr_pc:
26460 case T_MNEM_ldr_sp:
26461 case T_MNEM_str_sp:
26462 newsize = relax_immediate (fragp, 8, 2);
26463 break;
26464 case T_MNEM_ldr:
26465 case T_MNEM_str:
26466 newsize = relax_immediate (fragp, 5, 2);
26467 break;
26468 case T_MNEM_ldrh:
26469 case T_MNEM_strh:
26470 newsize = relax_immediate (fragp, 5, 1);
26471 break;
26472 case T_MNEM_ldrb:
26473 case T_MNEM_strb:
26474 newsize = relax_immediate (fragp, 5, 0);
26475 break;
26476 case T_MNEM_adr:
26477 newsize = relax_adr (fragp, sec, stretch);
26478 break;
26479 case T_MNEM_mov:
26480 case T_MNEM_movs:
26481 case T_MNEM_cmp:
26482 case T_MNEM_cmn:
26483 newsize = relax_immediate (fragp, 8, 0);
26484 break;
26485 case T_MNEM_b:
26486 newsize = relax_branch (fragp, sec, 11, stretch);
26487 break;
26488 case T_MNEM_bcond:
26489 newsize = relax_branch (fragp, sec, 8, stretch);
26490 break;
26491 case T_MNEM_add_sp:
26492 case T_MNEM_add_pc:
26493 newsize = relax_immediate (fragp, 8, 2);
26494 break;
26495 case T_MNEM_inc_sp:
26496 case T_MNEM_dec_sp:
26497 newsize = relax_immediate (fragp, 7, 2);
26498 break;
26499 case T_MNEM_addi:
26500 case T_MNEM_addis:
26501 case T_MNEM_subi:
26502 case T_MNEM_subis:
26503 newsize = relax_addsub (fragp, sec);
26504 break;
26505 default:
26506 abort ();
26509 fragp->fr_var = newsize;
26510 /* Freeze wide instructions that are at or before the same location as
26511 in the previous pass. This avoids infinite loops.
26512 Don't freeze them unconditionally because targets may be artificially
26513 misaligned by the expansion of preceding frags. */
26514 if (stretch <= 0 && newsize > 2)
26516 md_convert_frag (sec->owner, sec, fragp);
26517 frag_wane (fragp);
26520 return newsize - oldsize;
26523 /* Round up a section size to the appropriate boundary. */
26525 valueT
26526 md_section_align (segT segment ATTRIBUTE_UNUSED,
26527 valueT size)
26529 return size;
26532 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
26533 of an rs_align_code fragment. */
26535 void
26536 arm_handle_align (fragS * fragP)
26538 static unsigned char const arm_noop[2][2][4] =
26540 { /* ARMv1 */
26541 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
26542 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
26544 { /* ARMv6k */
26545 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
26546 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
26549 static unsigned char const thumb_noop[2][2][2] =
26551 { /* Thumb-1 */
26552 {0xc0, 0x46}, /* LE */
26553 {0x46, 0xc0}, /* BE */
26555 { /* Thumb-2 */
26556 {0x00, 0xbf}, /* LE */
26557 {0xbf, 0x00} /* BE */
26560 static unsigned char const wide_thumb_noop[2][4] =
26561 { /* Wide Thumb-2 */
26562 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
26563 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
26566 unsigned bytes, fix, noop_size;
26567 char * p;
26568 const unsigned char * noop;
26569 const unsigned char *narrow_noop = NULL;
26570 #ifdef OBJ_ELF
26571 enum mstate state;
26572 #endif
26574 if (fragP->fr_type != rs_align_code)
26575 return;
26577 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
26578 p = fragP->fr_literal + fragP->fr_fix;
26579 fix = 0;
26581 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
26582 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
26584 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
26586 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
26588 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26589 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
26591 narrow_noop = thumb_noop[1][target_big_endian];
26592 noop = wide_thumb_noop[target_big_endian];
26594 else
26595 noop = thumb_noop[0][target_big_endian];
26596 noop_size = 2;
26597 #ifdef OBJ_ELF
26598 state = MAP_THUMB;
26599 #endif
26601 else
26603 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26604 ? selected_cpu : arm_arch_none,
26605 arm_ext_v6k) != 0]
26606 [target_big_endian];
26607 noop_size = 4;
26608 #ifdef OBJ_ELF
26609 state = MAP_ARM;
26610 #endif
26613 fragP->fr_var = noop_size;
26615 if (bytes & (noop_size - 1))
26617 fix = bytes & (noop_size - 1);
26618 #ifdef OBJ_ELF
26619 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
26620 #endif
26621 memset (p, 0, fix);
26622 p += fix;
26623 bytes -= fix;
26626 if (narrow_noop)
26628 if (bytes & noop_size)
26630 /* Insert a narrow noop. */
26631 memcpy (p, narrow_noop, noop_size);
26632 p += noop_size;
26633 bytes -= noop_size;
26634 fix += noop_size;
26637 /* Use wide noops for the remainder */
26638 noop_size = 4;
26641 while (bytes >= noop_size)
26643 memcpy (p, noop, noop_size);
26644 p += noop_size;
26645 bytes -= noop_size;
26646 fix += noop_size;
26649 fragP->fr_fix += fix;
26652 /* Called from md_do_align. Used to create an alignment
26653 frag in a code section. */
26655 void
26656 arm_frag_align_code (int n, int max)
26658 char * p;
26660 /* We assume that there will never be a requirement
26661 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
26662 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
26664 char err_msg[128];
26666 sprintf (err_msg,
26667 _("alignments greater than %d bytes not supported in .text sections."),
26668 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
26669 as_fatal ("%s", err_msg);
26672 p = frag_var (rs_align_code,
26673 MAX_MEM_FOR_RS_ALIGN_CODE,
26675 (relax_substateT) max,
26676 (symbolS *) NULL,
26677 (offsetT) n,
26678 (char *) NULL);
26679 *p = 0;
26682 /* Perform target specific initialisation of a frag.
26683 Note - despite the name this initialisation is not done when the frag
26684 is created, but only when its type is assigned. A frag can be created
26685 and used a long time before its type is set, so beware of assuming that
26686 this initialisation is performed first. */
26688 #ifndef OBJ_ELF
26689 void
26690 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
26692 /* Record whether this frag is in an ARM or a THUMB area. */
26693 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
26696 #else /* OBJ_ELF is defined. */
26697 void
26698 arm_init_frag (fragS * fragP, int max_chars)
26700 bool frag_thumb_mode;
26702 /* If the current ARM vs THUMB mode has not already
26703 been recorded into this frag then do so now. */
26704 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
26705 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
26707 /* PR 21809: Do not set a mapping state for debug sections
26708 - it just confuses other tools. */
26709 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
26710 return;
26712 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
26714 /* Record a mapping symbol for alignment frags. We will delete this
26715 later if the alignment ends up empty. */
26716 switch (fragP->fr_type)
26718 case rs_align:
26719 case rs_align_test:
26720 case rs_fill:
26721 mapping_state_2 (MAP_DATA, max_chars);
26722 break;
26723 case rs_align_code:
26724 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
26725 break;
26726 default:
26727 break;
26731 /* When we change sections we need to issue a new mapping symbol. */
26733 void
26734 arm_elf_change_section (void)
26736 /* Link an unlinked unwind index table section to the .text section. */
26737 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
26738 && elf_linked_to_section (now_seg) == NULL)
26739 elf_linked_to_section (now_seg) = text_section;
26743 arm_elf_section_type (const char * str, size_t len)
26745 if (len == 5 && startswith (str, "exidx"))
26746 return SHT_ARM_EXIDX;
26748 return -1;
26751 /* Code to deal with unwinding tables. */
26753 static void add_unwind_adjustsp (offsetT);
26755 /* Generate any deferred unwind frame offset. */
26757 static void
26758 flush_pending_unwind (void)
26760 offsetT offset;
26762 offset = unwind.pending_offset;
26763 unwind.pending_offset = 0;
26764 if (offset != 0)
26765 add_unwind_adjustsp (offset);
26768 /* Add an opcode to this list for this function. Two-byte opcodes should
26769 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
26770 order. */
26772 static void
26773 add_unwind_opcode (valueT op, int length)
26775 /* Add any deferred stack adjustment. */
26776 if (unwind.pending_offset)
26777 flush_pending_unwind ();
26779 unwind.sp_restored = 0;
26781 if (unwind.opcode_count + length > unwind.opcode_alloc)
26783 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
26784 if (unwind.opcodes)
26785 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
26786 unwind.opcode_alloc);
26787 else
26788 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
26790 while (length > 0)
26792 length--;
26793 unwind.opcodes[unwind.opcode_count] = op & 0xff;
26794 op >>= 8;
26795 unwind.opcode_count++;
26799 /* Add unwind opcodes to adjust the stack pointer. */
26801 static void
26802 add_unwind_adjustsp (offsetT offset)
26804 valueT op;
26806 if (offset > 0x200)
26808 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
26809 char bytes[5];
26810 int n;
26811 valueT o;
26813 /* Long form: 0xb2, uleb128. */
26814 /* This might not fit in a word so add the individual bytes,
26815 remembering the list is built in reverse order. */
26816 o = (valueT) ((offset - 0x204) >> 2);
26817 if (o == 0)
26818 add_unwind_opcode (0, 1);
26820 /* Calculate the uleb128 encoding of the offset. */
26821 n = 0;
26822 while (o)
26824 bytes[n] = o & 0x7f;
26825 o >>= 7;
26826 if (o)
26827 bytes[n] |= 0x80;
26828 n++;
26830 /* Add the insn. */
26831 for (; n; n--)
26832 add_unwind_opcode (bytes[n - 1], 1);
26833 add_unwind_opcode (0xb2, 1);
26835 else if (offset > 0x100)
26837 /* Two short opcodes. */
26838 add_unwind_opcode (0x3f, 1);
26839 op = (offset - 0x104) >> 2;
26840 add_unwind_opcode (op, 1);
26842 else if (offset > 0)
26844 /* Short opcode. */
26845 op = (offset - 4) >> 2;
26846 add_unwind_opcode (op, 1);
26848 else if (offset < 0)
26850 offset = -offset;
26851 while (offset > 0x100)
26853 add_unwind_opcode (0x7f, 1);
26854 offset -= 0x100;
26856 op = ((offset - 4) >> 2) | 0x40;
26857 add_unwind_opcode (op, 1);
26861 /* Finish the list of unwind opcodes for this function. */
26863 static void
26864 finish_unwind_opcodes (void)
26866 valueT op;
26868 if (unwind.fp_used)
26870 /* Adjust sp as necessary. */
26871 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
26872 flush_pending_unwind ();
26874 /* After restoring sp from the frame pointer. */
26875 op = 0x90 | unwind.fp_reg;
26876 add_unwind_opcode (op, 1);
26878 else
26879 flush_pending_unwind ();
26883 /* Start an exception table entry. If idx is nonzero this is an index table
26884 entry. */
26886 static void
26887 start_unwind_section (const segT text_seg, int idx)
26889 const char * text_name;
26890 const char * prefix;
26891 const char * prefix_once;
26892 struct elf_section_match match;
26893 char * sec_name;
26894 int type;
26895 int flags;
26896 int linkonce;
26898 if (idx)
26900 prefix = ELF_STRING_ARM_unwind;
26901 prefix_once = ELF_STRING_ARM_unwind_once;
26902 type = SHT_ARM_EXIDX;
26904 else
26906 prefix = ELF_STRING_ARM_unwind_info;
26907 prefix_once = ELF_STRING_ARM_unwind_info_once;
26908 type = SHT_PROGBITS;
26911 text_name = segment_name (text_seg);
26912 if (streq (text_name, ".text"))
26913 text_name = "";
26915 if (startswith (text_name, ".gnu.linkonce.t."))
26917 prefix = prefix_once;
26918 text_name += strlen (".gnu.linkonce.t.");
26921 sec_name = concat (prefix, text_name, (char *) NULL);
26923 flags = SHF_ALLOC;
26924 linkonce = 0;
26925 memset (&match, 0, sizeof (match));
26927 /* Handle COMDAT group. */
26928 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
26930 match.group_name = elf_group_name (text_seg);
26931 if (match.group_name == NULL)
26933 as_bad (_("Group section `%s' has no group signature"),
26934 segment_name (text_seg));
26935 ignore_rest_of_line ();
26936 return;
26938 flags |= SHF_GROUP;
26939 linkonce = 1;
26942 obj_elf_change_section (sec_name, type, flags, 0, &match,
26943 linkonce);
26945 /* Set the section link for index tables. */
26946 if (idx)
26947 elf_linked_to_section (now_seg) = text_seg;
26951 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
26952 personality routine data. Returns zero, or the index table value for
26953 an inline entry. */
26955 static valueT
26956 create_unwind_entry (int have_data)
26958 int size;
26959 addressT where;
26960 char *ptr;
26961 /* The current word of data. */
26962 valueT data;
26963 /* The number of bytes left in this word. */
26964 int n;
26966 finish_unwind_opcodes ();
26968 /* Remember the current text section. */
26969 unwind.saved_seg = now_seg;
26970 unwind.saved_subseg = now_subseg;
26972 start_unwind_section (now_seg, 0);
26974 if (unwind.personality_routine == NULL)
26976 if (unwind.personality_index == -2)
26978 if (have_data)
26979 as_bad (_("handlerdata in cantunwind frame"));
26980 return 1; /* EXIDX_CANTUNWIND. */
26983 /* Use a default personality routine if none is specified. */
26984 if (unwind.personality_index == -1)
26986 if (unwind.opcode_count > 3)
26987 unwind.personality_index = 1;
26988 else
26989 unwind.personality_index = 0;
26992 /* Space for the personality routine entry. */
26993 if (unwind.personality_index == 0)
26995 if (unwind.opcode_count > 3)
26997 as_bad (_("too many unwind opcodes for personality routine 0"));
26998 return 1;
27001 if (!have_data)
27003 /* All the data is inline in the index table. */
27004 data = 0x80;
27005 n = 3;
27006 while (unwind.opcode_count > 0)
27008 unwind.opcode_count--;
27009 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27010 n--;
27013 /* Pad with "finish" opcodes. */
27014 while (n--)
27015 data = (data << 8) | 0xb0;
27017 return data;
27019 size = 0;
27021 else
27022 /* We get two opcodes "free" in the first word. */
27023 size = unwind.opcode_count - 2;
27025 else
27027 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27028 if (unwind.personality_index != -1)
27030 as_bad (_("attempt to recreate an unwind entry"));
27031 return 1;
27034 /* An extra byte is required for the opcode count. */
27035 size = unwind.opcode_count + 1;
27038 size = (size + 3) >> 2;
27039 if (size > 0xff)
27041 as_bad (_("too many unwind opcodes"));
27042 return 1;
27045 frag_align (2, 0, 0);
27046 record_alignment (now_seg, 2);
27047 unwind.table_entry = expr_build_dot ();
27049 /* Allocate the table entry. */
27050 ptr = frag_more ((size << 2) + 4);
27051 /* PR 13449: Zero the table entries in case some of them are not used. */
27052 memset (ptr, 0, (size << 2) + 4);
27053 where = frag_now_fix () - ((size << 2) + 4);
27055 switch (unwind.personality_index)
27057 case -1:
27058 /* ??? Should this be a PLT generating relocation? */
27059 /* Custom personality routine. */
27060 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27061 BFD_RELOC_ARM_PREL31);
27063 where += 4;
27064 ptr += 4;
27066 /* Set the first byte to the number of additional words. */
27067 data = size > 0 ? size - 1 : 0;
27068 n = 3;
27069 break;
27071 /* ABI defined personality routines. */
27072 case 0:
27073 /* Three opcodes bytes are packed into the first word. */
27074 data = 0x80;
27075 n = 3;
27076 break;
27078 case 1:
27079 case 2:
27080 /* The size and first two opcode bytes go in the first word. */
27081 data = ((0x80 + unwind.personality_index) << 8) | size;
27082 n = 2;
27083 break;
27085 default:
27086 /* Should never happen. */
27087 abort ();
27090 /* Pack the opcodes into words (MSB first), reversing the list at the same
27091 time. */
27092 while (unwind.opcode_count > 0)
27094 if (n == 0)
27096 md_number_to_chars (ptr, data, 4);
27097 ptr += 4;
27098 n = 4;
27099 data = 0;
27101 unwind.opcode_count--;
27102 n--;
27103 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27106 /* Finish off the last word. */
27107 if (n < 4)
27109 /* Pad with "finish" opcodes. */
27110 while (n--)
27111 data = (data << 8) | 0xb0;
27113 md_number_to_chars (ptr, data, 4);
27116 if (!have_data)
27118 /* Add an empty descriptor if there is no user-specified data. */
27119 ptr = frag_more (4);
27120 md_number_to_chars (ptr, 0, 4);
27123 return 0;
27126 /* Initialize the DWARF-2 unwind information for this procedure. */
27128 void
27129 tc_arm_frame_initial_instructions (void)
27131 cfi_add_CFA_def_cfa (REG_SP, 0);
27133 #endif /* OBJ_ELF */
27135 /* Convert REGNAME to a DWARF-2 register number. */
27138 tc_arm_regname_to_dw2regnum (char *regname)
27140 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
27141 if (reg != FAIL)
27142 return reg;
27144 /* PR 16694: Allow VFP registers as well. */
27145 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27146 if (reg != FAIL)
27147 return 64 + reg;
27149 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27150 if (reg != FAIL)
27151 return reg + 256;
27153 reg = arm_reg_parse (&regname, REG_TYPE_PSEUDO);
27154 if (reg != FAIL)
27155 return reg;
27157 return FAIL;
27160 #ifdef TE_PE
27161 void
27162 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
27164 expressionS exp;
27166 exp.X_op = O_secrel;
27167 exp.X_add_symbol = symbol;
27168 exp.X_add_number = 0;
27169 emit_expr (&exp, size);
27171 #endif
27173 /* MD interface: Symbol and relocation handling. */
27175 /* Return the address within the segment that a PC-relative fixup is
27176 relative to. For ARM, PC-relative fixups applied to instructions
27177 are generally relative to the location of the fixup plus 8 bytes.
27178 Thumb branches are offset by 4, and Thumb loads relative to PC
27179 require special handling. */
27181 long
27182 md_pcrel_from_section (fixS * fixP, segT seg)
27184 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27186 /* If this is pc-relative and we are going to emit a relocation
27187 then we just want to put out any pipeline compensation that the linker
27188 will need. Otherwise we want to use the calculated base.
27189 For WinCE we skip the bias for externals as well, since this
27190 is how the MS ARM-CE assembler behaves and we want to be compatible. */
27191 if (fixP->fx_pcrel
27192 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
27193 || (arm_force_relocation (fixP)
27194 #ifdef TE_WINCE
27195 && !S_IS_EXTERNAL (fixP->fx_addsy)
27196 #endif
27198 base = 0;
27201 switch (fixP->fx_r_type)
27203 /* PC relative addressing on the Thumb is slightly odd as the
27204 bottom two bits of the PC are forced to zero for the
27205 calculation. This happens *after* application of the
27206 pipeline offset. However, Thumb adrl already adjusts for
27207 this, so we need not do it again. */
27208 case BFD_RELOC_ARM_THUMB_ADD:
27209 return base & ~3;
27211 case BFD_RELOC_ARM_THUMB_OFFSET:
27212 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27213 case BFD_RELOC_ARM_T32_ADD_PC12:
27214 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
27215 return (base + 4) & ~3;
27217 /* Thumb branches are simply offset by +4. */
27218 case BFD_RELOC_THUMB_PCREL_BRANCH5:
27219 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27220 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27221 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27222 case BFD_RELOC_THUMB_PCREL_BRANCH20:
27223 case BFD_RELOC_THUMB_PCREL_BRANCH25:
27224 case BFD_RELOC_THUMB_PCREL_BFCSEL:
27225 case BFD_RELOC_ARM_THUMB_BF17:
27226 case BFD_RELOC_ARM_THUMB_BF19:
27227 case BFD_RELOC_ARM_THUMB_BF13:
27228 case BFD_RELOC_ARM_THUMB_LOOP12:
27229 return base + 4;
27231 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27232 if (fixP->fx_addsy
27233 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27234 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27235 && ARM_IS_FUNC (fixP->fx_addsy)
27236 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27237 base = fixP->fx_where + fixP->fx_frag->fr_address;
27238 return base + 4;
27240 /* BLX is like branches above, but forces the low two bits of PC to
27241 zero. */
27242 case BFD_RELOC_THUMB_PCREL_BLX:
27243 if (fixP->fx_addsy
27244 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27245 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27246 && THUMB_IS_FUNC (fixP->fx_addsy)
27247 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27248 base = fixP->fx_where + fixP->fx_frag->fr_address;
27249 return (base + 4) & ~3;
27251 /* ARM mode branches are offset by +8. However, the Windows CE
27252 loader expects the relocation not to take this into account. */
27253 case BFD_RELOC_ARM_PCREL_BLX:
27254 if (fixP->fx_addsy
27255 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27256 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27257 && ARM_IS_FUNC (fixP->fx_addsy)
27258 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27259 base = fixP->fx_where + fixP->fx_frag->fr_address;
27260 return base + 8;
27262 case BFD_RELOC_ARM_PCREL_CALL:
27263 if (fixP->fx_addsy
27264 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27265 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27266 && THUMB_IS_FUNC (fixP->fx_addsy)
27267 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27268 base = fixP->fx_where + fixP->fx_frag->fr_address;
27269 return base + 8;
27271 case BFD_RELOC_ARM_PCREL_BRANCH:
27272 case BFD_RELOC_ARM_PCREL_JUMP:
27273 case BFD_RELOC_ARM_PLT32:
27274 #ifdef TE_WINCE
27275 /* When handling fixups immediately, because we have already
27276 discovered the value of a symbol, or the address of the frag involved
27277 we must account for the offset by +8, as the OS loader will never see the reloc.
27278 see fixup_segment() in write.c
27279 The S_IS_EXTERNAL test handles the case of global symbols.
27280 Those need the calculated base, not just the pipe compensation the linker will need. */
27281 if (fixP->fx_pcrel
27282 && fixP->fx_addsy != NULL
27283 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27284 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27285 return base + 8;
27286 return base;
27287 #else
27288 return base + 8;
27289 #endif
27292 /* ARM mode loads relative to PC are also offset by +8. Unlike
27293 branches, the Windows CE loader *does* expect the relocation
27294 to take this into account. */
27295 case BFD_RELOC_ARM_OFFSET_IMM:
27296 case BFD_RELOC_ARM_OFFSET_IMM8:
27297 case BFD_RELOC_ARM_HWLITERAL:
27298 case BFD_RELOC_ARM_LITERAL:
27299 case BFD_RELOC_ARM_CP_OFF_IMM:
27300 return base + 8;
27303 /* Other PC-relative relocations are un-offset. */
27304 default:
27305 return base;
27309 static bool flag_warn_syms = true;
27311 bool
27312 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
27314 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27315 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27316 does mean that the resulting code might be very confusing to the reader.
27317 Also this warning can be triggered if the user omits an operand before
27318 an immediate address, eg:
27320 LDR =foo
27322 GAS treats this as an assignment of the value of the symbol foo to a
27323 symbol LDR, and so (without this code) it will not issue any kind of
27324 warning or error message.
27326 Note - ARM instructions are case-insensitive but the strings in the hash
27327 table are all stored in lower case, so we must first ensure that name is
27328 lower case too. */
27329 if (flag_warn_syms && arm_ops_hsh)
27331 char * nbuf = strdup (name);
27332 char * p;
27334 for (p = nbuf; *p; p++)
27335 *p = TOLOWER (*p);
27336 if (str_hash_find (arm_ops_hsh, nbuf) != NULL)
27338 static htab_t already_warned = NULL;
27340 if (already_warned == NULL)
27341 already_warned = str_htab_create ();
27342 /* Only warn about the symbol once. To keep the code
27343 simple we let str_hash_insert do the lookup for us. */
27344 if (str_hash_insert (already_warned, nbuf, NULL, 0) == NULL)
27345 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
27347 else
27348 free (nbuf);
27351 return false;
27354 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
27355 Otherwise we have no need to default values of symbols. */
27357 symbolS *
27358 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
27360 #ifdef OBJ_ELF
27361 if (name[0] == '_' && name[1] == 'G'
27362 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
27364 if (!GOT_symbol)
27366 if (symbol_find (name))
27367 as_bad (_("GOT already in the symbol table"));
27369 GOT_symbol = symbol_new (name, undefined_section,
27370 &zero_address_frag, 0);
27373 return GOT_symbol;
27375 #endif
27377 return NULL;
27380 /* Subroutine of md_apply_fix. Check to see if an immediate can be
27381 computed as two separate immediate values, added together. We
27382 already know that this value cannot be computed by just one ARM
27383 instruction. */
27385 static unsigned int
27386 validate_immediate_twopart (unsigned int val,
27387 unsigned int * highpart)
27389 unsigned int a;
27390 unsigned int i;
27392 for (i = 0; i < 32; i += 2)
27393 if (((a = rotate_left (val, i)) & 0xff) != 0)
27395 if (a & 0xff00)
27397 if (a & ~ 0xffff)
27398 continue;
27399 * highpart = (a >> 8) | ((i + 24) << 7);
27401 else if (a & 0xff0000)
27403 if (a & 0xff000000)
27404 continue;
27405 * highpart = (a >> 16) | ((i + 16) << 7);
27407 else
27409 gas_assert (a & 0xff000000);
27410 * highpart = (a >> 24) | ((i + 8) << 7);
27413 return (a & 0xff) | (i << 7);
27416 return FAIL;
27419 static int
27420 validate_offset_imm (unsigned int val, int hwse)
27422 if ((hwse && val > 255) || val > 4095)
27423 return FAIL;
27424 return val;
27427 /* Subroutine of md_apply_fix. Do those data_ops which can take a
27428 negative immediate constant by altering the instruction. A bit of
27429 a hack really.
27430 MOV <-> MVN
27431 AND <-> BIC
27432 ADC <-> SBC
27433 by inverting the second operand, and
27434 ADD <-> SUB
27435 CMP <-> CMN
27436 by negating the second operand. */
27438 static int
27439 negate_data_op (unsigned long * instruction,
27440 unsigned long value)
27442 int op, new_inst;
27443 unsigned long negated, inverted;
27445 negated = encode_arm_immediate (-value);
27446 inverted = encode_arm_immediate (~value);
27448 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
27449 switch (op)
27451 /* First negates. */
27452 case OPCODE_SUB: /* ADD <-> SUB */
27453 new_inst = OPCODE_ADD;
27454 value = negated;
27455 break;
27457 case OPCODE_ADD:
27458 new_inst = OPCODE_SUB;
27459 value = negated;
27460 break;
27462 case OPCODE_CMP: /* CMP <-> CMN */
27463 new_inst = OPCODE_CMN;
27464 value = negated;
27465 break;
27467 case OPCODE_CMN:
27468 new_inst = OPCODE_CMP;
27469 value = negated;
27470 break;
27472 /* Now Inverted ops. */
27473 case OPCODE_MOV: /* MOV <-> MVN */
27474 new_inst = OPCODE_MVN;
27475 value = inverted;
27476 break;
27478 case OPCODE_MVN:
27479 new_inst = OPCODE_MOV;
27480 value = inverted;
27481 break;
27483 case OPCODE_AND: /* AND <-> BIC */
27484 new_inst = OPCODE_BIC;
27485 value = inverted;
27486 break;
27488 case OPCODE_BIC:
27489 new_inst = OPCODE_AND;
27490 value = inverted;
27491 break;
27493 case OPCODE_ADC: /* ADC <-> SBC */
27494 new_inst = OPCODE_SBC;
27495 value = inverted;
27496 break;
27498 case OPCODE_SBC:
27499 new_inst = OPCODE_ADC;
27500 value = inverted;
27501 break;
27503 /* We cannot do anything. */
27504 default:
27505 return FAIL;
27508 if (value == (unsigned) FAIL)
27509 return FAIL;
27511 *instruction &= OPCODE_MASK;
27512 *instruction |= new_inst << DATA_OP_SHIFT;
27513 return value;
27516 /* Like negate_data_op, but for Thumb-2. */
27518 static unsigned int
27519 thumb32_negate_data_op (valueT *instruction, unsigned int value)
27521 unsigned int op, new_inst;
27522 unsigned int rd;
27523 unsigned int negated, inverted;
27525 negated = encode_thumb32_immediate (-value);
27526 inverted = encode_thumb32_immediate (~value);
27528 rd = (*instruction >> 8) & 0xf;
27529 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
27530 switch (op)
27532 /* ADD <-> SUB. Includes CMP <-> CMN. */
27533 case T2_OPCODE_SUB:
27534 new_inst = T2_OPCODE_ADD;
27535 value = negated;
27536 break;
27538 case T2_OPCODE_ADD:
27539 new_inst = T2_OPCODE_SUB;
27540 value = negated;
27541 break;
27543 /* ORR <-> ORN. Includes MOV <-> MVN. */
27544 case T2_OPCODE_ORR:
27545 new_inst = T2_OPCODE_ORN;
27546 value = inverted;
27547 break;
27549 case T2_OPCODE_ORN:
27550 new_inst = T2_OPCODE_ORR;
27551 value = inverted;
27552 break;
27554 /* AND <-> BIC. TST has no inverted equivalent. */
27555 case T2_OPCODE_AND:
27556 new_inst = T2_OPCODE_BIC;
27557 if (rd == 15)
27558 value = FAIL;
27559 else
27560 value = inverted;
27561 break;
27563 case T2_OPCODE_BIC:
27564 new_inst = T2_OPCODE_AND;
27565 value = inverted;
27566 break;
27568 /* ADC <-> SBC */
27569 case T2_OPCODE_ADC:
27570 new_inst = T2_OPCODE_SBC;
27571 value = inverted;
27572 break;
27574 case T2_OPCODE_SBC:
27575 new_inst = T2_OPCODE_ADC;
27576 value = inverted;
27577 break;
27579 /* We cannot do anything. */
27580 default:
27581 return FAIL;
27584 if (value == (unsigned int)FAIL)
27585 return FAIL;
27587 *instruction &= T2_OPCODE_MASK;
27588 *instruction |= new_inst << T2_DATA_OP_SHIFT;
27589 return value;
27592 /* Read a 32-bit thumb instruction from buf. */
27594 static unsigned long
27595 get_thumb32_insn (char * buf)
27597 unsigned long insn;
27598 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
27599 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27601 return insn;
27604 /* We usually want to set the low bit on the address of thumb function
27605 symbols. In particular .word foo - . should have the low bit set.
27606 Generic code tries to fold the difference of two symbols to
27607 a constant. Prevent this and force a relocation when the first symbols
27608 is a thumb function. */
27610 bool
27611 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
27613 if (op == O_subtract
27614 && l->X_op == O_symbol
27615 && r->X_op == O_symbol
27616 && THUMB_IS_FUNC (l->X_add_symbol))
27618 l->X_op = O_subtract;
27619 l->X_op_symbol = r->X_add_symbol;
27620 l->X_add_number -= r->X_add_number;
27621 return true;
27624 /* Process as normal. */
27625 return false;
27628 /* Encode Thumb2 unconditional branches and calls. The encoding
27629 for the 2 are identical for the immediate values. */
27631 static void
27632 encode_thumb2_b_bl_offset (char * buf, offsetT value)
27634 #define T2I1I2MASK ((1 << 13) | (1 << 11))
27635 offsetT newval;
27636 offsetT newval2;
27637 addressT S, I1, I2, lo, hi;
27639 S = (value >> 24) & 0x01;
27640 I1 = (value >> 23) & 0x01;
27641 I2 = (value >> 22) & 0x01;
27642 hi = (value >> 12) & 0x3ff;
27643 lo = (value >> 1) & 0x7ff;
27644 newval = md_chars_to_number (buf, THUMB_SIZE);
27645 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27646 newval |= (S << 10) | hi;
27647 newval2 &= ~T2I1I2MASK;
27648 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
27649 md_number_to_chars (buf, newval, THUMB_SIZE);
27650 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
27653 void
27654 md_apply_fix (fixS * fixP,
27655 valueT * valP,
27656 segT seg)
27658 valueT value = * valP;
27659 valueT newval;
27660 unsigned int newimm;
27661 unsigned long temp;
27662 int sign;
27663 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
27665 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
27667 /* Note whether this will delete the relocation. */
27669 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
27670 fixP->fx_done = 1;
27672 /* On a 64-bit host, silently truncate 'value' to 32 bits for
27673 consistency with the behaviour on 32-bit hosts. Remember value
27674 for emit_reloc. */
27675 value &= 0xffffffff;
27676 value ^= 0x80000000;
27677 value -= 0x80000000;
27679 *valP = value;
27680 fixP->fx_addnumber = value;
27682 /* Same treatment for fixP->fx_offset. */
27683 fixP->fx_offset &= 0xffffffff;
27684 fixP->fx_offset ^= 0x80000000;
27685 fixP->fx_offset -= 0x80000000;
27687 switch (fixP->fx_r_type)
27689 case BFD_RELOC_NONE:
27690 /* This will need to go in the object file. */
27691 fixP->fx_done = 0;
27692 break;
27694 case BFD_RELOC_ARM_IMMEDIATE:
27695 /* We claim that this fixup has been processed here,
27696 even if in fact we generate an error because we do
27697 not have a reloc for it, so tc_gen_reloc will reject it. */
27698 fixP->fx_done = 1;
27700 if (fixP->fx_addsy)
27702 const char *msg = 0;
27704 if (! S_IS_DEFINED (fixP->fx_addsy))
27705 msg = _("undefined symbol %s used as an immediate value");
27706 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27707 msg = _("symbol %s is in a different section");
27708 else if (S_IS_WEAK (fixP->fx_addsy))
27709 msg = _("symbol %s is weak and may be overridden later");
27711 if (msg)
27713 as_bad_where (fixP->fx_file, fixP->fx_line,
27714 msg, S_GET_NAME (fixP->fx_addsy));
27715 break;
27719 temp = md_chars_to_number (buf, INSN_SIZE);
27721 /* If the offset is negative, we should use encoding A2 for ADR. */
27722 if ((temp & 0xfff0000) == 0x28f0000 && (offsetT) value < 0)
27723 newimm = negate_data_op (&temp, value);
27724 else
27726 newimm = encode_arm_immediate (value);
27728 /* If the instruction will fail, see if we can fix things up by
27729 changing the opcode. */
27730 if (newimm == (unsigned int) FAIL)
27731 newimm = negate_data_op (&temp, value);
27732 /* MOV accepts both ARM modified immediate (A1 encoding) and
27733 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
27734 When disassembling, MOV is preferred when there is no encoding
27735 overlap. */
27736 if (newimm == (unsigned int) FAIL
27737 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
27738 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
27739 && !((temp >> SBIT_SHIFT) & 0x1)
27740 && value <= 0xffff)
27742 /* Clear bits[23:20] to change encoding from A1 to A2. */
27743 temp &= 0xff0fffff;
27744 /* Encoding high 4bits imm. Code below will encode the remaining
27745 low 12bits. */
27746 temp |= (value & 0x0000f000) << 4;
27747 newimm = value & 0x00000fff;
27751 if (newimm == (unsigned int) FAIL)
27753 as_bad_where (fixP->fx_file, fixP->fx_line,
27754 _("invalid constant (%lx) after fixup"),
27755 (unsigned long) value);
27756 break;
27759 newimm |= (temp & 0xfffff000);
27760 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
27761 break;
27763 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
27765 unsigned int highpart = 0;
27766 unsigned int newinsn = 0xe1a00000; /* nop. */
27768 if (fixP->fx_addsy)
27770 const char *msg = 0;
27772 if (! S_IS_DEFINED (fixP->fx_addsy))
27773 msg = _("undefined symbol %s used as an immediate value");
27774 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27775 msg = _("symbol %s is in a different section");
27776 else if (S_IS_WEAK (fixP->fx_addsy))
27777 msg = _("symbol %s is weak and may be overridden later");
27779 if (msg)
27781 as_bad_where (fixP->fx_file, fixP->fx_line,
27782 msg, S_GET_NAME (fixP->fx_addsy));
27783 break;
27787 newimm = encode_arm_immediate (value);
27788 temp = md_chars_to_number (buf, INSN_SIZE);
27790 /* If the instruction will fail, see if we can fix things up by
27791 changing the opcode. */
27792 if (newimm == (unsigned int) FAIL
27793 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
27795 /* No ? OK - try using two ADD instructions to generate
27796 the value. */
27797 newimm = validate_immediate_twopart (value, & highpart);
27799 /* Yes - then make sure that the second instruction is
27800 also an add. */
27801 if (newimm != (unsigned int) FAIL)
27802 newinsn = temp;
27803 /* Still No ? Try using a negated value. */
27804 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
27805 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
27806 /* Otherwise - give up. */
27807 else
27809 as_bad_where (fixP->fx_file, fixP->fx_line,
27810 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
27811 (long) value);
27812 break;
27815 /* Replace the first operand in the 2nd instruction (which
27816 is the PC) with the destination register. We have
27817 already added in the PC in the first instruction and we
27818 do not want to do it again. */
27819 newinsn &= ~ 0xf0000;
27820 newinsn |= ((newinsn & 0x0f000) << 4);
27823 newimm |= (temp & 0xfffff000);
27824 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
27826 highpart |= (newinsn & 0xfffff000);
27827 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
27829 break;
27831 case BFD_RELOC_ARM_OFFSET_IMM:
27832 if (!fixP->fx_done && seg->use_rela_p)
27833 value = 0;
27834 /* Fall through. */
27836 case BFD_RELOC_ARM_LITERAL:
27837 sign = (offsetT) value > 0;
27839 if ((offsetT) value < 0)
27840 value = - value;
27842 if (validate_offset_imm (value, 0) == FAIL)
27844 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
27845 as_bad_where (fixP->fx_file, fixP->fx_line,
27846 _("invalid literal constant: pool needs to be closer"));
27847 else
27848 as_bad_where (fixP->fx_file, fixP->fx_line,
27849 _("bad immediate value for offset (%ld)"),
27850 (long) value);
27851 break;
27854 newval = md_chars_to_number (buf, INSN_SIZE);
27855 if (value == 0)
27856 newval &= 0xfffff000;
27857 else
27859 newval &= 0xff7ff000;
27860 newval |= value | (sign ? INDEX_UP : 0);
27862 md_number_to_chars (buf, newval, INSN_SIZE);
27863 break;
27865 case BFD_RELOC_ARM_OFFSET_IMM8:
27866 case BFD_RELOC_ARM_HWLITERAL:
27867 sign = (offsetT) value > 0;
27869 if ((offsetT) value < 0)
27870 value = - value;
27872 if (validate_offset_imm (value, 1) == FAIL)
27874 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
27875 as_bad_where (fixP->fx_file, fixP->fx_line,
27876 _("invalid literal constant: pool needs to be closer"));
27877 else
27878 as_bad_where (fixP->fx_file, fixP->fx_line,
27879 _("bad immediate value for 8-bit offset (%ld)"),
27880 (long) value);
27881 break;
27884 newval = md_chars_to_number (buf, INSN_SIZE);
27885 if (value == 0)
27886 newval &= 0xfffff0f0;
27887 else
27889 newval &= 0xff7ff0f0;
27890 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
27892 md_number_to_chars (buf, newval, INSN_SIZE);
27893 break;
27895 case BFD_RELOC_ARM_T32_OFFSET_U8:
27896 if (value > 1020 || value % 4 != 0)
27897 as_bad_where (fixP->fx_file, fixP->fx_line,
27898 _("bad immediate value for offset (%ld)"), (long) value);
27899 value /= 4;
27901 newval = md_chars_to_number (buf+2, THUMB_SIZE);
27902 newval |= value;
27903 md_number_to_chars (buf+2, newval, THUMB_SIZE);
27904 break;
27906 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27907 /* This is a complicated relocation used for all varieties of Thumb32
27908 load/store instruction with immediate offset:
27910 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
27911 *4, optional writeback(W)
27912 (doubleword load/store)
27914 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
27915 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
27916 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
27917 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
27918 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
27920 Uppercase letters indicate bits that are already encoded at
27921 this point. Lowercase letters are our problem. For the
27922 second block of instructions, the secondary opcode nybble
27923 (bits 8..11) is present, and bit 23 is zero, even if this is
27924 a PC-relative operation. */
27925 newval = md_chars_to_number (buf, THUMB_SIZE);
27926 newval <<= 16;
27927 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
27929 if ((newval & 0xf0000000) == 0xe0000000)
27931 /* Doubleword load/store: 8-bit offset, scaled by 4. */
27932 if ((offsetT) value >= 0)
27933 newval |= (1 << 23);
27934 else
27935 value = -value;
27936 if (value % 4 != 0)
27938 as_bad_where (fixP->fx_file, fixP->fx_line,
27939 _("offset not a multiple of 4"));
27940 break;
27942 value /= 4;
27943 if (value > 0xff)
27945 as_bad_where (fixP->fx_file, fixP->fx_line,
27946 _("offset out of range"));
27947 break;
27949 newval &= ~0xff;
27951 else if ((newval & 0x000f0000) == 0x000f0000)
27953 /* PC-relative, 12-bit offset. */
27954 if ((offsetT) value >= 0)
27955 newval |= (1 << 23);
27956 else
27957 value = -value;
27958 if (value > 0xfff)
27960 as_bad_where (fixP->fx_file, fixP->fx_line,
27961 _("offset out of range"));
27962 break;
27964 newval &= ~0xfff;
27966 else if ((newval & 0x00000100) == 0x00000100)
27968 /* Writeback: 8-bit, +/- offset. */
27969 if ((offsetT) value >= 0)
27970 newval |= (1 << 9);
27971 else
27972 value = -value;
27973 if (value > 0xff)
27975 as_bad_where (fixP->fx_file, fixP->fx_line,
27976 _("offset out of range"));
27977 break;
27979 newval &= ~0xff;
27981 else if ((newval & 0x00000f00) == 0x00000e00)
27983 /* T-instruction: positive 8-bit offset. */
27984 if (value > 0xff)
27986 as_bad_where (fixP->fx_file, fixP->fx_line,
27987 _("offset out of range"));
27988 break;
27990 newval &= ~0xff;
27991 newval |= value;
27993 else
27995 /* Positive 12-bit or negative 8-bit offset. */
27996 unsigned int limit;
27997 if ((offsetT) value >= 0)
27999 newval |= (1 << 23);
28000 limit = 0xfff;
28002 else
28004 value = -value;
28005 limit = 0xff;
28007 if (value > limit)
28009 as_bad_where (fixP->fx_file, fixP->fx_line,
28010 _("offset out of range"));
28011 break;
28013 newval &= ~limit;
28016 newval |= value;
28017 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28018 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28019 break;
28021 case BFD_RELOC_ARM_SHIFT_IMM:
28022 newval = md_chars_to_number (buf, INSN_SIZE);
28023 if (value > 32
28024 || (value == 32
28025 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28027 as_bad_where (fixP->fx_file, fixP->fx_line,
28028 _("shift expression is too large"));
28029 break;
28032 if (value == 0)
28033 /* Shifts of zero must be done as lsl. */
28034 newval &= ~0x60;
28035 else if (value == 32)
28036 value = 0;
28037 newval &= 0xfffff07f;
28038 newval |= (value & 0x1f) << 7;
28039 md_number_to_chars (buf, newval, INSN_SIZE);
28040 break;
28042 case BFD_RELOC_ARM_T32_IMMEDIATE:
28043 case BFD_RELOC_ARM_T32_ADD_IMM:
28044 case BFD_RELOC_ARM_T32_IMM12:
28045 case BFD_RELOC_ARM_T32_ADD_PC12:
28046 /* We claim that this fixup has been processed here,
28047 even if in fact we generate an error because we do
28048 not have a reloc for it, so tc_gen_reloc will reject it. */
28049 fixP->fx_done = 1;
28051 if (fixP->fx_addsy
28052 && ! S_IS_DEFINED (fixP->fx_addsy))
28054 as_bad_where (fixP->fx_file, fixP->fx_line,
28055 _("undefined symbol %s used as an immediate value"),
28056 S_GET_NAME (fixP->fx_addsy));
28057 break;
28060 newval = md_chars_to_number (buf, THUMB_SIZE);
28061 newval <<= 16;
28062 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
28064 newimm = FAIL;
28065 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28066 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28067 Thumb2 modified immediate encoding (T2). */
28068 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
28069 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28071 newimm = encode_thumb32_immediate (value);
28072 if (newimm == (unsigned int) FAIL)
28073 newimm = thumb32_negate_data_op (&newval, value);
28075 if (newimm == (unsigned int) FAIL)
28077 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
28079 /* Turn add/sum into addw/subw. */
28080 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28081 newval = (newval & 0xfeffffff) | 0x02000000;
28082 /* No flat 12-bit imm encoding for addsw/subsw. */
28083 if ((newval & 0x00100000) == 0)
28085 /* 12 bit immediate for addw/subw. */
28086 if ((offsetT) value < 0)
28088 value = -value;
28089 newval ^= 0x00a00000;
28091 if (value > 0xfff)
28092 newimm = (unsigned int) FAIL;
28093 else
28094 newimm = value;
28097 else
28099 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28100 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28101 disassembling, MOV is preferred when there is no encoding
28102 overlap. */
28103 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
28104 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28105 but with the Rn field [19:16] set to 1111. */
28106 && (((newval >> 16) & 0xf) == 0xf)
28107 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28108 && !((newval >> T2_SBIT_SHIFT) & 0x1)
28109 && value <= 0xffff)
28111 /* Toggle bit[25] to change encoding from T2 to T3. */
28112 newval ^= 1 << 25;
28113 /* Clear bits[19:16]. */
28114 newval &= 0xfff0ffff;
28115 /* Encoding high 4bits imm. Code below will encode the
28116 remaining low 12bits. */
28117 newval |= (value & 0x0000f000) << 4;
28118 newimm = value & 0x00000fff;
28123 if (newimm == (unsigned int)FAIL)
28125 as_bad_where (fixP->fx_file, fixP->fx_line,
28126 _("invalid constant (%lx) after fixup"),
28127 (unsigned long) value);
28128 break;
28131 newval |= (newimm & 0x800) << 15;
28132 newval |= (newimm & 0x700) << 4;
28133 newval |= (newimm & 0x0ff);
28135 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28136 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28137 break;
28139 case BFD_RELOC_ARM_SMC:
28140 if (value > 0xf)
28141 as_bad_where (fixP->fx_file, fixP->fx_line,
28142 _("invalid smc expression"));
28144 newval = md_chars_to_number (buf, INSN_SIZE);
28145 newval |= (value & 0xf);
28146 md_number_to_chars (buf, newval, INSN_SIZE);
28147 break;
28149 case BFD_RELOC_ARM_HVC:
28150 if (value > 0xffff)
28151 as_bad_where (fixP->fx_file, fixP->fx_line,
28152 _("invalid hvc expression"));
28153 newval = md_chars_to_number (buf, INSN_SIZE);
28154 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28155 md_number_to_chars (buf, newval, INSN_SIZE);
28156 break;
28158 case BFD_RELOC_ARM_SWI:
28159 if (fixP->tc_fix_data != 0)
28161 if (value > 0xff)
28162 as_bad_where (fixP->fx_file, fixP->fx_line,
28163 _("invalid swi expression"));
28164 newval = md_chars_to_number (buf, THUMB_SIZE);
28165 newval |= value;
28166 md_number_to_chars (buf, newval, THUMB_SIZE);
28168 else
28170 if (value > 0x00ffffff)
28171 as_bad_where (fixP->fx_file, fixP->fx_line,
28172 _("invalid swi expression"));
28173 newval = md_chars_to_number (buf, INSN_SIZE);
28174 newval |= value;
28175 md_number_to_chars (buf, newval, INSN_SIZE);
28177 break;
28179 case BFD_RELOC_ARM_MULTI:
28180 if (value > 0xffff)
28181 as_bad_where (fixP->fx_file, fixP->fx_line,
28182 _("invalid expression in load/store multiple"));
28183 newval = value | md_chars_to_number (buf, INSN_SIZE);
28184 md_number_to_chars (buf, newval, INSN_SIZE);
28185 break;
28187 #ifdef OBJ_ELF
28188 case BFD_RELOC_ARM_PCREL_CALL:
28190 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28191 && fixP->fx_addsy
28192 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28193 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28194 && THUMB_IS_FUNC (fixP->fx_addsy))
28195 /* Flip the bl to blx. This is a simple flip
28196 bit here because we generate PCREL_CALL for
28197 unconditional bls. */
28199 newval = md_chars_to_number (buf, INSN_SIZE);
28200 newval = newval | 0x10000000;
28201 md_number_to_chars (buf, newval, INSN_SIZE);
28202 temp = 1;
28203 fixP->fx_done = 1;
28205 else
28206 temp = 3;
28207 goto arm_branch_common;
28209 case BFD_RELOC_ARM_PCREL_JUMP:
28210 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28211 && fixP->fx_addsy
28212 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28213 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28214 && THUMB_IS_FUNC (fixP->fx_addsy))
28216 /* This would map to a bl<cond>, b<cond>,
28217 b<always> to a Thumb function. We
28218 need to force a relocation for this particular
28219 case. */
28220 newval = md_chars_to_number (buf, INSN_SIZE);
28221 fixP->fx_done = 0;
28223 /* Fall through. */
28225 case BFD_RELOC_ARM_PLT32:
28226 #endif
28227 case BFD_RELOC_ARM_PCREL_BRANCH:
28228 temp = 3;
28229 goto arm_branch_common;
28231 case BFD_RELOC_ARM_PCREL_BLX:
28233 temp = 1;
28234 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28235 && fixP->fx_addsy
28236 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28237 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28238 && ARM_IS_FUNC (fixP->fx_addsy))
28240 /* Flip the blx to a bl and warn. */
28241 const char *name = S_GET_NAME (fixP->fx_addsy);
28242 newval = 0xeb000000;
28243 as_warn_where (fixP->fx_file, fixP->fx_line,
28244 _("blx to '%s' an ARM ISA state function changed to bl"),
28245 name);
28246 md_number_to_chars (buf, newval, INSN_SIZE);
28247 temp = 3;
28248 fixP->fx_done = 1;
28251 #ifdef OBJ_ELF
28252 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
28253 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
28254 #endif
28256 arm_branch_common:
28257 /* We are going to store value (shifted right by two) in the
28258 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28259 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
28260 also be clear. */
28261 if (value & temp)
28262 as_bad_where (fixP->fx_file, fixP->fx_line,
28263 _("misaligned branch destination"));
28264 if ((value & 0xfe000000) != 0
28265 && (value & 0xfe000000) != 0xfe000000)
28266 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28268 if (fixP->fx_done || !seg->use_rela_p)
28270 newval = md_chars_to_number (buf, INSN_SIZE);
28271 newval |= (value >> 2) & 0x00ffffff;
28272 /* Set the H bit on BLX instructions. */
28273 if (temp == 1)
28275 if (value & 2)
28276 newval |= 0x01000000;
28277 else
28278 newval &= ~0x01000000;
28280 md_number_to_chars (buf, newval, INSN_SIZE);
28282 break;
28284 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28285 /* CBZ can only branch forward. */
28287 /* Attempts to use CBZ to branch to the next instruction
28288 (which, strictly speaking, are prohibited) will be turned into
28289 no-ops.
28291 FIXME: It may be better to remove the instruction completely and
28292 perform relaxation. */
28293 if ((offsetT) value == -2)
28295 newval = md_chars_to_number (buf, THUMB_SIZE);
28296 newval = 0xbf00; /* NOP encoding T1 */
28297 md_number_to_chars (buf, newval, THUMB_SIZE);
28299 else
28301 if (value & ~0x7e)
28302 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28304 if (fixP->fx_done || !seg->use_rela_p)
28306 newval = md_chars_to_number (buf, THUMB_SIZE);
28307 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28308 md_number_to_chars (buf, newval, THUMB_SIZE);
28311 break;
28313 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
28314 if (out_of_range_p (value, 8))
28315 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28317 if (fixP->fx_done || !seg->use_rela_p)
28319 newval = md_chars_to_number (buf, THUMB_SIZE);
28320 newval |= (value & 0x1ff) >> 1;
28321 md_number_to_chars (buf, newval, THUMB_SIZE);
28323 break;
28325 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
28326 if (out_of_range_p (value, 11))
28327 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28329 if (fixP->fx_done || !seg->use_rela_p)
28331 newval = md_chars_to_number (buf, THUMB_SIZE);
28332 newval |= (value & 0xfff) >> 1;
28333 md_number_to_chars (buf, newval, THUMB_SIZE);
28335 break;
28337 /* This relocation is misnamed, it should be BRANCH21. */
28338 case BFD_RELOC_THUMB_PCREL_BRANCH20:
28339 if (fixP->fx_addsy
28340 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28341 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28342 && ARM_IS_FUNC (fixP->fx_addsy)
28343 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28345 /* Force a relocation for a branch 20 bits wide. */
28346 fixP->fx_done = 0;
28348 if (out_of_range_p (value, 20))
28349 as_bad_where (fixP->fx_file, fixP->fx_line,
28350 _("conditional branch out of range"));
28352 if (fixP->fx_done || !seg->use_rela_p)
28354 offsetT newval2;
28355 addressT S, J1, J2, lo, hi;
28357 S = (value & 0x00100000) >> 20;
28358 J2 = (value & 0x00080000) >> 19;
28359 J1 = (value & 0x00040000) >> 18;
28360 hi = (value & 0x0003f000) >> 12;
28361 lo = (value & 0x00000ffe) >> 1;
28363 newval = md_chars_to_number (buf, THUMB_SIZE);
28364 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28365 newval |= (S << 10) | hi;
28366 newval2 |= (J1 << 13) | (J2 << 11) | lo;
28367 md_number_to_chars (buf, newval, THUMB_SIZE);
28368 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28370 break;
28372 case BFD_RELOC_THUMB_PCREL_BLX:
28373 /* If there is a blx from a thumb state function to
28374 another thumb function flip this to a bl and warn
28375 about it. */
28377 if (fixP->fx_addsy
28378 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28379 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28380 && THUMB_IS_FUNC (fixP->fx_addsy))
28382 const char *name = S_GET_NAME (fixP->fx_addsy);
28383 as_warn_where (fixP->fx_file, fixP->fx_line,
28384 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
28385 name);
28386 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28387 newval = newval | 0x1000;
28388 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28389 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28390 fixP->fx_done = 1;
28394 goto thumb_bl_common;
28396 case BFD_RELOC_THUMB_PCREL_BRANCH23:
28397 /* A bl from Thumb state ISA to an internal ARM state function
28398 is converted to a blx. */
28399 if (fixP->fx_addsy
28400 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28401 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28402 && ARM_IS_FUNC (fixP->fx_addsy)
28403 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28405 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28406 newval = newval & ~0x1000;
28407 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28408 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
28409 fixP->fx_done = 1;
28412 thumb_bl_common:
28414 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28415 /* For a BLX instruction, make sure that the relocation is rounded up
28416 to a word boundary. This follows the semantics of the instruction
28417 which specifies that bit 1 of the target address will come from bit
28418 1 of the base address. */
28419 value = (value + 3) & ~ 3;
28421 #ifdef OBJ_ELF
28422 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
28423 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28424 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28425 #endif
28427 if (out_of_range_p (value, 22))
28429 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
28430 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28431 else if (out_of_range_p (value, 24))
28432 as_bad_where (fixP->fx_file, fixP->fx_line,
28433 _("Thumb2 branch out of range"));
28436 if (fixP->fx_done || !seg->use_rela_p)
28437 encode_thumb2_b_bl_offset (buf, value);
28439 break;
28441 case BFD_RELOC_THUMB_PCREL_BRANCH25:
28442 if (out_of_range_p (value, 24))
28443 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28445 if (fixP->fx_done || !seg->use_rela_p)
28446 encode_thumb2_b_bl_offset (buf, value);
28448 break;
28450 case BFD_RELOC_8:
28451 if (fixP->fx_done || !seg->use_rela_p)
28452 *buf = value;
28453 break;
28455 case BFD_RELOC_16:
28456 if (fixP->fx_done || !seg->use_rela_p)
28457 md_number_to_chars (buf, value, 2);
28458 break;
28460 #ifdef OBJ_ELF
28461 case BFD_RELOC_ARM_TLS_CALL:
28462 case BFD_RELOC_ARM_THM_TLS_CALL:
28463 case BFD_RELOC_ARM_TLS_DESCSEQ:
28464 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
28465 case BFD_RELOC_ARM_TLS_GOTDESC:
28466 case BFD_RELOC_ARM_TLS_GD32:
28467 case BFD_RELOC_ARM_TLS_LE32:
28468 case BFD_RELOC_ARM_TLS_IE32:
28469 case BFD_RELOC_ARM_TLS_LDM32:
28470 case BFD_RELOC_ARM_TLS_LDO32:
28471 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28472 break;
28474 /* Same handling as above, but with the arm_fdpic guard. */
28475 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
28476 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
28477 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
28478 if (arm_fdpic)
28480 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28482 else
28484 as_bad_where (fixP->fx_file, fixP->fx_line,
28485 _("Relocation supported only in FDPIC mode"));
28487 break;
28489 case BFD_RELOC_ARM_GOT32:
28490 case BFD_RELOC_ARM_GOTOFF:
28491 break;
28493 case BFD_RELOC_ARM_GOT_PREL:
28494 if (fixP->fx_done || !seg->use_rela_p)
28495 md_number_to_chars (buf, value, 4);
28496 break;
28498 case BFD_RELOC_ARM_TARGET2:
28499 /* TARGET2 is not partial-inplace, so we need to write the
28500 addend here for REL targets, because it won't be written out
28501 during reloc processing later. */
28502 if (fixP->fx_done || !seg->use_rela_p)
28503 md_number_to_chars (buf, fixP->fx_offset, 4);
28504 break;
28506 /* Relocations for FDPIC. */
28507 case BFD_RELOC_ARM_GOTFUNCDESC:
28508 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
28509 case BFD_RELOC_ARM_FUNCDESC:
28510 if (arm_fdpic)
28512 if (fixP->fx_done || !seg->use_rela_p)
28513 md_number_to_chars (buf, 0, 4);
28515 else
28517 as_bad_where (fixP->fx_file, fixP->fx_line,
28518 _("Relocation supported only in FDPIC mode"));
28520 break;
28521 #endif
28523 case BFD_RELOC_RVA:
28524 case BFD_RELOC_32:
28525 case BFD_RELOC_ARM_TARGET1:
28526 case BFD_RELOC_ARM_ROSEGREL32:
28527 case BFD_RELOC_ARM_SBREL32:
28528 case BFD_RELOC_32_PCREL:
28529 #ifdef TE_PE
28530 case BFD_RELOC_32_SECREL:
28531 #endif
28532 if (fixP->fx_done || !seg->use_rela_p)
28533 #ifdef TE_WINCE
28534 /* For WinCE we only do this for pcrel fixups. */
28535 if (fixP->fx_done || fixP->fx_pcrel)
28536 #endif
28537 md_number_to_chars (buf, value, 4);
28538 break;
28540 #ifdef OBJ_ELF
28541 case BFD_RELOC_ARM_PREL31:
28542 if (fixP->fx_done || !seg->use_rela_p)
28544 newval = md_chars_to_number (buf, 4) & 0x80000000;
28545 if ((value ^ (value >> 1)) & 0x40000000)
28547 as_bad_where (fixP->fx_file, fixP->fx_line,
28548 _("rel31 relocation overflow"));
28550 newval |= value & 0x7fffffff;
28551 md_number_to_chars (buf, newval, 4);
28553 break;
28554 #endif
28556 case BFD_RELOC_ARM_CP_OFF_IMM:
28557 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
28558 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
28559 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
28560 newval = md_chars_to_number (buf, INSN_SIZE);
28561 else
28562 newval = get_thumb32_insn (buf);
28563 if ((newval & 0x0f200f00) == 0x0d000900)
28565 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
28566 has permitted values that are multiples of 2, in the range -510
28567 to 510. */
28568 if (value + 510 > 510 + 510 || (value & 1))
28569 as_bad_where (fixP->fx_file, fixP->fx_line,
28570 _("co-processor offset out of range"));
28572 else if ((newval & 0xfe001f80) == 0xec000f80)
28574 if (value + 511 > 512 + 511 || (value & 3))
28575 as_bad_where (fixP->fx_file, fixP->fx_line,
28576 _("co-processor offset out of range"));
28578 else if (value + 1023 > 1023 + 1023 || (value & 3))
28579 as_bad_where (fixP->fx_file, fixP->fx_line,
28580 _("co-processor offset out of range"));
28581 cp_off_common:
28582 sign = (offsetT) value > 0;
28583 if ((offsetT) value < 0)
28584 value = -value;
28585 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28586 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28587 newval = md_chars_to_number (buf, INSN_SIZE);
28588 else
28589 newval = get_thumb32_insn (buf);
28590 if (value == 0)
28592 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28593 newval &= 0xffffff80;
28594 else
28595 newval &= 0xffffff00;
28597 else
28599 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28600 newval &= 0xff7fff80;
28601 else
28602 newval &= 0xff7fff00;
28603 if ((newval & 0x0f200f00) == 0x0d000900)
28605 /* This is a fp16 vstr/vldr.
28607 It requires the immediate offset in the instruction is shifted
28608 left by 1 to be a half-word offset.
28610 Here, left shift by 1 first, and later right shift by 2
28611 should get the right offset. */
28612 value <<= 1;
28614 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
28616 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28617 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28618 md_number_to_chars (buf, newval, INSN_SIZE);
28619 else
28620 put_thumb32_insn (buf, newval);
28621 break;
28623 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
28624 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
28625 if (value + 255 > 255 + 255)
28626 as_bad_where (fixP->fx_file, fixP->fx_line,
28627 _("co-processor offset out of range"));
28628 value *= 4;
28629 goto cp_off_common;
28631 case BFD_RELOC_ARM_THUMB_OFFSET:
28632 newval = md_chars_to_number (buf, THUMB_SIZE);
28633 /* Exactly what ranges, and where the offset is inserted depends
28634 on the type of instruction, we can establish this from the
28635 top 4 bits. */
28636 switch (newval >> 12)
28638 case 4: /* PC load. */
28639 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
28640 forced to zero for these loads; md_pcrel_from has already
28641 compensated for this. */
28642 if (value & 3)
28643 as_bad_where (fixP->fx_file, fixP->fx_line,
28644 _("invalid offset, target not word aligned (0x%08lX)"),
28645 (((unsigned long) fixP->fx_frag->fr_address
28646 + (unsigned long) fixP->fx_where) & ~3)
28647 + (unsigned long) value);
28648 else if (get_recorded_alignment (seg) < 2)
28649 as_warn_where (fixP->fx_file, fixP->fx_line,
28650 _("section does not have enough alignment to ensure safe PC-relative loads"));
28652 if (value & ~0x3fc)
28653 as_bad_where (fixP->fx_file, fixP->fx_line,
28654 _("invalid offset, value too big (0x%08lX)"),
28655 (long) value);
28657 newval |= value >> 2;
28658 break;
28660 case 9: /* SP load/store. */
28661 if (value & ~0x3fc)
28662 as_bad_where (fixP->fx_file, fixP->fx_line,
28663 _("invalid offset, value too big (0x%08lX)"),
28664 (long) value);
28665 newval |= value >> 2;
28666 break;
28668 case 6: /* Word load/store. */
28669 if (value & ~0x7c)
28670 as_bad_where (fixP->fx_file, fixP->fx_line,
28671 _("invalid offset, value too big (0x%08lX)"),
28672 (long) value);
28673 newval |= value << 4; /* 6 - 2. */
28674 break;
28676 case 7: /* Byte load/store. */
28677 if (value & ~0x1f)
28678 as_bad_where (fixP->fx_file, fixP->fx_line,
28679 _("invalid offset, value too big (0x%08lX)"),
28680 (long) value);
28681 newval |= value << 6;
28682 break;
28684 case 8: /* Halfword load/store. */
28685 if (value & ~0x3e)
28686 as_bad_where (fixP->fx_file, fixP->fx_line,
28687 _("invalid offset, value too big (0x%08lX)"),
28688 (long) value);
28689 newval |= value << 5; /* 6 - 1. */
28690 break;
28692 default:
28693 as_bad_where (fixP->fx_file, fixP->fx_line,
28694 "Unable to process relocation for thumb opcode: %lx",
28695 (unsigned long) newval);
28696 break;
28698 md_number_to_chars (buf, newval, THUMB_SIZE);
28699 break;
28701 case BFD_RELOC_ARM_THUMB_ADD:
28702 /* This is a complicated relocation, since we use it for all of
28703 the following immediate relocations:
28705 3bit ADD/SUB
28706 8bit ADD/SUB
28707 9bit ADD/SUB SP word-aligned
28708 10bit ADD PC/SP word-aligned
28710 The type of instruction being processed is encoded in the
28711 instruction field:
28713 0x8000 SUB
28714 0x00F0 Rd
28715 0x000F Rs
28717 newval = md_chars_to_number (buf, THUMB_SIZE);
28719 int rd = (newval >> 4) & 0xf;
28720 int rs = newval & 0xf;
28721 int subtract = !!(newval & 0x8000);
28723 /* Check for HI regs, only very restricted cases allowed:
28724 Adjusting SP, and using PC or SP to get an address. */
28725 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
28726 || (rs > 7 && rs != REG_SP && rs != REG_PC))
28727 as_bad_where (fixP->fx_file, fixP->fx_line,
28728 _("invalid Hi register with immediate"));
28730 /* If value is negative, choose the opposite instruction. */
28731 if ((offsetT) value < 0)
28733 value = -value;
28734 subtract = !subtract;
28735 if ((offsetT) value < 0)
28736 as_bad_where (fixP->fx_file, fixP->fx_line,
28737 _("immediate value out of range"));
28740 if (rd == REG_SP)
28742 if (value & ~0x1fc)
28743 as_bad_where (fixP->fx_file, fixP->fx_line,
28744 _("invalid immediate for stack address calculation"));
28745 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
28746 newval |= value >> 2;
28748 else if (rs == REG_PC || rs == REG_SP)
28750 /* PR gas/18541. If the addition is for a defined symbol
28751 within range of an ADR instruction then accept it. */
28752 if (subtract
28753 && value == 4
28754 && fixP->fx_addsy != NULL)
28756 subtract = 0;
28758 if (! S_IS_DEFINED (fixP->fx_addsy)
28759 || S_GET_SEGMENT (fixP->fx_addsy) != seg
28760 || S_IS_WEAK (fixP->fx_addsy))
28762 as_bad_where (fixP->fx_file, fixP->fx_line,
28763 _("address calculation needs a strongly defined nearby symbol"));
28765 else
28767 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
28769 /* Round up to the next 4-byte boundary. */
28770 if (v & 3)
28771 v = (v + 3) & ~ 3;
28772 else
28773 v += 4;
28774 v = S_GET_VALUE (fixP->fx_addsy) - v;
28776 if (v & ~0x3fc)
28778 as_bad_where (fixP->fx_file, fixP->fx_line,
28779 _("symbol too far away"));
28781 else
28783 fixP->fx_done = 1;
28784 value = v;
28789 if (subtract || value & ~0x3fc)
28790 as_bad_where (fixP->fx_file, fixP->fx_line,
28791 _("invalid immediate for address calculation (value = 0x%08lX)"),
28792 (unsigned long) (subtract ? - value : value));
28793 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
28794 newval |= rd << 8;
28795 newval |= value >> 2;
28797 else if (rs == rd)
28799 if (value & ~0xff)
28800 as_bad_where (fixP->fx_file, fixP->fx_line,
28801 _("immediate value out of range"));
28802 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
28803 newval |= (rd << 8) | value;
28805 else
28807 if (value & ~0x7)
28808 as_bad_where (fixP->fx_file, fixP->fx_line,
28809 _("immediate value out of range"));
28810 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
28811 newval |= rd | (rs << 3) | (value << 6);
28814 md_number_to_chars (buf, newval, THUMB_SIZE);
28815 break;
28817 case BFD_RELOC_ARM_THUMB_IMM:
28818 newval = md_chars_to_number (buf, THUMB_SIZE);
28819 if (value > 255)
28820 as_bad_where (fixP->fx_file, fixP->fx_line,
28821 _("invalid immediate: %ld is out of range"),
28822 (long) value);
28823 newval |= value;
28824 md_number_to_chars (buf, newval, THUMB_SIZE);
28825 break;
28827 case BFD_RELOC_ARM_THUMB_SHIFT:
28828 /* 5bit shift value (0..32). LSL cannot take 32. */
28829 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
28830 temp = newval & 0xf800;
28831 if (value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
28832 as_bad_where (fixP->fx_file, fixP->fx_line,
28833 _("invalid shift value: %ld"), (long) value);
28834 /* Shifts of zero must be encoded as LSL. */
28835 if (value == 0)
28836 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
28837 /* Shifts of 32 are encoded as zero. */
28838 else if (value == 32)
28839 value = 0;
28840 newval |= value << 6;
28841 md_number_to_chars (buf, newval, THUMB_SIZE);
28842 break;
28844 case BFD_RELOC_VTABLE_INHERIT:
28845 case BFD_RELOC_VTABLE_ENTRY:
28846 fixP->fx_done = 0;
28847 return;
28849 case BFD_RELOC_ARM_MOVW:
28850 case BFD_RELOC_ARM_MOVT:
28851 case BFD_RELOC_ARM_THUMB_MOVW:
28852 case BFD_RELOC_ARM_THUMB_MOVT:
28853 if (fixP->fx_done || !seg->use_rela_p)
28855 /* REL format relocations are limited to a 16-bit addend. */
28856 if (!fixP->fx_done)
28858 if (value + 0x8000 > 0x7fff + 0x8000)
28859 as_bad_where (fixP->fx_file, fixP->fx_line,
28860 _("offset out of range"));
28862 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
28863 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28865 value >>= 16;
28868 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
28869 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28871 newval = get_thumb32_insn (buf);
28872 newval &= 0xfbf08f00;
28873 newval |= (value & 0xf000) << 4;
28874 newval |= (value & 0x0800) << 15;
28875 newval |= (value & 0x0700) << 4;
28876 newval |= (value & 0x00ff);
28877 put_thumb32_insn (buf, newval);
28879 else
28881 newval = md_chars_to_number (buf, 4);
28882 newval &= 0xfff0f000;
28883 newval |= value & 0x0fff;
28884 newval |= (value & 0xf000) << 4;
28885 md_number_to_chars (buf, newval, 4);
28888 return;
28890 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
28891 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
28892 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
28893 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
28894 gas_assert (!fixP->fx_done);
28896 bfd_vma insn;
28897 bool is_mov;
28898 bfd_vma encoded_addend = value;
28900 /* Check that addend can be encoded in instruction. */
28901 if (!seg->use_rela_p && value > 255)
28902 as_bad_where (fixP->fx_file, fixP->fx_line,
28903 _("the offset 0x%08lX is not representable"),
28904 (unsigned long) encoded_addend);
28906 /* Extract the instruction. */
28907 insn = md_chars_to_number (buf, THUMB_SIZE);
28908 is_mov = (insn & 0xf800) == 0x2000;
28910 /* Encode insn. */
28911 if (is_mov)
28913 if (!seg->use_rela_p)
28914 insn |= encoded_addend;
28916 else
28918 int rd, rs;
28920 /* Extract the instruction. */
28921 /* Encoding is the following
28922 0x8000 SUB
28923 0x00F0 Rd
28924 0x000F Rs
28926 /* The following conditions must be true :
28927 - ADD
28928 - Rd == Rs
28929 - Rd <= 7
28931 rd = (insn >> 4) & 0xf;
28932 rs = insn & 0xf;
28933 if ((insn & 0x8000) || (rd != rs) || rd > 7)
28934 as_bad_where (fixP->fx_file, fixP->fx_line,
28935 _("Unable to process relocation for thumb opcode: %lx"),
28936 (unsigned long) insn);
28938 /* Encode as ADD immediate8 thumb 1 code. */
28939 insn = 0x3000 | (rd << 8);
28941 /* Place the encoded addend into the first 8 bits of the
28942 instruction. */
28943 if (!seg->use_rela_p)
28944 insn |= encoded_addend;
28947 /* Update the instruction. */
28948 md_number_to_chars (buf, insn, THUMB_SIZE);
28950 break;
28952 case BFD_RELOC_ARM_ALU_PC_G0_NC:
28953 case BFD_RELOC_ARM_ALU_PC_G0:
28954 case BFD_RELOC_ARM_ALU_PC_G1_NC:
28955 case BFD_RELOC_ARM_ALU_PC_G1:
28956 case BFD_RELOC_ARM_ALU_PC_G2:
28957 case BFD_RELOC_ARM_ALU_SB_G0_NC:
28958 case BFD_RELOC_ARM_ALU_SB_G0:
28959 case BFD_RELOC_ARM_ALU_SB_G1_NC:
28960 case BFD_RELOC_ARM_ALU_SB_G1:
28961 case BFD_RELOC_ARM_ALU_SB_G2:
28962 gas_assert (!fixP->fx_done);
28963 if (!seg->use_rela_p)
28965 bfd_vma insn;
28966 bfd_vma encoded_addend;
28967 bfd_vma addend_abs = llabs ((offsetT) value);
28969 /* Check that the absolute value of the addend can be
28970 expressed as an 8-bit constant plus a rotation. */
28971 encoded_addend = encode_arm_immediate (addend_abs);
28972 if (encoded_addend == (unsigned int) FAIL)
28973 as_bad_where (fixP->fx_file, fixP->fx_line,
28974 _("the offset 0x%08lX is not representable"),
28975 (unsigned long) addend_abs);
28977 /* Extract the instruction. */
28978 insn = md_chars_to_number (buf, INSN_SIZE);
28980 /* If the addend is positive, use an ADD instruction.
28981 Otherwise use a SUB. Take care not to destroy the S bit. */
28982 insn &= 0xff1fffff;
28983 if ((offsetT) value < 0)
28984 insn |= 1 << 22;
28985 else
28986 insn |= 1 << 23;
28988 /* Place the encoded addend into the first 12 bits of the
28989 instruction. */
28990 insn &= 0xfffff000;
28991 insn |= encoded_addend;
28993 /* Update the instruction. */
28994 md_number_to_chars (buf, insn, INSN_SIZE);
28996 break;
28998 case BFD_RELOC_ARM_LDR_PC_G0:
28999 case BFD_RELOC_ARM_LDR_PC_G1:
29000 case BFD_RELOC_ARM_LDR_PC_G2:
29001 case BFD_RELOC_ARM_LDR_SB_G0:
29002 case BFD_RELOC_ARM_LDR_SB_G1:
29003 case BFD_RELOC_ARM_LDR_SB_G2:
29004 gas_assert (!fixP->fx_done);
29005 if (!seg->use_rela_p)
29007 bfd_vma insn;
29008 bfd_vma addend_abs = llabs ((offsetT) value);
29010 /* Check that the absolute value of the addend can be
29011 encoded in 12 bits. */
29012 if (addend_abs >= 0x1000)
29013 as_bad_where (fixP->fx_file, fixP->fx_line,
29014 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29015 (unsigned long) addend_abs);
29017 /* Extract the instruction. */
29018 insn = md_chars_to_number (buf, INSN_SIZE);
29020 /* If the addend is negative, clear bit 23 of the instruction.
29021 Otherwise set it. */
29022 if ((offsetT) value < 0)
29023 insn &= ~(1 << 23);
29024 else
29025 insn |= 1 << 23;
29027 /* Place the absolute value of the addend into the first 12 bits
29028 of the instruction. */
29029 insn &= 0xfffff000;
29030 insn |= addend_abs;
29032 /* Update the instruction. */
29033 md_number_to_chars (buf, insn, INSN_SIZE);
29035 break;
29037 case BFD_RELOC_ARM_LDRS_PC_G0:
29038 case BFD_RELOC_ARM_LDRS_PC_G1:
29039 case BFD_RELOC_ARM_LDRS_PC_G2:
29040 case BFD_RELOC_ARM_LDRS_SB_G0:
29041 case BFD_RELOC_ARM_LDRS_SB_G1:
29042 case BFD_RELOC_ARM_LDRS_SB_G2:
29043 gas_assert (!fixP->fx_done);
29044 if (!seg->use_rela_p)
29046 bfd_vma insn;
29047 bfd_vma addend_abs = llabs ((offsetT) value);
29049 /* Check that the absolute value of the addend can be
29050 encoded in 8 bits. */
29051 if (addend_abs >= 0x100)
29052 as_bad_where (fixP->fx_file, fixP->fx_line,
29053 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29054 (unsigned long) addend_abs);
29056 /* Extract the instruction. */
29057 insn = md_chars_to_number (buf, INSN_SIZE);
29059 /* If the addend is negative, clear bit 23 of the instruction.
29060 Otherwise set it. */
29061 if ((offsetT) value < 0)
29062 insn &= ~(1 << 23);
29063 else
29064 insn |= 1 << 23;
29066 /* Place the first four bits of the absolute value of the addend
29067 into the first 4 bits of the instruction, and the remaining
29068 four into bits 8 .. 11. */
29069 insn &= 0xfffff0f0;
29070 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29072 /* Update the instruction. */
29073 md_number_to_chars (buf, insn, INSN_SIZE);
29075 break;
29077 case BFD_RELOC_ARM_LDC_PC_G0:
29078 case BFD_RELOC_ARM_LDC_PC_G1:
29079 case BFD_RELOC_ARM_LDC_PC_G2:
29080 case BFD_RELOC_ARM_LDC_SB_G0:
29081 case BFD_RELOC_ARM_LDC_SB_G1:
29082 case BFD_RELOC_ARM_LDC_SB_G2:
29083 gas_assert (!fixP->fx_done);
29084 if (!seg->use_rela_p)
29086 bfd_vma insn;
29087 bfd_vma addend_abs = llabs ((offsetT) value);
29089 /* Check that the absolute value of the addend is a multiple of
29090 four and, when divided by four, fits in 8 bits. */
29091 if (addend_abs & 0x3)
29092 as_bad_where (fixP->fx_file, fixP->fx_line,
29093 _("bad offset 0x%08lX (must be word-aligned)"),
29094 (unsigned long) addend_abs);
29096 if ((addend_abs >> 2) > 0xff)
29097 as_bad_where (fixP->fx_file, fixP->fx_line,
29098 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29099 (unsigned long) addend_abs);
29101 /* Extract the instruction. */
29102 insn = md_chars_to_number (buf, INSN_SIZE);
29104 /* If the addend is negative, clear bit 23 of the instruction.
29105 Otherwise set it. */
29106 if ((offsetT) value < 0)
29107 insn &= ~(1 << 23);
29108 else
29109 insn |= 1 << 23;
29111 /* Place the addend (divided by four) into the first eight
29112 bits of the instruction. */
29113 insn &= 0xfffffff0;
29114 insn |= addend_abs >> 2;
29116 /* Update the instruction. */
29117 md_number_to_chars (buf, insn, INSN_SIZE);
29119 break;
29121 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29122 if (fixP->fx_addsy
29123 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29124 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29125 && ARM_IS_FUNC (fixP->fx_addsy)
29126 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29128 /* Force a relocation for a branch 5 bits wide. */
29129 fixP->fx_done = 0;
29131 if (v8_1_branch_value_check (value, 5, false) == FAIL)
29132 as_bad_where (fixP->fx_file, fixP->fx_line,
29133 BAD_BRANCH_OFF);
29135 if (fixP->fx_done || !seg->use_rela_p)
29137 addressT boff = value >> 1;
29139 newval = md_chars_to_number (buf, THUMB_SIZE);
29140 newval |= (boff << 7);
29141 md_number_to_chars (buf, newval, THUMB_SIZE);
29143 break;
29145 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29146 if (fixP->fx_addsy
29147 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29148 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29149 && ARM_IS_FUNC (fixP->fx_addsy)
29150 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29152 fixP->fx_done = 0;
29154 if ((value & ~0x7f) && ((value & ~0x3f) != (valueT) ~0x3f))
29155 as_bad_where (fixP->fx_file, fixP->fx_line,
29156 _("branch out of range"));
29158 if (fixP->fx_done || !seg->use_rela_p)
29160 newval = md_chars_to_number (buf, THUMB_SIZE);
29162 addressT boff = ((newval & 0x0780) >> 7) << 1;
29163 addressT diff = value - boff;
29165 if (diff == 4)
29167 newval |= 1 << 1; /* T bit. */
29169 else if (diff != 2)
29171 as_bad_where (fixP->fx_file, fixP->fx_line,
29172 _("out of range label-relative fixup value"));
29174 md_number_to_chars (buf, newval, THUMB_SIZE);
29176 break;
29178 case BFD_RELOC_ARM_THUMB_BF17:
29179 if (fixP->fx_addsy
29180 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29181 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29182 && ARM_IS_FUNC (fixP->fx_addsy)
29183 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29185 /* Force a relocation for a branch 17 bits wide. */
29186 fixP->fx_done = 0;
29189 if (v8_1_branch_value_check (value, 17, true) == FAIL)
29190 as_bad_where (fixP->fx_file, fixP->fx_line,
29191 BAD_BRANCH_OFF);
29193 if (fixP->fx_done || !seg->use_rela_p)
29195 offsetT newval2;
29196 addressT immA, immB, immC;
29198 immA = (value & 0x0001f000) >> 12;
29199 immB = (value & 0x00000ffc) >> 2;
29200 immC = (value & 0x00000002) >> 1;
29202 newval = md_chars_to_number (buf, THUMB_SIZE);
29203 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29204 newval |= immA;
29205 newval2 |= (immC << 11) | (immB << 1);
29206 md_number_to_chars (buf, newval, THUMB_SIZE);
29207 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29209 break;
29211 case BFD_RELOC_ARM_THUMB_BF19:
29212 if (fixP->fx_addsy
29213 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29214 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29215 && ARM_IS_FUNC (fixP->fx_addsy)
29216 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29218 /* Force a relocation for a branch 19 bits wide. */
29219 fixP->fx_done = 0;
29222 if (v8_1_branch_value_check (value, 19, true) == FAIL)
29223 as_bad_where (fixP->fx_file, fixP->fx_line,
29224 BAD_BRANCH_OFF);
29226 if (fixP->fx_done || !seg->use_rela_p)
29228 offsetT newval2;
29229 addressT immA, immB, immC;
29231 immA = (value & 0x0007f000) >> 12;
29232 immB = (value & 0x00000ffc) >> 2;
29233 immC = (value & 0x00000002) >> 1;
29235 newval = md_chars_to_number (buf, THUMB_SIZE);
29236 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29237 newval |= immA;
29238 newval2 |= (immC << 11) | (immB << 1);
29239 md_number_to_chars (buf, newval, THUMB_SIZE);
29240 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29242 break;
29244 case BFD_RELOC_ARM_THUMB_BF13:
29245 if (fixP->fx_addsy
29246 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29247 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29248 && ARM_IS_FUNC (fixP->fx_addsy)
29249 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29251 /* Force a relocation for a branch 13 bits wide. */
29252 fixP->fx_done = 0;
29255 if (v8_1_branch_value_check (value, 13, true) == FAIL)
29256 as_bad_where (fixP->fx_file, fixP->fx_line,
29257 BAD_BRANCH_OFF);
29259 if (fixP->fx_done || !seg->use_rela_p)
29261 offsetT newval2;
29262 addressT immA, immB, immC;
29264 immA = (value & 0x00001000) >> 12;
29265 immB = (value & 0x00000ffc) >> 2;
29266 immC = (value & 0x00000002) >> 1;
29268 newval = md_chars_to_number (buf, THUMB_SIZE);
29269 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29270 newval |= immA;
29271 newval2 |= (immC << 11) | (immB << 1);
29272 md_number_to_chars (buf, newval, THUMB_SIZE);
29273 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29275 break;
29277 case BFD_RELOC_ARM_THUMB_LOOP12:
29278 if (fixP->fx_addsy
29279 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29280 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29281 && ARM_IS_FUNC (fixP->fx_addsy)
29282 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29284 /* Force a relocation for a branch 12 bits wide. */
29285 fixP->fx_done = 0;
29288 bfd_vma insn = get_thumb32_insn (buf);
29289 /* le lr, <label>, le <label> or letp lr, <label> */
29290 if (((insn & 0xffffffff) == 0xf00fc001)
29291 || ((insn & 0xffffffff) == 0xf02fc001)
29292 || ((insn & 0xffffffff) == 0xf01fc001))
29293 value = -value;
29295 if (v8_1_branch_value_check (value, 12, false) == FAIL)
29296 as_bad_where (fixP->fx_file, fixP->fx_line,
29297 BAD_BRANCH_OFF);
29298 if (fixP->fx_done || !seg->use_rela_p)
29300 addressT imml, immh;
29302 immh = (value & 0x00000ffc) >> 2;
29303 imml = (value & 0x00000002) >> 1;
29305 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29306 newval |= (imml << 11) | (immh << 1);
29307 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29309 break;
29311 case BFD_RELOC_ARM_V4BX:
29312 /* This will need to go in the object file. */
29313 fixP->fx_done = 0;
29314 break;
29316 case BFD_RELOC_UNUSED:
29317 default:
29318 as_bad_where (fixP->fx_file, fixP->fx_line,
29319 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29323 /* Translate internal representation of relocation info to BFD target
29324 format. */
29326 arelent *
29327 tc_gen_reloc (asection *section, fixS *fixp)
29329 arelent * reloc;
29330 bfd_reloc_code_real_type code;
29332 reloc = XNEW (arelent);
29334 reloc->sym_ptr_ptr = XNEW (asymbol *);
29335 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29336 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
29338 if (fixp->fx_pcrel)
29340 if (section->use_rela_p)
29341 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
29342 else
29343 fixp->fx_offset = reloc->address;
29345 reloc->addend = fixp->fx_offset;
29347 switch (fixp->fx_r_type)
29349 case BFD_RELOC_8:
29350 if (fixp->fx_pcrel)
29352 code = BFD_RELOC_8_PCREL;
29353 break;
29355 /* Fall through. */
29357 case BFD_RELOC_16:
29358 if (fixp->fx_pcrel)
29360 code = BFD_RELOC_16_PCREL;
29361 break;
29363 /* Fall through. */
29365 case BFD_RELOC_32:
29366 if (fixp->fx_pcrel)
29368 code = BFD_RELOC_32_PCREL;
29369 break;
29371 /* Fall through. */
29373 case BFD_RELOC_ARM_MOVW:
29374 if (fixp->fx_pcrel)
29376 code = BFD_RELOC_ARM_MOVW_PCREL;
29377 break;
29379 /* Fall through. */
29381 case BFD_RELOC_ARM_MOVT:
29382 if (fixp->fx_pcrel)
29384 code = BFD_RELOC_ARM_MOVT_PCREL;
29385 break;
29387 /* Fall through. */
29389 case BFD_RELOC_ARM_THUMB_MOVW:
29390 if (fixp->fx_pcrel)
29392 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
29393 break;
29395 /* Fall through. */
29397 case BFD_RELOC_ARM_THUMB_MOVT:
29398 if (fixp->fx_pcrel)
29400 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
29401 break;
29403 /* Fall through. */
29405 case BFD_RELOC_NONE:
29406 case BFD_RELOC_ARM_PCREL_BRANCH:
29407 case BFD_RELOC_ARM_PCREL_BLX:
29408 case BFD_RELOC_RVA:
29409 case BFD_RELOC_THUMB_PCREL_BRANCH7:
29410 case BFD_RELOC_THUMB_PCREL_BRANCH9:
29411 case BFD_RELOC_THUMB_PCREL_BRANCH12:
29412 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29413 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29414 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29415 case BFD_RELOC_VTABLE_ENTRY:
29416 case BFD_RELOC_VTABLE_INHERIT:
29417 #ifdef TE_PE
29418 case BFD_RELOC_32_SECREL:
29419 #endif
29420 code = fixp->fx_r_type;
29421 break;
29423 case BFD_RELOC_THUMB_PCREL_BLX:
29424 #ifdef OBJ_ELF
29425 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
29426 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
29427 else
29428 #endif
29429 code = BFD_RELOC_THUMB_PCREL_BLX;
29430 break;
29432 case BFD_RELOC_ARM_LITERAL:
29433 case BFD_RELOC_ARM_HWLITERAL:
29434 /* If this is called then the a literal has
29435 been referenced across a section boundary. */
29436 as_bad_where (fixp->fx_file, fixp->fx_line,
29437 _("literal referenced across section boundary"));
29438 return NULL;
29440 #ifdef OBJ_ELF
29441 case BFD_RELOC_ARM_TLS_CALL:
29442 case BFD_RELOC_ARM_THM_TLS_CALL:
29443 case BFD_RELOC_ARM_TLS_DESCSEQ:
29444 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
29445 case BFD_RELOC_ARM_GOT32:
29446 case BFD_RELOC_ARM_GOTOFF:
29447 case BFD_RELOC_ARM_GOT_PREL:
29448 case BFD_RELOC_ARM_PLT32:
29449 case BFD_RELOC_ARM_TARGET1:
29450 case BFD_RELOC_ARM_ROSEGREL32:
29451 case BFD_RELOC_ARM_SBREL32:
29452 case BFD_RELOC_ARM_PREL31:
29453 case BFD_RELOC_ARM_TARGET2:
29454 case BFD_RELOC_ARM_TLS_LDO32:
29455 case BFD_RELOC_ARM_PCREL_CALL:
29456 case BFD_RELOC_ARM_PCREL_JUMP:
29457 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29458 case BFD_RELOC_ARM_ALU_PC_G0:
29459 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29460 case BFD_RELOC_ARM_ALU_PC_G1:
29461 case BFD_RELOC_ARM_ALU_PC_G2:
29462 case BFD_RELOC_ARM_LDR_PC_G0:
29463 case BFD_RELOC_ARM_LDR_PC_G1:
29464 case BFD_RELOC_ARM_LDR_PC_G2:
29465 case BFD_RELOC_ARM_LDRS_PC_G0:
29466 case BFD_RELOC_ARM_LDRS_PC_G1:
29467 case BFD_RELOC_ARM_LDRS_PC_G2:
29468 case BFD_RELOC_ARM_LDC_PC_G0:
29469 case BFD_RELOC_ARM_LDC_PC_G1:
29470 case BFD_RELOC_ARM_LDC_PC_G2:
29471 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29472 case BFD_RELOC_ARM_ALU_SB_G0:
29473 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29474 case BFD_RELOC_ARM_ALU_SB_G1:
29475 case BFD_RELOC_ARM_ALU_SB_G2:
29476 case BFD_RELOC_ARM_LDR_SB_G0:
29477 case BFD_RELOC_ARM_LDR_SB_G1:
29478 case BFD_RELOC_ARM_LDR_SB_G2:
29479 case BFD_RELOC_ARM_LDRS_SB_G0:
29480 case BFD_RELOC_ARM_LDRS_SB_G1:
29481 case BFD_RELOC_ARM_LDRS_SB_G2:
29482 case BFD_RELOC_ARM_LDC_SB_G0:
29483 case BFD_RELOC_ARM_LDC_SB_G1:
29484 case BFD_RELOC_ARM_LDC_SB_G2:
29485 case BFD_RELOC_ARM_V4BX:
29486 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29487 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29488 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29489 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29490 case BFD_RELOC_ARM_GOTFUNCDESC:
29491 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29492 case BFD_RELOC_ARM_FUNCDESC:
29493 case BFD_RELOC_ARM_THUMB_BF17:
29494 case BFD_RELOC_ARM_THUMB_BF19:
29495 case BFD_RELOC_ARM_THUMB_BF13:
29496 code = fixp->fx_r_type;
29497 break;
29499 case BFD_RELOC_ARM_TLS_GOTDESC:
29500 case BFD_RELOC_ARM_TLS_GD32:
29501 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29502 case BFD_RELOC_ARM_TLS_LE32:
29503 case BFD_RELOC_ARM_TLS_IE32:
29504 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29505 case BFD_RELOC_ARM_TLS_LDM32:
29506 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29507 /* BFD will include the symbol's address in the addend.
29508 But we don't want that, so subtract it out again here. */
29509 if (!S_IS_COMMON (fixp->fx_addsy))
29510 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
29511 code = fixp->fx_r_type;
29512 break;
29513 #endif
29515 case BFD_RELOC_ARM_IMMEDIATE:
29516 as_bad_where (fixp->fx_file, fixp->fx_line,
29517 _("internal relocation (type: IMMEDIATE) not fixed up"));
29518 return NULL;
29520 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
29521 as_bad_where (fixp->fx_file, fixp->fx_line,
29522 _("ADRL used for a symbol not defined in the same file"));
29523 return NULL;
29525 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29526 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29527 case BFD_RELOC_ARM_THUMB_LOOP12:
29528 as_bad_where (fixp->fx_file, fixp->fx_line,
29529 _("%s used for a symbol not defined in the same file"),
29530 bfd_get_reloc_code_name (fixp->fx_r_type));
29531 return NULL;
29533 case BFD_RELOC_ARM_OFFSET_IMM:
29534 if (section->use_rela_p)
29536 code = fixp->fx_r_type;
29537 break;
29540 if (fixp->fx_addsy != NULL
29541 && !S_IS_DEFINED (fixp->fx_addsy)
29542 && S_IS_LOCAL (fixp->fx_addsy))
29544 as_bad_where (fixp->fx_file, fixp->fx_line,
29545 _("undefined local label `%s'"),
29546 S_GET_NAME (fixp->fx_addsy));
29547 return NULL;
29550 as_bad_where (fixp->fx_file, fixp->fx_line,
29551 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
29552 return NULL;
29554 default:
29556 const char * type;
29558 switch (fixp->fx_r_type)
29560 case BFD_RELOC_NONE: type = "NONE"; break;
29561 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
29562 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
29563 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
29564 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
29565 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
29566 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
29567 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
29568 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
29569 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
29570 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
29571 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
29572 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
29573 default: type = _("<unknown>"); break;
29575 as_bad_where (fixp->fx_file, fixp->fx_line,
29576 _("cannot represent %s relocation in this object file format"),
29577 type);
29578 return NULL;
29582 #ifdef OBJ_ELF
29583 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
29584 && GOT_symbol
29585 && fixp->fx_addsy == GOT_symbol)
29587 code = BFD_RELOC_ARM_GOTPC;
29588 reloc->addend = fixp->fx_offset = reloc->address;
29590 #endif
29592 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
29594 if (reloc->howto == NULL)
29596 as_bad_where (fixp->fx_file, fixp->fx_line,
29597 _("cannot represent %s relocation in this object file format"),
29598 bfd_get_reloc_code_name (code));
29599 return NULL;
29602 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
29603 vtable entry to be used in the relocation's section offset. */
29604 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
29605 reloc->address = fixp->fx_offset;
29607 return reloc;
29610 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
29612 void
29613 cons_fix_new_arm (fragS * frag,
29614 int where,
29615 int size,
29616 expressionS * exp,
29617 bfd_reloc_code_real_type reloc)
29619 int pcrel = 0;
29621 /* Pick a reloc.
29622 FIXME: @@ Should look at CPU word size. */
29623 switch (size)
29625 case 1:
29626 reloc = BFD_RELOC_8;
29627 break;
29628 case 2:
29629 reloc = BFD_RELOC_16;
29630 break;
29631 case 4:
29632 default:
29633 reloc = BFD_RELOC_32;
29634 break;
29635 case 8:
29636 reloc = BFD_RELOC_64;
29637 break;
29640 #ifdef TE_PE
29641 if (exp->X_op == O_secrel)
29643 exp->X_op = O_symbol;
29644 reloc = BFD_RELOC_32_SECREL;
29646 #endif
29648 fix_new_exp (frag, where, size, exp, pcrel, reloc);
29651 #if defined (OBJ_COFF)
29652 void
29653 arm_validate_fix (fixS * fixP)
29655 /* If the destination of the branch is a defined symbol which does not have
29656 the THUMB_FUNC attribute, then we must be calling a function which has
29657 the (interfacearm) attribute. We look for the Thumb entry point to that
29658 function and change the branch to refer to that function instead. */
29659 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
29660 && fixP->fx_addsy != NULL
29661 && S_IS_DEFINED (fixP->fx_addsy)
29662 && ! THUMB_IS_FUNC (fixP->fx_addsy))
29664 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
29667 #endif
29671 arm_force_relocation (struct fix * fixp)
29673 #if defined (OBJ_COFF) && defined (TE_PE)
29674 if (fixp->fx_r_type == BFD_RELOC_RVA)
29675 return 1;
29676 #endif
29678 /* In case we have a call or a branch to a function in ARM ISA mode from
29679 a thumb function or vice-versa force the relocation. These relocations
29680 are cleared off for some cores that might have blx and simple transformations
29681 are possible. */
29683 #ifdef OBJ_ELF
29684 switch (fixp->fx_r_type)
29686 case BFD_RELOC_ARM_PCREL_JUMP:
29687 case BFD_RELOC_ARM_PCREL_CALL:
29688 case BFD_RELOC_THUMB_PCREL_BLX:
29689 if (THUMB_IS_FUNC (fixp->fx_addsy))
29690 return 1;
29691 break;
29693 case BFD_RELOC_ARM_PCREL_BLX:
29694 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29695 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29696 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29697 if (ARM_IS_FUNC (fixp->fx_addsy))
29698 return 1;
29699 break;
29701 default:
29702 break;
29704 #endif
29706 /* Resolve these relocations even if the symbol is extern or weak.
29707 Technically this is probably wrong due to symbol preemption.
29708 In practice these relocations do not have enough range to be useful
29709 at dynamic link time, and some code (e.g. in the Linux kernel)
29710 expects these references to be resolved. */
29711 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
29712 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
29713 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
29714 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
29715 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29716 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
29717 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
29718 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH12
29719 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
29720 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
29721 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
29722 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
29723 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
29724 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
29725 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
29726 return 0;
29728 /* Always leave these relocations for the linker. */
29729 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29730 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29731 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
29732 return 1;
29734 /* Always generate relocations against function symbols. */
29735 if (fixp->fx_r_type == BFD_RELOC_32
29736 && fixp->fx_addsy
29737 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
29738 return 1;
29740 return generic_force_reloc (fixp);
29743 #if defined (OBJ_ELF) || defined (OBJ_COFF)
29744 /* Relocations against function names must be left unadjusted,
29745 so that the linker can use this information to generate interworking
29746 stubs. The MIPS version of this function
29747 also prevents relocations that are mips-16 specific, but I do not
29748 know why it does this.
29750 FIXME:
29751 There is one other problem that ought to be addressed here, but
29752 which currently is not: Taking the address of a label (rather
29753 than a function) and then later jumping to that address. Such
29754 addresses also ought to have their bottom bit set (assuming that
29755 they reside in Thumb code), but at the moment they will not. */
29757 bool
29758 arm_fix_adjustable (fixS * fixP)
29760 if (fixP->fx_addsy == NULL)
29761 return 1;
29763 /* Preserve relocations against symbols with function type. */
29764 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
29765 return false;
29767 if (THUMB_IS_FUNC (fixP->fx_addsy)
29768 && fixP->fx_subsy == NULL)
29769 return false;
29771 /* We need the symbol name for the VTABLE entries. */
29772 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
29773 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
29774 return false;
29776 /* Don't allow symbols to be discarded on GOT related relocs. */
29777 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
29778 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
29779 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
29780 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
29781 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
29782 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
29783 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
29784 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
29785 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
29786 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
29787 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
29788 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
29789 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
29790 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
29791 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
29792 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
29793 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
29794 return false;
29796 /* Similarly for group relocations. */
29797 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29798 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29799 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
29800 return false;
29802 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
29803 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
29804 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29805 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
29806 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
29807 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29808 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
29809 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
29810 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
29811 return false;
29813 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
29814 offsets, so keep these symbols. */
29815 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
29816 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
29817 return false;
29819 return true;
29821 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
29823 #ifdef OBJ_ELF
29824 const char *
29825 elf32_arm_target_format (void)
29827 #if defined (TE_VXWORKS)
29828 return (target_big_endian
29829 ? "elf32-bigarm-vxworks"
29830 : "elf32-littlearm-vxworks");
29831 #elif defined (TE_NACL)
29832 return (target_big_endian
29833 ? "elf32-bigarm-nacl"
29834 : "elf32-littlearm-nacl");
29835 #else
29836 if (arm_fdpic)
29838 if (target_big_endian)
29839 return "elf32-bigarm-fdpic";
29840 else
29841 return "elf32-littlearm-fdpic";
29843 else
29845 if (target_big_endian)
29846 return "elf32-bigarm";
29847 else
29848 return "elf32-littlearm";
29850 #endif
29853 void
29854 armelf_frob_symbol (symbolS * symp,
29855 int * puntp)
29857 elf_frob_symbol (symp, puntp);
29859 #endif
29861 /* MD interface: Finalization. */
29863 void
29864 arm_cleanup (void)
29866 literal_pool * pool;
29868 /* Ensure that all the predication blocks are properly closed. */
29869 check_pred_blocks_finished ();
29871 for (pool = list_of_pools; pool; pool = pool->next)
29873 /* Put it at the end of the relevant section. */
29874 subseg_set (pool->section, pool->sub_section);
29875 #ifdef OBJ_ELF
29876 arm_elf_change_section ();
29877 #endif
29878 s_ltorg (0);
29882 #ifdef OBJ_ELF
29883 /* Remove any excess mapping symbols generated for alignment frags in
29884 SEC. We may have created a mapping symbol before a zero byte
29885 alignment; remove it if there's a mapping symbol after the
29886 alignment. */
29887 static void
29888 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
29889 void *dummy ATTRIBUTE_UNUSED)
29891 segment_info_type *seginfo = seg_info (sec);
29892 fragS *fragp;
29894 if (seginfo == NULL || seginfo->frchainP == NULL)
29895 return;
29897 for (fragp = seginfo->frchainP->frch_root;
29898 fragp != NULL;
29899 fragp = fragp->fr_next)
29901 symbolS *sym = fragp->tc_frag_data.last_map;
29902 fragS *next = fragp->fr_next;
29904 /* Variable-sized frags have been converted to fixed size by
29905 this point. But if this was variable-sized to start with,
29906 there will be a fixed-size frag after it. So don't handle
29907 next == NULL. */
29908 if (sym == NULL || next == NULL)
29909 continue;
29911 if (S_GET_VALUE (sym) < next->fr_address)
29912 /* Not at the end of this frag. */
29913 continue;
29914 know (S_GET_VALUE (sym) == next->fr_address);
29918 if (next->tc_frag_data.first_map != NULL)
29920 /* Next frag starts with a mapping symbol. Discard this
29921 one. */
29922 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29923 break;
29926 if (next->fr_next == NULL)
29928 /* This mapping symbol is at the end of the section. Discard
29929 it. */
29930 know (next->fr_fix == 0 && next->fr_var == 0);
29931 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29932 break;
29935 /* As long as we have empty frags without any mapping symbols,
29936 keep looking. */
29937 /* If the next frag is non-empty and does not start with a
29938 mapping symbol, then this mapping symbol is required. */
29939 if (next->fr_address != next->fr_next->fr_address)
29940 break;
29942 next = next->fr_next;
29944 while (next != NULL);
29947 #endif
29949 /* Adjust the symbol table. This marks Thumb symbols as distinct from
29950 ARM ones. */
29952 void
29953 arm_adjust_symtab (void)
29955 #ifdef OBJ_COFF
29956 symbolS * sym;
29958 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
29960 if (ARM_IS_THUMB (sym))
29962 if (THUMB_IS_FUNC (sym))
29964 /* Mark the symbol as a Thumb function. */
29965 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
29966 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
29967 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
29969 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
29970 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
29971 else
29972 as_bad (_("%s: unexpected function type: %d"),
29973 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
29975 else switch (S_GET_STORAGE_CLASS (sym))
29977 case C_EXT:
29978 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
29979 break;
29980 case C_STAT:
29981 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
29982 break;
29983 case C_LABEL:
29984 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
29985 break;
29986 default:
29987 /* Do nothing. */
29988 break;
29992 if (ARM_IS_INTERWORK (sym))
29993 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
29995 #endif
29996 #ifdef OBJ_ELF
29997 symbolS * sym;
29998 char bind;
30000 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30002 if (ARM_IS_THUMB (sym))
30004 elf_symbol_type * elf_sym;
30006 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30007 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
30009 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30010 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
30012 /* If it's a .thumb_func, declare it as so,
30013 otherwise tag label as .code 16. */
30014 if (THUMB_IS_FUNC (sym))
30015 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30016 ST_BRANCH_TO_THUMB);
30017 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
30018 elf_sym->internal_elf_sym.st_info =
30019 ELF_ST_INFO (bind, STT_ARM_16BIT);
30024 /* Remove any overlapping mapping symbols generated by alignment frags. */
30025 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
30026 /* Now do generic ELF adjustments. */
30027 elf_adjust_symtab ();
30028 #endif
30031 /* MD interface: Initialization. */
30033 static void
30034 set_constant_flonums (void)
30036 int i;
30038 for (i = 0; i < NUM_FLOAT_VALS; i++)
30039 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30040 abort ();
30043 /* Auto-select Thumb mode if it's the only available instruction set for the
30044 given architecture. */
30046 static void
30047 autoselect_thumb_from_cpu_variant (void)
30049 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30050 opcode_select (16);
30053 void
30054 md_begin (void)
30056 unsigned mach;
30057 unsigned int i;
30059 arm_ops_hsh = str_htab_create ();
30060 arm_cond_hsh = str_htab_create ();
30061 arm_vcond_hsh = str_htab_create ();
30062 arm_shift_hsh = str_htab_create ();
30063 arm_psr_hsh = str_htab_create ();
30064 arm_v7m_psr_hsh = str_htab_create ();
30065 arm_reg_hsh = str_htab_create ();
30066 arm_reloc_hsh = str_htab_create ();
30067 arm_barrier_opt_hsh = str_htab_create ();
30069 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
30070 if (str_hash_find (arm_ops_hsh, insns[i].template_name) == NULL)
30071 str_hash_insert (arm_ops_hsh, insns[i].template_name, insns + i, 0);
30072 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
30073 str_hash_insert (arm_cond_hsh, conds[i].template_name, conds + i, 0);
30074 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30075 str_hash_insert (arm_vcond_hsh, vconds[i].template_name, vconds + i, 0);
30076 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
30077 str_hash_insert (arm_shift_hsh, shift_names[i].name, shift_names + i, 0);
30078 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
30079 str_hash_insert (arm_psr_hsh, psrs[i].template_name, psrs + i, 0);
30080 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
30081 str_hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
30082 v7m_psrs + i, 0);
30083 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
30084 str_hash_insert (arm_reg_hsh, reg_names[i].name, reg_names + i, 0);
30085 for (i = 0;
30086 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30087 i++)
30088 str_hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
30089 barrier_opt_names + i, 0);
30090 #ifdef OBJ_ELF
30091 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30093 struct reloc_entry * entry = reloc_names + i;
30095 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30096 /* This makes encode_branch() use the EABI versions of this relocation. */
30097 entry->reloc = BFD_RELOC_UNUSED;
30099 str_hash_insert (arm_reloc_hsh, entry->name, entry, 0);
30101 #endif
30103 set_constant_flonums ();
30105 /* Set the cpu variant based on the command-line options. We prefer
30106 -mcpu= over -march= if both are set (as for GCC); and we prefer
30107 -mfpu= over any other way of setting the floating point unit.
30108 Use of legacy options with new options are faulted. */
30109 if (legacy_cpu)
30111 if (mcpu_cpu_opt || march_cpu_opt)
30112 as_bad (_("use of old and new-style options to set CPU type"));
30114 selected_arch = *legacy_cpu;
30116 else if (mcpu_cpu_opt)
30118 selected_arch = *mcpu_cpu_opt;
30119 selected_ext = *mcpu_ext_opt;
30121 else if (march_cpu_opt)
30123 selected_arch = *march_cpu_opt;
30124 selected_ext = *march_ext_opt;
30126 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
30128 if (legacy_fpu)
30130 if (mfpu_opt)
30131 as_bad (_("use of old and new-style options to set FPU type"));
30133 selected_fpu = *legacy_fpu;
30135 else if (mfpu_opt)
30136 selected_fpu = *mfpu_opt;
30137 else
30139 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30140 || defined (TE_NetBSD) || defined (TE_VXWORKS))
30141 /* Some environments specify a default FPU. If they don't, infer it
30142 from the processor. */
30143 if (mcpu_fpu_opt)
30144 selected_fpu = *mcpu_fpu_opt;
30145 else if (march_fpu_opt)
30146 selected_fpu = *march_fpu_opt;
30147 else
30148 selected_fpu = fpu_default;
30149 #else
30150 selected_fpu = fpu_default;
30151 #endif
30154 #ifdef CPU_DEFAULT
30155 if (ARM_FEATURE_ZERO (selected_arch))
30157 selected_arch = cpu_default;
30158 selected_cpu = selected_arch;
30160 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30161 #else
30162 /* Autodection of feature mode: allow all features in cpu_variant but leave
30163 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30164 after all instruction have been processed and we can decide what CPU
30165 should be selected. */
30166 if (ARM_FEATURE_ZERO (selected_arch))
30167 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
30168 else
30169 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30170 #endif
30172 autoselect_thumb_from_cpu_variant ();
30174 arm_arch_used = thumb_arch_used = arm_arch_none;
30176 #if defined OBJ_COFF || defined OBJ_ELF
30178 unsigned int flags = 0;
30180 #if defined OBJ_ELF
30181 flags = meabi_flags;
30183 switch (meabi_flags)
30185 case EF_ARM_EABI_UNKNOWN:
30186 #endif
30187 /* Set the flags in the private structure. */
30188 if (uses_apcs_26) flags |= F_APCS26;
30189 if (support_interwork) flags |= F_INTERWORK;
30190 if (uses_apcs_float) flags |= F_APCS_FLOAT;
30191 if (pic_code) flags |= F_PIC;
30192 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
30193 flags |= F_SOFT_FLOAT;
30195 switch (mfloat_abi_opt)
30197 case ARM_FLOAT_ABI_SOFT:
30198 case ARM_FLOAT_ABI_SOFTFP:
30199 flags |= F_SOFT_FLOAT;
30200 break;
30202 case ARM_FLOAT_ABI_HARD:
30203 if (flags & F_SOFT_FLOAT)
30204 as_bad (_("hard-float conflicts with specified fpu"));
30205 break;
30208 /* Using pure-endian doubles (even if soft-float). */
30209 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
30210 flags |= F_VFP_FLOAT;
30212 #if defined OBJ_ELF
30213 case EF_ARM_EABI_VER4:
30214 case EF_ARM_EABI_VER5:
30215 /* No additional flags to set. */
30216 break;
30218 default:
30219 abort ();
30221 #endif
30222 bfd_set_private_flags (stdoutput, flags);
30224 /* We have run out flags in the COFF header to encode the
30225 status of ATPCS support, so instead we create a dummy,
30226 empty, debug section called .arm.atpcs. */
30227 if (atpcs)
30229 asection * sec;
30231 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30233 if (sec != NULL)
30235 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30236 bfd_set_section_size (sec, 0);
30237 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30241 #endif
30243 /* Record the CPU type as well. */
30244 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30245 mach = bfd_mach_arm_iWMMXt2;
30246 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
30247 mach = bfd_mach_arm_iWMMXt;
30248 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
30249 mach = bfd_mach_arm_XScale;
30250 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
30251 mach = bfd_mach_arm_5TE;
30252 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
30254 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30255 mach = bfd_mach_arm_5T;
30256 else
30257 mach = bfd_mach_arm_5;
30259 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
30261 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30262 mach = bfd_mach_arm_4T;
30263 else
30264 mach = bfd_mach_arm_4;
30266 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
30267 mach = bfd_mach_arm_3M;
30268 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30269 mach = bfd_mach_arm_3;
30270 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30271 mach = bfd_mach_arm_2a;
30272 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30273 mach = bfd_mach_arm_2;
30274 else
30275 mach = bfd_mach_arm_unknown;
30277 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30280 /* Command line processing. */
30282 /* md_parse_option
30283 Invocation line includes a switch not recognized by the base assembler.
30284 See if it's a processor-specific option.
30286 This routine is somewhat complicated by the need for backwards
30287 compatibility (since older releases of gcc can't be changed).
30288 The new options try to make the interface as compatible as
30289 possible with GCC.
30291 New options (supported) are:
30293 -mcpu=<cpu name> Assemble for selected processor
30294 -march=<architecture name> Assemble for selected architecture
30295 -mfpu=<fpu architecture> Assemble for selected FPU.
30296 -EB/-mbig-endian Big-endian
30297 -EL/-mlittle-endian Little-endian
30298 -k Generate PIC code
30299 -mthumb Start in Thumb mode
30300 -mthumb-interwork Code supports ARM/Thumb interworking
30302 -m[no-]warn-deprecated Warn about deprecated features
30303 -m[no-]warn-syms Warn when symbols match instructions
30305 For now we will also provide support for:
30307 -mapcs-32 32-bit Program counter
30308 -mapcs-26 26-bit Program counter
30309 -macps-float Floats passed in FP registers
30310 -mapcs-reentrant Reentrant code
30311 -matpcs
30312 (sometime these will probably be replaced with -mapcs=<list of options>
30313 and -matpcs=<list of options>)
30315 The remaining options are only supported for back-wards compatibility.
30316 Cpu variants, the arm part is optional:
30317 -m[arm]1 Currently not supported.
30318 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30319 -m[arm]3 Arm 3 processor
30320 -m[arm]6[xx], Arm 6 processors
30321 -m[arm]7[xx][t][[d]m] Arm 7 processors
30322 -m[arm]8[10] Arm 8 processors
30323 -m[arm]9[20][tdmi] Arm 9 processors
30324 -mstrongarm[110[0]] StrongARM processors
30325 -mxscale XScale processors
30326 -m[arm]v[2345[t[e]]] Arm architectures
30327 -mall All (except the ARM1)
30328 FP variants:
30329 -mvfpxd VFP Single precision
30330 -mvfp All VFP
30331 -mno-fpu Disable all floating point instructions
30333 The following CPU names are recognized:
30334 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
30335 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
30336 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
30337 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
30338 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
30339 arm10t arm10e, arm1020t, arm1020e, arm10200e,
30340 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
30344 const char * md_shortopts = "m:k";
30346 #ifdef ARM_BI_ENDIAN
30347 #define OPTION_EB (OPTION_MD_BASE + 0)
30348 #define OPTION_EL (OPTION_MD_BASE + 1)
30349 #else
30350 #if TARGET_BYTES_BIG_ENDIAN
30351 #define OPTION_EB (OPTION_MD_BASE + 0)
30352 #else
30353 #define OPTION_EL (OPTION_MD_BASE + 1)
30354 #endif
30355 #endif
30356 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
30357 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
30359 struct option md_longopts[] =
30361 #ifdef OPTION_EB
30362 {"EB", no_argument, NULL, OPTION_EB},
30363 #endif
30364 #ifdef OPTION_EL
30365 {"EL", no_argument, NULL, OPTION_EL},
30366 #endif
30367 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
30368 #ifdef OBJ_ELF
30369 {"fdpic", no_argument, NULL, OPTION_FDPIC},
30370 #endif
30371 {NULL, no_argument, NULL, 0}
30374 size_t md_longopts_size = sizeof (md_longopts);
30376 struct arm_option_table
30378 const char * option; /* Option name to match. */
30379 const char * help; /* Help information. */
30380 int * var; /* Variable to change. */
30381 int value; /* What to change it to. */
30382 const char * deprecated; /* If non-null, print this message. */
30385 struct arm_option_table arm_opts[] =
30387 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
30388 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
30389 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
30390 &support_interwork, 1, NULL},
30391 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
30392 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
30393 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
30394 1, NULL},
30395 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
30396 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
30397 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
30398 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
30399 NULL},
30401 /* These are recognized by the assembler, but have no affect on code. */
30402 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
30403 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
30405 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
30406 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
30407 &warn_on_deprecated, 0, NULL},
30409 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
30410 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
30411 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
30413 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), true, NULL},
30414 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), false, NULL},
30415 {NULL, NULL, NULL, 0, NULL}
30418 struct arm_legacy_option_table
30420 const char * option; /* Option name to match. */
30421 const arm_feature_set ** var; /* Variable to change. */
30422 const arm_feature_set value; /* What to change it to. */
30423 const char * deprecated; /* If non-null, print this message. */
30426 const struct arm_legacy_option_table arm_legacy_opts[] =
30428 /* DON'T add any new processors to this list -- we want the whole list
30429 to go away... Add them to the processors table instead. */
30430 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30431 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30432 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30433 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30434 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30435 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30436 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30437 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30438 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30439 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30440 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30441 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30442 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30443 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30444 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30445 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30446 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30447 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30448 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30449 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30450 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30451 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30452 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30453 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30454 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30455 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30456 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30457 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30458 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30459 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30460 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30461 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30462 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30463 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30464 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30465 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30466 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30467 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30468 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30469 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30470 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30471 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30472 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30473 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30474 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30475 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30476 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30477 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30478 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30479 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30480 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30481 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30482 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30483 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30484 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30485 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30486 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30487 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30488 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30489 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30490 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30491 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30492 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30493 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30494 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30495 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30496 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30497 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30498 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
30499 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
30500 N_("use -mcpu=strongarm110")},
30501 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
30502 N_("use -mcpu=strongarm1100")},
30503 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
30504 N_("use -mcpu=strongarm1110")},
30505 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
30506 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
30507 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
30509 /* Architecture variants -- don't add any more to this list either. */
30510 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30511 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30512 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30513 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30514 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30515 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30516 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30517 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30518 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30519 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30520 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30521 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30522 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30523 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30524 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30525 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30526 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30527 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30528 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, N_("use -mfpu=softvfp")},
30529 {NULL, NULL, ARM_ARCH_NONE, NULL}
30532 struct arm_cpu_option_table
30534 const char * name;
30535 size_t name_len;
30536 const arm_feature_set value;
30537 const arm_feature_set ext;
30538 /* For some CPUs we assume an FPU unless the user explicitly sets
30539 -mfpu=... */
30540 const arm_feature_set default_fpu;
30541 /* The canonical name of the CPU, or NULL to use NAME converted to upper
30542 case. */
30543 const char * canonical_name;
30546 /* This list should, at a minimum, contain all the cpu names
30547 recognized by GCC. */
30548 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
30550 static const struct arm_cpu_option_table arm_cpus[] =
30552 ARM_CPU_OPT ("all", NULL, ARM_ANY,
30553 ARM_ARCH_NONE,
30554 FPU_NONE),
30555 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
30556 ARM_ARCH_NONE,
30557 FPU_NONE),
30558 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
30559 ARM_ARCH_NONE,
30560 FPU_NONE),
30561 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
30562 ARM_ARCH_NONE,
30563 FPU_NONE),
30564 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
30565 ARM_ARCH_NONE,
30566 FPU_NONE),
30567 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
30568 ARM_ARCH_NONE,
30569 FPU_NONE),
30570 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
30571 ARM_ARCH_NONE,
30572 FPU_NONE),
30573 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
30574 ARM_ARCH_NONE,
30575 FPU_NONE),
30576 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
30577 ARM_ARCH_NONE,
30578 FPU_NONE),
30579 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
30580 ARM_ARCH_NONE,
30581 FPU_NONE),
30582 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
30583 ARM_ARCH_NONE,
30584 FPU_NONE),
30585 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
30586 ARM_ARCH_NONE,
30587 FPU_NONE),
30588 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
30589 ARM_ARCH_NONE,
30590 FPU_NONE),
30591 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
30592 ARM_ARCH_NONE,
30593 FPU_NONE),
30594 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
30595 ARM_ARCH_NONE,
30596 FPU_NONE),
30597 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
30598 ARM_ARCH_NONE,
30599 FPU_NONE),
30600 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
30601 ARM_ARCH_NONE,
30602 FPU_NONE),
30603 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
30604 ARM_ARCH_NONE,
30605 FPU_NONE),
30606 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
30607 ARM_ARCH_NONE,
30608 FPU_NONE),
30609 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
30610 ARM_ARCH_NONE,
30611 FPU_NONE),
30612 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
30613 ARM_ARCH_NONE,
30614 FPU_NONE),
30615 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
30616 ARM_ARCH_NONE,
30617 FPU_NONE),
30618 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
30619 ARM_ARCH_NONE,
30620 FPU_NONE),
30621 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
30622 ARM_ARCH_NONE,
30623 FPU_NONE),
30624 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
30625 ARM_ARCH_NONE,
30626 FPU_NONE),
30627 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
30628 ARM_ARCH_NONE,
30629 FPU_NONE),
30630 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
30631 ARM_ARCH_NONE,
30632 FPU_NONE),
30633 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
30634 ARM_ARCH_NONE,
30635 FPU_NONE),
30636 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
30637 ARM_ARCH_NONE,
30638 FPU_NONE),
30639 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
30640 ARM_ARCH_NONE,
30641 FPU_NONE),
30642 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
30643 ARM_ARCH_NONE,
30644 FPU_NONE),
30645 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
30646 ARM_ARCH_NONE,
30647 FPU_NONE),
30648 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
30649 ARM_ARCH_NONE,
30650 FPU_NONE),
30651 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
30652 ARM_ARCH_NONE,
30653 FPU_NONE),
30654 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
30655 ARM_ARCH_NONE,
30656 FPU_NONE),
30657 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
30658 ARM_ARCH_NONE,
30659 FPU_NONE),
30660 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
30661 ARM_ARCH_NONE,
30662 FPU_NONE),
30663 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
30664 ARM_ARCH_NONE,
30665 FPU_NONE),
30666 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
30667 ARM_ARCH_NONE,
30668 FPU_NONE),
30669 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
30670 ARM_ARCH_NONE,
30671 FPU_NONE),
30672 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
30673 ARM_ARCH_NONE,
30674 FPU_NONE),
30675 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
30676 ARM_ARCH_NONE,
30677 FPU_NONE),
30678 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
30679 ARM_ARCH_NONE,
30680 FPU_NONE),
30681 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
30682 ARM_ARCH_NONE,
30683 FPU_NONE),
30684 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
30685 ARM_ARCH_NONE,
30686 FPU_NONE),
30687 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
30688 ARM_ARCH_NONE,
30689 FPU_NONE),
30691 /* For V5 or later processors we default to using VFP; but the user
30692 should really set the FPU type explicitly. */
30693 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
30694 ARM_ARCH_NONE,
30695 FPU_ARCH_VFP_V2),
30696 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
30697 ARM_ARCH_NONE,
30698 FPU_ARCH_VFP_V2),
30699 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30700 ARM_ARCH_NONE,
30701 FPU_ARCH_VFP_V2),
30702 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30703 ARM_ARCH_NONE,
30704 FPU_ARCH_VFP_V2),
30705 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
30706 ARM_ARCH_NONE,
30707 FPU_ARCH_VFP_V2),
30708 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
30709 ARM_ARCH_NONE,
30710 FPU_ARCH_VFP_V2),
30711 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
30712 ARM_ARCH_NONE,
30713 FPU_ARCH_VFP_V2),
30714 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
30715 ARM_ARCH_NONE,
30716 FPU_ARCH_VFP_V2),
30717 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
30718 ARM_ARCH_NONE,
30719 FPU_ARCH_VFP_V2),
30720 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
30721 ARM_ARCH_NONE,
30722 FPU_ARCH_VFP_V2),
30723 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
30724 ARM_ARCH_NONE,
30725 FPU_ARCH_VFP_V2),
30726 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
30727 ARM_ARCH_NONE,
30728 FPU_ARCH_VFP_V2),
30729 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
30730 ARM_ARCH_NONE,
30731 FPU_ARCH_VFP_V1),
30732 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
30733 ARM_ARCH_NONE,
30734 FPU_ARCH_VFP_V1),
30735 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
30736 ARM_ARCH_NONE,
30737 FPU_ARCH_VFP_V2),
30738 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
30739 ARM_ARCH_NONE,
30740 FPU_ARCH_VFP_V2),
30741 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
30742 ARM_ARCH_NONE,
30743 FPU_ARCH_VFP_V1),
30744 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
30745 ARM_ARCH_NONE,
30746 FPU_ARCH_VFP_V2),
30747 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
30748 ARM_ARCH_NONE,
30749 FPU_ARCH_VFP_V2),
30750 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
30751 ARM_ARCH_NONE,
30752 FPU_ARCH_VFP_V2),
30753 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
30754 ARM_ARCH_NONE,
30755 FPU_ARCH_VFP_V2),
30756 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
30757 ARM_ARCH_NONE,
30758 FPU_ARCH_VFP_V2),
30759 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
30760 ARM_ARCH_NONE,
30761 FPU_ARCH_VFP_V2),
30762 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
30763 ARM_ARCH_NONE,
30764 FPU_ARCH_VFP_V2),
30765 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
30766 ARM_ARCH_NONE,
30767 FPU_ARCH_VFP_V2),
30768 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
30769 ARM_ARCH_NONE,
30770 FPU_ARCH_VFP_V2),
30771 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
30772 ARM_ARCH_NONE,
30773 FPU_ARCH_SOFTVFP),
30774 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
30775 ARM_ARCH_NONE,
30776 FPU_ARCH_SOFTVFP),
30777 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
30778 ARM_ARCH_NONE,
30779 FPU_ARCH_VFP_V2),
30780 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
30781 ARM_ARCH_NONE,
30782 FPU_ARCH_VFP_V2),
30783 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
30784 ARM_ARCH_NONE,
30785 FPU_ARCH_VFP_V2),
30786 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
30787 ARM_ARCH_NONE,
30788 FPU_ARCH_SOFTVFP),
30789 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
30790 ARM_ARCH_NONE,
30791 FPU_ARCH_SOFTVFP),
30792 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
30793 ARM_ARCH_NONE,
30794 FPU_ARCH_VFP_V2),
30795 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
30796 ARM_ARCH_NONE,
30797 FPU_ARCH_SOFTVFP),
30798 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
30799 ARM_ARCH_NONE,
30800 FPU_ARCH_VFP_V2),
30801 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
30802 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30803 FPU_ARCH_SOFTVFP),
30804 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
30805 ARM_ARCH_NONE,
30806 FPU_ARCH_NEON_VFP_V4),
30807 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
30808 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
30809 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30810 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
30811 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30812 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30813 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
30814 ARM_ARCH_NONE,
30815 FPU_ARCH_NEON_VFP_V4),
30816 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
30817 ARM_ARCH_NONE,
30818 FPU_ARCH_NEON_VFP_V4),
30819 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
30820 ARM_ARCH_NONE,
30821 FPU_ARCH_NEON_VFP_V4),
30822 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
30823 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30824 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30825 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
30826 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30827 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30828 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
30829 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30830 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30831 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
30832 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30833 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30834 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
30835 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30836 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30837 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
30838 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30839 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30840 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
30841 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30842 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30843 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
30844 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30845 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30846 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
30847 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30848 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30849 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
30850 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30851 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30852 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
30853 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30854 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30855 ARM_CPU_OPT ("cortex-a78", "Cortex-A78", ARM_ARCH_V8_2A,
30856 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
30857 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30858 ARM_CPU_OPT ("cortex-a78ae", "Cortex-A78AE", ARM_ARCH_V8_2A,
30859 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
30860 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30861 ARM_CPU_OPT ("cortex-a78c", "Cortex-A78C", ARM_ARCH_V8_2A,
30862 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
30863 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30864 ARM_CPU_OPT ("cortex-a710", "Cortex-A710", ARM_ARCH_V9A,
30865 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30866 | ARM_EXT2_BF16
30867 | ARM_EXT2_I8MM),
30868 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30869 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
30870 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30871 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30872 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
30873 ARM_ARCH_NONE,
30874 FPU_ARCH_SOFTVFP),
30875 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
30876 ARM_ARCH_NONE,
30877 FPU_ARCH_VFP_V3D16),
30878 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
30879 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30880 FPU_ARCH_SOFTVFP),
30881 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
30882 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30883 FPU_ARCH_VFP_V3D16),
30884 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
30885 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30886 FPU_ARCH_VFP_V3D16),
30887 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
30888 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30889 FPU_ARCH_NEON_VFP_ARMV8),
30890 ARM_CPU_OPT ("cortex-r52plus", "Cortex-R52+", ARM_ARCH_V8R,
30891 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30892 FPU_ARCH_NEON_VFP_ARMV8),
30893 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
30894 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30895 FPU_ARCH_SOFTVFP),
30896 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
30897 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30898 FPU_ARCH_SOFTVFP),
30899 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
30900 ARM_ARCH_NONE,
30901 FPU_ARCH_SOFTVFP),
30902 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
30903 ARM_ARCH_NONE,
30904 FPU_ARCH_SOFTVFP),
30905 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
30906 ARM_ARCH_NONE,
30907 FPU_ARCH_SOFTVFP),
30908 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
30909 ARM_ARCH_NONE,
30910 FPU_ARCH_SOFTVFP),
30911 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
30912 ARM_ARCH_NONE,
30913 FPU_ARCH_SOFTVFP),
30914 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
30915 ARM_ARCH_NONE,
30916 FPU_ARCH_SOFTVFP),
30917 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
30918 ARM_ARCH_NONE,
30919 FPU_ARCH_SOFTVFP),
30920 ARM_CPU_OPT ("cortex-x1", "Cortex-X1", ARM_ARCH_V8_2A,
30921 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
30922 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30923 ARM_CPU_OPT ("cortex-x1c", "Cortex-X1C", ARM_ARCH_V8_2A,
30924 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
30925 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30926 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
30927 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30928 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30929 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
30930 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30931 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30932 ARM_CPU_OPT ("neoverse-n2", "Neoverse N2", ARM_ARCH_V8_5A,
30933 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30934 | ARM_EXT2_BF16
30935 | ARM_EXT2_I8MM),
30936 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
30937 ARM_CPU_OPT ("neoverse-v1", "Neoverse V1", ARM_ARCH_V8_4A,
30938 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30939 | ARM_EXT2_BF16
30940 | ARM_EXT2_I8MM),
30941 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
30942 /* ??? XSCALE is really an architecture. */
30943 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
30944 ARM_ARCH_NONE,
30945 FPU_ARCH_VFP_V2),
30947 /* ??? iwmmxt is not a processor. */
30948 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
30949 ARM_ARCH_NONE,
30950 FPU_ARCH_VFP_V2),
30951 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
30952 ARM_ARCH_NONE,
30953 FPU_ARCH_VFP_V2),
30954 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
30955 ARM_ARCH_NONE,
30956 FPU_ARCH_VFP_V2),
30958 /* Maverick extensions are no-longer supported, but we can still
30959 recognize the CPU name and treat it like an Arm920T. */
30960 ARM_CPU_OPT ("ep9312", "ARM920T", ARM_ARCH_V4T,
30961 ARM_ARCH_NONE, FPU_NONE),
30963 /* Marvell processors. */
30964 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
30965 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30966 FPU_ARCH_VFP_V3D16),
30967 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
30968 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30969 FPU_ARCH_NEON_VFP_V4),
30971 /* APM X-Gene family. */
30972 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
30973 ARM_ARCH_NONE,
30974 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30975 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
30976 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
30977 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30979 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
30981 #undef ARM_CPU_OPT
30983 struct arm_ext_table
30985 const char * name;
30986 size_t name_len;
30987 const arm_feature_set merge;
30988 const arm_feature_set clear;
30991 struct arm_arch_option_table
30993 const char * name;
30994 size_t name_len;
30995 const arm_feature_set value;
30996 const arm_feature_set default_fpu;
30997 const struct arm_ext_table * ext_table;
31000 /* Used to add support for +E and +noE extension. */
31001 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31002 /* Used to add support for a +E extension. */
31003 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31004 /* Used to add support for a +noE extension. */
31005 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31007 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31008 ~0 & ~FPU_ENDIAN_PURE)
31010 static const struct arm_ext_table armv5te_ext_table[] =
31012 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31013 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31016 static const struct arm_ext_table armv7_ext_table[] =
31018 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31019 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31022 static const struct arm_ext_table armv7ve_ext_table[] =
31024 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31025 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31026 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31027 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31028 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31029 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31030 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31032 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31033 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31035 /* Aliases for +simd. */
31036 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31038 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31039 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31040 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31042 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31045 static const struct arm_ext_table armv7a_ext_table[] =
31047 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31048 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31049 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31050 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31051 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31052 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31053 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31055 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31056 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31058 /* Aliases for +simd. */
31059 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31060 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31062 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31063 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31065 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31066 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31067 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31070 static const struct arm_ext_table armv7r_ext_table[] =
31072 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31073 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31074 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31075 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31076 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31077 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31078 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31079 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31080 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31083 static const struct arm_ext_table armv7em_ext_table[] =
31085 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31086 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31087 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31088 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31089 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31090 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31091 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31094 static const struct arm_ext_table armv8a_ext_table[] =
31096 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31097 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31098 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31099 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31101 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31102 should use the +simd option to turn on FP. */
31103 ARM_REMOVE ("fp", ALL_FP),
31104 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31105 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31106 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31110 static const struct arm_ext_table armv81a_ext_table[] =
31112 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31113 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31114 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31116 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31117 should use the +simd option to turn on FP. */
31118 ARM_REMOVE ("fp", ALL_FP),
31119 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31120 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31121 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31124 static const struct arm_ext_table armv82a_ext_table[] =
31126 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31127 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31128 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
31129 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31130 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31131 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31132 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31133 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31135 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31136 should use the +simd option to turn on FP. */
31137 ARM_REMOVE ("fp", ALL_FP),
31138 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31139 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31140 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31143 static const struct arm_ext_table armv84a_ext_table[] =
31145 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31146 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31147 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31148 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31149 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31150 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31152 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31153 should use the +simd option to turn on FP. */
31154 ARM_REMOVE ("fp", ALL_FP),
31155 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31156 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31157 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31160 static const struct arm_ext_table armv85a_ext_table[] =
31162 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31163 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31164 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31165 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31166 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31167 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31169 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31170 should use the +simd option to turn on FP. */
31171 ARM_REMOVE ("fp", ALL_FP),
31172 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31175 static const struct arm_ext_table armv86a_ext_table[] =
31177 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31178 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31181 #define armv87a_ext_table armv86a_ext_table
31182 #define armv88a_ext_table armv87a_ext_table
31183 #define armv89a_ext_table armv88a_ext_table
31185 static const struct arm_ext_table armv9a_ext_table[] =
31187 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31188 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31189 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31190 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31191 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31192 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31194 /* Armv9-a does not allow an FP implementation without SIMD, so the user
31195 should use the +simd option to turn on FP. */
31196 ARM_REMOVE ("fp", ALL_FP),
31197 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31200 #define armv91a_ext_table armv86a_ext_table
31201 #define armv92a_ext_table armv91a_ext_table
31202 #define armv93a_ext_table armv92a_ext_table
31203 #define armv94a_ext_table armv93a_ext_table
31204 #define armv95a_ext_table armv94a_ext_table
31206 #define CDE_EXTENSIONS \
31207 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31208 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31209 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31210 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31211 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31212 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31213 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31214 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31216 static const struct arm_ext_table armv8m_main_ext_table[] =
31218 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31219 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31220 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31221 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31222 CDE_EXTENSIONS,
31223 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31227 static const struct arm_ext_table armv8_1m_main_ext_table[] =
31229 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31230 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31231 ARM_EXT ("fp",
31232 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31233 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31234 ALL_FP),
31235 ARM_ADD ("fp.dp",
31236 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31237 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31238 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
31239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
31240 ARM_ADD ("mve.fp",
31241 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31242 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
31243 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31244 CDE_EXTENSIONS,
31245 ARM_ADD ("pacbti", ARM_FEATURE_CORE_HIGH_HIGH (ARM_AEXT3_V8_1M_MAIN_PACBTI)),
31246 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31249 #undef CDE_EXTENSIONS
31251 static const struct arm_ext_table armv8r_ext_table[] =
31253 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31254 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31255 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31256 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31257 ARM_REMOVE ("fp", ALL_FP),
31258 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31259 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31262 /* This list should, at a minimum, contain all the architecture names
31263 recognized by GCC. */
31264 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31265 #define ARM_ARCH_OPT2(N, V, DF, ext) \
31266 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
31268 static const struct arm_arch_option_table arm_archs[] =
31270 ARM_ARCH_OPT ("all", ARM_ANY, FPU_NONE),
31271 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_NONE),
31272 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_NONE),
31273 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_NONE),
31274 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_NONE),
31275 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_NONE),
31276 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_NONE),
31277 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_NONE),
31278 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_NONE),
31279 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_NONE),
31280 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_NONE),
31281 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_SOFTVFP),
31282 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_SOFTVFP),
31283 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_SOFTVFP),
31284 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_SOFTVFP,
31285 armv5te),
31286 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_SOFTVFP,
31287 armv5te),
31288 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_SOFTVFP,
31289 armv5te),
31290 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_SOFTVFP,
31291 armv5te),
31292 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_SOFTVFP,
31293 armv5te),
31294 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_SOFTVFP,
31295 armv5te),
31296 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_SOFTVFP,
31297 armv5te),
31298 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31299 kept to preserve existing behaviour. */
31300 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_SOFTVFP,
31301 armv5te),
31302 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_SOFTVFP,
31303 armv5te),
31304 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_SOFTVFP,
31305 armv5te),
31306 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_SOFTVFP,
31307 armv5te),
31308 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_SOFTVFP,
31309 armv5te),
31310 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31311 kept to preserve existing behaviour. */
31312 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_SOFTVFP,
31313 armv5te),
31314 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_SOFTVFP,
31315 armv5te),
31316 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_SOFTVFP),
31317 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_SOFTVFP),
31318 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_SOFTVFP,
31319 armv7),
31320 /* The official spelling of the ARMv7 profile variants is the dashed form.
31321 Accept the non-dashed form for compatibility with old toolchains. */
31322 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_SOFTVFP,
31323 armv7a),
31324 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_SOFTVFP,
31325 armv7ve),
31326 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_SOFTVFP,
31327 armv7r),
31328 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_SOFTVFP),
31329 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_SOFTVFP,
31330 armv7a),
31331 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_SOFTVFP,
31332 armv7r),
31333 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_SOFTVFP),
31334 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_SOFTVFP,
31335 armv7em),
31336 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_SOFTVFP),
31337 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_SOFTVFP,
31338 armv8m_main),
31339 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_SOFTVFP,
31340 armv8_1m_main),
31341 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_SOFTVFP,
31342 armv8a),
31343 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_SOFTVFP,
31344 armv81a),
31345 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_SOFTVFP,
31346 armv82a),
31347 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_SOFTVFP,
31348 armv82a),
31349 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_SOFTVFP,
31350 armv8r),
31351 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_SOFTVFP,
31352 armv84a),
31353 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_SOFTVFP,
31354 armv85a),
31355 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_SOFTVFP,
31356 armv86a),
31357 ARM_ARCH_OPT2 ("armv8.7-a", ARM_ARCH_V8_7A, FPU_ARCH_SOFTVFP,
31358 armv87a),
31359 ARM_ARCH_OPT2 ("armv8.8-a", ARM_ARCH_V8_8A, FPU_ARCH_SOFTVFP,
31360 armv88a),
31361 ARM_ARCH_OPT2 ("armv8.9-a", ARM_ARCH_V8_9A, FPU_ARCH_SOFTVFP,
31362 armv89a),
31363 ARM_ARCH_OPT2 ("armv9-a", ARM_ARCH_V9A, FPU_ARCH_SOFTVFP,
31364 armv9a),
31365 ARM_ARCH_OPT2 ("armv9.1-a", ARM_ARCH_V9_1A, FPU_ARCH_SOFTVFP,
31366 armv91a),
31367 ARM_ARCH_OPT2 ("armv9.2-a", ARM_ARCH_V9_2A, FPU_ARCH_SOFTVFP,
31368 armv92a),
31369 ARM_ARCH_OPT2 ("armv9.3-a", ARM_ARCH_V9_2A, FPU_ARCH_SOFTVFP,
31370 armv93a),
31371 ARM_ARCH_OPT2 ("armv9.4-a", ARM_ARCH_V9_4A, FPU_ARCH_SOFTVFP,
31372 armv94a),
31373 ARM_ARCH_OPT2 ("armv9.5-a", ARM_ARCH_V9_5A, FPU_ARCH_SOFTVFP,
31374 armv95a),
31375 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_SOFTVFP),
31376 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_SOFTVFP),
31377 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_SOFTVFP),
31378 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31380 #undef ARM_ARCH_OPT
31382 /* ISA extensions in the co-processor and main instruction set space. */
31384 struct arm_option_extension_value_table
31386 const char * name;
31387 size_t name_len;
31388 const arm_feature_set merge_value;
31389 const arm_feature_set clear_value;
31390 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31391 indicates that an extension is available for all architectures while
31392 ARM_ANY marks an empty entry. */
31393 const arm_feature_set allowed_archs[2];
31396 /* The following table must be in alphabetical order with a NULL last entry. */
31398 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31399 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
31401 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
31402 use the context sensitive approach using arm_ext_table's. */
31403 static const struct arm_option_extension_value_table arm_extensions[] =
31405 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31406 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31407 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31408 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31409 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31410 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31411 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31412 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31413 ARM_ARCH_V8_2A),
31414 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31415 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31416 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
31417 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31418 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31419 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31420 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31421 ARM_ARCH_V8_2A),
31422 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31423 | ARM_EXT2_FP16_FML),
31424 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31425 | ARM_EXT2_FP16_FML),
31426 ARM_ARCH_V8_2A),
31427 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31428 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31429 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31430 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
31431 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
31432 Thumb divide instruction. Due to this having the same name as the
31433 previous entry, this will be ignored when doing command-line parsing and
31434 only considered by build attribute selection code. */
31435 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31436 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31437 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
31438 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
31439 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
31440 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
31441 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
31442 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
31443 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
31444 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31445 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
31446 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31447 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31448 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
31449 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
31450 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
31451 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
31452 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31453 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31454 ARM_ARCH_V8A),
31455 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
31456 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
31457 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
31458 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
31459 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
31460 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
31461 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31462 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31463 ARM_ARCH_V8A),
31464 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31465 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31466 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
31467 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
31468 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
31469 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
31470 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31471 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
31472 | ARM_EXT_DIV),
31473 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
31474 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
31475 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
31476 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
31477 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
31479 #undef ARM_EXT_OPT
31481 /* ISA floating-point and Advanced SIMD extensions. */
31482 struct arm_option_fpu_value_table
31484 const char * name;
31485 const arm_feature_set value;
31488 /* This list should, at a minimum, contain all the fpu names
31489 recognized by GCC. */
31490 static const struct arm_option_fpu_value_table arm_fpus[] =
31492 {"softfpa", FPU_NONE},
31493 {"softvfp", FPU_ARCH_SOFTVFP},
31494 {"softvfp+vfp", FPU_ARCH_VFP_V2},
31495 {"vfp", FPU_ARCH_VFP_V2},
31496 {"vfp9", FPU_ARCH_VFP_V2},
31497 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
31498 {"vfp10", FPU_ARCH_VFP_V2},
31499 {"vfp10-r0", FPU_ARCH_VFP_V1},
31500 {"vfpxd", FPU_ARCH_VFP_V1xD},
31501 {"vfpv2", FPU_ARCH_VFP_V2},
31502 {"vfpv3", FPU_ARCH_VFP_V3},
31503 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
31504 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
31505 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
31506 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
31507 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
31508 {"arm1020t", FPU_ARCH_VFP_V1},
31509 {"arm1020e", FPU_ARCH_VFP_V2},
31510 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
31511 {"arm1136jf-s", FPU_ARCH_VFP_V2},
31512 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
31513 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
31514 {"neon-fp16", FPU_ARCH_NEON_FP16},
31515 {"vfpv4", FPU_ARCH_VFP_V4},
31516 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
31517 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
31518 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
31519 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
31520 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
31521 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
31522 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
31523 {"crypto-neon-fp-armv8",
31524 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
31525 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
31526 {"crypto-neon-fp-armv8.1",
31527 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
31528 {NULL, ARM_ARCH_NONE}
31531 struct arm_option_value_table
31533 const char *name;
31534 long value;
31537 static const struct arm_option_value_table arm_float_abis[] =
31539 {"hard", ARM_FLOAT_ABI_HARD},
31540 {"softfp", ARM_FLOAT_ABI_SOFTFP},
31541 {"soft", ARM_FLOAT_ABI_SOFT},
31542 {NULL, 0}
31545 #ifdef OBJ_ELF
31546 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
31547 static const struct arm_option_value_table arm_eabis[] =
31549 {"gnu", EF_ARM_EABI_UNKNOWN},
31550 {"4", EF_ARM_EABI_VER4},
31551 {"5", EF_ARM_EABI_VER5},
31552 {NULL, 0}
31554 #endif
31556 struct arm_long_option_table
31558 const char *option; /* Substring to match. */
31559 const char *help; /* Help information. */
31560 bool (*func) (const char *subopt); /* Function to decode sub-option. */
31561 const char *deprecated; /* If non-null, print this message. */
31564 static bool
31565 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
31566 arm_feature_set *ext_set,
31567 const struct arm_ext_table *ext_table)
31569 /* We insist on extensions being specified in alphabetical order, and with
31570 extensions being added before being removed. We achieve this by having
31571 the global ARM_EXTENSIONS table in alphabetical order, and using the
31572 ADDING_VALUE variable to indicate whether we are adding an extension (1)
31573 or removing it (0) and only allowing it to change in the order
31574 -1 -> 1 -> 0. */
31575 const struct arm_option_extension_value_table * opt = NULL;
31576 const arm_feature_set arm_any = ARM_ANY;
31577 int adding_value = -1;
31579 while (str != NULL && *str != 0)
31581 const char *ext;
31582 size_t len;
31584 if (*str != '+')
31586 as_bad (_("invalid architectural extension"));
31587 return false;
31590 str++;
31591 ext = strchr (str, '+');
31593 if (ext != NULL)
31594 len = ext - str;
31595 else
31596 len = strlen (str);
31598 if (len >= 2 && startswith (str, "no"))
31600 if (adding_value != 0)
31602 adding_value = 0;
31603 opt = arm_extensions;
31606 len -= 2;
31607 str += 2;
31609 else if (len > 0)
31611 if (adding_value == -1)
31613 adding_value = 1;
31614 opt = arm_extensions;
31616 else if (adding_value != 1)
31618 as_bad (_("must specify extensions to add before specifying "
31619 "those to remove"));
31620 return false;
31624 if (len == 0)
31626 as_bad (_("missing architectural extension"));
31627 return false;
31630 gas_assert (adding_value != -1);
31631 gas_assert (opt != NULL);
31633 if (ext_table != NULL)
31635 const struct arm_ext_table * ext_opt = ext_table;
31636 bool found = false;
31637 for (; ext_opt->name != NULL; ext_opt++)
31638 if (ext_opt->name_len == len
31639 && strncmp (ext_opt->name, str, len) == 0)
31641 if (adding_value)
31643 if (ARM_FEATURE_ZERO (ext_opt->merge))
31644 /* TODO: Option not supported. When we remove the
31645 legacy table this case should error out. */
31646 continue;
31648 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
31650 else
31652 if (ARM_FEATURE_ZERO (ext_opt->clear))
31653 /* TODO: Option not supported. When we remove the
31654 legacy table this case should error out. */
31655 continue;
31656 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
31658 found = true;
31659 break;
31661 if (found)
31663 str = ext;
31664 continue;
31668 /* Scan over the options table trying to find an exact match. */
31669 for (; opt->name != NULL; opt++)
31670 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31672 int i, nb_allowed_archs =
31673 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
31674 /* Check we can apply the extension to this architecture. */
31675 for (i = 0; i < nb_allowed_archs; i++)
31677 /* Empty entry. */
31678 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
31679 continue;
31680 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
31681 break;
31683 if (i == nb_allowed_archs)
31685 as_bad (_("extension does not apply to the base architecture"));
31686 return false;
31689 /* Add or remove the extension. */
31690 if (adding_value)
31691 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
31692 else
31693 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
31695 /* Allowing Thumb division instructions for ARMv7 in autodetection
31696 rely on this break so that duplicate extensions (extensions
31697 with the same name as a previous extension in the list) are not
31698 considered for command-line parsing. */
31699 break;
31702 if (opt->name == NULL)
31704 /* Did we fail to find an extension because it wasn't specified in
31705 alphabetical order, or because it does not exist? */
31707 for (opt = arm_extensions; opt->name != NULL; opt++)
31708 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31709 break;
31711 if (opt->name == NULL)
31712 as_bad (_("unknown architectural extension `%s'"), str);
31713 else
31714 as_bad (_("architectural extensions must be specified in "
31715 "alphabetical order"));
31717 return false;
31719 else
31721 /* We should skip the extension we've just matched the next time
31722 round. */
31723 opt++;
31726 str = ext;
31729 return true;
31732 static bool
31733 arm_parse_fp16_opt (const char *str)
31735 if (strcasecmp (str, "ieee") == 0)
31736 fp16_format = ARM_FP16_FORMAT_IEEE;
31737 else if (strcasecmp (str, "alternative") == 0)
31738 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
31739 else
31741 as_bad (_("unrecognised float16 format \"%s\""), str);
31742 return false;
31745 return true;
31748 static bool
31749 arm_parse_cpu (const char *str)
31751 const struct arm_cpu_option_table *opt;
31752 const char *ext = strchr (str, '+');
31753 size_t len;
31755 if (ext != NULL)
31756 len = ext - str;
31757 else
31758 len = strlen (str);
31760 if (len == 0)
31762 as_bad (_("missing cpu name `%s'"), str);
31763 return false;
31766 for (opt = arm_cpus; opt->name != NULL; opt++)
31767 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31769 mcpu_cpu_opt = &opt->value;
31770 if (mcpu_ext_opt == NULL)
31771 mcpu_ext_opt = XNEW (arm_feature_set);
31772 *mcpu_ext_opt = opt->ext;
31773 mcpu_fpu_opt = &opt->default_fpu;
31774 if (opt->canonical_name)
31776 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
31777 strcpy (selected_cpu_name, opt->canonical_name);
31779 else
31781 size_t i;
31783 if (len >= sizeof selected_cpu_name)
31784 len = (sizeof selected_cpu_name) - 1;
31786 for (i = 0; i < len; i++)
31787 selected_cpu_name[i] = TOUPPER (opt->name[i]);
31788 selected_cpu_name[i] = 0;
31791 if (ext != NULL)
31792 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
31794 return true;
31797 as_bad (_("unknown cpu `%s'"), str);
31798 return false;
31801 static bool
31802 arm_parse_arch (const char *str)
31804 const struct arm_arch_option_table *opt;
31805 const char *ext = strchr (str, '+');
31806 size_t len;
31808 if (ext != NULL)
31809 len = ext - str;
31810 else
31811 len = strlen (str);
31813 if (len == 0)
31815 as_bad (_("missing architecture name `%s'"), str);
31816 return false;
31819 for (opt = arm_archs; opt->name != NULL; opt++)
31820 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31822 march_cpu_opt = &opt->value;
31823 if (march_ext_opt == NULL)
31824 march_ext_opt = XNEW (arm_feature_set);
31825 *march_ext_opt = arm_arch_none;
31826 march_fpu_opt = &opt->default_fpu;
31827 selected_ctx_ext_table = opt->ext_table;
31828 strcpy (selected_cpu_name, opt->name);
31830 if (ext != NULL)
31831 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
31832 opt->ext_table);
31834 return true;
31837 as_bad (_("unknown architecture `%s'\n"), str);
31838 return false;
31841 static bool
31842 arm_parse_fpu (const char * str)
31844 const struct arm_option_fpu_value_table * opt;
31846 for (opt = arm_fpus; opt->name != NULL; opt++)
31847 if (streq (opt->name, str))
31849 mfpu_opt = &opt->value;
31850 return true;
31853 as_bad (_("unknown floating point format `%s'\n"), str);
31854 return false;
31857 static bool
31858 arm_parse_float_abi (const char * str)
31860 const struct arm_option_value_table * opt;
31862 for (opt = arm_float_abis; opt->name != NULL; opt++)
31863 if (streq (opt->name, str))
31865 mfloat_abi_opt = opt->value;
31866 return true;
31869 as_bad (_("unknown floating point abi `%s'\n"), str);
31870 return false;
31873 #ifdef OBJ_ELF
31874 static bool
31875 arm_parse_eabi (const char * str)
31877 const struct arm_option_value_table *opt;
31879 for (opt = arm_eabis; opt->name != NULL; opt++)
31880 if (streq (opt->name, str))
31882 meabi_flags = opt->value;
31883 return true;
31885 as_bad (_("unknown EABI `%s'\n"), str);
31886 return false;
31888 #endif
31890 static bool
31891 arm_parse_it_mode (const char * str)
31893 bool ret = true;
31895 if (streq ("arm", str))
31896 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
31897 else if (streq ("thumb", str))
31898 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
31899 else if (streq ("always", str))
31900 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
31901 else if (streq ("never", str))
31902 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
31903 else
31905 as_bad (_("unknown implicit IT mode `%s', should be "\
31906 "arm, thumb, always, or never."), str);
31907 ret = false;
31910 return ret;
31913 static bool
31914 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
31916 codecomposer_syntax = true;
31917 arm_comment_chars[0] = ';';
31918 arm_line_separator_chars[0] = 0;
31919 return true;
31922 struct arm_long_option_table arm_long_opts[] =
31924 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
31925 arm_parse_cpu, NULL},
31926 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
31927 arm_parse_arch, NULL},
31928 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
31929 arm_parse_fpu, NULL},
31930 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
31931 arm_parse_float_abi, NULL},
31932 #ifdef OBJ_ELF
31933 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
31934 arm_parse_eabi, NULL},
31935 #endif
31936 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
31937 arm_parse_it_mode, NULL},
31938 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
31939 arm_ccs_mode, NULL},
31940 {"mfp16-format=",
31941 N_("[ieee|alternative]\n\
31942 set the encoding for half precision floating point "
31943 "numbers to IEEE\n\
31944 or Arm alternative format."),
31945 arm_parse_fp16_opt, NULL },
31946 {NULL, NULL, 0, NULL}
31950 md_parse_option (int c, const char * arg)
31952 struct arm_option_table *opt;
31953 const struct arm_legacy_option_table *fopt;
31954 struct arm_long_option_table *lopt;
31956 switch (c)
31958 #ifdef OPTION_EB
31959 case OPTION_EB:
31960 target_big_endian = 1;
31961 break;
31962 #endif
31964 #ifdef OPTION_EL
31965 case OPTION_EL:
31966 target_big_endian = 0;
31967 break;
31968 #endif
31970 case OPTION_FIX_V4BX:
31971 fix_v4bx = true;
31972 break;
31974 #ifdef OBJ_ELF
31975 case OPTION_FDPIC:
31976 arm_fdpic = true;
31977 break;
31978 #endif /* OBJ_ELF */
31980 case 'a':
31981 /* Listing option. Just ignore these, we don't support additional
31982 ones. */
31983 return 0;
31985 default:
31986 for (opt = arm_opts; opt->option != NULL; opt++)
31988 if (c == opt->option[0]
31989 && ((arg == NULL && opt->option[1] == 0)
31990 || streq (arg, opt->option + 1)))
31992 /* If the option is deprecated, tell the user. */
31993 if (warn_on_deprecated && opt->deprecated != NULL)
31994 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31995 arg ? arg : "", _(opt->deprecated));
31997 if (opt->var != NULL)
31998 *opt->var = opt->value;
32000 return 1;
32004 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32006 if (c == fopt->option[0]
32007 && ((arg == NULL && fopt->option[1] == 0)
32008 || streq (arg, fopt->option + 1)))
32010 /* If the option is deprecated, tell the user. */
32011 if (warn_on_deprecated && fopt->deprecated != NULL)
32012 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32013 arg ? arg : "", _(fopt->deprecated));
32015 if (fopt->var != NULL)
32016 *fopt->var = &fopt->value;
32018 return 1;
32022 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32024 /* These options are expected to have an argument. */
32025 if (c == lopt->option[0]
32026 && arg != NULL
32027 && strncmp (arg, lopt->option + 1,
32028 strlen (lopt->option + 1)) == 0)
32030 /* If the option is deprecated, tell the user. */
32031 if (warn_on_deprecated && lopt->deprecated != NULL)
32032 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32033 _(lopt->deprecated));
32035 /* Call the sup-option parser. */
32036 return lopt->func (arg + strlen (lopt->option) - 1);
32040 return 0;
32043 return 1;
32046 void
32047 md_show_usage (FILE * fp)
32049 struct arm_option_table *opt;
32050 struct arm_long_option_table *lopt;
32052 fprintf (fp, _(" ARM-specific assembler options:\n"));
32054 for (opt = arm_opts; opt->option != NULL; opt++)
32055 if (opt->help != NULL)
32056 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
32058 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32059 if (lopt->help != NULL)
32060 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
32062 #ifdef OPTION_EB
32063 fprintf (fp, _("\
32064 -EB assemble code for a big-endian cpu\n"));
32065 #endif
32067 #ifdef OPTION_EL
32068 fprintf (fp, _("\
32069 -EL assemble code for a little-endian cpu\n"));
32070 #endif
32072 fprintf (fp, _("\
32073 --fix-v4bx Allow BX in ARMv4 code\n"));
32075 #ifdef OBJ_ELF
32076 fprintf (fp, _("\
32077 --fdpic generate an FDPIC object file\n"));
32078 #endif /* OBJ_ELF */
32081 #ifdef OBJ_ELF
32083 typedef struct
32085 int val;
32086 arm_feature_set flags;
32087 } cpu_arch_ver_table;
32089 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32090 chronologically for architectures, with an exception for ARMv6-M and
32091 ARMv6S-M due to legacy reasons. No new architecture should have a
32092 special case. This allows for build attribute selection results to be
32093 stable when new architectures are added. */
32094 static const cpu_arch_ver_table cpu_arch_ver[] =
32096 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32097 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32098 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32099 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32100 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32101 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32102 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32103 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32104 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32105 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32106 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32107 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32108 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32109 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32110 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32111 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32112 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32113 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32114 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32115 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32116 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32117 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32118 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32119 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
32121 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32122 always selected build attributes to match those of ARMv6-M
32123 (resp. ARMv6S-M). However, due to these architectures being a strict
32124 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32125 would be selected when fully respecting chronology of architectures.
32126 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32127 move them before ARMv7 architectures. */
32128 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32129 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32131 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32132 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32133 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32134 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32135 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32136 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32137 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32138 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32139 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32140 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32141 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32142 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32143 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32144 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32145 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32146 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
32147 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32148 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_7A},
32149 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_8A},
32150 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_9A},
32151 {TAG_CPU_ARCH_V9, ARM_ARCH_V9A},
32152 {TAG_CPU_ARCH_V9, ARM_ARCH_V9_1A},
32153 {TAG_CPU_ARCH_V9, ARM_ARCH_V9_2A},
32154 {TAG_CPU_ARCH_V9, ARM_ARCH_V9_3A},
32155 {TAG_CPU_ARCH_V9, ARM_ARCH_V9_4A},
32156 {TAG_CPU_ARCH_V9, ARM_ARCH_V9_5A},
32157 {-1, ARM_ARCH_NONE}
32160 /* Set an attribute if it has not already been set by the user. */
32162 static void
32163 aeabi_set_attribute_int (int tag, int value)
32165 if (tag < 1
32166 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32167 || !attributes_set_explicitly[tag])
32168 if (!bfd_elf_add_proc_attr_int (stdoutput, tag, value))
32169 as_fatal (_("error adding attribute: %s"),
32170 bfd_errmsg (bfd_get_error ()));
32173 static void
32174 aeabi_set_attribute_string (int tag, const char *value)
32176 if (tag < 1
32177 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32178 || !attributes_set_explicitly[tag])
32179 if (!bfd_elf_add_proc_attr_string (stdoutput, tag, value))
32180 as_fatal (_("error adding attribute: %s"),
32181 bfd_errmsg (bfd_get_error ()));
32184 /* Return whether features in the *NEEDED feature set are available via
32185 extensions for the architecture whose feature set is *ARCH_FSET. */
32187 static bool
32188 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32189 const arm_feature_set *needed)
32191 int i, nb_allowed_archs;
32192 arm_feature_set ext_fset;
32193 const struct arm_option_extension_value_table *opt;
32195 ext_fset = arm_arch_none;
32196 for (opt = arm_extensions; opt->name != NULL; opt++)
32198 /* Extension does not provide any feature we need. */
32199 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32200 continue;
32202 nb_allowed_archs =
32203 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32204 for (i = 0; i < nb_allowed_archs; i++)
32206 /* Empty entry. */
32207 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32208 break;
32210 /* Extension is available, add it. */
32211 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32212 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32216 /* Can we enable all features in *needed? */
32217 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32220 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32221 a given architecture feature set *ARCH_EXT_FSET including extension feature
32222 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32223 - if true, check for an exact match of the architecture modulo extensions;
32224 - otherwise, select build attribute value of the first superset
32225 architecture released so that results remains stable when new architectures
32226 are added.
32227 For -march/-mcpu=all the build attribute value of the most featureful
32228 architecture is returned. Tag_CPU_arch_profile result is returned in
32229 PROFILE. */
32231 static int
32232 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32233 const arm_feature_set *ext_fset,
32234 char *profile, int exact_match)
32236 arm_feature_set arch_fset;
32237 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32239 /* Select most featureful architecture with all its extensions if building
32240 for -march=all as the feature sets used to set build attributes. */
32241 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32243 /* Force revisiting of decision for each new architecture. */
32244 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V9);
32245 *profile = 'A';
32246 return TAG_CPU_ARCH_V9;
32249 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32251 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32253 arm_feature_set known_arch_fset;
32255 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32256 if (exact_match)
32258 /* Base architecture match user-specified architecture and
32259 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32260 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32262 p_ver_ret = p_ver;
32263 goto found;
32265 /* Base architecture match user-specified architecture only
32266 (eg. ARMv6-M in the same case as above). Record it in case we
32267 find a match with above condition. */
32268 else if (p_ver_ret == NULL
32269 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32270 p_ver_ret = p_ver;
32272 else
32275 /* Architecture has all features wanted. */
32276 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32278 arm_feature_set added_fset;
32280 /* Compute features added by this architecture over the one
32281 recorded in p_ver_ret. */
32282 if (p_ver_ret != NULL)
32283 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32284 p_ver_ret->flags);
32285 /* First architecture that match incl. with extensions, or the
32286 only difference in features over the recorded match is
32287 features that were optional and are now mandatory. */
32288 if (p_ver_ret == NULL
32289 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32291 p_ver_ret = p_ver;
32292 goto found;
32295 else if (p_ver_ret == NULL)
32297 arm_feature_set needed_ext_fset;
32299 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32301 /* Architecture has all features needed when using some
32302 extensions. Record it and continue searching in case there
32303 exist an architecture providing all needed features without
32304 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32305 OS extension). */
32306 if (have_ext_for_needed_feat_p (&known_arch_fset,
32307 &needed_ext_fset))
32308 p_ver_ret = p_ver;
32313 if (p_ver_ret == NULL)
32314 return -1;
32316 found:
32317 /* Tag_CPU_arch_profile. */
32318 if (!ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r)
32319 && (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32320 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32321 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32322 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))))
32323 *profile = 'A';
32324 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)
32325 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r))
32326 *profile = 'R';
32327 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32328 *profile = 'M';
32329 else
32330 *profile = '\0';
32331 return p_ver_ret->val;
32334 /* Set the public EABI object attributes. */
32336 static void
32337 aeabi_set_public_attributes (void)
32339 char profile = '\0';
32340 int arch = -1;
32341 int virt_sec = 0;
32342 int fp16_optional = 0;
32343 int skip_exact_match = 0;
32344 arm_feature_set flags, flags_arch, flags_ext;
32346 /* Autodetection mode, choose the architecture based the instructions
32347 actually used. */
32348 if (no_cpu_selected ())
32350 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
32352 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32353 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
32355 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32356 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
32358 /* Code run during relaxation relies on selected_cpu being set. */
32359 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32360 flags_ext = arm_arch_none;
32361 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32362 selected_ext = flags_ext;
32363 selected_cpu = flags;
32365 /* Otherwise, choose the architecture based on the capabilities of the
32366 requested cpu. */
32367 else
32369 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32370 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32371 flags_ext = selected_ext;
32372 flags = selected_cpu;
32374 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
32376 /* Allow the user to override the reported architecture. */
32377 if (!ARM_FEATURE_ZERO (selected_object_arch))
32379 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
32380 flags_ext = arm_arch_none;
32382 else
32383 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
32385 /* When this function is run again after relaxation has happened there is no
32386 way to determine whether an architecture or CPU was specified by the user:
32387 - selected_cpu is set above for relaxation to work;
32388 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32389 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32390 Therefore, if not in -march=all case we first try an exact match and fall
32391 back to autodetection. */
32392 if (!skip_exact_match)
32393 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32394 if (arch == -1)
32395 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32396 if (arch == -1)
32397 as_bad (_("no architecture contains all the instructions used\n"));
32399 /* Tag_CPU_name. */
32400 if (selected_cpu_name[0])
32402 char *q;
32404 q = selected_cpu_name;
32405 if (startswith (q, "armv"))
32407 int i;
32409 q += 4;
32410 for (i = 0; q[i]; i++)
32411 q[i] = TOUPPER (q[i]);
32413 aeabi_set_attribute_string (Tag_CPU_name, q);
32416 /* Tag_CPU_arch. */
32417 aeabi_set_attribute_int (Tag_CPU_arch, arch);
32419 /* Tag_CPU_arch_profile. */
32420 if (profile != '\0')
32421 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
32423 /* Tag_DSP_extension. */
32424 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
32425 aeabi_set_attribute_int (Tag_DSP_extension, 1);
32427 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32428 /* Tag_ARM_ISA_use. */
32429 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
32430 || ARM_FEATURE_ZERO (flags_arch))
32431 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
32433 /* Tag_THUMB_ISA_use. */
32434 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
32435 || ARM_FEATURE_ZERO (flags_arch))
32437 int thumb_isa_use;
32439 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
32440 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
32441 thumb_isa_use = 3;
32442 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
32443 thumb_isa_use = 2;
32444 else
32445 thumb_isa_use = 1;
32446 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
32449 /* Tag_VFP_arch. */
32450 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
32451 aeabi_set_attribute_int (Tag_VFP_arch,
32452 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32453 ? 7 : 8);
32454 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
32455 aeabi_set_attribute_int (Tag_VFP_arch,
32456 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32457 ? 5 : 6);
32458 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
32460 fp16_optional = 1;
32461 aeabi_set_attribute_int (Tag_VFP_arch, 3);
32463 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
32465 aeabi_set_attribute_int (Tag_VFP_arch, 4);
32466 fp16_optional = 1;
32468 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
32469 aeabi_set_attribute_int (Tag_VFP_arch, 2);
32470 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
32471 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
32472 aeabi_set_attribute_int (Tag_VFP_arch, 1);
32474 /* Tag_ABI_HardFP_use. */
32475 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
32476 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
32477 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
32479 /* Tag_WMMX_arch. */
32480 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
32481 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
32482 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
32483 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
32485 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
32486 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
32487 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
32488 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
32489 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
32490 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
32492 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
32494 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
32496 else
32498 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
32499 fp16_optional = 1;
32503 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
32504 aeabi_set_attribute_int (Tag_MVE_arch, 2);
32505 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
32506 aeabi_set_attribute_int (Tag_MVE_arch, 1);
32508 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
32509 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
32510 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
32512 /* Tag_DIV_use.
32514 We set Tag_DIV_use to two when integer divide instructions have been used
32515 in ARM state, or when Thumb integer divide instructions have been used,
32516 but we have no architecture profile set, nor have we any ARM instructions.
32518 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
32519 by the base architecture.
32521 For new architectures we will have to check these tests. */
32522 gas_assert (arch <= TAG_CPU_ARCH_V9);
32523 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
32524 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
32525 aeabi_set_attribute_int (Tag_DIV_use, 0);
32526 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
32527 || (profile == '\0'
32528 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
32529 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
32530 aeabi_set_attribute_int (Tag_DIV_use, 2);
32532 /* Tag_MP_extension_use. */
32533 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
32534 aeabi_set_attribute_int (Tag_MPextension_use, 1);
32536 /* Tag Virtualization_use. */
32537 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
32538 virt_sec |= 1;
32539 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
32540 virt_sec |= 2;
32541 if (virt_sec != 0)
32542 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
32544 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
32545 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
32548 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
32549 finished and free extension feature bits which will not be used anymore. */
32551 void
32552 arm_md_post_relax (void)
32554 aeabi_set_public_attributes ();
32555 XDELETE (mcpu_ext_opt);
32556 mcpu_ext_opt = NULL;
32557 XDELETE (march_ext_opt);
32558 march_ext_opt = NULL;
32561 /* Add the default contents for the .ARM.attributes section. */
32563 void
32564 arm_md_finish (void)
32566 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
32567 return;
32569 aeabi_set_public_attributes ();
32571 #endif /* OBJ_ELF */
32573 /* Parse a .cpu directive. */
32575 static void
32576 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
32578 const struct arm_cpu_option_table *opt;
32579 char *name;
32580 char saved_char;
32582 name = input_line_pointer;
32583 input_line_pointer = find_end_of_line (input_line_pointer, flag_m68k_mri);
32584 saved_char = *input_line_pointer;
32585 *input_line_pointer = 0;
32587 if (!*name)
32589 as_bad (_(".cpu: missing cpu name"));
32590 *input_line_pointer = saved_char;
32591 return;
32594 /* Skip the first "all" entry. */
32595 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
32596 if (streq (opt->name, name))
32598 selected_arch = opt->value;
32599 selected_ext = opt->ext;
32600 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32601 if (opt->canonical_name)
32602 strcpy (selected_cpu_name, opt->canonical_name);
32603 else
32605 int i;
32606 for (i = 0; opt->name[i]; i++)
32607 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32609 selected_cpu_name[i] = 0;
32611 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32613 *input_line_pointer = saved_char;
32614 demand_empty_rest_of_line ();
32615 return;
32617 as_bad (_("unknown cpu `%s'"), name);
32618 *input_line_pointer = saved_char;
32621 /* Parse a .arch directive. */
32623 static void
32624 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
32626 const struct arm_arch_option_table *opt;
32627 char saved_char;
32628 char *name;
32630 name = input_line_pointer;
32631 input_line_pointer = find_end_of_line (input_line_pointer, flag_m68k_mri);
32632 saved_char = *input_line_pointer;
32633 *input_line_pointer = 0;
32635 if (!*name)
32637 as_bad (_(".arch: missing architecture name"));
32638 *input_line_pointer = saved_char;
32639 return;
32642 /* Skip the first "all" entry. */
32643 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32644 if (streq (opt->name, name))
32646 selected_arch = opt->value;
32647 selected_ctx_ext_table = opt->ext_table;
32648 selected_ext = arm_arch_none;
32649 selected_cpu = selected_arch;
32650 strcpy (selected_cpu_name, opt->name);
32651 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32652 *input_line_pointer = saved_char;
32653 demand_empty_rest_of_line ();
32654 return;
32657 as_bad (_("unknown architecture `%s'\n"), name);
32658 *input_line_pointer = saved_char;
32659 ignore_rest_of_line ();
32662 /* Parse a .object_arch directive. */
32664 static void
32665 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
32667 const struct arm_arch_option_table *opt;
32668 char saved_char;
32669 char *name;
32671 name = input_line_pointer;
32672 input_line_pointer = find_end_of_line (input_line_pointer, flag_m68k_mri);
32673 saved_char = *input_line_pointer;
32674 *input_line_pointer = 0;
32676 if (!*name)
32678 as_bad (_(".object_arch: missing architecture name"));
32679 *input_line_pointer = saved_char;
32680 return;
32683 /* Skip the first "all" entry. */
32684 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32685 if (streq (opt->name, name))
32687 selected_object_arch = opt->value;
32688 *input_line_pointer = saved_char;
32689 demand_empty_rest_of_line ();
32690 return;
32693 as_bad (_("unknown architecture `%s'\n"), name);
32694 *input_line_pointer = saved_char;
32695 ignore_rest_of_line ();
32698 /* Parse a .arch_extension directive. */
32700 static void
32701 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
32703 const struct arm_option_extension_value_table *opt;
32704 char saved_char;
32705 char *name;
32706 int adding_value = 1;
32708 name = input_line_pointer;
32709 input_line_pointer = find_end_of_line (input_line_pointer, flag_m68k_mri);
32710 saved_char = *input_line_pointer;
32711 *input_line_pointer = 0;
32713 if (!*name)
32715 as_bad (_(".arch_extension: missing architecture extension"));
32716 *input_line_pointer = saved_char;
32717 return;
32720 if (strlen (name) >= 2
32721 && startswith (name, "no"))
32723 adding_value = 0;
32724 name += 2;
32727 /* Check the context specific extension table */
32728 if (selected_ctx_ext_table)
32730 const struct arm_ext_table * ext_opt;
32731 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
32733 if (streq (ext_opt->name, name))
32735 if (adding_value)
32737 if (ARM_FEATURE_ZERO (ext_opt->merge))
32738 /* TODO: Option not supported. When we remove the
32739 legacy table this case should error out. */
32740 continue;
32741 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
32742 ext_opt->merge);
32744 else
32745 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
32747 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32748 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32749 *input_line_pointer = saved_char;
32750 demand_empty_rest_of_line ();
32751 return;
32756 for (opt = arm_extensions; opt->name != NULL; opt++)
32757 if (streq (opt->name, name))
32759 int i, nb_allowed_archs =
32760 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
32761 for (i = 0; i < nb_allowed_archs; i++)
32763 /* Empty entry. */
32764 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
32765 continue;
32766 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
32767 break;
32770 if (i == nb_allowed_archs)
32772 as_bad (_("architectural extension `%s' is not allowed for the "
32773 "current base architecture"), name);
32774 break;
32777 if (adding_value)
32778 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
32779 opt->merge_value);
32780 else
32781 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
32783 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32784 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32785 *input_line_pointer = saved_char;
32786 demand_empty_rest_of_line ();
32787 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
32788 on this return so that duplicate extensions (extensions with the
32789 same name as a previous extension in the list) are not considered
32790 for command-line parsing. */
32791 return;
32794 if (opt->name == NULL)
32795 as_bad (_("unknown architecture extension `%s'\n"), name);
32797 *input_line_pointer = saved_char;
32800 /* Parse a .fpu directive. */
32802 static void
32803 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
32805 const struct arm_option_fpu_value_table *opt;
32806 char saved_char;
32807 char *name;
32809 name = input_line_pointer;
32810 input_line_pointer = find_end_of_line (input_line_pointer, flag_m68k_mri);
32811 saved_char = *input_line_pointer;
32812 *input_line_pointer = 0;
32814 if (!*name)
32816 as_bad (_(".fpu: missing fpu name"));
32817 *input_line_pointer = saved_char;
32818 return;
32821 for (opt = arm_fpus; opt->name != NULL; opt++)
32822 if (streq (opt->name, name))
32824 selected_fpu = opt->value;
32825 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
32826 #ifndef CPU_DEFAULT
32827 if (no_cpu_selected ())
32828 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
32829 else
32830 #endif
32831 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32832 *input_line_pointer = saved_char;
32833 return;
32836 as_bad (_("unknown floating point format `%s'\n"), name);
32837 *input_line_pointer = saved_char;
32838 ignore_rest_of_line ();
32841 /* Copy symbol information. */
32843 void
32844 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
32846 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
32849 #ifdef OBJ_ELF
32850 /* Given a symbolic attribute NAME, return the proper integer value.
32851 Returns -1 if the attribute is not known. */
32854 arm_convert_symbolic_attribute (const char *name)
32856 static const struct
32858 const char * name;
32859 const int tag;
32861 attribute_table[] =
32863 /* When you modify this table you should
32864 also modify the list in doc/c-arm.texi. */
32865 #define T(tag) {#tag, tag}
32866 T (Tag_CPU_raw_name),
32867 T (Tag_CPU_name),
32868 T (Tag_CPU_arch),
32869 T (Tag_CPU_arch_profile),
32870 T (Tag_ARM_ISA_use),
32871 T (Tag_THUMB_ISA_use),
32872 T (Tag_FP_arch),
32873 T (Tag_VFP_arch),
32874 T (Tag_WMMX_arch),
32875 T (Tag_Advanced_SIMD_arch),
32876 T (Tag_PCS_config),
32877 T (Tag_ABI_PCS_R9_use),
32878 T (Tag_ABI_PCS_RW_data),
32879 T (Tag_ABI_PCS_RO_data),
32880 T (Tag_ABI_PCS_GOT_use),
32881 T (Tag_ABI_PCS_wchar_t),
32882 T (Tag_ABI_FP_rounding),
32883 T (Tag_ABI_FP_denormal),
32884 T (Tag_ABI_FP_exceptions),
32885 T (Tag_ABI_FP_user_exceptions),
32886 T (Tag_ABI_FP_number_model),
32887 T (Tag_ABI_align_needed),
32888 T (Tag_ABI_align8_needed),
32889 T (Tag_ABI_align_preserved),
32890 T (Tag_ABI_align8_preserved),
32891 T (Tag_ABI_enum_size),
32892 T (Tag_ABI_HardFP_use),
32893 T (Tag_ABI_VFP_args),
32894 T (Tag_ABI_WMMX_args),
32895 T (Tag_ABI_optimization_goals),
32896 T (Tag_ABI_FP_optimization_goals),
32897 T (Tag_compatibility),
32898 T (Tag_CPU_unaligned_access),
32899 T (Tag_FP_HP_extension),
32900 T (Tag_VFP_HP_extension),
32901 T (Tag_ABI_FP_16bit_format),
32902 T (Tag_MPextension_use),
32903 T (Tag_DIV_use),
32904 T (Tag_nodefaults),
32905 T (Tag_also_compatible_with),
32906 T (Tag_conformance),
32907 T (Tag_T2EE_use),
32908 T (Tag_Virtualization_use),
32909 T (Tag_DSP_extension),
32910 T (Tag_MVE_arch),
32911 T (Tag_PAC_extension),
32912 T (Tag_BTI_extension),
32913 T (Tag_BTI_use),
32914 T (Tag_PACRET_use),
32915 /* We deliberately do not include Tag_MPextension_use_legacy. */
32916 #undef T
32918 unsigned int i;
32920 if (name == NULL)
32921 return -1;
32923 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
32924 if (streq (name, attribute_table[i].name))
32925 return attribute_table[i].tag;
32927 return -1;
32930 /* Apply sym value for relocations only in the case that they are for
32931 local symbols in the same segment as the fixup and you have the
32932 respective architectural feature for blx and simple switches. */
32935 arm_apply_sym_value (struct fix * fixP, segT this_seg)
32937 if (fixP->fx_addsy
32938 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
32939 /* PR 17444: If the local symbol is in a different section then a reloc
32940 will always be generated for it, so applying the symbol value now
32941 will result in a double offset being stored in the relocation. */
32942 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
32943 && !S_FORCE_RELOC (fixP->fx_addsy, true))
32945 switch (fixP->fx_r_type)
32947 case BFD_RELOC_ARM_PCREL_BLX:
32948 case BFD_RELOC_THUMB_PCREL_BRANCH23:
32949 if (ARM_IS_FUNC (fixP->fx_addsy))
32950 return 1;
32951 break;
32953 case BFD_RELOC_ARM_PCREL_CALL:
32954 case BFD_RELOC_THUMB_PCREL_BLX:
32955 if (THUMB_IS_FUNC (fixP->fx_addsy))
32956 return 1;
32957 break;
32959 default:
32960 break;
32964 return 0;
32966 #endif /* OBJ_ELF */